Hi All.
Does anyone used OpenWatcom C/C++ compiler. It has beautiffull Register-Based calling convention. With this it produces very fast code.
I have switched from OpenWatcom to MinGW/GCC some days ago. I've found that code produced with OpenWatcom is little better then GCC one.
Q : Does GCC have something like Register-Based calling convention ?
P.S. If we have a function which receives one int parameter, GCC pushes it on stack i.e. we have memory op, we have one hope : this memory line already in cache, otherwise we have speed penalty.
Function parameter passing in Registers (GCC)
Re:Function parameter passing in Registers (GCC)
There is the "register" keyword, which is part of the C/C++ standard. The compiler is allowed to ignore it, however: It is a suggestion by the developer.
For GCC specifics, check out http://gcc.gnu.org/onlinedocs/gcc-4.0.0/gcc/Function-Attributes.html. fastcall and regparm look like interesting candidates.
For GCC specifics, check out http://gcc.gnu.org/onlinedocs/gcc-4.0.0/gcc/Function-Attributes.html. fastcall and regparm look like interesting candidates.
Every good solution is obvious once you've found it.
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Function parameter passing in Registers (GCC)
fortunately enough, the IA-32 are very good at caching the stack content (yeah, really). And using "foo(register int bar)" do not tell the compiler "i want bar to be passed through a register" but rather "once you retrieved bar, keep it in a register as i'm using it veryveryveryoften".
What i usually do is to tell the compiler the function is "static" so that it can feel free to do whatever it wants with it (inline it, break calling convention or whatever), since it now knows nothing from outside could possibly call the function.
What i usually do is to tell the compiler the function is "static" so that it can feel free to do whatever it wants with it (inline it, break calling convention or whatever), since it now knows nothing from outside could possibly call the function.
Re:Function parameter passing in Registers (GCC)
Actually "register" means that the address of the variable cannot be taken - nothing more and nothing less. This enables the compiler to keep (and possibly pass) it in a register.
It also enables several other optimizations, as it avoids several aliasing problems inherent in the language. If you're doing C99 and are interested in giving the compiler an easy time optimizing your code, you should also check the "restrict" keyword.
It also enables several other optimizations, as it avoids several aliasing problems inherent in the language. If you're doing C99 and are interested in giving the compiler an easy time optimizing your code, you should also check the "restrict" keyword.
Every good solution is obvious once you've found it.