View previous topic :: View next topic |
Author |
Message |
supercharger Advanced Cheater
Reputation: 0
Joined: 06 Aug 2009 Posts: 61
|
Posted: Sun Jul 11, 2010 3:20 am Post subject: ASM- which has higher efficiency ? |
|
|
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 |
|
 |
justa_dude Grandmaster Cheater
Reputation: 23
Joined: 29 Jun 2010 Posts: 891
|
Posted: Sat Jul 17, 2010 7:01 pm Post subject: |
|
|
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 |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Sat Jul 17, 2010 7:10 pm Post subject: |
|
|
It's also a pointless optimization for a game, as the bottleneck is usually the graphics card.
|
|
Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Sun Jul 18, 2010 7:53 am Post subject: |
|
|
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 |
|
 |
supercharger Advanced Cheater
Reputation: 0
Joined: 06 Aug 2009 Posts: 61
|
Posted: Mon Jul 19, 2010 5:14 pm Post subject: |
|
|
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 |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Mon Jul 19, 2010 7:49 pm Post subject: |
|
|
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 |
|
 |
|