added optimized case for signed division by 2

This commit is contained in:
Irmen de Jong
2022-07-24 13:20:38 +02:00
parent dcc1f00048
commit 046dceb5c2
6 changed files with 70 additions and 40 deletions
@@ -512,11 +512,7 @@ class CodeGen(internal val program: PtProgram,
return code
val pow2 = powersOfTwo.indexOf(factor)
if(pow2==1 && !signed) {
// just shift 1 bit
code += if(signed)
VmCodeInstruction(Opcode.ASR, dt, reg1=reg)
else
VmCodeInstruction(Opcode.LSR, dt, reg1=reg)
code += VmCodeInstruction(Opcode.LSR, dt, reg1=reg) // simple single bit shift
}
else if(pow2>=1 &&!signed) {
// just shift multiple bits
@@ -545,11 +541,7 @@ class CodeGen(internal val program: PtProgram,
return code
val pow2 = powersOfTwo.indexOf(factor)
if(pow2==1 && !signed) {
// just shift 1 bit
code += if(signed)
VmCodeInstruction(Opcode.ASRM, dt, value=address)
else
VmCodeInstruction(Opcode.LSRM, dt, value=address)
code += VmCodeInstruction(Opcode.LSRM, dt, value=address) // just simple bit shift
}
else if(pow2>=1 && !signed) {
// just shift multiple bits