small optimization idea

Post Reply
spacy51
Senior Member
Posts: 371
Joined: Tue Mar 18, 2008 4:59 pm

small optimization idea

Post by spacy51 »

gba-thumb.cpp @l1587:

// LDR Rd, [Rs, #Imm]
static INSN_REGPARM void thumb68(u32 opcode)

{

if (busPrefetchCount == 0)

Code: Select all

busPrefetch = busPrefetchEnable;

u32 address = reg[(opcode>>3)&7].I + b<<2)[/b];

reg[opcode&7].I = CPUReadMemory(address);

clockTicks = 3 + dataTicksAccess32(address) + codeTicksAccess16(armNextPC);

}

Couldn't the highlighted block be optimized by replacing it with

code[/code]

 

 

There are several cases like this around that area.

Last edited by spacy51 on Mon Aug 17, 2009 1:17 pm, edited 1 time in total.
User avatar
ZachBacon
Member
Posts: 242
Joined: Tue Mar 27, 2018 9:35 pm

small optimization idea

Post by ZachBacon »

I'll give it a try and see what happens [img]<fileStore.core_Emoticons>/emoticons/smile.png[/img]/emoticons/smile@2x.png 2x" width="20" height="20" />

User avatar
ZachBacon
Member
Posts: 242
Joined: Tue Mar 27, 2018 9:35 pm

small optimization idea

Post by ZachBacon »

ok tried

u32 address = reg[(opcode>>3)&7].I + (((opcode>>4)&124)<<2); and it didn't work (I know not what you said to try)

so then I tried

u32 address = reg[(opcode>>3)&7].I + (((opcode>>4)&124); compile didn't work since it was missing a bracket (that was kind of your fault for not giving the extra bracket [img]<fileStore.core_Emoticons>/emoticons/tongue.png[/img]/emoticons/tongue@2x.png 2x" width="20" height="20" />)

once the extra bracket was added it worked again

u32 address = reg[(opcode>>3)&7].I + (((opcode>>4)&124));

and it was fairly optimized [img]<fileStore.core_Emoticons>/emoticons/smile.png[/img]/emoticons/smile@2x.png 2x" width="20" height="20" />

spacy51
Senior Member
Posts: 371
Joined: Tue Mar 18, 2008 4:59 pm

small optimization idea

Post by spacy51 »

My replacement should be perfectly fine [img]<fileStore.core_Emoticons>/emoticons/huh.png[/img]/emoticons/huh@2x.png 2x" width="20" height="20" />

 

u32 address = reg[(opcode>>3)&7].I + b)[/b];

 

Do you seriously want to tell me there have to be two brackets???

:blah!:

 

It would be interesting to see the actual speed differences, if all of those similar code pieces were edited like that.

Last edited by spacy51 on Mon Aug 17, 2009 4:09 pm, edited 1 time in total.
User avatar
ZachBacon
Member
Posts: 242
Joined: Tue Mar 27, 2018 9:35 pm

small optimization idea

Post by ZachBacon »

well I was tired and didn't notice >_< I didn't have my coffee at all but yeah I say let's do this as an experiment first before submitting it to svn and if the others like it then submit it

spacy51
Senior Member
Posts: 371
Joined: Tue Mar 18, 2008 4:59 pm

small optimization idea

Post by spacy51 »

It would be cool if some binary junky can tell me if the expression (((opcode>>6)&31)<<2) always gives the same results as ((opcode>>4)&124). I only had some basic binary term transformation in school ^^. I really don't want to introduce bugs like I did before I took a break [img]<fileStore.core_Emoticons>/emoticons/laugh.png[/img]/emoticons/laugh@2x.png 2x" width="20" height="20" />

Last edited by spacy51 on Mon Aug 17, 2009 4:25 pm, edited 1 time in total.
jbo_85
Junior Member
Posts: 8
Joined: Sun Mar 23, 2008 8:05 pm

small optimization idea

Post by jbo_85 »

It would be cool if some binary junky can tell me if the expression (((opcode>>6)&31)<<2) always gives the same results as ((opcode>>4)&124). I only had some basic binary term transformation in school ^^. I really don't want to introduce bugs like I did before I took a break [img]<fileStore.core_Emoticons>/emoticons/laugh.png[/img]/emoticons/laugh@2x.png 2x" width="20" height="20" />

The two expressions are the same. But it doesn't make a difference for the release build because the compiler already optimizes it.

spacy51
Senior Member
Posts: 371
Joined: Tue Mar 18, 2008 4:59 pm

small optimization idea

Post by spacy51 »

Is there any proof that the compiler optimizes that? Hm, maybe it's possible to look at the assembler code the compiler produced.

Last edited by spacy51 on Mon Aug 17, 2009 6:04 pm, edited 1 time in total.
jbo_85
Junior Member
Posts: 8
Joined: Sun Mar 23, 2008 8:05 pm

small optimization idea

Post by jbo_85 »

I compared the executables.

spacy51
Senior Member
Posts: 371
Joined: Tue Mar 18, 2008 4:59 pm

small optimization idea

Post by spacy51 »

OK, good to know, thanks.

Post Reply