1c Copyright (C) 1988-2021 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} {size_t} __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
989@cindex @code{__real__} keyword
990@cindex @code{__imag__} keyword
991To extract the real part of a complex-valued expression @var{exp}, write
992@code{__real__ @var{exp}}.  Likewise, use @code{__imag__} to
993extract the imaginary part.  This is a GNU extension; for values of
994floating type, you should use the ISO C99 functions @code{crealf},
995@code{creal}, @code{creall}, @code{cimagf}, @code{cimag} and
996@code{cimagl}, declared in @code{<complex.h>} and also provided as
997built-in functions by GCC@.
998
999@cindex complex conjugation
1000The operator @samp{~} performs complex conjugation when used on a value
1001with a complex type.  This is a GNU extension; for values of
1002floating type, you should use the ISO C99 functions @code{conjf},
1003@code{conj} and @code{conjl}, declared in @code{<complex.h>} and also
1004provided as built-in functions by GCC@.
1005
1006GCC can allocate complex automatic variables in a noncontiguous
1007fashion; it's even possible for the real part to be in a register while
1008the imaginary part is on the stack (or vice versa).  Only the DWARF
1009debug info format can represent this, so use of DWARF is recommended.
1010If you are using the stabs debug info format, GCC describes a noncontiguous
1011complex variable as if it were two separate variables of noncomplex type.
1012If the variable's actual name is @code{foo}, the two fictitious
1013variables are named @code{foo$real} and @code{foo$imag}.  You can
1014examine and set these two fictitious variables with your debugger.
1015
1016@node Floating Types
1017@section Additional Floating Types
1018@cindex additional floating types
1019@cindex @code{_Float@var{n}} data types
1020@cindex @code{_Float@var{n}x} data types
1021@cindex @code{__float80} data type
1022@cindex @code{__float128} data type
1023@cindex @code{__ibm128} data type
1024@cindex @code{w} floating point suffix
1025@cindex @code{q} floating point suffix
1026@cindex @code{W} floating point suffix
1027@cindex @code{Q} floating point suffix
1028
1029ISO/IEC TS 18661-3:2015 defines C support for additional floating
1030types @code{_Float@var{n}} and @code{_Float@var{n}x}, and GCC supports
1031these type names; the set of types supported depends on the target
1032architecture.  These types are not supported when compiling C++.
1033Constants with these types use suffixes @code{f@var{n}} or
1034@code{F@var{n}} and @code{f@var{n}x} or @code{F@var{n}x}.  These type
1035names can be used together with @code{_Complex} to declare complex
1036types.
1037
1038As an extension, GNU C and GNU C++ support additional floating
1039types, which are not supported by all targets.
1040@itemize @bullet
1041@item @code{__float128} is available on i386, x86_64, IA-64, and
1042hppa HP-UX, as well as on PowerPC GNU/Linux targets that enable
1043the vector scalar (VSX) instruction set.  @code{__float128} supports
1044the 128-bit floating type.  On i386, x86_64, PowerPC, and IA-64
1045other than HP-UX, @code{__float128} is an alias for @code{_Float128}.
1046On hppa and IA-64 HP-UX, @code{__float128} is an alias for @code{long
1047double}.
1048
1049@item @code{__float80} is available on the i386, x86_64, and IA-64
1050targets, and supports the 80-bit (@code{XFmode}) floating type.  It is
1051an alias for the type name @code{_Float64x} on these targets.
1052
1053@item @code{__ibm128} is available on PowerPC targets, and provides
1054access to the IBM extended double format which is the current format
1055used for @code{long double}.  When @code{long double} transitions to
1056@code{__float128} on PowerPC in the future, @code{__ibm128} will remain
1057for use in conversions between the two types.
1058@end itemize
1059
1060Support for these additional types includes the arithmetic operators:
1061add, subtract, multiply, divide; unary arithmetic operators;
1062relational operators; equality operators; and conversions to and from
1063integer and other floating types.  Use a suffix @samp{w} or @samp{W}
1064in a literal constant of type @code{__float80} or type
1065@code{__ibm128}.  Use a suffix @samp{q} or @samp{Q} for @code{_float128}.
1066
1067In order to use @code{_Float128}, @code{__float128}, and @code{__ibm128}
1068on PowerPC Linux systems, you must use the @option{-mfloat128} option. It is
1069expected in future versions of GCC that @code{_Float128} and @code{__float128}
1070will be enabled automatically.
1071
1072The @code{_Float128} type is supported on all systems where
1073@code{__float128} is supported or where @code{long double} has the
1074IEEE binary128 format.  The @code{_Float64x} type is supported on all
1075systems where @code{__float128} is supported.  The @code{_Float32}
1076type is supported on all systems supporting IEEE binary32; the
1077@code{_Float64} and @code{_Float32x} types are supported on all systems
1078supporting IEEE binary64.  The @code{_Float16} type is supported on AArch64
1079systems by default, and on ARM systems when the IEEE format for 16-bit
1080floating-point types is selected with @option{-mfp16-format=ieee}.
1081GCC does not currently support @code{_Float128x} on any systems.
1082
1083On the i386, x86_64, IA-64, and HP-UX targets, you can declare complex
1084types using the corresponding internal complex type, @code{XCmode} for
1085@code{__float80} type and @code{TCmode} for @code{__float128} type:
1086
1087@smallexample
1088typedef _Complex float __attribute__((mode(TC))) _Complex128;
1089typedef _Complex float __attribute__((mode(XC))) _Complex80;
1090@end smallexample
1091
1092On the PowerPC Linux VSX targets, you can declare complex types using
1093the corresponding internal complex type, @code{KCmode} for
1094@code{__float128} type and @code{ICmode} for @code{__ibm128} type:
1095
1096@smallexample
1097typedef _Complex float __attribute__((mode(KC))) _Complex_float128;
1098typedef _Complex float __attribute__((mode(IC))) _Complex_ibm128;
1099@end smallexample
1100
1101@node Half-Precision
1102@section Half-Precision Floating Point
1103@cindex half-precision floating point
1104@cindex @code{__fp16} data type
1105
1106On ARM and AArch64 targets, GCC supports half-precision (16-bit) floating
1107point via the @code{__fp16} type defined in the ARM C Language Extensions.
1108On ARM systems, you must enable this type explicitly with the
1109@option{-mfp16-format} command-line option in order to use it.
1110
1111ARM targets support two incompatible representations for half-precision
1112floating-point values.  You must choose one of the representations and
1113use it consistently in your program.
1114
1115Specifying @option{-mfp16-format=ieee} selects the IEEE 754-2008 format.
1116This format can represent normalized values in the range of @math{2^{-14}} to 65504.
1117There are 11 bits of significand precision, approximately 3
1118decimal digits.
1119
1120Specifying @option{-mfp16-format=alternative} selects the ARM
1121alternative format.  This representation is similar to the IEEE
1122format, but does not support infinities or NaNs.  Instead, the range
1123of exponents is extended, so that this format can represent normalized
1124values in the range of @math{2^{-14}} to 131008.
1125
1126The GCC port for AArch64 only supports the IEEE 754-2008 format, and does
1127not require use of the @option{-mfp16-format} command-line option.
1128
1129The @code{__fp16} type may only be used as an argument to intrinsics defined
1130in @code{<arm_fp16.h>}, or as a storage format.  For purposes of
1131arithmetic and other operations, @code{__fp16} values in C or C++
1132expressions are automatically promoted to @code{float}.
1133
1134The ARM target provides hardware support for conversions between
1135@code{__fp16} and @code{float} values
1136as an extension to VFP and NEON (Advanced SIMD), and from ARMv8-A provides
1137hardware support for conversions between @code{__fp16} and @code{double}
1138values.  GCC generates code using these hardware instructions if you
1139compile with options to select an FPU that provides them;
1140for example, @option{-mfpu=neon-fp16 -mfloat-abi=softfp},
1141in addition to the @option{-mfp16-format} option to select
1142a half-precision format.
1143
1144Language-level support for the @code{__fp16} data type is
1145independent of whether GCC generates code using hardware floating-point
1146instructions.  In cases where hardware support is not specified, GCC
1147implements conversions between @code{__fp16} and other types as library
1148calls.
1149
1150It is recommended that portable code use the @code{_Float16} type defined
1151by ISO/IEC TS 18661-3:2015.  @xref{Floating Types}.
1152
1153@node Decimal Float
1154@section Decimal Floating Types
1155@cindex decimal floating types
1156@cindex @code{_Decimal32} data type
1157@cindex @code{_Decimal64} data type
1158@cindex @code{_Decimal128} data type
1159@cindex @code{df} integer suffix
1160@cindex @code{dd} integer suffix
1161@cindex @code{dl} integer suffix
1162@cindex @code{DF} integer suffix
1163@cindex @code{DD} integer suffix
1164@cindex @code{DL} integer suffix
1165
1166As an extension, GNU C supports decimal floating types as
1167defined in the N1312 draft of ISO/IEC WDTR24732.  Support for decimal
1168floating types in GCC will evolve as the draft technical report changes.
1169Calling conventions for any target might also change.  Not all targets
1170support decimal floating types.
1171
1172The decimal floating types are @code{_Decimal32}, @code{_Decimal64}, and
1173@code{_Decimal128}.  They use a radix of ten, unlike the floating types
1174@code{float}, @code{double}, and @code{long double} whose radix is not
1175specified by the C standard but is usually two.
1176
1177Support for decimal floating types includes the arithmetic operators
1178add, subtract, multiply, divide; unary arithmetic operators;
1179relational operators; equality operators; and conversions to and from
1180integer and other floating types.  Use a suffix @samp{df} or
1181@samp{DF} in a literal constant of type @code{_Decimal32}, @samp{dd}
1182or @samp{DD} for @code{_Decimal64}, and @samp{dl} or @samp{DL} for
1183@code{_Decimal128}.
1184
1185GCC support of decimal float as specified by the draft technical report
1186is incomplete:
1187
1188@itemize @bullet
1189@item
1190When the value of a decimal floating type cannot be represented in the
1191integer type to which it is being converted, the result is undefined
1192rather than the result value specified by the draft technical report.
1193
1194@item
1195GCC does not provide the C library functionality associated with
1196@file{math.h}, @file{fenv.h}, @file{stdio.h}, @file{stdlib.h}, and
1197@file{wchar.h}, which must come from a separate C library implementation.
1198Because of this the GNU C compiler does not define macro
1199@code{__STDC_DEC_FP__} to indicate that the implementation conforms to
1200the technical report.
1201@end itemize
1202
1203Types @code{_Decimal32}, @code{_Decimal64}, and @code{_Decimal128}
1204are supported by the DWARF debug information format.
1205
1206@node Hex Floats
1207@section Hex Floats
1208@cindex hex floats
1209
1210ISO C99 and ISO C++17 support floating-point numbers written not only in
1211the usual decimal notation, such as @code{1.55e1}, but also numbers such as
1212@code{0x1.fp3} written in hexadecimal format.  As a GNU extension, GCC
1213supports this in C90 mode (except in some cases when strictly
1214conforming) and in C++98, C++11 and C++14 modes.  In that format the
1215@samp{0x} hex introducer and the @samp{p} or @samp{P} exponent field are
1216mandatory.  The exponent is a decimal number that indicates the power of
12172 by which the significant part is multiplied.  Thus @samp{0x1.f} is
1218@tex
1219$1 {15\over16}$,
1220@end tex
1221@ifnottex
12221 15/16,
1223@end ifnottex
1224@samp{p3} multiplies it by 8, and the value of @code{0x1.fp3}
1225is the same as @code{1.55e1}.
1226
1227Unlike for floating-point numbers in the decimal notation the exponent
1228is always required in the hexadecimal notation.  Otherwise the compiler
1229would not be able to resolve the ambiguity of, e.g., @code{0x1.f}.  This
1230could mean @code{1.0f} or @code{1.9375} since @samp{f} is also the
1231extension for floating-point constants of type @code{float}.
1232
1233@node Fixed-Point
1234@section Fixed-Point Types
1235@cindex fixed-point types
1236@cindex @code{_Fract} data type
1237@cindex @code{_Accum} data type
1238@cindex @code{_Sat} data type
1239@cindex @code{hr} fixed-suffix
1240@cindex @code{r} fixed-suffix
1241@cindex @code{lr} fixed-suffix
1242@cindex @code{llr} fixed-suffix
1243@cindex @code{uhr} fixed-suffix
1244@cindex @code{ur} fixed-suffix
1245@cindex @code{ulr} fixed-suffix
1246@cindex @code{ullr} fixed-suffix
1247@cindex @code{hk} fixed-suffix
1248@cindex @code{k} fixed-suffix
1249@cindex @code{lk} fixed-suffix
1250@cindex @code{llk} fixed-suffix
1251@cindex @code{uhk} fixed-suffix
1252@cindex @code{uk} fixed-suffix
1253@cindex @code{ulk} fixed-suffix
1254@cindex @code{ullk} fixed-suffix
1255@cindex @code{HR} fixed-suffix
1256@cindex @code{R} fixed-suffix
1257@cindex @code{LR} fixed-suffix
1258@cindex @code{LLR} fixed-suffix
1259@cindex @code{UHR} fixed-suffix
1260@cindex @code{UR} fixed-suffix
1261@cindex @code{ULR} fixed-suffix
1262@cindex @code{ULLR} fixed-suffix
1263@cindex @code{HK} fixed-suffix
1264@cindex @code{K} fixed-suffix
1265@cindex @code{LK} fixed-suffix
1266@cindex @code{LLK} fixed-suffix
1267@cindex @code{UHK} fixed-suffix
1268@cindex @code{UK} fixed-suffix
1269@cindex @code{ULK} fixed-suffix
1270@cindex @code{ULLK} fixed-suffix
1271
1272As an extension, GNU C supports fixed-point types as
1273defined in the N1169 draft of ISO/IEC DTR 18037.  Support for fixed-point
1274types in GCC will evolve as the draft technical report changes.
1275Calling conventions for any target might also change.  Not all targets
1276support fixed-point types.
1277
1278The fixed-point types are
1279@code{short _Fract},
1280@code{_Fract},
1281@code{long _Fract},
1282@code{long long _Fract},
1283@code{unsigned short _Fract},
1284@code{unsigned _Fract},
1285@code{unsigned long _Fract},
1286@code{unsigned long long _Fract},
1287@code{_Sat short _Fract},
1288@code{_Sat _Fract},
1289@code{_Sat long _Fract},
1290@code{_Sat long long _Fract},
1291@code{_Sat unsigned short _Fract},
1292@code{_Sat unsigned _Fract},
1293@code{_Sat unsigned long _Fract},
1294@code{_Sat unsigned long long _Fract},
1295@code{short _Accum},
1296@code{_Accum},
1297@code{long _Accum},
1298@code{long long _Accum},
1299@code{unsigned short _Accum},
1300@code{unsigned _Accum},
1301@code{unsigned long _Accum},
1302@code{unsigned long long _Accum},
1303@code{_Sat short _Accum},
1304@code{_Sat _Accum},
1305@code{_Sat long _Accum},
1306@code{_Sat long long _Accum},
1307@code{_Sat unsigned short _Accum},
1308@code{_Sat unsigned _Accum},
1309@code{_Sat unsigned long _Accum},
1310@code{_Sat unsigned long long _Accum}.
1311
1312Fixed-point data values contain fractional and optional integral parts.
1313The format of fixed-point data varies and depends on the target machine.
1314
1315Support for fixed-point types includes:
1316@itemize @bullet
1317@item
1318prefix and postfix increment and decrement operators (@code{++}, @code{--})
1319@item
1320unary arithmetic operators (@code{+}, @code{-}, @code{!})
1321@item
1322binary arithmetic operators (@code{+}, @code{-}, @code{*}, @code{/})
1323@item
1324binary shift operators (@code{<<}, @code{>>})
1325@item
1326relational operators (@code{<}, @code{<=}, @code{>=}, @code{>})
1327@item
1328equality operators (@code{==}, @code{!=})
1329@item
1330assignment operators (@code{+=}, @code{-=}, @code{*=}, @code{/=},
1331@code{<<=}, @code{>>=})
1332@item
1333conversions to and from integer, floating-point, or fixed-point types
1334@end itemize
1335
1336Use a suffix in a fixed-point literal constant:
1337@itemize
1338@item @samp{hr} or @samp{HR} for @code{short _Fract} and
1339@code{_Sat short _Fract}
1340@item @samp{r} or @samp{R} for @code{_Fract} and @code{_Sat _Fract}
1341@item @samp{lr} or @samp{LR} for @code{long _Fract} and
1342@code{_Sat long _Fract}
1343@item @samp{llr} or @samp{LLR} for @code{long long _Fract} and
1344@code{_Sat long long _Fract}
1345@item @samp{uhr} or @samp{UHR} for @code{unsigned short _Fract} and
1346@code{_Sat unsigned short _Fract}
1347@item @samp{ur} or @samp{UR} for @code{unsigned _Fract} and
1348@code{_Sat unsigned _Fract}
1349@item @samp{ulr} or @samp{ULR} for @code{unsigned long _Fract} and
1350@code{_Sat unsigned long _Fract}
1351@item @samp{ullr} or @samp{ULLR} for @code{unsigned long long _Fract}
1352and @code{_Sat unsigned long long _Fract}
1353@item @samp{hk} or @samp{HK} for @code{short _Accum} and
1354@code{_Sat short _Accum}
1355@item @samp{k} or @samp{K} for @code{_Accum} and @code{_Sat _Accum}
1356@item @samp{lk} or @samp{LK} for @code{long _Accum} and
1357@code{_Sat long _Accum}
1358@item @samp{llk} or @samp{LLK} for @code{long long _Accum} and
1359@code{_Sat long long _Accum}
1360@item @samp{uhk} or @samp{UHK} for @code{unsigned short _Accum} and
1361@code{_Sat unsigned short _Accum}
1362@item @samp{uk} or @samp{UK} for @code{unsigned _Accum} and
1363@code{_Sat unsigned _Accum}
1364@item @samp{ulk} or @samp{ULK} for @code{unsigned long _Accum} and
1365@code{_Sat unsigned long _Accum}
1366@item @samp{ullk} or @samp{ULLK} for @code{unsigned long long _Accum}
1367and @code{_Sat unsigned long long _Accum}
1368@end itemize
1369
1370GCC support of fixed-point types as specified by the draft technical report
1371is incomplete:
1372
1373@itemize @bullet
1374@item
1375Pragmas to control overflow and rounding behaviors are not implemented.
1376@end itemize
1377
1378Fixed-point types are supported by the DWARF debug information format.
1379
1380@node Named Address Spaces
1381@section Named Address Spaces
1382@cindex Named Address Spaces
1383
1384As an extension, GNU C supports named address spaces as
1385defined in the N1275 draft of ISO/IEC DTR 18037.  Support for named
1386address spaces in GCC will evolve as the draft technical report
1387changes.  Calling conventions for any target might also change.  At
1388present, only the AVR, M32C, RL78, and x86 targets support
1389address spaces other than the generic address space.
1390
1391Address space identifiers may be used exactly like any other C type
1392qualifier (e.g., @code{const} or @code{volatile}).  See the N1275
1393document for more details.
1394
1395@anchor{AVR Named Address Spaces}
1396@subsection AVR Named Address Spaces
1397
1398On the AVR target, there are several address spaces that can be used
1399in order to put read-only data into the flash memory and access that
1400data by means of the special instructions @code{LPM} or @code{ELPM}
1401needed to read from flash.
1402
1403Devices belonging to @code{avrtiny} and @code{avrxmega3} can access
1404flash memory by means of @code{LD*} instructions because the flash
1405memory is mapped into the RAM address space.  There is @emph{no need}
1406for language extensions like @code{__flash} or attribute
1407@ref{AVR Variable Attributes,,@code{progmem}}.
1408The default linker description files for these devices cater for that
1409feature and @code{.rodata} stays in flash: The compiler just generates
1410@code{LD*} instructions, and the linker script adds core specific
1411offsets to all @code{.rodata} symbols: @code{0x4000} in the case of
1412@code{avrtiny} and @code{0x8000} in the case of @code{avrxmega3}.
1413See @ref{AVR Options} for a list of respective devices.
1414
1415For devices not in @code{avrtiny} or @code{avrxmega3},
1416any data including read-only data is located in RAM (the generic
1417address space) because flash memory is not visible in the RAM address
1418space.  In order to locate read-only data in flash memory @emph{and}
1419to generate the right instructions to access this data without
1420using (inline) assembler code, special address spaces are needed.
1421
1422@table @code
1423@item __flash
1424@cindex @code{__flash} AVR Named Address Spaces
1425The @code{__flash} qualifier locates data in the
1426@code{.progmem.data} section. Data is read using the @code{LPM}
1427instruction. Pointers to this address space are 16 bits wide.
1428
1429@item __flash1
1430@itemx __flash2
1431@itemx __flash3
1432@itemx __flash4
1433@itemx __flash5
1434@cindex @code{__flash1} AVR Named Address Spaces
1435@cindex @code{__flash2} AVR Named Address Spaces
1436@cindex @code{__flash3} AVR Named Address Spaces
1437@cindex @code{__flash4} AVR Named Address Spaces
1438@cindex @code{__flash5} AVR Named Address Spaces
1439These are 16-bit address spaces locating data in section
1440@code{.progmem@var{N}.data} where @var{N} refers to
1441address space @code{__flash@var{N}}.
1442The compiler sets the @code{RAMPZ} segment register appropriately
1443before reading data by means of the @code{ELPM} instruction.
1444
1445@item __memx
1446@cindex @code{__memx} AVR Named Address Spaces
1447This is a 24-bit address space that linearizes flash and RAM:
1448If the high bit of the address is set, data is read from
1449RAM using the lower two bytes as RAM address.
1450If the high bit of the address is clear, data is read from flash
1451with @code{RAMPZ} set according to the high byte of the address.
1452@xref{AVR Built-in Functions,,@code{__builtin_avr_flash_segment}}.
1453
1454Objects in this address space are located in @code{.progmemx.data}.
1455@end table
1456
1457@b{Example}
1458
1459@smallexample
1460char my_read (const __flash char ** p)
1461@{
1462    /* p is a pointer to RAM that points to a pointer to flash.
1463       The first indirection of p reads that flash pointer
1464       from RAM and the second indirection reads a char from this
1465       flash address.  */
1466
1467    return **p;
1468@}
1469
1470/* Locate array[] in flash memory */
1471const __flash int array[] = @{ 3, 5, 7, 11, 13, 17, 19 @};
1472
1473int i = 1;
1474
1475int main (void)
1476@{
1477   /* Return 17 by reading from flash memory */
1478   return array[array[i]];
1479@}
1480@end smallexample
1481
1482@noindent
1483For each named address space supported by avr-gcc there is an equally
1484named but uppercase built-in macro defined.
1485The purpose is to facilitate testing if respective address space
1486support is available or not:
1487
1488@smallexample
1489#ifdef __FLASH
1490const __flash int var = 1;
1491
1492int read_var (void)
1493@{
1494    return var;
1495@}
1496#else
1497#include <avr/pgmspace.h> /* From AVR-LibC */
1498
1499const int var PROGMEM = 1;
1500
1501int read_var (void)
1502@{
1503    return (int) pgm_read_word (&var);
1504@}
1505#endif /* __FLASH */
1506@end smallexample
1507
1508@noindent
1509Notice that attribute @ref{AVR Variable Attributes,,@code{progmem}}
1510locates data in flash but
1511accesses to these data read from generic address space, i.e.@:
1512from RAM,
1513so that you need special accessors like @code{pgm_read_byte}
1514from @w{@uref{http://nongnu.org/avr-libc/user-manual/,AVR-LibC}}
1515together with attribute @code{progmem}.
1516
1517@noindent
1518@b{Limitations and caveats}
1519
1520@itemize
1521@item
1522Reading across the 64@tie{}KiB section boundary of
1523the @code{__flash} or @code{__flash@var{N}} address spaces
1524shows undefined behavior. The only address space that
1525supports reading across the 64@tie{}KiB flash segment boundaries is
1526@code{__memx}.
1527
1528@item
1529If you use one of the @code{__flash@var{N}} address spaces
1530you must arrange your linker script to locate the
1531@code{.progmem@var{N}.data} sections according to your needs.
1532
1533@item
1534Any data or pointers to the non-generic address spaces must
1535be qualified as @code{const}, i.e.@: as read-only data.
1536This still applies if the data in one of these address
1537spaces like software version number or calibration lookup table are intended to
1538be changed after load time by, say, a boot loader. In this case
1539the right qualification is @code{const} @code{volatile} so that the compiler
1540must not optimize away known values or insert them
1541as immediates into operands of instructions.
1542
1543@item
1544The following code initializes a variable @code{pfoo}
1545located in static storage with a 24-bit address:
1546@smallexample
1547extern const __memx char foo;
1548const __memx void *pfoo = &foo;
1549@end smallexample
1550
1551@item
1552On the reduced Tiny devices like ATtiny40, no address spaces are supported.
1553Just use vanilla C / C++ code without overhead as outlined above.
1554Attribute @code{progmem} is supported but works differently,
1555see @ref{AVR Variable Attributes}.
1556
1557@end itemize
1558
1559@subsection M32C Named Address Spaces
1560@cindex @code{__far} M32C Named Address Spaces
1561
1562On the M32C target, with the R8C and M16C CPU variants, variables
1563qualified with @code{__far} are accessed using 32-bit addresses in
1564order to access memory beyond the first 64@tie{}Ki bytes.  If
1565@code{__far} is used with the M32CM or M32C CPU variants, it has no
1566effect.
1567
1568@subsection RL78 Named Address Spaces
1569@cindex @code{__far} RL78 Named Address Spaces
1570
1571On the RL78 target, variables qualified with @code{__far} are accessed
1572with 32-bit pointers (20-bit addresses) rather than the default 16-bit
1573addresses.  Non-far variables are assumed to appear in the topmost
157464@tie{}KiB of the address space.
1575
1576@subsection x86 Named Address Spaces
1577@cindex x86 named address spaces
1578
1579On the x86 target, variables may be declared as being relative
1580to the @code{%fs} or @code{%gs} segments.
1581
1582@table @code
1583@item __seg_fs
1584@itemx __seg_gs
1585@cindex @code{__seg_fs} x86 named address space
1586@cindex @code{__seg_gs} x86 named address space
1587The object is accessed with the respective segment override prefix.
1588
1589The respective segment base must be set via some method specific to
1590the operating system.  Rather than require an expensive system call
1591to retrieve the segment base, these address spaces are not considered
1592to be subspaces of the generic (flat) address space.  This means that
1593explicit casts are required to convert pointers between these address
1594spaces and the generic address space.  In practice the application
1595should cast to @code{uintptr_t} and apply the segment base offset
1596that it installed previously.
1597
1598The preprocessor symbols @code{__SEG_FS} and @code{__SEG_GS} are
1599defined when these address spaces are supported.
1600@end table
1601
1602@node Zero Length
1603@section Arrays of Length Zero
1604@cindex arrays of length zero
1605@cindex zero-length arrays
1606@cindex length-zero arrays
1607@cindex flexible array members
1608
1609Declaring zero-length arrays is allowed in GNU C as an extension.
1610A zero-length array can be useful as the last element of a structure
1611that is really a header for a variable-length object:
1612
1613@smallexample
1614struct line @{
1615  int length;
1616  char contents[0];
1617@};
1618
1619struct line *thisline = (struct line *)
1620  malloc (sizeof (struct line) + this_length);
1621thisline->length = this_length;
1622@end smallexample
1623
1624Although the size of a zero-length array is zero, an array member of
1625this kind may increase the size of the enclosing type as a result of tail
1626padding.  The offset of a zero-length array member from the beginning
1627of the enclosing structure is the same as the offset of an array with
1628one or more elements of the same type.  The alignment of a zero-length
1629array is the same as the alignment of its elements.
1630
1631Declaring zero-length arrays in other contexts, including as interior
1632members of structure objects or as non-member objects, is discouraged.
1633Accessing elements of zero-length arrays declared in such contexts is
1634undefined and may be diagnosed.
1635
1636In the absence of the zero-length array extension, in ISO C90
1637the @code{contents} array in the example above would typically be declared
1638to have a single element.  Unlike a zero-length array which only contributes
1639to the size of the enclosing structure for the purposes of alignment,
1640a one-element array always occupies at least as much space as a single
1641object of the type.  Although using one-element arrays this way is
1642discouraged, GCC handles accesses to trailing one-element array members
1643analogously to zero-length arrays.
1644
1645The preferred mechanism to declare variable-length types like
1646@code{struct line} above is the ISO C99 @dfn{flexible array member},
1647with slightly different syntax and semantics:
1648
1649@itemize @bullet
1650@item
1651Flexible array members are written as @code{contents[]} without
1652the @code{0}.
1653
1654@item
1655Flexible array members have incomplete type, and so the @code{sizeof}
1656operator may not be applied.  As a quirk of the original implementation
1657of zero-length arrays, @code{sizeof} evaluates to zero.
1658
1659@item
1660Flexible array members may only appear as the last member of a
1661@code{struct} that is otherwise non-empty.
1662
1663@item
1664A structure containing a flexible array member, or a union containing
1665such a structure (possibly recursively), may not be a member of a
1666structure or an element of an array.  (However, these uses are
1667permitted by GCC as extensions.)
1668@end itemize
1669
1670Non-empty initialization of zero-length
1671arrays is treated like any case where there are more initializer
1672elements than the array holds, in that a suitable warning about ``excess
1673elements in array'' is given, and the excess elements (all of them, in
1674this case) are ignored.
1675
1676GCC allows static initialization of flexible array members.
1677This is equivalent to defining a new structure containing the original
1678structure followed by an array of sufficient size to contain the data.
1679E.g.@: in the following, @code{f1} is constructed as if it were declared
1680like @code{f2}.
1681
1682@smallexample
1683struct f1 @{
1684  int x; int y[];
1685@} f1 = @{ 1, @{ 2, 3, 4 @} @};
1686
1687struct f2 @{
1688  struct f1 f1; int data[3];
1689@} f2 = @{ @{ 1 @}, @{ 2, 3, 4 @} @};
1690@end smallexample
1691
1692@noindent
1693The convenience of this extension is that @code{f1} has the desired
1694type, eliminating the need to consistently refer to @code{f2.f1}.
1695
1696This has symmetry with normal static arrays, in that an array of
1697unknown size is also written with @code{[]}.
1698
1699Of course, this extension only makes sense if the extra data comes at
1700the end of a top-level object, as otherwise we would be overwriting
1701data at subsequent offsets.  To avoid undue complication and confusion
1702with initialization of deeply nested arrays, we simply disallow any
1703non-empty initialization except when the structure is the top-level
1704object.  For example:
1705
1706@smallexample
1707struct foo @{ int x; int y[]; @};
1708struct bar @{ struct foo z; @};
1709
1710struct foo a = @{ 1, @{ 2, 3, 4 @} @};        // @r{Valid.}
1711struct bar b = @{ @{ 1, @{ 2, 3, 4 @} @} @};    // @r{Invalid.}
1712struct bar c = @{ @{ 1, @{ @} @} @};            // @r{Valid.}
1713struct foo d[1] = @{ @{ 1, @{ 2, 3, 4 @} @} @};  // @r{Invalid.}
1714@end smallexample
1715
1716@node Empty Structures
1717@section Structures with No Members
1718@cindex empty structures
1719@cindex zero-size structures
1720
1721GCC permits a C structure to have no members:
1722
1723@smallexample
1724struct empty @{
1725@};
1726@end smallexample
1727
1728The structure has size zero.  In C++, empty structures are part
1729of the language.  G++ treats empty structures as if they had a single
1730member of type @code{char}.
1731
1732@node Variable Length
1733@section Arrays of Variable Length
1734@cindex variable-length arrays
1735@cindex arrays of variable length
1736@cindex VLAs
1737
1738Variable-length automatic arrays are allowed in ISO C99, and as an
1739extension GCC accepts them in C90 mode and in C++.  These arrays are
1740declared like any other automatic arrays, but with a length that is not
1741a constant expression.  The storage is allocated at the point of
1742declaration and deallocated when the block scope containing the declaration
1743exits.  For
1744example:
1745
1746@smallexample
1747FILE *
1748concat_fopen (char *s1, char *s2, char *mode)
1749@{
1750  char str[strlen (s1) + strlen (s2) + 1];
1751  strcpy (str, s1);
1752  strcat (str, s2);
1753  return fopen (str, mode);
1754@}
1755@end smallexample
1756
1757@cindex scope of a variable length array
1758@cindex variable-length array scope
1759@cindex deallocating variable length arrays
1760Jumping or breaking out of the scope of the array name deallocates the
1761storage.  Jumping into the scope is not allowed; you get an error
1762message for it.
1763
1764@cindex variable-length array in a structure
1765As an extension, GCC accepts variable-length arrays as a member of
1766a structure or a union.  For example:
1767
1768@smallexample
1769void
1770foo (int n)
1771@{
1772  struct S @{ int x[n]; @};
1773@}
1774@end smallexample
1775
1776@cindex @code{alloca} vs variable-length arrays
1777You can use the function @code{alloca} to get an effect much like
1778variable-length arrays.  The function @code{alloca} is available in
1779many other C implementations (but not in all).  On the other hand,
1780variable-length arrays are more elegant.
1781
1782There are other differences between these two methods.  Space allocated
1783with @code{alloca} exists until the containing @emph{function} returns.
1784The space for a variable-length array is deallocated as soon as the array
1785name's scope ends, unless you also use @code{alloca} in this scope.
1786
1787You can also use variable-length arrays as arguments to functions:
1788
1789@smallexample
1790struct entry
1791tester (int len, char data[len][len])
1792@{
1793  /* @r{@dots{}} */
1794@}
1795@end smallexample
1796
1797The length of an array is computed once when the storage is allocated
1798and is remembered for the scope of the array in case you access it with
1799@code{sizeof}.
1800
1801If you want to pass the array first and the length afterward, you can
1802use a forward declaration in the parameter list---another GNU extension.
1803
1804@smallexample
1805struct entry
1806tester (int len; char data[len][len], int len)
1807@{
1808  /* @r{@dots{}} */
1809@}
1810@end smallexample
1811
1812@cindex parameter forward declaration
1813The @samp{int len} before the semicolon is a @dfn{parameter forward
1814declaration}, and it serves the purpose of making the name @code{len}
1815known when the declaration of @code{data} is parsed.
1816
1817You can write any number of such parameter forward declarations in the
1818parameter list.  They can be separated by commas or semicolons, but the
1819last one must end with a semicolon, which is followed by the ``real''
1820parameter declarations.  Each forward declaration must match a ``real''
1821declaration in parameter name and data type.  ISO C99 does not support
1822parameter forward declarations.
1823
1824@node Variadic Macros
1825@section Macros with a Variable Number of Arguments.
1826@cindex variable number of arguments
1827@cindex macro with variable arguments
1828@cindex rest argument (in macro)
1829@cindex variadic macros
1830
1831In the ISO C standard of 1999, a macro can be declared to accept a
1832variable number of arguments much as a function can.  The syntax for
1833defining the macro is similar to that of a function.  Here is an
1834example:
1835
1836@smallexample
1837#define debug(format, ...) fprintf (stderr, format, __VA_ARGS__)
1838@end smallexample
1839
1840@noindent
1841Here @samp{@dots{}} is a @dfn{variable argument}.  In the invocation of
1842such a macro, it represents the zero or more tokens until the closing
1843parenthesis that ends the invocation, including any commas.  This set of
1844tokens replaces the identifier @code{__VA_ARGS__} in the macro body
1845wherever it appears.  See the CPP manual for more information.
1846
1847GCC has long supported variadic macros, and used a different syntax that
1848allowed you to give a name to the variable arguments just like any other
1849argument.  Here is an example:
1850
1851@smallexample
1852#define debug(format, args...) fprintf (stderr, format, args)
1853@end smallexample
1854
1855@noindent
1856This is in all ways equivalent to the ISO C example above, but arguably
1857more readable and descriptive.
1858
1859GNU CPP has two further variadic macro extensions, and permits them to
1860be used with either of the above forms of macro definition.
1861
1862In standard C, you are not allowed to leave the variable argument out
1863entirely; but you are allowed to pass an empty argument.  For example,
1864this invocation is invalid in ISO C, because there is no comma after
1865the string:
1866
1867@smallexample
1868debug ("A message")
1869@end smallexample
1870
1871GNU CPP permits you to completely omit the variable arguments in this
1872way.  In the above examples, the compiler would complain, though since
1873the expansion of the macro still has the extra comma after the format
1874string.
1875
1876To help solve this problem, CPP behaves specially for variable arguments
1877used with the token paste operator, @samp{##}.  If instead you write
1878
1879@smallexample
1880#define debug(format, ...) fprintf (stderr, format, ## __VA_ARGS__)
1881@end smallexample
1882
1883@noindent
1884and if the variable arguments are omitted or empty, the @samp{##}
1885operator causes the preprocessor to remove the comma before it.  If you
1886do provide some variable arguments in your macro invocation, GNU CPP
1887does not complain about the paste operation and instead places the
1888variable arguments after the comma.  Just like any other pasted macro
1889argument, these arguments are not macro expanded.
1890
1891@node Escaped Newlines
1892@section Slightly Looser Rules for Escaped Newlines
1893@cindex escaped newlines
1894@cindex newlines (escaped)
1895
1896The preprocessor treatment of escaped newlines is more relaxed
1897than that specified by the C90 standard, which requires the newline
1898to immediately follow a backslash.
1899GCC's implementation allows whitespace in the form
1900of spaces, horizontal and vertical tabs, and form feeds between the
1901backslash and the subsequent newline.  The preprocessor issues a
1902warning, but treats it as a valid escaped newline and combines the two
1903lines to form a single logical line.  This works within comments and
1904tokens, as well as between tokens.  Comments are @emph{not} treated as
1905whitespace for the purposes of this relaxation, since they have not
1906yet been replaced with spaces.
1907
1908@node Subscripting
1909@section Non-Lvalue Arrays May Have Subscripts
1910@cindex subscripting
1911@cindex arrays, non-lvalue
1912
1913@cindex subscripting and function values
1914In ISO C99, arrays that are not lvalues still decay to pointers, and
1915may be subscripted, although they may not be modified or used after
1916the next sequence point and the unary @samp{&} operator may not be
1917applied to them.  As an extension, GNU C allows such arrays to be
1918subscripted in C90 mode, though otherwise they do not decay to
1919pointers outside C99 mode.  For example,
1920this is valid in GNU C though not valid in C90:
1921
1922@smallexample
1923@group
1924struct foo @{int a[4];@};
1925
1926struct foo f();
1927
1928bar (int index)
1929@{
1930  return f().a[index];
1931@}
1932@end group
1933@end smallexample
1934
1935@node Pointer Arith
1936@section Arithmetic on @code{void}- and Function-Pointers
1937@cindex void pointers, arithmetic
1938@cindex void, size of pointer to
1939@cindex function pointers, arithmetic
1940@cindex function, size of pointer to
1941
1942In GNU C, addition and subtraction operations are supported on pointers to
1943@code{void} and on pointers to functions.  This is done by treating the
1944size of a @code{void} or of a function as 1.
1945
1946A consequence of this is that @code{sizeof} is also allowed on @code{void}
1947and on function types, and returns 1.
1948
1949@opindex Wpointer-arith
1950The option @option{-Wpointer-arith} requests a warning if these extensions
1951are used.
1952
1953@node Variadic Pointer Args
1954@section Pointer Arguments in Variadic Functions
1955@cindex pointer arguments in variadic functions
1956@cindex variadic functions, pointer arguments
1957
1958Standard C requires that pointer types used with @code{va_arg} in
1959functions with variable argument lists either must be compatible with
1960that of the actual argument, or that one type must be a pointer to
1961@code{void} and the other a pointer to a character type.  GNU C
1962implements the POSIX XSI extension that additionally permits the use
1963of @code{va_arg} with a pointer type to receive arguments of any other
1964pointer type.
1965
1966In particular, in GNU C @samp{va_arg (ap, void *)} can safely be used
1967to consume an argument of any pointer type.
1968
1969@node Pointers to Arrays
1970@section Pointers to Arrays with Qualifiers Work as Expected
1971@cindex pointers to arrays
1972@cindex const qualifier
1973
1974In GNU C, pointers to arrays with qualifiers work similar to pointers
1975to other qualified types. For example, a value of type @code{int (*)[5]}
1976can be used to initialize a variable of type @code{const int (*)[5]}.
1977These types are incompatible in ISO C because the @code{const} qualifier
1978is formally attached to the element type of the array and not the
1979array itself.
1980
1981@smallexample
1982extern void
1983transpose (int N, int M, double out[M][N], const double in[N][M]);
1984double x[3][2];
1985double y[2][3];
1986@r{@dots{}}
1987transpose(3, 2, y, x);
1988@end smallexample
1989
1990@node Initializers
1991@section Non-Constant Initializers
1992@cindex initializers, non-constant
1993@cindex non-constant initializers
1994
1995As in standard C++ and ISO C99, the elements of an aggregate initializer for an
1996automatic variable are not required to be constant expressions in GNU C@.
1997Here is an example of an initializer with run-time varying elements:
1998
1999@smallexample
2000foo (float f, float g)
2001@{
2002  float beat_freqs[2] = @{ f-g, f+g @};
2003  /* @r{@dots{}} */
2004@}
2005@end smallexample
2006
2007@node Compound Literals
2008@section Compound Literals
2009@cindex constructor expressions
2010@cindex initializations in expressions
2011@cindex structures, constructor expression
2012@cindex expressions, constructor
2013@cindex compound literals
2014@c The GNU C name for what C99 calls compound literals was "constructor expressions".
2015
2016A compound literal looks like a cast of a brace-enclosed aggregate
2017initializer list.  Its value is an object of the type specified in
2018the cast, containing the elements specified in the initializer.
2019Unlike the result of a cast, a compound literal is an lvalue.  ISO
2020C99 and later support compound literals.  As an extension, GCC
2021supports compound literals also in C90 mode and in C++, although
2022as explained below, the C++ semantics are somewhat different.
2023
2024Usually, the specified type of a compound literal is a structure.  Assume
2025that @code{struct foo} and @code{structure} are declared as shown:
2026
2027@smallexample
2028struct foo @{int a; char b[2];@} structure;
2029@end smallexample
2030
2031@noindent
2032Here is an example of constructing a @code{struct foo} with a compound literal:
2033
2034@smallexample
2035structure = ((struct foo) @{x + y, 'a', 0@});
2036@end smallexample
2037
2038@noindent
2039This is equivalent to writing the following:
2040
2041@smallexample
2042@{
2043  struct foo temp = @{x + y, 'a', 0@};
2044  structure = temp;
2045@}
2046@end smallexample
2047
2048You can also construct an array, though this is dangerous in C++, as
2049explained below.  If all the elements of the compound literal are
2050(made up of) simple constant expressions suitable for use in
2051initializers of objects of static storage duration, then the compound
2052literal can be coerced to a pointer to its first element and used in
2053such an initializer, as shown here:
2054
2055@smallexample
2056char **foo = (char *[]) @{ "x", "y", "z" @};
2057@end smallexample
2058
2059Compound literals for scalar types and union types are also allowed.  In
2060the following example the variable @code{i} is initialized to the value
2061@code{2}, the result of incrementing the unnamed object created by
2062the compound literal.
2063
2064@smallexample
2065int i = ++(int) @{ 1 @};
2066@end smallexample
2067
2068As a GNU extension, GCC allows initialization of objects with static storage
2069duration by compound literals (which is not possible in ISO C99 because
2070the initializer is not a constant).
2071It is handled as if the object were initialized only with the brace-enclosed
2072list if the types of the compound literal and the object match.
2073The elements of the compound literal must be constant.
2074If the object being initialized has array type of unknown size, the size is
2075determined by the size of the compound literal.
2076
2077@smallexample
2078static struct foo x = (struct foo) @{1, 'a', 'b'@};
2079static int y[] = (int []) @{1, 2, 3@};
2080static int z[] = (int [3]) @{1@};
2081@end smallexample
2082
2083@noindent
2084The above lines are equivalent to the following:
2085@smallexample
2086static struct foo x = @{1, 'a', 'b'@};
2087static int y[] = @{1, 2, 3@};
2088static int z[] = @{1, 0, 0@};
2089@end smallexample
2090
2091In C, a compound literal designates an unnamed object with static or
2092automatic storage duration.  In C++, a compound literal designates a
2093temporary object that only lives until the end of its full-expression.
2094As a result, well-defined C code that takes the address of a subobject
2095of a compound literal can be undefined in C++, so G++ rejects
2096the conversion of a temporary array to a pointer.  For instance, if
2097the array compound literal example above appeared inside a function,
2098any subsequent use of @code{foo} in C++ would have undefined behavior
2099because the lifetime of the array ends after the declaration of @code{foo}.
2100
2101As an optimization, G++ sometimes gives array compound literals longer
2102lifetimes: when the array either appears outside a function or has
2103a @code{const}-qualified type.  If @code{foo} and its initializer had
2104elements of type @code{char *const} rather than @code{char *}, or if
2105@code{foo} were a global variable, the array would have static storage
2106duration.  But it is probably safest just to avoid the use of array
2107compound literals in C++ code.
2108
2109@node Designated Inits
2110@section Designated Initializers
2111@cindex initializers with labeled elements
2112@cindex labeled elements in initializers
2113@cindex case labels in initializers
2114@cindex designated initializers
2115
2116Standard C90 requires the elements of an initializer to appear in a fixed
2117order, the same as the order of the elements in the array or structure
2118being initialized.
2119
2120In ISO C99 you can give the elements in any order, specifying the array
2121indices or structure field names they apply to, and GNU C allows this as
2122an extension in C90 mode as well.  This extension is not
2123implemented in GNU C++.
2124
2125To specify an array index, write
2126@samp{[@var{index}] =} before the element value.  For example,
2127
2128@smallexample
2129int a[6] = @{ [4] = 29, [2] = 15 @};
2130@end smallexample
2131
2132@noindent
2133is equivalent to
2134
2135@smallexample
2136int a[6] = @{ 0, 0, 15, 0, 29, 0 @};
2137@end smallexample
2138
2139@noindent
2140The index values must be constant expressions, even if the array being
2141initialized is automatic.
2142
2143An alternative syntax for this that has been obsolete since GCC 2.5 but
2144GCC still accepts is to write @samp{[@var{index}]} before the element
2145value, with no @samp{=}.
2146
2147To initialize a range of elements to the same value, write
2148@samp{[@var{first} ... @var{last}] = @var{value}}.  This is a GNU
2149extension.  For example,
2150
2151@smallexample
2152int widths[] = @{ [0 ... 9] = 1, [10 ... 99] = 2, [100] = 3 @};
2153@end smallexample
2154
2155@noindent
2156If the value in it has side effects, the side effects happen only once,
2157not for each initialized field by the range initializer.
2158
2159@noindent
2160Note that the length of the array is the highest value specified
2161plus one.
2162
2163In a structure initializer, specify the name of a field to initialize
2164with @samp{.@var{fieldname} =} before the element value.  For example,
2165given the following structure,
2166
2167@smallexample
2168struct point @{ int x, y; @};
2169@end smallexample
2170
2171@noindent
2172the following initialization
2173
2174@smallexample
2175struct point p = @{ .y = yvalue, .x = xvalue @};
2176@end smallexample
2177
2178@noindent
2179is equivalent to
2180
2181@smallexample
2182struct point p = @{ xvalue, yvalue @};
2183@end smallexample
2184
2185Another syntax that has the same meaning, obsolete since GCC 2.5, is
2186@samp{@var{fieldname}:}, as shown here:
2187
2188@smallexample
2189struct point p = @{ y: yvalue, x: xvalue @};
2190@end smallexample
2191
2192Omitted fields are implicitly initialized the same as for objects
2193that have static storage duration.
2194
2195@cindex designators
2196The @samp{[@var{index}]} or @samp{.@var{fieldname}} is known as a
2197@dfn{designator}.  You can also use a designator (or the obsolete colon
2198syntax) when initializing a union, to specify which element of the union
2199should be used.  For example,
2200
2201@smallexample
2202union foo @{ int i; double d; @};
2203
2204union foo f = @{ .d = 4 @};
2205@end smallexample
2206
2207@noindent
2208converts 4 to a @code{double} to store it in the union using
2209the second element.  By contrast, casting 4 to type @code{union foo}
2210stores it into the union as the integer @code{i}, since it is
2211an integer.  @xref{Cast to Union}.
2212
2213You can combine this technique of naming elements with ordinary C
2214initialization of successive elements.  Each initializer element that
2215does not have a designator applies to the next consecutive element of the
2216array or structure.  For example,
2217
2218@smallexample
2219int a[6] = @{ [1] = v1, v2, [4] = v4 @};
2220@end smallexample
2221
2222@noindent
2223is equivalent to
2224
2225@smallexample
2226int a[6] = @{ 0, v1, v2, 0, v4, 0 @};
2227@end smallexample
2228
2229Labeling the elements of an array initializer is especially useful
2230when the indices are characters or belong to an @code{enum} type.
2231For example:
2232
2233@smallexample
2234int whitespace[256]
2235  = @{ [' '] = 1, ['\t'] = 1, ['\h'] = 1,
2236      ['\f'] = 1, ['\n'] = 1, ['\r'] = 1 @};
2237@end smallexample
2238
2239@cindex designator lists
2240You can also write a series of @samp{.@var{fieldname}} and
2241@samp{[@var{index}]} designators before an @samp{=} to specify a
2242nested subobject to initialize; the list is taken relative to the
2243subobject corresponding to the closest surrounding brace pair.  For
2244example, with the @samp{struct point} declaration above:
2245
2246@smallexample
2247struct point ptarray[10] = @{ [2].y = yv2, [2].x = xv2, [0].x = xv0 @};
2248@end smallexample
2249
2250If the same field is initialized multiple times, or overlapping
2251fields of a union are initialized, the value from the last
2252initialization is used.  When a field of a union is itself a structure,
2253the entire structure from the last field initialized is used.  If any previous
2254initializer has side effect, it is unspecified whether the side effect
2255happens or not.  Currently, GCC discards the side-effecting
2256initializer expressions and issues a warning.
2257
2258@node Case Ranges
2259@section Case Ranges
2260@cindex case ranges
2261@cindex ranges in case statements
2262
2263You can specify a range of consecutive values in a single @code{case} label,
2264like this:
2265
2266@smallexample
2267case @var{low} ... @var{high}:
2268@end smallexample
2269
2270@noindent
2271This has the same effect as the proper number of individual @code{case}
2272labels, one for each integer value from @var{low} to @var{high}, inclusive.
2273
2274This feature is especially useful for ranges of ASCII character codes:
2275
2276@smallexample
2277case 'A' ... 'Z':
2278@end smallexample
2279
2280@strong{Be careful:} Write spaces around the @code{...}, for otherwise
2281it may be parsed wrong when you use it with integer values.  For example,
2282write this:
2283
2284@smallexample
2285case 1 ... 5:
2286@end smallexample
2287
2288@noindent
2289rather than this:
2290
2291@smallexample
2292case 1...5:
2293@end smallexample
2294
2295@node Cast to Union
2296@section Cast to a Union Type
2297@cindex cast to a union
2298@cindex union, casting to a
2299
2300A cast to a union type is a C extension not available in C++.  It looks
2301just like ordinary casts with the constraint that the type specified is
2302a union type.  You can specify the type either with the @code{union}
2303keyword or with a @code{typedef} name that refers to a union.  The result
2304of a cast to a union is a temporary rvalue of the union type with a member
2305whose type matches that of the operand initialized to the value of
2306the operand.  The effect of a cast to a union is similar to a compound
2307literal except that it yields an rvalue like standard casts do.
2308@xref{Compound Literals}.
2309
2310Expressions that may be cast to the union type are those whose type matches
2311at least one of the members of the union.  Thus, given the following union
2312and variables:
2313
2314@smallexample
2315union foo @{ int i; double d; @};
2316int x;
2317double y;
2318union foo z;
2319@end smallexample
2320
2321@noindent
2322both @code{x} and @code{y} can be cast to type @code{union foo} and
2323the following assignments
2324@smallexample
2325  z = (union foo) x;
2326  z = (union foo) y;
2327@end smallexample
2328are shorthand equivalents of these
2329@smallexample
2330  z = (union foo) @{ .i = x @};
2331  z = (union foo) @{ .d = y @};
2332@end smallexample
2333
2334However, @code{(union foo) FLT_MAX;} is not a valid cast because the union
2335has no member of type @code{float}.
2336
2337Using the cast as the right-hand side of an assignment to a variable of
2338union type is equivalent to storing in a member of the union with
2339the same type
2340
2341@smallexample
2342union foo u;
2343/* @r{@dots{}} */
2344u = (union foo) x  @equiv{}  u.i = x
2345u = (union foo) y  @equiv{}  u.d = y
2346@end smallexample
2347
2348You can also use the union cast as a function argument:
2349
2350@smallexample
2351void hack (union foo);
2352/* @r{@dots{}} */
2353hack ((union foo) x);
2354@end smallexample
2355
2356@node Mixed Labels and Declarations
2357@section Mixed Declarations, Labels and Code
2358@cindex mixed declarations and code
2359@cindex declarations, mixed with code
2360@cindex code, mixed with declarations
2361
2362ISO C99 and ISO C++ allow declarations and code to be freely mixed
2363within compound statements.  ISO C2X allows labels to be
2364placed before declarations and at the end of a compound statement.
2365As an extension, GNU C also allows all this in C90 mode.  For example,
2366you could do:
2367
2368@smallexample
2369int i;
2370/* @r{@dots{}} */
2371i++;
2372int j = i + 2;
2373@end smallexample
2374
2375Each identifier is visible from where it is declared until the end of
2376the enclosing block.
2377
2378@node Function Attributes
2379@section Declaring Attributes of Functions
2380@cindex function attributes
2381@cindex declaring attributes of functions
2382@cindex @code{volatile} applied to function
2383@cindex @code{const} applied to function
2384
2385In GNU C and C++, you can use function attributes to specify certain
2386function properties that may help the compiler optimize calls or
2387check code more carefully for correctness.  For example, you
2388can use attributes to specify that a function never returns
2389(@code{noreturn}), returns a value depending only on the values of
2390its arguments (@code{const}), or has @code{printf}-style arguments
2391(@code{format}).
2392
2393You can also use attributes to control memory placement, code
2394generation options or call/return conventions within the function
2395being annotated.  Many of these attributes are target-specific.  For
2396example, many targets support attributes for defining interrupt
2397handler functions, which typically must follow special register usage
2398and return conventions.  Such attributes are described in the subsection
2399for each target.  However, a considerable number of attributes are
2400supported by most, if not all targets.  Those are described in
2401the @ref{Common Function Attributes} section.
2402
2403Function attributes are introduced by the @code{__attribute__} keyword
2404in the declaration of a function, followed by an attribute specification
2405enclosed in double parentheses.  You can specify multiple attributes in
2406a declaration by separating them by commas within the double parentheses
2407or by immediately following one attribute specification with another.
2408@xref{Attribute Syntax}, for the exact rules on attribute syntax and
2409placement.  Compatible attribute specifications on distinct declarations
2410of the same function are merged.  An attribute specification that is not
2411compatible with attributes already applied to a declaration of the same
2412function is ignored with a warning.
2413
2414Some function attributes take one or more arguments that refer to
2415the function's parameters by their positions within the function parameter
2416list.  Such attribute arguments are referred to as @dfn{positional arguments}.
2417Unless specified otherwise, positional arguments that specify properties
2418of parameters with pointer types can also specify the same properties of
2419the implicit C++ @code{this} argument in non-static member functions, and
2420of parameters of reference to a pointer type.  For ordinary functions,
2421position one refers to the first parameter on the list.  In C++ non-static
2422member functions, position one refers to the implicit @code{this} pointer.
2423The same restrictions and effects apply to function attributes used with
2424ordinary functions or C++ member functions.
2425
2426GCC also supports attributes on
2427variable declarations (@pxref{Variable Attributes}),
2428labels (@pxref{Label Attributes}),
2429enumerators (@pxref{Enumerator Attributes}),
2430statements (@pxref{Statement Attributes}),
2431and types (@pxref{Type Attributes}).
2432
2433There is some overlap between the purposes of attributes and pragmas
2434(@pxref{Pragmas,,Pragmas Accepted by GCC}).  It has been
2435found convenient to use @code{__attribute__} to achieve a natural
2436attachment of attributes to their corresponding declarations, whereas
2437@code{#pragma} is of use for compatibility with other compilers
2438or constructs that do not naturally form part of the grammar.
2439
2440In addition to the attributes documented here,
2441GCC plugins may provide their own attributes.
2442
2443@menu
2444* Common Function Attributes::
2445* AArch64 Function Attributes::
2446* AMD GCN Function Attributes::
2447* ARC Function Attributes::
2448* ARM Function Attributes::
2449* AVR Function Attributes::
2450* Blackfin Function Attributes::
2451* BPF Function Attributes::
2452* CR16 Function Attributes::
2453* C-SKY Function Attributes::
2454* Epiphany Function Attributes::
2455* H8/300 Function Attributes::
2456* IA-64 Function Attributes::
2457* M32C Function Attributes::
2458* M32R/D Function Attributes::
2459* m68k Function Attributes::
2460* MCORE Function Attributes::
2461* MeP Function Attributes::
2462* MicroBlaze Function Attributes::
2463* Microsoft Windows Function Attributes::
2464* MIPS Function Attributes::
2465* MSP430 Function Attributes::
2466* NDS32 Function Attributes::
2467* Nios II Function Attributes::
2468* Nvidia PTX Function Attributes::
2469* PowerPC Function Attributes::
2470* RISC-V Function Attributes::
2471* RL78 Function Attributes::
2472* RX Function Attributes::
2473* S/390 Function Attributes::
2474* SH Function Attributes::
2475* Symbian OS Function Attributes::
2476* V850 Function Attributes::
2477* Visium Function Attributes::
2478* x86 Function Attributes::
2479* Xstormy16 Function Attributes::
2480@end menu
2481
2482@node Common Function Attributes
2483@subsection Common Function Attributes
2484
2485The following attributes are supported on most targets.
2486
2487@table @code
2488@c Keep this table alphabetized by attribute name.  Treat _ as space.
2489
2490@item access
2491@itemx access (@var{access-mode}, @var{ref-index})
2492@itemx access (@var{access-mode}, @var{ref-index}, @var{size-index})
2493
2494The @code{access} attribute enables the detection of invalid or unsafe
2495accesses by functions to which they apply or their callers, as well as
2496write-only accesses to objects that are never read from.  Such accesses
2497may be diagnosed by warnings such as @option{-Wstringop-overflow},
2498@option{-Wuninitialized}, @option{-Wunused}, and others.
2499
2500The @code{access} attribute specifies that a function to whose by-reference
2501arguments the attribute applies accesses the referenced object according to
2502@var{access-mode}.  The @var{access-mode} argument is required and must be
2503one of four names: @code{read_only}, @code{read_write}, @code{write_only},
2504or @code{none}.  The remaining two are positional arguments.
2505
2506The required @var{ref-index} positional argument  denotes a function
2507argument of pointer (or in C++, reference) type that is subject to
2508the access.  The same pointer argument can be referenced by at most one
2509distinct @code{access} attribute.
2510
2511The optional @var{size-index} positional argument denotes a function
2512argument of integer type that specifies the maximum size of the access.
2513The size is the number of elements of the type referenced by @var{ref-index},
2514or the number of bytes when the pointer type is @code{void*}.  When no
2515@var{size-index} argument is specified, the pointer argument must be either
2516null or point to a space that is suitably aligned and large for at least one
2517object of the referenced type (this implies that a past-the-end pointer is
2518not a valid argument).  The actual size of the access may be less but it
2519must not be more.
2520
2521The @code{read_only} access mode specifies that the pointer to which it
2522applies is used to read the referenced object but not write to it.  Unless
2523the argument specifying the size of the access denoted by @var{size-index}
2524is zero, the referenced object must be initialized.  The mode implies
2525a stronger guarantee than the @code{const} qualifier which, when cast away
2526from a pointer, does not prevent the pointed-to object from being modified.
2527Examples of the use of the @code{read_only} access mode is the argument to
2528the @code{puts} function, or the second and third arguments to
2529the @code{memcpy} function.
2530
2531@smallexample
2532__attribute__ ((access (read_only, 1))) int puts (const char*);
2533__attribute__ ((access (read_only, 2, 3))) void* memcpy (void*, const void*, size_t);
2534@end smallexample
2535
2536The @code{read_write} access mode applies to arguments of pointer types
2537without the @code{const} qualifier.  It specifies that the pointer to which
2538it applies is used to both read and write the referenced object.  Unless
2539the argument specifying the size of the access denoted by @var{size-index}
2540is zero, the object referenced by the pointer must be initialized.  An example
2541of the use of the @code{read_write} access mode is the first argument to
2542the @code{strcat} function.
2543
2544@smallexample
2545__attribute__ ((access (read_write, 1), access (read_only, 2))) char* strcat (char*, const char*);
2546@end smallexample
2547
2548The @code{write_only} access mode applies to arguments of pointer types
2549without the @code{const} qualifier.  It specifies that the pointer to which
2550it applies is used to write to the referenced object but not read from it.
2551The object referenced by the pointer need not be initialized.  An example
2552of the use of the @code{write_only} access mode is the first argument to
2553the @code{strcpy} function, or the first two arguments to the @code{fgets}
2554function.
2555
2556@smallexample
2557__attribute__ ((access (write_only, 1), access (read_only, 2))) char* strcpy (char*, const char*);
2558__attribute__ ((access (write_only, 1, 2), access (read_write, 3))) int fgets (char*, int, FILE*);
2559@end smallexample
2560
2561The access mode @code{none} specifies that the pointer to which it applies
2562is not used to access the referenced object at all.  Unless the pointer is
2563null the pointed-to object must exist and have at least the size as denoted
2564by the @var{size-index} argument.  The object need not be initialized.
2565The mode is intended to be used as a means to help validate the expected
2566object size, for example in functions that call @code{__builtin_object_size}.
2567@xref{Object Size Checking}.
2568
2569@item alias ("@var{target}")
2570@cindex @code{alias} function attribute
2571The @code{alias} attribute causes the declaration to be emitted as an alias
2572for another symbol, which must have been previously declared with the same
2573type, and for variables, also the same size and alignment.  Declaring an alias
2574with a different type than the target is undefined and may be diagnosed.  As
2575an example, the following declarations:
2576
2577@smallexample
2578void __f () @{ /* @r{Do something.} */; @}
2579void f () __attribute__ ((weak, alias ("__f")));
2580@end smallexample
2581
2582@noindent
2583define @samp{f} to be a weak alias for @samp{__f}.  In C++, the mangled name
2584for the target must be used.  It is an error if @samp{__f} is not defined in
2585the same translation unit.
2586
2587This attribute requires assembler and object file support,
2588and may not be available on all targets.
2589
2590@item aligned
2591@itemx aligned (@var{alignment})
2592@cindex @code{aligned} function attribute
2593The @code{aligned} attribute specifies a minimum alignment for
2594the first instruction of the function, measured in bytes.  When specified,
2595@var{alignment} must be an integer constant power of 2.  Specifying no
2596@var{alignment} argument implies the ideal alignment for the target.
2597The @code{__alignof__} operator can be used to determine what that is
2598(@pxref{Alignment}).  The attribute has no effect when a definition for
2599the function is not provided in the same translation unit.
2600
2601The attribute cannot be used to decrease the alignment of a function
2602previously declared with a more restrictive alignment; only to increase
2603it.  Attempts to do otherwise are diagnosed.  Some targets specify
2604a minimum default alignment for functions that is greater than 1.  On
2605such targets, specifying a less restrictive alignment is silently ignored.
2606Using the attribute overrides the effect of the @option{-falign-functions}
2607(@pxref{Optimize Options}) option for this function.
2608
2609Note that the effectiveness of @code{aligned} attributes may be
2610limited by inherent limitations in the system linker
2611and/or object file format.  On some systems, the
2612linker is only able to arrange for functions to be aligned up to a
2613certain maximum alignment.  (For some linkers, the maximum supported
2614alignment may be very very small.)  See your linker documentation for
2615further information.
2616
2617The @code{aligned} attribute can also be used for variables and fields
2618(@pxref{Variable Attributes}.)
2619
2620@item alloc_align (@var{position})
2621@cindex @code{alloc_align} function attribute
2622The @code{alloc_align} attribute may be applied to a function that
2623returns a pointer and takes at least one argument of an integer or
2624enumerated type.
2625It indicates that the returned pointer is aligned on a boundary given
2626by the function argument at @var{position}.  Meaningful alignments are
2627powers of 2 greater than one.  GCC uses this information to improve
2628pointer alignment analysis.
2629
2630The function parameter denoting the allocated alignment is specified by
2631one constant integer argument whose number is the argument of the attribute.
2632Argument numbering starts at one.
2633
2634For instance,
2635
2636@smallexample
2637void* my_memalign (size_t, size_t) __attribute__ ((alloc_align (1)));
2638@end smallexample
2639
2640@noindent
2641declares that @code{my_memalign} returns memory with minimum alignment
2642given by parameter 1.
2643
2644@item alloc_size (@var{position})
2645@itemx alloc_size (@var{position-1}, @var{position-2})
2646@cindex @code{alloc_size} function attribute
2647The @code{alloc_size} attribute may be applied to a function that
2648returns a pointer and takes at least one argument of an integer or
2649enumerated type.
2650It indicates that the returned pointer points to memory whose size is
2651given by the function argument at @var{position-1}, or by the product
2652of the arguments at @var{position-1} and @var{position-2}.  Meaningful
2653sizes are positive values less than @code{PTRDIFF_MAX}.  GCC uses this
2654information to improve the results of @code{__builtin_object_size}.
2655
2656The function parameter(s) denoting the allocated size are specified by
2657one or two integer arguments supplied to the attribute.  The allocated size
2658is either the value of the single function argument specified or the product
2659of the two function arguments specified.  Argument numbering starts at
2660one for ordinary functions, and at two for C++ non-static member functions.
2661
2662For instance,
2663
2664@smallexample
2665void* my_calloc (size_t, size_t) __attribute__ ((alloc_size (1, 2)));
2666void* my_realloc (void*, size_t) __attribute__ ((alloc_size (2)));
2667@end smallexample
2668
2669@noindent
2670declares that @code{my_calloc} returns memory of the size given by
2671the product of parameter 1 and 2 and that @code{my_realloc} returns memory
2672of the size given by parameter 2.
2673
2674@item always_inline
2675@cindex @code{always_inline} function attribute
2676Generally, functions are not inlined unless optimization is specified.
2677For functions declared inline, this attribute inlines the function
2678independent of any restrictions that otherwise apply to inlining.
2679Failure to inline such a function is diagnosed as an error.
2680Note that if such a function is called indirectly the compiler may
2681or may not inline it depending on optimization level and a failure
2682to inline an indirect call may or may not be diagnosed.
2683
2684@item artificial
2685@cindex @code{artificial} function attribute
2686This attribute is useful for small inline wrappers that if possible
2687should appear during debugging as a unit.  Depending on the debug
2688info format it either means marking the function as artificial
2689or using the caller location for all instructions within the inlined
2690body.
2691
2692@item assume_aligned (@var{alignment})
2693@itemx assume_aligned (@var{alignment}, @var{offset})
2694@cindex @code{assume_aligned} function attribute
2695The @code{assume_aligned} attribute may be applied to a function that
2696returns a pointer.  It indicates that the returned pointer is aligned
2697on a boundary given by @var{alignment}.  If the attribute has two
2698arguments, the second argument is misalignment @var{offset}.  Meaningful
2699values of @var{alignment} are powers of 2 greater than one.  Meaningful
2700values of @var{offset} are greater than zero and less than @var{alignment}.
2701
2702For instance
2703
2704@smallexample
2705void* my_alloc1 (size_t) __attribute__((assume_aligned (16)));
2706void* my_alloc2 (size_t) __attribute__((assume_aligned (32, 8)));
2707@end smallexample
2708
2709@noindent
2710declares that @code{my_alloc1} returns 16-byte aligned pointers and
2711that @code{my_alloc2} returns a pointer whose value modulo 32 is equal
2712to 8.
2713
2714@item cold
2715@cindex @code{cold} function attribute
2716The @code{cold} attribute on functions is used to inform the compiler that
2717the function is unlikely to be executed.  The function is optimized for
2718size rather than speed and on many targets it is placed into a special
2719subsection of the text section so all cold functions appear close together,
2720improving code locality of non-cold parts of program.  The paths leading
2721to calls of cold functions within code are marked as unlikely by the branch
2722prediction mechanism.  It is thus useful to mark functions used to handle
2723unlikely conditions, such as @code{perror}, as cold to improve optimization
2724of hot functions that do call marked functions in rare occasions.
2725
2726When profile feedback is available, via @option{-fprofile-use}, cold functions
2727are automatically detected and this attribute is ignored.
2728
2729@item const
2730@cindex @code{const} function attribute
2731@cindex functions that have no side effects
2732Calls to functions whose return value is not affected by changes to
2733the observable state of the program and that have no observable effects
2734on such state other than to return a value may lend themselves to
2735optimizations such as common subexpression elimination.  Declaring such
2736functions with the @code{const} attribute allows GCC to avoid emitting
2737some calls in repeated invocations of the function with the same argument
2738values.
2739
2740For example,
2741
2742@smallexample
2743int square (int) __attribute__ ((const));
2744@end smallexample
2745
2746@noindent
2747tells GCC that subsequent calls to function @code{square} with the same
2748argument value can be replaced by the result of the first call regardless
2749of the statements in between.
2750
2751The @code{const} attribute prohibits a function from reading objects
2752that affect its return value between successive invocations.  However,
2753functions declared with the attribute can safely read objects that do
2754not change their return value, such as non-volatile constants.
2755
2756The @code{const} attribute imposes greater restrictions on a function's
2757definition than the similar @code{pure} attribute.  Declaring the same
2758function with both the @code{const} and the @code{pure} attribute is
2759diagnosed.  Because a const function cannot have any observable side
2760effects it does not make sense for it to return @code{void}.  Declaring
2761such a function is diagnosed.
2762
2763@cindex pointer arguments
2764Note that a function that has pointer arguments and examines the data
2765pointed to must @emph{not} be declared @code{const} if the pointed-to
2766data might change between successive invocations of the function.  In
2767general, since a function cannot distinguish data that might change
2768from data that cannot, const functions should never take pointer or,
2769in C++, reference arguments. Likewise, a function that calls a non-const
2770function usually must not be const itself.
2771
2772@item constructor
2773@itemx destructor
2774@itemx constructor (@var{priority})
2775@itemx destructor (@var{priority})
2776@cindex @code{constructor} function attribute
2777@cindex @code{destructor} function attribute
2778The @code{constructor} attribute causes the function to be called
2779automatically before execution enters @code{main ()}.  Similarly, the
2780@code{destructor} attribute causes the function to be called
2781automatically after @code{main ()} completes or @code{exit ()} is
2782called.  Functions with these attributes are useful for
2783initializing data that is used implicitly during the execution of
2784the program.
2785
2786On some targets the attributes also accept an integer argument to
2787specify a priority to control the order in which constructor and
2788destructor functions are run.  A constructor
2789with a smaller priority number runs before a constructor with a larger
2790priority number; the opposite relationship holds for destructors.  So,
2791if you have a constructor that allocates a resource and a destructor
2792that deallocates the same resource, both functions typically have the
2793same priority.  The priorities for constructor and destructor
2794functions are the same as those specified for namespace-scope C++
2795objects (@pxref{C++ Attributes}).  However, at present, the order in which
2796constructors for C++ objects with static storage duration and functions
2797decorated with attribute @code{constructor} are invoked is unspecified.
2798In mixed declarations, attribute @code{init_priority} can be used to
2799impose a specific ordering.
2800
2801Using the argument forms of the @code{constructor} and @code{destructor}
2802attributes on targets where the feature is not supported is rejected with
2803an error.
2804
2805@item copy
2806@itemx copy (@var{function})
2807@cindex @code{copy} function attribute
2808The @code{copy} attribute applies the set of attributes with which
2809@var{function} has been declared to the declaration of the function
2810to which the attribute is applied.  The attribute is designed for
2811libraries that define aliases or function resolvers that are expected
2812to specify the same set of attributes as their targets.  The @code{copy}
2813attribute can be used with functions, variables, or types.  However,
2814the kind of symbol to which the attribute is applied (either function
2815or variable) must match the kind of symbol to which the argument refers.
2816The @code{copy} attribute copies only syntactic and semantic attributes
2817but not attributes that affect a symbol's linkage or visibility such as
2818@code{alias}, @code{visibility}, or @code{weak}.  The @code{deprecated}
2819and @code{target_clones} attribute are also not copied.
2820@xref{Common Type Attributes}.
2821@xref{Common Variable Attributes}.
2822
2823For example, the @var{StrongAlias} macro below makes use of the @code{alias}
2824and @code{copy} attributes to define an alias named @var{alloc} for function
2825@var{allocate} declared with attributes @var{alloc_size}, @var{malloc}, and
2826@var{nothrow}.  Thanks to the @code{__typeof__} operator the alias has
2827the same type as the target function.  As a result of the @code{copy}
2828attribute the alias also shares the same attributes as the target.
2829
2830@smallexample
2831#define StrongAlias(TargetFunc, AliasDecl)  \
2832  extern __typeof__ (TargetFunc) AliasDecl  \
2833    __attribute__ ((alias (#TargetFunc), copy (TargetFunc)));
2834
2835extern __attribute__ ((alloc_size (1), malloc, nothrow))
2836  void* allocate (size_t);
2837StrongAlias (allocate, alloc);
2838@end smallexample
2839
2840@item deprecated
2841@itemx deprecated (@var{msg})
2842@cindex @code{deprecated} function attribute
2843The @code{deprecated} attribute results in a warning if the function
2844is used anywhere in the source file.  This is useful when identifying
2845functions that are expected to be removed in a future version of a
2846program.  The warning also includes the location of the declaration
2847of the deprecated function, to enable users to easily find further
2848information about why the function is deprecated, or what they should
2849do instead.  Note that the warnings only occurs for uses:
2850
2851@smallexample
2852int old_fn () __attribute__ ((deprecated));
2853int old_fn ();
2854int (*fn_ptr)() = old_fn;
2855@end smallexample
2856
2857@noindent
2858results in a warning on line 3 but not line 2.  The optional @var{msg}
2859argument, which must be a string, is printed in the warning if
2860present.
2861
2862The @code{deprecated} attribute can also be used for variables and
2863types (@pxref{Variable Attributes}, @pxref{Type Attributes}.)
2864
2865The message attached to the attribute is affected by the setting of
2866the @option{-fmessage-length} option.
2867
2868@item error ("@var{message}")
2869@itemx warning ("@var{message}")
2870@cindex @code{error} function attribute
2871@cindex @code{warning} function attribute
2872If the @code{error} or @code{warning} attribute
2873is used on a function declaration and a call to such a function
2874is not eliminated through dead code elimination or other optimizations,
2875an error or warning (respectively) that includes @var{message} is diagnosed.
2876This is useful
2877for compile-time checking, especially together with @code{__builtin_constant_p}
2878and inline functions where checking the inline function arguments is not
2879possible through @code{extern char [(condition) ? 1 : -1];} tricks.
2880
2881While it is possible to leave the function undefined and thus invoke
2882a link failure (to define the function with
2883a message in @code{.gnu.warning*} section),
2884when using these attributes the problem is diagnosed
2885earlier and with exact location of the call even in presence of inline
2886functions or when not emitting debugging information.
2887
2888@item externally_visible
2889@cindex @code{externally_visible} function attribute
2890This attribute, attached to a global variable or function, nullifies
2891the effect of the @option{-fwhole-program} command-line option, so the
2892object remains visible outside the current compilation unit.
2893
2894If @option{-fwhole-program} is used together with @option{-flto} and
2895@command{gold} is used as the linker plugin,
2896@code{externally_visible} attributes are automatically added to functions
2897(not variable yet due to a current @command{gold} issue)
2898that are accessed outside of LTO objects according to resolution file
2899produced by @command{gold}.
2900For other linkers that cannot generate resolution file,
2901explicit @code{externally_visible} attributes are still necessary.
2902
2903@item flatten
2904@cindex @code{flatten} function attribute
2905Generally, inlining into a function is limited.  For a function marked with
2906this attribute, every call inside this function is inlined, if possible.
2907Functions declared with attribute @code{noinline} and similar are not
2908inlined.  Whether the function itself is considered for inlining depends
2909on its size and the current inlining parameters.
2910
2911@item format (@var{archetype}, @var{string-index}, @var{first-to-check})
2912@cindex @code{format} function attribute
2913@cindex functions with @code{printf}, @code{scanf}, @code{strftime} or @code{strfmon} style arguments
2914@opindex Wformat
2915The @code{format} attribute specifies that a function takes @code{printf},
2916@code{scanf}, @code{strftime} or @code{strfmon} style arguments that
2917should be type-checked against a format string.  For example, the
2918declaration:
2919
2920@smallexample
2921extern int
2922my_printf (void *my_object, const char *my_format, ...)
2923      __attribute__ ((format (printf, 2, 3)));
2924@end smallexample
2925
2926@noindent
2927causes the compiler to check the arguments in calls to @code{my_printf}
2928for consistency with the @code{printf} style format string argument
2929@code{my_format}.
2930
2931The parameter @var{archetype} determines how the format string is
2932interpreted, and should be @code{printf}, @code{scanf}, @code{strftime},
2933@code{gnu_printf}, @code{gnu_scanf}, @code{gnu_strftime} or
2934@code{strfmon}.  (You can also use @code{__printf__},
2935@code{__scanf__}, @code{__strftime__} or @code{__strfmon__}.)  On
2936MinGW targets, @code{ms_printf}, @code{ms_scanf}, and
2937@code{ms_strftime} are also present.
2938@var{archetype} values such as @code{printf} refer to the formats accepted
2939by the system's C runtime library,
2940while values prefixed with @samp{gnu_} always refer
2941to the formats accepted by the GNU C Library.  On Microsoft Windows
2942targets, values prefixed with @samp{ms_} refer to the formats accepted by the
2943@file{msvcrt.dll} library.
2944The parameter @var{string-index}
2945specifies which argument is the format string argument (starting
2946from 1), while @var{first-to-check} is the number of the first
2947argument to check against the format string.  For functions
2948where the arguments are not available to be checked (such as
2949@code{vprintf}), specify the third parameter as zero.  In this case the
2950compiler only checks the format string for consistency.  For
2951@code{strftime} formats, the third parameter is required to be zero.
2952Since non-static C++ methods have an implicit @code{this} argument, the
2953arguments of such methods should be counted from two, not one, when
2954giving values for @var{string-index} and @var{first-to-check}.
2955
2956In the example above, the format string (@code{my_format}) is the second
2957argument of the function @code{my_print}, and the arguments to check
2958start with the third argument, so the correct parameters for the format
2959attribute are 2 and 3.
2960
2961@opindex ffreestanding
2962@opindex fno-builtin
2963The @code{format} attribute allows you to identify your own functions
2964that take format strings as arguments, so that GCC can check the
2965calls to these functions for errors.  The compiler always (unless
2966@option{-ffreestanding} or @option{-fno-builtin} is used) checks formats
2967for the standard library functions @code{printf}, @code{fprintf},
2968@code{sprintf}, @code{scanf}, @code{fscanf}, @code{sscanf}, @code{strftime},
2969@code{vprintf}, @code{vfprintf} and @code{vsprintf} whenever such
2970warnings are requested (using @option{-Wformat}), so there is no need to
2971modify the header file @file{stdio.h}.  In C99 mode, the functions
2972@code{snprintf}, @code{vsnprintf}, @code{vscanf}, @code{vfscanf} and
2973@code{vsscanf} are also checked.  Except in strictly conforming C
2974standard modes, the X/Open function @code{strfmon} is also checked as
2975are @code{printf_unlocked} and @code{fprintf_unlocked}.
2976@xref{C Dialect Options,,Options Controlling C Dialect}.
2977
2978For Objective-C dialects, @code{NSString} (or @code{__NSString__}) is
2979recognized in the same context.  Declarations including these format attributes
2980are parsed for correct syntax, however the result of checking of such format
2981strings is not yet defined, and is not carried out by this version of the
2982compiler.
2983
2984The target may also provide additional types of format checks.
2985@xref{Target Format Checks,,Format Checks Specific to Particular
2986Target Machines}.
2987
2988@item format_arg (@var{string-index})
2989@cindex @code{format_arg} function attribute
2990@opindex Wformat-nonliteral
2991The @code{format_arg} attribute specifies that a function takes one or
2992more format strings for a @code{printf}, @code{scanf}, @code{strftime} or
2993@code{strfmon} style function and modifies it (for example, to translate
2994it into another language), so the result can be passed to a
2995@code{printf}, @code{scanf}, @code{strftime} or @code{strfmon} style
2996function (with the remaining arguments to the format function the same
2997as they would have been for the unmodified string).  Multiple
2998@code{format_arg} attributes may be applied to the same function, each
2999designating a distinct parameter as a format string.  For example, the
3000declaration:
3001
3002@smallexample
3003extern char *
3004my_dgettext (char *my_domain, const char *my_format)
3005      __attribute__ ((format_arg (2)));
3006@end smallexample
3007
3008@noindent
3009causes the compiler to check the arguments in calls to a @code{printf},
3010@code{scanf}, @code{strftime} or @code{strfmon} type function, whose
3011format string argument is a call to the @code{my_dgettext} function, for
3012consistency with the format string argument @code{my_format}.  If the
3013@code{format_arg} attribute had not been specified, all the compiler
3014could tell in such calls to format functions would be that the format
3015string argument is not constant; this would generate a warning when
3016@option{-Wformat-nonliteral} is used, but the calls could not be checked
3017without the attribute.
3018
3019In calls to a function declared with more than one @code{format_arg}
3020attribute, each with a distinct argument value, the corresponding
3021actual function arguments are checked against all format strings
3022designated by the attributes.  This capability is designed to support
3023the GNU @code{ngettext} family of functions.
3024
3025The parameter @var{string-index} specifies which argument is the format
3026string argument (starting from one).  Since non-static C++ methods have
3027an implicit @code{this} argument, the arguments of such methods should
3028be counted from two.
3029
3030The @code{format_arg} attribute allows you to identify your own
3031functions that modify format strings, so that GCC can check the
3032calls to @code{printf}, @code{scanf}, @code{strftime} or @code{strfmon}
3033type function whose operands are a call to one of your own function.
3034The compiler always treats @code{gettext}, @code{dgettext}, and
3035@code{dcgettext} in this manner except when strict ISO C support is
3036requested by @option{-ansi} or an appropriate @option{-std} option, or
3037@option{-ffreestanding} or @option{-fno-builtin}
3038is used.  @xref{C Dialect Options,,Options
3039Controlling C Dialect}.
3040
3041For Objective-C dialects, the @code{format-arg} attribute may refer to an
3042@code{NSString} reference for compatibility with the @code{format} attribute
3043above.
3044
3045The target may also allow additional types in @code{format-arg} attributes.
3046@xref{Target Format Checks,,Format Checks Specific to Particular
3047Target Machines}.
3048
3049@item gnu_inline
3050@cindex @code{gnu_inline} function attribute
3051This attribute should be used with a function that is also declared
3052with the @code{inline} keyword.  It directs GCC to treat the function
3053as if it were defined in gnu90 mode even when compiling in C99 or
3054gnu99 mode.
3055
3056If the function is declared @code{extern}, then this definition of the
3057function is used only for inlining.  In no case is the function
3058compiled as a standalone function, not even if you take its address
3059explicitly.  Such an address becomes an external reference, as if you
3060had only declared the function, and had not defined it.  This has
3061almost the effect of a macro.  The way to use this is to put a
3062function definition in a header file with this attribute, and put
3063another copy of the function, without @code{extern}, in a library
3064file.  The definition in the header file causes most calls to the
3065function to be inlined.  If any uses of the function remain, they
3066refer to the single copy in the library.  Note that the two
3067definitions of the functions need not be precisely the same, although
3068if they do not have the same effect your program may behave oddly.
3069
3070In C, if the function is neither @code{extern} nor @code{static}, then
3071the function is compiled as a standalone function, as well as being
3072inlined where possible.
3073
3074This is how GCC traditionally handled functions declared
3075@code{inline}.  Since ISO C99 specifies a different semantics for
3076@code{inline}, this function attribute is provided as a transition
3077measure and as a useful feature in its own right.  This attribute is
3078available in GCC 4.1.3 and later.  It is available if either of the
3079preprocessor macros @code{__GNUC_GNU_INLINE__} or
3080@code{__GNUC_STDC_INLINE__} are defined.  @xref{Inline,,An Inline
3081Function is As Fast As a Macro}.
3082
3083In C++, this attribute does not depend on @code{extern} in any way,
3084but it still requires the @code{inline} keyword to enable its special
3085behavior.
3086
3087@item hot
3088@cindex @code{hot} function attribute
3089The @code{hot} attribute on a function is used to inform the compiler that
3090the function is a hot spot of the compiled program.  The function is
3091optimized more aggressively and on many targets it is placed into a special
3092subsection of the text section so all hot functions appear close together,
3093improving locality.
3094
3095When profile feedback is available, via @option{-fprofile-use}, hot functions
3096are automatically detected and this attribute is ignored.
3097
3098@item ifunc ("@var{resolver}")
3099@cindex @code{ifunc} function attribute
3100@cindex indirect functions
3101@cindex functions that are dynamically resolved
3102The @code{ifunc} attribute is used to mark a function as an indirect
3103function using the STT_GNU_IFUNC symbol type extension to the ELF
3104standard.  This allows the resolution of the symbol value to be
3105determined dynamically at load time, and an optimized version of the
3106routine to be selected for the particular processor or other system
3107characteristics determined then.  To use this attribute, first define
3108the implementation functions available, and a resolver function that
3109returns a pointer to the selected implementation function.  The
3110implementation functions' declarations must match the API of the
3111function being implemented.  The resolver should be declared to
3112be a function taking no arguments and returning a pointer to
3113a function of the same type as the implementation.  For example:
3114
3115@smallexample
3116void *my_memcpy (void *dst, const void *src, size_t len)
3117@{
3118  @dots{}
3119  return dst;
3120@}
3121
3122static void * (*resolve_memcpy (void))(void *, const void *, size_t)
3123@{
3124  return my_memcpy; // we will just always select this routine
3125@}
3126@end smallexample
3127
3128@noindent
3129The exported header file declaring the function the user calls would
3130contain:
3131
3132@smallexample
3133extern void *memcpy (void *, const void *, size_t);
3134@end smallexample
3135
3136@noindent
3137allowing the user to call @code{memcpy} as a regular function, unaware of
3138the actual implementation.  Finally, the indirect function needs to be
3139defined in the same translation unit as the resolver function:
3140
3141@smallexample
3142void *memcpy (void *, const void *, size_t)
3143     __attribute__ ((ifunc ("resolve_memcpy")));
3144@end smallexample
3145
3146In C++, the @code{ifunc} attribute takes a string that is the mangled name
3147of the resolver function.  A C++ resolver for a non-static member function
3148of class @code{C} should be declared to return a pointer to a non-member
3149function taking pointer to @code{C} as the first argument, followed by
3150the same arguments as of the implementation function.  G++ checks
3151the signatures of the two functions and issues
3152a @option{-Wattribute-alias} warning for mismatches.  To suppress a warning
3153for the necessary cast from a pointer to the implementation member function
3154to the type of the corresponding non-member function use
3155the @option{-Wno-pmf-conversions} option.  For example:
3156
3157@smallexample
3158class S
3159@{
3160private:
3161  int debug_impl (int);
3162  int optimized_impl (int);
3163
3164  typedef int Func (S*, int);
3165
3166  static Func* resolver ();
3167public:
3168
3169  int interface (int);
3170@};
3171
3172int S::debug_impl (int) @{ /* @r{@dots{}} */ @}
3173int S::optimized_impl (int) @{ /* @r{@dots{}} */ @}
3174
3175S::Func* S::resolver ()
3176@{
3177  int (S::*pimpl) (int)
3178    = getenv ("DEBUG") ? &S::debug_impl : &S::optimized_impl;
3179
3180  // Cast triggers -Wno-pmf-conversions.
3181  return reinterpret_cast<Func*>(pimpl);
3182@}
3183
3184int S::interface (int) __attribute__ ((ifunc ("_ZN1S8resolverEv")));
3185@end smallexample
3186
3187Indirect functions cannot be weak.  Binutils version 2.20.1 or higher
3188and GNU C Library version 2.11.1 are required to use this feature.
3189
3190@item interrupt
3191@itemx interrupt_handler
3192Many GCC back ends support attributes to indicate that a function is
3193an interrupt handler, which tells the compiler to generate function
3194entry and exit sequences that differ from those from regular
3195functions.  The exact syntax and behavior are target-specific;
3196refer to the following subsections for details.
3197
3198@item leaf
3199@cindex @code{leaf} function attribute
3200Calls to external functions with this attribute must return to the
3201current compilation unit only by return or by exception handling.  In
3202particular, a leaf function is not allowed to invoke callback functions
3203passed to it from the current compilation unit, directly call functions
3204exported by the unit, or @code{longjmp} into the unit.  Leaf functions
3205might still call functions from other compilation units and thus they
3206are not necessarily leaf in the sense that they contain no function
3207calls at all.
3208
3209The attribute is intended for library functions to improve dataflow
3210analysis.  The compiler takes the hint that any data not escaping the
3211current compilation unit cannot be used or modified by the leaf
3212function.  For example, the @code{sin} function is a leaf function, but
3213@code{qsort} is not.
3214
3215Note that leaf functions might indirectly run a signal handler defined
3216in the current compilation unit that uses static variables.  Similarly,
3217when lazy symbol resolution is in effect, leaf functions might invoke
3218indirect functions whose resolver function or implementation function is
3219defined in the current compilation unit and uses static variables.  There
3220is no standard-compliant way to write such a signal handler, resolver
3221function, or implementation function, and the best that you can do is to
3222remove the @code{leaf} attribute or mark all such static variables
3223@code{volatile}.  Lastly, for ELF-based systems that support symbol
3224interposition, care should be taken that functions defined in the
3225current compilation unit do not unexpectedly interpose other symbols
3226based on the defined standards mode and defined feature test macros;
3227otherwise an inadvertent callback would be added.
3228
3229The attribute has no effect on functions defined within the current
3230compilation unit.  This is to allow easy merging of multiple compilation
3231units into one, for example, by using the link-time optimization.  For
3232this reason the attribute is not allowed on types to annotate indirect
3233calls.
3234
3235@item malloc
3236@item malloc (@var{deallocator})
3237@item malloc (@var{deallocator}, @var{ptr-index})
3238@cindex @code{malloc} function attribute
3239@cindex functions that behave like malloc
3240Attribute @code{malloc} indicates that a function is @code{malloc}-like,
3241i.e., that the pointer @var{P} returned by the function cannot alias any
3242other pointer valid when the function returns, and moreover no
3243pointers to valid objects occur in any storage addressed by @var{P}. In
3244addition, the GCC predicts that a function with the attribute returns
3245non-null in most cases.
3246
3247Independently, the form of the attribute with one or two arguments
3248associates @code{deallocator} as a suitable deallocation function for
3249pointers returned from the @code{malloc}-like function.  @var{ptr-index}
3250denotes the positional argument to which when the pointer is passed in
3251calls to @code{deallocator} has the effect of deallocating it.
3252
3253Using the attribute with no arguments is designed to improve optimization
3254by relying on the aliasing property it implies.  Functions like @code{malloc}
3255and @code{calloc} have this property because they return a pointer to
3256uninitialized or zeroed-out, newly obtained storage.  However, functions
3257like @code{realloc} do not have this property, as they may return pointers
3258to storage containing pointers to existing objects.  Additionally, since
3259all such functions are assumed to return null only infrequently, callers
3260can be optimized based on that assumption.
3261
3262Associating a function with a @var{deallocator} helps detect calls to
3263mismatched allocation and deallocation functions and diagnose them under
3264the control of options such as @option{-Wmismatched-dealloc}.  It also
3265makes it possible to diagnose attempts to deallocate objects that were not
3266allocated dynamically, by @option{-Wfree-nonheap-object}.  To indicate
3267that an allocation function both satisifies the nonaliasing property and
3268has a deallocator associated with it, both the plain form of the attribute
3269and the one with the @var{deallocator} argument must be used.  The same
3270function can be both an allocator and a deallocator.  Since inlining one
3271of the associated functions but not the other could result in apparent
3272mismatches, this form of attribute @code{malloc} is not accepted on inline
3273functions.  For the same reason, using the attribute prevents both
3274the allocation and deallocation functions from being expanded inline.
3275
3276For example, besides stating that the functions return pointers that do
3277not alias any others, the following declarations make @code{fclose}
3278a suitable deallocator for pointers returned from all functions except
3279@code{popen}, and @code{pclose} as the only suitable deallocator for
3280pointers returned from @code{popen}.  The deallocator functions must
3281be declared before they can be referenced in the attribute.
3282
3283@smallexample
3284int fclose (FILE*);
3285int pclose (FILE*);
3286
3287__attribute__ ((malloc, malloc (fclose, 1)))
3288  FILE* fdopen (int, const char*);
3289__attribute__ ((malloc, malloc (fclose, 1)))
3290  FILE* fopen (const char*, const char*);
3291__attribute__ ((malloc, malloc (fclose, 1)))
3292  FILE* fmemopen(void *, size_t, const char *);
3293__attribute__ ((malloc, malloc (pclose, 1)))
3294  FILE* popen (const char*, const char*);
3295__attribute__ ((malloc, malloc (fclose, 1)))
3296  FILE* tmpfile (void);
3297@end smallexample
3298
3299The warnings guarded by @option{-fanalyzer} respect allocation and
3300deallocation pairs marked with the @code{malloc}.  In particular:
3301
3302@itemize @bullet
3303
3304@item
3305The analyzer will emit a @option{-Wanalyzer-mismatching-deallocation}
3306diagnostic if there is an execution path in which the result of an
3307allocation call is passed to a different deallocator.
3308
3309@item
3310The analyzer will emit a @option{-Wanalyzer-double-free}
3311diagnostic if there is an execution path in which a value is passed
3312more than once to a deallocation call.
3313
3314@item
3315The analyzer will consider the possibility that an allocation function
3316could fail and return NULL.  It will emit
3317@option{-Wanalyzer-possible-null-dereference} and
3318@option{-Wanalyzer-possible-null-argument} diagnostics if there are
3319execution paths in which an unchecked result of an allocation call is
3320dereferenced or passed to a function requiring a non-null argument.
3321If the allocator always returns non-null, use
3322@code{__attribute__ ((returns_nonnull))} to suppress these warnings.
3323For example:
3324@smallexample
3325char *xstrdup (const char *)
3326  __attribute__((malloc (free), returns_nonnull));
3327@end smallexample
3328
3329@item
3330The analyzer will emit a @option{-Wanalyzer-use-after-free}
3331diagnostic if there is an execution path in which the memory passed
3332by pointer to a deallocation call is used after the deallocation.
3333
3334@item
3335The analyzer will emit a @option{-Wanalyzer-malloc-leak} diagnostic if
3336there is an execution path in which the result of an allocation call
3337is leaked (without being passed to the deallocation function).
3338
3339@item
3340The analyzer will emit a @option{-Wanalyzer-free-of-non-heap} diagnostic
3341if a deallocation function is used on a global or on-stack variable.
3342
3343@end itemize
3344
3345The analyzer assumes that deallocators can gracefully handle the @code{NULL}
3346pointer.  If this is not the case, the deallocator can be marked with
3347@code{__attribute__((nonnull))} so that @option{-fanalyzer} can emit
3348a @option{-Wanalyzer-possible-null-argument} diagnostic for code paths
3349in which the deallocator is called with NULL.
3350
3351@item no_icf
3352@cindex @code{no_icf} function attribute
3353This function attribute prevents a functions from being merged with another
3354semantically equivalent function.
3355
3356@item no_instrument_function
3357@cindex @code{no_instrument_function} function attribute
3358@opindex finstrument-functions
3359@opindex p
3360@opindex pg
3361If any of @option{-finstrument-functions}, @option{-p}, or @option{-pg} are
3362given, profiling function calls are
3363generated at entry and exit of most user-compiled functions.
3364Functions with this attribute are not so instrumented.
3365
3366@item no_profile_instrument_function
3367@cindex @code{no_profile_instrument_function} function attribute
3368The @code{no_profile_instrument_function} attribute on functions is used
3369to inform the compiler that it should not process any profile feedback based
3370optimization code instrumentation.
3371
3372@item no_reorder
3373@cindex @code{no_reorder} function attribute
3374Do not reorder functions or variables marked @code{no_reorder}
3375against each other or top level assembler statements the executable.
3376The actual order in the program will depend on the linker command
3377line. Static variables marked like this are also not removed.
3378This has a similar effect
3379as the @option{-fno-toplevel-reorder} option, but only applies to the
3380marked symbols.
3381
3382@item no_sanitize ("@var{sanitize_option}")
3383@cindex @code{no_sanitize} function attribute
3384The @code{no_sanitize} attribute on functions is used
3385to inform the compiler that it should not do sanitization of any option
3386mentioned in @var{sanitize_option}.  A list of values acceptable by
3387the @option{-fsanitize} option can be provided.
3388
3389@smallexample
3390void __attribute__ ((no_sanitize ("alignment", "object-size")))
3391f () @{ /* @r{Do something.} */; @}
3392void __attribute__ ((no_sanitize ("alignment,object-size")))
3393g () @{ /* @r{Do something.} */; @}
3394@end smallexample
3395
3396@item no_sanitize_address
3397@itemx no_address_safety_analysis
3398@cindex @code{no_sanitize_address} function attribute
3399The @code{no_sanitize_address} attribute on functions is used
3400to inform the compiler that it should not instrument memory accesses
3401in the function when compiling with the @option{-fsanitize=address} option.
3402The @code{no_address_safety_analysis} is a deprecated alias of the
3403@code{no_sanitize_address} attribute, new code should use
3404@code{no_sanitize_address}.
3405
3406@item no_sanitize_thread
3407@cindex @code{no_sanitize_thread} function attribute
3408The @code{no_sanitize_thread} attribute on functions is used
3409to inform the compiler that it should not instrument memory accesses
3410in the function when compiling with the @option{-fsanitize=thread} option.
3411
3412@item no_sanitize_undefined
3413@cindex @code{no_sanitize_undefined} function attribute
3414The @code{no_sanitize_undefined} attribute on functions is used
3415to inform the compiler that it should not check for undefined behavior
3416in the function when compiling with the @option{-fsanitize=undefined} option.
3417
3418@item no_split_stack
3419@cindex @code{no_split_stack} function attribute
3420@opindex fsplit-stack
3421If @option{-fsplit-stack} is given, functions have a small
3422prologue which decides whether to split the stack.  Functions with the
3423@code{no_split_stack} attribute do not have that prologue, and thus
3424may run with only a small amount of stack space available.
3425
3426@item no_stack_limit
3427@cindex @code{no_stack_limit} function attribute
3428This attribute locally overrides the @option{-fstack-limit-register}
3429and @option{-fstack-limit-symbol} command-line options; it has the effect
3430of disabling stack limit checking in the function it applies to.
3431
3432@item noclone
3433@cindex @code{noclone} function attribute
3434This function attribute prevents a function from being considered for
3435cloning---a mechanism that produces specialized copies of functions
3436and which is (currently) performed by interprocedural constant
3437propagation.
3438
3439@item noinline
3440@cindex @code{noinline} function attribute
3441This function attribute prevents a function from being considered for
3442inlining.
3443@c Don't enumerate the optimizations by name here; we try to be
3444@c future-compatible with this mechanism.
3445If the function does not have side effects, there are optimizations
3446other than inlining that cause function calls to be optimized away,
3447although the function call is live.  To keep such calls from being
3448optimized away, put
3449@smallexample
3450asm ("");
3451@end smallexample
3452
3453@noindent
3454(@pxref{Extended Asm}) in the called function, to serve as a special
3455side effect.
3456
3457@item noipa
3458@cindex @code{noipa} function attribute
3459Disable interprocedural optimizations between the function with this
3460attribute and its callers, as if the body of the function is not available
3461when optimizing callers and the callers are unavailable when optimizing
3462the body.  This attribute implies @code{noinline}, @code{noclone} and
3463@code{no_icf} attributes.    However, this attribute is not equivalent
3464to a combination of other attributes, because its purpose is to suppress
3465existing and future optimizations employing interprocedural analysis,
3466including those that do not have an attribute suitable for disabling
3467them individually.  This attribute is supported mainly for the purpose
3468of testing the compiler.
3469
3470@item nonnull
3471@itemx nonnull (@var{arg-index}, @dots{})
3472@cindex @code{nonnull} function attribute
3473@cindex functions with non-null pointer arguments
3474The @code{nonnull} attribute may be applied to a function that takes at
3475least one argument of a pointer type.  It indicates that the referenced
3476arguments must be non-null pointers.  For instance, the declaration:
3477
3478@smallexample
3479extern void *
3480my_memcpy (void *dest, const void *src, size_t len)
3481        __attribute__((nonnull (1, 2)));
3482@end smallexample
3483
3484@noindent
3485causes the compiler to check that, in calls to @code{my_memcpy},
3486arguments @var{dest} and @var{src} are non-null.  If the compiler
3487determines that a null pointer is passed in an argument slot marked
3488as non-null, and the @option{-Wnonnull} option is enabled, a warning
3489is issued.  @xref{Warning Options}.  Unless disabled by
3490the @option{-fno-delete-null-pointer-checks} option the compiler may
3491also perform optimizations based on the knowledge that certain function
3492arguments cannot be null. In addition,
3493the @option{-fisolate-erroneous-paths-attribute} option can be specified
3494to have GCC transform calls with null arguments to non-null functions
3495into traps. @xref{Optimize Options}.
3496
3497If no @var{arg-index} is given to the @code{nonnull} attribute,
3498all pointer arguments are marked as non-null.  To illustrate, the
3499following declaration is equivalent to the previous example:
3500
3501@smallexample
3502extern void *
3503my_memcpy (void *dest, const void *src, size_t len)
3504        __attribute__((nonnull));
3505@end smallexample
3506
3507@item noplt
3508@cindex @code{noplt} function attribute
3509The @code{noplt} attribute is the counterpart to option @option{-fno-plt}.
3510Calls to functions marked with this attribute in position-independent code
3511do not use the PLT.
3512
3513@smallexample
3514@group
3515/* Externally defined function foo.  */
3516int foo () __attribute__ ((noplt));
3517
3518int
3519main (/* @r{@dots{}} */)
3520@{
3521  /* @r{@dots{}} */
3522  foo ();
3523  /* @r{@dots{}} */
3524@}
3525@end group
3526@end smallexample
3527
3528The @code{noplt} attribute on function @code{foo}
3529tells the compiler to assume that
3530the function @code{foo} is externally defined and that the call to
3531@code{foo} must avoid the PLT
3532in position-independent code.
3533
3534In position-dependent code, a few targets also convert calls to
3535functions that are marked to not use the PLT to use the GOT instead.
3536
3537@item noreturn
3538@cindex @code{noreturn} function attribute
3539@cindex functions that never return
3540A few standard library functions, such as @code{abort} and @code{exit},
3541cannot return.  GCC knows this automatically.  Some programs define
3542their own functions that never return.  You can declare them
3543@code{noreturn} to tell the compiler this fact.  For example,
3544
3545@smallexample
3546@group
3547void fatal () __attribute__ ((noreturn));
3548
3549void
3550fatal (/* @r{@dots{}} */)
3551@{
3552  /* @r{@dots{}} */ /* @r{Print error message.} */ /* @r{@dots{}} */
3553  exit (1);
3554@}
3555@end group
3556@end smallexample
3557
3558The @code{noreturn} keyword tells the compiler to assume that
3559@code{fatal} cannot return.  It can then optimize without regard to what
3560would happen if @code{fatal} ever did return.  This makes slightly
3561better code.  More importantly, it helps avoid spurious warnings of
3562uninitialized variables.
3563
3564The @code{noreturn} keyword does not affect the exceptional path when that
3565applies: a @code{noreturn}-marked function may still return to the caller
3566by throwing an exception or calling @code{longjmp}.
3567
3568In order to preserve backtraces, GCC will never turn calls to
3569@code{noreturn} functions into tail calls.
3570
3571Do not assume that registers saved by the calling function are
3572restored before calling the @code{noreturn} function.
3573
3574It does not make sense for a @code{noreturn} function to have a return
3575type other than @code{void}.
3576
3577@item nothrow
3578@cindex @code{nothrow} function attribute
3579The @code{nothrow} attribute is used to inform the compiler that a
3580function cannot throw an exception.  For example, most functions in
3581the standard C library can be guaranteed not to throw an exception
3582with the notable exceptions of @code{qsort} and @code{bsearch} that
3583take function pointer arguments.
3584
3585@item optimize (@var{level}, @dots{})
3586@item optimize (@var{string}, @dots{})
3587@cindex @code{optimize} function attribute
3588The @code{optimize} attribute is used to specify that a function is to
3589be compiled with different optimization options than specified on the
3590command line.  Valid arguments are constant non-negative integers and
3591strings.  Each numeric argument specifies an optimization @var{level}.
3592Each @var{string} argument consists of one or more comma-separated
3593substrings.  Each substring that begins with the letter @code{O} refers
3594to an optimization option such as @option{-O0} or @option{-Os}.  Other
3595substrings are taken as suffixes to the @code{-f} prefix jointly
3596forming the name of an optimization option.  @xref{Optimize Options}.
3597
3598@samp{#pragma GCC optimize} can be used to set optimization options
3599for more than one function.  @xref{Function Specific Option Pragmas},
3600for details about the pragma.
3601
3602Providing multiple strings as arguments separated by commas to specify
3603multiple options is equivalent to separating the option suffixes with
3604a comma (@samp{,}) within a single string.  Spaces are not permitted
3605within the strings.
3606
3607Not every optimization option that starts with the @var{-f} prefix
3608specified by the attribute necessarily has an effect on the function.
3609The @code{optimize} attribute should be used for debugging purposes only.
3610It is not suitable in production code.
3611
3612@item patchable_function_entry
3613@cindex @code{patchable_function_entry} function attribute
3614@cindex extra NOP instructions at the function entry point
3615In case the target's text segment can be made writable at run time by
3616any means, padding the function entry with a number of NOPs can be
3617used to provide a universal tool for instrumentation.
3618
3619The @code{patchable_function_entry} function attribute can be used to
3620change the number of NOPs to any desired value.  The two-value syntax
3621is the same as for the command-line switch
3622@option{-fpatchable-function-entry=N,M}, generating @var{N} NOPs, with
3623the function entry point before the @var{M}th NOP instruction.
3624@var{M} defaults to 0 if omitted e.g.@: function entry point is before
3625the first NOP.
3626
3627If patchable function entries are enabled globally using the command-line
3628option @option{-fpatchable-function-entry=N,M}, then you must disable
3629instrumentation on all functions that are part of the instrumentation
3630framework with the attribute @code{patchable_function_entry (0)}
3631to prevent recursion.
3632
3633@item pure
3634@cindex @code{pure} function attribute
3635@cindex functions that have no side effects
3636
3637Calls to functions that have no observable effects on the state of
3638the program other than to return a value may lend themselves to optimizations
3639such as common subexpression elimination.  Declaring such functions with
3640the @code{pure} attribute allows GCC to avoid emitting some calls in repeated
3641invocations of the function with the same argument values.
3642
3643The @code{pure} attribute prohibits a function from modifying the state
3644of the program that is observable by means other than inspecting
3645the function's return value.  However, functions declared with the @code{pure}
3646attribute can safely read any non-volatile objects, and modify the value of
3647objects in a way that does not affect their return value or the observable
3648state of the program.
3649
3650For example,
3651
3652@smallexample
3653int hash (char *) __attribute__ ((pure));
3654@end smallexample
3655
3656@noindent
3657tells GCC that subsequent calls to the function @code{hash} with the same
3658string can be replaced by the result of the first call provided the state
3659of the program observable by @code{hash}, including the contents of the array
3660itself, does not change in between.  Even though @code{hash} takes a non-const
3661pointer argument it must not modify the array it points to, or any other object
3662whose value the rest of the program may depend on.  However, the caller may
3663safely change the contents of the array between successive calls to
3664the function (doing so disables the optimization).  The restriction also
3665applies to member objects referenced by the @code{this} pointer in C++
3666non-static member functions.
3667
3668Some common examples of pure functions are @code{strlen} or @code{memcmp}.
3669Interesting non-pure functions are functions with infinite loops or those
3670depending on volatile memory or other system resource, that may change between
3671consecutive calls (such as the standard C @code{feof} function in
3672a multithreading environment).
3673
3674The @code{pure} attribute imposes similar but looser restrictions on
3675a function's definition than the @code{const} attribute: @code{pure}
3676allows the function to read any non-volatile memory, even if it changes
3677in between successive invocations of the function.  Declaring the same
3678function with both the @code{pure} and the @code{const} attribute is
3679diagnosed.  Because a pure function cannot have any observable side
3680effects it does not make sense for such a function to return @code{void}.
3681Declaring such a function is diagnosed.
3682
3683@item returns_nonnull
3684@cindex @code{returns_nonnull} function attribute
3685The @code{returns_nonnull} attribute specifies that the function
3686return value should be a non-null pointer.  For instance, the declaration:
3687
3688@smallexample
3689extern void *
3690mymalloc (size_t len) __attribute__((returns_nonnull));
3691@end smallexample
3692
3693@noindent
3694lets the compiler optimize callers based on the knowledge
3695that the return value will never be null.
3696
3697@item returns_twice
3698@cindex @code{returns_twice} function attribute
3699@cindex functions that return more than once
3700The @code{returns_twice} attribute tells the compiler that a function may
3701return more than one time.  The compiler ensures that all registers
3702are dead before calling such a function and emits a warning about
3703the variables that may be clobbered after the second return from the
3704function.  Examples of such functions are @code{setjmp} and @code{vfork}.
3705The @code{longjmp}-like counterpart of such function, if any, might need
3706to be marked with the @code{noreturn} attribute.
3707
3708@item section ("@var{section-name}")
3709@cindex @code{section} function attribute
3710@cindex functions in arbitrary sections
3711Normally, the compiler places the code it generates in the @code{text} section.
3712Sometimes, however, you need additional sections, or you need certain
3713particular functions to appear in special sections.  The @code{section}
3714attribute specifies that a function lives in a particular section.
3715For example, the declaration:
3716
3717@smallexample
3718extern void foobar (void) __attribute__ ((section ("bar")));
3719@end smallexample
3720
3721@noindent
3722puts the function @code{foobar} in the @code{bar} section.
3723
3724Some file formats do not support arbitrary sections so the @code{section}
3725attribute is not available on all platforms.
3726If you need to map the entire contents of a module to a particular
3727section, consider using the facilities of the linker instead.
3728
3729@item sentinel
3730@itemx sentinel (@var{position})
3731@cindex @code{sentinel} function attribute
3732This function attribute indicates that an argument in a call to the function
3733is expected to be an explicit @code{NULL}.  The attribute is only valid on
3734variadic functions.  By default, the sentinel is expected to be the last
3735argument of the function call.  If the optional @var{position} argument
3736is specified to the attribute, the sentinel must be located at
3737@var{position} counting backwards from the end of the argument list.
3738
3739@smallexample
3740__attribute__ ((sentinel))
3741is equivalent to
3742__attribute__ ((sentinel(0)))
3743@end smallexample
3744
3745The attribute is automatically set with a position of 0 for the built-in
3746functions @code{execl} and @code{execlp}.  The built-in function
3747@code{execle} has the attribute set with a position of 1.
3748
3749A valid @code{NULL} in this context is defined as zero with any object
3750pointer type.  If your system defines the @code{NULL} macro with
3751an integer type then you need to add an explicit cast.  During
3752installation GCC replaces the system @code{<stddef.h>} header with
3753a copy that redefines NULL appropriately.
3754
3755The warnings for missing or incorrect sentinels are enabled with
3756@option{-Wformat}.
3757
3758@item simd
3759@itemx simd("@var{mask}")
3760@cindex @code{simd} function attribute
3761This attribute enables creation of one or more function versions that
3762can process multiple arguments using SIMD instructions from a
3763single invocation.  Specifying this attribute allows compiler to
3764assume that such versions are available at link time (provided
3765in the same or another translation unit).  Generated versions are
3766target-dependent and described in the corresponding Vector ABI document.  For
3767x86_64 target this document can be found
3768@w{@uref{https://sourceware.org/glibc/wiki/libmvec?action=AttachFile&do=view&target=VectorABI.txt,here}}.
3769
3770The optional argument @var{mask} may have the value
3771@code{notinbranch} or @code{inbranch},
3772and instructs the compiler to generate non-masked or masked
3773clones correspondingly. By default, all clones are generated.
3774
3775If the attribute is specified and @code{#pragma omp declare simd} is
3776present on a declaration and the @option{-fopenmp} or @option{-fopenmp-simd}
3777switch is specified, then the attribute is ignored.
3778
3779@item stack_protect
3780@cindex @code{stack_protect} function attribute
3781This attribute adds stack protection code to the function if
3782flags @option{-fstack-protector}, @option{-fstack-protector-strong}
3783or @option{-fstack-protector-explicit} are set.
3784
3785@item no_stack_protector
3786@cindex @code{no_stack_protector} function attribute
3787This attribute prevents stack protection code for the function.
3788
3789@item target (@var{string}, @dots{})
3790@cindex @code{target} function attribute
3791Multiple target back ends implement the @code{target} attribute
3792to specify that a function is to
3793be compiled with different target options than specified on the
3794command line.  One or more strings can be provided as arguments.
3795Each string consists of one or more comma-separated suffixes to
3796the @code{-m} prefix jointly forming the name of a machine-dependent
3797option.  @xref{Submodel Options,,Machine-Dependent Options}.
3798
3799The @code{target} attribute can be used for instance to have a function
3800compiled with a different ISA (instruction set architecture) than the
3801default.  @samp{#pragma GCC target} can be used to specify target-specific
3802options for more than one function.  @xref{Function Specific Option Pragmas},
3803for details about the pragma.
3804
3805For instance, on an x86, you could declare one function with the
3806@code{target("sse4.1,arch=core2")} attribute and another with
3807@code{target("sse4a,arch=amdfam10")}.  This is equivalent to
3808compiling the first function with @option{-msse4.1} and
3809@option{-march=core2} options, and the second function with
3810@option{-msse4a} and @option{-march=amdfam10} options.  It is up to you
3811to make sure that a function is only invoked on a machine that
3812supports the particular ISA it is compiled for (for example by using
3813@code{cpuid} on x86 to determine what feature bits and architecture
3814family are used).
3815
3816@smallexample
3817int core2_func (void) __attribute__ ((__target__ ("arch=core2")));
3818int sse3_func (void) __attribute__ ((__target__ ("sse3")));
3819@end smallexample
3820
3821Providing multiple strings as arguments separated by commas to specify
3822multiple options is equivalent to separating the option suffixes with
3823a comma (@samp{,}) within a single string.  Spaces are not permitted
3824within the strings.
3825
3826The options supported are specific to each target; refer to @ref{x86
3827Function Attributes}, @ref{PowerPC Function Attributes},
3828@ref{ARM Function Attributes}, @ref{AArch64 Function Attributes},
3829@ref{Nios II Function Attributes}, and @ref{S/390 Function Attributes}
3830for details.
3831
3832@item symver ("@var{name2}@@@var{nodename}")
3833@cindex @code{symver} function attribute
3834On ELF targets this attribute creates a symbol version.  The @var{name2} part
3835of the parameter is the actual name of the symbol by which it will be
3836externally referenced.  The @code{nodename} portion should be the name of a
3837node specified in the version script supplied to the linker when building a
3838shared library.  Versioned symbol must be defined and must be exported with
3839default visibility.
3840
3841@smallexample
3842__attribute__ ((__symver__ ("foo@@VERS_1"))) int
3843foo_v1 (void)
3844@{
3845@}
3846@end smallexample
3847
3848Will produce a @code{.symver foo_v1, foo@@VERS_1} directive in the assembler
3849output.
3850
3851One can also define multiple version for a given symbol
3852(starting from binutils 2.35).
3853
3854@smallexample
3855__attribute__ ((__symver__ ("foo@@VERS_2"), __symver__ ("foo@@VERS_3")))
3856int symver_foo_v1 (void)
3857@{
3858@}
3859@end smallexample
3860
3861This example creates a symbol name @code{symver_foo_v1}
3862which will be version @code{VERS_2} and @code{VERS_3} of @code{foo}.
3863
3864If you have an older release of binutils, then symbol alias needs to
3865be used:
3866
3867@smallexample
3868__attribute__ ((__symver__ ("foo@@VERS_2")))
3869int foo_v1 (void)
3870@{
3871  return 0;
3872@}
3873
3874__attribute__ ((__symver__ ("foo@@VERS_3")))
3875__attribute__ ((alias ("foo_v1")))
3876int symver_foo_v1 (void);
3877@end smallexample
3878
3879Finally if the parameter is @code{"@var{name2}@@@@@var{nodename}"} then in
3880addition to creating a symbol version (as if
3881@code{"@var{name2}@@@var{nodename}"} was used) the version will be also used
3882to resolve @var{name2} by the linker.
3883
3884@item target_clones (@var{options})
3885@cindex @code{target_clones} function attribute
3886The @code{target_clones} attribute is used to specify that a function
3887be cloned into multiple versions compiled with different target options
3888than specified on the command line.  The supported options and restrictions
3889are the same as for @code{target} attribute.
3890
3891For instance, on an x86, you could compile a function with
3892@code{target_clones("sse4.1,avx")}.  GCC creates two function clones,
3893one compiled with @option{-msse4.1} and another with @option{-mavx}.
3894
3895On a PowerPC, you can compile a function with
3896@code{target_clones("cpu=power9,default")}.  GCC will create two
3897function clones, one compiled with @option{-mcpu=power9} and another
3898with the default options.  GCC must be configured to use GLIBC 2.23 or
3899newer in order to use the @code{target_clones} attribute.
3900
3901It also creates a resolver function (see
3902the @code{ifunc} attribute above) that dynamically selects a clone
3903suitable for current architecture.  The resolver is created only if there
3904is a usage of a function with @code{target_clones} attribute.
3905
3906Note that any subsequent call of a function without @code{target_clone}
3907from a @code{target_clone} caller will not lead to copying
3908(target clone) of the called function.
3909If you want to enforce such behaviour,
3910we recommend declaring the calling function with the @code{flatten} attribute?
3911
3912@item unused
3913@cindex @code{unused} function attribute
3914This attribute, attached to a function, means that the function is meant
3915to be possibly unused.  GCC does not produce a warning for this
3916function.
3917
3918@item used
3919@cindex @code{used} function attribute
3920This attribute, attached to a function, means that code must be emitted
3921for the function even if it appears that the function is not referenced.
3922This is useful, for example, when the function is referenced only in
3923inline assembly.
3924
3925When applied to a member function of a C++ class template, the
3926attribute also means that the function is instantiated if the
3927class itself is instantiated.
3928
3929@item retain
3930@cindex @code{retain} function attribute
3931For ELF targets that support the GNU or FreeBSD OSABIs, this attribute
3932will save the function from linker garbage collection.  To support
3933this behavior, functions that have not been placed in specific sections
3934(e.g. by the @code{section} attribute, or the @code{-ffunction-sections}
3935option), will be placed in new, unique sections.
3936
3937This additional functionality requires Binutils version 2.36 or later.
3938
3939@item visibility ("@var{visibility_type}")
3940@cindex @code{visibility} function attribute
3941This attribute affects the linkage of the declaration to which it is attached.
3942It can be applied to variables (@pxref{Common Variable Attributes}) and types
3943(@pxref{Common Type Attributes}) as well as functions.
3944
3945There are four supported @var{visibility_type} values: default,
3946hidden, protected or internal visibility.
3947
3948@smallexample
3949void __attribute__ ((visibility ("protected")))
3950f () @{ /* @r{Do something.} */; @}
3951int i __attribute__ ((visibility ("hidden")));
3952@end smallexample
3953
3954The possible values of @var{visibility_type} correspond to the
3955visibility settings in the ELF gABI.
3956
3957@table @code
3958@c keep this list of visibilities in alphabetical order.
3959
3960@item default
3961Default visibility is the normal case for the object file format.
3962This value is available for the visibility attribute to override other
3963options that may change the assumed visibility of entities.
3964
3965On ELF, default visibility means that the declaration is visible to other
3966modules and, in shared libraries, means that the declared entity may be
3967overridden.
3968
3969On Darwin, default visibility means that the declaration is visible to
3970other modules.
3971
3972Default visibility corresponds to ``external linkage'' in the language.
3973
3974@item hidden
3975Hidden visibility indicates that the entity declared has a new
3976form of linkage, which we call ``hidden linkage''.  Two
3977declarations of an object with hidden linkage refer to the same object
3978if they are in the same shared object.
3979
3980@item internal
3981Internal visibility is like hidden visibility, but with additional
3982processor specific semantics.  Unless otherwise specified by the
3983psABI, GCC defines internal visibility to mean that a function is
3984@emph{never} called from another module.  Compare this with hidden
3985functions which, while they cannot be referenced directly by other
3986modules, can be referenced indirectly via function pointers.  By
3987indicating that a function cannot be called from outside the module,
3988GCC may for instance omit the load of a PIC register since it is known
3989that the calling function loaded the correct value.
3990
3991@item protected
3992Protected visibility is like default visibility except that it
3993indicates that references within the defining module bind to the
3994definition in that module.  That is, the declared entity cannot be
3995overridden by another module.
3996
3997@end table
3998
3999All visibilities are supported on many, but not all, ELF targets
4000(supported when the assembler supports the @samp{.visibility}
4001pseudo-op).  Default visibility is supported everywhere.  Hidden
4002visibility is supported on Darwin targets.
4003
4004The visibility attribute should be applied only to declarations that
4005would otherwise have external linkage.  The attribute should be applied
4006consistently, so that the same entity should not be declared with
4007different settings of the attribute.
4008
4009In C++, the visibility attribute applies to types as well as functions
4010and objects, because in C++ types have linkage.  A class must not have
4011greater visibility than its non-static data member types and bases,
4012and class members default to the visibility of their class.  Also, a
4013declaration without explicit visibility is limited to the visibility
4014of its type.
4015
4016In C++, you can mark member functions and static member variables of a
4017class with the visibility attribute.  This is useful if you know a
4018particular method or static member variable should only be used from
4019one shared object; then you can mark it hidden while the rest of the
4020class has default visibility.  Care must be taken to avoid breaking
4021the One Definition Rule; for example, it is usually not useful to mark
4022an inline method as hidden without marking the whole class as hidden.
4023
4024A C++ namespace declaration can also have the visibility attribute.
4025
4026@smallexample
4027namespace nspace1 __attribute__ ((visibility ("protected")))
4028@{ /* @r{Do something.} */; @}
4029@end smallexample
4030
4031This attribute applies only to the particular namespace body, not to
4032other definitions of the same namespace; it is equivalent to using
4033@samp{#pragma GCC visibility} before and after the namespace
4034definition (@pxref{Visibility Pragmas}).
4035
4036In C++, if a template argument has limited visibility, this
4037restriction is implicitly propagated to the template instantiation.
4038Otherwise, template instantiations and specializations default to the
4039visibility of their template.
4040
4041If both the template and enclosing class have explicit visibility, the
4042visibility from the template is used.
4043
4044@item warn_unused_result
4045@cindex @code{warn_unused_result} function attribute
4046The @code{warn_unused_result} attribute causes a warning to be emitted
4047if a caller of the function with this attribute does not use its
4048return value.  This is useful for functions where not checking
4049the result is either a security problem or always a bug, such as
4050@code{realloc}.
4051
4052@smallexample
4053int fn () __attribute__ ((warn_unused_result));
4054int foo ()
4055@{
4056  if (fn () < 0) return -1;
4057  fn ();
4058  return 0;
4059@}
4060@end smallexample
4061
4062@noindent
4063results in warning on line 5.
4064
4065@item weak
4066@cindex @code{weak} function attribute
4067The @code{weak} attribute causes a declaration of an external symbol
4068to be emitted as a weak symbol rather than a global.  This is primarily
4069useful in defining library functions that can be overridden in user code,
4070though it can also be used with non-function declarations.  The overriding
4071symbol must have the same type as the weak symbol.  In addition, if it
4072designates a variable it must also have the same size and alignment as
4073the weak symbol.  Weak symbols are supported for ELF targets, and also
4074for a.out targets when using the GNU assembler and linker.
4075
4076@item weakref
4077@itemx weakref ("@var{target}")
4078@cindex @code{weakref} function attribute
4079The @code{weakref} attribute marks a declaration as a weak reference.
4080Without arguments, it should be accompanied by an @code{alias} attribute
4081naming the target symbol.  Alternatively, @var{target} may be given as
4082an argument to @code{weakref} itself, naming the target definition of
4083the alias.  The @var{target} must have the same type as the declaration.
4084In addition, if it designates a variable it must also have the same size
4085and alignment as the declaration.  In either form of the declaration
4086@code{weakref} implicitly marks the declared symbol as @code{weak}.  Without
4087a @var{target} given as an argument to @code{weakref} or to @code{alias},
4088@code{weakref} is equivalent to @code{weak} (in that case the declaration
4089may be @code{extern}).
4090
4091@smallexample
4092/* Given the declaration: */
4093extern int y (void);
4094
4095/* the following... */
4096static int x (void) __attribute__ ((weakref ("y")));
4097
4098/* is equivalent to... */
4099static int x (void) __attribute__ ((weakref, alias ("y")));
4100
4101/* or, alternatively, to... */
4102static int x (void) __attribute__ ((weakref));
4103static int x (void) __attribute__ ((alias ("y")));
4104@end smallexample
4105
4106A weak reference is an alias that does not by itself require a
4107definition to be given for the target symbol.  If the target symbol is
4108only referenced through weak references, then it becomes a @code{weak}
4109undefined symbol.  If it is directly referenced, however, then such
4110strong references prevail, and a definition is required for the
4111symbol, not necessarily in the same translation unit.
4112
4113The effect is equivalent to moving all references to the alias to a
4114separate translation unit, renaming the alias to the aliased symbol,
4115declaring it as weak, compiling the two separate translation units and
4116performing a link with relocatable output (i.e.@: @code{ld -r}) on them.
4117
4118A declaration to which @code{weakref} is attached and that is associated
4119with a named @code{target} must be @code{static}.
4120
4121@item zero_call_used_regs ("@var{choice}")
4122@cindex @code{zero_call_used_regs} function attribute
4123
4124The @code{zero_call_used_regs} attribute causes the compiler to zero
4125a subset of all call-used registers@footnote{A ``call-used'' register
4126is a register whose contents can be changed by a function call;
4127therefore, a caller cannot assume that the register has the same contents
4128on return from the function as it had before calling the function.  Such
4129registers are also called ``call-clobbered'', ``caller-saved'', or
4130``volatile''.} at function return.
4131This is used to increase program security by either mitigating
4132Return-Oriented Programming (ROP) attacks or preventing information leakage
4133through registers.
4134
4135In order to satisfy users with different security needs and control the
4136run-time overhead at the same time, the @var{choice} parameter provides a
4137flexible way to choose the subset of the call-used registers to be zeroed.
4138The three basic values of @var{choice} are:
4139
4140@itemize @bullet
4141@item
4142@samp{skip} doesn't zero any call-used registers.
4143
4144@item
4145@samp{used} only zeros call-used registers that are used in the function.
4146A ``used'' register is one whose content has been set or referenced in
4147the function.
4148
4149@item
4150@samp{all} zeros all call-used registers.
4151@end itemize
4152
4153In addition to these three basic choices, it is possible to modify
4154@samp{used} or @samp{all} as follows:
4155
4156@itemize @bullet
4157@item
4158Adding @samp{-gpr} restricts the zeroing to general-purpose registers.
4159
4160@item
4161Adding @samp{-arg} restricts the zeroing to registers that can sometimes
4162be used to pass function arguments.  This includes all argument registers
4163defined by the platform's calling conversion, regardless of whether the
4164function uses those registers for function arguments or not.
4165@end itemize
4166
4167The modifiers can be used individually or together.  If they are used
4168together, they must appear in the order above.
4169
4170The full list of @var{choice}s is therefore:
4171
4172@table @code
4173@item skip
4174doesn't zero any call-used register.
4175
4176@item used
4177only zeros call-used registers that are used in the function.
4178
4179@item used-gpr
4180only zeros call-used general purpose registers that are used in the function.
4181
4182@item used-arg
4183only zeros call-used registers that are used in the function and pass arguments.
4184
4185@item used-gpr-arg
4186only zeros call-used general purpose registers that are used in the function
4187and pass arguments.
4188
4189@item all
4190zeros all call-used registers.
4191
4192@item all-gpr
4193zeros all call-used general purpose registers.
4194
4195@item all-arg
4196zeros all call-used registers that pass arguments.
4197
4198@item all-gpr-arg
4199zeros all call-used general purpose registers that pass
4200arguments.
4201@end table
4202
4203Of this list, @samp{used-arg}, @samp{used-gpr-arg}, @samp{all-arg},
4204and @samp{all-gpr-arg} are mainly used for ROP mitigation.
4205
4206The default for the attribute is controlled by @option{-fzero-call-used-regs}.
4207@end table
4208
4209@c This is the end of the target-independent attribute table
4210
4211@node AArch64 Function Attributes
4212@subsection AArch64 Function Attributes
4213
4214The following target-specific function attributes are available for the
4215AArch64 target.  For the most part, these options mirror the behavior of
4216similar command-line options (@pxref{AArch64 Options}), but on a
4217per-function basis.
4218
4219@table @code
4220@item general-regs-only
4221@cindex @code{general-regs-only} function attribute, AArch64
4222Indicates that no floating-point or Advanced SIMD registers should be
4223used when generating code for this function.  If the function explicitly
4224uses floating-point code, then the compiler gives an error.  This is
4225the same behavior as that of the command-line option
4226@option{-mgeneral-regs-only}.
4227
4228@item fix-cortex-a53-835769
4229@cindex @code{fix-cortex-a53-835769} function attribute, AArch64
4230Indicates that the workaround for the Cortex-A53 erratum 835769 should be
4231applied to this function.  To explicitly disable the workaround for this
4232function specify the negated form: @code{no-fix-cortex-a53-835769}.
4233This corresponds to the behavior of the command line options
4234@option{-mfix-cortex-a53-835769} and @option{-mno-fix-cortex-a53-835769}.
4235
4236@item cmodel=
4237@cindex @code{cmodel=} function attribute, AArch64
4238Indicates that code should be generated for a particular code model for
4239this function.  The behavior and permissible arguments are the same as
4240for the command line option @option{-mcmodel=}.
4241
4242@item strict-align
4243@itemx no-strict-align
4244@cindex @code{strict-align} function attribute, AArch64
4245@code{strict-align} indicates that the compiler should not assume that unaligned
4246memory references are handled by the system.  To allow the compiler to assume
4247that aligned memory references are handled by the system, the inverse attribute
4248@code{no-strict-align} can be specified.  The behavior is same as for the
4249command-line option @option{-mstrict-align} and @option{-mno-strict-align}.
4250
4251@item omit-leaf-frame-pointer
4252@cindex @code{omit-leaf-frame-pointer} function attribute, AArch64
4253Indicates that the frame pointer should be omitted for a leaf function call.
4254To keep the frame pointer, the inverse attribute
4255@code{no-omit-leaf-frame-pointer} can be specified.  These attributes have
4256the same behavior as the command-line options @option{-momit-leaf-frame-pointer}
4257and @option{-mno-omit-leaf-frame-pointer}.
4258
4259@item tls-dialect=
4260@cindex @code{tls-dialect=} function attribute, AArch64
4261Specifies the TLS dialect to use for this function.  The behavior and
4262permissible arguments are the same as for the command-line option
4263@option{-mtls-dialect=}.
4264
4265@item arch=
4266@cindex @code{arch=} function attribute, AArch64
4267Specifies the architecture version and architectural extensions to use
4268for this function.  The behavior and permissible arguments are the same as
4269for the @option{-march=} command-line option.
4270
4271@item tune=
4272@cindex @code{tune=} function attribute, AArch64
4273Specifies the core for which to tune the performance of this function.
4274The behavior and permissible arguments are the same as for the @option{-mtune=}
4275command-line option.
4276
4277@item cpu=
4278@cindex @code{cpu=} function attribute, AArch64
4279Specifies the core for which to tune the performance of this function and also
4280whose architectural features to use.  The behavior and valid arguments are the
4281same as for the @option{-mcpu=} command-line option.
4282
4283@item sign-return-address
4284@cindex @code{sign-return-address} function attribute, AArch64
4285Select the function scope on which return address signing will be applied.  The
4286behavior and permissible arguments are the same as for the command-line option
4287@option{-msign-return-address=}.  The default value is @code{none}.  This
4288attribute is deprecated.  The @code{branch-protection} attribute should
4289be used instead.
4290
4291@item branch-protection
4292@cindex @code{branch-protection} function attribute, AArch64
4293Select the function scope on which branch protection will be applied.  The
4294behavior and permissible arguments are the same as for the command-line option
4295@option{-mbranch-protection=}.  The default value is @code{none}.
4296
4297@item outline-atomics
4298@cindex @code{outline-atomics} function attribute, AArch64
4299Enable or disable calls to out-of-line helpers to implement atomic operations.
4300This corresponds to the behavior of the command line options
4301@option{-moutline-atomics} and @option{-mno-outline-atomics}.
4302
4303@end table
4304
4305The above target attributes can be specified as follows:
4306
4307@smallexample
4308__attribute__((target("@var{attr-string}")))
4309int
4310f (int a)
4311@{
4312  return a + 5;
4313@}
4314@end smallexample
4315
4316where @code{@var{attr-string}} is one of the attribute strings specified above.
4317
4318Additionally, the architectural extension string may be specified on its
4319own.  This can be used to turn on and off particular architectural extensions
4320without having to specify a particular architecture version or core.  Example:
4321
4322@smallexample
4323__attribute__((target("+crc+nocrypto")))
4324int
4325foo (int a)
4326@{
4327  return a + 5;
4328@}
4329@end smallexample
4330
4331In this example @code{target("+crc+nocrypto")} enables the @code{crc}
4332extension and disables the @code{crypto} extension for the function @code{foo}
4333without modifying an existing @option{-march=} or @option{-mcpu} option.
4334
4335Multiple target function attributes can be specified by separating them with
4336a comma.  For example:
4337@smallexample
4338__attribute__((target("arch=armv8-a+crc+crypto,tune=cortex-a53")))
4339int
4340foo (int a)
4341@{
4342  return a + 5;
4343@}
4344@end smallexample
4345
4346is valid and compiles function @code{foo} for ARMv8-A with @code{crc}
4347and @code{crypto} extensions and tunes it for @code{cortex-a53}.
4348
4349@subsubsection Inlining rules
4350Specifying target attributes on individual functions or performing link-time
4351optimization across translation units compiled with different target options
4352can affect function inlining rules:
4353
4354In particular, a caller function can inline a callee function only if the
4355architectural features available to the callee are a subset of the features
4356available to the caller.
4357For example: A function @code{foo} compiled with @option{-march=armv8-a+crc},
4358or tagged with the equivalent @code{arch=armv8-a+crc} attribute,
4359can inline a function @code{bar} compiled with @option{-march=armv8-a+nocrc}
4360because the all the architectural features that function @code{bar} requires
4361are available to function @code{foo}.  Conversely, function @code{bar} cannot
4362inline function @code{foo}.
4363
4364Additionally inlining a function compiled with @option{-mstrict-align} into a
4365function compiled without @code{-mstrict-align} is not allowed.
4366However, inlining a function compiled without @option{-mstrict-align} into a
4367function compiled with @option{-mstrict-align} is allowed.
4368
4369Note that CPU tuning options and attributes such as the @option{-mcpu=},
4370@option{-mtune=} do not inhibit inlining unless the CPU specified by the
4371@option{-mcpu=} option or the @code{cpu=} attribute conflicts with the
4372architectural feature rules specified above.
4373
4374@node AMD GCN Function Attributes
4375@subsection AMD GCN Function Attributes
4376
4377These function attributes are supported by the AMD GCN back end:
4378
4379@table @code
4380@item amdgpu_hsa_kernel
4381@cindex @code{amdgpu_hsa_kernel} function attribute, AMD GCN
4382This attribute indicates that the corresponding function should be compiled as
4383a kernel function, that is an entry point that can be invoked from the host
4384via the HSA runtime library.  By default functions are only callable only from
4385other GCN functions.
4386
4387This attribute is implicitly applied to any function named @code{main}, using
4388default parameters.
4389
4390Kernel functions may return an integer value, which will be written to a
4391conventional place within the HSA "kernargs" region.
4392
4393The attribute parameters configure what values are passed into the kernel
4394function by the GPU drivers, via the initial register state.  Some values are
4395used by the compiler, and therefore forced on.  Enabling other options may
4396break assumptions in the compiler and/or run-time libraries.
4397
4398@table @code
4399@item private_segment_buffer
4400Set @code{enable_sgpr_private_segment_buffer} flag.  Always on (required to
4401locate the stack).
4402
4403@item dispatch_ptr
4404Set @code{enable_sgpr_dispatch_ptr} flag.  Always on (required to locate the
4405launch dimensions).
4406
4407@item queue_ptr
4408Set @code{enable_sgpr_queue_ptr} flag.  Always on (required to convert address
4409spaces).
4410
4411@item kernarg_segment_ptr
4412Set @code{enable_sgpr_kernarg_segment_ptr} flag.  Always on (required to
4413locate the kernel arguments, "kernargs").
4414
4415@item dispatch_id
4416Set @code{enable_sgpr_dispatch_id} flag.
4417
4418@item flat_scratch_init
4419Set @code{enable_sgpr_flat_scratch_init} flag.
4420
4421@item private_segment_size
4422Set @code{enable_sgpr_private_segment_size} flag.
4423
4424@item grid_workgroup_count_X
4425Set @code{enable_sgpr_grid_workgroup_count_x} flag.  Always on (required to
4426use OpenACC/OpenMP).
4427
4428@item grid_workgroup_count_Y
4429Set @code{enable_sgpr_grid_workgroup_count_y} flag.
4430
4431@item grid_workgroup_count_Z
4432Set @code{enable_sgpr_grid_workgroup_count_z} flag.
4433
4434@item workgroup_id_X
4435Set @code{enable_sgpr_workgroup_id_x} flag.
4436
4437@item workgroup_id_Y
4438Set @code{enable_sgpr_workgroup_id_y} flag.
4439
4440@item workgroup_id_Z
4441Set @code{enable_sgpr_workgroup_id_z} flag.
4442
4443@item workgroup_info
4444Set @code{enable_sgpr_workgroup_info} flag.
4445
4446@item private_segment_wave_offset
4447Set @code{enable_sgpr_private_segment_wave_byte_offset} flag.  Always on
4448(required to locate the stack).
4449
4450@item work_item_id_X
4451Set @code{enable_vgpr_workitem_id} parameter.  Always on (can't be disabled).
4452
4453@item work_item_id_Y
4454Set @code{enable_vgpr_workitem_id} parameter.  Always on (required to enable
4455vectorization.)
4456
4457@item work_item_id_Z
4458Set @code{enable_vgpr_workitem_id} parameter.  Always on (required to use
4459OpenACC/OpenMP).
4460
4461@end table
4462@end table
4463
4464@node ARC Function Attributes
4465@subsection ARC Function Attributes
4466
4467These function attributes are supported by the ARC back end:
4468
4469@table @code
4470@item interrupt
4471@cindex @code{interrupt} function attribute, ARC
4472Use this attribute to indicate
4473that the specified function is an interrupt handler.  The compiler generates
4474function entry and exit sequences suitable for use in an interrupt handler
4475when this attribute is present.
4476
4477On the ARC, you must specify the kind of interrupt to be handled
4478in a parameter to the interrupt attribute like this:
4479
4480@smallexample
4481void f () __attribute__ ((interrupt ("ilink1")));
4482@end smallexample
4483
4484Permissible values for this parameter are: @w{@code{ilink1}} and
4485@w{@code{ilink2}} for ARCv1 architecture, and @w{@code{ilink}} and
4486@w{@code{firq}} for ARCv2 architecture.
4487
4488@item long_call
4489@itemx medium_call
4490@itemx short_call
4491@cindex @code{long_call} function attribute, ARC
4492@cindex @code{medium_call} function attribute, ARC
4493@cindex @code{short_call} function attribute, ARC
4494@cindex indirect calls, ARC
4495These attributes specify how a particular function is called.
4496These attributes override the
4497@option{-mlong-calls} and @option{-mmedium-calls} (@pxref{ARC Options})
4498command-line switches and @code{#pragma long_calls} settings.
4499
4500For ARC, a function marked with the @code{long_call} attribute is
4501always called using register-indirect jump-and-link instructions,
4502thereby enabling the called function to be placed anywhere within the
450332-bit address space.  A function marked with the @code{medium_call}
4504attribute will always be close enough to be called with an unconditional
4505branch-and-link instruction, which has a 25-bit offset from
4506the call site.  A function marked with the @code{short_call}
4507attribute will always be close enough to be called with a conditional
4508branch-and-link instruction, which has a 21-bit offset from
4509the call site.
4510
4511@item jli_always
4512@cindex @code{jli_always} function attribute, ARC
4513Forces a particular function to be called using @code{jli}
4514instruction.  The @code{jli} instruction makes use of a table stored
4515into @code{.jlitab} section, which holds the location of the functions
4516which are addressed using this instruction.
4517
4518@item jli_fixed
4519@cindex @code{jli_fixed} function attribute, ARC
4520Identical like the above one, but the location of the function in the
4521@code{jli} table is known and given as an attribute parameter.
4522
4523@item secure_call
4524@cindex @code{secure_call} function attribute, ARC
4525This attribute allows one to mark secure-code functions that are
4526callable from normal mode.  The location of the secure call function
4527into the @code{sjli} table needs to be passed as argument.
4528
4529@item naked
4530@cindex @code{naked} function attribute, ARC
4531This attribute allows the compiler to construct the requisite function
4532declaration, while allowing the body of the function to be assembly
4533code.  The specified function will not have prologue/epilogue
4534sequences generated by the compiler.  Only basic @code{asm} statements
4535can safely be included in naked functions (@pxref{Basic Asm}).  While
4536using extended @code{asm} or a mixture of basic @code{asm} and C code
4537may appear to work, they cannot be depended upon to work reliably and
4538are not supported.
4539
4540@end table
4541
4542@node ARM Function Attributes
4543@subsection ARM Function Attributes
4544
4545These function attributes are supported for ARM targets:
4546
4547@table @code
4548
4549@item general-regs-only
4550@cindex @code{general-regs-only} function attribute, ARM
4551Indicates that no floating-point or Advanced SIMD registers should be
4552used when generating code for this function.  If the function explicitly
4553uses floating-point code, then the compiler gives an error.  This is
4554the same behavior as that of the command-line option
4555@option{-mgeneral-regs-only}.
4556
4557@item interrupt
4558@cindex @code{interrupt} function attribute, ARM
4559Use this attribute to indicate
4560that the specified function is an interrupt handler.  The compiler generates
4561function entry and exit sequences suitable for use in an interrupt handler
4562when this attribute is present.
4563
4564You can specify the kind of interrupt to be handled by
4565adding an optional parameter to the interrupt attribute like this:
4566
4567@smallexample
4568void f () __attribute__ ((interrupt ("IRQ")));
4569@end smallexample
4570
4571@noindent
4572Permissible values for this parameter are: @code{IRQ}, @code{FIQ},
4573@code{SWI}, @code{ABORT} and @code{UNDEF}.
4574
4575On ARMv7-M the interrupt type is ignored, and the attribute means the function
4576may be called with a word-aligned stack pointer.
4577
4578@item isr
4579@cindex @code{isr} function attribute, ARM
4580Use this attribute on ARM to write Interrupt Service Routines. This is an
4581alias to the @code{interrupt} attribute above.
4582
4583@item long_call
4584@itemx short_call
4585@cindex @code{long_call} function attribute, ARM
4586@cindex @code{short_call} function attribute, ARM
4587@cindex indirect calls, ARM
4588These attributes specify how a particular function is called.
4589These attributes override the
4590@option{-mlong-calls} (@pxref{ARM Options})
4591command-line switch and @code{#pragma long_calls} settings.  For ARM, the
4592@code{long_call} attribute indicates that the function might be far
4593away from the call site and require a different (more expensive)
4594calling sequence.   The @code{short_call} attribute always places
4595the offset to the function from the call site into the @samp{BL}
4596instruction directly.
4597
4598@item naked
4599@cindex @code{naked} function attribute, ARM
4600This attribute allows the compiler to construct the
4601requisite function declaration, while allowing the body of the
4602function to be assembly code. The specified function will not have
4603prologue/epilogue sequences generated by the compiler. Only basic
4604@code{asm} statements can safely be included in naked functions
4605(@pxref{Basic Asm}). While using extended @code{asm} or a mixture of
4606basic @code{asm} and C code may appear to work, they cannot be
4607depended upon to work reliably and are not supported.
4608
4609@item pcs
4610@cindex @code{pcs} function attribute, ARM
4611
4612The @code{pcs} attribute can be used to control the calling convention
4613used for a function on ARM.  The attribute takes an argument that specifies
4614the calling convention to use.
4615
4616When compiling using the AAPCS ABI (or a variant of it) then valid
4617values for the argument are @code{"aapcs"} and @code{"aapcs-vfp"}.  In
4618order to use a variant other than @code{"aapcs"} then the compiler must
4619be permitted to use the appropriate co-processor registers (i.e., the
4620VFP registers must be available in order to use @code{"aapcs-vfp"}).
4621For example,
4622
4623@smallexample
4624/* Argument passed in r0, and result returned in r0+r1.  */
4625double f2d (float) __attribute__((pcs("aapcs")));
4626@end smallexample
4627
4628Variadic functions always use the @code{"aapcs"} calling convention and
4629the compiler rejects attempts to specify an alternative.
4630
4631@item target (@var{options})
4632@cindex @code{target} function attribute
4633As discussed in @ref{Common Function Attributes}, this attribute
4634allows specification of target-specific compilation options.
4635
4636On ARM, the following options are allowed:
4637
4638@table @samp
4639@item thumb
4640@cindex @code{target("thumb")} function attribute, ARM
4641Force code generation in the Thumb (T16/T32) ISA, depending on the
4642architecture level.
4643
4644@item arm
4645@cindex @code{target("arm")} function attribute, ARM
4646Force code generation in the ARM (A32) ISA.
4647
4648Functions from different modes can be inlined in the caller's mode.
4649
4650@item fpu=
4651@cindex @code{target("fpu=")} function attribute, ARM
4652Specifies the fpu for which to tune the performance of this function.
4653The behavior and permissible arguments are the same as for the @option{-mfpu=}
4654command-line option.
4655
4656@item arch=
4657@cindex @code{arch=} function attribute, ARM
4658Specifies the architecture version and architectural extensions to use
4659for this function.  The behavior and permissible arguments are the same as
4660for the @option{-march=} command-line option.
4661
4662The above target attributes can be specified as follows:
4663
4664@smallexample
4665__attribute__((target("arch=armv8-a+crc")))
4666int
4667f (int a)
4668@{
4669  return a + 5;
4670@}
4671@end smallexample
4672
4673Additionally, the architectural extension string may be specified on its
4674own.  This can be used to turn on and off particular architectural extensions
4675without having to specify a particular architecture version or core.  Example:
4676
4677@smallexample
4678__attribute__((target("+crc+nocrypto")))
4679int
4680foo (int a)
4681@{
4682  return a + 5;
4683@}
4684@end smallexample
4685
4686In this example @code{target("+crc+nocrypto")} enables the @code{crc}
4687extension and disables the @code{crypto} extension for the function @code{foo}
4688without modifying an existing @option{-march=} or @option{-mcpu} option.
4689
4690@end table
4691
4692@end table
4693
4694@node AVR Function Attributes
4695@subsection AVR Function Attributes
4696
4697These function attributes are supported by the AVR back end:
4698
4699@table @code
4700@item interrupt
4701@cindex @code{interrupt} function attribute, AVR
4702Use this attribute to indicate
4703that the specified function is an interrupt handler.  The compiler generates
4704function entry and exit sequences suitable for use in an interrupt handler
4705when this attribute is present.
4706
4707On the AVR, the hardware globally disables interrupts when an
4708interrupt is executed.  The first instruction of an interrupt handler
4709declared with this attribute is a @code{SEI} instruction to
4710re-enable interrupts.  See also the @code{signal} function attribute
4711that does not insert a @code{SEI} instruction.  If both @code{signal} and
4712@code{interrupt} are specified for the same function, @code{signal}
4713is silently ignored.
4714
4715@item naked
4716@cindex @code{naked} function attribute, AVR
4717This attribute allows the compiler to construct the
4718requisite function declaration, while allowing the body of the
4719function to be assembly code. The specified function will not have
4720prologue/epilogue sequences generated by the compiler. Only basic
4721@code{asm} statements can safely be included in naked functions
4722(@pxref{Basic Asm}). While using extended @code{asm} or a mixture of
4723basic @code{asm} and C code may appear to work, they cannot be
4724depended upon to work reliably and are not supported.
4725
4726@item no_gccisr
4727@cindex @code{no_gccisr} function attribute, AVR
4728Do not use @code{__gcc_isr} pseudo instructions in a function with
4729the @code{interrupt} or @code{signal} attribute aka. interrupt
4730service routine (ISR).
4731Use this attribute if the preamble of the ISR prologue should always read
4732@example
4733push  __zero_reg__
4734push  __tmp_reg__
4735in    __tmp_reg__, __SREG__
4736push  __tmp_reg__
4737clr   __zero_reg__
4738@end example
4739and accordingly for the postamble of the epilogue --- no matter whether
4740the mentioned registers are actually used in the ISR or not.
4741Situations where you might want to use this attribute include:
4742@itemize @bullet
4743@item
4744Code that (effectively) clobbers bits of @code{SREG} other than the
4745@code{I}-flag by writing to the memory location of @code{SREG}.
4746@item
4747Code that uses inline assembler to jump to a different function which
4748expects (parts of) the prologue code as outlined above to be present.
4749@end itemize
4750To disable @code{__gcc_isr} generation for the whole compilation unit,
4751there is option @option{-mno-gas-isr-prologues}, @pxref{AVR Options}.
4752
4753@item OS_main
4754@itemx OS_task
4755@cindex @code{OS_main} function attribute, AVR
4756@cindex @code{OS_task} function attribute, AVR
4757On AVR, functions with the @code{OS_main} or @code{OS_task} attribute
4758do not save/restore any call-saved register in their prologue/epilogue.
4759
4760The @code{OS_main} attribute can be used when there @emph{is
4761guarantee} that interrupts are disabled at the time when the function
4762is entered.  This saves resources when the stack pointer has to be
4763changed to set up a frame for local variables.
4764
4765The @code{OS_task} attribute can be used when there is @emph{no
4766guarantee} that interrupts are disabled at that time when the function
4767is entered like for, e@.g@. task functions in a multi-threading operating
4768system. In that case, changing the stack pointer register is
4769guarded by save/clear/restore of the global interrupt enable flag.
4770
4771The differences to the @code{naked} function attribute are:
4772@itemize @bullet
4773@item @code{naked} functions do not have a return instruction whereas
4774@code{OS_main} and @code{OS_task} functions have a @code{RET} or
4775@code{RETI} return instruction.
4776@item @code{naked} functions do not set up a frame for local variables
4777or a frame pointer whereas @code{OS_main} and @code{OS_task} do this
4778as needed.
4779@end itemize
4780
4781@item signal
4782@cindex @code{signal} function attribute, AVR
4783Use this attribute on the AVR to indicate that the specified
4784function is an interrupt handler.  The compiler generates function
4785entry and exit sequences suitable for use in an interrupt handler when this
4786attribute is present.
4787
4788See also the @code{interrupt} function attribute.
4789
4790The AVR hardware globally disables interrupts when an interrupt is executed.
4791Interrupt handler functions defined with the @code{signal} attribute
4792do not re-enable interrupts.  It is save to enable interrupts in a
4793@code{signal} handler.  This ``save'' only applies to the code
4794generated by the compiler and not to the IRQ layout of the
4795application which is responsibility of the application.
4796
4797If both @code{signal} and @code{interrupt} are specified for the same
4798function, @code{signal} is silently ignored.
4799@end table
4800
4801@node Blackfin Function Attributes
4802@subsection Blackfin Function Attributes
4803
4804These function attributes are supported by the Blackfin back end:
4805
4806@table @code
4807
4808@item exception_handler
4809@cindex @code{exception_handler} function attribute
4810@cindex exception handler functions, Blackfin
4811Use this attribute on the Blackfin to indicate that the specified function
4812is an exception handler.  The compiler generates function entry and
4813exit sequences suitable for use in an exception handler when this
4814attribute is present.
4815
4816@item interrupt_handler
4817@cindex @code{interrupt_handler} function attribute, Blackfin
4818Use this attribute to
4819indicate that the specified function is an interrupt handler.  The compiler
4820generates function entry and exit sequences suitable for use in an
4821interrupt handler when this attribute is present.
4822
4823@item kspisusp
4824@cindex @code{kspisusp} function attribute, Blackfin
4825@cindex User stack pointer in interrupts on the Blackfin
4826When used together with @code{interrupt_handler}, @code{exception_handler}
4827or @code{nmi_handler}, code is generated to load the stack pointer
4828from the USP register in the function prologue.
4829
4830@item l1_text
4831@cindex @code{l1_text} function attribute, Blackfin
4832This attribute specifies a function to be placed into L1 Instruction
4833SRAM@. The function is put into a specific section named @code{.l1.text}.
4834With @option{-mfdpic}, function calls with a such function as the callee
4835or caller uses inlined PLT.
4836
4837@item l2
4838@cindex @code{l2} function attribute, Blackfin
4839This attribute specifies a function to be placed into L2
4840SRAM. The function is put into a specific section named
4841@code{.l2.text}. With @option{-mfdpic}, callers of such functions use
4842an inlined PLT.
4843
4844@item longcall
4845@itemx shortcall
4846@cindex indirect calls, Blackfin
4847@cindex @code{longcall} function attribute, Blackfin
4848@cindex @code{shortcall} function attribute, Blackfin
4849The @code{longcall} attribute
4850indicates that the function might be far away from the call site and
4851require a different (more expensive) calling sequence.  The
4852@code{shortcall} attribute indicates that the function is always close
4853enough for the shorter calling sequence to be used.  These attributes
4854override the @option{-mlongcall} switch.
4855
4856@item nesting
4857@cindex @code{nesting} function attribute, Blackfin
4858@cindex Allow nesting in an interrupt handler on the Blackfin processor
4859Use this attribute together with @code{interrupt_handler},
4860@code{exception_handler} or @code{nmi_handler} to indicate that the function
4861entry code should enable nested interrupts or exceptions.
4862
4863@item nmi_handler
4864@cindex @code{nmi_handler} function attribute, Blackfin
4865@cindex NMI handler functions on the Blackfin processor
4866Use this attribute on the Blackfin to indicate that the specified function
4867is an NMI handler.  The compiler generates function entry and
4868exit sequences suitable for use in an NMI handler when this
4869attribute is present.
4870
4871@item saveall
4872@cindex @code{saveall} function attribute, Blackfin
4873@cindex save all registers on the Blackfin
4874Use this attribute to indicate that
4875all registers except the stack pointer should be saved in the prologue
4876regardless of whether they are used or not.
4877@end table
4878
4879@node BPF Function Attributes
4880@subsection BPF Function Attributes
4881
4882These function attributes are supported by the BPF back end:
4883
4884@table @code
4885@item kernel_helper
4886@cindex @code{kernel helper}, function attribute, BPF
4887use this attribute to indicate the specified function declaration is a
4888kernel helper.  The helper function is passed as an argument to the
4889attribute.  Example:
4890
4891@smallexample
4892int bpf_probe_read (void *dst, int size, const void *unsafe_ptr)
4893  __attribute__ ((kernel_helper (4)));
4894@end smallexample
4895@end table
4896
4897@node CR16 Function Attributes
4898@subsection CR16 Function Attributes
4899
4900These function attributes are supported by the CR16 back end:
4901
4902@table @code
4903@item interrupt
4904@cindex @code{interrupt} function attribute, CR16
4905Use this attribute to indicate
4906that the specified function is an interrupt handler.  The compiler generates
4907function entry and exit sequences suitable for use in an interrupt handler
4908when this attribute is present.
4909@end table
4910
4911@node C-SKY Function Attributes
4912@subsection C-SKY Function Attributes
4913
4914These function attributes are supported by the C-SKY back end:
4915
4916@table @code
4917@item interrupt
4918@itemx isr
4919@cindex @code{interrupt} function attribute, C-SKY
4920@cindex @code{isr} function attribute, C-SKY
4921Use these attributes to indicate that the specified function
4922is an interrupt handler.
4923The compiler generates function entry and exit sequences suitable for
4924use in an interrupt handler when either of these attributes are present.
4925
4926Use of these options requires the @option{-mistack} command-line option
4927to enable support for the necessary interrupt stack instructions.  They
4928are ignored with a warning otherwise.  @xref{C-SKY Options}.
4929
4930@item naked
4931@cindex @code{naked} function attribute, C-SKY
4932This attribute allows the compiler to construct the
4933requisite function declaration, while allowing the body of the
4934function to be assembly code. The specified function will not have
4935prologue/epilogue sequences generated by the compiler. Only basic
4936@code{asm} statements can safely be included in naked functions
4937(@pxref{Basic Asm}). While using extended @code{asm} or a mixture of
4938basic @code{asm} and C code may appear to work, they cannot be
4939depended upon to work reliably and are not supported.
4940@end table
4941
4942
4943@node Epiphany Function Attributes
4944@subsection Epiphany Function Attributes
4945
4946These function attributes are supported by the Epiphany back end:
4947
4948@table @code
4949@item disinterrupt
4950@cindex @code{disinterrupt} function attribute, Epiphany
4951This attribute causes the compiler to emit
4952instructions to disable interrupts for the duration of the given
4953function.
4954
4955@item forwarder_section
4956@cindex @code{forwarder_section} function attribute, Epiphany
4957This attribute modifies the behavior of an interrupt handler.
4958The interrupt handler may be in external memory which cannot be
4959reached by a branch instruction, so generate a local memory trampoline
4960to transfer control.  The single parameter identifies the section where
4961the trampoline is placed.
4962
4963@item interrupt
4964@cindex @code{interrupt} function attribute, Epiphany
4965Use this attribute to indicate
4966that the specified function is an interrupt handler.  The compiler generates
4967function entry and exit sequences suitable for use in an interrupt handler
4968when this attribute is present.  It may also generate
4969a special section with code to initialize the interrupt vector table.
4970
4971On Epiphany targets one or more optional parameters can be added like this:
4972
4973@smallexample
4974void __attribute__ ((interrupt ("dma0, dma1"))) universal_dma_handler ();
4975@end smallexample
4976
4977Permissible values for these parameters are: @w{@code{reset}},
4978@w{@code{software_exception}}, @w{@code{page_miss}},
4979@w{@code{timer0}}, @w{@code{timer1}}, @w{@code{message}},
4980@w{@code{dma0}}, @w{@code{dma1}}, @w{@code{wand}} and @w{@code{swi}}.
4981Multiple parameters indicate that multiple entries in the interrupt
4982vector table should be initialized for this function, i.e.@: for each
4983parameter @w{@var{name}}, a jump to the function is emitted in
4984the section @w{ivt_entry_@var{name}}.  The parameter(s) may be omitted
4985entirely, in which case no interrupt vector table entry is provided.
4986
4987Note that interrupts are enabled inside the function
4988unless the @code{disinterrupt} attribute is also specified.
4989
4990The following examples are all valid uses of these attributes on
4991Epiphany targets:
4992@smallexample
4993void __attribute__ ((interrupt)) universal_handler ();
4994void __attribute__ ((interrupt ("dma1"))) dma1_handler ();
4995void __attribute__ ((interrupt ("dma0, dma1")))
4996  universal_dma_handler ();
4997void __attribute__ ((interrupt ("timer0"), disinterrupt))
4998  fast_timer_handler ();
4999void __attribute__ ((interrupt ("dma0, dma1"),
5000                     forwarder_section ("tramp")))
5001  external_dma_handler ();
5002@end smallexample
5003
5004@item long_call
5005@itemx short_call
5006@cindex @code{long_call} function attribute, Epiphany
5007@cindex @code{short_call} function attribute, Epiphany
5008@cindex indirect calls, Epiphany
5009These attributes specify how a particular function is called.
5010These attributes override the
5011@option{-mlong-calls} (@pxref{Adapteva Epiphany Options})
5012command-line switch and @code{#pragma long_calls} settings.
5013@end table
5014
5015
5016@node H8/300 Function Attributes
5017@subsection H8/300 Function Attributes
5018
5019These function attributes are available for H8/300 targets:
5020
5021@table @code
5022@item function_vector
5023@cindex @code{function_vector} function attribute, H8/300
5024Use this attribute on the H8/300, H8/300H, and H8S to indicate
5025that the specified function should be called through the function vector.
5026Calling a function through the function vector reduces code size; however,
5027the function vector has a limited size (maximum 128 entries on the H8/300
5028and 64 entries on the H8/300H and H8S)
5029and shares space with the interrupt vector.
5030
5031@item interrupt_handler
5032@cindex @code{interrupt_handler} function attribute, H8/300
5033Use this attribute on the H8/300, H8/300H, and H8S to
5034indicate that the specified function is an interrupt handler.  The compiler
5035generates function entry and exit sequences suitable for use in an
5036interrupt handler when this attribute is present.
5037
5038@item saveall
5039@cindex @code{saveall} function attribute, H8/300
5040@cindex save all registers on the H8/300, H8/300H, and H8S
5041Use this attribute on the H8/300, H8/300H, and H8S to indicate that
5042all registers except the stack pointer should be saved in the prologue
5043regardless of whether they are used or not.
5044@end table
5045
5046@node IA-64 Function Attributes
5047@subsection IA-64 Function Attributes
5048
5049These function attributes are supported on IA-64 targets:
5050
5051@table @code
5052@item syscall_linkage
5053@cindex @code{syscall_linkage} function attribute, IA-64
5054This attribute is used to modify the IA-64 calling convention by marking
5055all input registers as live at all function exits.  This makes it possible
5056to restart a system call after an interrupt without having to save/restore
5057the input registers.  This also prevents kernel data from leaking into
5058application code.
5059
5060@item version_id
5061@cindex @code{version_id} function attribute, IA-64
5062This IA-64 HP-UX attribute, attached to a global variable or function, renames a
5063symbol to contain a version string, thus allowing for function level
5064versioning.  HP-UX system header files may use function level versioning
5065for some system calls.
5066
5067@smallexample
5068extern int foo () __attribute__((version_id ("20040821")));
5069@end smallexample
5070
5071@noindent
5072Calls to @code{foo} are mapped to calls to @code{foo@{20040821@}}.
5073@end table
5074
5075@node M32C Function Attributes
5076@subsection M32C Function Attributes
5077
5078These function attributes are supported by the M32C back end:
5079
5080@table @code
5081@item bank_switch
5082@cindex @code{bank_switch} function attribute, M32C
5083When added to an interrupt handler with the M32C port, causes the
5084prologue and epilogue to use bank switching to preserve the registers
5085rather than saving them on the stack.
5086
5087@item fast_interrupt
5088@cindex @code{fast_interrupt} function attribute, M32C
5089Use this attribute on the M32C port to indicate that the specified
5090function is a fast interrupt handler.  This is just like the
5091@code{interrupt} attribute, except that @code{freit} is used to return
5092instead of @code{reit}.
5093
5094@item function_vector
5095@cindex @code{function_vector} function attribute, M16C/M32C
5096On M16C/M32C targets, the @code{function_vector} attribute declares a
5097special page subroutine call function. Use of this attribute reduces
5098the code size by 2 bytes for each call generated to the
5099subroutine. The argument to the attribute is the vector number entry
5100from the special page vector table which contains the 16 low-order
5101bits of the subroutine's entry address. Each vector table has special
5102page number (18 to 255) that is used in @code{jsrs} instructions.
5103Jump addresses of the routines are generated by adding 0x0F0000 (in
5104case of M16C targets) or 0xFF0000 (in case of M32C targets), to the
51052-byte addresses set in the vector table. Therefore you need to ensure
5106that all the special page vector routines should get mapped within the
5107address range 0x0F0000 to 0x0FFFFF (for M16C) and 0xFF0000 to 0xFFFFFF
5108(for M32C).
5109
5110In the following example 2 bytes are saved for each call to
5111function @code{foo}.
5112
5113@smallexample
5114void foo (void) __attribute__((function_vector(0x18)));
5115void foo (void)
5116@{
5117@}
5118
5119void bar (void)
5120@{
5121    foo();
5122@}
5123@end smallexample
5124
5125If functions are defined in one file and are called in another file,
5126then be sure to write this declaration in both files.
5127
5128This attribute is ignored for R8C target.
5129
5130@item interrupt
5131@cindex @code{interrupt} function attribute, M32C
5132Use this attribute to indicate
5133that the specified function is an interrupt handler.  The compiler generates
5134function entry and exit sequences suitable for use in an interrupt handler
5135when this attribute is present.
5136@end table
5137
5138@node M32R/D Function Attributes
5139@subsection M32R/D Function Attributes
5140
5141These function attributes are supported by the M32R/D back end:
5142
5143@table @code
5144@item interrupt
5145@cindex @code{interrupt} function attribute, M32R/D
5146Use this attribute to indicate
5147that the specified function is an interrupt handler.  The compiler generates
5148function entry and exit sequences suitable for use in an interrupt handler
5149when this attribute is present.
5150
5151@item model (@var{model-name})
5152@cindex @code{model} function attribute, M32R/D
5153@cindex function addressability on the M32R/D
5154
5155On the M32R/D, use this attribute to set the addressability of an
5156object, and of the code generated for a function.  The identifier
5157@var{model-name} is one of @code{small}, @code{medium}, or
5158@code{large}, representing each of the code models.
5159
5160Small model objects live in the lower 16MB of memory (so that their
5161addresses can be loaded with the @code{ld24} instruction), and are
5162callable with the @code{bl} instruction.
5163
5164Medium model objects may live anywhere in the 32-bit address space (the
5165compiler generates @code{seth/add3} instructions to load their addresses),
5166and are callable with the @code{bl} instruction.
5167
5168Large model objects may live anywhere in the 32-bit address space (the
5169compiler generates @code{seth/add3} instructions to load their addresses),
5170and may not be reachable with the @code{bl} instruction (the compiler
5171generates the much slower @code{seth/add3/jl} instruction sequence).
5172@end table
5173
5174@node m68k Function Attributes
5175@subsection m68k Function Attributes
5176
5177These function attributes are supported by the m68k back end:
5178
5179@table @code
5180@item interrupt
5181@itemx interrupt_handler
5182@cindex @code{interrupt} function attribute, m68k
5183@cindex @code{interrupt_handler} function attribute, m68k
5184Use this attribute to
5185indicate that the specified function is an interrupt handler.  The compiler
5186generates function entry and exit sequences suitable for use in an
5187interrupt handler when this attribute is present.  Either name may be used.
5188
5189@item interrupt_thread
5190@cindex @code{interrupt_thread} function attribute, fido
5191Use this attribute on fido, a subarchitecture of the m68k, to indicate
5192that the specified function is an interrupt handler that is designed
5193to run as a thread.  The compiler omits generate prologue/epilogue
5194sequences and replaces the return instruction with a @code{sleep}
5195instruction.  This attribute is available only on fido.
5196@end table
5197
5198@node MCORE Function Attributes
5199@subsection MCORE Function Attributes
5200
5201These function attributes are supported by the MCORE back end:
5202
5203@table @code
5204@item naked
5205@cindex @code{naked} function attribute, MCORE
5206This attribute allows the compiler to construct the
5207requisite function declaration, while allowing the body of the
5208function to be assembly code. The specified function will not have
5209prologue/epilogue sequences generated by the compiler. Only basic
5210@code{asm} statements can safely be included in naked functions
5211(@pxref{Basic Asm}). While using extended @code{asm} or a mixture of
5212basic @code{asm} and C code may appear to work, they cannot be
5213depended upon to work reliably and are not supported.
5214@end table
5215
5216@node MeP Function Attributes
5217@subsection MeP Function Attributes
5218
5219These function attributes are supported by the MeP back end:
5220
5221@table @code
5222@item disinterrupt
5223@cindex @code{disinterrupt} function attribute, MeP
5224On MeP targets, this attribute causes the compiler to emit
5225instructions to disable interrupts for the duration of the given
5226function.
5227
5228@item interrupt
5229@cindex @code{interrupt} function attribute, MeP
5230Use this attribute to indicate
5231that the specified function is an interrupt handler.  The compiler generates
5232function entry and exit sequences suitable for use in an interrupt handler
5233when this attribute is present.
5234
5235@item near
5236@cindex @code{near} function attribute, MeP
5237This attribute causes the compiler to assume the called
5238function is close enough to use the normal calling convention,
5239overriding the @option{-mtf} command-line option.
5240
5241@item far
5242@cindex @code{far} function attribute, MeP
5243On MeP targets this causes the compiler to use a calling convention
5244that assumes the called function is too far away for the built-in
5245addressing modes.
5246
5247@item vliw
5248@cindex @code{vliw} function attribute, MeP
5249The @code{vliw} attribute tells the compiler to emit
5250instructions in VLIW mode instead of core mode.  Note that this
5251attribute is not allowed unless a VLIW coprocessor has been configured
5252and enabled through command-line options.
5253@end table
5254
5255@node MicroBlaze Function Attributes
5256@subsection MicroBlaze Function Attributes
5257
5258These function attributes are supported on MicroBlaze targets:
5259
5260@table @code
5261@item save_volatiles
5262@cindex @code{save_volatiles} function attribute, MicroBlaze
5263Use this attribute to indicate that the function is
5264an interrupt handler.  All volatile registers (in addition to non-volatile
5265registers) are saved in the function prologue.  If the function is a leaf
5266function, only volatiles used by the function are saved.  A normal function
5267return is generated instead of a return from interrupt.
5268
5269@item break_handler
5270@cindex @code{break_handler} function attribute, MicroBlaze
5271@cindex break handler functions
5272Use this attribute to indicate that
5273the specified function is a break handler.  The compiler generates function
5274entry and exit sequences suitable for use in an break handler when this
5275attribute is present. The return from @code{break_handler} is done through
5276the @code{rtbd} instead of @code{rtsd}.
5277
5278@smallexample
5279void f () __attribute__ ((break_handler));
5280@end smallexample
5281
5282@item interrupt_handler
5283@itemx fast_interrupt
5284@cindex @code{interrupt_handler} function attribute, MicroBlaze
5285@cindex @code{fast_interrupt} function attribute, MicroBlaze
5286These attributes indicate that the specified function is an interrupt
5287handler.  Use the @code{fast_interrupt} attribute to indicate handlers
5288used in low-latency interrupt mode, and @code{interrupt_handler} for
5289interrupts that do not use low-latency handlers.  In both cases, GCC
5290emits appropriate prologue code and generates a return from the handler
5291using @code{rtid} instead of @code{rtsd}.
5292@end table
5293
5294@node Microsoft Windows Function Attributes
5295@subsection Microsoft Windows Function Attributes
5296
5297The following attributes are available on Microsoft Windows and Symbian OS
5298targets.
5299
5300@table @code
5301@item dllexport
5302@cindex @code{dllexport} function attribute
5303@cindex @code{__declspec(dllexport)}
5304On Microsoft Windows targets and Symbian OS targets the
5305@code{dllexport} attribute causes the compiler to provide a global
5306pointer to a pointer in a DLL, so that it can be referenced with the
5307@code{dllimport} attribute.  On Microsoft Windows targets, the pointer
5308name is formed by combining @code{_imp__} and the function or variable
5309name.
5310
5311You can use @code{__declspec(dllexport)} as a synonym for
5312@code{__attribute__ ((dllexport))} for compatibility with other
5313compilers.
5314
5315On systems that support the @code{visibility} attribute, this
5316attribute also implies ``default'' visibility.  It is an error to
5317explicitly specify any other visibility.
5318
5319GCC's default behavior is to emit all inline functions with the
5320@code{dllexport} attribute.  Since this can cause object file-size bloat,
5321you can use @option{-fno-keep-inline-dllexport}, which tells GCC to
5322ignore the attribute for inlined functions unless the
5323@option{-fkeep-inline-functions} flag is used instead.
5324
5325The attribute is ignored for undefined symbols.
5326
5327When applied to C++ classes, the attribute marks defined non-inlined
5328member functions and static data members as exports.  Static consts
5329initialized in-class are not marked unless they are also defined
5330out-of-class.
5331
5332For Microsoft Windows targets there are alternative methods for
5333including the symbol in the DLL's export table such as using a
5334@file{.def} file with an @code{EXPORTS} section or, with GNU ld, using
5335the @option{--export-all} linker flag.
5336
5337@item dllimport
5338@cindex @code{dllimport} function attribute
5339@cindex @code{__declspec(dllimport)}
5340On Microsoft Windows and Symbian OS targets, the @code{dllimport}
5341attribute causes the compiler to reference a function or variable via
5342a global pointer to a pointer that is set up by the DLL exporting the
5343symbol.  The attribute implies @code{extern}.  On Microsoft Windows
5344targets, the pointer name is formed by combining @code{_imp__} and the
5345function or variable name.
5346
5347You can use @code{__declspec(dllimport)} as a synonym for
5348@code{__attribute__ ((dllimport))} for compatibility with other
5349compilers.
5350
5351On systems that support the @code{visibility} attribute, this
5352attribute also implies ``default'' visibility.  It is an error to
5353explicitly specify any other visibility.
5354
5355Currently, the attribute is ignored for inlined functions.  If the
5356attribute is applied to a symbol @emph{definition}, an error is reported.
5357If a symbol previously declared @code{dllimport} is later defined, the
5358attribute is ignored in subsequent references, and a warning is emitted.
5359The attribute is also overridden by a subsequent declaration as
5360@code{dllexport}.
5361
5362When applied to C++ classes, the attribute marks non-inlined
5363member functions and static data members as imports.  However, the
5364attribute is ignored for virtual methods to allow creation of vtables
5365using thunks.
5366
5367On the SH Symbian OS target the @code{dllimport} attribute also has
5368another affect---it can cause the vtable and run-time type information
5369for a class to be exported.  This happens when the class has a
5370dllimported constructor or a non-inline, non-pure virtual function
5371and, for either of those two conditions, the class also has an inline
5372constructor or destructor and has a key function that is defined in
5373the current translation unit.
5374
5375For Microsoft Windows targets the use of the @code{dllimport}
5376attribute on functions is not necessary, but provides a small
5377performance benefit by eliminating a thunk in the DLL@.  The use of the
5378@code{dllimport} attribute on imported variables can be avoided by passing the
5379@option{--enable-auto-import} switch to the GNU linker.  As with
5380functions, using the attribute for a variable eliminates a thunk in
5381the DLL@.
5382
5383One drawback to using this attribute is that a pointer to a
5384@emph{variable} marked as @code{dllimport} cannot be used as a constant
5385address. However, a pointer to a @emph{function} with the
5386@code{dllimport} attribute can be used as a constant initializer; in
5387this case, the address of a stub function in the import lib is
5388referenced.  On Microsoft Windows targets, the attribute can be disabled
5389for functions by setting the @option{-mnop-fun-dllimport} flag.
5390@end table
5391
5392@node MIPS Function Attributes
5393@subsection MIPS Function Attributes
5394
5395These function attributes are supported by the MIPS back end:
5396
5397@table @code
5398@item interrupt
5399@cindex @code{interrupt} function attribute, MIPS
5400Use this attribute to indicate that the specified function is an interrupt
5401handler.  The compiler generates function entry and exit sequences suitable
5402for use in an interrupt handler when this attribute is present.
5403An optional argument is supported for the interrupt attribute which allows
5404the interrupt mode to be described.  By default GCC assumes the external
5405interrupt controller (EIC) mode is in use, this can be explicitly set using
5406@code{eic}.  When interrupts are non-masked then the requested Interrupt
5407Priority Level (IPL) is copied to the current IPL which has the effect of only
5408enabling higher priority interrupts.  To use vectored interrupt mode use
5409the argument @code{vector=[sw0|sw1|hw0|hw1|hw2|hw3|hw4|hw5]}, this will change
5410the behavior of the non-masked interrupt support and GCC will arrange to mask
5411all interrupts from sw0 up to and including the specified interrupt vector.
5412
5413You can use the following attributes to modify the behavior
5414of an interrupt handler:
5415@table @code
5416@item use_shadow_register_set
5417@cindex @code{use_shadow_register_set} function attribute, MIPS
5418Assume that the handler uses a shadow register set, instead of
5419the main general-purpose registers.  An optional argument @code{intstack} is
5420supported to indicate that the shadow register set contains a valid stack
5421pointer.
5422
5423@item keep_interrupts_masked
5424@cindex @code{keep_interrupts_masked} function attribute, MIPS
5425Keep interrupts masked for the whole function.  Without this attribute,
5426GCC tries to reenable interrupts for as much of the function as it can.
5427
5428@item use_debug_exception_return
5429@cindex @code{use_debug_exception_return} function attribute, MIPS
5430Return using the @code{deret} instruction.  Interrupt handlers that don't
5431have this attribute return using @code{eret} instead.
5432@end table
5433
5434You can use any combination of these attributes, as shown below:
5435@smallexample
5436void __attribute__ ((interrupt)) v0 ();
5437void __attribute__ ((interrupt, use_shadow_register_set)) v1 ();
5438void __attribute__ ((interrupt, keep_interrupts_masked)) v2 ();
5439void __attribute__ ((interrupt, use_debug_exception_return)) v3 ();
5440void __attribute__ ((interrupt, use_shadow_register_set,
5441                     keep_interrupts_masked)) v4 ();
5442void __attribute__ ((interrupt, use_shadow_register_set,
5443                     use_debug_exception_return)) v5 ();
5444void __attribute__ ((interrupt, keep_interrupts_masked,
5445                     use_debug_exception_return)) v6 ();
5446void __attribute__ ((interrupt, use_shadow_register_set,
5447                     keep_interrupts_masked,
5448                     use_debug_exception_return)) v7 ();
5449void __attribute__ ((interrupt("eic"))) v8 ();
5450void __attribute__ ((interrupt("vector=hw3"))) v9 ();
5451@end smallexample
5452
5453@item long_call
5454@itemx short_call
5455@itemx near
5456@itemx far
5457@cindex indirect calls, MIPS
5458@cindex @code{long_call} function attribute, MIPS
5459@cindex @code{short_call} function attribute, MIPS
5460@cindex @code{near} function attribute, MIPS
5461@cindex @code{far} function attribute, MIPS
5462These attributes specify how a particular function is called on MIPS@.
5463The attributes override the @option{-mlong-calls} (@pxref{MIPS Options})
5464command-line switch.  The @code{long_call} and @code{far} attributes are
5465synonyms, and cause the compiler to always call
5466the function by first loading its address into a register, and then using
5467the contents of that register.  The @code{short_call} and @code{near}
5468attributes are synonyms, and have the opposite
5469effect; they specify that non-PIC calls should be made using the more
5470efficient @code{jal} instruction.
5471
5472@item mips16
5473@itemx nomips16
5474@cindex @code{mips16} function attribute, MIPS
5475@cindex @code{nomips16} function attribute, MIPS
5476
5477On MIPS targets, you can use the @code{mips16} and @code{nomips16}
5478function attributes to locally select or turn off MIPS16 code generation.
5479A function with the @code{mips16} attribute is emitted as MIPS16 code,
5480while MIPS16 code generation is disabled for functions with the
5481@code{nomips16} attribute.  These attributes override the
5482@option{-mips16} and @option{-mno-mips16} options on the command line
5483(@pxref{MIPS Options}).
5484
5485When compiling files containing mixed MIPS16 and non-MIPS16 code, the
5486preprocessor symbol @code{__mips16} reflects the setting on the command line,
5487not that within individual functions.  Mixed MIPS16 and non-MIPS16 code
5488may interact badly with some GCC extensions such as @code{__builtin_apply}
5489(@pxref{Constructing Calls}).
5490
5491@item micromips, MIPS
5492@itemx nomicromips, MIPS
5493@cindex @code{micromips} function attribute
5494@cindex @code{nomicromips} function attribute
5495
5496On MIPS targets, you can use the @code{micromips} and @code{nomicromips}
5497function attributes to locally select or turn off microMIPS code generation.
5498A function with the @code{micromips} attribute is emitted as microMIPS code,
5499while microMIPS code generation is disabled for functions with the
5500@code{nomicromips} attribute.  These attributes override the
5501@option{-mmicromips} and @option{-mno-micromips} options on the command line
5502(@pxref{MIPS Options}).
5503
5504When compiling files containing mixed microMIPS and non-microMIPS code, the
5505preprocessor symbol @code{__mips_micromips} reflects the setting on the
5506command line,
5507not that within individual functions.  Mixed microMIPS and non-microMIPS code
5508may interact badly with some GCC extensions such as @code{__builtin_apply}
5509(@pxref{Constructing Calls}).
5510
5511@item nocompression
5512@cindex @code{nocompression} function attribute, MIPS
5513On MIPS targets, you can use the @code{nocompression} function attribute
5514to locally turn off MIPS16 and microMIPS code generation.  This attribute
5515overrides the @option{-mips16} and @option{-mmicromips} options on the
5516command line (@pxref{MIPS Options}).
5517@end table
5518
5519@node MSP430 Function Attributes
5520@subsection MSP430 Function Attributes
5521
5522These function attributes are supported by the MSP430 back end:
5523
5524@table @code
5525@item critical
5526@cindex @code{critical} function attribute, MSP430
5527Critical functions disable interrupts upon entry and restore the
5528previous interrupt state upon exit.  Critical functions cannot also
5529have the @code{naked}, @code{reentrant} or @code{interrupt} attributes.
5530
5531The MSP430 hardware ensures that interrupts are disabled on entry to
5532@code{interrupt} functions, and restores the previous interrupt state
5533on exit. The @code{critical} attribute is therefore redundant on
5534@code{interrupt} functions.
5535
5536@item interrupt
5537@cindex @code{interrupt} function attribute, MSP430
5538Use this attribute to indicate
5539that the specified function is an interrupt handler.  The compiler generates
5540function entry and exit sequences suitable for use in an interrupt handler
5541when this attribute is present.
5542
5543You can provide an argument to the interrupt
5544attribute which specifies a name or number.  If the argument is a
5545number it indicates the slot in the interrupt vector table (0 - 31) to
5546which this handler should be assigned.  If the argument is a name it
5547is treated as a symbolic name for the vector slot.  These names should
5548match up with appropriate entries in the linker script.  By default
5549the names @code{watchdog} for vector 26, @code{nmi} for vector 30 and
5550@code{reset} for vector 31 are recognized.
5551
5552@item naked
5553@cindex @code{naked} function attribute, MSP430
5554This attribute allows the compiler to construct the
5555requisite function declaration, while allowing the body of the
5556function to be assembly code. The specified function will not have
5557prologue/epilogue sequences generated by the compiler. Only basic
5558@code{asm} statements can safely be included in naked functions
5559(@pxref{Basic Asm}). While using extended @code{asm} or a mixture of
5560basic @code{asm} and C code may appear to work, they cannot be
5561depended upon to work reliably and are not supported.
5562
5563@item reentrant
5564@cindex @code{reentrant} function attribute, MSP430
5565Reentrant functions disable interrupts upon entry and enable them
5566upon exit.  Reentrant functions cannot also have the @code{naked}
5567or @code{critical} attributes.  They can have the @code{interrupt}
5568attribute.
5569
5570@item wakeup
5571@cindex @code{wakeup} function attribute, MSP430
5572This attribute only applies to interrupt functions.  It is silently
5573ignored if applied to a non-interrupt function.  A wakeup interrupt
5574function will rouse the processor from any low-power state that it
5575might be in when the function exits.
5576
5577@item lower
5578@itemx upper
5579@itemx either
5580@cindex @code{lower} function attribute, MSP430
5581@cindex @code{upper} function attribute, MSP430
5582@cindex @code{either} function attribute, MSP430
5583On the MSP430 target these attributes can be used to specify whether
5584the function or variable should be placed into low memory, high
5585memory, or the placement should be left to the linker to decide.  The
5586attributes are only significant if compiling for the MSP430X
5587architecture in the large memory model.
5588
5589The attributes work in conjunction with a linker script that has been
5590augmented to specify where to place sections with a @code{.lower} and
5591a @code{.upper} prefix.  So, for example, as well as placing the
5592@code{.data} section, the script also specifies the placement of a
5593@code{.lower.data} and a @code{.upper.data} section.  The intention
5594is that @code{lower} sections are placed into a small but easier to
5595access memory region and the upper sections are placed into a larger, but
5596slower to access, region.
5597
5598The @code{either} attribute is special.  It tells the linker to place
5599the object into the corresponding @code{lower} section if there is
5600room for it.  If there is insufficient room then the object is placed
5601into the corresponding @code{upper} section instead.  Note that the
5602placement algorithm is not very sophisticated.  It does not attempt to
5603find an optimal packing of the @code{lower} sections.  It just makes
5604one pass over the objects and does the best that it can.  Using the
5605@option{-ffunction-sections} and @option{-fdata-sections} command-line
5606options can help the packing, however, since they produce smaller,
5607easier to pack regions.
5608@end table
5609
5610@node NDS32 Function Attributes
5611@subsection NDS32 Function Attributes
5612
5613These function attributes are supported by the NDS32 back end:
5614
5615@table @code
5616@item exception
5617@cindex @code{exception} function attribute
5618@cindex exception handler functions, NDS32
5619Use this attribute on the NDS32 target to indicate that the specified function
5620is an exception handler.  The compiler will generate corresponding sections
5621for use in an exception handler.
5622
5623@item interrupt
5624@cindex @code{interrupt} function attribute, NDS32
5625On NDS32 target, this attribute indicates that the specified function
5626is an interrupt handler.  The compiler generates corresponding sections
5627for use in an interrupt handler.  You can use the following attributes
5628to modify the behavior:
5629@table @code
5630@item nested
5631@cindex @code{nested} function attribute, NDS32
5632This interrupt service routine is interruptible.
5633@item not_nested
5634@cindex @code{not_nested} function attribute, NDS32
5635This interrupt service routine is not interruptible.
5636@item nested_ready
5637@cindex @code{nested_ready} function attribute, NDS32
5638This interrupt service routine is interruptible after @code{PSW.GIE}
5639(global interrupt enable) is set.  This allows interrupt service routine to
5640finish some short critical code before enabling interrupts.
5641@item save_all
5642@cindex @code{save_all} function attribute, NDS32
5643The system will help save all registers into stack before entering
5644interrupt handler.
5645@item partial_save
5646@cindex @code{partial_save} function attribute, NDS32
5647The system will help save caller registers into stack before entering
5648interrupt handler.
5649@end table
5650
5651@item naked
5652@cindex @code{naked} function attribute, NDS32
5653This attribute allows the compiler to construct the
5654requisite function declaration, while allowing the body of the
5655function to be assembly code. The specified function will not have
5656prologue/epilogue sequences generated by the compiler. Only basic
5657@code{asm} statements can safely be included in naked functions
5658(@pxref{Basic Asm}). While using extended @code{asm} or a mixture of
5659basic @code{asm} and C code may appear to work, they cannot be
5660depended upon to work reliably and are not supported.
5661
5662@item reset
5663@cindex @code{reset} function attribute, NDS32
5664@cindex reset handler functions
5665Use this attribute on the NDS32 target to indicate that the specified function
5666is a reset handler.  The compiler will generate corresponding sections
5667for use in a reset handler.  You can use the following attributes
5668to provide extra exception handling:
5669@table @code
5670@item nmi
5671@cindex @code{nmi} function attribute, NDS32
5672Provide a user-defined function to handle NMI exception.
5673@item warm
5674@cindex @code{warm} function attribute, NDS32
5675Provide a user-defined function to handle warm reset exception.
5676@end table
5677@end table
5678
5679@node Nios II Function Attributes
5680@subsection Nios II Function Attributes
5681
5682These function attributes are supported by the Nios II back end:
5683
5684@table @code
5685@item target (@var{options})
5686@cindex @code{target} function attribute
5687As discussed in @ref{Common Function Attributes}, this attribute
5688allows specification of target-specific compilation options.
5689
5690When compiling for Nios II, the following options are allowed:
5691
5692@table @samp
5693@item custom-@var{insn}=@var{N}
5694@itemx no-custom-@var{insn}
5695@cindex @code{target("custom-@var{insn}=@var{N}")} function attribute, Nios II
5696@cindex @code{target("no-custom-@var{insn}")} function attribute, Nios II
5697Each @samp{custom-@var{insn}=@var{N}} attribute locally enables use of a
5698custom instruction with encoding @var{N} when generating code that uses
5699@var{insn}.  Similarly, @samp{no-custom-@var{insn}} locally inhibits use of
5700the custom instruction @var{insn}.
5701These target attributes correspond to the
5702@option{-mcustom-@var{insn}=@var{N}} and @option{-mno-custom-@var{insn}}
5703command-line options, and support the same set of @var{insn} keywords.
5704@xref{Nios II Options}, for more information.
5705
5706@item custom-fpu-cfg=@var{name}
5707@cindex @code{target("custom-fpu-cfg=@var{name}")} function attribute, Nios II
5708This attribute corresponds to the @option{-mcustom-fpu-cfg=@var{name}}
5709command-line option, to select a predefined set of custom instructions
5710named @var{name}.
5711@xref{Nios II Options}, for more information.
5712@end table
5713@end table
5714
5715@node Nvidia PTX Function Attributes
5716@subsection Nvidia PTX Function Attributes
5717
5718These function attributes are supported by the Nvidia PTX back end:
5719
5720@table @code
5721@item kernel
5722@cindex @code{kernel} attribute, Nvidia PTX
5723This attribute indicates that the corresponding function should be compiled
5724as a kernel function, which can be invoked from the host via the CUDA RT
5725library.
5726By default functions are only callable only from other PTX functions.
5727
5728Kernel functions must have @code{void} return type.
5729@end table
5730
5731@node PowerPC Function Attributes
5732@subsection PowerPC Function Attributes
5733
5734These function attributes are supported by the PowerPC back end:
5735
5736@table @code
5737@item longcall
5738@itemx shortcall
5739@cindex indirect calls, PowerPC
5740@cindex @code{longcall} function attribute, PowerPC
5741@cindex @code{shortcall} function attribute, PowerPC
5742The @code{longcall} attribute
5743indicates that the function might be far away from the call site and
5744require a different (more expensive) calling sequence.  The
5745@code{shortcall} attribute indicates that the function is always close
5746enough for the shorter calling sequence to be used.  These attributes
5747override both the @option{-mlongcall} switch and
5748the @code{#pragma longcall} setting.
5749
5750@xref{RS/6000 and PowerPC Options}, for more information on whether long
5751calls are necessary.
5752
5753@item target (@var{options})
5754@cindex @code{target} function attribute
5755As discussed in @ref{Common Function Attributes}, this attribute
5756allows specification of target-specific compilation options.
5757
5758On the PowerPC, the following options are allowed:
5759
5760@table @samp
5761@item altivec
5762@itemx no-altivec
5763@cindex @code{target("altivec")} function attribute, PowerPC
5764Generate code that uses (does not use) AltiVec instructions.  In
576532-bit code, you cannot enable AltiVec instructions unless
5766@option{-mabi=altivec} is used on the command line.
5767
5768@item cmpb
5769@itemx no-cmpb
5770@cindex @code{target("cmpb")} function attribute, PowerPC
5771Generate code that uses (does not use) the compare bytes instruction
5772implemented on the POWER6 processor and other processors that support
5773the PowerPC V2.05 architecture.
5774
5775@item dlmzb
5776@itemx no-dlmzb
5777@cindex @code{target("dlmzb")} function attribute, PowerPC
5778Generate code that uses (does not use) the string-search @samp{dlmzb}
5779instruction on the IBM 405, 440, 464 and 476 processors.  This instruction is
5780generated by default when targeting those processors.
5781
5782@item fprnd
5783@itemx no-fprnd
5784@cindex @code{target("fprnd")} function attribute, PowerPC
5785Generate code that uses (does not use) the FP round to integer
5786instructions implemented on the POWER5+ processor and other processors
5787that support the PowerPC V2.03 architecture.
5788
5789@item hard-dfp
5790@itemx no-hard-dfp
5791@cindex @code{target("hard-dfp")} function attribute, PowerPC
5792Generate code that uses (does not use) the decimal floating-point
5793instructions implemented on some POWER processors.
5794
5795@item isel
5796@itemx no-isel
5797@cindex @code{target("isel")} function attribute, PowerPC
5798Generate code that uses (does not use) ISEL instruction.
5799
5800@item mfcrf
5801@itemx no-mfcrf
5802@cindex @code{target("mfcrf")} function attribute, PowerPC
5803Generate code that uses (does not use) the move from condition
5804register field instruction implemented on the POWER4 processor and
5805other processors that support the PowerPC V2.01 architecture.
5806
5807@item mulhw
5808@itemx no-mulhw
5809@cindex @code{target("mulhw")} function attribute, PowerPC
5810Generate code that uses (does not use) the half-word multiply and
5811multiply-accumulate instructions on the IBM 405, 440, 464 and 476 processors.
5812These instructions are generated by default when targeting those
5813processors.
5814
5815@item multiple
5816@itemx no-multiple
5817@cindex @code{target("multiple")} function attribute, PowerPC
5818Generate code that uses (does not use) the load multiple word
5819instructions and the store multiple word instructions.
5820
5821@item update
5822@itemx no-update
5823@cindex @code{target("update")} function attribute, PowerPC
5824Generate code that uses (does not use) the load or store instructions
5825that update the base register to the address of the calculated memory
5826location.
5827
5828@item popcntb
5829@itemx no-popcntb
5830@cindex @code{target("popcntb")} function attribute, PowerPC
5831Generate code that uses (does not use) the popcount and double-precision
5832FP reciprocal estimate instruction implemented on the POWER5
5833processor and other processors that support the PowerPC V2.02
5834architecture.
5835
5836@item popcntd
5837@itemx no-popcntd
5838@cindex @code{target("popcntd")} function attribute, PowerPC
5839Generate code that uses (does not use) the popcount instruction
5840implemented on the POWER7 processor and other processors that support
5841the PowerPC V2.06 architecture.
5842
5843@item powerpc-gfxopt
5844@itemx no-powerpc-gfxopt
5845@cindex @code{target("powerpc-gfxopt")} function attribute, PowerPC
5846Generate code that uses (does not use) the optional PowerPC
5847architecture instructions in the Graphics group, including
5848floating-point select.
5849
5850@item powerpc-gpopt
5851@itemx no-powerpc-gpopt
5852@cindex @code{target("powerpc-gpopt")} function attribute, PowerPC
5853Generate code that uses (does not use) the optional PowerPC
5854architecture instructions in the General Purpose group, including
5855floating-point square root.
5856
5857@item recip-precision
5858@itemx no-recip-precision
5859@cindex @code{target("recip-precision")} function attribute, PowerPC
5860Assume (do not assume) that the reciprocal estimate instructions
5861provide higher-precision estimates than is mandated by the PowerPC
5862ABI.
5863
5864@item string
5865@itemx no-string
5866@cindex @code{target("string")} function attribute, PowerPC
5867Generate code that uses (does not use) the load string instructions
5868and the store string word instructions to save multiple registers and
5869do small block moves.
5870
5871@item vsx
5872@itemx no-vsx
5873@cindex @code{target("vsx")} function attribute, PowerPC
5874Generate code that uses (does not use) vector/scalar (VSX)
5875instructions, and also enable the use of built-in functions that allow
5876more direct access to the VSX instruction set.  In 32-bit code, you
5877cannot enable VSX or AltiVec instructions unless
5878@option{-mabi=altivec} is used on the command line.
5879
5880@item friz
5881@itemx no-friz
5882@cindex @code{target("friz")} function attribute, PowerPC
5883Generate (do not generate) the @code{friz} instruction when the
5884@option{-funsafe-math-optimizations} option is used to optimize
5885rounding a floating-point value to 64-bit integer and back to floating
5886point.  The @code{friz} instruction does not return the same value if
5887the floating-point number is too large to fit in an integer.
5888
5889@item avoid-indexed-addresses
5890@itemx no-avoid-indexed-addresses
5891@cindex @code{target("avoid-indexed-addresses")} function attribute, PowerPC
5892Generate code that tries to avoid (not avoid) the use of indexed load
5893or store instructions.
5894
5895@item paired
5896@itemx no-paired
5897@cindex @code{target("paired")} function attribute, PowerPC
5898Generate code that uses (does not use) the generation of PAIRED simd
5899instructions.
5900
5901@item longcall
5902@itemx no-longcall
5903@cindex @code{target("longcall")} function attribute, PowerPC
5904Generate code that assumes (does not assume) that all calls are far
5905away so that a longer more expensive calling sequence is required.
5906
5907@item cpu=@var{CPU}
5908@cindex @code{target("cpu=@var{CPU}")} function attribute, PowerPC
5909Specify the architecture to generate code for when compiling the
5910function.  If you select the @code{target("cpu=power7")} attribute when
5911generating 32-bit code, VSX and AltiVec instructions are not generated
5912unless you use the @option{-mabi=altivec} option on the command line.
5913
5914@item tune=@var{TUNE}
5915@cindex @code{target("tune=@var{TUNE}")} function attribute, PowerPC
5916Specify the architecture to tune for when compiling the function.  If
5917you do not specify the @code{target("tune=@var{TUNE}")} attribute and
5918you do specify the @code{target("cpu=@var{CPU}")} attribute,
5919compilation tunes for the @var{CPU} architecture, and not the
5920default tuning specified on the command line.
5921@end table
5922
5923On the PowerPC, the inliner does not inline a
5924function that has different target options than the caller, unless the
5925callee has a subset of the target options of the caller.
5926@end table
5927
5928@node RISC-V Function Attributes
5929@subsection RISC-V Function Attributes
5930
5931These function attributes are supported by the RISC-V back end:
5932
5933@table @code
5934@item naked
5935@cindex @code{naked} function attribute, RISC-V
5936This attribute allows the compiler to construct the
5937requisite function declaration, while allowing the body of the
5938function to be assembly code. The specified function will not have
5939prologue/epilogue sequences generated by the compiler. Only basic
5940@code{asm} statements can safely be included in naked functions
5941(@pxref{Basic Asm}). While using extended @code{asm} or a mixture of
5942basic @code{asm} and C code may appear to work, they cannot be
5943depended upon to work reliably and are not supported.
5944
5945@item interrupt
5946@cindex @code{interrupt} function attribute, RISC-V
5947Use this attribute to indicate that the specified function is an interrupt
5948handler.  The compiler generates function entry and exit sequences suitable
5949for use in an interrupt handler when this attribute is present.
5950
5951You can specify the kind of interrupt to be handled by adding an optional
5952parameter to the interrupt attribute like this:
5953
5954@smallexample
5955void f (void) __attribute__ ((interrupt ("user")));
5956@end smallexample
5957
5958Permissible values for this parameter are @code{user}, @code{supervisor},
5959and @code{machine}.  If there is no parameter, then it defaults to
5960@code{machine}.
5961@end table
5962
5963@node RL78 Function Attributes
5964@subsection RL78 Function Attributes
5965
5966These function attributes are supported by the RL78 back end:
5967
5968@table @code
5969@item interrupt
5970@itemx brk_interrupt
5971@cindex @code{interrupt} function attribute, RL78
5972@cindex @code{brk_interrupt} function attribute, RL78
5973These attributes indicate
5974that the specified function is an interrupt handler.  The compiler generates
5975function entry and exit sequences suitable for use in an interrupt handler
5976when this attribute is present.
5977
5978Use @code{brk_interrupt} instead of @code{interrupt} for
5979handlers intended to be used with the @code{BRK} opcode (i.e.@: those
5980that must end with @code{RETB} instead of @code{RETI}).
5981
5982@item naked
5983@cindex @code{naked} function attribute, RL78
5984This attribute allows the compiler to construct the
5985requisite function declaration, while allowing the body of the
5986function to be assembly code. The specified function will not have
5987prologue/epilogue sequences generated by the compiler. Only basic
5988@code{asm} statements can safely be included in naked functions
5989(@pxref{Basic Asm}). While using extended @code{asm} or a mixture of
5990basic @code{asm} and C code may appear to work, they cannot be
5991depended upon to work reliably and are not supported.
5992@end table
5993
5994@node RX Function Attributes
5995@subsection RX Function Attributes
5996
5997These function attributes are supported by the RX back end:
5998
5999@table @code
6000@item fast_interrupt
6001@cindex @code{fast_interrupt} function attribute, RX
6002Use this attribute on the RX port to indicate that the specified
6003function is a fast interrupt handler.  This is just like the
6004@code{interrupt} attribute, except that @code{freit} is used to return
6005instead of @code{reit}.
6006
6007@item interrupt
6008@cindex @code{interrupt} function attribute, RX
6009Use this attribute to indicate
6010that the specified function is an interrupt handler.  The compiler generates
6011function entry and exit sequences suitable for use in an interrupt handler
6012when this attribute is present.
6013
6014On RX and RL78 targets, you may specify one or more vector numbers as arguments
6015to the attribute, as well as naming an alternate table name.
6016Parameters are handled sequentially, so one handler can be assigned to
6017multiple entries in multiple tables.  One may also pass the magic
6018string @code{"$default"} which causes the function to be used for any
6019unfilled slots in the current table.
6020
6021This example shows a simple assignment of a function to one vector in
6022the default table (note that preprocessor macros may be used for
6023chip-specific symbolic vector names):
6024@smallexample
6025void __attribute__ ((interrupt (5))) txd1_handler ();
6026@end smallexample
6027
6028This example assigns a function to two slots in the default table
6029(using preprocessor macros defined elsewhere) and makes it the default
6030for the @code{dct} table:
6031@smallexample
6032void __attribute__ ((interrupt (RXD1_VECT,RXD2_VECT,"dct","$default")))
6033	txd1_handler ();
6034@end smallexample
6035
6036@item naked
6037@cindex @code{naked} function attribute, RX
6038This attribute allows the compiler to construct the
6039requisite function declaration, while allowing the body of the
6040function to be assembly code. The specified function will not have
6041prologue/epilogue sequences generated by the compiler. Only basic
6042@code{asm} statements can safely be included in naked functions
6043(@pxref{Basic Asm}). While using extended @code{asm} or a mixture of
6044basic @code{asm} and C code may appear to work, they cannot be
6045depended upon to work reliably and are not supported.
6046
6047@item vector
6048@cindex @code{vector} function attribute, RX
6049This RX attribute is similar to the @code{interrupt} attribute, including its
6050parameters, but does not make the function an interrupt-handler type
6051function (i.e.@: it retains the normal C function calling ABI).  See the
6052@code{interrupt} attribute for a description of its arguments.
6053@end table
6054
6055@node S/390 Function Attributes
6056@subsection S/390 Function Attributes
6057
6058These function attributes are supported on the S/390:
6059
6060@table @code
6061@item hotpatch (@var{halfwords-before-function-label},@var{halfwords-after-function-label})
6062@cindex @code{hotpatch} function attribute, S/390
6063
6064On S/390 System z targets, you can use this function attribute to
6065make GCC generate a ``hot-patching'' function prologue.  If the
6066@option{-mhotpatch=} command-line option is used at the same time,
6067the @code{hotpatch} attribute takes precedence.  The first of the
6068two arguments specifies the number of halfwords to be added before
6069the function label.  A second argument can be used to specify the
6070number of halfwords to be added after the function label.  For
6071both arguments the maximum allowed value is 1000000.
6072
6073If both arguments are zero, hotpatching is disabled.
6074
6075@item target (@var{options})
6076@cindex @code{target} function attribute
6077As discussed in @ref{Common Function Attributes}, this attribute
6078allows specification of target-specific compilation options.
6079
6080On S/390, the following options are supported:
6081
6082@table @samp
6083@item arch=
6084@item tune=
6085@item stack-guard=
6086@item stack-size=
6087@item branch-cost=
6088@item warn-framesize=
6089@item backchain
6090@itemx no-backchain
6091@item hard-dfp
6092@itemx no-hard-dfp
6093@item hard-float
6094@itemx soft-float
6095@item htm
6096@itemx no-htm
6097@item vx
6098@itemx no-vx
6099@item packed-stack
6100@itemx no-packed-stack
6101@item small-exec
6102@itemx no-small-exec
6103@item mvcle
6104@itemx no-mvcle
6105@item warn-dynamicstack
6106@itemx no-warn-dynamicstack
6107@end table
6108
6109The options work exactly like the S/390 specific command line
6110options (without the prefix @option{-m}) except that they do not
6111change any feature macros.  For example,
6112
6113@smallexample
6114@code{target("no-vx")}
6115@end smallexample
6116
6117does not undefine the @code{__VEC__} macro.
6118@end table
6119
6120@node SH Function Attributes
6121@subsection SH Function Attributes
6122
6123These function attributes are supported on the SH family of processors:
6124
6125@table @code
6126@item function_vector
6127@cindex @code{function_vector} function attribute, SH
6128@cindex calling functions through the function vector on SH2A
6129On SH2A targets, this attribute declares a function to be called using the
6130TBR relative addressing mode.  The argument to this attribute is the entry
6131number of the same function in a vector table containing all the TBR
6132relative addressable functions.  For correct operation the TBR must be setup
6133accordingly to point to the start of the vector table before any functions with
6134this attribute are invoked.  Usually a good place to do the initialization is
6135the startup routine.  The TBR relative vector table can have at max 256 function
6136entries.  The jumps to these functions are generated using a SH2A specific,
6137non delayed branch instruction JSR/N @@(disp8,TBR).  You must use GAS and GLD
6138from GNU binutils version 2.7 or later for this attribute to work correctly.
6139
6140In an application, for a function being called once, this attribute
6141saves at least 8 bytes of code; and if other successive calls are being
6142made to the same function, it saves 2 bytes of code per each of these
6143calls.
6144
6145@item interrupt_handler
6146@cindex @code{interrupt_handler} function attribute, SH
6147Use this attribute to
6148indicate that the specified function is an interrupt handler.  The compiler
6149generates function entry and exit sequences suitable for use in an
6150interrupt handler when this attribute is present.
6151
6152@item nosave_low_regs
6153@cindex @code{nosave_low_regs} function attribute, SH
6154Use this attribute on SH targets to indicate that an @code{interrupt_handler}
6155function should not save and restore registers R0..R7.  This can be used on SH3*
6156and SH4* targets that have a second R0..R7 register bank for non-reentrant
6157interrupt handlers.
6158
6159@item renesas
6160@cindex @code{renesas} function attribute, SH
6161On SH targets this attribute specifies that the function or struct follows the
6162Renesas ABI.
6163
6164@item resbank
6165@cindex @code{resbank} function attribute, SH
6166On the SH2A target, this attribute enables the high-speed register
6167saving and restoration using a register bank for @code{interrupt_handler}
6168routines.  Saving to the bank is performed automatically after the CPU
6169accepts an interrupt that uses a register bank.
6170
6171The nineteen 32-bit registers comprising general register R0 to R14,
6172control register GBR, and system registers MACH, MACL, and PR and the
6173vector table address offset are saved into a register bank.  Register
6174banks are stacked in first-in last-out (FILO) sequence.  Restoration
6175from the bank is executed by issuing a RESBANK instruction.
6176
6177@item sp_switch
6178@cindex @code{sp_switch} function attribute, SH
6179Use this attribute on the SH to indicate an @code{interrupt_handler}
6180function should switch to an alternate stack.  It expects a string
6181argument that names a global variable holding the address of the
6182alternate stack.
6183
6184@smallexample
6185void *alt_stack;
6186void f () __attribute__ ((interrupt_handler,
6187                          sp_switch ("alt_stack")));
6188@end smallexample
6189
6190@item trap_exit
6191@cindex @code{trap_exit} function attribute, SH
6192Use this attribute on the SH for an @code{interrupt_handler} to return using
6193@code{trapa} instead of @code{rte}.  This attribute expects an integer
6194argument specifying the trap number to be used.
6195
6196@item trapa_handler
6197@cindex @code{trapa_handler} function attribute, SH
6198On SH targets this function attribute is similar to @code{interrupt_handler}
6199but it does not save and restore all registers.
6200@end table
6201
6202@node Symbian OS Function Attributes
6203@subsection Symbian OS Function Attributes
6204
6205@xref{Microsoft Windows Function Attributes}, for discussion of the
6206@code{dllexport} and @code{dllimport} attributes.
6207
6208@node V850 Function Attributes
6209@subsection V850 Function Attributes
6210
6211The V850 back end supports these function attributes:
6212
6213@table @code
6214@item interrupt
6215@itemx interrupt_handler
6216@cindex @code{interrupt} function attribute, V850
6217@cindex @code{interrupt_handler} function attribute, V850
6218Use these attributes to indicate
6219that the specified function is an interrupt handler.  The compiler generates
6220function entry and exit sequences suitable for use in an interrupt handler
6221when either attribute is present.
6222@end table
6223
6224@node Visium Function Attributes
6225@subsection Visium Function Attributes
6226
6227These function attributes are supported by the Visium back end:
6228
6229@table @code
6230@item interrupt
6231@cindex @code{interrupt} function attribute, Visium
6232Use this attribute to indicate
6233that the specified function is an interrupt handler.  The compiler generates
6234function entry and exit sequences suitable for use in an interrupt handler
6235when this attribute is present.
6236@end table
6237
6238@node x86 Function Attributes
6239@subsection x86 Function Attributes
6240
6241These function attributes are supported by the x86 back end:
6242
6243@table @code
6244@item cdecl
6245@cindex @code{cdecl} function attribute, x86-32
6246@cindex functions that pop the argument stack on x86-32
6247@opindex mrtd
6248On the x86-32 targets, the @code{cdecl} attribute causes the compiler to
6249assume that the calling function pops off the stack space used to
6250pass arguments.  This is
6251useful to override the effects of the @option{-mrtd} switch.
6252
6253@item fastcall
6254@cindex @code{fastcall} function attribute, x86-32
6255@cindex functions that pop the argument stack on x86-32
6256On x86-32 targets, the @code{fastcall} attribute causes the compiler to
6257pass the first argument (if of integral type) in the register ECX and
6258the second argument (if of integral type) in the register EDX@.  Subsequent
6259and other typed arguments are passed on the stack.  The called function
6260pops the arguments off the stack.  If the number of arguments is variable all
6261arguments are pushed on the stack.
6262
6263@item thiscall
6264@cindex @code{thiscall} function attribute, x86-32
6265@cindex functions that pop the argument stack on x86-32
6266On x86-32 targets, the @code{thiscall} attribute causes the compiler to
6267pass the first argument (if of integral type) in the register ECX.
6268Subsequent and other typed arguments are passed on the stack. The called
6269function pops the arguments off the stack.
6270If the number of arguments is variable all arguments are pushed on the
6271stack.
6272The @code{thiscall} attribute is intended for C++ non-static member functions.
6273As a GCC extension, this calling convention can be used for C functions
6274and for static member methods.
6275
6276@item ms_abi
6277@itemx sysv_abi
6278@cindex @code{ms_abi} function attribute, x86
6279@cindex @code{sysv_abi} function attribute, x86
6280
6281On 32-bit and 64-bit x86 targets, you can use an ABI attribute
6282to indicate which calling convention should be used for a function.  The
6283@code{ms_abi} attribute tells the compiler to use the Microsoft ABI,
6284while the @code{sysv_abi} attribute tells the compiler to use the System V
6285ELF ABI, which is used on GNU/Linux and other systems.  The default is to use
6286the Microsoft ABI when targeting Windows.  On all other systems, the default
6287is the System V ELF ABI.
6288
6289Note, the @code{ms_abi} attribute for Microsoft Windows 64-bit targets currently
6290requires the @option{-maccumulate-outgoing-args} option.
6291
6292@item callee_pop_aggregate_return (@var{number})
6293@cindex @code{callee_pop_aggregate_return} function attribute, x86
6294
6295On x86-32 targets, you can use this attribute to control how
6296aggregates are returned in memory.  If the caller is responsible for
6297popping the hidden pointer together with the rest of the arguments, specify
6298@var{number} equal to zero.  If callee is responsible for popping the
6299hidden pointer, specify @var{number} equal to one.
6300
6301The default x86-32 ABI assumes that the callee pops the
6302stack for hidden pointer.  However, on x86-32 Microsoft Windows targets,
6303the compiler assumes that the
6304caller pops the stack for hidden pointer.
6305
6306@item ms_hook_prologue
6307@cindex @code{ms_hook_prologue} function attribute, x86
6308
6309On 32-bit and 64-bit x86 targets, you can use
6310this function attribute to make GCC generate the ``hot-patching'' function
6311prologue used in Win32 API functions in Microsoft Windows XP Service Pack 2
6312and newer.
6313
6314@item naked
6315@cindex @code{naked} function attribute, x86
6316This attribute allows the compiler to construct the
6317requisite function declaration, while allowing the body of the
6318function to be assembly code. The specified function will not have
6319prologue/epilogue sequences generated by the compiler. Only basic
6320@code{asm} statements can safely be included in naked functions
6321(@pxref{Basic Asm}). While using extended @code{asm} or a mixture of
6322basic @code{asm} and C code may appear to work, they cannot be
6323depended upon to work reliably and are not supported.
6324
6325@item regparm (@var{number})
6326@cindex @code{regparm} function attribute, x86
6327@cindex functions that are passed arguments in registers on x86-32
6328On x86-32 targets, the @code{regparm} attribute causes the compiler to
6329pass arguments number one to @var{number} if they are of integral type
6330in registers EAX, EDX, and ECX instead of on the stack.  Functions that
6331take a variable number of arguments continue to be passed all of their
6332arguments on the stack.
6333
6334Beware that on some ELF systems this attribute is unsuitable for
6335global functions in shared libraries with lazy binding (which is the
6336default).  Lazy binding sends the first call via resolving code in
6337the loader, which might assume EAX, EDX and ECX can be clobbered, as
6338per the standard calling conventions.  Solaris 8 is affected by this.
6339Systems with the GNU C Library version 2.1 or higher
6340and FreeBSD are believed to be
6341safe since the loaders there save EAX, EDX and ECX.  (Lazy binding can be
6342disabled with the linker or the loader if desired, to avoid the
6343problem.)
6344
6345@item sseregparm
6346@cindex @code{sseregparm} function attribute, x86
6347On x86-32 targets with SSE support, the @code{sseregparm} attribute
6348causes the compiler to pass up to 3 floating-point arguments in
6349SSE registers instead of on the stack.  Functions that take a
6350variable number of arguments continue to pass all of their
6351floating-point arguments on the stack.
6352
6353@item force_align_arg_pointer
6354@cindex @code{force_align_arg_pointer} function attribute, x86
6355On x86 targets, the @code{force_align_arg_pointer} attribute may be
6356applied to individual function definitions, generating an alternate
6357prologue and epilogue that realigns the run-time stack if necessary.
6358This supports mixing legacy codes that run with a 4-byte aligned stack
6359with modern codes that keep a 16-byte stack for SSE compatibility.
6360
6361@item stdcall
6362@cindex @code{stdcall} function attribute, x86-32
6363@cindex functions that pop the argument stack on x86-32
6364On x86-32 targets, the @code{stdcall} attribute causes the compiler to
6365assume that the called function pops off the stack space used to
6366pass arguments, unless it takes a variable number of arguments.
6367
6368@item no_caller_saved_registers
6369@cindex @code{no_caller_saved_registers} function attribute, x86
6370Use this attribute to indicate that the specified function has no
6371caller-saved registers. That is, all registers are callee-saved. For
6372example, this attribute can be used for a function called from an
6373interrupt handler. The compiler generates proper function entry and
6374exit sequences to save and restore any modified registers, except for
6375the EFLAGS register.  Since GCC doesn't preserve SSE, MMX nor x87
6376states, the GCC option @option{-mgeneral-regs-only} should be used to
6377compile functions with @code{no_caller_saved_registers} attribute.
6378
6379@item interrupt
6380@cindex @code{interrupt} function attribute, x86
6381Use this attribute to indicate that the specified function is an
6382interrupt handler or an exception handler (depending on parameters passed
6383to the function, explained further).  The compiler generates function
6384entry and exit sequences suitable for use in an interrupt handler when
6385this attribute is present.  The @code{IRET} instruction, instead of the
6386@code{RET} instruction, is used to return from interrupt handlers.  All
6387registers, except for the EFLAGS register which is restored by the
6388@code{IRET} instruction, are preserved by the compiler.  Since GCC
6389doesn't preserve SSE, MMX nor x87 states, the GCC option
6390@option{-mgeneral-regs-only} should be used to compile interrupt and
6391exception handlers.
6392
6393Any interruptible-without-stack-switch code must be compiled with
6394@option{-mno-red-zone} since interrupt handlers can and will, because
6395of the hardware design, touch the red zone.
6396
6397An interrupt handler must be declared with a mandatory pointer
6398argument:
6399
6400@smallexample
6401struct interrupt_frame;
6402
6403__attribute__ ((interrupt))
6404void
6405f (struct interrupt_frame *frame)
6406@{
6407@}
6408@end smallexample
6409
6410@noindent
6411and you must define @code{struct interrupt_frame} as described in the
6412processor's manual.
6413
6414Exception handlers differ from interrupt handlers because the system
6415pushes an error code on the stack.  An exception handler declaration is
6416similar to that for an interrupt handler, but with a different mandatory
6417function signature.  The compiler arranges to pop the error code off the
6418stack before the @code{IRET} instruction.
6419
6420@smallexample
6421#ifdef __x86_64__
6422typedef unsigned long long int uword_t;
6423#else
6424typedef unsigned int uword_t;
6425#endif
6426
6427struct interrupt_frame;
6428
6429__attribute__ ((interrupt))
6430void
6431f (struct interrupt_frame *frame, uword_t error_code)
6432@{
6433  ...
6434@}
6435@end smallexample
6436
6437Exception handlers should only be used for exceptions that push an error
6438code; you should use an interrupt handler in other cases.  The system
6439will crash if the wrong kind of handler is used.
6440
6441@item target (@var{options})
6442@cindex @code{target} function attribute
6443As discussed in @ref{Common Function Attributes}, this attribute
6444allows specification of target-specific compilation options.
6445
6446On the x86, the following options are allowed:
6447@table @samp
6448@item 3dnow
6449@itemx no-3dnow
6450@cindex @code{target("3dnow")} function attribute, x86
6451Enable/disable the generation of the 3DNow!@: instructions.
6452
6453@item 3dnowa
6454@itemx no-3dnowa
6455@cindex @code{target("3dnowa")} function attribute, x86
6456Enable/disable the generation of the enhanced 3DNow!@: instructions.
6457
6458@item abm
6459@itemx no-abm
6460@cindex @code{target("abm")} function attribute, x86
6461Enable/disable the generation of the advanced bit instructions.
6462
6463@item adx
6464@itemx no-adx
6465@cindex @code{target("adx")} function attribute, x86
6466Enable/disable the generation of the ADX instructions.
6467
6468@item aes
6469@itemx no-aes
6470@cindex @code{target("aes")} function attribute, x86
6471Enable/disable the generation of the AES instructions.
6472
6473@item avx
6474@itemx no-avx
6475@cindex @code{target("avx")} function attribute, x86
6476Enable/disable the generation of the AVX instructions.
6477
6478@item avx2
6479@itemx no-avx2
6480@cindex @code{target("avx2")} function attribute, x86
6481Enable/disable the generation of the AVX2 instructions.
6482
6483@item avx5124fmaps
6484@itemx no-avx5124fmaps
6485@cindex @code{target("avx5124fmaps")} function attribute, x86
6486Enable/disable the generation of the AVX5124FMAPS instructions.
6487
6488@item avx5124vnniw
6489@itemx no-avx5124vnniw
6490@cindex @code{target("avx5124vnniw")} function attribute, x86
6491Enable/disable the generation of the AVX5124VNNIW instructions.
6492
6493@item avx512bitalg
6494@itemx no-avx512bitalg
6495@cindex @code{target("avx512bitalg")} function attribute, x86
6496Enable/disable the generation of the AVX512BITALG instructions.
6497
6498@item avx512bw
6499@itemx no-avx512bw
6500@cindex @code{target("avx512bw")} function attribute, x86
6501Enable/disable the generation of the AVX512BW instructions.
6502
6503@item avx512cd
6504@itemx no-avx512cd
6505@cindex @code{target("avx512cd")} function attribute, x86
6506Enable/disable the generation of the AVX512CD instructions.
6507
6508@item avx512dq
6509@itemx no-avx512dq
6510@cindex @code{target("avx512dq")} function attribute, x86
6511Enable/disable the generation of the AVX512DQ instructions.
6512
6513@item avx512er
6514@itemx no-avx512er
6515@cindex @code{target("avx512er")} function attribute, x86
6516Enable/disable the generation of the AVX512ER instructions.
6517
6518@item avx512f
6519@itemx no-avx512f
6520@cindex @code{target("avx512f")} function attribute, x86
6521Enable/disable the generation of the AVX512F instructions.
6522
6523@item avx512ifma
6524@itemx no-avx512ifma
6525@cindex @code{target("avx512ifma")} function attribute, x86
6526Enable/disable the generation of the AVX512IFMA instructions.
6527
6528@item avx512pf
6529@itemx no-avx512pf
6530@cindex @code{target("avx512pf")} function attribute, x86
6531Enable/disable the generation of the AVX512PF instructions.
6532
6533@item avx512vbmi
6534@itemx no-avx512vbmi
6535@cindex @code{target("avx512vbmi")} function attribute, x86
6536Enable/disable the generation of the AVX512VBMI instructions.
6537
6538@item avx512vbmi2
6539@itemx no-avx512vbmi2
6540@cindex @code{target("avx512vbmi2")} function attribute, x86
6541Enable/disable the generation of the AVX512VBMI2 instructions.
6542
6543@item avx512vl
6544@itemx no-avx512vl
6545@cindex @code{target("avx512vl")} function attribute, x86
6546Enable/disable the generation of the AVX512VL instructions.
6547
6548@item avx512vnni
6549@itemx no-avx512vnni
6550@cindex @code{target("avx512vnni")} function attribute, x86
6551Enable/disable the generation of the AVX512VNNI instructions.
6552
6553@item avx512vpopcntdq
6554@itemx no-avx512vpopcntdq
6555@cindex @code{target("avx512vpopcntdq")} function attribute, x86
6556Enable/disable the generation of the AVX512VPOPCNTDQ instructions.
6557
6558@item bmi
6559@itemx no-bmi
6560@cindex @code{target("bmi")} function attribute, x86
6561Enable/disable the generation of the BMI instructions.
6562
6563@item bmi2
6564@itemx no-bmi2
6565@cindex @code{target("bmi2")} function attribute, x86
6566Enable/disable the generation of the BMI2 instructions.
6567
6568@item cldemote
6569@itemx no-cldemote
6570@cindex @code{target("cldemote")} function attribute, x86
6571Enable/disable the generation of the CLDEMOTE instructions.
6572
6573@item clflushopt
6574@itemx no-clflushopt
6575@cindex @code{target("clflushopt")} function attribute, x86
6576Enable/disable the generation of the CLFLUSHOPT instructions.
6577
6578@item clwb
6579@itemx no-clwb
6580@cindex @code{target("clwb")} function attribute, x86
6581Enable/disable the generation of the CLWB instructions.
6582
6583@item clzero
6584@itemx no-clzero
6585@cindex @code{target("clzero")} function attribute, x86
6586Enable/disable the generation of the CLZERO instructions.
6587
6588@item crc32
6589@itemx no-crc32
6590@cindex @code{target("crc32")} function attribute, x86
6591Enable/disable the generation of the CRC32 instructions.
6592
6593@item cx16
6594@itemx no-cx16
6595@cindex @code{target("cx16")} function attribute, x86
6596Enable/disable the generation of the CMPXCHG16B instructions.
6597
6598@item default
6599@cindex @code{target("default")} function attribute, x86
6600@xref{Function Multiversioning}, where it is used to specify the
6601default function version.
6602
6603@item f16c
6604@itemx no-f16c
6605@cindex @code{target("f16c")} function attribute, x86
6606Enable/disable the generation of the F16C instructions.
6607
6608@item fma
6609@itemx no-fma
6610@cindex @code{target("fma")} function attribute, x86
6611Enable/disable the generation of the FMA instructions.
6612
6613@item fma4
6614@itemx no-fma4
6615@cindex @code{target("fma4")} function attribute, x86
6616Enable/disable the generation of the FMA4 instructions.
6617
6618@item fsgsbase
6619@itemx no-fsgsbase
6620@cindex @code{target("fsgsbase")} function attribute, x86
6621Enable/disable the generation of the FSGSBASE instructions.
6622
6623@item fxsr
6624@itemx no-fxsr
6625@cindex @code{target("fxsr")} function attribute, x86
6626Enable/disable the generation of the FXSR instructions.
6627
6628@item gfni
6629@itemx no-gfni
6630@cindex @code{target("gfni")} function attribute, x86
6631Enable/disable the generation of the GFNI instructions.
6632
6633@item hle
6634@itemx no-hle
6635@cindex @code{target("hle")} function attribute, x86
6636Enable/disable the generation of the HLE instruction prefixes.
6637
6638@item lwp
6639@itemx no-lwp
6640@cindex @code{target("lwp")} function attribute, x86
6641Enable/disable the generation of the LWP instructions.
6642
6643@item lzcnt
6644@itemx no-lzcnt
6645@cindex @code{target("lzcnt")} function attribute, x86
6646Enable/disable the generation of the LZCNT instructions.
6647
6648@item mmx
6649@itemx no-mmx
6650@cindex @code{target("mmx")} function attribute, x86
6651Enable/disable the generation of the MMX instructions.
6652
6653@item movbe
6654@itemx no-movbe
6655@cindex @code{target("movbe")} function attribute, x86
6656Enable/disable the generation of the MOVBE instructions.
6657
6658@item movdir64b
6659@itemx no-movdir64b
6660@cindex @code{target("movdir64b")} function attribute, x86
6661Enable/disable the generation of the MOVDIR64B instructions.
6662
6663@item movdiri
6664@itemx no-movdiri
6665@cindex @code{target("movdiri")} function attribute, x86
6666Enable/disable the generation of the MOVDIRI instructions.
6667
6668@item mwaitx
6669@itemx no-mwaitx
6670@cindex @code{target("mwaitx")} function attribute, x86
6671Enable/disable the generation of the MWAITX instructions.
6672
6673@item pclmul
6674@itemx no-pclmul
6675@cindex @code{target("pclmul")} function attribute, x86
6676Enable/disable the generation of the PCLMUL instructions.
6677
6678@item pconfig
6679@itemx no-pconfig
6680@cindex @code{target("pconfig")} function attribute, x86
6681Enable/disable the generation of the PCONFIG instructions.
6682
6683@item pku
6684@itemx no-pku
6685@cindex @code{target("pku")} function attribute, x86
6686Enable/disable the generation of the PKU instructions.
6687
6688@item popcnt
6689@itemx no-popcnt
6690@cindex @code{target("popcnt")} function attribute, x86
6691Enable/disable the generation of the POPCNT instruction.
6692
6693@item prefetchwt1
6694@itemx no-prefetchwt1
6695@cindex @code{target("prefetchwt1")} function attribute, x86
6696Enable/disable the generation of the PREFETCHWT1 instructions.
6697
6698@item prfchw
6699@itemx no-prfchw
6700@cindex @code{target("prfchw")} function attribute, x86
6701Enable/disable the generation of the PREFETCHW instruction.
6702
6703@item ptwrite
6704@itemx no-ptwrite
6705@cindex @code{target("ptwrite")} function attribute, x86
6706Enable/disable the generation of the PTWRITE instructions.
6707
6708@item rdpid
6709@itemx no-rdpid
6710@cindex @code{target("rdpid")} function attribute, x86
6711Enable/disable the generation of the RDPID instructions.
6712
6713@item rdrnd
6714@itemx no-rdrnd
6715@cindex @code{target("rdrnd")} function attribute, x86
6716Enable/disable the generation of the RDRND instructions.
6717
6718@item rdseed
6719@itemx no-rdseed
6720@cindex @code{target("rdseed")} function attribute, x86
6721Enable/disable the generation of the RDSEED instructions.
6722
6723@item rtm
6724@itemx no-rtm
6725@cindex @code{target("rtm")} function attribute, x86
6726Enable/disable the generation of the RTM instructions.
6727
6728@item sahf
6729@itemx no-sahf
6730@cindex @code{target("sahf")} function attribute, x86
6731Enable/disable the generation of the SAHF instructions.
6732
6733@item sgx
6734@itemx no-sgx
6735@cindex @code{target("sgx")} function attribute, x86
6736Enable/disable the generation of the SGX instructions.
6737
6738@item sha
6739@itemx no-sha
6740@cindex @code{target("sha")} function attribute, x86
6741Enable/disable the generation of the SHA instructions.
6742
6743@item shstk
6744@itemx no-shstk
6745@cindex @code{target("shstk")} function attribute, x86
6746Enable/disable the shadow stack built-in functions from CET.
6747
6748@item sse
6749@itemx no-sse
6750@cindex @code{target("sse")} function attribute, x86
6751Enable/disable the generation of the SSE instructions.
6752
6753@item sse2
6754@itemx no-sse2
6755@cindex @code{target("sse2")} function attribute, x86
6756Enable/disable the generation of the SSE2 instructions.
6757
6758@item sse3
6759@itemx no-sse3
6760@cindex @code{target("sse3")} function attribute, x86
6761Enable/disable the generation of the SSE3 instructions.
6762
6763@item sse4
6764@itemx no-sse4
6765@cindex @code{target("sse4")} function attribute, x86
6766Enable/disable the generation of the SSE4 instructions (both SSE4.1
6767and SSE4.2).
6768
6769@item sse4.1
6770@itemx no-sse4.1
6771@cindex @code{target("sse4.1")} function attribute, x86
6772Enable/disable the generation of the sse4.1 instructions.
6773
6774@item sse4.2
6775@itemx no-sse4.2
6776@cindex @code{target("sse4.2")} function attribute, x86
6777Enable/disable the generation of the sse4.2 instructions.
6778
6779@item sse4a
6780@itemx no-sse4a
6781@cindex @code{target("sse4a")} function attribute, x86
6782Enable/disable the generation of the SSE4A instructions.
6783
6784@item ssse3
6785@itemx no-ssse3
6786@cindex @code{target("ssse3")} function attribute, x86
6787Enable/disable the generation of the SSSE3 instructions.
6788
6789@item tbm
6790@itemx no-tbm
6791@cindex @code{target("tbm")} function attribute, x86
6792Enable/disable the generation of the TBM instructions.
6793
6794@item vaes
6795@itemx no-vaes
6796@cindex @code{target("vaes")} function attribute, x86
6797Enable/disable the generation of the VAES instructions.
6798
6799@item vpclmulqdq
6800@itemx no-vpclmulqdq
6801@cindex @code{target("vpclmulqdq")} function attribute, x86
6802Enable/disable the generation of the VPCLMULQDQ instructions.
6803
6804@item waitpkg
6805@itemx no-waitpkg
6806@cindex @code{target("waitpkg")} function attribute, x86
6807Enable/disable the generation of the WAITPKG instructions.
6808
6809@item wbnoinvd
6810@itemx no-wbnoinvd
6811@cindex @code{target("wbnoinvd")} function attribute, x86
6812Enable/disable the generation of the WBNOINVD instructions.
6813
6814@item xop
6815@itemx no-xop
6816@cindex @code{target("xop")} function attribute, x86
6817Enable/disable the generation of the XOP instructions.
6818
6819@item xsave
6820@itemx no-xsave
6821@cindex @code{target("xsave")} function attribute, x86
6822Enable/disable the generation of the XSAVE instructions.
6823
6824@item xsavec
6825@itemx no-xsavec
6826@cindex @code{target("xsavec")} function attribute, x86
6827Enable/disable the generation of the XSAVEC instructions.
6828
6829@item xsaveopt
6830@itemx no-xsaveopt
6831@cindex @code{target("xsaveopt")} function attribute, x86
6832Enable/disable the generation of the XSAVEOPT instructions.
6833
6834@item xsaves
6835@itemx no-xsaves
6836@cindex @code{target("xsaves")} function attribute, x86
6837Enable/disable the generation of the XSAVES instructions.
6838
6839@item amx-tile
6840@itemx no-amx-tile
6841@cindex @code{target("amx-tile")} function attribute, x86
6842Enable/disable the generation of the AMX-TILE instructions.
6843
6844@item amx-int8
6845@itemx no-amx-int8
6846@cindex @code{target("amx-int8")} function attribute, x86
6847Enable/disable the generation of the AMX-INT8 instructions.
6848
6849@item amx-bf16
6850@itemx no-amx-bf16
6851@cindex @code{target("amx-bf16")} function attribute, x86
6852Enable/disable the generation of the AMX-BF16 instructions.
6853
6854@item uintr
6855@itemx no-uintr
6856@cindex @code{target("uintr")} function attribute, x86
6857Enable/disable the generation of the UINTR instructions.
6858
6859@item hreset
6860@itemx no-hreset
6861@cindex @code{target("hreset")} function attribute, x86
6862Enable/disable the generation of the HRESET instruction.
6863
6864@item kl
6865@itemx no-kl
6866@cindex @code{target("kl")} function attribute, x86
6867Enable/disable the generation of the KEYLOCKER instructions.
6868
6869@item widekl
6870@itemx no-widekl
6871@cindex @code{target("widekl")} function attribute, x86
6872Enable/disable the generation of the WIDEKL instructions.
6873
6874@item avxvnni
6875@itemx no-avxvnni
6876@cindex @code{target("avxvnni")} function attribute, x86
6877Enable/disable the generation of the AVXVNNI instructions.
6878
6879@item cld
6880@itemx no-cld
6881@cindex @code{target("cld")} function attribute, x86
6882Enable/disable the generation of the CLD before string moves.
6883
6884@item fancy-math-387
6885@itemx no-fancy-math-387
6886@cindex @code{target("fancy-math-387")} function attribute, x86
6887Enable/disable the generation of the @code{sin}, @code{cos}, and
6888@code{sqrt} instructions on the 387 floating-point unit.
6889
6890@item ieee-fp
6891@itemx no-ieee-fp
6892@cindex @code{target("ieee-fp")} function attribute, x86
6893Enable/disable the generation of floating point that depends on IEEE arithmetic.
6894
6895@item inline-all-stringops
6896@itemx no-inline-all-stringops
6897@cindex @code{target("inline-all-stringops")} function attribute, x86
6898Enable/disable inlining of string operations.
6899
6900@item inline-stringops-dynamically
6901@itemx no-inline-stringops-dynamically
6902@cindex @code{target("inline-stringops-dynamically")} function attribute, x86
6903Enable/disable the generation of the inline code to do small string
6904operations and calling the library routines for large operations.
6905
6906@item align-stringops
6907@itemx no-align-stringops
6908@cindex @code{target("align-stringops")} function attribute, x86
6909Do/do not align destination of inlined string operations.
6910
6911@item recip
6912@itemx no-recip
6913@cindex @code{target("recip")} function attribute, x86
6914Enable/disable the generation of RCPSS, RCPPS, RSQRTSS and RSQRTPS
6915instructions followed an additional Newton-Raphson step instead of
6916doing a floating-point division.
6917
6918@item general-regs-only
6919@cindex @code{target("general-regs-only")} function attribute, x86
6920Generate code which uses only the general registers.
6921
6922@item arch=@var{ARCH}
6923@cindex @code{target("arch=@var{ARCH}")} function attribute, x86
6924Specify the architecture to generate code for in compiling the function.
6925
6926@item tune=@var{TUNE}
6927@cindex @code{target("tune=@var{TUNE}")} function attribute, x86
6928Specify the architecture to tune for in compiling the function.
6929
6930@item fpmath=@var{FPMATH}
6931@cindex @code{target("fpmath=@var{FPMATH}")} function attribute, x86
6932Specify which floating-point unit to use.  You must specify the
6933@code{target("fpmath=sse,387")} option as
6934@code{target("fpmath=sse+387")} because the comma would separate
6935different options.
6936
6937@item prefer-vector-width=@var{OPT}
6938@cindex @code{prefer-vector-width} function attribute, x86
6939On x86 targets, the @code{prefer-vector-width} attribute informs the
6940compiler to use @var{OPT}-bit vector width in instructions
6941instead of the default on the selected platform.
6942
6943Valid @var{OPT} values are:
6944
6945@table @samp
6946@item none
6947No extra limitations applied to GCC other than defined by the selected platform.
6948
6949@item 128
6950Prefer 128-bit vector width for instructions.
6951
6952@item 256
6953Prefer 256-bit vector width for instructions.
6954
6955@item 512
6956Prefer 512-bit vector width for instructions.
6957@end table
6958
6959On the x86, the inliner does not inline a
6960function that has different target options than the caller, unless the
6961callee has a subset of the target options of the caller.  For example
6962a function declared with @code{target("sse3")} can inline a function
6963with @code{target("sse2")}, since @code{-msse3} implies @code{-msse2}.
6964@end table
6965
6966@item indirect_branch("@var{choice}")
6967@cindex @code{indirect_branch} function attribute, x86
6968On x86 targets, the @code{indirect_branch} attribute causes the compiler
6969to convert indirect call and jump with @var{choice}.  @samp{keep}
6970keeps indirect call and jump unmodified.  @samp{thunk} converts indirect
6971call and jump to call and return thunk.  @samp{thunk-inline} converts
6972indirect call and jump to inlined call and return thunk.
6973@samp{thunk-extern} converts indirect call and jump to external call
6974and return thunk provided in a separate object file.
6975
6976@item function_return("@var{choice}")
6977@cindex @code{function_return} function attribute, x86
6978On x86 targets, the @code{function_return} attribute causes the compiler
6979to convert function return with @var{choice}.  @samp{keep} keeps function
6980return unmodified.  @samp{thunk} converts function return to call and
6981return thunk.  @samp{thunk-inline} converts function return to inlined
6982call and return thunk.  @samp{thunk-extern} converts function return to
6983external call and return thunk provided in a separate object file.
6984
6985@item nocf_check
6986@cindex @code{nocf_check} function attribute
6987The @code{nocf_check} attribute on a function is used to inform the
6988compiler that the function's prologue should not be instrumented when
6989compiled with the @option{-fcf-protection=branch} option.  The
6990compiler assumes that the function's address is a valid target for a
6991control-flow transfer.
6992
6993The @code{nocf_check} attribute on a type of pointer to function is
6994used to inform the compiler that a call through the pointer should
6995not be instrumented when compiled with the
6996@option{-fcf-protection=branch} option.  The compiler assumes
6997that the function's address from the pointer is a valid target for
6998a control-flow transfer.  A direct function call through a function
6999name is assumed to be a safe call thus direct calls are not
7000instrumented by the compiler.
7001
7002The @code{nocf_check} attribute is applied to an object's type.
7003In case of assignment of a function address or a function pointer to
7004another pointer, the attribute is not carried over from the right-hand
7005object's type; the type of left-hand object stays unchanged.  The
7006compiler checks for @code{nocf_check} attribute mismatch and reports
7007a warning in case of mismatch.
7008
7009@smallexample
7010@{
7011int foo (void) __attribute__(nocf_check);
7012void (*foo1)(void) __attribute__(nocf_check);
7013void (*foo2)(void);
7014
7015/* foo's address is assumed to be valid.  */
7016int
7017foo (void)
7018
7019  /* This call site is not checked for control-flow
7020     validity.  */
7021  (*foo1)();
7022
7023  /* A warning is issued about attribute mismatch.  */
7024  foo1 = foo2;
7025
7026  /* This call site is still not checked.  */
7027  (*foo1)();
7028
7029  /* This call site is checked.  */
7030  (*foo2)();
7031
7032  /* A warning is issued about attribute mismatch.  */
7033  foo2 = foo1;
7034
7035  /* This call site is still checked.  */
7036  (*foo2)();
7037
7038  return 0;
7039@}
7040@end smallexample
7041
7042@item cf_check
7043@cindex @code{cf_check} function attribute, x86
7044
7045The @code{cf_check} attribute on a function is used to inform the
7046compiler that ENDBR instruction should be placed at the function
7047entry when @option{-fcf-protection=branch} is enabled.
7048
7049@item indirect_return
7050@cindex @code{indirect_return} function attribute, x86
7051
7052The @code{indirect_return} attribute can be applied to a function,
7053as well as variable or type of function pointer to inform the
7054compiler that the function may return via indirect branch.
7055
7056@item fentry_name("@var{name}")
7057@cindex @code{fentry_name} function attribute, x86
7058On x86 targets, the @code{fentry_name} attribute sets the function to
7059call on function entry when function instrumentation is enabled
7060with @option{-pg -mfentry}. When @var{name} is nop then a 5 byte
7061nop sequence is generated.
7062
7063@item fentry_section("@var{name}")
7064@cindex @code{fentry_section} function attribute, x86
7065On x86 targets, the @code{fentry_section} attribute sets the name
7066of the section to record function entry instrumentation calls in when
7067enabled with @option{-pg -mrecord-mcount}
7068
7069@end table
7070
7071@node Xstormy16 Function Attributes
7072@subsection Xstormy16 Function Attributes
7073
7074These function attributes are supported by the Xstormy16 back end:
7075
7076@table @code
7077@item interrupt
7078@cindex @code{interrupt} function attribute, Xstormy16
7079Use this attribute to indicate
7080that the specified function is an interrupt handler.  The compiler generates
7081function entry and exit sequences suitable for use in an interrupt handler
7082when this attribute is present.
7083@end table
7084
7085@node Variable Attributes
7086@section Specifying Attributes of Variables
7087@cindex attribute of variables
7088@cindex variable attributes
7089
7090The keyword @code{__attribute__} allows you to specify special properties
7091of variables, function parameters, or structure, union, and, in C++, class
7092members.  This @code{__attribute__} keyword is followed by an attribute
7093specification enclosed in double parentheses.  Some attributes are currently
7094defined generically for variables.  Other attributes are defined for
7095variables on particular target systems.  Other attributes are available
7096for functions (@pxref{Function Attributes}), labels (@pxref{Label Attributes}),
7097enumerators (@pxref{Enumerator Attributes}), statements
7098(@pxref{Statement Attributes}), and for types (@pxref{Type Attributes}).
7099Other front ends might define more attributes
7100(@pxref{C++ Extensions,,Extensions to the C++ Language}).
7101
7102@xref{Attribute Syntax}, for details of the exact syntax for using
7103attributes.
7104
7105@menu
7106* Common Variable Attributes::
7107* ARC Variable Attributes::
7108* AVR Variable Attributes::
7109* Blackfin Variable Attributes::
7110* H8/300 Variable Attributes::
7111* IA-64 Variable Attributes::
7112* M32R/D Variable Attributes::
7113* MeP Variable Attributes::
7114* Microsoft Windows Variable Attributes::
7115* MSP430 Variable Attributes::
7116* Nvidia PTX Variable Attributes::
7117* PowerPC Variable Attributes::
7118* RL78 Variable Attributes::
7119* V850 Variable Attributes::
7120* x86 Variable Attributes::
7121* Xstormy16 Variable Attributes::
7122@end menu
7123
7124@node Common Variable Attributes
7125@subsection Common Variable Attributes
7126
7127The following attributes are supported on most targets.
7128
7129@table @code
7130
7131@item alias ("@var{target}")
7132@cindex @code{alias} variable attribute
7133The @code{alias} variable attribute causes the declaration to be emitted
7134as an alias for another symbol known as an @dfn{alias target}.  Except
7135for top-level qualifiers the alias target must have the same type as
7136the alias.  For instance, the following
7137
7138@smallexample
7139int var_target;
7140extern int __attribute__ ((alias ("var_target"))) var_alias;
7141@end smallexample
7142
7143@noindent
7144defines @code{var_alias} to be an alias for the @code{var_target} variable.
7145
7146It is an error if the alias target is not defined in the same translation
7147unit as the alias.
7148
7149Note that in the absence of the attribute GCC assumes that distinct
7150declarations with external linkage denote distinct objects.  Using both
7151the alias and the alias target to access the same object is undefined
7152in a translation unit without a declaration of the alias with the attribute.
7153
7154This attribute requires assembler and object file support, and may not be
7155available on all targets.
7156
7157@cindex @code{aligned} variable attribute
7158@item aligned
7159@itemx aligned (@var{alignment})
7160The @code{aligned} attribute specifies a minimum alignment for the variable
7161or structure field, measured in bytes.  When specified, @var{alignment} must
7162be an integer constant power of 2.  Specifying no @var{alignment} argument
7163implies the maximum alignment for the target, which is often, but by no
7164means always, 8 or 16 bytes.
7165
7166For example, the declaration:
7167
7168@smallexample
7169int x __attribute__ ((aligned (16))) = 0;
7170@end smallexample
7171
7172@noindent
7173causes the compiler to allocate the global variable @code{x} on a
717416-byte boundary.  On a 68040, this could be used in conjunction with
7175an @code{asm} expression to access the @code{move16} instruction which
7176requires 16-byte aligned operands.
7177
7178You can also specify the alignment of structure fields.  For example, to
7179create a double-word aligned @code{int} pair, you could write:
7180
7181@smallexample
7182struct foo @{ int x[2] __attribute__ ((aligned (8))); @};
7183@end smallexample
7184
7185@noindent
7186This is an alternative to creating a union with a @code{double} member,
7187which forces the union to be double-word aligned.
7188
7189As in the preceding examples, you can explicitly specify the alignment
7190(in bytes) that you wish the compiler to use for a given variable or
7191structure field.  Alternatively, you can leave out the alignment factor
7192and just ask the compiler to align a variable or field to the
7193default alignment for the target architecture you are compiling for.
7194The default alignment is sufficient for all scalar types, but may not be
7195enough for all vector types on a target that supports vector operations.
7196The default alignment is fixed for a particular target ABI.
7197
7198GCC also provides a target specific macro @code{__BIGGEST_ALIGNMENT__},
7199which is the largest alignment ever used for any data type on the
7200target machine you are compiling for.  For example, you could write:
7201
7202@smallexample
7203short array[3] __attribute__ ((aligned (__BIGGEST_ALIGNMENT__)));
7204@end smallexample
7205
7206The compiler automatically sets the alignment for the declared
7207variable or field to @code{__BIGGEST_ALIGNMENT__}.  Doing this can
7208often make copy operations more efficient, because the compiler can
7209use whatever instructions copy the biggest chunks of memory when
7210performing copies to or from the variables or fields that you have
7211aligned this way.  Note that the value of @code{__BIGGEST_ALIGNMENT__}
7212may change depending on command-line options.
7213
7214When used on a struct, or struct member, the @code{aligned} attribute can
7215only increase the alignment; in order to decrease it, the @code{packed}
7216attribute must be specified as well.  When used as part of a typedef, the
7217@code{aligned} attribute can both increase and decrease alignment, and
7218specifying the @code{packed} attribute generates a warning.
7219
7220Note that the effectiveness of @code{aligned} attributes for static
7221variables may be limited by inherent limitations in the system linker
7222and/or object file format.  On some systems, the linker is
7223only able to arrange for variables to be aligned up to a certain maximum
7224alignment.  (For some linkers, the maximum supported alignment may
7225be very very small.)  If your linker is only able to align variables
7226up to a maximum of 8-byte alignment, then specifying @code{aligned(16)}
7227in an @code{__attribute__} still only provides you with 8-byte
7228alignment.  See your linker documentation for further information.
7229
7230Stack variables are not affected by linker restrictions; GCC can properly
7231align them on any target.
7232
7233The @code{aligned} attribute can also be used for functions
7234(@pxref{Common Function Attributes}.)
7235
7236@cindex @code{warn_if_not_aligned} variable attribute
7237@item warn_if_not_aligned (@var{alignment})
7238This attribute specifies a threshold for the structure field, measured
7239in bytes.  If the structure field is aligned below the threshold, a
7240warning will be issued.  For example, the declaration:
7241
7242@smallexample
7243struct foo
7244@{
7245  int i1;
7246  int i2;
7247  unsigned long long x __attribute__ ((warn_if_not_aligned (16)));
7248@};
7249@end smallexample
7250
7251@noindent
7252causes the compiler to issue an warning on @code{struct foo}, like
7253@samp{warning: alignment 8 of 'struct foo' is less than 16}.
7254The compiler also issues a warning, like @samp{warning: 'x' offset
72558 in 'struct foo' isn't aligned to 16}, when the structure field has
7256the misaligned offset:
7257
7258@smallexample
7259struct __attribute__ ((aligned (16))) foo
7260@{
7261  int i1;
7262  int i2;
7263  unsigned long long x __attribute__ ((warn_if_not_aligned (16)));
7264@};
7265@end smallexample
7266
7267This warning can be disabled by @option{-Wno-if-not-aligned}.
7268The @code{warn_if_not_aligned} attribute can also be used for types
7269(@pxref{Common Type Attributes}.)
7270
7271@item alloc_size (@var{position})
7272@itemx alloc_size (@var{position-1}, @var{position-2})
7273@cindex @code{alloc_size} variable attribute
7274The @code{alloc_size} variable attribute may be applied to the declaration
7275of a pointer to a function that returns a pointer and takes at least one
7276argument of an integer type.  It indicates that the returned pointer points
7277to an object whose size is given by the function argument at @var{position-1},
7278or by the product of the arguments at @var{position-1} and @var{position-2}.
7279Meaningful sizes are positive values less than @code{PTRDIFF_MAX}.  Other
7280sizes are disagnosed when detected.  GCC uses this information to improve
7281the results of @code{__builtin_object_size}.
7282
7283For instance, the following declarations
7284
7285@smallexample
7286typedef __attribute__ ((alloc_size (1, 2))) void*
7287  (*calloc_ptr) (size_t, size_t);
7288typedef __attribute__ ((alloc_size (1))) void*
7289  (*malloc_ptr) (size_t);
7290@end smallexample
7291
7292@noindent
7293specify that @code{calloc_ptr} is a pointer of a function that, like
7294the standard C function @code{calloc}, returns an object whose size
7295is given by the product of arguments 1 and 2, and similarly, that
7296@code{malloc_ptr}, like the standard C function @code{malloc},
7297returns an object whose size is given by argument 1 to the function.
7298
7299@item cleanup (@var{cleanup_function})
7300@cindex @code{cleanup} variable attribute
7301The @code{cleanup} attribute runs a function when the variable goes
7302out of scope.  This attribute can only be applied to auto function
7303scope variables; it may not be applied to parameters or variables
7304with static storage duration.  The function must take one parameter,
7305a pointer to a type compatible with the variable.  The return value
7306of the function (if any) is ignored.
7307
7308If @option{-fexceptions} is enabled, then @var{cleanup_function}
7309is run during the stack unwinding that happens during the
7310processing of the exception.  Note that the @code{cleanup} attribute
7311does not allow the exception to be caught, only to perform an action.
7312It is undefined what happens if @var{cleanup_function} does not
7313return normally.
7314
7315@item common
7316@itemx nocommon
7317@cindex @code{common} variable attribute
7318@cindex @code{nocommon} variable attribute
7319@opindex fcommon
7320@opindex fno-common
7321The @code{common} attribute requests GCC to place a variable in
7322``common'' storage.  The @code{nocommon} attribute requests the
7323opposite---to allocate space for it directly.
7324
7325These attributes override the default chosen by the
7326@option{-fno-common} and @option{-fcommon} flags respectively.
7327
7328@item copy
7329@itemx copy (@var{variable})
7330@cindex @code{copy} variable attribute
7331The @code{copy} attribute applies the set of attributes with which
7332@var{variable} has been declared to the declaration of the variable
7333to which the attribute is applied.  The attribute is designed for
7334libraries that define aliases that are expected to specify the same
7335set of attributes as the aliased symbols.  The @code{copy} attribute
7336can be used with variables, functions or types.  However, the kind
7337of symbol to which the attribute is applied (either varible or
7338function) must match the kind of symbol to which the argument refers.
7339The @code{copy} attribute copies only syntactic and semantic attributes
7340but not attributes that affect a symbol's linkage or visibility such as
7341@code{alias}, @code{visibility}, or @code{weak}.  The @code{deprecated}
7342attribute is also not copied.  @xref{Common Function Attributes}.
7343@xref{Common Type Attributes}.
7344
7345@item deprecated
7346@itemx deprecated (@var{msg})
7347@cindex @code{deprecated} variable attribute
7348The @code{deprecated} attribute results in a warning if the variable
7349is used anywhere in the source file.  This is useful when identifying
7350variables that are expected to be removed in a future version of a
7351program.  The warning also includes the location of the declaration
7352of the deprecated variable, to enable users to easily find further
7353information about why the variable is deprecated, or what they should
7354do instead.  Note that the warning only occurs for uses:
7355
7356@smallexample
7357extern int old_var __attribute__ ((deprecated));
7358extern int old_var;
7359int new_fn () @{ return old_var; @}
7360@end smallexample
7361
7362@noindent
7363results in a warning on line 3 but not line 2.  The optional @var{msg}
7364argument, which must be a string, is printed in the warning if
7365present.
7366
7367The @code{deprecated} attribute can also be used for functions and
7368types (@pxref{Common Function Attributes},
7369@pxref{Common Type Attributes}).
7370
7371The message attached to the attribute is affected by the setting of
7372the @option{-fmessage-length} option.
7373
7374@item mode (@var{mode})
7375@cindex @code{mode} variable attribute
7376This attribute specifies the data type for the declaration---whichever
7377type corresponds to the mode @var{mode}.  This in effect lets you
7378request an integer or floating-point type according to its width.
7379
7380@xref{Machine Modes,,, gccint, GNU Compiler Collection (GCC) Internals},
7381for a list of the possible keywords for @var{mode}.
7382You may also specify a mode of @code{byte} or @code{__byte__} to
7383indicate the mode corresponding to a one-byte integer, @code{word} or
7384@code{__word__} for the mode of a one-word integer, and @code{pointer}
7385or @code{__pointer__} for the mode used to represent pointers.
7386
7387@item nonstring
7388@cindex @code{nonstring} variable attribute
7389The @code{nonstring} variable attribute specifies that an object or member
7390declaration with type array of @code{char}, @code{signed char}, or
7391@code{unsigned char}, or pointer to such a type is intended to store
7392character arrays that do not necessarily contain a terminating @code{NUL}.
7393This is useful in detecting uses of such arrays or pointers with functions
7394that expect @code{NUL}-terminated strings, and to avoid warnings when such
7395an array or pointer is used as an argument to a bounded string manipulation
7396function such as @code{strncpy}.  For example, without the attribute, GCC
7397will issue a warning for the @code{strncpy} call below because it may
7398truncate the copy without appending the terminating @code{NUL} character.
7399Using the attribute makes it possible to suppress the warning.  However,
7400when the array is declared with the attribute the call to @code{strlen} is
7401diagnosed because when the array doesn't contain a @code{NUL}-terminated
7402string the call is undefined.  To copy, compare, of search non-string
7403character arrays use the @code{memcpy}, @code{memcmp}, @code{memchr},
7404and other functions that operate on arrays of bytes.  In addition,
7405calling @code{strnlen} and @code{strndup} with such arrays is safe
7406provided a suitable bound is specified, and not diagnosed.
7407
7408@smallexample
7409struct Data
7410@{
7411  char name [32] __attribute__ ((nonstring));
7412@};
7413
7414int f (struct Data *pd, const char *s)
7415@{
7416  strncpy (pd->name, s, sizeof pd->name);
7417  @dots{}
7418  return strlen (pd->name);   // unsafe, gets a warning
7419@}
7420@end smallexample
7421
7422@item packed
7423@cindex @code{packed} variable attribute
7424The @code{packed} attribute specifies that a structure member should have
7425the smallest possible alignment---one bit for a bit-field and one byte
7426otherwise, unless a larger value is specified with the @code{aligned}
7427attribute.  The attribute does not apply to non-member objects.
7428
7429For example in the structure below, the member array @code{x} is packed
7430so that it immediately follows @code{a} with no intervening padding:
7431
7432@smallexample
7433struct foo
7434@{
7435  char a;
7436  int x[2] __attribute__ ((packed));
7437@};
7438@end smallexample
7439
7440@emph{Note:} The 4.1, 4.2 and 4.3 series of GCC ignore the
7441@code{packed} attribute on bit-fields of type @code{char}.  This has
7442been fixed in GCC 4.4 but the change can lead to differences in the
7443structure layout.  See the documentation of
7444@option{-Wpacked-bitfield-compat} for more information.
7445
7446@item section ("@var{section-name}")
7447@cindex @code{section} variable attribute
7448Normally, the compiler places the objects it generates in sections like
7449@code{data} and @code{bss}.  Sometimes, however, you need additional sections,
7450or you need certain particular variables to appear in special sections,
7451for example to map to special hardware.  The @code{section}
7452attribute specifies that a variable (or function) lives in a particular
7453section.  For example, this small program uses several specific section names:
7454
7455@smallexample
7456struct duart a __attribute__ ((section ("DUART_A"))) = @{ 0 @};
7457struct duart b __attribute__ ((section ("DUART_B"))) = @{ 0 @};
7458char stack[10000] __attribute__ ((section ("STACK"))) = @{ 0 @};
7459int init_data __attribute__ ((section ("INITDATA")));
7460
7461main()
7462@{
7463  /* @r{Initialize stack pointer} */
7464  init_sp (stack + sizeof (stack));
7465
7466  /* @r{Initialize initialized data} */
7467  memcpy (&init_data, &data, &edata - &data);
7468
7469  /* @r{Turn on the serial ports} */
7470  init_duart (&a);
7471  init_duart (&b);
7472@}
7473@end smallexample
7474
7475@noindent
7476Use the @code{section} attribute with
7477@emph{global} variables and not @emph{local} variables,
7478as shown in the example.
7479
7480You may use the @code{section} attribute with initialized or
7481uninitialized global variables but the linker requires
7482each object be defined once, with the exception that uninitialized
7483variables tentatively go in the @code{common} (or @code{bss}) section
7484and can be multiply ``defined''.  Using the @code{section} attribute
7485changes what section the variable goes into and may cause the
7486linker to issue an error if an uninitialized variable has multiple
7487definitions.  You can force a variable to be initialized with the
7488@option{-fno-common} flag or the @code{nocommon} attribute.
7489
7490Some file formats do not support arbitrary sections so the @code{section}
7491attribute is not available on all platforms.
7492If you need to map the entire contents of a module to a particular
7493section, consider using the facilities of the linker instead.
7494
7495@item tls_model ("@var{tls_model}")
7496@cindex @code{tls_model} variable attribute
7497The @code{tls_model} attribute sets thread-local storage model
7498(@pxref{Thread-Local}) of a particular @code{__thread} variable,
7499overriding @option{-ftls-model=} command-line switch on a per-variable
7500basis.
7501The @var{tls_model} argument should be one of @code{global-dynamic},
7502@code{local-dynamic}, @code{initial-exec} or @code{local-exec}.
7503
7504Not all targets support this attribute.
7505
7506@item unused
7507@cindex @code{unused} variable attribute
7508This attribute, attached to a variable, means that the variable is meant
7509to be possibly unused.  GCC does not produce a warning for this
7510variable.
7511
7512@item used
7513@cindex @code{used} variable attribute
7514This attribute, attached to a variable with static storage, means that
7515the variable must be emitted even if it appears that the variable is not
7516referenced.
7517
7518When applied to a static data member of a C++ class template, the
7519attribute also means that the member is instantiated if the
7520class itself is instantiated.
7521
7522@item retain
7523@cindex @code{retain} variable attribute
7524For ELF targets that support the GNU or FreeBSD OSABIs, this attribute
7525will save the variable from linker garbage collection.  To support
7526this behavior, variables that have not been placed in specific sections
7527(e.g. by the @code{section} attribute, or the @code{-fdata-sections} option),
7528will be placed in new, unique sections.
7529
7530This additional functionality requires Binutils version 2.36 or later.
7531
7532@item vector_size (@var{bytes})
7533@cindex @code{vector_size} variable attribute
7534This attribute specifies the vector size for the type of the declared
7535variable, measured in bytes.  The type to which it applies is known as
7536the @dfn{base type}.  The @var{bytes} argument must be a positive
7537power-of-two multiple of the base type size.  For example, the declaration:
7538
7539@smallexample
7540int foo __attribute__ ((vector_size (16)));
7541@end smallexample
7542
7543@noindent
7544causes the compiler to set the mode for @code{foo}, to be 16 bytes,
7545divided into @code{int} sized units.  Assuming a 32-bit @code{int},
7546@code{foo}'s type is a vector of four units of four bytes each, and
7547the corresponding mode of @code{foo} is @code{V4SI}.
7548@xref{Vector Extensions}, for details of manipulating vector variables.
7549
7550This attribute is only applicable to integral and floating scalars,
7551although arrays, pointers, and function return values are allowed in
7552conjunction with this construct.
7553
7554Aggregates with this attribute are invalid, even if they are of the same
7555size as a corresponding scalar.  For example, the declaration:
7556
7557@smallexample
7558struct S @{ int a; @};
7559struct S  __attribute__ ((vector_size (16))) foo;
7560@end smallexample
7561
7562@noindent
7563is invalid even if the size of the structure is the same as the size of
7564the @code{int}.
7565
7566@item visibility ("@var{visibility_type}")
7567@cindex @code{visibility} variable attribute
7568This attribute affects the linkage of the declaration to which it is attached.
7569The @code{visibility} attribute is described in
7570@ref{Common Function Attributes}.
7571
7572@item weak
7573@cindex @code{weak} variable attribute
7574The @code{weak} attribute is described in
7575@ref{Common Function Attributes}.
7576
7577@item noinit
7578@cindex @code{noinit} variable attribute
7579Any data with the @code{noinit} attribute will not be initialized by
7580the C runtime startup code, or the program loader.  Not initializing
7581data in this way can reduce program startup times.
7582
7583This attribute is specific to ELF targets and relies on the linker
7584script to place sections with the @code{.noinit} prefix in the right
7585location.
7586
7587@item persistent
7588@cindex @code{persistent} variable attribute
7589Any data with the @code{persistent} attribute will not be initialized by
7590the C runtime startup code, but will be initialized by the program
7591loader.  This enables the value of the variable to @samp{persist}
7592between processor resets.
7593
7594This attribute is specific to ELF targets and relies on the linker
7595script to place the sections with the @code{.persistent} prefix in the
7596right location.  Specifically, some type of non-volatile, writeable
7597memory is required.
7598
7599@item objc_nullability (@var{nullability kind}) @r{(Objective-C and Objective-C++ only)}
7600@cindex @code{objc_nullability} variable attribute
7601This attribute applies to pointer variables only.  It allows marking the
7602pointer with one of four possible values describing the conditions under
7603which the pointer might have a @code{nil} value. In most cases, the
7604attribute is intended to be an internal representation for property and
7605method nullability (specified by language keywords); it is not recommended
7606to use it directly.
7607
7608When @var{nullability kind} is @code{"unspecified"} or @code{0}, nothing is
7609known about the conditions in which the pointer might be @code{nil}. Making
7610this state specific serves to avoid false positives in diagnostics.
7611
7612When @var{nullability kind} is @code{"nonnull"} or @code{1}, the pointer has
7613no meaning if it is @code{nil} and thus the compiler is free to emit
7614diagnostics if it can be determined that the value will be @code{nil}.
7615
7616When @var{nullability kind} is @code{"nullable"} or @code{2}, the pointer might
7617be @code{nil} and carry meaning as such.
7618
7619When @var{nullability kind} is @code{"resettable"} or @code{3} (used only in
7620the context of property attribute lists) this describes the case in which a
7621property setter may take the value @code{nil} (which perhaps causes the
7622property to be reset in some manner to a default) but for which the property
7623getter will never validly return @code{nil}.
7624
7625@end table
7626
7627@node ARC Variable Attributes
7628@subsection ARC Variable Attributes
7629
7630@table @code
7631@item aux
7632@cindex @code{aux} variable attribute, ARC
7633The @code{aux} attribute is used to directly access the ARC's
7634auxiliary register space from C.  The auxilirary register number is
7635given via attribute argument.
7636
7637@end table
7638
7639@node AVR Variable Attributes
7640@subsection AVR Variable Attributes
7641
7642@table @code
7643@item progmem
7644@cindex @code{progmem} variable attribute, AVR
7645The @code{progmem} attribute is used on the AVR to place read-only
7646data in the non-volatile program memory (flash). The @code{progmem}
7647attribute accomplishes this by putting respective variables into a
7648section whose name starts with @code{.progmem}.
7649
7650This attribute works similar to the @code{section} attribute
7651but adds additional checking.
7652
7653@table @asis
7654@item @bullet{}@tie{} Ordinary AVR cores with 32 general purpose registers:
7655@code{progmem} affects the location
7656of the data but not how this data is accessed.
7657In order to read data located with the @code{progmem} attribute
7658(inline) assembler must be used.
7659@smallexample
7660/* Use custom macros from @w{@uref{http://nongnu.org/avr-libc/user-manual/,AVR-LibC}} */
7661#include <avr/pgmspace.h>
7662
7663/* Locate var in flash memory */
7664const int var[2] PROGMEM = @{ 1, 2 @};
7665
7666int read_var (int i)
7667@{
7668    /* Access var[] by accessor macro from avr/pgmspace.h */
7669    return (int) pgm_read_word (& var[i]);
7670@}
7671@end smallexample
7672
7673AVR is a Harvard architecture processor and data and read-only data
7674normally resides in the data memory (RAM).
7675
7676See also the @ref{AVR Named Address Spaces} section for
7677an alternate way to locate and access data in flash memory.
7678
7679@item @bullet{}@tie{} AVR cores with flash memory visible in the RAM address range:
7680On such devices, there is no need for attribute @code{progmem} or
7681@ref{AVR Named Address Spaces,,@code{__flash}} qualifier at all.
7682Just use standard C / C++.  The compiler will generate @code{LD*}
7683instructions.  As flash memory is visible in the RAM address range,
7684and the default linker script does @emph{not} locate @code{.rodata} in
7685RAM, no special features are needed in order not to waste RAM for
7686read-only data or to read from flash.  You might even get slightly better
7687performance by
7688avoiding @code{progmem} and @code{__flash}.  This applies to devices from
7689families @code{avrtiny} and @code{avrxmega3}, see @ref{AVR Options} for
7690an overview.
7691
7692@item @bullet{}@tie{}Reduced AVR Tiny cores like ATtiny40:
7693The compiler adds @code{0x4000}
7694to the addresses of objects and declarations in @code{progmem} and locates
7695the objects in flash memory, namely in section @code{.progmem.data}.
7696The offset is needed because the flash memory is visible in the RAM
7697address space starting at address @code{0x4000}.
7698
7699Data in @code{progmem} can be accessed by means of ordinary C@tie{}code,
7700no special functions or macros are needed.
7701
7702@smallexample
7703/* var is located in flash memory */
7704extern const int var[2] __attribute__((progmem));
7705
7706int read_var (int i)
7707@{
7708    return var[i];
7709@}
7710@end smallexample
7711
7712Please notice that on these devices, there is no need for @code{progmem}
7713at all.
7714
7715@end table
7716
7717@item io
7718@itemx io (@var{addr})
7719@cindex @code{io} variable attribute, AVR
7720Variables with the @code{io} attribute are used to address
7721memory-mapped peripherals in the io address range.
7722If an address is specified, the variable
7723is assigned that address, and the value is interpreted as an
7724address in the data address space.
7725Example:
7726
7727@smallexample
7728volatile int porta __attribute__((io (0x22)));
7729@end smallexample
7730
7731The address specified in the address in the data address range.
7732
7733Otherwise, the variable it is not assigned an address, but the
7734compiler will still use in/out instructions where applicable,
7735assuming some other module assigns an address in the io address range.
7736Example:
7737
7738@smallexample
7739extern volatile int porta __attribute__((io));
7740@end smallexample
7741
7742@item io_low
7743@itemx io_low (@var{addr})
7744@cindex @code{io_low} variable attribute, AVR
7745This is like the @code{io} attribute, but additionally it informs the
7746compiler that the object lies in the lower half of the I/O area,
7747allowing the use of @code{cbi}, @code{sbi}, @code{sbic} and @code{sbis}
7748instructions.
7749
7750@item address
7751@itemx address (@var{addr})
7752@cindex @code{address} variable attribute, AVR
7753Variables with the @code{address} attribute are used to address
7754memory-mapped peripherals that may lie outside the io address range.
7755
7756@smallexample
7757volatile int porta __attribute__((address (0x600)));
7758@end smallexample
7759
7760@item absdata
7761@cindex @code{absdata} variable attribute, AVR
7762Variables in static storage and with the @code{absdata} attribute can
7763be accessed by the @code{LDS} and @code{STS} instructions which take
7764absolute addresses.
7765
7766@itemize @bullet
7767@item
7768This attribute is only supported for the reduced AVR Tiny core
7769like ATtiny40.
7770
7771@item
7772You must make sure that respective data is located in the
7773address range @code{0x40}@dots{}@code{0xbf} accessible by
7774@code{LDS} and @code{STS}.  One way to achieve this as an
7775appropriate linker description file.
7776
7777@item
7778If the location does not fit the address range of @code{LDS}
7779and @code{STS}, there is currently (Binutils 2.26) just an unspecific
7780warning like
7781@quotation
7782@code{module.c:(.text+0x1c): warning: internal error: out of range error}
7783@end quotation
7784
7785@end itemize
7786
7787See also the @option{-mabsdata} @ref{AVR Options,command-line option}.
7788
7789@end table
7790
7791@node Blackfin Variable Attributes
7792@subsection Blackfin Variable Attributes
7793
7794Three attributes are currently defined for the Blackfin.
7795
7796@table @code
7797@item l1_data
7798@itemx l1_data_A
7799@itemx l1_data_B
7800@cindex @code{l1_data} variable attribute, Blackfin
7801@cindex @code{l1_data_A} variable attribute, Blackfin
7802@cindex @code{l1_data_B} variable attribute, Blackfin
7803Use these attributes on the Blackfin to place the variable into L1 Data SRAM.
7804Variables with @code{l1_data} attribute are put into the specific section
7805named @code{.l1.data}. Those with @code{l1_data_A} attribute are put into
7806the specific section named @code{.l1.data.A}. Those with @code{l1_data_B}
7807attribute are put into the specific section named @code{.l1.data.B}.
7808
7809@item l2
7810@cindex @code{l2} variable attribute, Blackfin
7811Use this attribute on the Blackfin to place the variable into L2 SRAM.
7812Variables with @code{l2} attribute are put into the specific section
7813named @code{.l2.data}.
7814@end table
7815
7816@node H8/300 Variable Attributes
7817@subsection H8/300 Variable Attributes
7818
7819These variable attributes are available for H8/300 targets:
7820
7821@table @code
7822@item eightbit_data
7823@cindex @code{eightbit_data} variable attribute, H8/300
7824@cindex eight-bit data on the H8/300, H8/300H, and H8S
7825Use this attribute on the H8/300, H8/300H, and H8S to indicate that the specified
7826variable should be placed into the eight-bit data section.
7827The compiler generates more efficient code for certain operations
7828on data in the eight-bit data area.  Note the eight-bit data area is limited to
7829256 bytes of data.
7830
7831You must use GAS and GLD from GNU binutils version 2.7 or later for
7832this attribute to work correctly.
7833
7834@item tiny_data
7835@cindex @code{tiny_data} variable attribute, H8/300
7836@cindex tiny data section on the H8/300H and H8S
7837Use this attribute on the H8/300H and H8S to indicate that the specified
7838variable should be placed into the tiny data section.
7839The compiler generates more efficient code for loads and stores
7840on data in the tiny data section.  Note the tiny data area is limited to
7841slightly under 32KB of data.
7842
7843@end table
7844
7845@node IA-64 Variable Attributes
7846@subsection IA-64 Variable Attributes
7847
7848The IA-64 back end supports the following variable attribute:
7849
7850@table @code
7851@item model (@var{model-name})
7852@cindex @code{model} variable attribute, IA-64
7853
7854On IA-64, use this attribute to set the addressability of an object.
7855At present, the only supported identifier for @var{model-name} is
7856@code{small}, indicating addressability via ``small'' (22-bit)
7857addresses (so that their addresses can be loaded with the @code{addl}
7858instruction).  Caveat: such addressing is by definition not position
7859independent and hence this attribute must not be used for objects
7860defined by shared libraries.
7861
7862@end table
7863
7864@node M32R/D Variable Attributes
7865@subsection M32R/D Variable Attributes
7866
7867One attribute is currently defined for the M32R/D@.
7868
7869@table @code
7870@item model (@var{model-name})
7871@cindex @code{model-name} variable attribute, M32R/D
7872@cindex variable addressability on the M32R/D
7873Use this attribute on the M32R/D to set the addressability of an object.
7874The identifier @var{model-name} is one of @code{small}, @code{medium},
7875or @code{large}, representing each of the code models.
7876
7877Small model objects live in the lower 16MB of memory (so that their
7878addresses can be loaded with the @code{ld24} instruction).
7879
7880Medium and large model objects may live anywhere in the 32-bit address space
7881(the compiler generates @code{seth/add3} instructions to load their
7882addresses).
7883@end table
7884
7885@node MeP Variable Attributes
7886@subsection MeP Variable Attributes
7887
7888The MeP target has a number of addressing modes and busses.  The
7889@code{near} space spans the standard memory space's first 16 megabytes
7890(24 bits).  The @code{far} space spans the entire 32-bit memory space.
7891The @code{based} space is a 128-byte region in the memory space that
7892is addressed relative to the @code{$tp} register.  The @code{tiny}
7893space is a 65536-byte region relative to the @code{$gp} register.  In
7894addition to these memory regions, the MeP target has a separate 16-bit
7895control bus which is specified with @code{cb} attributes.
7896
7897@table @code
7898
7899@item based
7900@cindex @code{based} variable attribute, MeP
7901Any variable with the @code{based} attribute is assigned to the
7902@code{.based} section, and is accessed with relative to the
7903@code{$tp} register.
7904
7905@item tiny
7906@cindex @code{tiny} variable attribute, MeP
7907Likewise, the @code{tiny} attribute assigned variables to the
7908@code{.tiny} section, relative to the @code{$gp} register.
7909
7910@item near
7911@cindex @code{near} variable attribute, MeP
7912Variables with the @code{near} attribute are assumed to have addresses
7913that fit in a 24-bit addressing mode.  This is the default for large
7914variables (@code{-mtiny=4} is the default) but this attribute can
7915override @code{-mtiny=} for small variables, or override @code{-ml}.
7916
7917@item far
7918@cindex @code{far} variable attribute, MeP
7919Variables with the @code{far} attribute are addressed using a full
792032-bit address.  Since this covers the entire memory space, this
7921allows modules to make no assumptions about where variables might be
7922stored.
7923
7924@item io
7925@cindex @code{io} variable attribute, MeP
7926@itemx io (@var{addr})
7927Variables with the @code{io} attribute are used to address
7928memory-mapped peripherals.  If an address is specified, the variable
7929is assigned that address, else it is not assigned an address (it is
7930assumed some other module assigns an address).  Example:
7931
7932@smallexample
7933int timer_count __attribute__((io(0x123)));
7934@end smallexample
7935
7936@item cb
7937@itemx cb (@var{addr})
7938@cindex @code{cb} variable attribute, MeP
7939Variables with the @code{cb} attribute are used to access the control
7940bus, using special instructions.  @code{addr} indicates the control bus
7941address.  Example:
7942
7943@smallexample
7944int cpu_clock __attribute__((cb(0x123)));
7945@end smallexample
7946
7947@end table
7948
7949@node Microsoft Windows Variable Attributes
7950@subsection Microsoft Windows Variable Attributes
7951
7952You can use these attributes on Microsoft Windows targets.
7953@ref{x86 Variable Attributes} for additional Windows compatibility
7954attributes available on all x86 targets.
7955
7956@table @code
7957@item dllimport
7958@itemx dllexport
7959@cindex @code{dllimport} variable attribute
7960@cindex @code{dllexport} variable attribute
7961The @code{dllimport} and @code{dllexport} attributes are described in
7962@ref{Microsoft Windows Function Attributes}.
7963
7964@item selectany
7965@cindex @code{selectany} variable attribute
7966The @code{selectany} attribute causes an initialized global variable to
7967have link-once semantics.  When multiple definitions of the variable are
7968encountered by the linker, the first is selected and the remainder are
7969discarded.  Following usage by the Microsoft compiler, the linker is told
7970@emph{not} to warn about size or content differences of the multiple
7971definitions.
7972
7973Although the primary usage of this attribute is for POD types, the
7974attribute can also be applied to global C++ objects that are initialized
7975by a constructor.  In this case, the static initialization and destruction
7976code for the object is emitted in each translation defining the object,
7977but the calls to the constructor and destructor are protected by a
7978link-once guard variable.
7979
7980The @code{selectany} attribute is only available on Microsoft Windows
7981targets.  You can use @code{__declspec (selectany)} as a synonym for
7982@code{__attribute__ ((selectany))} for compatibility with other
7983compilers.
7984
7985@item shared
7986@cindex @code{shared} variable attribute
7987On Microsoft Windows, in addition to putting variable definitions in a named
7988section, the section can also be shared among all running copies of an
7989executable or DLL@.  For example, this small program defines shared data
7990by putting it in a named section @code{shared} and marking the section
7991shareable:
7992
7993@smallexample
7994int foo __attribute__((section ("shared"), shared)) = 0;
7995
7996int
7997main()
7998@{
7999  /* @r{Read and write foo.  All running
8000     copies see the same value.}  */
8001  return 0;
8002@}
8003@end smallexample
8004
8005@noindent
8006You may only use the @code{shared} attribute along with @code{section}
8007attribute with a fully-initialized global definition because of the way
8008linkers work.  See @code{section} attribute for more information.
8009
8010The @code{shared} attribute is only available on Microsoft Windows@.
8011
8012@end table
8013
8014@node MSP430 Variable Attributes
8015@subsection MSP430 Variable Attributes
8016
8017@table @code
8018@item upper
8019@itemx either
8020@cindex @code{upper} variable attribute, MSP430
8021@cindex @code{either} variable attribute, MSP430
8022These attributes are the same as the MSP430 function attributes of the
8023same name (@pxref{MSP430 Function Attributes}).
8024
8025@item lower
8026@cindex @code{lower} variable attribute, MSP430
8027This option behaves mostly the same as the MSP430 function attribute of the
8028same name (@pxref{MSP430 Function Attributes}), but it has some additional
8029functionality.
8030
8031If @option{-mdata-region=}@{@code{upper,either,none}@} has been passed, or
8032the @code{section} attribute is applied to a variable, the compiler will
8033generate 430X instructions to handle it.  This is because the compiler has
8034to assume that the variable could get placed in the upper memory region
8035(above address 0xFFFF).  Marking the variable with the @code{lower} attribute
8036informs the compiler that the variable will be placed in lower memory so it
8037is safe to use 430 instructions to handle it.
8038
8039In the case of the @code{section} attribute, the section name given
8040will be used, and the @code{.lower} prefix will not be added.
8041
8042@end table
8043
8044@node Nvidia PTX Variable Attributes
8045@subsection Nvidia PTX Variable Attributes
8046
8047These variable attributes are supported by the Nvidia PTX back end:
8048
8049@table @code
8050@item shared
8051@cindex @code{shared} attribute, Nvidia PTX
8052Use this attribute to place a variable in the @code{.shared} memory space.
8053This memory space is private to each cooperative thread array; only threads
8054within one thread block refer to the same instance of the variable.
8055The runtime does not initialize variables in this memory space.
8056@end table
8057
8058@node PowerPC Variable Attributes
8059@subsection PowerPC Variable Attributes
8060
8061Three attributes currently are defined for PowerPC configurations:
8062@code{altivec}, @code{ms_struct} and @code{gcc_struct}.
8063
8064@cindex @code{ms_struct} variable attribute, PowerPC
8065@cindex @code{gcc_struct} variable attribute, PowerPC
8066For full documentation of the struct attributes please see the
8067documentation in @ref{x86 Variable Attributes}.
8068
8069@cindex @code{altivec} variable attribute, PowerPC
8070For documentation of @code{altivec} attribute please see the
8071documentation in @ref{PowerPC Type Attributes}.
8072
8073@node RL78 Variable Attributes
8074@subsection RL78 Variable Attributes
8075
8076@cindex @code{saddr} variable attribute, RL78
8077The RL78 back end supports the @code{saddr} variable attribute.  This
8078specifies placement of the corresponding variable in the SADDR area,
8079which can be accessed more efficiently than the default memory region.
8080
8081@node V850 Variable Attributes
8082@subsection V850 Variable Attributes
8083
8084These variable attributes are supported by the V850 back end:
8085
8086@table @code
8087
8088@item sda
8089@cindex @code{sda} variable attribute, V850
8090Use this attribute to explicitly place a variable in the small data area,
8091which can hold up to 64 kilobytes.
8092
8093@item tda
8094@cindex @code{tda} variable attribute, V850
8095Use this attribute to explicitly place a variable in the tiny data area,
8096which can hold up to 256 bytes in total.
8097
8098@item zda
8099@cindex @code{zda} variable attribute, V850
8100Use this attribute to explicitly place a variable in the first 32 kilobytes
8101of memory.
8102@end table
8103
8104@node x86 Variable Attributes
8105@subsection x86 Variable Attributes
8106
8107Two attributes are currently defined for x86 configurations:
8108@code{ms_struct} and @code{gcc_struct}.
8109
8110@table @code
8111@item ms_struct
8112@itemx gcc_struct
8113@cindex @code{ms_struct} variable attribute, x86
8114@cindex @code{gcc_struct} variable attribute, x86
8115
8116If @code{packed} is used on a structure, or if bit-fields are used,
8117it may be that the Microsoft ABI lays out the structure differently
8118than the way GCC normally does.  Particularly when moving packed
8119data between functions compiled with GCC and the native Microsoft compiler
8120(either via function call or as data in a file), it may be necessary to access
8121either format.
8122
8123The @code{ms_struct} and @code{gcc_struct} attributes correspond
8124to the @option{-mms-bitfields} and @option{-mno-ms-bitfields}
8125command-line options, respectively;
8126see @ref{x86 Options}, for details of how structure layout is affected.
8127@xref{x86 Type Attributes}, for information about the corresponding
8128attributes on types.
8129
8130@end table
8131
8132@node Xstormy16 Variable Attributes
8133@subsection Xstormy16 Variable Attributes
8134
8135One attribute is currently defined for xstormy16 configurations:
8136@code{below100}.
8137
8138@table @code
8139@item below100
8140@cindex @code{below100} variable attribute, Xstormy16
8141
8142If a variable has the @code{below100} attribute (@code{BELOW100} is
8143allowed also), GCC places the variable in the first 0x100 bytes of
8144memory and use special opcodes to access it.  Such variables are
8145placed in either the @code{.bss_below100} section or the
8146@code{.data_below100} section.
8147
8148@end table
8149
8150@node Type Attributes
8151@section Specifying Attributes of Types
8152@cindex attribute of types
8153@cindex type attributes
8154
8155The keyword @code{__attribute__} allows you to specify various special
8156properties of types.  Some type attributes apply only to structure and
8157union types, and in C++, also class types, while others can apply to
8158any type defined via a @code{typedef} declaration.  Unless otherwise
8159specified, the same restrictions and effects apply to attributes regardless
8160of whether a type is a trivial structure or a C++ class with user-defined
8161constructors, destructors, or a copy assignment.
8162
8163Other attributes are defined for functions (@pxref{Function Attributes}),
8164labels (@pxref{Label  Attributes}), enumerators (@pxref{Enumerator
8165Attributes}), statements (@pxref{Statement Attributes}), and for variables
8166(@pxref{Variable Attributes}).
8167
8168The @code{__attribute__} keyword is followed by an attribute specification
8169enclosed in double parentheses.
8170
8171You may specify type attributes in an enum, struct or union type
8172declaration or definition by placing them immediately after the
8173@code{struct}, @code{union} or @code{enum} keyword.  You can also place
8174them just past the closing curly brace of the definition, but this is less
8175preferred because logically the type should be fully defined at
8176the closing brace.
8177
8178You can also include type attributes in a @code{typedef} declaration.
8179@xref{Attribute Syntax}, for details of the exact syntax for using
8180attributes.
8181
8182@menu
8183* Common Type Attributes::
8184* ARC Type Attributes::
8185* ARM Type Attributes::
8186* MeP Type Attributes::
8187* PowerPC Type Attributes::
8188* x86 Type Attributes::
8189@end menu
8190
8191@node Common Type Attributes
8192@subsection Common Type Attributes
8193
8194The following type attributes are supported on most targets.
8195
8196@table @code
8197@cindex @code{aligned} type attribute
8198@item aligned
8199@itemx aligned (@var{alignment})
8200The @code{aligned} attribute specifies a minimum alignment (in bytes) for
8201variables of the specified type.  When specified, @var{alignment} must be
8202a power of 2.  Specifying no @var{alignment} argument implies the maximum
8203alignment for the target, which is often, but by no means always, 8 or 16
8204bytes.  For example, the declarations:
8205
8206@smallexample
8207struct __attribute__ ((aligned (8))) S @{ short f[3]; @};
8208typedef int more_aligned_int __attribute__ ((aligned (8)));
8209@end smallexample
8210
8211@noindent
8212force the compiler to ensure (as far as it can) that each variable whose
8213type is @code{struct S} or @code{more_aligned_int} is allocated and
8214aligned @emph{at least} on a 8-byte boundary.  On a SPARC, having all
8215variables of type @code{struct S} aligned to 8-byte boundaries allows
8216the compiler to use the @code{ldd} and @code{std} (doubleword load and
8217store) instructions when copying one variable of type @code{struct S} to
8218another, thus improving run-time efficiency.
8219
8220Note that the alignment of any given @code{struct} or @code{union} type
8221is required by the ISO C standard to be at least a perfect multiple of
8222the lowest common multiple of the alignments of all of the members of
8223the @code{struct} or @code{union} in question.  This means that you @emph{can}
8224effectively adjust the alignment of a @code{struct} or @code{union}
8225type by attaching an @code{aligned} attribute to any one of the members
8226of such a type, but the notation illustrated in the example above is a
8227more obvious, intuitive, and readable way to request the compiler to
8228adjust the alignment of an entire @code{struct} or @code{union} type.
8229
8230As in the preceding example, you can explicitly specify the alignment
8231(in bytes) that you wish the compiler to use for a given @code{struct}
8232or @code{union} type.  Alternatively, you can leave out the alignment factor
8233and just ask the compiler to align a type to the maximum
8234useful alignment for the target machine you are compiling for.  For
8235example, you could write:
8236
8237@smallexample
8238struct __attribute__ ((aligned)) S @{ short f[3]; @};
8239@end smallexample
8240
8241Whenever you leave out the alignment factor in an @code{aligned}
8242attribute specification, the compiler automatically sets the alignment
8243for the type to the largest alignment that is ever used for any data
8244type on the target machine you are compiling for.  Doing this can often
8245make copy operations more efficient, because the compiler can use
8246whatever instructions copy the biggest chunks of memory when performing
8247copies to or from the variables that have types that you have aligned
8248this way.
8249
8250In the example above, if the size of each @code{short} is 2 bytes, then
8251the size of the entire @code{struct S} type is 6 bytes.  The smallest
8252power of two that is greater than or equal to that is 8, so the
8253compiler sets the alignment for the entire @code{struct S} type to 8
8254bytes.
8255
8256Note that although you can ask the compiler to select a time-efficient
8257alignment for a given type and then declare only individual stand-alone
8258objects of that type, the compiler's ability to select a time-efficient
8259alignment is primarily useful only when you plan to create arrays of
8260variables having the relevant (efficiently aligned) type.  If you
8261declare or use arrays of variables of an efficiently-aligned type, then
8262it is likely that your program also does pointer arithmetic (or
8263subscripting, which amounts to the same thing) on pointers to the
8264relevant type, and the code that the compiler generates for these
8265pointer arithmetic operations is often more efficient for
8266efficiently-aligned types than for other types.
8267
8268Note that the effectiveness of @code{aligned} attributes may be limited
8269by inherent limitations in your linker.  On many systems, the linker is
8270only able to arrange for variables to be aligned up to a certain maximum
8271alignment.  (For some linkers, the maximum supported alignment may
8272be very very small.)  If your linker is only able to align variables
8273up to a maximum of 8-byte alignment, then specifying @code{aligned (16)}
8274in an @code{__attribute__} still only provides you with 8-byte
8275alignment.  See your linker documentation for further information.
8276
8277When used on a struct, or struct member, the @code{aligned} attribute can
8278only increase the alignment; in order to decrease it, the @code{packed}
8279attribute must be specified as well.  When used as part of a typedef, the
8280@code{aligned} attribute can both increase and decrease alignment, and
8281specifying the @code{packed} attribute generates a warning.
8282
8283@cindex @code{warn_if_not_aligned} type attribute
8284@item warn_if_not_aligned (@var{alignment})
8285This attribute specifies a threshold for the structure field, measured
8286in bytes.  If the structure field is aligned below the threshold, a
8287warning will be issued.  For example, the declaration:
8288
8289@smallexample
8290typedef unsigned long long __u64
8291   __attribute__((aligned (4), warn_if_not_aligned (8)));
8292
8293struct foo
8294@{
8295  int i1;
8296  int i2;
8297  __u64 x;
8298@};
8299@end smallexample
8300
8301@noindent
8302causes the compiler to issue an warning on @code{struct foo}, like
8303@samp{warning: alignment 4 of 'struct foo' is less than 8}.
8304It is used to define @code{struct foo} in such a way that
8305@code{struct foo} has the same layout and the structure field @code{x}
8306has the same alignment when @code{__u64} is aligned at either 4 or
83078 bytes.  Align @code{struct foo} to 8 bytes:
8308
8309@smallexample
8310struct __attribute__ ((aligned (8))) foo
8311@{
8312  int i1;
8313  int i2;
8314  __u64 x;
8315@};
8316@end smallexample
8317
8318@noindent
8319silences the warning.  The compiler also issues a warning, like
8320@samp{warning: 'x' offset 12 in 'struct foo' isn't aligned to 8},
8321when the structure field has the misaligned offset:
8322
8323@smallexample
8324struct __attribute__ ((aligned (8))) foo
8325@{
8326  int i1;
8327  int i2;
8328  int i3;
8329  __u64 x;
8330@};
8331@end smallexample
8332
8333This warning can be disabled by @option{-Wno-if-not-aligned}.
8334
8335@item alloc_size (@var{position})
8336@itemx alloc_size (@var{position-1}, @var{position-2})
8337@cindex @code{alloc_size} type attribute
8338The @code{alloc_size} type attribute may be applied to the definition
8339of a type of a function that returns a pointer and takes at least one
8340argument of an integer type.  It indicates that the returned pointer
8341points to an object whose size is given by the function argument at
8342@var{position-1}, or by the product of the arguments at @var{position-1}
8343and @var{position-2}.  Meaningful sizes are positive values less than
8344@code{PTRDIFF_MAX}.  Other sizes are disagnosed when detected.  GCC uses
8345this information to improve the results of @code{__builtin_object_size}.
8346
8347For instance, the following declarations
8348
8349@smallexample
8350typedef __attribute__ ((alloc_size (1, 2))) void*
8351  calloc_type (size_t, size_t);
8352typedef __attribute__ ((alloc_size (1))) void*
8353  malloc_type (size_t);
8354@end smallexample
8355
8356@noindent
8357specify that @code{calloc_type} is a type of a function that, like
8358the standard C function @code{calloc}, returns an object whose size
8359is given by the product of arguments 1 and 2, and that
8360@code{malloc_type}, like the standard C function @code{malloc},
8361returns an object whose size is given by argument 1 to the function.
8362
8363@item copy
8364@itemx copy (@var{expression})
8365@cindex @code{copy} type attribute
8366The @code{copy} attribute applies the set of attributes with which
8367the type of the @var{expression} has been declared to the declaration
8368of the type to which the attribute is applied.  The attribute is
8369designed for libraries that define aliases that are expected to
8370specify the same set of attributes as the aliased symbols.
8371The @code{copy} attribute can be used with types, variables, or
8372functions.  However, the kind of symbol to which the attribute is
8373applied (either varible or function) must match the kind of symbol
8374to which the argument refers.
8375The @code{copy} attribute copies only syntactic and semantic attributes
8376but not attributes that affect a symbol's linkage or visibility such as
8377@code{alias}, @code{visibility}, or @code{weak}.  The @code{deprecated}
8378attribute is also not copied.  @xref{Common Function Attributes}.
8379@xref{Common Variable Attributes}.
8380
8381For example, suppose @code{struct A} below is defined in some third
8382party library header to have the alignment requirement @code{N} and
8383to force a warning whenever a variable of the type is not so aligned
8384due to attribute @code{packed}.  Specifying the @code{copy} attribute
8385on the definition on the unrelated @code{struct B} has the effect of
8386copying all relevant attributes from the type referenced by the pointer
8387expression to @code{struct B}.
8388
8389@smallexample
8390struct __attribute__ ((aligned (N), warn_if_not_aligned (N)))
8391A @{ /* @r{@dots{}} */ @};
8392struct __attribute__ ((copy ( (struct A *)0)) B @{ /* @r{@dots{}} */ @};
8393@end smallexample
8394
8395@item deprecated
8396@itemx deprecated (@var{msg})
8397@cindex @code{deprecated} type attribute
8398The @code{deprecated} attribute results in a warning if the type
8399is used anywhere in the source file.  This is useful when identifying
8400types that are expected to be removed in a future version of a program.
8401If possible, the warning also includes the location of the declaration
8402of the deprecated type, to enable users to easily find further
8403information about why the type is deprecated, or what they should do
8404instead.  Note that the warnings only occur for uses and then only
8405if the type is being applied to an identifier that itself is not being
8406declared as deprecated.
8407
8408@smallexample
8409typedef int T1 __attribute__ ((deprecated));
8410T1 x;
8411typedef T1 T2;
8412T2 y;
8413typedef T1 T3 __attribute__ ((deprecated));
8414T3 z __attribute__ ((deprecated));
8415@end smallexample
8416
8417@noindent
8418results in a warning on line 2 and 3 but not lines 4, 5, or 6.  No
8419warning is issued for line 4 because T2 is not explicitly
8420deprecated.  Line 5 has no warning because T3 is explicitly
8421deprecated.  Similarly for line 6.  The optional @var{msg}
8422argument, which must be a string, is printed in the warning if
8423present.  Control characters in the string will be replaced with
8424escape sequences, and if the @option{-fmessage-length} option is set
8425to 0 (its default value) then any newline characters will be ignored.
8426
8427The @code{deprecated} attribute can also be used for functions and
8428variables (@pxref{Function Attributes}, @pxref{Variable Attributes}.)
8429
8430The message attached to the attribute is affected by the setting of
8431the @option{-fmessage-length} option.
8432
8433@item designated_init
8434@cindex @code{designated_init} type attribute
8435This attribute may only be applied to structure types.  It indicates
8436that any initialization of an object of this type must use designated
8437initializers rather than positional initializers.  The intent of this
8438attribute is to allow the programmer to indicate that a structure's
8439layout may change, and that therefore relying on positional
8440initialization will result in future breakage.
8441
8442GCC emits warnings based on this attribute by default; use
8443@option{-Wno-designated-init} to suppress them.
8444
8445@item may_alias
8446@cindex @code{may_alias} type attribute
8447Accesses through pointers to types with this attribute are not subject
8448to type-based alias analysis, but are instead assumed to be able to alias
8449any other type of objects.
8450In the context of section 6.5 paragraph 7 of the C99 standard,
8451an lvalue expression
8452dereferencing such a pointer is treated like having a character type.
8453See @option{-fstrict-aliasing} for more information on aliasing issues.
8454This extension exists to support some vector APIs, in which pointers to
8455one vector type are permitted to alias pointers to a different vector type.
8456
8457Note that an object of a type with this attribute does not have any
8458special semantics.
8459
8460Example of use:
8461
8462@smallexample
8463typedef short __attribute__ ((__may_alias__)) short_a;
8464
8465int
8466main (void)
8467@{
8468  int a = 0x12345678;
8469  short_a *b = (short_a *) &a;
8470
8471  b[1] = 0;
8472
8473  if (a == 0x12345678)
8474    abort();
8475
8476  exit(0);
8477@}
8478@end smallexample
8479
8480@noindent
8481If you replaced @code{short_a} with @code{short} in the variable
8482declaration, the above program would abort when compiled with
8483@option{-fstrict-aliasing}, which is on by default at @option{-O2} or
8484above.
8485
8486@item mode (@var{mode})
8487@cindex @code{mode} type attribute
8488This attribute specifies the data type for the declaration---whichever
8489type corresponds to the mode @var{mode}.  This in effect lets you
8490request an integer or floating-point type according to its width.
8491
8492@xref{Machine Modes,,, gccint, GNU Compiler Collection (GCC) Internals},
8493for a list of the possible keywords for @var{mode}.
8494You may also specify a mode of @code{byte} or @code{__byte__} to
8495indicate the mode corresponding to a one-byte integer, @code{word} or
8496@code{__word__} for the mode of a one-word integer, and @code{pointer}
8497or @code{__pointer__} for the mode used to represent pointers.
8498
8499@item packed
8500@cindex @code{packed} type attribute
8501This attribute, attached to a @code{struct}, @code{union}, or C++ @code{class}
8502type definition, specifies that each of its members (other than zero-width
8503bit-fields) is placed to minimize the memory required.  This is equivalent
8504to specifying the @code{packed} attribute on each of the members.
8505
8506@opindex fshort-enums
8507When attached to an @code{enum} definition, the @code{packed} attribute
8508indicates that the smallest integral type should be used.
8509Specifying the @option{-fshort-enums} flag on the command line
8510is equivalent to specifying the @code{packed}
8511attribute on all @code{enum} definitions.
8512
8513In the following example @code{struct my_packed_struct}'s members are
8514packed closely together, but the internal layout of its @code{s} member
8515is not packed---to do that, @code{struct my_unpacked_struct} needs to
8516be packed too.
8517
8518@smallexample
8519struct my_unpacked_struct
8520 @{
8521    char c;
8522    int i;
8523 @};
8524
8525struct __attribute__ ((__packed__)) my_packed_struct
8526  @{
8527     char c;
8528     int  i;
8529     struct my_unpacked_struct s;
8530  @};
8531@end smallexample
8532
8533You may only specify the @code{packed} attribute on the definition
8534of an @code{enum}, @code{struct}, @code{union}, or @code{class},
8535not on a @code{typedef} that does not also define the enumerated type,
8536structure, union, or class.
8537
8538@item scalar_storage_order ("@var{endianness}")
8539@cindex @code{scalar_storage_order} type attribute
8540When attached to a @code{union} or a @code{struct}, this attribute sets
8541the storage order, aka endianness, of the scalar fields of the type, as
8542well as the array fields whose component is scalar.  The supported
8543endiannesses are @code{big-endian} and @code{little-endian}.  The attribute
8544has no effects on fields which are themselves a @code{union}, a @code{struct}
8545or an array whose component is a @code{union} or a @code{struct}, and it is
8546possible for these fields to have a different scalar storage order than the
8547enclosing type.
8548
8549This attribute is supported only for targets that use a uniform default
8550scalar storage order (fortunately, most of them), i.e.@: targets that store
8551the scalars either all in big-endian or all in little-endian.
8552
8553Additional restrictions are enforced for types with the reverse scalar
8554storage order with regard to the scalar storage order of the target:
8555
8556@itemize
8557@item Taking the address of a scalar field of a @code{union} or a
8558@code{struct} with reverse scalar storage order is not permitted and yields
8559an error.
8560@item Taking the address of an array field, whose component is scalar, of
8561a @code{union} or a @code{struct} with reverse scalar storage order is
8562permitted but yields a warning, unless @option{-Wno-scalar-storage-order}
8563is specified.
8564@item Taking the address of a @code{union} or a @code{struct} with reverse
8565scalar storage order is permitted.
8566@end itemize
8567
8568These restrictions exist because the storage order attribute is lost when
8569the address of a scalar or the address of an array with scalar component is
8570taken, so storing indirectly through this address generally does not work.
8571The second case is nevertheless allowed to be able to perform a block copy
8572from or to the array.
8573
8574Moreover, the use of type punning or aliasing to toggle the storage order
8575is not supported; that is to say, a given scalar object cannot be accessed
8576through distinct types that assign a different storage order to it.
8577
8578@item transparent_union
8579@cindex @code{transparent_union} type attribute
8580
8581This attribute, attached to a @code{union} type definition, indicates
8582that any function parameter having that union type causes calls to that
8583function to be treated in a special way.
8584
8585First, the argument corresponding to a transparent union type can be of
8586any type in the union; no cast is required.  Also, if the union contains
8587a pointer type, the corresponding argument can be a null pointer
8588constant or a void pointer expression; and if the union contains a void
8589pointer type, the corresponding argument can be any pointer expression.
8590If the union member type is a pointer, qualifiers like @code{const} on
8591the referenced type must be respected, just as with normal pointer
8592conversions.
8593
8594Second, the argument is passed to the function using the calling
8595conventions of the first member of the transparent union, not the calling
8596conventions of the union itself.  All members of the union must have the
8597same machine representation; this is necessary for this argument passing
8598to work properly.
8599
8600Transparent unions are designed for library functions that have multiple
8601interfaces for compatibility reasons.  For example, suppose the
8602@code{wait} function must accept either a value of type @code{int *} to
8603comply with POSIX, or a value of type @code{union wait *} to comply with
8604the 4.1BSD interface.  If @code{wait}'s parameter were @code{void *},
8605@code{wait} would accept both kinds of arguments, but it would also
8606accept any other pointer type and this would make argument type checking
8607less useful.  Instead, @code{<sys/wait.h>} might define the interface
8608as follows:
8609
8610@smallexample
8611typedef union __attribute__ ((__transparent_union__))
8612  @{
8613    int *__ip;
8614    union wait *__up;
8615  @} wait_status_ptr_t;
8616
8617pid_t wait (wait_status_ptr_t);
8618@end smallexample
8619
8620@noindent
8621This interface allows either @code{int *} or @code{union wait *}
8622arguments to be passed, using the @code{int *} calling convention.
8623The program can call @code{wait} with arguments of either type:
8624
8625@smallexample
8626int w1 () @{ int w; return wait (&w); @}
8627int w2 () @{ union wait w; return wait (&w); @}
8628@end smallexample
8629
8630@noindent
8631With this interface, @code{wait}'s implementation might look like this:
8632
8633@smallexample
8634pid_t wait (wait_status_ptr_t p)
8635@{
8636  return waitpid (-1, p.__ip, 0);
8637@}
8638@end smallexample
8639
8640@item unused
8641@cindex @code{unused} type attribute
8642When attached to a type (including a @code{union} or a @code{struct}),
8643this attribute means that variables of that type are meant to appear
8644possibly unused.  GCC does not produce a warning for any variables of
8645that type, even if the variable appears to do nothing.  This is often
8646the case with lock or thread classes, which are usually defined and then
8647not referenced, but contain constructors and destructors that have
8648nontrivial bookkeeping functions.
8649
8650@item vector_size (@var{bytes})
8651@cindex @code{vector_size} type attribute
8652This attribute specifies the vector size for the type, measured in bytes.
8653The type to which it applies is known as the @dfn{base type}.  The @var{bytes}
8654argument must be a positive power-of-two multiple of the base type size.  For
8655example, the following declarations:
8656
8657@smallexample
8658typedef __attribute__ ((vector_size (32))) int int_vec32_t ;
8659typedef __attribute__ ((vector_size (32))) int* int_vec32_ptr_t;
8660typedef __attribute__ ((vector_size (32))) int int_vec32_arr3_t[3];
8661@end smallexample
8662
8663@noindent
8664define @code{int_vec32_t} to be a 32-byte vector type composed of @code{int}
8665sized units.  With @code{int} having a size of 4 bytes, the type defines
8666a vector of eight units, four bytes each.  The mode of variables of type
8667@code{int_vec32_t} is @code{V8SI}.  @code{int_vec32_ptr_t} is then defined
8668to be a pointer to such a vector type, and @code{int_vec32_arr3_t} to be
8669an array of three such vectors.  @xref{Vector Extensions}, for details of
8670manipulating objects of vector types.
8671
8672This attribute is only applicable to integral and floating scalar types.
8673In function declarations the attribute applies to the function return
8674type.
8675
8676For example, the following:
8677@smallexample
8678__attribute__ ((vector_size (16))) float get_flt_vec16 (void);
8679@end smallexample
8680declares @code{get_flt_vec16} to be a function returning a 16-byte vector
8681with the base type @code{float}.
8682
8683@item visibility
8684@cindex @code{visibility} type attribute
8685In C++, attribute visibility (@pxref{Function Attributes}) can also be
8686applied to class, struct, union and enum types.  Unlike other type
8687attributes, the attribute must appear between the initial keyword and
8688the name of the type; it cannot appear after the body of the type.
8689
8690Note that the type visibility is applied to vague linkage entities
8691associated with the class (vtable, typeinfo node, etc.).  In
8692particular, if a class is thrown as an exception in one shared object
8693and caught in another, the class must have default visibility.
8694Otherwise the two shared objects are unable to use the same
8695typeinfo node and exception handling will break.
8696
8697@item objc_root_class @r{(Objective-C and Objective-C++ only)}
8698@cindex @code{objc_root_class} type attribute
8699This attribute marks a class as being a root class, and thus allows
8700the compiler to elide any warnings about a missing superclass and to
8701make additional checks for mandatory methods as needed.
8702
8703@end table
8704
8705To specify multiple attributes, separate them by commas within the
8706double parentheses: for example, @samp{__attribute__ ((aligned (16),
8707packed))}.
8708
8709@node ARC Type Attributes
8710@subsection ARC Type Attributes
8711
8712@cindex @code{uncached} type attribute, ARC
8713Declaring objects with @code{uncached} allows you to exclude
8714data-cache participation in load and store operations on those objects
8715without involving the additional semantic implications of
8716@code{volatile}.  The @code{.di} instruction suffix is used for all
8717loads and stores of data declared @code{uncached}.
8718
8719@node ARM Type Attributes
8720@subsection ARM Type Attributes
8721
8722@cindex @code{notshared} type attribute, ARM
8723On those ARM targets that support @code{dllimport} (such as Symbian
8724OS), you can use the @code{notshared} attribute to indicate that the
8725virtual table and other similar data for a class should not be
8726exported from a DLL@.  For example:
8727
8728@smallexample
8729class __declspec(notshared) C @{
8730public:
8731  __declspec(dllimport) C();
8732  virtual void f();
8733@}
8734
8735__declspec(dllexport)
8736C::C() @{@}
8737@end smallexample
8738
8739@noindent
8740In this code, @code{C::C} is exported from the current DLL, but the
8741virtual table for @code{C} is not exported.  (You can use
8742@code{__attribute__} instead of @code{__declspec} if you prefer, but
8743most Symbian OS code uses @code{__declspec}.)
8744
8745@node MeP Type Attributes
8746@subsection MeP Type Attributes
8747
8748@cindex @code{based} type attribute, MeP
8749@cindex @code{tiny} type attribute, MeP
8750@cindex @code{near} type attribute, MeP
8751@cindex @code{far} type attribute, MeP
8752Many of the MeP variable attributes may be applied to types as well.
8753Specifically, the @code{based}, @code{tiny}, @code{near}, and
8754@code{far} attributes may be applied to either.  The @code{io} and
8755@code{cb} attributes may not be applied to types.
8756
8757@node PowerPC Type Attributes
8758@subsection PowerPC Type Attributes
8759
8760Three attributes currently are defined for PowerPC configurations:
8761@code{altivec}, @code{ms_struct} and @code{gcc_struct}.
8762
8763@cindex @code{ms_struct} type attribute, PowerPC
8764@cindex @code{gcc_struct} type attribute, PowerPC
8765For full documentation of the @code{ms_struct} and @code{gcc_struct}
8766attributes please see the documentation in @ref{x86 Type Attributes}.
8767
8768@cindex @code{altivec} type attribute, PowerPC
8769The @code{altivec} attribute allows one to declare AltiVec vector data
8770types supported by the AltiVec Programming Interface Manual.  The
8771attribute requires an argument to specify one of three vector types:
8772@code{vector__}, @code{pixel__} (always followed by unsigned short),
8773and @code{bool__} (always followed by unsigned).
8774
8775@smallexample
8776__attribute__((altivec(vector__)))
8777__attribute__((altivec(pixel__))) unsigned short
8778__attribute__((altivec(bool__))) unsigned
8779@end smallexample
8780
8781These attributes mainly are intended to support the @code{__vector},
8782@code{__pixel}, and @code{__bool} AltiVec keywords.
8783
8784@node x86 Type Attributes
8785@subsection x86 Type Attributes
8786
8787Two attributes are currently defined for x86 configurations:
8788@code{ms_struct} and @code{gcc_struct}.
8789
8790@table @code
8791
8792@item ms_struct
8793@itemx gcc_struct
8794@cindex @code{ms_struct} type attribute, x86
8795@cindex @code{gcc_struct} type attribute, x86
8796
8797If @code{packed} is used on a structure, or if bit-fields are used
8798it may be that the Microsoft ABI packs them differently
8799than GCC normally packs them.  Particularly when moving packed
8800data between functions compiled with GCC and the native Microsoft compiler
8801(either via function call or as data in a file), it may be necessary to access
8802either format.
8803
8804The @code{ms_struct} and @code{gcc_struct} attributes correspond
8805to the @option{-mms-bitfields} and @option{-mno-ms-bitfields}
8806command-line options, respectively;
8807see @ref{x86 Options}, for details of how structure layout is affected.
8808@xref{x86 Variable Attributes}, for information about the corresponding
8809attributes on variables.
8810
8811@end table
8812
8813@node Label Attributes
8814@section Label Attributes
8815@cindex Label Attributes
8816
8817GCC allows attributes to be set on C labels.  @xref{Attribute Syntax}, for
8818details of the exact syntax for using attributes.  Other attributes are
8819available for functions (@pxref{Function Attributes}), variables
8820(@pxref{Variable Attributes}), enumerators (@pxref{Enumerator Attributes}),
8821statements (@pxref{Statement Attributes}), and for types
8822(@pxref{Type Attributes}). A label attribute followed
8823by a declaration appertains to the label and not the declaration.
8824
8825This example uses the @code{cold} label attribute to indicate the
8826@code{ErrorHandling} branch is unlikely to be taken and that the
8827@code{ErrorHandling} label is unused:
8828
8829@smallexample
8830
8831   asm goto ("some asm" : : : : NoError);
8832
8833/* This branch (the fall-through from the asm) is less commonly used */
8834ErrorHandling:
8835   __attribute__((cold, unused)); /* Semi-colon is required here */
8836   printf("error\n");
8837   return 0;
8838
8839NoError:
8840   printf("no error\n");
8841   return 1;
8842@end smallexample
8843
8844@table @code
8845@item unused
8846@cindex @code{unused} label attribute
8847This feature is intended for program-generated code that may contain
8848unused labels, but which is compiled with @option{-Wall}.  It is
8849not normally appropriate to use in it human-written code, though it
8850could be useful in cases where the code that jumps to the label is
8851contained within an @code{#ifdef} conditional.
8852
8853@item hot
8854@cindex @code{hot} label attribute
8855The @code{hot} attribute on a label is used to inform the compiler that
8856the path following the label is more likely than paths that are not so
8857annotated.  This attribute is used in cases where @code{__builtin_expect}
8858cannot be used, for instance with computed goto or @code{asm goto}.
8859
8860@item cold
8861@cindex @code{cold} label attribute
8862The @code{cold} attribute on labels is used to inform the compiler that
8863the path following the label is unlikely to be executed.  This attribute
8864is used in cases where @code{__builtin_expect} cannot be used, for instance
8865with computed goto or @code{asm goto}.
8866
8867@end table
8868
8869@node Enumerator Attributes
8870@section Enumerator Attributes
8871@cindex Enumerator Attributes
8872
8873GCC allows attributes to be set on enumerators.  @xref{Attribute Syntax}, for
8874details of the exact syntax for using attributes.  Other attributes are
8875available for functions (@pxref{Function Attributes}), variables
8876(@pxref{Variable Attributes}), labels (@pxref{Label Attributes}), statements
8877(@pxref{Statement Attributes}), and for types (@pxref{Type Attributes}).
8878
8879This example uses the @code{deprecated} enumerator attribute to indicate the
8880@code{oldval} enumerator is deprecated:
8881
8882@smallexample
8883enum E @{
8884  oldval __attribute__((deprecated)),
8885  newval
8886@};
8887
8888int
8889fn (void)
8890@{
8891  return oldval;
8892@}
8893@end smallexample
8894
8895@table @code
8896@item deprecated
8897@cindex @code{deprecated} enumerator attribute
8898The @code{deprecated} attribute results in a warning if the enumerator
8899is used anywhere in the source file.  This is useful when identifying
8900enumerators that are expected to be removed in a future version of a
8901program.  The warning also includes the location of the declaration
8902of the deprecated enumerator, to enable users to easily find further
8903information about why the enumerator is deprecated, or what they should
8904do instead.  Note that the warnings only occurs for uses.
8905
8906@end table
8907
8908@node Statement Attributes
8909@section Statement Attributes
8910@cindex Statement Attributes
8911
8912GCC allows attributes to be set on null statements.  @xref{Attribute Syntax},
8913for details of the exact syntax for using attributes.  Other attributes are
8914available for functions (@pxref{Function Attributes}), variables
8915(@pxref{Variable Attributes}), labels (@pxref{Label Attributes}), enumerators
8916(@pxref{Enumerator Attributes}), and for types (@pxref{Type Attributes}).
8917
8918This example uses the @code{fallthrough} statement attribute to indicate that
8919the @option{-Wimplicit-fallthrough} warning should not be emitted:
8920
8921@smallexample
8922switch (cond)
8923  @{
8924  case 1:
8925    bar (1);
8926    __attribute__((fallthrough));
8927  case 2:
8928    @dots{}
8929  @}
8930@end smallexample
8931
8932@table @code
8933@item fallthrough
8934@cindex @code{fallthrough} statement attribute
8935The @code{fallthrough} attribute with a null statement serves as a
8936fallthrough statement.  It hints to the compiler that a statement
8937that falls through to another case label, or user-defined label
8938in a switch statement is intentional and thus the
8939@option{-Wimplicit-fallthrough} warning must not trigger.  The
8940fallthrough attribute may appear at most once in each attribute
8941list, and may not be mixed with other attributes.  It can only
8942be used in a switch statement (the compiler will issue an error
8943otherwise), after a preceding statement and before a logically
8944succeeding case label, or user-defined label.
8945
8946@end table
8947
8948@node Attribute Syntax
8949@section Attribute Syntax
8950@cindex attribute syntax
8951
8952This section describes the syntax with which @code{__attribute__} may be
8953used, and the constructs to which attribute specifiers bind, for the C
8954language.  Some details may vary for C++ and Objective-C@.  Because of
8955infelicities in the grammar for attributes, some forms described here
8956may not be successfully parsed in all cases.
8957
8958There are some problems with the semantics of attributes in C++.  For
8959example, there are no manglings for attributes, although they may affect
8960code generation, so problems may arise when attributed types are used in
8961conjunction with templates or overloading.  Similarly, @code{typeid}
8962does not distinguish between types with different attributes.  Support
8963for attributes in C++ may be restricted in future to attributes on
8964declarations only, but not on nested declarators.
8965
8966@xref{Function Attributes}, for details of the semantics of attributes
8967applying to functions.  @xref{Variable Attributes}, for details of the
8968semantics of attributes applying to variables.  @xref{Type Attributes},
8969for details of the semantics of attributes applying to structure, union
8970and enumerated types.
8971@xref{Label Attributes}, for details of the semantics of attributes
8972applying to labels.
8973@xref{Enumerator Attributes}, for details of the semantics of attributes
8974applying to enumerators.
8975@xref{Statement Attributes}, for details of the semantics of attributes
8976applying to statements.
8977
8978An @dfn{attribute specifier} is of the form
8979@code{__attribute__ ((@var{attribute-list}))}.  An @dfn{attribute list}
8980is a possibly empty comma-separated sequence of @dfn{attributes}, where
8981each attribute is one of the following:
8982
8983@itemize @bullet
8984@item
8985Empty.  Empty attributes are ignored.
8986
8987@item
8988An attribute name
8989(which may be an identifier such as @code{unused}, or a reserved
8990word such as @code{const}).
8991
8992@item
8993An attribute name followed by a parenthesized list of
8994parameters for the attribute.
8995These parameters take one of the following forms:
8996
8997@itemize @bullet
8998@item
8999An identifier.  For example, @code{mode} attributes use this form.
9000
9001@item
9002An identifier followed by a comma and a non-empty comma-separated list
9003of expressions.  For example, @code{format} attributes use this form.
9004
9005@item
9006A possibly empty comma-separated list of expressions.  For example,
9007@code{format_arg} attributes use this form with the list being a single
9008integer constant expression, and @code{alias} attributes use this form
9009with the list being a single string constant.
9010@end itemize
9011@end itemize
9012
9013An @dfn{attribute specifier list} is a sequence of one or more attribute
9014specifiers, not separated by any other tokens.
9015
9016You may optionally specify attribute names with @samp{__}
9017preceding and following the name.
9018This allows you to use them in header files without
9019being concerned about a possible macro of the same name.  For example,
9020you may use the attribute name @code{__noreturn__} instead of @code{noreturn}.
9021
9022
9023@subsubheading Label Attributes
9024
9025In GNU C, an attribute specifier list may appear after the colon following a
9026label, other than a @code{case} or @code{default} label.  GNU C++ only permits
9027attributes on labels if the attribute specifier is immediately
9028followed by a semicolon (i.e., the label applies to an empty
9029statement).  If the semicolon is missing, C++ label attributes are
9030ambiguous, as it is permissible for a declaration, which could begin
9031with an attribute list, to be labelled in C++.  Declarations cannot be
9032labelled in C90 or C99, so the ambiguity does not arise there.
9033
9034@subsubheading Enumerator Attributes
9035
9036In GNU C, an attribute specifier list may appear as part of an enumerator.
9037The attribute goes after the enumeration constant, before @code{=}, if
9038present.  The optional attribute in the enumerator appertains to the
9039enumeration constant.  It is not possible to place the attribute after
9040the constant expression, if present.
9041
9042@subsubheading Statement Attributes
9043In GNU C, an attribute specifier list may appear as part of a null
9044statement.  The attribute goes before the semicolon.
9045
9046@subsubheading Type Attributes
9047
9048An attribute specifier list may appear as part of a @code{struct},
9049@code{union} or @code{enum} specifier.  It may go either immediately
9050after the @code{struct}, @code{union} or @code{enum} keyword, or after
9051the closing brace.  The former syntax is preferred.
9052Where attribute specifiers follow the closing brace, they are considered
9053to relate to the structure, union or enumerated type defined, not to any
9054enclosing declaration the type specifier appears in, and the type
9055defined is not complete until after the attribute specifiers.
9056@c Otherwise, there would be the following problems: a shift/reduce
9057@c conflict between attributes binding the struct/union/enum and
9058@c binding to the list of specifiers/qualifiers; and "aligned"
9059@c attributes could use sizeof for the structure, but the size could be
9060@c changed later by "packed" attributes.
9061
9062
9063@subsubheading All other attributes
9064
9065Otherwise, an attribute specifier appears as part of a declaration,
9066counting declarations of unnamed parameters and type names, and relates
9067to that declaration (which may be nested in another declaration, for
9068example in the case of a parameter declaration), or to a particular declarator
9069within a declaration.  Where an
9070attribute specifier is applied to a parameter declared as a function or
9071an array, it should apply to the function or array rather than the
9072pointer to which the parameter is implicitly converted, but this is not
9073yet correctly implemented.
9074
9075Any list of specifiers and qualifiers at the start of a declaration may
9076contain attribute specifiers, whether or not such a list may in that
9077context contain storage class specifiers.  (Some attributes, however,
9078are essentially in the nature of storage class specifiers, and only make
9079sense where storage class specifiers may be used; for example,
9080@code{section}.)  There is one necessary limitation to this syntax: the
9081first old-style parameter declaration in a function definition cannot
9082begin with an attribute specifier, because such an attribute applies to
9083the function instead by syntax described below (which, however, is not
9084yet implemented in this case).  In some other cases, attribute
9085specifiers are permitted by this grammar but not yet supported by the
9086compiler.  All attribute specifiers in this place relate to the
9087declaration as a whole.  In the obsolescent usage where a type of
9088@code{int} is implied by the absence of type specifiers, such a list of
9089specifiers and qualifiers may be an attribute specifier list with no
9090other specifiers or qualifiers.
9091
9092At present, the first parameter in a function prototype must have some
9093type specifier that is not an attribute specifier; this resolves an
9094ambiguity in the interpretation of @code{void f(int
9095(__attribute__((foo)) x))}, but is subject to change.  At present, if
9096the parentheses of a function declarator contain only attributes then
9097those attributes are ignored, rather than yielding an error or warning
9098or implying a single parameter of type int, but this is subject to
9099change.
9100
9101An attribute specifier list may appear immediately before a declarator
9102(other than the first) in a comma-separated list of declarators in a
9103declaration of more than one identifier using a single list of
9104specifiers and qualifiers.  Such attribute specifiers apply
9105only to the identifier before whose declarator they appear.  For
9106example, in
9107
9108@smallexample
9109__attribute__((noreturn)) void d0 (void),
9110    __attribute__((format(printf, 1, 2))) d1 (const char *, ...),
9111     d2 (void);
9112@end smallexample
9113
9114@noindent
9115the @code{noreturn} attribute applies to all the functions
9116declared; the @code{format} attribute only applies to @code{d1}.
9117
9118An attribute specifier list may appear immediately before the comma,
9119@code{=} or semicolon terminating the declaration of an identifier other
9120than a function definition.  Such attribute specifiers apply
9121to the declared object or function.  Where an
9122assembler name for an object or function is specified (@pxref{Asm
9123Labels}), the attribute must follow the @code{asm}
9124specification.
9125
9126An attribute specifier list may, in future, be permitted to appear after
9127the declarator in a function definition (before any old-style parameter
9128declarations or the function body).
9129
9130Attribute specifiers may be mixed with type qualifiers appearing inside
9131the @code{[]} of a parameter array declarator, in the C99 construct by
9132which such qualifiers are applied to the pointer to which the array is
9133implicitly converted.  Such attribute specifiers apply to the pointer,
9134not to the array, but at present this is not implemented and they are
9135ignored.
9136
9137An attribute specifier list may appear at the start of a nested
9138declarator.  At present, there are some limitations in this usage: the
9139attributes correctly apply to the declarator, but for most individual
9140attributes the semantics this implies are not implemented.
9141When attribute specifiers follow the @code{*} of a pointer
9142declarator, they may be mixed with any type qualifiers present.
9143The following describes the formal semantics of this syntax.  It makes the
9144most sense if you are familiar with the formal specification of
9145declarators in the ISO C standard.
9146
9147Consider (as in C99 subclause 6.7.5 paragraph 4) a declaration @code{T
9148D1}, where @code{T} contains declaration specifiers that specify a type
9149@var{Type} (such as @code{int}) and @code{D1} is a declarator that
9150contains an identifier @var{ident}.  The type specified for @var{ident}
9151for derived declarators whose type does not include an attribute
9152specifier is as in the ISO C standard.
9153
9154If @code{D1} has the form @code{( @var{attribute-specifier-list} D )},
9155and the declaration @code{T D} specifies the type
9156``@var{derived-declarator-type-list} @var{Type}'' for @var{ident}, then
9157@code{T D1} specifies the type ``@var{derived-declarator-type-list}
9158@var{attribute-specifier-list} @var{Type}'' for @var{ident}.
9159
9160If @code{D1} has the form @code{*
9161@var{type-qualifier-and-attribute-specifier-list} D}, and the
9162declaration @code{T D} specifies the type
9163``@var{derived-declarator-type-list} @var{Type}'' for @var{ident}, then
9164@code{T D1} specifies the type ``@var{derived-declarator-type-list}
9165@var{type-qualifier-and-attribute-specifier-list} pointer to @var{Type}'' for
9166@var{ident}.
9167
9168For example,
9169
9170@smallexample
9171void (__attribute__((noreturn)) ****f) (void);
9172@end smallexample
9173
9174@noindent
9175specifies the type ``pointer to pointer to pointer to pointer to
9176non-returning function returning @code{void}''.  As another example,
9177
9178@smallexample
9179char *__attribute__((aligned(8))) *f;
9180@end smallexample
9181
9182@noindent
9183specifies the type ``pointer to 8-byte-aligned pointer to @code{char}''.
9184Note again that this does not work with most attributes; for example,
9185the usage of @samp{aligned} and @samp{noreturn} attributes given above
9186is not yet supported.
9187
9188For compatibility with existing code written for compiler versions that
9189did not implement attributes on nested declarators, some laxity is
9190allowed in the placing of attributes.  If an attribute that only applies
9191to types is applied to a declaration, it is treated as applying to
9192the type of that declaration.  If an attribute that only applies to
9193declarations is applied to the type of a declaration, it is treated
9194as applying to that declaration; and, for compatibility with code
9195placing the attributes immediately before the identifier declared, such
9196an attribute applied to a function return type is treated as
9197applying to the function type, and such an attribute applied to an array
9198element type is treated as applying to the array type.  If an
9199attribute that only applies to function types is applied to a
9200pointer-to-function type, it is treated as applying to the pointer
9201target type; if such an attribute is applied to a function return type
9202that is not a pointer-to-function type, it is treated as applying
9203to the function type.
9204
9205@node Function Prototypes
9206@section Prototypes and Old-Style Function Definitions
9207@cindex function prototype declarations
9208@cindex old-style function definitions
9209@cindex promotion of formal parameters
9210
9211GNU C extends ISO C to allow a function prototype to override a later
9212old-style non-prototype definition.  Consider the following example:
9213
9214@smallexample
9215/* @r{Use prototypes unless the compiler is old-fashioned.}  */
9216#ifdef __STDC__
9217#define P(x) x
9218#else
9219#define P(x) ()
9220#endif
9221
9222/* @r{Prototype function declaration.}  */
9223int isroot P((uid_t));
9224
9225/* @r{Old-style function definition.}  */
9226int
9227isroot (x)   /* @r{??? lossage here ???} */
9228     uid_t x;
9229@{
9230  return x == 0;
9231@}
9232@end smallexample
9233
9234Suppose the type @code{uid_t} happens to be @code{short}.  ISO C does
9235not allow this example, because subword arguments in old-style
9236non-prototype definitions are promoted.  Therefore in this example the
9237function definition's argument is really an @code{int}, which does not
9238match the prototype argument type of @code{short}.
9239
9240This restriction of ISO C makes it hard to write code that is portable
9241to traditional C compilers, because the programmer does not know
9242whether the @code{uid_t} type is @code{short}, @code{int}, or
9243@code{long}.  Therefore, in cases like these GNU C allows a prototype
9244to override a later old-style definition.  More precisely, in GNU C, a
9245function prototype argument type overrides the argument type specified
9246by a later old-style definition if the former type is the same as the
9247latter type before promotion.  Thus in GNU C the above example is
9248equivalent to the following:
9249
9250@smallexample
9251int isroot (uid_t);
9252
9253int
9254isroot (uid_t x)
9255@{
9256  return x == 0;
9257@}
9258@end smallexample
9259
9260@noindent
9261GNU C++ does not support old-style function definitions, so this
9262extension is irrelevant.
9263
9264@node C++ Comments
9265@section C++ Style Comments
9266@cindex @code{//}
9267@cindex C++ comments
9268@cindex comments, C++ style
9269
9270In GNU C, you may use C++ style comments, which start with @samp{//} and
9271continue until the end of the line.  Many other C implementations allow
9272such comments, and they are included in the 1999 C standard.  However,
9273C++ style comments are not recognized if you specify an @option{-std}
9274option specifying a version of ISO C before C99, or @option{-ansi}
9275(equivalent to @option{-std=c90}).
9276
9277@node Dollar Signs
9278@section Dollar Signs in Identifier Names
9279@cindex $
9280@cindex dollar signs in identifier names
9281@cindex identifier names, dollar signs in
9282
9283In GNU C, you may normally use dollar signs in identifier names.
9284This is because many traditional C implementations allow such identifiers.
9285However, dollar signs in identifiers are not supported on a few target
9286machines, typically because the target assembler does not allow them.
9287
9288@node Character Escapes
9289@section The Character @key{ESC} in Constants
9290
9291You can use the sequence @samp{\e} in a string or character constant to
9292stand for the ASCII character @key{ESC}.
9293
9294@node Alignment
9295@section Determining the Alignment of Functions, Types or Variables
9296@cindex alignment
9297@cindex type alignment
9298@cindex variable alignment
9299
9300The keyword @code{__alignof__} determines the alignment requirement of
9301a function, object, or a type, or the minimum alignment usually required
9302by a type.  Its syntax is just like @code{sizeof} and C11 @code{_Alignof}.
9303
9304For example, if the target machine requires a @code{double} value to be
9305aligned on an 8-byte boundary, then @code{__alignof__ (double)} is 8.
9306This is true on many RISC machines.  On more traditional machine
9307designs, @code{__alignof__ (double)} is 4 or even 2.
9308
9309Some machines never actually require alignment; they allow references to any
9310data type even at an odd address.  For these machines, @code{__alignof__}
9311reports the smallest alignment that GCC gives the data type, usually as
9312mandated by the target ABI.
9313
9314If the operand of @code{__alignof__} is an lvalue rather than a type,
9315its value is the required alignment for its type, taking into account
9316any minimum alignment specified by attribute @code{aligned}
9317(@pxref{Common Variable Attributes}).  For example, after this
9318declaration:
9319
9320@smallexample
9321struct foo @{ int x; char y; @} foo1;
9322@end smallexample
9323
9324@noindent
9325the value of @code{__alignof__ (foo1.y)} is 1, even though its actual
9326alignment is probably 2 or 4, the same as @code{__alignof__ (int)}.
9327It is an error to ask for the alignment of an incomplete type other
9328than @code{void}.
9329
9330If the operand of the @code{__alignof__} expression is a function,
9331the expression evaluates to the alignment of the function which may
9332be specified by attribute @code{aligned} (@pxref{Common Function Attributes}).
9333
9334@node Inline
9335@section An Inline Function is As Fast As a Macro
9336@cindex inline functions
9337@cindex integrating function code
9338@cindex open coding
9339@cindex macros, inline alternative
9340
9341By declaring a function inline, you can direct GCC to make
9342calls to that function faster.  One way GCC can achieve this is to
9343integrate that function's code into the code for its callers.  This
9344makes execution faster by eliminating the function-call overhead; in
9345addition, if any of the actual argument values are constant, their
9346known values may permit simplifications at compile time so that not
9347all of the inline function's code needs to be included.  The effect on
9348code size is less predictable; object code may be larger or smaller
9349with function inlining, depending on the particular case.  You can
9350also direct GCC to try to integrate all ``simple enough'' functions
9351into their callers with the option @option{-finline-functions}.
9352
9353GCC implements three different semantics of declaring a function
9354inline.  One is available with @option{-std=gnu89} or
9355@option{-fgnu89-inline} or when @code{gnu_inline} attribute is present
9356on all inline declarations, another when
9357@option{-std=c99},
9358@option{-std=gnu99} or an option for a later C version is used
9359(without @option{-fgnu89-inline}), and the third
9360is used when compiling C++.
9361
9362To declare a function inline, use the @code{inline} keyword in its
9363declaration, like this:
9364
9365@smallexample
9366static inline int
9367inc (int *a)
9368@{
9369  return (*a)++;
9370@}
9371@end smallexample
9372
9373If you are writing a header file to be included in ISO C90 programs, write
9374@code{__inline__} instead of @code{inline}.  @xref{Alternate Keywords}.
9375
9376The three types of inlining behave similarly in two important cases:
9377when the @code{inline} keyword is used on a @code{static} function,
9378like the example above, and when a function is first declared without
9379using the @code{inline} keyword and then is defined with
9380@code{inline}, like this:
9381
9382@smallexample
9383extern int inc (int *a);
9384inline int
9385inc (int *a)
9386@{
9387  return (*a)++;
9388@}
9389@end smallexample
9390
9391In both of these common cases, the program behaves the same as if you
9392had not used the @code{inline} keyword, except for its speed.
9393
9394@cindex inline functions, omission of
9395@opindex fkeep-inline-functions
9396When a function is both inline and @code{static}, if all calls to the
9397function are integrated into the caller, and the function's address is
9398never used, then the function's own assembler code is never referenced.
9399In this case, GCC does not actually output assembler code for the
9400function, unless you specify the option @option{-fkeep-inline-functions}.
9401If there is a nonintegrated call, then the function is compiled to
9402assembler code as usual.  The function must also be compiled as usual if
9403the program refers to its address, because that cannot be inlined.
9404
9405@opindex Winline
9406Note that certain usages in a function definition can make it unsuitable
9407for inline substitution.  Among these usages are: variadic functions,
9408use of @code{alloca}, use of computed goto (@pxref{Labels as Values}),
9409use of nonlocal goto, use of nested functions, use of @code{setjmp}, use
9410of @code{__builtin_longjmp} and use of @code{__builtin_return} or
9411@code{__builtin_apply_args}.  Using @option{-Winline} warns when a
9412function marked @code{inline} could not be substituted, and gives the
9413reason for the failure.
9414
9415@cindex automatic @code{inline} for C++ member fns
9416@cindex @code{inline} automatic for C++ member fns
9417@cindex member fns, automatically @code{inline}
9418@cindex C++ member fns, automatically @code{inline}
9419@opindex fno-default-inline
9420As required by ISO C++, GCC considers member functions defined within
9421the body of a class to be marked inline even if they are
9422not explicitly declared with the @code{inline} keyword.  You can
9423override this with @option{-fno-default-inline}; @pxref{C++ Dialect
9424Options,,Options Controlling C++ Dialect}.
9425
9426GCC does not inline any functions when not optimizing unless you specify
9427the @samp{always_inline} attribute for the function, like this:
9428
9429@smallexample
9430/* @r{Prototype.}  */
9431inline void foo (const char) __attribute__((always_inline));
9432@end smallexample
9433
9434The remainder of this section is specific to GNU C90 inlining.
9435
9436@cindex non-static inline function
9437When an inline function is not @code{static}, then the compiler must assume
9438that there may be calls from other source files; since a global symbol can
9439be defined only once in any program, the function must not be defined in
9440the other source files, so the calls therein cannot be integrated.
9441Therefore, a non-@code{static} inline function is always compiled on its
9442own in the usual fashion.
9443
9444If you specify both @code{inline} and @code{extern} in the function
9445definition, then the definition is used only for inlining.  In no case
9446is the function compiled on its own, not even if you refer to its
9447address explicitly.  Such an address becomes an external reference, as
9448if you had only declared the function, and had not defined it.
9449
9450This combination of @code{inline} and @code{extern} has almost the
9451effect of a macro.  The way to use it is to put a function definition in
9452a header file with these keywords, and put another copy of the
9453definition (lacking @code{inline} and @code{extern}) in a library file.
9454The definition in the header file causes most calls to the function
9455to be inlined.  If any uses of the function remain, they refer to
9456the single copy in the library.
9457
9458@node Volatiles
9459@section When is a Volatile Object Accessed?
9460@cindex accessing volatiles
9461@cindex volatile read
9462@cindex volatile write
9463@cindex volatile access
9464
9465C has the concept of volatile objects.  These are normally accessed by
9466pointers and used for accessing hardware or inter-thread
9467communication.  The standard encourages compilers to refrain from
9468optimizations concerning accesses to volatile objects, but leaves it
9469implementation defined as to what constitutes a volatile access.  The
9470minimum requirement is that at a sequence point all previous accesses
9471to volatile objects have stabilized and no subsequent accesses have
9472occurred.  Thus an implementation is free to reorder and combine
9473volatile accesses that occur between sequence points, but cannot do
9474so for accesses across a sequence point.  The use of volatile does
9475not allow you to violate the restriction on updating objects multiple
9476times between two sequence points.
9477
9478Accesses to non-volatile objects are not ordered with respect to
9479volatile accesses.  You cannot use a volatile object as a memory
9480barrier to order a sequence of writes to non-volatile memory.  For
9481instance:
9482
9483@smallexample
9484int *ptr = @var{something};
9485volatile int vobj;
9486*ptr = @var{something};
9487vobj = 1;
9488@end smallexample
9489
9490@noindent
9491Unless @var{*ptr} and @var{vobj} can be aliased, it is not guaranteed
9492that the write to @var{*ptr} occurs by the time the update
9493of @var{vobj} happens.  If you need this guarantee, you must use
9494a stronger memory barrier such as:
9495
9496@smallexample
9497int *ptr = @var{something};
9498volatile int vobj;
9499*ptr = @var{something};
9500asm volatile ("" : : : "memory");
9501vobj = 1;
9502@end smallexample
9503
9504A scalar volatile object is read when it is accessed in a void context:
9505
9506@smallexample
9507volatile int *src = @var{somevalue};
9508*src;
9509@end smallexample
9510
9511Such expressions are rvalues, and GCC implements this as a
9512read of the volatile object being pointed to.
9513
9514Assignments are also expressions and have an rvalue.  However when
9515assigning to a scalar volatile, the volatile object is not reread,
9516regardless of whether the assignment expression's rvalue is used or
9517not.  If the assignment's rvalue is used, the value is that assigned
9518to the volatile object.  For instance, there is no read of @var{vobj}
9519in all the following cases:
9520
9521@smallexample
9522int obj;
9523volatile int vobj;
9524vobj = @var{something};
9525obj = vobj = @var{something};
9526obj ? vobj = @var{onething} : vobj = @var{anotherthing};
9527obj = (@var{something}, vobj = @var{anotherthing});
9528@end smallexample
9529
9530If you need to read the volatile object after an assignment has
9531occurred, you must use a separate expression with an intervening
9532sequence point.
9533
9534As bit-fields are not individually addressable, volatile bit-fields may
9535be implicitly read when written to, or when adjacent bit-fields are
9536accessed.  Bit-field operations may be optimized such that adjacent
9537bit-fields are only partially accessed, if they straddle a storage unit
9538boundary.  For these reasons it is unwise to use volatile bit-fields to
9539access hardware.
9540
9541@node Using Assembly Language with C
9542@section How to Use Inline Assembly Language in C Code
9543@cindex @code{asm} keyword
9544@cindex assembly language in C
9545@cindex inline assembly language
9546@cindex mixing assembly language and C
9547
9548The @code{asm} keyword allows you to embed assembler instructions
9549within C code.  GCC provides two forms of inline @code{asm}
9550statements.  A @dfn{basic @code{asm}} statement is one with no
9551operands (@pxref{Basic Asm}), while an @dfn{extended @code{asm}}
9552statement (@pxref{Extended Asm}) includes one or more operands.
9553The extended form is preferred for mixing C and assembly language
9554within a function, but to include assembly language at
9555top level you must use basic @code{asm}.
9556
9557You can also use the @code{asm} keyword to override the assembler name
9558for a C symbol, or to place a C variable in a specific register.
9559
9560@menu
9561* Basic Asm::          Inline assembler without operands.
9562* Extended Asm::       Inline assembler with operands.
9563* Constraints::        Constraints for @code{asm} operands
9564* Asm Labels::         Specifying the assembler name to use for a C symbol.
9565* Explicit Register Variables::  Defining variables residing in specified
9566                       registers.
9567* Size of an asm::     How GCC calculates the size of an @code{asm} block.
9568@end menu
9569
9570@node Basic Asm
9571@subsection Basic Asm --- Assembler Instructions Without Operands
9572@cindex basic @code{asm}
9573@cindex assembly language in C, basic
9574
9575A basic @code{asm} statement has the following syntax:
9576
9577@example
9578asm @var{asm-qualifiers} ( @var{AssemblerInstructions} )
9579@end example
9580
9581The @code{asm} keyword is a GNU extension.
9582When writing code that can be compiled with @option{-ansi} and the
9583various @option{-std} options, use @code{__asm__} instead of
9584@code{asm} (@pxref{Alternate Keywords}).
9585
9586@subsubheading Qualifiers
9587@table @code
9588@item volatile
9589The optional @code{volatile} qualifier has no effect.
9590All basic @code{asm} blocks are implicitly volatile.
9591
9592@item inline
9593If you use the @code{inline} qualifier, then for inlining purposes the size
9594of the @code{asm} statement is taken as the smallest size possible (@pxref{Size
9595of an asm}).
9596@end table
9597
9598@subsubheading Parameters
9599@table @var
9600
9601@item AssemblerInstructions
9602This is a literal string that specifies the assembler code. The string can
9603contain any instructions recognized by the assembler, including directives.
9604GCC does not parse the assembler instructions themselves and
9605does not know what they mean or even whether they are valid assembler input.
9606
9607You may place multiple assembler instructions together in a single @code{asm}
9608string, separated by the characters normally used in assembly code for the
9609system. A combination that works in most places is a newline to break the
9610line, plus a tab character (written as @samp{\n\t}).
9611Some assemblers allow semicolons as a line separator. However,
9612note that some assembler dialects use semicolons to start a comment.
9613@end table
9614
9615@subsubheading Remarks
9616Using extended @code{asm} (@pxref{Extended Asm}) typically produces
9617smaller, safer, and more efficient code, and in most cases it is a
9618better solution than basic @code{asm}.  However, there are two
9619situations where only basic @code{asm} can be used:
9620
9621@itemize @bullet
9622@item
9623Extended @code{asm} statements have to be inside a C
9624function, so to write inline assembly language at file scope (``top-level''),
9625outside of C functions, you must use basic @code{asm}.
9626You can use this technique to emit assembler directives,
9627define assembly language macros that can be invoked elsewhere in the file,
9628or write entire functions in assembly language.
9629Basic @code{asm} statements outside of functions may not use any
9630qualifiers.
9631
9632@item
9633Functions declared
9634with the @code{naked} attribute also require basic @code{asm}
9635(@pxref{Function Attributes}).
9636@end itemize
9637
9638Safely accessing C data and calling functions from basic @code{asm} is more
9639complex than it may appear. To access C data, it is better to use extended
9640@code{asm}.
9641
9642Do not expect a sequence of @code{asm} statements to remain perfectly
9643consecutive after compilation. If certain instructions need to remain
9644consecutive in the output, put them in a single multi-instruction @code{asm}
9645statement. Note that GCC's optimizers can move @code{asm} statements
9646relative to other code, including across jumps.
9647
9648@code{asm} statements may not perform jumps into other @code{asm} statements.
9649GCC does not know about these jumps, and therefore cannot take
9650account of them when deciding how to optimize. Jumps from @code{asm} to C
9651labels are only supported in extended @code{asm}.
9652
9653Under certain circumstances, GCC may duplicate (or remove duplicates of) your
9654assembly code when optimizing. This can lead to unexpected duplicate
9655symbol errors during compilation if your assembly code defines symbols or
9656labels.
9657
9658@strong{Warning:} The C standards do not specify semantics for @code{asm},
9659making it a potential source of incompatibilities between compilers.  These
9660incompatibilities may not produce compiler warnings/errors.
9661
9662GCC does not parse basic @code{asm}'s @var{AssemblerInstructions}, which
9663means there is no way to communicate to the compiler what is happening
9664inside them.  GCC has no visibility of symbols in the @code{asm} and may
9665discard them as unreferenced.  It also does not know about side effects of
9666the assembler code, such as modifications to memory or registers.  Unlike
9667some compilers, GCC assumes that no changes to general purpose registers
9668occur.  This assumption may change in a future release.
9669
9670To avoid complications from future changes to the semantics and the
9671compatibility issues between compilers, consider replacing basic @code{asm}
9672with extended @code{asm}.  See
9673@uref{https://gcc.gnu.org/wiki/ConvertBasicAsmToExtended, How to convert
9674from basic asm to extended asm} for information about how to perform this
9675conversion.
9676
9677The compiler copies the assembler instructions in a basic @code{asm}
9678verbatim to the assembly language output file, without
9679processing dialects or any of the @samp{%} operators that are available with
9680extended @code{asm}. This results in minor differences between basic
9681@code{asm} strings and extended @code{asm} templates. For example, to refer to
9682registers you might use @samp{%eax} in basic @code{asm} and
9683@samp{%%eax} in extended @code{asm}.
9684
9685On targets such as x86 that support multiple assembler dialects,
9686all basic @code{asm} blocks use the assembler dialect specified by the
9687@option{-masm} command-line option (@pxref{x86 Options}).
9688Basic @code{asm} provides no
9689mechanism to provide different assembler strings for different dialects.
9690
9691For basic @code{asm} with non-empty assembler string GCC assumes
9692the assembler block does not change any general purpose registers,
9693but it may read or write any globally accessible variable.
9694
9695Here is an example of basic @code{asm} for i386:
9696
9697@example
9698/* Note that this code will not compile with -masm=intel */
9699#define DebugBreak() asm("int $3")
9700@end example
9701
9702@node Extended Asm
9703@subsection Extended Asm - Assembler Instructions with C Expression Operands
9704@cindex extended @code{asm}
9705@cindex assembly language in C, extended
9706
9707With extended @code{asm} you can read and write C variables from
9708assembler and perform jumps from assembler code to C labels.
9709Extended @code{asm} syntax uses colons (@samp{:}) to delimit
9710the operand parameters after the assembler template:
9711
9712@example
9713asm @var{asm-qualifiers} ( @var{AssemblerTemplate}
9714                 : @var{OutputOperands}
9715                 @r{[} : @var{InputOperands}
9716                 @r{[} : @var{Clobbers} @r{]} @r{]})
9717
9718asm @var{asm-qualifiers} ( @var{AssemblerTemplate}
9719                      : @var{OutputOperands}
9720                      : @var{InputOperands}
9721                      : @var{Clobbers}
9722                      : @var{GotoLabels})
9723@end example
9724where in the last form, @var{asm-qualifiers} contains @code{goto} (and in the
9725first form, not).
9726
9727The @code{asm} keyword is a GNU extension.
9728When writing code that can be compiled with @option{-ansi} and the
9729various @option{-std} options, use @code{__asm__} instead of
9730@code{asm} (@pxref{Alternate Keywords}).
9731
9732@subsubheading Qualifiers
9733@table @code
9734
9735@item volatile
9736The typical use of extended @code{asm} statements is to manipulate input
9737values to produce output values. However, your @code{asm} statements may
9738also produce side effects. If so, you may need to use the @code{volatile}
9739qualifier to disable certain optimizations. @xref{Volatile}.
9740
9741@item inline
9742If you use the @code{inline} qualifier, then for inlining purposes the size
9743of the @code{asm} statement is taken as the smallest size possible
9744(@pxref{Size of an asm}).
9745
9746@item goto
9747This qualifier informs the compiler that the @code{asm} statement may
9748perform a jump to one of the labels listed in the @var{GotoLabels}.
9749@xref{GotoLabels}.
9750@end table
9751
9752@subsubheading Parameters
9753@table @var
9754@item AssemblerTemplate
9755This is a literal string that is the template for the assembler code. It is a
9756combination of fixed text and tokens that refer to the input, output,
9757and goto parameters. @xref{AssemblerTemplate}.
9758
9759@item OutputOperands
9760A comma-separated list of the C variables modified by the instructions in the
9761@var{AssemblerTemplate}.  An empty list is permitted.  @xref{OutputOperands}.
9762
9763@item InputOperands
9764A comma-separated list of C expressions read by the instructions in the
9765@var{AssemblerTemplate}.  An empty list is permitted.  @xref{InputOperands}.
9766
9767@item Clobbers
9768A comma-separated list of registers or other values changed by the
9769@var{AssemblerTemplate}, beyond those listed as outputs.
9770An empty list is permitted.  @xref{Clobbers and Scratch Registers}.
9771
9772@item GotoLabels
9773When you are using the @code{goto} form of @code{asm}, this section contains
9774the list of all C labels to which the code in the
9775@var{AssemblerTemplate} may jump.
9776@xref{GotoLabels}.
9777
9778@code{asm} statements may not perform jumps into other @code{asm} statements,
9779only to the listed @var{GotoLabels}.
9780GCC's optimizers do not know about other jumps; therefore they cannot take
9781account of them when deciding how to optimize.
9782@end table
9783
9784The total number of input + output + goto operands is limited to 30.
9785
9786@subsubheading Remarks
9787The @code{asm} statement allows you to include assembly instructions directly
9788within C code. This may help you to maximize performance in time-sensitive
9789code or to access assembly instructions that are not readily available to C
9790programs.
9791
9792Note that extended @code{asm} statements must be inside a function. Only
9793basic @code{asm} may be outside functions (@pxref{Basic Asm}).
9794Functions declared with the @code{naked} attribute also require basic
9795@code{asm} (@pxref{Function Attributes}).
9796
9797While the uses of @code{asm} are many and varied, it may help to think of an
9798@code{asm} statement as a series of low-level instructions that convert input
9799parameters to output parameters. So a simple (if not particularly useful)
9800example for i386 using @code{asm} might look like this:
9801
9802@example
9803int src = 1;
9804int dst;
9805
9806asm ("mov %1, %0\n\t"
9807    "add $1, %0"
9808    : "=r" (dst)
9809    : "r" (src));
9810
9811printf("%d\n", dst);
9812@end example
9813
9814This code copies @code{src} to @code{dst} and add 1 to @code{dst}.
9815
9816@anchor{Volatile}
9817@subsubsection Volatile
9818@cindex volatile @code{asm}
9819@cindex @code{asm} volatile
9820
9821GCC's optimizers sometimes discard @code{asm} statements if they determine
9822there is no need for the output variables. Also, the optimizers may move
9823code out of loops if they believe that the code will always return the same
9824result (i.e.@: none of its input values change between calls). Using the
9825@code{volatile} qualifier disables these optimizations. @code{asm} statements
9826that have no output operands and @code{asm goto} statements,
9827are implicitly volatile.
9828
9829This i386 code demonstrates a case that does not use (or require) the
9830@code{volatile} qualifier. If it is performing assertion checking, this code
9831uses @code{asm} to perform the validation. Otherwise, @code{dwRes} is
9832unreferenced by any code. As a result, the optimizers can discard the
9833@code{asm} statement, which in turn removes the need for the entire
9834@code{DoCheck} routine. By omitting the @code{volatile} qualifier when it
9835isn't needed you allow the optimizers to produce the most efficient code
9836possible.
9837
9838@example
9839void DoCheck(uint32_t dwSomeValue)
9840@{
9841   uint32_t dwRes;
9842
9843   // Assumes dwSomeValue is not zero.
9844   asm ("bsfl %1,%0"
9845     : "=r" (dwRes)
9846     : "r" (dwSomeValue)
9847     : "cc");
9848
9849   assert(dwRes > 3);
9850@}
9851@end example
9852
9853The next example shows a case where the optimizers can recognize that the input
9854(@code{dwSomeValue}) never changes during the execution of the function and can
9855therefore move the @code{asm} outside the loop to produce more efficient code.
9856Again, using the @code{volatile} qualifier disables this type of optimization.
9857
9858@example
9859void do_print(uint32_t dwSomeValue)
9860@{
9861   uint32_t dwRes;
9862
9863   for (uint32_t x=0; x < 5; x++)
9864   @{
9865      // Assumes dwSomeValue is not zero.
9866      asm ("bsfl %1,%0"
9867        : "=r" (dwRes)
9868        : "r" (dwSomeValue)
9869        : "cc");
9870
9871      printf("%u: %u %u\n", x, dwSomeValue, dwRes);
9872   @}
9873@}
9874@end example
9875
9876The following example demonstrates a case where you need to use the
9877@code{volatile} qualifier.
9878It uses the x86 @code{rdtsc} instruction, which reads
9879the computer's time-stamp counter. Without the @code{volatile} qualifier,
9880the optimizers might assume that the @code{asm} block will always return the
9881same value and therefore optimize away the second call.
9882
9883@example
9884uint64_t msr;
9885
9886asm volatile ( "rdtsc\n\t"    // Returns the time in EDX:EAX.
9887        "shl $32, %%rdx\n\t"  // Shift the upper bits left.
9888        "or %%rdx, %0"        // 'Or' in the lower bits.
9889        : "=a" (msr)
9890        :
9891        : "rdx");
9892
9893printf("msr: %llx\n", msr);
9894
9895// Do other work...
9896
9897// Reprint the timestamp
9898asm volatile ( "rdtsc\n\t"    // Returns the time in EDX:EAX.
9899        "shl $32, %%rdx\n\t"  // Shift the upper bits left.
9900        "or %%rdx, %0"        // 'Or' in the lower bits.
9901        : "=a" (msr)
9902        :
9903        : "rdx");
9904
9905printf("msr: %llx\n", msr);
9906@end example
9907
9908GCC's optimizers do not treat this code like the non-volatile code in the
9909earlier examples. They do not move it out of loops or omit it on the
9910assumption that the result from a previous call is still valid.
9911
9912Note that the compiler can move even @code{volatile asm} instructions relative
9913to other code, including across jump instructions. For example, on many
9914targets there is a system register that controls the rounding mode of
9915floating-point operations. Setting it with a @code{volatile asm} statement,
9916as in the following PowerPC example, does not work reliably.
9917
9918@example
9919asm volatile("mtfsf 255, %0" : : "f" (fpenv));
9920sum = x + y;
9921@end example
9922
9923The compiler may move the addition back before the @code{volatile asm}
9924statement. To make it work as expected, add an artificial dependency to
9925the @code{asm} by referencing a variable in the subsequent code, for
9926example:
9927
9928@example
9929asm volatile ("mtfsf 255,%1" : "=X" (sum) : "f" (fpenv));
9930sum = x + y;
9931@end example
9932
9933Under certain circumstances, GCC may duplicate (or remove duplicates of) your
9934assembly code when optimizing. This can lead to unexpected duplicate symbol
9935errors during compilation if your @code{asm} code defines symbols or labels.
9936Using @samp{%=}
9937(@pxref{AssemblerTemplate}) may help resolve this problem.
9938
9939@anchor{AssemblerTemplate}
9940@subsubsection Assembler Template
9941@cindex @code{asm} assembler template
9942
9943An assembler template is a literal string containing assembler instructions.
9944The compiler replaces tokens in the template that refer
9945to inputs, outputs, and goto labels,
9946and then outputs the resulting string to the assembler. The
9947string can contain any instructions recognized by the assembler, including
9948directives. GCC does not parse the assembler instructions
9949themselves and does not know what they mean or even whether they are valid
9950assembler input. However, it does count the statements
9951(@pxref{Size of an asm}).
9952
9953You may place multiple assembler instructions together in a single @code{asm}
9954string, separated by the characters normally used in assembly code for the
9955system. A combination that works in most places is a newline to break the
9956line, plus a tab character to move to the instruction field (written as
9957@samp{\n\t}).
9958Some assemblers allow semicolons as a line separator. However, note
9959that some assembler dialects use semicolons to start a comment.
9960
9961Do not expect a sequence of @code{asm} statements to remain perfectly
9962consecutive after compilation, even when you are using the @code{volatile}
9963qualifier. If certain instructions need to remain consecutive in the output,
9964put them in a single multi-instruction @code{asm} statement.
9965
9966Accessing data from C programs without using input/output operands (such as
9967by using global symbols directly from the assembler template) may not work as
9968expected. Similarly, calling functions directly from an assembler template
9969requires a detailed understanding of the target assembler and ABI.
9970
9971Since GCC does not parse the assembler template,
9972it has no visibility of any
9973symbols it references. This may result in GCC discarding those symbols as
9974unreferenced unless they are also listed as input, output, or goto operands.
9975
9976@subsubheading Special format strings
9977
9978In addition to the tokens described by the input, output, and goto operands,
9979these tokens have special meanings in the assembler template:
9980
9981@table @samp
9982@item %%
9983Outputs a single @samp{%} into the assembler code.
9984
9985@item %=
9986Outputs a number that is unique to each instance of the @code{asm}
9987statement in the entire compilation. This option is useful when creating local
9988labels and referring to them multiple times in a single template that
9989generates multiple assembler instructions.
9990
9991@item %@{
9992@itemx %|
9993@itemx %@}
9994Outputs @samp{@{}, @samp{|}, and @samp{@}} characters (respectively)
9995into the assembler code.  When unescaped, these characters have special
9996meaning to indicate multiple assembler dialects, as described below.
9997@end table
9998
9999@subsubheading Multiple assembler dialects in @code{asm} templates
10000
10001On targets such as x86, GCC supports multiple assembler dialects.
10002The @option{-masm} option controls which dialect GCC uses as its
10003default for inline assembler. The target-specific documentation for the
10004@option{-masm} option contains the list of supported dialects, as well as the
10005default dialect if the option is not specified. This information may be
10006important to understand, since assembler code that works correctly when
10007compiled using one dialect will likely fail if compiled using another.
10008@xref{x86 Options}.
10009
10010If your code needs to support multiple assembler dialects (for example, if
10011you are writing public headers that need to support a variety of compilation
10012options), use constructs of this form:
10013
10014@example
10015@{ dialect0 | dialect1 | dialect2... @}
10016@end example
10017
10018This construct outputs @code{dialect0}
10019when using dialect #0 to compile the code,
10020@code{dialect1} for dialect #1, etc. If there are fewer alternatives within the
10021braces than the number of dialects the compiler supports, the construct
10022outputs nothing.
10023
10024For example, if an x86 compiler supports two dialects
10025(@samp{att}, @samp{intel}), an
10026assembler template such as this:
10027
10028@example
10029"bt@{l %[Offset],%[Base] | %[Base],%[Offset]@}; jc %l2"
10030@end example
10031
10032@noindent
10033is equivalent to one of
10034
10035@example
10036"btl %[Offset],%[Base] ; jc %l2"   @r{/* att dialect */}
10037"bt %[Base],%[Offset]; jc %l2"     @r{/* intel dialect */}
10038@end example
10039
10040Using that same compiler, this code:
10041
10042@example
10043"xchg@{l@}\t@{%%@}ebx, %1"
10044@end example
10045
10046@noindent
10047corresponds to either
10048
10049@example
10050"xchgl\t%%ebx, %1"                 @r{/* att dialect */}
10051"xchg\tebx, %1"                    @r{/* intel dialect */}
10052@end example
10053
10054There is no support for nesting dialect alternatives.
10055
10056@anchor{OutputOperands}
10057@subsubsection Output Operands
10058@cindex @code{asm} output operands
10059
10060An @code{asm} statement has zero or more output operands indicating the names
10061of C variables modified by the assembler code.
10062
10063In this i386 example, @code{old} (referred to in the template string as
10064@code{%0}) and @code{*Base} (as @code{%1}) are outputs and @code{Offset}
10065(@code{%2}) is an input:
10066
10067@example
10068bool old;
10069
10070__asm__ ("btsl %2,%1\n\t" // Turn on zero-based bit #Offset in Base.
10071         "sbb %0,%0"      // Use the CF to calculate old.
10072   : "=r" (old), "+rm" (*Base)
10073   : "Ir" (Offset)
10074   : "cc");
10075
10076return old;
10077@end example
10078
10079Operands are separated by commas.  Each operand has this format:
10080
10081@example
10082@r{[} [@var{asmSymbolicName}] @r{]} @var{constraint} (@var{cvariablename})
10083@end example
10084
10085@table @var
10086@item asmSymbolicName
10087Specifies a symbolic name for the operand.
10088Reference the name in the assembler template
10089by enclosing it in square brackets
10090(i.e.@: @samp{%[Value]}). The scope of the name is the @code{asm} statement
10091that contains the definition. Any valid C variable name is acceptable,
10092including names already defined in the surrounding code. No two operands
10093within the same @code{asm} statement can use the same symbolic name.
10094
10095When not using an @var{asmSymbolicName}, use the (zero-based) position
10096of the operand
10097in the list of operands in the assembler template. For example if there are
10098three output operands, use @samp{%0} in the template to refer to the first,
10099@samp{%1} for the second, and @samp{%2} for the third.
10100
10101@item constraint
10102A string constant specifying constraints on the placement of the operand;
10103@xref{Constraints}, for details.
10104
10105Output constraints must begin with either @samp{=} (a variable overwriting an
10106existing value) or @samp{+} (when reading and writing). When using
10107@samp{=}, do not assume the location contains the existing value
10108on entry to the @code{asm}, except
10109when the operand is tied to an input; @pxref{InputOperands,,Input Operands}.
10110
10111After the prefix, there must be one or more additional constraints
10112(@pxref{Constraints}) that describe where the value resides. Common
10113constraints include @samp{r} for register and @samp{m} for memory.
10114When you list more than one possible location (for example, @code{"=rm"}),
10115the compiler chooses the most efficient one based on the current context.
10116If you list as many alternates as the @code{asm} statement allows, you permit
10117the optimizers to produce the best possible code.
10118If you must use a specific register, but your Machine Constraints do not
10119provide sufficient control to select the specific register you want,
10120local register variables may provide a solution (@pxref{Local Register
10121Variables}).
10122
10123@item cvariablename
10124Specifies a C lvalue expression to hold the output, typically a variable name.
10125The enclosing parentheses are a required part of the syntax.
10126
10127@end table
10128
10129When the compiler selects the registers to use to
10130represent the output operands, it does not use any of the clobbered registers
10131(@pxref{Clobbers and Scratch Registers}).
10132
10133Output operand expressions must be lvalues. The compiler cannot check whether
10134the operands have data types that are reasonable for the instruction being
10135executed. For output expressions that are not directly addressable (for
10136example a bit-field), the constraint must allow a register. In that case, GCC
10137uses the register as the output of the @code{asm}, and then stores that
10138register into the output.
10139
10140Operands using the @samp{+} constraint modifier count as two operands
10141(that is, both as input and output) towards the total maximum of 30 operands
10142per @code{asm} statement.
10143
10144Use the @samp{&} constraint modifier (@pxref{Modifiers}) on all output
10145operands that must not overlap an input.  Otherwise,
10146GCC may allocate the output operand in the same register as an unrelated
10147input operand, on the assumption that the assembler code consumes its
10148inputs before producing outputs. This assumption may be false if the assembler
10149code actually consists of more than one instruction.
10150
10151The same problem can occur if one output parameter (@var{a}) allows a register
10152constraint and another output parameter (@var{b}) allows a memory constraint.
10153The code generated by GCC to access the memory address in @var{b} can contain
10154registers which @emph{might} be shared by @var{a}, and GCC considers those
10155registers to be inputs to the asm. As above, GCC assumes that such input
10156registers are consumed before any outputs are written. This assumption may
10157result in incorrect behavior if the @code{asm} statement writes to @var{a}
10158before using
10159@var{b}. Combining the @samp{&} modifier with the register constraint on @var{a}
10160ensures that modifying @var{a} does not affect the address referenced by
10161@var{b}. Otherwise, the location of @var{b}
10162is undefined if @var{a} is modified before using @var{b}.
10163
10164@code{asm} supports operand modifiers on operands (for example @samp{%k2}
10165instead of simply @samp{%2}). Typically these qualifiers are hardware
10166dependent. The list of supported modifiers for x86 is found at
10167@ref{x86Operandmodifiers,x86 Operand modifiers}.
10168
10169If the C code that follows the @code{asm} makes no use of any of the output
10170operands, use @code{volatile} for the @code{asm} statement to prevent the
10171optimizers from discarding the @code{asm} statement as unneeded
10172(see @ref{Volatile}).
10173
10174This code makes no use of the optional @var{asmSymbolicName}. Therefore it
10175references the first output operand as @code{%0} (were there a second, it
10176would be @code{%1}, etc). The number of the first input operand is one greater
10177than that of the last output operand. In this i386 example, that makes
10178@code{Mask} referenced as @code{%1}:
10179
10180@example
10181uint32_t Mask = 1234;
10182uint32_t Index;
10183
10184  asm ("bsfl %1, %0"
10185     : "=r" (Index)
10186     : "r" (Mask)
10187     : "cc");
10188@end example
10189
10190That code overwrites the variable @code{Index} (@samp{=}),
10191placing the value in a register (@samp{r}).
10192Using the generic @samp{r} constraint instead of a constraint for a specific
10193register allows the compiler to pick the register to use, which can result
10194in more efficient code. This may not be possible if an assembler instruction
10195requires a specific register.
10196
10197The following i386 example uses the @var{asmSymbolicName} syntax.
10198It produces the
10199same result as the code above, but some may consider it more readable or more
10200maintainable since reordering index numbers is not necessary when adding or
10201removing operands. The names @code{aIndex} and @code{aMask}
10202are only used in this example to emphasize which
10203names get used where.
10204It is acceptable to reuse the names @code{Index} and @code{Mask}.
10205
10206@example
10207uint32_t Mask = 1234;
10208uint32_t Index;
10209
10210  asm ("bsfl %[aMask], %[aIndex]"
10211     : [aIndex] "=r" (Index)
10212     : [aMask] "r" (Mask)
10213     : "cc");
10214@end example
10215
10216Here are some more examples of output operands.
10217
10218@example
10219uint32_t c = 1;
10220uint32_t d;
10221uint32_t *e = &c;
10222
10223asm ("mov %[e], %[d]"
10224   : [d] "=rm" (d)
10225   : [e] "rm" (*e));
10226@end example
10227
10228Here, @code{d} may either be in a register or in memory. Since the compiler
10229might already have the current value of the @code{uint32_t} location
10230pointed to by @code{e}
10231in a register, you can enable it to choose the best location
10232for @code{d} by specifying both constraints.
10233
10234@anchor{FlagOutputOperands}
10235@subsubsection Flag Output Operands
10236@cindex @code{asm} flag output operands
10237
10238Some targets have a special register that holds the ``flags'' for the
10239result of an operation or comparison.  Normally, the contents of that
10240register are either unmodifed by the asm, or the @code{asm} statement is
10241considered to clobber the contents.
10242
10243On some targets, a special form of output operand exists by which
10244conditions in the flags register may be outputs of the asm.  The set of
10245conditions supported are target specific, but the general rule is that
10246the output variable must be a scalar integer, and the value is boolean.
10247When supported, the target defines the preprocessor symbol
10248@code{__GCC_ASM_FLAG_OUTPUTS__}.
10249
10250Because of the special nature of the flag output operands, the constraint
10251may not include alternatives.
10252
10253Most often, the target has only one flags register, and thus is an implied
10254operand of many instructions.  In this case, the operand should not be
10255referenced within the assembler template via @code{%0} etc, as there's
10256no corresponding text in the assembly language.
10257
10258@table @asis
10259@item ARM
10260@itemx AArch64
10261The flag output constraints for the ARM family are of the form
10262@samp{=@@cc@var{cond}} where @var{cond} is one of the standard
10263conditions defined in the ARM ARM for @code{ConditionHolds}.
10264
10265@table @code
10266@item eq
10267Z flag set, or equal
10268@item ne
10269Z flag clear or not equal
10270@item cs
10271@itemx hs
10272C flag set or unsigned greater than equal
10273@item cc
10274@itemx lo
10275C flag clear or unsigned less than
10276@item mi
10277N flag set or ``minus''
10278@item pl
10279N flag clear or ``plus''
10280@item vs
10281V flag set or signed overflow
10282@item vc
10283V flag clear
10284@item hi
10285unsigned greater than
10286@item ls
10287unsigned less than equal
10288@item ge
10289signed greater than equal
10290@item lt
10291signed less than
10292@item gt
10293signed greater than
10294@item le
10295signed less than equal
10296@end table
10297
10298The flag output constraints are not supported in thumb1 mode.
10299
10300@item x86 family
10301The flag output constraints for the x86 family are of the form
10302@samp{=@@cc@var{cond}} where @var{cond} is one of the standard
10303conditions defined in the ISA manual for @code{j@var{cc}} or
10304@code{set@var{cc}}.
10305
10306@table @code
10307@item a
10308``above'' or unsigned greater than
10309@item ae
10310``above or equal'' or unsigned greater than or equal
10311@item b
10312``below'' or unsigned less than
10313@item be
10314``below or equal'' or unsigned less than or equal
10315@item c
10316carry flag set
10317@item e
10318@itemx z
10319``equal'' or zero flag set
10320@item g
10321signed greater than
10322@item ge
10323signed greater than or equal
10324@item l
10325signed less than
10326@item le
10327signed less than or equal
10328@item o
10329overflow flag set
10330@item p
10331parity flag set
10332@item s
10333sign flag set
10334@item na
10335@itemx nae
10336@itemx nb
10337@itemx nbe
10338@itemx nc
10339@itemx ne
10340@itemx ng
10341@itemx nge
10342@itemx nl
10343@itemx nle
10344@itemx no
10345@itemx np
10346@itemx ns
10347@itemx nz
10348``not'' @var{flag}, or inverted versions of those above
10349@end table
10350
10351@end table
10352
10353@anchor{InputOperands}
10354@subsubsection Input Operands
10355@cindex @code{asm} input operands
10356@cindex @code{asm} expressions
10357
10358Input operands make values from C variables and expressions available to the
10359assembly code.
10360
10361Operands are separated by commas.  Each operand has this format:
10362
10363@example
10364@r{[} [@var{asmSymbolicName}] @r{]} @var{constraint} (@var{cexpression})
10365@end example
10366
10367@table @var
10368@item asmSymbolicName
10369Specifies a symbolic name for the operand.
10370Reference the name in the assembler template
10371by enclosing it in square brackets
10372(i.e.@: @samp{%[Value]}). The scope of the name is the @code{asm} statement
10373that contains the definition. Any valid C variable name is acceptable,
10374including names already defined in the surrounding code. No two operands
10375within the same @code{asm} statement can use the same symbolic name.
10376
10377When not using an @var{asmSymbolicName}, use the (zero-based) position
10378of the operand
10379in the list of operands in the assembler template. For example if there are
10380two output operands and three inputs,
10381use @samp{%2} in the template to refer to the first input operand,
10382@samp{%3} for the second, and @samp{%4} for the third.
10383
10384@item constraint
10385A string constant specifying constraints on the placement of the operand;
10386@xref{Constraints}, for details.
10387
10388Input constraint strings may not begin with either @samp{=} or @samp{+}.
10389When you list more than one possible location (for example, @samp{"irm"}),
10390the compiler chooses the most efficient one based on the current context.
10391If you must use a specific register, but your Machine Constraints do not
10392provide sufficient control to select the specific register you want,
10393local register variables may provide a solution (@pxref{Local Register
10394Variables}).
10395
10396Input constraints can also be digits (for example, @code{"0"}). This indicates
10397that the specified input must be in the same place as the output constraint
10398at the (zero-based) index in the output constraint list.
10399When using @var{asmSymbolicName} syntax for the output operands,
10400you may use these names (enclosed in brackets @samp{[]}) instead of digits.
10401
10402@item cexpression
10403This is the C variable or expression being passed to the @code{asm} statement
10404as input.  The enclosing parentheses are a required part of the syntax.
10405
10406@end table
10407
10408When the compiler selects the registers to use to represent the input
10409operands, it does not use any of the clobbered registers
10410(@pxref{Clobbers and Scratch Registers}).
10411
10412If there are no output operands but there are input operands, place two
10413consecutive colons where the output operands would go:
10414
10415@example
10416__asm__ ("some instructions"
10417   : /* No outputs. */
10418   : "r" (Offset / 8));
10419@end example
10420
10421@strong{Warning:} Do @emph{not} modify the contents of input-only operands
10422(except for inputs tied to outputs). The compiler assumes that on exit from
10423the @code{asm} statement these operands contain the same values as they
10424had before executing the statement.
10425It is @emph{not} possible to use clobbers
10426to inform the compiler that the values in these inputs are changing. One
10427common work-around is to tie the changing input variable to an output variable
10428that never gets used. Note, however, that if the code that follows the
10429@code{asm} statement makes no use of any of the output operands, the GCC
10430optimizers may discard the @code{asm} statement as unneeded
10431(see @ref{Volatile}).
10432
10433@code{asm} supports operand modifiers on operands (for example @samp{%k2}
10434instead of simply @samp{%2}). Typically these qualifiers are hardware
10435dependent. The list of supported modifiers for x86 is found at
10436@ref{x86Operandmodifiers,x86 Operand modifiers}.
10437
10438In this example using the fictitious @code{combine} instruction, the
10439constraint @code{"0"} for input operand 1 says that it must occupy the same
10440location as output operand 0. Only input operands may use numbers in
10441constraints, and they must each refer to an output operand. Only a number (or
10442the symbolic assembler name) in the constraint can guarantee that one operand
10443is in the same place as another. The mere fact that @code{foo} is the value of
10444both operands is not enough to guarantee that they are in the same place in
10445the generated assembler code.
10446
10447@example
10448asm ("combine %2, %0"
10449   : "=r" (foo)
10450   : "0" (foo), "g" (bar));
10451@end example
10452
10453Here is an example using symbolic names.
10454
10455@example
10456asm ("cmoveq %1, %2, %[result]"
10457   : [result] "=r"(result)
10458   : "r" (test), "r" (new), "[result]" (old));
10459@end example
10460
10461@anchor{Clobbers and Scratch Registers}
10462@subsubsection Clobbers and Scratch Registers
10463@cindex @code{asm} clobbers
10464@cindex @code{asm} scratch registers
10465
10466While the compiler is aware of changes to entries listed in the output
10467operands, the inline @code{asm} code may modify more than just the outputs. For
10468example, calculations may require additional registers, or the processor may
10469overwrite a register as a side effect of a particular assembler instruction.
10470In order to inform the compiler of these changes, list them in the clobber
10471list. Clobber list items are either register names or the special clobbers
10472(listed below). Each clobber list item is a string constant
10473enclosed in double quotes and separated by commas.
10474
10475Clobber descriptions may not in any way overlap with an input or output
10476operand. For example, you may not have an operand describing a register class
10477with one member when listing that register in the clobber list. Variables
10478declared to live in specific registers (@pxref{Explicit Register
10479Variables}) and used
10480as @code{asm} input or output operands must have no part mentioned in the
10481clobber description. In particular, there is no way to specify that input
10482operands get modified without also specifying them as output operands.
10483
10484When the compiler selects which registers to use to represent input and output
10485operands, it does not use any of the clobbered registers. As a result,
10486clobbered registers are available for any use in the assembler code.
10487
10488Another restriction is that the clobber list should not contain the
10489stack pointer register.  This is because the compiler requires the
10490value of the stack pointer to be the same after an @code{asm}
10491statement as it was on entry to the statement.  However, previous
10492versions of GCC did not enforce this rule and allowed the stack
10493pointer to appear in the list, with unclear semantics.  This behavior
10494is deprecated and listing the stack pointer may become an error in
10495future versions of GCC@.
10496
10497Here is a realistic example for the VAX showing the use of clobbered
10498registers:
10499
10500@example
10501asm volatile ("movc3 %0, %1, %2"
10502                   : /* No outputs. */
10503                   : "g" (from), "g" (to), "g" (count)
10504                   : "r0", "r1", "r2", "r3", "r4", "r5", "memory");
10505@end example
10506
10507Also, there are two special clobber arguments:
10508
10509@table @code
10510@item "cc"
10511The @code{"cc"} clobber indicates that the assembler code modifies the flags
10512register. On some machines, GCC represents the condition codes as a specific
10513hardware register; @code{"cc"} serves to name this register.
10514On other machines, condition code handling is different,
10515and specifying @code{"cc"} has no effect. But
10516it is valid no matter what the target.
10517
10518@item "memory"
10519The @code{"memory"} clobber tells the compiler that the assembly code
10520performs memory
10521reads or writes to items other than those listed in the input and output
10522operands (for example, accessing the memory pointed to by one of the input
10523parameters). To ensure memory contains correct values, GCC may need to flush
10524specific register values to memory before executing the @code{asm}. Further,
10525the compiler does not assume that any values read from memory before an
10526@code{asm} remain unchanged after that @code{asm}; it reloads them as
10527needed.
10528Using the @code{"memory"} clobber effectively forms a read/write
10529memory barrier for the compiler.
10530
10531Note that this clobber does not prevent the @emph{processor} from doing
10532speculative reads past the @code{asm} statement. To prevent that, you need
10533processor-specific fence instructions.
10534
10535@end table
10536
10537Flushing registers to memory has performance implications and may be
10538an issue for time-sensitive code.  You can provide better information
10539to GCC to avoid this, as shown in the following examples.  At a
10540minimum, aliasing rules allow GCC to know what memory @emph{doesn't}
10541need to be flushed.
10542
10543Here is a fictitious sum of squares instruction, that takes two
10544pointers to floating point values in memory and produces a floating
10545point register output.
10546Notice that @code{x}, and @code{y} both appear twice in the @code{asm}
10547parameters, once to specify memory accessed, and once to specify a
10548base register used by the @code{asm}.  You won't normally be wasting a
10549register by doing this as GCC can use the same register for both
10550purposes.  However, it would be foolish to use both @code{%1} and
10551@code{%3} for @code{x} in this @code{asm} and expect them to be the
10552same.  In fact, @code{%3} may well not be a register.  It might be a
10553symbolic memory reference to the object pointed to by @code{x}.
10554
10555@smallexample
10556asm ("sumsq %0, %1, %2"
10557     : "+f" (result)
10558     : "r" (x), "r" (y), "m" (*x), "m" (*y));
10559@end smallexample
10560
10561Here is a fictitious @code{*z++ = *x++ * *y++} instruction.
10562Notice that the @code{x}, @code{y} and @code{z} pointer registers
10563must be specified as input/output because the @code{asm} modifies
10564them.
10565
10566@smallexample
10567asm ("vecmul %0, %1, %2"
10568     : "+r" (z), "+r" (x), "+r" (y), "=m" (*z)
10569     : "m" (*x), "m" (*y));
10570@end smallexample
10571
10572An x86 example where the string memory argument is of unknown length.
10573
10574@smallexample
10575asm("repne scasb"
10576    : "=c" (count), "+D" (p)
10577    : "m" (*(const char (*)[]) p), "0" (-1), "a" (0));
10578@end smallexample
10579
10580If you know the above will only be reading a ten byte array then you
10581could instead use a memory input like:
10582@code{"m" (*(const char (*)[10]) p)}.
10583
10584Here is an example of a PowerPC vector scale implemented in assembly,
10585complete with vector and condition code clobbers, and some initialized
10586offset registers that are unchanged by the @code{asm}.
10587
10588@smallexample
10589void
10590dscal (size_t n, double *x, double alpha)
10591@{
10592  asm ("/* lots of asm here */"
10593       : "+m" (*(double (*)[n]) x), "+&r" (n), "+b" (x)
10594       : "d" (alpha), "b" (32), "b" (48), "b" (64),
10595         "b" (80), "b" (96), "b" (112)
10596       : "cr0",
10597         "vs32","vs33","vs34","vs35","vs36","vs37","vs38","vs39",
10598         "vs40","vs41","vs42","vs43","vs44","vs45","vs46","vs47");
10599@}
10600@end smallexample
10601
10602Rather than allocating fixed registers via clobbers to provide scratch
10603registers for an @code{asm} statement, an alternative is to define a
10604variable and make it an early-clobber output as with @code{a2} and
10605@code{a3} in the example below.  This gives the compiler register
10606allocator more freedom.  You can also define a variable and make it an
10607output tied to an input as with @code{a0} and @code{a1}, tied
10608respectively to @code{ap} and @code{lda}.  Of course, with tied
10609outputs your @code{asm} can't use the input value after modifying the
10610output register since they are one and the same register.  What's
10611more, if you omit the early-clobber on the output, it is possible that
10612GCC might allocate the same register to another of the inputs if GCC
10613could prove they had the same value on entry to the @code{asm}.  This
10614is why @code{a1} has an early-clobber.  Its tied input, @code{lda}
10615might conceivably be known to have the value 16 and without an
10616early-clobber share the same register as @code{%11}.  On the other
10617hand, @code{ap} can't be the same as any of the other inputs, so an
10618early-clobber on @code{a0} is not needed.  It is also not desirable in
10619this case.  An early-clobber on @code{a0} would cause GCC to allocate
10620a separate register for the @code{"m" (*(const double (*)[]) ap)}
10621input.  Note that tying an input to an output is the way to set up an
10622initialized temporary register modified by an @code{asm} statement.
10623An input not tied to an output is assumed by GCC to be unchanged, for
10624example @code{"b" (16)} below sets up @code{%11} to 16, and GCC might
10625use that register in following code if the value 16 happened to be
10626needed.  You can even use a normal @code{asm} output for a scratch if
10627all inputs that might share the same register are consumed before the
10628scratch is used.  The VSX registers clobbered by the @code{asm}
10629statement could have used this technique except for GCC's limit on the
10630number of @code{asm} parameters.
10631
10632@smallexample
10633static void
10634dgemv_kernel_4x4 (long n, const double *ap, long lda,
10635                  const double *x, double *y, double alpha)
10636@{
10637  double *a0;
10638  double *a1;
10639  double *a2;
10640  double *a3;
10641
10642  __asm__
10643    (
10644     /* lots of asm here */
10645     "#n=%1 ap=%8=%12 lda=%13 x=%7=%10 y=%0=%2 alpha=%9 o16=%11\n"
10646     "#a0=%3 a1=%4 a2=%5 a3=%6"
10647     :
10648       "+m" (*(double (*)[n]) y),
10649       "+&r" (n),	// 1
10650       "+b" (y),	// 2
10651       "=b" (a0),	// 3
10652       "=&b" (a1),	// 4
10653       "=&b" (a2),	// 5
10654       "=&b" (a3)	// 6
10655     :
10656       "m" (*(const double (*)[n]) x),
10657       "m" (*(const double (*)[]) ap),
10658       "d" (alpha),	// 9
10659       "r" (x),		// 10
10660       "b" (16),	// 11
10661       "3" (ap),	// 12
10662       "4" (lda)	// 13
10663     :
10664       "cr0",
10665       "vs32","vs33","vs34","vs35","vs36","vs37",
10666       "vs40","vs41","vs42","vs43","vs44","vs45","vs46","vs47"
10667     );
10668@}
10669@end smallexample
10670
10671@anchor{GotoLabels}
10672@subsubsection Goto Labels
10673@cindex @code{asm} goto labels
10674
10675@code{asm goto} allows assembly code to jump to one or more C labels.  The
10676@var{GotoLabels} section in an @code{asm goto} statement contains
10677a comma-separated
10678list of all C labels to which the assembler code may jump. GCC assumes that
10679@code{asm} execution falls through to the next statement (if this is not the
10680case, consider using the @code{__builtin_unreachable} intrinsic after the
10681@code{asm} statement). Optimization of @code{asm goto} may be improved by
10682using the @code{hot} and @code{cold} label attributes (@pxref{Label
10683Attributes}).
10684
10685If the assembler code does modify anything, use the @code{"memory"} clobber
10686to force the
10687optimizers to flush all register values to memory and reload them if
10688necessary after the @code{asm} statement.
10689
10690Also note that an @code{asm goto} statement is always implicitly
10691considered volatile.
10692
10693Be careful when you set output operands inside @code{asm goto} only on
10694some possible control flow paths.  If you don't set up the output on
10695given path and never use it on this path, it is okay.  Otherwise, you
10696should use @samp{+} constraint modifier meaning that the operand is
10697input and output one.  With this modifier you will have the correct
10698values on all possible paths from the @code{asm goto}.
10699
10700To reference a label in the assembler template, prefix it with
10701@samp{%l} (lowercase @samp{L}) followed by its (zero-based) position
10702in @var{GotoLabels} plus the number of input and output operands.
10703Output operand with constraint modifier @samp{+} is counted as two
10704operands because it is considered as one output and one input operand.
10705For example, if the @code{asm} has three inputs, one output operand
10706with constraint modifier @samp{+} and one output operand with
10707constraint modifier @samp{=} and references two labels, refer to the
10708first label as @samp{%l6} and the second as @samp{%l7}).
10709
10710Alternately, you can reference labels using the actual C label name
10711enclosed in brackets.  For example, to reference a label named
10712@code{carry}, you can use @samp{%l[carry]}.  The label must still be
10713listed in the @var{GotoLabels} section when using this approach.  It
10714is better to use the named references for labels as in this case you
10715can avoid counting input and output operands and special treatment of
10716output operands with constraint modifier @samp{+}.
10717
10718Here is an example of @code{asm goto} for i386:
10719
10720@example
10721asm goto (
10722    "btl %1, %0\n\t"
10723    "jc %l2"
10724    : /* No outputs. */
10725    : "r" (p1), "r" (p2)
10726    : "cc"
10727    : carry);
10728
10729return 0;
10730
10731carry:
10732return 1;
10733@end example
10734
10735The following example shows an @code{asm goto} that uses a memory clobber.
10736
10737@example
10738int frob(int x)
10739@{
10740  int y;
10741  asm goto ("frob %%r5, %1; jc %l[error]; mov (%2), %%r5"
10742            : /* No outputs. */
10743            : "r"(x), "r"(&y)
10744            : "r5", "memory"
10745            : error);
10746  return y;
10747error:
10748  return -1;
10749@}
10750@end example
10751
10752The following example shows an @code{asm goto} that uses an output.
10753
10754@example
10755int foo(int count)
10756@{
10757  asm goto ("dec %0; jb %l[stop]"
10758            : "+r" (count)
10759            :
10760            :
10761            : stop);
10762  return count;
10763stop:
10764  return 0;
10765@}
10766@end example
10767
10768The following artificial example shows an @code{asm goto} that sets
10769up an output only on one path inside the @code{asm goto}.  Usage of
10770constraint modifier @code{=} instead of @code{+} would be wrong as
10771@code{factor} is used on all paths from the @code{asm goto}.
10772
10773@example
10774int foo(int inp)
10775@{
10776  int factor = 0;
10777  asm goto ("cmp %1, 10; jb %l[lab]; mov 2, %0"
10778            : "+r" (factor)
10779            : "r" (inp)
10780            :
10781            : lab);
10782lab:
10783  return inp * factor; /* return 2 * inp or 0 if inp < 10 */
10784@}
10785@end example
10786
10787@anchor{x86Operandmodifiers}
10788@subsubsection x86 Operand Modifiers
10789
10790References to input, output, and goto operands in the assembler template
10791of extended @code{asm} statements can use
10792modifiers to affect the way the operands are formatted in
10793the code output to the assembler. For example, the
10794following code uses the @samp{h} and @samp{b} modifiers for x86:
10795
10796@example
10797uint16_t  num;
10798asm volatile ("xchg %h0, %b0" : "+a" (num) );
10799@end example
10800
10801@noindent
10802These modifiers generate this assembler code:
10803
10804@example
10805xchg %ah, %al
10806@end example
10807
10808The rest of this discussion uses the following code for illustrative purposes.
10809
10810@example
10811int main()
10812@{
10813   int iInt = 1;
10814
10815top:
10816
10817   asm volatile goto ("some assembler instructions here"
10818   : /* No outputs. */
10819   : "q" (iInt), "X" (sizeof(unsigned char) + 1), "i" (42)
10820   : /* No clobbers. */
10821   : top);
10822@}
10823@end example
10824
10825With no modifiers, this is what the output from the operands would be
10826for the @samp{att} and @samp{intel} dialects of assembler:
10827
10828@multitable {Operand} {$.L2} {OFFSET FLAT:.L2}
10829@headitem Operand @tab @samp{att} @tab @samp{intel}
10830@item @code{%0}
10831@tab @code{%eax}
10832@tab @code{eax}
10833@item @code{%1}
10834@tab @code{$2}
10835@tab @code{2}
10836@item @code{%3}
10837@tab @code{$.L3}
10838@tab @code{OFFSET FLAT:.L3}
10839@item @code{%4}
10840@tab @code{$8}
10841@tab @code{8}
10842@item @code{%5}
10843@tab @code{%xmm0}
10844@tab @code{xmm0}
10845@item @code{%7}
10846@tab @code{$0}
10847@tab @code{0}
10848@end multitable
10849
10850The table below shows the list of supported modifiers and their effects.
10851
10852@multitable {Modifier} {Print the opcode suffix for the size of th} {Operand} {@samp{att}} {@samp{intel}}
10853@headitem Modifier @tab Description @tab Operand @tab @samp{att} @tab @samp{intel}
10854@item @code{A}
10855@tab Print an absolute memory reference.
10856@tab @code{%A0}
10857@tab @code{*%rax}
10858@tab @code{rax}
10859@item @code{b}
10860@tab Print the QImode name of the register.
10861@tab @code{%b0}
10862@tab @code{%al}
10863@tab @code{al}
10864@item @code{B}
10865@tab print the opcode suffix of b.
10866@tab @code{%B0}
10867@tab @code{b}
10868@tab
10869@item @code{c}
10870@tab Require a constant operand and print the constant expression with no punctuation.
10871@tab @code{%c1}
10872@tab @code{2}
10873@tab @code{2}
10874@item @code{d}
10875@tab print duplicated register operand for AVX instruction.
10876@tab @code{%d5}
10877@tab @code{%xmm0, %xmm0}
10878@tab @code{xmm0, xmm0}
10879@item @code{E}
10880@tab Print the address in Double Integer (DImode) mode (8 bytes) when the target is 64-bit.
10881Otherwise mode is unspecified (VOIDmode).
10882@tab @code{%E1}
10883@tab @code{%(rax)}
10884@tab @code{[rax]}
10885@item @code{g}
10886@tab Print the V16SFmode name of the register.
10887@tab @code{%g0}
10888@tab @code{%zmm0}
10889@tab @code{zmm0}
10890@item @code{h}
10891@tab Print the QImode name for a ``high'' register.
10892@tab @code{%h0}
10893@tab @code{%ah}
10894@tab @code{ah}
10895@item @code{H}
10896@tab Add 8 bytes to an offsettable memory reference. Useful when accessing the
10897high 8 bytes of SSE values. For a memref in (%rax), it generates
10898@tab @code{%H0}
10899@tab @code{8(%rax)}
10900@tab @code{8[rax]}
10901@item @code{k}
10902@tab Print the SImode name of the register.
10903@tab @code{%k0}
10904@tab @code{%eax}
10905@tab @code{eax}
10906@item @code{l}
10907@tab Print the label name with no punctuation.
10908@tab @code{%l3}
10909@tab @code{.L3}
10910@tab @code{.L3}
10911@item @code{L}
10912@tab print the opcode suffix of l.
10913@tab @code{%L0}
10914@tab @code{l}
10915@tab
10916@item @code{N}
10917@tab print maskz.
10918@tab @code{%N7}
10919@tab @code{@{z@}}
10920@tab @code{@{z@}}
10921@item @code{p}
10922@tab Print raw symbol name (without syntax-specific prefixes).
10923@tab @code{%p2}
10924@tab @code{42}
10925@tab @code{42}
10926@item @code{P}
10927@tab If used for a function, print the PLT suffix and generate PIC code.
10928For example, emit @code{foo@@PLT} instead of 'foo' for the function
10929foo(). If used for a constant, drop all syntax-specific prefixes and
10930issue the bare constant. See @code{p} above.
10931@item @code{q}
10932@tab Print the DImode name of the register.
10933@tab @code{%q0}
10934@tab @code{%rax}
10935@tab @code{rax}
10936@item @code{Q}
10937@tab print the opcode suffix of q.
10938@tab @code{%Q0}
10939@tab @code{q}
10940@tab
10941@item @code{R}
10942@tab print embedded rounding and sae.
10943@tab @code{%R4}
10944@tab @code{@{rn-sae@}, }
10945@tab @code{, @{rn-sae@}}
10946@item @code{r}
10947@tab print only sae.
10948@tab @code{%r4}
10949@tab @code{@{sae@}, }
10950@tab @code{, @{sae@}}
10951@item @code{s}
10952@tab print a shift double count, followed by the assemblers argument
10953delimiterprint the opcode suffix of s.
10954@tab @code{%s1}
10955@tab @code{$2, }
10956@tab @code{2, }
10957@item @code{S}
10958@tab print the opcode suffix of s.
10959@tab @code{%S0}
10960@tab @code{s}
10961@tab
10962@item @code{t}
10963@tab print the V8SFmode name of the register.
10964@tab @code{%t5}
10965@tab @code{%ymm0}
10966@tab @code{ymm0}
10967@item @code{T}
10968@tab print the opcode suffix of t.
10969@tab @code{%T0}
10970@tab @code{t}
10971@tab
10972@item @code{V}
10973@tab print naked full integer register name without %.
10974@tab @code{%V0}
10975@tab @code{eax}
10976@tab @code{eax}
10977@item @code{w}
10978@tab Print the HImode name of the register.
10979@tab @code{%w0}
10980@tab @code{%ax}
10981@tab @code{ax}
10982@item @code{W}
10983@tab print the opcode suffix of w.
10984@tab @code{%W0}
10985@tab @code{w}
10986@tab
10987@item @code{x}
10988@tab print the V4SFmode name of the register.
10989@tab @code{%x5}
10990@tab @code{%xmm0}
10991@tab @code{xmm0}
10992@item @code{y}
10993@tab print "st(0)" instead of "st" as a register.
10994@tab @code{%y6}
10995@tab @code{%st(0)}
10996@tab @code{st(0)}
10997@item @code{z}
10998@tab Print the opcode suffix for the size of the current integer operand (one of @code{b}/@code{w}/@code{l}/@code{q}).
10999@tab @code{%z0}
11000@tab @code{l}
11001@tab
11002@item @code{Z}
11003@tab Like @code{z}, with special suffixes for x87 instructions.
11004@end multitable
11005
11006
11007@anchor{x86floatingpointasmoperands}
11008@subsubsection x86 Floating-Point @code{asm} Operands
11009
11010On x86 targets, there are several rules on the usage of stack-like registers
11011in the operands of an @code{asm}.  These rules apply only to the operands
11012that are stack-like registers:
11013
11014@enumerate
11015@item
11016Given a set of input registers that die in an @code{asm}, it is
11017necessary to know which are implicitly popped by the @code{asm}, and
11018which must be explicitly popped by GCC@.
11019
11020An input register that is implicitly popped by the @code{asm} must be
11021explicitly clobbered, unless it is constrained to match an
11022output operand.
11023
11024@item
11025For any input register that is implicitly popped by an @code{asm}, it is
11026necessary to know how to adjust the stack to compensate for the pop.
11027If any non-popped input is closer to the top of the reg-stack than
11028the implicitly popped register, it would not be possible to know what the
11029stack looked like---it's not clear how the rest of the stack ``slides
11030up''.
11031
11032All implicitly popped input registers must be closer to the top of
11033the reg-stack than any input that is not implicitly popped.
11034
11035It is possible that if an input dies in an @code{asm}, the compiler might
11036use the input register for an output reload.  Consider this example:
11037
11038@smallexample
11039asm ("foo" : "=t" (a) : "f" (b));
11040@end smallexample
11041
11042@noindent
11043This code says that input @code{b} is not popped by the @code{asm}, and that
11044the @code{asm} pushes a result onto the reg-stack, i.e., the stack is one
11045deeper after the @code{asm} than it was before.  But, it is possible that
11046reload may think that it can use the same register for both the input and
11047the output.
11048
11049To prevent this from happening,
11050if any input operand uses the @samp{f} constraint, all output register
11051constraints must use the @samp{&} early-clobber modifier.
11052
11053The example above is correctly written as:
11054
11055@smallexample
11056asm ("foo" : "=&t" (a) : "f" (b));
11057@end smallexample
11058
11059@item
11060Some operands need to be in particular places on the stack.  All
11061output operands fall in this category---GCC has no other way to
11062know which registers the outputs appear in unless you indicate
11063this in the constraints.
11064
11065Output operands must specifically indicate which register an output
11066appears in after an @code{asm}.  @samp{=f} is not allowed: the operand
11067constraints must select a class with a single register.
11068
11069@item
11070Output operands may not be ``inserted'' between existing stack registers.
11071Since no 387 opcode uses a read/write operand, all output operands
11072are dead before the @code{asm}, and are pushed by the @code{asm}.
11073It makes no sense to push anywhere but the top of the reg-stack.
11074
11075Output operands must start at the top of the reg-stack: output
11076operands may not ``skip'' a register.
11077
11078@item
11079Some @code{asm} statements may need extra stack space for internal
11080calculations.  This can be guaranteed by clobbering stack registers
11081unrelated to the inputs and outputs.
11082
11083@end enumerate
11084
11085This @code{asm}
11086takes one input, which is internally popped, and produces two outputs.
11087
11088@smallexample
11089asm ("fsincos" : "=t" (cos), "=u" (sin) : "0" (inp));
11090@end smallexample
11091
11092@noindent
11093This @code{asm} takes two inputs, which are popped by the @code{fyl2xp1} opcode,
11094and replaces them with one output.  The @code{st(1)} clobber is necessary
11095for the compiler to know that @code{fyl2xp1} pops both inputs.
11096
11097@smallexample
11098asm ("fyl2xp1" : "=t" (result) : "0" (x), "u" (y) : "st(1)");
11099@end smallexample
11100
11101@anchor{msp430Operandmodifiers}
11102@subsubsection MSP430 Operand Modifiers
11103
11104The list below describes the supported modifiers and their effects for MSP430.
11105
11106@multitable @columnfractions .10 .90
11107@headitem Modifier @tab Description
11108@item @code{A} @tab Select low 16-bits of the constant/register/memory operand.
11109@item @code{B} @tab Select high 16-bits of the constant/register/memory
11110operand.
11111@item @code{C} @tab Select bits 32-47 of the constant/register/memory operand.
11112@item @code{D} @tab Select bits 48-63 of the constant/register/memory operand.
11113@item @code{H} @tab Equivalent to @code{B} (for backwards compatibility).
11114@item @code{I} @tab Print the inverse (logical @code{NOT}) of the constant
11115value.
11116@item @code{J} @tab Print an integer without a @code{#} prefix.
11117@item @code{L} @tab Equivalent to @code{A} (for backwards compatibility).
11118@item @code{O} @tab Offset of the current frame from the top of the stack.
11119@item @code{Q} @tab Use the @code{A} instruction postfix.
11120@item @code{R} @tab Inverse of condition code, for unsigned comparisons.
11121@item @code{W} @tab Subtract 16 from the constant value.
11122@item @code{X} @tab Use the @code{X} instruction postfix.
11123@item @code{Y} @tab Subtract 4 from the constant value.
11124@item @code{Z} @tab Subtract 1 from the constant value.
11125@item @code{b} @tab Append @code{.B}, @code{.W} or @code{.A} to the
11126instruction, depending on the mode.
11127@item @code{d} @tab Offset 1 byte of a memory reference or constant value.
11128@item @code{e} @tab Offset 3 bytes of a memory reference or constant value.
11129@item @code{f} @tab Offset 5 bytes of a memory reference or constant value.
11130@item @code{g} @tab Offset 7 bytes of a memory reference or constant value.
11131@item @code{p} @tab Print the value of 2, raised to the power of the given
11132constant.  Used to select the specified bit position.
11133@item @code{r} @tab Inverse of condition code, for signed comparisons.
11134@item @code{x} @tab Equivialent to @code{X}, but only for pointers.
11135@end multitable
11136
11137@lowersections
11138@include md.texi
11139@raisesections
11140
11141@node Asm Labels
11142@subsection Controlling Names Used in Assembler Code
11143@cindex assembler names for identifiers
11144@cindex names used in assembler code
11145@cindex identifiers, names in assembler code
11146
11147You can specify the name to be used in the assembler code for a C
11148function or variable by writing the @code{asm} (or @code{__asm__})
11149keyword after the declarator.
11150It is up to you to make sure that the assembler names you choose do not
11151conflict with any other assembler symbols, or reference registers.
11152
11153@subsubheading Assembler names for data:
11154
11155This sample shows how to specify the assembler name for data:
11156
11157@smallexample
11158int foo asm ("myfoo") = 2;
11159@end smallexample
11160
11161@noindent
11162This specifies that the name to be used for the variable @code{foo} in
11163the assembler code should be @samp{myfoo} rather than the usual
11164@samp{_foo}.
11165
11166On systems where an underscore is normally prepended to the name of a C
11167variable, this feature allows you to define names for the
11168linker that do not start with an underscore.
11169
11170GCC does not support using this feature with a non-static local variable
11171since such variables do not have assembler names.  If you are
11172trying to put the variable in a particular register, see
11173@ref{Explicit Register Variables}.
11174
11175@subsubheading Assembler names for functions:
11176
11177To specify the assembler name for functions, write a declaration for the
11178function before its definition and put @code{asm} there, like this:
11179
11180@smallexample
11181int func (int x, int y) asm ("MYFUNC");
11182
11183int func (int x, int y)
11184@{
11185   /* @r{@dots{}} */
11186@end smallexample
11187
11188@noindent
11189This specifies that the name to be used for the function @code{func} in
11190the assembler code should be @code{MYFUNC}.
11191
11192@node Explicit Register Variables
11193@subsection Variables in Specified Registers
11194@anchor{Explicit Reg Vars}
11195@cindex explicit register variables
11196@cindex variables in specified registers
11197@cindex specified registers
11198
11199GNU C allows you to associate specific hardware registers with C
11200variables.  In almost all cases, allowing the compiler to assign
11201registers produces the best code.  However under certain unusual
11202circumstances, more precise control over the variable storage is
11203required.
11204
11205Both global and local variables can be associated with a register.  The
11206consequences of performing this association are very different between
11207the two, as explained in the sections below.
11208
11209@menu
11210* Global Register Variables::   Variables declared at global scope.
11211* Local Register Variables::    Variables declared within a function.
11212@end menu
11213
11214@node Global Register Variables
11215@subsubsection Defining Global Register Variables
11216@anchor{Global Reg Vars}
11217@cindex global register variables
11218@cindex registers, global variables in
11219@cindex registers, global allocation
11220
11221You can define a global register variable and associate it with a specified
11222register like this:
11223
11224@smallexample
11225register int *foo asm ("r12");
11226@end smallexample
11227
11228@noindent
11229Here @code{r12} is the name of the register that should be used. Note that
11230this is the same syntax used for defining local register variables, but for
11231a global variable the declaration appears outside a function. The
11232@code{register} keyword is required, and cannot be combined with
11233@code{static}. The register name must be a valid register name for the
11234target platform.
11235
11236Do not use type qualifiers such as @code{const} and @code{volatile}, as
11237the outcome may be contrary to expectations.  In  particular, using the
11238@code{volatile} qualifier does not fully prevent the compiler from
11239optimizing accesses to the register.
11240
11241Registers are a scarce resource on most systems and allowing the
11242compiler to manage their usage usually results in the best code. However,
11243under special circumstances it can make sense to reserve some globally.
11244For example this may be useful in programs such as programming language
11245interpreters that have a couple of global variables that are accessed
11246very often.
11247
11248After defining a global register variable, for the current compilation
11249unit:
11250
11251@itemize @bullet
11252@item If the register is a call-saved register, call ABI is affected:
11253the register will not be restored in function epilogue sequences after
11254the variable has been assigned.  Therefore, functions cannot safely
11255return to callers that assume standard ABI.
11256@item Conversely, if the register is a call-clobbered register, making
11257calls to functions that use standard ABI may lose contents of the variable.
11258Such calls may be created by the compiler even if none are evident in
11259the original program, for example when libgcc functions are used to
11260make up for unavailable instructions.
11261@item Accesses to the variable may be optimized as usual and the register
11262remains available for allocation and use in any computations, provided that
11263observable values of the variable are not affected.
11264@item If the variable is referenced in inline assembly, the type of access
11265must be provided to the compiler via constraints (@pxref{Constraints}).
11266Accesses from basic asms are not supported.
11267@end itemize
11268
11269Note that these points @emph{only} apply to code that is compiled with the
11270definition. The behavior of code that is merely linked in (for example
11271code from libraries) is not affected.
11272
11273If you want to recompile source files that do not actually use your global
11274register variable so they do not use the specified register for any other
11275purpose, you need not actually add the global register declaration to
11276their source code. It suffices to specify the compiler option
11277@option{-ffixed-@var{reg}} (@pxref{Code Gen Options}) to reserve the
11278register.
11279
11280@subsubheading Declaring the variable
11281
11282Global register variables cannot have initial values, because an
11283executable file has no means to supply initial contents for a register.
11284
11285When selecting a register, choose one that is normally saved and
11286restored by function calls on your machine. This ensures that code
11287which is unaware of this reservation (such as library routines) will
11288restore it before returning.
11289
11290On machines with register windows, be sure to choose a global
11291register that is not affected magically by the function call mechanism.
11292
11293@subsubheading Using the variable
11294
11295@cindex @code{qsort}, and global register variables
11296When calling routines that are not aware of the reservation, be
11297cautious if those routines call back into code which uses them. As an
11298example, if you call the system library version of @code{qsort}, it may
11299clobber your registers during execution, but (if you have selected
11300appropriate registers) it will restore them before returning. However
11301it will @emph{not} restore them before calling @code{qsort}'s comparison
11302function. As a result, global values will not reliably be available to
11303the comparison function unless the @code{qsort} function itself is rebuilt.
11304
11305Similarly, it is not safe to access the global register variables from signal
11306handlers or from more than one thread of control. Unless you recompile
11307them specially for the task at hand, the system library routines may
11308temporarily use the register for other things.  Furthermore, since the register
11309is not reserved exclusively for the variable, accessing it from handlers of
11310asynchronous signals may observe unrelated temporary values residing in the
11311register.
11312
11313@cindex register variable after @code{longjmp}
11314@cindex global register after @code{longjmp}
11315@cindex value after @code{longjmp}
11316@findex longjmp
11317@findex setjmp
11318On most machines, @code{longjmp} restores to each global register
11319variable the value it had at the time of the @code{setjmp}. On some
11320machines, however, @code{longjmp} does not change the value of global
11321register variables. To be portable, the function that called @code{setjmp}
11322should make other arrangements to save the values of the global register
11323variables, and to restore them in a @code{longjmp}. This way, the same
11324thing happens regardless of what @code{longjmp} does.
11325
11326@node Local Register Variables
11327@subsubsection Specifying Registers for Local Variables
11328@anchor{Local Reg Vars}
11329@cindex local variables, specifying registers
11330@cindex specifying registers for local variables
11331@cindex registers for local variables
11332
11333You can define a local register variable and associate it with a specified
11334register like this:
11335
11336@smallexample
11337register int *foo asm ("r12");
11338@end smallexample
11339
11340@noindent
11341Here @code{r12} is the name of the register that should be used.  Note
11342that this is the same syntax used for defining global register variables,
11343but for a local variable the declaration appears within a function.  The
11344@code{register} keyword is required, and cannot be combined with
11345@code{static}.  The register name must be a valid register name for the
11346target platform.
11347
11348Do not use type qualifiers such as @code{const} and @code{volatile}, as
11349the outcome may be contrary to expectations. In particular, when the
11350@code{const} qualifier is used, the compiler may substitute the
11351variable with its initializer in @code{asm} statements, which may cause
11352the corresponding operand to appear in a different register.
11353
11354As with global register variables, it is recommended that you choose
11355a register that is normally saved and restored by function calls on your
11356machine, so that calls to library routines will not clobber it.
11357
11358The only supported use for this feature is to specify registers
11359for input and output operands when calling Extended @code{asm}
11360(@pxref{Extended Asm}).  This may be necessary if the constraints for a
11361particular machine don't provide sufficient control to select the desired
11362register.  To force an operand into a register, create a local variable
11363and specify the register name after the variable's declaration.  Then use
11364the local variable for the @code{asm} operand and specify any constraint
11365letter that matches the register:
11366
11367@smallexample
11368register int *p1 asm ("r0") = @dots{};
11369register int *p2 asm ("r1") = @dots{};
11370register int *result asm ("r0");
11371asm ("sysint" : "=r" (result) : "0" (p1), "r" (p2));
11372@end smallexample
11373
11374@emph{Warning:} In the above example, be aware that a register (for example
11375@code{r0}) can be call-clobbered by subsequent code, including function
11376calls and library calls for arithmetic operators on other variables (for
11377example the initialization of @code{p2}).  In this case, use temporary
11378variables for expressions between the register assignments:
11379
11380@smallexample
11381int t1 = @dots{};
11382register int *p1 asm ("r0") = @dots{};
11383register int *p2 asm ("r1") = t1;
11384register int *result asm ("r0");
11385asm ("sysint" : "=r" (result) : "0" (p1), "r" (p2));
11386@end smallexample
11387
11388Defining a register variable does not reserve the register.  Other than
11389when invoking the Extended @code{asm}, the contents of the specified
11390register are not guaranteed.  For this reason, the following uses
11391are explicitly @emph{not} supported.  If they appear to work, it is only
11392happenstance, and may stop working as intended due to (seemingly)
11393unrelated changes in surrounding code, or even minor changes in the
11394optimization of a future version of gcc:
11395
11396@itemize @bullet
11397@item Passing parameters to or from Basic @code{asm}
11398@item Passing parameters to or from Extended @code{asm} without using input
11399or output operands.
11400@item Passing parameters to or from routines written in assembler (or
11401other languages) using non-standard calling conventions.
11402@end itemize
11403
11404Some developers use Local Register Variables in an attempt to improve
11405gcc's allocation of registers, especially in large functions.  In this
11406case the register name is essentially a hint to the register allocator.
11407While in some instances this can generate better code, improvements are
11408subject to the whims of the allocator/optimizers.  Since there are no
11409guarantees that your improvements won't be lost, this usage of Local
11410Register Variables is discouraged.
11411
11412On the MIPS platform, there is related use for local register variables
11413with slightly different characteristics (@pxref{MIPS Coprocessors,,
11414Defining coprocessor specifics for MIPS targets, gccint,
11415GNU Compiler Collection (GCC) Internals}).
11416
11417@node Size of an asm
11418@subsection Size of an @code{asm}
11419
11420Some targets require that GCC track the size of each instruction used
11421in order to generate correct code.  Because the final length of the
11422code produced by an @code{asm} statement is only known by the
11423assembler, GCC must make an estimate as to how big it will be.  It
11424does this by counting the number of instructions in the pattern of the
11425@code{asm} and multiplying that by the length of the longest
11426instruction supported by that processor.  (When working out the number
11427of instructions, it assumes that any occurrence of a newline or of
11428whatever statement separator character is supported by the assembler ---
11429typically @samp{;} --- indicates the end of an instruction.)
11430
11431Normally, GCC's estimate is adequate to ensure that correct
11432code is generated, but it is possible to confuse the compiler if you use
11433pseudo instructions or assembler macros that expand into multiple real
11434instructions, or if you use assembler directives that expand to more
11435space in the object file than is needed for a single instruction.
11436If this happens then the assembler may produce a diagnostic saying that
11437a label is unreachable.
11438
11439@cindex @code{asm inline}
11440This size is also used for inlining decisions.  If you use @code{asm inline}
11441instead of just @code{asm}, then for inlining purposes the size of the asm
11442is taken as the minimum size, ignoring how many instructions GCC thinks it is.
11443
11444@node Alternate Keywords
11445@section Alternate Keywords
11446@cindex alternate keywords
11447@cindex keywords, alternate
11448
11449@option{-ansi} and the various @option{-std} options disable certain
11450keywords.  This causes trouble when you want to use GNU C extensions, or
11451a general-purpose header file that should be usable by all programs,
11452including ISO C programs.  The keywords @code{asm}, @code{typeof} and
11453@code{inline} are not available in programs compiled with
11454@option{-ansi} or @option{-std} (although @code{inline} can be used in a
11455program compiled with @option{-std=c99} or a later standard).  The
11456ISO C99 keyword
11457@code{restrict} is only available when @option{-std=gnu99} (which will
11458eventually be the default) or @option{-std=c99} (or the equivalent
11459@option{-std=iso9899:1999}), or an option for a later standard
11460version, is used.
11461
11462The way to solve these problems is to put @samp{__} at the beginning and
11463end of each problematical keyword.  For example, use @code{__asm__}
11464instead of @code{asm}, and @code{__inline__} instead of @code{inline}.
11465
11466Other C compilers won't accept these alternative keywords; if you want to
11467compile with another compiler, you can define the alternate keywords as
11468macros to replace them with the customary keywords.  It looks like this:
11469
11470@smallexample
11471#ifndef __GNUC__
11472#define __asm__ asm
11473#endif
11474@end smallexample
11475
11476@findex __extension__
11477@opindex pedantic
11478@option{-pedantic} and other options cause warnings for many GNU C extensions.
11479You can
11480prevent such warnings within one expression by writing
11481@code{__extension__} before the expression.  @code{__extension__} has no
11482effect aside from this.
11483
11484@node Incomplete Enums
11485@section Incomplete @code{enum} Types
11486
11487You can define an @code{enum} tag without specifying its possible values.
11488This results in an incomplete type, much like what you get if you write
11489@code{struct foo} without describing the elements.  A later declaration
11490that does specify the possible values completes the type.
11491
11492You cannot allocate variables or storage using the type while it is
11493incomplete.  However, you can work with pointers to that type.
11494
11495This extension may not be very useful, but it makes the handling of
11496@code{enum} more consistent with the way @code{struct} and @code{union}
11497are handled.
11498
11499This extension is not supported by GNU C++.
11500
11501@node Function Names
11502@section Function Names as Strings
11503@cindex @code{__func__} identifier
11504@cindex @code{__FUNCTION__} identifier
11505@cindex @code{__PRETTY_FUNCTION__} identifier
11506
11507GCC provides three magic constants that hold the name of the current
11508function as a string.  In C++11 and later modes, all three are treated
11509as constant expressions and can be used in @code{constexpr} constexts.
11510The first of these constants is @code{__func__}, which is part of
11511the C99 standard:
11512
11513The identifier @code{__func__} is implicitly declared by the translator
11514as if, immediately following the opening brace of each function
11515definition, the declaration
11516
11517@smallexample
11518static const char __func__[] = "function-name";
11519@end smallexample
11520
11521@noindent
11522appeared, where function-name is the name of the lexically-enclosing
11523function.  This name is the unadorned name of the function.  As an
11524extension, at file (or, in C++, namespace scope), @code{__func__}
11525evaluates to the empty string.
11526
11527@code{__FUNCTION__} is another name for @code{__func__}, provided for
11528backward compatibility with old versions of GCC.
11529
11530In C, @code{__PRETTY_FUNCTION__} is yet another name for
11531@code{__func__}, except that at file scope (or, in C++, namespace scope),
11532it evaluates to the string @code{"top level"}.  In addition, in C++,
11533@code{__PRETTY_FUNCTION__} contains the signature of the function as
11534well as its bare name.  For example, this program:
11535
11536@smallexample
11537extern "C" int printf (const char *, ...);
11538
11539class a @{
11540 public:
11541  void sub (int i)
11542    @{
11543      printf ("__FUNCTION__ = %s\n", __FUNCTION__);
11544      printf ("__PRETTY_FUNCTION__ = %s\n", __PRETTY_FUNCTION__);
11545    @}
11546@};
11547
11548int
11549main (void)
11550@{
11551  a ax;
11552  ax.sub (0);
11553  return 0;
11554@}
11555@end smallexample
11556
11557@noindent
11558gives this output:
11559
11560@smallexample
11561__FUNCTION__ = sub
11562__PRETTY_FUNCTION__ = void a::sub(int)
11563@end smallexample
11564
11565These identifiers are variables, not preprocessor macros, and may not
11566be used to initialize @code{char} arrays or be concatenated with string
11567literals.
11568
11569@node Return Address
11570@section Getting the Return or Frame Address of a Function
11571
11572These functions may be used to get information about the callers of a
11573function.
11574
11575@deftypefn {Built-in Function} {void *} __builtin_return_address (unsigned int @var{level})
11576This function returns the return address of the current function, or of
11577one of its callers.  The @var{level} argument is number of frames to
11578scan up the call stack.  A value of @code{0} yields the return address
11579of the current function, a value of @code{1} yields the return address
11580of the caller of the current function, and so forth.  When inlining
11581the expected behavior is that the function returns the address of
11582the function that is returned to.  To work around this behavior use
11583the @code{noinline} function attribute.
11584
11585The @var{level} argument must be a constant integer.
11586
11587On some machines it may be impossible to determine the return address of
11588any function other than the current one; in such cases, or when the top
11589of the stack has been reached, this function returns an unspecified
11590value.  In addition, @code{__builtin_frame_address} may be used
11591to determine if the top of the stack has been reached.
11592
11593Additional post-processing of the returned value may be needed, see
11594@code{__builtin_extract_return_addr}.
11595
11596The stored representation of the return address in memory may be different
11597from the address returned by @code{__builtin_return_address}.  For example,
11598on AArch64 the stored address may be mangled with return address signing
11599whereas the address returned by @code{__builtin_return_address} is not.
11600
11601Calling this function with a nonzero argument can have unpredictable
11602effects, including crashing the calling program.  As a result, calls
11603that are considered unsafe are diagnosed when the @option{-Wframe-address}
11604option is in effect.  Such calls should only be made in debugging
11605situations.
11606
11607On targets where code addresses are representable as @code{void *},
11608@smallexample
11609void *addr = __builtin_extract_return_addr (__builtin_return_address (0));
11610@end smallexample
11611gives the code address where the current function would return.  For example,
11612such an address may be used with @code{dladdr} or other interfaces that work
11613with code addresses.
11614@end deftypefn
11615
11616@deftypefn {Built-in Function} {void *} __builtin_extract_return_addr (void *@var{addr})
11617The address as returned by @code{__builtin_return_address} may have to be fed
11618through this function to get the actual encoded address.  For example, on the
1161931-bit S/390 platform the highest bit has to be masked out, or on SPARC
11620platforms an offset has to be added for the true next instruction to be
11621executed.
11622
11623If no fixup is needed, this function simply passes through @var{addr}.
11624@end deftypefn
11625
11626@deftypefn {Built-in Function} {void *} __builtin_frob_return_addr (void *@var{addr})
11627This function does the reverse of @code{__builtin_extract_return_addr}.
11628@end deftypefn
11629
11630@deftypefn {Built-in Function} {void *} __builtin_frame_address (unsigned int @var{level})
11631This function is similar to @code{__builtin_return_address}, but it
11632returns the address of the function frame rather than the return address
11633of the function.  Calling @code{__builtin_frame_address} with a value of
11634@code{0} yields the frame address of the current function, a value of
11635@code{1} yields the frame address of the caller of the current function,
11636and so forth.
11637
11638The frame is the area on the stack that holds local variables and saved
11639registers.  The frame address is normally the address of the first word
11640pushed on to the stack by the function.  However, the exact definition
11641depends upon the processor and the calling convention.  If the processor
11642has a dedicated frame pointer register, and the function has a frame,
11643then @code{__builtin_frame_address} returns the value of the frame
11644pointer register.
11645
11646On some machines it may be impossible to determine the frame address of
11647any function other than the current one; in such cases, or when the top
11648of the stack has been reached, this function returns @code{0} if
11649the first frame pointer is properly initialized by the startup code.
11650
11651Calling this function with a nonzero argument can have unpredictable
11652effects, including crashing the calling program.  As a result, calls
11653that are considered unsafe are diagnosed when the @option{-Wframe-address}
11654option is in effect.  Such calls should only be made in debugging
11655situations.
11656@end deftypefn
11657
11658@node Vector Extensions
11659@section Using Vector Instructions through Built-in Functions
11660
11661On some targets, the instruction set contains SIMD vector instructions which
11662operate on multiple values contained in one large register at the same time.
11663For example, on the x86 the MMX, 3DNow!@: and SSE extensions can be used
11664this way.
11665
11666The first step in using these extensions is to provide the necessary data
11667types.  This should be done using an appropriate @code{typedef}:
11668
11669@smallexample
11670typedef int v4si __attribute__ ((vector_size (16)));
11671@end smallexample
11672
11673@noindent
11674The @code{int} type specifies the @dfn{base type}, while the attribute specifies
11675the vector size for the variable, measured in bytes.  For example, the
11676declaration above causes the compiler to set the mode for the @code{v4si}
11677type to be 16 bytes wide and divided into @code{int} sized units.  For
11678a 32-bit @code{int} this means a vector of 4 units of 4 bytes, and the
11679corresponding mode of @code{foo} is @acronym{V4SI}.
11680
11681The @code{vector_size} attribute is only applicable to integral and
11682floating scalars, although arrays, pointers, and function return values
11683are allowed in conjunction with this construct. Only sizes that are
11684positive power-of-two multiples of the base type size are currently allowed.
11685
11686All the basic integer types can be used as base types, both as signed
11687and as unsigned: @code{char}, @code{short}, @code{int}, @code{long},
11688@code{long long}.  In addition, @code{float} and @code{double} can be
11689used to build floating-point vector types.
11690
11691Specifying a combination that is not valid for the current architecture
11692causes GCC to synthesize the instructions using a narrower mode.
11693For example, if you specify a variable of type @code{V4SI} and your
11694architecture does not allow for this specific SIMD type, GCC
11695produces code that uses 4 @code{SIs}.
11696
11697The types defined in this manner can be used with a subset of normal C
11698operations.  Currently, GCC allows using the following operators
11699on these types: @code{+, -, *, /, unary minus, ^, |, &, ~, %}@.
11700
11701The operations behave like C++ @code{valarrays}.  Addition is defined as
11702the addition of the corresponding elements of the operands.  For
11703example, in the code below, each of the 4 elements in @var{a} is
11704added to the corresponding 4 elements in @var{b} and the resulting
11705vector is stored in @var{c}.
11706
11707@smallexample
11708typedef int v4si __attribute__ ((vector_size (16)));
11709
11710v4si a, b, c;
11711
11712c = a + b;
11713@end smallexample
11714
11715Subtraction, multiplication, division, and the logical operations
11716operate in a similar manner.  Likewise, the result of using the unary
11717minus or complement operators on a vector type is a vector whose
11718elements are the negative or complemented values of the corresponding
11719elements in the operand.
11720
11721It is possible to use shifting operators @code{<<}, @code{>>} on
11722integer-type vectors. The operation is defined as following: @code{@{a0,
11723a1, @dots{}, an@} >> @{b0, b1, @dots{}, bn@} == @{a0 >> b0, a1 >> b1,
11724@dots{}, an >> bn@}}@. Vector operands must have the same number of
11725elements.
11726
11727For convenience, it is allowed to use a binary vector operation
11728where one operand is a scalar. In that case the compiler transforms
11729the scalar operand into a vector where each element is the scalar from
11730the operation. The transformation happens only if the scalar could be
11731safely converted to the vector-element type.
11732Consider the following code.
11733
11734@smallexample
11735typedef int v4si __attribute__ ((vector_size (16)));
11736
11737v4si a, b, c;
11738long l;
11739
11740a = b + 1;    /* a = b + @{1,1,1,1@}; */
11741a = 2 * b;    /* a = @{2,2,2,2@} * b; */
11742
11743a = l + a;    /* Error, cannot convert long to int. */
11744@end smallexample
11745
11746Vectors can be subscripted as if the vector were an array with
11747the same number of elements and base type.  Out of bound accesses
11748invoke undefined behavior at run time.  Warnings for out of bound
11749accesses for vector subscription can be enabled with
11750@option{-Warray-bounds}.
11751
11752Vector comparison is supported with standard comparison
11753operators: @code{==, !=, <, <=, >, >=}. Comparison operands can be
11754vector expressions of integer-type or real-type. Comparison between
11755integer-type vectors and real-type vectors are not supported.  The
11756result of the comparison is a vector of the same width and number of
11757elements as the comparison operands with a signed integral element
11758type.
11759
11760Vectors are compared element-wise producing 0 when comparison is false
11761and -1 (constant of the appropriate type where all bits are set)
11762otherwise. Consider the following example.
11763
11764@smallexample
11765typedef int v4si __attribute__ ((vector_size (16)));
11766
11767v4si a = @{1,2,3,4@};
11768v4si b = @{3,2,1,4@};
11769v4si c;
11770
11771c = a >  b;     /* The result would be @{0, 0,-1, 0@}  */
11772c = a == b;     /* The result would be @{0,-1, 0,-1@}  */
11773@end smallexample
11774
11775In C++, the ternary operator @code{?:} is available. @code{a?b:c}, where
11776@code{b} and @code{c} are vectors of the same type and @code{a} is an
11777integer vector with the same number of elements of the same size as @code{b}
11778and @code{c}, computes all three arguments and creates a vector
11779@code{@{a[0]?b[0]:c[0], a[1]?b[1]:c[1], @dots{}@}}.  Note that unlike in
11780OpenCL, @code{a} is thus interpreted as @code{a != 0} and not @code{a < 0}.
11781As in the case of binary operations, this syntax is also accepted when
11782one of @code{b} or @code{c} is a scalar that is then transformed into a
11783vector. If both @code{b} and @code{c} are scalars and the type of
11784@code{true?b:c} has the same size as the element type of @code{a}, then
11785@code{b} and @code{c} are converted to a vector type whose elements have
11786this type and with the same number of elements as @code{a}.
11787
11788In C++, the logic operators @code{!, &&, ||} are available for vectors.
11789@code{!v} is equivalent to @code{v == 0}, @code{a && b} is equivalent to
11790@code{a!=0 & b!=0} and @code{a || b} is equivalent to @code{a!=0 | b!=0}.
11791For mixed operations between a scalar @code{s} and a vector @code{v},
11792@code{s && v} is equivalent to @code{s?v!=0:0} (the evaluation is
11793short-circuit) and @code{v && s} is equivalent to @code{v!=0 & (s?-1:0)}.
11794
11795@findex __builtin_shuffle
11796Vector shuffling is available using functions
11797@code{__builtin_shuffle (vec, mask)} and
11798@code{__builtin_shuffle (vec0, vec1, mask)}.
11799Both functions construct a permutation of elements from one or two
11800vectors and return a vector of the same type as the input vector(s).
11801The @var{mask} is an integral vector with the same width (@var{W})
11802and element count (@var{N}) as the output vector.
11803
11804The elements of the input vectors are numbered in memory ordering of
11805@var{vec0} beginning at 0 and @var{vec1} beginning at @var{N}.  The
11806elements of @var{mask} are considered modulo @var{N} in the single-operand
11807case and modulo @math{2*@var{N}} in the two-operand case.
11808
11809Consider the following example,
11810
11811@smallexample
11812typedef int v4si __attribute__ ((vector_size (16)));
11813
11814v4si a = @{1,2,3,4@};
11815v4si b = @{5,6,7,8@};
11816v4si mask1 = @{0,1,1,3@};
11817v4si mask2 = @{0,4,2,5@};
11818v4si res;
11819
11820res = __builtin_shuffle (a, mask1);       /* res is @{1,2,2,4@}  */
11821res = __builtin_shuffle (a, b, mask2);    /* res is @{1,5,3,6@}  */
11822@end smallexample
11823
11824Note that @code{__builtin_shuffle} is intentionally semantically
11825compatible with the OpenCL @code{shuffle} and @code{shuffle2} functions.
11826
11827You can declare variables and use them in function calls and returns, as
11828well as in assignments and some casts.  You can specify a vector type as
11829a return type for a function.  Vector types can also be used as function
11830arguments.  It is possible to cast from one vector type to another,
11831provided they are of the same size (in fact, you can also cast vectors
11832to and from other datatypes of the same size).
11833
11834You cannot operate between vectors of different lengths or different
11835signedness without a cast.
11836
11837@findex __builtin_convertvector
11838Vector conversion is available using the
11839@code{__builtin_convertvector (vec, vectype)}
11840function.  @var{vec} must be an expression with integral or floating
11841vector type and @var{vectype} an integral or floating vector type with the
11842same number of elements.  The result has @var{vectype} type and value of
11843a C cast of every element of @var{vec} to the element type of @var{vectype}.
11844
11845Consider the following example,
11846@smallexample
11847typedef int v4si __attribute__ ((vector_size (16)));
11848typedef float v4sf __attribute__ ((vector_size (16)));
11849typedef double v4df __attribute__ ((vector_size (32)));
11850typedef unsigned long long v4di __attribute__ ((vector_size (32)));
11851
11852v4si a = @{1,-2,3,-4@};
11853v4sf b = @{1.5f,-2.5f,3.f,7.f@};
11854v4di c = @{1ULL,5ULL,0ULL,10ULL@};
11855v4sf d = __builtin_convertvector (a, v4sf); /* d is @{1.f,-2.f,3.f,-4.f@} */
11856/* Equivalent of:
11857   v4sf d = @{ (float)a[0], (float)a[1], (float)a[2], (float)a[3] @}; */
11858v4df e = __builtin_convertvector (a, v4df); /* e is @{1.,-2.,3.,-4.@} */
11859v4df f = __builtin_convertvector (b, v4df); /* f is @{1.5,-2.5,3.,7.@} */
11860v4si g = __builtin_convertvector (f, v4si); /* g is @{1,-2,3,7@} */
11861v4si h = __builtin_convertvector (c, v4si); /* h is @{1,5,0,10@} */
11862@end smallexample
11863
11864@cindex vector types, using with x86 intrinsics
11865Sometimes it is desirable to write code using a mix of generic vector
11866operations (for clarity) and machine-specific vector intrinsics (to
11867access vector instructions that are not exposed via generic built-ins).
11868On x86, intrinsic functions for integer vectors typically use the same
11869vector type @code{__m128i} irrespective of how they interpret the vector,
11870making it necessary to cast their arguments and return values from/to
11871other vector types.  In C, you can make use of a @code{union} type:
11872@c In C++ such type punning via a union is not allowed by the language
11873@smallexample
11874#include <immintrin.h>
11875
11876typedef unsigned char u8x16 __attribute__ ((vector_size (16)));
11877typedef unsigned int  u32x4 __attribute__ ((vector_size (16)));
11878
11879typedef union @{
11880        __m128i mm;
11881        u8x16   u8;
11882        u32x4   u32;
11883@} v128;
11884@end smallexample
11885
11886@noindent
11887for variables that can be used with both built-in operators and x86
11888intrinsics:
11889
11890@smallexample
11891v128 x, y = @{ 0 @};
11892memcpy (&x, ptr, sizeof x);
11893y.u8  += 0x80;
11894x.mm  = _mm_adds_epu8 (x.mm, y.mm);
11895x.u32 &= 0xffffff;
11896
11897/* Instead of a variable, a compound literal may be used to pass the
11898   return value of an intrinsic call to a function expecting the union: */
11899v128 foo (v128);
11900x = foo ((v128) @{_mm_adds_epu8 (x.mm, y.mm)@});
11901@c This could be done implicitly with __attribute__((transparent_union)),
11902@c but GCC does not accept it for unions of vector types (PR 88955).
11903@end smallexample
11904
11905@node Offsetof
11906@section Support for @code{offsetof}
11907@findex __builtin_offsetof
11908
11909GCC implements for both C and C++ a syntactic extension to implement
11910the @code{offsetof} macro.
11911
11912@smallexample
11913primary:
11914        "__builtin_offsetof" "(" @code{typename} "," offsetof_member_designator ")"
11915
11916offsetof_member_designator:
11917          @code{identifier}
11918        | offsetof_member_designator "." @code{identifier}
11919        | offsetof_member_designator "[" @code{expr} "]"
11920@end smallexample
11921
11922This extension is sufficient such that
11923
11924@smallexample
11925#define offsetof(@var{type}, @var{member})  __builtin_offsetof (@var{type}, @var{member})
11926@end smallexample
11927
11928@noindent
11929is a suitable definition of the @code{offsetof} macro.  In C++, @var{type}
11930may be dependent.  In either case, @var{member} may consist of a single
11931identifier, or a sequence of member accesses and array references.
11932
11933@node __sync Builtins
11934@section Legacy @code{__sync} Built-in Functions for Atomic Memory Access
11935
11936The following built-in functions
11937are intended to be compatible with those described
11938in the @cite{Intel Itanium Processor-specific Application Binary Interface},
11939section 7.4.  As such, they depart from normal GCC practice by not using
11940the @samp{__builtin_} prefix and also by being overloaded so that they
11941work on multiple types.
11942
11943The definition given in the Intel documentation allows only for the use of
11944the types @code{int}, @code{long}, @code{long long} or their unsigned
11945counterparts.  GCC allows any scalar type that is 1, 2, 4 or 8 bytes in
11946size other than the C type @code{_Bool} or the C++ type @code{bool}.
11947Operations on pointer arguments are performed as if the operands were
11948of the @code{uintptr_t} type.  That is, they are not scaled by the size
11949of the type to which the pointer points.
11950
11951These functions are implemented in terms of the @samp{__atomic}
11952builtins (@pxref{__atomic Builtins}).  They should not be used for new
11953code which should use the @samp{__atomic} builtins instead.
11954
11955Not all operations are supported by all target processors.  If a particular
11956operation cannot be implemented on the target processor, a warning is
11957generated and a call to an external function is generated.  The external
11958function carries the same name as the built-in version,
11959with an additional suffix
11960@samp{_@var{n}} where @var{n} is the size of the data type.
11961
11962@c ??? Should we have a mechanism to suppress this warning?  This is almost
11963@c useful for implementing the operation under the control of an external
11964@c mutex.
11965
11966In most cases, these built-in functions are considered a @dfn{full barrier}.
11967That is,
11968no memory operand is moved across the operation, either forward or
11969backward.  Further, instructions are issued as necessary to prevent the
11970processor from speculating loads across the operation and from queuing stores
11971after the operation.
11972
11973All of the routines are described in the Intel documentation to take
11974``an optional list of variables protected by the memory barrier''.  It's
11975not clear what is meant by that; it could mean that @emph{only} the
11976listed variables are protected, or it could mean a list of additional
11977variables to be protected.  The list is ignored by GCC which treats it as
11978empty.  GCC interprets an empty list as meaning that all globally
11979accessible variables should be protected.
11980
11981@table @code
11982@item @var{type} __sync_fetch_and_add (@var{type} *ptr, @var{type} value, ...)
11983@itemx @var{type} __sync_fetch_and_sub (@var{type} *ptr, @var{type} value, ...)
11984@itemx @var{type} __sync_fetch_and_or (@var{type} *ptr, @var{type} value, ...)
11985@itemx @var{type} __sync_fetch_and_and (@var{type} *ptr, @var{type} value, ...)
11986@itemx @var{type} __sync_fetch_and_xor (@var{type} *ptr, @var{type} value, ...)
11987@itemx @var{type} __sync_fetch_and_nand (@var{type} *ptr, @var{type} value, ...)
11988@findex __sync_fetch_and_add
11989@findex __sync_fetch_and_sub
11990@findex __sync_fetch_and_or
11991@findex __sync_fetch_and_and
11992@findex __sync_fetch_and_xor
11993@findex __sync_fetch_and_nand
11994These built-in functions perform the operation suggested by the name, and
11995returns the value that had previously been in memory.  That is, operations
11996on integer operands have the following semantics.  Operations on pointer
11997arguments are performed as if the operands were of the @code{uintptr_t}
11998type.  That is, they are not scaled by the size of the type to which
11999the pointer points.
12000
12001@smallexample
12002@{ tmp = *ptr; *ptr @var{op}= value; return tmp; @}
12003@{ tmp = *ptr; *ptr = ~(tmp & value); return tmp; @}   // nand
12004@end smallexample
12005
12006The object pointed to by the first argument must be of integer or pointer
12007type.  It must not be a boolean type.
12008
12009@emph{Note:} GCC 4.4 and later implement @code{__sync_fetch_and_nand}
12010as @code{*ptr = ~(tmp & value)} instead of @code{*ptr = ~tmp & value}.
12011
12012@item @var{type} __sync_add_and_fetch (@var{type} *ptr, @var{type} value, ...)
12013@itemx @var{type} __sync_sub_and_fetch (@var{type} *ptr, @var{type} value, ...)
12014@itemx @var{type} __sync_or_and_fetch (@var{type} *ptr, @var{type} value, ...)
12015@itemx @var{type} __sync_and_and_fetch (@var{type} *ptr, @var{type} value, ...)
12016@itemx @var{type} __sync_xor_and_fetch (@var{type} *ptr, @var{type} value, ...)
12017@itemx @var{type} __sync_nand_and_fetch (@var{type} *ptr, @var{type} value, ...)
12018@findex __sync_add_and_fetch
12019@findex __sync_sub_and_fetch
12020@findex __sync_or_and_fetch
12021@findex __sync_and_and_fetch
12022@findex __sync_xor_and_fetch
12023@findex __sync_nand_and_fetch
12024These built-in functions perform the operation suggested by the name, and
12025return the new value.  That is, operations on integer operands have
12026the following semantics.  Operations on pointer operands are performed as
12027if the operand's type were @code{uintptr_t}.
12028
12029@smallexample
12030@{ *ptr @var{op}= value; return *ptr; @}
12031@{ *ptr = ~(*ptr & value); return *ptr; @}   // nand
12032@end smallexample
12033
12034The same constraints on arguments apply as for the corresponding
12035@code{__sync_op_and_fetch} built-in functions.
12036
12037@emph{Note:} GCC 4.4 and later implement @code{__sync_nand_and_fetch}
12038as @code{*ptr = ~(*ptr & value)} instead of
12039@code{*ptr = ~*ptr & value}.
12040
12041@item bool __sync_bool_compare_and_swap (@var{type} *ptr, @var{type} oldval, @var{type} newval, ...)
12042@itemx @var{type} __sync_val_compare_and_swap (@var{type} *ptr, @var{type} oldval, @var{type} newval, ...)
12043@findex __sync_bool_compare_and_swap
12044@findex __sync_val_compare_and_swap
12045These built-in functions perform an atomic compare and swap.
12046That is, if the current
12047value of @code{*@var{ptr}} is @var{oldval}, then write @var{newval} into
12048@code{*@var{ptr}}.
12049
12050The ``bool'' version returns @code{true} if the comparison is successful and
12051@var{newval} is written.  The ``val'' version returns the contents
12052of @code{*@var{ptr}} before the operation.
12053
12054@item __sync_synchronize (...)
12055@findex __sync_synchronize
12056This built-in function issues a full memory barrier.
12057
12058@item @var{type} __sync_lock_test_and_set (@var{type} *ptr, @var{type} value, ...)
12059@findex __sync_lock_test_and_set
12060This built-in function, as described by Intel, is not a traditional test-and-set
12061operation, but rather an atomic exchange operation.  It writes @var{value}
12062into @code{*@var{ptr}}, and returns the previous contents of
12063@code{*@var{ptr}}.
12064
12065Many targets have only minimal support for such locks, and do not support
12066a full exchange operation.  In this case, a target may support reduced
12067functionality here by which the @emph{only} valid value to store is the
12068immediate constant 1.  The exact value actually stored in @code{*@var{ptr}}
12069is implementation defined.
12070
12071This built-in function is not a full barrier,
12072but rather an @dfn{acquire barrier}.
12073This means that references after the operation cannot move to (or be
12074speculated to) before the operation, but previous memory stores may not
12075be globally visible yet, and previous memory loads may not yet be
12076satisfied.
12077
12078@item void __sync_lock_release (@var{type} *ptr, ...)
12079@findex __sync_lock_release
12080This built-in function releases the lock acquired by
12081@code{__sync_lock_test_and_set}.
12082Normally this means writing the constant 0 to @code{*@var{ptr}}.
12083
12084This built-in function is not a full barrier,
12085but rather a @dfn{release barrier}.
12086This means that all previous memory stores are globally visible, and all
12087previous memory loads have been satisfied, but following memory reads
12088are not prevented from being speculated to before the barrier.
12089@end table
12090
12091@node __atomic Builtins
12092@section Built-in Functions for Memory Model Aware Atomic Operations
12093
12094The following built-in functions approximately match the requirements
12095for the C++11 memory model.  They are all
12096identified by being prefixed with @samp{__atomic} and most are
12097overloaded so that they work with multiple types.
12098
12099These functions are intended to replace the legacy @samp{__sync}
12100builtins.  The main difference is that the memory order that is requested
12101is a parameter to the functions.  New code should always use the
12102@samp{__atomic} builtins rather than the @samp{__sync} builtins.
12103
12104Note that the @samp{__atomic} builtins assume that programs will
12105conform to the C++11 memory model.  In particular, they assume
12106that programs are free of data races.  See the C++11 standard for
12107detailed requirements.
12108
12109The @samp{__atomic} builtins can be used with any integral scalar or
12110pointer type that is 1, 2, 4, or 8 bytes in length.  16-byte integral
12111types are also allowed if @samp{__int128} (@pxref{__int128}) is
12112supported by the architecture.
12113
12114The four non-arithmetic functions (load, store, exchange, and
12115compare_exchange) all have a generic version as well.  This generic
12116version works on any data type.  It uses the lock-free built-in function
12117if the specific data type size makes that possible; otherwise, an
12118external call is left to be resolved at run time.  This external call is
12119the same format with the addition of a @samp{size_t} parameter inserted
12120as the first parameter indicating the size of the object being pointed to.
12121All objects must be the same size.
12122
12123There are 6 different memory orders that can be specified.  These map
12124to the C++11 memory orders with the same names, see the C++11 standard
12125or the @uref{http://gcc.gnu.org/wiki/Atomic/GCCMM/AtomicSync,GCC wiki
12126on atomic synchronization} for detailed definitions.  Individual
12127targets may also support additional memory orders for use on specific
12128architectures.  Refer to the target documentation for details of
12129these.
12130
12131An atomic operation can both constrain code motion and
12132be mapped to hardware instructions for synchronization between threads
12133(e.g., a fence).  To which extent this happens is controlled by the
12134memory orders, which are listed here in approximately ascending order of
12135strength.  The description of each memory order is only meant to roughly
12136illustrate the effects and is not a specification; see the C++11
12137memory model for precise semantics.
12138
12139@table  @code
12140@item __ATOMIC_RELAXED
12141Implies no inter-thread ordering constraints.
12142@item __ATOMIC_CONSUME
12143This is currently implemented using the stronger @code{__ATOMIC_ACQUIRE}
12144memory order because of a deficiency in C++11's semantics for
12145@code{memory_order_consume}.
12146@item __ATOMIC_ACQUIRE
12147Creates an inter-thread happens-before constraint from the release (or
12148stronger) semantic store to this acquire load.  Can prevent hoisting
12149of code to before the operation.
12150@item __ATOMIC_RELEASE
12151Creates an inter-thread happens-before constraint to acquire (or stronger)
12152semantic loads that read from this release store.  Can prevent sinking
12153of code to after the operation.
12154@item __ATOMIC_ACQ_REL
12155Combines the effects of both @code{__ATOMIC_ACQUIRE} and
12156@code{__ATOMIC_RELEASE}.
12157@item __ATOMIC_SEQ_CST
12158Enforces total ordering with all other @code{__ATOMIC_SEQ_CST} operations.
12159@end table
12160
12161Note that in the C++11 memory model, @emph{fences} (e.g.,
12162@samp{__atomic_thread_fence}) take effect in combination with other
12163atomic operations on specific memory locations (e.g., atomic loads);
12164operations on specific memory locations do not necessarily affect other
12165operations in the same way.
12166
12167Target architectures are encouraged to provide their own patterns for
12168each of the atomic built-in functions.  If no target is provided, the original
12169non-memory model set of @samp{__sync} atomic built-in functions are
12170used, along with any required synchronization fences surrounding it in
12171order to achieve the proper behavior.  Execution in this case is subject
12172to the same restrictions as those built-in functions.
12173
12174If there is no pattern or mechanism to provide a lock-free instruction
12175sequence, a call is made to an external routine with the same parameters
12176to be resolved at run time.
12177
12178When implementing patterns for these built-in functions, the memory order
12179parameter can be ignored as long as the pattern implements the most
12180restrictive @code{__ATOMIC_SEQ_CST} memory order.  Any of the other memory
12181orders execute correctly with this memory order but they may not execute as
12182efficiently as they could with a more appropriate implementation of the
12183relaxed requirements.
12184
12185Note that the C++11 standard allows for the memory order parameter to be
12186determined at run time rather than at compile time.  These built-in
12187functions map any run-time value to @code{__ATOMIC_SEQ_CST} rather
12188than invoke a runtime library call or inline a switch statement.  This is
12189standard compliant, safe, and the simplest approach for now.
12190
12191The memory order parameter is a signed int, but only the lower 16 bits are
12192reserved for the memory order.  The remainder of the signed int is reserved
12193for target use and should be 0.  Use of the predefined atomic values
12194ensures proper usage.
12195
12196@deftypefn {Built-in Function} @var{type} __atomic_load_n (@var{type} *ptr, int memorder)
12197This built-in function implements an atomic load operation.  It returns the
12198contents of @code{*@var{ptr}}.
12199
12200The valid memory order variants are
12201@code{__ATOMIC_RELAXED}, @code{__ATOMIC_SEQ_CST}, @code{__ATOMIC_ACQUIRE},
12202and @code{__ATOMIC_CONSUME}.
12203
12204@end deftypefn
12205
12206@deftypefn {Built-in Function} void __atomic_load (@var{type} *ptr, @var{type} *ret, int memorder)
12207This is the generic version of an atomic load.  It returns the
12208contents of @code{*@var{ptr}} in @code{*@var{ret}}.
12209
12210@end deftypefn
12211
12212@deftypefn {Built-in Function} void __atomic_store_n (@var{type} *ptr, @var{type} val, int memorder)
12213This built-in function implements an atomic store operation.  It writes
12214@code{@var{val}} into @code{*@var{ptr}}.
12215
12216The valid memory order variants are
12217@code{__ATOMIC_RELAXED}, @code{__ATOMIC_SEQ_CST}, and @code{__ATOMIC_RELEASE}.
12218
12219@end deftypefn
12220
12221@deftypefn {Built-in Function} void __atomic_store (@var{type} *ptr, @var{type} *val, int memorder)
12222This is the generic version of an atomic store.  It stores the value
12223of @code{*@var{val}} into @code{*@var{ptr}}.
12224
12225@end deftypefn
12226
12227@deftypefn {Built-in Function} @var{type} __atomic_exchange_n (@var{type} *ptr, @var{type} val, int memorder)
12228This built-in function implements an atomic exchange operation.  It writes
12229@var{val} into @code{*@var{ptr}}, and returns the previous contents of
12230@code{*@var{ptr}}.
12231
12232The valid memory order variants are
12233@code{__ATOMIC_RELAXED}, @code{__ATOMIC_SEQ_CST}, @code{__ATOMIC_ACQUIRE},
12234@code{__ATOMIC_RELEASE}, and @code{__ATOMIC_ACQ_REL}.
12235
12236@end deftypefn
12237
12238@deftypefn {Built-in Function} void __atomic_exchange (@var{type} *ptr, @var{type} *val, @var{type} *ret, int memorder)
12239This is the generic version of an atomic exchange.  It stores the
12240contents of @code{*@var{val}} into @code{*@var{ptr}}. The original value
12241of @code{*@var{ptr}} is copied into @code{*@var{ret}}.
12242
12243@end deftypefn
12244
12245@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)
12246This built-in function implements an atomic compare and exchange operation.
12247This compares the contents of @code{*@var{ptr}} with the contents of
12248@code{*@var{expected}}. If equal, the operation is a @emph{read-modify-write}
12249operation that writes @var{desired} into @code{*@var{ptr}}.  If they are not
12250equal, the operation is a @emph{read} and the current contents of
12251@code{*@var{ptr}} are written into @code{*@var{expected}}.  @var{weak} is @code{true}
12252for weak compare_exchange, which may fail spuriously, and @code{false} for
12253the strong variation, which never fails spuriously.  Many targets
12254only offer the strong variation and ignore the parameter.  When in doubt, use
12255the strong variation.
12256
12257If @var{desired} is written into @code{*@var{ptr}} then @code{true} is returned
12258and memory is affected according to the
12259memory order specified by @var{success_memorder}.  There are no
12260restrictions on what memory order can be used here.
12261
12262Otherwise, @code{false} is returned and memory is affected according
12263to @var{failure_memorder}. This memory order cannot be
12264@code{__ATOMIC_RELEASE} nor @code{__ATOMIC_ACQ_REL}.  It also cannot be a
12265stronger order than that specified by @var{success_memorder}.
12266
12267@end deftypefn
12268
12269@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)
12270This built-in function implements the generic version of
12271@code{__atomic_compare_exchange}.  The function is virtually identical to
12272@code{__atomic_compare_exchange_n}, except the desired value is also a
12273pointer.
12274
12275@end deftypefn
12276
12277@deftypefn {Built-in Function} @var{type} __atomic_add_fetch (@var{type} *ptr, @var{type} val, int memorder)
12278@deftypefnx {Built-in Function} @var{type} __atomic_sub_fetch (@var{type} *ptr, @var{type} val, int memorder)
12279@deftypefnx {Built-in Function} @var{type} __atomic_and_fetch (@var{type} *ptr, @var{type} val, int memorder)
12280@deftypefnx {Built-in Function} @var{type} __atomic_xor_fetch (@var{type} *ptr, @var{type} val, int memorder)
12281@deftypefnx {Built-in Function} @var{type} __atomic_or_fetch (@var{type} *ptr, @var{type} val, int memorder)
12282@deftypefnx {Built-in Function} @var{type} __atomic_nand_fetch (@var{type} *ptr, @var{type} val, int memorder)
12283These built-in functions perform the operation suggested by the name, and
12284return the result of the operation.  Operations on pointer arguments are
12285performed as if the operands were of the @code{uintptr_t} type.  That is,
12286they are not scaled by the size of the type to which the pointer points.
12287
12288@smallexample
12289@{ *ptr @var{op}= val; return *ptr; @}
12290@{ *ptr = ~(*ptr & val); return *ptr; @} // nand
12291@end smallexample
12292
12293The object pointed to by the first argument must be of integer or pointer
12294type.  It must not be a boolean type.  All memory orders are valid.
12295
12296@end deftypefn
12297
12298@deftypefn {Built-in Function} @var{type} __atomic_fetch_add (@var{type} *ptr, @var{type} val, int memorder)
12299@deftypefnx {Built-in Function} @var{type} __atomic_fetch_sub (@var{type} *ptr, @var{type} val, int memorder)
12300@deftypefnx {Built-in Function} @var{type} __atomic_fetch_and (@var{type} *ptr, @var{type} val, int memorder)
12301@deftypefnx {Built-in Function} @var{type} __atomic_fetch_xor (@var{type} *ptr, @var{type} val, int memorder)
12302@deftypefnx {Built-in Function} @var{type} __atomic_fetch_or (@var{type} *ptr, @var{type} val, int memorder)
12303@deftypefnx {Built-in Function} @var{type} __atomic_fetch_nand (@var{type} *ptr, @var{type} val, int memorder)
12304These built-in functions perform the operation suggested by the name, and
12305return the value that had previously been in @code{*@var{ptr}}.  Operations
12306on pointer arguments are performed as if the operands were of
12307the @code{uintptr_t} type.  That is, they are not scaled by the size of
12308the type to which the pointer points.
12309
12310@smallexample
12311@{ tmp = *ptr; *ptr @var{op}= val; return tmp; @}
12312@{ tmp = *ptr; *ptr = ~(*ptr & val); return tmp; @} // nand
12313@end smallexample
12314
12315The same constraints on arguments apply as for the corresponding
12316@code{__atomic_op_fetch} built-in functions.  All memory orders are valid.
12317
12318@end deftypefn
12319
12320@deftypefn {Built-in Function} bool __atomic_test_and_set (void *ptr, int memorder)
12321
12322This built-in function performs an atomic test-and-set operation on
12323the byte at @code{*@var{ptr}}.  The byte is set to some implementation
12324defined nonzero ``set'' value and the return value is @code{true} if and only
12325if the previous contents were ``set''.
12326It should be only used for operands of type @code{bool} or @code{char}. For
12327other types only part of the value may be set.
12328
12329All memory orders are valid.
12330
12331@end deftypefn
12332
12333@deftypefn {Built-in Function} void __atomic_clear (bool *ptr, int memorder)
12334
12335This built-in function performs an atomic clear operation on
12336@code{*@var{ptr}}.  After the operation, @code{*@var{ptr}} contains 0.
12337It should be only used for operands of type @code{bool} or @code{char} and
12338in conjunction with @code{__atomic_test_and_set}.
12339For other types it may only clear partially. If the type is not @code{bool}
12340prefer using @code{__atomic_store}.
12341
12342The valid memory order variants are
12343@code{__ATOMIC_RELAXED}, @code{__ATOMIC_SEQ_CST}, and
12344@code{__ATOMIC_RELEASE}.
12345
12346@end deftypefn
12347
12348@deftypefn {Built-in Function} void __atomic_thread_fence (int memorder)
12349
12350This built-in function acts as a synchronization fence between threads
12351based on the specified memory order.
12352
12353All memory orders are valid.
12354
12355@end deftypefn
12356
12357@deftypefn {Built-in Function} void __atomic_signal_fence (int memorder)
12358
12359This built-in function acts as a synchronization fence between a thread
12360and signal handlers based in the same thread.
12361
12362All memory orders are valid.
12363
12364@end deftypefn
12365
12366@deftypefn {Built-in Function} bool __atomic_always_lock_free (size_t size,  void *ptr)
12367
12368This built-in function returns @code{true} if objects of @var{size} bytes always
12369generate lock-free atomic instructions for the target architecture.
12370@var{size} must resolve to a compile-time constant and the result also
12371resolves to a compile-time constant.
12372
12373@var{ptr} is an optional pointer to the object that may be used to determine
12374alignment.  A value of 0 indicates typical alignment should be used.  The
12375compiler may also ignore this parameter.
12376
12377@smallexample
12378if (__atomic_always_lock_free (sizeof (long long), 0))
12379@end smallexample
12380
12381@end deftypefn
12382
12383@deftypefn {Built-in Function} bool __atomic_is_lock_free (size_t size, void *ptr)
12384
12385This built-in function returns @code{true} if objects of @var{size} bytes always
12386generate lock-free atomic instructions for the target architecture.  If
12387the built-in function is not known to be lock-free, a call is made to a
12388runtime routine named @code{__atomic_is_lock_free}.
12389
12390@var{ptr} is an optional pointer to the object that may be used to determine
12391alignment.  A value of 0 indicates typical alignment should be used.  The
12392compiler may also ignore this parameter.
12393@end deftypefn
12394
12395@node Integer Overflow Builtins
12396@section Built-in Functions to Perform Arithmetic with Overflow Checking
12397
12398The following built-in functions allow performing simple arithmetic operations
12399together with checking whether the operations overflowed.
12400
12401@deftypefn {Built-in Function} bool __builtin_add_overflow (@var{type1} a, @var{type2} b, @var{type3} *res)
12402@deftypefnx {Built-in Function} bool __builtin_sadd_overflow (int a, int b, int *res)
12403@deftypefnx {Built-in Function} bool __builtin_saddl_overflow (long int a, long int b, long int *res)
12404@deftypefnx {Built-in Function} bool __builtin_saddll_overflow (long long int a, long long int b, long long int *res)
12405@deftypefnx {Built-in Function} bool __builtin_uadd_overflow (unsigned int a, unsigned int b, unsigned int *res)
12406@deftypefnx {Built-in Function} bool __builtin_uaddl_overflow (unsigned long int a, unsigned long int b, unsigned long int *res)
12407@deftypefnx {Built-in Function} bool __builtin_uaddll_overflow (unsigned long long int a, unsigned long long int b, unsigned long long int *res)
12408
12409These built-in functions promote the first two operands into infinite precision signed
12410type and perform addition on those promoted operands.  The result is then
12411cast to the type the third pointer argument points to and stored there.
12412If the stored result is equal to the infinite precision result, the built-in
12413functions return @code{false}, otherwise they return @code{true}.  As the addition is
12414performed in infinite signed precision, these built-in functions have fully defined
12415behavior for all argument values.
12416
12417The first built-in function allows arbitrary integral types for operands and
12418the result type must be pointer to some integral type other than enumerated or
12419boolean type, the rest of the built-in functions have explicit integer types.
12420
12421The compiler will attempt to use hardware instructions to implement
12422these built-in functions where possible, like conditional jump on overflow
12423after addition, conditional jump on carry etc.
12424
12425@end deftypefn
12426
12427@deftypefn {Built-in Function} bool __builtin_sub_overflow (@var{type1} a, @var{type2} b, @var{type3} *res)
12428@deftypefnx {Built-in Function} bool __builtin_ssub_overflow (int a, int b, int *res)
12429@deftypefnx {Built-in Function} bool __builtin_ssubl_overflow (long int a, long int b, long int *res)
12430@deftypefnx {Built-in Function} bool __builtin_ssubll_overflow (long long int a, long long int b, long long int *res)
12431@deftypefnx {Built-in Function} bool __builtin_usub_overflow (unsigned int a, unsigned int b, unsigned int *res)
12432@deftypefnx {Built-in Function} bool __builtin_usubl_overflow (unsigned long int a, unsigned long int b, unsigned long int *res)
12433@deftypefnx {Built-in Function} bool __builtin_usubll_overflow (unsigned long long int a, unsigned long long int b, unsigned long long int *res)
12434
12435These built-in functions are similar to the add overflow checking built-in
12436functions above, except they perform subtraction, subtract the second argument
12437from the first one, instead of addition.
12438
12439@end deftypefn
12440
12441@deftypefn {Built-in Function} bool __builtin_mul_overflow (@var{type1} a, @var{type2} b, @var{type3} *res)
12442@deftypefnx {Built-in Function} bool __builtin_smul_overflow (int a, int b, int *res)
12443@deftypefnx {Built-in Function} bool __builtin_smull_overflow (long int a, long int b, long int *res)
12444@deftypefnx {Built-in Function} bool __builtin_smulll_overflow (long long int a, long long int b, long long int *res)
12445@deftypefnx {Built-in Function} bool __builtin_umul_overflow (unsigned int a, unsigned int b, unsigned int *res)
12446@deftypefnx {Built-in Function} bool __builtin_umull_overflow (unsigned long int a, unsigned long int b, unsigned long int *res)
12447@deftypefnx {Built-in Function} bool __builtin_umulll_overflow (unsigned long long int a, unsigned long long int b, unsigned long long int *res)
12448
12449These built-in functions are similar to the add overflow checking built-in
12450functions above, except they perform multiplication, instead of addition.
12451
12452@end deftypefn
12453
12454The following built-in functions allow checking if simple arithmetic operation
12455would overflow.
12456
12457@deftypefn {Built-in Function} bool __builtin_add_overflow_p (@var{type1} a, @var{type2} b, @var{type3} c)
12458@deftypefnx {Built-in Function} bool __builtin_sub_overflow_p (@var{type1} a, @var{type2} b, @var{type3} c)
12459@deftypefnx {Built-in Function} bool __builtin_mul_overflow_p (@var{type1} a, @var{type2} b, @var{type3} c)
12460
12461These built-in functions are similar to @code{__builtin_add_overflow},
12462@code{__builtin_sub_overflow}, or @code{__builtin_mul_overflow}, except that
12463they don't store the result of the arithmetic operation anywhere and the
12464last argument is not a pointer, but some expression with integral type other
12465than enumerated or boolean type.
12466
12467The built-in functions promote the first two operands into infinite precision signed type
12468and perform addition on those promoted operands. The result is then
12469cast to the type of the third argument.  If the cast result is equal to the infinite
12470precision result, the built-in functions return @code{false}, otherwise they return @code{true}.
12471The value of the third argument is ignored, just the side effects in the third argument
12472are evaluated, and no integral argument promotions are performed on the last argument.
12473If the third argument is a bit-field, the type used for the result cast has the
12474precision and signedness of the given bit-field, rather than precision and signedness
12475of the underlying type.
12476
12477For example, the following macro can be used to portably check, at
12478compile-time, whether or not adding two constant integers will overflow,
12479and perform the addition only when it is known to be safe and not to trigger
12480a @option{-Woverflow} warning.
12481
12482@smallexample
12483#define INT_ADD_OVERFLOW_P(a, b) \
12484   __builtin_add_overflow_p (a, b, (__typeof__ ((a) + (b))) 0)
12485
12486enum @{
12487    A = INT_MAX, B = 3,
12488    C = INT_ADD_OVERFLOW_P (A, B) ? 0 : A + B,
12489    D = __builtin_add_overflow_p (1, SCHAR_MAX, (signed char) 0)
12490@};
12491@end smallexample
12492
12493The compiler will attempt to use hardware instructions to implement
12494these built-in functions where possible, like conditional jump on overflow
12495after addition, conditional jump on carry etc.
12496
12497@end deftypefn
12498
12499@node x86 specific memory model extensions for transactional memory
12500@section x86-Specific Memory Model Extensions for Transactional Memory
12501
12502The x86 architecture supports additional memory ordering flags
12503to mark critical sections for hardware lock elision.
12504These must be specified in addition to an existing memory order to
12505atomic intrinsics.
12506
12507@table @code
12508@item __ATOMIC_HLE_ACQUIRE
12509Start lock elision on a lock variable.
12510Memory order must be @code{__ATOMIC_ACQUIRE} or stronger.
12511@item __ATOMIC_HLE_RELEASE
12512End lock elision on a lock variable.
12513Memory order must be @code{__ATOMIC_RELEASE} or stronger.
12514@end table
12515
12516When a lock acquire fails, it is required for good performance to abort
12517the transaction quickly. This can be done with a @code{_mm_pause}.
12518
12519@smallexample
12520#include <immintrin.h> // For _mm_pause
12521
12522int lockvar;
12523
12524/* Acquire lock with lock elision */
12525while (__atomic_exchange_n(&lockvar, 1, __ATOMIC_ACQUIRE|__ATOMIC_HLE_ACQUIRE))
12526    _mm_pause(); /* Abort failed transaction */
12527...
12528/* Free lock with lock elision */
12529__atomic_store_n(&lockvar, 0, __ATOMIC_RELEASE|__ATOMIC_HLE_RELEASE);
12530@end smallexample
12531
12532@node Object Size Checking
12533@section Object Size Checking Built-in Functions
12534@findex __builtin_object_size
12535@findex __builtin___memcpy_chk
12536@findex __builtin___mempcpy_chk
12537@findex __builtin___memmove_chk
12538@findex __builtin___memset_chk
12539@findex __builtin___strcpy_chk
12540@findex __builtin___stpcpy_chk
12541@findex __builtin___strncpy_chk
12542@findex __builtin___strcat_chk
12543@findex __builtin___strncat_chk
12544@findex __builtin___sprintf_chk
12545@findex __builtin___snprintf_chk
12546@findex __builtin___vsprintf_chk
12547@findex __builtin___vsnprintf_chk
12548@findex __builtin___printf_chk
12549@findex __builtin___vprintf_chk
12550@findex __builtin___fprintf_chk
12551@findex __builtin___vfprintf_chk
12552
12553GCC implements a limited buffer overflow protection mechanism that can
12554prevent some buffer overflow attacks by determining the sizes of objects
12555into which data is about to be written and preventing the writes when
12556the size isn't sufficient.  The built-in functions described below yield
12557the best results when used together and when optimization is enabled.
12558For example, to detect object sizes across function boundaries or to
12559follow pointer assignments through non-trivial control flow they rely
12560on various optimization passes enabled with @option{-O2}.  However, to
12561a limited extent, they can be used without optimization as well.
12562
12563@deftypefn {Built-in Function} {size_t} __builtin_object_size (const void * @var{ptr}, int @var{type})
12564is a built-in construct that returns a constant number of bytes from
12565@var{ptr} to the end of the object @var{ptr} pointer points to
12566(if known at compile time).  To determine the sizes of dynamically allocated
12567objects the function relies on the allocation functions called to obtain
12568the storage to be declared with the @code{alloc_size} attribute (@pxref{Common
12569Function Attributes}).  @code{__builtin_object_size} never evaluates
12570its arguments for side effects.  If there are any side effects in them, it
12571returns @code{(size_t) -1} for @var{type} 0 or 1 and @code{(size_t) 0}
12572for @var{type} 2 or 3.  If there are multiple objects @var{ptr} can
12573point to and all of them are known at compile time, the returned number
12574is the maximum of remaining byte counts in those objects if @var{type} & 2 is
125750 and minimum if nonzero.  If it is not possible to determine which objects
12576@var{ptr} points to at compile time, @code{__builtin_object_size} should
12577return @code{(size_t) -1} for @var{type} 0 or 1 and @code{(size_t) 0}
12578for @var{type} 2 or 3.
12579
12580@var{type} is an integer constant from 0 to 3.  If the least significant
12581bit is clear, objects are whole variables, if it is set, a closest
12582surrounding subobject is considered the object a pointer points to.
12583The second bit determines if maximum or minimum of remaining bytes
12584is computed.
12585
12586@smallexample
12587struct V @{ char buf1[10]; int b; char buf2[10]; @} var;
12588char *p = &var.buf1[1], *q = &var.b;
12589
12590/* Here the object p points to is var.  */
12591assert (__builtin_object_size (p, 0) == sizeof (var) - 1);
12592/* The subobject p points to is var.buf1.  */
12593assert (__builtin_object_size (p, 1) == sizeof (var.buf1) - 1);
12594/* The object q points to is var.  */
12595assert (__builtin_object_size (q, 0)
12596        == (char *) (&var + 1) - (char *) &var.b);
12597/* The subobject q points to is var.b.  */
12598assert (__builtin_object_size (q, 1) == sizeof (var.b));
12599@end smallexample
12600@end deftypefn
12601
12602There are built-in functions added for many common string operation
12603functions, e.g., for @code{memcpy} @code{__builtin___memcpy_chk}
12604built-in is provided.  This built-in has an additional last argument,
12605which is the number of bytes remaining in the object the @var{dest}
12606argument points to or @code{(size_t) -1} if the size is not known.
12607
12608The built-in functions are optimized into the normal string functions
12609like @code{memcpy} if the last argument is @code{(size_t) -1} or if
12610it is known at compile time that the destination object will not
12611be overflowed.  If the compiler can determine at compile time that the
12612object will always be overflowed, it issues a warning.
12613
12614The intended use can be e.g.@:
12615
12616@smallexample
12617#undef memcpy
12618#define bos0(dest) __builtin_object_size (dest, 0)
12619#define memcpy(dest, src, n) \
12620  __builtin___memcpy_chk (dest, src, n, bos0 (dest))
12621
12622char *volatile p;
12623char buf[10];
12624/* It is unknown what object p points to, so this is optimized
12625   into plain memcpy - no checking is possible.  */
12626memcpy (p, "abcde", n);
12627/* Destination is known and length too.  It is known at compile
12628   time there will be no overflow.  */
12629memcpy (&buf[5], "abcde", 5);
12630/* Destination is known, but the length is not known at compile time.
12631   This will result in __memcpy_chk call that can check for overflow
12632   at run time.  */
12633memcpy (&buf[5], "abcde", n);
12634/* Destination is known and it is known at compile time there will
12635   be overflow.  There will be a warning and __memcpy_chk call that
12636   will abort the program at run time.  */
12637memcpy (&buf[6], "abcde", 5);
12638@end smallexample
12639
12640Such built-in functions are provided for @code{memcpy}, @code{mempcpy},
12641@code{memmove}, @code{memset}, @code{strcpy}, @code{stpcpy}, @code{strncpy},
12642@code{strcat} and @code{strncat}.
12643
12644There are also checking built-in functions for formatted output functions.
12645@smallexample
12646int __builtin___sprintf_chk (char *s, int flag, size_t os, const char *fmt, ...);
12647int __builtin___snprintf_chk (char *s, size_t maxlen, int flag, size_t os,
12648                              const char *fmt, ...);
12649int __builtin___vsprintf_chk (char *s, int flag, size_t os, const char *fmt,
12650                              va_list ap);
12651int __builtin___vsnprintf_chk (char *s, size_t maxlen, int flag, size_t os,
12652                               const char *fmt, va_list ap);
12653@end smallexample
12654
12655The added @var{flag} argument is passed unchanged to @code{__sprintf_chk}
12656etc.@: functions and can contain implementation specific flags on what
12657additional security measures the checking function might take, such as
12658handling @code{%n} differently.
12659
12660The @var{os} argument is the object size @var{s} points to, like in the
12661other built-in functions.  There is a small difference in the behavior
12662though, if @var{os} is @code{(size_t) -1}, the built-in functions are
12663optimized into the non-checking functions only if @var{flag} is 0, otherwise
12664the checking function is called with @var{os} argument set to
12665@code{(size_t) -1}.
12666
12667In addition to this, there are checking built-in functions
12668@code{__builtin___printf_chk}, @code{__builtin___vprintf_chk},
12669@code{__builtin___fprintf_chk} and @code{__builtin___vfprintf_chk}.
12670These have just one additional argument, @var{flag}, right before
12671format string @var{fmt}.  If the compiler is able to optimize them to
12672@code{fputc} etc.@: functions, it does, otherwise the checking function
12673is called and the @var{flag} argument passed to it.
12674
12675@node Other Builtins
12676@section Other Built-in Functions Provided by GCC
12677@cindex built-in functions
12678@findex __builtin_alloca
12679@findex __builtin_alloca_with_align
12680@findex __builtin_alloca_with_align_and_max
12681@findex __builtin_call_with_static_chain
12682@findex __builtin_extend_pointer
12683@findex __builtin_fpclassify
12684@findex __builtin_has_attribute
12685@findex __builtin_isfinite
12686@findex __builtin_isnormal
12687@findex __builtin_isgreater
12688@findex __builtin_isgreaterequal
12689@findex __builtin_isinf_sign
12690@findex __builtin_isless
12691@findex __builtin_islessequal
12692@findex __builtin_islessgreater
12693@findex __builtin_isunordered
12694@findex __builtin_object_size
12695@findex __builtin_powi
12696@findex __builtin_powif
12697@findex __builtin_powil
12698@findex __builtin_speculation_safe_value
12699@findex _Exit
12700@findex _exit
12701@findex abort
12702@findex abs
12703@findex acos
12704@findex acosf
12705@findex acosh
12706@findex acoshf
12707@findex acoshl
12708@findex acosl
12709@findex alloca
12710@findex asin
12711@findex asinf
12712@findex asinh
12713@findex asinhf
12714@findex asinhl
12715@findex asinl
12716@findex atan
12717@findex atan2
12718@findex atan2f
12719@findex atan2l
12720@findex atanf
12721@findex atanh
12722@findex atanhf
12723@findex atanhl
12724@findex atanl
12725@findex bcmp
12726@findex bzero
12727@findex cabs
12728@findex cabsf
12729@findex cabsl
12730@findex cacos
12731@findex cacosf
12732@findex cacosh
12733@findex cacoshf
12734@findex cacoshl
12735@findex cacosl
12736@findex calloc
12737@findex carg
12738@findex cargf
12739@findex cargl
12740@findex casin
12741@findex casinf
12742@findex casinh
12743@findex casinhf
12744@findex casinhl
12745@findex casinl
12746@findex catan
12747@findex catanf
12748@findex catanh
12749@findex catanhf
12750@findex catanhl
12751@findex catanl
12752@findex cbrt
12753@findex cbrtf
12754@findex cbrtl
12755@findex ccos
12756@findex ccosf
12757@findex ccosh
12758@findex ccoshf
12759@findex ccoshl
12760@findex ccosl
12761@findex ceil
12762@findex ceilf
12763@findex ceill
12764@findex cexp
12765@findex cexpf
12766@findex cexpl
12767@findex cimag
12768@findex cimagf
12769@findex cimagl
12770@findex clog
12771@findex clogf
12772@findex clogl
12773@findex clog10
12774@findex clog10f
12775@findex clog10l
12776@findex conj
12777@findex conjf
12778@findex conjl
12779@findex copysign
12780@findex copysignf
12781@findex copysignl
12782@findex cos
12783@findex cosf
12784@findex cosh
12785@findex coshf
12786@findex coshl
12787@findex cosl
12788@findex cpow
12789@findex cpowf
12790@findex cpowl
12791@findex cproj
12792@findex cprojf
12793@findex cprojl
12794@findex creal
12795@findex crealf
12796@findex creall
12797@findex csin
12798@findex csinf
12799@findex csinh
12800@findex csinhf
12801@findex csinhl
12802@findex csinl
12803@findex csqrt
12804@findex csqrtf
12805@findex csqrtl
12806@findex ctan
12807@findex ctanf
12808@findex ctanh
12809@findex ctanhf
12810@findex ctanhl
12811@findex ctanl
12812@findex dcgettext
12813@findex dgettext
12814@findex drem
12815@findex dremf
12816@findex dreml
12817@findex erf
12818@findex erfc
12819@findex erfcf
12820@findex erfcl
12821@findex erff
12822@findex erfl
12823@findex exit
12824@findex exp
12825@findex exp10
12826@findex exp10f
12827@findex exp10l
12828@findex exp2
12829@findex exp2f
12830@findex exp2l
12831@findex expf
12832@findex expl
12833@findex expm1
12834@findex expm1f
12835@findex expm1l
12836@findex fabs
12837@findex fabsf
12838@findex fabsl
12839@findex fdim
12840@findex fdimf
12841@findex fdiml
12842@findex ffs
12843@findex floor
12844@findex floorf
12845@findex floorl
12846@findex fma
12847@findex fmaf
12848@findex fmal
12849@findex fmax
12850@findex fmaxf
12851@findex fmaxl
12852@findex fmin
12853@findex fminf
12854@findex fminl
12855@findex fmod
12856@findex fmodf
12857@findex fmodl
12858@findex fprintf
12859@findex fprintf_unlocked
12860@findex fputs
12861@findex fputs_unlocked
12862@findex free
12863@findex frexp
12864@findex frexpf
12865@findex frexpl
12866@findex fscanf
12867@findex gamma
12868@findex gammaf
12869@findex gammal
12870@findex gamma_r
12871@findex gammaf_r
12872@findex gammal_r
12873@findex gettext
12874@findex hypot
12875@findex hypotf
12876@findex hypotl
12877@findex ilogb
12878@findex ilogbf
12879@findex ilogbl
12880@findex imaxabs
12881@findex index
12882@findex isalnum
12883@findex isalpha
12884@findex isascii
12885@findex isblank
12886@findex iscntrl
12887@findex isdigit
12888@findex isgraph
12889@findex islower
12890@findex isprint
12891@findex ispunct
12892@findex isspace
12893@findex isupper
12894@findex iswalnum
12895@findex iswalpha
12896@findex iswblank
12897@findex iswcntrl
12898@findex iswdigit
12899@findex iswgraph
12900@findex iswlower
12901@findex iswprint
12902@findex iswpunct
12903@findex iswspace
12904@findex iswupper
12905@findex iswxdigit
12906@findex isxdigit
12907@findex j0
12908@findex j0f
12909@findex j0l
12910@findex j1
12911@findex j1f
12912@findex j1l
12913@findex jn
12914@findex jnf
12915@findex jnl
12916@findex labs
12917@findex ldexp
12918@findex ldexpf
12919@findex ldexpl
12920@findex lgamma
12921@findex lgammaf
12922@findex lgammal
12923@findex lgamma_r
12924@findex lgammaf_r
12925@findex lgammal_r
12926@findex llabs
12927@findex llrint
12928@findex llrintf
12929@findex llrintl
12930@findex llround
12931@findex llroundf
12932@findex llroundl
12933@findex log
12934@findex log10
12935@findex log10f
12936@findex log10l
12937@findex log1p
12938@findex log1pf
12939@findex log1pl
12940@findex log2
12941@findex log2f
12942@findex log2l
12943@findex logb
12944@findex logbf
12945@findex logbl
12946@findex logf
12947@findex logl
12948@findex lrint
12949@findex lrintf
12950@findex lrintl
12951@findex lround
12952@findex lroundf
12953@findex lroundl
12954@findex malloc
12955@findex memchr
12956@findex memcmp
12957@findex memcpy
12958@findex mempcpy
12959@findex memset
12960@findex modf
12961@findex modff
12962@findex modfl
12963@findex nearbyint
12964@findex nearbyintf
12965@findex nearbyintl
12966@findex nextafter
12967@findex nextafterf
12968@findex nextafterl
12969@findex nexttoward
12970@findex nexttowardf
12971@findex nexttowardl
12972@findex pow
12973@findex pow10
12974@findex pow10f
12975@findex pow10l
12976@findex powf
12977@findex powl
12978@findex printf
12979@findex printf_unlocked
12980@findex putchar
12981@findex puts
12982@findex realloc
12983@findex remainder
12984@findex remainderf
12985@findex remainderl
12986@findex remquo
12987@findex remquof
12988@findex remquol
12989@findex rindex
12990@findex rint
12991@findex rintf
12992@findex rintl
12993@findex round
12994@findex roundf
12995@findex roundl
12996@findex scalb
12997@findex scalbf
12998@findex scalbl
12999@findex scalbln
13000@findex scalblnf
13001@findex scalblnf
13002@findex scalbn
13003@findex scalbnf
13004@findex scanfnl
13005@findex signbit
13006@findex signbitf
13007@findex signbitl
13008@findex signbitd32
13009@findex signbitd64
13010@findex signbitd128
13011@findex significand
13012@findex significandf
13013@findex significandl
13014@findex sin
13015@findex sincos
13016@findex sincosf
13017@findex sincosl
13018@findex sinf
13019@findex sinh
13020@findex sinhf
13021@findex sinhl
13022@findex sinl
13023@findex snprintf
13024@findex sprintf
13025@findex sqrt
13026@findex sqrtf
13027@findex sqrtl
13028@findex sscanf
13029@findex stpcpy
13030@findex stpncpy
13031@findex strcasecmp
13032@findex strcat
13033@findex strchr
13034@findex strcmp
13035@findex strcpy
13036@findex strcspn
13037@findex strdup
13038@findex strfmon
13039@findex strftime
13040@findex strlen
13041@findex strncasecmp
13042@findex strncat
13043@findex strncmp
13044@findex strncpy
13045@findex strndup
13046@findex strnlen
13047@findex strpbrk
13048@findex strrchr
13049@findex strspn
13050@findex strstr
13051@findex tan
13052@findex tanf
13053@findex tanh
13054@findex tanhf
13055@findex tanhl
13056@findex tanl
13057@findex tgamma
13058@findex tgammaf
13059@findex tgammal
13060@findex toascii
13061@findex tolower
13062@findex toupper
13063@findex towlower
13064@findex towupper
13065@findex trunc
13066@findex truncf
13067@findex truncl
13068@findex vfprintf
13069@findex vfscanf
13070@findex vprintf
13071@findex vscanf
13072@findex vsnprintf
13073@findex vsprintf
13074@findex vsscanf
13075@findex y0
13076@findex y0f
13077@findex y0l
13078@findex y1
13079@findex y1f
13080@findex y1l
13081@findex yn
13082@findex ynf
13083@findex ynl
13084
13085GCC provides a large number of built-in functions other than the ones
13086mentioned above.  Some of these are for internal use in the processing
13087of exceptions or variable-length argument lists and are not
13088documented here because they may change from time to time; we do not
13089recommend general use of these functions.
13090
13091The remaining functions are provided for optimization purposes.
13092
13093With the exception of built-ins that have library equivalents such as
13094the standard C library functions discussed below, or that expand to
13095library calls, GCC built-in functions are always expanded inline and
13096thus do not have corresponding entry points and their address cannot
13097be obtained.  Attempting to use them in an expression other than
13098a function call results in a compile-time error.
13099
13100@opindex fno-builtin
13101GCC includes built-in versions of many of the functions in the standard
13102C library.  These functions come in two forms: one whose names start with
13103the @code{__builtin_} prefix, and the other without.  Both forms have the
13104same type (including prototype), the same address (when their address is
13105taken), and the same meaning as the C library functions even if you specify
13106the @option{-fno-builtin} option @pxref{C Dialect Options}).  Many of these
13107functions are only optimized in certain cases; if they are not optimized in
13108a particular case, a call to the library function is emitted.
13109
13110@opindex ansi
13111@opindex std
13112Outside strict ISO C mode (@option{-ansi}, @option{-std=c90},
13113@option{-std=c99} or @option{-std=c11}), the functions
13114@code{_exit}, @code{alloca}, @code{bcmp}, @code{bzero},
13115@code{dcgettext}, @code{dgettext}, @code{dremf}, @code{dreml},
13116@code{drem}, @code{exp10f}, @code{exp10l}, @code{exp10}, @code{ffsll},
13117@code{ffsl}, @code{ffs}, @code{fprintf_unlocked},
13118@code{fputs_unlocked}, @code{gammaf}, @code{gammal}, @code{gamma},
13119@code{gammaf_r}, @code{gammal_r}, @code{gamma_r}, @code{gettext},
13120@code{index}, @code{isascii}, @code{j0f}, @code{j0l}, @code{j0},
13121@code{j1f}, @code{j1l}, @code{j1}, @code{jnf}, @code{jnl}, @code{jn},
13122@code{lgammaf_r}, @code{lgammal_r}, @code{lgamma_r}, @code{mempcpy},
13123@code{pow10f}, @code{pow10l}, @code{pow10}, @code{printf_unlocked},
13124@code{rindex}, @code{roundeven}, @code{roundevenf}, @code{roundevenl},
13125@code{scalbf}, @code{scalbl}, @code{scalb},
13126@code{signbit}, @code{signbitf}, @code{signbitl}, @code{signbitd32},
13127@code{signbitd64}, @code{signbitd128}, @code{significandf},
13128@code{significandl}, @code{significand}, @code{sincosf},
13129@code{sincosl}, @code{sincos}, @code{stpcpy}, @code{stpncpy},
13130@code{strcasecmp}, @code{strdup}, @code{strfmon}, @code{strncasecmp},
13131@code{strndup}, @code{strnlen}, @code{toascii}, @code{y0f}, @code{y0l},
13132@code{y0}, @code{y1f}, @code{y1l}, @code{y1}, @code{ynf}, @code{ynl} and
13133@code{yn}
13134may be handled as built-in functions.
13135All these functions have corresponding versions
13136prefixed with @code{__builtin_}, which may be used even in strict C90
13137mode.
13138
13139The ISO C99 functions
13140@code{_Exit}, @code{acoshf}, @code{acoshl}, @code{acosh}, @code{asinhf},
13141@code{asinhl}, @code{asinh}, @code{atanhf}, @code{atanhl}, @code{atanh},
13142@code{cabsf}, @code{cabsl}, @code{cabs}, @code{cacosf}, @code{cacoshf},
13143@code{cacoshl}, @code{cacosh}, @code{cacosl}, @code{cacos},
13144@code{cargf}, @code{cargl}, @code{carg}, @code{casinf}, @code{casinhf},
13145@code{casinhl}, @code{casinh}, @code{casinl}, @code{casin},
13146@code{catanf}, @code{catanhf}, @code{catanhl}, @code{catanh},
13147@code{catanl}, @code{catan}, @code{cbrtf}, @code{cbrtl}, @code{cbrt},
13148@code{ccosf}, @code{ccoshf}, @code{ccoshl}, @code{ccosh}, @code{ccosl},
13149@code{ccos}, @code{cexpf}, @code{cexpl}, @code{cexp}, @code{cimagf},
13150@code{cimagl}, @code{cimag}, @code{clogf}, @code{clogl}, @code{clog},
13151@code{conjf}, @code{conjl}, @code{conj}, @code{copysignf}, @code{copysignl},
13152@code{copysign}, @code{cpowf}, @code{cpowl}, @code{cpow}, @code{cprojf},
13153@code{cprojl}, @code{cproj}, @code{crealf}, @code{creall}, @code{creal},
13154@code{csinf}, @code{csinhf}, @code{csinhl}, @code{csinh}, @code{csinl},
13155@code{csin}, @code{csqrtf}, @code{csqrtl}, @code{csqrt}, @code{ctanf},
13156@code{ctanhf}, @code{ctanhl}, @code{ctanh}, @code{ctanl}, @code{ctan},
13157@code{erfcf}, @code{erfcl}, @code{erfc}, @code{erff}, @code{erfl},
13158@code{erf}, @code{exp2f}, @code{exp2l}, @code{exp2}, @code{expm1f},
13159@code{expm1l}, @code{expm1}, @code{fdimf}, @code{fdiml}, @code{fdim},
13160@code{fmaf}, @code{fmal}, @code{fmaxf}, @code{fmaxl}, @code{fmax},
13161@code{fma}, @code{fminf}, @code{fminl}, @code{fmin}, @code{hypotf},
13162@code{hypotl}, @code{hypot}, @code{ilogbf}, @code{ilogbl}, @code{ilogb},
13163@code{imaxabs}, @code{isblank}, @code{iswblank}, @code{lgammaf},
13164@code{lgammal}, @code{lgamma}, @code{llabs}, @code{llrintf}, @code{llrintl},
13165@code{llrint}, @code{llroundf}, @code{llroundl}, @code{llround},
13166@code{log1pf}, @code{log1pl}, @code{log1p}, @code{log2f}, @code{log2l},
13167@code{log2}, @code{logbf}, @code{logbl}, @code{logb}, @code{lrintf},
13168@code{lrintl}, @code{lrint}, @code{lroundf}, @code{lroundl},
13169@code{lround}, @code{nearbyintf}, @code{nearbyintl}, @code{nearbyint},
13170@code{nextafterf}, @code{nextafterl}, @code{nextafter},
13171@code{nexttowardf}, @code{nexttowardl}, @code{nexttoward},
13172@code{remainderf}, @code{remainderl}, @code{remainder}, @code{remquof},
13173@code{remquol}, @code{remquo}, @code{rintf}, @code{rintl}, @code{rint},
13174@code{roundf}, @code{roundl}, @code{round}, @code{scalblnf},
13175@code{scalblnl}, @code{scalbln}, @code{scalbnf}, @code{scalbnl},
13176@code{scalbn}, @code{snprintf}, @code{tgammaf}, @code{tgammal},
13177@code{tgamma}, @code{truncf}, @code{truncl}, @code{trunc},
13178@code{vfscanf}, @code{vscanf}, @code{vsnprintf} and @code{vsscanf}
13179are handled as built-in functions
13180except in strict ISO C90 mode (@option{-ansi} or @option{-std=c90}).
13181
13182There are also built-in versions of the ISO C99 functions
13183@code{acosf}, @code{acosl}, @code{asinf}, @code{asinl}, @code{atan2f},
13184@code{atan2l}, @code{atanf}, @code{atanl}, @code{ceilf}, @code{ceill},
13185@code{cosf}, @code{coshf}, @code{coshl}, @code{cosl}, @code{expf},
13186@code{expl}, @code{fabsf}, @code{fabsl}, @code{floorf}, @code{floorl},
13187@code{fmodf}, @code{fmodl}, @code{frexpf}, @code{frexpl}, @code{ldexpf},
13188@code{ldexpl}, @code{log10f}, @code{log10l}, @code{logf}, @code{logl},
13189@code{modfl}, @code{modf}, @code{powf}, @code{powl}, @code{sinf},
13190@code{sinhf}, @code{sinhl}, @code{sinl}, @code{sqrtf}, @code{sqrtl},
13191@code{tanf}, @code{tanhf}, @code{tanhl} and @code{tanl}
13192that are recognized in any mode since ISO C90 reserves these names for
13193the purpose to which ISO C99 puts them.  All these functions have
13194corresponding versions prefixed with @code{__builtin_}.
13195
13196There are also built-in functions @code{__builtin_fabsf@var{n}},
13197@code{__builtin_fabsf@var{n}x}, @code{__builtin_copysignf@var{n}} and
13198@code{__builtin_copysignf@var{n}x}, corresponding to the TS 18661-3
13199functions @code{fabsf@var{n}}, @code{fabsf@var{n}x},
13200@code{copysignf@var{n}} and @code{copysignf@var{n}x}, for supported
13201types @code{_Float@var{n}} and @code{_Float@var{n}x}.
13202
13203There are also GNU extension functions @code{clog10}, @code{clog10f} and
13204@code{clog10l} which names are reserved by ISO C99 for future use.
13205All these functions have versions prefixed with @code{__builtin_}.
13206
13207The ISO C94 functions
13208@code{iswalnum}, @code{iswalpha}, @code{iswcntrl}, @code{iswdigit},
13209@code{iswgraph}, @code{iswlower}, @code{iswprint}, @code{iswpunct},
13210@code{iswspace}, @code{iswupper}, @code{iswxdigit}, @code{towlower} and
13211@code{towupper}
13212are handled as built-in functions
13213except in strict ISO C90 mode (@option{-ansi} or @option{-std=c90}).
13214
13215The ISO C90 functions
13216@code{abort}, @code{abs}, @code{acos}, @code{asin}, @code{atan2},
13217@code{atan}, @code{calloc}, @code{ceil}, @code{cosh}, @code{cos},
13218@code{exit}, @code{exp}, @code{fabs}, @code{floor}, @code{fmod},
13219@code{fprintf}, @code{fputs}, @code{free}, @code{frexp}, @code{fscanf},
13220@code{isalnum}, @code{isalpha}, @code{iscntrl}, @code{isdigit},
13221@code{isgraph}, @code{islower}, @code{isprint}, @code{ispunct},
13222@code{isspace}, @code{isupper}, @code{isxdigit}, @code{tolower},
13223@code{toupper}, @code{labs}, @code{ldexp}, @code{log10}, @code{log},
13224@code{malloc}, @code{memchr}, @code{memcmp}, @code{memcpy},
13225@code{memset}, @code{modf}, @code{pow}, @code{printf}, @code{putchar},
13226@code{puts}, @code{realloc}, @code{scanf}, @code{sinh}, @code{sin},
13227@code{snprintf}, @code{sprintf}, @code{sqrt}, @code{sscanf}, @code{strcat},
13228@code{strchr}, @code{strcmp}, @code{strcpy}, @code{strcspn},
13229@code{strlen}, @code{strncat}, @code{strncmp}, @code{strncpy},
13230@code{strpbrk}, @code{strrchr}, @code{strspn}, @code{strstr},
13231@code{tanh}, @code{tan}, @code{vfprintf}, @code{vprintf} and @code{vsprintf}
13232are all recognized as built-in functions unless
13233@option{-fno-builtin} is specified (or @option{-fno-builtin-@var{function}}
13234is specified for an individual function).  All of these functions have
13235corresponding versions prefixed with @code{__builtin_}.
13236
13237GCC provides built-in versions of the ISO C99 floating-point comparison
13238macros that avoid raising exceptions for unordered operands.  They have
13239the same names as the standard macros ( @code{isgreater},
13240@code{isgreaterequal}, @code{isless}, @code{islessequal},
13241@code{islessgreater}, and @code{isunordered}) , with @code{__builtin_}
13242prefixed.  We intend for a library implementor to be able to simply
13243@code{#define} each standard macro to its built-in equivalent.
13244In the same fashion, GCC provides @code{fpclassify}, @code{isfinite},
13245@code{isinf_sign}, @code{isnormal} and @code{signbit} built-ins used with
13246@code{__builtin_} prefixed.  The @code{isinf} and @code{isnan}
13247built-in functions appear both with and without the @code{__builtin_} prefix.
13248
13249@deftypefn {Built-in Function} void *__builtin_alloca (size_t size)
13250The @code{__builtin_alloca} function must be called at block scope.
13251The function allocates an object @var{size} bytes large on the stack
13252of the calling function.  The object is aligned on the default stack
13253alignment boundary for the target determined by the
13254@code{__BIGGEST_ALIGNMENT__} macro.  The @code{__builtin_alloca}
13255function returns a pointer to the first byte of the allocated object.
13256The lifetime of the allocated object ends just before the calling
13257function returns to its caller.   This is so even when
13258@code{__builtin_alloca} is called within a nested block.
13259
13260For example, the following function allocates eight objects of @code{n}
13261bytes each on the stack, storing a pointer to each in consecutive elements
13262of the array @code{a}.  It then passes the array to function @code{g}
13263which can safely use the storage pointed to by each of the array elements.
13264
13265@smallexample
13266void f (unsigned n)
13267@{
13268  void *a [8];
13269  for (int i = 0; i != 8; ++i)
13270    a [i] = __builtin_alloca (n);
13271
13272  g (a, n);   // @r{safe}
13273@}
13274@end smallexample
13275
13276Since the @code{__builtin_alloca} function doesn't validate its argument
13277it is the responsibility of its caller to make sure the argument doesn't
13278cause it to exceed the stack size limit.
13279The @code{__builtin_alloca} function is provided to make it possible to
13280allocate on the stack arrays of bytes with an upper bound that may be
13281computed at run time.  Since C99 Variable Length Arrays offer
13282similar functionality under a portable, more convenient, and safer
13283interface they are recommended instead, in both C99 and C++ programs
13284where GCC provides them as an extension.
13285@xref{Variable Length}, for details.
13286
13287@end deftypefn
13288
13289@deftypefn {Built-in Function} void *__builtin_alloca_with_align (size_t size, size_t alignment)
13290The @code{__builtin_alloca_with_align} function must be called at block
13291scope.  The function allocates an object @var{size} bytes large on
13292the stack of the calling function.  The allocated object is aligned on
13293the boundary specified by the argument @var{alignment} whose unit is given
13294in bits (not bytes).  The @var{size} argument must be positive and not
13295exceed the stack size limit.  The @var{alignment} argument must be a constant
13296integer expression that evaluates to a power of 2 greater than or equal to
13297@code{CHAR_BIT} and less than some unspecified maximum.  Invocations
13298with other values are rejected with an error indicating the valid bounds.
13299The function returns a pointer to the first byte of the allocated object.
13300The lifetime of the allocated object ends at the end of the block in which
13301the function was called.  The allocated storage is released no later than
13302just before the calling function returns to its caller, but may be released
13303at the end of the block in which the function was called.
13304
13305For example, in the following function the call to @code{g} is unsafe
13306because when @code{overalign} is non-zero, the space allocated by
13307@code{__builtin_alloca_with_align} may have been released at the end
13308of the @code{if} statement in which it was called.
13309
13310@smallexample
13311void f (unsigned n, bool overalign)
13312@{
13313  void *p;
13314  if (overalign)
13315    p = __builtin_alloca_with_align (n, 64 /* bits */);
13316  else
13317    p = __builtin_alloc (n);
13318
13319  g (p, n);   // @r{unsafe}
13320@}
13321@end smallexample
13322
13323Since the @code{__builtin_alloca_with_align} function doesn't validate its
13324@var{size} argument it is the responsibility of its caller to make sure
13325the argument doesn't cause it to exceed the stack size limit.
13326The @code{__builtin_alloca_with_align} function is provided to make
13327it possible to allocate on the stack overaligned arrays of bytes with
13328an upper bound that may be computed at run time.  Since C99
13329Variable Length Arrays offer the same functionality under
13330a portable, more convenient, and safer interface they are recommended
13331instead, in both C99 and C++ programs where GCC provides them as
13332an extension.  @xref{Variable Length}, for details.
13333
13334@end deftypefn
13335
13336@deftypefn {Built-in Function} void *__builtin_alloca_with_align_and_max (size_t size, size_t alignment, size_t max_size)
13337Similar to @code{__builtin_alloca_with_align} but takes an extra argument
13338specifying an upper bound for @var{size} in case its value cannot be computed
13339at compile time, for use by @option{-fstack-usage}, @option{-Wstack-usage}
13340and @option{-Walloca-larger-than}.  @var{max_size} must be a constant integer
13341expression, it has no effect on code generation and no attempt is made to
13342check its compatibility with @var{size}.
13343
13344@end deftypefn
13345
13346@deftypefn {Built-in Function} bool __builtin_has_attribute (@var{type-or-expression}, @var{attribute})
13347The @code{__builtin_has_attribute} function evaluates to an integer constant
13348expression equal to @code{true} if the symbol or type referenced by
13349the @var{type-or-expression} argument has been declared with
13350the @var{attribute} referenced by the second argument.  For
13351an @var{type-or-expression} argument that does not reference a symbol,
13352since attributes do not apply to expressions the built-in consider
13353the type of the argument.  Neither argument is evaluated.
13354The @var{type-or-expression} argument is subject to the same
13355restrictions as the argument to @code{typeof} (@pxref{Typeof}).  The
13356@var{attribute} argument is an attribute name optionally followed by
13357a comma-separated list of arguments enclosed in parentheses.  Both forms
13358of attribute names---with and without double leading and trailing
13359underscores---are recognized.  @xref{Attribute Syntax}, for details.
13360When no attribute arguments are specified for an attribute that expects
13361one or more arguments the function returns @code{true} if
13362@var{type-or-expression} has been declared with the attribute regardless
13363of the attribute argument values.  Arguments provided for an attribute
13364that expects some are validated and matched up to the provided number.
13365The function returns @code{true} if all provided arguments match.  For
13366example, the first call to the function below evaluates to @code{true}
13367because @code{x} is declared with the @code{aligned} attribute but
13368the second call evaluates to @code{false} because @code{x} is declared
13369@code{aligned (8)} and not @code{aligned (4)}.
13370
13371@smallexample
13372__attribute__ ((aligned (8))) int x;
13373_Static_assert (__builtin_has_attribute (x, aligned), "aligned");
13374_Static_assert (!__builtin_has_attribute (x, aligned (4)), "aligned (4)");
13375@end smallexample
13376
13377Due to a limitation the @code{__builtin_has_attribute} function returns
13378@code{false} for the @code{mode} attribute even if the type or variable
13379referenced by the @var{type-or-expression} argument was declared with one.
13380The function is also not supported with labels, and in C with enumerators.
13381
13382Note that unlike the @code{__has_attribute} preprocessor operator which
13383is suitable for use in @code{#if} preprocessing directives
13384@code{__builtin_has_attribute} is an intrinsic function that is not
13385recognized in such contexts.
13386
13387@end deftypefn
13388
13389@deftypefn {Built-in Function} @var{type} __builtin_speculation_safe_value (@var{type} val, @var{type} failval)
13390
13391This built-in function can be used to help mitigate against unsafe
13392speculative execution.  @var{type} may be any integral type or any
13393pointer type.
13394
13395@enumerate
13396@item
13397If the CPU is not speculatively executing the code, then @var{val}
13398is returned.
13399@item
13400If the CPU is executing speculatively then either:
13401@itemize
13402@item
13403The function may cause execution to pause until it is known that the
13404code is no-longer being executed speculatively (in which case
13405@var{val} can be returned, as above); or
13406@item
13407The function may use target-dependent speculation tracking state to cause
13408@var{failval} to be returned when it is known that speculative
13409execution has incorrectly predicted a conditional branch operation.
13410@end itemize
13411@end enumerate
13412
13413The second argument, @var{failval}, is optional and defaults to zero
13414if omitted.
13415
13416GCC defines the preprocessor macro
13417@code{__HAVE_BUILTIN_SPECULATION_SAFE_VALUE} for targets that have been
13418updated to support this builtin.
13419
13420The built-in function can be used where a variable appears to be used in a
13421safe way, but the CPU, due to speculative execution may temporarily ignore
13422the bounds checks.  Consider, for example, the following function:
13423
13424@smallexample
13425int array[500];
13426int f (unsigned untrusted_index)
13427@{
13428  if (untrusted_index < 500)
13429    return array[untrusted_index];
13430  return 0;
13431@}
13432@end smallexample
13433
13434If the function is called repeatedly with @code{untrusted_index} less
13435than the limit of 500, then a branch predictor will learn that the
13436block of code that returns a value stored in @code{array} will be
13437executed.  If the function is subsequently called with an
13438out-of-range value it will still try to execute that block of code
13439first until the CPU determines that the prediction was incorrect
13440(the CPU will unwind any incorrect operations at that point).
13441However, depending on how the result of the function is used, it might be
13442possible to leave traces in the cache that can reveal what was stored
13443at the out-of-bounds location.  The built-in function can be used to
13444provide some protection against leaking data in this way by changing
13445the code to:
13446
13447@smallexample
13448int array[500];
13449int f (unsigned untrusted_index)
13450@{
13451  if (untrusted_index < 500)
13452    return array[__builtin_speculation_safe_value (untrusted_index)];
13453  return 0;
13454@}
13455@end smallexample
13456
13457The built-in function will either cause execution to stall until the
13458conditional branch has been fully resolved, or it may permit
13459speculative execution to continue, but using 0 instead of
13460@code{untrusted_value} if that exceeds the limit.
13461
13462If accessing any memory location is potentially unsafe when speculative
13463execution is incorrect, then the code can be rewritten as
13464
13465@smallexample
13466int array[500];
13467int f (unsigned untrusted_index)
13468@{
13469  if (untrusted_index < 500)
13470    return *__builtin_speculation_safe_value (&array[untrusted_index], NULL);
13471  return 0;
13472@}
13473@end smallexample
13474
13475which will cause a @code{NULL} pointer to be used for the unsafe case.
13476
13477@end deftypefn
13478
13479@deftypefn {Built-in Function} int __builtin_types_compatible_p (@var{type1}, @var{type2})
13480
13481You can use the built-in function @code{__builtin_types_compatible_p} to
13482determine whether two types are the same.
13483
13484This built-in function returns 1 if the unqualified versions of the
13485types @var{type1} and @var{type2} (which are types, not expressions) are
13486compatible, 0 otherwise.  The result of this built-in function can be
13487used in integer constant expressions.
13488
13489This built-in function ignores top level qualifiers (e.g., @code{const},
13490@code{volatile}).  For example, @code{int} is equivalent to @code{const
13491int}.
13492
13493The type @code{int[]} and @code{int[5]} are compatible.  On the other
13494hand, @code{int} and @code{char *} are not compatible, even if the size
13495of their types, on the particular architecture are the same.  Also, the
13496amount of pointer indirection is taken into account when determining
13497similarity.  Consequently, @code{short *} is not similar to
13498@code{short **}.  Furthermore, two types that are typedefed are
13499considered compatible if their underlying types are compatible.
13500
13501An @code{enum} type is not considered to be compatible with another
13502@code{enum} type even if both are compatible with the same integer
13503type; this is what the C standard specifies.
13504For example, @code{enum @{foo, bar@}} is not similar to
13505@code{enum @{hot, dog@}}.
13506
13507You typically use this function in code whose execution varies
13508depending on the arguments' types.  For example:
13509
13510@smallexample
13511#define foo(x)                                                  \
13512  (@{                                                           \
13513    typeof (x) tmp = (x);                                       \
13514    if (__builtin_types_compatible_p (typeof (x), long double)) \
13515      tmp = foo_long_double (tmp);                              \
13516    else if (__builtin_types_compatible_p (typeof (x), double)) \
13517      tmp = foo_double (tmp);                                   \
13518    else if (__builtin_types_compatible_p (typeof (x), float))  \
13519      tmp = foo_float (tmp);                                    \
13520    else                                                        \
13521      abort ();                                                 \
13522    tmp;                                                        \
13523  @})
13524@end smallexample
13525
13526@emph{Note:} This construct is only available for C@.
13527
13528@end deftypefn
13529
13530@deftypefn {Built-in Function} @var{type} __builtin_call_with_static_chain (@var{call_exp}, @var{pointer_exp})
13531
13532The @var{call_exp} expression must be a function call, and the
13533@var{pointer_exp} expression must be a pointer.  The @var{pointer_exp}
13534is passed to the function call in the target's static chain location.
13535The result of builtin is the result of the function call.
13536
13537@emph{Note:} This builtin is only available for C@.
13538This builtin can be used to call Go closures from C.
13539
13540@end deftypefn
13541
13542@deftypefn {Built-in Function} @var{type} __builtin_choose_expr (@var{const_exp}, @var{exp1}, @var{exp2})
13543
13544You can use the built-in function @code{__builtin_choose_expr} to
13545evaluate code depending on the value of a constant expression.  This
13546built-in function returns @var{exp1} if @var{const_exp}, which is an
13547integer constant expression, is nonzero.  Otherwise it returns @var{exp2}.
13548
13549This built-in function is analogous to the @samp{? :} operator in C,
13550except that the expression returned has its type unaltered by promotion
13551rules.  Also, the built-in function does not evaluate the expression
13552that is not chosen.  For example, if @var{const_exp} evaluates to @code{true},
13553@var{exp2} is not evaluated even if it has side effects.
13554
13555This built-in function can return an lvalue if the chosen argument is an
13556lvalue.
13557
13558If @var{exp1} is returned, the return type is the same as @var{exp1}'s
13559type.  Similarly, if @var{exp2} is returned, its return type is the same
13560as @var{exp2}.
13561
13562Example:
13563
13564@smallexample
13565#define foo(x)                                                    \
13566  __builtin_choose_expr (                                         \
13567    __builtin_types_compatible_p (typeof (x), double),            \
13568    foo_double (x),                                               \
13569    __builtin_choose_expr (                                       \
13570      __builtin_types_compatible_p (typeof (x), float),           \
13571      foo_float (x),                                              \
13572      /* @r{The void expression results in a compile-time error}  \
13573         @r{when assigning the result to something.}  */          \
13574      (void)0))
13575@end smallexample
13576
13577@emph{Note:} This construct is only available for C@.  Furthermore, the
13578unused expression (@var{exp1} or @var{exp2} depending on the value of
13579@var{const_exp}) may still generate syntax errors.  This may change in
13580future revisions.
13581
13582@end deftypefn
13583
13584@deftypefn {Built-in Function} @var{type} __builtin_tgmath (@var{functions}, @var{arguments})
13585
13586The built-in function @code{__builtin_tgmath}, available only for C
13587and Objective-C, calls a function determined according to the rules of
13588@code{<tgmath.h>} macros.  It is intended to be used in
13589implementations of that header, so that expansions of macros from that
13590header only expand each of their arguments once, to avoid problems
13591when calls to such macros are nested inside the arguments of other
13592calls to such macros; in addition, it results in better diagnostics
13593for invalid calls to @code{<tgmath.h>} macros than implementations
13594using other GNU C language features.  For example, the @code{pow}
13595type-generic macro might be defined as:
13596
13597@smallexample
13598#define pow(a, b) __builtin_tgmath (powf, pow, powl, \
13599                                    cpowf, cpow, cpowl, a, b)
13600@end smallexample
13601
13602The arguments to @code{__builtin_tgmath} are at least two pointers to
13603functions, followed by the arguments to the type-generic macro (which
13604will be passed as arguments to the selected function).  All the
13605pointers to functions must be pointers to prototyped functions, none
13606of which may have variable arguments, and all of which must have the
13607same number of parameters; the number of parameters of the first
13608function determines how many arguments to @code{__builtin_tgmath} are
13609interpreted as function pointers, and how many as the arguments to the
13610called function.
13611
13612The types of the specified functions must all be different, but
13613related to each other in the same way as a set of functions that may
13614be selected between by a macro in @code{<tgmath.h>}.  This means that
13615the functions are parameterized by a floating-point type @var{t},
13616different for each such function.  The function return types may all
13617be the same type, or they may be @var{t} for each function, or they
13618may be the real type corresponding to @var{t} for each function (if
13619some of the types @var{t} are complex).  Likewise, for each parameter
13620position, the type of the parameter in that position may always be the
13621same type, or may be @var{t} for each function (this case must apply
13622for at least one parameter position), or may be the real type
13623corresponding to @var{t} for each function.
13624
13625The standard rules for @code{<tgmath.h>} macros are used to find a
13626common type @var{u} from the types of the arguments for parameters
13627whose types vary between the functions; complex integer types (a GNU
13628extension) are treated like @code{_Complex double} for this purpose
13629(or @code{_Complex _Float64} if all the function return types are the
13630same @code{_Float@var{n}} or @code{_Float@var{n}x} type).
13631If the function return types vary, or are all the same integer type,
13632the function called is the one for which @var{t} is @var{u}, and it is
13633an error if there is no such function.  If the function return types
13634are all the same floating-point type, the type-generic macro is taken
13635to be one of those from TS 18661 that rounds the result to a narrower
13636type; if there is a function for which @var{t} is @var{u}, it is
13637called, and otherwise the first function, if any, for which @var{t}
13638has at least the range and precision of @var{u} is called, and it is
13639an error if there is no such function.
13640
13641@end deftypefn
13642
13643@deftypefn {Built-in Function} @var{type} __builtin_complex (@var{real}, @var{imag})
13644
13645The built-in function @code{__builtin_complex} is provided for use in
13646implementing the ISO C11 macros @code{CMPLXF}, @code{CMPLX} and
13647@code{CMPLXL}.  @var{real} and @var{imag} must have the same type, a
13648real binary floating-point type, and the result has the corresponding
13649complex type with real and imaginary parts @var{real} and @var{imag}.
13650Unlike @samp{@var{real} + I * @var{imag}}, this works even when
13651infinities, NaNs and negative zeros are involved.
13652
13653@end deftypefn
13654
13655@deftypefn {Built-in Function} int __builtin_constant_p (@var{exp})
13656You can use the built-in function @code{__builtin_constant_p} to
13657determine if a value is known to be constant at compile time and hence
13658that GCC can perform constant-folding on expressions involving that
13659value.  The argument of the function is the value to test.  The function
13660returns the integer 1 if the argument is known to be a compile-time
13661constant and 0 if it is not known to be a compile-time constant.  A
13662return of 0 does not indicate that the value is @emph{not} a constant,
13663but merely that GCC cannot prove it is a constant with the specified
13664value of the @option{-O} option.
13665
13666You typically use this function in an embedded application where
13667memory is a critical resource.  If you have some complex calculation,
13668you may want it to be folded if it involves constants, but need to call
13669a function if it does not.  For example:
13670
13671@smallexample
13672#define Scale_Value(X)      \
13673  (__builtin_constant_p (X) \
13674  ? ((X) * SCALE + OFFSET) : Scale (X))
13675@end smallexample
13676
13677You may use this built-in function in either a macro or an inline
13678function.  However, if you use it in an inlined function and pass an
13679argument of the function as the argument to the built-in, GCC
13680never returns 1 when you call the inline function with a string constant
13681or compound literal (@pxref{Compound Literals}) and does not return 1
13682when you pass a constant numeric value to the inline function unless you
13683specify the @option{-O} option.
13684
13685You may also use @code{__builtin_constant_p} in initializers for static
13686data.  For instance, you can write
13687
13688@smallexample
13689static const int table[] = @{
13690   __builtin_constant_p (EXPRESSION) ? (EXPRESSION) : -1,
13691   /* @r{@dots{}} */
13692@};
13693@end smallexample
13694
13695@noindent
13696This is an acceptable initializer even if @var{EXPRESSION} is not a
13697constant expression, including the case where
13698@code{__builtin_constant_p} returns 1 because @var{EXPRESSION} can be
13699folded to a constant but @var{EXPRESSION} contains operands that are
13700not otherwise permitted in a static initializer (for example,
13701@code{0 && foo ()}).  GCC must be more conservative about evaluating the
13702built-in in this case, because it has no opportunity to perform
13703optimization.
13704@end deftypefn
13705
13706@deftypefn {Built-in Function} bool __builtin_is_constant_evaluated (void)
13707The @code{__builtin_is_constant_evaluated} function is available only
13708in C++.  The built-in is intended to be used by implementations of
13709the @code{std::is_constant_evaluated} C++ function.  Programs should make
13710use of the latter function rather than invoking the built-in directly.
13711
13712The main use case of the built-in is to determine whether a @code{constexpr}
13713function is being called in a @code{constexpr} context.  A call to
13714the function evaluates to a core constant expression with the value
13715@code{true} if and only if it occurs within the evaluation of an expression
13716or conversion that is manifestly constant-evaluated as defined in the C++
13717standard.  Manifestly constant-evaluated contexts include constant-expressions,
13718the conditions of @code{constexpr if} statements, constraint-expressions, and
13719initializers of variables usable in constant expressions.   For more details
13720refer to the latest revision of the C++ standard.
13721@end deftypefn
13722
13723@deftypefn {Built-in Function} void __builtin_clear_padding (@var{ptr})
13724The built-in function @code{__builtin_clear_padding} function clears
13725padding bits inside of the object representation of object pointed by
13726@var{ptr}, which has to be a pointer.  The value representation of the
13727object is not affected.  The type of the object is assumed to be the type
13728the pointer points to.  Inside of a union, the only cleared bits are
13729bits that are padding bits for all the union members.
13730
13731This built-in-function is useful if the padding bits of an object might
13732have intederminate values and the object representation needs to be
13733bitwise compared to some other object, for example for atomic operations.
13734@end deftypefn
13735
13736@deftypefn {Built-in Function} @var{type} __builtin_bit_cast (@var{type}, @var{arg})
13737The @code{__builtin_bit_cast} function is available only
13738in C++.  The built-in is intended to be used by implementations of
13739the @code{std::bit_cast} C++ template function.  Programs should make
13740use of the latter function rather than invoking the built-in directly.
13741
13742This built-in function allows reinterpreting the bits of the @var{arg}
13743argument as if it had type @var{type}.  @var{type} and the type of the
13744@var{arg} argument need to be trivially copyable types with the same size.
13745When manifestly constant-evaluated, it performs extra diagnostics required
13746for @code{std::bit_cast} and returns a constant expression if @var{arg}
13747is a constant expression.  For more details
13748refer to the latest revision of the C++ standard.
13749@end deftypefn
13750
13751@deftypefn {Built-in Function} long __builtin_expect (long @var{exp}, long @var{c})
13752@opindex fprofile-arcs
13753You may use @code{__builtin_expect} to provide the compiler with
13754branch prediction information.  In general, you should prefer to
13755use actual profile feedback for this (@option{-fprofile-arcs}), as
13756programmers are notoriously bad at predicting how their programs
13757actually perform.  However, there are applications in which this
13758data is hard to collect.
13759
13760The return value is the value of @var{exp}, which should be an integral
13761expression.  The semantics of the built-in are that it is expected that
13762@var{exp} == @var{c}.  For example:
13763
13764@smallexample
13765if (__builtin_expect (x, 0))
13766  foo ();
13767@end smallexample
13768
13769@noindent
13770indicates that we do not expect to call @code{foo}, since
13771we expect @code{x} to be zero.  Since you are limited to integral
13772expressions for @var{exp}, you should use constructions such as
13773
13774@smallexample
13775if (__builtin_expect (ptr != NULL, 1))
13776  foo (*ptr);
13777@end smallexample
13778
13779@noindent
13780when testing pointer or floating-point values.
13781
13782For the purposes of branch prediction optimizations, the probability that
13783a @code{__builtin_expect} expression is @code{true} is controlled by GCC's
13784@code{builtin-expect-probability} parameter, which defaults to 90%.
13785
13786You can also use @code{__builtin_expect_with_probability} to explicitly
13787assign a probability value to individual expressions.  If the built-in
13788is used in a loop construct, the provided probability will influence
13789the expected number of iterations made by loop optimizations.
13790@end deftypefn
13791
13792@deftypefn {Built-in Function} long __builtin_expect_with_probability
13793(long @var{exp}, long @var{c}, double @var{probability})
13794
13795This function has the same semantics as @code{__builtin_expect},
13796but the caller provides the expected probability that @var{exp} == @var{c}.
13797The last argument, @var{probability}, is a floating-point value in the
13798range 0.0 to 1.0, inclusive.  The @var{probability} argument must be
13799constant floating-point expression.
13800@end deftypefn
13801
13802@deftypefn {Built-in Function} void __builtin_trap (void)
13803This function causes the program to exit abnormally.  GCC implements
13804this function by using a target-dependent mechanism (such as
13805intentionally executing an illegal instruction) or by calling
13806@code{abort}.  The mechanism used may vary from release to release so
13807you should not rely on any particular implementation.
13808@end deftypefn
13809
13810@deftypefn {Built-in Function} void __builtin_unreachable (void)
13811If control flow reaches the point of the @code{__builtin_unreachable},
13812the program is undefined.  It is useful in situations where the
13813compiler cannot deduce the unreachability of the code.
13814
13815One such case is immediately following an @code{asm} statement that
13816either never terminates, or one that transfers control elsewhere
13817and never returns.  In this example, without the
13818@code{__builtin_unreachable}, GCC issues a warning that control
13819reaches the end of a non-void function.  It also generates code
13820to return after the @code{asm}.
13821
13822@smallexample
13823int f (int c, int v)
13824@{
13825  if (c)
13826    @{
13827      return v;
13828    @}
13829  else
13830    @{
13831      asm("jmp error_handler");
13832      __builtin_unreachable ();
13833    @}
13834@}
13835@end smallexample
13836
13837@noindent
13838Because the @code{asm} statement unconditionally transfers control out
13839of the function, control never reaches the end of the function
13840body.  The @code{__builtin_unreachable} is in fact unreachable and
13841communicates this fact to the compiler.
13842
13843Another use for @code{__builtin_unreachable} is following a call a
13844function that never returns but that is not declared
13845@code{__attribute__((noreturn))}, as in this example:
13846
13847@smallexample
13848void function_that_never_returns (void);
13849
13850int g (int c)
13851@{
13852  if (c)
13853    @{
13854      return 1;
13855    @}
13856  else
13857    @{
13858      function_that_never_returns ();
13859      __builtin_unreachable ();
13860    @}
13861@}
13862@end smallexample
13863
13864@end deftypefn
13865
13866@deftypefn {Built-in Function} {void *} __builtin_assume_aligned (const void *@var{exp}, size_t @var{align}, ...)
13867This function returns its first argument, and allows the compiler
13868to assume that the returned pointer is at least @var{align} bytes
13869aligned.  This built-in can have either two or three arguments,
13870if it has three, the third argument should have integer type, and
13871if it is nonzero means misalignment offset.  For example:
13872
13873@smallexample
13874void *x = __builtin_assume_aligned (arg, 16);
13875@end smallexample
13876
13877@noindent
13878means that the compiler can assume @code{x}, set to @code{arg}, is at least
1387916-byte aligned, while:
13880
13881@smallexample
13882void *x = __builtin_assume_aligned (arg, 32, 8);
13883@end smallexample
13884
13885@noindent
13886means that the compiler can assume for @code{x}, set to @code{arg}, that
13887@code{(char *) x - 8} is 32-byte aligned.
13888@end deftypefn
13889
13890@deftypefn {Built-in Function} int __builtin_LINE ()
13891This function is the equivalent of the preprocessor @code{__LINE__}
13892macro and returns a constant integer expression that evaluates to
13893the line number of the invocation of the built-in.  When used as a C++
13894default argument for a function @var{F}, it returns the line number
13895of the call to @var{F}.
13896@end deftypefn
13897
13898@deftypefn {Built-in Function} {const char *} __builtin_FUNCTION ()
13899This function is the equivalent of the @code{__FUNCTION__} symbol
13900and returns an address constant pointing to the name of the function
13901from which the built-in was invoked, or the empty string if
13902the invocation is not at function scope.  When used as a C++ default
13903argument for a function @var{F}, it returns the name of @var{F}'s
13904caller or the empty string if the call was not made at function
13905scope.
13906@end deftypefn
13907
13908@deftypefn {Built-in Function} {const char *} __builtin_FILE ()
13909This function is the equivalent of the preprocessor @code{__FILE__}
13910macro and returns an address constant pointing to the file name
13911containing the invocation of the built-in, or the empty string if
13912the invocation is not at function scope.  When used as a C++ default
13913argument for a function @var{F}, it returns the file name of the call
13914to @var{F} or the empty string if the call was not made at function
13915scope.
13916
13917For example, in the following, each call to function @code{foo} will
13918print a line similar to @code{"file.c:123: foo: message"} with the name
13919of the file and the line number of the @code{printf} call, the name of
13920the function @code{foo}, followed by the word @code{message}.
13921
13922@smallexample
13923const char*
13924function (const char *func = __builtin_FUNCTION ())
13925@{
13926  return func;
13927@}
13928
13929void foo (void)
13930@{
13931  printf ("%s:%i: %s: message\n", file (), line (), function ());
13932@}
13933@end smallexample
13934
13935@end deftypefn
13936
13937@deftypefn {Built-in Function} void __builtin___clear_cache (void *@var{begin}, void *@var{end})
13938This function is used to flush the processor's instruction cache for
13939the region of memory between @var{begin} inclusive and @var{end}
13940exclusive.  Some targets require that the instruction cache be
13941flushed, after modifying memory containing code, in order to obtain
13942deterministic behavior.
13943
13944If the target does not require instruction cache flushes,
13945@code{__builtin___clear_cache} has no effect.  Otherwise either
13946instructions are emitted in-line to clear the instruction cache or a
13947call to the @code{__clear_cache} function in libgcc is made.
13948@end deftypefn
13949
13950@deftypefn {Built-in Function} void __builtin_prefetch (const void *@var{addr}, ...)
13951This function is used to minimize cache-miss latency by moving data into
13952a cache before it is accessed.
13953You can insert calls to @code{__builtin_prefetch} into code for which
13954you know addresses of data in memory that is likely to be accessed soon.
13955If the target supports them, data prefetch instructions are generated.
13956If the prefetch is done early enough before the access then the data will
13957be in the cache by the time it is accessed.
13958
13959The value of @var{addr} is the address of the memory to prefetch.
13960There are two optional arguments, @var{rw} and @var{locality}.
13961The value of @var{rw} is a compile-time constant one or zero; one
13962means that the prefetch is preparing for a write to the memory address
13963and zero, the default, means that the prefetch is preparing for a read.
13964The value @var{locality} must be a compile-time constant integer between
13965zero and three.  A value of zero means that the data has no temporal
13966locality, so it need not be left in the cache after the access.  A value
13967of three means that the data has a high degree of temporal locality and
13968should be left in all levels of cache possible.  Values of one and two
13969mean, respectively, a low or moderate degree of temporal locality.  The
13970default is three.
13971
13972@smallexample
13973for (i = 0; i < n; i++)
13974  @{
13975    a[i] = a[i] + b[i];
13976    __builtin_prefetch (&a[i+j], 1, 1);
13977    __builtin_prefetch (&b[i+j], 0, 1);
13978    /* @r{@dots{}} */
13979  @}
13980@end smallexample
13981
13982Data prefetch does not generate faults if @var{addr} is invalid, but
13983the address expression itself must be valid.  For example, a prefetch
13984of @code{p->next} does not fault if @code{p->next} is not a valid
13985address, but evaluation faults if @code{p} is not a valid address.
13986
13987If the target does not support data prefetch, the address expression
13988is evaluated if it includes side effects but no other code is generated
13989and GCC does not issue a warning.
13990@end deftypefn
13991
13992@deftypefn {Built-in Function}{size_t} __builtin_object_size (const void * @var{ptr}, int @var{type})
13993Returns the size of an object pointed to by @var{ptr}.  @xref{Object Size
13994Checking}, for a detailed description of the function.
13995@end deftypefn
13996
13997@deftypefn {Built-in Function} double __builtin_huge_val (void)
13998Returns a positive infinity, if supported by the floating-point format,
13999else @code{DBL_MAX}.  This function is suitable for implementing the
14000ISO C macro @code{HUGE_VAL}.
14001@end deftypefn
14002
14003@deftypefn {Built-in Function} float __builtin_huge_valf (void)
14004Similar to @code{__builtin_huge_val}, except the return type is @code{float}.
14005@end deftypefn
14006
14007@deftypefn {Built-in Function} {long double} __builtin_huge_vall (void)
14008Similar to @code{__builtin_huge_val}, except the return
14009type is @code{long double}.
14010@end deftypefn
14011
14012@deftypefn {Built-in Function} _Float@var{n} __builtin_huge_valf@var{n} (void)
14013Similar to @code{__builtin_huge_val}, except the return type is
14014@code{_Float@var{n}}.
14015@end deftypefn
14016
14017@deftypefn {Built-in Function} _Float@var{n}x __builtin_huge_valf@var{n}x (void)
14018Similar to @code{__builtin_huge_val}, except the return type is
14019@code{_Float@var{n}x}.
14020@end deftypefn
14021
14022@deftypefn {Built-in Function} int __builtin_fpclassify (int, int, int, int, int, ...)
14023This built-in implements the C99 fpclassify functionality.  The first
14024five int arguments should be the target library's notion of the
14025possible FP classes and are used for return values.  They must be
14026constant values and they must appear in this order: @code{FP_NAN},
14027@code{FP_INFINITE}, @code{FP_NORMAL}, @code{FP_SUBNORMAL} and
14028@code{FP_ZERO}.  The ellipsis is for exactly one floating-point value
14029to classify.  GCC treats the last argument as type-generic, which
14030means it does not do default promotion from float to double.
14031@end deftypefn
14032
14033@deftypefn {Built-in Function} double __builtin_inf (void)
14034Similar to @code{__builtin_huge_val}, except a warning is generated
14035if the target floating-point format does not support infinities.
14036@end deftypefn
14037
14038@deftypefn {Built-in Function} _Decimal32 __builtin_infd32 (void)
14039Similar to @code{__builtin_inf}, except the return type is @code{_Decimal32}.
14040@end deftypefn
14041
14042@deftypefn {Built-in Function} _Decimal64 __builtin_infd64 (void)
14043Similar to @code{__builtin_inf}, except the return type is @code{_Decimal64}.
14044@end deftypefn
14045
14046@deftypefn {Built-in Function} _Decimal128 __builtin_infd128 (void)
14047Similar to @code{__builtin_inf}, except the return type is @code{_Decimal128}.
14048@end deftypefn
14049
14050@deftypefn {Built-in Function} float __builtin_inff (void)
14051Similar to @code{__builtin_inf}, except the return type is @code{float}.
14052This function is suitable for implementing the ISO C99 macro @code{INFINITY}.
14053@end deftypefn
14054
14055@deftypefn {Built-in Function} {long double} __builtin_infl (void)
14056Similar to @code{__builtin_inf}, except the return
14057type is @code{long double}.
14058@end deftypefn
14059
14060@deftypefn {Built-in Function} _Float@var{n} __builtin_inff@var{n} (void)
14061Similar to @code{__builtin_inf}, except the return
14062type is @code{_Float@var{n}}.
14063@end deftypefn
14064
14065@deftypefn {Built-in Function} _Float@var{n} __builtin_inff@var{n}x (void)
14066Similar to @code{__builtin_inf}, except the return
14067type is @code{_Float@var{n}x}.
14068@end deftypefn
14069
14070@deftypefn {Built-in Function} int __builtin_isinf_sign (...)
14071Similar to @code{isinf}, except the return value is -1 for
14072an argument of @code{-Inf} and 1 for an argument of @code{+Inf}.
14073Note while the parameter list is an
14074ellipsis, this function only accepts exactly one floating-point
14075argument.  GCC treats this parameter as type-generic, which means it
14076does not do default promotion from float to double.
14077@end deftypefn
14078
14079@deftypefn {Built-in Function} double __builtin_nan (const char *str)
14080This is an implementation of the ISO C99 function @code{nan}.
14081
14082Since ISO C99 defines this function in terms of @code{strtod}, which we
14083do not implement, a description of the parsing is in order.  The string
14084is parsed as by @code{strtol}; that is, the base is recognized by
14085leading @samp{0} or @samp{0x} prefixes.  The number parsed is placed
14086in the significand such that the least significant bit of the number
14087is at the least significant bit of the significand.  The number is
14088truncated to fit the significand field provided.  The significand is
14089forced to be a quiet NaN@.
14090
14091This function, if given a string literal all of which would have been
14092consumed by @code{strtol}, is evaluated early enough that it is considered a
14093compile-time constant.
14094@end deftypefn
14095
14096@deftypefn {Built-in Function} _Decimal32 __builtin_nand32 (const char *str)
14097Similar to @code{__builtin_nan}, except the return type is @code{_Decimal32}.
14098@end deftypefn
14099
14100@deftypefn {Built-in Function} _Decimal64 __builtin_nand64 (const char *str)
14101Similar to @code{__builtin_nan}, except the return type is @code{_Decimal64}.
14102@end deftypefn
14103
14104@deftypefn {Built-in Function} _Decimal128 __builtin_nand128 (const char *str)
14105Similar to @code{__builtin_nan}, except the return type is @code{_Decimal128}.
14106@end deftypefn
14107
14108@deftypefn {Built-in Function} float __builtin_nanf (const char *str)
14109Similar to @code{__builtin_nan}, except the return type is @code{float}.
14110@end deftypefn
14111
14112@deftypefn {Built-in Function} {long double} __builtin_nanl (const char *str)
14113Similar to @code{__builtin_nan}, except the return type is @code{long double}.
14114@end deftypefn
14115
14116@deftypefn {Built-in Function} _Float@var{n} __builtin_nanf@var{n} (const char *str)
14117Similar to @code{__builtin_nan}, except the return type is
14118@code{_Float@var{n}}.
14119@end deftypefn
14120
14121@deftypefn {Built-in Function} _Float@var{n}x __builtin_nanf@var{n}x (const char *str)
14122Similar to @code{__builtin_nan}, except the return type is
14123@code{_Float@var{n}x}.
14124@end deftypefn
14125
14126@deftypefn {Built-in Function} double __builtin_nans (const char *str)
14127Similar to @code{__builtin_nan}, except the significand is forced
14128to be a signaling NaN@.  The @code{nans} function is proposed by
14129@uref{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n965.htm,,WG14 N965}.
14130@end deftypefn
14131
14132@deftypefn {Built-in Function} _Decimal32 __builtin_nansd32 (const char *str)
14133Similar to @code{__builtin_nans}, except the return type is @code{_Decimal32}.
14134@end deftypefn
14135
14136@deftypefn {Built-in Function} _Decimal64 __builtin_nansd64 (const char *str)
14137Similar to @code{__builtin_nans}, except the return type is @code{_Decimal64}.
14138@end deftypefn
14139
14140@deftypefn {Built-in Function} _Decimal128 __builtin_nansd128 (const char *str)
14141Similar to @code{__builtin_nans}, except the return type is @code{_Decimal128}.
14142@end deftypefn
14143
14144@deftypefn {Built-in Function} float __builtin_nansf (const char *str)
14145Similar to @code{__builtin_nans}, except the return type is @code{float}.
14146@end deftypefn
14147
14148@deftypefn {Built-in Function} {long double} __builtin_nansl (const char *str)
14149Similar to @code{__builtin_nans}, except the return type is @code{long double}.
14150@end deftypefn
14151
14152@deftypefn {Built-in Function} _Float@var{n} __builtin_nansf@var{n} (const char *str)
14153Similar to @code{__builtin_nans}, except the return type is
14154@code{_Float@var{n}}.
14155@end deftypefn
14156
14157@deftypefn {Built-in Function} _Float@var{n}x __builtin_nansf@var{n}x (const char *str)
14158Similar to @code{__builtin_nans}, except the return type is
14159@code{_Float@var{n}x}.
14160@end deftypefn
14161
14162@deftypefn {Built-in Function} int __builtin_ffs (int x)
14163Returns one plus the index of the least significant 1-bit of @var{x}, or
14164if @var{x} is zero, returns zero.
14165@end deftypefn
14166
14167@deftypefn {Built-in Function} int __builtin_clz (unsigned int x)
14168Returns the number of leading 0-bits in @var{x}, starting at the most
14169significant bit position.  If @var{x} is 0, the result is undefined.
14170@end deftypefn
14171
14172@deftypefn {Built-in Function} int __builtin_ctz (unsigned int x)
14173Returns the number of trailing 0-bits in @var{x}, starting at the least
14174significant bit position.  If @var{x} is 0, the result is undefined.
14175@end deftypefn
14176
14177@deftypefn {Built-in Function} int __builtin_clrsb (int x)
14178Returns the number of leading redundant sign bits in @var{x}, i.e.@: the
14179number of bits following the most significant bit that are identical
14180to it.  There are no special cases for 0 or other values.
14181@end deftypefn
14182
14183@deftypefn {Built-in Function} int __builtin_popcount (unsigned int x)
14184Returns the number of 1-bits in @var{x}.
14185@end deftypefn
14186
14187@deftypefn {Built-in Function} int __builtin_parity (unsigned int x)
14188Returns the parity of @var{x}, i.e.@: the number of 1-bits in @var{x}
14189modulo 2.
14190@end deftypefn
14191
14192@deftypefn {Built-in Function} int __builtin_ffsl (long)
14193Similar to @code{__builtin_ffs}, except the argument type is
14194@code{long}.
14195@end deftypefn
14196
14197@deftypefn {Built-in Function} int __builtin_clzl (unsigned long)
14198Similar to @code{__builtin_clz}, except the argument type is
14199@code{unsigned long}.
14200@end deftypefn
14201
14202@deftypefn {Built-in Function} int __builtin_ctzl (unsigned long)
14203Similar to @code{__builtin_ctz}, except the argument type is
14204@code{unsigned long}.
14205@end deftypefn
14206
14207@deftypefn {Built-in Function} int __builtin_clrsbl (long)
14208Similar to @code{__builtin_clrsb}, except the argument type is
14209@code{long}.
14210@end deftypefn
14211
14212@deftypefn {Built-in Function} int __builtin_popcountl (unsigned long)
14213Similar to @code{__builtin_popcount}, except the argument type is
14214@code{unsigned long}.
14215@end deftypefn
14216
14217@deftypefn {Built-in Function} int __builtin_parityl (unsigned long)
14218Similar to @code{__builtin_parity}, except the argument type is
14219@code{unsigned long}.
14220@end deftypefn
14221
14222@deftypefn {Built-in Function} int __builtin_ffsll (long long)
14223Similar to @code{__builtin_ffs}, except the argument type is
14224@code{long long}.
14225@end deftypefn
14226
14227@deftypefn {Built-in Function} int __builtin_clzll (unsigned long long)
14228Similar to @code{__builtin_clz}, except the argument type is
14229@code{unsigned long long}.
14230@end deftypefn
14231
14232@deftypefn {Built-in Function} int __builtin_ctzll (unsigned long long)
14233Similar to @code{__builtin_ctz}, except the argument type is
14234@code{unsigned long long}.
14235@end deftypefn
14236
14237@deftypefn {Built-in Function} int __builtin_clrsbll (long long)
14238Similar to @code{__builtin_clrsb}, except the argument type is
14239@code{long long}.
14240@end deftypefn
14241
14242@deftypefn {Built-in Function} int __builtin_popcountll (unsigned long long)
14243Similar to @code{__builtin_popcount}, except the argument type is
14244@code{unsigned long long}.
14245@end deftypefn
14246
14247@deftypefn {Built-in Function} int __builtin_parityll (unsigned long long)
14248Similar to @code{__builtin_parity}, except the argument type is
14249@code{unsigned long long}.
14250@end deftypefn
14251
14252@deftypefn {Built-in Function} double __builtin_powi (double, int)
14253Returns the first argument raised to the power of the second.  Unlike the
14254@code{pow} function no guarantees about precision and rounding are made.
14255@end deftypefn
14256
14257@deftypefn {Built-in Function} float __builtin_powif (float, int)
14258Similar to @code{__builtin_powi}, except the argument and return types
14259are @code{float}.
14260@end deftypefn
14261
14262@deftypefn {Built-in Function} {long double} __builtin_powil (long double, int)
14263Similar to @code{__builtin_powi}, except the argument and return types
14264are @code{long double}.
14265@end deftypefn
14266
14267@deftypefn {Built-in Function} uint16_t __builtin_bswap16 (uint16_t x)
14268Returns @var{x} with the order of the bytes reversed; for example,
14269@code{0xaabb} becomes @code{0xbbaa}.  Byte here always means
14270exactly 8 bits.
14271@end deftypefn
14272
14273@deftypefn {Built-in Function} uint32_t __builtin_bswap32 (uint32_t x)
14274Similar to @code{__builtin_bswap16}, except the argument and return types
14275are 32-bit.
14276@end deftypefn
14277
14278@deftypefn {Built-in Function} uint64_t __builtin_bswap64 (uint64_t x)
14279Similar to @code{__builtin_bswap32}, except the argument and return types
14280are 64-bit.
14281@end deftypefn
14282
14283@deftypefn {Built-in Function} uint128_t __builtin_bswap128 (uint128_t x)
14284Similar to @code{__builtin_bswap64}, except the argument and return types
14285are 128-bit.  Only supported on targets when 128-bit types are supported.
14286@end deftypefn
14287
14288
14289@deftypefn {Built-in Function} Pmode __builtin_extend_pointer (void * x)
14290On targets where the user visible pointer size is smaller than the size
14291of an actual hardware address this function returns the extended user
14292pointer.  Targets where this is true included ILP32 mode on x86_64 or
14293Aarch64.  This function is mainly useful when writing inline assembly
14294code.
14295@end deftypefn
14296
14297@deftypefn {Built-in Function} int __builtin_goacc_parlevel_id (int x)
14298Returns the openacc gang, worker or vector id depending on whether @var{x} is
142990, 1 or 2.
14300@end deftypefn
14301
14302@deftypefn {Built-in Function} int __builtin_goacc_parlevel_size (int x)
14303Returns the openacc gang, worker or vector size depending on whether @var{x} is
143040, 1 or 2.
14305@end deftypefn
14306
14307@node Target Builtins
14308@section Built-in Functions Specific to Particular Target Machines
14309
14310On some target machines, GCC supports many built-in functions specific
14311to those machines.  Generally these generate calls to specific machine
14312instructions, but allow the compiler to schedule those calls.
14313
14314@menu
14315* AArch64 Built-in Functions::
14316* Alpha Built-in Functions::
14317* Altera Nios II Built-in Functions::
14318* ARC Built-in Functions::
14319* ARC SIMD Built-in Functions::
14320* ARM iWMMXt Built-in Functions::
14321* ARM C Language Extensions (ACLE)::
14322* ARM Floating Point Status and Control Intrinsics::
14323* ARM ARMv8-M Security Extensions::
14324* AVR Built-in Functions::
14325* Blackfin Built-in Functions::
14326* BPF Built-in Functions::
14327* FR-V Built-in Functions::
14328* MIPS DSP Built-in Functions::
14329* MIPS Paired-Single Support::
14330* MIPS Loongson Built-in Functions::
14331* MIPS SIMD Architecture (MSA) Support::
14332* Other MIPS Built-in Functions::
14333* MSP430 Built-in Functions::
14334* NDS32 Built-in Functions::
14335* picoChip Built-in Functions::
14336* Basic PowerPC Built-in Functions::
14337* PowerPC AltiVec/VSX Built-in Functions::
14338* PowerPC Hardware Transactional Memory Built-in Functions::
14339* PowerPC Atomic Memory Operation Functions::
14340* PowerPC Matrix-Multiply Assist Built-in Functions::
14341* PRU Built-in Functions::
14342* RISC-V Built-in Functions::
14343* RX Built-in Functions::
14344* S/390 System z Built-in Functions::
14345* SH Built-in Functions::
14346* SPARC VIS Built-in Functions::
14347* TI C6X Built-in Functions::
14348* TILE-Gx Built-in Functions::
14349* TILEPro Built-in Functions::
14350* x86 Built-in Functions::
14351* x86 transactional memory intrinsics::
14352* x86 control-flow protection intrinsics::
14353@end menu
14354
14355@node AArch64 Built-in Functions
14356@subsection AArch64 Built-in Functions
14357
14358These built-in functions are available for the AArch64 family of
14359processors.
14360@smallexample
14361unsigned int __builtin_aarch64_get_fpcr ()
14362void __builtin_aarch64_set_fpcr (unsigned int)
14363unsigned int __builtin_aarch64_get_fpsr ()
14364void __builtin_aarch64_set_fpsr (unsigned int)
14365
14366unsigned long long __builtin_aarch64_get_fpcr64 ()
14367void __builtin_aarch64_set_fpcr64 (unsigned long long)
14368unsigned long long __builtin_aarch64_get_fpsr64 ()
14369void __builtin_aarch64_set_fpsr64 (unsigned long long)
14370@end smallexample
14371
14372@node Alpha Built-in Functions
14373@subsection Alpha Built-in Functions
14374
14375These built-in functions are available for the Alpha family of
14376processors, depending on the command-line switches used.
14377
14378The following built-in functions are always available.  They
14379all generate the machine instruction that is part of the name.
14380
14381@smallexample
14382long __builtin_alpha_implver (void)
14383long __builtin_alpha_rpcc (void)
14384long __builtin_alpha_amask (long)
14385long __builtin_alpha_cmpbge (long, long)
14386long __builtin_alpha_extbl (long, long)
14387long __builtin_alpha_extwl (long, long)
14388long __builtin_alpha_extll (long, long)
14389long __builtin_alpha_extql (long, long)
14390long __builtin_alpha_extwh (long, long)
14391long __builtin_alpha_extlh (long, long)
14392long __builtin_alpha_extqh (long, long)
14393long __builtin_alpha_insbl (long, long)
14394long __builtin_alpha_inswl (long, long)
14395long __builtin_alpha_insll (long, long)
14396long __builtin_alpha_insql (long, long)
14397long __builtin_alpha_inswh (long, long)
14398long __builtin_alpha_inslh (long, long)
14399long __builtin_alpha_insqh (long, long)
14400long __builtin_alpha_mskbl (long, long)
14401long __builtin_alpha_mskwl (long, long)
14402long __builtin_alpha_mskll (long, long)
14403long __builtin_alpha_mskql (long, long)
14404long __builtin_alpha_mskwh (long, long)
14405long __builtin_alpha_msklh (long, long)
14406long __builtin_alpha_mskqh (long, long)
14407long __builtin_alpha_umulh (long, long)
14408long __builtin_alpha_zap (long, long)
14409long __builtin_alpha_zapnot (long, long)
14410@end smallexample
14411
14412The following built-in functions are always with @option{-mmax}
14413or @option{-mcpu=@var{cpu}} where @var{cpu} is @code{pca56} or
14414later.  They all generate the machine instruction that is part
14415of the name.
14416
14417@smallexample
14418long __builtin_alpha_pklb (long)
14419long __builtin_alpha_pkwb (long)
14420long __builtin_alpha_unpkbl (long)
14421long __builtin_alpha_unpkbw (long)
14422long __builtin_alpha_minub8 (long, long)
14423long __builtin_alpha_minsb8 (long, long)
14424long __builtin_alpha_minuw4 (long, long)
14425long __builtin_alpha_minsw4 (long, long)
14426long __builtin_alpha_maxub8 (long, long)
14427long __builtin_alpha_maxsb8 (long, long)
14428long __builtin_alpha_maxuw4 (long, long)
14429long __builtin_alpha_maxsw4 (long, long)
14430long __builtin_alpha_perr (long, long)
14431@end smallexample
14432
14433The following built-in functions are always with @option{-mcix}
14434or @option{-mcpu=@var{cpu}} where @var{cpu} is @code{ev67} or
14435later.  They all generate the machine instruction that is part
14436of the name.
14437
14438@smallexample
14439long __builtin_alpha_cttz (long)
14440long __builtin_alpha_ctlz (long)
14441long __builtin_alpha_ctpop (long)
14442@end smallexample
14443
14444The following built-in functions are available on systems that use the OSF/1
14445PALcode.  Normally they invoke the @code{rduniq} and @code{wruniq}
14446PAL calls, but when invoked with @option{-mtls-kernel}, they invoke
14447@code{rdval} and @code{wrval}.
14448
14449@smallexample
14450void *__builtin_thread_pointer (void)
14451void __builtin_set_thread_pointer (void *)
14452@end smallexample
14453
14454@node Altera Nios II Built-in Functions
14455@subsection Altera Nios II Built-in Functions
14456
14457These built-in functions are available for the Altera Nios II
14458family of processors.
14459
14460The following built-in functions are always available.  They
14461all generate the machine instruction that is part of the name.
14462
14463@example
14464int __builtin_ldbio (volatile const void *)
14465int __builtin_ldbuio (volatile const void *)
14466int __builtin_ldhio (volatile const void *)
14467int __builtin_ldhuio (volatile const void *)
14468int __builtin_ldwio (volatile const void *)
14469void __builtin_stbio (volatile void *, int)
14470void __builtin_sthio (volatile void *, int)
14471void __builtin_stwio (volatile void *, int)
14472void __builtin_sync (void)
14473int __builtin_rdctl (int)
14474int __builtin_rdprs (int, int)
14475void __builtin_wrctl (int, int)
14476void __builtin_flushd (volatile void *)
14477void __builtin_flushda (volatile void *)
14478int __builtin_wrpie (int);
14479void __builtin_eni (int);
14480int __builtin_ldex (volatile const void *)
14481int __builtin_stex (volatile void *, int)
14482int __builtin_ldsex (volatile const void *)
14483int __builtin_stsex (volatile void *, int)
14484@end example
14485
14486The following built-in functions are always available.  They
14487all generate a Nios II Custom Instruction. The name of the
14488function represents the types that the function takes and
14489returns. The letter before the @code{n} is the return type
14490or void if absent. The @code{n} represents the first parameter
14491to all the custom instructions, the custom instruction number.
14492The two letters after the @code{n} represent the up to two
14493parameters to the function.
14494
14495The letters represent the following data types:
14496@table @code
14497@item <no letter>
14498@code{void} for return type and no parameter for parameter types.
14499
14500@item i
14501@code{int} for return type and parameter type
14502
14503@item f
14504@code{float} for return type and parameter type
14505
14506@item p
14507@code{void *} for return type and parameter type
14508
14509@end table
14510
14511And the function names are:
14512@example
14513void __builtin_custom_n (void)
14514void __builtin_custom_ni (int)
14515void __builtin_custom_nf (float)
14516void __builtin_custom_np (void *)
14517void __builtin_custom_nii (int, int)
14518void __builtin_custom_nif (int, float)
14519void __builtin_custom_nip (int, void *)
14520void __builtin_custom_nfi (float, int)
14521void __builtin_custom_nff (float, float)
14522void __builtin_custom_nfp (float, void *)
14523void __builtin_custom_npi (void *, int)
14524void __builtin_custom_npf (void *, float)
14525void __builtin_custom_npp (void *, void *)
14526int __builtin_custom_in (void)
14527int __builtin_custom_ini (int)
14528int __builtin_custom_inf (float)
14529int __builtin_custom_inp (void *)
14530int __builtin_custom_inii (int, int)
14531int __builtin_custom_inif (int, float)
14532int __builtin_custom_inip (int, void *)
14533int __builtin_custom_infi (float, int)
14534int __builtin_custom_inff (float, float)
14535int __builtin_custom_infp (float, void *)
14536int __builtin_custom_inpi (void *, int)
14537int __builtin_custom_inpf (void *, float)
14538int __builtin_custom_inpp (void *, void *)
14539float __builtin_custom_fn (void)
14540float __builtin_custom_fni (int)
14541float __builtin_custom_fnf (float)
14542float __builtin_custom_fnp (void *)
14543float __builtin_custom_fnii (int, int)
14544float __builtin_custom_fnif (int, float)
14545float __builtin_custom_fnip (int, void *)
14546float __builtin_custom_fnfi (float, int)
14547float __builtin_custom_fnff (float, float)
14548float __builtin_custom_fnfp (float, void *)
14549float __builtin_custom_fnpi (void *, int)
14550float __builtin_custom_fnpf (void *, float)
14551float __builtin_custom_fnpp (void *, void *)
14552void * __builtin_custom_pn (void)
14553void * __builtin_custom_pni (int)
14554void * __builtin_custom_pnf (float)
14555void * __builtin_custom_pnp (void *)
14556void * __builtin_custom_pnii (int, int)
14557void * __builtin_custom_pnif (int, float)
14558void * __builtin_custom_pnip (int, void *)
14559void * __builtin_custom_pnfi (float, int)
14560void * __builtin_custom_pnff (float, float)
14561void * __builtin_custom_pnfp (float, void *)
14562void * __builtin_custom_pnpi (void *, int)
14563void * __builtin_custom_pnpf (void *, float)
14564void * __builtin_custom_pnpp (void *, void *)
14565@end example
14566
14567@node ARC Built-in Functions
14568@subsection ARC Built-in Functions
14569
14570The following built-in functions are provided for ARC targets.  The
14571built-ins generate the corresponding assembly instructions.  In the
14572examples given below, the generated code often requires an operand or
14573result to be in a register.  Where necessary further code will be
14574generated to ensure this is true, but for brevity this is not
14575described in each case.
14576
14577@emph{Note:} Using a built-in to generate an instruction not supported
14578by a target may cause problems. At present the compiler is not
14579guaranteed to detect such misuse, and as a result an internal compiler
14580error may be generated.
14581
14582@deftypefn {Built-in Function} int __builtin_arc_aligned (void *@var{val}, int @var{alignval})
14583Return 1 if @var{val} is known to have the byte alignment given
14584by @var{alignval}, otherwise return 0.
14585Note that this is different from
14586@smallexample
14587__alignof__(*(char *)@var{val}) >= alignval
14588@end smallexample
14589because __alignof__ sees only the type of the dereference, whereas
14590__builtin_arc_align uses alignment information from the pointer
14591as well as from the pointed-to type.
14592The information available will depend on optimization level.
14593@end deftypefn
14594
14595@deftypefn {Built-in Function} void __builtin_arc_brk (void)
14596Generates
14597@example
14598brk
14599@end example
14600@end deftypefn
14601
14602@deftypefn {Built-in Function} {unsigned int} __builtin_arc_core_read (unsigned int @var{regno})
14603The operand is the number of a register to be read.  Generates:
14604@example
14605mov  @var{dest}, r@var{regno}
14606@end example
14607where the value in @var{dest} will be the result returned from the
14608built-in.
14609@end deftypefn
14610
14611@deftypefn {Built-in Function} void __builtin_arc_core_write (unsigned int @var{regno}, unsigned int @var{val})
14612The first operand is the number of a register to be written, the
14613second operand is a compile time constant to write into that
14614register.  Generates:
14615@example
14616mov  r@var{regno}, @var{val}
14617@end example
14618@end deftypefn
14619
14620@deftypefn {Built-in Function} int __builtin_arc_divaw (int @var{a}, int @var{b})
14621Only available if either @option{-mcpu=ARC700} or @option{-meA} is set.
14622Generates:
14623@example
14624divaw  @var{dest}, @var{a}, @var{b}
14625@end example
14626where the value in @var{dest} will be the result returned from the
14627built-in.
14628@end deftypefn
14629
14630@deftypefn {Built-in Function} void __builtin_arc_flag (unsigned int @var{a})
14631Generates
14632@example
14633flag  @var{a}
14634@end example
14635@end deftypefn
14636
14637@deftypefn {Built-in Function} {unsigned int} __builtin_arc_lr (unsigned int @var{auxr})
14638The operand, @var{auxv}, is the address of an auxiliary register and
14639must be a compile time constant.  Generates:
14640@example
14641lr  @var{dest}, [@var{auxr}]
14642@end example
14643Where the value in @var{dest} will be the result returned from the
14644built-in.
14645@end deftypefn
14646
14647@deftypefn {Built-in Function} void __builtin_arc_mul64 (int @var{a}, int @var{b})
14648Only available with @option{-mmul64}.  Generates:
14649@example
14650mul64  @var{a}, @var{b}
14651@end example
14652@end deftypefn
14653
14654@deftypefn {Built-in Function} void __builtin_arc_mulu64 (unsigned int @var{a}, unsigned int @var{b})
14655Only available with @option{-mmul64}.  Generates:
14656@example
14657mulu64  @var{a}, @var{b}
14658@end example
14659@end deftypefn
14660
14661@deftypefn {Built-in Function} void __builtin_arc_nop (void)
14662Generates:
14663@example
14664nop
14665@end example
14666@end deftypefn
14667
14668@deftypefn {Built-in Function} int __builtin_arc_norm (int @var{src})
14669Only valid if the @samp{norm} instruction is available through the
14670@option{-mnorm} option or by default with @option{-mcpu=ARC700}.
14671Generates:
14672@example
14673norm  @var{dest}, @var{src}
14674@end example
14675Where the value in @var{dest} will be the result returned from the
14676built-in.
14677@end deftypefn
14678
14679@deftypefn {Built-in Function}  {short int} __builtin_arc_normw (short int @var{src})
14680Only valid if the @samp{normw} instruction is available through the
14681@option{-mnorm} option or by default with @option{-mcpu=ARC700}.
14682Generates:
14683@example
14684normw  @var{dest}, @var{src}
14685@end example
14686Where the value in @var{dest} will be the result returned from the
14687built-in.
14688@end deftypefn
14689
14690@deftypefn {Built-in Function}  void __builtin_arc_rtie (void)
14691Generates:
14692@example
14693rtie
14694@end example
14695@end deftypefn
14696
14697@deftypefn {Built-in Function}  void __builtin_arc_sleep (int @var{a}
14698Generates:
14699@example
14700sleep  @var{a}
14701@end example
14702@end deftypefn
14703
14704@deftypefn {Built-in Function}  void __builtin_arc_sr (unsigned int @var{auxr}, unsigned int @var{val})
14705The first argument, @var{auxv}, is the address of an auxiliary
14706register, the second argument, @var{val}, is a compile time constant
14707to be written to the register.  Generates:
14708@example
14709sr  @var{auxr}, [@var{val}]
14710@end example
14711@end deftypefn
14712
14713@deftypefn {Built-in Function}  int __builtin_arc_swap (int @var{src})
14714Only valid with @option{-mswap}.  Generates:
14715@example
14716swap  @var{dest}, @var{src}
14717@end example
14718Where the value in @var{dest} will be the result returned from the
14719built-in.
14720@end deftypefn
14721
14722@deftypefn {Built-in Function}  void __builtin_arc_swi (void)
14723Generates:
14724@example
14725swi
14726@end example
14727@end deftypefn
14728
14729@deftypefn {Built-in Function}  void __builtin_arc_sync (void)
14730Only available with @option{-mcpu=ARC700}.  Generates:
14731@example
14732sync
14733@end example
14734@end deftypefn
14735
14736@deftypefn {Built-in Function}  void __builtin_arc_trap_s (unsigned int @var{c})
14737Only available with @option{-mcpu=ARC700}.  Generates:
14738@example
14739trap_s  @var{c}
14740@end example
14741@end deftypefn
14742
14743@deftypefn {Built-in Function}  void __builtin_arc_unimp_s (void)
14744Only available with @option{-mcpu=ARC700}.  Generates:
14745@example
14746unimp_s
14747@end example
14748@end deftypefn
14749
14750The instructions generated by the following builtins are not
14751considered as candidates for scheduling.  They are not moved around by
14752the compiler during scheduling, and thus can be expected to appear
14753where they are put in the C code:
14754@example
14755__builtin_arc_brk()
14756__builtin_arc_core_read()
14757__builtin_arc_core_write()
14758__builtin_arc_flag()
14759__builtin_arc_lr()
14760__builtin_arc_sleep()
14761__builtin_arc_sr()
14762__builtin_arc_swi()
14763@end example
14764
14765@node ARC SIMD Built-in Functions
14766@subsection ARC SIMD Built-in Functions
14767
14768SIMD builtins provided by the compiler can be used to generate the
14769vector instructions.  This section describes the available builtins
14770and their usage in programs.  With the @option{-msimd} option, the
14771compiler provides 128-bit vector types, which can be specified using
14772the @code{vector_size} attribute.  The header file @file{arc-simd.h}
14773can be included to use the following predefined types:
14774@example
14775typedef int __v4si   __attribute__((vector_size(16)));
14776typedef short __v8hi __attribute__((vector_size(16)));
14777@end example
14778
14779These types can be used to define 128-bit variables.  The built-in
14780functions listed in the following section can be used on these
14781variables to generate the vector operations.
14782
14783For all builtins, @code{__builtin_arc_@var{someinsn}}, the header file
14784@file{arc-simd.h} also provides equivalent macros called
14785@code{_@var{someinsn}} that can be used for programming ease and
14786improved readability.  The following macros for DMA control are also
14787provided:
14788@example
14789#define _setup_dma_in_channel_reg _vdiwr
14790#define _setup_dma_out_channel_reg _vdowr
14791@end example
14792
14793The following is a complete list of all the SIMD built-ins provided
14794for ARC, grouped by calling signature.
14795
14796The following take two @code{__v8hi} arguments and return a
14797@code{__v8hi} result:
14798@example
14799__v8hi __builtin_arc_vaddaw (__v8hi, __v8hi)
14800__v8hi __builtin_arc_vaddw (__v8hi, __v8hi)
14801__v8hi __builtin_arc_vand (__v8hi, __v8hi)
14802__v8hi __builtin_arc_vandaw (__v8hi, __v8hi)
14803__v8hi __builtin_arc_vavb (__v8hi, __v8hi)
14804__v8hi __builtin_arc_vavrb (__v8hi, __v8hi)
14805__v8hi __builtin_arc_vbic (__v8hi, __v8hi)
14806__v8hi __builtin_arc_vbicaw (__v8hi, __v8hi)
14807__v8hi __builtin_arc_vdifaw (__v8hi, __v8hi)
14808__v8hi __builtin_arc_vdifw (__v8hi, __v8hi)
14809__v8hi __builtin_arc_veqw (__v8hi, __v8hi)
14810__v8hi __builtin_arc_vh264f (__v8hi, __v8hi)
14811__v8hi __builtin_arc_vh264ft (__v8hi, __v8hi)
14812__v8hi __builtin_arc_vh264fw (__v8hi, __v8hi)
14813__v8hi __builtin_arc_vlew (__v8hi, __v8hi)
14814__v8hi __builtin_arc_vltw (__v8hi, __v8hi)
14815__v8hi __builtin_arc_vmaxaw (__v8hi, __v8hi)
14816__v8hi __builtin_arc_vmaxw (__v8hi, __v8hi)
14817__v8hi __builtin_arc_vminaw (__v8hi, __v8hi)
14818__v8hi __builtin_arc_vminw (__v8hi, __v8hi)
14819__v8hi __builtin_arc_vmr1aw (__v8hi, __v8hi)
14820__v8hi __builtin_arc_vmr1w (__v8hi, __v8hi)
14821__v8hi __builtin_arc_vmr2aw (__v8hi, __v8hi)
14822__v8hi __builtin_arc_vmr2w (__v8hi, __v8hi)
14823__v8hi __builtin_arc_vmr3aw (__v8hi, __v8hi)
14824__v8hi __builtin_arc_vmr3w (__v8hi, __v8hi)
14825__v8hi __builtin_arc_vmr4aw (__v8hi, __v8hi)
14826__v8hi __builtin_arc_vmr4w (__v8hi, __v8hi)
14827__v8hi __builtin_arc_vmr5aw (__v8hi, __v8hi)
14828__v8hi __builtin_arc_vmr5w (__v8hi, __v8hi)
14829__v8hi __builtin_arc_vmr6aw (__v8hi, __v8hi)
14830__v8hi __builtin_arc_vmr6w (__v8hi, __v8hi)
14831__v8hi __builtin_arc_vmr7aw (__v8hi, __v8hi)
14832__v8hi __builtin_arc_vmr7w (__v8hi, __v8hi)
14833__v8hi __builtin_arc_vmrb (__v8hi, __v8hi)
14834__v8hi __builtin_arc_vmulaw (__v8hi, __v8hi)
14835__v8hi __builtin_arc_vmulfaw (__v8hi, __v8hi)
14836__v8hi __builtin_arc_vmulfw (__v8hi, __v8hi)
14837__v8hi __builtin_arc_vmulw (__v8hi, __v8hi)
14838__v8hi __builtin_arc_vnew (__v8hi, __v8hi)
14839__v8hi __builtin_arc_vor (__v8hi, __v8hi)
14840__v8hi __builtin_arc_vsubaw (__v8hi, __v8hi)
14841__v8hi __builtin_arc_vsubw (__v8hi, __v8hi)
14842__v8hi __builtin_arc_vsummw (__v8hi, __v8hi)
14843__v8hi __builtin_arc_vvc1f (__v8hi, __v8hi)
14844__v8hi __builtin_arc_vvc1ft (__v8hi, __v8hi)
14845__v8hi __builtin_arc_vxor (__v8hi, __v8hi)
14846__v8hi __builtin_arc_vxoraw (__v8hi, __v8hi)
14847@end example
14848
14849The following take one @code{__v8hi} and one @code{int} argument and return a
14850@code{__v8hi} result:
14851
14852@example
14853__v8hi __builtin_arc_vbaddw (__v8hi, int)
14854__v8hi __builtin_arc_vbmaxw (__v8hi, int)
14855__v8hi __builtin_arc_vbminw (__v8hi, int)
14856__v8hi __builtin_arc_vbmulaw (__v8hi, int)
14857__v8hi __builtin_arc_vbmulfw (__v8hi, int)
14858__v8hi __builtin_arc_vbmulw (__v8hi, int)
14859__v8hi __builtin_arc_vbrsubw (__v8hi, int)
14860__v8hi __builtin_arc_vbsubw (__v8hi, int)
14861@end example
14862
14863The following take one @code{__v8hi} argument and one @code{int} argument which
14864must be a 3-bit compile time constant indicating a register number
14865I0-I7.  They return a @code{__v8hi} result.
14866@example
14867__v8hi __builtin_arc_vasrw (__v8hi, const int)
14868__v8hi __builtin_arc_vsr8 (__v8hi, const int)
14869__v8hi __builtin_arc_vsr8aw (__v8hi, const int)
14870@end example
14871
14872The following take one @code{__v8hi} argument and one @code{int}
14873argument which must be a 6-bit compile time constant.  They return a
14874@code{__v8hi} result.
14875@example
14876__v8hi __builtin_arc_vasrpwbi (__v8hi, const int)
14877__v8hi __builtin_arc_vasrrpwbi (__v8hi, const int)
14878__v8hi __builtin_arc_vasrrwi (__v8hi, const int)
14879__v8hi __builtin_arc_vasrsrwi (__v8hi, const int)
14880__v8hi __builtin_arc_vasrwi (__v8hi, const int)
14881__v8hi __builtin_arc_vsr8awi (__v8hi, const int)
14882__v8hi __builtin_arc_vsr8i (__v8hi, const int)
14883@end example
14884
14885The following take one @code{__v8hi} argument and one @code{int} argument which
14886must be a 8-bit compile time constant.  They return a @code{__v8hi}
14887result.
14888@example
14889__v8hi __builtin_arc_vd6tapf (__v8hi, const int)
14890__v8hi __builtin_arc_vmvaw (__v8hi, const int)
14891__v8hi __builtin_arc_vmvw (__v8hi, const int)
14892__v8hi __builtin_arc_vmvzw (__v8hi, const int)
14893@end example
14894
14895The following take two @code{int} arguments, the second of which which
14896must be a 8-bit compile time constant.  They return a @code{__v8hi}
14897result:
14898@example
14899__v8hi __builtin_arc_vmovaw (int, const int)
14900__v8hi __builtin_arc_vmovw (int, const int)
14901__v8hi __builtin_arc_vmovzw (int, const int)
14902@end example
14903
14904The following take a single @code{__v8hi} argument and return a
14905@code{__v8hi} result:
14906@example
14907__v8hi __builtin_arc_vabsaw (__v8hi)
14908__v8hi __builtin_arc_vabsw (__v8hi)
14909__v8hi __builtin_arc_vaddsuw (__v8hi)
14910__v8hi __builtin_arc_vexch1 (__v8hi)
14911__v8hi __builtin_arc_vexch2 (__v8hi)
14912__v8hi __builtin_arc_vexch4 (__v8hi)
14913__v8hi __builtin_arc_vsignw (__v8hi)
14914__v8hi __builtin_arc_vupbaw (__v8hi)
14915__v8hi __builtin_arc_vupbw (__v8hi)
14916__v8hi __builtin_arc_vupsbaw (__v8hi)
14917__v8hi __builtin_arc_vupsbw (__v8hi)
14918@end example
14919
14920The following take two @code{int} arguments and return no result:
14921@example
14922void __builtin_arc_vdirun (int, int)
14923void __builtin_arc_vdorun (int, int)
14924@end example
14925
14926The following take two @code{int} arguments and return no result.  The
14927first argument must a 3-bit compile time constant indicating one of
14928the DR0-DR7 DMA setup channels:
14929@example
14930void __builtin_arc_vdiwr (const int, int)
14931void __builtin_arc_vdowr (const int, int)
14932@end example
14933
14934The following take an @code{int} argument and return no result:
14935@example
14936void __builtin_arc_vendrec (int)
14937void __builtin_arc_vrec (int)
14938void __builtin_arc_vrecrun (int)
14939void __builtin_arc_vrun (int)
14940@end example
14941
14942The following take a @code{__v8hi} argument and two @code{int}
14943arguments and return a @code{__v8hi} result.  The second argument must
14944be a 3-bit compile time constants, indicating one the registers I0-I7,
14945and the third argument must be an 8-bit compile time constant.
14946
14947@emph{Note:} Although the equivalent hardware instructions do not take
14948an SIMD register as an operand, these builtins overwrite the relevant
14949bits of the @code{__v8hi} register provided as the first argument with
14950the value loaded from the @code{[Ib, u8]} location in the SDM.
14951
14952@example
14953__v8hi __builtin_arc_vld32 (__v8hi, const int, const int)
14954__v8hi __builtin_arc_vld32wh (__v8hi, const int, const int)
14955__v8hi __builtin_arc_vld32wl (__v8hi, const int, const int)
14956__v8hi __builtin_arc_vld64 (__v8hi, const int, const int)
14957@end example
14958
14959The following take two @code{int} arguments and return a @code{__v8hi}
14960result.  The first argument must be a 3-bit compile time constants,
14961indicating one the registers I0-I7, and the second argument must be an
149628-bit compile time constant.
14963
14964@example
14965__v8hi __builtin_arc_vld128 (const int, const int)
14966__v8hi __builtin_arc_vld64w (const int, const int)
14967@end example
14968
14969The following take a @code{__v8hi} argument and two @code{int}
14970arguments and return no result.  The second argument must be a 3-bit
14971compile time constants, indicating one the registers I0-I7, and the
14972third argument must be an 8-bit compile time constant.
14973
14974@example
14975void __builtin_arc_vst128 (__v8hi, const int, const int)
14976void __builtin_arc_vst64 (__v8hi, const int, const int)
14977@end example
14978
14979The following take a @code{__v8hi} argument and three @code{int}
14980arguments and return no result.  The second argument must be a 3-bit
14981compile-time constant, identifying the 16-bit sub-register to be
14982stored, the third argument must be a 3-bit compile time constants,
14983indicating one the registers I0-I7, and the fourth argument must be an
149848-bit compile time constant.
14985
14986@example
14987void __builtin_arc_vst16_n (__v8hi, const int, const int, const int)
14988void __builtin_arc_vst32_n (__v8hi, const int, const int, const int)
14989@end example
14990
14991@node ARM iWMMXt Built-in Functions
14992@subsection ARM iWMMXt Built-in Functions
14993
14994These built-in functions are available for the ARM family of
14995processors when the @option{-mcpu=iwmmxt} switch is used:
14996
14997@smallexample
14998typedef int v2si __attribute__ ((vector_size (8)));
14999typedef short v4hi __attribute__ ((vector_size (8)));
15000typedef char v8qi __attribute__ ((vector_size (8)));
15001
15002int __builtin_arm_getwcgr0 (void)
15003void __builtin_arm_setwcgr0 (int)
15004int __builtin_arm_getwcgr1 (void)
15005void __builtin_arm_setwcgr1 (int)
15006int __builtin_arm_getwcgr2 (void)
15007void __builtin_arm_setwcgr2 (int)
15008int __builtin_arm_getwcgr3 (void)
15009void __builtin_arm_setwcgr3 (int)
15010int __builtin_arm_textrmsb (v8qi, int)
15011int __builtin_arm_textrmsh (v4hi, int)
15012int __builtin_arm_textrmsw (v2si, int)
15013int __builtin_arm_textrmub (v8qi, int)
15014int __builtin_arm_textrmuh (v4hi, int)
15015int __builtin_arm_textrmuw (v2si, int)
15016v8qi __builtin_arm_tinsrb (v8qi, int, int)
15017v4hi __builtin_arm_tinsrh (v4hi, int, int)
15018v2si __builtin_arm_tinsrw (v2si, int, int)
15019long long __builtin_arm_tmia (long long, int, int)
15020long long __builtin_arm_tmiabb (long long, int, int)
15021long long __builtin_arm_tmiabt (long long, int, int)
15022long long __builtin_arm_tmiaph (long long, int, int)
15023long long __builtin_arm_tmiatb (long long, int, int)
15024long long __builtin_arm_tmiatt (long long, int, int)
15025int __builtin_arm_tmovmskb (v8qi)
15026int __builtin_arm_tmovmskh (v4hi)
15027int __builtin_arm_tmovmskw (v2si)
15028long long __builtin_arm_waccb (v8qi)
15029long long __builtin_arm_wacch (v4hi)
15030long long __builtin_arm_waccw (v2si)
15031v8qi __builtin_arm_waddb (v8qi, v8qi)
15032v8qi __builtin_arm_waddbss (v8qi, v8qi)
15033v8qi __builtin_arm_waddbus (v8qi, v8qi)
15034v4hi __builtin_arm_waddh (v4hi, v4hi)
15035v4hi __builtin_arm_waddhss (v4hi, v4hi)
15036v4hi __builtin_arm_waddhus (v4hi, v4hi)
15037v2si __builtin_arm_waddw (v2si, v2si)
15038v2si __builtin_arm_waddwss (v2si, v2si)
15039v2si __builtin_arm_waddwus (v2si, v2si)
15040v8qi __builtin_arm_walign (v8qi, v8qi, int)
15041long long __builtin_arm_wand(long long, long long)
15042long long __builtin_arm_wandn (long long, long long)
15043v8qi __builtin_arm_wavg2b (v8qi, v8qi)
15044v8qi __builtin_arm_wavg2br (v8qi, v8qi)
15045v4hi __builtin_arm_wavg2h (v4hi, v4hi)
15046v4hi __builtin_arm_wavg2hr (v4hi, v4hi)
15047v8qi __builtin_arm_wcmpeqb (v8qi, v8qi)
15048v4hi __builtin_arm_wcmpeqh (v4hi, v4hi)
15049v2si __builtin_arm_wcmpeqw (v2si, v2si)
15050v8qi __builtin_arm_wcmpgtsb (v8qi, v8qi)
15051v4hi __builtin_arm_wcmpgtsh (v4hi, v4hi)
15052v2si __builtin_arm_wcmpgtsw (v2si, v2si)
15053v8qi __builtin_arm_wcmpgtub (v8qi, v8qi)
15054v4hi __builtin_arm_wcmpgtuh (v4hi, v4hi)
15055v2si __builtin_arm_wcmpgtuw (v2si, v2si)
15056long long __builtin_arm_wmacs (long long, v4hi, v4hi)
15057long long __builtin_arm_wmacsz (v4hi, v4hi)
15058long long __builtin_arm_wmacu (long long, v4hi, v4hi)
15059long long __builtin_arm_wmacuz (v4hi, v4hi)
15060v4hi __builtin_arm_wmadds (v4hi, v4hi)
15061v4hi __builtin_arm_wmaddu (v4hi, v4hi)
15062v8qi __builtin_arm_wmaxsb (v8qi, v8qi)
15063v4hi __builtin_arm_wmaxsh (v4hi, v4hi)
15064v2si __builtin_arm_wmaxsw (v2si, v2si)
15065v8qi __builtin_arm_wmaxub (v8qi, v8qi)
15066v4hi __builtin_arm_wmaxuh (v4hi, v4hi)
15067v2si __builtin_arm_wmaxuw (v2si, v2si)
15068v8qi __builtin_arm_wminsb (v8qi, v8qi)
15069v4hi __builtin_arm_wminsh (v4hi, v4hi)
15070v2si __builtin_arm_wminsw (v2si, v2si)
15071v8qi __builtin_arm_wminub (v8qi, v8qi)
15072v4hi __builtin_arm_wminuh (v4hi, v4hi)
15073v2si __builtin_arm_wminuw (v2si, v2si)
15074v4hi __builtin_arm_wmulsm (v4hi, v4hi)
15075v4hi __builtin_arm_wmulul (v4hi, v4hi)
15076v4hi __builtin_arm_wmulum (v4hi, v4hi)
15077long long __builtin_arm_wor (long long, long long)
15078v2si __builtin_arm_wpackdss (long long, long long)
15079v2si __builtin_arm_wpackdus (long long, long long)
15080v8qi __builtin_arm_wpackhss (v4hi, v4hi)
15081v8qi __builtin_arm_wpackhus (v4hi, v4hi)
15082v4hi __builtin_arm_wpackwss (v2si, v2si)
15083v4hi __builtin_arm_wpackwus (v2si, v2si)
15084long long __builtin_arm_wrord (long long, long long)
15085long long __builtin_arm_wrordi (long long, int)
15086v4hi __builtin_arm_wrorh (v4hi, long long)
15087v4hi __builtin_arm_wrorhi (v4hi, int)
15088v2si __builtin_arm_wrorw (v2si, long long)
15089v2si __builtin_arm_wrorwi (v2si, int)
15090v2si __builtin_arm_wsadb (v2si, v8qi, v8qi)
15091v2si __builtin_arm_wsadbz (v8qi, v8qi)
15092v2si __builtin_arm_wsadh (v2si, v4hi, v4hi)
15093v2si __builtin_arm_wsadhz (v4hi, v4hi)
15094v4hi __builtin_arm_wshufh (v4hi, int)
15095long long __builtin_arm_wslld (long long, long long)
15096long long __builtin_arm_wslldi (long long, int)
15097v4hi __builtin_arm_wsllh (v4hi, long long)
15098v4hi __builtin_arm_wsllhi (v4hi, int)
15099v2si __builtin_arm_wsllw (v2si, long long)
15100v2si __builtin_arm_wsllwi (v2si, int)
15101long long __builtin_arm_wsrad (long long, long long)
15102long long __builtin_arm_wsradi (long long, int)
15103v4hi __builtin_arm_wsrah (v4hi, long long)
15104v4hi __builtin_arm_wsrahi (v4hi, int)
15105v2si __builtin_arm_wsraw (v2si, long long)
15106v2si __builtin_arm_wsrawi (v2si, int)
15107long long __builtin_arm_wsrld (long long, long long)
15108long long __builtin_arm_wsrldi (long long, int)
15109v4hi __builtin_arm_wsrlh (v4hi, long long)
15110v4hi __builtin_arm_wsrlhi (v4hi, int)
15111v2si __builtin_arm_wsrlw (v2si, long long)
15112v2si __builtin_arm_wsrlwi (v2si, int)
15113v8qi __builtin_arm_wsubb (v8qi, v8qi)
15114v8qi __builtin_arm_wsubbss (v8qi, v8qi)
15115v8qi __builtin_arm_wsubbus (v8qi, v8qi)
15116v4hi __builtin_arm_wsubh (v4hi, v4hi)
15117v4hi __builtin_arm_wsubhss (v4hi, v4hi)
15118v4hi __builtin_arm_wsubhus (v4hi, v4hi)
15119v2si __builtin_arm_wsubw (v2si, v2si)
15120v2si __builtin_arm_wsubwss (v2si, v2si)
15121v2si __builtin_arm_wsubwus (v2si, v2si)
15122v4hi __builtin_arm_wunpckehsb (v8qi)
15123v2si __builtin_arm_wunpckehsh (v4hi)
15124long long __builtin_arm_wunpckehsw (v2si)
15125v4hi __builtin_arm_wunpckehub (v8qi)
15126v2si __builtin_arm_wunpckehuh (v4hi)
15127long long __builtin_arm_wunpckehuw (v2si)
15128v4hi __builtin_arm_wunpckelsb (v8qi)
15129v2si __builtin_arm_wunpckelsh (v4hi)
15130long long __builtin_arm_wunpckelsw (v2si)
15131v4hi __builtin_arm_wunpckelub (v8qi)
15132v2si __builtin_arm_wunpckeluh (v4hi)
15133long long __builtin_arm_wunpckeluw (v2si)
15134v8qi __builtin_arm_wunpckihb (v8qi, v8qi)
15135v4hi __builtin_arm_wunpckihh (v4hi, v4hi)
15136v2si __builtin_arm_wunpckihw (v2si, v2si)
15137v8qi __builtin_arm_wunpckilb (v8qi, v8qi)
15138v4hi __builtin_arm_wunpckilh (v4hi, v4hi)
15139v2si __builtin_arm_wunpckilw (v2si, v2si)
15140long long __builtin_arm_wxor (long long, long long)
15141long long __builtin_arm_wzero ()
15142@end smallexample
15143
15144
15145@node ARM C Language Extensions (ACLE)
15146@subsection ARM C Language Extensions (ACLE)
15147
15148GCC implements extensions for C as described in the ARM C Language
15149Extensions (ACLE) specification, which can be found at
15150@uref{https://developer.arm.com/documentation/ihi0053/latest/}.
15151
15152As a part of ACLE, GCC implements extensions for Advanced SIMD as described in
15153the ARM C Language Extensions Specification.  The complete list of Advanced SIMD
15154intrinsics can be found at
15155@uref{https://developer.arm.com/documentation/ihi0073/latest/}.
15156The built-in intrinsics for the Advanced SIMD extension are available when
15157NEON is enabled.
15158
15159Currently, ARM and AArch64 back ends do not support ACLE 2.0 fully.  Both
15160back ends support CRC32 intrinsics and the ARM back end supports the
15161Coprocessor intrinsics, all from @file{arm_acle.h}.  The ARM back end's 16-bit
15162floating-point Advanced SIMD intrinsics currently comply to ACLE v1.1.
15163AArch64's back end does not have support for 16-bit floating point Advanced SIMD
15164intrinsics yet.
15165
15166See @ref{ARM Options} and @ref{AArch64 Options} for more information on the
15167availability of extensions.
15168
15169@node ARM Floating Point Status and Control Intrinsics
15170@subsection ARM Floating Point Status and Control Intrinsics
15171
15172These built-in functions are available for the ARM family of
15173processors with floating-point unit.
15174
15175@smallexample
15176unsigned int __builtin_arm_get_fpscr ()
15177void __builtin_arm_set_fpscr (unsigned int)
15178@end smallexample
15179
15180@node ARM ARMv8-M Security Extensions
15181@subsection ARM ARMv8-M Security Extensions
15182
15183GCC implements the ARMv8-M Security Extensions as described in the ARMv8-M
15184Security Extensions: Requirements on Development Tools Engineering
15185Specification, which can be found at
15186@uref{https://developer.arm.com/documentation/ecm0359818/latest/}.
15187
15188As part of the Security Extensions GCC implements two new function attributes:
15189@code{cmse_nonsecure_entry} and @code{cmse_nonsecure_call}.
15190
15191As part of the Security Extensions GCC implements the intrinsics below.  FPTR
15192is used here to mean any function pointer type.
15193
15194@smallexample
15195cmse_address_info_t cmse_TT (void *)
15196cmse_address_info_t cmse_TT_fptr (FPTR)
15197cmse_address_info_t cmse_TTT (void *)
15198cmse_address_info_t cmse_TTT_fptr (FPTR)
15199cmse_address_info_t cmse_TTA (void *)
15200cmse_address_info_t cmse_TTA_fptr (FPTR)
15201cmse_address_info_t cmse_TTAT (void *)
15202cmse_address_info_t cmse_TTAT_fptr (FPTR)
15203void * cmse_check_address_range (void *, size_t, int)
15204typeof(p) cmse_nsfptr_create (FPTR p)
15205intptr_t cmse_is_nsfptr (FPTR)
15206int cmse_nonsecure_caller (void)
15207@end smallexample
15208
15209@node AVR Built-in Functions
15210@subsection AVR Built-in Functions
15211
15212For each built-in function for AVR, there is an equally named,
15213uppercase built-in macro defined. That way users can easily query if
15214or if not a specific built-in is implemented or not. For example, if
15215@code{__builtin_avr_nop} is available the macro
15216@code{__BUILTIN_AVR_NOP} is defined to @code{1} and undefined otherwise.
15217
15218@table @code
15219
15220@item void __builtin_avr_nop (void)
15221@itemx void __builtin_avr_sei (void)
15222@itemx void __builtin_avr_cli (void)
15223@itemx void __builtin_avr_sleep (void)
15224@itemx void __builtin_avr_wdr (void)
15225@itemx unsigned char __builtin_avr_swap (unsigned char)
15226@itemx unsigned int __builtin_avr_fmul (unsigned char, unsigned char)
15227@itemx int __builtin_avr_fmuls (char, char)
15228@itemx int __builtin_avr_fmulsu (char, unsigned char)
15229These built-in functions map to the respective machine
15230instruction, i.e.@: @code{nop}, @code{sei}, @code{cli}, @code{sleep},
15231@code{wdr}, @code{swap}, @code{fmul}, @code{fmuls}
15232resp. @code{fmulsu}. The three @code{fmul*} built-ins are implemented
15233as library call if no hardware multiplier is available.
15234
15235@item void __builtin_avr_delay_cycles (unsigned long ticks)
15236Delay execution for @var{ticks} cycles. Note that this
15237built-in does not take into account the effect of interrupts that
15238might increase delay time. @var{ticks} must be a compile-time
15239integer constant; delays with a variable number of cycles are not supported.
15240
15241@item char __builtin_avr_flash_segment (const __memx void*)
15242This built-in takes a byte address to the 24-bit
15243@ref{AVR Named Address Spaces,address space} @code{__memx} and returns
15244the number of the flash segment (the 64 KiB chunk) where the address
15245points to.  Counting starts at @code{0}.
15246If the address does not point to flash memory, return @code{-1}.
15247
15248@item uint8_t __builtin_avr_insert_bits (uint32_t map, uint8_t bits, uint8_t val)
15249Insert bits from @var{bits} into @var{val} and return the resulting
15250value. The nibbles of @var{map} determine how the insertion is
15251performed: Let @var{X} be the @var{n}-th nibble of @var{map}
15252@enumerate
15253@item If @var{X} is @code{0xf},
15254then the @var{n}-th bit of @var{val} is returned unaltered.
15255
15256@item If X is in the range 0@dots{}7,
15257then the @var{n}-th result bit is set to the @var{X}-th bit of @var{bits}
15258
15259@item If X is in the range 8@dots{}@code{0xe},
15260then the @var{n}-th result bit is undefined.
15261@end enumerate
15262
15263@noindent
15264One typical use case for this built-in is adjusting input and
15265output values to non-contiguous port layouts. Some examples:
15266
15267@smallexample
15268// same as val, bits is unused
15269__builtin_avr_insert_bits (0xffffffff, bits, val)
15270@end smallexample
15271
15272@smallexample
15273// same as bits, val is unused
15274__builtin_avr_insert_bits (0x76543210, bits, val)
15275@end smallexample
15276
15277@smallexample
15278// same as rotating bits by 4
15279__builtin_avr_insert_bits (0x32107654, bits, 0)
15280@end smallexample
15281
15282@smallexample
15283// high nibble of result is the high nibble of val
15284// low nibble of result is the low nibble of bits
15285__builtin_avr_insert_bits (0xffff3210, bits, val)
15286@end smallexample
15287
15288@smallexample
15289// reverse the bit order of bits
15290__builtin_avr_insert_bits (0x01234567, bits, 0)
15291@end smallexample
15292
15293@item void __builtin_avr_nops (unsigned count)
15294Insert @var{count} @code{NOP} instructions.
15295The number of instructions must be a compile-time integer constant.
15296
15297@end table
15298
15299@noindent
15300There are many more AVR-specific built-in functions that are used to
15301implement the ISO/IEC TR 18037 ``Embedded C'' fixed-point functions of
15302section 7.18a.6.  You don't need to use these built-ins directly.
15303Instead, use the declarations as supplied by the @code{stdfix.h} header
15304with GNU-C99:
15305
15306@smallexample
15307#include <stdfix.h>
15308
15309// Re-interpret the bit representation of unsigned 16-bit
15310// integer @var{uval} as Q-format 0.16 value.
15311unsigned fract get_bits (uint_ur_t uval)
15312@{
15313    return urbits (uval);
15314@}
15315@end smallexample
15316
15317@node Blackfin Built-in Functions
15318@subsection Blackfin Built-in Functions
15319
15320Currently, there are two Blackfin-specific built-in functions.  These are
15321used for generating @code{CSYNC} and @code{SSYNC} machine insns without
15322using inline assembly; by using these built-in functions the compiler can
15323automatically add workarounds for hardware errata involving these
15324instructions.  These functions are named as follows:
15325
15326@smallexample
15327void __builtin_bfin_csync (void)
15328void __builtin_bfin_ssync (void)
15329@end smallexample
15330
15331@node BPF Built-in Functions
15332@subsection BPF Built-in Functions
15333
15334The following built-in functions are available for eBPF targets.
15335
15336@deftypefn {Built-in Function} unsigned long long __builtin_bpf_load_byte (unsigned long long @var{offset})
15337Load a byte from the @code{struct sk_buff} packet data pointed by the register @code{%r6} and return it.
15338@end deftypefn
15339
15340@deftypefn {Built-in Function} unsigned long long __builtin_bpf_load_half (unsigned long long @var{offset})
15341Load 16-bits from the @code{struct sk_buff} packet data pointed by the register @code{%r6} and return it.
15342@end deftypefn
15343
15344@deftypefn {Built-in Function} unsigned long long __builtin_bpf_load_word (unsigned long long @var{offset})
15345Load 32-bits from the @code{struct sk_buff} packet data pointed by the register @code{%r6} and return it.
15346@end deftypefn
15347
15348@node FR-V Built-in Functions
15349@subsection FR-V Built-in Functions
15350
15351GCC provides many FR-V-specific built-in functions.  In general,
15352these functions are intended to be compatible with those described
15353by @cite{FR-V Family, Softune C/C++ Compiler Manual (V6), Fujitsu
15354Semiconductor}.  The two exceptions are @code{__MDUNPACKH} and
15355@code{__MBTOHE}, the GCC forms of which pass 128-bit values by
15356pointer rather than by value.
15357
15358Most of the functions are named after specific FR-V instructions.
15359Such functions are said to be ``directly mapped'' and are summarized
15360here in tabular form.
15361
15362@menu
15363* Argument Types::
15364* Directly-mapped Integer Functions::
15365* Directly-mapped Media Functions::
15366* Raw read/write Functions::
15367* Other Built-in Functions::
15368@end menu
15369
15370@node Argument Types
15371@subsubsection Argument Types
15372
15373The arguments to the built-in functions can be divided into three groups:
15374register numbers, compile-time constants and run-time values.  In order
15375to make this classification clear at a glance, the arguments and return
15376values are given the following pseudo types:
15377
15378@multitable @columnfractions .20 .30 .15 .35
15379@item Pseudo type @tab Real C type @tab Constant? @tab Description
15380@item @code{uh} @tab @code{unsigned short} @tab No @tab an unsigned halfword
15381@item @code{uw1} @tab @code{unsigned int} @tab No @tab an unsigned word
15382@item @code{sw1} @tab @code{int} @tab No @tab a signed word
15383@item @code{uw2} @tab @code{unsigned long long} @tab No
15384@tab an unsigned doubleword
15385@item @code{sw2} @tab @code{long long} @tab No @tab a signed doubleword
15386@item @code{const} @tab @code{int} @tab Yes @tab an integer constant
15387@item @code{acc} @tab @code{int} @tab Yes @tab an ACC register number
15388@item @code{iacc} @tab @code{int} @tab Yes @tab an IACC register number
15389@end multitable
15390
15391These pseudo types are not defined by GCC, they are simply a notational
15392convenience used in this manual.
15393
15394Arguments of type @code{uh}, @code{uw1}, @code{sw1}, @code{uw2}
15395and @code{sw2} are evaluated at run time.  They correspond to
15396register operands in the underlying FR-V instructions.
15397
15398@code{const} arguments represent immediate operands in the underlying
15399FR-V instructions.  They must be compile-time constants.
15400
15401@code{acc} arguments are evaluated at compile time and specify the number
15402of an accumulator register.  For example, an @code{acc} argument of 2
15403selects the ACC2 register.
15404
15405@code{iacc} arguments are similar to @code{acc} arguments but specify the
15406number of an IACC register.  See @pxref{Other Built-in Functions}
15407for more details.
15408
15409@node Directly-mapped Integer Functions
15410@subsubsection Directly-Mapped Integer Functions
15411
15412The functions listed below map directly to FR-V I-type instructions.
15413
15414@multitable @columnfractions .45 .32 .23
15415@item Function prototype @tab Example usage @tab Assembly output
15416@item @code{sw1 __ADDSS (sw1, sw1)}
15417@tab @code{@var{c} = __ADDSS (@var{a}, @var{b})}
15418@tab @code{ADDSS @var{a},@var{b},@var{c}}
15419@item @code{sw1 __SCAN (sw1, sw1)}
15420@tab @code{@var{c} = __SCAN (@var{a}, @var{b})}
15421@tab @code{SCAN @var{a},@var{b},@var{c}}
15422@item @code{sw1 __SCUTSS (sw1)}
15423@tab @code{@var{b} = __SCUTSS (@var{a})}
15424@tab @code{SCUTSS @var{a},@var{b}}
15425@item @code{sw1 __SLASS (sw1, sw1)}
15426@tab @code{@var{c} = __SLASS (@var{a}, @var{b})}
15427@tab @code{SLASS @var{a},@var{b},@var{c}}
15428@item @code{void __SMASS (sw1, sw1)}
15429@tab @code{__SMASS (@var{a}, @var{b})}
15430@tab @code{SMASS @var{a},@var{b}}
15431@item @code{void __SMSSS (sw1, sw1)}
15432@tab @code{__SMSSS (@var{a}, @var{b})}
15433@tab @code{SMSSS @var{a},@var{b}}
15434@item @code{void __SMU (sw1, sw1)}
15435@tab @code{__SMU (@var{a}, @var{b})}
15436@tab @code{SMU @var{a},@var{b}}
15437@item @code{sw2 __SMUL (sw1, sw1)}
15438@tab @code{@var{c} = __SMUL (@var{a}, @var{b})}
15439@tab @code{SMUL @var{a},@var{b},@var{c}}
15440@item @code{sw1 __SUBSS (sw1, sw1)}
15441@tab @code{@var{c} = __SUBSS (@var{a}, @var{b})}
15442@tab @code{SUBSS @var{a},@var{b},@var{c}}
15443@item @code{uw2 __UMUL (uw1, uw1)}
15444@tab @code{@var{c} = __UMUL (@var{a}, @var{b})}
15445@tab @code{UMUL @var{a},@var{b},@var{c}}
15446@end multitable
15447
15448@node Directly-mapped Media Functions
15449@subsubsection Directly-Mapped Media Functions
15450
15451The functions listed below map directly to FR-V M-type instructions.
15452
15453@multitable @columnfractions .45 .32 .23
15454@item Function prototype @tab Example usage @tab Assembly output
15455@item @code{uw1 __MABSHS (sw1)}
15456@tab @code{@var{b} = __MABSHS (@var{a})}
15457@tab @code{MABSHS @var{a},@var{b}}
15458@item @code{void __MADDACCS (acc, acc)}
15459@tab @code{__MADDACCS (@var{b}, @var{a})}
15460@tab @code{MADDACCS @var{a},@var{b}}
15461@item @code{sw1 __MADDHSS (sw1, sw1)}
15462@tab @code{@var{c} = __MADDHSS (@var{a}, @var{b})}
15463@tab @code{MADDHSS @var{a},@var{b},@var{c}}
15464@item @code{uw1 __MADDHUS (uw1, uw1)}
15465@tab @code{@var{c} = __MADDHUS (@var{a}, @var{b})}
15466@tab @code{MADDHUS @var{a},@var{b},@var{c}}
15467@item @code{uw1 __MAND (uw1, uw1)}
15468@tab @code{@var{c} = __MAND (@var{a}, @var{b})}
15469@tab @code{MAND @var{a},@var{b},@var{c}}
15470@item @code{void __MASACCS (acc, acc)}
15471@tab @code{__MASACCS (@var{b}, @var{a})}
15472@tab @code{MASACCS @var{a},@var{b}}
15473@item @code{uw1 __MAVEH (uw1, uw1)}
15474@tab @code{@var{c} = __MAVEH (@var{a}, @var{b})}
15475@tab @code{MAVEH @var{a},@var{b},@var{c}}
15476@item @code{uw2 __MBTOH (uw1)}
15477@tab @code{@var{b} = __MBTOH (@var{a})}
15478@tab @code{MBTOH @var{a},@var{b}}
15479@item @code{void __MBTOHE (uw1 *, uw1)}
15480@tab @code{__MBTOHE (&@var{b}, @var{a})}
15481@tab @code{MBTOHE @var{a},@var{b}}
15482@item @code{void __MCLRACC (acc)}
15483@tab @code{__MCLRACC (@var{a})}
15484@tab @code{MCLRACC @var{a}}
15485@item @code{void __MCLRACCA (void)}
15486@tab @code{__MCLRACCA ()}
15487@tab @code{MCLRACCA}
15488@item @code{uw1 __Mcop1 (uw1, uw1)}
15489@tab @code{@var{c} = __Mcop1 (@var{a}, @var{b})}
15490@tab @code{Mcop1 @var{a},@var{b},@var{c}}
15491@item @code{uw1 __Mcop2 (uw1, uw1)}
15492@tab @code{@var{c} = __Mcop2 (@var{a}, @var{b})}
15493@tab @code{Mcop2 @var{a},@var{b},@var{c}}
15494@item @code{uw1 __MCPLHI (uw2, const)}
15495@tab @code{@var{c} = __MCPLHI (@var{a}, @var{b})}
15496@tab @code{MCPLHI @var{a},#@var{b},@var{c}}
15497@item @code{uw1 __MCPLI (uw2, const)}
15498@tab @code{@var{c} = __MCPLI (@var{a}, @var{b})}
15499@tab @code{MCPLI @var{a},#@var{b},@var{c}}
15500@item @code{void __MCPXIS (acc, sw1, sw1)}
15501@tab @code{__MCPXIS (@var{c}, @var{a}, @var{b})}
15502@tab @code{MCPXIS @var{a},@var{b},@var{c}}
15503@item @code{void __MCPXIU (acc, uw1, uw1)}
15504@tab @code{__MCPXIU (@var{c}, @var{a}, @var{b})}
15505@tab @code{MCPXIU @var{a},@var{b},@var{c}}
15506@item @code{void __MCPXRS (acc, sw1, sw1)}
15507@tab @code{__MCPXRS (@var{c}, @var{a}, @var{b})}
15508@tab @code{MCPXRS @var{a},@var{b},@var{c}}
15509@item @code{void __MCPXRU (acc, uw1, uw1)}
15510@tab @code{__MCPXRU (@var{c}, @var{a}, @var{b})}
15511@tab @code{MCPXRU @var{a},@var{b},@var{c}}
15512@item @code{uw1 __MCUT (acc, uw1)}
15513@tab @code{@var{c} = __MCUT (@var{a}, @var{b})}
15514@tab @code{MCUT @var{a},@var{b},@var{c}}
15515@item @code{uw1 __MCUTSS (acc, sw1)}
15516@tab @code{@var{c} = __MCUTSS (@var{a}, @var{b})}
15517@tab @code{MCUTSS @var{a},@var{b},@var{c}}
15518@item @code{void __MDADDACCS (acc, acc)}
15519@tab @code{__MDADDACCS (@var{b}, @var{a})}
15520@tab @code{MDADDACCS @var{a},@var{b}}
15521@item @code{void __MDASACCS (acc, acc)}
15522@tab @code{__MDASACCS (@var{b}, @var{a})}
15523@tab @code{MDASACCS @var{a},@var{b}}
15524@item @code{uw2 __MDCUTSSI (acc, const)}
15525@tab @code{@var{c} = __MDCUTSSI (@var{a}, @var{b})}
15526@tab @code{MDCUTSSI @var{a},#@var{b},@var{c}}
15527@item @code{uw2 __MDPACKH (uw2, uw2)}
15528@tab @code{@var{c} = __MDPACKH (@var{a}, @var{b})}
15529@tab @code{MDPACKH @var{a},@var{b},@var{c}}
15530@item @code{uw2 __MDROTLI (uw2, const)}
15531@tab @code{@var{c} = __MDROTLI (@var{a}, @var{b})}
15532@tab @code{MDROTLI @var{a},#@var{b},@var{c}}
15533@item @code{void __MDSUBACCS (acc, acc)}
15534@tab @code{__MDSUBACCS (@var{b}, @var{a})}
15535@tab @code{MDSUBACCS @var{a},@var{b}}
15536@item @code{void __MDUNPACKH (uw1 *, uw2)}
15537@tab @code{__MDUNPACKH (&@var{b}, @var{a})}
15538@tab @code{MDUNPACKH @var{a},@var{b}}
15539@item @code{uw2 __MEXPDHD (uw1, const)}
15540@tab @code{@var{c} = __MEXPDHD (@var{a}, @var{b})}
15541@tab @code{MEXPDHD @var{a},#@var{b},@var{c}}
15542@item @code{uw1 __MEXPDHW (uw1, const)}
15543@tab @code{@var{c} = __MEXPDHW (@var{a}, @var{b})}
15544@tab @code{MEXPDHW @var{a},#@var{b},@var{c}}
15545@item @code{uw1 __MHDSETH (uw1, const)}
15546@tab @code{@var{c} = __MHDSETH (@var{a}, @var{b})}
15547@tab @code{MHDSETH @var{a},#@var{b},@var{c}}
15548@item @code{sw1 __MHDSETS (const)}
15549@tab @code{@var{b} = __MHDSETS (@var{a})}
15550@tab @code{MHDSETS #@var{a},@var{b}}
15551@item @code{uw1 __MHSETHIH (uw1, const)}
15552@tab @code{@var{b} = __MHSETHIH (@var{b}, @var{a})}
15553@tab @code{MHSETHIH #@var{a},@var{b}}
15554@item @code{sw1 __MHSETHIS (sw1, const)}
15555@tab @code{@var{b} = __MHSETHIS (@var{b}, @var{a})}
15556@tab @code{MHSETHIS #@var{a},@var{b}}
15557@item @code{uw1 __MHSETLOH (uw1, const)}
15558@tab @code{@var{b} = __MHSETLOH (@var{b}, @var{a})}
15559@tab @code{MHSETLOH #@var{a},@var{b}}
15560@item @code{sw1 __MHSETLOS (sw1, const)}
15561@tab @code{@var{b} = __MHSETLOS (@var{b}, @var{a})}
15562@tab @code{MHSETLOS #@var{a},@var{b}}
15563@item @code{uw1 __MHTOB (uw2)}
15564@tab @code{@var{b} = __MHTOB (@var{a})}
15565@tab @code{MHTOB @var{a},@var{b}}
15566@item @code{void __MMACHS (acc, sw1, sw1)}
15567@tab @code{__MMACHS (@var{c}, @var{a}, @var{b})}
15568@tab @code{MMACHS @var{a},@var{b},@var{c}}
15569@item @code{void __MMACHU (acc, uw1, uw1)}
15570@tab @code{__MMACHU (@var{c}, @var{a}, @var{b})}
15571@tab @code{MMACHU @var{a},@var{b},@var{c}}
15572@item @code{void __MMRDHS (acc, sw1, sw1)}
15573@tab @code{__MMRDHS (@var{c}, @var{a}, @var{b})}
15574@tab @code{MMRDHS @var{a},@var{b},@var{c}}
15575@item @code{void __MMRDHU (acc, uw1, uw1)}
15576@tab @code{__MMRDHU (@var{c}, @var{a}, @var{b})}
15577@tab @code{MMRDHU @var{a},@var{b},@var{c}}
15578@item @code{void __MMULHS (acc, sw1, sw1)}
15579@tab @code{__MMULHS (@var{c}, @var{a}, @var{b})}
15580@tab @code{MMULHS @var{a},@var{b},@var{c}}
15581@item @code{void __MMULHU (acc, uw1, uw1)}
15582@tab @code{__MMULHU (@var{c}, @var{a}, @var{b})}
15583@tab @code{MMULHU @var{a},@var{b},@var{c}}
15584@item @code{void __MMULXHS (acc, sw1, sw1)}
15585@tab @code{__MMULXHS (@var{c}, @var{a}, @var{b})}
15586@tab @code{MMULXHS @var{a},@var{b},@var{c}}
15587@item @code{void __MMULXHU (acc, uw1, uw1)}
15588@tab @code{__MMULXHU (@var{c}, @var{a}, @var{b})}
15589@tab @code{MMULXHU @var{a},@var{b},@var{c}}
15590@item @code{uw1 __MNOT (uw1)}
15591@tab @code{@var{b} = __MNOT (@var{a})}
15592@tab @code{MNOT @var{a},@var{b}}
15593@item @code{uw1 __MOR (uw1, uw1)}
15594@tab @code{@var{c} = __MOR (@var{a}, @var{b})}
15595@tab @code{MOR @var{a},@var{b},@var{c}}
15596@item @code{uw1 __MPACKH (uh, uh)}
15597@tab @code{@var{c} = __MPACKH (@var{a}, @var{b})}
15598@tab @code{MPACKH @var{a},@var{b},@var{c}}
15599@item @code{sw2 __MQADDHSS (sw2, sw2)}
15600@tab @code{@var{c} = __MQADDHSS (@var{a}, @var{b})}
15601@tab @code{MQADDHSS @var{a},@var{b},@var{c}}
15602@item @code{uw2 __MQADDHUS (uw2, uw2)}
15603@tab @code{@var{c} = __MQADDHUS (@var{a}, @var{b})}
15604@tab @code{MQADDHUS @var{a},@var{b},@var{c}}
15605@item @code{void __MQCPXIS (acc, sw2, sw2)}
15606@tab @code{__MQCPXIS (@var{c}, @var{a}, @var{b})}
15607@tab @code{MQCPXIS @var{a},@var{b},@var{c}}
15608@item @code{void __MQCPXIU (acc, uw2, uw2)}
15609@tab @code{__MQCPXIU (@var{c}, @var{a}, @var{b})}
15610@tab @code{MQCPXIU @var{a},@var{b},@var{c}}
15611@item @code{void __MQCPXRS (acc, sw2, sw2)}
15612@tab @code{__MQCPXRS (@var{c}, @var{a}, @var{b})}
15613@tab @code{MQCPXRS @var{a},@var{b},@var{c}}
15614@item @code{void __MQCPXRU (acc, uw2, uw2)}
15615@tab @code{__MQCPXRU (@var{c}, @var{a}, @var{b})}
15616@tab @code{MQCPXRU @var{a},@var{b},@var{c}}
15617@item @code{sw2 __MQLCLRHS (sw2, sw2)}
15618@tab @code{@var{c} = __MQLCLRHS (@var{a}, @var{b})}
15619@tab @code{MQLCLRHS @var{a},@var{b},@var{c}}
15620@item @code{sw2 __MQLMTHS (sw2, sw2)}
15621@tab @code{@var{c} = __MQLMTHS (@var{a}, @var{b})}
15622@tab @code{MQLMTHS @var{a},@var{b},@var{c}}
15623@item @code{void __MQMACHS (acc, sw2, sw2)}
15624@tab @code{__MQMACHS (@var{c}, @var{a}, @var{b})}
15625@tab @code{MQMACHS @var{a},@var{b},@var{c}}
15626@item @code{void __MQMACHU (acc, uw2, uw2)}
15627@tab @code{__MQMACHU (@var{c}, @var{a}, @var{b})}
15628@tab @code{MQMACHU @var{a},@var{b},@var{c}}
15629@item @code{void __MQMACXHS (acc, sw2, sw2)}
15630@tab @code{__MQMACXHS (@var{c}, @var{a}, @var{b})}
15631@tab @code{MQMACXHS @var{a},@var{b},@var{c}}
15632@item @code{void __MQMULHS (acc, sw2, sw2)}
15633@tab @code{__MQMULHS (@var{c}, @var{a}, @var{b})}
15634@tab @code{MQMULHS @var{a},@var{b},@var{c}}
15635@item @code{void __MQMULHU (acc, uw2, uw2)}
15636@tab @code{__MQMULHU (@var{c}, @var{a}, @var{b})}
15637@tab @code{MQMULHU @var{a},@var{b},@var{c}}
15638@item @code{void __MQMULXHS (acc, sw2, sw2)}
15639@tab @code{__MQMULXHS (@var{c}, @var{a}, @var{b})}
15640@tab @code{MQMULXHS @var{a},@var{b},@var{c}}
15641@item @code{void __MQMULXHU (acc, uw2, uw2)}
15642@tab @code{__MQMULXHU (@var{c}, @var{a}, @var{b})}
15643@tab @code{MQMULXHU @var{a},@var{b},@var{c}}
15644@item @code{sw2 __MQSATHS (sw2, sw2)}
15645@tab @code{@var{c} = __MQSATHS (@var{a}, @var{b})}
15646@tab @code{MQSATHS @var{a},@var{b},@var{c}}
15647@item @code{uw2 __MQSLLHI (uw2, int)}
15648@tab @code{@var{c} = __MQSLLHI (@var{a}, @var{b})}
15649@tab @code{MQSLLHI @var{a},@var{b},@var{c}}
15650@item @code{sw2 __MQSRAHI (sw2, int)}
15651@tab @code{@var{c} = __MQSRAHI (@var{a}, @var{b})}
15652@tab @code{MQSRAHI @var{a},@var{b},@var{c}}
15653@item @code{sw2 __MQSUBHSS (sw2, sw2)}
15654@tab @code{@var{c} = __MQSUBHSS (@var{a}, @var{b})}
15655@tab @code{MQSUBHSS @var{a},@var{b},@var{c}}
15656@item @code{uw2 __MQSUBHUS (uw2, uw2)}
15657@tab @code{@var{c} = __MQSUBHUS (@var{a}, @var{b})}
15658@tab @code{MQSUBHUS @var{a},@var{b},@var{c}}
15659@item @code{void __MQXMACHS (acc, sw2, sw2)}
15660@tab @code{__MQXMACHS (@var{c}, @var{a}, @var{b})}
15661@tab @code{MQXMACHS @var{a},@var{b},@var{c}}
15662@item @code{void __MQXMACXHS (acc, sw2, sw2)}
15663@tab @code{__MQXMACXHS (@var{c}, @var{a}, @var{b})}
15664@tab @code{MQXMACXHS @var{a},@var{b},@var{c}}
15665@item @code{uw1 __MRDACC (acc)}
15666@tab @code{@var{b} = __MRDACC (@var{a})}
15667@tab @code{MRDACC @var{a},@var{b}}
15668@item @code{uw1 __MRDACCG (acc)}
15669@tab @code{@var{b} = __MRDACCG (@var{a})}
15670@tab @code{MRDACCG @var{a},@var{b}}
15671@item @code{uw1 __MROTLI (uw1, const)}
15672@tab @code{@var{c} = __MROTLI (@var{a}, @var{b})}
15673@tab @code{MROTLI @var{a},#@var{b},@var{c}}
15674@item @code{uw1 __MROTRI (uw1, const)}
15675@tab @code{@var{c} = __MROTRI (@var{a}, @var{b})}
15676@tab @code{MROTRI @var{a},#@var{b},@var{c}}
15677@item @code{sw1 __MSATHS (sw1, sw1)}
15678@tab @code{@var{c} = __MSATHS (@var{a}, @var{b})}
15679@tab @code{MSATHS @var{a},@var{b},@var{c}}
15680@item @code{uw1 __MSATHU (uw1, uw1)}
15681@tab @code{@var{c} = __MSATHU (@var{a}, @var{b})}
15682@tab @code{MSATHU @var{a},@var{b},@var{c}}
15683@item @code{uw1 __MSLLHI (uw1, const)}
15684@tab @code{@var{c} = __MSLLHI (@var{a}, @var{b})}
15685@tab @code{MSLLHI @var{a},#@var{b},@var{c}}
15686@item @code{sw1 __MSRAHI (sw1, const)}
15687@tab @code{@var{c} = __MSRAHI (@var{a}, @var{b})}
15688@tab @code{MSRAHI @var{a},#@var{b},@var{c}}
15689@item @code{uw1 __MSRLHI (uw1, const)}
15690@tab @code{@var{c} = __MSRLHI (@var{a}, @var{b})}
15691@tab @code{MSRLHI @var{a},#@var{b},@var{c}}
15692@item @code{void __MSUBACCS (acc, acc)}
15693@tab @code{__MSUBACCS (@var{b}, @var{a})}
15694@tab @code{MSUBACCS @var{a},@var{b}}
15695@item @code{sw1 __MSUBHSS (sw1, sw1)}
15696@tab @code{@var{c} = __MSUBHSS (@var{a}, @var{b})}
15697@tab @code{MSUBHSS @var{a},@var{b},@var{c}}
15698@item @code{uw1 __MSUBHUS (uw1, uw1)}
15699@tab @code{@var{c} = __MSUBHUS (@var{a}, @var{b})}
15700@tab @code{MSUBHUS @var{a},@var{b},@var{c}}
15701@item @code{void __MTRAP (void)}
15702@tab @code{__MTRAP ()}
15703@tab @code{MTRAP}
15704@item @code{uw2 __MUNPACKH (uw1)}
15705@tab @code{@var{b} = __MUNPACKH (@var{a})}
15706@tab @code{MUNPACKH @var{a},@var{b}}
15707@item @code{uw1 __MWCUT (uw2, uw1)}
15708@tab @code{@var{c} = __MWCUT (@var{a}, @var{b})}
15709@tab @code{MWCUT @var{a},@var{b},@var{c}}
15710@item @code{void __MWTACC (acc, uw1)}
15711@tab @code{__MWTACC (@var{b}, @var{a})}
15712@tab @code{MWTACC @var{a},@var{b}}
15713@item @code{void __MWTACCG (acc, uw1)}
15714@tab @code{__MWTACCG (@var{b}, @var{a})}
15715@tab @code{MWTACCG @var{a},@var{b}}
15716@item @code{uw1 __MXOR (uw1, uw1)}
15717@tab @code{@var{c} = __MXOR (@var{a}, @var{b})}
15718@tab @code{MXOR @var{a},@var{b},@var{c}}
15719@end multitable
15720
15721@node Raw read/write Functions
15722@subsubsection Raw Read/Write Functions
15723
15724This sections describes built-in functions related to read and write
15725instructions to access memory.  These functions generate
15726@code{membar} instructions to flush the I/O load and stores where
15727appropriate, as described in Fujitsu's manual described above.
15728
15729@table @code
15730
15731@item unsigned char __builtin_read8 (void *@var{data})
15732@item unsigned short __builtin_read16 (void *@var{data})
15733@item unsigned long __builtin_read32 (void *@var{data})
15734@item unsigned long long __builtin_read64 (void *@var{data})
15735
15736@item void __builtin_write8 (void *@var{data}, unsigned char @var{datum})
15737@item void __builtin_write16 (void *@var{data}, unsigned short @var{datum})
15738@item void __builtin_write32 (void *@var{data}, unsigned long @var{datum})
15739@item void __builtin_write64 (void *@var{data}, unsigned long long @var{datum})
15740@end table
15741
15742@node Other Built-in Functions
15743@subsubsection Other Built-in Functions
15744
15745This section describes built-in functions that are not named after
15746a specific FR-V instruction.
15747
15748@table @code
15749@item sw2 __IACCreadll (iacc @var{reg})
15750Return the full 64-bit value of IACC0@.  The @var{reg} argument is reserved
15751for future expansion and must be 0.
15752
15753@item sw1 __IACCreadl (iacc @var{reg})
15754Return the value of IACC0H if @var{reg} is 0 and IACC0L if @var{reg} is 1.
15755Other values of @var{reg} are rejected as invalid.
15756
15757@item void __IACCsetll (iacc @var{reg}, sw2 @var{x})
15758Set the full 64-bit value of IACC0 to @var{x}.  The @var{reg} argument
15759is reserved for future expansion and must be 0.
15760
15761@item void __IACCsetl (iacc @var{reg}, sw1 @var{x})
15762Set IACC0H to @var{x} if @var{reg} is 0 and IACC0L to @var{x} if @var{reg}
15763is 1.  Other values of @var{reg} are rejected as invalid.
15764
15765@item void __data_prefetch0 (const void *@var{x})
15766Use the @code{dcpl} instruction to load the contents of address @var{x}
15767into the data cache.
15768
15769@item void __data_prefetch (const void *@var{x})
15770Use the @code{nldub} instruction to load the contents of address @var{x}
15771into the data cache.  The instruction is issued in slot I1@.
15772@end table
15773
15774@node MIPS DSP Built-in Functions
15775@subsection MIPS DSP Built-in Functions
15776
15777The MIPS DSP Application-Specific Extension (ASE) includes new
15778instructions that are designed to improve the performance of DSP and
15779media applications.  It provides instructions that operate on packed
157808-bit/16-bit integer data, Q7, Q15 and Q31 fractional data.
15781
15782GCC supports MIPS DSP operations using both the generic
15783vector extensions (@pxref{Vector Extensions}) and a collection of
15784MIPS-specific built-in functions.  Both kinds of support are
15785enabled by the @option{-mdsp} command-line option.
15786
15787Revision 2 of the ASE was introduced in the second half of 2006.
15788This revision adds extra instructions to the original ASE, but is
15789otherwise backwards-compatible with it.  You can select revision 2
15790using the command-line option @option{-mdspr2}; this option implies
15791@option{-mdsp}.
15792
15793The SCOUNT and POS bits of the DSP control register are global.  The
15794WRDSP, EXTPDP, EXTPDPV and MTHLIP instructions modify the SCOUNT and
15795POS bits.  During optimization, the compiler does not delete these
15796instructions and it does not delete calls to functions containing
15797these instructions.
15798
15799At present, GCC only provides support for operations on 32-bit
15800vectors.  The vector type associated with 8-bit integer data is
15801usually called @code{v4i8}, the vector type associated with Q7
15802is usually called @code{v4q7}, the vector type associated with 16-bit
15803integer data is usually called @code{v2i16}, and the vector type
15804associated with Q15 is usually called @code{v2q15}.  They can be
15805defined in C as follows:
15806
15807@smallexample
15808typedef signed char v4i8 __attribute__ ((vector_size(4)));
15809typedef signed char v4q7 __attribute__ ((vector_size(4)));
15810typedef short v2i16 __attribute__ ((vector_size(4)));
15811typedef short v2q15 __attribute__ ((vector_size(4)));
15812@end smallexample
15813
15814@code{v4i8}, @code{v4q7}, @code{v2i16} and @code{v2q15} values are
15815initialized in the same way as aggregates.  For example:
15816
15817@smallexample
15818v4i8 a = @{1, 2, 3, 4@};
15819v4i8 b;
15820b = (v4i8) @{5, 6, 7, 8@};
15821
15822v2q15 c = @{0x0fcb, 0x3a75@};
15823v2q15 d;
15824d = (v2q15) @{0.1234 * 0x1.0p15, 0.4567 * 0x1.0p15@};
15825@end smallexample
15826
15827@emph{Note:} The CPU's endianness determines the order in which values
15828are packed.  On little-endian targets, the first value is the least
15829significant and the last value is the most significant.  The opposite
15830order applies to big-endian targets.  For example, the code above
15831sets the lowest byte of @code{a} to @code{1} on little-endian targets
15832and @code{4} on big-endian targets.
15833
15834@emph{Note:} Q7, Q15 and Q31 values must be initialized with their integer
15835representation.  As shown in this example, the integer representation
15836of a Q7 value can be obtained by multiplying the fractional value by
15837@code{0x1.0p7}.  The equivalent for Q15 values is to multiply by
15838@code{0x1.0p15}.  The equivalent for Q31 values is to multiply by
15839@code{0x1.0p31}.
15840
15841The table below lists the @code{v4i8} and @code{v2q15} operations for which
15842hardware support exists.  @code{a} and @code{b} are @code{v4i8} values,
15843and @code{c} and @code{d} are @code{v2q15} values.
15844
15845@multitable @columnfractions .50 .50
15846@item C code @tab MIPS instruction
15847@item @code{a + b} @tab @code{addu.qb}
15848@item @code{c + d} @tab @code{addq.ph}
15849@item @code{a - b} @tab @code{subu.qb}
15850@item @code{c - d} @tab @code{subq.ph}
15851@end multitable
15852
15853The table below lists the @code{v2i16} operation for which
15854hardware support exists for the DSP ASE REV 2.  @code{e} and @code{f} are
15855@code{v2i16} values.
15856
15857@multitable @columnfractions .50 .50
15858@item C code @tab MIPS instruction
15859@item @code{e * f} @tab @code{mul.ph}
15860@end multitable
15861
15862It is easier to describe the DSP built-in functions if we first define
15863the following types:
15864
15865@smallexample
15866typedef int q31;
15867typedef int i32;
15868typedef unsigned int ui32;
15869typedef long long a64;
15870@end smallexample
15871
15872@code{q31} and @code{i32} are actually the same as @code{int}, but we
15873use @code{q31} to indicate a Q31 fractional value and @code{i32} to
15874indicate a 32-bit integer value.  Similarly, @code{a64} is the same as
15875@code{long long}, but we use @code{a64} to indicate values that are
15876placed in one of the four DSP accumulators (@code{$ac0},
15877@code{$ac1}, @code{$ac2} or @code{$ac3}).
15878
15879Also, some built-in functions prefer or require immediate numbers as
15880parameters, because the corresponding DSP instructions accept both immediate
15881numbers and register operands, or accept immediate numbers only.  The
15882immediate parameters are listed as follows.
15883
15884@smallexample
15885imm0_3: 0 to 3.
15886imm0_7: 0 to 7.
15887imm0_15: 0 to 15.
15888imm0_31: 0 to 31.
15889imm0_63: 0 to 63.
15890imm0_255: 0 to 255.
15891imm_n32_31: -32 to 31.
15892imm_n512_511: -512 to 511.
15893@end smallexample
15894
15895The following built-in functions map directly to a particular MIPS DSP
15896instruction.  Please refer to the architecture specification
15897for details on what each instruction does.
15898
15899@smallexample
15900v2q15 __builtin_mips_addq_ph (v2q15, v2q15)
15901v2q15 __builtin_mips_addq_s_ph (v2q15, v2q15)
15902q31 __builtin_mips_addq_s_w (q31, q31)
15903v4i8 __builtin_mips_addu_qb (v4i8, v4i8)
15904v4i8 __builtin_mips_addu_s_qb (v4i8, v4i8)
15905v2q15 __builtin_mips_subq_ph (v2q15, v2q15)
15906v2q15 __builtin_mips_subq_s_ph (v2q15, v2q15)
15907q31 __builtin_mips_subq_s_w (q31, q31)
15908v4i8 __builtin_mips_subu_qb (v4i8, v4i8)
15909v4i8 __builtin_mips_subu_s_qb (v4i8, v4i8)
15910i32 __builtin_mips_addsc (i32, i32)
15911i32 __builtin_mips_addwc (i32, i32)
15912i32 __builtin_mips_modsub (i32, i32)
15913i32 __builtin_mips_raddu_w_qb (v4i8)
15914v2q15 __builtin_mips_absq_s_ph (v2q15)
15915q31 __builtin_mips_absq_s_w (q31)
15916v4i8 __builtin_mips_precrq_qb_ph (v2q15, v2q15)
15917v2q15 __builtin_mips_precrq_ph_w (q31, q31)
15918v2q15 __builtin_mips_precrq_rs_ph_w (q31, q31)
15919v4i8 __builtin_mips_precrqu_s_qb_ph (v2q15, v2q15)
15920q31 __builtin_mips_preceq_w_phl (v2q15)
15921q31 __builtin_mips_preceq_w_phr (v2q15)
15922v2q15 __builtin_mips_precequ_ph_qbl (v4i8)
15923v2q15 __builtin_mips_precequ_ph_qbr (v4i8)
15924v2q15 __builtin_mips_precequ_ph_qbla (v4i8)
15925v2q15 __builtin_mips_precequ_ph_qbra (v4i8)
15926v2q15 __builtin_mips_preceu_ph_qbl (v4i8)
15927v2q15 __builtin_mips_preceu_ph_qbr (v4i8)
15928v2q15 __builtin_mips_preceu_ph_qbla (v4i8)
15929v2q15 __builtin_mips_preceu_ph_qbra (v4i8)
15930v4i8 __builtin_mips_shll_qb (v4i8, imm0_7)
15931v4i8 __builtin_mips_shll_qb (v4i8, i32)
15932v2q15 __builtin_mips_shll_ph (v2q15, imm0_15)
15933v2q15 __builtin_mips_shll_ph (v2q15, i32)
15934v2q15 __builtin_mips_shll_s_ph (v2q15, imm0_15)
15935v2q15 __builtin_mips_shll_s_ph (v2q15, i32)
15936q31 __builtin_mips_shll_s_w (q31, imm0_31)
15937q31 __builtin_mips_shll_s_w (q31, i32)
15938v4i8 __builtin_mips_shrl_qb (v4i8, imm0_7)
15939v4i8 __builtin_mips_shrl_qb (v4i8, i32)
15940v2q15 __builtin_mips_shra_ph (v2q15, imm0_15)
15941v2q15 __builtin_mips_shra_ph (v2q15, i32)
15942v2q15 __builtin_mips_shra_r_ph (v2q15, imm0_15)
15943v2q15 __builtin_mips_shra_r_ph (v2q15, i32)
15944q31 __builtin_mips_shra_r_w (q31, imm0_31)
15945q31 __builtin_mips_shra_r_w (q31, i32)
15946v2q15 __builtin_mips_muleu_s_ph_qbl (v4i8, v2q15)
15947v2q15 __builtin_mips_muleu_s_ph_qbr (v4i8, v2q15)
15948v2q15 __builtin_mips_mulq_rs_ph (v2q15, v2q15)
15949q31 __builtin_mips_muleq_s_w_phl (v2q15, v2q15)
15950q31 __builtin_mips_muleq_s_w_phr (v2q15, v2q15)
15951a64 __builtin_mips_dpau_h_qbl (a64, v4i8, v4i8)
15952a64 __builtin_mips_dpau_h_qbr (a64, v4i8, v4i8)
15953a64 __builtin_mips_dpsu_h_qbl (a64, v4i8, v4i8)
15954a64 __builtin_mips_dpsu_h_qbr (a64, v4i8, v4i8)
15955a64 __builtin_mips_dpaq_s_w_ph (a64, v2q15, v2q15)
15956a64 __builtin_mips_dpaq_sa_l_w (a64, q31, q31)
15957a64 __builtin_mips_dpsq_s_w_ph (a64, v2q15, v2q15)
15958a64 __builtin_mips_dpsq_sa_l_w (a64, q31, q31)
15959a64 __builtin_mips_mulsaq_s_w_ph (a64, v2q15, v2q15)
15960a64 __builtin_mips_maq_s_w_phl (a64, v2q15, v2q15)
15961a64 __builtin_mips_maq_s_w_phr (a64, v2q15, v2q15)
15962a64 __builtin_mips_maq_sa_w_phl (a64, v2q15, v2q15)
15963a64 __builtin_mips_maq_sa_w_phr (a64, v2q15, v2q15)
15964i32 __builtin_mips_bitrev (i32)
15965i32 __builtin_mips_insv (i32, i32)
15966v4i8 __builtin_mips_repl_qb (imm0_255)
15967v4i8 __builtin_mips_repl_qb (i32)
15968v2q15 __builtin_mips_repl_ph (imm_n512_511)
15969v2q15 __builtin_mips_repl_ph (i32)
15970void __builtin_mips_cmpu_eq_qb (v4i8, v4i8)
15971void __builtin_mips_cmpu_lt_qb (v4i8, v4i8)
15972void __builtin_mips_cmpu_le_qb (v4i8, v4i8)
15973i32 __builtin_mips_cmpgu_eq_qb (v4i8, v4i8)
15974i32 __builtin_mips_cmpgu_lt_qb (v4i8, v4i8)
15975i32 __builtin_mips_cmpgu_le_qb (v4i8, v4i8)
15976void __builtin_mips_cmp_eq_ph (v2q15, v2q15)
15977void __builtin_mips_cmp_lt_ph (v2q15, v2q15)
15978void __builtin_mips_cmp_le_ph (v2q15, v2q15)
15979v4i8 __builtin_mips_pick_qb (v4i8, v4i8)
15980v2q15 __builtin_mips_pick_ph (v2q15, v2q15)
15981v2q15 __builtin_mips_packrl_ph (v2q15, v2q15)
15982i32 __builtin_mips_extr_w (a64, imm0_31)
15983i32 __builtin_mips_extr_w (a64, i32)
15984i32 __builtin_mips_extr_r_w (a64, imm0_31)
15985i32 __builtin_mips_extr_s_h (a64, i32)
15986i32 __builtin_mips_extr_rs_w (a64, imm0_31)
15987i32 __builtin_mips_extr_rs_w (a64, i32)
15988i32 __builtin_mips_extr_s_h (a64, imm0_31)
15989i32 __builtin_mips_extr_r_w (a64, i32)
15990i32 __builtin_mips_extp (a64, imm0_31)
15991i32 __builtin_mips_extp (a64, i32)
15992i32 __builtin_mips_extpdp (a64, imm0_31)
15993i32 __builtin_mips_extpdp (a64, i32)
15994a64 __builtin_mips_shilo (a64, imm_n32_31)
15995a64 __builtin_mips_shilo (a64, i32)
15996a64 __builtin_mips_mthlip (a64, i32)
15997void __builtin_mips_wrdsp (i32, imm0_63)
15998i32 __builtin_mips_rddsp (imm0_63)
15999i32 __builtin_mips_lbux (void *, i32)
16000i32 __builtin_mips_lhx (void *, i32)
16001i32 __builtin_mips_lwx (void *, i32)
16002a64 __builtin_mips_ldx (void *, i32) [MIPS64 only]
16003i32 __builtin_mips_bposge32 (void)
16004a64 __builtin_mips_madd (a64, i32, i32);
16005a64 __builtin_mips_maddu (a64, ui32, ui32);
16006a64 __builtin_mips_msub (a64, i32, i32);
16007a64 __builtin_mips_msubu (a64, ui32, ui32);
16008a64 __builtin_mips_mult (i32, i32);
16009a64 __builtin_mips_multu (ui32, ui32);
16010@end smallexample
16011
16012The following built-in functions map directly to a particular MIPS DSP REV 2
16013instruction.  Please refer to the architecture specification
16014for details on what each instruction does.
16015
16016@smallexample
16017v4q7 __builtin_mips_absq_s_qb (v4q7);
16018v2i16 __builtin_mips_addu_ph (v2i16, v2i16);
16019v2i16 __builtin_mips_addu_s_ph (v2i16, v2i16);
16020v4i8 __builtin_mips_adduh_qb (v4i8, v4i8);
16021v4i8 __builtin_mips_adduh_r_qb (v4i8, v4i8);
16022i32 __builtin_mips_append (i32, i32, imm0_31);
16023i32 __builtin_mips_balign (i32, i32, imm0_3);
16024i32 __builtin_mips_cmpgdu_eq_qb (v4i8, v4i8);
16025i32 __builtin_mips_cmpgdu_lt_qb (v4i8, v4i8);
16026i32 __builtin_mips_cmpgdu_le_qb (v4i8, v4i8);
16027a64 __builtin_mips_dpa_w_ph (a64, v2i16, v2i16);
16028a64 __builtin_mips_dps_w_ph (a64, v2i16, v2i16);
16029v2i16 __builtin_mips_mul_ph (v2i16, v2i16);
16030v2i16 __builtin_mips_mul_s_ph (v2i16, v2i16);
16031q31 __builtin_mips_mulq_rs_w (q31, q31);
16032v2q15 __builtin_mips_mulq_s_ph (v2q15, v2q15);
16033q31 __builtin_mips_mulq_s_w (q31, q31);
16034a64 __builtin_mips_mulsa_w_ph (a64, v2i16, v2i16);
16035v4i8 __builtin_mips_precr_qb_ph (v2i16, v2i16);
16036v2i16 __builtin_mips_precr_sra_ph_w (i32, i32, imm0_31);
16037v2i16 __builtin_mips_precr_sra_r_ph_w (i32, i32, imm0_31);
16038i32 __builtin_mips_prepend (i32, i32, imm0_31);
16039v4i8 __builtin_mips_shra_qb (v4i8, imm0_7);
16040v4i8 __builtin_mips_shra_r_qb (v4i8, imm0_7);
16041v4i8 __builtin_mips_shra_qb (v4i8, i32);
16042v4i8 __builtin_mips_shra_r_qb (v4i8, i32);
16043v2i16 __builtin_mips_shrl_ph (v2i16, imm0_15);
16044v2i16 __builtin_mips_shrl_ph (v2i16, i32);
16045v2i16 __builtin_mips_subu_ph (v2i16, v2i16);
16046v2i16 __builtin_mips_subu_s_ph (v2i16, v2i16);
16047v4i8 __builtin_mips_subuh_qb (v4i8, v4i8);
16048v4i8 __builtin_mips_subuh_r_qb (v4i8, v4i8);
16049v2q15 __builtin_mips_addqh_ph (v2q15, v2q15);
16050v2q15 __builtin_mips_addqh_r_ph (v2q15, v2q15);
16051q31 __builtin_mips_addqh_w (q31, q31);
16052q31 __builtin_mips_addqh_r_w (q31, q31);
16053v2q15 __builtin_mips_subqh_ph (v2q15, v2q15);
16054v2q15 __builtin_mips_subqh_r_ph (v2q15, v2q15);
16055q31 __builtin_mips_subqh_w (q31, q31);
16056q31 __builtin_mips_subqh_r_w (q31, q31);
16057a64 __builtin_mips_dpax_w_ph (a64, v2i16, v2i16);
16058a64 __builtin_mips_dpsx_w_ph (a64, v2i16, v2i16);
16059a64 __builtin_mips_dpaqx_s_w_ph (a64, v2q15, v2q15);
16060a64 __builtin_mips_dpaqx_sa_w_ph (a64, v2q15, v2q15);
16061a64 __builtin_mips_dpsqx_s_w_ph (a64, v2q15, v2q15);
16062a64 __builtin_mips_dpsqx_sa_w_ph (a64, v2q15, v2q15);
16063@end smallexample
16064
16065
16066@node MIPS Paired-Single Support
16067@subsection MIPS Paired-Single Support
16068
16069The MIPS64 architecture includes a number of instructions that
16070operate on pairs of single-precision floating-point values.
16071Each pair is packed into a 64-bit floating-point register,
16072with one element being designated the ``upper half'' and
16073the other being designated the ``lower half''.
16074
16075GCC supports paired-single operations using both the generic
16076vector extensions (@pxref{Vector Extensions}) and a collection of
16077MIPS-specific built-in functions.  Both kinds of support are
16078enabled by the @option{-mpaired-single} command-line option.
16079
16080The vector type associated with paired-single values is usually
16081called @code{v2sf}.  It can be defined in C as follows:
16082
16083@smallexample
16084typedef float v2sf __attribute__ ((vector_size (8)));
16085@end smallexample
16086
16087@code{v2sf} values are initialized in the same way as aggregates.
16088For example:
16089
16090@smallexample
16091v2sf a = @{1.5, 9.1@};
16092v2sf b;
16093float e, f;
16094b = (v2sf) @{e, f@};
16095@end smallexample
16096
16097@emph{Note:} The CPU's endianness determines which value is stored in
16098the upper half of a register and which value is stored in the lower half.
16099On little-endian targets, the first value is the lower one and the second
16100value is the upper one.  The opposite order applies to big-endian targets.
16101For example, the code above sets the lower half of @code{a} to
16102@code{1.5} on little-endian targets and @code{9.1} on big-endian targets.
16103
16104@node MIPS Loongson Built-in Functions
16105@subsection MIPS Loongson Built-in Functions
16106
16107GCC provides intrinsics to access the SIMD instructions provided by the
16108ST Microelectronics Loongson-2E and -2F processors.  These intrinsics,
16109available after inclusion of the @code{loongson.h} header file,
16110operate on the following 64-bit vector types:
16111
16112@itemize
16113@item @code{uint8x8_t}, a vector of eight unsigned 8-bit integers;
16114@item @code{uint16x4_t}, a vector of four unsigned 16-bit integers;
16115@item @code{uint32x2_t}, a vector of two unsigned 32-bit integers;
16116@item @code{int8x8_t}, a vector of eight signed 8-bit integers;
16117@item @code{int16x4_t}, a vector of four signed 16-bit integers;
16118@item @code{int32x2_t}, a vector of two signed 32-bit integers.
16119@end itemize
16120
16121The intrinsics provided are listed below; each is named after the
16122machine instruction to which it corresponds, with suffixes added as
16123appropriate to distinguish intrinsics that expand to the same machine
16124instruction yet have different argument types.  Refer to the architecture
16125documentation for a description of the functionality of each
16126instruction.
16127
16128@smallexample
16129int16x4_t packsswh (int32x2_t s, int32x2_t t);
16130int8x8_t packsshb (int16x4_t s, int16x4_t t);
16131uint8x8_t packushb (uint16x4_t s, uint16x4_t t);
16132uint32x2_t paddw_u (uint32x2_t s, uint32x2_t t);
16133uint16x4_t paddh_u (uint16x4_t s, uint16x4_t t);
16134uint8x8_t paddb_u (uint8x8_t s, uint8x8_t t);
16135int32x2_t paddw_s (int32x2_t s, int32x2_t t);
16136int16x4_t paddh_s (int16x4_t s, int16x4_t t);
16137int8x8_t paddb_s (int8x8_t s, int8x8_t t);
16138uint64_t paddd_u (uint64_t s, uint64_t t);
16139int64_t paddd_s (int64_t s, int64_t t);
16140int16x4_t paddsh (int16x4_t s, int16x4_t t);
16141int8x8_t paddsb (int8x8_t s, int8x8_t t);
16142uint16x4_t paddush (uint16x4_t s, uint16x4_t t);
16143uint8x8_t paddusb (uint8x8_t s, uint8x8_t t);
16144uint64_t pandn_ud (uint64_t s, uint64_t t);
16145uint32x2_t pandn_uw (uint32x2_t s, uint32x2_t t);
16146uint16x4_t pandn_uh (uint16x4_t s, uint16x4_t t);
16147uint8x8_t pandn_ub (uint8x8_t s, uint8x8_t t);
16148int64_t pandn_sd (int64_t s, int64_t t);
16149int32x2_t pandn_sw (int32x2_t s, int32x2_t t);
16150int16x4_t pandn_sh (int16x4_t s, int16x4_t t);
16151int8x8_t pandn_sb (int8x8_t s, int8x8_t t);
16152uint16x4_t pavgh (uint16x4_t s, uint16x4_t t);
16153uint8x8_t pavgb (uint8x8_t s, uint8x8_t t);
16154uint32x2_t pcmpeqw_u (uint32x2_t s, uint32x2_t t);
16155uint16x4_t pcmpeqh_u (uint16x4_t s, uint16x4_t t);
16156uint8x8_t pcmpeqb_u (uint8x8_t s, uint8x8_t t);
16157int32x2_t pcmpeqw_s (int32x2_t s, int32x2_t t);
16158int16x4_t pcmpeqh_s (int16x4_t s, int16x4_t t);
16159int8x8_t pcmpeqb_s (int8x8_t s, int8x8_t t);
16160uint32x2_t pcmpgtw_u (uint32x2_t s, uint32x2_t t);
16161uint16x4_t pcmpgth_u (uint16x4_t s, uint16x4_t t);
16162uint8x8_t pcmpgtb_u (uint8x8_t s, uint8x8_t t);
16163int32x2_t pcmpgtw_s (int32x2_t s, int32x2_t t);
16164int16x4_t pcmpgth_s (int16x4_t s, int16x4_t t);
16165int8x8_t pcmpgtb_s (int8x8_t s, int8x8_t t);
16166uint16x4_t pextrh_u (uint16x4_t s, int field);
16167int16x4_t pextrh_s (int16x4_t s, int field);
16168uint16x4_t pinsrh_0_u (uint16x4_t s, uint16x4_t t);
16169uint16x4_t pinsrh_1_u (uint16x4_t s, uint16x4_t t);
16170uint16x4_t pinsrh_2_u (uint16x4_t s, uint16x4_t t);
16171uint16x4_t pinsrh_3_u (uint16x4_t s, uint16x4_t t);
16172int16x4_t pinsrh_0_s (int16x4_t s, int16x4_t t);
16173int16x4_t pinsrh_1_s (int16x4_t s, int16x4_t t);
16174int16x4_t pinsrh_2_s (int16x4_t s, int16x4_t t);
16175int16x4_t pinsrh_3_s (int16x4_t s, int16x4_t t);
16176int32x2_t pmaddhw (int16x4_t s, int16x4_t t);
16177int16x4_t pmaxsh (int16x4_t s, int16x4_t t);
16178uint8x8_t pmaxub (uint8x8_t s, uint8x8_t t);
16179int16x4_t pminsh (int16x4_t s, int16x4_t t);
16180uint8x8_t pminub (uint8x8_t s, uint8x8_t t);
16181uint8x8_t pmovmskb_u (uint8x8_t s);
16182int8x8_t pmovmskb_s (int8x8_t s);
16183uint16x4_t pmulhuh (uint16x4_t s, uint16x4_t t);
16184int16x4_t pmulhh (int16x4_t s, int16x4_t t);
16185int16x4_t pmullh (int16x4_t s, int16x4_t t);
16186int64_t pmuluw (uint32x2_t s, uint32x2_t t);
16187uint8x8_t pasubub (uint8x8_t s, uint8x8_t t);
16188uint16x4_t biadd (uint8x8_t s);
16189uint16x4_t psadbh (uint8x8_t s, uint8x8_t t);
16190uint16x4_t pshufh_u (uint16x4_t dest, uint16x4_t s, uint8_t order);
16191int16x4_t pshufh_s (int16x4_t dest, int16x4_t s, uint8_t order);
16192uint16x4_t psllh_u (uint16x4_t s, uint8_t amount);
16193int16x4_t psllh_s (int16x4_t s, uint8_t amount);
16194uint32x2_t psllw_u (uint32x2_t s, uint8_t amount);
16195int32x2_t psllw_s (int32x2_t s, uint8_t amount);
16196uint16x4_t psrlh_u (uint16x4_t s, uint8_t amount);
16197int16x4_t psrlh_s (int16x4_t s, uint8_t amount);
16198uint32x2_t psrlw_u (uint32x2_t s, uint8_t amount);
16199int32x2_t psrlw_s (int32x2_t s, uint8_t amount);
16200uint16x4_t psrah_u (uint16x4_t s, uint8_t amount);
16201int16x4_t psrah_s (int16x4_t s, uint8_t amount);
16202uint32x2_t psraw_u (uint32x2_t s, uint8_t amount);
16203int32x2_t psraw_s (int32x2_t s, uint8_t amount);
16204uint32x2_t psubw_u (uint32x2_t s, uint32x2_t t);
16205uint16x4_t psubh_u (uint16x4_t s, uint16x4_t t);
16206uint8x8_t psubb_u (uint8x8_t s, uint8x8_t t);
16207int32x2_t psubw_s (int32x2_t s, int32x2_t t);
16208int16x4_t psubh_s (int16x4_t s, int16x4_t t);
16209int8x8_t psubb_s (int8x8_t s, int8x8_t t);
16210uint64_t psubd_u (uint64_t s, uint64_t t);
16211int64_t psubd_s (int64_t s, int64_t t);
16212int16x4_t psubsh (int16x4_t s, int16x4_t t);
16213int8x8_t psubsb (int8x8_t s, int8x8_t t);
16214uint16x4_t psubush (uint16x4_t s, uint16x4_t t);
16215uint8x8_t psubusb (uint8x8_t s, uint8x8_t t);
16216uint32x2_t punpckhwd_u (uint32x2_t s, uint32x2_t t);
16217uint16x4_t punpckhhw_u (uint16x4_t s, uint16x4_t t);
16218uint8x8_t punpckhbh_u (uint8x8_t s, uint8x8_t t);
16219int32x2_t punpckhwd_s (int32x2_t s, int32x2_t t);
16220int16x4_t punpckhhw_s (int16x4_t s, int16x4_t t);
16221int8x8_t punpckhbh_s (int8x8_t s, int8x8_t t);
16222uint32x2_t punpcklwd_u (uint32x2_t s, uint32x2_t t);
16223uint16x4_t punpcklhw_u (uint16x4_t s, uint16x4_t t);
16224uint8x8_t punpcklbh_u (uint8x8_t s, uint8x8_t t);
16225int32x2_t punpcklwd_s (int32x2_t s, int32x2_t t);
16226int16x4_t punpcklhw_s (int16x4_t s, int16x4_t t);
16227int8x8_t punpcklbh_s (int8x8_t s, int8x8_t t);
16228@end smallexample
16229
16230@menu
16231* Paired-Single Arithmetic::
16232* Paired-Single Built-in Functions::
16233* MIPS-3D Built-in Functions::
16234@end menu
16235
16236@node Paired-Single Arithmetic
16237@subsubsection Paired-Single Arithmetic
16238
16239The table below lists the @code{v2sf} operations for which hardware
16240support exists.  @code{a}, @code{b} and @code{c} are @code{v2sf}
16241values and @code{x} is an integral value.
16242
16243@multitable @columnfractions .50 .50
16244@item C code @tab MIPS instruction
16245@item @code{a + b} @tab @code{add.ps}
16246@item @code{a - b} @tab @code{sub.ps}
16247@item @code{-a} @tab @code{neg.ps}
16248@item @code{a * b} @tab @code{mul.ps}
16249@item @code{a * b + c} @tab @code{madd.ps}
16250@item @code{a * b - c} @tab @code{msub.ps}
16251@item @code{-(a * b + c)} @tab @code{nmadd.ps}
16252@item @code{-(a * b - c)} @tab @code{nmsub.ps}
16253@item @code{x ? a : b} @tab @code{movn.ps}/@code{movz.ps}
16254@end multitable
16255
16256Note that the multiply-accumulate instructions can be disabled
16257using the command-line option @code{-mno-fused-madd}.
16258
16259@node Paired-Single Built-in Functions
16260@subsubsection Paired-Single Built-in Functions
16261
16262The following paired-single functions map directly to a particular
16263MIPS instruction.  Please refer to the architecture specification
16264for details on what each instruction does.
16265
16266@table @code
16267@item v2sf __builtin_mips_pll_ps (v2sf, v2sf)
16268Pair lower lower (@code{pll.ps}).
16269
16270@item v2sf __builtin_mips_pul_ps (v2sf, v2sf)
16271Pair upper lower (@code{pul.ps}).
16272
16273@item v2sf __builtin_mips_plu_ps (v2sf, v2sf)
16274Pair lower upper (@code{plu.ps}).
16275
16276@item v2sf __builtin_mips_puu_ps (v2sf, v2sf)
16277Pair upper upper (@code{puu.ps}).
16278
16279@item v2sf __builtin_mips_cvt_ps_s (float, float)
16280Convert pair to paired single (@code{cvt.ps.s}).
16281
16282@item float __builtin_mips_cvt_s_pl (v2sf)
16283Convert pair lower to single (@code{cvt.s.pl}).
16284
16285@item float __builtin_mips_cvt_s_pu (v2sf)
16286Convert pair upper to single (@code{cvt.s.pu}).
16287
16288@item v2sf __builtin_mips_abs_ps (v2sf)
16289Absolute value (@code{abs.ps}).
16290
16291@item v2sf __builtin_mips_alnv_ps (v2sf, v2sf, int)
16292Align variable (@code{alnv.ps}).
16293
16294@emph{Note:} The value of the third parameter must be 0 or 4
16295modulo 8, otherwise the result is unpredictable.  Please read the
16296instruction description for details.
16297@end table
16298
16299The following multi-instruction functions are also available.
16300In each case, @var{cond} can be any of the 16 floating-point conditions:
16301@code{f}, @code{un}, @code{eq}, @code{ueq}, @code{olt}, @code{ult},
16302@code{ole}, @code{ule}, @code{sf}, @code{ngle}, @code{seq}, @code{ngl},
16303@code{lt}, @code{nge}, @code{le} or @code{ngt}.
16304
16305@table @code
16306@item v2sf __builtin_mips_movt_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
16307@itemx v2sf __builtin_mips_movf_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
16308Conditional move based on floating-point comparison (@code{c.@var{cond}.ps},
16309@code{movt.ps}/@code{movf.ps}).
16310
16311The @code{movt} functions return the value @var{x} computed by:
16312
16313@smallexample
16314c.@var{cond}.ps @var{cc},@var{a},@var{b}
16315mov.ps @var{x},@var{c}
16316movt.ps @var{x},@var{d},@var{cc}
16317@end smallexample
16318
16319The @code{movf} functions are similar but use @code{movf.ps} instead
16320of @code{movt.ps}.
16321
16322@item int __builtin_mips_upper_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
16323@itemx int __builtin_mips_lower_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
16324Comparison of two paired-single values (@code{c.@var{cond}.ps},
16325@code{bc1t}/@code{bc1f}).
16326
16327These functions compare @var{a} and @var{b} using @code{c.@var{cond}.ps}
16328and return either the upper or lower half of the result.  For example:
16329
16330@smallexample
16331v2sf a, b;
16332if (__builtin_mips_upper_c_eq_ps (a, b))
16333  upper_halves_are_equal ();
16334else
16335  upper_halves_are_unequal ();
16336
16337if (__builtin_mips_lower_c_eq_ps (a, b))
16338  lower_halves_are_equal ();
16339else
16340  lower_halves_are_unequal ();
16341@end smallexample
16342@end table
16343
16344@node MIPS-3D Built-in Functions
16345@subsubsection MIPS-3D Built-in Functions
16346
16347The MIPS-3D Application-Specific Extension (ASE) includes additional
16348paired-single instructions that are designed to improve the performance
16349of 3D graphics operations.  Support for these instructions is controlled
16350by the @option{-mips3d} command-line option.
16351
16352The functions listed below map directly to a particular MIPS-3D
16353instruction.  Please refer to the architecture specification for
16354more details on what each instruction does.
16355
16356@table @code
16357@item v2sf __builtin_mips_addr_ps (v2sf, v2sf)
16358Reduction add (@code{addr.ps}).
16359
16360@item v2sf __builtin_mips_mulr_ps (v2sf, v2sf)
16361Reduction multiply (@code{mulr.ps}).
16362
16363@item v2sf __builtin_mips_cvt_pw_ps (v2sf)
16364Convert paired single to paired word (@code{cvt.pw.ps}).
16365
16366@item v2sf __builtin_mips_cvt_ps_pw (v2sf)
16367Convert paired word to paired single (@code{cvt.ps.pw}).
16368
16369@item float __builtin_mips_recip1_s (float)
16370@itemx double __builtin_mips_recip1_d (double)
16371@itemx v2sf __builtin_mips_recip1_ps (v2sf)
16372Reduced-precision reciprocal (sequence step 1) (@code{recip1.@var{fmt}}).
16373
16374@item float __builtin_mips_recip2_s (float, float)
16375@itemx double __builtin_mips_recip2_d (double, double)
16376@itemx v2sf __builtin_mips_recip2_ps (v2sf, v2sf)
16377Reduced-precision reciprocal (sequence step 2) (@code{recip2.@var{fmt}}).
16378
16379@item float __builtin_mips_rsqrt1_s (float)
16380@itemx double __builtin_mips_rsqrt1_d (double)
16381@itemx v2sf __builtin_mips_rsqrt1_ps (v2sf)
16382Reduced-precision reciprocal square root (sequence step 1)
16383(@code{rsqrt1.@var{fmt}}).
16384
16385@item float __builtin_mips_rsqrt2_s (float, float)
16386@itemx double __builtin_mips_rsqrt2_d (double, double)
16387@itemx v2sf __builtin_mips_rsqrt2_ps (v2sf, v2sf)
16388Reduced-precision reciprocal square root (sequence step 2)
16389(@code{rsqrt2.@var{fmt}}).
16390@end table
16391
16392The following multi-instruction functions are also available.
16393In each case, @var{cond} can be any of the 16 floating-point conditions:
16394@code{f}, @code{un}, @code{eq}, @code{ueq}, @code{olt}, @code{ult},
16395@code{ole}, @code{ule}, @code{sf}, @code{ngle}, @code{seq},
16396@code{ngl}, @code{lt}, @code{nge}, @code{le} or @code{ngt}.
16397
16398@table @code
16399@item int __builtin_mips_cabs_@var{cond}_s (float @var{a}, float @var{b})
16400@itemx int __builtin_mips_cabs_@var{cond}_d (double @var{a}, double @var{b})
16401Absolute comparison of two scalar values (@code{cabs.@var{cond}.@var{fmt}},
16402@code{bc1t}/@code{bc1f}).
16403
16404These functions compare @var{a} and @var{b} using @code{cabs.@var{cond}.s}
16405or @code{cabs.@var{cond}.d} and return the result as a boolean value.
16406For example:
16407
16408@smallexample
16409float a, b;
16410if (__builtin_mips_cabs_eq_s (a, b))
16411  true ();
16412else
16413  false ();
16414@end smallexample
16415
16416@item int __builtin_mips_upper_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
16417@itemx int __builtin_mips_lower_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
16418Absolute comparison of two paired-single values (@code{cabs.@var{cond}.ps},
16419@code{bc1t}/@code{bc1f}).
16420
16421These functions compare @var{a} and @var{b} using @code{cabs.@var{cond}.ps}
16422and return either the upper or lower half of the result.  For example:
16423
16424@smallexample
16425v2sf a, b;
16426if (__builtin_mips_upper_cabs_eq_ps (a, b))
16427  upper_halves_are_equal ();
16428else
16429  upper_halves_are_unequal ();
16430
16431if (__builtin_mips_lower_cabs_eq_ps (a, b))
16432  lower_halves_are_equal ();
16433else
16434  lower_halves_are_unequal ();
16435@end smallexample
16436
16437@item v2sf __builtin_mips_movt_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
16438@itemx v2sf __builtin_mips_movf_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
16439Conditional move based on absolute comparison (@code{cabs.@var{cond}.ps},
16440@code{movt.ps}/@code{movf.ps}).
16441
16442The @code{movt} functions return the value @var{x} computed by:
16443
16444@smallexample
16445cabs.@var{cond}.ps @var{cc},@var{a},@var{b}
16446mov.ps @var{x},@var{c}
16447movt.ps @var{x},@var{d},@var{cc}
16448@end smallexample
16449
16450The @code{movf} functions are similar but use @code{movf.ps} instead
16451of @code{movt.ps}.
16452
16453@item int __builtin_mips_any_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
16454@itemx int __builtin_mips_all_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
16455@itemx int __builtin_mips_any_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
16456@itemx int __builtin_mips_all_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
16457Comparison of two paired-single values
16458(@code{c.@var{cond}.ps}/@code{cabs.@var{cond}.ps},
16459@code{bc1any2t}/@code{bc1any2f}).
16460
16461These functions compare @var{a} and @var{b} using @code{c.@var{cond}.ps}
16462or @code{cabs.@var{cond}.ps}.  The @code{any} forms return @code{true} if either
16463result is @code{true} and the @code{all} forms return @code{true} if both results are @code{true}.
16464For example:
16465
16466@smallexample
16467v2sf a, b;
16468if (__builtin_mips_any_c_eq_ps (a, b))
16469  one_is_true ();
16470else
16471  both_are_false ();
16472
16473if (__builtin_mips_all_c_eq_ps (a, b))
16474  both_are_true ();
16475else
16476  one_is_false ();
16477@end smallexample
16478
16479@item int __builtin_mips_any_c_@var{cond}_4s (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
16480@itemx int __builtin_mips_all_c_@var{cond}_4s (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
16481@itemx int __builtin_mips_any_cabs_@var{cond}_4s (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
16482@itemx int __builtin_mips_all_cabs_@var{cond}_4s (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
16483Comparison of four paired-single values
16484(@code{c.@var{cond}.ps}/@code{cabs.@var{cond}.ps},
16485@code{bc1any4t}/@code{bc1any4f}).
16486
16487These functions use @code{c.@var{cond}.ps} or @code{cabs.@var{cond}.ps}
16488to compare @var{a} with @var{b} and to compare @var{c} with @var{d}.
16489The @code{any} forms return @code{true} if any of the four results are @code{true}
16490and the @code{all} forms return @code{true} if all four results are @code{true}.
16491For example:
16492
16493@smallexample
16494v2sf a, b, c, d;
16495if (__builtin_mips_any_c_eq_4s (a, b, c, d))
16496  some_are_true ();
16497else
16498  all_are_false ();
16499
16500if (__builtin_mips_all_c_eq_4s (a, b, c, d))
16501  all_are_true ();
16502else
16503  some_are_false ();
16504@end smallexample
16505@end table
16506
16507@node MIPS SIMD Architecture (MSA) Support
16508@subsection MIPS SIMD Architecture (MSA) Support
16509
16510@menu
16511* MIPS SIMD Architecture Built-in Functions::
16512@end menu
16513
16514GCC provides intrinsics to access the SIMD instructions provided by the
16515MSA MIPS SIMD Architecture.  The interface is made available by including
16516@code{<msa.h>} and using @option{-mmsa -mhard-float -mfp64 -mnan=2008}.
16517For each @code{__builtin_msa_*}, there is a shortened name of the intrinsic,
16518@code{__msa_*}.
16519
16520MSA implements 128-bit wide vector registers, operating on 8-, 16-, 32- and
1652164-bit integer, 16- and 32-bit fixed-point, or 32- and 64-bit floating point
16522data elements.  The following vectors typedefs are included in @code{msa.h}:
16523@itemize
16524@item @code{v16i8}, a vector of sixteen signed 8-bit integers;
16525@item @code{v16u8}, a vector of sixteen unsigned 8-bit integers;
16526@item @code{v8i16}, a vector of eight signed 16-bit integers;
16527@item @code{v8u16}, a vector of eight unsigned 16-bit integers;
16528@item @code{v4i32}, a vector of four signed 32-bit integers;
16529@item @code{v4u32}, a vector of four unsigned 32-bit integers;
16530@item @code{v2i64}, a vector of two signed 64-bit integers;
16531@item @code{v2u64}, a vector of two unsigned 64-bit integers;
16532@item @code{v4f32}, a vector of four 32-bit floats;
16533@item @code{v2f64}, a vector of two 64-bit doubles.
16534@end itemize
16535
16536Instructions and corresponding built-ins may have additional restrictions and/or
16537input/output values manipulated:
16538@itemize
16539@item @code{imm0_1}, an integer literal in range 0 to 1;
16540@item @code{imm0_3}, an integer literal in range 0 to 3;
16541@item @code{imm0_7}, an integer literal in range 0 to 7;
16542@item @code{imm0_15}, an integer literal in range 0 to 15;
16543@item @code{imm0_31}, an integer literal in range 0 to 31;
16544@item @code{imm0_63}, an integer literal in range 0 to 63;
16545@item @code{imm0_255}, an integer literal in range 0 to 255;
16546@item @code{imm_n16_15}, an integer literal in range -16 to 15;
16547@item @code{imm_n512_511}, an integer literal in range -512 to 511;
16548@item @code{imm_n1024_1022}, an integer literal in range -512 to 511 left
16549shifted by 1 bit, i.e., -1024, -1022, @dots{}, 1020, 1022;
16550@item @code{imm_n2048_2044}, an integer literal in range -512 to 511 left
16551shifted by 2 bits, i.e., -2048, -2044, @dots{}, 2040, 2044;
16552@item @code{imm_n4096_4088}, an integer literal in range -512 to 511 left
16553shifted by 3 bits, i.e., -4096, -4088, @dots{}, 4080, 4088;
16554@item @code{imm1_4}, an integer literal in range 1 to 4;
16555@item @code{i32, i64, u32, u64, f32, f64}, defined as follows:
16556@end itemize
16557
16558@smallexample
16559@{
16560typedef int i32;
16561#if __LONG_MAX__ == __LONG_LONG_MAX__
16562typedef long i64;
16563#else
16564typedef long long i64;
16565#endif
16566
16567typedef unsigned int u32;
16568#if __LONG_MAX__ == __LONG_LONG_MAX__
16569typedef unsigned long u64;
16570#else
16571typedef unsigned long long u64;
16572#endif
16573
16574typedef double f64;
16575typedef float f32;
16576@}
16577@end smallexample
16578
16579@node MIPS SIMD Architecture Built-in Functions
16580@subsubsection MIPS SIMD Architecture Built-in Functions
16581
16582The intrinsics provided are listed below; each is named after the
16583machine instruction.
16584
16585@smallexample
16586v16i8 __builtin_msa_add_a_b (v16i8, v16i8);
16587v8i16 __builtin_msa_add_a_h (v8i16, v8i16);
16588v4i32 __builtin_msa_add_a_w (v4i32, v4i32);
16589v2i64 __builtin_msa_add_a_d (v2i64, v2i64);
16590
16591v16i8 __builtin_msa_adds_a_b (v16i8, v16i8);
16592v8i16 __builtin_msa_adds_a_h (v8i16, v8i16);
16593v4i32 __builtin_msa_adds_a_w (v4i32, v4i32);
16594v2i64 __builtin_msa_adds_a_d (v2i64, v2i64);
16595
16596v16i8 __builtin_msa_adds_s_b (v16i8, v16i8);
16597v8i16 __builtin_msa_adds_s_h (v8i16, v8i16);
16598v4i32 __builtin_msa_adds_s_w (v4i32, v4i32);
16599v2i64 __builtin_msa_adds_s_d (v2i64, v2i64);
16600
16601v16u8 __builtin_msa_adds_u_b (v16u8, v16u8);
16602v8u16 __builtin_msa_adds_u_h (v8u16, v8u16);
16603v4u32 __builtin_msa_adds_u_w (v4u32, v4u32);
16604v2u64 __builtin_msa_adds_u_d (v2u64, v2u64);
16605
16606v16i8 __builtin_msa_addv_b (v16i8, v16i8);
16607v8i16 __builtin_msa_addv_h (v8i16, v8i16);
16608v4i32 __builtin_msa_addv_w (v4i32, v4i32);
16609v2i64 __builtin_msa_addv_d (v2i64, v2i64);
16610
16611v16i8 __builtin_msa_addvi_b (v16i8, imm0_31);
16612v8i16 __builtin_msa_addvi_h (v8i16, imm0_31);
16613v4i32 __builtin_msa_addvi_w (v4i32, imm0_31);
16614v2i64 __builtin_msa_addvi_d (v2i64, imm0_31);
16615
16616v16u8 __builtin_msa_and_v (v16u8, v16u8);
16617
16618v16u8 __builtin_msa_andi_b (v16u8, imm0_255);
16619
16620v16i8 __builtin_msa_asub_s_b (v16i8, v16i8);
16621v8i16 __builtin_msa_asub_s_h (v8i16, v8i16);
16622v4i32 __builtin_msa_asub_s_w (v4i32, v4i32);
16623v2i64 __builtin_msa_asub_s_d (v2i64, v2i64);
16624
16625v16u8 __builtin_msa_asub_u_b (v16u8, v16u8);
16626v8u16 __builtin_msa_asub_u_h (v8u16, v8u16);
16627v4u32 __builtin_msa_asub_u_w (v4u32, v4u32);
16628v2u64 __builtin_msa_asub_u_d (v2u64, v2u64);
16629
16630v16i8 __builtin_msa_ave_s_b (v16i8, v16i8);
16631v8i16 __builtin_msa_ave_s_h (v8i16, v8i16);
16632v4i32 __builtin_msa_ave_s_w (v4i32, v4i32);
16633v2i64 __builtin_msa_ave_s_d (v2i64, v2i64);
16634
16635v16u8 __builtin_msa_ave_u_b (v16u8, v16u8);
16636v8u16 __builtin_msa_ave_u_h (v8u16, v8u16);
16637v4u32 __builtin_msa_ave_u_w (v4u32, v4u32);
16638v2u64 __builtin_msa_ave_u_d (v2u64, v2u64);
16639
16640v16i8 __builtin_msa_aver_s_b (v16i8, v16i8);
16641v8i16 __builtin_msa_aver_s_h (v8i16, v8i16);
16642v4i32 __builtin_msa_aver_s_w (v4i32, v4i32);
16643v2i64 __builtin_msa_aver_s_d (v2i64, v2i64);
16644
16645v16u8 __builtin_msa_aver_u_b (v16u8, v16u8);
16646v8u16 __builtin_msa_aver_u_h (v8u16, v8u16);
16647v4u32 __builtin_msa_aver_u_w (v4u32, v4u32);
16648v2u64 __builtin_msa_aver_u_d (v2u64, v2u64);
16649
16650v16u8 __builtin_msa_bclr_b (v16u8, v16u8);
16651v8u16 __builtin_msa_bclr_h (v8u16, v8u16);
16652v4u32 __builtin_msa_bclr_w (v4u32, v4u32);
16653v2u64 __builtin_msa_bclr_d (v2u64, v2u64);
16654
16655v16u8 __builtin_msa_bclri_b (v16u8, imm0_7);
16656v8u16 __builtin_msa_bclri_h (v8u16, imm0_15);
16657v4u32 __builtin_msa_bclri_w (v4u32, imm0_31);
16658v2u64 __builtin_msa_bclri_d (v2u64, imm0_63);
16659
16660v16u8 __builtin_msa_binsl_b (v16u8, v16u8, v16u8);
16661v8u16 __builtin_msa_binsl_h (v8u16, v8u16, v8u16);
16662v4u32 __builtin_msa_binsl_w (v4u32, v4u32, v4u32);
16663v2u64 __builtin_msa_binsl_d (v2u64, v2u64, v2u64);
16664
16665v16u8 __builtin_msa_binsli_b (v16u8, v16u8, imm0_7);
16666v8u16 __builtin_msa_binsli_h (v8u16, v8u16, imm0_15);
16667v4u32 __builtin_msa_binsli_w (v4u32, v4u32, imm0_31);
16668v2u64 __builtin_msa_binsli_d (v2u64, v2u64, imm0_63);
16669
16670v16u8 __builtin_msa_binsr_b (v16u8, v16u8, v16u8);
16671v8u16 __builtin_msa_binsr_h (v8u16, v8u16, v8u16);
16672v4u32 __builtin_msa_binsr_w (v4u32, v4u32, v4u32);
16673v2u64 __builtin_msa_binsr_d (v2u64, v2u64, v2u64);
16674
16675v16u8 __builtin_msa_binsri_b (v16u8, v16u8, imm0_7);
16676v8u16 __builtin_msa_binsri_h (v8u16, v8u16, imm0_15);
16677v4u32 __builtin_msa_binsri_w (v4u32, v4u32, imm0_31);
16678v2u64 __builtin_msa_binsri_d (v2u64, v2u64, imm0_63);
16679
16680v16u8 __builtin_msa_bmnz_v (v16u8, v16u8, v16u8);
16681
16682v16u8 __builtin_msa_bmnzi_b (v16u8, v16u8, imm0_255);
16683
16684v16u8 __builtin_msa_bmz_v (v16u8, v16u8, v16u8);
16685
16686v16u8 __builtin_msa_bmzi_b (v16u8, v16u8, imm0_255);
16687
16688v16u8 __builtin_msa_bneg_b (v16u8, v16u8);
16689v8u16 __builtin_msa_bneg_h (v8u16, v8u16);
16690v4u32 __builtin_msa_bneg_w (v4u32, v4u32);
16691v2u64 __builtin_msa_bneg_d (v2u64, v2u64);
16692
16693v16u8 __builtin_msa_bnegi_b (v16u8, imm0_7);
16694v8u16 __builtin_msa_bnegi_h (v8u16, imm0_15);
16695v4u32 __builtin_msa_bnegi_w (v4u32, imm0_31);
16696v2u64 __builtin_msa_bnegi_d (v2u64, imm0_63);
16697
16698i32 __builtin_msa_bnz_b (v16u8);
16699i32 __builtin_msa_bnz_h (v8u16);
16700i32 __builtin_msa_bnz_w (v4u32);
16701i32 __builtin_msa_bnz_d (v2u64);
16702
16703i32 __builtin_msa_bnz_v (v16u8);
16704
16705v16u8 __builtin_msa_bsel_v (v16u8, v16u8, v16u8);
16706
16707v16u8 __builtin_msa_bseli_b (v16u8, v16u8, imm0_255);
16708
16709v16u8 __builtin_msa_bset_b (v16u8, v16u8);
16710v8u16 __builtin_msa_bset_h (v8u16, v8u16);
16711v4u32 __builtin_msa_bset_w (v4u32, v4u32);
16712v2u64 __builtin_msa_bset_d (v2u64, v2u64);
16713
16714v16u8 __builtin_msa_bseti_b (v16u8, imm0_7);
16715v8u16 __builtin_msa_bseti_h (v8u16, imm0_15);
16716v4u32 __builtin_msa_bseti_w (v4u32, imm0_31);
16717v2u64 __builtin_msa_bseti_d (v2u64, imm0_63);
16718
16719i32 __builtin_msa_bz_b (v16u8);
16720i32 __builtin_msa_bz_h (v8u16);
16721i32 __builtin_msa_bz_w (v4u32);
16722i32 __builtin_msa_bz_d (v2u64);
16723
16724i32 __builtin_msa_bz_v (v16u8);
16725
16726v16i8 __builtin_msa_ceq_b (v16i8, v16i8);
16727v8i16 __builtin_msa_ceq_h (v8i16, v8i16);
16728v4i32 __builtin_msa_ceq_w (v4i32, v4i32);
16729v2i64 __builtin_msa_ceq_d (v2i64, v2i64);
16730
16731v16i8 __builtin_msa_ceqi_b (v16i8, imm_n16_15);
16732v8i16 __builtin_msa_ceqi_h (v8i16, imm_n16_15);
16733v4i32 __builtin_msa_ceqi_w (v4i32, imm_n16_15);
16734v2i64 __builtin_msa_ceqi_d (v2i64, imm_n16_15);
16735
16736i32 __builtin_msa_cfcmsa (imm0_31);
16737
16738v16i8 __builtin_msa_cle_s_b (v16i8, v16i8);
16739v8i16 __builtin_msa_cle_s_h (v8i16, v8i16);
16740v4i32 __builtin_msa_cle_s_w (v4i32, v4i32);
16741v2i64 __builtin_msa_cle_s_d (v2i64, v2i64);
16742
16743v16i8 __builtin_msa_cle_u_b (v16u8, v16u8);
16744v8i16 __builtin_msa_cle_u_h (v8u16, v8u16);
16745v4i32 __builtin_msa_cle_u_w (v4u32, v4u32);
16746v2i64 __builtin_msa_cle_u_d (v2u64, v2u64);
16747
16748v16i8 __builtin_msa_clei_s_b (v16i8, imm_n16_15);
16749v8i16 __builtin_msa_clei_s_h (v8i16, imm_n16_15);
16750v4i32 __builtin_msa_clei_s_w (v4i32, imm_n16_15);
16751v2i64 __builtin_msa_clei_s_d (v2i64, imm_n16_15);
16752
16753v16i8 __builtin_msa_clei_u_b (v16u8, imm0_31);
16754v8i16 __builtin_msa_clei_u_h (v8u16, imm0_31);
16755v4i32 __builtin_msa_clei_u_w (v4u32, imm0_31);
16756v2i64 __builtin_msa_clei_u_d (v2u64, imm0_31);
16757
16758v16i8 __builtin_msa_clt_s_b (v16i8, v16i8);
16759v8i16 __builtin_msa_clt_s_h (v8i16, v8i16);
16760v4i32 __builtin_msa_clt_s_w (v4i32, v4i32);
16761v2i64 __builtin_msa_clt_s_d (v2i64, v2i64);
16762
16763v16i8 __builtin_msa_clt_u_b (v16u8, v16u8);
16764v8i16 __builtin_msa_clt_u_h (v8u16, v8u16);
16765v4i32 __builtin_msa_clt_u_w (v4u32, v4u32);
16766v2i64 __builtin_msa_clt_u_d (v2u64, v2u64);
16767
16768v16i8 __builtin_msa_clti_s_b (v16i8, imm_n16_15);
16769v8i16 __builtin_msa_clti_s_h (v8i16, imm_n16_15);
16770v4i32 __builtin_msa_clti_s_w (v4i32, imm_n16_15);
16771v2i64 __builtin_msa_clti_s_d (v2i64, imm_n16_15);
16772
16773v16i8 __builtin_msa_clti_u_b (v16u8, imm0_31);
16774v8i16 __builtin_msa_clti_u_h (v8u16, imm0_31);
16775v4i32 __builtin_msa_clti_u_w (v4u32, imm0_31);
16776v2i64 __builtin_msa_clti_u_d (v2u64, imm0_31);
16777
16778i32 __builtin_msa_copy_s_b (v16i8, imm0_15);
16779i32 __builtin_msa_copy_s_h (v8i16, imm0_7);
16780i32 __builtin_msa_copy_s_w (v4i32, imm0_3);
16781i64 __builtin_msa_copy_s_d (v2i64, imm0_1);
16782
16783u32 __builtin_msa_copy_u_b (v16i8, imm0_15);
16784u32 __builtin_msa_copy_u_h (v8i16, imm0_7);
16785u32 __builtin_msa_copy_u_w (v4i32, imm0_3);
16786u64 __builtin_msa_copy_u_d (v2i64, imm0_1);
16787
16788void __builtin_msa_ctcmsa (imm0_31, i32);
16789
16790v16i8 __builtin_msa_div_s_b (v16i8, v16i8);
16791v8i16 __builtin_msa_div_s_h (v8i16, v8i16);
16792v4i32 __builtin_msa_div_s_w (v4i32, v4i32);
16793v2i64 __builtin_msa_div_s_d (v2i64, v2i64);
16794
16795v16u8 __builtin_msa_div_u_b (v16u8, v16u8);
16796v8u16 __builtin_msa_div_u_h (v8u16, v8u16);
16797v4u32 __builtin_msa_div_u_w (v4u32, v4u32);
16798v2u64 __builtin_msa_div_u_d (v2u64, v2u64);
16799
16800v8i16 __builtin_msa_dotp_s_h (v16i8, v16i8);
16801v4i32 __builtin_msa_dotp_s_w (v8i16, v8i16);
16802v2i64 __builtin_msa_dotp_s_d (v4i32, v4i32);
16803
16804v8u16 __builtin_msa_dotp_u_h (v16u8, v16u8);
16805v4u32 __builtin_msa_dotp_u_w (v8u16, v8u16);
16806v2u64 __builtin_msa_dotp_u_d (v4u32, v4u32);
16807
16808v8i16 __builtin_msa_dpadd_s_h (v8i16, v16i8, v16i8);
16809v4i32 __builtin_msa_dpadd_s_w (v4i32, v8i16, v8i16);
16810v2i64 __builtin_msa_dpadd_s_d (v2i64, v4i32, v4i32);
16811
16812v8u16 __builtin_msa_dpadd_u_h (v8u16, v16u8, v16u8);
16813v4u32 __builtin_msa_dpadd_u_w (v4u32, v8u16, v8u16);
16814v2u64 __builtin_msa_dpadd_u_d (v2u64, v4u32, v4u32);
16815
16816v8i16 __builtin_msa_dpsub_s_h (v8i16, v16i8, v16i8);
16817v4i32 __builtin_msa_dpsub_s_w (v4i32, v8i16, v8i16);
16818v2i64 __builtin_msa_dpsub_s_d (v2i64, v4i32, v4i32);
16819
16820v8i16 __builtin_msa_dpsub_u_h (v8i16, v16u8, v16u8);
16821v4i32 __builtin_msa_dpsub_u_w (v4i32, v8u16, v8u16);
16822v2i64 __builtin_msa_dpsub_u_d (v2i64, v4u32, v4u32);
16823
16824v4f32 __builtin_msa_fadd_w (v4f32, v4f32);
16825v2f64 __builtin_msa_fadd_d (v2f64, v2f64);
16826
16827v4i32 __builtin_msa_fcaf_w (v4f32, v4f32);
16828v2i64 __builtin_msa_fcaf_d (v2f64, v2f64);
16829
16830v4i32 __builtin_msa_fceq_w (v4f32, v4f32);
16831v2i64 __builtin_msa_fceq_d (v2f64, v2f64);
16832
16833v4i32 __builtin_msa_fclass_w (v4f32);
16834v2i64 __builtin_msa_fclass_d (v2f64);
16835
16836v4i32 __builtin_msa_fcle_w (v4f32, v4f32);
16837v2i64 __builtin_msa_fcle_d (v2f64, v2f64);
16838
16839v4i32 __builtin_msa_fclt_w (v4f32, v4f32);
16840v2i64 __builtin_msa_fclt_d (v2f64, v2f64);
16841
16842v4i32 __builtin_msa_fcne_w (v4f32, v4f32);
16843v2i64 __builtin_msa_fcne_d (v2f64, v2f64);
16844
16845v4i32 __builtin_msa_fcor_w (v4f32, v4f32);
16846v2i64 __builtin_msa_fcor_d (v2f64, v2f64);
16847
16848v4i32 __builtin_msa_fcueq_w (v4f32, v4f32);
16849v2i64 __builtin_msa_fcueq_d (v2f64, v2f64);
16850
16851v4i32 __builtin_msa_fcule_w (v4f32, v4f32);
16852v2i64 __builtin_msa_fcule_d (v2f64, v2f64);
16853
16854v4i32 __builtin_msa_fcult_w (v4f32, v4f32);
16855v2i64 __builtin_msa_fcult_d (v2f64, v2f64);
16856
16857v4i32 __builtin_msa_fcun_w (v4f32, v4f32);
16858v2i64 __builtin_msa_fcun_d (v2f64, v2f64);
16859
16860v4i32 __builtin_msa_fcune_w (v4f32, v4f32);
16861v2i64 __builtin_msa_fcune_d (v2f64, v2f64);
16862
16863v4f32 __builtin_msa_fdiv_w (v4f32, v4f32);
16864v2f64 __builtin_msa_fdiv_d (v2f64, v2f64);
16865
16866v8i16 __builtin_msa_fexdo_h (v4f32, v4f32);
16867v4f32 __builtin_msa_fexdo_w (v2f64, v2f64);
16868
16869v4f32 __builtin_msa_fexp2_w (v4f32, v4i32);
16870v2f64 __builtin_msa_fexp2_d (v2f64, v2i64);
16871
16872v4f32 __builtin_msa_fexupl_w (v8i16);
16873v2f64 __builtin_msa_fexupl_d (v4f32);
16874
16875v4f32 __builtin_msa_fexupr_w (v8i16);
16876v2f64 __builtin_msa_fexupr_d (v4f32);
16877
16878v4f32 __builtin_msa_ffint_s_w (v4i32);
16879v2f64 __builtin_msa_ffint_s_d (v2i64);
16880
16881v4f32 __builtin_msa_ffint_u_w (v4u32);
16882v2f64 __builtin_msa_ffint_u_d (v2u64);
16883
16884v4f32 __builtin_msa_ffql_w (v8i16);
16885v2f64 __builtin_msa_ffql_d (v4i32);
16886
16887v4f32 __builtin_msa_ffqr_w (v8i16);
16888v2f64 __builtin_msa_ffqr_d (v4i32);
16889
16890v16i8 __builtin_msa_fill_b (i32);
16891v8i16 __builtin_msa_fill_h (i32);
16892v4i32 __builtin_msa_fill_w (i32);
16893v2i64 __builtin_msa_fill_d (i64);
16894
16895v4f32 __builtin_msa_flog2_w (v4f32);
16896v2f64 __builtin_msa_flog2_d (v2f64);
16897
16898v4f32 __builtin_msa_fmadd_w (v4f32, v4f32, v4f32);
16899v2f64 __builtin_msa_fmadd_d (v2f64, v2f64, v2f64);
16900
16901v4f32 __builtin_msa_fmax_w (v4f32, v4f32);
16902v2f64 __builtin_msa_fmax_d (v2f64, v2f64);
16903
16904v4f32 __builtin_msa_fmax_a_w (v4f32, v4f32);
16905v2f64 __builtin_msa_fmax_a_d (v2f64, v2f64);
16906
16907v4f32 __builtin_msa_fmin_w (v4f32, v4f32);
16908v2f64 __builtin_msa_fmin_d (v2f64, v2f64);
16909
16910v4f32 __builtin_msa_fmin_a_w (v4f32, v4f32);
16911v2f64 __builtin_msa_fmin_a_d (v2f64, v2f64);
16912
16913v4f32 __builtin_msa_fmsub_w (v4f32, v4f32, v4f32);
16914v2f64 __builtin_msa_fmsub_d (v2f64, v2f64, v2f64);
16915
16916v4f32 __builtin_msa_fmul_w (v4f32, v4f32);
16917v2f64 __builtin_msa_fmul_d (v2f64, v2f64);
16918
16919v4f32 __builtin_msa_frint_w (v4f32);
16920v2f64 __builtin_msa_frint_d (v2f64);
16921
16922v4f32 __builtin_msa_frcp_w (v4f32);
16923v2f64 __builtin_msa_frcp_d (v2f64);
16924
16925v4f32 __builtin_msa_frsqrt_w (v4f32);
16926v2f64 __builtin_msa_frsqrt_d (v2f64);
16927
16928v4i32 __builtin_msa_fsaf_w (v4f32, v4f32);
16929v2i64 __builtin_msa_fsaf_d (v2f64, v2f64);
16930
16931v4i32 __builtin_msa_fseq_w (v4f32, v4f32);
16932v2i64 __builtin_msa_fseq_d (v2f64, v2f64);
16933
16934v4i32 __builtin_msa_fsle_w (v4f32, v4f32);
16935v2i64 __builtin_msa_fsle_d (v2f64, v2f64);
16936
16937v4i32 __builtin_msa_fslt_w (v4f32, v4f32);
16938v2i64 __builtin_msa_fslt_d (v2f64, v2f64);
16939
16940v4i32 __builtin_msa_fsne_w (v4f32, v4f32);
16941v2i64 __builtin_msa_fsne_d (v2f64, v2f64);
16942
16943v4i32 __builtin_msa_fsor_w (v4f32, v4f32);
16944v2i64 __builtin_msa_fsor_d (v2f64, v2f64);
16945
16946v4f32 __builtin_msa_fsqrt_w (v4f32);
16947v2f64 __builtin_msa_fsqrt_d (v2f64);
16948
16949v4f32 __builtin_msa_fsub_w (v4f32, v4f32);
16950v2f64 __builtin_msa_fsub_d (v2f64, v2f64);
16951
16952v4i32 __builtin_msa_fsueq_w (v4f32, v4f32);
16953v2i64 __builtin_msa_fsueq_d (v2f64, v2f64);
16954
16955v4i32 __builtin_msa_fsule_w (v4f32, v4f32);
16956v2i64 __builtin_msa_fsule_d (v2f64, v2f64);
16957
16958v4i32 __builtin_msa_fsult_w (v4f32, v4f32);
16959v2i64 __builtin_msa_fsult_d (v2f64, v2f64);
16960
16961v4i32 __builtin_msa_fsun_w (v4f32, v4f32);
16962v2i64 __builtin_msa_fsun_d (v2f64, v2f64);
16963
16964v4i32 __builtin_msa_fsune_w (v4f32, v4f32);
16965v2i64 __builtin_msa_fsune_d (v2f64, v2f64);
16966
16967v4i32 __builtin_msa_ftint_s_w (v4f32);
16968v2i64 __builtin_msa_ftint_s_d (v2f64);
16969
16970v4u32 __builtin_msa_ftint_u_w (v4f32);
16971v2u64 __builtin_msa_ftint_u_d (v2f64);
16972
16973v8i16 __builtin_msa_ftq_h (v4f32, v4f32);
16974v4i32 __builtin_msa_ftq_w (v2f64, v2f64);
16975
16976v4i32 __builtin_msa_ftrunc_s_w (v4f32);
16977v2i64 __builtin_msa_ftrunc_s_d (v2f64);
16978
16979v4u32 __builtin_msa_ftrunc_u_w (v4f32);
16980v2u64 __builtin_msa_ftrunc_u_d (v2f64);
16981
16982v8i16 __builtin_msa_hadd_s_h (v16i8, v16i8);
16983v4i32 __builtin_msa_hadd_s_w (v8i16, v8i16);
16984v2i64 __builtin_msa_hadd_s_d (v4i32, v4i32);
16985
16986v8u16 __builtin_msa_hadd_u_h (v16u8, v16u8);
16987v4u32 __builtin_msa_hadd_u_w (v8u16, v8u16);
16988v2u64 __builtin_msa_hadd_u_d (v4u32, v4u32);
16989
16990v8i16 __builtin_msa_hsub_s_h (v16i8, v16i8);
16991v4i32 __builtin_msa_hsub_s_w (v8i16, v8i16);
16992v2i64 __builtin_msa_hsub_s_d (v4i32, v4i32);
16993
16994v8i16 __builtin_msa_hsub_u_h (v16u8, v16u8);
16995v4i32 __builtin_msa_hsub_u_w (v8u16, v8u16);
16996v2i64 __builtin_msa_hsub_u_d (v4u32, v4u32);
16997
16998v16i8 __builtin_msa_ilvev_b (v16i8, v16i8);
16999v8i16 __builtin_msa_ilvev_h (v8i16, v8i16);
17000v4i32 __builtin_msa_ilvev_w (v4i32, v4i32);
17001v2i64 __builtin_msa_ilvev_d (v2i64, v2i64);
17002
17003v16i8 __builtin_msa_ilvl_b (v16i8, v16i8);
17004v8i16 __builtin_msa_ilvl_h (v8i16, v8i16);
17005v4i32 __builtin_msa_ilvl_w (v4i32, v4i32);
17006v2i64 __builtin_msa_ilvl_d (v2i64, v2i64);
17007
17008v16i8 __builtin_msa_ilvod_b (v16i8, v16i8);
17009v8i16 __builtin_msa_ilvod_h (v8i16, v8i16);
17010v4i32 __builtin_msa_ilvod_w (v4i32, v4i32);
17011v2i64 __builtin_msa_ilvod_d (v2i64, v2i64);
17012
17013v16i8 __builtin_msa_ilvr_b (v16i8, v16i8);
17014v8i16 __builtin_msa_ilvr_h (v8i16, v8i16);
17015v4i32 __builtin_msa_ilvr_w (v4i32, v4i32);
17016v2i64 __builtin_msa_ilvr_d (v2i64, v2i64);
17017
17018v16i8 __builtin_msa_insert_b (v16i8, imm0_15, i32);
17019v8i16 __builtin_msa_insert_h (v8i16, imm0_7, i32);
17020v4i32 __builtin_msa_insert_w (v4i32, imm0_3, i32);
17021v2i64 __builtin_msa_insert_d (v2i64, imm0_1, i64);
17022
17023v16i8 __builtin_msa_insve_b (v16i8, imm0_15, v16i8);
17024v8i16 __builtin_msa_insve_h (v8i16, imm0_7, v8i16);
17025v4i32 __builtin_msa_insve_w (v4i32, imm0_3, v4i32);
17026v2i64 __builtin_msa_insve_d (v2i64, imm0_1, v2i64);
17027
17028v16i8 __builtin_msa_ld_b (const void *, imm_n512_511);
17029v8i16 __builtin_msa_ld_h (const void *, imm_n1024_1022);
17030v4i32 __builtin_msa_ld_w (const void *, imm_n2048_2044);
17031v2i64 __builtin_msa_ld_d (const void *, imm_n4096_4088);
17032
17033v16i8 __builtin_msa_ldi_b (imm_n512_511);
17034v8i16 __builtin_msa_ldi_h (imm_n512_511);
17035v4i32 __builtin_msa_ldi_w (imm_n512_511);
17036v2i64 __builtin_msa_ldi_d (imm_n512_511);
17037
17038v8i16 __builtin_msa_madd_q_h (v8i16, v8i16, v8i16);
17039v4i32 __builtin_msa_madd_q_w (v4i32, v4i32, v4i32);
17040
17041v8i16 __builtin_msa_maddr_q_h (v8i16, v8i16, v8i16);
17042v4i32 __builtin_msa_maddr_q_w (v4i32, v4i32, v4i32);
17043
17044v16i8 __builtin_msa_maddv_b (v16i8, v16i8, v16i8);
17045v8i16 __builtin_msa_maddv_h (v8i16, v8i16, v8i16);
17046v4i32 __builtin_msa_maddv_w (v4i32, v4i32, v4i32);
17047v2i64 __builtin_msa_maddv_d (v2i64, v2i64, v2i64);
17048
17049v16i8 __builtin_msa_max_a_b (v16i8, v16i8);
17050v8i16 __builtin_msa_max_a_h (v8i16, v8i16);
17051v4i32 __builtin_msa_max_a_w (v4i32, v4i32);
17052v2i64 __builtin_msa_max_a_d (v2i64, v2i64);
17053
17054v16i8 __builtin_msa_max_s_b (v16i8, v16i8);
17055v8i16 __builtin_msa_max_s_h (v8i16, v8i16);
17056v4i32 __builtin_msa_max_s_w (v4i32, v4i32);
17057v2i64 __builtin_msa_max_s_d (v2i64, v2i64);
17058
17059v16u8 __builtin_msa_max_u_b (v16u8, v16u8);
17060v8u16 __builtin_msa_max_u_h (v8u16, v8u16);
17061v4u32 __builtin_msa_max_u_w (v4u32, v4u32);
17062v2u64 __builtin_msa_max_u_d (v2u64, v2u64);
17063
17064v16i8 __builtin_msa_maxi_s_b (v16i8, imm_n16_15);
17065v8i16 __builtin_msa_maxi_s_h (v8i16, imm_n16_15);
17066v4i32 __builtin_msa_maxi_s_w (v4i32, imm_n16_15);
17067v2i64 __builtin_msa_maxi_s_d (v2i64, imm_n16_15);
17068
17069v16u8 __builtin_msa_maxi_u_b (v16u8, imm0_31);
17070v8u16 __builtin_msa_maxi_u_h (v8u16, imm0_31);
17071v4u32 __builtin_msa_maxi_u_w (v4u32, imm0_31);
17072v2u64 __builtin_msa_maxi_u_d (v2u64, imm0_31);
17073
17074v16i8 __builtin_msa_min_a_b (v16i8, v16i8);
17075v8i16 __builtin_msa_min_a_h (v8i16, v8i16);
17076v4i32 __builtin_msa_min_a_w (v4i32, v4i32);
17077v2i64 __builtin_msa_min_a_d (v2i64, v2i64);
17078
17079v16i8 __builtin_msa_min_s_b (v16i8, v16i8);
17080v8i16 __builtin_msa_min_s_h (v8i16, v8i16);
17081v4i32 __builtin_msa_min_s_w (v4i32, v4i32);
17082v2i64 __builtin_msa_min_s_d (v2i64, v2i64);
17083
17084v16u8 __builtin_msa_min_u_b (v16u8, v16u8);
17085v8u16 __builtin_msa_min_u_h (v8u16, v8u16);
17086v4u32 __builtin_msa_min_u_w (v4u32, v4u32);
17087v2u64 __builtin_msa_min_u_d (v2u64, v2u64);
17088
17089v16i8 __builtin_msa_mini_s_b (v16i8, imm_n16_15);
17090v8i16 __builtin_msa_mini_s_h (v8i16, imm_n16_15);
17091v4i32 __builtin_msa_mini_s_w (v4i32, imm_n16_15);
17092v2i64 __builtin_msa_mini_s_d (v2i64, imm_n16_15);
17093
17094v16u8 __builtin_msa_mini_u_b (v16u8, imm0_31);
17095v8u16 __builtin_msa_mini_u_h (v8u16, imm0_31);
17096v4u32 __builtin_msa_mini_u_w (v4u32, imm0_31);
17097v2u64 __builtin_msa_mini_u_d (v2u64, imm0_31);
17098
17099v16i8 __builtin_msa_mod_s_b (v16i8, v16i8);
17100v8i16 __builtin_msa_mod_s_h (v8i16, v8i16);
17101v4i32 __builtin_msa_mod_s_w (v4i32, v4i32);
17102v2i64 __builtin_msa_mod_s_d (v2i64, v2i64);
17103
17104v16u8 __builtin_msa_mod_u_b (v16u8, v16u8);
17105v8u16 __builtin_msa_mod_u_h (v8u16, v8u16);
17106v4u32 __builtin_msa_mod_u_w (v4u32, v4u32);
17107v2u64 __builtin_msa_mod_u_d (v2u64, v2u64);
17108
17109v16i8 __builtin_msa_move_v (v16i8);
17110
17111v8i16 __builtin_msa_msub_q_h (v8i16, v8i16, v8i16);
17112v4i32 __builtin_msa_msub_q_w (v4i32, v4i32, v4i32);
17113
17114v8i16 __builtin_msa_msubr_q_h (v8i16, v8i16, v8i16);
17115v4i32 __builtin_msa_msubr_q_w (v4i32, v4i32, v4i32);
17116
17117v16i8 __builtin_msa_msubv_b (v16i8, v16i8, v16i8);
17118v8i16 __builtin_msa_msubv_h (v8i16, v8i16, v8i16);
17119v4i32 __builtin_msa_msubv_w (v4i32, v4i32, v4i32);
17120v2i64 __builtin_msa_msubv_d (v2i64, v2i64, v2i64);
17121
17122v8i16 __builtin_msa_mul_q_h (v8i16, v8i16);
17123v4i32 __builtin_msa_mul_q_w (v4i32, v4i32);
17124
17125v8i16 __builtin_msa_mulr_q_h (v8i16, v8i16);
17126v4i32 __builtin_msa_mulr_q_w (v4i32, v4i32);
17127
17128v16i8 __builtin_msa_mulv_b (v16i8, v16i8);
17129v8i16 __builtin_msa_mulv_h (v8i16, v8i16);
17130v4i32 __builtin_msa_mulv_w (v4i32, v4i32);
17131v2i64 __builtin_msa_mulv_d (v2i64, v2i64);
17132
17133v16i8 __builtin_msa_nloc_b (v16i8);
17134v8i16 __builtin_msa_nloc_h (v8i16);
17135v4i32 __builtin_msa_nloc_w (v4i32);
17136v2i64 __builtin_msa_nloc_d (v2i64);
17137
17138v16i8 __builtin_msa_nlzc_b (v16i8);
17139v8i16 __builtin_msa_nlzc_h (v8i16);
17140v4i32 __builtin_msa_nlzc_w (v4i32);
17141v2i64 __builtin_msa_nlzc_d (v2i64);
17142
17143v16u8 __builtin_msa_nor_v (v16u8, v16u8);
17144
17145v16u8 __builtin_msa_nori_b (v16u8, imm0_255);
17146
17147v16u8 __builtin_msa_or_v (v16u8, v16u8);
17148
17149v16u8 __builtin_msa_ori_b (v16u8, imm0_255);
17150
17151v16i8 __builtin_msa_pckev_b (v16i8, v16i8);
17152v8i16 __builtin_msa_pckev_h (v8i16, v8i16);
17153v4i32 __builtin_msa_pckev_w (v4i32, v4i32);
17154v2i64 __builtin_msa_pckev_d (v2i64, v2i64);
17155
17156v16i8 __builtin_msa_pckod_b (v16i8, v16i8);
17157v8i16 __builtin_msa_pckod_h (v8i16, v8i16);
17158v4i32 __builtin_msa_pckod_w (v4i32, v4i32);
17159v2i64 __builtin_msa_pckod_d (v2i64, v2i64);
17160
17161v16i8 __builtin_msa_pcnt_b (v16i8);
17162v8i16 __builtin_msa_pcnt_h (v8i16);
17163v4i32 __builtin_msa_pcnt_w (v4i32);
17164v2i64 __builtin_msa_pcnt_d (v2i64);
17165
17166v16i8 __builtin_msa_sat_s_b (v16i8, imm0_7);
17167v8i16 __builtin_msa_sat_s_h (v8i16, imm0_15);
17168v4i32 __builtin_msa_sat_s_w (v4i32, imm0_31);
17169v2i64 __builtin_msa_sat_s_d (v2i64, imm0_63);
17170
17171v16u8 __builtin_msa_sat_u_b (v16u8, imm0_7);
17172v8u16 __builtin_msa_sat_u_h (v8u16, imm0_15);
17173v4u32 __builtin_msa_sat_u_w (v4u32, imm0_31);
17174v2u64 __builtin_msa_sat_u_d (v2u64, imm0_63);
17175
17176v16i8 __builtin_msa_shf_b (v16i8, imm0_255);
17177v8i16 __builtin_msa_shf_h (v8i16, imm0_255);
17178v4i32 __builtin_msa_shf_w (v4i32, imm0_255);
17179
17180v16i8 __builtin_msa_sld_b (v16i8, v16i8, i32);
17181v8i16 __builtin_msa_sld_h (v8i16, v8i16, i32);
17182v4i32 __builtin_msa_sld_w (v4i32, v4i32, i32);
17183v2i64 __builtin_msa_sld_d (v2i64, v2i64, i32);
17184
17185v16i8 __builtin_msa_sldi_b (v16i8, v16i8, imm0_15);
17186v8i16 __builtin_msa_sldi_h (v8i16, v8i16, imm0_7);
17187v4i32 __builtin_msa_sldi_w (v4i32, v4i32, imm0_3);
17188v2i64 __builtin_msa_sldi_d (v2i64, v2i64, imm0_1);
17189
17190v16i8 __builtin_msa_sll_b (v16i8, v16i8);
17191v8i16 __builtin_msa_sll_h (v8i16, v8i16);
17192v4i32 __builtin_msa_sll_w (v4i32, v4i32);
17193v2i64 __builtin_msa_sll_d (v2i64, v2i64);
17194
17195v16i8 __builtin_msa_slli_b (v16i8, imm0_7);
17196v8i16 __builtin_msa_slli_h (v8i16, imm0_15);
17197v4i32 __builtin_msa_slli_w (v4i32, imm0_31);
17198v2i64 __builtin_msa_slli_d (v2i64, imm0_63);
17199
17200v16i8 __builtin_msa_splat_b (v16i8, i32);
17201v8i16 __builtin_msa_splat_h (v8i16, i32);
17202v4i32 __builtin_msa_splat_w (v4i32, i32);
17203v2i64 __builtin_msa_splat_d (v2i64, i32);
17204
17205v16i8 __builtin_msa_splati_b (v16i8, imm0_15);
17206v8i16 __builtin_msa_splati_h (v8i16, imm0_7);
17207v4i32 __builtin_msa_splati_w (v4i32, imm0_3);
17208v2i64 __builtin_msa_splati_d (v2i64, imm0_1);
17209
17210v16i8 __builtin_msa_sra_b (v16i8, v16i8);
17211v8i16 __builtin_msa_sra_h (v8i16, v8i16);
17212v4i32 __builtin_msa_sra_w (v4i32, v4i32);
17213v2i64 __builtin_msa_sra_d (v2i64, v2i64);
17214
17215v16i8 __builtin_msa_srai_b (v16i8, imm0_7);
17216v8i16 __builtin_msa_srai_h (v8i16, imm0_15);
17217v4i32 __builtin_msa_srai_w (v4i32, imm0_31);
17218v2i64 __builtin_msa_srai_d (v2i64, imm0_63);
17219
17220v16i8 __builtin_msa_srar_b (v16i8, v16i8);
17221v8i16 __builtin_msa_srar_h (v8i16, v8i16);
17222v4i32 __builtin_msa_srar_w (v4i32, v4i32);
17223v2i64 __builtin_msa_srar_d (v2i64, v2i64);
17224
17225v16i8 __builtin_msa_srari_b (v16i8, imm0_7);
17226v8i16 __builtin_msa_srari_h (v8i16, imm0_15);
17227v4i32 __builtin_msa_srari_w (v4i32, imm0_31);
17228v2i64 __builtin_msa_srari_d (v2i64, imm0_63);
17229
17230v16i8 __builtin_msa_srl_b (v16i8, v16i8);
17231v8i16 __builtin_msa_srl_h (v8i16, v8i16);
17232v4i32 __builtin_msa_srl_w (v4i32, v4i32);
17233v2i64 __builtin_msa_srl_d (v2i64, v2i64);
17234
17235v16i8 __builtin_msa_srli_b (v16i8, imm0_7);
17236v8i16 __builtin_msa_srli_h (v8i16, imm0_15);
17237v4i32 __builtin_msa_srli_w (v4i32, imm0_31);
17238v2i64 __builtin_msa_srli_d (v2i64, imm0_63);
17239
17240v16i8 __builtin_msa_srlr_b (v16i8, v16i8);
17241v8i16 __builtin_msa_srlr_h (v8i16, v8i16);
17242v4i32 __builtin_msa_srlr_w (v4i32, v4i32);
17243v2i64 __builtin_msa_srlr_d (v2i64, v2i64);
17244
17245v16i8 __builtin_msa_srlri_b (v16i8, imm0_7);
17246v8i16 __builtin_msa_srlri_h (v8i16, imm0_15);
17247v4i32 __builtin_msa_srlri_w (v4i32, imm0_31);
17248v2i64 __builtin_msa_srlri_d (v2i64, imm0_63);
17249
17250void __builtin_msa_st_b (v16i8, void *, imm_n512_511);
17251void __builtin_msa_st_h (v8i16, void *, imm_n1024_1022);
17252void __builtin_msa_st_w (v4i32, void *, imm_n2048_2044);
17253void __builtin_msa_st_d (v2i64, void *, imm_n4096_4088);
17254
17255v16i8 __builtin_msa_subs_s_b (v16i8, v16i8);
17256v8i16 __builtin_msa_subs_s_h (v8i16, v8i16);
17257v4i32 __builtin_msa_subs_s_w (v4i32, v4i32);
17258v2i64 __builtin_msa_subs_s_d (v2i64, v2i64);
17259
17260v16u8 __builtin_msa_subs_u_b (v16u8, v16u8);
17261v8u16 __builtin_msa_subs_u_h (v8u16, v8u16);
17262v4u32 __builtin_msa_subs_u_w (v4u32, v4u32);
17263v2u64 __builtin_msa_subs_u_d (v2u64, v2u64);
17264
17265v16u8 __builtin_msa_subsus_u_b (v16u8, v16i8);
17266v8u16 __builtin_msa_subsus_u_h (v8u16, v8i16);
17267v4u32 __builtin_msa_subsus_u_w (v4u32, v4i32);
17268v2u64 __builtin_msa_subsus_u_d (v2u64, v2i64);
17269
17270v16i8 __builtin_msa_subsuu_s_b (v16u8, v16u8);
17271v8i16 __builtin_msa_subsuu_s_h (v8u16, v8u16);
17272v4i32 __builtin_msa_subsuu_s_w (v4u32, v4u32);
17273v2i64 __builtin_msa_subsuu_s_d (v2u64, v2u64);
17274
17275v16i8 __builtin_msa_subv_b (v16i8, v16i8);
17276v8i16 __builtin_msa_subv_h (v8i16, v8i16);
17277v4i32 __builtin_msa_subv_w (v4i32, v4i32);
17278v2i64 __builtin_msa_subv_d (v2i64, v2i64);
17279
17280v16i8 __builtin_msa_subvi_b (v16i8, imm0_31);
17281v8i16 __builtin_msa_subvi_h (v8i16, imm0_31);
17282v4i32 __builtin_msa_subvi_w (v4i32, imm0_31);
17283v2i64 __builtin_msa_subvi_d (v2i64, imm0_31);
17284
17285v16i8 __builtin_msa_vshf_b (v16i8, v16i8, v16i8);
17286v8i16 __builtin_msa_vshf_h (v8i16, v8i16, v8i16);
17287v4i32 __builtin_msa_vshf_w (v4i32, v4i32, v4i32);
17288v2i64 __builtin_msa_vshf_d (v2i64, v2i64, v2i64);
17289
17290v16u8 __builtin_msa_xor_v (v16u8, v16u8);
17291
17292v16u8 __builtin_msa_xori_b (v16u8, imm0_255);
17293@end smallexample
17294
17295@node Other MIPS Built-in Functions
17296@subsection Other MIPS Built-in Functions
17297
17298GCC provides other MIPS-specific built-in functions:
17299
17300@table @code
17301@item void __builtin_mips_cache (int @var{op}, const volatile void *@var{addr})
17302Insert a @samp{cache} instruction with operands @var{op} and @var{addr}.
17303GCC defines the preprocessor macro @code{___GCC_HAVE_BUILTIN_MIPS_CACHE}
17304when this function is available.
17305
17306@item unsigned int __builtin_mips_get_fcsr (void)
17307@itemx void __builtin_mips_set_fcsr (unsigned int @var{value})
17308Get and set the contents of the floating-point control and status register
17309(FPU control register 31).  These functions are only available in hard-float
17310code but can be called in both MIPS16 and non-MIPS16 contexts.
17311
17312@code{__builtin_mips_set_fcsr} can be used to change any bit of the
17313register except the condition codes, which GCC assumes are preserved.
17314@end table
17315
17316@node MSP430 Built-in Functions
17317@subsection MSP430 Built-in Functions
17318
17319GCC provides a couple of special builtin functions to aid in the
17320writing of interrupt handlers in C.
17321
17322@table @code
17323@item __bic_SR_register_on_exit (int @var{mask})
17324This clears the indicated bits in the saved copy of the status register
17325currently residing on the stack.  This only works inside interrupt
17326handlers and the changes to the status register will only take affect
17327once the handler returns.
17328
17329@item __bis_SR_register_on_exit (int @var{mask})
17330This sets the indicated bits in the saved copy of the status register
17331currently residing on the stack.  This only works inside interrupt
17332handlers and the changes to the status register will only take affect
17333once the handler returns.
17334
17335@item __delay_cycles (long long @var{cycles})
17336This inserts an instruction sequence that takes exactly @var{cycles}
17337cycles (between 0 and about 17E9) to complete.  The inserted sequence
17338may use jumps, loops, or no-ops, and does not interfere with any other
17339instructions.  Note that @var{cycles} must be a compile-time constant
17340integer - that is, you must pass a number, not a variable that may be
17341optimized to a constant later.  The number of cycles delayed by this
17342builtin is exact.
17343@end table
17344
17345@node NDS32 Built-in Functions
17346@subsection NDS32 Built-in Functions
17347
17348These built-in functions are available for the NDS32 target:
17349
17350@deftypefn {Built-in Function} void __builtin_nds32_isync (int *@var{addr})
17351Insert an ISYNC instruction into the instruction stream where
17352@var{addr} is an instruction address for serialization.
17353@end deftypefn
17354
17355@deftypefn {Built-in Function} void __builtin_nds32_isb (void)
17356Insert an ISB instruction into the instruction stream.
17357@end deftypefn
17358
17359@deftypefn {Built-in Function} int __builtin_nds32_mfsr (int @var{sr})
17360Return the content of a system register which is mapped by @var{sr}.
17361@end deftypefn
17362
17363@deftypefn {Built-in Function} int __builtin_nds32_mfusr (int @var{usr})
17364Return the content of a user space register which is mapped by @var{usr}.
17365@end deftypefn
17366
17367@deftypefn {Built-in Function} void __builtin_nds32_mtsr (int @var{value}, int @var{sr})
17368Move the @var{value} to a system register which is mapped by @var{sr}.
17369@end deftypefn
17370
17371@deftypefn {Built-in Function} void __builtin_nds32_mtusr (int @var{value}, int @var{usr})
17372Move the @var{value} to a user space register which is mapped by @var{usr}.
17373@end deftypefn
17374
17375@deftypefn {Built-in Function} void __builtin_nds32_setgie_en (void)
17376Enable global interrupt.
17377@end deftypefn
17378
17379@deftypefn {Built-in Function} void __builtin_nds32_setgie_dis (void)
17380Disable global interrupt.
17381@end deftypefn
17382
17383@node picoChip Built-in Functions
17384@subsection picoChip Built-in Functions
17385
17386GCC provides an interface to selected machine instructions from the
17387picoChip instruction set.
17388
17389@table @code
17390@item int __builtin_sbc (int @var{value})
17391Sign bit count.  Return the number of consecutive bits in @var{value}
17392that have the same value as the sign bit.  The result is the number of
17393leading sign bits minus one, giving the number of redundant sign bits in
17394@var{value}.
17395
17396@item int __builtin_byteswap (int @var{value})
17397Byte swap.  Return the result of swapping the upper and lower bytes of
17398@var{value}.
17399
17400@item int __builtin_brev (int @var{value})
17401Bit reversal.  Return the result of reversing the bits in
17402@var{value}.  Bit 15 is swapped with bit 0, bit 14 is swapped with bit 1,
17403and so on.
17404
17405@item int __builtin_adds (int @var{x}, int @var{y})
17406Saturating addition.  Return the result of adding @var{x} and @var{y},
17407storing the value 32767 if the result overflows.
17408
17409@item int __builtin_subs (int @var{x}, int @var{y})
17410Saturating subtraction.  Return the result of subtracting @var{y} from
17411@var{x}, storing the value @minus{}32768 if the result overflows.
17412
17413@item void __builtin_halt (void)
17414Halt.  The processor stops execution.  This built-in is useful for
17415implementing assertions.
17416
17417@end table
17418
17419@node Basic PowerPC Built-in Functions
17420@subsection Basic PowerPC Built-in Functions
17421
17422@menu
17423* Basic PowerPC Built-in Functions Available on all Configurations::
17424* Basic PowerPC Built-in Functions Available on ISA 2.05::
17425* Basic PowerPC Built-in Functions Available on ISA 2.06::
17426* Basic PowerPC Built-in Functions Available on ISA 2.07::
17427* Basic PowerPC Built-in Functions Available on ISA 3.0::
17428* Basic PowerPC Built-in Functions Available on ISA 3.1::
17429@end menu
17430
17431This section describes PowerPC built-in functions that do not require
17432the inclusion of any special header files to declare prototypes or
17433provide macro definitions.  The sections that follow describe
17434additional PowerPC built-in functions.
17435
17436@node Basic PowerPC Built-in Functions Available on all Configurations
17437@subsubsection Basic PowerPC Built-in Functions Available on all Configurations
17438
17439@deftypefn {Built-in Function} void __builtin_cpu_init (void)
17440This function is a @code{nop} on the PowerPC platform and is included solely
17441to maintain API compatibility with the x86 builtins.
17442@end deftypefn
17443
17444@deftypefn {Built-in Function} int __builtin_cpu_is (const char *@var{cpuname})
17445This function returns a value of @code{1} if the run-time CPU is of type
17446@var{cpuname} and returns @code{0} otherwise
17447
17448The @code{__builtin_cpu_is} function requires GLIBC 2.23 or newer
17449which exports the hardware capability bits.  GCC defines the macro
17450@code{__BUILTIN_CPU_SUPPORTS__} if the @code{__builtin_cpu_supports}
17451built-in function is fully supported.
17452
17453If GCC was configured to use a GLIBC before 2.23, the built-in
17454function @code{__builtin_cpu_is} always returns a 0 and the compiler
17455issues a warning.
17456
17457The following CPU names can be detected:
17458
17459@table @samp
17460@item power10
17461IBM POWER10 Server CPU.
17462@item power9
17463IBM POWER9 Server CPU.
17464@item power8
17465IBM POWER8 Server CPU.
17466@item power7
17467IBM POWER7 Server CPU.
17468@item power6x
17469IBM POWER6 Server CPU (RAW mode).
17470@item power6
17471IBM POWER6 Server CPU (Architected mode).
17472@item power5+
17473IBM POWER5+ Server CPU.
17474@item power5
17475IBM POWER5 Server CPU.
17476@item ppc970
17477IBM 970 Server CPU (ie, Apple G5).
17478@item power4
17479IBM POWER4 Server CPU.
17480@item ppca2
17481IBM A2 64-bit Embedded CPU
17482@item ppc476
17483IBM PowerPC 476FP 32-bit Embedded CPU.
17484@item ppc464
17485IBM PowerPC 464 32-bit Embedded CPU.
17486@item ppc440
17487PowerPC 440 32-bit Embedded CPU.
17488@item ppc405
17489PowerPC 405 32-bit Embedded CPU.
17490@item ppc-cell-be
17491IBM PowerPC Cell Broadband Engine Architecture CPU.
17492@end table
17493
17494Here is an example:
17495@smallexample
17496#ifdef __BUILTIN_CPU_SUPPORTS__
17497  if (__builtin_cpu_is ("power8"))
17498    @{
17499       do_power8 (); // POWER8 specific implementation.
17500    @}
17501  else
17502#endif
17503    @{
17504       do_generic (); // Generic implementation.
17505    @}
17506@end smallexample
17507@end deftypefn
17508
17509@deftypefn {Built-in Function} int __builtin_cpu_supports (const char *@var{feature})
17510This function returns a value of @code{1} if the run-time CPU supports the HWCAP
17511feature @var{feature} and returns @code{0} otherwise.
17512
17513The @code{__builtin_cpu_supports} function requires GLIBC 2.23 or
17514newer which exports the hardware capability bits.  GCC defines the
17515macro @code{__BUILTIN_CPU_SUPPORTS__} if the
17516@code{__builtin_cpu_supports} built-in function is fully supported.
17517
17518If GCC was configured to use a GLIBC before 2.23, the built-in
17519function @code{__builtin_cpu_suports} always returns a 0 and the
17520compiler issues a warning.
17521
17522The following features can be
17523detected:
17524
17525@table @samp
17526@item 4xxmac
175274xx CPU has a Multiply Accumulator.
17528@item altivec
17529CPU has a SIMD/Vector Unit.
17530@item arch_2_05
17531CPU supports ISA 2.05 (eg, POWER6)
17532@item arch_2_06
17533CPU supports ISA 2.06 (eg, POWER7)
17534@item arch_2_07
17535CPU supports ISA 2.07 (eg, POWER8)
17536@item arch_3_00
17537CPU supports ISA 3.0 (eg, POWER9)
17538@item arch_3_1
17539CPU supports ISA 3.1 (eg, POWER10)
17540@item archpmu
17541CPU supports the set of compatible performance monitoring events.
17542@item booke
17543CPU supports the Embedded ISA category.
17544@item cellbe
17545CPU has a CELL broadband engine.
17546@item darn
17547CPU supports the @code{darn} (deliver a random number) instruction.
17548@item dfp
17549CPU has a decimal floating point unit.
17550@item dscr
17551CPU supports the data stream control register.
17552@item ebb
17553CPU supports event base branching.
17554@item efpdouble
17555CPU has a SPE double precision floating point unit.
17556@item efpsingle
17557CPU has a SPE single precision floating point unit.
17558@item fpu
17559CPU has a floating point unit.
17560@item htm
17561CPU has hardware transaction memory instructions.
17562@item htm-nosc
17563Kernel aborts hardware transactions when a syscall is made.
17564@item htm-no-suspend
17565CPU supports hardware transaction memory but does not support the
17566@code{tsuspend.} instruction.
17567@item ic_snoop
17568CPU supports icache snooping capabilities.
17569@item ieee128
17570CPU supports 128-bit IEEE binary floating point instructions.
17571@item isel
17572CPU supports the integer select instruction.
17573@item mma
17574CPU supports the matrix-multiply assist instructions.
17575@item mmu
17576CPU has a memory management unit.
17577@item notb
17578CPU does not have a timebase (eg, 601 and 403gx).
17579@item pa6t
17580CPU supports the PA Semi 6T CORE ISA.
17581@item power4
17582CPU supports ISA 2.00 (eg, POWER4)
17583@item power5
17584CPU supports ISA 2.02 (eg, POWER5)
17585@item power5+
17586CPU supports ISA 2.03 (eg, POWER5+)
17587@item power6x
17588CPU supports ISA 2.05 (eg, POWER6) extended opcodes mffgpr and mftgpr.
17589@item ppc32
17590CPU supports 32-bit mode execution.
17591@item ppc601
17592CPU supports the old POWER ISA (eg, 601)
17593@item ppc64
17594CPU supports 64-bit mode execution.
17595@item ppcle
17596CPU supports a little-endian mode that uses address swizzling.
17597@item scv
17598Kernel supports system call vectored.
17599@item smt
17600CPU support simultaneous multi-threading.
17601@item spe
17602CPU has a signal processing extension unit.
17603@item tar
17604CPU supports the target address register.
17605@item true_le
17606CPU supports true little-endian mode.
17607@item ucache
17608CPU has unified I/D cache.
17609@item vcrypto
17610CPU supports the vector cryptography instructions.
17611@item vsx
17612CPU supports the vector-scalar extension.
17613@end table
17614
17615Here is an example:
17616@smallexample
17617#ifdef __BUILTIN_CPU_SUPPORTS__
17618  if (__builtin_cpu_supports ("fpu"))
17619    @{
17620       asm("fadd %0,%1,%2" : "=d"(dst) : "d"(src1), "d"(src2));
17621    @}
17622  else
17623#endif
17624    @{
17625       dst = __fadd (src1, src2); // Software FP addition function.
17626    @}
17627@end smallexample
17628@end deftypefn
17629
17630The following built-in functions are also available on all PowerPC
17631processors:
17632@smallexample
17633uint64_t __builtin_ppc_get_timebase ();
17634unsigned long __builtin_ppc_mftb ();
17635double __builtin_unpack_ibm128 (__ibm128, int);
17636__ibm128 __builtin_pack_ibm128 (double, double);
17637double __builtin_mffs (void);
17638void __builtin_mtfsf (const int, double);
17639void __builtin_mtfsb0 (const int);
17640void __builtin_mtfsb1 (const int);
17641void __builtin_set_fpscr_rn (int);
17642@end smallexample
17643
17644The @code{__builtin_ppc_get_timebase} and @code{__builtin_ppc_mftb}
17645functions generate instructions to read the Time Base Register.  The
17646@code{__builtin_ppc_get_timebase} function may generate multiple
17647instructions and always returns the 64 bits of the Time Base Register.
17648The @code{__builtin_ppc_mftb} function always generates one instruction and
17649returns the Time Base Register value as an unsigned long, throwing away
17650the most significant word on 32-bit environments.  The @code{__builtin_mffs}
17651return the value of the FPSCR register.  Note, ISA 3.0 supports the
17652@code{__builtin_mffsl()} which permits software to read the control and
17653non-sticky status bits in the FSPCR without the higher latency associated with
17654accessing the sticky status bits.  The @code{__builtin_mtfsf} takes a constant
176558-bit integer field mask and a double precision floating point argument
17656and generates the @code{mtfsf} (extended mnemonic) instruction to write new
17657values to selected fields of the FPSCR.  The
17658@code{__builtin_mtfsb0} and @code{__builtin_mtfsb1} take the bit to change
17659as an argument.  The valid bit range is between 0 and 31.  The builtins map to
17660the @code{mtfsb0} and @code{mtfsb1} instructions which take the argument and
17661add 32.  Hence these instructions only modify the FPSCR[32:63] bits by
17662changing the specified bit to a zero or one respectively.  The
17663@code{__builtin_set_fpscr_rn} builtin allows changing both of the floating
17664point rounding mode bits.  The argument is a 2-bit value.  The argument can
17665either be a @code{const int} or stored in a variable. The builtin uses
17666the ISA 3.0
17667instruction @code{mffscrn} if available, otherwise it reads the FPSCR, masks
17668the current rounding mode bits out and OR's in the new value.
17669
17670@node Basic PowerPC Built-in Functions Available on ISA 2.05
17671@subsubsection Basic PowerPC Built-in Functions Available on ISA 2.05
17672
17673The basic built-in functions described in this section are
17674available on the PowerPC family of processors starting with ISA 2.05
17675or later.  Unless specific options are explicitly disabled on the
17676command line, specifying option @option{-mcpu=power6} has the effect of
17677enabling the @option{-mpowerpc64}, @option{-mpowerpc-gpopt},
17678@option{-mpowerpc-gfxopt}, @option{-mmfcrf}, @option{-mpopcntb},
17679@option{-mfprnd}, @option{-mcmpb}, @option{-mhard-dfp}, and
17680@option{-mrecip-precision} options.  Specify the
17681@option{-maltivec} option explicitly in
17682combination with the above options if desired.
17683
17684The following functions require option @option{-mcmpb}.
17685@smallexample
17686unsigned long long __builtin_cmpb (unsigned long long int, unsigned long long int);
17687unsigned int __builtin_cmpb (unsigned int, unsigned int);
17688@end smallexample
17689
17690The @code{__builtin_cmpb} function
17691performs a byte-wise compare on the contents of its two arguments,
17692returning the result of the byte-wise comparison as the returned
17693value.  For each byte comparison, the corresponding byte of the return
17694value holds 0xff if the input bytes are equal and 0 if the input bytes
17695are not equal.  If either of the arguments to this built-in function
17696is wider than 32 bits, the function call expands into the form that
17697expects @code{unsigned long long int} arguments
17698which is only available on 64-bit targets.
17699
17700The following built-in functions are available
17701when hardware decimal floating point
17702(@option{-mhard-dfp}) is available:
17703@smallexample
17704void __builtin_set_fpscr_drn(int);
17705_Decimal64 __builtin_ddedpd (int, _Decimal64);
17706_Decimal128 __builtin_ddedpdq (int, _Decimal128);
17707_Decimal64 __builtin_denbcd (int, _Decimal64);
17708_Decimal128 __builtin_denbcdq (int, _Decimal128);
17709_Decimal64 __builtin_diex (long long, _Decimal64);
17710_Decimal128 _builtin_diexq (long long, _Decimal128);
17711_Decimal64 __builtin_dscli (_Decimal64, int);
17712_Decimal128 __builtin_dscliq (_Decimal128, int);
17713_Decimal64 __builtin_dscri (_Decimal64, int);
17714_Decimal128 __builtin_dscriq (_Decimal128, int);
17715long long __builtin_dxex (_Decimal64);
17716long long __builtin_dxexq (_Decimal128);
17717_Decimal128 __builtin_pack_dec128 (unsigned long long, unsigned long long);
17718unsigned long long __builtin_unpack_dec128 (_Decimal128, int);
17719
17720The @code{__builtin_set_fpscr_drn} builtin allows changing the three decimal
17721floating point rounding mode bits.  The argument is a 3-bit value.  The
17722argument can either be a @code{const int} or the value can be stored in
17723a variable.
17724The builtin uses the ISA 3.0 instruction @code{mffscdrn} if available.
17725Otherwise the builtin reads the FPSCR, masks the current decimal rounding
17726mode bits out and OR's in the new value.
17727
17728@end smallexample
17729
17730The following functions require @option{-mhard-float},
17731@option{-mpowerpc-gfxopt}, and @option{-mpopcntb} options.
17732
17733@smallexample
17734double __builtin_recipdiv (double, double);
17735float __builtin_recipdivf (float, float);
17736double __builtin_rsqrt (double);
17737float __builtin_rsqrtf (float);
17738@end smallexample
17739
17740The @code{vec_rsqrt}, @code{__builtin_rsqrt}, and
17741@code{__builtin_rsqrtf} functions generate multiple instructions to
17742implement the reciprocal sqrt functionality using reciprocal sqrt
17743estimate instructions.
17744
17745The @code{__builtin_recipdiv}, and @code{__builtin_recipdivf}
17746functions generate multiple instructions to implement division using
17747the reciprocal estimate instructions.
17748
17749The following functions require @option{-mhard-float} and
17750@option{-mmultiple} options.
17751
17752The @code{__builtin_unpack_longdouble} function takes a
17753@code{long double} argument and a compile time constant of 0 or 1.  If
17754the constant is 0, the first @code{double} within the
17755@code{long double} is returned, otherwise the second @code{double}
17756is returned.  The @code{__builtin_unpack_longdouble} function is only
17757available if @code{long double} uses the IBM extended double
17758representation.
17759
17760The @code{__builtin_pack_longdouble} function takes two @code{double}
17761arguments and returns a @code{long double} value that combines the two
17762arguments.  The @code{__builtin_pack_longdouble} function is only
17763available if @code{long double} uses the IBM extended double
17764representation.
17765
17766The @code{__builtin_unpack_ibm128} function takes a @code{__ibm128}
17767argument and a compile time constant of 0 or 1.  If the constant is 0,
17768the first @code{double} within the @code{__ibm128} is returned,
17769otherwise the second @code{double} is returned.
17770
17771The @code{__builtin_pack_ibm128} function takes two @code{double}
17772arguments and returns a @code{__ibm128} value that combines the two
17773arguments.
17774
17775Additional built-in functions are available for the 64-bit PowerPC
17776family of processors, for efficient use of 128-bit floating point
17777(@code{__float128}) values.
17778
17779@node Basic PowerPC Built-in Functions Available on ISA 2.06
17780@subsubsection Basic PowerPC Built-in Functions Available on ISA 2.06
17781
17782The basic built-in functions described in this section are
17783available on the PowerPC family of processors starting with ISA 2.05
17784or later.  Unless specific options are explicitly disabled on the
17785command line, specifying option @option{-mcpu=power7} has the effect of
17786enabling all the same options as for @option{-mcpu=power6} in
17787addition to the @option{-maltivec}, @option{-mpopcntd}, and
17788@option{-mvsx} options.
17789
17790The following basic built-in functions require @option{-mpopcntd}:
17791@smallexample
17792unsigned int __builtin_addg6s (unsigned int, unsigned int);
17793long long __builtin_bpermd (long long, long long);
17794unsigned int __builtin_cbcdtd (unsigned int);
17795unsigned int __builtin_cdtbcd (unsigned int);
17796long long __builtin_divde (long long, long long);
17797unsigned long long __builtin_divdeu (unsigned long long, unsigned long long);
17798int __builtin_divwe (int, int);
17799unsigned int __builtin_divweu (unsigned int, unsigned int);
17800vector __int128 __builtin_pack_vector_int128 (long long, long long);
17801void __builtin_rs6000_speculation_barrier (void);
17802long long __builtin_unpack_vector_int128 (vector __int128, signed char);
17803@end smallexample
17804
17805Of these, the @code{__builtin_divde} and @code{__builtin_divdeu} functions
17806require a 64-bit environment.
17807
17808The following basic built-in functions, which are also supported on
17809x86 targets, require @option{-mfloat128}.
17810@smallexample
17811__float128 __builtin_fabsq (__float128);
17812__float128 __builtin_copysignq (__float128, __float128);
17813__float128 __builtin_infq (void);
17814__float128 __builtin_huge_valq (void);
17815__float128 __builtin_nanq (void);
17816__float128 __builtin_nansq (void);
17817
17818__float128 __builtin_sqrtf128 (__float128);
17819__float128 __builtin_fmaf128 (__float128, __float128, __float128);
17820@end smallexample
17821
17822@node Basic PowerPC Built-in Functions Available on ISA 2.07
17823@subsubsection Basic PowerPC Built-in Functions Available on ISA 2.07
17824
17825The basic built-in functions described in this section are
17826available on the PowerPC family of processors starting with ISA 2.07
17827or later.  Unless specific options are explicitly disabled on the
17828command line, specifying option @option{-mcpu=power8} has the effect of
17829enabling all the same options as for @option{-mcpu=power7} in
17830addition to the @option{-mpower8-fusion}, @option{-mpower8-vector},
17831@option{-mcrypto}, @option{-mhtm}, @option{-mquad-memory}, and
17832@option{-mquad-memory-atomic} options.
17833
17834This section intentionally empty.
17835
17836@node Basic PowerPC Built-in Functions Available on ISA 3.0
17837@subsubsection Basic PowerPC Built-in Functions Available on ISA 3.0
17838
17839The basic built-in functions described in this section are
17840available on the PowerPC family of processors starting with ISA 3.0
17841or later.  Unless specific options are explicitly disabled on the
17842command line, specifying option @option{-mcpu=power9} has the effect of
17843enabling all the same options as for @option{-mcpu=power8} in
17844addition to the @option{-misel} option.
17845
17846The following built-in functions are available on Linux 64-bit systems
17847that use the ISA 3.0 instruction set (@option{-mcpu=power9}):
17848
17849@table @code
17850@item __float128 __builtin_addf128_round_to_odd (__float128, __float128)
17851Perform a 128-bit IEEE floating point add using round to odd as the
17852rounding mode.
17853@findex __builtin_addf128_round_to_odd
17854
17855@item __float128 __builtin_subf128_round_to_odd (__float128, __float128)
17856Perform a 128-bit IEEE floating point subtract using round to odd as
17857the rounding mode.
17858@findex __builtin_subf128_round_to_odd
17859
17860@item __float128 __builtin_mulf128_round_to_odd (__float128, __float128)
17861Perform a 128-bit IEEE floating point multiply using round to odd as
17862the rounding mode.
17863@findex __builtin_mulf128_round_to_odd
17864
17865@item __float128 __builtin_divf128_round_to_odd (__float128, __float128)
17866Perform a 128-bit IEEE floating point divide using round to odd as
17867the rounding mode.
17868@findex __builtin_divf128_round_to_odd
17869
17870@item __float128 __builtin_sqrtf128_round_to_odd (__float128)
17871Perform a 128-bit IEEE floating point square root using round to odd
17872as the rounding mode.
17873@findex __builtin_sqrtf128_round_to_odd
17874
17875@item __float128 __builtin_fmaf128_round_to_odd (__float128, __float128, __float128)
17876Perform a 128-bit IEEE floating point fused multiply and add operation
17877using round to odd as the rounding mode.
17878@findex __builtin_fmaf128_round_to_odd
17879
17880@item double __builtin_truncf128_round_to_odd (__float128)
17881Convert a 128-bit IEEE floating point value to @code{double} using
17882round to odd as the rounding mode.
17883@findex __builtin_truncf128_round_to_odd
17884@end table
17885
17886The following additional built-in functions are also available for the
17887PowerPC family of processors, starting with ISA 3.0 or later:
17888@smallexample
17889long long __builtin_darn (void);
17890long long __builtin_darn_raw (void);
17891int __builtin_darn_32 (void);
17892@end smallexample
17893
17894The @code{__builtin_darn} and @code{__builtin_darn_raw}
17895functions require a
1789664-bit environment supporting ISA 3.0 or later.
17897The @code{__builtin_darn} function provides a 64-bit conditioned
17898random number.  The @code{__builtin_darn_raw} function provides a
1789964-bit raw random number.  The @code{__builtin_darn_32} function
17900provides a 32-bit conditioned random number.
17901
17902The following additional built-in functions are also available for the
17903PowerPC family of processors, starting with ISA 3.0 or later:
17904
17905@smallexample
17906int __builtin_byte_in_set (unsigned char u, unsigned long long set);
17907int __builtin_byte_in_range (unsigned char u, unsigned int range);
17908int __builtin_byte_in_either_range (unsigned char u, unsigned int ranges);
17909
17910int __builtin_dfp_dtstsfi_lt (unsigned int comparison, _Decimal64 value);
17911int __builtin_dfp_dtstsfi_lt (unsigned int comparison, _Decimal128 value);
17912int __builtin_dfp_dtstsfi_lt_dd (unsigned int comparison, _Decimal64 value);
17913int __builtin_dfp_dtstsfi_lt_td (unsigned int comparison, _Decimal128 value);
17914
17915int __builtin_dfp_dtstsfi_gt (unsigned int comparison, _Decimal64 value);
17916int __builtin_dfp_dtstsfi_gt (unsigned int comparison, _Decimal128 value);
17917int __builtin_dfp_dtstsfi_gt_dd (unsigned int comparison, _Decimal64 value);
17918int __builtin_dfp_dtstsfi_gt_td (unsigned int comparison, _Decimal128 value);
17919
17920int __builtin_dfp_dtstsfi_eq (unsigned int comparison, _Decimal64 value);
17921int __builtin_dfp_dtstsfi_eq (unsigned int comparison, _Decimal128 value);
17922int __builtin_dfp_dtstsfi_eq_dd (unsigned int comparison, _Decimal64 value);
17923int __builtin_dfp_dtstsfi_eq_td (unsigned int comparison, _Decimal128 value);
17924
17925int __builtin_dfp_dtstsfi_ov (unsigned int comparison, _Decimal64 value);
17926int __builtin_dfp_dtstsfi_ov (unsigned int comparison, _Decimal128 value);
17927int __builtin_dfp_dtstsfi_ov_dd (unsigned int comparison, _Decimal64 value);
17928int __builtin_dfp_dtstsfi_ov_td (unsigned int comparison, _Decimal128 value);
17929
17930double __builtin_mffsl(void);
17931
17932@end smallexample
17933The @code{__builtin_byte_in_set} function requires a
1793464-bit environment supporting ISA 3.0 or later.  This function returns
17935a non-zero value if and only if its @code{u} argument exactly equals one of
17936the eight bytes contained within its 64-bit @code{set} argument.
17937
17938The @code{__builtin_byte_in_range} and
17939@code{__builtin_byte_in_either_range} require an environment
17940supporting ISA 3.0 or later.  For these two functions, the
17941@code{range} argument is encoded as 4 bytes, organized as
17942@code{hi_1:lo_1:hi_2:lo_2}.
17943The @code{__builtin_byte_in_range} function returns a
17944non-zero value if and only if its @code{u} argument is within the
17945range bounded between @code{lo_2} and @code{hi_2} inclusive.
17946The @code{__builtin_byte_in_either_range} function returns non-zero if
17947and only if its @code{u} argument is within either the range bounded
17948between @code{lo_1} and @code{hi_1} inclusive or the range bounded
17949between @code{lo_2} and @code{hi_2} inclusive.
17950
17951The @code{__builtin_dfp_dtstsfi_lt} function returns a non-zero value
17952if and only if the number of signficant digits of its @code{value} argument
17953is less than its @code{comparison} argument.  The
17954@code{__builtin_dfp_dtstsfi_lt_dd} and
17955@code{__builtin_dfp_dtstsfi_lt_td} functions behave similarly, but
17956require that the type of the @code{value} argument be
17957@code{__Decimal64} and @code{__Decimal128} respectively.
17958
17959The @code{__builtin_dfp_dtstsfi_gt} function returns a non-zero value
17960if and only if the number of signficant digits of its @code{value} argument
17961is greater than its @code{comparison} argument.  The
17962@code{__builtin_dfp_dtstsfi_gt_dd} and
17963@code{__builtin_dfp_dtstsfi_gt_td} functions behave similarly, but
17964require that the type of the @code{value} argument be
17965@code{__Decimal64} and @code{__Decimal128} respectively.
17966
17967The @code{__builtin_dfp_dtstsfi_eq} function returns a non-zero value
17968if and only if the number of signficant digits of its @code{value} argument
17969equals its @code{comparison} argument.  The
17970@code{__builtin_dfp_dtstsfi_eq_dd} and
17971@code{__builtin_dfp_dtstsfi_eq_td} functions behave similarly, but
17972require that the type of the @code{value} argument be
17973@code{__Decimal64} and @code{__Decimal128} respectively.
17974
17975The @code{__builtin_dfp_dtstsfi_ov} function returns a non-zero value
17976if and only if its @code{value} argument has an undefined number of
17977significant digits, such as when @code{value} is an encoding of @code{NaN}.
17978The @code{__builtin_dfp_dtstsfi_ov_dd} and
17979@code{__builtin_dfp_dtstsfi_ov_td} functions behave similarly, but
17980require that the type of the @code{value} argument be
17981@code{__Decimal64} and @code{__Decimal128} respectively.
17982
17983The @code{__builtin_mffsl} uses the ISA 3.0 @code{mffsl} instruction to read
17984the FPSCR.  The instruction is a lower latency version of the @code{mffs}
17985instruction.  If the @code{mffsl} instruction is not available, then the
17986builtin uses the older @code{mffs} instruction to read the FPSCR.
17987
17988@node Basic PowerPC Built-in Functions Available on ISA 3.1
17989@subsubsection Basic PowerPC Built-in Functions Available on ISA 3.1
17990
17991The basic built-in functions described in this section are
17992available on the PowerPC family of processors starting with ISA 3.1.
17993Unless specific options are explicitly disabled on the
17994command line, specifying option @option{-mcpu=power10} has the effect of
17995enabling all the same options as for @option{-mcpu=power9}.
17996
17997The following built-in functions are available on Linux 64-bit systems
17998that use a future architecture instruction set (@option{-mcpu=power10}):
17999
18000@smallexample
18001@exdent unsigned long long int
18002@exdent __builtin_cfuged (unsigned long long int, unsigned long long int)
18003@end smallexample
18004Perform a 64-bit centrifuge operation, as if implemented by the
18005@code{cfuged} instruction.
18006@findex __builtin_cfuged
18007
18008@smallexample
18009@exdent unsigned long long int
18010@exdent __builtin_cntlzdm (unsigned long long int, unsigned long long int)
18011@end smallexample
18012Perform a 64-bit count leading zeros operation under mask, as if
18013implemented by the @code{cntlzdm} instruction.
18014@findex __builtin_cntlzdm
18015
18016@smallexample
18017@exdent unsigned long long int
18018@exdent __builtin_cnttzdm (unsigned long long int, unsigned long long int)
18019@end smallexample
18020Perform a 64-bit count trailing zeros operation under mask, as if
18021implemented by the @code{cnttzdm} instruction.
18022@findex __builtin_cnttzdm
18023
18024@smallexample
18025@exdent unsigned long long int
18026@exdent __builtin_pdepd (unsigned long long int, unsigned long long int)
18027@end smallexample
18028Perform a 64-bit parallel bits deposit operation, as if implemented by the
18029@code{pdepd} instruction.
18030@findex __builtin_pdepd
18031
18032@smallexample
18033@exdent unsigned long long int
18034@exdent __builtin_pextd (unsigned long long int, unsigned long long int)
18035@end smallexample
18036Perform a 64-bit parallel bits extract operation, as if implemented by the
18037@code{pextd} instruction.
18038@findex __builtin_pextd
18039
18040@smallexample
18041@exdent vector signed __int128 vsx_xl_sext (signed long long, signed char *);
18042@exdent vector signed __int128 vsx_xl_sext (signed long long, signed short *);
18043@exdent vector signed __int128 vsx_xl_sext (signed long long, signed int *);
18044@exdent vector signed __int128 vsx_xl_sext (signed long long, signed long long *);
18045@exdent vector unsigned __int128 vsx_xl_zext (signed long long, unsigned char *);
18046@exdent vector unsigned __int128 vsx_xl_zext (signed long long, unsigned short *);
18047@exdent vector unsigned __int128 vsx_xl_zext (signed long long, unsigned int *);
18048@exdent vector unsigned __int128 vsx_xl_zext (signed long long, unsigned long long *);
18049@end smallexample
18050
18051Load (and sign extend) to an __int128 vector, as if implemented by the ISA 3.1
18052@code{lxvrbx} @code{lxvrhx} @code{lxvrwx} @code{lxvrdx} instructions.
18053@findex vsx_xl_sext
18054@findex vsx_xl_zext
18055
18056@smallexample
18057@exdent void vec_xst_trunc (vector signed __int128, signed long long, signed char *);
18058@exdent void vec_xst_trunc (vector signed __int128, signed long long, signed short *);
18059@exdent void vec_xst_trunc (vector signed __int128, signed long long, signed int *);
18060@exdent void vec_xst_trunc (vector signed __int128, signed long long, signed long long *);
18061@exdent void vec_xst_trunc (vector unsigned __int128, signed long long, unsigned char *);
18062@exdent void vec_xst_trunc (vector unsigned __int128, signed long long, unsigned short *);
18063@exdent void vec_xst_trunc (vector unsigned __int128, signed long long, unsigned int *);
18064@exdent void vec_xst_trunc (vector unsigned __int128, signed long long, unsigned long long *);
18065@end smallexample
18066
18067Truncate and store the rightmost element of a vector, as if implemented by the
18068ISA 3.1 @code{stxvrbx} @code{stxvrhx} @code{stxvrwx} @code{stxvrdx} instructions.
18069@findex vec_xst_trunc
18070
18071@node PowerPC AltiVec/VSX Built-in Functions
18072@subsection PowerPC AltiVec/VSX Built-in Functions
18073
18074GCC provides an interface for the PowerPC family of processors to access
18075the AltiVec operations described in Motorola's AltiVec Programming
18076Interface Manual.  The interface is made available by including
18077@code{<altivec.h>} and using @option{-maltivec} and
18078@option{-mabi=altivec}.  The interface supports the following vector
18079types.
18080
18081@smallexample
18082vector unsigned char
18083vector signed char
18084vector bool char
18085
18086vector unsigned short
18087vector signed short
18088vector bool short
18089vector pixel
18090
18091vector unsigned int
18092vector signed int
18093vector bool int
18094vector float
18095@end smallexample
18096
18097GCC's implementation of the high-level language interface available from
18098C and C++ code differs from Motorola's documentation in several ways.
18099
18100@itemize @bullet
18101
18102@item
18103A vector constant is a list of constant expressions within curly braces.
18104
18105@item
18106A vector initializer requires no cast if the vector constant is of the
18107same type as the variable it is initializing.
18108
18109@item
18110If @code{signed} or @code{unsigned} is omitted, the signedness of the
18111vector type is the default signedness of the base type.  The default
18112varies depending on the operating system, so a portable program should
18113always specify the signedness.
18114
18115@item
18116Compiling with @option{-maltivec} adds keywords @code{__vector},
18117@code{vector}, @code{__pixel}, @code{pixel}, @code{__bool} and
18118@code{bool}.  When compiling ISO C, the context-sensitive substitution
18119of the keywords @code{vector}, @code{pixel} and @code{bool} is
18120disabled.  To use them, you must include @code{<altivec.h>} instead.
18121
18122@item
18123GCC allows using a @code{typedef} name as the type specifier for a
18124vector type, but only under the following circumstances:
18125
18126@itemize @bullet
18127
18128@item
18129When using @code{__vector} instead of @code{vector}; for example,
18130
18131@smallexample
18132typedef signed short int16;
18133__vector int16 data;
18134@end smallexample
18135
18136@item
18137When using @code{vector} in keyword-and-predefine mode; for example,
18138
18139@smallexample
18140typedef signed short int16;
18141vector int16 data;
18142@end smallexample
18143
18144Note that keyword-and-predefine mode is enabled by disabling GNU
18145extensions (e.g., by using @code{-std=c11}) and including
18146@code{<altivec.h>}.
18147@end itemize
18148
18149@item
18150For C, overloaded functions are implemented with macros so the following
18151does not work:
18152
18153@smallexample
18154  vec_add ((vector signed int)@{1, 2, 3, 4@}, foo);
18155@end smallexample
18156
18157@noindent
18158Since @code{vec_add} is a macro, the vector constant in the example
18159is treated as four separate arguments.  Wrap the entire argument in
18160parentheses for this to work.
18161@end itemize
18162
18163@emph{Note:} Only the @code{<altivec.h>} interface is supported.
18164Internally, GCC uses built-in functions to achieve the functionality in
18165the aforementioned header file, but they are not supported and are
18166subject to change without notice.
18167
18168GCC complies with the Power Vector Intrinsic Programming Reference (PVIPR),
18169which may be found at
18170@uref{https://openpowerfoundation.org/?resource_lib=power-vector-intrinsic-programming-reference}.
18171Chapter 4 of this document fully documents the vector API interfaces
18172that must be
18173provided by compliant compilers.  Programmers should preferentially use
18174the interfaces described therein.  However, historically GCC has provided
18175additional interfaces for access to vector instructions.  These are
18176briefly described below.  Where the PVIPR provides a portable interface,
18177other functions in GCC that provide the same capabilities should be
18178considered deprecated.
18179
18180The PVIPR documents the following overloaded functions:
18181
18182@multitable @columnfractions 0.33 0.33 0.33
18183
18184@item @code{vec_abs}
18185@tab @code{vec_absd}
18186@tab @code{vec_abss}
18187@item @code{vec_add}
18188@tab @code{vec_addc}
18189@tab @code{vec_adde}
18190@item @code{vec_addec}
18191@tab @code{vec_adds}
18192@tab @code{vec_all_eq}
18193@item @code{vec_all_ge}
18194@tab @code{vec_all_gt}
18195@tab @code{vec_all_in}
18196@item @code{vec_all_le}
18197@tab @code{vec_all_lt}
18198@tab @code{vec_all_nan}
18199@item @code{vec_all_ne}
18200@tab @code{vec_all_nge}
18201@tab @code{vec_all_ngt}
18202@item @code{vec_all_nle}
18203@tab @code{vec_all_nlt}
18204@tab @code{vec_all_numeric}
18205@item @code{vec_and}
18206@tab @code{vec_andc}
18207@tab @code{vec_any_eq}
18208@item @code{vec_any_ge}
18209@tab @code{vec_any_gt}
18210@tab @code{vec_any_le}
18211@item @code{vec_any_lt}
18212@tab @code{vec_any_nan}
18213@tab @code{vec_any_ne}
18214@item @code{vec_any_nge}
18215@tab @code{vec_any_ngt}
18216@tab @code{vec_any_nle}
18217@item @code{vec_any_nlt}
18218@tab @code{vec_any_numeric}
18219@tab @code{vec_any_out}
18220@item @code{vec_avg}
18221@tab @code{vec_bperm}
18222@tab @code{vec_ceil}
18223@item @code{vec_cipher_be}
18224@tab @code{vec_cipherlast_be}
18225@tab @code{vec_cmpb}
18226@item @code{vec_cmpeq}
18227@tab @code{vec_cmpge}
18228@tab @code{vec_cmpgt}
18229@item @code{vec_cmple}
18230@tab @code{vec_cmplt}
18231@tab @code{vec_cmpne}
18232@item @code{vec_cmpnez}
18233@tab @code{vec_cntlz}
18234@tab @code{vec_cntlz_lsbb}
18235@item @code{vec_cnttz}
18236@tab @code{vec_cnttz_lsbb}
18237@tab @code{vec_cpsgn}
18238@item @code{vec_ctf}
18239@tab @code{vec_cts}
18240@tab @code{vec_ctu}
18241@item @code{vec_div}
18242@tab @code{vec_double}
18243@tab @code{vec_doublee}
18244@item @code{vec_doubleh}
18245@tab @code{vec_doublel}
18246@tab @code{vec_doubleo}
18247@item @code{vec_eqv}
18248@tab @code{vec_expte}
18249@tab @code{vec_extract}
18250@item @code{vec_extract_exp}
18251@tab @code{vec_extract_fp32_from_shorth}
18252@tab @code{vec_extract_fp32_from_shortl}
18253@item @code{vec_extract_sig}
18254@tab @code{vec_extract_4b}
18255@tab @code{vec_first_match_index}
18256@item @code{vec_first_match_or_eos_index}
18257@tab @code{vec_first_mismatch_index}
18258@tab @code{vec_first_mismatch_or_eos_index}
18259@item @code{vec_float}
18260@tab @code{vec_float2}
18261@tab @code{vec_floate}
18262@item @code{vec_floato}
18263@tab @code{vec_floor}
18264@tab @code{vec_gb}
18265@item @code{vec_insert}
18266@tab @code{vec_insert_exp}
18267@tab @code{vec_insert4b}
18268@item @code{vec_ld}
18269@tab @code{vec_lde}
18270@tab @code{vec_ldl}
18271@item @code{vec_loge}
18272@tab @code{vec_madd}
18273@tab @code{vec_madds}
18274@item @code{vec_max}
18275@tab @code{vec_mergee}
18276@tab @code{vec_mergeh}
18277@item @code{vec_mergel}
18278@tab @code{vec_mergeo}
18279@tab @code{vec_mfvscr}
18280@item @code{vec_min}
18281@tab @code{vec_mradds}
18282@tab @code{vec_msub}
18283@item @code{vec_msum}
18284@tab @code{vec_msums}
18285@tab @code{vec_mtvscr}
18286@item @code{vec_mul}
18287@tab @code{vec_mule}
18288@tab @code{vec_mulo}
18289@item @code{vec_nabs}
18290@tab @code{vec_nand}
18291@tab @code{vec_ncipher_be}
18292@item @code{vec_ncipherlast_be}
18293@tab @code{vec_nearbyint}
18294@tab @code{vec_neg}
18295@item @code{vec_nmadd}
18296@tab @code{vec_nmsub}
18297@tab @code{vec_nor}
18298@item @code{vec_or}
18299@tab @code{vec_orc}
18300@tab @code{vec_pack}
18301@item @code{vec_pack_to_short_fp32}
18302@tab @code{vec_packpx}
18303@tab @code{vec_packs}
18304@item @code{vec_packsu}
18305@tab @code{vec_parity_lsbb}
18306@tab @code{vec_perm}
18307@item @code{vec_permxor}
18308@tab @code{vec_pmsum_be}
18309@tab @code{vec_popcnt}
18310@item @code{vec_re}
18311@tab @code{vec_recipdiv}
18312@tab @code{vec_revb}
18313@item @code{vec_reve}
18314@tab @code{vec_rint}
18315@tab @code{vec_rl}
18316@item @code{vec_rlmi}
18317@tab @code{vec_rlnm}
18318@tab @code{vec_round}
18319@item @code{vec_rsqrt}
18320@tab @code{vec_rsqrte}
18321@tab @code{vec_sbox_be}
18322@item @code{vec_sel}
18323@tab @code{vec_shasigma_be}
18324@tab @code{vec_signed}
18325@item @code{vec_signed2}
18326@tab @code{vec_signede}
18327@tab @code{vec_signedo}
18328@item @code{vec_sl}
18329@tab @code{vec_sld}
18330@tab @code{vec_sldw}
18331@item @code{vec_sll}
18332@tab @code{vec_slo}
18333@tab @code{vec_slv}
18334@item @code{vec_splat}
18335@tab @code{vec_splat_s8}
18336@tab @code{vec_splat_s16}
18337@item @code{vec_splat_s32}
18338@tab @code{vec_splat_u8}
18339@tab @code{vec_splat_u16}
18340@item @code{vec_splat_u32}
18341@tab @code{vec_splats}
18342@tab @code{vec_sqrt}
18343@item @code{vec_sr}
18344@tab @code{vec_sra}
18345@tab @code{vec_srl}
18346@item @code{vec_sro}
18347@tab @code{vec_srv}
18348@tab @code{vec_st}
18349@item @code{vec_ste}
18350@tab @code{vec_stl}
18351@tab @code{vec_sub}
18352@item @code{vec_subc}
18353@tab @code{vec_sube}
18354@tab @code{vec_subec}
18355@item @code{vec_subs}
18356@tab @code{vec_sum2s}
18357@tab @code{vec_sum4s}
18358@item @code{vec_sums}
18359@tab @code{vec_test_data_class}
18360@tab @code{vec_trunc}
18361@item @code{vec_unpackh}
18362@tab @code{vec_unpackl}
18363@tab @code{vec_unsigned}
18364@item @code{vec_unsigned2}
18365@tab @code{vec_unsignede}
18366@tab @code{vec_unsignedo}
18367@item @code{vec_xl}
18368@tab @code{vec_xl_be}
18369@tab @code{vec_xl_len}
18370@item @code{vec_xl_len_r}
18371@tab @code{vec_xor}
18372@tab @code{vec_xst}
18373@item @code{vec_xst_be}
18374@tab @code{vec_xst_len}
18375@tab @code{vec_xst_len_r}
18376
18377@end multitable
18378
18379@menu
18380* PowerPC AltiVec Built-in Functions on ISA 2.05::
18381* PowerPC AltiVec Built-in Functions Available on ISA 2.06::
18382* PowerPC AltiVec Built-in Functions Available on ISA 2.07::
18383* PowerPC AltiVec Built-in Functions Available on ISA 3.0::
18384* PowerPC AltiVec Built-in Functions Available on ISA 3.1::
18385@end menu
18386
18387@node PowerPC AltiVec Built-in Functions on ISA 2.05
18388@subsubsection PowerPC AltiVec Built-in Functions on ISA 2.05
18389
18390The following interfaces are supported for the generic and specific
18391AltiVec operations and the AltiVec predicates.  In cases where there
18392is a direct mapping between generic and specific operations, only the
18393generic names are shown here, although the specific operations can also
18394be used.
18395
18396Arguments that are documented as @code{const int} require literal
18397integral values within the range required for that operation.
18398
18399Only functions excluded from the PVIPR are listed here.
18400
18401@smallexample
18402void vec_dss (const int);
18403
18404void vec_dssall (void);
18405
18406void vec_dst (const vector unsigned char *, int, const int);
18407void vec_dst (const vector signed char *, int, const int);
18408void vec_dst (const vector bool char *, int, const int);
18409void vec_dst (const vector unsigned short *, int, const int);
18410void vec_dst (const vector signed short *, int, const int);
18411void vec_dst (const vector bool short *, int, const int);
18412void vec_dst (const vector pixel *, int, const int);
18413void vec_dst (const vector unsigned int *, int, const int);
18414void vec_dst (const vector signed int *, int, const int);
18415void vec_dst (const vector bool int *, int, const int);
18416void vec_dst (const vector float *, int, const int);
18417void vec_dst (const unsigned char *, int, const int);
18418void vec_dst (const signed char *, int, const int);
18419void vec_dst (const unsigned short *, int, const int);
18420void vec_dst (const short *, int, const int);
18421void vec_dst (const unsigned int *, int, const int);
18422void vec_dst (const int *, int, const int);
18423void vec_dst (const float *, int, const int);
18424
18425void vec_dstst (const vector unsigned char *, int, const int);
18426void vec_dstst (const vector signed char *, int, const int);
18427void vec_dstst (const vector bool char *, int, const int);
18428void vec_dstst (const vector unsigned short *, int, const int);
18429void vec_dstst (const vector signed short *, int, const int);
18430void vec_dstst (const vector bool short *, int, const int);
18431void vec_dstst (const vector pixel *, int, const int);
18432void vec_dstst (const vector unsigned int *, int, const int);
18433void vec_dstst (const vector signed int *, int, const int);
18434void vec_dstst (const vector bool int *, int, const int);
18435void vec_dstst (const vector float *, int, const int);
18436void vec_dstst (const unsigned char *, int, const int);
18437void vec_dstst (const signed char *, int, const int);
18438void vec_dstst (const unsigned short *, int, const int);
18439void vec_dstst (const short *, int, const int);
18440void vec_dstst (const unsigned int *, int, const int);
18441void vec_dstst (const int *, int, const int);
18442void vec_dstst (const unsigned long *, int, const int);
18443void vec_dstst (const long *, int, const int);
18444void vec_dstst (const float *, int, const int);
18445
18446void vec_dststt (const vector unsigned char *, int, const int);
18447void vec_dststt (const vector signed char *, int, const int);
18448void vec_dststt (const vector bool char *, int, const int);
18449void vec_dststt (const vector unsigned short *, int, const int);
18450void vec_dststt (const vector signed short *, int, const int);
18451void vec_dststt (const vector bool short *, int, const int);
18452void vec_dststt (const vector pixel *, int, const int);
18453void vec_dststt (const vector unsigned int *, int, const int);
18454void vec_dststt (const vector signed int *, int, const int);
18455void vec_dststt (const vector bool int *, int, const int);
18456void vec_dststt (const vector float *, int, const int);
18457void vec_dststt (const unsigned char *, int, const int);
18458void vec_dststt (const signed char *, int, const int);
18459void vec_dststt (const unsigned short *, int, const int);
18460void vec_dststt (const short *, int, const int);
18461void vec_dststt (const unsigned int *, int, const int);
18462void vec_dststt (const int *, int, const int);
18463void vec_dststt (const float *, int, const int);
18464
18465void vec_dstt (const vector unsigned char *, int, const int);
18466void vec_dstt (const vector signed char *, int, const int);
18467void vec_dstt (const vector bool char *, int, const int);
18468void vec_dstt (const vector unsigned short *, int, const int);
18469void vec_dstt (const vector signed short *, int, const int);
18470void vec_dstt (const vector bool short *, int, const int);
18471void vec_dstt (const vector pixel *, int, const int);
18472void vec_dstt (const vector unsigned int *, int, const int);
18473void vec_dstt (const vector signed int *, int, const int);
18474void vec_dstt (const vector bool int *, int, const int);
18475void vec_dstt (const vector float *, int, const int);
18476void vec_dstt (const unsigned char *, int, const int);
18477void vec_dstt (const signed char *, int, const int);
18478void vec_dstt (const unsigned short *, int, const int);
18479void vec_dstt (const short *, int, const int);
18480void vec_dstt (const unsigned int *, int, const int);
18481void vec_dstt (const int *, int, const int);
18482void vec_dstt (const float *, int, const int);
18483
18484vector signed char vec_lvebx (int, char *);
18485vector unsigned char vec_lvebx (int, unsigned char *);
18486
18487vector signed short vec_lvehx (int, short *);
18488vector unsigned short vec_lvehx (int, unsigned short *);
18489
18490vector float vec_lvewx (int, float *);
18491vector signed int vec_lvewx (int, int *);
18492vector unsigned int vec_lvewx (int, unsigned int *);
18493
18494vector unsigned char vec_lvsl (int, const unsigned char *);
18495vector unsigned char vec_lvsl (int, const signed char *);
18496vector unsigned char vec_lvsl (int, const unsigned short *);
18497vector unsigned char vec_lvsl (int, const short *);
18498vector unsigned char vec_lvsl (int, const unsigned int *);
18499vector unsigned char vec_lvsl (int, const int *);
18500vector unsigned char vec_lvsl (int, const float *);
18501
18502vector unsigned char vec_lvsr (int, const unsigned char *);
18503vector unsigned char vec_lvsr (int, const signed char *);
18504vector unsigned char vec_lvsr (int, const unsigned short *);
18505vector unsigned char vec_lvsr (int, const short *);
18506vector unsigned char vec_lvsr (int, const unsigned int *);
18507vector unsigned char vec_lvsr (int, const int *);
18508vector unsigned char vec_lvsr (int, const float *);
18509
18510void vec_stvebx (vector signed char, int, signed char *);
18511void vec_stvebx (vector unsigned char, int, unsigned char *);
18512void vec_stvebx (vector bool char, int, signed char *);
18513void vec_stvebx (vector bool char, int, unsigned char *);
18514
18515void vec_stvehx (vector signed short, int, short *);
18516void vec_stvehx (vector unsigned short, int, unsigned short *);
18517void vec_stvehx (vector bool short, int, short *);
18518void vec_stvehx (vector bool short, int, unsigned short *);
18519
18520void vec_stvewx (vector float, int, float *);
18521void vec_stvewx (vector signed int, int, int *);
18522void vec_stvewx (vector unsigned int, int, unsigned int *);
18523void vec_stvewx (vector bool int, int, int *);
18524void vec_stvewx (vector bool int, int, unsigned int *);
18525
18526vector float vec_vaddfp (vector float, vector float);
18527
18528vector signed char vec_vaddsbs (vector bool char, vector signed char);
18529vector signed char vec_vaddsbs (vector signed char, vector bool char);
18530vector signed char vec_vaddsbs (vector signed char, vector signed char);
18531
18532vector signed short vec_vaddshs (vector bool short, vector signed short);
18533vector signed short vec_vaddshs (vector signed short, vector bool short);
18534vector signed short vec_vaddshs (vector signed short, vector signed short);
18535
18536vector signed int vec_vaddsws (vector bool int, vector signed int);
18537vector signed int vec_vaddsws (vector signed int, vector bool int);
18538vector signed int vec_vaddsws (vector signed int, vector signed int);
18539
18540vector signed char vec_vaddubm (vector bool char, vector signed char);
18541vector signed char vec_vaddubm (vector signed char, vector bool char);
18542vector signed char vec_vaddubm (vector signed char, vector signed char);
18543vector unsigned char vec_vaddubm (vector bool char, vector unsigned char);
18544vector unsigned char vec_vaddubm (vector unsigned char, vector bool char);
18545vector unsigned char vec_vaddubm (vector unsigned char, vector unsigned char);
18546
18547vector unsigned char vec_vaddubs (vector bool char, vector unsigned char);
18548vector unsigned char vec_vaddubs (vector unsigned char, vector bool char);
18549vector unsigned char vec_vaddubs (vector unsigned char, vector unsigned char);
18550
18551vector signed short vec_vadduhm (vector bool short, vector signed short);
18552vector signed short vec_vadduhm (vector signed short, vector bool short);
18553vector signed short vec_vadduhm (vector signed short, vector signed short);
18554vector unsigned short vec_vadduhm (vector bool short, vector unsigned short);
18555vector unsigned short vec_vadduhm (vector unsigned short, vector bool short);
18556vector unsigned short vec_vadduhm (vector unsigned short, vector unsigned short);
18557
18558vector unsigned short vec_vadduhs (vector bool short, vector unsigned short);
18559vector unsigned short vec_vadduhs (vector unsigned short, vector bool short);
18560vector unsigned short vec_vadduhs (vector unsigned short, vector unsigned short);
18561
18562vector signed int vec_vadduwm (vector bool int, vector signed int);
18563vector signed int vec_vadduwm (vector signed int, vector bool int);
18564vector signed int vec_vadduwm (vector signed int, vector signed int);
18565vector unsigned int vec_vadduwm (vector bool int, vector unsigned int);
18566vector unsigned int vec_vadduwm (vector unsigned int, vector bool int);
18567vector unsigned int vec_vadduwm (vector unsigned int, vector unsigned int);
18568
18569vector unsigned int vec_vadduws (vector bool int, vector unsigned int);
18570vector unsigned int vec_vadduws (vector unsigned int, vector bool int);
18571vector unsigned int vec_vadduws (vector unsigned int, vector unsigned int);
18572
18573vector signed char vec_vavgsb (vector signed char, vector signed char);
18574
18575vector signed short vec_vavgsh (vector signed short, vector signed short);
18576
18577vector signed int vec_vavgsw (vector signed int, vector signed int);
18578
18579vector unsigned char vec_vavgub (vector unsigned char, vector unsigned char);
18580
18581vector unsigned short vec_vavguh (vector unsigned short, vector unsigned short);
18582
18583vector unsigned int vec_vavguw (vector unsigned int, vector unsigned int);
18584
18585vector float vec_vcfsx (vector signed int, const int);
18586
18587vector float vec_vcfux (vector unsigned int, const int);
18588
18589vector bool int vec_vcmpeqfp (vector float, vector float);
18590
18591vector bool char vec_vcmpequb (vector signed char, vector signed char);
18592vector bool char vec_vcmpequb (vector unsigned char, vector unsigned char);
18593
18594vector bool short vec_vcmpequh (vector signed short, vector signed short);
18595vector bool short vec_vcmpequh (vector unsigned short, vector unsigned short);
18596
18597vector bool int vec_vcmpequw (vector signed int, vector signed int);
18598vector bool int vec_vcmpequw (vector unsigned int, vector unsigned int);
18599
18600vector bool int vec_vcmpgtfp (vector float, vector float);
18601
18602vector bool char vec_vcmpgtsb (vector signed char, vector signed char);
18603
18604vector bool short vec_vcmpgtsh (vector signed short, vector signed short);
18605
18606vector bool int vec_vcmpgtsw (vector signed int, vector signed int);
18607
18608vector bool char vec_vcmpgtub (vector unsigned char, vector unsigned char);
18609
18610vector bool short vec_vcmpgtuh (vector unsigned short, vector unsigned short);
18611
18612vector bool int vec_vcmpgtuw (vector unsigned int, vector unsigned int);
18613
18614vector float vec_vmaxfp (vector float, vector float);
18615
18616vector signed char vec_vmaxsb (vector bool char, vector signed char);
18617vector signed char vec_vmaxsb (vector signed char, vector bool char);
18618vector signed char vec_vmaxsb (vector signed char, vector signed char);
18619
18620vector signed short vec_vmaxsh (vector bool short, vector signed short);
18621vector signed short vec_vmaxsh (vector signed short, vector bool short);
18622vector signed short vec_vmaxsh (vector signed short, vector signed short);
18623
18624vector signed int vec_vmaxsw (vector bool int, vector signed int);
18625vector signed int vec_vmaxsw (vector signed int, vector bool int);
18626vector signed int vec_vmaxsw (vector signed int, vector signed int);
18627
18628vector unsigned char vec_vmaxub (vector bool char, vector unsigned char);
18629vector unsigned char vec_vmaxub (vector unsigned char, vector bool char);
18630vector unsigned char vec_vmaxub (vector unsigned char, vector unsigned char);
18631
18632vector unsigned short vec_vmaxuh (vector bool short, vector unsigned short);
18633vector unsigned short vec_vmaxuh (vector unsigned short, vector bool short);
18634vector unsigned short vec_vmaxuh (vector unsigned short, vector unsigned short);
18635
18636vector unsigned int vec_vmaxuw (vector bool int, vector unsigned int);
18637vector unsigned int vec_vmaxuw (vector unsigned int, vector bool int);
18638vector unsigned int vec_vmaxuw (vector unsigned int, vector unsigned int);
18639
18640vector float vec_vminfp (vector float, vector float);
18641
18642vector signed char vec_vminsb (vector bool char, vector signed char);
18643vector signed char vec_vminsb (vector signed char, vector bool char);
18644vector signed char vec_vminsb (vector signed char, vector signed char);
18645
18646vector signed short vec_vminsh (vector bool short, vector signed short);
18647vector signed short vec_vminsh (vector signed short, vector bool short);
18648vector signed short vec_vminsh (vector signed short, vector signed short);
18649
18650vector signed int vec_vminsw (vector bool int, vector signed int);
18651vector signed int vec_vminsw (vector signed int, vector bool int);
18652vector signed int vec_vminsw (vector signed int, vector signed int);
18653
18654vector unsigned char vec_vminub (vector bool char, vector unsigned char);
18655vector unsigned char vec_vminub (vector unsigned char, vector bool char);
18656vector unsigned char vec_vminub (vector unsigned char, vector unsigned char);
18657
18658vector unsigned short vec_vminuh (vector bool short, vector unsigned short);
18659vector unsigned short vec_vminuh (vector unsigned short, vector bool short);
18660vector unsigned short vec_vminuh (vector unsigned short, vector unsigned short);
18661
18662vector unsigned int vec_vminuw (vector bool int, vector unsigned int);
18663vector unsigned int vec_vminuw (vector unsigned int, vector bool int);
18664vector unsigned int vec_vminuw (vector unsigned int, vector unsigned int);
18665
18666vector bool char vec_vmrghb (vector bool char, vector bool char);
18667vector signed char vec_vmrghb (vector signed char, vector signed char);
18668vector unsigned char vec_vmrghb (vector unsigned char, vector unsigned char);
18669
18670vector bool short vec_vmrghh (vector bool short, vector bool short);
18671vector signed short vec_vmrghh (vector signed short, vector signed short);
18672vector unsigned short vec_vmrghh (vector unsigned short, vector unsigned short);
18673vector pixel vec_vmrghh (vector pixel, vector pixel);
18674
18675vector float vec_vmrghw (vector float, vector float);
18676vector bool int vec_vmrghw (vector bool int, vector bool int);
18677vector signed int vec_vmrghw (vector signed int, vector signed int);
18678vector unsigned int vec_vmrghw (vector unsigned int, vector unsigned int);
18679
18680vector bool char vec_vmrglb (vector bool char, vector bool char);
18681vector signed char vec_vmrglb (vector signed char, vector signed char);
18682vector unsigned char vec_vmrglb (vector unsigned char, vector unsigned char);
18683
18684vector bool short vec_vmrglh (vector bool short, vector bool short);
18685vector signed short vec_vmrglh (vector signed short, vector signed short);
18686vector unsigned short vec_vmrglh (vector unsigned short, vector unsigned short);
18687vector pixel vec_vmrglh (vector pixel, vector pixel);
18688
18689vector float vec_vmrglw (vector float, vector float);
18690vector signed int vec_vmrglw (vector signed int, vector signed int);
18691vector unsigned int vec_vmrglw (vector unsigned int, vector unsigned int);
18692vector bool int vec_vmrglw (vector bool int, vector bool int);
18693
18694vector signed int vec_vmsummbm (vector signed char, vector unsigned char,
18695                                vector signed int);
18696
18697vector signed int vec_vmsumshm (vector signed short, vector signed short,
18698                                vector signed int);
18699
18700vector signed int vec_vmsumshs (vector signed short, vector signed short,
18701                                vector signed int);
18702
18703vector unsigned int vec_vmsumubm (vector unsigned char, vector unsigned char,
18704                                  vector unsigned int);
18705
18706vector unsigned int vec_vmsumuhm (vector unsigned short, vector unsigned short,
18707                                  vector unsigned int);
18708
18709vector unsigned int vec_vmsumuhs (vector unsigned short, vector unsigned short,
18710                                  vector unsigned int);
18711
18712vector signed short vec_vmulesb (vector signed char, vector signed char);
18713
18714vector signed int vec_vmulesh (vector signed short, vector signed short);
18715
18716vector unsigned short vec_vmuleub (vector unsigned char, vector unsigned char);
18717
18718vector unsigned int vec_vmuleuh (vector unsigned short, vector unsigned short);
18719
18720vector signed short vec_vmulosb (vector signed char, vector signed char);
18721
18722vector signed int vec_vmulosh (vector signed short, vector signed short);
18723
18724vector unsigned short vec_vmuloub (vector unsigned char, vector unsigned char);
18725
18726vector unsigned int vec_vmulouh (vector unsigned short, vector unsigned short);
18727
18728vector signed char vec_vpkshss (vector signed short, vector signed short);
18729
18730vector unsigned char vec_vpkshus (vector signed short, vector signed short);
18731
18732vector signed short vec_vpkswss (vector signed int, vector signed int);
18733
18734vector unsigned short vec_vpkswus (vector signed int, vector signed int);
18735
18736vector bool char vec_vpkuhum (vector bool short, vector bool short);
18737vector signed char vec_vpkuhum (vector signed short, vector signed short);
18738vector unsigned char vec_vpkuhum (vector unsigned short, vector unsigned short);
18739
18740vector unsigned char vec_vpkuhus (vector unsigned short, vector unsigned short);
18741
18742vector bool short vec_vpkuwum (vector bool int, vector bool int);
18743vector signed short vec_vpkuwum (vector signed int, vector signed int);
18744vector unsigned short vec_vpkuwum (vector unsigned int, vector unsigned int);
18745
18746vector unsigned short vec_vpkuwus (vector unsigned int, vector unsigned int);
18747
18748vector signed char vec_vrlb (vector signed char, vector unsigned char);
18749vector unsigned char vec_vrlb (vector unsigned char, vector unsigned char);
18750
18751vector signed short vec_vrlh (vector signed short, vector unsigned short);
18752vector unsigned short vec_vrlh (vector unsigned short, vector unsigned short);
18753
18754vector signed int vec_vrlw (vector signed int, vector unsigned int);
18755vector unsigned int vec_vrlw (vector unsigned int, vector unsigned int);
18756
18757vector signed char vec_vslb (vector signed char, vector unsigned char);
18758vector unsigned char vec_vslb (vector unsigned char, vector unsigned char);
18759
18760vector signed short vec_vslh (vector signed short, vector unsigned short);
18761vector unsigned short vec_vslh (vector unsigned short, vector unsigned short);
18762
18763vector signed int vec_vslw (vector signed int, vector unsigned int);
18764vector unsigned int vec_vslw (vector unsigned int, vector unsigned int);
18765
18766vector signed char vec_vspltb (vector signed char, const int);
18767vector unsigned char vec_vspltb (vector unsigned char, const int);
18768vector bool char vec_vspltb (vector bool char, const int);
18769
18770vector bool short vec_vsplth (vector bool short, const int);
18771vector signed short vec_vsplth (vector signed short, const int);
18772vector unsigned short vec_vsplth (vector unsigned short, const int);
18773vector pixel vec_vsplth (vector pixel, const int);
18774
18775vector float vec_vspltw (vector float, const int);
18776vector signed int vec_vspltw (vector signed int, const int);
18777vector unsigned int vec_vspltw (vector unsigned int, const int);
18778vector bool int vec_vspltw (vector bool int, const int);
18779
18780vector signed char vec_vsrab (vector signed char, vector unsigned char);
18781vector unsigned char vec_vsrab (vector unsigned char, vector unsigned char);
18782
18783vector signed short vec_vsrah (vector signed short, vector unsigned short);
18784vector unsigned short vec_vsrah (vector unsigned short, vector unsigned short);
18785
18786vector signed int vec_vsraw (vector signed int, vector unsigned int);
18787vector unsigned int vec_vsraw (vector unsigned int, vector unsigned int);
18788
18789vector signed char vec_vsrb (vector signed char, vector unsigned char);
18790vector unsigned char vec_vsrb (vector unsigned char, vector unsigned char);
18791
18792vector signed short vec_vsrh (vector signed short, vector unsigned short);
18793vector unsigned short vec_vsrh (vector unsigned short, vector unsigned short);
18794
18795vector signed int vec_vsrw (vector signed int, vector unsigned int);
18796vector unsigned int vec_vsrw (vector unsigned int, vector unsigned int);
18797
18798vector float vec_vsubfp (vector float, vector float);
18799
18800vector signed char vec_vsubsbs (vector bool char, vector signed char);
18801vector signed char vec_vsubsbs (vector signed char, vector bool char);
18802vector signed char vec_vsubsbs (vector signed char, vector signed char);
18803
18804vector signed short vec_vsubshs (vector bool short, vector signed short);
18805vector signed short vec_vsubshs (vector signed short, vector bool short);
18806vector signed short vec_vsubshs (vector signed short, vector signed short);
18807
18808vector signed int vec_vsubsws (vector bool int, vector signed int);
18809vector signed int vec_vsubsws (vector signed int, vector bool int);
18810vector signed int vec_vsubsws (vector signed int, vector signed int);
18811
18812vector signed char vec_vsububm (vector bool char, vector signed char);
18813vector signed char vec_vsububm (vector signed char, vector bool char);
18814vector signed char vec_vsububm (vector signed char, vector signed char);
18815vector unsigned char vec_vsububm (vector bool char, vector unsigned char);
18816vector unsigned char vec_vsububm (vector unsigned char, vector bool char);
18817vector unsigned char vec_vsububm (vector unsigned char, vector unsigned char);
18818
18819vector unsigned char vec_vsububs (vector bool char, vector unsigned char);
18820vector unsigned char vec_vsububs (vector unsigned char, vector bool char);
18821vector unsigned char vec_vsububs (vector unsigned char, vector unsigned char);
18822
18823vector signed short vec_vsubuhm (vector bool short, vector signed short);
18824vector signed short vec_vsubuhm (vector signed short, vector bool short);
18825vector signed short vec_vsubuhm (vector signed short, vector signed short);
18826vector unsigned short vec_vsubuhm (vector bool short, vector unsigned short);
18827vector unsigned short vec_vsubuhm (vector unsigned short, vector bool short);
18828vector unsigned short vec_vsubuhm (vector unsigned short, vector unsigned short);
18829
18830vector unsigned short vec_vsubuhs (vector bool short, vector unsigned short);
18831vector unsigned short vec_vsubuhs (vector unsigned short, vector bool short);
18832vector unsigned short vec_vsubuhs (vector unsigned short, vector unsigned short);
18833
18834vector signed int vec_vsubuwm (vector bool int, vector signed int);
18835vector signed int vec_vsubuwm (vector signed int, vector bool int);
18836vector signed int vec_vsubuwm (vector signed int, vector signed int);
18837vector unsigned int vec_vsubuwm (vector bool int, vector unsigned int);
18838vector unsigned int vec_vsubuwm (vector unsigned int, vector bool int);
18839vector unsigned int vec_vsubuwm (vector unsigned int, vector unsigned int);
18840
18841vector unsigned int vec_vsubuws (vector bool int, vector unsigned int);
18842vector unsigned int vec_vsubuws (vector unsigned int, vector bool int);
18843vector unsigned int vec_vsubuws (vector unsigned int, vector unsigned int);
18844
18845vector signed int vec_vsum4sbs (vector signed char, vector signed int);
18846
18847vector signed int vec_vsum4shs (vector signed short, vector signed int);
18848
18849vector unsigned int vec_vsum4ubs (vector unsigned char, vector unsigned int);
18850
18851vector unsigned int vec_vupkhpx (vector pixel);
18852
18853vector bool short vec_vupkhsb (vector bool char);
18854vector signed short vec_vupkhsb (vector signed char);
18855
18856vector bool int vec_vupkhsh (vector bool short);
18857vector signed int vec_vupkhsh (vector signed short);
18858
18859vector unsigned int vec_vupklpx (vector pixel);
18860
18861vector bool short vec_vupklsb (vector bool char);
18862vector signed short vec_vupklsb (vector signed char);
18863
18864vector bool int vec_vupklsh (vector bool short);
18865vector signed int vec_vupklsh (vector signed short);
18866@end smallexample
18867
18868@node PowerPC AltiVec Built-in Functions Available on ISA 2.06
18869@subsubsection PowerPC AltiVec Built-in Functions Available on ISA 2.06
18870
18871The AltiVec built-in functions described in this section are
18872available on the PowerPC family of processors starting with ISA 2.06
18873or later.  These are normally enabled by adding @option{-mvsx} to the
18874command line.
18875
18876When @option{-mvsx} is used, the following additional vector types are
18877implemented.
18878
18879@smallexample
18880vector unsigned __int128
18881vector signed __int128
18882vector unsigned long long int
18883vector signed long long int
18884vector double
18885@end smallexample
18886
18887The long long types are only implemented for 64-bit code generation.
18888
18889Only functions excluded from the PVIPR are listed here.
18890
18891@smallexample
18892void vec_dst (const unsigned long *, int, const int);
18893void vec_dst (const long *, int, const int);
18894
18895void vec_dststt (const unsigned long *, int, const int);
18896void vec_dststt (const long *, int, const int);
18897
18898void vec_dstt (const unsigned long *, int, const int);
18899void vec_dstt (const long *, int, const int);
18900
18901vector unsigned char vec_lvsl (int, const unsigned long *);
18902vector unsigned char vec_lvsl (int, const long *);
18903
18904vector unsigned char vec_lvsr (int, const unsigned long *);
18905vector unsigned char vec_lvsr (int, const long *);
18906
18907vector unsigned char vec_lvsl (int, const double *);
18908vector unsigned char vec_lvsr (int, const double *);
18909
18910vector double vec_vsx_ld (int, const vector double *);
18911vector double vec_vsx_ld (int, const double *);
18912vector float vec_vsx_ld (int, const vector float *);
18913vector float vec_vsx_ld (int, const float *);
18914vector bool int vec_vsx_ld (int, const vector bool int *);
18915vector signed int vec_vsx_ld (int, const vector signed int *);
18916vector signed int vec_vsx_ld (int, const int *);
18917vector signed int vec_vsx_ld (int, const long *);
18918vector unsigned int vec_vsx_ld (int, const vector unsigned int *);
18919vector unsigned int vec_vsx_ld (int, const unsigned int *);
18920vector unsigned int vec_vsx_ld (int, const unsigned long *);
18921vector bool short vec_vsx_ld (int, const vector bool short *);
18922vector pixel vec_vsx_ld (int, const vector pixel *);
18923vector signed short vec_vsx_ld (int, const vector signed short *);
18924vector signed short vec_vsx_ld (int, const short *);
18925vector unsigned short vec_vsx_ld (int, const vector unsigned short *);
18926vector unsigned short vec_vsx_ld (int, const unsigned short *);
18927vector bool char vec_vsx_ld (int, const vector bool char *);
18928vector signed char vec_vsx_ld (int, const vector signed char *);
18929vector signed char vec_vsx_ld (int, const signed char *);
18930vector unsigned char vec_vsx_ld (int, const vector unsigned char *);
18931vector unsigned char vec_vsx_ld (int, const unsigned char *);
18932
18933void vec_vsx_st (vector double, int, vector double *);
18934void vec_vsx_st (vector double, int, double *);
18935void vec_vsx_st (vector float, int, vector float *);
18936void vec_vsx_st (vector float, int, float *);
18937void vec_vsx_st (vector signed int, int, vector signed int *);
18938void vec_vsx_st (vector signed int, int, int *);
18939void vec_vsx_st (vector unsigned int, int, vector unsigned int *);
18940void vec_vsx_st (vector unsigned int, int, unsigned int *);
18941void vec_vsx_st (vector bool int, int, vector bool int *);
18942void vec_vsx_st (vector bool int, int, unsigned int *);
18943void vec_vsx_st (vector bool int, int, int *);
18944void vec_vsx_st (vector signed short, int, vector signed short *);
18945void vec_vsx_st (vector signed short, int, short *);
18946void vec_vsx_st (vector unsigned short, int, vector unsigned short *);
18947void vec_vsx_st (vector unsigned short, int, unsigned short *);
18948void vec_vsx_st (vector bool short, int, vector bool short *);
18949void vec_vsx_st (vector bool short, int, unsigned short *);
18950void vec_vsx_st (vector pixel, int, vector pixel *);
18951void vec_vsx_st (vector pixel, int, unsigned short *);
18952void vec_vsx_st (vector pixel, int, short *);
18953void vec_vsx_st (vector bool short, int, short *);
18954void vec_vsx_st (vector signed char, int, vector signed char *);
18955void vec_vsx_st (vector signed char, int, signed char *);
18956void vec_vsx_st (vector unsigned char, int, vector unsigned char *);
18957void vec_vsx_st (vector unsigned char, int, unsigned char *);
18958void vec_vsx_st (vector bool char, int, vector bool char *);
18959void vec_vsx_st (vector bool char, int, unsigned char *);
18960void vec_vsx_st (vector bool char, int, signed char *);
18961
18962vector double vec_xxpermdi (vector double, vector double, const int);
18963vector float vec_xxpermdi (vector float, vector float, const int);
18964vector long long vec_xxpermdi (vector long long, vector long long, const int);
18965vector unsigned long long vec_xxpermdi (vector unsigned long long,
18966                                        vector unsigned long long, const int);
18967vector int vec_xxpermdi (vector int, vector int, const int);
18968vector unsigned int vec_xxpermdi (vector unsigned int,
18969                                  vector unsigned int, const int);
18970vector short vec_xxpermdi (vector short, vector short, const int);
18971vector unsigned short vec_xxpermdi (vector unsigned short,
18972                                    vector unsigned short, const int);
18973vector signed char vec_xxpermdi (vector signed char, vector signed char,
18974                                 const int);
18975vector unsigned char vec_xxpermdi (vector unsigned char,
18976                                   vector unsigned char, const int);
18977
18978vector double vec_xxsldi (vector double, vector double, int);
18979vector float vec_xxsldi (vector float, vector float, int);
18980vector long long vec_xxsldi (vector long long, vector long long, int);
18981vector unsigned long long vec_xxsldi (vector unsigned long long,
18982                                      vector unsigned long long, int);
18983vector int vec_xxsldi (vector int, vector int, int);
18984vector unsigned int vec_xxsldi (vector unsigned int, vector unsigned int, int);
18985vector short vec_xxsldi (vector short, vector short, int);
18986vector unsigned short vec_xxsldi (vector unsigned short,
18987                                  vector unsigned short, int);
18988vector signed char vec_xxsldi (vector signed char, vector signed char, int);
18989vector unsigned char vec_xxsldi (vector unsigned char,
18990                                 vector unsigned char, int);
18991@end smallexample
18992
18993Note that the @samp{vec_ld} and @samp{vec_st} built-in functions always
18994generate the AltiVec @samp{LVX} and @samp{STVX} instructions even
18995if the VSX instruction set is available.  The @samp{vec_vsx_ld} and
18996@samp{vec_vsx_st} built-in functions always generate the VSX @samp{LXVD2X},
18997@samp{LXVW4X}, @samp{STXVD2X}, and @samp{STXVW4X} instructions.
18998
18999@node PowerPC AltiVec Built-in Functions Available on ISA 2.07
19000@subsubsection PowerPC AltiVec Built-in Functions Available on ISA 2.07
19001
19002If the ISA 2.07 additions to the vector/scalar (power8-vector)
19003instruction set are available, the following additional functions are
19004available for both 32-bit and 64-bit targets.  For 64-bit targets, you
19005can use @var{vector long} instead of @var{vector long long},
19006@var{vector bool long} instead of @var{vector bool long long}, and
19007@var{vector unsigned long} instead of @var{vector unsigned long long}.
19008
19009Only functions excluded from the PVIPR are listed here.
19010
19011@smallexample
19012vector long long vec_vaddudm (vector long long, vector long long);
19013vector long long vec_vaddudm (vector bool long long, vector long long);
19014vector long long vec_vaddudm (vector long long, vector bool long long);
19015vector unsigned long long vec_vaddudm (vector unsigned long long,
19016                                       vector unsigned long long);
19017vector unsigned long long vec_vaddudm (vector bool unsigned long long,
19018                                       vector unsigned long long);
19019vector unsigned long long vec_vaddudm (vector unsigned long long,
19020                                       vector bool unsigned long long);
19021
19022vector long long vec_vclz (vector long long);
19023vector unsigned long long vec_vclz (vector unsigned long long);
19024vector int vec_vclz (vector int);
19025vector unsigned int vec_vclz (vector int);
19026vector short vec_vclz (vector short);
19027vector unsigned short vec_vclz (vector unsigned short);
19028vector signed char vec_vclz (vector signed char);
19029vector unsigned char vec_vclz (vector unsigned char);
19030
19031vector signed char vec_vclzb (vector signed char);
19032vector unsigned char vec_vclzb (vector unsigned char);
19033
19034vector long long vec_vclzd (vector long long);
19035vector unsigned long long vec_vclzd (vector unsigned long long);
19036
19037vector short vec_vclzh (vector short);
19038vector unsigned short vec_vclzh (vector unsigned short);
19039
19040vector int vec_vclzw (vector int);
19041vector unsigned int vec_vclzw (vector int);
19042
19043vector signed char vec_vgbbd (vector signed char);
19044vector unsigned char vec_vgbbd (vector unsigned char);
19045
19046vector long long vec_vmaxsd (vector long long, vector long long);
19047
19048vector unsigned long long vec_vmaxud (vector unsigned long long,
19049                                      unsigned vector long long);
19050
19051vector long long vec_vminsd (vector long long, vector long long);
19052
19053vector unsigned long long vec_vminud (vector long long, vector long long);
19054
19055vector int vec_vpksdss (vector long long, vector long long);
19056vector unsigned int vec_vpksdss (vector long long, vector long long);
19057
19058vector unsigned int vec_vpkudus (vector unsigned long long,
19059                                 vector unsigned long long);
19060
19061vector int vec_vpkudum (vector long long, vector long long);
19062vector unsigned int vec_vpkudum (vector unsigned long long,
19063                                 vector unsigned long long);
19064vector bool int vec_vpkudum (vector bool long long, vector bool long long);
19065
19066vector long long vec_vpopcnt (vector long long);
19067vector unsigned long long vec_vpopcnt (vector unsigned long long);
19068vector int vec_vpopcnt (vector int);
19069vector unsigned int vec_vpopcnt (vector int);
19070vector short vec_vpopcnt (vector short);
19071vector unsigned short vec_vpopcnt (vector unsigned short);
19072vector signed char vec_vpopcnt (vector signed char);
19073vector unsigned char vec_vpopcnt (vector unsigned char);
19074
19075vector signed char vec_vpopcntb (vector signed char);
19076vector unsigned char vec_vpopcntb (vector unsigned char);
19077
19078vector long long vec_vpopcntd (vector long long);
19079vector unsigned long long vec_vpopcntd (vector unsigned long long);
19080
19081vector short vec_vpopcnth (vector short);
19082vector unsigned short vec_vpopcnth (vector unsigned short);
19083
19084vector int vec_vpopcntw (vector int);
19085vector unsigned int vec_vpopcntw (vector int);
19086
19087vector long long vec_vrld (vector long long, vector unsigned long long);
19088vector unsigned long long vec_vrld (vector unsigned long long,
19089                                    vector unsigned long long);
19090
19091vector long long vec_vsld (vector long long, vector unsigned long long);
19092vector long long vec_vsld (vector unsigned long long,
19093                           vector unsigned long long);
19094
19095vector long long vec_vsrad (vector long long, vector unsigned long long);
19096vector unsigned long long vec_vsrad (vector unsigned long long,
19097                                     vector unsigned long long);
19098
19099vector long long vec_vsrd (vector long long, vector unsigned long long);
19100vector unsigned long long char vec_vsrd (vector unsigned long long,
19101                                         vector unsigned long long);
19102
19103vector long long vec_vsubudm (vector long long, vector long long);
19104vector long long vec_vsubudm (vector bool long long, vector long long);
19105vector long long vec_vsubudm (vector long long, vector bool long long);
19106vector unsigned long long vec_vsubudm (vector unsigned long long,
19107                                       vector unsigned long long);
19108vector unsigned long long vec_vsubudm (vector bool long long,
19109                                       vector unsigned long long);
19110vector unsigned long long vec_vsubudm (vector unsigned long long,
19111                                       vector bool long long);
19112
19113vector long long vec_vupkhsw (vector int);
19114vector unsigned long long vec_vupkhsw (vector unsigned int);
19115
19116vector long long vec_vupklsw (vector int);
19117vector unsigned long long vec_vupklsw (vector int);
19118@end smallexample
19119
19120If the ISA 2.07 additions to the vector/scalar (power8-vector)
19121instruction set are available, the following additional functions are
19122available for 64-bit targets.  New vector types
19123(@var{vector __int128} and @var{vector __uint128}) are available
19124to hold the @var{__int128} and @var{__uint128} types to use these
19125builtins.
19126
19127The normal vector extract, and set operations work on
19128@var{vector __int128} and @var{vector __uint128} types,
19129but the index value must be 0.
19130
19131Only functions excluded from the PVIPR are listed here.
19132
19133@smallexample
19134vector __int128 vec_vaddcuq (vector __int128, vector __int128);
19135vector __uint128 vec_vaddcuq (vector __uint128, vector __uint128);
19136
19137vector __int128 vec_vadduqm (vector __int128, vector __int128);
19138vector __uint128 vec_vadduqm (vector __uint128, vector __uint128);
19139
19140vector __int128 vec_vaddecuq (vector __int128, vector __int128,
19141                                vector __int128);
19142vector __uint128 vec_vaddecuq (vector __uint128, vector __uint128,
19143                                 vector __uint128);
19144
19145vector __int128 vec_vaddeuqm (vector __int128, vector __int128,
19146                                vector __int128);
19147vector __uint128 vec_vaddeuqm (vector __uint128, vector __uint128,
19148                                 vector __uint128);
19149
19150vector __int128 vec_vsubecuq (vector __int128, vector __int128,
19151                                vector __int128);
19152vector __uint128 vec_vsubecuq (vector __uint128, vector __uint128,
19153                                 vector __uint128);
19154
19155vector __int128 vec_vsubeuqm (vector __int128, vector __int128,
19156                                vector __int128);
19157vector __uint128 vec_vsubeuqm (vector __uint128, vector __uint128,
19158                                 vector __uint128);
19159
19160vector __int128 vec_vsubcuq (vector __int128, vector __int128);
19161vector __uint128 vec_vsubcuq (vector __uint128, vector __uint128);
19162
19163__int128 vec_vsubuqm (__int128, __int128);
19164__uint128 vec_vsubuqm (__uint128, __uint128);
19165
19166vector __int128 __builtin_bcdadd (vector __int128, vector __int128, const int);
19167vector unsigned char __builtin_bcdadd (vector unsigned char, vector unsigned char,
19168                                       const int);
19169int __builtin_bcdadd_lt (vector __int128, vector __int128, const int);
19170int __builtin_bcdadd_lt (vector unsigned char, vector unsigned char, const int);
19171int __builtin_bcdadd_eq (vector __int128, vector __int128, const int);
19172int __builtin_bcdadd_eq (vector unsigned char, vector unsigned char, const int);
19173int __builtin_bcdadd_gt (vector __int128, vector __int128, const int);
19174int __builtin_bcdadd_gt (vector unsigned char, vector unsigned char, const int);
19175int __builtin_bcdadd_ov (vector __int128, vector __int128, const int);
19176int __builtin_bcdadd_ov (vector unsigned char, vector unsigned char, const int);
19177
19178vector __int128 __builtin_bcdsub (vector __int128, vector __int128, const int);
19179vector unsigned char __builtin_bcdsub (vector unsigned char, vector unsigned char,
19180                                       const int);
19181int __builtin_bcdsub_lt (vector __int128, vector __int128, const int);
19182int __builtin_bcdsub_lt (vector unsigned char, vector unsigned char, const int);
19183int __builtin_bcdsub_eq (vector __int128, vector __int128, const int);
19184int __builtin_bcdsub_eq (vector unsigned char, vector unsigned char, const int);
19185int __builtin_bcdsub_gt (vector __int128, vector __int128, const int);
19186int __builtin_bcdsub_gt (vector unsigned char, vector unsigned char, const int);
19187int __builtin_bcdsub_ov (vector __int128, vector __int128, const int);
19188int __builtin_bcdsub_ov (vector unsigned char, vector unsigned char, const int);
19189@end smallexample
19190
19191@node PowerPC AltiVec Built-in Functions Available on ISA 3.0
19192@subsubsection PowerPC AltiVec Built-in Functions Available on ISA 3.0
19193
19194The following additional built-in functions are also available for the
19195PowerPC family of processors, starting with ISA 3.0
19196(@option{-mcpu=power9}) or later.
19197
19198Only instructions excluded from the PVIPR are listed here.
19199
19200@smallexample
19201unsigned int scalar_extract_exp (double source);
19202unsigned long long int scalar_extract_exp (__ieee128 source);
19203
19204unsigned long long int scalar_extract_sig (double source);
19205unsigned __int128 scalar_extract_sig (__ieee128 source);
19206
19207double scalar_insert_exp (unsigned long long int significand,
19208                          unsigned long long int exponent);
19209double scalar_insert_exp (double significand, unsigned long long int exponent);
19210
19211ieee_128 scalar_insert_exp (unsigned __int128 significand,
19212                            unsigned long long int exponent);
19213ieee_128 scalar_insert_exp (ieee_128 significand, unsigned long long int exponent);
19214
19215int scalar_cmp_exp_gt (double arg1, double arg2);
19216int scalar_cmp_exp_lt (double arg1, double arg2);
19217int scalar_cmp_exp_eq (double arg1, double arg2);
19218int scalar_cmp_exp_unordered (double arg1, double arg2);
19219
19220bool scalar_test_data_class (float source, const int condition);
19221bool scalar_test_data_class (double source, const int condition);
19222bool scalar_test_data_class (__ieee128 source, const int condition);
19223
19224bool scalar_test_neg (float source);
19225bool scalar_test_neg (double source);
19226bool scalar_test_neg (__ieee128 source);
19227@end smallexample
19228
19229The @code{scalar_extract_exp} and @code{scalar_extract_sig}
19230functions require a 64-bit environment supporting ISA 3.0 or later.
19231The @code{scalar_extract_exp} and @code{scalar_extract_sig} built-in
19232functions return the significand and the biased exponent value
19233respectively of their @code{source} arguments.
19234When supplied with a 64-bit @code{source} argument, the
19235result returned by @code{scalar_extract_sig} has
19236the @code{0x0010000000000000} bit set if the
19237function's @code{source} argument is in normalized form.
19238Otherwise, this bit is set to 0.
19239When supplied with a 128-bit @code{source} argument, the
19240@code{0x00010000000000000000000000000000} bit of the result is
19241treated similarly.
19242Note that the sign of the significand is not represented in the result
19243returned from the @code{scalar_extract_sig} function.  Use the
19244@code{scalar_test_neg} function to test the sign of its @code{double}
19245argument.
19246
19247The @code{scalar_insert_exp}
19248functions require a 64-bit environment supporting ISA 3.0 or later.
19249When supplied with a 64-bit first argument, the
19250@code{scalar_insert_exp} built-in function returns a double-precision
19251floating point value that is constructed by assembling the values of its
19252@code{significand} and @code{exponent} arguments.  The sign of the
19253result is copied from the most significant bit of the
19254@code{significand} argument.  The significand and exponent components
19255of the result are composed of the least significant 11 bits of the
19256@code{exponent} argument and the least significant 52 bits of the
19257@code{significand} argument respectively.
19258
19259When supplied with a 128-bit first argument, the
19260@code{scalar_insert_exp} built-in function returns a quad-precision
19261ieee floating point value.  The sign bit of the result is copied from
19262the most significant bit of the @code{significand} argument.
19263The significand and exponent components of the result are composed of
19264the least significant 15 bits of the @code{exponent} argument and the
19265least significant 112 bits of the @code{significand} argument respectively.
19266
19267The @code{scalar_cmp_exp_gt}, @code{scalar_cmp_exp_lt},
19268@code{scalar_cmp_exp_eq}, and @code{scalar_cmp_exp_unordered} built-in
19269functions return a non-zero value if @code{arg1} is greater than, less
19270than, equal to, or not comparable to @code{arg2} respectively.  The
19271arguments are not comparable if one or the other equals NaN (not a
19272number).
19273
19274The @code{scalar_test_data_class} built-in function returns 1
19275if any of the condition tests enabled by the value of the
19276@code{condition} variable are true, and 0 otherwise.  The
19277@code{condition} argument must be a compile-time constant integer with
19278value not exceeding 127.  The
19279@code{condition} argument is encoded as a bitmask with each bit
19280enabling the testing of a different condition, as characterized by the
19281following:
19282@smallexample
192830x40    Test for NaN
192840x20    Test for +Infinity
192850x10    Test for -Infinity
192860x08    Test for +Zero
192870x04    Test for -Zero
192880x02    Test for +Denormal
192890x01    Test for -Denormal
19290@end smallexample
19291
19292The @code{scalar_test_neg} built-in function returns 1 if its
19293@code{source} argument holds a negative value, 0 otherwise.
19294
19295The following built-in functions are also available for the PowerPC family
19296of processors, starting with ISA 3.0 or later
19297(@option{-mcpu=power9}).  These string functions are described
19298separately in order to group the descriptions closer to the function
19299prototypes.
19300
19301Only functions excluded from the PVIPR are listed here.
19302
19303@smallexample
19304int vec_all_nez (vector signed char, vector signed char);
19305int vec_all_nez (vector unsigned char, vector unsigned char);
19306int vec_all_nez (vector signed short, vector signed short);
19307int vec_all_nez (vector unsigned short, vector unsigned short);
19308int vec_all_nez (vector signed int, vector signed int);
19309int vec_all_nez (vector unsigned int, vector unsigned int);
19310
19311int vec_any_eqz (vector signed char, vector signed char);
19312int vec_any_eqz (vector unsigned char, vector unsigned char);
19313int vec_any_eqz (vector signed short, vector signed short);
19314int vec_any_eqz (vector unsigned short, vector unsigned short);
19315int vec_any_eqz (vector signed int, vector signed int);
19316int vec_any_eqz (vector unsigned int, vector unsigned int);
19317
19318signed char vec_xlx (unsigned int index, vector signed char data);
19319unsigned char vec_xlx (unsigned int index, vector unsigned char data);
19320signed short vec_xlx (unsigned int index, vector signed short data);
19321unsigned short vec_xlx (unsigned int index, vector unsigned short data);
19322signed int vec_xlx (unsigned int index, vector signed int data);
19323unsigned int vec_xlx (unsigned int index, vector unsigned int data);
19324float vec_xlx (unsigned int index, vector float data);
19325
19326signed char vec_xrx (unsigned int index, vector signed char data);
19327unsigned char vec_xrx (unsigned int index, vector unsigned char data);
19328signed short vec_xrx (unsigned int index, vector signed short data);
19329unsigned short vec_xrx (unsigned int index, vector unsigned short data);
19330signed int vec_xrx (unsigned int index, vector signed int data);
19331unsigned int vec_xrx (unsigned int index, vector unsigned int data);
19332float vec_xrx (unsigned int index, vector float data);
19333@end smallexample
19334
19335The @code{vec_all_nez}, @code{vec_any_eqz}, and @code{vec_cmpnez}
19336perform pairwise comparisons between the elements at the same
19337positions within their two vector arguments.
19338The @code{vec_all_nez} function returns a
19339non-zero value if and only if all pairwise comparisons are not
19340equal and no element of either vector argument contains a zero.
19341The @code{vec_any_eqz} function returns a
19342non-zero value if and only if at least one pairwise comparison is equal
19343or if at least one element of either vector argument contains a zero.
19344The @code{vec_cmpnez} function returns a vector of the same type as
19345its two arguments, within which each element consists of all ones to
19346denote that either the corresponding elements of the incoming arguments are
19347not equal or that at least one of the corresponding elements contains
19348zero.  Otherwise, the element of the returned vector contains all zeros.
19349
19350The @code{vec_xlx} and @code{vec_xrx} functions extract the single
19351element selected by the @code{index} argument from the vector
19352represented by the @code{data} argument.  The @code{index} argument
19353always specifies a byte offset, regardless of the size of the vector
19354element.  With @code{vec_xlx}, @code{index} is the offset of the first
19355byte of the element to be extracted.  With @code{vec_xrx}, @code{index}
19356represents the last byte of the element to be extracted, measured
19357from the right end of the vector.  In other words, the last byte of
19358the element to be extracted is found at position @code{(15 - index)}.
19359There is no requirement that @code{index} be a multiple of the vector
19360element size.  However, if the size of the vector element added to
19361@code{index} is greater than 15, the content of the returned value is
19362undefined.
19363
19364The following functions are also available if the ISA 3.0 instruction
19365set additions (@option{-mcpu=power9}) are available.
19366
19367Only functions excluded from the PVIPR are listed here.
19368
19369@smallexample
19370vector long long vec_vctz (vector long long);
19371vector unsigned long long vec_vctz (vector unsigned long long);
19372vector int vec_vctz (vector int);
19373vector unsigned int vec_vctz (vector int);
19374vector short vec_vctz (vector short);
19375vector unsigned short vec_vctz (vector unsigned short);
19376vector signed char vec_vctz (vector signed char);
19377vector unsigned char vec_vctz (vector unsigned char);
19378
19379vector signed char vec_vctzb (vector signed char);
19380vector unsigned char vec_vctzb (vector unsigned char);
19381
19382vector long long vec_vctzd (vector long long);
19383vector unsigned long long vec_vctzd (vector unsigned long long);
19384
19385vector short vec_vctzh (vector short);
19386vector unsigned short vec_vctzh (vector unsigned short);
19387
19388vector int vec_vctzw (vector int);
19389vector unsigned int vec_vctzw (vector int);
19390
19391vector int vec_vprtyb (vector int);
19392vector unsigned int vec_vprtyb (vector unsigned int);
19393vector long long vec_vprtyb (vector long long);
19394vector unsigned long long vec_vprtyb (vector unsigned long long);
19395
19396vector int vec_vprtybw (vector int);
19397vector unsigned int vec_vprtybw (vector unsigned int);
19398
19399vector long long vec_vprtybd (vector long long);
19400vector unsigned long long vec_vprtybd (vector unsigned long long);
19401@end smallexample
19402
19403On 64-bit targets, if the ISA 3.0 additions (@option{-mcpu=power9})
19404are available:
19405
19406@smallexample
19407vector long vec_vprtyb (vector long);
19408vector unsigned long vec_vprtyb (vector unsigned long);
19409vector __int128 vec_vprtyb (vector __int128);
19410vector __uint128 vec_vprtyb (vector __uint128);
19411
19412vector long vec_vprtybd (vector long);
19413vector unsigned long vec_vprtybd (vector unsigned long);
19414
19415vector __int128 vec_vprtybq (vector __int128);
19416vector __uint128 vec_vprtybd (vector __uint128);
19417@end smallexample
19418
19419The following built-in functions are available for the PowerPC family
19420of processors, starting with ISA 3.0 or later (@option{-mcpu=power9}).
19421
19422Only functions excluded from the PVIPR are listed here.
19423
19424@smallexample
19425__vector unsigned char
19426vec_absdb (__vector unsigned char arg1, __vector unsigned char arg2);
19427__vector unsigned short
19428vec_absdh (__vector unsigned short arg1, __vector unsigned short arg2);
19429__vector unsigned int
19430vec_absdw (__vector unsigned int arg1, __vector unsigned int arg2);
19431@end smallexample
19432
19433The @code{vec_absd}, @code{vec_absdb}, @code{vec_absdh}, and
19434@code{vec_absdw} built-in functions each computes the absolute
19435differences of the pairs of vector elements supplied in its two vector
19436arguments, placing the absolute differences into the corresponding
19437elements of the vector result.
19438
19439The following built-in functions are available for the PowerPC family
19440of processors, starting with ISA 3.0 or later (@option{-mcpu=power9}):
19441@smallexample
19442vector unsigned int vec_vrlnm (vector unsigned int, vector unsigned int);
19443vector unsigned long long vec_vrlnm (vector unsigned long long,
19444                                     vector unsigned long long);
19445@end smallexample
19446
19447The result of @code{vec_vrlnm} is obtained by rotating each element
19448of the first argument vector left and ANDing it with a mask.  The
19449second argument vector contains the mask  beginning in bits 11:15,
19450the mask end in bits 19:23, and the shift count in bits 27:31,
19451of each element.
19452
19453If the cryptographic instructions are enabled (@option{-mcrypto} or
19454@option{-mcpu=power8}), the following builtins are enabled.
19455
19456Only functions excluded from the PVIPR are listed here.
19457
19458@smallexample
19459vector unsigned long long __builtin_crypto_vsbox (vector unsigned long long);
19460
19461vector unsigned long long __builtin_crypto_vcipher (vector unsigned long long,
19462                                                    vector unsigned long long);
19463
19464vector unsigned long long __builtin_crypto_vcipherlast
19465                                     (vector unsigned long long,
19466                                      vector unsigned long long);
19467
19468vector unsigned long long __builtin_crypto_vncipher (vector unsigned long long,
19469                                                     vector unsigned long long);
19470
19471vector unsigned long long __builtin_crypto_vncipherlast (vector unsigned long long,
19472                                                         vector unsigned long long);
19473
19474vector unsigned char __builtin_crypto_vpermxor (vector unsigned char,
19475                                                vector unsigned char,
19476                                                vector unsigned char);
19477
19478vector unsigned short __builtin_crypto_vpermxor (vector unsigned short,
19479                                                 vector unsigned short,
19480                                                 vector unsigned short);
19481
19482vector unsigned int __builtin_crypto_vpermxor (vector unsigned int,
19483                                               vector unsigned int,
19484                                               vector unsigned int);
19485
19486vector unsigned long long __builtin_crypto_vpermxor (vector unsigned long long,
19487                                                     vector unsigned long long,
19488                                                     vector unsigned long long);
19489
19490vector unsigned char __builtin_crypto_vpmsumb (vector unsigned char,
19491                                               vector unsigned char);
19492
19493vector unsigned short __builtin_crypto_vpmsumh (vector unsigned short,
19494                                                vector unsigned short);
19495
19496vector unsigned int __builtin_crypto_vpmsumw (vector unsigned int,
19497                                              vector unsigned int);
19498
19499vector unsigned long long __builtin_crypto_vpmsumd (vector unsigned long long,
19500                                                    vector unsigned long long);
19501
19502vector unsigned long long __builtin_crypto_vshasigmad (vector unsigned long long,
19503                                                       int, int);
19504
19505vector unsigned int __builtin_crypto_vshasigmaw (vector unsigned int, int, int);
19506@end smallexample
19507
19508The second argument to @var{__builtin_crypto_vshasigmad} and
19509@var{__builtin_crypto_vshasigmaw} must be a constant
19510integer that is 0 or 1.  The third argument to these built-in functions
19511must be a constant integer in the range of 0 to 15.
19512
19513The following sign extension builtins are provided:
19514
19515@smallexample
19516vector signed int vec_signexti (vector signed char a)
19517vector signed long long vec_signextll (vector signed char a)
19518vector signed int vec_signexti (vector signed short a)
19519vector signed long long vec_signextll (vector signed short a)
19520vector signed long long vec_signextll (vector signed int a)
19521vector signed long long vec_signextq (vector signed long long a)
19522@end smallexample
19523
19524Each element of the result is produced by sign-extending the element of the
19525input vector that would fall in the least significant portion of the result
19526element. For example, a sign-extension of a vector signed char to a vector
19527signed long long will sign extend the rightmost byte of each doubleword.
19528
19529@node PowerPC AltiVec Built-in Functions Available on ISA 3.1
19530@subsubsection PowerPC AltiVec Built-in Functions Available on ISA 3.1
19531
19532The following additional built-in functions are also available for the
19533PowerPC family of processors, starting with ISA 3.1 (@option{-mcpu=power10}):
19534
19535
19536@smallexample
19537@exdent vector unsigned long long int
19538@exdent vec_cfuge (vector unsigned long long int, vector unsigned long long int)
19539@end smallexample
19540Perform a vector centrifuge operation, as if implemented by the
19541@code{vcfuged} instruction.
19542@findex vec_cfuge
19543
19544@smallexample
19545@exdent vector unsigned long long int
19546@exdent vec_cntlzm (vector unsigned long long int, vector unsigned long long int)
19547@end smallexample
19548Perform a vector count leading zeros under bit mask operation, as if
19549implemented by the @code{vclzdm} instruction.
19550@findex vec_cntlzm
19551
19552@smallexample
19553@exdent vector unsigned long long int
19554@exdent vec_cnttzm (vector unsigned long long int, vector unsigned long long int)
19555@end smallexample
19556Perform a vector count trailing zeros under bit mask operation, as if
19557implemented by the @code{vctzdm} instruction.
19558@findex vec_cnttzm
19559
19560@smallexample
19561@exdent vector signed char
19562@exdent vec_clrl (vector signed char a, unsigned int n)
19563@exdent vector unsigned char
19564@exdent vec_clrl (vector unsigned char a, unsigned int n)
19565@end smallexample
19566Clear the left-most @code{(16 - n)} bytes of vector argument @code{a}, as if
19567implemented by the @code{vclrlb} instruction on a big-endian target
19568and by the @code{vclrrb} instruction on a little-endian target.  A
19569value of @code{n} that is greater than 16 is treated as if it equaled 16.
19570@findex vec_clrl
19571
19572@smallexample
19573@exdent vector signed char
19574@exdent vec_clrr (vector signed char a, unsigned int n)
19575@exdent vector unsigned char
19576@exdent vec_clrr (vector unsigned char a, unsigned int n)
19577@end smallexample
19578Clear the right-most @code{(16 - n)} bytes of vector argument @code{a}, as if
19579implemented by the @code{vclrrb} instruction on a big-endian target
19580and by the @code{vclrlb} instruction on a little-endian target.  A
19581value of @code{n} that is greater than 16 is treated as if it equaled 16.
19582@findex vec_clrr
19583
19584@smallexample
19585@exdent vector unsigned long long int
19586@exdent vec_gnb (vector unsigned __int128, const unsigned char)
19587@end smallexample
19588Perform a 128-bit vector gather  operation, as if implemented by the
19589@code{vgnb} instruction.  The second argument must be a literal
19590integer value between 2 and 7 inclusive.
19591@findex vec_gnb
19592
19593
19594Vector Extract
19595
19596@smallexample
19597@exdent vector unsigned long long int
19598@exdent vec_extractl (vector unsigned char, vector unsigned char, unsigned int)
19599@exdent vector unsigned long long int
19600@exdent vec_extractl (vector unsigned short, vector unsigned short, unsigned int)
19601@exdent vector unsigned long long int
19602@exdent vec_extractl (vector unsigned int, vector unsigned int, unsigned int)
19603@exdent vector unsigned long long int
19604@exdent vec_extractl (vector unsigned long long, vector unsigned long long, unsigned int)
19605@end smallexample
19606Extract an element from two concatenated vectors starting at the given byte index
19607in natural-endian order, and place it zero-extended in doubleword 1 of the result
19608according to natural element order.  If the byte index is out of range for the
19609data type, the intrinsic will be rejected.
19610For little-endian, this output will match the placement by the hardware
19611instruction, i.e., dword[0] in RTL notation.  For big-endian, an additional
19612instruction is needed to move it from the "left" doubleword to the  "right" one.
19613For little-endian, semantics matching the @code{vextdubvrx},
19614@code{vextduhvrx}, @code{vextduwvrx} instruction will be generated, while for
19615big-endian, semantics matching the @code{vextdubvlx}, @code{vextduhvlx},
19616@code{vextduwvlx} instructions
19617will be generated.  Note that some fairly anomalous results can be generated if
19618the byte index is not aligned on an element boundary for the element being
19619extracted.  This is a limitation of the bi-endian vector programming model is
19620consistent with the limitation on @code{vec_perm}.
19621@findex vec_extractl
19622
19623@smallexample
19624@exdent vector unsigned long long int
19625@exdent vec_extracth (vector unsigned char, vector unsigned char, unsigned int)
19626@exdent vector unsigned long long int
19627@exdent vec_extracth (vector unsigned short, vector unsigned short,
19628unsigned int)
19629@exdent vector unsigned long long int
19630@exdent vec_extracth (vector unsigned int, vector unsigned int, unsigned int)
19631@exdent vector unsigned long long int
19632@exdent vec_extracth (vector unsigned long long, vector unsigned long long,
19633unsigned int)
19634@end smallexample
19635Extract an element from two concatenated vectors starting at the given byte
19636index.  The index is based on big endian order for a little endian system.
19637Similarly, the index is based on little endian order for a big endian system.
19638The extraced elements are zero-extended and put in doubleword 1
19639according to natural element order.  If the byte index is out of range for the
19640data type, the intrinsic will be rejected.  For little-endian, this output
19641will match the placement by the hardware instruction (vextdubvrx, vextduhvrx,
19642vextduwvrx, vextddvrx) i.e., dword[0] in RTL
19643notation.  For big-endian, an additional instruction is needed to move it
19644from the "left" doubleword to the "right" one.  For little-endian, semantics
19645matching the @code{vextdubvlx}, @code{vextduhvlx}, @code{vextduwvlx}
19646instructions will be generated, while for big-endian, semantics matching the
19647@code{vextdubvrx}, @code{vextduhvrx}, @code{vextduwvrx} instructions will
19648be generated.  Note that some fairly anomalous
19649results can be generated if the byte index is not aligned on the
19650element boundary for the element being extracted.  This is a
19651limitation of the bi-endian vector programming model consistent with the
19652limitation on @code{vec_perm}.
19653@findex vec_extracth
19654@smallexample
19655@exdent vector unsigned long long int
19656@exdent vec_pdep (vector unsigned long long int, vector unsigned long long int)
19657@end smallexample
19658Perform a vector parallel bits deposit operation, as if implemented by
19659the @code{vpdepd} instruction.
19660@findex vec_pdep
19661
19662Vector Insert
19663
19664@smallexample
19665@exdent vector unsigned char
19666@exdent vec_insertl (unsigned char, vector unsigned char, unsigned int);
19667@exdent vector unsigned short
19668@exdent vec_insertl (unsigned short, vector unsigned short, unsigned int);
19669@exdent vector unsigned int
19670@exdent vec_insertl (unsigned int, vector unsigned int, unsigned int);
19671@exdent vector unsigned long long
19672@exdent vec_insertl (unsigned long long, vector unsigned long long,
19673unsigned int);
19674@exdent vector unsigned char
19675@exdent vec_insertl (vector unsigned char, vector unsigned char, unsigned int;
19676@exdent vector unsigned short
19677@exdent vec_insertl (vector unsigned short, vector unsigned short,
19678unsigned int);
19679@exdent vector unsigned int
19680@exdent vec_insertl (vector unsigned int, vector unsigned int, unsigned int);
19681@end smallexample
19682
19683Let src be the first argument, when the first argument is a scalar, or the
19684rightmost element of the left doubleword of the first argument, when the first
19685argument is a vector.  Insert the source into the destination at the position
19686given by the third argument, using natural element order in the second
19687argument.  The rest of the second argument is unchanged.  If the byte
19688index is greater than 14 for halfwords, greater than 12 for words, or
19689greater than 8 for doublewords the result is undefined.   For little-endian,
19690the generated code will be semantically equivalent to @code{vins[bhwd]rx}
19691instructions.  Similarly for big-endian it will be semantically equivalent
19692to @code{vins[bhwd]lx}.  Note that some fairly anomalous results can be
19693generated if the byte index is not aligned on an element boundary for the
19694type of element being inserted.
19695@findex vec_insertl
19696
19697@smallexample
19698@exdent vector unsigned char
19699@exdent vec_inserth (unsigned char, vector unsigned char, unsigned int);
19700@exdent vector unsigned short
19701@exdent vec_inserth (unsigned short, vector unsigned short, unsigned int);
19702@exdent vector unsigned int
19703@exdent vec_inserth (unsigned int, vector unsigned int, unsigned int);
19704@exdent vector unsigned long long
19705@exdent vec_inserth (unsigned long long, vector unsigned long long,
19706unsigned int);
19707@exdent vector unsigned char
19708@exdent vec_inserth (vector unsigned char, vector unsigned char, unsigned int);
19709@exdent vector unsigned short
19710@exdent vec_inserth (vector unsigned short, vector unsigned short,
19711unsigned int);
19712@exdent vector unsigned int
19713@exdent vec_inserth (vector unsigned int, vector unsigned int, unsigned int);
19714@end smallexample
19715
19716Let src be the first argument, when the first argument is a scalar, or the
19717rightmost element of the first argument, when the first argument is a vector.
19718Insert src into the second argument at the position identified by the third
19719argument, using opposite element order in the second argument, and leaving the
19720rest of the second argument unchanged.  If the byte index is greater than 14
19721for halfwords, 12 for words, or 8 for doublewords, the intrinsic will be
19722rejected. Note that the underlying hardware instruction uses the same register
19723for the second argument and the result.
19724For little-endian, the code generation will be semantically equivalent to
19725@code{vins[bhwd]lx}, while for big-endian it will be semantically equivalent to
19726@code{vins[bhwd]rx}.
19727Note that some fairly anomalous results can be generated if the byte index is
19728not aligned on an element boundary for the sort of element being inserted.
19729@findex vec_inserth
19730
19731Vector Replace Element
19732@smallexample
19733@exdent vector signed int vec_replace_elt (vector signed int, signed int,
19734const int);
19735@exdent vector unsigned int vec_replace_elt (vector unsigned int,
19736unsigned int, const int);
19737@exdent vector float vec_replace_elt (vector float, float, const int);
19738@exdent vector signed long long vec_replace_elt (vector signed long long,
19739signed long long, const int);
19740@exdent vector unsigned long long vec_replace_elt (vector unsigned long long,
19741unsigned long long, const int);
19742@exdent vector double rec_replace_elt (vector double, double, const int);
19743@end smallexample
19744The third argument (constrained to [0,3]) identifies the natural-endian
19745element number of the first argument that will be replaced by the second
19746argument to produce the result.  The other elements of the first argument will
19747remain unchanged in the result.
19748
19749If it's desirable to insert a word at an unaligned position, use
19750vec_replace_unaligned instead.
19751
19752@findex vec_replace_element
19753
19754Vector Replace Unaligned
19755@smallexample
19756@exdent vector unsigned char vec_replace_unaligned (vector unsigned char,
19757signed int, const int);
19758@exdent vector unsigned char vec_replace_unaligned (vector unsigned char,
19759unsigned int, const int);
19760@exdent vector unsigned char vec_replace_unaligned (vector unsigned char,
19761float, const int);
19762@exdent vector unsigned char vec_replace_unaligned (vector unsigned char,
19763signed long long, const int);
19764@exdent vector unsigned char vec_replace_unaligned (vector unsigned char,
19765unsigned long long, const int);
19766@exdent vector unsigned char vec_replace_unaligned (vector unsigned char,
19767double, const int);
19768@end smallexample
19769
19770The second argument replaces a portion of the first argument to produce the
19771result, with the rest of the first argument unchanged in the result.  The
19772third argument identifies the byte index (using left-to-right, or big-endian
19773order) where the high-order byte of the second argument will be placed, with
19774the remaining bytes of the second argument placed naturally "to the right"
19775of the high-order byte.
19776
19777The programmer is responsible for understanding the endianness issues involved
19778with the first argument and the result.
19779@findex vec_replace_unaligned
19780
19781Vector Shift Left Double Bit Immediate
19782@smallexample
19783@exdent vector signed char vec_sldb (vector signed char, vector signed char,
19784const unsigned int);
19785@exdent vector unsigned char vec_sldb (vector unsigned char,
19786vector unsigned char, const unsigned int);
19787@exdent vector signed short vec_sldb (vector signed short, vector signed short,
19788const unsigned int);
19789@exdent vector unsigned short vec_sldb (vector unsigned short,
19790vector unsigned short, const unsigned int);
19791@exdent vector signed int vec_sldb (vector signed int, vector signed int,
19792const unsigned int);
19793@exdent vector unsigned int vec_sldb (vector unsigned int, vector unsigned int,
19794const unsigned int);
19795@exdent vector signed long long vec_sldb (vector signed long long,
19796vector signed long long, const unsigned int);
19797@exdent vector unsigned long long vec_sldb (vector unsigned long long,
19798vector unsigned long long, const unsigned int);
19799@end smallexample
19800
19801Shift the combined input vectors left by the amount specified by the low-order
19802three bits of the third argument, and return the leftmost remaining 128 bits.
19803Code using this instruction must be endian-aware.
19804
19805@findex vec_sldb
19806
19807Vector Shift Right Double Bit Immediate
19808
19809@smallexample
19810@exdent vector signed char vec_srdb (vector signed char, vector signed char,
19811const unsigned int);
19812@exdent vector unsigned char vec_srdb (vector unsigned char, vector unsigned char,
19813const unsigned int);
19814@exdent vector signed short vec_srdb (vector signed short, vector signed short,
19815const unsigned int);
19816@exdent vector unsigned short vec_srdb (vector unsigned short, vector unsigned short,
19817const unsigned int);
19818@exdent vector signed int vec_srdb (vector signed int, vector signed int,
19819const unsigned int);
19820@exdent vector unsigned int vec_srdb (vector unsigned int, vector unsigned int,
19821const unsigned int);
19822@exdent vector signed long long vec_srdb (vector signed long long,
19823vector signed long long, const unsigned int);
19824@exdent vector unsigned long long vec_srdb (vector unsigned long long,
19825vector unsigned long long, const unsigned int);
19826@end smallexample
19827
19828Shift the combined input vectors right by the amount specified by the low-order
19829three bits of the third argument, and return the remaining 128 bits.  Code
19830using this built-in must be endian-aware.
19831
19832@findex vec_srdb
19833
19834Vector Splat
19835
19836@smallexample
19837@exdent vector signed int vec_splati (const signed int);
19838@exdent vector float vec_splati (const float);
19839@end smallexample
19840
19841Splat a 32-bit immediate into a vector of words.
19842
19843@findex vec_splati
19844
19845@smallexample
19846@exdent vector double vec_splatid (const float);
19847@end smallexample
19848
19849Convert a single precision floating-point value to double-precision and splat
19850the result to a vector of double-precision floats.
19851
19852@findex vec_splatid
19853
19854@smallexample
19855@exdent vector signed int vec_splati_ins (vector signed int,
19856const unsigned int, const signed int);
19857@exdent vector unsigned int vec_splati_ins (vector unsigned int,
19858const unsigned int, const unsigned int);
19859@exdent vector float vec_splati_ins (vector float, const unsigned int,
19860const float);
19861@end smallexample
19862
19863Argument 2 must be either 0 or 1.  Splat the value of argument 3 into the word
19864identified by argument 2 of each doubleword of argument 1 and return the
19865result.  The other words of argument 1 are unchanged.
19866
19867@findex vec_splati_ins
19868
19869Vector Blend Variable
19870
19871@smallexample
19872@exdent vector signed char vec_blendv (vector signed char, vector signed char,
19873vector unsigned char);
19874@exdent vector unsigned char vec_blendv (vector unsigned char,
19875vector unsigned char, vector unsigned char);
19876@exdent vector signed short vec_blendv (vector signed short,
19877vector signed short, vector unsigned short);
19878@exdent vector unsigned short vec_blendv (vector unsigned short,
19879vector unsigned short, vector unsigned short);
19880@exdent vector signed int vec_blendv (vector signed int, vector signed int,
19881vector unsigned int);
19882@exdent vector unsigned int vec_blendv (vector unsigned int,
19883vector unsigned int, vector unsigned int);
19884@exdent vector signed long long vec_blendv (vector signed long long,
19885vector signed long long, vector unsigned long long);
19886@exdent vector unsigned long long vec_blendv (vector unsigned long long,
19887vector unsigned long long, vector unsigned long long);
19888@exdent vector float vec_blendv (vector float, vector float,
19889vector unsigned int);
19890@exdent vector double vec_blendv (vector double, vector double,
19891vector unsigned long long);
19892@end smallexample
19893
19894Blend the first and second argument vectors according to the sign bits of the
19895corresponding elements of the third argument vector.  This is similar to the
19896@code{vsel} and @code{xxsel} instructions but for bigger elements.
19897
19898@findex vec_blendv
19899
19900Vector Permute Extended
19901
19902@smallexample
19903@exdent vector signed char vec_permx (vector signed char, vector signed char,
19904vector unsigned char, const int);
19905@exdent vector unsigned char vec_permx (vector unsigned char,
19906vector unsigned char, vector unsigned char, const int);
19907@exdent vector signed short vec_permx (vector signed short,
19908vector signed short, vector unsigned char, const int);
19909@exdent vector unsigned short vec_permx (vector unsigned short,
19910vector unsigned short, vector unsigned char, const int);
19911@exdent vector signed int vec_permx (vector signed int, vector signed int,
19912vector unsigned char, const int);
19913@exdent vector unsigned int vec_permx (vector unsigned int,
19914vector unsigned int, vector unsigned char, const int);
19915@exdent vector signed long long vec_permx (vector signed long long,
19916vector signed long long, vector unsigned char, const int);
19917@exdent vector unsigned long long vec_permx (vector unsigned long long,
19918vector unsigned long long, vector unsigned char, const int);
19919@exdent vector float (vector float, vector float, vector unsigned char,
19920const int);
19921@exdent vector double (vector double, vector double, vector unsigned char,
19922const int);
19923@end smallexample
19924
19925Perform a partial permute of the first two arguments, which form a 32-byte
19926section of an emulated vector up to 256 bytes wide, using the partial permute
19927control vector in the third argument.  The fourth argument (constrained to
19928values of 0-7) identifies which 32-byte section of the emulated vector is
19929contained in the first two arguments.
19930@findex vec_permx
19931
19932@smallexample
19933@exdent vector unsigned long long int
19934@exdent vec_pext (vector unsigned long long int, vector unsigned long long int)
19935@end smallexample
19936Perform a vector parallel bit extract operation, as if implemented by
19937the @code{vpextd} instruction.
19938@findex vec_pext
19939
19940@smallexample
19941@exdent vector unsigned char vec_stril (vector unsigned char)
19942@exdent vector signed char vec_stril (vector signed char)
19943@exdent vector unsigned short vec_stril (vector unsigned short)
19944@exdent vector signed short vec_stril (vector signed short)
19945@end smallexample
19946Isolate the left-most non-zero elements of the incoming vector argument,
19947replacing all elements to the right of the left-most zero element
19948found within the argument with zero.  The typical implementation uses
19949the @code{vstribl} or @code{vstrihl} instruction on big-endian targets
19950and uses the @code{vstribr} or @code{vstrihr} instruction on
19951little-endian targets.
19952@findex vec_stril
19953
19954@smallexample
19955@exdent int vec_stril_p (vector unsigned char)
19956@exdent int vec_stril_p (vector signed char)
19957@exdent int short vec_stril_p (vector unsigned short)
19958@exdent int vec_stril_p (vector signed short)
19959@end smallexample
19960Return a non-zero value if and only if the argument contains a zero
19961element.  The typical implementation uses
19962the @code{vstribl.} or @code{vstrihl.} instruction on big-endian targets
19963and uses the @code{vstribr.} or @code{vstrihr.} instruction on
19964little-endian targets.  Choose this built-in to check for presence of
19965zero element if the same argument is also passed to @code{vec_stril}.
19966@findex vec_stril_p
19967
19968@smallexample
19969@exdent vector unsigned char vec_strir (vector unsigned char)
19970@exdent vector signed char vec_strir (vector signed char)
19971@exdent vector unsigned short vec_strir (vector unsigned short)
19972@exdent vector signed short vec_strir (vector signed short)
19973@end smallexample
19974Isolate the right-most non-zero elements of the incoming vector argument,
19975replacing all elements to the left of the right-most zero element
19976found within the argument with zero.  The typical implementation uses
19977the @code{vstribr} or @code{vstrihr} instruction on big-endian targets
19978and uses the @code{vstribl} or @code{vstrihl} instruction on
19979little-endian targets.
19980@findex vec_strir
19981
19982@smallexample
19983@exdent int vec_strir_p (vector unsigned char)
19984@exdent int vec_strir_p (vector signed char)
19985@exdent int short vec_strir_p (vector unsigned short)
19986@exdent int vec_strir_p (vector signed short)
19987@end smallexample
19988Return a non-zero value if and only if the argument contains a zero
19989element.  The typical implementation uses
19990the @code{vstribr.} or @code{vstrihr.} instruction on big-endian targets
19991and uses the @code{vstribl.} or @code{vstrihl.} instruction on
19992little-endian targets.  Choose this built-in to check for presence of
19993zero element if the same argument is also passed to @code{vec_strir}.
19994@findex vec_strir_p
19995
19996@smallexample
19997@exdent vector unsigned char
19998@exdent vec_ternarylogic (vector unsigned char, vector unsigned char,
19999            vector unsigned char, const unsigned int)
20000@exdent vector unsigned short
20001@exdent vec_ternarylogic (vector unsigned short, vector unsigned short,
20002            vector unsigned short, const unsigned int)
20003@exdent vector unsigned int
20004@exdent vec_ternarylogic (vector unsigned int, vector unsigned int,
20005            vector unsigned int, const unsigned int)
20006@exdent vector unsigned long long int
20007@exdent vec_ternarylogic (vector unsigned long long int, vector unsigned long long int,
20008            vector unsigned long long int, const unsigned int)
20009@exdent vector unsigned __int128
20010@exdent vec_ternarylogic (vector unsigned __int128, vector unsigned __int128,
20011            vector unsigned __int128, const unsigned int)
20012@end smallexample
20013Perform a 128-bit vector evaluate operation, as if implemented by the
20014@code{xxeval} instruction.  The fourth argument must be a literal
20015integer value between 0 and 255 inclusive.
20016@findex vec_ternarylogic
20017
20018@smallexample
20019@exdent vector unsigned char vec_genpcvm (vector unsigned char, const int)
20020@exdent vector unsigned short vec_genpcvm (vector unsigned short, const int)
20021@exdent vector unsigned int vec_genpcvm (vector unsigned int, const int)
20022@exdent vector unsigned int vec_genpcvm (vector unsigned long long int,
20023                                         const int)
20024@end smallexample
20025
20026Vector Integer Multiply/Divide/Modulo
20027
20028@smallexample
20029@exdent vector signed int
20030@exdent vec_mulh (vector signed int a, vector signed int b)
20031@exdent vector unsigned int
20032@exdent vec_mulh (vector unsigned int a, vector unsigned int b)
20033@end smallexample
20034
20035For each integer value @code{i} from 0 to 3, do the following. The integer
20036value in word element @code{i} of a is multiplied by the integer value in word
20037element @code{i} of b. The high-order 32 bits of the 64-bit product are placed
20038into word element @code{i} of the vector returned.
20039
20040@smallexample
20041@exdent vector signed long long
20042@exdent vec_mulh (vector signed long long a, vector signed long long b)
20043@exdent vector unsigned long long
20044@exdent vec_mulh (vector unsigned long long a, vector unsigned long long b)
20045@end smallexample
20046
20047For each integer value @code{i} from 0 to 1, do the following. The integer
20048value in doubleword element @code{i} of a is multiplied by the integer value in
20049doubleword element @code{i} of b. The high-order 64 bits of the 128-bit product
20050are placed into doubleword element @code{i} of the vector returned.
20051
20052@smallexample
20053@exdent vector unsigned long long
20054@exdent vec_mul (vector unsigned long long a, vector unsigned long long b)
20055@exdent vector signed long long
20056@exdent vec_mul (vector signed long long a, vector signed long long b)
20057@end smallexample
20058
20059For each integer value @code{i} from 0 to 1, do the following. The integer
20060value in doubleword element @code{i} of a is multiplied by the integer value in
20061doubleword element @code{i} of b. The low-order 64 bits of the 128-bit product
20062are placed into doubleword element @code{i} of the vector returned.
20063
20064@smallexample
20065@exdent vector signed int
20066@exdent vec_div (vector signed int a, vector signed int b)
20067@exdent vector unsigned int
20068@exdent vec_div (vector unsigned int a, vector unsigned int b)
20069@end smallexample
20070
20071For each integer value @code{i} from 0 to 3, do the following. The integer in
20072word element @code{i} of a is divided by the integer in word element @code{i}
20073of b. The unique integer quotient is placed into the word element @code{i} of
20074the vector returned. If an attempt is made to perform any of the divisions
20075<anything> ÷ 0 then the quotient is undefined.
20076
20077@smallexample
20078@exdent vector signed long long
20079@exdent vec_div (vector signed long long a, vector signed long long b)
20080@exdent vector unsigned long long
20081@exdent vec_div (vector unsigned long long a, vector unsigned long long b)
20082@end smallexample
20083
20084For each integer value @code{i} from 0 to 1, do the following. The integer in
20085doubleword element @code{i} of a is divided by the integer in doubleword
20086element @code{i} of b. The unique integer quotient is placed into the
20087doubleword element @code{i} of the vector returned. If an attempt is made to
20088perform any of the divisions 0x8000_0000_0000_0000 ÷ -1 or <anything> ÷ 0 then
20089the quotient is undefined.
20090
20091@smallexample
20092@exdent vector signed int
20093@exdent vec_dive (vector signed int a, vector signed int b)
20094@exdent vector unsigned int
20095@exdent vec_dive (vector unsigned int a, vector unsigned int b)
20096@end smallexample
20097
20098For each integer value @code{i} from 0 to 3, do the following. The integer in
20099word element @code{i} of a is shifted left by 32 bits, then divided by the
20100integer in word element @code{i} of b. The unique integer quotient is placed
20101into the word element @code{i} of the vector returned. If the quotient cannot
20102be represented in 32 bits, or if an attempt is made to perform any of the
20103divisions <anything> ÷ 0 then the quotient is undefined.
20104
20105@smallexample
20106@exdent vector signed long long
20107@exdent vec_dive (vector signed long long a, vector signed long long b)
20108@exdent vector unsigned long long
20109@exdent vec_dive (vector unsigned long long a, vector unsigned long long b)
20110@end smallexample
20111
20112For each integer value @code{i} from 0 to 1, do the following. The integer in
20113doubleword element @code{i} of a is shifted left by 64 bits, then divided by
20114the integer in doubleword element @code{i} of b. The unique integer quotient is
20115placed into the doubleword element @code{i} of the vector returned. If the
20116quotient cannot be represented in 64 bits, or if an attempt is made to perform
20117<anything> ÷ 0 then the quotient is undefined.
20118
20119@smallexample
20120@exdent vector signed int
20121@exdent vec_mod (vector signed int a, vector signed int b)
20122@exdent vector unsigned int
20123@exdent vec_mod (vector unsigned int a, vector unsigned int b)
20124@end smallexample
20125
20126For each integer value @code{i} from 0 to 3, do the following. The integer in
20127word element @code{i} of a is divided by the integer in word element @code{i}
20128of b. The unique integer remainder is placed into the word element @code{i} of
20129the vector returned.  If an attempt is made to perform any of the divisions
201300x8000_0000 ÷ -1 or <anything> ÷ 0 then the remainder is undefined.
20131
20132@smallexample
20133@exdent vector signed long long
20134@exdent vec_mod (vector signed long long a, vector signed long long b)
20135@exdent vector unsigned long long
20136@exdent vec_mod (vector unsigned long long a, vector unsigned long long b)
20137@end smallexample
20138
20139For each integer value @code{i} from 0 to 1, do the following. The integer in
20140doubleword element @code{i} of a is divided by the integer in doubleword
20141element @code{i} of b. The unique integer remainder is placed into the
20142doubleword element @code{i} of the vector returned. If an attempt is made to
20143perform <anything> ÷ 0 then the remainder is undefined.
20144
20145Generate PCV from specified Mask size, as if implemented by the
20146@code{xxgenpcvbm}, @code{xxgenpcvhm}, @code{xxgenpcvwm} instructions, where
20147immediate value is either 0, 1, 2 or 3.
20148@findex vec_genpcvm
20149
20150@smallexample
20151@exdent vector unsigned __int128 vec_rl (vector unsigned __int128 A,
20152                                         vector unsigned __int128 B);
20153@exdent vector signed __int128 vec_rl (vector signed __int128 A,
20154                                       vector unsigned __int128 B);
20155@end smallexample
20156
20157Result value: Each element of R is obtained by rotating the corresponding element
20158of A left by the number of bits specified by the corresponding element of B.
20159
20160
20161@smallexample
20162@exdent vector unsigned __int128 vec_rlmi (vector unsigned __int128,
20163                                           vector unsigned __int128,
20164                                           vector unsigned __int128);
20165@exdent vector signed __int128 vec_rlmi (vector signed __int128,
20166                                         vector signed __int128,
20167                                         vector unsigned __int128);
20168@end smallexample
20169
20170Returns the result of rotating the first input and inserting it under mask
20171into the second input.  The first bit in the mask, the last bit in the mask are
20172obtained from the two 7-bit fields bits [108:115] and bits [117:123]
20173respectively of the second input.  The shift is obtained from the third input
20174in the 7-bit field [125:131] where all bits counted from zero at the left.
20175
20176@smallexample
20177@exdent vector unsigned __int128 vec_rlnm (vector unsigned __int128,
20178                                           vector unsigned __int128,
20179                                           vector unsigned __int128);
20180@exdent vector signed __int128 vec_rlnm (vector signed __int128,
20181                                         vector unsigned __int128,
20182                                         vector unsigned __int128);
20183@end smallexample
20184
20185Returns the result of rotating the first input and ANDing it with a mask.  The
20186first bit in the mask and the last bit in the mask are obtained from the two
201877-bit fields bits [117:123] and bits [125:131] respectively of the second
20188input.  The shift is obtained from the third input in the 7-bit field bits
20189[125:131] where all bits counted from zero at the left.
20190
20191@smallexample
20192@exdent vector unsigned __int128 vec_sl(vector unsigned __int128 A, vector unsigned __int128 B);
20193@exdent vector signed __int128 vec_sl(vector signed __int128 A, vector unsigned __int128 B);
20194@end smallexample
20195
20196Result value: Each element of R is obtained by shifting the corresponding element of
20197A left by the number of bits specified by the corresponding element of B.
20198
20199@smallexample
20200@exdent vector unsigned __int128 vec_sr(vector unsigned __int128 A, vector unsigned __int128 B);
20201@exdent vector signed __int128 vec_sr(vector signed __int128 A, vector unsigned __int128 B);
20202@end smallexample
20203
20204Result value: Each element of R is obtained by shifting the corresponding element of
20205A right by the number of bits specified by the corresponding element of B.
20206
20207@smallexample
20208@exdent vector unsigned __int128 vec_sra(vector unsigned __int128 A, vector unsigned __int128 B);
20209@exdent vector signed __int128 vec_sra(vector signed __int128 A, vector unsigned __int128 B);
20210@end smallexample
20211
20212Result value: Each element of R is obtained by arithmetic shifting the corresponding
20213element of A right by the number of bits specified by the corresponding element of B.
20214
20215@smallexample
20216@exdent vector unsigned __int128 vec_mule (vector unsigned long long,
20217                                           vector unsigned long long);
20218@exdent vector signed __int128 vec_mule (vector signed long long,
20219                                         vector signed long long);
20220@end smallexample
20221
20222Returns a vector containing a 128-bit integer result of multiplying the even
20223doubleword elements of the two inputs.
20224
20225@smallexample
20226@exdent vector unsigned __int128 vec_mulo (vector unsigned long long,
20227                                           vector unsigned long long);
20228@exdent vector signed __int128 vec_mulo (vector signed long long,
20229                                         vector signed long long);
20230@end smallexample
20231
20232Returns a vector containing a 128-bit integer result of multiplying the odd
20233doubleword elements of the two inputs.
20234
20235@smallexample
20236@exdent vector unsigned __int128 vec_div (vector unsigned __int128,
20237                                          vector unsigned __int128);
20238@exdent vector signed __int128 vec_div (vector signed __int128,
20239                                        vector signed __int128);
20240@end smallexample
20241
20242Returns the result of dividing the first operand by the second operand. An
20243attempt to divide any value by zero or to divide the most negative signed
20244128-bit integer by negative one results in an undefined value.
20245
20246@smallexample
20247@exdent vector unsigned __int128 vec_dive (vector unsigned __int128,
20248                                           vector unsigned __int128);
20249@exdent vector signed __int128 vec_dive (vector signed __int128,
20250                                         vector signed __int128);
20251@end smallexample
20252
20253The result is produced by shifting the first input left by 128 bits and
20254dividing by the second.  If an attempt is made to divide by zero or the result
20255is larger than 128 bits, the result is undefined.
20256
20257@smallexample
20258@exdent vector unsigned __int128 vec_mod (vector unsigned __int128,
20259                                          vector unsigned __int128);
20260@exdent vector signed __int128 vec_mod (vector signed __int128,
20261                                        vector signed __int128);
20262@end smallexample
20263
20264The result is the modulo result of dividing the first input  by the second
20265input.
20266
20267The following builtins perform 128-bit vector comparisons.  The
20268@code{vec_all_xx}, @code{vec_any_xx}, and @code{vec_cmpxx}, where @code{xx} is
20269one of the operations @code{eq, ne, gt, lt, ge, le} perform pairwise
20270comparisons between the elements at the same positions within their two vector
20271arguments.  The @code{vec_all_xx}function returns a non-zero value if and only
20272if all pairwise comparisons are true.  The @code{vec_any_xx} function returns
20273a non-zero value if and only if at least one pairwise comparison is true.  The
20274@code{vec_cmpxx}function returns a vector of the same type as its two
20275arguments, within which each element consists of all ones to denote that
20276specified logical comparison of the corresponding elements was true.
20277Otherwise, the element of the returned vector contains all zeros.
20278
20279@smallexample
20280vector bool __int128 vec_cmpeq (vector signed __int128, vector signed __int128);
20281vector bool __int128 vec_cmpeq (vector unsigned __int128, vector unsigned __int128);
20282vector bool __int128 vec_cmpne (vector signed __int128, vector signed __int128);
20283vector bool __int128 vec_cmpne (vector unsigned __int128, vector unsigned __int128);
20284vector bool __int128 vec_cmpgt (vector signed __int128, vector signed __int128);
20285vector bool __int128 vec_cmpgt (vector unsigned __int128, vector unsigned __int128);
20286vector bool __int128 vec_cmplt (vector signed __int128, vector signed __int128);
20287vector bool __int128 vec_cmplt (vector unsigned __int128, vector unsigned __int128);
20288vector bool __int128 vec_cmpge (vector signed __int128, vector signed __int128);
20289vector bool __int128 vec_cmpge (vector unsigned __int128, vector unsigned __int128);
20290vector bool __int128 vec_cmple (vector signed __int128, vector signed __int128);
20291vector bool __int128 vec_cmple (vector unsigned __int128, vector unsigned __int128);
20292
20293int vec_all_eq (vector signed __int128, vector signed __int128);
20294int vec_all_eq (vector unsigned __int128, vector unsigned __int128);
20295int vec_all_ne (vector signed __int128, vector signed __int128);
20296int vec_all_ne (vector unsigned __int128, vector unsigned __int128);
20297int vec_all_gt (vector signed __int128, vector signed __int128);
20298int vec_all_gt (vector unsigned __int128, vector unsigned __int128);
20299int vec_all_lt (vector signed __int128, vector signed __int128);
20300int vec_all_lt (vector unsigned __int128, vector unsigned __int128);
20301int vec_all_ge (vector signed __int128, vector signed __int128);
20302int vec_all_ge (vector unsigned __int128, vector unsigned __int128);
20303int vec_all_le (vector signed __int128, vector signed __int128);
20304int vec_all_le (vector unsigned __int128, vector unsigned __int128);
20305
20306int vec_any_eq (vector signed __int128, vector signed __int128);
20307int vec_any_eq (vector unsigned __int128, vector unsigned __int128);
20308int vec_any_ne (vector signed __int128, vector signed __int128);
20309int vec_any_ne (vector unsigned __int128, vector unsigned __int128);
20310int vec_any_gt (vector signed __int128, vector signed __int128);
20311int vec_any_gt (vector unsigned __int128, vector unsigned __int128);
20312int vec_any_lt (vector signed __int128, vector signed __int128);
20313int vec_any_lt (vector unsigned __int128, vector unsigned __int128);
20314int vec_any_ge (vector signed __int128, vector signed __int128);
20315int vec_any_ge (vector unsigned __int128, vector unsigned __int128);
20316int vec_any_le (vector signed __int128, vector signed __int128);
20317int vec_any_le (vector unsigned __int128, vector unsigned __int128);
20318@end smallexample
20319
20320
20321@node PowerPC Hardware Transactional Memory Built-in Functions
20322@subsection PowerPC Hardware Transactional Memory Built-in Functions
20323GCC provides two interfaces for accessing the Hardware Transactional
20324Memory (HTM) instructions available on some of the PowerPC family
20325of processors (eg, POWER8).  The two interfaces come in a low level
20326interface, consisting of built-in functions specific to PowerPC and a
20327higher level interface consisting of inline functions that are common
20328between PowerPC and S/390.
20329
20330@subsubsection PowerPC HTM Low Level Built-in Functions
20331
20332The following low level built-in functions are available with
20333@option{-mhtm} or @option{-mcpu=CPU} where CPU is `power8' or later.
20334They all generate the machine instruction that is part of the name.
20335
20336The HTM builtins (with the exception of @code{__builtin_tbegin}) return
20337the full 4-bit condition register value set by their associated hardware
20338instruction.  The header file @code{htmintrin.h} defines some macros that can
20339be used to decipher the return value.  The @code{__builtin_tbegin} builtin
20340returns a simple @code{true} or @code{false} value depending on whether a transaction was
20341successfully started or not.  The arguments of the builtins match exactly the
20342type and order of the associated hardware instruction's operands, except for
20343the @code{__builtin_tcheck} builtin, which does not take any input arguments.
20344Refer to the ISA manual for a description of each instruction's operands.
20345
20346@smallexample
20347unsigned int __builtin_tbegin (unsigned int)
20348unsigned int __builtin_tend (unsigned int)
20349
20350unsigned int __builtin_tabort (unsigned int)
20351unsigned int __builtin_tabortdc (unsigned int, unsigned int, unsigned int)
20352unsigned int __builtin_tabortdci (unsigned int, unsigned int, int)
20353unsigned int __builtin_tabortwc (unsigned int, unsigned int, unsigned int)
20354unsigned int __builtin_tabortwci (unsigned int, unsigned int, int)
20355
20356unsigned int __builtin_tcheck (void)
20357unsigned int __builtin_treclaim (unsigned int)
20358unsigned int __builtin_trechkpt (void)
20359unsigned int __builtin_tsr (unsigned int)
20360@end smallexample
20361
20362In addition to the above HTM built-ins, we have added built-ins for
20363some common extended mnemonics of the HTM instructions:
20364
20365@smallexample
20366unsigned int __builtin_tendall (void)
20367unsigned int __builtin_tresume (void)
20368unsigned int __builtin_tsuspend (void)
20369@end smallexample
20370
20371Note that the semantics of the above HTM builtins are required to mimic
20372the locking semantics used for critical sections.  Builtins that are used
20373to create a new transaction or restart a suspended transaction must have
20374lock acquisition like semantics while those builtins that end or suspend a
20375transaction must have lock release like semantics.  Specifically, this must
20376mimic lock semantics as specified by C++11, for example: Lock acquisition is
20377as-if an execution of __atomic_exchange_n(&globallock,1,__ATOMIC_ACQUIRE)
20378that returns 0, and lock release is as-if an execution of
20379__atomic_store(&globallock,0,__ATOMIC_RELEASE), with globallock being an
20380implicit implementation-defined lock used for all transactions.  The HTM
20381instructions associated with with the builtins inherently provide the
20382correct acquisition and release hardware barriers required.  However,
20383the compiler must also be prohibited from moving loads and stores across
20384the builtins in a way that would violate their semantics.  This has been
20385accomplished by adding memory barriers to the associated HTM instructions
20386(which is a conservative approach to provide acquire and release semantics).
20387Earlier versions of the compiler did not treat the HTM instructions as
20388memory barriers.  A @code{__TM_FENCE__} macro has been added, which can
20389be used to determine whether the current compiler treats HTM instructions
20390as memory barriers or not.  This allows the user to explicitly add memory
20391barriers to their code when using an older version of the compiler.
20392
20393The following set of built-in functions are available to gain access
20394to the HTM specific special purpose registers.
20395
20396@smallexample
20397unsigned long __builtin_get_texasr (void)
20398unsigned long __builtin_get_texasru (void)
20399unsigned long __builtin_get_tfhar (void)
20400unsigned long __builtin_get_tfiar (void)
20401
20402void __builtin_set_texasr (unsigned long);
20403void __builtin_set_texasru (unsigned long);
20404void __builtin_set_tfhar (unsigned long);
20405void __builtin_set_tfiar (unsigned long);
20406@end smallexample
20407
20408Example usage of these low level built-in functions may look like:
20409
20410@smallexample
20411#include <htmintrin.h>
20412
20413int num_retries = 10;
20414
20415while (1)
20416  @{
20417    if (__builtin_tbegin (0))
20418      @{
20419        /* Transaction State Initiated.  */
20420        if (is_locked (lock))
20421          __builtin_tabort (0);
20422        ... transaction code...
20423        __builtin_tend (0);
20424        break;
20425      @}
20426    else
20427      @{
20428        /* Transaction State Failed.  Use locks if the transaction
20429           failure is "persistent" or we've tried too many times.  */
20430        if (num_retries-- <= 0
20431            || _TEXASRU_FAILURE_PERSISTENT (__builtin_get_texasru ()))
20432          @{
20433            acquire_lock (lock);
20434            ... non transactional fallback path...
20435            release_lock (lock);
20436            break;
20437          @}
20438      @}
20439  @}
20440@end smallexample
20441
20442One final built-in function has been added that returns the value of
20443the 2-bit Transaction State field of the Machine Status Register (MSR)
20444as stored in @code{CR0}.
20445
20446@smallexample
20447unsigned long __builtin_ttest (void)
20448@end smallexample
20449
20450This built-in can be used to determine the current transaction state
20451using the following code example:
20452
20453@smallexample
20454#include <htmintrin.h>
20455
20456unsigned char tx_state = _HTM_STATE (__builtin_ttest ());
20457
20458if (tx_state == _HTM_TRANSACTIONAL)
20459  @{
20460    /* Code to use in transactional state.  */
20461  @}
20462else if (tx_state == _HTM_NONTRANSACTIONAL)
20463  @{
20464    /* Code to use in non-transactional state.  */
20465  @}
20466else if (tx_state == _HTM_SUSPENDED)
20467  @{
20468    /* Code to use in transaction suspended state.  */
20469  @}
20470@end smallexample
20471
20472@subsubsection PowerPC HTM High Level Inline Functions
20473
20474The following high level HTM interface is made available by including
20475@code{<htmxlintrin.h>} and using @option{-mhtm} or @option{-mcpu=CPU}
20476where CPU is `power8' or later.  This interface is common between PowerPC
20477and S/390, allowing users to write one HTM source implementation that
20478can be compiled and executed on either system.
20479
20480@smallexample
20481long __TM_simple_begin (void)
20482long __TM_begin (void* const TM_buff)
20483long __TM_end (void)
20484void __TM_abort (void)
20485void __TM_named_abort (unsigned char const code)
20486void __TM_resume (void)
20487void __TM_suspend (void)
20488
20489long __TM_is_user_abort (void* const TM_buff)
20490long __TM_is_named_user_abort (void* const TM_buff, unsigned char *code)
20491long __TM_is_illegal (void* const TM_buff)
20492long __TM_is_footprint_exceeded (void* const TM_buff)
20493long __TM_nesting_depth (void* const TM_buff)
20494long __TM_is_nested_too_deep(void* const TM_buff)
20495long __TM_is_conflict(void* const TM_buff)
20496long __TM_is_failure_persistent(void* const TM_buff)
20497long __TM_failure_address(void* const TM_buff)
20498long long __TM_failure_code(void* const TM_buff)
20499@end smallexample
20500
20501Using these common set of HTM inline functions, we can create
20502a more portable version of the HTM example in the previous
20503section that will work on either PowerPC or S/390:
20504
20505@smallexample
20506#include <htmxlintrin.h>
20507
20508int num_retries = 10;
20509TM_buff_type TM_buff;
20510
20511while (1)
20512  @{
20513    if (__TM_begin (TM_buff) == _HTM_TBEGIN_STARTED)
20514      @{
20515        /* Transaction State Initiated.  */
20516        if (is_locked (lock))
20517          __TM_abort ();
20518        ... transaction code...
20519        __TM_end ();
20520        break;
20521      @}
20522    else
20523      @{
20524        /* Transaction State Failed.  Use locks if the transaction
20525           failure is "persistent" or we've tried too many times.  */
20526        if (num_retries-- <= 0
20527            || __TM_is_failure_persistent (TM_buff))
20528          @{
20529            acquire_lock (lock);
20530            ... non transactional fallback path...
20531            release_lock (lock);
20532            break;
20533          @}
20534      @}
20535  @}
20536@end smallexample
20537
20538@node PowerPC Atomic Memory Operation Functions
20539@subsection PowerPC Atomic Memory Operation Functions
20540ISA 3.0 of the PowerPC added new atomic memory operation (amo)
20541instructions.  GCC provides support for these instructions in 64-bit
20542environments.  All of the functions are declared in the include file
20543@code{amo.h}.
20544
20545The functions supported are:
20546
20547@smallexample
20548#include <amo.h>
20549
20550uint32_t amo_lwat_add (uint32_t *, uint32_t);
20551uint32_t amo_lwat_xor (uint32_t *, uint32_t);
20552uint32_t amo_lwat_ior (uint32_t *, uint32_t);
20553uint32_t amo_lwat_and (uint32_t *, uint32_t);
20554uint32_t amo_lwat_umax (uint32_t *, uint32_t);
20555uint32_t amo_lwat_umin (uint32_t *, uint32_t);
20556uint32_t amo_lwat_swap (uint32_t *, uint32_t);
20557
20558int32_t amo_lwat_sadd (int32_t *, int32_t);
20559int32_t amo_lwat_smax (int32_t *, int32_t);
20560int32_t amo_lwat_smin (int32_t *, int32_t);
20561int32_t amo_lwat_sswap (int32_t *, int32_t);
20562
20563uint64_t amo_ldat_add (uint64_t *, uint64_t);
20564uint64_t amo_ldat_xor (uint64_t *, uint64_t);
20565uint64_t amo_ldat_ior (uint64_t *, uint64_t);
20566uint64_t amo_ldat_and (uint64_t *, uint64_t);
20567uint64_t amo_ldat_umax (uint64_t *, uint64_t);
20568uint64_t amo_ldat_umin (uint64_t *, uint64_t);
20569uint64_t amo_ldat_swap (uint64_t *, uint64_t);
20570
20571int64_t amo_ldat_sadd (int64_t *, int64_t);
20572int64_t amo_ldat_smax (int64_t *, int64_t);
20573int64_t amo_ldat_smin (int64_t *, int64_t);
20574int64_t amo_ldat_sswap (int64_t *, int64_t);
20575
20576void amo_stwat_add (uint32_t *, uint32_t);
20577void amo_stwat_xor (uint32_t *, uint32_t);
20578void amo_stwat_ior (uint32_t *, uint32_t);
20579void amo_stwat_and (uint32_t *, uint32_t);
20580void amo_stwat_umax (uint32_t *, uint32_t);
20581void amo_stwat_umin (uint32_t *, uint32_t);
20582
20583void amo_stwat_sadd (int32_t *, int32_t);
20584void amo_stwat_smax (int32_t *, int32_t);
20585void amo_stwat_smin (int32_t *, int32_t);
20586
20587void amo_stdat_add (uint64_t *, uint64_t);
20588void amo_stdat_xor (uint64_t *, uint64_t);
20589void amo_stdat_ior (uint64_t *, uint64_t);
20590void amo_stdat_and (uint64_t *, uint64_t);
20591void amo_stdat_umax (uint64_t *, uint64_t);
20592void amo_stdat_umin (uint64_t *, uint64_t);
20593
20594void amo_stdat_sadd (int64_t *, int64_t);
20595void amo_stdat_smax (int64_t *, int64_t);
20596void amo_stdat_smin (int64_t *, int64_t);
20597@end smallexample
20598
20599@node PowerPC Matrix-Multiply Assist Built-in Functions
20600@subsection PowerPC Matrix-Multiply Assist Built-in Functions
20601ISA 3.1 of the PowerPC added new Matrix-Multiply Assist (MMA) instructions.
20602GCC provides support for these instructions through the following built-in
20603functions which are enabled with the @code{-mmma} option.  The vec_t type
20604below is defined to be a normal vector unsigned char type.  The uint2, uint4
20605and uint8 parameters are 2-bit, 4-bit and 8-bit unsigned integer constants
20606respectively.  The compiler will verify that they are constants and that
20607their values are within range.
20608
20609The built-in functions supported are:
20610
20611@smallexample
20612void __builtin_mma_xvi4ger8 (__vector_quad *, vec_t, vec_t);
20613void __builtin_mma_xvi8ger4 (__vector_quad *, vec_t, vec_t);
20614void __builtin_mma_xvi16ger2 (__vector_quad *, vec_t, vec_t);
20615void __builtin_mma_xvi16ger2s (__vector_quad *, vec_t, vec_t);
20616void __builtin_mma_xvf16ger2 (__vector_quad *, vec_t, vec_t);
20617void __builtin_mma_xvbf16ger2 (__vector_quad *, vec_t, vec_t);
20618void __builtin_mma_xvf32ger (__vector_quad *, vec_t, vec_t);
20619
20620void __builtin_mma_xvi4ger8pp (__vector_quad *, vec_t, vec_t);
20621void __builtin_mma_xvi8ger4pp (__vector_quad *, vec_t, vec_t);
20622void __builtin_mma_xvi8ger4spp(__vector_quad *, vec_t, vec_t);
20623void __builtin_mma_xvi16ger2pp (__vector_quad *, vec_t, vec_t);
20624void __builtin_mma_xvi16ger2spp (__vector_quad *, vec_t, vec_t);
20625void __builtin_mma_xvf16ger2pp (__vector_quad *, vec_t, vec_t);
20626void __builtin_mma_xvf16ger2pn (__vector_quad *, vec_t, vec_t);
20627void __builtin_mma_xvf16ger2np (__vector_quad *, vec_t, vec_t);
20628void __builtin_mma_xvf16ger2nn (__vector_quad *, vec_t, vec_t);
20629void __builtin_mma_xvbf16ger2pp (__vector_quad *, vec_t, vec_t);
20630void __builtin_mma_xvbf16ger2pn (__vector_quad *, vec_t, vec_t);
20631void __builtin_mma_xvbf16ger2np (__vector_quad *, vec_t, vec_t);
20632void __builtin_mma_xvbf16ger2nn (__vector_quad *, vec_t, vec_t);
20633void __builtin_mma_xvf32gerpp (__vector_quad *, vec_t, vec_t);
20634void __builtin_mma_xvf32gerpn (__vector_quad *, vec_t, vec_t);
20635void __builtin_mma_xvf32gernp (__vector_quad *, vec_t, vec_t);
20636void __builtin_mma_xvf32gernn (__vector_quad *, vec_t, vec_t);
20637
20638void __builtin_mma_pmxvi4ger8 (__vector_quad *, vec_t, vec_t, uint4, uint4, uint8);
20639void __builtin_mma_pmxvi4ger8pp (__vector_quad *, vec_t, vec_t, uint4, uint4, uint8);
20640
20641void __builtin_mma_pmxvi8ger4 (__vector_quad *, vec_t, vec_t, uint4, uint4, uint4);
20642void __builtin_mma_pmxvi8ger4pp (__vector_quad *, vec_t, vec_t, uint4, uint4, uint4);
20643void __builtin_mma_pmxvi8ger4spp(__vector_quad *, vec_t, vec_t, uint4, uint4, uint4);
20644
20645void __builtin_mma_pmxvi16ger2 (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2);
20646void __builtin_mma_pmxvi16ger2s (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2);
20647void __builtin_mma_pmxvf16ger2 (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2);
20648void __builtin_mma_pmxvbf16ger2 (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2);
20649
20650void __builtin_mma_pmxvi16ger2pp (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2);
20651void __builtin_mma_pmxvi16ger2spp (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2);
20652void __builtin_mma_pmxvf16ger2pp (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2);
20653void __builtin_mma_pmxvf16ger2pn (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2);
20654void __builtin_mma_pmxvf16ger2np (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2);
20655void __builtin_mma_pmxvf16ger2nn (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2);
20656void __builtin_mma_pmxvbf16ger2pp (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2);
20657void __builtin_mma_pmxvbf16ger2pn (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2);
20658void __builtin_mma_pmxvbf16ger2np (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2);
20659void __builtin_mma_pmxvbf16ger2nn (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2);
20660
20661void __builtin_mma_pmxvf32ger (__vector_quad *, vec_t, vec_t, uint4, uint4);
20662void __builtin_mma_pmxvf32gerpp (__vector_quad *, vec_t, vec_t, uint4, uint4);
20663void __builtin_mma_pmxvf32gerpn (__vector_quad *, vec_t, vec_t, uint4, uint4);
20664void __builtin_mma_pmxvf32gernp (__vector_quad *, vec_t, vec_t, uint4, uint4);
20665void __builtin_mma_pmxvf32gernn (__vector_quad *, vec_t, vec_t, uint4, uint4);
20666
20667void __builtin_mma_xvf64ger (__vector_quad *, __vector_pair, vec_t);
20668void __builtin_mma_xvf64gerpp (__vector_quad *, __vector_pair, vec_t);
20669void __builtin_mma_xvf64gerpn (__vector_quad *, __vector_pair, vec_t);
20670void __builtin_mma_xvf64gernp (__vector_quad *, __vector_pair, vec_t);
20671void __builtin_mma_xvf64gernn (__vector_quad *, __vector_pair, vec_t);
20672
20673void __builtin_mma_pmxvf64ger (__vector_quad *, __vector_pair, vec_t, uint4, uint2);
20674void __builtin_mma_pmxvf64gerpp (__vector_quad *, __vector_pair, vec_t, uint4, uint2);
20675void __builtin_mma_pmxvf64gerpn (__vector_quad *, __vector_pair, vec_t, uint4, uint2);
20676void __builtin_mma_pmxvf64gernp (__vector_quad *, __vector_pair, vec_t, uint4, uint2);
20677void __builtin_mma_pmxvf64gernn (__vector_quad *, __vector_pair, vec_t, uint4, uint2);
20678
20679void __builtin_mma_xxmtacc (__vector_quad *);
20680void __builtin_mma_xxmfacc (__vector_quad *);
20681void __builtin_mma_xxsetaccz (__vector_quad *);
20682
20683void __builtin_mma_build_acc (__vector_quad *, vec_t, vec_t, vec_t, vec_t);
20684void __builtin_mma_disassemble_acc (void *, __vector_quad *);
20685
20686void __builtin_vsx_build_pair (__vector_pair *, vec_t, vec_t);
20687void __builtin_vsx_disassemble_pair (void *, __vector_pair *);
20688
20689vec_t __builtin_vsx_xvcvspbf16 (vec_t);
20690vec_t __builtin_vsx_xvcvbf16spn (vec_t);
20691
20692__vector_pair __builtin_vsx_lxvp (size_t, __vector_pair *);
20693void __builtin_vsx_stxvp (__vector_pair, size_t, __vector_pair *);
20694@end smallexample
20695
20696@node PRU Built-in Functions
20697@subsection PRU Built-in Functions
20698
20699GCC provides a couple of special builtin functions to aid in utilizing
20700special PRU instructions.
20701
20702The built-in functions supported are:
20703
20704@table @code
20705@item __delay_cycles (long long @var{cycles})
20706This inserts an instruction sequence that takes exactly @var{cycles}
20707cycles (between 0 and 0xffffffff) to complete.  The inserted sequence
20708may use jumps, loops, or no-ops, and does not interfere with any other
20709instructions.  Note that @var{cycles} must be a compile-time constant
20710integer - that is, you must pass a number, not a variable that may be
20711optimized to a constant later.  The number of cycles delayed by this
20712builtin is exact.
20713
20714@item __halt (void)
20715This inserts a HALT instruction to stop processor execution.
20716
20717@item unsigned int __lmbd (unsigned int @var{wordval}, unsigned int @var{bitval})
20718This inserts LMBD instruction to calculate the left-most bit with value
20719@var{bitval} in value @var{wordval}.  Only the least significant bit
20720of @var{bitval} is taken into account.
20721@end table
20722
20723@node RISC-V Built-in Functions
20724@subsection RISC-V Built-in Functions
20725
20726These built-in functions are available for the RISC-V family of
20727processors.
20728
20729@deftypefn {Built-in Function} {void *} __builtin_thread_pointer (void)
20730Returns the value that is currently set in the @samp{tp} register.
20731@end deftypefn
20732
20733@node RX Built-in Functions
20734@subsection RX Built-in Functions
20735GCC supports some of the RX instructions which cannot be expressed in
20736the C programming language via the use of built-in functions.  The
20737following functions are supported:
20738
20739@deftypefn {Built-in Function}  void __builtin_rx_brk (void)
20740Generates the @code{brk} machine instruction.
20741@end deftypefn
20742
20743@deftypefn {Built-in Function}  void __builtin_rx_clrpsw (int)
20744Generates the @code{clrpsw} machine instruction to clear the specified
20745bit in the processor status word.
20746@end deftypefn
20747
20748@deftypefn {Built-in Function}  void __builtin_rx_int (int)
20749Generates the @code{int} machine instruction to generate an interrupt
20750with the specified value.
20751@end deftypefn
20752
20753@deftypefn {Built-in Function}  void __builtin_rx_machi (int, int)
20754Generates the @code{machi} machine instruction to add the result of
20755multiplying the top 16 bits of the two arguments into the
20756accumulator.
20757@end deftypefn
20758
20759@deftypefn {Built-in Function}  void __builtin_rx_maclo (int, int)
20760Generates the @code{maclo} machine instruction to add the result of
20761multiplying the bottom 16 bits of the two arguments into the
20762accumulator.
20763@end deftypefn
20764
20765@deftypefn {Built-in Function}  void __builtin_rx_mulhi (int, int)
20766Generates the @code{mulhi} machine instruction to place the result of
20767multiplying the top 16 bits of the two arguments into the
20768accumulator.
20769@end deftypefn
20770
20771@deftypefn {Built-in Function}  void __builtin_rx_mullo (int, int)
20772Generates the @code{mullo} machine instruction to place the result of
20773multiplying the bottom 16 bits of the two arguments into the
20774accumulator.
20775@end deftypefn
20776
20777@deftypefn {Built-in Function}  int  __builtin_rx_mvfachi (void)
20778Generates the @code{mvfachi} machine instruction to read the top
2077932 bits of the accumulator.
20780@end deftypefn
20781
20782@deftypefn {Built-in Function}  int  __builtin_rx_mvfacmi (void)
20783Generates the @code{mvfacmi} machine instruction to read the middle
2078432 bits of the accumulator.
20785@end deftypefn
20786
20787@deftypefn {Built-in Function}  int __builtin_rx_mvfc (int)
20788Generates the @code{mvfc} machine instruction which reads the control
20789register specified in its argument and returns its value.
20790@end deftypefn
20791
20792@deftypefn {Built-in Function}  void __builtin_rx_mvtachi (int)
20793Generates the @code{mvtachi} machine instruction to set the top
2079432 bits of the accumulator.
20795@end deftypefn
20796
20797@deftypefn {Built-in Function}  void __builtin_rx_mvtaclo (int)
20798Generates the @code{mvtaclo} machine instruction to set the bottom
2079932 bits of the accumulator.
20800@end deftypefn
20801
20802@deftypefn {Built-in Function}  void __builtin_rx_mvtc (int reg, int val)
20803Generates the @code{mvtc} machine instruction which sets control
20804register number @code{reg} to @code{val}.
20805@end deftypefn
20806
20807@deftypefn {Built-in Function}  void __builtin_rx_mvtipl (int)
20808Generates the @code{mvtipl} machine instruction set the interrupt
20809priority level.
20810@end deftypefn
20811
20812@deftypefn {Built-in Function}  void __builtin_rx_racw (int)
20813Generates the @code{racw} machine instruction to round the accumulator
20814according to the specified mode.
20815@end deftypefn
20816
20817@deftypefn {Built-in Function}  int __builtin_rx_revw (int)
20818Generates the @code{revw} machine instruction which swaps the bytes in
20819the argument so that bits 0--7 now occupy bits 8--15 and vice versa,
20820and also bits 16--23 occupy bits 24--31 and vice versa.
20821@end deftypefn
20822
20823@deftypefn {Built-in Function}  void __builtin_rx_rmpa (void)
20824Generates the @code{rmpa} machine instruction which initiates a
20825repeated multiply and accumulate sequence.
20826@end deftypefn
20827
20828@deftypefn {Built-in Function}  void __builtin_rx_round (float)
20829Generates the @code{round} machine instruction which returns the
20830floating-point argument rounded according to the current rounding mode
20831set in the floating-point status word register.
20832@end deftypefn
20833
20834@deftypefn {Built-in Function}  int __builtin_rx_sat (int)
20835Generates the @code{sat} machine instruction which returns the
20836saturated value of the argument.
20837@end deftypefn
20838
20839@deftypefn {Built-in Function}  void __builtin_rx_setpsw (int)
20840Generates the @code{setpsw} machine instruction to set the specified
20841bit in the processor status word.
20842@end deftypefn
20843
20844@deftypefn {Built-in Function}  void __builtin_rx_wait (void)
20845Generates the @code{wait} machine instruction.
20846@end deftypefn
20847
20848@node S/390 System z Built-in Functions
20849@subsection S/390 System z Built-in Functions
20850@deftypefn {Built-in Function} int __builtin_tbegin (void*)
20851Generates the @code{tbegin} machine instruction starting a
20852non-constrained hardware transaction.  If the parameter is non-NULL the
20853memory area is used to store the transaction diagnostic buffer and
20854will be passed as first operand to @code{tbegin}.  This buffer can be
20855defined using the @code{struct __htm_tdb} C struct defined in
20856@code{htmintrin.h} and must reside on a double-word boundary.  The
20857second tbegin operand is set to @code{0xff0c}. This enables
20858save/restore of all GPRs and disables aborts for FPR and AR
20859manipulations inside the transaction body.  The condition code set by
20860the tbegin instruction is returned as integer value.  The tbegin
20861instruction by definition overwrites the content of all FPRs.  The
20862compiler will generate code which saves and restores the FPRs.  For
20863soft-float code it is recommended to used the @code{*_nofloat}
20864variant.  In order to prevent a TDB from being written it is required
20865to pass a constant zero value as parameter.  Passing a zero value
20866through a variable is not sufficient.  Although modifications of
20867access registers inside the transaction will not trigger an
20868transaction abort it is not supported to actually modify them.  Access
20869registers do not get saved when entering a transaction. They will have
20870undefined state when reaching the abort code.
20871@end deftypefn
20872
20873Macros for the possible return codes of tbegin are defined in the
20874@code{htmintrin.h} header file:
20875
20876@table @code
20877@item _HTM_TBEGIN_STARTED
20878@code{tbegin} has been executed as part of normal processing.  The
20879transaction body is supposed to be executed.
20880@item _HTM_TBEGIN_INDETERMINATE
20881The transaction was aborted due to an indeterminate condition which
20882might be persistent.
20883@item _HTM_TBEGIN_TRANSIENT
20884The transaction aborted due to a transient failure.  The transaction
20885should be re-executed in that case.
20886@item _HTM_TBEGIN_PERSISTENT
20887The transaction aborted due to a persistent failure.  Re-execution
20888under same circumstances will not be productive.
20889@end table
20890
20891@defmac _HTM_FIRST_USER_ABORT_CODE
20892The @code{_HTM_FIRST_USER_ABORT_CODE} defined in @code{htmintrin.h}
20893specifies the first abort code which can be used for
20894@code{__builtin_tabort}.  Values below this threshold are reserved for
20895machine use.
20896@end defmac
20897
20898@deftp {Data type} {struct __htm_tdb}
20899The @code{struct __htm_tdb} defined in @code{htmintrin.h} describes
20900the structure of the transaction diagnostic block as specified in the
20901Principles of Operation manual chapter 5-91.
20902@end deftp
20903
20904@deftypefn {Built-in Function} int __builtin_tbegin_nofloat (void*)
20905Same as @code{__builtin_tbegin} but without FPR saves and restores.
20906Using this variant in code making use of FPRs will leave the FPRs in
20907undefined state when entering the transaction abort handler code.
20908@end deftypefn
20909
20910@deftypefn {Built-in Function} int __builtin_tbegin_retry (void*, int)
20911In addition to @code{__builtin_tbegin} a loop for transient failures
20912is generated.  If tbegin returns a condition code of 2 the transaction
20913will be retried as often as specified in the second argument.  The
20914perform processor assist instruction is used to tell the CPU about the
20915number of fails so far.
20916@end deftypefn
20917
20918@deftypefn {Built-in Function} int __builtin_tbegin_retry_nofloat (void*, int)
20919Same as @code{__builtin_tbegin_retry} but without FPR saves and
20920restores.  Using this variant in code making use of FPRs will leave
20921the FPRs in undefined state when entering the transaction abort
20922handler code.
20923@end deftypefn
20924
20925@deftypefn {Built-in Function} void __builtin_tbeginc (void)
20926Generates the @code{tbeginc} machine instruction starting a constrained
20927hardware transaction.  The second operand is set to @code{0xff08}.
20928@end deftypefn
20929
20930@deftypefn {Built-in Function} int __builtin_tend (void)
20931Generates the @code{tend} machine instruction finishing a transaction
20932and making the changes visible to other threads.  The condition code
20933generated by tend is returned as integer value.
20934@end deftypefn
20935
20936@deftypefn {Built-in Function} void __builtin_tabort (int)
20937Generates the @code{tabort} machine instruction with the specified
20938abort code.  Abort codes from 0 through 255 are reserved and will
20939result in an error message.
20940@end deftypefn
20941
20942@deftypefn {Built-in Function} void __builtin_tx_assist (int)
20943Generates the @code{ppa rX,rY,1} machine instruction.  Where the
20944integer parameter is loaded into rX and a value of zero is loaded into
20945rY.  The integer parameter specifies the number of times the
20946transaction repeatedly aborted.
20947@end deftypefn
20948
20949@deftypefn {Built-in Function} int __builtin_tx_nesting_depth (void)
20950Generates the @code{etnd} machine instruction.  The current nesting
20951depth is returned as integer value.  For a nesting depth of 0 the code
20952is not executed as part of an transaction.
20953@end deftypefn
20954
20955@deftypefn {Built-in Function} void __builtin_non_tx_store (uint64_t *, uint64_t)
20956
20957Generates the @code{ntstg} machine instruction.  The second argument
20958is written to the first arguments location.  The store operation will
20959not be rolled-back in case of an transaction abort.
20960@end deftypefn
20961
20962@node SH Built-in Functions
20963@subsection SH Built-in Functions
20964The following built-in functions are supported on the SH1, SH2, SH3 and SH4
20965families of processors:
20966
20967@deftypefn {Built-in Function} {void} __builtin_set_thread_pointer (void *@var{ptr})
20968Sets the @samp{GBR} register to the specified value @var{ptr}.  This is usually
20969used by system code that manages threads and execution contexts.  The compiler
20970normally does not generate code that modifies the contents of @samp{GBR} and
20971thus the value is preserved across function calls.  Changing the @samp{GBR}
20972value in user code must be done with caution, since the compiler might use
20973@samp{GBR} in order to access thread local variables.
20974
20975@end deftypefn
20976
20977@deftypefn {Built-in Function} {void *} __builtin_thread_pointer (void)
20978Returns the value that is currently set in the @samp{GBR} register.
20979Memory loads and stores that use the thread pointer as a base address are
20980turned into @samp{GBR} based displacement loads and stores, if possible.
20981For example:
20982@smallexample
20983struct my_tcb
20984@{
20985   int a, b, c, d, e;
20986@};
20987
20988int get_tcb_value (void)
20989@{
20990  // Generate @samp{mov.l @@(8,gbr),r0} instruction
20991  return ((my_tcb*)__builtin_thread_pointer ())->c;
20992@}
20993
20994@end smallexample
20995@end deftypefn
20996
20997@deftypefn {Built-in Function} {unsigned int} __builtin_sh_get_fpscr (void)
20998Returns the value that is currently set in the @samp{FPSCR} register.
20999@end deftypefn
21000
21001@deftypefn {Built-in Function} {void} __builtin_sh_set_fpscr (unsigned int @var{val})
21002Sets the @samp{FPSCR} register to the specified value @var{val}, while
21003preserving the current values of the FR, SZ and PR bits.
21004@end deftypefn
21005
21006@node SPARC VIS Built-in Functions
21007@subsection SPARC VIS Built-in Functions
21008
21009GCC supports SIMD operations on the SPARC using both the generic vector
21010extensions (@pxref{Vector Extensions}) as well as built-in functions for
21011the SPARC Visual Instruction Set (VIS).  When you use the @option{-mvis}
21012switch, the VIS extension is exposed as the following built-in functions:
21013
21014@smallexample
21015typedef int v1si __attribute__ ((vector_size (4)));
21016typedef int v2si __attribute__ ((vector_size (8)));
21017typedef short v4hi __attribute__ ((vector_size (8)));
21018typedef short v2hi __attribute__ ((vector_size (4)));
21019typedef unsigned char v8qi __attribute__ ((vector_size (8)));
21020typedef unsigned char v4qi __attribute__ ((vector_size (4)));
21021
21022void __builtin_vis_write_gsr (int64_t);
21023int64_t __builtin_vis_read_gsr (void);
21024
21025void * __builtin_vis_alignaddr (void *, long);
21026void * __builtin_vis_alignaddrl (void *, long);
21027int64_t __builtin_vis_faligndatadi (int64_t, int64_t);
21028v2si __builtin_vis_faligndatav2si (v2si, v2si);
21029v4hi __builtin_vis_faligndatav4hi (v4si, v4si);
21030v8qi __builtin_vis_faligndatav8qi (v8qi, v8qi);
21031
21032v4hi __builtin_vis_fexpand (v4qi);
21033
21034v4hi __builtin_vis_fmul8x16 (v4qi, v4hi);
21035v4hi __builtin_vis_fmul8x16au (v4qi, v2hi);
21036v4hi __builtin_vis_fmul8x16al (v4qi, v2hi);
21037v4hi __builtin_vis_fmul8sux16 (v8qi, v4hi);
21038v4hi __builtin_vis_fmul8ulx16 (v8qi, v4hi);
21039v2si __builtin_vis_fmuld8sux16 (v4qi, v2hi);
21040v2si __builtin_vis_fmuld8ulx16 (v4qi, v2hi);
21041
21042v4qi __builtin_vis_fpack16 (v4hi);
21043v8qi __builtin_vis_fpack32 (v2si, v8qi);
21044v2hi __builtin_vis_fpackfix (v2si);
21045v8qi __builtin_vis_fpmerge (v4qi, v4qi);
21046
21047int64_t __builtin_vis_pdist (v8qi, v8qi, int64_t);
21048
21049long __builtin_vis_edge8 (void *, void *);
21050long __builtin_vis_edge8l (void *, void *);
21051long __builtin_vis_edge16 (void *, void *);
21052long __builtin_vis_edge16l (void *, void *);
21053long __builtin_vis_edge32 (void *, void *);
21054long __builtin_vis_edge32l (void *, void *);
21055
21056long __builtin_vis_fcmple16 (v4hi, v4hi);
21057long __builtin_vis_fcmple32 (v2si, v2si);
21058long __builtin_vis_fcmpne16 (v4hi, v4hi);
21059long __builtin_vis_fcmpne32 (v2si, v2si);
21060long __builtin_vis_fcmpgt16 (v4hi, v4hi);
21061long __builtin_vis_fcmpgt32 (v2si, v2si);
21062long __builtin_vis_fcmpeq16 (v4hi, v4hi);
21063long __builtin_vis_fcmpeq32 (v2si, v2si);
21064
21065v4hi __builtin_vis_fpadd16 (v4hi, v4hi);
21066v2hi __builtin_vis_fpadd16s (v2hi, v2hi);
21067v2si __builtin_vis_fpadd32 (v2si, v2si);
21068v1si __builtin_vis_fpadd32s (v1si, v1si);
21069v4hi __builtin_vis_fpsub16 (v4hi, v4hi);
21070v2hi __builtin_vis_fpsub16s (v2hi, v2hi);
21071v2si __builtin_vis_fpsub32 (v2si, v2si);
21072v1si __builtin_vis_fpsub32s (v1si, v1si);
21073
21074long __builtin_vis_array8 (long, long);
21075long __builtin_vis_array16 (long, long);
21076long __builtin_vis_array32 (long, long);
21077@end smallexample
21078
21079When you use the @option{-mvis2} switch, the VIS version 2.0 built-in
21080functions also become available:
21081
21082@smallexample
21083long __builtin_vis_bmask (long, long);
21084int64_t __builtin_vis_bshuffledi (int64_t, int64_t);
21085v2si __builtin_vis_bshufflev2si (v2si, v2si);
21086v4hi __builtin_vis_bshufflev2si (v4hi, v4hi);
21087v8qi __builtin_vis_bshufflev2si (v8qi, v8qi);
21088
21089long __builtin_vis_edge8n (void *, void *);
21090long __builtin_vis_edge8ln (void *, void *);
21091long __builtin_vis_edge16n (void *, void *);
21092long __builtin_vis_edge16ln (void *, void *);
21093long __builtin_vis_edge32n (void *, void *);
21094long __builtin_vis_edge32ln (void *, void *);
21095@end smallexample
21096
21097When you use the @option{-mvis3} switch, the VIS version 3.0 built-in
21098functions also become available:
21099
21100@smallexample
21101void __builtin_vis_cmask8 (long);
21102void __builtin_vis_cmask16 (long);
21103void __builtin_vis_cmask32 (long);
21104
21105v4hi __builtin_vis_fchksm16 (v4hi, v4hi);
21106
21107v4hi __builtin_vis_fsll16 (v4hi, v4hi);
21108v4hi __builtin_vis_fslas16 (v4hi, v4hi);
21109v4hi __builtin_vis_fsrl16 (v4hi, v4hi);
21110v4hi __builtin_vis_fsra16 (v4hi, v4hi);
21111v2si __builtin_vis_fsll16 (v2si, v2si);
21112v2si __builtin_vis_fslas16 (v2si, v2si);
21113v2si __builtin_vis_fsrl16 (v2si, v2si);
21114v2si __builtin_vis_fsra16 (v2si, v2si);
21115
21116long __builtin_vis_pdistn (v8qi, v8qi);
21117
21118v4hi __builtin_vis_fmean16 (v4hi, v4hi);
21119
21120int64_t __builtin_vis_fpadd64 (int64_t, int64_t);
21121int64_t __builtin_vis_fpsub64 (int64_t, int64_t);
21122
21123v4hi __builtin_vis_fpadds16 (v4hi, v4hi);
21124v2hi __builtin_vis_fpadds16s (v2hi, v2hi);
21125v4hi __builtin_vis_fpsubs16 (v4hi, v4hi);
21126v2hi __builtin_vis_fpsubs16s (v2hi, v2hi);
21127v2si __builtin_vis_fpadds32 (v2si, v2si);
21128v1si __builtin_vis_fpadds32s (v1si, v1si);
21129v2si __builtin_vis_fpsubs32 (v2si, v2si);
21130v1si __builtin_vis_fpsubs32s (v1si, v1si);
21131
21132long __builtin_vis_fucmple8 (v8qi, v8qi);
21133long __builtin_vis_fucmpne8 (v8qi, v8qi);
21134long __builtin_vis_fucmpgt8 (v8qi, v8qi);
21135long __builtin_vis_fucmpeq8 (v8qi, v8qi);
21136
21137float __builtin_vis_fhadds (float, float);
21138double __builtin_vis_fhaddd (double, double);
21139float __builtin_vis_fhsubs (float, float);
21140double __builtin_vis_fhsubd (double, double);
21141float __builtin_vis_fnhadds (float, float);
21142double __builtin_vis_fnhaddd (double, double);
21143
21144int64_t __builtin_vis_umulxhi (int64_t, int64_t);
21145int64_t __builtin_vis_xmulx (int64_t, int64_t);
21146int64_t __builtin_vis_xmulxhi (int64_t, int64_t);
21147@end smallexample
21148
21149When you use the @option{-mvis4} switch, the VIS version 4.0 built-in
21150functions also become available:
21151
21152@smallexample
21153v8qi __builtin_vis_fpadd8 (v8qi, v8qi);
21154v8qi __builtin_vis_fpadds8 (v8qi, v8qi);
21155v8qi __builtin_vis_fpaddus8 (v8qi, v8qi);
21156v4hi __builtin_vis_fpaddus16 (v4hi, v4hi);
21157
21158v8qi __builtin_vis_fpsub8 (v8qi, v8qi);
21159v8qi __builtin_vis_fpsubs8 (v8qi, v8qi);
21160v8qi __builtin_vis_fpsubus8 (v8qi, v8qi);
21161v4hi __builtin_vis_fpsubus16 (v4hi, v4hi);
21162
21163long __builtin_vis_fpcmple8 (v8qi, v8qi);
21164long __builtin_vis_fpcmpgt8 (v8qi, v8qi);
21165long __builtin_vis_fpcmpule16 (v4hi, v4hi);
21166long __builtin_vis_fpcmpugt16 (v4hi, v4hi);
21167long __builtin_vis_fpcmpule32 (v2si, v2si);
21168long __builtin_vis_fpcmpugt32 (v2si, v2si);
21169
21170v8qi __builtin_vis_fpmax8 (v8qi, v8qi);
21171v4hi __builtin_vis_fpmax16 (v4hi, v4hi);
21172v2si __builtin_vis_fpmax32 (v2si, v2si);
21173
21174v8qi __builtin_vis_fpmaxu8 (v8qi, v8qi);
21175v4hi __builtin_vis_fpmaxu16 (v4hi, v4hi);
21176v2si __builtin_vis_fpmaxu32 (v2si, v2si);
21177
21178v8qi __builtin_vis_fpmin8 (v8qi, v8qi);
21179v4hi __builtin_vis_fpmin16 (v4hi, v4hi);
21180v2si __builtin_vis_fpmin32 (v2si, v2si);
21181
21182v8qi __builtin_vis_fpminu8 (v8qi, v8qi);
21183v4hi __builtin_vis_fpminu16 (v4hi, v4hi);
21184v2si __builtin_vis_fpminu32 (v2si, v2si);
21185@end smallexample
21186
21187When you use the @option{-mvis4b} switch, the VIS version 4.0B
21188built-in functions also become available:
21189
21190@smallexample
21191v8qi __builtin_vis_dictunpack8 (double, int);
21192v4hi __builtin_vis_dictunpack16 (double, int);
21193v2si __builtin_vis_dictunpack32 (double, int);
21194
21195long __builtin_vis_fpcmple8shl (v8qi, v8qi, int);
21196long __builtin_vis_fpcmpgt8shl (v8qi, v8qi, int);
21197long __builtin_vis_fpcmpeq8shl (v8qi, v8qi, int);
21198long __builtin_vis_fpcmpne8shl (v8qi, v8qi, int);
21199
21200long __builtin_vis_fpcmple16shl (v4hi, v4hi, int);
21201long __builtin_vis_fpcmpgt16shl (v4hi, v4hi, int);
21202long __builtin_vis_fpcmpeq16shl (v4hi, v4hi, int);
21203long __builtin_vis_fpcmpne16shl (v4hi, v4hi, int);
21204
21205long __builtin_vis_fpcmple32shl (v2si, v2si, int);
21206long __builtin_vis_fpcmpgt32shl (v2si, v2si, int);
21207long __builtin_vis_fpcmpeq32shl (v2si, v2si, int);
21208long __builtin_vis_fpcmpne32shl (v2si, v2si, int);
21209
21210long __builtin_vis_fpcmpule8shl (v8qi, v8qi, int);
21211long __builtin_vis_fpcmpugt8shl (v8qi, v8qi, int);
21212long __builtin_vis_fpcmpule16shl (v4hi, v4hi, int);
21213long __builtin_vis_fpcmpugt16shl (v4hi, v4hi, int);
21214long __builtin_vis_fpcmpule32shl (v2si, v2si, int);
21215long __builtin_vis_fpcmpugt32shl (v2si, v2si, int);
21216
21217long __builtin_vis_fpcmpde8shl (v8qi, v8qi, int);
21218long __builtin_vis_fpcmpde16shl (v4hi, v4hi, int);
21219long __builtin_vis_fpcmpde32shl (v2si, v2si, int);
21220
21221long __builtin_vis_fpcmpur8shl (v8qi, v8qi, int);
21222long __builtin_vis_fpcmpur16shl (v4hi, v4hi, int);
21223long __builtin_vis_fpcmpur32shl (v2si, v2si, int);
21224@end smallexample
21225
21226@node TI C6X Built-in Functions
21227@subsection TI C6X Built-in Functions
21228
21229GCC provides intrinsics to access certain instructions of the TI C6X
21230processors.  These intrinsics, listed below, are available after
21231inclusion of the @code{c6x_intrinsics.h} header file.  They map directly
21232to C6X instructions.
21233
21234@smallexample
21235
21236int _sadd (int, int)
21237int _ssub (int, int)
21238int _sadd2 (int, int)
21239int _ssub2 (int, int)
21240long long _mpy2 (int, int)
21241long long _smpy2 (int, int)
21242int _add4 (int, int)
21243int _sub4 (int, int)
21244int _saddu4 (int, int)
21245
21246int _smpy (int, int)
21247int _smpyh (int, int)
21248int _smpyhl (int, int)
21249int _smpylh (int, int)
21250
21251int _sshl (int, int)
21252int _subc (int, int)
21253
21254int _avg2 (int, int)
21255int _avgu4 (int, int)
21256
21257int _clrr (int, int)
21258int _extr (int, int)
21259int _extru (int, int)
21260int _abs (int)
21261int _abs2 (int)
21262
21263@end smallexample
21264
21265@node TILE-Gx Built-in Functions
21266@subsection TILE-Gx Built-in Functions
21267
21268GCC provides intrinsics to access every instruction of the TILE-Gx
21269processor.  The intrinsics are of the form:
21270
21271@smallexample
21272
21273unsigned long long __insn_@var{op} (...)
21274
21275@end smallexample
21276
21277Where @var{op} is the name of the instruction.  Refer to the ISA manual
21278for the complete list of instructions.
21279
21280GCC also provides intrinsics to directly access the network registers.
21281The intrinsics are:
21282
21283@smallexample
21284
21285unsigned long long __tile_idn0_receive (void)
21286unsigned long long __tile_idn1_receive (void)
21287unsigned long long __tile_udn0_receive (void)
21288unsigned long long __tile_udn1_receive (void)
21289unsigned long long __tile_udn2_receive (void)
21290unsigned long long __tile_udn3_receive (void)
21291void __tile_idn_send (unsigned long long)
21292void __tile_udn_send (unsigned long long)
21293
21294@end smallexample
21295
21296The intrinsic @code{void __tile_network_barrier (void)} is used to
21297guarantee that no network operations before it are reordered with
21298those after it.
21299
21300@node TILEPro Built-in Functions
21301@subsection TILEPro Built-in Functions
21302
21303GCC provides intrinsics to access every instruction of the TILEPro
21304processor.  The intrinsics are of the form:
21305
21306@smallexample
21307
21308unsigned __insn_@var{op} (...)
21309
21310@end smallexample
21311
21312@noindent
21313where @var{op} is the name of the instruction.  Refer to the ISA manual
21314for the complete list of instructions.
21315
21316GCC also provides intrinsics to directly access the network registers.
21317The intrinsics are:
21318
21319@smallexample
21320
21321unsigned __tile_idn0_receive (void)
21322unsigned __tile_idn1_receive (void)
21323unsigned __tile_sn_receive (void)
21324unsigned __tile_udn0_receive (void)
21325unsigned __tile_udn1_receive (void)
21326unsigned __tile_udn2_receive (void)
21327unsigned __tile_udn3_receive (void)
21328void __tile_idn_send (unsigned)
21329void __tile_sn_send (unsigned)
21330void __tile_udn_send (unsigned)
21331
21332@end smallexample
21333
21334The intrinsic @code{void __tile_network_barrier (void)} is used to
21335guarantee that no network operations before it are reordered with
21336those after it.
21337
21338@node x86 Built-in Functions
21339@subsection x86 Built-in Functions
21340
21341These built-in functions are available for the x86-32 and x86-64 family
21342of computers, depending on the command-line switches used.
21343
21344If you specify command-line switches such as @option{-msse},
21345the compiler could use the extended instruction sets even if the built-ins
21346are not used explicitly in the program.  For this reason, applications
21347that perform run-time CPU detection must compile separate files for each
21348supported architecture, using the appropriate flags.  In particular,
21349the file containing the CPU detection code should be compiled without
21350these options.
21351
21352The following machine modes are available for use with MMX built-in functions
21353(@pxref{Vector Extensions}): @code{V2SI} for a vector of two 32-bit integers,
21354@code{V4HI} for a vector of four 16-bit integers, and @code{V8QI} for a
21355vector of eight 8-bit integers.  Some of the built-in functions operate on
21356MMX registers as a whole 64-bit entity, these use @code{V1DI} as their mode.
21357
21358If 3DNow!@: extensions are enabled, @code{V2SF} is used as a mode for a vector
21359of two 32-bit floating-point values.
21360
21361If SSE extensions are enabled, @code{V4SF} is used for a vector of four 32-bit
21362floating-point values.  Some instructions use a vector of four 32-bit
21363integers, these use @code{V4SI}.  Finally, some instructions operate on an
21364entire vector register, interpreting it as a 128-bit integer, these use mode
21365@code{TI}.
21366
21367The x86-32 and x86-64 family of processors use additional built-in
21368functions for efficient use of @code{TF} (@code{__float128}) 128-bit
21369floating point and @code{TC} 128-bit complex floating-point values.
21370
21371The following floating-point built-in functions are always available.  All
21372of them implement the function that is part of the name.
21373
21374@smallexample
21375__float128 __builtin_fabsq (__float128)
21376__float128 __builtin_copysignq (__float128, __float128)
21377@end smallexample
21378
21379The following built-in functions are always available.
21380
21381@table @code
21382@item __float128 __builtin_infq (void)
21383Similar to @code{__builtin_inf}, except the return type is @code{__float128}.
21384@findex __builtin_infq
21385
21386@item __float128 __builtin_huge_valq (void)
21387Similar to @code{__builtin_huge_val}, except the return type is @code{__float128}.
21388@findex __builtin_huge_valq
21389
21390@item __float128 __builtin_nanq (void)
21391Similar to @code{__builtin_nan}, except the return type is @code{__float128}.
21392@findex __builtin_nanq
21393
21394@item __float128 __builtin_nansq (void)
21395Similar to @code{__builtin_nans}, except the return type is @code{__float128}.
21396@findex __builtin_nansq
21397@end table
21398
21399The following built-in function is always available.
21400
21401@table @code
21402@item void __builtin_ia32_pause (void)
21403Generates the @code{pause} machine instruction with a compiler memory
21404barrier.
21405@end table
21406
21407The following built-in functions are always available and can be used to
21408check the target platform type.
21409
21410@deftypefn {Built-in Function} void __builtin_cpu_init (void)
21411This function runs the CPU detection code to check the type of CPU and the
21412features supported.  This built-in function needs to be invoked along with the built-in functions
21413to check CPU type and features, @code{__builtin_cpu_is} and
21414@code{__builtin_cpu_supports}, only when used in a function that is
21415executed before any constructors are called.  The CPU detection code is
21416automatically executed in a very high priority constructor.
21417
21418For example, this function has to be used in @code{ifunc} resolvers that
21419check for CPU type using the built-in functions @code{__builtin_cpu_is}
21420and @code{__builtin_cpu_supports}, or in constructors on targets that
21421don't support constructor priority.
21422@smallexample
21423
21424static void (*resolve_memcpy (void)) (void)
21425@{
21426  // ifunc resolvers fire before constructors, explicitly call the init
21427  // function.
21428  __builtin_cpu_init ();
21429  if (__builtin_cpu_supports ("ssse3"))
21430    return ssse3_memcpy; // super fast memcpy with ssse3 instructions.
21431  else
21432    return default_memcpy;
21433@}
21434
21435void *memcpy (void *, const void *, size_t)
21436     __attribute__ ((ifunc ("resolve_memcpy")));
21437@end smallexample
21438
21439@end deftypefn
21440
21441@deftypefn {Built-in Function} int __builtin_cpu_is (const char *@var{cpuname})
21442This function returns a positive integer if the run-time CPU
21443is of type @var{cpuname}
21444and returns @code{0} otherwise. The following CPU names can be detected:
21445
21446@table @samp
21447@item amd
21448AMD CPU.
21449
21450@item intel
21451Intel CPU.
21452
21453@item atom
21454Intel Atom CPU.
21455
21456@item slm
21457Intel Silvermont CPU.
21458
21459@item core2
21460Intel Core 2 CPU.
21461
21462@item corei7
21463Intel Core i7 CPU.
21464
21465@item nehalem
21466Intel Core i7 Nehalem CPU.
21467
21468@item westmere
21469Intel Core i7 Westmere CPU.
21470
21471@item sandybridge
21472Intel Core i7 Sandy Bridge CPU.
21473
21474@item ivybridge
21475Intel Core i7 Ivy Bridge CPU.
21476
21477@item haswell
21478Intel Core i7 Haswell CPU.
21479
21480@item broadwell
21481Intel Core i7 Broadwell CPU.
21482
21483@item skylake
21484Intel Core i7 Skylake CPU.
21485
21486@item skylake-avx512
21487Intel Core i7 Skylake AVX512 CPU.
21488
21489@item cannonlake
21490Intel Core i7 Cannon Lake CPU.
21491
21492@item icelake-client
21493Intel Core i7 Ice Lake Client CPU.
21494
21495@item icelake-server
21496Intel Core i7 Ice Lake Server CPU.
21497
21498@item cascadelake
21499Intel Core i7 Cascadelake CPU.
21500
21501@item tigerlake
21502Intel Core i7 Tigerlake CPU.
21503
21504@item cooperlake
21505Intel Core i7 Cooperlake CPU.
21506
21507@item sapphirerapids
21508Intel Core i7 sapphirerapids CPU.
21509
21510@item alderlake
21511Intel Core i7 Alderlake CPU.
21512
21513@item rocketlake
21514Intel Core i7 Rocketlake CPU.
21515
21516@item bonnell
21517Intel Atom Bonnell CPU.
21518
21519@item silvermont
21520Intel Atom Silvermont CPU.
21521
21522@item goldmont
21523Intel Atom Goldmont CPU.
21524
21525@item goldmont-plus
21526Intel Atom Goldmont Plus CPU.
21527
21528@item tremont
21529Intel Atom Tremont CPU.
21530
21531@item knl
21532Intel Knights Landing CPU.
21533
21534@item knm
21535Intel Knights Mill CPU.
21536
21537@item amdfam10h
21538AMD Family 10h CPU.
21539
21540@item barcelona
21541AMD Family 10h Barcelona CPU.
21542
21543@item shanghai
21544AMD Family 10h Shanghai CPU.
21545
21546@item istanbul
21547AMD Family 10h Istanbul CPU.
21548
21549@item btver1
21550AMD Family 14h CPU.
21551
21552@item amdfam15h
21553AMD Family 15h CPU.
21554
21555@item bdver1
21556AMD Family 15h Bulldozer version 1.
21557
21558@item bdver2
21559AMD Family 15h Bulldozer version 2.
21560
21561@item bdver3
21562AMD Family 15h Bulldozer version 3.
21563
21564@item bdver4
21565AMD Family 15h Bulldozer version 4.
21566
21567@item btver2
21568AMD Family 16h CPU.
21569
21570@item amdfam17h
21571AMD Family 17h CPU.
21572
21573@item znver1
21574AMD Family 17h Zen version 1.
21575
21576@item znver2
21577AMD Family 17h Zen version 2.
21578
21579@item amdfam19h
21580AMD Family 19h CPU.
21581
21582@item znver3
21583AMD Family 19h Zen version 3.
21584@end table
21585
21586Here is an example:
21587@smallexample
21588if (__builtin_cpu_is ("corei7"))
21589  @{
21590     do_corei7 (); // Core i7 specific implementation.
21591  @}
21592else
21593  @{
21594     do_generic (); // Generic implementation.
21595  @}
21596@end smallexample
21597@end deftypefn
21598
21599@deftypefn {Built-in Function} int __builtin_cpu_supports (const char *@var{feature})
21600This function returns a positive integer if the run-time CPU
21601supports @var{feature}
21602and returns @code{0} otherwise. The following features can be detected:
21603
21604@table @samp
21605@item cmov
21606CMOV instruction.
21607@item mmx
21608MMX instructions.
21609@item popcnt
21610POPCNT instruction.
21611@item sse
21612SSE instructions.
21613@item sse2
21614SSE2 instructions.
21615@item sse3
21616SSE3 instructions.
21617@item ssse3
21618SSSE3 instructions.
21619@item sse4.1
21620SSE4.1 instructions.
21621@item sse4.2
21622SSE4.2 instructions.
21623@item avx
21624AVX instructions.
21625@item avx2
21626AVX2 instructions.
21627@item sse4a
21628SSE4A instructions.
21629@item fma4
21630FMA4 instructions.
21631@item xop
21632XOP instructions.
21633@item fma
21634FMA instructions.
21635@item avx512f
21636AVX512F instructions.
21637@item bmi
21638BMI instructions.
21639@item bmi2
21640BMI2 instructions.
21641@item aes
21642AES instructions.
21643@item pclmul
21644PCLMUL instructions.
21645@item avx512vl
21646AVX512VL instructions.
21647@item avx512bw
21648AVX512BW instructions.
21649@item avx512dq
21650AVX512DQ instructions.
21651@item avx512cd
21652AVX512CD instructions.
21653@item avx512er
21654AVX512ER instructions.
21655@item avx512pf
21656AVX512PF instructions.
21657@item avx512vbmi
21658AVX512VBMI instructions.
21659@item avx512ifma
21660AVX512IFMA instructions.
21661@item avx5124vnniw
21662AVX5124VNNIW instructions.
21663@item avx5124fmaps
21664AVX5124FMAPS instructions.
21665@item avx512vpopcntdq
21666AVX512VPOPCNTDQ instructions.
21667@item avx512vbmi2
21668AVX512VBMI2 instructions.
21669@item gfni
21670GFNI instructions.
21671@item vpclmulqdq
21672VPCLMULQDQ instructions.
21673@item avx512vnni
21674AVX512VNNI instructions.
21675@item avx512bitalg
21676AVX512BITALG instructions.
21677@end table
21678
21679Here is an example:
21680@smallexample
21681if (__builtin_cpu_supports ("popcnt"))
21682  @{
21683     asm("popcnt %1,%0" : "=r"(count) : "rm"(n) : "cc");
21684  @}
21685else
21686  @{
21687     count = generic_countbits (n); //generic implementation.
21688  @}
21689@end smallexample
21690@end deftypefn
21691
21692The following built-in functions are made available by @option{-mmmx}.
21693All of them generate the machine instruction that is part of the name.
21694
21695@smallexample
21696v8qi __builtin_ia32_paddb (v8qi, v8qi)
21697v4hi __builtin_ia32_paddw (v4hi, v4hi)
21698v2si __builtin_ia32_paddd (v2si, v2si)
21699v8qi __builtin_ia32_psubb (v8qi, v8qi)
21700v4hi __builtin_ia32_psubw (v4hi, v4hi)
21701v2si __builtin_ia32_psubd (v2si, v2si)
21702v8qi __builtin_ia32_paddsb (v8qi, v8qi)
21703v4hi __builtin_ia32_paddsw (v4hi, v4hi)
21704v8qi __builtin_ia32_psubsb (v8qi, v8qi)
21705v4hi __builtin_ia32_psubsw (v4hi, v4hi)
21706v8qi __builtin_ia32_paddusb (v8qi, v8qi)
21707v4hi __builtin_ia32_paddusw (v4hi, v4hi)
21708v8qi __builtin_ia32_psubusb (v8qi, v8qi)
21709v4hi __builtin_ia32_psubusw (v4hi, v4hi)
21710v4hi __builtin_ia32_pmullw (v4hi, v4hi)
21711v4hi __builtin_ia32_pmulhw (v4hi, v4hi)
21712di __builtin_ia32_pand (di, di)
21713di __builtin_ia32_pandn (di,di)
21714di __builtin_ia32_por (di, di)
21715di __builtin_ia32_pxor (di, di)
21716v8qi __builtin_ia32_pcmpeqb (v8qi, v8qi)
21717v4hi __builtin_ia32_pcmpeqw (v4hi, v4hi)
21718v2si __builtin_ia32_pcmpeqd (v2si, v2si)
21719v8qi __builtin_ia32_pcmpgtb (v8qi, v8qi)
21720v4hi __builtin_ia32_pcmpgtw (v4hi, v4hi)
21721v2si __builtin_ia32_pcmpgtd (v2si, v2si)
21722v8qi __builtin_ia32_punpckhbw (v8qi, v8qi)
21723v4hi __builtin_ia32_punpckhwd (v4hi, v4hi)
21724v2si __builtin_ia32_punpckhdq (v2si, v2si)
21725v8qi __builtin_ia32_punpcklbw (v8qi, v8qi)
21726v4hi __builtin_ia32_punpcklwd (v4hi, v4hi)
21727v2si __builtin_ia32_punpckldq (v2si, v2si)
21728v8qi __builtin_ia32_packsswb (v4hi, v4hi)
21729v4hi __builtin_ia32_packssdw (v2si, v2si)
21730v8qi __builtin_ia32_packuswb (v4hi, v4hi)
21731
21732v4hi __builtin_ia32_psllw (v4hi, v4hi)
21733v2si __builtin_ia32_pslld (v2si, v2si)
21734v1di __builtin_ia32_psllq (v1di, v1di)
21735v4hi __builtin_ia32_psrlw (v4hi, v4hi)
21736v2si __builtin_ia32_psrld (v2si, v2si)
21737v1di __builtin_ia32_psrlq (v1di, v1di)
21738v4hi __builtin_ia32_psraw (v4hi, v4hi)
21739v2si __builtin_ia32_psrad (v2si, v2si)
21740v4hi __builtin_ia32_psllwi (v4hi, int)
21741v2si __builtin_ia32_pslldi (v2si, int)
21742v1di __builtin_ia32_psllqi (v1di, int)
21743v4hi __builtin_ia32_psrlwi (v4hi, int)
21744v2si __builtin_ia32_psrldi (v2si, int)
21745v1di __builtin_ia32_psrlqi (v1di, int)
21746v4hi __builtin_ia32_psrawi (v4hi, int)
21747v2si __builtin_ia32_psradi (v2si, int)
21748
21749@end smallexample
21750
21751The following built-in functions are made available either with
21752@option{-msse}, or with @option{-m3dnowa}.  All of them generate
21753the machine instruction that is part of the name.
21754
21755@smallexample
21756v4hi __builtin_ia32_pmulhuw (v4hi, v4hi)
21757v8qi __builtin_ia32_pavgb (v8qi, v8qi)
21758v4hi __builtin_ia32_pavgw (v4hi, v4hi)
21759v1di __builtin_ia32_psadbw (v8qi, v8qi)
21760v8qi __builtin_ia32_pmaxub (v8qi, v8qi)
21761v4hi __builtin_ia32_pmaxsw (v4hi, v4hi)
21762v8qi __builtin_ia32_pminub (v8qi, v8qi)
21763v4hi __builtin_ia32_pminsw (v4hi, v4hi)
21764int __builtin_ia32_pmovmskb (v8qi)
21765void __builtin_ia32_maskmovq (v8qi, v8qi, char *)
21766void __builtin_ia32_movntq (di *, di)
21767void __builtin_ia32_sfence (void)
21768@end smallexample
21769
21770The following built-in functions are available when @option{-msse} is used.
21771All of them generate the machine instruction that is part of the name.
21772
21773@smallexample
21774int __builtin_ia32_comieq (v4sf, v4sf)
21775int __builtin_ia32_comineq (v4sf, v4sf)
21776int __builtin_ia32_comilt (v4sf, v4sf)
21777int __builtin_ia32_comile (v4sf, v4sf)
21778int __builtin_ia32_comigt (v4sf, v4sf)
21779int __builtin_ia32_comige (v4sf, v4sf)
21780int __builtin_ia32_ucomieq (v4sf, v4sf)
21781int __builtin_ia32_ucomineq (v4sf, v4sf)
21782int __builtin_ia32_ucomilt (v4sf, v4sf)
21783int __builtin_ia32_ucomile (v4sf, v4sf)
21784int __builtin_ia32_ucomigt (v4sf, v4sf)
21785int __builtin_ia32_ucomige (v4sf, v4sf)
21786v4sf __builtin_ia32_addps (v4sf, v4sf)
21787v4sf __builtin_ia32_subps (v4sf, v4sf)
21788v4sf __builtin_ia32_mulps (v4sf, v4sf)
21789v4sf __builtin_ia32_divps (v4sf, v4sf)
21790v4sf __builtin_ia32_addss (v4sf, v4sf)
21791v4sf __builtin_ia32_subss (v4sf, v4sf)
21792v4sf __builtin_ia32_mulss (v4sf, v4sf)
21793v4sf __builtin_ia32_divss (v4sf, v4sf)
21794v4sf __builtin_ia32_cmpeqps (v4sf, v4sf)
21795v4sf __builtin_ia32_cmpltps (v4sf, v4sf)
21796v4sf __builtin_ia32_cmpleps (v4sf, v4sf)
21797v4sf __builtin_ia32_cmpgtps (v4sf, v4sf)
21798v4sf __builtin_ia32_cmpgeps (v4sf, v4sf)
21799v4sf __builtin_ia32_cmpunordps (v4sf, v4sf)
21800v4sf __builtin_ia32_cmpneqps (v4sf, v4sf)
21801v4sf __builtin_ia32_cmpnltps (v4sf, v4sf)
21802v4sf __builtin_ia32_cmpnleps (v4sf, v4sf)
21803v4sf __builtin_ia32_cmpngtps (v4sf, v4sf)
21804v4sf __builtin_ia32_cmpngeps (v4sf, v4sf)
21805v4sf __builtin_ia32_cmpordps (v4sf, v4sf)
21806v4sf __builtin_ia32_cmpeqss (v4sf, v4sf)
21807v4sf __builtin_ia32_cmpltss (v4sf, v4sf)
21808v4sf __builtin_ia32_cmpless (v4sf, v4sf)
21809v4sf __builtin_ia32_cmpunordss (v4sf, v4sf)
21810v4sf __builtin_ia32_cmpneqss (v4sf, v4sf)
21811v4sf __builtin_ia32_cmpnltss (v4sf, v4sf)
21812v4sf __builtin_ia32_cmpnless (v4sf, v4sf)
21813v4sf __builtin_ia32_cmpordss (v4sf, v4sf)
21814v4sf __builtin_ia32_maxps (v4sf, v4sf)
21815v4sf __builtin_ia32_maxss (v4sf, v4sf)
21816v4sf __builtin_ia32_minps (v4sf, v4sf)
21817v4sf __builtin_ia32_minss (v4sf, v4sf)
21818v4sf __builtin_ia32_andps (v4sf, v4sf)
21819v4sf __builtin_ia32_andnps (v4sf, v4sf)
21820v4sf __builtin_ia32_orps (v4sf, v4sf)
21821v4sf __builtin_ia32_xorps (v4sf, v4sf)
21822v4sf __builtin_ia32_movss (v4sf, v4sf)
21823v4sf __builtin_ia32_movhlps (v4sf, v4sf)
21824v4sf __builtin_ia32_movlhps (v4sf, v4sf)
21825v4sf __builtin_ia32_unpckhps (v4sf, v4sf)
21826v4sf __builtin_ia32_unpcklps (v4sf, v4sf)
21827v4sf __builtin_ia32_cvtpi2ps (v4sf, v2si)
21828v4sf __builtin_ia32_cvtsi2ss (v4sf, int)
21829v2si __builtin_ia32_cvtps2pi (v4sf)
21830int __builtin_ia32_cvtss2si (v4sf)
21831v2si __builtin_ia32_cvttps2pi (v4sf)
21832int __builtin_ia32_cvttss2si (v4sf)
21833v4sf __builtin_ia32_rcpps (v4sf)
21834v4sf __builtin_ia32_rsqrtps (v4sf)
21835v4sf __builtin_ia32_sqrtps (v4sf)
21836v4sf __builtin_ia32_rcpss (v4sf)
21837v4sf __builtin_ia32_rsqrtss (v4sf)
21838v4sf __builtin_ia32_sqrtss (v4sf)
21839v4sf __builtin_ia32_shufps (v4sf, v4sf, int)
21840void __builtin_ia32_movntps (float *, v4sf)
21841int __builtin_ia32_movmskps (v4sf)
21842@end smallexample
21843
21844The following built-in functions are available when @option{-msse} is used.
21845
21846@table @code
21847@item v4sf __builtin_ia32_loadups (float *)
21848Generates the @code{movups} machine instruction as a load from memory.
21849@item void __builtin_ia32_storeups (float *, v4sf)
21850Generates the @code{movups} machine instruction as a store to memory.
21851@item v4sf __builtin_ia32_loadss (float *)
21852Generates the @code{movss} machine instruction as a load from memory.
21853@item v4sf __builtin_ia32_loadhps (v4sf, const v2sf *)
21854Generates the @code{movhps} machine instruction as a load from memory.
21855@item v4sf __builtin_ia32_loadlps (v4sf, const v2sf *)
21856Generates the @code{movlps} machine instruction as a load from memory
21857@item void __builtin_ia32_storehps (v2sf *, v4sf)
21858Generates the @code{movhps} machine instruction as a store to memory.
21859@item void __builtin_ia32_storelps (v2sf *, v4sf)
21860Generates the @code{movlps} machine instruction as a store to memory.
21861@end table
21862
21863The following built-in functions are available when @option{-msse2} is used.
21864All of them generate the machine instruction that is part of the name.
21865
21866@smallexample
21867int __builtin_ia32_comisdeq (v2df, v2df)
21868int __builtin_ia32_comisdlt (v2df, v2df)
21869int __builtin_ia32_comisdle (v2df, v2df)
21870int __builtin_ia32_comisdgt (v2df, v2df)
21871int __builtin_ia32_comisdge (v2df, v2df)
21872int __builtin_ia32_comisdneq (v2df, v2df)
21873int __builtin_ia32_ucomisdeq (v2df, v2df)
21874int __builtin_ia32_ucomisdlt (v2df, v2df)
21875int __builtin_ia32_ucomisdle (v2df, v2df)
21876int __builtin_ia32_ucomisdgt (v2df, v2df)
21877int __builtin_ia32_ucomisdge (v2df, v2df)
21878int __builtin_ia32_ucomisdneq (v2df, v2df)
21879v2df __builtin_ia32_cmpeqpd (v2df, v2df)
21880v2df __builtin_ia32_cmpltpd (v2df, v2df)
21881v2df __builtin_ia32_cmplepd (v2df, v2df)
21882v2df __builtin_ia32_cmpgtpd (v2df, v2df)
21883v2df __builtin_ia32_cmpgepd (v2df, v2df)
21884v2df __builtin_ia32_cmpunordpd (v2df, v2df)
21885v2df __builtin_ia32_cmpneqpd (v2df, v2df)
21886v2df __builtin_ia32_cmpnltpd (v2df, v2df)
21887v2df __builtin_ia32_cmpnlepd (v2df, v2df)
21888v2df __builtin_ia32_cmpngtpd (v2df, v2df)
21889v2df __builtin_ia32_cmpngepd (v2df, v2df)
21890v2df __builtin_ia32_cmpordpd (v2df, v2df)
21891v2df __builtin_ia32_cmpeqsd (v2df, v2df)
21892v2df __builtin_ia32_cmpltsd (v2df, v2df)
21893v2df __builtin_ia32_cmplesd (v2df, v2df)
21894v2df __builtin_ia32_cmpunordsd (v2df, v2df)
21895v2df __builtin_ia32_cmpneqsd (v2df, v2df)
21896v2df __builtin_ia32_cmpnltsd (v2df, v2df)
21897v2df __builtin_ia32_cmpnlesd (v2df, v2df)
21898v2df __builtin_ia32_cmpordsd (v2df, v2df)
21899v2di __builtin_ia32_paddq (v2di, v2di)
21900v2di __builtin_ia32_psubq (v2di, v2di)
21901v2df __builtin_ia32_addpd (v2df, v2df)
21902v2df __builtin_ia32_subpd (v2df, v2df)
21903v2df __builtin_ia32_mulpd (v2df, v2df)
21904v2df __builtin_ia32_divpd (v2df, v2df)
21905v2df __builtin_ia32_addsd (v2df, v2df)
21906v2df __builtin_ia32_subsd (v2df, v2df)
21907v2df __builtin_ia32_mulsd (v2df, v2df)
21908v2df __builtin_ia32_divsd (v2df, v2df)
21909v2df __builtin_ia32_minpd (v2df, v2df)
21910v2df __builtin_ia32_maxpd (v2df, v2df)
21911v2df __builtin_ia32_minsd (v2df, v2df)
21912v2df __builtin_ia32_maxsd (v2df, v2df)
21913v2df __builtin_ia32_andpd (v2df, v2df)
21914v2df __builtin_ia32_andnpd (v2df, v2df)
21915v2df __builtin_ia32_orpd (v2df, v2df)
21916v2df __builtin_ia32_xorpd (v2df, v2df)
21917v2df __builtin_ia32_movsd (v2df, v2df)
21918v2df __builtin_ia32_unpckhpd (v2df, v2df)
21919v2df __builtin_ia32_unpcklpd (v2df, v2df)
21920v16qi __builtin_ia32_paddb128 (v16qi, v16qi)
21921v8hi __builtin_ia32_paddw128 (v8hi, v8hi)
21922v4si __builtin_ia32_paddd128 (v4si, v4si)
21923v2di __builtin_ia32_paddq128 (v2di, v2di)
21924v16qi __builtin_ia32_psubb128 (v16qi, v16qi)
21925v8hi __builtin_ia32_psubw128 (v8hi, v8hi)
21926v4si __builtin_ia32_psubd128 (v4si, v4si)
21927v2di __builtin_ia32_psubq128 (v2di, v2di)
21928v8hi __builtin_ia32_pmullw128 (v8hi, v8hi)
21929v8hi __builtin_ia32_pmulhw128 (v8hi, v8hi)
21930v2di __builtin_ia32_pand128 (v2di, v2di)
21931v2di __builtin_ia32_pandn128 (v2di, v2di)
21932v2di __builtin_ia32_por128 (v2di, v2di)
21933v2di __builtin_ia32_pxor128 (v2di, v2di)
21934v16qi __builtin_ia32_pavgb128 (v16qi, v16qi)
21935v8hi __builtin_ia32_pavgw128 (v8hi, v8hi)
21936v16qi __builtin_ia32_pcmpeqb128 (v16qi, v16qi)
21937v8hi __builtin_ia32_pcmpeqw128 (v8hi, v8hi)
21938v4si __builtin_ia32_pcmpeqd128 (v4si, v4si)
21939v16qi __builtin_ia32_pcmpgtb128 (v16qi, v16qi)
21940v8hi __builtin_ia32_pcmpgtw128 (v8hi, v8hi)
21941v4si __builtin_ia32_pcmpgtd128 (v4si, v4si)
21942v16qi __builtin_ia32_pmaxub128 (v16qi, v16qi)
21943v8hi __builtin_ia32_pmaxsw128 (v8hi, v8hi)
21944v16qi __builtin_ia32_pminub128 (v16qi, v16qi)
21945v8hi __builtin_ia32_pminsw128 (v8hi, v8hi)
21946v16qi __builtin_ia32_punpckhbw128 (v16qi, v16qi)
21947v8hi __builtin_ia32_punpckhwd128 (v8hi, v8hi)
21948v4si __builtin_ia32_punpckhdq128 (v4si, v4si)
21949v2di __builtin_ia32_punpckhqdq128 (v2di, v2di)
21950v16qi __builtin_ia32_punpcklbw128 (v16qi, v16qi)
21951v8hi __builtin_ia32_punpcklwd128 (v8hi, v8hi)
21952v4si __builtin_ia32_punpckldq128 (v4si, v4si)
21953v2di __builtin_ia32_punpcklqdq128 (v2di, v2di)
21954v16qi __builtin_ia32_packsswb128 (v8hi, v8hi)
21955v8hi __builtin_ia32_packssdw128 (v4si, v4si)
21956v16qi __builtin_ia32_packuswb128 (v8hi, v8hi)
21957v8hi __builtin_ia32_pmulhuw128 (v8hi, v8hi)
21958void __builtin_ia32_maskmovdqu (v16qi, v16qi)
21959v2df __builtin_ia32_loadupd (double *)
21960void __builtin_ia32_storeupd (double *, v2df)
21961v2df __builtin_ia32_loadhpd (v2df, double const *)
21962v2df __builtin_ia32_loadlpd (v2df, double const *)
21963int __builtin_ia32_movmskpd (v2df)
21964int __builtin_ia32_pmovmskb128 (v16qi)
21965void __builtin_ia32_movnti (int *, int)
21966void __builtin_ia32_movnti64 (long long int *, long long int)
21967void __builtin_ia32_movntpd (double *, v2df)
21968void __builtin_ia32_movntdq (v2df *, v2df)
21969v4si __builtin_ia32_pshufd (v4si, int)
21970v8hi __builtin_ia32_pshuflw (v8hi, int)
21971v8hi __builtin_ia32_pshufhw (v8hi, int)
21972v2di __builtin_ia32_psadbw128 (v16qi, v16qi)
21973v2df __builtin_ia32_sqrtpd (v2df)
21974v2df __builtin_ia32_sqrtsd (v2df)
21975v2df __builtin_ia32_shufpd (v2df, v2df, int)
21976v2df __builtin_ia32_cvtdq2pd (v4si)
21977v4sf __builtin_ia32_cvtdq2ps (v4si)
21978v4si __builtin_ia32_cvtpd2dq (v2df)
21979v2si __builtin_ia32_cvtpd2pi (v2df)
21980v4sf __builtin_ia32_cvtpd2ps (v2df)
21981v4si __builtin_ia32_cvttpd2dq (v2df)
21982v2si __builtin_ia32_cvttpd2pi (v2df)
21983v2df __builtin_ia32_cvtpi2pd (v2si)
21984int __builtin_ia32_cvtsd2si (v2df)
21985int __builtin_ia32_cvttsd2si (v2df)
21986long long __builtin_ia32_cvtsd2si64 (v2df)
21987long long __builtin_ia32_cvttsd2si64 (v2df)
21988v4si __builtin_ia32_cvtps2dq (v4sf)
21989v2df __builtin_ia32_cvtps2pd (v4sf)
21990v4si __builtin_ia32_cvttps2dq (v4sf)
21991v2df __builtin_ia32_cvtsi2sd (v2df, int)
21992v2df __builtin_ia32_cvtsi642sd (v2df, long long)
21993v4sf __builtin_ia32_cvtsd2ss (v4sf, v2df)
21994v2df __builtin_ia32_cvtss2sd (v2df, v4sf)
21995void __builtin_ia32_clflush (const void *)
21996void __builtin_ia32_lfence (void)
21997void __builtin_ia32_mfence (void)
21998v16qi __builtin_ia32_loaddqu (const char *)
21999void __builtin_ia32_storedqu (char *, v16qi)
22000v1di __builtin_ia32_pmuludq (v2si, v2si)
22001v2di __builtin_ia32_pmuludq128 (v4si, v4si)
22002v8hi __builtin_ia32_psllw128 (v8hi, v8hi)
22003v4si __builtin_ia32_pslld128 (v4si, v4si)
22004v2di __builtin_ia32_psllq128 (v2di, v2di)
22005v8hi __builtin_ia32_psrlw128 (v8hi, v8hi)
22006v4si __builtin_ia32_psrld128 (v4si, v4si)
22007v2di __builtin_ia32_psrlq128 (v2di, v2di)
22008v8hi __builtin_ia32_psraw128 (v8hi, v8hi)
22009v4si __builtin_ia32_psrad128 (v4si, v4si)
22010v2di __builtin_ia32_pslldqi128 (v2di, int)
22011v8hi __builtin_ia32_psllwi128 (v8hi, int)
22012v4si __builtin_ia32_pslldi128 (v4si, int)
22013v2di __builtin_ia32_psllqi128 (v2di, int)
22014v2di __builtin_ia32_psrldqi128 (v2di, int)
22015v8hi __builtin_ia32_psrlwi128 (v8hi, int)
22016v4si __builtin_ia32_psrldi128 (v4si, int)
22017v2di __builtin_ia32_psrlqi128 (v2di, int)
22018v8hi __builtin_ia32_psrawi128 (v8hi, int)
22019v4si __builtin_ia32_psradi128 (v4si, int)
22020v4si __builtin_ia32_pmaddwd128 (v8hi, v8hi)
22021v2di __builtin_ia32_movq128 (v2di)
22022@end smallexample
22023
22024The following built-in functions are available when @option{-msse3} is used.
22025All of them generate the machine instruction that is part of the name.
22026
22027@smallexample
22028v2df __builtin_ia32_addsubpd (v2df, v2df)
22029v4sf __builtin_ia32_addsubps (v4sf, v4sf)
22030v2df __builtin_ia32_haddpd (v2df, v2df)
22031v4sf __builtin_ia32_haddps (v4sf, v4sf)
22032v2df __builtin_ia32_hsubpd (v2df, v2df)
22033v4sf __builtin_ia32_hsubps (v4sf, v4sf)
22034v16qi __builtin_ia32_lddqu (char const *)
22035void __builtin_ia32_monitor (void *, unsigned int, unsigned int)
22036v4sf __builtin_ia32_movshdup (v4sf)
22037v4sf __builtin_ia32_movsldup (v4sf)
22038void __builtin_ia32_mwait (unsigned int, unsigned int)
22039@end smallexample
22040
22041The following built-in functions are available when @option{-mssse3} is used.
22042All of them generate the machine instruction that is part of the name.
22043
22044@smallexample
22045v2si __builtin_ia32_phaddd (v2si, v2si)
22046v4hi __builtin_ia32_phaddw (v4hi, v4hi)
22047v4hi __builtin_ia32_phaddsw (v4hi, v4hi)
22048v2si __builtin_ia32_phsubd (v2si, v2si)
22049v4hi __builtin_ia32_phsubw (v4hi, v4hi)
22050v4hi __builtin_ia32_phsubsw (v4hi, v4hi)
22051v4hi __builtin_ia32_pmaddubsw (v8qi, v8qi)
22052v4hi __builtin_ia32_pmulhrsw (v4hi, v4hi)
22053v8qi __builtin_ia32_pshufb (v8qi, v8qi)
22054v8qi __builtin_ia32_psignb (v8qi, v8qi)
22055v2si __builtin_ia32_psignd (v2si, v2si)
22056v4hi __builtin_ia32_psignw (v4hi, v4hi)
22057v1di __builtin_ia32_palignr (v1di, v1di, int)
22058v8qi __builtin_ia32_pabsb (v8qi)
22059v2si __builtin_ia32_pabsd (v2si)
22060v4hi __builtin_ia32_pabsw (v4hi)
22061@end smallexample
22062
22063The following built-in functions are available when @option{-mssse3} is used.
22064All of them generate the machine instruction that is part of the name.
22065
22066@smallexample
22067v4si __builtin_ia32_phaddd128 (v4si, v4si)
22068v8hi __builtin_ia32_phaddw128 (v8hi, v8hi)
22069v8hi __builtin_ia32_phaddsw128 (v8hi, v8hi)
22070v4si __builtin_ia32_phsubd128 (v4si, v4si)
22071v8hi __builtin_ia32_phsubw128 (v8hi, v8hi)
22072v8hi __builtin_ia32_phsubsw128 (v8hi, v8hi)
22073v8hi __builtin_ia32_pmaddubsw128 (v16qi, v16qi)
22074v8hi __builtin_ia32_pmulhrsw128 (v8hi, v8hi)
22075v16qi __builtin_ia32_pshufb128 (v16qi, v16qi)
22076v16qi __builtin_ia32_psignb128 (v16qi, v16qi)
22077v4si __builtin_ia32_psignd128 (v4si, v4si)
22078v8hi __builtin_ia32_psignw128 (v8hi, v8hi)
22079v2di __builtin_ia32_palignr128 (v2di, v2di, int)
22080v16qi __builtin_ia32_pabsb128 (v16qi)
22081v4si __builtin_ia32_pabsd128 (v4si)
22082v8hi __builtin_ia32_pabsw128 (v8hi)
22083@end smallexample
22084
22085The following built-in functions are available when @option{-msse4.1} is
22086used.  All of them generate the machine instruction that is part of the
22087name.
22088
22089@smallexample
22090v2df __builtin_ia32_blendpd (v2df, v2df, const int)
22091v4sf __builtin_ia32_blendps (v4sf, v4sf, const int)
22092v2df __builtin_ia32_blendvpd (v2df, v2df, v2df)
22093v4sf __builtin_ia32_blendvps (v4sf, v4sf, v4sf)
22094v2df __builtin_ia32_dppd (v2df, v2df, const int)
22095v4sf __builtin_ia32_dpps (v4sf, v4sf, const int)
22096v4sf __builtin_ia32_insertps128 (v4sf, v4sf, const int)
22097v2di __builtin_ia32_movntdqa (v2di *);
22098v16qi __builtin_ia32_mpsadbw128 (v16qi, v16qi, const int)
22099v8hi __builtin_ia32_packusdw128 (v4si, v4si)
22100v16qi __builtin_ia32_pblendvb128 (v16qi, v16qi, v16qi)
22101v8hi __builtin_ia32_pblendw128 (v8hi, v8hi, const int)
22102v2di __builtin_ia32_pcmpeqq (v2di, v2di)
22103v8hi __builtin_ia32_phminposuw128 (v8hi)
22104v16qi __builtin_ia32_pmaxsb128 (v16qi, v16qi)
22105v4si __builtin_ia32_pmaxsd128 (v4si, v4si)
22106v4si __builtin_ia32_pmaxud128 (v4si, v4si)
22107v8hi __builtin_ia32_pmaxuw128 (v8hi, v8hi)
22108v16qi __builtin_ia32_pminsb128 (v16qi, v16qi)
22109v4si __builtin_ia32_pminsd128 (v4si, v4si)
22110v4si __builtin_ia32_pminud128 (v4si, v4si)
22111v8hi __builtin_ia32_pminuw128 (v8hi, v8hi)
22112v4si __builtin_ia32_pmovsxbd128 (v16qi)
22113v2di __builtin_ia32_pmovsxbq128 (v16qi)
22114v8hi __builtin_ia32_pmovsxbw128 (v16qi)
22115v2di __builtin_ia32_pmovsxdq128 (v4si)
22116v4si __builtin_ia32_pmovsxwd128 (v8hi)
22117v2di __builtin_ia32_pmovsxwq128 (v8hi)
22118v4si __builtin_ia32_pmovzxbd128 (v16qi)
22119v2di __builtin_ia32_pmovzxbq128 (v16qi)
22120v8hi __builtin_ia32_pmovzxbw128 (v16qi)
22121v2di __builtin_ia32_pmovzxdq128 (v4si)
22122v4si __builtin_ia32_pmovzxwd128 (v8hi)
22123v2di __builtin_ia32_pmovzxwq128 (v8hi)
22124v2di __builtin_ia32_pmuldq128 (v4si, v4si)
22125v4si __builtin_ia32_pmulld128 (v4si, v4si)
22126int __builtin_ia32_ptestc128 (v2di, v2di)
22127int __builtin_ia32_ptestnzc128 (v2di, v2di)
22128int __builtin_ia32_ptestz128 (v2di, v2di)
22129v2df __builtin_ia32_roundpd (v2df, const int)
22130v4sf __builtin_ia32_roundps (v4sf, const int)
22131v2df __builtin_ia32_roundsd (v2df, v2df, const int)
22132v4sf __builtin_ia32_roundss (v4sf, v4sf, const int)
22133@end smallexample
22134
22135The following built-in functions are available when @option{-msse4.1} is
22136used.
22137
22138@table @code
22139@item v4sf __builtin_ia32_vec_set_v4sf (v4sf, float, const int)
22140Generates the @code{insertps} machine instruction.
22141@item int __builtin_ia32_vec_ext_v16qi (v16qi, const int)
22142Generates the @code{pextrb} machine instruction.
22143@item v16qi __builtin_ia32_vec_set_v16qi (v16qi, int, const int)
22144Generates the @code{pinsrb} machine instruction.
22145@item v4si __builtin_ia32_vec_set_v4si (v4si, int, const int)
22146Generates the @code{pinsrd} machine instruction.
22147@item v2di __builtin_ia32_vec_set_v2di (v2di, long long, const int)
22148Generates the @code{pinsrq} machine instruction in 64bit mode.
22149@end table
22150
22151The following built-in functions are changed to generate new SSE4.1
22152instructions when @option{-msse4.1} is used.
22153
22154@table @code
22155@item float __builtin_ia32_vec_ext_v4sf (v4sf, const int)
22156Generates the @code{extractps} machine instruction.
22157@item int __builtin_ia32_vec_ext_v4si (v4si, const int)
22158Generates the @code{pextrd} machine instruction.
22159@item long long __builtin_ia32_vec_ext_v2di (v2di, const int)
22160Generates the @code{pextrq} machine instruction in 64bit mode.
22161@end table
22162
22163The following built-in functions are available when @option{-msse4.2} is
22164used.  All of them generate the machine instruction that is part of the
22165name.
22166
22167@smallexample
22168v16qi __builtin_ia32_pcmpestrm128 (v16qi, int, v16qi, int, const int)
22169int __builtin_ia32_pcmpestri128 (v16qi, int, v16qi, int, const int)
22170int __builtin_ia32_pcmpestria128 (v16qi, int, v16qi, int, const int)
22171int __builtin_ia32_pcmpestric128 (v16qi, int, v16qi, int, const int)
22172int __builtin_ia32_pcmpestrio128 (v16qi, int, v16qi, int, const int)
22173int __builtin_ia32_pcmpestris128 (v16qi, int, v16qi, int, const int)
22174int __builtin_ia32_pcmpestriz128 (v16qi, int, v16qi, int, const int)
22175v16qi __builtin_ia32_pcmpistrm128 (v16qi, v16qi, const int)
22176int __builtin_ia32_pcmpistri128 (v16qi, v16qi, const int)
22177int __builtin_ia32_pcmpistria128 (v16qi, v16qi, const int)
22178int __builtin_ia32_pcmpistric128 (v16qi, v16qi, const int)
22179int __builtin_ia32_pcmpistrio128 (v16qi, v16qi, const int)
22180int __builtin_ia32_pcmpistris128 (v16qi, v16qi, const int)
22181int __builtin_ia32_pcmpistriz128 (v16qi, v16qi, const int)
22182v2di __builtin_ia32_pcmpgtq (v2di, v2di)
22183@end smallexample
22184
22185The following built-in functions are available when @option{-msse4.2} is
22186used.
22187
22188@table @code
22189@item unsigned int __builtin_ia32_crc32qi (unsigned int, unsigned char)
22190Generates the @code{crc32b} machine instruction.
22191@item unsigned int __builtin_ia32_crc32hi (unsigned int, unsigned short)
22192Generates the @code{crc32w} machine instruction.
22193@item unsigned int __builtin_ia32_crc32si (unsigned int, unsigned int)
22194Generates the @code{crc32l} machine instruction.
22195@item unsigned long long __builtin_ia32_crc32di (unsigned long long, unsigned long long)
22196Generates the @code{crc32q} machine instruction.
22197@end table
22198
22199The following built-in functions are changed to generate new SSE4.2
22200instructions when @option{-msse4.2} is used.
22201
22202@table @code
22203@item int __builtin_popcount (unsigned int)
22204Generates the @code{popcntl} machine instruction.
22205@item int __builtin_popcountl (unsigned long)
22206Generates the @code{popcntl} or @code{popcntq} machine instruction,
22207depending on the size of @code{unsigned long}.
22208@item int __builtin_popcountll (unsigned long long)
22209Generates the @code{popcntq} machine instruction.
22210@end table
22211
22212The following built-in functions are available when @option{-mavx} is
22213used. All of them generate the machine instruction that is part of the
22214name.
22215
22216@smallexample
22217v4df __builtin_ia32_addpd256 (v4df,v4df)
22218v8sf __builtin_ia32_addps256 (v8sf,v8sf)
22219v4df __builtin_ia32_addsubpd256 (v4df,v4df)
22220v8sf __builtin_ia32_addsubps256 (v8sf,v8sf)
22221v4df __builtin_ia32_andnpd256 (v4df,v4df)
22222v8sf __builtin_ia32_andnps256 (v8sf,v8sf)
22223v4df __builtin_ia32_andpd256 (v4df,v4df)
22224v8sf __builtin_ia32_andps256 (v8sf,v8sf)
22225v4df __builtin_ia32_blendpd256 (v4df,v4df,int)
22226v8sf __builtin_ia32_blendps256 (v8sf,v8sf,int)
22227v4df __builtin_ia32_blendvpd256 (v4df,v4df,v4df)
22228v8sf __builtin_ia32_blendvps256 (v8sf,v8sf,v8sf)
22229v2df __builtin_ia32_cmppd (v2df,v2df,int)
22230v4df __builtin_ia32_cmppd256 (v4df,v4df,int)
22231v4sf __builtin_ia32_cmpps (v4sf,v4sf,int)
22232v8sf __builtin_ia32_cmpps256 (v8sf,v8sf,int)
22233v2df __builtin_ia32_cmpsd (v2df,v2df,int)
22234v4sf __builtin_ia32_cmpss (v4sf,v4sf,int)
22235v4df __builtin_ia32_cvtdq2pd256 (v4si)
22236v8sf __builtin_ia32_cvtdq2ps256 (v8si)
22237v4si __builtin_ia32_cvtpd2dq256 (v4df)
22238v4sf __builtin_ia32_cvtpd2ps256 (v4df)
22239v8si __builtin_ia32_cvtps2dq256 (v8sf)
22240v4df __builtin_ia32_cvtps2pd256 (v4sf)
22241v4si __builtin_ia32_cvttpd2dq256 (v4df)
22242v8si __builtin_ia32_cvttps2dq256 (v8sf)
22243v4df __builtin_ia32_divpd256 (v4df,v4df)
22244v8sf __builtin_ia32_divps256 (v8sf,v8sf)
22245v8sf __builtin_ia32_dpps256 (v8sf,v8sf,int)
22246v4df __builtin_ia32_haddpd256 (v4df,v4df)
22247v8sf __builtin_ia32_haddps256 (v8sf,v8sf)
22248v4df __builtin_ia32_hsubpd256 (v4df,v4df)
22249v8sf __builtin_ia32_hsubps256 (v8sf,v8sf)
22250v32qi __builtin_ia32_lddqu256 (pcchar)
22251v32qi __builtin_ia32_loaddqu256 (pcchar)
22252v4df __builtin_ia32_loadupd256 (pcdouble)
22253v8sf __builtin_ia32_loadups256 (pcfloat)
22254v2df __builtin_ia32_maskloadpd (pcv2df,v2df)
22255v4df __builtin_ia32_maskloadpd256 (pcv4df,v4df)
22256v4sf __builtin_ia32_maskloadps (pcv4sf,v4sf)
22257v8sf __builtin_ia32_maskloadps256 (pcv8sf,v8sf)
22258void __builtin_ia32_maskstorepd (pv2df,v2df,v2df)
22259void __builtin_ia32_maskstorepd256 (pv4df,v4df,v4df)
22260void __builtin_ia32_maskstoreps (pv4sf,v4sf,v4sf)
22261void __builtin_ia32_maskstoreps256 (pv8sf,v8sf,v8sf)
22262v4df __builtin_ia32_maxpd256 (v4df,v4df)
22263v8sf __builtin_ia32_maxps256 (v8sf,v8sf)
22264v4df __builtin_ia32_minpd256 (v4df,v4df)
22265v8sf __builtin_ia32_minps256 (v8sf,v8sf)
22266v4df __builtin_ia32_movddup256 (v4df)
22267int __builtin_ia32_movmskpd256 (v4df)
22268int __builtin_ia32_movmskps256 (v8sf)
22269v8sf __builtin_ia32_movshdup256 (v8sf)
22270v8sf __builtin_ia32_movsldup256 (v8sf)
22271v4df __builtin_ia32_mulpd256 (v4df,v4df)
22272v8sf __builtin_ia32_mulps256 (v8sf,v8sf)
22273v4df __builtin_ia32_orpd256 (v4df,v4df)
22274v8sf __builtin_ia32_orps256 (v8sf,v8sf)
22275v2df __builtin_ia32_pd_pd256 (v4df)
22276v4df __builtin_ia32_pd256_pd (v2df)
22277v4sf __builtin_ia32_ps_ps256 (v8sf)
22278v8sf __builtin_ia32_ps256_ps (v4sf)
22279int __builtin_ia32_ptestc256 (v4di,v4di,ptest)
22280int __builtin_ia32_ptestnzc256 (v4di,v4di,ptest)
22281int __builtin_ia32_ptestz256 (v4di,v4di,ptest)
22282v8sf __builtin_ia32_rcpps256 (v8sf)
22283v4df __builtin_ia32_roundpd256 (v4df,int)
22284v8sf __builtin_ia32_roundps256 (v8sf,int)
22285v8sf __builtin_ia32_rsqrtps_nr256 (v8sf)
22286v8sf __builtin_ia32_rsqrtps256 (v8sf)
22287v4df __builtin_ia32_shufpd256 (v4df,v4df,int)
22288v8sf __builtin_ia32_shufps256 (v8sf,v8sf,int)
22289v4si __builtin_ia32_si_si256 (v8si)
22290v8si __builtin_ia32_si256_si (v4si)
22291v4df __builtin_ia32_sqrtpd256 (v4df)
22292v8sf __builtin_ia32_sqrtps_nr256 (v8sf)
22293v8sf __builtin_ia32_sqrtps256 (v8sf)
22294void __builtin_ia32_storedqu256 (pchar,v32qi)
22295void __builtin_ia32_storeupd256 (pdouble,v4df)
22296void __builtin_ia32_storeups256 (pfloat,v8sf)
22297v4df __builtin_ia32_subpd256 (v4df,v4df)
22298v8sf __builtin_ia32_subps256 (v8sf,v8sf)
22299v4df __builtin_ia32_unpckhpd256 (v4df,v4df)
22300v8sf __builtin_ia32_unpckhps256 (v8sf,v8sf)
22301v4df __builtin_ia32_unpcklpd256 (v4df,v4df)
22302v8sf __builtin_ia32_unpcklps256 (v8sf,v8sf)
22303v4df __builtin_ia32_vbroadcastf128_pd256 (pcv2df)
22304v8sf __builtin_ia32_vbroadcastf128_ps256 (pcv4sf)
22305v4df __builtin_ia32_vbroadcastsd256 (pcdouble)
22306v4sf __builtin_ia32_vbroadcastss (pcfloat)
22307v8sf __builtin_ia32_vbroadcastss256 (pcfloat)
22308v2df __builtin_ia32_vextractf128_pd256 (v4df,int)
22309v4sf __builtin_ia32_vextractf128_ps256 (v8sf,int)
22310v4si __builtin_ia32_vextractf128_si256 (v8si,int)
22311v4df __builtin_ia32_vinsertf128_pd256 (v4df,v2df,int)
22312v8sf __builtin_ia32_vinsertf128_ps256 (v8sf,v4sf,int)
22313v8si __builtin_ia32_vinsertf128_si256 (v8si,v4si,int)
22314v4df __builtin_ia32_vperm2f128_pd256 (v4df,v4df,int)
22315v8sf __builtin_ia32_vperm2f128_ps256 (v8sf,v8sf,int)
22316v8si __builtin_ia32_vperm2f128_si256 (v8si,v8si,int)
22317v2df __builtin_ia32_vpermil2pd (v2df,v2df,v2di,int)
22318v4df __builtin_ia32_vpermil2pd256 (v4df,v4df,v4di,int)
22319v4sf __builtin_ia32_vpermil2ps (v4sf,v4sf,v4si,int)
22320v8sf __builtin_ia32_vpermil2ps256 (v8sf,v8sf,v8si,int)
22321v2df __builtin_ia32_vpermilpd (v2df,int)
22322v4df __builtin_ia32_vpermilpd256 (v4df,int)
22323v4sf __builtin_ia32_vpermilps (v4sf,int)
22324v8sf __builtin_ia32_vpermilps256 (v8sf,int)
22325v2df __builtin_ia32_vpermilvarpd (v2df,v2di)
22326v4df __builtin_ia32_vpermilvarpd256 (v4df,v4di)
22327v4sf __builtin_ia32_vpermilvarps (v4sf,v4si)
22328v8sf __builtin_ia32_vpermilvarps256 (v8sf,v8si)
22329int __builtin_ia32_vtestcpd (v2df,v2df,ptest)
22330int __builtin_ia32_vtestcpd256 (v4df,v4df,ptest)
22331int __builtin_ia32_vtestcps (v4sf,v4sf,ptest)
22332int __builtin_ia32_vtestcps256 (v8sf,v8sf,ptest)
22333int __builtin_ia32_vtestnzcpd (v2df,v2df,ptest)
22334int __builtin_ia32_vtestnzcpd256 (v4df,v4df,ptest)
22335int __builtin_ia32_vtestnzcps (v4sf,v4sf,ptest)
22336int __builtin_ia32_vtestnzcps256 (v8sf,v8sf,ptest)
22337int __builtin_ia32_vtestzpd (v2df,v2df,ptest)
22338int __builtin_ia32_vtestzpd256 (v4df,v4df,ptest)
22339int __builtin_ia32_vtestzps (v4sf,v4sf,ptest)
22340int __builtin_ia32_vtestzps256 (v8sf,v8sf,ptest)
22341void __builtin_ia32_vzeroall (void)
22342void __builtin_ia32_vzeroupper (void)
22343v4df __builtin_ia32_xorpd256 (v4df,v4df)
22344v8sf __builtin_ia32_xorps256 (v8sf,v8sf)
22345@end smallexample
22346
22347The following built-in functions are available when @option{-mavx2} is
22348used. All of them generate the machine instruction that is part of the
22349name.
22350
22351@smallexample
22352v32qi __builtin_ia32_mpsadbw256 (v32qi,v32qi,int)
22353v32qi __builtin_ia32_pabsb256 (v32qi)
22354v16hi __builtin_ia32_pabsw256 (v16hi)
22355v8si __builtin_ia32_pabsd256 (v8si)
22356v16hi __builtin_ia32_packssdw256 (v8si,v8si)
22357v32qi __builtin_ia32_packsswb256 (v16hi,v16hi)
22358v16hi __builtin_ia32_packusdw256 (v8si,v8si)
22359v32qi __builtin_ia32_packuswb256 (v16hi,v16hi)
22360v32qi __builtin_ia32_paddb256 (v32qi,v32qi)
22361v16hi __builtin_ia32_paddw256 (v16hi,v16hi)
22362v8si __builtin_ia32_paddd256 (v8si,v8si)
22363v4di __builtin_ia32_paddq256 (v4di,v4di)
22364v32qi __builtin_ia32_paddsb256 (v32qi,v32qi)
22365v16hi __builtin_ia32_paddsw256 (v16hi,v16hi)
22366v32qi __builtin_ia32_paddusb256 (v32qi,v32qi)
22367v16hi __builtin_ia32_paddusw256 (v16hi,v16hi)
22368v4di __builtin_ia32_palignr256 (v4di,v4di,int)
22369v4di __builtin_ia32_andsi256 (v4di,v4di)
22370v4di __builtin_ia32_andnotsi256 (v4di,v4di)
22371v32qi __builtin_ia32_pavgb256 (v32qi,v32qi)
22372v16hi __builtin_ia32_pavgw256 (v16hi,v16hi)
22373v32qi __builtin_ia32_pblendvb256 (v32qi,v32qi,v32qi)
22374v16hi __builtin_ia32_pblendw256 (v16hi,v16hi,int)
22375v32qi __builtin_ia32_pcmpeqb256 (v32qi,v32qi)
22376v16hi __builtin_ia32_pcmpeqw256 (v16hi,v16hi)
22377v8si __builtin_ia32_pcmpeqd256 (c8si,v8si)
22378v4di __builtin_ia32_pcmpeqq256 (v4di,v4di)
22379v32qi __builtin_ia32_pcmpgtb256 (v32qi,v32qi)
22380v16hi __builtin_ia32_pcmpgtw256 (16hi,v16hi)
22381v8si __builtin_ia32_pcmpgtd256 (v8si,v8si)
22382v4di __builtin_ia32_pcmpgtq256 (v4di,v4di)
22383v16hi __builtin_ia32_phaddw256 (v16hi,v16hi)
22384v8si __builtin_ia32_phaddd256 (v8si,v8si)
22385v16hi __builtin_ia32_phaddsw256 (v16hi,v16hi)
22386v16hi __builtin_ia32_phsubw256 (v16hi,v16hi)
22387v8si __builtin_ia32_phsubd256 (v8si,v8si)
22388v16hi __builtin_ia32_phsubsw256 (v16hi,v16hi)
22389v32qi __builtin_ia32_pmaddubsw256 (v32qi,v32qi)
22390v16hi __builtin_ia32_pmaddwd256 (v16hi,v16hi)
22391v32qi __builtin_ia32_pmaxsb256 (v32qi,v32qi)
22392v16hi __builtin_ia32_pmaxsw256 (v16hi,v16hi)
22393v8si __builtin_ia32_pmaxsd256 (v8si,v8si)
22394v32qi __builtin_ia32_pmaxub256 (v32qi,v32qi)
22395v16hi __builtin_ia32_pmaxuw256 (v16hi,v16hi)
22396v8si __builtin_ia32_pmaxud256 (v8si,v8si)
22397v32qi __builtin_ia32_pminsb256 (v32qi,v32qi)
22398v16hi __builtin_ia32_pminsw256 (v16hi,v16hi)
22399v8si __builtin_ia32_pminsd256 (v8si,v8si)
22400v32qi __builtin_ia32_pminub256 (v32qi,v32qi)
22401v16hi __builtin_ia32_pminuw256 (v16hi,v16hi)
22402v8si __builtin_ia32_pminud256 (v8si,v8si)
22403int __builtin_ia32_pmovmskb256 (v32qi)
22404v16hi __builtin_ia32_pmovsxbw256 (v16qi)
22405v8si __builtin_ia32_pmovsxbd256 (v16qi)
22406v4di __builtin_ia32_pmovsxbq256 (v16qi)
22407v8si __builtin_ia32_pmovsxwd256 (v8hi)
22408v4di __builtin_ia32_pmovsxwq256 (v8hi)
22409v4di __builtin_ia32_pmovsxdq256 (v4si)
22410v16hi __builtin_ia32_pmovzxbw256 (v16qi)
22411v8si __builtin_ia32_pmovzxbd256 (v16qi)
22412v4di __builtin_ia32_pmovzxbq256 (v16qi)
22413v8si __builtin_ia32_pmovzxwd256 (v8hi)
22414v4di __builtin_ia32_pmovzxwq256 (v8hi)
22415v4di __builtin_ia32_pmovzxdq256 (v4si)
22416v4di __builtin_ia32_pmuldq256 (v8si,v8si)
22417v16hi __builtin_ia32_pmulhrsw256 (v16hi, v16hi)
22418v16hi __builtin_ia32_pmulhuw256 (v16hi,v16hi)
22419v16hi __builtin_ia32_pmulhw256 (v16hi,v16hi)
22420v16hi __builtin_ia32_pmullw256 (v16hi,v16hi)
22421v8si __builtin_ia32_pmulld256 (v8si,v8si)
22422v4di __builtin_ia32_pmuludq256 (v8si,v8si)
22423v4di __builtin_ia32_por256 (v4di,v4di)
22424v16hi __builtin_ia32_psadbw256 (v32qi,v32qi)
22425v32qi __builtin_ia32_pshufb256 (v32qi,v32qi)
22426v8si __builtin_ia32_pshufd256 (v8si,int)
22427v16hi __builtin_ia32_pshufhw256 (v16hi,int)
22428v16hi __builtin_ia32_pshuflw256 (v16hi,int)
22429v32qi __builtin_ia32_psignb256 (v32qi,v32qi)
22430v16hi __builtin_ia32_psignw256 (v16hi,v16hi)
22431v8si __builtin_ia32_psignd256 (v8si,v8si)
22432v4di __builtin_ia32_pslldqi256 (v4di,int)
22433v16hi __builtin_ia32_psllwi256 (16hi,int)
22434v16hi __builtin_ia32_psllw256(v16hi,v8hi)
22435v8si __builtin_ia32_pslldi256 (v8si,int)
22436v8si __builtin_ia32_pslld256(v8si,v4si)
22437v4di __builtin_ia32_psllqi256 (v4di,int)
22438v4di __builtin_ia32_psllq256(v4di,v2di)
22439v16hi __builtin_ia32_psrawi256 (v16hi,int)
22440v16hi __builtin_ia32_psraw256 (v16hi,v8hi)
22441v8si __builtin_ia32_psradi256 (v8si,int)
22442v8si __builtin_ia32_psrad256 (v8si,v4si)
22443v4di __builtin_ia32_psrldqi256 (v4di, int)
22444v16hi __builtin_ia32_psrlwi256 (v16hi,int)
22445v16hi __builtin_ia32_psrlw256 (v16hi,v8hi)
22446v8si __builtin_ia32_psrldi256 (v8si,int)
22447v8si __builtin_ia32_psrld256 (v8si,v4si)
22448v4di __builtin_ia32_psrlqi256 (v4di,int)
22449v4di __builtin_ia32_psrlq256(v4di,v2di)
22450v32qi __builtin_ia32_psubb256 (v32qi,v32qi)
22451v32hi __builtin_ia32_psubw256 (v16hi,v16hi)
22452v8si __builtin_ia32_psubd256 (v8si,v8si)
22453v4di __builtin_ia32_psubq256 (v4di,v4di)
22454v32qi __builtin_ia32_psubsb256 (v32qi,v32qi)
22455v16hi __builtin_ia32_psubsw256 (v16hi,v16hi)
22456v32qi __builtin_ia32_psubusb256 (v32qi,v32qi)
22457v16hi __builtin_ia32_psubusw256 (v16hi,v16hi)
22458v32qi __builtin_ia32_punpckhbw256 (v32qi,v32qi)
22459v16hi __builtin_ia32_punpckhwd256 (v16hi,v16hi)
22460v8si __builtin_ia32_punpckhdq256 (v8si,v8si)
22461v4di __builtin_ia32_punpckhqdq256 (v4di,v4di)
22462v32qi __builtin_ia32_punpcklbw256 (v32qi,v32qi)
22463v16hi __builtin_ia32_punpcklwd256 (v16hi,v16hi)
22464v8si __builtin_ia32_punpckldq256 (v8si,v8si)
22465v4di __builtin_ia32_punpcklqdq256 (v4di,v4di)
22466v4di __builtin_ia32_pxor256 (v4di,v4di)
22467v4di __builtin_ia32_movntdqa256 (pv4di)
22468v4sf __builtin_ia32_vbroadcastss_ps (v4sf)
22469v8sf __builtin_ia32_vbroadcastss_ps256 (v4sf)
22470v4df __builtin_ia32_vbroadcastsd_pd256 (v2df)
22471v4di __builtin_ia32_vbroadcastsi256 (v2di)
22472v4si __builtin_ia32_pblendd128 (v4si,v4si)
22473v8si __builtin_ia32_pblendd256 (v8si,v8si)
22474v32qi __builtin_ia32_pbroadcastb256 (v16qi)
22475v16hi __builtin_ia32_pbroadcastw256 (v8hi)
22476v8si __builtin_ia32_pbroadcastd256 (v4si)
22477v4di __builtin_ia32_pbroadcastq256 (v2di)
22478v16qi __builtin_ia32_pbroadcastb128 (v16qi)
22479v8hi __builtin_ia32_pbroadcastw128 (v8hi)
22480v4si __builtin_ia32_pbroadcastd128 (v4si)
22481v2di __builtin_ia32_pbroadcastq128 (v2di)
22482v8si __builtin_ia32_permvarsi256 (v8si,v8si)
22483v4df __builtin_ia32_permdf256 (v4df,int)
22484v8sf __builtin_ia32_permvarsf256 (v8sf,v8sf)
22485v4di __builtin_ia32_permdi256 (v4di,int)
22486v4di __builtin_ia32_permti256 (v4di,v4di,int)
22487v4di __builtin_ia32_extract128i256 (v4di,int)
22488v4di __builtin_ia32_insert128i256 (v4di,v2di,int)
22489v8si __builtin_ia32_maskloadd256 (pcv8si,v8si)
22490v4di __builtin_ia32_maskloadq256 (pcv4di,v4di)
22491v4si __builtin_ia32_maskloadd (pcv4si,v4si)
22492v2di __builtin_ia32_maskloadq (pcv2di,v2di)
22493void __builtin_ia32_maskstored256 (pv8si,v8si,v8si)
22494void __builtin_ia32_maskstoreq256 (pv4di,v4di,v4di)
22495void __builtin_ia32_maskstored (pv4si,v4si,v4si)
22496void __builtin_ia32_maskstoreq (pv2di,v2di,v2di)
22497v8si __builtin_ia32_psllv8si (v8si,v8si)
22498v4si __builtin_ia32_psllv4si (v4si,v4si)
22499v4di __builtin_ia32_psllv4di (v4di,v4di)
22500v2di __builtin_ia32_psllv2di (v2di,v2di)
22501v8si __builtin_ia32_psrav8si (v8si,v8si)
22502v4si __builtin_ia32_psrav4si (v4si,v4si)
22503v8si __builtin_ia32_psrlv8si (v8si,v8si)
22504v4si __builtin_ia32_psrlv4si (v4si,v4si)
22505v4di __builtin_ia32_psrlv4di (v4di,v4di)
22506v2di __builtin_ia32_psrlv2di (v2di,v2di)
22507v2df __builtin_ia32_gathersiv2df (v2df, pcdouble,v4si,v2df,int)
22508v4df __builtin_ia32_gathersiv4df (v4df, pcdouble,v4si,v4df,int)
22509v2df __builtin_ia32_gatherdiv2df (v2df, pcdouble,v2di,v2df,int)
22510v4df __builtin_ia32_gatherdiv4df (v4df, pcdouble,v4di,v4df,int)
22511v4sf __builtin_ia32_gathersiv4sf (v4sf, pcfloat,v4si,v4sf,int)
22512v8sf __builtin_ia32_gathersiv8sf (v8sf, pcfloat,v8si,v8sf,int)
22513v4sf __builtin_ia32_gatherdiv4sf (v4sf, pcfloat,v2di,v4sf,int)
22514v4sf __builtin_ia32_gatherdiv4sf256 (v4sf, pcfloat,v4di,v4sf,int)
22515v2di __builtin_ia32_gathersiv2di (v2di, pcint64,v4si,v2di,int)
22516v4di __builtin_ia32_gathersiv4di (v4di, pcint64,v4si,v4di,int)
22517v2di __builtin_ia32_gatherdiv2di (v2di, pcint64,v2di,v2di,int)
22518v4di __builtin_ia32_gatherdiv4di (v4di, pcint64,v4di,v4di,int)
22519v4si __builtin_ia32_gathersiv4si (v4si, pcint,v4si,v4si,int)
22520v8si __builtin_ia32_gathersiv8si (v8si, pcint,v8si,v8si,int)
22521v4si __builtin_ia32_gatherdiv4si (v4si, pcint,v2di,v4si,int)
22522v4si __builtin_ia32_gatherdiv4si256 (v4si, pcint,v4di,v4si,int)
22523@end smallexample
22524
22525The following built-in functions are available when @option{-maes} is
22526used.  All of them generate the machine instruction that is part of the
22527name.
22528
22529@smallexample
22530v2di __builtin_ia32_aesenc128 (v2di, v2di)
22531v2di __builtin_ia32_aesenclast128 (v2di, v2di)
22532v2di __builtin_ia32_aesdec128 (v2di, v2di)
22533v2di __builtin_ia32_aesdeclast128 (v2di, v2di)
22534v2di __builtin_ia32_aeskeygenassist128 (v2di, const int)
22535v2di __builtin_ia32_aesimc128 (v2di)
22536@end smallexample
22537
22538The following built-in function is available when @option{-mpclmul} is
22539used.
22540
22541@table @code
22542@item v2di __builtin_ia32_pclmulqdq128 (v2di, v2di, const int)
22543Generates the @code{pclmulqdq} machine instruction.
22544@end table
22545
22546The following built-in function is available when @option{-mfsgsbase} is
22547used.  All of them generate the machine instruction that is part of the
22548name.
22549
22550@smallexample
22551unsigned int __builtin_ia32_rdfsbase32 (void)
22552unsigned long long __builtin_ia32_rdfsbase64 (void)
22553unsigned int __builtin_ia32_rdgsbase32 (void)
22554unsigned long long __builtin_ia32_rdgsbase64 (void)
22555void _writefsbase_u32 (unsigned int)
22556void _writefsbase_u64 (unsigned long long)
22557void _writegsbase_u32 (unsigned int)
22558void _writegsbase_u64 (unsigned long long)
22559@end smallexample
22560
22561The following built-in function is available when @option{-mrdrnd} is
22562used.  All of them generate the machine instruction that is part of the
22563name.
22564
22565@smallexample
22566unsigned int __builtin_ia32_rdrand16_step (unsigned short *)
22567unsigned int __builtin_ia32_rdrand32_step (unsigned int *)
22568unsigned int __builtin_ia32_rdrand64_step (unsigned long long *)
22569@end smallexample
22570
22571The following built-in function is available when @option{-mptwrite} is
22572used.  All of them generate the machine instruction that is part of the
22573name.
22574
22575@smallexample
22576void __builtin_ia32_ptwrite32 (unsigned)
22577void __builtin_ia32_ptwrite64 (unsigned long long)
22578@end smallexample
22579
22580The following built-in functions are available when @option{-msse4a} is used.
22581All of them generate the machine instruction that is part of the name.
22582
22583@smallexample
22584void __builtin_ia32_movntsd (double *, v2df)
22585void __builtin_ia32_movntss (float *, v4sf)
22586v2di __builtin_ia32_extrq  (v2di, v16qi)
22587v2di __builtin_ia32_extrqi (v2di, const unsigned int, const unsigned int)
22588v2di __builtin_ia32_insertq (v2di, v2di)
22589v2di __builtin_ia32_insertqi (v2di, v2di, const unsigned int, const unsigned int)
22590@end smallexample
22591
22592The following built-in functions are available when @option{-mxop} is used.
22593@smallexample
22594v2df __builtin_ia32_vfrczpd (v2df)
22595v4sf __builtin_ia32_vfrczps (v4sf)
22596v2df __builtin_ia32_vfrczsd (v2df)
22597v4sf __builtin_ia32_vfrczss (v4sf)
22598v4df __builtin_ia32_vfrczpd256 (v4df)
22599v8sf __builtin_ia32_vfrczps256 (v8sf)
22600v2di __builtin_ia32_vpcmov (v2di, v2di, v2di)
22601v2di __builtin_ia32_vpcmov_v2di (v2di, v2di, v2di)
22602v4si __builtin_ia32_vpcmov_v4si (v4si, v4si, v4si)
22603v8hi __builtin_ia32_vpcmov_v8hi (v8hi, v8hi, v8hi)
22604v16qi __builtin_ia32_vpcmov_v16qi (v16qi, v16qi, v16qi)
22605v2df __builtin_ia32_vpcmov_v2df (v2df, v2df, v2df)
22606v4sf __builtin_ia32_vpcmov_v4sf (v4sf, v4sf, v4sf)
22607v4di __builtin_ia32_vpcmov_v4di256 (v4di, v4di, v4di)
22608v8si __builtin_ia32_vpcmov_v8si256 (v8si, v8si, v8si)
22609v16hi __builtin_ia32_vpcmov_v16hi256 (v16hi, v16hi, v16hi)
22610v32qi __builtin_ia32_vpcmov_v32qi256 (v32qi, v32qi, v32qi)
22611v4df __builtin_ia32_vpcmov_v4df256 (v4df, v4df, v4df)
22612v8sf __builtin_ia32_vpcmov_v8sf256 (v8sf, v8sf, v8sf)
22613v16qi __builtin_ia32_vpcomeqb (v16qi, v16qi)
22614v8hi __builtin_ia32_vpcomeqw (v8hi, v8hi)
22615v4si __builtin_ia32_vpcomeqd (v4si, v4si)
22616v2di __builtin_ia32_vpcomeqq (v2di, v2di)
22617v16qi __builtin_ia32_vpcomequb (v16qi, v16qi)
22618v4si __builtin_ia32_vpcomequd (v4si, v4si)
22619v2di __builtin_ia32_vpcomequq (v2di, v2di)
22620v8hi __builtin_ia32_vpcomequw (v8hi, v8hi)
22621v8hi __builtin_ia32_vpcomeqw (v8hi, v8hi)
22622v16qi __builtin_ia32_vpcomfalseb (v16qi, v16qi)
22623v4si __builtin_ia32_vpcomfalsed (v4si, v4si)
22624v2di __builtin_ia32_vpcomfalseq (v2di, v2di)
22625v16qi __builtin_ia32_vpcomfalseub (v16qi, v16qi)
22626v4si __builtin_ia32_vpcomfalseud (v4si, v4si)
22627v2di __builtin_ia32_vpcomfalseuq (v2di, v2di)
22628v8hi __builtin_ia32_vpcomfalseuw (v8hi, v8hi)
22629v8hi __builtin_ia32_vpcomfalsew (v8hi, v8hi)
22630v16qi __builtin_ia32_vpcomgeb (v16qi, v16qi)
22631v4si __builtin_ia32_vpcomged (v4si, v4si)
22632v2di __builtin_ia32_vpcomgeq (v2di, v2di)
22633v16qi __builtin_ia32_vpcomgeub (v16qi, v16qi)
22634v4si __builtin_ia32_vpcomgeud (v4si, v4si)
22635v2di __builtin_ia32_vpcomgeuq (v2di, v2di)
22636v8hi __builtin_ia32_vpcomgeuw (v8hi, v8hi)
22637v8hi __builtin_ia32_vpcomgew (v8hi, v8hi)
22638v16qi __builtin_ia32_vpcomgtb (v16qi, v16qi)
22639v4si __builtin_ia32_vpcomgtd (v4si, v4si)
22640v2di __builtin_ia32_vpcomgtq (v2di, v2di)
22641v16qi __builtin_ia32_vpcomgtub (v16qi, v16qi)
22642v4si __builtin_ia32_vpcomgtud (v4si, v4si)
22643v2di __builtin_ia32_vpcomgtuq (v2di, v2di)
22644v8hi __builtin_ia32_vpcomgtuw (v8hi, v8hi)
22645v8hi __builtin_ia32_vpcomgtw (v8hi, v8hi)
22646v16qi __builtin_ia32_vpcomleb (v16qi, v16qi)
22647v4si __builtin_ia32_vpcomled (v4si, v4si)
22648v2di __builtin_ia32_vpcomleq (v2di, v2di)
22649v16qi __builtin_ia32_vpcomleub (v16qi, v16qi)
22650v4si __builtin_ia32_vpcomleud (v4si, v4si)
22651v2di __builtin_ia32_vpcomleuq (v2di, v2di)
22652v8hi __builtin_ia32_vpcomleuw (v8hi, v8hi)
22653v8hi __builtin_ia32_vpcomlew (v8hi, v8hi)
22654v16qi __builtin_ia32_vpcomltb (v16qi, v16qi)
22655v4si __builtin_ia32_vpcomltd (v4si, v4si)
22656v2di __builtin_ia32_vpcomltq (v2di, v2di)
22657v16qi __builtin_ia32_vpcomltub (v16qi, v16qi)
22658v4si __builtin_ia32_vpcomltud (v4si, v4si)
22659v2di __builtin_ia32_vpcomltuq (v2di, v2di)
22660v8hi __builtin_ia32_vpcomltuw (v8hi, v8hi)
22661v8hi __builtin_ia32_vpcomltw (v8hi, v8hi)
22662v16qi __builtin_ia32_vpcomneb (v16qi, v16qi)
22663v4si __builtin_ia32_vpcomned (v4si, v4si)
22664v2di __builtin_ia32_vpcomneq (v2di, v2di)
22665v16qi __builtin_ia32_vpcomneub (v16qi, v16qi)
22666v4si __builtin_ia32_vpcomneud (v4si, v4si)
22667v2di __builtin_ia32_vpcomneuq (v2di, v2di)
22668v8hi __builtin_ia32_vpcomneuw (v8hi, v8hi)
22669v8hi __builtin_ia32_vpcomnew (v8hi, v8hi)
22670v16qi __builtin_ia32_vpcomtrueb (v16qi, v16qi)
22671v4si __builtin_ia32_vpcomtrued (v4si, v4si)
22672v2di __builtin_ia32_vpcomtrueq (v2di, v2di)
22673v16qi __builtin_ia32_vpcomtrueub (v16qi, v16qi)
22674v4si __builtin_ia32_vpcomtrueud (v4si, v4si)
22675v2di __builtin_ia32_vpcomtrueuq (v2di, v2di)
22676v8hi __builtin_ia32_vpcomtrueuw (v8hi, v8hi)
22677v8hi __builtin_ia32_vpcomtruew (v8hi, v8hi)
22678v4si __builtin_ia32_vphaddbd (v16qi)
22679v2di __builtin_ia32_vphaddbq (v16qi)
22680v8hi __builtin_ia32_vphaddbw (v16qi)
22681v2di __builtin_ia32_vphadddq (v4si)
22682v4si __builtin_ia32_vphaddubd (v16qi)
22683v2di __builtin_ia32_vphaddubq (v16qi)
22684v8hi __builtin_ia32_vphaddubw (v16qi)
22685v2di __builtin_ia32_vphaddudq (v4si)
22686v4si __builtin_ia32_vphadduwd (v8hi)
22687v2di __builtin_ia32_vphadduwq (v8hi)
22688v4si __builtin_ia32_vphaddwd (v8hi)
22689v2di __builtin_ia32_vphaddwq (v8hi)
22690v8hi __builtin_ia32_vphsubbw (v16qi)
22691v2di __builtin_ia32_vphsubdq (v4si)
22692v4si __builtin_ia32_vphsubwd (v8hi)
22693v4si __builtin_ia32_vpmacsdd (v4si, v4si, v4si)
22694v2di __builtin_ia32_vpmacsdqh (v4si, v4si, v2di)
22695v2di __builtin_ia32_vpmacsdql (v4si, v4si, v2di)
22696v4si __builtin_ia32_vpmacssdd (v4si, v4si, v4si)
22697v2di __builtin_ia32_vpmacssdqh (v4si, v4si, v2di)
22698v2di __builtin_ia32_vpmacssdql (v4si, v4si, v2di)
22699v4si __builtin_ia32_vpmacsswd (v8hi, v8hi, v4si)
22700v8hi __builtin_ia32_vpmacssww (v8hi, v8hi, v8hi)
22701v4si __builtin_ia32_vpmacswd (v8hi, v8hi, v4si)
22702v8hi __builtin_ia32_vpmacsww (v8hi, v8hi, v8hi)
22703v4si __builtin_ia32_vpmadcsswd (v8hi, v8hi, v4si)
22704v4si __builtin_ia32_vpmadcswd (v8hi, v8hi, v4si)
22705v16qi __builtin_ia32_vpperm (v16qi, v16qi, v16qi)
22706v16qi __builtin_ia32_vprotb (v16qi, v16qi)
22707v4si __builtin_ia32_vprotd (v4si, v4si)
22708v2di __builtin_ia32_vprotq (v2di, v2di)
22709v8hi __builtin_ia32_vprotw (v8hi, v8hi)
22710v16qi __builtin_ia32_vpshab (v16qi, v16qi)
22711v4si __builtin_ia32_vpshad (v4si, v4si)
22712v2di __builtin_ia32_vpshaq (v2di, v2di)
22713v8hi __builtin_ia32_vpshaw (v8hi, v8hi)
22714v16qi __builtin_ia32_vpshlb (v16qi, v16qi)
22715v4si __builtin_ia32_vpshld (v4si, v4si)
22716v2di __builtin_ia32_vpshlq (v2di, v2di)
22717v8hi __builtin_ia32_vpshlw (v8hi, v8hi)
22718@end smallexample
22719
22720The following built-in functions are available when @option{-mfma4} is used.
22721All of them generate the machine instruction that is part of the name.
22722
22723@smallexample
22724v2df __builtin_ia32_vfmaddpd (v2df, v2df, v2df)
22725v4sf __builtin_ia32_vfmaddps (v4sf, v4sf, v4sf)
22726v2df __builtin_ia32_vfmaddsd (v2df, v2df, v2df)
22727v4sf __builtin_ia32_vfmaddss (v4sf, v4sf, v4sf)
22728v2df __builtin_ia32_vfmsubpd (v2df, v2df, v2df)
22729v4sf __builtin_ia32_vfmsubps (v4sf, v4sf, v4sf)
22730v2df __builtin_ia32_vfmsubsd (v2df, v2df, v2df)
22731v4sf __builtin_ia32_vfmsubss (v4sf, v4sf, v4sf)
22732v2df __builtin_ia32_vfnmaddpd (v2df, v2df, v2df)
22733v4sf __builtin_ia32_vfnmaddps (v4sf, v4sf, v4sf)
22734v2df __builtin_ia32_vfnmaddsd (v2df, v2df, v2df)
22735v4sf __builtin_ia32_vfnmaddss (v4sf, v4sf, v4sf)
22736v2df __builtin_ia32_vfnmsubpd (v2df, v2df, v2df)
22737v4sf __builtin_ia32_vfnmsubps (v4sf, v4sf, v4sf)
22738v2df __builtin_ia32_vfnmsubsd (v2df, v2df, v2df)
22739v4sf __builtin_ia32_vfnmsubss (v4sf, v4sf, v4sf)
22740v2df __builtin_ia32_vfmaddsubpd  (v2df, v2df, v2df)
22741v4sf __builtin_ia32_vfmaddsubps  (v4sf, v4sf, v4sf)
22742v2df __builtin_ia32_vfmsubaddpd  (v2df, v2df, v2df)
22743v4sf __builtin_ia32_vfmsubaddps  (v4sf, v4sf, v4sf)
22744v4df __builtin_ia32_vfmaddpd256 (v4df, v4df, v4df)
22745v8sf __builtin_ia32_vfmaddps256 (v8sf, v8sf, v8sf)
22746v4df __builtin_ia32_vfmsubpd256 (v4df, v4df, v4df)
22747v8sf __builtin_ia32_vfmsubps256 (v8sf, v8sf, v8sf)
22748v4df __builtin_ia32_vfnmaddpd256 (v4df, v4df, v4df)
22749v8sf __builtin_ia32_vfnmaddps256 (v8sf, v8sf, v8sf)
22750v4df __builtin_ia32_vfnmsubpd256 (v4df, v4df, v4df)
22751v8sf __builtin_ia32_vfnmsubps256 (v8sf, v8sf, v8sf)
22752v4df __builtin_ia32_vfmaddsubpd256 (v4df, v4df, v4df)
22753v8sf __builtin_ia32_vfmaddsubps256 (v8sf, v8sf, v8sf)
22754v4df __builtin_ia32_vfmsubaddpd256 (v4df, v4df, v4df)
22755v8sf __builtin_ia32_vfmsubaddps256 (v8sf, v8sf, v8sf)
22756
22757@end smallexample
22758
22759The following built-in functions are available when @option{-mlwp} is used.
22760
22761@smallexample
22762void __builtin_ia32_llwpcb16 (void *);
22763void __builtin_ia32_llwpcb32 (void *);
22764void __builtin_ia32_llwpcb64 (void *);
22765void * __builtin_ia32_llwpcb16 (void);
22766void * __builtin_ia32_llwpcb32 (void);
22767void * __builtin_ia32_llwpcb64 (void);
22768void __builtin_ia32_lwpval16 (unsigned short, unsigned int, unsigned short)
22769void __builtin_ia32_lwpval32 (unsigned int, unsigned int, unsigned int)
22770void __builtin_ia32_lwpval64 (unsigned __int64, unsigned int, unsigned int)
22771unsigned char __builtin_ia32_lwpins16 (unsigned short, unsigned int, unsigned short)
22772unsigned char __builtin_ia32_lwpins32 (unsigned int, unsigned int, unsigned int)
22773unsigned char __builtin_ia32_lwpins64 (unsigned __int64, unsigned int, unsigned int)
22774@end smallexample
22775
22776The following built-in functions are available when @option{-mbmi} is used.
22777All of them generate the machine instruction that is part of the name.
22778@smallexample
22779unsigned int __builtin_ia32_bextr_u32(unsigned int, unsigned int);
22780unsigned long long __builtin_ia32_bextr_u64 (unsigned long long, unsigned long long);
22781@end smallexample
22782
22783The following built-in functions are available when @option{-mbmi2} is used.
22784All of them generate the machine instruction that is part of the name.
22785@smallexample
22786unsigned int _bzhi_u32 (unsigned int, unsigned int)
22787unsigned int _pdep_u32 (unsigned int, unsigned int)
22788unsigned int _pext_u32 (unsigned int, unsigned int)
22789unsigned long long _bzhi_u64 (unsigned long long, unsigned long long)
22790unsigned long long _pdep_u64 (unsigned long long, unsigned long long)
22791unsigned long long _pext_u64 (unsigned long long, unsigned long long)
22792@end smallexample
22793
22794The following built-in functions are available when @option{-mlzcnt} is used.
22795All of them generate the machine instruction that is part of the name.
22796@smallexample
22797unsigned short __builtin_ia32_lzcnt_u16(unsigned short);
22798unsigned int __builtin_ia32_lzcnt_u32(unsigned int);
22799unsigned long long __builtin_ia32_lzcnt_u64 (unsigned long long);
22800@end smallexample
22801
22802The following built-in functions are available when @option{-mfxsr} is used.
22803All of them generate the machine instruction that is part of the name.
22804@smallexample
22805void __builtin_ia32_fxsave (void *)
22806void __builtin_ia32_fxrstor (void *)
22807void __builtin_ia32_fxsave64 (void *)
22808void __builtin_ia32_fxrstor64 (void *)
22809@end smallexample
22810
22811The following built-in functions are available when @option{-mxsave} is used.
22812All of them generate the machine instruction that is part of the name.
22813@smallexample
22814void __builtin_ia32_xsave (void *, long long)
22815void __builtin_ia32_xrstor (void *, long long)
22816void __builtin_ia32_xsave64 (void *, long long)
22817void __builtin_ia32_xrstor64 (void *, long long)
22818@end smallexample
22819
22820The following built-in functions are available when @option{-mxsaveopt} is used.
22821All of them generate the machine instruction that is part of the name.
22822@smallexample
22823void __builtin_ia32_xsaveopt (void *, long long)
22824void __builtin_ia32_xsaveopt64 (void *, long long)
22825@end smallexample
22826
22827The following built-in functions are available when @option{-mtbm} is used.
22828Both of them generate the immediate form of the bextr machine instruction.
22829@smallexample
22830unsigned int __builtin_ia32_bextri_u32 (unsigned int,
22831                                        const unsigned int);
22832unsigned long long __builtin_ia32_bextri_u64 (unsigned long long,
22833                                              const unsigned long long);
22834@end smallexample
22835
22836
22837The following built-in functions are available when @option{-m3dnow} is used.
22838All of them generate the machine instruction that is part of the name.
22839
22840@smallexample
22841void __builtin_ia32_femms (void)
22842v8qi __builtin_ia32_pavgusb (v8qi, v8qi)
22843v2si __builtin_ia32_pf2id (v2sf)
22844v2sf __builtin_ia32_pfacc (v2sf, v2sf)
22845v2sf __builtin_ia32_pfadd (v2sf, v2sf)
22846v2si __builtin_ia32_pfcmpeq (v2sf, v2sf)
22847v2si __builtin_ia32_pfcmpge (v2sf, v2sf)
22848v2si __builtin_ia32_pfcmpgt (v2sf, v2sf)
22849v2sf __builtin_ia32_pfmax (v2sf, v2sf)
22850v2sf __builtin_ia32_pfmin (v2sf, v2sf)
22851v2sf __builtin_ia32_pfmul (v2sf, v2sf)
22852v2sf __builtin_ia32_pfrcp (v2sf)
22853v2sf __builtin_ia32_pfrcpit1 (v2sf, v2sf)
22854v2sf __builtin_ia32_pfrcpit2 (v2sf, v2sf)
22855v2sf __builtin_ia32_pfrsqrt (v2sf)
22856v2sf __builtin_ia32_pfsub (v2sf, v2sf)
22857v2sf __builtin_ia32_pfsubr (v2sf, v2sf)
22858v2sf __builtin_ia32_pi2fd (v2si)
22859v4hi __builtin_ia32_pmulhrw (v4hi, v4hi)
22860@end smallexample
22861
22862The following built-in functions are available when @option{-m3dnowa} is used.
22863All of them generate the machine instruction that is part of the name.
22864
22865@smallexample
22866v2si __builtin_ia32_pf2iw (v2sf)
22867v2sf __builtin_ia32_pfnacc (v2sf, v2sf)
22868v2sf __builtin_ia32_pfpnacc (v2sf, v2sf)
22869v2sf __builtin_ia32_pi2fw (v2si)
22870v2sf __builtin_ia32_pswapdsf (v2sf)
22871v2si __builtin_ia32_pswapdsi (v2si)
22872@end smallexample
22873
22874The following built-in functions are available when @option{-mrtm} is used
22875They are used for restricted transactional memory. These are the internal
22876low level functions. Normally the functions in
22877@ref{x86 transactional memory intrinsics} should be used instead.
22878
22879@smallexample
22880int __builtin_ia32_xbegin ()
22881void __builtin_ia32_xend ()
22882void __builtin_ia32_xabort (status)
22883int __builtin_ia32_xtest ()
22884@end smallexample
22885
22886The following built-in functions are available when @option{-mmwaitx} is used.
22887All of them generate the machine instruction that is part of the name.
22888@smallexample
22889void __builtin_ia32_monitorx (void *, unsigned int, unsigned int)
22890void __builtin_ia32_mwaitx (unsigned int, unsigned int, unsigned int)
22891@end smallexample
22892
22893The following built-in functions are available when @option{-mclzero} is used.
22894All of them generate the machine instruction that is part of the name.
22895@smallexample
22896void __builtin_i32_clzero (void *)
22897@end smallexample
22898
22899The following built-in functions are available when @option{-mpku} is used.
22900They generate reads and writes to PKRU.
22901@smallexample
22902void __builtin_ia32_wrpkru (unsigned int)
22903unsigned int __builtin_ia32_rdpkru ()
22904@end smallexample
22905
22906The following built-in functions are available when
22907@option{-mshstk} option is used.  They support shadow stack
22908machine instructions from Intel Control-flow Enforcement Technology (CET).
22909Each built-in function generates the  machine instruction that is part
22910of the function's name.  These are the internal low-level functions.
22911Normally the functions in @ref{x86 control-flow protection intrinsics}
22912should be used instead.
22913
22914@smallexample
22915unsigned int __builtin_ia32_rdsspd (void)
22916unsigned long long __builtin_ia32_rdsspq (void)
22917void __builtin_ia32_incsspd (unsigned int)
22918void __builtin_ia32_incsspq (unsigned long long)
22919void __builtin_ia32_saveprevssp(void);
22920void __builtin_ia32_rstorssp(void *);
22921void __builtin_ia32_wrssd(unsigned int, void *);
22922void __builtin_ia32_wrssq(unsigned long long, void *);
22923void __builtin_ia32_wrussd(unsigned int, void *);
22924void __builtin_ia32_wrussq(unsigned long long, void *);
22925void __builtin_ia32_setssbsy(void);
22926void __builtin_ia32_clrssbsy(void *);
22927@end smallexample
22928
22929@node x86 transactional memory intrinsics
22930@subsection x86 Transactional Memory Intrinsics
22931
22932These hardware transactional memory intrinsics for x86 allow you to use
22933memory transactions with RTM (Restricted Transactional Memory).
22934This support is enabled with the @option{-mrtm} option.
22935For using HLE (Hardware Lock Elision) see
22936@ref{x86 specific memory model extensions for transactional memory} instead.
22937
22938A memory transaction commits all changes to memory in an atomic way,
22939as visible to other threads. If the transaction fails it is rolled back
22940and all side effects discarded.
22941
22942Generally there is no guarantee that a memory transaction ever succeeds
22943and suitable fallback code always needs to be supplied.
22944
22945@deftypefn {RTM Function} {unsigned} _xbegin ()
22946Start a RTM (Restricted Transactional Memory) transaction.
22947Returns @code{_XBEGIN_STARTED} when the transaction
22948started successfully (note this is not 0, so the constant has to be
22949explicitly tested).
22950
22951If the transaction aborts, all side effects
22952are undone and an abort code encoded as a bit mask is returned.
22953The following macros are defined:
22954
22955@table @code
22956@item _XABORT_EXPLICIT
22957Transaction was explicitly aborted with @code{_xabort}.  The parameter passed
22958to @code{_xabort} is available with @code{_XABORT_CODE(status)}.
22959@item _XABORT_RETRY
22960Transaction retry is possible.
22961@item _XABORT_CONFLICT
22962Transaction abort due to a memory conflict with another thread.
22963@item _XABORT_CAPACITY
22964Transaction abort due to the transaction using too much memory.
22965@item _XABORT_DEBUG
22966Transaction abort due to a debug trap.
22967@item _XABORT_NESTED
22968Transaction abort in an inner nested transaction.
22969@end table
22970
22971There is no guarantee
22972any transaction ever succeeds, so there always needs to be a valid
22973fallback path.
22974@end deftypefn
22975
22976@deftypefn {RTM Function} {void} _xend ()
22977Commit the current transaction. When no transaction is active this faults.
22978All memory side effects of the transaction become visible
22979to other threads in an atomic manner.
22980@end deftypefn
22981
22982@deftypefn {RTM Function} {int} _xtest ()
22983Return a nonzero value if a transaction is currently active, otherwise 0.
22984@end deftypefn
22985
22986@deftypefn {RTM Function} {void} _xabort (status)
22987Abort the current transaction. When no transaction is active this is a no-op.
22988The @var{status} is an 8-bit constant; its value is encoded in the return
22989value from @code{_xbegin}.
22990@end deftypefn
22991
22992Here is an example showing handling for @code{_XABORT_RETRY}
22993and a fallback path for other failures:
22994
22995@smallexample
22996#include <immintrin.h>
22997
22998int n_tries, max_tries;
22999unsigned status = _XABORT_EXPLICIT;
23000...
23001
23002for (n_tries = 0; n_tries < max_tries; n_tries++)
23003  @{
23004    status = _xbegin ();
23005    if (status == _XBEGIN_STARTED || !(status & _XABORT_RETRY))
23006      break;
23007  @}
23008if (status == _XBEGIN_STARTED)
23009  @{
23010    ... transaction code...
23011    _xend ();
23012  @}
23013else
23014  @{
23015    ... non-transactional fallback path...
23016  @}
23017@end smallexample
23018
23019@noindent
23020Note that, in most cases, the transactional and non-transactional code
23021must synchronize together to ensure consistency.
23022
23023@node x86 control-flow protection intrinsics
23024@subsection x86 Control-Flow Protection Intrinsics
23025
23026@deftypefn {CET Function} {ret_type} _get_ssp (void)
23027Get the current value of shadow stack pointer if shadow stack support
23028from Intel CET is enabled in the hardware or @code{0} otherwise.
23029The @code{ret_type} is @code{unsigned long long} for 64-bit targets
23030and @code{unsigned int} for 32-bit targets.
23031@end deftypefn
23032
23033@deftypefn {CET Function} void _inc_ssp (unsigned int)
23034Increment the current shadow stack pointer by the size specified by the
23035function argument.  The argument is masked to a byte value for security
23036reasons, so to increment by more than 255 bytes you must call the function
23037multiple times.
23038@end deftypefn
23039
23040The shadow stack unwind code looks like:
23041
23042@smallexample
23043#include <immintrin.h>
23044
23045/* Unwind the shadow stack for EH.  */
23046#define _Unwind_Frames_Extra(x)       \
23047  do                                  \
23048    @{                                \
23049      _Unwind_Word ssp = _get_ssp (); \
23050      if (ssp != 0)                   \
23051        @{                            \
23052          _Unwind_Word tmp = (x);     \
23053          while (tmp > 255)           \
23054            @{                        \
23055              _inc_ssp (tmp);         \
23056              tmp -= 255;             \
23057            @}                        \
23058          _inc_ssp (tmp);             \
23059        @}                            \
23060    @}                                \
23061    while (0)
23062@end smallexample
23063
23064@noindent
23065This code runs unconditionally on all 64-bit processors.  For 32-bit
23066processors the code runs on those that support multi-byte NOP instructions.
23067
23068@node Target Format Checks
23069@section Format Checks Specific to Particular Target Machines
23070
23071For some target machines, GCC supports additional options to the
23072format attribute
23073(@pxref{Function Attributes,,Declaring Attributes of Functions}).
23074
23075@menu
23076* Solaris Format Checks::
23077* Darwin Format Checks::
23078@end menu
23079
23080@node Solaris Format Checks
23081@subsection Solaris Format Checks
23082
23083Solaris targets support the @code{cmn_err} (or @code{__cmn_err__}) format
23084check.  @code{cmn_err} accepts a subset of the standard @code{printf}
23085conversions, and the two-argument @code{%b} conversion for displaying
23086bit-fields.  See the Solaris man page for @code{cmn_err} for more information.
23087
23088@node Darwin Format Checks
23089@subsection Darwin Format Checks
23090
23091In addition to the full set of format archetypes (attribute format style
23092arguments such as @code{printf}, @code{scanf}, @code{strftime}, and
23093@code{strfmon}), Darwin targets also support the @code{CFString} (or
23094@code{__CFString__}) archetype in the @code{format} attribute.
23095Declarations with this archetype are parsed for correct syntax
23096and argument types.  However, parsing of the format string itself and
23097validating arguments against it in calls to such functions is currently
23098not performed.
23099
23100Additionally, @code{CFStringRefs} (defined by the @code{CoreFoundation} headers) may
23101also be used as format arguments.  Note that the relevant headers are only likely to be
23102available on Darwin (OSX) installations.  On such installations, the XCode and system
23103documentation provide descriptions of @code{CFString}, @code{CFStringRefs} and
23104associated functions.
23105
23106@node Pragmas
23107@section Pragmas Accepted by GCC
23108@cindex pragmas
23109@cindex @code{#pragma}
23110
23111GCC supports several types of pragmas, primarily in order to compile
23112code originally written for other compilers.  Note that in general
23113we do not recommend the use of pragmas; @xref{Function Attributes},
23114for further explanation.
23115
23116The GNU C preprocessor recognizes several pragmas in addition to the
23117compiler pragmas documented here.  Refer to the CPP manual for more
23118information.
23119
23120@menu
23121* AArch64 Pragmas::
23122* ARM Pragmas::
23123* M32C Pragmas::
23124* MeP Pragmas::
23125* PRU Pragmas::
23126* RS/6000 and PowerPC Pragmas::
23127* S/390 Pragmas::
23128* Darwin Pragmas::
23129* Solaris Pragmas::
23130* Symbol-Renaming Pragmas::
23131* Structure-Layout Pragmas::
23132* Weak Pragmas::
23133* Diagnostic Pragmas::
23134* Visibility Pragmas::
23135* Push/Pop Macro Pragmas::
23136* Function Specific Option Pragmas::
23137* Loop-Specific Pragmas::
23138@end menu
23139
23140@node AArch64 Pragmas
23141@subsection AArch64 Pragmas
23142
23143The pragmas defined by the AArch64 target correspond to the AArch64
23144target function attributes.  They can be specified as below:
23145@smallexample
23146#pragma GCC target("string")
23147@end smallexample
23148
23149where @code{@var{string}} can be any string accepted as an AArch64 target
23150attribute.  @xref{AArch64 Function Attributes}, for more details
23151on the permissible values of @code{string}.
23152
23153@node ARM Pragmas
23154@subsection ARM Pragmas
23155
23156The ARM target defines pragmas for controlling the default addition of
23157@code{long_call} and @code{short_call} attributes to functions.
23158@xref{Function Attributes}, for information about the effects of these
23159attributes.
23160
23161@table @code
23162@item long_calls
23163@cindex pragma, long_calls
23164Set all subsequent functions to have the @code{long_call} attribute.
23165
23166@item no_long_calls
23167@cindex pragma, no_long_calls
23168Set all subsequent functions to have the @code{short_call} attribute.
23169
23170@item long_calls_off
23171@cindex pragma, long_calls_off
23172Do not affect the @code{long_call} or @code{short_call} attributes of
23173subsequent functions.
23174@end table
23175
23176@node M32C Pragmas
23177@subsection M32C Pragmas
23178
23179@table @code
23180@item GCC memregs @var{number}
23181@cindex pragma, memregs
23182Overrides the command-line option @code{-memregs=} for the current
23183file.  Use with care!  This pragma must be before any function in the
23184file, and mixing different memregs values in different objects may
23185make them incompatible.  This pragma is useful when a
23186performance-critical function uses a memreg for temporary values,
23187as it may allow you to reduce the number of memregs used.
23188
23189@item ADDRESS @var{name} @var{address}
23190@cindex pragma, address
23191For any declared symbols matching @var{name}, this does three things
23192to that symbol: it forces the symbol to be located at the given
23193address (a number), it forces the symbol to be volatile, and it
23194changes the symbol's scope to be static.  This pragma exists for
23195compatibility with other compilers, but note that the common
23196@code{1234H} numeric syntax is not supported (use @code{0x1234}
23197instead).  Example:
23198
23199@smallexample
23200#pragma ADDRESS port3 0x103
23201char port3;
23202@end smallexample
23203
23204@end table
23205
23206@node MeP Pragmas
23207@subsection MeP Pragmas
23208
23209@table @code
23210
23211@item custom io_volatile (on|off)
23212@cindex pragma, custom io_volatile
23213Overrides the command-line option @code{-mio-volatile} for the current
23214file.  Note that for compatibility with future GCC releases, this
23215option should only be used once before any @code{io} variables in each
23216file.
23217
23218@item GCC coprocessor available @var{registers}
23219@cindex pragma, coprocessor available
23220Specifies which coprocessor registers are available to the register
23221allocator.  @var{registers} may be a single register, register range
23222separated by ellipses, or comma-separated list of those.  Example:
23223
23224@smallexample
23225#pragma GCC coprocessor available $c0...$c10, $c28
23226@end smallexample
23227
23228@item GCC coprocessor call_saved @var{registers}
23229@cindex pragma, coprocessor call_saved
23230Specifies which coprocessor registers are to be saved and restored by
23231any function using them.  @var{registers} may be a single register,
23232register range separated by ellipses, or comma-separated list of
23233those.  Example:
23234
23235@smallexample
23236#pragma GCC coprocessor call_saved $c4...$c6, $c31
23237@end smallexample
23238
23239@item GCC coprocessor subclass '(A|B|C|D)' = @var{registers}
23240@cindex pragma, coprocessor subclass
23241Creates and defines a register class.  These register classes can be
23242used by inline @code{asm} constructs.  @var{registers} may be a single
23243register, register range separated by ellipses, or comma-separated
23244list of those.  Example:
23245
23246@smallexample
23247#pragma GCC coprocessor subclass 'B' = $c2, $c4, $c6
23248
23249asm ("cpfoo %0" : "=B" (x));
23250@end smallexample
23251
23252@item GCC disinterrupt @var{name} , @var{name} @dots{}
23253@cindex pragma, disinterrupt
23254For the named functions, the compiler adds code to disable interrupts
23255for the duration of those functions.  If any functions so named
23256are not encountered in the source, a warning is emitted that the pragma is
23257not used.  Examples:
23258
23259@smallexample
23260#pragma disinterrupt foo
23261#pragma disinterrupt bar, grill
23262int foo () @{ @dots{} @}
23263@end smallexample
23264
23265@item GCC call @var{name} , @var{name} @dots{}
23266@cindex pragma, call
23267For the named functions, the compiler always uses a register-indirect
23268call model when calling the named functions.  Examples:
23269
23270@smallexample
23271extern int foo ();
23272#pragma call foo
23273@end smallexample
23274
23275@end table
23276
23277@node PRU Pragmas
23278@subsection PRU Pragmas
23279
23280@table @code
23281
23282@item ctable_entry @var{index} @var{constant_address}
23283@cindex pragma, ctable_entry
23284Specifies that the PRU CTABLE entry given by @var{index} has the value
23285@var{constant_address}.  This enables GCC to emit LBCO/SBCO instructions
23286when the load/store address is known and can be addressed with some CTABLE
23287entry.  For example:
23288
23289@smallexample
23290/* will compile to "sbco Rx, 2, 0x10, 4" */
23291#pragma ctable_entry 2 0x4802a000
23292*(unsigned int *)0x4802a010 = val;
23293@end smallexample
23294
23295@end table
23296
23297@node RS/6000 and PowerPC Pragmas
23298@subsection RS/6000 and PowerPC Pragmas
23299
23300The RS/6000 and PowerPC targets define one pragma for controlling
23301whether or not the @code{longcall} attribute is added to function
23302declarations by default.  This pragma overrides the @option{-mlongcall}
23303option, but not the @code{longcall} and @code{shortcall} attributes.
23304@xref{RS/6000 and PowerPC Options}, for more information about when long
23305calls are and are not necessary.
23306
23307@table @code
23308@item longcall (1)
23309@cindex pragma, longcall
23310Apply the @code{longcall} attribute to all subsequent function
23311declarations.
23312
23313@item longcall (0)
23314Do not apply the @code{longcall} attribute to subsequent function
23315declarations.
23316@end table
23317
23318@c Describe h8300 pragmas here.
23319@c Describe sh pragmas here.
23320@c Describe v850 pragmas here.
23321
23322@node S/390 Pragmas
23323@subsection S/390 Pragmas
23324
23325The pragmas defined by the S/390 target correspond to the S/390
23326target function attributes and some the additional options:
23327
23328@table @samp
23329@item zvector
23330@itemx no-zvector
23331@end table
23332
23333Note that options of the pragma, unlike options of the target
23334attribute, do change the value of preprocessor macros like
23335@code{__VEC__}.  They can be specified as below:
23336
23337@smallexample
23338#pragma GCC target("string[,string]...")
23339#pragma GCC target("string"[,"string"]...)
23340@end smallexample
23341
23342@node Darwin Pragmas
23343@subsection Darwin Pragmas
23344
23345The following pragmas are available for all architectures running the
23346Darwin operating system.  These are useful for compatibility with other
23347Mac OS compilers.
23348
23349@table @code
23350@item mark @var{tokens}@dots{}
23351@cindex pragma, mark
23352This pragma is accepted, but has no effect.
23353
23354@item options align=@var{alignment}
23355@cindex pragma, options align
23356This pragma sets the alignment of fields in structures.  The values of
23357@var{alignment} may be @code{mac68k}, to emulate m68k alignment, or
23358@code{power}, to emulate PowerPC alignment.  Uses of this pragma nest
23359properly; to restore the previous setting, use @code{reset} for the
23360@var{alignment}.
23361
23362@item segment @var{tokens}@dots{}
23363@cindex pragma, segment
23364This pragma is accepted, but has no effect.
23365
23366@item unused (@var{var} [, @var{var}]@dots{})
23367@cindex pragma, unused
23368This pragma declares variables to be possibly unused.  GCC does not
23369produce warnings for the listed variables.  The effect is similar to
23370that of the @code{unused} attribute, except that this pragma may appear
23371anywhere within the variables' scopes.
23372@end table
23373
23374@node Solaris Pragmas
23375@subsection Solaris Pragmas
23376
23377The Solaris target supports @code{#pragma redefine_extname}
23378(@pxref{Symbol-Renaming Pragmas}).  It also supports additional
23379@code{#pragma} directives for compatibility with the system compiler.
23380
23381@table @code
23382@item align @var{alignment} (@var{variable} [, @var{variable}]...)
23383@cindex pragma, align
23384
23385Increase the minimum alignment of each @var{variable} to @var{alignment}.
23386This is the same as GCC's @code{aligned} attribute @pxref{Variable
23387Attributes}).  Macro expansion occurs on the arguments to this pragma
23388when compiling C and Objective-C@.  It does not currently occur when
23389compiling C++, but this is a bug which may be fixed in a future
23390release.
23391
23392@item fini (@var{function} [, @var{function}]...)
23393@cindex pragma, fini
23394
23395This pragma causes each listed @var{function} to be called after
23396main, or during shared module unloading, by adding a call to the
23397@code{.fini} section.
23398
23399@item init (@var{function} [, @var{function}]...)
23400@cindex pragma, init
23401
23402This pragma causes each listed @var{function} to be called during
23403initialization (before @code{main}) or during shared module loading, by
23404adding a call to the @code{.init} section.
23405
23406@end table
23407
23408@node Symbol-Renaming Pragmas
23409@subsection Symbol-Renaming Pragmas
23410
23411GCC supports a @code{#pragma} directive that changes the name used in
23412assembly for a given declaration. While this pragma is supported on all
23413platforms, it is intended primarily to provide compatibility with the
23414Solaris system headers. This effect can also be achieved using the asm
23415labels extension (@pxref{Asm Labels}).
23416
23417@table @code
23418@item redefine_extname @var{oldname} @var{newname}
23419@cindex pragma, redefine_extname
23420
23421This pragma gives the C function @var{oldname} the assembly symbol
23422@var{newname}.  The preprocessor macro @code{__PRAGMA_REDEFINE_EXTNAME}
23423is defined if this pragma is available (currently on all platforms).
23424@end table
23425
23426This pragma and the @code{asm} labels extension interact in a complicated
23427manner.  Here are some corner cases you may want to be aware of:
23428
23429@enumerate
23430@item This pragma silently applies only to declarations with external
23431linkage.  The @code{asm} label feature does not have this restriction.
23432
23433@item In C++, this pragma silently applies only to declarations with
23434``C'' linkage.  Again, @code{asm} labels do not have this restriction.
23435
23436@item If either of the ways of changing the assembly name of a
23437declaration are applied to a declaration whose assembly name has
23438already been determined (either by a previous use of one of these
23439features, or because the compiler needed the assembly name in order to
23440generate code), and the new name is different, a warning issues and
23441the name does not change.
23442
23443@item The @var{oldname} used by @code{#pragma redefine_extname} is
23444always the C-language name.
23445@end enumerate
23446
23447@node Structure-Layout Pragmas
23448@subsection Structure-Layout Pragmas
23449
23450For compatibility with Microsoft Windows compilers, GCC supports a
23451set of @code{#pragma} directives that change the maximum alignment of
23452members of structures (other than zero-width bit-fields), unions, and
23453classes subsequently defined. The @var{n} value below always is required
23454to be a small power of two and specifies the new alignment in bytes.
23455
23456@enumerate
23457@item @code{#pragma pack(@var{n})} simply sets the new alignment.
23458@item @code{#pragma pack()} sets the alignment to the one that was in
23459effect when compilation started (see also command-line option
23460@option{-fpack-struct[=@var{n}]} @pxref{Code Gen Options}).
23461@item @code{#pragma pack(push[,@var{n}])} pushes the current alignment
23462setting on an internal stack and then optionally sets the new alignment.
23463@item @code{#pragma pack(pop)} restores the alignment setting to the one
23464saved at the top of the internal stack (and removes that stack entry).
23465Note that @code{#pragma pack([@var{n}])} does not influence this internal
23466stack; thus it is possible to have @code{#pragma pack(push)} followed by
23467multiple @code{#pragma pack(@var{n})} instances and finalized by a single
23468@code{#pragma pack(pop)}.
23469@end enumerate
23470
23471Some targets, e.g.@: x86 and PowerPC, support the @code{#pragma ms_struct}
23472directive which lays out structures and unions subsequently defined as the
23473documented @code{__attribute__ ((ms_struct))}.
23474
23475@enumerate
23476@item @code{#pragma ms_struct on} turns on the Microsoft layout.
23477@item @code{#pragma ms_struct off} turns off the Microsoft layout.
23478@item @code{#pragma ms_struct reset} goes back to the default layout.
23479@end enumerate
23480
23481Most targets also support the @code{#pragma scalar_storage_order} directive
23482which lays out structures and unions subsequently defined as the documented
23483@code{__attribute__ ((scalar_storage_order))}.
23484
23485@enumerate
23486@item @code{#pragma scalar_storage_order big-endian} sets the storage order
23487of the scalar fields to big-endian.
23488@item @code{#pragma scalar_storage_order little-endian} sets the storage order
23489of the scalar fields to little-endian.
23490@item @code{#pragma scalar_storage_order default} goes back to the endianness
23491that was in effect when compilation started (see also command-line option
23492@option{-fsso-struct=@var{endianness}} @pxref{C Dialect Options}).
23493@end enumerate
23494
23495@node Weak Pragmas
23496@subsection Weak Pragmas
23497
23498For compatibility with SVR4, GCC supports a set of @code{#pragma}
23499directives for declaring symbols to be weak, and defining weak
23500aliases.
23501
23502@table @code
23503@item #pragma weak @var{symbol}
23504@cindex pragma, weak
23505This pragma declares @var{symbol} to be weak, as if the declaration
23506had the attribute of the same name.  The pragma may appear before
23507or after the declaration of @var{symbol}.  It is not an error for
23508@var{symbol} to never be defined at all.
23509
23510@item #pragma weak @var{symbol1} = @var{symbol2}
23511This pragma declares @var{symbol1} to be a weak alias of @var{symbol2}.
23512It is an error if @var{symbol2} is not defined in the current
23513translation unit.
23514@end table
23515
23516@node Diagnostic Pragmas
23517@subsection Diagnostic Pragmas
23518
23519GCC allows the user to selectively enable or disable certain types of
23520diagnostics, and change the kind of the diagnostic.  For example, a
23521project's policy might require that all sources compile with
23522@option{-Werror} but certain files might have exceptions allowing
23523specific types of warnings.  Or, a project might selectively enable
23524diagnostics and treat them as errors depending on which preprocessor
23525macros are defined.
23526
23527@table @code
23528@item #pragma GCC diagnostic @var{kind} @var{option}
23529@cindex pragma, diagnostic
23530
23531Modifies the disposition of a diagnostic.  Note that not all
23532diagnostics are modifiable; at the moment only warnings (normally
23533controlled by @samp{-W@dots{}}) can be controlled, and not all of them.
23534Use @option{-fdiagnostics-show-option} to determine which diagnostics
23535are controllable and which option controls them.
23536
23537@var{kind} is @samp{error} to treat this diagnostic as an error,
23538@samp{warning} to treat it like a warning (even if @option{-Werror} is
23539in effect), or @samp{ignored} if the diagnostic is to be ignored.
23540@var{option} is a double quoted string that matches the command-line
23541option.
23542
23543@smallexample
23544#pragma GCC diagnostic warning "-Wformat"
23545#pragma GCC diagnostic error "-Wformat"
23546#pragma GCC diagnostic ignored "-Wformat"
23547@end smallexample
23548
23549Note that these pragmas override any command-line options.  GCC keeps
23550track of the location of each pragma, and issues diagnostics according
23551to the state as of that point in the source file.  Thus, pragmas occurring
23552after a line do not affect diagnostics caused by that line.
23553
23554@item #pragma GCC diagnostic push
23555@itemx #pragma GCC diagnostic pop
23556
23557Causes GCC to remember the state of the diagnostics as of each
23558@code{push}, and restore to that point at each @code{pop}.  If a
23559@code{pop} has no matching @code{push}, the command-line options are
23560restored.
23561
23562@smallexample
23563#pragma GCC diagnostic error "-Wuninitialized"
23564  foo(a);                       /* error is given for this one */
23565#pragma GCC diagnostic push
23566#pragma GCC diagnostic ignored "-Wuninitialized"
23567  foo(b);                       /* no diagnostic for this one */
23568#pragma GCC diagnostic pop
23569  foo(c);                       /* error is given for this one */
23570#pragma GCC diagnostic pop
23571  foo(d);                       /* depends on command-line options */
23572@end smallexample
23573
23574@end table
23575
23576GCC also offers a simple mechanism for printing messages during
23577compilation.
23578
23579@table @code
23580@item #pragma message @var{string}
23581@cindex pragma, diagnostic
23582
23583Prints @var{string} as a compiler message on compilation.  The message
23584is informational only, and is neither a compilation warning nor an
23585error.  Newlines can be included in the string by using the @samp{\n}
23586escape sequence.
23587
23588@smallexample
23589#pragma message "Compiling " __FILE__ "..."
23590@end smallexample
23591
23592@var{string} may be parenthesized, and is printed with location
23593information.  For example,
23594
23595@smallexample
23596#define DO_PRAGMA(x) _Pragma (#x)
23597#define TODO(x) DO_PRAGMA(message ("TODO - " #x))
23598
23599TODO(Remember to fix this)
23600@end smallexample
23601
23602@noindent
23603prints @samp{/tmp/file.c:4: note: #pragma message:
23604TODO - Remember to fix this}.
23605
23606@item #pragma GCC error @var{message}
23607@cindex pragma, diagnostic
23608Generates an error message.  This pragma @emph{is} considered to
23609indicate an error in the compilation, and it will be treated as such.
23610
23611Newlines can be included in the string by using the @samp{\n}
23612escape sequence.  They will be displayed as newlines even if the
23613@option{-fmessage-length} option is set to zero.
23614
23615The error is only generated if the pragma is present in the code after
23616pre-processing has been completed.  It does not matter however if the
23617code containing the pragma is unreachable:
23618
23619@smallexample
23620#if 0
23621#pragma GCC error "this error is not seen"
23622#endif
23623void foo (void)
23624@{
23625  return;
23626#pragma GCC error "this error is seen"
23627@}
23628@end smallexample
23629
23630@item #pragma GCC warning @var{message}
23631@cindex pragma, diagnostic
23632This is just like @samp{pragma GCC error} except that a warning
23633message is issued instead of an error message.  Unless
23634@option{-Werror} is in effect, in which case this pragma will generate
23635an error as well.
23636
23637@end table
23638
23639@node Visibility Pragmas
23640@subsection Visibility Pragmas
23641
23642@table @code
23643@item #pragma GCC visibility push(@var{visibility})
23644@itemx #pragma GCC visibility pop
23645@cindex pragma, visibility
23646
23647This pragma allows the user to set the visibility for multiple
23648declarations without having to give each a visibility attribute
23649(@pxref{Function Attributes}).
23650
23651In C++, @samp{#pragma GCC visibility} affects only namespace-scope
23652declarations.  Class members and template specializations are not
23653affected; if you want to override the visibility for a particular
23654member or instantiation, you must use an attribute.
23655
23656@end table
23657
23658
23659@node Push/Pop Macro Pragmas
23660@subsection Push/Pop Macro Pragmas
23661
23662For compatibility with Microsoft Windows compilers, GCC supports
23663@samp{#pragma push_macro(@var{"macro_name"})}
23664and @samp{#pragma pop_macro(@var{"macro_name"})}.
23665
23666@table @code
23667@item #pragma push_macro(@var{"macro_name"})
23668@cindex pragma, push_macro
23669This pragma saves the value of the macro named as @var{macro_name} to
23670the top of the stack for this macro.
23671
23672@item #pragma pop_macro(@var{"macro_name"})
23673@cindex pragma, pop_macro
23674This pragma sets the value of the macro named as @var{macro_name} to
23675the value on top of the stack for this macro. If the stack for
23676@var{macro_name} is empty, the value of the macro remains unchanged.
23677@end table
23678
23679For example:
23680
23681@smallexample
23682#define X  1
23683#pragma push_macro("X")
23684#undef X
23685#define X -1
23686#pragma pop_macro("X")
23687int x [X];
23688@end smallexample
23689
23690@noindent
23691In this example, the definition of X as 1 is saved by @code{#pragma
23692push_macro} and restored by @code{#pragma pop_macro}.
23693
23694@node Function Specific Option Pragmas
23695@subsection Function Specific Option Pragmas
23696
23697@table @code
23698@item #pragma GCC target (@var{string}, @dots{})
23699@cindex pragma GCC target
23700
23701This pragma allows you to set target-specific options for functions
23702defined later in the source file.  One or more strings can be
23703specified.  Each function that is defined after this point is treated
23704as if it had been declared with one @code{target(}@var{string}@code{)}
23705attribute for each @var{string} argument.  The parentheses around
23706the strings in the pragma are optional.  @xref{Function Attributes},
23707for more information about the @code{target} attribute and the attribute
23708syntax.
23709
23710The @code{#pragma GCC target} pragma is presently implemented for
23711x86, ARM, AArch64, PowerPC, S/390, and Nios II targets only.
23712
23713@item #pragma GCC optimize (@var{string}, @dots{})
23714@cindex pragma GCC optimize
23715
23716This pragma allows you to set global optimization options for functions
23717defined later in the source file.  One or more strings can be
23718specified.  Each function that is defined after this point is treated
23719as if it had been declared with one @code{optimize(}@var{string}@code{)}
23720attribute for each @var{string} argument.  The parentheses around
23721the strings in the pragma are optional.  @xref{Function Attributes},
23722for more information about the @code{optimize} attribute and the attribute
23723syntax.
23724
23725@item #pragma GCC push_options
23726@itemx #pragma GCC pop_options
23727@cindex pragma GCC push_options
23728@cindex pragma GCC pop_options
23729
23730These pragmas maintain a stack of the current target and optimization
23731options.  It is intended for include files where you temporarily want
23732to switch to using a different @samp{#pragma GCC target} or
23733@samp{#pragma GCC optimize} and then to pop back to the previous
23734options.
23735
23736@item #pragma GCC reset_options
23737@cindex pragma GCC reset_options
23738
23739This pragma clears the current @code{#pragma GCC target} and
23740@code{#pragma GCC optimize} to use the default switches as specified
23741on the command line.
23742
23743@end table
23744
23745@node Loop-Specific Pragmas
23746@subsection Loop-Specific Pragmas
23747
23748@table @code
23749@item #pragma GCC ivdep
23750@cindex pragma GCC ivdep
23751
23752With this pragma, the programmer asserts that there are no loop-carried
23753dependencies which would prevent consecutive iterations of
23754the following loop from executing concurrently with SIMD
23755(single instruction multiple data) instructions.
23756
23757For example, the compiler can only unconditionally vectorize the following
23758loop with the pragma:
23759
23760@smallexample
23761void foo (int n, int *a, int *b, int *c)
23762@{
23763  int i, j;
23764#pragma GCC ivdep
23765  for (i = 0; i < n; ++i)
23766    a[i] = b[i] + c[i];
23767@}
23768@end smallexample
23769
23770@noindent
23771In this example, using the @code{restrict} qualifier had the same
23772effect. In the following example, that would not be possible. Assume
23773@math{k < -m} or @math{k >= m}. Only with the pragma, the compiler knows
23774that it can unconditionally vectorize the following loop:
23775
23776@smallexample
23777void ignore_vec_dep (int *a, int k, int c, int m)
23778@{
23779#pragma GCC ivdep
23780  for (int i = 0; i < m; i++)
23781    a[i] = a[i + k] * c;
23782@}
23783@end smallexample
23784
23785@item #pragma GCC unroll @var{n}
23786@cindex pragma GCC unroll @var{n}
23787
23788You can use this pragma to control how many times a loop should be unrolled.
23789It must be placed immediately before a @code{for}, @code{while} or @code{do}
23790loop or a @code{#pragma GCC ivdep}, and applies only to the loop that follows.
23791@var{n} is an integer constant expression specifying the unrolling factor.
23792The values of @math{0} and @math{1} block any unrolling of the loop.
23793
23794@end table
23795
23796@node Unnamed Fields
23797@section Unnamed Structure and Union Fields
23798@cindex @code{struct}
23799@cindex @code{union}
23800
23801As permitted by ISO C11 and for compatibility with other compilers,
23802GCC allows you to define
23803a structure or union that contains, as fields, structures and unions
23804without names.  For example:
23805
23806@smallexample
23807struct @{
23808  int a;
23809  union @{
23810    int b;
23811    float c;
23812  @};
23813  int d;
23814@} foo;
23815@end smallexample
23816
23817@noindent
23818In this example, you are able to access members of the unnamed
23819union with code like @samp{foo.b}.  Note that only unnamed structs and
23820unions are allowed, you may not have, for example, an unnamed
23821@code{int}.
23822
23823You must never create such structures that cause ambiguous field definitions.
23824For example, in this structure:
23825
23826@smallexample
23827struct @{
23828  int a;
23829  struct @{
23830    int a;
23831  @};
23832@} foo;
23833@end smallexample
23834
23835@noindent
23836it is ambiguous which @code{a} is being referred to with @samp{foo.a}.
23837The compiler gives errors for such constructs.
23838
23839@opindex fms-extensions
23840Unless @option{-fms-extensions} is used, the unnamed field must be a
23841structure or union definition without a tag (for example, @samp{struct
23842@{ int a; @};}).  If @option{-fms-extensions} is used, the field may
23843also be a definition with a tag such as @samp{struct foo @{ int a;
23844@};}, a reference to a previously defined structure or union such as
23845@samp{struct foo;}, or a reference to a @code{typedef} name for a
23846previously defined structure or union type.
23847
23848@opindex fplan9-extensions
23849The option @option{-fplan9-extensions} enables
23850@option{-fms-extensions} as well as two other extensions.  First, a
23851pointer to a structure is automatically converted to a pointer to an
23852anonymous field for assignments and function calls.  For example:
23853
23854@smallexample
23855struct s1 @{ int a; @};
23856struct s2 @{ struct s1; @};
23857extern void f1 (struct s1 *);
23858void f2 (struct s2 *p) @{ f1 (p); @}
23859@end smallexample
23860
23861@noindent
23862In the call to @code{f1} inside @code{f2}, the pointer @code{p} is
23863converted into a pointer to the anonymous field.
23864
23865Second, when the type of an anonymous field is a @code{typedef} for a
23866@code{struct} or @code{union}, code may refer to the field using the
23867name of the @code{typedef}.
23868
23869@smallexample
23870typedef struct @{ int a; @} s1;
23871struct s2 @{ s1; @};
23872s1 f1 (struct s2 *p) @{ return p->s1; @}
23873@end smallexample
23874
23875These usages are only permitted when they are not ambiguous.
23876
23877@node Thread-Local
23878@section Thread-Local Storage
23879@cindex Thread-Local Storage
23880@cindex @acronym{TLS}
23881@cindex @code{__thread}
23882
23883Thread-local storage (@acronym{TLS}) is a mechanism by which variables
23884are allocated such that there is one instance of the variable per extant
23885thread.  The runtime model GCC uses to implement this originates
23886in the IA-64 processor-specific ABI, but has since been migrated
23887to other processors as well.  It requires significant support from
23888the linker (@command{ld}), dynamic linker (@command{ld.so}), and
23889system libraries (@file{libc.so} and @file{libpthread.so}), so it
23890is not available everywhere.
23891
23892At the user level, the extension is visible with a new storage
23893class keyword: @code{__thread}.  For example:
23894
23895@smallexample
23896__thread int i;
23897extern __thread struct state s;
23898static __thread char *p;
23899@end smallexample
23900
23901The @code{__thread} specifier may be used alone, with the @code{extern}
23902or @code{static} specifiers, but with no other storage class specifier.
23903When used with @code{extern} or @code{static}, @code{__thread} must appear
23904immediately after the other storage class specifier.
23905
23906The @code{__thread} specifier may be applied to any global, file-scoped
23907static, function-scoped static, or static data member of a class.  It may
23908not be applied to block-scoped automatic or non-static data member.
23909
23910When the address-of operator is applied to a thread-local variable, it is
23911evaluated at run time and returns the address of the current thread's
23912instance of that variable.  An address so obtained may be used by any
23913thread.  When a thread terminates, any pointers to thread-local variables
23914in that thread become invalid.
23915
23916No static initialization may refer to the address of a thread-local variable.
23917
23918In C++, if an initializer is present for a thread-local variable, it must
23919be a @var{constant-expression}, as defined in 5.19.2 of the ANSI/ISO C++
23920standard.
23921
23922See @uref{https://www.akkadia.org/drepper/tls.pdf,
23923ELF Handling For Thread-Local Storage} for a detailed explanation of
23924the four thread-local storage addressing models, and how the runtime
23925is expected to function.
23926
23927@menu
23928* C99 Thread-Local Edits::
23929* C++98 Thread-Local Edits::
23930@end menu
23931
23932@node C99 Thread-Local Edits
23933@subsection ISO/IEC 9899:1999 Edits for Thread-Local Storage
23934
23935The following are a set of changes to ISO/IEC 9899:1999 (aka C99)
23936that document the exact semantics of the language extension.
23937
23938@itemize @bullet
23939@item
23940@cite{5.1.2  Execution environments}
23941
23942Add new text after paragraph 1
23943
23944@quotation
23945Within either execution environment, a @dfn{thread} is a flow of
23946control within a program.  It is implementation defined whether
23947or not there may be more than one thread associated with a program.
23948It is implementation defined how threads beyond the first are
23949created, the name and type of the function called at thread
23950startup, and how threads may be terminated.  However, objects
23951with thread storage duration shall be initialized before thread
23952startup.
23953@end quotation
23954
23955@item
23956@cite{6.2.4  Storage durations of objects}
23957
23958Add new text before paragraph 3
23959
23960@quotation
23961An object whose identifier is declared with the storage-class
23962specifier @w{@code{__thread}} has @dfn{thread storage duration}.
23963Its lifetime is the entire execution of the thread, and its
23964stored value is initialized only once, prior to thread startup.
23965@end quotation
23966
23967@item
23968@cite{6.4.1  Keywords}
23969
23970Add @code{__thread}.
23971
23972@item
23973@cite{6.7.1  Storage-class specifiers}
23974
23975Add @code{__thread} to the list of storage class specifiers in
23976paragraph 1.
23977
23978Change paragraph 2 to
23979
23980@quotation
23981With the exception of @code{__thread}, at most one storage-class
23982specifier may be given [@dots{}].  The @code{__thread} specifier may
23983be used alone, or immediately following @code{extern} or
23984@code{static}.
23985@end quotation
23986
23987Add new text after paragraph 6
23988
23989@quotation
23990The declaration of an identifier for a variable that has
23991block scope that specifies @code{__thread} shall also
23992specify either @code{extern} or @code{static}.
23993
23994The @code{__thread} specifier shall be used only with
23995variables.
23996@end quotation
23997@end itemize
23998
23999@node C++98 Thread-Local Edits
24000@subsection ISO/IEC 14882:1998 Edits for Thread-Local Storage
24001
24002The following are a set of changes to ISO/IEC 14882:1998 (aka C++98)
24003that document the exact semantics of the language extension.
24004
24005@itemize @bullet
24006@item
24007@b{[intro.execution]}
24008
24009New text after paragraph 4
24010
24011@quotation
24012A @dfn{thread} is a flow of control within the abstract machine.
24013It is implementation defined whether or not there may be more than
24014one thread.
24015@end quotation
24016
24017New text after paragraph 7
24018
24019@quotation
24020It is unspecified whether additional action must be taken to
24021ensure when and whether side effects are visible to other threads.
24022@end quotation
24023
24024@item
24025@b{[lex.key]}
24026
24027Add @code{__thread}.
24028
24029@item
24030@b{[basic.start.main]}
24031
24032Add after paragraph 5
24033
24034@quotation
24035The thread that begins execution at the @code{main} function is called
24036the @dfn{main thread}.  It is implementation defined how functions
24037beginning threads other than the main thread are designated or typed.
24038A function so designated, as well as the @code{main} function, is called
24039a @dfn{thread startup function}.  It is implementation defined what
24040happens if a thread startup function returns.  It is implementation
24041defined what happens to other threads when any thread calls @code{exit}.
24042@end quotation
24043
24044@item
24045@b{[basic.start.init]}
24046
24047Add after paragraph 4
24048
24049@quotation
24050The storage for an object of thread storage duration shall be
24051statically initialized before the first statement of the thread startup
24052function.  An object of thread storage duration shall not require
24053dynamic initialization.
24054@end quotation
24055
24056@item
24057@b{[basic.start.term]}
24058
24059Add after paragraph 3
24060
24061@quotation
24062The type of an object with thread storage duration shall not have a
24063non-trivial destructor, nor shall it be an array type whose elements
24064(directly or indirectly) have non-trivial destructors.
24065@end quotation
24066
24067@item
24068@b{[basic.stc]}
24069
24070Add ``thread storage duration'' to the list in paragraph 1.
24071
24072Change paragraph 2
24073
24074@quotation
24075Thread, static, and automatic storage durations are associated with
24076objects introduced by declarations [@dots{}].
24077@end quotation
24078
24079Add @code{__thread} to the list of specifiers in paragraph 3.
24080
24081@item
24082@b{[basic.stc.thread]}
24083
24084New section before @b{[basic.stc.static]}
24085
24086@quotation
24087The keyword @code{__thread} applied to a non-local object gives the
24088object thread storage duration.
24089
24090A local variable or class data member declared both @code{static}
24091and @code{__thread} gives the variable or member thread storage
24092duration.
24093@end quotation
24094
24095@item
24096@b{[basic.stc.static]}
24097
24098Change paragraph 1
24099
24100@quotation
24101All objects that have neither thread storage duration, dynamic
24102storage duration nor are local [@dots{}].
24103@end quotation
24104
24105@item
24106@b{[dcl.stc]}
24107
24108Add @code{__thread} to the list in paragraph 1.
24109
24110Change paragraph 1
24111
24112@quotation
24113With the exception of @code{__thread}, at most one
24114@var{storage-class-specifier} shall appear in a given
24115@var{decl-specifier-seq}.  The @code{__thread} specifier may
24116be used alone, or immediately following the @code{extern} or
24117@code{static} specifiers.  [@dots{}]
24118@end quotation
24119
24120Add after paragraph 5
24121
24122@quotation
24123The @code{__thread} specifier can be applied only to the names of objects
24124and to anonymous unions.
24125@end quotation
24126
24127@item
24128@b{[class.mem]}
24129
24130Add after paragraph 6
24131
24132@quotation
24133Non-@code{static} members shall not be @code{__thread}.
24134@end quotation
24135@end itemize
24136
24137@node Binary constants
24138@section Binary Constants using the @samp{0b} Prefix
24139@cindex Binary constants using the @samp{0b} prefix
24140
24141Integer constants can be written as binary constants, consisting of a
24142sequence of @samp{0} and @samp{1} digits, prefixed by @samp{0b} or
24143@samp{0B}.  This is particularly useful in environments that operate a
24144lot on the bit level (like microcontrollers).
24145
24146The following statements are identical:
24147
24148@smallexample
24149i =       42;
24150i =     0x2a;
24151i =      052;
24152i = 0b101010;
24153@end smallexample
24154
24155The type of these constants follows the same rules as for octal or
24156hexadecimal integer constants, so suffixes like @samp{L} or @samp{UL}
24157can be applied.
24158
24159@node C++ Extensions
24160@chapter Extensions to the C++ Language
24161@cindex extensions, C++ language
24162@cindex C++ language extensions
24163
24164The GNU compiler provides these extensions to the C++ language (and you
24165can also use most of the C language extensions in your C++ programs).  If you
24166want to write code that checks whether these features are available, you can
24167test for the GNU compiler the same way as for C programs: check for a
24168predefined macro @code{__GNUC__}.  You can also use @code{__GNUG__} to
24169test specifically for GNU C++ (@pxref{Common Predefined Macros,,
24170Predefined Macros,cpp,The GNU C Preprocessor}).
24171
24172@menu
24173* C++ Volatiles::       What constitutes an access to a volatile object.
24174* Restricted Pointers:: C99 restricted pointers and references.
24175* Vague Linkage::       Where G++ puts inlines, vtables and such.
24176* C++ Interface::       You can use a single C++ header file for both
24177                        declarations and definitions.
24178* Template Instantiation:: Methods for ensuring that exactly one copy of
24179                        each needed template instantiation is emitted.
24180* Bound member functions:: You can extract a function pointer to the
24181                        method denoted by a @samp{->*} or @samp{.*} expression.
24182* C++ Attributes::      Variable, function, and type attributes for C++ only.
24183* Function Multiversioning::   Declaring multiple function versions.
24184* Type Traits::         Compiler support for type traits.
24185* C++ Concepts::        Improved support for generic programming.
24186* Deprecated Features:: Things will disappear from G++.
24187* Backwards Compatibility:: Compatibilities with earlier definitions of C++.
24188@end menu
24189
24190@node C++ Volatiles
24191@section When is a Volatile C++ Object Accessed?
24192@cindex accessing volatiles
24193@cindex volatile read
24194@cindex volatile write
24195@cindex volatile access
24196
24197The C++ standard differs from the C standard in its treatment of
24198volatile objects.  It fails to specify what constitutes a volatile
24199access, except to say that C++ should behave in a similar manner to C
24200with respect to volatiles, where possible.  However, the different
24201lvalueness of expressions between C and C++ complicate the behavior.
24202G++ behaves the same as GCC for volatile access, @xref{C
24203Extensions,,Volatiles}, for a description of GCC's behavior.
24204
24205The C and C++ language specifications differ when an object is
24206accessed in a void context:
24207
24208@smallexample
24209volatile int *src = @var{somevalue};
24210*src;
24211@end smallexample
24212
24213The C++ standard specifies that such expressions do not undergo lvalue
24214to rvalue conversion, and that the type of the dereferenced object may
24215be incomplete.  The C++ standard does not specify explicitly that it
24216is lvalue to rvalue conversion that is responsible for causing an
24217access.  There is reason to believe that it is, because otherwise
24218certain simple expressions become undefined.  However, because it
24219would surprise most programmers, G++ treats dereferencing a pointer to
24220volatile object of complete type as GCC would do for an equivalent
24221type in C@.  When the object has incomplete type, G++ issues a
24222warning; if you wish to force an error, you must force a conversion to
24223rvalue with, for instance, a static cast.
24224
24225When using a reference to volatile, G++ does not treat equivalent
24226expressions as accesses to volatiles, but instead issues a warning that
24227no volatile is accessed.  The rationale for this is that otherwise it
24228becomes difficult to determine where volatile access occur, and not
24229possible to ignore the return value from functions returning volatile
24230references.  Again, if you wish to force a read, cast the reference to
24231an rvalue.
24232
24233G++ implements the same behavior as GCC does when assigning to a
24234volatile object---there is no reread of the assigned-to object, the
24235assigned rvalue is reused.  Note that in C++ assignment expressions
24236are lvalues, and if used as an lvalue, the volatile object is
24237referred to.  For instance, @var{vref} refers to @var{vobj}, as
24238expected, in the following example:
24239
24240@smallexample
24241volatile int vobj;
24242volatile int &vref = vobj = @var{something};
24243@end smallexample
24244
24245@node Restricted Pointers
24246@section Restricting Pointer Aliasing
24247@cindex restricted pointers
24248@cindex restricted references
24249@cindex restricted this pointer
24250
24251As with the C front end, G++ understands the C99 feature of restricted pointers,
24252specified with the @code{__restrict__}, or @code{__restrict} type
24253qualifier.  Because you cannot compile C++ by specifying the @option{-std=c99}
24254language flag, @code{restrict} is not a keyword in C++.
24255
24256In addition to allowing restricted pointers, you can specify restricted
24257references, which indicate that the reference is not aliased in the local
24258context.
24259
24260@smallexample
24261void fn (int *__restrict__ rptr, int &__restrict__ rref)
24262@{
24263  /* @r{@dots{}} */
24264@}
24265@end smallexample
24266
24267@noindent
24268In the body of @code{fn}, @var{rptr} points to an unaliased integer and
24269@var{rref} refers to a (different) unaliased integer.
24270
24271You may also specify whether a member function's @var{this} pointer is
24272unaliased by using @code{__restrict__} as a member function qualifier.
24273
24274@smallexample
24275void T::fn () __restrict__
24276@{
24277  /* @r{@dots{}} */
24278@}
24279@end smallexample
24280
24281@noindent
24282Within the body of @code{T::fn}, @var{this} has the effective
24283definition @code{T *__restrict__ const this}.  Notice that the
24284interpretation of a @code{__restrict__} member function qualifier is
24285different to that of @code{const} or @code{volatile} qualifier, in that it
24286is applied to the pointer rather than the object.  This is consistent with
24287other compilers that implement restricted pointers.
24288
24289As with all outermost parameter qualifiers, @code{__restrict__} is
24290ignored in function definition matching.  This means you only need to
24291specify @code{__restrict__} in a function definition, rather than
24292in a function prototype as well.
24293
24294@node Vague Linkage
24295@section Vague Linkage
24296@cindex vague linkage
24297
24298There are several constructs in C++ that require space in the object
24299file but are not clearly tied to a single translation unit.  We say that
24300these constructs have ``vague linkage''.  Typically such constructs are
24301emitted wherever they are needed, though sometimes we can be more
24302clever.
24303
24304@table @asis
24305@item Inline Functions
24306Inline functions are typically defined in a header file which can be
24307included in many different compilations.  Hopefully they can usually be
24308inlined, but sometimes an out-of-line copy is necessary, if the address
24309of the function is taken or if inlining fails.  In general, we emit an
24310out-of-line copy in all translation units where one is needed.  As an
24311exception, we only emit inline virtual functions with the vtable, since
24312it always requires a copy.
24313
24314Local static variables and string constants used in an inline function
24315are also considered to have vague linkage, since they must be shared
24316between all inlined and out-of-line instances of the function.
24317
24318@item VTables
24319@cindex vtable
24320C++ virtual functions are implemented in most compilers using a lookup
24321table, known as a vtable.  The vtable contains pointers to the virtual
24322functions provided by a class, and each object of the class contains a
24323pointer to its vtable (or vtables, in some multiple-inheritance
24324situations).  If the class declares any non-inline, non-pure virtual
24325functions, the first one is chosen as the ``key method'' for the class,
24326and the vtable is only emitted in the translation unit where the key
24327method is defined.
24328
24329@emph{Note:} If the chosen key method is later defined as inline, the
24330vtable is still emitted in every translation unit that defines it.
24331Make sure that any inline virtuals are declared inline in the class
24332body, even if they are not defined there.
24333
24334@item @code{type_info} objects
24335@cindex @code{type_info}
24336@cindex RTTI
24337C++ requires information about types to be written out in order to
24338implement @samp{dynamic_cast}, @samp{typeid} and exception handling.
24339For polymorphic classes (classes with virtual functions), the @samp{type_info}
24340object is written out along with the vtable so that @samp{dynamic_cast}
24341can determine the dynamic type of a class object at run time.  For all
24342other types, we write out the @samp{type_info} object when it is used: when
24343applying @samp{typeid} to an expression, throwing an object, or
24344referring to a type in a catch clause or exception specification.
24345
24346@item Template Instantiations
24347Most everything in this section also applies to template instantiations,
24348but there are other options as well.
24349@xref{Template Instantiation,,Where's the Template?}.
24350
24351@end table
24352
24353When used with GNU ld version 2.8 or later on an ELF system such as
24354GNU/Linux or Solaris 2, or on Microsoft Windows, duplicate copies of
24355these constructs will be discarded at link time.  This is known as
24356COMDAT support.
24357
24358On targets that don't support COMDAT, but do support weak symbols, GCC
24359uses them.  This way one copy overrides all the others, but
24360the unused copies still take up space in the executable.
24361
24362For targets that do not support either COMDAT or weak symbols,
24363most entities with vague linkage are emitted as local symbols to
24364avoid duplicate definition errors from the linker.  This does not happen
24365for local statics in inlines, however, as having multiple copies
24366almost certainly breaks things.
24367
24368@xref{C++ Interface,,Declarations and Definitions in One Header}, for
24369another way to control placement of these constructs.
24370
24371@node C++ Interface
24372@section C++ Interface and Implementation Pragmas
24373
24374@cindex interface and implementation headers, C++
24375@cindex C++ interface and implementation headers
24376@cindex pragmas, interface and implementation
24377
24378@code{#pragma interface} and @code{#pragma implementation} provide the
24379user with a way of explicitly directing the compiler to emit entities
24380with vague linkage (and debugging information) in a particular
24381translation unit.
24382
24383@emph{Note:} These @code{#pragma}s have been superceded as of GCC 2.7.2
24384by COMDAT support and the ``key method'' heuristic
24385mentioned in @ref{Vague Linkage}.  Using them can actually cause your
24386program to grow due to unnecessary out-of-line copies of inline
24387functions.
24388
24389@table @code
24390@item #pragma interface
24391@itemx #pragma interface "@var{subdir}/@var{objects}.h"
24392@kindex #pragma interface
24393Use this directive in @emph{header files} that define object classes, to save
24394space in most of the object files that use those classes.  Normally,
24395local copies of certain information (backup copies of inline member
24396functions, debugging information, and the internal tables that implement
24397virtual functions) must be kept in each object file that includes class
24398definitions.  You can use this pragma to avoid such duplication.  When a
24399header file containing @samp{#pragma interface} is included in a
24400compilation, this auxiliary information is not generated (unless
24401the main input source file itself uses @samp{#pragma implementation}).
24402Instead, the object files contain references to be resolved at link
24403time.
24404
24405The second form of this directive is useful for the case where you have
24406multiple headers with the same name in different directories.  If you
24407use this form, you must specify the same string to @samp{#pragma
24408implementation}.
24409
24410@item #pragma implementation
24411@itemx #pragma implementation "@var{objects}.h"
24412@kindex #pragma implementation
24413Use this pragma in a @emph{main input file}, when you want full output from
24414included header files to be generated (and made globally visible).  The
24415included header file, in turn, should use @samp{#pragma interface}.
24416Backup copies of inline member functions, debugging information, and the
24417internal tables used to implement virtual functions are all generated in
24418implementation files.
24419
24420@cindex implied @code{#pragma implementation}
24421@cindex @code{#pragma implementation}, implied
24422@cindex naming convention, implementation headers
24423If you use @samp{#pragma implementation} with no argument, it applies to
24424an include file with the same basename@footnote{A file's @dfn{basename}
24425is the name stripped of all leading path information and of trailing
24426suffixes, such as @samp{.h} or @samp{.C} or @samp{.cc}.} as your source
24427file.  For example, in @file{allclass.cc}, giving just
24428@samp{#pragma implementation}
24429by itself is equivalent to @samp{#pragma implementation "allclass.h"}.
24430
24431Use the string argument if you want a single implementation file to
24432include code from multiple header files.  (You must also use
24433@samp{#include} to include the header file; @samp{#pragma
24434implementation} only specifies how to use the file---it doesn't actually
24435include it.)
24436
24437There is no way to split up the contents of a single header file into
24438multiple implementation files.
24439@end table
24440
24441@cindex inlining and C++ pragmas
24442@cindex C++ pragmas, effect on inlining
24443@cindex pragmas in C++, effect on inlining
24444@samp{#pragma implementation} and @samp{#pragma interface} also have an
24445effect on function inlining.
24446
24447If you define a class in a header file marked with @samp{#pragma
24448interface}, the effect on an inline function defined in that class is
24449similar to an explicit @code{extern} declaration---the compiler emits
24450no code at all to define an independent version of the function.  Its
24451definition is used only for inlining with its callers.
24452
24453@opindex fno-implement-inlines
24454Conversely, when you include the same header file in a main source file
24455that declares it as @samp{#pragma implementation}, the compiler emits
24456code for the function itself; this defines a version of the function
24457that can be found via pointers (or by callers compiled without
24458inlining).  If all calls to the function can be inlined, you can avoid
24459emitting the function by compiling with @option{-fno-implement-inlines}.
24460If any calls are not inlined, you will get linker errors.
24461
24462@node Template Instantiation
24463@section Where's the Template?
24464@cindex template instantiation
24465
24466C++ templates were the first language feature to require more
24467intelligence from the environment than was traditionally found on a UNIX
24468system.  Somehow the compiler and linker have to make sure that each
24469template instance occurs exactly once in the executable if it is needed,
24470and not at all otherwise.  There are two basic approaches to this
24471problem, which are referred to as the Borland model and the Cfront model.
24472
24473@table @asis
24474@item Borland model
24475Borland C++ solved the template instantiation problem by adding the code
24476equivalent of common blocks to their linker; the compiler emits template
24477instances in each translation unit that uses them, and the linker
24478collapses them together.  The advantage of this model is that the linker
24479only has to consider the object files themselves; there is no external
24480complexity to worry about.  The disadvantage is that compilation time
24481is increased because the template code is being compiled repeatedly.
24482Code written for this model tends to include definitions of all
24483templates in the header file, since they must be seen to be
24484instantiated.
24485
24486@item Cfront model
24487The AT&T C++ translator, Cfront, solved the template instantiation
24488problem by creating the notion of a template repository, an
24489automatically maintained place where template instances are stored.  A
24490more modern version of the repository works as follows: As individual
24491object files are built, the compiler places any template definitions and
24492instantiations encountered in the repository.  At link time, the link
24493wrapper adds in the objects in the repository and compiles any needed
24494instances that were not previously emitted.  The advantages of this
24495model are more optimal compilation speed and the ability to use the
24496system linker; to implement the Borland model a compiler vendor also
24497needs to replace the linker.  The disadvantages are vastly increased
24498complexity, and thus potential for error; for some code this can be
24499just as transparent, but in practice it can been very difficult to build
24500multiple programs in one directory and one program in multiple
24501directories.  Code written for this model tends to separate definitions
24502of non-inline member templates into a separate file, which should be
24503compiled separately.
24504@end table
24505
24506G++ implements the Borland model on targets where the linker supports it,
24507including ELF targets (such as GNU/Linux), Mac OS X and Microsoft Windows.
24508Otherwise G++ implements neither automatic model.
24509
24510You have the following options for dealing with template instantiations:
24511
24512@enumerate
24513@item
24514Do nothing.  Code written for the Borland model works fine, but
24515each translation unit contains instances of each of the templates it
24516uses.  The duplicate instances will be discarded by the linker, but in
24517a large program, this can lead to an unacceptable amount of code
24518duplication in object files or shared libraries.
24519
24520Duplicate instances of a template can be avoided by defining an explicit
24521instantiation in one object file, and preventing the compiler from doing
24522implicit instantiations in any other object files by using an explicit
24523instantiation declaration, using the @code{extern template} syntax:
24524
24525@smallexample
24526extern template int max (int, int);
24527@end smallexample
24528
24529This syntax is defined in the C++ 2011 standard, but has been supported by
24530G++ and other compilers since well before 2011.
24531
24532Explicit instantiations can be used for the largest or most frequently
24533duplicated instances, without having to know exactly which other instances
24534are used in the rest of the program.  You can scatter the explicit
24535instantiations throughout your program, perhaps putting them in the
24536translation units where the instances are used or the translation units
24537that define the templates themselves; you can put all of the explicit
24538instantiations you need into one big file; or you can create small files
24539like
24540
24541@smallexample
24542#include "Foo.h"
24543#include "Foo.cc"
24544
24545template class Foo<int>;
24546template ostream& operator <<
24547                (ostream&, const Foo<int>&);
24548@end smallexample
24549
24550@noindent
24551for each of the instances you need, and create a template instantiation
24552library from those.
24553
24554This is the simplest option, but also offers flexibility and
24555fine-grained control when necessary. It is also the most portable
24556alternative and programs using this approach will work with most modern
24557compilers.
24558
24559@item
24560@opindex fno-implicit-templates
24561Compile your code with @option{-fno-implicit-templates} to disable the
24562implicit generation of template instances, and explicitly instantiate
24563all the ones you use.  This approach requires more knowledge of exactly
24564which instances you need than do the others, but it's less
24565mysterious and allows greater control if you want to ensure that only
24566the intended instances are used.
24567
24568If you are using Cfront-model code, you can probably get away with not
24569using @option{-fno-implicit-templates} when compiling files that don't
24570@samp{#include} the member template definitions.
24571
24572If you use one big file to do the instantiations, you may want to
24573compile it without @option{-fno-implicit-templates} so you get all of the
24574instances required by your explicit instantiations (but not by any
24575other files) without having to specify them as well.
24576
24577In addition to forward declaration of explicit instantiations
24578(with @code{extern}), G++ has extended the template instantiation
24579syntax to support instantiation of the compiler support data for a
24580template class (i.e.@: the vtable) without instantiating any of its
24581members (with @code{inline}), and instantiation of only the static data
24582members of a template class, without the support data or member
24583functions (with @code{static}):
24584
24585@smallexample
24586inline template class Foo<int>;
24587static template class Foo<int>;
24588@end smallexample
24589@end enumerate
24590
24591@node Bound member functions
24592@section Extracting the Function Pointer from a Bound Pointer to Member Function
24593@cindex pmf
24594@cindex pointer to member function
24595@cindex bound pointer to member function
24596
24597In C++, pointer to member functions (PMFs) are implemented using a wide
24598pointer of sorts to handle all the possible call mechanisms; the PMF
24599needs to store information about how to adjust the @samp{this} pointer,
24600and if the function pointed to is virtual, where to find the vtable, and
24601where in the vtable to look for the member function.  If you are using
24602PMFs in an inner loop, you should really reconsider that decision.  If
24603that is not an option, you can extract the pointer to the function that
24604would be called for a given object/PMF pair and call it directly inside
24605the inner loop, to save a bit of time.
24606
24607Note that you still pay the penalty for the call through a
24608function pointer; on most modern architectures, such a call defeats the
24609branch prediction features of the CPU@.  This is also true of normal
24610virtual function calls.
24611
24612The syntax for this extension is
24613
24614@smallexample
24615extern A a;
24616extern int (A::*fp)();
24617typedef int (*fptr)(A *);
24618
24619fptr p = (fptr)(a.*fp);
24620@end smallexample
24621
24622For PMF constants (i.e.@: expressions of the form @samp{&Klasse::Member}),
24623no object is needed to obtain the address of the function.  They can be
24624converted to function pointers directly:
24625
24626@smallexample
24627fptr p1 = (fptr)(&A::foo);
24628@end smallexample
24629
24630@opindex Wno-pmf-conversions
24631You must specify @option{-Wno-pmf-conversions} to use this extension.
24632
24633@node C++ Attributes
24634@section C++-Specific Variable, Function, and Type Attributes
24635
24636Some attributes only make sense for C++ programs.
24637
24638@table @code
24639@item abi_tag ("@var{tag}", ...)
24640@cindex @code{abi_tag} function attribute
24641@cindex @code{abi_tag} variable attribute
24642@cindex @code{abi_tag} type attribute
24643The @code{abi_tag} attribute can be applied to a function, variable, or class
24644declaration.  It modifies the mangled name of the entity to
24645incorporate the tag name, in order to distinguish the function or
24646class from an earlier version with a different ABI; perhaps the class
24647has changed size, or the function has a different return type that is
24648not encoded in the mangled name.
24649
24650The attribute can also be applied to an inline namespace, but does not
24651affect the mangled name of the namespace; in this case it is only used
24652for @option{-Wabi-tag} warnings and automatic tagging of functions and
24653variables.  Tagging inline namespaces is generally preferable to
24654tagging individual declarations, but the latter is sometimes
24655necessary, such as when only certain members of a class need to be
24656tagged.
24657
24658The argument can be a list of strings of arbitrary length.  The
24659strings are sorted on output, so the order of the list is
24660unimportant.
24661
24662A redeclaration of an entity must not add new ABI tags,
24663since doing so would change the mangled name.
24664
24665The ABI tags apply to a name, so all instantiations and
24666specializations of a template have the same tags.  The attribute will
24667be ignored if applied to an explicit specialization or instantiation.
24668
24669The @option{-Wabi-tag} flag enables a warning about a class which does
24670not have all the ABI tags used by its subobjects and virtual functions; for users with code
24671that needs to coexist with an earlier ABI, using this option can help
24672to find all affected types that need to be tagged.
24673
24674When a type involving an ABI tag is used as the type of a variable or
24675return type of a function where that tag is not already present in the
24676signature of the function, the tag is automatically applied to the
24677variable or function.  @option{-Wabi-tag} also warns about this
24678situation; this warning can be avoided by explicitly tagging the
24679variable or function or moving it into a tagged inline namespace.
24680
24681@item init_priority (@var{priority})
24682@cindex @code{init_priority} variable attribute
24683
24684In Standard C++, objects defined at namespace scope are guaranteed to be
24685initialized in an order in strict accordance with that of their definitions
24686@emph{in a given translation unit}.  No guarantee is made for initializations
24687across translation units.  However, GNU C++ allows users to control the
24688order of initialization of objects defined at namespace scope with the
24689@code{init_priority} attribute by specifying a relative @var{priority},
24690a constant integral expression currently bounded between 101 and 65535
24691inclusive.  Lower numbers indicate a higher priority.
24692
24693In the following example, @code{A} would normally be created before
24694@code{B}, but the @code{init_priority} attribute reverses that order:
24695
24696@smallexample
24697Some_Class  A  __attribute__ ((init_priority (2000)));
24698Some_Class  B  __attribute__ ((init_priority (543)));
24699@end smallexample
24700
24701@noindent
24702Note that the particular values of @var{priority} do not matter; only their
24703relative ordering.
24704
24705@item warn_unused
24706@cindex @code{warn_unused} type attribute
24707
24708For C++ types with non-trivial constructors and/or destructors it is
24709impossible for the compiler to determine whether a variable of this
24710type is truly unused if it is not referenced. This type attribute
24711informs the compiler that variables of this type should be warned
24712about if they appear to be unused, just like variables of fundamental
24713types.
24714
24715This attribute is appropriate for types which just represent a value,
24716such as @code{std::string}; it is not appropriate for types which
24717control a resource, such as @code{std::lock_guard}.
24718
24719This attribute is also accepted in C, but it is unnecessary because C
24720does not have constructors or destructors.
24721
24722@end table
24723
24724@node Function Multiversioning
24725@section Function Multiversioning
24726@cindex function versions
24727
24728With the GNU C++ front end, for x86 targets, you may specify multiple
24729versions of a function, where each function is specialized for a
24730specific target feature.  At runtime, the appropriate version of the
24731function is automatically executed depending on the characteristics of
24732the execution platform.  Here is an example.
24733
24734@smallexample
24735__attribute__ ((target ("default")))
24736int foo ()
24737@{
24738  // The default version of foo.
24739  return 0;
24740@}
24741
24742__attribute__ ((target ("sse4.2")))
24743int foo ()
24744@{
24745  // foo version for SSE4.2
24746  return 1;
24747@}
24748
24749__attribute__ ((target ("arch=atom")))
24750int foo ()
24751@{
24752  // foo version for the Intel ATOM processor
24753  return 2;
24754@}
24755
24756__attribute__ ((target ("arch=amdfam10")))
24757int foo ()
24758@{
24759  // foo version for the AMD Family 0x10 processors.
24760  return 3;
24761@}
24762
24763int main ()
24764@{
24765  int (*p)() = &foo;
24766  assert ((*p) () == foo ());
24767  return 0;
24768@}
24769@end smallexample
24770
24771In the above example, four versions of function foo are created. The
24772first version of foo with the target attribute "default" is the default
24773version.  This version gets executed when no other target specific
24774version qualifies for execution on a particular platform. A new version
24775of foo is created by using the same function signature but with a
24776different target string.  Function foo is called or a pointer to it is
24777taken just like a regular function.  GCC takes care of doing the
24778dispatching to call the right version at runtime.  Refer to the
24779@uref{http://gcc.gnu.org/wiki/FunctionMultiVersioning, GCC wiki on
24780Function Multiversioning} for more details.
24781
24782@node Type Traits
24783@section Type Traits
24784
24785The C++ front end implements syntactic extensions that allow
24786compile-time determination of
24787various characteristics of a type (or of a
24788pair of types).
24789
24790@table @code
24791@item __has_nothrow_assign (type)
24792If @code{type} is @code{const}-qualified or is a reference type then
24793the trait is @code{false}.  Otherwise if @code{__has_trivial_assign (type)}
24794is @code{true} then the trait is @code{true}, else if @code{type} is
24795a cv-qualified class or union type with copy assignment operators that are
24796known not to throw an exception then the trait is @code{true}, else it is
24797@code{false}.
24798Requires: @code{type} shall be a complete type, (possibly cv-qualified)
24799@code{void}, or an array of unknown bound.
24800
24801@item __has_nothrow_copy (type)
24802If @code{__has_trivial_copy (type)} is @code{true} then the trait is
24803@code{true}, else if @code{type} is a cv-qualified class or union type
24804with copy constructors that are known not to throw an exception then
24805the trait is @code{true}, else it is @code{false}.
24806Requires: @code{type} shall be a complete type, (possibly cv-qualified)
24807@code{void}, or an array of unknown bound.
24808
24809@item __has_nothrow_constructor (type)
24810If @code{__has_trivial_constructor (type)} is @code{true} then the trait
24811is @code{true}, else if @code{type} is a cv class or union type (or array
24812thereof) with a default constructor that is known not to throw an
24813exception then the trait is @code{true}, else it is @code{false}.
24814Requires: @code{type} shall be a complete type, (possibly cv-qualified)
24815@code{void}, or an array of unknown bound.
24816
24817@item __has_trivial_assign (type)
24818If @code{type} is @code{const}- qualified or is a reference type then
24819the trait is @code{false}.  Otherwise if @code{__is_pod (type)} is
24820@code{true} then the trait is @code{true}, else if @code{type} is
24821a cv-qualified class or union type with a trivial copy assignment
24822([class.copy]) then the trait is @code{true}, else it is @code{false}.
24823Requires: @code{type} shall be a complete type, (possibly cv-qualified)
24824@code{void}, or an array of unknown bound.
24825
24826@item __has_trivial_copy (type)
24827If @code{__is_pod (type)} is @code{true} or @code{type} is a reference
24828type then the trait is @code{true}, else if @code{type} is a cv class
24829or union type with a trivial copy constructor ([class.copy]) then the trait
24830is @code{true}, else it is @code{false}.  Requires: @code{type} shall be
24831a complete type, (possibly cv-qualified) @code{void}, or an array of unknown
24832bound.
24833
24834@item __has_trivial_constructor (type)
24835If @code{__is_pod (type)} is @code{true} then the trait is @code{true},
24836else if @code{type} is a cv-qualified class or union type (or array thereof)
24837with a trivial default constructor ([class.ctor]) then the trait is @code{true},
24838else it is @code{false}.
24839Requires: @code{type} shall be a complete type, (possibly cv-qualified)
24840@code{void}, or an array of unknown bound.
24841
24842@item __has_trivial_destructor (type)
24843If @code{__is_pod (type)} is @code{true} or @code{type} is a reference type
24844then the trait is @code{true}, else if @code{type} is a cv class or union
24845type (or array thereof) with a trivial destructor ([class.dtor]) then
24846the trait is @code{true}, else it is @code{false}.
24847Requires: @code{type} shall be a complete type, (possibly cv-qualified)
24848@code{void}, or an array of unknown bound.
24849
24850@item __has_virtual_destructor (type)
24851If @code{type} is a class type with a virtual destructor
24852([class.dtor]) then the trait is @code{true}, else it is @code{false}.
24853Requires: @code{type} shall be a complete type, (possibly cv-qualified)
24854@code{void}, or an array of unknown bound.
24855
24856@item __is_abstract (type)
24857If @code{type} is an abstract class ([class.abstract]) then the trait
24858is @code{true}, else it is @code{false}.
24859Requires: @code{type} shall be a complete type, (possibly cv-qualified)
24860@code{void}, or an array of unknown bound.
24861
24862@item __is_base_of (base_type, derived_type)
24863If @code{base_type} is a base class of @code{derived_type}
24864([class.derived]) then the trait is @code{true}, otherwise it is @code{false}.
24865Top-level cv-qualifications of @code{base_type} and
24866@code{derived_type} are ignored.  For the purposes of this trait, a
24867class type is considered is own base.
24868Requires: if @code{__is_class (base_type)} and @code{__is_class (derived_type)}
24869are @code{true} and @code{base_type} and @code{derived_type} are not the same
24870type (disregarding cv-qualifiers), @code{derived_type} shall be a complete
24871type.  A diagnostic is produced if this requirement is not met.
24872
24873@item __is_class (type)
24874If @code{type} is a cv-qualified class type, and not a union type
24875([basic.compound]) the trait is @code{true}, else it is @code{false}.
24876
24877@item __is_empty (type)
24878If @code{__is_class (type)} is @code{false} then the trait is @code{false}.
24879Otherwise @code{type} is considered empty if and only if: @code{type}
24880has no non-static data members, or all non-static data members, if
24881any, are bit-fields of length 0, and @code{type} has no virtual
24882members, and @code{type} has no virtual base classes, and @code{type}
24883has no base classes @code{base_type} for which
24884@code{__is_empty (base_type)} is @code{false}.
24885Requires: @code{type} shall be a complete type, (possibly cv-qualified)
24886@code{void}, or an array of unknown bound.
24887
24888@item __is_enum (type)
24889If @code{type} is a cv enumeration type ([basic.compound]) the trait is
24890@code{true}, else it is @code{false}.
24891
24892@item __is_literal_type (type)
24893If @code{type} is a literal type ([basic.types]) the trait is
24894@code{true}, else it is @code{false}.
24895Requires: @code{type} shall be a complete type, (possibly cv-qualified)
24896@code{void}, or an array of unknown bound.
24897
24898@item __is_pod (type)
24899If @code{type} is a cv POD type ([basic.types]) then the trait is @code{true},
24900else it is @code{false}.
24901Requires: @code{type} shall be a complete type, (possibly cv-qualified)
24902@code{void}, or an array of unknown bound.
24903
24904@item __is_polymorphic (type)
24905If @code{type} is a polymorphic class ([class.virtual]) then the trait
24906is @code{true}, else it is @code{false}.
24907Requires: @code{type} shall be a complete type, (possibly cv-qualified)
24908@code{void}, or an array of unknown bound.
24909
24910@item __is_standard_layout (type)
24911If @code{type} is a standard-layout type ([basic.types]) the trait is
24912@code{true}, else it is @code{false}.
24913Requires: @code{type} shall be a complete type, (possibly cv-qualified)
24914@code{void}, or an array of unknown bound.
24915
24916@item __is_trivial (type)
24917If @code{type} is a trivial type ([basic.types]) the trait is
24918@code{true}, else it is @code{false}.
24919Requires: @code{type} shall be a complete type, (possibly cv-qualified)
24920@code{void}, or an array of unknown bound.
24921
24922@item __is_union (type)
24923If @code{type} is a cv union type ([basic.compound]) the trait is
24924@code{true}, else it is @code{false}.
24925
24926@item __underlying_type (type)
24927The underlying type of @code{type}.
24928Requires: @code{type} shall be an enumeration type ([dcl.enum]).
24929
24930@item __integer_pack (length)
24931When used as the pattern of a pack expansion within a template
24932definition, expands to a template argument pack containing integers
24933from @code{0} to @code{length-1}.  This is provided for efficient
24934implementation of @code{std::make_integer_sequence}.
24935
24936@end table
24937
24938
24939@node C++ Concepts
24940@section C++ Concepts
24941
24942C++ concepts provide much-improved support for generic programming. In
24943particular, they allow the specification of constraints on template arguments.
24944The constraints are used to extend the usual overloading and partial
24945specialization capabilities of the language, allowing generic data structures
24946and algorithms to be ``refined'' based on their properties rather than their
24947type names.
24948
24949The following keywords are reserved for concepts.
24950
24951@table @code
24952@item assumes
24953States an expression as an assumption, and if possible, verifies that the
24954assumption is valid. For example, @code{assume(n > 0)}.
24955
24956@item axiom
24957Introduces an axiom definition. Axioms introduce requirements on values.
24958
24959@item forall
24960Introduces a universally quantified object in an axiom. For example,
24961@code{forall (int n) n + 0 == n}).
24962
24963@item concept
24964Introduces a concept definition. Concepts are sets of syntactic and semantic
24965requirements on types and their values.
24966
24967@item requires
24968Introduces constraints on template arguments or requirements for a member
24969function of a class template.
24970
24971@end table
24972
24973The front end also exposes a number of internal mechanism that can be used
24974to simplify the writing of type traits. Note that some of these traits are
24975likely to be removed in the future.
24976
24977@table @code
24978@item __is_same (type1, type2)
24979A binary type trait: @code{true} whenever the type arguments are the same.
24980
24981@end table
24982
24983
24984@node Deprecated Features
24985@section Deprecated Features
24986
24987In the past, the GNU C++ compiler was extended to experiment with new
24988features, at a time when the C++ language was still evolving.  Now that
24989the C++ standard is complete, some of those features are superseded by
24990superior alternatives.  Using the old features might cause a warning in
24991some cases that the feature will be dropped in the future.  In other
24992cases, the feature might be gone already.
24993
24994G++ allows a virtual function returning @samp{void *} to be overridden
24995by one returning a different pointer type.  This extension to the
24996covariant return type rules is now deprecated and will be removed from a
24997future version.
24998
24999The use of default arguments in function pointers, function typedefs
25000and other places where they are not permitted by the standard is
25001deprecated and will be removed from a future version of G++.
25002
25003G++ allows floating-point literals to appear in integral constant expressions,
25004e.g.@: @samp{ enum E @{ e = int(2.2 * 3.7) @} }
25005This extension is deprecated and will be removed from a future version.
25006
25007G++ allows static data members of const floating-point type to be declared
25008with an initializer in a class definition. The standard only allows
25009initializers for static members of const integral types and const
25010enumeration types so this extension has been deprecated and will be removed
25011from a future version.
25012
25013G++ allows attributes to follow a parenthesized direct initializer,
25014e.g.@: @samp{ int f (0) __attribute__ ((something)); } This extension
25015has been ignored since G++ 3.3 and is deprecated.
25016
25017G++ allows anonymous structs and unions to have members that are not
25018public non-static data members (i.e.@: fields).  These extensions are
25019deprecated.
25020
25021@node Backwards Compatibility
25022@section Backwards Compatibility
25023@cindex Backwards Compatibility
25024@cindex ARM [Annotated C++ Reference Manual]
25025
25026Now that there is a definitive ISO standard C++, G++ has a specification
25027to adhere to.  The C++ language evolved over time, and features that
25028used to be acceptable in previous drafts of the standard, such as the ARM
25029[Annotated C++ Reference Manual], are no longer accepted.  In order to allow
25030compilation of C++ written to such drafts, G++ contains some backwards
25031compatibilities.  @emph{All such backwards compatibility features are
25032liable to disappear in future versions of G++.} They should be considered
25033deprecated.   @xref{Deprecated Features}.
25034
25035@table @code
25036
25037@item Implicit C language
25038Old C system header files did not contain an @code{extern "C" @{@dots{}@}}
25039scope to set the language.  On such systems, all system header files are
25040implicitly scoped inside a C language scope.  Such headers must
25041correctly prototype function argument types, there is no leeway for
25042@code{()} to indicate an unspecified set of arguments.
25043
25044@end table
25045
25046@c  LocalWords:  emph deftypefn builtin ARCv2EM SIMD builtins msimd
25047@c  LocalWords:  typedef v4si v8hi DMA dma vdiwr vdowr
25048