# HG changeset patch # User Michael Pavone # Date 1548743866 28800 # Node ID 5bfed2eedc9d239ba97098f1aa184de087c21edc # Parent a16088324f3037c3aebbf811deb7bb3b81435b8d Fixed flag calculation for sub instructions in CPU DSL diff -r a16088324f30 -r 5bfed2eedc9d cpu_dsl.py --- a/cpu_dsl.py Mon Jan 28 21:30:23 2019 -0800 +++ b/cpu_dsl.py Mon Jan 28 22:37:46 2019 -0800 @@ -240,8 +240,8 @@ decl,name = prog.getTemp(size) dst = prog.carryFlowDst = name prog.lastA = a - prog.lastB = '(-' + b + ')' if op == '-' else b - prog.lastWasSub = op == '-' + prog.lastB = b + prog.lastBFlow = '(-' + b + ')' if op == '-' else b else: dst = params[2] return decl + '\n\t{dst} = {a} {op} {b};'.format( @@ -313,11 +313,10 @@ resultBit = prog.paramSize(prog.lastDst) elif calc == 'half': resultBit = 4 - fmt = '({a} ^ {b} ^ ~{res})' if prog.lastWasSub else '({a} ^ {b} ^ {res})' - myRes = fmt.format(a = prog.lastA, b = prog.lastB, res = lastDst) + myRes = '({a} ^ {b} ^ {res})'.format(a = prog.lastA, b = prog.lastB, res = lastDst) elif calc == 'overflow': resultBit = prog.paramSize(prog.lastDst) - 1 - myRes = '((~({a} ^ {b})) & ({a} ^ {res}))'.format(a = prog.lastA, b = prog.lastB, res = lastDst) + myRes = '((~({a} ^ {b})) & ({a} ^ {res}))'.format(a = prog.lastA, b = prog.lastBFlow, res = lastDst) else: resultBit = int(resultBit) if type(storage) is tuple: @@ -991,7 +990,7 @@ self.carryFlowDst = None self.lastA = None self.lastB = None - self.lastWasSub = False + self.lastBFlow = None def __str__(self): pieces = []