From 8e5cb9d205e58ed143f058e0305748f363d440db Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Mon, 28 Jan 2019 21:15:27 -0800 Subject: Initial stab at overflow flag implementation in CPU DSL. Probably broken for subtraction --- cpu_dsl.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'cpu_dsl.py') diff --git a/cpu_dsl.py b/cpu_dsl.py index 6401827..e836e08 100755 --- a/cpu_dsl.py +++ b/cpu_dsl.py @@ -304,7 +304,7 @@ def _updateFlagsCImpl(prog, params, rawParams): else: lastDst = prog.resolveParam(prog.lastDst, None, {}) storage = prog.flags.getStorage(flag) - if calc == 'bit' or calc == 'sign' or calc == 'carry' or calc == 'half': + if calc == 'bit' or calc == 'sign' or calc == 'carry' or calc == 'half' or calc == 'overflow': myRes = lastDst if calc == 'sign': resultBit = prog.paramSize(prog.lastDst) - 1 @@ -313,6 +313,9 @@ def _updateFlagsCImpl(prog, params, rawParams): elif calc == 'half': resultBit = 4 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) else: resultBit = int(resultBit) if type(storage) is tuple: @@ -347,9 +350,7 @@ def _updateFlagsCImpl(prog, params, rawParams): reg = prog.resolveParam(storage, None, {}) output.append('\n\t{reg} = {res} == 0;'.format( reg = reg, res = lastDst - )) - elif calc == 'overflow': - pass + )) elif calc == 'parity': pass else: -- cgit v1.2.3