Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


ASM- which has higher efficiency ?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
supercharger
Advanced Cheater
Reputation: 0

Joined: 06 Aug 2009
Posts: 61

PostPosted: Sun Jul 11, 2010 3:20 am    Post subject: ASM- which has higher efficiency ? Reply with quote

i saw in a game (developed after year2k) a lot of codes like these
fld dword ptr [xxxxxxxx] - which have the same output as fld1 or fldz or fldpi.
i wonder why they don't use fld1 (or fldz or fldpi) , which are shorter and don't require reading memory.

between fld dword ptr [xxxxxxx] and fld1, which as higher efficiency?
i have been writing codes and i prefer fld1 which is easier to read, unless fld1 costs more CPU time.

another question:
as CPU and FPU can work simultaneously, should i write codes this way:
mov eax,[xxxxxxx]
fadd dword ptr [ecx]
fsub dword ptr [eax]

or this way:
fadd dword ptr [ecx]
mov eax,[xxxxxxx]
fsub dword ptr [eax]

this is just an example of arranging the order of instructions, both ways are not very different in this case. but you can get the idea what i mean.
Back to top
View user's profile Send private message
justa_dude
Grandmaster Cheater
Reputation: 23

Joined: 29 Jun 2010
Posts: 891

PostPosted: Sat Jul 17, 2010 7:01 pm    Post subject: Reply with quote

Yes, fld1/pi/0 are faster than loading a real from memory. But loading from memory allows you to grab arbitrary values - not just constants.

With regard to your second question, I don't think that either code does what you're expecting. Values have to be loaded and copied/popped onto and off of the FPU stack, and I don't see you moving your values off in either snippet.

Cheers,
adude
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Sat Jul 17, 2010 7:10 pm    Post subject: Reply with quote

It's also a pointless optimization for a game, as the bottleneck is usually the graphics card.
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Sun Jul 18, 2010 7:53 am    Post subject: Reply with quote

to your second question, it probably doesn't make any difference since your cpu pipelines and takes advantage of out of order execution
Back to top
View user's profile Send private message
supercharger
Advanced Cheater
Reputation: 0

Joined: 06 Aug 2009
Posts: 61

PostPosted: Mon Jul 19, 2010 5:14 pm    Post subject: Reply with quote

Flyte wrote:
It's also a pointless optimization for a game, as the bottleneck is usually the graphics card.


right.
but i want to form a habit of writing effecient codes so i need to know which way is more efficient.
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Mon Jul 19, 2010 7:49 pm    Post subject: Reply with quote

supercharger wrote:
right.
but i want to form a habit of writing effecient codes so i need to know which way is more efficient.


Priority numero uno is to write code that works. You only optimize if it is necessary.

See: http://www.iso-9899.info/wiki/Why_not_fast
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites