Mercurial > repos > blastem
comparison cpu_dsl.py @ 2610:2de52352936c
Fix lsl in new CPU core and make asl less broken
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 15 Feb 2025 19:11:40 -0800 |
parents | fbb5115b1a27 |
children | 9bd90cd94000 |
comparison
equal
deleted
inserted
replaced
2609:fbb5115b1a27 | 2610:2de52352936c |
---|---|
540 myRes = lastDst | 540 myRes = lastDst |
541 after = '' | 541 after = '' |
542 if calc == 'sign': | 542 if calc == 'sign': |
543 resultBit = prog.getLastSize() - 1 | 543 resultBit = prog.getLastSize() - 1 |
544 elif calc == 'carry': | 544 elif calc == 'carry': |
545 if prog.lastOp.op in ('asr', 'lsr', 'rrc'): | 545 if prog.lastOp.op in ('asr', 'lsr', 'rrc', 'rlc'): |
546 if type(prog.lastB) is int: | 546 if type(prog.lastB) is int: |
547 if prog.lastB == 0: | 547 if prog.lastB == 0: |
548 explicit[flag] = 0 | 548 explicit[flag] = 0 |
549 continue | 549 continue |
550 elif prog.lastOp.op == 'rlc': | |
551 resultBit = prog.getLastSize() - prog.lastB | |
550 else: | 552 else: |
551 resultBit = prog.lastB - 1 | 553 resultBit = prog.lastB - 1 |
552 else: | 554 else: |
553 output.append(f'\n\tif (!{prog.lastB}) {{') | 555 output.append(f'\n\tif (!{prog.lastB}) {{') |
554 _addExplicitFlagSet(prog, output, flag, 0) | 556 _addExplicitFlagSet(prog, output, flag, 0) |
555 output.append('\n\t} else {') | 557 output.append('\n\t} else {') |
556 after = '\n\t}' | 558 after = '\n\t}' |
557 resultBit = f'({prog.lastB} - 1)' | 559 if prog.lastOp.op == 'rlc': |
560 resultBit = f'({prog.getLastSize()} - {prog.lastB})' | |
561 else: | |
562 resultBit = f'({prog.lastB} - 1)' | |
558 myRes = prog.lastA | 563 myRes = prog.lastA |
559 elif prog.lastOp.op == 'rlc': | 564 elif prog.lastOp.op in('rol', 'ror'): |
560 if type(prog.lastB) is int: | |
561 if prog.lastB == 0: | |
562 explicit[flag] = 0 | |
563 continue | |
564 else: | |
565 resultBit = prog.getLastSize() - prog.lastB | |
566 else: | |
567 output.append(f'\n\tif (!{prog.lastB}) {{') | |
568 _addExplicitFlagSet(prog, output, flag, 0) | |
569 output.append('\n\t} else {') | |
570 after = '\n\t}' | |
571 resultBit = f'({prog.getLastSize()} - {prog.lastB})' | |
572 myRes = prog.lastA | |
573 elif prog.lastOp.op == 'rol': | |
574 if type(prog.lastBUnmasked) is int: | 565 if type(prog.lastBUnmasked) is int: |
575 if prog.lastBUnmasked == 0: | 566 if prog.lastBUnmasked == 0: |
576 explicit[flag] = 0 | 567 explicit[flag] = 0 |
577 continue | 568 continue |
578 else: | 569 else: |
579 output.append(f'\n\tif (!{prog.lastBUnmasked}) {{') | 570 output.append(f'\n\tif (!{prog.lastBUnmasked}) {{') |
580 _addExplicitFlagSet(prog, output, flag, 0) | 571 _addExplicitFlagSet(prog, output, flag, 0) |
581 output.append('\n\t} else {') | 572 output.append('\n\t} else {') |
582 after = '\n\t}' | 573 after = '\n\t}' |
583 resultBit = 0 | 574 if prog.lastOp.op == 'ror': |
584 elif prog.lastOp.op == 'ror': | 575 resultBit = prog.getLastSize() - 1 |
585 if type(prog.lastBUnmasked) is int: | |
586 if prog.lastBUnmasked == 0: | |
587 explicit[flag] = 0 | |
588 continue | |
589 else: | 576 else: |
590 output.append(f'\n\tif (!{prog.lastBUnmasked}) {{') | 577 resultBit = 0 |
591 _addExplicitFlagSet(prog, output, flag, 0) | |
592 output.append('\n\t} else {') | |
593 after = '\n\t}' | |
594 resultBit = prog.getLastSize() - 1 | |
595 elif prog.lastOp.op == 'neg': | 578 elif prog.lastOp.op == 'neg': |
596 if prog.carryFlowDst: | 579 if prog.carryFlowDst: |
597 realSize = prog.getLastSize() | 580 realSize = prog.getLastSize() |
598 if realSize != prog.paramSize(prog.carryFlowDst): | 581 if realSize != prog.paramSize(prog.carryFlowDst): |
599 lastDst = '({res} & {mask})'.format(res=lastDst, mask = (1 << realSize) - 1) | 582 lastDst = '({res} & {mask})'.format(res=lastDst, mask = (1 << realSize) - 1) |
608 output.append('\n\t{reg} = {res} != 0;'.format( | 591 output.append('\n\t{reg} = {res} != 0;'.format( |
609 reg = reg, res = lastDst | 592 reg = reg, res = lastDst |
610 )) | 593 )) |
611 continue | 594 continue |
612 else: | 595 else: |
596 if prog.lastOp.op == 'lsl': | |
597 if type(prog.lastB) is int: | |
598 if prog.lastB == 0: | |
599 explicit[flag] = 0 | |
600 continue | |
601 else: | |
602 output.append(f'\n\tif (!{prog.lastB}) {{') | |
603 _addExplicitFlagSet(prog, output, flag, 0) | |
604 output.append('\n\t} else {') | |
605 after = '\n\t}' | |
613 resultBit = prog.getLastSize() | 606 resultBit = prog.getLastSize() |
614 elif calc == 'half': | 607 elif calc == 'half': |
615 resultBit = prog.getLastSize() - 4 | 608 resultBit = prog.getLastSize() - 4 |
616 myRes = '({a} ^ {b} ^ {res})'.format(a = prog.lastA, b = prog.lastB, res = lastDst) | 609 myRes = '({a} ^ {b} ^ {res})'.format(a = prog.lastA, b = prog.lastB, res = lastDst) |
617 elif calc == 'overflow': | 610 elif calc == 'overflow': |
653 if after: | 646 if after: |
654 output.append(after) | 647 output.append(after) |
655 elif calc == 'zero': | 648 elif calc == 'zero': |
656 if prog.carryFlowDst: | 649 if prog.carryFlowDst: |
657 realSize = prog.getLastSize() | 650 realSize = prog.getLastSize() |
651 output.append(f'\n\t//realSize = {realSize}, carryFlowDst size = {prog.paramSize(prog.carryFlowDst)}, carryFLowDst = {prog.carryFlowDst}') | |
658 if realSize != prog.paramSize(prog.carryFlowDst): | 652 if realSize != prog.paramSize(prog.carryFlowDst): |
659 lastDst = '({res} & {mask})'.format(res=lastDst, mask = (1 << realSize) - 1) | 653 lastDst = '({res} & {mask})'.format(res=lastDst, mask = (1 << realSize) - 1) |
660 if type(storage) is tuple: | 654 if type(storage) is tuple: |
661 reg,storageBit = storage | 655 reg,storageBit = storage |
662 reg = prog.resolveParam(reg, None, {}) | 656 reg = prog.resolveParam(reg, None, {}) |
2219 begin,sep,_ = name.partition('.') | 2213 begin,sep,_ = name.partition('.') |
2220 if sep and self.regs.isRegArray(begin): | 2214 if sep and self.regs.isRegArray(begin): |
2221 return self.regs.regArrays[begin][0] | 2215 return self.regs.regArrays[begin][0] |
2222 if self.regs.isReg(name): | 2216 if self.regs.isReg(name): |
2223 return self.regs.regs[name] | 2217 return self.regs.regs[name] |
2218 for size in self.temp: | |
2219 if self.temp[size] == name: | |
2220 return size | |
2224 return 32 | 2221 return 32 |
2225 | 2222 |
2226 def getLastSize(self): | 2223 def getLastSize(self): |
2227 if self.lastSize: | 2224 if self.lastSize: |
2228 return self.lastSize | 2225 return self.lastSize |