Jump to content
Visual Boy Advance-M
spacy51

small optimization idea

Recommended Posts

gba-thumb.cpp @l1587:

// LDR Rd, [Rs, #Imm]

static INSN_REGPARM void thumb68(u32 opcode)

{

if (busPrefetchCount == 0)

busPrefetch = busPrefetchEnable;

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

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

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

}

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

((opcode>>4)&124)

 

 

There are several cases like this around that area.

Share this post


Link to post
Share on other sites

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 :P)

once the extra bracket was added it worked again

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

and it was fairly optimized :)

Share this post


Link to post
Share on other sites

My replacement should be perfectly fine o.O

 

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

 

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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 xD

Share this post


Link to post
Share on other sites

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 xD

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×