From 2bee2db148af8d6a77b5aeefb8fc061f2a502452 Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Tue, 17 Oct 2017 23:59:41 +0200 Subject: [PATCH] Remove duplicate check for '|' Removed the 'if' and applied an indentation change; no further changes are done. --- lslopt/lslfoldconst.py | 79 +++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 40 deletions(-) diff --git a/lslopt/lslfoldconst.py b/lslopt/lslfoldconst.py index a241f28..99939ec 100644 --- a/lslopt/lslfoldconst.py +++ b/lslopt/lslfoldconst.py @@ -348,48 +348,47 @@ class foldconst(object): del val1, val2 del a, b, c, d, and1, and2 - if nt == '|': - # Absorb further flags, to allow chaining of && - # If ~r and s are constants, and s is a power of two: - # (!~(x|~r) && x&s) -> !~(x|(~r&~s)) - # This is implemented as: - # ~(x|~r) | !(x&s) -> ~(x|~(r|s)) - # because that's the intermediate result after conversion of &&. - # a and b are going to be the children of the main | - # a is going to be child that has the ~ - # b is the other child (with the !) - # c is the child of ~ which has x - # d is the child of ~ with the constant ~r - # e is the child of ! which has x - # f is the child of ! with the constant s - a, b = 0, 1 - if child[a]['nt'] != '~': - a, b = b, a - c, d = 0, 1 - if child[a]['nt'] == '~' and child[a]['ch'][0]['nt'] == '|': - if child[a]['ch'][0]['ch'][d]['nt'] != 'CONST': - c, d = d, c - e, f = 0, 1 - if child[b]['nt'] == '!' and child[b]['ch'][0]['nt'] == '&': - if child[b]['ch'][0]['ch'][f]['nt'] != 'CONST': - e, f = f, e - # All pointers are ready to check applicability. - if (child[a]['nt'] == '~' and child[a]['ch'][0]['nt'] == '|' - and child[b]['nt'] == '!' and child[b]['ch'][0]['nt'] == '&' + # Absorb further flags, to allow chaining of && + # If ~r and s are constants, and s is a power of two: + # (!~(x|~r) && x&s) -> !~(x|(~r&~s)) + # This is implemented as: + # ~(x|~r) | !(x&s) -> ~(x|~(r|s)) + # because that's the intermediate result after conversion of &&. + # a and b are going to be the children of the main | + # a is going to be child that has the ~ + # b is the other child (with the !) + # c is the child of ~ which has x + # d is the child of ~ with the constant ~r + # e is the child of ! which has x + # f is the child of ! with the constant s + a, b = 0, 1 + if child[a]['nt'] != '~': + a, b = b, a + c, d = 0, 1 + if child[a]['nt'] == '~' and child[a]['ch'][0]['nt'] == '|': + if child[a]['ch'][0]['ch'][d]['nt'] != 'CONST': + c, d = d, c + e, f = 0, 1 + if child[b]['nt'] == '!' and child[b]['ch'][0]['nt'] == '&': + if child[b]['ch'][0]['ch'][f]['nt'] != 'CONST': + e, f = f, e + # All pointers are ready to check applicability. + if (child[a]['nt'] == '~' and child[a]['ch'][0]['nt'] == '|' + and child[b]['nt'] == '!' and child[b]['ch'][0]['nt'] == '&' + ): + ch1 = child[a]['ch'][0]['ch'] + ch2 = child[b]['ch'][0]['ch'] + if (ch1[d]['nt'] == 'CONST' and ch2[f]['nt'] == 'CONST' + and (ch2[f]['value'] & (ch2[f]['value'] - 1)) == 0 ): - ch1 = child[a]['ch'][0]['ch'] - ch2 = child[b]['ch'][0]['ch'] - if (ch1[d]['nt'] == 'CONST' and ch2[f]['nt'] == 'CONST' - and (ch2[f]['value'] & (ch2[f]['value'] - 1)) == 0 - ): - if self.CompareTrees(ch1[c], ch2[e]): - # We're in that case. Apply optimization. - parent[index] = child[a] - ch1[d]['value'] &= ~ch2[f]['value'] - return - del ch1, ch2 + if self.CompareTrees(ch1[c], ch2[e]): + # We're in that case. Apply optimization. + parent[index] = child[a] + ch1[d]['value'] &= ~ch2[f]['value'] + return + del ch1, ch2 - del a, b, c, d, e, f + del a, b, c, d, e, f # Check if the operands are a negation ('!') or can be inverted