# HG changeset patch # User Michael Pavone # Date 1548825999 28800 # Node ID 87d4f0b4bf1da91ea947cdd3cd7e30d6bbb1e9e0 # Parent 2344b3650b386fbdd3d98cea55c2e3eb0abc8ec7 Actually correct overflow flag calculation in CPU DSL diff -r 2344b3650b38 -r 87d4f0b4bf1d cpu_dsl.py --- a/cpu_dsl.py Mon Jan 28 22:56:43 2019 -0800 +++ b/cpu_dsl.py Tue Jan 29 21:26:39 2019 -0800 @@ -241,7 +241,7 @@ dst = prog.carryFlowDst = name prog.lastA = a prog.lastB = b - prog.lastBFlow = '(-' + b + ')' if op == '-' else b + prog.lastBFlow = b if op == '-' else '(~{b})'.format(b=b) else: dst = params[2] return decl + '\n\t{dst} = {a} {op} {b};'.format( @@ -316,7 +316,7 @@ 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.lastBFlow, 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: @@ -440,8 +440,8 @@ decl,name = prog.getTemp(size) dst = prog.carryFlowDst = name prog.lastA = params[0] - prog.lastB = '({b} ^ ({check} ? 1 : 0))'.format(b = params[1], check = carryCheck) - prog.lastBFlow = prog.lastB + prog.lastB = '({b} + ({check} ? 1 : 0))'.format(b = params[1], check = carryCheck) + prog.lastBFlow = '(~{b})'.format(b=params[1]) else: dst = params[2] return decl + '\n\t{dst} = {a} + {b} + ({check} ? 1 : 0);'.format(dst = dst, @@ -469,7 +469,7 @@ dst = prog.carryFlowDst = name prog.lastA = params[1] prog.lastB = '({b} ^ ({check} ? 1 : 0))'.format(b = params[0], check = carryCheck) - prog.lastBFlow = '((-{b}) ^ ({check} ? -1 : 0))'.format(b = params[0], check = carryCheck) + prog.lastBFlow = params[0] else: dst = params[2] return decl + '\n\t{dst} = {b} - {a} - ({check} ? 1 : 0);'.format(dst = dst,