Post Reply 
 
Thread Rating:
  • 20 Votes - 3.3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
small optimization idea
Author Message
spacy51 Offline
VBA-M Developer
*******

Posts: 451
Joined: Mar 2008
Reputation: 3
Post: #1
small optimization idea
gba-thumb.cpp @l1587:
Quote:// 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
Code:
((opcode>>4)&124)


There are several cases like this around that area.
(This post was last modified: 08-18-2009 03:17 AM by spacy51.)
08-18-2009 03:16 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Zach Thibeau Offline
Administrator
*******

Posts: 251
Joined: Mar 2008
Reputation: 2
Post: #2
RE: small optimization idea
I'll give it a try and see what happens Smile

Emuskillet checking whats cooking in the emuscene | My Personal Blog
[Image: tealcsiler5bb.gif]
08-18-2009 05:46 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Zach Thibeau Offline
Administrator
*******

Posts: 251
Joined: Mar 2008
Reputation: 2
Post: #3
RE: small optimization idea
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 Tongue)
once the extra bracket was added it worked again
u32 address = reg[(opcode>>3)&7].I + (((opcode>>4)&124));
and it was fairly optimized Smile

Emuskillet checking whats cooking in the emuscene | My Personal Blog
[Image: tealcsiler5bb.gif]
08-18-2009 05:54 AM
Visit this user's website Find all posts by this user Quote this message in a reply
spacy51 Offline
VBA-M Developer
*******

Posts: 451
Joined: Mar 2008
Reputation: 3
Post: #4
RE: small optimization idea
My replacement should be perfectly fine o.o

(08-18-2009 05:54 AM)Zach Thibeau Wrote:  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.
(This post was last modified: 08-18-2009 06:09 AM by spacy51.)
08-18-2009 06:08 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Zach Thibeau Offline
Administrator
*******

Posts: 251
Joined: Mar 2008
Reputation: 2
Post: #5
RE: small optimization idea
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

Emuskillet checking whats cooking in the emuscene | My Personal Blog
[Image: tealcsiler5bb.gif]
08-18-2009 06:09 AM
Visit this user's website Find all posts by this user Quote this message in a reply
spacy51 Offline
VBA-M Developer
*******

Posts: 451
Joined: Mar 2008
Reputation: 3
Post: #6
RE: small optimization idea
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
(This post was last modified: 08-18-2009 06:25 AM by spacy51.)
08-18-2009 06:25 AM
Visit this user's website Find all posts by this user Quote this message in a reply
jbo_85 Offline
VBA-M Developer
*******

Posts: 9
Joined: Mar 2008
Reputation: 0
Post: #7
RE: small optimization idea
(08-18-2009 06:25 AM)spacy51 Wrote:  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.
08-18-2009 06:28 AM
Find all posts by this user Quote this message in a reply
spacy51 Offline
VBA-M Developer
*******

Posts: 451
Joined: Mar 2008
Reputation: 3
Post: #8
RE: small optimization idea
Is there any proof that the compiler optimizes that? Hm, maybe it's possible to look at the assembler code the compiler produced.
(This post was last modified: 08-18-2009 08:04 AM by spacy51.)
08-18-2009 07:37 AM
Visit this user's website Find all posts by this user Quote this message in a reply
jbo_85 Offline
VBA-M Developer
*******

Posts: 9
Joined: Mar 2008
Reputation: 0
Post: #9
RE: small optimization idea
I compared the executables.
08-18-2009 07:43 AM
Find all posts by this user Quote this message in a reply
spacy51 Offline
VBA-M Developer
*******

Posts: 451
Joined: Mar 2008
Reputation: 3
Post: #10
RE: small optimization idea
OK, good to know, thanks.
08-18-2009 08:04 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)

 Quick Theme: