1c Copyright (C) 1988-2022 Free Software Foundation, Inc. 2 3@c This is part of the GCC manual. 4@c For copying conditions, see the file gcc.texi. 5 6@node C Extensions 7@chapter Extensions to the C Language Family 8@cindex extensions, C language 9@cindex C language extensions 10 11@opindex pedantic 12GNU C provides several language features not found in ISO standard C@. 13(The @option{-pedantic} option directs GCC to print a warning message if 14any of these features is used.) To test for the availability of these 15features in conditional compilation, check for a predefined macro 16@code{__GNUC__}, which is always defined under GCC@. 17 18These extensions are available in C and Objective-C@. Most of them are 19also available in C++. @xref{C++ Extensions,,Extensions to the 20C++ Language}, for extensions that apply @emph{only} to C++. 21 22Some features that are in ISO C99 but not C90 or C++ are also, as 23extensions, accepted by GCC in C90 mode and in C++. 24 25@menu 26* Statement Exprs:: Putting statements and declarations inside expressions. 27* Local Labels:: Labels local to a block. 28* Labels as Values:: Getting pointers to labels, and computed gotos. 29* Nested Functions:: Nested function in GNU C. 30* Nonlocal Gotos:: Nonlocal gotos. 31* Constructing Calls:: Dispatching a call to another function. 32* Typeof:: @code{typeof}: referring to the type of an expression. 33* Conditionals:: Omitting the middle operand of a @samp{?:} expression. 34* __int128:: 128-bit integers---@code{__int128}. 35* Long Long:: Double-word integers---@code{long long int}. 36* Complex:: Data types for complex numbers. 37* Floating Types:: Additional Floating Types. 38* Half-Precision:: Half-Precision Floating Point. 39* Decimal Float:: Decimal Floating Types. 40* Hex Floats:: Hexadecimal floating-point constants. 41* Fixed-Point:: Fixed-Point Types. 42* Named Address Spaces::Named address spaces. 43* Zero Length:: Zero-length arrays. 44* Empty Structures:: Structures with no members. 45* Variable Length:: Arrays whose length is computed at run time. 46* Variadic Macros:: Macros with a variable number of arguments. 47* Escaped Newlines:: Slightly looser rules for escaped newlines. 48* Subscripting:: Any array can be subscripted, even if not an lvalue. 49* Pointer Arith:: Arithmetic on @code{void}-pointers and function pointers. 50* Variadic Pointer Args:: Pointer arguments to variadic functions. 51* Pointers to Arrays:: Pointers to arrays with qualifiers work as expected. 52* Initializers:: Non-constant initializers. 53* Compound Literals:: Compound literals give structures, unions 54 or arrays as values. 55* Designated Inits:: Labeling elements of initializers. 56* Case Ranges:: `case 1 ... 9' and such. 57* Cast to Union:: Casting to union type from any member of the union. 58* Mixed Labels and Declarations:: Mixing declarations, labels and code. 59* Function Attributes:: Declaring that functions have no side effects, 60 or that they can never return. 61* Variable Attributes:: Specifying attributes of variables. 62* Type Attributes:: Specifying attributes of types. 63* Label Attributes:: Specifying attributes on labels. 64* Enumerator Attributes:: Specifying attributes on enumerators. 65* Statement Attributes:: Specifying attributes on statements. 66* Attribute Syntax:: Formal syntax for attributes. 67* Function Prototypes:: Prototype declarations and old-style definitions. 68* C++ Comments:: C++ comments are recognized. 69* Dollar Signs:: Dollar sign is allowed in identifiers. 70* Character Escapes:: @samp{\e} stands for the character @key{ESC}. 71* Alignment:: Determining the alignment of a function, type or variable. 72* Inline:: Defining inline functions (as fast as macros). 73* Volatiles:: What constitutes an access to a volatile object. 74* Using Assembly Language with C:: Instructions and extensions for interfacing C with assembler. 75* Alternate Keywords:: @code{__const__}, @code{__asm__}, etc., for header files. 76* Incomplete Enums:: @code{enum foo;}, with details to follow. 77* Function Names:: Printable strings which are the name of the current 78 function. 79* Return Address:: Getting the return or frame address of a function. 80* Vector Extensions:: Using vector instructions through built-in functions. 81* Offsetof:: Special syntax for implementing @code{offsetof}. 82* __sync Builtins:: Legacy built-in functions for atomic memory access. 83* __atomic Builtins:: Atomic built-in functions with memory model. 84* Integer Overflow Builtins:: Built-in functions to perform arithmetics and 85 arithmetic overflow checking. 86* x86 specific memory model extensions for transactional memory:: x86 memory models. 87* Object Size Checking:: Built-in functions for limited buffer overflow 88 checking. 89* Other Builtins:: Other built-in functions. 90* Target Builtins:: Built-in functions specific to particular targets. 91* Target Format Checks:: Format checks specific to particular targets. 92* Pragmas:: Pragmas accepted by GCC. 93* Unnamed Fields:: Unnamed struct/union fields within structs/unions. 94* Thread-Local:: Per-thread variables. 95* Binary constants:: Binary constants using the @samp{0b} prefix. 96@end menu 97 98@node Statement Exprs 99@section Statements and Declarations in Expressions 100@cindex statements inside expressions 101@cindex declarations inside expressions 102@cindex expressions containing statements 103@cindex macros, statements in expressions 104 105@c the above section title wrapped and causes an underfull hbox.. i 106@c changed it from "within" to "in". --mew 4feb93 107A compound statement enclosed in parentheses may appear as an expression 108in GNU C@. This allows you to use loops, switches, and local variables 109within an expression. 110 111Recall that a compound statement is a sequence of statements surrounded 112by braces; in this construct, parentheses go around the braces. For 113example: 114 115@smallexample 116(@{ int y = foo (); int z; 117 if (y > 0) z = y; 118 else z = - y; 119 z; @}) 120@end smallexample 121 122@noindent 123is a valid (though slightly more complex than necessary) expression 124for the absolute value of @code{foo ()}. 125 126The last thing in the compound statement should be an expression 127followed by a semicolon; the value of this subexpression serves as the 128value of the entire construct. (If you use some other kind of statement 129last within the braces, the construct has type @code{void}, and thus 130effectively no value.) 131 132This feature is especially useful in making macro definitions ``safe'' (so 133that they evaluate each operand exactly once). For example, the 134``maximum'' function is commonly defined as a macro in standard C as 135follows: 136 137@smallexample 138#define max(a,b) ((a) > (b) ? (a) : (b)) 139@end smallexample 140 141@noindent 142@cindex side effects, macro argument 143But this definition computes either @var{a} or @var{b} twice, with bad 144results if the operand has side effects. In GNU C, if you know the 145type of the operands (here taken as @code{int}), you can avoid this 146problem by defining the macro as follows: 147 148@smallexample 149#define maxint(a,b) \ 150 (@{int _a = (a), _b = (b); _a > _b ? _a : _b; @}) 151@end smallexample 152 153Note that introducing variable declarations (as we do in @code{maxint}) can 154cause variable shadowing, so while this example using the @code{max} macro 155produces correct results: 156@smallexample 157int _a = 1, _b = 2, c; 158c = max (_a, _b); 159@end smallexample 160@noindent 161this example using maxint will not: 162@smallexample 163int _a = 1, _b = 2, c; 164c = maxint (_a, _b); 165@end smallexample 166 167This problem may for instance occur when we use this pattern recursively, like 168so: 169 170@smallexample 171#define maxint3(a, b, c) \ 172 (@{int _a = (a), _b = (b), _c = (c); maxint (maxint (_a, _b), _c); @}) 173@end smallexample 174 175Embedded statements are not allowed in constant expressions, such as 176the value of an enumeration constant, the width of a bit-field, or 177the initial value of a static variable. 178 179If you don't know the type of the operand, you can still do this, but you 180must use @code{typeof} or @code{__auto_type} (@pxref{Typeof}). 181 182In G++, the result value of a statement expression undergoes array and 183function pointer decay, and is returned by value to the enclosing 184expression. For instance, if @code{A} is a class, then 185 186@smallexample 187 A a; 188 189 (@{a;@}).Foo () 190@end smallexample 191 192@noindent 193constructs a temporary @code{A} object to hold the result of the 194statement expression, and that is used to invoke @code{Foo}. 195Therefore the @code{this} pointer observed by @code{Foo} is not the 196address of @code{a}. 197 198In a statement expression, any temporaries created within a statement 199are destroyed at that statement's end. This makes statement 200expressions inside macros slightly different from function calls. In 201the latter case temporaries introduced during argument evaluation are 202destroyed at the end of the statement that includes the function 203call. In the statement expression case they are destroyed during 204the statement expression. For instance, 205 206@smallexample 207#define macro(a) (@{__typeof__(a) b = (a); b + 3; @}) 208template<typename T> T function(T a) @{ T b = a; return b + 3; @} 209 210void foo () 211@{ 212 macro (X ()); 213 function (X ()); 214@} 215@end smallexample 216 217@noindent 218has different places where temporaries are destroyed. For the 219@code{macro} case, the temporary @code{X} is destroyed just after 220the initialization of @code{b}. In the @code{function} case that 221temporary is destroyed when the function returns. 222 223These considerations mean that it is probably a bad idea to use 224statement expressions of this form in header files that are designed to 225work with C++. (Note that some versions of the GNU C Library contained 226header files using statement expressions that lead to precisely this 227bug.) 228 229Jumping into a statement expression with @code{goto} or using a 230@code{switch} statement outside the statement expression with a 231@code{case} or @code{default} label inside the statement expression is 232not permitted. Jumping into a statement expression with a computed 233@code{goto} (@pxref{Labels as Values}) has undefined behavior. 234Jumping out of a statement expression is permitted, but if the 235statement expression is part of a larger expression then it is 236unspecified which other subexpressions of that expression have been 237evaluated except where the language definition requires certain 238subexpressions to be evaluated before or after the statement 239expression. A @code{break} or @code{continue} statement inside of 240a statement expression used in @code{while}, @code{do} or @code{for} 241loop or @code{switch} statement condition 242or @code{for} statement init or increment expressions jumps to an 243outer loop or @code{switch} statement if any (otherwise it is an error), 244rather than to the loop or @code{switch} statement in whose condition 245or init or increment expression it appears. 246In any case, as with a function call, the evaluation of a 247statement expression is not interleaved with the evaluation of other 248parts of the containing expression. For example, 249 250@smallexample 251 foo (), ((@{ bar1 (); goto a; 0; @}) + bar2 ()), baz(); 252@end smallexample 253 254@noindent 255calls @code{foo} and @code{bar1} and does not call @code{baz} but 256may or may not call @code{bar2}. If @code{bar2} is called, it is 257called after @code{foo} and before @code{bar1}. 258 259@node Local Labels 260@section Locally Declared Labels 261@cindex local labels 262@cindex macros, local labels 263 264GCC allows you to declare @dfn{local labels} in any nested block 265scope. A local label is just like an ordinary label, but you can 266only reference it (with a @code{goto} statement, or by taking its 267address) within the block in which it is declared. 268 269A local label declaration looks like this: 270 271@smallexample 272__label__ @var{label}; 273@end smallexample 274 275@noindent 276or 277 278@smallexample 279__label__ @var{label1}, @var{label2}, /* @r{@dots{}} */; 280@end smallexample 281 282Local label declarations must come at the beginning of the block, 283before any ordinary declarations or statements. 284 285The label declaration defines the label @emph{name}, but does not define 286the label itself. You must do this in the usual way, with 287@code{@var{label}:}, within the statements of the statement expression. 288 289The local label feature is useful for complex macros. If a macro 290contains nested loops, a @code{goto} can be useful for breaking out of 291them. However, an ordinary label whose scope is the whole function 292cannot be used: if the macro can be expanded several times in one 293function, the label is multiply defined in that function. A 294local label avoids this problem. For example: 295 296@smallexample 297#define SEARCH(value, array, target) \ 298do @{ \ 299 __label__ found; \ 300 typeof (target) _SEARCH_target = (target); \ 301 typeof (*(array)) *_SEARCH_array = (array); \ 302 int i, j; \ 303 int value; \ 304 for (i = 0; i < max; i++) \ 305 for (j = 0; j < max; j++) \ 306 if (_SEARCH_array[i][j] == _SEARCH_target) \ 307 @{ (value) = i; goto found; @} \ 308 (value) = -1; \ 309 found:; \ 310@} while (0) 311@end smallexample 312 313This could also be written using a statement expression: 314 315@smallexample 316#define SEARCH(array, target) \ 317(@{ \ 318 __label__ found; \ 319 typeof (target) _SEARCH_target = (target); \ 320 typeof (*(array)) *_SEARCH_array = (array); \ 321 int i, j; \ 322 int value; \ 323 for (i = 0; i < max; i++) \ 324 for (j = 0; j < max; j++) \ 325 if (_SEARCH_array[i][j] == _SEARCH_target) \ 326 @{ value = i; goto found; @} \ 327 value = -1; \ 328 found: \ 329 value; \ 330@}) 331@end smallexample 332 333Local label declarations also make the labels they declare visible to 334nested functions, if there are any. @xref{Nested Functions}, for details. 335 336@node Labels as Values 337@section Labels as Values 338@cindex labels as values 339@cindex computed gotos 340@cindex goto with computed label 341@cindex address of a label 342 343You can get the address of a label defined in the current function 344(or a containing function) with the unary operator @samp{&&}. The 345value has type @code{void *}. This value is a constant and can be used 346wherever a constant of that type is valid. For example: 347 348@smallexample 349void *ptr; 350/* @r{@dots{}} */ 351ptr = &&foo; 352@end smallexample 353 354To use these values, you need to be able to jump to one. This is done 355with the computed goto statement@footnote{The analogous feature in 356Fortran is called an assigned goto, but that name seems inappropriate in 357C, where one can do more than simply store label addresses in label 358variables.}, @code{goto *@var{exp};}. For example, 359 360@smallexample 361goto *ptr; 362@end smallexample 363 364@noindent 365Any expression of type @code{void *} is allowed. 366 367One way of using these constants is in initializing a static array that 368serves as a jump table: 369 370@smallexample 371static void *array[] = @{ &&foo, &&bar, &&hack @}; 372@end smallexample 373 374@noindent 375Then you can select a label with indexing, like this: 376 377@smallexample 378goto *array[i]; 379@end smallexample 380 381@noindent 382Note that this does not check whether the subscript is in bounds---array 383indexing in C never does that. 384 385Such an array of label values serves a purpose much like that of the 386@code{switch} statement. The @code{switch} statement is cleaner, so 387use that rather than an array unless the problem does not fit a 388@code{switch} statement very well. 389 390Another use of label values is in an interpreter for threaded code. 391The labels within the interpreter function can be stored in the 392threaded code for super-fast dispatching. 393 394You may not use this mechanism to jump to code in a different function. 395If you do that, totally unpredictable things happen. The best way to 396avoid this is to store the label address only in automatic variables and 397never pass it as an argument. 398 399An alternate way to write the above example is 400 401@smallexample 402static const int array[] = @{ &&foo - &&foo, &&bar - &&foo, 403 &&hack - &&foo @}; 404goto *(&&foo + array[i]); 405@end smallexample 406 407@noindent 408This is more friendly to code living in shared libraries, as it reduces 409the number of dynamic relocations that are needed, and by consequence, 410allows the data to be read-only. 411This alternative with label differences is not supported for the AVR target, 412please use the first approach for AVR programs. 413 414The @code{&&foo} expressions for the same label might have different 415values if the containing function is inlined or cloned. If a program 416relies on them being always the same, 417@code{__attribute__((__noinline__,__noclone__))} should be used to 418prevent inlining and cloning. If @code{&&foo} is used in a static 419variable initializer, inlining and cloning is forbidden. 420 421@node Nested Functions 422@section Nested Functions 423@cindex nested functions 424@cindex downward funargs 425@cindex thunks 426 427A @dfn{nested function} is a function defined inside another function. 428Nested functions are supported as an extension in GNU C, but are not 429supported by GNU C++. 430 431The nested function's name is local to the block where it is defined. 432For example, here we define a nested function named @code{square}, and 433call it twice: 434 435@smallexample 436@group 437foo (double a, double b) 438@{ 439 double square (double z) @{ return z * z; @} 440 441 return square (a) + square (b); 442@} 443@end group 444@end smallexample 445 446The nested function can access all the variables of the containing 447function that are visible at the point of its definition. This is 448called @dfn{lexical scoping}. For example, here we show a nested 449function which uses an inherited variable named @code{offset}: 450 451@smallexample 452@group 453bar (int *array, int offset, int size) 454@{ 455 int access (int *array, int index) 456 @{ return array[index + offset]; @} 457 int i; 458 /* @r{@dots{}} */ 459 for (i = 0; i < size; i++) 460 /* @r{@dots{}} */ access (array, i) /* @r{@dots{}} */ 461@} 462@end group 463@end smallexample 464 465Nested function definitions are permitted within functions in the places 466where variable definitions are allowed; that is, in any block, mixed 467with the other declarations and statements in the block. 468 469It is possible to call the nested function from outside the scope of its 470name by storing its address or passing the address to another function: 471 472@smallexample 473hack (int *array, int size) 474@{ 475 void store (int index, int value) 476 @{ array[index] = value; @} 477 478 intermediate (store, size); 479@} 480@end smallexample 481 482Here, the function @code{intermediate} receives the address of 483@code{store} as an argument. If @code{intermediate} calls @code{store}, 484the arguments given to @code{store} are used to store into @code{array}. 485But this technique works only so long as the containing function 486(@code{hack}, in this example) does not exit. 487 488If you try to call the nested function through its address after the 489containing function exits, all hell breaks loose. If you try 490to call it after a containing scope level exits, and if it refers 491to some of the variables that are no longer in scope, you may be lucky, 492but it's not wise to take the risk. If, however, the nested function 493does not refer to anything that has gone out of scope, you should be 494safe. 495 496GCC implements taking the address of a nested function using a technique 497called @dfn{trampolines}. This technique was described in 498@cite{Lexical Closures for C++} (Thomas M. Breuel, USENIX 499C++ Conference Proceedings, October 17-21, 1988). 500 501A nested function can jump to a label inherited from a containing 502function, provided the label is explicitly declared in the containing 503function (@pxref{Local Labels}). Such a jump returns instantly to the 504containing function, exiting the nested function that did the 505@code{goto} and any intermediate functions as well. Here is an example: 506 507@smallexample 508@group 509bar (int *array, int offset, int size) 510@{ 511 __label__ failure; 512 int access (int *array, int index) 513 @{ 514 if (index > size) 515 goto failure; 516 return array[index + offset]; 517 @} 518 int i; 519 /* @r{@dots{}} */ 520 for (i = 0; i < size; i++) 521 /* @r{@dots{}} */ access (array, i) /* @r{@dots{}} */ 522 /* @r{@dots{}} */ 523 return 0; 524 525 /* @r{Control comes here from @code{access} 526 if it detects an error.} */ 527 failure: 528 return -1; 529@} 530@end group 531@end smallexample 532 533A nested function always has no linkage. Declaring one with 534@code{extern} or @code{static} is erroneous. If you need to declare the nested function 535before its definition, use @code{auto} (which is otherwise meaningless 536for function declarations). 537 538@smallexample 539bar (int *array, int offset, int size) 540@{ 541 __label__ failure; 542 auto int access (int *, int); 543 /* @r{@dots{}} */ 544 int access (int *array, int index) 545 @{ 546 if (index > size) 547 goto failure; 548 return array[index + offset]; 549 @} 550 /* @r{@dots{}} */ 551@} 552@end smallexample 553 554@node Nonlocal Gotos 555@section Nonlocal Gotos 556@cindex nonlocal gotos 557 558GCC provides the built-in functions @code{__builtin_setjmp} and 559@code{__builtin_longjmp} which are similar to, but not interchangeable 560with, the C library functions @code{setjmp} and @code{longjmp}. 561The built-in versions are used internally by GCC's libraries 562to implement exception handling on some targets. You should use the 563standard C library functions declared in @code{<setjmp.h>} in user code 564instead of the builtins. 565 566The built-in versions of these functions use GCC's normal 567mechanisms to save and restore registers using the stack on function 568entry and exit. The jump buffer argument @var{buf} holds only the 569information needed to restore the stack frame, rather than the entire 570set of saved register values. 571 572An important caveat is that GCC arranges to save and restore only 573those registers known to the specific architecture variant being 574compiled for. This can make @code{__builtin_setjmp} and 575@code{__builtin_longjmp} more efficient than their library 576counterparts in some cases, but it can also cause incorrect and 577mysterious behavior when mixing with code that uses the full register 578set. 579 580You should declare the jump buffer argument @var{buf} to the 581built-in functions as: 582 583@smallexample 584#include <stdint.h> 585intptr_t @var{buf}[5]; 586@end smallexample 587 588@deftypefn {Built-in Function} {int} __builtin_setjmp (intptr_t *@var{buf}) 589This function saves the current stack context in @var{buf}. 590@code{__builtin_setjmp} returns 0 when returning directly, 591and 1 when returning from @code{__builtin_longjmp} using the same 592@var{buf}. 593@end deftypefn 594 595@deftypefn {Built-in Function} {void} __builtin_longjmp (intptr_t *@var{buf}, int @var{val}) 596This function restores the stack context in @var{buf}, 597saved by a previous call to @code{__builtin_setjmp}. After 598@code{__builtin_longjmp} is finished, the program resumes execution as 599if the matching @code{__builtin_setjmp} returns the value @var{val}, 600which must be 1. 601 602Because @code{__builtin_longjmp} depends on the function return 603mechanism to restore the stack context, it cannot be called 604from the same function calling @code{__builtin_setjmp} to 605initialize @var{buf}. It can only be called from a function called 606(directly or indirectly) from the function calling @code{__builtin_setjmp}. 607@end deftypefn 608 609@node Constructing Calls 610@section Constructing Function Calls 611@cindex constructing calls 612@cindex forwarding calls 613 614Using the built-in functions described below, you can record 615the arguments a function received, and call another function 616with the same arguments, without knowing the number or types 617of the arguments. 618 619You can also record the return value of that function call, 620and later return that value, without knowing what data type 621the function tried to return (as long as your caller expects 622that data type). 623 624However, these built-in functions may interact badly with some 625sophisticated features or other extensions of the language. It 626is, therefore, not recommended to use them outside very simple 627functions acting as mere forwarders for their arguments. 628 629@deftypefn {Built-in Function} {void *} __builtin_apply_args () 630This built-in function returns a pointer to data 631describing how to perform a call with the same arguments as are passed 632to the current function. 633 634The function saves the arg pointer register, structure value address, 635and all registers that might be used to pass arguments to a function 636into a block of memory allocated on the stack. Then it returns the 637address of that block. 638@end deftypefn 639 640@deftypefn {Built-in Function} {void *} __builtin_apply (void (*@var{function})(), void *@var{arguments}, size_t @var{size}) 641This built-in function invokes @var{function} 642with a copy of the parameters described by @var{arguments} 643and @var{size}. 644 645The value of @var{arguments} should be the value returned by 646@code{__builtin_apply_args}. The argument @var{size} specifies the size 647of the stack argument data, in bytes. 648 649This function returns a pointer to data describing 650how to return whatever value is returned by @var{function}. The data 651is saved in a block of memory allocated on the stack. 652 653It is not always simple to compute the proper value for @var{size}. The 654value is used by @code{__builtin_apply} to compute the amount of data 655that should be pushed on the stack and copied from the incoming argument 656area. 657@end deftypefn 658 659@deftypefn {Built-in Function} {void} __builtin_return (void *@var{result}) 660This built-in function returns the value described by @var{result} from 661the containing function. You should specify, for @var{result}, a value 662returned by @code{__builtin_apply}. 663@end deftypefn 664 665@deftypefn {Built-in Function} {} __builtin_va_arg_pack () 666This built-in function represents all anonymous arguments of an inline 667function. It can be used only in inline functions that are always 668inlined, never compiled as a separate function, such as those using 669@code{__attribute__ ((__always_inline__))} or 670@code{__attribute__ ((__gnu_inline__))} extern inline functions. 671It must be only passed as last argument to some other function 672with variable arguments. This is useful for writing small wrapper 673inlines for variable argument functions, when using preprocessor 674macros is undesirable. For example: 675@smallexample 676extern int myprintf (FILE *f, const char *format, ...); 677extern inline __attribute__ ((__gnu_inline__)) int 678myprintf (FILE *f, const char *format, ...) 679@{ 680 int r = fprintf (f, "myprintf: "); 681 if (r < 0) 682 return r; 683 int s = fprintf (f, format, __builtin_va_arg_pack ()); 684 if (s < 0) 685 return s; 686 return r + s; 687@} 688@end smallexample 689@end deftypefn 690 691@deftypefn {Built-in Function} {int} __builtin_va_arg_pack_len () 692This built-in function returns the number of anonymous arguments of 693an inline function. It can be used only in inline functions that 694are always inlined, never compiled as a separate function, such 695as those using @code{__attribute__ ((__always_inline__))} or 696@code{__attribute__ ((__gnu_inline__))} extern inline functions. 697For example following does link- or run-time checking of open 698arguments for optimized code: 699@smallexample 700#ifdef __OPTIMIZE__ 701extern inline __attribute__((__gnu_inline__)) int 702myopen (const char *path, int oflag, ...) 703@{ 704 if (__builtin_va_arg_pack_len () > 1) 705 warn_open_too_many_arguments (); 706 707 if (__builtin_constant_p (oflag)) 708 @{ 709 if ((oflag & O_CREAT) != 0 && __builtin_va_arg_pack_len () < 1) 710 @{ 711 warn_open_missing_mode (); 712 return __open_2 (path, oflag); 713 @} 714 return open (path, oflag, __builtin_va_arg_pack ()); 715 @} 716 717 if (__builtin_va_arg_pack_len () < 1) 718 return __open_2 (path, oflag); 719 720 return open (path, oflag, __builtin_va_arg_pack ()); 721@} 722#endif 723@end smallexample 724@end deftypefn 725 726@node Typeof 727@section Referring to a Type with @code{typeof} 728@findex typeof 729@findex sizeof 730@cindex macros, types of arguments 731 732Another way to refer to the type of an expression is with @code{typeof}. 733The syntax of using of this keyword looks like @code{sizeof}, but the 734construct acts semantically like a type name defined with @code{typedef}. 735 736There are two ways of writing the argument to @code{typeof}: with an 737expression or with a type. Here is an example with an expression: 738 739@smallexample 740typeof (x[0](1)) 741@end smallexample 742 743@noindent 744This assumes that @code{x} is an array of pointers to functions; 745the type described is that of the values of the functions. 746 747Here is an example with a typename as the argument: 748 749@smallexample 750typeof (int *) 751@end smallexample 752 753@noindent 754Here the type described is that of pointers to @code{int}. 755 756If you are writing a header file that must work when included in ISO C 757programs, write @code{__typeof__} instead of @code{typeof}. 758@xref{Alternate Keywords}. 759 760A @code{typeof} construct can be used anywhere a typedef name can be 761used. For example, you can use it in a declaration, in a cast, or inside 762of @code{sizeof} or @code{typeof}. 763 764The operand of @code{typeof} is evaluated for its side effects if and 765only if it is an expression of variably modified type or the name of 766such a type. 767 768@code{typeof} is often useful in conjunction with 769statement expressions (@pxref{Statement Exprs}). 770Here is how the two together can 771be used to define a safe ``maximum'' macro which operates on any 772arithmetic type and evaluates each of its arguments exactly once: 773 774@smallexample 775#define max(a,b) \ 776 (@{ typeof (a) _a = (a); \ 777 typeof (b) _b = (b); \ 778 _a > _b ? _a : _b; @}) 779@end smallexample 780 781@cindex underscores in variables in macros 782@cindex @samp{_} in variables in macros 783@cindex local variables in macros 784@cindex variables, local, in macros 785@cindex macros, local variables in 786 787The reason for using names that start with underscores for the local 788variables is to avoid conflicts with variable names that occur within the 789expressions that are substituted for @code{a} and @code{b}. Eventually we 790hope to design a new form of declaration syntax that allows you to declare 791variables whose scopes start only after their initializers; this will be a 792more reliable way to prevent such conflicts. 793 794@noindent 795Some more examples of the use of @code{typeof}: 796 797@itemize @bullet 798@item 799This declares @code{y} with the type of what @code{x} points to. 800 801@smallexample 802typeof (*x) y; 803@end smallexample 804 805@item 806This declares @code{y} as an array of such values. 807 808@smallexample 809typeof (*x) y[4]; 810@end smallexample 811 812@item 813This declares @code{y} as an array of pointers to characters: 814 815@smallexample 816typeof (typeof (char *)[4]) y; 817@end smallexample 818 819@noindent 820It is equivalent to the following traditional C declaration: 821 822@smallexample 823char *y[4]; 824@end smallexample 825 826To see the meaning of the declaration using @code{typeof}, and why it 827might be a useful way to write, rewrite it with these macros: 828 829@smallexample 830#define pointer(T) typeof(T *) 831#define array(T, N) typeof(T [N]) 832@end smallexample 833 834@noindent 835Now the declaration can be rewritten this way: 836 837@smallexample 838array (pointer (char), 4) y; 839@end smallexample 840 841@noindent 842Thus, @code{array (pointer (char), 4)} is the type of arrays of 4 843pointers to @code{char}. 844@end itemize 845 846In GNU C, but not GNU C++, you may also declare the type of a variable 847as @code{__auto_type}. In that case, the declaration must declare 848only one variable, whose declarator must just be an identifier, the 849declaration must be initialized, and the type of the variable is 850determined by the initializer; the name of the variable is not in 851scope until after the initializer. (In C++, you should use C++11 852@code{auto} for this purpose.) Using @code{__auto_type}, the 853``maximum'' macro above could be written as: 854 855@smallexample 856#define max(a,b) \ 857 (@{ __auto_type _a = (a); \ 858 __auto_type _b = (b); \ 859 _a > _b ? _a : _b; @}) 860@end smallexample 861 862Using @code{__auto_type} instead of @code{typeof} has two advantages: 863 864@itemize @bullet 865@item Each argument to the macro appears only once in the expansion of 866the macro. This prevents the size of the macro expansion growing 867exponentially when calls to such macros are nested inside arguments of 868such macros. 869 870@item If the argument to the macro has variably modified type, it is 871evaluated only once when using @code{__auto_type}, but twice if 872@code{typeof} is used. 873@end itemize 874 875@node Conditionals 876@section Conditionals with Omitted Operands 877@cindex conditional expressions, extensions 878@cindex omitted middle-operands 879@cindex middle-operands, omitted 880@cindex extensions, @code{?:} 881@cindex @code{?:} extensions 882 883The middle operand in a conditional expression may be omitted. Then 884if the first operand is nonzero, its value is the value of the conditional 885expression. 886 887Therefore, the expression 888 889@smallexample 890x ? : y 891@end smallexample 892 893@noindent 894has the value of @code{x} if that is nonzero; otherwise, the value of 895@code{y}. 896 897This example is perfectly equivalent to 898 899@smallexample 900x ? x : y 901@end smallexample 902 903@cindex side effect in @code{?:} 904@cindex @code{?:} side effect 905@noindent 906In this simple case, the ability to omit the middle operand is not 907especially useful. When it becomes useful is when the first operand does, 908or may (if it is a macro argument), contain a side effect. Then repeating 909the operand in the middle would perform the side effect twice. Omitting 910the middle operand uses the value already computed without the undesirable 911effects of recomputing it. 912 913@node __int128 914@section 128-bit Integers 915@cindex @code{__int128} data types 916 917As an extension the integer scalar type @code{__int128} is supported for 918targets which have an integer mode wide enough to hold 128 bits. 919Simply write @code{__int128} for a signed 128-bit integer, or 920@code{unsigned __int128} for an unsigned 128-bit integer. There is no 921support in GCC for expressing an integer constant of type @code{__int128} 922for targets with @code{long long} integer less than 128 bits wide. 923 924@node Long Long 925@section Double-Word Integers 926@cindex @code{long long} data types 927@cindex double-word arithmetic 928@cindex multiprecision arithmetic 929@cindex @code{LL} integer suffix 930@cindex @code{ULL} integer suffix 931 932ISO C99 and ISO C++11 support data types for integers that are at least 93364 bits wide, and as an extension GCC supports them in C90 and C++98 modes. 934Simply write @code{long long int} for a signed integer, or 935@code{unsigned long long int} for an unsigned integer. To make an 936integer constant of type @code{long long int}, add the suffix @samp{LL} 937to the integer. To make an integer constant of type @code{unsigned long 938long int}, add the suffix @samp{ULL} to the integer. 939 940You can use these types in arithmetic like any other integer types. 941Addition, subtraction, and bitwise boolean operations on these types 942are open-coded on all types of machines. Multiplication is open-coded 943if the machine supports a fullword-to-doubleword widening multiply 944instruction. Division and shifts are open-coded only on machines that 945provide special support. The operations that are not open-coded use 946special library routines that come with GCC@. 947 948There may be pitfalls when you use @code{long long} types for function 949arguments without function prototypes. If a function 950expects type @code{int} for its argument, and you pass a value of type 951@code{long long int}, confusion results because the caller and the 952subroutine disagree about the number of bytes for the argument. 953Likewise, if the function expects @code{long long int} and you pass 954@code{int}. The best way to avoid such problems is to use prototypes. 955 956@node Complex 957@section Complex Numbers 958@cindex complex numbers 959@cindex @code{_Complex} keyword 960@cindex @code{__complex__} keyword 961 962ISO C99 supports complex floating data types, and as an extension GCC 963supports them in C90 mode and in C++. GCC also supports complex integer data 964types which are not part of ISO C99. You can declare complex types 965using the keyword @code{_Complex}. As an extension, the older GNU 966keyword @code{__complex__} is also supported. 967 968For example, @samp{_Complex double x;} declares @code{x} as a 969variable whose real part and imaginary part are both of type 970@code{double}. @samp{_Complex short int y;} declares @code{y} to 971have real and imaginary parts of type @code{short int}; this is not 972likely to be useful, but it shows that the set of complex types is 973complete. 974 975To write a constant with a complex data type, use the suffix @samp{i} or 976@samp{j} (either one; they are equivalent). For example, @code{2.5fi} 977has type @code{_Complex float} and @code{3i} has type 978@code{_Complex int}. Such a constant always has a pure imaginary 979value, but you can form any complex value you like by adding one to a 980real constant. This is a GNU extension; if you have an ISO C99 981conforming C library (such as the GNU C Library), and want to construct complex 982constants of floating type, you should include @code{<complex.h>} and 983use the macros @code{I} or @code{_Complex_I} instead. 984 985The ISO C++14 library also defines the @samp{i} suffix, so C++14 code 986that includes the @samp{<complex>} header cannot use @samp{i} for the 987GNU extension. The @samp{j} suffix still has the GNU meaning. 988 989GCC can handle both implicit and explicit casts between the @code{_Complex} 990types and other @code{_Complex} types as casting both the real and imaginary 991parts to the scalar type. 992GCC can handle implicit and explicit casts from a scalar type to a @code{_Complex} 993type and where the imaginary part will be considered zero. 994The C front-end can handle implicit and explicit casts from a @code{_Complex} type 995to a scalar type where the imaginary part will be ignored. In C++ code, this cast 996is considered illformed and G++ will error out. 997 998GCC provides a built-in function @code{__builtin_complex} will can be used to 999construct a complex value. 1000 1001@cindex @code{__real__} keyword 1002@cindex @code{__imag__} keyword 1003 1004GCC has a few extensions which can be used to extract the real 1005and the imaginary part of the complex-valued expression. Note 1006these expressions are lvalues if the @var{exp} is an lvalue. 1007These expressions operands have the type of a complex type 1008which might get prompoted to a complex type from a scalar type. 1009E.g. @code{__real__ (int)@var{x}} is the same as casting to 1010@code{_Complex int} before @code{__real__} is done. 1011 1012@multitable @columnfractions .4 .6 1013@headitem Expression @tab Description 1014@item @code{__real__ @var{exp}} 1015@tab Extract the real part of @var{exp}. 1016@item @code{__imag__ @var{exp}} 1017@tab Extract the imaginary part of @var{exp}. 1018@end multitable 1019 1020For values of floating point, you should use the ISO C99 1021functions, declared in @code{<complex.h>} and also provided as 1022built-in functions by GCC@. 1023 1024@multitable @columnfractions .4 .2 .2 .2 1025@headitem Expression @tab float @tab double @tab long double 1026@item @code{__real__ @var{exp}} 1027@tab @code{crealf} @tab @code{creal} @tab @code{creall} 1028@item @code{__imag__ @var{exp}} 1029@tab @code{cimagf} @tab @code{cimag} @tab @code{cimagl} 1030@end multitable 1031 1032@cindex complex conjugation 1033The operator @samp{~} performs complex conjugation when used on a value 1034with a complex type. This is a GNU extension; for values of 1035floating type, you should use the ISO C99 functions @code{conjf}, 1036@code{conj} and @code{conjl}, declared in @code{<complex.h>} and also 1037provided as built-in functions by GCC@. Note unlike the @code{__real__} 1038and @code{__imag__} operators, this operator will not do an implicit cast 1039to the complex type because the @samp{~} is already a normal operator. 1040 1041GCC can allocate complex automatic variables in a noncontiguous 1042fashion; it's even possible for the real part to be in a register while 1043the imaginary part is on the stack (or vice versa). Only the DWARF 1044debug info format can represent this, so use of DWARF is recommended. 1045If you are using the stabs debug info format, GCC describes a noncontiguous 1046complex variable as if it were two separate variables of noncomplex type. 1047If the variable's actual name is @code{foo}, the two fictitious 1048variables are named @code{foo$real} and @code{foo$imag}. You can 1049examine and set these two fictitious variables with your debugger. 1050 1051@deftypefn {Built-in Function} @var{type} __builtin_complex (@var{real}, @var{imag}) 1052 1053The built-in function @code{__builtin_complex} is provided for use in 1054implementing the ISO C11 macros @code{CMPLXF}, @code{CMPLX} and 1055@code{CMPLXL}. @var{real} and @var{imag} must have the same type, a 1056real binary floating-point type, and the result has the corresponding 1057complex type with real and imaginary parts @var{real} and @var{imag}. 1058Unlike @samp{@var{real} + I * @var{imag}}, this works even when 1059infinities, NaNs and negative zeros are involved. 1060 1061@end deftypefn 1062 1063@node Floating Types 1064@section Additional Floating Types 1065@cindex additional floating types 1066@cindex @code{_Float@var{n}} data types 1067@cindex @code{_Float@var{n}x} data types 1068@cindex @code{__float80} data type 1069@cindex @code{__float128} data type 1070@cindex @code{__ibm128} data type 1071@cindex @code{w} floating point suffix 1072@cindex @code{q} floating point suffix 1073@cindex @code{W} floating point suffix 1074@cindex @code{Q} floating point suffix 1075 1076ISO/IEC TS 18661-3:2015 defines C support for additional floating 1077types @code{_Float@var{n}} and @code{_Float@var{n}x}, and GCC supports 1078these type names; the set of types supported depends on the target 1079architecture. These types are not supported when compiling C++. 1080Constants with these types use suffixes @code{f@var{n}} or 1081@code{F@var{n}} and @code{f@var{n}x} or @code{F@var{n}x}. These type 1082names can be used together with @code{_Complex} to declare complex 1083types. 1084 1085As an extension, GNU C and GNU C++ support additional floating 1086types, which are not supported by all targets. 1087@itemize @bullet 1088@item @code{__float128} is available on i386, x86_64, IA-64, and 1089hppa HP-UX, as well as on PowerPC GNU/Linux targets that enable 1090the vector scalar (VSX) instruction set. @code{__float128} supports 1091the 128-bit floating type. On i386, x86_64, PowerPC, and IA-64 1092other than HP-UX, @code{__float128} is an alias for @code{_Float128}. 1093On hppa and IA-64 HP-UX, @code{__float128} is an alias for @code{long 1094double}. 1095 1096@item @code{__float80} is available on the i386, x86_64, and IA-64 1097targets, and supports the 80-bit (@code{XFmode}) floating type. It is 1098an alias for the type name @code{_Float64x} on these targets. 1099 1100@item @code{__ibm128} is available on PowerPC targets, and provides 1101access to the IBM extended double format which is the current format 1102used for @code{long double}. When @code{long double} transitions to 1103@code{__float128} on PowerPC in the future, @code{__ibm128} will remain 1104for use in conversions between the two types. 1105@end itemize 1106 1107Support for these additional types includes the arithmetic operators: 1108add, subtract, multiply, divide; unary arithmetic operators; 1109relational operators; equality operators; and conversions to and from 1110integer and other floating types. Use a suffix @samp{w} or @samp{W} 1111in a literal constant of type @code{__float80} or type 1112@code{__ibm128}. Use a suffix @samp{q} or @samp{Q} for @code{_float128}. 1113 1114In order to use @code{_Float128}, @code{__float128}, and @code{__ibm128} 1115on PowerPC Linux systems, you must use the @option{-mfloat128} option. It is 1116expected in future versions of GCC that @code{_Float128} and @code{__float128} 1117will be enabled automatically. 1118 1119The @code{_Float128} type is supported on all systems where 1120@code{__float128} is supported or where @code{long double} has the 1121IEEE binary128 format. The @code{_Float64x} type is supported on all 1122systems where @code{__float128} is supported. The @code{_Float32} 1123type is supported on all systems supporting IEEE binary32; the 1124@code{_Float64} and @code{_Float32x} types are supported on all systems 1125supporting IEEE binary64. The @code{_Float16} type is supported on AArch64 1126systems by default, on ARM systems when the IEEE format for 16-bit 1127floating-point types is selected with @option{-mfp16-format=ieee} and, 1128for both C and C++, on x86 systems with SSE2 enabled. GCC does not currently 1129support @code{_Float128x} on any systems. 1130 1131On the i386, x86_64, IA-64, and HP-UX targets, you can declare complex 1132types using the corresponding internal complex type, @code{XCmode} for 1133@code{__float80} type and @code{TCmode} for @code{__float128} type: 1134 1135@smallexample 1136typedef _Complex float __attribute__((mode(TC))) _Complex128; 1137typedef _Complex float __attribute__((mode(XC))) _Complex80; 1138@end smallexample 1139 1140On the PowerPC Linux VSX targets, you can declare complex types using 1141the corresponding internal complex type, @code{KCmode} for 1142@code{__float128} type and @code{ICmode} for @code{__ibm128} type: 1143 1144@smallexample 1145typedef _Complex float __attribute__((mode(KC))) _Complex_float128; 1146typedef _Complex float __attribute__((mode(IC))) _Complex_ibm128; 1147@end smallexample 1148 1149@node Half-Precision 1150@section Half-Precision Floating Point 1151@cindex half-precision floating point 1152@cindex @code{__fp16} data type 1153@cindex @code{__Float16} data type 1154 1155On ARM and AArch64 targets, GCC supports half-precision (16-bit) floating 1156point via the @code{__fp16} type defined in the ARM C Language Extensions. 1157On ARM systems, you must enable this type explicitly with the 1158@option{-mfp16-format} command-line option in order to use it. 1159On x86 targets with SSE2 enabled, GCC supports half-precision (16-bit) 1160floating point via the @code{_Float16} type. For C++, x86 provides a builtin 1161type named @code{_Float16} which contains same data format as C. 1162 1163ARM targets support two incompatible representations for half-precision 1164floating-point values. You must choose one of the representations and 1165use it consistently in your program. 1166 1167Specifying @option{-mfp16-format=ieee} selects the IEEE 754-2008 format. 1168This format can represent normalized values in the range of @math{2^{-14}} to 65504. 1169There are 11 bits of significand precision, approximately 3 1170decimal digits. 1171 1172Specifying @option{-mfp16-format=alternative} selects the ARM 1173alternative format. This representation is similar to the IEEE 1174format, but does not support infinities or NaNs. Instead, the range 1175of exponents is extended, so that this format can represent normalized 1176values in the range of @math{2^{-14}} to 131008. 1177 1178The GCC port for AArch64 only supports the IEEE 754-2008 format, and does 1179not require use of the @option{-mfp16-format} command-line option. 1180 1181The @code{__fp16} type may only be used as an argument to intrinsics defined 1182in @code{<arm_fp16.h>}, or as a storage format. For purposes of 1183arithmetic and other operations, @code{__fp16} values in C or C++ 1184expressions are automatically promoted to @code{float}. 1185 1186The ARM target provides hardware support for conversions between 1187@code{__fp16} and @code{float} values 1188as an extension to VFP and NEON (Advanced SIMD), and from ARMv8-A provides 1189hardware support for conversions between @code{__fp16} and @code{double} 1190values. GCC generates code using these hardware instructions if you 1191compile with options to select an FPU that provides them; 1192for example, @option{-mfpu=neon-fp16 -mfloat-abi=softfp}, 1193in addition to the @option{-mfp16-format} option to select 1194a half-precision format. 1195 1196Language-level support for the @code{__fp16} data type is 1197independent of whether GCC generates code using hardware floating-point 1198instructions. In cases where hardware support is not specified, GCC 1199implements conversions between @code{__fp16} and other types as library 1200calls. 1201 1202It is recommended that portable code use the @code{_Float16} type defined 1203by ISO/IEC TS 18661-3:2015. @xref{Floating Types}. 1204 1205On x86 targets with SSE2 enabled, without @option{-mavx512fp16}, 1206all operations will be emulated by software emulation and the @code{float} 1207instructions. The default behavior for @code{FLT_EVAL_METHOD} is to keep the 1208intermediate result of the operation as 32-bit precision. This may lead to 1209inconsistent behavior between software emulation and AVX512-FP16 instructions. 1210Using @option{-fexcess-precision=16} will force round back after each operation. 1211 1212Using @option{-mavx512fp16} will generate AVX512-FP16 instructions instead of 1213software emulation. The default behavior of @code{FLT_EVAL_METHOD} is to round 1214after each operation. The same is true with @option{-fexcess-precision=standard} 1215and @option{-mfpmath=sse}. If there is no @option{-mfpmath=sse}, 1216@option{-fexcess-precision=standard} alone does the same thing as before, 1217It is useful for code that does not have @code{_Float16} and runs on the x87 1218FPU. 1219 1220@node Decimal Float 1221@section Decimal Floating Types 1222@cindex decimal floating types 1223@cindex @code{_Decimal32} data type 1224@cindex @code{_Decimal64} data type 1225@cindex @code{_Decimal128} data type 1226@cindex @code{df} integer suffix 1227@cindex @code{dd} integer suffix 1228@cindex @code{dl} integer suffix 1229@cindex @code{DF} integer suffix 1230@cindex @code{DD} integer suffix 1231@cindex @code{DL} integer suffix 1232 1233As an extension, GNU C supports decimal floating types as 1234defined in the N1312 draft of ISO/IEC WDTR24732. Support for decimal 1235floating types in GCC will evolve as the draft technical report changes. 1236Calling conventions for any target might also change. Not all targets 1237support decimal floating types. 1238 1239The decimal floating types are @code{_Decimal32}, @code{_Decimal64}, and 1240@code{_Decimal128}. They use a radix of ten, unlike the floating types 1241@code{float}, @code{double}, and @code{long double} whose radix is not 1242specified by the C standard but is usually two. 1243 1244Support for decimal floating types includes the arithmetic operators 1245add, subtract, multiply, divide; unary arithmetic operators; 1246relational operators; equality operators; and conversions to and from 1247integer and other floating types. Use a suffix @samp{df} or 1248@samp{DF} in a literal constant of type @code{_Decimal32}, @samp{dd} 1249or @samp{DD} for @code{_Decimal64}, and @samp{dl} or @samp{DL} for 1250@code{_Decimal128}. 1251 1252GCC support of decimal float as specified by the draft technical report 1253is incomplete: 1254 1255@itemize @bullet 1256@item 1257When the value of a decimal floating type cannot be represented in the 1258integer type to which it is being converted, the result is undefined 1259rather than the result value specified by the draft technical report. 1260 1261@item 1262GCC does not provide the C library functionality associated with 1263@file{math.h}, @file{fenv.h}, @file{stdio.h}, @file{stdlib.h}, and 1264@file{wchar.h}, which must come from a separate C library implementation. 1265Because of this the GNU C compiler does not define macro 1266@code{__STDC_DEC_FP__} to indicate that the implementation conforms to 1267the technical report. 1268@end itemize 1269 1270Types @code{_Decimal32}, @code{_Decimal64}, and @code{_Decimal128} 1271are supported by the DWARF debug information format. 1272 1273@node Hex Floats 1274@section Hex Floats 1275@cindex hex floats 1276 1277ISO C99 and ISO C++17 support floating-point numbers written not only in 1278the usual decimal notation, such as @code{1.55e1}, but also numbers such as 1279@code{0x1.fp3} written in hexadecimal format. As a GNU extension, GCC 1280supports this in C90 mode (except in some cases when strictly 1281conforming) and in C++98, C++11 and C++14 modes. In that format the 1282@samp{0x} hex introducer and the @samp{p} or @samp{P} exponent field are 1283mandatory. The exponent is a decimal number that indicates the power of 12842 by which the significant part is multiplied. Thus @samp{0x1.f} is 1285@tex 1286$1 {15\over16}$, 1287@end tex 1288@ifnottex 12891 15/16, 1290@end ifnottex 1291@samp{p3} multiplies it by 8, and the value of @code{0x1.fp3} 1292is the same as @code{1.55e1}. 1293 1294Unlike for floating-point numbers in the decimal notation the exponent 1295is always required in the hexadecimal notation. Otherwise the compiler 1296would not be able to resolve the ambiguity of, e.g., @code{0x1.f}. This 1297could mean @code{1.0f} or @code{1.9375} since @samp{f} is also the 1298extension for floating-point constants of type @code{float}. 1299 1300@node Fixed-Point 1301@section Fixed-Point Types 1302@cindex fixed-point types 1303@cindex @code{_Fract} data type 1304@cindex @code{_Accum} data type 1305@cindex @code{_Sat} data type 1306@cindex @code{hr} fixed-suffix 1307@cindex @code{r} fixed-suffix 1308@cindex @code{lr} fixed-suffix 1309@cindex @code{llr} fixed-suffix 1310@cindex @code{uhr} fixed-suffix 1311@cindex @code{ur} fixed-suffix 1312@cindex @code{ulr} fixed-suffix 1313@cindex @code{ullr} fixed-suffix 1314@cindex @code{hk} fixed-suffix 1315@cindex @code{k} fixed-suffix 1316@cindex @code{lk} fixed-suffix 1317@cindex @code{llk} fixed-suffix 1318@cindex @code{uhk} fixed-suffix 1319@cindex @code{uk} fixed-suffix 1320@cindex @code{ulk} fixed-suffix 1321@cindex @code{ullk} fixed-suffix 1322@cindex @code{HR} fixed-suffix 1323@cindex @code{R} fixed-suffix 1324@cindex @code{LR} fixed-suffix 1325@cindex @code{LLR} fixed-suffix 1326@cindex @code{UHR} fixed-suffix 1327@cindex @code{UR} fixed-suffix 1328@cindex @code{ULR} fixed-suffix 1329@cindex @code{ULLR} fixed-suffix 1330@cindex @code{HK} fixed-suffix 1331@cindex @code{K} fixed-suffix 1332@cindex @code{LK} fixed-suffix 1333@cindex @code{LLK} fixed-suffix 1334@cindex @code{UHK} fixed-suffix 1335@cindex @code{UK} fixed-suffix 1336@cindex @code{ULK} fixed-suffix 1337@cindex @code{ULLK} fixed-suffix 1338 1339As an extension, GNU C supports fixed-point types as 1340defined in the N1169 draft of ISO/IEC DTR 18037. Support for fixed-point 1341types in GCC will evolve as the draft technical report changes. 1342Calling conventions for any target might also change. Not all targets 1343support fixed-point types. 1344 1345The fixed-point types are 1346@code{short _Fract}, 1347@code{_Fract}, 1348@code{long _Fract}, 1349@code{long long _Fract}, 1350@code{unsigned short _Fract}, 1351@code{unsigned _Fract}, 1352@code{unsigned long _Fract}, 1353@code{unsigned long long _Fract}, 1354@code{_Sat short _Fract}, 1355@code{_Sat _Fract}, 1356@code{_Sat long _Fract}, 1357@code{_Sat long long _Fract}, 1358@code{_Sat unsigned short _Fract}, 1359@code{_Sat unsigned _Fract}, 1360@code{_Sat unsigned long _Fract}, 1361@code{_Sat unsigned long long _Fract}, 1362@code{short _Accum}, 1363@code{_Accum}, 1364@code{long _Accum}, 1365@code{long long _Accum}, 1366@code{unsigned short _Accum}, 1367@code{unsigned _Accum}, 1368@code{unsigned long _Accum}, 1369@code{unsigned long long _Accum}, 1370@code{_Sat short _Accum}, 1371@code{_Sat _Accum}, 1372@code{_Sat long _Accum}, 1373@code{_Sat long long _Accum}, 1374@code{_Sat unsigned short _Accum}, 1375@code{_Sat unsigned _Accum}, 1376@code{_Sat unsigned long _Accum}, 1377@code{_Sat unsigned long long _Accum}. 1378 1379Fixed-point data values contain fractional and optional integral parts. 1380The format of fixed-point data varies and depends on the target machine. 1381 1382Support for fixed-point types includes: 1383@itemize @bullet 1384@item 1385prefix and postfix increment and decrement operators (@code{++}, @code{--}) 1386@item 1387unary arithmetic operators (@code{+}, @code{-}, @code{!}) 1388@item 1389binary arithmetic operators (@code{+}, @code{-}, @code{*}, @code{/}) 1390@item 1391binary shift operators (@code{<<}, @code{>>}) 1392@item 1393relational operators (@code{<}, @code{<=}, @code{>=}, @code{>}) 1394@item 1395equality operators (@code{==}, @code{!=}) 1396@item 1397assignment operators (@code{+=}, @code{-=}, @code{*=}, @code{/=}, 1398@code{<<=}, @code{>>=}) 1399@item 1400conversions to and from integer, floating-point, or fixed-point types 1401@end itemize 1402 1403Use a suffix in a fixed-point literal constant: 1404@itemize 1405@item @samp{hr} or @samp{HR} for @code{short _Fract} and 1406@code{_Sat short _Fract} 1407@item @samp{r} or @samp{R} for @code{_Fract} and @code{_Sat _Fract} 1408@item @samp{lr} or @samp{LR} for @code{long _Fract} and 1409@code{_Sat long _Fract} 1410@item @samp{llr} or @samp{LLR} for @code{long long _Fract} and 1411@code{_Sat long long _Fract} 1412@item @samp{uhr} or @samp{UHR} for @code{unsigned short _Fract} and 1413@code{_Sat unsigned short _Fract} 1414@item @samp{ur} or @samp{UR} for @code{unsigned _Fract} and 1415@code{_Sat unsigned _Fract} 1416@item @samp{ulr} or @samp{ULR} for @code{unsigned long _Fract} and 1417@code{_Sat unsigned long _Fract} 1418@item @samp{ullr} or @samp{ULLR} for @code{unsigned long long _Fract} 1419and @code{_Sat unsigned long long _Fract} 1420@item @samp{hk} or @samp{HK} for @code{short _Accum} and 1421@code{_Sat short _Accum} 1422@item @samp{k} or @samp{K} for @code{_Accum} and @code{_Sat _Accum} 1423@item @samp{lk} or @samp{LK} for @code{long _Accum} and 1424@code{_Sat long _Accum} 1425@item @samp{llk} or @samp{LLK} for @code{long long _Accum} and 1426@code{_Sat long long _Accum} 1427@item @samp{uhk} or @samp{UHK} for @code{unsigned short _Accum} and 1428@code{_Sat unsigned short _Accum} 1429@item @samp{uk} or @samp{UK} for @code{unsigned _Accum} and 1430@code{_Sat unsigned _Accum} 1431@item @samp{ulk} or @samp{ULK} for @code{unsigned long _Accum} and 1432@code{_Sat unsigned long _Accum} 1433@item @samp{ullk} or @samp{ULLK} for @code{unsigned long long _Accum} 1434and @code{_Sat unsigned long long _Accum} 1435@end itemize 1436 1437GCC support of fixed-point types as specified by the draft technical report 1438is incomplete: 1439 1440@itemize @bullet 1441@item 1442Pragmas to control overflow and rounding behaviors are not implemented. 1443@end itemize 1444 1445Fixed-point types are supported by the DWARF debug information format. 1446 1447@node Named Address Spaces 1448@section Named Address Spaces 1449@cindex Named Address Spaces 1450 1451As an extension, GNU C supports named address spaces as 1452defined in the N1275 draft of ISO/IEC DTR 18037. Support for named 1453address spaces in GCC will evolve as the draft technical report 1454changes. Calling conventions for any target might also change. At 1455present, only the AVR, M32C, PRU, RL78, and x86 targets support 1456address spaces other than the generic address space. 1457 1458Address space identifiers may be used exactly like any other C type 1459qualifier (e.g., @code{const} or @code{volatile}). See the N1275 1460document for more details. 1461 1462@anchor{AVR Named Address Spaces} 1463@subsection AVR Named Address Spaces 1464 1465On the AVR target, there are several address spaces that can be used 1466in order to put read-only data into the flash memory and access that 1467data by means of the special instructions @code{LPM} or @code{ELPM} 1468needed to read from flash. 1469 1470Devices belonging to @code{avrtiny} and @code{avrxmega3} can access 1471flash memory by means of @code{LD*} instructions because the flash 1472memory is mapped into the RAM address space. There is @emph{no need} 1473for language extensions like @code{__flash} or attribute 1474@ref{AVR Variable Attributes,,@code{progmem}}. 1475The default linker description files for these devices cater for that 1476feature and @code{.rodata} stays in flash: The compiler just generates 1477@code{LD*} instructions, and the linker script adds core specific 1478offsets to all @code{.rodata} symbols: @code{0x4000} in the case of 1479@code{avrtiny} and @code{0x8000} in the case of @code{avrxmega3}. 1480See @ref{AVR Options} for a list of respective devices. 1481 1482For devices not in @code{avrtiny} or @code{avrxmega3}, 1483any data including read-only data is located in RAM (the generic 1484address space) because flash memory is not visible in the RAM address 1485space. In order to locate read-only data in flash memory @emph{and} 1486to generate the right instructions to access this data without 1487using (inline) assembler code, special address spaces are needed. 1488 1489@table @code 1490@item __flash 1491@cindex @code{__flash} AVR Named Address Spaces 1492The @code{__flash} qualifier locates data in the 1493@code{.progmem.data} section. Data is read using the @code{LPM} 1494instruction. Pointers to this address space are 16 bits wide. 1495 1496@item __flash1 1497@itemx __flash2 1498@itemx __flash3 1499@itemx __flash4 1500@itemx __flash5 1501@cindex @code{__flash1} AVR Named Address Spaces 1502@cindex @code{__flash2} AVR Named Address Spaces 1503@cindex @code{__flash3} AVR Named Address Spaces 1504@cindex @code{__flash4} AVR Named Address Spaces 1505@cindex @code{__flash5} AVR Named Address Spaces 1506These are 16-bit address spaces locating data in section 1507@code{.progmem@var{N}.data} where @var{N} refers to 1508address space @code{__flash@var{N}}. 1509The compiler sets the @code{RAMPZ} segment register appropriately 1510before reading data by means of the @code{ELPM} instruction. 1511 1512@item __memx 1513@cindex @code{__memx} AVR Named Address Spaces 1514This is a 24-bit address space that linearizes flash and RAM: 1515If the high bit of the address is set, data is read from 1516RAM using the lower two bytes as RAM address. 1517If the high bit of the address is clear, data is read from flash 1518with @code{RAMPZ} set according to the high byte of the address. 1519@xref{AVR Built-in Functions,,@code{__builtin_avr_flash_segment}}. 1520 1521Objects in this address space are located in @code{.progmemx.data}. 1522@end table 1523 1524@b{Example} 1525 1526@smallexample 1527char my_read (const __flash char ** p) 1528@{ 1529 /* p is a pointer to RAM that points to a pointer to flash. 1530 The first indirection of p reads that flash pointer 1531 from RAM and the second indirection reads a char from this 1532 flash address. */ 1533 1534 return **p; 1535@} 1536 1537/* Locate array[] in flash memory */ 1538const __flash int array[] = @{ 3, 5, 7, 11, 13, 17, 19 @}; 1539 1540int i = 1; 1541 1542int main (void) 1543@{ 1544 /* Return 17 by reading from flash memory */ 1545 return array[array[i]]; 1546@} 1547@end smallexample 1548 1549@noindent 1550For each named address space supported by avr-gcc there is an equally 1551named but uppercase built-in macro defined. 1552The purpose is to facilitate testing if respective address space 1553support is available or not: 1554 1555@smallexample 1556#ifdef __FLASH 1557const __flash int var = 1; 1558 1559int read_var (void) 1560@{ 1561 return var; 1562@} 1563#else 1564#include <avr/pgmspace.h> /* From AVR-LibC */ 1565 1566const int var PROGMEM = 1; 1567 1568int read_var (void) 1569@{ 1570 return (int) pgm_read_word (&var); 1571@} 1572#endif /* __FLASH */ 1573@end smallexample 1574 1575@noindent 1576Notice that attribute @ref{AVR Variable Attributes,,@code{progmem}} 1577locates data in flash but 1578accesses to these data read from generic address space, i.e.@: 1579from RAM, 1580so that you need special accessors like @code{pgm_read_byte} 1581from @w{@uref{http://nongnu.org/avr-libc/user-manual/,AVR-LibC}} 1582together with attribute @code{progmem}. 1583 1584@noindent 1585@b{Limitations and caveats} 1586 1587@itemize 1588@item 1589Reading across the 64@tie{}KiB section boundary of 1590the @code{__flash} or @code{__flash@var{N}} address spaces 1591shows undefined behavior. The only address space that 1592supports reading across the 64@tie{}KiB flash segment boundaries is 1593@code{__memx}. 1594 1595@item 1596If you use one of the @code{__flash@var{N}} address spaces 1597you must arrange your linker script to locate the 1598@code{.progmem@var{N}.data} sections according to your needs. 1599 1600@item 1601Any data or pointers to the non-generic address spaces must 1602be qualified as @code{const}, i.e.@: as read-only data. 1603This still applies if the data in one of these address 1604spaces like software version number or calibration lookup table are intended to 1605be changed after load time by, say, a boot loader. In this case 1606the right qualification is @code{const} @code{volatile} so that the compiler 1607must not optimize away known values or insert them 1608as immediates into operands of instructions. 1609 1610@item 1611The following code initializes a variable @code{pfoo} 1612located in static storage with a 24-bit address: 1613@smallexample 1614extern const __memx char foo; 1615const __memx void *pfoo = &foo; 1616@end smallexample 1617 1618@item 1619On the reduced Tiny devices like ATtiny40, no address spaces are supported. 1620Just use vanilla C / C++ code without overhead as outlined above. 1621Attribute @code{progmem} is supported but works differently, 1622see @ref{AVR Variable Attributes}. 1623 1624@end itemize 1625 1626@subsection M32C Named Address Spaces 1627@cindex @code{__far} M32C Named Address Spaces 1628 1629On the M32C target, with the R8C and M16C CPU variants, variables 1630qualified with @code{__far} are accessed using 32-bit addresses in 1631order to access memory beyond the first 64@tie{}Ki bytes. If 1632@code{__far} is used with the M32CM or M32C CPU variants, it has no 1633effect. 1634 1635@subsection PRU Named Address Spaces 1636@cindex @code{__regio_symbol} PRU Named Address Spaces 1637 1638On the PRU target, variables qualified with @code{__regio_symbol} are 1639aliases used to access the special I/O CPU registers. They must be 1640declared as @code{extern} because such variables will not be allocated in 1641any data memory. They must also be marked as @code{volatile}, and can 1642only be 32-bit integer types. The only names those variables can have 1643are @code{__R30} and @code{__R31}, representing respectively the 1644@code{R30} and @code{R31} special I/O CPU registers. Hence the following 1645example is the only valid usage of @code{__regio_symbol}: 1646 1647@smallexample 1648extern volatile __regio_symbol uint32_t __R30; 1649extern volatile __regio_symbol uint32_t __R31; 1650@end smallexample 1651 1652@subsection RL78 Named Address Spaces 1653@cindex @code{__far} RL78 Named Address Spaces 1654 1655On the RL78 target, variables qualified with @code{__far} are accessed 1656with 32-bit pointers (20-bit addresses) rather than the default 16-bit 1657addresses. Non-far variables are assumed to appear in the topmost 165864@tie{}KiB of the address space. 1659 1660@subsection x86 Named Address Spaces 1661@cindex x86 named address spaces 1662 1663On the x86 target, variables may be declared as being relative 1664to the @code{%fs} or @code{%gs} segments. 1665 1666@table @code 1667@item __seg_fs 1668@itemx __seg_gs 1669@cindex @code{__seg_fs} x86 named address space 1670@cindex @code{__seg_gs} x86 named address space 1671The object is accessed with the respective segment override prefix. 1672 1673The respective segment base must be set via some method specific to 1674the operating system. Rather than require an expensive system call 1675to retrieve the segment base, these address spaces are not considered 1676to be subspaces of the generic (flat) address space. This means that 1677explicit casts are required to convert pointers between these address 1678spaces and the generic address space. In practice the application 1679should cast to @code{uintptr_t} and apply the segment base offset 1680that it installed previously. 1681 1682The preprocessor symbols @code{__SEG_FS} and @code{__SEG_GS} are 1683defined when these address spaces are supported. 1684@end table 1685 1686@node Zero Length 1687@section Arrays of Length Zero 1688@cindex arrays of length zero 1689@cindex zero-length arrays 1690@cindex length-zero arrays 1691@cindex flexible array members 1692 1693Declaring zero-length arrays is allowed in GNU C as an extension. 1694A zero-length array can be useful as the last element of a structure 1695that is really a header for a variable-length object: 1696 1697@smallexample 1698struct line @{ 1699 int length; 1700 char contents[0]; 1701@}; 1702 1703struct line *thisline = (struct line *) 1704 malloc (sizeof (struct line) + this_length); 1705thisline->length = this_length; 1706@end smallexample 1707 1708Although the size of a zero-length array is zero, an array member of 1709this kind may increase the size of the enclosing type as a result of tail 1710padding. The offset of a zero-length array member from the beginning 1711of the enclosing structure is the same as the offset of an array with 1712one or more elements of the same type. The alignment of a zero-length 1713array is the same as the alignment of its elements. 1714 1715Declaring zero-length arrays in other contexts, including as interior 1716members of structure objects or as non-member objects, is discouraged. 1717Accessing elements of zero-length arrays declared in such contexts is 1718undefined and may be diagnosed. 1719 1720In the absence of the zero-length array extension, in ISO C90 1721the @code{contents} array in the example above would typically be declared 1722to have a single element. Unlike a zero-length array which only contributes 1723to the size of the enclosing structure for the purposes of alignment, 1724a one-element array always occupies at least as much space as a single 1725object of the type. Although using one-element arrays this way is 1726discouraged, GCC handles accesses to trailing one-element array members 1727analogously to zero-length arrays. 1728 1729The preferred mechanism to declare variable-length types like 1730@code{struct line} above is the ISO C99 @dfn{flexible array member}, 1731with slightly different syntax and semantics: 1732 1733@itemize @bullet 1734@item 1735Flexible array members are written as @code{contents[]} without 1736the @code{0}. 1737 1738@item 1739Flexible array members have incomplete type, and so the @code{sizeof} 1740operator may not be applied. As a quirk of the original implementation 1741of zero-length arrays, @code{sizeof} evaluates to zero. 1742 1743@item 1744Flexible array members may only appear as the last member of a 1745@code{struct} that is otherwise non-empty. 1746 1747@item 1748A structure containing a flexible array member, or a union containing 1749such a structure (possibly recursively), may not be a member of a 1750structure or an element of an array. (However, these uses are 1751permitted by GCC as extensions.) 1752@end itemize 1753 1754Non-empty initialization of zero-length 1755arrays is treated like any case where there are more initializer 1756elements than the array holds, in that a suitable warning about ``excess 1757elements in array'' is given, and the excess elements (all of them, in 1758this case) are ignored. 1759 1760GCC allows static initialization of flexible array members. 1761This is equivalent to defining a new structure containing the original 1762structure followed by an array of sufficient size to contain the data. 1763E.g.@: in the following, @code{f1} is constructed as if it were declared 1764like @code{f2}. 1765 1766@smallexample 1767struct f1 @{ 1768 int x; int y[]; 1769@} f1 = @{ 1, @{ 2, 3, 4 @} @}; 1770 1771struct f2 @{ 1772 struct f1 f1; int data[3]; 1773@} f2 = @{ @{ 1 @}, @{ 2, 3, 4 @} @}; 1774@end smallexample 1775 1776@noindent 1777The convenience of this extension is that @code{f1} has the desired 1778type, eliminating the need to consistently refer to @code{f2.f1}. 1779 1780This has symmetry with normal static arrays, in that an array of 1781unknown size is also written with @code{[]}. 1782 1783Of course, this extension only makes sense if the extra data comes at 1784the end of a top-level object, as otherwise we would be overwriting 1785data at subsequent offsets. To avoid undue complication and confusion 1786with initialization of deeply nested arrays, we simply disallow any 1787non-empty initialization except when the structure is the top-level 1788object. For example: 1789 1790@smallexample 1791struct foo @{ int x; int y[]; @}; 1792struct bar @{ struct foo z; @}; 1793 1794struct foo a = @{ 1, @{ 2, 3, 4 @} @}; // @r{Valid.} 1795struct bar b = @{ @{ 1, @{ 2, 3, 4 @} @} @}; // @r{Invalid.} 1796struct bar c = @{ @{ 1, @{ @} @} @}; // @r{Valid.} 1797struct foo d[1] = @{ @{ 1, @{ 2, 3, 4 @} @} @}; // @r{Invalid.} 1798@end smallexample 1799 1800@node Empty Structures 1801@section Structures with No Members 1802@cindex empty structures 1803@cindex zero-size structures 1804 1805GCC permits a C structure to have no members: 1806 1807@smallexample 1808struct empty @{ 1809@}; 1810@end smallexample 1811 1812The structure has size zero. In C++, empty structures are part 1813of the language. G++ treats empty structures as if they had a single 1814member of type @code{char}. 1815 1816@node Variable Length 1817@section Arrays of Variable Length 1818@cindex variable-length arrays 1819@cindex arrays of variable length 1820@cindex VLAs 1821 1822Variable-length automatic arrays are allowed in ISO C99, and as an 1823extension GCC accepts them in C90 mode and in C++. These arrays are 1824declared like any other automatic arrays, but with a length that is not 1825a constant expression. The storage is allocated at the point of 1826declaration and deallocated when the block scope containing the declaration 1827exits. For 1828example: 1829 1830@smallexample 1831FILE * 1832concat_fopen (char *s1, char *s2, char *mode) 1833@{ 1834 char str[strlen (s1) + strlen (s2) + 1]; 1835 strcpy (str, s1); 1836 strcat (str, s2); 1837 return fopen (str, mode); 1838@} 1839@end smallexample 1840 1841@cindex scope of a variable length array 1842@cindex variable-length array scope 1843@cindex deallocating variable length arrays 1844Jumping or breaking out of the scope of the array name deallocates the 1845storage. Jumping into the scope is not allowed; you get an error 1846message for it. 1847 1848@cindex variable-length array in a structure 1849As an extension, GCC accepts variable-length arrays as a member of 1850a structure or a union. For example: 1851 1852@smallexample 1853void 1854foo (int n) 1855@{ 1856 struct S @{ int x[n]; @}; 1857@} 1858@end smallexample 1859 1860@cindex @code{alloca} vs variable-length arrays 1861You can use the function @code{alloca} to get an effect much like 1862variable-length arrays. The function @code{alloca} is available in 1863many other C implementations (but not in all). On the other hand, 1864variable-length arrays are more elegant. 1865 1866There are other differences between these two methods. Space allocated 1867with @code{alloca} exists until the containing @emph{function} returns. 1868The space for a variable-length array is deallocated as soon as the array 1869name's scope ends, unless you also use @code{alloca} in this scope. 1870 1871You can also use variable-length arrays as arguments to functions: 1872 1873@smallexample 1874struct entry 1875tester (int len, char data[len][len]) 1876@{ 1877 /* @r{@dots{}} */ 1878@} 1879@end smallexample 1880 1881The length of an array is computed once when the storage is allocated 1882and is remembered for the scope of the array in case you access it with 1883@code{sizeof}. 1884 1885If you want to pass the array first and the length afterward, you can 1886use a forward declaration in the parameter list---another GNU extension. 1887 1888@smallexample 1889struct entry 1890tester (int len; char data[len][len], int len) 1891@{ 1892 /* @r{@dots{}} */ 1893@} 1894@end smallexample 1895 1896@cindex parameter forward declaration 1897The @samp{int len} before the semicolon is a @dfn{parameter forward 1898declaration}, and it serves the purpose of making the name @code{len} 1899known when the declaration of @code{data} is parsed. 1900 1901You can write any number of such parameter forward declarations in the 1902parameter list. They can be separated by commas or semicolons, but the 1903last one must end with a semicolon, which is followed by the ``real'' 1904parameter declarations. Each forward declaration must match a ``real'' 1905declaration in parameter name and data type. ISO C99 does not support 1906parameter forward declarations. 1907 1908@node Variadic Macros 1909@section Macros with a Variable Number of Arguments. 1910@cindex variable number of arguments 1911@cindex macro with variable arguments 1912@cindex rest argument (in macro) 1913@cindex variadic macros 1914 1915In the ISO C standard of 1999, a macro can be declared to accept a 1916variable number of arguments much as a function can. The syntax for 1917defining the macro is similar to that of a function. Here is an 1918example: 1919 1920@smallexample 1921#define debug(format, ...) fprintf (stderr, format, __VA_ARGS__) 1922@end smallexample 1923 1924@noindent 1925Here @samp{@dots{}} is a @dfn{variable argument}. In the invocation of 1926such a macro, it represents the zero or more tokens until the closing 1927parenthesis that ends the invocation, including any commas. This set of 1928tokens replaces the identifier @code{__VA_ARGS__} in the macro body 1929wherever it appears. See the CPP manual for more information. 1930 1931GCC has long supported variadic macros, and used a different syntax that 1932allowed you to give a name to the variable arguments just like any other 1933argument. Here is an example: 1934 1935@smallexample 1936#define debug(format, args...) fprintf (stderr, format, args) 1937@end smallexample 1938 1939@noindent 1940This is in all ways equivalent to the ISO C example above, but arguably 1941more readable and descriptive. 1942 1943GNU CPP has two further variadic macro extensions, and permits them to 1944be used with either of the above forms of macro definition. 1945 1946In standard C, you are not allowed to leave the variable argument out 1947entirely; but you are allowed to pass an empty argument. For example, 1948this invocation is invalid in ISO C, because there is no comma after 1949the string: 1950 1951@smallexample 1952debug ("A message") 1953@end smallexample 1954 1955GNU CPP permits you to completely omit the variable arguments in this 1956way. In the above examples, the compiler would complain, though since 1957the expansion of the macro still has the extra comma after the format 1958string. 1959 1960To help solve this problem, CPP behaves specially for variable arguments 1961used with the token paste operator, @samp{##}. If instead you write 1962 1963@smallexample 1964#define debug(format, ...) fprintf (stderr, format, ## __VA_ARGS__) 1965@end smallexample 1966 1967@noindent 1968and if the variable arguments are omitted or empty, the @samp{##} 1969operator causes the preprocessor to remove the comma before it. If you 1970do provide some variable arguments in your macro invocation, GNU CPP 1971does not complain about the paste operation and instead places the 1972variable arguments after the comma. Just like any other pasted macro 1973argument, these arguments are not macro expanded. 1974 1975@node Escaped Newlines 1976@section Slightly Looser Rules for Escaped Newlines 1977@cindex escaped newlines 1978@cindex newlines (escaped) 1979 1980The preprocessor treatment of escaped newlines is more relaxed 1981than that specified by the C90 standard, which requires the newline 1982to immediately follow a backslash. 1983GCC's implementation allows whitespace in the form 1984of spaces, horizontal and vertical tabs, and form feeds between the 1985backslash and the subsequent newline. The preprocessor issues a 1986warning, but treats it as a valid escaped newline and combines the two 1987lines to form a single logical line. This works within comments and 1988tokens, as well as between tokens. Comments are @emph{not} treated as 1989whitespace for the purposes of this relaxation, since they have not 1990yet been replaced with spaces. 1991 1992@node Subscripting 1993@section Non-Lvalue Arrays May Have Subscripts 1994@cindex subscripting 1995@cindex arrays, non-lvalue 1996 1997@cindex subscripting and function values 1998In ISO C99, arrays that are not lvalues still decay to pointers, and 1999may be subscripted, although they may not be modified or used after 2000the next sequence point and the unary @samp{&} operator may not be 2001applied to them. As an extension, GNU C allows such arrays to be 2002subscripted in C90 mode, though otherwise they do not decay to 2003pointers outside C99 mode. For example, 2004this is valid in GNU C though not valid in C90: 2005 2006@smallexample 2007@group 2008struct foo @{int a[4];@}; 2009 2010struct foo f(); 2011 2012bar (int index) 2013@{ 2014 return f().a[index]; 2015@} 2016@end group 2017@end smallexample 2018 2019@node Pointer Arith 2020@section Arithmetic on @code{void}- and Function-Pointers 2021@cindex void pointers, arithmetic 2022@cindex void, size of pointer to 2023@cindex function pointers, arithmetic 2024@cindex function, size of pointer to 2025 2026In GNU C, addition and subtraction operations are supported on pointers to 2027@code{void} and on pointers to functions. This is done by treating the 2028size of a @code{void} or of a function as 1. 2029 2030A consequence of this is that @code{sizeof} is also allowed on @code{void} 2031and on function types, and returns 1. 2032 2033@opindex Wpointer-arith 2034The option @option{-Wpointer-arith} requests a warning if these extensions 2035are used. 2036 2037@node Variadic Pointer Args 2038@section Pointer Arguments in Variadic Functions 2039@cindex pointer arguments in variadic functions 2040@cindex variadic functions, pointer arguments 2041 2042Standard C requires that pointer types used with @code{va_arg} in 2043functions with variable argument lists either must be compatible with 2044that of the actual argument, or that one type must be a pointer to 2045@code{void} and the other a pointer to a character type. GNU C 2046implements the POSIX XSI extension that additionally permits the use 2047of @code{va_arg} with a pointer type to receive arguments of any other 2048pointer type. 2049 2050In particular, in GNU C @samp{va_arg (ap, void *)} can safely be used 2051to consume an argument of any pointer type. 2052 2053@node Pointers to Arrays 2054@section Pointers to Arrays with Qualifiers Work as Expected 2055@cindex pointers to arrays 2056@cindex const qualifier 2057 2058In GNU C, pointers to arrays with qualifiers work similar to pointers 2059to other qualified types. For example, a value of type @code{int (*)[5]} 2060can be used to initialize a variable of type @code{const int (*)[5]}. 2061These types are incompatible in ISO C because the @code{const} qualifier 2062is formally attached to the element type of the array and not the 2063array itself. 2064 2065@smallexample 2066extern void 2067transpose (int N, int M, double out[M][N], const double in[N][M]); 2068double x[3][2]; 2069double y[2][3]; 2070@r{@dots{}} 2071transpose(3, 2, y, x); 2072@end smallexample 2073 2074@node Initializers 2075@section Non-Constant Initializers 2076@cindex initializers, non-constant 2077@cindex non-constant initializers 2078 2079As in standard C++ and ISO C99, the elements of an aggregate initializer for an 2080automatic variable are not required to be constant expressions in GNU C@. 2081Here is an example of an initializer with run-time varying elements: 2082 2083@smallexample 2084foo (float f, float g) 2085@{ 2086 float beat_freqs[2] = @{ f-g, f+g @}; 2087 /* @r{@dots{}} */ 2088@} 2089@end smallexample 2090 2091@node Compound Literals 2092@section Compound Literals 2093@cindex constructor expressions 2094@cindex initializations in expressions 2095@cindex structures, constructor expression 2096@cindex expressions, constructor 2097@cindex compound literals 2098@c The GNU C name for what C99 calls compound literals was "constructor expressions". 2099 2100A compound literal looks like a cast of a brace-enclosed aggregate 2101initializer list. Its value is an object of the type specified in 2102the cast, containing the elements specified in the initializer. 2103Unlike the result of a cast, a compound literal is an lvalue. ISO 2104C99 and later support compound literals. As an extension, GCC 2105supports compound literals also in C90 mode and in C++, although 2106as explained below, the C++ semantics are somewhat different. 2107 2108Usually, the specified type of a compound literal is a structure. Assume 2109that @code{struct foo} and @code{structure} are declared as shown: 2110 2111@smallexample 2112struct foo @{int a; char b[2];@} structure; 2113@end smallexample 2114 2115@noindent 2116Here is an example of constructing a @code{struct foo} with a compound literal: 2117 2118@smallexample 2119structure = ((struct foo) @{x + y, 'a', 0@}); 2120@end smallexample 2121 2122@noindent 2123This is equivalent to writing the following: 2124 2125@smallexample 2126@{ 2127 struct foo temp = @{x + y, 'a', 0@}; 2128 structure = temp; 2129@} 2130@end smallexample 2131 2132You can also construct an array, though this is dangerous in C++, as 2133explained below. If all the elements of the compound literal are 2134(made up of) simple constant expressions suitable for use in 2135initializers of objects of static storage duration, then the compound 2136literal can be coerced to a pointer to its first element and used in 2137such an initializer, as shown here: 2138 2139@smallexample 2140char **foo = (char *[]) @{ "x", "y", "z" @}; 2141@end smallexample 2142 2143Compound literals for scalar types and union types are also allowed. In 2144the following example the variable @code{i} is initialized to the value 2145@code{2}, the result of incrementing the unnamed object created by 2146the compound literal. 2147 2148@smallexample 2149int i = ++(int) @{ 1 @}; 2150@end smallexample 2151 2152As a GNU extension, GCC allows initialization of objects with static storage 2153duration by compound literals (which is not possible in ISO C99 because 2154the initializer is not a constant). 2155It is handled as if the object were initialized only with the brace-enclosed 2156list if the types of the compound literal and the object match. 2157The elements of the compound literal must be constant. 2158If the object being initialized has array type of unknown size, the size is 2159determined by the size of the compound literal. 2160 2161@smallexample 2162static struct foo x = (struct foo) @{1, 'a', 'b'@}; 2163static int y[] = (int []) @{1, 2, 3@}; 2164static int z[] = (int [3]) @{1@}; 2165@end smallexample 2166 2167@noindent 2168The above lines are equivalent to the following: 2169@smallexample 2170static struct foo x = @{1, 'a', 'b'@}; 2171static int y[] = @{1, 2, 3@}; 2172static int z[] = @{1, 0, 0@}; 2173@end smallexample 2174 2175In C, a compound literal designates an unnamed object with static or 2176automatic storage duration. In C++, a compound literal designates a 2177temporary object that only lives until the end of its full-expression. 2178As a result, well-defined C code that takes the address of a subobject 2179of a compound literal can be undefined in C++, so G++ rejects 2180the conversion of a temporary array to a pointer. For instance, if 2181the array compound literal example above appeared inside a function, 2182any subsequent use of @code{foo} in C++ would have undefined behavior 2183because the lifetime of the array ends after the declaration of @code{foo}. 2184 2185As an optimization, G++ sometimes gives array compound literals longer 2186lifetimes: when the array either appears outside a function or has 2187a @code{const}-qualified type. If @code{foo} and its initializer had 2188elements of type @code{char *const} rather than @code{char *}, or if 2189@code{foo} were a global variable, the array would have static storage 2190duration. But it is probably safest just to avoid the use of array 2191compound literals in C++ code. 2192 2193@node Designated Inits 2194@section Designated Initializers 2195@cindex initializers with labeled elements 2196@cindex labeled elements in initializers 2197@cindex case labels in initializers 2198@cindex designated initializers 2199 2200Standard C90 requires the elements of an initializer to appear in a fixed 2201order, the same as the order of the elements in the array or structure 2202being initialized. 2203 2204In ISO C99 you can give the elements in any order, specifying the array 2205indices or structure field names they apply to, and GNU C allows this as 2206an extension in C90 mode as well. This extension is not 2207implemented in GNU C++. 2208 2209To specify an array index, write 2210@samp{[@var{index}] =} before the element value. For example, 2211 2212@smallexample 2213int a[6] = @{ [4] = 29, [2] = 15 @}; 2214@end smallexample 2215 2216@noindent 2217is equivalent to 2218 2219@smallexample 2220int a[6] = @{ 0, 0, 15, 0, 29, 0 @}; 2221@end smallexample 2222 2223@noindent 2224The index values must be constant expressions, even if the array being 2225initialized is automatic. 2226 2227An alternative syntax for this that has been obsolete since GCC 2.5 but 2228GCC still accepts is to write @samp{[@var{index}]} before the element 2229value, with no @samp{=}. 2230 2231To initialize a range of elements to the same value, write 2232@samp{[@var{first} ... @var{last}] = @var{value}}. This is a GNU 2233extension. For example, 2234 2235@smallexample 2236int widths[] = @{ [0 ... 9] = 1, [10 ... 99] = 2, [100] = 3 @}; 2237@end smallexample 2238 2239@noindent 2240If the value in it has side effects, the side effects happen only once, 2241not for each initialized field by the range initializer. 2242 2243@noindent 2244Note that the length of the array is the highest value specified 2245plus one. 2246 2247In a structure initializer, specify the name of a field to initialize 2248with @samp{.@var{fieldname} =} before the element value. For example, 2249given the following structure, 2250 2251@smallexample 2252struct point @{ int x, y; @}; 2253@end smallexample 2254 2255@noindent 2256the following initialization 2257 2258@smallexample 2259struct point p = @{ .y = yvalue, .x = xvalue @}; 2260@end smallexample 2261 2262@noindent 2263is equivalent to 2264 2265@smallexample 2266struct point p = @{ xvalue, yvalue @}; 2267@end smallexample 2268 2269Another syntax that has the same meaning, obsolete since GCC 2.5, is 2270@samp{@var{fieldname}:}, as shown here: 2271 2272@smallexample 2273struct point p = @{ y: yvalue, x: xvalue @}; 2274@end smallexample 2275 2276Omitted fields are implicitly initialized the same as for objects 2277that have static storage duration. 2278 2279@cindex designators 2280The @samp{[@var{index}]} or @samp{.@var{fieldname}} is known as a 2281@dfn{designator}. You can also use a designator (or the obsolete colon 2282syntax) when initializing a union, to specify which element of the union 2283should be used. For example, 2284 2285@smallexample 2286union foo @{ int i; double d; @}; 2287 2288union foo f = @{ .d = 4 @}; 2289@end smallexample 2290 2291@noindent 2292converts 4 to a @code{double} to store it in the union using 2293the second element. By contrast, casting 4 to type @code{union foo} 2294stores it into the union as the integer @code{i}, since it is 2295an integer. @xref{Cast to Union}. 2296 2297You can combine this technique of naming elements with ordinary C 2298initialization of successive elements. Each initializer element that 2299does not have a designator applies to the next consecutive element of the 2300array or structure. For example, 2301 2302@smallexample 2303int a[6] = @{ [1] = v1, v2, [4] = v4 @}; 2304@end smallexample 2305 2306@noindent 2307is equivalent to 2308 2309@smallexample 2310int a[6] = @{ 0, v1, v2, 0, v4, 0 @}; 2311@end smallexample 2312 2313Labeling the elements of an array initializer is especially useful 2314when the indices are characters or belong to an @code{enum} type. 2315For example: 2316 2317@smallexample 2318int whitespace[256] 2319 = @{ [' '] = 1, ['\t'] = 1, ['\h'] = 1, 2320 ['\f'] = 1, ['\n'] = 1, ['\r'] = 1 @}; 2321@end smallexample 2322 2323@cindex designator lists 2324You can also write a series of @samp{.@var{fieldname}} and 2325@samp{[@var{index}]} designators before an @samp{=} to specify a 2326nested subobject to initialize; the list is taken relative to the 2327subobject corresponding to the closest surrounding brace pair. For 2328example, with the @samp{struct point} declaration above: 2329 2330@smallexample 2331struct point ptarray[10] = @{ [2].y = yv2, [2].x = xv2, [0].x = xv0 @}; 2332@end smallexample 2333 2334If the same field is initialized multiple times, or overlapping 2335fields of a union are initialized, the value from the last 2336initialization is used. When a field of a union is itself a structure, 2337the entire structure from the last field initialized is used. If any previous 2338initializer has side effect, it is unspecified whether the side effect 2339happens or not. Currently, GCC discards the side-effecting 2340initializer expressions and issues a warning. 2341 2342@node Case Ranges 2343@section Case Ranges 2344@cindex case ranges 2345@cindex ranges in case statements 2346 2347You can specify a range of consecutive values in a single @code{case} label, 2348like this: 2349 2350@smallexample 2351case @var{low} ... @var{high}: 2352@end smallexample 2353 2354@noindent 2355This has the same effect as the proper number of individual @code{case} 2356labels, one for each integer value from @var{low} to @var{high}, inclusive. 2357 2358This feature is especially useful for ranges of ASCII character codes: 2359 2360@smallexample 2361case 'A' ... 'Z': 2362@end smallexample 2363 2364@strong{Be careful:} Write spaces around the @code{...}, for otherwise 2365it may be parsed wrong when you use it with integer values. For example, 2366write this: 2367 2368@smallexample 2369case 1 ... 5: 2370@end smallexample 2371 2372@noindent 2373rather than this: 2374 2375@smallexample 2376case 1...5: 2377@end smallexample 2378 2379@node Cast to Union 2380@section Cast to a Union Type 2381@cindex cast to a union 2382@cindex union, casting to a 2383 2384A cast to a union type is a C extension not available in C++. It looks 2385just like ordinary casts with the constraint that the type specified is 2386a union type. You can specify the type either with the @code{union} 2387keyword or with a @code{typedef} name that refers to a union. The result 2388of a cast to a union is a temporary rvalue of the union type with a member 2389whose type matches that of the operand initialized to the value of 2390the operand. The effect of a cast to a union is similar to a compound 2391literal except that it yields an rvalue like standard casts do. 2392@xref{Compound Literals}. 2393 2394Expressions that may be cast to the union type are those whose type matches 2395at least one of the members of the union. Thus, given the following union 2396and variables: 2397 2398@smallexample 2399union foo @{ int i; double d; @}; 2400int x; 2401double y; 2402union foo z; 2403@end smallexample 2404 2405@noindent 2406both @code{x} and @code{y} can be cast to type @code{union foo} and 2407the following assignments 2408@smallexample 2409 z = (union foo) x; 2410 z = (union foo) y; 2411@end smallexample 2412are shorthand equivalents of these 2413@smallexample 2414 z = (union foo) @{ .i = x @}; 2415 z = (union foo) @{ .d = y @}; 2416@end smallexample 2417 2418However, @code{(union foo) FLT_MAX;} is not a valid cast because the union 2419has no member of type @code{float}. 2420 2421Using the cast as the right-hand side of an assignment to a variable of 2422union type is equivalent to storing in a member of the union with 2423the same type 2424 2425@smallexample 2426union foo u; 2427/* @r{@dots{}} */ 2428u = (union foo) x @equiv{} u.i = x 2429u = (union foo) y @equiv{} u.d = y 2430@end smallexample 2431 2432You can also use the union cast as a function argument: 2433 2434@smallexample 2435void hack (union foo); 2436/* @r{@dots{}} */ 2437hack ((union foo) x); 2438@end smallexample 2439 2440@node Mixed Labels and Declarations 2441@section Mixed Declarations, Labels and Code 2442@cindex mixed declarations and code 2443@cindex declarations, mixed with code 2444@cindex code, mixed with declarations 2445 2446ISO C99 and ISO C++ allow declarations and code to be freely mixed 2447within compound statements. ISO C2X allows labels to be 2448placed before declarations and at the end of a compound statement. 2449As an extension, GNU C also allows all this in C90 mode. For example, 2450you could do: 2451 2452@smallexample 2453int i; 2454/* @r{@dots{}} */ 2455i++; 2456int j = i + 2; 2457@end smallexample 2458 2459Each identifier is visible from where it is declared until the end of 2460the enclosing block. 2461 2462@node Function Attributes 2463@section Declaring Attributes of Functions 2464@cindex function attributes 2465@cindex declaring attributes of functions 2466@cindex @code{volatile} applied to function 2467@cindex @code{const} applied to function 2468 2469In GNU C and C++, you can use function attributes to specify certain 2470function properties that may help the compiler optimize calls or 2471check code more carefully for correctness. For example, you 2472can use attributes to specify that a function never returns 2473(@code{noreturn}), returns a value depending only on the values of 2474its arguments (@code{const}), or has @code{printf}-style arguments 2475(@code{format}). 2476 2477You can also use attributes to control memory placement, code 2478generation options or call/return conventions within the function 2479being annotated. Many of these attributes are target-specific. For 2480example, many targets support attributes for defining interrupt 2481handler functions, which typically must follow special register usage 2482and return conventions. Such attributes are described in the subsection 2483for each target. However, a considerable number of attributes are 2484supported by most, if not all targets. Those are described in 2485the @ref{Common Function Attributes} section. 2486 2487Function attributes are introduced by the @code{__attribute__} keyword 2488in the declaration of a function, followed by an attribute specification 2489enclosed in double parentheses. You can specify multiple attributes in 2490a declaration by separating them by commas within the double parentheses 2491or by immediately following one attribute specification with another. 2492@xref{Attribute Syntax}, for the exact rules on attribute syntax and 2493placement. Compatible attribute specifications on distinct declarations 2494of the same function are merged. An attribute specification that is not 2495compatible with attributes already applied to a declaration of the same 2496function is ignored with a warning. 2497 2498Some function attributes take one or more arguments that refer to 2499the function's parameters by their positions within the function parameter 2500list. Such attribute arguments are referred to as @dfn{positional arguments}. 2501Unless specified otherwise, positional arguments that specify properties 2502of parameters with pointer types can also specify the same properties of 2503the implicit C++ @code{this} argument in non-static member functions, and 2504of parameters of reference to a pointer type. For ordinary functions, 2505position one refers to the first parameter on the list. In C++ non-static 2506member functions, position one refers to the implicit @code{this} pointer. 2507The same restrictions and effects apply to function attributes used with 2508ordinary functions or C++ member functions. 2509 2510GCC also supports attributes on 2511variable declarations (@pxref{Variable Attributes}), 2512labels (@pxref{Label Attributes}), 2513enumerators (@pxref{Enumerator Attributes}), 2514statements (@pxref{Statement Attributes}), 2515types (@pxref{Type Attributes}), 2516and on field declarations (for @code{tainted_args}). 2517 2518There is some overlap between the purposes of attributes and pragmas 2519(@pxref{Pragmas,,Pragmas Accepted by GCC}). It has been 2520found convenient to use @code{__attribute__} to achieve a natural 2521attachment of attributes to their corresponding declarations, whereas 2522@code{#pragma} is of use for compatibility with other compilers 2523or constructs that do not naturally form part of the grammar. 2524 2525In addition to the attributes documented here, 2526GCC plugins may provide their own attributes. 2527 2528@menu 2529* Common Function Attributes:: 2530* AArch64 Function Attributes:: 2531* AMD GCN Function Attributes:: 2532* ARC Function Attributes:: 2533* ARM Function Attributes:: 2534* AVR Function Attributes:: 2535* Blackfin Function Attributes:: 2536* BPF Function Attributes:: 2537* CR16 Function Attributes:: 2538* C-SKY Function Attributes:: 2539* Epiphany Function Attributes:: 2540* H8/300 Function Attributes:: 2541* IA-64 Function Attributes:: 2542* M32C Function Attributes:: 2543* M32R/D Function Attributes:: 2544* m68k Function Attributes:: 2545* MCORE Function Attributes:: 2546* MeP Function Attributes:: 2547* MicroBlaze Function Attributes:: 2548* Microsoft Windows Function Attributes:: 2549* MIPS Function Attributes:: 2550* MSP430 Function Attributes:: 2551* NDS32 Function Attributes:: 2552* Nios II Function Attributes:: 2553* Nvidia PTX Function Attributes:: 2554* PowerPC Function Attributes:: 2555* RISC-V Function Attributes:: 2556* RL78 Function Attributes:: 2557* RX Function Attributes:: 2558* S/390 Function Attributes:: 2559* SH Function Attributes:: 2560* Symbian OS Function Attributes:: 2561* V850 Function Attributes:: 2562* Visium Function Attributes:: 2563* x86 Function Attributes:: 2564* Xstormy16 Function Attributes:: 2565@end menu 2566 2567@node Common Function Attributes 2568@subsection Common Function Attributes 2569 2570The following attributes are supported on most targets. 2571 2572@table @code 2573@c Keep this table alphabetized by attribute name. Treat _ as space. 2574 2575@item access (@var{access-mode}, @var{ref-index}) 2576@itemx access (@var{access-mode}, @var{ref-index}, @var{size-index}) 2577 2578The @code{access} attribute enables the detection of invalid or unsafe 2579accesses by functions to which they apply or their callers, as well as 2580write-only accesses to objects that are never read from. Such accesses 2581may be diagnosed by warnings such as @option{-Wstringop-overflow}, 2582@option{-Wuninitialized}, @option{-Wunused}, and others. 2583 2584The @code{access} attribute specifies that a function to whose by-reference 2585arguments the attribute applies accesses the referenced object according to 2586@var{access-mode}. The @var{access-mode} argument is required and must be 2587one of four names: @code{read_only}, @code{read_write}, @code{write_only}, 2588or @code{none}. The remaining two are positional arguments. 2589 2590The required @var{ref-index} positional argument denotes a function 2591argument of pointer (or in C++, reference) type that is subject to 2592the access. The same pointer argument can be referenced by at most one 2593distinct @code{access} attribute. 2594 2595The optional @var{size-index} positional argument denotes a function 2596argument of integer type that specifies the maximum size of the access. 2597The size is the number of elements of the type referenced by @var{ref-index}, 2598or the number of bytes when the pointer type is @code{void*}. When no 2599@var{size-index} argument is specified, the pointer argument must be either 2600null or point to a space that is suitably aligned and large for at least one 2601object of the referenced type (this implies that a past-the-end pointer is 2602not a valid argument). The actual size of the access may be less but it 2603must not be more. 2604 2605The @code{read_only} access mode specifies that the pointer to which it 2606applies is used to read the referenced object but not write to it. Unless 2607the argument specifying the size of the access denoted by @var{size-index} 2608is zero, the referenced object must be initialized. The mode implies 2609a stronger guarantee than the @code{const} qualifier which, when cast away 2610from a pointer, does not prevent the pointed-to object from being modified. 2611Examples of the use of the @code{read_only} access mode is the argument to 2612the @code{puts} function, or the second and third arguments to 2613the @code{memcpy} function. 2614 2615@smallexample 2616__attribute__ ((access (read_only, 1))) int puts (const char*); 2617__attribute__ ((access (read_only, 2, 3))) void* memcpy (void*, const void*, size_t); 2618@end smallexample 2619 2620The @code{read_write} access mode applies to arguments of pointer types 2621without the @code{const} qualifier. It specifies that the pointer to which 2622it applies is used to both read and write the referenced object. Unless 2623the argument specifying the size of the access denoted by @var{size-index} 2624is zero, the object referenced by the pointer must be initialized. An example 2625of the use of the @code{read_write} access mode is the first argument to 2626the @code{strcat} function. 2627 2628@smallexample 2629__attribute__ ((access (read_write, 1), access (read_only, 2))) char* strcat (char*, const char*); 2630@end smallexample 2631 2632The @code{write_only} access mode applies to arguments of pointer types 2633without the @code{const} qualifier. It specifies that the pointer to which 2634it applies is used to write to the referenced object but not read from it. 2635The object referenced by the pointer need not be initialized. An example 2636of the use of the @code{write_only} access mode is the first argument to 2637the @code{strcpy} function, or the first two arguments to the @code{fgets} 2638function. 2639 2640@smallexample 2641__attribute__ ((access (write_only, 1), access (read_only, 2))) char* strcpy (char*, const char*); 2642__attribute__ ((access (write_only, 1, 2), access (read_write, 3))) int fgets (char*, int, FILE*); 2643@end smallexample 2644 2645The access mode @code{none} specifies that the pointer to which it applies 2646is not used to access the referenced object at all. Unless the pointer is 2647null the pointed-to object must exist and have at least the size as denoted 2648by the @var{size-index} argument. When the optional @var{size-index} 2649argument is omitted for an argument of @code{void*} type the actual pointer 2650agument is ignored. The referenced object need not be initialized. 2651The mode is intended to be used as a means to help validate the expected 2652object size, for example in functions that call @code{__builtin_object_size}. 2653@xref{Object Size Checking}. 2654 2655Note that the @code{access} attribute merely specifies how an object 2656referenced by the pointer argument can be accessed; it does not imply that 2657an access @strong{will} happen. Also, the @code{access} attribute does not 2658imply the attribute @code{nonnull}; it may be appropriate to add both attributes 2659at the declaration of a function that unconditionally manipulates a buffer via 2660a pointer argument. See the @code{nonnull} attribute for more information and 2661caveats. 2662 2663@item alias ("@var{target}") 2664@cindex @code{alias} function attribute 2665The @code{alias} attribute causes the declaration to be emitted as an alias 2666for another symbol, which must have been previously declared with the same 2667type, and for variables, also the same size and alignment. Declaring an alias 2668with a different type than the target is undefined and may be diagnosed. As 2669an example, the following declarations: 2670 2671@smallexample 2672void __f () @{ /* @r{Do something.} */; @} 2673void f () __attribute__ ((weak, alias ("__f"))); 2674@end smallexample 2675 2676@noindent 2677define @samp{f} to be a weak alias for @samp{__f}. In C++, the mangled name 2678for the target must be used. It is an error if @samp{__f} is not defined in 2679the same translation unit. 2680 2681This attribute requires assembler and object file support, 2682and may not be available on all targets. 2683 2684@item aligned 2685@itemx aligned (@var{alignment}) 2686@cindex @code{aligned} function attribute 2687The @code{aligned} attribute specifies a minimum alignment for 2688the first instruction of the function, measured in bytes. When specified, 2689@var{alignment} must be an integer constant power of 2. Specifying no 2690@var{alignment} argument implies the ideal alignment for the target. 2691The @code{__alignof__} operator can be used to determine what that is 2692(@pxref{Alignment}). The attribute has no effect when a definition for 2693the function is not provided in the same translation unit. 2694 2695The attribute cannot be used to decrease the alignment of a function 2696previously declared with a more restrictive alignment; only to increase 2697it. Attempts to do otherwise are diagnosed. Some targets specify 2698a minimum default alignment for functions that is greater than 1. On 2699such targets, specifying a less restrictive alignment is silently ignored. 2700Using the attribute overrides the effect of the @option{-falign-functions} 2701(@pxref{Optimize Options}) option for this function. 2702 2703Note that the effectiveness of @code{aligned} attributes may be 2704limited by inherent limitations in the system linker 2705and/or object file format. On some systems, the 2706linker is only able to arrange for functions to be aligned up to a 2707certain maximum alignment. (For some linkers, the maximum supported 2708alignment may be very very small.) See your linker documentation for 2709further information. 2710 2711The @code{aligned} attribute can also be used for variables and fields 2712(@pxref{Variable Attributes}.) 2713 2714@item alloc_align (@var{position}) 2715@cindex @code{alloc_align} function attribute 2716The @code{alloc_align} attribute may be applied to a function that 2717returns a pointer and takes at least one argument of an integer or 2718enumerated type. 2719It indicates that the returned pointer is aligned on a boundary given 2720by the function argument at @var{position}. Meaningful alignments are 2721powers of 2 greater than one. GCC uses this information to improve 2722pointer alignment analysis. 2723 2724The function parameter denoting the allocated alignment is specified by 2725one constant integer argument whose number is the argument of the attribute. 2726Argument numbering starts at one. 2727 2728For instance, 2729 2730@smallexample 2731void* my_memalign (size_t, size_t) __attribute__ ((alloc_align (1))); 2732@end smallexample 2733 2734@noindent 2735declares that @code{my_memalign} returns memory with minimum alignment 2736given by parameter 1. 2737 2738@item alloc_size (@var{position}) 2739@itemx alloc_size (@var{position-1}, @var{position-2}) 2740@cindex @code{alloc_size} function attribute 2741The @code{alloc_size} attribute may be applied to a function that 2742returns a pointer and takes at least one argument of an integer or 2743enumerated type. 2744It indicates that the returned pointer points to memory whose size is 2745given by the function argument at @var{position-1}, or by the product 2746of the arguments at @var{position-1} and @var{position-2}. Meaningful 2747sizes are positive values less than @code{PTRDIFF_MAX}. GCC uses this 2748information to improve the results of @code{__builtin_object_size}. 2749 2750The function parameter(s) denoting the allocated size are specified by 2751one or two integer arguments supplied to the attribute. The allocated size 2752is either the value of the single function argument specified or the product 2753of the two function arguments specified. Argument numbering starts at 2754one for ordinary functions, and at two for C++ non-static member functions. 2755 2756For instance, 2757 2758@smallexample 2759void* my_calloc (size_t, size_t) __attribute__ ((alloc_size (1, 2))); 2760void* my_realloc (void*, size_t) __attribute__ ((alloc_size (2))); 2761@end smallexample 2762 2763@noindent 2764declares that @code{my_calloc} returns memory of the size given by 2765the product of parameter 1 and 2 and that @code{my_realloc} returns memory 2766of the size given by parameter 2. 2767 2768@item always_inline 2769@cindex @code{always_inline} function attribute 2770Generally, functions are not inlined unless optimization is specified. 2771For functions declared inline, this attribute inlines the function 2772independent of any restrictions that otherwise apply to inlining. 2773Failure to inline such a function is diagnosed as an error. 2774Note that if such a function is called indirectly the compiler may 2775or may not inline it depending on optimization level and a failure 2776to inline an indirect call may or may not be diagnosed. 2777 2778@item artificial 2779@cindex @code{artificial} function attribute 2780This attribute is useful for small inline wrappers that if possible 2781should appear during debugging as a unit. Depending on the debug 2782info format it either means marking the function as artificial 2783or using the caller location for all instructions within the inlined 2784body. 2785 2786@item assume_aligned (@var{alignment}) 2787@itemx assume_aligned (@var{alignment}, @var{offset}) 2788@cindex @code{assume_aligned} function attribute 2789The @code{assume_aligned} attribute may be applied to a function that 2790returns a pointer. It indicates that the returned pointer is aligned 2791on a boundary given by @var{alignment}. If the attribute has two 2792arguments, the second argument is misalignment @var{offset}. Meaningful 2793values of @var{alignment} are powers of 2 greater than one. Meaningful 2794values of @var{offset} are greater than zero and less than @var{alignment}. 2795 2796For instance 2797 2798@smallexample 2799void* my_alloc1 (size_t) __attribute__((assume_aligned (16))); 2800void* my_alloc2 (size_t) __attribute__((assume_aligned (32, 8))); 2801@end smallexample 2802 2803@noindent 2804declares that @code{my_alloc1} returns 16-byte aligned pointers and 2805that @code{my_alloc2} returns a pointer whose value modulo 32 is equal 2806to 8. 2807 2808@item cold 2809@cindex @code{cold} function attribute 2810The @code{cold} attribute on functions is used to inform the compiler that 2811the function is unlikely to be executed. The function is optimized for 2812size rather than speed and on many targets it is placed into a special 2813subsection of the text section so all cold functions appear close together, 2814improving code locality of non-cold parts of program. The paths leading 2815to calls of cold functions within code are marked as unlikely by the branch 2816prediction mechanism. It is thus useful to mark functions used to handle 2817unlikely conditions, such as @code{perror}, as cold to improve optimization 2818of hot functions that do call marked functions in rare occasions. 2819 2820When profile feedback is available, via @option{-fprofile-use}, cold functions 2821are automatically detected and this attribute is ignored. 2822 2823@item const 2824@cindex @code{const} function attribute 2825@cindex functions that have no side effects 2826Calls to functions whose return value is not affected by changes to 2827the observable state of the program and that have no observable effects 2828on such state other than to return a value may lend themselves to 2829optimizations such as common subexpression elimination. Declaring such 2830functions with the @code{const} attribute allows GCC to avoid emitting 2831some calls in repeated invocations of the function with the same argument 2832values. 2833 2834For example, 2835 2836@smallexample 2837int square (int) __attribute__ ((const)); 2838@end smallexample 2839 2840@noindent 2841tells GCC that subsequent calls to function @code{square} with the same 2842argument value can be replaced by the result of the first call regardless 2843of the statements in between. 2844 2845The @code{const} attribute prohibits a function from reading objects 2846that affect its return value between successive invocations. However, 2847functions declared with the attribute can safely read objects that do 2848not change their return value, such as non-volatile constants. 2849 2850The @code{const} attribute imposes greater restrictions on a function's 2851definition than the similar @code{pure} attribute. Declaring the same 2852function with both the @code{const} and the @code{pure} attribute is 2853diagnosed. Because a const function cannot have any observable side 2854effects it does not make sense for it to return @code{void}. Declaring 2855such a function is diagnosed. 2856 2857@cindex pointer arguments 2858Note that a function that has pointer arguments and examines the data 2859pointed to must @emph{not} be declared @code{const} if the pointed-to 2860data might change between successive invocations of the function. In 2861general, since a function cannot distinguish data that might change 2862from data that cannot, const functions should never take pointer or, 2863in C++, reference arguments. Likewise, a function that calls a non-const 2864function usually must not be const itself. 2865 2866@item constructor 2867@itemx destructor 2868@itemx constructor (@var{priority}) 2869@itemx destructor (@var{priority}) 2870@cindex @code{constructor} function attribute 2871@cindex @code{destructor} function attribute 2872The @code{constructor} attribute causes the function to be called 2873automatically before execution enters @code{main ()}. Similarly, the 2874@code{destructor} attribute causes the function to be called 2875automatically after @code{main ()} completes or @code{exit ()} is 2876called. Functions with these attributes are useful for 2877initializing data that is used implicitly during the execution of 2878the program. 2879 2880On some targets the attributes also accept an integer argument to 2881specify a priority to control the order in which constructor and 2882destructor functions are run. A constructor 2883with a smaller priority number runs before a constructor with a larger 2884priority number; the opposite relationship holds for destructors. Note 2885that priorities 0-100 are reserved. So, if you have a constructor that 2886allocates a resource and a destructor that deallocates the same 2887resource, both functions typically have the same priority. The 2888priorities for constructor and destructor functions are the same as 2889those specified for namespace-scope C++ objects (@pxref{C++ Attributes}). 2890However, at present, the order in which constructors for C++ objects 2891with static storage duration and functions decorated with attribute 2892@code{constructor} are invoked is unspecified. In mixed declarations, 2893attribute @code{init_priority} can be used to impose a specific ordering. 2894 2895Using the argument forms of the @code{constructor} and @code{destructor} 2896attributes on targets where the feature is not supported is rejected with 2897an error. 2898 2899@item copy 2900@itemx copy (@var{function}) 2901@cindex @code{copy} function attribute 2902The @code{copy} attribute applies the set of attributes with which 2903@var{function} has been declared to the declaration of the function 2904to which the attribute is applied. The attribute is designed for 2905libraries that define aliases or function resolvers that are expected 2906to specify the same set of attributes as their targets. The @code{copy} 2907attribute can be used with functions, variables, or types. However, 2908the kind of symbol to which the attribute is applied (either function 2909or variable) must match the kind of symbol to which the argument refers. 2910The @code{copy} attribute copies only syntactic and semantic attributes 2911but not attributes that affect a symbol's linkage or visibility such as 2912@code{alias}, @code{visibility}, or @code{weak}. The @code{deprecated} 2913and @code{target_clones} attribute are also not copied. 2914@xref{Common Type Attributes}. 2915@xref{Common Variable Attributes}. 2916 2917For example, the @var{StrongAlias} macro below makes use of the @code{alias} 2918and @code{copy} attributes to define an alias named @var{alloc} for function 2919@var{allocate} declared with attributes @var{alloc_size}, @var{malloc}, and 2920@var{nothrow}. Thanks to the @code{__typeof__} operator the alias has 2921the same type as the target function. As a result of the @code{copy} 2922attribute the alias also shares the same attributes as the target. 2923 2924@smallexample 2925#define StrongAlias(TargetFunc, AliasDecl) \ 2926 extern __typeof__ (TargetFunc) AliasDecl \ 2927 __attribute__ ((alias (#TargetFunc), copy (TargetFunc))); 2928 2929extern __attribute__ ((alloc_size (1), malloc, nothrow)) 2930 void* allocate (size_t); 2931StrongAlias (allocate, alloc); 2932@end smallexample 2933 2934@item deprecated 2935@itemx deprecated (@var{msg}) 2936@cindex @code{deprecated} function attribute 2937The @code{deprecated} attribute results in a warning if the function 2938is used anywhere in the source file. This is useful when identifying 2939functions that are expected to be removed in a future version of a 2940program. The warning also includes the location of the declaration 2941of the deprecated function, to enable users to easily find further 2942information about why the function is deprecated, or what they should 2943do instead. Note that the warnings only occurs for uses: 2944 2945@smallexample 2946int old_fn () __attribute__ ((deprecated)); 2947int old_fn (); 2948int (*fn_ptr)() = old_fn; 2949@end smallexample 2950 2951@noindent 2952results in a warning on line 3 but not line 2. The optional @var{msg} 2953argument, which must be a string, is printed in the warning if 2954present. 2955 2956The @code{deprecated} attribute can also be used for variables and 2957types (@pxref{Variable Attributes}, @pxref{Type Attributes}.) 2958 2959The message attached to the attribute is affected by the setting of 2960the @option{-fmessage-length} option. 2961 2962@item unavailable 2963@itemx unavailable (@var{msg}) 2964@cindex @code{unavailable} function attribute 2965The @code{unavailable} attribute results in an error if the function 2966is used anywhere in the source file. This is useful when identifying 2967functions that have been removed from a particular variation of an 2968interface. Other than emitting an error rather than a warning, the 2969@code{unavailable} attribute behaves in the same manner as 2970@code{deprecated}. 2971 2972The @code{unavailable} attribute can also be used for variables and 2973types (@pxref{Variable Attributes}, @pxref{Type Attributes}.) 2974 2975@item error ("@var{message}") 2976@itemx warning ("@var{message}") 2977@cindex @code{error} function attribute 2978@cindex @code{warning} function attribute 2979If the @code{error} or @code{warning} attribute 2980is used on a function declaration and a call to such a function 2981is not eliminated through dead code elimination or other optimizations, 2982an error or warning (respectively) that includes @var{message} is diagnosed. 2983This is useful 2984for compile-time checking, especially together with @code{__builtin_constant_p} 2985and inline functions where checking the inline function arguments is not 2986possible through @code{extern char [(condition) ? 1 : -1];} tricks. 2987 2988While it is possible to leave the function undefined and thus invoke 2989a link failure (to define the function with 2990a message in @code{.gnu.warning*} section), 2991when using these attributes the problem is diagnosed 2992earlier and with exact location of the call even in presence of inline 2993functions or when not emitting debugging information. 2994 2995@item externally_visible 2996@cindex @code{externally_visible} function attribute 2997This attribute, attached to a global variable or function, nullifies 2998the effect of the @option{-fwhole-program} command-line option, so the 2999object remains visible outside the current compilation unit. 3000 3001If @option{-fwhole-program} is used together with @option{-flto} and 3002@command{gold} is used as the linker plugin, 3003@code{externally_visible} attributes are automatically added to functions 3004(not variable yet due to a current @command{gold} issue) 3005that are accessed outside of LTO objects according to resolution file 3006produced by @command{gold}. 3007For other linkers that cannot generate resolution file, 3008explicit @code{externally_visible} attributes are still necessary. 3009 3010@item flatten 3011@cindex @code{flatten} function attribute 3012Generally, inlining into a function is limited. For a function marked with 3013this attribute, every call inside this function is inlined, if possible. 3014Functions declared with attribute @code{noinline} and similar are not 3015inlined. Whether the function itself is considered for inlining depends 3016on its size and the current inlining parameters. 3017 3018@item format (@var{archetype}, @var{string-index}, @var{first-to-check}) 3019@cindex @code{format} function attribute 3020@cindex functions with @code{printf}, @code{scanf}, @code{strftime} or @code{strfmon} style arguments 3021@opindex Wformat 3022The @code{format} attribute specifies that a function takes @code{printf}, 3023@code{scanf}, @code{strftime} or @code{strfmon} style arguments that 3024should be type-checked against a format string. For example, the 3025declaration: 3026 3027@smallexample 3028extern int 3029my_printf (void *my_object, const char *my_format, ...) 3030 __attribute__ ((format (printf, 2, 3))); 3031@end smallexample 3032 3033@noindent 3034causes the compiler to check the arguments in calls to @code{my_printf} 3035for consistency with the @code{printf} style format string argument 3036@code{my_format}. 3037 3038The parameter @var{archetype} determines how the format string is 3039interpreted, and should be @code{printf}, @code{scanf}, @code{strftime}, 3040@code{gnu_printf}, @code{gnu_scanf}, @code{gnu_strftime} or 3041@code{strfmon}. (You can also use @code{__printf__}, 3042@code{__scanf__}, @code{__strftime__} or @code{__strfmon__}.) On 3043MinGW targets, @code{ms_printf}, @code{ms_scanf}, and 3044@code{ms_strftime} are also present. 3045@var{archetype} values such as @code{printf} refer to the formats accepted 3046by the system's C runtime library, 3047while values prefixed with @samp{gnu_} always refer 3048to the formats accepted by the GNU C Library. On Microsoft Windows 3049targets, values prefixed with @samp{ms_} refer to the formats accepted by the 3050@file{msvcrt.dll} library. 3051The parameter @var{string-index} 3052specifies which argument is the format string argument (starting 3053from 1), while @var{first-to-check} is the number of the first 3054argument to check against the format string. For functions 3055where the arguments are not available to be checked (such as 3056@code{vprintf}), specify the third parameter as zero. In this case the 3057compiler only checks the format string for consistency. For 3058@code{strftime} formats, the third parameter is required to be zero. 3059Since non-static C++ methods have an implicit @code{this} argument, the 3060arguments of such methods should be counted from two, not one, when 3061giving values for @var{string-index} and @var{first-to-check}. 3062 3063In the example above, the format string (@code{my_format}) is the second 3064argument of the function @code{my_print}, and the arguments to check 3065start with the third argument, so the correct parameters for the format 3066attribute are 2 and 3. 3067 3068@opindex ffreestanding 3069@opindex fno-builtin 3070The @code{format} attribute allows you to identify your own functions 3071that take format strings as arguments, so that GCC can check the 3072calls to these functions for errors. The compiler always (unless 3073@option{-ffreestanding} or @option{-fno-builtin} is used) checks formats 3074for the standard library functions @code{printf}, @code{fprintf}, 3075@code{sprintf}, @code{scanf}, @code{fscanf}, @code{sscanf}, @code{strftime}, 3076@code{vprintf}, @code{vfprintf} and @code{vsprintf} whenever such 3077warnings are requested (using @option{-Wformat}), so there is no need to 3078modify the header file @file{stdio.h}. In C99 mode, the functions 3079@code{snprintf}, @code{vsnprintf}, @code{vscanf}, @code{vfscanf} and 3080@code{vsscanf} are also checked. Except in strictly conforming C 3081standard modes, the X/Open function @code{strfmon} is also checked as 3082are @code{printf_unlocked} and @code{fprintf_unlocked}. 3083@xref{C Dialect Options,,Options Controlling C Dialect}. 3084 3085For Objective-C dialects, @code{NSString} (or @code{__NSString__}) is 3086recognized in the same context. Declarations including these format attributes 3087are parsed for correct syntax, however the result of checking of such format 3088strings is not yet defined, and is not carried out by this version of the 3089compiler. 3090 3091The target may also provide additional types of format checks. 3092@xref{Target Format Checks,,Format Checks Specific to Particular 3093Target Machines}. 3094 3095@item format_arg (@var{string-index}) 3096@cindex @code{format_arg} function attribute 3097@opindex Wformat-nonliteral 3098The @code{format_arg} attribute specifies that a function takes one or 3099more format strings for a @code{printf}, @code{scanf}, @code{strftime} or 3100@code{strfmon} style function and modifies it (for example, to translate 3101it into another language), so the result can be passed to a 3102@code{printf}, @code{scanf}, @code{strftime} or @code{strfmon} style 3103function (with the remaining arguments to the format function the same 3104as they would have been for the unmodified string). Multiple 3105@code{format_arg} attributes may be applied to the same function, each 3106designating a distinct parameter as a format string. For example, the 3107declaration: 3108 3109@smallexample 3110extern char * 3111my_dgettext (char *my_domain, const char *my_format) 3112 __attribute__ ((format_arg (2))); 3113@end smallexample 3114 3115@noindent 3116causes the compiler to check the arguments in calls to a @code{printf}, 3117@code{scanf}, @code{strftime} or @code{strfmon} type function, whose 3118format string argument is a call to the @code{my_dgettext} function, for 3119consistency with the format string argument @code{my_format}. If the 3120@code{format_arg} attribute had not been specified, all the compiler 3121could tell in such calls to format functions would be that the format 3122string argument is not constant; this would generate a warning when 3123@option{-Wformat-nonliteral} is used, but the calls could not be checked 3124without the attribute. 3125 3126In calls to a function declared with more than one @code{format_arg} 3127attribute, each with a distinct argument value, the corresponding 3128actual function arguments are checked against all format strings 3129designated by the attributes. This capability is designed to support 3130the GNU @code{ngettext} family of functions. 3131 3132The parameter @var{string-index} specifies which argument is the format 3133string argument (starting from one). Since non-static C++ methods have 3134an implicit @code{this} argument, the arguments of such methods should 3135be counted from two. 3136 3137The @code{format_arg} attribute allows you to identify your own 3138functions that modify format strings, so that GCC can check the 3139calls to @code{printf}, @code{scanf}, @code{strftime} or @code{strfmon} 3140type function whose operands are a call to one of your own function. 3141The compiler always treats @code{gettext}, @code{dgettext}, and 3142@code{dcgettext} in this manner except when strict ISO C support is 3143requested by @option{-ansi} or an appropriate @option{-std} option, or 3144@option{-ffreestanding} or @option{-fno-builtin} 3145is used. @xref{C Dialect Options,,Options 3146Controlling C Dialect}. 3147 3148For Objective-C dialects, the @code{format-arg} attribute may refer to an 3149@code{NSString} reference for compatibility with the @code{format} attribute 3150above. 3151 3152The target may also allow additional types in @code{format-arg} attributes. 3153@xref{Target Format Checks,,Format Checks Specific to Particular 3154Target Machines}. 3155 3156@item gnu_inline 3157@cindex @code{gnu_inline} function attribute 3158This attribute should be used with a function that is also declared 3159with the @code{inline} keyword. It directs GCC to treat the function 3160as if it were defined in gnu90 mode even when compiling in C99 or 3161gnu99 mode. 3162 3163If the function is declared @code{extern}, then this definition of the 3164function is used only for inlining. In no case is the function 3165compiled as a standalone function, not even if you take its address 3166explicitly. Such an address becomes an external reference, as if you 3167had only declared the function, and had not defined it. This has 3168almost the effect of a macro. The way to use this is to put a 3169function definition in a header file with this attribute, and put 3170another copy of the function, without @code{extern}, in a library 3171file. The definition in the header file causes most calls to the 3172function to be inlined. If any uses of the function remain, they 3173refer to the single copy in the library. Note that the two 3174definitions of the functions need not be precisely the same, although 3175if they do not have the same effect your program may behave oddly. 3176 3177In C, if the function is neither @code{extern} nor @code{static}, then 3178the function is compiled as a standalone function, as well as being 3179inlined where possible. 3180 3181This is how GCC traditionally handled functions declared 3182@code{inline}. Since ISO C99 specifies a different semantics for 3183@code{inline}, this function attribute is provided as a transition 3184measure and as a useful feature in its own right. This attribute is 3185available in GCC 4.1.3 and later. It is available if either of the 3186preprocessor macros @code{__GNUC_GNU_INLINE__} or 3187@code{__GNUC_STDC_INLINE__} are defined. @xref{Inline,,An Inline 3188Function is As Fast As a Macro}. 3189 3190In C++, this attribute does not depend on @code{extern} in any way, 3191but it still requires the @code{inline} keyword to enable its special 3192behavior. 3193 3194@item hot 3195@cindex @code{hot} function attribute 3196The @code{hot} attribute on a function is used to inform the compiler that 3197the function is a hot spot of the compiled program. The function is 3198optimized more aggressively and on many targets it is placed into a special 3199subsection of the text section so all hot functions appear close together, 3200improving locality. 3201 3202When profile feedback is available, via @option{-fprofile-use}, hot functions 3203are automatically detected and this attribute is ignored. 3204 3205@item ifunc ("@var{resolver}") 3206@cindex @code{ifunc} function attribute 3207@cindex indirect functions 3208@cindex functions that are dynamically resolved 3209The @code{ifunc} attribute is used to mark a function as an indirect 3210function using the STT_GNU_IFUNC symbol type extension to the ELF 3211standard. This allows the resolution of the symbol value to be 3212determined dynamically at load time, and an optimized version of the 3213routine to be selected for the particular processor or other system 3214characteristics determined then. To use this attribute, first define 3215the implementation functions available, and a resolver function that 3216returns a pointer to the selected implementation function. The 3217implementation functions' declarations must match the API of the 3218function being implemented. The resolver should be declared to 3219be a function taking no arguments and returning a pointer to 3220a function of the same type as the implementation. For example: 3221 3222@smallexample 3223void *my_memcpy (void *dst, const void *src, size_t len) 3224@{ 3225 @dots{} 3226 return dst; 3227@} 3228 3229static void * (*resolve_memcpy (void))(void *, const void *, size_t) 3230@{ 3231 return my_memcpy; // we will just always select this routine 3232@} 3233@end smallexample 3234 3235@noindent 3236The exported header file declaring the function the user calls would 3237contain: 3238 3239@smallexample 3240extern void *memcpy (void *, const void *, size_t); 3241@end smallexample 3242 3243@noindent 3244allowing the user to call @code{memcpy} as a regular function, unaware of 3245the actual implementation. Finally, the indirect function needs to be 3246defined in the same translation unit as the resolver function: 3247 3248@smallexample 3249void *memcpy (void *, const void *, size_t) 3250 __attribute__ ((ifunc ("resolve_memcpy"))); 3251@end smallexample 3252 3253In C++, the @code{ifunc} attribute takes a string that is the mangled name 3254of the resolver function. A C++ resolver for a non-static member function 3255of class @code{C} should be declared to return a pointer to a non-member 3256function taking pointer to @code{C} as the first argument, followed by 3257the same arguments as of the implementation function. G++ checks 3258the signatures of the two functions and issues 3259a @option{-Wattribute-alias} warning for mismatches. To suppress a warning 3260for the necessary cast from a pointer to the implementation member function 3261to the type of the corresponding non-member function use 3262the @option{-Wno-pmf-conversions} option. For example: 3263 3264@smallexample 3265class S 3266@{ 3267private: 3268 int debug_impl (int); 3269 int optimized_impl (int); 3270 3271 typedef int Func (S*, int); 3272 3273 static Func* resolver (); 3274public: 3275 3276 int interface (int); 3277@}; 3278 3279int S::debug_impl (int) @{ /* @r{@dots{}} */ @} 3280int S::optimized_impl (int) @{ /* @r{@dots{}} */ @} 3281 3282S::Func* S::resolver () 3283@{ 3284 int (S::*pimpl) (int) 3285 = getenv ("DEBUG") ? &S::debug_impl : &S::optimized_impl; 3286 3287 // Cast triggers -Wno-pmf-conversions. 3288 return reinterpret_cast<Func*>(pimpl); 3289@} 3290 3291int S::interface (int) __attribute__ ((ifunc ("_ZN1S8resolverEv"))); 3292@end smallexample 3293 3294Indirect functions cannot be weak. Binutils version 2.20.1 or higher 3295and GNU C Library version 2.11.1 are required to use this feature. 3296 3297@item interrupt 3298@itemx interrupt_handler 3299Many GCC back ends support attributes to indicate that a function is 3300an interrupt handler, which tells the compiler to generate function 3301entry and exit sequences that differ from those from regular 3302functions. The exact syntax and behavior are target-specific; 3303refer to the following subsections for details. 3304 3305@item leaf 3306@cindex @code{leaf} function attribute 3307Calls to external functions with this attribute must return to the 3308current compilation unit only by return or by exception handling. In 3309particular, a leaf function is not allowed to invoke callback functions 3310passed to it from the current compilation unit, directly call functions 3311exported by the unit, or @code{longjmp} into the unit. Leaf functions 3312might still call functions from other compilation units and thus they 3313are not necessarily leaf in the sense that they contain no function 3314calls at all. 3315 3316The attribute is intended for library functions to improve dataflow 3317analysis. The compiler takes the hint that any data not escaping the 3318current compilation unit cannot be used or modified by the leaf 3319function. For example, the @code{sin} function is a leaf function, but 3320@code{qsort} is not. 3321 3322Note that leaf functions might indirectly run a signal handler defined 3323in the current compilation unit that uses static variables. Similarly, 3324when lazy symbol resolution is in effect, leaf functions might invoke 3325indirect functions whose resolver function or implementation function is 3326defined in the current compilation unit and uses static variables. There 3327is no standard-compliant way to write such a signal handler, resolver 3328function, or implementation function, and the best that you can do is to 3329remove the @code{leaf} attribute or mark all such static variables 3330@code{volatile}. Lastly, for ELF-based systems that support symbol 3331interposition, care should be taken that functions defined in the 3332current compilation unit do not unexpectedly interpose other symbols 3333based on the defined standards mode and defined feature test macros; 3334otherwise an inadvertent callback would be added. 3335 3336The attribute has no effect on functions defined within the current 3337compilation unit. This is to allow easy merging of multiple compilation 3338units into one, for example, by using the link-time optimization. For 3339this reason the attribute is not allowed on types to annotate indirect 3340calls. 3341 3342@item malloc 3343@item malloc (@var{deallocator}) 3344@item malloc (@var{deallocator}, @var{ptr-index}) 3345@cindex @code{malloc} function attribute 3346@cindex functions that behave like malloc 3347Attribute @code{malloc} indicates that a function is @code{malloc}-like, 3348i.e., that the pointer @var{P} returned by the function cannot alias any 3349other pointer valid when the function returns, and moreover no 3350pointers to valid objects occur in any storage addressed by @var{P}. In 3351addition, the GCC predicts that a function with the attribute returns 3352non-null in most cases. 3353 3354Independently, the form of the attribute with one or two arguments 3355associates @code{deallocator} as a suitable deallocation function for 3356pointers returned from the @code{malloc}-like function. @var{ptr-index} 3357denotes the positional argument to which when the pointer is passed in 3358calls to @code{deallocator} has the effect of deallocating it. 3359 3360Using the attribute with no arguments is designed to improve optimization 3361by relying on the aliasing property it implies. Functions like @code{malloc} 3362and @code{calloc} have this property because they return a pointer to 3363uninitialized or zeroed-out, newly obtained storage. However, functions 3364like @code{realloc} do not have this property, as they may return pointers 3365to storage containing pointers to existing objects. Additionally, since 3366all such functions are assumed to return null only infrequently, callers 3367can be optimized based on that assumption. 3368 3369Associating a function with a @var{deallocator} helps detect calls to 3370mismatched allocation and deallocation functions and diagnose them under 3371the control of options such as @option{-Wmismatched-dealloc}. It also 3372makes it possible to diagnose attempts to deallocate objects that were not 3373allocated dynamically, by @option{-Wfree-nonheap-object}. To indicate 3374that an allocation function both satisifies the nonaliasing property and 3375has a deallocator associated with it, both the plain form of the attribute 3376and the one with the @var{deallocator} argument must be used. The same 3377function can be both an allocator and a deallocator. Since inlining one 3378of the associated functions but not the other could result in apparent 3379mismatches, this form of attribute @code{malloc} is not accepted on inline 3380functions. For the same reason, using the attribute prevents both 3381the allocation and deallocation functions from being expanded inline. 3382 3383For example, besides stating that the functions return pointers that do 3384not alias any others, the following declarations make @code{fclose} 3385a suitable deallocator for pointers returned from all functions except 3386@code{popen}, and @code{pclose} as the only suitable deallocator for 3387pointers returned from @code{popen}. The deallocator functions must 3388be declared before they can be referenced in the attribute. 3389 3390@smallexample 3391int fclose (FILE*); 3392int pclose (FILE*); 3393 3394__attribute__ ((malloc, malloc (fclose, 1))) 3395 FILE* fdopen (int, const char*); 3396__attribute__ ((malloc, malloc (fclose, 1))) 3397 FILE* fopen (const char*, const char*); 3398__attribute__ ((malloc, malloc (fclose, 1))) 3399 FILE* fmemopen(void *, size_t, const char *); 3400__attribute__ ((malloc, malloc (pclose, 1))) 3401 FILE* popen (const char*, const char*); 3402__attribute__ ((malloc, malloc (fclose, 1))) 3403 FILE* tmpfile (void); 3404@end smallexample 3405 3406The warnings guarded by @option{-fanalyzer} respect allocation and 3407deallocation pairs marked with the @code{malloc}. In particular: 3408 3409@itemize @bullet 3410 3411@item 3412The analyzer will emit a @option{-Wanalyzer-mismatching-deallocation} 3413diagnostic if there is an execution path in which the result of an 3414allocation call is passed to a different deallocator. 3415 3416@item 3417The analyzer will emit a @option{-Wanalyzer-double-free} 3418diagnostic if there is an execution path in which a value is passed 3419more than once to a deallocation call. 3420 3421@item 3422The analyzer will consider the possibility that an allocation function 3423could fail and return NULL. It will emit 3424@option{-Wanalyzer-possible-null-dereference} and 3425@option{-Wanalyzer-possible-null-argument} diagnostics if there are 3426execution paths in which an unchecked result of an allocation call is 3427dereferenced or passed to a function requiring a non-null argument. 3428If the allocator always returns non-null, use 3429@code{__attribute__ ((returns_nonnull))} to suppress these warnings. 3430For example: 3431@smallexample 3432char *xstrdup (const char *) 3433 __attribute__((malloc (free), returns_nonnull)); 3434@end smallexample 3435 3436@item 3437The analyzer will emit a @option{-Wanalyzer-use-after-free} 3438diagnostic if there is an execution path in which the memory passed 3439by pointer to a deallocation call is used after the deallocation. 3440 3441@item 3442The analyzer will emit a @option{-Wanalyzer-malloc-leak} diagnostic if 3443there is an execution path in which the result of an allocation call 3444is leaked (without being passed to the deallocation function). 3445 3446@item 3447The analyzer will emit a @option{-Wanalyzer-free-of-non-heap} diagnostic 3448if a deallocation function is used on a global or on-stack variable. 3449 3450@end itemize 3451 3452The analyzer assumes that deallocators can gracefully handle the @code{NULL} 3453pointer. If this is not the case, the deallocator can be marked with 3454@code{__attribute__((nonnull))} so that @option{-fanalyzer} can emit 3455a @option{-Wanalyzer-possible-null-argument} diagnostic for code paths 3456in which the deallocator is called with NULL. 3457 3458@item no_icf 3459@cindex @code{no_icf} function attribute 3460This function attribute prevents a functions from being merged with another 3461semantically equivalent function. 3462 3463@item no_instrument_function 3464@cindex @code{no_instrument_function} function attribute 3465@opindex finstrument-functions 3466@opindex p 3467@opindex pg 3468If any of @option{-finstrument-functions}, @option{-p}, or @option{-pg} are 3469given, profiling function calls are 3470generated at entry and exit of most user-compiled functions. 3471Functions with this attribute are not so instrumented. 3472 3473@item no_profile_instrument_function 3474@cindex @code{no_profile_instrument_function} function attribute 3475The @code{no_profile_instrument_function} attribute on functions is used 3476to inform the compiler that it should not process any profile feedback based 3477optimization code instrumentation. 3478 3479@item no_reorder 3480@cindex @code{no_reorder} function attribute 3481Do not reorder functions or variables marked @code{no_reorder} 3482against each other or top level assembler statements the executable. 3483The actual order in the program will depend on the linker command 3484line. Static variables marked like this are also not removed. 3485This has a similar effect 3486as the @option{-fno-toplevel-reorder} option, but only applies to the 3487marked symbols. 3488 3489@item no_sanitize ("@var{sanitize_option}") 3490@cindex @code{no_sanitize} function attribute 3491The @code{no_sanitize} attribute on functions is used 3492to inform the compiler that it should not do sanitization of any option 3493mentioned in @var{sanitize_option}. A list of values acceptable by 3494the @option{-fsanitize} option can be provided. 3495 3496@smallexample 3497void __attribute__ ((no_sanitize ("alignment", "object-size"))) 3498f () @{ /* @r{Do something.} */; @} 3499void __attribute__ ((no_sanitize ("alignment,object-size"))) 3500g () @{ /* @r{Do something.} */; @} 3501@end smallexample 3502 3503@item no_sanitize_address 3504@itemx no_address_safety_analysis 3505@cindex @code{no_sanitize_address} function attribute 3506The @code{no_sanitize_address} attribute on functions is used 3507to inform the compiler that it should not instrument memory accesses 3508in the function when compiling with the @option{-fsanitize=address} option. 3509The @code{no_address_safety_analysis} is a deprecated alias of the 3510@code{no_sanitize_address} attribute, new code should use 3511@code{no_sanitize_address}. 3512 3513@item no_sanitize_thread 3514@cindex @code{no_sanitize_thread} function attribute 3515The @code{no_sanitize_thread} attribute on functions is used 3516to inform the compiler that it should not instrument memory accesses 3517in the function when compiling with the @option{-fsanitize=thread} option. 3518 3519@item no_sanitize_undefined 3520@cindex @code{no_sanitize_undefined} function attribute 3521The @code{no_sanitize_undefined} attribute on functions is used 3522to inform the compiler that it should not check for undefined behavior 3523in the function when compiling with the @option{-fsanitize=undefined} option. 3524 3525@item no_sanitize_coverage 3526@cindex @code{no_sanitize_coverage} function attribute 3527The @code{no_sanitize_coverage} attribute on functions is used 3528to inform the compiler that it should not do coverage-guided 3529fuzzing code instrumentation (@option{-fsanitize-coverage}). 3530 3531@item no_split_stack 3532@cindex @code{no_split_stack} function attribute 3533@opindex fsplit-stack 3534If @option{-fsplit-stack} is given, functions have a small 3535prologue which decides whether to split the stack. Functions with the 3536@code{no_split_stack} attribute do not have that prologue, and thus 3537may run with only a small amount of stack space available. 3538 3539@item no_stack_limit 3540@cindex @code{no_stack_limit} function attribute 3541This attribute locally overrides the @option{-fstack-limit-register} 3542and @option{-fstack-limit-symbol} command-line options; it has the effect 3543of disabling stack limit checking in the function it applies to. 3544 3545@item noclone 3546@cindex @code{noclone} function attribute 3547This function attribute prevents a function from being considered for 3548cloning---a mechanism that produces specialized copies of functions 3549and which is (currently) performed by interprocedural constant 3550propagation. 3551 3552@item noinline 3553@cindex @code{noinline} function attribute 3554This function attribute prevents a function from being considered for 3555inlining. 3556@c Don't enumerate the optimizations by name here; we try to be 3557@c future-compatible with this mechanism. 3558If the function does not have side effects, there are optimizations 3559other than inlining that cause function calls to be optimized away, 3560although the function call is live. To keep such calls from being 3561optimized away, put 3562@smallexample 3563asm (""); 3564@end smallexample 3565 3566@noindent 3567(@pxref{Extended Asm}) in the called function, to serve as a special 3568side effect. 3569 3570@item noipa 3571@cindex @code{noipa} function attribute 3572Disable interprocedural optimizations between the function with this 3573attribute and its callers, as if the body of the function is not available 3574when optimizing callers and the callers are unavailable when optimizing 3575the body. This attribute implies @code{noinline}, @code{noclone} and 3576@code{no_icf} attributes. However, this attribute is not equivalent 3577to a combination of other attributes, because its purpose is to suppress 3578existing and future optimizations employing interprocedural analysis, 3579including those that do not have an attribute suitable for disabling 3580them individually. This attribute is supported mainly for the purpose 3581of testing the compiler. 3582 3583@item nonnull 3584@itemx nonnull (@var{arg-index}, @dots{}) 3585@cindex @code{nonnull} function attribute 3586@cindex functions with non-null pointer arguments 3587The @code{nonnull} attribute may be applied to a function that takes at 3588least one argument of a pointer type. It indicates that the referenced 3589arguments must be non-null pointers. For instance, the declaration: 3590 3591@smallexample 3592extern void * 3593my_memcpy (void *dest, const void *src, size_t len) 3594 __attribute__((nonnull (1, 2))); 3595@end smallexample 3596 3597@noindent 3598informs the compiler that, in calls to @code{my_memcpy}, arguments 3599@var{dest} and @var{src} must be non-null. 3600 3601The attribute has an effect both on functions calls and function definitions. 3602 3603For function calls: 3604@itemize @bullet 3605@item If the compiler determines that a null pointer is 3606passed in an argument slot marked as non-null, and the 3607@option{-Wnonnull} option is enabled, a warning is issued. 3608@xref{Warning Options}. 3609@item The @option{-fisolate-erroneous-paths-attribute} option can be 3610specified to have GCC transform calls with null arguments to non-null 3611functions into traps. @xref{Optimize Options}. 3612@item The compiler may also perform optimizations based on the 3613knowledge that certain function arguments cannot be null. These 3614optimizations can be disabled by the 3615@option{-fno-delete-null-pointer-checks} option. @xref{Optimize Options}. 3616@end itemize 3617 3618For function definitions: 3619@itemize @bullet 3620@item If the compiler determines that a function parameter that is 3621marked with nonnull is compared with null, and 3622@option{-Wnonnull-compare} option is enabled, a warning is issued. 3623@xref{Warning Options}. 3624@item The compiler may also perform optimizations based on the 3625knowledge that @code{nonnul} parameters cannot be null. This can 3626currently not be disabled other than by removing the nonnull 3627attribute. 3628@end itemize 3629 3630If no @var{arg-index} is given to the @code{nonnull} attribute, 3631all pointer arguments are marked as non-null. To illustrate, the 3632following declaration is equivalent to the previous example: 3633 3634@smallexample 3635extern void * 3636my_memcpy (void *dest, const void *src, size_t len) 3637 __attribute__((nonnull)); 3638@end smallexample 3639 3640@item noplt 3641@cindex @code{noplt} function attribute 3642The @code{noplt} attribute is the counterpart to option @option{-fno-plt}. 3643Calls to functions marked with this attribute in position-independent code 3644do not use the PLT. 3645 3646@smallexample 3647@group 3648/* Externally defined function foo. */ 3649int foo () __attribute__ ((noplt)); 3650 3651int 3652main (/* @r{@dots{}} */) 3653@{ 3654 /* @r{@dots{}} */ 3655 foo (); 3656 /* @r{@dots{}} */ 3657@} 3658@end group 3659@end smallexample 3660 3661The @code{noplt} attribute on function @code{foo} 3662tells the compiler to assume that 3663the function @code{foo} is externally defined and that the call to 3664@code{foo} must avoid the PLT 3665in position-independent code. 3666 3667In position-dependent code, a few targets also convert calls to 3668functions that are marked to not use the PLT to use the GOT instead. 3669 3670@item noreturn 3671@cindex @code{noreturn} function attribute 3672@cindex functions that never return 3673A few standard library functions, such as @code{abort} and @code{exit}, 3674cannot return. GCC knows this automatically. Some programs define 3675their own functions that never return. You can declare them 3676@code{noreturn} to tell the compiler this fact. For example, 3677 3678@smallexample 3679@group 3680void fatal () __attribute__ ((noreturn)); 3681 3682void 3683fatal (/* @r{@dots{}} */) 3684@{ 3685 /* @r{@dots{}} */ /* @r{Print error message.} */ /* @r{@dots{}} */ 3686 exit (1); 3687@} 3688@end group 3689@end smallexample 3690 3691The @code{noreturn} keyword tells the compiler to assume that 3692@code{fatal} cannot return. It can then optimize without regard to what 3693would happen if @code{fatal} ever did return. This makes slightly 3694better code. More importantly, it helps avoid spurious warnings of 3695uninitialized variables. 3696 3697The @code{noreturn} keyword does not affect the exceptional path when that 3698applies: a @code{noreturn}-marked function may still return to the caller 3699by throwing an exception or calling @code{longjmp}. 3700 3701In order to preserve backtraces, GCC will never turn calls to 3702@code{noreturn} functions into tail calls. 3703 3704Do not assume that registers saved by the calling function are 3705restored before calling the @code{noreturn} function. 3706 3707It does not make sense for a @code{noreturn} function to have a return 3708type other than @code{void}. 3709 3710@item nothrow 3711@cindex @code{nothrow} function attribute 3712The @code{nothrow} attribute is used to inform the compiler that a 3713function cannot throw an exception. For example, most functions in 3714the standard C library can be guaranteed not to throw an exception 3715with the notable exceptions of @code{qsort} and @code{bsearch} that 3716take function pointer arguments. 3717 3718@item optimize (@var{level}, @dots{}) 3719@item optimize (@var{string}, @dots{}) 3720@cindex @code{optimize} function attribute 3721The @code{optimize} attribute is used to specify that a function is to 3722be compiled with different optimization options than specified on the 3723command line. The optimize attribute arguments of a function behave 3724behave as if appended to the command-line. 3725 3726Valid arguments are constant non-negative integers and 3727strings. Each numeric argument specifies an optimization @var{level}. 3728Each @var{string} argument consists of one or more comma-separated 3729substrings. Each substring that begins with the letter @code{O} refers 3730to an optimization option such as @option{-O0} or @option{-Os}. Other 3731substrings are taken as suffixes to the @code{-f} prefix jointly 3732forming the name of an optimization option. @xref{Optimize Options}. 3733 3734@samp{#pragma GCC optimize} can be used to set optimization options 3735for more than one function. @xref{Function Specific Option Pragmas}, 3736for details about the pragma. 3737 3738Providing multiple strings as arguments separated by commas to specify 3739multiple options is equivalent to separating the option suffixes with 3740a comma (@samp{,}) within a single string. Spaces are not permitted 3741within the strings. 3742 3743Not every optimization option that starts with the @var{-f} prefix 3744specified by the attribute necessarily has an effect on the function. 3745The @code{optimize} attribute should be used for debugging purposes only. 3746It is not suitable in production code. 3747 3748@item patchable_function_entry 3749@cindex @code{patchable_function_entry} function attribute 3750@cindex extra NOP instructions at the function entry point 3751In case the target's text segment can be made writable at run time by 3752any means, padding the function entry with a number of NOPs can be 3753used to provide a universal tool for instrumentation. 3754 3755The @code{patchable_function_entry} function attribute can be used to 3756change the number of NOPs to any desired value. The two-value syntax 3757is the same as for the command-line switch 3758@option{-fpatchable-function-entry=N,M}, generating @var{N} NOPs, with 3759the function entry point before the @var{M}th NOP instruction. 3760@var{M} defaults to 0 if omitted e.g.@: function entry point is before 3761the first NOP. 3762 3763If patchable function entries are enabled globally using the command-line 3764option @option{-fpatchable-function-entry=N,M}, then you must disable 3765instrumentation on all functions that are part of the instrumentation 3766framework with the attribute @code{patchable_function_entry (0)} 3767to prevent recursion. 3768 3769@item pure 3770@cindex @code{pure} function attribute 3771@cindex functions that have no side effects 3772 3773Calls to functions that have no observable effects on the state of 3774the program other than to return a value may lend themselves to optimizations 3775such as common subexpression elimination. Declaring such functions with 3776the @code{pure} attribute allows GCC to avoid emitting some calls in repeated 3777invocations of the function with the same argument values. 3778 3779The @code{pure} attribute prohibits a function from modifying the state 3780of the program that is observable by means other than inspecting 3781the function's return value. However, functions declared with the @code{pure} 3782attribute can safely read any non-volatile objects, and modify the value of 3783objects in a way that does not affect their return value or the observable 3784state of the program. 3785 3786For example, 3787 3788@smallexample 3789int hash (char *) __attribute__ ((pure)); 3790@end smallexample 3791 3792@noindent 3793tells GCC that subsequent calls to the function @code{hash} with the same 3794string can be replaced by the result of the first call provided the state 3795of the program observable by @code{hash}, including the contents of the array 3796itself, does not change in between. Even though @code{hash} takes a non-const 3797pointer argument it must not modify the array it points to, or any other object 3798whose value the rest of the program may depend on. However, the caller may 3799safely change the contents of the array between successive calls to 3800the function (doing so disables the optimization). The restriction also 3801applies to member objects referenced by the @code{this} pointer in C++ 3802non-static member functions. 3803 3804Some common examples of pure functions are @code{strlen} or @code{memcmp}. 3805Interesting non-pure functions are functions with infinite loops or those 3806depending on volatile memory or other system resource, that may change between 3807consecutive calls (such as the standard C @code{feof} function in 3808a multithreading environment). 3809 3810The @code{pure} attribute imposes similar but looser restrictions on 3811a function's definition than the @code{const} attribute: @code{pure} 3812allows the function to read any non-volatile memory, even if it changes 3813in between successive invocations of the function. Declaring the same 3814function with both the @code{pure} and the @code{const} attribute is 3815diagnosed. Because a pure function cannot have any observable side 3816effects it does not make sense for such a function to return @code{void}. 3817Declaring such a function is diagnosed. 3818 3819@item returns_nonnull 3820@cindex @code{returns_nonnull} function attribute 3821The @code{returns_nonnull} attribute specifies that the function 3822return value should be a non-null pointer. For instance, the declaration: 3823 3824@smallexample 3825extern void * 3826mymalloc (size_t len) __attribute__((returns_nonnull)); 3827@end smallexample 3828 3829@noindent 3830lets the compiler optimize callers based on the knowledge 3831that the return value will never be null. 3832 3833@item returns_twice 3834@cindex @code{returns_twice} function attribute 3835@cindex functions that return more than once 3836The @code{returns_twice} attribute tells the compiler that a function may 3837return more than one time. The compiler ensures that all registers 3838are dead before calling such a function and emits a warning about 3839the variables that may be clobbered after the second return from the 3840function. Examples of such functions are @code{setjmp} and @code{vfork}. 3841The @code{longjmp}-like counterpart of such function, if any, might need 3842to be marked with the @code{noreturn} attribute. 3843 3844@item section ("@var{section-name}") 3845@cindex @code{section} function attribute 3846@cindex functions in arbitrary sections 3847Normally, the compiler places the code it generates in the @code{text} section. 3848Sometimes, however, you need additional sections, or you need certain 3849particular functions to appear in special sections. The @code{section} 3850attribute specifies that a function lives in a particular section. 3851For example, the declaration: 3852 3853@smallexample 3854extern void foobar (void) __attribute__ ((section ("bar"))); 3855@end smallexample 3856 3857@noindent 3858puts the function @code{foobar} in the @code{bar} section. 3859 3860Some file formats do not support arbitrary sections so the @code{section} 3861attribute is not available on all platforms. 3862If you need to map the entire contents of a module to a particular 3863section, consider using the facilities of the linker instead. 3864 3865@item sentinel 3866@itemx sentinel (@var{position}) 3867@cindex @code{sentinel} function attribute 3868This function attribute indicates that an argument in a call to the function 3869is expected to be an explicit @code{NULL}. The attribute is only valid on 3870variadic functions. By default, the sentinel is expected to be the last 3871argument of the function call. If the optional @var{position} argument 3872is specified to the attribute, the sentinel must be located at 3873@var{position} counting backwards from the end of the argument list. 3874 3875@smallexample 3876__attribute__ ((sentinel)) 3877is equivalent to 3878__attribute__ ((sentinel(0))) 3879@end smallexample 3880 3881The attribute is automatically set with a position of 0 for the built-in 3882functions @code{execl} and @code{execlp}. The built-in function 3883@code{execle} has the attribute set with a position of 1. 3884 3885A valid @code{NULL} in this context is defined as zero with any object 3886pointer type. If your system defines the @code{NULL} macro with 3887an integer type then you need to add an explicit cast. During 3888installation GCC replaces the system @code{<stddef.h>} header with 3889a copy that redefines NULL appropriately. 3890 3891The warnings for missing or incorrect sentinels are enabled with 3892@option{-Wformat}. 3893 3894@item simd 3895@itemx simd("@var{mask}") 3896@cindex @code{simd} function attribute 3897This attribute enables creation of one or more function versions that 3898can process multiple arguments using SIMD instructions from a 3899single invocation. Specifying this attribute allows compiler to 3900assume that such versions are available at link time (provided 3901in the same or another translation unit). Generated versions are 3902target-dependent and described in the corresponding Vector ABI document. For 3903x86_64 target this document can be found 3904@w{@uref{https://sourceware.org/glibc/wiki/libmvec?action=AttachFile&do=view&target=VectorABI.txt,here}}. 3905 3906The optional argument @var{mask} may have the value 3907@code{notinbranch} or @code{inbranch}, 3908and instructs the compiler to generate non-masked or masked 3909clones correspondingly. By default, all clones are generated. 3910 3911If the attribute is specified and @code{#pragma omp declare simd} is 3912present on a declaration and the @option{-fopenmp} or @option{-fopenmp-simd} 3913switch is specified, then the attribute is ignored. 3914 3915@item stack_protect 3916@cindex @code{stack_protect} function attribute 3917This attribute adds stack protection code to the function if 3918flags @option{-fstack-protector}, @option{-fstack-protector-strong} 3919or @option{-fstack-protector-explicit} are set. 3920 3921@item no_stack_protector 3922@cindex @code{no_stack_protector} function attribute 3923This attribute prevents stack protection code for the function. 3924 3925@item target (@var{string}, @dots{}) 3926@cindex @code{target} function attribute 3927Multiple target back ends implement the @code{target} attribute 3928to specify that a function is to 3929be compiled with different target options than specified on the 3930command line. The original target command-line options are ignored. 3931One or more strings can be provided as arguments. 3932Each string consists of one or more comma-separated suffixes to 3933the @code{-m} prefix jointly forming the name of a machine-dependent 3934option. @xref{Submodel Options,,Machine-Dependent Options}. 3935 3936The @code{target} attribute can be used for instance to have a function 3937compiled with a different ISA (instruction set architecture) than the 3938default. @samp{#pragma GCC target} can be used to specify target-specific 3939options for more than one function. @xref{Function Specific Option Pragmas}, 3940for details about the pragma. 3941 3942For instance, on an x86, you could declare one function with the 3943@code{target("sse4.1,arch=core2")} attribute and another with 3944@code{target("sse4a,arch=amdfam10")}. This is equivalent to 3945compiling the first function with @option{-msse4.1} and 3946@option{-march=core2} options, and the second function with 3947@option{-msse4a} and @option{-march=amdfam10} options. It is up to you 3948to make sure that a function is only invoked on a machine that 3949supports the particular ISA it is compiled for (for example by using 3950@code{cpuid} on x86 to determine what feature bits and architecture 3951family are used). 3952 3953@smallexample 3954int core2_func (void) __attribute__ ((__target__ ("arch=core2"))); 3955int sse3_func (void) __attribute__ ((__target__ ("sse3"))); 3956@end smallexample 3957 3958Providing multiple strings as arguments separated by commas to specify 3959multiple options is equivalent to separating the option suffixes with 3960a comma (@samp{,}) within a single string. Spaces are not permitted 3961within the strings. 3962 3963The options supported are specific to each target; refer to @ref{x86 3964Function Attributes}, @ref{PowerPC Function Attributes}, 3965@ref{ARM Function Attributes}, @ref{AArch64 Function Attributes}, 3966@ref{Nios II Function Attributes}, and @ref{S/390 Function Attributes} 3967for details. 3968 3969@item symver ("@var{name2}@@@var{nodename}") 3970@cindex @code{symver} function attribute 3971On ELF targets this attribute creates a symbol version. The @var{name2} part 3972of the parameter is the actual name of the symbol by which it will be 3973externally referenced. The @code{nodename} portion should be the name of a 3974node specified in the version script supplied to the linker when building a 3975shared library. Versioned symbol must be defined and must be exported with 3976default visibility. 3977 3978@smallexample 3979__attribute__ ((__symver__ ("foo@@VERS_1"))) int 3980foo_v1 (void) 3981@{ 3982@} 3983@end smallexample 3984 3985Will produce a @code{.symver foo_v1, foo@@VERS_1} directive in the assembler 3986output. 3987 3988One can also define multiple version for a given symbol 3989(starting from binutils 2.35). 3990 3991@smallexample 3992__attribute__ ((__symver__ ("foo@@VERS_2"), __symver__ ("foo@@VERS_3"))) 3993int symver_foo_v1 (void) 3994@{ 3995@} 3996@end smallexample 3997 3998This example creates a symbol name @code{symver_foo_v1} 3999which will be version @code{VERS_2} and @code{VERS_3} of @code{foo}. 4000 4001If you have an older release of binutils, then symbol alias needs to 4002be used: 4003 4004@smallexample 4005__attribute__ ((__symver__ ("foo@@VERS_2"))) 4006int foo_v1 (void) 4007@{ 4008 return 0; 4009@} 4010 4011__attribute__ ((__symver__ ("foo@@VERS_3"))) 4012__attribute__ ((alias ("foo_v1"))) 4013int symver_foo_v1 (void); 4014@end smallexample 4015 4016Finally if the parameter is @code{"@var{name2}@@@@@var{nodename}"} then in 4017addition to creating a symbol version (as if 4018@code{"@var{name2}@@@var{nodename}"} was used) the version will be also used 4019to resolve @var{name2} by the linker. 4020 4021@item tainted_args 4022@cindex @code{tainted_args} function attribute 4023The @code{tainted_args} attribute is used to specify that a function is called 4024in a way that requires sanitization of its arguments, such as a system 4025call in an operating system kernel. Such a function can be considered part 4026of the ``attack surface'' of the program. The attribute can be used both 4027on function declarations, and on field declarations containing function 4028pointers. In the latter case, any function used as an initializer of 4029such a callback field will be treated as being called with tainted 4030arguments. 4031 4032The analyzer will pay particular attention to such functions when both 4033@option{-fanalyzer} and @option{-fanalyzer-checker=taint} are supplied, 4034potentially issuing warnings guarded by 4035@option{-Wanalyzer-tainted-allocation-size}, 4036@option{-Wanalyzer-tainted-array-index}, 4037@option{-Wanalyzer-tainted-divisor}, 4038@option{-Wanalyzer-tainted-offset}, 4039and @option{-Wanalyzer-tainted-size}. 4040 4041@item target_clones (@var{options}) 4042@cindex @code{target_clones} function attribute 4043The @code{target_clones} attribute is used to specify that a function 4044be cloned into multiple versions compiled with different target options 4045than specified on the command line. The supported options and restrictions 4046are the same as for @code{target} attribute. 4047 4048For instance, on an x86, you could compile a function with 4049@code{target_clones("sse4.1,avx")}. GCC creates two function clones, 4050one compiled with @option{-msse4.1} and another with @option{-mavx}. 4051 4052On a PowerPC, you can compile a function with 4053@code{target_clones("cpu=power9,default")}. GCC will create two 4054function clones, one compiled with @option{-mcpu=power9} and another 4055with the default options. GCC must be configured to use GLIBC 2.23 or 4056newer in order to use the @code{target_clones} attribute. 4057 4058It also creates a resolver function (see 4059the @code{ifunc} attribute above) that dynamically selects a clone 4060suitable for current architecture. The resolver is created only if there 4061is a usage of a function with @code{target_clones} attribute. 4062 4063Note that any subsequent call of a function without @code{target_clone} 4064from a @code{target_clone} caller will not lead to copying 4065(target clone) of the called function. 4066If you want to enforce such behaviour, 4067we recommend declaring the calling function with the @code{flatten} attribute? 4068 4069@item unused 4070@cindex @code{unused} function attribute 4071This attribute, attached to a function, means that the function is meant 4072to be possibly unused. GCC does not produce a warning for this 4073function. 4074 4075@item used 4076@cindex @code{used} function attribute 4077This attribute, attached to a function, means that code must be emitted 4078for the function even if it appears that the function is not referenced. 4079This is useful, for example, when the function is referenced only in 4080inline assembly. 4081 4082When applied to a member function of a C++ class template, the 4083attribute also means that the function is instantiated if the 4084class itself is instantiated. 4085 4086@item retain 4087@cindex @code{retain} function attribute 4088For ELF targets that support the GNU or FreeBSD OSABIs, this attribute 4089will save the function from linker garbage collection. To support 4090this behavior, functions that have not been placed in specific sections 4091(e.g. by the @code{section} attribute, or the @code{-ffunction-sections} 4092option), will be placed in new, unique sections. 4093 4094This additional functionality requires Binutils version 2.36 or later. 4095 4096@item visibility ("@var{visibility_type}") 4097@cindex @code{visibility} function attribute 4098This attribute affects the linkage of the declaration to which it is attached. 4099It can be applied to variables (@pxref{Common Variable Attributes}) and types 4100(@pxref{Common Type Attributes}) as well as functions. 4101 4102There are four supported @var{visibility_type} values: default, 4103hidden, protected or internal visibility. 4104 4105@smallexample 4106void __attribute__ ((visibility ("protected"))) 4107f () @{ /* @r{Do something.} */; @} 4108int i __attribute__ ((visibility ("hidden"))); 4109@end smallexample 4110 4111The possible values of @var{visibility_type} correspond to the 4112visibility settings in the ELF gABI. 4113 4114@table @code 4115@c keep this list of visibilities in alphabetical order. 4116 4117@item default 4118Default visibility is the normal case for the object file format. 4119This value is available for the visibility attribute to override other 4120options that may change the assumed visibility of entities. 4121 4122On ELF, default visibility means that the declaration is visible to other 4123modules and, in shared libraries, means that the declared entity may be 4124overridden. 4125 4126On Darwin, default visibility means that the declaration is visible to 4127other modules. 4128 4129Default visibility corresponds to ``external linkage'' in the language. 4130 4131@item hidden 4132Hidden visibility indicates that the entity declared has a new 4133form of linkage, which we call ``hidden linkage''. Two 4134declarations of an object with hidden linkage refer to the same object 4135if they are in the same shared object. 4136 4137@item internal 4138Internal visibility is like hidden visibility, but with additional 4139processor specific semantics. Unless otherwise specified by the 4140psABI, GCC defines internal visibility to mean that a function is 4141@emph{never} called from another module. Compare this with hidden 4142functions which, while they cannot be referenced directly by other 4143modules, can be referenced indirectly via function pointers. By 4144indicating that a function cannot be called from outside the module, 4145GCC may for instance omit the load of a PIC register since it is known 4146that the calling function loaded the correct value. 4147 4148@item protected 4149Protected visibility is like default visibility except that it 4150indicates that references within the defining module bind to the 4151definition in that module. That is, the declared entity cannot be 4152overridden by another module. 4153 4154@end table 4155 4156All visibilities are supported on many, but not all, ELF targets 4157(supported when the assembler supports the @samp{.visibility} 4158pseudo-op). Default visibility is supported everywhere. Hidden 4159visibility is supported on Darwin targets. 4160 4161The visibility attribute should be applied only to declarations that 4162would otherwise have external linkage. The attribute should be applied 4163consistently, so that the same entity should not be declared with 4164different settings of the attribute. 4165 4166In C++, the visibility attribute applies to types as well as functions 4167and objects, because in C++ types have linkage. A class must not have 4168greater visibility than its non-static data member types and bases, 4169and class members default to the visibility of their class. Also, a 4170declaration without explicit visibility is limited to the visibility 4171of its type. 4172 4173In C++, you can mark member functions and static member variables of a 4174class with the visibility attribute. This is useful if you know a 4175particular method or static member variable should only be used from 4176one shared object; then you can mark it hidden while the rest of the 4177class has default visibility. Care must be taken to avoid breaking 4178the One Definition Rule; for example, it is usually not useful to mark 4179an inline method as hidden without marking the whole class as hidden. 4180 4181A C++ namespace declaration can also have the visibility attribute. 4182 4183@smallexample 4184namespace nspace1 __attribute__ ((visibility ("protected"))) 4185@{ /* @r{Do something.} */; @} 4186@end smallexample 4187 4188This attribute applies only to the particular namespace body, not to 4189other definitions of the same namespace; it is equivalent to using 4190@samp{#pragma GCC visibility} before and after the namespace 4191definition (@pxref{Visibility Pragmas}). 4192 4193In C++, if a template argument has limited visibility, this 4194restriction is implicitly propagated to the template instantiation. 4195Otherwise, template instantiations and specializations default to the 4196visibility of their template. 4197 4198If both the template and enclosing class have explicit visibility, the 4199visibility from the template is used. 4200 4201@item warn_unused_result 4202@cindex @code{warn_unused_result} function attribute 4203The @code{warn_unused_result} attribute causes a warning to be emitted 4204if a caller of the function with this attribute does not use its 4205return value. This is useful for functions where not checking 4206the result is either a security problem or always a bug, such as 4207@code{realloc}. 4208 4209@smallexample 4210int fn () __attribute__ ((warn_unused_result)); 4211int foo () 4212@{ 4213 if (fn () < 0) return -1; 4214 fn (); 4215 return 0; 4216@} 4217@end smallexample 4218 4219@noindent 4220results in warning on line 5. 4221 4222@item weak 4223@cindex @code{weak} function attribute 4224The @code{weak} attribute causes a declaration of an external symbol 4225to be emitted as a weak symbol rather than a global. This is primarily 4226useful in defining library functions that can be overridden in user code, 4227though it can also be used with non-function declarations. The overriding 4228symbol must have the same type as the weak symbol. In addition, if it 4229designates a variable it must also have the same size and alignment as 4230the weak symbol. Weak symbols are supported for ELF targets, and also 4231for a.out targets when using the GNU assembler and linker. 4232 4233@item weakref 4234@itemx weakref ("@var{target}") 4235@cindex @code{weakref} function attribute 4236The @code{weakref} attribute marks a declaration as a weak reference. 4237Without arguments, it should be accompanied by an @code{alias} attribute 4238naming the target symbol. Alternatively, @var{target} may be given as 4239an argument to @code{weakref} itself, naming the target definition of 4240the alias. The @var{target} must have the same type as the declaration. 4241In addition, if it designates a variable it must also have the same size 4242and alignment as the declaration. In either form of the declaration 4243@code{weakref} implicitly marks the declared symbol as @code{weak}. Without 4244a @var{target} given as an argument to @code{weakref} or to @code{alias}, 4245@code{weakref} is equivalent to @code{weak} (in that case the declaration 4246may be @code{extern}). 4247 4248@smallexample 4249/* Given the declaration: */ 4250extern int y (void); 4251 4252/* the following... */ 4253static int x (void) __attribute__ ((weakref ("y"))); 4254 4255/* is equivalent to... */ 4256static int x (void) __attribute__ ((weakref, alias ("y"))); 4257 4258/* or, alternatively, to... */ 4259static int x (void) __attribute__ ((weakref)); 4260static int x (void) __attribute__ ((alias ("y"))); 4261@end smallexample 4262 4263A weak reference is an alias that does not by itself require a 4264definition to be given for the target symbol. If the target symbol is 4265only referenced through weak references, then it becomes a @code{weak} 4266undefined symbol. If it is directly referenced, however, then such 4267strong references prevail, and a definition is required for the 4268symbol, not necessarily in the same translation unit. 4269 4270The effect is equivalent to moving all references to the alias to a 4271separate translation unit, renaming the alias to the aliased symbol, 4272declaring it as weak, compiling the two separate translation units and 4273performing a link with relocatable output (i.e.@: @code{ld -r}) on them. 4274 4275A declaration to which @code{weakref} is attached and that is associated 4276with a named @code{target} must be @code{static}. 4277 4278@item zero_call_used_regs ("@var{choice}") 4279@cindex @code{zero_call_used_regs} function attribute 4280 4281The @code{zero_call_used_regs} attribute causes the compiler to zero 4282a subset of all call-used registers@footnote{A ``call-used'' register 4283is a register whose contents can be changed by a function call; 4284therefore, a caller cannot assume that the register has the same contents 4285on return from the function as it had before calling the function. Such 4286registers are also called ``call-clobbered'', ``caller-saved'', or 4287``volatile''.} at function return. 4288This is used to increase program security by either mitigating 4289Return-Oriented Programming (ROP) attacks or preventing information leakage 4290through registers. 4291 4292In order to satisfy users with different security needs and control the 4293run-time overhead at the same time, the @var{choice} parameter provides a 4294flexible way to choose the subset of the call-used registers to be zeroed. 4295The three basic values of @var{choice} are: 4296 4297@itemize @bullet 4298@item 4299@samp{skip} doesn't zero any call-used registers. 4300 4301@item 4302@samp{used} only zeros call-used registers that are used in the function. 4303A ``used'' register is one whose content has been set or referenced in 4304the function. 4305 4306@item 4307@samp{all} zeros all call-used registers. 4308@end itemize 4309 4310In addition to these three basic choices, it is possible to modify 4311@samp{used} or @samp{all} as follows: 4312 4313@itemize @bullet 4314@item 4315Adding @samp{-gpr} restricts the zeroing to general-purpose registers. 4316 4317@item 4318Adding @samp{-arg} restricts the zeroing to registers that can sometimes 4319be used to pass function arguments. This includes all argument registers 4320defined by the platform's calling conversion, regardless of whether the 4321function uses those registers for function arguments or not. 4322@end itemize 4323 4324The modifiers can be used individually or together. If they are used 4325together, they must appear in the order above. 4326 4327The full list of @var{choice}s is therefore: 4328 4329@table @code 4330@item skip 4331doesn't zero any call-used register. 4332 4333@item used 4334only zeros call-used registers that are used in the function. 4335 4336@item used-gpr 4337only zeros call-used general purpose registers that are used in the function. 4338 4339@item used-arg 4340only zeros call-used registers that are used in the function and pass arguments. 4341 4342@item used-gpr-arg 4343only zeros call-used general purpose registers that are used in the function 4344and pass arguments. 4345 4346@item all 4347zeros all call-used registers. 4348 4349@item all-gpr 4350zeros all call-used general purpose registers. 4351 4352@item all-arg 4353zeros all call-used registers that pass arguments. 4354 4355@item all-gpr-arg 4356zeros all call-used general purpose registers that pass 4357arguments. 4358@end table 4359 4360Of this list, @samp{used-arg}, @samp{used-gpr-arg}, @samp{all-arg}, 4361and @samp{all-gpr-arg} are mainly used for ROP mitigation. 4362 4363The default for the attribute is controlled by @option{-fzero-call-used-regs}. 4364@end table 4365 4366@c This is the end of the target-independent attribute table 4367 4368@node AArch64 Function Attributes 4369@subsection AArch64 Function Attributes 4370 4371The following target-specific function attributes are available for the 4372AArch64 target. For the most part, these options mirror the behavior of 4373similar command-line options (@pxref{AArch64 Options}), but on a 4374per-function basis. 4375 4376@table @code 4377@item general-regs-only 4378@cindex @code{general-regs-only} function attribute, AArch64 4379Indicates that no floating-point or Advanced SIMD registers should be 4380used when generating code for this function. If the function explicitly 4381uses floating-point code, then the compiler gives an error. This is 4382the same behavior as that of the command-line option 4383@option{-mgeneral-regs-only}. 4384 4385@item fix-cortex-a53-835769 4386@cindex @code{fix-cortex-a53-835769} function attribute, AArch64 4387Indicates that the workaround for the Cortex-A53 erratum 835769 should be 4388applied to this function. To explicitly disable the workaround for this 4389function specify the negated form: @code{no-fix-cortex-a53-835769}. 4390This corresponds to the behavior of the command line options 4391@option{-mfix-cortex-a53-835769} and @option{-mno-fix-cortex-a53-835769}. 4392 4393@item cmodel= 4394@cindex @code{cmodel=} function attribute, AArch64 4395Indicates that code should be generated for a particular code model for 4396this function. The behavior and permissible arguments are the same as 4397for the command line option @option{-mcmodel=}. 4398 4399@item strict-align 4400@itemx no-strict-align 4401@cindex @code{strict-align} function attribute, AArch64 4402@code{strict-align} indicates that the compiler should not assume that unaligned 4403memory references are handled by the system. To allow the compiler to assume 4404that aligned memory references are handled by the system, the inverse attribute 4405@code{no-strict-align} can be specified. The behavior is same as for the 4406command-line option @option{-mstrict-align} and @option{-mno-strict-align}. 4407 4408@item omit-leaf-frame-pointer 4409@cindex @code{omit-leaf-frame-pointer} function attribute, AArch64 4410Indicates that the frame pointer should be omitted for a leaf function call. 4411To keep the frame pointer, the inverse attribute 4412@code{no-omit-leaf-frame-pointer} can be specified. These attributes have 4413the same behavior as the command-line options @option{-momit-leaf-frame-pointer} 4414and @option{-mno-omit-leaf-frame-pointer}. 4415 4416@item tls-dialect= 4417@cindex @code{tls-dialect=} function attribute, AArch64 4418Specifies the TLS dialect to use for this function. The behavior and 4419permissible arguments are the same as for the command-line option 4420@option{-mtls-dialect=}. 4421 4422@item arch= 4423@cindex @code{arch=} function attribute, AArch64 4424Specifies the architecture version and architectural extensions to use 4425for this function. The behavior and permissible arguments are the same as 4426for the @option{-march=} command-line option. 4427 4428@item tune= 4429@cindex @code{tune=} function attribute, AArch64 4430Specifies the core for which to tune the performance of this function. 4431The behavior and permissible arguments are the same as for the @option{-mtune=} 4432command-line option. 4433 4434@item cpu= 4435@cindex @code{cpu=} function attribute, AArch64 4436Specifies the core for which to tune the performance of this function and also 4437whose architectural features to use. The behavior and valid arguments are the 4438same as for the @option{-mcpu=} command-line option. 4439 4440@item sign-return-address 4441@cindex @code{sign-return-address} function attribute, AArch64 4442Select the function scope on which return address signing will be applied. The 4443behavior and permissible arguments are the same as for the command-line option 4444@option{-msign-return-address=}. The default value is @code{none}. This 4445attribute is deprecated. The @code{branch-protection} attribute should 4446be used instead. 4447 4448@item branch-protection 4449@cindex @code{branch-protection} function attribute, AArch64 4450Select the function scope on which branch protection will be applied. The 4451behavior and permissible arguments are the same as for the command-line option 4452@option{-mbranch-protection=}. The default value is @code{none}. 4453 4454@item outline-atomics 4455@cindex @code{outline-atomics} function attribute, AArch64 4456Enable or disable calls to out-of-line helpers to implement atomic operations. 4457This corresponds to the behavior of the command line options 4458@option{-moutline-atomics} and @option{-mno-outline-atomics}. 4459 4460@end table 4461 4462The above target attributes can be specified as follows: 4463 4464@smallexample 4465__attribute__((target("@var{attr-string}"))) 4466int 4467f (int a) 4468@{ 4469 return a + 5; 4470@} 4471@end smallexample 4472 4473where @code{@var{attr-string}} is one of the attribute strings specified above. 4474 4475Additionally, the architectural extension string may be specified on its 4476own. This can be used to turn on and off particular architectural extensions 4477without having to specify a particular architecture version or core. Example: 4478 4479@smallexample 4480__attribute__((target("+crc+nocrypto"))) 4481int 4482foo (int a) 4483@{ 4484 return a + 5; 4485@} 4486@end smallexample 4487 4488In this example @code{target("+crc+nocrypto")} enables the @code{crc} 4489extension and disables the @code{crypto} extension for the function @code{foo} 4490without modifying an existing @option{-march=} or @option{-mcpu} option. 4491 4492Multiple target function attributes can be specified by separating them with 4493a comma. For example: 4494@smallexample 4495__attribute__((target("arch=armv8-a+crc+crypto,tune=cortex-a53"))) 4496int 4497foo (int a) 4498@{ 4499 return a + 5; 4500@} 4501@end smallexample 4502 4503is valid and compiles function @code{foo} for ARMv8-A with @code{crc} 4504and @code{crypto} extensions and tunes it for @code{cortex-a53}. 4505 4506@subsubsection Inlining rules 4507Specifying target attributes on individual functions or performing link-time 4508optimization across translation units compiled with different target options 4509can affect function inlining rules: 4510 4511In particular, a caller function can inline a callee function only if the 4512architectural features available to the callee are a subset of the features 4513available to the caller. 4514For example: A function @code{foo} compiled with @option{-march=armv8-a+crc}, 4515or tagged with the equivalent @code{arch=armv8-a+crc} attribute, 4516can inline a function @code{bar} compiled with @option{-march=armv8-a+nocrc} 4517because the all the architectural features that function @code{bar} requires 4518are available to function @code{foo}. Conversely, function @code{bar} cannot 4519inline function @code{foo}. 4520 4521Additionally inlining a function compiled with @option{-mstrict-align} into a 4522function compiled without @code{-mstrict-align} is not allowed. 4523However, inlining a function compiled without @option{-mstrict-align} into a 4524function compiled with @option{-mstrict-align} is allowed. 4525 4526Note that CPU tuning options and attributes such as the @option{-mcpu=}, 4527@option{-mtune=} do not inhibit inlining unless the CPU specified by the 4528@option{-mcpu=} option or the @code{cpu=} attribute conflicts with the 4529architectural feature rules specified above. 4530 4531@node AMD GCN Function Attributes 4532@subsection AMD GCN Function Attributes 4533 4534These function attributes are supported by the AMD GCN back end: 4535 4536@table @code 4537@item amdgpu_hsa_kernel 4538@cindex @code{amdgpu_hsa_kernel} function attribute, AMD GCN 4539This attribute indicates that the corresponding function should be compiled as 4540a kernel function, that is an entry point that can be invoked from the host 4541via the HSA runtime library. By default functions are only callable only from 4542other GCN functions. 4543 4544This attribute is implicitly applied to any function named @code{main}, using 4545default parameters. 4546 4547Kernel functions may return an integer value, which will be written to a 4548conventional place within the HSA "kernargs" region. 4549 4550The attribute parameters configure what values are passed into the kernel 4551function by the GPU drivers, via the initial register state. Some values are 4552used by the compiler, and therefore forced on. Enabling other options may 4553break assumptions in the compiler and/or run-time libraries. 4554 4555@table @code 4556@item private_segment_buffer 4557Set @code{enable_sgpr_private_segment_buffer} flag. Always on (required to 4558locate the stack). 4559 4560@item dispatch_ptr 4561Set @code{enable_sgpr_dispatch_ptr} flag. Always on (required to locate the 4562launch dimensions). 4563 4564@item queue_ptr 4565Set @code{enable_sgpr_queue_ptr} flag. Always on (required to convert address 4566spaces). 4567 4568@item kernarg_segment_ptr 4569Set @code{enable_sgpr_kernarg_segment_ptr} flag. Always on (required to 4570locate the kernel arguments, "kernargs"). 4571 4572@item dispatch_id 4573Set @code{enable_sgpr_dispatch_id} flag. 4574 4575@item flat_scratch_init 4576Set @code{enable_sgpr_flat_scratch_init} flag. 4577 4578@item private_segment_size 4579Set @code{enable_sgpr_private_segment_size} flag. 4580 4581@item grid_workgroup_count_X 4582Set @code{enable_sgpr_grid_workgroup_count_x} flag. Always on (required to 4583use OpenACC/OpenMP). 4584 4585@item grid_workgroup_count_Y 4586Set @code{enable_sgpr_grid_workgroup_count_y} flag. 4587 4588@item grid_workgroup_count_Z 4589Set @code{enable_sgpr_grid_workgroup_count_z} flag. 4590 4591@item workgroup_id_X 4592Set @code{enable_sgpr_workgroup_id_x} flag. 4593 4594@item workgroup_id_Y 4595Set @code{enable_sgpr_workgroup_id_y} flag. 4596 4597@item workgroup_id_Z 4598Set @code{enable_sgpr_workgroup_id_z} flag. 4599 4600@item workgroup_info 4601Set @code{enable_sgpr_workgroup_info} flag. 4602 4603@item private_segment_wave_offset 4604Set @code{enable_sgpr_private_segment_wave_byte_offset} flag. Always on 4605(required to locate the stack). 4606 4607@item work_item_id_X 4608Set @code{enable_vgpr_workitem_id} parameter. Always on (can't be disabled). 4609 4610@item work_item_id_Y 4611Set @code{enable_vgpr_workitem_id} parameter. Always on (required to enable 4612vectorization.) 4613 4614@item work_item_id_Z 4615Set @code{enable_vgpr_workitem_id} parameter. Always on (required to use 4616OpenACC/OpenMP). 4617 4618@end table 4619@end table 4620 4621@node ARC Function Attributes 4622@subsection ARC Function Attributes 4623 4624These function attributes are supported by the ARC back end: 4625 4626@table @code 4627@item interrupt 4628@cindex @code{interrupt} function attribute, ARC 4629Use this attribute to indicate 4630that the specified function is an interrupt handler. The compiler generates 4631function entry and exit sequences suitable for use in an interrupt handler 4632when this attribute is present. 4633 4634On the ARC, you must specify the kind of interrupt to be handled 4635in a parameter to the interrupt attribute like this: 4636 4637@smallexample 4638void f () __attribute__ ((interrupt ("ilink1"))); 4639@end smallexample 4640 4641Permissible values for this parameter are: @w{@code{ilink1}} and 4642@w{@code{ilink2}} for ARCv1 architecture, and @w{@code{ilink}} and 4643@w{@code{firq}} for ARCv2 architecture. 4644 4645@item long_call 4646@itemx medium_call 4647@itemx short_call 4648@cindex @code{long_call} function attribute, ARC 4649@cindex @code{medium_call} function attribute, ARC 4650@cindex @code{short_call} function attribute, ARC 4651@cindex indirect calls, ARC 4652These attributes specify how a particular function is called. 4653These attributes override the 4654@option{-mlong-calls} and @option{-mmedium-calls} (@pxref{ARC Options}) 4655command-line switches and @code{#pragma long_calls} settings. 4656 4657For ARC, a function marked with the @code{long_call} attribute is 4658always called using register-indirect jump-and-link instructions, 4659thereby enabling the called function to be placed anywhere within the 466032-bit address space. A function marked with the @code{medium_call} 4661attribute will always be close enough to be called with an unconditional 4662branch-and-link instruction, which has a 25-bit offset from 4663the call site. A function marked with the @code{short_call} 4664attribute will always be close enough to be called with a conditional 4665branch-and-link instruction, which has a 21-bit offset from 4666the call site. 4667 4668@item jli_always 4669@cindex @code{jli_always} function attribute, ARC 4670Forces a particular function to be called using @code{jli} 4671instruction. The @code{jli} instruction makes use of a table stored 4672into @code{.jlitab} section, which holds the location of the functions 4673which are addressed using this instruction. 4674 4675@item jli_fixed 4676@cindex @code{jli_fixed} function attribute, ARC 4677Identical like the above one, but the location of the function in the 4678@code{jli} table is known and given as an attribute parameter. 4679 4680@item secure_call 4681@cindex @code{secure_call} function attribute, ARC 4682This attribute allows one to mark secure-code functions that are 4683callable from normal mode. The location of the secure call function 4684into the @code{sjli} table needs to be passed as argument. 4685 4686@item naked 4687@cindex @code{naked} function attribute, ARC 4688This attribute allows the compiler to construct the requisite function 4689declaration, while allowing the body of the function to be assembly 4690code. The specified function will not have prologue/epilogue 4691sequences generated by the compiler. Only basic @code{asm} statements 4692can safely be included in naked functions (@pxref{Basic Asm}). While 4693using extended @code{asm} or a mixture of basic @code{asm} and C code 4694may appear to work, they cannot be depended upon to work reliably and 4695are not supported. 4696 4697@end table 4698 4699@node ARM Function Attributes 4700@subsection ARM Function Attributes 4701 4702These function attributes are supported for ARM targets: 4703 4704@table @code 4705 4706@item general-regs-only 4707@cindex @code{general-regs-only} function attribute, ARM 4708Indicates that no floating-point or Advanced SIMD registers should be 4709used when generating code for this function. If the function explicitly 4710uses floating-point code, then the compiler gives an error. This is 4711the same behavior as that of the command-line option 4712@option{-mgeneral-regs-only}. 4713 4714@item interrupt 4715@cindex @code{interrupt} function attribute, ARM 4716Use this attribute to indicate 4717that the specified function is an interrupt handler. The compiler generates 4718function entry and exit sequences suitable for use in an interrupt handler 4719when this attribute is present. 4720 4721You can specify the kind of interrupt to be handled by 4722adding an optional parameter to the interrupt attribute like this: 4723 4724@smallexample 4725void f () __attribute__ ((interrupt ("IRQ"))); 4726@end smallexample 4727 4728@noindent 4729Permissible values for this parameter are: @code{IRQ}, @code{FIQ}, 4730@code{SWI}, @code{ABORT} and @code{UNDEF}. 4731 4732On ARMv7-M the interrupt type is ignored, and the attribute means the function 4733may be called with a word-aligned stack pointer. 4734 4735@item isr 4736@cindex @code{isr} function attribute, ARM 4737Use this attribute on ARM to write Interrupt Service Routines. This is an 4738alias to the @code{interrupt} attribute above. 4739 4740@item long_call 4741@itemx short_call 4742@cindex @code{long_call} function attribute, ARM 4743@cindex @code{short_call} function attribute, ARM 4744@cindex indirect calls, ARM 4745These attributes specify how a particular function is called. 4746These attributes override the 4747@option{-mlong-calls} (@pxref{ARM Options}) 4748command-line switch and @code{#pragma long_calls} settings. For ARM, the 4749@code{long_call} attribute indicates that the function might be far 4750away from the call site and require a different (more expensive) 4751calling sequence. The @code{short_call} attribute always places 4752the offset to the function from the call site into the @samp{BL} 4753instruction directly. 4754 4755@item naked 4756@cindex @code{naked} function attribute, ARM 4757This attribute allows the compiler to construct the 4758requisite function declaration, while allowing the body of the 4759function to be assembly code. The specified function will not have 4760prologue/epilogue sequences generated by the compiler. Only basic 4761@code{asm} statements can safely be included in naked functions 4762(@pxref{Basic Asm}). While using extended @code{asm} or a mixture of 4763basic @code{asm} and C code may appear to work, they cannot be 4764depended upon to work reliably and are not supported. 4765 4766@item pcs 4767@cindex @code{pcs} function attribute, ARM 4768 4769The @code{pcs} attribute can be used to control the calling convention 4770used for a function on ARM. The attribute takes an argument that specifies 4771the calling convention to use. 4772 4773When compiling using the AAPCS ABI (or a variant of it) then valid 4774values for the argument are @code{"aapcs"} and @code{"aapcs-vfp"}. In 4775order to use a variant other than @code{"aapcs"} then the compiler must 4776be permitted to use the appropriate co-processor registers (i.e., the 4777VFP registers must be available in order to use @code{"aapcs-vfp"}). 4778For example, 4779 4780@smallexample 4781/* Argument passed in r0, and result returned in r0+r1. */ 4782double f2d (float) __attribute__((pcs("aapcs"))); 4783@end smallexample 4784 4785Variadic functions always use the @code{"aapcs"} calling convention and 4786the compiler rejects attempts to specify an alternative. 4787 4788@item target (@var{options}) 4789@cindex @code{target} function attribute 4790As discussed in @ref{Common Function Attributes}, this attribute 4791allows specification of target-specific compilation options. 4792 4793On ARM, the following options are allowed: 4794 4795@table @samp 4796@item thumb 4797@cindex @code{target("thumb")} function attribute, ARM 4798Force code generation in the Thumb (T16/T32) ISA, depending on the 4799architecture level. 4800 4801@item arm 4802@cindex @code{target("arm")} function attribute, ARM 4803Force code generation in the ARM (A32) ISA. 4804 4805Functions from different modes can be inlined in the caller's mode. 4806 4807@item fpu= 4808@cindex @code{target("fpu=")} function attribute, ARM 4809Specifies the fpu for which to tune the performance of this function. 4810The behavior and permissible arguments are the same as for the @option{-mfpu=} 4811command-line option. 4812 4813@item arch= 4814@cindex @code{arch=} function attribute, ARM 4815Specifies the architecture version and architectural extensions to use 4816for this function. The behavior and permissible arguments are the same as 4817for the @option{-march=} command-line option. 4818 4819The above target attributes can be specified as follows: 4820 4821@smallexample 4822__attribute__((target("arch=armv8-a+crc"))) 4823int 4824f (int a) 4825@{ 4826 return a + 5; 4827@} 4828@end smallexample 4829 4830Additionally, the architectural extension string may be specified on its 4831own. This can be used to turn on and off particular architectural extensions 4832without having to specify a particular architecture version or core. Example: 4833 4834@smallexample 4835__attribute__((target("+crc+nocrypto"))) 4836int 4837foo (int a) 4838@{ 4839 return a + 5; 4840@} 4841@end smallexample 4842 4843In this example @code{target("+crc+nocrypto")} enables the @code{crc} 4844extension and disables the @code{crypto} extension for the function @code{foo} 4845without modifying an existing @option{-march=} or @option{-mcpu} option. 4846 4847@end table 4848 4849@end table 4850 4851@node AVR Function Attributes 4852@subsection AVR Function Attributes 4853 4854These function attributes are supported by the AVR back end: 4855 4856@table @code 4857@item interrupt 4858@cindex @code{interrupt} function attribute, AVR 4859Use this attribute to indicate 4860that the specified function is an interrupt handler. The compiler generates 4861function entry and exit sequences suitable for use in an interrupt handler 4862when this attribute is present. 4863 4864On the AVR, the hardware globally disables interrupts when an 4865interrupt is executed. The first instruction of an interrupt handler 4866declared with this attribute is a @code{SEI} instruction to 4867re-enable interrupts. See also the @code{signal} function attribute 4868that does not insert a @code{SEI} instruction. If both @code{signal} and 4869@code{interrupt} are specified for the same function, @code{signal} 4870is silently ignored. 4871 4872@item naked 4873@cindex @code{naked} function attribute, AVR 4874This attribute allows the compiler to construct the 4875requisite function declaration, while allowing the body of the 4876function to be assembly code. The specified function will not have 4877prologue/epilogue sequences generated by the compiler. Only basic 4878@code{asm} statements can safely be included in naked functions 4879(@pxref{Basic Asm}). While using extended @code{asm} or a mixture of 4880basic @code{asm} and C code may appear to work, they cannot be 4881depended upon to work reliably and are not supported. 4882 4883@item no_gccisr 4884@cindex @code{no_gccisr} function attribute, AVR 4885Do not use @code{__gcc_isr} pseudo instructions in a function with 4886the @code{interrupt} or @code{signal} attribute aka. interrupt 4887service routine (ISR). 4888Use this attribute if the preamble of the ISR prologue should always read 4889@example 4890push __zero_reg__ 4891push __tmp_reg__ 4892in __tmp_reg__, __SREG__ 4893push __tmp_reg__ 4894clr __zero_reg__ 4895@end example 4896and accordingly for the postamble of the epilogue --- no matter whether 4897the mentioned registers are actually used in the ISR or not. 4898Situations where you might want to use this attribute include: 4899@itemize @bullet 4900@item 4901Code that (effectively) clobbers bits of @code{SREG} other than the 4902@code{I}-flag by writing to the memory location of @code{SREG}. 4903@item 4904Code that uses inline assembler to jump to a different function which 4905expects (parts of) the prologue code as outlined above to be present. 4906@end itemize 4907To disable @code{__gcc_isr} generation for the whole compilation unit, 4908there is option @option{-mno-gas-isr-prologues}, @pxref{AVR Options}. 4909 4910@item OS_main 4911@itemx OS_task 4912@cindex @code{OS_main} function attribute, AVR 4913@cindex @code{OS_task} function attribute, AVR 4914On AVR, functions with the @code{OS_main} or @code{OS_task} attribute 4915do not save/restore any call-saved register in their prologue/epilogue. 4916 4917The @code{OS_main} attribute can be used when there @emph{is 4918guarantee} that interrupts are disabled at the time when the function 4919is entered. This saves resources when the stack pointer has to be 4920changed to set up a frame for local variables. 4921 4922The @code{OS_task} attribute can be used when there is @emph{no 4923guarantee} that interrupts are disabled at that time when the function 4924is entered like for, e@.g@. task functions in a multi-threading operating 4925system. In that case, changing the stack pointer register is 4926guarded by save/clear/restore of the global interrupt enable flag. 4927 4928The differences to the @code{naked} function attribute are: 4929@itemize @bullet 4930@item @code{naked} functions do not have a return instruction whereas 4931@code{OS_main} and @code{OS_task} functions have a @code{RET} or 4932@code{RETI} return instruction. 4933@item @code{naked} functions do not set up a frame for local variables 4934or a frame pointer whereas @code{OS_main} and @code{OS_task} do this 4935as needed. 4936@end itemize 4937 4938@item signal 4939@cindex @code{signal} function attribute, AVR 4940Use this attribute on the AVR to indicate that the specified 4941function is an interrupt handler. The compiler generates function 4942entry and exit sequences suitable for use in an interrupt handler when this 4943attribute is present. 4944 4945See also the @code{interrupt} function attribute. 4946 4947The AVR hardware globally disables interrupts when an interrupt is executed. 4948Interrupt handler functions defined with the @code{signal} attribute 4949do not re-enable interrupts. It is save to enable interrupts in a 4950@code{signal} handler. This ``save'' only applies to the code 4951generated by the compiler and not to the IRQ layout of the 4952application which is responsibility of the application. 4953 4954If both @code{signal} and @code{interrupt} are specified for the same 4955function, @code{signal} is silently ignored. 4956@end table 4957 4958@node Blackfin Function Attributes 4959@subsection Blackfin Function Attributes 4960 4961These function attributes are supported by the Blackfin back end: 4962 4963@table @code 4964 4965@item exception_handler 4966@cindex @code{exception_handler} function attribute 4967@cindex exception handler functions, Blackfin 4968Use this attribute on the Blackfin to indicate that the specified function 4969is an exception handler. The compiler generates function entry and 4970exit sequences suitable for use in an exception handler when this 4971attribute is present. 4972 4973@item interrupt_handler 4974@cindex @code{interrupt_handler} function attribute, Blackfin 4975Use this attribute to 4976indicate that the specified function is an interrupt handler. The compiler 4977generates function entry and exit sequences suitable for use in an 4978interrupt handler when this attribute is present. 4979 4980@item kspisusp 4981@cindex @code{kspisusp} function attribute, Blackfin 4982@cindex User stack pointer in interrupts on the Blackfin 4983When used together with @code{interrupt_handler}, @code{exception_handler} 4984or @code{nmi_handler}, code is generated to load the stack pointer 4985from the USP register in the function prologue. 4986 4987@item l1_text 4988@cindex @code{l1_text} function attribute, Blackfin 4989This attribute specifies a function to be placed into L1 Instruction 4990SRAM@. The function is put into a specific section named @code{.l1.text}. 4991With @option{-mfdpic}, function calls with a such function as the callee 4992or caller uses inlined PLT. 4993 4994@item l2 4995@cindex @code{l2} function attribute, Blackfin 4996This attribute specifies a function to be placed into L2 4997SRAM. The function is put into a specific section named 4998@code{.l2.text}. With @option{-mfdpic}, callers of such functions use 4999an inlined PLT. 5000 5001@item longcall 5002@itemx shortcall 5003@cindex indirect calls, Blackfin 5004@cindex @code{longcall} function attribute, Blackfin 5005@cindex @code{shortcall} function attribute, Blackfin 5006The @code{longcall} attribute 5007indicates that the function might be far away from the call site and 5008require a different (more expensive) calling sequence. The 5009@code{shortcall} attribute indicates that the function is always close 5010enough for the shorter calling sequence to be used. These attributes 5011override the @option{-mlongcall} switch. 5012 5013@item nesting 5014@cindex @code{nesting} function attribute, Blackfin 5015@cindex Allow nesting in an interrupt handler on the Blackfin processor 5016Use this attribute together with @code{interrupt_handler}, 5017@code{exception_handler} or @code{nmi_handler} to indicate that the function 5018entry code should enable nested interrupts or exceptions. 5019 5020@item nmi_handler 5021@cindex @code{nmi_handler} function attribute, Blackfin 5022@cindex NMI handler functions on the Blackfin processor 5023Use this attribute on the Blackfin to indicate that the specified function 5024is an NMI handler. The compiler generates function entry and 5025exit sequences suitable for use in an NMI handler when this 5026attribute is present. 5027 5028@item saveall 5029@cindex @code{saveall} function attribute, Blackfin 5030@cindex save all registers on the Blackfin 5031Use this attribute to indicate that 5032all registers except the stack pointer should be saved in the prologue 5033regardless of whether they are used or not. 5034@end table 5035 5036@node BPF Function Attributes 5037@subsection BPF Function Attributes 5038 5039These function attributes are supported by the BPF back end: 5040 5041@table @code 5042@item kernel_helper 5043@cindex @code{kernel helper}, function attribute, BPF 5044use this attribute to indicate the specified function declaration is a 5045kernel helper. The helper function is passed as an argument to the 5046attribute. Example: 5047 5048@smallexample 5049int bpf_probe_read (void *dst, int size, const void *unsafe_ptr) 5050 __attribute__ ((kernel_helper (4))); 5051@end smallexample 5052@end table 5053 5054@node CR16 Function Attributes 5055@subsection CR16 Function Attributes 5056 5057These function attributes are supported by the CR16 back end: 5058 5059@table @code 5060@item interrupt 5061@cindex @code{interrupt} function attribute, CR16 5062Use this attribute to indicate 5063that the specified function is an interrupt handler. The compiler generates 5064function entry and exit sequences suitable for use in an interrupt handler 5065when this attribute is present. 5066@end table 5067 5068@node C-SKY Function Attributes 5069@subsection C-SKY Function Attributes 5070 5071These function attributes are supported by the C-SKY back end: 5072 5073@table @code 5074@item interrupt 5075@itemx isr 5076@cindex @code{interrupt} function attribute, C-SKY 5077@cindex @code{isr} function attribute, C-SKY 5078Use these attributes to indicate that the specified function 5079is an interrupt handler. 5080The compiler generates function entry and exit sequences suitable for 5081use in an interrupt handler when either of these attributes are present. 5082 5083Use of these options requires the @option{-mistack} command-line option 5084to enable support for the necessary interrupt stack instructions. They 5085are ignored with a warning otherwise. @xref{C-SKY Options}. 5086 5087@item naked 5088@cindex @code{naked} function attribute, C-SKY 5089This attribute allows the compiler to construct the 5090requisite function declaration, while allowing the body of the 5091function to be assembly code. The specified function will not have 5092prologue/epilogue sequences generated by the compiler. Only basic 5093@code{asm} statements can safely be included in naked functions 5094(@pxref{Basic Asm}). While using extended @code{asm} or a mixture of 5095basic @code{asm} and C code may appear to work, they cannot be 5096depended upon to work reliably and are not supported. 5097@end table 5098 5099 5100@node Epiphany Function Attributes 5101@subsection Epiphany Function Attributes 5102 5103These function attributes are supported by the Epiphany back end: 5104 5105@table @code 5106@item disinterrupt 5107@cindex @code{disinterrupt} function attribute, Epiphany 5108This attribute causes the compiler to emit 5109instructions to disable interrupts for the duration of the given 5110function. 5111 5112@item forwarder_section 5113@cindex @code{forwarder_section} function attribute, Epiphany 5114This attribute modifies the behavior of an interrupt handler. 5115The interrupt handler may be in external memory which cannot be 5116reached by a branch instruction, so generate a local memory trampoline 5117to transfer control. The single parameter identifies the section where 5118the trampoline is placed. 5119 5120@item interrupt 5121@cindex @code{interrupt} function attribute, Epiphany 5122Use this attribute to indicate 5123that the specified function is an interrupt handler. The compiler generates 5124function entry and exit sequences suitable for use in an interrupt handler 5125when this attribute is present. It may also generate 5126a special section with code to initialize the interrupt vector table. 5127 5128On Epiphany targets one or more optional parameters can be added like this: 5129 5130@smallexample 5131void __attribute__ ((interrupt ("dma0, dma1"))) universal_dma_handler (); 5132@end smallexample 5133 5134Permissible values for these parameters are: @w{@code{reset}}, 5135@w{@code{software_exception}}, @w{@code{page_miss}}, 5136@w{@code{timer0}}, @w{@code{timer1}}, @w{@code{message}}, 5137@w{@code{dma0}}, @w{@code{dma1}}, @w{@code{wand}} and @w{@code{swi}}. 5138Multiple parameters indicate that multiple entries in the interrupt 5139vector table should be initialized for this function, i.e.@: for each 5140parameter @w{@var{name}}, a jump to the function is emitted in 5141the section @w{ivt_entry_@var{name}}. The parameter(s) may be omitted 5142entirely, in which case no interrupt vector table entry is provided. 5143 5144Note that interrupts are enabled inside the function 5145unless the @code{disinterrupt} attribute is also specified. 5146 5147The following examples are all valid uses of these attributes on 5148Epiphany targets: 5149@smallexample 5150void __attribute__ ((interrupt)) universal_handler (); 5151void __attribute__ ((interrupt ("dma1"))) dma1_handler (); 5152void __attribute__ ((interrupt ("dma0, dma1"))) 5153 universal_dma_handler (); 5154void __attribute__ ((interrupt ("timer0"), disinterrupt)) 5155 fast_timer_handler (); 5156void __attribute__ ((interrupt ("dma0, dma1"), 5157 forwarder_section ("tramp"))) 5158 external_dma_handler (); 5159@end smallexample 5160 5161@item long_call 5162@itemx short_call 5163@cindex @code{long_call} function attribute, Epiphany 5164@cindex @code{short_call} function attribute, Epiphany 5165@cindex indirect calls, Epiphany 5166These attributes specify how a particular function is called. 5167These attributes override the 5168@option{-mlong-calls} (@pxref{Adapteva Epiphany Options}) 5169command-line switch and @code{#pragma long_calls} settings. 5170@end table 5171 5172 5173@node H8/300 Function Attributes 5174@subsection H8/300 Function Attributes 5175 5176These function attributes are available for H8/300 targets: 5177 5178@table @code 5179@item function_vector 5180@cindex @code{function_vector} function attribute, H8/300 5181Use this attribute on the H8/300, H8/300H, and H8S to indicate 5182that the specified function should be called through the function vector. 5183Calling a function through the function vector reduces code size; however, 5184the function vector has a limited size (maximum 128 entries on the H8/300 5185and 64 entries on the H8/300H and H8S) 5186and shares space with the interrupt vector. 5187 5188@item interrupt_handler 5189@cindex @code{interrupt_handler} function attribute, H8/300 5190Use this attribute on the H8/300, H8/300H, and H8S to 5191indicate that the specified function is an interrupt handler. The compiler 5192generates function entry and exit sequences suitable for use in an 5193interrupt handler when this attribute is present. 5194 5195@item saveall 5196@cindex @code{saveall} function attribute, H8/300 5197@cindex save all registers on the H8/300, H8/300H, and H8S 5198Use this attribute on the H8/300, H8/300H, and H8S to indicate that 5199all registers except the stack pointer should be saved in the prologue 5200regardless of whether they are used or not. 5201@end table 5202 5203@node IA-64 Function Attributes 5204@subsection IA-64 Function Attributes 5205 5206These function attributes are supported on IA-64 targets: 5207 5208@table @code 5209@item syscall_linkage 5210@cindex @code{syscall_linkage} function attribute, IA-64 5211This attribute is used to modify the IA-64 calling convention by marking 5212all input registers as live at all function exits. This makes it possible 5213to restart a system call after an interrupt without having to save/restore 5214the input registers. This also prevents kernel data from leaking into 5215application code. 5216 5217@item version_id 5218@cindex @code{version_id} function attribute, IA-64 5219This IA-64 HP-UX attribute, attached to a global variable or function, renames a 5220symbol to contain a version string, thus allowing for function level 5221versioning. HP-UX system header files may use function level versioning 5222for some system calls. 5223 5224@smallexample 5225extern int foo () __attribute__((version_id ("20040821"))); 5226@end smallexample 5227 5228@noindent 5229Calls to @code{foo} are mapped to calls to @code{foo@{20040821@}}. 5230@end table 5231 5232@node M32C Function Attributes 5233@subsection M32C Function Attributes 5234 5235These function attributes are supported by the M32C back end: 5236 5237@table @code 5238@item bank_switch 5239@cindex @code{bank_switch} function attribute, M32C 5240When added to an interrupt handler with the M32C port, causes the 5241prologue and epilogue to use bank switching to preserve the registers 5242rather than saving them on the stack. 5243 5244@item fast_interrupt 5245@cindex @code{fast_interrupt} function attribute, M32C 5246Use this attribute on the M32C port to indicate that the specified 5247function is a fast interrupt handler. This is just like the 5248@code{interrupt} attribute, except that @code{freit} is used to return 5249instead of @code{reit}. 5250 5251@item function_vector 5252@cindex @code{function_vector} function attribute, M16C/M32C 5253On M16C/M32C targets, the @code{function_vector} attribute declares a 5254special page subroutine call function. Use of this attribute reduces 5255the code size by 2 bytes for each call generated to the 5256subroutine. The argument to the attribute is the vector number entry 5257from the special page vector table which contains the 16 low-order 5258bits of the subroutine's entry address. Each vector table has special 5259page number (18 to 255) that is used in @code{jsrs} instructions. 5260Jump addresses of the routines are generated by adding 0x0F0000 (in 5261case of M16C targets) or 0xFF0000 (in case of M32C targets), to the 52622-byte addresses set in the vector table. Therefore you need to ensure 5263that all the special page vector routines should get mapped within the 5264address range 0x0F0000 to 0x0FFFFF (for M16C) and 0xFF0000 to 0xFFFFFF 5265(for M32C). 5266 5267In the following example 2 bytes are saved for each call to 5268function @code{foo}. 5269 5270@smallexample 5271void foo (void) __attribute__((function_vector(0x18))); 5272void foo (void) 5273@{ 5274@} 5275 5276void bar (void) 5277@{ 5278 foo(); 5279@} 5280@end smallexample 5281 5282If functions are defined in one file and are called in another file, 5283then be sure to write this declaration in both files. 5284 5285This attribute is ignored for R8C target. 5286 5287@item interrupt 5288@cindex @code{interrupt} function attribute, M32C 5289Use this attribute to indicate 5290that the specified function is an interrupt handler. The compiler generates 5291function entry and exit sequences suitable for use in an interrupt handler 5292when this attribute is present. 5293@end table 5294 5295@node M32R/D Function Attributes 5296@subsection M32R/D Function Attributes 5297 5298These function attributes are supported by the M32R/D back end: 5299 5300@table @code 5301@item interrupt 5302@cindex @code{interrupt} function attribute, M32R/D 5303Use this attribute to indicate 5304that the specified function is an interrupt handler. The compiler generates 5305function entry and exit sequences suitable for use in an interrupt handler 5306when this attribute is present. 5307 5308@item model (@var{model-name}) 5309@cindex @code{model} function attribute, M32R/D 5310@cindex function addressability on the M32R/D 5311 5312On the M32R/D, use this attribute to set the addressability of an 5313object, and of the code generated for a function. The identifier 5314@var{model-name} is one of @code{small}, @code{medium}, or 5315@code{large}, representing each of the code models. 5316 5317Small model objects live in the lower 16MB of memory (so that their 5318addresses can be loaded with the @code{ld24} instruction), and are 5319callable with the @code{bl} instruction. 5320 5321Medium model objects may live anywhere in the 32-bit address space (the 5322compiler generates @code{seth/add3} instructions to load their addresses), 5323and are callable with the @code{bl} instruction. 5324 5325Large model objects may live anywhere in the 32-bit address space (the 5326compiler generates @code{seth/add3} instructions to load their addresses), 5327and may not be reachable with the @code{bl} instruction (the compiler 5328generates the much slower @code{seth/add3/jl} instruction sequence). 5329@end table 5330 5331@node m68k Function Attributes 5332@subsection m68k Function Attributes 5333 5334These function attributes are supported by the m68k back end: 5335 5336@table @code 5337@item interrupt 5338@itemx interrupt_handler 5339@cindex @code{interrupt} function attribute, m68k 5340@cindex @code{interrupt_handler} function attribute, m68k 5341Use this attribute to 5342indicate that the specified function is an interrupt handler. The compiler 5343generates function entry and exit sequences suitable for use in an 5344interrupt handler when this attribute is present. Either name may be used. 5345 5346@item interrupt_thread 5347@cindex @code{interrupt_thread} function attribute, fido 5348Use this attribute on fido, a subarchitecture of the m68k, to indicate 5349that the specified function is an interrupt handler that is designed 5350to run as a thread. The compiler omits generate prologue/epilogue 5351sequences and replaces the return instruction with a @code{sleep} 5352instruction. This attribute is available only on fido. 5353@end table 5354 5355@node MCORE Function Attributes 5356@subsection MCORE Function Attributes 5357 5358These function attributes are supported by the MCORE back end: 5359 5360@table @code 5361@item naked 5362@cindex @code{naked} function attribute, MCORE 5363This attribute allows the compiler to construct the 5364requisite function declaration, while allowing the body of the 5365function to be assembly code. The specified function will not have 5366prologue/epilogue sequences generated by the compiler. Only basic 5367@code{asm} statements can safely be included in naked functions 5368(@pxref{Basic Asm}). While using extended @code{asm} or a mixture of 5369basic @code{asm} and C code may appear to work, they cannot be 5370depended upon to work reliably and are not supported. 5371@end table 5372 5373@node MeP Function Attributes 5374@subsection MeP Function Attributes 5375 5376These function attributes are supported by the MeP back end: 5377 5378@table @code 5379@item disinterrupt 5380@cindex @code{disinterrupt} function attribute, MeP 5381On MeP targets, this attribute causes the compiler to emit 5382instructions to disable interrupts for the duration of the given 5383function. 5384 5385@item interrupt 5386@cindex @code{interrupt} function attribute, MeP 5387Use this attribute to indicate 5388that the specified function is an interrupt handler. The compiler generates 5389function entry and exit sequences suitable for use in an interrupt handler 5390when this attribute is present. 5391 5392@item near 5393@cindex @code{near} function attribute, MeP 5394This attribute causes the compiler to assume the called 5395function is close enough to use the normal calling convention, 5396overriding the @option{-mtf} command-line option. 5397 5398@item far 5399@cindex @code{far} function attribute, MeP 5400On MeP targets this causes the compiler to use a calling convention 5401that assumes the called function is too far away for the built-in 5402addressing modes. 5403 5404@item vliw 5405@cindex @code{vliw} function attribute, MeP 5406The @code{vliw} attribute tells the compiler to emit 5407instructions in VLIW mode instead of core mode. Note that this 5408attribute is not allowed unless a VLIW coprocessor has been configured 5409and enabled through command-line options. 5410@end table 5411 5412@node MicroBlaze Function Attributes 5413@subsection MicroBlaze Function Attributes 5414 5415These function attributes are supported on MicroBlaze targets: 5416 5417@table @code 5418@item save_volatiles 5419@cindex @code{save_volatiles} function attribute, MicroBlaze 5420Use this attribute to indicate that the function is 5421an interrupt handler. All volatile registers (in addition to non-volatile 5422registers) are saved in the function prologue. If the function is a leaf 5423function, only volatiles used by the function are saved. A normal function 5424return is generated instead of a return from interrupt. 5425 5426@item break_handler 5427@cindex @code{break_handler} function attribute, MicroBlaze 5428@cindex break handler functions 5429Use this attribute to indicate that 5430the specified function is a break handler. The compiler generates function 5431entry and exit sequences suitable for use in an break handler when this 5432attribute is present. The return from @code{break_handler} is done through 5433the @code{rtbd} instead of @code{rtsd}. 5434 5435@smallexample 5436void f () __attribute__ ((break_handler)); 5437@end smallexample 5438 5439@item interrupt_handler 5440@itemx fast_interrupt 5441@cindex @code{interrupt_handler} function attribute, MicroBlaze 5442@cindex @code{fast_interrupt} function attribute, MicroBlaze 5443These attributes indicate that the specified function is an interrupt 5444handler. Use the @code{fast_interrupt} attribute to indicate handlers 5445used in low-latency interrupt mode, and @code{interrupt_handler} for 5446interrupts that do not use low-latency handlers. In both cases, GCC 5447emits appropriate prologue code and generates a return from the handler 5448using @code{rtid} instead of @code{rtsd}. 5449@end table 5450 5451@node Microsoft Windows Function Attributes 5452@subsection Microsoft Windows Function Attributes 5453 5454The following attributes are available on Microsoft Windows and Symbian OS 5455targets. 5456 5457@table @code 5458@item dllexport 5459@cindex @code{dllexport} function attribute 5460@cindex @code{__declspec(dllexport)} 5461On Microsoft Windows targets and Symbian OS targets the 5462@code{dllexport} attribute causes the compiler to provide a global 5463pointer to a pointer in a DLL, so that it can be referenced with the 5464@code{dllimport} attribute. On Microsoft Windows targets, the pointer 5465name is formed by combining @code{_imp__} and the function or variable 5466name. 5467 5468You can use @code{__declspec(dllexport)} as a synonym for 5469@code{__attribute__ ((dllexport))} for compatibility with other 5470compilers. 5471 5472On systems that support the @code{visibility} attribute, this 5473attribute also implies ``default'' visibility. It is an error to 5474explicitly specify any other visibility. 5475 5476GCC's default behavior is to emit all inline functions with the 5477@code{dllexport} attribute. Since this can cause object file-size bloat, 5478you can use @option{-fno-keep-inline-dllexport}, which tells GCC to 5479ignore the attribute for inlined functions unless the 5480@option{-fkeep-inline-functions} flag is used instead. 5481 5482The attribute is ignored for undefined symbols. 5483 5484When applied to C++ classes, the attribute marks defined non-inlined 5485member functions and static data members as exports. Static consts 5486initialized in-class are not marked unless they are also defined 5487out-of-class. 5488 5489For Microsoft Windows targets there are alternative methods for 5490including the symbol in the DLL's export table such as using a 5491@file{.def} file with an @code{EXPORTS} section or, with GNU ld, using 5492the @option{--export-all} linker flag. 5493 5494@item dllimport 5495@cindex @code{dllimport} function attribute 5496@cindex @code{__declspec(dllimport)} 5497On Microsoft Windows and Symbian OS targets, the @code{dllimport} 5498attribute causes the compiler to reference a function or variable via 5499a global pointer to a pointer that is set up by the DLL exporting the 5500symbol. The attribute implies @code{extern}. On Microsoft Windows 5501targets, the pointer name is formed by combining @code{_imp__} and the 5502function or variable name. 5503 5504You can use @code{__declspec(dllimport)} as a synonym for 5505@code{__attribute__ ((dllimport))} for compatibility with other 5506compilers. 5507 5508On systems that support the @code{visibility} attribute, this 5509attribute also implies ``default'' visibility. It is an error to 5510explicitly specify any other visibility. 5511 5512Currently, the attribute is ignored for inlined functions. If the 5513attribute is applied to a symbol @emph{definition}, an error is reported. 5514If a symbol previously declared @code{dllimport} is later defined, the 5515attribute is ignored in subsequent references, and a warning is emitted. 5516The attribute is also overridden by a subsequent declaration as 5517@code{dllexport}. 5518 5519When applied to C++ classes, the attribute marks non-inlined 5520member functions and static data members as imports. However, the 5521attribute is ignored for virtual methods to allow creation of vtables 5522using thunks. 5523 5524On the SH Symbian OS target the @code{dllimport} attribute also has 5525another affect---it can cause the vtable and run-time type information 5526for a class to be exported. This happens when the class has a 5527dllimported constructor or a non-inline, non-pure virtual function 5528and, for either of those two conditions, the class also has an inline 5529constructor or destructor and has a key function that is defined in 5530the current translation unit. 5531 5532For Microsoft Windows targets the use of the @code{dllimport} 5533attribute on functions is not necessary, but provides a small 5534performance benefit by eliminating a thunk in the DLL@. The use of the 5535@code{dllimport} attribute on imported variables can be avoided by passing the 5536@option{--enable-auto-import} switch to the GNU linker. As with 5537functions, using the attribute for a variable eliminates a thunk in 5538the DLL@. 5539 5540One drawback to using this attribute is that a pointer to a 5541@emph{variable} marked as @code{dllimport} cannot be used as a constant 5542address. However, a pointer to a @emph{function} with the 5543@code{dllimport} attribute can be used as a constant initializer; in 5544this case, the address of a stub function in the import lib is 5545referenced. On Microsoft Windows targets, the attribute can be disabled 5546for functions by setting the @option{-mnop-fun-dllimport} flag. 5547@end table 5548 5549@node MIPS Function Attributes 5550@subsection MIPS Function Attributes 5551 5552These function attributes are supported by the MIPS back end: 5553 5554@table @code 5555@item interrupt 5556@cindex @code{interrupt} function attribute, MIPS 5557Use this attribute to indicate that the specified function is an interrupt 5558handler. The compiler generates function entry and exit sequences suitable 5559for use in an interrupt handler when this attribute is present. 5560An optional argument is supported for the interrupt attribute which allows 5561the interrupt mode to be described. By default GCC assumes the external 5562interrupt controller (EIC) mode is in use, this can be explicitly set using 5563@code{eic}. When interrupts are non-masked then the requested Interrupt 5564Priority Level (IPL) is copied to the current IPL which has the effect of only 5565enabling higher priority interrupts. To use vectored interrupt mode use 5566the argument @code{vector=[sw0|sw1|hw0|hw1|hw2|hw3|hw4|hw5]}, this will change 5567the behavior of the non-masked interrupt support and GCC will arrange to mask 5568all interrupts from sw0 up to and including the specified interrupt vector. 5569 5570You can use the following attributes to modify the behavior 5571of an interrupt handler: 5572@table @code 5573@item use_shadow_register_set 5574@cindex @code{use_shadow_register_set} function attribute, MIPS 5575Assume that the handler uses a shadow register set, instead of 5576the main general-purpose registers. An optional argument @code{intstack} is 5577supported to indicate that the shadow register set contains a valid stack 5578pointer. 5579 5580@item keep_interrupts_masked 5581@cindex @code{keep_interrupts_masked} function attribute, MIPS 5582Keep interrupts masked for the whole function. Without this attribute, 5583GCC tries to reenable interrupts for as much of the function as it can. 5584 5585@item use_debug_exception_return 5586@cindex @code{use_debug_exception_return} function attribute, MIPS 5587Return using the @code{deret} instruction. Interrupt handlers that don't 5588have this attribute return using @code{eret} instead. 5589@end table 5590 5591You can use any combination of these attributes, as shown below: 5592@smallexample 5593void __attribute__ ((interrupt)) v0 (); 5594void __attribute__ ((interrupt, use_shadow_register_set)) v1 (); 5595void __attribute__ ((interrupt, keep_interrupts_masked)) v2 (); 5596void __attribute__ ((interrupt, use_debug_exception_return)) v3 (); 5597void __attribute__ ((interrupt, use_shadow_register_set, 5598 keep_interrupts_masked)) v4 (); 5599void __attribute__ ((interrupt, use_shadow_register_set, 5600 use_debug_exception_return)) v5 (); 5601void __attribute__ ((interrupt, keep_interrupts_masked, 5602 use_debug_exception_return)) v6 (); 5603void __attribute__ ((interrupt, use_shadow_register_set, 5604 keep_interrupts_masked, 5605 use_debug_exception_return)) v7 (); 5606void __attribute__ ((interrupt("eic"))) v8 (); 5607void __attribute__ ((interrupt("vector=hw3"))) v9 (); 5608@end smallexample 5609 5610@item long_call 5611@itemx short_call 5612@itemx near 5613@itemx far 5614@cindex indirect calls, MIPS 5615@cindex @code{long_call} function attribute, MIPS 5616@cindex @code{short_call} function attribute, MIPS 5617@cindex @code{near} function attribute, MIPS 5618@cindex @code{far} function attribute, MIPS 5619These attributes specify how a particular function is called on MIPS@. 5620The attributes override the @option{-mlong-calls} (@pxref{MIPS Options}) 5621command-line switch. The @code{long_call} and @code{far} attributes are 5622synonyms, and cause the compiler to always call 5623the function by first loading its address into a register, and then using 5624the contents of that register. The @code{short_call} and @code{near} 5625attributes are synonyms, and have the opposite 5626effect; they specify that non-PIC calls should be made using the more 5627efficient @code{jal} instruction. 5628 5629@item mips16 5630@itemx nomips16 5631@cindex @code{mips16} function attribute, MIPS 5632@cindex @code{nomips16} function attribute, MIPS 5633 5634On MIPS targets, you can use the @code{mips16} and @code{nomips16} 5635function attributes to locally select or turn off MIPS16 code generation. 5636A function with the @code{mips16} attribute is emitted as MIPS16 code, 5637while MIPS16 code generation is disabled for functions with the 5638@code{nomips16} attribute. These attributes override the 5639@option{-mips16} and @option{-mno-mips16} options on the command line 5640(@pxref{MIPS Options}). 5641 5642When compiling files containing mixed MIPS16 and non-MIPS16 code, the 5643preprocessor symbol @code{__mips16} reflects the setting on the command line, 5644not that within individual functions. Mixed MIPS16 and non-MIPS16 code 5645may interact badly with some GCC extensions such as @code{__builtin_apply} 5646(@pxref{Constructing Calls}). 5647 5648@item micromips, MIPS 5649@itemx nomicromips, MIPS 5650@cindex @code{micromips} function attribute 5651@cindex @code{nomicromips} function attribute 5652 5653On MIPS targets, you can use the @code{micromips} and @code{nomicromips} 5654function attributes to locally select or turn off microMIPS code generation. 5655A function with the @code{micromips} attribute is emitted as microMIPS code, 5656while microMIPS code generation is disabled for functions with the 5657@code{nomicromips} attribute. These attributes override the 5658@option{-mmicromips} and @option{-mno-micromips} options on the command line 5659(@pxref{MIPS Options}). 5660 5661When compiling files containing mixed microMIPS and non-microMIPS code, the 5662preprocessor symbol @code{__mips_micromips} reflects the setting on the 5663command line, 5664not that within individual functions. Mixed microMIPS and non-microMIPS code 5665may interact badly with some GCC extensions such as @code{__builtin_apply} 5666(@pxref{Constructing Calls}). 5667 5668@item nocompression 5669@cindex @code{nocompression} function attribute, MIPS 5670On MIPS targets, you can use the @code{nocompression} function attribute 5671to locally turn off MIPS16 and microMIPS code generation. This attribute 5672overrides the @option{-mips16} and @option{-mmicromips} options on the 5673command line (@pxref{MIPS Options}). 5674@end table 5675 5676@node MSP430 Function Attributes 5677@subsection MSP430 Function Attributes 5678 5679These function attributes are supported by the MSP430 back end: 5680 5681@table @code 5682@item critical 5683@cindex @code{critical} function attribute, MSP430 5684Critical functions disable interrupts upon entry and restore the 5685previous interrupt state upon exit. Critical functions cannot also 5686have the @code{naked}, @code{reentrant} or @code{interrupt} attributes. 5687 5688The MSP430 hardware ensures that interrupts are disabled on entry to 5689@code{interrupt} functions, and restores the previous interrupt state 5690on exit. The @code{critical} attribute is therefore redundant on 5691@code{interrupt} functions. 5692 5693@item interrupt 5694@cindex @code{interrupt} function attribute, MSP430 5695Use this attribute to indicate 5696that the specified function is an interrupt handler. The compiler generates 5697function entry and exit sequences suitable for use in an interrupt handler 5698when this attribute is present. 5699 5700You can provide an argument to the interrupt 5701attribute which specifies a name or number. If the argument is a 5702number it indicates the slot in the interrupt vector table (0 - 31) to 5703which this handler should be assigned. If the argument is a name it 5704is treated as a symbolic name for the vector slot. These names should 5705match up with appropriate entries in the linker script. By default 5706the names @code{watchdog} for vector 26, @code{nmi} for vector 30 and 5707@code{reset} for vector 31 are recognized. 5708 5709@item naked 5710@cindex @code{naked} function attribute, MSP430 5711This attribute allows the compiler to construct the 5712requisite function declaration, while allowing the body of the 5713function to be assembly code. The specified function will not have 5714prologue/epilogue sequences generated by the compiler. Only basic 5715@code{asm} statements can safely be included in naked functions 5716(@pxref{Basic Asm}). While using extended @code{asm} or a mixture of 5717basic @code{asm} and C code may appear to work, they cannot be 5718depended upon to work reliably and are not supported. 5719 5720@item reentrant 5721@cindex @code{reentrant} function attribute, MSP430 5722Reentrant functions disable interrupts upon entry and enable them 5723upon exit. Reentrant functions cannot also have the @code{naked} 5724or @code{critical} attributes. They can have the @code{interrupt} 5725attribute. 5726 5727@item wakeup 5728@cindex @code{wakeup} function attribute, MSP430 5729This attribute only applies to interrupt functions. It is silently 5730ignored if applied to a non-interrupt function. A wakeup interrupt 5731function will rouse the processor from any low-power state that it 5732might be in when the function exits. 5733 5734@item lower 5735@itemx upper 5736@itemx either 5737@cindex @code{lower} function attribute, MSP430 5738@cindex @code{upper} function attribute, MSP430 5739@cindex @code{either} function attribute, MSP430 5740On the MSP430 target these attributes can be used to specify whether 5741the function or variable should be placed into low memory, high 5742memory, or the placement should be left to the linker to decide. The 5743attributes are only significant if compiling for the MSP430X 5744architecture in the large memory model. 5745 5746The attributes work in conjunction with a linker script that has been 5747augmented to specify where to place sections with a @code{.lower} and 5748a @code{.upper} prefix. So, for example, as well as placing the 5749@code{.data} section, the script also specifies the placement of a 5750@code{.lower.data} and a @code{.upper.data} section. The intention 5751is that @code{lower} sections are placed into a small but easier to 5752access memory region and the upper sections are placed into a larger, but 5753slower to access, region. 5754 5755The @code{either} attribute is special. It tells the linker to place 5756the object into the corresponding @code{lower} section if there is 5757room for it. If there is insufficient room then the object is placed 5758into the corresponding @code{upper} section instead. Note that the 5759placement algorithm is not very sophisticated. It does not attempt to 5760find an optimal packing of the @code{lower} sections. It just makes 5761one pass over the objects and does the best that it can. Using the 5762@option{-ffunction-sections} and @option{-fdata-sections} command-line 5763options can help the packing, however, since they produce smaller, 5764easier to pack regions. 5765@end table 5766 5767@node NDS32 Function Attributes 5768@subsection NDS32 Function Attributes 5769 5770These function attributes are supported by the NDS32 back end: 5771 5772@table @code 5773@item exception 5774@cindex @code{exception} function attribute 5775@cindex exception handler functions, NDS32 5776Use this attribute on the NDS32 target to indicate that the specified function 5777is an exception handler. The compiler will generate corresponding sections 5778for use in an exception handler. 5779 5780@item interrupt 5781@cindex @code{interrupt} function attribute, NDS32 5782On NDS32 target, this attribute indicates that the specified function 5783is an interrupt handler. The compiler generates corresponding sections 5784for use in an interrupt handler. You can use the following attributes 5785to modify the behavior: 5786@table @code 5787@item nested 5788@cindex @code{nested} function attribute, NDS32 5789This interrupt service routine is interruptible. 5790@item not_nested 5791@cindex @code{not_nested} function attribute, NDS32 5792This interrupt service routine is not interruptible. 5793@item nested_ready 5794@cindex @code{nested_ready} function attribute, NDS32 5795This interrupt service routine is interruptible after @code{PSW.GIE} 5796(global interrupt enable) is set. This allows interrupt service routine to 5797finish some short critical code before enabling interrupts. 5798@item save_all 5799@cindex @code{save_all} function attribute, NDS32 5800The system will help save all registers into stack before entering 5801interrupt handler. 5802@item partial_save 5803@cindex @code{partial_save} function attribute, NDS32 5804The system will help save caller registers into stack before entering 5805interrupt handler. 5806@end table 5807 5808@item naked 5809@cindex @code{naked} function attribute, NDS32 5810This attribute allows the compiler to construct the 5811requisite function declaration, while allowing the body of the 5812function to be assembly code. The specified function will not have 5813prologue/epilogue sequences generated by the compiler. Only basic 5814@code{asm} statements can safely be included in naked functions 5815(@pxref{Basic Asm}). While using extended @code{asm} or a mixture of 5816basic @code{asm} and C code may appear to work, they cannot be 5817depended upon to work reliably and are not supported. 5818 5819@item reset 5820@cindex @code{reset} function attribute, NDS32 5821@cindex reset handler functions 5822Use this attribute on the NDS32 target to indicate that the specified function 5823is a reset handler. The compiler will generate corresponding sections 5824for use in a reset handler. You can use the following attributes 5825to provide extra exception handling: 5826@table @code 5827@item nmi 5828@cindex @code{nmi} function attribute, NDS32 5829Provide a user-defined function to handle NMI exception. 5830@item warm 5831@cindex @code{warm} function attribute, NDS32 5832Provide a user-defined function to handle warm reset exception. 5833@end table 5834@end table 5835 5836@node Nios II Function Attributes 5837@subsection Nios II Function Attributes 5838 5839These function attributes are supported by the Nios II back end: 5840 5841@table @code 5842@item target (@var{options}) 5843@cindex @code{target} function attribute 5844As discussed in @ref{Common Function Attributes}, this attribute 5845allows specification of target-specific compilation options. 5846 5847When compiling for Nios II, the following options are allowed: 5848 5849@table @samp 5850@item custom-@var{insn}=@var{N} 5851@itemx no-custom-@var{insn} 5852@cindex @code{target("custom-@var{insn}=@var{N}")} function attribute, Nios II 5853@cindex @code{target("no-custom-@var{insn}")} function attribute, Nios II 5854Each @samp{custom-@var{insn}=@var{N}} attribute locally enables use of a 5855custom instruction with encoding @var{N} when generating code that uses 5856@var{insn}. Similarly, @samp{no-custom-@var{insn}} locally inhibits use of 5857the custom instruction @var{insn}. 5858These target attributes correspond to the 5859@option{-mcustom-@var{insn}=@var{N}} and @option{-mno-custom-@var{insn}} 5860command-line options, and support the same set of @var{insn} keywords. 5861@xref{Nios II Options}, for more information. 5862 5863@item custom-fpu-cfg=@var{name} 5864@cindex @code{target("custom-fpu-cfg=@var{name}")} function attribute, Nios II 5865This attribute corresponds to the @option{-mcustom-fpu-cfg=@var{name}} 5866command-line option, to select a predefined set of custom instructions 5867named @var{name}. 5868@xref{Nios II Options}, for more information. 5869@end table 5870@end table 5871 5872@node Nvidia PTX Function Attributes 5873@subsection Nvidia PTX Function Attributes 5874 5875These function attributes are supported by the Nvidia PTX back end: 5876 5877@table @code 5878@item kernel 5879@cindex @code{kernel} attribute, Nvidia PTX 5880This attribute indicates that the corresponding function should be compiled 5881as a kernel function, which can be invoked from the host via the CUDA RT 5882library. 5883By default functions are only callable only from other PTX functions. 5884 5885Kernel functions must have @code{void} return type. 5886@end table 5887 5888@node PowerPC Function Attributes 5889@subsection PowerPC Function Attributes 5890 5891These function attributes are supported by the PowerPC back end: 5892 5893@table @code 5894@item longcall 5895@itemx shortcall 5896@cindex indirect calls, PowerPC 5897@cindex @code{longcall} function attribute, PowerPC 5898@cindex @code{shortcall} function attribute, PowerPC 5899The @code{longcall} attribute 5900indicates that the function might be far away from the call site and 5901require a different (more expensive) calling sequence. The 5902@code{shortcall} attribute indicates that the function is always close 5903enough for the shorter calling sequence to be used. These attributes 5904override both the @option{-mlongcall} switch and 5905the @code{#pragma longcall} setting. 5906 5907@xref{RS/6000 and PowerPC Options}, for more information on whether long 5908calls are necessary. 5909 5910@item target (@var{options}) 5911@cindex @code{target} function attribute 5912As discussed in @ref{Common Function Attributes}, this attribute 5913allows specification of target-specific compilation options. 5914 5915On the PowerPC, the following options are allowed: 5916 5917@table @samp 5918@item altivec 5919@itemx no-altivec 5920@cindex @code{target("altivec")} function attribute, PowerPC 5921Generate code that uses (does not use) AltiVec instructions. In 592232-bit code, you cannot enable AltiVec instructions unless 5923@option{-mabi=altivec} is used on the command line. 5924 5925@item cmpb 5926@itemx no-cmpb 5927@cindex @code{target("cmpb")} function attribute, PowerPC 5928Generate code that uses (does not use) the compare bytes instruction 5929implemented on the POWER6 processor and other processors that support 5930the PowerPC V2.05 architecture. 5931 5932@item dlmzb 5933@itemx no-dlmzb 5934@cindex @code{target("dlmzb")} function attribute, PowerPC 5935Generate code that uses (does not use) the string-search @samp{dlmzb} 5936instruction on the IBM 405, 440, 464 and 476 processors. This instruction is 5937generated by default when targeting those processors. 5938 5939@item fprnd 5940@itemx no-fprnd 5941@cindex @code{target("fprnd")} function attribute, PowerPC 5942Generate code that uses (does not use) the FP round to integer 5943instructions implemented on the POWER5+ processor and other processors 5944that support the PowerPC V2.03 architecture. 5945 5946@item hard-dfp 5947@itemx no-hard-dfp 5948@cindex @code{target("hard-dfp")} function attribute, PowerPC 5949Generate code that uses (does not use) the decimal floating-point 5950instructions implemented on some POWER processors. 5951 5952@item isel 5953@itemx no-isel 5954@cindex @code{target("isel")} function attribute, PowerPC 5955Generate code that uses (does not use) ISEL instruction. 5956 5957@item mfcrf 5958@itemx no-mfcrf 5959@cindex @code{target("mfcrf")} function attribute, PowerPC 5960Generate code that uses (does not use) the move from condition 5961register field instruction implemented on the POWER4 processor and 5962other processors that support the PowerPC V2.01 architecture. 5963 5964@item mulhw 5965@itemx no-mulhw 5966@cindex @code{target("mulhw")} function attribute, PowerPC 5967Generate code that uses (does not use) the half-word multiply and 5968multiply-accumulate instructions on the IBM 405, 440, 464 and 476 processors. 5969These instructions are generated by default when targeting those 5970processors. 5971 5972@item multiple 5973@itemx no-multiple 5974@cindex @code{target("multiple")} function attribute, PowerPC 5975Generate code that uses (does not use) the load multiple word 5976instructions and the store multiple word instructions. 5977 5978@item update 5979@itemx no-update 5980@cindex @code{target("update")} function attribute, PowerPC 5981Generate code that uses (does not use) the load or store instructions 5982that update the base register to the address of the calculated memory 5983location. 5984 5985@item popcntb 5986@itemx no-popcntb 5987@cindex @code{target("popcntb")} function attribute, PowerPC 5988Generate code that uses (does not use) the popcount and double-precision 5989FP reciprocal estimate instruction implemented on the POWER5 5990processor and other processors that support the PowerPC V2.02 5991architecture. 5992 5993@item popcntd 5994@itemx no-popcntd 5995@cindex @code{target("popcntd")} function attribute, PowerPC 5996Generate code that uses (does not use) the popcount instruction 5997implemented on the POWER7 processor and other processors that support 5998the PowerPC V2.06 architecture. 5999 6000@item powerpc-gfxopt 6001@itemx no-powerpc-gfxopt 6002@cindex @code{target("powerpc-gfxopt")} function attribute, PowerPC 6003Generate code that uses (does not use) the optional PowerPC 6004architecture instructions in the Graphics group, including 6005floating-point select. 6006 6007@item powerpc-gpopt 6008@itemx no-powerpc-gpopt 6009@cindex @code{target("powerpc-gpopt")} function attribute, PowerPC 6010Generate code that uses (does not use) the optional PowerPC 6011architecture instructions in the General Purpose group, including 6012floating-point square root. 6013 6014@item recip-precision 6015@itemx no-recip-precision 6016@cindex @code{target("recip-precision")} function attribute, PowerPC 6017Assume (do not assume) that the reciprocal estimate instructions 6018provide higher-precision estimates than is mandated by the PowerPC 6019ABI. 6020 6021@item string 6022@itemx no-string 6023@cindex @code{target("string")} function attribute, PowerPC 6024Generate code that uses (does not use) the load string instructions 6025and the store string word instructions to save multiple registers and 6026do small block moves. 6027 6028@item vsx 6029@itemx no-vsx 6030@cindex @code{target("vsx")} function attribute, PowerPC 6031Generate code that uses (does not use) vector/scalar (VSX) 6032instructions, and also enable the use of built-in functions that allow 6033more direct access to the VSX instruction set. In 32-bit code, you 6034cannot enable VSX or AltiVec instructions unless 6035@option{-mabi=altivec} is used on the command line. 6036 6037@item friz 6038@itemx no-friz 6039@cindex @code{target("friz")} function attribute, PowerPC 6040Generate (do not generate) the @code{friz} instruction when the 6041@option{-funsafe-math-optimizations} option is used to optimize 6042rounding a floating-point value to 64-bit integer and back to floating 6043point. The @code{friz} instruction does not return the same value if 6044the floating-point number is too large to fit in an integer. 6045 6046@item avoid-indexed-addresses 6047@itemx no-avoid-indexed-addresses 6048@cindex @code{target("avoid-indexed-addresses")} function attribute, PowerPC 6049Generate code that tries to avoid (not avoid) the use of indexed load 6050or store instructions. 6051 6052@item paired 6053@itemx no-paired 6054@cindex @code{target("paired")} function attribute, PowerPC 6055Generate code that uses (does not use) the generation of PAIRED simd 6056instructions. 6057 6058@item longcall 6059@itemx no-longcall 6060@cindex @code{target("longcall")} function attribute, PowerPC 6061Generate code that assumes (does not assume) that all calls are far 6062away so that a longer more expensive calling sequence is required. 6063 6064@item cpu=@var{CPU} 6065@cindex @code{target("cpu=@var{CPU}")} function attribute, PowerPC 6066Specify the architecture to generate code for when compiling the 6067function. If you select the @code{target("cpu=power7")} attribute when 6068generating 32-bit code, VSX and AltiVec instructions are not generated 6069unless you use the @option{-mabi=altivec} option on the command line. 6070 6071@item tune=@var{TUNE} 6072@cindex @code{target("tune=@var{TUNE}")} function attribute, PowerPC 6073Specify the architecture to tune for when compiling the function. If 6074you do not specify the @code{target("tune=@var{TUNE}")} attribute and 6075you do specify the @code{target("cpu=@var{CPU}")} attribute, 6076compilation tunes for the @var{CPU} architecture, and not the 6077default tuning specified on the command line. 6078@end table 6079 6080On the PowerPC, the inliner does not inline a 6081function that has different target options than the caller, unless the 6082callee has a subset of the target options of the caller. 6083@end table 6084 6085@node RISC-V Function Attributes 6086@subsection RISC-V Function Attributes 6087 6088These function attributes are supported by the RISC-V back end: 6089 6090@table @code 6091@item naked 6092@cindex @code{naked} function attribute, RISC-V 6093This attribute allows the compiler to construct the 6094requisite function declaration, while allowing the body of the 6095function to be assembly code. The specified function will not have 6096prologue/epilogue sequences generated by the compiler. Only basic 6097@code{asm} statements can safely be included in naked functions 6098(@pxref{Basic Asm}). While using extended @code{asm} or a mixture of 6099basic @code{asm} and C code may appear to work, they cannot be 6100depended upon to work reliably and are not supported. 6101 6102@item interrupt 6103@cindex @code{interrupt} function attribute, RISC-V 6104Use this attribute to indicate that the specified function is an interrupt 6105handler. The compiler generates function entry and exit sequences suitable 6106for use in an interrupt handler when this attribute is present. 6107 6108You can specify the kind of interrupt to be handled by adding an optional 6109parameter to the interrupt attribute like this: 6110 6111@smallexample 6112void f (void) __attribute__ ((interrupt ("user"))); 6113@end smallexample 6114 6115Permissible values for this parameter are @code{user}, @code{supervisor}, 6116and @code{machine}. If there is no parameter, then it defaults to 6117@code{machine}. 6118@end table 6119 6120@node RL78 Function Attributes 6121@subsection RL78 Function Attributes 6122 6123These function attributes are supported by the RL78 back end: 6124 6125@table @code 6126@item interrupt 6127@itemx brk_interrupt 6128@cindex @code{interrupt} function attribute, RL78 6129@cindex @code{brk_interrupt} function attribute, RL78 6130These attributes indicate 6131that the specified function is an interrupt handler. The compiler generates 6132function entry and exit sequences suitable for use in an interrupt handler 6133when this attribute is present. 6134 6135Use @code{brk_interrupt} instead of @code{interrupt} for 6136handlers intended to be used with the @code{BRK} opcode (i.e.@: those 6137that must end with @code{RETB} instead of @code{RETI}). 6138 6139@item naked 6140@cindex @code{naked} function attribute, RL78 6141This attribute allows the compiler to construct the 6142requisite function declaration, while allowing the body of the 6143function to be assembly code. The specified function will not have 6144prologue/epilogue sequences generated by the compiler. Only basic 6145@code{asm} statements can safely be included in naked functions 6146(@pxref{Basic Asm}). While using extended @code{asm} or a mixture of 6147basic @code{asm} and C code may appear to work, they cannot be 6148depended upon to work reliably and are not supported. 6149@end table 6150 6151@node RX Function Attributes 6152@subsection RX Function Attributes 6153 6154These function attributes are supported by the RX back end: 6155 6156@table @code 6157@item fast_interrupt 6158@cindex @code{fast_interrupt} function attribute, RX 6159Use this attribute on the RX port to indicate that the specified 6160function is a fast interrupt handler. This is just like the 6161@code{interrupt} attribute, except that @code{freit} is used to return 6162instead of @code{reit}. 6163 6164@item interrupt 6165@cindex @code{interrupt} function attribute, RX 6166Use this attribute to indicate 6167that the specified function is an interrupt handler. The compiler generates 6168function entry and exit sequences suitable for use in an interrupt handler 6169when this attribute is present. 6170 6171On RX and RL78 targets, you may specify one or more vector numbers as arguments 6172to the attribute, as well as naming an alternate table name. 6173Parameters are handled sequentially, so one handler can be assigned to 6174multiple entries in multiple tables. One may also pass the magic 6175string @code{"$default"} which causes the function to be used for any 6176unfilled slots in the current table. 6177 6178This example shows a simple assignment of a function to one vector in 6179the default table (note that preprocessor macros may be used for 6180chip-specific symbolic vector names): 6181@smallexample 6182void __attribute__ ((interrupt (5))) txd1_handler (); 6183@end smallexample 6184 6185This example assigns a function to two slots in the default table 6186(using preprocessor macros defined elsewhere) and makes it the default 6187for the @code{dct} table: 6188@smallexample 6189void __attribute__ ((interrupt (RXD1_VECT,RXD2_VECT,"dct","$default"))) 6190 txd1_handler (); 6191@end smallexample 6192 6193@item naked 6194@cindex @code{naked} function attribute, RX 6195This attribute allows the compiler to construct the 6196requisite function declaration, while allowing the body of the 6197function to be assembly code. The specified function will not have 6198prologue/epilogue sequences generated by the compiler. Only basic 6199@code{asm} statements can safely be included in naked functions 6200(@pxref{Basic Asm}). While using extended @code{asm} or a mixture of 6201basic @code{asm} and C code may appear to work, they cannot be 6202depended upon to work reliably and are not supported. 6203 6204@item vector 6205@cindex @code{vector} function attribute, RX 6206This RX attribute is similar to the @code{interrupt} attribute, including its 6207parameters, but does not make the function an interrupt-handler type 6208function (i.e.@: it retains the normal C function calling ABI). See the 6209@code{interrupt} attribute for a description of its arguments. 6210@end table 6211 6212@node S/390 Function Attributes 6213@subsection S/390 Function Attributes 6214 6215These function attributes are supported on the S/390: 6216 6217@table @code 6218@item hotpatch (@var{halfwords-before-function-label},@var{halfwords-after-function-label}) 6219@cindex @code{hotpatch} function attribute, S/390 6220 6221On S/390 System z targets, you can use this function attribute to 6222make GCC generate a ``hot-patching'' function prologue. If the 6223@option{-mhotpatch=} command-line option is used at the same time, 6224the @code{hotpatch} attribute takes precedence. The first of the 6225two arguments specifies the number of halfwords to be added before 6226the function label. A second argument can be used to specify the 6227number of halfwords to be added after the function label. For 6228both arguments the maximum allowed value is 1000000. 6229 6230If both arguments are zero, hotpatching is disabled. 6231 6232@item target (@var{options}) 6233@cindex @code{target} function attribute 6234As discussed in @ref{Common Function Attributes}, this attribute 6235allows specification of target-specific compilation options. 6236 6237On S/390, the following options are supported: 6238 6239@table @samp 6240@item arch= 6241@item tune= 6242@item stack-guard= 6243@item stack-size= 6244@item branch-cost= 6245@item warn-framesize= 6246@item backchain 6247@itemx no-backchain 6248@item hard-dfp 6249@itemx no-hard-dfp 6250@item hard-float 6251@itemx soft-float 6252@item htm 6253@itemx no-htm 6254@item vx 6255@itemx no-vx 6256@item packed-stack 6257@itemx no-packed-stack 6258@item small-exec 6259@itemx no-small-exec 6260@item mvcle 6261@itemx no-mvcle 6262@item warn-dynamicstack 6263@itemx no-warn-dynamicstack 6264@end table 6265 6266The options work exactly like the S/390 specific command line 6267options (without the prefix @option{-m}) except that they do not 6268change any feature macros. For example, 6269 6270@smallexample 6271@code{target("no-vx")} 6272@end smallexample 6273 6274does not undefine the @code{__VEC__} macro. 6275@end table 6276 6277@node SH Function Attributes 6278@subsection SH Function Attributes 6279 6280These function attributes are supported on the SH family of processors: 6281 6282@table @code 6283@item function_vector 6284@cindex @code{function_vector} function attribute, SH 6285@cindex calling functions through the function vector on SH2A 6286On SH2A targets, this attribute declares a function to be called using the 6287TBR relative addressing mode. The argument to this attribute is the entry 6288number of the same function in a vector table containing all the TBR 6289relative addressable functions. For correct operation the TBR must be setup 6290accordingly to point to the start of the vector table before any functions with 6291this attribute are invoked. Usually a good place to do the initialization is 6292the startup routine. The TBR relative vector table can have at max 256 function 6293entries. The jumps to these functions are generated using a SH2A specific, 6294non delayed branch instruction JSR/N @@(disp8,TBR). You must use GAS and GLD 6295from GNU binutils version 2.7 or later for this attribute to work correctly. 6296 6297In an application, for a function being called once, this attribute 6298saves at least 8 bytes of code; and if other successive calls are being 6299made to the same function, it saves 2 bytes of code per each of these 6300calls. 6301 6302@item interrupt_handler 6303@cindex @code{interrupt_handler} function attribute, SH 6304Use this attribute to 6305indicate that the specified function is an interrupt handler. The compiler 6306generates function entry and exit sequences suitable for use in an 6307interrupt handler when this attribute is present. 6308 6309@item nosave_low_regs 6310@cindex @code{nosave_low_regs} function attribute, SH 6311Use this attribute on SH targets to indicate that an @code{interrupt_handler} 6312function should not save and restore registers R0..R7. This can be used on SH3* 6313and SH4* targets that have a second R0..R7 register bank for non-reentrant 6314interrupt handlers. 6315 6316@item renesas 6317@cindex @code{renesas} function attribute, SH 6318On SH targets this attribute specifies that the function or struct follows the 6319Renesas ABI. 6320 6321@item resbank 6322@cindex @code{resbank} function attribute, SH 6323On the SH2A target, this attribute enables the high-speed register 6324saving and restoration using a register bank for @code{interrupt_handler} 6325routines. Saving to the bank is performed automatically after the CPU 6326accepts an interrupt that uses a register bank. 6327 6328The nineteen 32-bit registers comprising general register R0 to R14, 6329control register GBR, and system registers MACH, MACL, and PR and the 6330vector table address offset are saved into a register bank. Register 6331banks are stacked in first-in last-out (FILO) sequence. Restoration 6332from the bank is executed by issuing a RESBANK instruction. 6333 6334@item sp_switch 6335@cindex @code{sp_switch} function attribute, SH 6336Use this attribute on the SH to indicate an @code{interrupt_handler} 6337function should switch to an alternate stack. It expects a string 6338argument that names a global variable holding the address of the 6339alternate stack. 6340 6341@smallexample 6342void *alt_stack; 6343void f () __attribute__ ((interrupt_handler, 6344 sp_switch ("alt_stack"))); 6345@end smallexample 6346 6347@item trap_exit 6348@cindex @code{trap_exit} function attribute, SH 6349Use this attribute on the SH for an @code{interrupt_handler} to return using 6350@code{trapa} instead of @code{rte}. This attribute expects an integer 6351argument specifying the trap number to be used. 6352 6353@item trapa_handler 6354@cindex @code{trapa_handler} function attribute, SH 6355On SH targets this function attribute is similar to @code{interrupt_handler} 6356but it does not save and restore all registers. 6357@end table 6358 6359@node Symbian OS Function Attributes 6360@subsection Symbian OS Function Attributes 6361 6362@xref{Microsoft Windows Function Attributes}, for discussion of the 6363@code{dllexport} and @code{dllimport} attributes. 6364 6365@node V850 Function Attributes 6366@subsection V850 Function Attributes 6367 6368The V850 back end supports these function attributes: 6369 6370@table @code 6371@item interrupt 6372@itemx interrupt_handler 6373@cindex @code{interrupt} function attribute, V850 6374@cindex @code{interrupt_handler} function attribute, V850 6375Use these attributes to indicate 6376that the specified function is an interrupt handler. The compiler generates 6377function entry and exit sequences suitable for use in an interrupt handler 6378when either attribute is present. 6379@end table 6380 6381@node Visium Function Attributes 6382@subsection Visium Function Attributes 6383 6384These function attributes are supported by the Visium back end: 6385 6386@table @code 6387@item interrupt 6388@cindex @code{interrupt} function attribute, Visium 6389Use this attribute to indicate 6390that the specified function is an interrupt handler. The compiler generates 6391function entry and exit sequences suitable for use in an interrupt handler 6392when this attribute is present. 6393@end table 6394 6395@node x86 Function Attributes 6396@subsection x86 Function Attributes 6397 6398These function attributes are supported by the x86 back end: 6399 6400@table @code 6401@item cdecl 6402@cindex @code{cdecl} function attribute, x86-32 6403@cindex functions that pop the argument stack on x86-32 6404@opindex mrtd 6405On the x86-32 targets, the @code{cdecl} attribute causes the compiler to 6406assume that the calling function pops off the stack space used to 6407pass arguments. This is 6408useful to override the effects of the @option{-mrtd} switch. 6409 6410@item fastcall 6411@cindex @code{fastcall} function attribute, x86-32 6412@cindex functions that pop the argument stack on x86-32 6413On x86-32 targets, the @code{fastcall} attribute causes the compiler to 6414pass the first argument (if of integral type) in the register ECX and 6415the second argument (if of integral type) in the register EDX@. Subsequent 6416and other typed arguments are passed on the stack. The called function 6417pops the arguments off the stack. If the number of arguments is variable all 6418arguments are pushed on the stack. 6419 6420@item thiscall 6421@cindex @code{thiscall} function attribute, x86-32 6422@cindex functions that pop the argument stack on x86-32 6423On x86-32 targets, the @code{thiscall} attribute causes the compiler to 6424pass the first argument (if of integral type) in the register ECX. 6425Subsequent and other typed arguments are passed on the stack. The called 6426function pops the arguments off the stack. 6427If the number of arguments is variable all arguments are pushed on the 6428stack. 6429The @code{thiscall} attribute is intended for C++ non-static member functions. 6430As a GCC extension, this calling convention can be used for C functions 6431and for static member methods. 6432 6433@item ms_abi 6434@itemx sysv_abi 6435@cindex @code{ms_abi} function attribute, x86 6436@cindex @code{sysv_abi} function attribute, x86 6437 6438On 32-bit and 64-bit x86 targets, you can use an ABI attribute 6439to indicate which calling convention should be used for a function. The 6440@code{ms_abi} attribute tells the compiler to use the Microsoft ABI, 6441while the @code{sysv_abi} attribute tells the compiler to use the System V 6442ELF ABI, which is used on GNU/Linux and other systems. The default is to use 6443the Microsoft ABI when targeting Windows. On all other systems, the default 6444is the System V ELF ABI. 6445 6446Note, the @code{ms_abi} attribute for Microsoft Windows 64-bit targets currently 6447requires the @option{-maccumulate-outgoing-args} option. 6448 6449@item callee_pop_aggregate_return (@var{number}) 6450@cindex @code{callee_pop_aggregate_return} function attribute, x86 6451 6452On x86-32 targets, you can use this attribute to control how 6453aggregates are returned in memory. If the caller is responsible for 6454popping the hidden pointer together with the rest of the arguments, specify 6455@var{number} equal to zero. If callee is responsible for popping the 6456hidden pointer, specify @var{number} equal to one. 6457 6458The default x86-32 ABI assumes that the callee pops the 6459stack for hidden pointer. However, on x86-32 Microsoft Windows targets, 6460the compiler assumes that the 6461caller pops the stack for hidden pointer. 6462 6463@item ms_hook_prologue 6464@cindex @code{ms_hook_prologue} function attribute, x86 6465 6466On 32-bit and 64-bit x86 targets, you can use 6467this function attribute to make GCC generate the ``hot-patching'' function 6468prologue used in Win32 API functions in Microsoft Windows XP Service Pack 2 6469and newer. 6470 6471@item naked 6472@cindex @code{naked} function attribute, x86 6473This attribute allows the compiler to construct the 6474requisite function declaration, while allowing the body of the 6475function to be assembly code. The specified function will not have 6476prologue/epilogue sequences generated by the compiler. Only basic 6477@code{asm} statements can safely be included in naked functions 6478(@pxref{Basic Asm}). While using extended @code{asm} or a mixture of 6479basic @code{asm} and C code may appear to work, they cannot be 6480depended upon to work reliably and are not supported. 6481 6482@item regparm (@var{number}) 6483@cindex @code{regparm} function attribute, x86 6484@cindex functions that are passed arguments in registers on x86-32 6485On x86-32 targets, the @code{regparm} attribute causes the compiler to 6486pass arguments number one to @var{number} if they are of integral type 6487in registers EAX, EDX, and ECX instead of on the stack. Functions that 6488take a variable number of arguments continue to be passed all of their 6489arguments on the stack. 6490 6491Beware that on some ELF systems this attribute is unsuitable for 6492global functions in shared libraries with lazy binding (which is the 6493default). Lazy binding sends the first call via resolving code in 6494the loader, which might assume EAX, EDX and ECX can be clobbered, as 6495per the standard calling conventions. Solaris 8 is affected by this. 6496Systems with the GNU C Library version 2.1 or higher 6497and FreeBSD are believed to be 6498safe since the loaders there save EAX, EDX and ECX. (Lazy binding can be 6499disabled with the linker or the loader if desired, to avoid the 6500problem.) 6501 6502@item sseregparm 6503@cindex @code{sseregparm} function attribute, x86 6504On x86-32 targets with SSE support, the @code{sseregparm} attribute 6505causes the compiler to pass up to 3 floating-point arguments in 6506SSE registers instead of on the stack. Functions that take a 6507variable number of arguments continue to pass all of their 6508floating-point arguments on the stack. 6509 6510@item force_align_arg_pointer 6511@cindex @code{force_align_arg_pointer} function attribute, x86 6512On x86 targets, the @code{force_align_arg_pointer} attribute may be 6513applied to individual function definitions, generating an alternate 6514prologue and epilogue that realigns the run-time stack if necessary. 6515This supports mixing legacy codes that run with a 4-byte aligned stack 6516with modern codes that keep a 16-byte stack for SSE compatibility. 6517 6518@item stdcall 6519@cindex @code{stdcall} function attribute, x86-32 6520@cindex functions that pop the argument stack on x86-32 6521On x86-32 targets, the @code{stdcall} attribute causes the compiler to 6522assume that the called function pops off the stack space used to 6523pass arguments, unless it takes a variable number of arguments. 6524 6525@item no_caller_saved_registers 6526@cindex @code{no_caller_saved_registers} function attribute, x86 6527Use this attribute to indicate that the specified function has no 6528caller-saved registers. That is, all registers are callee-saved. For 6529example, this attribute can be used for a function called from an 6530interrupt handler. The compiler generates proper function entry and 6531exit sequences to save and restore any modified registers, except for 6532the EFLAGS register. Since GCC doesn't preserve SSE, MMX nor x87 6533states, the GCC option @option{-mgeneral-regs-only} should be used to 6534compile functions with @code{no_caller_saved_registers} attribute. 6535 6536@item interrupt 6537@cindex @code{interrupt} function attribute, x86 6538Use this attribute to indicate that the specified function is an 6539interrupt handler or an exception handler (depending on parameters passed 6540to the function, explained further). The compiler generates function 6541entry and exit sequences suitable for use in an interrupt handler when 6542this attribute is present. The @code{IRET} instruction, instead of the 6543@code{RET} instruction, is used to return from interrupt handlers. All 6544registers, except for the EFLAGS register which is restored by the 6545@code{IRET} instruction, are preserved by the compiler. Since GCC 6546doesn't preserve SSE, MMX nor x87 states, the GCC option 6547@option{-mgeneral-regs-only} should be used to compile interrupt and 6548exception handlers. 6549 6550Any interruptible-without-stack-switch code must be compiled with 6551@option{-mno-red-zone} since interrupt handlers can and will, because 6552of the hardware design, touch the red zone. 6553 6554An interrupt handler must be declared with a mandatory pointer 6555argument: 6556 6557@smallexample 6558struct interrupt_frame; 6559 6560__attribute__ ((interrupt)) 6561void 6562f (struct interrupt_frame *frame) 6563@{ 6564@} 6565@end smallexample 6566 6567@noindent 6568and you must define @code{struct interrupt_frame} as described in the 6569processor's manual. 6570 6571Exception handlers differ from interrupt handlers because the system 6572pushes an error code on the stack. An exception handler declaration is 6573similar to that for an interrupt handler, but with a different mandatory 6574function signature. The compiler arranges to pop the error code off the 6575stack before the @code{IRET} instruction. 6576 6577@smallexample 6578#ifdef __x86_64__ 6579typedef unsigned long long int uword_t; 6580#else 6581typedef unsigned int uword_t; 6582#endif 6583 6584struct interrupt_frame; 6585 6586__attribute__ ((interrupt)) 6587void 6588f (struct interrupt_frame *frame, uword_t error_code) 6589@{ 6590 ... 6591@} 6592@end smallexample 6593 6594Exception handlers should only be used for exceptions that push an error 6595code; you should use an interrupt handler in other cases. The system 6596will crash if the wrong kind of handler is used. 6597 6598@item target (@var{options}) 6599@cindex @code{target} function attribute 6600As discussed in @ref{Common Function Attributes}, this attribute 6601allows specification of target-specific compilation options. 6602 6603On the x86, the following options are allowed: 6604@table @samp 6605@item 3dnow 6606@itemx no-3dnow 6607@cindex @code{target("3dnow")} function attribute, x86 6608Enable/disable the generation of the 3DNow!@: instructions. 6609 6610@item 3dnowa 6611@itemx no-3dnowa 6612@cindex @code{target("3dnowa")} function attribute, x86 6613Enable/disable the generation of the enhanced 3DNow!@: instructions. 6614 6615@item abm 6616@itemx no-abm 6617@cindex @code{target("abm")} function attribute, x86 6618Enable/disable the generation of the advanced bit instructions. 6619 6620@item adx 6621@itemx no-adx 6622@cindex @code{target("adx")} function attribute, x86 6623Enable/disable the generation of the ADX instructions. 6624 6625@item aes 6626@itemx no-aes 6627@cindex @code{target("aes")} function attribute, x86 6628Enable/disable the generation of the AES instructions. 6629 6630@item avx 6631@itemx no-avx 6632@cindex @code{target("avx")} function attribute, x86 6633Enable/disable the generation of the AVX instructions. 6634 6635@item avx2 6636@itemx no-avx2 6637@cindex @code{target("avx2")} function attribute, x86 6638Enable/disable the generation of the AVX2 instructions. 6639 6640@item avx5124fmaps 6641@itemx no-avx5124fmaps 6642@cindex @code{target("avx5124fmaps")} function attribute, x86 6643Enable/disable the generation of the AVX5124FMAPS instructions. 6644 6645@item avx5124vnniw 6646@itemx no-avx5124vnniw 6647@cindex @code{target("avx5124vnniw")} function attribute, x86 6648Enable/disable the generation of the AVX5124VNNIW instructions. 6649 6650@item avx512bitalg 6651@itemx no-avx512bitalg 6652@cindex @code{target("avx512bitalg")} function attribute, x86 6653Enable/disable the generation of the AVX512BITALG instructions. 6654 6655@item avx512bw 6656@itemx no-avx512bw 6657@cindex @code{target("avx512bw")} function attribute, x86 6658Enable/disable the generation of the AVX512BW instructions. 6659 6660@item avx512cd 6661@itemx no-avx512cd 6662@cindex @code{target("avx512cd")} function attribute, x86 6663Enable/disable the generation of the AVX512CD instructions. 6664 6665@item avx512dq 6666@itemx no-avx512dq 6667@cindex @code{target("avx512dq")} function attribute, x86 6668Enable/disable the generation of the AVX512DQ instructions. 6669 6670@item avx512er 6671@itemx no-avx512er 6672@cindex @code{target("avx512er")} function attribute, x86 6673Enable/disable the generation of the AVX512ER instructions. 6674 6675@item avx512f 6676@itemx no-avx512f 6677@cindex @code{target("avx512f")} function attribute, x86 6678Enable/disable the generation of the AVX512F instructions. 6679 6680@item avx512ifma 6681@itemx no-avx512ifma 6682@cindex @code{target("avx512ifma")} function attribute, x86 6683Enable/disable the generation of the AVX512IFMA instructions. 6684 6685@item avx512pf 6686@itemx no-avx512pf 6687@cindex @code{target("avx512pf")} function attribute, x86 6688Enable/disable the generation of the AVX512PF instructions. 6689 6690@item avx512vbmi 6691@itemx no-avx512vbmi 6692@cindex @code{target("avx512vbmi")} function attribute, x86 6693Enable/disable the generation of the AVX512VBMI instructions. 6694 6695@item avx512vbmi2 6696@itemx no-avx512vbmi2 6697@cindex @code{target("avx512vbmi2")} function attribute, x86 6698Enable/disable the generation of the AVX512VBMI2 instructions. 6699 6700@item avx512vl 6701@itemx no-avx512vl 6702@cindex @code{target("avx512vl")} function attribute, x86 6703Enable/disable the generation of the AVX512VL instructions. 6704 6705@item avx512vnni 6706@itemx no-avx512vnni 6707@cindex @code{target("avx512vnni")} function attribute, x86 6708Enable/disable the generation of the AVX512VNNI instructions. 6709 6710@item avx512vpopcntdq 6711@itemx no-avx512vpopcntdq 6712@cindex @code{target("avx512vpopcntdq")} function attribute, x86 6713Enable/disable the generation of the AVX512VPOPCNTDQ instructions. 6714 6715@item bmi 6716@itemx no-bmi 6717@cindex @code{target("bmi")} function attribute, x86 6718Enable/disable the generation of the BMI instructions. 6719 6720@item bmi2 6721@itemx no-bmi2 6722@cindex @code{target("bmi2")} function attribute, x86 6723Enable/disable the generation of the BMI2 instructions. 6724 6725@item cldemote 6726@itemx no-cldemote 6727@cindex @code{target("cldemote")} function attribute, x86 6728Enable/disable the generation of the CLDEMOTE instructions. 6729 6730@item clflushopt 6731@itemx no-clflushopt 6732@cindex @code{target("clflushopt")} function attribute, x86 6733Enable/disable the generation of the CLFLUSHOPT instructions. 6734 6735@item clwb 6736@itemx no-clwb 6737@cindex @code{target("clwb")} function attribute, x86 6738Enable/disable the generation of the CLWB instructions. 6739 6740@item clzero 6741@itemx no-clzero 6742@cindex @code{target("clzero")} function attribute, x86 6743Enable/disable the generation of the CLZERO instructions. 6744 6745@item crc32 6746@itemx no-crc32 6747@cindex @code{target("crc32")} function attribute, x86 6748Enable/disable the generation of the CRC32 instructions. 6749 6750@item cx16 6751@itemx no-cx16 6752@cindex @code{target("cx16")} function attribute, x86 6753Enable/disable the generation of the CMPXCHG16B instructions. 6754 6755@item default 6756@cindex @code{target("default")} function attribute, x86 6757@xref{Function Multiversioning}, where it is used to specify the 6758default function version. 6759 6760@item f16c 6761@itemx no-f16c 6762@cindex @code{target("f16c")} function attribute, x86 6763Enable/disable the generation of the F16C instructions. 6764 6765@item fma 6766@itemx no-fma 6767@cindex @code{target("fma")} function attribute, x86 6768Enable/disable the generation of the FMA instructions. 6769 6770@item fma4 6771@itemx no-fma4 6772@cindex @code{target("fma4")} function attribute, x86 6773Enable/disable the generation of the FMA4 instructions. 6774 6775@item fsgsbase 6776@itemx no-fsgsbase 6777@cindex @code{target("fsgsbase")} function attribute, x86 6778Enable/disable the generation of the FSGSBASE instructions. 6779 6780@item fxsr 6781@itemx no-fxsr 6782@cindex @code{target("fxsr")} function attribute, x86 6783Enable/disable the generation of the FXSR instructions. 6784 6785@item gfni 6786@itemx no-gfni 6787@cindex @code{target("gfni")} function attribute, x86 6788Enable/disable the generation of the GFNI instructions. 6789 6790@item hle 6791@itemx no-hle 6792@cindex @code{target("hle")} function attribute, x86 6793Enable/disable the generation of the HLE instruction prefixes. 6794 6795@item lwp 6796@itemx no-lwp 6797@cindex @code{target("lwp")} function attribute, x86 6798Enable/disable the generation of the LWP instructions. 6799 6800@item lzcnt 6801@itemx no-lzcnt 6802@cindex @code{target("lzcnt")} function attribute, x86 6803Enable/disable the generation of the LZCNT instructions. 6804 6805@item mmx 6806@itemx no-mmx 6807@cindex @code{target("mmx")} function attribute, x86 6808Enable/disable the generation of the MMX instructions. 6809 6810@item movbe 6811@itemx no-movbe 6812@cindex @code{target("movbe")} function attribute, x86 6813Enable/disable the generation of the MOVBE instructions. 6814 6815@item movdir64b 6816@itemx no-movdir64b 6817@cindex @code{target("movdir64b")} function attribute, x86 6818Enable/disable the generation of the MOVDIR64B instructions. 6819 6820@item movdiri 6821@itemx no-movdiri 6822@cindex @code{target("movdiri")} function attribute, x86 6823Enable/disable the generation of the MOVDIRI instructions. 6824 6825@item mwait 6826@itemx no-mwait 6827@cindex @code{target("mwait")} function attribute, x86 6828Enable/disable the generation of the MWAIT and MONITOR instructions. 6829 6830@item mwaitx 6831@itemx no-mwaitx 6832@cindex @code{target("mwaitx")} function attribute, x86 6833Enable/disable the generation of the MWAITX instructions. 6834 6835@item pclmul 6836@itemx no-pclmul 6837@cindex @code{target("pclmul")} function attribute, x86 6838Enable/disable the generation of the PCLMUL instructions. 6839 6840@item pconfig 6841@itemx no-pconfig 6842@cindex @code{target("pconfig")} function attribute, x86 6843Enable/disable the generation of the PCONFIG instructions. 6844 6845@item pku 6846@itemx no-pku 6847@cindex @code{target("pku")} function attribute, x86 6848Enable/disable the generation of the PKU instructions. 6849 6850@item popcnt 6851@itemx no-popcnt 6852@cindex @code{target("popcnt")} function attribute, x86 6853Enable/disable the generation of the POPCNT instruction. 6854 6855@item prefetchwt1 6856@itemx no-prefetchwt1 6857@cindex @code{target("prefetchwt1")} function attribute, x86 6858Enable/disable the generation of the PREFETCHWT1 instructions. 6859 6860@item prfchw 6861@itemx no-prfchw 6862@cindex @code{target("prfchw")} function attribute, x86 6863Enable/disable the generation of the PREFETCHW instruction. 6864 6865@item ptwrite 6866@itemx no-ptwrite 6867@cindex @code{target("ptwrite")} function attribute, x86 6868Enable/disable the generation of the PTWRITE instructions. 6869 6870@item rdpid 6871@itemx no-rdpid 6872@cindex @code{target("rdpid")} function attribute, x86 6873Enable/disable the generation of the RDPID instructions. 6874 6875@item rdrnd 6876@itemx no-rdrnd 6877@cindex @code{target("rdrnd")} function attribute, x86 6878Enable/disable the generation of the RDRND instructions. 6879 6880@item rdseed 6881@itemx no-rdseed 6882@cindex @code{target("rdseed")} function attribute, x86 6883Enable/disable the generation of the RDSEED instructions. 6884 6885@item rtm 6886@itemx no-rtm 6887@cindex @code{target("rtm")} function attribute, x86 6888Enable/disable the generation of the RTM instructions. 6889 6890@item sahf 6891@itemx no-sahf 6892@cindex @code{target("sahf")} function attribute, x86 6893Enable/disable the generation of the SAHF instructions. 6894 6895@item sgx 6896@itemx no-sgx 6897@cindex @code{target("sgx")} function attribute, x86 6898Enable/disable the generation of the SGX instructions. 6899 6900@item sha 6901@itemx no-sha 6902@cindex @code{target("sha")} function attribute, x86 6903Enable/disable the generation of the SHA instructions. 6904 6905@item shstk 6906@itemx no-shstk 6907@cindex @code{target("shstk")} function attribute, x86 6908Enable/disable the shadow stack built-in functions from CET. 6909 6910@item sse 6911@itemx no-sse 6912@cindex @code{target("sse")} function attribute, x86 6913Enable/disable the generation of the SSE instructions. 6914 6915@item sse2 6916@itemx no-sse2 6917@cindex @code{target("sse2")} function attribute, x86 6918Enable/disable the generation of the SSE2 instructions. 6919 6920@item sse3 6921@itemx no-sse3 6922@cindex @code{target("sse3")} function attribute, x86 6923Enable/disable the generation of the SSE3 instructions. 6924 6925@item sse4 6926@itemx no-sse4 6927@cindex @code{target("sse4")} function attribute, x86 6928Enable/disable the generation of the SSE4 instructions (both SSE4.1 6929and SSE4.2). 6930 6931@item sse4.1 6932@itemx no-sse4.1 6933@cindex @code{target("sse4.1")} function attribute, x86 6934Enable/disable the generation of the SSE4.1 instructions. 6935 6936@item sse4.2 6937@itemx no-sse4.2 6938@cindex @code{target("sse4.2")} function attribute, x86 6939Enable/disable the generation of the SSE4.2 instructions. 6940 6941@item sse4a 6942@itemx no-sse4a 6943@cindex @code{target("sse4a")} function attribute, x86 6944Enable/disable the generation of the SSE4A instructions. 6945 6946@item ssse3 6947@itemx no-ssse3 6948@cindex @code{target("ssse3")} function attribute, x86 6949Enable/disable the generation of the SSSE3 instructions. 6950 6951@item tbm 6952@itemx no-tbm 6953@cindex @code{target("tbm")} function attribute, x86 6954Enable/disable the generation of the TBM instructions. 6955 6956@item vaes 6957@itemx no-vaes 6958@cindex @code{target("vaes")} function attribute, x86 6959Enable/disable the generation of the VAES instructions. 6960 6961@item vpclmulqdq 6962@itemx no-vpclmulqdq 6963@cindex @code{target("vpclmulqdq")} function attribute, x86 6964Enable/disable the generation of the VPCLMULQDQ instructions. 6965 6966@item waitpkg 6967@itemx no-waitpkg 6968@cindex @code{target("waitpkg")} function attribute, x86 6969Enable/disable the generation of the WAITPKG instructions. 6970 6971@item wbnoinvd 6972@itemx no-wbnoinvd 6973@cindex @code{target("wbnoinvd")} function attribute, x86 6974Enable/disable the generation of the WBNOINVD instructions. 6975 6976@item xop 6977@itemx no-xop 6978@cindex @code{target("xop")} function attribute, x86 6979Enable/disable the generation of the XOP instructions. 6980 6981@item xsave 6982@itemx no-xsave 6983@cindex @code{target("xsave")} function attribute, x86 6984Enable/disable the generation of the XSAVE instructions. 6985 6986@item xsavec 6987@itemx no-xsavec 6988@cindex @code{target("xsavec")} function attribute, x86 6989Enable/disable the generation of the XSAVEC instructions. 6990 6991@item xsaveopt 6992@itemx no-xsaveopt 6993@cindex @code{target("xsaveopt")} function attribute, x86 6994Enable/disable the generation of the XSAVEOPT instructions. 6995 6996@item xsaves 6997@itemx no-xsaves 6998@cindex @code{target("xsaves")} function attribute, x86 6999Enable/disable the generation of the XSAVES instructions. 7000 7001@item amx-tile 7002@itemx no-amx-tile 7003@cindex @code{target("amx-tile")} function attribute, x86 7004Enable/disable the generation of the AMX-TILE instructions. 7005 7006@item amx-int8 7007@itemx no-amx-int8 7008@cindex @code{target("amx-int8")} function attribute, x86 7009Enable/disable the generation of the AMX-INT8 instructions. 7010 7011@item amx-bf16 7012@itemx no-amx-bf16 7013@cindex @code{target("amx-bf16")} function attribute, x86 7014Enable/disable the generation of the AMX-BF16 instructions. 7015 7016@item uintr 7017@itemx no-uintr 7018@cindex @code{target("uintr")} function attribute, x86 7019Enable/disable the generation of the UINTR instructions. 7020 7021@item hreset 7022@itemx no-hreset 7023@cindex @code{target("hreset")} function attribute, x86 7024Enable/disable the generation of the HRESET instruction. 7025 7026@item kl 7027@itemx no-kl 7028@cindex @code{target("kl")} function attribute, x86 7029Enable/disable the generation of the KEYLOCKER instructions. 7030 7031@item widekl 7032@itemx no-widekl 7033@cindex @code{target("widekl")} function attribute, x86 7034Enable/disable the generation of the WIDEKL instructions. 7035 7036@item avxvnni 7037@itemx no-avxvnni 7038@cindex @code{target("avxvnni")} function attribute, x86 7039Enable/disable the generation of the AVXVNNI instructions. 7040 7041@item cld 7042@itemx no-cld 7043@cindex @code{target("cld")} function attribute, x86 7044Enable/disable the generation of the CLD before string moves. 7045 7046@item fancy-math-387 7047@itemx no-fancy-math-387 7048@cindex @code{target("fancy-math-387")} function attribute, x86 7049Enable/disable the generation of the @code{sin}, @code{cos}, and 7050@code{sqrt} instructions on the 387 floating-point unit. 7051 7052@item ieee-fp 7053@itemx no-ieee-fp 7054@cindex @code{target("ieee-fp")} function attribute, x86 7055Enable/disable the generation of floating point that depends on IEEE arithmetic. 7056 7057@item inline-all-stringops 7058@itemx no-inline-all-stringops 7059@cindex @code{target("inline-all-stringops")} function attribute, x86 7060Enable/disable inlining of string operations. 7061 7062@item inline-stringops-dynamically 7063@itemx no-inline-stringops-dynamically 7064@cindex @code{target("inline-stringops-dynamically")} function attribute, x86 7065Enable/disable the generation of the inline code to do small string 7066operations and calling the library routines for large operations. 7067 7068@item align-stringops 7069@itemx no-align-stringops 7070@cindex @code{target("align-stringops")} function attribute, x86 7071Do/do not align destination of inlined string operations. 7072 7073@item recip 7074@itemx no-recip 7075@cindex @code{target("recip")} function attribute, x86 7076Enable/disable the generation of RCPSS, RCPPS, RSQRTSS and RSQRTPS 7077instructions followed an additional Newton-Raphson step instead of 7078doing a floating-point division. 7079 7080@item general-regs-only 7081@cindex @code{target("general-regs-only")} function attribute, x86 7082Generate code which uses only the general registers. 7083 7084@item arch=@var{ARCH} 7085@cindex @code{target("arch=@var{ARCH}")} function attribute, x86 7086Specify the architecture to generate code for in compiling the function. 7087 7088@item tune=@var{TUNE} 7089@cindex @code{target("tune=@var{TUNE}")} function attribute, x86 7090Specify the architecture to tune for in compiling the function. 7091 7092@item fpmath=@var{FPMATH} 7093@cindex @code{target("fpmath=@var{FPMATH}")} function attribute, x86 7094Specify which floating-point unit to use. You must specify the 7095@code{target("fpmath=sse,387")} option as 7096@code{target("fpmath=sse+387")} because the comma would separate 7097different options. 7098 7099@item prefer-vector-width=@var{OPT} 7100@cindex @code{prefer-vector-width} function attribute, x86 7101On x86 targets, the @code{prefer-vector-width} attribute informs the 7102compiler to use @var{OPT}-bit vector width in instructions 7103instead of the default on the selected platform. 7104 7105Valid @var{OPT} values are: 7106 7107@table @samp 7108@item none 7109No extra limitations applied to GCC other than defined by the selected platform. 7110 7111@item 128 7112Prefer 128-bit vector width for instructions. 7113 7114@item 256 7115Prefer 256-bit vector width for instructions. 7116 7117@item 512 7118Prefer 512-bit vector width for instructions. 7119@end table 7120 7121On the x86, the inliner does not inline a 7122function that has different target options than the caller, unless the 7123callee has a subset of the target options of the caller. For example 7124a function declared with @code{target("sse3")} can inline a function 7125with @code{target("sse2")}, since @code{-msse3} implies @code{-msse2}. 7126@end table 7127 7128@item indirect_branch("@var{choice}") 7129@cindex @code{indirect_branch} function attribute, x86 7130On x86 targets, the @code{indirect_branch} attribute causes the compiler 7131to convert indirect call and jump with @var{choice}. @samp{keep} 7132keeps indirect call and jump unmodified. @samp{thunk} converts indirect 7133call and jump to call and return thunk. @samp{thunk-inline} converts 7134indirect call and jump to inlined call and return thunk. 7135@samp{thunk-extern} converts indirect call and jump to external call 7136and return thunk provided in a separate object file. 7137 7138@item function_return("@var{choice}") 7139@cindex @code{function_return} function attribute, x86 7140On x86 targets, the @code{function_return} attribute causes the compiler 7141to convert function return with @var{choice}. @samp{keep} keeps function 7142return unmodified. @samp{thunk} converts function return to call and 7143return thunk. @samp{thunk-inline} converts function return to inlined 7144call and return thunk. @samp{thunk-extern} converts function return to 7145external call and return thunk provided in a separate object file. 7146 7147@item nocf_check 7148@cindex @code{nocf_check} function attribute 7149The @code{nocf_check} attribute on a function is used to inform the 7150compiler that the function's prologue should not be instrumented when 7151compiled with the @option{-fcf-protection=branch} option. The 7152compiler assumes that the function's address is a valid target for a 7153control-flow transfer. 7154 7155The @code{nocf_check} attribute on a type of pointer to function is 7156used to inform the compiler that a call through the pointer should 7157not be instrumented when compiled with the 7158@option{-fcf-protection=branch} option. The compiler assumes 7159that the function's address from the pointer is a valid target for 7160a control-flow transfer. A direct function call through a function 7161name is assumed to be a safe call thus direct calls are not 7162instrumented by the compiler. 7163 7164The @code{nocf_check} attribute is applied to an object's type. 7165In case of assignment of a function address or a function pointer to 7166another pointer, the attribute is not carried over from the right-hand 7167object's type; the type of left-hand object stays unchanged. The 7168compiler checks for @code{nocf_check} attribute mismatch and reports 7169a warning in case of mismatch. 7170 7171@smallexample 7172@{ 7173int foo (void) __attribute__(nocf_check); 7174void (*foo1)(void) __attribute__(nocf_check); 7175void (*foo2)(void); 7176 7177/* foo's address is assumed to be valid. */ 7178int 7179foo (void) 7180 7181 /* This call site is not checked for control-flow 7182 validity. */ 7183 (*foo1)(); 7184 7185 /* A warning is issued about attribute mismatch. */ 7186 foo1 = foo2; 7187 7188 /* This call site is still not checked. */ 7189 (*foo1)(); 7190 7191 /* This call site is checked. */ 7192 (*foo2)(); 7193 7194 /* A warning is issued about attribute mismatch. */ 7195 foo2 = foo1; 7196 7197 /* This call site is still checked. */ 7198 (*foo2)(); 7199 7200 return 0; 7201@} 7202@end smallexample 7203 7204@item cf_check 7205@cindex @code{cf_check} function attribute, x86 7206 7207The @code{cf_check} attribute on a function is used to inform the 7208compiler that ENDBR instruction should be placed at the function 7209entry when @option{-fcf-protection=branch} is enabled. 7210 7211@item indirect_return 7212@cindex @code{indirect_return} function attribute, x86 7213 7214The @code{indirect_return} attribute can be applied to a function, 7215as well as variable or type of function pointer to inform the 7216compiler that the function may return via indirect branch. 7217 7218@item fentry_name("@var{name}") 7219@cindex @code{fentry_name} function attribute, x86 7220On x86 targets, the @code{fentry_name} attribute sets the function to 7221call on function entry when function instrumentation is enabled 7222with @option{-pg -mfentry}. When @var{name} is nop then a 5 byte 7223nop sequence is generated. 7224 7225@item fentry_section("@var{name}") 7226@cindex @code{fentry_section} function attribute, x86 7227On x86 targets, the @code{fentry_section} attribute sets the name 7228of the section to record function entry instrumentation calls in when 7229enabled with @option{-pg -mrecord-mcount} 7230 7231@item nodirect_extern_access 7232@cindex @code{nodirect_extern_access} function attribute 7233@opindex mno-direct-extern-access 7234This attribute, attached to a global variable or function, is the 7235counterpart to option @option{-mno-direct-extern-access}. 7236 7237@end table 7238 7239@node Xstormy16 Function Attributes 7240@subsection Xstormy16 Function Attributes 7241 7242These function attributes are supported by the Xstormy16 back end: 7243 7244@table @code 7245@item interrupt 7246@cindex @code{interrupt} function attribute, Xstormy16 7247Use this attribute to indicate 7248that the specified function is an interrupt handler. The compiler generates 7249function entry and exit sequences suitable for use in an interrupt handler 7250when this attribute is present. 7251@end table 7252 7253@node Variable Attributes 7254@section Specifying Attributes of Variables 7255@cindex attribute of variables 7256@cindex variable attributes 7257 7258The keyword @code{__attribute__} allows you to specify special properties 7259of variables, function parameters, or structure, union, and, in C++, class 7260members. This @code{__attribute__} keyword is followed by an attribute 7261specification enclosed in double parentheses. Some attributes are currently 7262defined generically for variables. Other attributes are defined for 7263variables on particular target systems. Other attributes are available 7264for functions (@pxref{Function Attributes}), labels (@pxref{Label Attributes}), 7265enumerators (@pxref{Enumerator Attributes}), statements 7266(@pxref{Statement Attributes}), and for types (@pxref{Type Attributes}). 7267Other front ends might define more attributes 7268(@pxref{C++ Extensions,,Extensions to the C++ Language}). 7269 7270@xref{Attribute Syntax}, for details of the exact syntax for using 7271attributes. 7272 7273@menu 7274* Common Variable Attributes:: 7275* ARC Variable Attributes:: 7276* AVR Variable Attributes:: 7277* Blackfin Variable Attributes:: 7278* H8/300 Variable Attributes:: 7279* IA-64 Variable Attributes:: 7280* M32R/D Variable Attributes:: 7281* MeP Variable Attributes:: 7282* Microsoft Windows Variable Attributes:: 7283* MSP430 Variable Attributes:: 7284* Nvidia PTX Variable Attributes:: 7285* PowerPC Variable Attributes:: 7286* RL78 Variable Attributes:: 7287* V850 Variable Attributes:: 7288* x86 Variable Attributes:: 7289* Xstormy16 Variable Attributes:: 7290@end menu 7291 7292@node Common Variable Attributes 7293@subsection Common Variable Attributes 7294 7295The following attributes are supported on most targets. 7296 7297@table @code 7298 7299@item alias ("@var{target}") 7300@cindex @code{alias} variable attribute 7301The @code{alias} variable attribute causes the declaration to be emitted 7302as an alias for another symbol known as an @dfn{alias target}. Except 7303for top-level qualifiers the alias target must have the same type as 7304the alias. For instance, the following 7305 7306@smallexample 7307int var_target; 7308extern int __attribute__ ((alias ("var_target"))) var_alias; 7309@end smallexample 7310 7311@noindent 7312defines @code{var_alias} to be an alias for the @code{var_target} variable. 7313 7314It is an error if the alias target is not defined in the same translation 7315unit as the alias. 7316 7317Note that in the absence of the attribute GCC assumes that distinct 7318declarations with external linkage denote distinct objects. Using both 7319the alias and the alias target to access the same object is undefined 7320in a translation unit without a declaration of the alias with the attribute. 7321 7322This attribute requires assembler and object file support, and may not be 7323available on all targets. 7324 7325@cindex @code{aligned} variable attribute 7326@item aligned 7327@itemx aligned (@var{alignment}) 7328The @code{aligned} attribute specifies a minimum alignment for the variable 7329or structure field, measured in bytes. When specified, @var{alignment} must 7330be an integer constant power of 2. Specifying no @var{alignment} argument 7331implies the maximum alignment for the target, which is often, but by no 7332means always, 8 or 16 bytes. 7333 7334For example, the declaration: 7335 7336@smallexample 7337int x __attribute__ ((aligned (16))) = 0; 7338@end smallexample 7339 7340@noindent 7341causes the compiler to allocate the global variable @code{x} on a 734216-byte boundary. On a 68040, this could be used in conjunction with 7343an @code{asm} expression to access the @code{move16} instruction which 7344requires 16-byte aligned operands. 7345 7346You can also specify the alignment of structure fields. For example, to 7347create a double-word aligned @code{int} pair, you could write: 7348 7349@smallexample 7350struct foo @{ int x[2] __attribute__ ((aligned (8))); @}; 7351@end smallexample 7352 7353@noindent 7354This is an alternative to creating a union with a @code{double} member, 7355which forces the union to be double-word aligned. 7356 7357As in the preceding examples, you can explicitly specify the alignment 7358(in bytes) that you wish the compiler to use for a given variable or 7359structure field. Alternatively, you can leave out the alignment factor 7360and just ask the compiler to align a variable or field to the 7361default alignment for the target architecture you are compiling for. 7362The default alignment is sufficient for all scalar types, but may not be 7363enough for all vector types on a target that supports vector operations. 7364The default alignment is fixed for a particular target ABI. 7365 7366GCC also provides a target specific macro @code{__BIGGEST_ALIGNMENT__}, 7367which is the largest alignment ever used for any data type on the 7368target machine you are compiling for. For example, you could write: 7369 7370@smallexample 7371short array[3] __attribute__ ((aligned (__BIGGEST_ALIGNMENT__))); 7372@end smallexample 7373 7374The compiler automatically sets the alignment for the declared 7375variable or field to @code{__BIGGEST_ALIGNMENT__}. Doing this can 7376often make copy operations more efficient, because the compiler can 7377use whatever instructions copy the biggest chunks of memory when 7378performing copies to or from the variables or fields that you have 7379aligned this way. Note that the value of @code{__BIGGEST_ALIGNMENT__} 7380may change depending on command-line options. 7381 7382When used on a struct, or struct member, the @code{aligned} attribute can 7383only increase the alignment; in order to decrease it, the @code{packed} 7384attribute must be specified as well. When used as part of a typedef, the 7385@code{aligned} attribute can both increase and decrease alignment, and 7386specifying the @code{packed} attribute generates a warning. 7387 7388Note that the effectiveness of @code{aligned} attributes for static 7389variables may be limited by inherent limitations in the system linker 7390and/or object file format. On some systems, the linker is 7391only able to arrange for variables to be aligned up to a certain maximum 7392alignment. (For some linkers, the maximum supported alignment may 7393be very very small.) If your linker is only able to align variables 7394up to a maximum of 8-byte alignment, then specifying @code{aligned(16)} 7395in an @code{__attribute__} still only provides you with 8-byte 7396alignment. See your linker documentation for further information. 7397 7398Stack variables are not affected by linker restrictions; GCC can properly 7399align them on any target. 7400 7401The @code{aligned} attribute can also be used for functions 7402(@pxref{Common Function Attributes}.) 7403 7404@cindex @code{warn_if_not_aligned} variable attribute 7405@item warn_if_not_aligned (@var{alignment}) 7406This attribute specifies a threshold for the structure field, measured 7407in bytes. If the structure field is aligned below the threshold, a 7408warning will be issued. For example, the declaration: 7409 7410@smallexample 7411struct foo 7412@{ 7413 int i1; 7414 int i2; 7415 unsigned long long x __attribute__ ((warn_if_not_aligned (16))); 7416@}; 7417@end smallexample 7418 7419@noindent 7420causes the compiler to issue an warning on @code{struct foo}, like 7421@samp{warning: alignment 8 of 'struct foo' is less than 16}. 7422The compiler also issues a warning, like @samp{warning: 'x' offset 74238 in 'struct foo' isn't aligned to 16}, when the structure field has 7424the misaligned offset: 7425 7426@smallexample 7427struct __attribute__ ((aligned (16))) foo 7428@{ 7429 int i1; 7430 int i2; 7431 unsigned long long x __attribute__ ((warn_if_not_aligned (16))); 7432@}; 7433@end smallexample 7434 7435This warning can be disabled by @option{-Wno-if-not-aligned}. 7436The @code{warn_if_not_aligned} attribute can also be used for types 7437(@pxref{Common Type Attributes}.) 7438 7439@item alloc_size (@var{position}) 7440@itemx alloc_size (@var{position-1}, @var{position-2}) 7441@cindex @code{alloc_size} variable attribute 7442The @code{alloc_size} variable attribute may be applied to the declaration 7443of a pointer to a function that returns a pointer and takes at least one 7444argument of an integer type. It indicates that the returned pointer points 7445to an object whose size is given by the function argument at @var{position}, 7446or by the product of the arguments at @var{position-1} and @var{position-2}. 7447Meaningful sizes are positive values less than @code{PTRDIFF_MAX}. Other 7448sizes are diagnosed when detected. GCC uses this information to improve 7449the results of @code{__builtin_object_size}. 7450 7451For instance, the following declarations 7452 7453@smallexample 7454typedef __attribute__ ((alloc_size (1, 2))) void* 7455 (*calloc_ptr) (size_t, size_t); 7456typedef __attribute__ ((alloc_size (1))) void* 7457 (*malloc_ptr) (size_t); 7458@end smallexample 7459 7460@noindent 7461specify that @code{calloc_ptr} is a pointer of a function that, like 7462the standard C function @code{calloc}, returns an object whose size 7463is given by the product of arguments 1 and 2, and similarly, that 7464@code{malloc_ptr}, like the standard C function @code{malloc}, 7465returns an object whose size is given by argument 1 to the function. 7466 7467@item cleanup (@var{cleanup_function}) 7468@cindex @code{cleanup} variable attribute 7469The @code{cleanup} attribute runs a function when the variable goes 7470out of scope. This attribute can only be applied to auto function 7471scope variables; it may not be applied to parameters or variables 7472with static storage duration. The function must take one parameter, 7473a pointer to a type compatible with the variable. The return value 7474of the function (if any) is ignored. 7475 7476If @option{-fexceptions} is enabled, then @var{cleanup_function} 7477is run during the stack unwinding that happens during the 7478processing of the exception. Note that the @code{cleanup} attribute 7479does not allow the exception to be caught, only to perform an action. 7480It is undefined what happens if @var{cleanup_function} does not 7481return normally. 7482 7483@item common 7484@itemx nocommon 7485@cindex @code{common} variable attribute 7486@cindex @code{nocommon} variable attribute 7487@opindex fcommon 7488@opindex fno-common 7489The @code{common} attribute requests GCC to place a variable in 7490``common'' storage. The @code{nocommon} attribute requests the 7491opposite---to allocate space for it directly. 7492 7493These attributes override the default chosen by the 7494@option{-fno-common} and @option{-fcommon} flags respectively. 7495 7496@item copy 7497@itemx copy (@var{variable}) 7498@cindex @code{copy} variable attribute 7499The @code{copy} attribute applies the set of attributes with which 7500@var{variable} has been declared to the declaration of the variable 7501to which the attribute is applied. The attribute is designed for 7502libraries that define aliases that are expected to specify the same 7503set of attributes as the aliased symbols. The @code{copy} attribute 7504can be used with variables, functions or types. However, the kind 7505of symbol to which the attribute is applied (either varible or 7506function) must match the kind of symbol to which the argument refers. 7507The @code{copy} attribute copies only syntactic and semantic attributes 7508but not attributes that affect a symbol's linkage or visibility such as 7509@code{alias}, @code{visibility}, or @code{weak}. The @code{deprecated} 7510attribute is also not copied. @xref{Common Function Attributes}. 7511@xref{Common Type Attributes}. 7512 7513@item deprecated 7514@itemx deprecated (@var{msg}) 7515@cindex @code{deprecated} variable attribute 7516The @code{deprecated} attribute results in a warning if the variable 7517is used anywhere in the source file. This is useful when identifying 7518variables that are expected to be removed in a future version of a 7519program. The warning also includes the location of the declaration 7520of the deprecated variable, to enable users to easily find further 7521information about why the variable is deprecated, or what they should 7522do instead. Note that the warning only occurs for uses: 7523 7524@smallexample 7525extern int old_var __attribute__ ((deprecated)); 7526extern int old_var; 7527int new_fn () @{ return old_var; @} 7528@end smallexample 7529 7530@noindent 7531results in a warning on line 3 but not line 2. The optional @var{msg} 7532argument, which must be a string, is printed in the warning if 7533present. 7534 7535The @code{deprecated} attribute can also be used for functions and 7536types (@pxref{Common Function Attributes}, 7537@pxref{Common Type Attributes}). 7538 7539The message attached to the attribute is affected by the setting of 7540the @option{-fmessage-length} option. 7541 7542@item unavailable 7543@itemx unavailable (@var{msg}) 7544@cindex @code{unavailable} variable attribute 7545The @code{unavailable} attribute indicates that the variable so marked 7546is not available, if it is used anywhere in the source file. It behaves 7547in the same manner as the @code{deprecated} attribute except that the 7548compiler will emit an error rather than a warning. 7549 7550It is expected that items marked as @code{deprecated} will eventually be 7551withdrawn from interfaces, and then become unavailable. This attribute 7552allows for marking them appropriately. 7553 7554The @code{unavailable} attribute can also be used for functions and 7555types (@pxref{Common Function Attributes}, 7556@pxref{Common Type Attributes}). 7557 7558@item mode (@var{mode}) 7559@cindex @code{mode} variable attribute 7560This attribute specifies the data type for the declaration---whichever 7561type corresponds to the mode @var{mode}. This in effect lets you 7562request an integer or floating-point type according to its width. 7563 7564@xref{Machine Modes,,, gccint, GNU Compiler Collection (GCC) Internals}, 7565for a list of the possible keywords for @var{mode}. 7566You may also specify a mode of @code{byte} or @code{__byte__} to 7567indicate the mode corresponding to a one-byte integer, @code{word} or 7568@code{__word__} for the mode of a one-word integer, and @code{pointer} 7569or @code{__pointer__} for the mode used to represent pointers. 7570 7571@item nonstring 7572@cindex @code{nonstring} variable attribute 7573The @code{nonstring} variable attribute specifies that an object or member 7574declaration with type array of @code{char}, @code{signed char}, or 7575@code{unsigned char}, or pointer to such a type is intended to store 7576character arrays that do not necessarily contain a terminating @code{NUL}. 7577This is useful in detecting uses of such arrays or pointers with functions 7578that expect @code{NUL}-terminated strings, and to avoid warnings when such 7579an array or pointer is used as an argument to a bounded string manipulation 7580function such as @code{strncpy}. For example, without the attribute, GCC 7581will issue a warning for the @code{strncpy} call below because it may 7582truncate the copy without appending the terminating @code{NUL} character. 7583Using the attribute makes it possible to suppress the warning. However, 7584when the array is declared with the attribute the call to @code{strlen} is 7585diagnosed because when the array doesn't contain a @code{NUL}-terminated 7586string the call is undefined. To copy, compare, of search non-string 7587character arrays use the @code{memcpy}, @code{memcmp}, @code{memchr}, 7588and other functions that operate on arrays of bytes. In addition, 7589calling @code{strnlen} and @code{strndup} with such arrays is safe 7590provided a suitable bound is specified, and not diagnosed. 7591 7592@smallexample 7593struct Data 7594@{ 7595 char name [32] __attribute__ ((nonstring)); 7596@}; 7597 7598int f (struct Data *pd, const char *s) 7599@{ 7600 strncpy (pd->name, s, sizeof pd->name); 7601 @dots{} 7602 return strlen (pd->name); // unsafe, gets a warning 7603@} 7604@end smallexample 7605 7606@item packed 7607@cindex @code{packed} variable attribute 7608The @code{packed} attribute specifies that a structure member should have 7609the smallest possible alignment---one bit for a bit-field and one byte 7610otherwise, unless a larger value is specified with the @code{aligned} 7611attribute. The attribute does not apply to non-member objects. 7612 7613For example in the structure below, the member array @code{x} is packed 7614so that it immediately follows @code{a} with no intervening padding: 7615 7616@smallexample 7617struct foo 7618@{ 7619 char a; 7620 int x[2] __attribute__ ((packed)); 7621@}; 7622@end smallexample 7623 7624@emph{Note:} The 4.1, 4.2 and 4.3 series of GCC ignore the 7625@code{packed} attribute on bit-fields of type @code{char}. This has 7626been fixed in GCC 4.4 but the change can lead to differences in the 7627structure layout. See the documentation of 7628@option{-Wpacked-bitfield-compat} for more information. 7629 7630@item section ("@var{section-name}") 7631@cindex @code{section} variable attribute 7632Normally, the compiler places the objects it generates in sections like 7633@code{data} and @code{bss}. Sometimes, however, you need additional sections, 7634or you need certain particular variables to appear in special sections, 7635for example to map to special hardware. The @code{section} 7636attribute specifies that a variable (or function) lives in a particular 7637section. For example, this small program uses several specific section names: 7638 7639@smallexample 7640struct duart a __attribute__ ((section ("DUART_A"))) = @{ 0 @}; 7641struct duart b __attribute__ ((section ("DUART_B"))) = @{ 0 @}; 7642char stack[10000] __attribute__ ((section ("STACK"))) = @{ 0 @}; 7643int init_data __attribute__ ((section ("INITDATA"))); 7644 7645main() 7646@{ 7647 /* @r{Initialize stack pointer} */ 7648 init_sp (stack + sizeof (stack)); 7649 7650 /* @r{Initialize initialized data} */ 7651 memcpy (&init_data, &data, &edata - &data); 7652 7653 /* @r{Turn on the serial ports} */ 7654 init_duart (&a); 7655 init_duart (&b); 7656@} 7657@end smallexample 7658 7659@noindent 7660Use the @code{section} attribute with 7661@emph{global} variables and not @emph{local} variables, 7662as shown in the example. 7663 7664You may use the @code{section} attribute with initialized or 7665uninitialized global variables but the linker requires 7666each object be defined once, with the exception that uninitialized 7667variables tentatively go in the @code{common} (or @code{bss}) section 7668and can be multiply ``defined''. Using the @code{section} attribute 7669changes what section the variable goes into and may cause the 7670linker to issue an error if an uninitialized variable has multiple 7671definitions. You can force a variable to be initialized with the 7672@option{-fno-common} flag or the @code{nocommon} attribute. 7673 7674Some file formats do not support arbitrary sections so the @code{section} 7675attribute is not available on all platforms. 7676If you need to map the entire contents of a module to a particular 7677section, consider using the facilities of the linker instead. 7678 7679@item tls_model ("@var{tls_model}") 7680@cindex @code{tls_model} variable attribute 7681The @code{tls_model} attribute sets thread-local storage model 7682(@pxref{Thread-Local}) of a particular @code{__thread} variable, 7683overriding @option{-ftls-model=} command-line switch on a per-variable 7684basis. 7685The @var{tls_model} argument should be one of @code{global-dynamic}, 7686@code{local-dynamic}, @code{initial-exec} or @code{local-exec}. 7687 7688Not all targets support this attribute. 7689 7690@item unused 7691@cindex @code{unused} variable attribute 7692This attribute, attached to a variable or structure field, means that 7693the variable or field is meant to be possibly unused. GCC does not 7694produce a warning for this variable or field. 7695 7696@item used 7697@cindex @code{used} variable attribute 7698This attribute, attached to a variable with static storage, means that 7699the variable must be emitted even if it appears that the variable is not 7700referenced. 7701 7702When applied to a static data member of a C++ class template, the 7703attribute also means that the member is instantiated if the 7704class itself is instantiated. 7705 7706@item retain 7707@cindex @code{retain} variable attribute 7708For ELF targets that support the GNU or FreeBSD OSABIs, this attribute 7709will save the variable from linker garbage collection. To support 7710this behavior, variables that have not been placed in specific sections 7711(e.g. by the @code{section} attribute, or the @code{-fdata-sections} option), 7712will be placed in new, unique sections. 7713 7714This additional functionality requires Binutils version 2.36 or later. 7715 7716@item uninitialized 7717@cindex @code{uninitialized} variable attribute 7718This attribute, attached to a variable with automatic storage, means that 7719the variable should not be automatically initialized by the compiler when 7720the option @code{-ftrivial-auto-var-init} presents. 7721 7722With the option @code{-ftrivial-auto-var-init}, all the automatic variables 7723that do not have explicit initializers will be initialized by the compiler. 7724These additional compiler initializations might incur run-time overhead, 7725sometimes dramatically. This attribute can be used to mark some variables 7726to be excluded from such automatical initialization in order to reduce runtime 7727overhead. 7728 7729This attribute has no effect when the option @code{-ftrivial-auto-var-init} 7730does not present. 7731 7732@item vector_size (@var{bytes}) 7733@cindex @code{vector_size} variable attribute 7734This attribute specifies the vector size for the type of the declared 7735variable, measured in bytes. The type to which it applies is known as 7736the @dfn{base type}. The @var{bytes} argument must be a positive 7737power-of-two multiple of the base type size. For example, the declaration: 7738 7739@smallexample 7740int foo __attribute__ ((vector_size (16))); 7741@end smallexample 7742 7743@noindent 7744causes the compiler to set the mode for @code{foo}, to be 16 bytes, 7745divided into @code{int} sized units. Assuming a 32-bit @code{int}, 7746@code{foo}'s type is a vector of four units of four bytes each, and 7747the corresponding mode of @code{foo} is @code{V4SI}. 7748@xref{Vector Extensions}, for details of manipulating vector variables. 7749 7750This attribute is only applicable to integral and floating scalars, 7751although arrays, pointers, and function return values are allowed in 7752conjunction with this construct. 7753 7754Aggregates with this attribute are invalid, even if they are of the same 7755size as a corresponding scalar. For example, the declaration: 7756 7757@smallexample 7758struct S @{ int a; @}; 7759struct S __attribute__ ((vector_size (16))) foo; 7760@end smallexample 7761 7762@noindent 7763is invalid even if the size of the structure is the same as the size of 7764the @code{int}. 7765 7766@item visibility ("@var{visibility_type}") 7767@cindex @code{visibility} variable attribute 7768This attribute affects the linkage of the declaration to which it is attached. 7769The @code{visibility} attribute is described in 7770@ref{Common Function Attributes}. 7771 7772@item weak 7773@cindex @code{weak} variable attribute 7774The @code{weak} attribute is described in 7775@ref{Common Function Attributes}. 7776 7777@item noinit 7778@cindex @code{noinit} variable attribute 7779Any data with the @code{noinit} attribute will not be initialized by 7780the C runtime startup code, or the program loader. Not initializing 7781data in this way can reduce program startup times. 7782 7783This attribute is specific to ELF targets and relies on the linker 7784script to place sections with the @code{.noinit} prefix in the right 7785location. 7786 7787@item persistent 7788@cindex @code{persistent} variable attribute 7789Any data with the @code{persistent} attribute will not be initialized by 7790the C runtime startup code, but will be initialized by the program 7791loader. This enables the value of the variable to @samp{persist} 7792between processor resets. 7793 7794This attribute is specific to ELF targets and relies on the linker 7795script to place the sections with the @code{.persistent} prefix in the 7796right location. Specifically, some type of non-volatile, writeable 7797memory is required. 7798 7799@item objc_nullability (@var{nullability kind}) @r{(Objective-C and Objective-C++ only)} 7800@cindex @code{objc_nullability} variable attribute 7801This attribute applies to pointer variables only. It allows marking the 7802pointer with one of four possible values describing the conditions under 7803which the pointer might have a @code{nil} value. In most cases, the 7804attribute is intended to be an internal representation for property and 7805method nullability (specified by language keywords); it is not recommended 7806to use it directly. 7807 7808When @var{nullability kind} is @code{"unspecified"} or @code{0}, nothing is 7809known about the conditions in which the pointer might be @code{nil}. Making 7810this state specific serves to avoid false positives in diagnostics. 7811 7812When @var{nullability kind} is @code{"nonnull"} or @code{1}, the pointer has 7813no meaning if it is @code{nil} and thus the compiler is free to emit 7814diagnostics if it can be determined that the value will be @code{nil}. 7815 7816When @var{nullability kind} is @code{"nullable"} or @code{2}, the pointer might 7817be @code{nil} and carry meaning as such. 7818 7819When @var{nullability kind} is @code{"resettable"} or @code{3} (used only in 7820the context of property attribute lists) this describes the case in which a 7821property setter may take the value @code{nil} (which perhaps causes the 7822property to be reset in some manner to a default) but for which the property 7823getter will never validly return @code{nil}. 7824 7825@end table 7826 7827@node ARC Variable Attributes 7828@subsection ARC Variable Attributes 7829 7830@table @code 7831@item aux 7832@cindex @code{aux} variable attribute, ARC 7833The @code{aux} attribute is used to directly access the ARC's 7834auxiliary register space from C. The auxilirary register number is 7835given via attribute argument. 7836 7837@end table 7838 7839@node AVR Variable Attributes 7840@subsection AVR Variable Attributes 7841 7842@table @code 7843@item progmem 7844@cindex @code{progmem} variable attribute, AVR 7845The @code{progmem} attribute is used on the AVR to place read-only 7846data in the non-volatile program memory (flash). The @code{progmem} 7847attribute accomplishes this by putting respective variables into a 7848section whose name starts with @code{.progmem}. 7849 7850This attribute works similar to the @code{section} attribute 7851but adds additional checking. 7852 7853@table @asis 7854@item @bullet{}@tie{} Ordinary AVR cores with 32 general purpose registers: 7855@code{progmem} affects the location 7856of the data but not how this data is accessed. 7857In order to read data located with the @code{progmem} attribute 7858(inline) assembler must be used. 7859@smallexample 7860/* Use custom macros from @w{@uref{http://nongnu.org/avr-libc/user-manual/,AVR-LibC}} */ 7861#include <avr/pgmspace.h> 7862 7863/* Locate var in flash memory */ 7864const int var[2] PROGMEM = @{ 1, 2 @}; 7865 7866int read_var (int i) 7867@{ 7868 /* Access var[] by accessor macro from avr/pgmspace.h */ 7869 return (int) pgm_read_word (& var[i]); 7870@} 7871@end smallexample 7872 7873AVR is a Harvard architecture processor and data and read-only data 7874normally resides in the data memory (RAM). 7875 7876See also the @ref{AVR Named Address Spaces} section for 7877an alternate way to locate and access data in flash memory. 7878 7879@item @bullet{}@tie{} AVR cores with flash memory visible in the RAM address range: 7880On such devices, there is no need for attribute @code{progmem} or 7881@ref{AVR Named Address Spaces,,@code{__flash}} qualifier at all. 7882Just use standard C / C++. The compiler will generate @code{LD*} 7883instructions. As flash memory is visible in the RAM address range, 7884and the default linker script does @emph{not} locate @code{.rodata} in 7885RAM, no special features are needed in order not to waste RAM for 7886read-only data or to read from flash. You might even get slightly better 7887performance by 7888avoiding @code{progmem} and @code{__flash}. This applies to devices from 7889families @code{avrtiny} and @code{avrxmega3}, see @ref{AVR Options} for 7890an overview. 7891 7892@item @bullet{}@tie{}Reduced AVR Tiny cores like ATtiny40: 7893The compiler adds @code{0x4000} 7894to the addresses of objects and declarations in @code{progmem} and locates 7895the objects in flash memory, namely in section @code{.progmem.data}. 7896The offset is needed because the flash memory is visible in the RAM 7897address space starting at address @code{0x4000}. 7898 7899Data in @code{progmem} can be accessed by means of ordinary C@tie{}code, 7900no special functions or macros are needed. 7901 7902@smallexample 7903/* var is located in flash memory */ 7904extern const int var[2] __attribute__((progmem)); 7905 7906int read_var (int i) 7907@{ 7908 return var[i]; 7909@} 7910@end smallexample 7911 7912Please notice that on these devices, there is no need for @code{progmem} 7913at all. 7914 7915@end table 7916 7917@item io 7918@itemx io (@var{addr}) 7919@cindex @code{io} variable attribute, AVR 7920Variables with the @code{io} attribute are used to address 7921memory-mapped peripherals in the io address range. 7922If an address is specified, the variable 7923is assigned that address, and the value is interpreted as an 7924address in the data address space. 7925Example: 7926 7927@smallexample 7928volatile int porta __attribute__((io (0x22))); 7929@end smallexample 7930 7931The address specified in the address in the data address range. 7932 7933Otherwise, the variable it is not assigned an address, but the 7934compiler will still use in/out instructions where applicable, 7935assuming some other module assigns an address in the io address range. 7936Example: 7937 7938@smallexample 7939extern volatile int porta __attribute__((io)); 7940@end smallexample 7941 7942@item io_low 7943@itemx io_low (@var{addr}) 7944@cindex @code{io_low} variable attribute, AVR 7945This is like the @code{io} attribute, but additionally it informs the 7946compiler that the object lies in the lower half of the I/O area, 7947allowing the use of @code{cbi}, @code{sbi}, @code{sbic} and @code{sbis} 7948instructions. 7949 7950@item address 7951@itemx address (@var{addr}) 7952@cindex @code{address} variable attribute, AVR 7953Variables with the @code{address} attribute are used to address 7954memory-mapped peripherals that may lie outside the io address range. 7955 7956@smallexample 7957volatile int porta __attribute__((address (0x600))); 7958@end smallexample 7959 7960@item absdata 7961@cindex @code{absdata} variable attribute, AVR 7962Variables in static storage and with the @code{absdata} attribute can 7963be accessed by the @code{LDS} and @code{STS} instructions which take 7964absolute addresses. 7965 7966@itemize @bullet 7967@item 7968This attribute is only supported for the reduced AVR Tiny core 7969like ATtiny40. 7970 7971@item 7972You must make sure that respective data is located in the 7973address range @code{0x40}@dots{}@code{0xbf} accessible by 7974@code{LDS} and @code{STS}. One way to achieve this as an 7975appropriate linker description file. 7976 7977@item 7978If the location does not fit the address range of @code{LDS} 7979and @code{STS}, there is currently (Binutils 2.26) just an unspecific 7980warning like 7981@quotation 7982@code{module.cc:(.text+0x1c): warning: internal error: out of range error} 7983@end quotation 7984 7985@end itemize 7986 7987See also the @option{-mabsdata} @ref{AVR Options,command-line option}. 7988 7989@end table 7990 7991@node Blackfin Variable Attributes 7992@subsection Blackfin Variable Attributes 7993 7994Three attributes are currently defined for the Blackfin. 7995 7996@table @code 7997@item l1_data 7998@itemx l1_data_A 7999@itemx l1_data_B 8000@cindex @code{l1_data} variable attribute, Blackfin 8001@cindex @code{l1_data_A} variable attribute, Blackfin 8002@cindex @code{l1_data_B} variable attribute, Blackfin 8003Use these attributes on the Blackfin to place the variable into L1 Data SRAM. 8004Variables with @code{l1_data} attribute are put into the specific section 8005named @code{.l1.data}. Those with @code{l1_data_A} attribute are put into 8006the specific section named @code{.l1.data.A}. Those with @code{l1_data_B} 8007attribute are put into the specific section named @code{.l1.data.B}. 8008 8009@item l2 8010@cindex @code{l2} variable attribute, Blackfin 8011Use this attribute on the Blackfin to place the variable into L2 SRAM. 8012Variables with @code{l2} attribute are put into the specific section 8013named @code{.l2.data}. 8014@end table 8015 8016@node H8/300 Variable Attributes 8017@subsection H8/300 Variable Attributes 8018 8019These variable attributes are available for H8/300 targets: 8020 8021@table @code 8022@item eightbit_data 8023@cindex @code{eightbit_data} variable attribute, H8/300 8024@cindex eight-bit data on the H8/300, H8/300H, and H8S 8025Use this attribute on the H8/300, H8/300H, and H8S to indicate that the specified 8026variable should be placed into the eight-bit data section. 8027The compiler generates more efficient code for certain operations 8028on data in the eight-bit data area. Note the eight-bit data area is limited to 8029256 bytes of data. 8030 8031You must use GAS and GLD from GNU binutils version 2.7 or later for 8032this attribute to work correctly. 8033 8034@item tiny_data 8035@cindex @code{tiny_data} variable attribute, H8/300 8036@cindex tiny data section on the H8/300H and H8S 8037Use this attribute on the H8/300H and H8S to indicate that the specified 8038variable should be placed into the tiny data section. 8039The compiler generates more efficient code for loads and stores 8040on data in the tiny data section. Note the tiny data area is limited to 8041slightly under 32KB of data. 8042 8043@end table 8044 8045@node IA-64 Variable Attributes 8046@subsection IA-64 Variable Attributes 8047 8048The IA-64 back end supports the following variable attribute: 8049 8050@table @code 8051@item model (@var{model-name}) 8052@cindex @code{model} variable attribute, IA-64 8053 8054On IA-64, use this attribute to set the addressability of an object. 8055At present, the only supported identifier for @var{model-name} is 8056@code{small}, indicating addressability via ``small'' (22-bit) 8057addresses (so that their addresses can be loaded with the @code{addl} 8058instruction). Caveat: such addressing is by definition not position 8059independent and hence this attribute must not be used for objects 8060defined by shared libraries. 8061 8062@end table 8063 8064@node M32R/D Variable Attributes 8065@subsection M32R/D Variable Attributes 8066 8067One attribute is currently defined for the M32R/D@. 8068 8069@table @code 8070@item model (@var{model-name}) 8071@cindex @code{model-name} variable attribute, M32R/D 8072@cindex variable addressability on the M32R/D 8073Use this attribute on the M32R/D to set the addressability of an object. 8074The identifier @var{model-name} is one of @code{small}, @code{medium}, 8075or @code{large}, representing each of the code models. 8076 8077Small model objects live in the lower 16MB of memory (so that their 8078addresses can be loaded with the @code{ld24} instruction). 8079 8080Medium and large model objects may live anywhere in the 32-bit address space 8081(the compiler generates @code{seth/add3} instructions to load their 8082addresses). 8083@end table 8084 8085@node MeP Variable Attributes 8086@subsection MeP Variable Attributes 8087 8088The MeP target has a number of addressing modes and busses. The 8089@code{near} space spans the standard memory space's first 16 megabytes 8090(24 bits). The @code{far} space spans the entire 32-bit memory space. 8091The @code{based} space is a 128-byte region in the memory space that 8092is addressed relative to the @code{$tp} register. The @code{tiny} 8093space is a 65536-byte region relative to the @code{$gp} register. In 8094addition to these memory regions, the MeP target has a separate 16-bit 8095control bus which is specified with @code{cb} attributes. 8096 8097@table @code 8098 8099@item based 8100@cindex @code{based} variable attribute, MeP 8101Any variable with the @code{based} attribute is assigned to the 8102@code{.based} section, and is accessed with relative to the 8103@code{$tp} register. 8104 8105@item tiny 8106@cindex @code{tiny} variable attribute, MeP 8107Likewise, the @code{tiny} attribute assigned variables to the 8108@code{.tiny} section, relative to the @code{$gp} register. 8109 8110@item near 8111@cindex @code{near} variable attribute, MeP 8112Variables with the @code{near} attribute are assumed to have addresses 8113that fit in a 24-bit addressing mode. This is the default for large 8114variables (@code{-mtiny=4} is the default) but this attribute can 8115override @code{-mtiny=} for small variables, or override @code{-ml}. 8116 8117@item far 8118@cindex @code{far} variable attribute, MeP 8119Variables with the @code{far} attribute are addressed using a full 812032-bit address. Since this covers the entire memory space, this 8121allows modules to make no assumptions about where variables might be 8122stored. 8123 8124@item io 8125@cindex @code{io} variable attribute, MeP 8126@itemx io (@var{addr}) 8127Variables with the @code{io} attribute are used to address 8128memory-mapped peripherals. If an address is specified, the variable 8129is assigned that address, else it is not assigned an address (it is 8130assumed some other module assigns an address). Example: 8131 8132@smallexample 8133int timer_count __attribute__((io(0x123))); 8134@end smallexample 8135 8136@item cb 8137@itemx cb (@var{addr}) 8138@cindex @code{cb} variable attribute, MeP 8139Variables with the @code{cb} attribute are used to access the control 8140bus, using special instructions. @code{addr} indicates the control bus 8141address. Example: 8142 8143@smallexample 8144int cpu_clock __attribute__((cb(0x123))); 8145@end smallexample 8146 8147@end table 8148 8149@node Microsoft Windows Variable Attributes 8150@subsection Microsoft Windows Variable Attributes 8151 8152You can use these attributes on Microsoft Windows targets. 8153@ref{x86 Variable Attributes} for additional Windows compatibility 8154attributes available on all x86 targets. 8155 8156@table @code 8157@item dllimport 8158@itemx dllexport 8159@cindex @code{dllimport} variable attribute 8160@cindex @code{dllexport} variable attribute 8161The @code{dllimport} and @code{dllexport} attributes are described in 8162@ref{Microsoft Windows Function Attributes}. 8163 8164@item selectany 8165@cindex @code{selectany} variable attribute 8166The @code{selectany} attribute causes an initialized global variable to 8167have link-once semantics. When multiple definitions of the variable are 8168encountered by the linker, the first is selected and the remainder are 8169discarded. Following usage by the Microsoft compiler, the linker is told 8170@emph{not} to warn about size or content differences of the multiple 8171definitions. 8172 8173Although the primary usage of this attribute is for POD types, the 8174attribute can also be applied to global C++ objects that are initialized 8175by a constructor. In this case, the static initialization and destruction 8176code for the object is emitted in each translation defining the object, 8177but the calls to the constructor and destructor are protected by a 8178link-once guard variable. 8179 8180The @code{selectany} attribute is only available on Microsoft Windows 8181targets. You can use @code{__declspec (selectany)} as a synonym for 8182@code{__attribute__ ((selectany))} for compatibility with other 8183compilers. 8184 8185@item shared 8186@cindex @code{shared} variable attribute 8187On Microsoft Windows, in addition to putting variable definitions in a named 8188section, the section can also be shared among all running copies of an 8189executable or DLL@. For example, this small program defines shared data 8190by putting it in a named section @code{shared} and marking the section 8191shareable: 8192 8193@smallexample 8194int foo __attribute__((section ("shared"), shared)) = 0; 8195 8196int 8197main() 8198@{ 8199 /* @r{Read and write foo. All running 8200 copies see the same value.} */ 8201 return 0; 8202@} 8203@end smallexample 8204 8205@noindent 8206You may only use the @code{shared} attribute along with @code{section} 8207attribute with a fully-initialized global definition because of the way 8208linkers work. See @code{section} attribute for more information. 8209 8210The @code{shared} attribute is only available on Microsoft Windows@. 8211 8212@end table 8213 8214@node MSP430 Variable Attributes 8215@subsection MSP430 Variable Attributes 8216 8217@table @code 8218@item upper 8219@itemx either 8220@cindex @code{upper} variable attribute, MSP430 8221@cindex @code{either} variable attribute, MSP430 8222These attributes are the same as the MSP430 function attributes of the 8223same name (@pxref{MSP430 Function Attributes}). 8224 8225@item lower 8226@cindex @code{lower} variable attribute, MSP430 8227This option behaves mostly the same as the MSP430 function attribute of the 8228same name (@pxref{MSP430 Function Attributes}), but it has some additional 8229functionality. 8230 8231If @option{-mdata-region=}@{@code{upper,either,none}@} has been passed, or 8232the @code{section} attribute is applied to a variable, the compiler will 8233generate 430X instructions to handle it. This is because the compiler has 8234to assume that the variable could get placed in the upper memory region 8235(above address 0xFFFF). Marking the variable with the @code{lower} attribute 8236informs the compiler that the variable will be placed in lower memory so it 8237is safe to use 430 instructions to handle it. 8238 8239In the case of the @code{section} attribute, the section name given 8240will be used, and the @code{.lower} prefix will not be added. 8241 8242@end table 8243 8244@node Nvidia PTX Variable Attributes 8245@subsection Nvidia PTX Variable Attributes 8246 8247These variable attributes are supported by the Nvidia PTX back end: 8248 8249@table @code 8250@item shared 8251@cindex @code{shared} attribute, Nvidia PTX 8252Use this attribute to place a variable in the @code{.shared} memory space. 8253This memory space is private to each cooperative thread array; only threads 8254within one thread block refer to the same instance of the variable. 8255The runtime does not initialize variables in this memory space. 8256@end table 8257 8258@node PowerPC Variable Attributes 8259@subsection PowerPC Variable Attributes 8260 8261Three attributes currently are defined for PowerPC configurations: 8262@code{altivec}, @code{ms_struct} and @code{gcc_struct}. 8263 8264@cindex @code{ms_struct} variable attribute, PowerPC 8265@cindex @code{gcc_struct} variable attribute, PowerPC 8266For full documentation of the struct attributes please see the 8267documentation in @ref{x86 Variable Attributes}. 8268 8269@cindex @code{altivec} variable attribute, PowerPC 8270For documentation of @code{altivec} attribute please see the 8271documentation in @ref{PowerPC Type Attributes}. 8272 8273@node RL78 Variable Attributes 8274@subsection RL78 Variable Attributes 8275 8276@cindex @code{saddr} variable attribute, RL78 8277The RL78 back end supports the @code{saddr} variable attribute. This 8278specifies placement of the corresponding variable in the SADDR area, 8279which can be accessed more efficiently than the default memory region. 8280 8281@node V850 Variable Attributes 8282@subsection V850 Variable Attributes 8283 8284These variable attributes are supported by the V850 back end: 8285 8286@table @code 8287 8288@item sda 8289@cindex @code{sda} variable attribute, V850 8290Use this attribute to explicitly place a variable in the small data area, 8291which can hold up to 64 kilobytes. 8292 8293@item tda 8294@cindex @code{tda} variable attribute, V850 8295Use this attribute to explicitly place a variable in the tiny data area, 8296which can hold up to 256 bytes in total. 8297 8298@item zda 8299@cindex @code{zda} variable attribute, V850 8300Use this attribute to explicitly place a variable in the first 32 kilobytes 8301of memory. 8302@end table 8303 8304@node x86 Variable Attributes 8305@subsection x86 Variable Attributes 8306 8307Two attributes are currently defined for x86 configurations: 8308@code{ms_struct} and @code{gcc_struct}. 8309 8310@table @code 8311@item ms_struct 8312@itemx gcc_struct 8313@cindex @code{ms_struct} variable attribute, x86 8314@cindex @code{gcc_struct} variable attribute, x86 8315 8316If @code{packed} is used on a structure, or if bit-fields are used, 8317it may be that the Microsoft ABI lays out the structure differently 8318than the way GCC normally does. Particularly when moving packed 8319data between functions compiled with GCC and the native Microsoft compiler 8320(either via function call or as data in a file), it may be necessary to access 8321either format. 8322 8323The @code{ms_struct} and @code{gcc_struct} attributes correspond 8324to the @option{-mms-bitfields} and @option{-mno-ms-bitfields} 8325command-line options, respectively; 8326see @ref{x86 Options}, for details of how structure layout is affected. 8327@xref{x86 Type Attributes}, for information about the corresponding 8328attributes on types. 8329 8330@end table 8331 8332@node Xstormy16 Variable Attributes 8333@subsection Xstormy16 Variable Attributes 8334 8335One attribute is currently defined for xstormy16 configurations: 8336@code{below100}. 8337 8338@table @code 8339@item below100 8340@cindex @code{below100} variable attribute, Xstormy16 8341 8342If a variable has the @code{below100} attribute (@code{BELOW100} is 8343allowed also), GCC places the variable in the first 0x100 bytes of 8344memory and use special opcodes to access it. Such variables are 8345placed in either the @code{.bss_below100} section or the 8346@code{.data_below100} section. 8347 8348@end table 8349 8350@node Type Attributes 8351@section Specifying Attributes of Types 8352@cindex attribute of types 8353@cindex type attributes 8354 8355The keyword @code{__attribute__} allows you to specify various special 8356properties of types. Some type attributes apply only to structure and 8357union types, and in C++, also class types, while others can apply to 8358any type defined via a @code{typedef} declaration. Unless otherwise 8359specified, the same restrictions and effects apply to attributes regardless 8360of whether a type is a trivial structure or a C++ class with user-defined 8361constructors, destructors, or a copy assignment. 8362 8363Other attributes are defined for functions (@pxref{Function Attributes}), 8364labels (@pxref{Label Attributes}), enumerators (@pxref{Enumerator 8365Attributes}), statements (@pxref{Statement Attributes}), and for variables 8366(@pxref{Variable Attributes}). 8367 8368The @code{__attribute__} keyword is followed by an attribute specification 8369enclosed in double parentheses. 8370 8371You may specify type attributes in an enum, struct or union type 8372declaration or definition by placing them immediately after the 8373@code{struct}, @code{union} or @code{enum} keyword. You can also place 8374them just past the closing curly brace of the definition, but this is less 8375preferred because logically the type should be fully defined at 8376the closing brace. 8377 8378You can also include type attributes in a @code{typedef} declaration. 8379@xref{Attribute Syntax}, for details of the exact syntax for using 8380attributes. 8381 8382@menu 8383* Common Type Attributes:: 8384* ARC Type Attributes:: 8385* ARM Type Attributes:: 8386* BPF Type Attributes:: 8387* MeP Type Attributes:: 8388* PowerPC Type Attributes:: 8389* x86 Type Attributes:: 8390@end menu 8391 8392@node Common Type Attributes 8393@subsection Common Type Attributes 8394 8395The following type attributes are supported on most targets. 8396 8397@table @code 8398@cindex @code{aligned} type attribute 8399@item aligned 8400@itemx aligned (@var{alignment}) 8401The @code{aligned} attribute specifies a minimum alignment (in bytes) for 8402variables of the specified type. When specified, @var{alignment} must be 8403a power of 2. Specifying no @var{alignment} argument implies the maximum 8404alignment for the target, which is often, but by no means always, 8 or 16 8405bytes. For example, the declarations: 8406 8407@smallexample 8408struct __attribute__ ((aligned (8))) S @{ short f[3]; @}; 8409typedef int more_aligned_int __attribute__ ((aligned (8))); 8410@end smallexample 8411 8412@noindent 8413force the compiler to ensure (as far as it can) that each variable whose 8414type is @code{struct S} or @code{more_aligned_int} is allocated and 8415aligned @emph{at least} on a 8-byte boundary. On a SPARC, having all 8416variables of type @code{struct S} aligned to 8-byte boundaries allows 8417the compiler to use the @code{ldd} and @code{std} (doubleword load and 8418store) instructions when copying one variable of type @code{struct S} to 8419another, thus improving run-time efficiency. 8420 8421Note that the alignment of any given @code{struct} or @code{union} type 8422is required by the ISO C standard to be at least a perfect multiple of 8423the lowest common multiple of the alignments of all of the members of 8424the @code{struct} or @code{union} in question. This means that you @emph{can} 8425effectively adjust the alignment of a @code{struct} or @code{union} 8426type by attaching an @code{aligned} attribute to any one of the members 8427of such a type, but the notation illustrated in the example above is a 8428more obvious, intuitive, and readable way to request the compiler to 8429adjust the alignment of an entire @code{struct} or @code{union} type. 8430 8431As in the preceding example, you can explicitly specify the alignment 8432(in bytes) that you wish the compiler to use for a given @code{struct} 8433or @code{union} type. Alternatively, you can leave out the alignment factor 8434and just ask the compiler to align a type to the maximum 8435useful alignment for the target machine you are compiling for. For 8436example, you could write: 8437 8438@smallexample 8439struct __attribute__ ((aligned)) S @{ short f[3]; @}; 8440@end smallexample 8441 8442Whenever you leave out the alignment factor in an @code{aligned} 8443attribute specification, the compiler automatically sets the alignment 8444for the type to the largest alignment that is ever used for any data 8445type on the target machine you are compiling for. Doing this can often 8446make copy operations more efficient, because the compiler can use 8447whatever instructions copy the biggest chunks of memory when performing 8448copies to or from the variables that have types that you have aligned 8449this way. 8450 8451In the example above, if the size of each @code{short} is 2 bytes, then 8452the size of the entire @code{struct S} type is 6 bytes. The smallest 8453power of two that is greater than or equal to that is 8, so the 8454compiler sets the alignment for the entire @code{struct S} type to 8 8455bytes. 8456 8457Note that although you can ask the compiler to select a time-efficient 8458alignment for a given type and then declare only individual stand-alone 8459objects of that type, the compiler's ability to select a time-efficient 8460alignment is primarily useful only when you plan to create arrays of 8461variables having the relevant (efficiently aligned) type. If you 8462declare or use arrays of variables of an efficiently-aligned type, then 8463it is likely that your program also does pointer arithmetic (or 8464subscripting, which amounts to the same thing) on pointers to the 8465relevant type, and the code that the compiler generates for these 8466pointer arithmetic operations is often more efficient for 8467efficiently-aligned types than for other types. 8468 8469Note that the effectiveness of @code{aligned} attributes may be limited 8470by inherent limitations in your linker. On many systems, the linker is 8471only able to arrange for variables to be aligned up to a certain maximum 8472alignment. (For some linkers, the maximum supported alignment may 8473be very very small.) If your linker is only able to align variables 8474up to a maximum of 8-byte alignment, then specifying @code{aligned (16)} 8475in an @code{__attribute__} still only provides you with 8-byte 8476alignment. See your linker documentation for further information. 8477 8478When used on a struct, or struct member, the @code{aligned} attribute can 8479only increase the alignment; in order to decrease it, the @code{packed} 8480attribute must be specified as well. When used as part of a typedef, the 8481@code{aligned} attribute can both increase and decrease alignment, and 8482specifying the @code{packed} attribute generates a warning. 8483 8484@cindex @code{warn_if_not_aligned} type attribute 8485@item warn_if_not_aligned (@var{alignment}) 8486This attribute specifies a threshold for the structure field, measured 8487in bytes. If the structure field is aligned below the threshold, a 8488warning will be issued. For example, the declaration: 8489 8490@smallexample 8491typedef unsigned long long __u64 8492 __attribute__((aligned (4), warn_if_not_aligned (8))); 8493 8494struct foo 8495@{ 8496 int i1; 8497 int i2; 8498 __u64 x; 8499@}; 8500@end smallexample 8501 8502@noindent 8503causes the compiler to issue an warning on @code{struct foo}, like 8504@samp{warning: alignment 4 of 'struct foo' is less than 8}. 8505It is used to define @code{struct foo} in such a way that 8506@code{struct foo} has the same layout and the structure field @code{x} 8507has the same alignment when @code{__u64} is aligned at either 4 or 85088 bytes. Align @code{struct foo} to 8 bytes: 8509 8510@smallexample 8511struct __attribute__ ((aligned (8))) foo 8512@{ 8513 int i1; 8514 int i2; 8515 __u64 x; 8516@}; 8517@end smallexample 8518 8519@noindent 8520silences the warning. The compiler also issues a warning, like 8521@samp{warning: 'x' offset 12 in 'struct foo' isn't aligned to 8}, 8522when the structure field has the misaligned offset: 8523 8524@smallexample 8525struct __attribute__ ((aligned (8))) foo 8526@{ 8527 int i1; 8528 int i2; 8529 int i3; 8530 __u64 x; 8531@}; 8532@end smallexample 8533 8534This warning can be disabled by @option{-Wno-if-not-aligned}. 8535 8536@item alloc_size (@var{position}) 8537@itemx alloc_size (@var{position-1}, @var{position-2}) 8538@cindex @code{alloc_size} type attribute 8539The @code{alloc_size} type attribute may be applied to the definition 8540of a type of a function that returns a pointer and takes at least one 8541argument of an integer type. It indicates that the returned pointer 8542points to an object whose size is given by the function argument at 8543@var{position-1}, or by the product of the arguments at @var{position-1} 8544and @var{position-2}. Meaningful sizes are positive values less than 8545@code{PTRDIFF_MAX}. Other sizes are disagnosed when detected. GCC uses 8546this information to improve the results of @code{__builtin_object_size}. 8547 8548For instance, the following declarations 8549 8550@smallexample 8551typedef __attribute__ ((alloc_size (1, 2))) void* 8552 calloc_type (size_t, size_t); 8553typedef __attribute__ ((alloc_size (1))) void* 8554 malloc_type (size_t); 8555@end smallexample 8556 8557@noindent 8558specify that @code{calloc_type} is a type of a function that, like 8559the standard C function @code{calloc}, returns an object whose size 8560is given by the product of arguments 1 and 2, and that 8561@code{malloc_type}, like the standard C function @code{malloc}, 8562returns an object whose size is given by argument 1 to the function. 8563 8564@item copy 8565@itemx copy (@var{expression}) 8566@cindex @code{copy} type attribute 8567The @code{copy} attribute applies the set of attributes with which 8568the type of the @var{expression} has been declared to the declaration 8569of the type to which the attribute is applied. The attribute is 8570designed for libraries that define aliases that are expected to 8571specify the same set of attributes as the aliased symbols. 8572The @code{copy} attribute can be used with types, variables, or 8573functions. However, the kind of symbol to which the attribute is 8574applied (either varible or function) must match the kind of symbol 8575to which the argument refers. 8576The @code{copy} attribute copies only syntactic and semantic attributes 8577but not attributes that affect a symbol's linkage or visibility such as 8578@code{alias}, @code{visibility}, or @code{weak}. The @code{deprecated} 8579attribute is also not copied. @xref{Common Function Attributes}. 8580@xref{Common Variable Attributes}. 8581 8582For example, suppose @code{struct A} below is defined in some third 8583party library header to have the alignment requirement @code{N} and 8584to force a warning whenever a variable of the type is not so aligned 8585due to attribute @code{packed}. Specifying the @code{copy} attribute 8586on the definition on the unrelated @code{struct B} has the effect of 8587copying all relevant attributes from the type referenced by the pointer 8588expression to @code{struct B}. 8589 8590@smallexample 8591struct __attribute__ ((aligned (N), warn_if_not_aligned (N))) 8592A @{ /* @r{@dots{}} */ @}; 8593struct __attribute__ ((copy ( (struct A *)0)) B @{ /* @r{@dots{}} */ @}; 8594@end smallexample 8595 8596@item deprecated 8597@itemx deprecated (@var{msg}) 8598@cindex @code{deprecated} type attribute 8599The @code{deprecated} attribute results in a warning if the type 8600is used anywhere in the source file. This is useful when identifying 8601types that are expected to be removed in a future version of a program. 8602If possible, the warning also includes the location of the declaration 8603of the deprecated type, to enable users to easily find further 8604information about why the type is deprecated, or what they should do 8605instead. Note that the warnings only occur for uses and then only 8606if the type is being applied to an identifier that itself is not being 8607declared as deprecated. 8608 8609@smallexample 8610typedef int T1 __attribute__ ((deprecated)); 8611T1 x; 8612typedef T1 T2; 8613T2 y; 8614typedef T1 T3 __attribute__ ((deprecated)); 8615T3 z __attribute__ ((deprecated)); 8616@end smallexample 8617 8618@noindent 8619results in a warning on line 2 and 3 but not lines 4, 5, or 6. No 8620warning is issued for line 4 because T2 is not explicitly 8621deprecated. Line 5 has no warning because T3 is explicitly 8622deprecated. Similarly for line 6. The optional @var{msg} 8623argument, which must be a string, is printed in the warning if 8624present. Control characters in the string will be replaced with 8625escape sequences, and if the @option{-fmessage-length} option is set 8626to 0 (its default value) then any newline characters will be ignored. 8627 8628The @code{deprecated} attribute can also be used for functions and 8629variables (@pxref{Function Attributes}, @pxref{Variable Attributes}.) 8630 8631The message attached to the attribute is affected by the setting of 8632the @option{-fmessage-length} option. 8633 8634@item unavailable 8635@itemx unavailable (@var{msg}) 8636@cindex @code{unavailable} type attribute 8637The @code{unavailable} attribute behaves in the same manner as the 8638@code{deprecated} one, but emits an error rather than a warning. It is 8639used to indicate that a (perhaps previously @code{deprecated}) type is 8640no longer usable. 8641 8642The @code{unavailable} attribute can also be used for functions and 8643variables (@pxref{Function Attributes}, @pxref{Variable Attributes}.) 8644 8645@item designated_init 8646@cindex @code{designated_init} type attribute 8647This attribute may only be applied to structure types. It indicates 8648that any initialization of an object of this type must use designated 8649initializers rather than positional initializers. The intent of this 8650attribute is to allow the programmer to indicate that a structure's 8651layout may change, and that therefore relying on positional 8652initialization will result in future breakage. 8653 8654GCC emits warnings based on this attribute by default; use 8655@option{-Wno-designated-init} to suppress them. 8656 8657@item may_alias 8658@cindex @code{may_alias} type attribute 8659Accesses through pointers to types with this attribute are not subject 8660to type-based alias analysis, but are instead assumed to be able to alias 8661any other type of objects. 8662In the context of section 6.5 paragraph 7 of the C99 standard, 8663an lvalue expression 8664dereferencing such a pointer is treated like having a character type. 8665See @option{-fstrict-aliasing} for more information on aliasing issues. 8666This extension exists to support some vector APIs, in which pointers to 8667one vector type are permitted to alias pointers to a different vector type. 8668 8669Note that an object of a type with this attribute does not have any 8670special semantics. 8671 8672Example of use: 8673 8674@smallexample 8675typedef short __attribute__ ((__may_alias__)) short_a; 8676 8677int 8678main (void) 8679@{ 8680 int a = 0x12345678; 8681 short_a *b = (short_a *) &a; 8682 8683 b[1] = 0; 8684 8685 if (a == 0x12345678) 8686 abort(); 8687 8688 exit(0); 8689@} 8690@end smallexample 8691 8692@noindent 8693If you replaced @code{short_a} with @code{short} in the variable 8694declaration, the above program would abort when compiled with 8695@option{-fstrict-aliasing}, which is on by default at @option{-O2} or 8696above. 8697 8698@item mode (@var{mode}) 8699@cindex @code{mode} type attribute 8700This attribute specifies the data type for the declaration---whichever 8701type corresponds to the mode @var{mode}. This in effect lets you 8702request an integer or floating-point type according to its width. 8703 8704@xref{Machine Modes,,, gccint, GNU Compiler Collection (GCC) Internals}, 8705for a list of the possible keywords for @var{mode}. 8706You may also specify a mode of @code{byte} or @code{__byte__} to 8707indicate the mode corresponding to a one-byte integer, @code{word} or 8708@code{__word__} for the mode of a one-word integer, and @code{pointer} 8709or @code{__pointer__} for the mode used to represent pointers. 8710 8711@item packed 8712@cindex @code{packed} type attribute 8713This attribute, attached to a @code{struct}, @code{union}, or C++ @code{class} 8714type definition, specifies that each of its members (other than zero-width 8715bit-fields) is placed to minimize the memory required. This is equivalent 8716to specifying the @code{packed} attribute on each of the members. 8717 8718@opindex fshort-enums 8719When attached to an @code{enum} definition, the @code{packed} attribute 8720indicates that the smallest integral type should be used. 8721Specifying the @option{-fshort-enums} flag on the command line 8722is equivalent to specifying the @code{packed} 8723attribute on all @code{enum} definitions. 8724 8725In the following example @code{struct my_packed_struct}'s members are 8726packed closely together, but the internal layout of its @code{s} member 8727is not packed---to do that, @code{struct my_unpacked_struct} needs to 8728be packed too. 8729 8730@smallexample 8731struct my_unpacked_struct 8732 @{ 8733 char c; 8734 int i; 8735 @}; 8736 8737struct __attribute__ ((__packed__)) my_packed_struct 8738 @{ 8739 char c; 8740 int i; 8741 struct my_unpacked_struct s; 8742 @}; 8743@end smallexample 8744 8745You may only specify the @code{packed} attribute on the definition 8746of an @code{enum}, @code{struct}, @code{union}, or @code{class}, 8747not on a @code{typedef} that does not also define the enumerated type, 8748structure, union, or class. 8749 8750@item scalar_storage_order ("@var{endianness}") 8751@cindex @code{scalar_storage_order} type attribute 8752When attached to a @code{union} or a @code{struct}, this attribute sets 8753the storage order, aka endianness, of the scalar fields of the type, as 8754well as the array fields whose component is scalar. The supported 8755endiannesses are @code{big-endian} and @code{little-endian}. The attribute 8756has no effects on fields which are themselves a @code{union}, a @code{struct} 8757or an array whose component is a @code{union} or a @code{struct}, and it is 8758possible for these fields to have a different scalar storage order than the 8759enclosing type. 8760 8761Note that neither pointer nor vector fields are considered scalar fields in 8762this context, so the attribute has no effects on these fields. 8763 8764This attribute is supported only for targets that use a uniform default 8765scalar storage order (fortunately, most of them), i.e.@: targets that store 8766the scalars either all in big-endian or all in little-endian. 8767 8768Additional restrictions are enforced for types with the reverse scalar 8769storage order with regard to the scalar storage order of the target: 8770 8771@itemize 8772@item Taking the address of a scalar field of a @code{union} or a 8773@code{struct} with reverse scalar storage order is not permitted and yields 8774an error. 8775@item Taking the address of an array field, whose component is scalar, of 8776a @code{union} or a @code{struct} with reverse scalar storage order is 8777permitted but yields a warning, unless @option{-Wno-scalar-storage-order} 8778is specified. 8779@item Taking the address of a @code{union} or a @code{struct} with reverse 8780scalar storage order is permitted. 8781@end itemize 8782 8783These restrictions exist because the storage order attribute is lost when 8784the address of a scalar or the address of an array with scalar component is 8785taken, so storing indirectly through this address generally does not work. 8786The second case is nevertheless allowed to be able to perform a block copy 8787from or to the array. 8788 8789Moreover, the use of type punning or aliasing to toggle the storage order 8790is not supported; that is to say, if a given scalar object can be accessed 8791through distinct types that assign a different storage order to it, then the 8792behavior is undefined. 8793 8794@item transparent_union 8795@cindex @code{transparent_union} type attribute 8796 8797This attribute, attached to a @code{union} type definition, indicates 8798that any function parameter having that union type causes calls to that 8799function to be treated in a special way. 8800 8801First, the argument corresponding to a transparent union type can be of 8802any type in the union; no cast is required. Also, if the union contains 8803a pointer type, the corresponding argument can be a null pointer 8804constant or a void pointer expression; and if the union contains a void 8805pointer type, the corresponding argument can be any pointer expression. 8806If the union member type is a pointer, qualifiers like @code{const} on 8807the referenced type must be respected, just as with normal pointer 8808conversions. 8809 8810Second, the argument is passed to the function using the calling 8811conventions of the first member of the transparent union, not the calling 8812conventions of the union itself. All members of the union must have the 8813same machine representation; this is necessary for this argument passing 8814to work properly. 8815 8816Transparent unions are designed for library functions that have multiple 8817interfaces for compatibility reasons. For example, suppose the 8818@code{wait} function must accept either a value of type @code{int *} to 8819comply with POSIX, or a value of type @code{union wait *} to comply with 8820the 4.1BSD interface. If @code{wait}'s parameter were @code{void *}, 8821@code{wait} would accept both kinds of arguments, but it would also 8822accept any other pointer type and this would make argument type checking 8823less useful. Instead, @code{<sys/wait.h>} might define the interface 8824as follows: 8825 8826@smallexample 8827typedef union __attribute__ ((__transparent_union__)) 8828 @{ 8829 int *__ip; 8830 union wait *__up; 8831 @} wait_status_ptr_t; 8832 8833pid_t wait (wait_status_ptr_t); 8834@end smallexample 8835 8836@noindent 8837This interface allows either @code{int *} or @code{union wait *} 8838arguments to be passed, using the @code{int *} calling convention. 8839The program can call @code{wait} with arguments of either type: 8840 8841@smallexample 8842int w1 () @{ int w; return wait (&w); @} 8843int w2 () @{ union wait w; return wait (&w); @} 8844@end smallexample 8845 8846@noindent 8847With this interface, @code{wait}'s implementation might look like this: 8848 8849@smallexample 8850pid_t wait (wait_status_ptr_t p) 8851@{ 8852 return waitpid (-1, p.__ip, 0); 8853@} 8854@end smallexample 8855 8856@item unused 8857@cindex @code{unused} type attribute 8858When attached to a type (including a @code{union} or a @code{struct}), 8859this attribute means that variables of that type are meant to appear 8860possibly unused. GCC does not produce a warning for any variables of 8861that type, even if the variable appears to do nothing. This is often 8862the case with lock or thread classes, which are usually defined and then 8863not referenced, but contain constructors and destructors that have 8864nontrivial bookkeeping functions. 8865 8866@item vector_size (@var{bytes}) 8867@cindex @code{vector_size} type attribute 8868This attribute specifies the vector size for the type, measured in bytes. 8869The type to which it applies is known as the @dfn{base type}. The @var{bytes} 8870argument must be a positive power-of-two multiple of the base type size. For 8871example, the following declarations: 8872 8873@smallexample 8874typedef __attribute__ ((vector_size (32))) int int_vec32_t ; 8875typedef __attribute__ ((vector_size (32))) int* int_vec32_ptr_t; 8876typedef __attribute__ ((vector_size (32))) int int_vec32_arr3_t[3]; 8877@end smallexample 8878 8879@noindent 8880define @code{int_vec32_t} to be a 32-byte vector type composed of @code{int} 8881sized units. With @code{int} having a size of 4 bytes, the type defines 8882a vector of eight units, four bytes each. The mode of variables of type 8883@code{int_vec32_t} is @code{V8SI}. @code{int_vec32_ptr_t} is then defined 8884to be a pointer to such a vector type, and @code{int_vec32_arr3_t} to be 8885an array of three such vectors. @xref{Vector Extensions}, for details of 8886manipulating objects of vector types. 8887 8888This attribute is only applicable to integral and floating scalar types. 8889In function declarations the attribute applies to the function return 8890type. 8891 8892For example, the following: 8893@smallexample 8894__attribute__ ((vector_size (16))) float get_flt_vec16 (void); 8895@end smallexample 8896declares @code{get_flt_vec16} to be a function returning a 16-byte vector 8897with the base type @code{float}. 8898 8899@item visibility 8900@cindex @code{visibility} type attribute 8901In C++, attribute visibility (@pxref{Function Attributes}) can also be 8902applied to class, struct, union and enum types. Unlike other type 8903attributes, the attribute must appear between the initial keyword and 8904the name of the type; it cannot appear after the body of the type. 8905 8906Note that the type visibility is applied to vague linkage entities 8907associated with the class (vtable, typeinfo node, etc.). In 8908particular, if a class is thrown as an exception in one shared object 8909and caught in another, the class must have default visibility. 8910Otherwise the two shared objects are unable to use the same 8911typeinfo node and exception handling will break. 8912 8913@item objc_root_class @r{(Objective-C and Objective-C++ only)} 8914@cindex @code{objc_root_class} type attribute 8915This attribute marks a class as being a root class, and thus allows 8916the compiler to elide any warnings about a missing superclass and to 8917make additional checks for mandatory methods as needed. 8918 8919@end table 8920 8921To specify multiple attributes, separate them by commas within the 8922double parentheses: for example, @samp{__attribute__ ((aligned (16), 8923packed))}. 8924 8925@node ARC Type Attributes 8926@subsection ARC Type Attributes 8927 8928@cindex @code{uncached} type attribute, ARC 8929Declaring objects with @code{uncached} allows you to exclude 8930data-cache participation in load and store operations on those objects 8931without involving the additional semantic implications of 8932@code{volatile}. The @code{.di} instruction suffix is used for all 8933loads and stores of data declared @code{uncached}. 8934 8935@node ARM Type Attributes 8936@subsection ARM Type Attributes 8937 8938@cindex @code{notshared} type attribute, ARM 8939On those ARM targets that support @code{dllimport} (such as Symbian 8940OS), you can use the @code{notshared} attribute to indicate that the 8941virtual table and other similar data for a class should not be 8942exported from a DLL@. For example: 8943 8944@smallexample 8945class __declspec(notshared) C @{ 8946public: 8947 __declspec(dllimport) C(); 8948 virtual void f(); 8949@} 8950 8951__declspec(dllexport) 8952C::C() @{@} 8953@end smallexample 8954 8955@noindent 8956In this code, @code{C::C} is exported from the current DLL, but the 8957virtual table for @code{C} is not exported. (You can use 8958@code{__attribute__} instead of @code{__declspec} if you prefer, but 8959most Symbian OS code uses @code{__declspec}.) 8960 8961@node BPF Type Attributes 8962@subsection BPF Type Attributes 8963 8964@cindex @code{preserve_access_index} type attribute, BPF 8965BPF Compile Once - Run Everywhere (CO-RE) support. When attached to a 8966@code{struct} or @code{union} type definition, indicates that CO-RE 8967relocation information should be generated for any access to a variable 8968of that type. The behavior is equivalent to the programmer manually 8969wrapping every such access with @code{__builtin_preserve_access_index}. 8970 8971 8972@node MeP Type Attributes 8973@subsection MeP Type Attributes 8974 8975@cindex @code{based} type attribute, MeP 8976@cindex @code{tiny} type attribute, MeP 8977@cindex @code{near} type attribute, MeP 8978@cindex @code{far} type attribute, MeP 8979Many of the MeP variable attributes may be applied to types as well. 8980Specifically, the @code{based}, @code{tiny}, @code{near}, and 8981@code{far} attributes may be applied to either. The @code{io} and 8982@code{cb} attributes may not be applied to types. 8983 8984@node PowerPC Type Attributes 8985@subsection PowerPC Type Attributes 8986 8987Three attributes currently are defined for PowerPC configurations: 8988@code{altivec}, @code{ms_struct} and @code{gcc_struct}. 8989 8990@cindex @code{ms_struct} type attribute, PowerPC 8991@cindex @code{gcc_struct} type attribute, PowerPC 8992For full documentation of the @code{ms_struct} and @code{gcc_struct} 8993attributes please see the documentation in @ref{x86 Type Attributes}. 8994 8995@cindex @code{altivec} type attribute, PowerPC 8996The @code{altivec} attribute allows one to declare AltiVec vector data 8997types supported by the AltiVec Programming Interface Manual. The 8998attribute requires an argument to specify one of three vector types: 8999@code{vector__}, @code{pixel__} (always followed by unsigned short), 9000and @code{bool__} (always followed by unsigned). 9001 9002@smallexample 9003__attribute__((altivec(vector__))) 9004__attribute__((altivec(pixel__))) unsigned short 9005__attribute__((altivec(bool__))) unsigned 9006@end smallexample 9007 9008These attributes mainly are intended to support the @code{__vector}, 9009@code{__pixel}, and @code{__bool} AltiVec keywords. 9010 9011@node x86 Type Attributes 9012@subsection x86 Type Attributes 9013 9014Two attributes are currently defined for x86 configurations: 9015@code{ms_struct} and @code{gcc_struct}. 9016 9017@table @code 9018 9019@item ms_struct 9020@itemx gcc_struct 9021@cindex @code{ms_struct} type attribute, x86 9022@cindex @code{gcc_struct} type attribute, x86 9023 9024If @code{packed} is used on a structure, or if bit-fields are used 9025it may be that the Microsoft ABI packs them differently 9026than GCC normally packs them. Particularly when moving packed 9027data between functions compiled with GCC and the native Microsoft compiler 9028(either via function call or as data in a file), it may be necessary to access 9029either format. 9030 9031The @code{ms_struct} and @code{gcc_struct} attributes correspond 9032to the @option{-mms-bitfields} and @option{-mno-ms-bitfields} 9033command-line options, respectively; 9034see @ref{x86 Options}, for details of how structure layout is affected. 9035@xref{x86 Variable Attributes}, for information about the corresponding 9036attributes on variables. 9037 9038@end table 9039 9040@node Label Attributes 9041@section Label Attributes 9042@cindex Label Attributes 9043 9044GCC allows attributes to be set on C labels. @xref{Attribute Syntax}, for 9045details of the exact syntax for using attributes. Other attributes are 9046available for functions (@pxref{Function Attributes}), variables 9047(@pxref{Variable Attributes}), enumerators (@pxref{Enumerator Attributes}), 9048statements (@pxref{Statement Attributes}), and for types 9049(@pxref{Type Attributes}). A label attribute followed 9050by a declaration appertains to the label and not the declaration. 9051 9052This example uses the @code{cold} label attribute to indicate the 9053@code{ErrorHandling} branch is unlikely to be taken and that the 9054@code{ErrorHandling} label is unused: 9055 9056@smallexample 9057 9058 asm goto ("some asm" : : : : NoError); 9059 9060/* This branch (the fall-through from the asm) is less commonly used */ 9061ErrorHandling: 9062 __attribute__((cold, unused)); /* Semi-colon is required here */ 9063 printf("error\n"); 9064 return 0; 9065 9066NoError: 9067 printf("no error\n"); 9068 return 1; 9069@end smallexample 9070 9071@table @code 9072@item unused 9073@cindex @code{unused} label attribute 9074This feature is intended for program-generated code that may contain 9075unused labels, but which is compiled with @option{-Wall}. It is 9076not normally appropriate to use in it human-written code, though it 9077could be useful in cases where the code that jumps to the label is 9078contained within an @code{#ifdef} conditional. 9079 9080@item hot 9081@cindex @code{hot} label attribute 9082The @code{hot} attribute on a label is used to inform the compiler that 9083the path following the label is more likely than paths that are not so 9084annotated. This attribute is used in cases where @code{__builtin_expect} 9085cannot be used, for instance with computed goto or @code{asm goto}. 9086 9087@item cold 9088@cindex @code{cold} label attribute 9089The @code{cold} attribute on labels is used to inform the compiler that 9090the path following the label is unlikely to be executed. This attribute 9091is used in cases where @code{__builtin_expect} cannot be used, for instance 9092with computed goto or @code{asm goto}. 9093 9094@end table 9095 9096@node Enumerator Attributes 9097@section Enumerator Attributes 9098@cindex Enumerator Attributes 9099 9100GCC allows attributes to be set on enumerators. @xref{Attribute Syntax}, for 9101details of the exact syntax for using attributes. Other attributes are 9102available for functions (@pxref{Function Attributes}), variables 9103(@pxref{Variable Attributes}), labels (@pxref{Label Attributes}), statements 9104(@pxref{Statement Attributes}), and for types (@pxref{Type Attributes}). 9105 9106This example uses the @code{deprecated} enumerator attribute to indicate the 9107@code{oldval} enumerator is deprecated: 9108 9109@smallexample 9110enum E @{ 9111 oldval __attribute__((deprecated)), 9112 newval 9113@}; 9114 9115int 9116fn (void) 9117@{ 9118 return oldval; 9119@} 9120@end smallexample 9121 9122@table @code 9123@item deprecated 9124@cindex @code{deprecated} enumerator attribute 9125The @code{deprecated} attribute results in a warning if the enumerator 9126is used anywhere in the source file. This is useful when identifying 9127enumerators that are expected to be removed in a future version of a 9128program. The warning also includes the location of the declaration 9129of the deprecated enumerator, to enable users to easily find further 9130information about why the enumerator is deprecated, or what they should 9131do instead. Note that the warnings only occurs for uses. 9132 9133@item unavailable 9134@cindex @code{unavailable} enumerator attribute 9135The @code{unavailable} attribute results in an error if the enumerator 9136is used anywhere in the source file. In other respects it behaves in the 9137same manner as the @code{deprecated} attribute. 9138 9139@end table 9140 9141@node Statement Attributes 9142@section Statement Attributes 9143@cindex Statement Attributes 9144 9145GCC allows attributes to be set on null statements. @xref{Attribute Syntax}, 9146for details of the exact syntax for using attributes. Other attributes are 9147available for functions (@pxref{Function Attributes}), variables 9148(@pxref{Variable Attributes}), labels (@pxref{Label Attributes}), enumerators 9149(@pxref{Enumerator Attributes}), and for types (@pxref{Type Attributes}). 9150 9151This example uses the @code{fallthrough} statement attribute to indicate that 9152the @option{-Wimplicit-fallthrough} warning should not be emitted: 9153 9154@smallexample 9155switch (cond) 9156 @{ 9157 case 1: 9158 bar (1); 9159 __attribute__((fallthrough)); 9160 case 2: 9161 @dots{} 9162 @} 9163@end smallexample 9164 9165@table @code 9166@item fallthrough 9167@cindex @code{fallthrough} statement attribute 9168The @code{fallthrough} attribute with a null statement serves as a 9169fallthrough statement. It hints to the compiler that a statement 9170that falls through to another case label, or user-defined label 9171in a switch statement is intentional and thus the 9172@option{-Wimplicit-fallthrough} warning must not trigger. The 9173fallthrough attribute may appear at most once in each attribute 9174list, and may not be mixed with other attributes. It can only 9175be used in a switch statement (the compiler will issue an error 9176otherwise), after a preceding statement and before a logically 9177succeeding case label, or user-defined label. 9178 9179@end table 9180 9181@node Attribute Syntax 9182@section Attribute Syntax 9183@cindex attribute syntax 9184 9185This section describes the syntax with which @code{__attribute__} may be 9186used, and the constructs to which attribute specifiers bind, for the C 9187language. Some details may vary for C++ and Objective-C@. Because of 9188infelicities in the grammar for attributes, some forms described here 9189may not be successfully parsed in all cases. 9190 9191There are some problems with the semantics of attributes in C++. For 9192example, there are no manglings for attributes, although they may affect 9193code generation, so problems may arise when attributed types are used in 9194conjunction with templates or overloading. Similarly, @code{typeid} 9195does not distinguish between types with different attributes. Support 9196for attributes in C++ may be restricted in future to attributes on 9197declarations only, but not on nested declarators. 9198 9199@xref{Function Attributes}, for details of the semantics of attributes 9200applying to functions. @xref{Variable Attributes}, for details of the 9201semantics of attributes applying to variables. @xref{Type Attributes}, 9202for details of the semantics of attributes applying to structure, union 9203and enumerated types. 9204@xref{Label Attributes}, for details of the semantics of attributes 9205applying to labels. 9206@xref{Enumerator Attributes}, for details of the semantics of attributes 9207applying to enumerators. 9208@xref{Statement Attributes}, for details of the semantics of attributes 9209applying to statements. 9210 9211An @dfn{attribute specifier} is of the form 9212@code{__attribute__ ((@var{attribute-list}))}. An @dfn{attribute list} 9213is a possibly empty comma-separated sequence of @dfn{attributes}, where 9214each attribute is one of the following: 9215 9216@itemize @bullet 9217@item 9218Empty. Empty attributes are ignored. 9219 9220@item 9221An attribute name 9222(which may be an identifier such as @code{unused}, or a reserved 9223word such as @code{const}). 9224 9225@item 9226An attribute name followed by a parenthesized list of 9227parameters for the attribute. 9228These parameters take one of the following forms: 9229 9230@itemize @bullet 9231@item 9232An identifier. For example, @code{mode} attributes use this form. 9233 9234@item 9235An identifier followed by a comma and a non-empty comma-separated list 9236of expressions. For example, @code{format} attributes use this form. 9237 9238@item 9239A possibly empty comma-separated list of expressions. For example, 9240@code{format_arg} attributes use this form with the list being a single 9241integer constant expression, and @code{alias} attributes use this form 9242with the list being a single string constant. 9243@end itemize 9244@end itemize 9245 9246An @dfn{attribute specifier list} is a sequence of one or more attribute 9247specifiers, not separated by any other tokens. 9248 9249You may optionally specify attribute names with @samp{__} 9250preceding and following the name. 9251This allows you to use them in header files without 9252being concerned about a possible macro of the same name. For example, 9253you may use the attribute name @code{__noreturn__} instead of @code{noreturn}. 9254 9255 9256@subsubheading Label Attributes 9257 9258In GNU C, an attribute specifier list may appear after the colon following a 9259label, other than a @code{case} or @code{default} label. GNU C++ only permits 9260attributes on labels if the attribute specifier is immediately 9261followed by a semicolon (i.e., the label applies to an empty 9262statement). If the semicolon is missing, C++ label attributes are 9263ambiguous, as it is permissible for a declaration, which could begin 9264with an attribute list, to be labelled in C++. Declarations cannot be 9265labelled in C90 or C99, so the ambiguity does not arise there. 9266 9267@subsubheading Enumerator Attributes 9268 9269In GNU C, an attribute specifier list may appear as part of an enumerator. 9270The attribute goes after the enumeration constant, before @code{=}, if 9271present. The optional attribute in the enumerator appertains to the 9272enumeration constant. It is not possible to place the attribute after 9273the constant expression, if present. 9274 9275@subsubheading Statement Attributes 9276In GNU C, an attribute specifier list may appear as part of a null 9277statement. The attribute goes before the semicolon. 9278 9279@subsubheading Type Attributes 9280 9281An attribute specifier list may appear as part of a @code{struct}, 9282@code{union} or @code{enum} specifier. It may go either immediately 9283after the @code{struct}, @code{union} or @code{enum} keyword, or after 9284the closing brace. The former syntax is preferred. 9285Where attribute specifiers follow the closing brace, they are considered 9286to relate to the structure, union or enumerated type defined, not to any 9287enclosing declaration the type specifier appears in, and the type 9288defined is not complete until after the attribute specifiers. 9289@c Otherwise, there would be the following problems: a shift/reduce 9290@c conflict between attributes binding the struct/union/enum and 9291@c binding to the list of specifiers/qualifiers; and "aligned" 9292@c attributes could use sizeof for the structure, but the size could be 9293@c changed later by "packed" attributes. 9294 9295 9296@subsubheading All other attributes 9297 9298Otherwise, an attribute specifier appears as part of a declaration, 9299counting declarations of unnamed parameters and type names, and relates 9300to that declaration (which may be nested in another declaration, for 9301example in the case of a parameter declaration), or to a particular declarator 9302within a declaration. Where an 9303attribute specifier is applied to a parameter declared as a function or 9304an array, it should apply to the function or array rather than the 9305pointer to which the parameter is implicitly converted, but this is not 9306yet correctly implemented. 9307 9308Any list of specifiers and qualifiers at the start of a declaration may 9309contain attribute specifiers, whether or not such a list may in that 9310context contain storage class specifiers. (Some attributes, however, 9311are essentially in the nature of storage class specifiers, and only make 9312sense where storage class specifiers may be used; for example, 9313@code{section}.) There is one necessary limitation to this syntax: the 9314first old-style parameter declaration in a function definition cannot 9315begin with an attribute specifier, because such an attribute applies to 9316the function instead by syntax described below (which, however, is not 9317yet implemented in this case). In some other cases, attribute 9318specifiers are permitted by this grammar but not yet supported by the 9319compiler. All attribute specifiers in this place relate to the 9320declaration as a whole. In the obsolescent usage where a type of 9321@code{int} is implied by the absence of type specifiers, such a list of 9322specifiers and qualifiers may be an attribute specifier list with no 9323other specifiers or qualifiers. 9324 9325At present, the first parameter in a function prototype must have some 9326type specifier that is not an attribute specifier; this resolves an 9327ambiguity in the interpretation of @code{void f(int 9328(__attribute__((foo)) x))}, but is subject to change. At present, if 9329the parentheses of a function declarator contain only attributes then 9330those attributes are ignored, rather than yielding an error or warning 9331or implying a single parameter of type int, but this is subject to 9332change. 9333 9334An attribute specifier list may appear immediately before a declarator 9335(other than the first) in a comma-separated list of declarators in a 9336declaration of more than one identifier using a single list of 9337specifiers and qualifiers. Such attribute specifiers apply 9338only to the identifier before whose declarator they appear. For 9339example, in 9340 9341@smallexample 9342__attribute__((noreturn)) void d0 (void), 9343 __attribute__((format(printf, 1, 2))) d1 (const char *, ...), 9344 d2 (void); 9345@end smallexample 9346 9347@noindent 9348the @code{noreturn} attribute applies to all the functions 9349declared; the @code{format} attribute only applies to @code{d1}. 9350 9351An attribute specifier list may appear immediately before the comma, 9352@code{=} or semicolon terminating the declaration of an identifier other 9353than a function definition. Such attribute specifiers apply 9354to the declared object or function. Where an 9355assembler name for an object or function is specified (@pxref{Asm 9356Labels}), the attribute must follow the @code{asm} 9357specification. 9358 9359An attribute specifier list may, in future, be permitted to appear after 9360the declarator in a function definition (before any old-style parameter 9361declarations or the function body). 9362 9363Attribute specifiers may be mixed with type qualifiers appearing inside 9364the @code{[]} of a parameter array declarator, in the C99 construct by 9365which such qualifiers are applied to the pointer to which the array is 9366implicitly converted. Such attribute specifiers apply to the pointer, 9367not to the array, but at present this is not implemented and they are 9368ignored. 9369 9370An attribute specifier list may appear at the start of a nested 9371declarator. At present, there are some limitations in this usage: the 9372attributes correctly apply to the declarator, but for most individual 9373attributes the semantics this implies are not implemented. 9374When attribute specifiers follow the @code{*} of a pointer 9375declarator, they may be mixed with any type qualifiers present. 9376The following describes the formal semantics of this syntax. It makes the 9377most sense if you are familiar with the formal specification of 9378declarators in the ISO C standard. 9379 9380Consider (as in C99 subclause 6.7.5 paragraph 4) a declaration @code{T 9381D1}, where @code{T} contains declaration specifiers that specify a type 9382@var{Type} (such as @code{int}) and @code{D1} is a declarator that 9383contains an identifier @var{ident}. The type specified for @var{ident} 9384for derived declarators whose type does not include an attribute 9385specifier is as in the ISO C standard. 9386 9387If @code{D1} has the form @code{( @var{attribute-specifier-list} D )}, 9388and the declaration @code{T D} specifies the type 9389``@var{derived-declarator-type-list} @var{Type}'' for @var{ident}, then 9390@code{T D1} specifies the type ``@var{derived-declarator-type-list} 9391@var{attribute-specifier-list} @var{Type}'' for @var{ident}. 9392 9393If @code{D1} has the form @code{* 9394@var{type-qualifier-and-attribute-specifier-list} D}, and the 9395declaration @code{T D} specifies the type 9396``@var{derived-declarator-type-list} @var{Type}'' for @var{ident}, then 9397@code{T D1} specifies the type ``@var{derived-declarator-type-list} 9398@var{type-qualifier-and-attribute-specifier-list} pointer to @var{Type}'' for 9399@var{ident}. 9400 9401For example, 9402 9403@smallexample 9404void (__attribute__((noreturn)) ****f) (void); 9405@end smallexample 9406 9407@noindent 9408specifies the type ``pointer to pointer to pointer to pointer to 9409non-returning function returning @code{void}''. As another example, 9410 9411@smallexample 9412char *__attribute__((aligned(8))) *f; 9413@end smallexample 9414 9415@noindent 9416specifies the type ``pointer to 8-byte-aligned pointer to @code{char}''. 9417Note again that this does not work with most attributes; for example, 9418the usage of @samp{aligned} and @samp{noreturn} attributes given above 9419is not yet supported. 9420 9421For compatibility with existing code written for compiler versions that 9422did not implement attributes on nested declarators, some laxity is 9423allowed in the placing of attributes. If an attribute that only applies 9424to types is applied to a declaration, it is treated as applying to 9425the type of that declaration. If an attribute that only applies to 9426declarations is applied to the type of a declaration, it is treated 9427as applying to that declaration; and, for compatibility with code 9428placing the attributes immediately before the identifier declared, such 9429an attribute applied to a function return type is treated as 9430applying to the function type, and such an attribute applied to an array 9431element type is treated as applying to the array type. If an 9432attribute that only applies to function types is applied to a 9433pointer-to-function type, it is treated as applying to the pointer 9434target type; if such an attribute is applied to a function return type 9435that is not a pointer-to-function type, it is treated as applying 9436to the function type. 9437 9438@node Function Prototypes 9439@section Prototypes and Old-Style Function Definitions 9440@cindex function prototype declarations 9441@cindex old-style function definitions 9442@cindex promotion of formal parameters 9443 9444GNU C extends ISO C to allow a function prototype to override a later 9445old-style non-prototype definition. Consider the following example: 9446 9447@smallexample 9448/* @r{Use prototypes unless the compiler is old-fashioned.} */ 9449#ifdef __STDC__ 9450#define P(x) x 9451#else 9452#define P(x) () 9453#endif 9454 9455/* @r{Prototype function declaration.} */ 9456int isroot P((uid_t)); 9457 9458/* @r{Old-style function definition.} */ 9459int 9460isroot (x) /* @r{??? lossage here ???} */ 9461 uid_t x; 9462@{ 9463 return x == 0; 9464@} 9465@end smallexample 9466 9467Suppose the type @code{uid_t} happens to be @code{short}. ISO C does 9468not allow this example, because subword arguments in old-style 9469non-prototype definitions are promoted. Therefore in this example the 9470function definition's argument is really an @code{int}, which does not 9471match the prototype argument type of @code{short}. 9472 9473This restriction of ISO C makes it hard to write code that is portable 9474to traditional C compilers, because the programmer does not know 9475whether the @code{uid_t} type is @code{short}, @code{int}, or 9476@code{long}. Therefore, in cases like these GNU C allows a prototype 9477to override a later old-style definition. More precisely, in GNU C, a 9478function prototype argument type overrides the argument type specified 9479by a later old-style definition if the former type is the same as the 9480latter type before promotion. Thus in GNU C the above example is 9481equivalent to the following: 9482 9483@smallexample 9484int isroot (uid_t); 9485 9486int 9487isroot (uid_t x) 9488@{ 9489 return x == 0; 9490@} 9491@end smallexample 9492 9493@noindent 9494GNU C++ does not support old-style function definitions, so this 9495extension is irrelevant. 9496 9497@node C++ Comments 9498@section C++ Style Comments 9499@cindex @code{//} 9500@cindex C++ comments 9501@cindex comments, C++ style 9502 9503In GNU C, you may use C++ style comments, which start with @samp{//} and 9504continue until the end of the line. Many other C implementations allow 9505such comments, and they are included in the 1999 C standard. However, 9506C++ style comments are not recognized if you specify an @option{-std} 9507option specifying a version of ISO C before C99, or @option{-ansi} 9508(equivalent to @option{-std=c90}). 9509 9510@node Dollar Signs 9511@section Dollar Signs in Identifier Names 9512@cindex $ 9513@cindex dollar signs in identifier names 9514@cindex identifier names, dollar signs in 9515 9516In GNU C, you may normally use dollar signs in identifier names. 9517This is because many traditional C implementations allow such identifiers. 9518However, dollar signs in identifiers are not supported on a few target 9519machines, typically because the target assembler does not allow them. 9520 9521@node Character Escapes 9522@section The Character @key{ESC} in Constants 9523 9524You can use the sequence @samp{\e} in a string or character constant to 9525stand for the ASCII character @key{ESC}. 9526 9527@node Alignment 9528@section Determining the Alignment of Functions, Types or Variables 9529@cindex alignment 9530@cindex type alignment 9531@cindex variable alignment 9532 9533The keyword @code{__alignof__} determines the alignment requirement of 9534a function, object, or a type, or the minimum alignment usually required 9535by a type. Its syntax is just like @code{sizeof} and C11 @code{_Alignof}. 9536 9537For example, if the target machine requires a @code{double} value to be 9538aligned on an 8-byte boundary, then @code{__alignof__ (double)} is 8. 9539This is true on many RISC machines. On more traditional machine 9540designs, @code{__alignof__ (double)} is 4 or even 2. 9541 9542Some machines never actually require alignment; they allow references to any 9543data type even at an odd address. For these machines, @code{__alignof__} 9544reports the smallest alignment that GCC gives the data type, usually as 9545mandated by the target ABI. 9546 9547If the operand of @code{__alignof__} is an lvalue rather than a type, 9548its value is the required alignment for its type, taking into account 9549any minimum alignment specified by attribute @code{aligned} 9550(@pxref{Common Variable Attributes}). For example, after this 9551declaration: 9552 9553@smallexample 9554struct foo @{ int x; char y; @} foo1; 9555@end smallexample 9556 9557@noindent 9558the value of @code{__alignof__ (foo1.y)} is 1, even though its actual 9559alignment is probably 2 or 4, the same as @code{__alignof__ (int)}. 9560It is an error to ask for the alignment of an incomplete type other 9561than @code{void}. 9562 9563If the operand of the @code{__alignof__} expression is a function, 9564the expression evaluates to the alignment of the function which may 9565be specified by attribute @code{aligned} (@pxref{Common Function Attributes}). 9566 9567@node Inline 9568@section An Inline Function is As Fast As a Macro 9569@cindex inline functions 9570@cindex integrating function code 9571@cindex open coding 9572@cindex macros, inline alternative 9573 9574By declaring a function inline, you can direct GCC to make 9575calls to that function faster. One way GCC can achieve this is to 9576integrate that function's code into the code for its callers. This 9577makes execution faster by eliminating the function-call overhead; in 9578addition, if any of the actual argument values are constant, their 9579known values may permit simplifications at compile time so that not 9580all of the inline function's code needs to be included. The effect on 9581code size is less predictable; object code may be larger or smaller 9582with function inlining, depending on the particular case. You can 9583also direct GCC to try to integrate all ``simple enough'' functions 9584into their callers with the option @option{-finline-functions}. 9585 9586GCC implements three different semantics of declaring a function 9587inline. One is available with @option{-std=gnu89} or 9588@option{-fgnu89-inline} or when @code{gnu_inline} attribute is present 9589on all inline declarations, another when 9590@option{-std=c99}, 9591@option{-std=gnu99} or an option for a later C version is used 9592(without @option{-fgnu89-inline}), and the third 9593is used when compiling C++. 9594 9595To declare a function inline, use the @code{inline} keyword in its 9596declaration, like this: 9597 9598@smallexample 9599static inline int 9600inc (int *a) 9601@{ 9602 return (*a)++; 9603@} 9604@end smallexample 9605 9606If you are writing a header file to be included in ISO C90 programs, write 9607@code{__inline__} instead of @code{inline}. @xref{Alternate Keywords}. 9608 9609The three types of inlining behave similarly in two important cases: 9610when the @code{inline} keyword is used on a @code{static} function, 9611like the example above, and when a function is first declared without 9612using the @code{inline} keyword and then is defined with 9613@code{inline}, like this: 9614 9615@smallexample 9616extern int inc (int *a); 9617inline int 9618inc (int *a) 9619@{ 9620 return (*a)++; 9621@} 9622@end smallexample 9623 9624In both of these common cases, the program behaves the same as if you 9625had not used the @code{inline} keyword, except for its speed. 9626 9627@cindex inline functions, omission of 9628@opindex fkeep-inline-functions 9629When a function is both inline and @code{static}, if all calls to the 9630function are integrated into the caller, and the function's address is 9631never used, then the function's own assembler code is never referenced. 9632In this case, GCC does not actually output assembler code for the 9633function, unless you specify the option @option{-fkeep-inline-functions}. 9634If there is a nonintegrated call, then the function is compiled to 9635assembler code as usual. The function must also be compiled as usual if 9636the program refers to its address, because that cannot be inlined. 9637 9638@opindex Winline 9639Note that certain usages in a function definition can make it unsuitable 9640for inline substitution. Among these usages are: variadic functions, 9641use of @code{alloca}, use of computed goto (@pxref{Labels as Values}), 9642use of nonlocal goto, use of nested functions, use of @code{setjmp}, use 9643of @code{__builtin_longjmp} and use of @code{__builtin_return} or 9644@code{__builtin_apply_args}. Using @option{-Winline} warns when a 9645function marked @code{inline} could not be substituted, and gives the 9646reason for the failure. 9647 9648@cindex automatic @code{inline} for C++ member fns 9649@cindex @code{inline} automatic for C++ member fns 9650@cindex member fns, automatically @code{inline} 9651@cindex C++ member fns, automatically @code{inline} 9652@opindex fno-default-inline 9653As required by ISO C++, GCC considers member functions defined within 9654the body of a class to be marked inline even if they are 9655not explicitly declared with the @code{inline} keyword. You can 9656override this with @option{-fno-default-inline}; @pxref{C++ Dialect 9657Options,,Options Controlling C++ Dialect}. 9658 9659GCC does not inline any functions when not optimizing unless you specify 9660the @samp{always_inline} attribute for the function, like this: 9661 9662@smallexample 9663/* @r{Prototype.} */ 9664inline void foo (const char) __attribute__((always_inline)); 9665@end smallexample 9666 9667The remainder of this section is specific to GNU C90 inlining. 9668 9669@cindex non-static inline function 9670When an inline function is not @code{static}, then the compiler must assume 9671that there may be calls from other source files; since a global symbol can 9672be defined only once in any program, the function must not be defined in 9673the other source files, so the calls therein cannot be integrated. 9674Therefore, a non-@code{static} inline function is always compiled on its 9675own in the usual fashion. 9676 9677If you specify both @code{inline} and @code{extern} in the function 9678definition, then the definition is used only for inlining. In no case 9679is the function compiled on its own, not even if you refer to its 9680address explicitly. Such an address becomes an external reference, as 9681if you had only declared the function, and had not defined it. 9682 9683This combination of @code{inline} and @code{extern} has almost the 9684effect of a macro. The way to use it is to put a function definition in 9685a header file with these keywords, and put another copy of the 9686definition (lacking @code{inline} and @code{extern}) in a library file. 9687The definition in the header file causes most calls to the function 9688to be inlined. If any uses of the function remain, they refer to 9689the single copy in the library. 9690 9691@node Volatiles 9692@section When is a Volatile Object Accessed? 9693@cindex accessing volatiles 9694@cindex volatile read 9695@cindex volatile write 9696@cindex volatile access 9697 9698C has the concept of volatile objects. These are normally accessed by 9699pointers and used for accessing hardware or inter-thread 9700communication. The standard encourages compilers to refrain from 9701optimizations concerning accesses to volatile objects, but leaves it 9702implementation defined as to what constitutes a volatile access. The 9703minimum requirement is that at a sequence point all previous accesses 9704to volatile objects have stabilized and no subsequent accesses have 9705occurred. Thus an implementation is free to reorder and combine 9706volatile accesses that occur between sequence points, but cannot do 9707so for accesses across a sequence point. The use of volatile does 9708not allow you to violate the restriction on updating objects multiple 9709times between two sequence points. 9710 9711Accesses to non-volatile objects are not ordered with respect to 9712volatile accesses. You cannot use a volatile object as a memory 9713barrier to order a sequence of writes to non-volatile memory. For 9714instance: 9715 9716@smallexample 9717int *ptr = @var{something}; 9718volatile int vobj; 9719*ptr = @var{something}; 9720vobj = 1; 9721@end smallexample 9722 9723@noindent 9724Unless @var{*ptr} and @var{vobj} can be aliased, it is not guaranteed 9725that the write to @var{*ptr} occurs by the time the update 9726of @var{vobj} happens. If you need this guarantee, you must use 9727a stronger memory barrier such as: 9728 9729@smallexample 9730int *ptr = @var{something}; 9731volatile int vobj; 9732*ptr = @var{something}; 9733asm volatile ("" : : : "memory"); 9734vobj = 1; 9735@end smallexample 9736 9737A scalar volatile object is read when it is accessed in a void context: 9738 9739@smallexample 9740volatile int *src = @var{somevalue}; 9741*src; 9742@end smallexample 9743 9744Such expressions are rvalues, and GCC implements this as a 9745read of the volatile object being pointed to. 9746 9747Assignments are also expressions and have an rvalue. However when 9748assigning to a scalar volatile, the volatile object is not reread, 9749regardless of whether the assignment expression's rvalue is used or 9750not. If the assignment's rvalue is used, the value is that assigned 9751to the volatile object. For instance, there is no read of @var{vobj} 9752in all the following cases: 9753 9754@smallexample 9755int obj; 9756volatile int vobj; 9757vobj = @var{something}; 9758obj = vobj = @var{something}; 9759obj ? vobj = @var{onething} : vobj = @var{anotherthing}; 9760obj = (@var{something}, vobj = @var{anotherthing}); 9761@end smallexample 9762 9763If you need to read the volatile object after an assignment has 9764occurred, you must use a separate expression with an intervening 9765sequence point. 9766 9767As bit-fields are not individually addressable, volatile bit-fields may 9768be implicitly read when written to, or when adjacent bit-fields are 9769accessed. Bit-field operations may be optimized such that adjacent 9770bit-fields are only partially accessed, if they straddle a storage unit 9771boundary. For these reasons it is unwise to use volatile bit-fields to 9772access hardware. 9773 9774@node Using Assembly Language with C 9775@section How to Use Inline Assembly Language in C Code 9776@cindex @code{asm} keyword 9777@cindex assembly language in C 9778@cindex inline assembly language 9779@cindex mixing assembly language and C 9780 9781The @code{asm} keyword allows you to embed assembler instructions 9782within C code. GCC provides two forms of inline @code{asm} 9783statements. A @dfn{basic @code{asm}} statement is one with no 9784operands (@pxref{Basic Asm}), while an @dfn{extended @code{asm}} 9785statement (@pxref{Extended Asm}) includes one or more operands. 9786The extended form is preferred for mixing C and assembly language 9787within a function, but to include assembly language at 9788top level you must use basic @code{asm}. 9789 9790You can also use the @code{asm} keyword to override the assembler name 9791for a C symbol, or to place a C variable in a specific register. 9792 9793@menu 9794* Basic Asm:: Inline assembler without operands. 9795* Extended Asm:: Inline assembler with operands. 9796* Constraints:: Constraints for @code{asm} operands 9797* Asm Labels:: Specifying the assembler name to use for a C symbol. 9798* Explicit Register Variables:: Defining variables residing in specified 9799 registers. 9800* Size of an asm:: How GCC calculates the size of an @code{asm} block. 9801@end menu 9802 9803@node Basic Asm 9804@subsection Basic Asm --- Assembler Instructions Without Operands 9805@cindex basic @code{asm} 9806@cindex assembly language in C, basic 9807 9808A basic @code{asm} statement has the following syntax: 9809 9810@example 9811asm @var{asm-qualifiers} ( @var{AssemblerInstructions} ) 9812@end example 9813 9814For the C language, the @code{asm} keyword is a GNU extension. 9815When writing C code that can be compiled with @option{-ansi} and the 9816@option{-std} options that select C dialects without GNU extensions, use 9817@code{__asm__} instead of @code{asm} (@pxref{Alternate Keywords}). For 9818the C++ language, @code{asm} is a standard keyword, but @code{__asm__} 9819can be used for code compiled with @option{-fno-asm}. 9820 9821@subsubheading Qualifiers 9822@table @code 9823@item volatile 9824The optional @code{volatile} qualifier has no effect. 9825All basic @code{asm} blocks are implicitly volatile. 9826 9827@item inline 9828If you use the @code{inline} qualifier, then for inlining purposes the size 9829of the @code{asm} statement is taken as the smallest size possible (@pxref{Size 9830of an asm}). 9831@end table 9832 9833@subsubheading Parameters 9834@table @var 9835 9836@item AssemblerInstructions 9837This is a literal string that specifies the assembler code. The string can 9838contain any instructions recognized by the assembler, including directives. 9839GCC does not parse the assembler instructions themselves and 9840does not know what they mean or even whether they are valid assembler input. 9841 9842You may place multiple assembler instructions together in a single @code{asm} 9843string, separated by the characters normally used in assembly code for the 9844system. A combination that works in most places is a newline to break the 9845line, plus a tab character (written as @samp{\n\t}). 9846Some assemblers allow semicolons as a line separator. However, 9847note that some assembler dialects use semicolons to start a comment. 9848@end table 9849 9850@subsubheading Remarks 9851Using extended @code{asm} (@pxref{Extended Asm}) typically produces 9852smaller, safer, and more efficient code, and in most cases it is a 9853better solution than basic @code{asm}. However, there are two 9854situations where only basic @code{asm} can be used: 9855 9856@itemize @bullet 9857@item 9858Extended @code{asm} statements have to be inside a C 9859function, so to write inline assembly language at file scope (``top-level''), 9860outside of C functions, you must use basic @code{asm}. 9861You can use this technique to emit assembler directives, 9862define assembly language macros that can be invoked elsewhere in the file, 9863or write entire functions in assembly language. 9864Basic @code{asm} statements outside of functions may not use any 9865qualifiers. 9866 9867@item 9868Functions declared 9869with the @code{naked} attribute also require basic @code{asm} 9870(@pxref{Function Attributes}). 9871@end itemize 9872 9873Safely accessing C data and calling functions from basic @code{asm} is more 9874complex than it may appear. To access C data, it is better to use extended 9875@code{asm}. 9876 9877Do not expect a sequence of @code{asm} statements to remain perfectly 9878consecutive after compilation. If certain instructions need to remain 9879consecutive in the output, put them in a single multi-instruction @code{asm} 9880statement. Note that GCC's optimizers can move @code{asm} statements 9881relative to other code, including across jumps. 9882 9883@code{asm} statements may not perform jumps into other @code{asm} statements. 9884GCC does not know about these jumps, and therefore cannot take 9885account of them when deciding how to optimize. Jumps from @code{asm} to C 9886labels are only supported in extended @code{asm}. 9887 9888Under certain circumstances, GCC may duplicate (or remove duplicates of) your 9889assembly code when optimizing. This can lead to unexpected duplicate 9890symbol errors during compilation if your assembly code defines symbols or 9891labels. 9892 9893@strong{Warning:} The C standards do not specify semantics for @code{asm}, 9894making it a potential source of incompatibilities between compilers. These 9895incompatibilities may not produce compiler warnings/errors. 9896 9897GCC does not parse basic @code{asm}'s @var{AssemblerInstructions}, which 9898means there is no way to communicate to the compiler what is happening 9899inside them. GCC has no visibility of symbols in the @code{asm} and may 9900discard them as unreferenced. It also does not know about side effects of 9901the assembler code, such as modifications to memory or registers. Unlike 9902some compilers, GCC assumes that no changes to general purpose registers 9903occur. This assumption may change in a future release. 9904 9905To avoid complications from future changes to the semantics and the 9906compatibility issues between compilers, consider replacing basic @code{asm} 9907with extended @code{asm}. See 9908@uref{https://gcc.gnu.org/wiki/ConvertBasicAsmToExtended, How to convert 9909from basic asm to extended asm} for information about how to perform this 9910conversion. 9911 9912The compiler copies the assembler instructions in a basic @code{asm} 9913verbatim to the assembly language output file, without 9914processing dialects or any of the @samp{%} operators that are available with 9915extended @code{asm}. This results in minor differences between basic 9916@code{asm} strings and extended @code{asm} templates. For example, to refer to 9917registers you might use @samp{%eax} in basic @code{asm} and 9918@samp{%%eax} in extended @code{asm}. 9919 9920On targets such as x86 that support multiple assembler dialects, 9921all basic @code{asm} blocks use the assembler dialect specified by the 9922@option{-masm} command-line option (@pxref{x86 Options}). 9923Basic @code{asm} provides no 9924mechanism to provide different assembler strings for different dialects. 9925 9926For basic @code{asm} with non-empty assembler string GCC assumes 9927the assembler block does not change any general purpose registers, 9928but it may read or write any globally accessible variable. 9929 9930Here is an example of basic @code{asm} for i386: 9931 9932@example 9933/* Note that this code will not compile with -masm=intel */ 9934#define DebugBreak() asm("int $3") 9935@end example 9936 9937@node Extended Asm 9938@subsection Extended Asm - Assembler Instructions with C Expression Operands 9939@cindex extended @code{asm} 9940@cindex assembly language in C, extended 9941 9942With extended @code{asm} you can read and write C variables from 9943assembler and perform jumps from assembler code to C labels. 9944Extended @code{asm} syntax uses colons (@samp{:}) to delimit 9945the operand parameters after the assembler template: 9946 9947@example 9948asm @var{asm-qualifiers} ( @var{AssemblerTemplate} 9949 : @var{OutputOperands} 9950 @r{[} : @var{InputOperands} 9951 @r{[} : @var{Clobbers} @r{]} @r{]}) 9952 9953asm @var{asm-qualifiers} ( @var{AssemblerTemplate} 9954 : @var{OutputOperands} 9955 : @var{InputOperands} 9956 : @var{Clobbers} 9957 : @var{GotoLabels}) 9958@end example 9959where in the last form, @var{asm-qualifiers} contains @code{goto} (and in the 9960first form, not). 9961 9962The @code{asm} keyword is a GNU extension. 9963When writing code that can be compiled with @option{-ansi} and the 9964various @option{-std} options, use @code{__asm__} instead of 9965@code{asm} (@pxref{Alternate Keywords}). 9966 9967@subsubheading Qualifiers 9968@table @code 9969 9970@item volatile 9971The typical use of extended @code{asm} statements is to manipulate input 9972values to produce output values. However, your @code{asm} statements may 9973also produce side effects. If so, you may need to use the @code{volatile} 9974qualifier to disable certain optimizations. @xref{Volatile}. 9975 9976@item inline 9977If you use the @code{inline} qualifier, then for inlining purposes the size 9978of the @code{asm} statement is taken as the smallest size possible 9979(@pxref{Size of an asm}). 9980 9981@item goto 9982This qualifier informs the compiler that the @code{asm} statement may 9983perform a jump to one of the labels listed in the @var{GotoLabels}. 9984@xref{GotoLabels}. 9985@end table 9986 9987@subsubheading Parameters 9988@table @var 9989@item AssemblerTemplate 9990This is a literal string that is the template for the assembler code. It is a 9991combination of fixed text and tokens that refer to the input, output, 9992and goto parameters. @xref{AssemblerTemplate}. 9993 9994@item OutputOperands 9995A comma-separated list of the C variables modified by the instructions in the 9996@var{AssemblerTemplate}. An empty list is permitted. @xref{OutputOperands}. 9997 9998@item InputOperands 9999A comma-separated list of C expressions read by the instructions in the 10000@var{AssemblerTemplate}. An empty list is permitted. @xref{InputOperands}. 10001 10002@item Clobbers 10003A comma-separated list of registers or other values changed by the 10004@var{AssemblerTemplate}, beyond those listed as outputs. 10005An empty list is permitted. @xref{Clobbers and Scratch Registers}. 10006 10007@item GotoLabels 10008When you are using the @code{goto} form of @code{asm}, this section contains 10009the list of all C labels to which the code in the 10010@var{AssemblerTemplate} may jump. 10011@xref{GotoLabels}. 10012 10013@code{asm} statements may not perform jumps into other @code{asm} statements, 10014only to the listed @var{GotoLabels}. 10015GCC's optimizers do not know about other jumps; therefore they cannot take 10016account of them when deciding how to optimize. 10017@end table 10018 10019The total number of input + output + goto operands is limited to 30. 10020 10021@subsubheading Remarks 10022The @code{asm} statement allows you to include assembly instructions directly 10023within C code. This may help you to maximize performance in time-sensitive 10024code or to access assembly instructions that are not readily available to C 10025programs. 10026 10027Note that extended @code{asm} statements must be inside a function. Only 10028basic @code{asm} may be outside functions (@pxref{Basic Asm}). 10029Functions declared with the @code{naked} attribute also require basic 10030@code{asm} (@pxref{Function Attributes}). 10031 10032While the uses of @code{asm} are many and varied, it may help to think of an 10033@code{asm} statement as a series of low-level instructions that convert input 10034parameters to output parameters. So a simple (if not particularly useful) 10035example for i386 using @code{asm} might look like this: 10036 10037@example 10038int src = 1; 10039int dst; 10040 10041asm ("mov %1, %0\n\t" 10042 "add $1, %0" 10043 : "=r" (dst) 10044 : "r" (src)); 10045 10046printf("%d\n", dst); 10047@end example 10048 10049This code copies @code{src} to @code{dst} and add 1 to @code{dst}. 10050 10051@anchor{Volatile} 10052@subsubsection Volatile 10053@cindex volatile @code{asm} 10054@cindex @code{asm} volatile 10055 10056GCC's optimizers sometimes discard @code{asm} statements if they determine 10057there is no need for the output variables. Also, the optimizers may move 10058code out of loops if they believe that the code will always return the same 10059result (i.e.@: none of its input values change between calls). Using the 10060@code{volatile} qualifier disables these optimizations. @code{asm} statements 10061that have no output operands and @code{asm goto} statements, 10062are implicitly volatile. 10063 10064This i386 code demonstrates a case that does not use (or require) the 10065@code{volatile} qualifier. If it is performing assertion checking, this code 10066uses @code{asm} to perform the validation. Otherwise, @code{dwRes} is 10067unreferenced by any code. As a result, the optimizers can discard the 10068@code{asm} statement, which in turn removes the need for the entire 10069@code{DoCheck} routine. By omitting the @code{volatile} qualifier when it 10070isn't needed you allow the optimizers to produce the most efficient code 10071possible. 10072 10073@example 10074void DoCheck(uint32_t dwSomeValue) 10075@{ 10076 uint32_t dwRes; 10077 10078 // Assumes dwSomeValue is not zero. 10079 asm ("bsfl %1,%0" 10080 : "=r" (dwRes) 10081 : "r" (dwSomeValue) 10082 : "cc"); 10083 10084 assert(dwRes > 3); 10085@} 10086@end example 10087 10088The next example shows a case where the optimizers can recognize that the input 10089(@code{dwSomeValue}) never changes during the execution of the function and can 10090therefore move the @code{asm} outside the loop to produce more efficient code. 10091Again, using the @code{volatile} qualifier disables this type of optimization. 10092 10093@example 10094void do_print(uint32_t dwSomeValue) 10095@{ 10096 uint32_t dwRes; 10097 10098 for (uint32_t x=0; x < 5; x++) 10099 @{ 10100 // Assumes dwSomeValue is not zero. 10101 asm ("bsfl %1,%0" 10102 : "=r" (dwRes) 10103 : "r" (dwSomeValue) 10104 : "cc"); 10105 10106 printf("%u: %u %u\n", x, dwSomeValue, dwRes); 10107 @} 10108@} 10109@end example 10110 10111The following example demonstrates a case where you need to use the 10112@code{volatile} qualifier. 10113It uses the x86 @code{rdtsc} instruction, which reads 10114the computer's time-stamp counter. Without the @code{volatile} qualifier, 10115the optimizers might assume that the @code{asm} block will always return the 10116same value and therefore optimize away the second call. 10117 10118@example 10119uint64_t msr; 10120 10121asm volatile ( "rdtsc\n\t" // Returns the time in EDX:EAX. 10122 "shl $32, %%rdx\n\t" // Shift the upper bits left. 10123 "or %%rdx, %0" // 'Or' in the lower bits. 10124 : "=a" (msr) 10125 : 10126 : "rdx"); 10127 10128printf("msr: %llx\n", msr); 10129 10130// Do other work... 10131 10132// Reprint the timestamp 10133asm volatile ( "rdtsc\n\t" // Returns the time in EDX:EAX. 10134 "shl $32, %%rdx\n\t" // Shift the upper bits left. 10135 "or %%rdx, %0" // 'Or' in the lower bits. 10136 : "=a" (msr) 10137 : 10138 : "rdx"); 10139 10140printf("msr: %llx\n", msr); 10141@end example 10142 10143GCC's optimizers do not treat this code like the non-volatile code in the 10144earlier examples. They do not move it out of loops or omit it on the 10145assumption that the result from a previous call is still valid. 10146 10147Note that the compiler can move even @code{volatile asm} instructions relative 10148to other code, including across jump instructions. For example, on many 10149targets there is a system register that controls the rounding mode of 10150floating-point operations. Setting it with a @code{volatile asm} statement, 10151as in the following PowerPC example, does not work reliably. 10152 10153@example 10154asm volatile("mtfsf 255, %0" : : "f" (fpenv)); 10155sum = x + y; 10156@end example 10157 10158The compiler may move the addition back before the @code{volatile asm} 10159statement. To make it work as expected, add an artificial dependency to 10160the @code{asm} by referencing a variable in the subsequent code, for 10161example: 10162 10163@example 10164asm volatile ("mtfsf 255,%1" : "=X" (sum) : "f" (fpenv)); 10165sum = x + y; 10166@end example 10167 10168Under certain circumstances, GCC may duplicate (or remove duplicates of) your 10169assembly code when optimizing. This can lead to unexpected duplicate symbol 10170errors during compilation if your @code{asm} code defines symbols or labels. 10171Using @samp{%=} 10172(@pxref{AssemblerTemplate}) may help resolve this problem. 10173 10174@anchor{AssemblerTemplate} 10175@subsubsection Assembler Template 10176@cindex @code{asm} assembler template 10177 10178An assembler template is a literal string containing assembler instructions. 10179The compiler replaces tokens in the template that refer 10180to inputs, outputs, and goto labels, 10181and then outputs the resulting string to the assembler. The 10182string can contain any instructions recognized by the assembler, including 10183directives. GCC does not parse the assembler instructions 10184themselves and does not know what they mean or even whether they are valid 10185assembler input. However, it does count the statements 10186(@pxref{Size of an asm}). 10187 10188You may place multiple assembler instructions together in a single @code{asm} 10189string, separated by the characters normally used in assembly code for the 10190system. A combination that works in most places is a newline to break the 10191line, plus a tab character to move to the instruction field (written as 10192@samp{\n\t}). 10193Some assemblers allow semicolons as a line separator. However, note 10194that some assembler dialects use semicolons to start a comment. 10195 10196Do not expect a sequence of @code{asm} statements to remain perfectly 10197consecutive after compilation, even when you are using the @code{volatile} 10198qualifier. If certain instructions need to remain consecutive in the output, 10199put them in a single multi-instruction @code{asm} statement. 10200 10201Accessing data from C programs without using input/output operands (such as 10202by using global symbols directly from the assembler template) may not work as 10203expected. Similarly, calling functions directly from an assembler template 10204requires a detailed understanding of the target assembler and ABI. 10205 10206Since GCC does not parse the assembler template, 10207it has no visibility of any 10208symbols it references. This may result in GCC discarding those symbols as 10209unreferenced unless they are also listed as input, output, or goto operands. 10210 10211@subsubheading Special format strings 10212 10213In addition to the tokens described by the input, output, and goto operands, 10214these tokens have special meanings in the assembler template: 10215 10216@table @samp 10217@item %% 10218Outputs a single @samp{%} into the assembler code. 10219 10220@item %= 10221Outputs a number that is unique to each instance of the @code{asm} 10222statement in the entire compilation. This option is useful when creating local 10223labels and referring to them multiple times in a single template that 10224generates multiple assembler instructions. 10225 10226@item %@{ 10227@itemx %| 10228@itemx %@} 10229Outputs @samp{@{}, @samp{|}, and @samp{@}} characters (respectively) 10230into the assembler code. When unescaped, these characters have special 10231meaning to indicate multiple assembler dialects, as described below. 10232@end table 10233 10234@subsubheading Multiple assembler dialects in @code{asm} templates 10235 10236On targets such as x86, GCC supports multiple assembler dialects. 10237The @option{-masm} option controls which dialect GCC uses as its 10238default for inline assembler. The target-specific documentation for the 10239@option{-masm} option contains the list of supported dialects, as well as the 10240default dialect if the option is not specified. This information may be 10241important to understand, since assembler code that works correctly when 10242compiled using one dialect will likely fail if compiled using another. 10243@xref{x86 Options}. 10244 10245If your code needs to support multiple assembler dialects (for example, if 10246you are writing public headers that need to support a variety of compilation 10247options), use constructs of this form: 10248 10249@example 10250@{ dialect0 | dialect1 | dialect2... @} 10251@end example 10252 10253This construct outputs @code{dialect0} 10254when using dialect #0 to compile the code, 10255@code{dialect1} for dialect #1, etc. If there are fewer alternatives within the 10256braces than the number of dialects the compiler supports, the construct 10257outputs nothing. 10258 10259For example, if an x86 compiler supports two dialects 10260(@samp{att}, @samp{intel}), an 10261assembler template such as this: 10262 10263@example 10264"bt@{l %[Offset],%[Base] | %[Base],%[Offset]@}; jc %l2" 10265@end example 10266 10267@noindent 10268is equivalent to one of 10269 10270@example 10271"btl %[Offset],%[Base] ; jc %l2" @r{/* att dialect */} 10272"bt %[Base],%[Offset]; jc %l2" @r{/* intel dialect */} 10273@end example 10274 10275Using that same compiler, this code: 10276 10277@example 10278"xchg@{l@}\t@{%%@}ebx, %1" 10279@end example 10280 10281@noindent 10282corresponds to either 10283 10284@example 10285"xchgl\t%%ebx, %1" @r{/* att dialect */} 10286"xchg\tebx, %1" @r{/* intel dialect */} 10287@end example 10288 10289There is no support for nesting dialect alternatives. 10290 10291@anchor{OutputOperands} 10292@subsubsection Output Operands 10293@cindex @code{asm} output operands 10294 10295An @code{asm} statement has zero or more output operands indicating the names 10296of C variables modified by the assembler code. 10297 10298In this i386 example, @code{old} (referred to in the template string as 10299@code{%0}) and @code{*Base} (as @code{%1}) are outputs and @code{Offset} 10300(@code{%2}) is an input: 10301 10302@example 10303bool old; 10304 10305__asm__ ("btsl %2,%1\n\t" // Turn on zero-based bit #Offset in Base. 10306 "sbb %0,%0" // Use the CF to calculate old. 10307 : "=r" (old), "+rm" (*Base) 10308 : "Ir" (Offset) 10309 : "cc"); 10310 10311return old; 10312@end example 10313 10314Operands are separated by commas. Each operand has this format: 10315 10316@example 10317@r{[} [@var{asmSymbolicName}] @r{]} @var{constraint} (@var{cvariablename}) 10318@end example 10319 10320@table @var 10321@item asmSymbolicName 10322Specifies a symbolic name for the operand. 10323Reference the name in the assembler template 10324by enclosing it in square brackets 10325(i.e.@: @samp{%[Value]}). The scope of the name is the @code{asm} statement 10326that contains the definition. Any valid C variable name is acceptable, 10327including names already defined in the surrounding code. No two operands 10328within the same @code{asm} statement can use the same symbolic name. 10329 10330When not using an @var{asmSymbolicName}, use the (zero-based) position 10331of the operand 10332in the list of operands in the assembler template. For example if there are 10333three output operands, use @samp{%0} in the template to refer to the first, 10334@samp{%1} for the second, and @samp{%2} for the third. 10335 10336@item constraint 10337A string constant specifying constraints on the placement of the operand; 10338@xref{Constraints}, for details. 10339 10340Output constraints must begin with either @samp{=} (a variable overwriting an 10341existing value) or @samp{+} (when reading and writing). When using 10342@samp{=}, do not assume the location contains the existing value 10343on entry to the @code{asm}, except 10344when the operand is tied to an input; @pxref{InputOperands,,Input Operands}. 10345 10346After the prefix, there must be one or more additional constraints 10347(@pxref{Constraints}) that describe where the value resides. Common 10348constraints include @samp{r} for register and @samp{m} for memory. 10349When you list more than one possible location (for example, @code{"=rm"}), 10350the compiler chooses the most efficient one based on the current context. 10351If you list as many alternates as the @code{asm} statement allows, you permit 10352the optimizers to produce the best possible code. 10353If you must use a specific register, but your Machine Constraints do not 10354provide sufficient control to select the specific register you want, 10355local register variables may provide a solution (@pxref{Local Register 10356Variables}). 10357 10358@item cvariablename 10359Specifies a C lvalue expression to hold the output, typically a variable name. 10360The enclosing parentheses are a required part of the syntax. 10361 10362@end table 10363 10364When the compiler selects the registers to use to 10365represent the output operands, it does not use any of the clobbered registers 10366(@pxref{Clobbers and Scratch Registers}). 10367 10368Output operand expressions must be lvalues. The compiler cannot check whether 10369the operands have data types that are reasonable for the instruction being 10370executed. For output expressions that are not directly addressable (for 10371example a bit-field), the constraint must allow a register. In that case, GCC 10372uses the register as the output of the @code{asm}, and then stores that 10373register into the output. 10374 10375Operands using the @samp{+} constraint modifier count as two operands 10376(that is, both as input and output) towards the total maximum of 30 operands 10377per @code{asm} statement. 10378 10379Use the @samp{&} constraint modifier (@pxref{Modifiers}) on all output 10380operands that must not overlap an input. Otherwise, 10381GCC may allocate the output operand in the same register as an unrelated 10382input operand, on the assumption that the assembler code consumes its 10383inputs before producing outputs. This assumption may be false if the assembler 10384code actually consists of more than one instruction. 10385 10386The same problem can occur if one output parameter (@var{a}) allows a register 10387constraint and another output parameter (@var{b}) allows a memory constraint. 10388The code generated by GCC to access the memory address in @var{b} can contain 10389registers which @emph{might} be shared by @var{a}, and GCC considers those 10390registers to be inputs to the asm. As above, GCC assumes that such input 10391registers are consumed before any outputs are written. This assumption may 10392result in incorrect behavior if the @code{asm} statement writes to @var{a} 10393before using 10394@var{b}. Combining the @samp{&} modifier with the register constraint on @var{a} 10395ensures that modifying @var{a} does not affect the address referenced by 10396@var{b}. Otherwise, the location of @var{b} 10397is undefined if @var{a} is modified before using @var{b}. 10398 10399@code{asm} supports operand modifiers on operands (for example @samp{%k2} 10400instead of simply @samp{%2}). Typically these qualifiers are hardware 10401dependent. The list of supported modifiers for x86 is found at 10402@ref{x86Operandmodifiers,x86 Operand modifiers}. 10403 10404If the C code that follows the @code{asm} makes no use of any of the output 10405operands, use @code{volatile} for the @code{asm} statement to prevent the 10406optimizers from discarding the @code{asm} statement as unneeded 10407(see @ref{Volatile}). 10408 10409This code makes no use of the optional @var{asmSymbolicName}. Therefore it 10410references the first output operand as @code{%0} (were there a second, it 10411would be @code{%1}, etc). The number of the first input operand is one greater 10412than that of the last output operand. In this i386 example, that makes 10413@code{Mask} referenced as @code{%1}: 10414 10415@example 10416uint32_t Mask = 1234; 10417uint32_t Index; 10418 10419 asm ("bsfl %1, %0" 10420 : "=r" (Index) 10421 : "r" (Mask) 10422 : "cc"); 10423@end example 10424 10425That code overwrites the variable @code{Index} (@samp{=}), 10426placing the value in a register (@samp{r}). 10427Using the generic @samp{r} constraint instead of a constraint for a specific 10428register allows the compiler to pick the register to use, which can result 10429in more efficient code. This may not be possible if an assembler instruction 10430requires a specific register. 10431 10432The following i386 example uses the @var{asmSymbolicName} syntax. 10433It produces the 10434same result as the code above, but some may consider it more readable or more 10435maintainable since reordering index numbers is not necessary when adding or 10436removing operands. The names @code{aIndex} and @code{aMask} 10437are only used in this example to emphasize which 10438names get used where. 10439It is acceptable to reuse the names @code{Index} and @code{Mask}. 10440 10441@example 10442uint32_t Mask = 1234; 10443uint32_t Index; 10444 10445 asm ("bsfl %[aMask], %[aIndex]" 10446 : [aIndex] "=r" (Index) 10447 : [aMask] "r" (Mask) 10448 : "cc"); 10449@end example 10450 10451Here are some more examples of output operands. 10452 10453@example 10454uint32_t c = 1; 10455uint32_t d; 10456uint32_t *e = &c; 10457 10458asm ("mov %[e], %[d]" 10459 : [d] "=rm" (d) 10460 : [e] "rm" (*e)); 10461@end example 10462 10463Here, @code{d} may either be in a register or in memory. Since the compiler 10464might already have the current value of the @code{uint32_t} location 10465pointed to by @code{e} 10466in a register, you can enable it to choose the best location 10467for @code{d} by specifying both constraints. 10468 10469@anchor{FlagOutputOperands} 10470@subsubsection Flag Output Operands 10471@cindex @code{asm} flag output operands 10472 10473Some targets have a special register that holds the ``flags'' for the 10474result of an operation or comparison. Normally, the contents of that 10475register are either unmodifed by the asm, or the @code{asm} statement is 10476considered to clobber the contents. 10477 10478On some targets, a special form of output operand exists by which 10479conditions in the flags register may be outputs of the asm. The set of 10480conditions supported are target specific, but the general rule is that 10481the output variable must be a scalar integer, and the value is boolean. 10482When supported, the target defines the preprocessor symbol 10483@code{__GCC_ASM_FLAG_OUTPUTS__}. 10484 10485Because of the special nature of the flag output operands, the constraint 10486may not include alternatives. 10487 10488Most often, the target has only one flags register, and thus is an implied 10489operand of many instructions. In this case, the operand should not be 10490referenced within the assembler template via @code{%0} etc, as there's 10491no corresponding text in the assembly language. 10492 10493@table @asis 10494@item ARM 10495@itemx AArch64 10496The flag output constraints for the ARM family are of the form 10497@samp{=@@cc@var{cond}} where @var{cond} is one of the standard 10498conditions defined in the ARM ARM for @code{ConditionHolds}. 10499 10500@table @code 10501@item eq 10502Z flag set, or equal 10503@item ne 10504Z flag clear or not equal 10505@item cs 10506@itemx hs 10507C flag set or unsigned greater than equal 10508@item cc 10509@itemx lo 10510C flag clear or unsigned less than 10511@item mi 10512N flag set or ``minus'' 10513@item pl 10514N flag clear or ``plus'' 10515@item vs 10516V flag set or signed overflow 10517@item vc 10518V flag clear 10519@item hi 10520unsigned greater than 10521@item ls 10522unsigned less than equal 10523@item ge 10524signed greater than equal 10525@item lt 10526signed less than 10527@item gt 10528signed greater than 10529@item le 10530signed less than equal 10531@end table 10532 10533The flag output constraints are not supported in thumb1 mode. 10534 10535@item x86 family 10536The flag output constraints for the x86 family are of the form 10537@samp{=@@cc@var{cond}} where @var{cond} is one of the standard 10538conditions defined in the ISA manual for @code{j@var{cc}} or 10539@code{set@var{cc}}. 10540 10541@table @code 10542@item a 10543``above'' or unsigned greater than 10544@item ae 10545``above or equal'' or unsigned greater than or equal 10546@item b 10547``below'' or unsigned less than 10548@item be 10549``below or equal'' or unsigned less than or equal 10550@item c 10551carry flag set 10552@item e 10553@itemx z 10554``equal'' or zero flag set 10555@item g 10556signed greater than 10557@item ge 10558signed greater than or equal 10559@item l 10560signed less than 10561@item le 10562signed less than or equal 10563@item o 10564overflow flag set 10565@item p 10566parity flag set 10567@item s 10568sign flag set 10569@item na 10570@itemx nae 10571@itemx nb 10572@itemx nbe 10573@itemx nc 10574@itemx ne 10575@itemx ng 10576@itemx nge 10577@itemx nl 10578@itemx nle 10579@itemx no 10580@itemx np 10581@itemx ns 10582@itemx nz 10583``not'' @var{flag}, or inverted versions of those above 10584@end table 10585 10586@end table 10587 10588@anchor{InputOperands} 10589@subsubsection Input Operands 10590@cindex @code{asm} input operands 10591@cindex @code{asm} expressions 10592 10593Input operands make values from C variables and expressions available to the 10594assembly code. 10595 10596Operands are separated by commas. Each operand has this format: 10597 10598@example 10599@r{[} [@var{asmSymbolicName}] @r{]} @var{constraint} (@var{cexpression}) 10600@end example 10601 10602@table @var 10603@item asmSymbolicName 10604Specifies a symbolic name for the operand. 10605Reference the name in the assembler template 10606by enclosing it in square brackets 10607(i.e.@: @samp{%[Value]}). The scope of the name is the @code{asm} statement 10608that contains the definition. Any valid C variable name is acceptable, 10609including names already defined in the surrounding code. No two operands 10610within the same @code{asm} statement can use the same symbolic name. 10611 10612When not using an @var{asmSymbolicName}, use the (zero-based) position 10613of the operand 10614in the list of operands in the assembler template. For example if there are 10615two output operands and three inputs, 10616use @samp{%2} in the template to refer to the first input operand, 10617@samp{%3} for the second, and @samp{%4} for the third. 10618 10619@item constraint 10620A string constant specifying constraints on the placement of the operand; 10621@xref{Constraints}, for details. 10622 10623Input constraint strings may not begin with either @samp{=} or @samp{+}. 10624When you list more than one possible location (for example, @samp{"irm"}), 10625the compiler chooses the most efficient one based on the current context. 10626If you must use a specific register, but your Machine Constraints do not 10627provide sufficient control to select the specific register you want, 10628local register variables may provide a solution (@pxref{Local Register 10629Variables}). 10630 10631Input constraints can also be digits (for example, @code{"0"}). This indicates 10632that the specified input must be in the same place as the output constraint 10633at the (zero-based) index in the output constraint list. 10634When using @var{asmSymbolicName} syntax for the output operands, 10635you may use these names (enclosed in brackets @samp{[]}) instead of digits. 10636 10637@item cexpression 10638This is the C variable or expression being passed to the @code{asm} statement 10639as input. The enclosing parentheses are a required part of the syntax. 10640 10641@end table 10642 10643When the compiler selects the registers to use to represent the input 10644operands, it does not use any of the clobbered registers 10645(@pxref{Clobbers and Scratch Registers}). 10646 10647If there are no output operands but there are input operands, place two 10648consecutive colons where the output operands would go: 10649 10650@example 10651__asm__ ("some instructions" 10652 : /* No outputs. */ 10653 : "r" (Offset / 8)); 10654@end example 10655 10656@strong{Warning:} Do @emph{not} modify the contents of input-only operands 10657(except for inputs tied to outputs). The compiler assumes that on exit from 10658the @code{asm} statement these operands contain the same values as they 10659had before executing the statement. 10660It is @emph{not} possible to use clobbers 10661to inform the compiler that the values in these inputs are changing. One 10662common work-around is to tie the changing input variable to an output variable 10663that never gets used. Note, however, that if the code that follows the 10664@code{asm} statement makes no use of any of the output operands, the GCC 10665optimizers may discard the @code{asm} statement as unneeded 10666(see @ref{Volatile}). 10667 10668@code{asm} supports operand modifiers on operands (for example @samp{%k2} 10669instead of simply @samp{%2}). Typically these qualifiers are hardware 10670dependent. The list of supported modifiers for x86 is found at 10671@ref{x86Operandmodifiers,x86 Operand modifiers}. 10672 10673In this example using the fictitious @code{combine} instruction, the 10674constraint @code{"0"} for input operand 1 says that it must occupy the same 10675location as output operand 0. Only input operands may use numbers in 10676constraints, and they must each refer to an output operand. Only a number (or 10677the symbolic assembler name) in the constraint can guarantee that one operand 10678is in the same place as another. The mere fact that @code{foo} is the value of 10679both operands is not enough to guarantee that they are in the same place in 10680the generated assembler code. 10681 10682@example 10683asm ("combine %2, %0" 10684 : "=r" (foo) 10685 : "0" (foo), "g" (bar)); 10686@end example 10687 10688Here is an example using symbolic names. 10689 10690@example 10691asm ("cmoveq %1, %2, %[result]" 10692 : [result] "=r"(result) 10693 : "r" (test), "r" (new), "[result]" (old)); 10694@end example 10695 10696@anchor{Clobbers and Scratch Registers} 10697@subsubsection Clobbers and Scratch Registers 10698@cindex @code{asm} clobbers 10699@cindex @code{asm} scratch registers 10700 10701While the compiler is aware of changes to entries listed in the output 10702operands, the inline @code{asm} code may modify more than just the outputs. For 10703example, calculations may require additional registers, or the processor may 10704overwrite a register as a side effect of a particular assembler instruction. 10705In order to inform the compiler of these changes, list them in the clobber 10706list. Clobber list items are either register names or the special clobbers 10707(listed below). Each clobber list item is a string constant 10708enclosed in double quotes and separated by commas. 10709 10710Clobber descriptions may not in any way overlap with an input or output 10711operand. For example, you may not have an operand describing a register class 10712with one member when listing that register in the clobber list. Variables 10713declared to live in specific registers (@pxref{Explicit Register 10714Variables}) and used 10715as @code{asm} input or output operands must have no part mentioned in the 10716clobber description. In particular, there is no way to specify that input 10717operands get modified without also specifying them as output operands. 10718 10719When the compiler selects which registers to use to represent input and output 10720operands, it does not use any of the clobbered registers. As a result, 10721clobbered registers are available for any use in the assembler code. 10722 10723Another restriction is that the clobber list should not contain the 10724stack pointer register. This is because the compiler requires the 10725value of the stack pointer to be the same after an @code{asm} 10726statement as it was on entry to the statement. However, previous 10727versions of GCC did not enforce this rule and allowed the stack 10728pointer to appear in the list, with unclear semantics. This behavior 10729is deprecated and listing the stack pointer may become an error in 10730future versions of GCC@. 10731 10732Here is a realistic example for the VAX showing the use of clobbered 10733registers: 10734 10735@example 10736asm volatile ("movc3 %0, %1, %2" 10737 : /* No outputs. */ 10738 : "g" (from), "g" (to), "g" (count) 10739 : "r0", "r1", "r2", "r3", "r4", "r5", "memory"); 10740@end example 10741 10742Also, there are two special clobber arguments: 10743 10744@table @code 10745@item "cc" 10746The @code{"cc"} clobber indicates that the assembler code modifies the flags 10747register. On some machines, GCC represents the condition codes as a specific 10748hardware register; @code{"cc"} serves to name this register. 10749On other machines, condition code handling is different, 10750and specifying @code{"cc"} has no effect. But 10751it is valid no matter what the target. 10752 10753@item "memory" 10754The @code{"memory"} clobber tells the compiler that the assembly code 10755performs memory 10756reads or writes to items other than those listed in the input and output 10757operands (for example, accessing the memory pointed to by one of the input 10758parameters). To ensure memory contains correct values, GCC may need to flush 10759specific register values to memory before executing the @code{asm}. Further, 10760the compiler does not assume that any values read from memory before an 10761@code{asm} remain unchanged after that @code{asm}; it reloads them as 10762needed. 10763Using the @code{"memory"} clobber effectively forms a read/write 10764memory barrier for the compiler. 10765 10766Note that this clobber does not prevent the @emph{processor} from doing 10767speculative reads past the @code{asm} statement. To prevent that, you need 10768processor-specific fence instructions. 10769 10770@end table 10771 10772Flushing registers to memory has performance implications and may be 10773an issue for time-sensitive code. You can provide better information 10774to GCC to avoid this, as shown in the following examples. At a 10775minimum, aliasing rules allow GCC to know what memory @emph{doesn't} 10776need to be flushed. 10777 10778Here is a fictitious sum of squares instruction, that takes two 10779pointers to floating point values in memory and produces a floating 10780point register output. 10781Notice that @code{x}, and @code{y} both appear twice in the @code{asm} 10782parameters, once to specify memory accessed, and once to specify a 10783base register used by the @code{asm}. You won't normally be wasting a 10784register by doing this as GCC can use the same register for both 10785purposes. However, it would be foolish to use both @code{%1} and 10786@code{%3} for @code{x} in this @code{asm} and expect them to be the 10787same. In fact, @code{%3} may well not be a register. It might be a 10788symbolic memory reference to the object pointed to by @code{x}. 10789 10790@smallexample 10791asm ("sumsq %0, %1, %2" 10792 : "+f" (result) 10793 : "r" (x), "r" (y), "m" (*x), "m" (*y)); 10794@end smallexample 10795 10796Here is a fictitious @code{*z++ = *x++ * *y++} instruction. 10797Notice that the @code{x}, @code{y} and @code{z} pointer registers 10798must be specified as input/output because the @code{asm} modifies 10799them. 10800 10801@smallexample 10802asm ("vecmul %0, %1, %2" 10803 : "+r" (z), "+r" (x), "+r" (y), "=m" (*z) 10804 : "m" (*x), "m" (*y)); 10805@end smallexample 10806 10807An x86 example where the string memory argument is of unknown length. 10808 10809@smallexample 10810asm("repne scasb" 10811 : "=c" (count), "+D" (p) 10812 : "m" (*(const char (*)[]) p), "0" (-1), "a" (0)); 10813@end smallexample 10814 10815If you know the above will only be reading a ten byte array then you 10816could instead use a memory input like: 10817@code{"m" (*(const char (*)[10]) p)}. 10818 10819Here is an example of a PowerPC vector scale implemented in assembly, 10820complete with vector and condition code clobbers, and some initialized 10821offset registers that are unchanged by the @code{asm}. 10822 10823@smallexample 10824void 10825dscal (size_t n, double *x, double alpha) 10826@{ 10827 asm ("/* lots of asm here */" 10828 : "+m" (*(double (*)[n]) x), "+&r" (n), "+b" (x) 10829 : "d" (alpha), "b" (32), "b" (48), "b" (64), 10830 "b" (80), "b" (96), "b" (112) 10831 : "cr0", 10832 "vs32","vs33","vs34","vs35","vs36","vs37","vs38","vs39", 10833 "vs40","vs41","vs42","vs43","vs44","vs45","vs46","vs47"); 10834@} 10835@end smallexample 10836 10837Rather than allocating fixed registers via clobbers to provide scratch 10838registers for an @code{asm} statement, an alternative is to define a 10839variable and make it an early-clobber output as with @code{a2} and 10840@code{a3} in the example below. This gives the compiler register 10841allocator more freedom. You can also define a variable and make it an 10842output tied to an input as with @code{a0} and @code{a1}, tied 10843respectively to @code{ap} and @code{lda}. Of course, with tied 10844outputs your @code{asm} can't use the input value after modifying the 10845output register since they are one and the same register. What's 10846more, if you omit the early-clobber on the output, it is possible that 10847GCC might allocate the same register to another of the inputs if GCC 10848could prove they had the same value on entry to the @code{asm}. This 10849is why @code{a1} has an early-clobber. Its tied input, @code{lda} 10850might conceivably be known to have the value 16 and without an 10851early-clobber share the same register as @code{%11}. On the other 10852hand, @code{ap} can't be the same as any of the other inputs, so an 10853early-clobber on @code{a0} is not needed. It is also not desirable in 10854this case. An early-clobber on @code{a0} would cause GCC to allocate 10855a separate register for the @code{"m" (*(const double (*)[]) ap)} 10856input. Note that tying an input to an output is the way to set up an 10857initialized temporary register modified by an @code{asm} statement. 10858An input not tied to an output is assumed by GCC to be unchanged, for 10859example @code{"b" (16)} below sets up @code{%11} to 16, and GCC might 10860use that register in following code if the value 16 happened to be 10861needed. You can even use a normal @code{asm} output for a scratch if 10862all inputs that might share the same register are consumed before the 10863scratch is used. The VSX registers clobbered by the @code{asm} 10864statement could have used this technique except for GCC's limit on the 10865number of @code{asm} parameters. 10866 10867@smallexample 10868static void 10869dgemv_kernel_4x4 (long n, const double *ap, long lda, 10870 const double *x, double *y, double alpha) 10871@{ 10872 double *a0; 10873 double *a1; 10874 double *a2; 10875 double *a3; 10876 10877 __asm__ 10878 ( 10879 /* lots of asm here */ 10880 "#n=%1 ap=%8=%12 lda=%13 x=%7=%10 y=%0=%2 alpha=%9 o16=%11\n" 10881 "#a0=%3 a1=%4 a2=%5 a3=%6" 10882 : 10883 "+m" (*(double (*)[n]) y), 10884 "+&r" (n), // 1 10885 "+b" (y), // 2 10886 "=b" (a0), // 3 10887 "=&b" (a1), // 4 10888 "=&b" (a2), // 5 10889 "=&b" (a3) // 6 10890 : 10891 "m" (*(const double (*)[n]) x), 10892 "m" (*(const double (*)[]) ap), 10893 "d" (alpha), // 9 10894 "r" (x), // 10 10895 "b" (16), // 11 10896 "3" (ap), // 12 10897 "4" (lda) // 13 10898 : 10899 "cr0", 10900 "vs32","vs33","vs34","vs35","vs36","vs37", 10901 "vs40","vs41","vs42","vs43","vs44","vs45","vs46","vs47" 10902 ); 10903@} 10904@end smallexample 10905 10906@anchor{GotoLabels} 10907@subsubsection Goto Labels 10908@cindex @code{asm} goto labels 10909 10910@code{asm goto} allows assembly code to jump to one or more C labels. The 10911@var{GotoLabels} section in an @code{asm goto} statement contains 10912a comma-separated 10913list of all C labels to which the assembler code may jump. GCC assumes that 10914@code{asm} execution falls through to the next statement (if this is not the 10915case, consider using the @code{__builtin_unreachable} intrinsic after the 10916@code{asm} statement). Optimization of @code{asm goto} may be improved by 10917using the @code{hot} and @code{cold} label attributes (@pxref{Label 10918Attributes}). 10919 10920If the assembler code does modify anything, use the @code{"memory"} clobber 10921to force the 10922optimizers to flush all register values to memory and reload them if 10923necessary after the @code{asm} statement. 10924 10925Also note that an @code{asm goto} statement is always implicitly 10926considered volatile. 10927 10928Be careful when you set output operands inside @code{asm goto} only on 10929some possible control flow paths. If you don't set up the output on 10930given path and never use it on this path, it is okay. Otherwise, you 10931should use @samp{+} constraint modifier meaning that the operand is 10932input and output one. With this modifier you will have the correct 10933values on all possible paths from the @code{asm goto}. 10934 10935To reference a label in the assembler template, prefix it with 10936@samp{%l} (lowercase @samp{L}) followed by its (zero-based) position 10937in @var{GotoLabels} plus the number of input and output operands. 10938Output operand with constraint modifier @samp{+} is counted as two 10939operands because it is considered as one output and one input operand. 10940For example, if the @code{asm} has three inputs, one output operand 10941with constraint modifier @samp{+} and one output operand with 10942constraint modifier @samp{=} and references two labels, refer to the 10943first label as @samp{%l6} and the second as @samp{%l7}). 10944 10945Alternately, you can reference labels using the actual C label name 10946enclosed in brackets. For example, to reference a label named 10947@code{carry}, you can use @samp{%l[carry]}. The label must still be 10948listed in the @var{GotoLabels} section when using this approach. It 10949is better to use the named references for labels as in this case you 10950can avoid counting input and output operands and special treatment of 10951output operands with constraint modifier @samp{+}. 10952 10953Here is an example of @code{asm goto} for i386: 10954 10955@example 10956asm goto ( 10957 "btl %1, %0\n\t" 10958 "jc %l2" 10959 : /* No outputs. */ 10960 : "r" (p1), "r" (p2) 10961 : "cc" 10962 : carry); 10963 10964return 0; 10965 10966carry: 10967return 1; 10968@end example 10969 10970The following example shows an @code{asm goto} that uses a memory clobber. 10971 10972@example 10973int frob(int x) 10974@{ 10975 int y; 10976 asm goto ("frob %%r5, %1; jc %l[error]; mov (%2), %%r5" 10977 : /* No outputs. */ 10978 : "r"(x), "r"(&y) 10979 : "r5", "memory" 10980 : error); 10981 return y; 10982error: 10983 return -1; 10984@} 10985@end example 10986 10987The following example shows an @code{asm goto} that uses an output. 10988 10989@example 10990int foo(int count) 10991@{ 10992 asm goto ("dec %0; jb %l[stop]" 10993 : "+r" (count) 10994 : 10995 : 10996 : stop); 10997 return count; 10998stop: 10999 return 0; 11000@} 11001@end example 11002 11003The following artificial example shows an @code{asm goto} that sets 11004up an output only on one path inside the @code{asm goto}. Usage of 11005constraint modifier @code{=} instead of @code{+} would be wrong as 11006@code{factor} is used on all paths from the @code{asm goto}. 11007 11008@example 11009int foo(int inp) 11010@{ 11011 int factor = 0; 11012 asm goto ("cmp %1, 10; jb %l[lab]; mov 2, %0" 11013 : "+r" (factor) 11014 : "r" (inp) 11015 : 11016 : lab); 11017lab: 11018 return inp * factor; /* return 2 * inp or 0 if inp < 10 */ 11019@} 11020@end example 11021 11022@anchor{x86Operandmodifiers} 11023@subsubsection x86 Operand Modifiers 11024 11025References to input, output, and goto operands in the assembler template 11026of extended @code{asm} statements can use 11027modifiers to affect the way the operands are formatted in 11028the code output to the assembler. For example, the 11029following code uses the @samp{h} and @samp{b} modifiers for x86: 11030 11031@example 11032uint16_t num; 11033asm volatile ("xchg %h0, %b0" : "+a" (num) ); 11034@end example 11035 11036@noindent 11037These modifiers generate this assembler code: 11038 11039@example 11040xchg %ah, %al 11041@end example 11042 11043The rest of this discussion uses the following code for illustrative purposes. 11044 11045@example 11046int main() 11047@{ 11048 int iInt = 1; 11049 11050top: 11051 11052 asm volatile goto ("some assembler instructions here" 11053 : /* No outputs. */ 11054 : "q" (iInt), "X" (sizeof(unsigned char) + 1), "i" (42) 11055 : /* No clobbers. */ 11056 : top); 11057@} 11058@end example 11059 11060With no modifiers, this is what the output from the operands would be 11061for the @samp{att} and @samp{intel} dialects of assembler: 11062 11063@multitable {Operand} {$.L2} {OFFSET FLAT:.L2} 11064@headitem Operand @tab @samp{att} @tab @samp{intel} 11065@item @code{%0} 11066@tab @code{%eax} 11067@tab @code{eax} 11068@item @code{%1} 11069@tab @code{$2} 11070@tab @code{2} 11071@item @code{%3} 11072@tab @code{$.L3} 11073@tab @code{OFFSET FLAT:.L3} 11074@item @code{%4} 11075@tab @code{$8} 11076@tab @code{8} 11077@item @code{%5} 11078@tab @code{%xmm0} 11079@tab @code{xmm0} 11080@item @code{%7} 11081@tab @code{$0} 11082@tab @code{0} 11083@end multitable 11084 11085The table below shows the list of supported modifiers and their effects. 11086 11087@multitable {Modifier} {Print the opcode suffix for the size of th} {Operand} {@samp{att}} {@samp{intel}} 11088@headitem Modifier @tab Description @tab Operand @tab @samp{att} @tab @samp{intel} 11089@item @code{A} 11090@tab Print an absolute memory reference. 11091@tab @code{%A0} 11092@tab @code{*%rax} 11093@tab @code{rax} 11094@item @code{b} 11095@tab Print the QImode name of the register. 11096@tab @code{%b0} 11097@tab @code{%al} 11098@tab @code{al} 11099@item @code{B} 11100@tab print the opcode suffix of b. 11101@tab @code{%B0} 11102@tab @code{b} 11103@tab 11104@item @code{c} 11105@tab Require a constant operand and print the constant expression with no punctuation. 11106@tab @code{%c1} 11107@tab @code{2} 11108@tab @code{2} 11109@item @code{d} 11110@tab print duplicated register operand for AVX instruction. 11111@tab @code{%d5} 11112@tab @code{%xmm0, %xmm0} 11113@tab @code{xmm0, xmm0} 11114@item @code{E} 11115@tab Print the address in Double Integer (DImode) mode (8 bytes) when the target is 64-bit. 11116Otherwise mode is unspecified (VOIDmode). 11117@tab @code{%E1} 11118@tab @code{%(rax)} 11119@tab @code{[rax]} 11120@item @code{g} 11121@tab Print the V16SFmode name of the register. 11122@tab @code{%g0} 11123@tab @code{%zmm0} 11124@tab @code{zmm0} 11125@item @code{h} 11126@tab Print the QImode name for a ``high'' register. 11127@tab @code{%h0} 11128@tab @code{%ah} 11129@tab @code{ah} 11130@item @code{H} 11131@tab Add 8 bytes to an offsettable memory reference. Useful when accessing the 11132high 8 bytes of SSE values. For a memref in (%rax), it generates 11133@tab @code{%H0} 11134@tab @code{8(%rax)} 11135@tab @code{8[rax]} 11136@item @code{k} 11137@tab Print the SImode name of the register. 11138@tab @code{%k0} 11139@tab @code{%eax} 11140@tab @code{eax} 11141@item @code{l} 11142@tab Print the label name with no punctuation. 11143@tab @code{%l3} 11144@tab @code{.L3} 11145@tab @code{.L3} 11146@item @code{L} 11147@tab print the opcode suffix of l. 11148@tab @code{%L0} 11149@tab @code{l} 11150@tab 11151@item @code{N} 11152@tab print maskz. 11153@tab @code{%N7} 11154@tab @code{@{z@}} 11155@tab @code{@{z@}} 11156@item @code{p} 11157@tab Print raw symbol name (without syntax-specific prefixes). 11158@tab @code{%p2} 11159@tab @code{42} 11160@tab @code{42} 11161@item @code{P} 11162@tab If used for a function, print the PLT suffix and generate PIC code. 11163For example, emit @code{foo@@PLT} instead of 'foo' for the function 11164foo(). If used for a constant, drop all syntax-specific prefixes and 11165issue the bare constant. See @code{p} above. 11166@item @code{q} 11167@tab Print the DImode name of the register. 11168@tab @code{%q0} 11169@tab @code{%rax} 11170@tab @code{rax} 11171@item @code{Q} 11172@tab print the opcode suffix of q. 11173@tab @code{%Q0} 11174@tab @code{q} 11175@tab 11176@item @code{R} 11177@tab print embedded rounding and sae. 11178@tab @code{%R4} 11179@tab @code{@{rn-sae@}, } 11180@tab @code{, @{rn-sae@}} 11181@item @code{r} 11182@tab print only sae. 11183@tab @code{%r4} 11184@tab @code{@{sae@}, } 11185@tab @code{, @{sae@}} 11186@item @code{s} 11187@tab print a shift double count, followed by the assemblers argument 11188delimiterprint the opcode suffix of s. 11189@tab @code{%s1} 11190@tab @code{$2, } 11191@tab @code{2, } 11192@item @code{S} 11193@tab print the opcode suffix of s. 11194@tab @code{%S0} 11195@tab @code{s} 11196@tab 11197@item @code{t} 11198@tab print the V8SFmode name of the register. 11199@tab @code{%t5} 11200@tab @code{%ymm0} 11201@tab @code{ymm0} 11202@item @code{T} 11203@tab print the opcode suffix of t. 11204@tab @code{%T0} 11205@tab @code{t} 11206@tab 11207@item @code{V} 11208@tab print naked full integer register name without %. 11209@tab @code{%V0} 11210@tab @code{eax} 11211@tab @code{eax} 11212@item @code{w} 11213@tab Print the HImode name of the register. 11214@tab @code{%w0} 11215@tab @code{%ax} 11216@tab @code{ax} 11217@item @code{W} 11218@tab print the opcode suffix of w. 11219@tab @code{%W0} 11220@tab @code{w} 11221@tab 11222@item @code{x} 11223@tab print the V4SFmode name of the register. 11224@tab @code{%x5} 11225@tab @code{%xmm0} 11226@tab @code{xmm0} 11227@item @code{y} 11228@tab print "st(0)" instead of "st" as a register. 11229@tab @code{%y6} 11230@tab @code{%st(0)} 11231@tab @code{st(0)} 11232@item @code{z} 11233@tab Print the opcode suffix for the size of the current integer operand (one of @code{b}/@code{w}/@code{l}/@code{q}). 11234@tab @code{%z0} 11235@tab @code{l} 11236@tab 11237@item @code{Z} 11238@tab Like @code{z}, with special suffixes for x87 instructions. 11239@end multitable 11240 11241 11242@anchor{x86floatingpointasmoperands} 11243@subsubsection x86 Floating-Point @code{asm} Operands 11244 11245On x86 targets, there are several rules on the usage of stack-like registers 11246in the operands of an @code{asm}. These rules apply only to the operands 11247that are stack-like registers: 11248 11249@enumerate 11250@item 11251Given a set of input registers that die in an @code{asm}, it is 11252necessary to know which are implicitly popped by the @code{asm}, and 11253which must be explicitly popped by GCC@. 11254 11255An input register that is implicitly popped by the @code{asm} must be 11256explicitly clobbered, unless it is constrained to match an 11257output operand. 11258 11259@item 11260For any input register that is implicitly popped by an @code{asm}, it is 11261necessary to know how to adjust the stack to compensate for the pop. 11262If any non-popped input is closer to the top of the reg-stack than 11263the implicitly popped register, it would not be possible to know what the 11264stack looked like---it's not clear how the rest of the stack ``slides 11265up''. 11266 11267All implicitly popped input registers must be closer to the top of 11268the reg-stack than any input that is not implicitly popped. 11269 11270It is possible that if an input dies in an @code{asm}, the compiler might 11271use the input register for an output reload. Consider this example: 11272 11273@smallexample 11274asm ("foo" : "=t" (a) : "f" (b)); 11275@end smallexample 11276 11277@noindent 11278This code says that input @code{b} is not popped by the @code{asm}, and that 11279the @code{asm} pushes a result onto the reg-stack, i.e., the stack is one 11280deeper after the @code{asm} than it was before. But, it is possible that 11281reload may think that it can use the same register for both the input and 11282the output. 11283 11284To prevent this from happening, 11285if any input operand uses the @samp{f} constraint, all output register 11286constraints must use the @samp{&} early-clobber modifier. 11287 11288The example above is correctly written as: 11289 11290@smallexample 11291asm ("foo" : "=&t" (a) : "f" (b)); 11292@end smallexample 11293 11294@item 11295Some operands need to be in particular places on the stack. All 11296output operands fall in this category---GCC has no other way to 11297know which registers the outputs appear in unless you indicate 11298this in the constraints. 11299 11300Output operands must specifically indicate which register an output 11301appears in after an @code{asm}. @samp{=f} is not allowed: the operand 11302constraints must select a class with a single register. 11303 11304@item 11305Output operands may not be ``inserted'' between existing stack registers. 11306Since no 387 opcode uses a read/write operand, all output operands 11307are dead before the @code{asm}, and are pushed by the @code{asm}. 11308It makes no sense to push anywhere but the top of the reg-stack. 11309 11310Output operands must start at the top of the reg-stack: output 11311operands may not ``skip'' a register. 11312 11313@item 11314Some @code{asm} statements may need extra stack space for internal 11315calculations. This can be guaranteed by clobbering stack registers 11316unrelated to the inputs and outputs. 11317 11318@end enumerate 11319 11320This @code{asm} 11321takes one input, which is internally popped, and produces two outputs. 11322 11323@smallexample 11324asm ("fsincos" : "=t" (cos), "=u" (sin) : "0" (inp)); 11325@end smallexample 11326 11327@noindent 11328This @code{asm} takes two inputs, which are popped by the @code{fyl2xp1} opcode, 11329and replaces them with one output. The @code{st(1)} clobber is necessary 11330for the compiler to know that @code{fyl2xp1} pops both inputs. 11331 11332@smallexample 11333asm ("fyl2xp1" : "=t" (result) : "0" (x), "u" (y) : "st(1)"); 11334@end smallexample 11335 11336@anchor{msp430Operandmodifiers} 11337@subsubsection MSP430 Operand Modifiers 11338 11339The list below describes the supported modifiers and their effects for MSP430. 11340 11341@multitable @columnfractions .10 .90 11342@headitem Modifier @tab Description 11343@item @code{A} @tab Select low 16-bits of the constant/register/memory operand. 11344@item @code{B} @tab Select high 16-bits of the constant/register/memory 11345operand. 11346@item @code{C} @tab Select bits 32-47 of the constant/register/memory operand. 11347@item @code{D} @tab Select bits 48-63 of the constant/register/memory operand. 11348@item @code{H} @tab Equivalent to @code{B} (for backwards compatibility). 11349@item @code{I} @tab Print the inverse (logical @code{NOT}) of the constant 11350value. 11351@item @code{J} @tab Print an integer without a @code{#} prefix. 11352@item @code{L} @tab Equivalent to @code{A} (for backwards compatibility). 11353@item @code{O} @tab Offset of the current frame from the top of the stack. 11354@item @code{Q} @tab Use the @code{A} instruction postfix. 11355@item @code{R} @tab Inverse of condition code, for unsigned comparisons. 11356@item @code{W} @tab Subtract 16 from the constant value. 11357@item @code{X} @tab Use the @code{X} instruction postfix. 11358@item @code{Y} @tab Subtract 4 from the constant value. 11359@item @code{Z} @tab Subtract 1 from the constant value. 11360@item @code{b} @tab Append @code{.B}, @code{.W} or @code{.A} to the 11361instruction, depending on the mode. 11362@item @code{d} @tab Offset 1 byte of a memory reference or constant value. 11363@item @code{e} @tab Offset 3 bytes of a memory reference or constant value. 11364@item @code{f} @tab Offset 5 bytes of a memory reference or constant value. 11365@item @code{g} @tab Offset 7 bytes of a memory reference or constant value. 11366@item @code{p} @tab Print the value of 2, raised to the power of the given 11367constant. Used to select the specified bit position. 11368@item @code{r} @tab Inverse of condition code, for signed comparisons. 11369@item @code{x} @tab Equivialent to @code{X}, but only for pointers. 11370@end multitable 11371 11372@lowersections 11373@include md.texi 11374@raisesections 11375 11376@node Asm Labels 11377@subsection Controlling Names Used in Assembler Code 11378@cindex assembler names for identifiers 11379@cindex names used in assembler code 11380@cindex identifiers, names in assembler code 11381 11382You can specify the name to be used in the assembler code for a C 11383function or variable by writing the @code{asm} (or @code{__asm__}) 11384keyword after the declarator. 11385It is up to you to make sure that the assembler names you choose do not 11386conflict with any other assembler symbols, or reference registers. 11387 11388@subsubheading Assembler names for data: 11389 11390This sample shows how to specify the assembler name for data: 11391 11392@smallexample 11393int foo asm ("myfoo") = 2; 11394@end smallexample 11395 11396@noindent 11397This specifies that the name to be used for the variable @code{foo} in 11398the assembler code should be @samp{myfoo} rather than the usual 11399@samp{_foo}. 11400 11401On systems where an underscore is normally prepended to the name of a C 11402variable, this feature allows you to define names for the 11403linker that do not start with an underscore. 11404 11405GCC does not support using this feature with a non-static local variable 11406since such variables do not have assembler names. If you are 11407trying to put the variable in a particular register, see 11408@ref{Explicit Register Variables}. 11409 11410@subsubheading Assembler names for functions: 11411 11412To specify the assembler name for functions, write a declaration for the 11413function before its definition and put @code{asm} there, like this: 11414 11415@smallexample 11416int func (int x, int y) asm ("MYFUNC"); 11417 11418int func (int x, int y) 11419@{ 11420 /* @r{@dots{}} */ 11421@end smallexample 11422 11423@noindent 11424This specifies that the name to be used for the function @code{func} in 11425the assembler code should be @code{MYFUNC}. 11426 11427@node Explicit Register Variables 11428@subsection Variables in Specified Registers 11429@anchor{Explicit Reg Vars} 11430@cindex explicit register variables 11431@cindex variables in specified registers 11432@cindex specified registers 11433 11434GNU C allows you to associate specific hardware registers with C 11435variables. In almost all cases, allowing the compiler to assign 11436registers produces the best code. However under certain unusual 11437circumstances, more precise control over the variable storage is 11438required. 11439 11440Both global and local variables can be associated with a register. The 11441consequences of performing this association are very different between 11442the two, as explained in the sections below. 11443 11444@menu 11445* Global Register Variables:: Variables declared at global scope. 11446* Local Register Variables:: Variables declared within a function. 11447@end menu 11448 11449@node Global Register Variables 11450@subsubsection Defining Global Register Variables 11451@anchor{Global Reg Vars} 11452@cindex global register variables 11453@cindex registers, global variables in 11454@cindex registers, global allocation 11455 11456You can define a global register variable and associate it with a specified 11457register like this: 11458 11459@smallexample 11460register int *foo asm ("r12"); 11461@end smallexample 11462 11463@noindent 11464Here @code{r12} is the name of the register that should be used. Note that 11465this is the same syntax used for defining local register variables, but for 11466a global variable the declaration appears outside a function. The 11467@code{register} keyword is required, and cannot be combined with 11468@code{static}. The register name must be a valid register name for the 11469target platform. 11470 11471Do not use type qualifiers such as @code{const} and @code{volatile}, as 11472the outcome may be contrary to expectations. In particular, using the 11473@code{volatile} qualifier does not fully prevent the compiler from 11474optimizing accesses to the register. 11475 11476Registers are a scarce resource on most systems and allowing the 11477compiler to manage their usage usually results in the best code. However, 11478under special circumstances it can make sense to reserve some globally. 11479For example this may be useful in programs such as programming language 11480interpreters that have a couple of global variables that are accessed 11481very often. 11482 11483After defining a global register variable, for the current compilation 11484unit: 11485 11486@itemize @bullet 11487@item If the register is a call-saved register, call ABI is affected: 11488the register will not be restored in function epilogue sequences after 11489the variable has been assigned. Therefore, functions cannot safely 11490return to callers that assume standard ABI. 11491@item Conversely, if the register is a call-clobbered register, making 11492calls to functions that use standard ABI may lose contents of the variable. 11493Such calls may be created by the compiler even if none are evident in 11494the original program, for example when libgcc functions are used to 11495make up for unavailable instructions. 11496@item Accesses to the variable may be optimized as usual and the register 11497remains available for allocation and use in any computations, provided that 11498observable values of the variable are not affected. 11499@item If the variable is referenced in inline assembly, the type of access 11500must be provided to the compiler via constraints (@pxref{Constraints}). 11501Accesses from basic asms are not supported. 11502@end itemize 11503 11504Note that these points @emph{only} apply to code that is compiled with the 11505definition. The behavior of code that is merely linked in (for example 11506code from libraries) is not affected. 11507 11508If you want to recompile source files that do not actually use your global 11509register variable so they do not use the specified register for any other 11510purpose, you need not actually add the global register declaration to 11511their source code. It suffices to specify the compiler option 11512@option{-ffixed-@var{reg}} (@pxref{Code Gen Options}) to reserve the 11513register. 11514 11515@subsubheading Declaring the variable 11516 11517Global register variables cannot have initial values, because an 11518executable file has no means to supply initial contents for a register. 11519 11520When selecting a register, choose one that is normally saved and 11521restored by function calls on your machine. This ensures that code 11522which is unaware of this reservation (such as library routines) will 11523restore it before returning. 11524 11525On machines with register windows, be sure to choose a global 11526register that is not affected magically by the function call mechanism. 11527 11528@subsubheading Using the variable 11529 11530@cindex @code{qsort}, and global register variables 11531When calling routines that are not aware of the reservation, be 11532cautious if those routines call back into code which uses them. As an 11533example, if you call the system library version of @code{qsort}, it may 11534clobber your registers during execution, but (if you have selected 11535appropriate registers) it will restore them before returning. However 11536it will @emph{not} restore them before calling @code{qsort}'s comparison 11537function. As a result, global values will not reliably be available to 11538the comparison function unless the @code{qsort} function itself is rebuilt. 11539 11540Similarly, it is not safe to access the global register variables from signal 11541handlers or from more than one thread of control. Unless you recompile 11542them specially for the task at hand, the system library routines may 11543temporarily use the register for other things. Furthermore, since the register 11544is not reserved exclusively for the variable, accessing it from handlers of 11545asynchronous signals may observe unrelated temporary values residing in the 11546register. 11547 11548@cindex register variable after @code{longjmp} 11549@cindex global register after @code{longjmp} 11550@cindex value after @code{longjmp} 11551@findex longjmp 11552@findex setjmp 11553On most machines, @code{longjmp} restores to each global register 11554variable the value it had at the time of the @code{setjmp}. On some 11555machines, however, @code{longjmp} does not change the value of global 11556register variables. To be portable, the function that called @code{setjmp} 11557should make other arrangements to save the values of the global register 11558variables, and to restore them in a @code{longjmp}. This way, the same 11559thing happens regardless of what @code{longjmp} does. 11560 11561@node Local Register Variables 11562@subsubsection Specifying Registers for Local Variables 11563@anchor{Local Reg Vars} 11564@cindex local variables, specifying registers 11565@cindex specifying registers for local variables 11566@cindex registers for local variables 11567 11568You can define a local register variable and associate it with a specified 11569register like this: 11570 11571@smallexample 11572register int *foo asm ("r12"); 11573@end smallexample 11574 11575@noindent 11576Here @code{r12} is the name of the register that should be used. Note 11577that this is the same syntax used for defining global register variables, 11578but for a local variable the declaration appears within a function. The 11579@code{register} keyword is required, and cannot be combined with 11580@code{static}. The register name must be a valid register name for the 11581target platform. 11582 11583Do not use type qualifiers such as @code{const} and @code{volatile}, as 11584the outcome may be contrary to expectations. In particular, when the 11585@code{const} qualifier is used, the compiler may substitute the 11586variable with its initializer in @code{asm} statements, which may cause 11587the corresponding operand to appear in a different register. 11588 11589As with global register variables, it is recommended that you choose 11590a register that is normally saved and restored by function calls on your 11591machine, so that calls to library routines will not clobber it. 11592 11593The only supported use for this feature is to specify registers 11594for input and output operands when calling Extended @code{asm} 11595(@pxref{Extended Asm}). This may be necessary if the constraints for a 11596particular machine don't provide sufficient control to select the desired 11597register. To force an operand into a register, create a local variable 11598and specify the register name after the variable's declaration. Then use 11599the local variable for the @code{asm} operand and specify any constraint 11600letter that matches the register: 11601 11602@smallexample 11603register int *p1 asm ("r0") = @dots{}; 11604register int *p2 asm ("r1") = @dots{}; 11605register int *result asm ("r0"); 11606asm ("sysint" : "=r" (result) : "0" (p1), "r" (p2)); 11607@end smallexample 11608 11609@emph{Warning:} In the above example, be aware that a register (for example 11610@code{r0}) can be call-clobbered by subsequent code, including function 11611calls and library calls for arithmetic operators on other variables (for 11612example the initialization of @code{p2}). In this case, use temporary 11613variables for expressions between the register assignments: 11614 11615@smallexample 11616int t1 = @dots{}; 11617register int *p1 asm ("r0") = @dots{}; 11618register int *p2 asm ("r1") = t1; 11619register int *result asm ("r0"); 11620asm ("sysint" : "=r" (result) : "0" (p1), "r" (p2)); 11621@end smallexample 11622 11623Defining a register variable does not reserve the register. Other than 11624when invoking the Extended @code{asm}, the contents of the specified 11625register are not guaranteed. For this reason, the following uses 11626are explicitly @emph{not} supported. If they appear to work, it is only 11627happenstance, and may stop working as intended due to (seemingly) 11628unrelated changes in surrounding code, or even minor changes in the 11629optimization of a future version of gcc: 11630 11631@itemize @bullet 11632@item Passing parameters to or from Basic @code{asm} 11633@item Passing parameters to or from Extended @code{asm} without using input 11634or output operands. 11635@item Passing parameters to or from routines written in assembler (or 11636other languages) using non-standard calling conventions. 11637@end itemize 11638 11639Some developers use Local Register Variables in an attempt to improve 11640gcc's allocation of registers, especially in large functions. In this 11641case the register name is essentially a hint to the register allocator. 11642While in some instances this can generate better code, improvements are 11643subject to the whims of the allocator/optimizers. Since there are no 11644guarantees that your improvements won't be lost, this usage of Local 11645Register Variables is discouraged. 11646 11647On the MIPS platform, there is related use for local register variables 11648with slightly different characteristics (@pxref{MIPS Coprocessors,, 11649Defining coprocessor specifics for MIPS targets, gccint, 11650GNU Compiler Collection (GCC) Internals}). 11651 11652@node Size of an asm 11653@subsection Size of an @code{asm} 11654 11655Some targets require that GCC track the size of each instruction used 11656in order to generate correct code. Because the final length of the 11657code produced by an @code{asm} statement is only known by the 11658assembler, GCC must make an estimate as to how big it will be. It 11659does this by counting the number of instructions in the pattern of the 11660@code{asm} and multiplying that by the length of the longest 11661instruction supported by that processor. (When working out the number 11662of instructions, it assumes that any occurrence of a newline or of 11663whatever statement separator character is supported by the assembler --- 11664typically @samp{;} --- indicates the end of an instruction.) 11665 11666Normally, GCC's estimate is adequate to ensure that correct 11667code is generated, but it is possible to confuse the compiler if you use 11668pseudo instructions or assembler macros that expand into multiple real 11669instructions, or if you use assembler directives that expand to more 11670space in the object file than is needed for a single instruction. 11671If this happens then the assembler may produce a diagnostic saying that 11672a label is unreachable. 11673 11674@cindex @code{asm inline} 11675This size is also used for inlining decisions. If you use @code{asm inline} 11676instead of just @code{asm}, then for inlining purposes the size of the asm 11677is taken as the minimum size, ignoring how many instructions GCC thinks it is. 11678 11679@node Alternate Keywords 11680@section Alternate Keywords 11681@cindex alternate keywords 11682@cindex keywords, alternate 11683 11684@option{-ansi} and the various @option{-std} options disable certain 11685keywords. This causes trouble when you want to use GNU C extensions, or 11686a general-purpose header file that should be usable by all programs, 11687including ISO C programs. The keywords @code{asm}, @code{typeof} and 11688@code{inline} are not available in programs compiled with 11689@option{-ansi} or @option{-std} (although @code{inline} can be used in a 11690program compiled with @option{-std=c99} or a later standard). The 11691ISO C99 keyword 11692@code{restrict} is only available when @option{-std=gnu99} (which will 11693eventually be the default) or @option{-std=c99} (or the equivalent 11694@option{-std=iso9899:1999}), or an option for a later standard 11695version, is used. 11696 11697The way to solve these problems is to put @samp{__} at the beginning and 11698end of each problematical keyword. For example, use @code{__asm__} 11699instead of @code{asm}, and @code{__inline__} instead of @code{inline}. 11700 11701Other C compilers won't accept these alternative keywords; if you want to 11702compile with another compiler, you can define the alternate keywords as 11703macros to replace them with the customary keywords. It looks like this: 11704 11705@smallexample 11706#ifndef __GNUC__ 11707#define __asm__ asm 11708#endif 11709@end smallexample 11710 11711@findex __extension__ 11712@opindex pedantic 11713@option{-pedantic} and other options cause warnings for many GNU C extensions. 11714You can 11715prevent such warnings within one expression by writing 11716@code{__extension__} before the expression. @code{__extension__} has no 11717effect aside from this. 11718 11719@node Incomplete Enums 11720@section Incomplete @code{enum} Types 11721 11722You can define an @code{enum} tag without specifying its possible values. 11723This results in an incomplete type, much like what you get if you write 11724@code{struct foo} without describing the elements. A later declaration 11725that does specify the possible values completes the type. 11726 11727You cannot allocate variables or storage using the type while it is 11728incomplete. However, you can work with pointers to that type. 11729 11730This extension may not be very useful, but it makes the handling of 11731@code{enum} more consistent with the way @code{struct} and @code{union} 11732are handled. 11733 11734This extension is not supported by GNU C++. 11735 11736@node Function Names 11737@section Function Names as Strings 11738@cindex @code{__func__} identifier 11739@cindex @code{__FUNCTION__} identifier 11740@cindex @code{__PRETTY_FUNCTION__} identifier 11741 11742GCC provides three magic constants that hold the name of the current 11743function as a string. In C++11 and later modes, all three are treated 11744as constant expressions and can be used in @code{constexpr} constexts. 11745The first of these constants is @code{__func__}, which is part of 11746the C99 standard: 11747 11748The identifier @code{__func__} is implicitly declared by the translator 11749as if, immediately following the opening brace of each function 11750definition, the declaration 11751 11752@smallexample 11753static const char __func__[] = "function-name"; 11754@end smallexample 11755 11756@noindent 11757appeared, where function-name is the name of the lexically-enclosing 11758function. This name is the unadorned name of the function. As an 11759extension, at file (or, in C++, namespace scope), @code{__func__} 11760evaluates to the empty string. 11761 11762@code{__FUNCTION__} is another name for @code{__func__}, provided for 11763backward compatibility with old versions of GCC. 11764 11765In C, @code{__PRETTY_FUNCTION__} is yet another name for 11766@code{__func__}, except that at file scope (or, in C++, namespace scope), 11767it evaluates to the string @code{"top level"}. In addition, in C++, 11768@code{__PRETTY_FUNCTION__} contains the signature of the function as 11769well as its bare name. For example, this program: 11770 11771@smallexample 11772extern "C" int printf (const char *, ...); 11773 11774class a @{ 11775 public: 11776 void sub (int i) 11777 @{ 11778 printf ("__FUNCTION__ = %s\n", __FUNCTION__); 11779 printf ("__PRETTY_FUNCTION__ = %s\n", __PRETTY_FUNCTION__); 11780 @} 11781@}; 11782 11783int 11784main (void) 11785@{ 11786 a ax; 11787 ax.sub (0); 11788 return 0; 11789@} 11790@end smallexample 11791 11792@noindent 11793gives this output: 11794 11795@smallexample 11796__FUNCTION__ = sub 11797__PRETTY_FUNCTION__ = void a::sub(int) 11798@end smallexample 11799 11800These identifiers are variables, not preprocessor macros, and may not 11801be used to initialize @code{char} arrays or be concatenated with string 11802literals. 11803 11804@node Return Address 11805@section Getting the Return or Frame Address of a Function 11806 11807These functions may be used to get information about the callers of a 11808function. 11809 11810@deftypefn {Built-in Function} {void *} __builtin_return_address (unsigned int @var{level}) 11811This function returns the return address of the current function, or of 11812one of its callers. The @var{level} argument is number of frames to 11813scan up the call stack. A value of @code{0} yields the return address 11814of the current function, a value of @code{1} yields the return address 11815of the caller of the current function, and so forth. When inlining 11816the expected behavior is that the function returns the address of 11817the function that is returned to. To work around this behavior use 11818the @code{noinline} function attribute. 11819 11820The @var{level} argument must be a constant integer. 11821 11822On some machines it may be impossible to determine the return address of 11823any function other than the current one; in such cases, or when the top 11824of the stack has been reached, this function returns an unspecified 11825value. In addition, @code{__builtin_frame_address} may be used 11826to determine if the top of the stack has been reached. 11827 11828Additional post-processing of the returned value may be needed, see 11829@code{__builtin_extract_return_addr}. 11830 11831The stored representation of the return address in memory may be different 11832from the address returned by @code{__builtin_return_address}. For example, 11833on AArch64 the stored address may be mangled with return address signing 11834whereas the address returned by @code{__builtin_return_address} is not. 11835 11836Calling this function with a nonzero argument can have unpredictable 11837effects, including crashing the calling program. As a result, calls 11838that are considered unsafe are diagnosed when the @option{-Wframe-address} 11839option is in effect. Such calls should only be made in debugging 11840situations. 11841 11842On targets where code addresses are representable as @code{void *}, 11843@smallexample 11844void *addr = __builtin_extract_return_addr (__builtin_return_address (0)); 11845@end smallexample 11846gives the code address where the current function would return. For example, 11847such an address may be used with @code{dladdr} or other interfaces that work 11848with code addresses. 11849@end deftypefn 11850 11851@deftypefn {Built-in Function} {void *} __builtin_extract_return_addr (void *@var{addr}) 11852The address as returned by @code{__builtin_return_address} may have to be fed 11853through this function to get the actual encoded address. For example, on the 1185431-bit S/390 platform the highest bit has to be masked out, or on SPARC 11855platforms an offset has to be added for the true next instruction to be 11856executed. 11857 11858If no fixup is needed, this function simply passes through @var{addr}. 11859@end deftypefn 11860 11861@deftypefn {Built-in Function} {void *} __builtin_frob_return_addr (void *@var{addr}) 11862This function does the reverse of @code{__builtin_extract_return_addr}. 11863@end deftypefn 11864 11865@deftypefn {Built-in Function} {void *} __builtin_frame_address (unsigned int @var{level}) 11866This function is similar to @code{__builtin_return_address}, but it 11867returns the address of the function frame rather than the return address 11868of the function. Calling @code{__builtin_frame_address} with a value of 11869@code{0} yields the frame address of the current function, a value of 11870@code{1} yields the frame address of the caller of the current function, 11871and so forth. 11872 11873The frame is the area on the stack that holds local variables and saved 11874registers. The frame address is normally the address of the first word 11875pushed on to the stack by the function. However, the exact definition 11876depends upon the processor and the calling convention. If the processor 11877has a dedicated frame pointer register, and the function has a frame, 11878then @code{__builtin_frame_address} returns the value of the frame 11879pointer register. 11880 11881On some machines it may be impossible to determine the frame address of 11882any function other than the current one; in such cases, or when the top 11883of the stack has been reached, this function returns @code{0} if 11884the first frame pointer is properly initialized by the startup code. 11885 11886Calling this function with a nonzero argument can have unpredictable 11887effects, including crashing the calling program. As a result, calls 11888that are considered unsafe are diagnosed when the @option{-Wframe-address} 11889option is in effect. Such calls should only be made in debugging 11890situations. 11891@end deftypefn 11892 11893@node Vector Extensions 11894@section Using Vector Instructions through Built-in Functions 11895 11896On some targets, the instruction set contains SIMD vector instructions which 11897operate on multiple values contained in one large register at the same time. 11898For example, on the x86 the MMX, 3DNow!@: and SSE extensions can be used 11899this way. 11900 11901The first step in using these extensions is to provide the necessary data 11902types. This should be done using an appropriate @code{typedef}: 11903 11904@smallexample 11905typedef int v4si __attribute__ ((vector_size (16))); 11906@end smallexample 11907 11908@noindent 11909The @code{int} type specifies the @dfn{base type}, while the attribute specifies 11910the vector size for the variable, measured in bytes. For example, the 11911declaration above causes the compiler to set the mode for the @code{v4si} 11912type to be 16 bytes wide and divided into @code{int} sized units. For 11913a 32-bit @code{int} this means a vector of 4 units of 4 bytes, and the 11914corresponding mode of @code{foo} is @acronym{V4SI}. 11915 11916The @code{vector_size} attribute is only applicable to integral and 11917floating scalars, although arrays, pointers, and function return values 11918are allowed in conjunction with this construct. Only sizes that are 11919positive power-of-two multiples of the base type size are currently allowed. 11920 11921All the basic integer types can be used as base types, both as signed 11922and as unsigned: @code{char}, @code{short}, @code{int}, @code{long}, 11923@code{long long}. In addition, @code{float} and @code{double} can be 11924used to build floating-point vector types. 11925 11926Specifying a combination that is not valid for the current architecture 11927causes GCC to synthesize the instructions using a narrower mode. 11928For example, if you specify a variable of type @code{V4SI} and your 11929architecture does not allow for this specific SIMD type, GCC 11930produces code that uses 4 @code{SIs}. 11931 11932The types defined in this manner can be used with a subset of normal C 11933operations. Currently, GCC allows using the following operators 11934on these types: @code{+, -, *, /, unary minus, ^, |, &, ~, %}@. 11935 11936The operations behave like C++ @code{valarrays}. Addition is defined as 11937the addition of the corresponding elements of the operands. For 11938example, in the code below, each of the 4 elements in @var{a} is 11939added to the corresponding 4 elements in @var{b} and the resulting 11940vector is stored in @var{c}. 11941 11942@smallexample 11943typedef int v4si __attribute__ ((vector_size (16))); 11944 11945v4si a, b, c; 11946 11947c = a + b; 11948@end smallexample 11949 11950Subtraction, multiplication, division, and the logical operations 11951operate in a similar manner. Likewise, the result of using the unary 11952minus or complement operators on a vector type is a vector whose 11953elements are the negative or complemented values of the corresponding 11954elements in the operand. 11955 11956It is possible to use shifting operators @code{<<}, @code{>>} on 11957integer-type vectors. The operation is defined as following: @code{@{a0, 11958a1, @dots{}, an@} >> @{b0, b1, @dots{}, bn@} == @{a0 >> b0, a1 >> b1, 11959@dots{}, an >> bn@}}@. Vector operands must have the same number of 11960elements. 11961 11962For convenience, it is allowed to use a binary vector operation 11963where one operand is a scalar. In that case the compiler transforms 11964the scalar operand into a vector where each element is the scalar from 11965the operation. The transformation happens only if the scalar could be 11966safely converted to the vector-element type. 11967Consider the following code. 11968 11969@smallexample 11970typedef int v4si __attribute__ ((vector_size (16))); 11971 11972v4si a, b, c; 11973long l; 11974 11975a = b + 1; /* a = b + @{1,1,1,1@}; */ 11976a = 2 * b; /* a = @{2,2,2,2@} * b; */ 11977 11978a = l + a; /* Error, cannot convert long to int. */ 11979@end smallexample 11980 11981Vectors can be subscripted as if the vector were an array with 11982the same number of elements and base type. Out of bound accesses 11983invoke undefined behavior at run time. Warnings for out of bound 11984accesses for vector subscription can be enabled with 11985@option{-Warray-bounds}. 11986 11987Vector comparison is supported with standard comparison 11988operators: @code{==, !=, <, <=, >, >=}. Comparison operands can be 11989vector expressions of integer-type or real-type. Comparison between 11990integer-type vectors and real-type vectors are not supported. The 11991result of the comparison is a vector of the same width and number of 11992elements as the comparison operands with a signed integral element 11993type. 11994 11995Vectors are compared element-wise producing 0 when comparison is false 11996and -1 (constant of the appropriate type where all bits are set) 11997otherwise. Consider the following example. 11998 11999@smallexample 12000typedef int v4si __attribute__ ((vector_size (16))); 12001 12002v4si a = @{1,2,3,4@}; 12003v4si b = @{3,2,1,4@}; 12004v4si c; 12005 12006c = a > b; /* The result would be @{0, 0,-1, 0@} */ 12007c = a == b; /* The result would be @{0,-1, 0,-1@} */ 12008@end smallexample 12009 12010In C++, the ternary operator @code{?:} is available. @code{a?b:c}, where 12011@code{b} and @code{c} are vectors of the same type and @code{a} is an 12012integer vector with the same number of elements of the same size as @code{b} 12013and @code{c}, computes all three arguments and creates a vector 12014@code{@{a[0]?b[0]:c[0], a[1]?b[1]:c[1], @dots{}@}}. Note that unlike in 12015OpenCL, @code{a} is thus interpreted as @code{a != 0} and not @code{a < 0}. 12016As in the case of binary operations, this syntax is also accepted when 12017one of @code{b} or @code{c} is a scalar that is then transformed into a 12018vector. If both @code{b} and @code{c} are scalars and the type of 12019@code{true?b:c} has the same size as the element type of @code{a}, then 12020@code{b} and @code{c} are converted to a vector type whose elements have 12021this type and with the same number of elements as @code{a}. 12022 12023In C++, the logic operators @code{!, &&, ||} are available for vectors. 12024@code{!v} is equivalent to @code{v == 0}, @code{a && b} is equivalent to 12025@code{a!=0 & b!=0} and @code{a || b} is equivalent to @code{a!=0 | b!=0}. 12026For mixed operations between a scalar @code{s} and a vector @code{v}, 12027@code{s && v} is equivalent to @code{s?v!=0:0} (the evaluation is 12028short-circuit) and @code{v && s} is equivalent to @code{v!=0 & (s?-1:0)}. 12029 12030@findex __builtin_shuffle 12031Vector shuffling is available using functions 12032@code{__builtin_shuffle (vec, mask)} and 12033@code{__builtin_shuffle (vec0, vec1, mask)}. 12034Both functions construct a permutation of elements from one or two 12035vectors and return a vector of the same type as the input vector(s). 12036The @var{mask} is an integral vector with the same width (@var{W}) 12037and element count (@var{N}) as the output vector. 12038 12039The elements of the input vectors are numbered in memory ordering of 12040@var{vec0} beginning at 0 and @var{vec1} beginning at @var{N}. The 12041elements of @var{mask} are considered modulo @var{N} in the single-operand 12042case and modulo @math{2*@var{N}} in the two-operand case. 12043 12044Consider the following example, 12045 12046@smallexample 12047typedef int v4si __attribute__ ((vector_size (16))); 12048 12049v4si a = @{1,2,3,4@}; 12050v4si b = @{5,6,7,8@}; 12051v4si mask1 = @{0,1,1,3@}; 12052v4si mask2 = @{0,4,2,5@}; 12053v4si res; 12054 12055res = __builtin_shuffle (a, mask1); /* res is @{1,2,2,4@} */ 12056res = __builtin_shuffle (a, b, mask2); /* res is @{1,5,3,6@} */ 12057@end smallexample 12058 12059Note that @code{__builtin_shuffle} is intentionally semantically 12060compatible with the OpenCL @code{shuffle} and @code{shuffle2} functions. 12061 12062You can declare variables and use them in function calls and returns, as 12063well as in assignments and some casts. You can specify a vector type as 12064a return type for a function. Vector types can also be used as function 12065arguments. It is possible to cast from one vector type to another, 12066provided they are of the same size (in fact, you can also cast vectors 12067to and from other datatypes of the same size). 12068 12069You cannot operate between vectors of different lengths or different 12070signedness without a cast. 12071 12072@findex __builtin_shufflevector 12073Vector shuffling is available using the 12074@code{__builtin_shufflevector (vec1, vec2, index...)} 12075function. @var{vec1} and @var{vec2} must be expressions with 12076vector type with a compatible element type. The result of 12077@code{__builtin_shufflevector} is a vector with the same element type 12078as @var{vec1} and @var{vec2} but that has an element count equal to 12079the number of indices specified. 12080 12081The @var{index} arguments are a list of integers that specify the 12082elements indices of the first two vectors that should be extracted and 12083returned in a new vector. These element indices are numbered sequentially 12084starting with the first vector, continuing into the second vector. 12085An index of -1 can be used to indicate that the corresponding element in 12086the returned vector is a don't care and can be freely chosen to optimized 12087the generated code sequence performing the shuffle operation. 12088 12089Consider the following example, 12090@smallexample 12091typedef int v4si __attribute__ ((vector_size (16))); 12092typedef int v8si __attribute__ ((vector_size (32))); 12093 12094v8si a = @{1,-2,3,-4,5,-6,7,-8@}; 12095v4si b = __builtin_shufflevector (a, a, 0, 2, 4, 6); /* b is @{1,3,5,7@} */ 12096v4si c = @{-2,-4,-6,-8@}; 12097v8si d = __builtin_shufflevector (c, b, 4, 0, 5, 1, 6, 2, 7, 3); /* d is a */ 12098@end smallexample 12099 12100@findex __builtin_convertvector 12101Vector conversion is available using the 12102@code{__builtin_convertvector (vec, vectype)} 12103function. @var{vec} must be an expression with integral or floating 12104vector type and @var{vectype} an integral or floating vector type with the 12105same number of elements. The result has @var{vectype} type and value of 12106a C cast of every element of @var{vec} to the element type of @var{vectype}. 12107 12108Consider the following example, 12109@smallexample 12110typedef int v4si __attribute__ ((vector_size (16))); 12111typedef float v4sf __attribute__ ((vector_size (16))); 12112typedef double v4df __attribute__ ((vector_size (32))); 12113typedef unsigned long long v4di __attribute__ ((vector_size (32))); 12114 12115v4si a = @{1,-2,3,-4@}; 12116v4sf b = @{1.5f,-2.5f,3.f,7.f@}; 12117v4di c = @{1ULL,5ULL,0ULL,10ULL@}; 12118v4sf d = __builtin_convertvector (a, v4sf); /* d is @{1.f,-2.f,3.f,-4.f@} */ 12119/* Equivalent of: 12120 v4sf d = @{ (float)a[0], (float)a[1], (float)a[2], (float)a[3] @}; */ 12121v4df e = __builtin_convertvector (a, v4df); /* e is @{1.,-2.,3.,-4.@} */ 12122v4df f = __builtin_convertvector (b, v4df); /* f is @{1.5,-2.5,3.,7.@} */ 12123v4si g = __builtin_convertvector (f, v4si); /* g is @{1,-2,3,7@} */ 12124v4si h = __builtin_convertvector (c, v4si); /* h is @{1,5,0,10@} */ 12125@end smallexample 12126 12127@cindex vector types, using with x86 intrinsics 12128Sometimes it is desirable to write code using a mix of generic vector 12129operations (for clarity) and machine-specific vector intrinsics (to 12130access vector instructions that are not exposed via generic built-ins). 12131On x86, intrinsic functions for integer vectors typically use the same 12132vector type @code{__m128i} irrespective of how they interpret the vector, 12133making it necessary to cast their arguments and return values from/to 12134other vector types. In C, you can make use of a @code{union} type: 12135@c In C++ such type punning via a union is not allowed by the language 12136@smallexample 12137#include <immintrin.h> 12138 12139typedef unsigned char u8x16 __attribute__ ((vector_size (16))); 12140typedef unsigned int u32x4 __attribute__ ((vector_size (16))); 12141 12142typedef union @{ 12143 __m128i mm; 12144 u8x16 u8; 12145 u32x4 u32; 12146@} v128; 12147@end smallexample 12148 12149@noindent 12150for variables that can be used with both built-in operators and x86 12151intrinsics: 12152 12153@smallexample 12154v128 x, y = @{ 0 @}; 12155memcpy (&x, ptr, sizeof x); 12156y.u8 += 0x80; 12157x.mm = _mm_adds_epu8 (x.mm, y.mm); 12158x.u32 &= 0xffffff; 12159 12160/* Instead of a variable, a compound literal may be used to pass the 12161 return value of an intrinsic call to a function expecting the union: */ 12162v128 foo (v128); 12163x = foo ((v128) @{_mm_adds_epu8 (x.mm, y.mm)@}); 12164@c This could be done implicitly with __attribute__((transparent_union)), 12165@c but GCC does not accept it for unions of vector types (PR 88955). 12166@end smallexample 12167 12168@node Offsetof 12169@section Support for @code{offsetof} 12170@findex __builtin_offsetof 12171 12172GCC implements for both C and C++ a syntactic extension to implement 12173the @code{offsetof} macro. 12174 12175@smallexample 12176primary: 12177 "__builtin_offsetof" "(" @code{typename} "," offsetof_member_designator ")" 12178 12179offsetof_member_designator: 12180 @code{identifier} 12181 | offsetof_member_designator "." @code{identifier} 12182 | offsetof_member_designator "[" @code{expr} "]" 12183@end smallexample 12184 12185This extension is sufficient such that 12186 12187@smallexample 12188#define offsetof(@var{type}, @var{member}) __builtin_offsetof (@var{type}, @var{member}) 12189@end smallexample 12190 12191@noindent 12192is a suitable definition of the @code{offsetof} macro. In C++, @var{type} 12193may be dependent. In either case, @var{member} may consist of a single 12194identifier, or a sequence of member accesses and array references. 12195 12196@node __sync Builtins 12197@section Legacy @code{__sync} Built-in Functions for Atomic Memory Access 12198 12199The following built-in functions 12200are intended to be compatible with those described 12201in the @cite{Intel Itanium Processor-specific Application Binary Interface}, 12202section 7.4. As such, they depart from normal GCC practice by not using 12203the @samp{__builtin_} prefix and also by being overloaded so that they 12204work on multiple types. 12205 12206The definition given in the Intel documentation allows only for the use of 12207the types @code{int}, @code{long}, @code{long long} or their unsigned 12208counterparts. GCC allows any scalar type that is 1, 2, 4 or 8 bytes in 12209size other than the C type @code{_Bool} or the C++ type @code{bool}. 12210Operations on pointer arguments are performed as if the operands were 12211of the @code{uintptr_t} type. That is, they are not scaled by the size 12212of the type to which the pointer points. 12213 12214These functions are implemented in terms of the @samp{__atomic} 12215builtins (@pxref{__atomic Builtins}). They should not be used for new 12216code which should use the @samp{__atomic} builtins instead. 12217 12218Not all operations are supported by all target processors. If a particular 12219operation cannot be implemented on the target processor, a warning is 12220generated and a call to an external function is generated. The external 12221function carries the same name as the built-in version, 12222with an additional suffix 12223@samp{_@var{n}} where @var{n} is the size of the data type. 12224 12225@c ??? Should we have a mechanism to suppress this warning? This is almost 12226@c useful for implementing the operation under the control of an external 12227@c mutex. 12228 12229In most cases, these built-in functions are considered a @dfn{full barrier}. 12230That is, 12231no memory operand is moved across the operation, either forward or 12232backward. Further, instructions are issued as necessary to prevent the 12233processor from speculating loads across the operation and from queuing stores 12234after the operation. 12235 12236All of the routines are described in the Intel documentation to take 12237``an optional list of variables protected by the memory barrier''. It's 12238not clear what is meant by that; it could mean that @emph{only} the 12239listed variables are protected, or it could mean a list of additional 12240variables to be protected. The list is ignored by GCC which treats it as 12241empty. GCC interprets an empty list as meaning that all globally 12242accessible variables should be protected. 12243 12244@table @code 12245@item @var{type} __sync_fetch_and_add (@var{type} *ptr, @var{type} value, ...) 12246@itemx @var{type} __sync_fetch_and_sub (@var{type} *ptr, @var{type} value, ...) 12247@itemx @var{type} __sync_fetch_and_or (@var{type} *ptr, @var{type} value, ...) 12248@itemx @var{type} __sync_fetch_and_and (@var{type} *ptr, @var{type} value, ...) 12249@itemx @var{type} __sync_fetch_and_xor (@var{type} *ptr, @var{type} value, ...) 12250@itemx @var{type} __sync_fetch_and_nand (@var{type} *ptr, @var{type} value, ...) 12251@findex __sync_fetch_and_add 12252@findex __sync_fetch_and_sub 12253@findex __sync_fetch_and_or 12254@findex __sync_fetch_and_and 12255@findex __sync_fetch_and_xor 12256@findex __sync_fetch_and_nand 12257These built-in functions perform the operation suggested by the name, and 12258returns the value that had previously been in memory. That is, operations 12259on integer operands have the following semantics. Operations on pointer 12260arguments are performed as if the operands were of the @code{uintptr_t} 12261type. That is, they are not scaled by the size of the type to which 12262the pointer points. 12263 12264@smallexample 12265@{ tmp = *ptr; *ptr @var{op}= value; return tmp; @} 12266@{ tmp = *ptr; *ptr = ~(tmp & value); return tmp; @} // nand 12267@end smallexample 12268 12269The object pointed to by the first argument must be of integer or pointer 12270type. It must not be a boolean type. 12271 12272@emph{Note:} GCC 4.4 and later implement @code{__sync_fetch_and_nand} 12273as @code{*ptr = ~(tmp & value)} instead of @code{*ptr = ~tmp & value}. 12274 12275@item @var{type} __sync_add_and_fetch (@var{type} *ptr, @var{type} value, ...) 12276@itemx @var{type} __sync_sub_and_fetch (@var{type} *ptr, @var{type} value, ...) 12277@itemx @var{type} __sync_or_and_fetch (@var{type} *ptr, @var{type} value, ...) 12278@itemx @var{type} __sync_and_and_fetch (@var{type} *ptr, @var{type} value, ...) 12279@itemx @var{type} __sync_xor_and_fetch (@var{type} *ptr, @var{type} value, ...) 12280@itemx @var{type} __sync_nand_and_fetch (@var{type} *ptr, @var{type} value, ...) 12281@findex __sync_add_and_fetch 12282@findex __sync_sub_and_fetch 12283@findex __sync_or_and_fetch 12284@findex __sync_and_and_fetch 12285@findex __sync_xor_and_fetch 12286@findex __sync_nand_and_fetch 12287These built-in functions perform the operation suggested by the name, and 12288return the new value. That is, operations on integer operands have 12289the following semantics. Operations on pointer operands are performed as 12290if the operand's type were @code{uintptr_t}. 12291 12292@smallexample 12293@{ *ptr @var{op}= value; return *ptr; @} 12294@{ *ptr = ~(*ptr & value); return *ptr; @} // nand 12295@end smallexample 12296 12297The same constraints on arguments apply as for the corresponding 12298@code{__sync_op_and_fetch} built-in functions. 12299 12300@emph{Note:} GCC 4.4 and later implement @code{__sync_nand_and_fetch} 12301as @code{*ptr = ~(*ptr & value)} instead of 12302@code{*ptr = ~*ptr & value}. 12303 12304@item bool __sync_bool_compare_and_swap (@var{type} *ptr, @var{type} oldval, @var{type} newval, ...) 12305@itemx @var{type} __sync_val_compare_and_swap (@var{type} *ptr, @var{type} oldval, @var{type} newval, ...) 12306@findex __sync_bool_compare_and_swap 12307@findex __sync_val_compare_and_swap 12308These built-in functions perform an atomic compare and swap. 12309That is, if the current 12310value of @code{*@var{ptr}} is @var{oldval}, then write @var{newval} into 12311@code{*@var{ptr}}. 12312 12313The ``bool'' version returns @code{true} if the comparison is successful and 12314@var{newval} is written. The ``val'' version returns the contents 12315of @code{*@var{ptr}} before the operation. 12316 12317@item __sync_synchronize (...) 12318@findex __sync_synchronize 12319This built-in function issues a full memory barrier. 12320 12321@item @var{type} __sync_lock_test_and_set (@var{type} *ptr, @var{type} value, ...) 12322@findex __sync_lock_test_and_set 12323This built-in function, as described by Intel, is not a traditional test-and-set 12324operation, but rather an atomic exchange operation. It writes @var{value} 12325into @code{*@var{ptr}}, and returns the previous contents of 12326@code{*@var{ptr}}. 12327 12328Many targets have only minimal support for such locks, and do not support 12329a full exchange operation. In this case, a target may support reduced 12330functionality here by which the @emph{only} valid value to store is the 12331immediate constant 1. The exact value actually stored in @code{*@var{ptr}} 12332is implementation defined. 12333 12334This built-in function is not a full barrier, 12335but rather an @dfn{acquire barrier}. 12336This means that references after the operation cannot move to (or be 12337speculated to) before the operation, but previous memory stores may not 12338be globally visible yet, and previous memory loads may not yet be 12339satisfied. 12340 12341@item void __sync_lock_release (@var{type} *ptr, ...) 12342@findex __sync_lock_release 12343This built-in function releases the lock acquired by 12344@code{__sync_lock_test_and_set}. 12345Normally this means writing the constant 0 to @code{*@var{ptr}}. 12346 12347This built-in function is not a full barrier, 12348but rather a @dfn{release barrier}. 12349This means that all previous memory stores are globally visible, and all 12350previous memory loads have been satisfied, but following memory reads 12351are not prevented from being speculated to before the barrier. 12352@end table 12353 12354@node __atomic Builtins 12355@section Built-in Functions for Memory Model Aware Atomic Operations 12356 12357The following built-in functions approximately match the requirements 12358for the C++11 memory model. They are all 12359identified by being prefixed with @samp{__atomic} and most are 12360overloaded so that they work with multiple types. 12361 12362These functions are intended to replace the legacy @samp{__sync} 12363builtins. The main difference is that the memory order that is requested 12364is a parameter to the functions. New code should always use the 12365@samp{__atomic} builtins rather than the @samp{__sync} builtins. 12366 12367Note that the @samp{__atomic} builtins assume that programs will 12368conform to the C++11 memory model. In particular, they assume 12369that programs are free of data races. See the C++11 standard for 12370detailed requirements. 12371 12372The @samp{__atomic} builtins can be used with any integral scalar or 12373pointer type that is 1, 2, 4, or 8 bytes in length. 16-byte integral 12374types are also allowed if @samp{__int128} (@pxref{__int128}) is 12375supported by the architecture. 12376 12377The four non-arithmetic functions (load, store, exchange, and 12378compare_exchange) all have a generic version as well. This generic 12379version works on any data type. It uses the lock-free built-in function 12380if the specific data type size makes that possible; otherwise, an 12381external call is left to be resolved at run time. This external call is 12382the same format with the addition of a @samp{size_t} parameter inserted 12383as the first parameter indicating the size of the object being pointed to. 12384All objects must be the same size. 12385 12386There are 6 different memory orders that can be specified. These map 12387to the C++11 memory orders with the same names, see the C++11 standard 12388or the @uref{https://gcc.gnu.org/wiki/Atomic/GCCMM/AtomicSync,GCC wiki 12389on atomic synchronization} for detailed definitions. Individual 12390targets may also support additional memory orders for use on specific 12391architectures. Refer to the target documentation for details of 12392these. 12393 12394An atomic operation can both constrain code motion and 12395be mapped to hardware instructions for synchronization between threads 12396(e.g., a fence). To which extent this happens is controlled by the 12397memory orders, which are listed here in approximately ascending order of 12398strength. The description of each memory order is only meant to roughly 12399illustrate the effects and is not a specification; see the C++11 12400memory model for precise semantics. 12401 12402@table @code 12403@item __ATOMIC_RELAXED 12404Implies no inter-thread ordering constraints. 12405@item __ATOMIC_CONSUME 12406This is currently implemented using the stronger @code{__ATOMIC_ACQUIRE} 12407memory order because of a deficiency in C++11's semantics for 12408@code{memory_order_consume}. 12409@item __ATOMIC_ACQUIRE 12410Creates an inter-thread happens-before constraint from the release (or 12411stronger) semantic store to this acquire load. Can prevent hoisting 12412of code to before the operation. 12413@item __ATOMIC_RELEASE 12414Creates an inter-thread happens-before constraint to acquire (or stronger) 12415semantic loads that read from this release store. Can prevent sinking 12416of code to after the operation. 12417@item __ATOMIC_ACQ_REL 12418Combines the effects of both @code{__ATOMIC_ACQUIRE} and 12419@code{__ATOMIC_RELEASE}. 12420@item __ATOMIC_SEQ_CST 12421Enforces total ordering with all other @code{__ATOMIC_SEQ_CST} operations. 12422@end table 12423 12424Note that in the C++11 memory model, @emph{fences} (e.g., 12425@samp{__atomic_thread_fence}) take effect in combination with other 12426atomic operations on specific memory locations (e.g., atomic loads); 12427operations on specific memory locations do not necessarily affect other 12428operations in the same way. 12429 12430Target architectures are encouraged to provide their own patterns for 12431each of the atomic built-in functions. If no target is provided, the original 12432non-memory model set of @samp{__sync} atomic built-in functions are 12433used, along with any required synchronization fences surrounding it in 12434order to achieve the proper behavior. Execution in this case is subject 12435to the same restrictions as those built-in functions. 12436 12437If there is no pattern or mechanism to provide a lock-free instruction 12438sequence, a call is made to an external routine with the same parameters 12439to be resolved at run time. 12440 12441When implementing patterns for these built-in functions, the memory order 12442parameter can be ignored as long as the pattern implements the most 12443restrictive @code{__ATOMIC_SEQ_CST} memory order. Any of the other memory 12444orders execute correctly with this memory order but they may not execute as 12445efficiently as they could with a more appropriate implementation of the 12446relaxed requirements. 12447 12448Note that the C++11 standard allows for the memory order parameter to be 12449determined at run time rather than at compile time. These built-in 12450functions map any run-time value to @code{__ATOMIC_SEQ_CST} rather 12451than invoke a runtime library call or inline a switch statement. This is 12452standard compliant, safe, and the simplest approach for now. 12453 12454The memory order parameter is a signed int, but only the lower 16 bits are 12455reserved for the memory order. The remainder of the signed int is reserved 12456for target use and should be 0. Use of the predefined atomic values 12457ensures proper usage. 12458 12459@deftypefn {Built-in Function} @var{type} __atomic_load_n (@var{type} *ptr, int memorder) 12460This built-in function implements an atomic load operation. It returns the 12461contents of @code{*@var{ptr}}. 12462 12463The valid memory order variants are 12464@code{__ATOMIC_RELAXED}, @code{__ATOMIC_SEQ_CST}, @code{__ATOMIC_ACQUIRE}, 12465and @code{__ATOMIC_CONSUME}. 12466 12467@end deftypefn 12468 12469@deftypefn {Built-in Function} void __atomic_load (@var{type} *ptr, @var{type} *ret, int memorder) 12470This is the generic version of an atomic load. It returns the 12471contents of @code{*@var{ptr}} in @code{*@var{ret}}. 12472 12473@end deftypefn 12474 12475@deftypefn {Built-in Function} void __atomic_store_n (@var{type} *ptr, @var{type} val, int memorder) 12476This built-in function implements an atomic store operation. It writes 12477@code{@var{val}} into @code{*@var{ptr}}. 12478 12479The valid memory order variants are 12480@code{__ATOMIC_RELAXED}, @code{__ATOMIC_SEQ_CST}, and @code{__ATOMIC_RELEASE}. 12481 12482@end deftypefn 12483 12484@deftypefn {Built-in Function} void __atomic_store (@var{type} *ptr, @var{type} *val, int memorder) 12485This is the generic version of an atomic store. It stores the value 12486of @code{*@var{val}} into @code{*@var{ptr}}. 12487 12488@end deftypefn 12489 12490@deftypefn {Built-in Function} @var{type} __atomic_exchange_n (@var{type} *ptr, @var{type} val, int memorder) 12491This built-in function implements an atomic exchange operation. It writes 12492@var{val} into @code{*@var{ptr}}, and returns the previous contents of 12493@code{*@var{ptr}}. 12494 12495All memory order variants are valid. 12496 12497@end deftypefn 12498 12499@deftypefn {Built-in Function} void __atomic_exchange (@var{type} *ptr, @var{type} *val, @var{type} *ret, int memorder) 12500This is the generic version of an atomic exchange. It stores the 12501contents of @code{*@var{val}} into @code{*@var{ptr}}. The original value 12502of @code{*@var{ptr}} is copied into @code{*@var{ret}}. 12503 12504@end deftypefn 12505 12506@deftypefn {Built-in Function} bool __atomic_compare_exchange_n (@var{type} *ptr, @var{type} *expected, @var{type} desired, bool weak, int success_memorder, int failure_memorder) 12507This built-in function implements an atomic compare and exchange operation. 12508This compares the contents of @code{*@var{ptr}} with the contents of 12509@code{*@var{expected}}. If equal, the operation is a @emph{read-modify-write} 12510operation that writes @var{desired} into @code{*@var{ptr}}. If they are not 12511equal, the operation is a @emph{read} and the current contents of 12512@code{*@var{ptr}} are written into @code{*@var{expected}}. @var{weak} is @code{true} 12513for weak compare_exchange, which may fail spuriously, and @code{false} for 12514the strong variation, which never fails spuriously. Many targets 12515only offer the strong variation and ignore the parameter. When in doubt, use 12516the strong variation. 12517 12518If @var{desired} is written into @code{*@var{ptr}} then @code{true} is returned 12519and memory is affected according to the 12520memory order specified by @var{success_memorder}. There are no 12521restrictions on what memory order can be used here. 12522 12523Otherwise, @code{false} is returned and memory is affected according 12524to @var{failure_memorder}. This memory order cannot be 12525@code{__ATOMIC_RELEASE} nor @code{__ATOMIC_ACQ_REL}. It also cannot be a 12526stronger order than that specified by @var{success_memorder}. 12527 12528@end deftypefn 12529 12530@deftypefn {Built-in Function} bool __atomic_compare_exchange (@var{type} *ptr, @var{type} *expected, @var{type} *desired, bool weak, int success_memorder, int failure_memorder) 12531This built-in function implements the generic version of 12532@code{__atomic_compare_exchange}. The function is virtually identical to 12533@code{__atomic_compare_exchange_n}, except the desired value is also a 12534pointer. 12535 12536@end deftypefn 12537 12538@deftypefn {Built-in Function} @var{type} __atomic_add_fetch (@var{type} *ptr, @var{type} val, int memorder) 12539@deftypefnx {Built-in Function} @var{type} __atomic_sub_fetch (@var{type} *ptr, @var{type} val, int memorder) 12540@deftypefnx {Built-in Function} @var{type} __atomic_and_fetch (@var{type} *ptr, @var{type} val, int memorder) 12541@deftypefnx {Built-in Function} @var{type} __atomic_xor_fetch (@var{type} *ptr, @var{type} val, int memorder) 12542@deftypefnx {Built-in Function} @var{type} __atomic_or_fetch (@var{type} *ptr, @var{type} val, int memorder) 12543@deftypefnx {Built-in Function} @var{type} __atomic_nand_fetch (@var{type} *ptr, @var{type} val, int memorder) 12544These built-in functions perform the operation suggested by the name, and 12545return the result of the operation. Operations on pointer arguments are 12546performed as if the operands were of the @code{uintptr_t} type. That is, 12547they are not scaled by the size of the type to which the pointer points. 12548 12549@smallexample 12550@{ *ptr @var{op}= val; return *ptr; @} 12551@{ *ptr = ~(*ptr & val); return *ptr; @} // nand 12552@end smallexample 12553 12554The object pointed to by the first argument must be of integer or pointer 12555type. It must not be a boolean type. All memory orders are valid. 12556 12557@end deftypefn 12558 12559@deftypefn {Built-in Function} @var{type} __atomic_fetch_add (@var{type} *ptr, @var{type} val, int memorder) 12560@deftypefnx {Built-in Function} @var{type} __atomic_fetch_sub (@var{type} *ptr, @var{type} val, int memorder) 12561@deftypefnx {Built-in Function} @var{type} __atomic_fetch_and (@var{type} *ptr, @var{type} val, int memorder) 12562@deftypefnx {Built-in Function} @var{type} __atomic_fetch_xor (@var{type} *ptr, @var{type} val, int memorder) 12563@deftypefnx {Built-in Function} @var{type} __atomic_fetch_or (@var{type} *ptr, @var{type} val, int memorder) 12564@deftypefnx {Built-in Function} @var{type} __atomic_fetch_nand (@var{type} *ptr, @var{type} val, int memorder) 12565These built-in functions perform the operation suggested by the name, and 12566return the value that had previously been in @code{*@var{ptr}}. Operations 12567on pointer arguments are performed as if the operands were of 12568the @code{uintptr_t} type. That is, they are not scaled by the size of 12569the type to which the pointer points. 12570 12571@smallexample 12572@{ tmp = *ptr; *ptr @var{op}= val; return tmp; @} 12573@{ tmp = *ptr; *ptr = ~(*ptr & val); return tmp; @} // nand 12574@end smallexample 12575 12576The same constraints on arguments apply as for the corresponding 12577@code{__atomic_op_fetch} built-in functions. All memory orders are valid. 12578 12579@end deftypefn 12580 12581@deftypefn {Built-in Function} bool __atomic_test_and_set (void *ptr, int memorder) 12582 12583This built-in function performs an atomic test-and-set operation on 12584the byte at @code{*@var{ptr}}. The byte is set to some implementation 12585defined nonzero ``set'' value and the return value is @code{true} if and only 12586if the previous contents were ``set''. 12587It should be only used for operands of type @code{bool} or @code{char}. For 12588other types only part of the value may be set. 12589 12590All memory orders are valid. 12591 12592@end deftypefn 12593 12594@deftypefn {Built-in Function} void __atomic_clear (bool *ptr, int memorder) 12595 12596This built-in function performs an atomic clear operation on 12597@code{*@var{ptr}}. After the operation, @code{*@var{ptr}} contains 0. 12598It should be only used for operands of type @code{bool} or @code{char} and 12599in conjunction with @code{__atomic_test_and_set}. 12600For other types it may only clear partially. If the type is not @code{bool} 12601prefer using @code{__atomic_store}. 12602 12603The valid memory order variants are 12604@code{__ATOMIC_RELAXED}, @code{__ATOMIC_SEQ_CST}, and 12605@code{__ATOMIC_RELEASE}. 12606 12607@end deftypefn 12608 12609@deftypefn {Built-in Function} void __atomic_thread_fence (int memorder) 12610 12611This built-in function acts as a synchronization fence between threads 12612based on the specified memory order. 12613 12614All memory orders are valid. 12615 12616@end deftypefn 12617 12618@deftypefn {Built-in Function} void __atomic_signal_fence (int memorder) 12619 12620This built-in function acts as a synchronization fence between a thread 12621and signal handlers based in the same thread. 12622 12623All memory orders are valid. 12624 12625@end deftypefn 12626 12627@deftypefn {Built-in Function} bool __atomic_always_lock_free (size_t size, void *ptr) 12628 12629This built-in function returns @code{true} if objects of @var{size} bytes always 12630generate lock-free atomic instructions for the target architecture. 12631@var{size} must resolve to a compile-time constant and the result also 12632resolves to a compile-time constant. 12633 12634@var{ptr} is an optional pointer to the object that may be used to determine 12635alignment. A value of 0 indicates typical alignment should be used. The 12636compiler may also ignore this parameter. 12637 12638@smallexample 12639if (__atomic_always_lock_free (sizeof (long long), 0)) 12640@end smallexample 12641 12642@end deftypefn 12643 12644@deftypefn {Built-in Function} bool __atomic_is_lock_free (size_t size, void *ptr) 12645 12646This built-in function returns @code{true} if objects of @var{size} bytes always 12647generate lock-free atomic instructions for the target architecture. If 12648the built-in function is not known to be lock-free, a call is made to a 12649runtime routine named @code{__atomic_is_lock_free}. 12650 12651@var{ptr} is an optional pointer to the object that may be used to determine 12652alignment. A value of 0 indicates typical alignment should be used. The 12653compiler may also ignore this parameter. 12654@end deftypefn 12655 12656@node Integer Overflow Builtins 12657@section Built-in Functions to Perform Arithmetic with Overflow Checking 12658 12659The following built-in functions allow performing simple arithmetic operations 12660together with checking whether the operations overflowed. 12661 12662@deftypefn {Built-in Function} bool __builtin_add_overflow (@var{type1} a, @var{type2} b, @var{type3} *res) 12663@deftypefnx {Built-in Function} bool __builtin_sadd_overflow (int a, int b, int *res) 12664@deftypefnx {Built-in Function} bool __builtin_saddl_overflow (long int a, long int b, long int *res) 12665@deftypefnx {Built-in Function} bool __builtin_saddll_overflow (long long int a, long long int b, long long int *res) 12666@deftypefnx {Built-in Function} bool __builtin_uadd_overflow (unsigned int a, unsigned int b, unsigned int *res) 12667@deftypefnx {Built-in Function} bool __builtin_uaddl_overflow (unsigned long int a, unsigned long int b, unsigned long int *res) 12668@deftypefnx {Built-in Function} bool __builtin_uaddll_overflow (unsigned long long int a, unsigned long long int b, unsigned long long int *res) 12669 12670These built-in functions promote the first two operands into infinite precision signed 12671type and perform addition on those promoted operands. The result is then 12672cast to the type the third pointer argument points to and stored there. 12673If the stored result is equal to the infinite precision result, the built-in 12674functions return @code{false}, otherwise they return @code{true}. As the addition is 12675performed in infinite signed precision, these built-in functions have fully defined 12676behavior for all argument values. 12677 12678The first built-in function allows arbitrary integral types for operands and 12679the result type must be pointer to some integral type other than enumerated or 12680boolean type, the rest of the built-in functions have explicit integer types. 12681 12682The compiler will attempt to use hardware instructions to implement 12683these built-in functions where possible, like conditional jump on overflow 12684after addition, conditional jump on carry etc. 12685 12686@end deftypefn 12687 12688@deftypefn {Built-in Function} bool __builtin_sub_overflow (@var{type1} a, @var{type2} b, @var{type3} *res) 12689@deftypefnx {Built-in Function} bool __builtin_ssub_overflow (int a, int b, int *res) 12690@deftypefnx {Built-in Function} bool __builtin_ssubl_overflow (long int a, long int b, long int *res) 12691@deftypefnx {Built-in Function} bool __builtin_ssubll_overflow (long long int a, long long int b, long long int *res) 12692@deftypefnx {Built-in Function} bool __builtin_usub_overflow (unsigned int a, unsigned int b, unsigned int *res) 12693@deftypefnx {Built-in Function} bool __builtin_usubl_overflow (unsigned long int a, unsigned long int b, unsigned long int *res) 12694@deftypefnx {Built-in Function} bool __builtin_usubll_overflow (unsigned long long int a, unsigned long long int b, unsigned long long int *res) 12695 12696These built-in functions are similar to the add overflow checking built-in 12697functions above, except they perform subtraction, subtract the second argument 12698from the first one, instead of addition. 12699 12700@end deftypefn 12701 12702@deftypefn {Built-in Function} bool __builtin_mul_overflow (@var{type1} a, @var{type2} b, @var{type3} *res) 12703@deftypefnx {Built-in Function} bool __builtin_smul_overflow (int a, int b, int *res) 12704@deftypefnx {Built-in Function} bool __builtin_smull_overflow (long int a, long int b, long int *res) 12705@deftypefnx {Built-in Function} bool __builtin_smulll_overflow (long long int a, long long int b, long long int *res) 12706@deftypefnx {Built-in Function} bool __builtin_umul_overflow (unsigned int a, unsigned int b, unsigned int *res) 12707@deftypefnx {Built-in Function} bool __builtin_umull_overflow (unsigned long int a, unsigned long int b, unsigned long int *res) 12708@deftypefnx {Built-in Function} bool __builtin_umulll_overflow (unsigned long long int a, unsigned long long int b, unsigned long long int *res) 12709 12710These built-in functions are similar to the add overflow checking built-in 12711functions above, except they perform multiplication, instead of addition. 12712 12713@end deftypefn 12714 12715The following built-in functions allow checking if simple arithmetic operation 12716would overflow. 12717 12718@deftypefn {Built-in Function} bool __builtin_add_overflow_p (@var{type1} a, @var{type2} b, @var{type3} c) 12719@deftypefnx {Built-in Function} bool __builtin_sub_overflow_p (@var{type1} a, @var{type2} b, @var{type3} c) 12720@deftypefnx {Built-in Function} bool __builtin_mul_overflow_p (@var{type1} a, @var{type2} b, @var{type3} c) 12721 12722These built-in functions are similar to @code{__builtin_add_overflow}, 12723@code{__builtin_sub_overflow}, or @code{__builtin_mul_overflow}, except that 12724they don't store the result of the arithmetic operation anywhere and the 12725last argument is not a pointer, but some expression with integral type other 12726than enumerated or boolean type. 12727 12728The built-in functions promote the first two operands into infinite precision signed type 12729and perform addition on those promoted operands. The result is then 12730cast to the type of the third argument. If the cast result is equal to the infinite 12731precision result, the built-in functions return @code{false}, otherwise they return @code{true}. 12732The value of the third argument is ignored, just the side effects in the third argument 12733are evaluated, and no integral argument promotions are performed on the last argument. 12734If the third argument is a bit-field, the type used for the result cast has the 12735precision and signedness of the given bit-field, rather than precision and signedness 12736of the underlying type. 12737 12738For example, the following macro can be used to portably check, at 12739compile-time, whether or not adding two constant integers will overflow, 12740and perform the addition only when it is known to be safe and not to trigger 12741a @option{-Woverflow} warning. 12742 12743@smallexample 12744#define INT_ADD_OVERFLOW_P(a, b) \ 12745 __builtin_add_overflow_p (a, b, (__typeof__ ((a) + (b))) 0) 12746 12747enum @{ 12748 A = INT_MAX, B = 3, 12749 C = INT_ADD_OVERFLOW_P (A, B) ? 0 : A + B, 12750 D = __builtin_add_overflow_p (1, SCHAR_MAX, (signed char) 0) 12751@}; 12752@end smallexample 12753 12754The compiler will attempt to use hardware instructions to implement 12755these built-in functions where possible, like conditional jump on overflow 12756after addition, conditional jump on carry etc. 12757 12758@end deftypefn 12759 12760@node x86 specific memory model extensions for transactional memory 12761@section x86-Specific Memory Model Extensions for Transactional Memory 12762 12763The x86 architecture supports additional memory ordering flags 12764to mark critical sections for hardware lock elision. 12765These must be specified in addition to an existing memory order to 12766atomic intrinsics. 12767 12768@table @code 12769@item __ATOMIC_HLE_ACQUIRE 12770Start lock elision on a lock variable. 12771Memory order must be @code{__ATOMIC_ACQUIRE} or stronger. 12772@item __ATOMIC_HLE_RELEASE 12773End lock elision on a lock variable. 12774Memory order must be @code{__ATOMIC_RELEASE} or stronger. 12775@end table 12776 12777When a lock acquire fails, it is required for good performance to abort 12778the transaction quickly. This can be done with a @code{_mm_pause}. 12779 12780@smallexample 12781#include <immintrin.h> // For _mm_pause 12782 12783int lockvar; 12784 12785/* Acquire lock with lock elision */ 12786while (__atomic_exchange_n(&lockvar, 1, __ATOMIC_ACQUIRE|__ATOMIC_HLE_ACQUIRE)) 12787 _mm_pause(); /* Abort failed transaction */ 12788... 12789/* Free lock with lock elision */ 12790__atomic_store_n(&lockvar, 0, __ATOMIC_RELEASE|__ATOMIC_HLE_RELEASE); 12791@end smallexample 12792 12793@node Object Size Checking 12794@section Object Size Checking Built-in Functions 12795@findex __builtin_object_size 12796@findex __builtin_dynamic_object_size 12797@findex __builtin___memcpy_chk 12798@findex __builtin___mempcpy_chk 12799@findex __builtin___memmove_chk 12800@findex __builtin___memset_chk 12801@findex __builtin___strcpy_chk 12802@findex __builtin___stpcpy_chk 12803@findex __builtin___strncpy_chk 12804@findex __builtin___strcat_chk 12805@findex __builtin___strncat_chk 12806@findex __builtin___sprintf_chk 12807@findex __builtin___snprintf_chk 12808@findex __builtin___vsprintf_chk 12809@findex __builtin___vsnprintf_chk 12810@findex __builtin___printf_chk 12811@findex __builtin___vprintf_chk 12812@findex __builtin___fprintf_chk 12813@findex __builtin___vfprintf_chk 12814 12815GCC implements a limited buffer overflow protection mechanism that can 12816prevent some buffer overflow attacks by determining the sizes of objects 12817into which data is about to be written and preventing the writes when 12818the size isn't sufficient. The built-in functions described below yield 12819the best results when used together and when optimization is enabled. 12820For example, to detect object sizes across function boundaries or to 12821follow pointer assignments through non-trivial control flow they rely 12822on various optimization passes enabled with @option{-O2}. However, to 12823a limited extent, they can be used without optimization as well. 12824 12825@deftypefn {Built-in Function} {size_t} __builtin_object_size (const void * @var{ptr}, int @var{type}) 12826is a built-in construct that returns a constant number of bytes from 12827@var{ptr} to the end of the object @var{ptr} pointer points to 12828(if known at compile time). To determine the sizes of dynamically allocated 12829objects the function relies on the allocation functions called to obtain 12830the storage to be declared with the @code{alloc_size} attribute (@pxref{Common 12831Function Attributes}). @code{__builtin_object_size} never evaluates 12832its arguments for side effects. If there are any side effects in them, it 12833returns @code{(size_t) -1} for @var{type} 0 or 1 and @code{(size_t) 0} 12834for @var{type} 2 or 3. If there are multiple objects @var{ptr} can 12835point to and all of them are known at compile time, the returned number 12836is the maximum of remaining byte counts in those objects if @var{type} & 2 is 128370 and minimum if nonzero. If it is not possible to determine which objects 12838@var{ptr} points to at compile time, @code{__builtin_object_size} should 12839return @code{(size_t) -1} for @var{type} 0 or 1 and @code{(size_t) 0} 12840for @var{type} 2 or 3. 12841 12842@var{type} is an integer constant from 0 to 3. If the least significant 12843bit is clear, objects are whole variables, if it is set, a closest 12844surrounding subobject is considered the object a pointer points to. 12845The second bit determines if maximum or minimum of remaining bytes 12846is computed. 12847 12848@smallexample 12849struct V @{ char buf1[10]; int b; char buf2[10]; @} var; 12850char *p = &var.buf1[1], *q = &var.b; 12851 12852/* Here the object p points to is var. */ 12853assert (__builtin_object_size (p, 0) == sizeof (var) - 1); 12854/* The subobject p points to is var.buf1. */ 12855assert (__builtin_object_size (p, 1) == sizeof (var.buf1) - 1); 12856/* The object q points to is var. */ 12857assert (__builtin_object_size (q, 0) 12858 == (char *) (&var + 1) - (char *) &var.b); 12859/* The subobject q points to is var.b. */ 12860assert (__builtin_object_size (q, 1) == sizeof (var.b)); 12861@end smallexample 12862@end deftypefn 12863 12864@deftypefn {Built-in Function} {size_t} __builtin_dynamic_object_size (const void * @var{ptr}, int @var{type}) 12865is similar to @code{__builtin_object_size} in that it returns a number of bytes 12866from @var{ptr} to the end of the object @var{ptr} pointer points to, except 12867that the size returned may not be a constant. This results in successful 12868evaluation of object size estimates in a wider range of use cases and can be 12869more precise than @code{__builtin_object_size}, but it incurs a performance 12870penalty since it may add a runtime overhead on size computation. Semantics of 12871@var{type} as well as return values in case it is not possible to determine 12872which objects @var{ptr} points to at compile time are the same as in the case 12873of @code{__builtin_object_size}. 12874@end deftypefn 12875 12876There are built-in functions added for many common string operation 12877functions, e.g., for @code{memcpy} @code{__builtin___memcpy_chk} 12878built-in is provided. This built-in has an additional last argument, 12879which is the number of bytes remaining in the object the @var{dest} 12880argument points to or @code{(size_t) -1} if the size is not known. 12881 12882The built-in functions are optimized into the normal string functions 12883like @code{memcpy} if the last argument is @code{(size_t) -1} or if 12884it is known at compile time that the destination object will not 12885be overflowed. If the compiler can determine at compile time that the 12886object will always be overflowed, it issues a warning. 12887 12888The intended use can be e.g.@: 12889 12890@smallexample 12891#undef memcpy 12892#define bos0(dest) __builtin_object_size (dest, 0) 12893#define memcpy(dest, src, n) \ 12894 __builtin___memcpy_chk (dest, src, n, bos0 (dest)) 12895 12896char *volatile p; 12897char buf[10]; 12898/* It is unknown what object p points to, so this is optimized 12899 into plain memcpy - no checking is possible. */ 12900memcpy (p, "abcde", n); 12901/* Destination is known and length too. It is known at compile 12902 time there will be no overflow. */ 12903memcpy (&buf[5], "abcde", 5); 12904/* Destination is known, but the length is not known at compile time. 12905 This will result in __memcpy_chk call that can check for overflow 12906 at run time. */ 12907memcpy (&buf[5], "abcde", n); 12908/* Destination is known and it is known at compile time there will 12909 be overflow. There will be a warning and __memcpy_chk call that 12910 will abort the program at run time. */ 12911memcpy (&buf[6], "abcde", 5); 12912@end smallexample 12913 12914Such built-in functions are provided for @code{memcpy}, @code{mempcpy}, 12915@code{memmove}, @code{memset}, @code{strcpy}, @code{stpcpy}, @code{strncpy}, 12916@code{strcat} and @code{strncat}. 12917 12918There are also checking built-in functions for formatted output functions. 12919@smallexample 12920int __builtin___sprintf_chk (char *s, int flag, size_t os, const char *fmt, ...); 12921int __builtin___snprintf_chk (char *s, size_t maxlen, int flag, size_t os, 12922 const char *fmt, ...); 12923int __builtin___vsprintf_chk (char *s, int flag, size_t os, const char *fmt, 12924 va_list ap); 12925int __builtin___vsnprintf_chk (char *s, size_t maxlen, int flag, size_t os, 12926 const char *fmt, va_list ap); 12927@end smallexample 12928 12929The added @var{flag} argument is passed unchanged to @code{__sprintf_chk} 12930etc.@: functions and can contain implementation specific flags on what 12931additional security measures the checking function might take, such as 12932handling @code{%n} differently. 12933 12934The @var{os} argument is the object size @var{s} points to, like in the 12935other built-in functions. There is a small difference in the behavior 12936though, if @var{os} is @code{(size_t) -1}, the built-in functions are 12937optimized into the non-checking functions only if @var{flag} is 0, otherwise 12938the checking function is called with @var{os} argument set to 12939@code{(size_t) -1}. 12940 12941In addition to this, there are checking built-in functions 12942@code{__builtin___printf_chk}, @code{__builtin___vprintf_chk}, 12943@code{__builtin___fprintf_chk} and @code{__builtin___vfprintf_chk}. 12944These have just one additional argument, @var{flag}, right before 12945format string @var{fmt}. If the compiler is able to optimize them to 12946@code{fputc} etc.@: functions, it does, otherwise the checking function 12947is called and the @var{flag} argument passed to it. 12948 12949@node Other Builtins 12950@section Other Built-in Functions Provided by GCC 12951@cindex built-in functions 12952@findex __builtin_alloca 12953@findex __builtin_alloca_with_align 12954@findex __builtin_alloca_with_align_and_max 12955@findex __builtin_call_with_static_chain 12956@findex __builtin_extend_pointer 12957@findex __builtin_fpclassify 12958@findex __builtin_has_attribute 12959@findex __builtin_isfinite 12960@findex __builtin_isnormal 12961@findex __builtin_isgreater 12962@findex __builtin_isgreaterequal 12963@findex __builtin_isinf_sign 12964@findex __builtin_isless 12965@findex __builtin_islessequal 12966@findex __builtin_islessgreater 12967@findex __builtin_isunordered 12968@findex __builtin_object_size 12969@findex __builtin_powi 12970@findex __builtin_powif 12971@findex __builtin_powil 12972@findex __builtin_speculation_safe_value 12973@findex _Exit 12974@findex _exit 12975@findex abort 12976@findex abs 12977@findex acos 12978@findex acosf 12979@findex acosh 12980@findex acoshf 12981@findex acoshl 12982@findex acosl 12983@findex alloca 12984@findex asin 12985@findex asinf 12986@findex asinh 12987@findex asinhf 12988@findex asinhl 12989@findex asinl 12990@findex atan 12991@findex atan2 12992@findex atan2f 12993@findex atan2l 12994@findex atanf 12995@findex atanh 12996@findex atanhf 12997@findex atanhl 12998@findex atanl 12999@findex bcmp 13000@findex bzero 13001@findex cabs 13002@findex cabsf 13003@findex cabsl 13004@findex cacos 13005@findex cacosf 13006@findex cacosh 13007@findex cacoshf 13008@findex cacoshl 13009@findex cacosl 13010@findex calloc 13011@findex carg 13012@findex cargf 13013@findex cargl 13014@findex casin 13015@findex casinf 13016@findex casinh 13017@findex casinhf 13018@findex casinhl 13019@findex casinl 13020@findex catan 13021@findex catanf 13022@findex catanh 13023@findex catanhf 13024@findex catanhl 13025@findex catanl 13026@findex cbrt 13027@findex cbrtf 13028@findex cbrtl 13029@findex ccos 13030@findex ccosf 13031@findex ccosh 13032@findex ccoshf 13033@findex ccoshl 13034@findex ccosl 13035@findex ceil 13036@findex ceilf 13037@findex ceill 13038@findex cexp 13039@findex cexpf 13040@findex cexpl 13041@findex cimag 13042@findex cimagf 13043@findex cimagl 13044@findex clog 13045@findex clogf 13046@findex clogl 13047@findex clog10 13048@findex clog10f 13049@findex clog10l 13050@findex conj 13051@findex conjf 13052@findex conjl 13053@findex copysign 13054@findex copysignf 13055@findex copysignl 13056@findex cos 13057@findex cosf 13058@findex cosh 13059@findex coshf 13060@findex coshl 13061@findex cosl 13062@findex cpow 13063@findex cpowf 13064@findex cpowl 13065@findex cproj 13066@findex cprojf 13067@findex cprojl 13068@findex creal 13069@findex crealf 13070@findex creall 13071@findex csin 13072@findex csinf 13073@findex csinh 13074@findex csinhf 13075@findex csinhl 13076@findex csinl 13077@findex csqrt 13078@findex csqrtf 13079@findex csqrtl 13080@findex ctan 13081@findex ctanf 13082@findex ctanh 13083@findex ctanhf 13084@findex ctanhl 13085@findex ctanl 13086@findex dcgettext 13087@findex dgettext 13088@findex drem 13089@findex dremf 13090@findex dreml 13091@findex erf 13092@findex erfc 13093@findex erfcf 13094@findex erfcl 13095@findex erff 13096@findex erfl 13097@findex exit 13098@findex exp 13099@findex exp10 13100@findex exp10f 13101@findex exp10l 13102@findex exp2 13103@findex exp2f 13104@findex exp2l 13105@findex expf 13106@findex expl 13107@findex expm1 13108@findex expm1f 13109@findex expm1l 13110@findex fabs 13111@findex fabsf 13112@findex fabsl 13113@findex fdim 13114@findex fdimf 13115@findex fdiml 13116@findex ffs 13117@findex floor 13118@findex floorf 13119@findex floorl 13120@findex fma 13121@findex fmaf 13122@findex fmal 13123@findex fmax 13124@findex fmaxf 13125@findex fmaxl 13126@findex fmin 13127@findex fminf 13128@findex fminl 13129@findex fmod 13130@findex fmodf 13131@findex fmodl 13132@findex fprintf 13133@findex fprintf_unlocked 13134@findex fputs 13135@findex fputs_unlocked 13136@findex free 13137@findex frexp 13138@findex frexpf 13139@findex frexpl 13140@findex fscanf 13141@findex gamma 13142@findex gammaf 13143@findex gammal 13144@findex gamma_r 13145@findex gammaf_r 13146@findex gammal_r 13147@findex gettext 13148@findex hypot 13149@findex hypotf 13150@findex hypotl 13151@findex ilogb 13152@findex ilogbf 13153@findex ilogbl 13154@findex imaxabs 13155@findex index 13156@findex isalnum 13157@findex isalpha 13158@findex isascii 13159@findex isblank 13160@findex iscntrl 13161@findex isdigit 13162@findex isgraph 13163@findex islower 13164@findex isprint 13165@findex ispunct 13166@findex isspace 13167@findex isupper 13168@findex iswalnum 13169@findex iswalpha 13170@findex iswblank 13171@findex iswcntrl 13172@findex iswdigit 13173@findex iswgraph 13174@findex iswlower 13175@findex iswprint 13176@findex iswpunct 13177@findex iswspace 13178@findex iswupper 13179@findex iswxdigit 13180@findex isxdigit 13181@findex j0 13182@findex j0f 13183@findex j0l 13184@findex j1 13185@findex j1f 13186@findex j1l 13187@findex jn 13188@findex jnf 13189@findex jnl 13190@findex labs 13191@findex ldexp 13192@findex ldexpf 13193@findex ldexpl 13194@findex lgamma 13195@findex lgammaf 13196@findex lgammal 13197@findex lgamma_r 13198@findex lgammaf_r 13199@findex lgammal_r 13200@findex llabs 13201@findex llrint 13202@findex llrintf 13203@findex llrintl 13204@findex llround 13205@findex llroundf 13206@findex llroundl 13207@findex log 13208@findex log10 13209@findex log10f 13210@findex log10l 13211@findex log1p 13212@findex log1pf 13213@findex log1pl 13214@findex log2 13215@findex log2f 13216@findex log2l 13217@findex logb 13218@findex logbf 13219@findex logbl 13220@findex logf 13221@findex logl 13222@findex lrint 13223@findex lrintf 13224@findex lrintl 13225@findex lround 13226@findex lroundf 13227@findex lroundl 13228@findex malloc 13229@findex memchr 13230@findex memcmp 13231@findex memcpy 13232@findex mempcpy 13233@findex memset 13234@findex modf 13235@findex modff 13236@findex modfl 13237@findex nearbyint 13238@findex nearbyintf 13239@findex nearbyintl 13240@findex nextafter 13241@findex nextafterf 13242@findex nextafterl 13243@findex nexttoward 13244@findex nexttowardf 13245@findex nexttowardl 13246@findex pow 13247@findex pow10 13248@findex pow10f 13249@findex pow10l 13250@findex powf 13251@findex powl 13252@findex printf 13253@findex printf_unlocked 13254@findex putchar 13255@findex puts 13256@findex realloc 13257@findex remainder 13258@findex remainderf 13259@findex remainderl 13260@findex remquo 13261@findex remquof 13262@findex remquol 13263@findex rindex 13264@findex rint 13265@findex rintf 13266@findex rintl 13267@findex round 13268@findex roundf 13269@findex roundl 13270@findex scalb 13271@findex scalbf 13272@findex scalbl 13273@findex scalbln 13274@findex scalblnf 13275@findex scalblnf 13276@findex scalbn 13277@findex scalbnf 13278@findex scanfnl 13279@findex signbit 13280@findex signbitf 13281@findex signbitl 13282@findex signbitd32 13283@findex signbitd64 13284@findex signbitd128 13285@findex significand 13286@findex significandf 13287@findex significandl 13288@findex sin 13289@findex sincos 13290@findex sincosf 13291@findex sincosl 13292@findex sinf 13293@findex sinh 13294@findex sinhf 13295@findex sinhl 13296@findex sinl 13297@findex snprintf 13298@findex sprintf 13299@findex sqrt 13300@findex sqrtf 13301@findex sqrtl 13302@findex sscanf 13303@findex stpcpy 13304@findex stpncpy 13305@findex strcasecmp 13306@findex strcat 13307@findex strchr 13308@findex strcmp 13309@findex strcpy 13310@findex strcspn 13311@findex strdup 13312@findex strfmon 13313@findex strftime 13314@findex strlen 13315@findex strncasecmp 13316@findex strncat 13317@findex strncmp 13318@findex strncpy 13319@findex strndup 13320@findex strnlen 13321@findex strpbrk 13322@findex strrchr 13323@findex strspn 13324@findex strstr 13325@findex tan 13326@findex tanf 13327@findex tanh 13328@findex tanhf 13329@findex tanhl 13330@findex tanl 13331@findex tgamma 13332@findex tgammaf 13333@findex tgammal 13334@findex toascii 13335@findex tolower 13336@findex toupper 13337@findex towlower 13338@findex towupper 13339@findex trunc 13340@findex truncf 13341@findex truncl 13342@findex vfprintf 13343@findex vfscanf 13344@findex vprintf 13345@findex vscanf 13346@findex vsnprintf 13347@findex vsprintf 13348@findex vsscanf 13349@findex y0 13350@findex y0f 13351@findex y0l 13352@findex y1 13353@findex y1f 13354@findex y1l 13355@findex yn 13356@findex ynf 13357@findex ynl 13358 13359GCC provides a large number of built-in functions other than the ones 13360mentioned above. Some of these are for internal use in the processing 13361of exceptions or variable-length argument lists and are not 13362documented here because they may change from time to time; we do not 13363recommend general use of these functions. 13364 13365The remaining functions are provided for optimization purposes. 13366 13367With the exception of built-ins that have library equivalents such as 13368the standard C library functions discussed below, or that expand to 13369library calls, GCC built-in functions are always expanded inline and 13370thus do not have corresponding entry points and their address cannot 13371be obtained. Attempting to use them in an expression other than 13372a function call results in a compile-time error. 13373 13374@opindex fno-builtin 13375GCC includes built-in versions of many of the functions in the standard 13376C library. These functions come in two forms: one whose names start with 13377the @code{__builtin_} prefix, and the other without. Both forms have the 13378same type (including prototype), the same address (when their address is 13379taken), and the same meaning as the C library functions even if you specify 13380the @option{-fno-builtin} option @pxref{C Dialect Options}). Many of these 13381functions are only optimized in certain cases; if they are not optimized in 13382a particular case, a call to the library function is emitted. 13383 13384@opindex ansi 13385@opindex std 13386Outside strict ISO C mode (@option{-ansi}, @option{-std=c90}, 13387@option{-std=c99} or @option{-std=c11}), the functions 13388@code{_exit}, @code{alloca}, @code{bcmp}, @code{bzero}, 13389@code{dcgettext}, @code{dgettext}, @code{dremf}, @code{dreml}, 13390@code{drem}, @code{exp10f}, @code{exp10l}, @code{exp10}, @code{ffsll}, 13391@code{ffsl}, @code{ffs}, @code{fprintf_unlocked}, 13392@code{fputs_unlocked}, @code{gammaf}, @code{gammal}, @code{gamma}, 13393@code{gammaf_r}, @code{gammal_r}, @code{gamma_r}, @code{gettext}, 13394@code{index}, @code{isascii}, @code{j0f}, @code{j0l}, @code{j0}, 13395@code{j1f}, @code{j1l}, @code{j1}, @code{jnf}, @code{jnl}, @code{jn}, 13396@code{lgammaf_r}, @code{lgammal_r}, @code{lgamma_r}, @code{mempcpy}, 13397@code{pow10f}, @code{pow10l}, @code{pow10}, @code{printf_unlocked}, 13398@code{rindex}, @code{roundeven}, @code{roundevenf}, @code{roundevenl}, 13399@code{scalbf}, @code{scalbl}, @code{scalb}, 13400@code{signbit}, @code{signbitf}, @code{signbitl}, @code{signbitd32}, 13401@code{signbitd64}, @code{signbitd128}, @code{significandf}, 13402@code{significandl}, @code{significand}, @code{sincosf}, 13403@code{sincosl}, @code{sincos}, @code{stpcpy}, @code{stpncpy}, 13404@code{strcasecmp}, @code{strdup}, @code{strfmon}, @code{strncasecmp}, 13405@code{strndup}, @code{strnlen}, @code{toascii}, @code{y0f}, @code{y0l}, 13406@code{y0}, @code{y1f}, @code{y1l}, @code{y1}, @code{ynf}, @code{ynl} and 13407@code{yn} 13408may be handled as built-in functions. 13409All these functions have corresponding versions 13410prefixed with @code{__builtin_}, which may be used even in strict C90 13411mode. 13412 13413The ISO C99 functions 13414@code{_Exit}, @code{acoshf}, @code{acoshl}, @code{acosh}, @code{asinhf}, 13415@code{asinhl}, @code{asinh}, @code{atanhf}, @code{atanhl}, @code{atanh}, 13416@code{cabsf}, @code{cabsl}, @code{cabs}, @code{cacosf}, @code{cacoshf}, 13417@code{cacoshl}, @code{cacosh}, @code{cacosl}, @code{cacos}, 13418@code{cargf}, @code{cargl}, @code{carg}, @code{casinf}, @code{casinhf}, 13419@code{casinhl}, @code{casinh}, @code{casinl}, @code{casin}, 13420@code{catanf}, @code{catanhf}, @code{catanhl}, @code{catanh}, 13421@code{catanl}, @code{catan}, @code{cbrtf}, @code{cbrtl}, @code{cbrt}, 13422@code{ccosf}, @code{ccoshf}, @code{ccoshl}, @code{ccosh}, @code{ccosl}, 13423@code{ccos}, @code{cexpf}, @code{cexpl}, @code{cexp}, @code{cimagf}, 13424@code{cimagl}, @code{cimag}, @code{clogf}, @code{clogl}, @code{clog}, 13425@code{conjf}, @code{conjl}, @code{conj}, @code{copysignf}, @code{copysignl}, 13426@code{copysign}, @code{cpowf}, @code{cpowl}, @code{cpow}, @code{cprojf}, 13427@code{cprojl}, @code{cproj}, @code{crealf}, @code{creall}, @code{creal}, 13428@code{csinf}, @code{csinhf}, @code{csinhl}, @code{csinh}, @code{csinl}, 13429@code{csin}, @code{csqrtf}, @code{csqrtl}, @code{csqrt}, @code{ctanf}, 13430@code{ctanhf}, @code{ctanhl}, @code{ctanh}, @code{ctanl}, @code{ctan}, 13431@code{erfcf}, @code{erfcl}, @code{erfc}, @code{erff}, @code{erfl}, 13432@code{erf}, @code{exp2f}, @code{exp2l}, @code{exp2}, @code{expm1f}, 13433@code{expm1l}, @code{expm1}, @code{fdimf}, @code{fdiml}, @code{fdim}, 13434@code{fmaf}, @code{fmal}, @code{fmaxf}, @code{fmaxl}, @code{fmax}, 13435@code{fma}, @code{fminf}, @code{fminl}, @code{fmin}, @code{hypotf}, 13436@code{hypotl}, @code{hypot}, @code{ilogbf}, @code{ilogbl}, @code{ilogb}, 13437@code{imaxabs}, @code{isblank}, @code{iswblank}, @code{lgammaf}, 13438@code{lgammal}, @code{lgamma}, @code{llabs}, @code{llrintf}, @code{llrintl}, 13439@code{llrint}, @code{llroundf}, @code{llroundl}, @code{llround}, 13440@code{log1pf}, @code{log1pl}, @code{log1p}, @code{log2f}, @code{log2l}, 13441@code{log2}, @code{logbf}, @code{logbl}, @code{logb}, @code{lrintf}, 13442@code{lrintl}, @code{lrint}, @code{lroundf}, @code{lroundl}, 13443@code{lround}, @code{nearbyintf}, @code{nearbyintl}, @code{nearbyint}, 13444@code{nextafterf}, @code{nextafterl}, @code{nextafter}, 13445@code{nexttowardf}, @code{nexttowardl}, @code{nexttoward}, 13446@code{remainderf}, @code{remainderl}, @code{remainder}, @code{remquof}, 13447@code{remquol}, @code{remquo}, @code{rintf}, @code{rintl}, @code{rint}, 13448@code{roundf}, @code{roundl}, @code{round}, @code{scalblnf}, 13449@code{scalblnl}, @code{scalbln}, @code{scalbnf}, @code{scalbnl}, 13450@code{scalbn}, @code{snprintf}, @code{tgammaf}, @code{tgammal}, 13451@code{tgamma}, @code{truncf}, @code{truncl}, @code{trunc}, 13452@code{vfscanf}, @code{vscanf}, @code{vsnprintf} and @code{vsscanf} 13453are handled as built-in functions 13454except in strict ISO C90 mode (@option{-ansi} or @option{-std=c90}). 13455 13456There are also built-in versions of the ISO C99 functions 13457@code{acosf}, @code{acosl}, @code{asinf}, @code{asinl}, @code{atan2f}, 13458@code{atan2l}, @code{atanf}, @code{atanl}, @code{ceilf}, @code{ceill}, 13459@code{cosf}, @code{coshf}, @code{coshl}, @code{cosl}, @code{expf}, 13460@code{expl}, @code{fabsf}, @code{fabsl}, @code{floorf}, @code{floorl}, 13461@code{fmodf}, @code{fmodl}, @code{frexpf}, @code{frexpl}, @code{ldexpf}, 13462@code{ldexpl}, @code{log10f}, @code{log10l}, @code{logf}, @code{logl}, 13463@code{modfl}, @code{modff}, @code{powf}, @code{powl}, @code{sinf}, 13464@code{sinhf}, @code{sinhl}, @code{sinl}, @code{sqrtf}, @code{sqrtl}, 13465@code{tanf}, @code{tanhf}, @code{tanhl} and @code{tanl} 13466that are recognized in any mode since ISO C90 reserves these names for 13467the purpose to which ISO C99 puts them. All these functions have 13468corresponding versions prefixed with @code{__builtin_}. 13469 13470There are also built-in functions @code{__builtin_fabsf@var{n}}, 13471@code{__builtin_fabsf@var{n}x}, @code{__builtin_copysignf@var{n}} and 13472@code{__builtin_copysignf@var{n}x}, corresponding to the TS 18661-3 13473functions @code{fabsf@var{n}}, @code{fabsf@var{n}x}, 13474@code{copysignf@var{n}} and @code{copysignf@var{n}x}, for supported 13475types @code{_Float@var{n}} and @code{_Float@var{n}x}. 13476 13477There are also GNU extension functions @code{clog10}, @code{clog10f} and 13478@code{clog10l} which names are reserved by ISO C99 for future use. 13479All these functions have versions prefixed with @code{__builtin_}. 13480 13481The ISO C94 functions 13482@code{iswalnum}, @code{iswalpha}, @code{iswcntrl}, @code{iswdigit}, 13483@code{iswgraph}, @code{iswlower}, @code{iswprint}, @code{iswpunct}, 13484@code{iswspace}, @code{iswupper}, @code{iswxdigit}, @code{towlower} and 13485@code{towupper} 13486are handled as built-in functions 13487except in strict ISO C90 mode (@option{-ansi} or @option{-std=c90}). 13488 13489The ISO C90 functions 13490@code{abort}, @code{abs}, @code{acos}, @code{asin}, @code{atan2}, 13491@code{atan}, @code{calloc}, @code{ceil}, @code{cosh}, @code{cos}, 13492@code{exit}, @code{exp}, @code{fabs}, @code{floor}, @code{fmod}, 13493@code{fprintf}, @code{fputs}, @code{free}, @code{frexp}, @code{fscanf}, 13494@code{isalnum}, @code{isalpha}, @code{iscntrl}, @code{isdigit}, 13495@code{isgraph}, @code{islower}, @code{isprint}, @code{ispunct}, 13496@code{isspace}, @code{isupper}, @code{isxdigit}, @code{tolower}, 13497@code{toupper}, @code{labs}, @code{ldexp}, @code{log10}, @code{log}, 13498@code{malloc}, @code{memchr}, @code{memcmp}, @code{memcpy}, 13499@code{memset}, @code{modf}, @code{pow}, @code{printf}, @code{putchar}, 13500@code{puts}, @code{realloc}, @code{scanf}, @code{sinh}, @code{sin}, 13501@code{snprintf}, @code{sprintf}, @code{sqrt}, @code{sscanf}, @code{strcat}, 13502@code{strchr}, @code{strcmp}, @code{strcpy}, @code{strcspn}, 13503@code{strlen}, @code{strncat}, @code{strncmp}, @code{strncpy}, 13504@code{strpbrk}, @code{strrchr}, @code{strspn}, @code{strstr}, 13505@code{tanh}, @code{tan}, @code{vfprintf}, @code{vprintf} and @code{vsprintf} 13506are all recognized as built-in functions unless 13507@option{-fno-builtin} is specified (or @option{-fno-builtin-@var{function}} 13508is specified for an individual function). All of these functions have 13509corresponding versions prefixed with @code{__builtin_}. 13510 13511GCC provides built-in versions of the ISO C99 floating-point comparison 13512macros that avoid raising exceptions for unordered operands. They have 13513the same names as the standard macros ( @code{isgreater}, 13514@code{isgreaterequal}, @code{isless}, @code{islessequal}, 13515@code{islessgreater}, and @code{isunordered}) , with @code{__builtin_} 13516prefixed. We intend for a library implementor to be able to simply 13517@code{#define} each standard macro to its built-in equivalent. 13518In the same fashion, GCC provides @code{fpclassify}, @code{isfinite}, 13519@code{isinf_sign}, @code{isnormal} and @code{signbit} built-ins used with 13520@code{__builtin_} prefixed. The @code{isinf} and @code{isnan} 13521built-in functions appear both with and without the @code{__builtin_} prefix. 13522 13523GCC provides built-in versions of the ISO C99 floating-point rounding and 13524exceptions handling functions @code{fegetround}, @code{feclearexcept} and 13525@code{feraiseexcept}. They may not be available for all targets, and because 13526they need close interaction with libc internal values, they may not be available 13527for all target libcs, but in all cases they will gracefully fallback to libc 13528calls. These built-in functions appear both with and without the 13529@code{__builtin_} prefix. 13530 13531@deftypefn {Built-in Function} void *__builtin_alloca (size_t size) 13532The @code{__builtin_alloca} function must be called at block scope. 13533The function allocates an object @var{size} bytes large on the stack 13534of the calling function. The object is aligned on the default stack 13535alignment boundary for the target determined by the 13536@code{__BIGGEST_ALIGNMENT__} macro. The @code{__builtin_alloca} 13537function returns a pointer to the first byte of the allocated object. 13538The lifetime of the allocated object ends just before the calling 13539function returns to its caller. This is so even when 13540@code{__builtin_alloca} is called within a nested block. 13541 13542For example, the following function allocates eight objects of @code{n} 13543bytes each on the stack, storing a pointer to each in consecutive elements 13544of the array @code{a}. It then passes the array to function @code{g} 13545which can safely use the storage pointed to by each of the array elements. 13546 13547@smallexample 13548void f (unsigned n) 13549@{ 13550 void *a [8]; 13551 for (int i = 0; i != 8; ++i) 13552 a [i] = __builtin_alloca (n); 13553 13554 g (a, n); // @r{safe} 13555@} 13556@end smallexample 13557 13558Since the @code{__builtin_alloca} function doesn't validate its argument 13559it is the responsibility of its caller to make sure the argument doesn't 13560cause it to exceed the stack size limit. 13561The @code{__builtin_alloca} function is provided to make it possible to 13562allocate on the stack arrays of bytes with an upper bound that may be 13563computed at run time. Since C99 Variable Length Arrays offer 13564similar functionality under a portable, more convenient, and safer 13565interface they are recommended instead, in both C99 and C++ programs 13566where GCC provides them as an extension. 13567@xref{Variable Length}, for details. 13568 13569@end deftypefn 13570 13571@deftypefn {Built-in Function} void *__builtin_alloca_with_align (size_t size, size_t alignment) 13572The @code{__builtin_alloca_with_align} function must be called at block 13573scope. The function allocates an object @var{size} bytes large on 13574the stack of the calling function. The allocated object is aligned on 13575the boundary specified by the argument @var{alignment} whose unit is given 13576in bits (not bytes). The @var{size} argument must be positive and not 13577exceed the stack size limit. The @var{alignment} argument must be a constant 13578integer expression that evaluates to a power of 2 greater than or equal to 13579@code{CHAR_BIT} and less than some unspecified maximum. Invocations 13580with other values are rejected with an error indicating the valid bounds. 13581The function returns a pointer to the first byte of the allocated object. 13582The lifetime of the allocated object ends at the end of the block in which 13583the function was called. The allocated storage is released no later than 13584just before the calling function returns to its caller, but may be released 13585at the end of the block in which the function was called. 13586 13587For example, in the following function the call to @code{g} is unsafe 13588because when @code{overalign} is non-zero, the space allocated by 13589@code{__builtin_alloca_with_align} may have been released at the end 13590of the @code{if} statement in which it was called. 13591 13592@smallexample 13593void f (unsigned n, bool overalign) 13594@{ 13595 void *p; 13596 if (overalign) 13597 p = __builtin_alloca_with_align (n, 64 /* bits */); 13598 else 13599 p = __builtin_alloc (n); 13600 13601 g (p, n); // @r{unsafe} 13602@} 13603@end smallexample 13604 13605Since the @code{__builtin_alloca_with_align} function doesn't validate its 13606@var{size} argument it is the responsibility of its caller to make sure 13607the argument doesn't cause it to exceed the stack size limit. 13608The @code{__builtin_alloca_with_align} function is provided to make 13609it possible to allocate on the stack overaligned arrays of bytes with 13610an upper bound that may be computed at run time. Since C99 13611Variable Length Arrays offer the same functionality under 13612a portable, more convenient, and safer interface they are recommended 13613instead, in both C99 and C++ programs where GCC provides them as 13614an extension. @xref{Variable Length}, for details. 13615 13616@end deftypefn 13617 13618@deftypefn {Built-in Function} void *__builtin_alloca_with_align_and_max (size_t size, size_t alignment, size_t max_size) 13619Similar to @code{__builtin_alloca_with_align} but takes an extra argument 13620specifying an upper bound for @var{size} in case its value cannot be computed 13621at compile time, for use by @option{-fstack-usage}, @option{-Wstack-usage} 13622and @option{-Walloca-larger-than}. @var{max_size} must be a constant integer 13623expression, it has no effect on code generation and no attempt is made to 13624check its compatibility with @var{size}. 13625 13626@end deftypefn 13627 13628@deftypefn {Built-in Function} bool __builtin_has_attribute (@var{type-or-expression}, @var{attribute}) 13629The @code{__builtin_has_attribute} function evaluates to an integer constant 13630expression equal to @code{true} if the symbol or type referenced by 13631the @var{type-or-expression} argument has been declared with 13632the @var{attribute} referenced by the second argument. For 13633an @var{type-or-expression} argument that does not reference a symbol, 13634since attributes do not apply to expressions the built-in consider 13635the type of the argument. Neither argument is evaluated. 13636The @var{type-or-expression} argument is subject to the same 13637restrictions as the argument to @code{typeof} (@pxref{Typeof}). The 13638@var{attribute} argument is an attribute name optionally followed by 13639a comma-separated list of arguments enclosed in parentheses. Both forms 13640of attribute names---with and without double leading and trailing 13641underscores---are recognized. @xref{Attribute Syntax}, for details. 13642When no attribute arguments are specified for an attribute that expects 13643one or more arguments the function returns @code{true} if 13644@var{type-or-expression} has been declared with the attribute regardless 13645of the attribute argument values. Arguments provided for an attribute 13646that expects some are validated and matched up to the provided number. 13647The function returns @code{true} if all provided arguments match. For 13648example, the first call to the function below evaluates to @code{true} 13649because @code{x} is declared with the @code{aligned} attribute but 13650the second call evaluates to @code{false} because @code{x} is declared 13651@code{aligned (8)} and not @code{aligned (4)}. 13652 13653@smallexample 13654__attribute__ ((aligned (8))) int x; 13655_Static_assert (__builtin_has_attribute (x, aligned), "aligned"); 13656_Static_assert (!__builtin_has_attribute (x, aligned (4)), "aligned (4)"); 13657@end smallexample 13658 13659Due to a limitation the @code{__builtin_has_attribute} function returns 13660@code{false} for the @code{mode} attribute even if the type or variable 13661referenced by the @var{type-or-expression} argument was declared with one. 13662The function is also not supported with labels, and in C with enumerators. 13663 13664Note that unlike the @code{__has_attribute} preprocessor operator which 13665is suitable for use in @code{#if} preprocessing directives 13666@code{__builtin_has_attribute} is an intrinsic function that is not 13667recognized in such contexts. 13668 13669@end deftypefn 13670 13671@deftypefn {Built-in Function} @var{type} __builtin_speculation_safe_value (@var{type} val, @var{type} failval) 13672 13673This built-in function can be used to help mitigate against unsafe 13674speculative execution. @var{type} may be any integral type or any 13675pointer type. 13676 13677@enumerate 13678@item 13679If the CPU is not speculatively executing the code, then @var{val} 13680is returned. 13681@item 13682If the CPU is executing speculatively then either: 13683@itemize 13684@item 13685The function may cause execution to pause until it is known that the 13686code is no-longer being executed speculatively (in which case 13687@var{val} can be returned, as above); or 13688@item 13689The function may use target-dependent speculation tracking state to cause 13690@var{failval} to be returned when it is known that speculative 13691execution has incorrectly predicted a conditional branch operation. 13692@end itemize 13693@end enumerate 13694 13695The second argument, @var{failval}, is optional and defaults to zero 13696if omitted. 13697 13698GCC defines the preprocessor macro 13699@code{__HAVE_BUILTIN_SPECULATION_SAFE_VALUE} for targets that have been 13700updated to support this builtin. 13701 13702The built-in function can be used where a variable appears to be used in a 13703safe way, but the CPU, due to speculative execution may temporarily ignore 13704the bounds checks. Consider, for example, the following function: 13705 13706@smallexample 13707int array[500]; 13708int f (unsigned untrusted_index) 13709@{ 13710 if (untrusted_index < 500) 13711 return array[untrusted_index]; 13712 return 0; 13713@} 13714@end smallexample 13715 13716If the function is called repeatedly with @code{untrusted_index} less 13717than the limit of 500, then a branch predictor will learn that the 13718block of code that returns a value stored in @code{array} will be 13719executed. If the function is subsequently called with an 13720out-of-range value it will still try to execute that block of code 13721first until the CPU determines that the prediction was incorrect 13722(the CPU will unwind any incorrect operations at that point). 13723However, depending on how the result of the function is used, it might be 13724possible to leave traces in the cache that can reveal what was stored 13725at the out-of-bounds location. The built-in function can be used to 13726provide some protection against leaking data in this way by changing 13727the code to: 13728 13729@smallexample 13730int array[500]; 13731int f (unsigned untrusted_index) 13732@{ 13733 if (untrusted_index < 500) 13734 return array[__builtin_speculation_safe_value (untrusted_index)]; 13735 return 0; 13736@} 13737@end smallexample 13738 13739The built-in function will either cause execution to stall until the 13740conditional branch has been fully resolved, or it may permit 13741speculative execution to continue, but using 0 instead of 13742@code{untrusted_value} if that exceeds the limit. 13743 13744If accessing any memory location is potentially unsafe when speculative 13745execution is incorrect, then the code can be rewritten as 13746 13747@smallexample 13748int array[500]; 13749int f (unsigned untrusted_index) 13750@{ 13751 if (untrusted_index < 500) 13752 return *__builtin_speculation_safe_value (&array[untrusted_index], NULL); 13753 return 0; 13754@} 13755@end smallexample 13756 13757which will cause a @code{NULL} pointer to be used for the unsafe case. 13758 13759@end deftypefn 13760 13761@deftypefn {Built-in Function} int __builtin_types_compatible_p (@var{type1}, @var{type2}) 13762 13763You can use the built-in function @code{__builtin_types_compatible_p} to 13764determine whether two types are the same. 13765 13766This built-in function returns 1 if the unqualified versions of the 13767types @var{type1} and @var{type2} (which are types, not expressions) are 13768compatible, 0 otherwise. The result of this built-in function can be 13769used in integer constant expressions. 13770 13771This built-in function ignores top level qualifiers (e.g., @code{const}, 13772@code{volatile}). For example, @code{int} is equivalent to @code{const 13773int}. 13774 13775The type @code{int[]} and @code{int[5]} are compatible. On the other 13776hand, @code{int} and @code{char *} are not compatible, even if the size 13777of their types, on the particular architecture are the same. Also, the 13778amount of pointer indirection is taken into account when determining 13779similarity. Consequently, @code{short *} is not similar to 13780@code{short **}. Furthermore, two types that are typedefed are 13781considered compatible if their underlying types are compatible. 13782 13783An @code{enum} type is not considered to be compatible with another 13784@code{enum} type even if both are compatible with the same integer 13785type; this is what the C standard specifies. 13786For example, @code{enum @{foo, bar@}} is not similar to 13787@code{enum @{hot, dog@}}. 13788 13789You typically use this function in code whose execution varies 13790depending on the arguments' types. For example: 13791 13792@smallexample 13793#define foo(x) \ 13794 (@{ \ 13795 typeof (x) tmp = (x); \ 13796 if (__builtin_types_compatible_p (typeof (x), long double)) \ 13797 tmp = foo_long_double (tmp); \ 13798 else if (__builtin_types_compatible_p (typeof (x), double)) \ 13799 tmp = foo_double (tmp); \ 13800 else if (__builtin_types_compatible_p (typeof (x), float)) \ 13801 tmp = foo_float (tmp); \ 13802 else \ 13803 abort (); \ 13804 tmp; \ 13805 @}) 13806@end smallexample 13807 13808@emph{Note:} This construct is only available for C@. 13809 13810@end deftypefn 13811 13812@deftypefn {Built-in Function} @var{type} __builtin_call_with_static_chain (@var{call_exp}, @var{pointer_exp}) 13813 13814The @var{call_exp} expression must be a function call, and the 13815@var{pointer_exp} expression must be a pointer. The @var{pointer_exp} 13816is passed to the function call in the target's static chain location. 13817The result of builtin is the result of the function call. 13818 13819@emph{Note:} This builtin is only available for C@. 13820This builtin can be used to call Go closures from C. 13821 13822@end deftypefn 13823 13824@deftypefn {Built-in Function} @var{type} __builtin_choose_expr (@var{const_exp}, @var{exp1}, @var{exp2}) 13825 13826You can use the built-in function @code{__builtin_choose_expr} to 13827evaluate code depending on the value of a constant expression. This 13828built-in function returns @var{exp1} if @var{const_exp}, which is an 13829integer constant expression, is nonzero. Otherwise it returns @var{exp2}. 13830 13831This built-in function is analogous to the @samp{? :} operator in C, 13832except that the expression returned has its type unaltered by promotion 13833rules. Also, the built-in function does not evaluate the expression 13834that is not chosen. For example, if @var{const_exp} evaluates to @code{true}, 13835@var{exp2} is not evaluated even if it has side effects. 13836 13837This built-in function can return an lvalue if the chosen argument is an 13838lvalue. 13839 13840If @var{exp1} is returned, the return type is the same as @var{exp1}'s 13841type. Similarly, if @var{exp2} is returned, its return type is the same 13842as @var{exp2}. 13843 13844Example: 13845 13846@smallexample 13847#define foo(x) \ 13848 __builtin_choose_expr ( \ 13849 __builtin_types_compatible_p (typeof (x), double), \ 13850 foo_double (x), \ 13851 __builtin_choose_expr ( \ 13852 __builtin_types_compatible_p (typeof (x), float), \ 13853 foo_float (x), \ 13854 /* @r{The void expression results in a compile-time error} \ 13855 @r{when assigning the result to something.} */ \ 13856 (void)0)) 13857@end smallexample 13858 13859@emph{Note:} This construct is only available for C@. Furthermore, the 13860unused expression (@var{exp1} or @var{exp2} depending on the value of 13861@var{const_exp}) may still generate syntax errors. This may change in 13862future revisions. 13863 13864@end deftypefn 13865 13866@deftypefn {Built-in Function} @var{type} __builtin_tgmath (@var{functions}, @var{arguments}) 13867 13868The built-in function @code{__builtin_tgmath}, available only for C 13869and Objective-C, calls a function determined according to the rules of 13870@code{<tgmath.h>} macros. It is intended to be used in 13871implementations of that header, so that expansions of macros from that 13872header only expand each of their arguments once, to avoid problems 13873when calls to such macros are nested inside the arguments of other 13874calls to such macros; in addition, it results in better diagnostics 13875for invalid calls to @code{<tgmath.h>} macros than implementations 13876using other GNU C language features. For example, the @code{pow} 13877type-generic macro might be defined as: 13878 13879@smallexample 13880#define pow(a, b) __builtin_tgmath (powf, pow, powl, \ 13881 cpowf, cpow, cpowl, a, b) 13882@end smallexample 13883 13884The arguments to @code{__builtin_tgmath} are at least two pointers to 13885functions, followed by the arguments to the type-generic macro (which 13886will be passed as arguments to the selected function). All the 13887pointers to functions must be pointers to prototyped functions, none 13888of which may have variable arguments, and all of which must have the 13889same number of parameters; the number of parameters of the first 13890function determines how many arguments to @code{__builtin_tgmath} are 13891interpreted as function pointers, and how many as the arguments to the 13892called function. 13893 13894The types of the specified functions must all be different, but 13895related to each other in the same way as a set of functions that may 13896be selected between by a macro in @code{<tgmath.h>}. This means that 13897the functions are parameterized by a floating-point type @var{t}, 13898different for each such function. The function return types may all 13899be the same type, or they may be @var{t} for each function, or they 13900may be the real type corresponding to @var{t} for each function (if 13901some of the types @var{t} are complex). Likewise, for each parameter 13902position, the type of the parameter in that position may always be the 13903same type, or may be @var{t} for each function (this case must apply 13904for at least one parameter position), or may be the real type 13905corresponding to @var{t} for each function. 13906 13907The standard rules for @code{<tgmath.h>} macros are used to find a 13908common type @var{u} from the types of the arguments for parameters 13909whose types vary between the functions; complex integer types (a GNU 13910extension) are treated like @code{_Complex double} for this purpose 13911(or @code{_Complex _Float64} if all the function return types are the 13912same @code{_Float@var{n}} or @code{_Float@var{n}x} type). 13913If the function return types vary, or are all the same integer type, 13914the function called is the one for which @var{t} is @var{u}, and it is 13915an error if there is no such function. If the function return types 13916are all the same floating-point type, the type-generic macro is taken 13917to be one of those from TS 18661 that rounds the result to a narrower 13918type; if there is a function for which @var{t} is @var{u}, it is 13919called, and otherwise the first function, if any, for which @var{t} 13920has at least the range and precision of @var{u} is called, and it is 13921an error if there is no such function. 13922 13923@end deftypefn 13924 13925@deftypefn {Built-in Function} int __builtin_constant_p (@var{exp}) 13926You can use the built-in function @code{__builtin_constant_p} to 13927determine if a value is known to be constant at compile time and hence 13928that GCC can perform constant-folding on expressions involving that 13929value. The argument of the function is the value to test. The function 13930returns the integer 1 if the argument is known to be a compile-time 13931constant and 0 if it is not known to be a compile-time constant. A 13932return of 0 does not indicate that the value is @emph{not} a constant, 13933but merely that GCC cannot prove it is a constant with the specified 13934value of the @option{-O} option. 13935 13936You typically use this function in an embedded application where 13937memory is a critical resource. If you have some complex calculation, 13938you may want it to be folded if it involves constants, but need to call 13939a function if it does not. For example: 13940 13941@smallexample 13942#define Scale_Value(X) \ 13943 (__builtin_constant_p (X) \ 13944 ? ((X) * SCALE + OFFSET) : Scale (X)) 13945@end smallexample 13946 13947You may use this built-in function in either a macro or an inline 13948function. However, if you use it in an inlined function and pass an 13949argument of the function as the argument to the built-in, GCC 13950never returns 1 when you call the inline function with a string constant 13951or compound literal (@pxref{Compound Literals}) and does not return 1 13952when you pass a constant numeric value to the inline function unless you 13953specify the @option{-O} option. 13954 13955You may also use @code{__builtin_constant_p} in initializers for static 13956data. For instance, you can write 13957 13958@smallexample 13959static const int table[] = @{ 13960 __builtin_constant_p (EXPRESSION) ? (EXPRESSION) : -1, 13961 /* @r{@dots{}} */ 13962@}; 13963@end smallexample 13964 13965@noindent 13966This is an acceptable initializer even if @var{EXPRESSION} is not a 13967constant expression, including the case where 13968@code{__builtin_constant_p} returns 1 because @var{EXPRESSION} can be 13969folded to a constant but @var{EXPRESSION} contains operands that are 13970not otherwise permitted in a static initializer (for example, 13971@code{0 && foo ()}). GCC must be more conservative about evaluating the 13972built-in in this case, because it has no opportunity to perform 13973optimization. 13974@end deftypefn 13975 13976@deftypefn {Built-in Function} bool __builtin_is_constant_evaluated (void) 13977The @code{__builtin_is_constant_evaluated} function is available only 13978in C++. The built-in is intended to be used by implementations of 13979the @code{std::is_constant_evaluated} C++ function. Programs should make 13980use of the latter function rather than invoking the built-in directly. 13981 13982The main use case of the built-in is to determine whether a @code{constexpr} 13983function is being called in a @code{constexpr} context. A call to 13984the function evaluates to a core constant expression with the value 13985@code{true} if and only if it occurs within the evaluation of an expression 13986or conversion that is manifestly constant-evaluated as defined in the C++ 13987standard. Manifestly constant-evaluated contexts include constant-expressions, 13988the conditions of @code{constexpr if} statements, constraint-expressions, and 13989initializers of variables usable in constant expressions. For more details 13990refer to the latest revision of the C++ standard. 13991@end deftypefn 13992 13993@deftypefn {Built-in Function} void __builtin_clear_padding (@var{ptr}) 13994The built-in function @code{__builtin_clear_padding} function clears 13995padding bits inside of the object representation of object pointed by 13996@var{ptr}, which has to be a pointer. The value representation of the 13997object is not affected. The type of the object is assumed to be the type 13998the pointer points to. Inside of a union, the only cleared bits are 13999bits that are padding bits for all the union members. 14000 14001This built-in-function is useful if the padding bits of an object might 14002have intederminate values and the object representation needs to be 14003bitwise compared to some other object, for example for atomic operations. 14004 14005For C++, @var{ptr} argument type should be pointer to trivially-copyable 14006type, unless the argument is address of a variable or parameter, because 14007otherwise it isn't known if the type isn't just a base class whose padding 14008bits are reused or laid out differently in a derived class. 14009@end deftypefn 14010 14011@deftypefn {Built-in Function} @var{type} __builtin_bit_cast (@var{type}, @var{arg}) 14012The @code{__builtin_bit_cast} function is available only 14013in C++. The built-in is intended to be used by implementations of 14014the @code{std::bit_cast} C++ template function. Programs should make 14015use of the latter function rather than invoking the built-in directly. 14016 14017This built-in function allows reinterpreting the bits of the @var{arg} 14018argument as if it had type @var{type}. @var{type} and the type of the 14019@var{arg} argument need to be trivially copyable types with the same size. 14020When manifestly constant-evaluated, it performs extra diagnostics required 14021for @code{std::bit_cast} and returns a constant expression if @var{arg} 14022is a constant expression. For more details 14023refer to the latest revision of the C++ standard. 14024@end deftypefn 14025 14026@deftypefn {Built-in Function} long __builtin_expect (long @var{exp}, long @var{c}) 14027@opindex fprofile-arcs 14028You may use @code{__builtin_expect} to provide the compiler with 14029branch prediction information. In general, you should prefer to 14030use actual profile feedback for this (@option{-fprofile-arcs}), as 14031programmers are notoriously bad at predicting how their programs 14032actually perform. However, there are applications in which this 14033data is hard to collect. 14034 14035The return value is the value of @var{exp}, which should be an integral 14036expression. The semantics of the built-in are that it is expected that 14037@var{exp} == @var{c}. For example: 14038 14039@smallexample 14040if (__builtin_expect (x, 0)) 14041 foo (); 14042@end smallexample 14043 14044@noindent 14045indicates that we do not expect to call @code{foo}, since 14046we expect @code{x} to be zero. Since you are limited to integral 14047expressions for @var{exp}, you should use constructions such as 14048 14049@smallexample 14050if (__builtin_expect (ptr != NULL, 1)) 14051 foo (*ptr); 14052@end smallexample 14053 14054@noindent 14055when testing pointer or floating-point values. 14056 14057For the purposes of branch prediction optimizations, the probability that 14058a @code{__builtin_expect} expression is @code{true} is controlled by GCC's 14059@code{builtin-expect-probability} parameter, which defaults to 90%. 14060 14061You can also use @code{__builtin_expect_with_probability} to explicitly 14062assign a probability value to individual expressions. If the built-in 14063is used in a loop construct, the provided probability will influence 14064the expected number of iterations made by loop optimizations. 14065@end deftypefn 14066 14067@deftypefn {Built-in Function} long __builtin_expect_with_probability 14068(long @var{exp}, long @var{c}, double @var{probability}) 14069 14070This function has the same semantics as @code{__builtin_expect}, 14071but the caller provides the expected probability that @var{exp} == @var{c}. 14072The last argument, @var{probability}, is a floating-point value in the 14073range 0.0 to 1.0, inclusive. The @var{probability} argument must be 14074constant floating-point expression. 14075@end deftypefn 14076 14077@deftypefn {Built-in Function} void __builtin_trap (void) 14078This function causes the program to exit abnormally. GCC implements 14079this function by using a target-dependent mechanism (such as 14080intentionally executing an illegal instruction) or by calling 14081@code{abort}. The mechanism used may vary from release to release so 14082you should not rely on any particular implementation. 14083@end deftypefn 14084 14085@deftypefn {Built-in Function} void __builtin_unreachable (void) 14086If control flow reaches the point of the @code{__builtin_unreachable}, 14087the program is undefined. It is useful in situations where the 14088compiler cannot deduce the unreachability of the code. 14089 14090One such case is immediately following an @code{asm} statement that 14091either never terminates, or one that transfers control elsewhere 14092and never returns. In this example, without the 14093@code{__builtin_unreachable}, GCC issues a warning that control 14094reaches the end of a non-void function. It also generates code 14095to return after the @code{asm}. 14096 14097@smallexample 14098int f (int c, int v) 14099@{ 14100 if (c) 14101 @{ 14102 return v; 14103 @} 14104 else 14105 @{ 14106 asm("jmp error_handler"); 14107 __builtin_unreachable (); 14108 @} 14109@} 14110@end smallexample 14111 14112@noindent 14113Because the @code{asm} statement unconditionally transfers control out 14114of the function, control never reaches the end of the function 14115body. The @code{__builtin_unreachable} is in fact unreachable and 14116communicates this fact to the compiler. 14117 14118Another use for @code{__builtin_unreachable} is following a call a 14119function that never returns but that is not declared 14120@code{__attribute__((noreturn))}, as in this example: 14121 14122@smallexample 14123void function_that_never_returns (void); 14124 14125int g (int c) 14126@{ 14127 if (c) 14128 @{ 14129 return 1; 14130 @} 14131 else 14132 @{ 14133 function_that_never_returns (); 14134 __builtin_unreachable (); 14135 @} 14136@} 14137@end smallexample 14138 14139@end deftypefn 14140 14141@deftypefn {Built-in Function} @var{type} __builtin_assoc_barrier (@var{type} @var{expr}) 14142This built-in inhibits re-association of the floating-point expression 14143@var{expr} with expressions consuming the return value of the built-in. The 14144expression @var{expr} itself can be reordered, and the whole expression 14145@var{expr} can be reordered with operands after the barrier. The barrier is 14146only relevant when @code{-fassociative-math} is active, since otherwise 14147floating-point is not treated as associative. 14148 14149@smallexample 14150float x0 = a + b - b; 14151float x1 = __builtin_assoc_barrier(a + b) - b; 14152@end smallexample 14153 14154@noindent 14155means that, with @code{-fassociative-math}, @code{x0} can be optimized to 14156@code{x0 = a} but @code{x1} cannot. 14157@end deftypefn 14158 14159@deftypefn {Built-in Function} {void *} __builtin_assume_aligned (const void *@var{exp}, size_t @var{align}, ...) 14160This function returns its first argument, and allows the compiler 14161to assume that the returned pointer is at least @var{align} bytes 14162aligned. This built-in can have either two or three arguments, 14163if it has three, the third argument should have integer type, and 14164if it is nonzero means misalignment offset. For example: 14165 14166@smallexample 14167void *x = __builtin_assume_aligned (arg, 16); 14168@end smallexample 14169 14170@noindent 14171means that the compiler can assume @code{x}, set to @code{arg}, is at least 1417216-byte aligned, while: 14173 14174@smallexample 14175void *x = __builtin_assume_aligned (arg, 32, 8); 14176@end smallexample 14177 14178@noindent 14179means that the compiler can assume for @code{x}, set to @code{arg}, that 14180@code{(char *) x - 8} is 32-byte aligned. 14181@end deftypefn 14182 14183@deftypefn {Built-in Function} int __builtin_LINE () 14184This function is the equivalent of the preprocessor @code{__LINE__} 14185macro and returns a constant integer expression that evaluates to 14186the line number of the invocation of the built-in. When used as a C++ 14187default argument for a function @var{F}, it returns the line number 14188of the call to @var{F}. 14189@end deftypefn 14190 14191@deftypefn {Built-in Function} {const char *} __builtin_FUNCTION () 14192This function is the equivalent of the @code{__FUNCTION__} symbol 14193and returns an address constant pointing to the name of the function 14194from which the built-in was invoked, or the empty string if 14195the invocation is not at function scope. When used as a C++ default 14196argument for a function @var{F}, it returns the name of @var{F}'s 14197caller or the empty string if the call was not made at function 14198scope. 14199@end deftypefn 14200 14201@deftypefn {Built-in Function} {const char *} __builtin_FILE () 14202This function is the equivalent of the preprocessor @code{__FILE__} 14203macro and returns an address constant pointing to the file name 14204containing the invocation of the built-in, or the empty string if 14205the invocation is not at function scope. When used as a C++ default 14206argument for a function @var{F}, it returns the file name of the call 14207to @var{F} or the empty string if the call was not made at function 14208scope. 14209 14210For example, in the following, each call to function @code{foo} will 14211print a line similar to @code{"file.c:123: foo: message"} with the name 14212of the file and the line number of the @code{printf} call, the name of 14213the function @code{foo}, followed by the word @code{message}. 14214 14215@smallexample 14216const char* 14217function (const char *func = __builtin_FUNCTION ()) 14218@{ 14219 return func; 14220@} 14221 14222void foo (void) 14223@{ 14224 printf ("%s:%i: %s: message\n", file (), line (), function ()); 14225@} 14226@end smallexample 14227 14228@end deftypefn 14229 14230@deftypefn {Built-in Function} void __builtin___clear_cache (void *@var{begin}, void *@var{end}) 14231This function is used to flush the processor's instruction cache for 14232the region of memory between @var{begin} inclusive and @var{end} 14233exclusive. Some targets require that the instruction cache be 14234flushed, after modifying memory containing code, in order to obtain 14235deterministic behavior. 14236 14237If the target does not require instruction cache flushes, 14238@code{__builtin___clear_cache} has no effect. Otherwise either 14239instructions are emitted in-line to clear the instruction cache or a 14240call to the @code{__clear_cache} function in libgcc is made. 14241@end deftypefn 14242 14243@deftypefn {Built-in Function} void __builtin_prefetch (const void *@var{addr}, ...) 14244This function is used to minimize cache-miss latency by moving data into 14245a cache before it is accessed. 14246You can insert calls to @code{__builtin_prefetch} into code for which 14247you know addresses of data in memory that is likely to be accessed soon. 14248If the target supports them, data prefetch instructions are generated. 14249If the prefetch is done early enough before the access then the data will 14250be in the cache by the time it is accessed. 14251 14252The value of @var{addr} is the address of the memory to prefetch. 14253There are two optional arguments, @var{rw} and @var{locality}. 14254The value of @var{rw} is a compile-time constant one or zero; one 14255means that the prefetch is preparing for a write to the memory address 14256and zero, the default, means that the prefetch is preparing for a read. 14257The value @var{locality} must be a compile-time constant integer between 14258zero and three. A value of zero means that the data has no temporal 14259locality, so it need not be left in the cache after the access. A value 14260of three means that the data has a high degree of temporal locality and 14261should be left in all levels of cache possible. Values of one and two 14262mean, respectively, a low or moderate degree of temporal locality. The 14263default is three. 14264 14265@smallexample 14266for (i = 0; i < n; i++) 14267 @{ 14268 a[i] = a[i] + b[i]; 14269 __builtin_prefetch (&a[i+j], 1, 1); 14270 __builtin_prefetch (&b[i+j], 0, 1); 14271 /* @r{@dots{}} */ 14272 @} 14273@end smallexample 14274 14275Data prefetch does not generate faults if @var{addr} is invalid, but 14276the address expression itself must be valid. For example, a prefetch 14277of @code{p->next} does not fault if @code{p->next} is not a valid 14278address, but evaluation faults if @code{p} is not a valid address. 14279 14280If the target does not support data prefetch, the address expression 14281is evaluated if it includes side effects but no other code is generated 14282and GCC does not issue a warning. 14283@end deftypefn 14284 14285@deftypefn {Built-in Function}{size_t} __builtin_object_size (const void * @var{ptr}, int @var{type}) 14286Returns the size of an object pointed to by @var{ptr}. @xref{Object Size 14287Checking}, for a detailed description of the function. 14288@end deftypefn 14289 14290@deftypefn {Built-in Function} double __builtin_huge_val (void) 14291Returns a positive infinity, if supported by the floating-point format, 14292else @code{DBL_MAX}. This function is suitable for implementing the 14293ISO C macro @code{HUGE_VAL}. 14294@end deftypefn 14295 14296@deftypefn {Built-in Function} float __builtin_huge_valf (void) 14297Similar to @code{__builtin_huge_val}, except the return type is @code{float}. 14298@end deftypefn 14299 14300@deftypefn {Built-in Function} {long double} __builtin_huge_vall (void) 14301Similar to @code{__builtin_huge_val}, except the return 14302type is @code{long double}. 14303@end deftypefn 14304 14305@deftypefn {Built-in Function} _Float@var{n} __builtin_huge_valf@var{n} (void) 14306Similar to @code{__builtin_huge_val}, except the return type is 14307@code{_Float@var{n}}. 14308@end deftypefn 14309 14310@deftypefn {Built-in Function} _Float@var{n}x __builtin_huge_valf@var{n}x (void) 14311Similar to @code{__builtin_huge_val}, except the return type is 14312@code{_Float@var{n}x}. 14313@end deftypefn 14314 14315@deftypefn {Built-in Function} int __builtin_fpclassify (int, int, int, int, int, ...) 14316This built-in implements the C99 fpclassify functionality. The first 14317five int arguments should be the target library's notion of the 14318possible FP classes and are used for return values. They must be 14319constant values and they must appear in this order: @code{FP_NAN}, 14320@code{FP_INFINITE}, @code{FP_NORMAL}, @code{FP_SUBNORMAL} and 14321@code{FP_ZERO}. The ellipsis is for exactly one floating-point value 14322to classify. GCC treats the last argument as type-generic, which 14323means it does not do default promotion from float to double. 14324@end deftypefn 14325 14326@deftypefn {Built-in Function} double __builtin_inf (void) 14327Similar to @code{__builtin_huge_val}, except a warning is generated 14328if the target floating-point format does not support infinities. 14329@end deftypefn 14330 14331@deftypefn {Built-in Function} _Decimal32 __builtin_infd32 (void) 14332Similar to @code{__builtin_inf}, except the return type is @code{_Decimal32}. 14333@end deftypefn 14334 14335@deftypefn {Built-in Function} _Decimal64 __builtin_infd64 (void) 14336Similar to @code{__builtin_inf}, except the return type is @code{_Decimal64}. 14337@end deftypefn 14338 14339@deftypefn {Built-in Function} _Decimal128 __builtin_infd128 (void) 14340Similar to @code{__builtin_inf}, except the return type is @code{_Decimal128}. 14341@end deftypefn 14342 14343@deftypefn {Built-in Function} float __builtin_inff (void) 14344Similar to @code{__builtin_inf}, except the return type is @code{float}. 14345This function is suitable for implementing the ISO C99 macro @code{INFINITY}. 14346@end deftypefn 14347 14348@deftypefn {Built-in Function} {long double} __builtin_infl (void) 14349Similar to @code{__builtin_inf}, except the return 14350type is @code{long double}. 14351@end deftypefn 14352 14353@deftypefn {Built-in Function} _Float@var{n} __builtin_inff@var{n} (void) 14354Similar to @code{__builtin_inf}, except the return 14355type is @code{_Float@var{n}}. 14356@end deftypefn 14357 14358@deftypefn {Built-in Function} _Float@var{n} __builtin_inff@var{n}x (void) 14359Similar to @code{__builtin_inf}, except the return 14360type is @code{_Float@var{n}x}. 14361@end deftypefn 14362 14363@deftypefn {Built-in Function} int __builtin_isinf_sign (...) 14364Similar to @code{isinf}, except the return value is -1 for 14365an argument of @code{-Inf} and 1 for an argument of @code{+Inf}. 14366Note while the parameter list is an 14367ellipsis, this function only accepts exactly one floating-point 14368argument. GCC treats this parameter as type-generic, which means it 14369does not do default promotion from float to double. 14370@end deftypefn 14371 14372@deftypefn {Built-in Function} double __builtin_nan (const char *str) 14373This is an implementation of the ISO C99 function @code{nan}. 14374 14375Since ISO C99 defines this function in terms of @code{strtod}, which we 14376do not implement, a description of the parsing is in order. The string 14377is parsed as by @code{strtol}; that is, the base is recognized by 14378leading @samp{0} or @samp{0x} prefixes. The number parsed is placed 14379in the significand such that the least significant bit of the number 14380is at the least significant bit of the significand. The number is 14381truncated to fit the significand field provided. The significand is 14382forced to be a quiet NaN@. 14383 14384This function, if given a string literal all of which would have been 14385consumed by @code{strtol}, is evaluated early enough that it is considered a 14386compile-time constant. 14387@end deftypefn 14388 14389@deftypefn {Built-in Function} _Decimal32 __builtin_nand32 (const char *str) 14390Similar to @code{__builtin_nan}, except the return type is @code{_Decimal32}. 14391@end deftypefn 14392 14393@deftypefn {Built-in Function} _Decimal64 __builtin_nand64 (const char *str) 14394Similar to @code{__builtin_nan}, except the return type is @code{_Decimal64}. 14395@end deftypefn 14396 14397@deftypefn {Built-in Function} _Decimal128 __builtin_nand128 (const char *str) 14398Similar to @code{__builtin_nan}, except the return type is @code{_Decimal128}. 14399@end deftypefn 14400 14401@deftypefn {Built-in Function} float __builtin_nanf (const char *str) 14402Similar to @code{__builtin_nan}, except the return type is @code{float}. 14403@end deftypefn 14404 14405@deftypefn {Built-in Function} {long double} __builtin_nanl (const char *str) 14406Similar to @code{__builtin_nan}, except the return type is @code{long double}. 14407@end deftypefn 14408 14409@deftypefn {Built-in Function} _Float@var{n} __builtin_nanf@var{n} (const char *str) 14410Similar to @code{__builtin_nan}, except the return type is 14411@code{_Float@var{n}}. 14412@end deftypefn 14413 14414@deftypefn {Built-in Function} _Float@var{n}x __builtin_nanf@var{n}x (const char *str) 14415Similar to @code{__builtin_nan}, except the return type is 14416@code{_Float@var{n}x}. 14417@end deftypefn 14418 14419@deftypefn {Built-in Function} double __builtin_nans (const char *str) 14420Similar to @code{__builtin_nan}, except the significand is forced 14421to be a signaling NaN@. The @code{nans} function is proposed by 14422@uref{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n965.htm,,WG14 N965}. 14423@end deftypefn 14424 14425@deftypefn {Built-in Function} _Decimal32 __builtin_nansd32 (const char *str) 14426Similar to @code{__builtin_nans}, except the return type is @code{_Decimal32}. 14427@end deftypefn 14428 14429@deftypefn {Built-in Function} _Decimal64 __builtin_nansd64 (const char *str) 14430Similar to @code{__builtin_nans}, except the return type is @code{_Decimal64}. 14431@end deftypefn 14432 14433@deftypefn {Built-in Function} _Decimal128 __builtin_nansd128 (const char *str) 14434Similar to @code{__builtin_nans}, except the return type is @code{_Decimal128}. 14435@end deftypefn 14436 14437@deftypefn {Built-in Function} float __builtin_nansf (const char *str) 14438Similar to @code{__builtin_nans}, except the return type is @code{float}. 14439@end deftypefn 14440 14441@deftypefn {Built-in Function} {long double} __builtin_nansl (const char *str) 14442Similar to @code{__builtin_nans}, except the return type is @code{long double}. 14443@end deftypefn 14444 14445@deftypefn {Built-in Function} _Float@var{n} __builtin_nansf@var{n} (const char *str) 14446Similar to @code{__builtin_nans}, except the return type is 14447@code{_Float@var{n}}. 14448@end deftypefn 14449 14450@deftypefn {Built-in Function} _Float@var{n}x __builtin_nansf@var{n}x (const char *str) 14451Similar to @code{__builtin_nans}, except the return type is 14452@code{_Float@var{n}x}. 14453@end deftypefn 14454 14455@deftypefn {Built-in Function} int __builtin_ffs (int x) 14456Returns one plus the index of the least significant 1-bit of @var{x}, or 14457if @var{x} is zero, returns zero. 14458@end deftypefn 14459 14460@deftypefn {Built-in Function} int __builtin_clz (unsigned int x) 14461Returns the number of leading 0-bits in @var{x}, starting at the most 14462significant bit position. If @var{x} is 0, the result is undefined. 14463@end deftypefn 14464 14465@deftypefn {Built-in Function} int __builtin_ctz (unsigned int x) 14466Returns the number of trailing 0-bits in @var{x}, starting at the least 14467significant bit position. If @var{x} is 0, the result is undefined. 14468@end deftypefn 14469 14470@deftypefn {Built-in Function} int __builtin_clrsb (int x) 14471Returns the number of leading redundant sign bits in @var{x}, i.e.@: the 14472number of bits following the most significant bit that are identical 14473to it. There are no special cases for 0 or other values. 14474@end deftypefn 14475 14476@deftypefn {Built-in Function} int __builtin_popcount (unsigned int x) 14477Returns the number of 1-bits in @var{x}. 14478@end deftypefn 14479 14480@deftypefn {Built-in Function} int __builtin_parity (unsigned int x) 14481Returns the parity of @var{x}, i.e.@: the number of 1-bits in @var{x} 14482modulo 2. 14483@end deftypefn 14484 14485@deftypefn {Built-in Function} int __builtin_ffsl (long) 14486Similar to @code{__builtin_ffs}, except the argument type is 14487@code{long}. 14488@end deftypefn 14489 14490@deftypefn {Built-in Function} int __builtin_clzl (unsigned long) 14491Similar to @code{__builtin_clz}, except the argument type is 14492@code{unsigned long}. 14493@end deftypefn 14494 14495@deftypefn {Built-in Function} int __builtin_ctzl (unsigned long) 14496Similar to @code{__builtin_ctz}, except the argument type is 14497@code{unsigned long}. 14498@end deftypefn 14499 14500@deftypefn {Built-in Function} int __builtin_clrsbl (long) 14501Similar to @code{__builtin_clrsb}, except the argument type is 14502@code{long}. 14503@end deftypefn 14504 14505@deftypefn {Built-in Function} int __builtin_popcountl (unsigned long) 14506Similar to @code{__builtin_popcount}, except the argument type is 14507@code{unsigned long}. 14508@end deftypefn 14509 14510@deftypefn {Built-in Function} int __builtin_parityl (unsigned long) 14511Similar to @code{__builtin_parity}, except the argument type is 14512@code{unsigned long}. 14513@end deftypefn 14514 14515@deftypefn {Built-in Function} int __builtin_ffsll (long long) 14516Similar to @code{__builtin_ffs}, except the argument type is 14517@code{long long}. 14518@end deftypefn 14519 14520@deftypefn {Built-in Function} int __builtin_clzll (unsigned long long) 14521Similar to @code{__builtin_clz}, except the argument type is 14522@code{unsigned long long}. 14523@end deftypefn 14524 14525@deftypefn {Built-in Function} int __builtin_ctzll (unsigned long long) 14526Similar to @code{__builtin_ctz}, except the argument type is 14527@code{unsigned long long}. 14528@end deftypefn 14529 14530@deftypefn {Built-in Function} int __builtin_clrsbll (long long) 14531Similar to @code{__builtin_clrsb}, except the argument type is 14532@code{long long}. 14533@end deftypefn 14534 14535@deftypefn {Built-in Function} int __builtin_popcountll (unsigned long long) 14536Similar to @code{__builtin_popcount}, except the argument type is 14537@code{unsigned long long}. 14538@end deftypefn 14539 14540@deftypefn {Built-in Function} int __builtin_parityll (unsigned long long) 14541Similar to @code{__builtin_parity}, except the argument type is 14542@code{unsigned long long}. 14543@end deftypefn 14544 14545@deftypefn {Built-in Function} double __builtin_powi (double, int) 14546Returns the first argument raised to the power of the second. Unlike the 14547@code{pow} function no guarantees about precision and rounding are made. 14548@end deftypefn 14549 14550@deftypefn {Built-in Function} float __builtin_powif (float, int) 14551Similar to @code{__builtin_powi}, except the argument and return types 14552are @code{float}. 14553@end deftypefn 14554 14555@deftypefn {Built-in Function} {long double} __builtin_powil (long double, int) 14556Similar to @code{__builtin_powi}, except the argument and return types 14557are @code{long double}. 14558@end deftypefn 14559 14560@deftypefn {Built-in Function} uint16_t __builtin_bswap16 (uint16_t x) 14561Returns @var{x} with the order of the bytes reversed; for example, 14562@code{0xaabb} becomes @code{0xbbaa}. Byte here always means 14563exactly 8 bits. 14564@end deftypefn 14565 14566@deftypefn {Built-in Function} uint32_t __builtin_bswap32 (uint32_t x) 14567Similar to @code{__builtin_bswap16}, except the argument and return types 14568are 32-bit. 14569@end deftypefn 14570 14571@deftypefn {Built-in Function} uint64_t __builtin_bswap64 (uint64_t x) 14572Similar to @code{__builtin_bswap32}, except the argument and return types 14573are 64-bit. 14574@end deftypefn 14575 14576@deftypefn {Built-in Function} uint128_t __builtin_bswap128 (uint128_t x) 14577Similar to @code{__builtin_bswap64}, except the argument and return types 14578are 128-bit. Only supported on targets when 128-bit types are supported. 14579@end deftypefn 14580 14581 14582@deftypefn {Built-in Function} Pmode __builtin_extend_pointer (void * x) 14583On targets where the user visible pointer size is smaller than the size 14584of an actual hardware address this function returns the extended user 14585pointer. Targets where this is true included ILP32 mode on x86_64 or 14586Aarch64. This function is mainly useful when writing inline assembly 14587code. 14588@end deftypefn 14589 14590@deftypefn {Built-in Function} int __builtin_goacc_parlevel_id (int x) 14591Returns the openacc gang, worker or vector id depending on whether @var{x} is 145920, 1 or 2. 14593@end deftypefn 14594 14595@deftypefn {Built-in Function} int __builtin_goacc_parlevel_size (int x) 14596Returns the openacc gang, worker or vector size depending on whether @var{x} is 145970, 1 or 2. 14598@end deftypefn 14599 14600@node Target Builtins 14601@section Built-in Functions Specific to Particular Target Machines 14602 14603On some target machines, GCC supports many built-in functions specific 14604to those machines. Generally these generate calls to specific machine 14605instructions, but allow the compiler to schedule those calls. 14606 14607@menu 14608* AArch64 Built-in Functions:: 14609* Alpha Built-in Functions:: 14610* Altera Nios II Built-in Functions:: 14611* ARC Built-in Functions:: 14612* ARC SIMD Built-in Functions:: 14613* ARM iWMMXt Built-in Functions:: 14614* ARM C Language Extensions (ACLE):: 14615* ARM Floating Point Status and Control Intrinsics:: 14616* ARM ARMv8-M Security Extensions:: 14617* AVR Built-in Functions:: 14618* Blackfin Built-in Functions:: 14619* BPF Built-in Functions:: 14620* FR-V Built-in Functions:: 14621* LoongArch Base Built-in Functions:: 14622* MIPS DSP Built-in Functions:: 14623* MIPS Paired-Single Support:: 14624* MIPS Loongson Built-in Functions:: 14625* MIPS SIMD Architecture (MSA) Support:: 14626* Other MIPS Built-in Functions:: 14627* MSP430 Built-in Functions:: 14628* NDS32 Built-in Functions:: 14629* picoChip Built-in Functions:: 14630* Basic PowerPC Built-in Functions:: 14631* PowerPC AltiVec/VSX Built-in Functions:: 14632* PowerPC Hardware Transactional Memory Built-in Functions:: 14633* PowerPC Atomic Memory Operation Functions:: 14634* PowerPC Matrix-Multiply Assist Built-in Functions:: 14635* PRU Built-in Functions:: 14636* RISC-V Built-in Functions:: 14637* RX Built-in Functions:: 14638* S/390 System z Built-in Functions:: 14639* SH Built-in Functions:: 14640* SPARC VIS Built-in Functions:: 14641* TI C6X Built-in Functions:: 14642* TILE-Gx Built-in Functions:: 14643* TILEPro Built-in Functions:: 14644* x86 Built-in Functions:: 14645* x86 transactional memory intrinsics:: 14646* x86 control-flow protection intrinsics:: 14647@end menu 14648 14649@node AArch64 Built-in Functions 14650@subsection AArch64 Built-in Functions 14651 14652These built-in functions are available for the AArch64 family of 14653processors. 14654@smallexample 14655unsigned int __builtin_aarch64_get_fpcr (); 14656void __builtin_aarch64_set_fpcr (unsigned int); 14657unsigned int __builtin_aarch64_get_fpsr (); 14658void __builtin_aarch64_set_fpsr (unsigned int); 14659 14660unsigned long long __builtin_aarch64_get_fpcr64 (); 14661void __builtin_aarch64_set_fpcr64 (unsigned long long); 14662unsigned long long __builtin_aarch64_get_fpsr64 (); 14663void __builtin_aarch64_set_fpsr64 (unsigned long long); 14664@end smallexample 14665 14666@node Alpha Built-in Functions 14667@subsection Alpha Built-in Functions 14668 14669These built-in functions are available for the Alpha family of 14670processors, depending on the command-line switches used. 14671 14672The following built-in functions are always available. They 14673all generate the machine instruction that is part of the name. 14674 14675@smallexample 14676long __builtin_alpha_implver (void); 14677long __builtin_alpha_rpcc (void); 14678long __builtin_alpha_amask (long); 14679long __builtin_alpha_cmpbge (long, long); 14680long __builtin_alpha_extbl (long, long); 14681long __builtin_alpha_extwl (long, long); 14682long __builtin_alpha_extll (long, long); 14683long __builtin_alpha_extql (long, long); 14684long __builtin_alpha_extwh (long, long); 14685long __builtin_alpha_extlh (long, long); 14686long __builtin_alpha_extqh (long, long); 14687long __builtin_alpha_insbl (long, long); 14688long __builtin_alpha_inswl (long, long); 14689long __builtin_alpha_insll (long, long); 14690long __builtin_alpha_insql (long, long); 14691long __builtin_alpha_inswh (long, long); 14692long __builtin_alpha_inslh (long, long); 14693long __builtin_alpha_insqh (long, long); 14694long __builtin_alpha_mskbl (long, long); 14695long __builtin_alpha_mskwl (long, long); 14696long __builtin_alpha_mskll (long, long); 14697long __builtin_alpha_mskql (long, long); 14698long __builtin_alpha_mskwh (long, long); 14699long __builtin_alpha_msklh (long, long); 14700long __builtin_alpha_mskqh (long, long); 14701long __builtin_alpha_umulh (long, long); 14702long __builtin_alpha_zap (long, long); 14703long __builtin_alpha_zapnot (long, long); 14704@end smallexample 14705 14706The following built-in functions are always with @option{-mmax} 14707or @option{-mcpu=@var{cpu}} where @var{cpu} is @code{pca56} or 14708later. They all generate the machine instruction that is part 14709of the name. 14710 14711@smallexample 14712long __builtin_alpha_pklb (long); 14713long __builtin_alpha_pkwb (long); 14714long __builtin_alpha_unpkbl (long); 14715long __builtin_alpha_unpkbw (long); 14716long __builtin_alpha_minub8 (long, long); 14717long __builtin_alpha_minsb8 (long, long); 14718long __builtin_alpha_minuw4 (long, long); 14719long __builtin_alpha_minsw4 (long, long); 14720long __builtin_alpha_maxub8 (long, long); 14721long __builtin_alpha_maxsb8 (long, long); 14722long __builtin_alpha_maxuw4 (long, long); 14723long __builtin_alpha_maxsw4 (long, long); 14724long __builtin_alpha_perr (long, long); 14725@end smallexample 14726 14727The following built-in functions are always with @option{-mcix} 14728or @option{-mcpu=@var{cpu}} where @var{cpu} is @code{ev67} or 14729later. They all generate the machine instruction that is part 14730of the name. 14731 14732@smallexample 14733long __builtin_alpha_cttz (long); 14734long __builtin_alpha_ctlz (long); 14735long __builtin_alpha_ctpop (long); 14736@end smallexample 14737 14738The following built-in functions are available on systems that use the OSF/1 14739PALcode. Normally they invoke the @code{rduniq} and @code{wruniq} 14740PAL calls, but when invoked with @option{-mtls-kernel}, they invoke 14741@code{rdval} and @code{wrval}. 14742 14743@smallexample 14744void *__builtin_thread_pointer (void); 14745void __builtin_set_thread_pointer (void *); 14746@end smallexample 14747 14748@node Altera Nios II Built-in Functions 14749@subsection Altera Nios II Built-in Functions 14750 14751These built-in functions are available for the Altera Nios II 14752family of processors. 14753 14754The following built-in functions are always available. They 14755all generate the machine instruction that is part of the name. 14756 14757@example 14758int __builtin_ldbio (volatile const void *); 14759int __builtin_ldbuio (volatile const void *); 14760int __builtin_ldhio (volatile const void *); 14761int __builtin_ldhuio (volatile const void *); 14762int __builtin_ldwio (volatile const void *); 14763void __builtin_stbio (volatile void *, int); 14764void __builtin_sthio (volatile void *, int); 14765void __builtin_stwio (volatile void *, int); 14766void __builtin_sync (void); 14767int __builtin_rdctl (int); 14768int __builtin_rdprs (int, int); 14769void __builtin_wrctl (int, int); 14770void __builtin_flushd (volatile void *); 14771void __builtin_flushda (volatile void *); 14772int __builtin_wrpie (int); 14773void __builtin_eni (int); 14774int __builtin_ldex (volatile const void *); 14775int __builtin_stex (volatile void *, int); 14776int __builtin_ldsex (volatile const void *); 14777int __builtin_stsex (volatile void *, int); 14778@end example 14779 14780The following built-in functions are always available. They 14781all generate a Nios II Custom Instruction. The name of the 14782function represents the types that the function takes and 14783returns. The letter before the @code{n} is the return type 14784or void if absent. The @code{n} represents the first parameter 14785to all the custom instructions, the custom instruction number. 14786The two letters after the @code{n} represent the up to two 14787parameters to the function. 14788 14789The letters represent the following data types: 14790@table @code 14791@item <no letter> 14792@code{void} for return type and no parameter for parameter types. 14793 14794@item i 14795@code{int} for return type and parameter type 14796 14797@item f 14798@code{float} for return type and parameter type 14799 14800@item p 14801@code{void *} for return type and parameter type 14802 14803@end table 14804 14805And the function names are: 14806@example 14807void __builtin_custom_n (void); 14808void __builtin_custom_ni (int); 14809void __builtin_custom_nf (float); 14810void __builtin_custom_np (void *); 14811void __builtin_custom_nii (int, int); 14812void __builtin_custom_nif (int, float); 14813void __builtin_custom_nip (int, void *); 14814void __builtin_custom_nfi (float, int); 14815void __builtin_custom_nff (float, float); 14816void __builtin_custom_nfp (float, void *); 14817void __builtin_custom_npi (void *, int); 14818void __builtin_custom_npf (void *, float); 14819void __builtin_custom_npp (void *, void *); 14820int __builtin_custom_in (void); 14821int __builtin_custom_ini (int); 14822int __builtin_custom_inf (float); 14823int __builtin_custom_inp (void *); 14824int __builtin_custom_inii (int, int); 14825int __builtin_custom_inif (int, float); 14826int __builtin_custom_inip (int, void *); 14827int __builtin_custom_infi (float, int); 14828int __builtin_custom_inff (float, float); 14829int __builtin_custom_infp (float, void *); 14830int __builtin_custom_inpi (void *, int); 14831int __builtin_custom_inpf (void *, float); 14832int __builtin_custom_inpp (void *, void *); 14833float __builtin_custom_fn (void); 14834float __builtin_custom_fni (int); 14835float __builtin_custom_fnf (float); 14836float __builtin_custom_fnp (void *); 14837float __builtin_custom_fnii (int, int); 14838float __builtin_custom_fnif (int, float); 14839float __builtin_custom_fnip (int, void *); 14840float __builtin_custom_fnfi (float, int); 14841float __builtin_custom_fnff (float, float); 14842float __builtin_custom_fnfp (float, void *); 14843float __builtin_custom_fnpi (void *, int); 14844float __builtin_custom_fnpf (void *, float); 14845float __builtin_custom_fnpp (void *, void *); 14846void * __builtin_custom_pn (void); 14847void * __builtin_custom_pni (int); 14848void * __builtin_custom_pnf (float); 14849void * __builtin_custom_pnp (void *); 14850void * __builtin_custom_pnii (int, int); 14851void * __builtin_custom_pnif (int, float); 14852void * __builtin_custom_pnip (int, void *); 14853void * __builtin_custom_pnfi (float, int); 14854void * __builtin_custom_pnff (float, float); 14855void * __builtin_custom_pnfp (float, void *); 14856void * __builtin_custom_pnpi (void *, int); 14857void * __builtin_custom_pnpf (void *, float); 14858void * __builtin_custom_pnpp (void *, void *); 14859@end example 14860 14861@node ARC Built-in Functions 14862@subsection ARC Built-in Functions 14863 14864The following built-in functions are provided for ARC targets. The 14865built-ins generate the corresponding assembly instructions. In the 14866examples given below, the generated code often requires an operand or 14867result to be in a register. Where necessary further code will be 14868generated to ensure this is true, but for brevity this is not 14869described in each case. 14870 14871@emph{Note:} Using a built-in to generate an instruction not supported 14872by a target may cause problems. At present the compiler is not 14873guaranteed to detect such misuse, and as a result an internal compiler 14874error may be generated. 14875 14876@deftypefn {Built-in Function} int __builtin_arc_aligned (void *@var{val}, int @var{alignval}) 14877Return 1 if @var{val} is known to have the byte alignment given 14878by @var{alignval}, otherwise return 0. 14879Note that this is different from 14880@smallexample 14881__alignof__(*(char *)@var{val}) >= alignval 14882@end smallexample 14883because __alignof__ sees only the type of the dereference, whereas 14884__builtin_arc_align uses alignment information from the pointer 14885as well as from the pointed-to type. 14886The information available will depend on optimization level. 14887@end deftypefn 14888 14889@deftypefn {Built-in Function} void __builtin_arc_brk (void) 14890Generates 14891@example 14892brk 14893@end example 14894@end deftypefn 14895 14896@deftypefn {Built-in Function} {unsigned int} __builtin_arc_core_read (unsigned int @var{regno}) 14897The operand is the number of a register to be read. Generates: 14898@example 14899mov @var{dest}, r@var{regno} 14900@end example 14901where the value in @var{dest} will be the result returned from the 14902built-in. 14903@end deftypefn 14904 14905@deftypefn {Built-in Function} void __builtin_arc_core_write (unsigned int @var{regno}, unsigned int @var{val}) 14906The first operand is the number of a register to be written, the 14907second operand is a compile time constant to write into that 14908register. Generates: 14909@example 14910mov r@var{regno}, @var{val} 14911@end example 14912@end deftypefn 14913 14914@deftypefn {Built-in Function} int __builtin_arc_divaw (int @var{a}, int @var{b}) 14915Only available if either @option{-mcpu=ARC700} or @option{-meA} is set. 14916Generates: 14917@example 14918divaw @var{dest}, @var{a}, @var{b} 14919@end example 14920where the value in @var{dest} will be the result returned from the 14921built-in. 14922@end deftypefn 14923 14924@deftypefn {Built-in Function} void __builtin_arc_flag (unsigned int @var{a}) 14925Generates 14926@example 14927flag @var{a} 14928@end example 14929@end deftypefn 14930 14931@deftypefn {Built-in Function} {unsigned int} __builtin_arc_lr (unsigned int @var{auxr}) 14932The operand, @var{auxv}, is the address of an auxiliary register and 14933must be a compile time constant. Generates: 14934@example 14935lr @var{dest}, [@var{auxr}] 14936@end example 14937Where the value in @var{dest} will be the result returned from the 14938built-in. 14939@end deftypefn 14940 14941@deftypefn {Built-in Function} void __builtin_arc_mul64 (int @var{a}, int @var{b}) 14942Only available with @option{-mmul64}. Generates: 14943@example 14944mul64 @var{a}, @var{b} 14945@end example 14946@end deftypefn 14947 14948@deftypefn {Built-in Function} void __builtin_arc_mulu64 (unsigned int @var{a}, unsigned int @var{b}) 14949Only available with @option{-mmul64}. Generates: 14950@example 14951mulu64 @var{a}, @var{b} 14952@end example 14953@end deftypefn 14954 14955@deftypefn {Built-in Function} void __builtin_arc_nop (void) 14956Generates: 14957@example 14958nop 14959@end example 14960@end deftypefn 14961 14962@deftypefn {Built-in Function} int __builtin_arc_norm (int @var{src}) 14963Only valid if the @samp{norm} instruction is available through the 14964@option{-mnorm} option or by default with @option{-mcpu=ARC700}. 14965Generates: 14966@example 14967norm @var{dest}, @var{src} 14968@end example 14969Where the value in @var{dest} will be the result returned from the 14970built-in. 14971@end deftypefn 14972 14973@deftypefn {Built-in Function} {short int} __builtin_arc_normw (short int @var{src}) 14974Only valid if the @samp{normw} instruction is available through the 14975@option{-mnorm} option or by default with @option{-mcpu=ARC700}. 14976Generates: 14977@example 14978normw @var{dest}, @var{src} 14979@end example 14980Where the value in @var{dest} will be the result returned from the 14981built-in. 14982@end deftypefn 14983 14984@deftypefn {Built-in Function} void __builtin_arc_rtie (void) 14985Generates: 14986@example 14987rtie 14988@end example 14989@end deftypefn 14990 14991@deftypefn {Built-in Function} void __builtin_arc_sleep (int @var{a} 14992Generates: 14993@example 14994sleep @var{a} 14995@end example 14996@end deftypefn 14997 14998@deftypefn {Built-in Function} void __builtin_arc_sr (unsigned int @var{val}, unsigned int @var{auxr}) 14999The first argument, @var{val}, is a compile time constant to be 15000written to the register, the second argument, @var{auxr}, is the 15001address of an auxiliary register. Generates: 15002@example 15003sr @var{val}, [@var{auxr}] 15004@end example 15005@end deftypefn 15006 15007@deftypefn {Built-in Function} int __builtin_arc_swap (int @var{src}) 15008Only valid with @option{-mswap}. Generates: 15009@example 15010swap @var{dest}, @var{src} 15011@end example 15012Where the value in @var{dest} will be the result returned from the 15013built-in. 15014@end deftypefn 15015 15016@deftypefn {Built-in Function} void __builtin_arc_swi (void) 15017Generates: 15018@example 15019swi 15020@end example 15021@end deftypefn 15022 15023@deftypefn {Built-in Function} void __builtin_arc_sync (void) 15024Only available with @option{-mcpu=ARC700}. Generates: 15025@example 15026sync 15027@end example 15028@end deftypefn 15029 15030@deftypefn {Built-in Function} void __builtin_arc_trap_s (unsigned int @var{c}) 15031Only available with @option{-mcpu=ARC700}. Generates: 15032@example 15033trap_s @var{c} 15034@end example 15035@end deftypefn 15036 15037@deftypefn {Built-in Function} void __builtin_arc_unimp_s (void) 15038Only available with @option{-mcpu=ARC700}. Generates: 15039@example 15040unimp_s 15041@end example 15042@end deftypefn 15043 15044The instructions generated by the following builtins are not 15045considered as candidates for scheduling. They are not moved around by 15046the compiler during scheduling, and thus can be expected to appear 15047where they are put in the C code: 15048@example 15049__builtin_arc_brk() 15050__builtin_arc_core_read() 15051__builtin_arc_core_write() 15052__builtin_arc_flag() 15053__builtin_arc_lr() 15054__builtin_arc_sleep() 15055__builtin_arc_sr() 15056__builtin_arc_swi() 15057@end example 15058 15059@node ARC SIMD Built-in Functions 15060@subsection ARC SIMD Built-in Functions 15061 15062SIMD builtins provided by the compiler can be used to generate the 15063vector instructions. This section describes the available builtins 15064and their usage in programs. With the @option{-msimd} option, the 15065compiler provides 128-bit vector types, which can be specified using 15066the @code{vector_size} attribute. The header file @file{arc-simd.h} 15067can be included to use the following predefined types: 15068@example 15069typedef int __v4si __attribute__((vector_size(16))); 15070typedef short __v8hi __attribute__((vector_size(16))); 15071@end example 15072 15073These types can be used to define 128-bit variables. The built-in 15074functions listed in the following section can be used on these 15075variables to generate the vector operations. 15076 15077For all builtins, @code{__builtin_arc_@var{someinsn}}, the header file 15078@file{arc-simd.h} also provides equivalent macros called 15079@code{_@var{someinsn}} that can be used for programming ease and 15080improved readability. The following macros for DMA control are also 15081provided: 15082@example 15083#define _setup_dma_in_channel_reg _vdiwr 15084#define _setup_dma_out_channel_reg _vdowr 15085@end example 15086 15087The following is a complete list of all the SIMD built-ins provided 15088for ARC, grouped by calling signature. 15089 15090The following take two @code{__v8hi} arguments and return a 15091@code{__v8hi} result: 15092@example 15093__v8hi __builtin_arc_vaddaw (__v8hi, __v8hi); 15094__v8hi __builtin_arc_vaddw (__v8hi, __v8hi); 15095__v8hi __builtin_arc_vand (__v8hi, __v8hi); 15096__v8hi __builtin_arc_vandaw (__v8hi, __v8hi); 15097__v8hi __builtin_arc_vavb (__v8hi, __v8hi); 15098__v8hi __builtin_arc_vavrb (__v8hi, __v8hi); 15099__v8hi __builtin_arc_vbic (__v8hi, __v8hi); 15100__v8hi __builtin_arc_vbicaw (__v8hi, __v8hi); 15101__v8hi __builtin_arc_vdifaw (__v8hi, __v8hi); 15102__v8hi __builtin_arc_vdifw (__v8hi, __v8hi); 15103__v8hi __builtin_arc_veqw (__v8hi, __v8hi); 15104__v8hi __builtin_arc_vh264f (__v8hi, __v8hi); 15105__v8hi __builtin_arc_vh264ft (__v8hi, __v8hi); 15106__v8hi __builtin_arc_vh264fw (__v8hi, __v8hi); 15107__v8hi __builtin_arc_vlew (__v8hi, __v8hi); 15108__v8hi __builtin_arc_vltw (__v8hi, __v8hi); 15109__v8hi __builtin_arc_vmaxaw (__v8hi, __v8hi); 15110__v8hi __builtin_arc_vmaxw (__v8hi, __v8hi); 15111__v8hi __builtin_arc_vminaw (__v8hi, __v8hi); 15112__v8hi __builtin_arc_vminw (__v8hi, __v8hi); 15113__v8hi __builtin_arc_vmr1aw (__v8hi, __v8hi); 15114__v8hi __builtin_arc_vmr1w (__v8hi, __v8hi); 15115__v8hi __builtin_arc_vmr2aw (__v8hi, __v8hi); 15116__v8hi __builtin_arc_vmr2w (__v8hi, __v8hi); 15117__v8hi __builtin_arc_vmr3aw (__v8hi, __v8hi); 15118__v8hi __builtin_arc_vmr3w (__v8hi, __v8hi); 15119__v8hi __builtin_arc_vmr4aw (__v8hi, __v8hi); 15120__v8hi __builtin_arc_vmr4w (__v8hi, __v8hi); 15121__v8hi __builtin_arc_vmr5aw (__v8hi, __v8hi); 15122__v8hi __builtin_arc_vmr5w (__v8hi, __v8hi); 15123__v8hi __builtin_arc_vmr6aw (__v8hi, __v8hi); 15124__v8hi __builtin_arc_vmr6w (__v8hi, __v8hi); 15125__v8hi __builtin_arc_vmr7aw (__v8hi, __v8hi); 15126__v8hi __builtin_arc_vmr7w (__v8hi, __v8hi); 15127__v8hi __builtin_arc_vmrb (__v8hi, __v8hi); 15128__v8hi __builtin_arc_vmulaw (__v8hi, __v8hi); 15129__v8hi __builtin_arc_vmulfaw (__v8hi, __v8hi); 15130__v8hi __builtin_arc_vmulfw (__v8hi, __v8hi); 15131__v8hi __builtin_arc_vmulw (__v8hi, __v8hi); 15132__v8hi __builtin_arc_vnew (__v8hi, __v8hi); 15133__v8hi __builtin_arc_vor (__v8hi, __v8hi); 15134__v8hi __builtin_arc_vsubaw (__v8hi, __v8hi); 15135__v8hi __builtin_arc_vsubw (__v8hi, __v8hi); 15136__v8hi __builtin_arc_vsummw (__v8hi, __v8hi); 15137__v8hi __builtin_arc_vvc1f (__v8hi, __v8hi); 15138__v8hi __builtin_arc_vvc1ft (__v8hi, __v8hi); 15139__v8hi __builtin_arc_vxor (__v8hi, __v8hi); 15140__v8hi __builtin_arc_vxoraw (__v8hi, __v8hi); 15141@end example 15142 15143The following take one @code{__v8hi} and one @code{int} argument and return a 15144@code{__v8hi} result: 15145 15146@example 15147__v8hi __builtin_arc_vbaddw (__v8hi, int); 15148__v8hi __builtin_arc_vbmaxw (__v8hi, int); 15149__v8hi __builtin_arc_vbminw (__v8hi, int); 15150__v8hi __builtin_arc_vbmulaw (__v8hi, int); 15151__v8hi __builtin_arc_vbmulfw (__v8hi, int); 15152__v8hi __builtin_arc_vbmulw (__v8hi, int); 15153__v8hi __builtin_arc_vbrsubw (__v8hi, int); 15154__v8hi __builtin_arc_vbsubw (__v8hi, int); 15155@end example 15156 15157The following take one @code{__v8hi} argument and one @code{int} argument which 15158must be a 3-bit compile time constant indicating a register number 15159I0-I7. They return a @code{__v8hi} result. 15160@example 15161__v8hi __builtin_arc_vasrw (__v8hi, const int); 15162__v8hi __builtin_arc_vsr8 (__v8hi, const int); 15163__v8hi __builtin_arc_vsr8aw (__v8hi, const int); 15164@end example 15165 15166The following take one @code{__v8hi} argument and one @code{int} 15167argument which must be a 6-bit compile time constant. They return a 15168@code{__v8hi} result. 15169@example 15170__v8hi __builtin_arc_vasrpwbi (__v8hi, const int); 15171__v8hi __builtin_arc_vasrrpwbi (__v8hi, const int); 15172__v8hi __builtin_arc_vasrrwi (__v8hi, const int); 15173__v8hi __builtin_arc_vasrsrwi (__v8hi, const int); 15174__v8hi __builtin_arc_vasrwi (__v8hi, const int); 15175__v8hi __builtin_arc_vsr8awi (__v8hi, const int); 15176__v8hi __builtin_arc_vsr8i (__v8hi, const int); 15177@end example 15178 15179The following take one @code{__v8hi} argument and one @code{int} argument which 15180must be a 8-bit compile time constant. They return a @code{__v8hi} 15181result. 15182@example 15183__v8hi __builtin_arc_vd6tapf (__v8hi, const int); 15184__v8hi __builtin_arc_vmvaw (__v8hi, const int); 15185__v8hi __builtin_arc_vmvw (__v8hi, const int); 15186__v8hi __builtin_arc_vmvzw (__v8hi, const int); 15187@end example 15188 15189The following take two @code{int} arguments, the second of which which 15190must be a 8-bit compile time constant. They return a @code{__v8hi} 15191result: 15192@example 15193__v8hi __builtin_arc_vmovaw (int, const int); 15194__v8hi __builtin_arc_vmovw (int, const int); 15195__v8hi __builtin_arc_vmovzw (int, const int); 15196@end example 15197 15198The following take a single @code{__v8hi} argument and return a 15199@code{__v8hi} result: 15200@example 15201__v8hi __builtin_arc_vabsaw (__v8hi); 15202__v8hi __builtin_arc_vabsw (__v8hi); 15203__v8hi __builtin_arc_vaddsuw (__v8hi); 15204__v8hi __builtin_arc_vexch1 (__v8hi); 15205__v8hi __builtin_arc_vexch2 (__v8hi); 15206__v8hi __builtin_arc_vexch4 (__v8hi); 15207__v8hi __builtin_arc_vsignw (__v8hi); 15208__v8hi __builtin_arc_vupbaw (__v8hi); 15209__v8hi __builtin_arc_vupbw (__v8hi); 15210__v8hi __builtin_arc_vupsbaw (__v8hi); 15211__v8hi __builtin_arc_vupsbw (__v8hi); 15212@end example 15213 15214The following take two @code{int} arguments and return no result: 15215@example 15216void __builtin_arc_vdirun (int, int); 15217void __builtin_arc_vdorun (int, int); 15218@end example 15219 15220The following take two @code{int} arguments and return no result. The 15221first argument must a 3-bit compile time constant indicating one of 15222the DR0-DR7 DMA setup channels: 15223@example 15224void __builtin_arc_vdiwr (const int, int); 15225void __builtin_arc_vdowr (const int, int); 15226@end example 15227 15228The following take an @code{int} argument and return no result: 15229@example 15230void __builtin_arc_vendrec (int); 15231void __builtin_arc_vrec (int); 15232void __builtin_arc_vrecrun (int); 15233void __builtin_arc_vrun (int); 15234@end example 15235 15236The following take a @code{__v8hi} argument and two @code{int} 15237arguments and return a @code{__v8hi} result. The second argument must 15238be a 3-bit compile time constants, indicating one the registers I0-I7, 15239and the third argument must be an 8-bit compile time constant. 15240 15241@emph{Note:} Although the equivalent hardware instructions do not take 15242an SIMD register as an operand, these builtins overwrite the relevant 15243bits of the @code{__v8hi} register provided as the first argument with 15244the value loaded from the @code{[Ib, u8]} location in the SDM. 15245 15246@example 15247__v8hi __builtin_arc_vld32 (__v8hi, const int, const int); 15248__v8hi __builtin_arc_vld32wh (__v8hi, const int, const int); 15249__v8hi __builtin_arc_vld32wl (__v8hi, const int, const int); 15250__v8hi __builtin_arc_vld64 (__v8hi, const int, const int); 15251@end example 15252 15253The following take two @code{int} arguments and return a @code{__v8hi} 15254result. The first argument must be a 3-bit compile time constants, 15255indicating one the registers I0-I7, and the second argument must be an 152568-bit compile time constant. 15257 15258@example 15259__v8hi __builtin_arc_vld128 (const int, const int); 15260__v8hi __builtin_arc_vld64w (const int, const int); 15261@end example 15262 15263The following take a @code{__v8hi} argument and two @code{int} 15264arguments and return no result. The second argument must be a 3-bit 15265compile time constants, indicating one the registers I0-I7, and the 15266third argument must be an 8-bit compile time constant. 15267 15268@example 15269void __builtin_arc_vst128 (__v8hi, const int, const int); 15270void __builtin_arc_vst64 (__v8hi, const int, const int); 15271@end example 15272 15273The following take a @code{__v8hi} argument and three @code{int} 15274arguments and return no result. The second argument must be a 3-bit 15275compile-time constant, identifying the 16-bit sub-register to be 15276stored, the third argument must be a 3-bit compile time constants, 15277indicating one the registers I0-I7, and the fourth argument must be an 152788-bit compile time constant. 15279 15280@example 15281void __builtin_arc_vst16_n (__v8hi, const int, const int, const int); 15282void __builtin_arc_vst32_n (__v8hi, const int, const int, const int); 15283@end example 15284 15285@node ARM iWMMXt Built-in Functions 15286@subsection ARM iWMMXt Built-in Functions 15287 15288These built-in functions are available for the ARM family of 15289processors when the @option{-mcpu=iwmmxt} switch is used: 15290 15291@smallexample 15292typedef int v2si __attribute__ ((vector_size (8))); 15293typedef short v4hi __attribute__ ((vector_size (8))); 15294typedef char v8qi __attribute__ ((vector_size (8))); 15295 15296int __builtin_arm_getwcgr0 (void); 15297void __builtin_arm_setwcgr0 (int); 15298int __builtin_arm_getwcgr1 (void); 15299void __builtin_arm_setwcgr1 (int); 15300int __builtin_arm_getwcgr2 (void); 15301void __builtin_arm_setwcgr2 (int); 15302int __builtin_arm_getwcgr3 (void); 15303void __builtin_arm_setwcgr3 (int); 15304int __builtin_arm_textrmsb (v8qi, int); 15305int __builtin_arm_textrmsh (v4hi, int); 15306int __builtin_arm_textrmsw (v2si, int); 15307int __builtin_arm_textrmub (v8qi, int); 15308int __builtin_arm_textrmuh (v4hi, int); 15309int __builtin_arm_textrmuw (v2si, int); 15310v8qi __builtin_arm_tinsrb (v8qi, int, int); 15311v4hi __builtin_arm_tinsrh (v4hi, int, int); 15312v2si __builtin_arm_tinsrw (v2si, int, int); 15313long long __builtin_arm_tmia (long long, int, int); 15314long long __builtin_arm_tmiabb (long long, int, int); 15315long long __builtin_arm_tmiabt (long long, int, int); 15316long long __builtin_arm_tmiaph (long long, int, int); 15317long long __builtin_arm_tmiatb (long long, int, int); 15318long long __builtin_arm_tmiatt (long long, int, int); 15319int __builtin_arm_tmovmskb (v8qi); 15320int __builtin_arm_tmovmskh (v4hi); 15321int __builtin_arm_tmovmskw (v2si); 15322long long __builtin_arm_waccb (v8qi); 15323long long __builtin_arm_wacch (v4hi); 15324long long __builtin_arm_waccw (v2si); 15325v8qi __builtin_arm_waddb (v8qi, v8qi); 15326v8qi __builtin_arm_waddbss (v8qi, v8qi); 15327v8qi __builtin_arm_waddbus (v8qi, v8qi); 15328v4hi __builtin_arm_waddh (v4hi, v4hi); 15329v4hi __builtin_arm_waddhss (v4hi, v4hi); 15330v4hi __builtin_arm_waddhus (v4hi, v4hi); 15331v2si __builtin_arm_waddw (v2si, v2si); 15332v2si __builtin_arm_waddwss (v2si, v2si); 15333v2si __builtin_arm_waddwus (v2si, v2si); 15334v8qi __builtin_arm_walign (v8qi, v8qi, int); 15335long long __builtin_arm_wand(long long, long long); 15336long long __builtin_arm_wandn (long long, long long); 15337v8qi __builtin_arm_wavg2b (v8qi, v8qi); 15338v8qi __builtin_arm_wavg2br (v8qi, v8qi); 15339v4hi __builtin_arm_wavg2h (v4hi, v4hi); 15340v4hi __builtin_arm_wavg2hr (v4hi, v4hi); 15341v8qi __builtin_arm_wcmpeqb (v8qi, v8qi); 15342v4hi __builtin_arm_wcmpeqh (v4hi, v4hi); 15343v2si __builtin_arm_wcmpeqw (v2si, v2si); 15344v8qi __builtin_arm_wcmpgtsb (v8qi, v8qi); 15345v4hi __builtin_arm_wcmpgtsh (v4hi, v4hi); 15346v2si __builtin_arm_wcmpgtsw (v2si, v2si); 15347v8qi __builtin_arm_wcmpgtub (v8qi, v8qi); 15348v4hi __builtin_arm_wcmpgtuh (v4hi, v4hi); 15349v2si __builtin_arm_wcmpgtuw (v2si, v2si); 15350long long __builtin_arm_wmacs (long long, v4hi, v4hi); 15351long long __builtin_arm_wmacsz (v4hi, v4hi); 15352long long __builtin_arm_wmacu (long long, v4hi, v4hi); 15353long long __builtin_arm_wmacuz (v4hi, v4hi); 15354v4hi __builtin_arm_wmadds (v4hi, v4hi); 15355v4hi __builtin_arm_wmaddu (v4hi, v4hi); 15356v8qi __builtin_arm_wmaxsb (v8qi, v8qi); 15357v4hi __builtin_arm_wmaxsh (v4hi, v4hi); 15358v2si __builtin_arm_wmaxsw (v2si, v2si); 15359v8qi __builtin_arm_wmaxub (v8qi, v8qi); 15360v4hi __builtin_arm_wmaxuh (v4hi, v4hi); 15361v2si __builtin_arm_wmaxuw (v2si, v2si); 15362v8qi __builtin_arm_wminsb (v8qi, v8qi); 15363v4hi __builtin_arm_wminsh (v4hi, v4hi); 15364v2si __builtin_arm_wminsw (v2si, v2si); 15365v8qi __builtin_arm_wminub (v8qi, v8qi); 15366v4hi __builtin_arm_wminuh (v4hi, v4hi); 15367v2si __builtin_arm_wminuw (v2si, v2si); 15368v4hi __builtin_arm_wmulsm (v4hi, v4hi); 15369v4hi __builtin_arm_wmulul (v4hi, v4hi); 15370v4hi __builtin_arm_wmulum (v4hi, v4hi); 15371long long __builtin_arm_wor (long long, long long); 15372v2si __builtin_arm_wpackdss (long long, long long); 15373v2si __builtin_arm_wpackdus (long long, long long); 15374v8qi __builtin_arm_wpackhss (v4hi, v4hi); 15375v8qi __builtin_arm_wpackhus (v4hi, v4hi); 15376v4hi __builtin_arm_wpackwss (v2si, v2si); 15377v4hi __builtin_arm_wpackwus (v2si, v2si); 15378long long __builtin_arm_wrord (long long, long long); 15379long long __builtin_arm_wrordi (long long, int); 15380v4hi __builtin_arm_wrorh (v4hi, long long); 15381v4hi __builtin_arm_wrorhi (v4hi, int); 15382v2si __builtin_arm_wrorw (v2si, long long); 15383v2si __builtin_arm_wrorwi (v2si, int); 15384v2si __builtin_arm_wsadb (v2si, v8qi, v8qi); 15385v2si __builtin_arm_wsadbz (v8qi, v8qi); 15386v2si __builtin_arm_wsadh (v2si, v4hi, v4hi); 15387v2si __builtin_arm_wsadhz (v4hi, v4hi); 15388v4hi __builtin_arm_wshufh (v4hi, int); 15389long long __builtin_arm_wslld (long long, long long); 15390long long __builtin_arm_wslldi (long long, int); 15391v4hi __builtin_arm_wsllh (v4hi, long long); 15392v4hi __builtin_arm_wsllhi (v4hi, int); 15393v2si __builtin_arm_wsllw (v2si, long long); 15394v2si __builtin_arm_wsllwi (v2si, int); 15395long long __builtin_arm_wsrad (long long, long long); 15396long long __builtin_arm_wsradi (long long, int); 15397v4hi __builtin_arm_wsrah (v4hi, long long); 15398v4hi __builtin_arm_wsrahi (v4hi, int); 15399v2si __builtin_arm_wsraw (v2si, long long); 15400v2si __builtin_arm_wsrawi (v2si, int); 15401long long __builtin_arm_wsrld (long long, long long); 15402long long __builtin_arm_wsrldi (long long, int); 15403v4hi __builtin_arm_wsrlh (v4hi, long long); 15404v4hi __builtin_arm_wsrlhi (v4hi, int); 15405v2si __builtin_arm_wsrlw (v2si, long long); 15406v2si __builtin_arm_wsrlwi (v2si, int); 15407v8qi __builtin_arm_wsubb (v8qi, v8qi); 15408v8qi __builtin_arm_wsubbss (v8qi, v8qi); 15409v8qi __builtin_arm_wsubbus (v8qi, v8qi); 15410v4hi __builtin_arm_wsubh (v4hi, v4hi); 15411v4hi __builtin_arm_wsubhss (v4hi, v4hi); 15412v4hi __builtin_arm_wsubhus (v4hi, v4hi); 15413v2si __builtin_arm_wsubw (v2si, v2si); 15414v2si __builtin_arm_wsubwss (v2si, v2si); 15415v2si __builtin_arm_wsubwus (v2si, v2si); 15416v4hi __builtin_arm_wunpckehsb (v8qi); 15417v2si __builtin_arm_wunpckehsh (v4hi); 15418long long __builtin_arm_wunpckehsw (v2si); 15419v4hi __builtin_arm_wunpckehub (v8qi); 15420v2si __builtin_arm_wunpckehuh (v4hi); 15421long long __builtin_arm_wunpckehuw (v2si); 15422v4hi __builtin_arm_wunpckelsb (v8qi); 15423v2si __builtin_arm_wunpckelsh (v4hi); 15424long long __builtin_arm_wunpckelsw (v2si); 15425v4hi __builtin_arm_wunpckelub (v8qi); 15426v2si __builtin_arm_wunpckeluh (v4hi); 15427long long __builtin_arm_wunpckeluw (v2si); 15428v8qi __builtin_arm_wunpckihb (v8qi, v8qi); 15429v4hi __builtin_arm_wunpckihh (v4hi, v4hi); 15430v2si __builtin_arm_wunpckihw (v2si, v2si); 15431v8qi __builtin_arm_wunpckilb (v8qi, v8qi); 15432v4hi __builtin_arm_wunpckilh (v4hi, v4hi); 15433v2si __builtin_arm_wunpckilw (v2si, v2si); 15434long long __builtin_arm_wxor (long long, long long); 15435long long __builtin_arm_wzero (); 15436@end smallexample 15437 15438 15439@node ARM C Language Extensions (ACLE) 15440@subsection ARM C Language Extensions (ACLE) 15441 15442GCC implements extensions for C as described in the ARM C Language 15443Extensions (ACLE) specification, which can be found at 15444@uref{https://developer.arm.com/documentation/ihi0053/latest/}. 15445 15446As a part of ACLE, GCC implements extensions for Advanced SIMD as described in 15447the ARM C Language Extensions Specification. The complete list of Advanced SIMD 15448intrinsics can be found at 15449@uref{https://developer.arm.com/documentation/ihi0073/latest/}. 15450The built-in intrinsics for the Advanced SIMD extension are available when 15451NEON is enabled. 15452 15453Currently, ARM and AArch64 back ends do not support ACLE 2.0 fully. Both 15454back ends support CRC32 intrinsics and the ARM back end supports the 15455Coprocessor intrinsics, all from @file{arm_acle.h}. The ARM back end's 16-bit 15456floating-point Advanced SIMD intrinsics currently comply to ACLE v1.1. 15457AArch64's back end does not have support for 16-bit floating point Advanced SIMD 15458intrinsics yet. 15459 15460See @ref{ARM Options} and @ref{AArch64 Options} for more information on the 15461availability of extensions. 15462 15463@node ARM Floating Point Status and Control Intrinsics 15464@subsection ARM Floating Point Status and Control Intrinsics 15465 15466These built-in functions are available for the ARM family of 15467processors with floating-point unit. 15468 15469@smallexample 15470unsigned int __builtin_arm_get_fpscr (); 15471void __builtin_arm_set_fpscr (unsigned int); 15472@end smallexample 15473 15474@node ARM ARMv8-M Security Extensions 15475@subsection ARM ARMv8-M Security Extensions 15476 15477GCC implements the ARMv8-M Security Extensions as described in the ARMv8-M 15478Security Extensions: Requirements on Development Tools Engineering 15479Specification, which can be found at 15480@uref{https://developer.arm.com/documentation/ecm0359818/latest/}. 15481 15482As part of the Security Extensions GCC implements two new function attributes: 15483@code{cmse_nonsecure_entry} and @code{cmse_nonsecure_call}. 15484 15485As part of the Security Extensions GCC implements the intrinsics below. FPTR 15486is used here to mean any function pointer type. 15487 15488@smallexample 15489cmse_address_info_t cmse_TT (void *); 15490cmse_address_info_t cmse_TT_fptr (FPTR); 15491cmse_address_info_t cmse_TTT (void *); 15492cmse_address_info_t cmse_TTT_fptr (FPTR); 15493cmse_address_info_t cmse_TTA (void *); 15494cmse_address_info_t cmse_TTA_fptr (FPTR); 15495cmse_address_info_t cmse_TTAT (void *); 15496cmse_address_info_t cmse_TTAT_fptr (FPTR); 15497void * cmse_check_address_range (void *, size_t, int); 15498typeof(p) cmse_nsfptr_create (FPTR p); 15499intptr_t cmse_is_nsfptr (FPTR); 15500int cmse_nonsecure_caller (void); 15501@end smallexample 15502 15503@node AVR Built-in Functions 15504@subsection AVR Built-in Functions 15505 15506For each built-in function for AVR, there is an equally named, 15507uppercase built-in macro defined. That way users can easily query if 15508or if not a specific built-in is implemented or not. For example, if 15509@code{__builtin_avr_nop} is available the macro 15510@code{__BUILTIN_AVR_NOP} is defined to @code{1} and undefined otherwise. 15511 15512@table @code 15513 15514@item void __builtin_avr_nop (void) 15515@itemx void __builtin_avr_sei (void) 15516@itemx void __builtin_avr_cli (void) 15517@itemx void __builtin_avr_sleep (void) 15518@itemx void __builtin_avr_wdr (void) 15519@itemx unsigned char __builtin_avr_swap (unsigned char) 15520@itemx unsigned int __builtin_avr_fmul (unsigned char, unsigned char) 15521@itemx int __builtin_avr_fmuls (char, char) 15522@itemx int __builtin_avr_fmulsu (char, unsigned char) 15523These built-in functions map to the respective machine 15524instruction, i.e.@: @code{nop}, @code{sei}, @code{cli}, @code{sleep}, 15525@code{wdr}, @code{swap}, @code{fmul}, @code{fmuls} 15526resp. @code{fmulsu}. The three @code{fmul*} built-ins are implemented 15527as library call if no hardware multiplier is available. 15528 15529@item void __builtin_avr_delay_cycles (unsigned long ticks) 15530Delay execution for @var{ticks} cycles. Note that this 15531built-in does not take into account the effect of interrupts that 15532might increase delay time. @var{ticks} must be a compile-time 15533integer constant; delays with a variable number of cycles are not supported. 15534 15535@item char __builtin_avr_flash_segment (const __memx void*) 15536This built-in takes a byte address to the 24-bit 15537@ref{AVR Named Address Spaces,address space} @code{__memx} and returns 15538the number of the flash segment (the 64 KiB chunk) where the address 15539points to. Counting starts at @code{0}. 15540If the address does not point to flash memory, return @code{-1}. 15541 15542@item uint8_t __builtin_avr_insert_bits (uint32_t map, uint8_t bits, uint8_t val) 15543Insert bits from @var{bits} into @var{val} and return the resulting 15544value. The nibbles of @var{map} determine how the insertion is 15545performed: Let @var{X} be the @var{n}-th nibble of @var{map} 15546@enumerate 15547@item If @var{X} is @code{0xf}, 15548then the @var{n}-th bit of @var{val} is returned unaltered. 15549 15550@item If X is in the range 0@dots{}7, 15551then the @var{n}-th result bit is set to the @var{X}-th bit of @var{bits} 15552 15553@item If X is in the range 8@dots{}@code{0xe}, 15554then the @var{n}-th result bit is undefined. 15555@end enumerate 15556 15557@noindent 15558One typical use case for this built-in is adjusting input and 15559output values to non-contiguous port layouts. Some examples: 15560 15561@smallexample 15562// same as val, bits is unused 15563__builtin_avr_insert_bits (0xffffffff, bits, val); 15564@end smallexample 15565 15566@smallexample 15567// same as bits, val is unused 15568__builtin_avr_insert_bits (0x76543210, bits, val); 15569@end smallexample 15570 15571@smallexample 15572// same as rotating bits by 4 15573__builtin_avr_insert_bits (0x32107654, bits, 0); 15574@end smallexample 15575 15576@smallexample 15577// high nibble of result is the high nibble of val 15578// low nibble of result is the low nibble of bits 15579__builtin_avr_insert_bits (0xffff3210, bits, val); 15580@end smallexample 15581 15582@smallexample 15583// reverse the bit order of bits 15584__builtin_avr_insert_bits (0x01234567, bits, 0); 15585@end smallexample 15586 15587@item void __builtin_avr_nops (unsigned count) 15588Insert @var{count} @code{NOP} instructions. 15589The number of instructions must be a compile-time integer constant. 15590 15591@end table 15592 15593@noindent 15594There are many more AVR-specific built-in functions that are used to 15595implement the ISO/IEC TR 18037 ``Embedded C'' fixed-point functions of 15596section 7.18a.6. You don't need to use these built-ins directly. 15597Instead, use the declarations as supplied by the @code{stdfix.h} header 15598with GNU-C99: 15599 15600@smallexample 15601#include <stdfix.h> 15602 15603// Re-interpret the bit representation of unsigned 16-bit 15604// integer @var{uval} as Q-format 0.16 value. 15605unsigned fract get_bits (uint_ur_t uval) 15606@{ 15607 return urbits (uval); 15608@} 15609@end smallexample 15610 15611@node Blackfin Built-in Functions 15612@subsection Blackfin Built-in Functions 15613 15614Currently, there are two Blackfin-specific built-in functions. These are 15615used for generating @code{CSYNC} and @code{SSYNC} machine insns without 15616using inline assembly; by using these built-in functions the compiler can 15617automatically add workarounds for hardware errata involving these 15618instructions. These functions are named as follows: 15619 15620@smallexample 15621void __builtin_bfin_csync (void); 15622void __builtin_bfin_ssync (void); 15623@end smallexample 15624 15625@node BPF Built-in Functions 15626@subsection BPF Built-in Functions 15627 15628The following built-in functions are available for eBPF targets. 15629 15630@deftypefn {Built-in Function} unsigned long long __builtin_bpf_load_byte (unsigned long long @var{offset}) 15631Load a byte from the @code{struct sk_buff} packet data pointed by the register @code{%r6} and return it. 15632@end deftypefn 15633 15634@deftypefn {Built-in Function} unsigned long long __builtin_bpf_load_half (unsigned long long @var{offset}) 15635Load 16-bits from the @code{struct sk_buff} packet data pointed by the register @code{%r6} and return it. 15636@end deftypefn 15637 15638@deftypefn {Built-in Function} unsigned long long __builtin_bpf_load_word (unsigned long long @var{offset}) 15639Load 32-bits from the @code{struct sk_buff} packet data pointed by the register @code{%r6} and return it. 15640@end deftypefn 15641 15642@deftypefn {Built-in Function} void * __builtin_preserve_access_index (@var{expr}) 15643BPF Compile Once-Run Everywhere (CO-RE) support. Instruct GCC to generate CO-RE relocation records for any accesses to aggregate data structures (struct, union, array types) in @var{expr}. This builtin is otherwise transparent, the return value is whatever @var{expr} evaluates to. It is also overloaded: @var{expr} may be of any type (not necessarily a pointer), the return type is the same. Has no effect if @code{-mco-re} is not in effect (either specified or implied). 15644@end deftypefn 15645 15646@node FR-V Built-in Functions 15647@subsection FR-V Built-in Functions 15648 15649GCC provides many FR-V-specific built-in functions. In general, 15650these functions are intended to be compatible with those described 15651by @cite{FR-V Family, Softune C/C++ Compiler Manual (V6), Fujitsu 15652Semiconductor}. The two exceptions are @code{__MDUNPACKH} and 15653@code{__MBTOHE}, the GCC forms of which pass 128-bit values by 15654pointer rather than by value. 15655 15656Most of the functions are named after specific FR-V instructions. 15657Such functions are said to be ``directly mapped'' and are summarized 15658here in tabular form. 15659 15660@menu 15661* Argument Types:: 15662* Directly-mapped Integer Functions:: 15663* Directly-mapped Media Functions:: 15664* Raw read/write Functions:: 15665* Other Built-in Functions:: 15666@end menu 15667 15668@node Argument Types 15669@subsubsection Argument Types 15670 15671The arguments to the built-in functions can be divided into three groups: 15672register numbers, compile-time constants and run-time values. In order 15673to make this classification clear at a glance, the arguments and return 15674values are given the following pseudo types: 15675 15676@multitable @columnfractions .20 .30 .15 .35 15677@headitem Pseudo type @tab Real C type @tab Constant? @tab Description 15678@item @code{uh} @tab @code{unsigned short} @tab No @tab an unsigned halfword 15679@item @code{uw1} @tab @code{unsigned int} @tab No @tab an unsigned word 15680@item @code{sw1} @tab @code{int} @tab No @tab a signed word 15681@item @code{uw2} @tab @code{unsigned long long} @tab No 15682@tab an unsigned doubleword 15683@item @code{sw2} @tab @code{long long} @tab No @tab a signed doubleword 15684@item @code{const} @tab @code{int} @tab Yes @tab an integer constant 15685@item @code{acc} @tab @code{int} @tab Yes @tab an ACC register number 15686@item @code{iacc} @tab @code{int} @tab Yes @tab an IACC register number 15687@end multitable 15688 15689These pseudo types are not defined by GCC, they are simply a notational 15690convenience used in this manual. 15691 15692Arguments of type @code{uh}, @code{uw1}, @code{sw1}, @code{uw2} 15693and @code{sw2} are evaluated at run time. They correspond to 15694register operands in the underlying FR-V instructions. 15695 15696@code{const} arguments represent immediate operands in the underlying 15697FR-V instructions. They must be compile-time constants. 15698 15699@code{acc} arguments are evaluated at compile time and specify the number 15700of an accumulator register. For example, an @code{acc} argument of 2 15701selects the ACC2 register. 15702 15703@code{iacc} arguments are similar to @code{acc} arguments but specify the 15704number of an IACC register. See @pxref{Other Built-in Functions} 15705for more details. 15706 15707@node Directly-mapped Integer Functions 15708@subsubsection Directly-Mapped Integer Functions 15709 15710The functions listed below map directly to FR-V I-type instructions. 15711 15712@multitable @columnfractions .45 .32 .23 15713@headitem Function prototype @tab Example usage @tab Assembly output 15714@item @code{sw1 __ADDSS (sw1, sw1)} 15715@tab @code{@var{c} = __ADDSS (@var{a}, @var{b})} 15716@tab @code{ADDSS @var{a},@var{b},@var{c}} 15717@item @code{sw1 __SCAN (sw1, sw1)} 15718@tab @code{@var{c} = __SCAN (@var{a}, @var{b})} 15719@tab @code{SCAN @var{a},@var{b},@var{c}} 15720@item @code{sw1 __SCUTSS (sw1)} 15721@tab @code{@var{b} = __SCUTSS (@var{a})} 15722@tab @code{SCUTSS @var{a},@var{b}} 15723@item @code{sw1 __SLASS (sw1, sw1)} 15724@tab @code{@var{c} = __SLASS (@var{a}, @var{b})} 15725@tab @code{SLASS @var{a},@var{b},@var{c}} 15726@item @code{void __SMASS (sw1, sw1)} 15727@tab @code{__SMASS (@var{a}, @var{b})} 15728@tab @code{SMASS @var{a},@var{b}} 15729@item @code{void __SMSSS (sw1, sw1)} 15730@tab @code{__SMSSS (@var{a}, @var{b})} 15731@tab @code{SMSSS @var{a},@var{b}} 15732@item @code{void __SMU (sw1, sw1)} 15733@tab @code{__SMU (@var{a}, @var{b})} 15734@tab @code{SMU @var{a},@var{b}} 15735@item @code{sw2 __SMUL (sw1, sw1)} 15736@tab @code{@var{c} = __SMUL (@var{a}, @var{b})} 15737@tab @code{SMUL @var{a},@var{b},@var{c}} 15738@item @code{sw1 __SUBSS (sw1, sw1)} 15739@tab @code{@var{c} = __SUBSS (@var{a}, @var{b})} 15740@tab @code{SUBSS @var{a},@var{b},@var{c}} 15741@item @code{uw2 __UMUL (uw1, uw1)} 15742@tab @code{@var{c} = __UMUL (@var{a}, @var{b})} 15743@tab @code{UMUL @var{a},@var{b},@var{c}} 15744@end multitable 15745 15746@node Directly-mapped Media Functions 15747@subsubsection Directly-Mapped Media Functions 15748 15749The functions listed below map directly to FR-V M-type instructions. 15750 15751@multitable @columnfractions .45 .32 .23 15752@headitem Function prototype @tab Example usage @tab Assembly output 15753@item @code{uw1 __MABSHS (sw1)} 15754@tab @code{@var{b} = __MABSHS (@var{a})} 15755@tab @code{MABSHS @var{a},@var{b}} 15756@item @code{void __MADDACCS (acc, acc)} 15757@tab @code{__MADDACCS (@var{b}, @var{a})} 15758@tab @code{MADDACCS @var{a},@var{b}} 15759@item @code{sw1 __MADDHSS (sw1, sw1)} 15760@tab @code{@var{c} = __MADDHSS (@var{a}, @var{b})} 15761@tab @code{MADDHSS @var{a},@var{b},@var{c}} 15762@item @code{uw1 __MADDHUS (uw1, uw1)} 15763@tab @code{@var{c} = __MADDHUS (@var{a}, @var{b})} 15764@tab @code{MADDHUS @var{a},@var{b},@var{c}} 15765@item @code{uw1 __MAND (uw1, uw1)} 15766@tab @code{@var{c} = __MAND (@var{a}, @var{b})} 15767@tab @code{MAND @var{a},@var{b},@var{c}} 15768@item @code{void __MASACCS (acc, acc)} 15769@tab @code{__MASACCS (@var{b}, @var{a})} 15770@tab @code{MASACCS @var{a},@var{b}} 15771@item @code{uw1 __MAVEH (uw1, uw1)} 15772@tab @code{@var{c} = __MAVEH (@var{a}, @var{b})} 15773@tab @code{MAVEH @var{a},@var{b},@var{c}} 15774@item @code{uw2 __MBTOH (uw1)} 15775@tab @code{@var{b} = __MBTOH (@var{a})} 15776@tab @code{MBTOH @var{a},@var{b}} 15777@item @code{void __MBTOHE (uw1 *, uw1)} 15778@tab @code{__MBTOHE (&@var{b}, @var{a})} 15779@tab @code{MBTOHE @var{a},@var{b}} 15780@item @code{void __MCLRACC (acc)} 15781@tab @code{__MCLRACC (@var{a})} 15782@tab @code{MCLRACC @var{a}} 15783@item @code{void __MCLRACCA (void)} 15784@tab @code{__MCLRACCA ()} 15785@tab @code{MCLRACCA} 15786@item @code{uw1 __Mcop1 (uw1, uw1)} 15787@tab @code{@var{c} = __Mcop1 (@var{a}, @var{b})} 15788@tab @code{Mcop1 @var{a},@var{b},@var{c}} 15789@item @code{uw1 __Mcop2 (uw1, uw1)} 15790@tab @code{@var{c} = __Mcop2 (@var{a}, @var{b})} 15791@tab @code{Mcop2 @var{a},@var{b},@var{c}} 15792@item @code{uw1 __MCPLHI (uw2, const)} 15793@tab @code{@var{c} = __MCPLHI (@var{a}, @var{b})} 15794@tab @code{MCPLHI @var{a},#@var{b},@var{c}} 15795@item @code{uw1 __MCPLI (uw2, const)} 15796@tab @code{@var{c} = __MCPLI (@var{a}, @var{b})} 15797@tab @code{MCPLI @var{a},#@var{b},@var{c}} 15798@item @code{void __MCPXIS (acc, sw1, sw1)} 15799@tab @code{__MCPXIS (@var{c}, @var{a}, @var{b})} 15800@tab @code{MCPXIS @var{a},@var{b},@var{c}} 15801@item @code{void __MCPXIU (acc, uw1, uw1)} 15802@tab @code{__MCPXIU (@var{c}, @var{a}, @var{b})} 15803@tab @code{MCPXIU @var{a},@var{b},@var{c}} 15804@item @code{void __MCPXRS (acc, sw1, sw1)} 15805@tab @code{__MCPXRS (@var{c}, @var{a}, @var{b})} 15806@tab @code{MCPXRS @var{a},@var{b},@var{c}} 15807@item @code{void __MCPXRU (acc, uw1, uw1)} 15808@tab @code{__MCPXRU (@var{c}, @var{a}, @var{b})} 15809@tab @code{MCPXRU @var{a},@var{b},@var{c}} 15810@item @code{uw1 __MCUT (acc, uw1)} 15811@tab @code{@var{c} = __MCUT (@var{a}, @var{b})} 15812@tab @code{MCUT @var{a},@var{b},@var{c}} 15813@item @code{uw1 __MCUTSS (acc, sw1)} 15814@tab @code{@var{c} = __MCUTSS (@var{a}, @var{b})} 15815@tab @code{MCUTSS @var{a},@var{b},@var{c}} 15816@item @code{void __MDADDACCS (acc, acc)} 15817@tab @code{__MDADDACCS (@var{b}, @var{a})} 15818@tab @code{MDADDACCS @var{a},@var{b}} 15819@item @code{void __MDASACCS (acc, acc)} 15820@tab @code{__MDASACCS (@var{b}, @var{a})} 15821@tab @code{MDASACCS @var{a},@var{b}} 15822@item @code{uw2 __MDCUTSSI (acc, const)} 15823@tab @code{@var{c} = __MDCUTSSI (@var{a}, @var{b})} 15824@tab @code{MDCUTSSI @var{a},#@var{b},@var{c}} 15825@item @code{uw2 __MDPACKH (uw2, uw2)} 15826@tab @code{@var{c} = __MDPACKH (@var{a}, @var{b})} 15827@tab @code{MDPACKH @var{a},@var{b},@var{c}} 15828@item @code{uw2 __MDROTLI (uw2, const)} 15829@tab @code{@var{c} = __MDROTLI (@var{a}, @var{b})} 15830@tab @code{MDROTLI @var{a},#@var{b},@var{c}} 15831@item @code{void __MDSUBACCS (acc, acc)} 15832@tab @code{__MDSUBACCS (@var{b}, @var{a})} 15833@tab @code{MDSUBACCS @var{a},@var{b}} 15834@item @code{void __MDUNPACKH (uw1 *, uw2)} 15835@tab @code{__MDUNPACKH (&@var{b}, @var{a})} 15836@tab @code{MDUNPACKH @var{a},@var{b}} 15837@item @code{uw2 __MEXPDHD (uw1, const)} 15838@tab @code{@var{c} = __MEXPDHD (@var{a}, @var{b})} 15839@tab @code{MEXPDHD @var{a},#@var{b},@var{c}} 15840@item @code{uw1 __MEXPDHW (uw1, const)} 15841@tab @code{@var{c} = __MEXPDHW (@var{a}, @var{b})} 15842@tab @code{MEXPDHW @var{a},#@var{b},@var{c}} 15843@item @code{uw1 __MHDSETH (uw1, const)} 15844@tab @code{@var{c} = __MHDSETH (@var{a}, @var{b})} 15845@tab @code{MHDSETH @var{a},#@var{b},@var{c}} 15846@item @code{sw1 __MHDSETS (const)} 15847@tab @code{@var{b} = __MHDSETS (@var{a})} 15848@tab @code{MHDSETS #@var{a},@var{b}} 15849@item @code{uw1 __MHSETHIH (uw1, const)} 15850@tab @code{@var{b} = __MHSETHIH (@var{b}, @var{a})} 15851@tab @code{MHSETHIH #@var{a},@var{b}} 15852@item @code{sw1 __MHSETHIS (sw1, const)} 15853@tab @code{@var{b} = __MHSETHIS (@var{b}, @var{a})} 15854@tab @code{MHSETHIS #@var{a},@var{b}} 15855@item @code{uw1 __MHSETLOH (uw1, const)} 15856@tab @code{@var{b} = __MHSETLOH (@var{b}, @var{a})} 15857@tab @code{MHSETLOH #@var{a},@var{b}} 15858@item @code{sw1 __MHSETLOS (sw1, const)} 15859@tab @code{@var{b} = __MHSETLOS (@var{b}, @var{a})} 15860@tab @code{MHSETLOS #@var{a},@var{b}} 15861@item @code{uw1 __MHTOB (uw2)} 15862@tab @code{@var{b} = __MHTOB (@var{a})} 15863@tab @code{MHTOB @var{a},@var{b}} 15864@item @code{void __MMACHS (acc, sw1, sw1)} 15865@tab @code{__MMACHS (@var{c}, @var{a}, @var{b})} 15866@tab @code{MMACHS @var{a},@var{b},@var{c}} 15867@item @code{void __MMACHU (acc, uw1, uw1)} 15868@tab @code{__MMACHU (@var{c}, @var{a}, @var{b})} 15869@tab @code{MMACHU @var{a},@var{b},@var{c}} 15870@item @code{void __MMRDHS (acc, sw1, sw1)} 15871@tab @code{__MMRDHS (@var{c}, @var{a}, @var{b})} 15872@tab @code{MMRDHS @var{a},@var{b},@var{c}} 15873@item @code{void __MMRDHU (acc, uw1, uw1)} 15874@tab @code{__MMRDHU (@var{c}, @var{a}, @var{b})} 15875@tab @code{MMRDHU @var{a},@var{b},@var{c}} 15876@item @code{void __MMULHS (acc, sw1, sw1)} 15877@tab @code{__MMULHS (@var{c}, @var{a}, @var{b})} 15878@tab @code{MMULHS @var{a},@var{b},@var{c}} 15879@item @code{void __MMULHU (acc, uw1, uw1)} 15880@tab @code{__MMULHU (@var{c}, @var{a}, @var{b})} 15881@tab @code{MMULHU @var{a},@var{b},@var{c}} 15882@item @code{void __MMULXHS (acc, sw1, sw1)} 15883@tab @code{__MMULXHS (@var{c}, @var{a}, @var{b})} 15884@tab @code{MMULXHS @var{a},@var{b},@var{c}} 15885@item @code{void __MMULXHU (acc, uw1, uw1)} 15886@tab @code{__MMULXHU (@var{c}, @var{a}, @var{b})} 15887@tab @code{MMULXHU @var{a},@var{b},@var{c}} 15888@item @code{uw1 __MNOT (uw1)} 15889@tab @code{@var{b} = __MNOT (@var{a})} 15890@tab @code{MNOT @var{a},@var{b}} 15891@item @code{uw1 __MOR (uw1, uw1)} 15892@tab @code{@var{c} = __MOR (@var{a}, @var{b})} 15893@tab @code{MOR @var{a},@var{b},@var{c}} 15894@item @code{uw1 __MPACKH (uh, uh)} 15895@tab @code{@var{c} = __MPACKH (@var{a}, @var{b})} 15896@tab @code{MPACKH @var{a},@var{b},@var{c}} 15897@item @code{sw2 __MQADDHSS (sw2, sw2)} 15898@tab @code{@var{c} = __MQADDHSS (@var{a}, @var{b})} 15899@tab @code{MQADDHSS @var{a},@var{b},@var{c}} 15900@item @code{uw2 __MQADDHUS (uw2, uw2)} 15901@tab @code{@var{c} = __MQADDHUS (@var{a}, @var{b})} 15902@tab @code{MQADDHUS @var{a},@var{b},@var{c}} 15903@item @code{void __MQCPXIS (acc, sw2, sw2)} 15904@tab @code{__MQCPXIS (@var{c}, @var{a}, @var{b})} 15905@tab @code{MQCPXIS @var{a},@var{b},@var{c}} 15906@item @code{void __MQCPXIU (acc, uw2, uw2)} 15907@tab @code{__MQCPXIU (@var{c}, @var{a}, @var{b})} 15908@tab @code{MQCPXIU @var{a},@var{b},@var{c}} 15909@item @code{void __MQCPXRS (acc, sw2, sw2)} 15910@tab @code{__MQCPXRS (@var{c}, @var{a}, @var{b})} 15911@tab @code{MQCPXRS @var{a},@var{b},@var{c}} 15912@item @code{void __MQCPXRU (acc, uw2, uw2)} 15913@tab @code{__MQCPXRU (@var{c}, @var{a}, @var{b})} 15914@tab @code{MQCPXRU @var{a},@var{b},@var{c}} 15915@item @code{sw2 __MQLCLRHS (sw2, sw2)} 15916@tab @code{@var{c} = __MQLCLRHS (@var{a}, @var{b})} 15917@tab @code{MQLCLRHS @var{a},@var{b},@var{c}} 15918@item @code{sw2 __MQLMTHS (sw2, sw2)} 15919@tab @code{@var{c} = __MQLMTHS (@var{a}, @var{b})} 15920@tab @code{MQLMTHS @var{a},@var{b},@var{c}} 15921@item @code{void __MQMACHS (acc, sw2, sw2)} 15922@tab @code{__MQMACHS (@var{c}, @var{a}, @var{b})} 15923@tab @code{MQMACHS @var{a},@var{b},@var{c}} 15924@item @code{void __MQMACHU (acc, uw2, uw2)} 15925@tab @code{__MQMACHU (@var{c}, @var{a}, @var{b})} 15926@tab @code{MQMACHU @var{a},@var{b},@var{c}} 15927@item @code{void __MQMACXHS (acc, sw2, sw2)} 15928@tab @code{__MQMACXHS (@var{c}, @var{a}, @var{b})} 15929@tab @code{MQMACXHS @var{a},@var{b},@var{c}} 15930@item @code{void __MQMULHS (acc, sw2, sw2)} 15931@tab @code{__MQMULHS (@var{c}, @var{a}, @var{b})} 15932@tab @code{MQMULHS @var{a},@var{b},@var{c}} 15933@item @code{void __MQMULHU (acc, uw2, uw2)} 15934@tab @code{__MQMULHU (@var{c}, @var{a}, @var{b})} 15935@tab @code{MQMULHU @var{a},@var{b},@var{c}} 15936@item @code{void __MQMULXHS (acc, sw2, sw2)} 15937@tab @code{__MQMULXHS (@var{c}, @var{a}, @var{b})} 15938@tab @code{MQMULXHS @var{a},@var{b},@var{c}} 15939@item @code{void __MQMULXHU (acc, uw2, uw2)} 15940@tab @code{__MQMULXHU (@var{c}, @var{a}, @var{b})} 15941@tab @code{MQMULXHU @var{a},@var{b},@var{c}} 15942@item @code{sw2 __MQSATHS (sw2, sw2)} 15943@tab @code{@var{c} = __MQSATHS (@var{a}, @var{b})} 15944@tab @code{MQSATHS @var{a},@var{b},@var{c}} 15945@item @code{uw2 __MQSLLHI (uw2, int)} 15946@tab @code{@var{c} = __MQSLLHI (@var{a}, @var{b})} 15947@tab @code{MQSLLHI @var{a},@var{b},@var{c}} 15948@item @code{sw2 __MQSRAHI (sw2, int)} 15949@tab @code{@var{c} = __MQSRAHI (@var{a}, @var{b})} 15950@tab @code{MQSRAHI @var{a},@var{b},@var{c}} 15951@item @code{sw2 __MQSUBHSS (sw2, sw2)} 15952@tab @code{@var{c} = __MQSUBHSS (@var{a}, @var{b})} 15953@tab @code{MQSUBHSS @var{a},@var{b},@var{c}} 15954@item @code{uw2 __MQSUBHUS (uw2, uw2)} 15955@tab @code{@var{c} = __MQSUBHUS (@var{a}, @var{b})} 15956@tab @code{MQSUBHUS @var{a},@var{b},@var{c}} 15957@item @code{void __MQXMACHS (acc, sw2, sw2)} 15958@tab @code{__MQXMACHS (@var{c}, @var{a}, @var{b})} 15959@tab @code{MQXMACHS @var{a},@var{b},@var{c}} 15960@item @code{void __MQXMACXHS (acc, sw2, sw2)} 15961@tab @code{__MQXMACXHS (@var{c}, @var{a}, @var{b})} 15962@tab @code{MQXMACXHS @var{a},@var{b},@var{c}} 15963@item @code{uw1 __MRDACC (acc)} 15964@tab @code{@var{b} = __MRDACC (@var{a})} 15965@tab @code{MRDACC @var{a},@var{b}} 15966@item @code{uw1 __MRDACCG (acc)} 15967@tab @code{@var{b} = __MRDACCG (@var{a})} 15968@tab @code{MRDACCG @var{a},@var{b}} 15969@item @code{uw1 __MROTLI (uw1, const)} 15970@tab @code{@var{c} = __MROTLI (@var{a}, @var{b})} 15971@tab @code{MROTLI @var{a},#@var{b},@var{c}} 15972@item @code{uw1 __MROTRI (uw1, const)} 15973@tab @code{@var{c} = __MROTRI (@var{a}, @var{b})} 15974@tab @code{MROTRI @var{a},#@var{b},@var{c}} 15975@item @code{sw1 __MSATHS (sw1, sw1)} 15976@tab @code{@var{c} = __MSATHS (@var{a}, @var{b})} 15977@tab @code{MSATHS @var{a},@var{b},@var{c}} 15978@item @code{uw1 __MSATHU (uw1, uw1)} 15979@tab @code{@var{c} = __MSATHU (@var{a}, @var{b})} 15980@tab @code{MSATHU @var{a},@var{b},@var{c}} 15981@item @code{uw1 __MSLLHI (uw1, const)} 15982@tab @code{@var{c} = __MSLLHI (@var{a}, @var{b})} 15983@tab @code{MSLLHI @var{a},#@var{b},@var{c}} 15984@item @code{sw1 __MSRAHI (sw1, const)} 15985@tab @code{@var{c} = __MSRAHI (@var{a}, @var{b})} 15986@tab @code{MSRAHI @var{a},#@var{b},@var{c}} 15987@item @code{uw1 __MSRLHI (uw1, const)} 15988@tab @code{@var{c} = __MSRLHI (@var{a}, @var{b})} 15989@tab @code{MSRLHI @var{a},#@var{b},@var{c}} 15990@item @code{void __MSUBACCS (acc, acc)} 15991@tab @code{__MSUBACCS (@var{b}, @var{a})} 15992@tab @code{MSUBACCS @var{a},@var{b}} 15993@item @code{sw1 __MSUBHSS (sw1, sw1)} 15994@tab @code{@var{c} = __MSUBHSS (@var{a}, @var{b})} 15995@tab @code{MSUBHSS @var{a},@var{b},@var{c}} 15996@item @code{uw1 __MSUBHUS (uw1, uw1)} 15997@tab @code{@var{c} = __MSUBHUS (@var{a}, @var{b})} 15998@tab @code{MSUBHUS @var{a},@var{b},@var{c}} 15999@item @code{void __MTRAP (void)} 16000@tab @code{__MTRAP ()} 16001@tab @code{MTRAP} 16002@item @code{uw2 __MUNPACKH (uw1)} 16003@tab @code{@var{b} = __MUNPACKH (@var{a})} 16004@tab @code{MUNPACKH @var{a},@var{b}} 16005@item @code{uw1 __MWCUT (uw2, uw1)} 16006@tab @code{@var{c} = __MWCUT (@var{a}, @var{b})} 16007@tab @code{MWCUT @var{a},@var{b},@var{c}} 16008@item @code{void __MWTACC (acc, uw1)} 16009@tab @code{__MWTACC (@var{b}, @var{a})} 16010@tab @code{MWTACC @var{a},@var{b}} 16011@item @code{void __MWTACCG (acc, uw1)} 16012@tab @code{__MWTACCG (@var{b}, @var{a})} 16013@tab @code{MWTACCG @var{a},@var{b}} 16014@item @code{uw1 __MXOR (uw1, uw1)} 16015@tab @code{@var{c} = __MXOR (@var{a}, @var{b})} 16016@tab @code{MXOR @var{a},@var{b},@var{c}} 16017@end multitable 16018 16019@node Raw read/write Functions 16020@subsubsection Raw Read/Write Functions 16021 16022This sections describes built-in functions related to read and write 16023instructions to access memory. These functions generate 16024@code{membar} instructions to flush the I/O load and stores where 16025appropriate, as described in Fujitsu's manual described above. 16026 16027@table @code 16028 16029@item unsigned char __builtin_read8 (void *@var{data}) 16030@item unsigned short __builtin_read16 (void *@var{data}) 16031@item unsigned long __builtin_read32 (void *@var{data}) 16032@item unsigned long long __builtin_read64 (void *@var{data}) 16033 16034@item void __builtin_write8 (void *@var{data}, unsigned char @var{datum}) 16035@item void __builtin_write16 (void *@var{data}, unsigned short @var{datum}) 16036@item void __builtin_write32 (void *@var{data}, unsigned long @var{datum}) 16037@item void __builtin_write64 (void *@var{data}, unsigned long long @var{datum}) 16038@end table 16039 16040@node Other Built-in Functions 16041@subsubsection Other Built-in Functions 16042 16043This section describes built-in functions that are not named after 16044a specific FR-V instruction. 16045 16046@table @code 16047@item sw2 __IACCreadll (iacc @var{reg}) 16048Return the full 64-bit value of IACC0@. The @var{reg} argument is reserved 16049for future expansion and must be 0. 16050 16051@item sw1 __IACCreadl (iacc @var{reg}) 16052Return the value of IACC0H if @var{reg} is 0 and IACC0L if @var{reg} is 1. 16053Other values of @var{reg} are rejected as invalid. 16054 16055@item void __IACCsetll (iacc @var{reg}, sw2 @var{x}) 16056Set the full 64-bit value of IACC0 to @var{x}. The @var{reg} argument 16057is reserved for future expansion and must be 0. 16058 16059@item void __IACCsetl (iacc @var{reg}, sw1 @var{x}) 16060Set IACC0H to @var{x} if @var{reg} is 0 and IACC0L to @var{x} if @var{reg} 16061is 1. Other values of @var{reg} are rejected as invalid. 16062 16063@item void __data_prefetch0 (const void *@var{x}) 16064Use the @code{dcpl} instruction to load the contents of address @var{x} 16065into the data cache. 16066 16067@item void __data_prefetch (const void *@var{x}) 16068Use the @code{nldub} instruction to load the contents of address @var{x} 16069into the data cache. The instruction is issued in slot I1@. 16070@end table 16071 16072@node LoongArch Base Built-in Functions 16073@subsection LoongArch Base Built-in Functions 16074 16075These built-in functions are available for LoongArch. 16076 16077Data Type Description: 16078@itemize 16079@item @code{imm0_31}, a compile-time constant in range 0 to 31; 16080@item @code{imm0_16383}, a compile-time constant in range 0 to 16383; 16081@item @code{imm0_32767}, a compile-time constant in range 0 to 32767; 16082@item @code{imm_n2048_2047}, a compile-time constant in range -2048 to 2047; 16083@end itemize 16084 16085The intrinsics provided are listed below: 16086@smallexample 16087 unsigned int __builtin_loongarch_movfcsr2gr (imm0_31) 16088 void __builtin_loongarch_movgr2fcsr (imm0_31, unsigned int) 16089 void __builtin_loongarch_cacop_d (imm0_31, unsigned long int, imm_n2048_2047) 16090 unsigned int __builtin_loongarch_cpucfg (unsigned int) 16091 void __builtin_loongarch_asrtle_d (long int, long int) 16092 void __builtin_loongarch_asrtgt_d (long int, long int) 16093 long int __builtin_loongarch_lddir_d (long int, imm0_31) 16094 void __builtin_loongarch_ldpte_d (long int, imm0_31) 16095 16096 int __builtin_loongarch_crc_w_b_w (char, int) 16097 int __builtin_loongarch_crc_w_h_w (short, int) 16098 int __builtin_loongarch_crc_w_w_w (int, int) 16099 int __builtin_loongarch_crc_w_d_w (long int, int) 16100 int __builtin_loongarch_crcc_w_b_w (char, int) 16101 int __builtin_loongarch_crcc_w_h_w (short, int) 16102 int __builtin_loongarch_crcc_w_w_w (int, int) 16103 int __builtin_loongarch_crcc_w_d_w (long int, int) 16104 16105 unsigned int __builtin_loongarch_csrrd_w (imm0_16383) 16106 unsigned int __builtin_loongarch_csrwr_w (unsigned int, imm0_16383) 16107 unsigned int __builtin_loongarch_csrxchg_w (unsigned int, unsigned int, imm0_16383) 16108 unsigned long int __builtin_loongarch_csrrd_d (imm0_16383) 16109 unsigned long int __builtin_loongarch_csrwr_d (unsigned long int, imm0_16383) 16110 unsigned long int __builtin_loongarch_csrxchg_d (unsigned long int, unsigned long int, imm0_16383) 16111 16112 unsigned char __builtin_loongarch_iocsrrd_b (unsigned int) 16113 unsigned short __builtin_loongarch_iocsrrd_h (unsigned int) 16114 unsigned int __builtin_loongarch_iocsrrd_w (unsigned int) 16115 unsigned long int __builtin_loongarch_iocsrrd_d (unsigned int) 16116 void __builtin_loongarch_iocsrwr_b (unsigned char, unsigned int) 16117 void __builtin_loongarch_iocsrwr_h (unsigned short, unsigned int) 16118 void __builtin_loongarch_iocsrwr_w (unsigned int, unsigned int) 16119 void __builtin_loongarch_iocsrwr_d (unsigned long int, unsigned int) 16120 16121 void __builtin_loongarch_dbar (imm0_32767) 16122 void __builtin_loongarch_ibar (imm0_32767) 16123 16124 void __builtin_loongarch_syscall (imm0_32767) 16125 void __builtin_loongarch_break (imm0_32767) 16126@end smallexample 16127 16128@emph{Note:}Since the control register is divided into 32-bit and 64-bit, 16129but the access instruction is not distinguished. So GCC renames the control 16130instructions when implementing intrinsics. 16131 16132Take the csrrd instruction as an example, built-in functions are implemented as follows: 16133@smallexample 16134 __builtin_loongarch_csrrd_w // When reading the 32-bit control register use. 16135 __builtin_loongarch_csrrd_d // When reading the 64-bit control register use. 16136@end smallexample 16137 16138For the convenience of use, the built-in functions are encapsulated, 16139the encapsulated functions and @code{__drdtime_t, __rdtime_t} are 16140defined in the @code{larchintrin.h}. So if you call the following 16141function you need to include @code{larchintrin.h}. 16142 16143@smallexample 16144 typedef struct drdtime@{ 16145 unsigned long dvalue; 16146 unsigned long dtimeid; 16147 @} __drdtime_t; 16148 16149 typedef struct rdtime@{ 16150 unsigned int value; 16151 unsigned int timeid; 16152 @} __rdtime_t; 16153@end smallexample 16154 16155@smallexample 16156 __drdtime_t __rdtime_d (void) 16157 __rdtime_t __rdtimel_w (void) 16158 __rdtime_t __rdtimeh_w (void) 16159 unsigned int __movfcsr2gr (imm0_31) 16160 void __movgr2fcsr (imm0_31, unsigned int) 16161 void __cacop_d (imm0_31, unsigned long, imm_n2048_2047) 16162 unsigned int __cpucfg (unsigned int) 16163 void __asrtle_d (long int, long int) 16164 void __asrtgt_d (long int, long int) 16165 long int __lddir_d (long int, imm0_31) 16166 void __ldpte_d (long int, imm0_31) 16167 16168 int __crc_w_b_w (char, int) 16169 int __crc_w_h_w (short, int) 16170 int __crc_w_w_w (int, int) 16171 int __crc_w_d_w (long int, int) 16172 int __crcc_w_b_w (char, int) 16173 int __crcc_w_h_w (short, int) 16174 int __crcc_w_w_w (int, int) 16175 int __crcc_w_d_w (long int, int) 16176 16177 unsigned int __csrrd_w (imm0_16383) 16178 unsigned int __csrwr_w (unsigned int, imm0_16383) 16179 unsigned int __csrxchg_w (unsigned int, unsigned int, imm0_16383) 16180 unsigned long __csrrd_d (imm0_16383) 16181 unsigned long __csrwr_d (unsigned long, imm0_16383) 16182 unsigned long __csrxchg_d (unsigned long, unsigned long, imm0_16383) 16183 16184 unsigned char __iocsrrd_b (unsigned int) 16185 unsigned short __iocsrrd_h (unsigned int) 16186 unsigned int __iocsrrd_w (unsigned int) 16187 unsigned long __iocsrrd_d (unsigned int) 16188 void __iocsrwr_b (unsigned char, unsigned int) 16189 void __iocsrwr_h (unsigned short, unsigned int) 16190 void __iocsrwr_w (unsigned int, unsigned int) 16191 void __iocsrwr_d (unsigned long, unsigned int) 16192 16193 void __dbar (imm0_32767) 16194 void __ibar (imm0_32767) 16195 16196 void __syscall (imm0_32767) 16197 void __break (imm0_32767) 16198@end smallexample 16199 16200Returns the value that is currently set in the @samp{tp} register. 16201@smallexample 16202 void * __builtin_thread_pointer (void) 16203@end smallexample 16204 16205@node MIPS DSP Built-in Functions 16206@subsection MIPS DSP Built-in Functions 16207 16208The MIPS DSP Application-Specific Extension (ASE) includes new 16209instructions that are designed to improve the performance of DSP and 16210media applications. It provides instructions that operate on packed 162118-bit/16-bit integer data, Q7, Q15 and Q31 fractional data. 16212 16213GCC supports MIPS DSP operations using both the generic 16214vector extensions (@pxref{Vector Extensions}) and a collection of 16215MIPS-specific built-in functions. Both kinds of support are 16216enabled by the @option{-mdsp} command-line option. 16217 16218Revision 2 of the ASE was introduced in the second half of 2006. 16219This revision adds extra instructions to the original ASE, but is 16220otherwise backwards-compatible with it. You can select revision 2 16221using the command-line option @option{-mdspr2}; this option implies 16222@option{-mdsp}. 16223 16224The SCOUNT and POS bits of the DSP control register are global. The 16225WRDSP, EXTPDP, EXTPDPV and MTHLIP instructions modify the SCOUNT and 16226POS bits. During optimization, the compiler does not delete these 16227instructions and it does not delete calls to functions containing 16228these instructions. 16229 16230At present, GCC only provides support for operations on 32-bit 16231vectors. The vector type associated with 8-bit integer data is 16232usually called @code{v4i8}, the vector type associated with Q7 16233is usually called @code{v4q7}, the vector type associated with 16-bit 16234integer data is usually called @code{v2i16}, and the vector type 16235associated with Q15 is usually called @code{v2q15}. They can be 16236defined in C as follows: 16237 16238@smallexample 16239typedef signed char v4i8 __attribute__ ((vector_size(4))); 16240typedef signed char v4q7 __attribute__ ((vector_size(4))); 16241typedef short v2i16 __attribute__ ((vector_size(4))); 16242typedef short v2q15 __attribute__ ((vector_size(4))); 16243@end smallexample 16244 16245@code{v4i8}, @code{v4q7}, @code{v2i16} and @code{v2q15} values are 16246initialized in the same way as aggregates. For example: 16247 16248@smallexample 16249v4i8 a = @{1, 2, 3, 4@}; 16250v4i8 b; 16251b = (v4i8) @{5, 6, 7, 8@}; 16252 16253v2q15 c = @{0x0fcb, 0x3a75@}; 16254v2q15 d; 16255d = (v2q15) @{0.1234 * 0x1.0p15, 0.4567 * 0x1.0p15@}; 16256@end smallexample 16257 16258@emph{Note:} The CPU's endianness determines the order in which values 16259are packed. On little-endian targets, the first value is the least 16260significant and the last value is the most significant. The opposite 16261order applies to big-endian targets. For example, the code above 16262sets the lowest byte of @code{a} to @code{1} on little-endian targets 16263and @code{4} on big-endian targets. 16264 16265@emph{Note:} Q7, Q15 and Q31 values must be initialized with their integer 16266representation. As shown in this example, the integer representation 16267of a Q7 value can be obtained by multiplying the fractional value by 16268@code{0x1.0p7}. The equivalent for Q15 values is to multiply by 16269@code{0x1.0p15}. The equivalent for Q31 values is to multiply by 16270@code{0x1.0p31}. 16271 16272The table below lists the @code{v4i8} and @code{v2q15} operations for which 16273hardware support exists. @code{a} and @code{b} are @code{v4i8} values, 16274and @code{c} and @code{d} are @code{v2q15} values. 16275 16276@multitable @columnfractions .50 .50 16277@headitem C code @tab MIPS instruction 16278@item @code{a + b} @tab @code{addu.qb} 16279@item @code{c + d} @tab @code{addq.ph} 16280@item @code{a - b} @tab @code{subu.qb} 16281@item @code{c - d} @tab @code{subq.ph} 16282@end multitable 16283 16284The table below lists the @code{v2i16} operation for which 16285hardware support exists for the DSP ASE REV 2. @code{e} and @code{f} are 16286@code{v2i16} values. 16287 16288@multitable @columnfractions .50 .50 16289@headitem C code @tab MIPS instruction 16290@item @code{e * f} @tab @code{mul.ph} 16291@end multitable 16292 16293It is easier to describe the DSP built-in functions if we first define 16294the following types: 16295 16296@smallexample 16297typedef int q31; 16298typedef int i32; 16299typedef unsigned int ui32; 16300typedef long long a64; 16301@end smallexample 16302 16303@code{q31} and @code{i32} are actually the same as @code{int}, but we 16304use @code{q31} to indicate a Q31 fractional value and @code{i32} to 16305indicate a 32-bit integer value. Similarly, @code{a64} is the same as 16306@code{long long}, but we use @code{a64} to indicate values that are 16307placed in one of the four DSP accumulators (@code{$ac0}, 16308@code{$ac1}, @code{$ac2} or @code{$ac3}). 16309 16310Also, some built-in functions prefer or require immediate numbers as 16311parameters, because the corresponding DSP instructions accept both immediate 16312numbers and register operands, or accept immediate numbers only. The 16313immediate parameters are listed as follows. 16314 16315@smallexample 16316imm0_3: 0 to 3. 16317imm0_7: 0 to 7. 16318imm0_15: 0 to 15. 16319imm0_31: 0 to 31. 16320imm0_63: 0 to 63. 16321imm0_255: 0 to 255. 16322imm_n32_31: -32 to 31. 16323imm_n512_511: -512 to 511. 16324@end smallexample 16325 16326The following built-in functions map directly to a particular MIPS DSP 16327instruction. Please refer to the architecture specification 16328for details on what each instruction does. 16329 16330@smallexample 16331v2q15 __builtin_mips_addq_ph (v2q15, v2q15); 16332v2q15 __builtin_mips_addq_s_ph (v2q15, v2q15); 16333q31 __builtin_mips_addq_s_w (q31, q31); 16334v4i8 __builtin_mips_addu_qb (v4i8, v4i8); 16335v4i8 __builtin_mips_addu_s_qb (v4i8, v4i8); 16336v2q15 __builtin_mips_subq_ph (v2q15, v2q15); 16337v2q15 __builtin_mips_subq_s_ph (v2q15, v2q15); 16338q31 __builtin_mips_subq_s_w (q31, q31); 16339v4i8 __builtin_mips_subu_qb (v4i8, v4i8); 16340v4i8 __builtin_mips_subu_s_qb (v4i8, v4i8); 16341i32 __builtin_mips_addsc (i32, i32); 16342i32 __builtin_mips_addwc (i32, i32); 16343i32 __builtin_mips_modsub (i32, i32); 16344i32 __builtin_mips_raddu_w_qb (v4i8); 16345v2q15 __builtin_mips_absq_s_ph (v2q15); 16346q31 __builtin_mips_absq_s_w (q31); 16347v4i8 __builtin_mips_precrq_qb_ph (v2q15, v2q15); 16348v2q15 __builtin_mips_precrq_ph_w (q31, q31); 16349v2q15 __builtin_mips_precrq_rs_ph_w (q31, q31); 16350v4i8 __builtin_mips_precrqu_s_qb_ph (v2q15, v2q15); 16351q31 __builtin_mips_preceq_w_phl (v2q15); 16352q31 __builtin_mips_preceq_w_phr (v2q15); 16353v2q15 __builtin_mips_precequ_ph_qbl (v4i8); 16354v2q15 __builtin_mips_precequ_ph_qbr (v4i8); 16355v2q15 __builtin_mips_precequ_ph_qbla (v4i8); 16356v2q15 __builtin_mips_precequ_ph_qbra (v4i8); 16357v2q15 __builtin_mips_preceu_ph_qbl (v4i8); 16358v2q15 __builtin_mips_preceu_ph_qbr (v4i8); 16359v2q15 __builtin_mips_preceu_ph_qbla (v4i8); 16360v2q15 __builtin_mips_preceu_ph_qbra (v4i8); 16361v4i8 __builtin_mips_shll_qb (v4i8, imm0_7); 16362v4i8 __builtin_mips_shll_qb (v4i8, i32); 16363v2q15 __builtin_mips_shll_ph (v2q15, imm0_15); 16364v2q15 __builtin_mips_shll_ph (v2q15, i32); 16365v2q15 __builtin_mips_shll_s_ph (v2q15, imm0_15); 16366v2q15 __builtin_mips_shll_s_ph (v2q15, i32); 16367q31 __builtin_mips_shll_s_w (q31, imm0_31); 16368q31 __builtin_mips_shll_s_w (q31, i32); 16369v4i8 __builtin_mips_shrl_qb (v4i8, imm0_7); 16370v4i8 __builtin_mips_shrl_qb (v4i8, i32); 16371v2q15 __builtin_mips_shra_ph (v2q15, imm0_15); 16372v2q15 __builtin_mips_shra_ph (v2q15, i32); 16373v2q15 __builtin_mips_shra_r_ph (v2q15, imm0_15); 16374v2q15 __builtin_mips_shra_r_ph (v2q15, i32); 16375q31 __builtin_mips_shra_r_w (q31, imm0_31); 16376q31 __builtin_mips_shra_r_w (q31, i32); 16377v2q15 __builtin_mips_muleu_s_ph_qbl (v4i8, v2q15); 16378v2q15 __builtin_mips_muleu_s_ph_qbr (v4i8, v2q15); 16379v2q15 __builtin_mips_mulq_rs_ph (v2q15, v2q15); 16380q31 __builtin_mips_muleq_s_w_phl (v2q15, v2q15); 16381q31 __builtin_mips_muleq_s_w_phr (v2q15, v2q15); 16382a64 __builtin_mips_dpau_h_qbl (a64, v4i8, v4i8); 16383a64 __builtin_mips_dpau_h_qbr (a64, v4i8, v4i8); 16384a64 __builtin_mips_dpsu_h_qbl (a64, v4i8, v4i8); 16385a64 __builtin_mips_dpsu_h_qbr (a64, v4i8, v4i8); 16386a64 __builtin_mips_dpaq_s_w_ph (a64, v2q15, v2q15); 16387a64 __builtin_mips_dpaq_sa_l_w (a64, q31, q31); 16388a64 __builtin_mips_dpsq_s_w_ph (a64, v2q15, v2q15); 16389a64 __builtin_mips_dpsq_sa_l_w (a64, q31, q31); 16390a64 __builtin_mips_mulsaq_s_w_ph (a64, v2q15, v2q15); 16391a64 __builtin_mips_maq_s_w_phl (a64, v2q15, v2q15); 16392a64 __builtin_mips_maq_s_w_phr (a64, v2q15, v2q15); 16393a64 __builtin_mips_maq_sa_w_phl (a64, v2q15, v2q15); 16394a64 __builtin_mips_maq_sa_w_phr (a64, v2q15, v2q15); 16395i32 __builtin_mips_bitrev (i32); 16396i32 __builtin_mips_insv (i32, i32); 16397v4i8 __builtin_mips_repl_qb (imm0_255); 16398v4i8 __builtin_mips_repl_qb (i32); 16399v2q15 __builtin_mips_repl_ph (imm_n512_511); 16400v2q15 __builtin_mips_repl_ph (i32); 16401void __builtin_mips_cmpu_eq_qb (v4i8, v4i8); 16402void __builtin_mips_cmpu_lt_qb (v4i8, v4i8); 16403void __builtin_mips_cmpu_le_qb (v4i8, v4i8); 16404i32 __builtin_mips_cmpgu_eq_qb (v4i8, v4i8); 16405i32 __builtin_mips_cmpgu_lt_qb (v4i8, v4i8); 16406i32 __builtin_mips_cmpgu_le_qb (v4i8, v4i8); 16407void __builtin_mips_cmp_eq_ph (v2q15, v2q15); 16408void __builtin_mips_cmp_lt_ph (v2q15, v2q15); 16409void __builtin_mips_cmp_le_ph (v2q15, v2q15); 16410v4i8 __builtin_mips_pick_qb (v4i8, v4i8); 16411v2q15 __builtin_mips_pick_ph (v2q15, v2q15); 16412v2q15 __builtin_mips_packrl_ph (v2q15, v2q15); 16413i32 __builtin_mips_extr_w (a64, imm0_31); 16414i32 __builtin_mips_extr_w (a64, i32); 16415i32 __builtin_mips_extr_r_w (a64, imm0_31); 16416i32 __builtin_mips_extr_s_h (a64, i32); 16417i32 __builtin_mips_extr_rs_w (a64, imm0_31); 16418i32 __builtin_mips_extr_rs_w (a64, i32); 16419i32 __builtin_mips_extr_s_h (a64, imm0_31); 16420i32 __builtin_mips_extr_r_w (a64, i32); 16421i32 __builtin_mips_extp (a64, imm0_31); 16422i32 __builtin_mips_extp (a64, i32); 16423i32 __builtin_mips_extpdp (a64, imm0_31); 16424i32 __builtin_mips_extpdp (a64, i32); 16425a64 __builtin_mips_shilo (a64, imm_n32_31); 16426a64 __builtin_mips_shilo (a64, i32); 16427a64 __builtin_mips_mthlip (a64, i32); 16428void __builtin_mips_wrdsp (i32, imm0_63); 16429i32 __builtin_mips_rddsp (imm0_63); 16430i32 __builtin_mips_lbux (void *, i32); 16431i32 __builtin_mips_lhx (void *, i32); 16432i32 __builtin_mips_lwx (void *, i32); 16433a64 __builtin_mips_ldx (void *, i32); /* MIPS64 only */ 16434i32 __builtin_mips_bposge32 (void); 16435a64 __builtin_mips_madd (a64, i32, i32); 16436a64 __builtin_mips_maddu (a64, ui32, ui32); 16437a64 __builtin_mips_msub (a64, i32, i32); 16438a64 __builtin_mips_msubu (a64, ui32, ui32); 16439a64 __builtin_mips_mult (i32, i32); 16440a64 __builtin_mips_multu (ui32, ui32); 16441@end smallexample 16442 16443The following built-in functions map directly to a particular MIPS DSP REV 2 16444instruction. Please refer to the architecture specification 16445for details on what each instruction does. 16446 16447@smallexample 16448v4q7 __builtin_mips_absq_s_qb (v4q7); 16449v2i16 __builtin_mips_addu_ph (v2i16, v2i16); 16450v2i16 __builtin_mips_addu_s_ph (v2i16, v2i16); 16451v4i8 __builtin_mips_adduh_qb (v4i8, v4i8); 16452v4i8 __builtin_mips_adduh_r_qb (v4i8, v4i8); 16453i32 __builtin_mips_append (i32, i32, imm0_31); 16454i32 __builtin_mips_balign (i32, i32, imm0_3); 16455i32 __builtin_mips_cmpgdu_eq_qb (v4i8, v4i8); 16456i32 __builtin_mips_cmpgdu_lt_qb (v4i8, v4i8); 16457i32 __builtin_mips_cmpgdu_le_qb (v4i8, v4i8); 16458a64 __builtin_mips_dpa_w_ph (a64, v2i16, v2i16); 16459a64 __builtin_mips_dps_w_ph (a64, v2i16, v2i16); 16460v2i16 __builtin_mips_mul_ph (v2i16, v2i16); 16461v2i16 __builtin_mips_mul_s_ph (v2i16, v2i16); 16462q31 __builtin_mips_mulq_rs_w (q31, q31); 16463v2q15 __builtin_mips_mulq_s_ph (v2q15, v2q15); 16464q31 __builtin_mips_mulq_s_w (q31, q31); 16465a64 __builtin_mips_mulsa_w_ph (a64, v2i16, v2i16); 16466v4i8 __builtin_mips_precr_qb_ph (v2i16, v2i16); 16467v2i16 __builtin_mips_precr_sra_ph_w (i32, i32, imm0_31); 16468v2i16 __builtin_mips_precr_sra_r_ph_w (i32, i32, imm0_31); 16469i32 __builtin_mips_prepend (i32, i32, imm0_31); 16470v4i8 __builtin_mips_shra_qb (v4i8, imm0_7); 16471v4i8 __builtin_mips_shra_r_qb (v4i8, imm0_7); 16472v4i8 __builtin_mips_shra_qb (v4i8, i32); 16473v4i8 __builtin_mips_shra_r_qb (v4i8, i32); 16474v2i16 __builtin_mips_shrl_ph (v2i16, imm0_15); 16475v2i16 __builtin_mips_shrl_ph (v2i16, i32); 16476v2i16 __builtin_mips_subu_ph (v2i16, v2i16); 16477v2i16 __builtin_mips_subu_s_ph (v2i16, v2i16); 16478v4i8 __builtin_mips_subuh_qb (v4i8, v4i8); 16479v4i8 __builtin_mips_subuh_r_qb (v4i8, v4i8); 16480v2q15 __builtin_mips_addqh_ph (v2q15, v2q15); 16481v2q15 __builtin_mips_addqh_r_ph (v2q15, v2q15); 16482q31 __builtin_mips_addqh_w (q31, q31); 16483q31 __builtin_mips_addqh_r_w (q31, q31); 16484v2q15 __builtin_mips_subqh_ph (v2q15, v2q15); 16485v2q15 __builtin_mips_subqh_r_ph (v2q15, v2q15); 16486q31 __builtin_mips_subqh_w (q31, q31); 16487q31 __builtin_mips_subqh_r_w (q31, q31); 16488a64 __builtin_mips_dpax_w_ph (a64, v2i16, v2i16); 16489a64 __builtin_mips_dpsx_w_ph (a64, v2i16, v2i16); 16490a64 __builtin_mips_dpaqx_s_w_ph (a64, v2q15, v2q15); 16491a64 __builtin_mips_dpaqx_sa_w_ph (a64, v2q15, v2q15); 16492a64 __builtin_mips_dpsqx_s_w_ph (a64, v2q15, v2q15); 16493a64 __builtin_mips_dpsqx_sa_w_ph (a64, v2q15, v2q15); 16494@end smallexample 16495 16496 16497@node MIPS Paired-Single Support 16498@subsection MIPS Paired-Single Support 16499 16500The MIPS64 architecture includes a number of instructions that 16501operate on pairs of single-precision floating-point values. 16502Each pair is packed into a 64-bit floating-point register, 16503with one element being designated the ``upper half'' and 16504the other being designated the ``lower half''. 16505 16506GCC supports paired-single operations using both the generic 16507vector extensions (@pxref{Vector Extensions}) and a collection of 16508MIPS-specific built-in functions. Both kinds of support are 16509enabled by the @option{-mpaired-single} command-line option. 16510 16511The vector type associated with paired-single values is usually 16512called @code{v2sf}. It can be defined in C as follows: 16513 16514@smallexample 16515typedef float v2sf __attribute__ ((vector_size (8))); 16516@end smallexample 16517 16518@code{v2sf} values are initialized in the same way as aggregates. 16519For example: 16520 16521@smallexample 16522v2sf a = @{1.5, 9.1@}; 16523v2sf b; 16524float e, f; 16525b = (v2sf) @{e, f@}; 16526@end smallexample 16527 16528@emph{Note:} The CPU's endianness determines which value is stored in 16529the upper half of a register and which value is stored in the lower half. 16530On little-endian targets, the first value is the lower one and the second 16531value is the upper one. The opposite order applies to big-endian targets. 16532For example, the code above sets the lower half of @code{a} to 16533@code{1.5} on little-endian targets and @code{9.1} on big-endian targets. 16534 16535@node MIPS Loongson Built-in Functions 16536@subsection MIPS Loongson Built-in Functions 16537 16538GCC provides intrinsics to access the SIMD instructions provided by the 16539ST Microelectronics Loongson-2E and -2F processors. These intrinsics, 16540available after inclusion of the @code{loongson.h} header file, 16541operate on the following 64-bit vector types: 16542 16543@itemize 16544@item @code{uint8x8_t}, a vector of eight unsigned 8-bit integers; 16545@item @code{uint16x4_t}, a vector of four unsigned 16-bit integers; 16546@item @code{uint32x2_t}, a vector of two unsigned 32-bit integers; 16547@item @code{int8x8_t}, a vector of eight signed 8-bit integers; 16548@item @code{int16x4_t}, a vector of four signed 16-bit integers; 16549@item @code{int32x2_t}, a vector of two signed 32-bit integers. 16550@end itemize 16551 16552The intrinsics provided are listed below; each is named after the 16553machine instruction to which it corresponds, with suffixes added as 16554appropriate to distinguish intrinsics that expand to the same machine 16555instruction yet have different argument types. Refer to the architecture 16556documentation for a description of the functionality of each 16557instruction. 16558 16559@smallexample 16560int16x4_t packsswh (int32x2_t s, int32x2_t t); 16561int8x8_t packsshb (int16x4_t s, int16x4_t t); 16562uint8x8_t packushb (uint16x4_t s, uint16x4_t t); 16563uint32x2_t paddw_u (uint32x2_t s, uint32x2_t t); 16564uint16x4_t paddh_u (uint16x4_t s, uint16x4_t t); 16565uint8x8_t paddb_u (uint8x8_t s, uint8x8_t t); 16566int32x2_t paddw_s (int32x2_t s, int32x2_t t); 16567int16x4_t paddh_s (int16x4_t s, int16x4_t t); 16568int8x8_t paddb_s (int8x8_t s, int8x8_t t); 16569uint64_t paddd_u (uint64_t s, uint64_t t); 16570int64_t paddd_s (int64_t s, int64_t t); 16571int16x4_t paddsh (int16x4_t s, int16x4_t t); 16572int8x8_t paddsb (int8x8_t s, int8x8_t t); 16573uint16x4_t paddush (uint16x4_t s, uint16x4_t t); 16574uint8x8_t paddusb (uint8x8_t s, uint8x8_t t); 16575uint64_t pandn_ud (uint64_t s, uint64_t t); 16576uint32x2_t pandn_uw (uint32x2_t s, uint32x2_t t); 16577uint16x4_t pandn_uh (uint16x4_t s, uint16x4_t t); 16578uint8x8_t pandn_ub (uint8x8_t s, uint8x8_t t); 16579int64_t pandn_sd (int64_t s, int64_t t); 16580int32x2_t pandn_sw (int32x2_t s, int32x2_t t); 16581int16x4_t pandn_sh (int16x4_t s, int16x4_t t); 16582int8x8_t pandn_sb (int8x8_t s, int8x8_t t); 16583uint16x4_t pavgh (uint16x4_t s, uint16x4_t t); 16584uint8x8_t pavgb (uint8x8_t s, uint8x8_t t); 16585uint32x2_t pcmpeqw_u (uint32x2_t s, uint32x2_t t); 16586uint16x4_t pcmpeqh_u (uint16x4_t s, uint16x4_t t); 16587uint8x8_t pcmpeqb_u (uint8x8_t s, uint8x8_t t); 16588int32x2_t pcmpeqw_s (int32x2_t s, int32x2_t t); 16589int16x4_t pcmpeqh_s (int16x4_t s, int16x4_t t); 16590int8x8_t pcmpeqb_s (int8x8_t s, int8x8_t t); 16591uint32x2_t pcmpgtw_u (uint32x2_t s, uint32x2_t t); 16592uint16x4_t pcmpgth_u (uint16x4_t s, uint16x4_t t); 16593uint8x8_t pcmpgtb_u (uint8x8_t s, uint8x8_t t); 16594int32x2_t pcmpgtw_s (int32x2_t s, int32x2_t t); 16595int16x4_t pcmpgth_s (int16x4_t s, int16x4_t t); 16596int8x8_t pcmpgtb_s (int8x8_t s, int8x8_t t); 16597uint16x4_t pextrh_u (uint16x4_t s, int field); 16598int16x4_t pextrh_s (int16x4_t s, int field); 16599uint16x4_t pinsrh_0_u (uint16x4_t s, uint16x4_t t); 16600uint16x4_t pinsrh_1_u (uint16x4_t s, uint16x4_t t); 16601uint16x4_t pinsrh_2_u (uint16x4_t s, uint16x4_t t); 16602uint16x4_t pinsrh_3_u (uint16x4_t s, uint16x4_t t); 16603int16x4_t pinsrh_0_s (int16x4_t s, int16x4_t t); 16604int16x4_t pinsrh_1_s (int16x4_t s, int16x4_t t); 16605int16x4_t pinsrh_2_s (int16x4_t s, int16x4_t t); 16606int16x4_t pinsrh_3_s (int16x4_t s, int16x4_t t); 16607int32x2_t pmaddhw (int16x4_t s, int16x4_t t); 16608int16x4_t pmaxsh (int16x4_t s, int16x4_t t); 16609uint8x8_t pmaxub (uint8x8_t s, uint8x8_t t); 16610int16x4_t pminsh (int16x4_t s, int16x4_t t); 16611uint8x8_t pminub (uint8x8_t s, uint8x8_t t); 16612uint8x8_t pmovmskb_u (uint8x8_t s); 16613int8x8_t pmovmskb_s (int8x8_t s); 16614uint16x4_t pmulhuh (uint16x4_t s, uint16x4_t t); 16615int16x4_t pmulhh (int16x4_t s, int16x4_t t); 16616int16x4_t pmullh (int16x4_t s, int16x4_t t); 16617int64_t pmuluw (uint32x2_t s, uint32x2_t t); 16618uint8x8_t pasubub (uint8x8_t s, uint8x8_t t); 16619uint16x4_t biadd (uint8x8_t s); 16620uint16x4_t psadbh (uint8x8_t s, uint8x8_t t); 16621uint16x4_t pshufh_u (uint16x4_t dest, uint16x4_t s, uint8_t order); 16622int16x4_t pshufh_s (int16x4_t dest, int16x4_t s, uint8_t order); 16623uint16x4_t psllh_u (uint16x4_t s, uint8_t amount); 16624int16x4_t psllh_s (int16x4_t s, uint8_t amount); 16625uint32x2_t psllw_u (uint32x2_t s, uint8_t amount); 16626int32x2_t psllw_s (int32x2_t s, uint8_t amount); 16627uint16x4_t psrlh_u (uint16x4_t s, uint8_t amount); 16628int16x4_t psrlh_s (int16x4_t s, uint8_t amount); 16629uint32x2_t psrlw_u (uint32x2_t s, uint8_t amount); 16630int32x2_t psrlw_s (int32x2_t s, uint8_t amount); 16631uint16x4_t psrah_u (uint16x4_t s, uint8_t amount); 16632int16x4_t psrah_s (int16x4_t s, uint8_t amount); 16633uint32x2_t psraw_u (uint32x2_t s, uint8_t amount); 16634int32x2_t psraw_s (int32x2_t s, uint8_t amount); 16635uint32x2_t psubw_u (uint32x2_t s, uint32x2_t t); 16636uint16x4_t psubh_u (uint16x4_t s, uint16x4_t t); 16637uint8x8_t psubb_u (uint8x8_t s, uint8x8_t t); 16638int32x2_t psubw_s (int32x2_t s, int32x2_t t); 16639int16x4_t psubh_s (int16x4_t s, int16x4_t t); 16640int8x8_t psubb_s (int8x8_t s, int8x8_t t); 16641uint64_t psubd_u (uint64_t s, uint64_t t); 16642int64_t psubd_s (int64_t s, int64_t t); 16643int16x4_t psubsh (int16x4_t s, int16x4_t t); 16644int8x8_t psubsb (int8x8_t s, int8x8_t t); 16645uint16x4_t psubush (uint16x4_t s, uint16x4_t t); 16646uint8x8_t psubusb (uint8x8_t s, uint8x8_t t); 16647uint32x2_t punpckhwd_u (uint32x2_t s, uint32x2_t t); 16648uint16x4_t punpckhhw_u (uint16x4_t s, uint16x4_t t); 16649uint8x8_t punpckhbh_u (uint8x8_t s, uint8x8_t t); 16650int32x2_t punpckhwd_s (int32x2_t s, int32x2_t t); 16651int16x4_t punpckhhw_s (int16x4_t s, int16x4_t t); 16652int8x8_t punpckhbh_s (int8x8_t s, int8x8_t t); 16653uint32x2_t punpcklwd_u (uint32x2_t s, uint32x2_t t); 16654uint16x4_t punpcklhw_u (uint16x4_t s, uint16x4_t t); 16655uint8x8_t punpcklbh_u (uint8x8_t s, uint8x8_t t); 16656int32x2_t punpcklwd_s (int32x2_t s, int32x2_t t); 16657int16x4_t punpcklhw_s (int16x4_t s, int16x4_t t); 16658int8x8_t punpcklbh_s (int8x8_t s, int8x8_t t); 16659@end smallexample 16660 16661@menu 16662* Paired-Single Arithmetic:: 16663* Paired-Single Built-in Functions:: 16664* MIPS-3D Built-in Functions:: 16665@end menu 16666 16667@node Paired-Single Arithmetic 16668@subsubsection Paired-Single Arithmetic 16669 16670The table below lists the @code{v2sf} operations for which hardware 16671support exists. @code{a}, @code{b} and @code{c} are @code{v2sf} 16672values and @code{x} is an integral value. 16673 16674@multitable @columnfractions .50 .50 16675@headitem C code @tab MIPS instruction 16676@item @code{a + b} @tab @code{add.ps} 16677@item @code{a - b} @tab @code{sub.ps} 16678@item @code{-a} @tab @code{neg.ps} 16679@item @code{a * b} @tab @code{mul.ps} 16680@item @code{a * b + c} @tab @code{madd.ps} 16681@item @code{a * b - c} @tab @code{msub.ps} 16682@item @code{-(a * b + c)} @tab @code{nmadd.ps} 16683@item @code{-(a * b - c)} @tab @code{nmsub.ps} 16684@item @code{x ? a : b} @tab @code{movn.ps}/@code{movz.ps} 16685@end multitable 16686 16687Note that the multiply-accumulate instructions can be disabled 16688using the command-line option @code{-mno-fused-madd}. 16689 16690@node Paired-Single Built-in Functions 16691@subsubsection Paired-Single Built-in Functions 16692 16693The following paired-single functions map directly to a particular 16694MIPS instruction. Please refer to the architecture specification 16695for details on what each instruction does. 16696 16697@table @code 16698@item v2sf __builtin_mips_pll_ps (v2sf, v2sf) 16699Pair lower lower (@code{pll.ps}). 16700 16701@item v2sf __builtin_mips_pul_ps (v2sf, v2sf) 16702Pair upper lower (@code{pul.ps}). 16703 16704@item v2sf __builtin_mips_plu_ps (v2sf, v2sf) 16705Pair lower upper (@code{plu.ps}). 16706 16707@item v2sf __builtin_mips_puu_ps (v2sf, v2sf) 16708Pair upper upper (@code{puu.ps}). 16709 16710@item v2sf __builtin_mips_cvt_ps_s (float, float) 16711Convert pair to paired single (@code{cvt.ps.s}). 16712 16713@item float __builtin_mips_cvt_s_pl (v2sf) 16714Convert pair lower to single (@code{cvt.s.pl}). 16715 16716@item float __builtin_mips_cvt_s_pu (v2sf) 16717Convert pair upper to single (@code{cvt.s.pu}). 16718 16719@item v2sf __builtin_mips_abs_ps (v2sf) 16720Absolute value (@code{abs.ps}). 16721 16722@item v2sf __builtin_mips_alnv_ps (v2sf, v2sf, int) 16723Align variable (@code{alnv.ps}). 16724 16725@emph{Note:} The value of the third parameter must be 0 or 4 16726modulo 8, otherwise the result is unpredictable. Please read the 16727instruction description for details. 16728@end table 16729 16730The following multi-instruction functions are also available. 16731In each case, @var{cond} can be any of the 16 floating-point conditions: 16732@code{f}, @code{un}, @code{eq}, @code{ueq}, @code{olt}, @code{ult}, 16733@code{ole}, @code{ule}, @code{sf}, @code{ngle}, @code{seq}, @code{ngl}, 16734@code{lt}, @code{nge}, @code{le} or @code{ngt}. 16735 16736@table @code 16737@item v2sf __builtin_mips_movt_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d}) 16738@itemx v2sf __builtin_mips_movf_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d}) 16739Conditional move based on floating-point comparison (@code{c.@var{cond}.ps}, 16740@code{movt.ps}/@code{movf.ps}). 16741 16742The @code{movt} functions return the value @var{x} computed by: 16743 16744@smallexample 16745c.@var{cond}.ps @var{cc},@var{a},@var{b} 16746mov.ps @var{x},@var{c} 16747movt.ps @var{x},@var{d},@var{cc} 16748@end smallexample 16749 16750The @code{movf} functions are similar but use @code{movf.ps} instead 16751of @code{movt.ps}. 16752 16753@item int __builtin_mips_upper_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}) 16754@itemx int __builtin_mips_lower_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}) 16755Comparison of two paired-single values (@code{c.@var{cond}.ps}, 16756@code{bc1t}/@code{bc1f}). 16757 16758These functions compare @var{a} and @var{b} using @code{c.@var{cond}.ps} 16759and return either the upper or lower half of the result. For example: 16760 16761@smallexample 16762v2sf a, b; 16763if (__builtin_mips_upper_c_eq_ps (a, b)) 16764 upper_halves_are_equal (); 16765else 16766 upper_halves_are_unequal (); 16767 16768if (__builtin_mips_lower_c_eq_ps (a, b)) 16769 lower_halves_are_equal (); 16770else 16771 lower_halves_are_unequal (); 16772@end smallexample 16773@end table 16774 16775@node MIPS-3D Built-in Functions 16776@subsubsection MIPS-3D Built-in Functions 16777 16778The MIPS-3D Application-Specific Extension (ASE) includes additional 16779paired-single instructions that are designed to improve the performance 16780of 3D graphics operations. Support for these instructions is controlled 16781by the @option{-mips3d} command-line option. 16782 16783The functions listed below map directly to a particular MIPS-3D 16784instruction. Please refer to the architecture specification for 16785more details on what each instruction does. 16786 16787@table @code 16788@item v2sf __builtin_mips_addr_ps (v2sf, v2sf) 16789Reduction add (@code{addr.ps}). 16790 16791@item v2sf __builtin_mips_mulr_ps (v2sf, v2sf) 16792Reduction multiply (@code{mulr.ps}). 16793 16794@item v2sf __builtin_mips_cvt_pw_ps (v2sf) 16795Convert paired single to paired word (@code{cvt.pw.ps}). 16796 16797@item v2sf __builtin_mips_cvt_ps_pw (v2sf) 16798Convert paired word to paired single (@code{cvt.ps.pw}). 16799 16800@item float __builtin_mips_recip1_s (float) 16801@itemx double __builtin_mips_recip1_d (double) 16802@itemx v2sf __builtin_mips_recip1_ps (v2sf) 16803Reduced-precision reciprocal (sequence step 1) (@code{recip1.@var{fmt}}). 16804 16805@item float __builtin_mips_recip2_s (float, float) 16806@itemx double __builtin_mips_recip2_d (double, double) 16807@itemx v2sf __builtin_mips_recip2_ps (v2sf, v2sf) 16808Reduced-precision reciprocal (sequence step 2) (@code{recip2.@var{fmt}}). 16809 16810@item float __builtin_mips_rsqrt1_s (float) 16811@itemx double __builtin_mips_rsqrt1_d (double) 16812@itemx v2sf __builtin_mips_rsqrt1_ps (v2sf) 16813Reduced-precision reciprocal square root (sequence step 1) 16814(@code{rsqrt1.@var{fmt}}). 16815 16816@item float __builtin_mips_rsqrt2_s (float, float) 16817@itemx double __builtin_mips_rsqrt2_d (double, double) 16818@itemx v2sf __builtin_mips_rsqrt2_ps (v2sf, v2sf) 16819Reduced-precision reciprocal square root (sequence step 2) 16820(@code{rsqrt2.@var{fmt}}). 16821@end table 16822 16823The following multi-instruction functions are also available. 16824In each case, @var{cond} can be any of the 16 floating-point conditions: 16825@code{f}, @code{un}, @code{eq}, @code{ueq}, @code{olt}, @code{ult}, 16826@code{ole}, @code{ule}, @code{sf}, @code{ngle}, @code{seq}, 16827@code{ngl}, @code{lt}, @code{nge}, @code{le} or @code{ngt}. 16828 16829@table @code 16830@item int __builtin_mips_cabs_@var{cond}_s (float @var{a}, float @var{b}) 16831@itemx int __builtin_mips_cabs_@var{cond}_d (double @var{a}, double @var{b}) 16832Absolute comparison of two scalar values (@code{cabs.@var{cond}.@var{fmt}}, 16833@code{bc1t}/@code{bc1f}). 16834 16835These functions compare @var{a} and @var{b} using @code{cabs.@var{cond}.s} 16836or @code{cabs.@var{cond}.d} and return the result as a boolean value. 16837For example: 16838 16839@smallexample 16840float a, b; 16841if (__builtin_mips_cabs_eq_s (a, b)) 16842 true (); 16843else 16844 false (); 16845@end smallexample 16846 16847@item int __builtin_mips_upper_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}) 16848@itemx int __builtin_mips_lower_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}) 16849Absolute comparison of two paired-single values (@code{cabs.@var{cond}.ps}, 16850@code{bc1t}/@code{bc1f}). 16851 16852These functions compare @var{a} and @var{b} using @code{cabs.@var{cond}.ps} 16853and return either the upper or lower half of the result. For example: 16854 16855@smallexample 16856v2sf a, b; 16857if (__builtin_mips_upper_cabs_eq_ps (a, b)) 16858 upper_halves_are_equal (); 16859else 16860 upper_halves_are_unequal (); 16861 16862if (__builtin_mips_lower_cabs_eq_ps (a, b)) 16863 lower_halves_are_equal (); 16864else 16865 lower_halves_are_unequal (); 16866@end smallexample 16867 16868@item v2sf __builtin_mips_movt_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d}) 16869@itemx v2sf __builtin_mips_movf_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d}) 16870Conditional move based on absolute comparison (@code{cabs.@var{cond}.ps}, 16871@code{movt.ps}/@code{movf.ps}). 16872 16873The @code{movt} functions return the value @var{x} computed by: 16874 16875@smallexample 16876cabs.@var{cond}.ps @var{cc},@var{a},@var{b} 16877mov.ps @var{x},@var{c} 16878movt.ps @var{x},@var{d},@var{cc} 16879@end smallexample 16880 16881The @code{movf} functions are similar but use @code{movf.ps} instead 16882of @code{movt.ps}. 16883 16884@item int __builtin_mips_any_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}) 16885@itemx int __builtin_mips_all_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}) 16886@itemx int __builtin_mips_any_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}) 16887@itemx int __builtin_mips_all_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}) 16888Comparison of two paired-single values 16889(@code{c.@var{cond}.ps}/@code{cabs.@var{cond}.ps}, 16890@code{bc1any2t}/@code{bc1any2f}). 16891 16892These functions compare @var{a} and @var{b} using @code{c.@var{cond}.ps} 16893or @code{cabs.@var{cond}.ps}. The @code{any} forms return @code{true} if either 16894result is @code{true} and the @code{all} forms return @code{true} if both results are @code{true}. 16895For example: 16896 16897@smallexample 16898v2sf a, b; 16899if (__builtin_mips_any_c_eq_ps (a, b)) 16900 one_is_true (); 16901else 16902 both_are_false (); 16903 16904if (__builtin_mips_all_c_eq_ps (a, b)) 16905 both_are_true (); 16906else 16907 one_is_false (); 16908@end smallexample 16909 16910@item int __builtin_mips_any_c_@var{cond}_4s (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d}) 16911@itemx int __builtin_mips_all_c_@var{cond}_4s (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d}) 16912@itemx int __builtin_mips_any_cabs_@var{cond}_4s (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d}) 16913@itemx int __builtin_mips_all_cabs_@var{cond}_4s (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d}) 16914Comparison of four paired-single values 16915(@code{c.@var{cond}.ps}/@code{cabs.@var{cond}.ps}, 16916@code{bc1any4t}/@code{bc1any4f}). 16917 16918These functions use @code{c.@var{cond}.ps} or @code{cabs.@var{cond}.ps} 16919to compare @var{a} with @var{b} and to compare @var{c} with @var{d}. 16920The @code{any} forms return @code{true} if any of the four results are @code{true} 16921and the @code{all} forms return @code{true} if all four results are @code{true}. 16922For example: 16923 16924@smallexample 16925v2sf a, b, c, d; 16926if (__builtin_mips_any_c_eq_4s (a, b, c, d)) 16927 some_are_true (); 16928else 16929 all_are_false (); 16930 16931if (__builtin_mips_all_c_eq_4s (a, b, c, d)) 16932 all_are_true (); 16933else 16934 some_are_false (); 16935@end smallexample 16936@end table 16937 16938@node MIPS SIMD Architecture (MSA) Support 16939@subsection MIPS SIMD Architecture (MSA) Support 16940 16941@menu 16942* MIPS SIMD Architecture Built-in Functions:: 16943@end menu 16944 16945GCC provides intrinsics to access the SIMD instructions provided by the 16946MSA MIPS SIMD Architecture. The interface is made available by including 16947@code{<msa.h>} and using @option{-mmsa -mhard-float -mfp64 -mnan=2008}. 16948For each @code{__builtin_msa_*}, there is a shortened name of the intrinsic, 16949@code{__msa_*}. 16950 16951MSA implements 128-bit wide vector registers, operating on 8-, 16-, 32- and 1695264-bit integer, 16- and 32-bit fixed-point, or 32- and 64-bit floating point 16953data elements. The following vectors typedefs are included in @code{msa.h}: 16954@itemize 16955@item @code{v16i8}, a vector of sixteen signed 8-bit integers; 16956@item @code{v16u8}, a vector of sixteen unsigned 8-bit integers; 16957@item @code{v8i16}, a vector of eight signed 16-bit integers; 16958@item @code{v8u16}, a vector of eight unsigned 16-bit integers; 16959@item @code{v4i32}, a vector of four signed 32-bit integers; 16960@item @code{v4u32}, a vector of four unsigned 32-bit integers; 16961@item @code{v2i64}, a vector of two signed 64-bit integers; 16962@item @code{v2u64}, a vector of two unsigned 64-bit integers; 16963@item @code{v4f32}, a vector of four 32-bit floats; 16964@item @code{v2f64}, a vector of two 64-bit doubles. 16965@end itemize 16966 16967Instructions and corresponding built-ins may have additional restrictions and/or 16968input/output values manipulated: 16969@itemize 16970@item @code{imm0_1}, an integer literal in range 0 to 1; 16971@item @code{imm0_3}, an integer literal in range 0 to 3; 16972@item @code{imm0_7}, an integer literal in range 0 to 7; 16973@item @code{imm0_15}, an integer literal in range 0 to 15; 16974@item @code{imm0_31}, an integer literal in range 0 to 31; 16975@item @code{imm0_63}, an integer literal in range 0 to 63; 16976@item @code{imm0_255}, an integer literal in range 0 to 255; 16977@item @code{imm_n16_15}, an integer literal in range -16 to 15; 16978@item @code{imm_n512_511}, an integer literal in range -512 to 511; 16979@item @code{imm_n1024_1022}, an integer literal in range -512 to 511 left 16980shifted by 1 bit, i.e., -1024, -1022, @dots{}, 1020, 1022; 16981@item @code{imm_n2048_2044}, an integer literal in range -512 to 511 left 16982shifted by 2 bits, i.e., -2048, -2044, @dots{}, 2040, 2044; 16983@item @code{imm_n4096_4088}, an integer literal in range -512 to 511 left 16984shifted by 3 bits, i.e., -4096, -4088, @dots{}, 4080, 4088; 16985@item @code{imm1_4}, an integer literal in range 1 to 4; 16986@item @code{i32, i64, u32, u64, f32, f64}, defined as follows: 16987@end itemize 16988 16989@smallexample 16990@{ 16991typedef int i32; 16992#if __LONG_MAX__ == __LONG_LONG_MAX__ 16993typedef long i64; 16994#else 16995typedef long long i64; 16996#endif 16997 16998typedef unsigned int u32; 16999#if __LONG_MAX__ == __LONG_LONG_MAX__ 17000typedef unsigned long u64; 17001#else 17002typedef unsigned long long u64; 17003#endif 17004 17005typedef double f64; 17006typedef float f32; 17007@} 17008@end smallexample 17009 17010@node MIPS SIMD Architecture Built-in Functions 17011@subsubsection MIPS SIMD Architecture Built-in Functions 17012 17013The intrinsics provided are listed below; each is named after the 17014machine instruction. 17015 17016@smallexample 17017v16i8 __builtin_msa_add_a_b (v16i8, v16i8); 17018v8i16 __builtin_msa_add_a_h (v8i16, v8i16); 17019v4i32 __builtin_msa_add_a_w (v4i32, v4i32); 17020v2i64 __builtin_msa_add_a_d (v2i64, v2i64); 17021 17022v16i8 __builtin_msa_adds_a_b (v16i8, v16i8); 17023v8i16 __builtin_msa_adds_a_h (v8i16, v8i16); 17024v4i32 __builtin_msa_adds_a_w (v4i32, v4i32); 17025v2i64 __builtin_msa_adds_a_d (v2i64, v2i64); 17026 17027v16i8 __builtin_msa_adds_s_b (v16i8, v16i8); 17028v8i16 __builtin_msa_adds_s_h (v8i16, v8i16); 17029v4i32 __builtin_msa_adds_s_w (v4i32, v4i32); 17030v2i64 __builtin_msa_adds_s_d (v2i64, v2i64); 17031 17032v16u8 __builtin_msa_adds_u_b (v16u8, v16u8); 17033v8u16 __builtin_msa_adds_u_h (v8u16, v8u16); 17034v4u32 __builtin_msa_adds_u_w (v4u32, v4u32); 17035v2u64 __builtin_msa_adds_u_d (v2u64, v2u64); 17036 17037v16i8 __builtin_msa_addv_b (v16i8, v16i8); 17038v8i16 __builtin_msa_addv_h (v8i16, v8i16); 17039v4i32 __builtin_msa_addv_w (v4i32, v4i32); 17040v2i64 __builtin_msa_addv_d (v2i64, v2i64); 17041 17042v16i8 __builtin_msa_addvi_b (v16i8, imm0_31); 17043v8i16 __builtin_msa_addvi_h (v8i16, imm0_31); 17044v4i32 __builtin_msa_addvi_w (v4i32, imm0_31); 17045v2i64 __builtin_msa_addvi_d (v2i64, imm0_31); 17046 17047v16u8 __builtin_msa_and_v (v16u8, v16u8); 17048 17049v16u8 __builtin_msa_andi_b (v16u8, imm0_255); 17050 17051v16i8 __builtin_msa_asub_s_b (v16i8, v16i8); 17052v8i16 __builtin_msa_asub_s_h (v8i16, v8i16); 17053v4i32 __builtin_msa_asub_s_w (v4i32, v4i32); 17054v2i64 __builtin_msa_asub_s_d (v2i64, v2i64); 17055 17056v16u8 __builtin_msa_asub_u_b (v16u8, v16u8); 17057v8u16 __builtin_msa_asub_u_h (v8u16, v8u16); 17058v4u32 __builtin_msa_asub_u_w (v4u32, v4u32); 17059v2u64 __builtin_msa_asub_u_d (v2u64, v2u64); 17060 17061v16i8 __builtin_msa_ave_s_b (v16i8, v16i8); 17062v8i16 __builtin_msa_ave_s_h (v8i16, v8i16); 17063v4i32 __builtin_msa_ave_s_w (v4i32, v4i32); 17064v2i64 __builtin_msa_ave_s_d (v2i64, v2i64); 17065 17066v16u8 __builtin_msa_ave_u_b (v16u8, v16u8); 17067v8u16 __builtin_msa_ave_u_h (v8u16, v8u16); 17068v4u32 __builtin_msa_ave_u_w (v4u32, v4u32); 17069v2u64 __builtin_msa_ave_u_d (v2u64, v2u64); 17070 17071v16i8 __builtin_msa_aver_s_b (v16i8, v16i8); 17072v8i16 __builtin_msa_aver_s_h (v8i16, v8i16); 17073v4i32 __builtin_msa_aver_s_w (v4i32, v4i32); 17074v2i64 __builtin_msa_aver_s_d (v2i64, v2i64); 17075 17076v16u8 __builtin_msa_aver_u_b (v16u8, v16u8); 17077v8u16 __builtin_msa_aver_u_h (v8u16, v8u16); 17078v4u32 __builtin_msa_aver_u_w (v4u32, v4u32); 17079v2u64 __builtin_msa_aver_u_d (v2u64, v2u64); 17080 17081v16u8 __builtin_msa_bclr_b (v16u8, v16u8); 17082v8u16 __builtin_msa_bclr_h (v8u16, v8u16); 17083v4u32 __builtin_msa_bclr_w (v4u32, v4u32); 17084v2u64 __builtin_msa_bclr_d (v2u64, v2u64); 17085 17086v16u8 __builtin_msa_bclri_b (v16u8, imm0_7); 17087v8u16 __builtin_msa_bclri_h (v8u16, imm0_15); 17088v4u32 __builtin_msa_bclri_w (v4u32, imm0_31); 17089v2u64 __builtin_msa_bclri_d (v2u64, imm0_63); 17090 17091v16u8 __builtin_msa_binsl_b (v16u8, v16u8, v16u8); 17092v8u16 __builtin_msa_binsl_h (v8u16, v8u16, v8u16); 17093v4u32 __builtin_msa_binsl_w (v4u32, v4u32, v4u32); 17094v2u64 __builtin_msa_binsl_d (v2u64, v2u64, v2u64); 17095 17096v16u8 __builtin_msa_binsli_b (v16u8, v16u8, imm0_7); 17097v8u16 __builtin_msa_binsli_h (v8u16, v8u16, imm0_15); 17098v4u32 __builtin_msa_binsli_w (v4u32, v4u32, imm0_31); 17099v2u64 __builtin_msa_binsli_d (v2u64, v2u64, imm0_63); 17100 17101v16u8 __builtin_msa_binsr_b (v16u8, v16u8, v16u8); 17102v8u16 __builtin_msa_binsr_h (v8u16, v8u16, v8u16); 17103v4u32 __builtin_msa_binsr_w (v4u32, v4u32, v4u32); 17104v2u64 __builtin_msa_binsr_d (v2u64, v2u64, v2u64); 17105 17106v16u8 __builtin_msa_binsri_b (v16u8, v16u8, imm0_7); 17107v8u16 __builtin_msa_binsri_h (v8u16, v8u16, imm0_15); 17108v4u32 __builtin_msa_binsri_w (v4u32, v4u32, imm0_31); 17109v2u64 __builtin_msa_binsri_d (v2u64, v2u64, imm0_63); 17110 17111v16u8 __builtin_msa_bmnz_v (v16u8, v16u8, v16u8); 17112 17113v16u8 __builtin_msa_bmnzi_b (v16u8, v16u8, imm0_255); 17114 17115v16u8 __builtin_msa_bmz_v (v16u8, v16u8, v16u8); 17116 17117v16u8 __builtin_msa_bmzi_b (v16u8, v16u8, imm0_255); 17118 17119v16u8 __builtin_msa_bneg_b (v16u8, v16u8); 17120v8u16 __builtin_msa_bneg_h (v8u16, v8u16); 17121v4u32 __builtin_msa_bneg_w (v4u32, v4u32); 17122v2u64 __builtin_msa_bneg_d (v2u64, v2u64); 17123 17124v16u8 __builtin_msa_bnegi_b (v16u8, imm0_7); 17125v8u16 __builtin_msa_bnegi_h (v8u16, imm0_15); 17126v4u32 __builtin_msa_bnegi_w (v4u32, imm0_31); 17127v2u64 __builtin_msa_bnegi_d (v2u64, imm0_63); 17128 17129i32 __builtin_msa_bnz_b (v16u8); 17130i32 __builtin_msa_bnz_h (v8u16); 17131i32 __builtin_msa_bnz_w (v4u32); 17132i32 __builtin_msa_bnz_d (v2u64); 17133 17134i32 __builtin_msa_bnz_v (v16u8); 17135 17136v16u8 __builtin_msa_bsel_v (v16u8, v16u8, v16u8); 17137 17138v16u8 __builtin_msa_bseli_b (v16u8, v16u8, imm0_255); 17139 17140v16u8 __builtin_msa_bset_b (v16u8, v16u8); 17141v8u16 __builtin_msa_bset_h (v8u16, v8u16); 17142v4u32 __builtin_msa_bset_w (v4u32, v4u32); 17143v2u64 __builtin_msa_bset_d (v2u64, v2u64); 17144 17145v16u8 __builtin_msa_bseti_b (v16u8, imm0_7); 17146v8u16 __builtin_msa_bseti_h (v8u16, imm0_15); 17147v4u32 __builtin_msa_bseti_w (v4u32, imm0_31); 17148v2u64 __builtin_msa_bseti_d (v2u64, imm0_63); 17149 17150i32 __builtin_msa_bz_b (v16u8); 17151i32 __builtin_msa_bz_h (v8u16); 17152i32 __builtin_msa_bz_w (v4u32); 17153i32 __builtin_msa_bz_d (v2u64); 17154 17155i32 __builtin_msa_bz_v (v16u8); 17156 17157v16i8 __builtin_msa_ceq_b (v16i8, v16i8); 17158v8i16 __builtin_msa_ceq_h (v8i16, v8i16); 17159v4i32 __builtin_msa_ceq_w (v4i32, v4i32); 17160v2i64 __builtin_msa_ceq_d (v2i64, v2i64); 17161 17162v16i8 __builtin_msa_ceqi_b (v16i8, imm_n16_15); 17163v8i16 __builtin_msa_ceqi_h (v8i16, imm_n16_15); 17164v4i32 __builtin_msa_ceqi_w (v4i32, imm_n16_15); 17165v2i64 __builtin_msa_ceqi_d (v2i64, imm_n16_15); 17166 17167i32 __builtin_msa_cfcmsa (imm0_31); 17168 17169v16i8 __builtin_msa_cle_s_b (v16i8, v16i8); 17170v8i16 __builtin_msa_cle_s_h (v8i16, v8i16); 17171v4i32 __builtin_msa_cle_s_w (v4i32, v4i32); 17172v2i64 __builtin_msa_cle_s_d (v2i64, v2i64); 17173 17174v16i8 __builtin_msa_cle_u_b (v16u8, v16u8); 17175v8i16 __builtin_msa_cle_u_h (v8u16, v8u16); 17176v4i32 __builtin_msa_cle_u_w (v4u32, v4u32); 17177v2i64 __builtin_msa_cle_u_d (v2u64, v2u64); 17178 17179v16i8 __builtin_msa_clei_s_b (v16i8, imm_n16_15); 17180v8i16 __builtin_msa_clei_s_h (v8i16, imm_n16_15); 17181v4i32 __builtin_msa_clei_s_w (v4i32, imm_n16_15); 17182v2i64 __builtin_msa_clei_s_d (v2i64, imm_n16_15); 17183 17184v16i8 __builtin_msa_clei_u_b (v16u8, imm0_31); 17185v8i16 __builtin_msa_clei_u_h (v8u16, imm0_31); 17186v4i32 __builtin_msa_clei_u_w (v4u32, imm0_31); 17187v2i64 __builtin_msa_clei_u_d (v2u64, imm0_31); 17188 17189v16i8 __builtin_msa_clt_s_b (v16i8, v16i8); 17190v8i16 __builtin_msa_clt_s_h (v8i16, v8i16); 17191v4i32 __builtin_msa_clt_s_w (v4i32, v4i32); 17192v2i64 __builtin_msa_clt_s_d (v2i64, v2i64); 17193 17194v16i8 __builtin_msa_clt_u_b (v16u8, v16u8); 17195v8i16 __builtin_msa_clt_u_h (v8u16, v8u16); 17196v4i32 __builtin_msa_clt_u_w (v4u32, v4u32); 17197v2i64 __builtin_msa_clt_u_d (v2u64, v2u64); 17198 17199v16i8 __builtin_msa_clti_s_b (v16i8, imm_n16_15); 17200v8i16 __builtin_msa_clti_s_h (v8i16, imm_n16_15); 17201v4i32 __builtin_msa_clti_s_w (v4i32, imm_n16_15); 17202v2i64 __builtin_msa_clti_s_d (v2i64, imm_n16_15); 17203 17204v16i8 __builtin_msa_clti_u_b (v16u8, imm0_31); 17205v8i16 __builtin_msa_clti_u_h (v8u16, imm0_31); 17206v4i32 __builtin_msa_clti_u_w (v4u32, imm0_31); 17207v2i64 __builtin_msa_clti_u_d (v2u64, imm0_31); 17208 17209i32 __builtin_msa_copy_s_b (v16i8, imm0_15); 17210i32 __builtin_msa_copy_s_h (v8i16, imm0_7); 17211i32 __builtin_msa_copy_s_w (v4i32, imm0_3); 17212i64 __builtin_msa_copy_s_d (v2i64, imm0_1); 17213 17214u32 __builtin_msa_copy_u_b (v16i8, imm0_15); 17215u32 __builtin_msa_copy_u_h (v8i16, imm0_7); 17216u32 __builtin_msa_copy_u_w (v4i32, imm0_3); 17217u64 __builtin_msa_copy_u_d (v2i64, imm0_1); 17218 17219void __builtin_msa_ctcmsa (imm0_31, i32); 17220 17221v16i8 __builtin_msa_div_s_b (v16i8, v16i8); 17222v8i16 __builtin_msa_div_s_h (v8i16, v8i16); 17223v4i32 __builtin_msa_div_s_w (v4i32, v4i32); 17224v2i64 __builtin_msa_div_s_d (v2i64, v2i64); 17225 17226v16u8 __builtin_msa_div_u_b (v16u8, v16u8); 17227v8u16 __builtin_msa_div_u_h (v8u16, v8u16); 17228v4u32 __builtin_msa_div_u_w (v4u32, v4u32); 17229v2u64 __builtin_msa_div_u_d (v2u64, v2u64); 17230 17231v8i16 __builtin_msa_dotp_s_h (v16i8, v16i8); 17232v4i32 __builtin_msa_dotp_s_w (v8i16, v8i16); 17233v2i64 __builtin_msa_dotp_s_d (v4i32, v4i32); 17234 17235v8u16 __builtin_msa_dotp_u_h (v16u8, v16u8); 17236v4u32 __builtin_msa_dotp_u_w (v8u16, v8u16); 17237v2u64 __builtin_msa_dotp_u_d (v4u32, v4u32); 17238 17239v8i16 __builtin_msa_dpadd_s_h (v8i16, v16i8, v16i8); 17240v4i32 __builtin_msa_dpadd_s_w (v4i32, v8i16, v8i16); 17241v2i64 __builtin_msa_dpadd_s_d (v2i64, v4i32, v4i32); 17242 17243v8u16 __builtin_msa_dpadd_u_h (v8u16, v16u8, v16u8); 17244v4u32 __builtin_msa_dpadd_u_w (v4u32, v8u16, v8u16); 17245v2u64 __builtin_msa_dpadd_u_d (v2u64, v4u32, v4u32); 17246 17247v8i16 __builtin_msa_dpsub_s_h (v8i16, v16i8, v16i8); 17248v4i32 __builtin_msa_dpsub_s_w (v4i32, v8i16, v8i16); 17249v2i64 __builtin_msa_dpsub_s_d (v2i64, v4i32, v4i32); 17250 17251v8i16 __builtin_msa_dpsub_u_h (v8i16, v16u8, v16u8); 17252v4i32 __builtin_msa_dpsub_u_w (v4i32, v8u16, v8u16); 17253v2i64 __builtin_msa_dpsub_u_d (v2i64, v4u32, v4u32); 17254 17255v4f32 __builtin_msa_fadd_w (v4f32, v4f32); 17256v2f64 __builtin_msa_fadd_d (v2f64, v2f64); 17257 17258v4i32 __builtin_msa_fcaf_w (v4f32, v4f32); 17259v2i64 __builtin_msa_fcaf_d (v2f64, v2f64); 17260 17261v4i32 __builtin_msa_fceq_w (v4f32, v4f32); 17262v2i64 __builtin_msa_fceq_d (v2f64, v2f64); 17263 17264v4i32 __builtin_msa_fclass_w (v4f32); 17265v2i64 __builtin_msa_fclass_d (v2f64); 17266 17267v4i32 __builtin_msa_fcle_w (v4f32, v4f32); 17268v2i64 __builtin_msa_fcle_d (v2f64, v2f64); 17269 17270v4i32 __builtin_msa_fclt_w (v4f32, v4f32); 17271v2i64 __builtin_msa_fclt_d (v2f64, v2f64); 17272 17273v4i32 __builtin_msa_fcne_w (v4f32, v4f32); 17274v2i64 __builtin_msa_fcne_d (v2f64, v2f64); 17275 17276v4i32 __builtin_msa_fcor_w (v4f32, v4f32); 17277v2i64 __builtin_msa_fcor_d (v2f64, v2f64); 17278 17279v4i32 __builtin_msa_fcueq_w (v4f32, v4f32); 17280v2i64 __builtin_msa_fcueq_d (v2f64, v2f64); 17281 17282v4i32 __builtin_msa_fcule_w (v4f32, v4f32); 17283v2i64 __builtin_msa_fcule_d (v2f64, v2f64); 17284 17285v4i32 __builtin_msa_fcult_w (v4f32, v4f32); 17286v2i64 __builtin_msa_fcult_d (v2f64, v2f64); 17287 17288v4i32 __builtin_msa_fcun_w (v4f32, v4f32); 17289v2i64 __builtin_msa_fcun_d (v2f64, v2f64); 17290 17291v4i32 __builtin_msa_fcune_w (v4f32, v4f32); 17292v2i64 __builtin_msa_fcune_d (v2f64, v2f64); 17293 17294v4f32 __builtin_msa_fdiv_w (v4f32, v4f32); 17295v2f64 __builtin_msa_fdiv_d (v2f64, v2f64); 17296 17297v8i16 __builtin_msa_fexdo_h (v4f32, v4f32); 17298v4f32 __builtin_msa_fexdo_w (v2f64, v2f64); 17299 17300v4f32 __builtin_msa_fexp2_w (v4f32, v4i32); 17301v2f64 __builtin_msa_fexp2_d (v2f64, v2i64); 17302 17303v4f32 __builtin_msa_fexupl_w (v8i16); 17304v2f64 __builtin_msa_fexupl_d (v4f32); 17305 17306v4f32 __builtin_msa_fexupr_w (v8i16); 17307v2f64 __builtin_msa_fexupr_d (v4f32); 17308 17309v4f32 __builtin_msa_ffint_s_w (v4i32); 17310v2f64 __builtin_msa_ffint_s_d (v2i64); 17311 17312v4f32 __builtin_msa_ffint_u_w (v4u32); 17313v2f64 __builtin_msa_ffint_u_d (v2u64); 17314 17315v4f32 __builtin_msa_ffql_w (v8i16); 17316v2f64 __builtin_msa_ffql_d (v4i32); 17317 17318v4f32 __builtin_msa_ffqr_w (v8i16); 17319v2f64 __builtin_msa_ffqr_d (v4i32); 17320 17321v16i8 __builtin_msa_fill_b (i32); 17322v8i16 __builtin_msa_fill_h (i32); 17323v4i32 __builtin_msa_fill_w (i32); 17324v2i64 __builtin_msa_fill_d (i64); 17325 17326v4f32 __builtin_msa_flog2_w (v4f32); 17327v2f64 __builtin_msa_flog2_d (v2f64); 17328 17329v4f32 __builtin_msa_fmadd_w (v4f32, v4f32, v4f32); 17330v2f64 __builtin_msa_fmadd_d (v2f64, v2f64, v2f64); 17331 17332v4f32 __builtin_msa_fmax_w (v4f32, v4f32); 17333v2f64 __builtin_msa_fmax_d (v2f64, v2f64); 17334 17335v4f32 __builtin_msa_fmax_a_w (v4f32, v4f32); 17336v2f64 __builtin_msa_fmax_a_d (v2f64, v2f64); 17337 17338v4f32 __builtin_msa_fmin_w (v4f32, v4f32); 17339v2f64 __builtin_msa_fmin_d (v2f64, v2f64); 17340 17341v4f32 __builtin_msa_fmin_a_w (v4f32, v4f32); 17342v2f64 __builtin_msa_fmin_a_d (v2f64, v2f64); 17343 17344v4f32 __builtin_msa_fmsub_w (v4f32, v4f32, v4f32); 17345v2f64 __builtin_msa_fmsub_d (v2f64, v2f64, v2f64); 17346 17347v4f32 __builtin_msa_fmul_w (v4f32, v4f32); 17348v2f64 __builtin_msa_fmul_d (v2f64, v2f64); 17349 17350v4f32 __builtin_msa_frint_w (v4f32); 17351v2f64 __builtin_msa_frint_d (v2f64); 17352 17353v4f32 __builtin_msa_frcp_w (v4f32); 17354v2f64 __builtin_msa_frcp_d (v2f64); 17355 17356v4f32 __builtin_msa_frsqrt_w (v4f32); 17357v2f64 __builtin_msa_frsqrt_d (v2f64); 17358 17359v4i32 __builtin_msa_fsaf_w (v4f32, v4f32); 17360v2i64 __builtin_msa_fsaf_d (v2f64, v2f64); 17361 17362v4i32 __builtin_msa_fseq_w (v4f32, v4f32); 17363v2i64 __builtin_msa_fseq_d (v2f64, v2f64); 17364 17365v4i32 __builtin_msa_fsle_w (v4f32, v4f32); 17366v2i64 __builtin_msa_fsle_d (v2f64, v2f64); 17367 17368v4i32 __builtin_msa_fslt_w (v4f32, v4f32); 17369v2i64 __builtin_msa_fslt_d (v2f64, v2f64); 17370 17371v4i32 __builtin_msa_fsne_w (v4f32, v4f32); 17372v2i64 __builtin_msa_fsne_d (v2f64, v2f64); 17373 17374v4i32 __builtin_msa_fsor_w (v4f32, v4f32); 17375v2i64 __builtin_msa_fsor_d (v2f64, v2f64); 17376 17377v4f32 __builtin_msa_fsqrt_w (v4f32); 17378v2f64 __builtin_msa_fsqrt_d (v2f64); 17379 17380v4f32 __builtin_msa_fsub_w (v4f32, v4f32); 17381v2f64 __builtin_msa_fsub_d (v2f64, v2f64); 17382 17383v4i32 __builtin_msa_fsueq_w (v4f32, v4f32); 17384v2i64 __builtin_msa_fsueq_d (v2f64, v2f64); 17385 17386v4i32 __builtin_msa_fsule_w (v4f32, v4f32); 17387v2i64 __builtin_msa_fsule_d (v2f64, v2f64); 17388 17389v4i32 __builtin_msa_fsult_w (v4f32, v4f32); 17390v2i64 __builtin_msa_fsult_d (v2f64, v2f64); 17391 17392v4i32 __builtin_msa_fsun_w (v4f32, v4f32); 17393v2i64 __builtin_msa_fsun_d (v2f64, v2f64); 17394 17395v4i32 __builtin_msa_fsune_w (v4f32, v4f32); 17396v2i64 __builtin_msa_fsune_d (v2f64, v2f64); 17397 17398v4i32 __builtin_msa_ftint_s_w (v4f32); 17399v2i64 __builtin_msa_ftint_s_d (v2f64); 17400 17401v4u32 __builtin_msa_ftint_u_w (v4f32); 17402v2u64 __builtin_msa_ftint_u_d (v2f64); 17403 17404v8i16 __builtin_msa_ftq_h (v4f32, v4f32); 17405v4i32 __builtin_msa_ftq_w (v2f64, v2f64); 17406 17407v4i32 __builtin_msa_ftrunc_s_w (v4f32); 17408v2i64 __builtin_msa_ftrunc_s_d (v2f64); 17409 17410v4u32 __builtin_msa_ftrunc_u_w (v4f32); 17411v2u64 __builtin_msa_ftrunc_u_d (v2f64); 17412 17413v8i16 __builtin_msa_hadd_s_h (v16i8, v16i8); 17414v4i32 __builtin_msa_hadd_s_w (v8i16, v8i16); 17415v2i64 __builtin_msa_hadd_s_d (v4i32, v4i32); 17416 17417v8u16 __builtin_msa_hadd_u_h (v16u8, v16u8); 17418v4u32 __builtin_msa_hadd_u_w (v8u16, v8u16); 17419v2u64 __builtin_msa_hadd_u_d (v4u32, v4u32); 17420 17421v8i16 __builtin_msa_hsub_s_h (v16i8, v16i8); 17422v4i32 __builtin_msa_hsub_s_w (v8i16, v8i16); 17423v2i64 __builtin_msa_hsub_s_d (v4i32, v4i32); 17424 17425v8i16 __builtin_msa_hsub_u_h (v16u8, v16u8); 17426v4i32 __builtin_msa_hsub_u_w (v8u16, v8u16); 17427v2i64 __builtin_msa_hsub_u_d (v4u32, v4u32); 17428 17429v16i8 __builtin_msa_ilvev_b (v16i8, v16i8); 17430v8i16 __builtin_msa_ilvev_h (v8i16, v8i16); 17431v4i32 __builtin_msa_ilvev_w (v4i32, v4i32); 17432v2i64 __builtin_msa_ilvev_d (v2i64, v2i64); 17433 17434v16i8 __builtin_msa_ilvl_b (v16i8, v16i8); 17435v8i16 __builtin_msa_ilvl_h (v8i16, v8i16); 17436v4i32 __builtin_msa_ilvl_w (v4i32, v4i32); 17437v2i64 __builtin_msa_ilvl_d (v2i64, v2i64); 17438 17439v16i8 __builtin_msa_ilvod_b (v16i8, v16i8); 17440v8i16 __builtin_msa_ilvod_h (v8i16, v8i16); 17441v4i32 __builtin_msa_ilvod_w (v4i32, v4i32); 17442v2i64 __builtin_msa_ilvod_d (v2i64, v2i64); 17443 17444v16i8 __builtin_msa_ilvr_b (v16i8, v16i8); 17445v8i16 __builtin_msa_ilvr_h (v8i16, v8i16); 17446v4i32 __builtin_msa_ilvr_w (v4i32, v4i32); 17447v2i64 __builtin_msa_ilvr_d (v2i64, v2i64); 17448 17449v16i8 __builtin_msa_insert_b (v16i8, imm0_15, i32); 17450v8i16 __builtin_msa_insert_h (v8i16, imm0_7, i32); 17451v4i32 __builtin_msa_insert_w (v4i32, imm0_3, i32); 17452v2i64 __builtin_msa_insert_d (v2i64, imm0_1, i64); 17453 17454v16i8 __builtin_msa_insve_b (v16i8, imm0_15, v16i8); 17455v8i16 __builtin_msa_insve_h (v8i16, imm0_7, v8i16); 17456v4i32 __builtin_msa_insve_w (v4i32, imm0_3, v4i32); 17457v2i64 __builtin_msa_insve_d (v2i64, imm0_1, v2i64); 17458 17459v16i8 __builtin_msa_ld_b (const void *, imm_n512_511); 17460v8i16 __builtin_msa_ld_h (const void *, imm_n1024_1022); 17461v4i32 __builtin_msa_ld_w (const void *, imm_n2048_2044); 17462v2i64 __builtin_msa_ld_d (const void *, imm_n4096_4088); 17463 17464v16i8 __builtin_msa_ldi_b (imm_n512_511); 17465v8i16 __builtin_msa_ldi_h (imm_n512_511); 17466v4i32 __builtin_msa_ldi_w (imm_n512_511); 17467v2i64 __builtin_msa_ldi_d (imm_n512_511); 17468 17469v8i16 __builtin_msa_madd_q_h (v8i16, v8i16, v8i16); 17470v4i32 __builtin_msa_madd_q_w (v4i32, v4i32, v4i32); 17471 17472v8i16 __builtin_msa_maddr_q_h (v8i16, v8i16, v8i16); 17473v4i32 __builtin_msa_maddr_q_w (v4i32, v4i32, v4i32); 17474 17475v16i8 __builtin_msa_maddv_b (v16i8, v16i8, v16i8); 17476v8i16 __builtin_msa_maddv_h (v8i16, v8i16, v8i16); 17477v4i32 __builtin_msa_maddv_w (v4i32, v4i32, v4i32); 17478v2i64 __builtin_msa_maddv_d (v2i64, v2i64, v2i64); 17479 17480v16i8 __builtin_msa_max_a_b (v16i8, v16i8); 17481v8i16 __builtin_msa_max_a_h (v8i16, v8i16); 17482v4i32 __builtin_msa_max_a_w (v4i32, v4i32); 17483v2i64 __builtin_msa_max_a_d (v2i64, v2i64); 17484 17485v16i8 __builtin_msa_max_s_b (v16i8, v16i8); 17486v8i16 __builtin_msa_max_s_h (v8i16, v8i16); 17487v4i32 __builtin_msa_max_s_w (v4i32, v4i32); 17488v2i64 __builtin_msa_max_s_d (v2i64, v2i64); 17489 17490v16u8 __builtin_msa_max_u_b (v16u8, v16u8); 17491v8u16 __builtin_msa_max_u_h (v8u16, v8u16); 17492v4u32 __builtin_msa_max_u_w (v4u32, v4u32); 17493v2u64 __builtin_msa_max_u_d (v2u64, v2u64); 17494 17495v16i8 __builtin_msa_maxi_s_b (v16i8, imm_n16_15); 17496v8i16 __builtin_msa_maxi_s_h (v8i16, imm_n16_15); 17497v4i32 __builtin_msa_maxi_s_w (v4i32, imm_n16_15); 17498v2i64 __builtin_msa_maxi_s_d (v2i64, imm_n16_15); 17499 17500v16u8 __builtin_msa_maxi_u_b (v16u8, imm0_31); 17501v8u16 __builtin_msa_maxi_u_h (v8u16, imm0_31); 17502v4u32 __builtin_msa_maxi_u_w (v4u32, imm0_31); 17503v2u64 __builtin_msa_maxi_u_d (v2u64, imm0_31); 17504 17505v16i8 __builtin_msa_min_a_b (v16i8, v16i8); 17506v8i16 __builtin_msa_min_a_h (v8i16, v8i16); 17507v4i32 __builtin_msa_min_a_w (v4i32, v4i32); 17508v2i64 __builtin_msa_min_a_d (v2i64, v2i64); 17509 17510v16i8 __builtin_msa_min_s_b (v16i8, v16i8); 17511v8i16 __builtin_msa_min_s_h (v8i16, v8i16); 17512v4i32 __builtin_msa_min_s_w (v4i32, v4i32); 17513v2i64 __builtin_msa_min_s_d (v2i64, v2i64); 17514 17515v16u8 __builtin_msa_min_u_b (v16u8, v16u8); 17516v8u16 __builtin_msa_min_u_h (v8u16, v8u16); 17517v4u32 __builtin_msa_min_u_w (v4u32, v4u32); 17518v2u64 __builtin_msa_min_u_d (v2u64, v2u64); 17519 17520v16i8 __builtin_msa_mini_s_b (v16i8, imm_n16_15); 17521v8i16 __builtin_msa_mini_s_h (v8i16, imm_n16_15); 17522v4i32 __builtin_msa_mini_s_w (v4i32, imm_n16_15); 17523v2i64 __builtin_msa_mini_s_d (v2i64, imm_n16_15); 17524 17525v16u8 __builtin_msa_mini_u_b (v16u8, imm0_31); 17526v8u16 __builtin_msa_mini_u_h (v8u16, imm0_31); 17527v4u32 __builtin_msa_mini_u_w (v4u32, imm0_31); 17528v2u64 __builtin_msa_mini_u_d (v2u64, imm0_31); 17529 17530v16i8 __builtin_msa_mod_s_b (v16i8, v16i8); 17531v8i16 __builtin_msa_mod_s_h (v8i16, v8i16); 17532v4i32 __builtin_msa_mod_s_w (v4i32, v4i32); 17533v2i64 __builtin_msa_mod_s_d (v2i64, v2i64); 17534 17535v16u8 __builtin_msa_mod_u_b (v16u8, v16u8); 17536v8u16 __builtin_msa_mod_u_h (v8u16, v8u16); 17537v4u32 __builtin_msa_mod_u_w (v4u32, v4u32); 17538v2u64 __builtin_msa_mod_u_d (v2u64, v2u64); 17539 17540v16i8 __builtin_msa_move_v (v16i8); 17541 17542v8i16 __builtin_msa_msub_q_h (v8i16, v8i16, v8i16); 17543v4i32 __builtin_msa_msub_q_w (v4i32, v4i32, v4i32); 17544 17545v8i16 __builtin_msa_msubr_q_h (v8i16, v8i16, v8i16); 17546v4i32 __builtin_msa_msubr_q_w (v4i32, v4i32, v4i32); 17547 17548v16i8 __builtin_msa_msubv_b (v16i8, v16i8, v16i8); 17549v8i16 __builtin_msa_msubv_h (v8i16, v8i16, v8i16); 17550v4i32 __builtin_msa_msubv_w (v4i32, v4i32, v4i32); 17551v2i64 __builtin_msa_msubv_d (v2i64, v2i64, v2i64); 17552 17553v8i16 __builtin_msa_mul_q_h (v8i16, v8i16); 17554v4i32 __builtin_msa_mul_q_w (v4i32, v4i32); 17555 17556v8i16 __builtin_msa_mulr_q_h (v8i16, v8i16); 17557v4i32 __builtin_msa_mulr_q_w (v4i32, v4i32); 17558 17559v16i8 __builtin_msa_mulv_b (v16i8, v16i8); 17560v8i16 __builtin_msa_mulv_h (v8i16, v8i16); 17561v4i32 __builtin_msa_mulv_w (v4i32, v4i32); 17562v2i64 __builtin_msa_mulv_d (v2i64, v2i64); 17563 17564v16i8 __builtin_msa_nloc_b (v16i8); 17565v8i16 __builtin_msa_nloc_h (v8i16); 17566v4i32 __builtin_msa_nloc_w (v4i32); 17567v2i64 __builtin_msa_nloc_d (v2i64); 17568 17569v16i8 __builtin_msa_nlzc_b (v16i8); 17570v8i16 __builtin_msa_nlzc_h (v8i16); 17571v4i32 __builtin_msa_nlzc_w (v4i32); 17572v2i64 __builtin_msa_nlzc_d (v2i64); 17573 17574v16u8 __builtin_msa_nor_v (v16u8, v16u8); 17575 17576v16u8 __builtin_msa_nori_b (v16u8, imm0_255); 17577 17578v16u8 __builtin_msa_or_v (v16u8, v16u8); 17579 17580v16u8 __builtin_msa_ori_b (v16u8, imm0_255); 17581 17582v16i8 __builtin_msa_pckev_b (v16i8, v16i8); 17583v8i16 __builtin_msa_pckev_h (v8i16, v8i16); 17584v4i32 __builtin_msa_pckev_w (v4i32, v4i32); 17585v2i64 __builtin_msa_pckev_d (v2i64, v2i64); 17586 17587v16i8 __builtin_msa_pckod_b (v16i8, v16i8); 17588v8i16 __builtin_msa_pckod_h (v8i16, v8i16); 17589v4i32 __builtin_msa_pckod_w (v4i32, v4i32); 17590v2i64 __builtin_msa_pckod_d (v2i64, v2i64); 17591 17592v16i8 __builtin_msa_pcnt_b (v16i8); 17593v8i16 __builtin_msa_pcnt_h (v8i16); 17594v4i32 __builtin_msa_pcnt_w (v4i32); 17595v2i64 __builtin_msa_pcnt_d (v2i64); 17596 17597v16i8 __builtin_msa_sat_s_b (v16i8, imm0_7); 17598v8i16 __builtin_msa_sat_s_h (v8i16, imm0_15); 17599v4i32 __builtin_msa_sat_s_w (v4i32, imm0_31); 17600v2i64 __builtin_msa_sat_s_d (v2i64, imm0_63); 17601 17602v16u8 __builtin_msa_sat_u_b (v16u8, imm0_7); 17603v8u16 __builtin_msa_sat_u_h (v8u16, imm0_15); 17604v4u32 __builtin_msa_sat_u_w (v4u32, imm0_31); 17605v2u64 __builtin_msa_sat_u_d (v2u64, imm0_63); 17606 17607v16i8 __builtin_msa_shf_b (v16i8, imm0_255); 17608v8i16 __builtin_msa_shf_h (v8i16, imm0_255); 17609v4i32 __builtin_msa_shf_w (v4i32, imm0_255); 17610 17611v16i8 __builtin_msa_sld_b (v16i8, v16i8, i32); 17612v8i16 __builtin_msa_sld_h (v8i16, v8i16, i32); 17613v4i32 __builtin_msa_sld_w (v4i32, v4i32, i32); 17614v2i64 __builtin_msa_sld_d (v2i64, v2i64, i32); 17615 17616v16i8 __builtin_msa_sldi_b (v16i8, v16i8, imm0_15); 17617v8i16 __builtin_msa_sldi_h (v8i16, v8i16, imm0_7); 17618v4i32 __builtin_msa_sldi_w (v4i32, v4i32, imm0_3); 17619v2i64 __builtin_msa_sldi_d (v2i64, v2i64, imm0_1); 17620 17621v16i8 __builtin_msa_sll_b (v16i8, v16i8); 17622v8i16 __builtin_msa_sll_h (v8i16, v8i16); 17623v4i32 __builtin_msa_sll_w (v4i32, v4i32); 17624v2i64 __builtin_msa_sll_d (v2i64, v2i64); 17625 17626v16i8 __builtin_msa_slli_b (v16i8, imm0_7); 17627v8i16 __builtin_msa_slli_h (v8i16, imm0_15); 17628v4i32 __builtin_msa_slli_w (v4i32, imm0_31); 17629v2i64 __builtin_msa_slli_d (v2i64, imm0_63); 17630 17631v16i8 __builtin_msa_splat_b (v16i8, i32); 17632v8i16 __builtin_msa_splat_h (v8i16, i32); 17633v4i32 __builtin_msa_splat_w (v4i32, i32); 17634v2i64 __builtin_msa_splat_d (v2i64, i32); 17635 17636v16i8 __builtin_msa_splati_b (v16i8, imm0_15); 17637v8i16 __builtin_msa_splati_h (v8i16, imm0_7); 17638v4i32 __builtin_msa_splati_w (v4i32, imm0_3); 17639v2i64 __builtin_msa_splati_d (v2i64, imm0_1); 17640 17641v16i8 __builtin_msa_sra_b (v16i8, v16i8); 17642v8i16 __builtin_msa_sra_h (v8i16, v8i16); 17643v4i32 __builtin_msa_sra_w (v4i32, v4i32); 17644v2i64 __builtin_msa_sra_d (v2i64, v2i64); 17645 17646v16i8 __builtin_msa_srai_b (v16i8, imm0_7); 17647v8i16 __builtin_msa_srai_h (v8i16, imm0_15); 17648v4i32 __builtin_msa_srai_w (v4i32, imm0_31); 17649v2i64 __builtin_msa_srai_d (v2i64, imm0_63); 17650 17651v16i8 __builtin_msa_srar_b (v16i8, v16i8); 17652v8i16 __builtin_msa_srar_h (v8i16, v8i16); 17653v4i32 __builtin_msa_srar_w (v4i32, v4i32); 17654v2i64 __builtin_msa_srar_d (v2i64, v2i64); 17655 17656v16i8 __builtin_msa_srari_b (v16i8, imm0_7); 17657v8i16 __builtin_msa_srari_h (v8i16, imm0_15); 17658v4i32 __builtin_msa_srari_w (v4i32, imm0_31); 17659v2i64 __builtin_msa_srari_d (v2i64, imm0_63); 17660 17661v16i8 __builtin_msa_srl_b (v16i8, v16i8); 17662v8i16 __builtin_msa_srl_h (v8i16, v8i16); 17663v4i32 __builtin_msa_srl_w (v4i32, v4i32); 17664v2i64 __builtin_msa_srl_d (v2i64, v2i64); 17665 17666v16i8 __builtin_msa_srli_b (v16i8, imm0_7); 17667v8i16 __builtin_msa_srli_h (v8i16, imm0_15); 17668v4i32 __builtin_msa_srli_w (v4i32, imm0_31); 17669v2i64 __builtin_msa_srli_d (v2i64, imm0_63); 17670 17671v16i8 __builtin_msa_srlr_b (v16i8, v16i8); 17672v8i16 __builtin_msa_srlr_h (v8i16, v8i16); 17673v4i32 __builtin_msa_srlr_w (v4i32, v4i32); 17674v2i64 __builtin_msa_srlr_d (v2i64, v2i64); 17675 17676v16i8 __builtin_msa_srlri_b (v16i8, imm0_7); 17677v8i16 __builtin_msa_srlri_h (v8i16, imm0_15); 17678v4i32 __builtin_msa_srlri_w (v4i32, imm0_31); 17679v2i64 __builtin_msa_srlri_d (v2i64, imm0_63); 17680 17681void __builtin_msa_st_b (v16i8, void *, imm_n512_511); 17682void __builtin_msa_st_h (v8i16, void *, imm_n1024_1022); 17683void __builtin_msa_st_w (v4i32, void *, imm_n2048_2044); 17684void __builtin_msa_st_d (v2i64, void *, imm_n4096_4088); 17685 17686v16i8 __builtin_msa_subs_s_b (v16i8, v16i8); 17687v8i16 __builtin_msa_subs_s_h (v8i16, v8i16); 17688v4i32 __builtin_msa_subs_s_w (v4i32, v4i32); 17689v2i64 __builtin_msa_subs_s_d (v2i64, v2i64); 17690 17691v16u8 __builtin_msa_subs_u_b (v16u8, v16u8); 17692v8u16 __builtin_msa_subs_u_h (v8u16, v8u16); 17693v4u32 __builtin_msa_subs_u_w (v4u32, v4u32); 17694v2u64 __builtin_msa_subs_u_d (v2u64, v2u64); 17695 17696v16u8 __builtin_msa_subsus_u_b (v16u8, v16i8); 17697v8u16 __builtin_msa_subsus_u_h (v8u16, v8i16); 17698v4u32 __builtin_msa_subsus_u_w (v4u32, v4i32); 17699v2u64 __builtin_msa_subsus_u_d (v2u64, v2i64); 17700 17701v16i8 __builtin_msa_subsuu_s_b (v16u8, v16u8); 17702v8i16 __builtin_msa_subsuu_s_h (v8u16, v8u16); 17703v4i32 __builtin_msa_subsuu_s_w (v4u32, v4u32); 17704v2i64 __builtin_msa_subsuu_s_d (v2u64, v2u64); 17705 17706v16i8 __builtin_msa_subv_b (v16i8, v16i8); 17707v8i16 __builtin_msa_subv_h (v8i16, v8i16); 17708v4i32 __builtin_msa_subv_w (v4i32, v4i32); 17709v2i64 __builtin_msa_subv_d (v2i64, v2i64); 17710 17711v16i8 __builtin_msa_subvi_b (v16i8, imm0_31); 17712v8i16 __builtin_msa_subvi_h (v8i16, imm0_31); 17713v4i32 __builtin_msa_subvi_w (v4i32, imm0_31); 17714v2i64 __builtin_msa_subvi_d (v2i64, imm0_31); 17715 17716v16i8 __builtin_msa_vshf_b (v16i8, v16i8, v16i8); 17717v8i16 __builtin_msa_vshf_h (v8i16, v8i16, v8i16); 17718v4i32 __builtin_msa_vshf_w (v4i32, v4i32, v4i32); 17719v2i64 __builtin_msa_vshf_d (v2i64, v2i64, v2i64); 17720 17721v16u8 __builtin_msa_xor_v (v16u8, v16u8); 17722 17723v16u8 __builtin_msa_xori_b (v16u8, imm0_255); 17724@end smallexample 17725 17726@node Other MIPS Built-in Functions 17727@subsection Other MIPS Built-in Functions 17728 17729GCC provides other MIPS-specific built-in functions: 17730 17731@table @code 17732@item void __builtin_mips_cache (int @var{op}, const volatile void *@var{addr}) 17733Insert a @samp{cache} instruction with operands @var{op} and @var{addr}. 17734GCC defines the preprocessor macro @code{___GCC_HAVE_BUILTIN_MIPS_CACHE} 17735when this function is available. 17736 17737@item unsigned int __builtin_mips_get_fcsr (void) 17738@itemx void __builtin_mips_set_fcsr (unsigned int @var{value}) 17739Get and set the contents of the floating-point control and status register 17740(FPU control register 31). These functions are only available in hard-float 17741code but can be called in both MIPS16 and non-MIPS16 contexts. 17742 17743@code{__builtin_mips_set_fcsr} can be used to change any bit of the 17744register except the condition codes, which GCC assumes are preserved. 17745@end table 17746 17747@node MSP430 Built-in Functions 17748@subsection MSP430 Built-in Functions 17749 17750GCC provides a couple of special builtin functions to aid in the 17751writing of interrupt handlers in C. 17752 17753@table @code 17754@item __bic_SR_register_on_exit (int @var{mask}) 17755This clears the indicated bits in the saved copy of the status register 17756currently residing on the stack. This only works inside interrupt 17757handlers and the changes to the status register will only take affect 17758once the handler returns. 17759 17760@item __bis_SR_register_on_exit (int @var{mask}) 17761This sets the indicated bits in the saved copy of the status register 17762currently residing on the stack. This only works inside interrupt 17763handlers and the changes to the status register will only take affect 17764once the handler returns. 17765 17766@item __delay_cycles (long long @var{cycles}) 17767This inserts an instruction sequence that takes exactly @var{cycles} 17768cycles (between 0 and about 17E9) to complete. The inserted sequence 17769may use jumps, loops, or no-ops, and does not interfere with any other 17770instructions. Note that @var{cycles} must be a compile-time constant 17771integer - that is, you must pass a number, not a variable that may be 17772optimized to a constant later. The number of cycles delayed by this 17773builtin is exact. 17774@end table 17775 17776@node NDS32 Built-in Functions 17777@subsection NDS32 Built-in Functions 17778 17779These built-in functions are available for the NDS32 target: 17780 17781@deftypefn {Built-in Function} void __builtin_nds32_isync (int *@var{addr}) 17782Insert an ISYNC instruction into the instruction stream where 17783@var{addr} is an instruction address for serialization. 17784@end deftypefn 17785 17786@deftypefn {Built-in Function} void __builtin_nds32_isb (void) 17787Insert an ISB instruction into the instruction stream. 17788@end deftypefn 17789 17790@deftypefn {Built-in Function} int __builtin_nds32_mfsr (int @var{sr}) 17791Return the content of a system register which is mapped by @var{sr}. 17792@end deftypefn 17793 17794@deftypefn {Built-in Function} int __builtin_nds32_mfusr (int @var{usr}) 17795Return the content of a user space register which is mapped by @var{usr}. 17796@end deftypefn 17797 17798@deftypefn {Built-in Function} void __builtin_nds32_mtsr (int @var{value}, int @var{sr}) 17799Move the @var{value} to a system register which is mapped by @var{sr}. 17800@end deftypefn 17801 17802@deftypefn {Built-in Function} void __builtin_nds32_mtusr (int @var{value}, int @var{usr}) 17803Move the @var{value} to a user space register which is mapped by @var{usr}. 17804@end deftypefn 17805 17806@deftypefn {Built-in Function} void __builtin_nds32_setgie_en (void) 17807Enable global interrupt. 17808@end deftypefn 17809 17810@deftypefn {Built-in Function} void __builtin_nds32_setgie_dis (void) 17811Disable global interrupt. 17812@end deftypefn 17813 17814@node picoChip Built-in Functions 17815@subsection picoChip Built-in Functions 17816 17817GCC provides an interface to selected machine instructions from the 17818picoChip instruction set. 17819 17820@table @code 17821@item int __builtin_sbc (int @var{value}) 17822Sign bit count. Return the number of consecutive bits in @var{value} 17823that have the same value as the sign bit. The result is the number of 17824leading sign bits minus one, giving the number of redundant sign bits in 17825@var{value}. 17826 17827@item int __builtin_byteswap (int @var{value}) 17828Byte swap. Return the result of swapping the upper and lower bytes of 17829@var{value}. 17830 17831@item int __builtin_brev (int @var{value}) 17832Bit reversal. Return the result of reversing the bits in 17833@var{value}. Bit 15 is swapped with bit 0, bit 14 is swapped with bit 1, 17834and so on. 17835 17836@item int __builtin_adds (int @var{x}, int @var{y}) 17837Saturating addition. Return the result of adding @var{x} and @var{y}, 17838storing the value 32767 if the result overflows. 17839 17840@item int __builtin_subs (int @var{x}, int @var{y}) 17841Saturating subtraction. Return the result of subtracting @var{y} from 17842@var{x}, storing the value @minus{}32768 if the result overflows. 17843 17844@item void __builtin_halt (void) 17845Halt. The processor stops execution. This built-in is useful for 17846implementing assertions. 17847 17848@end table 17849 17850@node Basic PowerPC Built-in Functions 17851@subsection Basic PowerPC Built-in Functions 17852 17853@menu 17854* Basic PowerPC Built-in Functions Available on all Configurations:: 17855* Basic PowerPC Built-in Functions Available on ISA 2.05:: 17856* Basic PowerPC Built-in Functions Available on ISA 2.06:: 17857* Basic PowerPC Built-in Functions Available on ISA 2.07:: 17858* Basic PowerPC Built-in Functions Available on ISA 3.0:: 17859* Basic PowerPC Built-in Functions Available on ISA 3.1:: 17860@end menu 17861 17862This section describes PowerPC built-in functions that do not require 17863the inclusion of any special header files to declare prototypes or 17864provide macro definitions. The sections that follow describe 17865additional PowerPC built-in functions. 17866 17867@node Basic PowerPC Built-in Functions Available on all Configurations 17868@subsubsection Basic PowerPC Built-in Functions Available on all Configurations 17869 17870@deftypefn {Built-in Function} void __builtin_cpu_init (void) 17871This function is a @code{nop} on the PowerPC platform and is included solely 17872to maintain API compatibility with the x86 builtins. 17873@end deftypefn 17874 17875@deftypefn {Built-in Function} int __builtin_cpu_is (const char *@var{cpuname}) 17876This function returns a value of @code{1} if the run-time CPU is of type 17877@var{cpuname} and returns @code{0} otherwise 17878 17879The @code{__builtin_cpu_is} function requires GLIBC 2.23 or newer 17880which exports the hardware capability bits. GCC defines the macro 17881@code{__BUILTIN_CPU_SUPPORTS__} if the @code{__builtin_cpu_supports} 17882built-in function is fully supported. 17883 17884If GCC was configured to use a GLIBC before 2.23, the built-in 17885function @code{__builtin_cpu_is} always returns a 0 and the compiler 17886issues a warning. 17887 17888The following CPU names can be detected: 17889 17890@table @samp 17891@item power10 17892IBM POWER10 Server CPU. 17893@item power9 17894IBM POWER9 Server CPU. 17895@item power8 17896IBM POWER8 Server CPU. 17897@item power7 17898IBM POWER7 Server CPU. 17899@item power6x 17900IBM POWER6 Server CPU (RAW mode). 17901@item power6 17902IBM POWER6 Server CPU (Architected mode). 17903@item power5+ 17904IBM POWER5+ Server CPU. 17905@item power5 17906IBM POWER5 Server CPU. 17907@item ppc970 17908IBM 970 Server CPU (ie, Apple G5). 17909@item power4 17910IBM POWER4 Server CPU. 17911@item ppca2 17912IBM A2 64-bit Embedded CPU 17913@item ppc476 17914IBM PowerPC 476FP 32-bit Embedded CPU. 17915@item ppc464 17916IBM PowerPC 464 32-bit Embedded CPU. 17917@item ppc440 17918PowerPC 440 32-bit Embedded CPU. 17919@item ppc405 17920PowerPC 405 32-bit Embedded CPU. 17921@item ppc-cell-be 17922IBM PowerPC Cell Broadband Engine Architecture CPU. 17923@end table 17924 17925Here is an example: 17926@smallexample 17927#ifdef __BUILTIN_CPU_SUPPORTS__ 17928 if (__builtin_cpu_is ("power8")) 17929 @{ 17930 do_power8 (); // POWER8 specific implementation. 17931 @} 17932 else 17933#endif 17934 @{ 17935 do_generic (); // Generic implementation. 17936 @} 17937@end smallexample 17938@end deftypefn 17939 17940@deftypefn {Built-in Function} int __builtin_cpu_supports (const char *@var{feature}) 17941This function returns a value of @code{1} if the run-time CPU supports the HWCAP 17942feature @var{feature} and returns @code{0} otherwise. 17943 17944The @code{__builtin_cpu_supports} function requires GLIBC 2.23 or 17945newer which exports the hardware capability bits. GCC defines the 17946macro @code{__BUILTIN_CPU_SUPPORTS__} if the 17947@code{__builtin_cpu_supports} built-in function is fully supported. 17948 17949If GCC was configured to use a GLIBC before 2.23, the built-in 17950function @code{__builtin_cpu_supports} always returns a 0 and the 17951compiler issues a warning. 17952 17953The following features can be 17954detected: 17955 17956@table @samp 17957@item 4xxmac 179584xx CPU has a Multiply Accumulator. 17959@item altivec 17960CPU has a SIMD/Vector Unit. 17961@item arch_2_05 17962CPU supports ISA 2.05 (eg, POWER6) 17963@item arch_2_06 17964CPU supports ISA 2.06 (eg, POWER7) 17965@item arch_2_07 17966CPU supports ISA 2.07 (eg, POWER8) 17967@item arch_3_00 17968CPU supports ISA 3.0 (eg, POWER9) 17969@item arch_3_1 17970CPU supports ISA 3.1 (eg, POWER10) 17971@item archpmu 17972CPU supports the set of compatible performance monitoring events. 17973@item booke 17974CPU supports the Embedded ISA category. 17975@item cellbe 17976CPU has a CELL broadband engine. 17977@item darn 17978CPU supports the @code{darn} (deliver a random number) instruction. 17979@item dfp 17980CPU has a decimal floating point unit. 17981@item dscr 17982CPU supports the data stream control register. 17983@item ebb 17984CPU supports event base branching. 17985@item efpdouble 17986CPU has a SPE double precision floating point unit. 17987@item efpsingle 17988CPU has a SPE single precision floating point unit. 17989@item fpu 17990CPU has a floating point unit. 17991@item htm 17992CPU has hardware transaction memory instructions. 17993@item htm-nosc 17994Kernel aborts hardware transactions when a syscall is made. 17995@item htm-no-suspend 17996CPU supports hardware transaction memory but does not support the 17997@code{tsuspend.} instruction. 17998@item ic_snoop 17999CPU supports icache snooping capabilities. 18000@item ieee128 18001CPU supports 128-bit IEEE binary floating point instructions. 18002@item isel 18003CPU supports the integer select instruction. 18004@item mma 18005CPU supports the matrix-multiply assist instructions. 18006@item mmu 18007CPU has a memory management unit. 18008@item notb 18009CPU does not have a timebase (eg, 601 and 403gx). 18010@item pa6t 18011CPU supports the PA Semi 6T CORE ISA. 18012@item power4 18013CPU supports ISA 2.00 (eg, POWER4) 18014@item power5 18015CPU supports ISA 2.02 (eg, POWER5) 18016@item power5+ 18017CPU supports ISA 2.03 (eg, POWER5+) 18018@item power6x 18019CPU supports ISA 2.05 (eg, POWER6) extended opcodes mffgpr and mftgpr. 18020@item ppc32 18021CPU supports 32-bit mode execution. 18022@item ppc601 18023CPU supports the old POWER ISA (eg, 601) 18024@item ppc64 18025CPU supports 64-bit mode execution. 18026@item ppcle 18027CPU supports a little-endian mode that uses address swizzling. 18028@item scv 18029Kernel supports system call vectored. 18030@item smt 18031CPU support simultaneous multi-threading. 18032@item spe 18033CPU has a signal processing extension unit. 18034@item tar 18035CPU supports the target address register. 18036@item true_le 18037CPU supports true little-endian mode. 18038@item ucache 18039CPU has unified I/D cache. 18040@item vcrypto 18041CPU supports the vector cryptography instructions. 18042@item vsx 18043CPU supports the vector-scalar extension. 18044@end table 18045 18046Here is an example: 18047@smallexample 18048#ifdef __BUILTIN_CPU_SUPPORTS__ 18049 if (__builtin_cpu_supports ("fpu")) 18050 @{ 18051 asm("fadd %0,%1,%2" : "=d"(dst) : "d"(src1), "d"(src2)); 18052 @} 18053 else 18054#endif 18055 @{ 18056 dst = __fadd (src1, src2); // Software FP addition function. 18057 @} 18058@end smallexample 18059@end deftypefn 18060 18061The following built-in functions are also available on all PowerPC 18062processors: 18063@smallexample 18064uint64_t __builtin_ppc_get_timebase (); 18065unsigned long __builtin_ppc_mftb (); 18066double __builtin_unpack_ibm128 (__ibm128, int); 18067__ibm128 __builtin_pack_ibm128 (double, double); 18068double __builtin_mffs (void); 18069void __builtin_mtfsf (const int, double); 18070void __builtin_mtfsb0 (const int); 18071void __builtin_mtfsb1 (const int); 18072void __builtin_set_fpscr_rn (int); 18073@end smallexample 18074 18075The @code{__builtin_ppc_get_timebase} and @code{__builtin_ppc_mftb} 18076functions generate instructions to read the Time Base Register. The 18077@code{__builtin_ppc_get_timebase} function may generate multiple 18078instructions and always returns the 64 bits of the Time Base Register. 18079The @code{__builtin_ppc_mftb} function always generates one instruction and 18080returns the Time Base Register value as an unsigned long, throwing away 18081the most significant word on 32-bit environments. The @code{__builtin_mffs} 18082return the value of the FPSCR register. Note, ISA 3.0 supports the 18083@code{__builtin_mffsl()} which permits software to read the control and 18084non-sticky status bits in the FSPCR without the higher latency associated with 18085accessing the sticky status bits. The @code{__builtin_mtfsf} takes a constant 180868-bit integer field mask and a double precision floating point argument 18087and generates the @code{mtfsf} (extended mnemonic) instruction to write new 18088values to selected fields of the FPSCR. The 18089@code{__builtin_mtfsb0} and @code{__builtin_mtfsb1} take the bit to change 18090as an argument. The valid bit range is between 0 and 31. The builtins map to 18091the @code{mtfsb0} and @code{mtfsb1} instructions which take the argument and 18092add 32. Hence these instructions only modify the FPSCR[32:63] bits by 18093changing the specified bit to a zero or one respectively. The 18094@code{__builtin_set_fpscr_rn} builtin allows changing both of the floating 18095point rounding mode bits. The argument is a 2-bit value. The argument can 18096either be a @code{const int} or stored in a variable. The builtin uses 18097the ISA 3.0 18098instruction @code{mffscrn} if available, otherwise it reads the FPSCR, masks 18099the current rounding mode bits out and OR's in the new value. 18100 18101@node Basic PowerPC Built-in Functions Available on ISA 2.05 18102@subsubsection Basic PowerPC Built-in Functions Available on ISA 2.05 18103 18104The basic built-in functions described in this section are 18105available on the PowerPC family of processors starting with ISA 2.05 18106or later. Unless specific options are explicitly disabled on the 18107command line, specifying option @option{-mcpu=power6} has the effect of 18108enabling the @option{-mpowerpc64}, @option{-mpowerpc-gpopt}, 18109@option{-mpowerpc-gfxopt}, @option{-mmfcrf}, @option{-mpopcntb}, 18110@option{-mfprnd}, @option{-mcmpb}, @option{-mhard-dfp}, and 18111@option{-mrecip-precision} options. Specify the 18112@option{-maltivec} option explicitly in 18113combination with the above options if desired. 18114 18115The following functions require option @option{-mcmpb}. 18116@smallexample 18117unsigned long long __builtin_cmpb (unsigned long long int, unsigned long long int); 18118unsigned int __builtin_cmpb (unsigned int, unsigned int); 18119@end smallexample 18120 18121The @code{__builtin_cmpb} function 18122performs a byte-wise compare on the contents of its two arguments, 18123returning the result of the byte-wise comparison as the returned 18124value. For each byte comparison, the corresponding byte of the return 18125value holds 0xff if the input bytes are equal and 0 if the input bytes 18126are not equal. If either of the arguments to this built-in function 18127is wider than 32 bits, the function call expands into the form that 18128expects @code{unsigned long long int} arguments 18129which is only available on 64-bit targets. 18130 18131The following built-in functions are available 18132when hardware decimal floating point 18133(@option{-mhard-dfp}) is available: 18134@smallexample 18135void __builtin_set_fpscr_drn(int); 18136_Decimal64 __builtin_ddedpd (int, _Decimal64); 18137_Decimal128 __builtin_ddedpdq (int, _Decimal128); 18138_Decimal64 __builtin_denbcd (int, _Decimal64); 18139_Decimal128 __builtin_denbcdq (int, _Decimal128); 18140_Decimal64 __builtin_diex (long long, _Decimal64); 18141_Decimal128 _builtin_diexq (long long, _Decimal128); 18142_Decimal64 __builtin_dscli (_Decimal64, int); 18143_Decimal128 __builtin_dscliq (_Decimal128, int); 18144_Decimal64 __builtin_dscri (_Decimal64, int); 18145_Decimal128 __builtin_dscriq (_Decimal128, int); 18146long long __builtin_dxex (_Decimal64); 18147long long __builtin_dxexq (_Decimal128); 18148_Decimal128 __builtin_pack_dec128 (unsigned long long, unsigned long long); 18149unsigned long long __builtin_unpack_dec128 (_Decimal128, int); 18150 18151The @code{__builtin_set_fpscr_drn} builtin allows changing the three decimal 18152floating point rounding mode bits. The argument is a 3-bit value. The 18153argument can either be a @code{const int} or the value can be stored in 18154a variable. 18155The builtin uses the ISA 3.0 instruction @code{mffscdrn} if available. 18156Otherwise the builtin reads the FPSCR, masks the current decimal rounding 18157mode bits out and OR's in the new value. 18158 18159@end smallexample 18160 18161The following functions require @option{-mhard-float}, 18162@option{-mpowerpc-gfxopt}, and @option{-mpopcntb} options. 18163 18164@smallexample 18165double __builtin_recipdiv (double, double); 18166float __builtin_recipdivf (float, float); 18167double __builtin_rsqrt (double); 18168float __builtin_rsqrtf (float); 18169@end smallexample 18170 18171The @code{vec_rsqrt}, @code{__builtin_rsqrt}, and 18172@code{__builtin_rsqrtf} functions generate multiple instructions to 18173implement the reciprocal sqrt functionality using reciprocal sqrt 18174estimate instructions. 18175 18176The @code{__builtin_recipdiv}, and @code{__builtin_recipdivf} 18177functions generate multiple instructions to implement division using 18178the reciprocal estimate instructions. 18179 18180The following functions require @option{-mhard-float} and 18181@option{-mmultiple} options. 18182 18183The @code{__builtin_unpack_longdouble} function takes a 18184@code{long double} argument and a compile time constant of 0 or 1. If 18185the constant is 0, the first @code{double} within the 18186@code{long double} is returned, otherwise the second @code{double} 18187is returned. The @code{__builtin_unpack_longdouble} function is only 18188available if @code{long double} uses the IBM extended double 18189representation. 18190 18191The @code{__builtin_pack_longdouble} function takes two @code{double} 18192arguments and returns a @code{long double} value that combines the two 18193arguments. The @code{__builtin_pack_longdouble} function is only 18194available if @code{long double} uses the IBM extended double 18195representation. 18196 18197The @code{__builtin_unpack_ibm128} function takes a @code{__ibm128} 18198argument and a compile time constant of 0 or 1. If the constant is 0, 18199the first @code{double} within the @code{__ibm128} is returned, 18200otherwise the second @code{double} is returned. 18201 18202The @code{__builtin_pack_ibm128} function takes two @code{double} 18203arguments and returns a @code{__ibm128} value that combines the two 18204arguments. 18205 18206Additional built-in functions are available for the 64-bit PowerPC 18207family of processors, for efficient use of 128-bit floating point 18208(@code{__float128}) values. 18209 18210@node Basic PowerPC Built-in Functions Available on ISA 2.06 18211@subsubsection Basic PowerPC Built-in Functions Available on ISA 2.06 18212 18213The basic built-in functions described in this section are 18214available on the PowerPC family of processors starting with ISA 2.05 18215or later. Unless specific options are explicitly disabled on the 18216command line, specifying option @option{-mcpu=power7} has the effect of 18217enabling all the same options as for @option{-mcpu=power6} in 18218addition to the @option{-maltivec}, @option{-mpopcntd}, and 18219@option{-mvsx} options. 18220 18221The following basic built-in functions require @option{-mpopcntd}: 18222@smallexample 18223unsigned int __builtin_addg6s (unsigned int, unsigned int); 18224long long __builtin_bpermd (long long, long long); 18225unsigned int __builtin_cbcdtd (unsigned int); 18226unsigned int __builtin_cdtbcd (unsigned int); 18227long long __builtin_divde (long long, long long); 18228unsigned long long __builtin_divdeu (unsigned long long, unsigned long long); 18229int __builtin_divwe (int, int); 18230unsigned int __builtin_divweu (unsigned int, unsigned int); 18231vector __int128 __builtin_pack_vector_int128 (long long, long long); 18232void __builtin_rs6000_speculation_barrier (void); 18233long long __builtin_unpack_vector_int128 (vector __int128, signed char); 18234@end smallexample 18235 18236Of these, the @code{__builtin_divde} and @code{__builtin_divdeu} functions 18237require a 64-bit environment. 18238 18239The following basic built-in functions, which are also supported on 18240x86 targets, require @option{-mfloat128}. 18241@smallexample 18242__float128 __builtin_fabsq (__float128); 18243__float128 __builtin_copysignq (__float128, __float128); 18244__float128 __builtin_infq (void); 18245__float128 __builtin_huge_valq (void); 18246__float128 __builtin_nanq (void); 18247__float128 __builtin_nansq (void); 18248 18249__float128 __builtin_sqrtf128 (__float128); 18250__float128 __builtin_fmaf128 (__float128, __float128, __float128); 18251@end smallexample 18252 18253@node Basic PowerPC Built-in Functions Available on ISA 2.07 18254@subsubsection Basic PowerPC Built-in Functions Available on ISA 2.07 18255 18256The basic built-in functions described in this section are 18257available on the PowerPC family of processors starting with ISA 2.07 18258or later. Unless specific options are explicitly disabled on the 18259command line, specifying option @option{-mcpu=power8} has the effect of 18260enabling all the same options as for @option{-mcpu=power7} in 18261addition to the @option{-mpower8-fusion}, @option{-mpower8-vector}, 18262@option{-mcrypto}, @option{-mhtm}, @option{-mquad-memory}, and 18263@option{-mquad-memory-atomic} options. 18264 18265This section intentionally empty. 18266 18267@node Basic PowerPC Built-in Functions Available on ISA 3.0 18268@subsubsection Basic PowerPC Built-in Functions Available on ISA 3.0 18269 18270The basic built-in functions described in this section are 18271available on the PowerPC family of processors starting with ISA 3.0 18272or later. Unless specific options are explicitly disabled on the 18273command line, specifying option @option{-mcpu=power9} has the effect of 18274enabling all the same options as for @option{-mcpu=power8} in 18275addition to the @option{-misel} option. 18276 18277The following built-in functions are available on Linux 64-bit systems 18278that use the ISA 3.0 instruction set (@option{-mcpu=power9}): 18279 18280@table @code 18281@item __float128 __builtin_addf128_round_to_odd (__float128, __float128) 18282Perform a 128-bit IEEE floating point add using round to odd as the 18283rounding mode. 18284@findex __builtin_addf128_round_to_odd 18285 18286@item __float128 __builtin_subf128_round_to_odd (__float128, __float128) 18287Perform a 128-bit IEEE floating point subtract using round to odd as 18288the rounding mode. 18289@findex __builtin_subf128_round_to_odd 18290 18291@item __float128 __builtin_mulf128_round_to_odd (__float128, __float128) 18292Perform a 128-bit IEEE floating point multiply using round to odd as 18293the rounding mode. 18294@findex __builtin_mulf128_round_to_odd 18295 18296@item __float128 __builtin_divf128_round_to_odd (__float128, __float128) 18297Perform a 128-bit IEEE floating point divide using round to odd as 18298the rounding mode. 18299@findex __builtin_divf128_round_to_odd 18300 18301@item __float128 __builtin_sqrtf128_round_to_odd (__float128) 18302Perform a 128-bit IEEE floating point square root using round to odd 18303as the rounding mode. 18304@findex __builtin_sqrtf128_round_to_odd 18305 18306@item __float128 __builtin_fmaf128_round_to_odd (__float128, __float128, __float128) 18307Perform a 128-bit IEEE floating point fused multiply and add operation 18308using round to odd as the rounding mode. 18309@findex __builtin_fmaf128_round_to_odd 18310 18311@item double __builtin_truncf128_round_to_odd (__float128) 18312Convert a 128-bit IEEE floating point value to @code{double} using 18313round to odd as the rounding mode. 18314@findex __builtin_truncf128_round_to_odd 18315@end table 18316 18317The following additional built-in functions are also available for the 18318PowerPC family of processors, starting with ISA 3.0 or later: 18319@smallexample 18320long long __builtin_darn (void); 18321long long __builtin_darn_raw (void); 18322int __builtin_darn_32 (void); 18323@end smallexample 18324 18325The @code{__builtin_darn} and @code{__builtin_darn_raw} 18326functions require a 1832764-bit environment supporting ISA 3.0 or later. 18328The @code{__builtin_darn} function provides a 64-bit conditioned 18329random number. The @code{__builtin_darn_raw} function provides a 1833064-bit raw random number. The @code{__builtin_darn_32} function 18331provides a 32-bit conditioned random number. 18332 18333The following additional built-in functions are also available for the 18334PowerPC family of processors, starting with ISA 3.0 or later: 18335 18336@smallexample 18337int __builtin_byte_in_set (unsigned char u, unsigned long long set); 18338int __builtin_byte_in_range (unsigned char u, unsigned int range); 18339int __builtin_byte_in_either_range (unsigned char u, unsigned int ranges); 18340 18341int __builtin_dfp_dtstsfi_lt (unsigned int comparison, _Decimal64 value); 18342int __builtin_dfp_dtstsfi_lt (unsigned int comparison, _Decimal128 value); 18343int __builtin_dfp_dtstsfi_lt_dd (unsigned int comparison, _Decimal64 value); 18344int __builtin_dfp_dtstsfi_lt_td (unsigned int comparison, _Decimal128 value); 18345 18346int __builtin_dfp_dtstsfi_gt (unsigned int comparison, _Decimal64 value); 18347int __builtin_dfp_dtstsfi_gt (unsigned int comparison, _Decimal128 value); 18348int __builtin_dfp_dtstsfi_gt_dd (unsigned int comparison, _Decimal64 value); 18349int __builtin_dfp_dtstsfi_gt_td (unsigned int comparison, _Decimal128 value); 18350 18351int __builtin_dfp_dtstsfi_eq (unsigned int comparison, _Decimal64 value); 18352int __builtin_dfp_dtstsfi_eq (unsigned int comparison, _Decimal128 value); 18353int __builtin_dfp_dtstsfi_eq_dd (unsigned int comparison, _Decimal64 value); 18354int __builtin_dfp_dtstsfi_eq_td (unsigned int comparison, _Decimal128 value); 18355 18356int __builtin_dfp_dtstsfi_ov (unsigned int comparison, _Decimal64 value); 18357int __builtin_dfp_dtstsfi_ov (unsigned int comparison, _Decimal128 value); 18358int __builtin_dfp_dtstsfi_ov_dd (unsigned int comparison, _Decimal64 value); 18359int __builtin_dfp_dtstsfi_ov_td (unsigned int comparison, _Decimal128 value); 18360 18361double __builtin_mffsl(void); 18362 18363@end smallexample 18364The @code{__builtin_byte_in_set} function requires a 1836564-bit environment supporting ISA 3.0 or later. This function returns 18366a non-zero value if and only if its @code{u} argument exactly equals one of 18367the eight bytes contained within its 64-bit @code{set} argument. 18368 18369The @code{__builtin_byte_in_range} and 18370@code{__builtin_byte_in_either_range} require an environment 18371supporting ISA 3.0 or later. For these two functions, the 18372@code{range} argument is encoded as 4 bytes, organized as 18373@code{hi_1:lo_1:hi_2:lo_2}. 18374The @code{__builtin_byte_in_range} function returns a 18375non-zero value if and only if its @code{u} argument is within the 18376range bounded between @code{lo_2} and @code{hi_2} inclusive. 18377The @code{__builtin_byte_in_either_range} function returns non-zero if 18378and only if its @code{u} argument is within either the range bounded 18379between @code{lo_1} and @code{hi_1} inclusive or the range bounded 18380between @code{lo_2} and @code{hi_2} inclusive. 18381 18382The @code{__builtin_dfp_dtstsfi_lt} function returns a non-zero value 18383if and only if the number of signficant digits of its @code{value} argument 18384is less than its @code{comparison} argument. The 18385@code{__builtin_dfp_dtstsfi_lt_dd} and 18386@code{__builtin_dfp_dtstsfi_lt_td} functions behave similarly, but 18387require that the type of the @code{value} argument be 18388@code{__Decimal64} and @code{__Decimal128} respectively. 18389 18390The @code{__builtin_dfp_dtstsfi_gt} function returns a non-zero value 18391if and only if the number of signficant digits of its @code{value} argument 18392is greater than its @code{comparison} argument. The 18393@code{__builtin_dfp_dtstsfi_gt_dd} and 18394@code{__builtin_dfp_dtstsfi_gt_td} functions behave similarly, but 18395require that the type of the @code{value} argument be 18396@code{__Decimal64} and @code{__Decimal128} respectively. 18397 18398The @code{__builtin_dfp_dtstsfi_eq} function returns a non-zero value 18399if and only if the number of signficant digits of its @code{value} argument 18400equals its @code{comparison} argument. The 18401@code{__builtin_dfp_dtstsfi_eq_dd} and 18402@code{__builtin_dfp_dtstsfi_eq_td} functions behave similarly, but 18403require that the type of the @code{value} argument be 18404@code{__Decimal64} and @code{__Decimal128} respectively. 18405 18406The @code{__builtin_dfp_dtstsfi_ov} function returns a non-zero value 18407if and only if its @code{value} argument has an undefined number of 18408significant digits, such as when @code{value} is an encoding of @code{NaN}. 18409The @code{__builtin_dfp_dtstsfi_ov_dd} and 18410@code{__builtin_dfp_dtstsfi_ov_td} functions behave similarly, but 18411require that the type of the @code{value} argument be 18412@code{__Decimal64} and @code{__Decimal128} respectively. 18413 18414The @code{__builtin_mffsl} uses the ISA 3.0 @code{mffsl} instruction to read 18415the FPSCR. The instruction is a lower latency version of the @code{mffs} 18416instruction. If the @code{mffsl} instruction is not available, then the 18417builtin uses the older @code{mffs} instruction to read the FPSCR. 18418 18419@node Basic PowerPC Built-in Functions Available on ISA 3.1 18420@subsubsection Basic PowerPC Built-in Functions Available on ISA 3.1 18421 18422The basic built-in functions described in this section are 18423available on the PowerPC family of processors starting with ISA 3.1. 18424Unless specific options are explicitly disabled on the 18425command line, specifying option @option{-mcpu=power10} has the effect of 18426enabling all the same options as for @option{-mcpu=power9}. 18427 18428The following built-in functions are available on Linux 64-bit systems 18429that use a future architecture instruction set (@option{-mcpu=power10}): 18430 18431@smallexample 18432@exdent unsigned long long 18433@exdent __builtin_cfuged (unsigned long long, unsigned long long) 18434@end smallexample 18435Perform a 64-bit centrifuge operation, as if implemented by the 18436@code{cfuged} instruction. 18437@findex __builtin_cfuged 18438 18439@smallexample 18440@exdent unsigned long long 18441@exdent __builtin_cntlzdm (unsigned long long, unsigned long long) 18442@end smallexample 18443Perform a 64-bit count leading zeros operation under mask, as if 18444implemented by the @code{cntlzdm} instruction. 18445@findex __builtin_cntlzdm 18446 18447@smallexample 18448@exdent unsigned long long 18449@exdent __builtin_cnttzdm (unsigned long long, unsigned long long) 18450@end smallexample 18451Perform a 64-bit count trailing zeros operation under mask, as if 18452implemented by the @code{cnttzdm} instruction. 18453@findex __builtin_cnttzdm 18454 18455@smallexample 18456@exdent unsigned long long 18457@exdent __builtin_pdepd (unsigned long long, unsigned long long) 18458@end smallexample 18459Perform a 64-bit parallel bits deposit operation, as if implemented by the 18460@code{pdepd} instruction. 18461@findex __builtin_pdepd 18462 18463@smallexample 18464@exdent unsigned long long 18465@exdent __builtin_pextd (unsigned long long, unsigned long long) 18466@end smallexample 18467Perform a 64-bit parallel bits extract operation, as if implemented by the 18468@code{pextd} instruction. 18469@findex __builtin_pextd 18470 18471@smallexample 18472@exdent vector signed __int128 vsx_xl_sext (signed long long, signed char *) 18473 18474@exdent vector signed __int128 vsx_xl_sext (signed long long, signed short *) 18475 18476@exdent vector signed __int128 vsx_xl_sext (signed long long, signed int *) 18477 18478@exdent vector signed __int128 vsx_xl_sext (signed long long, signed long long *) 18479 18480@exdent vector unsigned __int128 vsx_xl_zext (signed long long, unsigned char *) 18481 18482@exdent vector unsigned __int128 vsx_xl_zext (signed long long, unsigned short *) 18483 18484@exdent vector unsigned __int128 vsx_xl_zext (signed long long, unsigned int *) 18485 18486@exdent vector unsigned __int128 vsx_xl_zext (signed long long, unsigned long long *) 18487@end smallexample 18488 18489Load (and sign extend) to an __int128 vector, as if implemented by the ISA 3.1 18490@code{lxvrbx}, @code{lxvrhx}, @code{lxvrwx}, and @code{lxvrdx} instructions. 18491@findex vsx_xl_sext 18492@findex vsx_xl_zext 18493 18494@smallexample 18495@exdent void vec_xst_trunc (vector signed __int128, signed long long, signed char *) 18496 18497@exdent void vec_xst_trunc (vector signed __int128, signed long long, signed short *) 18498 18499@exdent void vec_xst_trunc (vector signed __int128, signed long long, signed int *) 18500 18501@exdent void vec_xst_trunc (vector signed __int128, signed long long, signed long long *) 18502 18503@exdent void vec_xst_trunc (vector unsigned __int128, signed long long, unsigned char *) 18504 18505@exdent void vec_xst_trunc (vector unsigned __int128, signed long long, unsigned short *) 18506 18507@exdent void vec_xst_trunc (vector unsigned __int128, signed long long, unsigned int *) 18508 18509@exdent void vec_xst_trunc (vector unsigned __int128, signed long long, unsigned long long *) 18510@end smallexample 18511 18512Truncate and store the rightmost element of a vector, as if implemented by the 18513ISA 3.1 @code{stxvrbx}, @code{stxvrhx}, @code{stxvrwx}, and @code{stxvrdx} 18514instructions. 18515@findex vec_xst_trunc 18516 18517@node PowerPC AltiVec/VSX Built-in Functions 18518@subsection PowerPC AltiVec/VSX Built-in Functions 18519 18520GCC provides an interface for the PowerPC family of processors to access 18521the AltiVec operations described in Motorola's AltiVec Programming 18522Interface Manual. The interface is made available by including 18523@code{<altivec.h>} and using @option{-maltivec} and 18524@option{-mabi=altivec}. The interface supports the following vector 18525types. 18526 18527@smallexample 18528vector unsigned char 18529vector signed char 18530vector bool char 18531 18532vector unsigned short 18533vector signed short 18534vector bool short 18535vector pixel 18536 18537vector unsigned int 18538vector signed int 18539vector bool int 18540vector float 18541@end smallexample 18542 18543GCC's implementation of the high-level language interface available from 18544C and C++ code differs from Motorola's documentation in several ways. 18545 18546@itemize @bullet 18547 18548@item 18549A vector constant is a list of constant expressions within curly braces. 18550 18551@item 18552A vector initializer requires no cast if the vector constant is of the 18553same type as the variable it is initializing. 18554 18555@item 18556If @code{signed} or @code{unsigned} is omitted, the signedness of the 18557vector type is the default signedness of the base type. The default 18558varies depending on the operating system, so a portable program should 18559always specify the signedness. 18560 18561@item 18562Compiling with @option{-maltivec} adds keywords @code{__vector}, 18563@code{vector}, @code{__pixel}, @code{pixel}, @code{__bool} and 18564@code{bool}. When compiling ISO C, the context-sensitive substitution 18565of the keywords @code{vector}, @code{pixel} and @code{bool} is 18566disabled. To use them, you must include @code{<altivec.h>} instead. 18567 18568@item 18569GCC allows using a @code{typedef} name as the type specifier for a 18570vector type, but only under the following circumstances: 18571 18572@itemize @bullet 18573 18574@item 18575When using @code{__vector} instead of @code{vector}; for example, 18576 18577@smallexample 18578typedef signed short int16; 18579__vector int16 data; 18580@end smallexample 18581 18582@item 18583When using @code{vector} in keyword-and-predefine mode; for example, 18584 18585@smallexample 18586typedef signed short int16; 18587vector int16 data; 18588@end smallexample 18589 18590Note that keyword-and-predefine mode is enabled by disabling GNU 18591extensions (e.g., by using @code{-std=c11}) and including 18592@code{<altivec.h>}. 18593@end itemize 18594 18595@item 18596For C, overloaded functions are implemented with macros so the following 18597does not work: 18598 18599@smallexample 18600 vec_add ((vector signed int)@{1, 2, 3, 4@}, foo); 18601@end smallexample 18602 18603@noindent 18604Since @code{vec_add} is a macro, the vector constant in the example 18605is treated as four separate arguments. Wrap the entire argument in 18606parentheses for this to work. 18607@end itemize 18608 18609@emph{Note:} Only the @code{<altivec.h>} interface is supported. 18610Internally, GCC uses built-in functions to achieve the functionality in 18611the aforementioned header file, but they are not supported and are 18612subject to change without notice. 18613 18614GCC complies with the Power Vector Intrinsic Programming Reference (PVIPR), 18615which may be found at 18616@uref{https://openpowerfoundation.org/?resource_lib=power-vector-intrinsic-programming-reference}. 18617Chapter 4 of this document fully documents the vector API interfaces 18618that must be 18619provided by compliant compilers. Programmers should preferentially use 18620the interfaces described therein. However, historically GCC has provided 18621additional interfaces for access to vector instructions. These are 18622briefly described below. Where the PVIPR provides a portable interface, 18623other functions in GCC that provide the same capabilities should be 18624considered deprecated. 18625 18626The PVIPR documents the following overloaded functions: 18627 18628@multitable @columnfractions 0.33 0.33 0.33 18629 18630@item @code{vec_abs} 18631@tab @code{vec_absd} 18632@tab @code{vec_abss} 18633@item @code{vec_add} 18634@tab @code{vec_addc} 18635@tab @code{vec_adde} 18636@item @code{vec_addec} 18637@tab @code{vec_adds} 18638@tab @code{vec_all_eq} 18639@item @code{vec_all_ge} 18640@tab @code{vec_all_gt} 18641@tab @code{vec_all_in} 18642@item @code{vec_all_le} 18643@tab @code{vec_all_lt} 18644@tab @code{vec_all_nan} 18645@item @code{vec_all_ne} 18646@tab @code{vec_all_nge} 18647@tab @code{vec_all_ngt} 18648@item @code{vec_all_nle} 18649@tab @code{vec_all_nlt} 18650@tab @code{vec_all_numeric} 18651@item @code{vec_and} 18652@tab @code{vec_andc} 18653@tab @code{vec_any_eq} 18654@item @code{vec_any_ge} 18655@tab @code{vec_any_gt} 18656@tab @code{vec_any_le} 18657@item @code{vec_any_lt} 18658@tab @code{vec_any_nan} 18659@tab @code{vec_any_ne} 18660@item @code{vec_any_nge} 18661@tab @code{vec_any_ngt} 18662@tab @code{vec_any_nle} 18663@item @code{vec_any_nlt} 18664@tab @code{vec_any_numeric} 18665@tab @code{vec_any_out} 18666@item @code{vec_avg} 18667@tab @code{vec_bperm} 18668@tab @code{vec_ceil} 18669@item @code{vec_cipher_be} 18670@tab @code{vec_cipherlast_be} 18671@tab @code{vec_cmpb} 18672@item @code{vec_cmpeq} 18673@tab @code{vec_cmpge} 18674@tab @code{vec_cmpgt} 18675@item @code{vec_cmple} 18676@tab @code{vec_cmplt} 18677@tab @code{vec_cmpne} 18678@item @code{vec_cmpnez} 18679@tab @code{vec_cntlz} 18680@tab @code{vec_cntlz_lsbb} 18681@item @code{vec_cnttz} 18682@tab @code{vec_cnttz_lsbb} 18683@tab @code{vec_cpsgn} 18684@item @code{vec_ctf} 18685@tab @code{vec_cts} 18686@tab @code{vec_ctu} 18687@item @code{vec_div} 18688@tab @code{vec_double} 18689@tab @code{vec_doublee} 18690@item @code{vec_doubleh} 18691@tab @code{vec_doublel} 18692@tab @code{vec_doubleo} 18693@item @code{vec_eqv} 18694@tab @code{vec_expte} 18695@tab @code{vec_extract} 18696@item @code{vec_extract_exp} 18697@tab @code{vec_extract_fp32_from_shorth} 18698@tab @code{vec_extract_fp32_from_shortl} 18699@item @code{vec_extract_sig} 18700@tab @code{vec_extract_4b} 18701@tab @code{vec_first_match_index} 18702@item @code{vec_first_match_or_eos_index} 18703@tab @code{vec_first_mismatch_index} 18704@tab @code{vec_first_mismatch_or_eos_index} 18705@item @code{vec_float} 18706@tab @code{vec_float2} 18707@tab @code{vec_floate} 18708@item @code{vec_floato} 18709@tab @code{vec_floor} 18710@tab @code{vec_gb} 18711@item @code{vec_insert} 18712@tab @code{vec_insert_exp} 18713@tab @code{vec_insert4b} 18714@item @code{vec_ld} 18715@tab @code{vec_lde} 18716@tab @code{vec_ldl} 18717@item @code{vec_loge} 18718@tab @code{vec_madd} 18719@tab @code{vec_madds} 18720@item @code{vec_max} 18721@tab @code{vec_mergee} 18722@tab @code{vec_mergeh} 18723@item @code{vec_mergel} 18724@tab @code{vec_mergeo} 18725@tab @code{vec_mfvscr} 18726@item @code{vec_min} 18727@tab @code{vec_mradds} 18728@tab @code{vec_msub} 18729@item @code{vec_msum} 18730@tab @code{vec_msums} 18731@tab @code{vec_mtvscr} 18732@item @code{vec_mul} 18733@tab @code{vec_mule} 18734@tab @code{vec_mulo} 18735@item @code{vec_nabs} 18736@tab @code{vec_nand} 18737@tab @code{vec_ncipher_be} 18738@item @code{vec_ncipherlast_be} 18739@tab @code{vec_nearbyint} 18740@tab @code{vec_neg} 18741@item @code{vec_nmadd} 18742@tab @code{vec_nmsub} 18743@tab @code{vec_nor} 18744@item @code{vec_or} 18745@tab @code{vec_orc} 18746@tab @code{vec_pack} 18747@item @code{vec_pack_to_short_fp32} 18748@tab @code{vec_packpx} 18749@tab @code{vec_packs} 18750@item @code{vec_packsu} 18751@tab @code{vec_parity_lsbb} 18752@tab @code{vec_perm} 18753@item @code{vec_permxor} 18754@tab @code{vec_pmsum_be} 18755@tab @code{vec_popcnt} 18756@item @code{vec_re} 18757@tab @code{vec_recipdiv} 18758@tab @code{vec_revb} 18759@item @code{vec_reve} 18760@tab @code{vec_rint} 18761@tab @code{vec_rl} 18762@item @code{vec_rlmi} 18763@tab @code{vec_rlnm} 18764@tab @code{vec_round} 18765@item @code{vec_rsqrt} 18766@tab @code{vec_rsqrte} 18767@tab @code{vec_sbox_be} 18768@item @code{vec_sel} 18769@tab @code{vec_shasigma_be} 18770@tab @code{vec_signed} 18771@item @code{vec_signed2} 18772@tab @code{vec_signede} 18773@tab @code{vec_signedo} 18774@item @code{vec_sl} 18775@tab @code{vec_sld} 18776@tab @code{vec_sldw} 18777@item @code{vec_sll} 18778@tab @code{vec_slo} 18779@tab @code{vec_slv} 18780@item @code{vec_splat} 18781@tab @code{vec_splat_s8} 18782@tab @code{vec_splat_s16} 18783@item @code{vec_splat_s32} 18784@tab @code{vec_splat_u8} 18785@tab @code{vec_splat_u16} 18786@item @code{vec_splat_u32} 18787@tab @code{vec_splats} 18788@tab @code{vec_sqrt} 18789@item @code{vec_sr} 18790@tab @code{vec_sra} 18791@tab @code{vec_srl} 18792@item @code{vec_sro} 18793@tab @code{vec_srv} 18794@tab @code{vec_st} 18795@item @code{vec_ste} 18796@tab @code{vec_stl} 18797@tab @code{vec_sub} 18798@item @code{vec_subc} 18799@tab @code{vec_sube} 18800@tab @code{vec_subec} 18801@item @code{vec_subs} 18802@tab @code{vec_sum2s} 18803@tab @code{vec_sum4s} 18804@item @code{vec_sums} 18805@tab @code{vec_test_data_class} 18806@tab @code{vec_trunc} 18807@item @code{vec_unpackh} 18808@tab @code{vec_unpackl} 18809@tab @code{vec_unsigned} 18810@item @code{vec_unsigned2} 18811@tab @code{vec_unsignede} 18812@tab @code{vec_unsignedo} 18813@item @code{vec_xl} 18814@tab @code{vec_xl_be} 18815@tab @code{vec_xl_len} 18816@item @code{vec_xl_len_r} 18817@tab @code{vec_xor} 18818@tab @code{vec_xst} 18819@item @code{vec_xst_be} 18820@tab @code{vec_xst_len} 18821@tab @code{vec_xst_len_r} 18822 18823@end multitable 18824 18825@menu 18826* PowerPC AltiVec Built-in Functions on ISA 2.05:: 18827* PowerPC AltiVec Built-in Functions Available on ISA 2.06:: 18828* PowerPC AltiVec Built-in Functions Available on ISA 2.07:: 18829* PowerPC AltiVec Built-in Functions Available on ISA 3.0:: 18830* PowerPC AltiVec Built-in Functions Available on ISA 3.1:: 18831@end menu 18832 18833@node PowerPC AltiVec Built-in Functions on ISA 2.05 18834@subsubsection PowerPC AltiVec Built-in Functions on ISA 2.05 18835 18836The following interfaces are supported for the generic and specific 18837AltiVec operations and the AltiVec predicates. In cases where there 18838is a direct mapping between generic and specific operations, only the 18839generic names are shown here, although the specific operations can also 18840be used. 18841 18842Arguments that are documented as @code{const int} require literal 18843integral values within the range required for that operation. 18844 18845Only functions excluded from the PVIPR are listed here. 18846 18847@smallexample 18848void vec_dss (const int); 18849 18850void vec_dssall (void); 18851 18852void vec_dst (const vector unsigned char *, int, const int); 18853void vec_dst (const vector signed char *, int, const int); 18854void vec_dst (const vector bool char *, int, const int); 18855void vec_dst (const vector unsigned short *, int, const int); 18856void vec_dst (const vector signed short *, int, const int); 18857void vec_dst (const vector bool short *, int, const int); 18858void vec_dst (const vector pixel *, int, const int); 18859void vec_dst (const vector unsigned int *, int, const int); 18860void vec_dst (const vector signed int *, int, const int); 18861void vec_dst (const vector bool int *, int, const int); 18862void vec_dst (const vector float *, int, const int); 18863void vec_dst (const unsigned char *, int, const int); 18864void vec_dst (const signed char *, int, const int); 18865void vec_dst (const unsigned short *, int, const int); 18866void vec_dst (const short *, int, const int); 18867void vec_dst (const unsigned int *, int, const int); 18868void vec_dst (const int *, int, const int); 18869void vec_dst (const float *, int, const int); 18870 18871void vec_dstst (const vector unsigned char *, int, const int); 18872void vec_dstst (const vector signed char *, int, const int); 18873void vec_dstst (const vector bool char *, int, const int); 18874void vec_dstst (const vector unsigned short *, int, const int); 18875void vec_dstst (const vector signed short *, int, const int); 18876void vec_dstst (const vector bool short *, int, const int); 18877void vec_dstst (const vector pixel *, int, const int); 18878void vec_dstst (const vector unsigned int *, int, const int); 18879void vec_dstst (const vector signed int *, int, const int); 18880void vec_dstst (const vector bool int *, int, const int); 18881void vec_dstst (const vector float *, int, const int); 18882void vec_dstst (const unsigned char *, int, const int); 18883void vec_dstst (const signed char *, int, const int); 18884void vec_dstst (const unsigned short *, int, const int); 18885void vec_dstst (const short *, int, const int); 18886void vec_dstst (const unsigned int *, int, const int); 18887void vec_dstst (const int *, int, const int); 18888void vec_dstst (const unsigned long *, int, const int); 18889void vec_dstst (const long *, int, const int); 18890void vec_dstst (const float *, int, const int); 18891 18892void vec_dststt (const vector unsigned char *, int, const int); 18893void vec_dststt (const vector signed char *, int, const int); 18894void vec_dststt (const vector bool char *, int, const int); 18895void vec_dststt (const vector unsigned short *, int, const int); 18896void vec_dststt (const vector signed short *, int, const int); 18897void vec_dststt (const vector bool short *, int, const int); 18898void vec_dststt (const vector pixel *, int, const int); 18899void vec_dststt (const vector unsigned int *, int, const int); 18900void vec_dststt (const vector signed int *, int, const int); 18901void vec_dststt (const vector bool int *, int, const int); 18902void vec_dststt (const vector float *, int, const int); 18903void vec_dststt (const unsigned char *, int, const int); 18904void vec_dststt (const signed char *, int, const int); 18905void vec_dststt (const unsigned short *, int, const int); 18906void vec_dststt (const short *, int, const int); 18907void vec_dststt (const unsigned int *, int, const int); 18908void vec_dststt (const int *, int, const int); 18909void vec_dststt (const float *, int, const int); 18910 18911void vec_dstt (const vector unsigned char *, int, const int); 18912void vec_dstt (const vector signed char *, int, const int); 18913void vec_dstt (const vector bool char *, int, const int); 18914void vec_dstt (const vector unsigned short *, int, const int); 18915void vec_dstt (const vector signed short *, int, const int); 18916void vec_dstt (const vector bool short *, int, const int); 18917void vec_dstt (const vector pixel *, int, const int); 18918void vec_dstt (const vector unsigned int *, int, const int); 18919void vec_dstt (const vector signed int *, int, const int); 18920void vec_dstt (const vector bool int *, int, const int); 18921void vec_dstt (const vector float *, int, const int); 18922void vec_dstt (const unsigned char *, int, const int); 18923void vec_dstt (const signed char *, int, const int); 18924void vec_dstt (const unsigned short *, int, const int); 18925void vec_dstt (const short *, int, const int); 18926void vec_dstt (const unsigned int *, int, const int); 18927void vec_dstt (const int *, int, const int); 18928void vec_dstt (const float *, int, const int); 18929 18930vector signed char vec_lvebx (int, char *); 18931vector unsigned char vec_lvebx (int, unsigned char *); 18932 18933vector signed short vec_lvehx (int, short *); 18934vector unsigned short vec_lvehx (int, unsigned short *); 18935 18936vector float vec_lvewx (int, float *); 18937vector signed int vec_lvewx (int, int *); 18938vector unsigned int vec_lvewx (int, unsigned int *); 18939 18940vector unsigned char vec_lvsl (int, const unsigned char *); 18941vector unsigned char vec_lvsl (int, const signed char *); 18942vector unsigned char vec_lvsl (int, const unsigned short *); 18943vector unsigned char vec_lvsl (int, const short *); 18944vector unsigned char vec_lvsl (int, const unsigned int *); 18945vector unsigned char vec_lvsl (int, const int *); 18946vector unsigned char vec_lvsl (int, const float *); 18947 18948vector unsigned char vec_lvsr (int, const unsigned char *); 18949vector unsigned char vec_lvsr (int, const signed char *); 18950vector unsigned char vec_lvsr (int, const unsigned short *); 18951vector unsigned char vec_lvsr (int, const short *); 18952vector unsigned char vec_lvsr (int, const unsigned int *); 18953vector unsigned char vec_lvsr (int, const int *); 18954vector unsigned char vec_lvsr (int, const float *); 18955 18956void vec_stvebx (vector signed char, int, signed char *); 18957void vec_stvebx (vector unsigned char, int, unsigned char *); 18958void vec_stvebx (vector bool char, int, signed char *); 18959void vec_stvebx (vector bool char, int, unsigned char *); 18960 18961void vec_stvehx (vector signed short, int, short *); 18962void vec_stvehx (vector unsigned short, int, unsigned short *); 18963void vec_stvehx (vector bool short, int, short *); 18964void vec_stvehx (vector bool short, int, unsigned short *); 18965 18966void vec_stvewx (vector float, int, float *); 18967void vec_stvewx (vector signed int, int, int *); 18968void vec_stvewx (vector unsigned int, int, unsigned int *); 18969void vec_stvewx (vector bool int, int, int *); 18970void vec_stvewx (vector bool int, int, unsigned int *); 18971 18972vector float vec_vaddfp (vector float, vector float); 18973 18974vector signed char vec_vaddsbs (vector bool char, vector signed char); 18975vector signed char vec_vaddsbs (vector signed char, vector bool char); 18976vector signed char vec_vaddsbs (vector signed char, vector signed char); 18977 18978vector signed short vec_vaddshs (vector bool short, vector signed short); 18979vector signed short vec_vaddshs (vector signed short, vector bool short); 18980vector signed short vec_vaddshs (vector signed short, vector signed short); 18981 18982vector signed int vec_vaddsws (vector bool int, vector signed int); 18983vector signed int vec_vaddsws (vector signed int, vector bool int); 18984vector signed int vec_vaddsws (vector signed int, vector signed int); 18985 18986vector signed char vec_vaddubm (vector bool char, vector signed char); 18987vector signed char vec_vaddubm (vector signed char, vector bool char); 18988vector signed char vec_vaddubm (vector signed char, vector signed char); 18989vector unsigned char vec_vaddubm (vector bool char, vector unsigned char); 18990vector unsigned char vec_vaddubm (vector unsigned char, vector bool char); 18991vector unsigned char vec_vaddubm (vector unsigned char, vector unsigned char); 18992 18993vector unsigned char vec_vaddubs (vector bool char, vector unsigned char); 18994vector unsigned char vec_vaddubs (vector unsigned char, vector bool char); 18995vector unsigned char vec_vaddubs (vector unsigned char, vector unsigned char); 18996 18997vector signed short vec_vadduhm (vector bool short, vector signed short); 18998vector signed short vec_vadduhm (vector signed short, vector bool short); 18999vector signed short vec_vadduhm (vector signed short, vector signed short); 19000vector unsigned short vec_vadduhm (vector bool short, vector unsigned short); 19001vector unsigned short vec_vadduhm (vector unsigned short, vector bool short); 19002vector unsigned short vec_vadduhm (vector unsigned short, vector unsigned short); 19003 19004vector unsigned short vec_vadduhs (vector bool short, vector unsigned short); 19005vector unsigned short vec_vadduhs (vector unsigned short, vector bool short); 19006vector unsigned short vec_vadduhs (vector unsigned short, vector unsigned short); 19007 19008vector signed int vec_vadduwm (vector bool int, vector signed int); 19009vector signed int vec_vadduwm (vector signed int, vector bool int); 19010vector signed int vec_vadduwm (vector signed int, vector signed int); 19011vector unsigned int vec_vadduwm (vector bool int, vector unsigned int); 19012vector unsigned int vec_vadduwm (vector unsigned int, vector bool int); 19013vector unsigned int vec_vadduwm (vector unsigned int, vector unsigned int); 19014 19015vector unsigned int vec_vadduws (vector bool int, vector unsigned int); 19016vector unsigned int vec_vadduws (vector unsigned int, vector bool int); 19017vector unsigned int vec_vadduws (vector unsigned int, vector unsigned int); 19018 19019vector signed char vec_vavgsb (vector signed char, vector signed char); 19020 19021vector signed short vec_vavgsh (vector signed short, vector signed short); 19022 19023vector signed int vec_vavgsw (vector signed int, vector signed int); 19024 19025vector unsigned char vec_vavgub (vector unsigned char, vector unsigned char); 19026 19027vector unsigned short vec_vavguh (vector unsigned short, vector unsigned short); 19028 19029vector unsigned int vec_vavguw (vector unsigned int, vector unsigned int); 19030 19031vector float vec_vcfsx (vector signed int, const int); 19032 19033vector float vec_vcfux (vector unsigned int, const int); 19034 19035vector bool int vec_vcmpeqfp (vector float, vector float); 19036 19037vector bool char vec_vcmpequb (vector signed char, vector signed char); 19038vector bool char vec_vcmpequb (vector unsigned char, vector unsigned char); 19039 19040vector bool short vec_vcmpequh (vector signed short, vector signed short); 19041vector bool short vec_vcmpequh (vector unsigned short, vector unsigned short); 19042 19043vector bool int vec_vcmpequw (vector signed int, vector signed int); 19044vector bool int vec_vcmpequw (vector unsigned int, vector unsigned int); 19045 19046vector bool int vec_vcmpgtfp (vector float, vector float); 19047 19048vector bool char vec_vcmpgtsb (vector signed char, vector signed char); 19049 19050vector bool short vec_vcmpgtsh (vector signed short, vector signed short); 19051 19052vector bool int vec_vcmpgtsw (vector signed int, vector signed int); 19053 19054vector bool char vec_vcmpgtub (vector unsigned char, vector unsigned char); 19055 19056vector bool short vec_vcmpgtuh (vector unsigned short, vector unsigned short); 19057 19058vector bool int vec_vcmpgtuw (vector unsigned int, vector unsigned int); 19059 19060vector float vec_vmaxfp (vector float, vector float); 19061 19062vector signed char vec_vmaxsb (vector bool char, vector signed char); 19063vector signed char vec_vmaxsb (vector signed char, vector bool char); 19064vector signed char vec_vmaxsb (vector signed char, vector signed char); 19065 19066vector signed short vec_vmaxsh (vector bool short, vector signed short); 19067vector signed short vec_vmaxsh (vector signed short, vector bool short); 19068vector signed short vec_vmaxsh (vector signed short, vector signed short); 19069 19070vector signed int vec_vmaxsw (vector bool int, vector signed int); 19071vector signed int vec_vmaxsw (vector signed int, vector bool int); 19072vector signed int vec_vmaxsw (vector signed int, vector signed int); 19073 19074vector unsigned char vec_vmaxub (vector bool char, vector unsigned char); 19075vector unsigned char vec_vmaxub (vector unsigned char, vector bool char); 19076vector unsigned char vec_vmaxub (vector unsigned char, vector unsigned char); 19077 19078vector unsigned short vec_vmaxuh (vector bool short, vector unsigned short); 19079vector unsigned short vec_vmaxuh (vector unsigned short, vector bool short); 19080vector unsigned short vec_vmaxuh (vector unsigned short, vector unsigned short); 19081 19082vector unsigned int vec_vmaxuw (vector bool int, vector unsigned int); 19083vector unsigned int vec_vmaxuw (vector unsigned int, vector bool int); 19084vector unsigned int vec_vmaxuw (vector unsigned int, vector unsigned int); 19085 19086vector float vec_vminfp (vector float, vector float); 19087 19088vector signed char vec_vminsb (vector bool char, vector signed char); 19089vector signed char vec_vminsb (vector signed char, vector bool char); 19090vector signed char vec_vminsb (vector signed char, vector signed char); 19091 19092vector signed short vec_vminsh (vector bool short, vector signed short); 19093vector signed short vec_vminsh (vector signed short, vector bool short); 19094vector signed short vec_vminsh (vector signed short, vector signed short); 19095 19096vector signed int vec_vminsw (vector bool int, vector signed int); 19097vector signed int vec_vminsw (vector signed int, vector bool int); 19098vector signed int vec_vminsw (vector signed int, vector signed int); 19099 19100vector unsigned char vec_vminub (vector bool char, vector unsigned char); 19101vector unsigned char vec_vminub (vector unsigned char, vector bool char); 19102vector unsigned char vec_vminub (vector unsigned char, vector unsigned char); 19103 19104vector unsigned short vec_vminuh (vector bool short, vector unsigned short); 19105vector unsigned short vec_vminuh (vector unsigned short, vector bool short); 19106vector unsigned short vec_vminuh (vector unsigned short, vector unsigned short); 19107 19108vector unsigned int vec_vminuw (vector bool int, vector unsigned int); 19109vector unsigned int vec_vminuw (vector unsigned int, vector bool int); 19110vector unsigned int vec_vminuw (vector unsigned int, vector unsigned int); 19111 19112vector bool char vec_vmrghb (vector bool char, vector bool char); 19113vector signed char vec_vmrghb (vector signed char, vector signed char); 19114vector unsigned char vec_vmrghb (vector unsigned char, vector unsigned char); 19115 19116vector bool short vec_vmrghh (vector bool short, vector bool short); 19117vector signed short vec_vmrghh (vector signed short, vector signed short); 19118vector unsigned short vec_vmrghh (vector unsigned short, vector unsigned short); 19119vector pixel vec_vmrghh (vector pixel, vector pixel); 19120 19121vector float vec_vmrghw (vector float, vector float); 19122vector bool int vec_vmrghw (vector bool int, vector bool int); 19123vector signed int vec_vmrghw (vector signed int, vector signed int); 19124vector unsigned int vec_vmrghw (vector unsigned int, vector unsigned int); 19125 19126vector bool char vec_vmrglb (vector bool char, vector bool char); 19127vector signed char vec_vmrglb (vector signed char, vector signed char); 19128vector unsigned char vec_vmrglb (vector unsigned char, vector unsigned char); 19129 19130vector bool short vec_vmrglh (vector bool short, vector bool short); 19131vector signed short vec_vmrglh (vector signed short, vector signed short); 19132vector unsigned short vec_vmrglh (vector unsigned short, vector unsigned short); 19133vector pixel vec_vmrglh (vector pixel, vector pixel); 19134 19135vector float vec_vmrglw (vector float, vector float); 19136vector signed int vec_vmrglw (vector signed int, vector signed int); 19137vector unsigned int vec_vmrglw (vector unsigned int, vector unsigned int); 19138vector bool int vec_vmrglw (vector bool int, vector bool int); 19139 19140vector signed int vec_vmsummbm (vector signed char, vector unsigned char, 19141 vector signed int); 19142 19143vector signed int vec_vmsumshm (vector signed short, vector signed short, 19144 vector signed int); 19145 19146vector signed int vec_vmsumshs (vector signed short, vector signed short, 19147 vector signed int); 19148 19149vector unsigned int vec_vmsumubm (vector unsigned char, vector unsigned char, 19150 vector unsigned int); 19151 19152vector unsigned int vec_vmsumuhm (vector unsigned short, vector unsigned short, 19153 vector unsigned int); 19154 19155vector unsigned int vec_vmsumuhs (vector unsigned short, vector unsigned short, 19156 vector unsigned int); 19157 19158vector signed short vec_vmulesb (vector signed char, vector signed char); 19159 19160vector signed int vec_vmulesh (vector signed short, vector signed short); 19161 19162vector unsigned short vec_vmuleub (vector unsigned char, vector unsigned char); 19163 19164vector unsigned int vec_vmuleuh (vector unsigned short, vector unsigned short); 19165 19166vector signed short vec_vmulosb (vector signed char, vector signed char); 19167 19168vector signed int vec_vmulosh (vector signed short, vector signed short); 19169 19170vector unsigned short vec_vmuloub (vector unsigned char, vector unsigned char); 19171 19172vector unsigned int vec_vmulouh (vector unsigned short, vector unsigned short); 19173 19174vector signed char vec_vpkshss (vector signed short, vector signed short); 19175 19176vector unsigned char vec_vpkshus (vector signed short, vector signed short); 19177 19178vector signed short vec_vpkswss (vector signed int, vector signed int); 19179 19180vector unsigned short vec_vpkswus (vector signed int, vector signed int); 19181 19182vector bool char vec_vpkuhum (vector bool short, vector bool short); 19183vector signed char vec_vpkuhum (vector signed short, vector signed short); 19184vector unsigned char vec_vpkuhum (vector unsigned short, vector unsigned short); 19185 19186vector unsigned char vec_vpkuhus (vector unsigned short, vector unsigned short); 19187 19188vector bool short vec_vpkuwum (vector bool int, vector bool int); 19189vector signed short vec_vpkuwum (vector signed int, vector signed int); 19190vector unsigned short vec_vpkuwum (vector unsigned int, vector unsigned int); 19191 19192vector unsigned short vec_vpkuwus (vector unsigned int, vector unsigned int); 19193 19194vector signed char vec_vrlb (vector signed char, vector unsigned char); 19195vector unsigned char vec_vrlb (vector unsigned char, vector unsigned char); 19196 19197vector signed short vec_vrlh (vector signed short, vector unsigned short); 19198vector unsigned short vec_vrlh (vector unsigned short, vector unsigned short); 19199 19200vector signed int vec_vrlw (vector signed int, vector unsigned int); 19201vector unsigned int vec_vrlw (vector unsigned int, vector unsigned int); 19202 19203vector signed char vec_vslb (vector signed char, vector unsigned char); 19204vector unsigned char vec_vslb (vector unsigned char, vector unsigned char); 19205 19206vector signed short vec_vslh (vector signed short, vector unsigned short); 19207vector unsigned short vec_vslh (vector unsigned short, vector unsigned short); 19208 19209vector signed int vec_vslw (vector signed int, vector unsigned int); 19210vector unsigned int vec_vslw (vector unsigned int, vector unsigned int); 19211 19212vector signed char vec_vspltb (vector signed char, const int); 19213vector unsigned char vec_vspltb (vector unsigned char, const int); 19214vector bool char vec_vspltb (vector bool char, const int); 19215 19216vector bool short vec_vsplth (vector bool short, const int); 19217vector signed short vec_vsplth (vector signed short, const int); 19218vector unsigned short vec_vsplth (vector unsigned short, const int); 19219vector pixel vec_vsplth (vector pixel, const int); 19220 19221vector float vec_vspltw (vector float, const int); 19222vector signed int vec_vspltw (vector signed int, const int); 19223vector unsigned int vec_vspltw (vector unsigned int, const int); 19224vector bool int vec_vspltw (vector bool int, const int); 19225 19226vector signed char vec_vsrab (vector signed char, vector unsigned char); 19227vector unsigned char vec_vsrab (vector unsigned char, vector unsigned char); 19228 19229vector signed short vec_vsrah (vector signed short, vector unsigned short); 19230vector unsigned short vec_vsrah (vector unsigned short, vector unsigned short); 19231 19232vector signed int vec_vsraw (vector signed int, vector unsigned int); 19233vector unsigned int vec_vsraw (vector unsigned int, vector unsigned int); 19234 19235vector signed char vec_vsrb (vector signed char, vector unsigned char); 19236vector unsigned char vec_vsrb (vector unsigned char, vector unsigned char); 19237 19238vector signed short vec_vsrh (vector signed short, vector unsigned short); 19239vector unsigned short vec_vsrh (vector unsigned short, vector unsigned short); 19240 19241vector signed int vec_vsrw (vector signed int, vector unsigned int); 19242vector unsigned int vec_vsrw (vector unsigned int, vector unsigned int); 19243 19244vector float vec_vsubfp (vector float, vector float); 19245 19246vector signed char vec_vsubsbs (vector bool char, vector signed char); 19247vector signed char vec_vsubsbs (vector signed char, vector bool char); 19248vector signed char vec_vsubsbs (vector signed char, vector signed char); 19249 19250vector signed short vec_vsubshs (vector bool short, vector signed short); 19251vector signed short vec_vsubshs (vector signed short, vector bool short); 19252vector signed short vec_vsubshs (vector signed short, vector signed short); 19253 19254vector signed int vec_vsubsws (vector bool int, vector signed int); 19255vector signed int vec_vsubsws (vector signed int, vector bool int); 19256vector signed int vec_vsubsws (vector signed int, vector signed int); 19257 19258vector signed char vec_vsububm (vector bool char, vector signed char); 19259vector signed char vec_vsububm (vector signed char, vector bool char); 19260vector signed char vec_vsububm (vector signed char, vector signed char); 19261vector unsigned char vec_vsububm (vector bool char, vector unsigned char); 19262vector unsigned char vec_vsububm (vector unsigned char, vector bool char); 19263vector unsigned char vec_vsububm (vector unsigned char, vector unsigned char); 19264 19265vector unsigned char vec_vsububs (vector bool char, vector unsigned char); 19266vector unsigned char vec_vsububs (vector unsigned char, vector bool char); 19267vector unsigned char vec_vsububs (vector unsigned char, vector unsigned char); 19268 19269vector signed short vec_vsubuhm (vector bool short, vector signed short); 19270vector signed short vec_vsubuhm (vector signed short, vector bool short); 19271vector signed short vec_vsubuhm (vector signed short, vector signed short); 19272vector unsigned short vec_vsubuhm (vector bool short, vector unsigned short); 19273vector unsigned short vec_vsubuhm (vector unsigned short, vector bool short); 19274vector unsigned short vec_vsubuhm (vector unsigned short, vector unsigned short); 19275 19276vector unsigned short vec_vsubuhs (vector bool short, vector unsigned short); 19277vector unsigned short vec_vsubuhs (vector unsigned short, vector bool short); 19278vector unsigned short vec_vsubuhs (vector unsigned short, vector unsigned short); 19279 19280vector signed int vec_vsubuwm (vector bool int, vector signed int); 19281vector signed int vec_vsubuwm (vector signed int, vector bool int); 19282vector signed int vec_vsubuwm (vector signed int, vector signed int); 19283vector unsigned int vec_vsubuwm (vector bool int, vector unsigned int); 19284vector unsigned int vec_vsubuwm (vector unsigned int, vector bool int); 19285vector unsigned int vec_vsubuwm (vector unsigned int, vector unsigned int); 19286 19287vector unsigned int vec_vsubuws (vector bool int, vector unsigned int); 19288vector unsigned int vec_vsubuws (vector unsigned int, vector bool int); 19289vector unsigned int vec_vsubuws (vector unsigned int, vector unsigned int); 19290 19291vector signed int vec_vsum4sbs (vector signed char, vector signed int); 19292 19293vector signed int vec_vsum4shs (vector signed short, vector signed int); 19294 19295vector unsigned int vec_vsum4ubs (vector unsigned char, vector unsigned int); 19296 19297vector unsigned int vec_vupkhpx (vector pixel); 19298 19299vector bool short vec_vupkhsb (vector bool char); 19300vector signed short vec_vupkhsb (vector signed char); 19301 19302vector bool int vec_vupkhsh (vector bool short); 19303vector signed int vec_vupkhsh (vector signed short); 19304 19305vector unsigned int vec_vupklpx (vector pixel); 19306 19307vector bool short vec_vupklsb (vector bool char); 19308vector signed short vec_vupklsb (vector signed char); 19309 19310vector bool int vec_vupklsh (vector bool short); 19311vector signed int vec_vupklsh (vector signed short); 19312@end smallexample 19313 19314@node PowerPC AltiVec Built-in Functions Available on ISA 2.06 19315@subsubsection PowerPC AltiVec Built-in Functions Available on ISA 2.06 19316 19317The AltiVec built-in functions described in this section are 19318available on the PowerPC family of processors starting with ISA 2.06 19319or later. These are normally enabled by adding @option{-mvsx} to the 19320command line. 19321 19322When @option{-mvsx} is used, the following additional vector types are 19323implemented. 19324 19325@smallexample 19326vector unsigned __int128 19327vector signed __int128 19328vector unsigned long long int 19329vector signed long long int 19330vector double 19331@end smallexample 19332 19333The long long types are only implemented for 64-bit code generation. 19334 19335Only functions excluded from the PVIPR are listed here. 19336 19337@smallexample 19338void vec_dst (const unsigned long *, int, const int); 19339void vec_dst (const long *, int, const int); 19340 19341void vec_dststt (const unsigned long *, int, const int); 19342void vec_dststt (const long *, int, const int); 19343 19344void vec_dstt (const unsigned long *, int, const int); 19345void vec_dstt (const long *, int, const int); 19346 19347vector unsigned char vec_lvsl (int, const unsigned long *); 19348vector unsigned char vec_lvsl (int, const long *); 19349 19350vector unsigned char vec_lvsr (int, const unsigned long *); 19351vector unsigned char vec_lvsr (int, const long *); 19352 19353vector unsigned char vec_lvsl (int, const double *); 19354vector unsigned char vec_lvsr (int, const double *); 19355 19356vector double vec_vsx_ld (int, const vector double *); 19357vector double vec_vsx_ld (int, const double *); 19358vector float vec_vsx_ld (int, const vector float *); 19359vector float vec_vsx_ld (int, const float *); 19360vector bool int vec_vsx_ld (int, const vector bool int *); 19361vector signed int vec_vsx_ld (int, const vector signed int *); 19362vector signed int vec_vsx_ld (int, const int *); 19363vector signed int vec_vsx_ld (int, const long *); 19364vector unsigned int vec_vsx_ld (int, const vector unsigned int *); 19365vector unsigned int vec_vsx_ld (int, const unsigned int *); 19366vector unsigned int vec_vsx_ld (int, const unsigned long *); 19367vector bool short vec_vsx_ld (int, const vector bool short *); 19368vector pixel vec_vsx_ld (int, const vector pixel *); 19369vector signed short vec_vsx_ld (int, const vector signed short *); 19370vector signed short vec_vsx_ld (int, const short *); 19371vector unsigned short vec_vsx_ld (int, const vector unsigned short *); 19372vector unsigned short vec_vsx_ld (int, const unsigned short *); 19373vector bool char vec_vsx_ld (int, const vector bool char *); 19374vector signed char vec_vsx_ld (int, const vector signed char *); 19375vector signed char vec_vsx_ld (int, const signed char *); 19376vector unsigned char vec_vsx_ld (int, const vector unsigned char *); 19377vector unsigned char vec_vsx_ld (int, const unsigned char *); 19378 19379void vec_vsx_st (vector double, int, vector double *); 19380void vec_vsx_st (vector double, int, double *); 19381void vec_vsx_st (vector float, int, vector float *); 19382void vec_vsx_st (vector float, int, float *); 19383void vec_vsx_st (vector signed int, int, vector signed int *); 19384void vec_vsx_st (vector signed int, int, int *); 19385void vec_vsx_st (vector unsigned int, int, vector unsigned int *); 19386void vec_vsx_st (vector unsigned int, int, unsigned int *); 19387void vec_vsx_st (vector bool int, int, vector bool int *); 19388void vec_vsx_st (vector bool int, int, unsigned int *); 19389void vec_vsx_st (vector bool int, int, int *); 19390void vec_vsx_st (vector signed short, int, vector signed short *); 19391void vec_vsx_st (vector signed short, int, short *); 19392void vec_vsx_st (vector unsigned short, int, vector unsigned short *); 19393void vec_vsx_st (vector unsigned short, int, unsigned short *); 19394void vec_vsx_st (vector bool short, int, vector bool short *); 19395void vec_vsx_st (vector bool short, int, unsigned short *); 19396void vec_vsx_st (vector pixel, int, vector pixel *); 19397void vec_vsx_st (vector pixel, int, unsigned short *); 19398void vec_vsx_st (vector pixel, int, short *); 19399void vec_vsx_st (vector bool short, int, short *); 19400void vec_vsx_st (vector signed char, int, vector signed char *); 19401void vec_vsx_st (vector signed char, int, signed char *); 19402void vec_vsx_st (vector unsigned char, int, vector unsigned char *); 19403void vec_vsx_st (vector unsigned char, int, unsigned char *); 19404void vec_vsx_st (vector bool char, int, vector bool char *); 19405void vec_vsx_st (vector bool char, int, unsigned char *); 19406void vec_vsx_st (vector bool char, int, signed char *); 19407 19408vector double vec_xxpermdi (vector double, vector double, const int); 19409vector float vec_xxpermdi (vector float, vector float, const int); 19410vector long long vec_xxpermdi (vector long long, vector long long, const int); 19411vector unsigned long long vec_xxpermdi (vector unsigned long long, 19412 vector unsigned long long, const int); 19413vector int vec_xxpermdi (vector int, vector int, const int); 19414vector unsigned int vec_xxpermdi (vector unsigned int, 19415 vector unsigned int, const int); 19416vector short vec_xxpermdi (vector short, vector short, const int); 19417vector unsigned short vec_xxpermdi (vector unsigned short, 19418 vector unsigned short, const int); 19419vector signed char vec_xxpermdi (vector signed char, vector signed char, 19420 const int); 19421vector unsigned char vec_xxpermdi (vector unsigned char, 19422 vector unsigned char, const int); 19423 19424vector double vec_xxsldi (vector double, vector double, int); 19425vector float vec_xxsldi (vector float, vector float, int); 19426vector long long vec_xxsldi (vector long long, vector long long, int); 19427vector unsigned long long vec_xxsldi (vector unsigned long long, 19428 vector unsigned long long, int); 19429vector int vec_xxsldi (vector int, vector int, int); 19430vector unsigned int vec_xxsldi (vector unsigned int, vector unsigned int, int); 19431vector short vec_xxsldi (vector short, vector short, int); 19432vector unsigned short vec_xxsldi (vector unsigned short, 19433 vector unsigned short, int); 19434vector signed char vec_xxsldi (vector signed char, vector signed char, int); 19435vector unsigned char vec_xxsldi (vector unsigned char, 19436 vector unsigned char, int); 19437@end smallexample 19438 19439Note that the @samp{vec_ld} and @samp{vec_st} built-in functions always 19440generate the AltiVec @samp{LVX} and @samp{STVX} instructions even 19441if the VSX instruction set is available. The @samp{vec_vsx_ld} and 19442@samp{vec_vsx_st} built-in functions always generate the VSX @samp{LXVD2X}, 19443@samp{LXVW4X}, @samp{STXVD2X}, and @samp{STXVW4X} instructions. 19444 19445@node PowerPC AltiVec Built-in Functions Available on ISA 2.07 19446@subsubsection PowerPC AltiVec Built-in Functions Available on ISA 2.07 19447 19448If the ISA 2.07 additions to the vector/scalar (power8-vector) 19449instruction set are available, the following additional functions are 19450available for both 32-bit and 64-bit targets. For 64-bit targets, you 19451can use @var{vector long} instead of @var{vector long long}, 19452@var{vector bool long} instead of @var{vector bool long long}, and 19453@var{vector unsigned long} instead of @var{vector unsigned long long}. 19454 19455Only functions excluded from the PVIPR are listed here. 19456 19457@smallexample 19458vector long long vec_vaddudm (vector long long, vector long long); 19459vector long long vec_vaddudm (vector bool long long, vector long long); 19460vector long long vec_vaddudm (vector long long, vector bool long long); 19461vector unsigned long long vec_vaddudm (vector unsigned long long, 19462 vector unsigned long long); 19463vector unsigned long long vec_vaddudm (vector bool unsigned long long, 19464 vector unsigned long long); 19465vector unsigned long long vec_vaddudm (vector unsigned long long, 19466 vector bool unsigned long long); 19467 19468vector long long vec_vclz (vector long long); 19469vector unsigned long long vec_vclz (vector unsigned long long); 19470vector int vec_vclz (vector int); 19471vector unsigned int vec_vclz (vector int); 19472vector short vec_vclz (vector short); 19473vector unsigned short vec_vclz (vector unsigned short); 19474vector signed char vec_vclz (vector signed char); 19475vector unsigned char vec_vclz (vector unsigned char); 19476 19477vector signed char vec_vclzb (vector signed char); 19478vector unsigned char vec_vclzb (vector unsigned char); 19479 19480vector long long vec_vclzd (vector long long); 19481vector unsigned long long vec_vclzd (vector unsigned long long); 19482 19483vector short vec_vclzh (vector short); 19484vector unsigned short vec_vclzh (vector unsigned short); 19485 19486vector int vec_vclzw (vector int); 19487vector unsigned int vec_vclzw (vector int); 19488 19489vector signed char vec_vgbbd (vector signed char); 19490vector unsigned char vec_vgbbd (vector unsigned char); 19491 19492vector long long vec_vmaxsd (vector long long, vector long long); 19493 19494vector unsigned long long vec_vmaxud (vector unsigned long long, 19495 unsigned vector long long); 19496 19497vector long long vec_vminsd (vector long long, vector long long); 19498 19499vector unsigned long long vec_vminud (vector long long, vector long long); 19500 19501vector int vec_vpksdss (vector long long, vector long long); 19502vector unsigned int vec_vpksdss (vector long long, vector long long); 19503 19504vector unsigned int vec_vpkudus (vector unsigned long long, 19505 vector unsigned long long); 19506 19507vector int vec_vpkudum (vector long long, vector long long); 19508vector unsigned int vec_vpkudum (vector unsigned long long, 19509 vector unsigned long long); 19510vector bool int vec_vpkudum (vector bool long long, vector bool long long); 19511 19512vector long long vec_vpopcnt (vector long long); 19513vector unsigned long long vec_vpopcnt (vector unsigned long long); 19514vector int vec_vpopcnt (vector int); 19515vector unsigned int vec_vpopcnt (vector int); 19516vector short vec_vpopcnt (vector short); 19517vector unsigned short vec_vpopcnt (vector unsigned short); 19518vector signed char vec_vpopcnt (vector signed char); 19519vector unsigned char vec_vpopcnt (vector unsigned char); 19520 19521vector signed char vec_vpopcntb (vector signed char); 19522vector unsigned char vec_vpopcntb (vector unsigned char); 19523 19524vector long long vec_vpopcntd (vector long long); 19525vector unsigned long long vec_vpopcntd (vector unsigned long long); 19526 19527vector short vec_vpopcnth (vector short); 19528vector unsigned short vec_vpopcnth (vector unsigned short); 19529 19530vector int vec_vpopcntw (vector int); 19531vector unsigned int vec_vpopcntw (vector int); 19532 19533vector long long vec_vrld (vector long long, vector unsigned long long); 19534vector unsigned long long vec_vrld (vector unsigned long long, 19535 vector unsigned long long); 19536 19537vector long long vec_vsld (vector long long, vector unsigned long long); 19538vector long long vec_vsld (vector unsigned long long, 19539 vector unsigned long long); 19540 19541vector long long vec_vsrad (vector long long, vector unsigned long long); 19542vector unsigned long long vec_vsrad (vector unsigned long long, 19543 vector unsigned long long); 19544 19545vector long long vec_vsrd (vector long long, vector unsigned long long); 19546vector unsigned long long char vec_vsrd (vector unsigned long long, 19547 vector unsigned long long); 19548 19549vector long long vec_vsubudm (vector long long, vector long long); 19550vector long long vec_vsubudm (vector bool long long, vector long long); 19551vector long long vec_vsubudm (vector long long, vector bool long long); 19552vector unsigned long long vec_vsubudm (vector unsigned long long, 19553 vector unsigned long long); 19554vector unsigned long long vec_vsubudm (vector bool long long, 19555 vector unsigned long long); 19556vector unsigned long long vec_vsubudm (vector unsigned long long, 19557 vector bool long long); 19558 19559vector long long vec_vupkhsw (vector int); 19560vector unsigned long long vec_vupkhsw (vector unsigned int); 19561 19562vector long long vec_vupklsw (vector int); 19563vector unsigned long long vec_vupklsw (vector int); 19564@end smallexample 19565 19566If the ISA 2.07 additions to the vector/scalar (power8-vector) 19567instruction set are available, the following additional functions are 19568available for 64-bit targets. New vector types 19569(@var{vector __int128} and @var{vector __uint128}) are available 19570to hold the @var{__int128} and @var{__uint128} types to use these 19571builtins. 19572 19573The normal vector extract, and set operations work on 19574@var{vector __int128} and @var{vector __uint128} types, 19575but the index value must be 0. 19576 19577Only functions excluded from the PVIPR are listed here. 19578 19579@smallexample 19580vector __int128 vec_vaddcuq (vector __int128, vector __int128); 19581vector __uint128 vec_vaddcuq (vector __uint128, vector __uint128); 19582 19583vector __int128 vec_vadduqm (vector __int128, vector __int128); 19584vector __uint128 vec_vadduqm (vector __uint128, vector __uint128); 19585 19586vector __int128 vec_vaddecuq (vector __int128, vector __int128, 19587 vector __int128); 19588vector __uint128 vec_vaddecuq (vector __uint128, vector __uint128, 19589 vector __uint128); 19590 19591vector __int128 vec_vaddeuqm (vector __int128, vector __int128, 19592 vector __int128); 19593vector __uint128 vec_vaddeuqm (vector __uint128, vector __uint128, 19594 vector __uint128); 19595 19596vector __int128 vec_vsubecuq (vector __int128, vector __int128, 19597 vector __int128); 19598vector __uint128 vec_vsubecuq (vector __uint128, vector __uint128, 19599 vector __uint128); 19600 19601vector __int128 vec_vsubeuqm (vector __int128, vector __int128, 19602 vector __int128); 19603vector __uint128 vec_vsubeuqm (vector __uint128, vector __uint128, 19604 vector __uint128); 19605 19606vector __int128 vec_vsubcuq (vector __int128, vector __int128); 19607vector __uint128 vec_vsubcuq (vector __uint128, vector __uint128); 19608 19609__int128 vec_vsubuqm (__int128, __int128); 19610__uint128 vec_vsubuqm (__uint128, __uint128); 19611 19612vector __int128 __builtin_bcdadd (vector __int128, vector __int128, const int); 19613vector unsigned char __builtin_bcdadd (vector unsigned char, vector unsigned char, 19614 const int); 19615int __builtin_bcdadd_lt (vector __int128, vector __int128, const int); 19616int __builtin_bcdadd_lt (vector unsigned char, vector unsigned char, const int); 19617int __builtin_bcdadd_eq (vector __int128, vector __int128, const int); 19618int __builtin_bcdadd_eq (vector unsigned char, vector unsigned char, const int); 19619int __builtin_bcdadd_gt (vector __int128, vector __int128, const int); 19620int __builtin_bcdadd_gt (vector unsigned char, vector unsigned char, const int); 19621int __builtin_bcdadd_ov (vector __int128, vector __int128, const int); 19622int __builtin_bcdadd_ov (vector unsigned char, vector unsigned char, const int); 19623 19624vector __int128 __builtin_bcdsub (vector __int128, vector __int128, const int); 19625vector unsigned char __builtin_bcdsub (vector unsigned char, vector unsigned char, 19626 const int); 19627int __builtin_bcdsub_lt (vector __int128, vector __int128, const int); 19628int __builtin_bcdsub_lt (vector unsigned char, vector unsigned char, const int); 19629int __builtin_bcdsub_eq (vector __int128, vector __int128, const int); 19630int __builtin_bcdsub_eq (vector unsigned char, vector unsigned char, const int); 19631int __builtin_bcdsub_gt (vector __int128, vector __int128, const int); 19632int __builtin_bcdsub_gt (vector unsigned char, vector unsigned char, const int); 19633int __builtin_bcdsub_ov (vector __int128, vector __int128, const int); 19634int __builtin_bcdsub_ov (vector unsigned char, vector unsigned char, const int); 19635@end smallexample 19636 19637@node PowerPC AltiVec Built-in Functions Available on ISA 3.0 19638@subsubsection PowerPC AltiVec Built-in Functions Available on ISA 3.0 19639 19640The following additional built-in functions are also available for the 19641PowerPC family of processors, starting with ISA 3.0 19642(@option{-mcpu=power9}) or later. 19643 19644Only instructions excluded from the PVIPR are listed here. 19645 19646@smallexample 19647unsigned int scalar_extract_exp (double source); 19648unsigned long long int scalar_extract_exp (__ieee128 source); 19649 19650unsigned long long int scalar_extract_sig (double source); 19651unsigned __int128 scalar_extract_sig (__ieee128 source); 19652 19653double scalar_insert_exp (unsigned long long int significand, 19654 unsigned long long int exponent); 19655double scalar_insert_exp (double significand, unsigned long long int exponent); 19656 19657ieee_128 scalar_insert_exp (unsigned __int128 significand, 19658 unsigned long long int exponent); 19659ieee_128 scalar_insert_exp (ieee_128 significand, unsigned long long int exponent); 19660 19661int scalar_cmp_exp_gt (double arg1, double arg2); 19662int scalar_cmp_exp_lt (double arg1, double arg2); 19663int scalar_cmp_exp_eq (double arg1, double arg2); 19664int scalar_cmp_exp_unordered (double arg1, double arg2); 19665 19666bool scalar_test_data_class (float source, const int condition); 19667bool scalar_test_data_class (double source, const int condition); 19668bool scalar_test_data_class (__ieee128 source, const int condition); 19669 19670bool scalar_test_neg (float source); 19671bool scalar_test_neg (double source); 19672bool scalar_test_neg (__ieee128 source); 19673@end smallexample 19674 19675The @code{scalar_extract_exp} and @code{scalar_extract_sig} 19676functions require a 64-bit environment supporting ISA 3.0 or later. 19677The @code{scalar_extract_exp} and @code{scalar_extract_sig} built-in 19678functions return the significand and the biased exponent value 19679respectively of their @code{source} arguments. 19680When supplied with a 64-bit @code{source} argument, the 19681result returned by @code{scalar_extract_sig} has 19682the @code{0x0010000000000000} bit set if the 19683function's @code{source} argument is in normalized form. 19684Otherwise, this bit is set to 0. 19685When supplied with a 128-bit @code{source} argument, the 19686@code{0x00010000000000000000000000000000} bit of the result is 19687treated similarly. 19688Note that the sign of the significand is not represented in the result 19689returned from the @code{scalar_extract_sig} function. Use the 19690@code{scalar_test_neg} function to test the sign of its @code{double} 19691argument. 19692 19693The @code{scalar_insert_exp} 19694functions require a 64-bit environment supporting ISA 3.0 or later. 19695When supplied with a 64-bit first argument, the 19696@code{scalar_insert_exp} built-in function returns a double-precision 19697floating point value that is constructed by assembling the values of its 19698@code{significand} and @code{exponent} arguments. The sign of the 19699result is copied from the most significant bit of the 19700@code{significand} argument. The significand and exponent components 19701of the result are composed of the least significant 11 bits of the 19702@code{exponent} argument and the least significant 52 bits of the 19703@code{significand} argument respectively. 19704 19705When supplied with a 128-bit first argument, the 19706@code{scalar_insert_exp} built-in function returns a quad-precision 19707ieee floating point value. The sign bit of the result is copied from 19708the most significant bit of the @code{significand} argument. 19709The significand and exponent components of the result are composed of 19710the least significant 15 bits of the @code{exponent} argument and the 19711least significant 112 bits of the @code{significand} argument respectively. 19712 19713The @code{scalar_cmp_exp_gt}, @code{scalar_cmp_exp_lt}, 19714@code{scalar_cmp_exp_eq}, and @code{scalar_cmp_exp_unordered} built-in 19715functions return a non-zero value if @code{arg1} is greater than, less 19716than, equal to, or not comparable to @code{arg2} respectively. The 19717arguments are not comparable if one or the other equals NaN (not a 19718number). 19719 19720The @code{scalar_test_data_class} built-in function returns 1 19721if any of the condition tests enabled by the value of the 19722@code{condition} variable are true, and 0 otherwise. The 19723@code{condition} argument must be a compile-time constant integer with 19724value not exceeding 127. The 19725@code{condition} argument is encoded as a bitmask with each bit 19726enabling the testing of a different condition, as characterized by the 19727following: 19728@smallexample 197290x40 Test for NaN 197300x20 Test for +Infinity 197310x10 Test for -Infinity 197320x08 Test for +Zero 197330x04 Test for -Zero 197340x02 Test for +Denormal 197350x01 Test for -Denormal 19736@end smallexample 19737 19738The @code{scalar_test_neg} built-in function returns 1 if its 19739@code{source} argument holds a negative value, 0 otherwise. 19740 19741The following built-in functions are also available for the PowerPC family 19742of processors, starting with ISA 3.0 or later 19743(@option{-mcpu=power9}). These string functions are described 19744separately in order to group the descriptions closer to the function 19745prototypes. 19746 19747Only functions excluded from the PVIPR are listed here. 19748 19749@smallexample 19750int vec_all_nez (vector signed char, vector signed char); 19751int vec_all_nez (vector unsigned char, vector unsigned char); 19752int vec_all_nez (vector signed short, vector signed short); 19753int vec_all_nez (vector unsigned short, vector unsigned short); 19754int vec_all_nez (vector signed int, vector signed int); 19755int vec_all_nez (vector unsigned int, vector unsigned int); 19756 19757int vec_any_eqz (vector signed char, vector signed char); 19758int vec_any_eqz (vector unsigned char, vector unsigned char); 19759int vec_any_eqz (vector signed short, vector signed short); 19760int vec_any_eqz (vector unsigned short, vector unsigned short); 19761int vec_any_eqz (vector signed int, vector signed int); 19762int vec_any_eqz (vector unsigned int, vector unsigned int); 19763 19764signed char vec_xlx (unsigned int index, vector signed char data); 19765unsigned char vec_xlx (unsigned int index, vector unsigned char data); 19766signed short vec_xlx (unsigned int index, vector signed short data); 19767unsigned short vec_xlx (unsigned int index, vector unsigned short data); 19768signed int vec_xlx (unsigned int index, vector signed int data); 19769unsigned int vec_xlx (unsigned int index, vector unsigned int data); 19770float vec_xlx (unsigned int index, vector float data); 19771 19772signed char vec_xrx (unsigned int index, vector signed char data); 19773unsigned char vec_xrx (unsigned int index, vector unsigned char data); 19774signed short vec_xrx (unsigned int index, vector signed short data); 19775unsigned short vec_xrx (unsigned int index, vector unsigned short data); 19776signed int vec_xrx (unsigned int index, vector signed int data); 19777unsigned int vec_xrx (unsigned int index, vector unsigned int data); 19778float vec_xrx (unsigned int index, vector float data); 19779@end smallexample 19780 19781The @code{vec_all_nez}, @code{vec_any_eqz}, and @code{vec_cmpnez} 19782perform pairwise comparisons between the elements at the same 19783positions within their two vector arguments. 19784The @code{vec_all_nez} function returns a 19785non-zero value if and only if all pairwise comparisons are not 19786equal and no element of either vector argument contains a zero. 19787The @code{vec_any_eqz} function returns a 19788non-zero value if and only if at least one pairwise comparison is equal 19789or if at least one element of either vector argument contains a zero. 19790The @code{vec_cmpnez} function returns a vector of the same type as 19791its two arguments, within which each element consists of all ones to 19792denote that either the corresponding elements of the incoming arguments are 19793not equal or that at least one of the corresponding elements contains 19794zero. Otherwise, the element of the returned vector contains all zeros. 19795 19796The @code{vec_xlx} and @code{vec_xrx} functions extract the single 19797element selected by the @code{index} argument from the vector 19798represented by the @code{data} argument. The @code{index} argument 19799always specifies a byte offset, regardless of the size of the vector 19800element. With @code{vec_xlx}, @code{index} is the offset of the first 19801byte of the element to be extracted. With @code{vec_xrx}, @code{index} 19802represents the last byte of the element to be extracted, measured 19803from the right end of the vector. In other words, the last byte of 19804the element to be extracted is found at position @code{(15 - index)}. 19805There is no requirement that @code{index} be a multiple of the vector 19806element size. However, if the size of the vector element added to 19807@code{index} is greater than 15, the content of the returned value is 19808undefined. 19809 19810The following functions are also available if the ISA 3.0 instruction 19811set additions (@option{-mcpu=power9}) are available. 19812 19813Only functions excluded from the PVIPR are listed here. 19814 19815@smallexample 19816vector long long vec_vctz (vector long long); 19817vector unsigned long long vec_vctz (vector unsigned long long); 19818vector int vec_vctz (vector int); 19819vector unsigned int vec_vctz (vector int); 19820vector short vec_vctz (vector short); 19821vector unsigned short vec_vctz (vector unsigned short); 19822vector signed char vec_vctz (vector signed char); 19823vector unsigned char vec_vctz (vector unsigned char); 19824 19825vector signed char vec_vctzb (vector signed char); 19826vector unsigned char vec_vctzb (vector unsigned char); 19827 19828vector long long vec_vctzd (vector long long); 19829vector unsigned long long vec_vctzd (vector unsigned long long); 19830 19831vector short vec_vctzh (vector short); 19832vector unsigned short vec_vctzh (vector unsigned short); 19833 19834vector int vec_vctzw (vector int); 19835vector unsigned int vec_vctzw (vector int); 19836 19837vector int vec_vprtyb (vector int); 19838vector unsigned int vec_vprtyb (vector unsigned int); 19839vector long long vec_vprtyb (vector long long); 19840vector unsigned long long vec_vprtyb (vector unsigned long long); 19841 19842vector int vec_vprtybw (vector int); 19843vector unsigned int vec_vprtybw (vector unsigned int); 19844 19845vector long long vec_vprtybd (vector long long); 19846vector unsigned long long vec_vprtybd (vector unsigned long long); 19847@end smallexample 19848 19849On 64-bit targets, if the ISA 3.0 additions (@option{-mcpu=power9}) 19850are available: 19851 19852@smallexample 19853vector long vec_vprtyb (vector long); 19854vector unsigned long vec_vprtyb (vector unsigned long); 19855vector __int128 vec_vprtyb (vector __int128); 19856vector __uint128 vec_vprtyb (vector __uint128); 19857 19858vector long vec_vprtybd (vector long); 19859vector unsigned long vec_vprtybd (vector unsigned long); 19860 19861vector __int128 vec_vprtybq (vector __int128); 19862vector __uint128 vec_vprtybd (vector __uint128); 19863@end smallexample 19864 19865The following built-in functions are available for the PowerPC family 19866of processors, starting with ISA 3.0 or later (@option{-mcpu=power9}). 19867 19868Only functions excluded from the PVIPR are listed here. 19869 19870@smallexample 19871__vector unsigned char 19872vec_absdb (__vector unsigned char arg1, __vector unsigned char arg2); 19873__vector unsigned short 19874vec_absdh (__vector unsigned short arg1, __vector unsigned short arg2); 19875__vector unsigned int 19876vec_absdw (__vector unsigned int arg1, __vector unsigned int arg2); 19877@end smallexample 19878 19879The @code{vec_absd}, @code{vec_absdb}, @code{vec_absdh}, and 19880@code{vec_absdw} built-in functions each computes the absolute 19881differences of the pairs of vector elements supplied in its two vector 19882arguments, placing the absolute differences into the corresponding 19883elements of the vector result. 19884 19885The following built-in functions are available for the PowerPC family 19886of processors, starting with ISA 3.0 or later (@option{-mcpu=power9}): 19887@smallexample 19888vector unsigned int vec_vrlnm (vector unsigned int, vector unsigned int); 19889vector unsigned long long vec_vrlnm (vector unsigned long long, 19890 vector unsigned long long); 19891@end smallexample 19892 19893The result of @code{vec_vrlnm} is obtained by rotating each element 19894of the first argument vector left and ANDing it with a mask. The 19895second argument vector contains the mask beginning in bits 11:15, 19896the mask end in bits 19:23, and the shift count in bits 27:31, 19897of each element. 19898 19899If the cryptographic instructions are enabled (@option{-mcrypto} or 19900@option{-mcpu=power8}), the following builtins are enabled. 19901 19902Only functions excluded from the PVIPR are listed here. 19903 19904@smallexample 19905vector unsigned long long __builtin_crypto_vsbox (vector unsigned long long); 19906 19907vector unsigned long long __builtin_crypto_vcipher (vector unsigned long long, 19908 vector unsigned long long); 19909 19910vector unsigned long long __builtin_crypto_vcipherlast 19911 (vector unsigned long long, 19912 vector unsigned long long); 19913 19914vector unsigned long long __builtin_crypto_vncipher (vector unsigned long long, 19915 vector unsigned long long); 19916 19917vector unsigned long long __builtin_crypto_vncipherlast (vector unsigned long long, 19918 vector unsigned long long); 19919 19920vector unsigned char __builtin_crypto_vpermxor (vector unsigned char, 19921 vector unsigned char, 19922 vector unsigned char); 19923 19924vector unsigned short __builtin_crypto_vpermxor (vector unsigned short, 19925 vector unsigned short, 19926 vector unsigned short); 19927 19928vector unsigned int __builtin_crypto_vpermxor (vector unsigned int, 19929 vector unsigned int, 19930 vector unsigned int); 19931 19932vector unsigned long long __builtin_crypto_vpermxor (vector unsigned long long, 19933 vector unsigned long long, 19934 vector unsigned long long); 19935 19936vector unsigned char __builtin_crypto_vpmsumb (vector unsigned char, 19937 vector unsigned char); 19938 19939vector unsigned short __builtin_crypto_vpmsumh (vector unsigned short, 19940 vector unsigned short); 19941 19942vector unsigned int __builtin_crypto_vpmsumw (vector unsigned int, 19943 vector unsigned int); 19944 19945vector unsigned long long __builtin_crypto_vpmsumd (vector unsigned long long, 19946 vector unsigned long long); 19947 19948vector unsigned long long __builtin_crypto_vshasigmad (vector unsigned long long, 19949 int, int); 19950 19951vector unsigned int __builtin_crypto_vshasigmaw (vector unsigned int, int, int); 19952@end smallexample 19953 19954The second argument to @var{__builtin_crypto_vshasigmad} and 19955@var{__builtin_crypto_vshasigmaw} must be a constant 19956integer that is 0 or 1. The third argument to these built-in functions 19957must be a constant integer in the range of 0 to 15. 19958 19959The following sign extension builtins are provided: 19960 19961@smallexample 19962vector signed int vec_signexti (vector signed char a); 19963vector signed long long vec_signextll (vector signed char a); 19964vector signed int vec_signexti (vector signed short a); 19965vector signed long long vec_signextll (vector signed short a); 19966vector signed long long vec_signextll (vector signed int a); 19967vector signed long long vec_signextq (vector signed long long a); 19968@end smallexample 19969 19970Each element of the result is produced by sign-extending the element of the 19971input vector that would fall in the least significant portion of the result 19972element. For example, a sign-extension of a vector signed char to a vector 19973signed long long will sign extend the rightmost byte of each doubleword. 19974 19975@node PowerPC AltiVec Built-in Functions Available on ISA 3.1 19976@subsubsection PowerPC AltiVec Built-in Functions Available on ISA 3.1 19977 19978The following additional built-in functions are also available for the 19979PowerPC family of processors, starting with ISA 3.1 (@option{-mcpu=power10}): 19980 19981 19982@smallexample 19983@exdent vector unsigned long long int 19984@exdent vec_cfuge (vector unsigned long long int, vector unsigned long long int); 19985@end smallexample 19986Perform a vector centrifuge operation, as if implemented by the 19987@code{vcfuged} instruction. 19988@findex vec_cfuge 19989 19990@smallexample 19991@exdent vector unsigned long long int 19992@exdent vec_cntlzm (vector unsigned long long int, vector unsigned long long int); 19993@end smallexample 19994Perform a vector count leading zeros under bit mask operation, as if 19995implemented by the @code{vclzdm} instruction. 19996@findex vec_cntlzm 19997 19998@smallexample 19999@exdent vector unsigned long long int 20000@exdent vec_cnttzm (vector unsigned long long int, vector unsigned long long int); 20001@end smallexample 20002Perform a vector count trailing zeros under bit mask operation, as if 20003implemented by the @code{vctzdm} instruction. 20004@findex vec_cnttzm 20005 20006@smallexample 20007@exdent vector signed char 20008@exdent vec_clrl (vector signed char a, unsigned int n); 20009@exdent vector unsigned char 20010@exdent vec_clrl (vector unsigned char a, unsigned int n); 20011@end smallexample 20012Clear the left-most @code{(16 - n)} bytes of vector argument @code{a}, as if 20013implemented by the @code{vclrlb} instruction on a big-endian target 20014and by the @code{vclrrb} instruction on a little-endian target. A 20015value of @code{n} that is greater than 16 is treated as if it equaled 16. 20016@findex vec_clrl 20017 20018@smallexample 20019@exdent vector signed char 20020@exdent vec_clrr (vector signed char a, unsigned int n); 20021@exdent vector unsigned char 20022@exdent vec_clrr (vector unsigned char a, unsigned int n); 20023@end smallexample 20024Clear the right-most @code{(16 - n)} bytes of vector argument @code{a}, as if 20025implemented by the @code{vclrrb} instruction on a big-endian target 20026and by the @code{vclrlb} instruction on a little-endian target. A 20027value of @code{n} that is greater than 16 is treated as if it equaled 16. 20028@findex vec_clrr 20029 20030@smallexample 20031@exdent vector unsigned long long int 20032@exdent vec_gnb (vector unsigned __int128, const unsigned char); 20033@end smallexample 20034Perform a 128-bit vector gather operation, as if implemented by the 20035@code{vgnb} instruction. The second argument must be a literal 20036integer value between 2 and 7 inclusive. 20037@findex vec_gnb 20038 20039 20040Vector Extract 20041 20042@smallexample 20043@exdent vector unsigned long long int 20044@exdent vec_extractl (vector unsigned char, vector unsigned char, unsigned int); 20045@exdent vector unsigned long long int 20046@exdent vec_extractl (vector unsigned short, vector unsigned short, unsigned int); 20047@exdent vector unsigned long long int 20048@exdent vec_extractl (vector unsigned int, vector unsigned int, unsigned int); 20049@exdent vector unsigned long long int 20050@exdent vec_extractl (vector unsigned long long, vector unsigned long long, unsigned int); 20051@end smallexample 20052Extract an element from two concatenated vectors starting at the given byte index 20053in natural-endian order, and place it zero-extended in doubleword 1 of the result 20054according to natural element order. If the byte index is out of range for the 20055data type, the intrinsic will be rejected. 20056For little-endian, this output will match the placement by the hardware 20057instruction, i.e., dword[0] in RTL notation. For big-endian, an additional 20058instruction is needed to move it from the "left" doubleword to the "right" one. 20059For little-endian, semantics matching the @code{vextdubvrx}, 20060@code{vextduhvrx}, @code{vextduwvrx} instruction will be generated, while for 20061big-endian, semantics matching the @code{vextdubvlx}, @code{vextduhvlx}, 20062@code{vextduwvlx} instructions 20063will be generated. Note that some fairly anomalous results can be generated if 20064the byte index is not aligned on an element boundary for the element being 20065extracted. This is a limitation of the bi-endian vector programming model is 20066consistent with the limitation on @code{vec_perm}. 20067@findex vec_extractl 20068 20069@smallexample 20070@exdent vector unsigned long long int 20071@exdent vec_extracth (vector unsigned char, vector unsigned char, unsigned int); 20072@exdent vector unsigned long long int 20073@exdent vec_extracth (vector unsigned short, vector unsigned short, 20074unsigned int); 20075@exdent vector unsigned long long int 20076@exdent vec_extracth (vector unsigned int, vector unsigned int, unsigned int); 20077@exdent vector unsigned long long int 20078@exdent vec_extracth (vector unsigned long long, vector unsigned long long, 20079unsigned int); 20080@end smallexample 20081Extract an element from two concatenated vectors starting at the given byte 20082index. The index is based on big endian order for a little endian system. 20083Similarly, the index is based on little endian order for a big endian system. 20084The extraced elements are zero-extended and put in doubleword 1 20085according to natural element order. If the byte index is out of range for the 20086data type, the intrinsic will be rejected. For little-endian, this output 20087will match the placement by the hardware instruction (vextdubvrx, vextduhvrx, 20088vextduwvrx, vextddvrx) i.e., dword[0] in RTL 20089notation. For big-endian, an additional instruction is needed to move it 20090from the "left" doubleword to the "right" one. For little-endian, semantics 20091matching the @code{vextdubvlx}, @code{vextduhvlx}, @code{vextduwvlx} 20092instructions will be generated, while for big-endian, semantics matching the 20093@code{vextdubvrx}, @code{vextduhvrx}, @code{vextduwvrx} instructions will 20094be generated. Note that some fairly anomalous 20095results can be generated if the byte index is not aligned on the 20096element boundary for the element being extracted. This is a 20097limitation of the bi-endian vector programming model consistent with the 20098limitation on @code{vec_perm}. 20099@findex vec_extracth 20100@smallexample 20101@exdent vector unsigned long long int 20102@exdent vec_pdep (vector unsigned long long int, vector unsigned long long int); 20103@end smallexample 20104Perform a vector parallel bits deposit operation, as if implemented by 20105the @code{vpdepd} instruction. 20106@findex vec_pdep 20107 20108Vector Insert 20109 20110@smallexample 20111@exdent vector unsigned char 20112@exdent vec_insertl (unsigned char, vector unsigned char, unsigned int); 20113@exdent vector unsigned short 20114@exdent vec_insertl (unsigned short, vector unsigned short, unsigned int); 20115@exdent vector unsigned int 20116@exdent vec_insertl (unsigned int, vector unsigned int, unsigned int); 20117@exdent vector unsigned long long 20118@exdent vec_insertl (unsigned long long, vector unsigned long long, 20119unsigned int); 20120@exdent vector unsigned char 20121@exdent vec_insertl (vector unsigned char, vector unsigned char, unsigned int; 20122@exdent vector unsigned short 20123@exdent vec_insertl (vector unsigned short, vector unsigned short, 20124unsigned int); 20125@exdent vector unsigned int 20126@exdent vec_insertl (vector unsigned int, vector unsigned int, unsigned int); 20127@end smallexample 20128 20129Let src be the first argument, when the first argument is a scalar, or the 20130rightmost element of the left doubleword of the first argument, when the first 20131argument is a vector. Insert the source into the destination at the position 20132given by the third argument, using natural element order in the second 20133argument. The rest of the second argument is unchanged. If the byte 20134index is greater than 14 for halfwords, greater than 12 for words, or 20135greater than 8 for doublewords the result is undefined. For little-endian, 20136the generated code will be semantically equivalent to @code{vins[bhwd]rx} 20137instructions. Similarly for big-endian it will be semantically equivalent 20138to @code{vins[bhwd]lx}. Note that some fairly anomalous results can be 20139generated if the byte index is not aligned on an element boundary for the 20140type of element being inserted. 20141@findex vec_insertl 20142 20143@smallexample 20144@exdent vector unsigned char 20145@exdent vec_inserth (unsigned char, vector unsigned char, unsigned int); 20146@exdent vector unsigned short 20147@exdent vec_inserth (unsigned short, vector unsigned short, unsigned int); 20148@exdent vector unsigned int 20149@exdent vec_inserth (unsigned int, vector unsigned int, unsigned int); 20150@exdent vector unsigned long long 20151@exdent vec_inserth (unsigned long long, vector unsigned long long, 20152unsigned int); 20153@exdent vector unsigned char 20154@exdent vec_inserth (vector unsigned char, vector unsigned char, unsigned int); 20155@exdent vector unsigned short 20156@exdent vec_inserth (vector unsigned short, vector unsigned short, 20157unsigned int); 20158@exdent vector unsigned int 20159@exdent vec_inserth (vector unsigned int, vector unsigned int, unsigned int); 20160@end smallexample 20161 20162Let src be the first argument, when the first argument is a scalar, or the 20163rightmost element of the first argument, when the first argument is a vector. 20164Insert src into the second argument at the position identified by the third 20165argument, using opposite element order in the second argument, and leaving the 20166rest of the second argument unchanged. If the byte index is greater than 14 20167for halfwords, 12 for words, or 8 for doublewords, the intrinsic will be 20168rejected. Note that the underlying hardware instruction uses the same register 20169for the second argument and the result. 20170For little-endian, the code generation will be semantically equivalent to 20171@code{vins[bhwd]lx}, while for big-endian it will be semantically equivalent to 20172@code{vins[bhwd]rx}. 20173Note that some fairly anomalous results can be generated if the byte index is 20174not aligned on an element boundary for the sort of element being inserted. 20175@findex vec_inserth 20176 20177Vector Replace Element 20178@smallexample 20179@exdent vector signed int vec_replace_elt (vector signed int, signed int, 20180const int); 20181@exdent vector unsigned int vec_replace_elt (vector unsigned int, 20182unsigned int, const int); 20183@exdent vector float vec_replace_elt (vector float, float, const int); 20184@exdent vector signed long long vec_replace_elt (vector signed long long, 20185signed long long, const int); 20186@exdent vector unsigned long long vec_replace_elt (vector unsigned long long, 20187unsigned long long, const int); 20188@exdent vector double rec_replace_elt (vector double, double, const int); 20189@end smallexample 20190The third argument (constrained to [0,3]) identifies the natural-endian 20191element number of the first argument that will be replaced by the second 20192argument to produce the result. The other elements of the first argument will 20193remain unchanged in the result. 20194 20195If it's desirable to insert a word at an unaligned position, use 20196vec_replace_unaligned instead. 20197 20198@findex vec_replace_element 20199 20200Vector Replace Unaligned 20201@smallexample 20202@exdent vector unsigned char vec_replace_unaligned (vector unsigned char, 20203signed int, const int); 20204@exdent vector unsigned char vec_replace_unaligned (vector unsigned char, 20205unsigned int, const int); 20206@exdent vector unsigned char vec_replace_unaligned (vector unsigned char, 20207float, const int); 20208@exdent vector unsigned char vec_replace_unaligned (vector unsigned char, 20209signed long long, const int); 20210@exdent vector unsigned char vec_replace_unaligned (vector unsigned char, 20211unsigned long long, const int); 20212@exdent vector unsigned char vec_replace_unaligned (vector unsigned char, 20213double, const int); 20214@end smallexample 20215 20216The second argument replaces a portion of the first argument to produce the 20217result, with the rest of the first argument unchanged in the result. The 20218third argument identifies the byte index (using left-to-right, or big-endian 20219order) where the high-order byte of the second argument will be placed, with 20220the remaining bytes of the second argument placed naturally "to the right" 20221of the high-order byte. 20222 20223The programmer is responsible for understanding the endianness issues involved 20224with the first argument and the result. 20225@findex vec_replace_unaligned 20226 20227Vector Shift Left Double Bit Immediate 20228@smallexample 20229@exdent vector signed char vec_sldb (vector signed char, vector signed char, 20230const unsigned int); 20231@exdent vector unsigned char vec_sldb (vector unsigned char, 20232vector unsigned char, const unsigned int); 20233@exdent vector signed short vec_sldb (vector signed short, vector signed short, 20234const unsigned int); 20235@exdent vector unsigned short vec_sldb (vector unsigned short, 20236vector unsigned short, const unsigned int); 20237@exdent vector signed int vec_sldb (vector signed int, vector signed int, 20238const unsigned int); 20239@exdent vector unsigned int vec_sldb (vector unsigned int, vector unsigned int, 20240const unsigned int); 20241@exdent vector signed long long vec_sldb (vector signed long long, 20242vector signed long long, const unsigned int); 20243@exdent vector unsigned long long vec_sldb (vector unsigned long long, 20244vector unsigned long long, const unsigned int); 20245@end smallexample 20246 20247Shift the combined input vectors left by the amount specified by the low-order 20248three bits of the third argument, and return the leftmost remaining 128 bits. 20249Code using this instruction must be endian-aware. 20250 20251@findex vec_sldb 20252 20253Vector Shift Right Double Bit Immediate 20254 20255@smallexample 20256@exdent vector signed char vec_srdb (vector signed char, vector signed char, 20257const unsigned int); 20258@exdent vector unsigned char vec_srdb (vector unsigned char, vector unsigned char, 20259const unsigned int); 20260@exdent vector signed short vec_srdb (vector signed short, vector signed short, 20261const unsigned int); 20262@exdent vector unsigned short vec_srdb (vector unsigned short, vector unsigned short, 20263const unsigned int); 20264@exdent vector signed int vec_srdb (vector signed int, vector signed int, 20265const unsigned int); 20266@exdent vector unsigned int vec_srdb (vector unsigned int, vector unsigned int, 20267const unsigned int); 20268@exdent vector signed long long vec_srdb (vector signed long long, 20269vector signed long long, const unsigned int); 20270@exdent vector unsigned long long vec_srdb (vector unsigned long long, 20271vector unsigned long long, const unsigned int); 20272@end smallexample 20273 20274Shift the combined input vectors right by the amount specified by the low-order 20275three bits of the third argument, and return the remaining 128 bits. Code 20276using this built-in must be endian-aware. 20277 20278@findex vec_srdb 20279 20280Vector Splat 20281 20282@smallexample 20283@exdent vector signed int vec_splati (const signed int); 20284@exdent vector float vec_splati (const float); 20285@end smallexample 20286 20287Splat a 32-bit immediate into a vector of words. 20288 20289@findex vec_splati 20290 20291@smallexample 20292@exdent vector double vec_splatid (const float); 20293@end smallexample 20294 20295Convert a single precision floating-point value to double-precision and splat 20296the result to a vector of double-precision floats. 20297 20298@findex vec_splatid 20299 20300@smallexample 20301@exdent vector signed int vec_splati_ins (vector signed int, 20302const unsigned int, const signed int); 20303@exdent vector unsigned int vec_splati_ins (vector unsigned int, 20304const unsigned int, const unsigned int); 20305@exdent vector float vec_splati_ins (vector float, const unsigned int, 20306const float); 20307@end smallexample 20308 20309Argument 2 must be either 0 or 1. Splat the value of argument 3 into the word 20310identified by argument 2 of each doubleword of argument 1 and return the 20311result. The other words of argument 1 are unchanged. 20312 20313@findex vec_splati_ins 20314 20315Vector Blend Variable 20316 20317@smallexample 20318@exdent vector signed char vec_blendv (vector signed char, vector signed char, 20319vector unsigned char); 20320@exdent vector unsigned char vec_blendv (vector unsigned char, 20321vector unsigned char, vector unsigned char); 20322@exdent vector signed short vec_blendv (vector signed short, 20323vector signed short, vector unsigned short); 20324@exdent vector unsigned short vec_blendv (vector unsigned short, 20325vector unsigned short, vector unsigned short); 20326@exdent vector signed int vec_blendv (vector signed int, vector signed int, 20327vector unsigned int); 20328@exdent vector unsigned int vec_blendv (vector unsigned int, 20329vector unsigned int, vector unsigned int); 20330@exdent vector signed long long vec_blendv (vector signed long long, 20331vector signed long long, vector unsigned long long); 20332@exdent vector unsigned long long vec_blendv (vector unsigned long long, 20333vector unsigned long long, vector unsigned long long); 20334@exdent vector float vec_blendv (vector float, vector float, 20335vector unsigned int); 20336@exdent vector double vec_blendv (vector double, vector double, 20337vector unsigned long long); 20338@end smallexample 20339 20340Blend the first and second argument vectors according to the sign bits of the 20341corresponding elements of the third argument vector. This is similar to the 20342@code{vsel} and @code{xxsel} instructions but for bigger elements. 20343 20344@findex vec_blendv 20345 20346Vector Permute Extended 20347 20348@smallexample 20349@exdent vector signed char vec_permx (vector signed char, vector signed char, 20350vector unsigned char, const int); 20351@exdent vector unsigned char vec_permx (vector unsigned char, 20352vector unsigned char, vector unsigned char, const int); 20353@exdent vector signed short vec_permx (vector signed short, 20354vector signed short, vector unsigned char, const int); 20355@exdent vector unsigned short vec_permx (vector unsigned short, 20356vector unsigned short, vector unsigned char, const int); 20357@exdent vector signed int vec_permx (vector signed int, vector signed int, 20358vector unsigned char, const int); 20359@exdent vector unsigned int vec_permx (vector unsigned int, 20360vector unsigned int, vector unsigned char, const int); 20361@exdent vector signed long long vec_permx (vector signed long long, 20362vector signed long long, vector unsigned char, const int); 20363@exdent vector unsigned long long vec_permx (vector unsigned long long, 20364vector unsigned long long, vector unsigned char, const int); 20365@exdent vector float (vector float, vector float, vector unsigned char, 20366const int); 20367@exdent vector double (vector double, vector double, vector unsigned char, 20368const int); 20369@end smallexample 20370 20371Perform a partial permute of the first two arguments, which form a 32-byte 20372section of an emulated vector up to 256 bytes wide, using the partial permute 20373control vector in the third argument. The fourth argument (constrained to 20374values of 0-7) identifies which 32-byte section of the emulated vector is 20375contained in the first two arguments. 20376@findex vec_permx 20377 20378@smallexample 20379@exdent vector unsigned long long int 20380@exdent vec_pext (vector unsigned long long int, vector unsigned long long int); 20381@end smallexample 20382Perform a vector parallel bit extract operation, as if implemented by 20383the @code{vpextd} instruction. 20384@findex vec_pext 20385 20386@smallexample 20387@exdent vector unsigned char vec_stril (vector unsigned char); 20388@exdent vector signed char vec_stril (vector signed char); 20389@exdent vector unsigned short vec_stril (vector unsigned short); 20390@exdent vector signed short vec_stril (vector signed short); 20391@end smallexample 20392Isolate the left-most non-zero elements of the incoming vector argument, 20393replacing all elements to the right of the left-most zero element 20394found within the argument with zero. The typical implementation uses 20395the @code{vstribl} or @code{vstrihl} instruction on big-endian targets 20396and uses the @code{vstribr} or @code{vstrihr} instruction on 20397little-endian targets. 20398@findex vec_stril 20399 20400@smallexample 20401@exdent int vec_stril_p (vector unsigned char); 20402@exdent int vec_stril_p (vector signed char); 20403@exdent int short vec_stril_p (vector unsigned short); 20404@exdent int vec_stril_p (vector signed short); 20405@end smallexample 20406Return a non-zero value if and only if the argument contains a zero 20407element. The typical implementation uses 20408the @code{vstribl.} or @code{vstrihl.} instruction on big-endian targets 20409and uses the @code{vstribr.} or @code{vstrihr.} instruction on 20410little-endian targets. Choose this built-in to check for presence of 20411zero element if the same argument is also passed to @code{vec_stril}. 20412@findex vec_stril_p 20413 20414@smallexample 20415@exdent vector unsigned char vec_strir (vector unsigned char); 20416@exdent vector signed char vec_strir (vector signed char); 20417@exdent vector unsigned short vec_strir (vector unsigned short); 20418@exdent vector signed short vec_strir (vector signed short); 20419@end smallexample 20420Isolate the right-most non-zero elements of the incoming vector argument, 20421replacing all elements to the left of the right-most zero element 20422found within the argument with zero. The typical implementation uses 20423the @code{vstribr} or @code{vstrihr} instruction on big-endian targets 20424and uses the @code{vstribl} or @code{vstrihl} instruction on 20425little-endian targets. 20426@findex vec_strir 20427 20428@smallexample 20429@exdent int vec_strir_p (vector unsigned char); 20430@exdent int vec_strir_p (vector signed char); 20431@exdent int short vec_strir_p (vector unsigned short); 20432@exdent int vec_strir_p (vector signed short); 20433@end smallexample 20434Return a non-zero value if and only if the argument contains a zero 20435element. The typical implementation uses 20436the @code{vstribr.} or @code{vstrihr.} instruction on big-endian targets 20437and uses the @code{vstribl.} or @code{vstrihl.} instruction on 20438little-endian targets. Choose this built-in to check for presence of 20439zero element if the same argument is also passed to @code{vec_strir}. 20440@findex vec_strir_p 20441 20442@smallexample 20443@exdent vector unsigned char 20444@exdent vec_ternarylogic (vector unsigned char, vector unsigned char, 20445 vector unsigned char, const unsigned int); 20446@exdent vector unsigned short 20447@exdent vec_ternarylogic (vector unsigned short, vector unsigned short, 20448 vector unsigned short, const unsigned int); 20449@exdent vector unsigned int 20450@exdent vec_ternarylogic (vector unsigned int, vector unsigned int, 20451 vector unsigned int, const unsigned int); 20452@exdent vector unsigned long long int 20453@exdent vec_ternarylogic (vector unsigned long long int, vector unsigned long long int, 20454 vector unsigned long long int, const unsigned int); 20455@exdent vector unsigned __int128 20456@exdent vec_ternarylogic (vector unsigned __int128, vector unsigned __int128, 20457 vector unsigned __int128, const unsigned int); 20458@end smallexample 20459Perform a 128-bit vector evaluate operation, as if implemented by the 20460@code{xxeval} instruction. The fourth argument must be a literal 20461integer value between 0 and 255 inclusive. 20462@findex vec_ternarylogic 20463 20464@smallexample 20465@exdent vector unsigned char vec_genpcvm (vector unsigned char, const int); 20466@exdent vector unsigned short vec_genpcvm (vector unsigned short, const int); 20467@exdent vector unsigned int vec_genpcvm (vector unsigned int, const int); 20468@exdent vector unsigned int vec_genpcvm (vector unsigned long long int, 20469 const int); 20470@end smallexample 20471 20472Vector Integer Multiply/Divide/Modulo 20473 20474@smallexample 20475@exdent vector signed int 20476@exdent vec_mulh (vector signed int a, vector signed int b); 20477@exdent vector unsigned int 20478@exdent vec_mulh (vector unsigned int a, vector unsigned int b); 20479@end smallexample 20480 20481For each integer value @code{i} from 0 to 3, do the following. The integer 20482value in word element @code{i} of a is multiplied by the integer value in word 20483element @code{i} of b. The high-order 32 bits of the 64-bit product are placed 20484into word element @code{i} of the vector returned. 20485 20486@smallexample 20487@exdent vector signed long long 20488@exdent vec_mulh (vector signed long long a, vector signed long long b); 20489@exdent vector unsigned long long 20490@exdent vec_mulh (vector unsigned long long a, vector unsigned long long b); 20491@end smallexample 20492 20493For each integer value @code{i} from 0 to 1, do the following. The integer 20494value in doubleword element @code{i} of a is multiplied by the integer value in 20495doubleword element @code{i} of b. The high-order 64 bits of the 128-bit product 20496are placed into doubleword element @code{i} of the vector returned. 20497 20498@smallexample 20499@exdent vector unsigned long long 20500@exdent vec_mul (vector unsigned long long a, vector unsigned long long b); 20501@exdent vector signed long long 20502@exdent vec_mul (vector signed long long a, vector signed long long b); 20503@end smallexample 20504 20505For each integer value @code{i} from 0 to 1, do the following. The integer 20506value in doubleword element @code{i} of a is multiplied by the integer value in 20507doubleword element @code{i} of b. The low-order 64 bits of the 128-bit product 20508are placed into doubleword element @code{i} of the vector returned. 20509 20510@smallexample 20511@exdent vector signed int 20512@exdent vec_div (vector signed int a, vector signed int b); 20513@exdent vector unsigned int 20514@exdent vec_div (vector unsigned int a, vector unsigned int b); 20515@end smallexample 20516 20517For each integer value @code{i} from 0 to 3, do the following. The integer in 20518word element @code{i} of a is divided by the integer in word element @code{i} 20519of b. The unique integer quotient is placed into the word element @code{i} of 20520the vector returned. If an attempt is made to perform any of the divisions 20521<anything> ÷ 0 then the quotient is undefined. 20522 20523@smallexample 20524@exdent vector signed long long 20525@exdent vec_div (vector signed long long a, vector signed long long b); 20526@exdent vector unsigned long long 20527@exdent vec_div (vector unsigned long long a, vector unsigned long long b); 20528@end smallexample 20529 20530For each integer value @code{i} from 0 to 1, do the following. The integer in 20531doubleword element @code{i} of a is divided by the integer in doubleword 20532element @code{i} of b. The unique integer quotient is placed into the 20533doubleword element @code{i} of the vector returned. If an attempt is made to 20534perform any of the divisions 0x8000_0000_0000_0000 ÷ -1 or <anything> ÷ 0 then 20535the quotient is undefined. 20536 20537@smallexample 20538@exdent vector signed int 20539@exdent vec_dive (vector signed int a, vector signed int b); 20540@exdent vector unsigned int 20541@exdent vec_dive (vector unsigned int a, vector unsigned int b); 20542@end smallexample 20543 20544For each integer value @code{i} from 0 to 3, do the following. The integer in 20545word element @code{i} of a is shifted left by 32 bits, then divided by the 20546integer in word element @code{i} of b. The unique integer quotient is placed 20547into the word element @code{i} of the vector returned. If the quotient cannot 20548be represented in 32 bits, or if an attempt is made to perform any of the 20549divisions <anything> ÷ 0 then the quotient is undefined. 20550 20551@smallexample 20552@exdent vector signed long long 20553@exdent vec_dive (vector signed long long a, vector signed long long b); 20554@exdent vector unsigned long long 20555@exdent vec_dive (vector unsigned long long a, vector unsigned long long b); 20556@end smallexample 20557 20558For each integer value @code{i} from 0 to 1, do the following. The integer in 20559doubleword element @code{i} of a is shifted left by 64 bits, then divided by 20560the integer in doubleword element @code{i} of b. The unique integer quotient is 20561placed into the doubleword element @code{i} of the vector returned. If the 20562quotient cannot be represented in 64 bits, or if an attempt is made to perform 20563<anything> ÷ 0 then the quotient is undefined. 20564 20565@smallexample 20566@exdent vector signed int 20567@exdent vec_mod (vector signed int a, vector signed int b); 20568@exdent vector unsigned int 20569@exdent vec_mod (vector unsigned int a, vector unsigned int b); 20570@end smallexample 20571 20572For each integer value @code{i} from 0 to 3, do the following. The integer in 20573word element @code{i} of a is divided by the integer in word element @code{i} 20574of b. The unique integer remainder is placed into the word element @code{i} of 20575the vector returned. If an attempt is made to perform any of the divisions 205760x8000_0000 ÷ -1 or <anything> ÷ 0 then the remainder is undefined. 20577 20578@smallexample 20579@exdent vector signed long long 20580@exdent vec_mod (vector signed long long a, vector signed long long b); 20581@exdent vector unsigned long long 20582@exdent vec_mod (vector unsigned long long a, vector unsigned long long b); 20583@end smallexample 20584 20585For each integer value @code{i} from 0 to 1, do the following. The integer in 20586doubleword element @code{i} of a is divided by the integer in doubleword 20587element @code{i} of b. The unique integer remainder is placed into the 20588doubleword element @code{i} of the vector returned. If an attempt is made to 20589perform <anything> ÷ 0 then the remainder is undefined. 20590 20591Generate PCV from specified Mask size, as if implemented by the 20592@code{xxgenpcvbm}, @code{xxgenpcvhm}, @code{xxgenpcvwm} instructions, where 20593immediate value is either 0, 1, 2 or 3. 20594@findex vec_genpcvm 20595 20596@smallexample 20597@exdent vector unsigned __int128 vec_rl (vector unsigned __int128 A, 20598 vector unsigned __int128 B); 20599@exdent vector signed __int128 vec_rl (vector signed __int128 A, 20600 vector unsigned __int128 B); 20601@end smallexample 20602 20603Result value: Each element of R is obtained by rotating the corresponding element 20604of A left by the number of bits specified by the corresponding element of B. 20605 20606 20607@smallexample 20608@exdent vector unsigned __int128 vec_rlmi (vector unsigned __int128, 20609 vector unsigned __int128, 20610 vector unsigned __int128); 20611@exdent vector signed __int128 vec_rlmi (vector signed __int128, 20612 vector signed __int128, 20613 vector unsigned __int128); 20614@end smallexample 20615 20616Returns the result of rotating the first input and inserting it under mask 20617into the second input. The first bit in the mask, the last bit in the mask are 20618obtained from the two 7-bit fields bits [108:115] and bits [117:123] 20619respectively of the second input. The shift is obtained from the third input 20620in the 7-bit field [125:131] where all bits counted from zero at the left. 20621 20622@smallexample 20623@exdent vector unsigned __int128 vec_rlnm (vector unsigned __int128, 20624 vector unsigned __int128, 20625 vector unsigned __int128); 20626@exdent vector signed __int128 vec_rlnm (vector signed __int128, 20627 vector unsigned __int128, 20628 vector unsigned __int128); 20629@end smallexample 20630 20631Returns the result of rotating the first input and ANDing it with a mask. The 20632first bit in the mask and the last bit in the mask are obtained from the two 206337-bit fields bits [117:123] and bits [125:131] respectively of the second 20634input. The shift is obtained from the third input in the 7-bit field bits 20635[125:131] where all bits counted from zero at the left. 20636 20637@smallexample 20638@exdent vector unsigned __int128 vec_sl(vector unsigned __int128 A, vector unsigned __int128 B); 20639@exdent vector signed __int128 vec_sl(vector signed __int128 A, vector unsigned __int128 B); 20640@end smallexample 20641 20642Result value: Each element of R is obtained by shifting the corresponding element of 20643A left by the number of bits specified by the corresponding element of B. 20644 20645@smallexample 20646@exdent vector unsigned __int128 vec_sr(vector unsigned __int128 A, vector unsigned __int128 B); 20647@exdent vector signed __int128 vec_sr(vector signed __int128 A, vector unsigned __int128 B); 20648@end smallexample 20649 20650Result value: Each element of R is obtained by shifting the corresponding element of 20651A right by the number of bits specified by the corresponding element of B. 20652 20653@smallexample 20654@exdent vector unsigned __int128 vec_sra(vector unsigned __int128 A, vector unsigned __int128 B); 20655@exdent vector signed __int128 vec_sra(vector signed __int128 A, vector unsigned __int128 B); 20656@end smallexample 20657 20658Result value: Each element of R is obtained by arithmetic shifting the corresponding 20659element of A right by the number of bits specified by the corresponding element of B. 20660 20661@smallexample 20662@exdent vector unsigned __int128 vec_mule (vector unsigned long long, 20663 vector unsigned long long); 20664@exdent vector signed __int128 vec_mule (vector signed long long, 20665 vector signed long long); 20666@end smallexample 20667 20668Returns a vector containing a 128-bit integer result of multiplying the even 20669doubleword elements of the two inputs. 20670 20671@smallexample 20672@exdent vector unsigned __int128 vec_mulo (vector unsigned long long, 20673 vector unsigned long long); 20674@exdent vector signed __int128 vec_mulo (vector signed long long, 20675 vector signed long long); 20676@end smallexample 20677 20678Returns a vector containing a 128-bit integer result of multiplying the odd 20679doubleword elements of the two inputs. 20680 20681@smallexample 20682@exdent vector unsigned __int128 vec_div (vector unsigned __int128, 20683 vector unsigned __int128); 20684@exdent vector signed __int128 vec_div (vector signed __int128, 20685 vector signed __int128); 20686@end smallexample 20687 20688Returns the result of dividing the first operand by the second operand. An 20689attempt to divide any value by zero or to divide the most negative signed 20690128-bit integer by negative one results in an undefined value. 20691 20692@smallexample 20693@exdent vector unsigned __int128 vec_dive (vector unsigned __int128, 20694 vector unsigned __int128); 20695@exdent vector signed __int128 vec_dive (vector signed __int128, 20696 vector signed __int128); 20697@end smallexample 20698 20699The result is produced by shifting the first input left by 128 bits and 20700dividing by the second. If an attempt is made to divide by zero or the result 20701is larger than 128 bits, the result is undefined. 20702 20703@smallexample 20704@exdent vector unsigned __int128 vec_mod (vector unsigned __int128, 20705 vector unsigned __int128); 20706@exdent vector signed __int128 vec_mod (vector signed __int128, 20707 vector signed __int128); 20708@end smallexample 20709 20710The result is the modulo result of dividing the first input by the second 20711input. 20712 20713The following builtins perform 128-bit vector comparisons. The 20714@code{vec_all_xx}, @code{vec_any_xx}, and @code{vec_cmpxx}, where @code{xx} is 20715one of the operations @code{eq, ne, gt, lt, ge, le} perform pairwise 20716comparisons between the elements at the same positions within their two vector 20717arguments. The @code{vec_all_xx}function returns a non-zero value if and only 20718if all pairwise comparisons are true. The @code{vec_any_xx} function returns 20719a non-zero value if and only if at least one pairwise comparison is true. The 20720@code{vec_cmpxx}function returns a vector of the same type as its two 20721arguments, within which each element consists of all ones to denote that 20722specified logical comparison of the corresponding elements was true. 20723Otherwise, the element of the returned vector contains all zeros. 20724 20725@smallexample 20726vector bool __int128 vec_cmpeq (vector signed __int128, vector signed __int128); 20727vector bool __int128 vec_cmpeq (vector unsigned __int128, vector unsigned __int128); 20728vector bool __int128 vec_cmpne (vector signed __int128, vector signed __int128); 20729vector bool __int128 vec_cmpne (vector unsigned __int128, vector unsigned __int128); 20730vector bool __int128 vec_cmpgt (vector signed __int128, vector signed __int128); 20731vector bool __int128 vec_cmpgt (vector unsigned __int128, vector unsigned __int128); 20732vector bool __int128 vec_cmplt (vector signed __int128, vector signed __int128); 20733vector bool __int128 vec_cmplt (vector unsigned __int128, vector unsigned __int128); 20734vector bool __int128 vec_cmpge (vector signed __int128, vector signed __int128); 20735vector bool __int128 vec_cmpge (vector unsigned __int128, vector unsigned __int128); 20736vector bool __int128 vec_cmple (vector signed __int128, vector signed __int128); 20737vector bool __int128 vec_cmple (vector unsigned __int128, vector unsigned __int128); 20738 20739int vec_all_eq (vector signed __int128, vector signed __int128); 20740int vec_all_eq (vector unsigned __int128, vector unsigned __int128); 20741int vec_all_ne (vector signed __int128, vector signed __int128); 20742int vec_all_ne (vector unsigned __int128, vector unsigned __int128); 20743int vec_all_gt (vector signed __int128, vector signed __int128); 20744int vec_all_gt (vector unsigned __int128, vector unsigned __int128); 20745int vec_all_lt (vector signed __int128, vector signed __int128); 20746int vec_all_lt (vector unsigned __int128, vector unsigned __int128); 20747int vec_all_ge (vector signed __int128, vector signed __int128); 20748int vec_all_ge (vector unsigned __int128, vector unsigned __int128); 20749int vec_all_le (vector signed __int128, vector signed __int128); 20750int vec_all_le (vector unsigned __int128, vector unsigned __int128); 20751 20752int vec_any_eq (vector signed __int128, vector signed __int128); 20753int vec_any_eq (vector unsigned __int128, vector unsigned __int128); 20754int vec_any_ne (vector signed __int128, vector signed __int128); 20755int vec_any_ne (vector unsigned __int128, vector unsigned __int128); 20756int vec_any_gt (vector signed __int128, vector signed __int128); 20757int vec_any_gt (vector unsigned __int128, vector unsigned __int128); 20758int vec_any_lt (vector signed __int128, vector signed __int128); 20759int vec_any_lt (vector unsigned __int128, vector unsigned __int128); 20760int vec_any_ge (vector signed __int128, vector signed __int128); 20761int vec_any_ge (vector unsigned __int128, vector unsigned __int128); 20762int vec_any_le (vector signed __int128, vector signed __int128); 20763int vec_any_le (vector unsigned __int128, vector unsigned __int128); 20764@end smallexample 20765 20766 20767@node PowerPC Hardware Transactional Memory Built-in Functions 20768@subsection PowerPC Hardware Transactional Memory Built-in Functions 20769GCC provides two interfaces for accessing the Hardware Transactional 20770Memory (HTM) instructions available on some of the PowerPC family 20771of processors (eg, POWER8). The two interfaces come in a low level 20772interface, consisting of built-in functions specific to PowerPC and a 20773higher level interface consisting of inline functions that are common 20774between PowerPC and S/390. 20775 20776@subsubsection PowerPC HTM Low Level Built-in Functions 20777 20778The following low level built-in functions are available with 20779@option{-mhtm} or @option{-mcpu=CPU} where CPU is `power8' or later. 20780They all generate the machine instruction that is part of the name. 20781 20782The HTM builtins (with the exception of @code{__builtin_tbegin}) return 20783the full 4-bit condition register value set by their associated hardware 20784instruction. The header file @code{htmintrin.h} defines some macros that can 20785be used to decipher the return value. The @code{__builtin_tbegin} builtin 20786returns a simple @code{true} or @code{false} value depending on whether a transaction was 20787successfully started or not. The arguments of the builtins match exactly the 20788type and order of the associated hardware instruction's operands, except for 20789the @code{__builtin_tcheck} builtin, which does not take any input arguments. 20790Refer to the ISA manual for a description of each instruction's operands. 20791 20792@smallexample 20793unsigned int __builtin_tbegin (unsigned int); 20794unsigned int __builtin_tend (unsigned int); 20795 20796unsigned int __builtin_tabort (unsigned int); 20797unsigned int __builtin_tabortdc (unsigned int, unsigned int, unsigned int); 20798unsigned int __builtin_tabortdci (unsigned int, unsigned int, int); 20799unsigned int __builtin_tabortwc (unsigned int, unsigned int, unsigned int); 20800unsigned int __builtin_tabortwci (unsigned int, unsigned int, int); 20801 20802unsigned int __builtin_tcheck (void); 20803unsigned int __builtin_treclaim (unsigned int); 20804unsigned int __builtin_trechkpt (void); 20805unsigned int __builtin_tsr (unsigned int); 20806@end smallexample 20807 20808In addition to the above HTM built-ins, we have added built-ins for 20809some common extended mnemonics of the HTM instructions: 20810 20811@smallexample 20812unsigned int __builtin_tendall (void); 20813unsigned int __builtin_tresume (void); 20814unsigned int __builtin_tsuspend (void); 20815@end smallexample 20816 20817Note that the semantics of the above HTM builtins are required to mimic 20818the locking semantics used for critical sections. Builtins that are used 20819to create a new transaction or restart a suspended transaction must have 20820lock acquisition like semantics while those builtins that end or suspend a 20821transaction must have lock release like semantics. Specifically, this must 20822mimic lock semantics as specified by C++11, for example: Lock acquisition is 20823as-if an execution of __atomic_exchange_n(&globallock,1,__ATOMIC_ACQUIRE) 20824that returns 0, and lock release is as-if an execution of 20825__atomic_store(&globallock,0,__ATOMIC_RELEASE), with globallock being an 20826implicit implementation-defined lock used for all transactions. The HTM 20827instructions associated with with the builtins inherently provide the 20828correct acquisition and release hardware barriers required. However, 20829the compiler must also be prohibited from moving loads and stores across 20830the builtins in a way that would violate their semantics. This has been 20831accomplished by adding memory barriers to the associated HTM instructions 20832(which is a conservative approach to provide acquire and release semantics). 20833Earlier versions of the compiler did not treat the HTM instructions as 20834memory barriers. A @code{__TM_FENCE__} macro has been added, which can 20835be used to determine whether the current compiler treats HTM instructions 20836as memory barriers or not. This allows the user to explicitly add memory 20837barriers to their code when using an older version of the compiler. 20838 20839The following set of built-in functions are available to gain access 20840to the HTM specific special purpose registers. 20841 20842@smallexample 20843unsigned long __builtin_get_texasr (void); 20844unsigned long __builtin_get_texasru (void); 20845unsigned long __builtin_get_tfhar (void); 20846unsigned long __builtin_get_tfiar (void); 20847 20848void __builtin_set_texasr (unsigned long); 20849void __builtin_set_texasru (unsigned long); 20850void __builtin_set_tfhar (unsigned long); 20851void __builtin_set_tfiar (unsigned long); 20852@end smallexample 20853 20854Example usage of these low level built-in functions may look like: 20855 20856@smallexample 20857#include <htmintrin.h> 20858 20859int num_retries = 10; 20860 20861while (1) 20862 @{ 20863 if (__builtin_tbegin (0)) 20864 @{ 20865 /* Transaction State Initiated. */ 20866 if (is_locked (lock)) 20867 __builtin_tabort (0); 20868 ... transaction code... 20869 __builtin_tend (0); 20870 break; 20871 @} 20872 else 20873 @{ 20874 /* Transaction State Failed. Use locks if the transaction 20875 failure is "persistent" or we've tried too many times. */ 20876 if (num_retries-- <= 0 20877 || _TEXASRU_FAILURE_PERSISTENT (__builtin_get_texasru ())) 20878 @{ 20879 acquire_lock (lock); 20880 ... non transactional fallback path... 20881 release_lock (lock); 20882 break; 20883 @} 20884 @} 20885 @} 20886@end smallexample 20887 20888One final built-in function has been added that returns the value of 20889the 2-bit Transaction State field of the Machine Status Register (MSR) 20890as stored in @code{CR0}. 20891 20892@smallexample 20893unsigned long __builtin_ttest (void) 20894@end smallexample 20895 20896This built-in can be used to determine the current transaction state 20897using the following code example: 20898 20899@smallexample 20900#include <htmintrin.h> 20901 20902unsigned char tx_state = _HTM_STATE (__builtin_ttest ()); 20903 20904if (tx_state == _HTM_TRANSACTIONAL) 20905 @{ 20906 /* Code to use in transactional state. */ 20907 @} 20908else if (tx_state == _HTM_NONTRANSACTIONAL) 20909 @{ 20910 /* Code to use in non-transactional state. */ 20911 @} 20912else if (tx_state == _HTM_SUSPENDED) 20913 @{ 20914 /* Code to use in transaction suspended state. */ 20915 @} 20916@end smallexample 20917 20918@subsubsection PowerPC HTM High Level Inline Functions 20919 20920The following high level HTM interface is made available by including 20921@code{<htmxlintrin.h>} and using @option{-mhtm} or @option{-mcpu=CPU} 20922where CPU is `power8' or later. This interface is common between PowerPC 20923and S/390, allowing users to write one HTM source implementation that 20924can be compiled and executed on either system. 20925 20926@smallexample 20927long __TM_simple_begin (void); 20928long __TM_begin (void* const TM_buff); 20929long __TM_end (void); 20930void __TM_abort (void); 20931void __TM_named_abort (unsigned char const code); 20932void __TM_resume (void); 20933void __TM_suspend (void); 20934 20935long __TM_is_user_abort (void* const TM_buff); 20936long __TM_is_named_user_abort (void* const TM_buff, unsigned char *code); 20937long __TM_is_illegal (void* const TM_buff); 20938long __TM_is_footprint_exceeded (void* const TM_buff); 20939long __TM_nesting_depth (void* const TM_buff); 20940long __TM_is_nested_too_deep(void* const TM_buff); 20941long __TM_is_conflict(void* const TM_buff); 20942long __TM_is_failure_persistent(void* const TM_buff); 20943long __TM_failure_address(void* const TM_buff); 20944long long __TM_failure_code(void* const TM_buff); 20945@end smallexample 20946 20947Using these common set of HTM inline functions, we can create 20948a more portable version of the HTM example in the previous 20949section that will work on either PowerPC or S/390: 20950 20951@smallexample 20952#include <htmxlintrin.h> 20953 20954int num_retries = 10; 20955TM_buff_type TM_buff; 20956 20957while (1) 20958 @{ 20959 if (__TM_begin (TM_buff) == _HTM_TBEGIN_STARTED) 20960 @{ 20961 /* Transaction State Initiated. */ 20962 if (is_locked (lock)) 20963 __TM_abort (); 20964 ... transaction code... 20965 __TM_end (); 20966 break; 20967 @} 20968 else 20969 @{ 20970 /* Transaction State Failed. Use locks if the transaction 20971 failure is "persistent" or we've tried too many times. */ 20972 if (num_retries-- <= 0 20973 || __TM_is_failure_persistent (TM_buff)) 20974 @{ 20975 acquire_lock (lock); 20976 ... non transactional fallback path... 20977 release_lock (lock); 20978 break; 20979 @} 20980 @} 20981 @} 20982@end smallexample 20983 20984@node PowerPC Atomic Memory Operation Functions 20985@subsection PowerPC Atomic Memory Operation Functions 20986ISA 3.0 of the PowerPC added new atomic memory operation (amo) 20987instructions. GCC provides support for these instructions in 64-bit 20988environments. All of the functions are declared in the include file 20989@code{amo.h}. 20990 20991The functions supported are: 20992 20993@smallexample 20994#include <amo.h> 20995 20996uint32_t amo_lwat_add (uint32_t *, uint32_t); 20997uint32_t amo_lwat_xor (uint32_t *, uint32_t); 20998uint32_t amo_lwat_ior (uint32_t *, uint32_t); 20999uint32_t amo_lwat_and (uint32_t *, uint32_t); 21000uint32_t amo_lwat_umax (uint32_t *, uint32_t); 21001uint32_t amo_lwat_umin (uint32_t *, uint32_t); 21002uint32_t amo_lwat_swap (uint32_t *, uint32_t); 21003 21004int32_t amo_lwat_sadd (int32_t *, int32_t); 21005int32_t amo_lwat_smax (int32_t *, int32_t); 21006int32_t amo_lwat_smin (int32_t *, int32_t); 21007int32_t amo_lwat_sswap (int32_t *, int32_t); 21008 21009uint64_t amo_ldat_add (uint64_t *, uint64_t); 21010uint64_t amo_ldat_xor (uint64_t *, uint64_t); 21011uint64_t amo_ldat_ior (uint64_t *, uint64_t); 21012uint64_t amo_ldat_and (uint64_t *, uint64_t); 21013uint64_t amo_ldat_umax (uint64_t *, uint64_t); 21014uint64_t amo_ldat_umin (uint64_t *, uint64_t); 21015uint64_t amo_ldat_swap (uint64_t *, uint64_t); 21016 21017int64_t amo_ldat_sadd (int64_t *, int64_t); 21018int64_t amo_ldat_smax (int64_t *, int64_t); 21019int64_t amo_ldat_smin (int64_t *, int64_t); 21020int64_t amo_ldat_sswap (int64_t *, int64_t); 21021 21022void amo_stwat_add (uint32_t *, uint32_t); 21023void amo_stwat_xor (uint32_t *, uint32_t); 21024void amo_stwat_ior (uint32_t *, uint32_t); 21025void amo_stwat_and (uint32_t *, uint32_t); 21026void amo_stwat_umax (uint32_t *, uint32_t); 21027void amo_stwat_umin (uint32_t *, uint32_t); 21028 21029void amo_stwat_sadd (int32_t *, int32_t); 21030void amo_stwat_smax (int32_t *, int32_t); 21031void amo_stwat_smin (int32_t *, int32_t); 21032 21033void amo_stdat_add (uint64_t *, uint64_t); 21034void amo_stdat_xor (uint64_t *, uint64_t); 21035void amo_stdat_ior (uint64_t *, uint64_t); 21036void amo_stdat_and (uint64_t *, uint64_t); 21037void amo_stdat_umax (uint64_t *, uint64_t); 21038void amo_stdat_umin (uint64_t *, uint64_t); 21039 21040void amo_stdat_sadd (int64_t *, int64_t); 21041void amo_stdat_smax (int64_t *, int64_t); 21042void amo_stdat_smin (int64_t *, int64_t); 21043@end smallexample 21044 21045@node PowerPC Matrix-Multiply Assist Built-in Functions 21046@subsection PowerPC Matrix-Multiply Assist Built-in Functions 21047ISA 3.1 of the PowerPC added new Matrix-Multiply Assist (MMA) instructions. 21048GCC provides support for these instructions through the following built-in 21049functions which are enabled with the @code{-mmma} option. The vec_t type 21050below is defined to be a normal vector unsigned char type. The uint2, uint4 21051and uint8 parameters are 2-bit, 4-bit and 8-bit unsigned integer constants 21052respectively. The compiler will verify that they are constants and that 21053their values are within range. 21054 21055The built-in functions supported are: 21056 21057@smallexample 21058void __builtin_mma_xvi4ger8 (__vector_quad *, vec_t, vec_t); 21059void __builtin_mma_xvi8ger4 (__vector_quad *, vec_t, vec_t); 21060void __builtin_mma_xvi16ger2 (__vector_quad *, vec_t, vec_t); 21061void __builtin_mma_xvi16ger2s (__vector_quad *, vec_t, vec_t); 21062void __builtin_mma_xvf16ger2 (__vector_quad *, vec_t, vec_t); 21063void __builtin_mma_xvbf16ger2 (__vector_quad *, vec_t, vec_t); 21064void __builtin_mma_xvf32ger (__vector_quad *, vec_t, vec_t); 21065 21066void __builtin_mma_xvi4ger8pp (__vector_quad *, vec_t, vec_t); 21067void __builtin_mma_xvi8ger4pp (__vector_quad *, vec_t, vec_t); 21068void __builtin_mma_xvi8ger4spp(__vector_quad *, vec_t, vec_t); 21069void __builtin_mma_xvi16ger2pp (__vector_quad *, vec_t, vec_t); 21070void __builtin_mma_xvi16ger2spp (__vector_quad *, vec_t, vec_t); 21071void __builtin_mma_xvf16ger2pp (__vector_quad *, vec_t, vec_t); 21072void __builtin_mma_xvf16ger2pn (__vector_quad *, vec_t, vec_t); 21073void __builtin_mma_xvf16ger2np (__vector_quad *, vec_t, vec_t); 21074void __builtin_mma_xvf16ger2nn (__vector_quad *, vec_t, vec_t); 21075void __builtin_mma_xvbf16ger2pp (__vector_quad *, vec_t, vec_t); 21076void __builtin_mma_xvbf16ger2pn (__vector_quad *, vec_t, vec_t); 21077void __builtin_mma_xvbf16ger2np (__vector_quad *, vec_t, vec_t); 21078void __builtin_mma_xvbf16ger2nn (__vector_quad *, vec_t, vec_t); 21079void __builtin_mma_xvf32gerpp (__vector_quad *, vec_t, vec_t); 21080void __builtin_mma_xvf32gerpn (__vector_quad *, vec_t, vec_t); 21081void __builtin_mma_xvf32gernp (__vector_quad *, vec_t, vec_t); 21082void __builtin_mma_xvf32gernn (__vector_quad *, vec_t, vec_t); 21083 21084void __builtin_mma_pmxvi4ger8 (__vector_quad *, vec_t, vec_t, uint4, uint4, uint8); 21085void __builtin_mma_pmxvi4ger8pp (__vector_quad *, vec_t, vec_t, uint4, uint4, uint8); 21086 21087void __builtin_mma_pmxvi8ger4 (__vector_quad *, vec_t, vec_t, uint4, uint4, uint4); 21088void __builtin_mma_pmxvi8ger4pp (__vector_quad *, vec_t, vec_t, uint4, uint4, uint4); 21089void __builtin_mma_pmxvi8ger4spp(__vector_quad *, vec_t, vec_t, uint4, uint4, uint4); 21090 21091void __builtin_mma_pmxvi16ger2 (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2); 21092void __builtin_mma_pmxvi16ger2s (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2); 21093void __builtin_mma_pmxvf16ger2 (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2); 21094void __builtin_mma_pmxvbf16ger2 (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2); 21095 21096void __builtin_mma_pmxvi16ger2pp (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2); 21097void __builtin_mma_pmxvi16ger2spp (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2); 21098void __builtin_mma_pmxvf16ger2pp (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2); 21099void __builtin_mma_pmxvf16ger2pn (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2); 21100void __builtin_mma_pmxvf16ger2np (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2); 21101void __builtin_mma_pmxvf16ger2nn (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2); 21102void __builtin_mma_pmxvbf16ger2pp (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2); 21103void __builtin_mma_pmxvbf16ger2pn (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2); 21104void __builtin_mma_pmxvbf16ger2np (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2); 21105void __builtin_mma_pmxvbf16ger2nn (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2); 21106 21107void __builtin_mma_pmxvf32ger (__vector_quad *, vec_t, vec_t, uint4, uint4); 21108void __builtin_mma_pmxvf32gerpp (__vector_quad *, vec_t, vec_t, uint4, uint4); 21109void __builtin_mma_pmxvf32gerpn (__vector_quad *, vec_t, vec_t, uint4, uint4); 21110void __builtin_mma_pmxvf32gernp (__vector_quad *, vec_t, vec_t, uint4, uint4); 21111void __builtin_mma_pmxvf32gernn (__vector_quad *, vec_t, vec_t, uint4, uint4); 21112 21113void __builtin_mma_xvf64ger (__vector_quad *, __vector_pair, vec_t); 21114void __builtin_mma_xvf64gerpp (__vector_quad *, __vector_pair, vec_t); 21115void __builtin_mma_xvf64gerpn (__vector_quad *, __vector_pair, vec_t); 21116void __builtin_mma_xvf64gernp (__vector_quad *, __vector_pair, vec_t); 21117void __builtin_mma_xvf64gernn (__vector_quad *, __vector_pair, vec_t); 21118 21119void __builtin_mma_pmxvf64ger (__vector_quad *, __vector_pair, vec_t, uint4, uint2); 21120void __builtin_mma_pmxvf64gerpp (__vector_quad *, __vector_pair, vec_t, uint4, uint2); 21121void __builtin_mma_pmxvf64gerpn (__vector_quad *, __vector_pair, vec_t, uint4, uint2); 21122void __builtin_mma_pmxvf64gernp (__vector_quad *, __vector_pair, vec_t, uint4, uint2); 21123void __builtin_mma_pmxvf64gernn (__vector_quad *, __vector_pair, vec_t, uint4, uint2); 21124 21125void __builtin_mma_xxmtacc (__vector_quad *); 21126void __builtin_mma_xxmfacc (__vector_quad *); 21127void __builtin_mma_xxsetaccz (__vector_quad *); 21128 21129void __builtin_mma_build_acc (__vector_quad *, vec_t, vec_t, vec_t, vec_t); 21130void __builtin_mma_disassemble_acc (void *, __vector_quad *); 21131 21132void __builtin_vsx_build_pair (__vector_pair *, vec_t, vec_t); 21133void __builtin_vsx_disassemble_pair (void *, __vector_pair *); 21134 21135vec_t __builtin_vsx_xvcvspbf16 (vec_t); 21136vec_t __builtin_vsx_xvcvbf16spn (vec_t); 21137 21138__vector_pair __builtin_vsx_lxvp (size_t, __vector_pair *); 21139void __builtin_vsx_stxvp (__vector_pair, size_t, __vector_pair *); 21140@end smallexample 21141 21142@node PRU Built-in Functions 21143@subsection PRU Built-in Functions 21144 21145GCC provides a couple of special builtin functions to aid in utilizing 21146special PRU instructions. 21147 21148The built-in functions supported are: 21149 21150@table @code 21151@item __delay_cycles (long long @var{cycles}) 21152This inserts an instruction sequence that takes exactly @var{cycles} 21153cycles (between 0 and 0xffffffff) to complete. The inserted sequence 21154may use jumps, loops, or no-ops, and does not interfere with any other 21155instructions. Note that @var{cycles} must be a compile-time constant 21156integer - that is, you must pass a number, not a variable that may be 21157optimized to a constant later. The number of cycles delayed by this 21158builtin is exact. 21159 21160@item __halt (void) 21161This inserts a HALT instruction to stop processor execution. 21162 21163@item unsigned int __lmbd (unsigned int @var{wordval}, unsigned int @var{bitval}) 21164This inserts LMBD instruction to calculate the left-most bit with value 21165@var{bitval} in value @var{wordval}. Only the least significant bit 21166of @var{bitval} is taken into account. 21167@end table 21168 21169@node RISC-V Built-in Functions 21170@subsection RISC-V Built-in Functions 21171 21172These built-in functions are available for the RISC-V family of 21173processors. 21174 21175@deftypefn {Built-in Function} {void *} __builtin_thread_pointer (void) 21176Returns the value that is currently set in the @samp{tp} register. 21177@end deftypefn 21178 21179@node RX Built-in Functions 21180@subsection RX Built-in Functions 21181GCC supports some of the RX instructions which cannot be expressed in 21182the C programming language via the use of built-in functions. The 21183following functions are supported: 21184 21185@deftypefn {Built-in Function} void __builtin_rx_brk (void) 21186Generates the @code{brk} machine instruction. 21187@end deftypefn 21188 21189@deftypefn {Built-in Function} void __builtin_rx_clrpsw (int) 21190Generates the @code{clrpsw} machine instruction to clear the specified 21191bit in the processor status word. 21192@end deftypefn 21193 21194@deftypefn {Built-in Function} void __builtin_rx_int (int) 21195Generates the @code{int} machine instruction to generate an interrupt 21196with the specified value. 21197@end deftypefn 21198 21199@deftypefn {Built-in Function} void __builtin_rx_machi (int, int) 21200Generates the @code{machi} machine instruction to add the result of 21201multiplying the top 16 bits of the two arguments into the 21202accumulator. 21203@end deftypefn 21204 21205@deftypefn {Built-in Function} void __builtin_rx_maclo (int, int) 21206Generates the @code{maclo} machine instruction to add the result of 21207multiplying the bottom 16 bits of the two arguments into the 21208accumulator. 21209@end deftypefn 21210 21211@deftypefn {Built-in Function} void __builtin_rx_mulhi (int, int) 21212Generates the @code{mulhi} machine instruction to place the result of 21213multiplying the top 16 bits of the two arguments into the 21214accumulator. 21215@end deftypefn 21216 21217@deftypefn {Built-in Function} void __builtin_rx_mullo (int, int) 21218Generates the @code{mullo} machine instruction to place the result of 21219multiplying the bottom 16 bits of the two arguments into the 21220accumulator. 21221@end deftypefn 21222 21223@deftypefn {Built-in Function} int __builtin_rx_mvfachi (void) 21224Generates the @code{mvfachi} machine instruction to read the top 2122532 bits of the accumulator. 21226@end deftypefn 21227 21228@deftypefn {Built-in Function} int __builtin_rx_mvfacmi (void) 21229Generates the @code{mvfacmi} machine instruction to read the middle 2123032 bits of the accumulator. 21231@end deftypefn 21232 21233@deftypefn {Built-in Function} int __builtin_rx_mvfc (int) 21234Generates the @code{mvfc} machine instruction which reads the control 21235register specified in its argument and returns its value. 21236@end deftypefn 21237 21238@deftypefn {Built-in Function} void __builtin_rx_mvtachi (int) 21239Generates the @code{mvtachi} machine instruction to set the top 2124032 bits of the accumulator. 21241@end deftypefn 21242 21243@deftypefn {Built-in Function} void __builtin_rx_mvtaclo (int) 21244Generates the @code{mvtaclo} machine instruction to set the bottom 2124532 bits of the accumulator. 21246@end deftypefn 21247 21248@deftypefn {Built-in Function} void __builtin_rx_mvtc (int reg, int val) 21249Generates the @code{mvtc} machine instruction which sets control 21250register number @code{reg} to @code{val}. 21251@end deftypefn 21252 21253@deftypefn {Built-in Function} void __builtin_rx_mvtipl (int) 21254Generates the @code{mvtipl} machine instruction set the interrupt 21255priority level. 21256@end deftypefn 21257 21258@deftypefn {Built-in Function} void __builtin_rx_racw (int) 21259Generates the @code{racw} machine instruction to round the accumulator 21260according to the specified mode. 21261@end deftypefn 21262 21263@deftypefn {Built-in Function} int __builtin_rx_revw (int) 21264Generates the @code{revw} machine instruction which swaps the bytes in 21265the argument so that bits 0--7 now occupy bits 8--15 and vice versa, 21266and also bits 16--23 occupy bits 24--31 and vice versa. 21267@end deftypefn 21268 21269@deftypefn {Built-in Function} void __builtin_rx_rmpa (void) 21270Generates the @code{rmpa} machine instruction which initiates a 21271repeated multiply and accumulate sequence. 21272@end deftypefn 21273 21274@deftypefn {Built-in Function} void __builtin_rx_round (float) 21275Generates the @code{round} machine instruction which returns the 21276floating-point argument rounded according to the current rounding mode 21277set in the floating-point status word register. 21278@end deftypefn 21279 21280@deftypefn {Built-in Function} int __builtin_rx_sat (int) 21281Generates the @code{sat} machine instruction which returns the 21282saturated value of the argument. 21283@end deftypefn 21284 21285@deftypefn {Built-in Function} void __builtin_rx_setpsw (int) 21286Generates the @code{setpsw} machine instruction to set the specified 21287bit in the processor status word. 21288@end deftypefn 21289 21290@deftypefn {Built-in Function} void __builtin_rx_wait (void) 21291Generates the @code{wait} machine instruction. 21292@end deftypefn 21293 21294@node S/390 System z Built-in Functions 21295@subsection S/390 System z Built-in Functions 21296@deftypefn {Built-in Function} int __builtin_tbegin (void*) 21297Generates the @code{tbegin} machine instruction starting a 21298non-constrained hardware transaction. If the parameter is non-NULL the 21299memory area is used to store the transaction diagnostic buffer and 21300will be passed as first operand to @code{tbegin}. This buffer can be 21301defined using the @code{struct __htm_tdb} C struct defined in 21302@code{htmintrin.h} and must reside on a double-word boundary. The 21303second tbegin operand is set to @code{0xff0c}. This enables 21304save/restore of all GPRs and disables aborts for FPR and AR 21305manipulations inside the transaction body. The condition code set by 21306the tbegin instruction is returned as integer value. The tbegin 21307instruction by definition overwrites the content of all FPRs. The 21308compiler will generate code which saves and restores the FPRs. For 21309soft-float code it is recommended to used the @code{*_nofloat} 21310variant. In order to prevent a TDB from being written it is required 21311to pass a constant zero value as parameter. Passing a zero value 21312through a variable is not sufficient. Although modifications of 21313access registers inside the transaction will not trigger an 21314transaction abort it is not supported to actually modify them. Access 21315registers do not get saved when entering a transaction. They will have 21316undefined state when reaching the abort code. 21317@end deftypefn 21318 21319Macros for the possible return codes of tbegin are defined in the 21320@code{htmintrin.h} header file: 21321 21322@table @code 21323@item _HTM_TBEGIN_STARTED 21324@code{tbegin} has been executed as part of normal processing. The 21325transaction body is supposed to be executed. 21326@item _HTM_TBEGIN_INDETERMINATE 21327The transaction was aborted due to an indeterminate condition which 21328might be persistent. 21329@item _HTM_TBEGIN_TRANSIENT 21330The transaction aborted due to a transient failure. The transaction 21331should be re-executed in that case. 21332@item _HTM_TBEGIN_PERSISTENT 21333The transaction aborted due to a persistent failure. Re-execution 21334under same circumstances will not be productive. 21335@end table 21336 21337@defmac _HTM_FIRST_USER_ABORT_CODE 21338The @code{_HTM_FIRST_USER_ABORT_CODE} defined in @code{htmintrin.h} 21339specifies the first abort code which can be used for 21340@code{__builtin_tabort}. Values below this threshold are reserved for 21341machine use. 21342@end defmac 21343 21344@deftp {Data type} {struct __htm_tdb} 21345The @code{struct __htm_tdb} defined in @code{htmintrin.h} describes 21346the structure of the transaction diagnostic block as specified in the 21347Principles of Operation manual chapter 5-91. 21348@end deftp 21349 21350@deftypefn {Built-in Function} int __builtin_tbegin_nofloat (void*) 21351Same as @code{__builtin_tbegin} but without FPR saves and restores. 21352Using this variant in code making use of FPRs will leave the FPRs in 21353undefined state when entering the transaction abort handler code. 21354@end deftypefn 21355 21356@deftypefn {Built-in Function} int __builtin_tbegin_retry (void*, int) 21357In addition to @code{__builtin_tbegin} a loop for transient failures 21358is generated. If tbegin returns a condition code of 2 the transaction 21359will be retried as often as specified in the second argument. The 21360perform processor assist instruction is used to tell the CPU about the 21361number of fails so far. 21362@end deftypefn 21363 21364@deftypefn {Built-in Function} int __builtin_tbegin_retry_nofloat (void*, int) 21365Same as @code{__builtin_tbegin_retry} but without FPR saves and 21366restores. Using this variant in code making use of FPRs will leave 21367the FPRs in undefined state when entering the transaction abort 21368handler code. 21369@end deftypefn 21370 21371@deftypefn {Built-in Function} void __builtin_tbeginc (void) 21372Generates the @code{tbeginc} machine instruction starting a constrained 21373hardware transaction. The second operand is set to @code{0xff08}. 21374@end deftypefn 21375 21376@deftypefn {Built-in Function} int __builtin_tend (void) 21377Generates the @code{tend} machine instruction finishing a transaction 21378and making the changes visible to other threads. The condition code 21379generated by tend is returned as integer value. 21380@end deftypefn 21381 21382@deftypefn {Built-in Function} void __builtin_tabort (int) 21383Generates the @code{tabort} machine instruction with the specified 21384abort code. Abort codes from 0 through 255 are reserved and will 21385result in an error message. 21386@end deftypefn 21387 21388@deftypefn {Built-in Function} void __builtin_tx_assist (int) 21389Generates the @code{ppa rX,rY,1} machine instruction. Where the 21390integer parameter is loaded into rX and a value of zero is loaded into 21391rY. The integer parameter specifies the number of times the 21392transaction repeatedly aborted. 21393@end deftypefn 21394 21395@deftypefn {Built-in Function} int __builtin_tx_nesting_depth (void) 21396Generates the @code{etnd} machine instruction. The current nesting 21397depth is returned as integer value. For a nesting depth of 0 the code 21398is not executed as part of an transaction. 21399@end deftypefn 21400 21401@deftypefn {Built-in Function} void __builtin_non_tx_store (uint64_t *, uint64_t) 21402 21403Generates the @code{ntstg} machine instruction. The second argument 21404is written to the first arguments location. The store operation will 21405not be rolled-back in case of an transaction abort. 21406@end deftypefn 21407 21408@node SH Built-in Functions 21409@subsection SH Built-in Functions 21410The following built-in functions are supported on the SH1, SH2, SH3 and SH4 21411families of processors: 21412 21413@deftypefn {Built-in Function} {void} __builtin_set_thread_pointer (void *@var{ptr}) 21414Sets the @samp{GBR} register to the specified value @var{ptr}. This is usually 21415used by system code that manages threads and execution contexts. The compiler 21416normally does not generate code that modifies the contents of @samp{GBR} and 21417thus the value is preserved across function calls. Changing the @samp{GBR} 21418value in user code must be done with caution, since the compiler might use 21419@samp{GBR} in order to access thread local variables. 21420 21421@end deftypefn 21422 21423@deftypefn {Built-in Function} {void *} __builtin_thread_pointer (void) 21424Returns the value that is currently set in the @samp{GBR} register. 21425Memory loads and stores that use the thread pointer as a base address are 21426turned into @samp{GBR} based displacement loads and stores, if possible. 21427For example: 21428@smallexample 21429struct my_tcb 21430@{ 21431 int a, b, c, d, e; 21432@}; 21433 21434int get_tcb_value (void) 21435@{ 21436 // Generate @samp{mov.l @@(8,gbr),r0} instruction 21437 return ((my_tcb*)__builtin_thread_pointer ())->c; 21438@} 21439 21440@end smallexample 21441@end deftypefn 21442 21443@deftypefn {Built-in Function} {unsigned int} __builtin_sh_get_fpscr (void) 21444Returns the value that is currently set in the @samp{FPSCR} register. 21445@end deftypefn 21446 21447@deftypefn {Built-in Function} {void} __builtin_sh_set_fpscr (unsigned int @var{val}) 21448Sets the @samp{FPSCR} register to the specified value @var{val}, while 21449preserving the current values of the FR, SZ and PR bits. 21450@end deftypefn 21451 21452@node SPARC VIS Built-in Functions 21453@subsection SPARC VIS Built-in Functions 21454 21455GCC supports SIMD operations on the SPARC using both the generic vector 21456extensions (@pxref{Vector Extensions}) as well as built-in functions for 21457the SPARC Visual Instruction Set (VIS). When you use the @option{-mvis} 21458switch, the VIS extension is exposed as the following built-in functions: 21459 21460@smallexample 21461typedef int v1si __attribute__ ((vector_size (4))); 21462typedef int v2si __attribute__ ((vector_size (8))); 21463typedef short v4hi __attribute__ ((vector_size (8))); 21464typedef short v2hi __attribute__ ((vector_size (4))); 21465typedef unsigned char v8qi __attribute__ ((vector_size (8))); 21466typedef unsigned char v4qi __attribute__ ((vector_size (4))); 21467 21468void __builtin_vis_write_gsr (int64_t); 21469int64_t __builtin_vis_read_gsr (void); 21470 21471void * __builtin_vis_alignaddr (void *, long); 21472void * __builtin_vis_alignaddrl (void *, long); 21473int64_t __builtin_vis_faligndatadi (int64_t, int64_t); 21474v2si __builtin_vis_faligndatav2si (v2si, v2si); 21475v4hi __builtin_vis_faligndatav4hi (v4si, v4si); 21476v8qi __builtin_vis_faligndatav8qi (v8qi, v8qi); 21477 21478v4hi __builtin_vis_fexpand (v4qi); 21479 21480v4hi __builtin_vis_fmul8x16 (v4qi, v4hi); 21481v4hi __builtin_vis_fmul8x16au (v4qi, v2hi); 21482v4hi __builtin_vis_fmul8x16al (v4qi, v2hi); 21483v4hi __builtin_vis_fmul8sux16 (v8qi, v4hi); 21484v4hi __builtin_vis_fmul8ulx16 (v8qi, v4hi); 21485v2si __builtin_vis_fmuld8sux16 (v4qi, v2hi); 21486v2si __builtin_vis_fmuld8ulx16 (v4qi, v2hi); 21487 21488v4qi __builtin_vis_fpack16 (v4hi); 21489v8qi __builtin_vis_fpack32 (v2si, v8qi); 21490v2hi __builtin_vis_fpackfix (v2si); 21491v8qi __builtin_vis_fpmerge (v4qi, v4qi); 21492 21493int64_t __builtin_vis_pdist (v8qi, v8qi, int64_t); 21494 21495long __builtin_vis_edge8 (void *, void *); 21496long __builtin_vis_edge8l (void *, void *); 21497long __builtin_vis_edge16 (void *, void *); 21498long __builtin_vis_edge16l (void *, void *); 21499long __builtin_vis_edge32 (void *, void *); 21500long __builtin_vis_edge32l (void *, void *); 21501 21502long __builtin_vis_fcmple16 (v4hi, v4hi); 21503long __builtin_vis_fcmple32 (v2si, v2si); 21504long __builtin_vis_fcmpne16 (v4hi, v4hi); 21505long __builtin_vis_fcmpne32 (v2si, v2si); 21506long __builtin_vis_fcmpgt16 (v4hi, v4hi); 21507long __builtin_vis_fcmpgt32 (v2si, v2si); 21508long __builtin_vis_fcmpeq16 (v4hi, v4hi); 21509long __builtin_vis_fcmpeq32 (v2si, v2si); 21510 21511v4hi __builtin_vis_fpadd16 (v4hi, v4hi); 21512v2hi __builtin_vis_fpadd16s (v2hi, v2hi); 21513v2si __builtin_vis_fpadd32 (v2si, v2si); 21514v1si __builtin_vis_fpadd32s (v1si, v1si); 21515v4hi __builtin_vis_fpsub16 (v4hi, v4hi); 21516v2hi __builtin_vis_fpsub16s (v2hi, v2hi); 21517v2si __builtin_vis_fpsub32 (v2si, v2si); 21518v1si __builtin_vis_fpsub32s (v1si, v1si); 21519 21520long __builtin_vis_array8 (long, long); 21521long __builtin_vis_array16 (long, long); 21522long __builtin_vis_array32 (long, long); 21523@end smallexample 21524 21525When you use the @option{-mvis2} switch, the VIS version 2.0 built-in 21526functions also become available: 21527 21528@smallexample 21529long __builtin_vis_bmask (long, long); 21530int64_t __builtin_vis_bshuffledi (int64_t, int64_t); 21531v2si __builtin_vis_bshufflev2si (v2si, v2si); 21532v4hi __builtin_vis_bshufflev2si (v4hi, v4hi); 21533v8qi __builtin_vis_bshufflev2si (v8qi, v8qi); 21534 21535long __builtin_vis_edge8n (void *, void *); 21536long __builtin_vis_edge8ln (void *, void *); 21537long __builtin_vis_edge16n (void *, void *); 21538long __builtin_vis_edge16ln (void *, void *); 21539long __builtin_vis_edge32n (void *, void *); 21540long __builtin_vis_edge32ln (void *, void *); 21541@end smallexample 21542 21543When you use the @option{-mvis3} switch, the VIS version 3.0 built-in 21544functions also become available: 21545 21546@smallexample 21547void __builtin_vis_cmask8 (long); 21548void __builtin_vis_cmask16 (long); 21549void __builtin_vis_cmask32 (long); 21550 21551v4hi __builtin_vis_fchksm16 (v4hi, v4hi); 21552 21553v4hi __builtin_vis_fsll16 (v4hi, v4hi); 21554v4hi __builtin_vis_fslas16 (v4hi, v4hi); 21555v4hi __builtin_vis_fsrl16 (v4hi, v4hi); 21556v4hi __builtin_vis_fsra16 (v4hi, v4hi); 21557v2si __builtin_vis_fsll16 (v2si, v2si); 21558v2si __builtin_vis_fslas16 (v2si, v2si); 21559v2si __builtin_vis_fsrl16 (v2si, v2si); 21560v2si __builtin_vis_fsra16 (v2si, v2si); 21561 21562long __builtin_vis_pdistn (v8qi, v8qi); 21563 21564v4hi __builtin_vis_fmean16 (v4hi, v4hi); 21565 21566int64_t __builtin_vis_fpadd64 (int64_t, int64_t); 21567int64_t __builtin_vis_fpsub64 (int64_t, int64_t); 21568 21569v4hi __builtin_vis_fpadds16 (v4hi, v4hi); 21570v2hi __builtin_vis_fpadds16s (v2hi, v2hi); 21571v4hi __builtin_vis_fpsubs16 (v4hi, v4hi); 21572v2hi __builtin_vis_fpsubs16s (v2hi, v2hi); 21573v2si __builtin_vis_fpadds32 (v2si, v2si); 21574v1si __builtin_vis_fpadds32s (v1si, v1si); 21575v2si __builtin_vis_fpsubs32 (v2si, v2si); 21576v1si __builtin_vis_fpsubs32s (v1si, v1si); 21577 21578long __builtin_vis_fucmple8 (v8qi, v8qi); 21579long __builtin_vis_fucmpne8 (v8qi, v8qi); 21580long __builtin_vis_fucmpgt8 (v8qi, v8qi); 21581long __builtin_vis_fucmpeq8 (v8qi, v8qi); 21582 21583float __builtin_vis_fhadds (float, float); 21584double __builtin_vis_fhaddd (double, double); 21585float __builtin_vis_fhsubs (float, float); 21586double __builtin_vis_fhsubd (double, double); 21587float __builtin_vis_fnhadds (float, float); 21588double __builtin_vis_fnhaddd (double, double); 21589 21590int64_t __builtin_vis_umulxhi (int64_t, int64_t); 21591int64_t __builtin_vis_xmulx (int64_t, int64_t); 21592int64_t __builtin_vis_xmulxhi (int64_t, int64_t); 21593@end smallexample 21594 21595When you use the @option{-mvis4} switch, the VIS version 4.0 built-in 21596functions also become available: 21597 21598@smallexample 21599v8qi __builtin_vis_fpadd8 (v8qi, v8qi); 21600v8qi __builtin_vis_fpadds8 (v8qi, v8qi); 21601v8qi __builtin_vis_fpaddus8 (v8qi, v8qi); 21602v4hi __builtin_vis_fpaddus16 (v4hi, v4hi); 21603 21604v8qi __builtin_vis_fpsub8 (v8qi, v8qi); 21605v8qi __builtin_vis_fpsubs8 (v8qi, v8qi); 21606v8qi __builtin_vis_fpsubus8 (v8qi, v8qi); 21607v4hi __builtin_vis_fpsubus16 (v4hi, v4hi); 21608 21609long __builtin_vis_fpcmple8 (v8qi, v8qi); 21610long __builtin_vis_fpcmpgt8 (v8qi, v8qi); 21611long __builtin_vis_fpcmpule16 (v4hi, v4hi); 21612long __builtin_vis_fpcmpugt16 (v4hi, v4hi); 21613long __builtin_vis_fpcmpule32 (v2si, v2si); 21614long __builtin_vis_fpcmpugt32 (v2si, v2si); 21615 21616v8qi __builtin_vis_fpmax8 (v8qi, v8qi); 21617v4hi __builtin_vis_fpmax16 (v4hi, v4hi); 21618v2si __builtin_vis_fpmax32 (v2si, v2si); 21619 21620v8qi __builtin_vis_fpmaxu8 (v8qi, v8qi); 21621v4hi __builtin_vis_fpmaxu16 (v4hi, v4hi); 21622v2si __builtin_vis_fpmaxu32 (v2si, v2si); 21623 21624v8qi __builtin_vis_fpmin8 (v8qi, v8qi); 21625v4hi __builtin_vis_fpmin16 (v4hi, v4hi); 21626v2si __builtin_vis_fpmin32 (v2si, v2si); 21627 21628v8qi __builtin_vis_fpminu8 (v8qi, v8qi); 21629v4hi __builtin_vis_fpminu16 (v4hi, v4hi); 21630v2si __builtin_vis_fpminu32 (v2si, v2si); 21631@end smallexample 21632 21633When you use the @option{-mvis4b} switch, the VIS version 4.0B 21634built-in functions also become available: 21635 21636@smallexample 21637v8qi __builtin_vis_dictunpack8 (double, int); 21638v4hi __builtin_vis_dictunpack16 (double, int); 21639v2si __builtin_vis_dictunpack32 (double, int); 21640 21641long __builtin_vis_fpcmple8shl (v8qi, v8qi, int); 21642long __builtin_vis_fpcmpgt8shl (v8qi, v8qi, int); 21643long __builtin_vis_fpcmpeq8shl (v8qi, v8qi, int); 21644long __builtin_vis_fpcmpne8shl (v8qi, v8qi, int); 21645 21646long __builtin_vis_fpcmple16shl (v4hi, v4hi, int); 21647long __builtin_vis_fpcmpgt16shl (v4hi, v4hi, int); 21648long __builtin_vis_fpcmpeq16shl (v4hi, v4hi, int); 21649long __builtin_vis_fpcmpne16shl (v4hi, v4hi, int); 21650 21651long __builtin_vis_fpcmple32shl (v2si, v2si, int); 21652long __builtin_vis_fpcmpgt32shl (v2si, v2si, int); 21653long __builtin_vis_fpcmpeq32shl (v2si, v2si, int); 21654long __builtin_vis_fpcmpne32shl (v2si, v2si, int); 21655 21656long __builtin_vis_fpcmpule8shl (v8qi, v8qi, int); 21657long __builtin_vis_fpcmpugt8shl (v8qi, v8qi, int); 21658long __builtin_vis_fpcmpule16shl (v4hi, v4hi, int); 21659long __builtin_vis_fpcmpugt16shl (v4hi, v4hi, int); 21660long __builtin_vis_fpcmpule32shl (v2si, v2si, int); 21661long __builtin_vis_fpcmpugt32shl (v2si, v2si, int); 21662 21663long __builtin_vis_fpcmpde8shl (v8qi, v8qi, int); 21664long __builtin_vis_fpcmpde16shl (v4hi, v4hi, int); 21665long __builtin_vis_fpcmpde32shl (v2si, v2si, int); 21666 21667long __builtin_vis_fpcmpur8shl (v8qi, v8qi, int); 21668long __builtin_vis_fpcmpur16shl (v4hi, v4hi, int); 21669long __builtin_vis_fpcmpur32shl (v2si, v2si, int); 21670@end smallexample 21671 21672@node TI C6X Built-in Functions 21673@subsection TI C6X Built-in Functions 21674 21675GCC provides intrinsics to access certain instructions of the TI C6X 21676processors. These intrinsics, listed below, are available after 21677inclusion of the @code{c6x_intrinsics.h} header file. They map directly 21678to C6X instructions. 21679 21680@smallexample 21681int _sadd (int, int); 21682int _ssub (int, int); 21683int _sadd2 (int, int); 21684int _ssub2 (int, int); 21685long long _mpy2 (int, int); 21686long long _smpy2 (int, int); 21687int _add4 (int, int); 21688int _sub4 (int, int); 21689int _saddu4 (int, int); 21690 21691int _smpy (int, int); 21692int _smpyh (int, int); 21693int _smpyhl (int, int); 21694int _smpylh (int, int); 21695 21696int _sshl (int, int); 21697int _subc (int, int); 21698 21699int _avg2 (int, int); 21700int _avgu4 (int, int); 21701 21702int _clrr (int, int); 21703int _extr (int, int); 21704int _extru (int, int); 21705int _abs (int); 21706int _abs2 (int); 21707@end smallexample 21708 21709@node TILE-Gx Built-in Functions 21710@subsection TILE-Gx Built-in Functions 21711 21712GCC provides intrinsics to access every instruction of the TILE-Gx 21713processor. The intrinsics are of the form: 21714 21715@smallexample 21716 21717unsigned long long __insn_@var{op} (...) 21718 21719@end smallexample 21720 21721Where @var{op} is the name of the instruction. Refer to the ISA manual 21722for the complete list of instructions. 21723 21724GCC also provides intrinsics to directly access the network registers. 21725The intrinsics are: 21726 21727@smallexample 21728unsigned long long __tile_idn0_receive (void); 21729unsigned long long __tile_idn1_receive (void); 21730unsigned long long __tile_udn0_receive (void); 21731unsigned long long __tile_udn1_receive (void); 21732unsigned long long __tile_udn2_receive (void); 21733unsigned long long __tile_udn3_receive (void); 21734void __tile_idn_send (unsigned long long); 21735void __tile_udn_send (unsigned long long); 21736@end smallexample 21737 21738The intrinsic @code{void __tile_network_barrier (void)} is used to 21739guarantee that no network operations before it are reordered with 21740those after it. 21741 21742@node TILEPro Built-in Functions 21743@subsection TILEPro Built-in Functions 21744 21745GCC provides intrinsics to access every instruction of the TILEPro 21746processor. The intrinsics are of the form: 21747 21748@smallexample 21749 21750unsigned __insn_@var{op} (...) 21751 21752@end smallexample 21753 21754@noindent 21755where @var{op} is the name of the instruction. Refer to the ISA manual 21756for the complete list of instructions. 21757 21758GCC also provides intrinsics to directly access the network registers. 21759The intrinsics are: 21760 21761@smallexample 21762unsigned __tile_idn0_receive (void); 21763unsigned __tile_idn1_receive (void); 21764unsigned __tile_sn_receive (void); 21765unsigned __tile_udn0_receive (void); 21766unsigned __tile_udn1_receive (void); 21767unsigned __tile_udn2_receive (void); 21768unsigned __tile_udn3_receive (void); 21769void __tile_idn_send (unsigned); 21770void __tile_sn_send (unsigned); 21771void __tile_udn_send (unsigned); 21772@end smallexample 21773 21774The intrinsic @code{void __tile_network_barrier (void)} is used to 21775guarantee that no network operations before it are reordered with 21776those after it. 21777 21778@node x86 Built-in Functions 21779@subsection x86 Built-in Functions 21780 21781These built-in functions are available for the x86-32 and x86-64 family 21782of computers, depending on the command-line switches used. 21783 21784If you specify command-line switches such as @option{-msse}, 21785the compiler could use the extended instruction sets even if the built-ins 21786are not used explicitly in the program. For this reason, applications 21787that perform run-time CPU detection must compile separate files for each 21788supported architecture, using the appropriate flags. In particular, 21789the file containing the CPU detection code should be compiled without 21790these options. 21791 21792The following machine modes are available for use with MMX built-in functions 21793(@pxref{Vector Extensions}): @code{V2SI} for a vector of two 32-bit integers, 21794@code{V4HI} for a vector of four 16-bit integers, and @code{V8QI} for a 21795vector of eight 8-bit integers. Some of the built-in functions operate on 21796MMX registers as a whole 64-bit entity, these use @code{V1DI} as their mode. 21797 21798If 3DNow!@: extensions are enabled, @code{V2SF} is used as a mode for a vector 21799of two 32-bit floating-point values. 21800 21801If SSE extensions are enabled, @code{V4SF} is used for a vector of four 32-bit 21802floating-point values. Some instructions use a vector of four 32-bit 21803integers, these use @code{V4SI}. Finally, some instructions operate on an 21804entire vector register, interpreting it as a 128-bit integer, these use mode 21805@code{TI}. 21806 21807The x86-32 and x86-64 family of processors use additional built-in 21808functions for efficient use of @code{TF} (@code{__float128}) 128-bit 21809floating point and @code{TC} 128-bit complex floating-point values. 21810 21811The following floating-point built-in functions are always available. All 21812of them implement the function that is part of the name. 21813 21814@smallexample 21815__float128 __builtin_fabsq (__float128) 21816__float128 __builtin_copysignq (__float128, __float128) 21817@end smallexample 21818 21819The following built-in functions are always available. 21820 21821@table @code 21822@item __float128 __builtin_infq (void) 21823Similar to @code{__builtin_inf}, except the return type is @code{__float128}. 21824@findex __builtin_infq 21825 21826@item __float128 __builtin_huge_valq (void) 21827Similar to @code{__builtin_huge_val}, except the return type is @code{__float128}. 21828@findex __builtin_huge_valq 21829 21830@item __float128 __builtin_nanq (void) 21831Similar to @code{__builtin_nan}, except the return type is @code{__float128}. 21832@findex __builtin_nanq 21833 21834@item __float128 __builtin_nansq (void) 21835Similar to @code{__builtin_nans}, except the return type is @code{__float128}. 21836@findex __builtin_nansq 21837@end table 21838 21839The following built-in function is always available. 21840 21841@table @code 21842@item void __builtin_ia32_pause (void) 21843Generates the @code{pause} machine instruction with a compiler memory 21844barrier. 21845@end table 21846 21847The following built-in functions are always available and can be used to 21848check the target platform type. 21849 21850@deftypefn {Built-in Function} void __builtin_cpu_init (void) 21851This function runs the CPU detection code to check the type of CPU and the 21852features supported. This built-in function needs to be invoked along with the built-in functions 21853to check CPU type and features, @code{__builtin_cpu_is} and 21854@code{__builtin_cpu_supports}, only when used in a function that is 21855executed before any constructors are called. The CPU detection code is 21856automatically executed in a very high priority constructor. 21857 21858For example, this function has to be used in @code{ifunc} resolvers that 21859check for CPU type using the built-in functions @code{__builtin_cpu_is} 21860and @code{__builtin_cpu_supports}, or in constructors on targets that 21861don't support constructor priority. 21862@smallexample 21863 21864static void (*resolve_memcpy (void)) (void) 21865@{ 21866 // ifunc resolvers fire before constructors, explicitly call the init 21867 // function. 21868 __builtin_cpu_init (); 21869 if (__builtin_cpu_supports ("ssse3")) 21870 return ssse3_memcpy; // super fast memcpy with ssse3 instructions. 21871 else 21872 return default_memcpy; 21873@} 21874 21875void *memcpy (void *, const void *, size_t) 21876 __attribute__ ((ifunc ("resolve_memcpy"))); 21877@end smallexample 21878 21879@end deftypefn 21880 21881@deftypefn {Built-in Function} int __builtin_cpu_is (const char *@var{cpuname}) 21882This function returns a positive integer if the run-time CPU 21883is of type @var{cpuname} 21884and returns @code{0} otherwise. The following CPU names can be detected: 21885 21886@table @samp 21887@item amd 21888AMD CPU. 21889 21890@item intel 21891Intel CPU. 21892 21893@item atom 21894Intel Atom CPU. 21895 21896@item slm 21897Intel Silvermont CPU. 21898 21899@item core2 21900Intel Core 2 CPU. 21901 21902@item corei7 21903Intel Core i7 CPU. 21904 21905@item nehalem 21906Intel Core i7 Nehalem CPU. 21907 21908@item westmere 21909Intel Core i7 Westmere CPU. 21910 21911@item sandybridge 21912Intel Core i7 Sandy Bridge CPU. 21913 21914@item ivybridge 21915Intel Core i7 Ivy Bridge CPU. 21916 21917@item haswell 21918Intel Core i7 Haswell CPU. 21919 21920@item broadwell 21921Intel Core i7 Broadwell CPU. 21922 21923@item skylake 21924Intel Core i7 Skylake CPU. 21925 21926@item skylake-avx512 21927Intel Core i7 Skylake AVX512 CPU. 21928 21929@item cannonlake 21930Intel Core i7 Cannon Lake CPU. 21931 21932@item icelake-client 21933Intel Core i7 Ice Lake Client CPU. 21934 21935@item icelake-server 21936Intel Core i7 Ice Lake Server CPU. 21937 21938@item cascadelake 21939Intel Core i7 Cascadelake CPU. 21940 21941@item tigerlake 21942Intel Core i7 Tigerlake CPU. 21943 21944@item cooperlake 21945Intel Core i7 Cooperlake CPU. 21946 21947@item sapphirerapids 21948Intel Core i7 sapphirerapids CPU. 21949 21950@item alderlake 21951Intel Core i7 Alderlake CPU. 21952 21953@item rocketlake 21954Intel Core i7 Rocketlake CPU. 21955 21956@item bonnell 21957Intel Atom Bonnell CPU. 21958 21959@item silvermont 21960Intel Atom Silvermont CPU. 21961 21962@item goldmont 21963Intel Atom Goldmont CPU. 21964 21965@item goldmont-plus 21966Intel Atom Goldmont Plus CPU. 21967 21968@item tremont 21969Intel Atom Tremont CPU. 21970 21971@item knl 21972Intel Knights Landing CPU. 21973 21974@item knm 21975Intel Knights Mill CPU. 21976 21977@item amdfam10h 21978AMD Family 10h CPU. 21979 21980@item barcelona 21981AMD Family 10h Barcelona CPU. 21982 21983@item shanghai 21984AMD Family 10h Shanghai CPU. 21985 21986@item istanbul 21987AMD Family 10h Istanbul CPU. 21988 21989@item btver1 21990AMD Family 14h CPU. 21991 21992@item amdfam15h 21993AMD Family 15h CPU. 21994 21995@item bdver1 21996AMD Family 15h Bulldozer version 1. 21997 21998@item bdver2 21999AMD Family 15h Bulldozer version 2. 22000 22001@item bdver3 22002AMD Family 15h Bulldozer version 3. 22003 22004@item bdver4 22005AMD Family 15h Bulldozer version 4. 22006 22007@item btver2 22008AMD Family 16h CPU. 22009 22010@item amdfam17h 22011AMD Family 17h CPU. 22012 22013@item znver1 22014AMD Family 17h Zen version 1. 22015 22016@item znver2 22017AMD Family 17h Zen version 2. 22018 22019@item amdfam19h 22020AMD Family 19h CPU. 22021 22022@item znver3 22023AMD Family 19h Zen version 3. 22024 22025@item znver4 22026AMD Family 19h Zen version 4. 22027@end table 22028 22029Here is an example: 22030@smallexample 22031if (__builtin_cpu_is ("corei7")) 22032 @{ 22033 do_corei7 (); // Core i7 specific implementation. 22034 @} 22035else 22036 @{ 22037 do_generic (); // Generic implementation. 22038 @} 22039@end smallexample 22040@end deftypefn 22041 22042@deftypefn {Built-in Function} int __builtin_cpu_supports (const char *@var{feature}) 22043This function returns a positive integer if the run-time CPU 22044supports @var{feature} 22045and returns @code{0} otherwise. The following features can be detected: 22046 22047@table @samp 22048@item cmov 22049CMOV instruction. 22050@item mmx 22051MMX instructions. 22052@item popcnt 22053POPCNT instruction. 22054@item sse 22055SSE instructions. 22056@item sse2 22057SSE2 instructions. 22058@item sse3 22059SSE3 instructions. 22060@item ssse3 22061SSSE3 instructions. 22062@item sse4.1 22063SSE4.1 instructions. 22064@item sse4.2 22065SSE4.2 instructions. 22066@item avx 22067AVX instructions. 22068@item avx2 22069AVX2 instructions. 22070@item sse4a 22071SSE4A instructions. 22072@item fma4 22073FMA4 instructions. 22074@item xop 22075XOP instructions. 22076@item fma 22077FMA instructions. 22078@item avx512f 22079AVX512F instructions. 22080@item bmi 22081BMI instructions. 22082@item bmi2 22083BMI2 instructions. 22084@item aes 22085AES instructions. 22086@item pclmul 22087PCLMUL instructions. 22088@item avx512vl 22089AVX512VL instructions. 22090@item avx512bw 22091AVX512BW instructions. 22092@item avx512dq 22093AVX512DQ instructions. 22094@item avx512cd 22095AVX512CD instructions. 22096@item avx512er 22097AVX512ER instructions. 22098@item avx512pf 22099AVX512PF instructions. 22100@item avx512vbmi 22101AVX512VBMI instructions. 22102@item avx512ifma 22103AVX512IFMA instructions. 22104@item avx5124vnniw 22105AVX5124VNNIW instructions. 22106@item avx5124fmaps 22107AVX5124FMAPS instructions. 22108@item avx512vpopcntdq 22109AVX512VPOPCNTDQ instructions. 22110@item avx512vbmi2 22111AVX512VBMI2 instructions. 22112@item gfni 22113GFNI instructions. 22114@item vpclmulqdq 22115VPCLMULQDQ instructions. 22116@item avx512vnni 22117AVX512VNNI instructions. 22118@item avx512bitalg 22119AVX512BITALG instructions. 22120@item x86-64 22121Baseline x86-64 microarchitecture level (as defined in x86-64 psABI). 22122@item x86-64-v2 22123x86-64-v2 microarchitecture level. 22124@item x86-64-v3 22125x86-64-v3 microarchitecture level. 22126@item x86-64-v4 22127x86-64-v4 microarchitecture level. 22128 22129 22130@end table 22131 22132Here is an example: 22133@smallexample 22134if (__builtin_cpu_supports ("popcnt")) 22135 @{ 22136 asm("popcnt %1,%0" : "=r"(count) : "rm"(n) : "cc"); 22137 @} 22138else 22139 @{ 22140 count = generic_countbits (n); //generic implementation. 22141 @} 22142@end smallexample 22143@end deftypefn 22144 22145The following built-in functions are made available by @option{-mmmx}. 22146All of them generate the machine instruction that is part of the name. 22147 22148@smallexample 22149v8qi __builtin_ia32_paddb (v8qi, v8qi); 22150v4hi __builtin_ia32_paddw (v4hi, v4hi); 22151v2si __builtin_ia32_paddd (v2si, v2si); 22152v8qi __builtin_ia32_psubb (v8qi, v8qi); 22153v4hi __builtin_ia32_psubw (v4hi, v4hi); 22154v2si __builtin_ia32_psubd (v2si, v2si); 22155v8qi __builtin_ia32_paddsb (v8qi, v8qi); 22156v4hi __builtin_ia32_paddsw (v4hi, v4hi); 22157v8qi __builtin_ia32_psubsb (v8qi, v8qi); 22158v4hi __builtin_ia32_psubsw (v4hi, v4hi); 22159v8qi __builtin_ia32_paddusb (v8qi, v8qi); 22160v4hi __builtin_ia32_paddusw (v4hi, v4hi); 22161v8qi __builtin_ia32_psubusb (v8qi, v8qi); 22162v4hi __builtin_ia32_psubusw (v4hi, v4hi); 22163v4hi __builtin_ia32_pmullw (v4hi, v4hi); 22164v4hi __builtin_ia32_pmulhw (v4hi, v4hi); 22165di __builtin_ia32_pand (di, di); 22166di __builtin_ia32_pandn (di,di); 22167di __builtin_ia32_por (di, di); 22168di __builtin_ia32_pxor (di, di); 22169v8qi __builtin_ia32_pcmpeqb (v8qi, v8qi); 22170v4hi __builtin_ia32_pcmpeqw (v4hi, v4hi); 22171v2si __builtin_ia32_pcmpeqd (v2si, v2si); 22172v8qi __builtin_ia32_pcmpgtb (v8qi, v8qi); 22173v4hi __builtin_ia32_pcmpgtw (v4hi, v4hi); 22174v2si __builtin_ia32_pcmpgtd (v2si, v2si); 22175v8qi __builtin_ia32_punpckhbw (v8qi, v8qi); 22176v4hi __builtin_ia32_punpckhwd (v4hi, v4hi); 22177v2si __builtin_ia32_punpckhdq (v2si, v2si); 22178v8qi __builtin_ia32_punpcklbw (v8qi, v8qi); 22179v4hi __builtin_ia32_punpcklwd (v4hi, v4hi); 22180v2si __builtin_ia32_punpckldq (v2si, v2si); 22181v8qi __builtin_ia32_packsswb (v4hi, v4hi); 22182v4hi __builtin_ia32_packssdw (v2si, v2si); 22183v8qi __builtin_ia32_packuswb (v4hi, v4hi); 22184 22185v4hi __builtin_ia32_psllw (v4hi, v4hi); 22186v2si __builtin_ia32_pslld (v2si, v2si); 22187v1di __builtin_ia32_psllq (v1di, v1di); 22188v4hi __builtin_ia32_psrlw (v4hi, v4hi); 22189v2si __builtin_ia32_psrld (v2si, v2si); 22190v1di __builtin_ia32_psrlq (v1di, v1di); 22191v4hi __builtin_ia32_psraw (v4hi, v4hi); 22192v2si __builtin_ia32_psrad (v2si, v2si); 22193v4hi __builtin_ia32_psllwi (v4hi, int); 22194v2si __builtin_ia32_pslldi (v2si, int); 22195v1di __builtin_ia32_psllqi (v1di, int); 22196v4hi __builtin_ia32_psrlwi (v4hi, int); 22197v2si __builtin_ia32_psrldi (v2si, int); 22198v1di __builtin_ia32_psrlqi (v1di, int); 22199v4hi __builtin_ia32_psrawi (v4hi, int); 22200v2si __builtin_ia32_psradi (v2si, int); 22201@end smallexample 22202 22203The following built-in functions are made available either with 22204@option{-msse}, or with @option{-m3dnowa}. All of them generate 22205the machine instruction that is part of the name. 22206 22207@smallexample 22208v4hi __builtin_ia32_pmulhuw (v4hi, v4hi); 22209v8qi __builtin_ia32_pavgb (v8qi, v8qi); 22210v4hi __builtin_ia32_pavgw (v4hi, v4hi); 22211v1di __builtin_ia32_psadbw (v8qi, v8qi); 22212v8qi __builtin_ia32_pmaxub (v8qi, v8qi); 22213v4hi __builtin_ia32_pmaxsw (v4hi, v4hi); 22214v8qi __builtin_ia32_pminub (v8qi, v8qi); 22215v4hi __builtin_ia32_pminsw (v4hi, v4hi); 22216int __builtin_ia32_pmovmskb (v8qi); 22217void __builtin_ia32_maskmovq (v8qi, v8qi, char *); 22218void __builtin_ia32_movntq (di *, di); 22219void __builtin_ia32_sfence (void); 22220@end smallexample 22221 22222The following built-in functions are available when @option{-msse} is used. 22223All of them generate the machine instruction that is part of the name. 22224 22225@smallexample 22226int __builtin_ia32_comieq (v4sf, v4sf); 22227int __builtin_ia32_comineq (v4sf, v4sf); 22228int __builtin_ia32_comilt (v4sf, v4sf); 22229int __builtin_ia32_comile (v4sf, v4sf); 22230int __builtin_ia32_comigt (v4sf, v4sf); 22231int __builtin_ia32_comige (v4sf, v4sf); 22232int __builtin_ia32_ucomieq (v4sf, v4sf); 22233int __builtin_ia32_ucomineq (v4sf, v4sf); 22234int __builtin_ia32_ucomilt (v4sf, v4sf); 22235int __builtin_ia32_ucomile (v4sf, v4sf); 22236int __builtin_ia32_ucomigt (v4sf, v4sf); 22237int __builtin_ia32_ucomige (v4sf, v4sf); 22238v4sf __builtin_ia32_addps (v4sf, v4sf); 22239v4sf __builtin_ia32_subps (v4sf, v4sf); 22240v4sf __builtin_ia32_mulps (v4sf, v4sf); 22241v4sf __builtin_ia32_divps (v4sf, v4sf); 22242v4sf __builtin_ia32_addss (v4sf, v4sf); 22243v4sf __builtin_ia32_subss (v4sf, v4sf); 22244v4sf __builtin_ia32_mulss (v4sf, v4sf); 22245v4sf __builtin_ia32_divss (v4sf, v4sf); 22246v4sf __builtin_ia32_cmpeqps (v4sf, v4sf); 22247v4sf __builtin_ia32_cmpltps (v4sf, v4sf); 22248v4sf __builtin_ia32_cmpleps (v4sf, v4sf); 22249v4sf __builtin_ia32_cmpgtps (v4sf, v4sf); 22250v4sf __builtin_ia32_cmpgeps (v4sf, v4sf); 22251v4sf __builtin_ia32_cmpunordps (v4sf, v4sf); 22252v4sf __builtin_ia32_cmpneqps (v4sf, v4sf); 22253v4sf __builtin_ia32_cmpnltps (v4sf, v4sf); 22254v4sf __builtin_ia32_cmpnleps (v4sf, v4sf); 22255v4sf __builtin_ia32_cmpngtps (v4sf, v4sf); 22256v4sf __builtin_ia32_cmpngeps (v4sf, v4sf); 22257v4sf __builtin_ia32_cmpordps (v4sf, v4sf); 22258v4sf __builtin_ia32_cmpeqss (v4sf, v4sf); 22259v4sf __builtin_ia32_cmpltss (v4sf, v4sf); 22260v4sf __builtin_ia32_cmpless (v4sf, v4sf); 22261v4sf __builtin_ia32_cmpunordss (v4sf, v4sf); 22262v4sf __builtin_ia32_cmpneqss (v4sf, v4sf); 22263v4sf __builtin_ia32_cmpnltss (v4sf, v4sf); 22264v4sf __builtin_ia32_cmpnless (v4sf, v4sf); 22265v4sf __builtin_ia32_cmpordss (v4sf, v4sf); 22266v4sf __builtin_ia32_maxps (v4sf, v4sf); 22267v4sf __builtin_ia32_maxss (v4sf, v4sf); 22268v4sf __builtin_ia32_minps (v4sf, v4sf); 22269v4sf __builtin_ia32_minss (v4sf, v4sf); 22270v4sf __builtin_ia32_andps (v4sf, v4sf); 22271v4sf __builtin_ia32_andnps (v4sf, v4sf); 22272v4sf __builtin_ia32_orps (v4sf, v4sf); 22273v4sf __builtin_ia32_xorps (v4sf, v4sf); 22274v4sf __builtin_ia32_movss (v4sf, v4sf); 22275v4sf __builtin_ia32_movhlps (v4sf, v4sf); 22276v4sf __builtin_ia32_movlhps (v4sf, v4sf); 22277v4sf __builtin_ia32_unpckhps (v4sf, v4sf); 22278v4sf __builtin_ia32_unpcklps (v4sf, v4sf); 22279v4sf __builtin_ia32_cvtpi2ps (v4sf, v2si); 22280v4sf __builtin_ia32_cvtsi2ss (v4sf, int); 22281v2si __builtin_ia32_cvtps2pi (v4sf); 22282int __builtin_ia32_cvtss2si (v4sf); 22283v2si __builtin_ia32_cvttps2pi (v4sf); 22284int __builtin_ia32_cvttss2si (v4sf); 22285v4sf __builtin_ia32_rcpps (v4sf); 22286v4sf __builtin_ia32_rsqrtps (v4sf); 22287v4sf __builtin_ia32_sqrtps (v4sf); 22288v4sf __builtin_ia32_rcpss (v4sf); 22289v4sf __builtin_ia32_rsqrtss (v4sf); 22290v4sf __builtin_ia32_sqrtss (v4sf); 22291v4sf __builtin_ia32_shufps (v4sf, v4sf, int); 22292void __builtin_ia32_movntps (float *, v4sf); 22293int __builtin_ia32_movmskps (v4sf); 22294@end smallexample 22295 22296The following built-in functions are available when @option{-msse} is used. 22297 22298@table @code 22299@item v4sf __builtin_ia32_loadups (float *) 22300Generates the @code{movups} machine instruction as a load from memory. 22301@item void __builtin_ia32_storeups (float *, v4sf) 22302Generates the @code{movups} machine instruction as a store to memory. 22303@item v4sf __builtin_ia32_loadss (float *) 22304Generates the @code{movss} machine instruction as a load from memory. 22305@item v4sf __builtin_ia32_loadhps (v4sf, const v2sf *) 22306Generates the @code{movhps} machine instruction as a load from memory. 22307@item v4sf __builtin_ia32_loadlps (v4sf, const v2sf *) 22308Generates the @code{movlps} machine instruction as a load from memory 22309@item void __builtin_ia32_storehps (v2sf *, v4sf) 22310Generates the @code{movhps} machine instruction as a store to memory. 22311@item void __builtin_ia32_storelps (v2sf *, v4sf) 22312Generates the @code{movlps} machine instruction as a store to memory. 22313@end table 22314 22315The following built-in functions are available when @option{-msse2} is used. 22316All of them generate the machine instruction that is part of the name. 22317 22318@smallexample 22319int __builtin_ia32_comisdeq (v2df, v2df); 22320int __builtin_ia32_comisdlt (v2df, v2df); 22321int __builtin_ia32_comisdle (v2df, v2df); 22322int __builtin_ia32_comisdgt (v2df, v2df); 22323int __builtin_ia32_comisdge (v2df, v2df); 22324int __builtin_ia32_comisdneq (v2df, v2df); 22325int __builtin_ia32_ucomisdeq (v2df, v2df); 22326int __builtin_ia32_ucomisdlt (v2df, v2df); 22327int __builtin_ia32_ucomisdle (v2df, v2df); 22328int __builtin_ia32_ucomisdgt (v2df, v2df); 22329int __builtin_ia32_ucomisdge (v2df, v2df); 22330int __builtin_ia32_ucomisdneq (v2df, v2df); 22331v2df __builtin_ia32_cmpeqpd (v2df, v2df); 22332v2df __builtin_ia32_cmpltpd (v2df, v2df); 22333v2df __builtin_ia32_cmplepd (v2df, v2df); 22334v2df __builtin_ia32_cmpgtpd (v2df, v2df); 22335v2df __builtin_ia32_cmpgepd (v2df, v2df); 22336v2df __builtin_ia32_cmpunordpd (v2df, v2df); 22337v2df __builtin_ia32_cmpneqpd (v2df, v2df); 22338v2df __builtin_ia32_cmpnltpd (v2df, v2df); 22339v2df __builtin_ia32_cmpnlepd (v2df, v2df); 22340v2df __builtin_ia32_cmpngtpd (v2df, v2df); 22341v2df __builtin_ia32_cmpngepd (v2df, v2df); 22342v2df __builtin_ia32_cmpordpd (v2df, v2df); 22343v2df __builtin_ia32_cmpeqsd (v2df, v2df); 22344v2df __builtin_ia32_cmpltsd (v2df, v2df); 22345v2df __builtin_ia32_cmplesd (v2df, v2df); 22346v2df __builtin_ia32_cmpunordsd (v2df, v2df); 22347v2df __builtin_ia32_cmpneqsd (v2df, v2df); 22348v2df __builtin_ia32_cmpnltsd (v2df, v2df); 22349v2df __builtin_ia32_cmpnlesd (v2df, v2df); 22350v2df __builtin_ia32_cmpordsd (v2df, v2df); 22351v2di __builtin_ia32_paddq (v2di, v2di); 22352v2di __builtin_ia32_psubq (v2di, v2di); 22353v2df __builtin_ia32_addpd (v2df, v2df); 22354v2df __builtin_ia32_subpd (v2df, v2df); 22355v2df __builtin_ia32_mulpd (v2df, v2df); 22356v2df __builtin_ia32_divpd (v2df, v2df); 22357v2df __builtin_ia32_addsd (v2df, v2df); 22358v2df __builtin_ia32_subsd (v2df, v2df); 22359v2df __builtin_ia32_mulsd (v2df, v2df); 22360v2df __builtin_ia32_divsd (v2df, v2df); 22361v2df __builtin_ia32_minpd (v2df, v2df); 22362v2df __builtin_ia32_maxpd (v2df, v2df); 22363v2df __builtin_ia32_minsd (v2df, v2df); 22364v2df __builtin_ia32_maxsd (v2df, v2df); 22365v2df __builtin_ia32_andpd (v2df, v2df); 22366v2df __builtin_ia32_andnpd (v2df, v2df); 22367v2df __builtin_ia32_orpd (v2df, v2df); 22368v2df __builtin_ia32_xorpd (v2df, v2df); 22369v2df __builtin_ia32_movsd (v2df, v2df); 22370v2df __builtin_ia32_unpckhpd (v2df, v2df); 22371v2df __builtin_ia32_unpcklpd (v2df, v2df); 22372v16qi __builtin_ia32_paddb128 (v16qi, v16qi); 22373v8hi __builtin_ia32_paddw128 (v8hi, v8hi); 22374v4si __builtin_ia32_paddd128 (v4si, v4si); 22375v2di __builtin_ia32_paddq128 (v2di, v2di); 22376v16qi __builtin_ia32_psubb128 (v16qi, v16qi); 22377v8hi __builtin_ia32_psubw128 (v8hi, v8hi); 22378v4si __builtin_ia32_psubd128 (v4si, v4si); 22379v2di __builtin_ia32_psubq128 (v2di, v2di); 22380v8hi __builtin_ia32_pmullw128 (v8hi, v8hi); 22381v8hi __builtin_ia32_pmulhw128 (v8hi, v8hi); 22382v2di __builtin_ia32_pand128 (v2di, v2di); 22383v2di __builtin_ia32_pandn128 (v2di, v2di); 22384v2di __builtin_ia32_por128 (v2di, v2di); 22385v2di __builtin_ia32_pxor128 (v2di, v2di); 22386v16qi __builtin_ia32_pavgb128 (v16qi, v16qi); 22387v8hi __builtin_ia32_pavgw128 (v8hi, v8hi); 22388v16qi __builtin_ia32_pcmpeqb128 (v16qi, v16qi); 22389v8hi __builtin_ia32_pcmpeqw128 (v8hi, v8hi); 22390v4si __builtin_ia32_pcmpeqd128 (v4si, v4si); 22391v16qi __builtin_ia32_pcmpgtb128 (v16qi, v16qi); 22392v8hi __builtin_ia32_pcmpgtw128 (v8hi, v8hi); 22393v4si __builtin_ia32_pcmpgtd128 (v4si, v4si); 22394v16qi __builtin_ia32_pmaxub128 (v16qi, v16qi); 22395v8hi __builtin_ia32_pmaxsw128 (v8hi, v8hi); 22396v16qi __builtin_ia32_pminub128 (v16qi, v16qi); 22397v8hi __builtin_ia32_pminsw128 (v8hi, v8hi); 22398v16qi __builtin_ia32_punpckhbw128 (v16qi, v16qi); 22399v8hi __builtin_ia32_punpckhwd128 (v8hi, v8hi); 22400v4si __builtin_ia32_punpckhdq128 (v4si, v4si); 22401v2di __builtin_ia32_punpckhqdq128 (v2di, v2di); 22402v16qi __builtin_ia32_punpcklbw128 (v16qi, v16qi); 22403v8hi __builtin_ia32_punpcklwd128 (v8hi, v8hi); 22404v4si __builtin_ia32_punpckldq128 (v4si, v4si); 22405v2di __builtin_ia32_punpcklqdq128 (v2di, v2di); 22406v16qi __builtin_ia32_packsswb128 (v8hi, v8hi); 22407v8hi __builtin_ia32_packssdw128 (v4si, v4si); 22408v16qi __builtin_ia32_packuswb128 (v8hi, v8hi); 22409v8hi __builtin_ia32_pmulhuw128 (v8hi, v8hi); 22410void __builtin_ia32_maskmovdqu (v16qi, v16qi); 22411v2df __builtin_ia32_loadupd (double *); 22412void __builtin_ia32_storeupd (double *, v2df); 22413v2df __builtin_ia32_loadhpd (v2df, double const *); 22414v2df __builtin_ia32_loadlpd (v2df, double const *); 22415int __builtin_ia32_movmskpd (v2df); 22416int __builtin_ia32_pmovmskb128 (v16qi); 22417void __builtin_ia32_movnti (int *, int); 22418void __builtin_ia32_movnti64 (long long int *, long long int); 22419void __builtin_ia32_movntpd (double *, v2df); 22420void __builtin_ia32_movntdq (v2df *, v2df); 22421v4si __builtin_ia32_pshufd (v4si, int); 22422v8hi __builtin_ia32_pshuflw (v8hi, int); 22423v8hi __builtin_ia32_pshufhw (v8hi, int); 22424v2di __builtin_ia32_psadbw128 (v16qi, v16qi); 22425v2df __builtin_ia32_sqrtpd (v2df); 22426v2df __builtin_ia32_sqrtsd (v2df); 22427v2df __builtin_ia32_shufpd (v2df, v2df, int); 22428v2df __builtin_ia32_cvtdq2pd (v4si); 22429v4sf __builtin_ia32_cvtdq2ps (v4si); 22430v4si __builtin_ia32_cvtpd2dq (v2df); 22431v2si __builtin_ia32_cvtpd2pi (v2df); 22432v4sf __builtin_ia32_cvtpd2ps (v2df); 22433v4si __builtin_ia32_cvttpd2dq (v2df); 22434v2si __builtin_ia32_cvttpd2pi (v2df); 22435v2df __builtin_ia32_cvtpi2pd (v2si); 22436int __builtin_ia32_cvtsd2si (v2df); 22437int __builtin_ia32_cvttsd2si (v2df); 22438long long __builtin_ia32_cvtsd2si64 (v2df); 22439long long __builtin_ia32_cvttsd2si64 (v2df); 22440v4si __builtin_ia32_cvtps2dq (v4sf); 22441v2df __builtin_ia32_cvtps2pd (v4sf); 22442v4si __builtin_ia32_cvttps2dq (v4sf); 22443v2df __builtin_ia32_cvtsi2sd (v2df, int); 22444v2df __builtin_ia32_cvtsi642sd (v2df, long long); 22445v4sf __builtin_ia32_cvtsd2ss (v4sf, v2df); 22446v2df __builtin_ia32_cvtss2sd (v2df, v4sf); 22447void __builtin_ia32_clflush (const void *); 22448void __builtin_ia32_lfence (void); 22449void __builtin_ia32_mfence (void); 22450v16qi __builtin_ia32_loaddqu (const char *); 22451void __builtin_ia32_storedqu (char *, v16qi); 22452v1di __builtin_ia32_pmuludq (v2si, v2si); 22453v2di __builtin_ia32_pmuludq128 (v4si, v4si); 22454v8hi __builtin_ia32_psllw128 (v8hi, v8hi); 22455v4si __builtin_ia32_pslld128 (v4si, v4si); 22456v2di __builtin_ia32_psllq128 (v2di, v2di); 22457v8hi __builtin_ia32_psrlw128 (v8hi, v8hi); 22458v4si __builtin_ia32_psrld128 (v4si, v4si); 22459v2di __builtin_ia32_psrlq128 (v2di, v2di); 22460v8hi __builtin_ia32_psraw128 (v8hi, v8hi); 22461v4si __builtin_ia32_psrad128 (v4si, v4si); 22462v2di __builtin_ia32_pslldqi128 (v2di, int); 22463v8hi __builtin_ia32_psllwi128 (v8hi, int); 22464v4si __builtin_ia32_pslldi128 (v4si, int); 22465v2di __builtin_ia32_psllqi128 (v2di, int); 22466v2di __builtin_ia32_psrldqi128 (v2di, int); 22467v8hi __builtin_ia32_psrlwi128 (v8hi, int); 22468v4si __builtin_ia32_psrldi128 (v4si, int); 22469v2di __builtin_ia32_psrlqi128 (v2di, int); 22470v8hi __builtin_ia32_psrawi128 (v8hi, int); 22471v4si __builtin_ia32_psradi128 (v4si, int); 22472v4si __builtin_ia32_pmaddwd128 (v8hi, v8hi); 22473v2di __builtin_ia32_movq128 (v2di); 22474@end smallexample 22475 22476The following built-in functions are available when @option{-msse3} is used. 22477All of them generate the machine instruction that is part of the name. 22478 22479@smallexample 22480v2df __builtin_ia32_addsubpd (v2df, v2df); 22481v4sf __builtin_ia32_addsubps (v4sf, v4sf); 22482v2df __builtin_ia32_haddpd (v2df, v2df); 22483v4sf __builtin_ia32_haddps (v4sf, v4sf); 22484v2df __builtin_ia32_hsubpd (v2df, v2df); 22485v4sf __builtin_ia32_hsubps (v4sf, v4sf); 22486v16qi __builtin_ia32_lddqu (char const *); 22487void __builtin_ia32_monitor (void *, unsigned int, unsigned int); 22488v4sf __builtin_ia32_movshdup (v4sf); 22489v4sf __builtin_ia32_movsldup (v4sf); 22490void __builtin_ia32_mwait (unsigned int, unsigned int); 22491@end smallexample 22492 22493The following built-in functions are available when @option{-mssse3} is used. 22494All of them generate the machine instruction that is part of the name. 22495 22496@smallexample 22497v2si __builtin_ia32_phaddd (v2si, v2si); 22498v4hi __builtin_ia32_phaddw (v4hi, v4hi); 22499v4hi __builtin_ia32_phaddsw (v4hi, v4hi); 22500v2si __builtin_ia32_phsubd (v2si, v2si); 22501v4hi __builtin_ia32_phsubw (v4hi, v4hi); 22502v4hi __builtin_ia32_phsubsw (v4hi, v4hi); 22503v4hi __builtin_ia32_pmaddubsw (v8qi, v8qi); 22504v4hi __builtin_ia32_pmulhrsw (v4hi, v4hi); 22505v8qi __builtin_ia32_pshufb (v8qi, v8qi); 22506v8qi __builtin_ia32_psignb (v8qi, v8qi); 22507v2si __builtin_ia32_psignd (v2si, v2si); 22508v4hi __builtin_ia32_psignw (v4hi, v4hi); 22509v1di __builtin_ia32_palignr (v1di, v1di, int); 22510v8qi __builtin_ia32_pabsb (v8qi); 22511v2si __builtin_ia32_pabsd (v2si); 22512v4hi __builtin_ia32_pabsw (v4hi); 22513@end smallexample 22514 22515The following built-in functions are available when @option{-mssse3} is used. 22516All of them generate the machine instruction that is part of the name. 22517 22518@smallexample 22519v4si __builtin_ia32_phaddd128 (v4si, v4si); 22520v8hi __builtin_ia32_phaddw128 (v8hi, v8hi); 22521v8hi __builtin_ia32_phaddsw128 (v8hi, v8hi); 22522v4si __builtin_ia32_phsubd128 (v4si, v4si); 22523v8hi __builtin_ia32_phsubw128 (v8hi, v8hi); 22524v8hi __builtin_ia32_phsubsw128 (v8hi, v8hi); 22525v8hi __builtin_ia32_pmaddubsw128 (v16qi, v16qi); 22526v8hi __builtin_ia32_pmulhrsw128 (v8hi, v8hi); 22527v16qi __builtin_ia32_pshufb128 (v16qi, v16qi); 22528v16qi __builtin_ia32_psignb128 (v16qi, v16qi); 22529v4si __builtin_ia32_psignd128 (v4si, v4si); 22530v8hi __builtin_ia32_psignw128 (v8hi, v8hi); 22531v2di __builtin_ia32_palignr128 (v2di, v2di, int); 22532v16qi __builtin_ia32_pabsb128 (v16qi); 22533v4si __builtin_ia32_pabsd128 (v4si); 22534v8hi __builtin_ia32_pabsw128 (v8hi); 22535@end smallexample 22536 22537The following built-in functions are available when @option{-msse4.1} is 22538used. All of them generate the machine instruction that is part of the 22539name. 22540 22541@smallexample 22542v2df __builtin_ia32_blendpd (v2df, v2df, const int); 22543v4sf __builtin_ia32_blendps (v4sf, v4sf, const int); 22544v2df __builtin_ia32_blendvpd (v2df, v2df, v2df); 22545v4sf __builtin_ia32_blendvps (v4sf, v4sf, v4sf); 22546v2df __builtin_ia32_dppd (v2df, v2df, const int); 22547v4sf __builtin_ia32_dpps (v4sf, v4sf, const int); 22548v4sf __builtin_ia32_insertps128 (v4sf, v4sf, const int); 22549v2di __builtin_ia32_movntdqa (v2di *); 22550v16qi __builtin_ia32_mpsadbw128 (v16qi, v16qi, const int); 22551v8hi __builtin_ia32_packusdw128 (v4si, v4si); 22552v16qi __builtin_ia32_pblendvb128 (v16qi, v16qi, v16qi); 22553v8hi __builtin_ia32_pblendw128 (v8hi, v8hi, const int); 22554v2di __builtin_ia32_pcmpeqq (v2di, v2di); 22555v8hi __builtin_ia32_phminposuw128 (v8hi); 22556v16qi __builtin_ia32_pmaxsb128 (v16qi, v16qi); 22557v4si __builtin_ia32_pmaxsd128 (v4si, v4si); 22558v4si __builtin_ia32_pmaxud128 (v4si, v4si); 22559v8hi __builtin_ia32_pmaxuw128 (v8hi, v8hi); 22560v16qi __builtin_ia32_pminsb128 (v16qi, v16qi); 22561v4si __builtin_ia32_pminsd128 (v4si, v4si); 22562v4si __builtin_ia32_pminud128 (v4si, v4si); 22563v8hi __builtin_ia32_pminuw128 (v8hi, v8hi); 22564v4si __builtin_ia32_pmovsxbd128 (v16qi); 22565v2di __builtin_ia32_pmovsxbq128 (v16qi); 22566v8hi __builtin_ia32_pmovsxbw128 (v16qi); 22567v2di __builtin_ia32_pmovsxdq128 (v4si); 22568v4si __builtin_ia32_pmovsxwd128 (v8hi); 22569v2di __builtin_ia32_pmovsxwq128 (v8hi); 22570v4si __builtin_ia32_pmovzxbd128 (v16qi); 22571v2di __builtin_ia32_pmovzxbq128 (v16qi); 22572v8hi __builtin_ia32_pmovzxbw128 (v16qi); 22573v2di __builtin_ia32_pmovzxdq128 (v4si); 22574v4si __builtin_ia32_pmovzxwd128 (v8hi); 22575v2di __builtin_ia32_pmovzxwq128 (v8hi); 22576v2di __builtin_ia32_pmuldq128 (v4si, v4si); 22577v4si __builtin_ia32_pmulld128 (v4si, v4si); 22578int __builtin_ia32_ptestc128 (v2di, v2di); 22579int __builtin_ia32_ptestnzc128 (v2di, v2di); 22580int __builtin_ia32_ptestz128 (v2di, v2di); 22581v2df __builtin_ia32_roundpd (v2df, const int); 22582v4sf __builtin_ia32_roundps (v4sf, const int); 22583v2df __builtin_ia32_roundsd (v2df, v2df, const int); 22584v4sf __builtin_ia32_roundss (v4sf, v4sf, const int); 22585@end smallexample 22586 22587The following built-in functions are available when @option{-msse4.1} is 22588used. 22589 22590@table @code 22591@item v4sf __builtin_ia32_vec_set_v4sf (v4sf, float, const int) 22592Generates the @code{insertps} machine instruction. 22593@item int __builtin_ia32_vec_ext_v16qi (v16qi, const int) 22594Generates the @code{pextrb} machine instruction. 22595@item v16qi __builtin_ia32_vec_set_v16qi (v16qi, int, const int) 22596Generates the @code{pinsrb} machine instruction. 22597@item v4si __builtin_ia32_vec_set_v4si (v4si, int, const int) 22598Generates the @code{pinsrd} machine instruction. 22599@item v2di __builtin_ia32_vec_set_v2di (v2di, long long, const int) 22600Generates the @code{pinsrq} machine instruction in 64bit mode. 22601@end table 22602 22603The following built-in functions are changed to generate new SSE4.1 22604instructions when @option{-msse4.1} is used. 22605 22606@table @code 22607@item float __builtin_ia32_vec_ext_v4sf (v4sf, const int) 22608Generates the @code{extractps} machine instruction. 22609@item int __builtin_ia32_vec_ext_v4si (v4si, const int) 22610Generates the @code{pextrd} machine instruction. 22611@item long long __builtin_ia32_vec_ext_v2di (v2di, const int) 22612Generates the @code{pextrq} machine instruction in 64bit mode. 22613@end table 22614 22615The following built-in functions are available when @option{-msse4.2} is 22616used. All of them generate the machine instruction that is part of the 22617name. 22618 22619@smallexample 22620v16qi __builtin_ia32_pcmpestrm128 (v16qi, int, v16qi, int, const int); 22621int __builtin_ia32_pcmpestri128 (v16qi, int, v16qi, int, const int); 22622int __builtin_ia32_pcmpestria128 (v16qi, int, v16qi, int, const int); 22623int __builtin_ia32_pcmpestric128 (v16qi, int, v16qi, int, const int); 22624int __builtin_ia32_pcmpestrio128 (v16qi, int, v16qi, int, const int); 22625int __builtin_ia32_pcmpestris128 (v16qi, int, v16qi, int, const int); 22626int __builtin_ia32_pcmpestriz128 (v16qi, int, v16qi, int, const int); 22627v16qi __builtin_ia32_pcmpistrm128 (v16qi, v16qi, const int); 22628int __builtin_ia32_pcmpistri128 (v16qi, v16qi, const int); 22629int __builtin_ia32_pcmpistria128 (v16qi, v16qi, const int); 22630int __builtin_ia32_pcmpistric128 (v16qi, v16qi, const int); 22631int __builtin_ia32_pcmpistrio128 (v16qi, v16qi, const int); 22632int __builtin_ia32_pcmpistris128 (v16qi, v16qi, const int); 22633int __builtin_ia32_pcmpistriz128 (v16qi, v16qi, const int); 22634v2di __builtin_ia32_pcmpgtq (v2di, v2di); 22635@end smallexample 22636 22637The following built-in functions are available when @option{-msse4.2} is 22638used. 22639 22640@table @code 22641@item unsigned int __builtin_ia32_crc32qi (unsigned int, unsigned char) 22642Generates the @code{crc32b} machine instruction. 22643@item unsigned int __builtin_ia32_crc32hi (unsigned int, unsigned short) 22644Generates the @code{crc32w} machine instruction. 22645@item unsigned int __builtin_ia32_crc32si (unsigned int, unsigned int) 22646Generates the @code{crc32l} machine instruction. 22647@item unsigned long long __builtin_ia32_crc32di (unsigned long long, unsigned long long) 22648Generates the @code{crc32q} machine instruction. 22649@end table 22650 22651The following built-in functions are changed to generate new SSE4.2 22652instructions when @option{-msse4.2} is used. 22653 22654@table @code 22655@item int __builtin_popcount (unsigned int) 22656Generates the @code{popcntl} machine instruction. 22657@item int __builtin_popcountl (unsigned long) 22658Generates the @code{popcntl} or @code{popcntq} machine instruction, 22659depending on the size of @code{unsigned long}. 22660@item int __builtin_popcountll (unsigned long long) 22661Generates the @code{popcntq} machine instruction. 22662@end table 22663 22664The following built-in functions are available when @option{-mavx} is 22665used. All of them generate the machine instruction that is part of the 22666name. 22667 22668@smallexample 22669v4df __builtin_ia32_addpd256 (v4df,v4df); 22670v8sf __builtin_ia32_addps256 (v8sf,v8sf); 22671v4df __builtin_ia32_addsubpd256 (v4df,v4df); 22672v8sf __builtin_ia32_addsubps256 (v8sf,v8sf); 22673v4df __builtin_ia32_andnpd256 (v4df,v4df); 22674v8sf __builtin_ia32_andnps256 (v8sf,v8sf); 22675v4df __builtin_ia32_andpd256 (v4df,v4df); 22676v8sf __builtin_ia32_andps256 (v8sf,v8sf); 22677v4df __builtin_ia32_blendpd256 (v4df,v4df,int); 22678v8sf __builtin_ia32_blendps256 (v8sf,v8sf,int); 22679v4df __builtin_ia32_blendvpd256 (v4df,v4df,v4df); 22680v8sf __builtin_ia32_blendvps256 (v8sf,v8sf,v8sf); 22681v2df __builtin_ia32_cmppd (v2df,v2df,int); 22682v4df __builtin_ia32_cmppd256 (v4df,v4df,int); 22683v4sf __builtin_ia32_cmpps (v4sf,v4sf,int); 22684v8sf __builtin_ia32_cmpps256 (v8sf,v8sf,int); 22685v2df __builtin_ia32_cmpsd (v2df,v2df,int); 22686v4sf __builtin_ia32_cmpss (v4sf,v4sf,int); 22687v4df __builtin_ia32_cvtdq2pd256 (v4si); 22688v8sf __builtin_ia32_cvtdq2ps256 (v8si); 22689v4si __builtin_ia32_cvtpd2dq256 (v4df); 22690v4sf __builtin_ia32_cvtpd2ps256 (v4df); 22691v8si __builtin_ia32_cvtps2dq256 (v8sf); 22692v4df __builtin_ia32_cvtps2pd256 (v4sf); 22693v4si __builtin_ia32_cvttpd2dq256 (v4df); 22694v8si __builtin_ia32_cvttps2dq256 (v8sf); 22695v4df __builtin_ia32_divpd256 (v4df,v4df); 22696v8sf __builtin_ia32_divps256 (v8sf,v8sf); 22697v8sf __builtin_ia32_dpps256 (v8sf,v8sf,int); 22698v4df __builtin_ia32_haddpd256 (v4df,v4df); 22699v8sf __builtin_ia32_haddps256 (v8sf,v8sf); 22700v4df __builtin_ia32_hsubpd256 (v4df,v4df); 22701v8sf __builtin_ia32_hsubps256 (v8sf,v8sf); 22702v32qi __builtin_ia32_lddqu256 (pcchar); 22703v32qi __builtin_ia32_loaddqu256 (pcchar); 22704v4df __builtin_ia32_loadupd256 (pcdouble); 22705v8sf __builtin_ia32_loadups256 (pcfloat); 22706v2df __builtin_ia32_maskloadpd (pcv2df,v2df); 22707v4df __builtin_ia32_maskloadpd256 (pcv4df,v4df); 22708v4sf __builtin_ia32_maskloadps (pcv4sf,v4sf); 22709v8sf __builtin_ia32_maskloadps256 (pcv8sf,v8sf); 22710void __builtin_ia32_maskstorepd (pv2df,v2df,v2df); 22711void __builtin_ia32_maskstorepd256 (pv4df,v4df,v4df); 22712void __builtin_ia32_maskstoreps (pv4sf,v4sf,v4sf); 22713void __builtin_ia32_maskstoreps256 (pv8sf,v8sf,v8sf); 22714v4df __builtin_ia32_maxpd256 (v4df,v4df); 22715v8sf __builtin_ia32_maxps256 (v8sf,v8sf); 22716v4df __builtin_ia32_minpd256 (v4df,v4df); 22717v8sf __builtin_ia32_minps256 (v8sf,v8sf); 22718v4df __builtin_ia32_movddup256 (v4df); 22719int __builtin_ia32_movmskpd256 (v4df); 22720int __builtin_ia32_movmskps256 (v8sf); 22721v8sf __builtin_ia32_movshdup256 (v8sf); 22722v8sf __builtin_ia32_movsldup256 (v8sf); 22723v4df __builtin_ia32_mulpd256 (v4df,v4df); 22724v8sf __builtin_ia32_mulps256 (v8sf,v8sf); 22725v4df __builtin_ia32_orpd256 (v4df,v4df); 22726v8sf __builtin_ia32_orps256 (v8sf,v8sf); 22727v2df __builtin_ia32_pd_pd256 (v4df); 22728v4df __builtin_ia32_pd256_pd (v2df); 22729v4sf __builtin_ia32_ps_ps256 (v8sf); 22730v8sf __builtin_ia32_ps256_ps (v4sf); 22731int __builtin_ia32_ptestc256 (v4di,v4di,ptest); 22732int __builtin_ia32_ptestnzc256 (v4di,v4di,ptest); 22733int __builtin_ia32_ptestz256 (v4di,v4di,ptest); 22734v8sf __builtin_ia32_rcpps256 (v8sf); 22735v4df __builtin_ia32_roundpd256 (v4df,int); 22736v8sf __builtin_ia32_roundps256 (v8sf,int); 22737v8sf __builtin_ia32_rsqrtps_nr256 (v8sf); 22738v8sf __builtin_ia32_rsqrtps256 (v8sf); 22739v4df __builtin_ia32_shufpd256 (v4df,v4df,int); 22740v8sf __builtin_ia32_shufps256 (v8sf,v8sf,int); 22741v4si __builtin_ia32_si_si256 (v8si); 22742v8si __builtin_ia32_si256_si (v4si); 22743v4df __builtin_ia32_sqrtpd256 (v4df); 22744v8sf __builtin_ia32_sqrtps_nr256 (v8sf); 22745v8sf __builtin_ia32_sqrtps256 (v8sf); 22746void __builtin_ia32_storedqu256 (pchar,v32qi); 22747void __builtin_ia32_storeupd256 (pdouble,v4df); 22748void __builtin_ia32_storeups256 (pfloat,v8sf); 22749v4df __builtin_ia32_subpd256 (v4df,v4df); 22750v8sf __builtin_ia32_subps256 (v8sf,v8sf); 22751v4df __builtin_ia32_unpckhpd256 (v4df,v4df); 22752v8sf __builtin_ia32_unpckhps256 (v8sf,v8sf); 22753v4df __builtin_ia32_unpcklpd256 (v4df,v4df); 22754v8sf __builtin_ia32_unpcklps256 (v8sf,v8sf); 22755v4df __builtin_ia32_vbroadcastf128_pd256 (pcv2df); 22756v8sf __builtin_ia32_vbroadcastf128_ps256 (pcv4sf); 22757v4df __builtin_ia32_vbroadcastsd256 (pcdouble); 22758v4sf __builtin_ia32_vbroadcastss (pcfloat); 22759v8sf __builtin_ia32_vbroadcastss256 (pcfloat); 22760v2df __builtin_ia32_vextractf128_pd256 (v4df,int); 22761v4sf __builtin_ia32_vextractf128_ps256 (v8sf,int); 22762v4si __builtin_ia32_vextractf128_si256 (v8si,int); 22763v4df __builtin_ia32_vinsertf128_pd256 (v4df,v2df,int); 22764v8sf __builtin_ia32_vinsertf128_ps256 (v8sf,v4sf,int); 22765v8si __builtin_ia32_vinsertf128_si256 (v8si,v4si,int); 22766v4df __builtin_ia32_vperm2f128_pd256 (v4df,v4df,int); 22767v8sf __builtin_ia32_vperm2f128_ps256 (v8sf,v8sf,int); 22768v8si __builtin_ia32_vperm2f128_si256 (v8si,v8si,int); 22769v2df __builtin_ia32_vpermil2pd (v2df,v2df,v2di,int); 22770v4df __builtin_ia32_vpermil2pd256 (v4df,v4df,v4di,int); 22771v4sf __builtin_ia32_vpermil2ps (v4sf,v4sf,v4si,int); 22772v8sf __builtin_ia32_vpermil2ps256 (v8sf,v8sf,v8si,int); 22773v2df __builtin_ia32_vpermilpd (v2df,int); 22774v4df __builtin_ia32_vpermilpd256 (v4df,int); 22775v4sf __builtin_ia32_vpermilps (v4sf,int); 22776v8sf __builtin_ia32_vpermilps256 (v8sf,int); 22777v2df __builtin_ia32_vpermilvarpd (v2df,v2di); 22778v4df __builtin_ia32_vpermilvarpd256 (v4df,v4di); 22779v4sf __builtin_ia32_vpermilvarps (v4sf,v4si); 22780v8sf __builtin_ia32_vpermilvarps256 (v8sf,v8si); 22781int __builtin_ia32_vtestcpd (v2df,v2df,ptest); 22782int __builtin_ia32_vtestcpd256 (v4df,v4df,ptest); 22783int __builtin_ia32_vtestcps (v4sf,v4sf,ptest); 22784int __builtin_ia32_vtestcps256 (v8sf,v8sf,ptest); 22785int __builtin_ia32_vtestnzcpd (v2df,v2df,ptest); 22786int __builtin_ia32_vtestnzcpd256 (v4df,v4df,ptest); 22787int __builtin_ia32_vtestnzcps (v4sf,v4sf,ptest); 22788int __builtin_ia32_vtestnzcps256 (v8sf,v8sf,ptest); 22789int __builtin_ia32_vtestzpd (v2df,v2df,ptest); 22790int __builtin_ia32_vtestzpd256 (v4df,v4df,ptest); 22791int __builtin_ia32_vtestzps (v4sf,v4sf,ptest); 22792int __builtin_ia32_vtestzps256 (v8sf,v8sf,ptest); 22793void __builtin_ia32_vzeroall (void); 22794void __builtin_ia32_vzeroupper (void); 22795v4df __builtin_ia32_xorpd256 (v4df,v4df); 22796v8sf __builtin_ia32_xorps256 (v8sf,v8sf); 22797@end smallexample 22798 22799The following built-in functions are available when @option{-mavx2} is 22800used. All of them generate the machine instruction that is part of the 22801name. 22802 22803@smallexample 22804v32qi __builtin_ia32_mpsadbw256 (v32qi,v32qi,int); 22805v32qi __builtin_ia32_pabsb256 (v32qi); 22806v16hi __builtin_ia32_pabsw256 (v16hi); 22807v8si __builtin_ia32_pabsd256 (v8si); 22808v16hi __builtin_ia32_packssdw256 (v8si,v8si); 22809v32qi __builtin_ia32_packsswb256 (v16hi,v16hi); 22810v16hi __builtin_ia32_packusdw256 (v8si,v8si); 22811v32qi __builtin_ia32_packuswb256 (v16hi,v16hi); 22812v32qi __builtin_ia32_paddb256 (v32qi,v32qi); 22813v16hi __builtin_ia32_paddw256 (v16hi,v16hi); 22814v8si __builtin_ia32_paddd256 (v8si,v8si); 22815v4di __builtin_ia32_paddq256 (v4di,v4di); 22816v32qi __builtin_ia32_paddsb256 (v32qi,v32qi); 22817v16hi __builtin_ia32_paddsw256 (v16hi,v16hi); 22818v32qi __builtin_ia32_paddusb256 (v32qi,v32qi); 22819v16hi __builtin_ia32_paddusw256 (v16hi,v16hi); 22820v4di __builtin_ia32_palignr256 (v4di,v4di,int); 22821v4di __builtin_ia32_andsi256 (v4di,v4di); 22822v4di __builtin_ia32_andnotsi256 (v4di,v4di); 22823v32qi __builtin_ia32_pavgb256 (v32qi,v32qi); 22824v16hi __builtin_ia32_pavgw256 (v16hi,v16hi); 22825v32qi __builtin_ia32_pblendvb256 (v32qi,v32qi,v32qi); 22826v16hi __builtin_ia32_pblendw256 (v16hi,v16hi,int); 22827v32qi __builtin_ia32_pcmpeqb256 (v32qi,v32qi); 22828v16hi __builtin_ia32_pcmpeqw256 (v16hi,v16hi); 22829v8si __builtin_ia32_pcmpeqd256 (c8si,v8si); 22830v4di __builtin_ia32_pcmpeqq256 (v4di,v4di); 22831v32qi __builtin_ia32_pcmpgtb256 (v32qi,v32qi); 22832v16hi __builtin_ia32_pcmpgtw256 (16hi,v16hi); 22833v8si __builtin_ia32_pcmpgtd256 (v8si,v8si); 22834v4di __builtin_ia32_pcmpgtq256 (v4di,v4di); 22835v16hi __builtin_ia32_phaddw256 (v16hi,v16hi); 22836v8si __builtin_ia32_phaddd256 (v8si,v8si); 22837v16hi __builtin_ia32_phaddsw256 (v16hi,v16hi); 22838v16hi __builtin_ia32_phsubw256 (v16hi,v16hi); 22839v8si __builtin_ia32_phsubd256 (v8si,v8si); 22840v16hi __builtin_ia32_phsubsw256 (v16hi,v16hi); 22841v32qi __builtin_ia32_pmaddubsw256 (v32qi,v32qi); 22842v16hi __builtin_ia32_pmaddwd256 (v16hi,v16hi); 22843v32qi __builtin_ia32_pmaxsb256 (v32qi,v32qi); 22844v16hi __builtin_ia32_pmaxsw256 (v16hi,v16hi); 22845v8si __builtin_ia32_pmaxsd256 (v8si,v8si); 22846v32qi __builtin_ia32_pmaxub256 (v32qi,v32qi); 22847v16hi __builtin_ia32_pmaxuw256 (v16hi,v16hi); 22848v8si __builtin_ia32_pmaxud256 (v8si,v8si); 22849v32qi __builtin_ia32_pminsb256 (v32qi,v32qi); 22850v16hi __builtin_ia32_pminsw256 (v16hi,v16hi); 22851v8si __builtin_ia32_pminsd256 (v8si,v8si); 22852v32qi __builtin_ia32_pminub256 (v32qi,v32qi); 22853v16hi __builtin_ia32_pminuw256 (v16hi,v16hi); 22854v8si __builtin_ia32_pminud256 (v8si,v8si); 22855int __builtin_ia32_pmovmskb256 (v32qi); 22856v16hi __builtin_ia32_pmovsxbw256 (v16qi); 22857v8si __builtin_ia32_pmovsxbd256 (v16qi); 22858v4di __builtin_ia32_pmovsxbq256 (v16qi); 22859v8si __builtin_ia32_pmovsxwd256 (v8hi); 22860v4di __builtin_ia32_pmovsxwq256 (v8hi); 22861v4di __builtin_ia32_pmovsxdq256 (v4si); 22862v16hi __builtin_ia32_pmovzxbw256 (v16qi); 22863v8si __builtin_ia32_pmovzxbd256 (v16qi); 22864v4di __builtin_ia32_pmovzxbq256 (v16qi); 22865v8si __builtin_ia32_pmovzxwd256 (v8hi); 22866v4di __builtin_ia32_pmovzxwq256 (v8hi); 22867v4di __builtin_ia32_pmovzxdq256 (v4si); 22868v4di __builtin_ia32_pmuldq256 (v8si,v8si); 22869v16hi __builtin_ia32_pmulhrsw256 (v16hi, v16hi); 22870v16hi __builtin_ia32_pmulhuw256 (v16hi,v16hi); 22871v16hi __builtin_ia32_pmulhw256 (v16hi,v16hi); 22872v16hi __builtin_ia32_pmullw256 (v16hi,v16hi); 22873v8si __builtin_ia32_pmulld256 (v8si,v8si); 22874v4di __builtin_ia32_pmuludq256 (v8si,v8si); 22875v4di __builtin_ia32_por256 (v4di,v4di); 22876v16hi __builtin_ia32_psadbw256 (v32qi,v32qi); 22877v32qi __builtin_ia32_pshufb256 (v32qi,v32qi); 22878v8si __builtin_ia32_pshufd256 (v8si,int); 22879v16hi __builtin_ia32_pshufhw256 (v16hi,int); 22880v16hi __builtin_ia32_pshuflw256 (v16hi,int); 22881v32qi __builtin_ia32_psignb256 (v32qi,v32qi); 22882v16hi __builtin_ia32_psignw256 (v16hi,v16hi); 22883v8si __builtin_ia32_psignd256 (v8si,v8si); 22884v4di __builtin_ia32_pslldqi256 (v4di,int); 22885v16hi __builtin_ia32_psllwi256 (16hi,int); 22886v16hi __builtin_ia32_psllw256(v16hi,v8hi); 22887v8si __builtin_ia32_pslldi256 (v8si,int); 22888v8si __builtin_ia32_pslld256(v8si,v4si); 22889v4di __builtin_ia32_psllqi256 (v4di,int); 22890v4di __builtin_ia32_psllq256(v4di,v2di); 22891v16hi __builtin_ia32_psrawi256 (v16hi,int); 22892v16hi __builtin_ia32_psraw256 (v16hi,v8hi); 22893v8si __builtin_ia32_psradi256 (v8si,int); 22894v8si __builtin_ia32_psrad256 (v8si,v4si); 22895v4di __builtin_ia32_psrldqi256 (v4di, int); 22896v16hi __builtin_ia32_psrlwi256 (v16hi,int); 22897v16hi __builtin_ia32_psrlw256 (v16hi,v8hi); 22898v8si __builtin_ia32_psrldi256 (v8si,int); 22899v8si __builtin_ia32_psrld256 (v8si,v4si); 22900v4di __builtin_ia32_psrlqi256 (v4di,int); 22901v4di __builtin_ia32_psrlq256(v4di,v2di); 22902v32qi __builtin_ia32_psubb256 (v32qi,v32qi); 22903v32hi __builtin_ia32_psubw256 (v16hi,v16hi); 22904v8si __builtin_ia32_psubd256 (v8si,v8si); 22905v4di __builtin_ia32_psubq256 (v4di,v4di); 22906v32qi __builtin_ia32_psubsb256 (v32qi,v32qi); 22907v16hi __builtin_ia32_psubsw256 (v16hi,v16hi); 22908v32qi __builtin_ia32_psubusb256 (v32qi,v32qi); 22909v16hi __builtin_ia32_psubusw256 (v16hi,v16hi); 22910v32qi __builtin_ia32_punpckhbw256 (v32qi,v32qi); 22911v16hi __builtin_ia32_punpckhwd256 (v16hi,v16hi); 22912v8si __builtin_ia32_punpckhdq256 (v8si,v8si); 22913v4di __builtin_ia32_punpckhqdq256 (v4di,v4di); 22914v32qi __builtin_ia32_punpcklbw256 (v32qi,v32qi); 22915v16hi __builtin_ia32_punpcklwd256 (v16hi,v16hi); 22916v8si __builtin_ia32_punpckldq256 (v8si,v8si); 22917v4di __builtin_ia32_punpcklqdq256 (v4di,v4di); 22918v4di __builtin_ia32_pxor256 (v4di,v4di); 22919v4di __builtin_ia32_movntdqa256 (pv4di); 22920v4sf __builtin_ia32_vbroadcastss_ps (v4sf); 22921v8sf __builtin_ia32_vbroadcastss_ps256 (v4sf); 22922v4df __builtin_ia32_vbroadcastsd_pd256 (v2df); 22923v4di __builtin_ia32_vbroadcastsi256 (v2di); 22924v4si __builtin_ia32_pblendd128 (v4si,v4si); 22925v8si __builtin_ia32_pblendd256 (v8si,v8si); 22926v32qi __builtin_ia32_pbroadcastb256 (v16qi); 22927v16hi __builtin_ia32_pbroadcastw256 (v8hi); 22928v8si __builtin_ia32_pbroadcastd256 (v4si); 22929v4di __builtin_ia32_pbroadcastq256 (v2di); 22930v16qi __builtin_ia32_pbroadcastb128 (v16qi); 22931v8hi __builtin_ia32_pbroadcastw128 (v8hi); 22932v4si __builtin_ia32_pbroadcastd128 (v4si); 22933v2di __builtin_ia32_pbroadcastq128 (v2di); 22934v8si __builtin_ia32_permvarsi256 (v8si,v8si); 22935v4df __builtin_ia32_permdf256 (v4df,int); 22936v8sf __builtin_ia32_permvarsf256 (v8sf,v8sf); 22937v4di __builtin_ia32_permdi256 (v4di,int); 22938v4di __builtin_ia32_permti256 (v4di,v4di,int); 22939v4di __builtin_ia32_extract128i256 (v4di,int); 22940v4di __builtin_ia32_insert128i256 (v4di,v2di,int); 22941v8si __builtin_ia32_maskloadd256 (pcv8si,v8si); 22942v4di __builtin_ia32_maskloadq256 (pcv4di,v4di); 22943v4si __builtin_ia32_maskloadd (pcv4si,v4si); 22944v2di __builtin_ia32_maskloadq (pcv2di,v2di); 22945void __builtin_ia32_maskstored256 (pv8si,v8si,v8si); 22946void __builtin_ia32_maskstoreq256 (pv4di,v4di,v4di); 22947void __builtin_ia32_maskstored (pv4si,v4si,v4si); 22948void __builtin_ia32_maskstoreq (pv2di,v2di,v2di); 22949v8si __builtin_ia32_psllv8si (v8si,v8si); 22950v4si __builtin_ia32_psllv4si (v4si,v4si); 22951v4di __builtin_ia32_psllv4di (v4di,v4di); 22952v2di __builtin_ia32_psllv2di (v2di,v2di); 22953v8si __builtin_ia32_psrav8si (v8si,v8si); 22954v4si __builtin_ia32_psrav4si (v4si,v4si); 22955v8si __builtin_ia32_psrlv8si (v8si,v8si); 22956v4si __builtin_ia32_psrlv4si (v4si,v4si); 22957v4di __builtin_ia32_psrlv4di (v4di,v4di); 22958v2di __builtin_ia32_psrlv2di (v2di,v2di); 22959v2df __builtin_ia32_gathersiv2df (v2df, pcdouble,v4si,v2df,int); 22960v4df __builtin_ia32_gathersiv4df (v4df, pcdouble,v4si,v4df,int); 22961v2df __builtin_ia32_gatherdiv2df (v2df, pcdouble,v2di,v2df,int); 22962v4df __builtin_ia32_gatherdiv4df (v4df, pcdouble,v4di,v4df,int); 22963v4sf __builtin_ia32_gathersiv4sf (v4sf, pcfloat,v4si,v4sf,int); 22964v8sf __builtin_ia32_gathersiv8sf (v8sf, pcfloat,v8si,v8sf,int); 22965v4sf __builtin_ia32_gatherdiv4sf (v4sf, pcfloat,v2di,v4sf,int); 22966v4sf __builtin_ia32_gatherdiv4sf256 (v4sf, pcfloat,v4di,v4sf,int); 22967v2di __builtin_ia32_gathersiv2di (v2di, pcint64,v4si,v2di,int); 22968v4di __builtin_ia32_gathersiv4di (v4di, pcint64,v4si,v4di,int); 22969v2di __builtin_ia32_gatherdiv2di (v2di, pcint64,v2di,v2di,int); 22970v4di __builtin_ia32_gatherdiv4di (v4di, pcint64,v4di,v4di,int); 22971v4si __builtin_ia32_gathersiv4si (v4si, pcint,v4si,v4si,int); 22972v8si __builtin_ia32_gathersiv8si (v8si, pcint,v8si,v8si,int); 22973v4si __builtin_ia32_gatherdiv4si (v4si, pcint,v2di,v4si,int); 22974v4si __builtin_ia32_gatherdiv4si256 (v4si, pcint,v4di,v4si,int); 22975@end smallexample 22976 22977The following built-in functions are available when @option{-maes} is 22978used. All of them generate the machine instruction that is part of the 22979name. 22980 22981@smallexample 22982v2di __builtin_ia32_aesenc128 (v2di, v2di); 22983v2di __builtin_ia32_aesenclast128 (v2di, v2di); 22984v2di __builtin_ia32_aesdec128 (v2di, v2di); 22985v2di __builtin_ia32_aesdeclast128 (v2di, v2di); 22986v2di __builtin_ia32_aeskeygenassist128 (v2di, const int); 22987v2di __builtin_ia32_aesimc128 (v2di); 22988@end smallexample 22989 22990The following built-in function is available when @option{-mpclmul} is 22991used. 22992 22993@table @code 22994@item v2di __builtin_ia32_pclmulqdq128 (v2di, v2di, const int) 22995Generates the @code{pclmulqdq} machine instruction. 22996@end table 22997 22998The following built-in function is available when @option{-mfsgsbase} is 22999used. All of them generate the machine instruction that is part of the 23000name. 23001 23002@smallexample 23003unsigned int __builtin_ia32_rdfsbase32 (void); 23004unsigned long long __builtin_ia32_rdfsbase64 (void); 23005unsigned int __builtin_ia32_rdgsbase32 (void); 23006unsigned long long __builtin_ia32_rdgsbase64 (void); 23007void _writefsbase_u32 (unsigned int); 23008void _writefsbase_u64 (unsigned long long); 23009void _writegsbase_u32 (unsigned int); 23010void _writegsbase_u64 (unsigned long long); 23011@end smallexample 23012 23013The following built-in function is available when @option{-mrdrnd} is 23014used. All of them generate the machine instruction that is part of the 23015name. 23016 23017@smallexample 23018unsigned int __builtin_ia32_rdrand16_step (unsigned short *); 23019unsigned int __builtin_ia32_rdrand32_step (unsigned int *); 23020unsigned int __builtin_ia32_rdrand64_step (unsigned long long *); 23021@end smallexample 23022 23023The following built-in function is available when @option{-mptwrite} is 23024used. All of them generate the machine instruction that is part of the 23025name. 23026 23027@smallexample 23028void __builtin_ia32_ptwrite32 (unsigned); 23029void __builtin_ia32_ptwrite64 (unsigned long long); 23030@end smallexample 23031 23032The following built-in functions are available when @option{-msse4a} is used. 23033All of them generate the machine instruction that is part of the name. 23034 23035@smallexample 23036void __builtin_ia32_movntsd (double *, v2df); 23037void __builtin_ia32_movntss (float *, v4sf); 23038v2di __builtin_ia32_extrq (v2di, v16qi); 23039v2di __builtin_ia32_extrqi (v2di, const unsigned int, const unsigned int); 23040v2di __builtin_ia32_insertq (v2di, v2di); 23041v2di __builtin_ia32_insertqi (v2di, v2di, const unsigned int, const unsigned int); 23042@end smallexample 23043 23044The following built-in functions are available when @option{-mxop} is used. 23045@smallexample 23046v2df __builtin_ia32_vfrczpd (v2df); 23047v4sf __builtin_ia32_vfrczps (v4sf); 23048v2df __builtin_ia32_vfrczsd (v2df); 23049v4sf __builtin_ia32_vfrczss (v4sf); 23050v4df __builtin_ia32_vfrczpd256 (v4df); 23051v8sf __builtin_ia32_vfrczps256 (v8sf); 23052v2di __builtin_ia32_vpcmov (v2di, v2di, v2di); 23053v2di __builtin_ia32_vpcmov_v2di (v2di, v2di, v2di); 23054v4si __builtin_ia32_vpcmov_v4si (v4si, v4si, v4si); 23055v8hi __builtin_ia32_vpcmov_v8hi (v8hi, v8hi, v8hi); 23056v16qi __builtin_ia32_vpcmov_v16qi (v16qi, v16qi, v16qi); 23057v2df __builtin_ia32_vpcmov_v2df (v2df, v2df, v2df); 23058v4sf __builtin_ia32_vpcmov_v4sf (v4sf, v4sf, v4sf); 23059v4di __builtin_ia32_vpcmov_v4di256 (v4di, v4di, v4di); 23060v8si __builtin_ia32_vpcmov_v8si256 (v8si, v8si, v8si); 23061v16hi __builtin_ia32_vpcmov_v16hi256 (v16hi, v16hi, v16hi); 23062v32qi __builtin_ia32_vpcmov_v32qi256 (v32qi, v32qi, v32qi); 23063v4df __builtin_ia32_vpcmov_v4df256 (v4df, v4df, v4df); 23064v8sf __builtin_ia32_vpcmov_v8sf256 (v8sf, v8sf, v8sf); 23065v16qi __builtin_ia32_vpcomeqb (v16qi, v16qi); 23066v8hi __builtin_ia32_vpcomeqw (v8hi, v8hi); 23067v4si __builtin_ia32_vpcomeqd (v4si, v4si); 23068v2di __builtin_ia32_vpcomeqq (v2di, v2di); 23069v16qi __builtin_ia32_vpcomequb (v16qi, v16qi); 23070v4si __builtin_ia32_vpcomequd (v4si, v4si); 23071v2di __builtin_ia32_vpcomequq (v2di, v2di); 23072v8hi __builtin_ia32_vpcomequw (v8hi, v8hi); 23073v8hi __builtin_ia32_vpcomeqw (v8hi, v8hi); 23074v16qi __builtin_ia32_vpcomfalseb (v16qi, v16qi); 23075v4si __builtin_ia32_vpcomfalsed (v4si, v4si); 23076v2di __builtin_ia32_vpcomfalseq (v2di, v2di); 23077v16qi __builtin_ia32_vpcomfalseub (v16qi, v16qi); 23078v4si __builtin_ia32_vpcomfalseud (v4si, v4si); 23079v2di __builtin_ia32_vpcomfalseuq (v2di, v2di); 23080v8hi __builtin_ia32_vpcomfalseuw (v8hi, v8hi); 23081v8hi __builtin_ia32_vpcomfalsew (v8hi, v8hi); 23082v16qi __builtin_ia32_vpcomgeb (v16qi, v16qi); 23083v4si __builtin_ia32_vpcomged (v4si, v4si); 23084v2di __builtin_ia32_vpcomgeq (v2di, v2di); 23085v16qi __builtin_ia32_vpcomgeub (v16qi, v16qi); 23086v4si __builtin_ia32_vpcomgeud (v4si, v4si); 23087v2di __builtin_ia32_vpcomgeuq (v2di, v2di); 23088v8hi __builtin_ia32_vpcomgeuw (v8hi, v8hi); 23089v8hi __builtin_ia32_vpcomgew (v8hi, v8hi); 23090v16qi __builtin_ia32_vpcomgtb (v16qi, v16qi); 23091v4si __builtin_ia32_vpcomgtd (v4si, v4si); 23092v2di __builtin_ia32_vpcomgtq (v2di, v2di); 23093v16qi __builtin_ia32_vpcomgtub (v16qi, v16qi); 23094v4si __builtin_ia32_vpcomgtud (v4si, v4si); 23095v2di __builtin_ia32_vpcomgtuq (v2di, v2di); 23096v8hi __builtin_ia32_vpcomgtuw (v8hi, v8hi); 23097v8hi __builtin_ia32_vpcomgtw (v8hi, v8hi); 23098v16qi __builtin_ia32_vpcomleb (v16qi, v16qi); 23099v4si __builtin_ia32_vpcomled (v4si, v4si); 23100v2di __builtin_ia32_vpcomleq (v2di, v2di); 23101v16qi __builtin_ia32_vpcomleub (v16qi, v16qi); 23102v4si __builtin_ia32_vpcomleud (v4si, v4si); 23103v2di __builtin_ia32_vpcomleuq (v2di, v2di); 23104v8hi __builtin_ia32_vpcomleuw (v8hi, v8hi); 23105v8hi __builtin_ia32_vpcomlew (v8hi, v8hi); 23106v16qi __builtin_ia32_vpcomltb (v16qi, v16qi); 23107v4si __builtin_ia32_vpcomltd (v4si, v4si); 23108v2di __builtin_ia32_vpcomltq (v2di, v2di); 23109v16qi __builtin_ia32_vpcomltub (v16qi, v16qi); 23110v4si __builtin_ia32_vpcomltud (v4si, v4si); 23111v2di __builtin_ia32_vpcomltuq (v2di, v2di); 23112v8hi __builtin_ia32_vpcomltuw (v8hi, v8hi); 23113v8hi __builtin_ia32_vpcomltw (v8hi, v8hi); 23114v16qi __builtin_ia32_vpcomneb (v16qi, v16qi); 23115v4si __builtin_ia32_vpcomned (v4si, v4si); 23116v2di __builtin_ia32_vpcomneq (v2di, v2di); 23117v16qi __builtin_ia32_vpcomneub (v16qi, v16qi); 23118v4si __builtin_ia32_vpcomneud (v4si, v4si); 23119v2di __builtin_ia32_vpcomneuq (v2di, v2di); 23120v8hi __builtin_ia32_vpcomneuw (v8hi, v8hi); 23121v8hi __builtin_ia32_vpcomnew (v8hi, v8hi); 23122v16qi __builtin_ia32_vpcomtrueb (v16qi, v16qi); 23123v4si __builtin_ia32_vpcomtrued (v4si, v4si); 23124v2di __builtin_ia32_vpcomtrueq (v2di, v2di); 23125v16qi __builtin_ia32_vpcomtrueub (v16qi, v16qi); 23126v4si __builtin_ia32_vpcomtrueud (v4si, v4si); 23127v2di __builtin_ia32_vpcomtrueuq (v2di, v2di); 23128v8hi __builtin_ia32_vpcomtrueuw (v8hi, v8hi); 23129v8hi __builtin_ia32_vpcomtruew (v8hi, v8hi); 23130v4si __builtin_ia32_vphaddbd (v16qi); 23131v2di __builtin_ia32_vphaddbq (v16qi); 23132v8hi __builtin_ia32_vphaddbw (v16qi); 23133v2di __builtin_ia32_vphadddq (v4si); 23134v4si __builtin_ia32_vphaddubd (v16qi); 23135v2di __builtin_ia32_vphaddubq (v16qi); 23136v8hi __builtin_ia32_vphaddubw (v16qi); 23137v2di __builtin_ia32_vphaddudq (v4si); 23138v4si __builtin_ia32_vphadduwd (v8hi); 23139v2di __builtin_ia32_vphadduwq (v8hi); 23140v4si __builtin_ia32_vphaddwd (v8hi); 23141v2di __builtin_ia32_vphaddwq (v8hi); 23142v8hi __builtin_ia32_vphsubbw (v16qi); 23143v2di __builtin_ia32_vphsubdq (v4si); 23144v4si __builtin_ia32_vphsubwd (v8hi); 23145v4si __builtin_ia32_vpmacsdd (v4si, v4si, v4si); 23146v2di __builtin_ia32_vpmacsdqh (v4si, v4si, v2di); 23147v2di __builtin_ia32_vpmacsdql (v4si, v4si, v2di); 23148v4si __builtin_ia32_vpmacssdd (v4si, v4si, v4si); 23149v2di __builtin_ia32_vpmacssdqh (v4si, v4si, v2di); 23150v2di __builtin_ia32_vpmacssdql (v4si, v4si, v2di); 23151v4si __builtin_ia32_vpmacsswd (v8hi, v8hi, v4si); 23152v8hi __builtin_ia32_vpmacssww (v8hi, v8hi, v8hi); 23153v4si __builtin_ia32_vpmacswd (v8hi, v8hi, v4si); 23154v8hi __builtin_ia32_vpmacsww (v8hi, v8hi, v8hi); 23155v4si __builtin_ia32_vpmadcsswd (v8hi, v8hi, v4si); 23156v4si __builtin_ia32_vpmadcswd (v8hi, v8hi, v4si); 23157v16qi __builtin_ia32_vpperm (v16qi, v16qi, v16qi); 23158v16qi __builtin_ia32_vprotb (v16qi, v16qi); 23159v4si __builtin_ia32_vprotd (v4si, v4si); 23160v2di __builtin_ia32_vprotq (v2di, v2di); 23161v8hi __builtin_ia32_vprotw (v8hi, v8hi); 23162v16qi __builtin_ia32_vpshab (v16qi, v16qi); 23163v4si __builtin_ia32_vpshad (v4si, v4si); 23164v2di __builtin_ia32_vpshaq (v2di, v2di); 23165v8hi __builtin_ia32_vpshaw (v8hi, v8hi); 23166v16qi __builtin_ia32_vpshlb (v16qi, v16qi); 23167v4si __builtin_ia32_vpshld (v4si, v4si); 23168v2di __builtin_ia32_vpshlq (v2di, v2di); 23169v8hi __builtin_ia32_vpshlw (v8hi, v8hi); 23170@end smallexample 23171 23172The following built-in functions are available when @option{-mfma4} is used. 23173All of them generate the machine instruction that is part of the name. 23174 23175@smallexample 23176v2df __builtin_ia32_vfmaddpd (v2df, v2df, v2df); 23177v4sf __builtin_ia32_vfmaddps (v4sf, v4sf, v4sf); 23178v2df __builtin_ia32_vfmaddsd (v2df, v2df, v2df); 23179v4sf __builtin_ia32_vfmaddss (v4sf, v4sf, v4sf); 23180v2df __builtin_ia32_vfmsubpd (v2df, v2df, v2df); 23181v4sf __builtin_ia32_vfmsubps (v4sf, v4sf, v4sf); 23182v2df __builtin_ia32_vfmsubsd (v2df, v2df, v2df); 23183v4sf __builtin_ia32_vfmsubss (v4sf, v4sf, v4sf); 23184v2df __builtin_ia32_vfnmaddpd (v2df, v2df, v2df); 23185v4sf __builtin_ia32_vfnmaddps (v4sf, v4sf, v4sf); 23186v2df __builtin_ia32_vfnmaddsd (v2df, v2df, v2df); 23187v4sf __builtin_ia32_vfnmaddss (v4sf, v4sf, v4sf); 23188v2df __builtin_ia32_vfnmsubpd (v2df, v2df, v2df); 23189v4sf __builtin_ia32_vfnmsubps (v4sf, v4sf, v4sf); 23190v2df __builtin_ia32_vfnmsubsd (v2df, v2df, v2df); 23191v4sf __builtin_ia32_vfnmsubss (v4sf, v4sf, v4sf); 23192v2df __builtin_ia32_vfmaddsubpd (v2df, v2df, v2df); 23193v4sf __builtin_ia32_vfmaddsubps (v4sf, v4sf, v4sf); 23194v2df __builtin_ia32_vfmsubaddpd (v2df, v2df, v2df); 23195v4sf __builtin_ia32_vfmsubaddps (v4sf, v4sf, v4sf); 23196v4df __builtin_ia32_vfmaddpd256 (v4df, v4df, v4df); 23197v8sf __builtin_ia32_vfmaddps256 (v8sf, v8sf, v8sf); 23198v4df __builtin_ia32_vfmsubpd256 (v4df, v4df, v4df); 23199v8sf __builtin_ia32_vfmsubps256 (v8sf, v8sf, v8sf); 23200v4df __builtin_ia32_vfnmaddpd256 (v4df, v4df, v4df); 23201v8sf __builtin_ia32_vfnmaddps256 (v8sf, v8sf, v8sf); 23202v4df __builtin_ia32_vfnmsubpd256 (v4df, v4df, v4df); 23203v8sf __builtin_ia32_vfnmsubps256 (v8sf, v8sf, v8sf); 23204v4df __builtin_ia32_vfmaddsubpd256 (v4df, v4df, v4df); 23205v8sf __builtin_ia32_vfmaddsubps256 (v8sf, v8sf, v8sf); 23206v4df __builtin_ia32_vfmsubaddpd256 (v4df, v4df, v4df); 23207v8sf __builtin_ia32_vfmsubaddps256 (v8sf, v8sf, v8sf); 23208 23209@end smallexample 23210 23211The following built-in functions are available when @option{-mlwp} is used. 23212 23213@smallexample 23214void __builtin_ia32_llwpcb16 (void *); 23215void __builtin_ia32_llwpcb32 (void *); 23216void __builtin_ia32_llwpcb64 (void *); 23217void * __builtin_ia32_llwpcb16 (void); 23218void * __builtin_ia32_llwpcb32 (void); 23219void * __builtin_ia32_llwpcb64 (void); 23220void __builtin_ia32_lwpval16 (unsigned short, unsigned int, unsigned short); 23221void __builtin_ia32_lwpval32 (unsigned int, unsigned int, unsigned int); 23222void __builtin_ia32_lwpval64 (unsigned __int64, unsigned int, unsigned int); 23223unsigned char __builtin_ia32_lwpins16 (unsigned short, unsigned int, unsigned short); 23224unsigned char __builtin_ia32_lwpins32 (unsigned int, unsigned int, unsigned int); 23225unsigned char __builtin_ia32_lwpins64 (unsigned __int64, unsigned int, unsigned int); 23226@end smallexample 23227 23228The following built-in functions are available when @option{-mbmi} is used. 23229All of them generate the machine instruction that is part of the name. 23230@smallexample 23231unsigned int __builtin_ia32_bextr_u32(unsigned int, unsigned int); 23232unsigned long long __builtin_ia32_bextr_u64 (unsigned long long, unsigned long long); 23233@end smallexample 23234 23235The following built-in functions are available when @option{-mbmi2} is used. 23236All of them generate the machine instruction that is part of the name. 23237@smallexample 23238unsigned int _bzhi_u32 (unsigned int, unsigned int); 23239unsigned int _pdep_u32 (unsigned int, unsigned int); 23240unsigned int _pext_u32 (unsigned int, unsigned int); 23241unsigned long long _bzhi_u64 (unsigned long long, unsigned long long); 23242unsigned long long _pdep_u64 (unsigned long long, unsigned long long); 23243unsigned long long _pext_u64 (unsigned long long, unsigned long long); 23244@end smallexample 23245 23246The following built-in functions are available when @option{-mlzcnt} is used. 23247All of them generate the machine instruction that is part of the name. 23248@smallexample 23249unsigned short __builtin_ia32_lzcnt_u16(unsigned short); 23250unsigned int __builtin_ia32_lzcnt_u32(unsigned int); 23251unsigned long long __builtin_ia32_lzcnt_u64 (unsigned long long); 23252@end smallexample 23253 23254The following built-in functions are available when @option{-mfxsr} is used. 23255All of them generate the machine instruction that is part of the name. 23256@smallexample 23257void __builtin_ia32_fxsave (void *); 23258void __builtin_ia32_fxrstor (void *); 23259void __builtin_ia32_fxsave64 (void *); 23260void __builtin_ia32_fxrstor64 (void *); 23261@end smallexample 23262 23263The following built-in functions are available when @option{-mxsave} is used. 23264All of them generate the machine instruction that is part of the name. 23265@smallexample 23266void __builtin_ia32_xsave (void *, long long); 23267void __builtin_ia32_xrstor (void *, long long); 23268void __builtin_ia32_xsave64 (void *, long long); 23269void __builtin_ia32_xrstor64 (void *, long long); 23270@end smallexample 23271 23272The following built-in functions are available when @option{-mxsaveopt} is used. 23273All of them generate the machine instruction that is part of the name. 23274@smallexample 23275void __builtin_ia32_xsaveopt (void *, long long); 23276void __builtin_ia32_xsaveopt64 (void *, long long); 23277@end smallexample 23278 23279The following built-in functions are available when @option{-mtbm} is used. 23280Both of them generate the immediate form of the bextr machine instruction. 23281@smallexample 23282unsigned int __builtin_ia32_bextri_u32 (unsigned int, 23283 const unsigned int); 23284unsigned long long __builtin_ia32_bextri_u64 (unsigned long long, 23285 const unsigned long long); 23286@end smallexample 23287 23288 23289The following built-in functions are available when @option{-m3dnow} is used. 23290All of them generate the machine instruction that is part of the name. 23291 23292@smallexample 23293void __builtin_ia32_femms (void); 23294v8qi __builtin_ia32_pavgusb (v8qi, v8qi); 23295v2si __builtin_ia32_pf2id (v2sf); 23296v2sf __builtin_ia32_pfacc (v2sf, v2sf); 23297v2sf __builtin_ia32_pfadd (v2sf, v2sf); 23298v2si __builtin_ia32_pfcmpeq (v2sf, v2sf); 23299v2si __builtin_ia32_pfcmpge (v2sf, v2sf); 23300v2si __builtin_ia32_pfcmpgt (v2sf, v2sf); 23301v2sf __builtin_ia32_pfmax (v2sf, v2sf); 23302v2sf __builtin_ia32_pfmin (v2sf, v2sf); 23303v2sf __builtin_ia32_pfmul (v2sf, v2sf); 23304v2sf __builtin_ia32_pfrcp (v2sf); 23305v2sf __builtin_ia32_pfrcpit1 (v2sf, v2sf); 23306v2sf __builtin_ia32_pfrcpit2 (v2sf, v2sf); 23307v2sf __builtin_ia32_pfrsqrt (v2sf); 23308v2sf __builtin_ia32_pfsub (v2sf, v2sf); 23309v2sf __builtin_ia32_pfsubr (v2sf, v2sf); 23310v2sf __builtin_ia32_pi2fd (v2si); 23311v4hi __builtin_ia32_pmulhrw (v4hi, v4hi); 23312@end smallexample 23313 23314The following built-in functions are available when @option{-m3dnowa} is used. 23315All of them generate the machine instruction that is part of the name. 23316 23317@smallexample 23318v2si __builtin_ia32_pf2iw (v2sf); 23319v2sf __builtin_ia32_pfnacc (v2sf, v2sf); 23320v2sf __builtin_ia32_pfpnacc (v2sf, v2sf); 23321v2sf __builtin_ia32_pi2fw (v2si); 23322v2sf __builtin_ia32_pswapdsf (v2sf); 23323v2si __builtin_ia32_pswapdsi (v2si); 23324@end smallexample 23325 23326The following built-in functions are available when @option{-mrtm} is used 23327They are used for restricted transactional memory. These are the internal 23328low level functions. Normally the functions in 23329@ref{x86 transactional memory intrinsics} should be used instead. 23330 23331@smallexample 23332int __builtin_ia32_xbegin (); 23333void __builtin_ia32_xend (); 23334void __builtin_ia32_xabort (status); 23335int __builtin_ia32_xtest (); 23336@end smallexample 23337 23338The following built-in functions are available when @option{-mmwaitx} is used. 23339All of them generate the machine instruction that is part of the name. 23340@smallexample 23341void __builtin_ia32_monitorx (void *, unsigned int, unsigned int); 23342void __builtin_ia32_mwaitx (unsigned int, unsigned int, unsigned int); 23343@end smallexample 23344 23345The following built-in functions are available when @option{-mclzero} is used. 23346All of them generate the machine instruction that is part of the name. 23347@smallexample 23348void __builtin_i32_clzero (void *); 23349@end smallexample 23350 23351The following built-in functions are available when @option{-mpku} is used. 23352They generate reads and writes to PKRU. 23353@smallexample 23354void __builtin_ia32_wrpkru (unsigned int); 23355unsigned int __builtin_ia32_rdpkru (); 23356@end smallexample 23357 23358The following built-in functions are available when 23359@option{-mshstk} option is used. They support shadow stack 23360machine instructions from Intel Control-flow Enforcement Technology (CET). 23361Each built-in function generates the machine instruction that is part 23362of the function's name. These are the internal low-level functions. 23363Normally the functions in @ref{x86 control-flow protection intrinsics} 23364should be used instead. 23365 23366@smallexample 23367unsigned int __builtin_ia32_rdsspd (void); 23368unsigned long long __builtin_ia32_rdsspq (void); 23369void __builtin_ia32_incsspd (unsigned int); 23370void __builtin_ia32_incsspq (unsigned long long); 23371void __builtin_ia32_saveprevssp(void); 23372void __builtin_ia32_rstorssp(void *); 23373void __builtin_ia32_wrssd(unsigned int, void *); 23374void __builtin_ia32_wrssq(unsigned long long, void *); 23375void __builtin_ia32_wrussd(unsigned int, void *); 23376void __builtin_ia32_wrussq(unsigned long long, void *); 23377void __builtin_ia32_setssbsy(void); 23378void __builtin_ia32_clrssbsy(void *); 23379@end smallexample 23380 23381@node x86 transactional memory intrinsics 23382@subsection x86 Transactional Memory Intrinsics 23383 23384These hardware transactional memory intrinsics for x86 allow you to use 23385memory transactions with RTM (Restricted Transactional Memory). 23386This support is enabled with the @option{-mrtm} option. 23387For using HLE (Hardware Lock Elision) see 23388@ref{x86 specific memory model extensions for transactional memory} instead. 23389 23390A memory transaction commits all changes to memory in an atomic way, 23391as visible to other threads. If the transaction fails it is rolled back 23392and all side effects discarded. 23393 23394Generally there is no guarantee that a memory transaction ever succeeds 23395and suitable fallback code always needs to be supplied. 23396 23397@deftypefn {RTM Function} {unsigned} _xbegin () 23398Start a RTM (Restricted Transactional Memory) transaction. 23399Returns @code{_XBEGIN_STARTED} when the transaction 23400started successfully (note this is not 0, so the constant has to be 23401explicitly tested). 23402 23403If the transaction aborts, all side effects 23404are undone and an abort code encoded as a bit mask is returned. 23405The following macros are defined: 23406 23407@table @code 23408@item _XABORT_EXPLICIT 23409Transaction was explicitly aborted with @code{_xabort}. The parameter passed 23410to @code{_xabort} is available with @code{_XABORT_CODE(status)}. 23411@item _XABORT_RETRY 23412Transaction retry is possible. 23413@item _XABORT_CONFLICT 23414Transaction abort due to a memory conflict with another thread. 23415@item _XABORT_CAPACITY 23416Transaction abort due to the transaction using too much memory. 23417@item _XABORT_DEBUG 23418Transaction abort due to a debug trap. 23419@item _XABORT_NESTED 23420Transaction abort in an inner nested transaction. 23421@end table 23422 23423There is no guarantee 23424any transaction ever succeeds, so there always needs to be a valid 23425fallback path. 23426@end deftypefn 23427 23428@deftypefn {RTM Function} {void} _xend () 23429Commit the current transaction. When no transaction is active this faults. 23430All memory side effects of the transaction become visible 23431to other threads in an atomic manner. 23432@end deftypefn 23433 23434@deftypefn {RTM Function} {int} _xtest () 23435Return a nonzero value if a transaction is currently active, otherwise 0. 23436@end deftypefn 23437 23438@deftypefn {RTM Function} {void} _xabort (status) 23439Abort the current transaction. When no transaction is active this is a no-op. 23440The @var{status} is an 8-bit constant; its value is encoded in the return 23441value from @code{_xbegin}. 23442@end deftypefn 23443 23444Here is an example showing handling for @code{_XABORT_RETRY} 23445and a fallback path for other failures: 23446 23447@smallexample 23448#include <immintrin.h> 23449 23450int n_tries, max_tries; 23451unsigned status = _XABORT_EXPLICIT; 23452... 23453 23454for (n_tries = 0; n_tries < max_tries; n_tries++) 23455 @{ 23456 status = _xbegin (); 23457 if (status == _XBEGIN_STARTED || !(status & _XABORT_RETRY)) 23458 break; 23459 @} 23460if (status == _XBEGIN_STARTED) 23461 @{ 23462 ... transaction code... 23463 _xend (); 23464 @} 23465else 23466 @{ 23467 ... non-transactional fallback path... 23468 @} 23469@end smallexample 23470 23471@noindent 23472Note that, in most cases, the transactional and non-transactional code 23473must synchronize together to ensure consistency. 23474 23475@node x86 control-flow protection intrinsics 23476@subsection x86 Control-Flow Protection Intrinsics 23477 23478@deftypefn {CET Function} {ret_type} _get_ssp (void) 23479Get the current value of shadow stack pointer if shadow stack support 23480from Intel CET is enabled in the hardware or @code{0} otherwise. 23481The @code{ret_type} is @code{unsigned long long} for 64-bit targets 23482and @code{unsigned int} for 32-bit targets. 23483@end deftypefn 23484 23485@deftypefn {CET Function} void _inc_ssp (unsigned int) 23486Increment the current shadow stack pointer by the size specified by the 23487function argument. The argument is masked to a byte value for security 23488reasons, so to increment by more than 255 bytes you must call the function 23489multiple times. 23490@end deftypefn 23491 23492The shadow stack unwind code looks like: 23493 23494@smallexample 23495#include <immintrin.h> 23496 23497/* Unwind the shadow stack for EH. */ 23498#define _Unwind_Frames_Extra(x) \ 23499 do \ 23500 @{ \ 23501 _Unwind_Word ssp = _get_ssp (); \ 23502 if (ssp != 0) \ 23503 @{ \ 23504 _Unwind_Word tmp = (x); \ 23505 while (tmp > 255) \ 23506 @{ \ 23507 _inc_ssp (tmp); \ 23508 tmp -= 255; \ 23509 @} \ 23510 _inc_ssp (tmp); \ 23511 @} \ 23512 @} \ 23513 while (0) 23514@end smallexample 23515 23516@noindent 23517This code runs unconditionally on all 64-bit processors. For 32-bit 23518processors the code runs on those that support multi-byte NOP instructions. 23519 23520@node Target Format Checks 23521@section Format Checks Specific to Particular Target Machines 23522 23523For some target machines, GCC supports additional options to the 23524format attribute 23525(@pxref{Function Attributes,,Declaring Attributes of Functions}). 23526 23527@menu 23528* Solaris Format Checks:: 23529* Darwin Format Checks:: 23530@end menu 23531 23532@node Solaris Format Checks 23533@subsection Solaris Format Checks 23534 23535Solaris targets support the @code{cmn_err} (or @code{__cmn_err__}) format 23536check. @code{cmn_err} accepts a subset of the standard @code{printf} 23537conversions, and the two-argument @code{%b} conversion for displaying 23538bit-fields. See the Solaris man page for @code{cmn_err} for more information. 23539 23540@node Darwin Format Checks 23541@subsection Darwin Format Checks 23542 23543In addition to the full set of format archetypes (attribute format style 23544arguments such as @code{printf}, @code{scanf}, @code{strftime}, and 23545@code{strfmon}), Darwin targets also support the @code{CFString} (or 23546@code{__CFString__}) archetype in the @code{format} attribute. 23547Declarations with this archetype are parsed for correct syntax 23548and argument types. However, parsing of the format string itself and 23549validating arguments against it in calls to such functions is currently 23550not performed. 23551 23552Additionally, @code{CFStringRefs} (defined by the @code{CoreFoundation} headers) may 23553also be used as format arguments. Note that the relevant headers are only likely to be 23554available on Darwin (OSX) installations. On such installations, the XCode and system 23555documentation provide descriptions of @code{CFString}, @code{CFStringRefs} and 23556associated functions. 23557 23558@node Pragmas 23559@section Pragmas Accepted by GCC 23560@cindex pragmas 23561@cindex @code{#pragma} 23562 23563GCC supports several types of pragmas, primarily in order to compile 23564code originally written for other compilers. Note that in general 23565we do not recommend the use of pragmas; @xref{Function Attributes}, 23566for further explanation. 23567 23568The GNU C preprocessor recognizes several pragmas in addition to the 23569compiler pragmas documented here. Refer to the CPP manual for more 23570information. 23571 23572@menu 23573* AArch64 Pragmas:: 23574* ARM Pragmas:: 23575* M32C Pragmas:: 23576* MeP Pragmas:: 23577* PRU Pragmas:: 23578* RS/6000 and PowerPC Pragmas:: 23579* S/390 Pragmas:: 23580* Darwin Pragmas:: 23581* Solaris Pragmas:: 23582* Symbol-Renaming Pragmas:: 23583* Structure-Layout Pragmas:: 23584* Weak Pragmas:: 23585* Diagnostic Pragmas:: 23586* Visibility Pragmas:: 23587* Push/Pop Macro Pragmas:: 23588* Function Specific Option Pragmas:: 23589* Loop-Specific Pragmas:: 23590@end menu 23591 23592@node AArch64 Pragmas 23593@subsection AArch64 Pragmas 23594 23595The pragmas defined by the AArch64 target correspond to the AArch64 23596target function attributes. They can be specified as below: 23597@smallexample 23598#pragma GCC target("string") 23599@end smallexample 23600 23601where @code{@var{string}} can be any string accepted as an AArch64 target 23602attribute. @xref{AArch64 Function Attributes}, for more details 23603on the permissible values of @code{string}. 23604 23605@node ARM Pragmas 23606@subsection ARM Pragmas 23607 23608The ARM target defines pragmas for controlling the default addition of 23609@code{long_call} and @code{short_call} attributes to functions. 23610@xref{Function Attributes}, for information about the effects of these 23611attributes. 23612 23613@table @code 23614@item long_calls 23615@cindex pragma, long_calls 23616Set all subsequent functions to have the @code{long_call} attribute. 23617 23618@item no_long_calls 23619@cindex pragma, no_long_calls 23620Set all subsequent functions to have the @code{short_call} attribute. 23621 23622@item long_calls_off 23623@cindex pragma, long_calls_off 23624Do not affect the @code{long_call} or @code{short_call} attributes of 23625subsequent functions. 23626@end table 23627 23628@node M32C Pragmas 23629@subsection M32C Pragmas 23630 23631@table @code 23632@item GCC memregs @var{number} 23633@cindex pragma, memregs 23634Overrides the command-line option @code{-memregs=} for the current 23635file. Use with care! This pragma must be before any function in the 23636file, and mixing different memregs values in different objects may 23637make them incompatible. This pragma is useful when a 23638performance-critical function uses a memreg for temporary values, 23639as it may allow you to reduce the number of memregs used. 23640 23641@item ADDRESS @var{name} @var{address} 23642@cindex pragma, address 23643For any declared symbols matching @var{name}, this does three things 23644to that symbol: it forces the symbol to be located at the given 23645address (a number), it forces the symbol to be volatile, and it 23646changes the symbol's scope to be static. This pragma exists for 23647compatibility with other compilers, but note that the common 23648@code{1234H} numeric syntax is not supported (use @code{0x1234} 23649instead). Example: 23650 23651@smallexample 23652#pragma ADDRESS port3 0x103 23653char port3; 23654@end smallexample 23655 23656@end table 23657 23658@node MeP Pragmas 23659@subsection MeP Pragmas 23660 23661@table @code 23662 23663@item custom io_volatile (on|off) 23664@cindex pragma, custom io_volatile 23665Overrides the command-line option @code{-mio-volatile} for the current 23666file. Note that for compatibility with future GCC releases, this 23667option should only be used once before any @code{io} variables in each 23668file. 23669 23670@item GCC coprocessor available @var{registers} 23671@cindex pragma, coprocessor available 23672Specifies which coprocessor registers are available to the register 23673allocator. @var{registers} may be a single register, register range 23674separated by ellipses, or comma-separated list of those. Example: 23675 23676@smallexample 23677#pragma GCC coprocessor available $c0...$c10, $c28 23678@end smallexample 23679 23680@item GCC coprocessor call_saved @var{registers} 23681@cindex pragma, coprocessor call_saved 23682Specifies which coprocessor registers are to be saved and restored by 23683any function using them. @var{registers} may be a single register, 23684register range separated by ellipses, or comma-separated list of 23685those. Example: 23686 23687@smallexample 23688#pragma GCC coprocessor call_saved $c4...$c6, $c31 23689@end smallexample 23690 23691@item GCC coprocessor subclass '(A|B|C|D)' = @var{registers} 23692@cindex pragma, coprocessor subclass 23693Creates and defines a register class. These register classes can be 23694used by inline @code{asm} constructs. @var{registers} may be a single 23695register, register range separated by ellipses, or comma-separated 23696list of those. Example: 23697 23698@smallexample 23699#pragma GCC coprocessor subclass 'B' = $c2, $c4, $c6 23700 23701asm ("cpfoo %0" : "=B" (x)); 23702@end smallexample 23703 23704@item GCC disinterrupt @var{name} , @var{name} @dots{} 23705@cindex pragma, disinterrupt 23706For the named functions, the compiler adds code to disable interrupts 23707for the duration of those functions. If any functions so named 23708are not encountered in the source, a warning is emitted that the pragma is 23709not used. Examples: 23710 23711@smallexample 23712#pragma disinterrupt foo 23713#pragma disinterrupt bar, grill 23714int foo () @{ @dots{} @} 23715@end smallexample 23716 23717@item GCC call @var{name} , @var{name} @dots{} 23718@cindex pragma, call 23719For the named functions, the compiler always uses a register-indirect 23720call model when calling the named functions. Examples: 23721 23722@smallexample 23723extern int foo (); 23724#pragma call foo 23725@end smallexample 23726 23727@end table 23728 23729@node PRU Pragmas 23730@subsection PRU Pragmas 23731 23732@table @code 23733 23734@item ctable_entry @var{index} @var{constant_address} 23735@cindex pragma, ctable_entry 23736Specifies that the PRU CTABLE entry given by @var{index} has the value 23737@var{constant_address}. This enables GCC to emit LBCO/SBCO instructions 23738when the load/store address is known and can be addressed with some CTABLE 23739entry. For example: 23740 23741@smallexample 23742/* will compile to "sbco Rx, 2, 0x10, 4" */ 23743#pragma ctable_entry 2 0x4802a000 23744*(unsigned int *)0x4802a010 = val; 23745@end smallexample 23746 23747@end table 23748 23749@node RS/6000 and PowerPC Pragmas 23750@subsection RS/6000 and PowerPC Pragmas 23751 23752The RS/6000 and PowerPC targets define one pragma for controlling 23753whether or not the @code{longcall} attribute is added to function 23754declarations by default. This pragma overrides the @option{-mlongcall} 23755option, but not the @code{longcall} and @code{shortcall} attributes. 23756@xref{RS/6000 and PowerPC Options}, for more information about when long 23757calls are and are not necessary. 23758 23759@table @code 23760@item longcall (1) 23761@cindex pragma, longcall 23762Apply the @code{longcall} attribute to all subsequent function 23763declarations. 23764 23765@item longcall (0) 23766Do not apply the @code{longcall} attribute to subsequent function 23767declarations. 23768@end table 23769 23770@c Describe h8300 pragmas here. 23771@c Describe sh pragmas here. 23772@c Describe v850 pragmas here. 23773 23774@node S/390 Pragmas 23775@subsection S/390 Pragmas 23776 23777The pragmas defined by the S/390 target correspond to the S/390 23778target function attributes and some the additional options: 23779 23780@table @samp 23781@item zvector 23782@itemx no-zvector 23783@end table 23784 23785Note that options of the pragma, unlike options of the target 23786attribute, do change the value of preprocessor macros like 23787@code{__VEC__}. They can be specified as below: 23788 23789@smallexample 23790#pragma GCC target("string[,string]...") 23791#pragma GCC target("string"[,"string"]...) 23792@end smallexample 23793 23794@node Darwin Pragmas 23795@subsection Darwin Pragmas 23796 23797The following pragmas are available for all architectures running the 23798Darwin operating system. These are useful for compatibility with other 23799Mac OS compilers. 23800 23801@table @code 23802@item mark @var{tokens}@dots{} 23803@cindex pragma, mark 23804This pragma is accepted, but has no effect. 23805 23806@item options align=@var{alignment} 23807@cindex pragma, options align 23808This pragma sets the alignment of fields in structures. The values of 23809@var{alignment} may be @code{mac68k}, to emulate m68k alignment, or 23810@code{power}, to emulate PowerPC alignment. Uses of this pragma nest 23811properly; to restore the previous setting, use @code{reset} for the 23812@var{alignment}. 23813 23814@item segment @var{tokens}@dots{} 23815@cindex pragma, segment 23816This pragma is accepted, but has no effect. 23817 23818@item unused (@var{var} [, @var{var}]@dots{}) 23819@cindex pragma, unused 23820This pragma declares variables to be possibly unused. GCC does not 23821produce warnings for the listed variables. The effect is similar to 23822that of the @code{unused} attribute, except that this pragma may appear 23823anywhere within the variables' scopes. 23824@end table 23825 23826@node Solaris Pragmas 23827@subsection Solaris Pragmas 23828 23829The Solaris target supports @code{#pragma redefine_extname} 23830(@pxref{Symbol-Renaming Pragmas}). It also supports additional 23831@code{#pragma} directives for compatibility with the system compiler. 23832 23833@table @code 23834@item align @var{alignment} (@var{variable} [, @var{variable}]...) 23835@cindex pragma, align 23836 23837Increase the minimum alignment of each @var{variable} to @var{alignment}. 23838This is the same as GCC's @code{aligned} attribute @pxref{Variable 23839Attributes}). Macro expansion occurs on the arguments to this pragma 23840when compiling C and Objective-C@. It does not currently occur when 23841compiling C++, but this is a bug which may be fixed in a future 23842release. 23843 23844@item fini (@var{function} [, @var{function}]...) 23845@cindex pragma, fini 23846 23847This pragma causes each listed @var{function} to be called after 23848main, or during shared module unloading, by adding a call to the 23849@code{.fini} section. 23850 23851@item init (@var{function} [, @var{function}]...) 23852@cindex pragma, init 23853 23854This pragma causes each listed @var{function} to be called during 23855initialization (before @code{main}) or during shared module loading, by 23856adding a call to the @code{.init} section. 23857 23858@end table 23859 23860@node Symbol-Renaming Pragmas 23861@subsection Symbol-Renaming Pragmas 23862 23863GCC supports a @code{#pragma} directive that changes the name used in 23864assembly for a given declaration. While this pragma is supported on all 23865platforms, it is intended primarily to provide compatibility with the 23866Solaris system headers. This effect can also be achieved using the asm 23867labels extension (@pxref{Asm Labels}). 23868 23869@table @code 23870@item redefine_extname @var{oldname} @var{newname} 23871@cindex pragma, redefine_extname 23872 23873This pragma gives the C function @var{oldname} the assembly symbol 23874@var{newname}. The preprocessor macro @code{__PRAGMA_REDEFINE_EXTNAME} 23875is defined if this pragma is available (currently on all platforms). 23876@end table 23877 23878This pragma and the @code{asm} labels extension interact in a complicated 23879manner. Here are some corner cases you may want to be aware of: 23880 23881@enumerate 23882@item This pragma silently applies only to declarations with external 23883linkage. The @code{asm} label feature does not have this restriction. 23884 23885@item In C++, this pragma silently applies only to declarations with 23886``C'' linkage. Again, @code{asm} labels do not have this restriction. 23887 23888@item If either of the ways of changing the assembly name of a 23889declaration are applied to a declaration whose assembly name has 23890already been determined (either by a previous use of one of these 23891features, or because the compiler needed the assembly name in order to 23892generate code), and the new name is different, a warning issues and 23893the name does not change. 23894 23895@item The @var{oldname} used by @code{#pragma redefine_extname} is 23896always the C-language name. 23897@end enumerate 23898 23899@node Structure-Layout Pragmas 23900@subsection Structure-Layout Pragmas 23901 23902For compatibility with Microsoft Windows compilers, GCC supports a 23903set of @code{#pragma} directives that change the maximum alignment of 23904members of structures (other than zero-width bit-fields), unions, and 23905classes subsequently defined. The @var{n} value below always is required 23906to be a small power of two and specifies the new alignment in bytes. 23907 23908@enumerate 23909@item @code{#pragma pack(@var{n})} simply sets the new alignment. 23910@item @code{#pragma pack()} sets the alignment to the one that was in 23911effect when compilation started (see also command-line option 23912@option{-fpack-struct[=@var{n}]} @pxref{Code Gen Options}). 23913@item @code{#pragma pack(push[,@var{n}])} pushes the current alignment 23914setting on an internal stack and then optionally sets the new alignment. 23915@item @code{#pragma pack(pop)} restores the alignment setting to the one 23916saved at the top of the internal stack (and removes that stack entry). 23917Note that @code{#pragma pack([@var{n}])} does not influence this internal 23918stack; thus it is possible to have @code{#pragma pack(push)} followed by 23919multiple @code{#pragma pack(@var{n})} instances and finalized by a single 23920@code{#pragma pack(pop)}. 23921@end enumerate 23922 23923Some targets, e.g.@: x86 and PowerPC, support the @code{#pragma ms_struct} 23924directive which lays out structures and unions subsequently defined as the 23925documented @code{__attribute__ ((ms_struct))}. 23926 23927@enumerate 23928@item @code{#pragma ms_struct on} turns on the Microsoft layout. 23929@item @code{#pragma ms_struct off} turns off the Microsoft layout. 23930@item @code{#pragma ms_struct reset} goes back to the default layout. 23931@end enumerate 23932 23933Most targets also support the @code{#pragma scalar_storage_order} directive 23934which lays out structures and unions subsequently defined as the documented 23935@code{__attribute__ ((scalar_storage_order))}. 23936 23937@enumerate 23938@item @code{#pragma scalar_storage_order big-endian} sets the storage order 23939of the scalar fields to big-endian. 23940@item @code{#pragma scalar_storage_order little-endian} sets the storage order 23941of the scalar fields to little-endian. 23942@item @code{#pragma scalar_storage_order default} goes back to the endianness 23943that was in effect when compilation started (see also command-line option 23944@option{-fsso-struct=@var{endianness}} @pxref{C Dialect Options}). 23945@end enumerate 23946 23947@node Weak Pragmas 23948@subsection Weak Pragmas 23949 23950For compatibility with SVR4, GCC supports a set of @code{#pragma} 23951directives for declaring symbols to be weak, and defining weak 23952aliases. 23953 23954@table @code 23955@item #pragma weak @var{symbol} 23956@cindex pragma, weak 23957This pragma declares @var{symbol} to be weak, as if the declaration 23958had the attribute of the same name. The pragma may appear before 23959or after the declaration of @var{symbol}. It is not an error for 23960@var{symbol} to never be defined at all. 23961 23962@item #pragma weak @var{symbol1} = @var{symbol2} 23963This pragma declares @var{symbol1} to be a weak alias of @var{symbol2}. 23964It is an error if @var{symbol2} is not defined in the current 23965translation unit. 23966@end table 23967 23968@node Diagnostic Pragmas 23969@subsection Diagnostic Pragmas 23970 23971GCC allows the user to selectively enable or disable certain types of 23972diagnostics, and change the kind of the diagnostic. For example, a 23973project's policy might require that all sources compile with 23974@option{-Werror} but certain files might have exceptions allowing 23975specific types of warnings. Or, a project might selectively enable 23976diagnostics and treat them as errors depending on which preprocessor 23977macros are defined. 23978 23979@table @code 23980@item #pragma GCC diagnostic @var{kind} @var{option} 23981@cindex pragma, diagnostic 23982 23983Modifies the disposition of a diagnostic. Note that not all 23984diagnostics are modifiable; at the moment only warnings (normally 23985controlled by @samp{-W@dots{}}) can be controlled, and not all of them. 23986Use @option{-fdiagnostics-show-option} to determine which diagnostics 23987are controllable and which option controls them. 23988 23989@var{kind} is @samp{error} to treat this diagnostic as an error, 23990@samp{warning} to treat it like a warning (even if @option{-Werror} is 23991in effect), or @samp{ignored} if the diagnostic is to be ignored. 23992@var{option} is a double quoted string that matches the command-line 23993option. 23994 23995@smallexample 23996#pragma GCC diagnostic warning "-Wformat" 23997#pragma GCC diagnostic error "-Wformat" 23998#pragma GCC diagnostic ignored "-Wformat" 23999@end smallexample 24000 24001Note that these pragmas override any command-line options. GCC keeps 24002track of the location of each pragma, and issues diagnostics according 24003to the state as of that point in the source file. Thus, pragmas occurring 24004after a line do not affect diagnostics caused by that line. 24005 24006@item #pragma GCC diagnostic push 24007@itemx #pragma GCC diagnostic pop 24008 24009Causes GCC to remember the state of the diagnostics as of each 24010@code{push}, and restore to that point at each @code{pop}. If a 24011@code{pop} has no matching @code{push}, the command-line options are 24012restored. 24013 24014@smallexample 24015#pragma GCC diagnostic error "-Wuninitialized" 24016 foo(a); /* error is given for this one */ 24017#pragma GCC diagnostic push 24018#pragma GCC diagnostic ignored "-Wuninitialized" 24019 foo(b); /* no diagnostic for this one */ 24020#pragma GCC diagnostic pop 24021 foo(c); /* error is given for this one */ 24022#pragma GCC diagnostic pop 24023 foo(d); /* depends on command-line options */ 24024@end smallexample 24025 24026@item #pragma GCC diagnostic ignored_attributes 24027 24028Similarly to @option{-Wno-attributes=}, this pragma allows users to suppress 24029warnings about unknown scoped attributes (in C++11 and C2X). For example, 24030@code{#pragma GCC diagnostic ignored_attributes "vendor::attr"} disables 24031warning about the following declaration: 24032 24033@smallexample 24034[[vendor::attr]] void f(); 24035@end smallexample 24036 24037whereas @code{#pragma GCC diagnostic ignored_attributes "vendor::"} prevents 24038warning about both of these declarations: 24039 24040@smallexample 24041[[vendor::safe]] void f(); 24042[[vendor::unsafe]] void f2(); 24043@end smallexample 24044 24045@end table 24046 24047GCC also offers a simple mechanism for printing messages during 24048compilation. 24049 24050@table @code 24051@item #pragma message @var{string} 24052@cindex pragma, diagnostic 24053 24054Prints @var{string} as a compiler message on compilation. The message 24055is informational only, and is neither a compilation warning nor an 24056error. Newlines can be included in the string by using the @samp{\n} 24057escape sequence. 24058 24059@smallexample 24060#pragma message "Compiling " __FILE__ "..." 24061@end smallexample 24062 24063@var{string} may be parenthesized, and is printed with location 24064information. For example, 24065 24066@smallexample 24067#define DO_PRAGMA(x) _Pragma (#x) 24068#define TODO(x) DO_PRAGMA(message ("TODO - " #x)) 24069 24070TODO(Remember to fix this) 24071@end smallexample 24072 24073@noindent 24074prints @samp{/tmp/file.c:4: note: #pragma message: 24075TODO - Remember to fix this}. 24076 24077@item #pragma GCC error @var{message} 24078@cindex pragma, diagnostic 24079Generates an error message. This pragma @emph{is} considered to 24080indicate an error in the compilation, and it will be treated as such. 24081 24082Newlines can be included in the string by using the @samp{\n} 24083escape sequence. They will be displayed as newlines even if the 24084@option{-fmessage-length} option is set to zero. 24085 24086The error is only generated if the pragma is present in the code after 24087pre-processing has been completed. It does not matter however if the 24088code containing the pragma is unreachable: 24089 24090@smallexample 24091#if 0 24092#pragma GCC error "this error is not seen" 24093#endif 24094void foo (void) 24095@{ 24096 return; 24097#pragma GCC error "this error is seen" 24098@} 24099@end smallexample 24100 24101@item #pragma GCC warning @var{message} 24102@cindex pragma, diagnostic 24103This is just like @samp{pragma GCC error} except that a warning 24104message is issued instead of an error message. Unless 24105@option{-Werror} is in effect, in which case this pragma will generate 24106an error as well. 24107 24108@end table 24109 24110@node Visibility Pragmas 24111@subsection Visibility Pragmas 24112 24113@table @code 24114@item #pragma GCC visibility push(@var{visibility}) 24115@itemx #pragma GCC visibility pop 24116@cindex pragma, visibility 24117 24118This pragma allows the user to set the visibility for multiple 24119declarations without having to give each a visibility attribute 24120(@pxref{Function Attributes}). 24121 24122In C++, @samp{#pragma GCC visibility} affects only namespace-scope 24123declarations. Class members and template specializations are not 24124affected; if you want to override the visibility for a particular 24125member or instantiation, you must use an attribute. 24126 24127@end table 24128 24129 24130@node Push/Pop Macro Pragmas 24131@subsection Push/Pop Macro Pragmas 24132 24133For compatibility with Microsoft Windows compilers, GCC supports 24134@samp{#pragma push_macro(@var{"macro_name"})} 24135and @samp{#pragma pop_macro(@var{"macro_name"})}. 24136 24137@table @code 24138@item #pragma push_macro(@var{"macro_name"}) 24139@cindex pragma, push_macro 24140This pragma saves the value of the macro named as @var{macro_name} to 24141the top of the stack for this macro. 24142 24143@item #pragma pop_macro(@var{"macro_name"}) 24144@cindex pragma, pop_macro 24145This pragma sets the value of the macro named as @var{macro_name} to 24146the value on top of the stack for this macro. If the stack for 24147@var{macro_name} is empty, the value of the macro remains unchanged. 24148@end table 24149 24150For example: 24151 24152@smallexample 24153#define X 1 24154#pragma push_macro("X") 24155#undef X 24156#define X -1 24157#pragma pop_macro("X") 24158int x [X]; 24159@end smallexample 24160 24161@noindent 24162In this example, the definition of X as 1 is saved by @code{#pragma 24163push_macro} and restored by @code{#pragma pop_macro}. 24164 24165@node Function Specific Option Pragmas 24166@subsection Function Specific Option Pragmas 24167 24168@table @code 24169@item #pragma GCC target (@var{string}, @dots{}) 24170@cindex pragma GCC target 24171 24172This pragma allows you to set target-specific options for functions 24173defined later in the source file. One or more strings can be 24174specified. Each function that is defined after this point is treated 24175as if it had been declared with one @code{target(}@var{string}@code{)} 24176attribute for each @var{string} argument. The parentheses around 24177the strings in the pragma are optional. @xref{Function Attributes}, 24178for more information about the @code{target} attribute and the attribute 24179syntax. 24180 24181The @code{#pragma GCC target} pragma is presently implemented for 24182x86, ARM, AArch64, PowerPC, S/390, and Nios II targets only. 24183 24184@item #pragma GCC optimize (@var{string}, @dots{}) 24185@cindex pragma GCC optimize 24186 24187This pragma allows you to set global optimization options for functions 24188defined later in the source file. One or more strings can be 24189specified. Each function that is defined after this point is treated 24190as if it had been declared with one @code{optimize(}@var{string}@code{)} 24191attribute for each @var{string} argument. The parentheses around 24192the strings in the pragma are optional. @xref{Function Attributes}, 24193for more information about the @code{optimize} attribute and the attribute 24194syntax. 24195 24196@item #pragma GCC push_options 24197@itemx #pragma GCC pop_options 24198@cindex pragma GCC push_options 24199@cindex pragma GCC pop_options 24200 24201These pragmas maintain a stack of the current target and optimization 24202options. It is intended for include files where you temporarily want 24203to switch to using a different @samp{#pragma GCC target} or 24204@samp{#pragma GCC optimize} and then to pop back to the previous 24205options. 24206 24207@item #pragma GCC reset_options 24208@cindex pragma GCC reset_options 24209 24210This pragma clears the current @code{#pragma GCC target} and 24211@code{#pragma GCC optimize} to use the default switches as specified 24212on the command line. 24213 24214@end table 24215 24216@node Loop-Specific Pragmas 24217@subsection Loop-Specific Pragmas 24218 24219@table @code 24220@item #pragma GCC ivdep 24221@cindex pragma GCC ivdep 24222 24223With this pragma, the programmer asserts that there are no loop-carried 24224dependencies which would prevent consecutive iterations of 24225the following loop from executing concurrently with SIMD 24226(single instruction multiple data) instructions. 24227 24228For example, the compiler can only unconditionally vectorize the following 24229loop with the pragma: 24230 24231@smallexample 24232void foo (int n, int *a, int *b, int *c) 24233@{ 24234 int i, j; 24235#pragma GCC ivdep 24236 for (i = 0; i < n; ++i) 24237 a[i] = b[i] + c[i]; 24238@} 24239@end smallexample 24240 24241@noindent 24242In this example, using the @code{restrict} qualifier had the same 24243effect. In the following example, that would not be possible. Assume 24244@math{k < -m} or @math{k >= m}. Only with the pragma, the compiler knows 24245that it can unconditionally vectorize the following loop: 24246 24247@smallexample 24248void ignore_vec_dep (int *a, int k, int c, int m) 24249@{ 24250#pragma GCC ivdep 24251 for (int i = 0; i < m; i++) 24252 a[i] = a[i + k] * c; 24253@} 24254@end smallexample 24255 24256@item #pragma GCC unroll @var{n} 24257@cindex pragma GCC unroll @var{n} 24258 24259You can use this pragma to control how many times a loop should be unrolled. 24260It must be placed immediately before a @code{for}, @code{while} or @code{do} 24261loop or a @code{#pragma GCC ivdep}, and applies only to the loop that follows. 24262@var{n} is an integer constant expression specifying the unrolling factor. 24263The values of @math{0} and @math{1} block any unrolling of the loop. 24264 24265@end table 24266 24267@node Unnamed Fields 24268@section Unnamed Structure and Union Fields 24269@cindex @code{struct} 24270@cindex @code{union} 24271 24272As permitted by ISO C11 and for compatibility with other compilers, 24273GCC allows you to define 24274a structure or union that contains, as fields, structures and unions 24275without names. For example: 24276 24277@smallexample 24278struct @{ 24279 int a; 24280 union @{ 24281 int b; 24282 float c; 24283 @}; 24284 int d; 24285@} foo; 24286@end smallexample 24287 24288@noindent 24289In this example, you are able to access members of the unnamed 24290union with code like @samp{foo.b}. Note that only unnamed structs and 24291unions are allowed, you may not have, for example, an unnamed 24292@code{int}. 24293 24294You must never create such structures that cause ambiguous field definitions. 24295For example, in this structure: 24296 24297@smallexample 24298struct @{ 24299 int a; 24300 struct @{ 24301 int a; 24302 @}; 24303@} foo; 24304@end smallexample 24305 24306@noindent 24307it is ambiguous which @code{a} is being referred to with @samp{foo.a}. 24308The compiler gives errors for such constructs. 24309 24310@opindex fms-extensions 24311Unless @option{-fms-extensions} is used, the unnamed field must be a 24312structure or union definition without a tag (for example, @samp{struct 24313@{ int a; @};}). If @option{-fms-extensions} is used, the field may 24314also be a definition with a tag such as @samp{struct foo @{ int a; 24315@};}, a reference to a previously defined structure or union such as 24316@samp{struct foo;}, or a reference to a @code{typedef} name for a 24317previously defined structure or union type. 24318 24319@opindex fplan9-extensions 24320The option @option{-fplan9-extensions} enables 24321@option{-fms-extensions} as well as two other extensions. First, a 24322pointer to a structure is automatically converted to a pointer to an 24323anonymous field for assignments and function calls. For example: 24324 24325@smallexample 24326struct s1 @{ int a; @}; 24327struct s2 @{ struct s1; @}; 24328extern void f1 (struct s1 *); 24329void f2 (struct s2 *p) @{ f1 (p); @} 24330@end smallexample 24331 24332@noindent 24333In the call to @code{f1} inside @code{f2}, the pointer @code{p} is 24334converted into a pointer to the anonymous field. 24335 24336Second, when the type of an anonymous field is a @code{typedef} for a 24337@code{struct} or @code{union}, code may refer to the field using the 24338name of the @code{typedef}. 24339 24340@smallexample 24341typedef struct @{ int a; @} s1; 24342struct s2 @{ s1; @}; 24343s1 f1 (struct s2 *p) @{ return p->s1; @} 24344@end smallexample 24345 24346These usages are only permitted when they are not ambiguous. 24347 24348@node Thread-Local 24349@section Thread-Local Storage 24350@cindex Thread-Local Storage 24351@cindex @acronym{TLS} 24352@cindex @code{__thread} 24353 24354Thread-local storage (@acronym{TLS}) is a mechanism by which variables 24355are allocated such that there is one instance of the variable per extant 24356thread. The runtime model GCC uses to implement this originates 24357in the IA-64 processor-specific ABI, but has since been migrated 24358to other processors as well. It requires significant support from 24359the linker (@command{ld}), dynamic linker (@command{ld.so}), and 24360system libraries (@file{libc.so} and @file{libpthread.so}), so it 24361is not available everywhere. 24362 24363At the user level, the extension is visible with a new storage 24364class keyword: @code{__thread}. For example: 24365 24366@smallexample 24367__thread int i; 24368extern __thread struct state s; 24369static __thread char *p; 24370@end smallexample 24371 24372The @code{__thread} specifier may be used alone, with the @code{extern} 24373or @code{static} specifiers, but with no other storage class specifier. 24374When used with @code{extern} or @code{static}, @code{__thread} must appear 24375immediately after the other storage class specifier. 24376 24377The @code{__thread} specifier may be applied to any global, file-scoped 24378static, function-scoped static, or static data member of a class. It may 24379not be applied to block-scoped automatic or non-static data member. 24380 24381When the address-of operator is applied to a thread-local variable, it is 24382evaluated at run time and returns the address of the current thread's 24383instance of that variable. An address so obtained may be used by any 24384thread. When a thread terminates, any pointers to thread-local variables 24385in that thread become invalid. 24386 24387No static initialization may refer to the address of a thread-local variable. 24388 24389In C++, if an initializer is present for a thread-local variable, it must 24390be a @var{constant-expression}, as defined in 5.19.2 of the ANSI/ISO C++ 24391standard. 24392 24393See @uref{https://www.akkadia.org/drepper/tls.pdf, 24394ELF Handling For Thread-Local Storage} for a detailed explanation of 24395the four thread-local storage addressing models, and how the runtime 24396is expected to function. 24397 24398@menu 24399* C99 Thread-Local Edits:: 24400* C++98 Thread-Local Edits:: 24401@end menu 24402 24403@node C99 Thread-Local Edits 24404@subsection ISO/IEC 9899:1999 Edits for Thread-Local Storage 24405 24406The following are a set of changes to ISO/IEC 9899:1999 (aka C99) 24407that document the exact semantics of the language extension. 24408 24409@itemize @bullet 24410@item 24411@cite{5.1.2 Execution environments} 24412 24413Add new text after paragraph 1 24414 24415@quotation 24416Within either execution environment, a @dfn{thread} is a flow of 24417control within a program. It is implementation defined whether 24418or not there may be more than one thread associated with a program. 24419It is implementation defined how threads beyond the first are 24420created, the name and type of the function called at thread 24421startup, and how threads may be terminated. However, objects 24422with thread storage duration shall be initialized before thread 24423startup. 24424@end quotation 24425 24426@item 24427@cite{6.2.4 Storage durations of objects} 24428 24429Add new text before paragraph 3 24430 24431@quotation 24432An object whose identifier is declared with the storage-class 24433specifier @w{@code{__thread}} has @dfn{thread storage duration}. 24434Its lifetime is the entire execution of the thread, and its 24435stored value is initialized only once, prior to thread startup. 24436@end quotation 24437 24438@item 24439@cite{6.4.1 Keywords} 24440 24441Add @code{__thread}. 24442 24443@item 24444@cite{6.7.1 Storage-class specifiers} 24445 24446Add @code{__thread} to the list of storage class specifiers in 24447paragraph 1. 24448 24449Change paragraph 2 to 24450 24451@quotation 24452With the exception of @code{__thread}, at most one storage-class 24453specifier may be given [@dots{}]. The @code{__thread} specifier may 24454be used alone, or immediately following @code{extern} or 24455@code{static}. 24456@end quotation 24457 24458Add new text after paragraph 6 24459 24460@quotation 24461The declaration of an identifier for a variable that has 24462block scope that specifies @code{__thread} shall also 24463specify either @code{extern} or @code{static}. 24464 24465The @code{__thread} specifier shall be used only with 24466variables. 24467@end quotation 24468@end itemize 24469 24470@node C++98 Thread-Local Edits 24471@subsection ISO/IEC 14882:1998 Edits for Thread-Local Storage 24472 24473The following are a set of changes to ISO/IEC 14882:1998 (aka C++98) 24474that document the exact semantics of the language extension. 24475 24476@itemize @bullet 24477@item 24478@b{[intro.execution]} 24479 24480New text after paragraph 4 24481 24482@quotation 24483A @dfn{thread} is a flow of control within the abstract machine. 24484It is implementation defined whether or not there may be more than 24485one thread. 24486@end quotation 24487 24488New text after paragraph 7 24489 24490@quotation 24491It is unspecified whether additional action must be taken to 24492ensure when and whether side effects are visible to other threads. 24493@end quotation 24494 24495@item 24496@b{[lex.key]} 24497 24498Add @code{__thread}. 24499 24500@item 24501@b{[basic.start.main]} 24502 24503Add after paragraph 5 24504 24505@quotation 24506The thread that begins execution at the @code{main} function is called 24507the @dfn{main thread}. It is implementation defined how functions 24508beginning threads other than the main thread are designated or typed. 24509A function so designated, as well as the @code{main} function, is called 24510a @dfn{thread startup function}. It is implementation defined what 24511happens if a thread startup function returns. It is implementation 24512defined what happens to other threads when any thread calls @code{exit}. 24513@end quotation 24514 24515@item 24516@b{[basic.start.init]} 24517 24518Add after paragraph 4 24519 24520@quotation 24521The storage for an object of thread storage duration shall be 24522statically initialized before the first statement of the thread startup 24523function. An object of thread storage duration shall not require 24524dynamic initialization. 24525@end quotation 24526 24527@item 24528@b{[basic.start.term]} 24529 24530Add after paragraph 3 24531 24532@quotation 24533The type of an object with thread storage duration shall not have a 24534non-trivial destructor, nor shall it be an array type whose elements 24535(directly or indirectly) have non-trivial destructors. 24536@end quotation 24537 24538@item 24539@b{[basic.stc]} 24540 24541Add ``thread storage duration'' to the list in paragraph 1. 24542 24543Change paragraph 2 24544 24545@quotation 24546Thread, static, and automatic storage durations are associated with 24547objects introduced by declarations [@dots{}]. 24548@end quotation 24549 24550Add @code{__thread} to the list of specifiers in paragraph 3. 24551 24552@item 24553@b{[basic.stc.thread]} 24554 24555New section before @b{[basic.stc.static]} 24556 24557@quotation 24558The keyword @code{__thread} applied to a non-local object gives the 24559object thread storage duration. 24560 24561A local variable or class data member declared both @code{static} 24562and @code{__thread} gives the variable or member thread storage 24563duration. 24564@end quotation 24565 24566@item 24567@b{[basic.stc.static]} 24568 24569Change paragraph 1 24570 24571@quotation 24572All objects that have neither thread storage duration, dynamic 24573storage duration nor are local [@dots{}]. 24574@end quotation 24575 24576@item 24577@b{[dcl.stc]} 24578 24579Add @code{__thread} to the list in paragraph 1. 24580 24581Change paragraph 1 24582 24583@quotation 24584With the exception of @code{__thread}, at most one 24585@var{storage-class-specifier} shall appear in a given 24586@var{decl-specifier-seq}. The @code{__thread} specifier may 24587be used alone, or immediately following the @code{extern} or 24588@code{static} specifiers. [@dots{}] 24589@end quotation 24590 24591Add after paragraph 5 24592 24593@quotation 24594The @code{__thread} specifier can be applied only to the names of objects 24595and to anonymous unions. 24596@end quotation 24597 24598@item 24599@b{[class.mem]} 24600 24601Add after paragraph 6 24602 24603@quotation 24604Non-@code{static} members shall not be @code{__thread}. 24605@end quotation 24606@end itemize 24607 24608@node Binary constants 24609@section Binary Constants using the @samp{0b} Prefix 24610@cindex Binary constants using the @samp{0b} prefix 24611 24612Integer constants can be written as binary constants, consisting of a 24613sequence of @samp{0} and @samp{1} digits, prefixed by @samp{0b} or 24614@samp{0B}. This is particularly useful in environments that operate a 24615lot on the bit level (like microcontrollers). 24616 24617The following statements are identical: 24618 24619@smallexample 24620i = 42; 24621i = 0x2a; 24622i = 052; 24623i = 0b101010; 24624@end smallexample 24625 24626The type of these constants follows the same rules as for octal or 24627hexadecimal integer constants, so suffixes like @samp{L} or @samp{UL} 24628can be applied. 24629 24630@node C++ Extensions 24631@chapter Extensions to the C++ Language 24632@cindex extensions, C++ language 24633@cindex C++ language extensions 24634 24635The GNU compiler provides these extensions to the C++ language (and you 24636can also use most of the C language extensions in your C++ programs). If you 24637want to write code that checks whether these features are available, you can 24638test for the GNU compiler the same way as for C programs: check for a 24639predefined macro @code{__GNUC__}. You can also use @code{__GNUG__} to 24640test specifically for GNU C++ (@pxref{Common Predefined Macros,, 24641Predefined Macros,cpp,The GNU C Preprocessor}). 24642 24643@menu 24644* C++ Volatiles:: What constitutes an access to a volatile object. 24645* Restricted Pointers:: C99 restricted pointers and references. 24646* Vague Linkage:: Where G++ puts inlines, vtables and such. 24647* C++ Interface:: You can use a single C++ header file for both 24648 declarations and definitions. 24649* Template Instantiation:: Methods for ensuring that exactly one copy of 24650 each needed template instantiation is emitted. 24651* Bound member functions:: You can extract a function pointer to the 24652 method denoted by a @samp{->*} or @samp{.*} expression. 24653* C++ Attributes:: Variable, function, and type attributes for C++ only. 24654* Function Multiversioning:: Declaring multiple function versions. 24655* Type Traits:: Compiler support for type traits. 24656* C++ Concepts:: Improved support for generic programming. 24657* Deprecated Features:: Things will disappear from G++. 24658* Backwards Compatibility:: Compatibilities with earlier definitions of C++. 24659@end menu 24660 24661@node C++ Volatiles 24662@section When is a Volatile C++ Object Accessed? 24663@cindex accessing volatiles 24664@cindex volatile read 24665@cindex volatile write 24666@cindex volatile access 24667 24668The C++ standard differs from the C standard in its treatment of 24669volatile objects. It fails to specify what constitutes a volatile 24670access, except to say that C++ should behave in a similar manner to C 24671with respect to volatiles, where possible. However, the different 24672lvalueness of expressions between C and C++ complicate the behavior. 24673G++ behaves the same as GCC for volatile access, @xref{C 24674Extensions,,Volatiles}, for a description of GCC's behavior. 24675 24676The C and C++ language specifications differ when an object is 24677accessed in a void context: 24678 24679@smallexample 24680volatile int *src = @var{somevalue}; 24681*src; 24682@end smallexample 24683 24684The C++ standard specifies that such expressions do not undergo lvalue 24685to rvalue conversion, and that the type of the dereferenced object may 24686be incomplete. The C++ standard does not specify explicitly that it 24687is lvalue to rvalue conversion that is responsible for causing an 24688access. There is reason to believe that it is, because otherwise 24689certain simple expressions become undefined. However, because it 24690would surprise most programmers, G++ treats dereferencing a pointer to 24691volatile object of complete type as GCC would do for an equivalent 24692type in C@. When the object has incomplete type, G++ issues a 24693warning; if you wish to force an error, you must force a conversion to 24694rvalue with, for instance, a static cast. 24695 24696When using a reference to volatile, G++ does not treat equivalent 24697expressions as accesses to volatiles, but instead issues a warning that 24698no volatile is accessed. The rationale for this is that otherwise it 24699becomes difficult to determine where volatile access occur, and not 24700possible to ignore the return value from functions returning volatile 24701references. Again, if you wish to force a read, cast the reference to 24702an rvalue. 24703 24704G++ implements the same behavior as GCC does when assigning to a 24705volatile object---there is no reread of the assigned-to object, the 24706assigned rvalue is reused. Note that in C++ assignment expressions 24707are lvalues, and if used as an lvalue, the volatile object is 24708referred to. For instance, @var{vref} refers to @var{vobj}, as 24709expected, in the following example: 24710 24711@smallexample 24712volatile int vobj; 24713volatile int &vref = vobj = @var{something}; 24714@end smallexample 24715 24716@node Restricted Pointers 24717@section Restricting Pointer Aliasing 24718@cindex restricted pointers 24719@cindex restricted references 24720@cindex restricted this pointer 24721 24722As with the C front end, G++ understands the C99 feature of restricted pointers, 24723specified with the @code{__restrict__}, or @code{__restrict} type 24724qualifier. Because you cannot compile C++ by specifying the @option{-std=c99} 24725language flag, @code{restrict} is not a keyword in C++. 24726 24727In addition to allowing restricted pointers, you can specify restricted 24728references, which indicate that the reference is not aliased in the local 24729context. 24730 24731@smallexample 24732void fn (int *__restrict__ rptr, int &__restrict__ rref) 24733@{ 24734 /* @r{@dots{}} */ 24735@} 24736@end smallexample 24737 24738@noindent 24739In the body of @code{fn}, @var{rptr} points to an unaliased integer and 24740@var{rref} refers to a (different) unaliased integer. 24741 24742You may also specify whether a member function's @var{this} pointer is 24743unaliased by using @code{__restrict__} as a member function qualifier. 24744 24745@smallexample 24746void T::fn () __restrict__ 24747@{ 24748 /* @r{@dots{}} */ 24749@} 24750@end smallexample 24751 24752@noindent 24753Within the body of @code{T::fn}, @var{this} has the effective 24754definition @code{T *__restrict__ const this}. Notice that the 24755interpretation of a @code{__restrict__} member function qualifier is 24756different to that of @code{const} or @code{volatile} qualifier, in that it 24757is applied to the pointer rather than the object. This is consistent with 24758other compilers that implement restricted pointers. 24759 24760As with all outermost parameter qualifiers, @code{__restrict__} is 24761ignored in function definition matching. This means you only need to 24762specify @code{__restrict__} in a function definition, rather than 24763in a function prototype as well. 24764 24765@node Vague Linkage 24766@section Vague Linkage 24767@cindex vague linkage 24768 24769There are several constructs in C++ that require space in the object 24770file but are not clearly tied to a single translation unit. We say that 24771these constructs have ``vague linkage''. Typically such constructs are 24772emitted wherever they are needed, though sometimes we can be more 24773clever. 24774 24775@table @asis 24776@item Inline Functions 24777Inline functions are typically defined in a header file which can be 24778included in many different compilations. Hopefully they can usually be 24779inlined, but sometimes an out-of-line copy is necessary, if the address 24780of the function is taken or if inlining fails. In general, we emit an 24781out-of-line copy in all translation units where one is needed. As an 24782exception, we only emit inline virtual functions with the vtable, since 24783it always requires a copy. 24784 24785Local static variables and string constants used in an inline function 24786are also considered to have vague linkage, since they must be shared 24787between all inlined and out-of-line instances of the function. 24788 24789@item VTables 24790@cindex vtable 24791C++ virtual functions are implemented in most compilers using a lookup 24792table, known as a vtable. The vtable contains pointers to the virtual 24793functions provided by a class, and each object of the class contains a 24794pointer to its vtable (or vtables, in some multiple-inheritance 24795situations). If the class declares any non-inline, non-pure virtual 24796functions, the first one is chosen as the ``key method'' for the class, 24797and the vtable is only emitted in the translation unit where the key 24798method is defined. 24799 24800@emph{Note:} If the chosen key method is later defined as inline, the 24801vtable is still emitted in every translation unit that defines it. 24802Make sure that any inline virtuals are declared inline in the class 24803body, even if they are not defined there. 24804 24805@item @code{type_info} objects 24806@cindex @code{type_info} 24807@cindex RTTI 24808C++ requires information about types to be written out in order to 24809implement @samp{dynamic_cast}, @samp{typeid} and exception handling. 24810For polymorphic classes (classes with virtual functions), the @samp{type_info} 24811object is written out along with the vtable so that @samp{dynamic_cast} 24812can determine the dynamic type of a class object at run time. For all 24813other types, we write out the @samp{type_info} object when it is used: when 24814applying @samp{typeid} to an expression, throwing an object, or 24815referring to a type in a catch clause or exception specification. 24816 24817@item Template Instantiations 24818Most everything in this section also applies to template instantiations, 24819but there are other options as well. 24820@xref{Template Instantiation,,Where's the Template?}. 24821 24822@end table 24823 24824When used with GNU ld version 2.8 or later on an ELF system such as 24825GNU/Linux or Solaris 2, or on Microsoft Windows, duplicate copies of 24826these constructs will be discarded at link time. This is known as 24827COMDAT support. 24828 24829On targets that don't support COMDAT, but do support weak symbols, GCC 24830uses them. This way one copy overrides all the others, but 24831the unused copies still take up space in the executable. 24832 24833For targets that do not support either COMDAT or weak symbols, 24834most entities with vague linkage are emitted as local symbols to 24835avoid duplicate definition errors from the linker. This does not happen 24836for local statics in inlines, however, as having multiple copies 24837almost certainly breaks things. 24838 24839@xref{C++ Interface,,Declarations and Definitions in One Header}, for 24840another way to control placement of these constructs. 24841 24842@node C++ Interface 24843@section C++ Interface and Implementation Pragmas 24844 24845@cindex interface and implementation headers, C++ 24846@cindex C++ interface and implementation headers 24847@cindex pragmas, interface and implementation 24848 24849@code{#pragma interface} and @code{#pragma implementation} provide the 24850user with a way of explicitly directing the compiler to emit entities 24851with vague linkage (and debugging information) in a particular 24852translation unit. 24853 24854@emph{Note:} These @code{#pragma}s have been superceded as of GCC 2.7.2 24855by COMDAT support and the ``key method'' heuristic 24856mentioned in @ref{Vague Linkage}. Using them can actually cause your 24857program to grow due to unnecessary out-of-line copies of inline 24858functions. 24859 24860@table @code 24861@item #pragma interface 24862@itemx #pragma interface "@var{subdir}/@var{objects}.h" 24863@kindex #pragma interface 24864Use this directive in @emph{header files} that define object classes, to save 24865space in most of the object files that use those classes. Normally, 24866local copies of certain information (backup copies of inline member 24867functions, debugging information, and the internal tables that implement 24868virtual functions) must be kept in each object file that includes class 24869definitions. You can use this pragma to avoid such duplication. When a 24870header file containing @samp{#pragma interface} is included in a 24871compilation, this auxiliary information is not generated (unless 24872the main input source file itself uses @samp{#pragma implementation}). 24873Instead, the object files contain references to be resolved at link 24874time. 24875 24876The second form of this directive is useful for the case where you have 24877multiple headers with the same name in different directories. If you 24878use this form, you must specify the same string to @samp{#pragma 24879implementation}. 24880 24881@item #pragma implementation 24882@itemx #pragma implementation "@var{objects}.h" 24883@kindex #pragma implementation 24884Use this pragma in a @emph{main input file}, when you want full output from 24885included header files to be generated (and made globally visible). The 24886included header file, in turn, should use @samp{#pragma interface}. 24887Backup copies of inline member functions, debugging information, and the 24888internal tables used to implement virtual functions are all generated in 24889implementation files. 24890 24891@cindex implied @code{#pragma implementation} 24892@cindex @code{#pragma implementation}, implied 24893@cindex naming convention, implementation headers 24894If you use @samp{#pragma implementation} with no argument, it applies to 24895an include file with the same basename@footnote{A file's @dfn{basename} 24896is the name stripped of all leading path information and of trailing 24897suffixes, such as @samp{.h} or @samp{.C} or @samp{.cc}.} as your source 24898file. For example, in @file{allclass.cc}, giving just 24899@samp{#pragma implementation} 24900by itself is equivalent to @samp{#pragma implementation "allclass.h"}. 24901 24902Use the string argument if you want a single implementation file to 24903include code from multiple header files. (You must also use 24904@samp{#include} to include the header file; @samp{#pragma 24905implementation} only specifies how to use the file---it doesn't actually 24906include it.) 24907 24908There is no way to split up the contents of a single header file into 24909multiple implementation files. 24910@end table 24911 24912@cindex inlining and C++ pragmas 24913@cindex C++ pragmas, effect on inlining 24914@cindex pragmas in C++, effect on inlining 24915@samp{#pragma implementation} and @samp{#pragma interface} also have an 24916effect on function inlining. 24917 24918If you define a class in a header file marked with @samp{#pragma 24919interface}, the effect on an inline function defined in that class is 24920similar to an explicit @code{extern} declaration---the compiler emits 24921no code at all to define an independent version of the function. Its 24922definition is used only for inlining with its callers. 24923 24924@opindex fno-implement-inlines 24925Conversely, when you include the same header file in a main source file 24926that declares it as @samp{#pragma implementation}, the compiler emits 24927code for the function itself; this defines a version of the function 24928that can be found via pointers (or by callers compiled without 24929inlining). If all calls to the function can be inlined, you can avoid 24930emitting the function by compiling with @option{-fno-implement-inlines}. 24931If any calls are not inlined, you will get linker errors. 24932 24933@node Template Instantiation 24934@section Where's the Template? 24935@cindex template instantiation 24936 24937C++ templates were the first language feature to require more 24938intelligence from the environment than was traditionally found on a UNIX 24939system. Somehow the compiler and linker have to make sure that each 24940template instance occurs exactly once in the executable if it is needed, 24941and not at all otherwise. There are two basic approaches to this 24942problem, which are referred to as the Borland model and the Cfront model. 24943 24944@table @asis 24945@item Borland model 24946Borland C++ solved the template instantiation problem by adding the code 24947equivalent of common blocks to their linker; the compiler emits template 24948instances in each translation unit that uses them, and the linker 24949collapses them together. The advantage of this model is that the linker 24950only has to consider the object files themselves; there is no external 24951complexity to worry about. The disadvantage is that compilation time 24952is increased because the template code is being compiled repeatedly. 24953Code written for this model tends to include definitions of all 24954templates in the header file, since they must be seen to be 24955instantiated. 24956 24957@item Cfront model 24958The AT&T C++ translator, Cfront, solved the template instantiation 24959problem by creating the notion of a template repository, an 24960automatically maintained place where template instances are stored. A 24961more modern version of the repository works as follows: As individual 24962object files are built, the compiler places any template definitions and 24963instantiations encountered in the repository. At link time, the link 24964wrapper adds in the objects in the repository and compiles any needed 24965instances that were not previously emitted. The advantages of this 24966model are more optimal compilation speed and the ability to use the 24967system linker; to implement the Borland model a compiler vendor also 24968needs to replace the linker. The disadvantages are vastly increased 24969complexity, and thus potential for error; for some code this can be 24970just as transparent, but in practice it can been very difficult to build 24971multiple programs in one directory and one program in multiple 24972directories. Code written for this model tends to separate definitions 24973of non-inline member templates into a separate file, which should be 24974compiled separately. 24975@end table 24976 24977G++ implements the Borland model on targets where the linker supports it, 24978including ELF targets (such as GNU/Linux), Mac OS X and Microsoft Windows. 24979Otherwise G++ implements neither automatic model. 24980 24981You have the following options for dealing with template instantiations: 24982 24983@enumerate 24984@item 24985Do nothing. Code written for the Borland model works fine, but 24986each translation unit contains instances of each of the templates it 24987uses. The duplicate instances will be discarded by the linker, but in 24988a large program, this can lead to an unacceptable amount of code 24989duplication in object files or shared libraries. 24990 24991Duplicate instances of a template can be avoided by defining an explicit 24992instantiation in one object file, and preventing the compiler from doing 24993implicit instantiations in any other object files by using an explicit 24994instantiation declaration, using the @code{extern template} syntax: 24995 24996@smallexample 24997extern template int max (int, int); 24998@end smallexample 24999 25000This syntax is defined in the C++ 2011 standard, but has been supported by 25001G++ and other compilers since well before 2011. 25002 25003Explicit instantiations can be used for the largest or most frequently 25004duplicated instances, without having to know exactly which other instances 25005are used in the rest of the program. You can scatter the explicit 25006instantiations throughout your program, perhaps putting them in the 25007translation units where the instances are used or the translation units 25008that define the templates themselves; you can put all of the explicit 25009instantiations you need into one big file; or you can create small files 25010like 25011 25012@smallexample 25013#include "Foo.h" 25014#include "Foo.cc" 25015 25016template class Foo<int>; 25017template ostream& operator << 25018 (ostream&, const Foo<int>&); 25019@end smallexample 25020 25021@noindent 25022for each of the instances you need, and create a template instantiation 25023library from those. 25024 25025This is the simplest option, but also offers flexibility and 25026fine-grained control when necessary. It is also the most portable 25027alternative and programs using this approach will work with most modern 25028compilers. 25029 25030@item 25031@opindex fno-implicit-templates 25032Compile your code with @option{-fno-implicit-templates} to disable the 25033implicit generation of template instances, and explicitly instantiate 25034all the ones you use. This approach requires more knowledge of exactly 25035which instances you need than do the others, but it's less 25036mysterious and allows greater control if you want to ensure that only 25037the intended instances are used. 25038 25039If you are using Cfront-model code, you can probably get away with not 25040using @option{-fno-implicit-templates} when compiling files that don't 25041@samp{#include} the member template definitions. 25042 25043If you use one big file to do the instantiations, you may want to 25044compile it without @option{-fno-implicit-templates} so you get all of the 25045instances required by your explicit instantiations (but not by any 25046other files) without having to specify them as well. 25047 25048In addition to forward declaration of explicit instantiations 25049(with @code{extern}), G++ has extended the template instantiation 25050syntax to support instantiation of the compiler support data for a 25051template class (i.e.@: the vtable) without instantiating any of its 25052members (with @code{inline}), and instantiation of only the static data 25053members of a template class, without the support data or member 25054functions (with @code{static}): 25055 25056@smallexample 25057inline template class Foo<int>; 25058static template class Foo<int>; 25059@end smallexample 25060@end enumerate 25061 25062@node Bound member functions 25063@section Extracting the Function Pointer from a Bound Pointer to Member Function 25064@cindex pmf 25065@cindex pointer to member function 25066@cindex bound pointer to member function 25067 25068In C++, pointer to member functions (PMFs) are implemented using a wide 25069pointer of sorts to handle all the possible call mechanisms; the PMF 25070needs to store information about how to adjust the @samp{this} pointer, 25071and if the function pointed to is virtual, where to find the vtable, and 25072where in the vtable to look for the member function. If you are using 25073PMFs in an inner loop, you should really reconsider that decision. If 25074that is not an option, you can extract the pointer to the function that 25075would be called for a given object/PMF pair and call it directly inside 25076the inner loop, to save a bit of time. 25077 25078Note that you still pay the penalty for the call through a 25079function pointer; on most modern architectures, such a call defeats the 25080branch prediction features of the CPU@. This is also true of normal 25081virtual function calls. 25082 25083The syntax for this extension is 25084 25085@smallexample 25086extern A a; 25087extern int (A::*fp)(); 25088typedef int (*fptr)(A *); 25089 25090fptr p = (fptr)(a.*fp); 25091@end smallexample 25092 25093For PMF constants (i.e.@: expressions of the form @samp{&Klasse::Member}), 25094no object is needed to obtain the address of the function. They can be 25095converted to function pointers directly: 25096 25097@smallexample 25098fptr p1 = (fptr)(&A::foo); 25099@end smallexample 25100 25101@opindex Wno-pmf-conversions 25102You must specify @option{-Wno-pmf-conversions} to use this extension. 25103 25104@node C++ Attributes 25105@section C++-Specific Variable, Function, and Type Attributes 25106 25107Some attributes only make sense for C++ programs. 25108 25109@table @code 25110@item abi_tag ("@var{tag}", ...) 25111@cindex @code{abi_tag} function attribute 25112@cindex @code{abi_tag} variable attribute 25113@cindex @code{abi_tag} type attribute 25114The @code{abi_tag} attribute can be applied to a function, variable, or class 25115declaration. It modifies the mangled name of the entity to 25116incorporate the tag name, in order to distinguish the function or 25117class from an earlier version with a different ABI; perhaps the class 25118has changed size, or the function has a different return type that is 25119not encoded in the mangled name. 25120 25121The attribute can also be applied to an inline namespace, but does not 25122affect the mangled name of the namespace; in this case it is only used 25123for @option{-Wabi-tag} warnings and automatic tagging of functions and 25124variables. Tagging inline namespaces is generally preferable to 25125tagging individual declarations, but the latter is sometimes 25126necessary, such as when only certain members of a class need to be 25127tagged. 25128 25129The argument can be a list of strings of arbitrary length. The 25130strings are sorted on output, so the order of the list is 25131unimportant. 25132 25133A redeclaration of an entity must not add new ABI tags, 25134since doing so would change the mangled name. 25135 25136The ABI tags apply to a name, so all instantiations and 25137specializations of a template have the same tags. The attribute will 25138be ignored if applied to an explicit specialization or instantiation. 25139 25140The @option{-Wabi-tag} flag enables a warning about a class which does 25141not have all the ABI tags used by its subobjects and virtual functions; for users with code 25142that needs to coexist with an earlier ABI, using this option can help 25143to find all affected types that need to be tagged. 25144 25145When a type involving an ABI tag is used as the type of a variable or 25146return type of a function where that tag is not already present in the 25147signature of the function, the tag is automatically applied to the 25148variable or function. @option{-Wabi-tag} also warns about this 25149situation; this warning can be avoided by explicitly tagging the 25150variable or function or moving it into a tagged inline namespace. 25151 25152@item init_priority (@var{priority}) 25153@cindex @code{init_priority} variable attribute 25154 25155In Standard C++, objects defined at namespace scope are guaranteed to be 25156initialized in an order in strict accordance with that of their definitions 25157@emph{in a given translation unit}. No guarantee is made for initializations 25158across translation units. However, GNU C++ allows users to control the 25159order of initialization of objects defined at namespace scope with the 25160@code{init_priority} attribute by specifying a relative @var{priority}, 25161a constant integral expression currently bounded between 101 and 65535 25162inclusive. Lower numbers indicate a higher priority. 25163 25164In the following example, @code{A} would normally be created before 25165@code{B}, but the @code{init_priority} attribute reverses that order: 25166 25167@smallexample 25168Some_Class A __attribute__ ((init_priority (2000))); 25169Some_Class B __attribute__ ((init_priority (543))); 25170@end smallexample 25171 25172@noindent 25173Note that the particular values of @var{priority} do not matter; only their 25174relative ordering. 25175 25176@item warn_unused 25177@cindex @code{warn_unused} type attribute 25178 25179For C++ types with non-trivial constructors and/or destructors it is 25180impossible for the compiler to determine whether a variable of this 25181type is truly unused if it is not referenced. This type attribute 25182informs the compiler that variables of this type should be warned 25183about if they appear to be unused, just like variables of fundamental 25184types. 25185 25186This attribute is appropriate for types which just represent a value, 25187such as @code{std::string}; it is not appropriate for types which 25188control a resource, such as @code{std::lock_guard}. 25189 25190This attribute is also accepted in C, but it is unnecessary because C 25191does not have constructors or destructors. 25192 25193@end table 25194 25195@node Function Multiversioning 25196@section Function Multiversioning 25197@cindex function versions 25198 25199With the GNU C++ front end, for x86 targets, you may specify multiple 25200versions of a function, where each function is specialized for a 25201specific target feature. At runtime, the appropriate version of the 25202function is automatically executed depending on the characteristics of 25203the execution platform. Here is an example. 25204 25205@smallexample 25206__attribute__ ((target ("default"))) 25207int foo () 25208@{ 25209 // The default version of foo. 25210 return 0; 25211@} 25212 25213__attribute__ ((target ("sse4.2"))) 25214int foo () 25215@{ 25216 // foo version for SSE4.2 25217 return 1; 25218@} 25219 25220__attribute__ ((target ("arch=atom"))) 25221int foo () 25222@{ 25223 // foo version for the Intel ATOM processor 25224 return 2; 25225@} 25226 25227__attribute__ ((target ("arch=amdfam10"))) 25228int foo () 25229@{ 25230 // foo version for the AMD Family 0x10 processors. 25231 return 3; 25232@} 25233 25234int main () 25235@{ 25236 int (*p)() = &foo; 25237 assert ((*p) () == foo ()); 25238 return 0; 25239@} 25240@end smallexample 25241 25242In the above example, four versions of function foo are created. The 25243first version of foo with the target attribute "default" is the default 25244version. This version gets executed when no other target specific 25245version qualifies for execution on a particular platform. A new version 25246of foo is created by using the same function signature but with a 25247different target string. Function foo is called or a pointer to it is 25248taken just like a regular function. GCC takes care of doing the 25249dispatching to call the right version at runtime. Refer to the 25250@uref{https://gcc.gnu.org/wiki/FunctionMultiVersioning, GCC wiki on 25251Function Multiversioning} for more details. 25252 25253@node Type Traits 25254@section Type Traits 25255 25256The C++ front end implements syntactic extensions that allow 25257compile-time determination of 25258various characteristics of a type (or of a 25259pair of types). 25260 25261@table @code 25262@item __has_nothrow_assign (type) 25263If @code{type} is @code{const}-qualified or is a reference type then 25264the trait is @code{false}. Otherwise if @code{__has_trivial_assign (type)} 25265is @code{true} then the trait is @code{true}, else if @code{type} is 25266a cv-qualified class or union type with copy assignment operators that are 25267known not to throw an exception then the trait is @code{true}, else it is 25268@code{false}. 25269Requires: @code{type} shall be a complete type, (possibly cv-qualified) 25270@code{void}, or an array of unknown bound. 25271 25272@item __has_nothrow_copy (type) 25273If @code{__has_trivial_copy (type)} is @code{true} then the trait is 25274@code{true}, else if @code{type} is a cv-qualified class or union type 25275with copy constructors that are known not to throw an exception then 25276the trait is @code{true}, else it is @code{false}. 25277Requires: @code{type} shall be a complete type, (possibly cv-qualified) 25278@code{void}, or an array of unknown bound. 25279 25280@item __has_nothrow_constructor (type) 25281If @code{__has_trivial_constructor (type)} is @code{true} then the trait 25282is @code{true}, else if @code{type} is a cv class or union type (or array 25283thereof) with a default constructor that is known not to throw an 25284exception then the trait is @code{true}, else it is @code{false}. 25285Requires: @code{type} shall be a complete type, (possibly cv-qualified) 25286@code{void}, or an array of unknown bound. 25287 25288@item __has_trivial_assign (type) 25289If @code{type} is @code{const}- qualified or is a reference type then 25290the trait is @code{false}. Otherwise if @code{__is_trivial (type)} is 25291@code{true} then the trait is @code{true}, else if @code{type} is 25292a cv-qualified class or union type with a trivial copy assignment 25293([class.copy]) then the trait is @code{true}, else it is @code{false}. 25294Requires: @code{type} shall be a complete type, (possibly cv-qualified) 25295@code{void}, or an array of unknown bound. 25296 25297@item __has_trivial_copy (type) 25298If @code{__is_trivial (type)} is @code{true} or @code{type} is a reference 25299type then the trait is @code{true}, else if @code{type} is a cv class 25300or union type with a trivial copy constructor ([class.copy]) then the trait 25301is @code{true}, else it is @code{false}. Requires: @code{type} shall be 25302a complete type, (possibly cv-qualified) @code{void}, or an array of unknown 25303bound. 25304 25305@item __has_trivial_constructor (type) 25306If @code{__is_trivial (type)} is @code{true} then the trait is @code{true}, 25307else if @code{type} is a cv-qualified class or union type (or array thereof) 25308with a trivial default constructor ([class.ctor]) then the trait is @code{true}, 25309else it is @code{false}. 25310Requires: @code{type} shall be a complete type, (possibly cv-qualified) 25311@code{void}, or an array of unknown bound. 25312 25313@item __has_trivial_destructor (type) 25314If @code{__is_trivial (type)} is @code{true} or @code{type} is a reference type 25315then the trait is @code{true}, else if @code{type} is a cv class or union 25316type (or array thereof) with a trivial destructor ([class.dtor]) then 25317the trait is @code{true}, else it is @code{false}. 25318Requires: @code{type} shall be a complete type, (possibly cv-qualified) 25319@code{void}, or an array of unknown bound. 25320 25321@item __has_virtual_destructor (type) 25322If @code{type} is a class type with a virtual destructor 25323([class.dtor]) then the trait is @code{true}, else it is @code{false}. 25324Requires: @code{type} shall be a complete type, (possibly cv-qualified) 25325@code{void}, or an array of unknown bound. 25326 25327@item __is_abstract (type) 25328If @code{type} is an abstract class ([class.abstract]) then the trait 25329is @code{true}, else it is @code{false}. 25330Requires: @code{type} shall be a complete type, (possibly cv-qualified) 25331@code{void}, or an array of unknown bound. 25332 25333@item __is_base_of (base_type, derived_type) 25334If @code{base_type} is a base class of @code{derived_type} 25335([class.derived]) then the trait is @code{true}, otherwise it is @code{false}. 25336Top-level cv-qualifications of @code{base_type} and 25337@code{derived_type} are ignored. For the purposes of this trait, a 25338class type is considered is own base. 25339Requires: if @code{__is_class (base_type)} and @code{__is_class (derived_type)} 25340are @code{true} and @code{base_type} and @code{derived_type} are not the same 25341type (disregarding cv-qualifiers), @code{derived_type} shall be a complete 25342type. A diagnostic is produced if this requirement is not met. 25343 25344@item __is_class (type) 25345If @code{type} is a cv-qualified class type, and not a union type 25346([basic.compound]) the trait is @code{true}, else it is @code{false}. 25347 25348@item __is_empty (type) 25349If @code{__is_class (type)} is @code{false} then the trait is @code{false}. 25350Otherwise @code{type} is considered empty if and only if: @code{type} 25351has no non-static data members, or all non-static data members, if 25352any, are bit-fields of length 0, and @code{type} has no virtual 25353members, and @code{type} has no virtual base classes, and @code{type} 25354has no base classes @code{base_type} for which 25355@code{__is_empty (base_type)} is @code{false}. 25356Requires: @code{type} shall be a complete type, (possibly cv-qualified) 25357@code{void}, or an array of unknown bound. 25358 25359@item __is_enum (type) 25360If @code{type} is a cv enumeration type ([basic.compound]) the trait is 25361@code{true}, else it is @code{false}. 25362 25363@item __is_literal_type (type) 25364If @code{type} is a literal type ([basic.types]) the trait is 25365@code{true}, else it is @code{false}. 25366Requires: @code{type} shall be a complete type, (possibly cv-qualified) 25367@code{void}, or an array of unknown bound. 25368 25369@item __is_pod (type) 25370If @code{type} is a cv POD type ([basic.types]) then the trait is @code{true}, 25371else it is @code{false}. 25372Requires: @code{type} shall be a complete type, (possibly cv-qualified) 25373@code{void}, or an array of unknown bound. 25374 25375@item __is_polymorphic (type) 25376If @code{type} is a polymorphic class ([class.virtual]) then the trait 25377is @code{true}, else it is @code{false}. 25378Requires: @code{type} shall be a complete type, (possibly cv-qualified) 25379@code{void}, or an array of unknown bound. 25380 25381@item __is_standard_layout (type) 25382If @code{type} is a standard-layout type ([basic.types]) the trait is 25383@code{true}, else it is @code{false}. 25384Requires: @code{type} shall be a complete type, (possibly cv-qualified) 25385@code{void}, or an array of unknown bound. 25386 25387@item __is_trivial (type) 25388If @code{type} is a trivial type ([basic.types]) the trait is 25389@code{true}, else it is @code{false}. 25390Requires: @code{type} shall be a complete type, (possibly cv-qualified) 25391@code{void}, or an array of unknown bound. 25392 25393@item __is_union (type) 25394If @code{type} is a cv union type ([basic.compound]) the trait is 25395@code{true}, else it is @code{false}. 25396 25397@item __underlying_type (type) 25398The underlying type of @code{type}. 25399Requires: @code{type} shall be an enumeration type ([dcl.enum]). 25400 25401@item __integer_pack (length) 25402When used as the pattern of a pack expansion within a template 25403definition, expands to a template argument pack containing integers 25404from @code{0} to @code{length-1}. This is provided for efficient 25405implementation of @code{std::make_integer_sequence}. 25406 25407@end table 25408 25409 25410@node C++ Concepts 25411@section C++ Concepts 25412 25413C++ concepts provide much-improved support for generic programming. In 25414particular, they allow the specification of constraints on template arguments. 25415The constraints are used to extend the usual overloading and partial 25416specialization capabilities of the language, allowing generic data structures 25417and algorithms to be ``refined'' based on their properties rather than their 25418type names. 25419 25420The following keywords are reserved for concepts. 25421 25422@table @code 25423@item assumes 25424States an expression as an assumption, and if possible, verifies that the 25425assumption is valid. For example, @code{assume(n > 0)}. 25426 25427@item axiom 25428Introduces an axiom definition. Axioms introduce requirements on values. 25429 25430@item forall 25431Introduces a universally quantified object in an axiom. For example, 25432@code{forall (int n) n + 0 == n}). 25433 25434@item concept 25435Introduces a concept definition. Concepts are sets of syntactic and semantic 25436requirements on types and their values. 25437 25438@item requires 25439Introduces constraints on template arguments or requirements for a member 25440function of a class template. 25441 25442@end table 25443 25444The front end also exposes a number of internal mechanism that can be used 25445to simplify the writing of type traits. Note that some of these traits are 25446likely to be removed in the future. 25447 25448@table @code 25449@item __is_same (type1, type2) 25450A binary type trait: @code{true} whenever the type arguments are the same. 25451 25452@end table 25453 25454 25455@node Deprecated Features 25456@section Deprecated Features 25457 25458In the past, the GNU C++ compiler was extended to experiment with new 25459features, at a time when the C++ language was still evolving. Now that 25460the C++ standard is complete, some of those features are superseded by 25461superior alternatives. Using the old features might cause a warning in 25462some cases that the feature will be dropped in the future. In other 25463cases, the feature might be gone already. 25464 25465G++ allows a virtual function returning @samp{void *} to be overridden 25466by one returning a different pointer type. This extension to the 25467covariant return type rules is now deprecated and will be removed from a 25468future version. 25469 25470The use of default arguments in function pointers, function typedefs 25471and other places where they are not permitted by the standard is 25472deprecated and will be removed from a future version of G++. 25473 25474G++ allows floating-point literals to appear in integral constant expressions, 25475e.g.@: @samp{ enum E @{ e = int(2.2 * 3.7) @} } 25476This extension is deprecated and will be removed from a future version. 25477 25478G++ allows static data members of const floating-point type to be declared 25479with an initializer in a class definition. The standard only allows 25480initializers for static members of const integral types and const 25481enumeration types so this extension has been deprecated and will be removed 25482from a future version. 25483 25484G++ allows attributes to follow a parenthesized direct initializer, 25485e.g.@: @samp{ int f (0) __attribute__ ((something)); } This extension 25486has been ignored since G++ 3.3 and is deprecated. 25487 25488G++ allows anonymous structs and unions to have members that are not 25489public non-static data members (i.e.@: fields). These extensions are 25490deprecated. 25491 25492@node Backwards Compatibility 25493@section Backwards Compatibility 25494@cindex Backwards Compatibility 25495@cindex ARM [Annotated C++ Reference Manual] 25496 25497Now that there is a definitive ISO standard C++, G++ has a specification 25498to adhere to. The C++ language evolved over time, and features that 25499used to be acceptable in previous drafts of the standard, such as the ARM 25500[Annotated C++ Reference Manual], are no longer accepted. In order to allow 25501compilation of C++ written to such drafts, G++ contains some backwards 25502compatibilities. @emph{All such backwards compatibility features are 25503liable to disappear in future versions of G++.} They should be considered 25504deprecated. @xref{Deprecated Features}. 25505 25506@table @code 25507 25508@item Implicit C language 25509Old C system header files did not contain an @code{extern "C" @{@dots{}@}} 25510scope to set the language. On such systems, all system header files are 25511implicitly scoped inside a C language scope. Such headers must 25512correctly prototype function argument types, there is no leeway for 25513@code{()} to indicate an unspecified set of arguments. 25514 25515@end table 25516 25517@c LocalWords: emph deftypefn builtin ARCv2EM SIMD builtins msimd 25518@c LocalWords: typedef v4si v8hi DMA dma vdiwr vdowr 25519