Mercurial > repos > blastem
comparison cpu_dsl.py @ 2562:595719fe69f2
Implement exg, muls and mulu in new 68K core
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 25 Jan 2025 21:25:01 -0800 |
parents | ad50530a7c27 |
children | 5f725429d08f |
comparison
equal
deleted
inserted
replaced
2561:8dc8eb079584 | 2562:595719fe69f2 |
---|---|
13 binaryOps = { | 13 binaryOps = { |
14 '+': 'add', | 14 '+': 'add', |
15 '-': 'sub', | 15 '-': 'sub', |
16 '<<': 'lsl', | 16 '<<': 'lsl', |
17 '>>': 'lsr', | 17 '>>': 'lsr', |
18 '*': 'mulu', | |
19 '*S': 'muls', | |
18 '&': 'and', | 20 '&': 'and', |
19 '|': 'or', | 21 '|': 'or', |
20 '^': 'xor' | 22 '^': 'xor' |
21 } | 23 } |
22 unaryOps = { | 24 unaryOps = { |
749 fmt = '\n\t{dst} = {src} & 0x80 ? {src} | 0xFF00 : {src} & 0x7F;' | 751 fmt = '\n\t{dst} = {src} & 0x80 ? {src} | 0xFF00 : {src} & 0x7F;' |
750 else: | 752 else: |
751 fmt = '\n\t{dst} = {src} & 0x8000 ? {src} | 0xFFFF0000 : {src} & 0x7FFF;' | 753 fmt = '\n\t{dst} = {src} & 0x8000 ? {src} | 0xFFFF0000 : {src} & 0x7FFF;' |
752 prog.lastSize = params[0] | 754 prog.lastSize = params[0] |
753 return fmt.format(src=params[1], dst=params[2]) | 755 return fmt.format(src=params[1], dst=params[2]) |
756 | |
757 def _mulsCImpl(prog, params, rawParams, flagUpdates): | |
758 p0Size = prog.paramSize(rawParams[0]) | |
759 p1Size = prog.paramSize(rawParams[1]) | |
760 destSize = prog.paramSize(rawParams[2]) | |
761 if len(params) > 3: | |
762 size = params[3] | |
763 if size == 0: | |
764 size = 8 | |
765 elif size == 1: | |
766 size = 16 | |
767 else: | |
768 size = 32 | |
769 prog.lastSize = size | |
770 else: | |
771 size = destSize | |
772 if p0Size >= size: | |
773 p0Size = size // 2 | |
774 if p1Size >= size: | |
775 p1Size = size // 2 | |
776 #TODO: Handle case in which destSize > size | |
777 return f'\n\t{params[2]} = (int{size}_t)(((int{p0Size}_t){params[0]}) * ((int{p1Size}_t){params[1]}));' | |
778 | |
779 def _muluCImpl(prog, params, rawParams, flagUpdates): | |
780 p0Size = prog.paramSize(rawParams[0]) | |
781 p1Size = prog.paramSize(rawParams[1]) | |
782 destSize = prog.paramSize(rawParams[2]) | |
783 if len(params) > 3: | |
784 size = params[3] | |
785 if size == 0: | |
786 size = 8 | |
787 elif size == 1: | |
788 size = 16 | |
789 else: | |
790 size = 32 | |
791 prog.lastSize = size | |
792 else: | |
793 size = destSize | |
794 if p0Size >= size: | |
795 p0Size = size // 2 | |
796 if p1Size >= size: | |
797 p1Size = size // 2 | |
798 #TODO: Handle case in which destSize > size | |
799 return f'\n\t{params[2]} = ((uint{p0Size}_t){params[0]}) * ((uint{p1Size}_t){params[1]});' | |
754 | 800 |
755 def _getCarryCheck(prog): | 801 def _getCarryCheck(prog): |
756 carryFlag = None | 802 carryFlag = None |
757 for flag in prog.flags.flagOrder: | 803 for flag in prog.flags.flagOrder: |
758 if prog.flags.flagCalc[flag] == 'carry': | 804 if prog.flags.flagCalc[flag] == 'carry': |
954 'asr': Op(lambda a, b: a >> b).addImplementation('c', 2, _asrCImpl), | 1000 'asr': Op(lambda a, b: a >> b).addImplementation('c', 2, _asrCImpl), |
955 'rol': Op().addImplementation('c', 2, _rolCImpl), | 1001 'rol': Op().addImplementation('c', 2, _rolCImpl), |
956 'rlc': Op().addImplementation('c', 2, _rlcCImpl), | 1002 'rlc': Op().addImplementation('c', 2, _rlcCImpl), |
957 'ror': Op().addImplementation('c', 2, _rorCImpl), | 1003 'ror': Op().addImplementation('c', 2, _rorCImpl), |
958 'rrc': Op().addImplementation('c', 2, _rrcCImpl), | 1004 'rrc': Op().addImplementation('c', 2, _rrcCImpl), |
1005 'mulu': Op(lambda a, b: a * b).addImplementation('c', 2, _muluCImpl), | |
1006 'muls': Op().addImplementation('c', 2, _mulsCImpl), | |
959 'and': Op(lambda a, b: a & b).cBinaryOperator('&'), | 1007 'and': Op(lambda a, b: a & b).cBinaryOperator('&'), |
960 'or': Op(lambda a, b: a | b).cBinaryOperator('|'), | 1008 'or': Op(lambda a, b: a | b).cBinaryOperator('|'), |
961 'xor': Op(lambda a, b: a ^ b).cBinaryOperator('^'), | 1009 'xor': Op(lambda a, b: a ^ b).cBinaryOperator('^'), |
962 'abs': Op(lambda val: abs(val)).addImplementation( | 1010 'abs': Op(lambda val: abs(val)).addImplementation( |
963 'c', 1, lambda prog, params: '\n\t{dst} = abs({src});'.format(dst=params[1], src=params[0]) | 1011 'c', 1, lambda prog, params: '\n\t{dst} = abs({src});'.format(dst=params[1], src=params[0]) |
1094 self.default = None | 1142 self.default = None |
1095 self.default_locals = None | 1143 self.default_locals = None |
1096 | 1144 |
1097 def addOp(self, op): | 1145 def addOp(self, op): |
1098 if op.op == 'case': | 1146 if op.op == 'case': |
1099 val = int(op.params[0], 16) if op.params[0].startswith('0x') else int(op.params[0]) | 1147 if op.params[0].startswith('0x'): |
1148 val = int(op.params[0], 16) | |
1149 elif op.params[0].startswith('0b'): | |
1150 val = int(op.params[0], 2) | |
1151 else: | |
1152 val = int(op.params[0]) | |
1100 self.cases[val] = self.current_case = [] | 1153 self.cases[val] = self.current_case = [] |
1101 self.case_locals[val] = self.current_locals = {} | 1154 self.case_locals[val] = self.current_locals = {} |
1102 elif op.op == 'default': | 1155 elif op.op == 'default': |
1103 self.default = self.current_case = [] | 1156 self.default = self.current_case = [] |
1104 self.default_locals = self.current_locals = {} | 1157 self.default_locals = self.current_locals = {} |
1775 try: | 1828 try: |
1776 if type(param) is int: | 1829 if type(param) is int: |
1777 pass | 1830 pass |
1778 elif param.startswith('0x'): | 1831 elif param.startswith('0x'): |
1779 param = int(param, 16) | 1832 param = int(param, 16) |
1833 elif param.startswith('0b'): | |
1834 param = int(param, 2) | |
1780 else: | 1835 else: |
1781 param = int(param) | 1836 param = int(param) |
1782 except ValueError: | 1837 except ValueError: |
1783 | 1838 |
1784 if parent: | 1839 if parent: |