Static Value-Flow Analysis
Loading...
Searching...
No Matches
SVF::IntervalValue Class Reference

#include <IntervalValue.h>

Public Member Functions

bool isTop () const
bool isBottom () const
 IntervalValue ()
 Create default IntervalValue.
 IntervalValue (s64_t n)
 Create the IntervalValue [n, n].
 IntervalValue (s32_t n)
 IntervalValue (u32_t n)
 IntervalValue (double n)
 IntervalValue (BoundedInt n)
 IntervalValue (BoundedInt lb, BoundedInt ub)
 Create the IntervalValue [lb, ub].
 IntervalValue (s64_t lb, s64_t ub)
 IntervalValue (double lb, double ub)
 IntervalValue (float lb, float ub)
 IntervalValue (s32_t lb, s32_t ub)
 IntervalValue (u32_t lb, u32_t ub)
 IntervalValue (u64_t lb, u64_t ub)
 IntervalValue (const IntervalValue &)=default
 Copy constructor.
 IntervalValue (IntervalValue &&)=default
 Move constructor.
IntervalValue & operator= (const IntervalValue &a)=default
 Copy assignment operator.
IntervalValue & operator= (IntervalValue &&)=default
 Move assignment operator.
IntervalValue operator== (const IntervalValue &other) const
 Equality comparison.
IntervalValue operator!= (const IntervalValue &other) const
 Equality comparison.
 ~IntervalValue ()=default
 Destructor.
const BoundedInt & lb () const
 Return the lower bound.
const BoundedInt & ub () const
 Return the upper bound.
bool is_zero () const
 Return true if the IntervalValue is [0, 0].
bool is_infinite () const
 Return true if the IntervalValue is infinite IntervalValue.
bool is_int () const
bool is_real () const
s64_t getNumeral () const
 Return.
s64_t getIntNumeral () const
double getRealNumeral () const
bool is_numeral () const
 Return true if the IntervalValue is a number [num, num].
void set_to_bottom ()
 Set current IntervalValue as bottom.
void set_to_top ()
 Set current IntervalValue as top.
bool containedWithin (const IntervalValue &other) const
bool contain (const IntervalValue &other) const
bool leq (const IntervalValue &other) const
bool geq (const IntervalValue &other) const
bool equals (const IntervalValue &other) const
 Equality comparison.
void join_with (const IntervalValue &other)
 Current IntervalValue joins with another IntervalValue.
void widen_with (const IntervalValue &other)
 Current IntervalValue widen with another IntervalValue.
void narrow_with (const IntervalValue &other)
 Current IntervalValue narrow with another IntervalValue.
void meet_with (const IntervalValue &other)
 Return a intersected IntervalValue.
bool contains (int n) const
 Return true if the IntervalValue contains n.
void dump (std::ostream &o) const
const std::string toString () const

Static Public Member Functions

static BoundedInt minus_infinity ()
 Get minus infinity -inf.
static BoundedInt plus_infinity ()
 Get plus infinity +inf.
static bool is_infinite (const BoundedInt &e)
static IntervalValue top ()
 Create the IntervalValue [-inf, +inf].
static IntervalValue bottom ()
 Create the bottom IntervalValue [+inf, -inf].

Private Member Functions

void setValue (const BoundedInt &lb, const BoundedInt &ub)
 Set the lower bound.

Static Private Member Functions

static IntervalValue create (const BoundedInt &lb, const BoundedInt &ub)

Private Attributes

BoundedInt _lb
BoundedInt _ub

Friends

IntervalValue operator+ (const IntervalValue &lhs, const IntervalValue &rhs)
 Add IntervalValues.
IntervalValue operator- (const IntervalValue &lhs, const IntervalValue &rhs)
 Subtract IntervalValues.
IntervalValue operator* (const IntervalValue &lhs, const IntervalValue &rhs)
 Multiply IntervalValues.
IntervalValue operator/ (const IntervalValue &lhs, const IntervalValue &rhs)
 Divide IntervalValues.
IntervalValue operator<< (const IntervalValue &lhs, const IntervalValue &rhs)
 Left binary shift of IntervalValues.
IntervalValue operator>> (const IntervalValue &lhs, const IntervalValue &rhs)
 Left binary shift of IntervalValues.
IntervalValue operator& (const IntervalValue &lhs, const IntervalValue &rhs)
 Bitwise AND of IntervalValues.
IntervalValue operator| (const IntervalValue &lhs, const IntervalValue &rhs)
 Bitwise OR of IntervalValues.
IntervalValue operator^ (const IntervalValue &lhs, const IntervalValue &rhs)
 Bitwise XOR of IntervalValues.

Detailed Description

IntervalValue abstract value

Implemented as a pair of bounds

Definition at line 45 of file IntervalValue.h.

Constructor & Destructor Documentation

◆ IntervalValue() [1/15]

SVF::IntervalValue::IntervalValue ( )
inlineexplicit

Create default IntervalValue.

Definition at line 106 of file IntervalValue.h.

static BoundedInt minus_infinity()
Get minus infinity -inf.
static BoundedInt plus_infinity()
Get plus infinity +inf.

◆ IntervalValue() [2/15]

SVF::IntervalValue::IntervalValue ( s64_t n)
inlineexplicit

Create the IntervalValue [n, n].

Definition at line 109 of file IntervalValue.h.

109: _lb(n), _ub(n) {}
cJSON * n
Definition cJSON.cpp:2558

◆ IntervalValue() [3/15]

SVF::IntervalValue::IntervalValue ( s32_t n)
inlineexplicit

Definition at line 111 of file IntervalValue.h.

111: IntervalValue((s64_t) n) {}
IntervalValue()
Create default IntervalValue.
signed long long s64_t
Definition GeneralType.h:70

◆ IntervalValue() [4/15]

SVF::IntervalValue::IntervalValue ( u32_t n)
inlineexplicit

Definition at line 113 of file IntervalValue.h.

113: IntervalValue((s64_t) n) {}

◆ IntervalValue() [5/15]

SVF::IntervalValue::IntervalValue ( double n)
inlineexplicit

Definition at line 115 of file IntervalValue.h.

115: _lb(n), _ub(n) {}

◆ IntervalValue() [6/15]

SVF::IntervalValue::IntervalValue ( BoundedInt n)
inlineexplicit

Definition at line 117 of file IntervalValue.h.

117: IntervalValue(n, n) {}

◆ IntervalValue() [7/15]

SVF::IntervalValue::IntervalValue ( BoundedInt lb,
BoundedInt ub )
inlineexplicit

Create the IntervalValue [lb, ub].

Definition at line 120 of file IntervalValue.h.

120 : _lb(std::move(lb)), _ub(std::move(ub))
121 {
122 assert((isBottom() || _lb.leq(_ub)) && "lower bound should be less than or equal to upper bound");
123 }
const BoundedInt & ub() const
Return the upper bound.
bool isBottom() const
const BoundedInt & lb() const
Return the lower bound.

◆ IntervalValue() [8/15]

SVF::IntervalValue::IntervalValue ( s64_t lb,
s64_t ub )
inlineexplicit

Definition at line 125 of file IntervalValue.h.

125: IntervalValue(BoundedInt(lb), BoundedInt(ub)) {}

◆ IntervalValue() [9/15]

SVF::IntervalValue::IntervalValue ( double lb,
double ub )
inlineexplicit

Definition at line 127 of file IntervalValue.h.

127: IntervalValue(BoundedInt(lb), BoundedInt(ub)) {}

◆ IntervalValue() [10/15]

SVF::IntervalValue::IntervalValue ( float lb,
float ub )
inlineexplicit

Definition at line 129 of file IntervalValue.h.

129: IntervalValue(BoundedInt(lb), BoundedInt(ub)) {}

◆ IntervalValue() [11/15]

SVF::IntervalValue::IntervalValue ( s32_t lb,
s32_t ub )
inlineexplicit

Definition at line 131 of file IntervalValue.h.

131: IntervalValue((s64_t) lb, (s64_t) ub) {}

◆ IntervalValue() [12/15]

SVF::IntervalValue::IntervalValue ( u32_t lb,
u32_t ub )
inlineexplicit

Definition at line 133 of file IntervalValue.h.

133: IntervalValue((s64_t) lb, (s64_t) ub) {}

◆ IntervalValue() [13/15]

SVF::IntervalValue::IntervalValue ( u64_t lb,
u64_t ub )
inlineexplicit

Definition at line 135 of file IntervalValue.h.

135: IntervalValue((s64_t) lb, (s64_t) ub) {}

◆ IntervalValue() [14/15]

SVF::IntervalValue::IntervalValue ( const IntervalValue & )
default

Copy constructor.

◆ IntervalValue() [15/15]

SVF::IntervalValue::IntervalValue ( IntervalValue && )
default

Move constructor.

◆ ~IntervalValue()

SVF::IntervalValue::~IntervalValue ( )
default

Destructor.

Member Function Documentation

◆ bottom()

IntervalValue SVF::IntervalValue::bottom ( )
inlinestatic

Create the bottom IntervalValue [+inf, -inf].

Definition at line 100 of file IntervalValue.h.

101 {
103 }

◆ contain()

bool SVF::IntervalValue::contain ( const IntervalValue & other) const
inline

Determines if the current IntervalValue fully contains another IntervalValue. Example: this: [1, 4], other: [2, 3] -> returns true Note: If the current interval is 'bottom', it is considered to contain any interval. If the other interval is 'bottom', it cannot be contained by any interval.

Definition at line 321 of file IntervalValue.h.

322 {
323 if (this->isBottom())
324 {
325 return true;
326 }
327 else if (other.isBottom())
328 {
329 return false;
330 }
331 else
332 {
333 return other._lb.geq(this->_lb) && this->_ub.geq(other._ub);
334 }
335 }

◆ containedWithin()

bool SVF::IntervalValue::containedWithin ( const IntervalValue & other) const
inline

Determines if the current IntervalValue is fully contained within another IntervalValue. Example: this: [2, 3], other: [1, 4] -> returns true Note: If the current interval is 'bottom', it is considered contained within any interval. If the other interval is 'bottom', it cannot contain any interval.

Definition at line 300 of file IntervalValue.h.

301 {
302 if (this->isBottom())
303 {
304 return true;
305 }
306 else if (other.isBottom())
307 {
308 return false;
309 }
310 else
311 {
312 return other._lb.leq(this->_lb) && this->_ub.leq(other._ub);
313 }
314
315 }

◆ contains()

bool SVF::IntervalValue::contains ( int n) const
inline

Return true if the IntervalValue contains n.

Definition at line 495 of file IntervalValue.h.

496 {
497 return this->_lb.leq(n) && this->_ub.geq(n);
498 }

◆ create()

IntervalValue SVF::IntervalValue::create ( const BoundedInt & lb,
const BoundedInt & ub )
inlinestaticprivate

Definition at line 539 of file IntervalValue.h.

540 {
541 if (!lb.leq(ub))
542 return IntervalValue::bottom();
543 else
544 return IntervalValue(lb, ub);
545 }
static IntervalValue bottom()
Create the bottom IntervalValue [+inf, -inf].

◆ dump()

void SVF::IntervalValue::dump ( std::ostream & o) const
inline

Definition at line 500 of file IntervalValue.h.

501 {
502 if (this->isBottom())
503 {
504 o << "⊥";
505 }
506 else
507 {
508 o << "[" << this->_lb << ", " << this->_ub << "]";
509 }
510 }

◆ equals()

bool SVF::IntervalValue::equals ( const IntervalValue & other) const
inline

Equality comparison.

Definition at line 375 of file IntervalValue.h.

376 {
377 if (this->isBottom())
378 {
379 return other.isBottom();
380 }
381 else if (other.isBottom())
382 {
383 return false;
384 }
385 else
386 {
387 if (this->is_real() && other.is_real())
388 {
389 return this->_lb.equal(other._lb) && this->_ub.equal(other._ub);
390 }
391 else if (this->is_int() && other.is_int())
392 {
393 return this->_lb.equal(other._lb) && this->_ub.equal(other._ub);
394 }
395 else if (this->is_int())
396 {
397 double thislb = this->_lb.getIntNumeral();
398 double thisub = this->_ub.getIntNumeral();
399 double otherlb = other._lb.getRealNumeral();
400 double otherub = other._ub.getRealNumeral();
401 return thislb == otherlb && thisub == otherub;
402 }
403 else
404 {
405 double thislb = this->_lb.getRealNumeral();
406 double thisub = this->_ub.getRealNumeral();
407 double otherlb = other._lb.getIntNumeral();
408 double otherub = other._ub.getIntNumeral();
409 return thislb == otherlb && thisub == otherub;
410 }
411 assert(false && "not implemented");
412 }
413 }
bool is_int() const
bool is_real() const

◆ geq()

bool SVF::IntervalValue::geq ( const IntervalValue & other) const
inline

Check the lower bound of this Interval is greater than or equal to the upper bound e.g. [3, 5] > [1, 3] return true, lhs.lb >= rhs.ub

Definition at line 357 of file IntervalValue.h.

358 {
359 if (this->isBottom())
360 {
361 return true;
362 }
363 else if (other.isBottom())
364 {
365 return false;
366 }
367 else
368 {
369 return this->_lb.geq(other._ub);
370 }
371 }

◆ getIntNumeral()

s64_t SVF::IntervalValue::getIntNumeral ( ) const
inline

Definition at line 264 of file IntervalValue.h.

265 {
266 assert(is_numeral() && "this IntervalValue is not numeral");
267 return _lb.getIntNumeral();
268 }
bool is_numeral() const
Return true if the IntervalValue is a number [num, num].

◆ getNumeral()

s64_t SVF::IntervalValue::getNumeral ( ) const
inline

Return.

Definition at line 258 of file IntervalValue.h.

259 {
260 assert(is_numeral() && "this IntervalValue is not numeral");
261 return _lb.getNumeral();
262 }

◆ getRealNumeral()

double SVF::IntervalValue::getRealNumeral ( ) const
inline

Definition at line 270 of file IntervalValue.h.

271 {
272 assert(is_numeral() && "this IntervalValue is not numeral");
273 return _lb.getRealNumeral();
274 }

◆ is_infinite() [1/2]

bool SVF::IntervalValue::is_infinite ( ) const
inline

Return true if the IntervalValue is infinite IntervalValue.

Definition at line 240 of file IntervalValue.h.

241 {
242 return _lb.is_infinity() || _ub.is_infinity();
243 }

◆ is_infinite() [2/2]

bool SVF::IntervalValue::is_infinite ( const BoundedInt & e)
inlinestatic

Definition at line 88 of file IntervalValue.h.

89 {
90 return e.is_infinity();
91 }

◆ is_int()

bool SVF::IntervalValue::is_int ( ) const
inline

Definition at line 245 of file IntervalValue.h.

246 {
247 return !is_real();
248 }

◆ is_numeral()

bool SVF::IntervalValue::is_numeral ( ) const
inline

Return true if the IntervalValue is a number [num, num].

Definition at line 277 of file IntervalValue.h.

278 {
279 return eq(_lb, _ub);
280 }

◆ is_real()

bool SVF::IntervalValue::is_real ( ) const
inline

Definition at line 250 of file IntervalValue.h.

251 {
252 bool lb_real = _lb.is_real();
253 bool ub_real = _ub.is_real();
254 return lb_real || ub_real;
255 }

◆ is_zero()

bool SVF::IntervalValue::is_zero ( ) const
inline

Return true if the IntervalValue is [0, 0].

Definition at line 234 of file IntervalValue.h.

235 {
236 return _lb.is_zero() && _ub.is_zero();
237 }

◆ isBottom()

bool SVF::IntervalValue::isBottom ( ) const
inline

Definition at line 71 of file IntervalValue.h.

72 {
73 return _lb.is_plus_infinity() && _ub.is_minus_infinity();
74 }

◆ isTop()

bool SVF::IntervalValue::isTop ( ) const
inline

Definition at line 66 of file IntervalValue.h.

67 {
68 return _lb.is_minus_infinity() && _ub.is_plus_infinity();
69 }

◆ join_with()

void SVF::IntervalValue::join_with ( const IntervalValue & other)
inline

Current IntervalValue joins with another IntervalValue.

Definition at line 416 of file IntervalValue.h.

417 {
418 if (this->isBottom())
419 {
420 if (other.isBottom())
421 {
422 return;
423 }
424 else
425 {
426 setValue(other.lb(), other.ub());
427 }
428 }
429 else if (other.isBottom())
430 {
431 return;
432 }
433 else
434 {
435 setValue(min(this->lb(), other.lb()), max(this->ub(), other.ub()));
436 }
437 }
void setValue(const BoundedInt &lb, const BoundedInt &ub)
Set the lower bound.

◆ lb()

const BoundedInt & SVF::IntervalValue::lb ( ) const
inline

Return the lower bound.

Definition at line 220 of file IntervalValue.h.

221 {
222 assert(!this->isBottom() && "bottom interval does not have lower bound");
223 return this->_lb;
224 }

◆ leq()

bool SVF::IntervalValue::leq ( const IntervalValue & other) const
inline

Check the upper bound of this Interval is less than or equal to the lower bound e.g. [1, 3] < [3, 5] return true, lhs.ub <= rhs.lb

Definition at line 339 of file IntervalValue.h.

340 {
341 if (this->isBottom())
342 {
343 return true;
344 }
345 else if (other.isBottom())
346 {
347 return false;
348 }
349 else
350 {
351 return this->_ub.leq(other._lb);
352 }
353 }

◆ meet_with()

void SVF::IntervalValue::meet_with ( const IntervalValue & other)
inline

Return a intersected IntervalValue.

Definition at line 475 of file IntervalValue.h.

476 {
477 if (this->isBottom() || other.isBottom())
478 {
479 this->set_to_bottom();
480 }
481 else
482 {
483 if (!(max(this->_lb, other.lb()).leq(min(this->_ub, other.ub()))))
484 {
485 this->set_to_bottom();
486 }
487 else
488 {
489 setValue(max(this->_lb, other.lb()), min(this->_ub, other.ub()));
490 }
491 }
492 }
void set_to_bottom()
Set current IntervalValue as bottom.

◆ minus_infinity()

BoundedInt SVF::IntervalValue::minus_infinity ( )
inlinestatic

Get minus infinity -inf.

Definition at line 77 of file IntervalValue.h.

78 {
80 }
static BoundedInt minus_infinity()

◆ narrow_with()

void SVF::IntervalValue::narrow_with ( const IntervalValue & other)
inline

Current IntervalValue narrow with another IntervalValue.

Definition at line 458 of file IntervalValue.h.

459 {
460 if (this->isBottom() || other.isBottom())
461 {
462 this->set_to_bottom();
463 }
464 else if (other.isBottom())
465 {
466 return;
467 }
468 else
469 {
470 setValue(is_infinite(this->lb()) ? other._lb : this->_lb, is_infinite(this->ub()) ? other._ub : this->_ub);
471 }
472 }
bool is_infinite() const
Return true if the IntervalValue is infinite IntervalValue.
static bool is_infinite(const BoundedInt &e)

◆ operator!=()

IntervalValue SVF::IntervalValue::operator!= ( const IntervalValue & other) const
inline

Equality comparison.

Definition at line 184 of file IntervalValue.h.

185 {
186 if (this->isBottom() || other.isBottom())
187 {
188 return bottom();
189 }
190 else if (this->isTop() || other.isTop())
191 {
192 return top();
193 }
194 else
195 {
196 if (this->is_numeral() && other.is_numeral())
197 {
198 return eq(this->_lb, other._lb) ? IntervalValue(0, 0) : IntervalValue(1, 1);
199 }
200 else
201 {
202 IntervalValue value = *this;
203 value.meet_with(other);
204 if (!value.isBottom())
205 {
206 return IntervalValue(0, 1);
207 }
208 else
209 {
210 return IntervalValue(1, 1);
211 }
212 }
213 }
214 }
bool isTop() const
static IntervalValue top()
Create the IntervalValue [-inf, +inf].

◆ operator=() [1/2]

IntervalValue & SVF::IntervalValue::operator= ( const IntervalValue & a)
default

Copy assignment operator.

◆ operator=() [2/2]

IntervalValue & SVF::IntervalValue::operator= ( IntervalValue && )
default

Move assignment operator.

◆ operator==()

IntervalValue SVF::IntervalValue::operator== ( const IntervalValue & other) const
inline

Equality comparison.

Definition at line 150 of file IntervalValue.h.

151 {
152 if (this->isBottom() || other.isBottom())
153 {
154 return bottom();
155 }
156 else if (this->isTop() || other.isTop())
157 {
158 return top();
159 }
160 else
161 {
162 if (this->is_numeral() && other.is_numeral())
163 {
164 return eq(this->_lb, other._lb) ? IntervalValue(1, 1) : IntervalValue(0, 0);
165 }
166 else
167 {
168 IntervalValue value = *this;
169 value.meet_with(other);
170 if (value.isBottom())
171 {
172 return IntervalValue(0, 0);
173 }
174 else
175 {
176 // return top();
177 return IntervalValue(0, 1);
178 }
179 }
180 }
181 }

◆ plus_infinity()

BoundedInt SVF::IntervalValue::plus_infinity ( )
inlinestatic

Get plus infinity +inf.

Definition at line 83 of file IntervalValue.h.

84 {
86 }
static BoundedInt plus_infinity()

◆ set_to_bottom()

void SVF::IntervalValue::set_to_bottom ( )
inline

Set current IntervalValue as bottom.

Definition at line 283 of file IntervalValue.h.

284 {
285 this->_lb = plus_infinity();
286 this->_ub = minus_infinity();
287 }

◆ set_to_top()

void SVF::IntervalValue::set_to_top ( )
inline

Set current IntervalValue as top.

Definition at line 290 of file IntervalValue.h.

291 {
292 this->_lb = minus_infinity();
293 this->_ub = plus_infinity();
294 }

◆ setValue()

void SVF::IntervalValue::setValue ( const BoundedInt & lb,
const BoundedInt & ub )
inlineprivate

Set the lower bound.

Definition at line 528 of file IntervalValue.h.

529 {
530 assert(((lb.is_plus_infinity() && ub.is_minus_infinity()) ||
531 lb.leq(ub)) &&
532 "lower bound should be less than or equal to upper bound");
533 this->_lb = lb;
534 this->_ub = ub;
535 }

◆ top()

IntervalValue SVF::IntervalValue::top ( )
inlinestatic

Create the IntervalValue [-inf, +inf].

Definition at line 94 of file IntervalValue.h.

95 {
97 }

◆ toString()

const std::string SVF::IntervalValue::toString ( ) const
inline

Definition at line 512 of file IntervalValue.h.

513 {
514 std::string str;
515 std::stringstream rawStr(str);
516 if (this->isBottom())
517 {
518 rawStr << "⊥";
519 }
520 else
521 {
522 rawStr << "[" << lb().to_string() << ", " << ub().to_string() << "]";
523 }
524 return rawStr.str();
525 }
virtual const std::string to_string() const

◆ ub()

const BoundedInt & SVF::IntervalValue::ub ( ) const
inline

Return the upper bound.

Definition at line 227 of file IntervalValue.h.

228 {
229 assert(!this->isBottom() && "bottom interval does not have upper bound");
230 return this->_ub;
231 }

◆ widen_with()

void SVF::IntervalValue::widen_with ( const IntervalValue & other)
inline

Current IntervalValue widen with another IntervalValue.

Definition at line 440 of file IntervalValue.h.

441 {
442 if (this->isBottom())
443 {
444 this->_lb = other._lb;
445 this->_ub = other._ub;
446 }
447 else if (other.isBottom())
448 {
449 return;
450 }
451 else
452 {
453 setValue(!lb().leq(other.lb()) ? minus_infinity() : this->lb(), !ub().geq(other.ub()) ? plus_infinity() : this->ub());
454 }
455 }
bool leq(const IntervalValue &other) const
bool geq(const IntervalValue &other) const

◆ operator&

IntervalValue operator& ( const IntervalValue & lhs,
const IntervalValue & rhs )
friend

Bitwise AND of IntervalValues.

Definition at line 951 of file IntervalValue.h.

952{
953 if (lhs.isBottom() || rhs.isBottom())
954 return IntervalValue::bottom();
955 else if (lhs.is_numeral() && rhs.is_numeral())
956 {
957 return IntervalValue(lhs.lb() & rhs.lb());
958 }
959 else if (lhs.lb().getNumeral() >= 0 && rhs.lb().getNumeral() >= 0)
960 {
961 return IntervalValue((s64_t) 0, min(lhs.ub(), rhs.ub()));
962 }
963 else if (lhs.lb().getNumeral() >= 0)
964 {
965 return IntervalValue((s64_t) 0, lhs.ub());
966 }
967 else if (rhs.lb().getNumeral() >= 0)
968 {
969 return IntervalValue((s64_t) 0, rhs.ub());
970 }
971 else
972 {
973 return IntervalValue::top();
974 }
975}

◆ operator*

IntervalValue operator* ( const IntervalValue & lhs,
const IntervalValue & rhs )
friend

Multiply IntervalValues.

Definition at line 585 of file IntervalValue.h.

587{
588 if (lhs.isBottom() || rhs.isBottom())
589 {
590 return IntervalValue::bottom();
591 }
592 else
593 {
594 BoundedInt ll = lhs.lb() * rhs.lb();
595 BoundedInt lu = lhs.lb() * rhs.ub();
596 BoundedInt ul = lhs.ub() * rhs.lb();
597 BoundedInt uu = lhs.ub() * rhs.ub();
598 std::vector<BoundedInt> vec{ll, lu, ul, uu};
599 return IntervalValue(BoundedInt::min(vec),
600 BoundedInt::max(vec));
601 }
602}
friend BoundedInt max(const BoundedInt &lhs, const BoundedInt &rhs)
friend BoundedInt min(const BoundedInt &lhs, const BoundedInt &rhs)

◆ operator+

IntervalValue operator+ ( const IntervalValue & lhs,
const IntervalValue & rhs )
friend

Add IntervalValues.

Definition at line 549 of file IntervalValue.h.

551{
552 if (lhs.isBottom() || rhs.isBottom())
553 {
554 return IntervalValue::bottom();
555 }
556 else if (lhs.isTop() || rhs.isTop())
557 {
558 return IntervalValue::top();
559 }
560 else
561 {
562 return IntervalValue(lhs.lb() + rhs.lb(), lhs.ub() + rhs.ub());
563 }
564}

◆ operator-

IntervalValue operator- ( const IntervalValue & lhs,
const IntervalValue & rhs )
friend

Subtract IntervalValues.

Definition at line 567 of file IntervalValue.h.

569{
570 if (lhs.isBottom() || rhs.isBottom())
571 {
572 return IntervalValue::bottom();
573 }
574 else if (lhs.isTop() || rhs.isTop())
575 {
576 return IntervalValue::top();
577 }
578 else
579 {
580 return IntervalValue(lhs.lb() - rhs.ub(), lhs.ub() - rhs.lb());
581 }
582}

◆ operator/

IntervalValue operator/ ( const IntervalValue & lhs,
const IntervalValue & rhs )
friend

Divide IntervalValues.

Definition at line 605 of file IntervalValue.h.

607{
608 if (lhs.isBottom() || rhs.isBottom())
609 {
610 return IntervalValue::bottom();
611 }
612 else if (rhs.contains(0))
613 {
614 IntervalValue lb = IntervalValue::create(rhs.lb(), -1);
616 IntervalValue l_res = lhs / lb;
617 IntervalValue r_res = lhs / ub;
618 l_res.join_with(r_res);
619 return l_res;
620 }
621 else if (lhs.contains(0))
622 {
623 IntervalValue lb = IntervalValue::create(lhs.lb(), -1);
625 IntervalValue l_res = lb / rhs;
626 IntervalValue r_res = ub / rhs;
627 l_res.join_with(r_res);
628 l_res.join_with(IntervalValue(0));
629 return l_res;
630 }
631 else
632 {
633 // Neither the dividend nor the divisor contains 0
634 BoundedInt ll = lhs.lb() / rhs.lb();
635 BoundedInt lu = lhs.lb() / rhs.ub();
636 BoundedInt ul = lhs.ub() / rhs.lb();
637 BoundedInt uu = lhs.ub() / rhs.ub();
638 std::vector<BoundedInt> vec{ll, lu, ul, uu};
639
641 BoundedInt::max(vec));
642 return res;
643 }
644}
static IntervalValue create(const BoundedInt &lb, const BoundedInt &ub)

◆ operator<<

IntervalValue operator<< ( const IntervalValue & lhs,
const IntervalValue & rhs )
friend

Left binary shift of IntervalValues.

Definition at line 890 of file IntervalValue.h.

891{
892 if (lhs.isBottom() || rhs.isBottom())
893 return IntervalValue::bottom();
894 if (lhs.isTop() && rhs.isTop())
895 return IntervalValue::top();
896 else
897 {
898 IntervalValue shift = rhs;
899 shift.meet_with(IntervalValue(0, IntervalValue::plus_infinity()));
900 if (shift.isBottom())
901 return IntervalValue::bottom();
902 // Zero stays zero for any admitted shift, even an unbounded one.
903 if (lhs.equals(IntervalValue(0)))
904 return lhs;
905 // 1 << 31 overflows a signed 32-bit coefficient and may create an
906 // invalid interval whose lower bound is greater than its upper bound.
907 if (shift.ub().is_infinity() || shift.ub().getIntNumeral() >= 31)
908 return IntervalValue::top();
909 const s32_t low = static_cast<s32_t>(shift.lb().getIntNumeral());
910 const s32_t high = static_cast<s32_t>(shift.ub().getIntNumeral());
911 return lhs * IntervalValue(s64_t(1) << low, s64_t(1) << high);
912 }
913}
s64_t getIntNumeral() const
signed s32_t
Definition GeneralType.h:68

◆ operator>>

IntervalValue operator>> ( const IntervalValue & lhs,
const IntervalValue & rhs )
friend

Left binary shift of IntervalValues.

Definition at line 916 of file IntervalValue.h.

917{
918 if (lhs.isBottom() || rhs.isBottom())
919 return IntervalValue::bottom();
920 else if (lhs.isTop() && rhs.isTop())
921 return IntervalValue::top();
922 else
923 {
924 IntervalValue shift = rhs;
925 shift.meet_with(IntervalValue(0, IntervalValue::plus_infinity()));
926 if (shift.isBottom())
927 return IntervalValue::bottom();
928 if (lhs.contains(0))
929 {
930 IntervalValue l = IntervalValue::create(lhs.lb(), -1);
931 IntervalValue u = IntervalValue::create(1, lhs.ub());
932 IntervalValue tmp = l >> rhs;
933 tmp.join_with(u >> rhs);
934 tmp.join_with(IntervalValue(0));
935 return tmp;
936 }
937 else
938 {
939 BoundedInt ll = lhs.lb() >> shift.lb();
940 BoundedInt lu = lhs.lb() >> shift.ub();
941 BoundedInt ul = lhs.ub() >> shift.lb();
942 BoundedInt uu = lhs.ub() >> shift.ub();
943 std::vector<BoundedInt> vec{ll, lu, ul, uu};
944 return IntervalValue(BoundedInt::min(vec),
945 BoundedInt::max(vec));
946 }
947 }
948}

◆ operator^

IntervalValue operator^ ( const IntervalValue & lhs,
const IntervalValue & rhs )
friend

Bitwise XOR of IntervalValues.

Definition at line 1007 of file IntervalValue.h.

1008{
1009 auto next_power_of_2 = [](s64_t num)
1010 {
1011 int i = 1;
1012 while ((num >> i) != 0)
1013 {
1014 ++i;
1015 }
1016 return 1 << i;
1017 };
1018 if (lhs.isBottom() || rhs.isBottom())
1019 return IntervalValue::bottom();
1020 else if (lhs.is_numeral() && rhs.is_numeral())
1021 return IntervalValue(lhs.lb() ^ rhs.lb());
1022 else if (lhs.lb().getNumeral() >= 0 && !lhs.ub().is_infinity() &&
1023 rhs.lb().getNumeral() >= 0 && !rhs.ub().is_infinity())
1024 {
1025 s64_t m = std::max(lhs.ub().getNumeral(), rhs.ub().getNumeral());
1026 s64_t ub = next_power_of_2(s64_t(m)) - 1;
1027 return IntervalValue((s64_t) 0, (s64_t) ub);
1028 }
1029 else
1030 {
1031 return IntervalValue::top();
1032 }
1033}

◆ operator|

IntervalValue operator| ( const IntervalValue & lhs,
const IntervalValue & rhs )
friend

Bitwise OR of IntervalValues.

Definition at line 978 of file IntervalValue.h.

979{
980 auto next_power_of_2 = [](s64_t num)
981 {
982 int i = 1;
983 while ((num >> i) != 0)
984 {
985 ++i;
986 }
987 return 1 << i;
988 };
989 if (lhs.isBottom() || rhs.isBottom())
990 return IntervalValue::bottom();
991 else if (lhs.is_numeral() && rhs.is_numeral())
992 return IntervalValue(lhs.lb() | rhs.lb());
993 else if (lhs.lb().getNumeral() >= 0 && !lhs.ub().is_infinity() &&
994 rhs.lb().getNumeral() >= 0 && !rhs.ub().is_infinity())
995 {
996 s64_t m = std::max(lhs.ub().getNumeral(), rhs.ub().getNumeral());
997 s64_t ub = next_power_of_2(s64_t(m)) - 1;
998 return IntervalValue((s64_t) 0, (s64_t) ub);
999 }
1000 else
1001 {
1002 return IntervalValue::top();
1003 }
1004}

Member Data Documentation

◆ _lb

BoundedInt SVF::IntervalValue::_lb
private

Definition at line 49 of file IntervalValue.h.

◆ _ub

BoundedInt SVF::IntervalValue::_ub
private

Definition at line 52 of file IntervalValue.h.


The documentation for this class was generated from the following file: