Killer framerates.

Started by
29 comments, last by Vlion 22 years, 6 months ago
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
~V'lionBugle4d
Advertisement
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
i just look at that url and found out it was for borland compilers.

another reason why (unfortunaly) microsoft rule .


MENTAL
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.
HardDrop - hard link shell extension."Tread softly because you tread on my dreams" - Yeats
A tip could be to not render the tri''s that aren''t visible, but i guess you have code for that already...
HardDrop - hard link shell extension."Tread softly because you tread on my dreams" - Yeats
ummm, that code was chruned out in debug mode with no optimizations thank you very much.


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



MENTAL
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.
HardDrop - hard link shell extension."Tread softly because you tread on my dreams" - Yeats
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
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.

This topic is closed to new replies.

Advertisement