angr.analyses.decompiler.peephole_optimizations.magic_div_simplifier

class angr.analyses.decompiler.peephole_optimizations.magic_div_simplifier.MagicDivisionSimplifier

Bases: PeepholeOptimizationExprBase

Restore divisions by constants that compilers lower into shifts and multiply-high sequences:

  • (x + ((x >>a (n-1)) >> (n-k))) >>a k and (x + (x >> (n-1))) >>a 1 => x /s 2**k

  • x - ((x + <same bias>) & -2**k) => x %s 2**k

  • ((x + hi(x * M)) >>a s) - (x >>a (n-1)) and (hi(x * M) >>a s) - (x >>a (n-1)) => x /s d

  • hi(x * M) >> s => x /u d

where hi(x * M) is the upper half of a double-width product. Each candidate divisor is checked by evaluating the matched sequence on sample inputs.

NAME = 'Simplify divisions by constants lowered to shifts and multiply-high'
expr_classes = (<class 'angr.ailment.expression.BinaryOp'>, <class 'angr.ailment.expression.Convert'>)
optimize(expr, **kwargs)
Parameters:

expr (BinaryOp | Convert)