Optimize 8 by 16 bit multiply

This commit is contained in:
drmortalwombat 2024-10-04 20:06:56 +02:00
parent 1f492e7820
commit 056b49e1d1
2 changed files with 56 additions and 2 deletions

View File

@ -839,6 +839,55 @@ W1: asl accu
#endif
}
#if 1
__asm mul16by8
{
lsr
beq zero
more:
ldx #0
ldy #0
bcc skip
odd:
ldy accu
ldx accu + 1
bcs skip
loop:
sta tmpy
clc
tya
adc accu
tay
txa
adc accu + 1
tax
lda tmpy
skip:
asl accu
rol accu + 1
lsr
bcc skip
bne loop
done:
clc
tya
adc accu
sta accu
txa
adc accu + 1
sta accu + 1
rts
zero:
bcs one
sta accu
sta accu + 1
one:
rts
}
#else
__asm mul16by8
{
ldy #0
@ -866,6 +915,7 @@ L2:
sty tmp + 2
rts
}
#endif
__asm divs16
{

View File

@ -9390,6 +9390,8 @@ int NativeCodeBasicBlock::ShortMultiply(InterCodeProcedure* proc, NativeCodeProc
NativeCodeGenerator::Runtime& rt(nproc->mGenerator->ResolveRuntime(Ident::Unique("mul16by8")));
mIns.Push(NativeCodeInstruction(ins, ASMIT_JSR, ASMIM_ABSOLUTE, rt.mOffset, rt.mLinkerObject, NCIF_RUNTIME | NCIF_LOWER | NCIF_UPPER | NCIF_USE_CPU_REG_A));
return BC_REG_ACCU;
}
else
{
@ -9425,6 +9427,8 @@ int NativeCodeBasicBlock::ShortMultiply(InterCodeProcedure* proc, NativeCodeProc
NativeCodeGenerator::Runtime& rt(nproc->mGenerator->ResolveRuntime(Ident::Unique("mul16by8")));
mIns.Push(NativeCodeInstruction(ins, ASMIT_JSR, ASMIM_ABSOLUTE, rt.mOffset, rt.mLinkerObject, NCIF_RUNTIME | NCIF_LOWER | NCIF_UPPER | NCIF_USE_CPU_REG_A));
return BC_REG_ACCU;
}
return BC_REG_WORK + 2;
@ -10995,7 +10999,7 @@ NativeCodeBasicBlock* NativeCodeBasicBlock::BinaryOperator(InterCodeProcedure* p
NativeCodeGenerator::Runtime& frt(nproc->mGenerator->ResolveRuntime(Ident::Unique("mul16by8")));
mIns.Push(NativeCodeInstruction(ins, ASMIT_JSR, ASMIM_ABSOLUTE, frt.mOffset, frt.mLinkerObject, NCIF_RUNTIME | NCIF_LOWER | NCIF_UPPER | NCIF_USE_CPU_REG_A));
reg = BC_REG_WORK + 2;
reg = BC_REG_ACCU;
}
else if (ins->mOperator == IA_MUL && ins->mSrc[1].IsUByte())
{
@ -11019,7 +11023,7 @@ NativeCodeBasicBlock* NativeCodeBasicBlock::BinaryOperator(InterCodeProcedure* p
NativeCodeGenerator::Runtime& frt(nproc->mGenerator->ResolveRuntime(Ident::Unique("mul16by8")));
mIns.Push(NativeCodeInstruction(ins, ASMIT_JSR, ASMIM_ABSOLUTE, frt.mOffset, frt.mLinkerObject, NCIF_RUNTIME | NCIF_LOWER | NCIF_UPPER | NCIF_USE_CPU_REG_A));
reg = BC_REG_WORK + 2;
reg = BC_REG_ACCU;
}
#if 1
else if (ins->mOperator == IA_DIVS && ins->mSrc[0].mTemp < 0 && (ins->mSrc[0].mIntConst == 2 || ins->mSrc[0].mIntConst == 4 || ins->mSrc[0].mIntConst == 8))