Archived

This topic is now archived and is closed to further replies.

Member Function calls in asm

This topic is 5826 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
The calls look like stdcall, except this is passed in ecx(on msvc). The items are passed right to left (last argument pushed first). The called function cleans up the stack. About your optimized switch, gcc has some extension for that where you can index your case addresses in an array.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites