About __builtin_Functions.
Dhruv Matani
dhruvbird@HotPOP.com
Sun Mar 14 17:23:00 GMT 2004
On Sun, 2004-03-14 at 20:54, Phil Edwards wrote:
> On Sun, Mar 14, 2004 at 06:32:32PM +0530, Dhruv Matani wrote:
> > Hello,
> > I wanted to know whether ALL __builtin_functions are guaranteed to be
> > inlined?
>
> Depends on the function. The URL that I posted earlier contains several
> paragraphs describing when builtins are used and when they aren't.
>
> It should be noted that compiler builtins (formally known as intrinsics,
> if you happen across that term elsewhere) aren't really the same as inline
> functions. There's no "source code" to be inlined for an intrinsic;
> the compiler itself emits the raw instructions.
So, __builtin_expect would be like an intrinsic, which is merely a hint
for the compiler?
>
> Some intrinsics don't emit code, e.g., __builtin_constant_p. Some can only
> be open coded -- again, not the same thing as inlined -- under certain
> circumstances, e.g., the math builtins, or the vector builtins.
Ok, but what exactly is open coded?
>
> My advice would be to pick a __builtin that's interesting to you and look
> to see how it's implemented. That will give you an idea of how they work.
Ok, I tried doing that for the one I'm interested in, which would be:
__builtin_ctz, by greping through the whole gcc include directory, but
couldn't find how it's implemented.
Ok, I did find the bsfl instruction somewhere in the code, but the whole
string __builtin_ctz, no... That's why I can't figure out:
1. How it's implemented, and
2. Whether it will be inlined or not.
I could compile with -S and check, but that would be too tedious for
each and every builtin that I use, and I couldn't even confirm for every
platform on which the code is compiled on.
I saw the compiled code, and it is being inlined on my platform
x86-GNU/Linux. Will it hold for all platforms?
However I could find the macro __builtin_expect which is defined to be a
macro translating to the first expression passed to it, and as you
mentioned about it being an intrinsic, which does not generate any code
so there is no question about inlining.
Thanks.
--
-Dhruv Matani.
http://www.geocities.com/dhruvbird/
Proud to be a Vegetarian.
http://www.vegetarianstarterkit.com/
http://www.vegkids.com/vegkids/index.html
More information about the Libstdc++
mailing list