Library Builtins (Using the GNU Compiler Collection (GCC)) (original) (raw)


7.1 Builtins for C Library Functions

GCC includes built-in versions of many of the functions in the standard C library. These functions come in two forms: one whose names start with the __builtin_ prefix, and the other without. Both forms have the same type (including prototype), the same address (when their address is taken), and the same meaning as the C library functions even if you specify the -fno-builtin option see Options Controlling C Dialect). Many of these functions are only optimized in certain cases; if they are not optimized in a particular case, a call to the library function is emitted.

Outside strict ISO C mode (-ansi, -std=c90,-std=c99 or -std=c11), the functions_exit, alloca, bcmp, bzero,dcgettext, dgettext, dremf, dreml,drem, exp10f, exp10l, exp10, ffsll,ffsl, ffs, fprintf_unlocked,fputs_unlocked, gammaf, gammal, gamma,gammaf_r, gammal_r, gamma_r, gettext,index, isascii, j0f, j0l, j0,j1f, j1l, j1, jnf, jnl, jn,lgammaf_r, lgammal_r, lgamma_r, mempcpy,pow10f, pow10l, pow10, printf_unlocked,rindex, roundeven, roundevenf, roundevenl,scalbf, scalbl, scalb,signbit, signbitf, signbitl, signbitd32,signbitd64, signbitd128, significandf,significandl, significand, sincosf,sincosl, sincos, stpcpy, stpncpy,strcasecmp, strdup, strfmon, strncasecmp,strndup, strnlen, toascii, y0f, y0l,y0, y1f, y1l, y1, ynf, ynl andynmay be handled as built-in functions. All these functions have corresponding versions prefixed with __builtin_, which may be used even in strict C90 mode.

The ISO C99 functions_Exit, acoshf, acoshl, acosh, asinhf,asinhl, asinh, atanhf, atanhl, atanh,cabsf, cabsl, cabs, cacosf, cacoshf,cacoshl, cacosh, cacosl, cacos,cargf, cargl, carg, casinf, casinhf,casinhl, casinh, casinl, casin,catanf, catanhf, catanhl, catanh,catanl, catan, cbrtf, cbrtl, cbrt,ccosf, ccoshf, ccoshl, ccosh, ccosl,ccos, cexpf, cexpl, cexp, cimagf,cimagl, cimag, clogf, clogl, clog,conjf, conjl, conj, copysignf, copysignl,copysign, cpowf, cpowl, cpow, cprojf,cprojl, cproj, crealf, creall, creal,csinf, csinhf, csinhl, csinh, csinl,csin, csqrtf, csqrtl, csqrt, ctanf,ctanhf, ctanhl, ctanh, ctanl, ctan,erfcf, erfcl, erfc, erff, erfl,erf, exp2f, exp2l, exp2, expm1f,expm1l, expm1, fdimf, fdiml, fdim,fmaf, fmal, fmaxf, fmaxl, fmax,fma, fminf, fminl, fmin, hypotf,hypotl, hypot, ilogbf, ilogbl, ilogb,imaxabs, isblank, iswblank, lgammaf,lgammal, lgamma, llabs, llrintf, llrintl,llrint, llroundf, llroundl, llround,log1pf, log1pl, log1p, log2f, log2l,log2, logbf, logbl, logb, lrintf,lrintl, lrint, lroundf, lroundl,lround, nearbyintf, nearbyintl, nearbyint,nextafterf, nextafterl, nextafter,nexttowardf, nexttowardl, nexttoward,remainderf, remainderl, remainder, remquof,remquol, remquo, rintf, rintl, rint,roundf, roundl, round, scalblnf,scalblnl, scalbln, scalbnf, scalbnl,scalbn, snprintf, tgammaf, tgammal,tgamma, truncf, truncl, trunc,vfscanf, vscanf, vsnprintf and vsscanfare handled as built-in functions except in strict ISO C90 mode (-ansi or -std=c90).

There are also built-in versions of the ISO C99 functionsacosf, acosl, asinf, asinl, atan2f,atan2l, atanf, atanl, ceilf, ceill,cosf, coshf, coshl, cosl, expf,expl, fabsf, fabsl, floorf, floorl,fmodf, fmodl, frexpf, frexpl, ldexpf,ldexpl, log10f, log10l, logf, logl,modfl, modff, powf, powl, sinf,sinhf, sinhl, sinl, sqrtf, sqrtl,tanf, tanhf, tanhl and tanlthat are recognized in any mode since ISO C90 reserves these names for the purpose to which ISO C99 puts them. All these functions have corresponding versions prefixed with __builtin_.

There are also built-in functions __builtin_fabsfn,__builtin_fabsfnx, __builtin_copysignfn and__builtin_copysignfnx, corresponding to the TS 18661-3 functions fabsfn, fabsfnx,copysignfn and copysignfnx, for supported types _Floatn and _Floatnx.

There are also GNU extension functions clog10, clog10f andclog10l which names are reserved by ISO C99 for future use. All these functions have versions prefixed with __builtin_.

The ISO C94 functionsiswalnum, iswalpha, iswcntrl, iswdigit,iswgraph, iswlower, iswprint, iswpunct,iswspace, iswupper, iswxdigit, towlower andtowupperare handled as built-in functions except in strict ISO C90 mode (-ansi or -std=c90).

The ISO C90 functionsabort, abs, acos, asin, atan2,atan, calloc, ceil, cosh, cos,exit, exp, fabs, floor, fmod,fprintf, fputs, free, frexp, fscanf,isalnum, isalpha, iscntrl, isdigit,isgraph, islower, isprint, ispunct,isspace, isupper, isxdigit, tolower,toupper, labs, ldexp, log10, log,malloc, memchr, memcmp, memcpy,memset, modf, pow, printf, putchar,puts, realloc, scanf, sinh, sin,snprintf, sprintf, sqrt, sscanf, strcat,strchr, strcmp, strcpy, strcspn,strlen, strncat, strncmp, strncpy,strpbrk, strrchr, strspn, strstr,tanh, tan, vfprintf, vprintf and vsprintfare all recognized as built-in functions unless-fno-builtin is specified (or -fno-builtin-functionis specified for an individual function). All of these functions have corresponding versions prefixed with __builtin_.

GCC provides built-in versions of the ISO C99 floating-point comparison macros that avoid raising exceptions for unordered operands. They have the same names as the standard macros ( isgreater,isgreaterequal, isless, islessequal,islessgreater, and isunordered) , with __builtin_prefixed. We intend for a library implementor to be able to simply#define each standard macro to its built-in equivalent. In the same fashion, GCC provides fpclassify, iseqsig,isfinite, isinf_sign, isnormal and signbit built-ins used with __builtin_ prefixed. The isinf and isnanbuilt-in functions appear both with and without the __builtin_ prefix. With -ffinite-math-only option the isinf and isnanbuilt-in functions will always return 0.

GCC provides built-in versions of the ISO C99 floating-point rounding and exceptions handling functions fegetround, feclearexcept andferaiseexcept. They may not be available for all targets, and because they need close interaction with libc internal values, they may not be available for all target libcs, but in all cases they will gracefully fallback to libc calls. These built-in functions appear both with and without the__builtin_ prefix.