comparison cpu_dsl.py @ 1705:9ab64ef5cba0

Initial stab at overflow flag implementation in CPU DSL. Probably broken for subtraction
author Michael Pavone <pavone@retrodev.com>
date Mon, 28 Jan 2019 21:15:27 -0800
parents 89932fd29abd
children a16088324f30
comparison
equal deleted inserted replaced
1704:89932fd29abd 1705:9ab64ef5cba0
302 if prog.carryFlowDst: 302 if prog.carryFlowDst:
303 lastDst = prog.carryFlowDst 303 lastDst = prog.carryFlowDst
304 else: 304 else:
305 lastDst = prog.resolveParam(prog.lastDst, None, {}) 305 lastDst = prog.resolveParam(prog.lastDst, None, {})
306 storage = prog.flags.getStorage(flag) 306 storage = prog.flags.getStorage(flag)
307 if calc == 'bit' or calc == 'sign' or calc == 'carry' or calc == 'half': 307 if calc == 'bit' or calc == 'sign' or calc == 'carry' or calc == 'half' or calc == 'overflow':
308 myRes = lastDst 308 myRes = lastDst
309 if calc == 'sign': 309 if calc == 'sign':
310 resultBit = prog.paramSize(prog.lastDst) - 1 310 resultBit = prog.paramSize(prog.lastDst) - 1
311 elif calc == 'carry': 311 elif calc == 'carry':
312 resultBit = prog.paramSize(prog.lastDst) 312 resultBit = prog.paramSize(prog.lastDst)
313 elif calc == 'half': 313 elif calc == 'half':
314 resultBit = 4 314 resultBit = 4
315 myRes = '({a} ^ {b} ^ {res})'.format(a = prog.lastA, b = prog.lastB, res = lastDst) 315 myRes = '({a} ^ {b} ^ {res})'.format(a = prog.lastA, b = prog.lastB, res = lastDst)
316 elif calc == 'overflow':
317 resultBit = prog.paramSize(prog.lastDst) - 1
318 myRes = '((~({a} ^ {b})) & ({a} ^ {res}))'.format(a = prog.lastA, b = prog.lastB, res = lastDst)
316 else: 319 else:
317 resultBit = int(resultBit) 320 resultBit = int(resultBit)
318 if type(storage) is tuple: 321 if type(storage) is tuple:
319 reg,storageBit = storage 322 reg,storageBit = storage
320 reg = prog.resolveParam(reg, None, {}) 323 reg = prog.resolveParam(reg, None, {})
345 )) 348 ))
346 else: 349 else:
347 reg = prog.resolveParam(storage, None, {}) 350 reg = prog.resolveParam(storage, None, {})
348 output.append('\n\t{reg} = {res} == 0;'.format( 351 output.append('\n\t{reg} = {res} == 0;'.format(
349 reg = reg, res = lastDst 352 reg = reg, res = lastDst
350 )) 353 ))
351 elif calc == 'overflow':
352 pass
353 elif calc == 'parity': 354 elif calc == 'parity':
354 pass 355 pass
355 else: 356 else:
356 raise Exception('Unknown flag calc type: ' + calc) 357 raise Exception('Unknown flag calc type: ' + calc)
357 if prog.carryFlowDst: 358 if prog.carryFlowDst: