Jump to content

  • Log In with Google      Sign In   
  • Create Account


Killer framerates.


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
30 replies to this topic

#21 Vlion   Members   -  Reputation: 151

Like
Likes
Like

Posted 14 October 2001 - 07:48 AM

heheh.
Heres VC++6 asm for i++ and ++j;
---
235: int i = 0, j = 0;
00401988 C7 45 FC 00 00 00 00 mov dword ptr [ebp-4],0
0040198F C7 45 F8 00 00 00 00 mov dword ptr [ebp-8],0
236: i++;
00401996 8B 45 FC mov eax,dword ptr [ebp-4]
00401999 83 C0 01 add eax,1
0040199C 89 45 FC mov dword ptr [ebp-4],eax
237: ++j;
0040199F 8B 4D F8 mov ecx,dword ptr [ebp-8]
004019A2 83 C1 01 add ecx,1
004019A5 89 4D F8 mov dword ptr [ebp-8],ecx
---
I see no difference.

Mentor- I dropped your code into my program, and it worksok.
It holds to a constant framerate- about 22-23 fps.
Not the greatest, but alot better than before.
Next I need to integrate it/work on it some.
Then I`ll try for vertex arrays and whatever else I can squeeze out of OGL.

The goal is to display a 1056x1056 map at a reasonable framerate, along with some units.
I need to work out some stuff before I display stuff that big. :D

~V''lion

I came, I saw, I got programmers block.
~V''''lion

Sponsor:

#22 MENTAL   Members   -  Reputation: 382

Like
Likes
Like

Posted 14 October 2001 - 09:37 AM

like i said, ++i and i++ do the same thing. in ye olde dayse when C was new and compilers were crap, ++i might have been faster, but to be frank, i think people caught onto the fact that ++i and i++ do the same thing, so they gave them the same line of asm code, as Vilon showed.



; 6 : i++;

mov eax, DWORD PTR _i$[ebp]
add eax, 1
mov DWORD PTR _i$[ebp], eax

; 7 : ++j;

mov ecx, DWORD PTR _j$[ebp]
add ecx, 1
mov DWORD PTR _j$[ebp], ecx


my results, just to show that they are identical. i got a bit parinoid when i saw that i++ used eax and ++j used ecx, so i changed them around, and look:


; 6 : ++j;

mov eax, DWORD PTR _j$[ebp]
add eax, 1
mov DWORD PTR _j$[ebp], eax

; 7 : i++;

mov ecx, DWORD PTR _i$[ebp]
add ecx, 1
mov DWORD PTR _i$[ebp], ecx


now ++j uses eax and i++ uses ecx.

heh i rule .

MENTAL

#23 MENTAL   Members   -  Reputation: 382

Like
Likes
Like

Posted 14 October 2001 - 09:41 AM

i just look at that url and found out it was for borland compilers.

another reason why (unfortunaly) microsoft rule .


MENTAL

#24 DigitalDelusion   Members   -  Reputation: 874

Like
Likes
Like

Posted 16 October 2001 - 04:37 AM

MENTAL: you''re wrong, both pre and post increment are defiend in the ANSI C standard. But on a modern optimizing compiler it''s quite possible that they produce the same code.
But in the general case or when in C++ you overload the operators the preincrement (++i) version is faster because it removes a temporary object.

PLZ before stating crap know the fact, and not some bogus facts that an assembly listing from a compiler with all optimizationse enabled are with regard to how the original program was written. Know the standard know the code it should produce if not optimized and then go on ranting.. before that you just make yourself look stupid.

#25 DigitalDelusion   Members   -  Reputation: 874

Like
Likes
Like

Posted 16 October 2001 - 04:41 AM

A tip could be to not render the tri''s that aren''t visible, but i guess you have code for that already...

#26 MENTAL   Members   -  Reputation: 382

Like
Likes
Like

Posted 16 October 2001 - 06:59 AM

ummm, that code was chruned out in debug mode with no optimizations thank you very much.


MENTAL

#27 MENTAL   Members   -  Reputation: 382

Like
Likes
Like

Posted 16 October 2001 - 07:00 AM

anyway, since when did microsoft pay any attention to ANSI???



MENTAL

#28 DigitalDelusion   Members   -  Reputation: 874

Like
Likes
Like

Posted 16 October 2001 - 10:24 AM

I didn''t look at the assembly listning.
And there is a diffrence trust me on that.
But most of the time it doesnt matter, but when using
classes with operator overloading it does. It''s even made it way into most of the litterature on C++ by now just because it''s a so common missconception that they are the same.

#29 buzzy_b   Members   -  Reputation: 122

Like
Likes
Like

Posted 16 October 2001 - 10:45 AM

In The C++ Programming Language 3rd Ed. by Bjarne Stroustrup (the creator of C++) this is how the increment operator works.

y = ++x;
is equivalent to
y = (x+=1);

while
y = x++;
is equivalent to
y = (t=x, x+=1, t) where t is a variable of the same type as x.

Perhaps modern compilers (i.e. VC++) produce the same assembly code for both, but the official definition of C++ says that there is a difference. I hope that clears that up.

--Buzzy

#30 Obelix   Members   -  Reputation: 122

Like
Likes
Like

Posted 16 October 2001 - 12:38 PM

Right, ++i and i++ is not the same but it should not be any speed difference. Perhaps it was different a long time ago with bad compilers and no cache.
If you are working in a team will "optimized" non convetional code just annoy the other members.

#31 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 17 October 2001 - 04:36 AM

quote:
Original post by buzzy_b
In The C++ Programming Language 3rd Ed. by Bjarne Stroustrup (the creator of C++) this is how the increment operator works.

y = ++x;
is equivalent to
y = (x+=1);

while
y = x++;
is equivalent to
y = (t=x, x+=1, t) where t is a variable of the same type as x.

Perhaps modern compilers (i.e. VC++) produce the same assembly code for both, but the official definition of C++ says that there is a difference. I hope that clears that up.

--Buzzy


No one says they are the same. The ++x returns the incremented value, and x++ returns the value before increment. That t value only makes an appearance because they wanted to write it in one line of C in the spec. Remember, the spec is defining the behavior of the statements, but you are free to use any _equivalent_ implementation and you will still be following the standard.

Assembly doesn''t do as much in a single line as C, so it is going to roll out into multiple statements.

Here, let me write an equivalent statement to the spec''s in C (with multiple statements).

y = ++x;
is equivalent to:
x = x + 1; y = x;
while
y = x++
is:
y = x;x = x + 1;

Same number of operations, See?

You do often need some extra space when it''s an overloaded operator on a class, but in C, there is _no_ speed difference. C++ /might/ have a difference, depending on how the programmer wrote the pre and post increment functions. But I could certainly overload my operators in such a way that postincrement would be faster, if I so desired.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS