Skip to content

Commit

Permalink
Improve BackendConcrete is_true/is_false fast paths
Browse files Browse the repository at this point in the history
  • Loading branch information
twizmwazin committed Nov 19, 2024
1 parent c84f8d2 commit 580ea1c
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions claripy/backends/backend_concrete/backend_concrete.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from functools import reduce

import claripy
from claripy.ast import BV, Base, Bool
from claripy.ast import BV, Bool
from claripy.backends.backend import Backend
from claripy.backends.backend_concrete import bv, fp, strings
from claripy.errors import BackendError, UnsatError
Expand Down Expand Up @@ -195,21 +195,17 @@ def _solution(self, expr, v, extra_constraints=(), solver=None, model_callback=N

# Override Backend.is_true() for a better performance
def is_true(self, e, extra_constraints=(), solver=None, model_callback=None):
if e in {True, 1, 1.0}:
return True
if e in {False, 0, 0.0}:
return False
if type(e) is Base and e.op == "BoolV" and len(e.args) == 1 and e.args[0] is True:
if isinstance(e, numbers.Number):
return bool(e)
if e is claripy.true():
return True
return super().is_true(e, extra_constraints=extra_constraints, solver=solver, model_callback=model_callback)

# Override Backend.is_false() for a better performance
def is_false(self, e, extra_constraints=(), solver=None, model_callback=None):
if e in {False, 0, 0.0}:
return True
if e in {True, 1, 1.0}:
return False
if type(e) is Base and e.op == "BoolV" and len(e.args) == 1 and e.args[0] is False:
if isinstance(e, numbers.Number):
return not bool(e)
if e is claripy.false():
return True
return super().is_false(e, extra_constraints=extra_constraints, solver=solver, model_callback=model_callback)

Expand Down

0 comments on commit 580ea1c

Please sign in to comment.