Mercurial > repos > blastem
comparison cpu_dsl.py @ 1713:0264d8b288e2
Implement parity flag calculation type
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 29 Jan 2019 22:16:57 -0800 |
parents | 87d4f0b4bf1d |
children | 4fd84c3efc72 |
comparison
equal
deleted
inserted
replaced
1712:0a9a88b3d061 | 1713:0264d8b288e2 |
---|---|
294 return '\n\timpl_{tbl}[{op}](context);'.format(tbl = table, op = params[0]) | 294 return '\n\timpl_{tbl}[{op}](context);'.format(tbl = table, op = params[0]) |
295 | 295 |
296 def _updateFlagsCImpl(prog, params, rawParams): | 296 def _updateFlagsCImpl(prog, params, rawParams): |
297 autoUpdate, explicit = prog.flags.parseFlagUpdate(params[0]) | 297 autoUpdate, explicit = prog.flags.parseFlagUpdate(params[0]) |
298 output = [] | 298 output = [] |
299 #TODO: handle autoUpdate flags | 299 parity = None |
300 for flag in autoUpdate: | 300 for flag in autoUpdate: |
301 calc = prog.flags.flagCalc[flag] | 301 calc = prog.flags.flagCalc[flag] |
302 calc,_,resultBit = calc.partition('-') | 302 calc,_,resultBit = calc.partition('-') |
303 if prog.carryFlowDst: | 303 if prog.carryFlowDst: |
304 lastDst = prog.carryFlowDst | 304 lastDst = prog.carryFlowDst |
351 reg = prog.resolveParam(storage, None, {}) | 351 reg = prog.resolveParam(storage, None, {}) |
352 output.append('\n\t{reg} = {res} == 0;'.format( | 352 output.append('\n\t{reg} = {res} == 0;'.format( |
353 reg = reg, res = lastDst | 353 reg = reg, res = lastDst |
354 )) | 354 )) |
355 elif calc == 'parity': | 355 elif calc == 'parity': |
356 pass | 356 parity = storage |
357 paritySize = prog.paramSize(prog.lastDst) | |
358 if prog.carryFlowDst: | |
359 parityDst = paritySrc = prog.carryFlowDst | |
360 else: | |
361 paritySrc = lastDst | |
362 decl,name = prog.getTemp(paritySize) | |
363 output.append(decl) | |
364 parityDst = name | |
357 else: | 365 else: |
358 raise Exception('Unknown flag calc type: ' + calc) | 366 raise Exception('Unknown flag calc type: ' + calc) |
359 if prog.carryFlowDst: | 367 if prog.carryFlowDst: |
360 output.append('\n\t{dst} = {tmpdst};'.format(dst = prog.resolveParam(prog.lastDst, None, {}), tmpdst = prog.carryFlowDst)) | 368 output.append('\n\t{dst} = {tmpdst};'.format(dst = prog.resolveParam(prog.lastDst, None, {}), tmpdst = prog.carryFlowDst)) |
361 prog.carryFlowDst = None | 369 prog.carryFlowDst = None |
370 if parity: | |
371 if paritySize > 8: | |
372 if paritySize > 16: | |
373 output.append('\n\t{dst} = {src} ^ ({src} >> 16);'.format(dst=parityDst, src=paritySrc)) | |
374 paritySrc = parityDst | |
375 output.append('\n\t{dst} = {src} ^ ({src} >> 8);'.format(dst=parityDst, src=paritySrc)) | |
376 paritySrc = parityDst | |
377 output.append('\n\t{dst} = ({src} ^ ({src} >> 4)) & 0xF;'.format(dst=parityDst, src=paritySrc)) | |
378 if type(parity) is tuple: | |
379 reg,bit = parity | |
380 reg = prog.resolveParam(reg, None, {}) | |
381 output.append('\n\t{flag} = ({flag} & ~{mask}U) | ((0x6996 >> {parity}) << {bit} & {mask}U);'.format( | |
382 flag=reg, mask = 1 << bit, bit = bit, parity = parityDst | |
383 )) | |
384 else: | |
385 reg = prog.resolveParam(parity, None, {}) | |
386 output.append('\n\t{flag} = 0x9669 >> {parity} & 1;'.format(flag=reg, parity=parityDst)) | |
387 | |
362 #TODO: combine explicit flags targeting the same storage location | 388 #TODO: combine explicit flags targeting the same storage location |
363 for flag in explicit: | 389 for flag in explicit: |
364 location = prog.flags.getStorage(flag) | 390 location = prog.flags.getStorage(flag) |
365 if type(location) is tuple: | 391 if type(location) is tuple: |
366 reg,bit = location | 392 reg,bit = location |