Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve BackendConcrete is_true/is_false fast paths #574

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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