Optimized mnemonic lookup.

This commit is contained in:
Chris Hodges 2021-08-03 18:28:53 +02:00
parent 71398f51d2
commit 5881dcdaf8
3 changed files with 13 additions and 21 deletions

View File

@ -77,6 +77,7 @@ make it work with JUnit 5. Feel free to use the code (in package ```de.platon42.
- Cosmetics: Changed Register Flow Documentation wording from _reads_ to _uses_ and from _modifies_ to _changes_. - Cosmetics: Changed Register Flow Documentation wording from _reads_ to _uses_ and from _modifies_ to _changes_.
- Bugfix: Minor fix for `andi/eori/ori to ccr` which were not byte sized in ISA. - Bugfix: Minor fix for `andi/eori/ori to ccr` which were not byte sized in ISA.
- Bugfix: Added alternate condition code tests `HS (=CC)` and `LO (=CS)`. - Bugfix: Added alternate condition code tests `HS (=CC)` and `LO (=CS)`.
- Performance: Optimized mnemonic lookup.
### V0.4 (03-Aug-21) ### V0.4 (03-Aug-21)

View File

@ -63,6 +63,7 @@ patchPluginXml {
<li>Cosmetics: Changed Register Flow Documentation wording from 'reads' to 'uses' and from 'modifies' to 'changes'. <li>Cosmetics: Changed Register Flow Documentation wording from 'reads' to 'uses' and from 'modifies' to 'changes'.
<li>Bugfix: Minor fix for `andi/eori/ori to ccr` which were not byte sized in ISA. <li>Bugfix: Minor fix for `andi/eori/ori to ccr` which were not byte sized in ISA.
<li>Bugfix: Added alternate condition code tests HS (=CC) and LO (=CS). <li>Bugfix: Added alternate condition code tests HS (=CC) and LO (=CS).
<li>Performance: Optimized mnemonic lookup.
</ul> </ul>
<h4>V0.4 (03-Aug-21)</h4> <h4>V0.4 (03-Aug-21)</h4>
<ul> <ul>

View File

@ -1002,29 +1002,19 @@ object M68kIsa {
) )
) )
val mnemonics = private val mnemonicLookupMap = isaData.asSequence()
isaData.asSequence() .flatMap {
.flatMap { (if (it.conditionCodes.isEmpty()) it.altMnemonics.plus(it.mnemonic) else it.altMnemonics.plus(it.conditionCodes
if (it.conditionCodes.isEmpty()) it.altMnemonics.plus(it.mnemonic) else it.altMnemonics.plus(it.conditionCodes .map { cc ->
.map { cc -> it.mnemonic.replace("CC", cc)
it.mnemonic.replace("CC", cc) })).map { mnemonic -> mnemonic to it }
}) }
} .groupBy({ it.first }) { it.second }
.toSet()
val mnemonics = mnemonicLookupMap.keys
fun findMatchingInstructions(mnemonic: String): List<IsaData> { fun findMatchingInstructions(mnemonic: String): List<IsaData> {
val lowerMnemonic = mnemonic.lowercase() return mnemonicLookupMap.getOrDefault(mnemonic.lowercase(), emptyList())
return isaData
.filter {
if (it.conditionCodes.isEmpty()) {
(it.mnemonic == lowerMnemonic) || it.altMnemonics.any { altMnemonic -> altMnemonic == lowerMnemonic }
} else {
it.altMnemonics.any { altMnemonic -> altMnemonic == lowerMnemonic } ||
it.conditionCodes.any { cc ->
it.mnemonic.replace("CC", cc) == lowerMnemonic
}
}
}
} }
fun findMatchingOpMode(candidates: List<IsaData>, op1: AddressMode?, op2: AddressMode?, opSize: Int?, specialReg: String?): List<IsaData> { fun findMatchingOpMode(candidates: List<IsaData>, op1: AddressMode?, op2: AddressMode?, opSize: Int?, specialReg: String?): List<IsaData> {