Mercurial > repos > blastem
comparison cpu_dsl.py @ 2451:edd73a009537
Fix implementation of cmp for 32-bit operands or when operation size is smaller than the size of the operands
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 19 Feb 2024 17:55:45 -0800 |
parents | d1eec03dca09 |
children | 8b3daed1c076 |
comparison
equal
deleted
inserted
replaced
2450:6c93869babc1 | 2451:edd73a009537 |
---|---|
619 reg = prog.resolveReg(location, None, {}) | 619 reg = prog.resolveReg(location, None, {}) |
620 output.append('\n\t{reg} = {val};'.format(reg=reg, val=explicit[flag])) | 620 output.append('\n\t{reg} = {val};'.format(reg=reg, val=explicit[flag])) |
621 return ''.join(output) | 621 return ''.join(output) |
622 | 622 |
623 def _cmpCImpl(prog, params, rawParams, flagUpdates): | 623 def _cmpCImpl(prog, params, rawParams, flagUpdates): |
624 size = prog.paramSize(rawParams[1]) | 624 b_size = size = prog.paramSize(rawParams[1]) |
625 needsCarry = False | 625 needsCarry = False |
626 if flagUpdates: | 626 if flagUpdates: |
627 for flag in flagUpdates: | 627 for flag in flagUpdates: |
628 calc = prog.flags.flagCalc[flag] | 628 calc = prog.flags.flagCalc[flag] |
629 if calc == 'carry': | 629 if calc == 'carry': |
630 needsCarry = True | 630 needsCarry = True |
631 break | 631 break |
632 if len(params) > 2: | |
633 size = params[2] | |
634 if size == 0: | |
635 size = 8 | |
636 elif size == 1: | |
637 size = 16 | |
638 else: | |
639 size = 32 | |
640 prog.lastSize = size | |
632 if needsCarry: | 641 if needsCarry: |
633 size *= 2 | 642 size *= 2 |
634 tmpvar = 'cmp_tmp{sz}__'.format(sz=size) | 643 tmpvar = 'cmp_tmp{sz}__'.format(sz=size) |
635 if flagUpdates: | 644 if flagUpdates: |
636 prog.carryFlowDst = tmpvar | 645 prog.carryFlowDst = tmpvar |
639 prog.lastBFlow = params[0] | 648 prog.lastBFlow = params[0] |
640 scope = prog.getRootScope() | 649 scope = prog.getRootScope() |
641 if not scope.resolveLocal(tmpvar): | 650 if not scope.resolveLocal(tmpvar): |
642 scope.addLocal(tmpvar, size) | 651 scope.addLocal(tmpvar, size) |
643 prog.lastDst = rawParams[1] | 652 prog.lastDst = rawParams[1] |
644 if len(params) > 2: | 653 a = params[0] |
645 size = params[2] | 654 b = params[1] |
646 if size == 0: | 655 a_size = prog.paramSize(rawParams[0]) |
647 size = 8 | 656 if prog.lastSize != a_size: |
648 elif size == 1: | 657 a = '(({a}) & {mask})'.format(a = a, mask = (1 << prog.lastSize) - 1) |
649 size = 16 | 658 if prog.lastSize != b_size: |
650 else: | 659 b = '(({b}) & {mask})'.format(b = b, mask = (1 << prog.lastSize) - 1) |
651 size = 32 | 660 if size == 64: |
652 prog.lastSize = size | 661 a = '((uint64_t){a})'.format(a = a) |
653 else: | 662 b = '((uint64_t){b})'.format(b = b) |
654 prog.lastSize = None | 663 return '\n\t{var} = {b} - {a};'.format(var = tmpvar, a = a, b = b) |
655 return '\n\t{var} = {b} - {a};'.format(var = tmpvar, a = params[0], b = params[1]) | |
656 | 664 |
657 def _asrCImpl(prog, params, rawParams, flagUpdates): | 665 def _asrCImpl(prog, params, rawParams, flagUpdates): |
658 needsCarry = False | 666 needsCarry = False |
659 if flagUpdates: | 667 if flagUpdates: |
660 for flag in flagUpdates: | 668 for flag in flagUpdates: |