optimize msb(cx16.r0) -> cx16.r0H, lsb(cx16.r0) -> cx16.r0L

This commit is contained in:
Irmen de Jong 2022-07-02 21:38:22 +02:00
parent 7a3745f642
commit 7fff4f249d
3 changed files with 16 additions and 7 deletions

View File

@ -12,10 +12,7 @@ import prog8.ast.statements.IfElse
import prog8.ast.statements.Jump
import prog8.ast.walk.AstWalker
import prog8.ast.walk.IAstModification
import prog8.code.core.AssociativeOperators
import prog8.code.core.DataType
import prog8.code.core.IntegerDatatypes
import prog8.code.core.NumericDatatypes
import prog8.code.core.*
import kotlin.math.abs
import kotlin.math.log2
import kotlin.math.pow
@ -260,6 +257,12 @@ class ExpressionSimplifier(private val program: Program) : AstWalker() {
return listOf(IAstModification.ReplaceNode(functionCallExpr, arg.expression, parent))
}
} else {
if(arg is IdentifierReference && arg.nameInSource.size==2
&& arg.nameInSource[0]=="cx16" && arg.nameInSource[1].uppercase() in RegisterOrPair.names) {
// lsb(cx16.r0) -> cx16.r0L
val highReg = IdentifierReference(listOf("cx16", arg.nameInSource[1]+'L'), arg.position)
return listOf(IAstModification.ReplaceNode(functionCallExpr, highReg, parent))
}
val argDt = arg.inferType(program)
if (argDt istype DataType.BYTE || argDt istype DataType.UBYTE) {
// useless lsb() of byte value
@ -281,6 +284,12 @@ class ExpressionSimplifier(private val program: Program) : AstWalker() {
parent))
}
} else {
if(arg is IdentifierReference && arg.nameInSource.size==2
&& arg.nameInSource[0]=="cx16" && arg.nameInSource[1].uppercase() in RegisterOrPair.names) {
// msb(cx16.r0) -> cx16.r0H
val highReg = IdentifierReference(listOf("cx16", arg.nameInSource[1]+'H'), arg.position)
return listOf(IAstModification.ReplaceNode(functionCallExpr, highReg, parent))
}
val argDt = arg.inferType(program)
if (argDt istype DataType.BYTE || argDt istype DataType.UBYTE) {
// useless msb() of byte value, replace with 0

View File

@ -81,7 +81,7 @@ psg {
envelope_states[cx16.r15L] = 1 ; start release
}
envelope_volumes[cx16.r15L] = cx16.r0
volume(cx16.r15L, msb(cx16.r0))
volume(cx16.r15L, msb(cx16.r0)) ; TODO optimize to not use vpoke and use vera auto increment
}
1 -> {
; release
@ -91,7 +91,7 @@ psg {
envelope_releases[cx16.r15L] = 0
}
envelope_volumes[cx16.r15L] = cx16.r0
volume(cx16.r15L, msb(cx16.r0))
volume(cx16.r15L, msb(cx16.r0)) ; TODO optimize to not use vpoke and use vera auto increment
}
}
}

View File

@ -3,7 +3,7 @@ TODO
For next release
^^^^^^^^^^^^^^^^
- optimize msb(cx16.r0) -> cx16.r0H, lsb(cx16.r0) -> cx16.r0L
- psg: use all 16 voices and see how many rasterlines the envelope interrupt handler takes
- if passing a subroutine or label name as an uword argument, without &, add the addressof automatically
- convert the sounds in cx16 tehtriz to use the psg module instead
- notify petaxian that it could use the psg module too?