ConsoleTom
Member
Hi !
I am trying to optimize an Emu and i would like to rewrite routines in assembly. Now i would like to know if it would be an optimization when i rewrite this example in assembly ?
There are many if's and switch+case and i thought when i rewrite all (i know it's a lot of work but i really have time) it should get faster. Am i right or is it nonsensical ?
...
switch(addr&0xff)
{
case (TIM6BKUP&0xff):
mTIM_6_BKUP=data;
break;
case (TIM7BKUP&0xff):
mTIM_7_BKUP=data;
break;
case (TIM0CTLA&0xff):
mTimerInterruptMask&=(0x01^0xff);
mTimerInterruptMask|=(data&0x80)?0x01:0x00;
mTIM_0_ENABLE_RELOAD=data&0x10;
mTIM_0_ENABLE_COUNT=data&0x08;
mTIM_0_LINKING=data&0x07;
if(data&0x40) mTIM_0_TIMER_DONE=0;
if(data&0x48)
{
mTIM_0_LAST_COUNT=gSystemCycleCount;
gNextTimerEvent=gSystemCycleCount;
}
break;
...
My ASM-Code of one 'case' could look like this
<save used registers>
ldr r0, =addr
ldr r1, =TIM7BKUP
and r0,r0,#0xFF
and r1,r1,#0xFF
cmp r0,r1
bne othercase
ldr r0,=mTIM_7_BKUP
ldr r1,=data
str r0,[r1]
othercase:
...
<load used registers and exit>
Is this code ok like this ? Could it be done better ? And is it faster then c ?
Greetings
Tobias
I am trying to optimize an Emu and i would like to rewrite routines in assembly. Now i would like to know if it would be an optimization when i rewrite this example in assembly ?
There are many if's and switch+case and i thought when i rewrite all (i know it's a lot of work but i really have time) it should get faster. Am i right or is it nonsensical ?
...
switch(addr&0xff)
{
case (TIM6BKUP&0xff):
mTIM_6_BKUP=data;
break;
case (TIM7BKUP&0xff):
mTIM_7_BKUP=data;
break;
case (TIM0CTLA&0xff):
mTimerInterruptMask&=(0x01^0xff);
mTimerInterruptMask|=(data&0x80)?0x01:0x00;
mTIM_0_ENABLE_RELOAD=data&0x10;
mTIM_0_ENABLE_COUNT=data&0x08;
mTIM_0_LINKING=data&0x07;
if(data&0x40) mTIM_0_TIMER_DONE=0;
if(data&0x48)
{
mTIM_0_LAST_COUNT=gSystemCycleCount;
gNextTimerEvent=gSystemCycleCount;
}
break;
...
My ASM-Code of one 'case' could look like this
<save used registers>
ldr r0, =addr
ldr r1, =TIM7BKUP
and r0,r0,#0xFF
and r1,r1,#0xFF
cmp r0,r1
bne othercase
ldr r0,=mTIM_7_BKUP
ldr r1,=data
str r0,[r1]
othercase:
...
<load used registers and exit>
Is this code ok like this ? Could it be done better ? And is it faster then c ?
Greetings
Tobias