Skip to main content
GameDev.net gamedev.net
🔒 Locked

Member Function calls in asm

Started by Doener Jan 2, 2002 at 8:07 PM 1 replies 450+ views
Original Post
Doener
Doener
Hi, I'm currently designing a gaming engine and had that bad feeling about performance when my design required a quite large switch statement, so I decided to replace the switch statement with the following code: __asm { call dummy dummy: pop eax add eax, switchVar jmp eax // case1 ... // case2 ... // ... ... // lastCase ... } As you may see, I defined my state-constants so that they have the offset from dummy to the code to be executed. I think that should be a lot faster than a switch cause I have just a simple add and jmp instead of a multitude of sub's an je's. Please correct me if I'm wrong. My actual question is how I call member functions of a class in asm, cause I don't know in which order I have to put the parameters and this pointer on the stack and if I have to clean up the stack and so on. Thanks in advance and tell me what you think about my optimization attempt Edited by - Doener on January 2, 2002 9:11:23 PM
DrPizza
DrPizza
Your compiler will probably optimize it better than you.

If it can use a jump table efficiently, it will likely use a jump table. If the range is too large for a jump table, it''ll use cascaded comparisons and be better off for it , or perhaps even a binary search to find the right option.

Anyway.

Have you determined that this switch statement is actually a bottleneck? If you haven''t, you should stop wasting your time. Don''t try to guess where bottlenecks are, you''re probably wrong. Profile the code.
char a[99999],*p=a;int main(int c,char**V){char*v=c>0?1[V]:(char*)V;if(c>=0)for(;*v&&93!=*v;){62==*v&&++p||60==*v&&--p||43==*v&&++*p||45==*v&&--*p||44==*v&&(*p=getchar())||46==*v&&putchar(*p)||91==*v&&(*p&&main(0,(char**)(--v+2))||(v=(char*)main(-1,(char**)++v)-1));++v;}else for(c=1;c;c+=(91==*v)-(93==*v),++v);return(int)v;} /*** drpizza@battleaxe.net ***/

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.