]> git.ipfire.org Git - people/ms/gcc.git/blame - gcc/doc/extend.texi
docs: Add @defbuiltin family of helpers
[people/ms/gcc.git] / gcc / doc / extend.texi
CommitLineData
e1e5ecb2 1@c Copyright (C) 1988-2023 Free Software Foundation, Inc.
d77de738
ML
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
f25efe50 588@defbuiltin{{int} __builtin_setjmp (intptr_t *@var{buf})}
d77de738
ML
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}.
f25efe50 593@enddefbuiltin
d77de738 594
f25efe50 595@defbuiltin{{void} __builtin_longjmp (intptr_t *@var{buf}, int @var{val})}
d77de738
ML
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}.
f25efe50 607@enddefbuiltin
d77de738
ML
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
f25efe50 629@defbuiltin{{void *} __builtin_apply_args ()}
d77de738
ML
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.
f25efe50 638@enddefbuiltin
d77de738 639
f25efe50 640@defbuiltin{{void *} __builtin_apply (void (*@var{function})(), void *@var{arguments}, size_t @var{size})}
d77de738
ML
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.
f25efe50 657@enddefbuiltin
d77de738 658
f25efe50 659@defbuiltin{{void} __builtin_return (void *@var{result})}
d77de738
ML
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}.
f25efe50 663@enddefbuiltin
d77de738 664
f25efe50 665@defbuiltin{{} __builtin_va_arg_pack ()}
d77de738
ML
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
f25efe50 689@enddefbuiltin
d77de738 690
f25efe50 691@defbuiltin{int __builtin_va_arg_pack_len ()}
d77de738
ML
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
f25efe50 724@enddefbuiltin
d77de738
ML
725
726@node Typeof
727@section Referring to a Type with @code{typeof}
728@findex typeof
729@findex sizeof
730@cindex macros, types of arguments
731
732Another way to refer to the type of an expression is with @code{typeof}.
733The syntax of using of this keyword looks like @code{sizeof}, but the
734construct acts semantically like a type name defined with @code{typedef}.
735
736There are two ways of writing the argument to @code{typeof}: with an
737expression or with a type. Here is an example with an expression:
738
739@smallexample
740typeof (x[0](1))
741@end smallexample
742
743@noindent
744This assumes that @code{x} is an array of pointers to functions;
745the type described is that of the values of the functions.
746
747Here is an example with a typename as the argument:
748
749@smallexample
750typeof (int *)
751@end smallexample
752
753@noindent
754Here the type described is that of pointers to @code{int}.
755
756If you are writing a header file that must work when included in ISO C
757programs, write @code{__typeof__} instead of @code{typeof}.
758@xref{Alternate Keywords}.
759
760A @code{typeof} construct can be used anywhere a typedef name can be
761used. For example, you can use it in a declaration, in a cast, or inside
762of @code{sizeof} or @code{typeof}.
763
764The operand of @code{typeof} is evaluated for its side effects if and
765only if it is an expression of variably modified type or the name of
766such a type.
767
768@code{typeof} is often useful in conjunction with
769statement expressions (@pxref{Statement Exprs}).
770Here is how the two together can
771be used to define a safe ``maximum'' macro which operates on any
772arithmetic type and evaluates each of its arguments exactly once:
773
774@smallexample
775#define max(a,b) \
776 (@{ typeof (a) _a = (a); \
777 typeof (b) _b = (b); \
778 _a > _b ? _a : _b; @})
779@end smallexample
780
781@cindex underscores in variables in macros
782@cindex @samp{_} in variables in macros
783@cindex local variables in macros
784@cindex variables, local, in macros
785@cindex macros, local variables in
786
787The reason for using names that start with underscores for the local
788variables is to avoid conflicts with variable names that occur within the
789expressions that are substituted for @code{a} and @code{b}. Eventually we
790hope to design a new form of declaration syntax that allows you to declare
791variables whose scopes start only after their initializers; this will be a
792more reliable way to prevent such conflicts.
793
794@noindent
795Some more examples of the use of @code{typeof}:
796
797@itemize @bullet
798@item
799This declares @code{y} with the type of what @code{x} points to.
800
801@smallexample
802typeof (*x) y;
803@end smallexample
804
805@item
806This declares @code{y} as an array of such values.
807
808@smallexample
809typeof (*x) y[4];
810@end smallexample
811
812@item
813This declares @code{y} as an array of pointers to characters:
814
815@smallexample
816typeof (typeof (char *)[4]) y;
817@end smallexample
818
819@noindent
820It is equivalent to the following traditional C declaration:
821
822@smallexample
823char *y[4];
824@end smallexample
825
826To see the meaning of the declaration using @code{typeof}, and why it
827might be a useful way to write, rewrite it with these macros:
828
829@smallexample
830#define pointer(T) typeof(T *)
831#define array(T, N) typeof(T [N])
832@end smallexample
833
834@noindent
835Now the declaration can be rewritten this way:
836
837@smallexample
838array (pointer (char), 4) y;
839@end smallexample
840
841@noindent
842Thus, @code{array (pointer (char), 4)} is the type of arrays of 4
843pointers to @code{char}.
844@end itemize
845
846In GNU C, but not GNU C++, you may also declare the type of a variable
847as @code{__auto_type}. In that case, the declaration must declare
848only one variable, whose declarator must just be an identifier, the
849declaration must be initialized, and the type of the variable is
850determined by the initializer; the name of the variable is not in
851scope until after the initializer. (In C++, you should use C++11
852@code{auto} for this purpose.) Using @code{__auto_type}, the
853``maximum'' macro above could be written as:
854
855@smallexample
856#define max(a,b) \
857 (@{ __auto_type _a = (a); \
858 __auto_type _b = (b); \
859 _a > _b ? _a : _b; @})
860@end smallexample
861
862Using @code{__auto_type} instead of @code{typeof} has two advantages:
863
864@itemize @bullet
865@item Each argument to the macro appears only once in the expansion of
866the macro. This prevents the size of the macro expansion growing
867exponentially when calls to such macros are nested inside arguments of
868such macros.
869
870@item If the argument to the macro has variably modified type, it is
871evaluated only once when using @code{__auto_type}, but twice if
872@code{typeof} is used.
873@end itemize
874
875@node Conditionals
876@section Conditionals with Omitted Operands
877@cindex conditional expressions, extensions
878@cindex omitted middle-operands
879@cindex middle-operands, omitted
880@cindex extensions, @code{?:}
881@cindex @code{?:} extensions
882
883The middle operand in a conditional expression may be omitted. Then
884if the first operand is nonzero, its value is the value of the conditional
885expression.
886
887Therefore, the expression
888
889@smallexample
890x ? : y
891@end smallexample
892
893@noindent
894has the value of @code{x} if that is nonzero; otherwise, the value of
895@code{y}.
896
897This example is perfectly equivalent to
898
899@smallexample
900x ? x : y
901@end smallexample
902
903@cindex side effect in @code{?:}
904@cindex @code{?:} side effect
905@noindent
906In this simple case, the ability to omit the middle operand is not
907especially useful. When it becomes useful is when the first operand does,
908or may (if it is a macro argument), contain a side effect. Then repeating
909the operand in the middle would perform the side effect twice. Omitting
910the middle operand uses the value already computed without the undesirable
911effects of recomputing it.
912
913@node __int128
914@section 128-bit Integers
915@cindex @code{__int128} data types
916
917As an extension the integer scalar type @code{__int128} is supported for
918targets which have an integer mode wide enough to hold 128 bits.
919Simply write @code{__int128} for a signed 128-bit integer, or
920@code{unsigned __int128} for an unsigned 128-bit integer. There is no
921support in GCC for expressing an integer constant of type @code{__int128}
922for targets with @code{long long} integer less than 128 bits wide.
923
924@node Long Long
925@section Double-Word Integers
926@cindex @code{long long} data types
927@cindex double-word arithmetic
928@cindex multiprecision arithmetic
929@cindex @code{LL} integer suffix
930@cindex @code{ULL} integer suffix
931
932ISO C99 and ISO C++11 support data types for integers that are at least
93364 bits wide, and as an extension GCC supports them in C90 and C++98 modes.
934Simply write @code{long long int} for a signed integer, or
935@code{unsigned long long int} for an unsigned integer. To make an
936integer constant of type @code{long long int}, add the suffix @samp{LL}
937to the integer. To make an integer constant of type @code{unsigned long
938long int}, add the suffix @samp{ULL} to the integer.
939
940You can use these types in arithmetic like any other integer types.
941Addition, subtraction, and bitwise boolean operations on these types
942are open-coded on all types of machines. Multiplication is open-coded
943if the machine supports a fullword-to-doubleword widening multiply
944instruction. Division and shifts are open-coded only on machines that
945provide special support. The operations that are not open-coded use
946special library routines that come with GCC@.
947
948There may be pitfalls when you use @code{long long} types for function
949arguments without function prototypes. If a function
950expects type @code{int} for its argument, and you pass a value of type
951@code{long long int}, confusion results because the caller and the
952subroutine disagree about the number of bytes for the argument.
953Likewise, if the function expects @code{long long int} and you pass
954@code{int}. The best way to avoid such problems is to use prototypes.
955
956@node Complex
957@section Complex Numbers
958@cindex complex numbers
959@cindex @code{_Complex} keyword
960@cindex @code{__complex__} keyword
961
962ISO C99 supports complex floating data types, and as an extension GCC
963supports them in C90 mode and in C++. GCC also supports complex integer data
964types which are not part of ISO C99. You can declare complex types
965using the keyword @code{_Complex}. As an extension, the older GNU
966keyword @code{__complex__} is also supported.
967
968For example, @samp{_Complex double x;} declares @code{x} as a
969variable whose real part and imaginary part are both of type
970@code{double}. @samp{_Complex short int y;} declares @code{y} to
971have real and imaginary parts of type @code{short int}; this is not
972likely to be useful, but it shows that the set of complex types is
973complete.
974
975To write a constant with a complex data type, use the suffix @samp{i} or
976@samp{j} (either one; they are equivalent). For example, @code{2.5fi}
977has type @code{_Complex float} and @code{3i} has type
978@code{_Complex int}. Such a constant always has a pure imaginary
979value, but you can form any complex value you like by adding one to a
980real constant. This is a GNU extension; if you have an ISO C99
981conforming C library (such as the GNU C Library), and want to construct complex
982constants of floating type, you should include @code{<complex.h>} and
983use the macros @code{I} or @code{_Complex_I} instead.
984
985The ISO C++14 library also defines the @samp{i} suffix, so C++14 code
986that includes the @samp{<complex>} header cannot use @samp{i} for the
987GNU extension. The @samp{j} suffix still has the GNU meaning.
988
989GCC can handle both implicit and explicit casts between the @code{_Complex}
990types and other @code{_Complex} types as casting both the real and imaginary
991parts to the scalar type.
992GCC can handle implicit and explicit casts from a scalar type to a @code{_Complex}
993type and where the imaginary part will be considered zero.
994The C front-end can handle implicit and explicit casts from a @code{_Complex} type
995to a scalar type where the imaginary part will be ignored. In C++ code, this cast
996is considered illformed and G++ will error out.
997
998GCC provides a built-in function @code{__builtin_complex} will can be used to
999construct a complex value.
1000
1001@cindex @code{__real__} keyword
1002@cindex @code{__imag__} keyword
1003
1004GCC has a few extensions which can be used to extract the real
1005and the imaginary part of the complex-valued expression. Note
1006these expressions are lvalues if the @var{exp} is an lvalue.
1007These expressions operands have the type of a complex type
1008which might get prompoted to a complex type from a scalar type.
1009E.g. @code{__real__ (int)@var{x}} is the same as casting to
1010@code{_Complex int} before @code{__real__} is done.
1011
1012@multitable @columnfractions .4 .6
1013@headitem Expression @tab Description
1014@item @code{__real__ @var{exp}}
1015@tab Extract the real part of @var{exp}.
1016@item @code{__imag__ @var{exp}}
1017@tab Extract the imaginary part of @var{exp}.
1018@end multitable
1019
1020For values of floating point, you should use the ISO C99
1021functions, declared in @code{<complex.h>} and also provided as
1022built-in functions by GCC@.
1023
1024@multitable @columnfractions .4 .2 .2 .2
1025@headitem Expression @tab float @tab double @tab long double
1026@item @code{__real__ @var{exp}}
1027@tab @code{crealf} @tab @code{creal} @tab @code{creall}
1028@item @code{__imag__ @var{exp}}
1029@tab @code{cimagf} @tab @code{cimag} @tab @code{cimagl}
1030@end multitable
1031
1032@cindex complex conjugation
1033The operator @samp{~} performs complex conjugation when used on a value
1034with a complex type. This is a GNU extension; for values of
1035floating type, you should use the ISO C99 functions @code{conjf},
1036@code{conj} and @code{conjl}, declared in @code{<complex.h>} and also
1037provided as built-in functions by GCC@. Note unlike the @code{__real__}
1038and @code{__imag__} operators, this operator will not do an implicit cast
1039to the complex type because the @samp{~} is already a normal operator.
1040
1041GCC can allocate complex automatic variables in a noncontiguous
1042fashion; it's even possible for the real part to be in a register while
1043the imaginary part is on the stack (or vice versa). Only the DWARF
1044debug info format can represent this, so use of DWARF is recommended.
1045If you are using the stabs debug info format, GCC describes a noncontiguous
1046complex variable as if it were two separate variables of noncomplex type.
1047If the variable's actual name is @code{foo}, the two fictitious
1048variables are named @code{foo$real} and @code{foo$imag}. You can
1049examine and set these two fictitious variables with your debugger.
1050
f25efe50 1051@defbuiltin{@var{type} __builtin_complex (@var{real}, @var{imag})}
d77de738
ML
1052
1053The built-in function @code{__builtin_complex} is provided for use in
1054implementing the ISO C11 macros @code{CMPLXF}, @code{CMPLX} and
1055@code{CMPLXL}. @var{real} and @var{imag} must have the same type, a
1056real binary floating-point type, and the result has the corresponding
1057complex type with real and imaginary parts @var{real} and @var{imag}.
1058Unlike @samp{@var{real} + I * @var{imag}}, this works even when
1059infinities, NaNs and negative zeros are involved.
1060
f25efe50 1061@enddefbuiltin
d77de738
ML
1062
1063@node Floating Types
1064@section Additional Floating Types
1065@cindex additional floating types
1066@cindex @code{_Float@var{n}} data types
1067@cindex @code{_Float@var{n}x} data types
1068@cindex @code{__float80} data type
1069@cindex @code{__float128} data type
1070@cindex @code{__ibm128} data type
1071@cindex @code{w} floating point suffix
1072@cindex @code{q} floating point suffix
1073@cindex @code{W} floating point suffix
1074@cindex @code{Q} floating point suffix
1075
1076ISO/IEC TS 18661-3:2015 defines C support for additional floating
1077types @code{_Float@var{n}} and @code{_Float@var{n}x}, and GCC supports
1078these type names; the set of types supported depends on the target
1079architecture. These types are not supported when compiling C++.
1080Constants with these types use suffixes @code{f@var{n}} or
1081@code{F@var{n}} and @code{f@var{n}x} or @code{F@var{n}x}. These type
1082names can be used together with @code{_Complex} to declare complex
1083types.
1084
1085As an extension, GNU C and GNU C++ support additional floating
1086types, which are not supported by all targets.
1087@itemize @bullet
1088@item @code{__float128} is available on i386, x86_64, IA-64, and
1089hppa HP-UX, as well as on PowerPC GNU/Linux targets that enable
1090the vector scalar (VSX) instruction set. @code{__float128} supports
1091the 128-bit floating type. On i386, x86_64, PowerPC, and IA-64
1092other than HP-UX, @code{__float128} is an alias for @code{_Float128}.
1093On hppa and IA-64 HP-UX, @code{__float128} is an alias for @code{long
1094double}.
1095
1096@item @code{__float80} is available on the i386, x86_64, and IA-64
1097targets, and supports the 80-bit (@code{XFmode}) floating type. It is
1098an alias for the type name @code{_Float64x} on these targets.
1099
1100@item @code{__ibm128} is available on PowerPC targets, and provides
1101access to the IBM extended double format which is the current format
1102used for @code{long double}. When @code{long double} transitions to
1103@code{__float128} on PowerPC in the future, @code{__ibm128} will remain
1104for use in conversions between the two types.
1105@end itemize
1106
1107Support for these additional types includes the arithmetic operators:
1108add, subtract, multiply, divide; unary arithmetic operators;
1109relational operators; equality operators; and conversions to and from
1110integer and other floating types. Use a suffix @samp{w} or @samp{W}
1111in a literal constant of type @code{__float80} or type
1112@code{__ibm128}. Use a suffix @samp{q} or @samp{Q} for @code{__float128}.
1113
1114In order to use @code{_Float128}, @code{__float128}, and @code{__ibm128}
1115on PowerPC Linux systems, you must use the @option{-mfloat128} option. It is
1116expected in future versions of GCC that @code{_Float128} and @code{__float128}
1117will be enabled automatically.
1118
1119The @code{_Float128} type is supported on all systems where
1120@code{__float128} is supported or where @code{long double} has the
1121IEEE binary128 format. The @code{_Float64x} type is supported on all
1122systems where @code{__float128} is supported. The @code{_Float32}
1123type is supported on all systems supporting IEEE binary32; the
1124@code{_Float64} and @code{_Float32x} types are supported on all systems
1125supporting IEEE binary64. The @code{_Float16} type is supported on AArch64
1126systems by default, on ARM systems when the IEEE format for 16-bit
1127floating-point types is selected with @option{-mfp16-format=ieee} and,
1128for both C and C++, on x86 systems with SSE2 enabled. GCC does not currently
1129support @code{_Float128x} on any systems.
1130
1131On the i386, x86_64, IA-64, and HP-UX targets, you can declare complex
1132types using the corresponding internal complex type, @code{XCmode} for
1133@code{__float80} type and @code{TCmode} for @code{__float128} type:
1134
1135@smallexample
1136typedef _Complex float __attribute__((mode(TC))) _Complex128;
1137typedef _Complex float __attribute__((mode(XC))) _Complex80;
1138@end smallexample
1139
1140On the PowerPC Linux VSX targets, you can declare complex types using
1141the corresponding internal complex type, @code{KCmode} for
1142@code{__float128} type and @code{ICmode} for @code{__ibm128} type:
1143
1144@smallexample
1145typedef _Complex float __attribute__((mode(KC))) _Complex_float128;
1146typedef _Complex float __attribute__((mode(IC))) _Complex_ibm128;
1147@end smallexample
1148
1149@node Half-Precision
1150@section Half-Precision Floating Point
1151@cindex half-precision floating point
1152@cindex @code{__fp16} data type
1153@cindex @code{__Float16} data type
1154
1155On ARM and AArch64 targets, GCC supports half-precision (16-bit) floating
1156point via the @code{__fp16} type defined in the ARM C Language Extensions.
1157On ARM systems, you must enable this type explicitly with the
1158@option{-mfp16-format} command-line option in order to use it.
1159On x86 targets with SSE2 enabled, GCC supports half-precision (16-bit)
1160floating point via the @code{_Float16} type. For C++, x86 provides a builtin
1161type named @code{_Float16} which contains same data format as C.
1162
1163ARM targets support two incompatible representations for half-precision
1164floating-point values. You must choose one of the representations and
1165use it consistently in your program.
1166
1167Specifying @option{-mfp16-format=ieee} selects the IEEE 754-2008 format.
1168This format can represent normalized values in the range of @math{2^{-14}} to 65504.
1169There are 11 bits of significand precision, approximately 3
1170decimal digits.
1171
1172Specifying @option{-mfp16-format=alternative} selects the ARM
1173alternative format. This representation is similar to the IEEE
1174format, but does not support infinities or NaNs. Instead, the range
1175of exponents is extended, so that this format can represent normalized
1176values in the range of @math{2^{-14}} to 131008.
1177
1178The GCC port for AArch64 only supports the IEEE 754-2008 format, and does
1179not require use of the @option{-mfp16-format} command-line option.
1180
1181The @code{__fp16} type may only be used as an argument to intrinsics defined
1182in @code{<arm_fp16.h>}, or as a storage format. For purposes of
1183arithmetic and other operations, @code{__fp16} values in C or C++
1184expressions are automatically promoted to @code{float}.
1185
1186The ARM target provides hardware support for conversions between
1187@code{__fp16} and @code{float} values
1188as an extension to VFP and NEON (Advanced SIMD), and from ARMv8-A provides
1189hardware support for conversions between @code{__fp16} and @code{double}
1190values. GCC generates code using these hardware instructions if you
1191compile with options to select an FPU that provides them;
1192for example, @option{-mfpu=neon-fp16 -mfloat-abi=softfp},
1193in addition to the @option{-mfp16-format} option to select
1194a half-precision format.
1195
1196Language-level support for the @code{__fp16} data type is
1197independent of whether GCC generates code using hardware floating-point
1198instructions. In cases where hardware support is not specified, GCC
1199implements conversions between @code{__fp16} and other types as library
1200calls.
1201
1202It is recommended that portable code use the @code{_Float16} type defined
1203by ISO/IEC TS 18661-3:2015. @xref{Floating Types}.
1204
1205On x86 targets with SSE2 enabled, without @option{-mavx512fp16},
1206all operations will be emulated by software emulation and the @code{float}
1207instructions. The default behavior for @code{FLT_EVAL_METHOD} is to keep the
1208intermediate result of the operation as 32-bit precision. This may lead to
1209inconsistent behavior between software emulation and AVX512-FP16 instructions.
1210Using @option{-fexcess-precision=16} will force round back after each operation.
1211
1212Using @option{-mavx512fp16} will generate AVX512-FP16 instructions instead of
1213software emulation. The default behavior of @code{FLT_EVAL_METHOD} is to round
1214after each operation. The same is true with @option{-fexcess-precision=standard}
1215and @option{-mfpmath=sse}. If there is no @option{-mfpmath=sse},
1216@option{-fexcess-precision=standard} alone does the same thing as before,
1217It is useful for code that does not have @code{_Float16} and runs on the x87
1218FPU.
1219
1220@node Decimal Float
1221@section Decimal Floating Types
1222@cindex decimal floating types
1223@cindex @code{_Decimal32} data type
1224@cindex @code{_Decimal64} data type
1225@cindex @code{_Decimal128} data type
1226@cindex @code{df} integer suffix
1227@cindex @code{dd} integer suffix
1228@cindex @code{dl} integer suffix
1229@cindex @code{DF} integer suffix
1230@cindex @code{DD} integer suffix
1231@cindex @code{DL} integer suffix
1232
1233As an extension, GNU C supports decimal floating types as
1234defined in the N1312 draft of ISO/IEC WDTR24732. Support for decimal
1235floating types in GCC will evolve as the draft technical report changes.
1236Calling conventions for any target might also change. Not all targets
1237support decimal floating types.
1238
1239The decimal floating types are @code{_Decimal32}, @code{_Decimal64}, and
1240@code{_Decimal128}. They use a radix of ten, unlike the floating types
1241@code{float}, @code{double}, and @code{long double} whose radix is not
1242specified by the C standard but is usually two.
1243
1244Support for decimal floating types includes the arithmetic operators
1245add, subtract, multiply, divide; unary arithmetic operators;
1246relational operators; equality operators; and conversions to and from
1247integer and other floating types. Use a suffix @samp{df} or
1248@samp{DF} in a literal constant of type @code{_Decimal32}, @samp{dd}
1249or @samp{DD} for @code{_Decimal64}, and @samp{dl} or @samp{DL} for
1250@code{_Decimal128}.
1251
1252GCC support of decimal float as specified by the draft technical report
1253is incomplete:
1254
1255@itemize @bullet
1256@item
1257When the value of a decimal floating type cannot be represented in the
1258integer type to which it is being converted, the result is undefined
1259rather than the result value specified by the draft technical report.
1260
1261@item
1262GCC does not provide the C library functionality associated with
1263@file{math.h}, @file{fenv.h}, @file{stdio.h}, @file{stdlib.h}, and
1264@file{wchar.h}, which must come from a separate C library implementation.
1265Because of this the GNU C compiler does not define macro
1266@code{__STDC_DEC_FP__} to indicate that the implementation conforms to
1267the technical report.
1268@end itemize
1269
1270Types @code{_Decimal32}, @code{_Decimal64}, and @code{_Decimal128}
1271are supported by the DWARF debug information format.
1272
1273@node Hex Floats
1274@section Hex Floats
1275@cindex hex floats
1276
1277ISO C99 and ISO C++17 support floating-point numbers written not only in
1278the usual decimal notation, such as @code{1.55e1}, but also numbers such as
1279@code{0x1.fp3} written in hexadecimal format. As a GNU extension, GCC
1280supports this in C90 mode (except in some cases when strictly
1281conforming) and in C++98, C++11 and C++14 modes. In that format the
1282@samp{0x} hex introducer and the @samp{p} or @samp{P} exponent field are
1283mandatory. The exponent is a decimal number that indicates the power of
12842 by which the significant part is multiplied. Thus @samp{0x1.f} is
1285@tex
1286$1 {15\over16}$,
1287@end tex
1288@ifnottex
12891 15/16,
1290@end ifnottex
1291@samp{p3} multiplies it by 8, and the value of @code{0x1.fp3}
1292is the same as @code{1.55e1}.
1293
1294Unlike for floating-point numbers in the decimal notation the exponent
1295is always required in the hexadecimal notation. Otherwise the compiler
1296would not be able to resolve the ambiguity of, e.g., @code{0x1.f}. This
1297could mean @code{1.0f} or @code{1.9375} since @samp{f} is also the
1298extension for floating-point constants of type @code{float}.
1299
1300@node Fixed-Point
1301@section Fixed-Point Types
1302@cindex fixed-point types
1303@cindex @code{_Fract} data type
1304@cindex @code{_Accum} data type
1305@cindex @code{_Sat} data type
1306@cindex @code{hr} fixed-suffix
1307@cindex @code{r} fixed-suffix
1308@cindex @code{lr} fixed-suffix
1309@cindex @code{llr} fixed-suffix
1310@cindex @code{uhr} fixed-suffix
1311@cindex @code{ur} fixed-suffix
1312@cindex @code{ulr} fixed-suffix
1313@cindex @code{ullr} fixed-suffix
1314@cindex @code{hk} fixed-suffix
1315@cindex @code{k} fixed-suffix
1316@cindex @code{lk} fixed-suffix
1317@cindex @code{llk} fixed-suffix
1318@cindex @code{uhk} fixed-suffix
1319@cindex @code{uk} fixed-suffix
1320@cindex @code{ulk} fixed-suffix
1321@cindex @code{ullk} fixed-suffix
1322@cindex @code{HR} fixed-suffix
1323@cindex @code{R} fixed-suffix
1324@cindex @code{LR} fixed-suffix
1325@cindex @code{LLR} fixed-suffix
1326@cindex @code{UHR} fixed-suffix
1327@cindex @code{UR} fixed-suffix
1328@cindex @code{ULR} fixed-suffix
1329@cindex @code{ULLR} fixed-suffix
1330@cindex @code{HK} fixed-suffix
1331@cindex @code{K} fixed-suffix
1332@cindex @code{LK} fixed-suffix
1333@cindex @code{LLK} fixed-suffix
1334@cindex @code{UHK} fixed-suffix
1335@cindex @code{UK} fixed-suffix
1336@cindex @code{ULK} fixed-suffix
1337@cindex @code{ULLK} fixed-suffix
1338
1339As an extension, GNU C supports fixed-point types as
1340defined in the N1169 draft of ISO/IEC DTR 18037. Support for fixed-point
1341types in GCC will evolve as the draft technical report changes.
1342Calling conventions for any target might also change. Not all targets
1343support fixed-point types.
1344
1345The fixed-point types are
1346@code{short _Fract},
1347@code{_Fract},
1348@code{long _Fract},
1349@code{long long _Fract},
1350@code{unsigned short _Fract},
1351@code{unsigned _Fract},
1352@code{unsigned long _Fract},
1353@code{unsigned long long _Fract},
1354@code{_Sat short _Fract},
1355@code{_Sat _Fract},
1356@code{_Sat long _Fract},
1357@code{_Sat long long _Fract},
1358@code{_Sat unsigned short _Fract},
1359@code{_Sat unsigned _Fract},
1360@code{_Sat unsigned long _Fract},
1361@code{_Sat unsigned long long _Fract},
1362@code{short _Accum},
1363@code{_Accum},
1364@code{long _Accum},
1365@code{long long _Accum},
1366@code{unsigned short _Accum},
1367@code{unsigned _Accum},
1368@code{unsigned long _Accum},
1369@code{unsigned long long _Accum},
1370@code{_Sat short _Accum},
1371@code{_Sat _Accum},
1372@code{_Sat long _Accum},
1373@code{_Sat long long _Accum},
1374@code{_Sat unsigned short _Accum},
1375@code{_Sat unsigned _Accum},
1376@code{_Sat unsigned long _Accum},
1377@code{_Sat unsigned long long _Accum}.
1378
1379Fixed-point data values contain fractional and optional integral parts.
1380The format of fixed-point data varies and depends on the target machine.
1381
1382Support for fixed-point types includes:
1383@itemize @bullet
1384@item
1385prefix and postfix increment and decrement operators (@code{++}, @code{--})
1386@item
1387unary arithmetic operators (@code{+}, @code{-}, @code{!})
1388@item
1389binary arithmetic operators (@code{+}, @code{-}, @code{*}, @code{/})
1390@item
1391binary shift operators (@code{<<}, @code{>>})
1392@item
1393relational operators (@code{<}, @code{<=}, @code{>=}, @code{>})
1394@item
1395equality operators (@code{==}, @code{!=})
1396@item
1397assignment operators (@code{+=}, @code{-=}, @code{*=}, @code{/=},
1398@code{<<=}, @code{>>=})
1399@item
1400conversions to and from integer, floating-point, or fixed-point types
1401@end itemize
1402
1403Use a suffix in a fixed-point literal constant:
1404@itemize
1405@item @samp{hr} or @samp{HR} for @code{short _Fract} and
1406@code{_Sat short _Fract}
1407@item @samp{r} or @samp{R} for @code{_Fract} and @code{_Sat _Fract}
1408@item @samp{lr} or @samp{LR} for @code{long _Fract} and
1409@code{_Sat long _Fract}
1410@item @samp{llr} or @samp{LLR} for @code{long long _Fract} and
1411@code{_Sat long long _Fract}
1412@item @samp{uhr} or @samp{UHR} for @code{unsigned short _Fract} and
1413@code{_Sat unsigned short _Fract}
1414@item @samp{ur} or @samp{UR} for @code{unsigned _Fract} and
1415@code{_Sat unsigned _Fract}
1416@item @samp{ulr} or @samp{ULR} for @code{unsigned long _Fract} and
1417@code{_Sat unsigned long _Fract}
1418@item @samp{ullr} or @samp{ULLR} for @code{unsigned long long _Fract}
1419and @code{_Sat unsigned long long _Fract}
1420@item @samp{hk} or @samp{HK} for @code{short _Accum} and
1421@code{_Sat short _Accum}
1422@item @samp{k} or @samp{K} for @code{_Accum} and @code{_Sat _Accum}
1423@item @samp{lk} or @samp{LK} for @code{long _Accum} and
1424@code{_Sat long _Accum}
1425@item @samp{llk} or @samp{LLK} for @code{long long _Accum} and
1426@code{_Sat long long _Accum}
1427@item @samp{uhk} or @samp{UHK} for @code{unsigned short _Accum} and
1428@code{_Sat unsigned short _Accum}
1429@item @samp{uk} or @samp{UK} for @code{unsigned _Accum} and
1430@code{_Sat unsigned _Accum}
1431@item @samp{ulk} or @samp{ULK} for @code{unsigned long _Accum} and
1432@code{_Sat unsigned long _Accum}
1433@item @samp{ullk} or @samp{ULLK} for @code{unsigned long long _Accum}
1434and @code{_Sat unsigned long long _Accum}
1435@end itemize
1436
1437GCC support of fixed-point types as specified by the draft technical report
1438is incomplete:
1439
1440@itemize @bullet
1441@item
1442Pragmas to control overflow and rounding behaviors are not implemented.
1443@end itemize
1444
1445Fixed-point types are supported by the DWARF debug information format.
1446
1447@node Named Address Spaces
1448@section Named Address Spaces
1449@cindex Named Address Spaces
1450
1451As an extension, GNU C supports named address spaces as
1452defined in the N1275 draft of ISO/IEC DTR 18037. Support for named
1453address spaces in GCC will evolve as the draft technical report
1454changes. Calling conventions for any target might also change. At
1455present, only the AVR, M32C, PRU, RL78, and x86 targets support
1456address spaces other than the generic address space.
1457
1458Address space identifiers may be used exactly like any other C type
1459qualifier (e.g., @code{const} or @code{volatile}). See the N1275
1460document for more details.
1461
1462@anchor{AVR Named Address Spaces}
1463@subsection AVR Named Address Spaces
1464
1465On the AVR target, there are several address spaces that can be used
1466in order to put read-only data into the flash memory and access that
1467data by means of the special instructions @code{LPM} or @code{ELPM}
1468needed to read from flash.
1469
1470Devices belonging to @code{avrtiny} and @code{avrxmega3} can access
1471flash memory by means of @code{LD*} instructions because the flash
1472memory is mapped into the RAM address space. There is @emph{no need}
1473for language extensions like @code{__flash} or attribute
1474@ref{AVR Variable Attributes,,@code{progmem}}.
1475The default linker description files for these devices cater for that
1476feature and @code{.rodata} stays in flash: The compiler just generates
1477@code{LD*} instructions, and the linker script adds core specific
1478offsets to all @code{.rodata} symbols: @code{0x4000} in the case of
1479@code{avrtiny} and @code{0x8000} in the case of @code{avrxmega3}.
1480See @ref{AVR Options} for a list of respective devices.
1481
1482For devices not in @code{avrtiny} or @code{avrxmega3},
1483any data including read-only data is located in RAM (the generic
1484address space) because flash memory is not visible in the RAM address
1485space. In order to locate read-only data in flash memory @emph{and}
1486to generate the right instructions to access this data without
1487using (inline) assembler code, special address spaces are needed.
1488
1489@table @code
d77de738 1490@cindex @code{__flash} AVR Named Address Spaces
f33d7a88 1491@item __flash
d77de738
ML
1492The @code{__flash} qualifier locates data in the
1493@code{.progmem.data} section. Data is read using the @code{LPM}
1494instruction. Pointers to this address space are 16 bits wide.
1495
d77de738
ML
1496@cindex @code{__flash1} AVR Named Address Spaces
1497@cindex @code{__flash2} AVR Named Address Spaces
1498@cindex @code{__flash3} AVR Named Address Spaces
1499@cindex @code{__flash4} AVR Named Address Spaces
1500@cindex @code{__flash5} AVR Named Address Spaces
f33d7a88
AA
1501@item __flash1
1502@itemx __flash2
1503@itemx __flash3
1504@itemx __flash4
1505@itemx __flash5
d77de738
ML
1506These are 16-bit address spaces locating data in section
1507@code{.progmem@var{N}.data} where @var{N} refers to
1508address space @code{__flash@var{N}}.
1509The compiler sets the @code{RAMPZ} segment register appropriately
1510before reading data by means of the @code{ELPM} instruction.
1511
d77de738 1512@cindex @code{__memx} AVR Named Address Spaces
f33d7a88 1513@item __memx
d77de738
ML
1514This is a 24-bit address space that linearizes flash and RAM:
1515If the high bit of the address is set, data is read from
1516RAM using the lower two bytes as RAM address.
1517If the high bit of the address is clear, data is read from flash
1518with @code{RAMPZ} set according to the high byte of the address.
1519@xref{AVR Built-in Functions,,@code{__builtin_avr_flash_segment}}.
1520
1521Objects in this address space are located in @code{.progmemx.data}.
1522@end table
1523
1524@b{Example}
1525
1526@smallexample
1527char my_read (const __flash char ** p)
1528@{
1529 /* p is a pointer to RAM that points to a pointer to flash.
1530 The first indirection of p reads that flash pointer
1531 from RAM and the second indirection reads a char from this
1532 flash address. */
1533
1534 return **p;
1535@}
1536
1537/* Locate array[] in flash memory */
1538const __flash int array[] = @{ 3, 5, 7, 11, 13, 17, 19 @};
1539
1540int i = 1;
1541
1542int main (void)
1543@{
1544 /* Return 17 by reading from flash memory */
1545 return array[array[i]];
1546@}
1547@end smallexample
1548
1549@noindent
1550For each named address space supported by avr-gcc there is an equally
1551named but uppercase built-in macro defined.
1552The purpose is to facilitate testing if respective address space
1553support is available or not:
1554
1555@smallexample
1556#ifdef __FLASH
1557const __flash int var = 1;
1558
1559int read_var (void)
1560@{
1561 return var;
1562@}
1563#else
1564#include <avr/pgmspace.h> /* From AVR-LibC */
1565
1566const int var PROGMEM = 1;
1567
1568int read_var (void)
1569@{
1570 return (int) pgm_read_word (&var);
1571@}
1572#endif /* __FLASH */
1573@end smallexample
1574
1575@noindent
1576Notice that attribute @ref{AVR Variable Attributes,,@code{progmem}}
1577locates data in flash but
1578accesses to these data read from generic address space, i.e.@:
1579from RAM,
1580so that you need special accessors like @code{pgm_read_byte}
38bce6ff 1581from @w{@uref{https://www.nongnu.org/avr-libc/user-manual/,AVR-LibC}}
d77de738
ML
1582together with attribute @code{progmem}.
1583
1584@noindent
1585@b{Limitations and caveats}
1586
1587@itemize
1588@item
1589Reading across the 64@tie{}KiB section boundary of
1590the @code{__flash} or @code{__flash@var{N}} address spaces
1591shows undefined behavior. The only address space that
1592supports reading across the 64@tie{}KiB flash segment boundaries is
1593@code{__memx}.
1594
1595@item
1596If you use one of the @code{__flash@var{N}} address spaces
1597you must arrange your linker script to locate the
1598@code{.progmem@var{N}.data} sections according to your needs.
1599
1600@item
1601Any data or pointers to the non-generic address spaces must
1602be qualified as @code{const}, i.e.@: as read-only data.
1603This still applies if the data in one of these address
1604spaces like software version number or calibration lookup table are intended to
1605be changed after load time by, say, a boot loader. In this case
1606the right qualification is @code{const} @code{volatile} so that the compiler
1607must not optimize away known values or insert them
1608as immediates into operands of instructions.
1609
1610@item
1611The following code initializes a variable @code{pfoo}
1612located in static storage with a 24-bit address:
1613@smallexample
1614extern const __memx char foo;
1615const __memx void *pfoo = &foo;
1616@end smallexample
1617
1618@item
1619On the reduced Tiny devices like ATtiny40, no address spaces are supported.
1620Just use vanilla C / C++ code without overhead as outlined above.
1621Attribute @code{progmem} is supported but works differently,
1622see @ref{AVR Variable Attributes}.
1623
1624@end itemize
1625
1626@subsection M32C Named Address Spaces
1627@cindex @code{__far} M32C Named Address Spaces
1628
1629On the M32C target, with the R8C and M16C CPU variants, variables
1630qualified with @code{__far} are accessed using 32-bit addresses in
1631order to access memory beyond the first 64@tie{}Ki bytes. If
1632@code{__far} is used with the M32CM or M32C CPU variants, it has no
1633effect.
1634
1635@subsection PRU Named Address Spaces
1636@cindex @code{__regio_symbol} PRU Named Address Spaces
1637
1638On the PRU target, variables qualified with @code{__regio_symbol} are
1639aliases used to access the special I/O CPU registers. They must be
1640declared as @code{extern} because such variables will not be allocated in
1641any data memory. They must also be marked as @code{volatile}, and can
1642only be 32-bit integer types. The only names those variables can have
1643are @code{__R30} and @code{__R31}, representing respectively the
1644@code{R30} and @code{R31} special I/O CPU registers. Hence the following
1645example is the only valid usage of @code{__regio_symbol}:
1646
1647@smallexample
1648extern volatile __regio_symbol uint32_t __R30;
1649extern volatile __regio_symbol uint32_t __R31;
1650@end smallexample
1651
1652@subsection RL78 Named Address Spaces
1653@cindex @code{__far} RL78 Named Address Spaces
1654
1655On the RL78 target, variables qualified with @code{__far} are accessed
1656with 32-bit pointers (20-bit addresses) rather than the default 16-bit
1657addresses. Non-far variables are assumed to appear in the topmost
165864@tie{}KiB of the address space.
1659
1660@subsection x86 Named Address Spaces
1661@cindex x86 named address spaces
1662
1663On the x86 target, variables may be declared as being relative
1664to the @code{%fs} or @code{%gs} segments.
1665
1666@table @code
d77de738
ML
1667@cindex @code{__seg_fs} x86 named address space
1668@cindex @code{__seg_gs} x86 named address space
f33d7a88
AA
1669@item __seg_fs
1670@itemx __seg_gs
d77de738
ML
1671The object is accessed with the respective segment override prefix.
1672
1673The respective segment base must be set via some method specific to
1674the operating system. Rather than require an expensive system call
1675to retrieve the segment base, these address spaces are not considered
1676to be subspaces of the generic (flat) address space. This means that
1677explicit casts are required to convert pointers between these address
1678spaces and the generic address space. In practice the application
1679should cast to @code{uintptr_t} and apply the segment base offset
1680that it installed previously.
1681
1682The preprocessor symbols @code{__SEG_FS} and @code{__SEG_GS} are
1683defined when these address spaces are supported.
1684@end table
1685
1686@node Zero Length
1687@section Arrays of Length Zero
1688@cindex arrays of length zero
1689@cindex zero-length arrays
1690@cindex length-zero arrays
1691@cindex flexible array members
1692
1693Declaring zero-length arrays is allowed in GNU C as an extension.
1694A zero-length array can be useful as the last element of a structure
1695that is really a header for a variable-length object:
1696
1697@smallexample
1698struct line @{
1699 int length;
1700 char contents[0];
1701@};
1702
1703struct line *thisline = (struct line *)
1704 malloc (sizeof (struct line) + this_length);
1705thisline->length = this_length;
1706@end smallexample
1707
1708Although the size of a zero-length array is zero, an array member of
1709this kind may increase the size of the enclosing type as a result of tail
1710padding. The offset of a zero-length array member from the beginning
1711of the enclosing structure is the same as the offset of an array with
1712one or more elements of the same type. The alignment of a zero-length
1713array is the same as the alignment of its elements.
1714
1715Declaring zero-length arrays in other contexts, including as interior
1716members of structure objects or as non-member objects, is discouraged.
1717Accessing elements of zero-length arrays declared in such contexts is
1718undefined and may be diagnosed.
1719
1720In the absence of the zero-length array extension, in ISO C90
1721the @code{contents} array in the example above would typically be declared
1722to have a single element. Unlike a zero-length array which only contributes
1723to the size of the enclosing structure for the purposes of alignment,
1724a one-element array always occupies at least as much space as a single
1725object of the type. Although using one-element arrays this way is
1726discouraged, GCC handles accesses to trailing one-element array members
1727analogously to zero-length arrays.
1728
1729The preferred mechanism to declare variable-length types like
1730@code{struct line} above is the ISO C99 @dfn{flexible array member},
1731with slightly different syntax and semantics:
1732
1733@itemize @bullet
1734@item
1735Flexible array members are written as @code{contents[]} without
1736the @code{0}.
1737
1738@item
1739Flexible array members have incomplete type, and so the @code{sizeof}
1740operator may not be applied. As a quirk of the original implementation
1741of zero-length arrays, @code{sizeof} evaluates to zero.
1742
1743@item
1744Flexible array members may only appear as the last member of a
1745@code{struct} that is otherwise non-empty.
1746
1747@item
1748A structure containing a flexible array member, or a union containing
1749such a structure (possibly recursively), may not be a member of a
1750structure or an element of an array. (However, these uses are
1751permitted by GCC as extensions.)
1752@end itemize
1753
1754Non-empty initialization of zero-length
1755arrays is treated like any case where there are more initializer
1756elements than the array holds, in that a suitable warning about ``excess
1757elements in array'' is given, and the excess elements (all of them, in
1758this case) are ignored.
1759
1760GCC allows static initialization of flexible array members.
1761This is equivalent to defining a new structure containing the original
1762structure followed by an array of sufficient size to contain the data.
1763E.g.@: in the following, @code{f1} is constructed as if it were declared
1764like @code{f2}.
1765
1766@smallexample
1767struct f1 @{
1768 int x; int y[];
1769@} f1 = @{ 1, @{ 2, 3, 4 @} @};
1770
1771struct f2 @{
1772 struct f1 f1; int data[3];
1773@} f2 = @{ @{ 1 @}, @{ 2, 3, 4 @} @};
1774@end smallexample
1775
1776@noindent
1777The convenience of this extension is that @code{f1} has the desired
1778type, eliminating the need to consistently refer to @code{f2.f1}.
1779
1780This has symmetry with normal static arrays, in that an array of
1781unknown size is also written with @code{[]}.
1782
1783Of course, this extension only makes sense if the extra data comes at
1784the end of a top-level object, as otherwise we would be overwriting
1785data at subsequent offsets. To avoid undue complication and confusion
1786with initialization of deeply nested arrays, we simply disallow any
1787non-empty initialization except when the structure is the top-level
1788object. For example:
1789
1790@smallexample
1791struct foo @{ int x; int y[]; @};
1792struct bar @{ struct foo z; @};
1793
1794struct foo a = @{ 1, @{ 2, 3, 4 @} @}; // @r{Valid.}
1795struct bar b = @{ @{ 1, @{ 2, 3, 4 @} @} @}; // @r{Invalid.}
1796struct bar c = @{ @{ 1, @{ @} @} @}; // @r{Valid.}
1797struct foo d[1] = @{ @{ 1, @{ 2, 3, 4 @} @} @}; // @r{Invalid.}
1798@end smallexample
1799
1800@node Empty Structures
1801@section Structures with No Members
1802@cindex empty structures
1803@cindex zero-size structures
1804
1805GCC permits a C structure to have no members:
1806
1807@smallexample
1808struct empty @{
1809@};
1810@end smallexample
1811
1812The structure has size zero. In C++, empty structures are part
1813of the language. G++ treats empty structures as if they had a single
1814member of type @code{char}.
1815
1816@node Variable Length
1817@section Arrays of Variable Length
1818@cindex variable-length arrays
1819@cindex arrays of variable length
1820@cindex VLAs
1821
1822Variable-length automatic arrays are allowed in ISO C99, and as an
1823extension GCC accepts them in C90 mode and in C++. These arrays are
1824declared like any other automatic arrays, but with a length that is not
1825a constant expression. The storage is allocated at the point of
1826declaration and deallocated when the block scope containing the declaration
1827exits. For
1828example:
1829
1830@smallexample
1831FILE *
1832concat_fopen (char *s1, char *s2, char *mode)
1833@{
1834 char str[strlen (s1) + strlen (s2) + 1];
1835 strcpy (str, s1);
1836 strcat (str, s2);
1837 return fopen (str, mode);
1838@}
1839@end smallexample
1840
1841@cindex scope of a variable length array
1842@cindex variable-length array scope
1843@cindex deallocating variable length arrays
1844Jumping or breaking out of the scope of the array name deallocates the
1845storage. Jumping into the scope is not allowed; you get an error
1846message for it.
1847
1848@cindex variable-length array in a structure
1849As an extension, GCC accepts variable-length arrays as a member of
1850a structure or a union. For example:
1851
1852@smallexample
1853void
1854foo (int n)
1855@{
1856 struct S @{ int x[n]; @};
1857@}
1858@end smallexample
1859
1860@cindex @code{alloca} vs variable-length arrays
1861You can use the function @code{alloca} to get an effect much like
1862variable-length arrays. The function @code{alloca} is available in
1863many other C implementations (but not in all). On the other hand,
1864variable-length arrays are more elegant.
1865
1866There are other differences between these two methods. Space allocated
1867with @code{alloca} exists until the containing @emph{function} returns.
1868The space for a variable-length array is deallocated as soon as the array
1869name's scope ends, unless you also use @code{alloca} in this scope.
1870
1871You can also use variable-length arrays as arguments to functions:
1872
1873@smallexample
1874struct entry
1875tester (int len, char data[len][len])
1876@{
1877 /* @r{@dots{}} */
1878@}
1879@end smallexample
1880
1881The length of an array is computed once when the storage is allocated
1882and is remembered for the scope of the array in case you access it with
1883@code{sizeof}.
1884
1885If you want to pass the array first and the length afterward, you can
1886use a forward declaration in the parameter list---another GNU extension.
1887
1888@smallexample
1889struct entry
1890tester (int len; char data[len][len], int len)
1891@{
1892 /* @r{@dots{}} */
1893@}
1894@end smallexample
1895
1896@cindex parameter forward declaration
1897The @samp{int len} before the semicolon is a @dfn{parameter forward
1898declaration}, and it serves the purpose of making the name @code{len}
1899known when the declaration of @code{data} is parsed.
1900
1901You can write any number of such parameter forward declarations in the
1902parameter list. They can be separated by commas or semicolons, but the
1903last one must end with a semicolon, which is followed by the ``real''
1904parameter declarations. Each forward declaration must match a ``real''
1905declaration in parameter name and data type. ISO C99 does not support
1906parameter forward declarations.
1907
1908@node Variadic Macros
1909@section Macros with a Variable Number of Arguments.
1910@cindex variable number of arguments
1911@cindex macro with variable arguments
1912@cindex rest argument (in macro)
1913@cindex variadic macros
1914
1915In the ISO C standard of 1999, a macro can be declared to accept a
1916variable number of arguments much as a function can. The syntax for
1917defining the macro is similar to that of a function. Here is an
1918example:
1919
1920@smallexample
1921#define debug(format, ...) fprintf (stderr, format, __VA_ARGS__)
1922@end smallexample
1923
1924@noindent
1925Here @samp{@dots{}} is a @dfn{variable argument}. In the invocation of
1926such a macro, it represents the zero or more tokens until the closing
1927parenthesis that ends the invocation, including any commas. This set of
1928tokens replaces the identifier @code{__VA_ARGS__} in the macro body
1929wherever it appears. See the CPP manual for more information.
1930
1931GCC has long supported variadic macros, and used a different syntax that
1932allowed you to give a name to the variable arguments just like any other
1933argument. Here is an example:
1934
1935@smallexample
1936#define debug(format, args...) fprintf (stderr, format, args)
1937@end smallexample
1938
1939@noindent
1940This is in all ways equivalent to the ISO C example above, but arguably
1941more readable and descriptive.
1942
1943GNU CPP has two further variadic macro extensions, and permits them to
1944be used with either of the above forms of macro definition.
1945
1946In standard C, you are not allowed to leave the variable argument out
1947entirely; but you are allowed to pass an empty argument. For example,
1948this invocation is invalid in ISO C, because there is no comma after
1949the string:
1950
1951@smallexample
1952debug ("A message")
1953@end smallexample
1954
1955GNU CPP permits you to completely omit the variable arguments in this
1956way. In the above examples, the compiler would complain, though since
1957the expansion of the macro still has the extra comma after the format
1958string.
1959
1960To help solve this problem, CPP behaves specially for variable arguments
1961used with the token paste operator, @samp{##}. If instead you write
1962
1963@smallexample
1964#define debug(format, ...) fprintf (stderr, format, ## __VA_ARGS__)
1965@end smallexample
1966
1967@noindent
1968and if the variable arguments are omitted or empty, the @samp{##}
1969operator causes the preprocessor to remove the comma before it. If you
1970do provide some variable arguments in your macro invocation, GNU CPP
1971does not complain about the paste operation and instead places the
1972variable arguments after the comma. Just like any other pasted macro
1973argument, these arguments are not macro expanded.
1974
1975@node Escaped Newlines
1976@section Slightly Looser Rules for Escaped Newlines
1977@cindex escaped newlines
1978@cindex newlines (escaped)
1979
1980The preprocessor treatment of escaped newlines is more relaxed
1981than that specified by the C90 standard, which requires the newline
1982to immediately follow a backslash.
1983GCC's implementation allows whitespace in the form
1984of spaces, horizontal and vertical tabs, and form feeds between the
1985backslash and the subsequent newline. The preprocessor issues a
1986warning, but treats it as a valid escaped newline and combines the two
1987lines to form a single logical line. This works within comments and
1988tokens, as well as between tokens. Comments are @emph{not} treated as
1989whitespace for the purposes of this relaxation, since they have not
1990yet been replaced with spaces.
1991
1992@node Subscripting
1993@section Non-Lvalue Arrays May Have Subscripts
1994@cindex subscripting
1995@cindex arrays, non-lvalue
1996
1997@cindex subscripting and function values
1998In ISO C99, arrays that are not lvalues still decay to pointers, and
1999may be subscripted, although they may not be modified or used after
2000the next sequence point and the unary @samp{&} operator may not be
2001applied to them. As an extension, GNU C allows such arrays to be
2002subscripted in C90 mode, though otherwise they do not decay to
2003pointers outside C99 mode. For example,
2004this is valid in GNU C though not valid in C90:
2005
2006@smallexample
2007@group
2008struct foo @{int a[4];@};
2009
2010struct foo f();
2011
2012bar (int index)
2013@{
2014 return f().a[index];
2015@}
2016@end group
2017@end smallexample
2018
2019@node Pointer Arith
2020@section Arithmetic on @code{void}- and Function-Pointers
2021@cindex void pointers, arithmetic
2022@cindex void, size of pointer to
2023@cindex function pointers, arithmetic
2024@cindex function, size of pointer to
2025
2026In GNU C, addition and subtraction operations are supported on pointers to
2027@code{void} and on pointers to functions. This is done by treating the
2028size of a @code{void} or of a function as 1.
2029
2030A consequence of this is that @code{sizeof} is also allowed on @code{void}
2031and on function types, and returns 1.
2032
2033@opindex Wpointer-arith
2034The option @option{-Wpointer-arith} requests a warning if these extensions
2035are used.
2036
2037@node Variadic Pointer Args
2038@section Pointer Arguments in Variadic Functions
2039@cindex pointer arguments in variadic functions
2040@cindex variadic functions, pointer arguments
2041
2042Standard C requires that pointer types used with @code{va_arg} in
2043functions with variable argument lists either must be compatible with
2044that of the actual argument, or that one type must be a pointer to
2045@code{void} and the other a pointer to a character type. GNU C
2046implements the POSIX XSI extension that additionally permits the use
2047of @code{va_arg} with a pointer type to receive arguments of any other
2048pointer type.
2049
2050In particular, in GNU C @samp{va_arg (ap, void *)} can safely be used
2051to consume an argument of any pointer type.
2052
2053@node Pointers to Arrays
2054@section Pointers to Arrays with Qualifiers Work as Expected
2055@cindex pointers to arrays
2056@cindex const qualifier
2057
2058In GNU C, pointers to arrays with qualifiers work similar to pointers
2059to other qualified types. For example, a value of type @code{int (*)[5]}
2060can be used to initialize a variable of type @code{const int (*)[5]}.
2061These types are incompatible in ISO C because the @code{const} qualifier
2062is formally attached to the element type of the array and not the
2063array itself.
2064
2065@smallexample
2066extern void
2067transpose (int N, int M, double out[M][N], const double in[N][M]);
2068double x[3][2];
2069double y[2][3];
2070@r{@dots{}}
2071transpose(3, 2, y, x);
2072@end smallexample
2073
2074@node Initializers
2075@section Non-Constant Initializers
2076@cindex initializers, non-constant
2077@cindex non-constant initializers
2078
2079As in standard C++ and ISO C99, the elements of an aggregate initializer for an
2080automatic variable are not required to be constant expressions in GNU C@.
2081Here is an example of an initializer with run-time varying elements:
2082
2083@smallexample
2084foo (float f, float g)
2085@{
2086 float beat_freqs[2] = @{ f-g, f+g @};
2087 /* @r{@dots{}} */
2088@}
2089@end smallexample
2090
2091@node Compound Literals
2092@section Compound Literals
2093@cindex constructor expressions
2094@cindex initializations in expressions
2095@cindex structures, constructor expression
2096@cindex expressions, constructor
2097@cindex compound literals
2098@c The GNU C name for what C99 calls compound literals was "constructor expressions".
2099
2100A compound literal looks like a cast of a brace-enclosed aggregate
2101initializer list. Its value is an object of the type specified in
2102the cast, containing the elements specified in the initializer.
2103Unlike the result of a cast, a compound literal is an lvalue. ISO
2104C99 and later support compound literals. As an extension, GCC
2105supports compound literals also in C90 mode and in C++, although
2106as explained below, the C++ semantics are somewhat different.
2107
2108Usually, the specified type of a compound literal is a structure. Assume
2109that @code{struct foo} and @code{structure} are declared as shown:
2110
2111@smallexample
2112struct foo @{int a; char b[2];@} structure;
2113@end smallexample
2114
2115@noindent
2116Here is an example of constructing a @code{struct foo} with a compound literal:
2117
2118@smallexample
2119structure = ((struct foo) @{x + y, 'a', 0@});
2120@end smallexample
2121
2122@noindent
2123This is equivalent to writing the following:
2124
2125@smallexample
2126@{
2127 struct foo temp = @{x + y, 'a', 0@};
2128 structure = temp;
2129@}
2130@end smallexample
2131
2132You can also construct an array, though this is dangerous in C++, as
2133explained below. If all the elements of the compound literal are
2134(made up of) simple constant expressions suitable for use in
2135initializers of objects of static storage duration, then the compound
2136literal can be coerced to a pointer to its first element and used in
2137such an initializer, as shown here:
2138
2139@smallexample
2140char **foo = (char *[]) @{ "x", "y", "z" @};
2141@end smallexample
2142
2143Compound literals for scalar types and union types are also allowed. In
2144the following example the variable @code{i} is initialized to the value
2145@code{2}, the result of incrementing the unnamed object created by
2146the compound literal.
2147
2148@smallexample
2149int i = ++(int) @{ 1 @};
2150@end smallexample
2151
2152As a GNU extension, GCC allows initialization of objects with static storage
2153duration by compound literals (which is not possible in ISO C99 because
2154the initializer is not a constant).
2155It is handled as if the object were initialized only with the brace-enclosed
2156list if the types of the compound literal and the object match.
2157The elements of the compound literal must be constant.
2158If the object being initialized has array type of unknown size, the size is
2159determined by the size of the compound literal.
2160
2161@smallexample
2162static struct foo x = (struct foo) @{1, 'a', 'b'@};
2163static int y[] = (int []) @{1, 2, 3@};
2164static int z[] = (int [3]) @{1@};
2165@end smallexample
2166
2167@noindent
2168The above lines are equivalent to the following:
2169@smallexample
2170static struct foo x = @{1, 'a', 'b'@};
2171static int y[] = @{1, 2, 3@};
2172static int z[] = @{1, 0, 0@};
2173@end smallexample
2174
2175In C, a compound literal designates an unnamed object with static or
2176automatic storage duration. In C++, a compound literal designates a
2177temporary object that only lives until the end of its full-expression.
2178As a result, well-defined C code that takes the address of a subobject
2179of a compound literal can be undefined in C++, so G++ rejects
2180the conversion of a temporary array to a pointer. For instance, if
2181the array compound literal example above appeared inside a function,
2182any subsequent use of @code{foo} in C++ would have undefined behavior
2183because the lifetime of the array ends after the declaration of @code{foo}.
2184
2185As an optimization, G++ sometimes gives array compound literals longer
2186lifetimes: when the array either appears outside a function or has
2187a @code{const}-qualified type. If @code{foo} and its initializer had
2188elements of type @code{char *const} rather than @code{char *}, or if
2189@code{foo} were a global variable, the array would have static storage
2190duration. But it is probably safest just to avoid the use of array
2191compound literals in C++ code.
2192
2193@node Designated Inits
2194@section Designated Initializers
2195@cindex initializers with labeled elements
2196@cindex labeled elements in initializers
2197@cindex case labels in initializers
2198@cindex designated initializers
2199
2200Standard C90 requires the elements of an initializer to appear in a fixed
2201order, the same as the order of the elements in the array or structure
2202being initialized.
2203
2204In ISO C99 you can give the elements in any order, specifying the array
2205indices or structure field names they apply to, and GNU C allows this as
2206an extension in C90 mode as well. This extension is not
2207implemented in GNU C++.
2208
2209To specify an array index, write
2210@samp{[@var{index}] =} before the element value. For example,
2211
2212@smallexample
2213int a[6] = @{ [4] = 29, [2] = 15 @};
2214@end smallexample
2215
2216@noindent
2217is equivalent to
2218
2219@smallexample
2220int a[6] = @{ 0, 0, 15, 0, 29, 0 @};
2221@end smallexample
2222
2223@noindent
2224The index values must be constant expressions, even if the array being
2225initialized is automatic.
2226
2227An alternative syntax for this that has been obsolete since GCC 2.5 but
2228GCC still accepts is to write @samp{[@var{index}]} before the element
2229value, with no @samp{=}.
2230
2231To initialize a range of elements to the same value, write
2232@samp{[@var{first} ... @var{last}] = @var{value}}. This is a GNU
2233extension. For example,
2234
2235@smallexample
2236int widths[] = @{ [0 ... 9] = 1, [10 ... 99] = 2, [100] = 3 @};
2237@end smallexample
2238
2239@noindent
2240If the value in it has side effects, the side effects happen only once,
2241not for each initialized field by the range initializer.
2242
2243@noindent
2244Note that the length of the array is the highest value specified
2245plus one.
2246
2247In a structure initializer, specify the name of a field to initialize
2248with @samp{.@var{fieldname} =} before the element value. For example,
2249given the following structure,
2250
2251@smallexample
2252struct point @{ int x, y; @};
2253@end smallexample
2254
2255@noindent
2256the following initialization
2257
2258@smallexample
2259struct point p = @{ .y = yvalue, .x = xvalue @};
2260@end smallexample
2261
2262@noindent
2263is equivalent to
2264
2265@smallexample
2266struct point p = @{ xvalue, yvalue @};
2267@end smallexample
2268
2269Another syntax that has the same meaning, obsolete since GCC 2.5, is
2270@samp{@var{fieldname}:}, as shown here:
2271
2272@smallexample
2273struct point p = @{ y: yvalue, x: xvalue @};
2274@end smallexample
2275
2276Omitted fields are implicitly initialized the same as for objects
2277that have static storage duration.
2278
2279@cindex designators
2280The @samp{[@var{index}]} or @samp{.@var{fieldname}} is known as a
2281@dfn{designator}. You can also use a designator (or the obsolete colon
2282syntax) when initializing a union, to specify which element of the union
2283should be used. For example,
2284
2285@smallexample
2286union foo @{ int i; double d; @};
2287
2288union foo f = @{ .d = 4 @};
2289@end smallexample
2290
2291@noindent
2292converts 4 to a @code{double} to store it in the union using
2293the second element. By contrast, casting 4 to type @code{union foo}
2294stores it into the union as the integer @code{i}, since it is
2295an integer. @xref{Cast to Union}.
2296
2297You can combine this technique of naming elements with ordinary C
2298initialization of successive elements. Each initializer element that
2299does not have a designator applies to the next consecutive element of the
2300array or structure. For example,
2301
2302@smallexample
2303int a[6] = @{ [1] = v1, v2, [4] = v4 @};
2304@end smallexample
2305
2306@noindent
2307is equivalent to
2308
2309@smallexample
2310int a[6] = @{ 0, v1, v2, 0, v4, 0 @};
2311@end smallexample
2312
2313Labeling the elements of an array initializer is especially useful
2314when the indices are characters or belong to an @code{enum} type.
2315For example:
2316
2317@smallexample
2318int whitespace[256]
2319 = @{ [' '] = 1, ['\t'] = 1, ['\h'] = 1,
2320 ['\f'] = 1, ['\n'] = 1, ['\r'] = 1 @};
2321@end smallexample
2322
2323@cindex designator lists
2324You can also write a series of @samp{.@var{fieldname}} and
2325@samp{[@var{index}]} designators before an @samp{=} to specify a
2326nested subobject to initialize; the list is taken relative to the
2327subobject corresponding to the closest surrounding brace pair. For
2328example, with the @samp{struct point} declaration above:
2329
2330@smallexample
2331struct point ptarray[10] = @{ [2].y = yv2, [2].x = xv2, [0].x = xv0 @};
2332@end smallexample
2333
2334If the same field is initialized multiple times, or overlapping
2335fields of a union are initialized, the value from the last
2336initialization is used. When a field of a union is itself a structure,
2337the entire structure from the last field initialized is used. If any previous
2338initializer has side effect, it is unspecified whether the side effect
2339happens or not. Currently, GCC discards the side-effecting
2340initializer expressions and issues a warning.
2341
2342@node Case Ranges
2343@section Case Ranges
2344@cindex case ranges
2345@cindex ranges in case statements
2346
2347You can specify a range of consecutive values in a single @code{case} label,
2348like this:
2349
2350@smallexample
2351case @var{low} ... @var{high}:
2352@end smallexample
2353
2354@noindent
2355This has the same effect as the proper number of individual @code{case}
2356labels, one for each integer value from @var{low} to @var{high}, inclusive.
2357
2358This feature is especially useful for ranges of ASCII character codes:
2359
2360@smallexample
2361case 'A' ... 'Z':
2362@end smallexample
2363
2364@strong{Be careful:} Write spaces around the @code{...}, for otherwise
2365it may be parsed wrong when you use it with integer values. For example,
2366write this:
2367
2368@smallexample
2369case 1 ... 5:
2370@end smallexample
2371
2372@noindent
2373rather than this:
2374
2375@smallexample
2376case 1...5:
2377@end smallexample
2378
2379@node Cast to Union
2380@section Cast to a Union Type
2381@cindex cast to a union
2382@cindex union, casting to a
2383
2384A cast to a union type is a C extension not available in C++. It looks
2385just like ordinary casts with the constraint that the type specified is
2386a union type. You can specify the type either with the @code{union}
2387keyword or with a @code{typedef} name that refers to a union. The result
2388of a cast to a union is a temporary rvalue of the union type with a member
2389whose type matches that of the operand initialized to the value of
2390the operand. The effect of a cast to a union is similar to a compound
2391literal except that it yields an rvalue like standard casts do.
2392@xref{Compound Literals}.
2393
2394Expressions that may be cast to the union type are those whose type matches
2395at least one of the members of the union. Thus, given the following union
2396and variables:
2397
2398@smallexample
2399union foo @{ int i; double d; @};
2400int x;
2401double y;
2402union foo z;
2403@end smallexample
2404
2405@noindent
2406both @code{x} and @code{y} can be cast to type @code{union foo} and
2407the following assignments
2408@smallexample
2409 z = (union foo) x;
2410 z = (union foo) y;
2411@end smallexample
2412are shorthand equivalents of these
2413@smallexample
2414 z = (union foo) @{ .i = x @};
2415 z = (union foo) @{ .d = y @};
2416@end smallexample
2417
2418However, @code{(union foo) FLT_MAX;} is not a valid cast because the union
2419has no member of type @code{float}.
2420
2421Using the cast as the right-hand side of an assignment to a variable of
2422union type is equivalent to storing in a member of the union with
2423the same type
2424
2425@smallexample
2426union foo u;
2427/* @r{@dots{}} */
2428u = (union foo) x @equiv{} u.i = x
2429u = (union foo) y @equiv{} u.d = y
2430@end smallexample
2431
2432You can also use the union cast as a function argument:
2433
2434@smallexample
2435void hack (union foo);
2436/* @r{@dots{}} */
2437hack ((union foo) x);
2438@end smallexample
2439
2440@node Mixed Labels and Declarations
2441@section Mixed Declarations, Labels and Code
2442@cindex mixed declarations and code
2443@cindex declarations, mixed with code
2444@cindex code, mixed with declarations
2445
2446ISO C99 and ISO C++ allow declarations and code to be freely mixed
2447within compound statements. ISO C2X allows labels to be
2448placed before declarations and at the end of a compound statement.
2449As an extension, GNU C also allows all this in C90 mode. For example,
2450you could do:
2451
2452@smallexample
2453int i;
2454/* @r{@dots{}} */
2455i++;
2456int j = i + 2;
2457@end smallexample
2458
2459Each identifier is visible from where it is declared until the end of
2460the enclosing block.
2461
2462@node Function Attributes
2463@section Declaring Attributes of Functions
2464@cindex function attributes
2465@cindex declaring attributes of functions
2466@cindex @code{volatile} applied to function
2467@cindex @code{const} applied to function
2468
2469In GNU C and C++, you can use function attributes to specify certain
2470function properties that may help the compiler optimize calls or
2471check code more carefully for correctness. For example, you
2472can use attributes to specify that a function never returns
2473(@code{noreturn}), returns a value depending only on the values of
2474its arguments (@code{const}), or has @code{printf}-style arguments
2475(@code{format}).
2476
2477You can also use attributes to control memory placement, code
2478generation options or call/return conventions within the function
2479being annotated. Many of these attributes are target-specific. For
2480example, many targets support attributes for defining interrupt
2481handler functions, which typically must follow special register usage
2482and return conventions. Such attributes are described in the subsection
2483for each target. However, a considerable number of attributes are
2484supported by most, if not all targets. Those are described in
2485the @ref{Common Function Attributes} section.
2486
2487Function attributes are introduced by the @code{__attribute__} keyword
2488in the declaration of a function, followed by an attribute specification
2489enclosed in double parentheses. You can specify multiple attributes in
2490a declaration by separating them by commas within the double parentheses
2491or by immediately following one attribute specification with another.
2492@xref{Attribute Syntax}, for the exact rules on attribute syntax and
2493placement. Compatible attribute specifications on distinct declarations
2494of the same function are merged. An attribute specification that is not
2495compatible with attributes already applied to a declaration of the same
2496function is ignored with a warning.
2497
2498Some function attributes take one or more arguments that refer to
2499the function's parameters by their positions within the function parameter
2500list. Such attribute arguments are referred to as @dfn{positional arguments}.
2501Unless specified otherwise, positional arguments that specify properties
2502of parameters with pointer types can also specify the same properties of
2503the implicit C++ @code{this} argument in non-static member functions, and
2504of parameters of reference to a pointer type. For ordinary functions,
2505position one refers to the first parameter on the list. In C++ non-static
2506member functions, position one refers to the implicit @code{this} pointer.
2507The same restrictions and effects apply to function attributes used with
2508ordinary functions or C++ member functions.
2509
2510GCC also supports attributes on
2511variable declarations (@pxref{Variable Attributes}),
2512labels (@pxref{Label Attributes}),
2513enumerators (@pxref{Enumerator Attributes}),
2514statements (@pxref{Statement Attributes}),
2515types (@pxref{Type Attributes}),
2516and on field declarations (for @code{tainted_args}).
2517
2518There is some overlap between the purposes of attributes and pragmas
2519(@pxref{Pragmas,,Pragmas Accepted by GCC}). It has been
2520found convenient to use @code{__attribute__} to achieve a natural
2521attachment of attributes to their corresponding declarations, whereas
2522@code{#pragma} is of use for compatibility with other compilers
2523or constructs that do not naturally form part of the grammar.
2524
2525In addition to the attributes documented here,
2526GCC plugins may provide their own attributes.
2527
2528@menu
2529* Common Function Attributes::
2530* AArch64 Function Attributes::
2531* AMD GCN Function Attributes::
2532* ARC Function Attributes::
2533* ARM Function Attributes::
2534* AVR Function Attributes::
2535* Blackfin Function Attributes::
2536* BPF Function Attributes::
2537* C-SKY Function Attributes::
2538* Epiphany Function Attributes::
2539* H8/300 Function Attributes::
2540* IA-64 Function Attributes::
2541* M32C Function Attributes::
2542* M32R/D Function Attributes::
2543* m68k Function Attributes::
2544* MCORE Function Attributes::
d77de738
ML
2545* MicroBlaze Function Attributes::
2546* Microsoft Windows Function Attributes::
2547* MIPS Function Attributes::
2548* MSP430 Function Attributes::
2549* NDS32 Function Attributes::
2550* Nios II Function Attributes::
2551* Nvidia PTX Function Attributes::
2552* PowerPC Function Attributes::
2553* RISC-V Function Attributes::
2554* RL78 Function Attributes::
2555* RX Function Attributes::
2556* S/390 Function Attributes::
2557* SH Function Attributes::
2558* Symbian OS Function Attributes::
2559* V850 Function Attributes::
2560* Visium Function Attributes::
2561* x86 Function Attributes::
2562* Xstormy16 Function Attributes::
2563@end menu
2564
2565@node Common Function Attributes
2566@subsection Common Function Attributes
2567
2568The following attributes are supported on most targets.
2569
2570@table @code
2571@c Keep this table alphabetized by attribute name. Treat _ as space.
2572
2573@item access (@var{access-mode}, @var{ref-index})
2574@itemx access (@var{access-mode}, @var{ref-index}, @var{size-index})
2575
2576The @code{access} attribute enables the detection of invalid or unsafe
2577accesses by functions to which they apply or their callers, as well as
2578write-only accesses to objects that are never read from. Such accesses
2579may be diagnosed by warnings such as @option{-Wstringop-overflow},
2580@option{-Wuninitialized}, @option{-Wunused}, and others.
2581
2582The @code{access} attribute specifies that a function to whose by-reference
2583arguments the attribute applies accesses the referenced object according to
2584@var{access-mode}. The @var{access-mode} argument is required and must be
2585one of four names: @code{read_only}, @code{read_write}, @code{write_only},
2586or @code{none}. The remaining two are positional arguments.
2587
2588The required @var{ref-index} positional argument denotes a function
2589argument of pointer (or in C++, reference) type that is subject to
2590the access. The same pointer argument can be referenced by at most one
2591distinct @code{access} attribute.
2592
2593The optional @var{size-index} positional argument denotes a function
2594argument of integer type that specifies the maximum size of the access.
2595The size is the number of elements of the type referenced by @var{ref-index},
2596or the number of bytes when the pointer type is @code{void*}. When no
2597@var{size-index} argument is specified, the pointer argument must be either
2598null or point to a space that is suitably aligned and large for at least one
2599object of the referenced type (this implies that a past-the-end pointer is
2600not a valid argument). The actual size of the access may be less but it
2601must not be more.
2602
2603The @code{read_only} access mode specifies that the pointer to which it
2604applies is used to read the referenced object but not write to it. Unless
2605the argument specifying the size of the access denoted by @var{size-index}
2606is zero, the referenced object must be initialized. The mode implies
2607a stronger guarantee than the @code{const} qualifier which, when cast away
2608from a pointer, does not prevent the pointed-to object from being modified.
2609Examples of the use of the @code{read_only} access mode is the argument to
2610the @code{puts} function, or the second and third arguments to
2611the @code{memcpy} function.
2612
2613@smallexample
4ace81b6
SL
2614__attribute__ ((access (read_only, 1)))
2615int puts (const char*);
2616
2617__attribute__ ((access (read_only, 2, 3)))
2618void* memcpy (void*, const void*, size_t);
d77de738
ML
2619@end smallexample
2620
2621The @code{read_write} access mode applies to arguments of pointer types
2622without the @code{const} qualifier. It specifies that the pointer to which
2623it applies is used to both read and write the referenced object. Unless
2624the argument specifying the size of the access denoted by @var{size-index}
2625is zero, the object referenced by the pointer must be initialized. An example
2626of the use of the @code{read_write} access mode is the first argument to
2627the @code{strcat} function.
2628
2629@smallexample
4ace81b6
SL
2630__attribute__ ((access (read_write, 1), access (read_only, 2)))
2631char* strcat (char*, const char*);
d77de738
ML
2632@end smallexample
2633
2634The @code{write_only} access mode applies to arguments of pointer types
2635without the @code{const} qualifier. It specifies that the pointer to which
2636it applies is used to write to the referenced object but not read from it.
2637The object referenced by the pointer need not be initialized. An example
2638of the use of the @code{write_only} access mode is the first argument to
2639the @code{strcpy} function, or the first two arguments to the @code{fgets}
2640function.
2641
2642@smallexample
4ace81b6
SL
2643__attribute__ ((access (write_only, 1), access (read_only, 2)))
2644char* strcpy (char*, const char*);
2645
2646__attribute__ ((access (write_only, 1, 2), access (read_write, 3)))
2647int fgets (char*, int, FILE*);
d77de738
ML
2648@end smallexample
2649
2650The access mode @code{none} specifies that the pointer to which it applies
2651is not used to access the referenced object at all. Unless the pointer is
2652null the pointed-to object must exist and have at least the size as denoted
2653by the @var{size-index} argument. When the optional @var{size-index}
2654argument is omitted for an argument of @code{void*} type the actual pointer
2655agument is ignored. The referenced object need not be initialized.
2656The mode is intended to be used as a means to help validate the expected
2657object size, for example in functions that call @code{__builtin_object_size}.
2658@xref{Object Size Checking}.
2659
2660Note that the @code{access} attribute merely specifies how an object
2661referenced by the pointer argument can be accessed; it does not imply that
2662an access @strong{will} happen. Also, the @code{access} attribute does not
2663imply the attribute @code{nonnull}; it may be appropriate to add both attributes
2664at the declaration of a function that unconditionally manipulates a buffer via
2665a pointer argument. See the @code{nonnull} attribute for more information and
2666caveats.
2667
d77de738 2668@cindex @code{alias} function attribute
f33d7a88 2669@item alias ("@var{target}")
d77de738
ML
2670The @code{alias} attribute causes the declaration to be emitted as an alias
2671for another symbol, which must have been previously declared with the same
2672type, and for variables, also the same size and alignment. Declaring an alias
2673with a different type than the target is undefined and may be diagnosed. As
2674an example, the following declarations:
2675
2676@smallexample
2677void __f () @{ /* @r{Do something.} */; @}
2678void f () __attribute__ ((weak, alias ("__f")));
2679@end smallexample
2680
2681@noindent
2682define @samp{f} to be a weak alias for @samp{__f}. In C++, the mangled name
2683for the target must be used. It is an error if @samp{__f} is not defined in
2684the same translation unit.
2685
2686This attribute requires assembler and object file support,
2687and may not be available on all targets.
2688
f33d7a88 2689@cindex @code{aligned} function attribute
d77de738
ML
2690@item aligned
2691@itemx aligned (@var{alignment})
d77de738
ML
2692The @code{aligned} attribute specifies a minimum alignment for
2693the first instruction of the function, measured in bytes. When specified,
2694@var{alignment} must be an integer constant power of 2. Specifying no
2695@var{alignment} argument implies the ideal alignment for the target.
2696The @code{__alignof__} operator can be used to determine what that is
2697(@pxref{Alignment}). The attribute has no effect when a definition for
2698the function is not provided in the same translation unit.
2699
2700The attribute cannot be used to decrease the alignment of a function
2701previously declared with a more restrictive alignment; only to increase
2702it. Attempts to do otherwise are diagnosed. Some targets specify
2703a minimum default alignment for functions that is greater than 1. On
2704such targets, specifying a less restrictive alignment is silently ignored.
2705Using the attribute overrides the effect of the @option{-falign-functions}
2706(@pxref{Optimize Options}) option for this function.
2707
2708Note that the effectiveness of @code{aligned} attributes may be
2709limited by inherent limitations in the system linker
2710and/or object file format. On some systems, the
2711linker is only able to arrange for functions to be aligned up to a
2712certain maximum alignment. (For some linkers, the maximum supported
2713alignment may be very very small.) See your linker documentation for
2714further information.
2715
2716The @code{aligned} attribute can also be used for variables and fields
2717(@pxref{Variable Attributes}.)
2718
d77de738 2719@cindex @code{alloc_align} function attribute
f33d7a88 2720@item alloc_align (@var{position})
d77de738
ML
2721The @code{alloc_align} attribute may be applied to a function that
2722returns a pointer and takes at least one argument of an integer or
2723enumerated type.
2724It indicates that the returned pointer is aligned on a boundary given
2725by the function argument at @var{position}. Meaningful alignments are
2726powers of 2 greater than one. GCC uses this information to improve
2727pointer alignment analysis.
2728
2729The function parameter denoting the allocated alignment is specified by
2730one constant integer argument whose number is the argument of the attribute.
2731Argument numbering starts at one.
2732
2733For instance,
2734
2735@smallexample
2736void* my_memalign (size_t, size_t) __attribute__ ((alloc_align (1)));
2737@end smallexample
2738
2739@noindent
2740declares that @code{my_memalign} returns memory with minimum alignment
2741given by parameter 1.
2742
f33d7a88 2743@cindex @code{alloc_size} function attribute
d77de738
ML
2744@item alloc_size (@var{position})
2745@itemx alloc_size (@var{position-1}, @var{position-2})
d77de738
ML
2746The @code{alloc_size} attribute may be applied to a function that
2747returns a pointer and takes at least one argument of an integer or
2748enumerated type.
2749It indicates that the returned pointer points to memory whose size is
2750given by the function argument at @var{position-1}, or by the product
2751of the arguments at @var{position-1} and @var{position-2}. Meaningful
2752sizes are positive values less than @code{PTRDIFF_MAX}. GCC uses this
2753information to improve the results of @code{__builtin_object_size}.
2754
2755The function parameter(s) denoting the allocated size are specified by
2756one or two integer arguments supplied to the attribute. The allocated size
2757is either the value of the single function argument specified or the product
2758of the two function arguments specified. Argument numbering starts at
2759one for ordinary functions, and at two for C++ non-static member functions.
2760
2761For instance,
2762
2763@smallexample
2764void* my_calloc (size_t, size_t) __attribute__ ((alloc_size (1, 2)));
2765void* my_realloc (void*, size_t) __attribute__ ((alloc_size (2)));
2766@end smallexample
2767
2768@noindent
2769declares that @code{my_calloc} returns memory of the size given by
2770the product of parameter 1 and 2 and that @code{my_realloc} returns memory
2771of the size given by parameter 2.
2772
d77de738 2773@cindex @code{always_inline} function attribute
f33d7a88 2774@item always_inline
d77de738
ML
2775Generally, functions are not inlined unless optimization is specified.
2776For functions declared inline, this attribute inlines the function
2777independent of any restrictions that otherwise apply to inlining.
2778Failure to inline such a function is diagnosed as an error.
2779Note that if such a function is called indirectly the compiler may
2780or may not inline it depending on optimization level and a failure
2781to inline an indirect call may or may not be diagnosed.
2782
d77de738 2783@cindex @code{artificial} function attribute
f33d7a88 2784@item artificial
d77de738
ML
2785This attribute is useful for small inline wrappers that if possible
2786should appear during debugging as a unit. Depending on the debug
2787info format it either means marking the function as artificial
2788or using the caller location for all instructions within the inlined
2789body.
2790
f33d7a88 2791@cindex @code{assume_aligned} function attribute
d77de738
ML
2792@item assume_aligned (@var{alignment})
2793@itemx assume_aligned (@var{alignment}, @var{offset})
d77de738
ML
2794The @code{assume_aligned} attribute may be applied to a function that
2795returns a pointer. It indicates that the returned pointer is aligned
2796on a boundary given by @var{alignment}. If the attribute has two
2797arguments, the second argument is misalignment @var{offset}. Meaningful
2798values of @var{alignment} are powers of 2 greater than one. Meaningful
2799values of @var{offset} are greater than zero and less than @var{alignment}.
2800
2801For instance
2802
2803@smallexample
2804void* my_alloc1 (size_t) __attribute__((assume_aligned (16)));
2805void* my_alloc2 (size_t) __attribute__((assume_aligned (32, 8)));
2806@end smallexample
2807
2808@noindent
2809declares that @code{my_alloc1} returns 16-byte aligned pointers and
2810that @code{my_alloc2} returns a pointer whose value modulo 32 is equal
2811to 8.
2812
d77de738 2813@cindex @code{cold} function attribute
f33d7a88 2814@item cold
d77de738
ML
2815The @code{cold} attribute on functions is used to inform the compiler that
2816the function is unlikely to be executed. The function is optimized for
2817size rather than speed and on many targets it is placed into a special
2818subsection of the text section so all cold functions appear close together,
2819improving code locality of non-cold parts of program. The paths leading
2820to calls of cold functions within code are marked as unlikely by the branch
2821prediction mechanism. It is thus useful to mark functions used to handle
2822unlikely conditions, such as @code{perror}, as cold to improve optimization
2823of hot functions that do call marked functions in rare occasions.
2824
2825When profile feedback is available, via @option{-fprofile-use}, cold functions
2826are automatically detected and this attribute is ignored.
2827
d77de738
ML
2828@cindex @code{const} function attribute
2829@cindex functions that have no side effects
f33d7a88 2830@item const
d77de738
ML
2831Calls to functions whose return value is not affected by changes to
2832the observable state of the program and that have no observable effects
2833on such state other than to return a value may lend themselves to
2834optimizations such as common subexpression elimination. Declaring such
2835functions with the @code{const} attribute allows GCC to avoid emitting
2836some calls in repeated invocations of the function with the same argument
2837values.
2838
2839For example,
2840
2841@smallexample
2842int square (int) __attribute__ ((const));
2843@end smallexample
2844
2845@noindent
2846tells GCC that subsequent calls to function @code{square} with the same
2847argument value can be replaced by the result of the first call regardless
2848of the statements in between.
2849
2850The @code{const} attribute prohibits a function from reading objects
2851that affect its return value between successive invocations. However,
2852functions declared with the attribute can safely read objects that do
2853not change their return value, such as non-volatile constants.
2854
2855The @code{const} attribute imposes greater restrictions on a function's
2856definition than the similar @code{pure} attribute. Declaring the same
2857function with both the @code{const} and the @code{pure} attribute is
2858diagnosed. Because a const function cannot have any observable side
2859effects it does not make sense for it to return @code{void}. Declaring
2860such a function is diagnosed.
2861
2862@cindex pointer arguments
2863Note that a function that has pointer arguments and examines the data
2864pointed to must @emph{not} be declared @code{const} if the pointed-to
2865data might change between successive invocations of the function. In
2866general, since a function cannot distinguish data that might change
2867from data that cannot, const functions should never take pointer or,
2868in C++, reference arguments. Likewise, a function that calls a non-const
2869function usually must not be const itself.
2870
f33d7a88
AA
2871@cindex @code{constructor} function attribute
2872@cindex @code{destructor} function attribute
d77de738
ML
2873@item constructor
2874@itemx destructor
2875@itemx constructor (@var{priority})
2876@itemx destructor (@var{priority})
d77de738
ML
2877The @code{constructor} attribute causes the function to be called
2878automatically before execution enters @code{main ()}. Similarly, the
2879@code{destructor} attribute causes the function to be called
2880automatically after @code{main ()} completes or @code{exit ()} is
2881called. Functions with these attributes are useful for
2882initializing data that is used implicitly during the execution of
2883the program.
2884
2885On some targets the attributes also accept an integer argument to
2886specify a priority to control the order in which constructor and
2887destructor functions are run. A constructor
2888with a smaller priority number runs before a constructor with a larger
2889priority number; the opposite relationship holds for destructors. Note
2890that priorities 0-100 are reserved. So, if you have a constructor that
2891allocates a resource and a destructor that deallocates the same
2892resource, both functions typically have the same priority. The
2893priorities for constructor and destructor functions are the same as
2894those specified for namespace-scope C++ objects (@pxref{C++ Attributes}).
2895However, at present, the order in which constructors for C++ objects
2896with static storage duration and functions decorated with attribute
2897@code{constructor} are invoked is unspecified. In mixed declarations,
2898attribute @code{init_priority} can be used to impose a specific ordering.
2899
2900Using the argument forms of the @code{constructor} and @code{destructor}
2901attributes on targets where the feature is not supported is rejected with
2902an error.
2903
f33d7a88 2904@cindex @code{copy} function attribute
d77de738
ML
2905@item copy
2906@itemx copy (@var{function})
d77de738
ML
2907The @code{copy} attribute applies the set of attributes with which
2908@var{function} has been declared to the declaration of the function
2909to which the attribute is applied. The attribute is designed for
2910libraries that define aliases or function resolvers that are expected
2911to specify the same set of attributes as their targets. The @code{copy}
2912attribute can be used with functions, variables, or types. However,
2913the kind of symbol to which the attribute is applied (either function
2914or variable) must match the kind of symbol to which the argument refers.
2915The @code{copy} attribute copies only syntactic and semantic attributes
2916but not attributes that affect a symbol's linkage or visibility such as
2917@code{alias}, @code{visibility}, or @code{weak}. The @code{deprecated}
2918and @code{target_clones} attribute are also not copied.
2919@xref{Common Type Attributes}.
2920@xref{Common Variable Attributes}.
2921
2922For example, the @var{StrongAlias} macro below makes use of the @code{alias}
2923and @code{copy} attributes to define an alias named @var{alloc} for function
2924@var{allocate} declared with attributes @var{alloc_size}, @var{malloc}, and
2925@var{nothrow}. Thanks to the @code{__typeof__} operator the alias has
2926the same type as the target function. As a result of the @code{copy}
2927attribute the alias also shares the same attributes as the target.
2928
2929@smallexample
2930#define StrongAlias(TargetFunc, AliasDecl) \
2931 extern __typeof__ (TargetFunc) AliasDecl \
2932 __attribute__ ((alias (#TargetFunc), copy (TargetFunc)));
2933
2934extern __attribute__ ((alloc_size (1), malloc, nothrow))
2935 void* allocate (size_t);
2936StrongAlias (allocate, alloc);
2937@end smallexample
2938
f33d7a88 2939@cindex @code{deprecated} function attribute
d77de738
ML
2940@item deprecated
2941@itemx deprecated (@var{msg})
d77de738
ML
2942The @code{deprecated} attribute results in a warning if the function
2943is used anywhere in the source file. This is useful when identifying
2944functions that are expected to be removed in a future version of a
2945program. The warning also includes the location of the declaration
2946of the deprecated function, to enable users to easily find further
2947information about why the function is deprecated, or what they should
2948do instead. Note that the warnings only occurs for uses:
2949
2950@smallexample
2951int old_fn () __attribute__ ((deprecated));
2952int old_fn ();
2953int (*fn_ptr)() = old_fn;
2954@end smallexample
2955
2956@noindent
2957results in a warning on line 3 but not line 2. The optional @var{msg}
2958argument, which must be a string, is printed in the warning if
2959present.
2960
2961The @code{deprecated} attribute can also be used for variables and
2962types (@pxref{Variable Attributes}, @pxref{Type Attributes}.)
2963
2964The message attached to the attribute is affected by the setting of
2965the @option{-fmessage-length} option.
2966
f33d7a88 2967@cindex @code{unavailable} function attribute
d77de738
ML
2968@item unavailable
2969@itemx unavailable (@var{msg})
d77de738
ML
2970The @code{unavailable} attribute results in an error if the function
2971is used anywhere in the source file. This is useful when identifying
2972functions that have been removed from a particular variation of an
2973interface. Other than emitting an error rather than a warning, the
2974@code{unavailable} attribute behaves in the same manner as
2975@code{deprecated}.
2976
2977The @code{unavailable} attribute can also be used for variables and
2978types (@pxref{Variable Attributes}, @pxref{Type Attributes}.)
2979
d77de738
ML
2980@cindex @code{error} function attribute
2981@cindex @code{warning} function attribute
f33d7a88
AA
2982@item error ("@var{message}")
2983@itemx warning ("@var{message}")
d77de738
ML
2984If the @code{error} or @code{warning} attribute
2985is used on a function declaration and a call to such a function
2986is not eliminated through dead code elimination or other optimizations,
2987an error or warning (respectively) that includes @var{message} is diagnosed.
2988This is useful
2989for compile-time checking, especially together with @code{__builtin_constant_p}
2990and inline functions where checking the inline function arguments is not
2991possible through @code{extern char [(condition) ? 1 : -1];} tricks.
2992
2993While it is possible to leave the function undefined and thus invoke
2994a link failure (to define the function with
2995a message in @code{.gnu.warning*} section),
2996when using these attributes the problem is diagnosed
2997earlier and with exact location of the call even in presence of inline
2998functions or when not emitting debugging information.
2999
d77de738 3000@cindex @code{externally_visible} function attribute
f33d7a88 3001@item externally_visible
d77de738
ML
3002This attribute, attached to a global variable or function, nullifies
3003the effect of the @option{-fwhole-program} command-line option, so the
3004object remains visible outside the current compilation unit.
3005
3006If @option{-fwhole-program} is used together with @option{-flto} and
3007@command{gold} is used as the linker plugin,
3008@code{externally_visible} attributes are automatically added to functions
3009(not variable yet due to a current @command{gold} issue)
3010that are accessed outside of LTO objects according to resolution file
3011produced by @command{gold}.
3012For other linkers that cannot generate resolution file,
3013explicit @code{externally_visible} attributes are still necessary.
3014
f33d7a88 3015@cindex @code{fd_arg} function attribute
d77de738
ML
3016@item fd_arg
3017@itemx fd_arg (@var{N})
d77de738
ML
3018The @code{fd_arg} attribute may be applied to a function that takes an open
3019file descriptor at referenced argument @var{N}.
3020
3021It indicates that the passed filedescriptor must not have been closed.
3022Therefore, when the analyzer is enabled with @option{-fanalyzer}, the
3023analyzer may emit a @option{-Wanalyzer-fd-use-after-close} diagnostic
3024if it detects a code path in which a function with this attribute is
3025called with a closed file descriptor.
3026
3027The attribute also indicates that the file descriptor must have been checked for
3028validity before usage. Therefore, analyzer may emit
3029@option{-Wanalyzer-fd-use-without-check} diagnostic if it detects a code path in
3030which a function with this attribute is called with a file descriptor that has
3031not been checked for validity.
3032
f33d7a88 3033@cindex @code{fd_arg_read} function attribute
d77de738
ML
3034@item fd_arg_read
3035@itemx fd_arg_read (@var{N})
d77de738
ML
3036The @code{fd_arg_read} is identical to @code{fd_arg}, but with the additional
3037requirement that it might read from the file descriptor, and thus, the file
3038descriptor must not have been opened as write-only.
3039
3040The analyzer may emit a @option{-Wanalyzer-access-mode-mismatch}
3041diagnostic if it detects a code path in which a function with this
3042attribute is called on a file descriptor opened with @code{O_WRONLY}.
3043
f33d7a88 3044@cindex @code{fd_arg_write} function attribute
d77de738
ML
3045@item fd_arg_write
3046@itemx fd_arg_write (@var{N})
d77de738
ML
3047The @code{fd_arg_write} is identical to @code{fd_arg_read} except that the
3048analyzer may emit a @option{-Wanalyzer-access-mode-mismatch} diagnostic if
3049it detects a code path in which a function with this attribute is called on a
3050file descriptor opened with @code{O_RDONLY}.
3051
d77de738 3052@cindex @code{flatten} function attribute
f33d7a88 3053@item flatten
d77de738
ML
3054Generally, inlining into a function is limited. For a function marked with
3055this attribute, every call inside this function is inlined, if possible.
3056Functions declared with attribute @code{noinline} and similar are not
3057inlined. Whether the function itself is considered for inlining depends
3058on its size and the current inlining parameters.
3059
d77de738
ML
3060@cindex @code{format} function attribute
3061@cindex functions with @code{printf}, @code{scanf}, @code{strftime} or @code{strfmon} style arguments
3062@opindex Wformat
f33d7a88 3063@item format (@var{archetype}, @var{string-index}, @var{first-to-check})
d77de738
ML
3064The @code{format} attribute specifies that a function takes @code{printf},
3065@code{scanf}, @code{strftime} or @code{strfmon} style arguments that
3066should be type-checked against a format string. For example, the
3067declaration:
3068
3069@smallexample
3070extern int
3071my_printf (void *my_object, const char *my_format, ...)
3072 __attribute__ ((format (printf, 2, 3)));
3073@end smallexample
3074
3075@noindent
3076causes the compiler to check the arguments in calls to @code{my_printf}
3077for consistency with the @code{printf} style format string argument
3078@code{my_format}.
3079
3080The parameter @var{archetype} determines how the format string is
3081interpreted, and should be @code{printf}, @code{scanf}, @code{strftime},
3082@code{gnu_printf}, @code{gnu_scanf}, @code{gnu_strftime} or
3083@code{strfmon}. (You can also use @code{__printf__},
3084@code{__scanf__}, @code{__strftime__} or @code{__strfmon__}.) On
3085MinGW targets, @code{ms_printf}, @code{ms_scanf}, and
3086@code{ms_strftime} are also present.
3087@var{archetype} values such as @code{printf} refer to the formats accepted
3088by the system's C runtime library,
3089while values prefixed with @samp{gnu_} always refer
3090to the formats accepted by the GNU C Library. On Microsoft Windows
3091targets, values prefixed with @samp{ms_} refer to the formats accepted by the
3092@file{msvcrt.dll} library.
3093The parameter @var{string-index}
3094specifies which argument is the format string argument (starting
3095from 1), while @var{first-to-check} is the number of the first
3096argument to check against the format string. For functions
3097where the arguments are not available to be checked (such as
3098@code{vprintf}), specify the third parameter as zero. In this case the
3099compiler only checks the format string for consistency. For
3100@code{strftime} formats, the third parameter is required to be zero.
3101Since non-static C++ methods have an implicit @code{this} argument, the
3102arguments of such methods should be counted from two, not one, when
3103giving values for @var{string-index} and @var{first-to-check}.
3104
3105In the example above, the format string (@code{my_format}) is the second
3106argument of the function @code{my_print}, and the arguments to check
3107start with the third argument, so the correct parameters for the format
3108attribute are 2 and 3.
3109
3110@opindex ffreestanding
3111@opindex fno-builtin
3112The @code{format} attribute allows you to identify your own functions
3113that take format strings as arguments, so that GCC can check the
3114calls to these functions for errors. The compiler always (unless
3115@option{-ffreestanding} or @option{-fno-builtin} is used) checks formats
3116for the standard library functions @code{printf}, @code{fprintf},
3117@code{sprintf}, @code{scanf}, @code{fscanf}, @code{sscanf}, @code{strftime},
3118@code{vprintf}, @code{vfprintf} and @code{vsprintf} whenever such
3119warnings are requested (using @option{-Wformat}), so there is no need to
3120modify the header file @file{stdio.h}. In C99 mode, the functions
3121@code{snprintf}, @code{vsnprintf}, @code{vscanf}, @code{vfscanf} and
3122@code{vsscanf} are also checked. Except in strictly conforming C
3123standard modes, the X/Open function @code{strfmon} is also checked as
3124are @code{printf_unlocked} and @code{fprintf_unlocked}.
3125@xref{C Dialect Options,,Options Controlling C Dialect}.
3126
3127For Objective-C dialects, @code{NSString} (or @code{__NSString__}) is
3128recognized in the same context. Declarations including these format attributes
3129are parsed for correct syntax, however the result of checking of such format
3130strings is not yet defined, and is not carried out by this version of the
3131compiler.
3132
3133The target may also provide additional types of format checks.
3134@xref{Target Format Checks,,Format Checks Specific to Particular
3135Target Machines}.
3136
d77de738
ML
3137@cindex @code{format_arg} function attribute
3138@opindex Wformat-nonliteral
f33d7a88 3139@item format_arg (@var{string-index})
d77de738
ML
3140The @code{format_arg} attribute specifies that a function takes one or
3141more format strings for a @code{printf}, @code{scanf}, @code{strftime} or
3142@code{strfmon} style function and modifies it (for example, to translate
3143it into another language), so the result can be passed to a
3144@code{printf}, @code{scanf}, @code{strftime} or @code{strfmon} style
3145function (with the remaining arguments to the format function the same
3146as they would have been for the unmodified string). Multiple
3147@code{format_arg} attributes may be applied to the same function, each
3148designating a distinct parameter as a format string. For example, the
3149declaration:
3150
3151@smallexample
3152extern char *
3153my_dgettext (char *my_domain, const char *my_format)
3154 __attribute__ ((format_arg (2)));
3155@end smallexample
3156
3157@noindent
3158causes the compiler to check the arguments in calls to a @code{printf},
3159@code{scanf}, @code{strftime} or @code{strfmon} type function, whose
3160format string argument is a call to the @code{my_dgettext} function, for
3161consistency with the format string argument @code{my_format}. If the
3162@code{format_arg} attribute had not been specified, all the compiler
3163could tell in such calls to format functions would be that the format
3164string argument is not constant; this would generate a warning when
3165@option{-Wformat-nonliteral} is used, but the calls could not be checked
3166without the attribute.
3167
3168In calls to a function declared with more than one @code{format_arg}
3169attribute, each with a distinct argument value, the corresponding
3170actual function arguments are checked against all format strings
3171designated by the attributes. This capability is designed to support
3172the GNU @code{ngettext} family of functions.
3173
3174The parameter @var{string-index} specifies which argument is the format
3175string argument (starting from one). Since non-static C++ methods have
3176an implicit @code{this} argument, the arguments of such methods should
3177be counted from two.
3178
3179The @code{format_arg} attribute allows you to identify your own
3180functions that modify format strings, so that GCC can check the
3181calls to @code{printf}, @code{scanf}, @code{strftime} or @code{strfmon}
3182type function whose operands are a call to one of your own function.
3183The compiler always treats @code{gettext}, @code{dgettext}, and
3184@code{dcgettext} in this manner except when strict ISO C support is
3185requested by @option{-ansi} or an appropriate @option{-std} option, or
3186@option{-ffreestanding} or @option{-fno-builtin}
3187is used. @xref{C Dialect Options,,Options
3188Controlling C Dialect}.
3189
3190For Objective-C dialects, the @code{format-arg} attribute may refer to an
3191@code{NSString} reference for compatibility with the @code{format} attribute
3192above.
3193
3194The target may also allow additional types in @code{format-arg} attributes.
3195@xref{Target Format Checks,,Format Checks Specific to Particular
3196Target Machines}.
3197
d77de738 3198@cindex @code{gnu_inline} function attribute
f33d7a88 3199@item gnu_inline
d77de738
ML
3200This attribute should be used with a function that is also declared
3201with the @code{inline} keyword. It directs GCC to treat the function
3202as if it were defined in gnu90 mode even when compiling in C99 or
3203gnu99 mode.
3204
3205If the function is declared @code{extern}, then this definition of the
3206function is used only for inlining. In no case is the function
3207compiled as a standalone function, not even if you take its address
3208explicitly. Such an address becomes an external reference, as if you
3209had only declared the function, and had not defined it. This has
3210almost the effect of a macro. The way to use this is to put a
3211function definition in a header file with this attribute, and put
3212another copy of the function, without @code{extern}, in a library
3213file. The definition in the header file causes most calls to the
3214function to be inlined. If any uses of the function remain, they
3215refer to the single copy in the library. Note that the two
3216definitions of the functions need not be precisely the same, although
3217if they do not have the same effect your program may behave oddly.
3218
3219In C, if the function is neither @code{extern} nor @code{static}, then
3220the function is compiled as a standalone function, as well as being
3221inlined where possible.
3222
3223This is how GCC traditionally handled functions declared
3224@code{inline}. Since ISO C99 specifies a different semantics for
3225@code{inline}, this function attribute is provided as a transition
3226measure and as a useful feature in its own right. This attribute is
3227available in GCC 4.1.3 and later. It is available if either of the
3228preprocessor macros @code{__GNUC_GNU_INLINE__} or
3229@code{__GNUC_STDC_INLINE__} are defined. @xref{Inline,,An Inline
3230Function is As Fast As a Macro}.
3231
3232In C++, this attribute does not depend on @code{extern} in any way,
3233but it still requires the @code{inline} keyword to enable its special
3234behavior.
3235
d77de738 3236@cindex @code{hot} function attribute
f33d7a88 3237@item hot
d77de738
ML
3238The @code{hot} attribute on a function is used to inform the compiler that
3239the function is a hot spot of the compiled program. The function is
3240optimized more aggressively and on many targets it is placed into a special
3241subsection of the text section so all hot functions appear close together,
3242improving locality.
3243
3244When profile feedback is available, via @option{-fprofile-use}, hot functions
3245are automatically detected and this attribute is ignored.
3246
d77de738
ML
3247@cindex @code{ifunc} function attribute
3248@cindex indirect functions
3249@cindex functions that are dynamically resolved
f33d7a88 3250@item ifunc ("@var{resolver}")
d77de738
ML
3251The @code{ifunc} attribute is used to mark a function as an indirect
3252function using the STT_GNU_IFUNC symbol type extension to the ELF
3253standard. This allows the resolution of the symbol value to be
3254determined dynamically at load time, and an optimized version of the
3255routine to be selected for the particular processor or other system
3256characteristics determined then. To use this attribute, first define
3257the implementation functions available, and a resolver function that
3258returns a pointer to the selected implementation function. The
3259implementation functions' declarations must match the API of the
3260function being implemented. The resolver should be declared to
3261be a function taking no arguments and returning a pointer to
3262a function of the same type as the implementation. For example:
3263
3264@smallexample
3265void *my_memcpy (void *dst, const void *src, size_t len)
3266@{
3267 @dots{}
3268 return dst;
3269@}
3270
3271static void * (*resolve_memcpy (void))(void *, const void *, size_t)
3272@{
3273 return my_memcpy; // we will just always select this routine
3274@}
3275@end smallexample
3276
3277@noindent
3278The exported header file declaring the function the user calls would
3279contain:
3280
3281@smallexample
3282extern void *memcpy (void *, const void *, size_t);
3283@end smallexample
3284
3285@noindent
3286allowing the user to call @code{memcpy} as a regular function, unaware of
3287the actual implementation. Finally, the indirect function needs to be
3288defined in the same translation unit as the resolver function:
3289
3290@smallexample
3291void *memcpy (void *, const void *, size_t)
3292 __attribute__ ((ifunc ("resolve_memcpy")));
3293@end smallexample
3294
3295In C++, the @code{ifunc} attribute takes a string that is the mangled name
3296of the resolver function. A C++ resolver for a non-static member function
3297of class @code{C} should be declared to return a pointer to a non-member
3298function taking pointer to @code{C} as the first argument, followed by
3299the same arguments as of the implementation function. G++ checks
3300the signatures of the two functions and issues
3301a @option{-Wattribute-alias} warning for mismatches. To suppress a warning
3302for the necessary cast from a pointer to the implementation member function
3303to the type of the corresponding non-member function use
3304the @option{-Wno-pmf-conversions} option. For example:
3305
3306@smallexample
3307class S
3308@{
3309private:
3310 int debug_impl (int);
3311 int optimized_impl (int);
3312
3313 typedef int Func (S*, int);
3314
3315 static Func* resolver ();
3316public:
3317
3318 int interface (int);
3319@};
3320
3321int S::debug_impl (int) @{ /* @r{@dots{}} */ @}
3322int S::optimized_impl (int) @{ /* @r{@dots{}} */ @}
3323
3324S::Func* S::resolver ()
3325@{
3326 int (S::*pimpl) (int)
3327 = getenv ("DEBUG") ? &S::debug_impl : &S::optimized_impl;
3328
3329 // Cast triggers -Wno-pmf-conversions.
3330 return reinterpret_cast<Func*>(pimpl);
3331@}
3332
3333int S::interface (int) __attribute__ ((ifunc ("_ZN1S8resolverEv")));
3334@end smallexample
3335
3336Indirect functions cannot be weak. Binutils version 2.20.1 or higher
3337and GNU C Library version 2.11.1 are required to use this feature.
3338
3339@item interrupt
3340@itemx interrupt_handler
3341Many GCC back ends support attributes to indicate that a function is
3342an interrupt handler, which tells the compiler to generate function
3343entry and exit sequences that differ from those from regular
3344functions. The exact syntax and behavior are target-specific;
3345refer to the following subsections for details.
3346
d77de738 3347@cindex @code{leaf} function attribute
f33d7a88 3348@item leaf
d77de738
ML
3349Calls to external functions with this attribute must return to the
3350current compilation unit only by return or by exception handling. In
3351particular, a leaf function is not allowed to invoke callback functions
3352passed to it from the current compilation unit, directly call functions
3353exported by the unit, or @code{longjmp} into the unit. Leaf functions
3354might still call functions from other compilation units and thus they
3355are not necessarily leaf in the sense that they contain no function
3356calls at all.
3357
3358The attribute is intended for library functions to improve dataflow
3359analysis. The compiler takes the hint that any data not escaping the
3360current compilation unit cannot be used or modified by the leaf
3361function. For example, the @code{sin} function is a leaf function, but
3362@code{qsort} is not.
3363
3364Note that leaf functions might indirectly run a signal handler defined
3365in the current compilation unit that uses static variables. Similarly,
3366when lazy symbol resolution is in effect, leaf functions might invoke
3367indirect functions whose resolver function or implementation function is
3368defined in the current compilation unit and uses static variables. There
3369is no standard-compliant way to write such a signal handler, resolver
3370function, or implementation function, and the best that you can do is to
3371remove the @code{leaf} attribute or mark all such static variables
3372@code{volatile}. Lastly, for ELF-based systems that support symbol
3373interposition, care should be taken that functions defined in the
3374current compilation unit do not unexpectedly interpose other symbols
3375based on the defined standards mode and defined feature test macros;
3376otherwise an inadvertent callback would be added.
3377
3378The attribute has no effect on functions defined within the current
3379compilation unit. This is to allow easy merging of multiple compilation
3380units into one, for example, by using the link-time optimization. For
3381this reason the attribute is not allowed on types to annotate indirect
3382calls.
3383
f33d7a88
AA
3384@cindex @code{malloc} function attribute
3385@cindex functions that behave like malloc
d77de738
ML
3386@item malloc
3387@item malloc (@var{deallocator})
3388@item malloc (@var{deallocator}, @var{ptr-index})
d77de738
ML
3389Attribute @code{malloc} indicates that a function is @code{malloc}-like,
3390i.e., that the pointer @var{P} returned by the function cannot alias any
3391other pointer valid when the function returns, and moreover no
3392pointers to valid objects occur in any storage addressed by @var{P}. In
dfc5ea6b 3393addition, GCC predicts that a function with the attribute returns
d77de738
ML
3394non-null in most cases.
3395
3396Independently, the form of the attribute with one or two arguments
3397associates @code{deallocator} as a suitable deallocation function for
3398pointers returned from the @code{malloc}-like function. @var{ptr-index}
3399denotes the positional argument to which when the pointer is passed in
3400calls to @code{deallocator} has the effect of deallocating it.
3401
3402Using the attribute with no arguments is designed to improve optimization
3403by relying on the aliasing property it implies. Functions like @code{malloc}
3404and @code{calloc} have this property because they return a pointer to
3405uninitialized or zeroed-out, newly obtained storage. However, functions
3406like @code{realloc} do not have this property, as they may return pointers
3407to storage containing pointers to existing objects. Additionally, since
3408all such functions are assumed to return null only infrequently, callers
3409can be optimized based on that assumption.
3410
3411Associating a function with a @var{deallocator} helps detect calls to
3412mismatched allocation and deallocation functions and diagnose them under
3413the control of options such as @option{-Wmismatched-dealloc}. It also
3414makes it possible to diagnose attempts to deallocate objects that were not
3415allocated dynamically, by @option{-Wfree-nonheap-object}. To indicate
3416that an allocation function both satisifies the nonaliasing property and
3417has a deallocator associated with it, both the plain form of the attribute
3418and the one with the @var{deallocator} argument must be used. The same
3419function can be both an allocator and a deallocator. Since inlining one
3420of the associated functions but not the other could result in apparent
3421mismatches, this form of attribute @code{malloc} is not accepted on inline
3422functions. For the same reason, using the attribute prevents both
3423the allocation and deallocation functions from being expanded inline.
3424
3425For example, besides stating that the functions return pointers that do
3426not alias any others, the following declarations make @code{fclose}
3427a suitable deallocator for pointers returned from all functions except
3428@code{popen}, and @code{pclose} as the only suitable deallocator for
3429pointers returned from @code{popen}. The deallocator functions must
3430be declared before they can be referenced in the attribute.
3431
3432@smallexample
3433int fclose (FILE*);
3434int pclose (FILE*);
3435
3436__attribute__ ((malloc, malloc (fclose, 1)))
3437 FILE* fdopen (int, const char*);
3438__attribute__ ((malloc, malloc (fclose, 1)))
3439 FILE* fopen (const char*, const char*);
3440__attribute__ ((malloc, malloc (fclose, 1)))
3441 FILE* fmemopen(void *, size_t, const char *);
3442__attribute__ ((malloc, malloc (pclose, 1)))
3443 FILE* popen (const char*, const char*);
3444__attribute__ ((malloc, malloc (fclose, 1)))
3445 FILE* tmpfile (void);
3446@end smallexample
3447
3448The warnings guarded by @option{-fanalyzer} respect allocation and
3449deallocation pairs marked with the @code{malloc}. In particular:
3450
3451@itemize @bullet
3452
3453@item
4ace81b6 3454The analyzer emits a @option{-Wanalyzer-mismatching-deallocation}
d77de738
ML
3455diagnostic if there is an execution path in which the result of an
3456allocation call is passed to a different deallocator.
3457
3458@item
4ace81b6 3459The analyzer emits a @option{-Wanalyzer-double-free}
d77de738
ML
3460diagnostic if there is an execution path in which a value is passed
3461more than once to a deallocation call.
3462
3463@item
4ace81b6
SL
3464The analyzer considers the possibility that an allocation function
3465could fail and return null. If there are
d77de738 3466execution paths in which an unchecked result of an allocation call is
4ace81b6
SL
3467dereferenced or passed to a function requiring a non-null argument,
3468it emits
3469@option{-Wanalyzer-possible-null-dereference} and
3470@option{-Wanalyzer-possible-null-argument} diagnostics.
d77de738
ML
3471If the allocator always returns non-null, use
3472@code{__attribute__ ((returns_nonnull))} to suppress these warnings.
3473For example:
3474@smallexample
3475char *xstrdup (const char *)
3476 __attribute__((malloc (free), returns_nonnull));
3477@end smallexample
3478
3479@item
4ace81b6 3480The analyzer emits a @option{-Wanalyzer-use-after-free}
d77de738
ML
3481diagnostic if there is an execution path in which the memory passed
3482by pointer to a deallocation call is used after the deallocation.
3483
3484@item
4ace81b6 3485The analyzer emits a @option{-Wanalyzer-malloc-leak} diagnostic if
d77de738
ML
3486there is an execution path in which the result of an allocation call
3487is leaked (without being passed to the deallocation function).
3488
3489@item
4ace81b6 3490The analyzer emits a @option{-Wanalyzer-free-of-non-heap} diagnostic
d77de738
ML
3491if a deallocation function is used on a global or on-stack variable.
3492
3493@end itemize
3494
4ace81b6 3495The analyzer assumes that deallocators can gracefully handle the null
d77de738
ML
3496pointer. If this is not the case, the deallocator can be marked with
3497@code{__attribute__((nonnull))} so that @option{-fanalyzer} can emit
3498a @option{-Wanalyzer-possible-null-argument} diagnostic for code paths
4ace81b6 3499in which the deallocator is called with null.
d77de738 3500
d77de738 3501@cindex @code{no_icf} function attribute
f33d7a88 3502@item no_icf
d77de738
ML
3503This function attribute prevents a functions from being merged with another
3504semantically equivalent function.
3505
d77de738
ML
3506@cindex @code{no_instrument_function} function attribute
3507@opindex finstrument-functions
3508@opindex p
3509@opindex pg
f33d7a88 3510@item no_instrument_function
d77de738
ML
3511If any of @option{-finstrument-functions}, @option{-p}, or @option{-pg} are
3512given, profiling function calls are
3513generated at entry and exit of most user-compiled functions.
3514Functions with this attribute are not so instrumented.
3515
d77de738 3516@cindex @code{no_profile_instrument_function} function attribute
f33d7a88 3517@item no_profile_instrument_function
d77de738
ML
3518The @code{no_profile_instrument_function} attribute on functions is used
3519to inform the compiler that it should not process any profile feedback based
3520optimization code instrumentation.
3521
d77de738 3522@cindex @code{no_reorder} function attribute
f33d7a88 3523@item no_reorder
d77de738
ML
3524Do not reorder functions or variables marked @code{no_reorder}
3525against each other or top level assembler statements the executable.
3526The actual order in the program will depend on the linker command
3527line. Static variables marked like this are also not removed.
3528This has a similar effect
3529as the @option{-fno-toplevel-reorder} option, but only applies to the
3530marked symbols.
3531
d77de738 3532@cindex @code{no_sanitize} function attribute
f33d7a88 3533@item no_sanitize ("@var{sanitize_option}")
d77de738
ML
3534The @code{no_sanitize} attribute on functions is used
3535to inform the compiler that it should not do sanitization of any option
3536mentioned in @var{sanitize_option}. A list of values acceptable by
3537the @option{-fsanitize} option can be provided.
3538
3539@smallexample
3540void __attribute__ ((no_sanitize ("alignment", "object-size")))
3541f () @{ /* @r{Do something.} */; @}
3542void __attribute__ ((no_sanitize ("alignment,object-size")))
3543g () @{ /* @r{Do something.} */; @}
3544@end smallexample
3545
f33d7a88 3546@cindex @code{no_sanitize_address} function attribute
d77de738
ML
3547@item no_sanitize_address
3548@itemx no_address_safety_analysis
d77de738
ML
3549The @code{no_sanitize_address} attribute on functions is used
3550to inform the compiler that it should not instrument memory accesses
3551in the function when compiling with the @option{-fsanitize=address} option.
3552The @code{no_address_safety_analysis} is a deprecated alias of the
3553@code{no_sanitize_address} attribute, new code should use
3554@code{no_sanitize_address}.
3555
d77de738 3556@cindex @code{no_sanitize_thread} function attribute
f33d7a88 3557@item no_sanitize_thread
d77de738
ML
3558The @code{no_sanitize_thread} attribute on functions is used
3559to inform the compiler that it should not instrument memory accesses
3560in the function when compiling with the @option{-fsanitize=thread} option.
3561
d77de738 3562@cindex @code{no_sanitize_undefined} function attribute
f33d7a88 3563@item no_sanitize_undefined
d77de738
ML
3564The @code{no_sanitize_undefined} attribute on functions is used
3565to inform the compiler that it should not check for undefined behavior
3566in the function when compiling with the @option{-fsanitize=undefined} option.
3567
d77de738 3568@cindex @code{no_sanitize_coverage} function attribute
f33d7a88 3569@item no_sanitize_coverage
d77de738
ML
3570The @code{no_sanitize_coverage} attribute on functions is used
3571to inform the compiler that it should not do coverage-guided
3572fuzzing code instrumentation (@option{-fsanitize-coverage}).
3573
d77de738
ML
3574@cindex @code{no_split_stack} function attribute
3575@opindex fsplit-stack
f33d7a88 3576@item no_split_stack
d77de738
ML
3577If @option{-fsplit-stack} is given, functions have a small
3578prologue which decides whether to split the stack. Functions with the
3579@code{no_split_stack} attribute do not have that prologue, and thus
3580may run with only a small amount of stack space available.
3581
d77de738 3582@cindex @code{no_stack_limit} function attribute
f33d7a88 3583@item no_stack_limit
d77de738
ML
3584This attribute locally overrides the @option{-fstack-limit-register}
3585and @option{-fstack-limit-symbol} command-line options; it has the effect
3586of disabling stack limit checking in the function it applies to.
3587
d77de738 3588@cindex @code{noclone} function attribute
f33d7a88 3589@item noclone
d77de738
ML
3590This function attribute prevents a function from being considered for
3591cloning---a mechanism that produces specialized copies of functions
3592and which is (currently) performed by interprocedural constant
3593propagation.
3594
d77de738 3595@cindex @code{noinline} function attribute
f33d7a88 3596@item noinline
d77de738
ML
3597This function attribute prevents a function from being considered for
3598inlining.
3599@c Don't enumerate the optimizations by name here; we try to be
3600@c future-compatible with this mechanism.
3601If the function does not have side effects, there are optimizations
3602other than inlining that cause function calls to be optimized away,
3603although the function call is live. To keep such calls from being
3604optimized away, put
3605@smallexample
3606asm ("");
3607@end smallexample
3608
3609@noindent
3610(@pxref{Extended Asm}) in the called function, to serve as a special
3611side effect.
3612
d77de738 3613@cindex @code{noipa} function attribute
f33d7a88 3614@item noipa
d77de738
ML
3615Disable interprocedural optimizations between the function with this
3616attribute and its callers, as if the body of the function is not available
3617when optimizing callers and the callers are unavailable when optimizing
3618the body. This attribute implies @code{noinline}, @code{noclone} and
3619@code{no_icf} attributes. However, this attribute is not equivalent
3620to a combination of other attributes, because its purpose is to suppress
3621existing and future optimizations employing interprocedural analysis,
3622including those that do not have an attribute suitable for disabling
3623them individually. This attribute is supported mainly for the purpose
3624of testing the compiler.
3625
d77de738
ML
3626@cindex @code{nonnull} function attribute
3627@cindex functions with non-null pointer arguments
f33d7a88
AA
3628@item nonnull
3629@itemx nonnull (@var{arg-index}, @dots{})
d77de738
ML
3630The @code{nonnull} attribute may be applied to a function that takes at
3631least one argument of a pointer type. It indicates that the referenced
3632arguments must be non-null pointers. For instance, the declaration:
3633
3634@smallexample
3635extern void *
3636my_memcpy (void *dest, const void *src, size_t len)
3637 __attribute__((nonnull (1, 2)));
3638@end smallexample
3639
3640@noindent
3641informs the compiler that, in calls to @code{my_memcpy}, arguments
3642@var{dest} and @var{src} must be non-null.
3643
3644The attribute has an effect both on functions calls and function definitions.
3645
3646For function calls:
3647@itemize @bullet
3648@item If the compiler determines that a null pointer is
3649passed in an argument slot marked as non-null, and the
3650@option{-Wnonnull} option is enabled, a warning is issued.
3651@xref{Warning Options}.
3652@item The @option{-fisolate-erroneous-paths-attribute} option can be
3653specified to have GCC transform calls with null arguments to non-null
3654functions into traps. @xref{Optimize Options}.
3655@item The compiler may also perform optimizations based on the
3656knowledge that certain function arguments cannot be null. These
3657optimizations can be disabled by the
3658@option{-fno-delete-null-pointer-checks} option. @xref{Optimize Options}.
3659@end itemize
3660
3661For function definitions:
3662@itemize @bullet
3663@item If the compiler determines that a function parameter that is
3664marked with nonnull is compared with null, and
3665@option{-Wnonnull-compare} option is enabled, a warning is issued.
3666@xref{Warning Options}.
3667@item The compiler may also perform optimizations based on the
0e38aedc 3668knowledge that @code{nonnull} parameters cannot be null. This can
d77de738
ML
3669currently not be disabled other than by removing the nonnull
3670attribute.
3671@end itemize
3672
3673If no @var{arg-index} is given to the @code{nonnull} attribute,
3674all pointer arguments are marked as non-null. To illustrate, the
3675following declaration is equivalent to the previous example:
3676
3677@smallexample
3678extern void *
3679my_memcpy (void *dest, const void *src, size_t len)
3680 __attribute__((nonnull));
3681@end smallexample
3682
d77de738 3683@cindex @code{noplt} function attribute
f33d7a88 3684@item noplt
d77de738
ML
3685The @code{noplt} attribute is the counterpart to option @option{-fno-plt}.
3686Calls to functions marked with this attribute in position-independent code
3687do not use the PLT.
3688
3689@smallexample
3690@group
3691/* Externally defined function foo. */
3692int foo () __attribute__ ((noplt));
3693
3694int
3695main (/* @r{@dots{}} */)
3696@{
3697 /* @r{@dots{}} */
3698 foo ();
3699 /* @r{@dots{}} */
3700@}
3701@end group
3702@end smallexample
3703
3704The @code{noplt} attribute on function @code{foo}
3705tells the compiler to assume that
3706the function @code{foo} is externally defined and that the call to
3707@code{foo} must avoid the PLT
3708in position-independent code.
3709
3710In position-dependent code, a few targets also convert calls to
3711functions that are marked to not use the PLT to use the GOT instead.
3712
d77de738
ML
3713@cindex @code{noreturn} function attribute
3714@cindex functions that never return
f33d7a88 3715@item noreturn
d77de738
ML
3716A few standard library functions, such as @code{abort} and @code{exit},
3717cannot return. GCC knows this automatically. Some programs define
3718their own functions that never return. You can declare them
3719@code{noreturn} to tell the compiler this fact. For example,
3720
3721@smallexample
3722@group
3723void fatal () __attribute__ ((noreturn));
3724
3725void
3726fatal (/* @r{@dots{}} */)
3727@{
3728 /* @r{@dots{}} */ /* @r{Print error message.} */ /* @r{@dots{}} */
3729 exit (1);
3730@}
3731@end group
3732@end smallexample
3733
3734The @code{noreturn} keyword tells the compiler to assume that
3735@code{fatal} cannot return. It can then optimize without regard to what
3736would happen if @code{fatal} ever did return. This makes slightly
3737better code. More importantly, it helps avoid spurious warnings of
3738uninitialized variables.
3739
3740The @code{noreturn} keyword does not affect the exceptional path when that
3741applies: a @code{noreturn}-marked function may still return to the caller
3742by throwing an exception or calling @code{longjmp}.
3743
3744In order to preserve backtraces, GCC will never turn calls to
3745@code{noreturn} functions into tail calls.
3746
3747Do not assume that registers saved by the calling function are
3748restored before calling the @code{noreturn} function.
3749
3750It does not make sense for a @code{noreturn} function to have a return
3751type other than @code{void}.
3752
d77de738 3753@cindex @code{nothrow} function attribute
f33d7a88 3754@item nothrow
d77de738
ML
3755The @code{nothrow} attribute is used to inform the compiler that a
3756function cannot throw an exception. For example, most functions in
3757the standard C library can be guaranteed not to throw an exception
3758with the notable exceptions of @code{qsort} and @code{bsearch} that
3759take function pointer arguments.
3760
f33d7a88 3761@cindex @code{optimize} function attribute
d77de738
ML
3762@item optimize (@var{level}, @dots{})
3763@item optimize (@var{string}, @dots{})
d77de738
ML
3764The @code{optimize} attribute is used to specify that a function is to
3765be compiled with different optimization options than specified on the
3766command line. The optimize attribute arguments of a function behave
3767behave as if appended to the command-line.
3768
3769Valid arguments are constant non-negative integers and
3770strings. Each numeric argument specifies an optimization @var{level}.
3771Each @var{string} argument consists of one or more comma-separated
3772substrings. Each substring that begins with the letter @code{O} refers
3773to an optimization option such as @option{-O0} or @option{-Os}. Other
3774substrings are taken as suffixes to the @code{-f} prefix jointly
3775forming the name of an optimization option. @xref{Optimize Options}.
3776
3777@samp{#pragma GCC optimize} can be used to set optimization options
3778for more than one function. @xref{Function Specific Option Pragmas},
3779for details about the pragma.
3780
3781Providing multiple strings as arguments separated by commas to specify
3782multiple options is equivalent to separating the option suffixes with
3783a comma (@samp{,}) within a single string. Spaces are not permitted
3784within the strings.
3785
3786Not every optimization option that starts with the @var{-f} prefix
3787specified by the attribute necessarily has an effect on the function.
3788The @code{optimize} attribute should be used for debugging purposes only.
3789It is not suitable in production code.
3790
d77de738
ML
3791@cindex @code{patchable_function_entry} function attribute
3792@cindex extra NOP instructions at the function entry point
f33d7a88 3793@item patchable_function_entry
d77de738
ML
3794In case the target's text segment can be made writable at run time by
3795any means, padding the function entry with a number of NOPs can be
3796used to provide a universal tool for instrumentation.
3797
3798The @code{patchable_function_entry} function attribute can be used to
3799change the number of NOPs to any desired value. The two-value syntax
3800is the same as for the command-line switch
3801@option{-fpatchable-function-entry=N,M}, generating @var{N} NOPs, with
3802the function entry point before the @var{M}th NOP instruction.
3803@var{M} defaults to 0 if omitted e.g.@: function entry point is before
3804the first NOP.
3805
3806If patchable function entries are enabled globally using the command-line
3807option @option{-fpatchable-function-entry=N,M}, then you must disable
3808instrumentation on all functions that are part of the instrumentation
3809framework with the attribute @code{patchable_function_entry (0)}
3810to prevent recursion.
3811
d77de738
ML
3812@cindex @code{pure} function attribute
3813@cindex functions that have no side effects
f33d7a88 3814@item pure
d77de738
ML
3815
3816Calls to functions that have no observable effects on the state of
3817the program other than to return a value may lend themselves to optimizations
3818such as common subexpression elimination. Declaring such functions with
3819the @code{pure} attribute allows GCC to avoid emitting some calls in repeated
3820invocations of the function with the same argument values.
3821
3822The @code{pure} attribute prohibits a function from modifying the state
3823of the program that is observable by means other than inspecting
3824the function's return value. However, functions declared with the @code{pure}
3825attribute can safely read any non-volatile objects, and modify the value of
3826objects in a way that does not affect their return value or the observable
3827state of the program.
3828
3829For example,
3830
3831@smallexample
3832int hash (char *) __attribute__ ((pure));
3833@end smallexample
3834
3835@noindent
3836tells GCC that subsequent calls to the function @code{hash} with the same
3837string can be replaced by the result of the first call provided the state
3838of the program observable by @code{hash}, including the contents of the array
3839itself, does not change in between. Even though @code{hash} takes a non-const
3840pointer argument it must not modify the array it points to, or any other object
3841whose value the rest of the program may depend on. However, the caller may
3842safely change the contents of the array between successive calls to
3843the function (doing so disables the optimization). The restriction also
3844applies to member objects referenced by the @code{this} pointer in C++
3845non-static member functions.
3846
3847Some common examples of pure functions are @code{strlen} or @code{memcmp}.
3848Interesting non-pure functions are functions with infinite loops or those
3849depending on volatile memory or other system resource, that may change between
3850consecutive calls (such as the standard C @code{feof} function in
3851a multithreading environment).
3852
3853The @code{pure} attribute imposes similar but looser restrictions on
3854a function's definition than the @code{const} attribute: @code{pure}
3855allows the function to read any non-volatile memory, even if it changes
3856in between successive invocations of the function. Declaring the same
3857function with both the @code{pure} and the @code{const} attribute is
3858diagnosed. Because a pure function cannot have any observable side
3859effects it does not make sense for such a function to return @code{void}.
3860Declaring such a function is diagnosed.
3861
d77de738 3862@cindex @code{returns_nonnull} function attribute
f33d7a88 3863@item returns_nonnull
d77de738
ML
3864The @code{returns_nonnull} attribute specifies that the function
3865return value should be a non-null pointer. For instance, the declaration:
3866
3867@smallexample
3868extern void *
3869mymalloc (size_t len) __attribute__((returns_nonnull));
3870@end smallexample
3871
3872@noindent
3873lets the compiler optimize callers based on the knowledge
3874that the return value will never be null.
3875
d77de738
ML
3876@cindex @code{returns_twice} function attribute
3877@cindex functions that return more than once
f33d7a88 3878@item returns_twice
d77de738
ML
3879The @code{returns_twice} attribute tells the compiler that a function may
3880return more than one time. The compiler ensures that all registers
3881are dead before calling such a function and emits a warning about
3882the variables that may be clobbered after the second return from the
3883function. Examples of such functions are @code{setjmp} and @code{vfork}.
3884The @code{longjmp}-like counterpart of such function, if any, might need
3885to be marked with the @code{noreturn} attribute.
3886
d77de738
ML
3887@cindex @code{section} function attribute
3888@cindex functions in arbitrary sections
f33d7a88 3889@item section ("@var{section-name}")
d77de738
ML
3890Normally, the compiler places the code it generates in the @code{text} section.
3891Sometimes, however, you need additional sections, or you need certain
3892particular functions to appear in special sections. The @code{section}
3893attribute specifies that a function lives in a particular section.
3894For example, the declaration:
3895
3896@smallexample
3897extern void foobar (void) __attribute__ ((section ("bar")));
3898@end smallexample
3899
3900@noindent
3901puts the function @code{foobar} in the @code{bar} section.
3902
3903Some file formats do not support arbitrary sections so the @code{section}
3904attribute is not available on all platforms.
3905If you need to map the entire contents of a module to a particular
3906section, consider using the facilities of the linker instead.
3907
f33d7a88 3908@cindex @code{sentinel} function attribute
d77de738
ML
3909@item sentinel
3910@itemx sentinel (@var{position})
d77de738
ML
3911This function attribute indicates that an argument in a call to the function
3912is expected to be an explicit @code{NULL}. The attribute is only valid on
3913variadic functions. By default, the sentinel is expected to be the last
3914argument of the function call. If the optional @var{position} argument
3915is specified to the attribute, the sentinel must be located at
3916@var{position} counting backwards from the end of the argument list.
3917
3918@smallexample
3919__attribute__ ((sentinel))
3920is equivalent to
3921__attribute__ ((sentinel(0)))
3922@end smallexample
3923
3924The attribute is automatically set with a position of 0 for the built-in
3925functions @code{execl} and @code{execlp}. The built-in function
3926@code{execle} has the attribute set with a position of 1.
3927
3928A valid @code{NULL} in this context is defined as zero with any object
3929pointer type. If your system defines the @code{NULL} macro with
3930an integer type then you need to add an explicit cast. During
3931installation GCC replaces the system @code{<stddef.h>} header with
3932a copy that redefines NULL appropriately.
3933
3934The warnings for missing or incorrect sentinels are enabled with
3935@option{-Wformat}.
3936
f33d7a88 3937@cindex @code{simd} function attribute
d77de738
ML
3938@item simd
3939@itemx simd("@var{mask}")
d77de738
ML
3940This attribute enables creation of one or more function versions that
3941can process multiple arguments using SIMD instructions from a
3942single invocation. Specifying this attribute allows compiler to
3943assume that such versions are available at link time (provided
3944in the same or another translation unit). Generated versions are
3945target-dependent and described in the corresponding Vector ABI document. For
3946x86_64 target this document can be found
3947@w{@uref{https://sourceware.org/glibc/wiki/libmvec?action=AttachFile&do=view&target=VectorABI.txt,here}}.
3948
3949The optional argument @var{mask} may have the value
3950@code{notinbranch} or @code{inbranch},
3951and instructs the compiler to generate non-masked or masked
3952clones correspondingly. By default, all clones are generated.
3953
3954If the attribute is specified and @code{#pragma omp declare simd} is
3955present on a declaration and the @option{-fopenmp} or @option{-fopenmp-simd}
3956switch is specified, then the attribute is ignored.
3957
d77de738 3958@cindex @code{stack_protect} function attribute
f33d7a88 3959@item stack_protect
d77de738
ML
3960This attribute adds stack protection code to the function if
3961flags @option{-fstack-protector}, @option{-fstack-protector-strong}
3962or @option{-fstack-protector-explicit} are set.
3963
d77de738 3964@cindex @code{no_stack_protector} function attribute
f33d7a88 3965@item no_stack_protector
d77de738
ML
3966This attribute prevents stack protection code for the function.
3967
d77de738 3968@cindex @code{target} function attribute
f33d7a88 3969@item target (@var{string}, @dots{})
d77de738
ML
3970Multiple target back ends implement the @code{target} attribute
3971to specify that a function is to
3972be compiled with different target options than specified on the
3973command line. The original target command-line options are ignored.
3974One or more strings can be provided as arguments.
3975Each string consists of one or more comma-separated suffixes to
3976the @code{-m} prefix jointly forming the name of a machine-dependent
3977option. @xref{Submodel Options,,Machine-Dependent Options}.
3978
3979The @code{target} attribute can be used for instance to have a function
3980compiled with a different ISA (instruction set architecture) than the
3981default. @samp{#pragma GCC target} can be used to specify target-specific
3982options for more than one function. @xref{Function Specific Option Pragmas},
3983for details about the pragma.
3984
3985For instance, on an x86, you could declare one function with the
3986@code{target("sse4.1,arch=core2")} attribute and another with
3987@code{target("sse4a,arch=amdfam10")}. This is equivalent to
3988compiling the first function with @option{-msse4.1} and
3989@option{-march=core2} options, and the second function with
3990@option{-msse4a} and @option{-march=amdfam10} options. It is up to you
3991to make sure that a function is only invoked on a machine that
3992supports the particular ISA it is compiled for (for example by using
3993@code{cpuid} on x86 to determine what feature bits and architecture
3994family are used).
3995
3996@smallexample
3997int core2_func (void) __attribute__ ((__target__ ("arch=core2")));
3998int sse3_func (void) __attribute__ ((__target__ ("sse3")));
3999@end smallexample
4000
4001Providing multiple strings as arguments separated by commas to specify
4002multiple options is equivalent to separating the option suffixes with
4003a comma (@samp{,}) within a single string. Spaces are not permitted
4004within the strings.
4005
4006The options supported are specific to each target; refer to @ref{x86
4007Function Attributes}, @ref{PowerPC Function Attributes},
4008@ref{ARM Function Attributes}, @ref{AArch64 Function Attributes},
4009@ref{Nios II Function Attributes}, and @ref{S/390 Function Attributes}
4010for details.
4011
d77de738 4012@cindex @code{symver} function attribute
f33d7a88 4013@item symver ("@var{name2}@@@var{nodename}")
d77de738
ML
4014On ELF targets this attribute creates a symbol version. The @var{name2} part
4015of the parameter is the actual name of the symbol by which it will be
4016externally referenced. The @code{nodename} portion should be the name of a
4017node specified in the version script supplied to the linker when building a
4018shared library. Versioned symbol must be defined and must be exported with
4019default visibility.
4020
4021@smallexample
4022__attribute__ ((__symver__ ("foo@@VERS_1"))) int
4023foo_v1 (void)
4024@{
4025@}
4026@end smallexample
4027
4028Will produce a @code{.symver foo_v1, foo@@VERS_1} directive in the assembler
4029output.
4030
4031One can also define multiple version for a given symbol
4032(starting from binutils 2.35).
4033
4034@smallexample
4035__attribute__ ((__symver__ ("foo@@VERS_2"), __symver__ ("foo@@VERS_3")))
4036int symver_foo_v1 (void)
4037@{
4038@}
4039@end smallexample
4040
4041This example creates a symbol name @code{symver_foo_v1}
4042which will be version @code{VERS_2} and @code{VERS_3} of @code{foo}.
4043
4044If you have an older release of binutils, then symbol alias needs to
4045be used:
4046
4047@smallexample
4048__attribute__ ((__symver__ ("foo@@VERS_2")))
4049int foo_v1 (void)
4050@{
4051 return 0;
4052@}
4053
4054__attribute__ ((__symver__ ("foo@@VERS_3")))
4055__attribute__ ((alias ("foo_v1")))
4056int symver_foo_v1 (void);
4057@end smallexample
4058
4059Finally if the parameter is @code{"@var{name2}@@@@@var{nodename}"} then in
4060addition to creating a symbol version (as if
4061@code{"@var{name2}@@@var{nodename}"} was used) the version will be also used
4062to resolve @var{name2} by the linker.
4063
d77de738 4064@cindex @code{tainted_args} function attribute
f33d7a88 4065@item tainted_args
d77de738
ML
4066The @code{tainted_args} attribute is used to specify that a function is called
4067in a way that requires sanitization of its arguments, such as a system
4068call in an operating system kernel. Such a function can be considered part
4069of the ``attack surface'' of the program. The attribute can be used both
4070on function declarations, and on field declarations containing function
4071pointers. In the latter case, any function used as an initializer of
4072such a callback field will be treated as being called with tainted
4073arguments.
4074
4075The analyzer will pay particular attention to such functions when both
4076@option{-fanalyzer} and @option{-fanalyzer-checker=taint} are supplied,
4077potentially issuing warnings guarded by
4078@option{-Wanalyzer-tainted-allocation-size},
4079@option{-Wanalyzer-tainted-array-index},
4080@option{-Wanalyzer-tainted-divisor},
4081@option{-Wanalyzer-tainted-offset},
4082and @option{-Wanalyzer-tainted-size}.
4083
d77de738 4084@cindex @code{target_clones} function attribute
f33d7a88 4085@item target_clones (@var{options})
d77de738
ML
4086The @code{target_clones} attribute is used to specify that a function
4087be cloned into multiple versions compiled with different target options
4088than specified on the command line. The supported options and restrictions
4089are the same as for @code{target} attribute.
4090
4091For instance, on an x86, you could compile a function with
4092@code{target_clones("sse4.1,avx")}. GCC creates two function clones,
4093one compiled with @option{-msse4.1} and another with @option{-mavx}.
4094
4095On a PowerPC, you can compile a function with
4096@code{target_clones("cpu=power9,default")}. GCC will create two
4097function clones, one compiled with @option{-mcpu=power9} and another
4098with the default options. GCC must be configured to use GLIBC 2.23 or
4099newer in order to use the @code{target_clones} attribute.
4100
4101It also creates a resolver function (see
4102the @code{ifunc} attribute above) that dynamically selects a clone
4103suitable for current architecture. The resolver is created only if there
4104is a usage of a function with @code{target_clones} attribute.
4105
4106Note that any subsequent call of a function without @code{target_clone}
4107from a @code{target_clone} caller will not lead to copying
4108(target clone) of the called function.
4109If you want to enforce such behaviour,
4110we recommend declaring the calling function with the @code{flatten} attribute?
4111
d77de738 4112@cindex @code{unused} function attribute
f33d7a88 4113@item unused
d77de738
ML
4114This attribute, attached to a function, means that the function is meant
4115to be possibly unused. GCC does not produce a warning for this
4116function.
4117
d77de738 4118@cindex @code{used} function attribute
f33d7a88 4119@item used
d77de738
ML
4120This attribute, attached to a function, means that code must be emitted
4121for the function even if it appears that the function is not referenced.
4122This is useful, for example, when the function is referenced only in
4123inline assembly.
4124
4125When applied to a member function of a C++ class template, the
4126attribute also means that the function is instantiated if the
4127class itself is instantiated.
4128
d77de738 4129@cindex @code{retain} function attribute
f33d7a88 4130@item retain
d77de738
ML
4131For ELF targets that support the GNU or FreeBSD OSABIs, this attribute
4132will save the function from linker garbage collection. To support
4133this behavior, functions that have not been placed in specific sections
4134(e.g. by the @code{section} attribute, or the @code{-ffunction-sections}
4135option), will be placed in new, unique sections.
4136
4137This additional functionality requires Binutils version 2.36 or later.
4138
d77de738 4139@cindex @code{visibility} function attribute
f33d7a88 4140@item visibility ("@var{visibility_type}")
d77de738
ML
4141This attribute affects the linkage of the declaration to which it is attached.
4142It can be applied to variables (@pxref{Common Variable Attributes}) and types
4143(@pxref{Common Type Attributes}) as well as functions.
4144
4145There are four supported @var{visibility_type} values: default,
4146hidden, protected or internal visibility.
4147
4148@smallexample
4149void __attribute__ ((visibility ("protected")))
4150f () @{ /* @r{Do something.} */; @}
4151int i __attribute__ ((visibility ("hidden")));
4152@end smallexample
4153
4154The possible values of @var{visibility_type} correspond to the
4155visibility settings in the ELF gABI.
4156
4157@table @code
4158@c keep this list of visibilities in alphabetical order.
4159
4160@item default
4161Default visibility is the normal case for the object file format.
4162This value is available for the visibility attribute to override other
4163options that may change the assumed visibility of entities.
4164
4165On ELF, default visibility means that the declaration is visible to other
4166modules and, in shared libraries, means that the declared entity may be
4167overridden.
4168
4169On Darwin, default visibility means that the declaration is visible to
4170other modules.
4171
4172Default visibility corresponds to ``external linkage'' in the language.
4173
4174@item hidden
4175Hidden visibility indicates that the entity declared has a new
4176form of linkage, which we call ``hidden linkage''. Two
4177declarations of an object with hidden linkage refer to the same object
4178if they are in the same shared object.
4179
4180@item internal
4181Internal visibility is like hidden visibility, but with additional
4182processor specific semantics. Unless otherwise specified by the
4183psABI, GCC defines internal visibility to mean that a function is
4184@emph{never} called from another module. Compare this with hidden
4185functions which, while they cannot be referenced directly by other
4186modules, can be referenced indirectly via function pointers. By
4187indicating that a function cannot be called from outside the module,
4188GCC may for instance omit the load of a PIC register since it is known
4189that the calling function loaded the correct value.
4190
4191@item protected
4192Protected visibility is like default visibility except that it
4193indicates that references within the defining module bind to the
4194definition in that module. That is, the declared entity cannot be
4195overridden by another module.
4196
4197@end table
4198
4199All visibilities are supported on many, but not all, ELF targets
4200(supported when the assembler supports the @samp{.visibility}
4201pseudo-op). Default visibility is supported everywhere. Hidden
4202visibility is supported on Darwin targets.
4203
4204The visibility attribute should be applied only to declarations that
4205would otherwise have external linkage. The attribute should be applied
4206consistently, so that the same entity should not be declared with
4207different settings of the attribute.
4208
4209In C++, the visibility attribute applies to types as well as functions
4210and objects, because in C++ types have linkage. A class must not have
4211greater visibility than its non-static data member types and bases,
4212and class members default to the visibility of their class. Also, a
4213declaration without explicit visibility is limited to the visibility
4214of its type.
4215
4216In C++, you can mark member functions and static member variables of a
4217class with the visibility attribute. This is useful if you know a
4218particular method or static member variable should only be used from
4219one shared object; then you can mark it hidden while the rest of the
4220class has default visibility. Care must be taken to avoid breaking
4221the One Definition Rule; for example, it is usually not useful to mark
4222an inline method as hidden without marking the whole class as hidden.
4223
4224A C++ namespace declaration can also have the visibility attribute.
4225
4226@smallexample
4227namespace nspace1 __attribute__ ((visibility ("protected")))
4228@{ /* @r{Do something.} */; @}
4229@end smallexample
4230
4231This attribute applies only to the particular namespace body, not to
4232other definitions of the same namespace; it is equivalent to using
4233@samp{#pragma GCC visibility} before and after the namespace
4234definition (@pxref{Visibility Pragmas}).
4235
4236In C++, if a template argument has limited visibility, this
4237restriction is implicitly propagated to the template instantiation.
4238Otherwise, template instantiations and specializations default to the
4239visibility of their template.
4240
4241If both the template and enclosing class have explicit visibility, the
4242visibility from the template is used.
4243
d77de738 4244@cindex @code{warn_unused_result} function attribute
f33d7a88 4245@item warn_unused_result
d77de738
ML
4246The @code{warn_unused_result} attribute causes a warning to be emitted
4247if a caller of the function with this attribute does not use its
4248return value. This is useful for functions where not checking
4249the result is either a security problem or always a bug, such as
4250@code{realloc}.
4251
4252@smallexample
4253int fn () __attribute__ ((warn_unused_result));
4254int foo ()
4255@{
4256 if (fn () < 0) return -1;
4257 fn ();
4258 return 0;
4259@}
4260@end smallexample
4261
4262@noindent
4263results in warning on line 5.
4264
d77de738 4265@cindex @code{weak} function attribute
f33d7a88 4266@item weak
d77de738
ML
4267The @code{weak} attribute causes a declaration of an external symbol
4268to be emitted as a weak symbol rather than a global. This is primarily
4269useful in defining library functions that can be overridden in user code,
4270though it can also be used with non-function declarations. The overriding
4271symbol must have the same type as the weak symbol. In addition, if it
4272designates a variable it must also have the same size and alignment as
4273the weak symbol. Weak symbols are supported for ELF targets, and also
4274for a.out targets when using the GNU assembler and linker.
4275
f33d7a88 4276@cindex @code{weakref} function attribute
d77de738
ML
4277@item weakref
4278@itemx weakref ("@var{target}")
d77de738
ML
4279The @code{weakref} attribute marks a declaration as a weak reference.
4280Without arguments, it should be accompanied by an @code{alias} attribute
4281naming the target symbol. Alternatively, @var{target} may be given as
4282an argument to @code{weakref} itself, naming the target definition of
4283the alias. The @var{target} must have the same type as the declaration.
4284In addition, if it designates a variable it must also have the same size
4285and alignment as the declaration. In either form of the declaration
4286@code{weakref} implicitly marks the declared symbol as @code{weak}. Without
4287a @var{target} given as an argument to @code{weakref} or to @code{alias},
4288@code{weakref} is equivalent to @code{weak} (in that case the declaration
4289may be @code{extern}).
4290
4291@smallexample
4292/* Given the declaration: */
4293extern int y (void);
4294
4295/* the following... */
4296static int x (void) __attribute__ ((weakref ("y")));
4297
4298/* is equivalent to... */
4299static int x (void) __attribute__ ((weakref, alias ("y")));
4300
4301/* or, alternatively, to... */
4302static int x (void) __attribute__ ((weakref));
4303static int x (void) __attribute__ ((alias ("y")));
4304@end smallexample
4305
4306A weak reference is an alias that does not by itself require a
4307definition to be given for the target symbol. If the target symbol is
4308only referenced through weak references, then it becomes a @code{weak}
4309undefined symbol. If it is directly referenced, however, then such
4310strong references prevail, and a definition is required for the
4311symbol, not necessarily in the same translation unit.
4312
4313The effect is equivalent to moving all references to the alias to a
4314separate translation unit, renaming the alias to the aliased symbol,
4315declaring it as weak, compiling the two separate translation units and
4316performing a link with relocatable output (i.e.@: @code{ld -r}) on them.
4317
4318A declaration to which @code{weakref} is attached and that is associated
4319with a named @code{target} must be @code{static}.
4320
d77de738 4321@cindex @code{zero_call_used_regs} function attribute
f33d7a88 4322@item zero_call_used_regs ("@var{choice}")
d77de738
ML
4323
4324The @code{zero_call_used_regs} attribute causes the compiler to zero
4325a subset of all call-used registers@footnote{A ``call-used'' register
4326is a register whose contents can be changed by a function call;
4327therefore, a caller cannot assume that the register has the same contents
4328on return from the function as it had before calling the function. Such
4329registers are also called ``call-clobbered'', ``caller-saved'', or
4330``volatile''.} at function return.
4331This is used to increase program security by either mitigating
4332Return-Oriented Programming (ROP) attacks or preventing information leakage
4333through registers.
4334
4335In order to satisfy users with different security needs and control the
4336run-time overhead at the same time, the @var{choice} parameter provides a
4337flexible way to choose the subset of the call-used registers to be zeroed.
4338The three basic values of @var{choice} are:
4339
4340@itemize @bullet
4341@item
4342@samp{skip} doesn't zero any call-used registers.
4343
4344@item
4345@samp{used} only zeros call-used registers that are used in the function.
4346A ``used'' register is one whose content has been set or referenced in
4347the function.
4348
4349@item
4350@samp{all} zeros all call-used registers.
4351@end itemize
4352
4353In addition to these three basic choices, it is possible to modify
4354@samp{used} or @samp{all} as follows:
4355
4356@itemize @bullet
4357@item
4358Adding @samp{-gpr} restricts the zeroing to general-purpose registers.
4359
4360@item
4361Adding @samp{-arg} restricts the zeroing to registers that can sometimes
4362be used to pass function arguments. This includes all argument registers
4363defined by the platform's calling conversion, regardless of whether the
4364function uses those registers for function arguments or not.
4365@end itemize
4366
4367The modifiers can be used individually or together. If they are used
4368together, they must appear in the order above.
4369
4370The full list of @var{choice}s is therefore:
4371
4372@table @code
4373@item skip
4374doesn't zero any call-used register.
4375
4376@item used
4377only zeros call-used registers that are used in the function.
4378
4379@item used-gpr
4380only zeros call-used general purpose registers that are used in the function.
4381
4382@item used-arg
4383only zeros call-used registers that are used in the function and pass arguments.
4384
4385@item used-gpr-arg
4386only zeros call-used general purpose registers that are used in the function
4387and pass arguments.
4388
4389@item all
4390zeros all call-used registers.
4391
4392@item all-gpr
4393zeros all call-used general purpose registers.
4394
4395@item all-arg
4396zeros all call-used registers that pass arguments.
4397
4398@item all-gpr-arg
4399zeros all call-used general purpose registers that pass
4400arguments.
4401@end table
4402
4403Of this list, @samp{used-arg}, @samp{used-gpr-arg}, @samp{all-arg},
4404and @samp{all-gpr-arg} are mainly used for ROP mitigation.
4405
4406The default for the attribute is controlled by @option{-fzero-call-used-regs}.
4407@end table
4408
4409@c This is the end of the target-independent attribute table
4410
4411@node AArch64 Function Attributes
4412@subsection AArch64 Function Attributes
4413
4414The following target-specific function attributes are available for the
4415AArch64 target. For the most part, these options mirror the behavior of
4416similar command-line options (@pxref{AArch64 Options}), but on a
4417per-function basis.
4418
4419@table @code
d77de738 4420@cindex @code{general-regs-only} function attribute, AArch64
f33d7a88 4421@item general-regs-only
d77de738
ML
4422Indicates that no floating-point or Advanced SIMD registers should be
4423used when generating code for this function. If the function explicitly
4424uses floating-point code, then the compiler gives an error. This is
4425the same behavior as that of the command-line option
4426@option{-mgeneral-regs-only}.
4427
d77de738 4428@cindex @code{fix-cortex-a53-835769} function attribute, AArch64
f33d7a88 4429@item fix-cortex-a53-835769
d77de738
ML
4430Indicates that the workaround for the Cortex-A53 erratum 835769 should be
4431applied to this function. To explicitly disable the workaround for this
4432function specify the negated form: @code{no-fix-cortex-a53-835769}.
4433This corresponds to the behavior of the command line options
4434@option{-mfix-cortex-a53-835769} and @option{-mno-fix-cortex-a53-835769}.
4435
d77de738 4436@cindex @code{cmodel=} function attribute, AArch64
f33d7a88 4437@item cmodel=
d77de738
ML
4438Indicates that code should be generated for a particular code model for
4439this function. The behavior and permissible arguments are the same as
4440for the command line option @option{-mcmodel=}.
4441
f33d7a88 4442@cindex @code{strict-align} function attribute, AArch64
d77de738
ML
4443@item strict-align
4444@itemx no-strict-align
d77de738
ML
4445@code{strict-align} indicates that the compiler should not assume that unaligned
4446memory references are handled by the system. To allow the compiler to assume
4447that aligned memory references are handled by the system, the inverse attribute
4448@code{no-strict-align} can be specified. The behavior is same as for the
4449command-line option @option{-mstrict-align} and @option{-mno-strict-align}.
4450
d77de738 4451@cindex @code{omit-leaf-frame-pointer} function attribute, AArch64
f33d7a88 4452@item omit-leaf-frame-pointer
d77de738
ML
4453Indicates that the frame pointer should be omitted for a leaf function call.
4454To keep the frame pointer, the inverse attribute
4455@code{no-omit-leaf-frame-pointer} can be specified. These attributes have
4456the same behavior as the command-line options @option{-momit-leaf-frame-pointer}
4457and @option{-mno-omit-leaf-frame-pointer}.
4458
d77de738 4459@cindex @code{tls-dialect=} function attribute, AArch64
f33d7a88 4460@item tls-dialect=
d77de738
ML
4461Specifies the TLS dialect to use for this function. The behavior and
4462permissible arguments are the same as for the command-line option
4463@option{-mtls-dialect=}.
4464
d77de738 4465@cindex @code{arch=} function attribute, AArch64
f33d7a88 4466@item arch=
d77de738
ML
4467Specifies the architecture version and architectural extensions to use
4468for this function. The behavior and permissible arguments are the same as
4469for the @option{-march=} command-line option.
4470
d77de738 4471@cindex @code{tune=} function attribute, AArch64
f33d7a88 4472@item tune=
d77de738
ML
4473Specifies the core for which to tune the performance of this function.
4474The behavior and permissible arguments are the same as for the @option{-mtune=}
4475command-line option.
4476
d77de738 4477@cindex @code{cpu=} function attribute, AArch64
f33d7a88 4478@item cpu=
d77de738
ML
4479Specifies the core for which to tune the performance of this function and also
4480whose architectural features to use. The behavior and valid arguments are the
4481same as for the @option{-mcpu=} command-line option.
4482
d77de738 4483@cindex @code{sign-return-address} function attribute, AArch64
f33d7a88 4484@item sign-return-address
d77de738
ML
4485Select the function scope on which return address signing will be applied. The
4486behavior and permissible arguments are the same as for the command-line option
4487@option{-msign-return-address=}. The default value is @code{none}. This
4488attribute is deprecated. The @code{branch-protection} attribute should
4489be used instead.
4490
d77de738 4491@cindex @code{branch-protection} function attribute, AArch64
f33d7a88 4492@item branch-protection
d77de738
ML
4493Select the function scope on which branch protection will be applied. The
4494behavior and permissible arguments are the same as for the command-line option
4495@option{-mbranch-protection=}. The default value is @code{none}.
4496
d77de738 4497@cindex @code{outline-atomics} function attribute, AArch64
f33d7a88 4498@item outline-atomics
d77de738
ML
4499Enable or disable calls to out-of-line helpers to implement atomic operations.
4500This corresponds to the behavior of the command line options
4501@option{-moutline-atomics} and @option{-mno-outline-atomics}.
4502
4503@end table
4504
4505The above target attributes can be specified as follows:
4506
4507@smallexample
4508__attribute__((target("@var{attr-string}")))
4509int
4510f (int a)
4511@{
4512 return a + 5;
4513@}
4514@end smallexample
4515
4516where @code{@var{attr-string}} is one of the attribute strings specified above.
4517
4518Additionally, the architectural extension string may be specified on its
4519own. This can be used to turn on and off particular architectural extensions
4520without having to specify a particular architecture version or core. Example:
4521
4522@smallexample
4523__attribute__((target("+crc+nocrypto")))
4524int
4525foo (int a)
4526@{
4527 return a + 5;
4528@}
4529@end smallexample
4530
4531In this example @code{target("+crc+nocrypto")} enables the @code{crc}
4532extension and disables the @code{crypto} extension for the function @code{foo}
4533without modifying an existing @option{-march=} or @option{-mcpu} option.
4534
4535Multiple target function attributes can be specified by separating them with
4536a comma. For example:
4537@smallexample
4538__attribute__((target("arch=armv8-a+crc+crypto,tune=cortex-a53")))
4539int
4540foo (int a)
4541@{
4542 return a + 5;
4543@}
4544@end smallexample
4545
4546is valid and compiles function @code{foo} for ARMv8-A with @code{crc}
4547and @code{crypto} extensions and tunes it for @code{cortex-a53}.
4548
4549@subsubsection Inlining rules
4550Specifying target attributes on individual functions or performing link-time
4551optimization across translation units compiled with different target options
4552can affect function inlining rules:
4553
4554In particular, a caller function can inline a callee function only if the
4555architectural features available to the callee are a subset of the features
4556available to the caller.
4557For example: A function @code{foo} compiled with @option{-march=armv8-a+crc},
4558or tagged with the equivalent @code{arch=armv8-a+crc} attribute,
4559can inline a function @code{bar} compiled with @option{-march=armv8-a+nocrc}
4560because the all the architectural features that function @code{bar} requires
4561are available to function @code{foo}. Conversely, function @code{bar} cannot
4562inline function @code{foo}.
4563
4564Additionally inlining a function compiled with @option{-mstrict-align} into a
4565function compiled without @code{-mstrict-align} is not allowed.
4566However, inlining a function compiled without @option{-mstrict-align} into a
4567function compiled with @option{-mstrict-align} is allowed.
4568
4569Note that CPU tuning options and attributes such as the @option{-mcpu=},
4570@option{-mtune=} do not inhibit inlining unless the CPU specified by the
4571@option{-mcpu=} option or the @code{cpu=} attribute conflicts with the
4572architectural feature rules specified above.
4573
4574@node AMD GCN Function Attributes
4575@subsection AMD GCN Function Attributes
4576
4577These function attributes are supported by the AMD GCN back end:
4578
4579@table @code
d77de738 4580@cindex @code{amdgpu_hsa_kernel} function attribute, AMD GCN
f33d7a88 4581@item amdgpu_hsa_kernel
d77de738
ML
4582This attribute indicates that the corresponding function should be compiled as
4583a kernel function, that is an entry point that can be invoked from the host
4584via the HSA runtime library. By default functions are only callable only from
4585other GCN functions.
4586
4587This attribute is implicitly applied to any function named @code{main}, using
4588default parameters.
4589
4590Kernel functions may return an integer value, which will be written to a
4591conventional place within the HSA "kernargs" region.
4592
4593The attribute parameters configure what values are passed into the kernel
4594function by the GPU drivers, via the initial register state. Some values are
4595used by the compiler, and therefore forced on. Enabling other options may
4596break assumptions in the compiler and/or run-time libraries.
4597
4598@table @code
4599@item private_segment_buffer
4600Set @code{enable_sgpr_private_segment_buffer} flag. Always on (required to
4601locate the stack).
4602
4603@item dispatch_ptr
4604Set @code{enable_sgpr_dispatch_ptr} flag. Always on (required to locate the
4605launch dimensions).
4606
4607@item queue_ptr
4608Set @code{enable_sgpr_queue_ptr} flag. Always on (required to convert address
4609spaces).
4610
4611@item kernarg_segment_ptr
4612Set @code{enable_sgpr_kernarg_segment_ptr} flag. Always on (required to
4613locate the kernel arguments, "kernargs").
4614
4615@item dispatch_id
4616Set @code{enable_sgpr_dispatch_id} flag.
4617
4618@item flat_scratch_init
4619Set @code{enable_sgpr_flat_scratch_init} flag.
4620
4621@item private_segment_size
4622Set @code{enable_sgpr_private_segment_size} flag.
4623
4624@item grid_workgroup_count_X
4625Set @code{enable_sgpr_grid_workgroup_count_x} flag. Always on (required to
4626use OpenACC/OpenMP).
4627
4628@item grid_workgroup_count_Y
4629Set @code{enable_sgpr_grid_workgroup_count_y} flag.
4630
4631@item grid_workgroup_count_Z
4632Set @code{enable_sgpr_grid_workgroup_count_z} flag.
4633
4634@item workgroup_id_X
4635Set @code{enable_sgpr_workgroup_id_x} flag.
4636
4637@item workgroup_id_Y
4638Set @code{enable_sgpr_workgroup_id_y} flag.
4639
4640@item workgroup_id_Z
4641Set @code{enable_sgpr_workgroup_id_z} flag.
4642
4643@item workgroup_info
4644Set @code{enable_sgpr_workgroup_info} flag.
4645
4646@item private_segment_wave_offset
4647Set @code{enable_sgpr_private_segment_wave_byte_offset} flag. Always on
4648(required to locate the stack).
4649
4650@item work_item_id_X
4651Set @code{enable_vgpr_workitem_id} parameter. Always on (can't be disabled).
4652
4653@item work_item_id_Y
4654Set @code{enable_vgpr_workitem_id} parameter. Always on (required to enable
4655vectorization.)
4656
4657@item work_item_id_Z
4658Set @code{enable_vgpr_workitem_id} parameter. Always on (required to use
4659OpenACC/OpenMP).
4660
4661@end table
4662@end table
4663
4664@node ARC Function Attributes
4665@subsection ARC Function Attributes
4666
4667These function attributes are supported by the ARC back end:
4668
4669@table @code
d77de738 4670@cindex @code{interrupt} function attribute, ARC
f33d7a88 4671@item interrupt
d77de738
ML
4672Use this attribute to indicate
4673that the specified function is an interrupt handler. The compiler generates
4674function entry and exit sequences suitable for use in an interrupt handler
4675when this attribute is present.
4676
4677On the ARC, you must specify the kind of interrupt to be handled
4678in a parameter to the interrupt attribute like this:
4679
4680@smallexample
4681void f () __attribute__ ((interrupt ("ilink1")));
4682@end smallexample
4683
4684Permissible values for this parameter are: @w{@code{ilink1}} and
4685@w{@code{ilink2}} for ARCv1 architecture, and @w{@code{ilink}} and
4686@w{@code{firq}} for ARCv2 architecture.
4687
d77de738
ML
4688@cindex @code{long_call} function attribute, ARC
4689@cindex @code{medium_call} function attribute, ARC
4690@cindex @code{short_call} function attribute, ARC
4691@cindex indirect calls, ARC
f33d7a88
AA
4692@item long_call
4693@itemx medium_call
4694@itemx short_call
d77de738
ML
4695These attributes specify how a particular function is called.
4696These attributes override the
4697@option{-mlong-calls} and @option{-mmedium-calls} (@pxref{ARC Options})
4698command-line switches and @code{#pragma long_calls} settings.
4699
4700For ARC, a function marked with the @code{long_call} attribute is
4701always called using register-indirect jump-and-link instructions,
4702thereby enabling the called function to be placed anywhere within the
470332-bit address space. A function marked with the @code{medium_call}
4704attribute will always be close enough to be called with an unconditional
4705branch-and-link instruction, which has a 25-bit offset from
4706the call site. A function marked with the @code{short_call}
4707attribute will always be close enough to be called with a conditional
4708branch-and-link instruction, which has a 21-bit offset from
4709the call site.
4710
d77de738 4711@cindex @code{jli_always} function attribute, ARC
f33d7a88 4712@item jli_always
d77de738
ML
4713Forces a particular function to be called using @code{jli}
4714instruction. The @code{jli} instruction makes use of a table stored
4715into @code{.jlitab} section, which holds the location of the functions
4716which are addressed using this instruction.
4717
d77de738 4718@cindex @code{jli_fixed} function attribute, ARC
f33d7a88 4719@item jli_fixed
d77de738
ML
4720Identical like the above one, but the location of the function in the
4721@code{jli} table is known and given as an attribute parameter.
4722
d77de738 4723@cindex @code{secure_call} function attribute, ARC
f33d7a88 4724@item secure_call
d77de738
ML
4725This attribute allows one to mark secure-code functions that are
4726callable from normal mode. The location of the secure call function
4727into the @code{sjli} table needs to be passed as argument.
4728
d77de738 4729@cindex @code{naked} function attribute, ARC
f33d7a88 4730@item naked
d77de738
ML
4731This attribute allows the compiler to construct the requisite function
4732declaration, while allowing the body of the function to be assembly
4733code. The specified function will not have prologue/epilogue
4734sequences generated by the compiler. Only basic @code{asm} statements
4735can safely be included in naked functions (@pxref{Basic Asm}). While
4736using extended @code{asm} or a mixture of basic @code{asm} and C code
4737may appear to work, they cannot be depended upon to work reliably and
4738are not supported.
4739
4740@end table
4741
4742@node ARM Function Attributes
4743@subsection ARM Function Attributes
4744
4745These function attributes are supported for ARM targets:
4746
4747@table @code
4748
d77de738 4749@cindex @code{general-regs-only} function attribute, ARM
f33d7a88 4750@item general-regs-only
d77de738
ML
4751Indicates that no floating-point or Advanced SIMD registers should be
4752used when generating code for this function. If the function explicitly
4753uses floating-point code, then the compiler gives an error. This is
4754the same behavior as that of the command-line option
4755@option{-mgeneral-regs-only}.
4756
d77de738 4757@cindex @code{interrupt} function attribute, ARM
f33d7a88 4758@item interrupt
d77de738
ML
4759Use this attribute to indicate
4760that the specified function is an interrupt handler. The compiler generates
4761function entry and exit sequences suitable for use in an interrupt handler
4762when this attribute is present.
4763
4764You can specify the kind of interrupt to be handled by
4765adding an optional parameter to the interrupt attribute like this:
4766
4767@smallexample
4768void f () __attribute__ ((interrupt ("IRQ")));
4769@end smallexample
4770
4771@noindent
4772Permissible values for this parameter are: @code{IRQ}, @code{FIQ},
4773@code{SWI}, @code{ABORT} and @code{UNDEF}.
4774
4775On ARMv7-M the interrupt type is ignored, and the attribute means the function
4776may be called with a word-aligned stack pointer.
4777
d77de738 4778@cindex @code{isr} function attribute, ARM
f33d7a88 4779@item isr
d77de738
ML
4780Use this attribute on ARM to write Interrupt Service Routines. This is an
4781alias to the @code{interrupt} attribute above.
4782
d77de738
ML
4783@cindex @code{long_call} function attribute, ARM
4784@cindex @code{short_call} function attribute, ARM
4785@cindex indirect calls, ARM
f33d7a88
AA
4786@item long_call
4787@itemx short_call
d77de738
ML
4788These attributes specify how a particular function is called.
4789These attributes override the
4790@option{-mlong-calls} (@pxref{ARM Options})
4791command-line switch and @code{#pragma long_calls} settings. For ARM, the
4792@code{long_call} attribute indicates that the function might be far
4793away from the call site and require a different (more expensive)
4794calling sequence. The @code{short_call} attribute always places
4795the offset to the function from the call site into the @samp{BL}
4796instruction directly.
4797
d77de738 4798@cindex @code{naked} function attribute, ARM
f33d7a88 4799@item naked
d77de738
ML
4800This attribute allows the compiler to construct the
4801requisite function declaration, while allowing the body of the
4802function to be assembly code. The specified function will not have
4803prologue/epilogue sequences generated by the compiler. Only basic
4804@code{asm} statements can safely be included in naked functions
4805(@pxref{Basic Asm}). While using extended @code{asm} or a mixture of
4806basic @code{asm} and C code may appear to work, they cannot be
4807depended upon to work reliably and are not supported.
4808
d77de738 4809@cindex @code{pcs} function attribute, ARM
f33d7a88 4810@item pcs
d77de738
ML
4811
4812The @code{pcs} attribute can be used to control the calling convention
4813used for a function on ARM. The attribute takes an argument that specifies
4814the calling convention to use.
4815
4816When compiling using the AAPCS ABI (or a variant of it) then valid
4817values for the argument are @code{"aapcs"} and @code{"aapcs-vfp"}. In
4818order to use a variant other than @code{"aapcs"} then the compiler must
4819be permitted to use the appropriate co-processor registers (i.e., the
4820VFP registers must be available in order to use @code{"aapcs-vfp"}).
4821For example,
4822
4823@smallexample
4824/* Argument passed in r0, and result returned in r0+r1. */
4825double f2d (float) __attribute__((pcs("aapcs")));
4826@end smallexample
4827
4828Variadic functions always use the @code{"aapcs"} calling convention and
4829the compiler rejects attempts to specify an alternative.
4830
d77de738 4831@cindex @code{target} function attribute
f33d7a88 4832@item target (@var{options})
d77de738
ML
4833As discussed in @ref{Common Function Attributes}, this attribute
4834allows specification of target-specific compilation options.
4835
4836On ARM, the following options are allowed:
4837
4838@table @samp
d77de738 4839@cindex @code{target("thumb")} function attribute, ARM
f33d7a88 4840@item thumb
d77de738
ML
4841Force code generation in the Thumb (T16/T32) ISA, depending on the
4842architecture level.
4843
d77de738 4844@cindex @code{target("arm")} function attribute, ARM
f33d7a88 4845@item arm
d77de738
ML
4846Force code generation in the ARM (A32) ISA.
4847
4848Functions from different modes can be inlined in the caller's mode.
4849
d77de738 4850@cindex @code{target("fpu=")} function attribute, ARM
f33d7a88 4851@item fpu=
d77de738
ML
4852Specifies the fpu for which to tune the performance of this function.
4853The behavior and permissible arguments are the same as for the @option{-mfpu=}
4854command-line option.
4855
d77de738 4856@cindex @code{arch=} function attribute, ARM
f33d7a88 4857@item arch=
d77de738
ML
4858Specifies the architecture version and architectural extensions to use
4859for this function. The behavior and permissible arguments are the same as
4860for the @option{-march=} command-line option.
4861
4862The above target attributes can be specified as follows:
4863
4864@smallexample
4865__attribute__((target("arch=armv8-a+crc")))
4866int
4867f (int a)
4868@{
4869 return a + 5;
4870@}
4871@end smallexample
4872
4873Additionally, the architectural extension string may be specified on its
4874own. This can be used to turn on and off particular architectural extensions
4875without having to specify a particular architecture version or core. Example:
4876
4877@smallexample
4878__attribute__((target("+crc+nocrypto")))
4879int
4880foo (int a)
4881@{
4882 return a + 5;
4883@}
4884@end smallexample
4885
4886In this example @code{target("+crc+nocrypto")} enables the @code{crc}
4887extension and disables the @code{crypto} extension for the function @code{foo}
4888without modifying an existing @option{-march=} or @option{-mcpu} option.
4889
4890@end table
4891
4892@end table
4893
4894@node AVR Function Attributes
4895@subsection AVR Function Attributes
4896
4897These function attributes are supported by the AVR back end:
4898
4899@table @code
d77de738 4900@cindex @code{interrupt} function attribute, AVR
f33d7a88 4901@item interrupt
d77de738
ML
4902Use this attribute to indicate
4903that the specified function is an interrupt handler. The compiler generates
4904function entry and exit sequences suitable for use in an interrupt handler
4905when this attribute is present.
4906
4907On the AVR, the hardware globally disables interrupts when an
4908interrupt is executed. The first instruction of an interrupt handler
4909declared with this attribute is a @code{SEI} instruction to
4910re-enable interrupts. See also the @code{signal} function attribute
4911that does not insert a @code{SEI} instruction. If both @code{signal} and
4912@code{interrupt} are specified for the same function, @code{signal}
4913is silently ignored.
4914
d77de738 4915@cindex @code{naked} function attribute, AVR
f33d7a88 4916@item naked
d77de738
ML
4917This attribute allows the compiler to construct the
4918requisite function declaration, while allowing the body of the
4919function to be assembly code. The specified function will not have
4920prologue/epilogue sequences generated by the compiler. Only basic
4921@code{asm} statements can safely be included in naked functions
4922(@pxref{Basic Asm}). While using extended @code{asm} or a mixture of
4923basic @code{asm} and C code may appear to work, they cannot be
4924depended upon to work reliably and are not supported.
4925
d77de738 4926@cindex @code{no_gccisr} function attribute, AVR
f33d7a88 4927@item no_gccisr
d77de738
ML
4928Do not use @code{__gcc_isr} pseudo instructions in a function with
4929the @code{interrupt} or @code{signal} attribute aka. interrupt
4930service routine (ISR).
4931Use this attribute if the preamble of the ISR prologue should always read
4932@example
4933push __zero_reg__
4934push __tmp_reg__
4935in __tmp_reg__, __SREG__
4936push __tmp_reg__
4937clr __zero_reg__
4938@end example
4939and accordingly for the postamble of the epilogue --- no matter whether
4940the mentioned registers are actually used in the ISR or not.
4941Situations where you might want to use this attribute include:
4942@itemize @bullet
4943@item
4944Code that (effectively) clobbers bits of @code{SREG} other than the
4945@code{I}-flag by writing to the memory location of @code{SREG}.
4946@item
4947Code that uses inline assembler to jump to a different function which
4948expects (parts of) the prologue code as outlined above to be present.
4949@end itemize
4950To disable @code{__gcc_isr} generation for the whole compilation unit,
4951there is option @option{-mno-gas-isr-prologues}, @pxref{AVR Options}.
4952
d77de738
ML
4953@cindex @code{OS_main} function attribute, AVR
4954@cindex @code{OS_task} function attribute, AVR
f33d7a88
AA
4955@item OS_main
4956@itemx OS_task
d77de738
ML
4957On AVR, functions with the @code{OS_main} or @code{OS_task} attribute
4958do not save/restore any call-saved register in their prologue/epilogue.
4959
4960The @code{OS_main} attribute can be used when there @emph{is
4961guarantee} that interrupts are disabled at the time when the function
4962is entered. This saves resources when the stack pointer has to be
4963changed to set up a frame for local variables.
4964
4965The @code{OS_task} attribute can be used when there is @emph{no
4966guarantee} that interrupts are disabled at that time when the function
4967is entered like for, e@.g@. task functions in a multi-threading operating
4968system. In that case, changing the stack pointer register is
4969guarded by save/clear/restore of the global interrupt enable flag.
4970
4971The differences to the @code{naked} function attribute are:
4972@itemize @bullet
4973@item @code{naked} functions do not have a return instruction whereas
4974@code{OS_main} and @code{OS_task} functions have a @code{RET} or
4975@code{RETI} return instruction.
4976@item @code{naked} functions do not set up a frame for local variables
4977or a frame pointer whereas @code{OS_main} and @code{OS_task} do this
4978as needed.
4979@end itemize
4980
d77de738 4981@cindex @code{signal} function attribute, AVR
f33d7a88 4982@item signal
d77de738
ML
4983Use this attribute on the AVR to indicate that the specified
4984function is an interrupt handler. The compiler generates function
4985entry and exit sequences suitable for use in an interrupt handler when this
4986attribute is present.
4987
4988See also the @code{interrupt} function attribute.
4989
4990The AVR hardware globally disables interrupts when an interrupt is executed.
4991Interrupt handler functions defined with the @code{signal} attribute
4992do not re-enable interrupts. It is save to enable interrupts in a
4993@code{signal} handler. This ``save'' only applies to the code
4994generated by the compiler and not to the IRQ layout of the
4995application which is responsibility of the application.
4996
4997If both @code{signal} and @code{interrupt} are specified for the same
4998function, @code{signal} is silently ignored.
4999@end table
5000
5001@node Blackfin Function Attributes
5002@subsection Blackfin Function Attributes
5003
5004These function attributes are supported by the Blackfin back end:
5005
5006@table @code
5007
d77de738
ML
5008@cindex @code{exception_handler} function attribute
5009@cindex exception handler functions, Blackfin
f33d7a88 5010@item exception_handler
d77de738
ML
5011Use this attribute on the Blackfin to indicate that the specified function
5012is an exception handler. The compiler generates function entry and
5013exit sequences suitable for use in an exception handler when this
5014attribute is present.
5015
d77de738 5016@cindex @code{interrupt_handler} function attribute, Blackfin
f33d7a88 5017@item interrupt_handler
d77de738
ML
5018Use this attribute to
5019indicate that the specified function is an interrupt handler. The compiler
5020generates function entry and exit sequences suitable for use in an
5021interrupt handler when this attribute is present.
5022
d77de738
ML
5023@cindex @code{kspisusp} function attribute, Blackfin
5024@cindex User stack pointer in interrupts on the Blackfin
f33d7a88 5025@item kspisusp
d77de738
ML
5026When used together with @code{interrupt_handler}, @code{exception_handler}
5027or @code{nmi_handler}, code is generated to load the stack pointer
5028from the USP register in the function prologue.
5029
d77de738 5030@cindex @code{l1_text} function attribute, Blackfin
f33d7a88 5031@item l1_text
d77de738
ML
5032This attribute specifies a function to be placed into L1 Instruction
5033SRAM@. The function is put into a specific section named @code{.l1.text}.
5034With @option{-mfdpic}, function calls with a such function as the callee
5035or caller uses inlined PLT.
5036
d77de738 5037@cindex @code{l2} function attribute, Blackfin
f33d7a88 5038@item l2
d77de738
ML
5039This attribute specifies a function to be placed into L2
5040SRAM. The function is put into a specific section named
5041@code{.l2.text}. With @option{-mfdpic}, callers of such functions use
5042an inlined PLT.
5043
d77de738
ML
5044@cindex indirect calls, Blackfin
5045@cindex @code{longcall} function attribute, Blackfin
5046@cindex @code{shortcall} function attribute, Blackfin
f33d7a88
AA
5047@item longcall
5048@itemx shortcall
d77de738
ML
5049The @code{longcall} attribute
5050indicates that the function might be far away from the call site and
5051require a different (more expensive) calling sequence. The
5052@code{shortcall} attribute indicates that the function is always close
5053enough for the shorter calling sequence to be used. These attributes
5054override the @option{-mlongcall} switch.
5055
d77de738
ML
5056@cindex @code{nesting} function attribute, Blackfin
5057@cindex Allow nesting in an interrupt handler on the Blackfin processor
f33d7a88 5058@item nesting
d77de738
ML
5059Use this attribute together with @code{interrupt_handler},
5060@code{exception_handler} or @code{nmi_handler} to indicate that the function
5061entry code should enable nested interrupts or exceptions.
5062
d77de738
ML
5063@cindex @code{nmi_handler} function attribute, Blackfin
5064@cindex NMI handler functions on the Blackfin processor
f33d7a88 5065@item nmi_handler
d77de738
ML
5066Use this attribute on the Blackfin to indicate that the specified function
5067is an NMI handler. The compiler generates function entry and
5068exit sequences suitable for use in an NMI handler when this
5069attribute is present.
5070
d77de738
ML
5071@cindex @code{saveall} function attribute, Blackfin
5072@cindex save all registers on the Blackfin
f33d7a88 5073@item saveall
d77de738
ML
5074Use this attribute to indicate that
5075all registers except the stack pointer should be saved in the prologue
5076regardless of whether they are used or not.
5077@end table
5078
5079@node BPF Function Attributes
5080@subsection BPF Function Attributes
5081
5082These function attributes are supported by the BPF back end:
5083
5084@table @code
d77de738 5085@cindex @code{kernel helper}, function attribute, BPF
f33d7a88 5086@item kernel_helper
d77de738
ML
5087use this attribute to indicate the specified function declaration is a
5088kernel helper. The helper function is passed as an argument to the
5089attribute. Example:
5090
5091@smallexample
5092int bpf_probe_read (void *dst, int size, const void *unsafe_ptr)
5093 __attribute__ ((kernel_helper (4)));
5094@end smallexample
5095@end table
5096
5097@node C-SKY Function Attributes
5098@subsection C-SKY Function Attributes
5099
5100These function attributes are supported by the C-SKY back end:
5101
5102@table @code
d77de738
ML
5103@cindex @code{interrupt} function attribute, C-SKY
5104@cindex @code{isr} function attribute, C-SKY
f33d7a88
AA
5105@item interrupt
5106@itemx isr
d77de738
ML
5107Use these attributes to indicate that the specified function
5108is an interrupt handler.
5109The compiler generates function entry and exit sequences suitable for
5110use in an interrupt handler when either of these attributes are present.
5111
5112Use of these options requires the @option{-mistack} command-line option
5113to enable support for the necessary interrupt stack instructions. They
5114are ignored with a warning otherwise. @xref{C-SKY Options}.
5115
d77de738 5116@cindex @code{naked} function attribute, C-SKY
f33d7a88 5117@item naked
d77de738
ML
5118This attribute allows the compiler to construct the
5119requisite function declaration, while allowing the body of the
5120function to be assembly code. The specified function will not have
5121prologue/epilogue sequences generated by the compiler. Only basic
5122@code{asm} statements can safely be included in naked functions
5123(@pxref{Basic Asm}). While using extended @code{asm} or a mixture of
5124basic @code{asm} and C code may appear to work, they cannot be
5125depended upon to work reliably and are not supported.
5126@end table
5127
5128
5129@node Epiphany Function Attributes
5130@subsection Epiphany Function Attributes
5131
5132These function attributes are supported by the Epiphany back end:
5133
5134@table @code
d77de738 5135@cindex @code{disinterrupt} function attribute, Epiphany
f33d7a88 5136@item disinterrupt
d77de738
ML
5137This attribute causes the compiler to emit
5138instructions to disable interrupts for the duration of the given
5139function.
5140
d77de738 5141@cindex @code{forwarder_section} function attribute, Epiphany
f33d7a88 5142@item forwarder_section
d77de738
ML
5143This attribute modifies the behavior of an interrupt handler.
5144The interrupt handler may be in external memory which cannot be
5145reached by a branch instruction, so generate a local memory trampoline
5146to transfer control. The single parameter identifies the section where
5147the trampoline is placed.
5148
d77de738 5149@cindex @code{interrupt} function attribute, Epiphany
f33d7a88 5150@item interrupt
d77de738
ML
5151Use this attribute to indicate
5152that the specified function is an interrupt handler. The compiler generates
5153function entry and exit sequences suitable for use in an interrupt handler
5154when this attribute is present. It may also generate
5155a special section with code to initialize the interrupt vector table.
5156
5157On Epiphany targets one or more optional parameters can be added like this:
5158
5159@smallexample
5160void __attribute__ ((interrupt ("dma0, dma1"))) universal_dma_handler ();
5161@end smallexample
5162
5163Permissible values for these parameters are: @w{@code{reset}},
5164@w{@code{software_exception}}, @w{@code{page_miss}},
5165@w{@code{timer0}}, @w{@code{timer1}}, @w{@code{message}},
5166@w{@code{dma0}}, @w{@code{dma1}}, @w{@code{wand}} and @w{@code{swi}}.
5167Multiple parameters indicate that multiple entries in the interrupt
5168vector table should be initialized for this function, i.e.@: for each
5169parameter @w{@var{name}}, a jump to the function is emitted in
5170the section @w{ivt_entry_@var{name}}. The parameter(s) may be omitted
5171entirely, in which case no interrupt vector table entry is provided.
5172
5173Note that interrupts are enabled inside the function
5174unless the @code{disinterrupt} attribute is also specified.
5175
5176The following examples are all valid uses of these attributes on
5177Epiphany targets:
5178@smallexample
5179void __attribute__ ((interrupt)) universal_handler ();
5180void __attribute__ ((interrupt ("dma1"))) dma1_handler ();
5181void __attribute__ ((interrupt ("dma0, dma1")))
5182 universal_dma_handler ();
5183void __attribute__ ((interrupt ("timer0"), disinterrupt))
5184 fast_timer_handler ();
5185void __attribute__ ((interrupt ("dma0, dma1"),
5186 forwarder_section ("tramp")))
5187 external_dma_handler ();
5188@end smallexample
5189
d77de738
ML
5190@cindex @code{long_call} function attribute, Epiphany
5191@cindex @code{short_call} function attribute, Epiphany
5192@cindex indirect calls, Epiphany
f33d7a88
AA
5193@item long_call
5194@itemx short_call
d77de738
ML
5195These attributes specify how a particular function is called.
5196These attributes override the
5197@option{-mlong-calls} (@pxref{Adapteva Epiphany Options})
5198command-line switch and @code{#pragma long_calls} settings.
5199@end table
5200
5201
5202@node H8/300 Function Attributes
5203@subsection H8/300 Function Attributes
5204
5205These function attributes are available for H8/300 targets:
5206
5207@table @code
d77de738 5208@cindex @code{function_vector} function attribute, H8/300
f33d7a88 5209@item function_vector
d77de738
ML
5210Use this attribute on the H8/300, H8/300H, and H8S to indicate
5211that the specified function should be called through the function vector.
5212Calling a function through the function vector reduces code size; however,
5213the function vector has a limited size (maximum 128 entries on the H8/300
5214and 64 entries on the H8/300H and H8S)
5215and shares space with the interrupt vector.
5216
d77de738 5217@cindex @code{interrupt_handler} function attribute, H8/300
f33d7a88 5218@item interrupt_handler
d77de738
ML
5219Use this attribute on the H8/300, H8/300H, and H8S to
5220indicate that the specified function is an interrupt handler. The compiler
5221generates function entry and exit sequences suitable for use in an
5222interrupt handler when this attribute is present.
5223
d77de738
ML
5224@cindex @code{saveall} function attribute, H8/300
5225@cindex save all registers on the H8/300, H8/300H, and H8S
f33d7a88 5226@item saveall
d77de738
ML
5227Use this attribute on the H8/300, H8/300H, and H8S to indicate that
5228all registers except the stack pointer should be saved in the prologue
5229regardless of whether they are used or not.
5230@end table
5231
5232@node IA-64 Function Attributes
5233@subsection IA-64 Function Attributes
5234
5235These function attributes are supported on IA-64 targets:
5236
5237@table @code
d77de738 5238@cindex @code{syscall_linkage} function attribute, IA-64
f33d7a88 5239@item syscall_linkage
d77de738
ML
5240This attribute is used to modify the IA-64 calling convention by marking
5241all input registers as live at all function exits. This makes it possible
5242to restart a system call after an interrupt without having to save/restore
5243the input registers. This also prevents kernel data from leaking into
5244application code.
5245
d77de738 5246@cindex @code{version_id} function attribute, IA-64
f33d7a88 5247@item version_id
d77de738
ML
5248This IA-64 HP-UX attribute, attached to a global variable or function, renames a
5249symbol to contain a version string, thus allowing for function level
5250versioning. HP-UX system header files may use function level versioning
5251for some system calls.
5252
5253@smallexample
5254extern int foo () __attribute__((version_id ("20040821")));
5255@end smallexample
5256
5257@noindent
5258Calls to @code{foo} are mapped to calls to @code{foo@{20040821@}}.
5259@end table
5260
5261@node M32C Function Attributes
5262@subsection M32C Function Attributes
5263
5264These function attributes are supported by the M32C back end:
5265
5266@table @code
d77de738 5267@cindex @code{bank_switch} function attribute, M32C
f33d7a88 5268@item bank_switch
d77de738
ML
5269When added to an interrupt handler with the M32C port, causes the
5270prologue and epilogue to use bank switching to preserve the registers
5271rather than saving them on the stack.
5272
d77de738 5273@cindex @code{fast_interrupt} function attribute, M32C
f33d7a88 5274@item fast_interrupt
d77de738
ML
5275Use this attribute on the M32C port to indicate that the specified
5276function is a fast interrupt handler. This is just like the
5277@code{interrupt} attribute, except that @code{freit} is used to return
5278instead of @code{reit}.
5279
d77de738 5280@cindex @code{function_vector} function attribute, M16C/M32C
f33d7a88 5281@item function_vector
d77de738
ML
5282On M16C/M32C targets, the @code{function_vector} attribute declares a
5283special page subroutine call function. Use of this attribute reduces
5284the code size by 2 bytes for each call generated to the
5285subroutine. The argument to the attribute is the vector number entry
5286from the special page vector table which contains the 16 low-order
5287bits of the subroutine's entry address. Each vector table has special
5288page number (18 to 255) that is used in @code{jsrs} instructions.
5289Jump addresses of the routines are generated by adding 0x0F0000 (in
5290case of M16C targets) or 0xFF0000 (in case of M32C targets), to the
52912-byte addresses set in the vector table. Therefore you need to ensure
5292that all the special page vector routines should get mapped within the
5293address range 0x0F0000 to 0x0FFFFF (for M16C) and 0xFF0000 to 0xFFFFFF
5294(for M32C).
5295
5296In the following example 2 bytes are saved for each call to
5297function @code{foo}.
5298
5299@smallexample
5300void foo (void) __attribute__((function_vector(0x18)));
5301void foo (void)
5302@{
5303@}
5304
5305void bar (void)
5306@{
5307 foo();
5308@}
5309@end smallexample
5310
5311If functions are defined in one file and are called in another file,
5312then be sure to write this declaration in both files.
5313
5314This attribute is ignored for R8C target.
5315
d77de738 5316@cindex @code{interrupt} function attribute, M32C
f33d7a88 5317@item interrupt
d77de738
ML
5318Use this attribute to indicate
5319that the specified function is an interrupt handler. The compiler generates
5320function entry and exit sequences suitable for use in an interrupt handler
5321when this attribute is present.
5322@end table
5323
5324@node M32R/D Function Attributes
5325@subsection M32R/D Function Attributes
5326
5327These function attributes are supported by the M32R/D back end:
5328
5329@table @code
d77de738 5330@cindex @code{interrupt} function attribute, M32R/D
f33d7a88 5331@item interrupt
d77de738
ML
5332Use this attribute to indicate
5333that the specified function is an interrupt handler. The compiler generates
5334function entry and exit sequences suitable for use in an interrupt handler
5335when this attribute is present.
5336
d77de738
ML
5337@cindex @code{model} function attribute, M32R/D
5338@cindex function addressability on the M32R/D
f33d7a88 5339@item model (@var{model-name})
d77de738
ML
5340
5341On the M32R/D, use this attribute to set the addressability of an
5342object, and of the code generated for a function. The identifier
5343@var{model-name} is one of @code{small}, @code{medium}, or
5344@code{large}, representing each of the code models.
5345
5346Small model objects live in the lower 16MB of memory (so that their
5347addresses can be loaded with the @code{ld24} instruction), and are
5348callable with the @code{bl} instruction.
5349
5350Medium model objects may live anywhere in the 32-bit address space (the
5351compiler generates @code{seth/add3} instructions to load their addresses),
5352and are callable with the @code{bl} instruction.
5353
5354Large model objects may live anywhere in the 32-bit address space (the
5355compiler generates @code{seth/add3} instructions to load their addresses),
5356and may not be reachable with the @code{bl} instruction (the compiler
5357generates the much slower @code{seth/add3/jl} instruction sequence).
5358@end table
5359
5360@node m68k Function Attributes
5361@subsection m68k Function Attributes
5362
5363These function attributes are supported by the m68k back end:
5364
5365@table @code
d77de738
ML
5366@cindex @code{interrupt} function attribute, m68k
5367@cindex @code{interrupt_handler} function attribute, m68k
f33d7a88
AA
5368@item interrupt
5369@itemx interrupt_handler
d77de738
ML
5370Use this attribute to
5371indicate that the specified function is an interrupt handler. The compiler
5372generates function entry and exit sequences suitable for use in an
5373interrupt handler when this attribute is present. Either name may be used.
5374
d77de738 5375@cindex @code{interrupt_thread} function attribute, fido
f33d7a88 5376@item interrupt_thread
d77de738
ML
5377Use this attribute on fido, a subarchitecture of the m68k, to indicate
5378that the specified function is an interrupt handler that is designed
5379to run as a thread. The compiler omits generate prologue/epilogue
5380sequences and replaces the return instruction with a @code{sleep}
5381instruction. This attribute is available only on fido.
5382@end table
5383
5384@node MCORE Function Attributes
5385@subsection MCORE Function Attributes
5386
5387These function attributes are supported by the MCORE back end:
5388
5389@table @code
d77de738 5390@cindex @code{naked} function attribute, MCORE
f33d7a88 5391@item naked
d77de738
ML
5392This attribute allows the compiler to construct the
5393requisite function declaration, while allowing the body of the
5394function to be assembly code. The specified function will not have
5395prologue/epilogue sequences generated by the compiler. Only basic
5396@code{asm} statements can safely be included in naked functions
5397(@pxref{Basic Asm}). While using extended @code{asm} or a mixture of
5398basic @code{asm} and C code may appear to work, they cannot be
5399depended upon to work reliably and are not supported.
5400@end table
5401
d77de738
ML
5402@node MicroBlaze Function Attributes
5403@subsection MicroBlaze Function Attributes
5404
5405These function attributes are supported on MicroBlaze targets:
5406
5407@table @code
d77de738 5408@cindex @code{save_volatiles} function attribute, MicroBlaze
f33d7a88 5409@item save_volatiles
d77de738
ML
5410Use this attribute to indicate that the function is
5411an interrupt handler. All volatile registers (in addition to non-volatile
5412registers) are saved in the function prologue. If the function is a leaf
5413function, only volatiles used by the function are saved. A normal function
5414return is generated instead of a return from interrupt.
5415
d77de738
ML
5416@cindex @code{break_handler} function attribute, MicroBlaze
5417@cindex break handler functions
f33d7a88 5418@item break_handler
d77de738
ML
5419Use this attribute to indicate that
5420the specified function is a break handler. The compiler generates function
5421entry and exit sequences suitable for use in an break handler when this
5422attribute is present. The return from @code{break_handler} is done through
5423the @code{rtbd} instead of @code{rtsd}.
5424
5425@smallexample
5426void f () __attribute__ ((break_handler));
5427@end smallexample
5428
d77de738
ML
5429@cindex @code{interrupt_handler} function attribute, MicroBlaze
5430@cindex @code{fast_interrupt} function attribute, MicroBlaze
f33d7a88
AA
5431@item interrupt_handler
5432@itemx fast_interrupt
d77de738
ML
5433These attributes indicate that the specified function is an interrupt
5434handler. Use the @code{fast_interrupt} attribute to indicate handlers
5435used in low-latency interrupt mode, and @code{interrupt_handler} for
5436interrupts that do not use low-latency handlers. In both cases, GCC
5437emits appropriate prologue code and generates a return from the handler
5438using @code{rtid} instead of @code{rtsd}.
5439@end table
5440
5441@node Microsoft Windows Function Attributes
5442@subsection Microsoft Windows Function Attributes
5443
5444The following attributes are available on Microsoft Windows and Symbian OS
5445targets.
5446
5447@table @code
d77de738
ML
5448@cindex @code{dllexport} function attribute
5449@cindex @code{__declspec(dllexport)}
f33d7a88 5450@item dllexport
d77de738
ML
5451On Microsoft Windows targets and Symbian OS targets the
5452@code{dllexport} attribute causes the compiler to provide a global
5453pointer to a pointer in a DLL, so that it can be referenced with the
5454@code{dllimport} attribute. On Microsoft Windows targets, the pointer
5455name is formed by combining @code{_imp__} and the function or variable
5456name.
5457
5458You can use @code{__declspec(dllexport)} as a synonym for
5459@code{__attribute__ ((dllexport))} for compatibility with other
5460compilers.
5461
5462On systems that support the @code{visibility} attribute, this
5463attribute also implies ``default'' visibility. It is an error to
5464explicitly specify any other visibility.
5465
5466GCC's default behavior is to emit all inline functions with the
5467@code{dllexport} attribute. Since this can cause object file-size bloat,
5468you can use @option{-fno-keep-inline-dllexport}, which tells GCC to
5469ignore the attribute for inlined functions unless the
5470@option{-fkeep-inline-functions} flag is used instead.
5471
5472The attribute is ignored for undefined symbols.
5473
5474When applied to C++ classes, the attribute marks defined non-inlined
5475member functions and static data members as exports. Static consts
5476initialized in-class are not marked unless they are also defined
5477out-of-class.
5478
5479For Microsoft Windows targets there are alternative methods for
5480including the symbol in the DLL's export table such as using a
5481@file{.def} file with an @code{EXPORTS} section or, with GNU ld, using
5482the @option{--export-all} linker flag.
5483
d77de738
ML
5484@cindex @code{dllimport} function attribute
5485@cindex @code{__declspec(dllimport)}
f33d7a88 5486@item dllimport
d77de738
ML
5487On Microsoft Windows and Symbian OS targets, the @code{dllimport}
5488attribute causes the compiler to reference a function or variable via
5489a global pointer to a pointer that is set up by the DLL exporting the
5490symbol. The attribute implies @code{extern}. On Microsoft Windows
5491targets, the pointer name is formed by combining @code{_imp__} and the
5492function or variable name.
5493
5494You can use @code{__declspec(dllimport)} as a synonym for
5495@code{__attribute__ ((dllimport))} for compatibility with other
5496compilers.
5497
5498On systems that support the @code{visibility} attribute, this
5499attribute also implies ``default'' visibility. It is an error to
5500explicitly specify any other visibility.
5501
5502Currently, the attribute is ignored for inlined functions. If the
5503attribute is applied to a symbol @emph{definition}, an error is reported.
5504If a symbol previously declared @code{dllimport} is later defined, the
5505attribute is ignored in subsequent references, and a warning is emitted.
5506The attribute is also overridden by a subsequent declaration as
5507@code{dllexport}.
5508
5509When applied to C++ classes, the attribute marks non-inlined
5510member functions and static data members as imports. However, the
5511attribute is ignored for virtual methods to allow creation of vtables
5512using thunks.
5513
5514On the SH Symbian OS target the @code{dllimport} attribute also has
5515another affect---it can cause the vtable and run-time type information
5516for a class to be exported. This happens when the class has a
5517dllimported constructor or a non-inline, non-pure virtual function
5518and, for either of those two conditions, the class also has an inline
5519constructor or destructor and has a key function that is defined in
5520the current translation unit.
5521
5522For Microsoft Windows targets the use of the @code{dllimport}
5523attribute on functions is not necessary, but provides a small
5524performance benefit by eliminating a thunk in the DLL@. The use of the
5525@code{dllimport} attribute on imported variables can be avoided by passing the
5526@option{--enable-auto-import} switch to the GNU linker. As with
5527functions, using the attribute for a variable eliminates a thunk in
5528the DLL@.
5529
5530One drawback to using this attribute is that a pointer to a
5531@emph{variable} marked as @code{dllimport} cannot be used as a constant
5532address. However, a pointer to a @emph{function} with the
5533@code{dllimport} attribute can be used as a constant initializer; in
5534this case, the address of a stub function in the import lib is
5535referenced. On Microsoft Windows targets, the attribute can be disabled
5536for functions by setting the @option{-mnop-fun-dllimport} flag.
5537@end table
5538
5539@node MIPS Function Attributes
5540@subsection MIPS Function Attributes
5541
5542These function attributes are supported by the MIPS back end:
5543
5544@table @code
d77de738 5545@cindex @code{interrupt} function attribute, MIPS
f33d7a88 5546@item interrupt
d77de738
ML
5547Use this attribute to indicate that the specified function is an interrupt
5548handler. The compiler generates function entry and exit sequences suitable
5549for use in an interrupt handler when this attribute is present.
5550An optional argument is supported for the interrupt attribute which allows
5551the interrupt mode to be described. By default GCC assumes the external
5552interrupt controller (EIC) mode is in use, this can be explicitly set using
5553@code{eic}. When interrupts are non-masked then the requested Interrupt
5554Priority Level (IPL) is copied to the current IPL which has the effect of only
5555enabling higher priority interrupts. To use vectored interrupt mode use
5556the argument @code{vector=[sw0|sw1|hw0|hw1|hw2|hw3|hw4|hw5]}, this will change
5557the behavior of the non-masked interrupt support and GCC will arrange to mask
5558all interrupts from sw0 up to and including the specified interrupt vector.
5559
5560You can use the following attributes to modify the behavior
5561of an interrupt handler:
5562@table @code
d77de738 5563@cindex @code{use_shadow_register_set} function attribute, MIPS
f33d7a88 5564@item use_shadow_register_set
d77de738
ML
5565Assume that the handler uses a shadow register set, instead of
5566the main general-purpose registers. An optional argument @code{intstack} is
5567supported to indicate that the shadow register set contains a valid stack
5568pointer.
5569
d77de738 5570@cindex @code{keep_interrupts_masked} function attribute, MIPS
f33d7a88 5571@item keep_interrupts_masked
d77de738
ML
5572Keep interrupts masked for the whole function. Without this attribute,
5573GCC tries to reenable interrupts for as much of the function as it can.
5574
d77de738 5575@cindex @code{use_debug_exception_return} function attribute, MIPS
f33d7a88 5576@item use_debug_exception_return
d77de738
ML
5577Return using the @code{deret} instruction. Interrupt handlers that don't
5578have this attribute return using @code{eret} instead.
5579@end table
5580
5581You can use any combination of these attributes, as shown below:
5582@smallexample
5583void __attribute__ ((interrupt)) v0 ();
5584void __attribute__ ((interrupt, use_shadow_register_set)) v1 ();
5585void __attribute__ ((interrupt, keep_interrupts_masked)) v2 ();
5586void __attribute__ ((interrupt, use_debug_exception_return)) v3 ();
5587void __attribute__ ((interrupt, use_shadow_register_set,
5588 keep_interrupts_masked)) v4 ();
5589void __attribute__ ((interrupt, use_shadow_register_set,
5590 use_debug_exception_return)) v5 ();
5591void __attribute__ ((interrupt, keep_interrupts_masked,
5592 use_debug_exception_return)) v6 ();
5593void __attribute__ ((interrupt, use_shadow_register_set,
5594 keep_interrupts_masked,
5595 use_debug_exception_return)) v7 ();
5596void __attribute__ ((interrupt("eic"))) v8 ();
5597void __attribute__ ((interrupt("vector=hw3"))) v9 ();
5598@end smallexample
5599
d77de738
ML
5600@cindex indirect calls, MIPS
5601@cindex @code{long_call} function attribute, MIPS
5602@cindex @code{short_call} function attribute, MIPS
5603@cindex @code{near} function attribute, MIPS
5604@cindex @code{far} function attribute, MIPS
f33d7a88
AA
5605@item long_call
5606@itemx short_call
5607@itemx near
5608@itemx far
d77de738
ML
5609These attributes specify how a particular function is called on MIPS@.
5610The attributes override the @option{-mlong-calls} (@pxref{MIPS Options})
5611command-line switch. The @code{long_call} and @code{far} attributes are
5612synonyms, and cause the compiler to always call
5613the function by first loading its address into a register, and then using
5614the contents of that register. The @code{short_call} and @code{near}
5615attributes are synonyms, and have the opposite
5616effect; they specify that non-PIC calls should be made using the more
5617efficient @code{jal} instruction.
5618
d77de738
ML
5619@cindex @code{mips16} function attribute, MIPS
5620@cindex @code{nomips16} function attribute, MIPS
f33d7a88
AA
5621@item mips16
5622@itemx nomips16
d77de738
ML
5623
5624On MIPS targets, you can use the @code{mips16} and @code{nomips16}
5625function attributes to locally select or turn off MIPS16 code generation.
5626A function with the @code{mips16} attribute is emitted as MIPS16 code,
5627while MIPS16 code generation is disabled for functions with the
5628@code{nomips16} attribute. These attributes override the
5629@option{-mips16} and @option{-mno-mips16} options on the command line
5630(@pxref{MIPS Options}).
5631
5632When compiling files containing mixed MIPS16 and non-MIPS16 code, the
5633preprocessor symbol @code{__mips16} reflects the setting on the command line,
5634not that within individual functions. Mixed MIPS16 and non-MIPS16 code
5635may interact badly with some GCC extensions such as @code{__builtin_apply}
5636(@pxref{Constructing Calls}).
5637
d77de738
ML
5638@cindex @code{micromips} function attribute
5639@cindex @code{nomicromips} function attribute
f33d7a88
AA
5640@item micromips, MIPS
5641@itemx nomicromips, MIPS
d77de738
ML
5642
5643On MIPS targets, you can use the @code{micromips} and @code{nomicromips}
5644function attributes to locally select or turn off microMIPS code generation.
5645A function with the @code{micromips} attribute is emitted as microMIPS code,
5646while microMIPS code generation is disabled for functions with the
5647@code{nomicromips} attribute. These attributes override the
5648@option{-mmicromips} and @option{-mno-micromips} options on the command line
5649(@pxref{MIPS Options}).
5650
5651When compiling files containing mixed microMIPS and non-microMIPS code, the
5652preprocessor symbol @code{__mips_micromips} reflects the setting on the
5653command line,
5654not that within individual functions. Mixed microMIPS and non-microMIPS code
5655may interact badly with some GCC extensions such as @code{__builtin_apply}
5656(@pxref{Constructing Calls}).
5657
d77de738 5658@cindex @code{nocompression} function attribute, MIPS
f33d7a88 5659@item nocompression
d77de738
ML
5660On MIPS targets, you can use the @code{nocompression} function attribute
5661to locally turn off MIPS16 and microMIPS code generation. This attribute
5662overrides the @option{-mips16} and @option{-mmicromips} options on the
5663command line (@pxref{MIPS Options}).
a3a45f0b
JZ
5664
5665@item use_hazard_barrier_return
5666@cindex @code{use_hazard_barrier_return} function attribute, MIPS
5667This function attribute instructs the compiler to generate a hazard barrier
5668return that clears all execution and instruction hazards while returning,
5669instead of generating a normal return instruction.
d77de738
ML
5670@end table
5671
5672@node MSP430 Function Attributes
5673@subsection MSP430 Function Attributes
5674
5675These function attributes are supported by the MSP430 back end:
5676
5677@table @code
d77de738 5678@cindex @code{critical} function attribute, MSP430
f33d7a88 5679@item critical
d77de738
ML
5680Critical functions disable interrupts upon entry and restore the
5681previous interrupt state upon exit. Critical functions cannot also
5682have the @code{naked}, @code{reentrant} or @code{interrupt} attributes.
5683
5684The MSP430 hardware ensures that interrupts are disabled on entry to
5685@code{interrupt} functions, and restores the previous interrupt state
5686on exit. The @code{critical} attribute is therefore redundant on
5687@code{interrupt} functions.
5688
d77de738 5689@cindex @code{interrupt} function attribute, MSP430
f33d7a88 5690@item interrupt
d77de738
ML
5691Use this attribute to indicate
5692that the specified function is an interrupt handler. The compiler generates
5693function entry and exit sequences suitable for use in an interrupt handler
5694when this attribute is present.
5695
5696You can provide an argument to the interrupt
5697attribute which specifies a name or number. If the argument is a
5698number it indicates the slot in the interrupt vector table (0 - 31) to
5699which this handler should be assigned. If the argument is a name it
5700is treated as a symbolic name for the vector slot. These names should
5701match up with appropriate entries in the linker script. By default
5702the names @code{watchdog} for vector 26, @code{nmi} for vector 30 and
5703@code{reset} for vector 31 are recognized.
5704
d77de738 5705@cindex @code{naked} function attribute, MSP430
f33d7a88 5706@item naked
d77de738
ML
5707This attribute allows the compiler to construct the
5708requisite function declaration, while allowing the body of the
5709function to be assembly code. The specified function will not have
5710prologue/epilogue sequences generated by the compiler. Only basic
5711@code{asm} statements can safely be included in naked functions
5712(@pxref{Basic Asm}). While using extended @code{asm} or a mixture of
5713basic @code{asm} and C code may appear to work, they cannot be
5714depended upon to work reliably and are not supported.
5715
d77de738 5716@cindex @code{reentrant} function attribute, MSP430
f33d7a88 5717@item reentrant
d77de738
ML
5718Reentrant functions disable interrupts upon entry and enable them
5719upon exit. Reentrant functions cannot also have the @code{naked}
5720or @code{critical} attributes. They can have the @code{interrupt}
5721attribute.
5722
d77de738 5723@cindex @code{wakeup} function attribute, MSP430
f33d7a88 5724@item wakeup
d77de738
ML
5725This attribute only applies to interrupt functions. It is silently
5726ignored if applied to a non-interrupt function. A wakeup interrupt
5727function will rouse the processor from any low-power state that it
5728might be in when the function exits.
5729
d77de738
ML
5730@cindex @code{lower} function attribute, MSP430
5731@cindex @code{upper} function attribute, MSP430
5732@cindex @code{either} function attribute, MSP430
f33d7a88
AA
5733@item lower
5734@itemx upper
5735@itemx either
d77de738
ML
5736On the MSP430 target these attributes can be used to specify whether
5737the function or variable should be placed into low memory, high
5738memory, or the placement should be left to the linker to decide. The
5739attributes are only significant if compiling for the MSP430X
5740architecture in the large memory model.
5741
5742The attributes work in conjunction with a linker script that has been
5743augmented to specify where to place sections with a @code{.lower} and
5744a @code{.upper} prefix. So, for example, as well as placing the
5745@code{.data} section, the script also specifies the placement of a
5746@code{.lower.data} and a @code{.upper.data} section. The intention
5747is that @code{lower} sections are placed into a small but easier to
5748access memory region and the upper sections are placed into a larger, but
5749slower to access, region.
5750
5751The @code{either} attribute is special. It tells the linker to place
5752the object into the corresponding @code{lower} section if there is
5753room for it. If there is insufficient room then the object is placed
5754into the corresponding @code{upper} section instead. Note that the
5755placement algorithm is not very sophisticated. It does not attempt to
5756find an optimal packing of the @code{lower} sections. It just makes
5757one pass over the objects and does the best that it can. Using the
5758@option{-ffunction-sections} and @option{-fdata-sections} command-line
5759options can help the packing, however, since they produce smaller,
5760easier to pack regions.
5761@end table
5762
5763@node NDS32 Function Attributes
5764@subsection NDS32 Function Attributes
5765
5766These function attributes are supported by the NDS32 back end:
5767
5768@table @code
d77de738
ML
5769@cindex @code{exception} function attribute
5770@cindex exception handler functions, NDS32
f33d7a88 5771@item exception
d77de738
ML
5772Use this attribute on the NDS32 target to indicate that the specified function
5773is an exception handler. The compiler will generate corresponding sections
5774for use in an exception handler.
5775
d77de738 5776@cindex @code{interrupt} function attribute, NDS32
f33d7a88 5777@item interrupt
d77de738
ML
5778On NDS32 target, this attribute indicates that the specified function
5779is an interrupt handler. The compiler generates corresponding sections
5780for use in an interrupt handler. You can use the following attributes
5781to modify the behavior:
5782@table @code
d77de738 5783@cindex @code{nested} function attribute, NDS32
f33d7a88 5784@item nested
d77de738 5785This interrupt service routine is interruptible.
d77de738 5786@cindex @code{not_nested} function attribute, NDS32
f33d7a88 5787@item not_nested
d77de738 5788This interrupt service routine is not interruptible.
d77de738 5789@cindex @code{nested_ready} function attribute, NDS32
f33d7a88 5790@item nested_ready
d77de738
ML
5791This interrupt service routine is interruptible after @code{PSW.GIE}
5792(global interrupt enable) is set. This allows interrupt service routine to
5793finish some short critical code before enabling interrupts.
d77de738 5794@cindex @code{save_all} function attribute, NDS32
f33d7a88 5795@item save_all
d77de738
ML
5796The system will help save all registers into stack before entering
5797interrupt handler.
d77de738 5798@cindex @code{partial_save} function attribute, NDS32
f33d7a88 5799@item partial_save
d77de738
ML
5800The system will help save caller registers into stack before entering
5801interrupt handler.
5802@end table
5803
d77de738 5804@cindex @code{naked} function attribute, NDS32
f33d7a88 5805@item naked
d77de738
ML
5806This attribute allows the compiler to construct the
5807requisite function declaration, while allowing the body of the
5808function to be assembly code. The specified function will not have
5809prologue/epilogue sequences generated by the compiler. Only basic
5810@code{asm} statements can safely be included in naked functions
5811(@pxref{Basic Asm}). While using extended @code{asm} or a mixture of
5812basic @code{asm} and C code may appear to work, they cannot be
5813depended upon to work reliably and are not supported.
5814
d77de738
ML
5815@cindex @code{reset} function attribute, NDS32
5816@cindex reset handler functions
f33d7a88 5817@item reset
d77de738
ML
5818Use this attribute on the NDS32 target to indicate that the specified function
5819is a reset handler. The compiler will generate corresponding sections
5820for use in a reset handler. You can use the following attributes
5821to provide extra exception handling:
5822@table @code
d77de738 5823@cindex @code{nmi} function attribute, NDS32
f33d7a88 5824@item nmi
d77de738 5825Provide a user-defined function to handle NMI exception.
d77de738 5826@cindex @code{warm} function attribute, NDS32
f33d7a88 5827@item warm
d77de738
ML
5828Provide a user-defined function to handle warm reset exception.
5829@end table
5830@end table
5831
5832@node Nios II Function Attributes
5833@subsection Nios II Function Attributes
5834
5835These function attributes are supported by the Nios II back end:
5836
5837@table @code
d77de738 5838@cindex @code{target} function attribute
f33d7a88 5839@item target (@var{options})
d77de738
ML
5840As discussed in @ref{Common Function Attributes}, this attribute
5841allows specification of target-specific compilation options.
5842
5843When compiling for Nios II, the following options are allowed:
5844
5845@table @samp
d77de738
ML
5846@cindex @code{target("custom-@var{insn}=@var{N}")} function attribute, Nios II
5847@cindex @code{target("no-custom-@var{insn}")} function attribute, Nios II
f33d7a88
AA
5848@item custom-@var{insn}=@var{N}
5849@itemx no-custom-@var{insn}
d77de738
ML
5850Each @samp{custom-@var{insn}=@var{N}} attribute locally enables use of a
5851custom instruction with encoding @var{N} when generating code that uses
5852@var{insn}. Similarly, @samp{no-custom-@var{insn}} locally inhibits use of
5853the custom instruction @var{insn}.
5854These target attributes correspond to the
5855@option{-mcustom-@var{insn}=@var{N}} and @option{-mno-custom-@var{insn}}
5856command-line options, and support the same set of @var{insn} keywords.
5857@xref{Nios II Options}, for more information.
5858
d77de738 5859@cindex @code{target("custom-fpu-cfg=@var{name}")} function attribute, Nios II
f33d7a88 5860@item custom-fpu-cfg=@var{name}
d77de738
ML
5861This attribute corresponds to the @option{-mcustom-fpu-cfg=@var{name}}
5862command-line option, to select a predefined set of custom instructions
5863named @var{name}.
5864@xref{Nios II Options}, for more information.
5865@end table
5866@end table
5867
5868@node Nvidia PTX Function Attributes
5869@subsection Nvidia PTX Function Attributes
5870
5871These function attributes are supported by the Nvidia PTX back end:
5872
5873@table @code
d77de738 5874@cindex @code{kernel} attribute, Nvidia PTX
f33d7a88 5875@item kernel
d77de738
ML
5876This attribute indicates that the corresponding function should be compiled
5877as a kernel function, which can be invoked from the host via the CUDA RT
5878library.
5879By default functions are only callable only from other PTX functions.
5880
5881Kernel functions must have @code{void} return type.
5882@end table
5883
5884@node PowerPC Function Attributes
5885@subsection PowerPC Function Attributes
5886
5887These function attributes are supported by the PowerPC back end:
5888
5889@table @code
d77de738
ML
5890@cindex indirect calls, PowerPC
5891@cindex @code{longcall} function attribute, PowerPC
5892@cindex @code{shortcall} function attribute, PowerPC
f33d7a88
AA
5893@item longcall
5894@itemx shortcall
d77de738
ML
5895The @code{longcall} attribute
5896indicates that the function might be far away from the call site and
5897require a different (more expensive) calling sequence. The
5898@code{shortcall} attribute indicates that the function is always close
5899enough for the shorter calling sequence to be used. These attributes
5900override both the @option{-mlongcall} switch and
5901the @code{#pragma longcall} setting.
5902
5903@xref{RS/6000 and PowerPC Options}, for more information on whether long
5904calls are necessary.
5905
d77de738 5906@cindex @code{target} function attribute
f33d7a88 5907@item target (@var{options})
d77de738
ML
5908As discussed in @ref{Common Function Attributes}, this attribute
5909allows specification of target-specific compilation options.
5910
5911On the PowerPC, the following options are allowed:
5912
5913@table @samp
f33d7a88 5914@cindex @code{target("altivec")} function attribute, PowerPC
d77de738
ML
5915@item altivec
5916@itemx no-altivec
d77de738
ML
5917Generate code that uses (does not use) AltiVec instructions. In
591832-bit code, you cannot enable AltiVec instructions unless
5919@option{-mabi=altivec} is used on the command line.
5920
f33d7a88 5921@cindex @code{target("cmpb")} function attribute, PowerPC
d77de738
ML
5922@item cmpb
5923@itemx no-cmpb
d77de738
ML
5924Generate code that uses (does not use) the compare bytes instruction
5925implemented on the POWER6 processor and other processors that support
5926the PowerPC V2.05 architecture.
5927
f33d7a88 5928@cindex @code{target("dlmzb")} function attribute, PowerPC
d77de738
ML
5929@item dlmzb
5930@itemx no-dlmzb
d77de738
ML
5931Generate code that uses (does not use) the string-search @samp{dlmzb}
5932instruction on the IBM 405, 440, 464 and 476 processors. This instruction is
5933generated by default when targeting those processors.
5934
f33d7a88 5935@cindex @code{target("fprnd")} function attribute, PowerPC
d77de738
ML
5936@item fprnd
5937@itemx no-fprnd
d77de738
ML
5938Generate code that uses (does not use) the FP round to integer
5939instructions implemented on the POWER5+ processor and other processors
5940that support the PowerPC V2.03 architecture.
5941
f33d7a88 5942@cindex @code{target("hard-dfp")} function attribute, PowerPC
d77de738
ML
5943@item hard-dfp
5944@itemx no-hard-dfp
d77de738
ML
5945Generate code that uses (does not use) the decimal floating-point
5946instructions implemented on some POWER processors.
5947
f33d7a88 5948@cindex @code{target("isel")} function attribute, PowerPC
d77de738
ML
5949@item isel
5950@itemx no-isel
d77de738
ML
5951Generate code that uses (does not use) ISEL instruction.
5952
f33d7a88 5953@cindex @code{target("mfcrf")} function attribute, PowerPC
d77de738
ML
5954@item mfcrf
5955@itemx no-mfcrf
d77de738
ML
5956Generate code that uses (does not use) the move from condition
5957register field instruction implemented on the POWER4 processor and
5958other processors that support the PowerPC V2.01 architecture.
5959
f33d7a88 5960@cindex @code{target("mulhw")} function attribute, PowerPC
d77de738
ML
5961@item mulhw
5962@itemx no-mulhw
d77de738
ML
5963Generate code that uses (does not use) the half-word multiply and
5964multiply-accumulate instructions on the IBM 405, 440, 464 and 476 processors.
5965These instructions are generated by default when targeting those
5966processors.
5967
f33d7a88 5968@cindex @code{target("multiple")} function attribute, PowerPC
d77de738
ML
5969@item multiple
5970@itemx no-multiple
d77de738
ML
5971Generate code that uses (does not use) the load multiple word
5972instructions and the store multiple word instructions.
5973
f33d7a88 5974@cindex @code{target("update")} function attribute, PowerPC
d77de738
ML
5975@item update
5976@itemx no-update
d77de738
ML
5977Generate code that uses (does not use) the load or store instructions
5978that update the base register to the address of the calculated memory
5979location.
5980
f33d7a88 5981@cindex @code{target("popcntb")} function attribute, PowerPC
d77de738
ML
5982@item popcntb
5983@itemx no-popcntb
d77de738
ML
5984Generate code that uses (does not use) the popcount and double-precision
5985FP reciprocal estimate instruction implemented on the POWER5
5986processor and other processors that support the PowerPC V2.02
5987architecture.
5988
f33d7a88 5989@cindex @code{target("popcntd")} function attribute, PowerPC
d77de738
ML
5990@item popcntd
5991@itemx no-popcntd
d77de738
ML
5992Generate code that uses (does not use) the popcount instruction
5993implemented on the POWER7 processor and other processors that support
5994the PowerPC V2.06 architecture.
5995
f33d7a88 5996@cindex @code{target("powerpc-gfxopt")} function attribute, PowerPC
d77de738
ML
5997@item powerpc-gfxopt
5998@itemx no-powerpc-gfxopt
d77de738
ML
5999Generate code that uses (does not use) the optional PowerPC
6000architecture instructions in the Graphics group, including
6001floating-point select.
6002
f33d7a88 6003@cindex @code{target("powerpc-gpopt")} function attribute, PowerPC
d77de738
ML
6004@item powerpc-gpopt
6005@itemx no-powerpc-gpopt
d77de738
ML
6006Generate code that uses (does not use) the optional PowerPC
6007architecture instructions in the General Purpose group, including
6008floating-point square root.
6009
f33d7a88 6010@cindex @code{target("recip-precision")} function attribute, PowerPC
d77de738
ML
6011@item recip-precision
6012@itemx no-recip-precision
d77de738
ML
6013Assume (do not assume) that the reciprocal estimate instructions
6014provide higher-precision estimates than is mandated by the PowerPC
6015ABI.
6016
f33d7a88 6017@cindex @code{target("string")} function attribute, PowerPC
d77de738
ML
6018@item string
6019@itemx no-string
d77de738
ML
6020Generate code that uses (does not use) the load string instructions
6021and the store string word instructions to save multiple registers and
6022do small block moves.
6023
f33d7a88 6024@cindex @code{target("vsx")} function attribute, PowerPC
d77de738
ML
6025@item vsx
6026@itemx no-vsx
d77de738
ML
6027Generate code that uses (does not use) vector/scalar (VSX)
6028instructions, and also enable the use of built-in functions that allow
6029more direct access to the VSX instruction set. In 32-bit code, you
6030cannot enable VSX or AltiVec instructions unless
6031@option{-mabi=altivec} is used on the command line.
6032
f33d7a88 6033@cindex @code{target("friz")} function attribute, PowerPC
d77de738
ML
6034@item friz
6035@itemx no-friz
d77de738
ML
6036Generate (do not generate) the @code{friz} instruction when the
6037@option{-funsafe-math-optimizations} option is used to optimize
6038rounding a floating-point value to 64-bit integer and back to floating
6039point. The @code{friz} instruction does not return the same value if
6040the floating-point number is too large to fit in an integer.
6041
f33d7a88 6042@cindex @code{target("avoid-indexed-addresses")} function attribute, PowerPC
d77de738
ML
6043@item avoid-indexed-addresses
6044@itemx no-avoid-indexed-addresses
d77de738
ML
6045Generate code that tries to avoid (not avoid) the use of indexed load
6046or store instructions.
6047
f33d7a88 6048@cindex @code{target("paired")} function attribute, PowerPC
d77de738
ML
6049@item paired
6050@itemx no-paired
d77de738
ML
6051Generate code that uses (does not use) the generation of PAIRED simd
6052instructions.
6053
f33d7a88 6054@cindex @code{target("longcall")} function attribute, PowerPC
d77de738
ML
6055@item longcall
6056@itemx no-longcall
d77de738
ML
6057Generate code that assumes (does not assume) that all calls are far
6058away so that a longer more expensive calling sequence is required.
6059
d77de738 6060@cindex @code{target("cpu=@var{CPU}")} function attribute, PowerPC
f33d7a88 6061@item cpu=@var{CPU}
d77de738
ML
6062Specify the architecture to generate code for when compiling the
6063function. If you select the @code{target("cpu=power7")} attribute when
6064generating 32-bit code, VSX and AltiVec instructions are not generated
6065unless you use the @option{-mabi=altivec} option on the command line.
6066
d77de738 6067@cindex @code{target("tune=@var{TUNE}")} function attribute, PowerPC
f33d7a88 6068@item tune=@var{TUNE}
d77de738
ML
6069Specify the architecture to tune for when compiling the function. If
6070you do not specify the @code{target("tune=@var{TUNE}")} attribute and
6071you do specify the @code{target("cpu=@var{CPU}")} attribute,
6072compilation tunes for the @var{CPU} architecture, and not the
6073default tuning specified on the command line.
6074@end table
6075
6076On the PowerPC, the inliner does not inline a
6077function that has different target options than the caller, unless the
6078callee has a subset of the target options of the caller.
6079@end table
6080
6081@node RISC-V Function Attributes
6082@subsection RISC-V Function Attributes
6083
6084These function attributes are supported by the RISC-V back end:
6085
6086@table @code
d77de738 6087@cindex @code{naked} function attribute, RISC-V
f33d7a88 6088@item naked
d77de738
ML
6089This attribute allows the compiler to construct the
6090requisite function declaration, while allowing the body of the
6091function to be assembly code. The specified function will not have
6092prologue/epilogue sequences generated by the compiler. Only basic
6093@code{asm} statements can safely be included in naked functions
6094(@pxref{Basic Asm}). While using extended @code{asm} or a mixture of
6095basic @code{asm} and C code may appear to work, they cannot be
6096depended upon to work reliably and are not supported.
6097
d77de738 6098@cindex @code{interrupt} function attribute, RISC-V
f33d7a88 6099@item interrupt
d77de738
ML
6100Use this attribute to indicate that the specified function is an interrupt
6101handler. The compiler generates function entry and exit sequences suitable
6102for use in an interrupt handler when this attribute is present.
6103
6104You can specify the kind of interrupt to be handled by adding an optional
6105parameter to the interrupt attribute like this:
6106
6107@smallexample
6108void f (void) __attribute__ ((interrupt ("user")));
6109@end smallexample
6110
6111Permissible values for this parameter are @code{user}, @code{supervisor},
6112and @code{machine}. If there is no parameter, then it defaults to
6113@code{machine}.
6114@end table
6115
6116@node RL78 Function Attributes
6117@subsection RL78 Function Attributes
6118
6119These function attributes are supported by the RL78 back end:
6120
6121@table @code
d77de738
ML
6122@cindex @code{interrupt} function attribute, RL78
6123@cindex @code{brk_interrupt} function attribute, RL78
f33d7a88
AA
6124@item interrupt
6125@itemx brk_interrupt
d77de738
ML
6126These attributes indicate
6127that the specified function is an interrupt handler. The compiler generates
6128function entry and exit sequences suitable for use in an interrupt handler
6129when this attribute is present.
6130
6131Use @code{brk_interrupt} instead of @code{interrupt} for
6132handlers intended to be used with the @code{BRK} opcode (i.e.@: those
6133that must end with @code{RETB} instead of @code{RETI}).
6134
d77de738 6135@cindex @code{naked} function attribute, RL78
f33d7a88 6136@item naked
d77de738
ML
6137This attribute allows the compiler to construct the
6138requisite function declaration, while allowing the body of the
6139function to be assembly code. The specified function will not have
6140prologue/epilogue sequences generated by the compiler. Only basic
6141@code{asm} statements can safely be included in naked functions
6142(@pxref{Basic Asm}). While using extended @code{asm} or a mixture of
6143basic @code{asm} and C code may appear to work, they cannot be
6144depended upon to work reliably and are not supported.
6145@end table
6146
6147@node RX Function Attributes
6148@subsection RX Function Attributes
6149
6150These function attributes are supported by the RX back end:
6151
6152@table @code
d77de738 6153@cindex @code{fast_interrupt} function attribute, RX
f33d7a88 6154@item fast_interrupt
d77de738
ML
6155Use this attribute on the RX port to indicate that the specified
6156function is a fast interrupt handler. This is just like the
6157@code{interrupt} attribute, except that @code{freit} is used to return
6158instead of @code{reit}.
6159
d77de738 6160@cindex @code{interrupt} function attribute, RX
f33d7a88 6161@item interrupt
d77de738
ML
6162Use this attribute to indicate
6163that the specified function is an interrupt handler. The compiler generates
6164function entry and exit sequences suitable for use in an interrupt handler
6165when this attribute is present.
6166
6167On RX and RL78 targets, you may specify one or more vector numbers as arguments
6168to the attribute, as well as naming an alternate table name.
6169Parameters are handled sequentially, so one handler can be assigned to
6170multiple entries in multiple tables. One may also pass the magic
6171string @code{"$default"} which causes the function to be used for any
6172unfilled slots in the current table.
6173
6174This example shows a simple assignment of a function to one vector in
6175the default table (note that preprocessor macros may be used for
6176chip-specific symbolic vector names):
6177@smallexample
6178void __attribute__ ((interrupt (5))) txd1_handler ();
6179@end smallexample
6180
6181This example assigns a function to two slots in the default table
6182(using preprocessor macros defined elsewhere) and makes it the default
6183for the @code{dct} table:
6184@smallexample
6185void __attribute__ ((interrupt (RXD1_VECT,RXD2_VECT,"dct","$default")))
6186 txd1_handler ();
6187@end smallexample
6188
d77de738 6189@cindex @code{naked} function attribute, RX
f33d7a88 6190@item naked
d77de738
ML
6191This attribute allows the compiler to construct the
6192requisite function declaration, while allowing the body of the
6193function to be assembly code. The specified function will not have
6194prologue/epilogue sequences generated by the compiler. Only basic
6195@code{asm} statements can safely be included in naked functions
6196(@pxref{Basic Asm}). While using extended @code{asm} or a mixture of
6197basic @code{asm} and C code may appear to work, they cannot be
6198depended upon to work reliably and are not supported.
6199
d77de738 6200@cindex @code{vector} function attribute, RX
f33d7a88 6201@item vector
d77de738
ML
6202This RX attribute is similar to the @code{interrupt} attribute, including its
6203parameters, but does not make the function an interrupt-handler type
6204function (i.e.@: it retains the normal C function calling ABI). See the
6205@code{interrupt} attribute for a description of its arguments.
6206@end table
6207
6208@node S/390 Function Attributes
6209@subsection S/390 Function Attributes
6210
6211These function attributes are supported on the S/390:
6212
6213@table @code
d77de738 6214@cindex @code{hotpatch} function attribute, S/390
f33d7a88 6215@item hotpatch (@var{halfwords-before-function-label},@var{halfwords-after-function-label})
d77de738
ML
6216
6217On S/390 System z targets, you can use this function attribute to
6218make GCC generate a ``hot-patching'' function prologue. If the
6219@option{-mhotpatch=} command-line option is used at the same time,
6220the @code{hotpatch} attribute takes precedence. The first of the
6221two arguments specifies the number of halfwords to be added before
6222the function label. A second argument can be used to specify the
6223number of halfwords to be added after the function label. For
6224both arguments the maximum allowed value is 1000000.
6225
6226If both arguments are zero, hotpatching is disabled.
6227
d77de738 6228@cindex @code{target} function attribute
f33d7a88 6229@item target (@var{options})
d77de738
ML
6230As discussed in @ref{Common Function Attributes}, this attribute
6231allows specification of target-specific compilation options.
6232
6233On S/390, the following options are supported:
6234
6235@table @samp
6236@item arch=
6237@item tune=
6238@item stack-guard=
6239@item stack-size=
6240@item branch-cost=
6241@item warn-framesize=
6242@item backchain
6243@itemx no-backchain
6244@item hard-dfp
6245@itemx no-hard-dfp
6246@item hard-float
6247@itemx soft-float
6248@item htm
6249@itemx no-htm
6250@item vx
6251@itemx no-vx
6252@item packed-stack
6253@itemx no-packed-stack
6254@item small-exec
6255@itemx no-small-exec
6256@item mvcle
6257@itemx no-mvcle
6258@item warn-dynamicstack
6259@itemx no-warn-dynamicstack
6260@end table
6261
6262The options work exactly like the S/390 specific command line
6263options (without the prefix @option{-m}) except that they do not
6264change any feature macros. For example,
6265
6266@smallexample
6267@code{target("no-vx")}
6268@end smallexample
6269
6270does not undefine the @code{__VEC__} macro.
6271@end table
6272
6273@node SH Function Attributes
6274@subsection SH Function Attributes
6275
6276These function attributes are supported on the SH family of processors:
6277
6278@table @code
d77de738
ML
6279@cindex @code{function_vector} function attribute, SH
6280@cindex calling functions through the function vector on SH2A
f33d7a88 6281@item function_vector
d77de738
ML
6282On SH2A targets, this attribute declares a function to be called using the
6283TBR relative addressing mode. The argument to this attribute is the entry
6284number of the same function in a vector table containing all the TBR
6285relative addressable functions. For correct operation the TBR must be setup
6286accordingly to point to the start of the vector table before any functions with
6287this attribute are invoked. Usually a good place to do the initialization is
6288the startup routine. The TBR relative vector table can have at max 256 function
6289entries. The jumps to these functions are generated using a SH2A specific,
6290non delayed branch instruction JSR/N @@(disp8,TBR). You must use GAS and GLD
6291from GNU binutils version 2.7 or later for this attribute to work correctly.
6292
6293In an application, for a function being called once, this attribute
6294saves at least 8 bytes of code; and if other successive calls are being
6295made to the same function, it saves 2 bytes of code per each of these
6296calls.
6297
d77de738 6298@cindex @code{interrupt_handler} function attribute, SH
f33d7a88 6299@item interrupt_handler
d77de738
ML
6300Use this attribute to
6301indicate that the specified function is an interrupt handler. The compiler
6302generates function entry and exit sequences suitable for use in an
6303interrupt handler when this attribute is present.
6304
d77de738 6305@cindex @code{nosave_low_regs} function attribute, SH
f33d7a88 6306@item nosave_low_regs
d77de738
ML
6307Use this attribute on SH targets to indicate that an @code{interrupt_handler}
6308function should not save and restore registers R0..R7. This can be used on SH3*
6309and SH4* targets that have a second R0..R7 register bank for non-reentrant
6310interrupt handlers.
6311
d77de738 6312@cindex @code{renesas} function attribute, SH
f33d7a88 6313@item renesas
d77de738
ML
6314On SH targets this attribute specifies that the function or struct follows the
6315Renesas ABI.
6316
d77de738 6317@cindex @code{resbank} function attribute, SH
f33d7a88 6318@item resbank
d77de738
ML
6319On the SH2A target, this attribute enables the high-speed register
6320saving and restoration using a register bank for @code{interrupt_handler}
6321routines. Saving to the bank is performed automatically after the CPU
6322accepts an interrupt that uses a register bank.
6323
6324The nineteen 32-bit registers comprising general register R0 to R14,
6325control register GBR, and system registers MACH, MACL, and PR and the
6326vector table address offset are saved into a register bank. Register
6327banks are stacked in first-in last-out (FILO) sequence. Restoration
6328from the bank is executed by issuing a RESBANK instruction.
6329
d77de738 6330@cindex @code{sp_switch} function attribute, SH
f33d7a88 6331@item sp_switch
d77de738
ML
6332Use this attribute on the SH to indicate an @code{interrupt_handler}
6333function should switch to an alternate stack. It expects a string
6334argument that names a global variable holding the address of the
6335alternate stack.
6336
6337@smallexample
6338void *alt_stack;
6339void f () __attribute__ ((interrupt_handler,
6340 sp_switch ("alt_stack")));
6341@end smallexample
6342
d77de738 6343@cindex @code{trap_exit} function attribute, SH
f33d7a88 6344@item trap_exit
d77de738
ML
6345Use this attribute on the SH for an @code{interrupt_handler} to return using
6346@code{trapa} instead of @code{rte}. This attribute expects an integer
6347argument specifying the trap number to be used.
6348
d77de738 6349@cindex @code{trapa_handler} function attribute, SH
f33d7a88 6350@item trapa_handler
d77de738
ML
6351On SH targets this function attribute is similar to @code{interrupt_handler}
6352but it does not save and restore all registers.
6353@end table
6354
6355@node Symbian OS Function Attributes
6356@subsection Symbian OS Function Attributes
6357
6358@xref{Microsoft Windows Function Attributes}, for discussion of the
6359@code{dllexport} and @code{dllimport} attributes.
6360
6361@node V850 Function Attributes
6362@subsection V850 Function Attributes
6363
6364The V850 back end supports these function attributes:
6365
6366@table @code
d77de738
ML
6367@cindex @code{interrupt} function attribute, V850
6368@cindex @code{interrupt_handler} function attribute, V850
f33d7a88
AA
6369@item interrupt
6370@itemx interrupt_handler
d77de738
ML
6371Use these attributes to indicate
6372that the specified function is an interrupt handler. The compiler generates
6373function entry and exit sequences suitable for use in an interrupt handler
6374when either attribute is present.
6375@end table
6376
6377@node Visium Function Attributes
6378@subsection Visium Function Attributes
6379
6380These function attributes are supported by the Visium back end:
6381
6382@table @code
d77de738 6383@cindex @code{interrupt} function attribute, Visium
f33d7a88 6384@item interrupt
d77de738
ML
6385Use this attribute to indicate
6386that the specified function is an interrupt handler. The compiler generates
6387function entry and exit sequences suitable for use in an interrupt handler
6388when this attribute is present.
6389@end table
6390
6391@node x86 Function Attributes
6392@subsection x86 Function Attributes
6393
6394These function attributes are supported by the x86 back end:
6395
6396@table @code
d77de738
ML
6397@cindex @code{cdecl} function attribute, x86-32
6398@cindex functions that pop the argument stack on x86-32
6399@opindex mrtd
f33d7a88 6400@item cdecl
d77de738
ML
6401On the x86-32 targets, the @code{cdecl} attribute causes the compiler to
6402assume that the calling function pops off the stack space used to
6403pass arguments. This is
6404useful to override the effects of the @option{-mrtd} switch.
6405
d77de738
ML
6406@cindex @code{fastcall} function attribute, x86-32
6407@cindex functions that pop the argument stack on x86-32
f33d7a88 6408@item fastcall
d77de738
ML
6409On x86-32 targets, the @code{fastcall} attribute causes the compiler to
6410pass the first argument (if of integral type) in the register ECX and
6411the second argument (if of integral type) in the register EDX@. Subsequent
6412and other typed arguments are passed on the stack. The called function
6413pops the arguments off the stack. If the number of arguments is variable all
6414arguments are pushed on the stack.
6415
d77de738
ML
6416@cindex @code{thiscall} function attribute, x86-32
6417@cindex functions that pop the argument stack on x86-32
f33d7a88 6418@item thiscall
d77de738
ML
6419On x86-32 targets, the @code{thiscall} attribute causes the compiler to
6420pass the first argument (if of integral type) in the register ECX.
6421Subsequent and other typed arguments are passed on the stack. The called
6422function pops the arguments off the stack.
6423If the number of arguments is variable all arguments are pushed on the
6424stack.
6425The @code{thiscall} attribute is intended for C++ non-static member functions.
6426As a GCC extension, this calling convention can be used for C functions
6427and for static member methods.
6428
d77de738
ML
6429@cindex @code{ms_abi} function attribute, x86
6430@cindex @code{sysv_abi} function attribute, x86
f33d7a88
AA
6431@item ms_abi
6432@itemx sysv_abi
d77de738
ML
6433
6434On 32-bit and 64-bit x86 targets, you can use an ABI attribute
6435to indicate which calling convention should be used for a function. The
6436@code{ms_abi} attribute tells the compiler to use the Microsoft ABI,
6437while the @code{sysv_abi} attribute tells the compiler to use the System V
6438ELF ABI, which is used on GNU/Linux and other systems. The default is to use
6439the Microsoft ABI when targeting Windows. On all other systems, the default
6440is the System V ELF ABI.
6441
6442Note, the @code{ms_abi} attribute for Microsoft Windows 64-bit targets currently
6443requires the @option{-maccumulate-outgoing-args} option.
6444
d77de738 6445@cindex @code{callee_pop_aggregate_return} function attribute, x86
f33d7a88 6446@item callee_pop_aggregate_return (@var{number})
d77de738
ML
6447
6448On x86-32 targets, you can use this attribute to control how
6449aggregates are returned in memory. If the caller is responsible for
6450popping the hidden pointer together with the rest of the arguments, specify
6451@var{number} equal to zero. If callee is responsible for popping the
6452hidden pointer, specify @var{number} equal to one.
6453
6454The default x86-32 ABI assumes that the callee pops the
6455stack for hidden pointer. However, on x86-32 Microsoft Windows targets,
6456the compiler assumes that the
6457caller pops the stack for hidden pointer.
6458
d77de738 6459@cindex @code{ms_hook_prologue} function attribute, x86
f33d7a88 6460@item ms_hook_prologue
d77de738
ML
6461
6462On 32-bit and 64-bit x86 targets, you can use
6463this function attribute to make GCC generate the ``hot-patching'' function
6464prologue used in Win32 API functions in Microsoft Windows XP Service Pack 2
6465and newer.
6466
d77de738 6467@cindex @code{naked} function attribute, x86
f33d7a88 6468@item naked
d77de738
ML
6469This attribute allows the compiler to construct the
6470requisite function declaration, while allowing the body of the
6471function to be assembly code. The specified function will not have
6472prologue/epilogue sequences generated by the compiler. Only basic
6473@code{asm} statements can safely be included in naked functions
6474(@pxref{Basic Asm}). While using extended @code{asm} or a mixture of
6475basic @code{asm} and C code may appear to work, they cannot be
6476depended upon to work reliably and are not supported.
6477
d77de738
ML
6478@cindex @code{regparm} function attribute, x86
6479@cindex functions that are passed arguments in registers on x86-32
f33d7a88 6480@item regparm (@var{number})
d77de738
ML
6481On x86-32 targets, the @code{regparm} attribute causes the compiler to
6482pass arguments number one to @var{number} if they are of integral type
6483in registers EAX, EDX, and ECX instead of on the stack. Functions that
6484take a variable number of arguments continue to be passed all of their
6485arguments on the stack.
6486
6487Beware that on some ELF systems this attribute is unsuitable for
6488global functions in shared libraries with lazy binding (which is the
6489default). Lazy binding sends the first call via resolving code in
6490the loader, which might assume EAX, EDX and ECX can be clobbered, as
6491per the standard calling conventions. Solaris 8 is affected by this.
6492Systems with the GNU C Library version 2.1 or higher
6493and FreeBSD are believed to be
6494safe since the loaders there save EAX, EDX and ECX. (Lazy binding can be
6495disabled with the linker or the loader if desired, to avoid the
6496problem.)
6497
d77de738 6498@cindex @code{sseregparm} function attribute, x86
f33d7a88 6499@item sseregparm
d77de738
ML
6500On x86-32 targets with SSE support, the @code{sseregparm} attribute
6501causes the compiler to pass up to 3 floating-point arguments in
6502SSE registers instead of on the stack. Functions that take a
6503variable number of arguments continue to pass all of their
6504floating-point arguments on the stack.
6505
d77de738 6506@cindex @code{force_align_arg_pointer} function attribute, x86
f33d7a88 6507@item force_align_arg_pointer
d77de738
ML
6508On x86 targets, the @code{force_align_arg_pointer} attribute may be
6509applied to individual function definitions, generating an alternate
6510prologue and epilogue that realigns the run-time stack if necessary.
6511This supports mixing legacy codes that run with a 4-byte aligned stack
6512with modern codes that keep a 16-byte stack for SSE compatibility.
6513
d77de738
ML
6514@cindex @code{stdcall} function attribute, x86-32
6515@cindex functions that pop the argument stack on x86-32
f33d7a88 6516@item stdcall
d77de738
ML
6517On x86-32 targets, the @code{stdcall} attribute causes the compiler to
6518assume that the called function pops off the stack space used to
6519pass arguments, unless it takes a variable number of arguments.
6520
d77de738 6521@cindex @code{no_caller_saved_registers} function attribute, x86
f33d7a88 6522@item no_caller_saved_registers
d77de738
ML
6523Use this attribute to indicate that the specified function has no
6524caller-saved registers. That is, all registers are callee-saved. For
6525example, this attribute can be used for a function called from an
6526interrupt handler. The compiler generates proper function entry and
6527exit sequences to save and restore any modified registers, except for
6528the EFLAGS register. Since GCC doesn't preserve SSE, MMX nor x87
6529states, the GCC option @option{-mgeneral-regs-only} should be used to
6530compile functions with @code{no_caller_saved_registers} attribute.
6531
d77de738 6532@cindex @code{interrupt} function attribute, x86
f33d7a88 6533@item interrupt
d77de738
ML
6534Use this attribute to indicate that the specified function is an
6535interrupt handler or an exception handler (depending on parameters passed
6536to the function, explained further). The compiler generates function
6537entry and exit sequences suitable for use in an interrupt handler when
6538this attribute is present. The @code{IRET} instruction, instead of the
6539@code{RET} instruction, is used to return from interrupt handlers. All
6540registers, except for the EFLAGS register which is restored by the
6541@code{IRET} instruction, are preserved by the compiler. Since GCC
6542doesn't preserve SSE, MMX nor x87 states, the GCC option
6543@option{-mgeneral-regs-only} should be used to compile interrupt and
6544exception handlers.
6545
6546Any interruptible-without-stack-switch code must be compiled with
6547@option{-mno-red-zone} since interrupt handlers can and will, because
6548of the hardware design, touch the red zone.
6549
6550An interrupt handler must be declared with a mandatory pointer
6551argument:
6552
6553@smallexample
6554struct interrupt_frame;
6555
6556__attribute__ ((interrupt))
6557void
6558f (struct interrupt_frame *frame)
6559@{
6560@}
6561@end smallexample
6562
6563@noindent
6564and you must define @code{struct interrupt_frame} as described in the
6565processor's manual.
6566
6567Exception handlers differ from interrupt handlers because the system
6568pushes an error code on the stack. An exception handler declaration is
6569similar to that for an interrupt handler, but with a different mandatory
6570function signature. The compiler arranges to pop the error code off the
6571stack before the @code{IRET} instruction.
6572
6573@smallexample
6574#ifdef __x86_64__
6575typedef unsigned long long int uword_t;
6576#else
6577typedef unsigned int uword_t;
6578#endif
6579
6580struct interrupt_frame;
6581
6582__attribute__ ((interrupt))
6583void
6584f (struct interrupt_frame *frame, uword_t error_code)
6585@{
6586 ...
6587@}
6588@end smallexample
6589
6590Exception handlers should only be used for exceptions that push an error
6591code; you should use an interrupt handler in other cases. The system
6592will crash if the wrong kind of handler is used.
6593
d77de738 6594@cindex @code{target} function attribute
f33d7a88 6595@item target (@var{options})
d77de738
ML
6596As discussed in @ref{Common Function Attributes}, this attribute
6597allows specification of target-specific compilation options.
6598
6599On the x86, the following options are allowed:
6600@table @samp
f33d7a88 6601@cindex @code{target("3dnow")} function attribute, x86
d77de738
ML
6602@item 3dnow
6603@itemx no-3dnow
d77de738
ML
6604Enable/disable the generation of the 3DNow!@: instructions.
6605
f33d7a88 6606@cindex @code{target("3dnowa")} function attribute, x86
d77de738
ML
6607@item 3dnowa
6608@itemx no-3dnowa
d77de738
ML
6609Enable/disable the generation of the enhanced 3DNow!@: instructions.
6610
f33d7a88 6611@cindex @code{target("abm")} function attribute, x86
d77de738
ML
6612@item abm
6613@itemx no-abm
d77de738
ML
6614Enable/disable the generation of the advanced bit instructions.
6615
f33d7a88 6616@cindex @code{target("adx")} function attribute, x86
d77de738
ML
6617@item adx
6618@itemx no-adx
d77de738
ML
6619Enable/disable the generation of the ADX instructions.
6620
f33d7a88 6621@cindex @code{target("aes")} function attribute, x86
d77de738
ML
6622@item aes
6623@itemx no-aes
d77de738
ML
6624Enable/disable the generation of the AES instructions.
6625
f33d7a88 6626@cindex @code{target("avx")} function attribute, x86
d77de738
ML
6627@item avx
6628@itemx no-avx
d77de738
ML
6629Enable/disable the generation of the AVX instructions.
6630
f33d7a88 6631@cindex @code{target("avx2")} function attribute, x86
d77de738
ML
6632@item avx2
6633@itemx no-avx2
d77de738
ML
6634Enable/disable the generation of the AVX2 instructions.
6635
f33d7a88 6636@cindex @code{target("avx5124fmaps")} function attribute, x86
d77de738
ML
6637@item avx5124fmaps
6638@itemx no-avx5124fmaps
d77de738
ML
6639Enable/disable the generation of the AVX5124FMAPS instructions.
6640
f33d7a88 6641@cindex @code{target("avx5124vnniw")} function attribute, x86
d77de738
ML
6642@item avx5124vnniw
6643@itemx no-avx5124vnniw
d77de738
ML
6644Enable/disable the generation of the AVX5124VNNIW instructions.
6645
f33d7a88 6646@cindex @code{target("avx512bitalg")} function attribute, x86
d77de738
ML
6647@item avx512bitalg
6648@itemx no-avx512bitalg
d77de738
ML
6649Enable/disable the generation of the AVX512BITALG instructions.
6650
f33d7a88 6651@cindex @code{target("avx512bw")} function attribute, x86
d77de738
ML
6652@item avx512bw
6653@itemx no-avx512bw
d77de738
ML
6654Enable/disable the generation of the AVX512BW instructions.
6655
f33d7a88 6656@cindex @code{target("avx512cd")} function attribute, x86
d77de738
ML
6657@item avx512cd
6658@itemx no-avx512cd
d77de738
ML
6659Enable/disable the generation of the AVX512CD instructions.
6660
f33d7a88 6661@cindex @code{target("avx512dq")} function attribute, x86
d77de738
ML
6662@item avx512dq
6663@itemx no-avx512dq
d77de738
ML
6664Enable/disable the generation of the AVX512DQ instructions.
6665
f33d7a88 6666@cindex @code{target("avx512er")} function attribute, x86
d77de738
ML
6667@item avx512er
6668@itemx no-avx512er
d77de738
ML
6669Enable/disable the generation of the AVX512ER instructions.
6670
f33d7a88 6671@cindex @code{target("avx512f")} function attribute, x86
d77de738
ML
6672@item avx512f
6673@itemx no-avx512f
d77de738
ML
6674Enable/disable the generation of the AVX512F instructions.
6675
f33d7a88 6676@cindex @code{target("avx512ifma")} function attribute, x86
d77de738
ML
6677@item avx512ifma
6678@itemx no-avx512ifma
d77de738
ML
6679Enable/disable the generation of the AVX512IFMA instructions.
6680
f33d7a88 6681@cindex @code{target("avx512pf")} function attribute, x86
d77de738
ML
6682@item avx512pf
6683@itemx no-avx512pf
d77de738
ML
6684Enable/disable the generation of the AVX512PF instructions.
6685
f33d7a88 6686@cindex @code{target("avx512vbmi")} function attribute, x86
d77de738
ML
6687@item avx512vbmi
6688@itemx no-avx512vbmi
d77de738
ML
6689Enable/disable the generation of the AVX512VBMI instructions.
6690
f33d7a88 6691@cindex @code{target("avx512vbmi2")} function attribute, x86
d77de738
ML
6692@item avx512vbmi2
6693@itemx no-avx512vbmi2
d77de738
ML
6694Enable/disable the generation of the AVX512VBMI2 instructions.
6695
f33d7a88 6696@cindex @code{target("avx512vl")} function attribute, x86
d77de738
ML
6697@item avx512vl
6698@itemx no-avx512vl
d77de738
ML
6699Enable/disable the generation of the AVX512VL instructions.
6700
f33d7a88 6701@cindex @code{target("avx512vnni")} function attribute, x86
d77de738
ML
6702@item avx512vnni
6703@itemx no-avx512vnni
d77de738
ML
6704Enable/disable the generation of the AVX512VNNI instructions.
6705
f33d7a88 6706@cindex @code{target("avx512vpopcntdq")} function attribute, x86
d77de738
ML
6707@item avx512vpopcntdq
6708@itemx no-avx512vpopcntdq
d77de738
ML
6709Enable/disable the generation of the AVX512VPOPCNTDQ instructions.
6710
f33d7a88 6711@cindex @code{target("bmi")} function attribute, x86
d77de738
ML
6712@item bmi
6713@itemx no-bmi
d77de738
ML
6714Enable/disable the generation of the BMI instructions.
6715
f33d7a88 6716@cindex @code{target("bmi2")} function attribute, x86
d77de738
ML
6717@item bmi2
6718@itemx no-bmi2
d77de738
ML
6719Enable/disable the generation of the BMI2 instructions.
6720
f33d7a88 6721@cindex @code{target("cldemote")} function attribute, x86
d77de738
ML
6722@item cldemote
6723@itemx no-cldemote
d77de738
ML
6724Enable/disable the generation of the CLDEMOTE instructions.
6725
f33d7a88 6726@cindex @code{target("clflushopt")} function attribute, x86
d77de738
ML
6727@item clflushopt
6728@itemx no-clflushopt
d77de738
ML
6729Enable/disable the generation of the CLFLUSHOPT instructions.
6730
f33d7a88 6731@cindex @code{target("clwb")} function attribute, x86
d77de738
ML
6732@item clwb
6733@itemx no-clwb
d77de738
ML
6734Enable/disable the generation of the CLWB instructions.
6735
f33d7a88 6736@cindex @code{target("clzero")} function attribute, x86
d77de738
ML
6737@item clzero
6738@itemx no-clzero
d77de738
ML
6739Enable/disable the generation of the CLZERO instructions.
6740
f33d7a88 6741@cindex @code{target("crc32")} function attribute, x86
d77de738
ML
6742@item crc32
6743@itemx no-crc32
d77de738
ML
6744Enable/disable the generation of the CRC32 instructions.
6745
f33d7a88 6746@cindex @code{target("cx16")} function attribute, x86
d77de738
ML
6747@item cx16
6748@itemx no-cx16
d77de738
ML
6749Enable/disable the generation of the CMPXCHG16B instructions.
6750
d77de738 6751@cindex @code{target("default")} function attribute, x86
f33d7a88 6752@item default
d77de738
ML
6753@xref{Function Multiversioning}, where it is used to specify the
6754default function version.
6755
f33d7a88 6756@cindex @code{target("f16c")} function attribute, x86
d77de738
ML
6757@item f16c
6758@itemx no-f16c
d77de738
ML
6759Enable/disable the generation of the F16C instructions.
6760
f33d7a88 6761@cindex @code{target("fma")} function attribute, x86
d77de738
ML
6762@item fma
6763@itemx no-fma
d77de738
ML
6764Enable/disable the generation of the FMA instructions.
6765
f33d7a88 6766@cindex @code{target("fma4")} function attribute, x86
d77de738
ML
6767@item fma4
6768@itemx no-fma4
d77de738
ML
6769Enable/disable the generation of the FMA4 instructions.
6770
f33d7a88 6771@cindex @code{target("fsgsbase")} function attribute, x86
d77de738
ML
6772@item fsgsbase
6773@itemx no-fsgsbase
d77de738
ML
6774Enable/disable the generation of the FSGSBASE instructions.
6775
f33d7a88 6776@cindex @code{target("fxsr")} function attribute, x86
d77de738
ML
6777@item fxsr
6778@itemx no-fxsr
d77de738
ML
6779Enable/disable the generation of the FXSR instructions.
6780
f33d7a88 6781@cindex @code{target("gfni")} function attribute, x86
d77de738
ML
6782@item gfni
6783@itemx no-gfni
d77de738
ML
6784Enable/disable the generation of the GFNI instructions.
6785
f33d7a88 6786@cindex @code{target("hle")} function attribute, x86
d77de738
ML
6787@item hle
6788@itemx no-hle
d77de738
ML
6789Enable/disable the generation of the HLE instruction prefixes.
6790
f33d7a88 6791@cindex @code{target("lwp")} function attribute, x86
d77de738
ML
6792@item lwp
6793@itemx no-lwp
d77de738
ML
6794Enable/disable the generation of the LWP instructions.
6795
f33d7a88 6796@cindex @code{target("lzcnt")} function attribute, x86
d77de738
ML
6797@item lzcnt
6798@itemx no-lzcnt
d77de738
ML
6799Enable/disable the generation of the LZCNT instructions.
6800
f33d7a88 6801@cindex @code{target("mmx")} function attribute, x86
d77de738
ML
6802@item mmx
6803@itemx no-mmx
d77de738
ML
6804Enable/disable the generation of the MMX instructions.
6805
f33d7a88 6806@cindex @code{target("movbe")} function attribute, x86
d77de738
ML
6807@item movbe
6808@itemx no-movbe
d77de738
ML
6809Enable/disable the generation of the MOVBE instructions.
6810
f33d7a88 6811@cindex @code{target("movdir64b")} function attribute, x86
d77de738
ML
6812@item movdir64b
6813@itemx no-movdir64b
d77de738
ML
6814Enable/disable the generation of the MOVDIR64B instructions.
6815
f33d7a88 6816@cindex @code{target("movdiri")} function attribute, x86
d77de738
ML
6817@item movdiri
6818@itemx no-movdiri
d77de738
ML
6819Enable/disable the generation of the MOVDIRI instructions.
6820
f33d7a88 6821@cindex @code{target("mwait")} function attribute, x86
d77de738
ML
6822@item mwait
6823@itemx no-mwait
d77de738
ML
6824Enable/disable the generation of the MWAIT and MONITOR instructions.
6825
f33d7a88 6826@cindex @code{target("mwaitx")} function attribute, x86
d77de738
ML
6827@item mwaitx
6828@itemx no-mwaitx
d77de738
ML
6829Enable/disable the generation of the MWAITX instructions.
6830
f33d7a88 6831@cindex @code{target("pclmul")} function attribute, x86
d77de738
ML
6832@item pclmul
6833@itemx no-pclmul
d77de738
ML
6834Enable/disable the generation of the PCLMUL instructions.
6835
f33d7a88 6836@cindex @code{target("pconfig")} function attribute, x86
d77de738
ML
6837@item pconfig
6838@itemx no-pconfig
d77de738
ML
6839Enable/disable the generation of the PCONFIG instructions.
6840
f33d7a88 6841@cindex @code{target("pku")} function attribute, x86
d77de738
ML
6842@item pku
6843@itemx no-pku
d77de738
ML
6844Enable/disable the generation of the PKU instructions.
6845
f33d7a88 6846@cindex @code{target("popcnt")} function attribute, x86
d77de738
ML
6847@item popcnt
6848@itemx no-popcnt
d77de738
ML
6849Enable/disable the generation of the POPCNT instruction.
6850
f33d7a88 6851@cindex @code{target("prefetchwt1")} function attribute, x86
d77de738
ML
6852@item prefetchwt1
6853@itemx no-prefetchwt1
d77de738
ML
6854Enable/disable the generation of the PREFETCHWT1 instructions.
6855
f33d7a88 6856@cindex @code{target("prfchw")} function attribute, x86
d77de738
ML
6857@item prfchw
6858@itemx no-prfchw
d77de738
ML
6859Enable/disable the generation of the PREFETCHW instruction.
6860
f33d7a88 6861@cindex @code{target("ptwrite")} function attribute, x86
d77de738
ML
6862@item ptwrite
6863@itemx no-ptwrite
d77de738
ML
6864Enable/disable the generation of the PTWRITE instructions.
6865
f33d7a88 6866@cindex @code{target("rdpid")} function attribute, x86
d77de738
ML
6867@item rdpid
6868@itemx no-rdpid
d77de738
ML
6869Enable/disable the generation of the RDPID instructions.
6870
f33d7a88 6871@cindex @code{target("rdrnd")} function attribute, x86
d77de738
ML
6872@item rdrnd
6873@itemx no-rdrnd
d77de738
ML
6874Enable/disable the generation of the RDRND instructions.
6875
f33d7a88 6876@cindex @code{target("rdseed")} function attribute, x86
d77de738
ML
6877@item rdseed
6878@itemx no-rdseed
d77de738
ML
6879Enable/disable the generation of the RDSEED instructions.
6880
f33d7a88 6881@cindex @code{target("rtm")} function attribute, x86
d77de738
ML
6882@item rtm
6883@itemx no-rtm
d77de738
ML
6884Enable/disable the generation of the RTM instructions.
6885
f33d7a88 6886@cindex @code{target("sahf")} function attribute, x86
d77de738
ML
6887@item sahf
6888@itemx no-sahf
d77de738
ML
6889Enable/disable the generation of the SAHF instructions.
6890
f33d7a88 6891@cindex @code{target("sgx")} function attribute, x86
d77de738
ML
6892@item sgx
6893@itemx no-sgx
d77de738
ML
6894Enable/disable the generation of the SGX instructions.
6895
f33d7a88 6896@cindex @code{target("sha")} function attribute, x86
d77de738
ML
6897@item sha
6898@itemx no-sha
d77de738
ML
6899Enable/disable the generation of the SHA instructions.
6900
f33d7a88 6901@cindex @code{target("shstk")} function attribute, x86
d77de738
ML
6902@item shstk
6903@itemx no-shstk
d77de738
ML
6904Enable/disable the shadow stack built-in functions from CET.
6905
f33d7a88 6906@cindex @code{target("sse")} function attribute, x86
d77de738
ML
6907@item sse
6908@itemx no-sse
d77de738
ML
6909Enable/disable the generation of the SSE instructions.
6910
f33d7a88 6911@cindex @code{target("sse2")} function attribute, x86
d77de738
ML
6912@item sse2
6913@itemx no-sse2
d77de738
ML
6914Enable/disable the generation of the SSE2 instructions.
6915
f33d7a88 6916@cindex @code{target("sse3")} function attribute, x86
d77de738
ML
6917@item sse3
6918@itemx no-sse3
d77de738
ML
6919Enable/disable the generation of the SSE3 instructions.
6920
f33d7a88 6921@cindex @code{target("sse4")} function attribute, x86
d77de738
ML
6922@item sse4
6923@itemx no-sse4
d77de738
ML
6924Enable/disable the generation of the SSE4 instructions (both SSE4.1
6925and SSE4.2).
6926
f33d7a88 6927@cindex @code{target("sse4.1")} function attribute, x86
d77de738
ML
6928@item sse4.1
6929@itemx no-sse4.1
d77de738
ML
6930Enable/disable the generation of the SSE4.1 instructions.
6931
f33d7a88 6932@cindex @code{target("sse4.2")} function attribute, x86
d77de738
ML
6933@item sse4.2
6934@itemx no-sse4.2
d77de738
ML
6935Enable/disable the generation of the SSE4.2 instructions.
6936
f33d7a88 6937@cindex @code{target("sse4a")} function attribute, x86
d77de738
ML
6938@item sse4a
6939@itemx no-sse4a
d77de738
ML
6940Enable/disable the generation of the SSE4A instructions.
6941
f33d7a88 6942@cindex @code{target("ssse3")} function attribute, x86
d77de738
ML
6943@item ssse3
6944@itemx no-ssse3
d77de738
ML
6945Enable/disable the generation of the SSSE3 instructions.
6946
f33d7a88 6947@cindex @code{target("tbm")} function attribute, x86
d77de738
ML
6948@item tbm
6949@itemx no-tbm
d77de738
ML
6950Enable/disable the generation of the TBM instructions.
6951
f33d7a88 6952@cindex @code{target("vaes")} function attribute, x86
d77de738
ML
6953@item vaes
6954@itemx no-vaes
d77de738
ML
6955Enable/disable the generation of the VAES instructions.
6956
f33d7a88 6957@cindex @code{target("vpclmulqdq")} function attribute, x86
d77de738
ML
6958@item vpclmulqdq
6959@itemx no-vpclmulqdq
d77de738
ML
6960Enable/disable the generation of the VPCLMULQDQ instructions.
6961
f33d7a88 6962@cindex @code{target("waitpkg")} function attribute, x86
d77de738
ML
6963@item waitpkg
6964@itemx no-waitpkg
d77de738
ML
6965Enable/disable the generation of the WAITPKG instructions.
6966
f33d7a88 6967@cindex @code{target("wbnoinvd")} function attribute, x86
d77de738
ML
6968@item wbnoinvd
6969@itemx no-wbnoinvd
d77de738
ML
6970Enable/disable the generation of the WBNOINVD instructions.
6971
f33d7a88 6972@cindex @code{target("xop")} function attribute, x86
d77de738
ML
6973@item xop
6974@itemx no-xop
d77de738
ML
6975Enable/disable the generation of the XOP instructions.
6976
f33d7a88 6977@cindex @code{target("xsave")} function attribute, x86
d77de738
ML
6978@item xsave
6979@itemx no-xsave
d77de738
ML
6980Enable/disable the generation of the XSAVE instructions.
6981
f33d7a88 6982@cindex @code{target("xsavec")} function attribute, x86
d77de738
ML
6983@item xsavec
6984@itemx no-xsavec
d77de738
ML
6985Enable/disable the generation of the XSAVEC instructions.
6986
f33d7a88 6987@cindex @code{target("xsaveopt")} function attribute, x86
d77de738
ML
6988@item xsaveopt
6989@itemx no-xsaveopt
d77de738
ML
6990Enable/disable the generation of the XSAVEOPT instructions.
6991
f33d7a88 6992@cindex @code{target("xsaves")} function attribute, x86
d77de738
ML
6993@item xsaves
6994@itemx no-xsaves
d77de738
ML
6995Enable/disable the generation of the XSAVES instructions.
6996
f33d7a88 6997@cindex @code{target("amx-tile")} function attribute, x86
d77de738
ML
6998@item amx-tile
6999@itemx no-amx-tile
d77de738
ML
7000Enable/disable the generation of the AMX-TILE instructions.
7001
f33d7a88 7002@cindex @code{target("amx-int8")} function attribute, x86
d77de738
ML
7003@item amx-int8
7004@itemx no-amx-int8
d77de738
ML
7005Enable/disable the generation of the AMX-INT8 instructions.
7006
f33d7a88 7007@cindex @code{target("amx-bf16")} function attribute, x86
d77de738
ML
7008@item amx-bf16
7009@itemx no-amx-bf16
d77de738
ML
7010Enable/disable the generation of the AMX-BF16 instructions.
7011
f33d7a88 7012@cindex @code{target("uintr")} function attribute, x86
d77de738
ML
7013@item uintr
7014@itemx no-uintr
d77de738
ML
7015Enable/disable the generation of the UINTR instructions.
7016
f33d7a88 7017@cindex @code{target("hreset")} function attribute, x86
d77de738
ML
7018@item hreset
7019@itemx no-hreset
d77de738
ML
7020Enable/disable the generation of the HRESET instruction.
7021
f33d7a88 7022@cindex @code{target("kl")} function attribute, x86
d77de738
ML
7023@item kl
7024@itemx no-kl
d77de738
ML
7025Enable/disable the generation of the KEYLOCKER instructions.
7026
f33d7a88 7027@cindex @code{target("widekl")} function attribute, x86
d77de738
ML
7028@item widekl
7029@itemx no-widekl
d77de738
ML
7030Enable/disable the generation of the WIDEKL instructions.
7031
f33d7a88 7032@cindex @code{target("avxvnni")} function attribute, x86
d77de738
ML
7033@item avxvnni
7034@itemx no-avxvnni
d77de738
ML
7035Enable/disable the generation of the AVXVNNI instructions.
7036
f33d7a88 7037@cindex @code{target("avxifma")} function attribute, x86
d77de738
ML
7038@item avxifma
7039@itemx no-avxifma
d77de738
ML
7040Enable/disable the generation of the AVXIFMA instructions.
7041
f33d7a88 7042@cindex @code{target("avxvnniint8")} function attribute, x86
d77de738
ML
7043@item avxvnniint8
7044@itemx no-avxvnniint8
d77de738
ML
7045Enable/disable the generation of the AVXVNNIINT8 instructions.
7046
f33d7a88 7047@cindex @code{target("avxneconvert")} function attribute, x86
d77de738
ML
7048@item avxneconvert
7049@itemx no-avxneconvert
d77de738
ML
7050Enable/disable the generation of the AVXNECONVERT instructions.
7051
f33d7a88 7052@cindex @code{target("cmpccxadd")} function attribute, x86
d77de738
ML
7053@item cmpccxadd
7054@itemx no-cmpccxadd
d77de738
ML
7055Enable/disable the generation of the CMPccXADD instructions.
7056
f33d7a88 7057@cindex @code{target("amx-fp16")} function attribute, x86
d77de738
ML
7058@item amx-fp16
7059@itemx no-amx-fp16
d77de738
ML
7060Enable/disable the generation of the AMX-FP16 instructions.
7061
f33d7a88 7062@cindex @code{target("prefetchi")} function attribute, x86
d77de738
ML
7063@item prefetchi
7064@itemx no-prefetchi
d77de738
ML
7065Enable/disable the generation of the PREFETCHI instructions.
7066
f33d7a88 7067@cindex @code{target("raoint")} function attribute, x86
d77de738
ML
7068@item raoint
7069@itemx no-raoint
d77de738
ML
7070Enable/disable the generation of the RAOINT instructions.
7071
f33d7a88 7072@cindex @code{target("cld")} function attribute, x86
d77de738
ML
7073@item cld
7074@itemx no-cld
d77de738
ML
7075Enable/disable the generation of the CLD before string moves.
7076
f33d7a88 7077@cindex @code{target("fancy-math-387")} function attribute, x86
d77de738
ML
7078@item fancy-math-387
7079@itemx no-fancy-math-387
d77de738
ML
7080Enable/disable the generation of the @code{sin}, @code{cos}, and
7081@code{sqrt} instructions on the 387 floating-point unit.
7082
f33d7a88 7083@cindex @code{target("ieee-fp")} function attribute, x86
d77de738
ML
7084@item ieee-fp
7085@itemx no-ieee-fp
d77de738
ML
7086Enable/disable the generation of floating point that depends on IEEE arithmetic.
7087
f33d7a88 7088@cindex @code{target("inline-all-stringops")} function attribute, x86
d77de738
ML
7089@item inline-all-stringops
7090@itemx no-inline-all-stringops
d77de738
ML
7091Enable/disable inlining of string operations.
7092
f33d7a88 7093@cindex @code{target("inline-stringops-dynamically")} function attribute, x86
d77de738
ML
7094@item inline-stringops-dynamically
7095@itemx no-inline-stringops-dynamically
d77de738
ML
7096Enable/disable the generation of the inline code to do small string
7097operations and calling the library routines for large operations.
7098
f33d7a88 7099@cindex @code{target("align-stringops")} function attribute, x86
d77de738
ML
7100@item align-stringops
7101@itemx no-align-stringops
d77de738
ML
7102Do/do not align destination of inlined string operations.
7103
f33d7a88 7104@cindex @code{target("recip")} function attribute, x86
d77de738
ML
7105@item recip
7106@itemx no-recip
d77de738
ML
7107Enable/disable the generation of RCPSS, RCPPS, RSQRTSS and RSQRTPS
7108instructions followed an additional Newton-Raphson step instead of
7109doing a floating-point division.
7110
d77de738 7111@cindex @code{target("general-regs-only")} function attribute, x86
f33d7a88 7112@item general-regs-only
d77de738
ML
7113Generate code which uses only the general registers.
7114
d77de738 7115@cindex @code{target("arch=@var{ARCH}")} function attribute, x86
f33d7a88 7116@item arch=@var{ARCH}
d77de738
ML
7117Specify the architecture to generate code for in compiling the function.
7118
d77de738 7119@cindex @code{target("tune=@var{TUNE}")} function attribute, x86
f33d7a88 7120@item tune=@var{TUNE}
d77de738
ML
7121Specify the architecture to tune for in compiling the function.
7122
d77de738 7123@cindex @code{target("fpmath=@var{FPMATH}")} function attribute, x86
f33d7a88 7124@item fpmath=@var{FPMATH}
d77de738
ML
7125Specify which floating-point unit to use. You must specify the
7126@code{target("fpmath=sse,387")} option as
7127@code{target("fpmath=sse+387")} because the comma would separate
7128different options.
7129
d77de738 7130@cindex @code{prefer-vector-width} function attribute, x86
f33d7a88 7131@item prefer-vector-width=@var{OPT}
d77de738
ML
7132On x86 targets, the @code{prefer-vector-width} attribute informs the
7133compiler to use @var{OPT}-bit vector width in instructions
7134instead of the default on the selected platform.
7135
7136Valid @var{OPT} values are:
7137
7138@table @samp
7139@item none
7140No extra limitations applied to GCC other than defined by the selected platform.
7141
7142@item 128
7143Prefer 128-bit vector width for instructions.
7144
7145@item 256
7146Prefer 256-bit vector width for instructions.
7147
7148@item 512
7149Prefer 512-bit vector width for instructions.
7150@end table
7151
7152On the x86, the inliner does not inline a
7153function that has different target options than the caller, unless the
7154callee has a subset of the target options of the caller. For example
7155a function declared with @code{target("sse3")} can inline a function
7156with @code{target("sse2")}, since @code{-msse3} implies @code{-msse2}.
7157@end table
7158
d77de738 7159@cindex @code{indirect_branch} function attribute, x86
f33d7a88 7160@item indirect_branch("@var{choice}")
d77de738
ML
7161On x86 targets, the @code{indirect_branch} attribute causes the compiler
7162to convert indirect call and jump with @var{choice}. @samp{keep}
7163keeps indirect call and jump unmodified. @samp{thunk} converts indirect
7164call and jump to call and return thunk. @samp{thunk-inline} converts
7165indirect call and jump to inlined call and return thunk.
7166@samp{thunk-extern} converts indirect call and jump to external call
7167and return thunk provided in a separate object file.
7168
d77de738 7169@cindex @code{function_return} function attribute, x86
f33d7a88 7170@item function_return("@var{choice}")
d77de738
ML
7171On x86 targets, the @code{function_return} attribute causes the compiler
7172to convert function return with @var{choice}. @samp{keep} keeps function
7173return unmodified. @samp{thunk} converts function return to call and
7174return thunk. @samp{thunk-inline} converts function return to inlined
7175call and return thunk. @samp{thunk-extern} converts function return to
7176external call and return thunk provided in a separate object file.
7177
d77de738 7178@cindex @code{nocf_check} function attribute
f33d7a88 7179@item nocf_check
d77de738
ML
7180The @code{nocf_check} attribute on a function is used to inform the
7181compiler that the function's prologue should not be instrumented when
7182compiled with the @option{-fcf-protection=branch} option. The
7183compiler assumes that the function's address is a valid target for a
7184control-flow transfer.
7185
7186The @code{nocf_check} attribute on a type of pointer to function is
7187used to inform the compiler that a call through the pointer should
7188not be instrumented when compiled with the
7189@option{-fcf-protection=branch} option. The compiler assumes
7190that the function's address from the pointer is a valid target for
7191a control-flow transfer. A direct function call through a function
7192name is assumed to be a safe call thus direct calls are not
7193instrumented by the compiler.
7194
7195The @code{nocf_check} attribute is applied to an object's type.
7196In case of assignment of a function address or a function pointer to
7197another pointer, the attribute is not carried over from the right-hand
7198object's type; the type of left-hand object stays unchanged. The
7199compiler checks for @code{nocf_check} attribute mismatch and reports
7200a warning in case of mismatch.
7201
7202@smallexample
7203@{
7204int foo (void) __attribute__(nocf_check);
7205void (*foo1)(void) __attribute__(nocf_check);
7206void (*foo2)(void);
7207
7208/* foo's address is assumed to be valid. */
7209int
7210foo (void)
7211
7212 /* This call site is not checked for control-flow
7213 validity. */
7214 (*foo1)();
7215
7216 /* A warning is issued about attribute mismatch. */
7217 foo1 = foo2;
7218
7219 /* This call site is still not checked. */
7220 (*foo1)();
7221
7222 /* This call site is checked. */
7223 (*foo2)();
7224
7225 /* A warning is issued about attribute mismatch. */
7226 foo2 = foo1;
7227
7228 /* This call site is still checked. */
7229 (*foo2)();
7230
7231 return 0;
7232@}
7233@end smallexample
7234
d77de738 7235@cindex @code{cf_check} function attribute, x86
f33d7a88 7236@item cf_check
d77de738
ML
7237
7238The @code{cf_check} attribute on a function is used to inform the
7239compiler that ENDBR instruction should be placed at the function
7240entry when @option{-fcf-protection=branch} is enabled.
7241
d77de738 7242@cindex @code{indirect_return} function attribute, x86
f33d7a88 7243@item indirect_return
d77de738
ML
7244
7245The @code{indirect_return} attribute can be applied to a function,
7246as well as variable or type of function pointer to inform the
7247compiler that the function may return via indirect branch.
7248
d77de738 7249@cindex @code{fentry_name} function attribute, x86
f33d7a88 7250@item fentry_name("@var{name}")
d77de738
ML
7251On x86 targets, the @code{fentry_name} attribute sets the function to
7252call on function entry when function instrumentation is enabled
7253with @option{-pg -mfentry}. When @var{name} is nop then a 5 byte
7254nop sequence is generated.
7255
d77de738 7256@cindex @code{fentry_section} function attribute, x86
f33d7a88 7257@item fentry_section("@var{name}")
d77de738
ML
7258On x86 targets, the @code{fentry_section} attribute sets the name
7259of the section to record function entry instrumentation calls in when
7260enabled with @option{-pg -mrecord-mcount}
7261
d77de738
ML
7262@cindex @code{nodirect_extern_access} function attribute
7263@opindex mno-direct-extern-access
f33d7a88 7264@item nodirect_extern_access
d77de738
ML
7265This attribute, attached to a global variable or function, is the
7266counterpart to option @option{-mno-direct-extern-access}.
7267
7268@end table
7269
7270@node Xstormy16 Function Attributes
7271@subsection Xstormy16 Function Attributes
7272
7273These function attributes are supported by the Xstormy16 back end:
7274
7275@table @code
d77de738 7276@cindex @code{interrupt} function attribute, Xstormy16
f33d7a88 7277@item interrupt
d77de738
ML
7278Use this attribute to indicate
7279that the specified function is an interrupt handler. The compiler generates
7280function entry and exit sequences suitable for use in an interrupt handler
7281when this attribute is present.
7282@end table
7283
7284@node Variable Attributes
7285@section Specifying Attributes of Variables
7286@cindex attribute of variables
7287@cindex variable attributes
7288
7289The keyword @code{__attribute__} allows you to specify special properties
7290of variables, function parameters, or structure, union, and, in C++, class
7291members. This @code{__attribute__} keyword is followed by an attribute
7292specification enclosed in double parentheses. Some attributes are currently
7293defined generically for variables. Other attributes are defined for
7294variables on particular target systems. Other attributes are available
7295for functions (@pxref{Function Attributes}), labels (@pxref{Label Attributes}),
7296enumerators (@pxref{Enumerator Attributes}), statements
7297(@pxref{Statement Attributes}), and for types (@pxref{Type Attributes}).
7298Other front ends might define more attributes
7299(@pxref{C++ Extensions,,Extensions to the C++ Language}).
7300
7301@xref{Attribute Syntax}, for details of the exact syntax for using
7302attributes.
7303
7304@menu
7305* Common Variable Attributes::
7306* ARC Variable Attributes::
7307* AVR Variable Attributes::
7308* Blackfin Variable Attributes::
7309* H8/300 Variable Attributes::
7310* IA-64 Variable Attributes::
7311* LoongArch Variable Attributes::
7312* M32R/D Variable Attributes::
d77de738
ML
7313* Microsoft Windows Variable Attributes::
7314* MSP430 Variable Attributes::
7315* Nvidia PTX Variable Attributes::
7316* PowerPC Variable Attributes::
7317* RL78 Variable Attributes::
7318* V850 Variable Attributes::
7319* x86 Variable Attributes::
7320* Xstormy16 Variable Attributes::
7321@end menu
7322
7323@node Common Variable Attributes
7324@subsection Common Variable Attributes
7325
7326The following attributes are supported on most targets.
7327
7328@table @code
7329
d77de738 7330@cindex @code{alias} variable attribute
f33d7a88 7331@item alias ("@var{target}")
d77de738
ML
7332The @code{alias} variable attribute causes the declaration to be emitted
7333as an alias for another symbol known as an @dfn{alias target}. Except
7334for top-level qualifiers the alias target must have the same type as
7335the alias. For instance, the following
7336
7337@smallexample
7338int var_target;
7339extern int __attribute__ ((alias ("var_target"))) var_alias;
7340@end smallexample
7341
7342@noindent
7343defines @code{var_alias} to be an alias for the @code{var_target} variable.
7344
7345It is an error if the alias target is not defined in the same translation
7346unit as the alias.
7347
7348Note that in the absence of the attribute GCC assumes that distinct
7349declarations with external linkage denote distinct objects. Using both
7350the alias and the alias target to access the same object is undefined
7351in a translation unit without a declaration of the alias with the attribute.
7352
7353This attribute requires assembler and object file support, and may not be
7354available on all targets.
7355
7356@cindex @code{aligned} variable attribute
7357@item aligned
7358@itemx aligned (@var{alignment})
7359The @code{aligned} attribute specifies a minimum alignment for the variable
7360or structure field, measured in bytes. When specified, @var{alignment} must
7361be an integer constant power of 2. Specifying no @var{alignment} argument
7362implies the maximum alignment for the target, which is often, but by no
7363means always, 8 or 16 bytes.
7364
7365For example, the declaration:
7366
7367@smallexample
7368int x __attribute__ ((aligned (16))) = 0;
7369@end smallexample
7370
7371@noindent
7372causes the compiler to allocate the global variable @code{x} on a
737316-byte boundary. On a 68040, this could be used in conjunction with
7374an @code{asm} expression to access the @code{move16} instruction which
7375requires 16-byte aligned operands.
7376
7377You can also specify the alignment of structure fields. For example, to
7378create a double-word aligned @code{int} pair, you could write:
7379
7380@smallexample
7381struct foo @{ int x[2] __attribute__ ((aligned (8))); @};
7382@end smallexample
7383
7384@noindent
7385This is an alternative to creating a union with a @code{double} member,
7386which forces the union to be double-word aligned.
7387
7388As in the preceding examples, you can explicitly specify the alignment
7389(in bytes) that you wish the compiler to use for a given variable or
7390structure field. Alternatively, you can leave out the alignment factor
7391and just ask the compiler to align a variable or field to the
7392default alignment for the target architecture you are compiling for.
7393The default alignment is sufficient for all scalar types, but may not be
7394enough for all vector types on a target that supports vector operations.
7395The default alignment is fixed for a particular target ABI.
7396
7397GCC also provides a target specific macro @code{__BIGGEST_ALIGNMENT__},
7398which is the largest alignment ever used for any data type on the
7399target machine you are compiling for. For example, you could write:
7400
7401@smallexample
7402short array[3] __attribute__ ((aligned (__BIGGEST_ALIGNMENT__)));
7403@end smallexample
7404
7405The compiler automatically sets the alignment for the declared
7406variable or field to @code{__BIGGEST_ALIGNMENT__}. Doing this can
7407often make copy operations more efficient, because the compiler can
7408use whatever instructions copy the biggest chunks of memory when
7409performing copies to or from the variables or fields that you have
7410aligned this way. Note that the value of @code{__BIGGEST_ALIGNMENT__}
7411may change depending on command-line options.
7412
7413When used on a struct, or struct member, the @code{aligned} attribute can
7414only increase the alignment; in order to decrease it, the @code{packed}
7415attribute must be specified as well. When used as part of a typedef, the
7416@code{aligned} attribute can both increase and decrease alignment, and
7417specifying the @code{packed} attribute generates a warning.
7418
7419Note that the effectiveness of @code{aligned} attributes for static
7420variables may be limited by inherent limitations in the system linker
7421and/or object file format. On some systems, the linker is
7422only able to arrange for variables to be aligned up to a certain maximum
7423alignment. (For some linkers, the maximum supported alignment may
7424be very very small.) If your linker is only able to align variables
7425up to a maximum of 8-byte alignment, then specifying @code{aligned(16)}
7426in an @code{__attribute__} still only provides you with 8-byte
7427alignment. See your linker documentation for further information.
7428
7429Stack variables are not affected by linker restrictions; GCC can properly
7430align them on any target.
7431
7432The @code{aligned} attribute can also be used for functions
7433(@pxref{Common Function Attributes}.)
7434
7435@cindex @code{warn_if_not_aligned} variable attribute
7436@item warn_if_not_aligned (@var{alignment})
7437This attribute specifies a threshold for the structure field, measured
7438in bytes. If the structure field is aligned below the threshold, a
7439warning will be issued. For example, the declaration:
7440
7441@smallexample
7442struct foo
7443@{
7444 int i1;
7445 int i2;
7446 unsigned long long x __attribute__ ((warn_if_not_aligned (16)));
7447@};
7448@end smallexample
7449
7450@noindent
7451causes the compiler to issue an warning on @code{struct foo}, like
7452@samp{warning: alignment 8 of 'struct foo' is less than 16}.
7453The compiler also issues a warning, like @samp{warning: 'x' offset
74548 in 'struct foo' isn't aligned to 16}, when the structure field has
7455the misaligned offset:
7456
7457@smallexample
7458struct __attribute__ ((aligned (16))) foo
7459@{
7460 int i1;
7461 int i2;
7462 unsigned long long x __attribute__ ((warn_if_not_aligned (16)));
7463@};
7464@end smallexample
7465
7466This warning can be disabled by @option{-Wno-if-not-aligned}.
7467The @code{warn_if_not_aligned} attribute can also be used for types
7468(@pxref{Common Type Attributes}.)
7469
7470@cindex @code{strict_flex_array} variable attribute
7471@item strict_flex_array (@var{level})
7472The @code{strict_flex_array} attribute should be attached to the trailing
7473array field of a structure. It controls when to treat the trailing array
7474field of a structure as a flexible array member for the purposes of accessing
7475the elements of such an array.
7476@var{level} must be an integer betwen 0 to 3.
7477
7478@var{level}=0 is the least strict level, all trailing arrays of structures
7479are treated as flexible array members. @var{level}=3 is the strictest level,
7480only when the trailing array is declared as a flexible array member per C99
7481standard onwards (@samp{[]}), it is treated as a flexible array member.
7482
7483There are two more levels in between 0 and 3, which are provided to support
7484older codes that use GCC zero-length array extension (@samp{[0]}) or one-element
7485array as flexible array members (@samp{[1]}):
7486When @var{level} is 1, the trailing array is treated as a flexible array member
7487when it is declared as either @samp{[]}, @samp{[0]}, or @samp{[1]};
7488When @var{level} is 2, the trailing array is treated as a flexible array member
7489when it is declared as either @samp{[]}, or @samp{[0]}.
7490
7491This attribute can be used with or without the @option{-fstrict-flex-arrays}.
7492When both the attribute and the option present at the same time, the level of
7493the strictness for the specific trailing array field is determined by the
7494attribute.
7495
f33d7a88 7496@cindex @code{alloc_size} variable attribute
d77de738
ML
7497@item alloc_size (@var{position})
7498@itemx alloc_size (@var{position-1}, @var{position-2})
d77de738
ML
7499The @code{alloc_size} variable attribute may be applied to the declaration
7500of a pointer to a function that returns a pointer and takes at least one
7501argument of an integer type. It indicates that the returned pointer points
7502to an object whose size is given by the function argument at @var{position},
7503or by the product of the arguments at @var{position-1} and @var{position-2}.
7504Meaningful sizes are positive values less than @code{PTRDIFF_MAX}. Other
7505sizes are diagnosed when detected. GCC uses this information to improve
7506the results of @code{__builtin_object_size}.
7507
7508For instance, the following declarations
7509
7510@smallexample
7511typedef __attribute__ ((alloc_size (1, 2))) void*
7512 (*calloc_ptr) (size_t, size_t);
7513typedef __attribute__ ((alloc_size (1))) void*
7514 (*malloc_ptr) (size_t);
7515@end smallexample
7516
7517@noindent
7518specify that @code{calloc_ptr} is a pointer of a function that, like
7519the standard C function @code{calloc}, returns an object whose size
7520is given by the product of arguments 1 and 2, and similarly, that
7521@code{malloc_ptr}, like the standard C function @code{malloc},
7522returns an object whose size is given by argument 1 to the function.
7523
d77de738 7524@cindex @code{cleanup} variable attribute
f33d7a88 7525@item cleanup (@var{cleanup_function})
d77de738
ML
7526The @code{cleanup} attribute runs a function when the variable goes
7527out of scope. This attribute can only be applied to auto function
7528scope variables; it may not be applied to parameters or variables
7529with static storage duration. The function must take one parameter,
7530a pointer to a type compatible with the variable. The return value
7531of the function (if any) is ignored.
7532
7533If @option{-fexceptions} is enabled, then @var{cleanup_function}
7534is run during the stack unwinding that happens during the
7535processing of the exception. Note that the @code{cleanup} attribute
7536does not allow the exception to be caught, only to perform an action.
7537It is undefined what happens if @var{cleanup_function} does not
7538return normally.
7539
d77de738
ML
7540@cindex @code{common} variable attribute
7541@cindex @code{nocommon} variable attribute
7542@opindex fcommon
7543@opindex fno-common
f33d7a88
AA
7544@item common
7545@itemx nocommon
d77de738
ML
7546The @code{common} attribute requests GCC to place a variable in
7547``common'' storage. The @code{nocommon} attribute requests the
7548opposite---to allocate space for it directly.
7549
7550These attributes override the default chosen by the
7551@option{-fno-common} and @option{-fcommon} flags respectively.
7552
f33d7a88 7553@cindex @code{copy} variable attribute
d77de738
ML
7554@item copy
7555@itemx copy (@var{variable})
d77de738
ML
7556The @code{copy} attribute applies the set of attributes with which
7557@var{variable} has been declared to the declaration of the variable
7558to which the attribute is applied. The attribute is designed for
7559libraries that define aliases that are expected to specify the same
7560set of attributes as the aliased symbols. The @code{copy} attribute
7561can be used with variables, functions or types. However, the kind
7562of symbol to which the attribute is applied (either varible or
7563function) must match the kind of symbol to which the argument refers.
7564The @code{copy} attribute copies only syntactic and semantic attributes
7565but not attributes that affect a symbol's linkage or visibility such as
7566@code{alias}, @code{visibility}, or @code{weak}. The @code{deprecated}
7567attribute is also not copied. @xref{Common Function Attributes}.
7568@xref{Common Type Attributes}.
7569
f33d7a88 7570@cindex @code{deprecated} variable attribute
d77de738
ML
7571@item deprecated
7572@itemx deprecated (@var{msg})
d77de738
ML
7573The @code{deprecated} attribute results in a warning if the variable
7574is used anywhere in the source file. This is useful when identifying
7575variables that are expected to be removed in a future version of a
7576program. The warning also includes the location of the declaration
7577of the deprecated variable, to enable users to easily find further
7578information about why the variable is deprecated, or what they should
7579do instead. Note that the warning only occurs for uses:
7580
7581@smallexample
7582extern int old_var __attribute__ ((deprecated));
7583extern int old_var;
7584int new_fn () @{ return old_var; @}
7585@end smallexample
7586
7587@noindent
7588results in a warning on line 3 but not line 2. The optional @var{msg}
7589argument, which must be a string, is printed in the warning if
7590present.
7591
7592The @code{deprecated} attribute can also be used for functions and
7593types (@pxref{Common Function Attributes},
7594@pxref{Common Type Attributes}).
7595
7596The message attached to the attribute is affected by the setting of
7597the @option{-fmessage-length} option.
7598
f33d7a88 7599@cindex @code{unavailable} variable attribute
d77de738
ML
7600@item unavailable
7601@itemx unavailable (@var{msg})
d77de738
ML
7602The @code{unavailable} attribute indicates that the variable so marked
7603is not available, if it is used anywhere in the source file. It behaves
7604in the same manner as the @code{deprecated} attribute except that the
7605compiler will emit an error rather than a warning.
7606
7607It is expected that items marked as @code{deprecated} will eventually be
7608withdrawn from interfaces, and then become unavailable. This attribute
7609allows for marking them appropriately.
7610
7611The @code{unavailable} attribute can also be used for functions and
7612types (@pxref{Common Function Attributes},
7613@pxref{Common Type Attributes}).
7614
d77de738 7615@cindex @code{mode} variable attribute
f33d7a88 7616@item mode (@var{mode})
d77de738
ML
7617This attribute specifies the data type for the declaration---whichever
7618type corresponds to the mode @var{mode}. This in effect lets you
7619request an integer or floating-point type according to its width.
7620
7621@xref{Machine Modes,,, gccint, GNU Compiler Collection (GCC) Internals},
7622for a list of the possible keywords for @var{mode}.
7623You may also specify a mode of @code{byte} or @code{__byte__} to
7624indicate the mode corresponding to a one-byte integer, @code{word} or
7625@code{__word__} for the mode of a one-word integer, and @code{pointer}
7626or @code{__pointer__} for the mode used to represent pointers.
7627
d77de738 7628@cindex @code{nonstring} variable attribute
f33d7a88 7629@item nonstring
d77de738
ML
7630The @code{nonstring} variable attribute specifies that an object or member
7631declaration with type array of @code{char}, @code{signed char}, or
7632@code{unsigned char}, or pointer to such a type is intended to store
7633character arrays that do not necessarily contain a terminating @code{NUL}.
7634This is useful in detecting uses of such arrays or pointers with functions
7635that expect @code{NUL}-terminated strings, and to avoid warnings when such
7636an array or pointer is used as an argument to a bounded string manipulation
7637function such as @code{strncpy}. For example, without the attribute, GCC
7638will issue a warning for the @code{strncpy} call below because it may
7639truncate the copy without appending the terminating @code{NUL} character.
7640Using the attribute makes it possible to suppress the warning. However,
7641when the array is declared with the attribute the call to @code{strlen} is
7642diagnosed because when the array doesn't contain a @code{NUL}-terminated
7643string the call is undefined. To copy, compare, of search non-string
7644character arrays use the @code{memcpy}, @code{memcmp}, @code{memchr},
7645and other functions that operate on arrays of bytes. In addition,
7646calling @code{strnlen} and @code{strndup} with such arrays is safe
7647provided a suitable bound is specified, and not diagnosed.
7648
7649@smallexample
7650struct Data
7651@{
7652 char name [32] __attribute__ ((nonstring));
7653@};
7654
7655int f (struct Data *pd, const char *s)
7656@{
7657 strncpy (pd->name, s, sizeof pd->name);
7658 @dots{}
7659 return strlen (pd->name); // unsafe, gets a warning
7660@}
7661@end smallexample
7662
d77de738 7663@cindex @code{packed} variable attribute
f33d7a88 7664@item packed
d77de738
ML
7665The @code{packed} attribute specifies that a structure member should have
7666the smallest possible alignment---one bit for a bit-field and one byte
7667otherwise, unless a larger value is specified with the @code{aligned}
7668attribute. The attribute does not apply to non-member objects.
7669
7670For example in the structure below, the member array @code{x} is packed
7671so that it immediately follows @code{a} with no intervening padding:
7672
7673@smallexample
7674struct foo
7675@{
7676 char a;
7677 int x[2] __attribute__ ((packed));
7678@};
7679@end smallexample
7680
7681@emph{Note:} The 4.1, 4.2 and 4.3 series of GCC ignore the
7682@code{packed} attribute on bit-fields of type @code{char}. This has
7683been fixed in GCC 4.4 but the change can lead to differences in the
7684structure layout. See the documentation of
7685@option{-Wpacked-bitfield-compat} for more information.
7686
d77de738 7687@cindex @code{section} variable attribute
f33d7a88 7688@item section ("@var{section-name}")
d77de738
ML
7689Normally, the compiler places the objects it generates in sections like
7690@code{data} and @code{bss}. Sometimes, however, you need additional sections,
7691or you need certain particular variables to appear in special sections,
7692for example to map to special hardware. The @code{section}
7693attribute specifies that a variable (or function) lives in a particular
7694section. For example, this small program uses several specific section names:
7695
7696@smallexample
7697struct duart a __attribute__ ((section ("DUART_A"))) = @{ 0 @};
7698struct duart b __attribute__ ((section ("DUART_B"))) = @{ 0 @};
7699char stack[10000] __attribute__ ((section ("STACK"))) = @{ 0 @};
7700int init_data __attribute__ ((section ("INITDATA")));
7701
7702main()
7703@{
7704 /* @r{Initialize stack pointer} */
7705 init_sp (stack + sizeof (stack));
7706
7707 /* @r{Initialize initialized data} */
7708 memcpy (&init_data, &data, &edata - &data);
7709
7710 /* @r{Turn on the serial ports} */
7711 init_duart (&a);
7712 init_duart (&b);
7713@}
7714@end smallexample
7715
7716@noindent
7717Use the @code{section} attribute with
7718@emph{global} variables and not @emph{local} variables,
7719as shown in the example.
7720
7721You may use the @code{section} attribute with initialized or
7722uninitialized global variables but the linker requires
7723each object be defined once, with the exception that uninitialized
7724variables tentatively go in the @code{common} (or @code{bss}) section
7725and can be multiply ``defined''. Using the @code{section} attribute
7726changes what section the variable goes into and may cause the
7727linker to issue an error if an uninitialized variable has multiple
7728definitions. You can force a variable to be initialized with the
7729@option{-fno-common} flag or the @code{nocommon} attribute.
7730
7731Some file formats do not support arbitrary sections so the @code{section}
7732attribute is not available on all platforms.
7733If you need to map the entire contents of a module to a particular
7734section, consider using the facilities of the linker instead.
7735
d77de738 7736@cindex @code{tls_model} variable attribute
f33d7a88 7737@item tls_model ("@var{tls_model}")
d77de738
ML
7738The @code{tls_model} attribute sets thread-local storage model
7739(@pxref{Thread-Local}) of a particular @code{__thread} variable,
7740overriding @option{-ftls-model=} command-line switch on a per-variable
7741basis.
7742The @var{tls_model} argument should be one of @code{global-dynamic},
7743@code{local-dynamic}, @code{initial-exec} or @code{local-exec}.
7744
7745Not all targets support this attribute.
7746
d77de738 7747@cindex @code{unused} variable attribute
f33d7a88 7748@item unused
d77de738
ML
7749This attribute, attached to a variable or structure field, means that
7750the variable or field is meant to be possibly unused. GCC does not
7751produce a warning for this variable or field.
7752
d77de738 7753@cindex @code{used} variable attribute
f33d7a88 7754@item used
d77de738
ML
7755This attribute, attached to a variable with static storage, means that
7756the variable must be emitted even if it appears that the variable is not
7757referenced.
7758
7759When applied to a static data member of a C++ class template, the
7760attribute also means that the member is instantiated if the
7761class itself is instantiated.
7762
d77de738 7763@cindex @code{retain} variable attribute
f33d7a88 7764@item retain
d77de738
ML
7765For ELF targets that support the GNU or FreeBSD OSABIs, this attribute
7766will save the variable from linker garbage collection. To support
7767this behavior, variables that have not been placed in specific sections
7768(e.g. by the @code{section} attribute, or the @code{-fdata-sections} option),
7769will be placed in new, unique sections.
7770
7771This additional functionality requires Binutils version 2.36 or later.
7772
d77de738 7773@cindex @code{uninitialized} variable attribute
f33d7a88 7774@item uninitialized
d77de738
ML
7775This attribute, attached to a variable with automatic storage, means that
7776the variable should not be automatically initialized by the compiler when
7777the option @code{-ftrivial-auto-var-init} presents.
7778
7779With the option @code{-ftrivial-auto-var-init}, all the automatic variables
7780that do not have explicit initializers will be initialized by the compiler.
7781These additional compiler initializations might incur run-time overhead,
7782sometimes dramatically. This attribute can be used to mark some variables
7783to be excluded from such automatical initialization in order to reduce runtime
7784overhead.
7785
7786This attribute has no effect when the option @code{-ftrivial-auto-var-init}
7787does not present.
7788
d77de738 7789@cindex @code{vector_size} variable attribute
f33d7a88 7790@item vector_size (@var{bytes})
d77de738
ML
7791This attribute specifies the vector size for the type of the declared
7792variable, measured in bytes. The type to which it applies is known as
7793the @dfn{base type}. The @var{bytes} argument must be a positive
7794power-of-two multiple of the base type size. For example, the declaration:
7795
7796@smallexample
7797int foo __attribute__ ((vector_size (16)));
7798@end smallexample
7799
7800@noindent
7801causes the compiler to set the mode for @code{foo}, to be 16 bytes,
7802divided into @code{int} sized units. Assuming a 32-bit @code{int},
7803@code{foo}'s type is a vector of four units of four bytes each, and
7804the corresponding mode of @code{foo} is @code{V4SI}.
7805@xref{Vector Extensions}, for details of manipulating vector variables.
7806
7807This attribute is only applicable to integral and floating scalars,
7808although arrays, pointers, and function return values are allowed in
7809conjunction with this construct.
7810
7811Aggregates with this attribute are invalid, even if they are of the same
7812size as a corresponding scalar. For example, the declaration:
7813
7814@smallexample
7815struct S @{ int a; @};
7816struct S __attribute__ ((vector_size (16))) foo;
7817@end smallexample
7818
7819@noindent
7820is invalid even if the size of the structure is the same as the size of
7821the @code{int}.
7822
d77de738 7823@cindex @code{visibility} variable attribute
f33d7a88 7824@item visibility ("@var{visibility_type}")
d77de738
ML
7825This attribute affects the linkage of the declaration to which it is attached.
7826The @code{visibility} attribute is described in
7827@ref{Common Function Attributes}.
7828
d77de738 7829@cindex @code{weak} variable attribute
f33d7a88 7830@item weak
d77de738
ML
7831The @code{weak} attribute is described in
7832@ref{Common Function Attributes}.
7833
d77de738 7834@cindex @code{noinit} variable attribute
f33d7a88 7835@item noinit
d77de738
ML
7836Any data with the @code{noinit} attribute will not be initialized by
7837the C runtime startup code, or the program loader. Not initializing
7838data in this way can reduce program startup times.
7839
7840This attribute is specific to ELF targets and relies on the linker
7841script to place sections with the @code{.noinit} prefix in the right
7842location.
7843
d77de738 7844@cindex @code{persistent} variable attribute
f33d7a88 7845@item persistent
d77de738
ML
7846Any data with the @code{persistent} attribute will not be initialized by
7847the C runtime startup code, but will be initialized by the program
7848loader. This enables the value of the variable to @samp{persist}
7849between processor resets.
7850
7851This attribute is specific to ELF targets and relies on the linker
7852script to place the sections with the @code{.persistent} prefix in the
7853right location. Specifically, some type of non-volatile, writeable
7854memory is required.
7855
d77de738 7856@cindex @code{objc_nullability} variable attribute
f33d7a88 7857@item objc_nullability (@var{nullability kind}) @r{(Objective-C and Objective-C++ only)}
d77de738
ML
7858This attribute applies to pointer variables only. It allows marking the
7859pointer with one of four possible values describing the conditions under
7860which the pointer might have a @code{nil} value. In most cases, the
7861attribute is intended to be an internal representation for property and
7862method nullability (specified by language keywords); it is not recommended
7863to use it directly.
7864
7865When @var{nullability kind} is @code{"unspecified"} or @code{0}, nothing is
7866known about the conditions in which the pointer might be @code{nil}. Making
7867this state specific serves to avoid false positives in diagnostics.
7868
7869When @var{nullability kind} is @code{"nonnull"} or @code{1}, the pointer has
7870no meaning if it is @code{nil} and thus the compiler is free to emit
7871diagnostics if it can be determined that the value will be @code{nil}.
7872
7873When @var{nullability kind} is @code{"nullable"} or @code{2}, the pointer might
7874be @code{nil} and carry meaning as such.
7875
7876When @var{nullability kind} is @code{"resettable"} or @code{3} (used only in
7877the context of property attribute lists) this describes the case in which a
7878property setter may take the value @code{nil} (which perhaps causes the
7879property to be reset in some manner to a default) but for which the property
7880getter will never validly return @code{nil}.
7881
7882@end table
7883
7884@node ARC Variable Attributes
7885@subsection ARC Variable Attributes
7886
7887@table @code
d77de738 7888@cindex @code{aux} variable attribute, ARC
f33d7a88 7889@item aux
d77de738
ML
7890The @code{aux} attribute is used to directly access the ARC's
7891auxiliary register space from C. The auxilirary register number is
7892given via attribute argument.
7893
7894@end table
7895
7896@node AVR Variable Attributes
7897@subsection AVR Variable Attributes
7898
7899@table @code
d77de738 7900@cindex @code{progmem} variable attribute, AVR
f33d7a88 7901@item progmem
d77de738
ML
7902The @code{progmem} attribute is used on the AVR to place read-only
7903data in the non-volatile program memory (flash). The @code{progmem}
7904attribute accomplishes this by putting respective variables into a
7905section whose name starts with @code{.progmem}.
7906
7907This attribute works similar to the @code{section} attribute
7908but adds additional checking.
7909
7910@table @asis
7911@item @bullet{} Ordinary AVR cores with 32 general purpose registers:
7912@code{progmem} affects the location
7913of the data but not how this data is accessed.
7914In order to read data located with the @code{progmem} attribute
7915(inline) assembler must be used.
7916@smallexample
1be72408 7917/* Use custom macros from AVR-LibC */
d77de738
ML
7918#include <avr/pgmspace.h>
7919
7920/* Locate var in flash memory */
7921const int var[2] PROGMEM = @{ 1, 2 @};
7922
7923int read_var (int i)
7924@{
7925 /* Access var[] by accessor macro from avr/pgmspace.h */
7926 return (int) pgm_read_word (& var[i]);
7927@}
7928@end smallexample
7929
7930AVR is a Harvard architecture processor and data and read-only data
7931normally resides in the data memory (RAM).
7932
7933See also the @ref{AVR Named Address Spaces} section for
7934an alternate way to locate and access data in flash memory.
7935
7936@item @bullet{} AVR cores with flash memory visible in the RAM address range:
7937On such devices, there is no need for attribute @code{progmem} or
7938@ref{AVR Named Address Spaces,,@code{__flash}} qualifier at all.
7939Just use standard C / C++. The compiler will generate @code{LD*}
7940instructions. As flash memory is visible in the RAM address range,
7941and the default linker script does @emph{not} locate @code{.rodata} in
7942RAM, no special features are needed in order not to waste RAM for
7943read-only data or to read from flash. You might even get slightly better
7944performance by
7945avoiding @code{progmem} and @code{__flash}. This applies to devices from
7946families @code{avrtiny} and @code{avrxmega3}, see @ref{AVR Options} for
7947an overview.
7948
7949@item @bullet{} Reduced AVR Tiny cores like ATtiny40:
7950The compiler adds @code{0x4000}
7951to the addresses of objects and declarations in @code{progmem} and locates
7952the objects in flash memory, namely in section @code{.progmem.data}.
7953The offset is needed because the flash memory is visible in the RAM
7954address space starting at address @code{0x4000}.
7955
7956Data in @code{progmem} can be accessed by means of ordinary C@tie{}code,
7957no special functions or macros are needed.
7958
7959@smallexample
7960/* var is located in flash memory */
7961extern const int var[2] __attribute__((progmem));
7962
7963int read_var (int i)
7964@{
7965 return var[i];
7966@}
7967@end smallexample
7968
7969Please notice that on these devices, there is no need for @code{progmem}
7970at all.
7971
7972@end table
7973
f33d7a88 7974@cindex @code{io} variable attribute, AVR
d77de738
ML
7975@item io
7976@itemx io (@var{addr})
d77de738
ML
7977Variables with the @code{io} attribute are used to address
7978memory-mapped peripherals in the io address range.
7979If an address is specified, the variable
7980is assigned that address, and the value is interpreted as an
7981address in the data address space.
7982Example:
7983
7984@smallexample
7985volatile int porta __attribute__((io (0x22)));
7986@end smallexample
7987
7988The address specified in the address in the data address range.
7989
7990Otherwise, the variable it is not assigned an address, but the
7991compiler will still use in/out instructions where applicable,
7992assuming some other module assigns an address in the io address range.
7993Example:
7994
7995@smallexample
7996extern volatile int porta __attribute__((io));
7997@end smallexample
7998
f33d7a88 7999@cindex @code{io_low} variable attribute, AVR
d77de738
ML
8000@item io_low
8001@itemx io_low (@var{addr})
d77de738
ML
8002This is like the @code{io} attribute, but additionally it informs the
8003compiler that the object lies in the lower half of the I/O area,
8004allowing the use of @code{cbi}, @code{sbi}, @code{sbic} and @code{sbis}
8005instructions.
8006
f33d7a88 8007@cindex @code{address} variable attribute, AVR
d77de738
ML
8008@item address
8009@itemx address (@var{addr})
d77de738
ML
8010Variables with the @code{address} attribute are used to address
8011memory-mapped peripherals that may lie outside the io address range.
8012
8013@smallexample
8014volatile int porta __attribute__((address (0x600)));
8015@end smallexample
8016
d77de738 8017@cindex @code{absdata} variable attribute, AVR
f33d7a88 8018@item absdata
d77de738
ML
8019Variables in static storage and with the @code{absdata} attribute can
8020be accessed by the @code{LDS} and @code{STS} instructions which take
8021absolute addresses.
8022
8023@itemize @bullet
8024@item
8025This attribute is only supported for the reduced AVR Tiny core
8026like ATtiny40.
8027
8028@item
8029You must make sure that respective data is located in the
8030address range @code{0x40}@dots{}@code{0xbf} accessible by
8031@code{LDS} and @code{STS}. One way to achieve this as an
8032appropriate linker description file.
8033
8034@item
8035If the location does not fit the address range of @code{LDS}
8036and @code{STS}, there is currently (Binutils 2.26) just an unspecific
8037warning like
8038@quotation
8039@code{module.cc:(.text+0x1c): warning: internal error: out of range error}
8040@end quotation
8041
8042@end itemize
8043
8044See also the @option{-mabsdata} @ref{AVR Options,command-line option}.
8045
8046@end table
8047
8048@node Blackfin Variable Attributes
8049@subsection Blackfin Variable Attributes
8050
8051Three attributes are currently defined for the Blackfin.
8052
8053@table @code
d77de738
ML
8054@cindex @code{l1_data} variable attribute, Blackfin
8055@cindex @code{l1_data_A} variable attribute, Blackfin
8056@cindex @code{l1_data_B} variable attribute, Blackfin
f33d7a88
AA
8057@item l1_data
8058@itemx l1_data_A
8059@itemx l1_data_B
d77de738
ML
8060Use these attributes on the Blackfin to place the variable into L1 Data SRAM.
8061Variables with @code{l1_data} attribute are put into the specific section
8062named @code{.l1.data}. Those with @code{l1_data_A} attribute are put into
8063the specific section named @code{.l1.data.A}. Those with @code{l1_data_B}
8064attribute are put into the specific section named @code{.l1.data.B}.
8065
d77de738 8066@cindex @code{l2} variable attribute, Blackfin
f33d7a88 8067@item l2
d77de738
ML
8068Use this attribute on the Blackfin to place the variable into L2 SRAM.
8069Variables with @code{l2} attribute are put into the specific section
8070named @code{.l2.data}.
8071@end table
8072
8073@node H8/300 Variable Attributes
8074@subsection H8/300 Variable Attributes
8075
8076These variable attributes are available for H8/300 targets:
8077
8078@table @code
d77de738
ML
8079@cindex @code{eightbit_data} variable attribute, H8/300
8080@cindex eight-bit data on the H8/300, H8/300H, and H8S
f33d7a88 8081@item eightbit_data
d77de738
ML
8082Use this attribute on the H8/300, H8/300H, and H8S to indicate that the specified
8083variable should be placed into the eight-bit data section.
8084The compiler generates more efficient code for certain operations
8085on data in the eight-bit data area. Note the eight-bit data area is limited to
8086256 bytes of data.
8087
8088You must use GAS and GLD from GNU binutils version 2.7 or later for
8089this attribute to work correctly.
8090
d77de738
ML
8091@cindex @code{tiny_data} variable attribute, H8/300
8092@cindex tiny data section on the H8/300H and H8S
f33d7a88 8093@item tiny_data
d77de738
ML
8094Use this attribute on the H8/300H and H8S to indicate that the specified
8095variable should be placed into the tiny data section.
8096The compiler generates more efficient code for loads and stores
8097on data in the tiny data section. Note the tiny data area is limited to
8098slightly under 32KB of data.
8099
8100@end table
8101
8102@node IA-64 Variable Attributes
8103@subsection IA-64 Variable Attributes
8104
8105The IA-64 back end supports the following variable attribute:
8106
8107@table @code
d77de738 8108@cindex @code{model} variable attribute, IA-64
f33d7a88 8109@item model (@var{model-name})
d77de738
ML
8110
8111On IA-64, use this attribute to set the addressability of an object.
8112At present, the only supported identifier for @var{model-name} is
8113@code{small}, indicating addressability via ``small'' (22-bit)
8114addresses (so that their addresses can be loaded with the @code{addl}
8115instruction). Caveat: such addressing is by definition not position
8116independent and hence this attribute must not be used for objects
8117defined by shared libraries.
8118
8119@end table
8120
8121@node LoongArch Variable Attributes
8122@subsection LoongArch Variable Attributes
8123
8124One attribute is currently defined for the LoongArch.
8125
8126@table @code
d77de738 8127@cindex @code{model} variable attribute, LoongArch
f33d7a88 8128@item model("@var{name}")
d77de738
ML
8129Use this attribute on the LoongArch to use a different code model for
8130addressing this variable, than the code model specified by the global
8131@option{-mcmodel} option. This attribute is mostly useful if a
8132@code{section} attribute and/or a linker script will locate this object
8133specially. Currently the only supported values of @var{name} are
8134@code{normal} and @code{extreme}.
8135@end table
8136
8137@node M32R/D Variable Attributes
8138@subsection M32R/D Variable Attributes
8139
8140One attribute is currently defined for the M32R/D@.
8141
8142@table @code
d77de738
ML
8143@cindex @code{model-name} variable attribute, M32R/D
8144@cindex variable addressability on the M32R/D
f33d7a88 8145@item model (@var{model-name})
d77de738
ML
8146Use this attribute on the M32R/D to set the addressability of an object.
8147The identifier @var{model-name} is one of @code{small}, @code{medium},
8148or @code{large}, representing each of the code models.
8149
8150Small model objects live in the lower 16MB of memory (so that their
8151addresses can be loaded with the @code{ld24} instruction).
8152
8153Medium and large model objects may live anywhere in the 32-bit address space
8154(the compiler generates @code{seth/add3} instructions to load their
8155addresses).
8156@end table
8157
d77de738
ML
8158@node Microsoft Windows Variable Attributes
8159@subsection Microsoft Windows Variable Attributes
8160
8161You can use these attributes on Microsoft Windows targets.
8162@ref{x86 Variable Attributes} for additional Windows compatibility
8163attributes available on all x86 targets.
8164
8165@table @code
d77de738
ML
8166@cindex @code{dllimport} variable attribute
8167@cindex @code{dllexport} variable attribute
f33d7a88
AA
8168@item dllimport
8169@itemx dllexport
d77de738
ML
8170The @code{dllimport} and @code{dllexport} attributes are described in
8171@ref{Microsoft Windows Function Attributes}.
8172
d77de738 8173@cindex @code{selectany} variable attribute
f33d7a88 8174@item selectany
d77de738
ML
8175The @code{selectany} attribute causes an initialized global variable to
8176have link-once semantics. When multiple definitions of the variable are
8177encountered by the linker, the first is selected and the remainder are
8178discarded. Following usage by the Microsoft compiler, the linker is told
8179@emph{not} to warn about size or content differences of the multiple
8180definitions.
8181
8182Although the primary usage of this attribute is for POD types, the
8183attribute can also be applied to global C++ objects that are initialized
8184by a constructor. In this case, the static initialization and destruction
8185code for the object is emitted in each translation defining the object,
8186but the calls to the constructor and destructor are protected by a
8187link-once guard variable.
8188
8189The @code{selectany} attribute is only available on Microsoft Windows
8190targets. You can use @code{__declspec (selectany)} as a synonym for
8191@code{__attribute__ ((selectany))} for compatibility with other
8192compilers.
8193
d77de738 8194@cindex @code{shared} variable attribute
f33d7a88 8195@item shared
d77de738
ML
8196On Microsoft Windows, in addition to putting variable definitions in a named
8197section, the section can also be shared among all running copies of an
8198executable or DLL@. For example, this small program defines shared data
8199by putting it in a named section @code{shared} and marking the section
8200shareable:
8201
8202@smallexample
8203int foo __attribute__((section ("shared"), shared)) = 0;
8204
8205int
8206main()
8207@{
8208 /* @r{Read and write foo. All running
8209 copies see the same value.} */
8210 return 0;
8211@}
8212@end smallexample
8213
8214@noindent
8215You may only use the @code{shared} attribute along with @code{section}
8216attribute with a fully-initialized global definition because of the way
8217linkers work. See @code{section} attribute for more information.
8218
8219The @code{shared} attribute is only available on Microsoft Windows@.
8220
8221@end table
8222
8223@node MSP430 Variable Attributes
8224@subsection MSP430 Variable Attributes
8225
8226@table @code
d77de738
ML
8227@cindex @code{upper} variable attribute, MSP430
8228@cindex @code{either} variable attribute, MSP430
f33d7a88
AA
8229@item upper
8230@itemx either
d77de738
ML
8231These attributes are the same as the MSP430 function attributes of the
8232same name (@pxref{MSP430 Function Attributes}).
8233
d77de738 8234@cindex @code{lower} variable attribute, MSP430
f33d7a88 8235@item lower
d77de738
ML
8236This option behaves mostly the same as the MSP430 function attribute of the
8237same name (@pxref{MSP430 Function Attributes}), but it has some additional
8238functionality.
8239
8240If @option{-mdata-region=}@{@code{upper,either,none}@} has been passed, or
8241the @code{section} attribute is applied to a variable, the compiler will
8242generate 430X instructions to handle it. This is because the compiler has
8243to assume that the variable could get placed in the upper memory region
8244(above address 0xFFFF). Marking the variable with the @code{lower} attribute
8245informs the compiler that the variable will be placed in lower memory so it
8246is safe to use 430 instructions to handle it.
8247
8248In the case of the @code{section} attribute, the section name given
8249will be used, and the @code{.lower} prefix will not be added.
8250
8251@end table
8252
8253@node Nvidia PTX Variable Attributes
8254@subsection Nvidia PTX Variable Attributes
8255
8256These variable attributes are supported by the Nvidia PTX back end:
8257
8258@table @code
d77de738 8259@cindex @code{shared} attribute, Nvidia PTX
f33d7a88 8260@item shared
d77de738
ML
8261Use this attribute to place a variable in the @code{.shared} memory space.
8262This memory space is private to each cooperative thread array; only threads
8263within one thread block refer to the same instance of the variable.
8264The runtime does not initialize variables in this memory space.
8265@end table
8266
8267@node PowerPC Variable Attributes
8268@subsection PowerPC Variable Attributes
8269
8270Three attributes currently are defined for PowerPC configurations:
8271@code{altivec}, @code{ms_struct} and @code{gcc_struct}.
8272
8273@cindex @code{ms_struct} variable attribute, PowerPC
8274@cindex @code{gcc_struct} variable attribute, PowerPC
8275For full documentation of the struct attributes please see the
8276documentation in @ref{x86 Variable Attributes}.
8277
8278@cindex @code{altivec} variable attribute, PowerPC
8279For documentation of @code{altivec} attribute please see the
8280documentation in @ref{PowerPC Type Attributes}.
8281
8282@node RL78 Variable Attributes
8283@subsection RL78 Variable Attributes
8284
8285@cindex @code{saddr} variable attribute, RL78
8286The RL78 back end supports the @code{saddr} variable attribute. This
8287specifies placement of the corresponding variable in the SADDR area,
8288which can be accessed more efficiently than the default memory region.
8289
8290@node V850 Variable Attributes
8291@subsection V850 Variable Attributes
8292
8293These variable attributes are supported by the V850 back end:
8294
8295@table @code
8296
d77de738 8297@cindex @code{sda} variable attribute, V850
f33d7a88 8298@item sda
d77de738
ML
8299Use this attribute to explicitly place a variable in the small data area,
8300which can hold up to 64 kilobytes.
8301
d77de738 8302@cindex @code{tda} variable attribute, V850
f33d7a88 8303@item tda
d77de738
ML
8304Use this attribute to explicitly place a variable in the tiny data area,
8305which can hold up to 256 bytes in total.
8306
d77de738 8307@cindex @code{zda} variable attribute, V850
f33d7a88 8308@item zda
d77de738
ML
8309Use this attribute to explicitly place a variable in the first 32 kilobytes
8310of memory.
8311@end table
8312
8313@node x86 Variable Attributes
8314@subsection x86 Variable Attributes
8315
8316Two attributes are currently defined for x86 configurations:
8317@code{ms_struct} and @code{gcc_struct}.
8318
8319@table @code
d77de738
ML
8320@cindex @code{ms_struct} variable attribute, x86
8321@cindex @code{gcc_struct} variable attribute, x86
f33d7a88
AA
8322@item ms_struct
8323@itemx gcc_struct
d77de738
ML
8324
8325If @code{packed} is used on a structure, or if bit-fields are used,
8326it may be that the Microsoft ABI lays out the structure differently
8327than the way GCC normally does. Particularly when moving packed
8328data between functions compiled with GCC and the native Microsoft compiler
8329(either via function call or as data in a file), it may be necessary to access
8330either format.
8331
8332The @code{ms_struct} and @code{gcc_struct} attributes correspond
8333to the @option{-mms-bitfields} and @option{-mno-ms-bitfields}
8334command-line options, respectively;
8335see @ref{x86 Options}, for details of how structure layout is affected.
8336@xref{x86 Type Attributes}, for information about the corresponding
8337attributes on types.
8338
8339@end table
8340
8341@node Xstormy16 Variable Attributes
8342@subsection Xstormy16 Variable Attributes
8343
8344One attribute is currently defined for xstormy16 configurations:
8345@code{below100}.
8346
8347@table @code
d77de738 8348@cindex @code{below100} variable attribute, Xstormy16
f33d7a88 8349@item below100
d77de738
ML
8350
8351If a variable has the @code{below100} attribute (@code{BELOW100} is
8352allowed also), GCC places the variable in the first 0x100 bytes of
8353memory and use special opcodes to access it. Such variables are
8354placed in either the @code{.bss_below100} section or the
8355@code{.data_below100} section.
8356
8357@end table
8358
8359@node Type Attributes
8360@section Specifying Attributes of Types
8361@cindex attribute of types
8362@cindex type attributes
8363
8364The keyword @code{__attribute__} allows you to specify various special
8365properties of types. Some type attributes apply only to structure and
8366union types, and in C++, also class types, while others can apply to
8367any type defined via a @code{typedef} declaration. Unless otherwise
8368specified, the same restrictions and effects apply to attributes regardless
8369of whether a type is a trivial structure or a C++ class with user-defined
8370constructors, destructors, or a copy assignment.
8371
8372Other attributes are defined for functions (@pxref{Function Attributes}),
8373labels (@pxref{Label Attributes}), enumerators (@pxref{Enumerator
8374Attributes}), statements (@pxref{Statement Attributes}), and for variables
8375(@pxref{Variable Attributes}).
8376
8377The @code{__attribute__} keyword is followed by an attribute specification
8378enclosed in double parentheses.
8379
8380You may specify type attributes in an enum, struct or union type
8381declaration or definition by placing them immediately after the
8382@code{struct}, @code{union} or @code{enum} keyword. You can also place
8383them just past the closing curly brace of the definition, but this is less
8384preferred because logically the type should be fully defined at
8385the closing brace.
8386
8387You can also include type attributes in a @code{typedef} declaration.
8388@xref{Attribute Syntax}, for details of the exact syntax for using
8389attributes.
8390
8391@menu
8392* Common Type Attributes::
8393* ARC Type Attributes::
8394* ARM Type Attributes::
8395* BPF Type Attributes::
d77de738
ML
8396* PowerPC Type Attributes::
8397* x86 Type Attributes::
8398@end menu
8399
8400@node Common Type Attributes
8401@subsection Common Type Attributes
8402
8403The following type attributes are supported on most targets.
8404
8405@table @code
8406@cindex @code{aligned} type attribute
8407@item aligned
8408@itemx aligned (@var{alignment})
8409The @code{aligned} attribute specifies a minimum alignment (in bytes) for
8410variables of the specified type. When specified, @var{alignment} must be
8411a power of 2. Specifying no @var{alignment} argument implies the maximum
8412alignment for the target, which is often, but by no means always, 8 or 16
8413bytes. For example, the declarations:
8414
8415@smallexample
8416struct __attribute__ ((aligned (8))) S @{ short f[3]; @};
8417typedef int more_aligned_int __attribute__ ((aligned (8)));
8418@end smallexample
8419
8420@noindent
8421force the compiler to ensure (as far as it can) that each variable whose
8422type is @code{struct S} or @code{more_aligned_int} is allocated and
8423aligned @emph{at least} on a 8-byte boundary. On a SPARC, having all
8424variables of type @code{struct S} aligned to 8-byte boundaries allows
8425the compiler to use the @code{ldd} and @code{std} (doubleword load and
8426store) instructions when copying one variable of type @code{struct S} to
8427another, thus improving run-time efficiency.
8428
8429Note that the alignment of any given @code{struct} or @code{union} type
8430is required by the ISO C standard to be at least a perfect multiple of
8431the lowest common multiple of the alignments of all of the members of
8432the @code{struct} or @code{union} in question. This means that you @emph{can}
8433effectively adjust the alignment of a @code{struct} or @code{union}
8434type by attaching an @code{aligned} attribute to any one of the members
8435of such a type, but the notation illustrated in the example above is a
8436more obvious, intuitive, and readable way to request the compiler to
8437adjust the alignment of an entire @code{struct} or @code{union} type.
8438
8439As in the preceding example, you can explicitly specify the alignment
8440(in bytes) that you wish the compiler to use for a given @code{struct}
8441or @code{union} type. Alternatively, you can leave out the alignment factor
8442and just ask the compiler to align a type to the maximum
8443useful alignment for the target machine you are compiling for. For
8444example, you could write:
8445
8446@smallexample
8447struct __attribute__ ((aligned)) S @{ short f[3]; @};
8448@end smallexample
8449
8450Whenever you leave out the alignment factor in an @code{aligned}
8451attribute specification, the compiler automatically sets the alignment
8452for the type to the largest alignment that is ever used for any data
8453type on the target machine you are compiling for. Doing this can often
8454make copy operations more efficient, because the compiler can use
8455whatever instructions copy the biggest chunks of memory when performing
8456copies to or from the variables that have types that you have aligned
8457this way.
8458
8459In the example above, if the size of each @code{short} is 2 bytes, then
8460the size of the entire @code{struct S} type is 6 bytes. The smallest
8461power of two that is greater than or equal to that is 8, so the
8462compiler sets the alignment for the entire @code{struct S} type to 8
8463bytes.
8464
8465Note that although you can ask the compiler to select a time-efficient
8466alignment for a given type and then declare only individual stand-alone
8467objects of that type, the compiler's ability to select a time-efficient
8468alignment is primarily useful only when you plan to create arrays of
8469variables having the relevant (efficiently aligned) type. If you
8470declare or use arrays of variables of an efficiently-aligned type, then
8471it is likely that your program also does pointer arithmetic (or
8472subscripting, which amounts to the same thing) on pointers to the
8473relevant type, and the code that the compiler generates for these
8474pointer arithmetic operations is often more efficient for
8475efficiently-aligned types than for other types.
8476
8477Note that the effectiveness of @code{aligned} attributes may be limited
8478by inherent limitations in your linker. On many systems, the linker is
8479only able to arrange for variables to be aligned up to a certain maximum
8480alignment. (For some linkers, the maximum supported alignment may
8481be very very small.) If your linker is only able to align variables
8482up to a maximum of 8-byte alignment, then specifying @code{aligned (16)}
8483in an @code{__attribute__} still only provides you with 8-byte
8484alignment. See your linker documentation for further information.
8485
8486When used on a struct, or struct member, the @code{aligned} attribute can
8487only increase the alignment; in order to decrease it, the @code{packed}
8488attribute must be specified as well. When used as part of a typedef, the
8489@code{aligned} attribute can both increase and decrease alignment, and
8490specifying the @code{packed} attribute generates a warning.
8491
8492@cindex @code{warn_if_not_aligned} type attribute
8493@item warn_if_not_aligned (@var{alignment})
8494This attribute specifies a threshold for the structure field, measured
8495in bytes. If the structure field is aligned below the threshold, a
8496warning will be issued. For example, the declaration:
8497
8498@smallexample
8499typedef unsigned long long __u64
8500 __attribute__((aligned (4), warn_if_not_aligned (8)));
8501
8502struct foo
8503@{
8504 int i1;
8505 int i2;
8506 __u64 x;
8507@};
8508@end smallexample
8509
8510@noindent
8511causes the compiler to issue an warning on @code{struct foo}, like
8512@samp{warning: alignment 4 of 'struct foo' is less than 8}.
8513It is used to define @code{struct foo} in such a way that
8514@code{struct foo} has the same layout and the structure field @code{x}
8515has the same alignment when @code{__u64} is aligned at either 4 or
85168 bytes. Align @code{struct foo} to 8 bytes:
8517
8518@smallexample
8519struct __attribute__ ((aligned (8))) foo
8520@{
8521 int i1;
8522 int i2;
8523 __u64 x;
8524@};
8525@end smallexample
8526
8527@noindent
8528silences the warning. The compiler also issues a warning, like
8529@samp{warning: 'x' offset 12 in 'struct foo' isn't aligned to 8},
8530when the structure field has the misaligned offset:
8531
8532@smallexample
8533struct __attribute__ ((aligned (8))) foo
8534@{
8535 int i1;
8536 int i2;
8537 int i3;
8538 __u64 x;
8539@};
8540@end smallexample
8541
8542This warning can be disabled by @option{-Wno-if-not-aligned}.
8543
f33d7a88 8544@cindex @code{alloc_size} type attribute
d77de738
ML
8545@item alloc_size (@var{position})
8546@itemx alloc_size (@var{position-1}, @var{position-2})
d77de738
ML
8547The @code{alloc_size} type attribute may be applied to the definition
8548of a type of a function that returns a pointer and takes at least one
8549argument of an integer type. It indicates that the returned pointer
8550points to an object whose size is given by the function argument at
8551@var{position-1}, or by the product of the arguments at @var{position-1}
8552and @var{position-2}. Meaningful sizes are positive values less than
8553@code{PTRDIFF_MAX}. Other sizes are disagnosed when detected. GCC uses
8554this information to improve the results of @code{__builtin_object_size}.
8555
8556For instance, the following declarations
8557
8558@smallexample
8559typedef __attribute__ ((alloc_size (1, 2))) void*
8560 calloc_type (size_t, size_t);
8561typedef __attribute__ ((alloc_size (1))) void*
8562 malloc_type (size_t);
8563@end smallexample
8564
8565@noindent
8566specify that @code{calloc_type} is a type of a function that, like
8567the standard C function @code{calloc}, returns an object whose size
8568is given by the product of arguments 1 and 2, and that
8569@code{malloc_type}, like the standard C function @code{malloc},
8570returns an object whose size is given by argument 1 to the function.
8571
f33d7a88 8572@cindex @code{copy} type attribute
d77de738
ML
8573@item copy
8574@itemx copy (@var{expression})
d77de738
ML
8575The @code{copy} attribute applies the set of attributes with which
8576the type of the @var{expression} has been declared to the declaration
8577of the type to which the attribute is applied. The attribute is
8578designed for libraries that define aliases that are expected to
8579specify the same set of attributes as the aliased symbols.
8580The @code{copy} attribute can be used with types, variables, or
8581functions. However, the kind of symbol to which the attribute is
8582applied (either varible or function) must match the kind of symbol
8583to which the argument refers.
8584The @code{copy} attribute copies only syntactic and semantic attributes
8585but not attributes that affect a symbol's linkage or visibility such as
8586@code{alias}, @code{visibility}, or @code{weak}. The @code{deprecated}
8587attribute is also not copied. @xref{Common Function Attributes}.
8588@xref{Common Variable Attributes}.
8589
8590For example, suppose @code{struct A} below is defined in some third
8591party library header to have the alignment requirement @code{N} and
8592to force a warning whenever a variable of the type is not so aligned
8593due to attribute @code{packed}. Specifying the @code{copy} attribute
8594on the definition on the unrelated @code{struct B} has the effect of
8595copying all relevant attributes from the type referenced by the pointer
8596expression to @code{struct B}.
8597
8598@smallexample
8599struct __attribute__ ((aligned (N), warn_if_not_aligned (N)))
8600A @{ /* @r{@dots{}} */ @};
8601struct __attribute__ ((copy ( (struct A *)0)) B @{ /* @r{@dots{}} */ @};
8602@end smallexample
8603
f33d7a88 8604@cindex @code{deprecated} type attribute
d77de738
ML
8605@item deprecated
8606@itemx deprecated (@var{msg})
d77de738
ML
8607The @code{deprecated} attribute results in a warning if the type
8608is used anywhere in the source file. This is useful when identifying
8609types that are expected to be removed in a future version of a program.
8610If possible, the warning also includes the location of the declaration
8611of the deprecated type, to enable users to easily find further
8612information about why the type is deprecated, or what they should do
8613instead. Note that the warnings only occur for uses and then only
8614if the type is being applied to an identifier that itself is not being
8615declared as deprecated.
8616
8617@smallexample
8618typedef int T1 __attribute__ ((deprecated));
8619T1 x;
8620typedef T1 T2;
8621T2 y;
8622typedef T1 T3 __attribute__ ((deprecated));
8623T3 z __attribute__ ((deprecated));
8624@end smallexample
8625
8626@noindent
8627results in a warning on line 2 and 3 but not lines 4, 5, or 6. No
8628warning is issued for line 4 because T2 is not explicitly
8629deprecated. Line 5 has no warning because T3 is explicitly
8630deprecated. Similarly for line 6. The optional @var{msg}
8631argument, which must be a string, is printed in the warning if
8632present. Control characters in the string will be replaced with
8633escape sequences, and if the @option{-fmessage-length} option is set
8634to 0 (its default value) then any newline characters will be ignored.
8635
8636The @code{deprecated} attribute can also be used for functions and
8637variables (@pxref{Function Attributes}, @pxref{Variable Attributes}.)
8638
8639The message attached to the attribute is affected by the setting of
8640the @option{-fmessage-length} option.
8641
f33d7a88 8642@cindex @code{unavailable} type attribute
d77de738
ML
8643@item unavailable
8644@itemx unavailable (@var{msg})
d77de738
ML
8645The @code{unavailable} attribute behaves in the same manner as the
8646@code{deprecated} one, but emits an error rather than a warning. It is
8647used to indicate that a (perhaps previously @code{deprecated}) type is
8648no longer usable.
8649
8650The @code{unavailable} attribute can also be used for functions and
8651variables (@pxref{Function Attributes}, @pxref{Variable Attributes}.)
8652
d77de738 8653@cindex @code{designated_init} type attribute
f33d7a88 8654@item designated_init
d77de738
ML
8655This attribute may only be applied to structure types. It indicates
8656that any initialization of an object of this type must use designated
8657initializers rather than positional initializers. The intent of this
8658attribute is to allow the programmer to indicate that a structure's
8659layout may change, and that therefore relying on positional
8660initialization will result in future breakage.
8661
8662GCC emits warnings based on this attribute by default; use
8663@option{-Wno-designated-init} to suppress them.
8664
d77de738 8665@cindex @code{may_alias} type attribute
f33d7a88 8666@item may_alias
d77de738
ML
8667Accesses through pointers to types with this attribute are not subject
8668to type-based alias analysis, but are instead assumed to be able to alias
8669any other type of objects.
8670In the context of section 6.5 paragraph 7 of the C99 standard,
8671an lvalue expression
8672dereferencing such a pointer is treated like having a character type.
8673See @option{-fstrict-aliasing} for more information on aliasing issues.
8674This extension exists to support some vector APIs, in which pointers to
8675one vector type are permitted to alias pointers to a different vector type.
8676
8677Note that an object of a type with this attribute does not have any
8678special semantics.
8679
8680Example of use:
8681
8682@smallexample
8683typedef short __attribute__ ((__may_alias__)) short_a;
8684
8685int
8686main (void)
8687@{
8688 int a = 0x12345678;
8689 short_a *b = (short_a *) &a;
8690
8691 b[1] = 0;
8692
8693 if (a == 0x12345678)
8694 abort();
8695
8696 exit(0);
8697@}
8698@end smallexample
8699
8700@noindent
8701If you replaced @code{short_a} with @code{short} in the variable
8702declaration, the above program would abort when compiled with
8703@option{-fstrict-aliasing}, which is on by default at @option{-O2} or
8704above.
8705
d77de738 8706@cindex @code{mode} type attribute
f33d7a88 8707@item mode (@var{mode})
d77de738
ML
8708This attribute specifies the data type for the declaration---whichever
8709type corresponds to the mode @var{mode}. This in effect lets you
8710request an integer or floating-point type according to its width.
8711
8712@xref{Machine Modes,,, gccint, GNU Compiler Collection (GCC) Internals},
8713for a list of the possible keywords for @var{mode}.
8714You may also specify a mode of @code{byte} or @code{__byte__} to
8715indicate the mode corresponding to a one-byte integer, @code{word} or
8716@code{__word__} for the mode of a one-word integer, and @code{pointer}
8717or @code{__pointer__} for the mode used to represent pointers.
8718
d77de738 8719@cindex @code{packed} type attribute
f33d7a88 8720@item packed
d77de738
ML
8721This attribute, attached to a @code{struct}, @code{union}, or C++ @code{class}
8722type definition, specifies that each of its members (other than zero-width
8723bit-fields) is placed to minimize the memory required. This is equivalent
8724to specifying the @code{packed} attribute on each of the members.
8725
8726@opindex fshort-enums
8727When attached to an @code{enum} definition, the @code{packed} attribute
8728indicates that the smallest integral type should be used.
8729Specifying the @option{-fshort-enums} flag on the command line
8730is equivalent to specifying the @code{packed}
8731attribute on all @code{enum} definitions.
8732
8733In the following example @code{struct my_packed_struct}'s members are
8734packed closely together, but the internal layout of its @code{s} member
8735is not packed---to do that, @code{struct my_unpacked_struct} needs to
8736be packed too.
8737
8738@smallexample
8739struct my_unpacked_struct
8740 @{
8741 char c;
8742 int i;
8743 @};
8744
8745struct __attribute__ ((__packed__)) my_packed_struct
8746 @{
8747 char c;
8748 int i;
8749 struct my_unpacked_struct s;
8750 @};
8751@end smallexample
8752
8753You may only specify the @code{packed} attribute on the definition
8754of an @code{enum}, @code{struct}, @code{union}, or @code{class},
8755not on a @code{typedef} that does not also define the enumerated type,
8756structure, union, or class.
8757
d77de738 8758@cindex @code{scalar_storage_order} type attribute
f33d7a88 8759@item scalar_storage_order ("@var{endianness}")
d77de738
ML
8760When attached to a @code{union} or a @code{struct}, this attribute sets
8761the storage order, aka endianness, of the scalar fields of the type, as
8762well as the array fields whose component is scalar. The supported
8763endiannesses are @code{big-endian} and @code{little-endian}. The attribute
8764has no effects on fields which are themselves a @code{union}, a @code{struct}
8765or an array whose component is a @code{union} or a @code{struct}, and it is
8766possible for these fields to have a different scalar storage order than the
8767enclosing type.
8768
8769Note that neither pointer nor vector fields are considered scalar fields in
8770this context, so the attribute has no effects on these fields.
8771
8772This attribute is supported only for targets that use a uniform default
8773scalar storage order (fortunately, most of them), i.e.@: targets that store
8774the scalars either all in big-endian or all in little-endian.
8775
8776Additional restrictions are enforced for types with the reverse scalar
8777storage order with regard to the scalar storage order of the target:
8778
8779@itemize
8780@item Taking the address of a scalar field of a @code{union} or a
8781@code{struct} with reverse scalar storage order is not permitted and yields
8782an error.
8783@item Taking the address of an array field, whose component is scalar, of
8784a @code{union} or a @code{struct} with reverse scalar storage order is
8785permitted but yields a warning, unless @option{-Wno-scalar-storage-order}
8786is specified.
8787@item Taking the address of a @code{union} or a @code{struct} with reverse
8788scalar storage order is permitted.
8789@end itemize
8790
8791These restrictions exist because the storage order attribute is lost when
8792the address of a scalar or the address of an array with scalar component is
8793taken, so storing indirectly through this address generally does not work.
8794The second case is nevertheless allowed to be able to perform a block copy
8795from or to the array.
8796
8797Moreover, the use of type punning or aliasing to toggle the storage order
8798is not supported; that is to say, if a given scalar object can be accessed
8799through distinct types that assign a different storage order to it, then the
8800behavior is undefined.
8801
d77de738 8802@cindex @code{transparent_union} type attribute
f33d7a88 8803@item transparent_union
d77de738
ML
8804
8805This attribute, attached to a @code{union} type definition, indicates
8806that any function parameter having that union type causes calls to that
8807function to be treated in a special way.
8808
8809First, the argument corresponding to a transparent union type can be of
8810any type in the union; no cast is required. Also, if the union contains
8811a pointer type, the corresponding argument can be a null pointer
8812constant or a void pointer expression; and if the union contains a void
8813pointer type, the corresponding argument can be any pointer expression.
8814If the union member type is a pointer, qualifiers like @code{const} on
8815the referenced type must be respected, just as with normal pointer
8816conversions.
8817
8818Second, the argument is passed to the function using the calling
8819conventions of the first member of the transparent union, not the calling
8820conventions of the union itself. All members of the union must have the
8821same machine representation; this is necessary for this argument passing
8822to work properly.
8823
8824Transparent unions are designed for library functions that have multiple
8825interfaces for compatibility reasons. For example, suppose the
8826@code{wait} function must accept either a value of type @code{int *} to
8827comply with POSIX, or a value of type @code{union wait *} to comply with
8828the 4.1BSD interface. If @code{wait}'s parameter were @code{void *},
8829@code{wait} would accept both kinds of arguments, but it would also
8830accept any other pointer type and this would make argument type checking
8831less useful. Instead, @code{<sys/wait.h>} might define the interface
8832as follows:
8833
8834@smallexample
8835typedef union __attribute__ ((__transparent_union__))
8836 @{
8837 int *__ip;
8838 union wait *__up;
8839 @} wait_status_ptr_t;
8840
8841pid_t wait (wait_status_ptr_t);
8842@end smallexample
8843
8844@noindent
8845This interface allows either @code{int *} or @code{union wait *}
8846arguments to be passed, using the @code{int *} calling convention.
8847The program can call @code{wait} with arguments of either type:
8848
8849@smallexample
8850int w1 () @{ int w; return wait (&w); @}
8851int w2 () @{ union wait w; return wait (&w); @}
8852@end smallexample
8853
8854@noindent
8855With this interface, @code{wait}'s implementation might look like this:
8856
8857@smallexample
8858pid_t wait (wait_status_ptr_t p)
8859@{
8860 return waitpid (-1, p.__ip, 0);
8861@}
8862@end smallexample
8863
d77de738 8864@cindex @code{unused} type attribute
f33d7a88 8865@item unused
d77de738
ML
8866When attached to a type (including a @code{union} or a @code{struct}),
8867this attribute means that variables of that type are meant to appear
8868possibly unused. GCC does not produce a warning for any variables of
8869that type, even if the variable appears to do nothing. This is often
8870the case with lock or thread classes, which are usually defined and then
8871not referenced, but contain constructors and destructors that have
8872nontrivial bookkeeping functions.
8873
d77de738 8874@cindex @code{vector_size} type attribute
f33d7a88 8875@item vector_size (@var{bytes})
d77de738
ML
8876This attribute specifies the vector size for the type, measured in bytes.
8877The type to which it applies is known as the @dfn{base type}. The @var{bytes}
8878argument must be a positive power-of-two multiple of the base type size. For
8879example, the following declarations:
8880
8881@smallexample
8882typedef __attribute__ ((vector_size (32))) int int_vec32_t ;
8883typedef __attribute__ ((vector_size (32))) int* int_vec32_ptr_t;
8884typedef __attribute__ ((vector_size (32))) int int_vec32_arr3_t[3];
8885@end smallexample
8886
8887@noindent
8888define @code{int_vec32_t} to be a 32-byte vector type composed of @code{int}
8889sized units. With @code{int} having a size of 4 bytes, the type defines
8890a vector of eight units, four bytes each. The mode of variables of type
8891@code{int_vec32_t} is @code{V8SI}. @code{int_vec32_ptr_t} is then defined
8892to be a pointer to such a vector type, and @code{int_vec32_arr3_t} to be
8893an array of three such vectors. @xref{Vector Extensions}, for details of
8894manipulating objects of vector types.
8895
8896This attribute is only applicable to integral and floating scalar types.
8897In function declarations the attribute applies to the function return
8898type.
8899
8900For example, the following:
8901@smallexample
8902__attribute__ ((vector_size (16))) float get_flt_vec16 (void);
8903@end smallexample
8904declares @code{get_flt_vec16} to be a function returning a 16-byte vector
8905with the base type @code{float}.
8906
d77de738 8907@cindex @code{visibility} type attribute
f33d7a88 8908@item visibility
d77de738
ML
8909In C++, attribute visibility (@pxref{Function Attributes}) can also be
8910applied to class, struct, union and enum types. Unlike other type
8911attributes, the attribute must appear between the initial keyword and
8912the name of the type; it cannot appear after the body of the type.
8913
8914Note that the type visibility is applied to vague linkage entities
8915associated with the class (vtable, typeinfo node, etc.). In
8916particular, if a class is thrown as an exception in one shared object
8917and caught in another, the class must have default visibility.
8918Otherwise the two shared objects are unable to use the same
8919typeinfo node and exception handling will break.
8920
d77de738 8921@cindex @code{objc_root_class} type attribute
f33d7a88 8922@item objc_root_class @r{(Objective-C and Objective-C++ only)}
d77de738
ML
8923This attribute marks a class as being a root class, and thus allows
8924the compiler to elide any warnings about a missing superclass and to
8925make additional checks for mandatory methods as needed.
8926
8927@end table
8928
8929To specify multiple attributes, separate them by commas within the
8930double parentheses: for example, @samp{__attribute__ ((aligned (16),
8931packed))}.
8932
8933@node ARC Type Attributes
8934@subsection ARC Type Attributes
8935
8936@cindex @code{uncached} type attribute, ARC
8937Declaring objects with @code{uncached} allows you to exclude
8938data-cache participation in load and store operations on those objects
8939without involving the additional semantic implications of
8940@code{volatile}. The @code{.di} instruction suffix is used for all
8941loads and stores of data declared @code{uncached}.
8942
8943@node ARM Type Attributes
8944@subsection ARM Type Attributes
8945
8946@cindex @code{notshared} type attribute, ARM
8947On those ARM targets that support @code{dllimport} (such as Symbian
8948OS), you can use the @code{notshared} attribute to indicate that the
8949virtual table and other similar data for a class should not be
8950exported from a DLL@. For example:
8951
8952@smallexample
8953class __declspec(notshared) C @{
8954public:
8955 __declspec(dllimport) C();
8956 virtual void f();
8957@}
8958
8959__declspec(dllexport)
8960C::C() @{@}
8961@end smallexample
8962
8963@noindent
8964In this code, @code{C::C} is exported from the current DLL, but the
8965virtual table for @code{C} is not exported. (You can use
8966@code{__attribute__} instead of @code{__declspec} if you prefer, but
8967most Symbian OS code uses @code{__declspec}.)
8968
8969@node BPF Type Attributes
8970@subsection BPF Type Attributes
8971
8972@cindex @code{preserve_access_index} type attribute, BPF
8973BPF Compile Once - Run Everywhere (CO-RE) support. When attached to a
8974@code{struct} or @code{union} type definition, indicates that CO-RE
8975relocation information should be generated for any access to a variable
8976of that type. The behavior is equivalent to the programmer manually
8977wrapping every such access with @code{__builtin_preserve_access_index}.
8978
8979
d77de738
ML
8980@node PowerPC Type Attributes
8981@subsection PowerPC Type Attributes
8982
8983Three attributes currently are defined for PowerPC configurations:
8984@code{altivec}, @code{ms_struct} and @code{gcc_struct}.
8985
8986@cindex @code{ms_struct} type attribute, PowerPC
8987@cindex @code{gcc_struct} type attribute, PowerPC
8988For full documentation of the @code{ms_struct} and @code{gcc_struct}
8989attributes please see the documentation in @ref{x86 Type Attributes}.
8990
8991@cindex @code{altivec} type attribute, PowerPC
8992The @code{altivec} attribute allows one to declare AltiVec vector data
8993types supported by the AltiVec Programming Interface Manual. The
8994attribute requires an argument to specify one of three vector types:
8995@code{vector__}, @code{pixel__} (always followed by unsigned short),
8996and @code{bool__} (always followed by unsigned).
8997
8998@smallexample
8999__attribute__((altivec(vector__)))
9000__attribute__((altivec(pixel__))) unsigned short
9001__attribute__((altivec(bool__))) unsigned
9002@end smallexample
9003
9004These attributes mainly are intended to support the @code{__vector},
9005@code{__pixel}, and @code{__bool} AltiVec keywords.
9006
9007@node x86 Type Attributes
9008@subsection x86 Type Attributes
9009
9010Two attributes are currently defined for x86 configurations:
9011@code{ms_struct} and @code{gcc_struct}.
9012
9013@table @code
9014
d77de738
ML
9015@cindex @code{ms_struct} type attribute, x86
9016@cindex @code{gcc_struct} type attribute, x86
f33d7a88
AA
9017@item ms_struct
9018@itemx gcc_struct
d77de738
ML
9019
9020If @code{packed} is used on a structure, or if bit-fields are used
9021it may be that the Microsoft ABI packs them differently
9022than GCC normally packs them. Particularly when moving packed
9023data between functions compiled with GCC and the native Microsoft compiler
9024(either via function call or as data in a file), it may be necessary to access
9025either format.
9026
9027The @code{ms_struct} and @code{gcc_struct} attributes correspond
9028to the @option{-mms-bitfields} and @option{-mno-ms-bitfields}
9029command-line options, respectively;
9030see @ref{x86 Options}, for details of how structure layout is affected.
9031@xref{x86 Variable Attributes}, for information about the corresponding
9032attributes on variables.
9033
9034@end table
9035
9036@node Label Attributes
9037@section Label Attributes
9038@cindex Label Attributes
9039
9040GCC allows attributes to be set on C labels. @xref{Attribute Syntax}, for
9041details of the exact syntax for using attributes. Other attributes are
9042available for functions (@pxref{Function Attributes}), variables
9043(@pxref{Variable Attributes}), enumerators (@pxref{Enumerator Attributes}),
9044statements (@pxref{Statement Attributes}), and for types
9045(@pxref{Type Attributes}). A label attribute followed
9046by a declaration appertains to the label and not the declaration.
9047
9048This example uses the @code{cold} label attribute to indicate the
9049@code{ErrorHandling} branch is unlikely to be taken and that the
9050@code{ErrorHandling} label is unused:
9051
9052@smallexample
9053
9054 asm goto ("some asm" : : : : NoError);
9055
9056/* This branch (the fall-through from the asm) is less commonly used */
9057ErrorHandling:
9058 __attribute__((cold, unused)); /* Semi-colon is required here */
9059 printf("error\n");
9060 return 0;
9061
9062NoError:
9063 printf("no error\n");
9064 return 1;
9065@end smallexample
9066
9067@table @code
d77de738 9068@cindex @code{unused} label attribute
f33d7a88 9069@item unused
d77de738
ML
9070This feature is intended for program-generated code that may contain
9071unused labels, but which is compiled with @option{-Wall}. It is
9072not normally appropriate to use in it human-written code, though it
9073could be useful in cases where the code that jumps to the label is
9074contained within an @code{#ifdef} conditional.
9075
d77de738 9076@cindex @code{hot} label attribute
f33d7a88 9077@item hot
d77de738
ML
9078The @code{hot} attribute on a label is used to inform the compiler that
9079the path following the label is more likely than paths that are not so
9080annotated. This attribute is used in cases where @code{__builtin_expect}
9081cannot be used, for instance with computed goto or @code{asm goto}.
9082
d77de738 9083@cindex @code{cold} label attribute
f33d7a88 9084@item cold
d77de738
ML
9085The @code{cold} attribute on labels is used to inform the compiler that
9086the path following the label is unlikely to be executed. This attribute
9087is used in cases where @code{__builtin_expect} cannot be used, for instance
9088with computed goto or @code{asm goto}.
9089
9090@end table
9091
9092@node Enumerator Attributes
9093@section Enumerator Attributes
9094@cindex Enumerator Attributes
9095
9096GCC allows attributes to be set on enumerators. @xref{Attribute Syntax}, for
9097details of the exact syntax for using attributes. Other attributes are
9098available for functions (@pxref{Function Attributes}), variables
9099(@pxref{Variable Attributes}), labels (@pxref{Label Attributes}), statements
9100(@pxref{Statement Attributes}), and for types (@pxref{Type Attributes}).
9101
9102This example uses the @code{deprecated} enumerator attribute to indicate the
9103@code{oldval} enumerator is deprecated:
9104
9105@smallexample
9106enum E @{
9107 oldval __attribute__((deprecated)),
9108 newval
9109@};
9110
9111int
9112fn (void)
9113@{
9114 return oldval;
9115@}
9116@end smallexample
9117
9118@table @code
d77de738 9119@cindex @code{deprecated} enumerator attribute
f33d7a88 9120@item deprecated
d77de738
ML
9121The @code{deprecated} attribute results in a warning if the enumerator
9122is used anywhere in the source file. This is useful when identifying
9123enumerators that are expected to be removed in a future version of a
9124program. The warning also includes the location of the declaration
9125of the deprecated enumerator, to enable users to easily find further
9126information about why the enumerator is deprecated, or what they should
9127do instead. Note that the warnings only occurs for uses.
9128
d77de738 9129@cindex @code{unavailable} enumerator attribute
f33d7a88 9130@item unavailable
d77de738
ML
9131The @code{unavailable} attribute results in an error if the enumerator
9132is used anywhere in the source file. In other respects it behaves in the
9133same manner as the @code{deprecated} attribute.
9134
9135@end table
9136
9137@node Statement Attributes
9138@section Statement Attributes
9139@cindex Statement Attributes
9140
9141GCC allows attributes to be set on null statements. @xref{Attribute Syntax},
9142for details of the exact syntax for using attributes. Other attributes are
9143available for functions (@pxref{Function Attributes}), variables
9144(@pxref{Variable Attributes}), labels (@pxref{Label Attributes}), enumerators
9145(@pxref{Enumerator Attributes}), and for types (@pxref{Type Attributes}).
9146
9147@table @code
d77de738 9148@cindex @code{fallthrough} statement attribute
f33d7a88 9149@item fallthrough
d77de738
ML
9150The @code{fallthrough} attribute with a null statement serves as a
9151fallthrough statement. It hints to the compiler that a statement
9152that falls through to another case label, or user-defined label
9153in a switch statement is intentional and thus the
9154@option{-Wimplicit-fallthrough} warning must not trigger. The
9155fallthrough attribute may appear at most once in each attribute
9156list, and may not be mixed with other attributes. It can only
9157be used in a switch statement (the compiler will issue an error
9158otherwise), after a preceding statement and before a logically
9159succeeding case label, or user-defined label.
9160
9161This example uses the @code{fallthrough} statement attribute to indicate that
9162the @option{-Wimplicit-fallthrough} warning should not be emitted:
9163
9164@smallexample
9165switch (cond)
9166 @{
9167 case 1:
9168 bar (1);
9169 __attribute__((fallthrough));
9170 case 2:
9171 @dots{}
9172 @}
9173@end smallexample
9174
d77de738 9175@cindex @code{assume} statement attribute
f33d7a88 9176@item assume
d77de738
ML
9177The @code{assume} attribute with a null statement serves as portable
9178assumption. It should have a single argument, a conditional expression,
9179which is not evaluated. If the argument would evaluate to true
9180at the point where it appears, it has no effect, otherwise there
9181is undefined behavior. This is a GNU variant of the ISO C++23
9182standard @code{assume} attribute, but it can be used in any version of
9183both C and C++.
9184
9185@smallexample
9186int
9187foo (int x, int y)
9188@{
9189 __attribute__((assume(x == 42)));
9190 __attribute__((assume(++y == 43)));
9191 return x + y;
9192@}
9193@end smallexample
9194
9195@code{y} is not actually incremented and the compiler can but does not
9196have to optimize it to just @code{return 42 + 42;}.
9197
9198@end table
9199
9200@node Attribute Syntax
9201@section Attribute Syntax
9202@cindex attribute syntax
9203
9204This section describes the syntax with which @code{__attribute__} may be
9205used, and the constructs to which attribute specifiers bind, for the C
9206language. Some details may vary for C++ and Objective-C@. Because of
d9922e4b 9207limitations in the grammar for attributes, some forms described here
d77de738
ML
9208may not be successfully parsed in all cases.
9209
9210There are some problems with the semantics of attributes in C++. For
9211example, there are no manglings for attributes, although they may affect
9212code generation, so problems may arise when attributed types are used in
9213conjunction with templates or overloading. Similarly, @code{typeid}
9214does not distinguish between types with different attributes. Support
9215for attributes in C++ may be restricted in future to attributes on
9216declarations only, but not on nested declarators.
9217
9218@xref{Function Attributes}, for details of the semantics of attributes
9219applying to functions. @xref{Variable Attributes}, for details of the
9220semantics of attributes applying to variables. @xref{Type Attributes},
9221for details of the semantics of attributes applying to structure, union
9222and enumerated types.
9223@xref{Label Attributes}, for details of the semantics of attributes
9224applying to labels.
9225@xref{Enumerator Attributes}, for details of the semantics of attributes
9226applying to enumerators.
9227@xref{Statement Attributes}, for details of the semantics of attributes
9228applying to statements.
9229
9230An @dfn{attribute specifier} is of the form
9231@code{__attribute__ ((@var{attribute-list}))}. An @dfn{attribute list}
9232is a possibly empty comma-separated sequence of @dfn{attributes}, where
9233each attribute is one of the following:
9234
9235@itemize @bullet
9236@item
9237Empty. Empty attributes are ignored.
9238
9239@item
9240An attribute name
9241(which may be an identifier such as @code{unused}, or a reserved
9242word such as @code{const}).
9243
9244@item
9245An attribute name followed by a parenthesized list of
9246parameters for the attribute.
9247These parameters take one of the following forms:
9248
9249@itemize @bullet
9250@item
9251An identifier. For example, @code{mode} attributes use this form.
9252
9253@item
9254An identifier followed by a comma and a non-empty comma-separated list
9255of expressions. For example, @code{format} attributes use this form.
9256
9257@item
9258A possibly empty comma-separated list of expressions. For example,
9259@code{format_arg} attributes use this form with the list being a single
9260integer constant expression, and @code{alias} attributes use this form
9261with the list being a single string constant.
9262@end itemize
9263@end itemize
9264
9265An @dfn{attribute specifier list} is a sequence of one or more attribute
9266specifiers, not separated by any other tokens.
9267
9268You may optionally specify attribute names with @samp{__}
9269preceding and following the name.
9270This allows you to use them in header files without
9271being concerned about a possible macro of the same name. For example,
9272you may use the attribute name @code{__noreturn__} instead of @code{noreturn}.
9273
9274
9275@subsubheading Label Attributes
9276
9277In GNU C, an attribute specifier list may appear after the colon following a
9278label, other than a @code{case} or @code{default} label. GNU C++ only permits
9279attributes on labels if the attribute specifier is immediately
9280followed by a semicolon (i.e., the label applies to an empty
9281statement). If the semicolon is missing, C++ label attributes are
9282ambiguous, as it is permissible for a declaration, which could begin
9283with an attribute list, to be labelled in C++. Declarations cannot be
9284labelled in C90 or C99, so the ambiguity does not arise there.
9285
9286@subsubheading Enumerator Attributes
9287
9288In GNU C, an attribute specifier list may appear as part of an enumerator.
9289The attribute goes after the enumeration constant, before @code{=}, if
9290present. The optional attribute in the enumerator appertains to the
9291enumeration constant. It is not possible to place the attribute after
9292the constant expression, if present.
9293
9294@subsubheading Statement Attributes
9295In GNU C, an attribute specifier list may appear as part of a null
9296statement. The attribute goes before the semicolon.
9297
9298@subsubheading Type Attributes
9299
9300An attribute specifier list may appear as part of a @code{struct},
9301@code{union} or @code{enum} specifier. It may go either immediately
9302after the @code{struct}, @code{union} or @code{enum} keyword, or after
9303the closing brace. The former syntax is preferred.
9304Where attribute specifiers follow the closing brace, they are considered
9305to relate to the structure, union or enumerated type defined, not to any
9306enclosing declaration the type specifier appears in, and the type
9307defined is not complete until after the attribute specifiers.
9308@c Otherwise, there would be the following problems: a shift/reduce
9309@c conflict between attributes binding the struct/union/enum and
9310@c binding to the list of specifiers/qualifiers; and "aligned"
9311@c attributes could use sizeof for the structure, but the size could be
9312@c changed later by "packed" attributes.
9313
9314
9315@subsubheading All other attributes
9316
9317Otherwise, an attribute specifier appears as part of a declaration,
9318counting declarations of unnamed parameters and type names, and relates
9319to that declaration (which may be nested in another declaration, for
9320example in the case of a parameter declaration), or to a particular declarator
9321within a declaration. Where an
9322attribute specifier is applied to a parameter declared as a function or
9323an array, it should apply to the function or array rather than the
9324pointer to which the parameter is implicitly converted, but this is not
9325yet correctly implemented.
9326
9327Any list of specifiers and qualifiers at the start of a declaration may
9328contain attribute specifiers, whether or not such a list may in that
9329context contain storage class specifiers. (Some attributes, however,
9330are essentially in the nature of storage class specifiers, and only make
9331sense where storage class specifiers may be used; for example,
9332@code{section}.) There is one necessary limitation to this syntax: the
9333first old-style parameter declaration in a function definition cannot
9334begin with an attribute specifier, because such an attribute applies to
9335the function instead by syntax described below (which, however, is not
9336yet implemented in this case). In some other cases, attribute
9337specifiers are permitted by this grammar but not yet supported by the
9338compiler. All attribute specifiers in this place relate to the
9339declaration as a whole. In the obsolescent usage where a type of
9340@code{int} is implied by the absence of type specifiers, such a list of
9341specifiers and qualifiers may be an attribute specifier list with no
9342other specifiers or qualifiers.
9343
9344At present, the first parameter in a function prototype must have some
9345type specifier that is not an attribute specifier; this resolves an
9346ambiguity in the interpretation of @code{void f(int
9347(__attribute__((foo)) x))}, but is subject to change. At present, if
9348the parentheses of a function declarator contain only attributes then
9349those attributes are ignored, rather than yielding an error or warning
9350or implying a single parameter of type int, but this is subject to
9351change.
9352
9353An attribute specifier list may appear immediately before a declarator
9354(other than the first) in a comma-separated list of declarators in a
9355declaration of more than one identifier using a single list of
9356specifiers and qualifiers. Such attribute specifiers apply
9357only to the identifier before whose declarator they appear. For
9358example, in
9359
9360@smallexample
9361__attribute__((noreturn)) void d0 (void),
9362 __attribute__((format(printf, 1, 2))) d1 (const char *, ...),
9363 d2 (void);
9364@end smallexample
9365
9366@noindent
9367the @code{noreturn} attribute applies to all the functions
9368declared; the @code{format} attribute only applies to @code{d1}.
9369
9370An attribute specifier list may appear immediately before the comma,
9371@code{=} or semicolon terminating the declaration of an identifier other
9372than a function definition. Such attribute specifiers apply
9373to the declared object or function. Where an
9374assembler name for an object or function is specified (@pxref{Asm
9375Labels}), the attribute must follow the @code{asm}
9376specification.
9377
9378An attribute specifier list may, in future, be permitted to appear after
9379the declarator in a function definition (before any old-style parameter
9380declarations or the function body).
9381
9382Attribute specifiers may be mixed with type qualifiers appearing inside
9383the @code{[]} of a parameter array declarator, in the C99 construct by
9384which such qualifiers are applied to the pointer to which the array is
9385implicitly converted. Such attribute specifiers apply to the pointer,
9386not to the array, but at present this is not implemented and they are
9387ignored.
9388
9389An attribute specifier list may appear at the start of a nested
9390declarator. At present, there are some limitations in this usage: the
9391attributes correctly apply to the declarator, but for most individual
9392attributes the semantics this implies are not implemented.
9393When attribute specifiers follow the @code{*} of a pointer
9394declarator, they may be mixed with any type qualifiers present.
9395The following describes the formal semantics of this syntax. It makes the
9396most sense if you are familiar with the formal specification of
9397declarators in the ISO C standard.
9398
9399Consider (as in C99 subclause 6.7.5 paragraph 4) a declaration @code{T
9400D1}, where @code{T} contains declaration specifiers that specify a type
9401@var{Type} (such as @code{int}) and @code{D1} is a declarator that
9402contains an identifier @var{ident}. The type specified for @var{ident}
9403for derived declarators whose type does not include an attribute
9404specifier is as in the ISO C standard.
9405
9406If @code{D1} has the form @code{( @var{attribute-specifier-list} D )},
9407and the declaration @code{T D} specifies the type
9408``@var{derived-declarator-type-list} @var{Type}'' for @var{ident}, then
9409@code{T D1} specifies the type ``@var{derived-declarator-type-list}
9410@var{attribute-specifier-list} @var{Type}'' for @var{ident}.
9411
9412If @code{D1} has the form @code{*
9413@var{type-qualifier-and-attribute-specifier-list} D}, and the
9414declaration @code{T D} specifies the type
9415``@var{derived-declarator-type-list} @var{Type}'' for @var{ident}, then
9416@code{T D1} specifies the type ``@var{derived-declarator-type-list}
9417@var{type-qualifier-and-attribute-specifier-list} pointer to @var{Type}'' for
9418@var{ident}.
9419
9420For example,
9421
9422@smallexample
9423void (__attribute__((noreturn)) ****f) (void);
9424@end smallexample
9425
9426@noindent
9427specifies the type ``pointer to pointer to pointer to pointer to
9428non-returning function returning @code{void}''. As another example,
9429
9430@smallexample
9431char *__attribute__((aligned(8))) *f;
9432@end smallexample
9433
9434@noindent
9435specifies the type ``pointer to 8-byte-aligned pointer to @code{char}''.
9436Note again that this does not work with most attributes; for example,
9437the usage of @samp{aligned} and @samp{noreturn} attributes given above
9438is not yet supported.
9439
9440For compatibility with existing code written for compiler versions that
9441did not implement attributes on nested declarators, some laxity is
9442allowed in the placing of attributes. If an attribute that only applies
9443to types is applied to a declaration, it is treated as applying to
9444the type of that declaration. If an attribute that only applies to
9445declarations is applied to the type of a declaration, it is treated
9446as applying to that declaration; and, for compatibility with code
9447placing the attributes immediately before the identifier declared, such
9448an attribute applied to a function return type is treated as
9449applying to the function type, and such an attribute applied to an array
9450element type is treated as applying to the array type. If an
9451attribute that only applies to function types is applied to a
9452pointer-to-function type, it is treated as applying to the pointer
9453target type; if such an attribute is applied to a function return type
9454that is not a pointer-to-function type, it is treated as applying
9455to the function type.
9456
9457@node Function Prototypes
9458@section Prototypes and Old-Style Function Definitions
9459@cindex function prototype declarations
9460@cindex old-style function definitions
9461@cindex promotion of formal parameters
9462
9463GNU C extends ISO C to allow a function prototype to override a later
9464old-style non-prototype definition. Consider the following example:
9465
9466@smallexample
9467/* @r{Use prototypes unless the compiler is old-fashioned.} */
9468#ifdef __STDC__
9469#define P(x) x
9470#else
9471#define P(x) ()
9472#endif
9473
9474/* @r{Prototype function declaration.} */
9475int isroot P((uid_t));
9476
9477/* @r{Old-style function definition.} */
9478int
9479isroot (x) /* @r{??? lossage here ???} */
9480 uid_t x;
9481@{
9482 return x == 0;
9483@}
9484@end smallexample
9485
9486Suppose the type @code{uid_t} happens to be @code{short}. ISO C does
9487not allow this example, because subword arguments in old-style
9488non-prototype definitions are promoted. Therefore in this example the
9489function definition's argument is really an @code{int}, which does not
9490match the prototype argument type of @code{short}.
9491
9492This restriction of ISO C makes it hard to write code that is portable
9493to traditional C compilers, because the programmer does not know
9494whether the @code{uid_t} type is @code{short}, @code{int}, or
9495@code{long}. Therefore, in cases like these GNU C allows a prototype
9496to override a later old-style definition. More precisely, in GNU C, a
9497function prototype argument type overrides the argument type specified
9498by a later old-style definition if the former type is the same as the
9499latter type before promotion. Thus in GNU C the above example is
9500equivalent to the following:
9501
9502@smallexample
9503int isroot (uid_t);
9504
9505int
9506isroot (uid_t x)
9507@{
9508 return x == 0;
9509@}
9510@end smallexample
9511
9512@noindent
9513GNU C++ does not support old-style function definitions, so this
9514extension is irrelevant.
9515
9516@node C++ Comments
9517@section C++ Style Comments
9518@cindex @code{//}
9519@cindex C++ comments
9520@cindex comments, C++ style
9521
9522In GNU C, you may use C++ style comments, which start with @samp{//} and
9523continue until the end of the line. Many other C implementations allow
9524such comments, and they are included in the 1999 C standard. However,
9525C++ style comments are not recognized if you specify an @option{-std}
9526option specifying a version of ISO C before C99, or @option{-ansi}
9527(equivalent to @option{-std=c90}).
9528
9529@node Dollar Signs
9530@section Dollar Signs in Identifier Names
9531@cindex $
9532@cindex dollar signs in identifier names
9533@cindex identifier names, dollar signs in
9534
9535In GNU C, you may normally use dollar signs in identifier names.
9536This is because many traditional C implementations allow such identifiers.
9537However, dollar signs in identifiers are not supported on a few target
9538machines, typically because the target assembler does not allow them.
9539
9540@node Character Escapes
9541@section The Character @key{ESC} in Constants
9542
9543You can use the sequence @samp{\e} in a string or character constant to
9544stand for the ASCII character @key{ESC}.
9545
9546@node Alignment
9547@section Determining the Alignment of Functions, Types or Variables
9548@cindex alignment
9549@cindex type alignment
9550@cindex variable alignment
9551
9552The keyword @code{__alignof__} determines the alignment requirement of
9553a function, object, or a type, or the minimum alignment usually required
9554by a type. Its syntax is just like @code{sizeof} and C11 @code{_Alignof}.
9555
9556For example, if the target machine requires a @code{double} value to be
9557aligned on an 8-byte boundary, then @code{__alignof__ (double)} is 8.
9558This is true on many RISC machines. On more traditional machine
9559designs, @code{__alignof__ (double)} is 4 or even 2.
9560
9561Some machines never actually require alignment; they allow references to any
9562data type even at an odd address. For these machines, @code{__alignof__}
9563reports the smallest alignment that GCC gives the data type, usually as
9564mandated by the target ABI.
9565
9566If the operand of @code{__alignof__} is an lvalue rather than a type,
9567its value is the required alignment for its type, taking into account
9568any minimum alignment specified by attribute @code{aligned}
9569(@pxref{Common Variable Attributes}). For example, after this
9570declaration:
9571
9572@smallexample
9573struct foo @{ int x; char y; @} foo1;
9574@end smallexample
9575
9576@noindent
9577the value of @code{__alignof__ (foo1.y)} is 1, even though its actual
9578alignment is probably 2 or 4, the same as @code{__alignof__ (int)}.
9579It is an error to ask for the alignment of an incomplete type other
9580than @code{void}.
9581
9582If the operand of the @code{__alignof__} expression is a function,
9583the expression evaluates to the alignment of the function which may
9584be specified by attribute @code{aligned} (@pxref{Common Function Attributes}).
9585
9586@node Inline
9587@section An Inline Function is As Fast As a Macro
9588@cindex inline functions
9589@cindex integrating function code
9590@cindex open coding
9591@cindex macros, inline alternative
9592
9593By declaring a function inline, you can direct GCC to make
9594calls to that function faster. One way GCC can achieve this is to
9595integrate that function's code into the code for its callers. This
9596makes execution faster by eliminating the function-call overhead; in
9597addition, if any of the actual argument values are constant, their
9598known values may permit simplifications at compile time so that not
9599all of the inline function's code needs to be included. The effect on
9600code size is less predictable; object code may be larger or smaller
9601with function inlining, depending on the particular case. You can
9602also direct GCC to try to integrate all ``simple enough'' functions
9603into their callers with the option @option{-finline-functions}.
9604
9605GCC implements three different semantics of declaring a function
9606inline. One is available with @option{-std=gnu89} or
9607@option{-fgnu89-inline} or when @code{gnu_inline} attribute is present
9608on all inline declarations, another when
9609@option{-std=c99},
9610@option{-std=gnu99} or an option for a later C version is used
9611(without @option{-fgnu89-inline}), and the third
9612is used when compiling C++.
9613
9614To declare a function inline, use the @code{inline} keyword in its
9615declaration, like this:
9616
9617@smallexample
9618static inline int
9619inc (int *a)
9620@{
9621 return (*a)++;
9622@}
9623@end smallexample
9624
9625If you are writing a header file to be included in ISO C90 programs, write
9626@code{__inline__} instead of @code{inline}. @xref{Alternate Keywords}.
9627
9628The three types of inlining behave similarly in two important cases:
9629when the @code{inline} keyword is used on a @code{static} function,
9630like the example above, and when a function is first declared without
9631using the @code{inline} keyword and then is defined with
9632@code{inline}, like this:
9633
9634@smallexample
9635extern int inc (int *a);
9636inline int
9637inc (int *a)
9638@{
9639 return (*a)++;
9640@}
9641@end smallexample
9642
9643In both of these common cases, the program behaves the same as if you
9644had not used the @code{inline} keyword, except for its speed.
9645
9646@cindex inline functions, omission of
9647@opindex fkeep-inline-functions
9648When a function is both inline and @code{static}, if all calls to the
9649function are integrated into the caller, and the function's address is
9650never used, then the function's own assembler code is never referenced.
9651In this case, GCC does not actually output assembler code for the
9652function, unless you specify the option @option{-fkeep-inline-functions}.
9653If there is a nonintegrated call, then the function is compiled to
9654assembler code as usual. The function must also be compiled as usual if
9655the program refers to its address, because that cannot be inlined.
9656
9657@opindex Winline
9658Note that certain usages in a function definition can make it unsuitable
9659for inline substitution. Among these usages are: variadic functions,
9660use of @code{alloca}, use of computed goto (@pxref{Labels as Values}),
9661use of nonlocal goto, use of nested functions, use of @code{setjmp}, use
9662of @code{__builtin_longjmp} and use of @code{__builtin_return} or
9663@code{__builtin_apply_args}. Using @option{-Winline} warns when a
9664function marked @code{inline} could not be substituted, and gives the
9665reason for the failure.
9666
9667@cindex automatic @code{inline} for C++ member fns
9668@cindex @code{inline} automatic for C++ member fns
9669@cindex member fns, automatically @code{inline}
9670@cindex C++ member fns, automatically @code{inline}
9671@opindex fno-default-inline
9672As required by ISO C++, GCC considers member functions defined within
9673the body of a class to be marked inline even if they are
9674not explicitly declared with the @code{inline} keyword. You can
9675override this with @option{-fno-default-inline}; @pxref{C++ Dialect
9676Options,,Options Controlling C++ Dialect}.
9677
9678GCC does not inline any functions when not optimizing unless you specify
9679the @samp{always_inline} attribute for the function, like this:
9680
9681@smallexample
9682/* @r{Prototype.} */
9683inline void foo (const char) __attribute__((always_inline));
9684@end smallexample
9685
9686The remainder of this section is specific to GNU C90 inlining.
9687
9688@cindex non-static inline function
9689When an inline function is not @code{static}, then the compiler must assume
9690that there may be calls from other source files; since a global symbol can
9691be defined only once in any program, the function must not be defined in
9692the other source files, so the calls therein cannot be integrated.
9693Therefore, a non-@code{static} inline function is always compiled on its
9694own in the usual fashion.
9695
9696If you specify both @code{inline} and @code{extern} in the function
9697definition, then the definition is used only for inlining. In no case
9698is the function compiled on its own, not even if you refer to its
9699address explicitly. Such an address becomes an external reference, as
9700if you had only declared the function, and had not defined it.
9701
9702This combination of @code{inline} and @code{extern} has almost the
9703effect of a macro. The way to use it is to put a function definition in
9704a header file with these keywords, and put another copy of the
9705definition (lacking @code{inline} and @code{extern}) in a library file.
9706The definition in the header file causes most calls to the function
9707to be inlined. If any uses of the function remain, they refer to
9708the single copy in the library.
9709
9710@node Volatiles
9711@section When is a Volatile Object Accessed?
9712@cindex accessing volatiles
9713@cindex volatile read
9714@cindex volatile write
9715@cindex volatile access
9716
9717C has the concept of volatile objects. These are normally accessed by
9718pointers and used for accessing hardware or inter-thread
9719communication. The standard encourages compilers to refrain from
9720optimizations concerning accesses to volatile objects, but leaves it
9721implementation defined as to what constitutes a volatile access. The
9722minimum requirement is that at a sequence point all previous accesses
9723to volatile objects have stabilized and no subsequent accesses have
9724occurred. Thus an implementation is free to reorder and combine
9725volatile accesses that occur between sequence points, but cannot do
9726so for accesses across a sequence point. The use of volatile does
9727not allow you to violate the restriction on updating objects multiple
9728times between two sequence points.
9729
9730Accesses to non-volatile objects are not ordered with respect to
9731volatile accesses. You cannot use a volatile object as a memory
9732barrier to order a sequence of writes to non-volatile memory. For
9733instance:
9734
9735@smallexample
9736int *ptr = @var{something};
9737volatile int vobj;
9738*ptr = @var{something};
9739vobj = 1;
9740@end smallexample
9741
9742@noindent
9743Unless @var{*ptr} and @var{vobj} can be aliased, it is not guaranteed
9744that the write to @var{*ptr} occurs by the time the update
9745of @var{vobj} happens. If you need this guarantee, you must use
9746a stronger memory barrier such as:
9747
9748@smallexample
9749int *ptr = @var{something};
9750volatile int vobj;
9751*ptr = @var{something};
9752asm volatile ("" : : : "memory");
9753vobj = 1;
9754@end smallexample
9755
9756A scalar volatile object is read when it is accessed in a void context:
9757
9758@smallexample
9759volatile int *src = @var{somevalue};
9760*src;
9761@end smallexample
9762
9763Such expressions are rvalues, and GCC implements this as a
9764read of the volatile object being pointed to.
9765
9766Assignments are also expressions and have an rvalue. However when
9767assigning to a scalar volatile, the volatile object is not reread,
9768regardless of whether the assignment expression's rvalue is used or
9769not. If the assignment's rvalue is used, the value is that assigned
9770to the volatile object. For instance, there is no read of @var{vobj}
9771in all the following cases:
9772
9773@smallexample
9774int obj;
9775volatile int vobj;
9776vobj = @var{something};
9777obj = vobj = @var{something};
9778obj ? vobj = @var{onething} : vobj = @var{anotherthing};
9779obj = (@var{something}, vobj = @var{anotherthing});
9780@end smallexample
9781
9782If you need to read the volatile object after an assignment has
9783occurred, you must use a separate expression with an intervening
9784sequence point.
9785
9786As bit-fields are not individually addressable, volatile bit-fields may
9787be implicitly read when written to, or when adjacent bit-fields are
9788accessed. Bit-field operations may be optimized such that adjacent
9789bit-fields are only partially accessed, if they straddle a storage unit
9790boundary. For these reasons it is unwise to use volatile bit-fields to
9791access hardware.
9792
9793@node Using Assembly Language with C
9794@section How to Use Inline Assembly Language in C Code
9795@cindex @code{asm} keyword
9796@cindex assembly language in C
9797@cindex inline assembly language
9798@cindex mixing assembly language and C
9799
9800The @code{asm} keyword allows you to embed assembler instructions
9801within C code. GCC provides two forms of inline @code{asm}
9802statements. A @dfn{basic @code{asm}} statement is one with no
9803operands (@pxref{Basic Asm}), while an @dfn{extended @code{asm}}
9804statement (@pxref{Extended Asm}) includes one or more operands.
9805The extended form is preferred for mixing C and assembly language
9806within a function, but to include assembly language at
9807top level you must use basic @code{asm}.
9808
9809You can also use the @code{asm} keyword to override the assembler name
9810for a C symbol, or to place a C variable in a specific register.
9811
9812@menu
9813* Basic Asm:: Inline assembler without operands.
9814* Extended Asm:: Inline assembler with operands.
9815* Constraints:: Constraints for @code{asm} operands
9816* Asm Labels:: Specifying the assembler name to use for a C symbol.
9817* Explicit Register Variables:: Defining variables residing in specified
9818 registers.
9819* Size of an asm:: How GCC calculates the size of an @code{asm} block.
9820@end menu
9821
9822@node Basic Asm
9823@subsection Basic Asm --- Assembler Instructions Without Operands
9824@cindex basic @code{asm}
9825@cindex assembly language in C, basic
9826
9827A basic @code{asm} statement has the following syntax:
9828
9829@example
9830asm @var{asm-qualifiers} ( @var{AssemblerInstructions} )
9831@end example
9832
9833For the C language, the @code{asm} keyword is a GNU extension.
9834When writing C code that can be compiled with @option{-ansi} and the
9835@option{-std} options that select C dialects without GNU extensions, use
9836@code{__asm__} instead of @code{asm} (@pxref{Alternate Keywords}). For
9837the C++ language, @code{asm} is a standard keyword, but @code{__asm__}
9838can be used for code compiled with @option{-fno-asm}.
9839
9840@subsubheading Qualifiers
9841@table @code
9842@item volatile
9843The optional @code{volatile} qualifier has no effect.
9844All basic @code{asm} blocks are implicitly volatile.
9845
9846@item inline
9847If you use the @code{inline} qualifier, then for inlining purposes the size
9848of the @code{asm} statement is taken as the smallest size possible (@pxref{Size
9849of an asm}).
9850@end table
9851
9852@subsubheading Parameters
9853@table @var
9854
9855@item AssemblerInstructions
9856This is a literal string that specifies the assembler code. The string can
9857contain any instructions recognized by the assembler, including directives.
9858GCC does not parse the assembler instructions themselves and
9859does not know what they mean or even whether they are valid assembler input.
9860
9861You may place multiple assembler instructions together in a single @code{asm}
9862string, separated by the characters normally used in assembly code for the
9863system. A combination that works in most places is a newline to break the
9864line, plus a tab character (written as @samp{\n\t}).
9865Some assemblers allow semicolons as a line separator. However,
9866note that some assembler dialects use semicolons to start a comment.
9867@end table
9868
9869@subsubheading Remarks
9870Using extended @code{asm} (@pxref{Extended Asm}) typically produces
9871smaller, safer, and more efficient code, and in most cases it is a
9872better solution than basic @code{asm}. However, there are two
9873situations where only basic @code{asm} can be used:
9874
9875@itemize @bullet
9876@item
9877Extended @code{asm} statements have to be inside a C
9878function, so to write inline assembly language at file scope (``top-level''),
9879outside of C functions, you must use basic @code{asm}.
9880You can use this technique to emit assembler directives,
9881define assembly language macros that can be invoked elsewhere in the file,
9882or write entire functions in assembly language.
9883Basic @code{asm} statements outside of functions may not use any
9884qualifiers.
9885
9886@item
9887Functions declared
9888with the @code{naked} attribute also require basic @code{asm}
9889(@pxref{Function Attributes}).
9890@end itemize
9891
9892Safely accessing C data and calling functions from basic @code{asm} is more
9893complex than it may appear. To access C data, it is better to use extended
9894@code{asm}.
9895
9896Do not expect a sequence of @code{asm} statements to remain perfectly
9897consecutive after compilation. If certain instructions need to remain
9898consecutive in the output, put them in a single multi-instruction @code{asm}
9899statement. Note that GCC's optimizers can move @code{asm} statements
9900relative to other code, including across jumps.
9901
9902@code{asm} statements may not perform jumps into other @code{asm} statements.
9903GCC does not know about these jumps, and therefore cannot take
9904account of them when deciding how to optimize. Jumps from @code{asm} to C
9905labels are only supported in extended @code{asm}.
9906
9907Under certain circumstances, GCC may duplicate (or remove duplicates of) your
9908assembly code when optimizing. This can lead to unexpected duplicate
9909symbol errors during compilation if your assembly code defines symbols or
9910labels.
9911
9912@strong{Warning:} The C standards do not specify semantics for @code{asm},
9913making it a potential source of incompatibilities between compilers. These
9914incompatibilities may not produce compiler warnings/errors.
9915
9916GCC does not parse basic @code{asm}'s @var{AssemblerInstructions}, which
9917means there is no way to communicate to the compiler what is happening
9918inside them. GCC has no visibility of symbols in the @code{asm} and may
9919discard them as unreferenced. It also does not know about side effects of
9920the assembler code, such as modifications to memory or registers. Unlike
9921some compilers, GCC assumes that no changes to general purpose registers
9922occur. This assumption may change in a future release.
9923
9924To avoid complications from future changes to the semantics and the
9925compatibility issues between compilers, consider replacing basic @code{asm}
9926with extended @code{asm}. See
9927@uref{https://gcc.gnu.org/wiki/ConvertBasicAsmToExtended, How to convert
9928from basic asm to extended asm} for information about how to perform this
9929conversion.
9930
9931The compiler copies the assembler instructions in a basic @code{asm}
9932verbatim to the assembly language output file, without
9933processing dialects or any of the @samp{%} operators that are available with
9934extended @code{asm}. This results in minor differences between basic
9935@code{asm} strings and extended @code{asm} templates. For example, to refer to
9936registers you might use @samp{%eax} in basic @code{asm} and
9937@samp{%%eax} in extended @code{asm}.
9938
9939On targets such as x86 that support multiple assembler dialects,
9940all basic @code{asm} blocks use the assembler dialect specified by the
9941@option{-masm} command-line option (@pxref{x86 Options}).
9942Basic @code{asm} provides no
9943mechanism to provide different assembler strings for different dialects.
9944
9945For basic @code{asm} with non-empty assembler string GCC assumes
9946the assembler block does not change any general purpose registers,
9947but it may read or write any globally accessible variable.
9948
9949Here is an example of basic @code{asm} for i386:
9950
9951@example
9952/* Note that this code will not compile with -masm=intel */
9953#define DebugBreak() asm("int $3")
9954@end example
9955
9956@node Extended Asm
9957@subsection Extended Asm - Assembler Instructions with C Expression Operands
9958@cindex extended @code{asm}
9959@cindex assembly language in C, extended
9960
9961With extended @code{asm} you can read and write C variables from
9962assembler and perform jumps from assembler code to C labels.
9963Extended @code{asm} syntax uses colons (@samp{:}) to delimit
9964the operand parameters after the assembler template:
9965
9966@example
9967asm @var{asm-qualifiers} ( @var{AssemblerTemplate}
9968 : @var{OutputOperands}
9969 @r{[} : @var{InputOperands}
9970 @r{[} : @var{Clobbers} @r{]} @r{]})
9971
9972asm @var{asm-qualifiers} ( @var{AssemblerTemplate}
9973 : @var{OutputOperands}
9974 : @var{InputOperands}
9975 : @var{Clobbers}
9976 : @var{GotoLabels})
9977@end example
9978where in the last form, @var{asm-qualifiers} contains @code{goto} (and in the
9979first form, not).
9980
9981The @code{asm} keyword is a GNU extension.
9982When writing code that can be compiled with @option{-ansi} and the
9983various @option{-std} options, use @code{__asm__} instead of
9984@code{asm} (@pxref{Alternate Keywords}).
9985
9986@subsubheading Qualifiers
9987@table @code
9988
9989@item volatile
9990The typical use of extended @code{asm} statements is to manipulate input
9991values to produce output values. However, your @code{asm} statements may
9992also produce side effects. If so, you may need to use the @code{volatile}
9993qualifier to disable certain optimizations. @xref{Volatile}.
9994
9995@item inline
9996If you use the @code{inline} qualifier, then for inlining purposes the size
9997of the @code{asm} statement is taken as the smallest size possible
9998(@pxref{Size of an asm}).
9999
10000@item goto
10001This qualifier informs the compiler that the @code{asm} statement may
10002perform a jump to one of the labels listed in the @var{GotoLabels}.
10003@xref{GotoLabels}.
10004@end table
10005
10006@subsubheading Parameters
10007@table @var
10008@item AssemblerTemplate
10009This is a literal string that is the template for the assembler code. It is a
10010combination of fixed text and tokens that refer to the input, output,
10011and goto parameters. @xref{AssemblerTemplate}.
10012
10013@item OutputOperands
10014A comma-separated list of the C variables modified by the instructions in the
10015@var{AssemblerTemplate}. An empty list is permitted. @xref{OutputOperands}.
10016
10017@item InputOperands
10018A comma-separated list of C expressions read by the instructions in the
10019@var{AssemblerTemplate}. An empty list is permitted. @xref{InputOperands}.
10020
10021@item Clobbers
10022A comma-separated list of registers or other values changed by the
10023@var{AssemblerTemplate}, beyond those listed as outputs.
10024An empty list is permitted. @xref{Clobbers and Scratch Registers}.
10025
10026@item GotoLabels
10027When you are using the @code{goto} form of @code{asm}, this section contains
10028the list of all C labels to which the code in the
10029@var{AssemblerTemplate} may jump.
10030@xref{GotoLabels}.
10031
10032@code{asm} statements may not perform jumps into other @code{asm} statements,
10033only to the listed @var{GotoLabels}.
10034GCC's optimizers do not know about other jumps; therefore they cannot take
10035account of them when deciding how to optimize.
10036@end table
10037
10038The total number of input + output + goto operands is limited to 30.
10039
10040@subsubheading Remarks
10041The @code{asm} statement allows you to include assembly instructions directly
10042within C code. This may help you to maximize performance in time-sensitive
10043code or to access assembly instructions that are not readily available to C
10044programs.
10045
10046Note that extended @code{asm} statements must be inside a function. Only
10047basic @code{asm} may be outside functions (@pxref{Basic Asm}).
10048Functions declared with the @code{naked} attribute also require basic
10049@code{asm} (@pxref{Function Attributes}).
10050
10051While the uses of @code{asm} are many and varied, it may help to think of an
10052@code{asm} statement as a series of low-level instructions that convert input
10053parameters to output parameters. So a simple (if not particularly useful)
10054example for i386 using @code{asm} might look like this:
10055
10056@example
10057int src = 1;
10058int dst;
10059
10060asm ("mov %1, %0\n\t"
10061 "add $1, %0"
10062 : "=r" (dst)
10063 : "r" (src));
10064
10065printf("%d\n", dst);
10066@end example
10067
10068This code copies @code{src} to @code{dst} and add 1 to @code{dst}.
10069
10070@anchor{Volatile}
10071@subsubsection Volatile
10072@cindex volatile @code{asm}
10073@cindex @code{asm} volatile
10074
10075GCC's optimizers sometimes discard @code{asm} statements if they determine
10076there is no need for the output variables. Also, the optimizers may move
10077code out of loops if they believe that the code will always return the same
10078result (i.e.@: none of its input values change between calls). Using the
10079@code{volatile} qualifier disables these optimizations. @code{asm} statements
10080that have no output operands and @code{asm goto} statements,
10081are implicitly volatile.
10082
10083This i386 code demonstrates a case that does not use (or require) the
10084@code{volatile} qualifier. If it is performing assertion checking, this code
10085uses @code{asm} to perform the validation. Otherwise, @code{dwRes} is
10086unreferenced by any code. As a result, the optimizers can discard the
10087@code{asm} statement, which in turn removes the need for the entire
10088@code{DoCheck} routine. By omitting the @code{volatile} qualifier when it
10089isn't needed you allow the optimizers to produce the most efficient code
10090possible.
10091
10092@example
10093void DoCheck(uint32_t dwSomeValue)
10094@{
10095 uint32_t dwRes;
10096
10097 // Assumes dwSomeValue is not zero.
10098 asm ("bsfl %1,%0"
10099 : "=r" (dwRes)
10100 : "r" (dwSomeValue)
10101 : "cc");
10102
10103 assert(dwRes > 3);
10104@}
10105@end example
10106
10107The next example shows a case where the optimizers can recognize that the input
10108(@code{dwSomeValue}) never changes during the execution of the function and can
10109therefore move the @code{asm} outside the loop to produce more efficient code.
10110Again, using the @code{volatile} qualifier disables this type of optimization.
10111
10112@example
10113void do_print(uint32_t dwSomeValue)
10114@{
10115 uint32_t dwRes;
10116
10117 for (uint32_t x=0; x < 5; x++)
10118 @{
10119 // Assumes dwSomeValue is not zero.
10120 asm ("bsfl %1,%0"
10121 : "=r" (dwRes)
10122 : "r" (dwSomeValue)
10123 : "cc");
10124
10125 printf("%u: %u %u\n", x, dwSomeValue, dwRes);
10126 @}
10127@}
10128@end example
10129
10130The following example demonstrates a case where you need to use the
10131@code{volatile} qualifier.
10132It uses the x86 @code{rdtsc} instruction, which reads
10133the computer's time-stamp counter. Without the @code{volatile} qualifier,
10134the optimizers might assume that the @code{asm} block will always return the
10135same value and therefore optimize away the second call.
10136
10137@example
10138uint64_t msr;
10139
10140asm volatile ( "rdtsc\n\t" // Returns the time in EDX:EAX.
10141 "shl $32, %%rdx\n\t" // Shift the upper bits left.
10142 "or %%rdx, %0" // 'Or' in the lower bits.
10143 : "=a" (msr)
10144 :
10145 : "rdx");
10146
10147printf("msr: %llx\n", msr);
10148
10149// Do other work...
10150
10151// Reprint the timestamp
10152asm volatile ( "rdtsc\n\t" // Returns the time in EDX:EAX.
10153 "shl $32, %%rdx\n\t" // Shift the upper bits left.
10154 "or %%rdx, %0" // 'Or' in the lower bits.
10155 : "=a" (msr)
10156 :
10157 : "rdx");
10158
10159printf("msr: %llx\n", msr);
10160@end example
10161
10162GCC's optimizers do not treat this code like the non-volatile code in the
10163earlier examples. They do not move it out of loops or omit it on the
10164assumption that the result from a previous call is still valid.
10165
10166Note that the compiler can move even @code{volatile asm} instructions relative
10167to other code, including across jump instructions. For example, on many
10168targets there is a system register that controls the rounding mode of
10169floating-point operations. Setting it with a @code{volatile asm} statement,
10170as in the following PowerPC example, does not work reliably.
10171
10172@example
10173asm volatile("mtfsf 255, %0" : : "f" (fpenv));
10174sum = x + y;
10175@end example
10176
10177The compiler may move the addition back before the @code{volatile asm}
10178statement. To make it work as expected, add an artificial dependency to
10179the @code{asm} by referencing a variable in the subsequent code, for
10180example:
10181
10182@example
10183asm volatile ("mtfsf 255,%1" : "=X" (sum) : "f" (fpenv));
10184sum = x + y;
10185@end example
10186
10187Under certain circumstances, GCC may duplicate (or remove duplicates of) your
10188assembly code when optimizing. This can lead to unexpected duplicate symbol
10189errors during compilation if your @code{asm} code defines symbols or labels.
10190Using @samp{%=}
10191(@pxref{AssemblerTemplate}) may help resolve this problem.
10192
10193@anchor{AssemblerTemplate}
10194@subsubsection Assembler Template
10195@cindex @code{asm} assembler template
10196
10197An assembler template is a literal string containing assembler instructions.
10198The compiler replaces tokens in the template that refer
10199to inputs, outputs, and goto labels,
10200and then outputs the resulting string to the assembler. The
10201string can contain any instructions recognized by the assembler, including
10202directives. GCC does not parse the assembler instructions
10203themselves and does not know what they mean or even whether they are valid
10204assembler input. However, it does count the statements
10205(@pxref{Size of an asm}).
10206
10207You may place multiple assembler instructions together in a single @code{asm}
10208string, separated by the characters normally used in assembly code for the
10209system. A combination that works in most places is a newline to break the
10210line, plus a tab character to move to the instruction field (written as
10211@samp{\n\t}).
10212Some assemblers allow semicolons as a line separator. However, note
10213that some assembler dialects use semicolons to start a comment.
10214
10215Do not expect a sequence of @code{asm} statements to remain perfectly
10216consecutive after compilation, even when you are using the @code{volatile}
10217qualifier. If certain instructions need to remain consecutive in the output,
10218put them in a single multi-instruction @code{asm} statement.
10219
10220Accessing data from C programs without using input/output operands (such as
10221by using global symbols directly from the assembler template) may not work as
10222expected. Similarly, calling functions directly from an assembler template
10223requires a detailed understanding of the target assembler and ABI.
10224
10225Since GCC does not parse the assembler template,
10226it has no visibility of any
10227symbols it references. This may result in GCC discarding those symbols as
10228unreferenced unless they are also listed as input, output, or goto operands.
10229
10230@subsubheading Special format strings
10231
10232In addition to the tokens described by the input, output, and goto operands,
10233these tokens have special meanings in the assembler template:
10234
10235@table @samp
10236@item %%
10237Outputs a single @samp{%} into the assembler code.
10238
10239@item %=
10240Outputs a number that is unique to each instance of the @code{asm}
10241statement in the entire compilation. This option is useful when creating local
10242labels and referring to them multiple times in a single template that
10243generates multiple assembler instructions.
10244
10245@item %@{
10246@itemx %|
10247@itemx %@}
10248Outputs @samp{@{}, @samp{|}, and @samp{@}} characters (respectively)
10249into the assembler code. When unescaped, these characters have special
10250meaning to indicate multiple assembler dialects, as described below.
10251@end table
10252
10253@subsubheading Multiple assembler dialects in @code{asm} templates
10254
10255On targets such as x86, GCC supports multiple assembler dialects.
10256The @option{-masm} option controls which dialect GCC uses as its
10257default for inline assembler. The target-specific documentation for the
10258@option{-masm} option contains the list of supported dialects, as well as the
10259default dialect if the option is not specified. This information may be
10260important to understand, since assembler code that works correctly when
10261compiled using one dialect will likely fail if compiled using another.
10262@xref{x86 Options}.
10263
10264If your code needs to support multiple assembler dialects (for example, if
10265you are writing public headers that need to support a variety of compilation
10266options), use constructs of this form:
10267
10268@example
10269@{ dialect0 | dialect1 | dialect2... @}
10270@end example
10271
10272This construct outputs @code{dialect0}
10273when using dialect #0 to compile the code,
10274@code{dialect1} for dialect #1, etc. If there are fewer alternatives within the
10275braces than the number of dialects the compiler supports, the construct
10276outputs nothing.
10277
10278For example, if an x86 compiler supports two dialects
10279(@samp{att}, @samp{intel}), an
10280assembler template such as this:
10281
10282@example
10283"bt@{l %[Offset],%[Base] | %[Base],%[Offset]@}; jc %l2"
10284@end example
10285
10286@noindent
10287is equivalent to one of
10288
10289@example
10290"btl %[Offset],%[Base] ; jc %l2" @r{/* att dialect */}
10291"bt %[Base],%[Offset]; jc %l2" @r{/* intel dialect */}
10292@end example
10293
10294Using that same compiler, this code:
10295
10296@example
10297"xchg@{l@}\t@{%%@}ebx, %1"
10298@end example
10299
10300@noindent
10301corresponds to either
10302
10303@example
10304"xchgl\t%%ebx, %1" @r{/* att dialect */}
10305"xchg\tebx, %1" @r{/* intel dialect */}
10306@end example
10307
10308There is no support for nesting dialect alternatives.
10309
10310@anchor{OutputOperands}
10311@subsubsection Output Operands
10312@cindex @code{asm} output operands
10313
10314An @code{asm} statement has zero or more output operands indicating the names
10315of C variables modified by the assembler code.
10316
10317In this i386 example, @code{old} (referred to in the template string as
10318@code{%0}) and @code{*Base} (as @code{%1}) are outputs and @code{Offset}
10319(@code{%2}) is an input:
10320
10321@example
10322bool old;
10323
10324__asm__ ("btsl %2,%1\n\t" // Turn on zero-based bit #Offset in Base.
10325 "sbb %0,%0" // Use the CF to calculate old.
10326 : "=r" (old), "+rm" (*Base)
10327 : "Ir" (Offset)
10328 : "cc");
10329
10330return old;
10331@end example
10332
10333Operands are separated by commas. Each operand has this format:
10334
10335@example
10336@r{[} [@var{asmSymbolicName}] @r{]} @var{constraint} (@var{cvariablename})
10337@end example
10338
10339@table @var
10340@item asmSymbolicName
10341Specifies a symbolic name for the operand.
10342Reference the name in the assembler template
10343by enclosing it in square brackets
10344(i.e.@: @samp{%[Value]}). The scope of the name is the @code{asm} statement
10345that contains the definition. Any valid C variable name is acceptable,
10346including names already defined in the surrounding code. No two operands
10347within the same @code{asm} statement can use the same symbolic name.
10348
10349When not using an @var{asmSymbolicName}, use the (zero-based) position
10350of the operand
10351in the list of operands in the assembler template. For example if there are
10352three output operands, use @samp{%0} in the template to refer to the first,
10353@samp{%1} for the second, and @samp{%2} for the third.
10354
10355@item constraint
10356A string constant specifying constraints on the placement of the operand;
10357@xref{Constraints}, for details.
10358
10359Output constraints must begin with either @samp{=} (a variable overwriting an
10360existing value) or @samp{+} (when reading and writing). When using
10361@samp{=}, do not assume the location contains the existing value
10362on entry to the @code{asm}, except
10363when the operand is tied to an input; @pxref{InputOperands,,Input Operands}.
10364
10365After the prefix, there must be one or more additional constraints
10366(@pxref{Constraints}) that describe where the value resides. Common
10367constraints include @samp{r} for register and @samp{m} for memory.
10368When you list more than one possible location (for example, @code{"=rm"}),
10369the compiler chooses the most efficient one based on the current context.
10370If you list as many alternates as the @code{asm} statement allows, you permit
10371the optimizers to produce the best possible code.
10372If you must use a specific register, but your Machine Constraints do not
10373provide sufficient control to select the specific register you want,
10374local register variables may provide a solution (@pxref{Local Register
10375Variables}).
10376
10377@item cvariablename
10378Specifies a C lvalue expression to hold the output, typically a variable name.
10379The enclosing parentheses are a required part of the syntax.
10380
10381@end table
10382
10383When the compiler selects the registers to use to
10384represent the output operands, it does not use any of the clobbered registers
10385(@pxref{Clobbers and Scratch Registers}).
10386
10387Output operand expressions must be lvalues. The compiler cannot check whether
10388the operands have data types that are reasonable for the instruction being
10389executed. For output expressions that are not directly addressable (for
10390example a bit-field), the constraint must allow a register. In that case, GCC
10391uses the register as the output of the @code{asm}, and then stores that
10392register into the output.
10393
10394Operands using the @samp{+} constraint modifier count as two operands
10395(that is, both as input and output) towards the total maximum of 30 operands
10396per @code{asm} statement.
10397
10398Use the @samp{&} constraint modifier (@pxref{Modifiers}) on all output
10399operands that must not overlap an input. Otherwise,
10400GCC may allocate the output operand in the same register as an unrelated
10401input operand, on the assumption that the assembler code consumes its
10402inputs before producing outputs. This assumption may be false if the assembler
10403code actually consists of more than one instruction.
10404
10405The same problem can occur if one output parameter (@var{a}) allows a register
10406constraint and another output parameter (@var{b}) allows a memory constraint.
10407The code generated by GCC to access the memory address in @var{b} can contain
10408registers which @emph{might} be shared by @var{a}, and GCC considers those
10409registers to be inputs to the asm. As above, GCC assumes that such input
10410registers are consumed before any outputs are written. This assumption may
10411result in incorrect behavior if the @code{asm} statement writes to @var{a}
10412before using
10413@var{b}. Combining the @samp{&} modifier with the register constraint on @var{a}
10414ensures that modifying @var{a} does not affect the address referenced by
10415@var{b}. Otherwise, the location of @var{b}
10416is undefined if @var{a} is modified before using @var{b}.
10417
10418@code{asm} supports operand modifiers on operands (for example @samp{%k2}
b5ea0f07
LC
10419instead of simply @samp{%2}). @ref{GenericOperandmodifiers,
10420Generic Operand modifiers} lists the modifiers that are available
10421on all targets. Other modifiers are hardware dependent.
10422For example, the list of supported modifiers for x86 is found at
d77de738
ML
10423@ref{x86Operandmodifiers,x86 Operand modifiers}.
10424
10425If the C code that follows the @code{asm} makes no use of any of the output
10426operands, use @code{volatile} for the @code{asm} statement to prevent the
10427optimizers from discarding the @code{asm} statement as unneeded
10428(see @ref{Volatile}).
10429
10430This code makes no use of the optional @var{asmSymbolicName}. Therefore it
10431references the first output operand as @code{%0} (were there a second, it
10432would be @code{%1}, etc). The number of the first input operand is one greater
10433than that of the last output operand. In this i386 example, that makes
10434@code{Mask} referenced as @code{%1}:
10435
10436@example
10437uint32_t Mask = 1234;
10438uint32_t Index;
10439
10440 asm ("bsfl %1, %0"
10441 : "=r" (Index)
10442 : "r" (Mask)
10443 : "cc");
10444@end example
10445
10446That code overwrites the variable @code{Index} (@samp{=}),
10447placing the value in a register (@samp{r}).
10448Using the generic @samp{r} constraint instead of a constraint for a specific
10449register allows the compiler to pick the register to use, which can result
10450in more efficient code. This may not be possible if an assembler instruction
10451requires a specific register.
10452
10453The following i386 example uses the @var{asmSymbolicName} syntax.
10454It produces the
10455same result as the code above, but some may consider it more readable or more
10456maintainable since reordering index numbers is not necessary when adding or
10457removing operands. The names @code{aIndex} and @code{aMask}
10458are only used in this example to emphasize which
10459names get used where.
10460It is acceptable to reuse the names @code{Index} and @code{Mask}.
10461
10462@example
10463uint32_t Mask = 1234;
10464uint32_t Index;
10465
10466 asm ("bsfl %[aMask], %[aIndex]"
10467 : [aIndex] "=r" (Index)
10468 : [aMask] "r" (Mask)
10469 : "cc");
10470@end example
10471
10472Here are some more examples of output operands.
10473
10474@example
10475uint32_t c = 1;
10476uint32_t d;
10477uint32_t *e = &c;
10478
10479asm ("mov %[e], %[d]"
10480 : [d] "=rm" (d)
10481 : [e] "rm" (*e));
10482@end example
10483
10484Here, @code{d} may either be in a register or in memory. Since the compiler
10485might already have the current value of the @code{uint32_t} location
10486pointed to by @code{e}
10487in a register, you can enable it to choose the best location
10488for @code{d} by specifying both constraints.
10489
10490@anchor{FlagOutputOperands}
10491@subsubsection Flag Output Operands
10492@cindex @code{asm} flag output operands
10493
10494Some targets have a special register that holds the ``flags'' for the
10495result of an operation or comparison. Normally, the contents of that
10496register are either unmodifed by the asm, or the @code{asm} statement is
10497considered to clobber the contents.
10498
10499On some targets, a special form of output operand exists by which
10500conditions in the flags register may be outputs of the asm. The set of
10501conditions supported are target specific, but the general rule is that
10502the output variable must be a scalar integer, and the value is boolean.
10503When supported, the target defines the preprocessor symbol
10504@code{__GCC_ASM_FLAG_OUTPUTS__}.
10505
10506Because of the special nature of the flag output operands, the constraint
10507may not include alternatives.
10508
10509Most often, the target has only one flags register, and thus is an implied
10510operand of many instructions. In this case, the operand should not be
10511referenced within the assembler template via @code{%0} etc, as there's
10512no corresponding text in the assembly language.
10513
10514@table @asis
10515@item ARM
10516@itemx AArch64
10517The flag output constraints for the ARM family are of the form
10518@samp{=@@cc@var{cond}} where @var{cond} is one of the standard
10519conditions defined in the ARM ARM for @code{ConditionHolds}.
10520
10521@table @code
10522@item eq
10523Z flag set, or equal
10524@item ne
10525Z flag clear or not equal
10526@item cs
10527@itemx hs
10528C flag set or unsigned greater than equal
10529@item cc
10530@itemx lo
10531C flag clear or unsigned less than
10532@item mi
10533N flag set or ``minus''
10534@item pl
10535N flag clear or ``plus''
10536@item vs
10537V flag set or signed overflow
10538@item vc
10539V flag clear
10540@item hi
10541unsigned greater than
10542@item ls
10543unsigned less than equal
10544@item ge
10545signed greater than equal
10546@item lt
10547signed less than
10548@item gt
10549signed greater than
10550@item le
10551signed less than equal
10552@end table
10553
10554The flag output constraints are not supported in thumb1 mode.
10555
10556@item x86 family
10557The flag output constraints for the x86 family are of the form
10558@samp{=@@cc@var{cond}} where @var{cond} is one of the standard
10559conditions defined in the ISA manual for @code{j@var{cc}} or
10560@code{set@var{cc}}.
10561
10562@table @code
10563@item a
10564``above'' or unsigned greater than
10565@item ae
10566``above or equal'' or unsigned greater than or equal
10567@item b
10568``below'' or unsigned less than
10569@item be
10570``below or equal'' or unsigned less than or equal
10571@item c
10572carry flag set
10573@item e
10574@itemx z
10575``equal'' or zero flag set
10576@item g
10577signed greater than
10578@item ge
10579signed greater than or equal
10580@item l
10581signed less than
10582@item le
10583signed less than or equal
10584@item o
10585overflow flag set
10586@item p
10587parity flag set
10588@item s
10589sign flag set
10590@item na
10591@itemx nae
10592@itemx nb
10593@itemx nbe
10594@itemx nc
10595@itemx ne
10596@itemx ng
10597@itemx nge
10598@itemx nl
10599@itemx nle
10600@itemx no
10601@itemx np
10602@itemx ns
10603@itemx nz
10604``not'' @var{flag}, or inverted versions of those above
10605@end table
10606
10607@end table
10608
10609@anchor{InputOperands}
10610@subsubsection Input Operands
10611@cindex @code{asm} input operands
10612@cindex @code{asm} expressions
10613
10614Input operands make values from C variables and expressions available to the
10615assembly code.
10616
10617Operands are separated by commas. Each operand has this format:
10618
10619@example
10620@r{[} [@var{asmSymbolicName}] @r{]} @var{constraint} (@var{cexpression})
10621@end example
10622
10623@table @var
10624@item asmSymbolicName
10625Specifies a symbolic name for the operand.
10626Reference the name in the assembler template
10627by enclosing it in square brackets
10628(i.e.@: @samp{%[Value]}). The scope of the name is the @code{asm} statement
10629that contains the definition. Any valid C variable name is acceptable,
10630including names already defined in the surrounding code. No two operands
10631within the same @code{asm} statement can use the same symbolic name.
10632
10633When not using an @var{asmSymbolicName}, use the (zero-based) position
10634of the operand
10635in the list of operands in the assembler template. For example if there are
10636two output operands and three inputs,
10637use @samp{%2} in the template to refer to the first input operand,
10638@samp{%3} for the second, and @samp{%4} for the third.
10639
10640@item constraint
10641A string constant specifying constraints on the placement of the operand;
10642@xref{Constraints}, for details.
10643
10644Input constraint strings may not begin with either @samp{=} or @samp{+}.
10645When you list more than one possible location (for example, @samp{"irm"}),
10646the compiler chooses the most efficient one based on the current context.
10647If you must use a specific register, but your Machine Constraints do not
10648provide sufficient control to select the specific register you want,
10649local register variables may provide a solution (@pxref{Local Register
10650Variables}).
10651
10652Input constraints can also be digits (for example, @code{"0"}). This indicates
10653that the specified input must be in the same place as the output constraint
10654at the (zero-based) index in the output constraint list.
10655When using @var{asmSymbolicName} syntax for the output operands,
10656you may use these names (enclosed in brackets @samp{[]}) instead of digits.
10657
10658@item cexpression
10659This is the C variable or expression being passed to the @code{asm} statement
10660as input. The enclosing parentheses are a required part of the syntax.
10661
10662@end table
10663
10664When the compiler selects the registers to use to represent the input
10665operands, it does not use any of the clobbered registers
10666(@pxref{Clobbers and Scratch Registers}).
10667
10668If there are no output operands but there are input operands, place two
10669consecutive colons where the output operands would go:
10670
10671@example
10672__asm__ ("some instructions"
10673 : /* No outputs. */
10674 : "r" (Offset / 8));
10675@end example
10676
10677@strong{Warning:} Do @emph{not} modify the contents of input-only operands
10678(except for inputs tied to outputs). The compiler assumes that on exit from
10679the @code{asm} statement these operands contain the same values as they
10680had before executing the statement.
10681It is @emph{not} possible to use clobbers
10682to inform the compiler that the values in these inputs are changing. One
10683common work-around is to tie the changing input variable to an output variable
10684that never gets used. Note, however, that if the code that follows the
10685@code{asm} statement makes no use of any of the output operands, the GCC
10686optimizers may discard the @code{asm} statement as unneeded
10687(see @ref{Volatile}).
10688
10689@code{asm} supports operand modifiers on operands (for example @samp{%k2}
b5ea0f07
LC
10690instead of simply @samp{%2}). @ref{GenericOperandmodifiers,
10691Generic Operand modifiers} lists the modifiers that are available
10692on all targets. Other modifiers are hardware dependent.
10693For example, the list of supported modifiers for x86 is found at
d77de738
ML
10694@ref{x86Operandmodifiers,x86 Operand modifiers}.
10695
10696In this example using the fictitious @code{combine} instruction, the
10697constraint @code{"0"} for input operand 1 says that it must occupy the same
10698location as output operand 0. Only input operands may use numbers in
10699constraints, and they must each refer to an output operand. Only a number (or
10700the symbolic assembler name) in the constraint can guarantee that one operand
10701is in the same place as another. The mere fact that @code{foo} is the value of
10702both operands is not enough to guarantee that they are in the same place in
10703the generated assembler code.
10704
10705@example
10706asm ("combine %2, %0"
10707 : "=r" (foo)
10708 : "0" (foo), "g" (bar));
10709@end example
10710
10711Here is an example using symbolic names.
10712
10713@example
10714asm ("cmoveq %1, %2, %[result]"
10715 : [result] "=r"(result)
10716 : "r" (test), "r" (new), "[result]" (old));
10717@end example
10718
10719@anchor{Clobbers and Scratch Registers}
10720@subsubsection Clobbers and Scratch Registers
10721@cindex @code{asm} clobbers
10722@cindex @code{asm} scratch registers
10723
10724While the compiler is aware of changes to entries listed in the output
10725operands, the inline @code{asm} code may modify more than just the outputs. For
10726example, calculations may require additional registers, or the processor may
10727overwrite a register as a side effect of a particular assembler instruction.
10728In order to inform the compiler of these changes, list them in the clobber
10729list. Clobber list items are either register names or the special clobbers
10730(listed below). Each clobber list item is a string constant
10731enclosed in double quotes and separated by commas.
10732
10733Clobber descriptions may not in any way overlap with an input or output
10734operand. For example, you may not have an operand describing a register class
10735with one member when listing that register in the clobber list. Variables
10736declared to live in specific registers (@pxref{Explicit Register
10737Variables}) and used
10738as @code{asm} input or output operands must have no part mentioned in the
10739clobber description. In particular, there is no way to specify that input
10740operands get modified without also specifying them as output operands.
10741
10742When the compiler selects which registers to use to represent input and output
10743operands, it does not use any of the clobbered registers. As a result,
10744clobbered registers are available for any use in the assembler code.
10745
10746Another restriction is that the clobber list should not contain the
10747stack pointer register. This is because the compiler requires the
10748value of the stack pointer to be the same after an @code{asm}
10749statement as it was on entry to the statement. However, previous
10750versions of GCC did not enforce this rule and allowed the stack
10751pointer to appear in the list, with unclear semantics. This behavior
10752is deprecated and listing the stack pointer may become an error in
10753future versions of GCC@.
10754
10755Here is a realistic example for the VAX showing the use of clobbered
10756registers:
10757
10758@example
10759asm volatile ("movc3 %0, %1, %2"
10760 : /* No outputs. */
10761 : "g" (from), "g" (to), "g" (count)
10762 : "r0", "r1", "r2", "r3", "r4", "r5", "memory");
10763@end example
10764
10765Also, there are two special clobber arguments:
10766
10767@table @code
10768@item "cc"
10769The @code{"cc"} clobber indicates that the assembler code modifies the flags
10770register. On some machines, GCC represents the condition codes as a specific
10771hardware register; @code{"cc"} serves to name this register.
10772On other machines, condition code handling is different,
10773and specifying @code{"cc"} has no effect. But
10774it is valid no matter what the target.
10775
10776@item "memory"
10777The @code{"memory"} clobber tells the compiler that the assembly code
10778performs memory
10779reads or writes to items other than those listed in the input and output
10780operands (for example, accessing the memory pointed to by one of the input
10781parameters). To ensure memory contains correct values, GCC may need to flush
10782specific register values to memory before executing the @code{asm}. Further,
10783the compiler does not assume that any values read from memory before an
10784@code{asm} remain unchanged after that @code{asm}; it reloads them as
10785needed.
10786Using the @code{"memory"} clobber effectively forms a read/write
10787memory barrier for the compiler.
10788
10789Note that this clobber does not prevent the @emph{processor} from doing
10790speculative reads past the @code{asm} statement. To prevent that, you need
10791processor-specific fence instructions.
10792
10793@end table
10794
10795Flushing registers to memory has performance implications and may be
10796an issue for time-sensitive code. You can provide better information
10797to GCC to avoid this, as shown in the following examples. At a
10798minimum, aliasing rules allow GCC to know what memory @emph{doesn't}
10799need to be flushed.
10800
10801Here is a fictitious sum of squares instruction, that takes two
10802pointers to floating point values in memory and produces a floating
10803point register output.
10804Notice that @code{x}, and @code{y} both appear twice in the @code{asm}
10805parameters, once to specify memory accessed, and once to specify a
10806base register used by the @code{asm}. You won't normally be wasting a
10807register by doing this as GCC can use the same register for both
10808purposes. However, it would be foolish to use both @code{%1} and
10809@code{%3} for @code{x} in this @code{asm} and expect them to be the
10810same. In fact, @code{%3} may well not be a register. It might be a
10811symbolic memory reference to the object pointed to by @code{x}.
10812
10813@smallexample
10814asm ("sumsq %0, %1, %2"
10815 : "+f" (result)
10816 : "r" (x), "r" (y), "m" (*x), "m" (*y));
10817@end smallexample
10818
10819Here is a fictitious @code{*z++ = *x++ * *y++} instruction.
10820Notice that the @code{x}, @code{y} and @code{z} pointer registers
10821must be specified as input/output because the @code{asm} modifies
10822them.
10823
10824@smallexample
10825asm ("vecmul %0, %1, %2"
10826 : "+r" (z), "+r" (x), "+r" (y), "=m" (*z)
10827 : "m" (*x), "m" (*y));
10828@end smallexample
10829
10830An x86 example where the string memory argument is of unknown length.
10831
10832@smallexample
10833asm("repne scasb"
10834 : "=c" (count), "+D" (p)
10835 : "m" (*(const char (*)[]) p), "0" (-1), "a" (0));
10836@end smallexample
10837
10838If you know the above will only be reading a ten byte array then you
10839could instead use a memory input like:
10840@code{"m" (*(const char (*)[10]) p)}.
10841
10842Here is an example of a PowerPC vector scale implemented in assembly,
10843complete with vector and condition code clobbers, and some initialized
10844offset registers that are unchanged by the @code{asm}.
10845
10846@smallexample
10847void
10848dscal (size_t n, double *x, double alpha)
10849@{
10850 asm ("/* lots of asm here */"
10851 : "+m" (*(double (*)[n]) x), "+&r" (n), "+b" (x)
10852 : "d" (alpha), "b" (32), "b" (48), "b" (64),
10853 "b" (80), "b" (96), "b" (112)
10854 : "cr0",
10855 "vs32","vs33","vs34","vs35","vs36","vs37","vs38","vs39",
10856 "vs40","vs41","vs42","vs43","vs44","vs45","vs46","vs47");
10857@}
10858@end smallexample
10859
10860Rather than allocating fixed registers via clobbers to provide scratch
10861registers for an @code{asm} statement, an alternative is to define a
10862variable and make it an early-clobber output as with @code{a2} and
10863@code{a3} in the example below. This gives the compiler register
10864allocator more freedom. You can also define a variable and make it an
10865output tied to an input as with @code{a0} and @code{a1}, tied
10866respectively to @code{ap} and @code{lda}. Of course, with tied
10867outputs your @code{asm} can't use the input value after modifying the
10868output register since they are one and the same register. What's
10869more, if you omit the early-clobber on the output, it is possible that
10870GCC might allocate the same register to another of the inputs if GCC
10871could prove they had the same value on entry to the @code{asm}. This
10872is why @code{a1} has an early-clobber. Its tied input, @code{lda}
10873might conceivably be known to have the value 16 and without an
10874early-clobber share the same register as @code{%11}. On the other
10875hand, @code{ap} can't be the same as any of the other inputs, so an
10876early-clobber on @code{a0} is not needed. It is also not desirable in
10877this case. An early-clobber on @code{a0} would cause GCC to allocate
10878a separate register for the @code{"m" (*(const double (*)[]) ap)}
10879input. Note that tying an input to an output is the way to set up an
10880initialized temporary register modified by an @code{asm} statement.
10881An input not tied to an output is assumed by GCC to be unchanged, for
10882example @code{"b" (16)} below sets up @code{%11} to 16, and GCC might
10883use that register in following code if the value 16 happened to be
10884needed. You can even use a normal @code{asm} output for a scratch if
10885all inputs that might share the same register are consumed before the
10886scratch is used. The VSX registers clobbered by the @code{asm}
10887statement could have used this technique except for GCC's limit on the
10888number of @code{asm} parameters.
10889
10890@smallexample
10891static void
10892dgemv_kernel_4x4 (long n, const double *ap, long lda,
10893 const double *x, double *y, double alpha)
10894@{
10895 double *a0;
10896 double *a1;
10897 double *a2;
10898 double *a3;
10899
10900 __asm__
10901 (
10902 /* lots of asm here */
10903 "#n=%1 ap=%8=%12 lda=%13 x=%7=%10 y=%0=%2 alpha=%9 o16=%11\n"
10904 "#a0=%3 a1=%4 a2=%5 a3=%6"
10905 :
10906 "+m" (*(double (*)[n]) y),
10907 "+&r" (n), // 1
10908 "+b" (y), // 2
10909 "=b" (a0), // 3
10910 "=&b" (a1), // 4
10911 "=&b" (a2), // 5
10912 "=&b" (a3) // 6
10913 :
10914 "m" (*(const double (*)[n]) x),
10915 "m" (*(const double (*)[]) ap),
10916 "d" (alpha), // 9
10917 "r" (x), // 10
10918 "b" (16), // 11
10919 "3" (ap), // 12
10920 "4" (lda) // 13
10921 :
10922 "cr0",
10923 "vs32","vs33","vs34","vs35","vs36","vs37",
10924 "vs40","vs41","vs42","vs43","vs44","vs45","vs46","vs47"
10925 );
10926@}
10927@end smallexample
10928
10929@anchor{GotoLabels}
10930@subsubsection Goto Labels
10931@cindex @code{asm} goto labels
10932
10933@code{asm goto} allows assembly code to jump to one or more C labels. The
10934@var{GotoLabels} section in an @code{asm goto} statement contains
10935a comma-separated
10936list of all C labels to which the assembler code may jump. GCC assumes that
10937@code{asm} execution falls through to the next statement (if this is not the
10938case, consider using the @code{__builtin_unreachable} intrinsic after the
10939@code{asm} statement). Optimization of @code{asm goto} may be improved by
10940using the @code{hot} and @code{cold} label attributes (@pxref{Label
10941Attributes}).
10942
10943If the assembler code does modify anything, use the @code{"memory"} clobber
10944to force the
10945optimizers to flush all register values to memory and reload them if
10946necessary after the @code{asm} statement.
10947
10948Also note that an @code{asm goto} statement is always implicitly
10949considered volatile.
10950
10951Be careful when you set output operands inside @code{asm goto} only on
10952some possible control flow paths. If you don't set up the output on
10953given path and never use it on this path, it is okay. Otherwise, you
10954should use @samp{+} constraint modifier meaning that the operand is
10955input and output one. With this modifier you will have the correct
10956values on all possible paths from the @code{asm goto}.
10957
10958To reference a label in the assembler template, prefix it with
10959@samp{%l} (lowercase @samp{L}) followed by its (zero-based) position
10960in @var{GotoLabels} plus the number of input and output operands.
10961Output operand with constraint modifier @samp{+} is counted as two
10962operands because it is considered as one output and one input operand.
10963For example, if the @code{asm} has three inputs, one output operand
10964with constraint modifier @samp{+} and one output operand with
10965constraint modifier @samp{=} and references two labels, refer to the
10966first label as @samp{%l6} and the second as @samp{%l7}).
10967
10968Alternately, you can reference labels using the actual C label name
10969enclosed in brackets. For example, to reference a label named
10970@code{carry}, you can use @samp{%l[carry]}. The label must still be
10971listed in the @var{GotoLabels} section when using this approach. It
10972is better to use the named references for labels as in this case you
10973can avoid counting input and output operands and special treatment of
10974output operands with constraint modifier @samp{+}.
10975
10976Here is an example of @code{asm goto} for i386:
10977
10978@example
10979asm goto (
10980 "btl %1, %0\n\t"
10981 "jc %l2"
10982 : /* No outputs. */
10983 : "r" (p1), "r" (p2)
10984 : "cc"
10985 : carry);
10986
10987return 0;
10988
10989carry:
10990return 1;
10991@end example
10992
10993The following example shows an @code{asm goto} that uses a memory clobber.
10994
10995@example
10996int frob(int x)
10997@{
10998 int y;
10999 asm goto ("frob %%r5, %1; jc %l[error]; mov (%2), %%r5"
11000 : /* No outputs. */
11001 : "r"(x), "r"(&y)
11002 : "r5", "memory"
11003 : error);
11004 return y;
11005error:
11006 return -1;
11007@}
11008@end example
11009
11010The following example shows an @code{asm goto} that uses an output.
11011
11012@example
11013int foo(int count)
11014@{
11015 asm goto ("dec %0; jb %l[stop]"
11016 : "+r" (count)
11017 :
11018 :
11019 : stop);
11020 return count;
11021stop:
11022 return 0;
11023@}
11024@end example
11025
11026The following artificial example shows an @code{asm goto} that sets
11027up an output only on one path inside the @code{asm goto}. Usage of
11028constraint modifier @code{=} instead of @code{+} would be wrong as
11029@code{factor} is used on all paths from the @code{asm goto}.
11030
11031@example
11032int foo(int inp)
11033@{
11034 int factor = 0;
11035 asm goto ("cmp %1, 10; jb %l[lab]; mov 2, %0"
11036 : "+r" (factor)
11037 : "r" (inp)
11038 :
11039 : lab);
11040lab:
11041 return inp * factor; /* return 2 * inp or 0 if inp < 10 */
11042@}
11043@end example
11044
b5ea0f07
LC
11045@anchor{GenericOperandmodifiers}
11046@subsubsection Generic Operand Modifiers
11047@noindent
11048The following table shows the modifiers supported by all targets and their effects:
11049
4ace81b6 11050@multitable @columnfractions 0.15 0.7 0.15
b5ea0f07
LC
11051@headitem Modifier @tab Description @tab Example
11052@item @code{c}
11053@tab Require a constant operand and print the constant expression with no punctuation.
11054@tab @code{%c0}
11055@item @code{n}
11056@tab Like @samp{%c} except that the value of the constant is negated before printing.
11057@tab @code{%n0}
11058@item @code{a}
11059@tab Substitute a memory reference, with the actual operand treated as the address.
11060This may be useful when outputting a ``load address'' instruction, because
11061often the assembler syntax for such an instruction requires you to write the
11062operand as if it were a memory reference.
11063@tab @code{%a0}
11064@item @code{l}
11065@tab Print the label name with no punctuation.
11066@tab @code{%l0}
11067@end multitable
11068
d77de738
ML
11069@anchor{x86Operandmodifiers}
11070@subsubsection x86 Operand Modifiers
11071
11072References to input, output, and goto operands in the assembler template
11073of extended @code{asm} statements can use
11074modifiers to affect the way the operands are formatted in
11075the code output to the assembler. For example, the
11076following code uses the @samp{h} and @samp{b} modifiers for x86:
11077
11078@example
11079uint16_t num;
11080asm volatile ("xchg %h0, %b0" : "+a" (num) );
11081@end example
11082
11083@noindent
11084These modifiers generate this assembler code:
11085
11086@example
11087xchg %ah, %al
11088@end example
11089
11090The rest of this discussion uses the following code for illustrative purposes.
11091
11092@example
11093int main()
11094@{
11095 int iInt = 1;
11096
11097top:
11098
11099 asm volatile goto ("some assembler instructions here"
11100 : /* No outputs. */
11101 : "q" (iInt), "X" (sizeof(unsigned char) + 1), "i" (42)
11102 : /* No clobbers. */
11103 : top);
11104@}
11105@end example
11106
11107With no modifiers, this is what the output from the operands would be
11108for the @samp{att} and @samp{intel} dialects of assembler:
11109
11110@multitable {Operand} {$.L2} {OFFSET FLAT:.L2}
11111@headitem Operand @tab @samp{att} @tab @samp{intel}
11112@item @code{%0}
11113@tab @code{%eax}
11114@tab @code{eax}
11115@item @code{%1}
11116@tab @code{$2}
11117@tab @code{2}
11118@item @code{%3}
11119@tab @code{$.L3}
11120@tab @code{OFFSET FLAT:.L3}
11121@item @code{%4}
11122@tab @code{$8}
11123@tab @code{8}
11124@item @code{%5}
11125@tab @code{%xmm0}
11126@tab @code{xmm0}
11127@item @code{%7}
11128@tab @code{$0}
11129@tab @code{0}
11130@end multitable
11131
11132The table below shows the list of supported modifiers and their effects.
11133
11134@multitable {Modifier} {Print the opcode suffix for the size of th} {Operand} {@samp{att}} {@samp{intel}}
11135@headitem Modifier @tab Description @tab Operand @tab @samp{att} @tab @samp{intel}
11136@item @code{A}
11137@tab Print an absolute memory reference.
11138@tab @code{%A0}
11139@tab @code{*%rax}
11140@tab @code{rax}
11141@item @code{b}
11142@tab Print the QImode name of the register.
11143@tab @code{%b0}
11144@tab @code{%al}
11145@tab @code{al}
11146@item @code{B}
11147@tab print the opcode suffix of b.
11148@tab @code{%B0}
11149@tab @code{b}
11150@tab
11151@item @code{c}
11152@tab Require a constant operand and print the constant expression with no punctuation.
11153@tab @code{%c1}
11154@tab @code{2}
11155@tab @code{2}
11156@item @code{d}
11157@tab print duplicated register operand for AVX instruction.
11158@tab @code{%d5}
11159@tab @code{%xmm0, %xmm0}
11160@tab @code{xmm0, xmm0}
11161@item @code{E}
11162@tab Print the address in Double Integer (DImode) mode (8 bytes) when the target is 64-bit.
11163Otherwise mode is unspecified (VOIDmode).
11164@tab @code{%E1}
11165@tab @code{%(rax)}
11166@tab @code{[rax]}
11167@item @code{g}
11168@tab Print the V16SFmode name of the register.
11169@tab @code{%g0}
11170@tab @code{%zmm0}
11171@tab @code{zmm0}
11172@item @code{h}
11173@tab Print the QImode name for a ``high'' register.
11174@tab @code{%h0}
11175@tab @code{%ah}
11176@tab @code{ah}
11177@item @code{H}
11178@tab Add 8 bytes to an offsettable memory reference. Useful when accessing the
11179high 8 bytes of SSE values. For a memref in (%rax), it generates
11180@tab @code{%H0}
11181@tab @code{8(%rax)}
11182@tab @code{8[rax]}
11183@item @code{k}
11184@tab Print the SImode name of the register.
11185@tab @code{%k0}
11186@tab @code{%eax}
11187@tab @code{eax}
11188@item @code{l}
11189@tab Print the label name with no punctuation.
11190@tab @code{%l3}
11191@tab @code{.L3}
11192@tab @code{.L3}
11193@item @code{L}
11194@tab print the opcode suffix of l.
11195@tab @code{%L0}
11196@tab @code{l}
11197@tab
11198@item @code{N}
11199@tab print maskz.
11200@tab @code{%N7}
11201@tab @code{@{z@}}
11202@tab @code{@{z@}}
11203@item @code{p}
11204@tab Print raw symbol name (without syntax-specific prefixes).
11205@tab @code{%p2}
11206@tab @code{42}
11207@tab @code{42}
11208@item @code{P}
11209@tab If used for a function, print the PLT suffix and generate PIC code.
11210For example, emit @code{foo@@PLT} instead of 'foo' for the function
11211foo(). If used for a constant, drop all syntax-specific prefixes and
11212issue the bare constant. See @code{p} above.
11213@item @code{q}
11214@tab Print the DImode name of the register.
11215@tab @code{%q0}
11216@tab @code{%rax}
11217@tab @code{rax}
11218@item @code{Q}
11219@tab print the opcode suffix of q.
11220@tab @code{%Q0}
11221@tab @code{q}
11222@tab
11223@item @code{R}
11224@tab print embedded rounding and sae.
11225@tab @code{%R4}
11226@tab @code{@{rn-sae@}, }
11227@tab @code{, @{rn-sae@}}
11228@item @code{r}
11229@tab print only sae.
11230@tab @code{%r4}
11231@tab @code{@{sae@}, }
11232@tab @code{, @{sae@}}
11233@item @code{s}
11234@tab print a shift double count, followed by the assemblers argument
11235delimiterprint the opcode suffix of s.
11236@tab @code{%s1}
11237@tab @code{$2, }
11238@tab @code{2, }
11239@item @code{S}
11240@tab print the opcode suffix of s.
11241@tab @code{%S0}
11242@tab @code{s}
11243@tab
11244@item @code{t}
11245@tab print the V8SFmode name of the register.
11246@tab @code{%t5}
11247@tab @code{%ymm0}
11248@tab @code{ymm0}
11249@item @code{T}
11250@tab print the opcode suffix of t.
11251@tab @code{%T0}
11252@tab @code{t}
11253@tab
11254@item @code{V}
11255@tab print naked full integer register name without %.
11256@tab @code{%V0}
11257@tab @code{eax}
11258@tab @code{eax}
11259@item @code{w}
11260@tab Print the HImode name of the register.
11261@tab @code{%w0}
11262@tab @code{%ax}
11263@tab @code{ax}
11264@item @code{W}
11265@tab print the opcode suffix of w.
11266@tab @code{%W0}
11267@tab @code{w}
11268@tab
11269@item @code{x}
11270@tab print the V4SFmode name of the register.
11271@tab @code{%x5}
11272@tab @code{%xmm0}
11273@tab @code{xmm0}
11274@item @code{y}
11275@tab print "st(0)" instead of "st" as a register.
11276@tab @code{%y6}
11277@tab @code{%st(0)}
11278@tab @code{st(0)}
11279@item @code{z}
11280@tab Print the opcode suffix for the size of the current integer operand (one of @code{b}/@code{w}/@code{l}/@code{q}).
11281@tab @code{%z0}
11282@tab @code{l}
11283@tab
11284@item @code{Z}
11285@tab Like @code{z}, with special suffixes for x87 instructions.
11286@end multitable
11287
11288
11289@anchor{x86floatingpointasmoperands}
11290@subsubsection x86 Floating-Point @code{asm} Operands
11291
11292On x86 targets, there are several rules on the usage of stack-like registers
11293in the operands of an @code{asm}. These rules apply only to the operands
11294that are stack-like registers:
11295
11296@enumerate
11297@item
11298Given a set of input registers that die in an @code{asm}, it is
11299necessary to know which are implicitly popped by the @code{asm}, and
11300which must be explicitly popped by GCC@.
11301
11302An input register that is implicitly popped by the @code{asm} must be
11303explicitly clobbered, unless it is constrained to match an
11304output operand.
11305
11306@item
11307For any input register that is implicitly popped by an @code{asm}, it is
11308necessary to know how to adjust the stack to compensate for the pop.
11309If any non-popped input is closer to the top of the reg-stack than
11310the implicitly popped register, it would not be possible to know what the
11311stack looked like---it's not clear how the rest of the stack ``slides
11312up''.
11313
11314All implicitly popped input registers must be closer to the top of
11315the reg-stack than any input that is not implicitly popped.
11316
11317It is possible that if an input dies in an @code{asm}, the compiler might
11318use the input register for an output reload. Consider this example:
11319
11320@smallexample
11321asm ("foo" : "=t" (a) : "f" (b));
11322@end smallexample
11323
11324@noindent
11325This code says that input @code{b} is not popped by the @code{asm}, and that
11326the @code{asm} pushes a result onto the reg-stack, i.e., the stack is one
11327deeper after the @code{asm} than it was before. But, it is possible that
11328reload may think that it can use the same register for both the input and
11329the output.
11330
11331To prevent this from happening,
11332if any input operand uses the @samp{f} constraint, all output register
11333constraints must use the @samp{&} early-clobber modifier.
11334
11335The example above is correctly written as:
11336
11337@smallexample
11338asm ("foo" : "=&t" (a) : "f" (b));
11339@end smallexample
11340
11341@item
11342Some operands need to be in particular places on the stack. All
11343output operands fall in this category---GCC has no other way to
11344know which registers the outputs appear in unless you indicate
11345this in the constraints.
11346
11347Output operands must specifically indicate which register an output
11348appears in after an @code{asm}. @samp{=f} is not allowed: the operand
11349constraints must select a class with a single register.
11350
11351@item
11352Output operands may not be ``inserted'' between existing stack registers.
11353Since no 387 opcode uses a read/write operand, all output operands
11354are dead before the @code{asm}, and are pushed by the @code{asm}.
11355It makes no sense to push anywhere but the top of the reg-stack.
11356
11357Output operands must start at the top of the reg-stack: output
11358operands may not ``skip'' a register.
11359
11360@item
11361Some @code{asm} statements may need extra stack space for internal
11362calculations. This can be guaranteed by clobbering stack registers
11363unrelated to the inputs and outputs.
11364
11365@end enumerate
11366
11367This @code{asm}
11368takes one input, which is internally popped, and produces two outputs.
11369
11370@smallexample
11371asm ("fsincos" : "=t" (cos), "=u" (sin) : "0" (inp));
11372@end smallexample
11373
11374@noindent
11375This @code{asm} takes two inputs, which are popped by the @code{fyl2xp1} opcode,
11376and replaces them with one output. The @code{st(1)} clobber is necessary
11377for the compiler to know that @code{fyl2xp1} pops both inputs.
11378
11379@smallexample
11380asm ("fyl2xp1" : "=t" (result) : "0" (x), "u" (y) : "st(1)");
11381@end smallexample
11382
11383@anchor{msp430Operandmodifiers}
11384@subsubsection MSP430 Operand Modifiers
11385
11386The list below describes the supported modifiers and their effects for MSP430.
11387
11388@multitable @columnfractions .10 .90
11389@headitem Modifier @tab Description
11390@item @code{A} @tab Select low 16-bits of the constant/register/memory operand.
11391@item @code{B} @tab Select high 16-bits of the constant/register/memory
11392operand.
11393@item @code{C} @tab Select bits 32-47 of the constant/register/memory operand.
11394@item @code{D} @tab Select bits 48-63 of the constant/register/memory operand.
11395@item @code{H} @tab Equivalent to @code{B} (for backwards compatibility).
11396@item @code{I} @tab Print the inverse (logical @code{NOT}) of the constant
11397value.
11398@item @code{J} @tab Print an integer without a @code{#} prefix.
11399@item @code{L} @tab Equivalent to @code{A} (for backwards compatibility).
11400@item @code{O} @tab Offset of the current frame from the top of the stack.
11401@item @code{Q} @tab Use the @code{A} instruction postfix.
11402@item @code{R} @tab Inverse of condition code, for unsigned comparisons.
11403@item @code{W} @tab Subtract 16 from the constant value.
11404@item @code{X} @tab Use the @code{X} instruction postfix.
11405@item @code{Y} @tab Subtract 4 from the constant value.
11406@item @code{Z} @tab Subtract 1 from the constant value.
11407@item @code{b} @tab Append @code{.B}, @code{.W} or @code{.A} to the
11408instruction, depending on the mode.
11409@item @code{d} @tab Offset 1 byte of a memory reference or constant value.
11410@item @code{e} @tab Offset 3 bytes of a memory reference or constant value.
11411@item @code{f} @tab Offset 5 bytes of a memory reference or constant value.
11412@item @code{g} @tab Offset 7 bytes of a memory reference or constant value.
11413@item @code{p} @tab Print the value of 2, raised to the power of the given
11414constant. Used to select the specified bit position.
11415@item @code{r} @tab Inverse of condition code, for signed comparisons.
11416@item @code{x} @tab Equivialent to @code{X}, but only for pointers.
11417@end multitable
11418
b5ea0f07
LC
11419@anchor{loongarchOperandmodifiers}
11420@subsubsection LoongArch Operand Modifiers
11421
11422The list below describes the supported modifiers and their effects for LoongArch.
11423
11424@multitable @columnfractions .10 .90
11425@headitem Modifier @tab Description
11426@item @code{d} @tab Same as @code{c}.
11427@item @code{i} @tab Print the character ''@code{i}'' if the operand is not a register.
11428@item @code{m} @tab Same as @code{c}, but the printed value is @code{operand - 1}.
11429@item @code{X} @tab Print a constant integer operand in hexadecimal.
11430@item @code{z} @tab Print the operand in its unmodified form, followed by a comma.
11431@end multitable
11432
11433
d77de738
ML
11434@lowersections
11435@include md.texi
11436@raisesections
11437
11438@node Asm Labels
11439@subsection Controlling Names Used in Assembler Code
11440@cindex assembler names for identifiers
11441@cindex names used in assembler code
11442@cindex identifiers, names in assembler code
11443
11444You can specify the name to be used in the assembler code for a C
11445function or variable by writing the @code{asm} (or @code{__asm__})
11446keyword after the declarator.
11447It is up to you to make sure that the assembler names you choose do not
11448conflict with any other assembler symbols, or reference registers.
11449
11450@subsubheading Assembler names for data
11451
11452This sample shows how to specify the assembler name for data:
11453
11454@smallexample
11455int foo asm ("myfoo") = 2;
11456@end smallexample
11457
11458@noindent
11459This specifies that the name to be used for the variable @code{foo} in
11460the assembler code should be @samp{myfoo} rather than the usual
11461@samp{_foo}.
11462
11463On systems where an underscore is normally prepended to the name of a C
11464variable, this feature allows you to define names for the
11465linker that do not start with an underscore.
11466
11467GCC does not support using this feature with a non-static local variable
11468since such variables do not have assembler names. If you are
11469trying to put the variable in a particular register, see
11470@ref{Explicit Register Variables}.
11471
11472@subsubheading Assembler names for functions
11473
11474To specify the assembler name for functions, write a declaration for the
11475function before its definition and put @code{asm} there, like this:
11476
11477@smallexample
11478int func (int x, int y) asm ("MYFUNC");
11479
11480int func (int x, int y)
11481@{
11482 /* @r{@dots{}} */
11483@end smallexample
11484
11485@noindent
11486This specifies that the name to be used for the function @code{func} in
11487the assembler code should be @code{MYFUNC}.
11488
11489@node Explicit Register Variables
11490@subsection Variables in Specified Registers
11491@anchor{Explicit Reg Vars}
11492@cindex explicit register variables
11493@cindex variables in specified registers
11494@cindex specified registers
11495
11496GNU C allows you to associate specific hardware registers with C
11497variables. In almost all cases, allowing the compiler to assign
11498registers produces the best code. However under certain unusual
11499circumstances, more precise control over the variable storage is
11500required.
11501
11502Both global and local variables can be associated with a register. The
11503consequences of performing this association are very different between
11504the two, as explained in the sections below.
11505
11506@menu
11507* Global Register Variables:: Variables declared at global scope.
11508* Local Register Variables:: Variables declared within a function.
11509@end menu
11510
11511@node Global Register Variables
11512@subsubsection Defining Global Register Variables
11513@anchor{Global Reg Vars}
11514@cindex global register variables
11515@cindex registers, global variables in
11516@cindex registers, global allocation
11517
11518You can define a global register variable and associate it with a specified
11519register like this:
11520
11521@smallexample
11522register int *foo asm ("r12");
11523@end smallexample
11524
11525@noindent
11526Here @code{r12} is the name of the register that should be used. Note that
11527this is the same syntax used for defining local register variables, but for
11528a global variable the declaration appears outside a function. The
11529@code{register} keyword is required, and cannot be combined with
11530@code{static}. The register name must be a valid register name for the
11531target platform.
11532
11533Do not use type qualifiers such as @code{const} and @code{volatile}, as
11534the outcome may be contrary to expectations. In particular, using the
11535@code{volatile} qualifier does not fully prevent the compiler from
11536optimizing accesses to the register.
11537
11538Registers are a scarce resource on most systems and allowing the
11539compiler to manage their usage usually results in the best code. However,
11540under special circumstances it can make sense to reserve some globally.
11541For example this may be useful in programs such as programming language
11542interpreters that have a couple of global variables that are accessed
11543very often.
11544
11545After defining a global register variable, for the current compilation
11546unit:
11547
11548@itemize @bullet
11549@item If the register is a call-saved register, call ABI is affected:
11550the register will not be restored in function epilogue sequences after
11551the variable has been assigned. Therefore, functions cannot safely
11552return to callers that assume standard ABI.
11553@item Conversely, if the register is a call-clobbered register, making
11554calls to functions that use standard ABI may lose contents of the variable.
11555Such calls may be created by the compiler even if none are evident in
11556the original program, for example when libgcc functions are used to
11557make up for unavailable instructions.
11558@item Accesses to the variable may be optimized as usual and the register
11559remains available for allocation and use in any computations, provided that
11560observable values of the variable are not affected.
11561@item If the variable is referenced in inline assembly, the type of access
11562must be provided to the compiler via constraints (@pxref{Constraints}).
11563Accesses from basic asms are not supported.
11564@end itemize
11565
11566Note that these points @emph{only} apply to code that is compiled with the
11567definition. The behavior of code that is merely linked in (for example
11568code from libraries) is not affected.
11569
11570If you want to recompile source files that do not actually use your global
11571register variable so they do not use the specified register for any other
11572purpose, you need not actually add the global register declaration to
11573their source code. It suffices to specify the compiler option
11574@option{-ffixed-@var{reg}} (@pxref{Code Gen Options}) to reserve the
11575register.
11576
11577@subsubheading Declaring the variable
11578
11579Global register variables cannot have initial values, because an
11580executable file has no means to supply initial contents for a register.
11581
11582When selecting a register, choose one that is normally saved and
11583restored by function calls on your machine. This ensures that code
11584which is unaware of this reservation (such as library routines) will
11585restore it before returning.
11586
11587On machines with register windows, be sure to choose a global
11588register that is not affected magically by the function call mechanism.
11589
11590@subsubheading Using the variable
11591
11592@cindex @code{qsort}, and global register variables
11593When calling routines that are not aware of the reservation, be
11594cautious if those routines call back into code which uses them. As an
11595example, if you call the system library version of @code{qsort}, it may
11596clobber your registers during execution, but (if you have selected
11597appropriate registers) it will restore them before returning. However
11598it will @emph{not} restore them before calling @code{qsort}'s comparison
11599function. As a result, global values will not reliably be available to
11600the comparison function unless the @code{qsort} function itself is rebuilt.
11601
11602Similarly, it is not safe to access the global register variables from signal
11603handlers or from more than one thread of control. Unless you recompile
11604them specially for the task at hand, the system library routines may
11605temporarily use the register for other things. Furthermore, since the register
11606is not reserved exclusively for the variable, accessing it from handlers of
11607asynchronous signals may observe unrelated temporary values residing in the
11608register.
11609
11610@cindex register variable after @code{longjmp}
11611@cindex global register after @code{longjmp}
11612@cindex value after @code{longjmp}
11613@findex longjmp
11614@findex setjmp
11615On most machines, @code{longjmp} restores to each global register
11616variable the value it had at the time of the @code{setjmp}. On some
11617machines, however, @code{longjmp} does not change the value of global
11618register variables. To be portable, the function that called @code{setjmp}
11619should make other arrangements to save the values of the global register
11620variables, and to restore them in a @code{longjmp}. This way, the same
11621thing happens regardless of what @code{longjmp} does.
11622
11623@node Local Register Variables
11624@subsubsection Specifying Registers for Local Variables
11625@anchor{Local Reg Vars}
11626@cindex local variables, specifying registers
11627@cindex specifying registers for local variables
11628@cindex registers for local variables
11629
11630You can define a local register variable and associate it with a specified
11631register like this:
11632
11633@smallexample
11634register int *foo asm ("r12");
11635@end smallexample
11636
11637@noindent
11638Here @code{r12} is the name of the register that should be used. Note
11639that this is the same syntax used for defining global register variables,
11640but for a local variable the declaration appears within a function. The
11641@code{register} keyword is required, and cannot be combined with
11642@code{static}. The register name must be a valid register name for the
11643target platform.
11644
11645Do not use type qualifiers such as @code{const} and @code{volatile}, as
11646the outcome may be contrary to expectations. In particular, when the
11647@code{const} qualifier is used, the compiler may substitute the
11648variable with its initializer in @code{asm} statements, which may cause
11649the corresponding operand to appear in a different register.
11650
11651As with global register variables, it is recommended that you choose
11652a register that is normally saved and restored by function calls on your
11653machine, so that calls to library routines will not clobber it.
11654
11655The only supported use for this feature is to specify registers
11656for input and output operands when calling Extended @code{asm}
11657(@pxref{Extended Asm}). This may be necessary if the constraints for a
11658particular machine don't provide sufficient control to select the desired
11659register. To force an operand into a register, create a local variable
11660and specify the register name after the variable's declaration. Then use
11661the local variable for the @code{asm} operand and specify any constraint
11662letter that matches the register:
11663
11664@smallexample
11665register int *p1 asm ("r0") = @dots{};
11666register int *p2 asm ("r1") = @dots{};
11667register int *result asm ("r0");
11668asm ("sysint" : "=r" (result) : "0" (p1), "r" (p2));
11669@end smallexample
11670
11671@emph{Warning:} In the above example, be aware that a register (for example
11672@code{r0}) can be call-clobbered by subsequent code, including function
11673calls and library calls for arithmetic operators on other variables (for
11674example the initialization of @code{p2}). In this case, use temporary
11675variables for expressions between the register assignments:
11676
11677@smallexample
11678int t1 = @dots{};
11679register int *p1 asm ("r0") = @dots{};
11680register int *p2 asm ("r1") = t1;
11681register int *result asm ("r0");
11682asm ("sysint" : "=r" (result) : "0" (p1), "r" (p2));
11683@end smallexample
11684
11685Defining a register variable does not reserve the register. Other than
11686when invoking the Extended @code{asm}, the contents of the specified
11687register are not guaranteed. For this reason, the following uses
11688are explicitly @emph{not} supported. If they appear to work, it is only
11689happenstance, and may stop working as intended due to (seemingly)
11690unrelated changes in surrounding code, or even minor changes in the
11691optimization of a future version of gcc:
11692
11693@itemize @bullet
11694@item Passing parameters to or from Basic @code{asm}
11695@item Passing parameters to or from Extended @code{asm} without using input
11696or output operands.
11697@item Passing parameters to or from routines written in assembler (or
11698other languages) using non-standard calling conventions.
11699@end itemize
11700
11701Some developers use Local Register Variables in an attempt to improve
11702gcc's allocation of registers, especially in large functions. In this
11703case the register name is essentially a hint to the register allocator.
11704While in some instances this can generate better code, improvements are
11705subject to the whims of the allocator/optimizers. Since there are no
11706guarantees that your improvements won't be lost, this usage of Local
11707Register Variables is discouraged.
11708
11709On the MIPS platform, there is related use for local register variables
11710with slightly different characteristics (@pxref{MIPS Coprocessors,,
11711Defining coprocessor specifics for MIPS targets, gccint,
11712GNU Compiler Collection (GCC) Internals}).
11713
11714@node Size of an asm
11715@subsection Size of an @code{asm}
11716
11717Some targets require that GCC track the size of each instruction used
11718in order to generate correct code. Because the final length of the
11719code produced by an @code{asm} statement is only known by the
11720assembler, GCC must make an estimate as to how big it will be. It
11721does this by counting the number of instructions in the pattern of the
11722@code{asm} and multiplying that by the length of the longest
11723instruction supported by that processor. (When working out the number
11724of instructions, it assumes that any occurrence of a newline or of
11725whatever statement separator character is supported by the assembler ---
11726typically @samp{;} --- indicates the end of an instruction.)
11727
11728Normally, GCC's estimate is adequate to ensure that correct
11729code is generated, but it is possible to confuse the compiler if you use
11730pseudo instructions or assembler macros that expand into multiple real
11731instructions, or if you use assembler directives that expand to more
11732space in the object file than is needed for a single instruction.
11733If this happens then the assembler may produce a diagnostic saying that
11734a label is unreachable.
11735
11736@cindex @code{asm inline}
11737This size is also used for inlining decisions. If you use @code{asm inline}
11738instead of just @code{asm}, then for inlining purposes the size of the asm
11739is taken as the minimum size, ignoring how many instructions GCC thinks it is.
11740
11741@node Alternate Keywords
11742@section Alternate Keywords
11743@cindex alternate keywords
11744@cindex keywords, alternate
11745
11746@option{-ansi} and the various @option{-std} options disable certain
11747keywords. This causes trouble when you want to use GNU C extensions, or
11748a general-purpose header file that should be usable by all programs,
11749including ISO C programs. The keywords @code{asm}, @code{typeof} and
11750@code{inline} are not available in programs compiled with
11751@option{-ansi} or @option{-std} (although @code{inline} can be used in a
11752program compiled with @option{-std=c99} or a later standard). The
11753ISO C99 keyword
11754@code{restrict} is only available when @option{-std=gnu99} (which will
11755eventually be the default) or @option{-std=c99} (or the equivalent
11756@option{-std=iso9899:1999}), or an option for a later standard
11757version, is used.
11758
11759The way to solve these problems is to put @samp{__} at the beginning and
11760end of each problematical keyword. For example, use @code{__asm__}
11761instead of @code{asm}, and @code{__inline__} instead of @code{inline}.
11762
11763Other C compilers won't accept these alternative keywords; if you want to
11764compile with another compiler, you can define the alternate keywords as
11765macros to replace them with the customary keywords. It looks like this:
11766
11767@smallexample
11768#ifndef __GNUC__
11769#define __asm__ asm
11770#endif
11771@end smallexample
11772
11773@findex __extension__
11774@opindex pedantic
11775@option{-pedantic} and other options cause warnings for many GNU C extensions.
11776You can
11777prevent such warnings within one expression by writing
11778@code{__extension__} before the expression. @code{__extension__} has no
11779effect aside from this.
11780
11781@node Incomplete Enums
11782@section Incomplete @code{enum} Types
11783
11784You can define an @code{enum} tag without specifying its possible values.
11785This results in an incomplete type, much like what you get if you write
11786@code{struct foo} without describing the elements. A later declaration
11787that does specify the possible values completes the type.
11788
11789You cannot allocate variables or storage using the type while it is
11790incomplete. However, you can work with pointers to that type.
11791
11792This extension may not be very useful, but it makes the handling of
11793@code{enum} more consistent with the way @code{struct} and @code{union}
11794are handled.
11795
11796This extension is not supported by GNU C++.
11797
11798@node Function Names
11799@section Function Names as Strings
11800@cindex @code{__func__} identifier
11801@cindex @code{__FUNCTION__} identifier
11802@cindex @code{__PRETTY_FUNCTION__} identifier
11803
11804GCC provides three magic constants that hold the name of the current
11805function as a string. In C++11 and later modes, all three are treated
11806as constant expressions and can be used in @code{constexpr} constexts.
11807The first of these constants is @code{__func__}, which is part of
11808the C99 standard:
11809
11810The identifier @code{__func__} is implicitly declared by the translator
11811as if, immediately following the opening brace of each function
11812definition, the declaration
11813
11814@smallexample
11815static const char __func__[] = "function-name";
11816@end smallexample
11817
11818@noindent
11819appeared, where function-name is the name of the lexically-enclosing
11820function. This name is the unadorned name of the function. As an
11821extension, at file (or, in C++, namespace scope), @code{__func__}
11822evaluates to the empty string.
11823
11824@code{__FUNCTION__} is another name for @code{__func__}, provided for
11825backward compatibility with old versions of GCC.
11826
11827In C, @code{__PRETTY_FUNCTION__} is yet another name for
11828@code{__func__}, except that at file scope (or, in C++, namespace scope),
11829it evaluates to the string @code{"top level"}. In addition, in C++,
11830@code{__PRETTY_FUNCTION__} contains the signature of the function as
11831well as its bare name. For example, this program:
11832
11833@smallexample
11834extern "C" int printf (const char *, ...);
11835
11836class a @{
11837 public:
11838 void sub (int i)
11839 @{
11840 printf ("__FUNCTION__ = %s\n", __FUNCTION__);
11841 printf ("__PRETTY_FUNCTION__ = %s\n", __PRETTY_FUNCTION__);
11842 @}
11843@};
11844
11845int
11846main (void)
11847@{
11848 a ax;
11849 ax.sub (0);
11850 return 0;
11851@}
11852@end smallexample
11853
11854@noindent
11855gives this output:
11856
11857@smallexample
11858__FUNCTION__ = sub
11859__PRETTY_FUNCTION__ = void a::sub(int)
11860@end smallexample
11861
11862These identifiers are variables, not preprocessor macros, and may not
11863be used to initialize @code{char} arrays or be concatenated with string
11864literals.
11865
11866@node Return Address
11867@section Getting the Return or Frame Address of a Function
11868
11869These functions may be used to get information about the callers of a
11870function.
11871
f25efe50 11872@defbuiltin{{void *} __builtin_return_address (unsigned int @var{level})}
d77de738
ML
11873This function returns the return address of the current function, or of
11874one of its callers. The @var{level} argument is number of frames to
11875scan up the call stack. A value of @code{0} yields the return address
11876of the current function, a value of @code{1} yields the return address
11877of the caller of the current function, and so forth. When inlining
11878the expected behavior is that the function returns the address of
11879the function that is returned to. To work around this behavior use
11880the @code{noinline} function attribute.
11881
11882The @var{level} argument must be a constant integer.
11883
11884On some machines it may be impossible to determine the return address of
11885any function other than the current one; in such cases, or when the top
11886of the stack has been reached, this function returns an unspecified
11887value. In addition, @code{__builtin_frame_address} may be used
11888to determine if the top of the stack has been reached.
11889
11890Additional post-processing of the returned value may be needed, see
11891@code{__builtin_extract_return_addr}.
11892
11893The stored representation of the return address in memory may be different
11894from the address returned by @code{__builtin_return_address}. For example,
11895on AArch64 the stored address may be mangled with return address signing
11896whereas the address returned by @code{__builtin_return_address} is not.
11897
11898Calling this function with a nonzero argument can have unpredictable
11899effects, including crashing the calling program. As a result, calls
11900that are considered unsafe are diagnosed when the @option{-Wframe-address}
11901option is in effect. Such calls should only be made in debugging
11902situations.
11903
11904On targets where code addresses are representable as @code{void *},
11905@smallexample
11906void *addr = __builtin_extract_return_addr (__builtin_return_address (0));
11907@end smallexample
11908gives the code address where the current function would return. For example,
11909such an address may be used with @code{dladdr} or other interfaces that work
11910with code addresses.
f25efe50 11911@enddefbuiltin
d77de738 11912
f25efe50 11913@defbuiltin{{void *} __builtin_extract_return_addr (void *@var{addr})}
d77de738
ML
11914The address as returned by @code{__builtin_return_address} may have to be fed
11915through this function to get the actual encoded address. For example, on the
1191631-bit S/390 platform the highest bit has to be masked out, or on SPARC
11917platforms an offset has to be added for the true next instruction to be
11918executed.
11919
11920If no fixup is needed, this function simply passes through @var{addr}.
f25efe50 11921@enddefbuiltin
d77de738 11922
f25efe50 11923@defbuiltin{{void *} __builtin_frob_return_addr (void *@var{addr})}
d77de738 11924This function does the reverse of @code{__builtin_extract_return_addr}.
f25efe50 11925@enddefbuiltin
d77de738 11926
f25efe50 11927@defbuiltin{{void *} __builtin_frame_address (unsigned int @var{level})}
d77de738
ML
11928This function is similar to @code{__builtin_return_address}, but it
11929returns the address of the function frame rather than the return address
11930of the function. Calling @code{__builtin_frame_address} with a value of
11931@code{0} yields the frame address of the current function, a value of
11932@code{1} yields the frame address of the caller of the current function,
11933and so forth.
11934
11935The frame is the area on the stack that holds local variables and saved
11936registers. The frame address is normally the address of the first word
11937pushed on to the stack by the function. However, the exact definition
11938depends upon the processor and the calling convention. If the processor
11939has a dedicated frame pointer register, and the function has a frame,
11940then @code{__builtin_frame_address} returns the value of the frame
11941pointer register.
11942
11943On some machines it may be impossible to determine the frame address of
11944any function other than the current one; in such cases, or when the top
11945of the stack has been reached, this function returns @code{0} if
11946the first frame pointer is properly initialized by the startup code.
11947
11948Calling this function with a nonzero argument can have unpredictable
11949effects, including crashing the calling program. As a result, calls
11950that are considered unsafe are diagnosed when the @option{-Wframe-address}
11951option is in effect. Such calls should only be made in debugging
11952situations.
f25efe50 11953@enddefbuiltin
d77de738
ML
11954
11955@node Vector Extensions
11956@section Using Vector Instructions through Built-in Functions
11957
11958On some targets, the instruction set contains SIMD vector instructions which
11959operate on multiple values contained in one large register at the same time.
11960For example, on the x86 the MMX, 3DNow!@: and SSE extensions can be used
11961this way.
11962
11963The first step in using these extensions is to provide the necessary data
11964types. This should be done using an appropriate @code{typedef}:
11965
11966@smallexample
11967typedef int v4si __attribute__ ((vector_size (16)));
11968@end smallexample
11969
11970@noindent
11971The @code{int} type specifies the @dfn{base type}, while the attribute specifies
11972the vector size for the variable, measured in bytes. For example, the
11973declaration above causes the compiler to set the mode for the @code{v4si}
11974type to be 16 bytes wide and divided into @code{int} sized units. For
11975a 32-bit @code{int} this means a vector of 4 units of 4 bytes, and the
11976corresponding mode of @code{foo} is @acronym{V4SI}.
11977
11978The @code{vector_size} attribute is only applicable to integral and
11979floating scalars, although arrays, pointers, and function return values
11980are allowed in conjunction with this construct. Only sizes that are
11981positive power-of-two multiples of the base type size are currently allowed.
11982
11983All the basic integer types can be used as base types, both as signed
11984and as unsigned: @code{char}, @code{short}, @code{int}, @code{long},
11985@code{long long}. In addition, @code{float} and @code{double} can be
11986used to build floating-point vector types.
11987
11988Specifying a combination that is not valid for the current architecture
11989causes GCC to synthesize the instructions using a narrower mode.
11990For example, if you specify a variable of type @code{V4SI} and your
11991architecture does not allow for this specific SIMD type, GCC
11992produces code that uses 4 @code{SIs}.
11993
11994The types defined in this manner can be used with a subset of normal C
11995operations. Currently, GCC allows using the following operators
11996on these types: @code{+, -, *, /, unary minus, ^, |, &, ~, %}@.
11997
11998The operations behave like C++ @code{valarrays}. Addition is defined as
11999the addition of the corresponding elements of the operands. For
12000example, in the code below, each of the 4 elements in @var{a} is
12001added to the corresponding 4 elements in @var{b} and the resulting
12002vector is stored in @var{c}.
12003
12004@smallexample
12005typedef int v4si __attribute__ ((vector_size (16)));
12006
12007v4si a, b, c;
12008
12009c = a + b;
12010@end smallexample
12011
12012Subtraction, multiplication, division, and the logical operations
12013operate in a similar manner. Likewise, the result of using the unary
12014minus or complement operators on a vector type is a vector whose
12015elements are the negative or complemented values of the corresponding
12016elements in the operand.
12017
12018It is possible to use shifting operators @code{<<}, @code{>>} on
12019integer-type vectors. The operation is defined as following: @code{@{a0,
12020a1, @dots{}, an@} >> @{b0, b1, @dots{}, bn@} == @{a0 >> b0, a1 >> b1,
12021@dots{}, an >> bn@}}@. Vector operands must have the same number of
12022elements.
12023
12024For convenience, it is allowed to use a binary vector operation
12025where one operand is a scalar. In that case the compiler transforms
12026the scalar operand into a vector where each element is the scalar from
12027the operation. The transformation happens only if the scalar could be
12028safely converted to the vector-element type.
12029Consider the following code.
12030
12031@smallexample
12032typedef int v4si __attribute__ ((vector_size (16)));
12033
12034v4si a, b, c;
12035long l;
12036
12037a = b + 1; /* a = b + @{1,1,1,1@}; */
12038a = 2 * b; /* a = @{2,2,2,2@} * b; */
12039
12040a = l + a; /* Error, cannot convert long to int. */
12041@end smallexample
12042
12043Vectors can be subscripted as if the vector were an array with
12044the same number of elements and base type. Out of bound accesses
12045invoke undefined behavior at run time. Warnings for out of bound
12046accesses for vector subscription can be enabled with
12047@option{-Warray-bounds}.
12048
12049Vector comparison is supported with standard comparison
12050operators: @code{==, !=, <, <=, >, >=}. Comparison operands can be
12051vector expressions of integer-type or real-type. Comparison between
12052integer-type vectors and real-type vectors are not supported. The
12053result of the comparison is a vector of the same width and number of
12054elements as the comparison operands with a signed integral element
12055type.
12056
12057Vectors are compared element-wise producing 0 when comparison is false
12058and -1 (constant of the appropriate type where all bits are set)
12059otherwise. Consider the following example.
12060
12061@smallexample
12062typedef int v4si __attribute__ ((vector_size (16)));
12063
12064v4si a = @{1,2,3,4@};
12065v4si b = @{3,2,1,4@};
12066v4si c;
12067
12068c = a > b; /* The result would be @{0, 0,-1, 0@} */
12069c = a == b; /* The result would be @{0,-1, 0,-1@} */
12070@end smallexample
12071
12072In C++, the ternary operator @code{?:} is available. @code{a?b:c}, where
12073@code{b} and @code{c} are vectors of the same type and @code{a} is an
12074integer vector with the same number of elements of the same size as @code{b}
12075and @code{c}, computes all three arguments and creates a vector
12076@code{@{a[0]?b[0]:c[0], a[1]?b[1]:c[1], @dots{}@}}. Note that unlike in
12077OpenCL, @code{a} is thus interpreted as @code{a != 0} and not @code{a < 0}.
12078As in the case of binary operations, this syntax is also accepted when
12079one of @code{b} or @code{c} is a scalar that is then transformed into a
12080vector. If both @code{b} and @code{c} are scalars and the type of
12081@code{true?b:c} has the same size as the element type of @code{a}, then
12082@code{b} and @code{c} are converted to a vector type whose elements have
12083this type and with the same number of elements as @code{a}.
12084
12085In C++, the logic operators @code{!, &&, ||} are available for vectors.
12086@code{!v} is equivalent to @code{v == 0}, @code{a && b} is equivalent to
12087@code{a!=0 & b!=0} and @code{a || b} is equivalent to @code{a!=0 | b!=0}.
12088For mixed operations between a scalar @code{s} and a vector @code{v},
12089@code{s && v} is equivalent to @code{s?v!=0:0} (the evaluation is
12090short-circuit) and @code{v && s} is equivalent to @code{v!=0 & (s?-1:0)}.
12091
12092@findex __builtin_shuffle
12093Vector shuffling is available using functions
12094@code{__builtin_shuffle (vec, mask)} and
12095@code{__builtin_shuffle (vec0, vec1, mask)}.
12096Both functions construct a permutation of elements from one or two
12097vectors and return a vector of the same type as the input vector(s).
12098The @var{mask} is an integral vector with the same width (@var{W})
12099and element count (@var{N}) as the output vector.
12100
12101The elements of the input vectors are numbered in memory ordering of
12102@var{vec0} beginning at 0 and @var{vec1} beginning at @var{N}. The
12103elements of @var{mask} are considered modulo @var{N} in the single-operand
12104case and modulo @math{2*@var{N}} in the two-operand case.
12105
12106Consider the following example,
12107
12108@smallexample
12109typedef int v4si __attribute__ ((vector_size (16)));
12110
12111v4si a = @{1,2,3,4@};
12112v4si b = @{5,6,7,8@};
12113v4si mask1 = @{0,1,1,3@};
12114v4si mask2 = @{0,4,2,5@};
12115v4si res;
12116
12117res = __builtin_shuffle (a, mask1); /* res is @{1,2,2,4@} */
12118res = __builtin_shuffle (a, b, mask2); /* res is @{1,5,3,6@} */
12119@end smallexample
12120
12121Note that @code{__builtin_shuffle} is intentionally semantically
12122compatible with the OpenCL @code{shuffle} and @code{shuffle2} functions.
12123
12124You can declare variables and use them in function calls and returns, as
12125well as in assignments and some casts. You can specify a vector type as
12126a return type for a function. Vector types can also be used as function
12127arguments. It is possible to cast from one vector type to another,
12128provided they are of the same size (in fact, you can also cast vectors
12129to and from other datatypes of the same size).
12130
12131You cannot operate between vectors of different lengths or different
12132signedness without a cast.
12133
12134@findex __builtin_shufflevector
12135Vector shuffling is available using the
12136@code{__builtin_shufflevector (vec1, vec2, index...)}
12137function. @var{vec1} and @var{vec2} must be expressions with
12138vector type with a compatible element type. The result of
12139@code{__builtin_shufflevector} is a vector with the same element type
12140as @var{vec1} and @var{vec2} but that has an element count equal to
12141the number of indices specified.
12142
12143The @var{index} arguments are a list of integers that specify the
12144elements indices of the first two vectors that should be extracted and
12145returned in a new vector. These element indices are numbered sequentially
12146starting with the first vector, continuing into the second vector.
12147An index of -1 can be used to indicate that the corresponding element in
12148the returned vector is a don't care and can be freely chosen to optimized
12149the generated code sequence performing the shuffle operation.
12150
12151Consider the following example,
12152@smallexample
12153typedef int v4si __attribute__ ((vector_size (16)));
12154typedef int v8si __attribute__ ((vector_size (32)));
12155
12156v8si a = @{1,-2,3,-4,5,-6,7,-8@};
12157v4si b = __builtin_shufflevector (a, a, 0, 2, 4, 6); /* b is @{1,3,5,7@} */
12158v4si c = @{-2,-4,-6,-8@};
12159v8si d = __builtin_shufflevector (c, b, 4, 0, 5, 1, 6, 2, 7, 3); /* d is a */
12160@end smallexample
12161
12162@findex __builtin_convertvector
12163Vector conversion is available using the
12164@code{__builtin_convertvector (vec, vectype)}
12165function. @var{vec} must be an expression with integral or floating
12166vector type and @var{vectype} an integral or floating vector type with the
12167same number of elements. The result has @var{vectype} type and value of
12168a C cast of every element of @var{vec} to the element type of @var{vectype}.
12169
12170Consider the following example,
12171@smallexample
12172typedef int v4si __attribute__ ((vector_size (16)));
12173typedef float v4sf __attribute__ ((vector_size (16)));
12174typedef double v4df __attribute__ ((vector_size (32)));
12175typedef unsigned long long v4di __attribute__ ((vector_size (32)));
12176
12177v4si a = @{1,-2,3,-4@};
12178v4sf b = @{1.5f,-2.5f,3.f,7.f@};
12179v4di c = @{1ULL,5ULL,0ULL,10ULL@};
12180v4sf d = __builtin_convertvector (a, v4sf); /* d is @{1.f,-2.f,3.f,-4.f@} */
12181/* Equivalent of:
12182 v4sf d = @{ (float)a[0], (float)a[1], (float)a[2], (float)a[3] @}; */
12183v4df e = __builtin_convertvector (a, v4df); /* e is @{1.,-2.,3.,-4.@} */
12184v4df f = __builtin_convertvector (b, v4df); /* f is @{1.5,-2.5,3.,7.@} */
12185v4si g = __builtin_convertvector (f, v4si); /* g is @{1,-2,3,7@} */
12186v4si h = __builtin_convertvector (c, v4si); /* h is @{1,5,0,10@} */
12187@end smallexample
12188
12189@cindex vector types, using with x86 intrinsics
12190Sometimes it is desirable to write code using a mix of generic vector
12191operations (for clarity) and machine-specific vector intrinsics (to
12192access vector instructions that are not exposed via generic built-ins).
12193On x86, intrinsic functions for integer vectors typically use the same
12194vector type @code{__m128i} irrespective of how they interpret the vector,
12195making it necessary to cast their arguments and return values from/to
12196other vector types. In C, you can make use of a @code{union} type:
12197@c In C++ such type punning via a union is not allowed by the language
12198@smallexample
12199#include <immintrin.h>
12200
12201typedef unsigned char u8x16 __attribute__ ((vector_size (16)));
12202typedef unsigned int u32x4 __attribute__ ((vector_size (16)));
12203
12204typedef union @{
12205 __m128i mm;
12206 u8x16 u8;
12207 u32x4 u32;
12208@} v128;
12209@end smallexample
12210
12211@noindent
12212for variables that can be used with both built-in operators and x86
12213intrinsics:
12214
12215@smallexample
12216v128 x, y = @{ 0 @};
12217memcpy (&x, ptr, sizeof x);
12218y.u8 += 0x80;
12219x.mm = _mm_adds_epu8 (x.mm, y.mm);
12220x.u32 &= 0xffffff;
12221
12222/* Instead of a variable, a compound literal may be used to pass the
12223 return value of an intrinsic call to a function expecting the union: */
12224v128 foo (v128);
12225x = foo ((v128) @{_mm_adds_epu8 (x.mm, y.mm)@});
12226@c This could be done implicitly with __attribute__((transparent_union)),
12227@c but GCC does not accept it for unions of vector types (PR 88955).
12228@end smallexample
12229
12230@node Offsetof
12231@section Support for @code{offsetof}
12232@findex __builtin_offsetof
12233
12234GCC implements for both C and C++ a syntactic extension to implement
12235the @code{offsetof} macro.
12236
12237@smallexample
12238primary:
12239 "__builtin_offsetof" "(" @code{typename} "," offsetof_member_designator ")"
12240
12241offsetof_member_designator:
12242 @code{identifier}
12243 | offsetof_member_designator "." @code{identifier}
12244 | offsetof_member_designator "[" @code{expr} "]"
12245@end smallexample
12246
12247This extension is sufficient such that
12248
12249@smallexample
12250#define offsetof(@var{type}, @var{member}) __builtin_offsetof (@var{type}, @var{member})
12251@end smallexample
12252
12253@noindent
12254is a suitable definition of the @code{offsetof} macro. In C++, @var{type}
12255may be dependent. In either case, @var{member} may consist of a single
12256identifier, or a sequence of member accesses and array references.
12257
12258@node __sync Builtins
12259@section Legacy @code{__sync} Built-in Functions for Atomic Memory Access
12260
12261The following built-in functions
12262are intended to be compatible with those described
12263in the @cite{Intel Itanium Processor-specific Application Binary Interface},
12264section 7.4. As such, they depart from normal GCC practice by not using
12265the @samp{__builtin_} prefix and also by being overloaded so that they
12266work on multiple types.
12267
12268The definition given in the Intel documentation allows only for the use of
12269the types @code{int}, @code{long}, @code{long long} or their unsigned
12270counterparts. GCC allows any scalar type that is 1, 2, 4 or 8 bytes in
12271size other than the C type @code{_Bool} or the C++ type @code{bool}.
12272Operations on pointer arguments are performed as if the operands were
12273of the @code{uintptr_t} type. That is, they are not scaled by the size
12274of the type to which the pointer points.
12275
12276These functions are implemented in terms of the @samp{__atomic}
12277builtins (@pxref{__atomic Builtins}). They should not be used for new
12278code which should use the @samp{__atomic} builtins instead.
12279
12280Not all operations are supported by all target processors. If a particular
12281operation cannot be implemented on the target processor, a warning is
12282generated and a call to an external function is generated. The external
12283function carries the same name as the built-in version,
12284with an additional suffix
12285@samp{_@var{n}} where @var{n} is the size of the data type.
12286
12287@c ??? Should we have a mechanism to suppress this warning? This is almost
12288@c useful for implementing the operation under the control of an external
12289@c mutex.
12290
12291In most cases, these built-in functions are considered a @dfn{full barrier}.
12292That is,
12293no memory operand is moved across the operation, either forward or
12294backward. Further, instructions are issued as necessary to prevent the
12295processor from speculating loads across the operation and from queuing stores
12296after the operation.
12297
12298All of the routines are described in the Intel documentation to take
12299``an optional list of variables protected by the memory barrier''. It's
12300not clear what is meant by that; it could mean that @emph{only} the
12301listed variables are protected, or it could mean a list of additional
12302variables to be protected. The list is ignored by GCC which treats it as
12303empty. GCC interprets an empty list as meaning that all globally
12304accessible variables should be protected.
12305
f25efe50
AA
12306@defbuiltin{@var{type} __sync_fetch_and_add (@var{type} *ptr, @var{type} value, ...)}
12307@defbuiltinx{@var{type} __sync_fetch_and_sub (@var{type} *ptr, @var{type} value, ...)}
12308@defbuiltinx{@var{type} __sync_fetch_and_or (@var{type} *ptr, @var{type} value, ...)}
12309@defbuiltinx{@var{type} __sync_fetch_and_and (@var{type} *ptr, @var{type} value, ...)}
12310@defbuiltinx{@var{type} __sync_fetch_and_xor (@var{type} *ptr, @var{type} value, ...)}
12311@defbuiltinx{@var{type} __sync_fetch_and_nand (@var{type} *ptr, @var{type} value, ...)}
d77de738
ML
12312These built-in functions perform the operation suggested by the name, and
12313returns the value that had previously been in memory. That is, operations
12314on integer operands have the following semantics. Operations on pointer
12315arguments are performed as if the operands were of the @code{uintptr_t}
12316type. That is, they are not scaled by the size of the type to which
12317the pointer points.
12318
12319@smallexample
12320@{ tmp = *ptr; *ptr @var{op}= value; return tmp; @}
12321@{ tmp = *ptr; *ptr = ~(tmp & value); return tmp; @} // nand
12322@end smallexample
12323
12324The object pointed to by the first argument must be of integer or pointer
12325type. It must not be a boolean type.
12326
12327@emph{Note:} GCC 4.4 and later implement @code{__sync_fetch_and_nand}
12328as @code{*ptr = ~(tmp & value)} instead of @code{*ptr = ~tmp & value}.
f25efe50
AA
12329@enddefbuiltin
12330
12331@defbuiltin{@var{type} __sync_add_and_fetch (@var{type} *ptr, @
12332 @var{type} value, ...)}
12333@defbuiltinx{@var{type} __sync_sub_and_fetch (@var{type} *ptr, @var{type} value, ...)}
12334@defbuiltinx{@var{type} __sync_or_and_fetch (@var{type} *ptr, @var{type} value, ...)}
12335@defbuiltinx{@var{type} __sync_and_and_fetch (@var{type} *ptr, @var{type} value, ...)}
12336@defbuiltinx{@var{type} __sync_xor_and_fetch (@var{type} *ptr, @var{type} value, ...)}
12337@defbuiltinx{@var{type} __sync_nand_and_fetch (@var{type} *ptr, @var{type} value, ...)}
d77de738
ML
12338These built-in functions perform the operation suggested by the name, and
12339return the new value. That is, operations on integer operands have
12340the following semantics. Operations on pointer operands are performed as
12341if the operand's type were @code{uintptr_t}.
12342
12343@smallexample
12344@{ *ptr @var{op}= value; return *ptr; @}
12345@{ *ptr = ~(*ptr & value); return *ptr; @} // nand
12346@end smallexample
12347
12348The same constraints on arguments apply as for the corresponding
12349@code{__sync_op_and_fetch} built-in functions.
12350
12351@emph{Note:} GCC 4.4 and later implement @code{__sync_nand_and_fetch}
12352as @code{*ptr = ~(*ptr & value)} instead of
12353@code{*ptr = ~*ptr & value}.
f25efe50 12354@enddefbuiltin
d77de738 12355
f25efe50
AA
12356@defbuiltin{bool __sync_bool_compare_and_swap (@var{type} *ptr, @var{type} oldval, @var{type} newval, ...)}
12357@defbuiltinx{@var{type} __sync_val_compare_and_swap (@var{type} *ptr, @var{type} oldval, @var{type} newval, ...)}
d77de738
ML
12358These built-in functions perform an atomic compare and swap.
12359That is, if the current
12360value of @code{*@var{ptr}} is @var{oldval}, then write @var{newval} into
12361@code{*@var{ptr}}.
12362
12363The ``bool'' version returns @code{true} if the comparison is successful and
12364@var{newval} is written. The ``val'' version returns the contents
12365of @code{*@var{ptr}} before the operation.
f25efe50 12366@enddefbuiltin
d77de738 12367
f25efe50 12368@defbuiltin{void __sync_synchronize (...)}
d77de738 12369This built-in function issues a full memory barrier.
f25efe50 12370@enddefbuiltin
d77de738 12371
f25efe50 12372@defbuiltin{@var{type} __sync_lock_test_and_set (@var{type} *ptr, @var{type} value, ...)}
d77de738
ML
12373This built-in function, as described by Intel, is not a traditional test-and-set
12374operation, but rather an atomic exchange operation. It writes @var{value}
12375into @code{*@var{ptr}}, and returns the previous contents of
12376@code{*@var{ptr}}.
12377
12378Many targets have only minimal support for such locks, and do not support
12379a full exchange operation. In this case, a target may support reduced
12380functionality here by which the @emph{only} valid value to store is the
12381immediate constant 1. The exact value actually stored in @code{*@var{ptr}}
12382is implementation defined.
12383
12384This built-in function is not a full barrier,
12385but rather an @dfn{acquire barrier}.
12386This means that references after the operation cannot move to (or be
12387speculated to) before the operation, but previous memory stores may not
12388be globally visible yet, and previous memory loads may not yet be
12389satisfied.
f25efe50 12390@enddefbuiltin
d77de738 12391
f25efe50 12392@defbuiltin{void __sync_lock_release (@var{type} *ptr, ...)}
d77de738
ML
12393This built-in function releases the lock acquired by
12394@code{__sync_lock_test_and_set}.
12395Normally this means writing the constant 0 to @code{*@var{ptr}}.
12396
12397This built-in function is not a full barrier,
12398but rather a @dfn{release barrier}.
12399This means that all previous memory stores are globally visible, and all
12400previous memory loads have been satisfied, but following memory reads
12401are not prevented from being speculated to before the barrier.
f25efe50 12402@enddefbuiltin
d77de738
ML
12403
12404@node __atomic Builtins
12405@section Built-in Functions for Memory Model Aware Atomic Operations
12406
12407The following built-in functions approximately match the requirements
12408for the C++11 memory model. They are all
12409identified by being prefixed with @samp{__atomic} and most are
12410overloaded so that they work with multiple types.
12411
12412These functions are intended to replace the legacy @samp{__sync}
12413builtins. The main difference is that the memory order that is requested
12414is a parameter to the functions. New code should always use the
12415@samp{__atomic} builtins rather than the @samp{__sync} builtins.
12416
12417Note that the @samp{__atomic} builtins assume that programs will
12418conform to the C++11 memory model. In particular, they assume
12419that programs are free of data races. See the C++11 standard for
12420detailed requirements.
12421
12422The @samp{__atomic} builtins can be used with any integral scalar or
12423pointer type that is 1, 2, 4, or 8 bytes in length. 16-byte integral
12424types are also allowed if @samp{__int128} (@pxref{__int128}) is
12425supported by the architecture.
12426
12427The four non-arithmetic functions (load, store, exchange, and
12428compare_exchange) all have a generic version as well. This generic
12429version works on any data type. It uses the lock-free built-in function
12430if the specific data type size makes that possible; otherwise, an
12431external call is left to be resolved at run time. This external call is
12432the same format with the addition of a @samp{size_t} parameter inserted
12433as the first parameter indicating the size of the object being pointed to.
12434All objects must be the same size.
12435
12436There are 6 different memory orders that can be specified. These map
12437to the C++11 memory orders with the same names, see the C++11 standard
12438or the @uref{https://gcc.gnu.org/wiki/Atomic/GCCMM/AtomicSync,GCC wiki
12439on atomic synchronization} for detailed definitions. Individual
12440targets may also support additional memory orders for use on specific
12441architectures. Refer to the target documentation for details of
12442these.
12443
12444An atomic operation can both constrain code motion and
12445be mapped to hardware instructions for synchronization between threads
12446(e.g., a fence). To which extent this happens is controlled by the
12447memory orders, which are listed here in approximately ascending order of
12448strength. The description of each memory order is only meant to roughly
12449illustrate the effects and is not a specification; see the C++11
12450memory model for precise semantics.
12451
12452@table @code
12453@item __ATOMIC_RELAXED
12454Implies no inter-thread ordering constraints.
12455@item __ATOMIC_CONSUME
12456This is currently implemented using the stronger @code{__ATOMIC_ACQUIRE}
12457memory order because of a deficiency in C++11's semantics for
12458@code{memory_order_consume}.
12459@item __ATOMIC_ACQUIRE
12460Creates an inter-thread happens-before constraint from the release (or
12461stronger) semantic store to this acquire load. Can prevent hoisting
12462of code to before the operation.
12463@item __ATOMIC_RELEASE
12464Creates an inter-thread happens-before constraint to acquire (or stronger)
12465semantic loads that read from this release store. Can prevent sinking
12466of code to after the operation.
12467@item __ATOMIC_ACQ_REL
12468Combines the effects of both @code{__ATOMIC_ACQUIRE} and
12469@code{__ATOMIC_RELEASE}.
12470@item __ATOMIC_SEQ_CST
12471Enforces total ordering with all other @code{__ATOMIC_SEQ_CST} operations.
12472@end table
12473
12474Note that in the C++11 memory model, @emph{fences} (e.g.,
12475@samp{__atomic_thread_fence}) take effect in combination with other
12476atomic operations on specific memory locations (e.g., atomic loads);
12477operations on specific memory locations do not necessarily affect other
12478operations in the same way.
12479
12480Target architectures are encouraged to provide their own patterns for
12481each of the atomic built-in functions. If no target is provided, the original
12482non-memory model set of @samp{__sync} atomic built-in functions are
12483used, along with any required synchronization fences surrounding it in
12484order to achieve the proper behavior. Execution in this case is subject
12485to the same restrictions as those built-in functions.
12486
12487If there is no pattern or mechanism to provide a lock-free instruction
12488sequence, a call is made to an external routine with the same parameters
12489to be resolved at run time.
12490
12491When implementing patterns for these built-in functions, the memory order
12492parameter can be ignored as long as the pattern implements the most
12493restrictive @code{__ATOMIC_SEQ_CST} memory order. Any of the other memory
12494orders execute correctly with this memory order but they may not execute as
12495efficiently as they could with a more appropriate implementation of the
12496relaxed requirements.
12497
12498Note that the C++11 standard allows for the memory order parameter to be
12499determined at run time rather than at compile time. These built-in
12500functions map any run-time value to @code{__ATOMIC_SEQ_CST} rather
12501than invoke a runtime library call or inline a switch statement. This is
12502standard compliant, safe, and the simplest approach for now.
12503
12504The memory order parameter is a signed int, but only the lower 16 bits are
12505reserved for the memory order. The remainder of the signed int is reserved
12506for target use and should be 0. Use of the predefined atomic values
12507ensures proper usage.
12508
f25efe50 12509@defbuiltin{@var{type} __atomic_load_n (@var{type} *ptr, int memorder)}
d77de738
ML
12510This built-in function implements an atomic load operation. It returns the
12511contents of @code{*@var{ptr}}.
12512
12513The valid memory order variants are
12514@code{__ATOMIC_RELAXED}, @code{__ATOMIC_SEQ_CST}, @code{__ATOMIC_ACQUIRE},
12515and @code{__ATOMIC_CONSUME}.
12516
f25efe50 12517@enddefbuiltin
d77de738 12518
f25efe50 12519@defbuiltin{void __atomic_load (@var{type} *ptr, @var{type} *ret, int memorder)}
d77de738
ML
12520This is the generic version of an atomic load. It returns the
12521contents of @code{*@var{ptr}} in @code{*@var{ret}}.
12522
f25efe50 12523@enddefbuiltin
d77de738 12524
f25efe50 12525@defbuiltin{void __atomic_store_n (@var{type} *ptr, @var{type} val, int memorder)}
d77de738
ML
12526This built-in function implements an atomic store operation. It writes
12527@code{@var{val}} into @code{*@var{ptr}}.
12528
12529The valid memory order variants are
12530@code{__ATOMIC_RELAXED}, @code{__ATOMIC_SEQ_CST}, and @code{__ATOMIC_RELEASE}.
12531
f25efe50 12532@enddefbuiltin
d77de738 12533
f25efe50 12534@defbuiltin{void __atomic_store (@var{type} *ptr, @var{type} *val, int memorder)}
d77de738
ML
12535This is the generic version of an atomic store. It stores the value
12536of @code{*@var{val}} into @code{*@var{ptr}}.
12537
f25efe50 12538@enddefbuiltin
d77de738 12539
f25efe50 12540@defbuiltin{@var{type} __atomic_exchange_n (@var{type} *ptr, @var{type} val, int memorder)}
d77de738
ML
12541This built-in function implements an atomic exchange operation. It writes
12542@var{val} into @code{*@var{ptr}}, and returns the previous contents of
12543@code{*@var{ptr}}.
12544
12545All memory order variants are valid.
12546
f25efe50 12547@enddefbuiltin
d77de738 12548
f25efe50 12549@defbuiltin{void __atomic_exchange (@var{type} *ptr, @var{type} *val, @var{type} *ret, int memorder)}
d77de738
ML
12550This is the generic version of an atomic exchange. It stores the
12551contents of @code{*@var{val}} into @code{*@var{ptr}}. The original value
12552of @code{*@var{ptr}} is copied into @code{*@var{ret}}.
12553
f25efe50 12554@enddefbuiltin
d77de738 12555
f25efe50 12556@defbuiltin{bool __atomic_compare_exchange_n (@var{type} *ptr, @var{type} *expected, @var{type} desired, bool weak, int success_memorder, int failure_memorder)}
d77de738
ML
12557This built-in function implements an atomic compare and exchange operation.
12558This compares the contents of @code{*@var{ptr}} with the contents of
12559@code{*@var{expected}}. If equal, the operation is a @emph{read-modify-write}
12560operation that writes @var{desired} into @code{*@var{ptr}}. If they are not
12561equal, the operation is a @emph{read} and the current contents of
12562@code{*@var{ptr}} are written into @code{*@var{expected}}. @var{weak} is @code{true}
12563for weak compare_exchange, which may fail spuriously, and @code{false} for
12564the strong variation, which never fails spuriously. Many targets
12565only offer the strong variation and ignore the parameter. When in doubt, use
12566the strong variation.
12567
12568If @var{desired} is written into @code{*@var{ptr}} then @code{true} is returned
12569and memory is affected according to the
12570memory order specified by @var{success_memorder}. There are no
12571restrictions on what memory order can be used here.
12572
12573Otherwise, @code{false} is returned and memory is affected according
12574to @var{failure_memorder}. This memory order cannot be
12575@code{__ATOMIC_RELEASE} nor @code{__ATOMIC_ACQ_REL}. It also cannot be a
12576stronger order than that specified by @var{success_memorder}.
12577
f25efe50 12578@enddefbuiltin
d77de738 12579
f25efe50 12580@defbuiltin{bool __atomic_compare_exchange (@var{type} *ptr, @var{type} *expected, @var{type} *desired, bool weak, int success_memorder, int failure_memorder)}
d77de738
ML
12581This built-in function implements the generic version of
12582@code{__atomic_compare_exchange}. The function is virtually identical to
12583@code{__atomic_compare_exchange_n}, except the desired value is also a
12584pointer.
12585
f25efe50 12586@enddefbuiltin
d77de738 12587
f25efe50
AA
12588@defbuiltin{@var{type} __atomic_add_fetch (@var{type} *ptr, @var{type} val, int memorder)}
12589@defbuiltinx{@var{type} __atomic_sub_fetch (@var{type} *ptr, @var{type} val, int memorder)}
12590@defbuiltinx{@var{type} __atomic_and_fetch (@var{type} *ptr, @var{type} val, int memorder)}
12591@defbuiltinx{@var{type} __atomic_xor_fetch (@var{type} *ptr, @var{type} val, int memorder)}
12592@defbuiltinx{@var{type} __atomic_or_fetch (@var{type} *ptr, @var{type} val, int memorder)}
12593@defbuiltinx{@var{type} __atomic_nand_fetch (@var{type} *ptr, @var{type} val, int memorder)}
d77de738
ML
12594These built-in functions perform the operation suggested by the name, and
12595return the result of the operation. Operations on pointer arguments are
12596performed as if the operands were of the @code{uintptr_t} type. That is,
12597they are not scaled by the size of the type to which the pointer points.
12598
12599@smallexample
12600@{ *ptr @var{op}= val; return *ptr; @}
12601@{ *ptr = ~(*ptr & val); return *ptr; @} // nand
12602@end smallexample
12603
12604The object pointed to by the first argument must be of integer or pointer
12605type. It must not be a boolean type. All memory orders are valid.
12606
f25efe50 12607@enddefbuiltin
d77de738 12608
f25efe50
AA
12609@defbuiltin{@var{type} __atomic_fetch_add (@var{type} *ptr, @var{type} val, int memorder)}
12610@defbuiltinx{@var{type} __atomic_fetch_sub (@var{type} *ptr, @var{type} val, int memorder)}
12611@defbuiltinx{@var{type} __atomic_fetch_and (@var{type} *ptr, @var{type} val, int memorder)}
12612@defbuiltinx{@var{type} __atomic_fetch_xor (@var{type} *ptr, @var{type} val, int memorder)}
12613@defbuiltinx{@var{type} __atomic_fetch_or (@var{type} *ptr, @var{type} val, int memorder)}
12614@defbuiltinx{@var{type} __atomic_fetch_nand (@var{type} *ptr, @var{type} val, int memorder)}
d77de738
ML
12615These built-in functions perform the operation suggested by the name, and
12616return the value that had previously been in @code{*@var{ptr}}. Operations
12617on pointer arguments are performed as if the operands were of
12618the @code{uintptr_t} type. That is, they are not scaled by the size of
12619the type to which the pointer points.
12620
12621@smallexample
12622@{ tmp = *ptr; *ptr @var{op}= val; return tmp; @}
12623@{ tmp = *ptr; *ptr = ~(*ptr & val); return tmp; @} // nand
12624@end smallexample
12625
12626The same constraints on arguments apply as for the corresponding
12627@code{__atomic_op_fetch} built-in functions. All memory orders are valid.
12628
f25efe50 12629@enddefbuiltin
d77de738 12630
f25efe50 12631@defbuiltin{bool __atomic_test_and_set (void *ptr, int memorder)}
d77de738
ML
12632
12633This built-in function performs an atomic test-and-set operation on
12634the byte at @code{*@var{ptr}}. The byte is set to some implementation
12635defined nonzero ``set'' value and the return value is @code{true} if and only
12636if the previous contents were ``set''.
12637It should be only used for operands of type @code{bool} or @code{char}. For
12638other types only part of the value may be set.
12639
12640All memory orders are valid.
12641
f25efe50 12642@enddefbuiltin
d77de738 12643
f25efe50 12644@defbuiltin{void __atomic_clear (bool *ptr, int memorder)}
d77de738
ML
12645
12646This built-in function performs an atomic clear operation on
12647@code{*@var{ptr}}. After the operation, @code{*@var{ptr}} contains 0.
12648It should be only used for operands of type @code{bool} or @code{char} and
12649in conjunction with @code{__atomic_test_and_set}.
12650For other types it may only clear partially. If the type is not @code{bool}
12651prefer using @code{__atomic_store}.
12652
12653The valid memory order variants are
12654@code{__ATOMIC_RELAXED}, @code{__ATOMIC_SEQ_CST}, and
12655@code{__ATOMIC_RELEASE}.
12656
f25efe50 12657@enddefbuiltin
d77de738 12658
f25efe50 12659@defbuiltin{void __atomic_thread_fence (int memorder)}
d77de738
ML
12660
12661This built-in function acts as a synchronization fence between threads
12662based on the specified memory order.
12663
12664All memory orders are valid.
12665
f25efe50 12666@enddefbuiltin
d77de738 12667
f25efe50 12668@defbuiltin{void __atomic_signal_fence (int memorder)}
d77de738
ML
12669
12670This built-in function acts as a synchronization fence between a thread
12671and signal handlers based in the same thread.
12672
12673All memory orders are valid.
12674
f25efe50 12675@enddefbuiltin
d77de738 12676
f25efe50 12677@defbuiltin{bool __atomic_always_lock_free (size_t size, void *ptr)}
d77de738
ML
12678
12679This built-in function returns @code{true} if objects of @var{size} bytes always
12680generate lock-free atomic instructions for the target architecture.
12681@var{size} must resolve to a compile-time constant and the result also
12682resolves to a compile-time constant.
12683
12684@var{ptr} is an optional pointer to the object that may be used to determine
12685alignment. A value of 0 indicates typical alignment should be used. The
12686compiler may also ignore this parameter.
12687
12688@smallexample
12689if (__atomic_always_lock_free (sizeof (long long), 0))
12690@end smallexample
12691
f25efe50 12692@enddefbuiltin
d77de738 12693
f25efe50 12694@defbuiltin{bool __atomic_is_lock_free (size_t size, void *ptr)}
d77de738
ML
12695
12696This built-in function returns @code{true} if objects of @var{size} bytes always
12697generate lock-free atomic instructions for the target architecture. If
12698the built-in function is not known to be lock-free, a call is made to a
12699runtime routine named @code{__atomic_is_lock_free}.
12700
12701@var{ptr} is an optional pointer to the object that may be used to determine
12702alignment. A value of 0 indicates typical alignment should be used. The
12703compiler may also ignore this parameter.
f25efe50 12704@enddefbuiltin
d77de738
ML
12705
12706@node Integer Overflow Builtins
12707@section Built-in Functions to Perform Arithmetic with Overflow Checking
12708
12709The following built-in functions allow performing simple arithmetic operations
12710together with checking whether the operations overflowed.
12711
f25efe50
AA
12712@defbuiltin{bool __builtin_add_overflow (@var{type1} a, @var{type2} b, @var{type3} *res)}
12713@defbuiltinx{bool __builtin_sadd_overflow (int a, int b, int *res)}
12714@defbuiltinx{bool __builtin_saddl_overflow (long int a, long int b, long int *res)}
12715@defbuiltinx{bool __builtin_saddll_overflow (long long int a, long long int b, long long int *res)}
12716@defbuiltinx{bool __builtin_uadd_overflow (unsigned int a, unsigned int b, unsigned int *res)}
12717@defbuiltinx{bool __builtin_uaddl_overflow (unsigned long int a, unsigned long int b, unsigned long int *res)}
12718@defbuiltinx{bool __builtin_uaddll_overflow (unsigned long long int a, unsigned long long int b, unsigned long long int *res)}
d77de738
ML
12719
12720These built-in functions promote the first two operands into infinite precision signed
12721type and perform addition on those promoted operands. The result is then
12722cast to the type the third pointer argument points to and stored there.
12723If the stored result is equal to the infinite precision result, the built-in
12724functions return @code{false}, otherwise they return @code{true}. As the addition is
12725performed in infinite signed precision, these built-in functions have fully defined
12726behavior for all argument values.
12727
12728The first built-in function allows arbitrary integral types for operands and
12729the result type must be pointer to some integral type other than enumerated or
12730boolean type, the rest of the built-in functions have explicit integer types.
12731
12732The compiler will attempt to use hardware instructions to implement
12733these built-in functions where possible, like conditional jump on overflow
12734after addition, conditional jump on carry etc.
12735
f25efe50 12736@enddefbuiltin
d77de738 12737
f25efe50
AA
12738@defbuiltin{bool __builtin_sub_overflow (@var{type1} a, @var{type2} b, @var{type3} *res)}
12739@defbuiltinx{bool __builtin_ssub_overflow (int a, int b, int *res)}
12740@defbuiltinx{bool __builtin_ssubl_overflow (long int a, long int b, long int *res)}
12741@defbuiltinx{bool __builtin_ssubll_overflow (long long int a, long long int b, long long int *res)}
12742@defbuiltinx{bool __builtin_usub_overflow (unsigned int a, unsigned int b, unsigned int *res)}
12743@defbuiltinx{bool __builtin_usubl_overflow (unsigned long int a, unsigned long int b, unsigned long int *res)}
12744@defbuiltinx{bool __builtin_usubll_overflow (unsigned long long int a, unsigned long long int b, unsigned long long int *res)}
d77de738
ML
12745
12746These built-in functions are similar to the add overflow checking built-in
12747functions above, except they perform subtraction, subtract the second argument
12748from the first one, instead of addition.
12749
f25efe50 12750@enddefbuiltin
d77de738 12751
f25efe50
AA
12752@defbuiltin{bool __builtin_mul_overflow (@var{type1} a, @var{type2} b, @var{type3} *res)}
12753@defbuiltinx{bool __builtin_smul_overflow (int a, int b, int *res)}
12754@defbuiltinx{bool __builtin_smull_overflow (long int a, long int b, long int *res)}
12755@defbuiltinx{bool __builtin_smulll_overflow (long long int a, long long int b, long long int *res)}
12756@defbuiltinx{bool __builtin_umul_overflow (unsigned int a, unsigned int b, unsigned int *res)}
12757@defbuiltinx{bool __builtin_umull_overflow (unsigned long int a, unsigned long int b, unsigned long int *res)}
12758@defbuiltinx{bool __builtin_umulll_overflow (unsigned long long int a, unsigned long long int b, unsigned long long int *res)}
d77de738
ML
12759
12760These built-in functions are similar to the add overflow checking built-in
12761functions above, except they perform multiplication, instead of addition.
12762
f25efe50 12763@enddefbuiltin
d77de738
ML
12764
12765The following built-in functions allow checking if simple arithmetic operation
12766would overflow.
12767
f25efe50
AA
12768@defbuiltin{bool __builtin_add_overflow_p (@var{type1} a, @var{type2} b, @var{type3} c)}
12769@defbuiltinx{bool __builtin_sub_overflow_p (@var{type1} a, @var{type2} b, @var{type3} c)}
12770@defbuiltinx{bool __builtin_mul_overflow_p (@var{type1} a, @var{type2} b, @var{type3} c)}
d77de738
ML
12771
12772These built-in functions are similar to @code{__builtin_add_overflow},
12773@code{__builtin_sub_overflow}, or @code{__builtin_mul_overflow}, except that
12774they don't store the result of the arithmetic operation anywhere and the
12775last argument is not a pointer, but some expression with integral type other
12776than enumerated or boolean type.
12777
12778The built-in functions promote the first two operands into infinite precision signed type
12779and perform addition on those promoted operands. The result is then
12780cast to the type of the third argument. If the cast result is equal to the infinite
12781precision result, the built-in functions return @code{false}, otherwise they return @code{true}.
12782The value of the third argument is ignored, just the side effects in the third argument
12783are evaluated, and no integral argument promotions are performed on the last argument.
12784If the third argument is a bit-field, the type used for the result cast has the
12785precision and signedness of the given bit-field, rather than precision and signedness
12786of the underlying type.
12787
12788For example, the following macro can be used to portably check, at
12789compile-time, whether or not adding two constant integers will overflow,
12790and perform the addition only when it is known to be safe and not to trigger
12791a @option{-Woverflow} warning.
12792
12793@smallexample
12794#define INT_ADD_OVERFLOW_P(a, b) \
12795 __builtin_add_overflow_p (a, b, (__typeof__ ((a) + (b))) 0)
12796
12797enum @{
12798 A = INT_MAX, B = 3,
12799 C = INT_ADD_OVERFLOW_P (A, B) ? 0 : A + B,
12800 D = __builtin_add_overflow_p (1, SCHAR_MAX, (signed char) 0)
12801@};
12802@end smallexample
12803
12804The compiler will attempt to use hardware instructions to implement
12805these built-in functions where possible, like conditional jump on overflow
12806after addition, conditional jump on carry etc.
12807
f25efe50 12808@enddefbuiltin
d77de738
ML
12809
12810@node x86 specific memory model extensions for transactional memory
12811@section x86-Specific Memory Model Extensions for Transactional Memory
12812
12813The x86 architecture supports additional memory ordering flags
12814to mark critical sections for hardware lock elision.
12815These must be specified in addition to an existing memory order to
12816atomic intrinsics.
12817
12818@table @code
12819@item __ATOMIC_HLE_ACQUIRE
12820Start lock elision on a lock variable.
12821Memory order must be @code{__ATOMIC_ACQUIRE} or stronger.
12822@item __ATOMIC_HLE_RELEASE
12823End lock elision on a lock variable.
12824Memory order must be @code{__ATOMIC_RELEASE} or stronger.
12825@end table
12826
12827When a lock acquire fails, it is required for good performance to abort
12828the transaction quickly. This can be done with a @code{_mm_pause}.
12829
12830@smallexample
12831#include <immintrin.h> // For _mm_pause
12832
12833int lockvar;
12834
12835/* Acquire lock with lock elision */
12836while (__atomic_exchange_n(&lockvar, 1, __ATOMIC_ACQUIRE|__ATOMIC_HLE_ACQUIRE))
12837 _mm_pause(); /* Abort failed transaction */
12838...
12839/* Free lock with lock elision */
12840__atomic_store_n(&lockvar, 0, __ATOMIC_RELEASE|__ATOMIC_HLE_RELEASE);
12841@end smallexample
12842
12843@node Object Size Checking
b3009222
SP
12844@section Object Size Checking
12845
12846@subsection Object Size Checking Built-in Functions
d77de738
ML
12847@findex __builtin___memcpy_chk
12848@findex __builtin___mempcpy_chk
12849@findex __builtin___memmove_chk
12850@findex __builtin___memset_chk
12851@findex __builtin___strcpy_chk
12852@findex __builtin___stpcpy_chk
12853@findex __builtin___strncpy_chk
12854@findex __builtin___strcat_chk
12855@findex __builtin___strncat_chk
d77de738
ML
12856
12857GCC implements a limited buffer overflow protection mechanism that can
12858prevent some buffer overflow attacks by determining the sizes of objects
12859into which data is about to be written and preventing the writes when
12860the size isn't sufficient. The built-in functions described below yield
12861the best results when used together and when optimization is enabled.
12862For example, to detect object sizes across function boundaries or to
12863follow pointer assignments through non-trivial control flow they rely
12864on various optimization passes enabled with @option{-O2}. However, to
12865a limited extent, they can be used without optimization as well.
12866
f25efe50 12867@defbuiltin{size_t __builtin_object_size (const void * @var{ptr}, int @var{type})}
d77de738
ML
12868is a built-in construct that returns a constant number of bytes from
12869@var{ptr} to the end of the object @var{ptr} pointer points to
12870(if known at compile time). To determine the sizes of dynamically allocated
12871objects the function relies on the allocation functions called to obtain
12872the storage to be declared with the @code{alloc_size} attribute (@pxref{Common
12873Function Attributes}). @code{__builtin_object_size} never evaluates
12874its arguments for side effects. If there are any side effects in them, it
12875returns @code{(size_t) -1} for @var{type} 0 or 1 and @code{(size_t) 0}
12876for @var{type} 2 or 3. If there are multiple objects @var{ptr} can
12877point to and all of them are known at compile time, the returned number
12878is the maximum of remaining byte counts in those objects if @var{type} & 2 is
128790 and minimum if nonzero. If it is not possible to determine which objects
12880@var{ptr} points to at compile time, @code{__builtin_object_size} should
12881return @code{(size_t) -1} for @var{type} 0 or 1 and @code{(size_t) 0}
12882for @var{type} 2 or 3.
12883
12884@var{type} is an integer constant from 0 to 3. If the least significant
12885bit is clear, objects are whole variables, if it is set, a closest
12886surrounding subobject is considered the object a pointer points to.
12887The second bit determines if maximum or minimum of remaining bytes
12888is computed.
12889
12890@smallexample
12891struct V @{ char buf1[10]; int b; char buf2[10]; @} var;
12892char *p = &var.buf1[1], *q = &var.b;
12893
12894/* Here the object p points to is var. */
12895assert (__builtin_object_size (p, 0) == sizeof (var) - 1);
12896/* The subobject p points to is var.buf1. */
12897assert (__builtin_object_size (p, 1) == sizeof (var.buf1) - 1);
12898/* The object q points to is var. */
12899assert (__builtin_object_size (q, 0)
12900 == (char *) (&var + 1) - (char *) &var.b);
12901/* The subobject q points to is var.b. */
12902assert (__builtin_object_size (q, 1) == sizeof (var.b));
12903@end smallexample
f25efe50 12904@enddefbuiltin
d77de738 12905
f25efe50 12906@defbuiltin{{size_t} __builtin_dynamic_object_size (const void * @var{ptr}, int @var{type})}
d77de738
ML
12907is similar to @code{__builtin_object_size} in that it returns a number of bytes
12908from @var{ptr} to the end of the object @var{ptr} pointer points to, except
12909that the size returned may not be a constant. This results in successful
12910evaluation of object size estimates in a wider range of use cases and can be
12911more precise than @code{__builtin_object_size}, but it incurs a performance
12912penalty since it may add a runtime overhead on size computation. Semantics of
12913@var{type} as well as return values in case it is not possible to determine
12914which objects @var{ptr} points to at compile time are the same as in the case
12915of @code{__builtin_object_size}.
f25efe50 12916@enddefbuiltin
d77de738 12917
b3009222
SP
12918@subsection Object Size Checking and Source Fortification
12919
12920Hardening of function calls using the @code{_FORTIFY_SOURCE} macro is
12921one of the key uses of the object size checking built-in functions. To
12922make implementation of these features more convenient and improve
12923optimization and diagnostics, there are built-in functions added for
12924many common string operation functions, e.g., for @code{memcpy}
12925@code{__builtin___memcpy_chk} built-in is provided. This built-in has
12926an additional last argument, which is the number of bytes remaining in
12927the object the @var{dest} argument points to or @code{(size_t) -1} if
12928the size is not known.
d77de738
ML
12929
12930The built-in functions are optimized into the normal string functions
12931like @code{memcpy} if the last argument is @code{(size_t) -1} or if
12932it is known at compile time that the destination object will not
12933be overflowed. If the compiler can determine at compile time that the
12934object will always be overflowed, it issues a warning.
12935
12936The intended use can be e.g.@:
12937
12938@smallexample
12939#undef memcpy
12940#define bos0(dest) __builtin_object_size (dest, 0)
12941#define memcpy(dest, src, n) \
12942 __builtin___memcpy_chk (dest, src, n, bos0 (dest))
12943
12944char *volatile p;
12945char buf[10];
12946/* It is unknown what object p points to, so this is optimized
12947 into plain memcpy - no checking is possible. */
12948memcpy (p, "abcde", n);
12949/* Destination is known and length too. It is known at compile
12950 time there will be no overflow. */
12951memcpy (&buf[5], "abcde", 5);
12952/* Destination is known, but the length is not known at compile time.
12953 This will result in __memcpy_chk call that can check for overflow
12954 at run time. */
12955memcpy (&buf[5], "abcde", n);
12956/* Destination is known and it is known at compile time there will
12957 be overflow. There will be a warning and __memcpy_chk call that
12958 will abort the program at run time. */
12959memcpy (&buf[6], "abcde", 5);
12960@end smallexample
12961
12962Such built-in functions are provided for @code{memcpy}, @code{mempcpy},
12963@code{memmove}, @code{memset}, @code{strcpy}, @code{stpcpy}, @code{strncpy},
12964@code{strcat} and @code{strncat}.
12965
e1e5ecb2 12966@subsubsection Formatted Output Function Checking
f25efe50
AA
12967@defbuiltin{int __builtin___sprintf_chk @
12968 (char *@var{s}, int @var{flag}, size_t @var{os}, @
12969 const char *@var{fmt}, ...)}
12970@defbuiltinx{int __builtin___snprintf_chk @
12971 (char *@var{s}, size_t @var{maxlen}, int @var{flag}, @
12972 size_t @var{os}, const char *@var{fmt}, ...)}
12973@defbuiltinx{int __builtin___vsprintf_chk @
12974 (char *@var{s}, int @var{flag}, size_t @var{os}, @
12975 const char *@var{fmt}, va_list @var{ap})}
12976@defbuiltinx{int __builtin___vsnprintf_chk @
12977 (char *@var{s}, size_t @var{maxlen}, int @var{flag}, @
12978 size_t @var{os}, const char *@var{fmt}, @
12979 va_list @var{ap})}
d77de738
ML
12980
12981The added @var{flag} argument is passed unchanged to @code{__sprintf_chk}
12982etc.@: functions and can contain implementation specific flags on what
12983additional security measures the checking function might take, such as
12984handling @code{%n} differently.
12985
12986The @var{os} argument is the object size @var{s} points to, like in the
12987other built-in functions. There is a small difference in the behavior
12988though, if @var{os} is @code{(size_t) -1}, the built-in functions are
12989optimized into the non-checking functions only if @var{flag} is 0, otherwise
12990the checking function is called with @var{os} argument set to
12991@code{(size_t) -1}.
12992
12993In addition to this, there are checking built-in functions
12994@code{__builtin___printf_chk}, @code{__builtin___vprintf_chk},
12995@code{__builtin___fprintf_chk} and @code{__builtin___vfprintf_chk}.
12996These have just one additional argument, @var{flag}, right before
12997format string @var{fmt}. If the compiler is able to optimize them to
12998@code{fputc} etc.@: functions, it does, otherwise the checking function
12999is called and the @var{flag} argument passed to it.
f25efe50 13000@enddefbuiltin
d77de738
ML
13001
13002@node Other Builtins
13003@section Other Built-in Functions Provided by GCC
13004@cindex built-in functions
d77de738
ML
13005@findex __builtin_isfinite
13006@findex __builtin_isnormal
13007@findex __builtin_isgreater
13008@findex __builtin_isgreaterequal
d77de738 13009@findex __builtin_isunordered
d77de738
ML
13010@findex __builtin_speculation_safe_value
13011@findex _Exit
13012@findex _exit
13013@findex abort
13014@findex abs
13015@findex acos
13016@findex acosf
13017@findex acosh
13018@findex acoshf
13019@findex acoshl
13020@findex acosl
13021@findex alloca
13022@findex asin
13023@findex asinf
13024@findex asinh
13025@findex asinhf
13026@findex asinhl
13027@findex asinl
13028@findex atan
13029@findex atan2
13030@findex atan2f
13031@findex atan2l
13032@findex atanf
13033@findex atanh
13034@findex atanhf
13035@findex atanhl
13036@findex atanl
13037@findex bcmp
13038@findex bzero
13039@findex cabs
13040@findex cabsf
13041@findex cabsl
13042@findex cacos
13043@findex cacosf
13044@findex cacosh
13045@findex cacoshf
13046@findex cacoshl
13047@findex cacosl
13048@findex calloc
13049@findex carg
13050@findex cargf
13051@findex cargl
13052@findex casin
13053@findex casinf
13054@findex casinh
13055@findex casinhf
13056@findex casinhl
13057@findex casinl
13058@findex catan
13059@findex catanf
13060@findex catanh
13061@findex catanhf
13062@findex catanhl
13063@findex catanl
13064@findex cbrt
13065@findex cbrtf
13066@findex cbrtl
13067@findex ccos
13068@findex ccosf
13069@findex ccosh
13070@findex ccoshf
13071@findex ccoshl
13072@findex ccosl
13073@findex ceil
13074@findex ceilf
13075@findex ceill
13076@findex cexp
13077@findex cexpf
13078@findex cexpl
13079@findex cimag
13080@findex cimagf
13081@findex cimagl
13082@findex clog
13083@findex clogf
13084@findex clogl
13085@findex clog10
13086@findex clog10f
13087@findex clog10l
13088@findex conj
13089@findex conjf
13090@findex conjl
13091@findex copysign
13092@findex copysignf
13093@findex copysignl
13094@findex cos
13095@findex cosf
13096@findex cosh
13097@findex coshf
13098@findex coshl
13099@findex cosl
13100@findex cpow
13101@findex cpowf
13102@findex cpowl
13103@findex cproj
13104@findex cprojf
13105@findex cprojl
13106@findex creal
13107@findex crealf
13108@findex creall
13109@findex csin
13110@findex csinf
13111@findex csinh
13112@findex csinhf
13113@findex csinhl
13114@findex csinl
13115@findex csqrt
13116@findex csqrtf
13117@findex csqrtl
13118@findex ctan
13119@findex ctanf
13120@findex ctanh
13121@findex ctanhf
13122@findex ctanhl
13123@findex ctanl
13124@findex dcgettext
13125@findex dgettext
13126@findex drem
13127@findex dremf
13128@findex dreml
13129@findex erf
13130@findex erfc
13131@findex erfcf
13132@findex erfcl
13133@findex erff
13134@findex erfl
13135@findex exit
13136@findex exp
13137@findex exp10
13138@findex exp10f
13139@findex exp10l
13140@findex exp2
13141@findex exp2f
13142@findex exp2l
13143@findex expf
13144@findex expl
13145@findex expm1
13146@findex expm1f
13147@findex expm1l
13148@findex fabs
13149@findex fabsf
13150@findex fabsl
13151@findex fdim
13152@findex fdimf
13153@findex fdiml
13154@findex ffs
13155@findex floor
13156@findex floorf
13157@findex floorl
13158@findex fma
13159@findex fmaf
13160@findex fmal
13161@findex fmax
13162@findex fmaxf
13163@findex fmaxl
13164@findex fmin
13165@findex fminf
13166@findex fminl
13167@findex fmod
13168@findex fmodf
13169@findex fmodl
13170@findex fprintf
13171@findex fprintf_unlocked
13172@findex fputs
13173@findex fputs_unlocked
13174@findex free
13175@findex frexp
13176@findex frexpf
13177@findex frexpl
13178@findex fscanf
13179@findex gamma
13180@findex gammaf
13181@findex gammal
13182@findex gamma_r
13183@findex gammaf_r
13184@findex gammal_r
13185@findex gettext
13186@findex hypot
13187@findex hypotf
13188@findex hypotl
13189@findex ilogb
13190@findex ilogbf
13191@findex ilogbl
13192@findex imaxabs
13193@findex index
13194@findex isalnum
13195@findex isalpha
13196@findex isascii
13197@findex isblank
13198@findex iscntrl
13199@findex isdigit
13200@findex isgraph
13201@findex islower
13202@findex isprint
13203@findex ispunct
13204@findex isspace
13205@findex isupper
13206@findex iswalnum
13207@findex iswalpha
13208@findex iswblank
13209@findex iswcntrl
13210@findex iswdigit
13211@findex iswgraph
13212@findex iswlower
13213@findex iswprint
13214@findex iswpunct
13215@findex iswspace
13216@findex iswupper
13217@findex iswxdigit
13218@findex isxdigit
13219@findex j0
13220@findex j0f
13221@findex j0l
13222@findex j1
13223@findex j1f
13224@findex j1l
13225@findex jn
13226@findex jnf
13227@findex jnl
13228@findex labs
13229@findex ldexp
13230@findex ldexpf
13231@findex ldexpl
13232@findex lgamma
13233@findex lgammaf
13234@findex lgammal
13235@findex lgamma_r
13236@findex lgammaf_r
13237@findex lgammal_r
13238@findex llabs
13239@findex llrint
13240@findex llrintf
13241@findex llrintl
13242@findex llround
13243@findex llroundf
13244@findex llroundl
13245@findex log
13246@findex log10
13247@findex log10f
13248@findex log10l
13249@findex log1p
13250@findex log1pf
13251@findex log1pl
13252@findex log2
13253@findex log2f
13254@findex log2l
13255@findex logb
13256@findex logbf
13257@findex logbl
13258@findex logf
13259@findex logl
13260@findex lrint
13261@findex lrintf
13262@findex lrintl
13263@findex lround
13264@findex lroundf
13265@findex lroundl
13266@findex malloc
13267@findex memchr
13268@findex memcmp
13269@findex memcpy
13270@findex mempcpy
13271@findex memset
13272@findex modf
13273@findex modff
13274@findex modfl
13275@findex nearbyint
13276@findex nearbyintf
13277@findex nearbyintl
13278@findex nextafter
13279@findex nextafterf
13280@findex nextafterl
13281@findex nexttoward
13282@findex nexttowardf
13283@findex nexttowardl
13284@findex pow
13285@findex pow10
13286@findex pow10f
13287@findex pow10l
13288@findex powf
13289@findex powl
13290@findex printf
13291@findex printf_unlocked
13292@findex putchar
13293@findex puts
13294@findex realloc
13295@findex remainder
13296@findex remainderf
13297@findex remainderl
13298@findex remquo
13299@findex remquof
13300@findex remquol
13301@findex rindex
13302@findex rint
13303@findex rintf
13304@findex rintl
13305@findex round
13306@findex roundf
13307@findex roundl
13308@findex scalb
13309@findex scalbf
13310@findex scalbl
13311@findex scalbln
13312@findex scalblnf
13313@findex scalblnf
13314@findex scalbn
13315@findex scalbnf
13316@findex scanfnl
13317@findex signbit
13318@findex signbitf
13319@findex signbitl
13320@findex signbitd32
13321@findex signbitd64
13322@findex signbitd128
13323@findex significand
13324@findex significandf
13325@findex significandl
13326@findex sin
13327@findex sincos
13328@findex sincosf
13329@findex sincosl
13330@findex sinf
13331@findex sinh
13332@findex sinhf
13333@findex sinhl
13334@findex sinl
13335@findex snprintf
13336@findex sprintf
13337@findex sqrt
13338@findex sqrtf
13339@findex sqrtl
13340@findex sscanf
13341@findex stpcpy
13342@findex stpncpy
13343@findex strcasecmp
13344@findex strcat
13345@findex strchr
13346@findex strcmp
13347@findex strcpy
13348@findex strcspn
13349@findex strdup
13350@findex strfmon
13351@findex strftime
13352@findex strlen
13353@findex strncasecmp
13354@findex strncat
13355@findex strncmp
13356@findex strncpy
13357@findex strndup
13358@findex strnlen
13359@findex strpbrk
13360@findex strrchr
13361@findex strspn
13362@findex strstr
13363@findex tan
13364@findex tanf
13365@findex tanh
13366@findex tanhf
13367@findex tanhl
13368@findex tanl
13369@findex tgamma
13370@findex tgammaf
13371@findex tgammal
13372@findex toascii
13373@findex tolower
13374@findex toupper
13375@findex towlower
13376@findex towupper
13377@findex trunc
13378@findex truncf
13379@findex truncl
13380@findex vfprintf
13381@findex vfscanf
13382@findex vprintf
13383@findex vscanf
13384@findex vsnprintf
13385@findex vsprintf
13386@findex vsscanf
13387@findex y0
13388@findex y0f
13389@findex y0l
13390@findex y1
13391@findex y1f
13392@findex y1l
13393@findex yn
13394@findex ynf
13395@findex ynl
13396
13397GCC provides a large number of built-in functions other than the ones
13398mentioned above. Some of these are for internal use in the processing
13399of exceptions or variable-length argument lists and are not
13400documented here because they may change from time to time; we do not
13401recommend general use of these functions.
13402
13403The remaining functions are provided for optimization purposes.
13404
13405With the exception of built-ins that have library equivalents such as
13406the standard C library functions discussed below, or that expand to
13407library calls, GCC built-in functions are always expanded inline and
13408thus do not have corresponding entry points and their address cannot
13409be obtained. Attempting to use them in an expression other than
13410a function call results in a compile-time error.
13411
13412@opindex fno-builtin
13413GCC includes built-in versions of many of the functions in the standard
13414C library. These functions come in two forms: one whose names start with
13415the @code{__builtin_} prefix, and the other without. Both forms have the
13416same type (including prototype), the same address (when their address is
13417taken), and the same meaning as the C library functions even if you specify
13418the @option{-fno-builtin} option @pxref{C Dialect Options}). Many of these
13419functions are only optimized in certain cases; if they are not optimized in
13420a particular case, a call to the library function is emitted.
13421
13422@opindex ansi
13423@opindex std
13424Outside strict ISO C mode (@option{-ansi}, @option{-std=c90},
13425@option{-std=c99} or @option{-std=c11}), the functions
13426@code{_exit}, @code{alloca}, @code{bcmp}, @code{bzero},
13427@code{dcgettext}, @code{dgettext}, @code{dremf}, @code{dreml},
13428@code{drem}, @code{exp10f}, @code{exp10l}, @code{exp10}, @code{ffsll},
13429@code{ffsl}, @code{ffs}, @code{fprintf_unlocked},
13430@code{fputs_unlocked}, @code{gammaf}, @code{gammal}, @code{gamma},
13431@code{gammaf_r}, @code{gammal_r}, @code{gamma_r}, @code{gettext},
13432@code{index}, @code{isascii}, @code{j0f}, @code{j0l}, @code{j0},
13433@code{j1f}, @code{j1l}, @code{j1}, @code{jnf}, @code{jnl}, @code{jn},
13434@code{lgammaf_r}, @code{lgammal_r}, @code{lgamma_r}, @code{mempcpy},
13435@code{pow10f}, @code{pow10l}, @code{pow10}, @code{printf_unlocked},
13436@code{rindex}, @code{roundeven}, @code{roundevenf}, @code{roundevenl},
13437@code{scalbf}, @code{scalbl}, @code{scalb},
13438@code{signbit}, @code{signbitf}, @code{signbitl}, @code{signbitd32},
13439@code{signbitd64}, @code{signbitd128}, @code{significandf},
13440@code{significandl}, @code{significand}, @code{sincosf},
13441@code{sincosl}, @code{sincos}, @code{stpcpy}, @code{stpncpy},
13442@code{strcasecmp}, @code{strdup}, @code{strfmon}, @code{strncasecmp},
13443@code{strndup}, @code{strnlen}, @code{toascii}, @code{y0f}, @code{y0l},
13444@code{y0}, @code{y1f}, @code{y1l}, @code{y1}, @code{ynf}, @code{ynl} and
13445@code{yn}
13446may be handled as built-in functions.
13447All these functions have corresponding versions
13448prefixed with @code{__builtin_}, which may be used even in strict C90
13449mode.
13450
13451The ISO C99 functions
13452@code{_Exit}, @code{acoshf}, @code{acoshl}, @code{acosh}, @code{asinhf},
13453@code{asinhl}, @code{asinh}, @code{atanhf}, @code{atanhl}, @code{atanh},
13454@code{cabsf}, @code{cabsl}, @code{cabs}, @code{cacosf}, @code{cacoshf},
13455@code{cacoshl}, @code{cacosh}, @code{cacosl}, @code{cacos},
13456@code{cargf}, @code{cargl}, @code{carg}, @code{casinf}, @code{casinhf},
13457@code{casinhl}, @code{casinh}, @code{casinl}, @code{casin},
13458@code{catanf}, @code{catanhf}, @code{catanhl}, @code{catanh},
13459@code{catanl}, @code{catan}, @code{cbrtf}, @code{cbrtl}, @code{cbrt},
13460@code{ccosf}, @code{ccoshf}, @code{ccoshl}, @code{ccosh}, @code{ccosl},
13461@code{ccos}, @code{cexpf}, @code{cexpl}, @code{cexp}, @code{cimagf},
13462@code{cimagl}, @code{cimag}, @code{clogf}, @code{clogl}, @code{clog},
13463@code{conjf}, @code{conjl}, @code{conj}, @code{copysignf}, @code{copysignl},
13464@code{copysign}, @code{cpowf}, @code{cpowl}, @code{cpow}, @code{cprojf},
13465@code{cprojl}, @code{cproj}, @code{crealf}, @code{creall}, @code{creal},
13466@code{csinf}, @code{csinhf}, @code{csinhl}, @code{csinh}, @code{csinl},
13467@code{csin}, @code{csqrtf}, @code{csqrtl}, @code{csqrt}, @code{ctanf},
13468@code{ctanhf}, @code{ctanhl}, @code{ctanh}, @code{ctanl}, @code{ctan},
13469@code{erfcf}, @code{erfcl}, @code{erfc}, @code{erff}, @code{erfl},
13470@code{erf}, @code{exp2f}, @code{exp2l}, @code{exp2}, @code{expm1f},
13471@code{expm1l}, @code{expm1}, @code{fdimf}, @code{fdiml}, @code{fdim},
13472@code{fmaf}, @code{fmal}, @code{fmaxf}, @code{fmaxl}, @code{fmax},
13473@code{fma}, @code{fminf}, @code{fminl}, @code{fmin}, @code{hypotf},
13474@code{hypotl}, @code{hypot}, @code{ilogbf}, @code{ilogbl}, @code{ilogb},
13475@code{imaxabs}, @code{isblank}, @code{iswblank}, @code{lgammaf},
13476@code{lgammal}, @code{lgamma}, @code{llabs}, @code{llrintf}, @code{llrintl},
13477@code{llrint}, @code{llroundf}, @code{llroundl}, @code{llround},
13478@code{log1pf}, @code{log1pl}, @code{log1p}, @code{log2f}, @code{log2l},
13479@code{log2}, @code{logbf}, @code{logbl}, @code{logb}, @code{lrintf},
13480@code{lrintl}, @code{lrint}, @code{lroundf}, @code{lroundl},
13481@code{lround}, @code{nearbyintf}, @code{nearbyintl}, @code{nearbyint},
13482@code{nextafterf}, @code{nextafterl}, @code{nextafter},
13483@code{nexttowardf}, @code{nexttowardl}, @code{nexttoward},
13484@code{remainderf}, @code{remainderl}, @code{remainder}, @code{remquof},
13485@code{remquol}, @code{remquo}, @code{rintf}, @code{rintl}, @code{rint},
13486@code{roundf}, @code{roundl}, @code{round}, @code{scalblnf},
13487@code{scalblnl}, @code{scalbln}, @code{scalbnf}, @code{scalbnl},
13488@code{scalbn}, @code{snprintf}, @code{tgammaf}, @code{tgammal},
13489@code{tgamma}, @code{truncf}, @code{truncl}, @code{trunc},
13490@code{vfscanf}, @code{vscanf}, @code{vsnprintf} and @code{vsscanf}
13491are handled as built-in functions
13492except in strict ISO C90 mode (@option{-ansi} or @option{-std=c90}).
13493
13494There are also built-in versions of the ISO C99 functions
13495@code{acosf}, @code{acosl}, @code{asinf}, @code{asinl}, @code{atan2f},
13496@code{atan2l}, @code{atanf}, @code{atanl}, @code{ceilf}, @code{ceill},
13497@code{cosf}, @code{coshf}, @code{coshl}, @code{cosl}, @code{expf},
13498@code{expl}, @code{fabsf}, @code{fabsl}, @code{floorf}, @code{floorl},
13499@code{fmodf}, @code{fmodl}, @code{frexpf}, @code{frexpl}, @code{ldexpf},
13500@code{ldexpl}, @code{log10f}, @code{log10l}, @code{logf}, @code{logl},
13501@code{modfl}, @code{modff}, @code{powf}, @code{powl}, @code{sinf},
13502@code{sinhf}, @code{sinhl}, @code{sinl}, @code{sqrtf}, @code{sqrtl},
13503@code{tanf}, @code{tanhf}, @code{tanhl} and @code{tanl}
13504that are recognized in any mode since ISO C90 reserves these names for
13505the purpose to which ISO C99 puts them. All these functions have
13506corresponding versions prefixed with @code{__builtin_}.
13507
13508There are also built-in functions @code{__builtin_fabsf@var{n}},
13509@code{__builtin_fabsf@var{n}x}, @code{__builtin_copysignf@var{n}} and
13510@code{__builtin_copysignf@var{n}x}, corresponding to the TS 18661-3
13511functions @code{fabsf@var{n}}, @code{fabsf@var{n}x},
13512@code{copysignf@var{n}} and @code{copysignf@var{n}x}, for supported
13513types @code{_Float@var{n}} and @code{_Float@var{n}x}.
13514
13515There are also GNU extension functions @code{clog10}, @code{clog10f} and
13516@code{clog10l} which names are reserved by ISO C99 for future use.
13517All these functions have versions prefixed with @code{__builtin_}.
13518
13519The ISO C94 functions
13520@code{iswalnum}, @code{iswalpha}, @code{iswcntrl}, @code{iswdigit},
13521@code{iswgraph}, @code{iswlower}, @code{iswprint}, @code{iswpunct},
13522@code{iswspace}, @code{iswupper}, @code{iswxdigit}, @code{towlower} and
13523@code{towupper}
13524are handled as built-in functions
13525except in strict ISO C90 mode (@option{-ansi} or @option{-std=c90}).
13526
13527The ISO C90 functions
13528@code{abort}, @code{abs}, @code{acos}, @code{asin}, @code{atan2},
13529@code{atan}, @code{calloc}, @code{ceil}, @code{cosh}, @code{cos},
13530@code{exit}, @code{exp}, @code{fabs}, @code{floor}, @code{fmod},
13531@code{fprintf}, @code{fputs}, @code{free}, @code{frexp}, @code{fscanf},
13532@code{isalnum}, @code{isalpha}, @code{iscntrl}, @code{isdigit},
13533@code{isgraph}, @code{islower}, @code{isprint}, @code{ispunct},
13534@code{isspace}, @code{isupper}, @code{isxdigit}, @code{tolower},
13535@code{toupper}, @code{labs}, @code{ldexp}, @code{log10}, @code{log},
13536@code{malloc}, @code{memchr}, @code{memcmp}, @code{memcpy},
13537@code{memset}, @code{modf}, @code{pow}, @code{printf}, @code{putchar},
13538@code{puts}, @code{realloc}, @code{scanf}, @code{sinh}, @code{sin},
13539@code{snprintf}, @code{sprintf}, @code{sqrt}, @code{sscanf}, @code{strcat},
13540@code{strchr}, @code{strcmp}, @code{strcpy}, @code{strcspn},
13541@code{strlen}, @code{strncat}, @code{strncmp}, @code{strncpy},
13542@code{strpbrk}, @code{strrchr}, @code{strspn}, @code{strstr},
13543@code{tanh}, @code{tan}, @code{vfprintf}, @code{vprintf} and @code{vsprintf}
13544are all recognized as built-in functions unless
13545@option{-fno-builtin} is specified (or @option{-fno-builtin-@var{function}}
13546is specified for an individual function). All of these functions have
13547corresponding versions prefixed with @code{__builtin_}.
13548
13549GCC provides built-in versions of the ISO C99 floating-point comparison
13550macros that avoid raising exceptions for unordered operands. They have
13551the same names as the standard macros ( @code{isgreater},
13552@code{isgreaterequal}, @code{isless}, @code{islessequal},
13553@code{islessgreater}, and @code{isunordered}) , with @code{__builtin_}
13554prefixed. We intend for a library implementor to be able to simply
13555@code{#define} each standard macro to its built-in equivalent.
13556In the same fashion, GCC provides @code{fpclassify}, @code{isfinite},
13557@code{isinf_sign}, @code{isnormal} and @code{signbit} built-ins used with
13558@code{__builtin_} prefixed. The @code{isinf} and @code{isnan}
13559built-in functions appear both with and without the @code{__builtin_} prefix.
13560With @code{-ffinite-math-only} option the @code{isinf} and @code{isnan}
13561built-in functions will always return 0.
13562
13563GCC provides built-in versions of the ISO C99 floating-point rounding and
13564exceptions handling functions @code{fegetround}, @code{feclearexcept} and
13565@code{feraiseexcept}. They may not be available for all targets, and because
13566they need close interaction with libc internal values, they may not be available
13567for all target libcs, but in all cases they will gracefully fallback to libc
13568calls. These built-in functions appear both with and without the
13569@code{__builtin_} prefix.
13570
f25efe50 13571@defbuiltin{{void *} __builtin_alloca (size_t size)}
d77de738
ML
13572The @code{__builtin_alloca} function must be called at block scope.
13573The function allocates an object @var{size} bytes large on the stack
13574of the calling function. The object is aligned on the default stack
13575alignment boundary for the target determined by the
13576@code{__BIGGEST_ALIGNMENT__} macro. The @code{__builtin_alloca}
13577function returns a pointer to the first byte of the allocated object.
13578The lifetime of the allocated object ends just before the calling
13579function returns to its caller. This is so even when
13580@code{__builtin_alloca} is called within a nested block.
13581
13582For example, the following function allocates eight objects of @code{n}
13583bytes each on the stack, storing a pointer to each in consecutive elements
13584of the array @code{a}. It then passes the array to function @code{g}
13585which can safely use the storage pointed to by each of the array elements.
13586
13587@smallexample
13588void f (unsigned n)
13589@{
13590 void *a [8];
13591 for (int i = 0; i != 8; ++i)
13592 a [i] = __builtin_alloca (n);
13593
13594 g (a, n); // @r{safe}
13595@}
13596@end smallexample
13597
13598Since the @code{__builtin_alloca} function doesn't validate its argument
13599it is the responsibility of its caller to make sure the argument doesn't
13600cause it to exceed the stack size limit.
13601The @code{__builtin_alloca} function is provided to make it possible to
13602allocate on the stack arrays of bytes with an upper bound that may be
13603computed at run time. Since C99 Variable Length Arrays offer
13604similar functionality under a portable, more convenient, and safer
13605interface they are recommended instead, in both C99 and C++ programs
13606where GCC provides them as an extension.
13607@xref{Variable Length}, for details.
13608
f25efe50 13609@enddefbuiltin
d77de738 13610
f25efe50 13611@defbuiltin{{void *} __builtin_alloca_with_align (size_t size, size_t alignment)}
d77de738
ML
13612The @code{__builtin_alloca_with_align} function must be called at block
13613scope. The function allocates an object @var{size} bytes large on
13614the stack of the calling function. The allocated object is aligned on
13615the boundary specified by the argument @var{alignment} whose unit is given
13616in bits (not bytes). The @var{size} argument must be positive and not
13617exceed the stack size limit. The @var{alignment} argument must be a constant
13618integer expression that evaluates to a power of 2 greater than or equal to
13619@code{CHAR_BIT} and less than some unspecified maximum. Invocations
13620with other values are rejected with an error indicating the valid bounds.
13621The function returns a pointer to the first byte of the allocated object.
13622The lifetime of the allocated object ends at the end of the block in which
13623the function was called. The allocated storage is released no later than
13624just before the calling function returns to its caller, but may be released
13625at the end of the block in which the function was called.
13626
13627For example, in the following function the call to @code{g} is unsafe
13628because when @code{overalign} is non-zero, the space allocated by
13629@code{__builtin_alloca_with_align} may have been released at the end
13630of the @code{if} statement in which it was called.
13631
13632@smallexample
13633void f (unsigned n, bool overalign)
13634@{
13635 void *p;
13636 if (overalign)
13637 p = __builtin_alloca_with_align (n, 64 /* bits */);
13638 else
13639 p = __builtin_alloc (n);
13640
13641 g (p, n); // @r{unsafe}
13642@}
13643@end smallexample
13644
13645Since the @code{__builtin_alloca_with_align} function doesn't validate its
13646@var{size} argument it is the responsibility of its caller to make sure
13647the argument doesn't cause it to exceed the stack size limit.
13648The @code{__builtin_alloca_with_align} function is provided to make
13649it possible to allocate on the stack overaligned arrays of bytes with
13650an upper bound that may be computed at run time. Since C99
13651Variable Length Arrays offer the same functionality under
13652a portable, more convenient, and safer interface they are recommended
13653instead, in both C99 and C++ programs where GCC provides them as
13654an extension. @xref{Variable Length}, for details.
13655
f25efe50 13656@enddefbuiltin
d77de738 13657
f25efe50 13658@defbuiltin{{void *}__builtin_alloca_with_align_and_max (size_t size, size_t alignment, size_t max_size)}
d77de738
ML
13659Similar to @code{__builtin_alloca_with_align} but takes an extra argument
13660specifying an upper bound for @var{size} in case its value cannot be computed
13661at compile time, for use by @option{-fstack-usage}, @option{-Wstack-usage}
13662and @option{-Walloca-larger-than}. @var{max_size} must be a constant integer
13663expression, it has no effect on code generation and no attempt is made to
13664check its compatibility with @var{size}.
13665
f25efe50 13666@enddefbuiltin
d77de738 13667
f25efe50 13668@defbuiltin{bool __builtin_has_attribute (@var{type-or-expression}, @var{attribute})}
d77de738
ML
13669The @code{__builtin_has_attribute} function evaluates to an integer constant
13670expression equal to @code{true} if the symbol or type referenced by
13671the @var{type-or-expression} argument has been declared with
13672the @var{attribute} referenced by the second argument. For
13673an @var{type-or-expression} argument that does not reference a symbol,
13674since attributes do not apply to expressions the built-in consider
13675the type of the argument. Neither argument is evaluated.
13676The @var{type-or-expression} argument is subject to the same
13677restrictions as the argument to @code{typeof} (@pxref{Typeof}). The
13678@var{attribute} argument is an attribute name optionally followed by
13679a comma-separated list of arguments enclosed in parentheses. Both forms
13680of attribute names---with and without double leading and trailing
13681underscores---are recognized. @xref{Attribute Syntax}, for details.
13682When no attribute arguments are specified for an attribute that expects
13683one or more arguments the function returns @code{true} if
13684@var{type-or-expression} has been declared with the attribute regardless
13685of the attribute argument values. Arguments provided for an attribute
13686that expects some are validated and matched up to the provided number.
13687The function returns @code{true} if all provided arguments match. For
13688example, the first call to the function below evaluates to @code{true}
13689because @code{x} is declared with the @code{aligned} attribute but
13690the second call evaluates to @code{false} because @code{x} is declared
13691@code{aligned (8)} and not @code{aligned (4)}.
13692
13693@smallexample
13694__attribute__ ((aligned (8))) int x;
13695_Static_assert (__builtin_has_attribute (x, aligned), "aligned");
13696_Static_assert (!__builtin_has_attribute (x, aligned (4)), "aligned (4)");
13697@end smallexample
13698
13699Due to a limitation the @code{__builtin_has_attribute} function returns
13700@code{false} for the @code{mode} attribute even if the type or variable
13701referenced by the @var{type-or-expression} argument was declared with one.
13702The function is also not supported with labels, and in C with enumerators.
13703
13704Note that unlike the @code{__has_attribute} preprocessor operator which
13705is suitable for use in @code{#if} preprocessing directives
13706@code{__builtin_has_attribute} is an intrinsic function that is not
13707recognized in such contexts.
13708
f25efe50 13709@enddefbuiltin
d77de738 13710
f25efe50 13711@defbuiltin{@var{type} __builtin_speculation_safe_value (@var{type} val, @var{type} failval)}
d77de738
ML
13712
13713This built-in function can be used to help mitigate against unsafe
13714speculative execution. @var{type} may be any integral type or any
13715pointer type.
13716
13717@enumerate
13718@item
13719If the CPU is not speculatively executing the code, then @var{val}
13720is returned.
13721@item
13722If the CPU is executing speculatively then either:
13723@itemize
13724@item
13725The function may cause execution to pause until it is known that the
13726code is no-longer being executed speculatively (in which case
13727@var{val} can be returned, as above); or
13728@item
13729The function may use target-dependent speculation tracking state to cause
13730@var{failval} to be returned when it is known that speculative
13731execution has incorrectly predicted a conditional branch operation.
13732@end itemize
13733@end enumerate
13734
13735The second argument, @var{failval}, is optional and defaults to zero
13736if omitted.
13737
13738GCC defines the preprocessor macro
13739@code{__HAVE_BUILTIN_SPECULATION_SAFE_VALUE} for targets that have been
13740updated to support this builtin.
13741
13742The built-in function can be used where a variable appears to be used in a
13743safe way, but the CPU, due to speculative execution may temporarily ignore
13744the bounds checks. Consider, for example, the following function:
13745
13746@smallexample
13747int array[500];
13748int f (unsigned untrusted_index)
13749@{
13750 if (untrusted_index < 500)
13751 return array[untrusted_index];
13752 return 0;
13753@}
13754@end smallexample
13755
13756If the function is called repeatedly with @code{untrusted_index} less
13757than the limit of 500, then a branch predictor will learn that the
13758block of code that returns a value stored in @code{array} will be
13759executed. If the function is subsequently called with an
13760out-of-range value it will still try to execute that block of code
13761first until the CPU determines that the prediction was incorrect
13762(the CPU will unwind any incorrect operations at that point).
13763However, depending on how the result of the function is used, it might be
13764possible to leave traces in the cache that can reveal what was stored
13765at the out-of-bounds location. The built-in function can be used to
13766provide some protection against leaking data in this way by changing
13767the code to:
13768
13769@smallexample
13770int array[500];
13771int f (unsigned untrusted_index)
13772@{
13773 if (untrusted_index < 500)
13774 return array[__builtin_speculation_safe_value (untrusted_index)];
13775 return 0;
13776@}
13777@end smallexample
13778
13779The built-in function will either cause execution to stall until the
13780conditional branch has been fully resolved, or it may permit
13781speculative execution to continue, but using 0 instead of
13782@code{untrusted_value} if that exceeds the limit.
13783
13784If accessing any memory location is potentially unsafe when speculative
13785execution is incorrect, then the code can be rewritten as
13786
13787@smallexample
13788int array[500];
13789int f (unsigned untrusted_index)
13790@{
13791 if (untrusted_index < 500)
13792 return *__builtin_speculation_safe_value (&array[untrusted_index], NULL);
13793 return 0;
13794@}
13795@end smallexample
13796
13797which will cause a @code{NULL} pointer to be used for the unsafe case.
13798
f25efe50 13799@enddefbuiltin
d77de738 13800
f25efe50 13801@defbuiltin{int __builtin_types_compatible_p (@var{type1}, @var{type2})}
d77de738
ML
13802
13803You can use the built-in function @code{__builtin_types_compatible_p} to
13804determine whether two types are the same.
13805
13806This built-in function returns 1 if the unqualified versions of the
13807types @var{type1} and @var{type2} (which are types, not expressions) are
13808compatible, 0 otherwise. The result of this built-in function can be
13809used in integer constant expressions.
13810
13811This built-in function ignores top level qualifiers (e.g., @code{const},
13812@code{volatile}). For example, @code{int} is equivalent to @code{const
13813int}.
13814
13815The type @code{int[]} and @code{int[5]} are compatible. On the other
13816hand, @code{int} and @code{char *} are not compatible, even if the size
13817of their types, on the particular architecture are the same. Also, the
13818amount of pointer indirection is taken into account when determining
13819similarity. Consequently, @code{short *} is not similar to
13820@code{short **}. Furthermore, two types that are typedefed are
13821considered compatible if their underlying types are compatible.
13822
13823An @code{enum} type is not considered to be compatible with another
13824@code{enum} type even if both are compatible with the same integer
13825type; this is what the C standard specifies.
13826For example, @code{enum @{foo, bar@}} is not similar to
13827@code{enum @{hot, dog@}}.
13828
13829You typically use this function in code whose execution varies
13830depending on the arguments' types. For example:
13831
13832@smallexample
13833#define foo(x) \
13834 (@{ \
13835 typeof (x) tmp = (x); \
13836 if (__builtin_types_compatible_p (typeof (x), long double)) \
13837 tmp = foo_long_double (tmp); \
13838 else if (__builtin_types_compatible_p (typeof (x), double)) \
13839 tmp = foo_double (tmp); \
13840 else if (__builtin_types_compatible_p (typeof (x), float)) \
13841 tmp = foo_float (tmp); \
13842 else \
13843 abort (); \
13844 tmp; \
13845 @})
13846@end smallexample
13847
13848@emph{Note:} This construct is only available for C@.
13849
f25efe50 13850@enddefbuiltin
d77de738 13851
f25efe50 13852@defbuiltin{@var{type} __builtin_call_with_static_chain (@var{call_exp}, @var{pointer_exp})}
d77de738
ML
13853
13854The @var{call_exp} expression must be a function call, and the
13855@var{pointer_exp} expression must be a pointer. The @var{pointer_exp}
13856is passed to the function call in the target's static chain location.
13857The result of builtin is the result of the function call.
13858
13859@emph{Note:} This builtin is only available for C@.
13860This builtin can be used to call Go closures from C.
13861
f25efe50 13862@enddefbuiltin
d77de738 13863
f25efe50 13864@defbuiltin{@var{type} __builtin_choose_expr (@var{const_exp}, @var{exp1}, @var{exp2})}
d77de738
ML
13865
13866You can use the built-in function @code{__builtin_choose_expr} to
13867evaluate code depending on the value of a constant expression. This
13868built-in function returns @var{exp1} if @var{const_exp}, which is an
13869integer constant expression, is nonzero. Otherwise it returns @var{exp2}.
13870
13871This built-in function is analogous to the @samp{? :} operator in C,
13872except that the expression returned has its type unaltered by promotion
13873rules. Also, the built-in function does not evaluate the expression
13874that is not chosen. For example, if @var{const_exp} evaluates to @code{true},
13875@var{exp2} is not evaluated even if it has side effects.
13876
13877This built-in function can return an lvalue if the chosen argument is an
13878lvalue.
13879
13880If @var{exp1} is returned, the return type is the same as @var{exp1}'s
13881type. Similarly, if @var{exp2} is returned, its return type is the same
13882as @var{exp2}.
13883
13884Example:
13885
13886@smallexample
13887#define foo(x) \
13888 __builtin_choose_expr ( \
13889 __builtin_types_compatible_p (typeof (x), double), \
13890 foo_double (x), \
13891 __builtin_choose_expr ( \
13892 __builtin_types_compatible_p (typeof (x), float), \
13893 foo_float (x), \
13894 /* @r{The void expression results in a compile-time error} \
13895 @r{when assigning the result to something.} */ \
13896 (void)0))
13897@end smallexample
13898
13899@emph{Note:} This construct is only available for C@. Furthermore, the
13900unused expression (@var{exp1} or @var{exp2} depending on the value of
13901@var{const_exp}) may still generate syntax errors. This may change in
13902future revisions.
13903
f25efe50 13904@enddefbuiltin
d77de738 13905
f25efe50 13906@defbuiltin{@var{type} __builtin_tgmath (@var{functions}, @var{arguments})}
d77de738
ML
13907
13908The built-in function @code{__builtin_tgmath}, available only for C
13909and Objective-C, calls a function determined according to the rules of
13910@code{<tgmath.h>} macros. It is intended to be used in
13911implementations of that header, so that expansions of macros from that
13912header only expand each of their arguments once, to avoid problems
13913when calls to such macros are nested inside the arguments of other
13914calls to such macros; in addition, it results in better diagnostics
13915for invalid calls to @code{<tgmath.h>} macros than implementations
13916using other GNU C language features. For example, the @code{pow}
13917type-generic macro might be defined as:
13918
13919@smallexample
13920#define pow(a, b) __builtin_tgmath (powf, pow, powl, \
13921 cpowf, cpow, cpowl, a, b)
13922@end smallexample
13923
13924The arguments to @code{__builtin_tgmath} are at least two pointers to
13925functions, followed by the arguments to the type-generic macro (which
13926will be passed as arguments to the selected function). All the
13927pointers to functions must be pointers to prototyped functions, none
13928of which may have variable arguments, and all of which must have the
13929same number of parameters; the number of parameters of the first
13930function determines how many arguments to @code{__builtin_tgmath} are
13931interpreted as function pointers, and how many as the arguments to the
13932called function.
13933
13934The types of the specified functions must all be different, but
13935related to each other in the same way as a set of functions that may
13936be selected between by a macro in @code{<tgmath.h>}. This means that
13937the functions are parameterized by a floating-point type @var{t},
13938different for each such function. The function return types may all
13939be the same type, or they may be @var{t} for each function, or they
13940may be the real type corresponding to @var{t} for each function (if
13941some of the types @var{t} are complex). Likewise, for each parameter
13942position, the type of the parameter in that position may always be the
13943same type, or may be @var{t} for each function (this case must apply
13944for at least one parameter position), or may be the real type
13945corresponding to @var{t} for each function.
13946
13947The standard rules for @code{<tgmath.h>} macros are used to find a
13948common type @var{u} from the types of the arguments for parameters
13949whose types vary between the functions; complex integer types (a GNU
5b68fb47
JM
13950extension) are treated like the complex type corresponding to the real
13951floating type that would be chosen for the corresponding real integer type.
d77de738
ML
13952If the function return types vary, or are all the same integer type,
13953the function called is the one for which @var{t} is @var{u}, and it is
13954an error if there is no such function. If the function return types
13955are all the same floating-point type, the type-generic macro is taken
13956to be one of those from TS 18661 that rounds the result to a narrower
13957type; if there is a function for which @var{t} is @var{u}, it is
13958called, and otherwise the first function, if any, for which @var{t}
13959has at least the range and precision of @var{u} is called, and it is
13960an error if there is no such function.
13961
f25efe50 13962@enddefbuiltin
d77de738 13963
f25efe50 13964@defbuiltin{int __builtin_constant_p (@var{exp})}
d77de738
ML
13965You can use the built-in function @code{__builtin_constant_p} to
13966determine if a value is known to be constant at compile time and hence
13967that GCC can perform constant-folding on expressions involving that
13968value. The argument of the function is the value to test. The function
13969returns the integer 1 if the argument is known to be a compile-time
13970constant and 0 if it is not known to be a compile-time constant. A
13971return of 0 does not indicate that the value is @emph{not} a constant,
13972but merely that GCC cannot prove it is a constant with the specified
13973value of the @option{-O} option.
13974
13975You typically use this function in an embedded application where
13976memory is a critical resource. If you have some complex calculation,
13977you may want it to be folded if it involves constants, but need to call
13978a function if it does not. For example:
13979
13980@smallexample
13981#define Scale_Value(X) \
13982 (__builtin_constant_p (X) \
13983 ? ((X) * SCALE + OFFSET) : Scale (X))
13984@end smallexample
13985
13986You may use this built-in function in either a macro or an inline
13987function. However, if you use it in an inlined function and pass an
13988argument of the function as the argument to the built-in, GCC
13989never returns 1 when you call the inline function with a string constant
13990or compound literal (@pxref{Compound Literals}) and does not return 1
13991when you pass a constant numeric value to the inline function unless you
13992specify the @option{-O} option.
13993
13994You may also use @code{__builtin_constant_p} in initializers for static
13995data. For instance, you can write
13996
13997@smallexample
13998static const int table[] = @{
13999 __builtin_constant_p (EXPRESSION) ? (EXPRESSION) : -1,
14000 /* @r{@dots{}} */
14001@};
14002@end smallexample
14003
14004@noindent
14005This is an acceptable initializer even if @var{EXPRESSION} is not a
14006constant expression, including the case where
14007@code{__builtin_constant_p} returns 1 because @var{EXPRESSION} can be
14008folded to a constant but @var{EXPRESSION} contains operands that are
14009not otherwise permitted in a static initializer (for example,
14010@code{0 && foo ()}). GCC must be more conservative about evaluating the
14011built-in in this case, because it has no opportunity to perform
14012optimization.
f25efe50 14013@enddefbuiltin
d77de738 14014
f25efe50 14015@defbuiltin{bool __builtin_is_constant_evaluated (void)}
d77de738
ML
14016The @code{__builtin_is_constant_evaluated} function is available only
14017in C++. The built-in is intended to be used by implementations of
14018the @code{std::is_constant_evaluated} C++ function. Programs should make
14019use of the latter function rather than invoking the built-in directly.
14020
14021The main use case of the built-in is to determine whether a @code{constexpr}
14022function is being called in a @code{constexpr} context. A call to
14023the function evaluates to a core constant expression with the value
14024@code{true} if and only if it occurs within the evaluation of an expression
14025or conversion that is manifestly constant-evaluated as defined in the C++
14026standard. Manifestly constant-evaluated contexts include constant-expressions,
14027the conditions of @code{constexpr if} statements, constraint-expressions, and
14028initializers of variables usable in constant expressions. For more details
14029refer to the latest revision of the C++ standard.
f25efe50 14030@enddefbuiltin
d77de738 14031
f25efe50 14032@defbuiltin{void __builtin_clear_padding (@var{ptr})}
d77de738
ML
14033The built-in function @code{__builtin_clear_padding} function clears
14034padding bits inside of the object representation of object pointed by
14035@var{ptr}, which has to be a pointer. The value representation of the
14036object is not affected. The type of the object is assumed to be the type
14037the pointer points to. Inside of a union, the only cleared bits are
14038bits that are padding bits for all the union members.
14039
14040This built-in-function is useful if the padding bits of an object might
14041have intederminate values and the object representation needs to be
14042bitwise compared to some other object, for example for atomic operations.
14043
14044For C++, @var{ptr} argument type should be pointer to trivially-copyable
14045type, unless the argument is address of a variable or parameter, because
14046otherwise it isn't known if the type isn't just a base class whose padding
14047bits are reused or laid out differently in a derived class.
f25efe50 14048@enddefbuiltin
d77de738 14049
f25efe50 14050@defbuiltin{@var{type} __builtin_bit_cast (@var{type}, @var{arg})}
d77de738
ML
14051The @code{__builtin_bit_cast} function is available only
14052in C++. The built-in is intended to be used by implementations of
14053the @code{std::bit_cast} C++ template function. Programs should make
14054use of the latter function rather than invoking the built-in directly.
14055
14056This built-in function allows reinterpreting the bits of the @var{arg}
14057argument as if it had type @var{type}. @var{type} and the type of the
14058@var{arg} argument need to be trivially copyable types with the same size.
14059When manifestly constant-evaluated, it performs extra diagnostics required
14060for @code{std::bit_cast} and returns a constant expression if @var{arg}
14061is a constant expression. For more details
14062refer to the latest revision of the C++ standard.
f25efe50 14063@enddefbuiltin
d77de738 14064
f25efe50 14065@defbuiltin{long __builtin_expect (long @var{exp}, long @var{c})}
d77de738
ML
14066@opindex fprofile-arcs
14067You may use @code{__builtin_expect} to provide the compiler with
14068branch prediction information. In general, you should prefer to
14069use actual profile feedback for this (@option{-fprofile-arcs}), as
14070programmers are notoriously bad at predicting how their programs
14071actually perform. However, there are applications in which this
14072data is hard to collect.
14073
14074The return value is the value of @var{exp}, which should be an integral
14075expression. The semantics of the built-in are that it is expected that
14076@var{exp} == @var{c}. For example:
14077
14078@smallexample
14079if (__builtin_expect (x, 0))
14080 foo ();
14081@end smallexample
14082
14083@noindent
14084indicates that we do not expect to call @code{foo}, since
14085we expect @code{x} to be zero. Since you are limited to integral
14086expressions for @var{exp}, you should use constructions such as
14087
14088@smallexample
14089if (__builtin_expect (ptr != NULL, 1))
14090 foo (*ptr);
14091@end smallexample
14092
14093@noindent
14094when testing pointer or floating-point values.
14095
14096For the purposes of branch prediction optimizations, the probability that
14097a @code{__builtin_expect} expression is @code{true} is controlled by GCC's
14098@code{builtin-expect-probability} parameter, which defaults to 90%.
14099
14100You can also use @code{__builtin_expect_with_probability} to explicitly
14101assign a probability value to individual expressions. If the built-in
14102is used in a loop construct, the provided probability will influence
14103the expected number of iterations made by loop optimizations.
f25efe50 14104@enddefbuiltin
d77de738 14105
f25efe50 14106@defbuiltin{long __builtin_expect_with_probability}
d77de738
ML
14107(long @var{exp}, long @var{c}, double @var{probability})
14108
14109This function has the same semantics as @code{__builtin_expect},
14110but the caller provides the expected probability that @var{exp} == @var{c}.
14111The last argument, @var{probability}, is a floating-point value in the
14112range 0.0 to 1.0, inclusive. The @var{probability} argument must be
14113constant floating-point expression.
f25efe50 14114@enddefbuiltin
d77de738 14115
f25efe50 14116@defbuiltin{void __builtin_trap (void)}
d77de738
ML
14117This function causes the program to exit abnormally. GCC implements
14118this function by using a target-dependent mechanism (such as
14119intentionally executing an illegal instruction) or by calling
14120@code{abort}. The mechanism used may vary from release to release so
14121you should not rely on any particular implementation.
f25efe50 14122@enddefbuiltin
d77de738 14123
f25efe50 14124@defbuiltin{void __builtin_unreachable (void)}
d77de738
ML
14125If control flow reaches the point of the @code{__builtin_unreachable},
14126the program is undefined. It is useful in situations where the
14127compiler cannot deduce the unreachability of the code.
14128
14129One such case is immediately following an @code{asm} statement that
14130either never terminates, or one that transfers control elsewhere
14131and never returns. In this example, without the
14132@code{__builtin_unreachable}, GCC issues a warning that control
14133reaches the end of a non-void function. It also generates code
14134to return after the @code{asm}.
14135
14136@smallexample
14137int f (int c, int v)
14138@{
14139 if (c)
14140 @{
14141 return v;
14142 @}
14143 else
14144 @{
14145 asm("jmp error_handler");
14146 __builtin_unreachable ();
14147 @}
14148@}
14149@end smallexample
14150
14151@noindent
14152Because the @code{asm} statement unconditionally transfers control out
14153of the function, control never reaches the end of the function
14154body. The @code{__builtin_unreachable} is in fact unreachable and
14155communicates this fact to the compiler.
14156
14157Another use for @code{__builtin_unreachable} is following a call a
14158function that never returns but that is not declared
14159@code{__attribute__((noreturn))}, as in this example:
14160
14161@smallexample
14162void function_that_never_returns (void);
14163
14164int g (int c)
14165@{
14166 if (c)
14167 @{
14168 return 1;
14169 @}
14170 else
14171 @{
14172 function_that_never_returns ();
14173 __builtin_unreachable ();
14174 @}
14175@}
14176@end smallexample
14177
f25efe50 14178@enddefbuiltin
d77de738 14179
f25efe50 14180@defbuiltin{@var{type} __builtin_assoc_barrier (@var{type} @var{expr})}
d77de738
ML
14181This built-in inhibits re-association of the floating-point expression
14182@var{expr} with expressions consuming the return value of the built-in. The
14183expression @var{expr} itself can be reordered, and the whole expression
14184@var{expr} can be reordered with operands after the barrier. The barrier is
14185only relevant when @code{-fassociative-math} is active, since otherwise
14186floating-point is not treated as associative.
14187
14188@smallexample
14189float x0 = a + b - b;
14190float x1 = __builtin_assoc_barrier(a + b) - b;
14191@end smallexample
14192
14193@noindent
14194means that, with @code{-fassociative-math}, @code{x0} can be optimized to
14195@code{x0 = a} but @code{x1} cannot.
f25efe50 14196@enddefbuiltin
d77de738 14197
f25efe50 14198@defbuiltin{{void *} __builtin_assume_aligned (const void *@var{exp}, size_t @var{align}, ...)}
d77de738
ML
14199This function returns its first argument, and allows the compiler
14200to assume that the returned pointer is at least @var{align} bytes
14201aligned. This built-in can have either two or three arguments,
14202if it has three, the third argument should have integer type, and
14203if it is nonzero means misalignment offset. For example:
14204
14205@smallexample
14206void *x = __builtin_assume_aligned (arg, 16);
14207@end smallexample
14208
14209@noindent
14210means that the compiler can assume @code{x}, set to @code{arg}, is at least
1421116-byte aligned, while:
14212
14213@smallexample
14214void *x = __builtin_assume_aligned (arg, 32, 8);
14215@end smallexample
14216
14217@noindent
14218means that the compiler can assume for @code{x}, set to @code{arg}, that
14219@code{(char *) x - 8} is 32-byte aligned.
f25efe50 14220@enddefbuiltin
d77de738 14221
f25efe50 14222@defbuiltin{int __builtin_LINE ()}
d77de738
ML
14223This function is the equivalent of the preprocessor @code{__LINE__}
14224macro and returns a constant integer expression that evaluates to
14225the line number of the invocation of the built-in. When used as a C++
14226default argument for a function @var{F}, it returns the line number
14227of the call to @var{F}.
f25efe50 14228@enddefbuiltin
d77de738 14229
f25efe50 14230@defbuiltin{{const char *} __builtin_FUNCTION ()}
d77de738
ML
14231This function is the equivalent of the @code{__FUNCTION__} symbol
14232and returns an address constant pointing to the name of the function
14233from which the built-in was invoked, or the empty string if
14234the invocation is not at function scope. When used as a C++ default
14235argument for a function @var{F}, it returns the name of @var{F}'s
14236caller or the empty string if the call was not made at function
14237scope.
f25efe50 14238@enddefbuiltin
d77de738 14239
f25efe50 14240@defbuiltin{{const char *} __builtin_FILE ()}
d77de738
ML
14241This function is the equivalent of the preprocessor @code{__FILE__}
14242macro and returns an address constant pointing to the file name
14243containing the invocation of the built-in, or the empty string if
14244the invocation is not at function scope. When used as a C++ default
14245argument for a function @var{F}, it returns the file name of the call
14246to @var{F} or the empty string if the call was not made at function
14247scope.
14248
14249For example, in the following, each call to function @code{foo} will
14250print a line similar to @code{"file.c:123: foo: message"} with the name
14251of the file and the line number of the @code{printf} call, the name of
14252the function @code{foo}, followed by the word @code{message}.
14253
14254@smallexample
14255const char*
14256function (const char *func = __builtin_FUNCTION ())
14257@{
14258 return func;
14259@}
14260
14261void foo (void)
14262@{
14263 printf ("%s:%i: %s: message\n", file (), line (), function ());
14264@}
14265@end smallexample
14266
f25efe50 14267@enddefbuiltin
d77de738 14268
f25efe50 14269@defbuiltin{void __builtin___clear_cache (void *@var{begin}, void *@var{end})}
d77de738
ML
14270This function is used to flush the processor's instruction cache for
14271the region of memory between @var{begin} inclusive and @var{end}
14272exclusive. Some targets require that the instruction cache be
14273flushed, after modifying memory containing code, in order to obtain
14274deterministic behavior.
14275
14276If the target does not require instruction cache flushes,
14277@code{__builtin___clear_cache} has no effect. Otherwise either
14278instructions are emitted in-line to clear the instruction cache or a
14279call to the @code{__clear_cache} function in libgcc is made.
f25efe50 14280@enddefbuiltin
d77de738 14281
f25efe50 14282@defbuiltin{void __builtin_prefetch (const void *@var{addr}, ...)}
d77de738
ML
14283This function is used to minimize cache-miss latency by moving data into
14284a cache before it is accessed.
14285You can insert calls to @code{__builtin_prefetch} into code for which
14286you know addresses of data in memory that is likely to be accessed soon.
14287If the target supports them, data prefetch instructions are generated.
14288If the prefetch is done early enough before the access then the data will
14289be in the cache by the time it is accessed.
14290
14291The value of @var{addr} is the address of the memory to prefetch.
14292There are two optional arguments, @var{rw} and @var{locality}.
14293The value of @var{rw} is a compile-time constant one or zero; one
14294means that the prefetch is preparing for a write to the memory address
14295and zero, the default, means that the prefetch is preparing for a read.
14296The value @var{locality} must be a compile-time constant integer between
14297zero and three. A value of zero means that the data has no temporal
14298locality, so it need not be left in the cache after the access. A value
14299of three means that the data has a high degree of temporal locality and
14300should be left in all levels of cache possible. Values of one and two
14301mean, respectively, a low or moderate degree of temporal locality. The
14302default is three.
14303
14304@smallexample
14305for (i = 0; i < n; i++)
14306 @{
14307 a[i] = a[i] + b[i];
14308 __builtin_prefetch (&a[i+j], 1, 1);
14309 __builtin_prefetch (&b[i+j], 0, 1);
14310 /* @r{@dots{}} */
14311 @}
14312@end smallexample
14313
14314Data prefetch does not generate faults if @var{addr} is invalid, but
14315the address expression itself must be valid. For example, a prefetch
14316of @code{p->next} does not fault if @code{p->next} is not a valid
14317address, but evaluation faults if @code{p} is not a valid address.
14318
14319If the target does not support data prefetch, the address expression
14320is evaluated if it includes side effects but no other code is generated
14321and GCC does not issue a warning.
f25efe50 14322@enddefbuiltin
d77de738 14323
f25efe50 14324@defbuiltin{{size_t} __builtin_object_size (const void * @var{ptr}, int @var{type})}
f5300d28
SP
14325Returns a constant size estimate of an object pointed to by @var{ptr}.
14326@xref{Object Size Checking}, for a detailed description of the function.
f25efe50 14327@enddefbuiltin
f5300d28 14328
f25efe50 14329@defbuiltin{{size_t} __builtin_dynamic_object_size (const void * @var{ptr}, int @var{type})}
f5300d28
SP
14330Similar to @code{__builtin_object_size} except that the return value
14331need not be a constant. @xref{Object Size Checking}, for a detailed
14332description of the function.
f25efe50 14333@enddefbuiltin
d77de738 14334
f25efe50 14335@defbuiltin{double __builtin_huge_val (void)}
d77de738
ML
14336Returns a positive infinity, if supported by the floating-point format,
14337else @code{DBL_MAX}. This function is suitable for implementing the
14338ISO C macro @code{HUGE_VAL}.
f25efe50 14339@enddefbuiltin
d77de738 14340
f25efe50 14341@defbuiltin{float __builtin_huge_valf (void)}
d77de738 14342Similar to @code{__builtin_huge_val}, except the return type is @code{float}.
f25efe50 14343@enddefbuiltin
d77de738 14344
f25efe50 14345@defbuiltin{{long double} __builtin_huge_vall (void)}
d77de738
ML
14346Similar to @code{__builtin_huge_val}, except the return
14347type is @code{long double}.
f25efe50 14348@enddefbuiltin
d77de738 14349
f25efe50 14350@defbuiltin{_Float@var{n} __builtin_huge_valf@var{n} (void)}
d77de738
ML
14351Similar to @code{__builtin_huge_val}, except the return type is
14352@code{_Float@var{n}}.
f25efe50 14353@enddefbuiltin
d77de738 14354
f25efe50 14355@defbuiltin{_Float@var{n}x __builtin_huge_valf@var{n}x (void)}
d77de738
ML
14356Similar to @code{__builtin_huge_val}, except the return type is
14357@code{_Float@var{n}x}.
f25efe50 14358@enddefbuiltin
d77de738 14359
f25efe50 14360@defbuiltin{int __builtin_fpclassify (int, int, int, int, int, ...)}
d77de738
ML
14361This built-in implements the C99 fpclassify functionality. The first
14362five int arguments should be the target library's notion of the
14363possible FP classes and are used for return values. They must be
14364constant values and they must appear in this order: @code{FP_NAN},
14365@code{FP_INFINITE}, @code{FP_NORMAL}, @code{FP_SUBNORMAL} and
14366@code{FP_ZERO}. The ellipsis is for exactly one floating-point value
14367to classify. GCC treats the last argument as type-generic, which
14368means it does not do default promotion from float to double.
f25efe50 14369@enddefbuiltin
d77de738 14370
f25efe50 14371@defbuiltin{double __builtin_inf (void)}
d77de738
ML
14372Similar to @code{__builtin_huge_val}, except a warning is generated
14373if the target floating-point format does not support infinities.
f25efe50 14374@enddefbuiltin
d77de738 14375
f25efe50 14376@defbuiltin{_Decimal32 __builtin_infd32 (void)}
d77de738 14377Similar to @code{__builtin_inf}, except the return type is @code{_Decimal32}.
f25efe50 14378@enddefbuiltin
d77de738 14379
f25efe50 14380@defbuiltin{_Decimal64 __builtin_infd64 (void)}
d77de738 14381Similar to @code{__builtin_inf}, except the return type is @code{_Decimal64}.
f25efe50 14382@enddefbuiltin
d77de738 14383
f25efe50 14384@defbuiltin{_Decimal128 __builtin_infd128 (void)}
d77de738 14385Similar to @code{__builtin_inf}, except the return type is @code{_Decimal128}.
f25efe50 14386@enddefbuiltin
d77de738 14387
f25efe50 14388@defbuiltin{float __builtin_inff (void)}
d77de738
ML
14389Similar to @code{__builtin_inf}, except the return type is @code{float}.
14390This function is suitable for implementing the ISO C99 macro @code{INFINITY}.
f25efe50 14391@enddefbuiltin
d77de738 14392
f25efe50 14393@defbuiltin{{long double} __builtin_infl (void)}
d77de738
ML
14394Similar to @code{__builtin_inf}, except the return
14395type is @code{long double}.
f25efe50 14396@enddefbuiltin
d77de738 14397
f25efe50 14398@defbuiltin{_Float@var{n} __builtin_inff@var{n} (void)}
d77de738
ML
14399Similar to @code{__builtin_inf}, except the return
14400type is @code{_Float@var{n}}.
f25efe50 14401@enddefbuiltin
d77de738 14402
f25efe50 14403@defbuiltin{_Float@var{n} __builtin_inff@var{n}x (void)}
d77de738
ML
14404Similar to @code{__builtin_inf}, except the return
14405type is @code{_Float@var{n}x}.
f25efe50 14406@enddefbuiltin
d77de738 14407
f25efe50 14408@defbuiltin{int __builtin_isinf_sign (...)}
d77de738
ML
14409Similar to @code{isinf}, except the return value is -1 for
14410an argument of @code{-Inf} and 1 for an argument of @code{+Inf}.
14411Note while the parameter list is an
14412ellipsis, this function only accepts exactly one floating-point
14413argument. GCC treats this parameter as type-generic, which means it
14414does not do default promotion from float to double.
f25efe50 14415@enddefbuiltin
d77de738 14416
f25efe50 14417@defbuiltin{double __builtin_nan (const char *str)}
d77de738
ML
14418This is an implementation of the ISO C99 function @code{nan}.
14419
14420Since ISO C99 defines this function in terms of @code{strtod}, which we
14421do not implement, a description of the parsing is in order. The string
14422is parsed as by @code{strtol}; that is, the base is recognized by
14423leading @samp{0} or @samp{0x} prefixes. The number parsed is placed
14424in the significand such that the least significant bit of the number
14425is at the least significant bit of the significand. The number is
14426truncated to fit the significand field provided. The significand is
14427forced to be a quiet NaN@.
14428
14429This function, if given a string literal all of which would have been
14430consumed by @code{strtol}, is evaluated early enough that it is considered a
14431compile-time constant.
f25efe50 14432@enddefbuiltin
d77de738 14433
f25efe50 14434@defbuiltin{_Decimal32 __builtin_nand32 (const char *str)}
d77de738 14435Similar to @code{__builtin_nan}, except the return type is @code{_Decimal32}.
f25efe50 14436@enddefbuiltin
d77de738 14437
f25efe50 14438@defbuiltin{_Decimal64 __builtin_nand64 (const char *str)}
d77de738 14439Similar to @code{__builtin_nan}, except the return type is @code{_Decimal64}.
f25efe50 14440@enddefbuiltin
d77de738 14441
f25efe50 14442@defbuiltin{_Decimal128 __builtin_nand128 (const char *str)}
d77de738 14443Similar to @code{__builtin_nan}, except the return type is @code{_Decimal128}.
f25efe50 14444@enddefbuiltin
d77de738 14445
f25efe50 14446@defbuiltin{float __builtin_nanf (const char *str)}
d77de738 14447Similar to @code{__builtin_nan}, except the return type is @code{float}.
f25efe50 14448@enddefbuiltin
d77de738 14449
f25efe50 14450@defbuiltin{{long double} __builtin_nanl (const char *str)}
d77de738 14451Similar to @code{__builtin_nan}, except the return type is @code{long double}.
f25efe50 14452@enddefbuiltin
d77de738 14453
f25efe50 14454@defbuiltin{_Float@var{n} __builtin_nanf@var{n} (const char *str)}
d77de738
ML
14455Similar to @code{__builtin_nan}, except the return type is
14456@code{_Float@var{n}}.
f25efe50 14457@enddefbuiltin
d77de738 14458
f25efe50 14459@defbuiltin{_Float@var{n}x __builtin_nanf@var{n}x (const char *str)}
d77de738
ML
14460Similar to @code{__builtin_nan}, except the return type is
14461@code{_Float@var{n}x}.
f25efe50 14462@enddefbuiltin
d77de738 14463
f25efe50 14464@defbuiltin{double __builtin_nans (const char *str)}
d77de738
ML
14465Similar to @code{__builtin_nan}, except the significand is forced
14466to be a signaling NaN@. The @code{nans} function is proposed by
d1bf1c97 14467@uref{https://www.open-std.org/jtc1/sc22/wg14/www/docs/n965.htm,,WG14 N965}.
f25efe50 14468@enddefbuiltin
d77de738 14469
f25efe50 14470@defbuiltin{_Decimal32 __builtin_nansd32 (const char *str)}
d77de738 14471Similar to @code{__builtin_nans}, except the return type is @code{_Decimal32}.
f25efe50 14472@enddefbuiltin
d77de738 14473
f25efe50 14474@defbuiltin{_Decimal64 __builtin_nansd64 (const char *str)}
d77de738 14475Similar to @code{__builtin_nans}, except the return type is @code{_Decimal64}.
f25efe50 14476@enddefbuiltin
d77de738 14477
f25efe50 14478@defbuiltin{_Decimal128 __builtin_nansd128 (const char *str)}
d77de738 14479Similar to @code{__builtin_nans}, except the return type is @code{_Decimal128}.
f25efe50 14480@enddefbuiltin
d77de738 14481
f25efe50 14482@defbuiltin{float __builtin_nansf (const char *str)}
d77de738 14483Similar to @code{__builtin_nans}, except the return type is @code{float}.
f25efe50 14484@enddefbuiltin
d77de738 14485
f25efe50 14486@defbuiltin{{long double} __builtin_nansl (const char *str)}
d77de738 14487Similar to @code{__builtin_nans}, except the return type is @code{long double}.
f25efe50 14488@enddefbuiltin
d77de738 14489
f25efe50 14490@defbuiltin{_Float@var{n} __builtin_nansf@var{n} (const char *str)}
d77de738
ML
14491Similar to @code{__builtin_nans}, except the return type is
14492@code{_Float@var{n}}.
f25efe50 14493@enddefbuiltin
d77de738 14494
f25efe50 14495@defbuiltin{_Float@var{n}x __builtin_nansf@var{n}x (const char *str)}
d77de738
ML
14496Similar to @code{__builtin_nans}, except the return type is
14497@code{_Float@var{n}x}.
f25efe50 14498@enddefbuiltin
d77de738 14499
f25efe50 14500@defbuiltin{int __builtin_issignaling (...)}
d77de738
ML
14501Return non-zero if the argument is a signaling NaN and zero otherwise.
14502Note while the parameter list is an
14503ellipsis, this function only accepts exactly one floating-point
14504argument. GCC treats this parameter as type-generic, which means it
14505does not do default promotion from float to double.
14506This built-in function can work even without the non-default
14507@code{-fsignaling-nans} option, although if a signaling NaN is computed,
14508stored or passed as argument to some function other than this built-in
14509in the current translation unit, it is safer to use @code{-fsignaling-nans}.
14510With @code{-ffinite-math-only} option this built-in function will always
14511return 0.
f25efe50 14512@enddefbuiltin
d77de738 14513
f25efe50 14514@defbuiltin{int __builtin_ffs (int x)}
d77de738
ML
14515Returns one plus the index of the least significant 1-bit of @var{x}, or
14516if @var{x} is zero, returns zero.
f25efe50 14517@enddefbuiltin
d77de738 14518
f25efe50 14519@defbuiltin{int __builtin_clz (unsigned int x)}
d77de738
ML
14520Returns the number of leading 0-bits in @var{x}, starting at the most
14521significant bit position. If @var{x} is 0, the result is undefined.
f25efe50 14522@enddefbuiltin
d77de738 14523
f25efe50 14524@defbuiltin{int __builtin_ctz (unsigned int x)}
d77de738
ML
14525Returns the number of trailing 0-bits in @var{x}, starting at the least
14526significant bit position. If @var{x} is 0, the result is undefined.
f25efe50 14527@enddefbuiltin
d77de738 14528
f25efe50 14529@defbuiltin{int __builtin_clrsb (int x)}
d77de738
ML
14530Returns the number of leading redundant sign bits in @var{x}, i.e.@: the
14531number of bits following the most significant bit that are identical
14532to it. There are no special cases for 0 or other values.
f25efe50 14533@enddefbuiltin
d77de738 14534
f25efe50 14535@defbuiltin{int __builtin_popcount (unsigned int x)}
d77de738 14536Returns the number of 1-bits in @var{x}.
f25efe50 14537@enddefbuiltin
d77de738 14538
f25efe50 14539@defbuiltin{int __builtin_parity (unsigned int x)}
d77de738
ML
14540Returns the parity of @var{x}, i.e.@: the number of 1-bits in @var{x}
14541modulo 2.
f25efe50 14542@enddefbuiltin
d77de738 14543
f25efe50 14544@defbuiltin{int __builtin_ffsl (long)}
d77de738
ML
14545Similar to @code{__builtin_ffs}, except the argument type is
14546@code{long}.
f25efe50 14547@enddefbuiltin
d77de738 14548
f25efe50 14549@defbuiltin{int __builtin_clzl (unsigned long)}
d77de738
ML
14550Similar to @code{__builtin_clz}, except the argument type is
14551@code{unsigned long}.
f25efe50 14552@enddefbuiltin
d77de738 14553
f25efe50 14554@defbuiltin{int __builtin_ctzl (unsigned long)}
d77de738
ML
14555Similar to @code{__builtin_ctz}, except the argument type is
14556@code{unsigned long}.
f25efe50 14557@enddefbuiltin
d77de738 14558
f25efe50 14559@defbuiltin{int __builtin_clrsbl (long)}
d77de738
ML
14560Similar to @code{__builtin_clrsb}, except the argument type is
14561@code{long}.
f25efe50 14562@enddefbuiltin
d77de738 14563
f25efe50 14564@defbuiltin{int __builtin_popcountl (unsigned long)}
d77de738
ML
14565Similar to @code{__builtin_popcount}, except the argument type is
14566@code{unsigned long}.
f25efe50 14567@enddefbuiltin
d77de738 14568
f25efe50 14569@defbuiltin{int __builtin_parityl (unsigned long)}
d77de738
ML
14570Similar to @code{__builtin_parity}, except the argument type is
14571@code{unsigned long}.
f25efe50 14572@enddefbuiltin
d77de738 14573
f25efe50 14574@defbuiltin{int __builtin_ffsll (long long)}
d77de738
ML
14575Similar to @code{__builtin_ffs}, except the argument type is
14576@code{long long}.
f25efe50 14577@enddefbuiltin
d77de738 14578
f25efe50 14579@defbuiltin{int __builtin_clzll (unsigned long long)}
d77de738
ML
14580Similar to @code{__builtin_clz}, except the argument type is
14581@code{unsigned long long}.
f25efe50 14582@enddefbuiltin
d77de738 14583
f25efe50 14584@defbuiltin{int __builtin_ctzll (unsigned long long)}
d77de738
ML
14585Similar to @code{__builtin_ctz}, except the argument type is
14586@code{unsigned long long}.
f25efe50 14587@enddefbuiltin
d77de738 14588
f25efe50 14589@defbuiltin{int __builtin_clrsbll (long long)}
d77de738
ML
14590Similar to @code{__builtin_clrsb}, except the argument type is
14591@code{long long}.
f25efe50 14592@enddefbuiltin
d77de738 14593
f25efe50 14594@defbuiltin{int __builtin_popcountll (unsigned long long)}
d77de738
ML
14595Similar to @code{__builtin_popcount}, except the argument type is
14596@code{unsigned long long}.
f25efe50 14597@enddefbuiltin
d77de738 14598
f25efe50 14599@defbuiltin{int __builtin_parityll (unsigned long long)}
d77de738
ML
14600Similar to @code{__builtin_parity}, except the argument type is
14601@code{unsigned long long}.
f25efe50 14602@enddefbuiltin
d77de738 14603
f25efe50
AA
14604@defbuiltin{double __builtin_powi (double, int)}
14605@defbuiltinx{float __builtin_powif (float, int)}
14606@defbuiltinx{{long double} __builtin_powil (long double, int)}
d77de738
ML
14607Returns the first argument raised to the power of the second. Unlike the
14608@code{pow} function no guarantees about precision and rounding are made.
f25efe50 14609@enddefbuiltin
d77de738 14610
f25efe50 14611@defbuiltin{uint16_t __builtin_bswap16 (uint16_t x)}
d77de738
ML
14612Returns @var{x} with the order of the bytes reversed; for example,
14613@code{0xaabb} becomes @code{0xbbaa}. Byte here always means
14614exactly 8 bits.
f25efe50 14615@enddefbuiltin
d77de738 14616
f25efe50 14617@defbuiltin{uint32_t __builtin_bswap32 (uint32_t x)}
d77de738
ML
14618Similar to @code{__builtin_bswap16}, except the argument and return types
14619are 32-bit.
f25efe50 14620@enddefbuiltin
d77de738 14621
f25efe50 14622@defbuiltin{uint64_t __builtin_bswap64 (uint64_t x)}
d77de738
ML
14623Similar to @code{__builtin_bswap32}, except the argument and return types
14624are 64-bit.
f25efe50 14625@enddefbuiltin
d77de738 14626
f25efe50 14627@defbuiltin{uint128_t __builtin_bswap128 (uint128_t x)}
d77de738
ML
14628Similar to @code{__builtin_bswap64}, except the argument and return types
14629are 128-bit. Only supported on targets when 128-bit types are supported.
f25efe50 14630@enddefbuiltin
d77de738
ML
14631
14632
f25efe50 14633@defbuiltin{Pmode __builtin_extend_pointer (void * x)}
d77de738
ML
14634On targets where the user visible pointer size is smaller than the size
14635of an actual hardware address this function returns the extended user
14636pointer. Targets where this is true included ILP32 mode on x86_64 or
14637Aarch64. This function is mainly useful when writing inline assembly
14638code.
f25efe50 14639@enddefbuiltin
d77de738 14640
f25efe50 14641@defbuiltin{int __builtin_goacc_parlevel_id (int x)}
d77de738
ML
14642Returns the openacc gang, worker or vector id depending on whether @var{x} is
146430, 1 or 2.
f25efe50 14644@enddefbuiltin
d77de738 14645
f25efe50 14646@defbuiltin{int __builtin_goacc_parlevel_size (int x)}
d77de738
ML
14647Returns the openacc gang, worker or vector size depending on whether @var{x} is
146480, 1 or 2.
f25efe50 14649@enddefbuiltin
d77de738
ML
14650
14651@node Target Builtins
14652@section Built-in Functions Specific to Particular Target Machines
14653
14654On some target machines, GCC supports many built-in functions specific
14655to those machines. Generally these generate calls to specific machine
14656instructions, but allow the compiler to schedule those calls.
14657
14658@menu
14659* AArch64 Built-in Functions::
14660* Alpha Built-in Functions::
14661* Altera Nios II Built-in Functions::
14662* ARC Built-in Functions::
14663* ARC SIMD Built-in Functions::
14664* ARM iWMMXt Built-in Functions::
14665* ARM C Language Extensions (ACLE)::
14666* ARM Floating Point Status and Control Intrinsics::
14667* ARM ARMv8-M Security Extensions::
14668* AVR Built-in Functions::
14669* Blackfin Built-in Functions::
14670* BPF Built-in Functions::
14671* FR-V Built-in Functions::
14672* MIPS DSP Built-in Functions::
14673* MIPS Paired-Single Support::
14674* MIPS Loongson Built-in Functions::
14675* MIPS SIMD Architecture (MSA) Support::
14676* Other MIPS Built-in Functions::
14677* MSP430 Built-in Functions::
14678* NDS32 Built-in Functions::
d77de738
ML
14679* Basic PowerPC Built-in Functions::
14680* PowerPC AltiVec/VSX Built-in Functions::
14681* PowerPC Hardware Transactional Memory Built-in Functions::
14682* PowerPC Atomic Memory Operation Functions::
14683* PowerPC Matrix-Multiply Assist Built-in Functions::
14684* PRU Built-in Functions::
14685* RISC-V Built-in Functions::
14686* RX Built-in Functions::
14687* S/390 System z Built-in Functions::
14688* SH Built-in Functions::
14689* SPARC VIS Built-in Functions::
14690* TI C6X Built-in Functions::
14691* x86 Built-in Functions::
14692* x86 transactional memory intrinsics::
14693* x86 control-flow protection intrinsics::
14694@end menu
14695
14696@node AArch64 Built-in Functions
14697@subsection AArch64 Built-in Functions
14698
14699These built-in functions are available for the AArch64 family of
14700processors.
14701@smallexample
14702unsigned int __builtin_aarch64_get_fpcr ();
14703void __builtin_aarch64_set_fpcr (unsigned int);
14704unsigned int __builtin_aarch64_get_fpsr ();
14705void __builtin_aarch64_set_fpsr (unsigned int);
14706
14707unsigned long long __builtin_aarch64_get_fpcr64 ();
14708void __builtin_aarch64_set_fpcr64 (unsigned long long);
14709unsigned long long __builtin_aarch64_get_fpsr64 ();
14710void __builtin_aarch64_set_fpsr64 (unsigned long long);
14711@end smallexample
14712
14713@node Alpha Built-in Functions
14714@subsection Alpha Built-in Functions
14715
14716These built-in functions are available for the Alpha family of
14717processors, depending on the command-line switches used.
14718
14719The following built-in functions are always available. They
14720all generate the machine instruction that is part of the name.
14721
14722@smallexample
14723long __builtin_alpha_implver (void);
14724long __builtin_alpha_rpcc (void);
14725long __builtin_alpha_amask (long);
14726long __builtin_alpha_cmpbge (long, long);
14727long __builtin_alpha_extbl (long, long);
14728long __builtin_alpha_extwl (long, long);
14729long __builtin_alpha_extll (long, long);
14730long __builtin_alpha_extql (long, long);
14731long __builtin_alpha_extwh (long, long);
14732long __builtin_alpha_extlh (long, long);
14733long __builtin_alpha_extqh (long, long);
14734long __builtin_alpha_insbl (long, long);
14735long __builtin_alpha_inswl (long, long);
14736long __builtin_alpha_insll (long, long);
14737long __builtin_alpha_insql (long, long);
14738long __builtin_alpha_inswh (long, long);
14739long __builtin_alpha_inslh (long, long);
14740long __builtin_alpha_insqh (long, long);
14741long __builtin_alpha_mskbl (long, long);
14742long __builtin_alpha_mskwl (long, long);
14743long __builtin_alpha_mskll (long, long);
14744long __builtin_alpha_mskql (long, long);
14745long __builtin_alpha_mskwh (long, long);
14746long __builtin_alpha_msklh (long, long);
14747long __builtin_alpha_mskqh (long, long);
14748long __builtin_alpha_umulh (long, long);
14749long __builtin_alpha_zap (long, long);
14750long __builtin_alpha_zapnot (long, long);
14751@end smallexample
14752
14753The following built-in functions are always with @option{-mmax}
14754or @option{-mcpu=@var{cpu}} where @var{cpu} is @code{pca56} or
14755later. They all generate the machine instruction that is part
14756of the name.
14757
14758@smallexample
14759long __builtin_alpha_pklb (long);
14760long __builtin_alpha_pkwb (long);
14761long __builtin_alpha_unpkbl (long);
14762long __builtin_alpha_unpkbw (long);
14763long __builtin_alpha_minub8 (long, long);
14764long __builtin_alpha_minsb8 (long, long);
14765long __builtin_alpha_minuw4 (long, long);
14766long __builtin_alpha_minsw4 (long, long);
14767long __builtin_alpha_maxub8 (long, long);
14768long __builtin_alpha_maxsb8 (long, long);
14769long __builtin_alpha_maxuw4 (long, long);
14770long __builtin_alpha_maxsw4 (long, long);
14771long __builtin_alpha_perr (long, long);
14772@end smallexample
14773
14774The following built-in functions are always with @option{-mcix}
14775or @option{-mcpu=@var{cpu}} where @var{cpu} is @code{ev67} or
14776later. They all generate the machine instruction that is part
14777of the name.
14778
14779@smallexample
14780long __builtin_alpha_cttz (long);
14781long __builtin_alpha_ctlz (long);
14782long __builtin_alpha_ctpop (long);
14783@end smallexample
14784
14785The following built-in functions are available on systems that use the OSF/1
14786PALcode. Normally they invoke the @code{rduniq} and @code{wruniq}
14787PAL calls, but when invoked with @option{-mtls-kernel}, they invoke
14788@code{rdval} and @code{wrval}.
14789
14790@smallexample
14791void *__builtin_thread_pointer (void);
14792void __builtin_set_thread_pointer (void *);
14793@end smallexample
14794
14795@node Altera Nios II Built-in Functions
14796@subsection Altera Nios II Built-in Functions
14797
14798These built-in functions are available for the Altera Nios II
14799family of processors.
14800
14801The following built-in functions are always available. They
14802all generate the machine instruction that is part of the name.
14803
14804@example
14805int __builtin_ldbio (volatile const void *);
14806int __builtin_ldbuio (volatile const void *);
14807int __builtin_ldhio (volatile const void *);
14808int __builtin_ldhuio (volatile const void *);
14809int __builtin_ldwio (volatile const void *);
14810void __builtin_stbio (volatile void *, int);
14811void __builtin_sthio (volatile void *, int);
14812void __builtin_stwio (volatile void *, int);
14813void __builtin_sync (void);
14814int __builtin_rdctl (int);
14815int __builtin_rdprs (int, int);
14816void __builtin_wrctl (int, int);
14817void __builtin_flushd (volatile void *);
14818void __builtin_flushda (volatile void *);
14819int __builtin_wrpie (int);
14820void __builtin_eni (int);
14821int __builtin_ldex (volatile const void *);
14822int __builtin_stex (volatile void *, int);
14823int __builtin_ldsex (volatile const void *);
14824int __builtin_stsex (volatile void *, int);
14825@end example
14826
14827The following built-in functions are always available. They
14828all generate a Nios II Custom Instruction. The name of the
14829function represents the types that the function takes and
14830returns. The letter before the @code{n} is the return type
14831or void if absent. The @code{n} represents the first parameter
14832to all the custom instructions, the custom instruction number.
14833The two letters after the @code{n} represent the up to two
14834parameters to the function.
14835
14836The letters represent the following data types:
14837@table @code
14838@item <no letter>
14839@code{void} for return type and no parameter for parameter types.
14840
14841@item i
14842@code{int} for return type and parameter type
14843
14844@item f
14845@code{float} for return type and parameter type
14846
14847@item p
14848@code{void *} for return type and parameter type
14849
14850@end table
14851
14852And the function names are:
14853@example
14854void __builtin_custom_n (void);
14855void __builtin_custom_ni (int);
14856void __builtin_custom_nf (float);
14857void __builtin_custom_np (void *);
14858void __builtin_custom_nii (int, int);
14859void __builtin_custom_nif (int, float);
14860void __builtin_custom_nip (int, void *);
14861void __builtin_custom_nfi (float, int);
14862void __builtin_custom_nff (float, float);
14863void __builtin_custom_nfp (float, void *);
14864void __builtin_custom_npi (void *, int);
14865void __builtin_custom_npf (void *, float);
14866void __builtin_custom_npp (void *, void *);
14867int __builtin_custom_in (void);
14868int __builtin_custom_ini (int);
14869int __builtin_custom_inf (float);
14870int __builtin_custom_inp (void *);
14871int __builtin_custom_inii (int, int);
14872int __builtin_custom_inif (int, float);
14873int __builtin_custom_inip (int, void *);
14874int __builtin_custom_infi (float, int);
14875int __builtin_custom_inff (float, float);
14876int __builtin_custom_infp (float, void *);
14877int __builtin_custom_inpi (void *, int);
14878int __builtin_custom_inpf (void *, float);
14879int __builtin_custom_inpp (void *, void *);
14880float __builtin_custom_fn (void);
14881float __builtin_custom_fni (int);
14882float __builtin_custom_fnf (float);
14883float __builtin_custom_fnp (void *);
14884float __builtin_custom_fnii (int, int);
14885float __builtin_custom_fnif (int, float);
14886float __builtin_custom_fnip (int, void *);
14887float __builtin_custom_fnfi (float, int);
14888float __builtin_custom_fnff (float, float);
14889float __builtin_custom_fnfp (float, void *);
14890float __builtin_custom_fnpi (void *, int);
14891float __builtin_custom_fnpf (void *, float);
14892float __builtin_custom_fnpp (void *, void *);
14893void * __builtin_custom_pn (void);
14894void * __builtin_custom_pni (int);
14895void * __builtin_custom_pnf (float);
14896void * __builtin_custom_pnp (void *);
14897void * __builtin_custom_pnii (int, int);
14898void * __builtin_custom_pnif (int, float);
14899void * __builtin_custom_pnip (int, void *);
14900void * __builtin_custom_pnfi (float, int);
14901void * __builtin_custom_pnff (float, float);
14902void * __builtin_custom_pnfp (float, void *);
14903void * __builtin_custom_pnpi (void *, int);
14904void * __builtin_custom_pnpf (void *, float);
14905void * __builtin_custom_pnpp (void *, void *);
14906@end example
14907
14908@node ARC Built-in Functions
14909@subsection ARC Built-in Functions
14910
14911The following built-in functions are provided for ARC targets. The
14912built-ins generate the corresponding assembly instructions. In the
14913examples given below, the generated code often requires an operand or
14914result to be in a register. Where necessary further code will be
14915generated to ensure this is true, but for brevity this is not
14916described in each case.
14917
14918@emph{Note:} Using a built-in to generate an instruction not supported
14919by a target may cause problems. At present the compiler is not
14920guaranteed to detect such misuse, and as a result an internal compiler
14921error may be generated.
14922
f25efe50 14923@defbuiltin{int __builtin_arc_aligned (void *@var{val}, int @var{alignval})}
d77de738
ML
14924Return 1 if @var{val} is known to have the byte alignment given
14925by @var{alignval}, otherwise return 0.
14926Note that this is different from
14927@smallexample
14928__alignof__(*(char *)@var{val}) >= alignval
14929@end smallexample
14930because __alignof__ sees only the type of the dereference, whereas
14931__builtin_arc_align uses alignment information from the pointer
14932as well as from the pointed-to type.
14933The information available will depend on optimization level.
f25efe50 14934@enddefbuiltin
d77de738 14935
f25efe50 14936@defbuiltin{void __builtin_arc_brk (void)}
d77de738
ML
14937Generates
14938@example
14939brk
14940@end example
f25efe50 14941@enddefbuiltin
d77de738 14942
f25efe50 14943@defbuiltin{{unsigned int} __builtin_arc_core_read (unsigned int @var{regno})}
d77de738
ML
14944The operand is the number of a register to be read. Generates:
14945@example
14946mov @var{dest}, r@var{regno}
14947@end example
14948where the value in @var{dest} will be the result returned from the
14949built-in.
f25efe50 14950@enddefbuiltin
d77de738 14951
f25efe50 14952@defbuiltin{void __builtin_arc_core_write (unsigned int @var{regno}, unsigned int @var{val})}
d77de738
ML
14953The first operand is the number of a register to be written, the
14954second operand is a compile time constant to write into that
14955register. Generates:
14956@example
14957mov r@var{regno}, @var{val}
14958@end example
f25efe50 14959@enddefbuiltin
d77de738 14960
f25efe50 14961@defbuiltin{int __builtin_arc_divaw (int @var{a}, int @var{b})}
d77de738
ML
14962Only available if either @option{-mcpu=ARC700} or @option{-meA} is set.
14963Generates:
14964@example
14965divaw @var{dest}, @var{a}, @var{b}
14966@end example
14967where the value in @var{dest} will be the result returned from the
14968built-in.
f25efe50 14969@enddefbuiltin
d77de738 14970
f25efe50 14971@defbuiltin{void __builtin_arc_flag (unsigned int @var{a})}
d77de738
ML
14972Generates
14973@example
14974flag @var{a}
14975@end example
f25efe50 14976@enddefbuiltin
d77de738 14977
f25efe50 14978@defbuiltin{{unsigned int} __builtin_arc_lr (unsigned int @var{auxr})}
d77de738
ML
14979The operand, @var{auxv}, is the address of an auxiliary register and
14980must be a compile time constant. Generates:
14981@example
14982lr @var{dest}, [@var{auxr}]
14983@end example
14984Where the value in @var{dest} will be the result returned from the
14985built-in.
f25efe50 14986@enddefbuiltin
d77de738 14987
f25efe50 14988@defbuiltin{void __builtin_arc_mul64 (int @var{a}, int @var{b})}
d77de738
ML
14989Only available with @option{-mmul64}. Generates:
14990@example
14991mul64 @var{a}, @var{b}
14992@end example
f25efe50 14993@enddefbuiltin
d77de738 14994
f25efe50 14995@defbuiltin{void __builtin_arc_mulu64 (unsigned int @var{a}, unsigned int @var{b})}
d77de738
ML
14996Only available with @option{-mmul64}. Generates:
14997@example
14998mulu64 @var{a}, @var{b}
14999@end example
f25efe50 15000@enddefbuiltin
d77de738 15001
f25efe50 15002@defbuiltin{void __builtin_arc_nop (void)}
d77de738
ML
15003Generates:
15004@example
15005nop
15006@end example
f25efe50 15007@enddefbuiltin
d77de738 15008
f25efe50 15009@defbuiltin{int __builtin_arc_norm (int @var{src})}
d77de738
ML
15010Only valid if the @samp{norm} instruction is available through the
15011@option{-mnorm} option or by default with @option{-mcpu=ARC700}.
15012Generates:
15013@example
15014norm @var{dest}, @var{src}
15015@end example
15016Where the value in @var{dest} will be the result returned from the
15017built-in.
f25efe50 15018@enddefbuiltin
d77de738 15019
f25efe50 15020@defbuiltin{{short int} __builtin_arc_normw (short int @var{src})}
d77de738
ML
15021Only valid if the @samp{normw} instruction is available through the
15022@option{-mnorm} option or by default with @option{-mcpu=ARC700}.
15023Generates:
15024@example
15025normw @var{dest}, @var{src}
15026@end example
15027Where the value in @var{dest} will be the result returned from the
15028built-in.
f25efe50 15029@enddefbuiltin
d77de738 15030
f25efe50 15031@defbuiltin{void __builtin_arc_rtie (void)}
d77de738
ML
15032Generates:
15033@example
15034rtie
15035@end example
f25efe50 15036@enddefbuiltin
d77de738 15037
f25efe50 15038@defbuiltin{void __builtin_arc_sleep (int @var{a}}
d77de738
ML
15039Generates:
15040@example
15041sleep @var{a}
15042@end example
f25efe50 15043@enddefbuiltin
d77de738 15044
f25efe50 15045@defbuiltin{void __builtin_arc_sr (unsigned int @var{val}, unsigned int @var{auxr})}
d77de738
ML
15046The first argument, @var{val}, is a compile time constant to be
15047written to the register, the second argument, @var{auxr}, is the
15048address of an auxiliary register. Generates:
15049@example
15050sr @var{val}, [@var{auxr}]
15051@end example
f25efe50 15052@enddefbuiltin
d77de738 15053
f25efe50 15054@defbuiltin{int __builtin_arc_swap (int @var{src})}
d77de738
ML
15055Only valid with @option{-mswap}. Generates:
15056@example
15057swap @var{dest}, @var{src}
15058@end example
15059Where the value in @var{dest} will be the result returned from the
15060built-in.
f25efe50 15061@enddefbuiltin
d77de738 15062
f25efe50 15063@defbuiltin{void __builtin_arc_swi (void)}
d77de738
ML
15064Generates:
15065@example
15066swi
15067@end example
f25efe50 15068@enddefbuiltin
d77de738 15069
f25efe50 15070@defbuiltin{void __builtin_arc_sync (void)}
d77de738
ML
15071Only available with @option{-mcpu=ARC700}. Generates:
15072@example
15073sync
15074@end example
f25efe50 15075@enddefbuiltin
d77de738 15076
f25efe50 15077@defbuiltin{void __builtin_arc_trap_s (unsigned int @var{c})}
d77de738
ML
15078Only available with @option{-mcpu=ARC700}. Generates:
15079@example
15080trap_s @var{c}
15081@end example
f25efe50 15082@enddefbuiltin
d77de738 15083
f25efe50 15084@defbuiltin{void __builtin_arc_unimp_s (void)}
d77de738
ML
15085Only available with @option{-mcpu=ARC700}. Generates:
15086@example
15087unimp_s
15088@end example
f25efe50 15089@enddefbuiltin
d77de738
ML
15090
15091The instructions generated by the following builtins are not
15092considered as candidates for scheduling. They are not moved around by
15093the compiler during scheduling, and thus can be expected to appear
15094where they are put in the C code:
15095@example
15096__builtin_arc_brk()
15097__builtin_arc_core_read()
15098__builtin_arc_core_write()
15099__builtin_arc_flag()
15100__builtin_arc_lr()
15101__builtin_arc_sleep()
15102__builtin_arc_sr()
15103__builtin_arc_swi()
15104@end example
15105
15106@node ARC SIMD Built-in Functions
15107@subsection ARC SIMD Built-in Functions
15108
15109SIMD builtins provided by the compiler can be used to generate the
15110vector instructions. This section describes the available builtins
15111and their usage in programs. With the @option{-msimd} option, the
15112compiler provides 128-bit vector types, which can be specified using
15113the @code{vector_size} attribute. The header file @file{arc-simd.h}
15114can be included to use the following predefined types:
15115@example
15116typedef int __v4si __attribute__((vector_size(16)));
15117typedef short __v8hi __attribute__((vector_size(16)));
15118@end example
15119
15120These types can be used to define 128-bit variables. The built-in
15121functions listed in the following section can be used on these
15122variables to generate the vector operations.
15123
15124For all builtins, @code{__builtin_arc_@var{someinsn}}, the header file
15125@file{arc-simd.h} also provides equivalent macros called
15126@code{_@var{someinsn}} that can be used for programming ease and
15127improved readability. The following macros for DMA control are also
15128provided:
15129@example
15130#define _setup_dma_in_channel_reg _vdiwr
15131#define _setup_dma_out_channel_reg _vdowr
15132@end example
15133
15134The following is a complete list of all the SIMD built-ins provided
15135for ARC, grouped by calling signature.
15136
15137The following take two @code{__v8hi} arguments and return a
15138@code{__v8hi} result:
15139@example
15140__v8hi __builtin_arc_vaddaw (__v8hi, __v8hi);
15141__v8hi __builtin_arc_vaddw (__v8hi, __v8hi);
15142__v8hi __builtin_arc_vand (__v8hi, __v8hi);
15143__v8hi __builtin_arc_vandaw (__v8hi, __v8hi);
15144__v8hi __builtin_arc_vavb (__v8hi, __v8hi);
15145__v8hi __builtin_arc_vavrb (__v8hi, __v8hi);
15146__v8hi __builtin_arc_vbic (__v8hi, __v8hi);
15147__v8hi __builtin_arc_vbicaw (__v8hi, __v8hi);
15148__v8hi __builtin_arc_vdifaw (__v8hi, __v8hi);
15149__v8hi __builtin_arc_vdifw (__v8hi, __v8hi);
15150__v8hi __builtin_arc_veqw (__v8hi, __v8hi);
15151__v8hi __builtin_arc_vh264f (__v8hi, __v8hi);
15152__v8hi __builtin_arc_vh264ft (__v8hi, __v8hi);
15153__v8hi __builtin_arc_vh264fw (__v8hi, __v8hi);
15154__v8hi __builtin_arc_vlew (__v8hi, __v8hi);
15155__v8hi __builtin_arc_vltw (__v8hi, __v8hi);
15156__v8hi __builtin_arc_vmaxaw (__v8hi, __v8hi);
15157__v8hi __builtin_arc_vmaxw (__v8hi, __v8hi);
15158__v8hi __builtin_arc_vminaw (__v8hi, __v8hi);
15159__v8hi __builtin_arc_vminw (__v8hi, __v8hi);
15160__v8hi __builtin_arc_vmr1aw (__v8hi, __v8hi);
15161__v8hi __builtin_arc_vmr1w (__v8hi, __v8hi);
15162__v8hi __builtin_arc_vmr2aw (__v8hi, __v8hi);
15163__v8hi __builtin_arc_vmr2w (__v8hi, __v8hi);
15164__v8hi __builtin_arc_vmr3aw (__v8hi, __v8hi);
15165__v8hi __builtin_arc_vmr3w (__v8hi, __v8hi);
15166__v8hi __builtin_arc_vmr4aw (__v8hi, __v8hi);
15167__v8hi __builtin_arc_vmr4w (__v8hi, __v8hi);
15168__v8hi __builtin_arc_vmr5aw (__v8hi, __v8hi);
15169__v8hi __builtin_arc_vmr5w (__v8hi, __v8hi);
15170__v8hi __builtin_arc_vmr6aw (__v8hi, __v8hi);
15171__v8hi __builtin_arc_vmr6w (__v8hi, __v8hi);
15172__v8hi __builtin_arc_vmr7aw (__v8hi, __v8hi);
15173__v8hi __builtin_arc_vmr7w (__v8hi, __v8hi);
15174__v8hi __builtin_arc_vmrb (__v8hi, __v8hi);
15175__v8hi __builtin_arc_vmulaw (__v8hi, __v8hi);
15176__v8hi __builtin_arc_vmulfaw (__v8hi, __v8hi);
15177__v8hi __builtin_arc_vmulfw (__v8hi, __v8hi);
15178__v8hi __builtin_arc_vmulw (__v8hi, __v8hi);
15179__v8hi __builtin_arc_vnew (__v8hi, __v8hi);
15180__v8hi __builtin_arc_vor (__v8hi, __v8hi);
15181__v8hi __builtin_arc_vsubaw (__v8hi, __v8hi);
15182__v8hi __builtin_arc_vsubw (__v8hi, __v8hi);
15183__v8hi __builtin_arc_vsummw (__v8hi, __v8hi);
15184__v8hi __builtin_arc_vvc1f (__v8hi, __v8hi);
15185__v8hi __builtin_arc_vvc1ft (__v8hi, __v8hi);
15186__v8hi __builtin_arc_vxor (__v8hi, __v8hi);
15187__v8hi __builtin_arc_vxoraw (__v8hi, __v8hi);
15188@end example
15189
15190The following take one @code{__v8hi} and one @code{int} argument and return a
15191@code{__v8hi} result:
15192
15193@example
15194__v8hi __builtin_arc_vbaddw (__v8hi, int);
15195__v8hi __builtin_arc_vbmaxw (__v8hi, int);
15196__v8hi __builtin_arc_vbminw (__v8hi, int);
15197__v8hi __builtin_arc_vbmulaw (__v8hi, int);
15198__v8hi __builtin_arc_vbmulfw (__v8hi, int);
15199__v8hi __builtin_arc_vbmulw (__v8hi, int);
15200__v8hi __builtin_arc_vbrsubw (__v8hi, int);
15201__v8hi __builtin_arc_vbsubw (__v8hi, int);
15202@end example
15203
15204The following take one @code{__v8hi} argument and one @code{int} argument which
15205must be a 3-bit compile time constant indicating a register number
15206I0-I7. They return a @code{__v8hi} result.
15207@example
15208__v8hi __builtin_arc_vasrw (__v8hi, const int);
15209__v8hi __builtin_arc_vsr8 (__v8hi, const int);
15210__v8hi __builtin_arc_vsr8aw (__v8hi, const int);
15211@end example
15212
15213The following take one @code{__v8hi} argument and one @code{int}
15214argument which must be a 6-bit compile time constant. They return a
15215@code{__v8hi} result.
15216@example
15217__v8hi __builtin_arc_vasrpwbi (__v8hi, const int);
15218__v8hi __builtin_arc_vasrrpwbi (__v8hi, const int);
15219__v8hi __builtin_arc_vasrrwi (__v8hi, const int);
15220__v8hi __builtin_arc_vasrsrwi (__v8hi, const int);
15221__v8hi __builtin_arc_vasrwi (__v8hi, const int);
15222__v8hi __builtin_arc_vsr8awi (__v8hi, const int);
15223__v8hi __builtin_arc_vsr8i (__v8hi, const int);
15224@end example
15225
15226The following take one @code{__v8hi} argument and one @code{int} argument which
15227must be a 8-bit compile time constant. They return a @code{__v8hi}
15228result.
15229@example
15230__v8hi __builtin_arc_vd6tapf (__v8hi, const int);
15231__v8hi __builtin_arc_vmvaw (__v8hi, const int);
15232__v8hi __builtin_arc_vmvw (__v8hi, const int);
15233__v8hi __builtin_arc_vmvzw (__v8hi, const int);
15234@end example
15235
15236The following take two @code{int} arguments, the second of which which
15237must be a 8-bit compile time constant. They return a @code{__v8hi}
15238result:
15239@example
15240__v8hi __builtin_arc_vmovaw (int, const int);
15241__v8hi __builtin_arc_vmovw (int, const int);
15242__v8hi __builtin_arc_vmovzw (int, const int);
15243@end example
15244
15245The following take a single @code{__v8hi} argument and return a
15246@code{__v8hi} result:
15247@example
15248__v8hi __builtin_arc_vabsaw (__v8hi);
15249__v8hi __builtin_arc_vabsw (__v8hi);
15250__v8hi __builtin_arc_vaddsuw (__v8hi);
15251__v8hi __builtin_arc_vexch1 (__v8hi);
15252__v8hi __builtin_arc_vexch2 (__v8hi);
15253__v8hi __builtin_arc_vexch4 (__v8hi);
15254__v8hi __builtin_arc_vsignw (__v8hi);
15255__v8hi __builtin_arc_vupbaw (__v8hi);
15256__v8hi __builtin_arc_vupbw (__v8hi);
15257__v8hi __builtin_arc_vupsbaw (__v8hi);
15258__v8hi __builtin_arc_vupsbw (__v8hi);
15259@end example
15260
15261The following take two @code{int} arguments and return no result:
15262@example
15263void __builtin_arc_vdirun (int, int);
15264void __builtin_arc_vdorun (int, int);
15265@end example
15266
15267The following take two @code{int} arguments and return no result. The
15268first argument must a 3-bit compile time constant indicating one of
15269the DR0-DR7 DMA setup channels:
15270@example
15271void __builtin_arc_vdiwr (const int, int);
15272void __builtin_arc_vdowr (const int, int);
15273@end example
15274
15275The following take an @code{int} argument and return no result:
15276@example
15277void __builtin_arc_vendrec (int);
15278void __builtin_arc_vrec (int);
15279void __builtin_arc_vrecrun (int);
15280void __builtin_arc_vrun (int);
15281@end example
15282
15283The following take a @code{__v8hi} argument and two @code{int}
15284arguments and return a @code{__v8hi} result. The second argument must
15285be a 3-bit compile time constants, indicating one the registers I0-I7,
15286and the third argument must be an 8-bit compile time constant.
15287
15288@emph{Note:} Although the equivalent hardware instructions do not take
15289an SIMD register as an operand, these builtins overwrite the relevant
15290bits of the @code{__v8hi} register provided as the first argument with
15291the value loaded from the @code{[Ib, u8]} location in the SDM.
15292
15293@example
15294__v8hi __builtin_arc_vld32 (__v8hi, const int, const int);
15295__v8hi __builtin_arc_vld32wh (__v8hi, const int, const int);
15296__v8hi __builtin_arc_vld32wl (__v8hi, const int, const int);
15297__v8hi __builtin_arc_vld64 (__v8hi, const int, const int);
15298@end example
15299
15300The following take two @code{int} arguments and return a @code{__v8hi}
15301result. The first argument must be a 3-bit compile time constants,
15302indicating one the registers I0-I7, and the second argument must be an
153038-bit compile time constant.
15304
15305@example
15306__v8hi __builtin_arc_vld128 (const int, const int);
15307__v8hi __builtin_arc_vld64w (const int, const int);
15308@end example
15309
15310The following take a @code{__v8hi} argument and two @code{int}
15311arguments and return no result. The second argument must be a 3-bit
15312compile time constants, indicating one the registers I0-I7, and the
15313third argument must be an 8-bit compile time constant.
15314
15315@example
15316void __builtin_arc_vst128 (__v8hi, const int, const int);
15317void __builtin_arc_vst64 (__v8hi, const int, const int);
15318@end example
15319
15320The following take a @code{__v8hi} argument and three @code{int}
15321arguments and return no result. The second argument must be a 3-bit
15322compile-time constant, identifying the 16-bit sub-register to be
15323stored, the third argument must be a 3-bit compile time constants,
15324indicating one the registers I0-I7, and the fourth argument must be an
153258-bit compile time constant.
15326
15327@example
15328void __builtin_arc_vst16_n (__v8hi, const int, const int, const int);
15329void __builtin_arc_vst32_n (__v8hi, const int, const int, const int);
15330@end example
15331
15332@node ARM iWMMXt Built-in Functions
15333@subsection ARM iWMMXt Built-in Functions
15334
15335These built-in functions are available for the ARM family of
15336processors when the @option{-mcpu=iwmmxt} switch is used:
15337
15338@smallexample
15339typedef int v2si __attribute__ ((vector_size (8)));
15340typedef short v4hi __attribute__ ((vector_size (8)));
15341typedef char v8qi __attribute__ ((vector_size (8)));
15342
15343int __builtin_arm_getwcgr0 (void);
15344void __builtin_arm_setwcgr0 (int);
15345int __builtin_arm_getwcgr1 (void);
15346void __builtin_arm_setwcgr1 (int);
15347int __builtin_arm_getwcgr2 (void);
15348void __builtin_arm_setwcgr2 (int);
15349int __builtin_arm_getwcgr3 (void);
15350void __builtin_arm_setwcgr3 (int);
15351int __builtin_arm_textrmsb (v8qi, int);
15352int __builtin_arm_textrmsh (v4hi, int);
15353int __builtin_arm_textrmsw (v2si, int);
15354int __builtin_arm_textrmub (v8qi, int);
15355int __builtin_arm_textrmuh (v4hi, int);
15356int __builtin_arm_textrmuw (v2si, int);
15357v8qi __builtin_arm_tinsrb (v8qi, int, int);
15358v4hi __builtin_arm_tinsrh (v4hi, int, int);
15359v2si __builtin_arm_tinsrw (v2si, int, int);
15360long long __builtin_arm_tmia (long long, int, int);
15361long long __builtin_arm_tmiabb (long long, int, int);
15362long long __builtin_arm_tmiabt (long long, int, int);
15363long long __builtin_arm_tmiaph (long long, int, int);
15364long long __builtin_arm_tmiatb (long long, int, int);
15365long long __builtin_arm_tmiatt (long long, int, int);
15366int __builtin_arm_tmovmskb (v8qi);
15367int __builtin_arm_tmovmskh (v4hi);
15368int __builtin_arm_tmovmskw (v2si);
15369long long __builtin_arm_waccb (v8qi);
15370long long __builtin_arm_wacch (v4hi);
15371long long __builtin_arm_waccw (v2si);
15372v8qi __builtin_arm_waddb (v8qi, v8qi);
15373v8qi __builtin_arm_waddbss (v8qi, v8qi);
15374v8qi __builtin_arm_waddbus (v8qi, v8qi);
15375v4hi __builtin_arm_waddh (v4hi, v4hi);
15376v4hi __builtin_arm_waddhss (v4hi, v4hi);
15377v4hi __builtin_arm_waddhus (v4hi, v4hi);
15378v2si __builtin_arm_waddw (v2si, v2si);
15379v2si __builtin_arm_waddwss (v2si, v2si);
15380v2si __builtin_arm_waddwus (v2si, v2si);
15381v8qi __builtin_arm_walign (v8qi, v8qi, int);
15382long long __builtin_arm_wand(long long, long long);
15383long long __builtin_arm_wandn (long long, long long);
15384v8qi __builtin_arm_wavg2b (v8qi, v8qi);
15385v8qi __builtin_arm_wavg2br (v8qi, v8qi);
15386v4hi __builtin_arm_wavg2h (v4hi, v4hi);
15387v4hi __builtin_arm_wavg2hr (v4hi, v4hi);
15388v8qi __builtin_arm_wcmpeqb (v8qi, v8qi);
15389v4hi __builtin_arm_wcmpeqh (v4hi, v4hi);
15390v2si __builtin_arm_wcmpeqw (v2si, v2si);
15391v8qi __builtin_arm_wcmpgtsb (v8qi, v8qi);
15392v4hi __builtin_arm_wcmpgtsh (v4hi, v4hi);
15393v2si __builtin_arm_wcmpgtsw (v2si, v2si);
15394v8qi __builtin_arm_wcmpgtub (v8qi, v8qi);
15395v4hi __builtin_arm_wcmpgtuh (v4hi, v4hi);
15396v2si __builtin_arm_wcmpgtuw (v2si, v2si);
15397long long __builtin_arm_wmacs (long long, v4hi, v4hi);
15398long long __builtin_arm_wmacsz (v4hi, v4hi);
15399long long __builtin_arm_wmacu (long long, v4hi, v4hi);
15400long long __builtin_arm_wmacuz (v4hi, v4hi);
15401v4hi __builtin_arm_wmadds (v4hi, v4hi);
15402v4hi __builtin_arm_wmaddu (v4hi, v4hi);
15403v8qi __builtin_arm_wmaxsb (v8qi, v8qi);
15404v4hi __builtin_arm_wmaxsh (v4hi, v4hi);
15405v2si __builtin_arm_wmaxsw (v2si, v2si);
15406v8qi __builtin_arm_wmaxub (v8qi, v8qi);
15407v4hi __builtin_arm_wmaxuh (v4hi, v4hi);
15408v2si __builtin_arm_wmaxuw (v2si, v2si);
15409v8qi __builtin_arm_wminsb (v8qi, v8qi);
15410v4hi __builtin_arm_wminsh (v4hi, v4hi);
15411v2si __builtin_arm_wminsw (v2si, v2si);
15412v8qi __builtin_arm_wminub (v8qi, v8qi);
15413v4hi __builtin_arm_wminuh (v4hi, v4hi);
15414v2si __builtin_arm_wminuw (v2si, v2si);
15415v4hi __builtin_arm_wmulsm (v4hi, v4hi);
15416v4hi __builtin_arm_wmulul (v4hi, v4hi);
15417v4hi __builtin_arm_wmulum (v4hi, v4hi);
15418long long __builtin_arm_wor (long long, long long);
15419v2si __builtin_arm_wpackdss (long long, long long);
15420v2si __builtin_arm_wpackdus (long long, long long);
15421v8qi __builtin_arm_wpackhss (v4hi, v4hi);
15422v8qi __builtin_arm_wpackhus (v4hi, v4hi);
15423v4hi __builtin_arm_wpackwss (v2si, v2si);
15424v4hi __builtin_arm_wpackwus (v2si, v2si);
15425long long __builtin_arm_wrord (long long, long long);
15426long long __builtin_arm_wrordi (long long, int);
15427v4hi __builtin_arm_wrorh (v4hi, long long);
15428v4hi __builtin_arm_wrorhi (v4hi, int);
15429v2si __builtin_arm_wrorw (v2si, long long);
15430v2si __builtin_arm_wrorwi (v2si, int);
15431v2si __builtin_arm_wsadb (v2si, v8qi, v8qi);
15432v2si __builtin_arm_wsadbz (v8qi, v8qi);
15433v2si __builtin_arm_wsadh (v2si, v4hi, v4hi);
15434v2si __builtin_arm_wsadhz (v4hi, v4hi);
15435v4hi __builtin_arm_wshufh (v4hi, int);
15436long long __builtin_arm_wslld (long long, long long);
15437long long __builtin_arm_wslldi (long long, int);
15438v4hi __builtin_arm_wsllh (v4hi, long long);
15439v4hi __builtin_arm_wsllhi (v4hi, int);
15440v2si __builtin_arm_wsllw (v2si, long long);
15441v2si __builtin_arm_wsllwi (v2si, int);
15442long long __builtin_arm_wsrad (long long, long long);
15443long long __builtin_arm_wsradi (long long, int);
15444v4hi __builtin_arm_wsrah (v4hi, long long);
15445v4hi __builtin_arm_wsrahi (v4hi, int);
15446v2si __builtin_arm_wsraw (v2si, long long);
15447v2si __builtin_arm_wsrawi (v2si, int);
15448long long __builtin_arm_wsrld (long long, long long);
15449long long __builtin_arm_wsrldi (long long, int);
15450v4hi __builtin_arm_wsrlh (v4hi, long long);
15451v4hi __builtin_arm_wsrlhi (v4hi, int);
15452v2si __builtin_arm_wsrlw (v2si, long long);
15453v2si __builtin_arm_wsrlwi (v2si, int);
15454v8qi __builtin_arm_wsubb (v8qi, v8qi);
15455v8qi __builtin_arm_wsubbss (v8qi, v8qi);
15456v8qi __builtin_arm_wsubbus (v8qi, v8qi);
15457v4hi __builtin_arm_wsubh (v4hi, v4hi);
15458v4hi __builtin_arm_wsubhss (v4hi, v4hi);
15459v4hi __builtin_arm_wsubhus (v4hi, v4hi);
15460v2si __builtin_arm_wsubw (v2si, v2si);
15461v2si __builtin_arm_wsubwss (v2si, v2si);
15462v2si __builtin_arm_wsubwus (v2si, v2si);
15463v4hi __builtin_arm_wunpckehsb (v8qi);
15464v2si __builtin_arm_wunpckehsh (v4hi);
15465long long __builtin_arm_wunpckehsw (v2si);
15466v4hi __builtin_arm_wunpckehub (v8qi);
15467v2si __builtin_arm_wunpckehuh (v4hi);
15468long long __builtin_arm_wunpckehuw (v2si);
15469v4hi __builtin_arm_wunpckelsb (v8qi);
15470v2si __builtin_arm_wunpckelsh (v4hi);
15471long long __builtin_arm_wunpckelsw (v2si);
15472v4hi __builtin_arm_wunpckelub (v8qi);
15473v2si __builtin_arm_wunpckeluh (v4hi);
15474long long __builtin_arm_wunpckeluw (v2si);
15475v8qi __builtin_arm_wunpckihb (v8qi, v8qi);
15476v4hi __builtin_arm_wunpckihh (v4hi, v4hi);
15477v2si __builtin_arm_wunpckihw (v2si, v2si);
15478v8qi __builtin_arm_wunpckilb (v8qi, v8qi);
15479v4hi __builtin_arm_wunpckilh (v4hi, v4hi);
15480v2si __builtin_arm_wunpckilw (v2si, v2si);
15481long long __builtin_arm_wxor (long long, long long);
15482long long __builtin_arm_wzero ();
15483@end smallexample
15484
15485
15486@node ARM C Language Extensions (ACLE)
15487@subsection ARM C Language Extensions (ACLE)
15488
15489GCC implements extensions for C as described in the ARM C Language
15490Extensions (ACLE) specification, which can be found at
15491@uref{https://developer.arm.com/documentation/ihi0053/latest/}.
15492
15493As a part of ACLE, GCC implements extensions for Advanced SIMD as described in
15494the ARM C Language Extensions Specification. The complete list of Advanced SIMD
15495intrinsics can be found at
15496@uref{https://developer.arm.com/documentation/ihi0073/latest/}.
15497The built-in intrinsics for the Advanced SIMD extension are available when
15498NEON is enabled.
15499
15500Currently, ARM and AArch64 back ends do not support ACLE 2.0 fully. Both
15501back ends support CRC32 intrinsics and the ARM back end supports the
15502Coprocessor intrinsics, all from @file{arm_acle.h}. The ARM back end's 16-bit
15503floating-point Advanced SIMD intrinsics currently comply to ACLE v1.1.
15504AArch64's back end does not have support for 16-bit floating point Advanced SIMD
15505intrinsics yet.
15506
15507See @ref{ARM Options} and @ref{AArch64 Options} for more information on the
15508availability of extensions.
15509
15510@node ARM Floating Point Status and Control Intrinsics
15511@subsection ARM Floating Point Status and Control Intrinsics
15512
15513These built-in functions are available for the ARM family of
15514processors with floating-point unit.
15515
15516@smallexample
15517unsigned int __builtin_arm_get_fpscr ();
15518void __builtin_arm_set_fpscr (unsigned int);
15519@end smallexample
15520
15521@node ARM ARMv8-M Security Extensions
15522@subsection ARM ARMv8-M Security Extensions
15523
15524GCC implements the ARMv8-M Security Extensions as described in the ARMv8-M
15525Security Extensions: Requirements on Development Tools Engineering
15526Specification, which can be found at
15527@uref{https://developer.arm.com/documentation/ecm0359818/latest/}.
15528
15529As part of the Security Extensions GCC implements two new function attributes:
15530@code{cmse_nonsecure_entry} and @code{cmse_nonsecure_call}.
15531
15532As part of the Security Extensions GCC implements the intrinsics below. FPTR
15533is used here to mean any function pointer type.
15534
15535@smallexample
15536cmse_address_info_t cmse_TT (void *);
15537cmse_address_info_t cmse_TT_fptr (FPTR);
15538cmse_address_info_t cmse_TTT (void *);
15539cmse_address_info_t cmse_TTT_fptr (FPTR);
15540cmse_address_info_t cmse_TTA (void *);
15541cmse_address_info_t cmse_TTA_fptr (FPTR);
15542cmse_address_info_t cmse_TTAT (void *);
15543cmse_address_info_t cmse_TTAT_fptr (FPTR);
15544void * cmse_check_address_range (void *, size_t, int);
15545typeof(p) cmse_nsfptr_create (FPTR p);
15546intptr_t cmse_is_nsfptr (FPTR);
15547int cmse_nonsecure_caller (void);
15548@end smallexample
15549
15550@node AVR Built-in Functions
15551@subsection AVR Built-in Functions
15552
15553For each built-in function for AVR, there is an equally named,
15554uppercase built-in macro defined. That way users can easily query if
15555or if not a specific built-in is implemented or not. For example, if
15556@code{__builtin_avr_nop} is available the macro
15557@code{__BUILTIN_AVR_NOP} is defined to @code{1} and undefined otherwise.
15558
15559@table @code
15560
15561@item void __builtin_avr_nop (void)
15562@itemx void __builtin_avr_sei (void)
15563@itemx void __builtin_avr_cli (void)
15564@itemx void __builtin_avr_sleep (void)
15565@itemx void __builtin_avr_wdr (void)
15566@itemx unsigned char __builtin_avr_swap (unsigned char)
15567@itemx unsigned int __builtin_avr_fmul (unsigned char, unsigned char)
15568@itemx int __builtin_avr_fmuls (char, char)
15569@itemx int __builtin_avr_fmulsu (char, unsigned char)
15570These built-in functions map to the respective machine
15571instruction, i.e.@: @code{nop}, @code{sei}, @code{cli}, @code{sleep},
15572@code{wdr}, @code{swap}, @code{fmul}, @code{fmuls}
15573resp. @code{fmulsu}. The three @code{fmul*} built-ins are implemented
15574as library call if no hardware multiplier is available.
15575
15576@item void __builtin_avr_delay_cycles (unsigned long ticks)
15577Delay execution for @var{ticks} cycles. Note that this
15578built-in does not take into account the effect of interrupts that
15579might increase delay time. @var{ticks} must be a compile-time
15580integer constant; delays with a variable number of cycles are not supported.
15581
15582@item char __builtin_avr_flash_segment (const __memx void*)
15583This built-in takes a byte address to the 24-bit
15584@ref{AVR Named Address Spaces,address space} @code{__memx} and returns
15585the number of the flash segment (the 64 KiB chunk) where the address
15586points to. Counting starts at @code{0}.
15587If the address does not point to flash memory, return @code{-1}.
15588
15589@item uint8_t __builtin_avr_insert_bits (uint32_t map, uint8_t bits, uint8_t val)
15590Insert bits from @var{bits} into @var{val} and return the resulting
15591value. The nibbles of @var{map} determine how the insertion is
15592performed: Let @var{X} be the @var{n}-th nibble of @var{map}
15593@enumerate
15594@item If @var{X} is @code{0xf},
15595then the @var{n}-th bit of @var{val} is returned unaltered.
15596
15597@item If X is in the range 0@dots{}7,
15598then the @var{n}-th result bit is set to the @var{X}-th bit of @var{bits}
15599
15600@item If X is in the range 8@dots{}@code{0xe},
15601then the @var{n}-th result bit is undefined.
15602@end enumerate
15603
15604@noindent
15605One typical use case for this built-in is adjusting input and
15606output values to non-contiguous port layouts. Some examples:
15607
15608@smallexample
15609// same as val, bits is unused
15610__builtin_avr_insert_bits (0xffffffff, bits, val);
15611@end smallexample
15612
15613@smallexample
15614// same as bits, val is unused
15615__builtin_avr_insert_bits (0x76543210, bits, val);
15616@end smallexample
15617
15618@smallexample
15619// same as rotating bits by 4
15620__builtin_avr_insert_bits (0x32107654, bits, 0);
15621@end smallexample
15622
15623@smallexample
15624// high nibble of result is the high nibble of val
15625// low nibble of result is the low nibble of bits
15626__builtin_avr_insert_bits (0xffff3210, bits, val);
15627@end smallexample
15628
15629@smallexample
15630// reverse the bit order of bits
15631__builtin_avr_insert_bits (0x01234567, bits, 0);
15632@end smallexample
15633
15634@item void __builtin_avr_nops (unsigned count)
15635Insert @var{count} @code{NOP} instructions.
15636The number of instructions must be a compile-time integer constant.
15637
15638@end table
15639
15640@noindent
15641There are many more AVR-specific built-in functions that are used to
15642implement the ISO/IEC TR 18037 ``Embedded C'' fixed-point functions of
15643section 7.18a.6. You don't need to use these built-ins directly.
15644Instead, use the declarations as supplied by the @code{stdfix.h} header
15645with GNU-C99:
15646
15647@smallexample
15648#include <stdfix.h>
15649
15650// Re-interpret the bit representation of unsigned 16-bit
15651// integer @var{uval} as Q-format 0.16 value.
15652unsigned fract get_bits (uint_ur_t uval)
15653@{
15654 return urbits (uval);
15655@}
15656@end smallexample
15657
15658@node Blackfin Built-in Functions
15659@subsection Blackfin Built-in Functions
15660
15661Currently, there are two Blackfin-specific built-in functions. These are
15662used for generating @code{CSYNC} and @code{SSYNC} machine insns without
15663using inline assembly; by using these built-in functions the compiler can
15664automatically add workarounds for hardware errata involving these
15665instructions. These functions are named as follows:
15666
15667@smallexample
15668void __builtin_bfin_csync (void);
15669void __builtin_bfin_ssync (void);
15670@end smallexample
15671
15672@node BPF Built-in Functions
15673@subsection BPF Built-in Functions
15674
15675The following built-in functions are available for eBPF targets.
15676
f25efe50 15677@defbuiltin{{unsigned long long} __builtin_bpf_load_byte (unsigned long long @var{offset})}
d77de738 15678Load a byte from the @code{struct sk_buff} packet data pointed by the register @code{%r6} and return it.
f25efe50 15679@enddefbuiltin
d77de738 15680
f25efe50 15681@defbuiltin{{unsigned long long} __builtin_bpf_load_half (unsigned long long @var{offset})}
7ffbc74c 15682Load 16 bits from the @code{struct sk_buff} packet data pointed by the register @code{%r6} and return it.
f25efe50 15683@enddefbuiltin
d77de738 15684
f25efe50 15685@defbuiltin{{unsigned long long} __builtin_bpf_load_word (unsigned long long @var{offset})}
7ffbc74c 15686Load 32 bits from the @code{struct sk_buff} packet data pointed by the register @code{%r6} and return it.
f25efe50 15687@enddefbuiltin
d77de738 15688
f25efe50 15689@defbuiltin{{void *} __builtin_preserve_access_index (@var{expr})}
d77de738 15690BPF Compile Once-Run Everywhere (CO-RE) support. Instruct GCC to generate CO-RE relocation records for any accesses to aggregate data structures (struct, union, array types) in @var{expr}. This builtin is otherwise transparent, the return value is whatever @var{expr} evaluates to. It is also overloaded: @var{expr} may be of any type (not necessarily a pointer), the return type is the same. Has no effect if @code{-mco-re} is not in effect (either specified or implied).
f25efe50 15691@enddefbuiltin
d77de738 15692
f25efe50 15693@defbuiltin{{unsigned int} __builtin_preserve_field_info (@var{expr}, unsigned int @var{kind})}
d77de738
ML
15694BPF Compile Once-Run Everywhere (CO-RE) support. This builtin is used to
15695extract information to aid in struct/union relocations. @var{expr} is
15696an access to a field of a struct or union. Depending on @var{kind}, different
15697information is returned to the program. A CO-RE relocation for the access in
15698@var{expr} with kind @var{kind} is recorded if @code{-mco-re} is in effect.
15699
15700The following values are supported for @var{kind}:
7ffbc74c 15701@table @code
d77de738
ML
15702@item FIELD_BYTE_OFFSET = 0
15703The returned value is the offset, in bytes, of the field from the
7ffbc74c 15704beginning of the containing structure. For bit-fields, this is the byte offset
d77de738
ML
15705of the containing word.
15706
15707@item FIELD_BYTE_SIZE = 1
7ffbc74c
SL
15708The returned value is the size, in bytes, of the field. For bit-fields,
15709this is the size in bytes of the containing word.
d77de738
ML
15710
15711@item FIELD_EXISTENCE = 2
15712The returned value is 1 if the field exists, 0 otherwise. Always 1 at
15713compile time.
15714
15715@item FIELD_SIGNEDNESS = 3
15716The returned value is 1 if the field is signed, 0 otherwise.
15717
15718@item FIELD_LSHIFT_U64 = 4
15719@itemx FIELD_RSHIFT_U64 = 5
15720The returned value is the number of bits of left- or right-shifting
7ffbc74c
SL
15721(respectively) needed in order to recover the original value of the field,
15722after it has been loaded by a read of @code{FIELD_BYTE_SIZE} bytes into an
15723unsigned 64-bit value. Primarily useful for reading bit-field values
15724from structures that may change between kernel versions.
d77de738
ML
15725
15726@end table
15727
15728Note that the return value is a constant which is known at
7ffbc74c
SL
15729compile time. If the field has a variable offset then
15730@code{FIELD_BYTE_OFFSET}, @code{FIELD_LSHIFT_U64},
15731and @code{FIELD_RSHIFT_U64} are not supported.
15732Similarly, if the field has a variable size then
15733@code{FIELD_BYTE_SIZE}, @code{FIELD_LSHIFT_U64},
15734and @code{FIELD_RSHIFT_U64} are not supported.
15735
15736For example, @code{__builtin_preserve_field_info} can be used to reliably
15737extract bit-field values from a structure that may change between
d77de738
ML
15738kernel versions:
15739
7ffbc74c 15740@smallexample
d77de738
ML
15741struct S
15742@{
15743 short a;
15744 int x:7;
15745 int y:5;
15746@};
15747
15748int
15749read_y (struct S *arg)
15750@{
15751 unsigned long long val;
7ffbc74c
SL
15752 unsigned int offset
15753 = __builtin_preserve_field_info (arg->y, FIELD_BYTE_OFFSET);
15754 unsigned int size
15755 = __builtin_preserve_field_info (arg->y, FIELD_BYTE_SIZE);
d77de738
ML
15756
15757 /* Read size bytes from arg + offset into val. */
15758 bpf_probe_read (&val, size, arg + offset);
15759
15760 val <<= __builtin_preserve_field_info (arg->y, FIELD_LSHIFT_U64);
15761
15762 if (__builtin_preserve_field_info (arg->y, FIELD_SIGNEDNESS))
7ffbc74c
SL
15763 val = ((long long) val
15764 >> __builtin_preserve_field_info (arg->y, FIELD_RSHIFT_U64));
d77de738
ML
15765 else
15766 val >>= __builtin_preserve_field_info (arg->y, FIELD_RSHIFT_U64);
15767
15768 return val;
15769@}
15770
7ffbc74c 15771@end smallexample
f25efe50 15772@enddefbuiltin
d77de738
ML
15773
15774@node FR-V Built-in Functions
15775@subsection FR-V Built-in Functions
15776
15777GCC provides many FR-V-specific built-in functions. In general,
15778these functions are intended to be compatible with those described
15779by @cite{FR-V Family, Softune C/C++ Compiler Manual (V6), Fujitsu
15780Semiconductor}. The two exceptions are @code{__MDUNPACKH} and
15781@code{__MBTOHE}, the GCC forms of which pass 128-bit values by
15782pointer rather than by value.
15783
15784Most of the functions are named after specific FR-V instructions.
15785Such functions are said to be ``directly mapped'' and are summarized
15786here in tabular form.
15787
15788@menu
15789* Argument Types::
15790* Directly-mapped Integer Functions::
15791* Directly-mapped Media Functions::
15792* Raw read/write Functions::
15793* Other Built-in Functions::
15794@end menu
15795
15796@node Argument Types
15797@subsubsection Argument Types
15798
15799The arguments to the built-in functions can be divided into three groups:
15800register numbers, compile-time constants and run-time values. In order
15801to make this classification clear at a glance, the arguments and return
15802values are given the following pseudo types:
15803
15804@multitable @columnfractions .20 .30 .15 .35
15805@headitem Pseudo type @tab Real C type @tab Constant? @tab Description
15806@item @code{uh} @tab @code{unsigned short} @tab No @tab an unsigned halfword
15807@item @code{uw1} @tab @code{unsigned int} @tab No @tab an unsigned word
15808@item @code{sw1} @tab @code{int} @tab No @tab a signed word
15809@item @code{uw2} @tab @code{unsigned long long} @tab No
15810@tab an unsigned doubleword
15811@item @code{sw2} @tab @code{long long} @tab No @tab a signed doubleword
15812@item @code{const} @tab @code{int} @tab Yes @tab an integer constant
15813@item @code{acc} @tab @code{int} @tab Yes @tab an ACC register number
15814@item @code{iacc} @tab @code{int} @tab Yes @tab an IACC register number
15815@end multitable
15816
15817These pseudo types are not defined by GCC, they are simply a notational
15818convenience used in this manual.
15819
15820Arguments of type @code{uh}, @code{uw1}, @code{sw1}, @code{uw2}
15821and @code{sw2} are evaluated at run time. They correspond to
15822register operands in the underlying FR-V instructions.
15823
15824@code{const} arguments represent immediate operands in the underlying
15825FR-V instructions. They must be compile-time constants.
15826
15827@code{acc} arguments are evaluated at compile time and specify the number
15828of an accumulator register. For example, an @code{acc} argument of 2
15829selects the ACC2 register.
15830
15831@code{iacc} arguments are similar to @code{acc} arguments but specify the
15832number of an IACC register. See @pxref{Other Built-in Functions}
15833for more details.
15834
15835@node Directly-mapped Integer Functions
15836@subsubsection Directly-Mapped Integer Functions
15837
15838The functions listed below map directly to FR-V I-type instructions.
15839
15840@multitable @columnfractions .45 .32 .23
15841@headitem Function prototype @tab Example usage @tab Assembly output
15842@item @code{sw1 __ADDSS (sw1, sw1)}
15843@tab @code{@var{c} = __ADDSS (@var{a}, @var{b})}
15844@tab @code{ADDSS @var{a},@var{b},@var{c}}
15845@item @code{sw1 __SCAN (sw1, sw1)}
15846@tab @code{@var{c} = __SCAN (@var{a}, @var{b})}
15847@tab @code{SCAN @var{a},@var{b},@var{c}}
15848@item @code{sw1 __SCUTSS (sw1)}
15849@tab @code{@var{b} = __SCUTSS (@var{a})}
15850@tab @code{SCUTSS @var{a},@var{b}}
15851@item @code{sw1 __SLASS (sw1, sw1)}
15852@tab @code{@var{c} = __SLASS (@var{a}, @var{b})}
15853@tab @code{SLASS @var{a},@var{b},@var{c}}
15854@item @code{void __SMASS (sw1, sw1)}
15855@tab @code{__SMASS (@var{a}, @var{b})}
15856@tab @code{SMASS @var{a},@var{b}}
15857@item @code{void __SMSSS (sw1, sw1)}
15858@tab @code{__SMSSS (@var{a}, @var{b})}
15859@tab @code{SMSSS @var{a},@var{b}}
15860@item @code{void __SMU (sw1, sw1)}
15861@tab @code{__SMU (@var{a}, @var{b})}
15862@tab @code{SMU @var{a},@var{b}}
15863@item @code{sw2 __SMUL (sw1, sw1)}
15864@tab @code{@var{c} = __SMUL (@var{a}, @var{b})}
15865@tab @code{SMUL @var{a},@var{b},@var{c}}
15866@item @code{sw1 __SUBSS (sw1, sw1)}
15867@tab @code{@var{c} = __SUBSS (@var{a}, @var{b})}
15868@tab @code{SUBSS @var{a},@var{b},@var{c}}
15869@item @code{uw2 __UMUL (uw1, uw1)}
15870@tab @code{@var{c} = __UMUL (@var{a}, @var{b})}
15871@tab @code{UMUL @var{a},@var{b},@var{c}}
15872@end multitable
15873
15874@node Directly-mapped Media Functions
15875@subsubsection Directly-Mapped Media Functions
15876
15877The functions listed below map directly to FR-V M-type instructions.
15878
15879@multitable @columnfractions .45 .32 .23
15880@headitem Function prototype @tab Example usage @tab Assembly output
15881@item @code{uw1 __MABSHS (sw1)}
15882@tab @code{@var{b} = __MABSHS (@var{a})}
15883@tab @code{MABSHS @var{a},@var{b}}
15884@item @code{void __MADDACCS (acc, acc)}
15885@tab @code{__MADDACCS (@var{b}, @var{a})}
15886@tab @code{MADDACCS @var{a},@var{b}}
15887@item @code{sw1 __MADDHSS (sw1, sw1)}
15888@tab @code{@var{c} = __MADDHSS (@var{a}, @var{b})}
15889@tab @code{MADDHSS @var{a},@var{b},@var{c}}
15890@item @code{uw1 __MADDHUS (uw1, uw1)}
15891@tab @code{@var{c} = __MADDHUS (@var{a}, @var{b})}
15892@tab @code{MADDHUS @var{a},@var{b},@var{c}}
15893@item @code{uw1 __MAND (uw1, uw1)}
15894@tab @code{@var{c} = __MAND (@var{a}, @var{b})}
15895@tab @code{MAND @var{a},@var{b},@var{c}}
15896@item @code{void __MASACCS (acc, acc)}
15897@tab @code{__MASACCS (@var{b}, @var{a})}
15898@tab @code{MASACCS @var{a},@var{b}}
15899@item @code{uw1 __MAVEH (uw1, uw1)}
15900@tab @code{@var{c} = __MAVEH (@var{a}, @var{b})}
15901@tab @code{MAVEH @var{a},@var{b},@var{c}}
15902@item @code{uw2 __MBTOH (uw1)}
15903@tab @code{@var{b} = __MBTOH (@var{a})}
15904@tab @code{MBTOH @var{a},@var{b}}
15905@item @code{void __MBTOHE (uw1 *, uw1)}
15906@tab @code{__MBTOHE (&@var{b}, @var{a})}
15907@tab @code{MBTOHE @var{a},@var{b}}
15908@item @code{void __MCLRACC (acc)}
15909@tab @code{__MCLRACC (@var{a})}
15910@tab @code{MCLRACC @var{a}}
15911@item @code{void __MCLRACCA (void)}
15912@tab @code{__MCLRACCA ()}
15913@tab @code{MCLRACCA}
15914@item @code{uw1 __Mcop1 (uw1, uw1)}
15915@tab @code{@var{c} = __Mcop1 (@var{a}, @var{b})}
15916@tab @code{Mcop1 @var{a},@var{b},@var{c}}
15917@item @code{uw1 __Mcop2 (uw1, uw1)}
15918@tab @code{@var{c} = __Mcop2 (@var{a}, @var{b})}
15919@tab @code{Mcop2 @var{a},@var{b},@var{c}}
15920@item @code{uw1 __MCPLHI (uw2, const)}
15921@tab @code{@var{c} = __MCPLHI (@var{a}, @var{b})}
15922@tab @code{MCPLHI @var{a},#@var{b},@var{c}}
15923@item @code{uw1 __MCPLI (uw2, const)}
15924@tab @code{@var{c} = __MCPLI (@var{a}, @var{b})}
15925@tab @code{MCPLI @var{a},#@var{b},@var{c}}
15926@item @code{void __MCPXIS (acc, sw1, sw1)}
15927@tab @code{__MCPXIS (@var{c}, @var{a}, @var{b})}
15928@tab @code{MCPXIS @var{a},@var{b},@var{c}}
15929@item @code{void __MCPXIU (acc, uw1, uw1)}
15930@tab @code{__MCPXIU (@var{c}, @var{a}, @var{b})}
15931@tab @code{MCPXIU @var{a},@var{b},@var{c}}
15932@item @code{void __MCPXRS (acc, sw1, sw1)}
15933@tab @code{__MCPXRS (@var{c}, @var{a}, @var{b})}
15934@tab @code{MCPXRS @var{a},@var{b},@var{c}}
15935@item @code{void __MCPXRU (acc, uw1, uw1)}
15936@tab @code{__MCPXRU (@var{c}, @var{a}, @var{b})}
15937@tab @code{MCPXRU @var{a},@var{b},@var{c}}
15938@item @code{uw1 __MCUT (acc, uw1)}
15939@tab @code{@var{c} = __MCUT (@var{a}, @var{b})}
15940@tab @code{MCUT @var{a},@var{b},@var{c}}
15941@item @code{uw1 __MCUTSS (acc, sw1)}
15942@tab @code{@var{c} = __MCUTSS (@var{a}, @var{b})}
15943@tab @code{MCUTSS @var{a},@var{b},@var{c}}
15944@item @code{void __MDADDACCS (acc, acc)}
15945@tab @code{__MDADDACCS (@var{b}, @var{a})}
15946@tab @code{MDADDACCS @var{a},@var{b}}
15947@item @code{void __MDASACCS (acc, acc)}
15948@tab @code{__MDASACCS (@var{b}, @var{a})}
15949@tab @code{MDASACCS @var{a},@var{b}}
15950@item @code{uw2 __MDCUTSSI (acc, const)}
15951@tab @code{@var{c} = __MDCUTSSI (@var{a}, @var{b})}
15952@tab @code{MDCUTSSI @var{a},#@var{b},@var{c}}
15953@item @code{uw2 __MDPACKH (uw2, uw2)}
15954@tab @code{@var{c} = __MDPACKH (@var{a}, @var{b})}
15955@tab @code{MDPACKH @var{a},@var{b},@var{c}}
15956@item @code{uw2 __MDROTLI (uw2, const)}
15957@tab @code{@var{c} = __MDROTLI (@var{a}, @var{b})}
15958@tab @code{MDROTLI @var{a},#@var{b},@var{c}}
15959@item @code{void __MDSUBACCS (acc, acc)}
15960@tab @code{__MDSUBACCS (@var{b}, @var{a})}
15961@tab @code{MDSUBACCS @var{a},@var{b}}
15962@item @code{void __MDUNPACKH (uw1 *, uw2)}
15963@tab @code{__MDUNPACKH (&@var{b}, @var{a})}
15964@tab @code{MDUNPACKH @var{a},@var{b}}
15965@item @code{uw2 __MEXPDHD (uw1, const)}
15966@tab @code{@var{c} = __MEXPDHD (@var{a}, @var{b})}
15967@tab @code{MEXPDHD @var{a},#@var{b},@var{c}}
15968@item @code{uw1 __MEXPDHW (uw1, const)}
15969@tab @code{@var{c} = __MEXPDHW (@var{a}, @var{b})}
15970@tab @code{MEXPDHW @var{a},#@var{b},@var{c}}
15971@item @code{uw1 __MHDSETH (uw1, const)}
15972@tab @code{@var{c} = __MHDSETH (@var{a}, @var{b})}
15973@tab @code{MHDSETH @var{a},#@var{b},@var{c}}
15974@item @code{sw1 __MHDSETS (const)}
15975@tab @code{@var{b} = __MHDSETS (@var{a})}
15976@tab @code{MHDSETS #@var{a},@var{b}}
15977@item @code{uw1 __MHSETHIH (uw1, const)}
15978@tab @code{@var{b} = __MHSETHIH (@var{b}, @var{a})}
15979@tab @code{MHSETHIH #@var{a},@var{b}}
15980@item @code{sw1 __MHSETHIS (sw1, const)}
15981@tab @code{@var{b} = __MHSETHIS (@var{b}, @var{a})}
15982@tab @code{MHSETHIS #@var{a},@var{b}}
15983@item @code{uw1 __MHSETLOH (uw1, const)}
15984@tab @code{@var{b} = __MHSETLOH (@var{b}, @var{a})}
15985@tab @code{MHSETLOH #@var{a},@var{b}}
15986@item @code{sw1 __MHSETLOS (sw1, const)}
15987@tab @code{@var{b} = __MHSETLOS (@var{b}, @var{a})}
15988@tab @code{MHSETLOS #@var{a},@var{b}}
15989@item @code{uw1 __MHTOB (uw2)}
15990@tab @code{@var{b} = __MHTOB (@var{a})}
15991@tab @code{MHTOB @var{a},@var{b}}
15992@item @code{void __MMACHS (acc, sw1, sw1)}
15993@tab @code{__MMACHS (@var{c}, @var{a}, @var{b})}
15994@tab @code{MMACHS @var{a},@var{b},@var{c}}
15995@item @code{void __MMACHU (acc, uw1, uw1)}
15996@tab @code{__MMACHU (@var{c}, @var{a}, @var{b})}
15997@tab @code{MMACHU @var{a},@var{b},@var{c}}
15998@item @code{void __MMRDHS (acc, sw1, sw1)}
15999@tab @code{__MMRDHS (@var{c}, @var{a}, @var{b})}
16000@tab @code{MMRDHS @var{a},@var{b},@var{c}}
16001@item @code{void __MMRDHU (acc, uw1, uw1)}
16002@tab @code{__MMRDHU (@var{c}, @var{a}, @var{b})}
16003@tab @code{MMRDHU @var{a},@var{b},@var{c}}
16004@item @code{void __MMULHS (acc, sw1, sw1)}
16005@tab @code{__MMULHS (@var{c}, @var{a}, @var{b})}
16006@tab @code{MMULHS @var{a},@var{b},@var{c}}
16007@item @code{void __MMULHU (acc, uw1, uw1)}
16008@tab @code{__MMULHU (@var{c}, @var{a}, @var{b})}
16009@tab @code{MMULHU @var{a},@var{b},@var{c}}
16010@item @code{void __MMULXHS (acc, sw1, sw1)}
16011@tab @code{__MMULXHS (@var{c}, @var{a}, @var{b})}
16012@tab @code{MMULXHS @var{a},@var{b},@var{c}}
16013@item @code{void __MMULXHU (acc, uw1, uw1)}
16014@tab @code{__MMULXHU (@var{c}, @var{a}, @var{b})}
16015@tab @code{MMULXHU @var{a},@var{b},@var{c}}
16016@item @code{uw1 __MNOT (uw1)}
16017@tab @code{@var{b} = __MNOT (@var{a})}
16018@tab @code{MNOT @var{a},@var{b}}
16019@item @code{uw1 __MOR (uw1, uw1)}
16020@tab @code{@var{c} = __MOR (@var{a}, @var{b})}
16021@tab @code{MOR @var{a},@var{b},@var{c}}
16022@item @code{uw1 __MPACKH (uh, uh)}
16023@tab @code{@var{c} = __MPACKH (@var{a}, @var{b})}
16024@tab @code{MPACKH @var{a},@var{b},@var{c}}
16025@item @code{sw2 __MQADDHSS (sw2, sw2)}
16026@tab @code{@var{c} = __MQADDHSS (@var{a}, @var{b})}
16027@tab @code{MQADDHSS @var{a},@var{b},@var{c}}
16028@item @code{uw2 __MQADDHUS (uw2, uw2)}
16029@tab @code{@var{c} = __MQADDHUS (@var{a}, @var{b})}
16030@tab @code{MQADDHUS @var{a},@var{b},@var{c}}
16031@item @code{void __MQCPXIS (acc, sw2, sw2)}
16032@tab @code{__MQCPXIS (@var{c}, @var{a}, @var{b})}
16033@tab @code{MQCPXIS @var{a},@var{b},@var{c}}
16034@item @code{void __MQCPXIU (acc, uw2, uw2)}
16035@tab @code{__MQCPXIU (@var{c}, @var{a}, @var{b})}
16036@tab @code{MQCPXIU @var{a},@var{b},@var{c}}
16037@item @code{void __MQCPXRS (acc, sw2, sw2)}
16038@tab @code{__MQCPXRS (@var{c}, @var{a}, @var{b})}
16039@tab @code{MQCPXRS @var{a},@var{b},@var{c}}
16040@item @code{void __MQCPXRU (acc, uw2, uw2)}
16041@tab @code{__MQCPXRU (@var{c}, @var{a}, @var{b})}
16042@tab @code{MQCPXRU @var{a},@var{b},@var{c}}
16043@item @code{sw2 __MQLCLRHS (sw2, sw2)}
16044@tab @code{@var{c} = __MQLCLRHS (@var{a}, @var{b})}
16045@tab @code{MQLCLRHS @var{a},@var{b},@var{c}}
16046@item @code{sw2 __MQLMTHS (sw2, sw2)}
16047@tab @code{@var{c} = __MQLMTHS (@var{a}, @var{b})}
16048@tab @code{MQLMTHS @var{a},@var{b},@var{c}}
16049@item @code{void __MQMACHS (acc, sw2, sw2)}
16050@tab @code{__MQMACHS (@var{c}, @var{a}, @var{b})}
16051@tab @code{MQMACHS @var{a},@var{b},@var{c}}
16052@item @code{void __MQMACHU (acc, uw2, uw2)}
16053@tab @code{__MQMACHU (@var{c}, @var{a}, @var{b})}
16054@tab @code{MQMACHU @var{a},@var{b},@var{c}}
16055@item @code{void __MQMACXHS (acc, sw2, sw2)}
16056@tab @code{__MQMACXHS (@var{c}, @var{a}, @var{b})}
16057@tab @code{MQMACXHS @var{a},@var{b},@var{c}}
16058@item @code{void __MQMULHS (acc, sw2, sw2)}
16059@tab @code{__MQMULHS (@var{c}, @var{a}, @var{b})}
16060@tab @code{MQMULHS @var{a},@var{b},@var{c}}
16061@item @code{void __MQMULHU (acc, uw2, uw2)}
16062@tab @code{__MQMULHU (@var{c}, @var{a}, @var{b})}
16063@tab @code{MQMULHU @var{a},@var{b},@var{c}}
16064@item @code{void __MQMULXHS (acc, sw2, sw2)}
16065@tab @code{__MQMULXHS (@var{c}, @var{a}, @var{b})}
16066@tab @code{MQMULXHS @var{a},@var{b},@var{c}}
16067@item @code{void __MQMULXHU (acc, uw2, uw2)}
16068@tab @code{__MQMULXHU (@var{c}, @var{a}, @var{b})}
16069@tab @code{MQMULXHU @var{a},@var{b},@var{c}}
16070@item @code{sw2 __MQSATHS (sw2, sw2)}
16071@tab @code{@var{c} = __MQSATHS (@var{a}, @var{b})}
16072@tab @code{MQSATHS @var{a},@var{b},@var{c}}
16073@item @code{uw2 __MQSLLHI (uw2, int)}
16074@tab @code{@var{c} = __MQSLLHI (@var{a}, @var{b})}
16075@tab @code{MQSLLHI @var{a},@var{b},@var{c}}
16076@item @code{sw2 __MQSRAHI (sw2, int)}
16077@tab @code{@var{c} = __MQSRAHI (@var{a}, @var{b})}
16078@tab @code{MQSRAHI @var{a},@var{b},@var{c}}
16079@item @code{sw2 __MQSUBHSS (sw2, sw2)}
16080@tab @code{@var{c} = __MQSUBHSS (@var{a}, @var{b})}
16081@tab @code{MQSUBHSS @var{a},@var{b},@var{c}}
16082@item @code{uw2 __MQSUBHUS (uw2, uw2)}
16083@tab @code{@var{c} = __MQSUBHUS (@var{a}, @var{b})}
16084@tab @code{MQSUBHUS @var{a},@var{b},@var{c}}
16085@item @code{void __MQXMACHS (acc, sw2, sw2)}
16086@tab @code{__MQXMACHS (@var{c}, @var{a}, @var{b})}
16087@tab @code{MQXMACHS @var{a},@var{b},@var{c}}
16088@item @code{void __MQXMACXHS (acc, sw2, sw2)}
16089@tab @code{__MQXMACXHS (@var{c}, @var{a}, @var{b})}
16090@tab @code{MQXMACXHS @var{a},@var{b},@var{c}}
16091@item @code{uw1 __MRDACC (acc)}
16092@tab @code{@var{b} = __MRDACC (@var{a})}
16093@tab @code{MRDACC @var{a},@var{b}}
16094@item @code{uw1 __MRDACCG (acc)}
16095@tab @code{@var{b} = __MRDACCG (@var{a})}
16096@tab @code{MRDACCG @var{a},@var{b}}
16097@item @code{uw1 __MROTLI (uw1, const)}
16098@tab @code{@var{c} = __MROTLI (@var{a}, @var{b})}
16099@tab @code{MROTLI @var{a},#@var{b},@var{c}}
16100@item @code{uw1 __MROTRI (uw1, const)}
16101@tab @code{@var{c} = __MROTRI (@var{a}, @var{b})}
16102@tab @code{MROTRI @var{a},#@var{b},@var{c}}
16103@item @code{sw1 __MSATHS (sw1, sw1)}
16104@tab @code{@var{c} = __MSATHS (@var{a}, @var{b})}
16105@tab @code{MSATHS @var{a},@var{b},@var{c}}
16106@item @code{uw1 __MSATHU (uw1, uw1)}
16107@tab @code{@var{c} = __MSATHU (@var{a}, @var{b})}
16108@tab @code{MSATHU @var{a},@var{b},@var{c}}
16109@item @code{uw1 __MSLLHI (uw1, const)}
16110@tab @code{@var{c} = __MSLLHI (@var{a}, @var{b})}
16111@tab @code{MSLLHI @var{a},#@var{b},@var{c}}
16112@item @code{sw1 __MSRAHI (sw1, const)}
16113@tab @code{@var{c} = __MSRAHI (@var{a}, @var{b})}
16114@tab @code{MSRAHI @var{a},#@var{b},@var{c}}
16115@item @code{uw1 __MSRLHI (uw1, const)}
16116@tab @code{@var{c} = __MSRLHI (@var{a}, @var{b})}
16117@tab @code{MSRLHI @var{a},#@var{b},@var{c}}
16118@item @code{void __MSUBACCS (acc, acc)}
16119@tab @code{__MSUBACCS (@var{b}, @var{a})}
16120@tab @code{MSUBACCS @var{a},@var{b}}
16121@item @code{sw1 __MSUBHSS (sw1, sw1)}
16122@tab @code{@var{c} = __MSUBHSS (@var{a}, @var{b})}
16123@tab @code{MSUBHSS @var{a},@var{b},@var{c}}
16124@item @code{uw1 __MSUBHUS (uw1, uw1)}
16125@tab @code{@var{c} = __MSUBHUS (@var{a}, @var{b})}
16126@tab @code{MSUBHUS @var{a},@var{b},@var{c}}
16127@item @code{void __MTRAP (void)}
16128@tab @code{__MTRAP ()}
16129@tab @code{MTRAP}
16130@item @code{uw2 __MUNPACKH (uw1)}
16131@tab @code{@var{b} = __MUNPACKH (@var{a})}
16132@tab @code{MUNPACKH @var{a},@var{b}}
16133@item @code{uw1 __MWCUT (uw2, uw1)}
16134@tab @code{@var{c} = __MWCUT (@var{a}, @var{b})}
16135@tab @code{MWCUT @var{a},@var{b},@var{c}}
16136@item @code{void __MWTACC (acc, uw1)}
16137@tab @code{__MWTACC (@var{b}, @var{a})}
16138@tab @code{MWTACC @var{a},@var{b}}
16139@item @code{void __MWTACCG (acc, uw1)}
16140@tab @code{__MWTACCG (@var{b}, @var{a})}
16141@tab @code{MWTACCG @var{a},@var{b}}
16142@item @code{uw1 __MXOR (uw1, uw1)}
16143@tab @code{@var{c} = __MXOR (@var{a}, @var{b})}
16144@tab @code{MXOR @var{a},@var{b},@var{c}}
16145@end multitable
16146
16147@node Raw read/write Functions
16148@subsubsection Raw Read/Write Functions
16149
16150This sections describes built-in functions related to read and write
16151instructions to access memory. These functions generate
16152@code{membar} instructions to flush the I/O load and stores where
16153appropriate, as described in Fujitsu's manual described above.
16154
16155@table @code
16156
16157@item unsigned char __builtin_read8 (void *@var{data})
16158@item unsigned short __builtin_read16 (void *@var{data})
16159@item unsigned long __builtin_read32 (void *@var{data})
16160@item unsigned long long __builtin_read64 (void *@var{data})
16161
16162@item void __builtin_write8 (void *@var{data}, unsigned char @var{datum})
16163@item void __builtin_write16 (void *@var{data}, unsigned short @var{datum})
16164@item void __builtin_write32 (void *@var{data}, unsigned long @var{datum})
16165@item void __builtin_write64 (void *@var{data}, unsigned long long @var{datum})
16166@end table
16167
16168@node Other Built-in Functions
16169@subsubsection Other Built-in Functions
16170
16171This section describes built-in functions that are not named after
16172a specific FR-V instruction.
16173
16174@table @code
16175@item sw2 __IACCreadll (iacc @var{reg})
16176Return the full 64-bit value of IACC0@. The @var{reg} argument is reserved
16177for future expansion and must be 0.
16178
16179@item sw1 __IACCreadl (iacc @var{reg})
16180Return the value of IACC0H if @var{reg} is 0 and IACC0L if @var{reg} is 1.
16181Other values of @var{reg} are rejected as invalid.
16182
16183@item void __IACCsetll (iacc @var{reg}, sw2 @var{x})
16184Set the full 64-bit value of IACC0 to @var{x}. The @var{reg} argument
16185is reserved for future expansion and must be 0.
16186
16187@item void __IACCsetl (iacc @var{reg}, sw1 @var{x})
16188Set IACC0H to @var{x} if @var{reg} is 0 and IACC0L to @var{x} if @var{reg}
16189is 1. Other values of @var{reg} are rejected as invalid.
16190
16191@item void __data_prefetch0 (const void *@var{x})
16192Use the @code{dcpl} instruction to load the contents of address @var{x}
16193into the data cache.
16194
16195@item void __data_prefetch (const void *@var{x})
16196Use the @code{nldub} instruction to load the contents of address @var{x}
16197into the data cache. The instruction is issued in slot I1@.
16198@end table
16199
16200@node MIPS DSP Built-in Functions
16201@subsection MIPS DSP Built-in Functions
16202
16203The MIPS DSP Application-Specific Extension (ASE) includes new
16204instructions that are designed to improve the performance of DSP and
16205media applications. It provides instructions that operate on packed
162068-bit/16-bit integer data, Q7, Q15 and Q31 fractional data.
16207
16208GCC supports MIPS DSP operations using both the generic
16209vector extensions (@pxref{Vector Extensions}) and a collection of
16210MIPS-specific built-in functions. Both kinds of support are
16211enabled by the @option{-mdsp} command-line option.
16212
16213Revision 2 of the ASE was introduced in the second half of 2006.
16214This revision adds extra instructions to the original ASE, but is
16215otherwise backwards-compatible with it. You can select revision 2
16216using the command-line option @option{-mdspr2}; this option implies
16217@option{-mdsp}.
16218
16219The SCOUNT and POS bits of the DSP control register are global. The
16220WRDSP, EXTPDP, EXTPDPV and MTHLIP instructions modify the SCOUNT and
16221POS bits. During optimization, the compiler does not delete these
16222instructions and it does not delete calls to functions containing
16223these instructions.
16224
16225At present, GCC only provides support for operations on 32-bit
16226vectors. The vector type associated with 8-bit integer data is
16227usually called @code{v4i8}, the vector type associated with Q7
16228is usually called @code{v4q7}, the vector type associated with 16-bit
16229integer data is usually called @code{v2i16}, and the vector type
16230associated with Q15 is usually called @code{v2q15}. They can be
16231defined in C as follows:
16232
16233@smallexample
16234typedef signed char v4i8 __attribute__ ((vector_size(4)));
16235typedef signed char v4q7 __attribute__ ((vector_size(4)));
16236typedef short v2i16 __attribute__ ((vector_size(4)));
16237typedef short v2q15 __attribute__ ((vector_size(4)));
16238@end smallexample
16239
16240@code{v4i8}, @code{v4q7}, @code{v2i16} and @code{v2q15} values are
16241initialized in the same way as aggregates. For example:
16242
16243@smallexample
16244v4i8 a = @{1, 2, 3, 4@};
16245v4i8 b;
16246b = (v4i8) @{5, 6, 7, 8@};
16247
16248v2q15 c = @{0x0fcb, 0x3a75@};
16249v2q15 d;
16250d = (v2q15) @{0.1234 * 0x1.0p15, 0.4567 * 0x1.0p15@};
16251@end smallexample
16252
16253@emph{Note:} The CPU's endianness determines the order in which values
16254are packed. On little-endian targets, the first value is the least
16255significant and the last value is the most significant. The opposite
16256order applies to big-endian targets. For example, the code above
16257sets the lowest byte of @code{a} to @code{1} on little-endian targets
16258and @code{4} on big-endian targets.
16259
16260@emph{Note:} Q7, Q15 and Q31 values must be initialized with their integer
16261representation. As shown in this example, the integer representation
16262of a Q7 value can be obtained by multiplying the fractional value by
16263@code{0x1.0p7}. The equivalent for Q15 values is to multiply by
16264@code{0x1.0p15}. The equivalent for Q31 values is to multiply by
16265@code{0x1.0p31}.
16266
16267The table below lists the @code{v4i8} and @code{v2q15} operations for which
16268hardware support exists. @code{a} and @code{b} are @code{v4i8} values,
16269and @code{c} and @code{d} are @code{v2q15} values.
16270
16271@multitable @columnfractions .50 .50
16272@headitem C code @tab MIPS instruction
16273@item @code{a + b} @tab @code{addu.qb}
16274@item @code{c + d} @tab @code{addq.ph}
16275@item @code{a - b} @tab @code{subu.qb}
16276@item @code{c - d} @tab @code{subq.ph}
16277@end multitable
16278
16279The table below lists the @code{v2i16} operation for which
16280hardware support exists for the DSP ASE REV 2. @code{e} and @code{f} are
16281@code{v2i16} values.
16282
16283@multitable @columnfractions .50 .50
16284@headitem C code @tab MIPS instruction
16285@item @code{e * f} @tab @code{mul.ph}
16286@end multitable
16287
16288It is easier to describe the DSP built-in functions if we first define
16289the following types:
16290
16291@smallexample
16292typedef int q31;
16293typedef int i32;
16294typedef unsigned int ui32;
16295typedef long long a64;
16296@end smallexample
16297
16298@code{q31} and @code{i32} are actually the same as @code{int}, but we
16299use @code{q31} to indicate a Q31 fractional value and @code{i32} to
16300indicate a 32-bit integer value. Similarly, @code{a64} is the same as
16301@code{long long}, but we use @code{a64} to indicate values that are
16302placed in one of the four DSP accumulators (@code{$ac0},
16303@code{$ac1}, @code{$ac2} or @code{$ac3}).
16304
16305Also, some built-in functions prefer or require immediate numbers as
16306parameters, because the corresponding DSP instructions accept both immediate
16307numbers and register operands, or accept immediate numbers only. The
16308immediate parameters are listed as follows.
16309
16310@smallexample
16311imm0_3: 0 to 3.
16312imm0_7: 0 to 7.
16313imm0_15: 0 to 15.
16314imm0_31: 0 to 31.
16315imm0_63: 0 to 63.
16316imm0_255: 0 to 255.
16317imm_n32_31: -32 to 31.
16318imm_n512_511: -512 to 511.
16319@end smallexample
16320
16321The following built-in functions map directly to a particular MIPS DSP
16322instruction. Please refer to the architecture specification
16323for details on what each instruction does.
16324
16325@smallexample
16326v2q15 __builtin_mips_addq_ph (v2q15, v2q15);
16327v2q15 __builtin_mips_addq_s_ph (v2q15, v2q15);
16328q31 __builtin_mips_addq_s_w (q31, q31);
16329v4i8 __builtin_mips_addu_qb (v4i8, v4i8);
16330v4i8 __builtin_mips_addu_s_qb (v4i8, v4i8);
16331v2q15 __builtin_mips_subq_ph (v2q15, v2q15);
16332v2q15 __builtin_mips_subq_s_ph (v2q15, v2q15);
16333q31 __builtin_mips_subq_s_w (q31, q31);
16334v4i8 __builtin_mips_subu_qb (v4i8, v4i8);
16335v4i8 __builtin_mips_subu_s_qb (v4i8, v4i8);
16336i32 __builtin_mips_addsc (i32, i32);
16337i32 __builtin_mips_addwc (i32, i32);
16338i32 __builtin_mips_modsub (i32, i32);
16339i32 __builtin_mips_raddu_w_qb (v4i8);
16340v2q15 __builtin_mips_absq_s_ph (v2q15);
16341q31 __builtin_mips_absq_s_w (q31);
16342v4i8 __builtin_mips_precrq_qb_ph (v2q15, v2q15);
16343v2q15 __builtin_mips_precrq_ph_w (q31, q31);
16344v2q15 __builtin_mips_precrq_rs_ph_w (q31, q31);
16345v4i8 __builtin_mips_precrqu_s_qb_ph (v2q15, v2q15);
16346q31 __builtin_mips_preceq_w_phl (v2q15);
16347q31 __builtin_mips_preceq_w_phr (v2q15);
16348v2q15 __builtin_mips_precequ_ph_qbl (v4i8);
16349v2q15 __builtin_mips_precequ_ph_qbr (v4i8);
16350v2q15 __builtin_mips_precequ_ph_qbla (v4i8);
16351v2q15 __builtin_mips_precequ_ph_qbra (v4i8);
16352v2q15 __builtin_mips_preceu_ph_qbl (v4i8);
16353v2q15 __builtin_mips_preceu_ph_qbr (v4i8);
16354v2q15 __builtin_mips_preceu_ph_qbla (v4i8);
16355v2q15 __builtin_mips_preceu_ph_qbra (v4i8);
16356v4i8 __builtin_mips_shll_qb (v4i8, imm0_7);
16357v4i8 __builtin_mips_shll_qb (v4i8, i32);
16358v2q15 __builtin_mips_shll_ph (v2q15, imm0_15);
16359v2q15 __builtin_mips_shll_ph (v2q15, i32);
16360v2q15 __builtin_mips_shll_s_ph (v2q15, imm0_15);
16361v2q15 __builtin_mips_shll_s_ph (v2q15, i32);
16362q31 __builtin_mips_shll_s_w (q31, imm0_31);
16363q31 __builtin_mips_shll_s_w (q31, i32);
16364v4i8 __builtin_mips_shrl_qb (v4i8, imm0_7);
16365v4i8 __builtin_mips_shrl_qb (v4i8, i32);
16366v2q15 __builtin_mips_shra_ph (v2q15, imm0_15);
16367v2q15 __builtin_mips_shra_ph (v2q15, i32);
16368v2q15 __builtin_mips_shra_r_ph (v2q15, imm0_15);
16369v2q15 __builtin_mips_shra_r_ph (v2q15, i32);
16370q31 __builtin_mips_shra_r_w (q31, imm0_31);
16371q31 __builtin_mips_shra_r_w (q31, i32);
16372v2q15 __builtin_mips_muleu_s_ph_qbl (v4i8, v2q15);
16373v2q15 __builtin_mips_muleu_s_ph_qbr (v4i8, v2q15);
16374v2q15 __builtin_mips_mulq_rs_ph (v2q15, v2q15);
16375q31 __builtin_mips_muleq_s_w_phl (v2q15, v2q15);
16376q31 __builtin_mips_muleq_s_w_phr (v2q15, v2q15);
16377a64 __builtin_mips_dpau_h_qbl (a64, v4i8, v4i8);
16378a64 __builtin_mips_dpau_h_qbr (a64, v4i8, v4i8);
16379a64 __builtin_mips_dpsu_h_qbl (a64, v4i8, v4i8);
16380a64 __builtin_mips_dpsu_h_qbr (a64, v4i8, v4i8);
16381a64 __builtin_mips_dpaq_s_w_ph (a64, v2q15, v2q15);
16382a64 __builtin_mips_dpaq_sa_l_w (a64, q31, q31);
16383a64 __builtin_mips_dpsq_s_w_ph (a64, v2q15, v2q15);
16384a64 __builtin_mips_dpsq_sa_l_w (a64, q31, q31);
16385a64 __builtin_mips_mulsaq_s_w_ph (a64, v2q15, v2q15);
16386a64 __builtin_mips_maq_s_w_phl (a64, v2q15, v2q15);
16387a64 __builtin_mips_maq_s_w_phr (a64, v2q15, v2q15);
16388a64 __builtin_mips_maq_sa_w_phl (a64, v2q15, v2q15);
16389a64 __builtin_mips_maq_sa_w_phr (a64, v2q15, v2q15);
16390i32 __builtin_mips_bitrev (i32);
16391i32 __builtin_mips_insv (i32, i32);
16392v4i8 __builtin_mips_repl_qb (imm0_255);
16393v4i8 __builtin_mips_repl_qb (i32);
16394v2q15 __builtin_mips_repl_ph (imm_n512_511);
16395v2q15 __builtin_mips_repl_ph (i32);
16396void __builtin_mips_cmpu_eq_qb (v4i8, v4i8);
16397void __builtin_mips_cmpu_lt_qb (v4i8, v4i8);
16398void __builtin_mips_cmpu_le_qb (v4i8, v4i8);
16399i32 __builtin_mips_cmpgu_eq_qb (v4i8, v4i8);
16400i32 __builtin_mips_cmpgu_lt_qb (v4i8, v4i8);
16401i32 __builtin_mips_cmpgu_le_qb (v4i8, v4i8);
16402void __builtin_mips_cmp_eq_ph (v2q15, v2q15);
16403void __builtin_mips_cmp_lt_ph (v2q15, v2q15);
16404void __builtin_mips_cmp_le_ph (v2q15, v2q15);
16405v4i8 __builtin_mips_pick_qb (v4i8, v4i8);
16406v2q15 __builtin_mips_pick_ph (v2q15, v2q15);
16407v2q15 __builtin_mips_packrl_ph (v2q15, v2q15);
16408i32 __builtin_mips_extr_w (a64, imm0_31);
16409i32 __builtin_mips_extr_w (a64, i32);
16410i32 __builtin_mips_extr_r_w (a64, imm0_31);
16411i32 __builtin_mips_extr_s_h (a64, i32);
16412i32 __builtin_mips_extr_rs_w (a64, imm0_31);
16413i32 __builtin_mips_extr_rs_w (a64, i32);
16414i32 __builtin_mips_extr_s_h (a64, imm0_31);
16415i32 __builtin_mips_extr_r_w (a64, i32);
16416i32 __builtin_mips_extp (a64, imm0_31);
16417i32 __builtin_mips_extp (a64, i32);
16418i32 __builtin_mips_extpdp (a64, imm0_31);
16419i32 __builtin_mips_extpdp (a64, i32);
16420a64 __builtin_mips_shilo (a64, imm_n32_31);
16421a64 __builtin_mips_shilo (a64, i32);
16422a64 __builtin_mips_mthlip (a64, i32);
16423void __builtin_mips_wrdsp (i32, imm0_63);
16424i32 __builtin_mips_rddsp (imm0_63);
16425i32 __builtin_mips_lbux (void *, i32);
16426i32 __builtin_mips_lhx (void *, i32);
16427i32 __builtin_mips_lwx (void *, i32);
16428a64 __builtin_mips_ldx (void *, i32); /* MIPS64 only */
16429i32 __builtin_mips_bposge32 (void);
16430a64 __builtin_mips_madd (a64, i32, i32);
16431a64 __builtin_mips_maddu (a64, ui32, ui32);
16432a64 __builtin_mips_msub (a64, i32, i32);
16433a64 __builtin_mips_msubu (a64, ui32, ui32);
16434a64 __builtin_mips_mult (i32, i32);
16435a64 __builtin_mips_multu (ui32, ui32);
16436@end smallexample
16437
16438The following built-in functions map directly to a particular MIPS DSP REV 2
16439instruction. Please refer to the architecture specification
16440for details on what each instruction does.
16441
16442@smallexample
16443v4q7 __builtin_mips_absq_s_qb (v4q7);
16444v2i16 __builtin_mips_addu_ph (v2i16, v2i16);
16445v2i16 __builtin_mips_addu_s_ph (v2i16, v2i16);
16446v4i8 __builtin_mips_adduh_qb (v4i8, v4i8);
16447v4i8 __builtin_mips_adduh_r_qb (v4i8, v4i8);
16448i32 __builtin_mips_append (i32, i32, imm0_31);
16449i32 __builtin_mips_balign (i32, i32, imm0_3);
16450i32 __builtin_mips_cmpgdu_eq_qb (v4i8, v4i8);
16451i32 __builtin_mips_cmpgdu_lt_qb (v4i8, v4i8);
16452i32 __builtin_mips_cmpgdu_le_qb (v4i8, v4i8);
16453a64 __builtin_mips_dpa_w_ph (a64, v2i16, v2i16);
16454a64 __builtin_mips_dps_w_ph (a64, v2i16, v2i16);
16455v2i16 __builtin_mips_mul_ph (v2i16, v2i16);
16456v2i16 __builtin_mips_mul_s_ph (v2i16, v2i16);
16457q31 __builtin_mips_mulq_rs_w (q31, q31);
16458v2q15 __builtin_mips_mulq_s_ph (v2q15, v2q15);
16459q31 __builtin_mips_mulq_s_w (q31, q31);
16460a64 __builtin_mips_mulsa_w_ph (a64, v2i16, v2i16);
16461v4i8 __builtin_mips_precr_qb_ph (v2i16, v2i16);
16462v2i16 __builtin_mips_precr_sra_ph_w (i32, i32, imm0_31);
16463v2i16 __builtin_mips_precr_sra_r_ph_w (i32, i32, imm0_31);
16464i32 __builtin_mips_prepend (i32, i32, imm0_31);
16465v4i8 __builtin_mips_shra_qb (v4i8, imm0_7);
16466v4i8 __builtin_mips_shra_r_qb (v4i8, imm0_7);
16467v4i8 __builtin_mips_shra_qb (v4i8, i32);
16468v4i8 __builtin_mips_shra_r_qb (v4i8, i32);
16469v2i16 __builtin_mips_shrl_ph (v2i16, imm0_15);
16470v2i16 __builtin_mips_shrl_ph (v2i16, i32);
16471v2i16 __builtin_mips_subu_ph (v2i16, v2i16);
16472v2i16 __builtin_mips_subu_s_ph (v2i16, v2i16);
16473v4i8 __builtin_mips_subuh_qb (v4i8, v4i8);
16474v4i8 __builtin_mips_subuh_r_qb (v4i8, v4i8);
16475v2q15 __builtin_mips_addqh_ph (v2q15, v2q15);
16476v2q15 __builtin_mips_addqh_r_ph (v2q15, v2q15);
16477q31 __builtin_mips_addqh_w (q31, q31);
16478q31 __builtin_mips_addqh_r_w (q31, q31);
16479v2q15 __builtin_mips_subqh_ph (v2q15, v2q15);
16480v2q15 __builtin_mips_subqh_r_ph (v2q15, v2q15);
16481q31 __builtin_mips_subqh_w (q31, q31);
16482q31 __builtin_mips_subqh_r_w (q31, q31);
16483a64 __builtin_mips_dpax_w_ph (a64, v2i16, v2i16);
16484a64 __builtin_mips_dpsx_w_ph (a64, v2i16, v2i16);
16485a64 __builtin_mips_dpaqx_s_w_ph (a64, v2q15, v2q15);
16486a64 __builtin_mips_dpaqx_sa_w_ph (a64, v2q15, v2q15);
16487a64 __builtin_mips_dpsqx_s_w_ph (a64, v2q15, v2q15);
16488a64 __builtin_mips_dpsqx_sa_w_ph (a64, v2q15, v2q15);
16489@end smallexample
16490
16491
16492@node MIPS Paired-Single Support
16493@subsection MIPS Paired-Single Support
16494
16495The MIPS64 architecture includes a number of instructions that
16496operate on pairs of single-precision floating-point values.
16497Each pair is packed into a 64-bit floating-point register,
16498with one element being designated the ``upper half'' and
16499the other being designated the ``lower half''.
16500
16501GCC supports paired-single operations using both the generic
16502vector extensions (@pxref{Vector Extensions}) and a collection of
16503MIPS-specific built-in functions. Both kinds of support are
16504enabled by the @option{-mpaired-single} command-line option.
16505
16506The vector type associated with paired-single values is usually
16507called @code{v2sf}. It can be defined in C as follows:
16508
16509@smallexample
16510typedef float v2sf __attribute__ ((vector_size (8)));
16511@end smallexample
16512
16513@code{v2sf} values are initialized in the same way as aggregates.
16514For example:
16515
16516@smallexample
16517v2sf a = @{1.5, 9.1@};
16518v2sf b;
16519float e, f;
16520b = (v2sf) @{e, f@};
16521@end smallexample
16522
16523@emph{Note:} The CPU's endianness determines which value is stored in
16524the upper half of a register and which value is stored in the lower half.
16525On little-endian targets, the first value is the lower one and the second
16526value is the upper one. The opposite order applies to big-endian targets.
16527For example, the code above sets the lower half of @code{a} to
16528@code{1.5} on little-endian targets and @code{9.1} on big-endian targets.
16529
16530@node MIPS Loongson Built-in Functions
16531@subsection MIPS Loongson Built-in Functions
16532
16533GCC provides intrinsics to access the SIMD instructions provided by the
16534ST Microelectronics Loongson-2E and -2F processors. These intrinsics,
16535available after inclusion of the @code{loongson.h} header file,
16536operate on the following 64-bit vector types:
16537
16538@itemize
16539@item @code{uint8x8_t}, a vector of eight unsigned 8-bit integers;
16540@item @code{uint16x4_t}, a vector of four unsigned 16-bit integers;
16541@item @code{uint32x2_t}, a vector of two unsigned 32-bit integers;
16542@item @code{int8x8_t}, a vector of eight signed 8-bit integers;
16543@item @code{int16x4_t}, a vector of four signed 16-bit integers;
16544@item @code{int32x2_t}, a vector of two signed 32-bit integers.
16545@end itemize
16546
16547The intrinsics provided are listed below; each is named after the
16548machine instruction to which it corresponds, with suffixes added as
16549appropriate to distinguish intrinsics that expand to the same machine
16550instruction yet have different argument types. Refer to the architecture
16551documentation for a description of the functionality of each
16552instruction.
16553
16554@smallexample
16555int16x4_t packsswh (int32x2_t s, int32x2_t t);
16556int8x8_t packsshb (int16x4_t s, int16x4_t t);
16557uint8x8_t packushb (uint16x4_t s, uint16x4_t t);
16558uint32x2_t paddw_u (uint32x2_t s, uint32x2_t t);
16559uint16x4_t paddh_u (uint16x4_t s, uint16x4_t t);
16560uint8x8_t paddb_u (uint8x8_t s, uint8x8_t t);
16561int32x2_t paddw_s (int32x2_t s, int32x2_t t);
16562int16x4_t paddh_s (int16x4_t s, int16x4_t t);
16563int8x8_t paddb_s (int8x8_t s, int8x8_t t);
16564uint64_t paddd_u (uint64_t s, uint64_t t);
16565int64_t paddd_s (int64_t s, int64_t t);
16566int16x4_t paddsh (int16x4_t s, int16x4_t t);
16567int8x8_t paddsb (int8x8_t s, int8x8_t t);
16568uint16x4_t paddush (uint16x4_t s, uint16x4_t t);
16569uint8x8_t paddusb (uint8x8_t s, uint8x8_t t);
16570uint64_t pandn_ud (uint64_t s, uint64_t t);
16571uint32x2_t pandn_uw (uint32x2_t s, uint32x2_t t);
16572uint16x4_t pandn_uh (uint16x4_t s, uint16x4_t t);
16573uint8x8_t pandn_ub (uint8x8_t s, uint8x8_t t);
16574int64_t pandn_sd (int64_t s, int64_t t);
16575int32x2_t pandn_sw (int32x2_t s, int32x2_t t);
16576int16x4_t pandn_sh (int16x4_t s, int16x4_t t);
16577int8x8_t pandn_sb (int8x8_t s, int8x8_t t);
16578uint16x4_t pavgh (uint16x4_t s, uint16x4_t t);
16579uint8x8_t pavgb (uint8x8_t s, uint8x8_t t);
16580uint32x2_t pcmpeqw_u (uint32x2_t s, uint32x2_t t);
16581uint16x4_t pcmpeqh_u (uint16x4_t s, uint16x4_t t);
16582uint8x8_t pcmpeqb_u (uint8x8_t s, uint8x8_t t);
16583int32x2_t pcmpeqw_s (int32x2_t s, int32x2_t t);
16584int16x4_t pcmpeqh_s (int16x4_t s, int16x4_t t);
16585int8x8_t pcmpeqb_s (int8x8_t s, int8x8_t t);
16586uint32x2_t pcmpgtw_u (uint32x2_t s, uint32x2_t t);
16587uint16x4_t pcmpgth_u (uint16x4_t s, uint16x4_t t);
16588uint8x8_t pcmpgtb_u (uint8x8_t s, uint8x8_t t);
16589int32x2_t pcmpgtw_s (int32x2_t s, int32x2_t t);
16590int16x4_t pcmpgth_s (int16x4_t s, int16x4_t t);
16591int8x8_t pcmpgtb_s (int8x8_t s, int8x8_t t);
16592uint16x4_t pextrh_u (uint16x4_t s, int field);
16593int16x4_t pextrh_s (int16x4_t s, int field);
16594uint16x4_t pinsrh_0_u (uint16x4_t s, uint16x4_t t);
16595uint16x4_t pinsrh_1_u (uint16x4_t s, uint16x4_t t);
16596uint16x4_t pinsrh_2_u (uint16x4_t s, uint16x4_t t);
16597uint16x4_t pinsrh_3_u (uint16x4_t s, uint16x4_t t);
16598int16x4_t pinsrh_0_s (int16x4_t s, int16x4_t t);
16599int16x4_t pinsrh_1_s (int16x4_t s, int16x4_t t);
16600int16x4_t pinsrh_2_s (int16x4_t s, int16x4_t t);
16601int16x4_t pinsrh_3_s (int16x4_t s, int16x4_t t);
16602int32x2_t pmaddhw (int16x4_t s, int16x4_t t);
16603int16x4_t pmaxsh (int16x4_t s, int16x4_t t);
16604uint8x8_t pmaxub (uint8x8_t s, uint8x8_t t);
16605int16x4_t pminsh (int16x4_t s, int16x4_t t);
16606uint8x8_t pminub (uint8x8_t s, uint8x8_t t);
16607uint8x8_t pmovmskb_u (uint8x8_t s);
16608int8x8_t pmovmskb_s (int8x8_t s);
16609uint16x4_t pmulhuh (uint16x4_t s, uint16x4_t t);
16610int16x4_t pmulhh (int16x4_t s, int16x4_t t);
16611int16x4_t pmullh (int16x4_t s, int16x4_t t);
16612int64_t pmuluw (uint32x2_t s, uint32x2_t t);
16613uint8x8_t pasubub (uint8x8_t s, uint8x8_t t);
16614uint16x4_t biadd (uint8x8_t s);
16615uint16x4_t psadbh (uint8x8_t s, uint8x8_t t);
16616uint16x4_t pshufh_u (uint16x4_t dest, uint16x4_t s, uint8_t order);
16617int16x4_t pshufh_s (int16x4_t dest, int16x4_t s, uint8_t order);
16618uint16x4_t psllh_u (uint16x4_t s, uint8_t amount);
16619int16x4_t psllh_s (int16x4_t s, uint8_t amount);
16620uint32x2_t psllw_u (uint32x2_t s, uint8_t amount);
16621int32x2_t psllw_s (int32x2_t s, uint8_t amount);
16622uint16x4_t psrlh_u (uint16x4_t s, uint8_t amount);
16623int16x4_t psrlh_s (int16x4_t s, uint8_t amount);
16624uint32x2_t psrlw_u (uint32x2_t s, uint8_t amount);
16625int32x2_t psrlw_s (int32x2_t s, uint8_t amount);
16626uint16x4_t psrah_u (uint16x4_t s, uint8_t amount);
16627int16x4_t psrah_s (int16x4_t s, uint8_t amount);
16628uint32x2_t psraw_u (uint32x2_t s, uint8_t amount);
16629int32x2_t psraw_s (int32x2_t s, uint8_t amount);
16630uint32x2_t psubw_u (uint32x2_t s, uint32x2_t t);
16631uint16x4_t psubh_u (uint16x4_t s, uint16x4_t t);
16632uint8x8_t psubb_u (uint8x8_t s, uint8x8_t t);
16633int32x2_t psubw_s (int32x2_t s, int32x2_t t);
16634int16x4_t psubh_s (int16x4_t s, int16x4_t t);
16635int8x8_t psubb_s (int8x8_t s, int8x8_t t);
16636uint64_t psubd_u (uint64_t s, uint64_t t);
16637int64_t psubd_s (int64_t s, int64_t t);
16638int16x4_t psubsh (int16x4_t s, int16x4_t t);
16639int8x8_t psubsb (int8x8_t s, int8x8_t t);
16640uint16x4_t psubush (uint16x4_t s, uint16x4_t t);
16641uint8x8_t psubusb (uint8x8_t s, uint8x8_t t);
16642uint32x2_t punpckhwd_u (uint32x2_t s, uint32x2_t t);
16643uint16x4_t punpckhhw_u (uint16x4_t s, uint16x4_t t);
16644uint8x8_t punpckhbh_u (uint8x8_t s, uint8x8_t t);
16645int32x2_t punpckhwd_s (int32x2_t s, int32x2_t t);
16646int16x4_t punpckhhw_s (int16x4_t s, int16x4_t t);
16647int8x8_t punpckhbh_s (int8x8_t s, int8x8_t t);
16648uint32x2_t punpcklwd_u (uint32x2_t s, uint32x2_t t);
16649uint16x4_t punpcklhw_u (uint16x4_t s, uint16x4_t t);
16650uint8x8_t punpcklbh_u (uint8x8_t s, uint8x8_t t);
16651int32x2_t punpcklwd_s (int32x2_t s, int32x2_t t);
16652int16x4_t punpcklhw_s (int16x4_t s, int16x4_t t);
16653int8x8_t punpcklbh_s (int8x8_t s, int8x8_t t);
16654@end smallexample
16655
16656@menu
16657* Paired-Single Arithmetic::
16658* Paired-Single Built-in Functions::
16659* MIPS-3D Built-in Functions::
16660@end menu
16661
16662@node Paired-Single Arithmetic
16663@subsubsection Paired-Single Arithmetic
16664
16665The table below lists the @code{v2sf} operations for which hardware
16666support exists. @code{a}, @code{b} and @code{c} are @code{v2sf}
16667values and @code{x} is an integral value.
16668
16669@multitable @columnfractions .50 .50
16670@headitem C code @tab MIPS instruction
16671@item @code{a + b} @tab @code{add.ps}
16672@item @code{a - b} @tab @code{sub.ps}
16673@item @code{-a} @tab @code{neg.ps}
16674@item @code{a * b} @tab @code{mul.ps}
16675@item @code{a * b + c} @tab @code{madd.ps}
16676@item @code{a * b - c} @tab @code{msub.ps}
16677@item @code{-(a * b + c)} @tab @code{nmadd.ps}
16678@item @code{-(a * b - c)} @tab @code{nmsub.ps}
16679@item @code{x ? a : b} @tab @code{movn.ps}/@code{movz.ps}
16680@end multitable
16681
16682Note that the multiply-accumulate instructions can be disabled
16683using the command-line option @code{-mno-fused-madd}.
16684
16685@node Paired-Single Built-in Functions
16686@subsubsection Paired-Single Built-in Functions
16687
16688The following paired-single functions map directly to a particular
16689MIPS instruction. Please refer to the architecture specification
16690for details on what each instruction does.
16691
16692@table @code
16693@item v2sf __builtin_mips_pll_ps (v2sf, v2sf)
16694Pair lower lower (@code{pll.ps}).
16695
16696@item v2sf __builtin_mips_pul_ps (v2sf, v2sf)
16697Pair upper lower (@code{pul.ps}).
16698
16699@item v2sf __builtin_mips_plu_ps (v2sf, v2sf)
16700Pair lower upper (@code{plu.ps}).
16701
16702@item v2sf __builtin_mips_puu_ps (v2sf, v2sf)
16703Pair upper upper (@code{puu.ps}).
16704
16705@item v2sf __builtin_mips_cvt_ps_s (float, float)
16706Convert pair to paired single (@code{cvt.ps.s}).
16707
16708@item float __builtin_mips_cvt_s_pl (v2sf)
16709Convert pair lower to single (@code{cvt.s.pl}).
16710
16711@item float __builtin_mips_cvt_s_pu (v2sf)
16712Convert pair upper to single (@code{cvt.s.pu}).
16713
16714@item v2sf __builtin_mips_abs_ps (v2sf)
16715Absolute value (@code{abs.ps}).
16716
16717@item v2sf __builtin_mips_alnv_ps (v2sf, v2sf, int)
16718Align variable (@code{alnv.ps}).
16719
16720@emph{Note:} The value of the third parameter must be 0 or 4
16721modulo 8, otherwise the result is unpredictable. Please read the
16722instruction description for details.
16723@end table
16724
16725The following multi-instruction functions are also available.
16726In each case, @var{cond} can be any of the 16 floating-point conditions:
16727@code{f}, @code{un}, @code{eq}, @code{ueq}, @code{olt}, @code{ult},
16728@code{ole}, @code{ule}, @code{sf}, @code{ngle}, @code{seq}, @code{ngl},
16729@code{lt}, @code{nge}, @code{le} or @code{ngt}.
16730
16731@table @code
16732@item v2sf __builtin_mips_movt_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
16733@itemx v2sf __builtin_mips_movf_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
16734Conditional move based on floating-point comparison (@code{c.@var{cond}.ps},
16735@code{movt.ps}/@code{movf.ps}).
16736
16737The @code{movt} functions return the value @var{x} computed by:
16738
16739@smallexample
16740c.@var{cond}.ps @var{cc},@var{a},@var{b}
16741mov.ps @var{x},@var{c}
16742movt.ps @var{x},@var{d},@var{cc}
16743@end smallexample
16744
16745The @code{movf} functions are similar but use @code{movf.ps} instead
16746of @code{movt.ps}.
16747
16748@item int __builtin_mips_upper_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
16749@itemx int __builtin_mips_lower_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
16750Comparison of two paired-single values (@code{c.@var{cond}.ps},
16751@code{bc1t}/@code{bc1f}).
16752
16753These functions compare @var{a} and @var{b} using @code{c.@var{cond}.ps}
16754and return either the upper or lower half of the result. For example:
16755
16756@smallexample
16757v2sf a, b;
16758if (__builtin_mips_upper_c_eq_ps (a, b))
16759 upper_halves_are_equal ();
16760else
16761 upper_halves_are_unequal ();
16762
16763if (__builtin_mips_lower_c_eq_ps (a, b))
16764 lower_halves_are_equal ();
16765else
16766 lower_halves_are_unequal ();
16767@end smallexample
16768@end table
16769
16770@node MIPS-3D Built-in Functions
16771@subsubsection MIPS-3D Built-in Functions
16772
16773The MIPS-3D Application-Specific Extension (ASE) includes additional
16774paired-single instructions that are designed to improve the performance
16775of 3D graphics operations. Support for these instructions is controlled
16776by the @option{-mips3d} command-line option.
16777
16778The functions listed below map directly to a particular MIPS-3D
16779instruction. Please refer to the architecture specification for
16780more details on what each instruction does.
16781
16782@table @code
16783@item v2sf __builtin_mips_addr_ps (v2sf, v2sf)
16784Reduction add (@code{addr.ps}).
16785
16786@item v2sf __builtin_mips_mulr_ps (v2sf, v2sf)
16787Reduction multiply (@code{mulr.ps}).
16788
16789@item v2sf __builtin_mips_cvt_pw_ps (v2sf)
16790Convert paired single to paired word (@code{cvt.pw.ps}).
16791
16792@item v2sf __builtin_mips_cvt_ps_pw (v2sf)
16793Convert paired word to paired single (@code{cvt.ps.pw}).
16794
16795@item float __builtin_mips_recip1_s (float)
16796@itemx double __builtin_mips_recip1_d (double)
16797@itemx v2sf __builtin_mips_recip1_ps (v2sf)
16798Reduced-precision reciprocal (sequence step 1) (@code{recip1.@var{fmt}}).
16799
16800@item float __builtin_mips_recip2_s (float, float)
16801@itemx double __builtin_mips_recip2_d (double, double)
16802@itemx v2sf __builtin_mips_recip2_ps (v2sf, v2sf)
16803Reduced-precision reciprocal (sequence step 2) (@code{recip2.@var{fmt}}).
16804
16805@item float __builtin_mips_rsqrt1_s (float)
16806@itemx double __builtin_mips_rsqrt1_d (double)
16807@itemx v2sf __builtin_mips_rsqrt1_ps (v2sf)
16808Reduced-precision reciprocal square root (sequence step 1)
16809(@code{rsqrt1.@var{fmt}}).
16810
16811@item float __builtin_mips_rsqrt2_s (float, float)
16812@itemx double __builtin_mips_rsqrt2_d (double, double)
16813@itemx v2sf __builtin_mips_rsqrt2_ps (v2sf, v2sf)
16814Reduced-precision reciprocal square root (sequence step 2)
16815(@code{rsqrt2.@var{fmt}}).
16816@end table
16817
16818The following multi-instruction functions are also available.
16819In each case, @var{cond} can be any of the 16 floating-point conditions:
16820@code{f}, @code{un}, @code{eq}, @code{ueq}, @code{olt}, @code{ult},
16821@code{ole}, @code{ule}, @code{sf}, @code{ngle}, @code{seq},
16822@code{ngl}, @code{lt}, @code{nge}, @code{le} or @code{ngt}.
16823
16824@table @code
16825@item int __builtin_mips_cabs_@var{cond}_s (float @var{a}, float @var{b})
16826@itemx int __builtin_mips_cabs_@var{cond}_d (double @var{a}, double @var{b})
16827Absolute comparison of two scalar values (@code{cabs.@var{cond}.@var{fmt}},
16828@code{bc1t}/@code{bc1f}).
16829
16830These functions compare @var{a} and @var{b} using @code{cabs.@var{cond}.s}
16831or @code{cabs.@var{cond}.d} and return the result as a boolean value.
16832For example:
16833
16834@smallexample
16835float a, b;
16836if (__builtin_mips_cabs_eq_s (a, b))
16837 true ();
16838else
16839 false ();
16840@end smallexample
16841
16842@item int __builtin_mips_upper_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
16843@itemx int __builtin_mips_lower_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
16844Absolute comparison of two paired-single values (@code{cabs.@var{cond}.ps},
16845@code{bc1t}/@code{bc1f}).
16846
16847These functions compare @var{a} and @var{b} using @code{cabs.@var{cond}.ps}
16848and return either the upper or lower half of the result. For example:
16849
16850@smallexample
16851v2sf a, b;
16852if (__builtin_mips_upper_cabs_eq_ps (a, b))
16853 upper_halves_are_equal ();
16854else
16855 upper_halves_are_unequal ();
16856
16857if (__builtin_mips_lower_cabs_eq_ps (a, b))
16858 lower_halves_are_equal ();
16859else
16860 lower_halves_are_unequal ();
16861@end smallexample
16862
16863@item v2sf __builtin_mips_movt_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
16864@itemx v2sf __builtin_mips_movf_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
16865Conditional move based on absolute comparison (@code{cabs.@var{cond}.ps},
16866@code{movt.ps}/@code{movf.ps}).
16867
16868The @code{movt} functions return the value @var{x} computed by:
16869
16870@smallexample
16871cabs.@var{cond}.ps @var{cc},@var{a},@var{b}
16872mov.ps @var{x},@var{c}
16873movt.ps @var{x},@var{d},@var{cc}
16874@end smallexample
16875
16876The @code{movf} functions are similar but use @code{movf.ps} instead
16877of @code{movt.ps}.
16878
16879@item int __builtin_mips_any_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
16880@itemx int __builtin_mips_all_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
16881@itemx int __builtin_mips_any_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
16882@itemx int __builtin_mips_all_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
16883Comparison of two paired-single values
16884(@code{c.@var{cond}.ps}/@code{cabs.@var{cond}.ps},
16885@code{bc1any2t}/@code{bc1any2f}).
16886
16887These functions compare @var{a} and @var{b} using @code{c.@var{cond}.ps}
16888or @code{cabs.@var{cond}.ps}. The @code{any} forms return @code{true} if either
16889result is @code{true} and the @code{all} forms return @code{true} if both results are @code{true}.
16890For example:
16891
16892@smallexample
16893v2sf a, b;
16894if (__builtin_mips_any_c_eq_ps (a, b))
16895 one_is_true ();
16896else
16897 both_are_false ();
16898
16899if (__builtin_mips_all_c_eq_ps (a, b))
16900 both_are_true ();
16901else
16902 one_is_false ();
16903@end smallexample
16904
16905@item int __builtin_mips_any_c_@var{cond}_4s (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
16906@itemx int __builtin_mips_all_c_@var{cond}_4s (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
16907@itemx int __builtin_mips_any_cabs_@var{cond}_4s (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
16908@itemx int __builtin_mips_all_cabs_@var{cond}_4s (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
16909Comparison of four paired-single values
16910(@code{c.@var{cond}.ps}/@code{cabs.@var{cond}.ps},
16911@code{bc1any4t}/@code{bc1any4f}).
16912
16913These functions use @code{c.@var{cond}.ps} or @code{cabs.@var{cond}.ps}
16914to compare @var{a} with @var{b} and to compare @var{c} with @var{d}.
16915The @code{any} forms return @code{true} if any of the four results are @code{true}
16916and the @code{all} forms return @code{true} if all four results are @code{true}.
16917For example:
16918
16919@smallexample
16920v2sf a, b, c, d;
16921if (__builtin_mips_any_c_eq_4s (a, b, c, d))
16922 some_are_true ();
16923else
16924 all_are_false ();
16925
16926if (__builtin_mips_all_c_eq_4s (a, b, c, d))
16927 all_are_true ();
16928else
16929 some_are_false ();
16930@end smallexample
16931@end table
16932
16933@node MIPS SIMD Architecture (MSA) Support
16934@subsection MIPS SIMD Architecture (MSA) Support
16935
16936@menu
16937* MIPS SIMD Architecture Built-in Functions::
16938@end menu
16939
16940GCC provides intrinsics to access the SIMD instructions provided by the
16941MSA MIPS SIMD Architecture. The interface is made available by including
16942@code{<msa.h>} and using @option{-mmsa -mhard-float -mfp64 -mnan=2008}.
16943For each @code{__builtin_msa_*}, there is a shortened name of the intrinsic,
16944@code{__msa_*}.
16945
16946MSA implements 128-bit wide vector registers, operating on 8-, 16-, 32- and
1694764-bit integer, 16- and 32-bit fixed-point, or 32- and 64-bit floating point
16948data elements. The following vectors typedefs are included in @code{msa.h}:
16949@itemize
16950@item @code{v16i8}, a vector of sixteen signed 8-bit integers;
16951@item @code{v16u8}, a vector of sixteen unsigned 8-bit integers;
16952@item @code{v8i16}, a vector of eight signed 16-bit integers;
16953@item @code{v8u16}, a vector of eight unsigned 16-bit integers;
16954@item @code{v4i32}, a vector of four signed 32-bit integers;
16955@item @code{v4u32}, a vector of four unsigned 32-bit integers;
16956@item @code{v2i64}, a vector of two signed 64-bit integers;
16957@item @code{v2u64}, a vector of two unsigned 64-bit integers;
16958@item @code{v4f32}, a vector of four 32-bit floats;
16959@item @code{v2f64}, a vector of two 64-bit doubles.
16960@end itemize
16961
16962Instructions and corresponding built-ins may have additional restrictions and/or
16963input/output values manipulated:
16964@itemize
16965@item @code{imm0_1}, an integer literal in range 0 to 1;
16966@item @code{imm0_3}, an integer literal in range 0 to 3;
16967@item @code{imm0_7}, an integer literal in range 0 to 7;
16968@item @code{imm0_15}, an integer literal in range 0 to 15;
16969@item @code{imm0_31}, an integer literal in range 0 to 31;
16970@item @code{imm0_63}, an integer literal in range 0 to 63;
16971@item @code{imm0_255}, an integer literal in range 0 to 255;
16972@item @code{imm_n16_15}, an integer literal in range -16 to 15;
16973@item @code{imm_n512_511}, an integer literal in range -512 to 511;
16974@item @code{imm_n1024_1022}, an integer literal in range -512 to 511 left
16975shifted by 1 bit, i.e., -1024, -1022, @dots{}, 1020, 1022;
16976@item @code{imm_n2048_2044}, an integer literal in range -512 to 511 left
16977shifted by 2 bits, i.e., -2048, -2044, @dots{}, 2040, 2044;
16978@item @code{imm_n4096_4088}, an integer literal in range -512 to 511 left
16979shifted by 3 bits, i.e., -4096, -4088, @dots{}, 4080, 4088;
16980@item @code{imm1_4}, an integer literal in range 1 to 4;
16981@item @code{i32, i64, u32, u64, f32, f64}, defined as follows:
16982@end itemize
16983
16984@smallexample
16985@{
16986typedef int i32;
16987#if __LONG_MAX__ == __LONG_LONG_MAX__
16988typedef long i64;
16989#else
16990typedef long long i64;
16991#endif
16992
16993typedef unsigned int u32;
16994#if __LONG_MAX__ == __LONG_LONG_MAX__
16995typedef unsigned long u64;
16996#else
16997typedef unsigned long long u64;
16998#endif
16999
17000typedef double f64;
17001typedef float f32;
17002@}
17003@end smallexample
17004
17005@node MIPS SIMD Architecture Built-in Functions
17006@subsubsection MIPS SIMD Architecture Built-in Functions
17007
17008The intrinsics provided are listed below; each is named after the
17009machine instruction.
17010
17011@smallexample
17012v16i8 __builtin_msa_add_a_b (v16i8, v16i8);
17013v8i16 __builtin_msa_add_a_h (v8i16, v8i16);
17014v4i32 __builtin_msa_add_a_w (v4i32, v4i32);
17015v2i64 __builtin_msa_add_a_d (v2i64, v2i64);
17016
17017v16i8 __builtin_msa_adds_a_b (v16i8, v16i8);
17018v8i16 __builtin_msa_adds_a_h (v8i16, v8i16);
17019v4i32 __builtin_msa_adds_a_w (v4i32, v4i32);
17020v2i64 __builtin_msa_adds_a_d (v2i64, v2i64);
17021
17022v16i8 __builtin_msa_adds_s_b (v16i8, v16i8);
17023v8i16 __builtin_msa_adds_s_h (v8i16, v8i16);
17024v4i32 __builtin_msa_adds_s_w (v4i32, v4i32);
17025v2i64 __builtin_msa_adds_s_d (v2i64, v2i64);
17026
17027v16u8 __builtin_msa_adds_u_b (v16u8, v16u8);
17028v8u16 __builtin_msa_adds_u_h (v8u16, v8u16);
17029v4u32 __builtin_msa_adds_u_w (v4u32, v4u32);
17030v2u64 __builtin_msa_adds_u_d (v2u64, v2u64);
17031
17032v16i8 __builtin_msa_addv_b (v16i8, v16i8);
17033v8i16 __builtin_msa_addv_h (v8i16, v8i16);
17034v4i32 __builtin_msa_addv_w (v4i32, v4i32);
17035v2i64 __builtin_msa_addv_d (v2i64, v2i64);
17036
17037v16i8 __builtin_msa_addvi_b (v16i8, imm0_31);
17038v8i16 __builtin_msa_addvi_h (v8i16, imm0_31);
17039v4i32 __builtin_msa_addvi_w (v4i32, imm0_31);
17040v2i64 __builtin_msa_addvi_d (v2i64, imm0_31);
17041
17042v16u8 __builtin_msa_and_v (v16u8, v16u8);
17043
17044v16u8 __builtin_msa_andi_b (v16u8, imm0_255);
17045
17046v16i8 __builtin_msa_asub_s_b (v16i8, v16i8);
17047v8i16 __builtin_msa_asub_s_h (v8i16, v8i16);
17048v4i32 __builtin_msa_asub_s_w (v4i32, v4i32);
17049v2i64 __builtin_msa_asub_s_d (v2i64, v2i64);
17050
17051v16u8 __builtin_msa_asub_u_b (v16u8, v16u8);
17052v8u16 __builtin_msa_asub_u_h (v8u16, v8u16);
17053v4u32 __builtin_msa_asub_u_w (v4u32, v4u32);
17054v2u64 __builtin_msa_asub_u_d (v2u64, v2u64);
17055
17056v16i8 __builtin_msa_ave_s_b (v16i8, v16i8);
17057v8i16 __builtin_msa_ave_s_h (v8i16, v8i16);
17058v4i32 __builtin_msa_ave_s_w (v4i32, v4i32);
17059v2i64 __builtin_msa_ave_s_d (v2i64, v2i64);
17060
17061v16u8 __builtin_msa_ave_u_b (v16u8, v16u8);
17062v8u16 __builtin_msa_ave_u_h (v8u16, v8u16);
17063v4u32 __builtin_msa_ave_u_w (v4u32, v4u32);
17064v2u64 __builtin_msa_ave_u_d (v2u64, v2u64);
17065
17066v16i8 __builtin_msa_aver_s_b (v16i8, v16i8);
17067v8i16 __builtin_msa_aver_s_h (v8i16, v8i16);
17068v4i32 __builtin_msa_aver_s_w (v4i32, v4i32);
17069v2i64 __builtin_msa_aver_s_d (v2i64, v2i64);
17070
17071v16u8 __builtin_msa_aver_u_b (v16u8, v16u8);
17072v8u16 __builtin_msa_aver_u_h (v8u16, v8u16);
17073v4u32 __builtin_msa_aver_u_w (v4u32, v4u32);
17074v2u64 __builtin_msa_aver_u_d (v2u64, v2u64);
17075
17076v16u8 __builtin_msa_bclr_b (v16u8, v16u8);
17077v8u16 __builtin_msa_bclr_h (v8u16, v8u16);
17078v4u32 __builtin_msa_bclr_w (v4u32, v4u32);
17079v2u64 __builtin_msa_bclr_d (v2u64, v2u64);
17080
17081v16u8 __builtin_msa_bclri_b (v16u8, imm0_7);
17082v8u16 __builtin_msa_bclri_h (v8u16, imm0_15);
17083v4u32 __builtin_msa_bclri_w (v4u32, imm0_31);
17084v2u64 __builtin_msa_bclri_d (v2u64, imm0_63);
17085
17086v16u8 __builtin_msa_binsl_b (v16u8, v16u8, v16u8);
17087v8u16 __builtin_msa_binsl_h (v8u16, v8u16, v8u16);
17088v4u32 __builtin_msa_binsl_w (v4u32, v4u32, v4u32);
17089v2u64 __builtin_msa_binsl_d (v2u64, v2u64, v2u64);
17090
17091v16u8 __builtin_msa_binsli_b (v16u8, v16u8, imm0_7);
17092v8u16 __builtin_msa_binsli_h (v8u16, v8u16, imm0_15);
17093v4u32 __builtin_msa_binsli_w (v4u32, v4u32, imm0_31);
17094v2u64 __builtin_msa_binsli_d (v2u64, v2u64, imm0_63);
17095
17096v16u8 __builtin_msa_binsr_b (v16u8, v16u8, v16u8);
17097v8u16 __builtin_msa_binsr_h (v8u16, v8u16, v8u16);
17098v4u32 __builtin_msa_binsr_w (v4u32, v4u32, v4u32);
17099v2u64 __builtin_msa_binsr_d (v2u64, v2u64, v2u64);
17100
17101v16u8 __builtin_msa_binsri_b (v16u8, v16u8, imm0_7);
17102v8u16 __builtin_msa_binsri_h (v8u16, v8u16, imm0_15);
17103v4u32 __builtin_msa_binsri_w (v4u32, v4u32, imm0_31);
17104v2u64 __builtin_msa_binsri_d (v2u64, v2u64, imm0_63);
17105
17106v16u8 __builtin_msa_bmnz_v (v16u8, v16u8, v16u8);
17107
17108v16u8 __builtin_msa_bmnzi_b (v16u8, v16u8, imm0_255);
17109
17110v16u8 __builtin_msa_bmz_v (v16u8, v16u8, v16u8);
17111
17112v16u8 __builtin_msa_bmzi_b (v16u8, v16u8, imm0_255);
17113
17114v16u8 __builtin_msa_bneg_b (v16u8, v16u8);
17115v8u16 __builtin_msa_bneg_h (v8u16, v8u16);
17116v4u32 __builtin_msa_bneg_w (v4u32, v4u32);
17117v2u64 __builtin_msa_bneg_d (v2u64, v2u64);
17118
17119v16u8 __builtin_msa_bnegi_b (v16u8, imm0_7);
17120v8u16 __builtin_msa_bnegi_h (v8u16, imm0_15);
17121v4u32 __builtin_msa_bnegi_w (v4u32, imm0_31);
17122v2u64 __builtin_msa_bnegi_d (v2u64, imm0_63);
17123
17124i32 __builtin_msa_bnz_b (v16u8);
17125i32 __builtin_msa_bnz_h (v8u16);
17126i32 __builtin_msa_bnz_w (v4u32);
17127i32 __builtin_msa_bnz_d (v2u64);
17128
17129i32 __builtin_msa_bnz_v (v16u8);
17130
17131v16u8 __builtin_msa_bsel_v (v16u8, v16u8, v16u8);
17132
17133v16u8 __builtin_msa_bseli_b (v16u8, v16u8, imm0_255);
17134
17135v16u8 __builtin_msa_bset_b (v16u8, v16u8);
17136v8u16 __builtin_msa_bset_h (v8u16, v8u16);
17137v4u32 __builtin_msa_bset_w (v4u32, v4u32);
17138v2u64 __builtin_msa_bset_d (v2u64, v2u64);
17139
17140v16u8 __builtin_msa_bseti_b (v16u8, imm0_7);
17141v8u16 __builtin_msa_bseti_h (v8u16, imm0_15);
17142v4u32 __builtin_msa_bseti_w (v4u32, imm0_31);
17143v2u64 __builtin_msa_bseti_d (v2u64, imm0_63);
17144
17145i32 __builtin_msa_bz_b (v16u8);
17146i32 __builtin_msa_bz_h (v8u16);
17147i32 __builtin_msa_bz_w (v4u32);
17148i32 __builtin_msa_bz_d (v2u64);
17149
17150i32 __builtin_msa_bz_v (v16u8);
17151
17152v16i8 __builtin_msa_ceq_b (v16i8, v16i8);
17153v8i16 __builtin_msa_ceq_h (v8i16, v8i16);
17154v4i32 __builtin_msa_ceq_w (v4i32, v4i32);
17155v2i64 __builtin_msa_ceq_d (v2i64, v2i64);
17156
17157v16i8 __builtin_msa_ceqi_b (v16i8, imm_n16_15);
17158v8i16 __builtin_msa_ceqi_h (v8i16, imm_n16_15);
17159v4i32 __builtin_msa_ceqi_w (v4i32, imm_n16_15);
17160v2i64 __builtin_msa_ceqi_d (v2i64, imm_n16_15);
17161
17162i32 __builtin_msa_cfcmsa (imm0_31);
17163
17164v16i8 __builtin_msa_cle_s_b (v16i8, v16i8);
17165v8i16 __builtin_msa_cle_s_h (v8i16, v8i16);
17166v4i32 __builtin_msa_cle_s_w (v4i32, v4i32);
17167v2i64 __builtin_msa_cle_s_d (v2i64, v2i64);
17168
17169v16i8 __builtin_msa_cle_u_b (v16u8, v16u8);
17170v8i16 __builtin_msa_cle_u_h (v8u16, v8u16);
17171v4i32 __builtin_msa_cle_u_w (v4u32, v4u32);
17172v2i64 __builtin_msa_cle_u_d (v2u64, v2u64);
17173
17174v16i8 __builtin_msa_clei_s_b (v16i8, imm_n16_15);
17175v8i16 __builtin_msa_clei_s_h (v8i16, imm_n16_15);
17176v4i32 __builtin_msa_clei_s_w (v4i32, imm_n16_15);
17177v2i64 __builtin_msa_clei_s_d (v2i64, imm_n16_15);
17178
17179v16i8 __builtin_msa_clei_u_b (v16u8, imm0_31);
17180v8i16 __builtin_msa_clei_u_h (v8u16, imm0_31);
17181v4i32 __builtin_msa_clei_u_w (v4u32, imm0_31);
17182v2i64 __builtin_msa_clei_u_d (v2u64, imm0_31);
17183
17184v16i8 __builtin_msa_clt_s_b (v16i8, v16i8);
17185v8i16 __builtin_msa_clt_s_h (v8i16, v8i16);
17186v4i32 __builtin_msa_clt_s_w (v4i32, v4i32);
17187v2i64 __builtin_msa_clt_s_d (v2i64, v2i64);
17188
17189v16i8 __builtin_msa_clt_u_b (v16u8, v16u8);
17190v8i16 __builtin_msa_clt_u_h (v8u16, v8u16);
17191v4i32 __builtin_msa_clt_u_w (v4u32, v4u32);
17192v2i64 __builtin_msa_clt_u_d (v2u64, v2u64);
17193
17194v16i8 __builtin_msa_clti_s_b (v16i8, imm_n16_15);
17195v8i16 __builtin_msa_clti_s_h (v8i16, imm_n16_15);
17196v4i32 __builtin_msa_clti_s_w (v4i32, imm_n16_15);
17197v2i64 __builtin_msa_clti_s_d (v2i64, imm_n16_15);
17198
17199v16i8 __builtin_msa_clti_u_b (v16u8, imm0_31);
17200v8i16 __builtin_msa_clti_u_h (v8u16, imm0_31);
17201v4i32 __builtin_msa_clti_u_w (v4u32, imm0_31);
17202v2i64 __builtin_msa_clti_u_d (v2u64, imm0_31);
17203
17204i32 __builtin_msa_copy_s_b (v16i8, imm0_15);
17205i32 __builtin_msa_copy_s_h (v8i16, imm0_7);
17206i32 __builtin_msa_copy_s_w (v4i32, imm0_3);
17207i64 __builtin_msa_copy_s_d (v2i64, imm0_1);
17208
17209u32 __builtin_msa_copy_u_b (v16i8, imm0_15);
17210u32 __builtin_msa_copy_u_h (v8i16, imm0_7);
17211u32 __builtin_msa_copy_u_w (v4i32, imm0_3);
17212u64 __builtin_msa_copy_u_d (v2i64, imm0_1);
17213
17214void __builtin_msa_ctcmsa (imm0_31, i32);
17215
17216v16i8 __builtin_msa_div_s_b (v16i8, v16i8);
17217v8i16 __builtin_msa_div_s_h (v8i16, v8i16);
17218v4i32 __builtin_msa_div_s_w (v4i32, v4i32);
17219v2i64 __builtin_msa_div_s_d (v2i64, v2i64);
17220
17221v16u8 __builtin_msa_div_u_b (v16u8, v16u8);
17222v8u16 __builtin_msa_div_u_h (v8u16, v8u16);
17223v4u32 __builtin_msa_div_u_w (v4u32, v4u32);
17224v2u64 __builtin_msa_div_u_d (v2u64, v2u64);
17225
17226v8i16 __builtin_msa_dotp_s_h (v16i8, v16i8);
17227v4i32 __builtin_msa_dotp_s_w (v8i16, v8i16);
17228v2i64 __builtin_msa_dotp_s_d (v4i32, v4i32);
17229
17230v8u16 __builtin_msa_dotp_u_h (v16u8, v16u8);
17231v4u32 __builtin_msa_dotp_u_w (v8u16, v8u16);
17232v2u64 __builtin_msa_dotp_u_d (v4u32, v4u32);
17233
17234v8i16 __builtin_msa_dpadd_s_h (v8i16, v16i8, v16i8);
17235v4i32 __builtin_msa_dpadd_s_w (v4i32, v8i16, v8i16);
17236v2i64 __builtin_msa_dpadd_s_d (v2i64, v4i32, v4i32);
17237
17238v8u16 __builtin_msa_dpadd_u_h (v8u16, v16u8, v16u8);
17239v4u32 __builtin_msa_dpadd_u_w (v4u32, v8u16, v8u16);
17240v2u64 __builtin_msa_dpadd_u_d (v2u64, v4u32, v4u32);
17241
17242v8i16 __builtin_msa_dpsub_s_h (v8i16, v16i8, v16i8);
17243v4i32 __builtin_msa_dpsub_s_w (v4i32, v8i16, v8i16);
17244v2i64 __builtin_msa_dpsub_s_d (v2i64, v4i32, v4i32);
17245
17246v8i16 __builtin_msa_dpsub_u_h (v8i16, v16u8, v16u8);
17247v4i32 __builtin_msa_dpsub_u_w (v4i32, v8u16, v8u16);
17248v2i64 __builtin_msa_dpsub_u_d (v2i64, v4u32, v4u32);
17249
17250v4f32 __builtin_msa_fadd_w (v4f32, v4f32);
17251v2f64 __builtin_msa_fadd_d (v2f64, v2f64);
17252
17253v4i32 __builtin_msa_fcaf_w (v4f32, v4f32);
17254v2i64 __builtin_msa_fcaf_d (v2f64, v2f64);
17255
17256v4i32 __builtin_msa_fceq_w (v4f32, v4f32);
17257v2i64 __builtin_msa_fceq_d (v2f64, v2f64);
17258
17259v4i32 __builtin_msa_fclass_w (v4f32);
17260v2i64 __builtin_msa_fclass_d (v2f64);
17261
17262v4i32 __builtin_msa_fcle_w (v4f32, v4f32);
17263v2i64 __builtin_msa_fcle_d (v2f64, v2f64);
17264
17265v4i32 __builtin_msa_fclt_w (v4f32, v4f32);
17266v2i64 __builtin_msa_fclt_d (v2f64, v2f64);
17267
17268v4i32 __builtin_msa_fcne_w (v4f32, v4f32);
17269v2i64 __builtin_msa_fcne_d (v2f64, v2f64);
17270
17271v4i32 __builtin_msa_fcor_w (v4f32, v4f32);
17272v2i64 __builtin_msa_fcor_d (v2f64, v2f64);
17273
17274v4i32 __builtin_msa_fcueq_w (v4f32, v4f32);
17275v2i64 __builtin_msa_fcueq_d (v2f64, v2f64);
17276
17277v4i32 __builtin_msa_fcule_w (v4f32, v4f32);
17278v2i64 __builtin_msa_fcule_d (v2f64, v2f64);
17279
17280v4i32 __builtin_msa_fcult_w (v4f32, v4f32);
17281v2i64 __builtin_msa_fcult_d (v2f64, v2f64);
17282
17283v4i32 __builtin_msa_fcun_w (v4f32, v4f32);
17284v2i64 __builtin_msa_fcun_d (v2f64, v2f64);
17285
17286v4i32 __builtin_msa_fcune_w (v4f32, v4f32);
17287v2i64 __builtin_msa_fcune_d (v2f64, v2f64);
17288
17289v4f32 __builtin_msa_fdiv_w (v4f32, v4f32);
17290v2f64 __builtin_msa_fdiv_d (v2f64, v2f64);
17291
17292v8i16 __builtin_msa_fexdo_h (v4f32, v4f32);
17293v4f32 __builtin_msa_fexdo_w (v2f64, v2f64);
17294
17295v4f32 __builtin_msa_fexp2_w (v4f32, v4i32);
17296v2f64 __builtin_msa_fexp2_d (v2f64, v2i64);
17297
17298v4f32 __builtin_msa_fexupl_w (v8i16);
17299v2f64 __builtin_msa_fexupl_d (v4f32);
17300
17301v4f32 __builtin_msa_fexupr_w (v8i16);
17302v2f64 __builtin_msa_fexupr_d (v4f32);
17303
17304v4f32 __builtin_msa_ffint_s_w (v4i32);
17305v2f64 __builtin_msa_ffint_s_d (v2i64);
17306
17307v4f32 __builtin_msa_ffint_u_w (v4u32);
17308v2f64 __builtin_msa_ffint_u_d (v2u64);
17309
17310v4f32 __builtin_msa_ffql_w (v8i16);
17311v2f64 __builtin_msa_ffql_d (v4i32);
17312
17313v4f32 __builtin_msa_ffqr_w (v8i16);
17314v2f64 __builtin_msa_ffqr_d (v4i32);
17315
17316v16i8 __builtin_msa_fill_b (i32);
17317v8i16 __builtin_msa_fill_h (i32);
17318v4i32 __builtin_msa_fill_w (i32);
17319v2i64 __builtin_msa_fill_d (i64);
17320
17321v4f32 __builtin_msa_flog2_w (v4f32);
17322v2f64 __builtin_msa_flog2_d (v2f64);
17323
17324v4f32 __builtin_msa_fmadd_w (v4f32, v4f32, v4f32);
17325v2f64 __builtin_msa_fmadd_d (v2f64, v2f64, v2f64);
17326
17327v4f32 __builtin_msa_fmax_w (v4f32, v4f32);
17328v2f64 __builtin_msa_fmax_d (v2f64, v2f64);
17329
17330v4f32 __builtin_msa_fmax_a_w (v4f32, v4f32);
17331v2f64 __builtin_msa_fmax_a_d (v2f64, v2f64);
17332
17333v4f32 __builtin_msa_fmin_w (v4f32, v4f32);
17334v2f64 __builtin_msa_fmin_d (v2f64, v2f64);
17335
17336v4f32 __builtin_msa_fmin_a_w (v4f32, v4f32);
17337v2f64 __builtin_msa_fmin_a_d (v2f64, v2f64);
17338
17339v4f32 __builtin_msa_fmsub_w (v4f32, v4f32, v4f32);
17340v2f64 __builtin_msa_fmsub_d (v2f64, v2f64, v2f64);
17341
17342v4f32 __builtin_msa_fmul_w (v4f32, v4f32);
17343v2f64 __builtin_msa_fmul_d (v2f64, v2f64);
17344
17345v4f32 __builtin_msa_frint_w (v4f32);
17346v2f64 __builtin_msa_frint_d (v2f64);
17347
17348v4f32 __builtin_msa_frcp_w (v4f32);
17349v2f64 __builtin_msa_frcp_d (v2f64);
17350
17351v4f32 __builtin_msa_frsqrt_w (v4f32);
17352v2f64 __builtin_msa_frsqrt_d (v2f64);
17353
17354v4i32 __builtin_msa_fsaf_w (v4f32, v4f32);
17355v2i64 __builtin_msa_fsaf_d (v2f64, v2f64);
17356
17357v4i32 __builtin_msa_fseq_w (v4f32, v4f32);
17358v2i64 __builtin_msa_fseq_d (v2f64, v2f64);
17359
17360v4i32 __builtin_msa_fsle_w (v4f32, v4f32);
17361v2i64 __builtin_msa_fsle_d (v2f64, v2f64);
17362
17363v4i32 __builtin_msa_fslt_w (v4f32, v4f32);
17364v2i64 __builtin_msa_fslt_d (v2f64, v2f64);
17365
17366v4i32 __builtin_msa_fsne_w (v4f32, v4f32);
17367v2i64 __builtin_msa_fsne_d (v2f64, v2f64);
17368
17369v4i32 __builtin_msa_fsor_w (v4f32, v4f32);
17370v2i64 __builtin_msa_fsor_d (v2f64, v2f64);
17371
17372v4f32 __builtin_msa_fsqrt_w (v4f32);
17373v2f64 __builtin_msa_fsqrt_d (v2f64);
17374
17375v4f32 __builtin_msa_fsub_w (v4f32, v4f32);
17376v2f64 __builtin_msa_fsub_d (v2f64, v2f64);
17377
17378v4i32 __builtin_msa_fsueq_w (v4f32, v4f32);
17379v2i64 __builtin_msa_fsueq_d (v2f64, v2f64);
17380
17381v4i32 __builtin_msa_fsule_w (v4f32, v4f32);
17382v2i64 __builtin_msa_fsule_d (v2f64, v2f64);
17383
17384v4i32 __builtin_msa_fsult_w (v4f32, v4f32);
17385v2i64 __builtin_msa_fsult_d (v2f64, v2f64);
17386
17387v4i32 __builtin_msa_fsun_w (v4f32, v4f32);
17388v2i64 __builtin_msa_fsun_d (v2f64, v2f64);
17389
17390v4i32 __builtin_msa_fsune_w (v4f32, v4f32);
17391v2i64 __builtin_msa_fsune_d (v2f64, v2f64);
17392
17393v4i32 __builtin_msa_ftint_s_w (v4f32);
17394v2i64 __builtin_msa_ftint_s_d (v2f64);
17395
17396v4u32 __builtin_msa_ftint_u_w (v4f32);
17397v2u64 __builtin_msa_ftint_u_d (v2f64);
17398
17399v8i16 __builtin_msa_ftq_h (v4f32, v4f32);
17400v4i32 __builtin_msa_ftq_w (v2f64, v2f64);
17401
17402v4i32 __builtin_msa_ftrunc_s_w (v4f32);
17403v2i64 __builtin_msa_ftrunc_s_d (v2f64);
17404
17405v4u32 __builtin_msa_ftrunc_u_w (v4f32);
17406v2u64 __builtin_msa_ftrunc_u_d (v2f64);
17407
17408v8i16 __builtin_msa_hadd_s_h (v16i8, v16i8);
17409v4i32 __builtin_msa_hadd_s_w (v8i16, v8i16);
17410v2i64 __builtin_msa_hadd_s_d (v4i32, v4i32);
17411
17412v8u16 __builtin_msa_hadd_u_h (v16u8, v16u8);
17413v4u32 __builtin_msa_hadd_u_w (v8u16, v8u16);
17414v2u64 __builtin_msa_hadd_u_d (v4u32, v4u32);
17415
17416v8i16 __builtin_msa_hsub_s_h (v16i8, v16i8);
17417v4i32 __builtin_msa_hsub_s_w (v8i16, v8i16);
17418v2i64 __builtin_msa_hsub_s_d (v4i32, v4i32);
17419
17420v8i16 __builtin_msa_hsub_u_h (v16u8, v16u8);
17421v4i32 __builtin_msa_hsub_u_w (v8u16, v8u16);
17422v2i64 __builtin_msa_hsub_u_d (v4u32, v4u32);
17423
17424v16i8 __builtin_msa_ilvev_b (v16i8, v16i8);
17425v8i16 __builtin_msa_ilvev_h (v8i16, v8i16);
17426v4i32 __builtin_msa_ilvev_w (v4i32, v4i32);
17427v2i64 __builtin_msa_ilvev_d (v2i64, v2i64);
17428
17429v16i8 __builtin_msa_ilvl_b (v16i8, v16i8);
17430v8i16 __builtin_msa_ilvl_h (v8i16, v8i16);
17431v4i32 __builtin_msa_ilvl_w (v4i32, v4i32);
17432v2i64 __builtin_msa_ilvl_d (v2i64, v2i64);
17433
17434v16i8 __builtin_msa_ilvod_b (v16i8, v16i8);
17435v8i16 __builtin_msa_ilvod_h (v8i16, v8i16);
17436v4i32 __builtin_msa_ilvod_w (v4i32, v4i32);
17437v2i64 __builtin_msa_ilvod_d (v2i64, v2i64);
17438
17439v16i8 __builtin_msa_ilvr_b (v16i8, v16i8);
17440v8i16 __builtin_msa_ilvr_h (v8i16, v8i16);
17441v4i32 __builtin_msa_ilvr_w (v4i32, v4i32);
17442v2i64 __builtin_msa_ilvr_d (v2i64, v2i64);
17443
17444v16i8 __builtin_msa_insert_b (v16i8, imm0_15, i32);
17445v8i16 __builtin_msa_insert_h (v8i16, imm0_7, i32);
17446v4i32 __builtin_msa_insert_w (v4i32, imm0_3, i32);
17447v2i64 __builtin_msa_insert_d (v2i64, imm0_1, i64);
17448
17449v16i8 __builtin_msa_insve_b (v16i8, imm0_15, v16i8);
17450v8i16 __builtin_msa_insve_h (v8i16, imm0_7, v8i16);
17451v4i32 __builtin_msa_insve_w (v4i32, imm0_3, v4i32);
17452v2i64 __builtin_msa_insve_d (v2i64, imm0_1, v2i64);
17453
17454v16i8 __builtin_msa_ld_b (const void *, imm_n512_511);
17455v8i16 __builtin_msa_ld_h (const void *, imm_n1024_1022);
17456v4i32 __builtin_msa_ld_w (const void *, imm_n2048_2044);
17457v2i64 __builtin_msa_ld_d (const void *, imm_n4096_4088);
17458
17459v16i8 __builtin_msa_ldi_b (imm_n512_511);
17460v8i16 __builtin_msa_ldi_h (imm_n512_511);
17461v4i32 __builtin_msa_ldi_w (imm_n512_511);
17462v2i64 __builtin_msa_ldi_d (imm_n512_511);
17463
17464v8i16 __builtin_msa_madd_q_h (v8i16, v8i16, v8i16);
17465v4i32 __builtin_msa_madd_q_w (v4i32, v4i32, v4i32);
17466
17467v8i16 __builtin_msa_maddr_q_h (v8i16, v8i16, v8i16);
17468v4i32 __builtin_msa_maddr_q_w (v4i32, v4i32, v4i32);
17469
17470v16i8 __builtin_msa_maddv_b (v16i8, v16i8, v16i8);
17471v8i16 __builtin_msa_maddv_h (v8i16, v8i16, v8i16);
17472v4i32 __builtin_msa_maddv_w (v4i32, v4i32, v4i32);
17473v2i64 __builtin_msa_maddv_d (v2i64, v2i64, v2i64);
17474
17475v16i8 __builtin_msa_max_a_b (v16i8, v16i8);
17476v8i16 __builtin_msa_max_a_h (v8i16, v8i16);
17477v4i32 __builtin_msa_max_a_w (v4i32, v4i32);
17478v2i64 __builtin_msa_max_a_d (v2i64, v2i64);
17479
17480v16i8 __builtin_msa_max_s_b (v16i8, v16i8);
17481v8i16 __builtin_msa_max_s_h (v8i16, v8i16);
17482v4i32 __builtin_msa_max_s_w (v4i32, v4i32);
17483v2i64 __builtin_msa_max_s_d (v2i64, v2i64);
17484
17485v16u8 __builtin_msa_max_u_b (v16u8, v16u8);
17486v8u16 __builtin_msa_max_u_h (v8u16, v8u16);
17487v4u32 __builtin_msa_max_u_w (v4u32, v4u32);
17488v2u64 __builtin_msa_max_u_d (v2u64, v2u64);
17489
17490v16i8 __builtin_msa_maxi_s_b (v16i8, imm_n16_15);
17491v8i16 __builtin_msa_maxi_s_h (v8i16, imm_n16_15);
17492v4i32 __builtin_msa_maxi_s_w (v4i32, imm_n16_15);
17493v2i64 __builtin_msa_maxi_s_d (v2i64, imm_n16_15);
17494
17495v16u8 __builtin_msa_maxi_u_b (v16u8, imm0_31);
17496v8u16 __builtin_msa_maxi_u_h (v8u16, imm0_31);
17497v4u32 __builtin_msa_maxi_u_w (v4u32, imm0_31);
17498v2u64 __builtin_msa_maxi_u_d (v2u64, imm0_31);
17499
17500v16i8 __builtin_msa_min_a_b (v16i8, v16i8);
17501v8i16 __builtin_msa_min_a_h (v8i16, v8i16);
17502v4i32 __builtin_msa_min_a_w (v4i32, v4i32);
17503v2i64 __builtin_msa_min_a_d (v2i64, v2i64);
17504
17505v16i8 __builtin_msa_min_s_b (v16i8, v16i8);
17506v8i16 __builtin_msa_min_s_h (v8i16, v8i16);
17507v4i32 __builtin_msa_min_s_w (v4i32, v4i32);
17508v2i64 __builtin_msa_min_s_d (v2i64, v2i64);
17509
17510v16u8 __builtin_msa_min_u_b (v16u8, v16u8);
17511v8u16 __builtin_msa_min_u_h (v8u16, v8u16);
17512v4u32 __builtin_msa_min_u_w (v4u32, v4u32);
17513v2u64 __builtin_msa_min_u_d (v2u64, v2u64);
17514
17515v16i8 __builtin_msa_mini_s_b (v16i8, imm_n16_15);
17516v8i16 __builtin_msa_mini_s_h (v8i16, imm_n16_15);
17517v4i32 __builtin_msa_mini_s_w (v4i32, imm_n16_15);
17518v2i64 __builtin_msa_mini_s_d (v2i64, imm_n16_15);
17519
17520v16u8 __builtin_msa_mini_u_b (v16u8, imm0_31);
17521v8u16 __builtin_msa_mini_u_h (v8u16, imm0_31);
17522v4u32 __builtin_msa_mini_u_w (v4u32, imm0_31);
17523v2u64 __builtin_msa_mini_u_d (v2u64, imm0_31);
17524
17525v16i8 __builtin_msa_mod_s_b (v16i8, v16i8);
17526v8i16 __builtin_msa_mod_s_h (v8i16, v8i16);
17527v4i32 __builtin_msa_mod_s_w (v4i32, v4i32);
17528v2i64 __builtin_msa_mod_s_d (v2i64, v2i64);
17529
17530v16u8 __builtin_msa_mod_u_b (v16u8, v16u8);
17531v8u16 __builtin_msa_mod_u_h (v8u16, v8u16);
17532v4u32 __builtin_msa_mod_u_w (v4u32, v4u32);
17533v2u64 __builtin_msa_mod_u_d (v2u64, v2u64);
17534
17535v16i8 __builtin_msa_move_v (v16i8);
17536
17537v8i16 __builtin_msa_msub_q_h (v8i16, v8i16, v8i16);
17538v4i32 __builtin_msa_msub_q_w (v4i32, v4i32, v4i32);
17539
17540v8i16 __builtin_msa_msubr_q_h (v8i16, v8i16, v8i16);
17541v4i32 __builtin_msa_msubr_q_w (v4i32, v4i32, v4i32);
17542
17543v16i8 __builtin_msa_msubv_b (v16i8, v16i8, v16i8);
17544v8i16 __builtin_msa_msubv_h (v8i16, v8i16, v8i16);
17545v4i32 __builtin_msa_msubv_w (v4i32, v4i32, v4i32);
17546v2i64 __builtin_msa_msubv_d (v2i64, v2i64, v2i64);
17547
17548v8i16 __builtin_msa_mul_q_h (v8i16, v8i16);
17549v4i32 __builtin_msa_mul_q_w (v4i32, v4i32);
17550
17551v8i16 __builtin_msa_mulr_q_h (v8i16, v8i16);
17552v4i32 __builtin_msa_mulr_q_w (v4i32, v4i32);
17553
17554v16i8 __builtin_msa_mulv_b (v16i8, v16i8);
17555v8i16 __builtin_msa_mulv_h (v8i16, v8i16);
17556v4i32 __builtin_msa_mulv_w (v4i32, v4i32);
17557v2i64 __builtin_msa_mulv_d (v2i64, v2i64);
17558
17559v16i8 __builtin_msa_nloc_b (v16i8);
17560v8i16 __builtin_msa_nloc_h (v8i16);
17561v4i32 __builtin_msa_nloc_w (v4i32);
17562v2i64 __builtin_msa_nloc_d (v2i64);
17563
17564v16i8 __builtin_msa_nlzc_b (v16i8);
17565v8i16 __builtin_msa_nlzc_h (v8i16);
17566v4i32 __builtin_msa_nlzc_w (v4i32);
17567v2i64 __builtin_msa_nlzc_d (v2i64);
17568
17569v16u8 __builtin_msa_nor_v (v16u8, v16u8);
17570
17571v16u8 __builtin_msa_nori_b (v16u8, imm0_255);
17572
17573v16u8 __builtin_msa_or_v (v16u8, v16u8);
17574
17575v16u8 __builtin_msa_ori_b (v16u8, imm0_255);
17576
17577v16i8 __builtin_msa_pckev_b (v16i8, v16i8);
17578v8i16 __builtin_msa_pckev_h (v8i16, v8i16);
17579v4i32 __builtin_msa_pckev_w (v4i32, v4i32);
17580v2i64 __builtin_msa_pckev_d (v2i64, v2i64);
17581
17582v16i8 __builtin_msa_pckod_b (v16i8, v16i8);
17583v8i16 __builtin_msa_pckod_h (v8i16, v8i16);
17584v4i32 __builtin_msa_pckod_w (v4i32, v4i32);
17585v2i64 __builtin_msa_pckod_d (v2i64, v2i64);
17586
17587v16i8 __builtin_msa_pcnt_b (v16i8);
17588v8i16 __builtin_msa_pcnt_h (v8i16);
17589v4i32 __builtin_msa_pcnt_w (v4i32);
17590v2i64 __builtin_msa_pcnt_d (v2i64);
17591
17592v16i8 __builtin_msa_sat_s_b (v16i8, imm0_7);
17593v8i16 __builtin_msa_sat_s_h (v8i16, imm0_15);
17594v4i32 __builtin_msa_sat_s_w (v4i32, imm0_31);
17595v2i64 __builtin_msa_sat_s_d (v2i64, imm0_63);
17596
17597v16u8 __builtin_msa_sat_u_b (v16u8, imm0_7);
17598v8u16 __builtin_msa_sat_u_h (v8u16, imm0_15);
17599v4u32 __builtin_msa_sat_u_w (v4u32, imm0_31);
17600v2u64 __builtin_msa_sat_u_d (v2u64, imm0_63);
17601
17602v16i8 __builtin_msa_shf_b (v16i8, imm0_255);
17603v8i16 __builtin_msa_shf_h (v8i16, imm0_255);
17604v4i32 __builtin_msa_shf_w (v4i32, imm0_255);
17605
17606v16i8 __builtin_msa_sld_b (v16i8, v16i8, i32);
17607v8i16 __builtin_msa_sld_h (v8i16, v8i16, i32);
17608v4i32 __builtin_msa_sld_w (v4i32, v4i32, i32);
17609v2i64 __builtin_msa_sld_d (v2i64, v2i64, i32);
17610
17611v16i8 __builtin_msa_sldi_b (v16i8, v16i8, imm0_15);
17612v8i16 __builtin_msa_sldi_h (v8i16, v8i16, imm0_7);
17613v4i32 __builtin_msa_sldi_w (v4i32, v4i32, imm0_3);
17614v2i64 __builtin_msa_sldi_d (v2i64, v2i64, imm0_1);
17615
17616v16i8 __builtin_msa_sll_b (v16i8, v16i8);
17617v8i16 __builtin_msa_sll_h (v8i16, v8i16);
17618v4i32 __builtin_msa_sll_w (v4i32, v4i32);
17619v2i64 __builtin_msa_sll_d (v2i64, v2i64);
17620
17621v16i8 __builtin_msa_slli_b (v16i8, imm0_7);
17622v8i16 __builtin_msa_slli_h (v8i16, imm0_15);
17623v4i32 __builtin_msa_slli_w (v4i32, imm0_31);
17624v2i64 __builtin_msa_slli_d (v2i64, imm0_63);
17625
17626v16i8 __builtin_msa_splat_b (v16i8, i32);
17627v8i16 __builtin_msa_splat_h (v8i16, i32);
17628v4i32 __builtin_msa_splat_w (v4i32, i32);
17629v2i64 __builtin_msa_splat_d (v2i64, i32);
17630
17631v16i8 __builtin_msa_splati_b (v16i8, imm0_15);
17632v8i16 __builtin_msa_splati_h (v8i16, imm0_7);
17633v4i32 __builtin_msa_splati_w (v4i32, imm0_3);
17634v2i64 __builtin_msa_splati_d (v2i64, imm0_1);
17635
17636v16i8 __builtin_msa_sra_b (v16i8, v16i8);
17637v8i16 __builtin_msa_sra_h (v8i16, v8i16);
17638v4i32 __builtin_msa_sra_w (v4i32, v4i32);
17639v2i64 __builtin_msa_sra_d (v2i64, v2i64);
17640
17641v16i8 __builtin_msa_srai_b (v16i8, imm0_7);
17642v8i16 __builtin_msa_srai_h (v8i16, imm0_15);
17643v4i32 __builtin_msa_srai_w (v4i32, imm0_31);
17644v2i64 __builtin_msa_srai_d (v2i64, imm0_63);
17645
17646v16i8 __builtin_msa_srar_b (v16i8, v16i8);
17647v8i16 __builtin_msa_srar_h (v8i16, v8i16);
17648v4i32 __builtin_msa_srar_w (v4i32, v4i32);
17649v2i64 __builtin_msa_srar_d (v2i64, v2i64);
17650
17651v16i8 __builtin_msa_srari_b (v16i8, imm0_7);
17652v8i16 __builtin_msa_srari_h (v8i16, imm0_15);
17653v4i32 __builtin_msa_srari_w (v4i32, imm0_31);
17654v2i64 __builtin_msa_srari_d (v2i64, imm0_63);
17655
17656v16i8 __builtin_msa_srl_b (v16i8, v16i8);
17657v8i16 __builtin_msa_srl_h (v8i16, v8i16);
17658v4i32 __builtin_msa_srl_w (v4i32, v4i32);
17659v2i64 __builtin_msa_srl_d (v2i64, v2i64);
17660
17661v16i8 __builtin_msa_srli_b (v16i8, imm0_7);
17662v8i16 __builtin_msa_srli_h (v8i16, imm0_15);
17663v4i32 __builtin_msa_srli_w (v4i32, imm0_31);
17664v2i64 __builtin_msa_srli_d (v2i64, imm0_63);
17665
17666v16i8 __builtin_msa_srlr_b (v16i8, v16i8);
17667v8i16 __builtin_msa_srlr_h (v8i16, v8i16);
17668v4i32 __builtin_msa_srlr_w (v4i32, v4i32);
17669v2i64 __builtin_msa_srlr_d (v2i64, v2i64);
17670
17671v16i8 __builtin_msa_srlri_b (v16i8, imm0_7);
17672v8i16 __builtin_msa_srlri_h (v8i16, imm0_15);
17673v4i32 __builtin_msa_srlri_w (v4i32, imm0_31);
17674v2i64 __builtin_msa_srlri_d (v2i64, imm0_63);
17675
17676void __builtin_msa_st_b (v16i8, void *, imm_n512_511);
17677void __builtin_msa_st_h (v8i16, void *, imm_n1024_1022);
17678void __builtin_msa_st_w (v4i32, void *, imm_n2048_2044);
17679void __builtin_msa_st_d (v2i64, void *, imm_n4096_4088);
17680
17681v16i8 __builtin_msa_subs_s_b (v16i8, v16i8);
17682v8i16 __builtin_msa_subs_s_h (v8i16, v8i16);
17683v4i32 __builtin_msa_subs_s_w (v4i32, v4i32);
17684v2i64 __builtin_msa_subs_s_d (v2i64, v2i64);
17685
17686v16u8 __builtin_msa_subs_u_b (v16u8, v16u8);
17687v8u16 __builtin_msa_subs_u_h (v8u16, v8u16);
17688v4u32 __builtin_msa_subs_u_w (v4u32, v4u32);
17689v2u64 __builtin_msa_subs_u_d (v2u64, v2u64);
17690
17691v16u8 __builtin_msa_subsus_u_b (v16u8, v16i8);
17692v8u16 __builtin_msa_subsus_u_h (v8u16, v8i16);
17693v4u32 __builtin_msa_subsus_u_w (v4u32, v4i32);
17694v2u64 __builtin_msa_subsus_u_d (v2u64, v2i64);
17695
17696v16i8 __builtin_msa_subsuu_s_b (v16u8, v16u8);
17697v8i16 __builtin_msa_subsuu_s_h (v8u16, v8u16);
17698v4i32 __builtin_msa_subsuu_s_w (v4u32, v4u32);
17699v2i64 __builtin_msa_subsuu_s_d (v2u64, v2u64);
17700
17701v16i8 __builtin_msa_subv_b (v16i8, v16i8);
17702v8i16 __builtin_msa_subv_h (v8i16, v8i16);
17703v4i32 __builtin_msa_subv_w (v4i32, v4i32);
17704v2i64 __builtin_msa_subv_d (v2i64, v2i64);
17705
17706v16i8 __builtin_msa_subvi_b (v16i8, imm0_31);
17707v8i16 __builtin_msa_subvi_h (v8i16, imm0_31);
17708v4i32 __builtin_msa_subvi_w (v4i32, imm0_31);
17709v2i64 __builtin_msa_subvi_d (v2i64, imm0_31);
17710
17711v16i8 __builtin_msa_vshf_b (v16i8, v16i8, v16i8);
17712v8i16 __builtin_msa_vshf_h (v8i16, v8i16, v8i16);
17713v4i32 __builtin_msa_vshf_w (v4i32, v4i32, v4i32);
17714v2i64 __builtin_msa_vshf_d (v2i64, v2i64, v2i64);
17715
17716v16u8 __builtin_msa_xor_v (v16u8, v16u8);
17717
17718v16u8 __builtin_msa_xori_b (v16u8, imm0_255);
17719@end smallexample
17720
17721@node Other MIPS Built-in Functions
17722@subsection Other MIPS Built-in Functions
17723
17724GCC provides other MIPS-specific built-in functions:
17725
17726@table @code
17727@item void __builtin_mips_cache (int @var{op}, const volatile void *@var{addr})
17728Insert a @samp{cache} instruction with operands @var{op} and @var{addr}.
17729GCC defines the preprocessor macro @code{___GCC_HAVE_BUILTIN_MIPS_CACHE}
17730when this function is available.
17731
17732@item unsigned int __builtin_mips_get_fcsr (void)
17733@itemx void __builtin_mips_set_fcsr (unsigned int @var{value})
17734Get and set the contents of the floating-point control and status register
17735(FPU control register 31). These functions are only available in hard-float
17736code but can be called in both MIPS16 and non-MIPS16 contexts.
17737
17738@code{__builtin_mips_set_fcsr} can be used to change any bit of the
17739register except the condition codes, which GCC assumes are preserved.
17740@end table
17741
17742@node MSP430 Built-in Functions
17743@subsection MSP430 Built-in Functions
17744
17745GCC provides a couple of special builtin functions to aid in the
17746writing of interrupt handlers in C.
17747
17748@table @code
17749@item __bic_SR_register_on_exit (int @var{mask})
17750This clears the indicated bits in the saved copy of the status register
17751currently residing on the stack. This only works inside interrupt
17752handlers and the changes to the status register will only take affect
17753once the handler returns.
17754
17755@item __bis_SR_register_on_exit (int @var{mask})
17756This sets the indicated bits in the saved copy of the status register
17757currently residing on the stack. This only works inside interrupt
17758handlers and the changes to the status register will only take affect
17759once the handler returns.
17760
17761@item __delay_cycles (long long @var{cycles})
17762This inserts an instruction sequence that takes exactly @var{cycles}
17763cycles (between 0 and about 17E9) to complete. The inserted sequence
17764may use jumps, loops, or no-ops, and does not interfere with any other
17765instructions. Note that @var{cycles} must be a compile-time constant
17766integer - that is, you must pass a number, not a variable that may be
17767optimized to a constant later. The number of cycles delayed by this
17768builtin is exact.
17769@end table
17770
17771@node NDS32 Built-in Functions
17772@subsection NDS32 Built-in Functions
17773
17774These built-in functions are available for the NDS32 target:
17775
f25efe50 17776@defbuiltin{void __builtin_nds32_isync (int *@var{addr})}
d77de738
ML
17777Insert an ISYNC instruction into the instruction stream where
17778@var{addr} is an instruction address for serialization.
f25efe50 17779@enddefbuiltin
d77de738 17780
f25efe50 17781@defbuiltin{void __builtin_nds32_isb (void)}
d77de738 17782Insert an ISB instruction into the instruction stream.
f25efe50 17783@enddefbuiltin
d77de738 17784
f25efe50 17785@defbuiltin{int __builtin_nds32_mfsr (int @var{sr})}
d77de738 17786Return the content of a system register which is mapped by @var{sr}.
f25efe50 17787@enddefbuiltin
d77de738 17788
f25efe50 17789@defbuiltin{int __builtin_nds32_mfusr (int @var{usr})}
d77de738 17790Return the content of a user space register which is mapped by @var{usr}.
f25efe50 17791@enddefbuiltin
d77de738 17792
f25efe50 17793@defbuiltin{void __builtin_nds32_mtsr (int @var{value}, int @var{sr})}
d77de738 17794Move the @var{value} to a system register which is mapped by @var{sr}.
f25efe50 17795@enddefbuiltin
d77de738 17796
f25efe50 17797@defbuiltin{void __builtin_nds32_mtusr (int @var{value}, int @var{usr})}
d77de738 17798Move the @var{value} to a user space register which is mapped by @var{usr}.
f25efe50 17799@enddefbuiltin
d77de738 17800
f25efe50 17801@defbuiltin{void __builtin_nds32_setgie_en (void)}
d77de738 17802Enable global interrupt.
f25efe50 17803@enddefbuiltin
d77de738 17804
f25efe50 17805@defbuiltin{void __builtin_nds32_setgie_dis (void)}
d77de738 17806Disable global interrupt.
f25efe50 17807@enddefbuiltin
d77de738 17808
d77de738
ML
17809@node Basic PowerPC Built-in Functions
17810@subsection Basic PowerPC Built-in Functions
17811
17812@menu
17813* Basic PowerPC Built-in Functions Available on all Configurations::
17814* Basic PowerPC Built-in Functions Available on ISA 2.05::
17815* Basic PowerPC Built-in Functions Available on ISA 2.06::
17816* Basic PowerPC Built-in Functions Available on ISA 2.07::
17817* Basic PowerPC Built-in Functions Available on ISA 3.0::
17818* Basic PowerPC Built-in Functions Available on ISA 3.1::
17819@end menu
17820
17821This section describes PowerPC built-in functions that do not require
17822the inclusion of any special header files to declare prototypes or
17823provide macro definitions. The sections that follow describe
17824additional PowerPC built-in functions.
17825
17826@node Basic PowerPC Built-in Functions Available on all Configurations
17827@subsubsection Basic PowerPC Built-in Functions Available on all Configurations
17828
f25efe50 17829@defbuiltin{void __builtin_cpu_init (void)}
d77de738
ML
17830This function is a @code{nop} on the PowerPC platform and is included solely
17831to maintain API compatibility with the x86 builtins.
f25efe50 17832@enddefbuiltin
d77de738 17833
f25efe50 17834@defbuiltin{int __builtin_cpu_is (const char *@var{cpuname})}
d77de738
ML
17835This function returns a value of @code{1} if the run-time CPU is of type
17836@var{cpuname} and returns @code{0} otherwise
17837
17838The @code{__builtin_cpu_is} function requires GLIBC 2.23 or newer
17839which exports the hardware capability bits. GCC defines the macro
17840@code{__BUILTIN_CPU_SUPPORTS__} if the @code{__builtin_cpu_supports}
17841built-in function is fully supported.
17842
17843If GCC was configured to use a GLIBC before 2.23, the built-in
17844function @code{__builtin_cpu_is} always returns a 0 and the compiler
17845issues a warning.
17846
17847The following CPU names can be detected:
17848
17849@table @samp
17850@item power10
17851IBM POWER10 Server CPU.
17852@item power9
17853IBM POWER9 Server CPU.
17854@item power8
17855IBM POWER8 Server CPU.
17856@item power7
17857IBM POWER7 Server CPU.
17858@item power6x
17859IBM POWER6 Server CPU (RAW mode).
17860@item power6
17861IBM POWER6 Server CPU (Architected mode).
17862@item power5+
17863IBM POWER5+ Server CPU.
17864@item power5
17865IBM POWER5 Server CPU.
17866@item ppc970
17867IBM 970 Server CPU (ie, Apple G5).
17868@item power4
17869IBM POWER4 Server CPU.
17870@item ppca2
17871IBM A2 64-bit Embedded CPU
17872@item ppc476
17873IBM PowerPC 476FP 32-bit Embedded CPU.
17874@item ppc464
17875IBM PowerPC 464 32-bit Embedded CPU.
17876@item ppc440
17877PowerPC 440 32-bit Embedded CPU.
17878@item ppc405
17879PowerPC 405 32-bit Embedded CPU.
17880@item ppc-cell-be
17881IBM PowerPC Cell Broadband Engine Architecture CPU.
17882@end table
17883
17884Here is an example:
17885@smallexample
17886#ifdef __BUILTIN_CPU_SUPPORTS__
17887 if (__builtin_cpu_is ("power8"))
17888 @{
17889 do_power8 (); // POWER8 specific implementation.
17890 @}
17891 else
17892#endif
17893 @{
17894 do_generic (); // Generic implementation.
17895 @}
17896@end smallexample
f25efe50 17897@enddefbuiltin
d77de738 17898
f25efe50 17899@defbuiltin{int __builtin_cpu_supports (const char *@var{feature})}
d77de738
ML
17900This function returns a value of @code{1} if the run-time CPU supports the HWCAP
17901feature @var{feature} and returns @code{0} otherwise.
17902
17903The @code{__builtin_cpu_supports} function requires GLIBC 2.23 or
17904newer which exports the hardware capability bits. GCC defines the
17905macro @code{__BUILTIN_CPU_SUPPORTS__} if the
17906@code{__builtin_cpu_supports} built-in function is fully supported.
17907
17908If GCC was configured to use a GLIBC before 2.23, the built-in
17909function @code{__builtin_cpu_supports} always returns a 0 and the
17910compiler issues a warning.
17911
17912The following features can be
17913detected:
17914
17915@table @samp
17916@item 4xxmac
179174xx CPU has a Multiply Accumulator.
17918@item altivec
17919CPU has a SIMD/Vector Unit.
17920@item arch_2_05
17921CPU supports ISA 2.05 (eg, POWER6)
17922@item arch_2_06
17923CPU supports ISA 2.06 (eg, POWER7)
17924@item arch_2_07
17925CPU supports ISA 2.07 (eg, POWER8)
17926@item arch_3_00
17927CPU supports ISA 3.0 (eg, POWER9)
17928@item arch_3_1
17929CPU supports ISA 3.1 (eg, POWER10)
17930@item archpmu
17931CPU supports the set of compatible performance monitoring events.
17932@item booke
17933CPU supports the Embedded ISA category.
17934@item cellbe
17935CPU has a CELL broadband engine.
17936@item darn
17937CPU supports the @code{darn} (deliver a random number) instruction.
17938@item dfp
17939CPU has a decimal floating point unit.
17940@item dscr
17941CPU supports the data stream control register.
17942@item ebb
17943CPU supports event base branching.
17944@item efpdouble
17945CPU has a SPE double precision floating point unit.
17946@item efpsingle
17947CPU has a SPE single precision floating point unit.
17948@item fpu
17949CPU has a floating point unit.
17950@item htm
17951CPU has hardware transaction memory instructions.
17952@item htm-nosc
17953Kernel aborts hardware transactions when a syscall is made.
17954@item htm-no-suspend
17955CPU supports hardware transaction memory but does not support the
17956@code{tsuspend.} instruction.
17957@item ic_snoop
17958CPU supports icache snooping capabilities.
17959@item ieee128
17960CPU supports 128-bit IEEE binary floating point instructions.
17961@item isel
17962CPU supports the integer select instruction.
17963@item mma
17964CPU supports the matrix-multiply assist instructions.
17965@item mmu
17966CPU has a memory management unit.
17967@item notb
17968CPU does not have a timebase (eg, 601 and 403gx).
17969@item pa6t
17970CPU supports the PA Semi 6T CORE ISA.
17971@item power4
17972CPU supports ISA 2.00 (eg, POWER4)
17973@item power5
17974CPU supports ISA 2.02 (eg, POWER5)
17975@item power5+
17976CPU supports ISA 2.03 (eg, POWER5+)
17977@item power6x
17978CPU supports ISA 2.05 (eg, POWER6) extended opcodes mffgpr and mftgpr.
17979@item ppc32
17980CPU supports 32-bit mode execution.
17981@item ppc601
17982CPU supports the old POWER ISA (eg, 601)
17983@item ppc64
17984CPU supports 64-bit mode execution.
17985@item ppcle
17986CPU supports a little-endian mode that uses address swizzling.
17987@item scv
17988Kernel supports system call vectored.
17989@item smt
17990CPU support simultaneous multi-threading.
17991@item spe
17992CPU has a signal processing extension unit.
17993@item tar
17994CPU supports the target address register.
17995@item true_le
17996CPU supports true little-endian mode.
17997@item ucache
17998CPU has unified I/D cache.
17999@item vcrypto
18000CPU supports the vector cryptography instructions.
18001@item vsx
18002CPU supports the vector-scalar extension.
18003@end table
18004
18005Here is an example:
18006@smallexample
18007#ifdef __BUILTIN_CPU_SUPPORTS__
18008 if (__builtin_cpu_supports ("fpu"))
18009 @{
18010 asm("fadd %0,%1,%2" : "=d"(dst) : "d"(src1), "d"(src2));
18011 @}
18012 else
18013#endif
18014 @{
18015 dst = __fadd (src1, src2); // Software FP addition function.
18016 @}
18017@end smallexample
f25efe50 18018@enddefbuiltin
d77de738
ML
18019
18020The following built-in functions are also available on all PowerPC
18021processors:
18022@smallexample
18023uint64_t __builtin_ppc_get_timebase ();
18024unsigned long __builtin_ppc_mftb ();
18025double __builtin_unpack_ibm128 (__ibm128, int);
18026__ibm128 __builtin_pack_ibm128 (double, double);
18027double __builtin_mffs (void);
18028void __builtin_mtfsf (const int, double);
18029void __builtin_mtfsb0 (const int);
18030void __builtin_mtfsb1 (const int);
18031void __builtin_set_fpscr_rn (int);
18032@end smallexample
18033
18034The @code{__builtin_ppc_get_timebase} and @code{__builtin_ppc_mftb}
18035functions generate instructions to read the Time Base Register. The
18036@code{__builtin_ppc_get_timebase} function may generate multiple
18037instructions and always returns the 64 bits of the Time Base Register.
18038The @code{__builtin_ppc_mftb} function always generates one instruction and
18039returns the Time Base Register value as an unsigned long, throwing away
18040the most significant word on 32-bit environments. The @code{__builtin_mffs}
18041return the value of the FPSCR register. Note, ISA 3.0 supports the
18042@code{__builtin_mffsl()} which permits software to read the control and
18043non-sticky status bits in the FSPCR without the higher latency associated with
18044accessing the sticky status bits. The @code{__builtin_mtfsf} takes a constant
180458-bit integer field mask and a double precision floating point argument
18046and generates the @code{mtfsf} (extended mnemonic) instruction to write new
18047values to selected fields of the FPSCR. The
18048@code{__builtin_mtfsb0} and @code{__builtin_mtfsb1} take the bit to change
18049as an argument. The valid bit range is between 0 and 31. The builtins map to
18050the @code{mtfsb0} and @code{mtfsb1} instructions which take the argument and
18051add 32. Hence these instructions only modify the FPSCR[32:63] bits by
18052changing the specified bit to a zero or one respectively. The
18053@code{__builtin_set_fpscr_rn} builtin allows changing both of the floating
18054point rounding mode bits. The argument is a 2-bit value. The argument can
18055either be a @code{const int} or stored in a variable. The builtin uses
18056the ISA 3.0
18057instruction @code{mffscrn} if available, otherwise it reads the FPSCR, masks
18058the current rounding mode bits out and OR's in the new value.
18059
18060@node Basic PowerPC Built-in Functions Available on ISA 2.05
18061@subsubsection Basic PowerPC Built-in Functions Available on ISA 2.05
18062
18063The basic built-in functions described in this section are
18064available on the PowerPC family of processors starting with ISA 2.05
18065or later. Unless specific options are explicitly disabled on the
18066command line, specifying option @option{-mcpu=power6} has the effect of
18067enabling the @option{-mpowerpc64}, @option{-mpowerpc-gpopt},
18068@option{-mpowerpc-gfxopt}, @option{-mmfcrf}, @option{-mpopcntb},
18069@option{-mfprnd}, @option{-mcmpb}, @option{-mhard-dfp}, and
18070@option{-mrecip-precision} options. Specify the
18071@option{-maltivec} option explicitly in
18072combination with the above options if desired.
18073
18074The following functions require option @option{-mcmpb}.
18075@smallexample
18076unsigned long long __builtin_cmpb (unsigned long long int, unsigned long long int);
18077unsigned int __builtin_cmpb (unsigned int, unsigned int);
18078@end smallexample
18079
18080The @code{__builtin_cmpb} function
18081performs a byte-wise compare on the contents of its two arguments,
18082returning the result of the byte-wise comparison as the returned
18083value. For each byte comparison, the corresponding byte of the return
18084value holds 0xff if the input bytes are equal and 0 if the input bytes
18085are not equal. If either of the arguments to this built-in function
18086is wider than 32 bits, the function call expands into the form that
18087expects @code{unsigned long long int} arguments
18088which is only available on 64-bit targets.
18089
18090The following built-in functions are available
18091when hardware decimal floating point
18092(@option{-mhard-dfp}) is available:
18093@smallexample
18094void __builtin_set_fpscr_drn(int);
18095_Decimal64 __builtin_ddedpd (int, _Decimal64);
18096_Decimal128 __builtin_ddedpdq (int, _Decimal128);
18097_Decimal64 __builtin_denbcd (int, _Decimal64);
18098_Decimal128 __builtin_denbcdq (int, _Decimal128);
18099_Decimal64 __builtin_diex (long long, _Decimal64);
18100_Decimal128 _builtin_diexq (long long, _Decimal128);
18101_Decimal64 __builtin_dscli (_Decimal64, int);
18102_Decimal128 __builtin_dscliq (_Decimal128, int);
18103_Decimal64 __builtin_dscri (_Decimal64, int);
18104_Decimal128 __builtin_dscriq (_Decimal128, int);
18105long long __builtin_dxex (_Decimal64);
18106long long __builtin_dxexq (_Decimal128);
18107_Decimal128 __builtin_pack_dec128 (unsigned long long, unsigned long long);
18108unsigned long long __builtin_unpack_dec128 (_Decimal128, int);
18109
18110The @code{__builtin_set_fpscr_drn} builtin allows changing the three decimal
18111floating point rounding mode bits. The argument is a 3-bit value. The
18112argument can either be a @code{const int} or the value can be stored in
18113a variable.
18114The builtin uses the ISA 3.0 instruction @code{mffscdrn} if available.
18115Otherwise the builtin reads the FPSCR, masks the current decimal rounding
18116mode bits out and OR's in the new value.
18117
18118@end smallexample
18119
18120The following functions require @option{-mhard-float},
18121@option{-mpowerpc-gfxopt}, and @option{-mpopcntb} options.
18122
18123@smallexample
18124double __builtin_recipdiv (double, double);
18125float __builtin_recipdivf (float, float);
18126double __builtin_rsqrt (double);
18127float __builtin_rsqrtf (float);
18128@end smallexample
18129
18130The @code{vec_rsqrt}, @code{__builtin_rsqrt}, and
18131@code{__builtin_rsqrtf} functions generate multiple instructions to
18132implement the reciprocal sqrt functionality using reciprocal sqrt
18133estimate instructions.
18134
18135The @code{__builtin_recipdiv}, and @code{__builtin_recipdivf}
18136functions generate multiple instructions to implement division using
18137the reciprocal estimate instructions.
18138
18139The following functions require @option{-mhard-float} and
18140@option{-mmultiple} options.
18141
18142The @code{__builtin_unpack_longdouble} function takes a
18143@code{long double} argument and a compile time constant of 0 or 1. If
18144the constant is 0, the first @code{double} within the
18145@code{long double} is returned, otherwise the second @code{double}
18146is returned. The @code{__builtin_unpack_longdouble} function is only
18147available if @code{long double} uses the IBM extended double
18148representation.
18149
18150The @code{__builtin_pack_longdouble} function takes two @code{double}
18151arguments and returns a @code{long double} value that combines the two
18152arguments. The @code{__builtin_pack_longdouble} function is only
18153available if @code{long double} uses the IBM extended double
18154representation.
18155
18156The @code{__builtin_unpack_ibm128} function takes a @code{__ibm128}
18157argument and a compile time constant of 0 or 1. If the constant is 0,
18158the first @code{double} within the @code{__ibm128} is returned,
18159otherwise the second @code{double} is returned.
18160
18161The @code{__builtin_pack_ibm128} function takes two @code{double}
18162arguments and returns a @code{__ibm128} value that combines the two
18163arguments.
18164
18165Additional built-in functions are available for the 64-bit PowerPC
18166family of processors, for efficient use of 128-bit floating point
18167(@code{__float128}) values.
18168
18169@node Basic PowerPC Built-in Functions Available on ISA 2.06
18170@subsubsection Basic PowerPC Built-in Functions Available on ISA 2.06
18171
18172The basic built-in functions described in this section are
18173available on the PowerPC family of processors starting with ISA 2.05
18174or later. Unless specific options are explicitly disabled on the
18175command line, specifying option @option{-mcpu=power7} has the effect of
18176enabling all the same options as for @option{-mcpu=power6} in
18177addition to the @option{-maltivec}, @option{-mpopcntd}, and
18178@option{-mvsx} options.
18179
18180The following basic built-in functions require @option{-mpopcntd}:
18181@smallexample
18182unsigned int __builtin_addg6s (unsigned int, unsigned int);
18183long long __builtin_bpermd (long long, long long);
18184unsigned int __builtin_cbcdtd (unsigned int);
18185unsigned int __builtin_cdtbcd (unsigned int);
18186long long __builtin_divde (long long, long long);
18187unsigned long long __builtin_divdeu (unsigned long long, unsigned long long);
18188int __builtin_divwe (int, int);
18189unsigned int __builtin_divweu (unsigned int, unsigned int);
18190vector __int128 __builtin_pack_vector_int128 (long long, long long);
18191void __builtin_rs6000_speculation_barrier (void);
18192long long __builtin_unpack_vector_int128 (vector __int128, signed char);
18193@end smallexample
18194
18195Of these, the @code{__builtin_divde} and @code{__builtin_divdeu} functions
18196require a 64-bit environment.
18197
18198The following basic built-in functions, which are also supported on
18199x86 targets, require @option{-mfloat128}.
18200@smallexample
18201__float128 __builtin_fabsq (__float128);
18202__float128 __builtin_copysignq (__float128, __float128);
18203__float128 __builtin_infq (void);
18204__float128 __builtin_huge_valq (void);
18205__float128 __builtin_nanq (void);
18206__float128 __builtin_nansq (void);
18207
18208__float128 __builtin_sqrtf128 (__float128);
18209__float128 __builtin_fmaf128 (__float128, __float128, __float128);
18210@end smallexample
18211
18212@node Basic PowerPC Built-in Functions Available on ISA 2.07
18213@subsubsection Basic PowerPC Built-in Functions Available on ISA 2.07
18214
18215The basic built-in functions described in this section are
18216available on the PowerPC family of processors starting with ISA 2.07
18217or later. Unless specific options are explicitly disabled on the
18218command line, specifying option @option{-mcpu=power8} has the effect of
18219enabling all the same options as for @option{-mcpu=power7} in
18220addition to the @option{-mpower8-fusion}, @option{-mpower8-vector},
18221@option{-mcrypto}, @option{-mhtm}, @option{-mquad-memory}, and
18222@option{-mquad-memory-atomic} options.
18223
18224This section intentionally empty.
18225
18226@node Basic PowerPC Built-in Functions Available on ISA 3.0
18227@subsubsection Basic PowerPC Built-in Functions Available on ISA 3.0
18228
18229The basic built-in functions described in this section are
18230available on the PowerPC family of processors starting with ISA 3.0
18231or later. Unless specific options are explicitly disabled on the
18232command line, specifying option @option{-mcpu=power9} has the effect of
18233enabling all the same options as for @option{-mcpu=power8} in
18234addition to the @option{-misel} option.
18235
18236The following built-in functions are available on Linux 64-bit systems
18237that use the ISA 3.0 instruction set (@option{-mcpu=power9}):
18238
f25efe50 18239@defbuiltin{__float128 __builtin_addf128_round_to_odd (__float128, __float128)}
d77de738
ML
18240Perform a 128-bit IEEE floating point add using round to odd as the
18241rounding mode.
f25efe50 18242@enddefbuiltin
d77de738 18243
f25efe50 18244@defbuiltin{__float128 __builtin_subf128_round_to_odd (__float128, __float128)}
d77de738
ML
18245Perform a 128-bit IEEE floating point subtract using round to odd as
18246the rounding mode.
f25efe50 18247@enddefbuiltin
d77de738 18248
f25efe50 18249@defbuiltin{__float128 __builtin_mulf128_round_to_odd (__float128, __float128)}
d77de738
ML
18250Perform a 128-bit IEEE floating point multiply using round to odd as
18251the rounding mode.
f25efe50 18252@enddefbuiltin
d77de738 18253
f25efe50 18254@defbuiltin{__float128 __builtin_divf128_round_to_odd (__float128, __float128)}
d77de738
ML
18255Perform a 128-bit IEEE floating point divide using round to odd as
18256the rounding mode.
f25efe50 18257@enddefbuiltin
d77de738 18258
f25efe50 18259@defbuiltin{__float128 __builtin_sqrtf128_round_to_odd (__float128)}
d77de738
ML
18260Perform a 128-bit IEEE floating point square root using round to odd
18261as the rounding mode.
f25efe50 18262@enddefbuiltin
d77de738 18263
f25efe50 18264@defbuiltin{__float128 __builtin_fmaf128_round_to_odd (__float128, __float128, __float128)}
d77de738
ML
18265Perform a 128-bit IEEE floating point fused multiply and add operation
18266using round to odd as the rounding mode.
f25efe50 18267@enddefbuiltin
d77de738 18268
f25efe50 18269@defbuiltin{double __builtin_truncf128_round_to_odd (__float128)}
d77de738
ML
18270Convert a 128-bit IEEE floating point value to @code{double} using
18271round to odd as the rounding mode.
f25efe50
AA
18272@enddefbuiltin
18273
d77de738
ML
18274
18275The following additional built-in functions are also available for the
18276PowerPC family of processors, starting with ISA 3.0 or later:
d77de738 18277
f25efe50
AA
18278@defbuiltin{long long __builtin_darn (void)}
18279@defbuiltinx{long long __builtin_darn_raw (void)}
18280@defbuiltinx{int __builtin_darn_32 (void)}
d77de738
ML
18281The @code{__builtin_darn} and @code{__builtin_darn_raw}
18282functions require a
1828364-bit environment supporting ISA 3.0 or later.
18284The @code{__builtin_darn} function provides a 64-bit conditioned
18285random number. The @code{__builtin_darn_raw} function provides a
1828664-bit raw random number. The @code{__builtin_darn_32} function
18287provides a 32-bit conditioned random number.
f25efe50 18288@enddefbuiltin
d77de738
ML
18289
18290The following additional built-in functions are also available for the
18291PowerPC family of processors, starting with ISA 3.0 or later:
18292
18293@smallexample
18294int __builtin_byte_in_set (unsigned char u, unsigned long long set);
18295int __builtin_byte_in_range (unsigned char u, unsigned int range);
18296int __builtin_byte_in_either_range (unsigned char u, unsigned int ranges);
18297
18298int __builtin_dfp_dtstsfi_lt (unsigned int comparison, _Decimal64 value);
18299int __builtin_dfp_dtstsfi_lt (unsigned int comparison, _Decimal128 value);
18300int __builtin_dfp_dtstsfi_lt_dd (unsigned int comparison, _Decimal64 value);
18301int __builtin_dfp_dtstsfi_lt_td (unsigned int comparison, _Decimal128 value);
18302
18303int __builtin_dfp_dtstsfi_gt (unsigned int comparison, _Decimal64 value);
18304int __builtin_dfp_dtstsfi_gt (unsigned int comparison, _Decimal128 value);
18305int __builtin_dfp_dtstsfi_gt_dd (unsigned int comparison, _Decimal64 value);
18306int __builtin_dfp_dtstsfi_gt_td (unsigned int comparison, _Decimal128 value);
18307
18308int __builtin_dfp_dtstsfi_eq (unsigned int comparison, _Decimal64 value);
18309int __builtin_dfp_dtstsfi_eq (unsigned int comparison, _Decimal128 value);
18310int __builtin_dfp_dtstsfi_eq_dd (unsigned int comparison, _Decimal64 value);
18311int __builtin_dfp_dtstsfi_eq_td (unsigned int comparison, _Decimal128 value);
18312
18313int __builtin_dfp_dtstsfi_ov (unsigned int comparison, _Decimal64 value);
18314int __builtin_dfp_dtstsfi_ov (unsigned int comparison, _Decimal128 value);
18315int __builtin_dfp_dtstsfi_ov_dd (unsigned int comparison, _Decimal64 value);
18316int __builtin_dfp_dtstsfi_ov_td (unsigned int comparison, _Decimal128 value);
18317
18318double __builtin_mffsl(void);
18319
18320@end smallexample
18321The @code{__builtin_byte_in_set} function requires a
1832264-bit environment supporting ISA 3.0 or later. This function returns
18323a non-zero value if and only if its @code{u} argument exactly equals one of
18324the eight bytes contained within its 64-bit @code{set} argument.
18325
18326The @code{__builtin_byte_in_range} and
18327@code{__builtin_byte_in_either_range} require an environment
18328supporting ISA 3.0 or later. For these two functions, the
18329@code{range} argument is encoded as 4 bytes, organized as
18330@code{hi_1:lo_1:hi_2:lo_2}.
18331The @code{__builtin_byte_in_range} function returns a
18332non-zero value if and only if its @code{u} argument is within the
18333range bounded between @code{lo_2} and @code{hi_2} inclusive.
18334The @code{__builtin_byte_in_either_range} function returns non-zero if
18335and only if its @code{u} argument is within either the range bounded
18336between @code{lo_1} and @code{hi_1} inclusive or the range bounded
18337between @code{lo_2} and @code{hi_2} inclusive.
18338
18339The @code{__builtin_dfp_dtstsfi_lt} function returns a non-zero value
18340if and only if the number of signficant digits of its @code{value} argument
18341is less than its @code{comparison} argument. The
18342@code{__builtin_dfp_dtstsfi_lt_dd} and
18343@code{__builtin_dfp_dtstsfi_lt_td} functions behave similarly, but
18344require that the type of the @code{value} argument be
18345@code{__Decimal64} and @code{__Decimal128} respectively.
18346
18347The @code{__builtin_dfp_dtstsfi_gt} function returns a non-zero value
18348if and only if the number of signficant digits of its @code{value} argument
18349is greater than its @code{comparison} argument. The
18350@code{__builtin_dfp_dtstsfi_gt_dd} and
18351@code{__builtin_dfp_dtstsfi_gt_td} functions behave similarly, but
18352require that the type of the @code{value} argument be
18353@code{__Decimal64} and @code{__Decimal128} respectively.
18354
18355The @code{__builtin_dfp_dtstsfi_eq} function returns a non-zero value
18356if and only if the number of signficant digits of its @code{value} argument
18357equals its @code{comparison} argument. The
18358@code{__builtin_dfp_dtstsfi_eq_dd} and
18359@code{__builtin_dfp_dtstsfi_eq_td} functions behave similarly, but
18360require that the type of the @code{value} argument be
18361@code{__Decimal64} and @code{__Decimal128} respectively.
18362
18363The @code{__builtin_dfp_dtstsfi_ov} function returns a non-zero value
18364if and only if its @code{value} argument has an undefined number of
18365significant digits, such as when @code{value} is an encoding of @code{NaN}.
18366The @code{__builtin_dfp_dtstsfi_ov_dd} and
18367@code{__builtin_dfp_dtstsfi_ov_td} functions behave similarly, but
18368require that the type of the @code{value} argument be
18369@code{__Decimal64} and @code{__Decimal128} respectively.
18370
18371The @code{__builtin_mffsl} uses the ISA 3.0 @code{mffsl} instruction to read
18372the FPSCR. The instruction is a lower latency version of the @code{mffs}
18373instruction. If the @code{mffsl} instruction is not available, then the
18374builtin uses the older @code{mffs} instruction to read the FPSCR.
18375
18376@node Basic PowerPC Built-in Functions Available on ISA 3.1
18377@subsubsection Basic PowerPC Built-in Functions Available on ISA 3.1
18378
18379The basic built-in functions described in this section are
18380available on the PowerPC family of processors starting with ISA 3.1.
18381Unless specific options are explicitly disabled on the
18382command line, specifying option @option{-mcpu=power10} has the effect of
18383enabling all the same options as for @option{-mcpu=power9}.
18384
18385The following built-in functions are available on Linux 64-bit systems
18386that use a future architecture instruction set (@option{-mcpu=power10}):
18387
f25efe50
AA
18388@defbuiltin{{unsigned long long} @
18389 __builtin_cfuged (unsigned long long, unsigned long long)}
d77de738
ML
18390Perform a 64-bit centrifuge operation, as if implemented by the
18391@code{cfuged} instruction.
f25efe50 18392@enddefbuiltin
d77de738 18393
f25efe50
AA
18394@defbuiltin{{unsigned long long} @
18395 __builtin_cntlzdm (unsigned long long, unsigned long long)}
d77de738
ML
18396Perform a 64-bit count leading zeros operation under mask, as if
18397implemented by the @code{cntlzdm} instruction.
f25efe50 18398@enddefbuiltin
d77de738 18399
f25efe50
AA
18400@defbuiltin{{unsigned long long} @
18401 __builtin_cnttzdm (unsigned long long, unsigned long long)}
d77de738
ML
18402Perform a 64-bit count trailing zeros operation under mask, as if
18403implemented by the @code{cnttzdm} instruction.
f25efe50 18404@enddefbuiltin
d77de738 18405
f25efe50
AA
18406@defbuiltin{{unsigned long long} @
18407 __builtin_pdepd (unsigned long long, unsigned long long)}
d77de738
ML
18408Perform a 64-bit parallel bits deposit operation, as if implemented by the
18409@code{pdepd} instruction.
f25efe50 18410@enddefbuiltin
d77de738 18411
f25efe50
AA
18412@defbuiltin{{unsigned long long} @
18413 __builtin_pextd (unsigned long long, unsigned long long)}
d77de738
ML
18414Perform a 64-bit parallel bits extract operation, as if implemented by the
18415@code{pextd} instruction.
f25efe50 18416@enddefbuiltin
d77de738 18417
f25efe50
AA
18418@defbuiltin{{vector signed __int128} vsx_xl_sext (signed long long, signed char *)}
18419@defbuiltinx{{vector signed __int128} vsx_xl_sext (signed long long, signed short *)}
18420@defbuiltinx{{vector signed __int128} vsx_xl_sext (signed long long, signed int *)}
18421@defbuiltinx{{vector signed __int128} vsx_xl_sext (signed long long, signed long long *)}
18422@defbuiltinx{{vector unsigned __int128} vsx_xl_zext (signed long long, unsigned char *)}
18423@defbuiltinx{{vector unsigned __int128} vsx_xl_zext (signed long long, unsigned short *)}
18424@defbuiltinx{{vector unsigned __int128} vsx_xl_zext (signed long long, unsigned int *)}
18425@defbuiltinx{{vector unsigned __int128} vsx_xl_zext (signed long long, unsigned long long *)}
d77de738
ML
18426
18427Load (and sign extend) to an __int128 vector, as if implemented by the ISA 3.1
f25efe50
AA
18428@code{lxvrbx}, @code{lxvrhx}, @code{lxvrwx}, and @code{lxvrdx}
18429instructions.
18430@enddefbuiltin
d77de738 18431
f25efe50
AA
18432@defbuiltin{{void} vec_xst_trunc (vector signed __int128, signed long long, signed char *)}
18433@defbuiltinx{{void} vec_xst_trunc (vector signed __int128, signed long long, signed short *)}
18434@defbuiltinx{{void} vec_xst_trunc (vector signed __int128, signed long long, signed int *)}
18435@defbuiltinx{{void} vec_xst_trunc (vector signed __int128, signed long long, signed long long *)}
18436@defbuiltinx{{void} vec_xst_trunc (vector unsigned __int128, signed long long, unsigned char *)}
18437@defbuiltinx{{void} vec_xst_trunc (vector unsigned __int128, signed long long, unsigned short *)}
18438@defbuiltinx{{void} vec_xst_trunc (vector unsigned __int128, signed long long, unsigned int *)}
18439@defbuiltinx{{void} vec_xst_trunc (vector unsigned __int128, signed long long, unsigned long long *)}
d77de738
ML
18440
18441Truncate and store the rightmost element of a vector, as if implemented by the
18442ISA 3.1 @code{stxvrbx}, @code{stxvrhx}, @code{stxvrwx}, and @code{stxvrdx}
18443instructions.
f25efe50 18444@enddefbuiltin
d77de738
ML
18445
18446@node PowerPC AltiVec/VSX Built-in Functions
18447@subsection PowerPC AltiVec/VSX Built-in Functions
18448
18449GCC provides an interface for the PowerPC family of processors to access
18450the AltiVec operations described in Motorola's AltiVec Programming
18451Interface Manual. The interface is made available by including
18452@code{<altivec.h>} and using @option{-maltivec} and
18453@option{-mabi=altivec}. The interface supports the following vector
18454types.
18455
18456@smallexample
18457vector unsigned char
18458vector signed char
18459vector bool char
18460
18461vector unsigned short
18462vector signed short
18463vector bool short
18464vector pixel
18465
18466vector unsigned int
18467vector signed int
18468vector bool int
18469vector float
18470@end smallexample
18471
18472GCC's implementation of the high-level language interface available from
18473C and C++ code differs from Motorola's documentation in several ways.
18474
18475@itemize @bullet
18476
18477@item
18478A vector constant is a list of constant expressions within curly braces.
18479
18480@item
18481A vector initializer requires no cast if the vector constant is of the
18482same type as the variable it is initializing.
18483
18484@item
18485If @code{signed} or @code{unsigned} is omitted, the signedness of the
18486vector type is the default signedness of the base type. The default
18487varies depending on the operating system, so a portable program should
18488always specify the signedness.
18489
18490@item
18491Compiling with @option{-maltivec} adds keywords @code{__vector},
18492@code{vector}, @code{__pixel}, @code{pixel}, @code{__bool} and
18493@code{bool}. When compiling ISO C, the context-sensitive substitution
18494of the keywords @code{vector}, @code{pixel} and @code{bool} is
18495disabled. To use them, you must include @code{<altivec.h>} instead.
18496
18497@item
18498GCC allows using a @code{typedef} name as the type specifier for a
18499vector type, but only under the following circumstances:
18500
18501@itemize @bullet
18502
18503@item
18504When using @code{__vector} instead of @code{vector}; for example,
18505
18506@smallexample
18507typedef signed short int16;
18508__vector int16 data;
18509@end smallexample
18510
18511@item
18512When using @code{vector} in keyword-and-predefine mode; for example,
18513
18514@smallexample
18515typedef signed short int16;
18516vector int16 data;
18517@end smallexample
18518
18519Note that keyword-and-predefine mode is enabled by disabling GNU
18520extensions (e.g., by using @code{-std=c11}) and including
18521@code{<altivec.h>}.
18522@end itemize
18523
18524@item
18525For C, overloaded functions are implemented with macros so the following
18526does not work:
18527
18528@smallexample
18529 vec_add ((vector signed int)@{1, 2, 3, 4@}, foo);
18530@end smallexample
18531
18532@noindent
18533Since @code{vec_add} is a macro, the vector constant in the example
18534is treated as four separate arguments. Wrap the entire argument in
18535parentheses for this to work.
18536@end itemize
18537
18538@emph{Note:} Only the @code{<altivec.h>} interface is supported.
18539Internally, GCC uses built-in functions to achieve the functionality in
18540the aforementioned header file, but they are not supported and are
18541subject to change without notice.
18542
18543GCC complies with the Power Vector Intrinsic Programming Reference (PVIPR),
18544which may be found at
18545@uref{https://openpowerfoundation.org/?resource_lib=power-vector-intrinsic-programming-reference}.
18546Chapter 4 of this document fully documents the vector API interfaces
18547that must be
18548provided by compliant compilers. Programmers should preferentially use
18549the interfaces described therein. However, historically GCC has provided
18550additional interfaces for access to vector instructions. These are
18551briefly described below. Where the PVIPR provides a portable interface,
18552other functions in GCC that provide the same capabilities should be
18553considered deprecated.
18554
18555The PVIPR documents the following overloaded functions:
18556
18557@multitable @columnfractions 0.33 0.33 0.33
18558
18559@item @code{vec_abs}
18560@tab @code{vec_absd}
18561@tab @code{vec_abss}
18562@item @code{vec_add}
18563@tab @code{vec_addc}
18564@tab @code{vec_adde}
18565@item @code{vec_addec}
18566@tab @code{vec_adds}
18567@tab @code{vec_all_eq}
18568@item @code{vec_all_ge}
18569@tab @code{vec_all_gt}
18570@tab @code{vec_all_in}
18571@item @code{vec_all_le}
18572@tab @code{vec_all_lt}
18573@tab @code{vec_all_nan}
18574@item @code{vec_all_ne}
18575@tab @code{vec_all_nge}
18576@tab @code{vec_all_ngt}
18577@item @code{vec_all_nle}
18578@tab @code{vec_all_nlt}
18579@tab @code{vec_all_numeric}
18580@item @code{vec_and}
18581@tab @code{vec_andc}
18582@tab @code{vec_any_eq}
18583@item @code{vec_any_ge}
18584@tab @code{vec_any_gt}
18585@tab @code{vec_any_le}
18586@item @code{vec_any_lt}
18587@tab @code{vec_any_nan}
18588@tab @code{vec_any_ne}
18589@item @code{vec_any_nge}
18590@tab @code{vec_any_ngt}
18591@tab @code{vec_any_nle}
18592@item @code{vec_any_nlt}
18593@tab @code{vec_any_numeric}
18594@tab @code{vec_any_out}
18595@item @code{vec_avg}
18596@tab @code{vec_bperm}
18597@tab @code{vec_ceil}
18598@item @code{vec_cipher_be}
18599@tab @code{vec_cipherlast_be}
18600@tab @code{vec_cmpb}
18601@item @code{vec_cmpeq}
18602@tab @code{vec_cmpge}
18603@tab @code{vec_cmpgt}
18604@item @code{vec_cmple}
18605@tab @code{vec_cmplt}
18606@tab @code{vec_cmpne}
18607@item @code{vec_cmpnez}
18608@tab @code{vec_cntlz}
18609@tab @code{vec_cntlz_lsbb}
18610@item @code{vec_cnttz}
18611@tab @code{vec_cnttz_lsbb}
18612@tab @code{vec_cpsgn}
18613@item @code{vec_ctf}
18614@tab @code{vec_cts}
18615@tab @code{vec_ctu}
18616@item @code{vec_div}
18617@tab @code{vec_double}
18618@tab @code{vec_doublee}
18619@item @code{vec_doubleh}
18620@tab @code{vec_doublel}
18621@tab @code{vec_doubleo}
18622@item @code{vec_eqv}
18623@tab @code{vec_expte}
18624@tab @code{vec_extract}
18625@item @code{vec_extract_exp}
18626@tab @code{vec_extract_fp32_from_shorth}
18627@tab @code{vec_extract_fp32_from_shortl}
18628@item @code{vec_extract_sig}
18629@tab @code{vec_extract_4b}
18630@tab @code{vec_first_match_index}
18631@item @code{vec_first_match_or_eos_index}
18632@tab @code{vec_first_mismatch_index}
18633@tab @code{vec_first_mismatch_or_eos_index}
18634@item @code{vec_float}
18635@tab @code{vec_float2}
18636@tab @code{vec_floate}
18637@item @code{vec_floato}
18638@tab @code{vec_floor}
18639@tab @code{vec_gb}
18640@item @code{vec_insert}
18641@tab @code{vec_insert_exp}
18642@tab @code{vec_insert4b}
18643@item @code{vec_ld}
18644@tab @code{vec_lde}
18645@tab @code{vec_ldl}
18646@item @code{vec_loge}
18647@tab @code{vec_madd}
18648@tab @code{vec_madds}
18649@item @code{vec_max}
18650@tab @code{vec_mergee}
18651@tab @code{vec_mergeh}
18652@item @code{vec_mergel}
18653@tab @code{vec_mergeo}
18654@tab @code{vec_mfvscr}
18655@item @code{vec_min}
18656@tab @code{vec_mradds}
18657@tab @code{vec_msub}
18658@item @code{vec_msum}
18659@tab @code{vec_msums}
18660@tab @code{vec_mtvscr}
18661@item @code{vec_mul}
18662@tab @code{vec_mule}
18663@tab @code{vec_mulo}
18664@item @code{vec_nabs}
18665@tab @code{vec_nand}
18666@tab @code{vec_ncipher_be}
18667@item @code{vec_ncipherlast_be}
18668@tab @code{vec_nearbyint}
18669@tab @code{vec_neg}
18670@item @code{vec_nmadd}
18671@tab @code{vec_nmsub}
18672@tab @code{vec_nor}
18673@item @code{vec_or}
18674@tab @code{vec_orc}
18675@tab @code{vec_pack}
18676@item @code{vec_pack_to_short_fp32}
18677@tab @code{vec_packpx}
18678@tab @code{vec_packs}
18679@item @code{vec_packsu}
18680@tab @code{vec_parity_lsbb}
18681@tab @code{vec_perm}
18682@item @code{vec_permxor}
18683@tab @code{vec_pmsum_be}
18684@tab @code{vec_popcnt}
18685@item @code{vec_re}
18686@tab @code{vec_recipdiv}
18687@tab @code{vec_revb}
18688@item @code{vec_reve}
18689@tab @code{vec_rint}
18690@tab @code{vec_rl}
18691@item @code{vec_rlmi}
18692@tab @code{vec_rlnm}
18693@tab @code{vec_round}
18694@item @code{vec_rsqrt}
18695@tab @code{vec_rsqrte}
18696@tab @code{vec_sbox_be}
18697@item @code{vec_sel}
18698@tab @code{vec_shasigma_be}
18699@tab @code{vec_signed}
18700@item @code{vec_signed2}
18701@tab @code{vec_signede}
18702@tab @code{vec_signedo}
18703@item @code{vec_sl}
18704@tab @code{vec_sld}
18705@tab @code{vec_sldw}
18706@item @code{vec_sll}
18707@tab @code{vec_slo}
18708@tab @code{vec_slv}
18709@item @code{vec_splat}
18710@tab @code{vec_splat_s8}
18711@tab @code{vec_splat_s16}
18712@item @code{vec_splat_s32}
18713@tab @code{vec_splat_u8}
18714@tab @code{vec_splat_u16}
18715@item @code{vec_splat_u32}
18716@tab @code{vec_splats}
18717@tab @code{vec_sqrt}
18718@item @code{vec_sr}
18719@tab @code{vec_sra}
18720@tab @code{vec_srl}
18721@item @code{vec_sro}
18722@tab @code{vec_srv}
18723@tab @code{vec_st}
18724@item @code{vec_ste}
18725@tab @code{vec_stl}
18726@tab @code{vec_sub}
18727@item @code{vec_subc}
18728@tab @code{vec_sube}
18729@tab @code{vec_subec}
18730@item @code{vec_subs}
18731@tab @code{vec_sum2s}
18732@tab @code{vec_sum4s}
18733@item @code{vec_sums}
18734@tab @code{vec_test_data_class}
18735@tab @code{vec_trunc}
18736@item @code{vec_unpackh}
18737@tab @code{vec_unpackl}
18738@tab @code{vec_unsigned}
18739@item @code{vec_unsigned2}
18740@tab @code{vec_unsignede}
18741@tab @code{vec_unsignedo}
18742@item @code{vec_xl}
18743@tab @code{vec_xl_be}
18744@tab @code{vec_xl_len}
18745@item @code{vec_xl_len_r}
18746@tab @code{vec_xor}
18747@tab @code{vec_xst}
18748@item @code{vec_xst_be}
18749@tab @code{vec_xst_len}
18750@tab @code{vec_xst_len_r}
18751
18752@end multitable
18753
18754@menu
18755* PowerPC AltiVec Built-in Functions on ISA 2.05::
18756* PowerPC AltiVec Built-in Functions Available on ISA 2.06::
18757* PowerPC AltiVec Built-in Functions Available on ISA 2.07::
18758* PowerPC AltiVec Built-in Functions Available on ISA 3.0::
18759* PowerPC AltiVec Built-in Functions Available on ISA 3.1::
18760@end menu
18761
18762@node PowerPC AltiVec Built-in Functions on ISA 2.05
18763@subsubsection PowerPC AltiVec Built-in Functions on ISA 2.05
18764
18765The following interfaces are supported for the generic and specific
18766AltiVec operations and the AltiVec predicates. In cases where there
18767is a direct mapping between generic and specific operations, only the
18768generic names are shown here, although the specific operations can also
18769be used.
18770
18771Arguments that are documented as @code{const int} require literal
18772integral values within the range required for that operation.
18773
18774Only functions excluded from the PVIPR are listed here.
18775
18776@smallexample
18777void vec_dss (const int);
18778
18779void vec_dssall (void);
18780
18781void vec_dst (const vector unsigned char *, int, const int);
18782void vec_dst (const vector signed char *, int, const int);
18783void vec_dst (const vector bool char *, int, const int);
18784void vec_dst (const vector unsigned short *, int, const int);
18785void vec_dst (const vector signed short *, int, const int);
18786void vec_dst (const vector bool short *, int, const int);
18787void vec_dst (const vector pixel *, int, const int);
18788void vec_dst (const vector unsigned int *, int, const int);
18789void vec_dst (const vector signed int *, int, const int);
18790void vec_dst (const vector bool int *, int, const int);
18791void vec_dst (const vector float *, int, const int);
18792void vec_dst (const unsigned char *, int, const int);
18793void vec_dst (const signed char *, int, const int);
18794void vec_dst (const unsigned short *, int, const int);
18795void vec_dst (const short *, int, const int);
18796void vec_dst (const unsigned int *, int, const int);
18797void vec_dst (const int *, int, const int);
18798void vec_dst (const float *, int, const int);
18799
18800void vec_dstst (const vector unsigned char *, int, const int);
18801void vec_dstst (const vector signed char *, int, const int);
18802void vec_dstst (const vector bool char *, int, const int);
18803void vec_dstst (const vector unsigned short *, int, const int);
18804void vec_dstst (const vector signed short *, int, const int);
18805void vec_dstst (const vector bool short *, int, const int);
18806void vec_dstst (const vector pixel *, int, const int);
18807void vec_dstst (const vector unsigned int *, int, const int);
18808void vec_dstst (const vector signed int *, int, const int);
18809void vec_dstst (const vector bool int *, int, const int);
18810void vec_dstst (const vector float *, int, const int);
18811void vec_dstst (const unsigned char *, int, const int);
18812void vec_dstst (const signed char *, int, const int);
18813void vec_dstst (const unsigned short *, int, const int);
18814void vec_dstst (const short *, int, const int);
18815void vec_dstst (const unsigned int *, int, const int);
18816void vec_dstst (const int *, int, const int);
18817void vec_dstst (const unsigned long *, int, const int);
18818void vec_dstst (const long *, int, const int);
18819void vec_dstst (const float *, int, const int);
18820
18821void vec_dststt (const vector unsigned char *, int, const int);
18822void vec_dststt (const vector signed char *, int, const int);
18823void vec_dststt (const vector bool char *, int, const int);
18824void vec_dststt (const vector unsigned short *, int, const int);
18825void vec_dststt (const vector signed short *, int, const int);
18826void vec_dststt (const vector bool short *, int, const int);
18827void vec_dststt (const vector pixel *, int, const int);
18828void vec_dststt (const vector unsigned int *, int, const int);
18829void vec_dststt (const vector signed int *, int, const int);
18830void vec_dststt (const vector bool int *, int, const int);
18831void vec_dststt (const vector float *, int, const int);
18832void vec_dststt (const unsigned char *, int, const int);
18833void vec_dststt (const signed char *, int, const int);
18834void vec_dststt (const unsigned short *, int, const int);
18835void vec_dststt (const short *, int, const int);
18836void vec_dststt (const unsigned int *, int, const int);
18837void vec_dststt (const int *, int, const int);
18838void vec_dststt (const float *, int, const int);
18839
18840void vec_dstt (const vector unsigned char *, int, const int);
18841void vec_dstt (const vector signed char *, int, const int);
18842void vec_dstt (const vector bool char *, int, const int);
18843void vec_dstt (const vector unsigned short *, int, const int);
18844void vec_dstt (const vector signed short *, int, const int);
18845void vec_dstt (const vector bool short *, int, const int);
18846void vec_dstt (const vector pixel *, int, const int);
18847void vec_dstt (const vector unsigned int *, int, const int);
18848void vec_dstt (const vector signed int *, int, const int);
18849void vec_dstt (const vector bool int *, int, const int);
18850void vec_dstt (const vector float *, int, const int);
18851void vec_dstt (const unsigned char *, int, const int);
18852void vec_dstt (const signed char *, int, const int);
18853void vec_dstt (const unsigned short *, int, const int);
18854void vec_dstt (const short *, int, const int);
18855void vec_dstt (const unsigned int *, int, const int);
18856void vec_dstt (const int *, int, const int);
18857void vec_dstt (const float *, int, const int);
18858
18859vector signed char vec_lvebx (int, char *);
18860vector unsigned char vec_lvebx (int, unsigned char *);
18861
18862vector signed short vec_lvehx (int, short *);
18863vector unsigned short vec_lvehx (int, unsigned short *);
18864
18865vector float vec_lvewx (int, float *);
18866vector signed int vec_lvewx (int, int *);
18867vector unsigned int vec_lvewx (int, unsigned int *);
18868
18869vector unsigned char vec_lvsl (int, const unsigned char *);
18870vector unsigned char vec_lvsl (int, const signed char *);
18871vector unsigned char vec_lvsl (int, const unsigned short *);
18872vector unsigned char vec_lvsl (int, const short *);
18873vector unsigned char vec_lvsl (int, const unsigned int *);
18874vector unsigned char vec_lvsl (int, const int *);
18875vector unsigned char vec_lvsl (int, const float *);
18876
18877vector unsigned char vec_lvsr (int, const unsigned char *);
18878vector unsigned char vec_lvsr (int, const signed char *);
18879vector unsigned char vec_lvsr (int, const unsigned short *);
18880vector unsigned char vec_lvsr (int, const short *);
18881vector unsigned char vec_lvsr (int, const unsigned int *);
18882vector unsigned char vec_lvsr (int, const int *);
18883vector unsigned char vec_lvsr (int, const float *);
18884
18885void vec_stvebx (vector signed char, int, signed char *);
18886void vec_stvebx (vector unsigned char, int, unsigned char *);
18887void vec_stvebx (vector bool char, int, signed char *);
18888void vec_stvebx (vector bool char, int, unsigned char *);
18889
18890void vec_stvehx (vector signed short, int, short *);
18891void vec_stvehx (vector unsigned short, int, unsigned short *);
18892void vec_stvehx (vector bool short, int, short *);
18893void vec_stvehx (vector bool short, int, unsigned short *);
18894
18895void vec_stvewx (vector float, int, float *);
18896void vec_stvewx (vector signed int, int, int *);
18897void vec_stvewx (vector unsigned int, int, unsigned int *);
18898void vec_stvewx (vector bool int, int, int *);
18899void vec_stvewx (vector bool int, int, unsigned int *);
18900
18901vector float vec_vaddfp (vector float, vector float);
18902
18903vector signed char vec_vaddsbs (vector bool char, vector signed char);
18904vector signed char vec_vaddsbs (vector signed char, vector bool char);
18905vector signed char vec_vaddsbs (vector signed char, vector signed char);
18906
18907vector signed short vec_vaddshs (vector bool short, vector signed short);
18908vector signed short vec_vaddshs (vector signed short, vector bool short);
18909vector signed short vec_vaddshs (vector signed short, vector signed short);
18910
18911vector signed int vec_vaddsws (vector bool int, vector signed int);
18912vector signed int vec_vaddsws (vector signed int, vector bool int);
18913vector signed int vec_vaddsws (vector signed int, vector signed int);
18914
18915vector signed char vec_vaddubm (vector bool char, vector signed char);
18916vector signed char vec_vaddubm (vector signed char, vector bool char);
18917vector signed char vec_vaddubm (vector signed char, vector signed char);
18918vector unsigned char vec_vaddubm (vector bool char, vector unsigned char);
18919vector unsigned char vec_vaddubm (vector unsigned char, vector bool char);
18920vector unsigned char vec_vaddubm (vector unsigned char, vector unsigned char);
18921
18922vector unsigned char vec_vaddubs (vector bool char, vector unsigned char);
18923vector unsigned char vec_vaddubs (vector unsigned char, vector bool char);
18924vector unsigned char vec_vaddubs (vector unsigned char, vector unsigned char);
18925
18926vector signed short vec_vadduhm (vector bool short, vector signed short);
18927vector signed short vec_vadduhm (vector signed short, vector bool short);
18928vector signed short vec_vadduhm (vector signed short, vector signed short);
18929vector unsigned short vec_vadduhm (vector bool short, vector unsigned short);
18930vector unsigned short vec_vadduhm (vector unsigned short, vector bool short);
18931vector unsigned short vec_vadduhm (vector unsigned short, vector unsigned short);
18932
18933vector unsigned short vec_vadduhs (vector bool short, vector unsigned short);
18934vector unsigned short vec_vadduhs (vector unsigned short, vector bool short);
18935vector unsigned short vec_vadduhs (vector unsigned short, vector unsigned short);
18936
18937vector signed int vec_vadduwm (vector bool int, vector signed int);
18938vector signed int vec_vadduwm (vector signed int, vector bool int);
18939vector signed int vec_vadduwm (vector signed int, vector signed int);
18940vector unsigned int vec_vadduwm (vector bool int, vector unsigned int);
18941vector unsigned int vec_vadduwm (vector unsigned int, vector bool int);
18942vector unsigned int vec_vadduwm (vector unsigned int, vector unsigned int);
18943
18944vector unsigned int vec_vadduws (vector bool int, vector unsigned int);
18945vector unsigned int vec_vadduws (vector unsigned int, vector bool int);
18946vector unsigned int vec_vadduws (vector unsigned int, vector unsigned int);
18947
18948vector signed char vec_vavgsb (vector signed char, vector signed char);
18949
18950vector signed short vec_vavgsh (vector signed short, vector signed short);
18951
18952vector signed int vec_vavgsw (vector signed int, vector signed int);
18953
18954vector unsigned char vec_vavgub (vector unsigned char, vector unsigned char);
18955
18956vector unsigned short vec_vavguh (vector unsigned short, vector unsigned short);
18957
18958vector unsigned int vec_vavguw (vector unsigned int, vector unsigned int);
18959
18960vector float vec_vcfsx (vector signed int, const int);
18961
18962vector float vec_vcfux (vector unsigned int, const int);
18963
18964vector bool int vec_vcmpeqfp (vector float, vector float);
18965
18966vector bool char vec_vcmpequb (vector signed char, vector signed char);
18967vector bool char vec_vcmpequb (vector unsigned char, vector unsigned char);
18968
18969vector bool short vec_vcmpequh (vector signed short, vector signed short);
18970vector bool short vec_vcmpequh (vector unsigned short, vector unsigned short);
18971
18972vector bool int vec_vcmpequw (vector signed int, vector signed int);
18973vector bool int vec_vcmpequw (vector unsigned int, vector unsigned int);
18974
18975vector bool int vec_vcmpgtfp (vector float, vector float);
18976
18977vector bool char vec_vcmpgtsb (vector signed char, vector signed char);
18978
18979vector bool short vec_vcmpgtsh (vector signed short, vector signed short);
18980
18981vector bool int vec_vcmpgtsw (vector signed int, vector signed int);
18982
18983vector bool char vec_vcmpgtub (vector unsigned char, vector unsigned char);
18984
18985vector bool short vec_vcmpgtuh (vector unsigned short, vector unsigned short);
18986
18987vector bool int vec_vcmpgtuw (vector unsigned int, vector unsigned int);
18988
18989vector float vec_vmaxfp (vector float, vector float);
18990
18991vector signed char vec_vmaxsb (vector bool char, vector signed char);
18992vector signed char vec_vmaxsb (vector signed char, vector bool char);
18993vector signed char vec_vmaxsb (vector signed char, vector signed char);
18994
18995vector signed short vec_vmaxsh (vector bool short, vector signed short);
18996vector signed short vec_vmaxsh (vector signed short, vector bool short);
18997vector signed short vec_vmaxsh (vector signed short, vector signed short);
18998
18999vector signed int vec_vmaxsw (vector bool int, vector signed int);
19000vector signed int vec_vmaxsw (vector signed int, vector bool int);
19001vector signed int vec_vmaxsw (vector signed int, vector signed int);
19002
19003vector unsigned char vec_vmaxub (vector bool char, vector unsigned char);
19004vector unsigned char vec_vmaxub (vector unsigned char, vector bool char);
19005vector unsigned char vec_vmaxub (vector unsigned char, vector unsigned char);
19006
19007vector unsigned short vec_vmaxuh (vector bool short, vector unsigned short);
19008vector unsigned short vec_vmaxuh (vector unsigned short, vector bool short);
19009vector unsigned short vec_vmaxuh (vector unsigned short, vector unsigned short);
19010
19011vector unsigned int vec_vmaxuw (vector bool int, vector unsigned int);
19012vector unsigned int vec_vmaxuw (vector unsigned int, vector bool int);
19013vector unsigned int vec_vmaxuw (vector unsigned int, vector unsigned int);
19014
19015vector float vec_vminfp (vector float, vector float);
19016
19017vector signed char vec_vminsb (vector bool char, vector signed char);
19018vector signed char vec_vminsb (vector signed char, vector bool char);
19019vector signed char vec_vminsb (vector signed char, vector signed char);
19020
19021vector signed short vec_vminsh (vector bool short, vector signed short);
19022vector signed short vec_vminsh (vector signed short, vector bool short);
19023vector signed short vec_vminsh (vector signed short, vector signed short);
19024
19025vector signed int vec_vminsw (vector bool int, vector signed int);
19026vector signed int vec_vminsw (vector signed int, vector bool int);
19027vector signed int vec_vminsw (vector signed int, vector signed int);
19028
19029vector unsigned char vec_vminub (vector bool char, vector unsigned char);
19030vector unsigned char vec_vminub (vector unsigned char, vector bool char);
19031vector unsigned char vec_vminub (vector unsigned char, vector unsigned char);
19032
19033vector unsigned short vec_vminuh (vector bool short, vector unsigned short);
19034vector unsigned short vec_vminuh (vector unsigned short, vector bool short);
19035vector unsigned short vec_vminuh (vector unsigned short, vector unsigned short);
19036
19037vector unsigned int vec_vminuw (vector bool int, vector unsigned int);
19038vector unsigned int vec_vminuw (vector unsigned int, vector bool int);
19039vector unsigned int vec_vminuw (vector unsigned int, vector unsigned int);
19040
19041vector bool char vec_vmrghb (vector bool char, vector bool char);
19042vector signed char vec_vmrghb (vector signed char, vector signed char);
19043vector unsigned char vec_vmrghb (vector unsigned char, vector unsigned char);
19044
19045vector bool short vec_vmrghh (vector bool short, vector bool short);
19046vector signed short vec_vmrghh (vector signed short, vector signed short);
19047vector unsigned short vec_vmrghh (vector unsigned short, vector unsigned short);
19048vector pixel vec_vmrghh (vector pixel, vector pixel);
19049
19050vector float vec_vmrghw (vector float, vector float);
19051vector bool int vec_vmrghw (vector bool int, vector bool int);
19052vector signed int vec_vmrghw (vector signed int, vector signed int);
19053vector unsigned int vec_vmrghw (vector unsigned int, vector unsigned int);
19054
19055vector bool char vec_vmrglb (vector bool char, vector bool char);
19056vector signed char vec_vmrglb (vector signed char, vector signed char);
19057vector unsigned char vec_vmrglb (vector unsigned char, vector unsigned char);
19058
19059vector bool short vec_vmrglh (vector bool short, vector bool short);
19060vector signed short vec_vmrglh (vector signed short, vector signed short);
19061vector unsigned short vec_vmrglh (vector unsigned short, vector unsigned short);
19062vector pixel vec_vmrglh (vector pixel, vector pixel);
19063
19064vector float vec_vmrglw (vector float, vector float);
19065vector signed int vec_vmrglw (vector signed int, vector signed int);
19066vector unsigned int vec_vmrglw (vector unsigned int, vector unsigned int);
19067vector bool int vec_vmrglw (vector bool int, vector bool int);
19068
19069vector signed int vec_vmsummbm (vector signed char, vector unsigned char,
19070 vector signed int);
19071
19072vector signed int vec_vmsumshm (vector signed short, vector signed short,
19073 vector signed int);
19074
19075vector signed int vec_vmsumshs (vector signed short, vector signed short,
19076 vector signed int);
19077
19078vector unsigned int vec_vmsumubm (vector unsigned char, vector unsigned char,
19079 vector unsigned int);
19080
19081vector unsigned int vec_vmsumuhm (vector unsigned short, vector unsigned short,
19082 vector unsigned int);
19083
19084vector unsigned int vec_vmsumuhs (vector unsigned short, vector unsigned short,
19085 vector unsigned int);
19086
19087vector signed short vec_vmulesb (vector signed char, vector signed char);
19088
19089vector signed int vec_vmulesh (vector signed short, vector signed short);
19090
19091vector unsigned short vec_vmuleub (vector unsigned char, vector unsigned char);
19092
19093vector unsigned int vec_vmuleuh (vector unsigned short, vector unsigned short);
19094
19095vector signed short vec_vmulosb (vector signed char, vector signed char);
19096
19097vector signed int vec_vmulosh (vector signed short, vector signed short);
19098
19099vector unsigned short vec_vmuloub (vector unsigned char, vector unsigned char);
19100
19101vector unsigned int vec_vmulouh (vector unsigned short, vector unsigned short);
19102
19103vector signed char vec_vpkshss (vector signed short, vector signed short);
19104
19105vector unsigned char vec_vpkshus (vector signed short, vector signed short);
19106
19107vector signed short vec_vpkswss (vector signed int, vector signed int);
19108
19109vector unsigned short vec_vpkswus (vector signed int, vector signed int);
19110
19111vector bool char vec_vpkuhum (vector bool short, vector bool short);
19112vector signed char vec_vpkuhum (vector signed short, vector signed short);
19113vector unsigned char vec_vpkuhum (vector unsigned short, vector unsigned short);
19114
19115vector unsigned char vec_vpkuhus (vector unsigned short, vector unsigned short);
19116
19117vector bool short vec_vpkuwum (vector bool int, vector bool int);
19118vector signed short vec_vpkuwum (vector signed int, vector signed int);
19119vector unsigned short vec_vpkuwum (vector unsigned int, vector unsigned int);
19120
19121vector unsigned short vec_vpkuwus (vector unsigned int, vector unsigned int);
19122
19123vector signed char vec_vrlb (vector signed char, vector unsigned char);
19124vector unsigned char vec_vrlb (vector unsigned char, vector unsigned char);
19125
19126vector signed short vec_vrlh (vector signed short, vector unsigned short);
19127vector unsigned short vec_vrlh (vector unsigned short, vector unsigned short);
19128
19129vector signed int vec_vrlw (vector signed int, vector unsigned int);
19130vector unsigned int vec_vrlw (vector unsigned int, vector unsigned int);
19131
19132vector signed char vec_vslb (vector signed char, vector unsigned char);
19133vector unsigned char vec_vslb (vector unsigned char, vector unsigned char);
19134
19135vector signed short vec_vslh (vector signed short, vector unsigned short);
19136vector unsigned short vec_vslh (vector unsigned short, vector unsigned short);
19137
19138vector signed int vec_vslw (vector signed int, vector unsigned int);
19139vector unsigned int vec_vslw (vector unsigned int, vector unsigned int);
19140
19141vector signed char vec_vspltb (vector signed char, const int);
19142vector unsigned char vec_vspltb (vector unsigned char, const int);
19143vector bool char vec_vspltb (vector bool char, const int);
19144
19145vector bool short vec_vsplth (vector bool short, const int);
19146vector signed short vec_vsplth (vector signed short, const int);
19147vector unsigned short vec_vsplth (vector unsigned short, const int);
19148vector pixel vec_vsplth (vector pixel, const int);
19149
19150vector float vec_vspltw (vector float, const int);
19151vector signed int vec_vspltw (vector signed int, const int);
19152vector unsigned int vec_vspltw (vector unsigned int, const int);
19153vector bool int vec_vspltw (vector bool int, const int);
19154
19155vector signed char vec_vsrab (vector signed char, vector unsigned char);
19156vector unsigned char vec_vsrab (vector unsigned char, vector unsigned char);
19157
19158vector signed short vec_vsrah (vector signed short, vector unsigned short);
19159vector unsigned short vec_vsrah (vector unsigned short, vector unsigned short);
19160
19161vector signed int vec_vsraw (vector signed int, vector unsigned int);
19162vector unsigned int vec_vsraw (vector unsigned int, vector unsigned int);
19163
19164vector signed char vec_vsrb (vector signed char, vector unsigned char);
19165vector unsigned char vec_vsrb (vector unsigned char, vector unsigned char);
19166
19167vector signed short vec_vsrh (vector signed short, vector unsigned short);
19168vector unsigned short vec_vsrh (vector unsigned short, vector unsigned short);
19169
19170vector signed int vec_vsrw (vector signed int, vector unsigned int);
19171vector unsigned int vec_vsrw (vector unsigned int, vector unsigned int);
19172
19173vector float vec_vsubfp (vector float, vector float);
19174
19175vector signed char vec_vsubsbs (vector bool char, vector signed char);
19176vector signed char vec_vsubsbs (vector signed char, vector bool char);
19177vector signed char vec_vsubsbs (vector signed char, vector signed char);
19178
19179vector signed short vec_vsubshs (vector bool short, vector signed short);
19180vector signed short vec_vsubshs (vector signed short, vector bool short);
19181vector signed short vec_vsubshs (vector signed short, vector signed short);
19182
19183vector signed int vec_vsubsws (vector bool int, vector signed int);
19184vector signed int vec_vsubsws (vector signed int, vector bool int);
19185vector signed int vec_vsubsws (vector signed int, vector signed int);
19186
19187vector signed char vec_vsububm (vector bool char, vector signed char);
19188vector signed char vec_vsububm (vector signed char, vector bool char);
19189vector signed char vec_vsububm (vector signed char, vector signed char);
19190vector unsigned char vec_vsububm (vector bool char, vector unsigned char);
19191vector unsigned char vec_vsububm (vector unsigned char, vector bool char);
19192vector unsigned char vec_vsububm (vector unsigned char, vector unsigned char);
19193
19194vector unsigned char vec_vsububs (vector bool char, vector unsigned char);
19195vector unsigned char vec_vsububs (vector unsigned char, vector bool char);
19196vector unsigned char vec_vsububs (vector unsigned char, vector unsigned char);
19197
19198vector signed short vec_vsubuhm (vector bool short, vector signed short);
19199vector signed short vec_vsubuhm (vector signed short, vector bool short);
19200vector signed short vec_vsubuhm (vector signed short, vector signed short);
19201vector unsigned short vec_vsubuhm (vector bool short, vector unsigned short);
19202vector unsigned short vec_vsubuhm (vector unsigned short, vector bool short);
19203vector unsigned short vec_vsubuhm (vector unsigned short, vector unsigned short);
19204
19205vector unsigned short vec_vsubuhs (vector bool short, vector unsigned short);
19206vector unsigned short vec_vsubuhs (vector unsigned short, vector bool short);
19207vector unsigned short vec_vsubuhs (vector unsigned short, vector unsigned short);
19208
19209vector signed int vec_vsubuwm (vector bool int, vector signed int);
19210vector signed int vec_vsubuwm (vector signed int, vector bool int);
19211vector signed int vec_vsubuwm (vector signed int, vector signed int);
19212vector unsigned int vec_vsubuwm (vector bool int, vector unsigned int);
19213vector unsigned int vec_vsubuwm (vector unsigned int, vector bool int);
19214vector unsigned int vec_vsubuwm (vector unsigned int, vector unsigned int);
19215
19216vector unsigned int vec_vsubuws (vector bool int, vector unsigned int);
19217vector unsigned int vec_vsubuws (vector unsigned int, vector bool int);
19218vector unsigned int vec_vsubuws (vector unsigned int, vector unsigned int);
19219
19220vector signed int vec_vsum4sbs (vector signed char, vector signed int);
19221
19222vector signed int vec_vsum4shs (vector signed short, vector signed int);
19223
19224vector unsigned int vec_vsum4ubs (vector unsigned char, vector unsigned int);
19225
19226vector unsigned int vec_vupkhpx (vector pixel);
19227
19228vector bool short vec_vupkhsb (vector bool char);
19229vector signed short vec_vupkhsb (vector signed char);
19230
19231vector bool int vec_vupkhsh (vector bool short);
19232vector signed int vec_vupkhsh (vector signed short);
19233
19234vector unsigned int vec_vupklpx (vector pixel);
19235
19236vector bool short vec_vupklsb (vector bool char);
19237vector signed short vec_vupklsb (vector signed char);
19238
19239vector bool int vec_vupklsh (vector bool short);
19240vector signed int vec_vupklsh (vector signed short);
19241@end smallexample
19242
19243@node PowerPC AltiVec Built-in Functions Available on ISA 2.06
19244@subsubsection PowerPC AltiVec Built-in Functions Available on ISA 2.06
19245
19246The AltiVec built-in functions described in this section are
19247available on the PowerPC family of processors starting with ISA 2.06
19248or later. These are normally enabled by adding @option{-mvsx} to the
19249command line.
19250
19251When @option{-mvsx} is used, the following additional vector types are
19252implemented.
19253
19254@smallexample
19255vector unsigned __int128
19256vector signed __int128
19257vector unsigned long long int
19258vector signed long long int
19259vector double
19260@end smallexample
19261
19262The long long types are only implemented for 64-bit code generation.
19263
19264Only functions excluded from the PVIPR are listed here.
19265
19266@smallexample
19267void vec_dst (const unsigned long *, int, const int);
19268void vec_dst (const long *, int, const int);
19269
19270void vec_dststt (const unsigned long *, int, const int);
19271void vec_dststt (const long *, int, const int);
19272
19273void vec_dstt (const unsigned long *, int, const int);
19274void vec_dstt (const long *, int, const int);
19275
19276vector unsigned char vec_lvsl (int, const unsigned long *);
19277vector unsigned char vec_lvsl (int, const long *);
19278
19279vector unsigned char vec_lvsr (int, const unsigned long *);
19280vector unsigned char vec_lvsr (int, const long *);
19281
19282vector unsigned char vec_lvsl (int, const double *);
19283vector unsigned char vec_lvsr (int, const double *);
19284
19285vector double vec_vsx_ld (int, const vector double *);
19286vector double vec_vsx_ld (int, const double *);
19287vector float vec_vsx_ld (int, const vector float *);
19288vector float vec_vsx_ld (int, const float *);
19289vector bool int vec_vsx_ld (int, const vector bool int *);
19290vector signed int vec_vsx_ld (int, const vector signed int *);
19291vector signed int vec_vsx_ld (int, const int *);
19292vector signed int vec_vsx_ld (int, const long *);
19293vector unsigned int vec_vsx_ld (int, const vector unsigned int *);
19294vector unsigned int vec_vsx_ld (int, const unsigned int *);
19295vector unsigned int vec_vsx_ld (int, const unsigned long *);
19296vector bool short vec_vsx_ld (int, const vector bool short *);
19297vector pixel vec_vsx_ld (int, const vector pixel *);
19298vector signed short vec_vsx_ld (int, const vector signed short *);
19299vector signed short vec_vsx_ld (int, const short *);
19300vector unsigned short vec_vsx_ld (int, const vector unsigned short *);
19301vector unsigned short vec_vsx_ld (int, const unsigned short *);
19302vector bool char vec_vsx_ld (int, const vector bool char *);
19303vector signed char vec_vsx_ld (int, const vector signed char *);
19304vector signed char vec_vsx_ld (int, const signed char *);
19305vector unsigned char vec_vsx_ld (int, const vector unsigned char *);
19306vector unsigned char vec_vsx_ld (int, const unsigned char *);
19307
19308void vec_vsx_st (vector double, int, vector double *);
19309void vec_vsx_st (vector double, int, double *);
19310void vec_vsx_st (vector float, int, vector float *);
19311void vec_vsx_st (vector float, int, float *);
19312void vec_vsx_st (vector signed int, int, vector signed int *);
19313void vec_vsx_st (vector signed int, int, int *);
19314void vec_vsx_st (vector unsigned int, int, vector unsigned int *);
19315void vec_vsx_st (vector unsigned int, int, unsigned int *);
19316void vec_vsx_st (vector bool int, int, vector bool int *);
19317void vec_vsx_st (vector bool int, int, unsigned int *);
19318void vec_vsx_st (vector bool int, int, int *);
19319void vec_vsx_st (vector signed short, int, vector signed short *);
19320void vec_vsx_st (vector signed short, int, short *);
19321void vec_vsx_st (vector unsigned short, int, vector unsigned short *);
19322void vec_vsx_st (vector unsigned short, int, unsigned short *);
19323void vec_vsx_st (vector bool short, int, vector bool short *);
19324void vec_vsx_st (vector bool short, int, unsigned short *);
19325void vec_vsx_st (vector pixel, int, vector pixel *);
19326void vec_vsx_st (vector pixel, int, unsigned short *);
19327void vec_vsx_st (vector pixel, int, short *);
19328void vec_vsx_st (vector bool short, int, short *);
19329void vec_vsx_st (vector signed char, int, vector signed char *);
19330void vec_vsx_st (vector signed char, int, signed char *);
19331void vec_vsx_st (vector unsigned char, int, vector unsigned char *);
19332void vec_vsx_st (vector unsigned char, int, unsigned char *);
19333void vec_vsx_st (vector bool char, int, vector bool char *);
19334void vec_vsx_st (vector bool char, int, unsigned char *);
19335void vec_vsx_st (vector bool char, int, signed char *);
19336
19337vector double vec_xxpermdi (vector double, vector double, const int);
19338vector float vec_xxpermdi (vector float, vector float, const int);
19339vector long long vec_xxpermdi (vector long long, vector long long, const int);
19340vector unsigned long long vec_xxpermdi (vector unsigned long long,
19341 vector unsigned long long, const int);
19342vector int vec_xxpermdi (vector int, vector int, const int);
19343vector unsigned int vec_xxpermdi (vector unsigned int,
19344 vector unsigned int, const int);
19345vector short vec_xxpermdi (vector short, vector short, const int);
19346vector unsigned short vec_xxpermdi (vector unsigned short,
19347 vector unsigned short, const int);
19348vector signed char vec_xxpermdi (vector signed char, vector signed char,
19349 const int);
19350vector unsigned char vec_xxpermdi (vector unsigned char,
19351 vector unsigned char, const int);
19352
19353vector double vec_xxsldi (vector double, vector double, int);
19354vector float vec_xxsldi (vector float, vector float, int);
19355vector long long vec_xxsldi (vector long long, vector long long, int);
19356vector unsigned long long vec_xxsldi (vector unsigned long long,
19357 vector unsigned long long, int);
19358vector int vec_xxsldi (vector int, vector int, int);
19359vector unsigned int vec_xxsldi (vector unsigned int, vector unsigned int, int);
19360vector short vec_xxsldi (vector short, vector short, int);
19361vector unsigned short vec_xxsldi (vector unsigned short,
19362 vector unsigned short, int);
19363vector signed char vec_xxsldi (vector signed char, vector signed char, int);
19364vector unsigned char vec_xxsldi (vector unsigned char,
19365 vector unsigned char, int);
19366@end smallexample
19367
19368Note that the @samp{vec_ld} and @samp{vec_st} built-in functions always
19369generate the AltiVec @samp{LVX} and @samp{STVX} instructions even
19370if the VSX instruction set is available. The @samp{vec_vsx_ld} and
19371@samp{vec_vsx_st} built-in functions always generate the VSX @samp{LXVD2X},
19372@samp{LXVW4X}, @samp{STXVD2X}, and @samp{STXVW4X} instructions.
19373
19374@node PowerPC AltiVec Built-in Functions Available on ISA 2.07
19375@subsubsection PowerPC AltiVec Built-in Functions Available on ISA 2.07
19376
19377If the ISA 2.07 additions to the vector/scalar (power8-vector)
19378instruction set are available, the following additional functions are
19379available for both 32-bit and 64-bit targets. For 64-bit targets, you
19380can use @var{vector long} instead of @var{vector long long},
19381@var{vector bool long} instead of @var{vector bool long long}, and
19382@var{vector unsigned long} instead of @var{vector unsigned long long}.
19383
19384Only functions excluded from the PVIPR are listed here.
19385
19386@smallexample
19387vector long long vec_vaddudm (vector long long, vector long long);
19388vector long long vec_vaddudm (vector bool long long, vector long long);
19389vector long long vec_vaddudm (vector long long, vector bool long long);
19390vector unsigned long long vec_vaddudm (vector unsigned long long,
19391 vector unsigned long long);
19392vector unsigned long long vec_vaddudm (vector bool unsigned long long,
19393 vector unsigned long long);
19394vector unsigned long long vec_vaddudm (vector unsigned long long,
19395 vector bool unsigned long long);
19396
19397vector long long vec_vclz (vector long long);
19398vector unsigned long long vec_vclz (vector unsigned long long);
19399vector int vec_vclz (vector int);
19400vector unsigned int vec_vclz (vector int);
19401vector short vec_vclz (vector short);
19402vector unsigned short vec_vclz (vector unsigned short);
19403vector signed char vec_vclz (vector signed char);
19404vector unsigned char vec_vclz (vector unsigned char);
19405
19406vector signed char vec_vclzb (vector signed char);
19407vector unsigned char vec_vclzb (vector unsigned char);
19408
19409vector long long vec_vclzd (vector long long);
19410vector unsigned long long vec_vclzd (vector unsigned long long);
19411
19412vector short vec_vclzh (vector short);
19413vector unsigned short vec_vclzh (vector unsigned short);
19414
19415vector int vec_vclzw (vector int);
19416vector unsigned int vec_vclzw (vector int);
19417
19418vector signed char vec_vgbbd (vector signed char);
19419vector unsigned char vec_vgbbd (vector unsigned char);
19420
19421vector long long vec_vmaxsd (vector long long, vector long long);
19422
19423vector unsigned long long vec_vmaxud (vector unsigned long long,
19424 unsigned vector long long);
19425
19426vector long long vec_vminsd (vector long long, vector long long);
19427
19428vector unsigned long long vec_vminud (vector long long, vector long long);
19429
19430vector int vec_vpksdss (vector long long, vector long long);
19431vector unsigned int vec_vpksdss (vector long long, vector long long);
19432
19433vector unsigned int vec_vpkudus (vector unsigned long long,
19434 vector unsigned long long);
19435
19436vector int vec_vpkudum (vector long long, vector long long);
19437vector unsigned int vec_vpkudum (vector unsigned long long,
19438 vector unsigned long long);
19439vector bool int vec_vpkudum (vector bool long long, vector bool long long);
19440
19441vector long long vec_vpopcnt (vector long long);
19442vector unsigned long long vec_vpopcnt (vector unsigned long long);
19443vector int vec_vpopcnt (vector int);
19444vector unsigned int vec_vpopcnt (vector int);
19445vector short vec_vpopcnt (vector short);
19446vector unsigned short vec_vpopcnt (vector unsigned short);
19447vector signed char vec_vpopcnt (vector signed char);
19448vector unsigned char vec_vpopcnt (vector unsigned char);
19449
19450vector signed char vec_vpopcntb (vector signed char);
19451vector unsigned char vec_vpopcntb (vector unsigned char);
19452
19453vector long long vec_vpopcntd (vector long long);
19454vector unsigned long long vec_vpopcntd (vector unsigned long long);
19455
19456vector short vec_vpopcnth (vector short);
19457vector unsigned short vec_vpopcnth (vector unsigned short);
19458
19459vector int vec_vpopcntw (vector int);
19460vector unsigned int vec_vpopcntw (vector int);
19461
19462vector long long vec_vrld (vector long long, vector unsigned long long);
19463vector unsigned long long vec_vrld (vector unsigned long long,
19464 vector unsigned long long);
19465
19466vector long long vec_vsld (vector long long, vector unsigned long long);
19467vector long long vec_vsld (vector unsigned long long,
19468 vector unsigned long long);
19469
19470vector long long vec_vsrad (vector long long, vector unsigned long long);
19471vector unsigned long long vec_vsrad (vector unsigned long long,
19472 vector unsigned long long);
19473
19474vector long long vec_vsrd (vector long long, vector unsigned long long);
19475vector unsigned long long char vec_vsrd (vector unsigned long long,
19476 vector unsigned long long);
19477
19478vector long long vec_vsubudm (vector long long, vector long long);
19479vector long long vec_vsubudm (vector bool long long, vector long long);
19480vector long long vec_vsubudm (vector long long, vector bool long long);
19481vector unsigned long long vec_vsubudm (vector unsigned long long,
19482 vector unsigned long long);
19483vector unsigned long long vec_vsubudm (vector bool long long,
19484 vector unsigned long long);
19485vector unsigned long long vec_vsubudm (vector unsigned long long,
19486 vector bool long long);
19487
19488vector long long vec_vupkhsw (vector int);
19489vector unsigned long long vec_vupkhsw (vector unsigned int);
19490
19491vector long long vec_vupklsw (vector int);
19492vector unsigned long long vec_vupklsw (vector int);
19493@end smallexample
19494
19495If the ISA 2.07 additions to the vector/scalar (power8-vector)
19496instruction set are available, the following additional functions are
19497available for 64-bit targets. New vector types
19498(@var{vector __int128} and @var{vector __uint128}) are available
19499to hold the @var{__int128} and @var{__uint128} types to use these
19500builtins.
19501
19502The normal vector extract, and set operations work on
19503@var{vector __int128} and @var{vector __uint128} types,
19504but the index value must be 0.
19505
19506Only functions excluded from the PVIPR are listed here.
19507
19508@smallexample
19509vector __int128 vec_vaddcuq (vector __int128, vector __int128);
19510vector __uint128 vec_vaddcuq (vector __uint128, vector __uint128);
19511
19512vector __int128 vec_vadduqm (vector __int128, vector __int128);
19513vector __uint128 vec_vadduqm (vector __uint128, vector __uint128);
19514
19515vector __int128 vec_vaddecuq (vector __int128, vector __int128,
19516 vector __int128);
19517vector __uint128 vec_vaddecuq (vector __uint128, vector __uint128,
19518 vector __uint128);
19519
19520vector __int128 vec_vaddeuqm (vector __int128, vector __int128,
19521 vector __int128);
19522vector __uint128 vec_vaddeuqm (vector __uint128, vector __uint128,
19523 vector __uint128);
19524
19525vector __int128 vec_vsubecuq (vector __int128, vector __int128,
19526 vector __int128);
19527vector __uint128 vec_vsubecuq (vector __uint128, vector __uint128,
19528 vector __uint128);
19529
19530vector __int128 vec_vsubeuqm (vector __int128, vector __int128,
19531 vector __int128);
19532vector __uint128 vec_vsubeuqm (vector __uint128, vector __uint128,
19533 vector __uint128);
19534
19535vector __int128 vec_vsubcuq (vector __int128, vector __int128);
19536vector __uint128 vec_vsubcuq (vector __uint128, vector __uint128);
19537
19538__int128 vec_vsubuqm (__int128, __int128);
19539__uint128 vec_vsubuqm (__uint128, __uint128);
19540
19541vector __int128 __builtin_bcdadd (vector __int128, vector __int128, const int);
19542vector unsigned char __builtin_bcdadd (vector unsigned char, vector unsigned char,
19543 const int);
19544int __builtin_bcdadd_lt (vector __int128, vector __int128, const int);
19545int __builtin_bcdadd_lt (vector unsigned char, vector unsigned char, const int);
19546int __builtin_bcdadd_eq (vector __int128, vector __int128, const int);
19547int __builtin_bcdadd_eq (vector unsigned char, vector unsigned char, const int);
19548int __builtin_bcdadd_gt (vector __int128, vector __int128, const int);
19549int __builtin_bcdadd_gt (vector unsigned char, vector unsigned char, const int);
19550int __builtin_bcdadd_ov (vector __int128, vector __int128, const int);
19551int __builtin_bcdadd_ov (vector unsigned char, vector unsigned char, const int);
19552
19553vector __int128 __builtin_bcdsub (vector __int128, vector __int128, const int);
19554vector unsigned char __builtin_bcdsub (vector unsigned char, vector unsigned char,
19555 const int);
19556int __builtin_bcdsub_lt (vector __int128, vector __int128, const int);
19557int __builtin_bcdsub_lt (vector unsigned char, vector unsigned char, const int);
19558int __builtin_bcdsub_eq (vector __int128, vector __int128, const int);
19559int __builtin_bcdsub_eq (vector unsigned char, vector unsigned char, const int);
19560int __builtin_bcdsub_gt (vector __int128, vector __int128, const int);
19561int __builtin_bcdsub_gt (vector unsigned char, vector unsigned char, const int);
19562int __builtin_bcdsub_ov (vector __int128, vector __int128, const int);
19563int __builtin_bcdsub_ov (vector unsigned char, vector unsigned char, const int);
19564@end smallexample
19565
19566@node PowerPC AltiVec Built-in Functions Available on ISA 3.0
19567@subsubsection PowerPC AltiVec Built-in Functions Available on ISA 3.0
19568
19569The following additional built-in functions are also available for the
19570PowerPC family of processors, starting with ISA 3.0
19571(@option{-mcpu=power9}) or later.
19572
19573Only instructions excluded from the PVIPR are listed here.
19574
19575@smallexample
19576unsigned int scalar_extract_exp (double source);
19577unsigned long long int scalar_extract_exp (__ieee128 source);
19578
19579unsigned long long int scalar_extract_sig (double source);
19580unsigned __int128 scalar_extract_sig (__ieee128 source);
19581
19582double scalar_insert_exp (unsigned long long int significand,
19583 unsigned long long int exponent);
19584double scalar_insert_exp (double significand, unsigned long long int exponent);
19585
19586ieee_128 scalar_insert_exp (unsigned __int128 significand,
19587 unsigned long long int exponent);
19588ieee_128 scalar_insert_exp (ieee_128 significand, unsigned long long int exponent);
19589
19590int scalar_cmp_exp_gt (double arg1, double arg2);
19591int scalar_cmp_exp_lt (double arg1, double arg2);
19592int scalar_cmp_exp_eq (double arg1, double arg2);
19593int scalar_cmp_exp_unordered (double arg1, double arg2);
19594
19595bool scalar_test_data_class (float source, const int condition);
19596bool scalar_test_data_class (double source, const int condition);
19597bool scalar_test_data_class (__ieee128 source, const int condition);
19598
19599bool scalar_test_neg (float source);
19600bool scalar_test_neg (double source);
19601bool scalar_test_neg (__ieee128 source);
19602@end smallexample
19603
19604The @code{scalar_extract_exp} and @code{scalar_extract_sig}
19605functions require a 64-bit environment supporting ISA 3.0 or later.
19606The @code{scalar_extract_exp} and @code{scalar_extract_sig} built-in
19607functions return the significand and the biased exponent value
19608respectively of their @code{source} arguments.
19609When supplied with a 64-bit @code{source} argument, the
19610result returned by @code{scalar_extract_sig} has
19611the @code{0x0010000000000000} bit set if the
19612function's @code{source} argument is in normalized form.
19613Otherwise, this bit is set to 0.
19614When supplied with a 128-bit @code{source} argument, the
19615@code{0x00010000000000000000000000000000} bit of the result is
19616treated similarly.
19617Note that the sign of the significand is not represented in the result
19618returned from the @code{scalar_extract_sig} function. Use the
19619@code{scalar_test_neg} function to test the sign of its @code{double}
19620argument.
19621
19622The @code{scalar_insert_exp}
19623functions require a 64-bit environment supporting ISA 3.0 or later.
19624When supplied with a 64-bit first argument, the
19625@code{scalar_insert_exp} built-in function returns a double-precision
19626floating point value that is constructed by assembling the values of its
19627@code{significand} and @code{exponent} arguments. The sign of the
19628result is copied from the most significant bit of the
19629@code{significand} argument. The significand and exponent components
19630of the result are composed of the least significant 11 bits of the
19631@code{exponent} argument and the least significant 52 bits of the
19632@code{significand} argument respectively.
19633
19634When supplied with a 128-bit first argument, the
19635@code{scalar_insert_exp} built-in function returns a quad-precision
19636ieee floating point value. The sign bit of the result is copied from
19637the most significant bit of the @code{significand} argument.
19638The significand and exponent components of the result are composed of
19639the least significant 15 bits of the @code{exponent} argument and the
19640least significant 112 bits of the @code{significand} argument respectively.
19641
19642The @code{scalar_cmp_exp_gt}, @code{scalar_cmp_exp_lt},
19643@code{scalar_cmp_exp_eq}, and @code{scalar_cmp_exp_unordered} built-in
19644functions return a non-zero value if @code{arg1} is greater than, less
19645than, equal to, or not comparable to @code{arg2} respectively. The
19646arguments are not comparable if one or the other equals NaN (not a
19647number).
19648
19649The @code{scalar_test_data_class} built-in function returns 1
19650if any of the condition tests enabled by the value of the
19651@code{condition} variable are true, and 0 otherwise. The
19652@code{condition} argument must be a compile-time constant integer with
19653value not exceeding 127. The
19654@code{condition} argument is encoded as a bitmask with each bit
19655enabling the testing of a different condition, as characterized by the
19656following:
19657@smallexample
196580x40 Test for NaN
196590x20 Test for +Infinity
196600x10 Test for -Infinity
196610x08 Test for +Zero
196620x04 Test for -Zero
196630x02 Test for +Denormal
196640x01 Test for -Denormal
19665@end smallexample
19666
19667The @code{scalar_test_neg} built-in function returns 1 if its
19668@code{source} argument holds a negative value, 0 otherwise.
19669
19670The following built-in functions are also available for the PowerPC family
19671of processors, starting with ISA 3.0 or later
19672(@option{-mcpu=power9}). These string functions are described
19673separately in order to group the descriptions closer to the function
19674prototypes.
19675
19676Only functions excluded from the PVIPR are listed here.
19677
19678@smallexample
19679int vec_all_nez (vector signed char, vector signed char);
19680int vec_all_nez (vector unsigned char, vector unsigned char);
19681int vec_all_nez (vector signed short, vector signed short);
19682int vec_all_nez (vector unsigned short, vector unsigned short);
19683int vec_all_nez (vector signed int, vector signed int);
19684int vec_all_nez (vector unsigned int, vector unsigned int);
19685
19686int vec_any_eqz (vector signed char, vector signed char);
19687int vec_any_eqz (vector unsigned char, vector unsigned char);
19688int vec_any_eqz (vector signed short, vector signed short);
19689int vec_any_eqz (vector unsigned short, vector unsigned short);
19690int vec_any_eqz (vector signed int, vector signed int);
19691int vec_any_eqz (vector unsigned int, vector unsigned int);
19692
19693signed char vec_xlx (unsigned int index, vector signed char data);
19694unsigned char vec_xlx (unsigned int index, vector unsigned char data);
19695signed short vec_xlx (unsigned int index, vector signed short data);
19696unsigned short vec_xlx (unsigned int index, vector unsigned short data);
19697signed int vec_xlx (unsigned int index, vector signed int data);
19698unsigned int vec_xlx (unsigned int index, vector unsigned int data);
19699float vec_xlx (unsigned int index, vector float data);
19700
19701signed char vec_xrx (unsigned int index, vector signed char data);
19702unsigned char vec_xrx (unsigned int index, vector unsigned char data);
19703signed short vec_xrx (unsigned int index, vector signed short data);
19704unsigned short vec_xrx (unsigned int index, vector unsigned short data);
19705signed int vec_xrx (unsigned int index, vector signed int data);
19706unsigned int vec_xrx (unsigned int index, vector unsigned int data);
19707float vec_xrx (unsigned int index, vector float data);
19708@end smallexample
19709
19710The @code{vec_all_nez}, @code{vec_any_eqz}, and @code{vec_cmpnez}
19711perform pairwise comparisons between the elements at the same
19712positions within their two vector arguments.
19713The @code{vec_all_nez} function returns a
19714non-zero value if and only if all pairwise comparisons are not
19715equal and no element of either vector argument contains a zero.
19716The @code{vec_any_eqz} function returns a
19717non-zero value if and only if at least one pairwise comparison is equal
19718or if at least one element of either vector argument contains a zero.
19719The @code{vec_cmpnez} function returns a vector of the same type as
19720its two arguments, within which each element consists of all ones to
19721denote that either the corresponding elements of the incoming arguments are
19722not equal or that at least one of the corresponding elements contains
19723zero. Otherwise, the element of the returned vector contains all zeros.
19724
19725The @code{vec_xlx} and @code{vec_xrx} functions extract the single
19726element selected by the @code{index} argument from the vector
19727represented by the @code{data} argument. The @code{index} argument
19728always specifies a byte offset, regardless of the size of the vector
19729element. With @code{vec_xlx}, @code{index} is the offset of the first
19730byte of the element to be extracted. With @code{vec_xrx}, @code{index}
19731represents the last byte of the element to be extracted, measured
19732from the right end of the vector. In other words, the last byte of
19733the element to be extracted is found at position @code{(15 - index)}.
19734There is no requirement that @code{index} be a multiple of the vector
19735element size. However, if the size of the vector element added to
19736@code{index} is greater than 15, the content of the returned value is
19737undefined.
19738
19739The following functions are also available if the ISA 3.0 instruction
19740set additions (@option{-mcpu=power9}) are available.
19741
19742Only functions excluded from the PVIPR are listed here.
19743
19744@smallexample
19745vector long long vec_vctz (vector long long);
19746vector unsigned long long vec_vctz (vector unsigned long long);
19747vector int vec_vctz (vector int);
19748vector unsigned int vec_vctz (vector int);
19749vector short vec_vctz (vector short);
19750vector unsigned short vec_vctz (vector unsigned short);
19751vector signed char vec_vctz (vector signed char);
19752vector unsigned char vec_vctz (vector unsigned char);
19753
19754vector signed char vec_vctzb (vector signed char);
19755vector unsigned char vec_vctzb (vector unsigned char);
19756
19757vector long long vec_vctzd (vector long long);
19758vector unsigned long long vec_vctzd (vector unsigned long long);
19759
19760vector short vec_vctzh (vector short);
19761vector unsigned short vec_vctzh (vector unsigned short);
19762
19763vector int vec_vctzw (vector int);
19764vector unsigned int vec_vctzw (vector int);
19765
19766vector int vec_vprtyb (vector int);
19767vector unsigned int vec_vprtyb (vector unsigned int);
19768vector long long vec_vprtyb (vector long long);
19769vector unsigned long long vec_vprtyb (vector unsigned long long);
19770
19771vector int vec_vprtybw (vector int);
19772vector unsigned int vec_vprtybw (vector unsigned int);
19773
19774vector long long vec_vprtybd (vector long long);
19775vector unsigned long long vec_vprtybd (vector unsigned long long);
19776@end smallexample
19777
19778On 64-bit targets, if the ISA 3.0 additions (@option{-mcpu=power9})
19779are available:
19780
19781@smallexample
19782vector long vec_vprtyb (vector long);
19783vector unsigned long vec_vprtyb (vector unsigned long);
19784vector __int128 vec_vprtyb (vector __int128);
19785vector __uint128 vec_vprtyb (vector __uint128);
19786
19787vector long vec_vprtybd (vector long);
19788vector unsigned long vec_vprtybd (vector unsigned long);
19789
19790vector __int128 vec_vprtybq (vector __int128);
19791vector __uint128 vec_vprtybd (vector __uint128);
19792@end smallexample
19793
19794The following built-in functions are available for the PowerPC family
19795of processors, starting with ISA 3.0 or later (@option{-mcpu=power9}).
19796
19797Only functions excluded from the PVIPR are listed here.
19798
19799@smallexample
19800__vector unsigned char
19801vec_absdb (__vector unsigned char arg1, __vector unsigned char arg2);
19802__vector unsigned short
19803vec_absdh (__vector unsigned short arg1, __vector unsigned short arg2);
19804__vector unsigned int
19805vec_absdw (__vector unsigned int arg1, __vector unsigned int arg2);
19806@end smallexample
19807
19808The @code{vec_absd}, @code{vec_absdb}, @code{vec_absdh}, and
19809@code{vec_absdw} built-in functions each computes the absolute
19810differences of the pairs of vector elements supplied in its two vector
19811arguments, placing the absolute differences into the corresponding
19812elements of the vector result.
19813
19814The following built-in functions are available for the PowerPC family
19815of processors, starting with ISA 3.0 or later (@option{-mcpu=power9}):
19816@smallexample
19817vector unsigned int vec_vrlnm (vector unsigned int, vector unsigned int);
19818vector unsigned long long vec_vrlnm (vector unsigned long long,
19819 vector unsigned long long);
19820@end smallexample
19821
19822The result of @code{vec_vrlnm} is obtained by rotating each element
19823of the first argument vector left and ANDing it with a mask. The
19824second argument vector contains the mask beginning in bits 11:15,
19825the mask end in bits 19:23, and the shift count in bits 27:31,
19826of each element.
19827
19828If the cryptographic instructions are enabled (@option{-mcrypto} or
19829@option{-mcpu=power8}), the following builtins are enabled.
19830
19831Only functions excluded from the PVIPR are listed here.
19832
19833@smallexample
19834vector unsigned long long __builtin_crypto_vsbox (vector unsigned long long);
19835
19836vector unsigned long long __builtin_crypto_vcipher (vector unsigned long long,
19837 vector unsigned long long);
19838
19839vector unsigned long long __builtin_crypto_vcipherlast
19840 (vector unsigned long long,
19841 vector unsigned long long);
19842
19843vector unsigned long long __builtin_crypto_vncipher (vector unsigned long long,
19844 vector unsigned long long);
19845
19846vector unsigned long long __builtin_crypto_vncipherlast (vector unsigned long long,
19847 vector unsigned long long);
19848
19849vector unsigned char __builtin_crypto_vpermxor (vector unsigned char,
19850 vector unsigned char,
19851 vector unsigned char);
19852
19853vector unsigned short __builtin_crypto_vpermxor (vector unsigned short,
19854 vector unsigned short,
19855 vector unsigned short);
19856
19857vector unsigned int __builtin_crypto_vpermxor (vector unsigned int,
19858 vector unsigned int,
19859 vector unsigned int);
19860
19861vector unsigned long long __builtin_crypto_vpermxor (vector unsigned long long,
19862 vector unsigned long long,
19863 vector unsigned long long);
19864
19865vector unsigned char __builtin_crypto_vpmsumb (vector unsigned char,
19866 vector unsigned char);
19867
19868vector unsigned short __builtin_crypto_vpmsumh (vector unsigned short,
19869 vector unsigned short);
19870
19871vector unsigned int __builtin_crypto_vpmsumw (vector unsigned int,
19872 vector unsigned int);
19873
19874vector unsigned long long __builtin_crypto_vpmsumd (vector unsigned long long,
19875 vector unsigned long long);
19876
19877vector unsigned long long __builtin_crypto_vshasigmad (vector unsigned long long,
19878 int, int);
19879
19880vector unsigned int __builtin_crypto_vshasigmaw (vector unsigned int, int, int);
19881@end smallexample
19882
19883The second argument to @var{__builtin_crypto_vshasigmad} and
19884@var{__builtin_crypto_vshasigmaw} must be a constant
19885integer that is 0 or 1. The third argument to these built-in functions
19886must be a constant integer in the range of 0 to 15.
19887
19888The following sign extension builtins are provided:
19889
19890@smallexample
19891vector signed int vec_signexti (vector signed char a);
19892vector signed long long vec_signextll (vector signed char a);
19893vector signed int vec_signexti (vector signed short a);
19894vector signed long long vec_signextll (vector signed short a);
19895vector signed long long vec_signextll (vector signed int a);
19896vector signed long long vec_signextq (vector signed long long a);
19897@end smallexample
19898
19899Each element of the result is produced by sign-extending the element of the
19900input vector that would fall in the least significant portion of the result
19901element. For example, a sign-extension of a vector signed char to a vector
19902signed long long will sign extend the rightmost byte of each doubleword.
19903
19904@node PowerPC AltiVec Built-in Functions Available on ISA 3.1
19905@subsubsection PowerPC AltiVec Built-in Functions Available on ISA 3.1
19906
19907The following additional built-in functions are also available for the
19908PowerPC family of processors, starting with ISA 3.1 (@option{-mcpu=power10}):
19909
19910
19911@smallexample
19912@exdent vector unsigned long long int
19913@exdent vec_cfuge (vector unsigned long long int, vector unsigned long long int);
19914@end smallexample
19915Perform a vector centrifuge operation, as if implemented by the
19916@code{vcfuged} instruction.
19917@findex vec_cfuge
19918
19919@smallexample
19920@exdent vector unsigned long long int
19921@exdent vec_cntlzm (vector unsigned long long int, vector unsigned long long int);
19922@end smallexample
19923Perform a vector count leading zeros under bit mask operation, as if
19924implemented by the @code{vclzdm} instruction.
19925@findex vec_cntlzm
19926
19927@smallexample
19928@exdent vector unsigned long long int
19929@exdent vec_cnttzm (vector unsigned long long int, vector unsigned long long int);
19930@end smallexample
19931Perform a vector count trailing zeros under bit mask operation, as if
19932implemented by the @code{vctzdm} instruction.
19933@findex vec_cnttzm
19934
19935@smallexample
19936@exdent vector signed char
19937@exdent vec_clrl (vector signed char a, unsigned int n);
19938@exdent vector unsigned char
19939@exdent vec_clrl (vector unsigned char a, unsigned int n);
19940@end smallexample
19941Clear the left-most @code{(16 - n)} bytes of vector argument @code{a}, as if
19942implemented by the @code{vclrlb} instruction on a big-endian target
19943and by the @code{vclrrb} instruction on a little-endian target. A
19944value of @code{n} that is greater than 16 is treated as if it equaled 16.
19945@findex vec_clrl
19946
19947@smallexample
19948@exdent vector signed char
19949@exdent vec_clrr (vector signed char a, unsigned int n);
19950@exdent vector unsigned char
19951@exdent vec_clrr (vector unsigned char a, unsigned int n);
19952@end smallexample
19953Clear the right-most @code{(16 - n)} bytes of vector argument @code{a}, as if
19954implemented by the @code{vclrrb} instruction on a big-endian target
19955and by the @code{vclrlb} instruction on a little-endian target. A
19956value of @code{n} that is greater than 16 is treated as if it equaled 16.
19957@findex vec_clrr
19958
19959@smallexample
19960@exdent vector unsigned long long int
19961@exdent vec_gnb (vector unsigned __int128, const unsigned char);
19962@end smallexample
19963Perform a 128-bit vector gather operation, as if implemented by the
19964@code{vgnb} instruction. The second argument must be a literal
19965integer value between 2 and 7 inclusive.
19966@findex vec_gnb
19967
19968
19969Vector Extract
19970
19971@smallexample
19972@exdent vector unsigned long long int
19973@exdent vec_extractl (vector unsigned char, vector unsigned char, unsigned int);
19974@exdent vector unsigned long long int
19975@exdent vec_extractl (vector unsigned short, vector unsigned short, unsigned int);
19976@exdent vector unsigned long long int
19977@exdent vec_extractl (vector unsigned int, vector unsigned int, unsigned int);
19978@exdent vector unsigned long long int
19979@exdent vec_extractl (vector unsigned long long, vector unsigned long long, unsigned int);
19980@end smallexample
19981Extract an element from two concatenated vectors starting at the given byte index
19982in natural-endian order, and place it zero-extended in doubleword 1 of the result
19983according to natural element order. If the byte index is out of range for the
19984data type, the intrinsic will be rejected.
19985For little-endian, this output will match the placement by the hardware
19986instruction, i.e., dword[0] in RTL notation. For big-endian, an additional
19987instruction is needed to move it from the "left" doubleword to the "right" one.
19988For little-endian, semantics matching the @code{vextdubvrx},
19989@code{vextduhvrx}, @code{vextduwvrx} instruction will be generated, while for
19990big-endian, semantics matching the @code{vextdubvlx}, @code{vextduhvlx},
19991@code{vextduwvlx} instructions
19992will be generated. Note that some fairly anomalous results can be generated if
19993the byte index is not aligned on an element boundary for the element being
19994extracted. This is a limitation of the bi-endian vector programming model is
19995consistent with the limitation on @code{vec_perm}.
19996@findex vec_extractl
19997
19998@smallexample
19999@exdent vector unsigned long long int
20000@exdent vec_extracth (vector unsigned char, vector unsigned char, unsigned int);
20001@exdent vector unsigned long long int
20002@exdent vec_extracth (vector unsigned short, vector unsigned short,
20003unsigned int);
20004@exdent vector unsigned long long int
20005@exdent vec_extracth (vector unsigned int, vector unsigned int, unsigned int);
20006@exdent vector unsigned long long int
20007@exdent vec_extracth (vector unsigned long long, vector unsigned long long,
20008unsigned int);
20009@end smallexample
20010Extract an element from two concatenated vectors starting at the given byte
20011index. The index is based on big endian order for a little endian system.
20012Similarly, the index is based on little endian order for a big endian system.
20013The extraced elements are zero-extended and put in doubleword 1
20014according to natural element order. If the byte index is out of range for the
20015data type, the intrinsic will be rejected. For little-endian, this output
20016will match the placement by the hardware instruction (vextdubvrx, vextduhvrx,
20017vextduwvrx, vextddvrx) i.e., dword[0] in RTL
20018notation. For big-endian, an additional instruction is needed to move it
20019from the "left" doubleword to the "right" one. For little-endian, semantics
20020matching the @code{vextdubvlx}, @code{vextduhvlx}, @code{vextduwvlx}
20021instructions will be generated, while for big-endian, semantics matching the
20022@code{vextdubvrx}, @code{vextduhvrx}, @code{vextduwvrx} instructions will
20023be generated. Note that some fairly anomalous
20024results can be generated if the byte index is not aligned on the
20025element boundary for the element being extracted. This is a
20026limitation of the bi-endian vector programming model consistent with the
20027limitation on @code{vec_perm}.
20028@findex vec_extracth
20029@smallexample
20030@exdent vector unsigned long long int
20031@exdent vec_pdep (vector unsigned long long int, vector unsigned long long int);
20032@end smallexample
20033Perform a vector parallel bits deposit operation, as if implemented by
20034the @code{vpdepd} instruction.
20035@findex vec_pdep
20036
20037Vector Insert
20038
20039@smallexample
20040@exdent vector unsigned char
20041@exdent vec_insertl (unsigned char, vector unsigned char, unsigned int);
20042@exdent vector unsigned short
20043@exdent vec_insertl (unsigned short, vector unsigned short, unsigned int);
20044@exdent vector unsigned int
20045@exdent vec_insertl (unsigned int, vector unsigned int, unsigned int);
20046@exdent vector unsigned long long
20047@exdent vec_insertl (unsigned long long, vector unsigned long long,
20048unsigned int);
20049@exdent vector unsigned char
20050@exdent vec_insertl (vector unsigned char, vector unsigned char, unsigned int;
20051@exdent vector unsigned short
20052@exdent vec_insertl (vector unsigned short, vector unsigned short,
20053unsigned int);
20054@exdent vector unsigned int
20055@exdent vec_insertl (vector unsigned int, vector unsigned int, unsigned int);
20056@end smallexample
20057
20058Let src be the first argument, when the first argument is a scalar, or the
20059rightmost element of the left doubleword of the first argument, when the first
20060argument is a vector. Insert the source into the destination at the position
20061given by the third argument, using natural element order in the second
20062argument. The rest of the second argument is unchanged. If the byte
20063index is greater than 14 for halfwords, greater than 12 for words, or
20064greater than 8 for doublewords the result is undefined. For little-endian,
20065the generated code will be semantically equivalent to @code{vins[bhwd]rx}
20066instructions. Similarly for big-endian it will be semantically equivalent
20067to @code{vins[bhwd]lx}. Note that some fairly anomalous results can be
20068generated if the byte index is not aligned on an element boundary for the
20069type of element being inserted.
20070@findex vec_insertl
20071
20072@smallexample
20073@exdent vector unsigned char
20074@exdent vec_inserth (unsigned char, vector unsigned char, unsigned int);
20075@exdent vector unsigned short
20076@exdent vec_inserth (unsigned short, vector unsigned short, unsigned int);
20077@exdent vector unsigned int
20078@exdent vec_inserth (unsigned int, vector unsigned int, unsigned int);
20079@exdent vector unsigned long long
20080@exdent vec_inserth (unsigned long long, vector unsigned long long,
20081unsigned int);
20082@exdent vector unsigned char
20083@exdent vec_inserth (vector unsigned char, vector unsigned char, unsigned int);
20084@exdent vector unsigned short
20085@exdent vec_inserth (vector unsigned short, vector unsigned short,
20086unsigned int);
20087@exdent vector unsigned int
20088@exdent vec_inserth (vector unsigned int, vector unsigned int, unsigned int);
20089@end smallexample
20090
20091Let src be the first argument, when the first argument is a scalar, or the
20092rightmost element of the first argument, when the first argument is a vector.
20093Insert src into the second argument at the position identified by the third
20094argument, using opposite element order in the second argument, and leaving the
20095rest of the second argument unchanged. If the byte index is greater than 14
20096for halfwords, 12 for words, or 8 for doublewords, the intrinsic will be
20097rejected. Note that the underlying hardware instruction uses the same register
20098for the second argument and the result.
20099For little-endian, the code generation will be semantically equivalent to
20100@code{vins[bhwd]lx}, while for big-endian it will be semantically equivalent to
20101@code{vins[bhwd]rx}.
20102Note that some fairly anomalous results can be generated if the byte index is
20103not aligned on an element boundary for the sort of element being inserted.
20104@findex vec_inserth
20105
20106Vector Replace Element
20107@smallexample
20108@exdent vector signed int vec_replace_elt (vector signed int, signed int,
20109const int);
20110@exdent vector unsigned int vec_replace_elt (vector unsigned int,
20111unsigned int, const int);
20112@exdent vector float vec_replace_elt (vector float, float, const int);
20113@exdent vector signed long long vec_replace_elt (vector signed long long,
20114signed long long, const int);
20115@exdent vector unsigned long long vec_replace_elt (vector unsigned long long,
20116unsigned long long, const int);
20117@exdent vector double rec_replace_elt (vector double, double, const int);
20118@end smallexample
20119The third argument (constrained to [0,3]) identifies the natural-endian
20120element number of the first argument that will be replaced by the second
20121argument to produce the result. The other elements of the first argument will
20122remain unchanged in the result.
20123
20124If it's desirable to insert a word at an unaligned position, use
20125vec_replace_unaligned instead.
20126
20127@findex vec_replace_element
20128
20129Vector Replace Unaligned
20130@smallexample
20131@exdent vector unsigned char vec_replace_unaligned (vector unsigned char,
20132signed int, const int);
20133@exdent vector unsigned char vec_replace_unaligned (vector unsigned char,
20134unsigned int, const int);
20135@exdent vector unsigned char vec_replace_unaligned (vector unsigned char,
20136float, const int);
20137@exdent vector unsigned char vec_replace_unaligned (vector unsigned char,
20138signed long long, const int);
20139@exdent vector unsigned char vec_replace_unaligned (vector unsigned char,
20140unsigned long long, const int);
20141@exdent vector unsigned char vec_replace_unaligned (vector unsigned char,
20142double, const int);
20143@end smallexample
20144
20145The second argument replaces a portion of the first argument to produce the
20146result, with the rest of the first argument unchanged in the result. The
20147third argument identifies the byte index (using left-to-right, or big-endian
20148order) where the high-order byte of the second argument will be placed, with
20149the remaining bytes of the second argument placed naturally "to the right"
20150of the high-order byte.
20151
20152The programmer is responsible for understanding the endianness issues involved
20153with the first argument and the result.
20154@findex vec_replace_unaligned
20155
20156Vector Shift Left Double Bit Immediate
20157@smallexample
20158@exdent vector signed char vec_sldb (vector signed char, vector signed char,
20159const unsigned int);
20160@exdent vector unsigned char vec_sldb (vector unsigned char,
20161vector unsigned char, const unsigned int);
20162@exdent vector signed short vec_sldb (vector signed short, vector signed short,
20163const unsigned int);
20164@exdent vector unsigned short vec_sldb (vector unsigned short,
20165vector unsigned short, const unsigned int);
20166@exdent vector signed int vec_sldb (vector signed int, vector signed int,
20167const unsigned int);
20168@exdent vector unsigned int vec_sldb (vector unsigned int, vector unsigned int,
20169const unsigned int);
20170@exdent vector signed long long vec_sldb (vector signed long long,
20171vector signed long long, const unsigned int);
20172@exdent vector unsigned long long vec_sldb (vector unsigned long long,
20173vector unsigned long long, const unsigned int);
20174@end smallexample
20175
20176Shift the combined input vectors left by the amount specified by the low-order
20177three bits of the third argument, and return the leftmost remaining 128 bits.
20178Code using this instruction must be endian-aware.
20179
20180@findex vec_sldb
20181
20182Vector Shift Right Double Bit Immediate
20183
20184@smallexample
20185@exdent vector signed char vec_srdb (vector signed char, vector signed char,
20186const unsigned int);
20187@exdent vector unsigned char vec_srdb (vector unsigned char, vector unsigned char,
20188const unsigned int);
20189@exdent vector signed short vec_srdb (vector signed short, vector signed short,
20190const unsigned int);
20191@exdent vector unsigned short vec_srdb (vector unsigned short, vector unsigned short,
20192const unsigned int);
20193@exdent vector signed int vec_srdb (vector signed int, vector signed int,
20194const unsigned int);
20195@exdent vector unsigned int vec_srdb (vector unsigned int, vector unsigned int,
20196const unsigned int);
20197@exdent vector signed long long vec_srdb (vector signed long long,
20198vector signed long long, const unsigned int);
20199@exdent vector unsigned long long vec_srdb (vector unsigned long long,
20200vector unsigned long long, const unsigned int);
20201@end smallexample
20202
20203Shift the combined input vectors right by the amount specified by the low-order
20204three bits of the third argument, and return the remaining 128 bits. Code
20205using this built-in must be endian-aware.
20206
20207@findex vec_srdb
20208
20209Vector Splat
20210
20211@smallexample
20212@exdent vector signed int vec_splati (const signed int);
20213@exdent vector float vec_splati (const float);
20214@end smallexample
20215
20216Splat a 32-bit immediate into a vector of words.
20217
20218@findex vec_splati
20219
20220@smallexample
20221@exdent vector double vec_splatid (const float);
20222@end smallexample
20223
20224Convert a single precision floating-point value to double-precision and splat
20225the result to a vector of double-precision floats.
20226
20227@findex vec_splatid
20228
20229@smallexample
20230@exdent vector signed int vec_splati_ins (vector signed int,
20231const unsigned int, const signed int);
20232@exdent vector unsigned int vec_splati_ins (vector unsigned int,
20233const unsigned int, const unsigned int);
20234@exdent vector float vec_splati_ins (vector float, const unsigned int,
20235const float);
20236@end smallexample
20237
20238Argument 2 must be either 0 or 1. Splat the value of argument 3 into the word
20239identified by argument 2 of each doubleword of argument 1 and return the
20240result. The other words of argument 1 are unchanged.
20241
20242@findex vec_splati_ins
20243
20244Vector Blend Variable
20245
20246@smallexample
20247@exdent vector signed char vec_blendv (vector signed char, vector signed char,
20248vector unsigned char);
20249@exdent vector unsigned char vec_blendv (vector unsigned char,
20250vector unsigned char, vector unsigned char);
20251@exdent vector signed short vec_blendv (vector signed short,
20252vector signed short, vector unsigned short);
20253@exdent vector unsigned short vec_blendv (vector unsigned short,
20254vector unsigned short, vector unsigned short);
20255@exdent vector signed int vec_blendv (vector signed int, vector signed int,
20256vector unsigned int);
20257@exdent vector unsigned int vec_blendv (vector unsigned int,
20258vector unsigned int, vector unsigned int);
20259@exdent vector signed long long vec_blendv (vector signed long long,
20260vector signed long long, vector unsigned long long);
20261@exdent vector unsigned long long vec_blendv (vector unsigned long long,
20262vector unsigned long long, vector unsigned long long);
20263@exdent vector float vec_blendv (vector float, vector float,
20264vector unsigned int);
20265@exdent vector double vec_blendv (vector double, vector double,
20266vector unsigned long long);
20267@end smallexample
20268
20269Blend the first and second argument vectors according to the sign bits of the
20270corresponding elements of the third argument vector. This is similar to the
20271@code{vsel} and @code{xxsel} instructions but for bigger elements.
20272
20273@findex vec_blendv
20274
20275Vector Permute Extended
20276
20277@smallexample
20278@exdent vector signed char vec_permx (vector signed char, vector signed char,
20279vector unsigned char, const int);
20280@exdent vector unsigned char vec_permx (vector unsigned char,
20281vector unsigned char, vector unsigned char, const int);
20282@exdent vector signed short vec_permx (vector signed short,
20283vector signed short, vector unsigned char, const int);
20284@exdent vector unsigned short vec_permx (vector unsigned short,
20285vector unsigned short, vector unsigned char, const int);
20286@exdent vector signed int vec_permx (vector signed int, vector signed int,
20287vector unsigned char, const int);
20288@exdent vector unsigned int vec_permx (vector unsigned int,
20289vector unsigned int, vector unsigned char, const int);
20290@exdent vector signed long long vec_permx (vector signed long long,
20291vector signed long long, vector unsigned char, const int);
20292@exdent vector unsigned long long vec_permx (vector unsigned long long,
20293vector unsigned long long, vector unsigned char, const int);
20294@exdent vector float (vector float, vector float, vector unsigned char,
20295const int);
20296@exdent vector double (vector double, vector double, vector unsigned char,
20297const int);
20298@end smallexample
20299
20300Perform a partial permute of the first two arguments, which form a 32-byte
20301section of an emulated vector up to 256 bytes wide, using the partial permute
20302control vector in the third argument. The fourth argument (constrained to
20303values of 0-7) identifies which 32-byte section of the emulated vector is
20304contained in the first two arguments.
20305@findex vec_permx
20306
20307@smallexample
20308@exdent vector unsigned long long int
20309@exdent vec_pext (vector unsigned long long int, vector unsigned long long int);
20310@end smallexample
20311Perform a vector parallel bit extract operation, as if implemented by
20312the @code{vpextd} instruction.
20313@findex vec_pext
20314
20315@smallexample
20316@exdent vector unsigned char vec_stril (vector unsigned char);
20317@exdent vector signed char vec_stril (vector signed char);
20318@exdent vector unsigned short vec_stril (vector unsigned short);
20319@exdent vector signed short vec_stril (vector signed short);
20320@end smallexample
20321Isolate the left-most non-zero elements of the incoming vector argument,
20322replacing all elements to the right of the left-most zero element
20323found within the argument with zero. The typical implementation uses
20324the @code{vstribl} or @code{vstrihl} instruction on big-endian targets
20325and uses the @code{vstribr} or @code{vstrihr} instruction on
20326little-endian targets.
20327@findex vec_stril
20328
20329@smallexample
20330@exdent int vec_stril_p (vector unsigned char);
20331@exdent int vec_stril_p (vector signed char);
20332@exdent int short vec_stril_p (vector unsigned short);
20333@exdent int vec_stril_p (vector signed short);
20334@end smallexample
20335Return a non-zero value if and only if the argument contains a zero
20336element. The typical implementation uses
20337the @code{vstribl.} or @code{vstrihl.} instruction on big-endian targets
20338and uses the @code{vstribr.} or @code{vstrihr.} instruction on
20339little-endian targets. Choose this built-in to check for presence of
20340zero element if the same argument is also passed to @code{vec_stril}.
20341@findex vec_stril_p
20342
20343@smallexample
20344@exdent vector unsigned char vec_strir (vector unsigned char);
20345@exdent vector signed char vec_strir (vector signed char);
20346@exdent vector unsigned short vec_strir (vector unsigned short);
20347@exdent vector signed short vec_strir (vector signed short);
20348@end smallexample
20349Isolate the right-most non-zero elements of the incoming vector argument,
20350replacing all elements to the left of the right-most zero element
20351found within the argument with zero. The typical implementation uses
20352the @code{vstribr} or @code{vstrihr} instruction on big-endian targets
20353and uses the @code{vstribl} or @code{vstrihl} instruction on
20354little-endian targets.
20355@findex vec_strir
20356
20357@smallexample
20358@exdent int vec_strir_p (vector unsigned char);
20359@exdent int vec_strir_p (vector signed char);
20360@exdent int short vec_strir_p (vector unsigned short);
20361@exdent int vec_strir_p (vector signed short);
20362@end smallexample
20363Return a non-zero value if and only if the argument contains a zero
20364element. The typical implementation uses
20365the @code{vstribr.} or @code{vstrihr.} instruction on big-endian targets
20366and uses the @code{vstribl.} or @code{vstrihl.} instruction on
20367little-endian targets. Choose this built-in to check for presence of
20368zero element if the same argument is also passed to @code{vec_strir}.
20369@findex vec_strir_p
20370
20371@smallexample
20372@exdent vector unsigned char
20373@exdent vec_ternarylogic (vector unsigned char, vector unsigned char,
20374 vector unsigned char, const unsigned int);
20375@exdent vector unsigned short
20376@exdent vec_ternarylogic (vector unsigned short, vector unsigned short,
20377 vector unsigned short, const unsigned int);
20378@exdent vector unsigned int
20379@exdent vec_ternarylogic (vector unsigned int, vector unsigned int,
20380 vector unsigned int, const unsigned int);
20381@exdent vector unsigned long long int
20382@exdent vec_ternarylogic (vector unsigned long long int, vector unsigned long long int,
20383 vector unsigned long long int, const unsigned int);
20384@exdent vector unsigned __int128
20385@exdent vec_ternarylogic (vector unsigned __int128, vector unsigned __int128,
20386 vector unsigned __int128, const unsigned int);
20387@end smallexample
20388Perform a 128-bit vector evaluate operation, as if implemented by the
20389@code{xxeval} instruction. The fourth argument must be a literal
20390integer value between 0 and 255 inclusive.
20391@findex vec_ternarylogic
20392
20393@smallexample
20394@exdent vector unsigned char vec_genpcvm (vector unsigned char, const int);
20395@exdent vector unsigned short vec_genpcvm (vector unsigned short, const int);
20396@exdent vector unsigned int vec_genpcvm (vector unsigned int, const int);
20397@exdent vector unsigned int vec_genpcvm (vector unsigned long long int,
20398 const int);
20399@end smallexample
20400
20401Vector Integer Multiply/Divide/Modulo
20402
20403@smallexample
20404@exdent vector signed int
20405@exdent vec_mulh (vector signed int a, vector signed int b);
20406@exdent vector unsigned int
20407@exdent vec_mulh (vector unsigned int a, vector unsigned int b);
20408@end smallexample
20409
20410For each integer value @code{i} from 0 to 3, do the following. The integer
20411value in word element @code{i} of a is multiplied by the integer value in word
20412element @code{i} of b. The high-order 32 bits of the 64-bit product are placed
20413into word element @code{i} of the vector returned.
20414
20415@smallexample
20416@exdent vector signed long long
20417@exdent vec_mulh (vector signed long long a, vector signed long long b);
20418@exdent vector unsigned long long
20419@exdent vec_mulh (vector unsigned long long a, vector unsigned long long b);
20420@end smallexample
20421
20422For each integer value @code{i} from 0 to 1, do the following. The integer
20423value in doubleword element @code{i} of a is multiplied by the integer value in
20424doubleword element @code{i} of b. The high-order 64 bits of the 128-bit product
20425are placed into doubleword element @code{i} of the vector returned.
20426
20427@smallexample
20428@exdent vector unsigned long long
20429@exdent vec_mul (vector unsigned long long a, vector unsigned long long b);
20430@exdent vector signed long long
20431@exdent vec_mul (vector signed long long a, vector signed long long b);
20432@end smallexample
20433
20434For each integer value @code{i} from 0 to 1, do the following. The integer
20435value in doubleword element @code{i} of a is multiplied by the integer value in
20436doubleword element @code{i} of b. The low-order 64 bits of the 128-bit product
20437are placed into doubleword element @code{i} of the vector returned.
20438
20439@smallexample
20440@exdent vector signed int
20441@exdent vec_div (vector signed int a, vector signed int b);
20442@exdent vector unsigned int
20443@exdent vec_div (vector unsigned int a, vector unsigned int b);
20444@end smallexample
20445
20446For each integer value @code{i} from 0 to 3, do the following. The integer in
20447word element @code{i} of a is divided by the integer in word element @code{i}
20448of b. The unique integer quotient is placed into the word element @code{i} of
20449the vector returned. If an attempt is made to perform any of the divisions
20450<anything> ÷ 0 then the quotient is undefined.
20451
20452@smallexample
20453@exdent vector signed long long
20454@exdent vec_div (vector signed long long a, vector signed long long b);
20455@exdent vector unsigned long long
20456@exdent vec_div (vector unsigned long long a, vector unsigned long long b);
20457@end smallexample
20458
20459For each integer value @code{i} from 0 to 1, do the following. The integer in
20460doubleword element @code{i} of a is divided by the integer in doubleword
20461element @code{i} of b. The unique integer quotient is placed into the
20462doubleword element @code{i} of the vector returned. If an attempt is made to
20463perform any of the divisions 0x8000_0000_0000_0000 ÷ -1 or <anything> ÷ 0 then
20464the quotient is undefined.
20465
20466@smallexample
20467@exdent vector signed int
20468@exdent vec_dive (vector signed int a, vector signed int b);
20469@exdent vector unsigned int
20470@exdent vec_dive (vector unsigned int a, vector unsigned int b);
20471@end smallexample
20472
20473For each integer value @code{i} from 0 to 3, do the following. The integer in
20474word element @code{i} of a is shifted left by 32 bits, then divided by the
20475integer in word element @code{i} of b. The unique integer quotient is placed
20476into the word element @code{i} of the vector returned. If the quotient cannot
20477be represented in 32 bits, or if an attempt is made to perform any of the
20478divisions <anything> ÷ 0 then the quotient is undefined.
20479
20480@smallexample
20481@exdent vector signed long long
20482@exdent vec_dive (vector signed long long a, vector signed long long b);
20483@exdent vector unsigned long long
20484@exdent vec_dive (vector unsigned long long a, vector unsigned long long b);
20485@end smallexample
20486
20487For each integer value @code{i} from 0 to 1, do the following. The integer in
20488doubleword element @code{i} of a is shifted left by 64 bits, then divided by
20489the integer in doubleword element @code{i} of b. The unique integer quotient is
20490placed into the doubleword element @code{i} of the vector returned. If the
20491quotient cannot be represented in 64 bits, or if an attempt is made to perform
20492<anything> ÷ 0 then the quotient is undefined.
20493
20494@smallexample
20495@exdent vector signed int
20496@exdent vec_mod (vector signed int a, vector signed int b);
20497@exdent vector unsigned int
20498@exdent vec_mod (vector unsigned int a, vector unsigned int b);
20499@end smallexample
20500
20501For each integer value @code{i} from 0 to 3, do the following. The integer in
20502word element @code{i} of a is divided by the integer in word element @code{i}
20503of b. The unique integer remainder is placed into the word element @code{i} of
20504the vector returned. If an attempt is made to perform any of the divisions
205050x8000_0000 ÷ -1 or <anything> ÷ 0 then the remainder is undefined.
20506
20507@smallexample
20508@exdent vector signed long long
20509@exdent vec_mod (vector signed long long a, vector signed long long b);
20510@exdent vector unsigned long long
20511@exdent vec_mod (vector unsigned long long a, vector unsigned long long b);
20512@end smallexample
20513
20514For each integer value @code{i} from 0 to 1, do the following. The integer in
20515doubleword element @code{i} of a is divided by the integer in doubleword
20516element @code{i} of b. The unique integer remainder is placed into the
20517doubleword element @code{i} of the vector returned. If an attempt is made to
20518perform <anything> ÷ 0 then the remainder is undefined.
20519
20520Generate PCV from specified Mask size, as if implemented by the
20521@code{xxgenpcvbm}, @code{xxgenpcvhm}, @code{xxgenpcvwm} instructions, where
20522immediate value is either 0, 1, 2 or 3.
20523@findex vec_genpcvm
20524
20525@smallexample
20526@exdent vector unsigned __int128 vec_rl (vector unsigned __int128 A,
20527 vector unsigned __int128 B);
20528@exdent vector signed __int128 vec_rl (vector signed __int128 A,
20529 vector unsigned __int128 B);
20530@end smallexample
20531
20532Result value: Each element of R is obtained by rotating the corresponding element
20533of A left by the number of bits specified by the corresponding element of B.
20534
20535
20536@smallexample
20537@exdent vector unsigned __int128 vec_rlmi (vector unsigned __int128,
20538 vector unsigned __int128,
20539 vector unsigned __int128);
20540@exdent vector signed __int128 vec_rlmi (vector signed __int128,
20541 vector signed __int128,
20542 vector unsigned __int128);
20543@end smallexample
20544
20545Returns the result of rotating the first input and inserting it under mask
20546into the second input. The first bit in the mask, the last bit in the mask are
20547obtained from the two 7-bit fields bits [108:115] and bits [117:123]
20548respectively of the second input. The shift is obtained from the third input
20549in the 7-bit field [125:131] where all bits counted from zero at the left.
20550
20551@smallexample
20552@exdent vector unsigned __int128 vec_rlnm (vector unsigned __int128,
20553 vector unsigned __int128,
20554 vector unsigned __int128);
20555@exdent vector signed __int128 vec_rlnm (vector signed __int128,
20556 vector unsigned __int128,
20557 vector unsigned __int128);
20558@end smallexample
20559
20560Returns the result of rotating the first input and ANDing it with a mask. The
20561first bit in the mask and the last bit in the mask are obtained from the two
205627-bit fields bits [117:123] and bits [125:131] respectively of the second
20563input. The shift is obtained from the third input in the 7-bit field bits
20564[125:131] where all bits counted from zero at the left.
20565
20566@smallexample
20567@exdent vector unsigned __int128 vec_sl(vector unsigned __int128 A, vector unsigned __int128 B);
20568@exdent vector signed __int128 vec_sl(vector signed __int128 A, vector unsigned __int128 B);
20569@end smallexample
20570
20571Result value: Each element of R is obtained by shifting the corresponding element of
20572A left by the number of bits specified by the corresponding element of B.
20573
20574@smallexample
20575@exdent vector unsigned __int128 vec_sr(vector unsigned __int128 A, vector unsigned __int128 B);
20576@exdent vector signed __int128 vec_sr(vector signed __int128 A, vector unsigned __int128 B);
20577@end smallexample
20578
20579Result value: Each element of R is obtained by shifting the corresponding element of
20580A right by the number of bits specified by the corresponding element of B.
20581
20582@smallexample
20583@exdent vector unsigned __int128 vec_sra(vector unsigned __int128 A, vector unsigned __int128 B);
20584@exdent vector signed __int128 vec_sra(vector signed __int128 A, vector unsigned __int128 B);
20585@end smallexample
20586
20587Result value: Each element of R is obtained by arithmetic shifting the corresponding
20588element of A right by the number of bits specified by the corresponding element of B.
20589
20590@smallexample
20591@exdent vector unsigned __int128 vec_mule (vector unsigned long long,
20592 vector unsigned long long);
20593@exdent vector signed __int128 vec_mule (vector signed long long,
20594 vector signed long long);
20595@end smallexample
20596
20597Returns a vector containing a 128-bit integer result of multiplying the even
20598doubleword elements of the two inputs.
20599
20600@smallexample
20601@exdent vector unsigned __int128 vec_mulo (vector unsigned long long,
20602 vector unsigned long long);
20603@exdent vector signed __int128 vec_mulo (vector signed long long,
20604 vector signed long long);
20605@end smallexample
20606
20607Returns a vector containing a 128-bit integer result of multiplying the odd
20608doubleword elements of the two inputs.
20609
20610@smallexample
20611@exdent vector unsigned __int128 vec_div (vector unsigned __int128,
20612 vector unsigned __int128);
20613@exdent vector signed __int128 vec_div (vector signed __int128,
20614 vector signed __int128);
20615@end smallexample
20616
20617Returns the result of dividing the first operand by the second operand. An
20618attempt to divide any value by zero or to divide the most negative signed
20619128-bit integer by negative one results in an undefined value.
20620
20621@smallexample
20622@exdent vector unsigned __int128 vec_dive (vector unsigned __int128,
20623 vector unsigned __int128);
20624@exdent vector signed __int128 vec_dive (vector signed __int128,
20625 vector signed __int128);
20626@end smallexample
20627
20628The result is produced by shifting the first input left by 128 bits and
20629dividing by the second. If an attempt is made to divide by zero or the result
20630is larger than 128 bits, the result is undefined.
20631
20632@smallexample
20633@exdent vector unsigned __int128 vec_mod (vector unsigned __int128,
20634 vector unsigned __int128);
20635@exdent vector signed __int128 vec_mod (vector signed __int128,
20636 vector signed __int128);
20637@end smallexample
20638
20639The result is the modulo result of dividing the first input by the second
20640input.
20641
20642The following builtins perform 128-bit vector comparisons. The
20643@code{vec_all_xx}, @code{vec_any_xx}, and @code{vec_cmpxx}, where @code{xx} is
20644one of the operations @code{eq, ne, gt, lt, ge, le} perform pairwise
20645comparisons between the elements at the same positions within their two vector
20646arguments. The @code{vec_all_xx}function returns a non-zero value if and only
20647if all pairwise comparisons are true. The @code{vec_any_xx} function returns
20648a non-zero value if and only if at least one pairwise comparison is true. The
20649@code{vec_cmpxx}function returns a vector of the same type as its two
20650arguments, within which each element consists of all ones to denote that
20651specified logical comparison of the corresponding elements was true.
20652Otherwise, the element of the returned vector contains all zeros.
20653
20654@smallexample
20655vector bool __int128 vec_cmpeq (vector signed __int128, vector signed __int128);
20656vector bool __int128 vec_cmpeq (vector unsigned __int128, vector unsigned __int128);
20657vector bool __int128 vec_cmpne (vector signed __int128, vector signed __int128);
20658vector bool __int128 vec_cmpne (vector unsigned __int128, vector unsigned __int128);
20659vector bool __int128 vec_cmpgt (vector signed __int128, vector signed __int128);
20660vector bool __int128 vec_cmpgt (vector unsigned __int128, vector unsigned __int128);
20661vector bool __int128 vec_cmplt (vector signed __int128, vector signed __int128);
20662vector bool __int128 vec_cmplt (vector unsigned __int128, vector unsigned __int128);
20663vector bool __int128 vec_cmpge (vector signed __int128, vector signed __int128);
20664vector bool __int128 vec_cmpge (vector unsigned __int128, vector unsigned __int128);
20665vector bool __int128 vec_cmple (vector signed __int128, vector signed __int128);
20666vector bool __int128 vec_cmple (vector unsigned __int128, vector unsigned __int128);
20667
20668int vec_all_eq (vector signed __int128, vector signed __int128);
20669int vec_all_eq (vector unsigned __int128, vector unsigned __int128);
20670int vec_all_ne (vector signed __int128, vector signed __int128);
20671int vec_all_ne (vector unsigned __int128, vector unsigned __int128);
20672int vec_all_gt (vector signed __int128, vector signed __int128);
20673int vec_all_gt (vector unsigned __int128, vector unsigned __int128);
20674int vec_all_lt (vector signed __int128, vector signed __int128);
20675int vec_all_lt (vector unsigned __int128, vector unsigned __int128);
20676int vec_all_ge (vector signed __int128, vector signed __int128);
20677int vec_all_ge (vector unsigned __int128, vector unsigned __int128);
20678int vec_all_le (vector signed __int128, vector signed __int128);
20679int vec_all_le (vector unsigned __int128, vector unsigned __int128);
20680
20681int vec_any_eq (vector signed __int128, vector signed __int128);
20682int vec_any_eq (vector unsigned __int128, vector unsigned __int128);
20683int vec_any_ne (vector signed __int128, vector signed __int128);
20684int vec_any_ne (vector unsigned __int128, vector unsigned __int128);
20685int vec_any_gt (vector signed __int128, vector signed __int128);
20686int vec_any_gt (vector unsigned __int128, vector unsigned __int128);
20687int vec_any_lt (vector signed __int128, vector signed __int128);
20688int vec_any_lt (vector unsigned __int128, vector unsigned __int128);
20689int vec_any_ge (vector signed __int128, vector signed __int128);
20690int vec_any_ge (vector unsigned __int128, vector unsigned __int128);
20691int vec_any_le (vector signed __int128, vector signed __int128);
20692int vec_any_le (vector unsigned __int128, vector unsigned __int128);
20693@end smallexample
20694
20695
20696@node PowerPC Hardware Transactional Memory Built-in Functions
20697@subsection PowerPC Hardware Transactional Memory Built-in Functions
20698GCC provides two interfaces for accessing the Hardware Transactional
20699Memory (HTM) instructions available on some of the PowerPC family
20700of processors (eg, POWER8). The two interfaces come in a low level
20701interface, consisting of built-in functions specific to PowerPC and a
20702higher level interface consisting of inline functions that are common
20703between PowerPC and S/390.
20704
20705@subsubsection PowerPC HTM Low Level Built-in Functions
20706
20707The following low level built-in functions are available with
20708@option{-mhtm} or @option{-mcpu=CPU} where CPU is `power8' or later.
20709They all generate the machine instruction that is part of the name.
20710
20711The HTM builtins (with the exception of @code{__builtin_tbegin}) return
20712the full 4-bit condition register value set by their associated hardware
20713instruction. The header file @code{htmintrin.h} defines some macros that can
20714be used to decipher the return value. The @code{__builtin_tbegin} builtin
20715returns a simple @code{true} or @code{false} value depending on whether a transaction was
20716successfully started or not. The arguments of the builtins match exactly the
20717type and order of the associated hardware instruction's operands, except for
20718the @code{__builtin_tcheck} builtin, which does not take any input arguments.
20719Refer to the ISA manual for a description of each instruction's operands.
20720
20721@smallexample
20722unsigned int __builtin_tbegin (unsigned int);
20723unsigned int __builtin_tend (unsigned int);
20724
20725unsigned int __builtin_tabort (unsigned int);
20726unsigned int __builtin_tabortdc (unsigned int, unsigned int, unsigned int);
20727unsigned int __builtin_tabortdci (unsigned int, unsigned int, int);
20728unsigned int __builtin_tabortwc (unsigned int, unsigned int, unsigned int);
20729unsigned int __builtin_tabortwci (unsigned int, unsigned int, int);
20730
20731unsigned int __builtin_tcheck (void);
20732unsigned int __builtin_treclaim (unsigned int);
20733unsigned int __builtin_trechkpt (void);
20734unsigned int __builtin_tsr (unsigned int);
20735@end smallexample
20736
20737In addition to the above HTM built-ins, we have added built-ins for
20738some common extended mnemonics of the HTM instructions:
20739
20740@smallexample
20741unsigned int __builtin_tendall (void);
20742unsigned int __builtin_tresume (void);
20743unsigned int __builtin_tsuspend (void);
20744@end smallexample
20745
20746Note that the semantics of the above HTM builtins are required to mimic
20747the locking semantics used for critical sections. Builtins that are used
20748to create a new transaction or restart a suspended transaction must have
20749lock acquisition like semantics while those builtins that end or suspend a
20750transaction must have lock release like semantics. Specifically, this must
20751mimic lock semantics as specified by C++11, for example: Lock acquisition is
20752as-if an execution of __atomic_exchange_n(&globallock,1,__ATOMIC_ACQUIRE)
20753that returns 0, and lock release is as-if an execution of
20754__atomic_store(&globallock,0,__ATOMIC_RELEASE), with globallock being an
20755implicit implementation-defined lock used for all transactions. The HTM
20756instructions associated with with the builtins inherently provide the
20757correct acquisition and release hardware barriers required. However,
20758the compiler must also be prohibited from moving loads and stores across
20759the builtins in a way that would violate their semantics. This has been
20760accomplished by adding memory barriers to the associated HTM instructions
20761(which is a conservative approach to provide acquire and release semantics).
20762Earlier versions of the compiler did not treat the HTM instructions as
20763memory barriers. A @code{__TM_FENCE__} macro has been added, which can
20764be used to determine whether the current compiler treats HTM instructions
20765as memory barriers or not. This allows the user to explicitly add memory
20766barriers to their code when using an older version of the compiler.
20767
20768The following set of built-in functions are available to gain access
20769to the HTM specific special purpose registers.
20770
20771@smallexample
20772unsigned long __builtin_get_texasr (void);
20773unsigned long __builtin_get_texasru (void);
20774unsigned long __builtin_get_tfhar (void);
20775unsigned long __builtin_get_tfiar (void);
20776
20777void __builtin_set_texasr (unsigned long);
20778void __builtin_set_texasru (unsigned long);
20779void __builtin_set_tfhar (unsigned long);
20780void __builtin_set_tfiar (unsigned long);
20781@end smallexample
20782
20783Example usage of these low level built-in functions may look like:
20784
20785@smallexample
20786#include <htmintrin.h>
20787
20788int num_retries = 10;
20789
20790while (1)
20791 @{
20792 if (__builtin_tbegin (0))
20793 @{
20794 /* Transaction State Initiated. */
20795 if (is_locked (lock))
20796 __builtin_tabort (0);
20797 ... transaction code...
20798 __builtin_tend (0);
20799 break;
20800 @}
20801 else
20802 @{
20803 /* Transaction State Failed. Use locks if the transaction
20804 failure is "persistent" or we've tried too many times. */
20805 if (num_retries-- <= 0
20806 || _TEXASRU_FAILURE_PERSISTENT (__builtin_get_texasru ()))
20807 @{
20808 acquire_lock (lock);
20809 ... non transactional fallback path...
20810 release_lock (lock);
20811 break;
20812 @}
20813 @}
20814 @}
20815@end smallexample
20816
20817One final built-in function has been added that returns the value of
20818the 2-bit Transaction State field of the Machine Status Register (MSR)
20819as stored in @code{CR0}.
20820
20821@smallexample
20822unsigned long __builtin_ttest (void)
20823@end smallexample
20824
20825This built-in can be used to determine the current transaction state
20826using the following code example:
20827
20828@smallexample
20829#include <htmintrin.h>
20830
20831unsigned char tx_state = _HTM_STATE (__builtin_ttest ());
20832
20833if (tx_state == _HTM_TRANSACTIONAL)
20834 @{
20835 /* Code to use in transactional state. */
20836 @}
20837else if (tx_state == _HTM_NONTRANSACTIONAL)
20838 @{
20839 /* Code to use in non-transactional state. */
20840 @}
20841else if (tx_state == _HTM_SUSPENDED)
20842 @{
20843 /* Code to use in transaction suspended state. */
20844 @}
20845@end smallexample
20846
20847@subsubsection PowerPC HTM High Level Inline Functions
20848
20849The following high level HTM interface is made available by including
20850@code{<htmxlintrin.h>} and using @option{-mhtm} or @option{-mcpu=CPU}
20851where CPU is `power8' or later. This interface is common between PowerPC
20852and S/390, allowing users to write one HTM source implementation that
20853can be compiled and executed on either system.
20854
20855@smallexample
20856long __TM_simple_begin (void);
20857long __TM_begin (void* const TM_buff);
20858long __TM_end (void);
20859void __TM_abort (void);
20860void __TM_named_abort (unsigned char const code);
20861void __TM_resume (void);
20862void __TM_suspend (void);
20863
20864long __TM_is_user_abort (void* const TM_buff);
20865long __TM_is_named_user_abort (void* const TM_buff, unsigned char *code);
20866long __TM_is_illegal (void* const TM_buff);
20867long __TM_is_footprint_exceeded (void* const TM_buff);
20868long __TM_nesting_depth (void* const TM_buff);
20869long __TM_is_nested_too_deep(void* const TM_buff);
20870long __TM_is_conflict(void* const TM_buff);
20871long __TM_is_failure_persistent(void* const TM_buff);
20872long __TM_failure_address(void* const TM_buff);
20873long long __TM_failure_code(void* const TM_buff);
20874@end smallexample
20875
20876Using these common set of HTM inline functions, we can create
20877a more portable version of the HTM example in the previous
20878section that will work on either PowerPC or S/390:
20879
20880@smallexample
20881#include <htmxlintrin.h>
20882
20883int num_retries = 10;
20884TM_buff_type TM_buff;
20885
20886while (1)
20887 @{
20888 if (__TM_begin (TM_buff) == _HTM_TBEGIN_STARTED)
20889 @{
20890 /* Transaction State Initiated. */
20891 if (is_locked (lock))
20892 __TM_abort ();
20893 ... transaction code...
20894 __TM_end ();
20895 break;
20896 @}
20897 else
20898 @{
20899 /* Transaction State Failed. Use locks if the transaction
20900 failure is "persistent" or we've tried too many times. */
20901 if (num_retries-- <= 0
20902 || __TM_is_failure_persistent (TM_buff))
20903 @{
20904 acquire_lock (lock);
20905 ... non transactional fallback path...
20906 release_lock (lock);
20907 break;
20908 @}
20909 @}
20910 @}
20911@end smallexample
20912
20913@node PowerPC Atomic Memory Operation Functions
20914@subsection PowerPC Atomic Memory Operation Functions
20915ISA 3.0 of the PowerPC added new atomic memory operation (amo)
20916instructions. GCC provides support for these instructions in 64-bit
20917environments. All of the functions are declared in the include file
20918@code{amo.h}.
20919
20920The functions supported are:
20921
20922@smallexample
20923#include <amo.h>
20924
20925uint32_t amo_lwat_add (uint32_t *, uint32_t);
20926uint32_t amo_lwat_xor (uint32_t *, uint32_t);
20927uint32_t amo_lwat_ior (uint32_t *, uint32_t);
20928uint32_t amo_lwat_and (uint32_t *, uint32_t);
20929uint32_t amo_lwat_umax (uint32_t *, uint32_t);
20930uint32_t amo_lwat_umin (uint32_t *, uint32_t);
20931uint32_t amo_lwat_swap (uint32_t *, uint32_t);
20932
20933int32_t amo_lwat_sadd (int32_t *, int32_t);
20934int32_t amo_lwat_smax (int32_t *, int32_t);
20935int32_t amo_lwat_smin (int32_t *, int32_t);
20936int32_t amo_lwat_sswap (int32_t *, int32_t);
20937
20938uint64_t amo_ldat_add (uint64_t *, uint64_t);
20939uint64_t amo_ldat_xor (uint64_t *, uint64_t);
20940uint64_t amo_ldat_ior (uint64_t *, uint64_t);
20941uint64_t amo_ldat_and (uint64_t *, uint64_t);
20942uint64_t amo_ldat_umax (uint64_t *, uint64_t);
20943uint64_t amo_ldat_umin (uint64_t *, uint64_t);
20944uint64_t amo_ldat_swap (uint64_t *, uint64_t);
20945
20946int64_t amo_ldat_sadd (int64_t *, int64_t);
20947int64_t amo_ldat_smax (int64_t *, int64_t);
20948int64_t amo_ldat_smin (int64_t *, int64_t);
20949int64_t amo_ldat_sswap (int64_t *, int64_t);
20950
20951void amo_stwat_add (uint32_t *, uint32_t);
20952void amo_stwat_xor (uint32_t *, uint32_t);
20953void amo_stwat_ior (uint32_t *, uint32_t);
20954void amo_stwat_and (uint32_t *, uint32_t);
20955void amo_stwat_umax (uint32_t *, uint32_t);
20956void amo_stwat_umin (uint32_t *, uint32_t);
20957
20958void amo_stwat_sadd (int32_t *, int32_t);
20959void amo_stwat_smax (int32_t *, int32_t);
20960void amo_stwat_smin (int32_t *, int32_t);
20961
20962void amo_stdat_add (uint64_t *, uint64_t);
20963void amo_stdat_xor (uint64_t *, uint64_t);
20964void amo_stdat_ior (uint64_t *, uint64_t);
20965void amo_stdat_and (uint64_t *, uint64_t);
20966void amo_stdat_umax (uint64_t *, uint64_t);
20967void amo_stdat_umin (uint64_t *, uint64_t);
20968
20969void amo_stdat_sadd (int64_t *, int64_t);
20970void amo_stdat_smax (int64_t *, int64_t);
20971void amo_stdat_smin (int64_t *, int64_t);
20972@end smallexample
20973
20974@node PowerPC Matrix-Multiply Assist Built-in Functions
20975@subsection PowerPC Matrix-Multiply Assist Built-in Functions
20976ISA 3.1 of the PowerPC added new Matrix-Multiply Assist (MMA) instructions.
20977GCC provides support for these instructions through the following built-in
20978functions which are enabled with the @code{-mmma} option. The vec_t type
20979below is defined to be a normal vector unsigned char type. The uint2, uint4
20980and uint8 parameters are 2-bit, 4-bit and 8-bit unsigned integer constants
20981respectively. The compiler will verify that they are constants and that
20982their values are within range.
20983
20984The built-in functions supported are:
20985
20986@smallexample
20987void __builtin_mma_xvi4ger8 (__vector_quad *, vec_t, vec_t);
20988void __builtin_mma_xvi8ger4 (__vector_quad *, vec_t, vec_t);
20989void __builtin_mma_xvi16ger2 (__vector_quad *, vec_t, vec_t);
20990void __builtin_mma_xvi16ger2s (__vector_quad *, vec_t, vec_t);
20991void __builtin_mma_xvf16ger2 (__vector_quad *, vec_t, vec_t);
20992void __builtin_mma_xvbf16ger2 (__vector_quad *, vec_t, vec_t);
20993void __builtin_mma_xvf32ger (__vector_quad *, vec_t, vec_t);
20994
20995void __builtin_mma_xvi4ger8pp (__vector_quad *, vec_t, vec_t);
20996void __builtin_mma_xvi8ger4pp (__vector_quad *, vec_t, vec_t);
20997void __builtin_mma_xvi8ger4spp(__vector_quad *, vec_t, vec_t);
20998void __builtin_mma_xvi16ger2pp (__vector_quad *, vec_t, vec_t);
20999void __builtin_mma_xvi16ger2spp (__vector_quad *, vec_t, vec_t);
21000void __builtin_mma_xvf16ger2pp (__vector_quad *, vec_t, vec_t);
21001void __builtin_mma_xvf16ger2pn (__vector_quad *, vec_t, vec_t);
21002void __builtin_mma_xvf16ger2np (__vector_quad *, vec_t, vec_t);
21003void __builtin_mma_xvf16ger2nn (__vector_quad *, vec_t, vec_t);
21004void __builtin_mma_xvbf16ger2pp (__vector_quad *, vec_t, vec_t);
21005void __builtin_mma_xvbf16ger2pn (__vector_quad *, vec_t, vec_t);
21006void __builtin_mma_xvbf16ger2np (__vector_quad *, vec_t, vec_t);
21007void __builtin_mma_xvbf16ger2nn (__vector_quad *, vec_t, vec_t);
21008void __builtin_mma_xvf32gerpp (__vector_quad *, vec_t, vec_t);
21009void __builtin_mma_xvf32gerpn (__vector_quad *, vec_t, vec_t);
21010void __builtin_mma_xvf32gernp (__vector_quad *, vec_t, vec_t);
21011void __builtin_mma_xvf32gernn (__vector_quad *, vec_t, vec_t);
21012
21013void __builtin_mma_pmxvi4ger8 (__vector_quad *, vec_t, vec_t, uint4, uint4, uint8);
21014void __builtin_mma_pmxvi4ger8pp (__vector_quad *, vec_t, vec_t, uint4, uint4, uint8);
21015
21016void __builtin_mma_pmxvi8ger4 (__vector_quad *, vec_t, vec_t, uint4, uint4, uint4);
21017void __builtin_mma_pmxvi8ger4pp (__vector_quad *, vec_t, vec_t, uint4, uint4, uint4);
21018void __builtin_mma_pmxvi8ger4spp(__vector_quad *, vec_t, vec_t, uint4, uint4, uint4);
21019
21020void __builtin_mma_pmxvi16ger2 (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2);
21021void __builtin_mma_pmxvi16ger2s (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2);
21022void __builtin_mma_pmxvf16ger2 (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2);
21023void __builtin_mma_pmxvbf16ger2 (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2);
21024
21025void __builtin_mma_pmxvi16ger2pp (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2);
21026void __builtin_mma_pmxvi16ger2spp (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2);
21027void __builtin_mma_pmxvf16ger2pp (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2);
21028void __builtin_mma_pmxvf16ger2pn (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2);
21029void __builtin_mma_pmxvf16ger2np (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2);
21030void __builtin_mma_pmxvf16ger2nn (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2);
21031void __builtin_mma_pmxvbf16ger2pp (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2);
21032void __builtin_mma_pmxvbf16ger2pn (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2);
21033void __builtin_mma_pmxvbf16ger2np (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2);
21034void __builtin_mma_pmxvbf16ger2nn (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2);
21035
21036void __builtin_mma_pmxvf32ger (__vector_quad *, vec_t, vec_t, uint4, uint4);
21037void __builtin_mma_pmxvf32gerpp (__vector_quad *, vec_t, vec_t, uint4, uint4);
21038void __builtin_mma_pmxvf32gerpn (__vector_quad *, vec_t, vec_t, uint4, uint4);
21039void __builtin_mma_pmxvf32gernp (__vector_quad *, vec_t, vec_t, uint4, uint4);
21040void __builtin_mma_pmxvf32gernn (__vector_quad *, vec_t, vec_t, uint4, uint4);
21041
21042void __builtin_mma_xvf64ger (__vector_quad *, __vector_pair, vec_t);
21043void __builtin_mma_xvf64gerpp (__vector_quad *, __vector_pair, vec_t);
21044void __builtin_mma_xvf64gerpn (__vector_quad *, __vector_pair, vec_t);
21045void __builtin_mma_xvf64gernp (__vector_quad *, __vector_pair, vec_t);
21046void __builtin_mma_xvf64gernn (__vector_quad *, __vector_pair, vec_t);
21047
21048void __builtin_mma_pmxvf64ger (__vector_quad *, __vector_pair, vec_t, uint4, uint2);
21049void __builtin_mma_pmxvf64gerpp (__vector_quad *, __vector_pair, vec_t, uint4, uint2);
21050void __builtin_mma_pmxvf64gerpn (__vector_quad *, __vector_pair, vec_t, uint4, uint2);
21051void __builtin_mma_pmxvf64gernp (__vector_quad *, __vector_pair, vec_t, uint4, uint2);
21052void __builtin_mma_pmxvf64gernn (__vector_quad *, __vector_pair, vec_t, uint4, uint2);
21053
21054void __builtin_mma_xxmtacc (__vector_quad *);
21055void __builtin_mma_xxmfacc (__vector_quad *);
21056void __builtin_mma_xxsetaccz (__vector_quad *);
21057
21058void __builtin_mma_build_acc (__vector_quad *, vec_t, vec_t, vec_t, vec_t);
21059void __builtin_mma_disassemble_acc (void *, __vector_quad *);
21060
21061void __builtin_vsx_build_pair (__vector_pair *, vec_t, vec_t);
21062void __builtin_vsx_disassemble_pair (void *, __vector_pair *);
21063
21064vec_t __builtin_vsx_xvcvspbf16 (vec_t);
21065vec_t __builtin_vsx_xvcvbf16spn (vec_t);
21066
21067__vector_pair __builtin_vsx_lxvp (size_t, __vector_pair *);
21068void __builtin_vsx_stxvp (__vector_pair, size_t, __vector_pair *);
21069@end smallexample
21070
21071@node PRU Built-in Functions
21072@subsection PRU Built-in Functions
21073
21074GCC provides a couple of special builtin functions to aid in utilizing
21075special PRU instructions.
21076
21077The built-in functions supported are:
21078
f25efe50 21079@defbuiltin{void __delay_cycles (constant long long @var{cycles})}
d77de738
ML
21080This inserts an instruction sequence that takes exactly @var{cycles}
21081cycles (between 0 and 0xffffffff) to complete. The inserted sequence
21082may use jumps, loops, or no-ops, and does not interfere with any other
21083instructions. Note that @var{cycles} must be a compile-time constant
21084integer - that is, you must pass a number, not a variable that may be
21085optimized to a constant later. The number of cycles delayed by this
21086builtin is exact.
f25efe50 21087@enddefbuiltin
d77de738 21088
f25efe50 21089@defbuiltin{void __halt (void)}
d77de738 21090This inserts a HALT instruction to stop processor execution.
f25efe50 21091@enddefbuiltin
d77de738 21092
f25efe50
AA
21093@defbuiltin{{unsigned int} @
21094 __lmbd (unsigned int @var{wordval}, @
21095 unsigned int @var{bitval})}
d77de738
ML
21096This inserts LMBD instruction to calculate the left-most bit with value
21097@var{bitval} in value @var{wordval}. Only the least significant bit
21098of @var{bitval} is taken into account.
f25efe50 21099@enddefbuiltin
d77de738
ML
21100
21101@node RISC-V Built-in Functions
21102@subsection RISC-V Built-in Functions
21103
21104These built-in functions are available for the RISC-V family of
21105processors.
21106
f25efe50 21107@defbuiltin{{void *} __builtin_thread_pointer (void)}
d77de738 21108Returns the value that is currently set in the @samp{tp} register.
f25efe50 21109@enddefbuiltin
d77de738 21110
f25efe50 21111@defbuiltin{void __builtin_riscv_pause (void)}
df049cb2
PD
21112Generates the @code{pause} (hint) machine instruction. This implies the
21113Xgnuzihintpausestate extension, which redefines the @code{pause} instruction to
21114change architectural state.
f25efe50 21115@enddefbuiltin
c717a92d 21116
d77de738
ML
21117@node RX Built-in Functions
21118@subsection RX Built-in Functions
21119GCC supports some of the RX instructions which cannot be expressed in
21120the C programming language via the use of built-in functions. The
21121following functions are supported:
21122
f25efe50 21123@defbuiltin{void __builtin_rx_brk (void)}
d77de738 21124Generates the @code{brk} machine instruction.
f25efe50 21125@enddefbuiltin
d77de738 21126
f25efe50 21127@defbuiltin{void __builtin_rx_clrpsw (int)}
d77de738
ML
21128Generates the @code{clrpsw} machine instruction to clear the specified
21129bit in the processor status word.
f25efe50 21130@enddefbuiltin
d77de738 21131
f25efe50 21132@defbuiltin{void __builtin_rx_int (int)}
d77de738
ML
21133Generates the @code{int} machine instruction to generate an interrupt
21134with the specified value.
f25efe50 21135@enddefbuiltin
d77de738 21136
f25efe50 21137@defbuiltin{void __builtin_rx_machi (int, int)}
d77de738
ML
21138Generates the @code{machi} machine instruction to add the result of
21139multiplying the top 16 bits of the two arguments into the
21140accumulator.
f25efe50 21141@enddefbuiltin
d77de738 21142
f25efe50 21143@defbuiltin{void __builtin_rx_maclo (int, int)}
d77de738
ML
21144Generates the @code{maclo} machine instruction to add the result of
21145multiplying the bottom 16 bits of the two arguments into the
21146accumulator.
f25efe50 21147@enddefbuiltin
d77de738 21148
f25efe50 21149@defbuiltin{void __builtin_rx_mulhi (int, int)}
d77de738
ML
21150Generates the @code{mulhi} machine instruction to place the result of
21151multiplying the top 16 bits of the two arguments into the
21152accumulator.
f25efe50 21153@enddefbuiltin
d77de738 21154
f25efe50 21155@defbuiltin{void __builtin_rx_mullo (int, int)}
d77de738
ML
21156Generates the @code{mullo} machine instruction to place the result of
21157multiplying the bottom 16 bits of the two arguments into the
21158accumulator.
f25efe50 21159@enddefbuiltin
d77de738 21160
f25efe50 21161@defbuiltin{int __builtin_rx_mvfachi (void)}
d77de738
ML
21162Generates the @code{mvfachi} machine instruction to read the top
2116332 bits of the accumulator.
f25efe50 21164@enddefbuiltin
d77de738 21165
f25efe50 21166@defbuiltin{int __builtin_rx_mvfacmi (void)}
d77de738
ML
21167Generates the @code{mvfacmi} machine instruction to read the middle
2116832 bits of the accumulator.
f25efe50 21169@enddefbuiltin
d77de738 21170
f25efe50 21171@defbuiltin{int __builtin_rx_mvfc (int)}
d77de738
ML
21172Generates the @code{mvfc} machine instruction which reads the control
21173register specified in its argument and returns its value.
f25efe50 21174@enddefbuiltin
d77de738 21175
f25efe50 21176@defbuiltin{void __builtin_rx_mvtachi (int)}
d77de738
ML
21177Generates the @code{mvtachi} machine instruction to set the top
2117832 bits of the accumulator.
f25efe50 21179@enddefbuiltin
d77de738 21180
f25efe50 21181@defbuiltin{void __builtin_rx_mvtaclo (int)}
d77de738
ML
21182Generates the @code{mvtaclo} machine instruction to set the bottom
2118332 bits of the accumulator.
f25efe50 21184@enddefbuiltin
d77de738 21185
f25efe50 21186@defbuiltin{void __builtin_rx_mvtc (int reg, int val)}
d77de738
ML
21187Generates the @code{mvtc} machine instruction which sets control
21188register number @code{reg} to @code{val}.
f25efe50 21189@enddefbuiltin
d77de738 21190
f25efe50 21191@defbuiltin{void __builtin_rx_mvtipl (int)}
d77de738
ML
21192Generates the @code{mvtipl} machine instruction set the interrupt
21193priority level.
f25efe50 21194@enddefbuiltin
d77de738 21195
f25efe50 21196@defbuiltin{void __builtin_rx_racw (int)}
d77de738
ML
21197Generates the @code{racw} machine instruction to round the accumulator
21198according to the specified mode.
f25efe50 21199@enddefbuiltin
d77de738 21200
f25efe50 21201@defbuiltin{int __builtin_rx_revw (int)}
d77de738
ML
21202Generates the @code{revw} machine instruction which swaps the bytes in
21203the argument so that bits 0--7 now occupy bits 8--15 and vice versa,
21204and also bits 16--23 occupy bits 24--31 and vice versa.
f25efe50 21205@enddefbuiltin
d77de738 21206
f25efe50 21207@defbuiltin{void __builtin_rx_rmpa (void)}
d77de738
ML
21208Generates the @code{rmpa} machine instruction which initiates a
21209repeated multiply and accumulate sequence.
f25efe50 21210@enddefbuiltin
d77de738 21211
f25efe50 21212@defbuiltin{void __builtin_rx_round (float)}
d77de738
ML
21213Generates the @code{round} machine instruction which returns the
21214floating-point argument rounded according to the current rounding mode
21215set in the floating-point status word register.
f25efe50 21216@enddefbuiltin
d77de738 21217
f25efe50 21218@defbuiltin{int __builtin_rx_sat (int)}
d77de738
ML
21219Generates the @code{sat} machine instruction which returns the
21220saturated value of the argument.
f25efe50 21221@enddefbuiltin
d77de738 21222
f25efe50 21223@defbuiltin{void __builtin_rx_setpsw (int)}
d77de738
ML
21224Generates the @code{setpsw} machine instruction to set the specified
21225bit in the processor status word.
f25efe50 21226@enddefbuiltin
d77de738 21227
f25efe50 21228@defbuiltin{void __builtin_rx_wait (void)}
d77de738 21229Generates the @code{wait} machine instruction.
f25efe50 21230@enddefbuiltin
d77de738
ML
21231
21232@node S/390 System z Built-in Functions
21233@subsection S/390 System z Built-in Functions
f25efe50 21234@defbuiltin{int __builtin_tbegin (void*)}
d77de738
ML
21235Generates the @code{tbegin} machine instruction starting a
21236non-constrained hardware transaction. If the parameter is non-NULL the
21237memory area is used to store the transaction diagnostic buffer and
21238will be passed as first operand to @code{tbegin}. This buffer can be
21239defined using the @code{struct __htm_tdb} C struct defined in
21240@code{htmintrin.h} and must reside on a double-word boundary. The
21241second tbegin operand is set to @code{0xff0c}. This enables
21242save/restore of all GPRs and disables aborts for FPR and AR
21243manipulations inside the transaction body. The condition code set by
21244the tbegin instruction is returned as integer value. The tbegin
21245instruction by definition overwrites the content of all FPRs. The
21246compiler will generate code which saves and restores the FPRs. For
21247soft-float code it is recommended to used the @code{*_nofloat}
21248variant. In order to prevent a TDB from being written it is required
21249to pass a constant zero value as parameter. Passing a zero value
21250through a variable is not sufficient. Although modifications of
21251access registers inside the transaction will not trigger an
21252transaction abort it is not supported to actually modify them. Access
21253registers do not get saved when entering a transaction. They will have
21254undefined state when reaching the abort code.
f25efe50 21255@enddefbuiltin
d77de738
ML
21256
21257Macros for the possible return codes of tbegin are defined in the
21258@code{htmintrin.h} header file:
21259
f25efe50 21260@defmac _HTM_TBEGIN_STARTED
d77de738
ML
21261@code{tbegin} has been executed as part of normal processing. The
21262transaction body is supposed to be executed.
f25efe50
AA
21263@end defmac
21264
21265@defmac _HTM_TBEGIN_INDETERMINATE
d77de738
ML
21266The transaction was aborted due to an indeterminate condition which
21267might be persistent.
f25efe50
AA
21268@end defmac
21269
21270@defmac _HTM_TBEGIN_TRANSIENT
d77de738
ML
21271The transaction aborted due to a transient failure. The transaction
21272should be re-executed in that case.
f25efe50
AA
21273@end defmac
21274
21275@defmac _HTM_TBEGIN_PERSISTENT
d77de738
ML
21276The transaction aborted due to a persistent failure. Re-execution
21277under same circumstances will not be productive.
f25efe50 21278@end defmac
d77de738
ML
21279
21280@defmac _HTM_FIRST_USER_ABORT_CODE
21281The @code{_HTM_FIRST_USER_ABORT_CODE} defined in @code{htmintrin.h}
21282specifies the first abort code which can be used for
21283@code{__builtin_tabort}. Values below this threshold are reserved for
21284machine use.
21285@end defmac
21286
21287@deftp {Data type} {struct __htm_tdb}
21288The @code{struct __htm_tdb} defined in @code{htmintrin.h} describes
21289the structure of the transaction diagnostic block as specified in the
21290Principles of Operation manual chapter 5-91.
21291@end deftp
21292
f25efe50 21293@defbuiltin{int __builtin_tbegin_nofloat (void*)}
d77de738
ML
21294Same as @code{__builtin_tbegin} but without FPR saves and restores.
21295Using this variant in code making use of FPRs will leave the FPRs in
21296undefined state when entering the transaction abort handler code.
f25efe50 21297@enddefbuiltin
d77de738 21298
f25efe50 21299@defbuiltin{int __builtin_tbegin_retry (void*, int)}
d77de738
ML
21300In addition to @code{__builtin_tbegin} a loop for transient failures
21301is generated. If tbegin returns a condition code of 2 the transaction
21302will be retried as often as specified in the second argument. The
21303perform processor assist instruction is used to tell the CPU about the
21304number of fails so far.
f25efe50 21305@enddefbuiltin
d77de738 21306
f25efe50 21307@defbuiltin{int __builtin_tbegin_retry_nofloat (void*, int)}
d77de738
ML
21308Same as @code{__builtin_tbegin_retry} but without FPR saves and
21309restores. Using this variant in code making use of FPRs will leave
21310the FPRs in undefined state when entering the transaction abort
21311handler code.
f25efe50 21312@enddefbuiltin
d77de738 21313
f25efe50 21314@defbuiltin{void __builtin_tbeginc (void)}
d77de738
ML
21315Generates the @code{tbeginc} machine instruction starting a constrained
21316hardware transaction. The second operand is set to @code{0xff08}.
f25efe50 21317@enddefbuiltin
d77de738 21318
f25efe50 21319@defbuiltin{int __builtin_tend (void)}
d77de738
ML
21320Generates the @code{tend} machine instruction finishing a transaction
21321and making the changes visible to other threads. The condition code
21322generated by tend is returned as integer value.
f25efe50 21323@enddefbuiltin
d77de738 21324
f25efe50 21325@defbuiltin{void __builtin_tabort (int)}
d77de738
ML
21326Generates the @code{tabort} machine instruction with the specified
21327abort code. Abort codes from 0 through 255 are reserved and will
21328result in an error message.
f25efe50 21329@enddefbuiltin
d77de738 21330
f25efe50 21331@defbuiltin{void __builtin_tx_assist (int)}
d77de738
ML
21332Generates the @code{ppa rX,rY,1} machine instruction. Where the
21333integer parameter is loaded into rX and a value of zero is loaded into
21334rY. The integer parameter specifies the number of times the
21335transaction repeatedly aborted.
f25efe50 21336@enddefbuiltin
d77de738 21337
f25efe50 21338@defbuiltin{int __builtin_tx_nesting_depth (void)}
d77de738
ML
21339Generates the @code{etnd} machine instruction. The current nesting
21340depth is returned as integer value. For a nesting depth of 0 the code
21341is not executed as part of an transaction.
f25efe50 21342@enddefbuiltin
d77de738 21343
f25efe50 21344@defbuiltin{void __builtin_non_tx_store (uint64_t *, uint64_t)}
d77de738
ML
21345
21346Generates the @code{ntstg} machine instruction. The second argument
21347is written to the first arguments location. The store operation will
21348not be rolled-back in case of an transaction abort.
f25efe50 21349@enddefbuiltin
d77de738
ML
21350
21351@node SH Built-in Functions
21352@subsection SH Built-in Functions
21353The following built-in functions are supported on the SH1, SH2, SH3 and SH4
21354families of processors:
21355
f25efe50 21356@defbuiltin{{void} __builtin_set_thread_pointer (void *@var{ptr})}
d77de738
ML
21357Sets the @samp{GBR} register to the specified value @var{ptr}. This is usually
21358used by system code that manages threads and execution contexts. The compiler
21359normally does not generate code that modifies the contents of @samp{GBR} and
21360thus the value is preserved across function calls. Changing the @samp{GBR}
21361value in user code must be done with caution, since the compiler might use
21362@samp{GBR} in order to access thread local variables.
21363
f25efe50 21364@enddefbuiltin
d77de738 21365
f25efe50 21366@defbuiltin{{void *} __builtin_thread_pointer (void)}
d77de738
ML
21367Returns the value that is currently set in the @samp{GBR} register.
21368Memory loads and stores that use the thread pointer as a base address are
21369turned into @samp{GBR} based displacement loads and stores, if possible.
21370For example:
21371@smallexample
21372struct my_tcb
21373@{
21374 int a, b, c, d, e;
21375@};
21376
21377int get_tcb_value (void)
21378@{
21379 // Generate @samp{mov.l @@(8,gbr),r0} instruction
21380 return ((my_tcb*)__builtin_thread_pointer ())->c;
21381@}
21382
21383@end smallexample
f25efe50 21384@enddefbuiltin
d77de738 21385
f25efe50 21386@defbuiltin{{unsigned int} __builtin_sh_get_fpscr (void)}
d77de738 21387Returns the value that is currently set in the @samp{FPSCR} register.
f25efe50 21388@enddefbuiltin
d77de738 21389
f25efe50 21390@defbuiltin{{void} __builtin_sh_set_fpscr (unsigned int @var{val})}
d77de738
ML
21391Sets the @samp{FPSCR} register to the specified value @var{val}, while
21392preserving the current values of the FR, SZ and PR bits.
f25efe50 21393@enddefbuiltin
d77de738
ML
21394
21395@node SPARC VIS Built-in Functions
21396@subsection SPARC VIS Built-in Functions
21397
21398GCC supports SIMD operations on the SPARC using both the generic vector
21399extensions (@pxref{Vector Extensions}) as well as built-in functions for
21400the SPARC Visual Instruction Set (VIS). When you use the @option{-mvis}
21401switch, the VIS extension is exposed as the following built-in functions:
21402
21403@smallexample
21404typedef int v1si __attribute__ ((vector_size (4)));
21405typedef int v2si __attribute__ ((vector_size (8)));
21406typedef short v4hi __attribute__ ((vector_size (8)));
21407typedef short v2hi __attribute__ ((vector_size (4)));
21408typedef unsigned char v8qi __attribute__ ((vector_size (8)));
21409typedef unsigned char v4qi __attribute__ ((vector_size (4)));
21410
21411void __builtin_vis_write_gsr (int64_t);
21412int64_t __builtin_vis_read_gsr (void);
21413
21414void * __builtin_vis_alignaddr (void *, long);
21415void * __builtin_vis_alignaddrl (void *, long);
21416int64_t __builtin_vis_faligndatadi (int64_t, int64_t);
21417v2si __builtin_vis_faligndatav2si (v2si, v2si);
21418v4hi __builtin_vis_faligndatav4hi (v4si, v4si);
21419v8qi __builtin_vis_faligndatav8qi (v8qi, v8qi);
21420
21421v4hi __builtin_vis_fexpand (v4qi);
21422
21423v4hi __builtin_vis_fmul8x16 (v4qi, v4hi);
21424v4hi __builtin_vis_fmul8x16au (v4qi, v2hi);
21425v4hi __builtin_vis_fmul8x16al (v4qi, v2hi);
21426v4hi __builtin_vis_fmul8sux16 (v8qi, v4hi);
21427v4hi __builtin_vis_fmul8ulx16 (v8qi, v4hi);
21428v2si __builtin_vis_fmuld8sux16 (v4qi, v2hi);
21429v2si __builtin_vis_fmuld8ulx16 (v4qi, v2hi);
21430
21431v4qi __builtin_vis_fpack16 (v4hi);
21432v8qi __builtin_vis_fpack32 (v2si, v8qi);
21433v2hi __builtin_vis_fpackfix (v2si);
21434v8qi __builtin_vis_fpmerge (v4qi, v4qi);
21435
21436int64_t __builtin_vis_pdist (v8qi, v8qi, int64_t);
21437
21438long __builtin_vis_edge8 (void *, void *);
21439long __builtin_vis_edge8l (void *, void *);
21440long __builtin_vis_edge16 (void *, void *);
21441long __builtin_vis_edge16l (void *, void *);
21442long __builtin_vis_edge32 (void *, void *);
21443long __builtin_vis_edge32l (void *, void *);
21444
21445long __builtin_vis_fcmple16 (v4hi, v4hi);
21446long __builtin_vis_fcmple32 (v2si, v2si);
21447long __builtin_vis_fcmpne16 (v4hi, v4hi);
21448long __builtin_vis_fcmpne32 (v2si, v2si);
21449long __builtin_vis_fcmpgt16 (v4hi, v4hi);
21450long __builtin_vis_fcmpgt32 (v2si, v2si);
21451long __builtin_vis_fcmpeq16 (v4hi, v4hi);
21452long __builtin_vis_fcmpeq32 (v2si, v2si);
21453
21454v4hi __builtin_vis_fpadd16 (v4hi, v4hi);
21455v2hi __builtin_vis_fpadd16s (v2hi, v2hi);
21456v2si __builtin_vis_fpadd32 (v2si, v2si);
21457v1si __builtin_vis_fpadd32s (v1si, v1si);
21458v4hi __builtin_vis_fpsub16 (v4hi, v4hi);
21459v2hi __builtin_vis_fpsub16s (v2hi, v2hi);
21460v2si __builtin_vis_fpsub32 (v2si, v2si);
21461v1si __builtin_vis_fpsub32s (v1si, v1si);
21462
21463long __builtin_vis_array8 (long, long);
21464long __builtin_vis_array16 (long, long);
21465long __builtin_vis_array32 (long, long);
21466@end smallexample
21467
21468When you use the @option{-mvis2} switch, the VIS version 2.0 built-in
21469functions also become available:
21470
21471@smallexample
21472long __builtin_vis_bmask (long, long);
21473int64_t __builtin_vis_bshuffledi (int64_t, int64_t);
21474v2si __builtin_vis_bshufflev2si (v2si, v2si);
21475v4hi __builtin_vis_bshufflev2si (v4hi, v4hi);
21476v8qi __builtin_vis_bshufflev2si (v8qi, v8qi);
21477
21478long __builtin_vis_edge8n (void *, void *);
21479long __builtin_vis_edge8ln (void *, void *);
21480long __builtin_vis_edge16n (void *, void *);
21481long __builtin_vis_edge16ln (void *, void *);
21482long __builtin_vis_edge32n (void *, void *);
21483long __builtin_vis_edge32ln (void *, void *);
21484@end smallexample
21485
21486When you use the @option{-mvis3} switch, the VIS version 3.0 built-in
21487functions also become available:
21488
21489@smallexample
21490void __builtin_vis_cmask8 (long);
21491void __builtin_vis_cmask16 (long);
21492void __builtin_vis_cmask32 (long);
21493
21494v4hi __builtin_vis_fchksm16 (v4hi, v4hi);
21495
21496v4hi __builtin_vis_fsll16 (v4hi, v4hi);
21497v4hi __builtin_vis_fslas16 (v4hi, v4hi);
21498v4hi __builtin_vis_fsrl16 (v4hi, v4hi);
21499v4hi __builtin_vis_fsra16 (v4hi, v4hi);
21500v2si __builtin_vis_fsll16 (v2si, v2si);
21501v2si __builtin_vis_fslas16 (v2si, v2si);
21502v2si __builtin_vis_fsrl16 (v2si, v2si);
21503v2si __builtin_vis_fsra16 (v2si, v2si);
21504
21505long __builtin_vis_pdistn (v8qi, v8qi);
21506
21507v4hi __builtin_vis_fmean16 (v4hi, v4hi);
21508
21509int64_t __builtin_vis_fpadd64 (int64_t, int64_t);
21510int64_t __builtin_vis_fpsub64 (int64_t, int64_t);
21511
21512v4hi __builtin_vis_fpadds16 (v4hi, v4hi);
21513v2hi __builtin_vis_fpadds16s (v2hi, v2hi);
21514v4hi __builtin_vis_fpsubs16 (v4hi, v4hi);
21515v2hi __builtin_vis_fpsubs16s (v2hi, v2hi);
21516v2si __builtin_vis_fpadds32 (v2si, v2si);
21517v1si __builtin_vis_fpadds32s (v1si, v1si);
21518v2si __builtin_vis_fpsubs32 (v2si, v2si);
21519v1si __builtin_vis_fpsubs32s (v1si, v1si);
21520
21521long __builtin_vis_fucmple8 (v8qi, v8qi);
21522long __builtin_vis_fucmpne8 (v8qi, v8qi);
21523long __builtin_vis_fucmpgt8 (v8qi, v8qi);
21524long __builtin_vis_fucmpeq8 (v8qi, v8qi);
21525
21526float __builtin_vis_fhadds (float, float);
21527double __builtin_vis_fhaddd (double, double);
21528float __builtin_vis_fhsubs (float, float);
21529double __builtin_vis_fhsubd (double, double);
21530float __builtin_vis_fnhadds (float, float);
21531double __builtin_vis_fnhaddd (double, double);
21532
21533int64_t __builtin_vis_umulxhi (int64_t, int64_t);
21534int64_t __builtin_vis_xmulx (int64_t, int64_t);
21535int64_t __builtin_vis_xmulxhi (int64_t, int64_t);
21536@end smallexample
21537
21538When you use the @option{-mvis4} switch, the VIS version 4.0 built-in
21539functions also become available:
21540
21541@smallexample
21542v8qi __builtin_vis_fpadd8 (v8qi, v8qi);
21543v8qi __builtin_vis_fpadds8 (v8qi, v8qi);
21544v8qi __builtin_vis_fpaddus8 (v8qi, v8qi);
21545v4hi __builtin_vis_fpaddus16 (v4hi, v4hi);
21546
21547v8qi __builtin_vis_fpsub8 (v8qi, v8qi);
21548v8qi __builtin_vis_fpsubs8 (v8qi, v8qi);
21549v8qi __builtin_vis_fpsubus8 (v8qi, v8qi);
21550v4hi __builtin_vis_fpsubus16 (v4hi, v4hi);
21551
21552long __builtin_vis_fpcmple8 (v8qi, v8qi);
21553long __builtin_vis_fpcmpgt8 (v8qi, v8qi);
21554long __builtin_vis_fpcmpule16 (v4hi, v4hi);
21555long __builtin_vis_fpcmpugt16 (v4hi, v4hi);
21556long __builtin_vis_fpcmpule32 (v2si, v2si);
21557long __builtin_vis_fpcmpugt32 (v2si, v2si);
21558
21559v8qi __builtin_vis_fpmax8 (v8qi, v8qi);
21560v4hi __builtin_vis_fpmax16 (v4hi, v4hi);
21561v2si __builtin_vis_fpmax32 (v2si, v2si);
21562
21563v8qi __builtin_vis_fpmaxu8 (v8qi, v8qi);
21564v4hi __builtin_vis_fpmaxu16 (v4hi, v4hi);
21565v2si __builtin_vis_fpmaxu32 (v2si, v2si);
21566
21567v8qi __builtin_vis_fpmin8 (v8qi, v8qi);
21568v4hi __builtin_vis_fpmin16 (v4hi, v4hi);
21569v2si __builtin_vis_fpmin32 (v2si, v2si);
21570
21571v8qi __builtin_vis_fpminu8 (v8qi, v8qi);
21572v4hi __builtin_vis_fpminu16 (v4hi, v4hi);
21573v2si __builtin_vis_fpminu32 (v2si, v2si);
21574@end smallexample
21575
21576When you use the @option{-mvis4b} switch, the VIS version 4.0B
21577built-in functions also become available:
21578
21579@smallexample
21580v8qi __builtin_vis_dictunpack8 (double, int);
21581v4hi __builtin_vis_dictunpack16 (double, int);
21582v2si __builtin_vis_dictunpack32 (double, int);
21583
21584long __builtin_vis_fpcmple8shl (v8qi, v8qi, int);
21585long __builtin_vis_fpcmpgt8shl (v8qi, v8qi, int);
21586long __builtin_vis_fpcmpeq8shl (v8qi, v8qi, int);
21587long __builtin_vis_fpcmpne8shl (v8qi, v8qi, int);
21588
21589long __builtin_vis_fpcmple16shl (v4hi, v4hi, int);
21590long __builtin_vis_fpcmpgt16shl (v4hi, v4hi, int);
21591long __builtin_vis_fpcmpeq16shl (v4hi, v4hi, int);
21592long __builtin_vis_fpcmpne16shl (v4hi, v4hi, int);
21593
21594long __builtin_vis_fpcmple32shl (v2si, v2si, int);
21595long __builtin_vis_fpcmpgt32shl (v2si, v2si, int);
21596long __builtin_vis_fpcmpeq32shl (v2si, v2si, int);
21597long __builtin_vis_fpcmpne32shl (v2si, v2si, int);
21598
21599long __builtin_vis_fpcmpule8shl (v8qi, v8qi, int);
21600long __builtin_vis_fpcmpugt8shl (v8qi, v8qi, int);
21601long __builtin_vis_fpcmpule16shl (v4hi, v4hi, int);
21602long __builtin_vis_fpcmpugt16shl (v4hi, v4hi, int);
21603long __builtin_vis_fpcmpule32shl (v2si, v2si, int);
21604long __builtin_vis_fpcmpugt32shl (v2si, v2si, int);
21605
21606long __builtin_vis_fpcmpde8shl (v8qi, v8qi, int);
21607long __builtin_vis_fpcmpde16shl (v4hi, v4hi, int);
21608long __builtin_vis_fpcmpde32shl (v2si, v2si, int);
21609
21610long __builtin_vis_fpcmpur8shl (v8qi, v8qi, int);
21611long __builtin_vis_fpcmpur16shl (v4hi, v4hi, int);
21612long __builtin_vis_fpcmpur32shl (v2si, v2si, int);
21613@end smallexample
21614
21615@node TI C6X Built-in Functions
21616@subsection TI C6X Built-in Functions
21617
21618GCC provides intrinsics to access certain instructions of the TI C6X
21619processors. These intrinsics, listed below, are available after
21620inclusion of the @code{c6x_intrinsics.h} header file. They map directly
21621to C6X instructions.
21622
21623@smallexample
21624int _sadd (int, int);
21625int _ssub (int, int);
21626int _sadd2 (int, int);
21627int _ssub2 (int, int);
21628long long _mpy2 (int, int);
21629long long _smpy2 (int, int);
21630int _add4 (int, int);
21631int _sub4 (int, int);
21632int _saddu4 (int, int);
21633
21634int _smpy (int, int);
21635int _smpyh (int, int);
21636int _smpyhl (int, int);
21637int _smpylh (int, int);
21638
21639int _sshl (int, int);
21640int _subc (int, int);
21641
21642int _avg2 (int, int);
21643int _avgu4 (int, int);
21644
21645int _clrr (int, int);
21646int _extr (int, int);
21647int _extru (int, int);
21648int _abs (int);
21649int _abs2 (int);
21650@end smallexample
21651
21652@node x86 Built-in Functions
21653@subsection x86 Built-in Functions
21654
21655These built-in functions are available for the x86-32 and x86-64 family
21656of computers, depending on the command-line switches used.
21657
21658If you specify command-line switches such as @option{-msse},
21659the compiler could use the extended instruction sets even if the built-ins
21660are not used explicitly in the program. For this reason, applications
21661that perform run-time CPU detection must compile separate files for each
21662supported architecture, using the appropriate flags. In particular,
21663the file containing the CPU detection code should be compiled without
21664these options.
21665
21666The following machine modes are available for use with MMX built-in functions
21667(@pxref{Vector Extensions}): @code{V2SI} for a vector of two 32-bit integers,
21668@code{V4HI} for a vector of four 16-bit integers, and @code{V8QI} for a
21669vector of eight 8-bit integers. Some of the built-in functions operate on
21670MMX registers as a whole 64-bit entity, these use @code{V1DI} as their mode.
21671
21672If 3DNow!@: extensions are enabled, @code{V2SF} is used as a mode for a vector
21673of two 32-bit floating-point values.
21674
21675If SSE extensions are enabled, @code{V4SF} is used for a vector of four 32-bit
21676floating-point values. Some instructions use a vector of four 32-bit
21677integers, these use @code{V4SI}. Finally, some instructions operate on an
21678entire vector register, interpreting it as a 128-bit integer, these use mode
21679@code{TI}.
21680
21681The x86-32 and x86-64 family of processors use additional built-in
21682functions for efficient use of @code{TF} (@code{__float128}) 128-bit
21683floating point and @code{TC} 128-bit complex floating-point values.
21684
f25efe50 21685The following floating-point built-in functions are always available:
d77de738 21686
f25efe50
AA
21687@defbuiltin{__float128 __builtin_fabsq (__float128 @var{x}))}
21688Computes the absolute value of @var{x}.
21689@enddefbuiltin
d77de738 21690
f25efe50
AA
21691@defbuiltin{__float128 __builtin_copysignq (__float128 @var{x}, @
21692 __float128 @var{y})}
21693Copies the sign of @var{y} into @var{x} and returns the new value of
21694@var{x}.
21695@enddefbuiltin
d77de738 21696
f25efe50 21697@defbuiltin{__float128 __builtin_infq (void)}
d77de738 21698Similar to @code{__builtin_inf}, except the return type is @code{__float128}.
f25efe50 21699@enddefbuiltin
d77de738 21700
f25efe50 21701@defbuiltin{__float128 __builtin_huge_valq (void)}
d77de738 21702Similar to @code{__builtin_huge_val}, except the return type is @code{__float128}.
f25efe50 21703@enddefbuiltin
d77de738 21704
f25efe50 21705@defbuiltin{__float128 __builtin_nanq (void)}
d77de738 21706Similar to @code{__builtin_nan}, except the return type is @code{__float128}.
f25efe50 21707@enddefbuiltin
d77de738 21708
f25efe50 21709@defbuiltin{__float128 __builtin_nansq (void)}
d77de738 21710Similar to @code{__builtin_nans}, except the return type is @code{__float128}.
f25efe50 21711@enddefbuiltin
d77de738
ML
21712
21713The following built-in function is always available.
21714
f25efe50 21715@defbuiltin{void __builtin_ia32_pause (void)}
d77de738
ML
21716Generates the @code{pause} machine instruction with a compiler memory
21717barrier.
f25efe50 21718@enddefbuiltin
d77de738
ML
21719
21720The following built-in functions are always available and can be used to
21721check the target platform type.
21722
f25efe50 21723@defbuiltin{void __builtin_cpu_init (void)}
d77de738
ML
21724This function runs the CPU detection code to check the type of CPU and the
21725features supported. This built-in function needs to be invoked along with the built-in functions
21726to check CPU type and features, @code{__builtin_cpu_is} and
21727@code{__builtin_cpu_supports}, only when used in a function that is
21728executed before any constructors are called. The CPU detection code is
21729automatically executed in a very high priority constructor.
21730
21731For example, this function has to be used in @code{ifunc} resolvers that
21732check for CPU type using the built-in functions @code{__builtin_cpu_is}
21733and @code{__builtin_cpu_supports}, or in constructors on targets that
21734don't support constructor priority.
21735@smallexample
21736
21737static void (*resolve_memcpy (void)) (void)
21738@{
21739 // ifunc resolvers fire before constructors, explicitly call the init
21740 // function.
21741 __builtin_cpu_init ();
21742 if (__builtin_cpu_supports ("ssse3"))
21743 return ssse3_memcpy; // super fast memcpy with ssse3 instructions.
21744 else
21745 return default_memcpy;
21746@}
21747
21748void *memcpy (void *, const void *, size_t)
21749 __attribute__ ((ifunc ("resolve_memcpy")));
21750@end smallexample
21751
f25efe50 21752@enddefbuiltin
d77de738 21753
f25efe50 21754@defbuiltin{int __builtin_cpu_is (const char *@var{cpuname})}
d77de738
ML
21755This function returns a positive integer if the run-time CPU
21756is of type @var{cpuname}
21757and returns @code{0} otherwise. The following CPU names can be detected:
21758
21759@table @samp
21760@item amd
21761AMD CPU.
21762
21763@item intel
21764Intel CPU.
21765
21766@item atom
21767Intel Atom CPU.
21768
21769@item slm
21770Intel Silvermont CPU.
21771
21772@item core2
21773Intel Core 2 CPU.
21774
21775@item corei7
21776Intel Core i7 CPU.
21777
21778@item nehalem
21779Intel Core i7 Nehalem CPU.
21780
21781@item westmere
21782Intel Core i7 Westmere CPU.
21783
21784@item sandybridge
21785Intel Core i7 Sandy Bridge CPU.
21786
21787@item ivybridge
21788Intel Core i7 Ivy Bridge CPU.
21789
21790@item haswell
21791Intel Core i7 Haswell CPU.
21792
21793@item broadwell
21794Intel Core i7 Broadwell CPU.
21795
21796@item skylake
21797Intel Core i7 Skylake CPU.
21798
21799@item skylake-avx512
21800Intel Core i7 Skylake AVX512 CPU.
21801
21802@item cannonlake
21803Intel Core i7 Cannon Lake CPU.
21804
21805@item icelake-client
21806Intel Core i7 Ice Lake Client CPU.
21807
21808@item icelake-server
21809Intel Core i7 Ice Lake Server CPU.
21810
21811@item cascadelake
21812Intel Core i7 Cascadelake CPU.
21813
21814@item tigerlake
21815Intel Core i7 Tigerlake CPU.
21816
21817@item cooperlake
21818Intel Core i7 Cooperlake CPU.
21819
21820@item sapphirerapids
21821Intel Core i7 sapphirerapids CPU.
21822
21823@item alderlake
21824Intel Core i7 Alderlake CPU.
21825
21826@item rocketlake
21827Intel Core i7 Rocketlake CPU.
21828
21829@item graniterapids
21830Intel Core i7 graniterapids CPU.
21831
21832@item bonnell
21833Intel Atom Bonnell CPU.
21834
21835@item silvermont
21836Intel Atom Silvermont CPU.
21837
21838@item goldmont
21839Intel Atom Goldmont CPU.
21840
21841@item goldmont-plus
21842Intel Atom Goldmont Plus CPU.
21843
21844@item tremont
21845Intel Atom Tremont CPU.
21846
21847@item sierraforest
21848Intel Atom Sierra Forest CPU.
21849
21850@item grandridge
21851Intel Atom Grand Ridge CPU.
21852
21853@item knl
21854Intel Knights Landing CPU.
21855
21856@item knm
21857Intel Knights Mill CPU.
21858
21859@item lujiazui
21860ZHAOXIN lujiazui CPU.
21861
21862@item amdfam10h
21863AMD Family 10h CPU.
21864
21865@item barcelona
21866AMD Family 10h Barcelona CPU.
21867
21868@item shanghai
21869AMD Family 10h Shanghai CPU.
21870
21871@item istanbul
21872AMD Family 10h Istanbul CPU.
21873
21874@item btver1
21875AMD Family 14h CPU.
21876
21877@item amdfam15h
21878AMD Family 15h CPU.
21879
21880@item bdver1
21881AMD Family 15h Bulldozer version 1.
21882
21883@item bdver2
21884AMD Family 15h Bulldozer version 2.
21885
21886@item bdver3
21887AMD Family 15h Bulldozer version 3.
21888
21889@item bdver4
21890AMD Family 15h Bulldozer version 4.
21891
21892@item btver2
21893AMD Family 16h CPU.
21894
21895@item amdfam17h
21896AMD Family 17h CPU.
21897
21898@item znver1
21899AMD Family 17h Zen version 1.
21900
21901@item znver2
21902AMD Family 17h Zen version 2.
21903
21904@item amdfam19h
21905AMD Family 19h CPU.
21906
21907@item znver3
21908AMD Family 19h Zen version 3.
21909
21910@item znver4
21911AMD Family 19h Zen version 4.
d77de738
ML
21912@end table
21913
21914Here is an example:
21915@smallexample
21916if (__builtin_cpu_is ("corei7"))
21917 @{
21918 do_corei7 (); // Core i7 specific implementation.
21919 @}
21920else
21921 @{
21922 do_generic (); // Generic implementation.
21923 @}
21924@end smallexample
f25efe50 21925@enddefbuiltin
d77de738 21926
f25efe50 21927@defbuiltin{int __builtin_cpu_supports (const char *@var{feature})}
d77de738
ML
21928This function returns a positive integer if the run-time CPU
21929supports @var{feature}
21930and returns @code{0} otherwise. The following features can be detected:
21931
21932@table @samp
21933@item cmov
21934CMOV instruction.
21935@item mmx
21936MMX instructions.
21937@item popcnt
21938POPCNT instruction.
21939@item sse
21940SSE instructions.
21941@item sse2
21942SSE2 instructions.
21943@item sse3
21944SSE3 instructions.
21945@item ssse3
21946SSSE3 instructions.
21947@item sse4.1
21948SSE4.1 instructions.
21949@item sse4.2
21950SSE4.2 instructions.
21951@item avx
21952AVX instructions.
21953@item avx2
21954AVX2 instructions.
21955@item sse4a
21956SSE4A instructions.
21957@item fma4
21958FMA4 instructions.
21959@item xop
21960XOP instructions.
21961@item fma
21962FMA instructions.
21963@item avx512f
21964AVX512F instructions.
21965@item bmi
21966BMI instructions.
21967@item bmi2
21968BMI2 instructions.
21969@item aes
21970AES instructions.
21971@item pclmul
21972PCLMUL instructions.
21973@item avx512vl
21974AVX512VL instructions.
21975@item avx512bw
21976AVX512BW instructions.
21977@item avx512dq
21978AVX512DQ instructions.
21979@item avx512cd
21980AVX512CD instructions.
21981@item avx512er
21982AVX512ER instructions.
21983@item avx512pf
21984AVX512PF instructions.
21985@item avx512vbmi
21986AVX512VBMI instructions.
21987@item avx512ifma
21988AVX512IFMA instructions.
21989@item avx5124vnniw
21990AVX5124VNNIW instructions.
21991@item avx5124fmaps
21992AVX5124FMAPS instructions.
21993@item avx512vpopcntdq
21994AVX512VPOPCNTDQ instructions.
21995@item avx512vbmi2
21996AVX512VBMI2 instructions.
21997@item gfni
21998GFNI instructions.
21999@item vpclmulqdq
22000VPCLMULQDQ instructions.
22001@item avx512vnni
22002AVX512VNNI instructions.
22003@item avx512bitalg
22004AVX512BITALG instructions.
d71b20fc
ML
22005@item x86-64
22006Baseline x86-64 microarchitecture level (as defined in x86-64 psABI).
22007@item x86-64-v2
22008x86-64-v2 microarchitecture level.
22009@item x86-64-v3
22010x86-64-v3 microarchitecture level.
22011@item x86-64-v4
22012x86-64-v4 microarchitecture level.
22013
22014
d77de738
ML
22015@end table
22016
22017Here is an example:
22018@smallexample
22019if (__builtin_cpu_supports ("popcnt"))
22020 @{
22021 asm("popcnt %1,%0" : "=r"(count) : "rm"(n) : "cc");
22022 @}
22023else
22024 @{
22025 count = generic_countbits (n); //generic implementation.
22026 @}
22027@end smallexample
f25efe50 22028@enddefbuiltin
d77de738
ML
22029
22030The following built-in functions are made available by @option{-mmmx}.
22031All of them generate the machine instruction that is part of the name.
22032
22033@smallexample
22034v8qi __builtin_ia32_paddb (v8qi, v8qi);
22035v4hi __builtin_ia32_paddw (v4hi, v4hi);
22036v2si __builtin_ia32_paddd (v2si, v2si);
22037v8qi __builtin_ia32_psubb (v8qi, v8qi);
22038v4hi __builtin_ia32_psubw (v4hi, v4hi);
22039v2si __builtin_ia32_psubd (v2si, v2si);
22040v8qi __builtin_ia32_paddsb (v8qi, v8qi);
22041v4hi __builtin_ia32_paddsw (v4hi, v4hi);
22042v8qi __builtin_ia32_psubsb (v8qi, v8qi);
22043v4hi __builtin_ia32_psubsw (v4hi, v4hi);
22044v8qi __builtin_ia32_paddusb (v8qi, v8qi);
22045v4hi __builtin_ia32_paddusw (v4hi, v4hi);
22046v8qi __builtin_ia32_psubusb (v8qi, v8qi);
22047v4hi __builtin_ia32_psubusw (v4hi, v4hi);
22048v4hi __builtin_ia32_pmullw (v4hi, v4hi);
22049v4hi __builtin_ia32_pmulhw (v4hi, v4hi);
22050di __builtin_ia32_pand (di, di);
22051di __builtin_ia32_pandn (di,di);
22052di __builtin_ia32_por (di, di);
22053di __builtin_ia32_pxor (di, di);
22054v8qi __builtin_ia32_pcmpeqb (v8qi, v8qi);
22055v4hi __builtin_ia32_pcmpeqw (v4hi, v4hi);
22056v2si __builtin_ia32_pcmpeqd (v2si, v2si);
22057v8qi __builtin_ia32_pcmpgtb (v8qi, v8qi);
22058v4hi __builtin_ia32_pcmpgtw (v4hi, v4hi);
22059v2si __builtin_ia32_pcmpgtd (v2si, v2si);
22060v8qi __builtin_ia32_punpckhbw (v8qi, v8qi);
22061v4hi __builtin_ia32_punpckhwd (v4hi, v4hi);
22062v2si __builtin_ia32_punpckhdq (v2si, v2si);
22063v8qi __builtin_ia32_punpcklbw (v8qi, v8qi);
22064v4hi __builtin_ia32_punpcklwd (v4hi, v4hi);
22065v2si __builtin_ia32_punpckldq (v2si, v2si);
22066v8qi __builtin_ia32_packsswb (v4hi, v4hi);
22067v4hi __builtin_ia32_packssdw (v2si, v2si);
22068v8qi __builtin_ia32_packuswb (v4hi, v4hi);
22069
22070v4hi __builtin_ia32_psllw (v4hi, v4hi);
22071v2si __builtin_ia32_pslld (v2si, v2si);
22072v1di __builtin_ia32_psllq (v1di, v1di);
22073v4hi __builtin_ia32_psrlw (v4hi, v4hi);
22074v2si __builtin_ia32_psrld (v2si, v2si);
22075v1di __builtin_ia32_psrlq (v1di, v1di);
22076v4hi __builtin_ia32_psraw (v4hi, v4hi);
22077v2si __builtin_ia32_psrad (v2si, v2si);
22078v4hi __builtin_ia32_psllwi (v4hi, int);
22079v2si __builtin_ia32_pslldi (v2si, int);
22080v1di __builtin_ia32_psllqi (v1di, int);
22081v4hi __builtin_ia32_psrlwi (v4hi, int);
22082v2si __builtin_ia32_psrldi (v2si, int);
22083v1di __builtin_ia32_psrlqi (v1di, int);
22084v4hi __builtin_ia32_psrawi (v4hi, int);
22085v2si __builtin_ia32_psradi (v2si, int);
22086@end smallexample
22087
22088The following built-in functions are made available either with
22089@option{-msse}, or with @option{-m3dnowa}. All of them generate
22090the machine instruction that is part of the name.
22091
22092@smallexample
22093v4hi __builtin_ia32_pmulhuw (v4hi, v4hi);
22094v8qi __builtin_ia32_pavgb (v8qi, v8qi);
22095v4hi __builtin_ia32_pavgw (v4hi, v4hi);
22096v1di __builtin_ia32_psadbw (v8qi, v8qi);
22097v8qi __builtin_ia32_pmaxub (v8qi, v8qi);
22098v4hi __builtin_ia32_pmaxsw (v4hi, v4hi);
22099v8qi __builtin_ia32_pminub (v8qi, v8qi);
22100v4hi __builtin_ia32_pminsw (v4hi, v4hi);
22101int __builtin_ia32_pmovmskb (v8qi);
22102void __builtin_ia32_maskmovq (v8qi, v8qi, char *);
22103void __builtin_ia32_movntq (di *, di);
22104void __builtin_ia32_sfence (void);
22105@end smallexample
22106
22107The following built-in functions are available when @option{-msse} is used.
22108All of them generate the machine instruction that is part of the name.
22109
22110@smallexample
22111int __builtin_ia32_comieq (v4sf, v4sf);
22112int __builtin_ia32_comineq (v4sf, v4sf);
22113int __builtin_ia32_comilt (v4sf, v4sf);
22114int __builtin_ia32_comile (v4sf, v4sf);
22115int __builtin_ia32_comigt (v4sf, v4sf);
22116int __builtin_ia32_comige (v4sf, v4sf);
22117int __builtin_ia32_ucomieq (v4sf, v4sf);
22118int __builtin_ia32_ucomineq (v4sf, v4sf);
22119int __builtin_ia32_ucomilt (v4sf, v4sf);
22120int __builtin_ia32_ucomile (v4sf, v4sf);
22121int __builtin_ia32_ucomigt (v4sf, v4sf);
22122int __builtin_ia32_ucomige (v4sf, v4sf);
22123v4sf __builtin_ia32_addps (v4sf, v4sf);
22124v4sf __builtin_ia32_subps (v4sf, v4sf);
22125v4sf __builtin_ia32_mulps (v4sf, v4sf);
22126v4sf __builtin_ia32_divps (v4sf, v4sf);
22127v4sf __builtin_ia32_addss (v4sf, v4sf);
22128v4sf __builtin_ia32_subss (v4sf, v4sf);
22129v4sf __builtin_ia32_mulss (v4sf, v4sf);
22130v4sf __builtin_ia32_divss (v4sf, v4sf);
22131v4sf __builtin_ia32_cmpeqps (v4sf, v4sf);
22132v4sf __builtin_ia32_cmpltps (v4sf, v4sf);
22133v4sf __builtin_ia32_cmpleps (v4sf, v4sf);
22134v4sf __builtin_ia32_cmpgtps (v4sf, v4sf);
22135v4sf __builtin_ia32_cmpgeps (v4sf, v4sf);
22136v4sf __builtin_ia32_cmpunordps (v4sf, v4sf);
22137v4sf __builtin_ia32_cmpneqps (v4sf, v4sf);
22138v4sf __builtin_ia32_cmpnltps (v4sf, v4sf);
22139v4sf __builtin_ia32_cmpnleps (v4sf, v4sf);
22140v4sf __builtin_ia32_cmpngtps (v4sf, v4sf);
22141v4sf __builtin_ia32_cmpngeps (v4sf, v4sf);
22142v4sf __builtin_ia32_cmpordps (v4sf, v4sf);
22143v4sf __builtin_ia32_cmpeqss (v4sf, v4sf);
22144v4sf __builtin_ia32_cmpltss (v4sf, v4sf);
22145v4sf __builtin_ia32_cmpless (v4sf, v4sf);
22146v4sf __builtin_ia32_cmpunordss (v4sf, v4sf);
22147v4sf __builtin_ia32_cmpneqss (v4sf, v4sf);
22148v4sf __builtin_ia32_cmpnltss (v4sf, v4sf);
22149v4sf __builtin_ia32_cmpnless (v4sf, v4sf);
22150v4sf __builtin_ia32_cmpordss (v4sf, v4sf);
22151v4sf __builtin_ia32_maxps (v4sf, v4sf);
22152v4sf __builtin_ia32_maxss (v4sf, v4sf);
22153v4sf __builtin_ia32_minps (v4sf, v4sf);
22154v4sf __builtin_ia32_minss (v4sf, v4sf);
22155v4sf __builtin_ia32_andps (v4sf, v4sf);
22156v4sf __builtin_ia32_andnps (v4sf, v4sf);
22157v4sf __builtin_ia32_orps (v4sf, v4sf);
22158v4sf __builtin_ia32_xorps (v4sf, v4sf);
22159v4sf __builtin_ia32_movss (v4sf, v4sf);
22160v4sf __builtin_ia32_movhlps (v4sf, v4sf);
22161v4sf __builtin_ia32_movlhps (v4sf, v4sf);
22162v4sf __builtin_ia32_unpckhps (v4sf, v4sf);
22163v4sf __builtin_ia32_unpcklps (v4sf, v4sf);
22164v4sf __builtin_ia32_cvtpi2ps (v4sf, v2si);
22165v4sf __builtin_ia32_cvtsi2ss (v4sf, int);
22166v2si __builtin_ia32_cvtps2pi (v4sf);
22167int __builtin_ia32_cvtss2si (v4sf);
22168v2si __builtin_ia32_cvttps2pi (v4sf);
22169int __builtin_ia32_cvttss2si (v4sf);
22170v4sf __builtin_ia32_rcpps (v4sf);
22171v4sf __builtin_ia32_rsqrtps (v4sf);
22172v4sf __builtin_ia32_sqrtps (v4sf);
22173v4sf __builtin_ia32_rcpss (v4sf);
22174v4sf __builtin_ia32_rsqrtss (v4sf);
22175v4sf __builtin_ia32_sqrtss (v4sf);
22176v4sf __builtin_ia32_shufps (v4sf, v4sf, int);
22177void __builtin_ia32_movntps (float *, v4sf);
22178int __builtin_ia32_movmskps (v4sf);
22179@end smallexample
22180
22181The following built-in functions are available when @option{-msse} is used.
22182
f25efe50 22183@defbuiltin{v4sf __builtin_ia32_loadups (float *)}
d77de738 22184Generates the @code{movups} machine instruction as a load from memory.
f25efe50
AA
22185@enddefbuiltin
22186
22187@defbuiltin{void __builtin_ia32_storeups (float *, v4sf)}
d77de738 22188Generates the @code{movups} machine instruction as a store to memory.
f25efe50
AA
22189@enddefbuiltin
22190
22191@defbuiltin{v4sf __builtin_ia32_loadss (float *)}
d77de738 22192Generates the @code{movss} machine instruction as a load from memory.
f25efe50
AA
22193@enddefbuiltin
22194
22195@defbuiltin{v4sf __builtin_ia32_loadhps (v4sf, const v2sf *)}
d77de738 22196Generates the @code{movhps} machine instruction as a load from memory.
f25efe50
AA
22197@enddefbuiltin
22198
22199@defbuiltin{v4sf __builtin_ia32_loadlps (v4sf, const v2sf *)}
d77de738 22200Generates the @code{movlps} machine instruction as a load from memory
f25efe50
AA
22201@enddefbuiltin
22202
22203@defbuiltin{void __builtin_ia32_storehps (v2sf *, v4sf)}
d77de738 22204Generates the @code{movhps} machine instruction as a store to memory.
f25efe50
AA
22205@enddefbuiltin
22206
22207@defbuiltin{void __builtin_ia32_storelps (v2sf *, v4sf)}
d77de738 22208Generates the @code{movlps} machine instruction as a store to memory.
f25efe50 22209@enddefbuiltin
d77de738
ML
22210
22211The following built-in functions are available when @option{-msse2} is used.
22212All of them generate the machine instruction that is part of the name.
22213
22214@smallexample
22215int __builtin_ia32_comisdeq (v2df, v2df);
22216int __builtin_ia32_comisdlt (v2df, v2df);
22217int __builtin_ia32_comisdle (v2df, v2df);
22218int __builtin_ia32_comisdgt (v2df, v2df);
22219int __builtin_ia32_comisdge (v2df, v2df);
22220int __builtin_ia32_comisdneq (v2df, v2df);
22221int __builtin_ia32_ucomisdeq (v2df, v2df);
22222int __builtin_ia32_ucomisdlt (v2df, v2df);
22223int __builtin_ia32_ucomisdle (v2df, v2df);
22224int __builtin_ia32_ucomisdgt (v2df, v2df);
22225int __builtin_ia32_ucomisdge (v2df, v2df);
22226int __builtin_ia32_ucomisdneq (v2df, v2df);
22227v2df __builtin_ia32_cmpeqpd (v2df, v2df);
22228v2df __builtin_ia32_cmpltpd (v2df, v2df);
22229v2df __builtin_ia32_cmplepd (v2df, v2df);
22230v2df __builtin_ia32_cmpgtpd (v2df, v2df);
22231v2df __builtin_ia32_cmpgepd (v2df, v2df);
22232v2df __builtin_ia32_cmpunordpd (v2df, v2df);
22233v2df __builtin_ia32_cmpneqpd (v2df, v2df);
22234v2df __builtin_ia32_cmpnltpd (v2df, v2df);
22235v2df __builtin_ia32_cmpnlepd (v2df, v2df);
22236v2df __builtin_ia32_cmpngtpd (v2df, v2df);
22237v2df __builtin_ia32_cmpngepd (v2df, v2df);
22238v2df __builtin_ia32_cmpordpd (v2df, v2df);
22239v2df __builtin_ia32_cmpeqsd (v2df, v2df);
22240v2df __builtin_ia32_cmpltsd (v2df, v2df);
22241v2df __builtin_ia32_cmplesd (v2df, v2df);
22242v2df __builtin_ia32_cmpunordsd (v2df, v2df);
22243v2df __builtin_ia32_cmpneqsd (v2df, v2df);
22244v2df __builtin_ia32_cmpnltsd (v2df, v2df);
22245v2df __builtin_ia32_cmpnlesd (v2df, v2df);
22246v2df __builtin_ia32_cmpordsd (v2df, v2df);
22247v2di __builtin_ia32_paddq (v2di, v2di);
22248v2di __builtin_ia32_psubq (v2di, v2di);
22249v2df __builtin_ia32_addpd (v2df, v2df);
22250v2df __builtin_ia32_subpd (v2df, v2df);
22251v2df __builtin_ia32_mulpd (v2df, v2df);
22252v2df __builtin_ia32_divpd (v2df, v2df);
22253v2df __builtin_ia32_addsd (v2df, v2df);
22254v2df __builtin_ia32_subsd (v2df, v2df);
22255v2df __builtin_ia32_mulsd (v2df, v2df);
22256v2df __builtin_ia32_divsd (v2df, v2df);
22257v2df __builtin_ia32_minpd (v2df, v2df);
22258v2df __builtin_ia32_maxpd (v2df, v2df);
22259v2df __builtin_ia32_minsd (v2df, v2df);
22260v2df __builtin_ia32_maxsd (v2df, v2df);
22261v2df __builtin_ia32_andpd (v2df, v2df);
22262v2df __builtin_ia32_andnpd (v2df, v2df);
22263v2df __builtin_ia32_orpd (v2df, v2df);
22264v2df __builtin_ia32_xorpd (v2df, v2df);
22265v2df __builtin_ia32_movsd (v2df, v2df);
22266v2df __builtin_ia32_unpckhpd (v2df, v2df);
22267v2df __builtin_ia32_unpcklpd (v2df, v2df);
22268v16qi __builtin_ia32_paddb128 (v16qi, v16qi);
22269v8hi __builtin_ia32_paddw128 (v8hi, v8hi);
22270v4si __builtin_ia32_paddd128 (v4si, v4si);
22271v2di __builtin_ia32_paddq128 (v2di, v2di);
22272v16qi __builtin_ia32_psubb128 (v16qi, v16qi);
22273v8hi __builtin_ia32_psubw128 (v8hi, v8hi);
22274v4si __builtin_ia32_psubd128 (v4si, v4si);
22275v2di __builtin_ia32_psubq128 (v2di, v2di);
22276v8hi __builtin_ia32_pmullw128 (v8hi, v8hi);
22277v8hi __builtin_ia32_pmulhw128 (v8hi, v8hi);
22278v2di __builtin_ia32_pand128 (v2di, v2di);
22279v2di __builtin_ia32_pandn128 (v2di, v2di);
22280v2di __builtin_ia32_por128 (v2di, v2di);
22281v2di __builtin_ia32_pxor128 (v2di, v2di);
22282v16qi __builtin_ia32_pavgb128 (v16qi, v16qi);
22283v8hi __builtin_ia32_pavgw128 (v8hi, v8hi);
22284v16qi __builtin_ia32_pcmpeqb128 (v16qi, v16qi);
22285v8hi __builtin_ia32_pcmpeqw128 (v8hi, v8hi);
22286v4si __builtin_ia32_pcmpeqd128 (v4si, v4si);
22287v16qi __builtin_ia32_pcmpgtb128 (v16qi, v16qi);
22288v8hi __builtin_ia32_pcmpgtw128 (v8hi, v8hi);
22289v4si __builtin_ia32_pcmpgtd128 (v4si, v4si);
22290v16qi __builtin_ia32_pmaxub128 (v16qi, v16qi);
22291v8hi __builtin_ia32_pmaxsw128 (v8hi, v8hi);
22292v16qi __builtin_ia32_pminub128 (v16qi, v16qi);
22293v8hi __builtin_ia32_pminsw128 (v8hi, v8hi);
22294v16qi __builtin_ia32_punpckhbw128 (v16qi, v16qi);
22295v8hi __builtin_ia32_punpckhwd128 (v8hi, v8hi);
22296v4si __builtin_ia32_punpckhdq128 (v4si, v4si);
22297v2di __builtin_ia32_punpckhqdq128 (v2di, v2di);
22298v16qi __builtin_ia32_punpcklbw128 (v16qi, v16qi);
22299v8hi __builtin_ia32_punpcklwd128 (v8hi, v8hi);
22300v4si __builtin_ia32_punpckldq128 (v4si, v4si);
22301v2di __builtin_ia32_punpcklqdq128 (v2di, v2di);
22302v16qi __builtin_ia32_packsswb128 (v8hi, v8hi);
22303v8hi __builtin_ia32_packssdw128 (v4si, v4si);
22304v16qi __builtin_ia32_packuswb128 (v8hi, v8hi);
22305v8hi __builtin_ia32_pmulhuw128 (v8hi, v8hi);
22306void __builtin_ia32_maskmovdqu (v16qi, v16qi);
22307v2df __builtin_ia32_loadupd (double *);
22308void __builtin_ia32_storeupd (double *, v2df);
22309v2df __builtin_ia32_loadhpd (v2df, double const *);
22310v2df __builtin_ia32_loadlpd (v2df, double const *);
22311int __builtin_ia32_movmskpd (v2df);
22312int __builtin_ia32_pmovmskb128 (v16qi);
22313void __builtin_ia32_movnti (int *, int);
22314void __builtin_ia32_movnti64 (long long int *, long long int);
22315void __builtin_ia32_movntpd (double *, v2df);
22316void __builtin_ia32_movntdq (v2df *, v2df);
22317v4si __builtin_ia32_pshufd (v4si, int);
22318v8hi __builtin_ia32_pshuflw (v8hi, int);
22319v8hi __builtin_ia32_pshufhw (v8hi, int);
22320v2di __builtin_ia32_psadbw128 (v16qi, v16qi);
22321v2df __builtin_ia32_sqrtpd (v2df);
22322v2df __builtin_ia32_sqrtsd (v2df);
22323v2df __builtin_ia32_shufpd (v2df, v2df, int);
22324v2df __builtin_ia32_cvtdq2pd (v4si);
22325v4sf __builtin_ia32_cvtdq2ps (v4si);
22326v4si __builtin_ia32_cvtpd2dq (v2df);
22327v2si __builtin_ia32_cvtpd2pi (v2df);
22328v4sf __builtin_ia32_cvtpd2ps (v2df);
22329v4si __builtin_ia32_cvttpd2dq (v2df);
22330v2si __builtin_ia32_cvttpd2pi (v2df);
22331v2df __builtin_ia32_cvtpi2pd (v2si);
22332int __builtin_ia32_cvtsd2si (v2df);
22333int __builtin_ia32_cvttsd2si (v2df);
22334long long __builtin_ia32_cvtsd2si64 (v2df);
22335long long __builtin_ia32_cvttsd2si64 (v2df);
22336v4si __builtin_ia32_cvtps2dq (v4sf);
22337v2df __builtin_ia32_cvtps2pd (v4sf);
22338v4si __builtin_ia32_cvttps2dq (v4sf);
22339v2df __builtin_ia32_cvtsi2sd (v2df, int);
22340v2df __builtin_ia32_cvtsi642sd (v2df, long long);
22341v4sf __builtin_ia32_cvtsd2ss (v4sf, v2df);
22342v2df __builtin_ia32_cvtss2sd (v2df, v4sf);
22343void __builtin_ia32_clflush (const void *);
22344void __builtin_ia32_lfence (void);
22345void __builtin_ia32_mfence (void);
22346v16qi __builtin_ia32_loaddqu (const char *);
22347void __builtin_ia32_storedqu (char *, v16qi);
22348v1di __builtin_ia32_pmuludq (v2si, v2si);
22349v2di __builtin_ia32_pmuludq128 (v4si, v4si);
22350v8hi __builtin_ia32_psllw128 (v8hi, v8hi);
22351v4si __builtin_ia32_pslld128 (v4si, v4si);
22352v2di __builtin_ia32_psllq128 (v2di, v2di);
22353v8hi __builtin_ia32_psrlw128 (v8hi, v8hi);
22354v4si __builtin_ia32_psrld128 (v4si, v4si);
22355v2di __builtin_ia32_psrlq128 (v2di, v2di);
22356v8hi __builtin_ia32_psraw128 (v8hi, v8hi);
22357v4si __builtin_ia32_psrad128 (v4si, v4si);
22358v2di __builtin_ia32_pslldqi128 (v2di, int);
22359v8hi __builtin_ia32_psllwi128 (v8hi, int);
22360v4si __builtin_ia32_pslldi128 (v4si, int);
22361v2di __builtin_ia32_psllqi128 (v2di, int);
22362v2di __builtin_ia32_psrldqi128 (v2di, int);
22363v8hi __builtin_ia32_psrlwi128 (v8hi, int);
22364v4si __builtin_ia32_psrldi128 (v4si, int);
22365v2di __builtin_ia32_psrlqi128 (v2di, int);
22366v8hi __builtin_ia32_psrawi128 (v8hi, int);
22367v4si __builtin_ia32_psradi128 (v4si, int);
22368v4si __builtin_ia32_pmaddwd128 (v8hi, v8hi);
22369v2di __builtin_ia32_movq128 (v2di);
22370@end smallexample
22371
22372The following built-in functions are available when @option{-msse3} is used.
22373All of them generate the machine instruction that is part of the name.
22374
22375@smallexample
22376v2df __builtin_ia32_addsubpd (v2df, v2df);
22377v4sf __builtin_ia32_addsubps (v4sf, v4sf);
22378v2df __builtin_ia32_haddpd (v2df, v2df);
22379v4sf __builtin_ia32_haddps (v4sf, v4sf);
22380v2df __builtin_ia32_hsubpd (v2df, v2df);
22381v4sf __builtin_ia32_hsubps (v4sf, v4sf);
22382v16qi __builtin_ia32_lddqu (char const *);
22383void __builtin_ia32_monitor (void *, unsigned int, unsigned int);
22384v4sf __builtin_ia32_movshdup (v4sf);
22385v4sf __builtin_ia32_movsldup (v4sf);
22386void __builtin_ia32_mwait (unsigned int, unsigned int);
22387@end smallexample
22388
22389The following built-in functions are available when @option{-mssse3} is used.
22390All of them generate the machine instruction that is part of the name.
22391
22392@smallexample
22393v2si __builtin_ia32_phaddd (v2si, v2si);
22394v4hi __builtin_ia32_phaddw (v4hi, v4hi);
22395v4hi __builtin_ia32_phaddsw (v4hi, v4hi);
22396v2si __builtin_ia32_phsubd (v2si, v2si);
22397v4hi __builtin_ia32_phsubw (v4hi, v4hi);
22398v4hi __builtin_ia32_phsubsw (v4hi, v4hi);
22399v4hi __builtin_ia32_pmaddubsw (v8qi, v8qi);
22400v4hi __builtin_ia32_pmulhrsw (v4hi, v4hi);
22401v8qi __builtin_ia32_pshufb (v8qi, v8qi);
22402v8qi __builtin_ia32_psignb (v8qi, v8qi);
22403v2si __builtin_ia32_psignd (v2si, v2si);
22404v4hi __builtin_ia32_psignw (v4hi, v4hi);
22405v1di __builtin_ia32_palignr (v1di, v1di, int);
22406v8qi __builtin_ia32_pabsb (v8qi);
22407v2si __builtin_ia32_pabsd (v2si);
22408v4hi __builtin_ia32_pabsw (v4hi);
22409@end smallexample
22410
22411The following built-in functions are available when @option{-mssse3} is used.
22412All of them generate the machine instruction that is part of the name.
22413
22414@smallexample
22415v4si __builtin_ia32_phaddd128 (v4si, v4si);
22416v8hi __builtin_ia32_phaddw128 (v8hi, v8hi);
22417v8hi __builtin_ia32_phaddsw128 (v8hi, v8hi);
22418v4si __builtin_ia32_phsubd128 (v4si, v4si);
22419v8hi __builtin_ia32_phsubw128 (v8hi, v8hi);
22420v8hi __builtin_ia32_phsubsw128 (v8hi, v8hi);
22421v8hi __builtin_ia32_pmaddubsw128 (v16qi, v16qi);
22422v8hi __builtin_ia32_pmulhrsw128 (v8hi, v8hi);
22423v16qi __builtin_ia32_pshufb128 (v16qi, v16qi);
22424v16qi __builtin_ia32_psignb128 (v16qi, v16qi);
22425v4si __builtin_ia32_psignd128 (v4si, v4si);
22426v8hi __builtin_ia32_psignw128 (v8hi, v8hi);
22427v2di __builtin_ia32_palignr128 (v2di, v2di, int);
22428v16qi __builtin_ia32_pabsb128 (v16qi);
22429v4si __builtin_ia32_pabsd128 (v4si);
22430v8hi __builtin_ia32_pabsw128 (v8hi);
22431@end smallexample
22432
22433The following built-in functions are available when @option{-msse4.1} is
22434used. All of them generate the machine instruction that is part of the
22435name.
22436
22437@smallexample
22438v2df __builtin_ia32_blendpd (v2df, v2df, const int);
22439v4sf __builtin_ia32_blendps (v4sf, v4sf, const int);
22440v2df __builtin_ia32_blendvpd (v2df, v2df, v2df);
22441v4sf __builtin_ia32_blendvps (v4sf, v4sf, v4sf);
22442v2df __builtin_ia32_dppd (v2df, v2df, const int);
22443v4sf __builtin_ia32_dpps (v4sf, v4sf, const int);
22444v4sf __builtin_ia32_insertps128 (v4sf, v4sf, const int);
22445v2di __builtin_ia32_movntdqa (v2di *);
22446v16qi __builtin_ia32_mpsadbw128 (v16qi, v16qi, const int);
22447v8hi __builtin_ia32_packusdw128 (v4si, v4si);
22448v16qi __builtin_ia32_pblendvb128 (v16qi, v16qi, v16qi);
22449v8hi __builtin_ia32_pblendw128 (v8hi, v8hi, const int);
22450v2di __builtin_ia32_pcmpeqq (v2di, v2di);
22451v8hi __builtin_ia32_phminposuw128 (v8hi);
22452v16qi __builtin_ia32_pmaxsb128 (v16qi, v16qi);
22453v4si __builtin_ia32_pmaxsd128 (v4si, v4si);
22454v4si __builtin_ia32_pmaxud128 (v4si, v4si);
22455v8hi __builtin_ia32_pmaxuw128 (v8hi, v8hi);
22456v16qi __builtin_ia32_pminsb128 (v16qi, v16qi);
22457v4si __builtin_ia32_pminsd128 (v4si, v4si);
22458v4si __builtin_ia32_pminud128 (v4si, v4si);
22459v8hi __builtin_ia32_pminuw128 (v8hi, v8hi);
22460v4si __builtin_ia32_pmovsxbd128 (v16qi);
22461v2di __builtin_ia32_pmovsxbq128 (v16qi);
22462v8hi __builtin_ia32_pmovsxbw128 (v16qi);
22463v2di __builtin_ia32_pmovsxdq128 (v4si);
22464v4si __builtin_ia32_pmovsxwd128 (v8hi);
22465v2di __builtin_ia32_pmovsxwq128 (v8hi);
22466v4si __builtin_ia32_pmovzxbd128 (v16qi);
22467v2di __builtin_ia32_pmovzxbq128 (v16qi);
22468v8hi __builtin_ia32_pmovzxbw128 (v16qi);
22469v2di __builtin_ia32_pmovzxdq128 (v4si);
22470v4si __builtin_ia32_pmovzxwd128 (v8hi);
22471v2di __builtin_ia32_pmovzxwq128 (v8hi);
22472v2di __builtin_ia32_pmuldq128 (v4si, v4si);
22473v4si __builtin_ia32_pmulld128 (v4si, v4si);
22474int __builtin_ia32_ptestc128 (v2di, v2di);
22475int __builtin_ia32_ptestnzc128 (v2di, v2di);
22476int __builtin_ia32_ptestz128 (v2di, v2di);
22477v2df __builtin_ia32_roundpd (v2df, const int);
22478v4sf __builtin_ia32_roundps (v4sf, const int);
22479v2df __builtin_ia32_roundsd (v2df, v2df, const int);
22480v4sf __builtin_ia32_roundss (v4sf, v4sf, const int);
22481@end smallexample
22482
22483The following built-in functions are available when @option{-msse4.1} is
22484used.
22485
f25efe50 22486@defbuiltin{v4sf __builtin_ia32_vec_set_v4sf (v4sf, float, const int)}
d77de738 22487Generates the @code{insertps} machine instruction.
f25efe50
AA
22488@enddefbuiltin
22489
22490@defbuiltin{int __builtin_ia32_vec_ext_v16qi (v16qi, const int)}
d77de738 22491Generates the @code{pextrb} machine instruction.
f25efe50
AA
22492@enddefbuiltin
22493
22494@defbuiltin{v16qi __builtin_ia32_vec_set_v16qi (v16qi, int, const int)}
d77de738 22495Generates the @code{pinsrb} machine instruction.
f25efe50
AA
22496@enddefbuiltin
22497
22498@defbuiltin{v4si __builtin_ia32_vec_set_v4si (v4si, int, const int)}
d77de738 22499Generates the @code{pinsrd} machine instruction.
f25efe50
AA
22500@enddefbuiltin
22501
22502@defbuiltin{v2di __builtin_ia32_vec_set_v2di (v2di, long long, const int)}
d77de738 22503Generates the @code{pinsrq} machine instruction in 64bit mode.
f25efe50 22504@enddefbuiltin
d77de738
ML
22505
22506The following built-in functions are changed to generate new SSE4.1
22507instructions when @option{-msse4.1} is used.
22508
f25efe50 22509@defbuiltin{float __builtin_ia32_vec_ext_v4sf (v4sf, const int)}
d77de738 22510Generates the @code{extractps} machine instruction.
f25efe50
AA
22511@enddefbuiltin
22512
22513@defbuiltin{int __builtin_ia32_vec_ext_v4si (v4si, const int)}
d77de738 22514Generates the @code{pextrd} machine instruction.
f25efe50
AA
22515@enddefbuiltin
22516
22517@defbuiltin{long long __builtin_ia32_vec_ext_v2di (v2di, const int)}
d77de738 22518Generates the @code{pextrq} machine instruction in 64bit mode.
f25efe50 22519@enddefbuiltin
d77de738
ML
22520
22521The following built-in functions are available when @option{-msse4.2} is
22522used. All of them generate the machine instruction that is part of the
22523name.
22524
22525@smallexample
22526v16qi __builtin_ia32_pcmpestrm128 (v16qi, int, v16qi, int, const int);
22527int __builtin_ia32_pcmpestri128 (v16qi, int, v16qi, int, const int);
22528int __builtin_ia32_pcmpestria128 (v16qi, int, v16qi, int, const int);
22529int __builtin_ia32_pcmpestric128 (v16qi, int, v16qi, int, const int);
22530int __builtin_ia32_pcmpestrio128 (v16qi, int, v16qi, int, const int);
22531int __builtin_ia32_pcmpestris128 (v16qi, int, v16qi, int, const int);
22532int __builtin_ia32_pcmpestriz128 (v16qi, int, v16qi, int, const int);
22533v16qi __builtin_ia32_pcmpistrm128 (v16qi, v16qi, const int);
22534int __builtin_ia32_pcmpistri128 (v16qi, v16qi, const int);
22535int __builtin_ia32_pcmpistria128 (v16qi, v16qi, const int);
22536int __builtin_ia32_pcmpistric128 (v16qi, v16qi, const int);
22537int __builtin_ia32_pcmpistrio128 (v16qi, v16qi, const int);
22538int __builtin_ia32_pcmpistris128 (v16qi, v16qi, const int);
22539int __builtin_ia32_pcmpistriz128 (v16qi, v16qi, const int);
22540v2di __builtin_ia32_pcmpgtq (v2di, v2di);
22541@end smallexample
22542
22543The following built-in functions are available when @option{-msse4.2} is
22544used.
22545
f25efe50 22546@defbuiltin{unsigned int __builtin_ia32_crc32qi (unsigned int, unsigned char)}
d77de738 22547Generates the @code{crc32b} machine instruction.
f25efe50
AA
22548@enddefbuiltin
22549
22550@defbuiltin{unsigned int __builtin_ia32_crc32hi (unsigned int, unsigned short)}
d77de738 22551Generates the @code{crc32w} machine instruction.
f25efe50
AA
22552@enddefbuiltin
22553
22554@defbuiltin{unsigned int __builtin_ia32_crc32si (unsigned int, unsigned int)}
d77de738 22555Generates the @code{crc32l} machine instruction.
f25efe50
AA
22556@enddefbuiltin
22557
22558@defbuiltin{unsigned long long __builtin_ia32_crc32di (unsigned long long, unsigned long long)}
d77de738 22559Generates the @code{crc32q} machine instruction.
f25efe50 22560@enddefbuiltin
d77de738
ML
22561
22562The following built-in functions are changed to generate new SSE4.2
22563instructions when @option{-msse4.2} is used.
22564
f25efe50 22565@defbuiltin{int __builtin_popcount (unsigned int)}
d77de738 22566Generates the @code{popcntl} machine instruction.
f25efe50
AA
22567@enddefbuiltin
22568
22569@defbuiltin{int __builtin_popcountl (unsigned long)}
d77de738
ML
22570Generates the @code{popcntl} or @code{popcntq} machine instruction,
22571depending on the size of @code{unsigned long}.
f25efe50
AA
22572@enddefbuiltin
22573
22574@defbuiltin{int __builtin_popcountll (unsigned long long)}
d77de738 22575Generates the @code{popcntq} machine instruction.
f25efe50 22576@enddefbuiltin
d77de738
ML
22577
22578The following built-in functions are available when @option{-mavx} is
22579used. All of them generate the machine instruction that is part of the
22580name.
22581
22582@smallexample
22583v4df __builtin_ia32_addpd256 (v4df,v4df);
22584v8sf __builtin_ia32_addps256 (v8sf,v8sf);
22585v4df __builtin_ia32_addsubpd256 (v4df,v4df);
22586v8sf __builtin_ia32_addsubps256 (v8sf,v8sf);
22587v4df __builtin_ia32_andnpd256 (v4df,v4df);
22588v8sf __builtin_ia32_andnps256 (v8sf,v8sf);
22589v4df __builtin_ia32_andpd256 (v4df,v4df);
22590v8sf __builtin_ia32_andps256 (v8sf,v8sf);
22591v4df __builtin_ia32_blendpd256 (v4df,v4df,int);
22592v8sf __builtin_ia32_blendps256 (v8sf,v8sf,int);
22593v4df __builtin_ia32_blendvpd256 (v4df,v4df,v4df);
22594v8sf __builtin_ia32_blendvps256 (v8sf,v8sf,v8sf);
22595v2df __builtin_ia32_cmppd (v2df,v2df,int);
22596v4df __builtin_ia32_cmppd256 (v4df,v4df,int);
22597v4sf __builtin_ia32_cmpps (v4sf,v4sf,int);
22598v8sf __builtin_ia32_cmpps256 (v8sf,v8sf,int);
22599v2df __builtin_ia32_cmpsd (v2df,v2df,int);
22600v4sf __builtin_ia32_cmpss (v4sf,v4sf,int);
22601v4df __builtin_ia32_cvtdq2pd256 (v4si);
22602v8sf __builtin_ia32_cvtdq2ps256 (v8si);
22603v4si __builtin_ia32_cvtpd2dq256 (v4df);
22604v4sf __builtin_ia32_cvtpd2ps256 (v4df);
22605v8si __builtin_ia32_cvtps2dq256 (v8sf);
22606v4df __builtin_ia32_cvtps2pd256 (v4sf);
22607v4si __builtin_ia32_cvttpd2dq256 (v4df);
22608v8si __builtin_ia32_cvttps2dq256 (v8sf);
22609v4df __builtin_ia32_divpd256 (v4df,v4df);
22610v8sf __builtin_ia32_divps256 (v8sf,v8sf);
22611v8sf __builtin_ia32_dpps256 (v8sf,v8sf,int);
22612v4df __builtin_ia32_haddpd256 (v4df,v4df);
22613v8sf __builtin_ia32_haddps256 (v8sf,v8sf);
22614v4df __builtin_ia32_hsubpd256 (v4df,v4df);
22615v8sf __builtin_ia32_hsubps256 (v8sf,v8sf);
22616v32qi __builtin_ia32_lddqu256 (pcchar);
22617v32qi __builtin_ia32_loaddqu256 (pcchar);
22618v4df __builtin_ia32_loadupd256 (pcdouble);
22619v8sf __builtin_ia32_loadups256 (pcfloat);
22620v2df __builtin_ia32_maskloadpd (pcv2df,v2df);
22621v4df __builtin_ia32_maskloadpd256 (pcv4df,v4df);
22622v4sf __builtin_ia32_maskloadps (pcv4sf,v4sf);
22623v8sf __builtin_ia32_maskloadps256 (pcv8sf,v8sf);
22624void __builtin_ia32_maskstorepd (pv2df,v2df,v2df);
22625void __builtin_ia32_maskstorepd256 (pv4df,v4df,v4df);
22626void __builtin_ia32_maskstoreps (pv4sf,v4sf,v4sf);
22627void __builtin_ia32_maskstoreps256 (pv8sf,v8sf,v8sf);
22628v4df __builtin_ia32_maxpd256 (v4df,v4df);
22629v8sf __builtin_ia32_maxps256 (v8sf,v8sf);
22630v4df __builtin_ia32_minpd256 (v4df,v4df);
22631v8sf __builtin_ia32_minps256 (v8sf,v8sf);
22632v4df __builtin_ia32_movddup256 (v4df);
22633int __builtin_ia32_movmskpd256 (v4df);
22634int __builtin_ia32_movmskps256 (v8sf);
22635v8sf __builtin_ia32_movshdup256 (v8sf);
22636v8sf __builtin_ia32_movsldup256 (v8sf);
22637v4df __builtin_ia32_mulpd256 (v4df,v4df);
22638v8sf __builtin_ia32_mulps256 (v8sf,v8sf);
22639v4df __builtin_ia32_orpd256 (v4df,v4df);
22640v8sf __builtin_ia32_orps256 (v8sf,v8sf);
22641v2df __builtin_ia32_pd_pd256 (v4df);
22642v4df __builtin_ia32_pd256_pd (v2df);
22643v4sf __builtin_ia32_ps_ps256 (v8sf);
22644v8sf __builtin_ia32_ps256_ps (v4sf);
22645int __builtin_ia32_ptestc256 (v4di,v4di,ptest);
22646int __builtin_ia32_ptestnzc256 (v4di,v4di,ptest);
22647int __builtin_ia32_ptestz256 (v4di,v4di,ptest);
22648v8sf __builtin_ia32_rcpps256 (v8sf);
22649v4df __builtin_ia32_roundpd256 (v4df,int);
22650v8sf __builtin_ia32_roundps256 (v8sf,int);
22651v8sf __builtin_ia32_rsqrtps_nr256 (v8sf);
22652v8sf __builtin_ia32_rsqrtps256 (v8sf);
22653v4df __builtin_ia32_shufpd256 (v4df,v4df,int);
22654v8sf __builtin_ia32_shufps256 (v8sf,v8sf,int);
22655v4si __builtin_ia32_si_si256 (v8si);
22656v8si __builtin_ia32_si256_si (v4si);
22657v4df __builtin_ia32_sqrtpd256 (v4df);
22658v8sf __builtin_ia32_sqrtps_nr256 (v8sf);
22659v8sf __builtin_ia32_sqrtps256 (v8sf);
22660void __builtin_ia32_storedqu256 (pchar,v32qi);
22661void __builtin_ia32_storeupd256 (pdouble,v4df);
22662void __builtin_ia32_storeups256 (pfloat,v8sf);
22663v4df __builtin_ia32_subpd256 (v4df,v4df);
22664v8sf __builtin_ia32_subps256 (v8sf,v8sf);
22665v4df __builtin_ia32_unpckhpd256 (v4df,v4df);
22666v8sf __builtin_ia32_unpckhps256 (v8sf,v8sf);
22667v4df __builtin_ia32_unpcklpd256 (v4df,v4df);
22668v8sf __builtin_ia32_unpcklps256 (v8sf,v8sf);
22669v4df __builtin_ia32_vbroadcastf128_pd256 (pcv2df);
22670v8sf __builtin_ia32_vbroadcastf128_ps256 (pcv4sf);
22671v4df __builtin_ia32_vbroadcastsd256 (pcdouble);
22672v4sf __builtin_ia32_vbroadcastss (pcfloat);
22673v8sf __builtin_ia32_vbroadcastss256 (pcfloat);
22674v2df __builtin_ia32_vextractf128_pd256 (v4df,int);
22675v4sf __builtin_ia32_vextractf128_ps256 (v8sf,int);
22676v4si __builtin_ia32_vextractf128_si256 (v8si,int);
22677v4df __builtin_ia32_vinsertf128_pd256 (v4df,v2df,int);
22678v8sf __builtin_ia32_vinsertf128_ps256 (v8sf,v4sf,int);
22679v8si __builtin_ia32_vinsertf128_si256 (v8si,v4si,int);
22680v4df __builtin_ia32_vperm2f128_pd256 (v4df,v4df,int);
22681v8sf __builtin_ia32_vperm2f128_ps256 (v8sf,v8sf,int);
22682v8si __builtin_ia32_vperm2f128_si256 (v8si,v8si,int);
22683v2df __builtin_ia32_vpermil2pd (v2df,v2df,v2di,int);
22684v4df __builtin_ia32_vpermil2pd256 (v4df,v4df,v4di,int);
22685v4sf __builtin_ia32_vpermil2ps (v4sf,v4sf,v4si,int);
22686v8sf __builtin_ia32_vpermil2ps256 (v8sf,v8sf,v8si,int);
22687v2df __builtin_ia32_vpermilpd (v2df,int);
22688v4df __builtin_ia32_vpermilpd256 (v4df,int);
22689v4sf __builtin_ia32_vpermilps (v4sf,int);
22690v8sf __builtin_ia32_vpermilps256 (v8sf,int);
22691v2df __builtin_ia32_vpermilvarpd (v2df,v2di);
22692v4df __builtin_ia32_vpermilvarpd256 (v4df,v4di);
22693v4sf __builtin_ia32_vpermilvarps (v4sf,v4si);
22694v8sf __builtin_ia32_vpermilvarps256 (v8sf,v8si);
22695int __builtin_ia32_vtestcpd (v2df,v2df,ptest);
22696int __builtin_ia32_vtestcpd256 (v4df,v4df,ptest);
22697int __builtin_ia32_vtestcps (v4sf,v4sf,ptest);
22698int __builtin_ia32_vtestcps256 (v8sf,v8sf,ptest);
22699int __builtin_ia32_vtestnzcpd (v2df,v2df,ptest);
22700int __builtin_ia32_vtestnzcpd256 (v4df,v4df,ptest);
22701int __builtin_ia32_vtestnzcps (v4sf,v4sf,ptest);
22702int __builtin_ia32_vtestnzcps256 (v8sf,v8sf,ptest);
22703int __builtin_ia32_vtestzpd (v2df,v2df,ptest);
22704int __builtin_ia32_vtestzpd256 (v4df,v4df,ptest);
22705int __builtin_ia32_vtestzps (v4sf,v4sf,ptest);
22706int __builtin_ia32_vtestzps256 (v8sf,v8sf,ptest);
22707void __builtin_ia32_vzeroall (void);
22708void __builtin_ia32_vzeroupper (void);
22709v4df __builtin_ia32_xorpd256 (v4df,v4df);
22710v8sf __builtin_ia32_xorps256 (v8sf,v8sf);
22711@end smallexample
22712
22713The following built-in functions are available when @option{-mavx2} is
22714used. All of them generate the machine instruction that is part of the
22715name.
22716
22717@smallexample
22718v32qi __builtin_ia32_mpsadbw256 (v32qi,v32qi,int);
22719v32qi __builtin_ia32_pabsb256 (v32qi);
22720v16hi __builtin_ia32_pabsw256 (v16hi);
22721v8si __builtin_ia32_pabsd256 (v8si);
22722v16hi __builtin_ia32_packssdw256 (v8si,v8si);
22723v32qi __builtin_ia32_packsswb256 (v16hi,v16hi);
22724v16hi __builtin_ia32_packusdw256 (v8si,v8si);
22725v32qi __builtin_ia32_packuswb256 (v16hi,v16hi);
22726v32qi __builtin_ia32_paddb256 (v32qi,v32qi);
22727v16hi __builtin_ia32_paddw256 (v16hi,v16hi);
22728v8si __builtin_ia32_paddd256 (v8si,v8si);
22729v4di __builtin_ia32_paddq256 (v4di,v4di);
22730v32qi __builtin_ia32_paddsb256 (v32qi,v32qi);
22731v16hi __builtin_ia32_paddsw256 (v16hi,v16hi);
22732v32qi __builtin_ia32_paddusb256 (v32qi,v32qi);
22733v16hi __builtin_ia32_paddusw256 (v16hi,v16hi);
22734v4di __builtin_ia32_palignr256 (v4di,v4di,int);
22735v4di __builtin_ia32_andsi256 (v4di,v4di);
22736v4di __builtin_ia32_andnotsi256 (v4di,v4di);
22737v32qi __builtin_ia32_pavgb256 (v32qi,v32qi);
22738v16hi __builtin_ia32_pavgw256 (v16hi,v16hi);
22739v32qi __builtin_ia32_pblendvb256 (v32qi,v32qi,v32qi);
22740v16hi __builtin_ia32_pblendw256 (v16hi,v16hi,int);
22741v32qi __builtin_ia32_pcmpeqb256 (v32qi,v32qi);
22742v16hi __builtin_ia32_pcmpeqw256 (v16hi,v16hi);
22743v8si __builtin_ia32_pcmpeqd256 (c8si,v8si);
22744v4di __builtin_ia32_pcmpeqq256 (v4di,v4di);
22745v32qi __builtin_ia32_pcmpgtb256 (v32qi,v32qi);
22746v16hi __builtin_ia32_pcmpgtw256 (16hi,v16hi);
22747v8si __builtin_ia32_pcmpgtd256 (v8si,v8si);
22748v4di __builtin_ia32_pcmpgtq256 (v4di,v4di);
22749v16hi __builtin_ia32_phaddw256 (v16hi,v16hi);
22750v8si __builtin_ia32_phaddd256 (v8si,v8si);
22751v16hi __builtin_ia32_phaddsw256 (v16hi,v16hi);
22752v16hi __builtin_ia32_phsubw256 (v16hi,v16hi);
22753v8si __builtin_ia32_phsubd256 (v8si,v8si);
22754v16hi __builtin_ia32_phsubsw256 (v16hi,v16hi);
22755v32qi __builtin_ia32_pmaddubsw256 (v32qi,v32qi);
22756v16hi __builtin_ia32_pmaddwd256 (v16hi,v16hi);
22757v32qi __builtin_ia32_pmaxsb256 (v32qi,v32qi);
22758v16hi __builtin_ia32_pmaxsw256 (v16hi,v16hi);
22759v8si __builtin_ia32_pmaxsd256 (v8si,v8si);
22760v32qi __builtin_ia32_pmaxub256 (v32qi,v32qi);
22761v16hi __builtin_ia32_pmaxuw256 (v16hi,v16hi);
22762v8si __builtin_ia32_pmaxud256 (v8si,v8si);
22763v32qi __builtin_ia32_pminsb256 (v32qi,v32qi);
22764v16hi __builtin_ia32_pminsw256 (v16hi,v16hi);
22765v8si __builtin_ia32_pminsd256 (v8si,v8si);
22766v32qi __builtin_ia32_pminub256 (v32qi,v32qi);
22767v16hi __builtin_ia32_pminuw256 (v16hi,v16hi);
22768v8si __builtin_ia32_pminud256 (v8si,v8si);
22769int __builtin_ia32_pmovmskb256 (v32qi);
22770v16hi __builtin_ia32_pmovsxbw256 (v16qi);
22771v8si __builtin_ia32_pmovsxbd256 (v16qi);
22772v4di __builtin_ia32_pmovsxbq256 (v16qi);
22773v8si __builtin_ia32_pmovsxwd256 (v8hi);
22774v4di __builtin_ia32_pmovsxwq256 (v8hi);
22775v4di __builtin_ia32_pmovsxdq256 (v4si);
22776v16hi __builtin_ia32_pmovzxbw256 (v16qi);
22777v8si __builtin_ia32_pmovzxbd256 (v16qi);
22778v4di __builtin_ia32_pmovzxbq256 (v16qi);
22779v8si __builtin_ia32_pmovzxwd256 (v8hi);
22780v4di __builtin_ia32_pmovzxwq256 (v8hi);
22781v4di __builtin_ia32_pmovzxdq256 (v4si);
22782v4di __builtin_ia32_pmuldq256 (v8si,v8si);
22783v16hi __builtin_ia32_pmulhrsw256 (v16hi, v16hi);
22784v16hi __builtin_ia32_pmulhuw256 (v16hi,v16hi);
22785v16hi __builtin_ia32_pmulhw256 (v16hi,v16hi);
22786v16hi __builtin_ia32_pmullw256 (v16hi,v16hi);
22787v8si __builtin_ia32_pmulld256 (v8si,v8si);
22788v4di __builtin_ia32_pmuludq256 (v8si,v8si);
22789v4di __builtin_ia32_por256 (v4di,v4di);
22790v16hi __builtin_ia32_psadbw256 (v32qi,v32qi);
22791v32qi __builtin_ia32_pshufb256 (v32qi,v32qi);
22792v8si __builtin_ia32_pshufd256 (v8si,int);
22793v16hi __builtin_ia32_pshufhw256 (v16hi,int);
22794v16hi __builtin_ia32_pshuflw256 (v16hi,int);
22795v32qi __builtin_ia32_psignb256 (v32qi,v32qi);
22796v16hi __builtin_ia32_psignw256 (v16hi,v16hi);
22797v8si __builtin_ia32_psignd256 (v8si,v8si);
22798v4di __builtin_ia32_pslldqi256 (v4di,int);
22799v16hi __builtin_ia32_psllwi256 (16hi,int);
22800v16hi __builtin_ia32_psllw256(v16hi,v8hi);
22801v8si __builtin_ia32_pslldi256 (v8si,int);
22802v8si __builtin_ia32_pslld256(v8si,v4si);
22803v4di __builtin_ia32_psllqi256 (v4di,int);
22804v4di __builtin_ia32_psllq256(v4di,v2di);
22805v16hi __builtin_ia32_psrawi256 (v16hi,int);
22806v16hi __builtin_ia32_psraw256 (v16hi,v8hi);
22807v8si __builtin_ia32_psradi256 (v8si,int);
22808v8si __builtin_ia32_psrad256 (v8si,v4si);
22809v4di __builtin_ia32_psrldqi256 (v4di, int);
22810v16hi __builtin_ia32_psrlwi256 (v16hi,int);
22811v16hi __builtin_ia32_psrlw256 (v16hi,v8hi);
22812v8si __builtin_ia32_psrldi256 (v8si,int);
22813v8si __builtin_ia32_psrld256 (v8si,v4si);
22814v4di __builtin_ia32_psrlqi256 (v4di,int);
22815v4di __builtin_ia32_psrlq256(v4di,v2di);
22816v32qi __builtin_ia32_psubb256 (v32qi,v32qi);
22817v32hi __builtin_ia32_psubw256 (v16hi,v16hi);
22818v8si __builtin_ia32_psubd256 (v8si,v8si);
22819v4di __builtin_ia32_psubq256 (v4di,v4di);
22820v32qi __builtin_ia32_psubsb256 (v32qi,v32qi);
22821v16hi __builtin_ia32_psubsw256 (v16hi,v16hi);
22822v32qi __builtin_ia32_psubusb256 (v32qi,v32qi);
22823v16hi __builtin_ia32_psubusw256 (v16hi,v16hi);
22824v32qi __builtin_ia32_punpckhbw256 (v32qi,v32qi);
22825v16hi __builtin_ia32_punpckhwd256 (v16hi,v16hi);
22826v8si __builtin_ia32_punpckhdq256 (v8si,v8si);
22827v4di __builtin_ia32_punpckhqdq256 (v4di,v4di);
22828v32qi __builtin_ia32_punpcklbw256 (v32qi,v32qi);
22829v16hi __builtin_ia32_punpcklwd256 (v16hi,v16hi);
22830v8si __builtin_ia32_punpckldq256 (v8si,v8si);
22831v4di __builtin_ia32_punpcklqdq256 (v4di,v4di);
22832v4di __builtin_ia32_pxor256 (v4di,v4di);
22833v4di __builtin_ia32_movntdqa256 (pv4di);
22834v4sf __builtin_ia32_vbroadcastss_ps (v4sf);
22835v8sf __builtin_ia32_vbroadcastss_ps256 (v4sf);
22836v4df __builtin_ia32_vbroadcastsd_pd256 (v2df);
22837v4di __builtin_ia32_vbroadcastsi256 (v2di);
22838v4si __builtin_ia32_pblendd128 (v4si,v4si);
22839v8si __builtin_ia32_pblendd256 (v8si,v8si);
22840v32qi __builtin_ia32_pbroadcastb256 (v16qi);
22841v16hi __builtin_ia32_pbroadcastw256 (v8hi);
22842v8si __builtin_ia32_pbroadcastd256 (v4si);
22843v4di __builtin_ia32_pbroadcastq256 (v2di);
22844v16qi __builtin_ia32_pbroadcastb128 (v16qi);
22845v8hi __builtin_ia32_pbroadcastw128 (v8hi);
22846v4si __builtin_ia32_pbroadcastd128 (v4si);
22847v2di __builtin_ia32_pbroadcastq128 (v2di);
22848v8si __builtin_ia32_permvarsi256 (v8si,v8si);
22849v4df __builtin_ia32_permdf256 (v4df,int);
22850v8sf __builtin_ia32_permvarsf256 (v8sf,v8sf);
22851v4di __builtin_ia32_permdi256 (v4di,int);
22852v4di __builtin_ia32_permti256 (v4di,v4di,int);
22853v4di __builtin_ia32_extract128i256 (v4di,int);
22854v4di __builtin_ia32_insert128i256 (v4di,v2di,int);
22855v8si __builtin_ia32_maskloadd256 (pcv8si,v8si);
22856v4di __builtin_ia32_maskloadq256 (pcv4di,v4di);
22857v4si __builtin_ia32_maskloadd (pcv4si,v4si);
22858v2di __builtin_ia32_maskloadq (pcv2di,v2di);
22859void __builtin_ia32_maskstored256 (pv8si,v8si,v8si);
22860void __builtin_ia32_maskstoreq256 (pv4di,v4di,v4di);
22861void __builtin_ia32_maskstored (pv4si,v4si,v4si);
22862void __builtin_ia32_maskstoreq (pv2di,v2di,v2di);
22863v8si __builtin_ia32_psllv8si (v8si,v8si);
22864v4si __builtin_ia32_psllv4si (v4si,v4si);
22865v4di __builtin_ia32_psllv4di (v4di,v4di);
22866v2di __builtin_ia32_psllv2di (v2di,v2di);
22867v8si __builtin_ia32_psrav8si (v8si,v8si);
22868v4si __builtin_ia32_psrav4si (v4si,v4si);
22869v8si __builtin_ia32_psrlv8si (v8si,v8si);
22870v4si __builtin_ia32_psrlv4si (v4si,v4si);
22871v4di __builtin_ia32_psrlv4di (v4di,v4di);
22872v2di __builtin_ia32_psrlv2di (v2di,v2di);
22873v2df __builtin_ia32_gathersiv2df (v2df, pcdouble,v4si,v2df,int);
22874v4df __builtin_ia32_gathersiv4df (v4df, pcdouble,v4si,v4df,int);
22875v2df __builtin_ia32_gatherdiv2df (v2df, pcdouble,v2di,v2df,int);
22876v4df __builtin_ia32_gatherdiv4df (v4df, pcdouble,v4di,v4df,int);
22877v4sf __builtin_ia32_gathersiv4sf (v4sf, pcfloat,v4si,v4sf,int);
22878v8sf __builtin_ia32_gathersiv8sf (v8sf, pcfloat,v8si,v8sf,int);
22879v4sf __builtin_ia32_gatherdiv4sf (v4sf, pcfloat,v2di,v4sf,int);
22880v4sf __builtin_ia32_gatherdiv4sf256 (v4sf, pcfloat,v4di,v4sf,int);
22881v2di __builtin_ia32_gathersiv2di (v2di, pcint64,v4si,v2di,int);
22882v4di __builtin_ia32_gathersiv4di (v4di, pcint64,v4si,v4di,int);
22883v2di __builtin_ia32_gatherdiv2di (v2di, pcint64,v2di,v2di,int);
22884v4di __builtin_ia32_gatherdiv4di (v4di, pcint64,v4di,v4di,int);
22885v4si __builtin_ia32_gathersiv4si (v4si, pcint,v4si,v4si,int);
22886v8si __builtin_ia32_gathersiv8si (v8si, pcint,v8si,v8si,int);
22887v4si __builtin_ia32_gatherdiv4si (v4si, pcint,v2di,v4si,int);
22888v4si __builtin_ia32_gatherdiv4si256 (v4si, pcint,v4di,v4si,int);
22889@end smallexample
22890
22891The following built-in functions are available when @option{-maes} is
22892used. All of them generate the machine instruction that is part of the
22893name.
22894
22895@smallexample
22896v2di __builtin_ia32_aesenc128 (v2di, v2di);
22897v2di __builtin_ia32_aesenclast128 (v2di, v2di);
22898v2di __builtin_ia32_aesdec128 (v2di, v2di);
22899v2di __builtin_ia32_aesdeclast128 (v2di, v2di);
22900v2di __builtin_ia32_aeskeygenassist128 (v2di, const int);
22901v2di __builtin_ia32_aesimc128 (v2di);
22902@end smallexample
22903
22904The following built-in function is available when @option{-mpclmul} is
22905used.
22906
f25efe50 22907@defbuiltin{v2di __builtin_ia32_pclmulqdq128 (v2di, v2di, const int)}
d77de738 22908Generates the @code{pclmulqdq} machine instruction.
f25efe50 22909@enddefbuiltin
d77de738
ML
22910
22911The following built-in function is available when @option{-mfsgsbase} is
22912used. All of them generate the machine instruction that is part of the
22913name.
22914
22915@smallexample
22916unsigned int __builtin_ia32_rdfsbase32 (void);
22917unsigned long long __builtin_ia32_rdfsbase64 (void);
22918unsigned int __builtin_ia32_rdgsbase32 (void);
22919unsigned long long __builtin_ia32_rdgsbase64 (void);
22920void _writefsbase_u32 (unsigned int);
22921void _writefsbase_u64 (unsigned long long);
22922void _writegsbase_u32 (unsigned int);
22923void _writegsbase_u64 (unsigned long long);
22924@end smallexample
22925
22926The following built-in function is available when @option{-mrdrnd} is
22927used. All of them generate the machine instruction that is part of the
22928name.
22929
22930@smallexample
22931unsigned int __builtin_ia32_rdrand16_step (unsigned short *);
22932unsigned int __builtin_ia32_rdrand32_step (unsigned int *);
22933unsigned int __builtin_ia32_rdrand64_step (unsigned long long *);
22934@end smallexample
22935
22936The following built-in function is available when @option{-mptwrite} is
22937used. All of them generate the machine instruction that is part of the
22938name.
22939
22940@smallexample
22941void __builtin_ia32_ptwrite32 (unsigned);
22942void __builtin_ia32_ptwrite64 (unsigned long long);
22943@end smallexample
22944
22945The following built-in functions are available when @option{-msse4a} is used.
22946All of them generate the machine instruction that is part of the name.
22947
22948@smallexample
22949void __builtin_ia32_movntsd (double *, v2df);
22950void __builtin_ia32_movntss (float *, v4sf);
22951v2di __builtin_ia32_extrq (v2di, v16qi);
22952v2di __builtin_ia32_extrqi (v2di, const unsigned int, const unsigned int);
22953v2di __builtin_ia32_insertq (v2di, v2di);
22954v2di __builtin_ia32_insertqi (v2di, v2di, const unsigned int, const unsigned int);
22955@end smallexample
22956
22957The following built-in functions are available when @option{-mxop} is used.
22958@smallexample
22959v2df __builtin_ia32_vfrczpd (v2df);
22960v4sf __builtin_ia32_vfrczps (v4sf);
22961v2df __builtin_ia32_vfrczsd (v2df);
22962v4sf __builtin_ia32_vfrczss (v4sf);
22963v4df __builtin_ia32_vfrczpd256 (v4df);
22964v8sf __builtin_ia32_vfrczps256 (v8sf);
22965v2di __builtin_ia32_vpcmov (v2di, v2di, v2di);
22966v2di __builtin_ia32_vpcmov_v2di (v2di, v2di, v2di);
22967v4si __builtin_ia32_vpcmov_v4si (v4si, v4si, v4si);
22968v8hi __builtin_ia32_vpcmov_v8hi (v8hi, v8hi, v8hi);
22969v16qi __builtin_ia32_vpcmov_v16qi (v16qi, v16qi, v16qi);
22970v2df __builtin_ia32_vpcmov_v2df (v2df, v2df, v2df);
22971v4sf __builtin_ia32_vpcmov_v4sf (v4sf, v4sf, v4sf);
22972v4di __builtin_ia32_vpcmov_v4di256 (v4di, v4di, v4di);
22973v8si __builtin_ia32_vpcmov_v8si256 (v8si, v8si, v8si);
22974v16hi __builtin_ia32_vpcmov_v16hi256 (v16hi, v16hi, v16hi);
22975v32qi __builtin_ia32_vpcmov_v32qi256 (v32qi, v32qi, v32qi);
22976v4df __builtin_ia32_vpcmov_v4df256 (v4df, v4df, v4df);
22977v8sf __builtin_ia32_vpcmov_v8sf256 (v8sf, v8sf, v8sf);
22978v16qi __builtin_ia32_vpcomeqb (v16qi, v16qi);
22979v8hi __builtin_ia32_vpcomeqw (v8hi, v8hi);
22980v4si __builtin_ia32_vpcomeqd (v4si, v4si);
22981v2di __builtin_ia32_vpcomeqq (v2di, v2di);
22982v16qi __builtin_ia32_vpcomequb (v16qi, v16qi);
22983v4si __builtin_ia32_vpcomequd (v4si, v4si);
22984v2di __builtin_ia32_vpcomequq (v2di, v2di);
22985v8hi __builtin_ia32_vpcomequw (v8hi, v8hi);
22986v8hi __builtin_ia32_vpcomeqw (v8hi, v8hi);
22987v16qi __builtin_ia32_vpcomfalseb (v16qi, v16qi);
22988v4si __builtin_ia32_vpcomfalsed (v4si, v4si);
22989v2di __builtin_ia32_vpcomfalseq (v2di, v2di);
22990v16qi __builtin_ia32_vpcomfalseub (v16qi, v16qi);
22991v4si __builtin_ia32_vpcomfalseud (v4si, v4si);
22992v2di __builtin_ia32_vpcomfalseuq (v2di, v2di);
22993v8hi __builtin_ia32_vpcomfalseuw (v8hi, v8hi);
22994v8hi __builtin_ia32_vpcomfalsew (v8hi, v8hi);
22995v16qi __builtin_ia32_vpcomgeb (v16qi, v16qi);
22996v4si __builtin_ia32_vpcomged (v4si, v4si);
22997v2di __builtin_ia32_vpcomgeq (v2di, v2di);
22998v16qi __builtin_ia32_vpcomgeub (v16qi, v16qi);
22999v4si __builtin_ia32_vpcomgeud (v4si, v4si);
23000v2di __builtin_ia32_vpcomgeuq (v2di, v2di);
23001v8hi __builtin_ia32_vpcomgeuw (v8hi, v8hi);
23002v8hi __builtin_ia32_vpcomgew (v8hi, v8hi);
23003v16qi __builtin_ia32_vpcomgtb (v16qi, v16qi);
23004v4si __builtin_ia32_vpcomgtd (v4si, v4si);
23005v2di __builtin_ia32_vpcomgtq (v2di, v2di);
23006v16qi __builtin_ia32_vpcomgtub (v16qi, v16qi);
23007v4si __builtin_ia32_vpcomgtud (v4si, v4si);
23008v2di __builtin_ia32_vpcomgtuq (v2di, v2di);
23009v8hi __builtin_ia32_vpcomgtuw (v8hi, v8hi);
23010v8hi __builtin_ia32_vpcomgtw (v8hi, v8hi);
23011v16qi __builtin_ia32_vpcomleb (v16qi, v16qi);
23012v4si __builtin_ia32_vpcomled (v4si, v4si);
23013v2di __builtin_ia32_vpcomleq (v2di, v2di);
23014v16qi __builtin_ia32_vpcomleub (v16qi, v16qi);
23015v4si __builtin_ia32_vpcomleud (v4si, v4si);
23016v2di __builtin_ia32_vpcomleuq (v2di, v2di);
23017v8hi __builtin_ia32_vpcomleuw (v8hi, v8hi);
23018v8hi __builtin_ia32_vpcomlew (v8hi, v8hi);
23019v16qi __builtin_ia32_vpcomltb (v16qi, v16qi);
23020v4si __builtin_ia32_vpcomltd (v4si, v4si);
23021v2di __builtin_ia32_vpcomltq (v2di, v2di);
23022v16qi __builtin_ia32_vpcomltub (v16qi, v16qi);
23023v4si __builtin_ia32_vpcomltud (v4si, v4si);
23024v2di __builtin_ia32_vpcomltuq (v2di, v2di);
23025v8hi __builtin_ia32_vpcomltuw (v8hi, v8hi);
23026v8hi __builtin_ia32_vpcomltw (v8hi, v8hi);
23027v16qi __builtin_ia32_vpcomneb (v16qi, v16qi);
23028v4si __builtin_ia32_vpcomned (v4si, v4si);
23029v2di __builtin_ia32_vpcomneq (v2di, v2di);
23030v16qi __builtin_ia32_vpcomneub (v16qi, v16qi);
23031v4si __builtin_ia32_vpcomneud (v4si, v4si);
23032v2di __builtin_ia32_vpcomneuq (v2di, v2di);
23033v8hi __builtin_ia32_vpcomneuw (v8hi, v8hi);
23034v8hi __builtin_ia32_vpcomnew (v8hi, v8hi);
23035v16qi __builtin_ia32_vpcomtrueb (v16qi, v16qi);
23036v4si __builtin_ia32_vpcomtrued (v4si, v4si);
23037v2di __builtin_ia32_vpcomtrueq (v2di, v2di);
23038v16qi __builtin_ia32_vpcomtrueub (v16qi, v16qi);
23039v4si __builtin_ia32_vpcomtrueud (v4si, v4si);
23040v2di __builtin_ia32_vpcomtrueuq (v2di, v2di);
23041v8hi __builtin_ia32_vpcomtrueuw (v8hi, v8hi);
23042v8hi __builtin_ia32_vpcomtruew (v8hi, v8hi);
23043v4si __builtin_ia32_vphaddbd (v16qi);
23044v2di __builtin_ia32_vphaddbq (v16qi);
23045v8hi __builtin_ia32_vphaddbw (v16qi);
23046v2di __builtin_ia32_vphadddq (v4si);
23047v4si __builtin_ia32_vphaddubd (v16qi);
23048v2di __builtin_ia32_vphaddubq (v16qi);
23049v8hi __builtin_ia32_vphaddubw (v16qi);
23050v2di __builtin_ia32_vphaddudq (v4si);
23051v4si __builtin_ia32_vphadduwd (v8hi);
23052v2di __builtin_ia32_vphadduwq (v8hi);
23053v4si __builtin_ia32_vphaddwd (v8hi);
23054v2di __builtin_ia32_vphaddwq (v8hi);
23055v8hi __builtin_ia32_vphsubbw (v16qi);
23056v2di __builtin_ia32_vphsubdq (v4si);
23057v4si __builtin_ia32_vphsubwd (v8hi);
23058v4si __builtin_ia32_vpmacsdd (v4si, v4si, v4si);
23059v2di __builtin_ia32_vpmacsdqh (v4si, v4si, v2di);
23060v2di __builtin_ia32_vpmacsdql (v4si, v4si, v2di);
23061v4si __builtin_ia32_vpmacssdd (v4si, v4si, v4si);
23062v2di __builtin_ia32_vpmacssdqh (v4si, v4si, v2di);
23063v2di __builtin_ia32_vpmacssdql (v4si, v4si, v2di);
23064v4si __builtin_ia32_vpmacsswd (v8hi, v8hi, v4si);
23065v8hi __builtin_ia32_vpmacssww (v8hi, v8hi, v8hi);
23066v4si __builtin_ia32_vpmacswd (v8hi, v8hi, v4si);
23067v8hi __builtin_ia32_vpmacsww (v8hi, v8hi, v8hi);
23068v4si __builtin_ia32_vpmadcsswd (v8hi, v8hi, v4si);
23069v4si __builtin_ia32_vpmadcswd (v8hi, v8hi, v4si);
23070v16qi __builtin_ia32_vpperm (v16qi, v16qi, v16qi);
23071v16qi __builtin_ia32_vprotb (v16qi, v16qi);
23072v4si __builtin_ia32_vprotd (v4si, v4si);
23073v2di __builtin_ia32_vprotq (v2di, v2di);
23074v8hi __builtin_ia32_vprotw (v8hi, v8hi);
23075v16qi __builtin_ia32_vpshab (v16qi, v16qi);
23076v4si __builtin_ia32_vpshad (v4si, v4si);
23077v2di __builtin_ia32_vpshaq (v2di, v2di);
23078v8hi __builtin_ia32_vpshaw (v8hi, v8hi);
23079v16qi __builtin_ia32_vpshlb (v16qi, v16qi);
23080v4si __builtin_ia32_vpshld (v4si, v4si);
23081v2di __builtin_ia32_vpshlq (v2di, v2di);
23082v8hi __builtin_ia32_vpshlw (v8hi, v8hi);
23083@end smallexample
23084
23085The following built-in functions are available when @option{-mfma4} is used.
23086All of them generate the machine instruction that is part of the name.
23087
23088@smallexample
23089v2df __builtin_ia32_vfmaddpd (v2df, v2df, v2df);
23090v4sf __builtin_ia32_vfmaddps (v4sf, v4sf, v4sf);
23091v2df __builtin_ia32_vfmaddsd (v2df, v2df, v2df);
23092v4sf __builtin_ia32_vfmaddss (v4sf, v4sf, v4sf);
23093v2df __builtin_ia32_vfmsubpd (v2df, v2df, v2df);
23094v4sf __builtin_ia32_vfmsubps (v4sf, v4sf, v4sf);
23095v2df __builtin_ia32_vfmsubsd (v2df, v2df, v2df);
23096v4sf __builtin_ia32_vfmsubss (v4sf, v4sf, v4sf);
23097v2df __builtin_ia32_vfnmaddpd (v2df, v2df, v2df);
23098v4sf __builtin_ia32_vfnmaddps (v4sf, v4sf, v4sf);
23099v2df __builtin_ia32_vfnmaddsd (v2df, v2df, v2df);
23100v4sf __builtin_ia32_vfnmaddss (v4sf, v4sf, v4sf);
23101v2df __builtin_ia32_vfnmsubpd (v2df, v2df, v2df);
23102v4sf __builtin_ia32_vfnmsubps (v4sf, v4sf, v4sf);
23103v2df __builtin_ia32_vfnmsubsd (v2df, v2df, v2df);
23104v4sf __builtin_ia32_vfnmsubss (v4sf, v4sf, v4sf);
23105v2df __builtin_ia32_vfmaddsubpd (v2df, v2df, v2df);
23106v4sf __builtin_ia32_vfmaddsubps (v4sf, v4sf, v4sf);
23107v2df __builtin_ia32_vfmsubaddpd (v2df, v2df, v2df);
23108v4sf __builtin_ia32_vfmsubaddps (v4sf, v4sf, v4sf);
23109v4df __builtin_ia32_vfmaddpd256 (v4df, v4df, v4df);
23110v8sf __builtin_ia32_vfmaddps256 (v8sf, v8sf, v8sf);
23111v4df __builtin_ia32_vfmsubpd256 (v4df, v4df, v4df);
23112v8sf __builtin_ia32_vfmsubps256 (v8sf, v8sf, v8sf);
23113v4df __builtin_ia32_vfnmaddpd256 (v4df, v4df, v4df);
23114v8sf __builtin_ia32_vfnmaddps256 (v8sf, v8sf, v8sf);
23115v4df __builtin_ia32_vfnmsubpd256 (v4df, v4df, v4df);
23116v8sf __builtin_ia32_vfnmsubps256 (v8sf, v8sf, v8sf);
23117v4df __builtin_ia32_vfmaddsubpd256 (v4df, v4df, v4df);
23118v8sf __builtin_ia32_vfmaddsubps256 (v8sf, v8sf, v8sf);
23119v4df __builtin_ia32_vfmsubaddpd256 (v4df, v4df, v4df);
23120v8sf __builtin_ia32_vfmsubaddps256 (v8sf, v8sf, v8sf);
23121
23122@end smallexample
23123
23124The following built-in functions are available when @option{-mlwp} is used.
23125
23126@smallexample
23127void __builtin_ia32_llwpcb16 (void *);
23128void __builtin_ia32_llwpcb32 (void *);
23129void __builtin_ia32_llwpcb64 (void *);
23130void * __builtin_ia32_llwpcb16 (void);
23131void * __builtin_ia32_llwpcb32 (void);
23132void * __builtin_ia32_llwpcb64 (void);
23133void __builtin_ia32_lwpval16 (unsigned short, unsigned int, unsigned short);
23134void __builtin_ia32_lwpval32 (unsigned int, unsigned int, unsigned int);
23135void __builtin_ia32_lwpval64 (unsigned __int64, unsigned int, unsigned int);
23136unsigned char __builtin_ia32_lwpins16 (unsigned short, unsigned int, unsigned short);
23137unsigned char __builtin_ia32_lwpins32 (unsigned int, unsigned int, unsigned int);
23138unsigned char __builtin_ia32_lwpins64 (unsigned __int64, unsigned int, unsigned int);
23139@end smallexample
23140
23141The following built-in functions are available when @option{-mbmi} is used.
23142All of them generate the machine instruction that is part of the name.
23143@smallexample
23144unsigned int __builtin_ia32_bextr_u32(unsigned int, unsigned int);
23145unsigned long long __builtin_ia32_bextr_u64 (unsigned long long, unsigned long long);
23146@end smallexample
23147
23148The following built-in functions are available when @option{-mbmi2} is used.
23149All of them generate the machine instruction that is part of the name.
23150@smallexample
23151unsigned int _bzhi_u32 (unsigned int, unsigned int);
23152unsigned int _pdep_u32 (unsigned int, unsigned int);
23153unsigned int _pext_u32 (unsigned int, unsigned int);
23154unsigned long long _bzhi_u64 (unsigned long long, unsigned long long);
23155unsigned long long _pdep_u64 (unsigned long long, unsigned long long);
23156unsigned long long _pext_u64 (unsigned long long, unsigned long long);
23157@end smallexample
23158
23159The following built-in functions are available when @option{-mlzcnt} is used.
23160All of them generate the machine instruction that is part of the name.
23161@smallexample
23162unsigned short __builtin_ia32_lzcnt_u16(unsigned short);
23163unsigned int __builtin_ia32_lzcnt_u32(unsigned int);
23164unsigned long long __builtin_ia32_lzcnt_u64 (unsigned long long);
23165@end smallexample
23166
23167The following built-in functions are available when @option{-mfxsr} is used.
23168All of them generate the machine instruction that is part of the name.
23169@smallexample
23170void __builtin_ia32_fxsave (void *);
23171void __builtin_ia32_fxrstor (void *);
23172void __builtin_ia32_fxsave64 (void *);
23173void __builtin_ia32_fxrstor64 (void *);
23174@end smallexample
23175
23176The following built-in functions are available when @option{-mxsave} is used.
23177All of them generate the machine instruction that is part of the name.
23178@smallexample
23179void __builtin_ia32_xsave (void *, long long);
23180void __builtin_ia32_xrstor (void *, long long);
23181void __builtin_ia32_xsave64 (void *, long long);
23182void __builtin_ia32_xrstor64 (void *, long long);
23183@end smallexample
23184
23185The following built-in functions are available when @option{-mxsaveopt} is used.
23186All of them generate the machine instruction that is part of the name.
23187@smallexample
23188void __builtin_ia32_xsaveopt (void *, long long);
23189void __builtin_ia32_xsaveopt64 (void *, long long);
23190@end smallexample
23191
23192The following built-in functions are available when @option{-mtbm} is used.
23193Both of them generate the immediate form of the bextr machine instruction.
23194@smallexample
23195unsigned int __builtin_ia32_bextri_u32 (unsigned int,
23196 const unsigned int);
23197unsigned long long __builtin_ia32_bextri_u64 (unsigned long long,
23198 const unsigned long long);
23199@end smallexample
23200
23201
23202The following built-in functions are available when @option{-m3dnow} is used.
23203All of them generate the machine instruction that is part of the name.
23204
23205@smallexample
23206void __builtin_ia32_femms (void);
23207v8qi __builtin_ia32_pavgusb (v8qi, v8qi);
23208v2si __builtin_ia32_pf2id (v2sf);
23209v2sf __builtin_ia32_pfacc (v2sf, v2sf);
23210v2sf __builtin_ia32_pfadd (v2sf, v2sf);
23211v2si __builtin_ia32_pfcmpeq (v2sf, v2sf);
23212v2si __builtin_ia32_pfcmpge (v2sf, v2sf);
23213v2si __builtin_ia32_pfcmpgt (v2sf, v2sf);
23214v2sf __builtin_ia32_pfmax (v2sf, v2sf);
23215v2sf __builtin_ia32_pfmin (v2sf, v2sf);
23216v2sf __builtin_ia32_pfmul (v2sf, v2sf);
23217v2sf __builtin_ia32_pfrcp (v2sf);
23218v2sf __builtin_ia32_pfrcpit1 (v2sf, v2sf);
23219v2sf __builtin_ia32_pfrcpit2 (v2sf, v2sf);
23220v2sf __builtin_ia32_pfrsqrt (v2sf);
23221v2sf __builtin_ia32_pfsub (v2sf, v2sf);
23222v2sf __builtin_ia32_pfsubr (v2sf, v2sf);
23223v2sf __builtin_ia32_pi2fd (v2si);
23224v4hi __builtin_ia32_pmulhrw (v4hi, v4hi);
23225@end smallexample
23226
23227The following built-in functions are available when @option{-m3dnowa} is used.
23228All of them generate the machine instruction that is part of the name.
23229
23230@smallexample
23231v2si __builtin_ia32_pf2iw (v2sf);
23232v2sf __builtin_ia32_pfnacc (v2sf, v2sf);
23233v2sf __builtin_ia32_pfpnacc (v2sf, v2sf);
23234v2sf __builtin_ia32_pi2fw (v2si);
23235v2sf __builtin_ia32_pswapdsf (v2sf);
23236v2si __builtin_ia32_pswapdsi (v2si);
23237@end smallexample
23238
23239The following built-in functions are available when @option{-mrtm} is used
23240They are used for restricted transactional memory. These are the internal
23241low level functions. Normally the functions in
23242@ref{x86 transactional memory intrinsics} should be used instead.
23243
23244@smallexample
23245int __builtin_ia32_xbegin ();
23246void __builtin_ia32_xend ();
23247void __builtin_ia32_xabort (status);
23248int __builtin_ia32_xtest ();
23249@end smallexample
23250
23251The following built-in functions are available when @option{-mmwaitx} is used.
23252All of them generate the machine instruction that is part of the name.
23253@smallexample
23254void __builtin_ia32_monitorx (void *, unsigned int, unsigned int);
23255void __builtin_ia32_mwaitx (unsigned int, unsigned int, unsigned int);
23256@end smallexample
23257
23258The following built-in functions are available when @option{-mclzero} is used.
23259All of them generate the machine instruction that is part of the name.
23260@smallexample
23261void __builtin_i32_clzero (void *);
23262@end smallexample
23263
23264The following built-in functions are available when @option{-mpku} is used.
23265They generate reads and writes to PKRU.
23266@smallexample
23267void __builtin_ia32_wrpkru (unsigned int);
23268unsigned int __builtin_ia32_rdpkru ();
23269@end smallexample
23270
23271The following built-in functions are available when
23272@option{-mshstk} option is used. They support shadow stack
23273machine instructions from Intel Control-flow Enforcement Technology (CET).
23274Each built-in function generates the machine instruction that is part
23275of the function's name. These are the internal low-level functions.
23276Normally the functions in @ref{x86 control-flow protection intrinsics}
23277should be used instead.
23278
23279@smallexample
23280unsigned int __builtin_ia32_rdsspd (void);
23281unsigned long long __builtin_ia32_rdsspq (void);
23282void __builtin_ia32_incsspd (unsigned int);
23283void __builtin_ia32_incsspq (unsigned long long);
23284void __builtin_ia32_saveprevssp(void);
23285void __builtin_ia32_rstorssp(void *);
23286void __builtin_ia32_wrssd(unsigned int, void *);
23287void __builtin_ia32_wrssq(unsigned long long, void *);
23288void __builtin_ia32_wrussd(unsigned int, void *);
23289void __builtin_ia32_wrussq(unsigned long long, void *);
23290void __builtin_ia32_setssbsy(void);
23291void __builtin_ia32_clrssbsy(void *);
23292@end smallexample
23293
23294@node x86 transactional memory intrinsics
23295@subsection x86 Transactional Memory Intrinsics
23296
23297These hardware transactional memory intrinsics for x86 allow you to use
23298memory transactions with RTM (Restricted Transactional Memory).
23299This support is enabled with the @option{-mrtm} option.
23300For using HLE (Hardware Lock Elision) see
23301@ref{x86 specific memory model extensions for transactional memory} instead.
23302
23303A memory transaction commits all changes to memory in an atomic way,
23304as visible to other threads. If the transaction fails it is rolled back
23305and all side effects discarded.
23306
23307Generally there is no guarantee that a memory transaction ever succeeds
23308and suitable fallback code always needs to be supplied.
23309
23310@deftypefn {RTM Function} {unsigned} _xbegin ()
23311Start a RTM (Restricted Transactional Memory) transaction.
23312Returns @code{_XBEGIN_STARTED} when the transaction
23313started successfully (note this is not 0, so the constant has to be
23314explicitly tested).
23315
23316If the transaction aborts, all side effects
23317are undone and an abort code encoded as a bit mask is returned.
23318The following macros are defined:
23319
f25efe50 23320@defmac{_XABORT_EXPLICIT}
d77de738
ML
23321Transaction was explicitly aborted with @code{_xabort}. The parameter passed
23322to @code{_xabort} is available with @code{_XABORT_CODE(status)}.
f25efe50
AA
23323@end defmac
23324
23325@defmac{_XABORT_RETRY}
d77de738 23326Transaction retry is possible.
f25efe50
AA
23327@end defmac
23328
23329@defmac{_XABORT_CONFLICT}
d77de738 23330Transaction abort due to a memory conflict with another thread.
f25efe50
AA
23331@end defmac
23332
23333@defmac{_XABORT_CAPACITY}
d77de738 23334Transaction abort due to the transaction using too much memory.
f25efe50
AA
23335@end defmac
23336
23337@defmac{_XABORT_DEBUG}
d77de738 23338Transaction abort due to a debug trap.
f25efe50
AA
23339@end defmac
23340
23341@defmac{_XABORT_NESTED}
d77de738 23342Transaction abort in an inner nested transaction.
f25efe50 23343@end defmac
d77de738
ML
23344
23345There is no guarantee
23346any transaction ever succeeds, so there always needs to be a valid
23347fallback path.
23348@end deftypefn
23349
23350@deftypefn {RTM Function} {void} _xend ()
23351Commit the current transaction. When no transaction is active this faults.
23352All memory side effects of the transaction become visible
23353to other threads in an atomic manner.
23354@end deftypefn
23355
23356@deftypefn {RTM Function} {int} _xtest ()
23357Return a nonzero value if a transaction is currently active, otherwise 0.
23358@end deftypefn
23359
23360@deftypefn {RTM Function} {void} _xabort (status)
23361Abort the current transaction. When no transaction is active this is a no-op.
23362The @var{status} is an 8-bit constant; its value is encoded in the return
23363value from @code{_xbegin}.
23364@end deftypefn
23365
23366Here is an example showing handling for @code{_XABORT_RETRY}
23367and a fallback path for other failures:
23368
23369@smallexample
23370#include <immintrin.h>
23371
23372int n_tries, max_tries;
23373unsigned status = _XABORT_EXPLICIT;
23374...
23375
23376for (n_tries = 0; n_tries < max_tries; n_tries++)
23377 @{
23378 status = _xbegin ();
23379 if (status == _XBEGIN_STARTED || !(status & _XABORT_RETRY))
23380 break;
23381 @}
23382if (status == _XBEGIN_STARTED)
23383 @{
23384 ... transaction code...
23385 _xend ();
23386 @}
23387else
23388 @{
23389 ... non-transactional fallback path...
23390 @}
23391@end smallexample
23392
23393@noindent
23394Note that, in most cases, the transactional and non-transactional code
23395must synchronize together to ensure consistency.
23396
23397@node x86 control-flow protection intrinsics
23398@subsection x86 Control-Flow Protection Intrinsics
23399
23400@deftypefn {CET Function} {ret_type} _get_ssp (void)
23401Get the current value of shadow stack pointer if shadow stack support
23402from Intel CET is enabled in the hardware or @code{0} otherwise.
23403The @code{ret_type} is @code{unsigned long long} for 64-bit targets
23404and @code{unsigned int} for 32-bit targets.
23405@end deftypefn
23406
23407@deftypefn {CET Function} void _inc_ssp (unsigned int)
23408Increment the current shadow stack pointer by the size specified by the
23409function argument. The argument is masked to a byte value for security
23410reasons, so to increment by more than 255 bytes you must call the function
23411multiple times.
23412@end deftypefn
23413
23414The shadow stack unwind code looks like:
23415
23416@smallexample
23417#include <immintrin.h>
23418
23419/* Unwind the shadow stack for EH. */
23420#define _Unwind_Frames_Extra(x) \
23421 do \
23422 @{ \
23423 _Unwind_Word ssp = _get_ssp (); \
23424 if (ssp != 0) \
23425 @{ \
23426 _Unwind_Word tmp = (x); \
23427 while (tmp > 255) \
23428 @{ \
23429 _inc_ssp (tmp); \
23430 tmp -= 255; \
23431 @} \
23432 _inc_ssp (tmp); \
23433 @} \
23434 @} \
23435 while (0)
23436@end smallexample
23437
23438@noindent
23439This code runs unconditionally on all 64-bit processors. For 32-bit
23440processors the code runs on those that support multi-byte NOP instructions.
23441
23442@node Target Format Checks
23443@section Format Checks Specific to Particular Target Machines
23444
23445For some target machines, GCC supports additional options to the
23446format attribute
23447(@pxref{Function Attributes,,Declaring Attributes of Functions}).
23448
23449@menu
23450* Solaris Format Checks::
23451* Darwin Format Checks::
23452@end menu
23453
23454@node Solaris Format Checks
23455@subsection Solaris Format Checks
23456
23457Solaris targets support the @code{cmn_err} (or @code{__cmn_err__}) format
23458check. @code{cmn_err} accepts a subset of the standard @code{printf}
23459conversions, and the two-argument @code{%b} conversion for displaying
23460bit-fields. See the Solaris man page for @code{cmn_err} for more information.
23461
23462@node Darwin Format Checks
23463@subsection Darwin Format Checks
23464
23465In addition to the full set of format archetypes (attribute format style
23466arguments such as @code{printf}, @code{scanf}, @code{strftime}, and
23467@code{strfmon}), Darwin targets also support the @code{CFString} (or
23468@code{__CFString__}) archetype in the @code{format} attribute.
23469Declarations with this archetype are parsed for correct syntax
23470and argument types. However, parsing of the format string itself and
23471validating arguments against it in calls to such functions is currently
23472not performed.
23473
23474Additionally, @code{CFStringRefs} (defined by the @code{CoreFoundation} headers) may
23475also be used as format arguments. Note that the relevant headers are only likely to be
23476available on Darwin (OSX) installations. On such installations, the XCode and system
23477documentation provide descriptions of @code{CFString}, @code{CFStringRefs} and
23478associated functions.
23479
23480@node Pragmas
23481@section Pragmas Accepted by GCC
23482@cindex pragmas
23483@cindex @code{#pragma}
23484
23485GCC supports several types of pragmas, primarily in order to compile
23486code originally written for other compilers. Note that in general
23487we do not recommend the use of pragmas; @xref{Function Attributes},
23488for further explanation.
23489
23490The GNU C preprocessor recognizes several pragmas in addition to the
23491compiler pragmas documented here. Refer to the CPP manual for more
23492information.
23493
23494@menu
23495* AArch64 Pragmas::
23496* ARM Pragmas::
23497* M32C Pragmas::
d77de738
ML
23498* PRU Pragmas::
23499* RS/6000 and PowerPC Pragmas::
23500* S/390 Pragmas::
23501* Darwin Pragmas::
23502* Solaris Pragmas::
23503* Symbol-Renaming Pragmas::
23504* Structure-Layout Pragmas::
23505* Weak Pragmas::
23506* Diagnostic Pragmas::
23507* Visibility Pragmas::
23508* Push/Pop Macro Pragmas::
23509* Function Specific Option Pragmas::
23510* Loop-Specific Pragmas::
23511@end menu
23512
23513@node AArch64 Pragmas
23514@subsection AArch64 Pragmas
23515
23516The pragmas defined by the AArch64 target correspond to the AArch64
23517target function attributes. They can be specified as below:
23518@smallexample
23519#pragma GCC target("string")
23520@end smallexample
23521
23522where @code{@var{string}} can be any string accepted as an AArch64 target
23523attribute. @xref{AArch64 Function Attributes}, for more details
23524on the permissible values of @code{string}.
23525
23526@node ARM Pragmas
23527@subsection ARM Pragmas
23528
23529The ARM target defines pragmas for controlling the default addition of
23530@code{long_call} and @code{short_call} attributes to functions.
23531@xref{Function Attributes}, for information about the effects of these
23532attributes.
23533
23534@table @code
d77de738 23535@cindex pragma, long_calls
f25efe50 23536@item long_calls
d77de738
ML
23537Set all subsequent functions to have the @code{long_call} attribute.
23538
d77de738 23539@cindex pragma, no_long_calls
f25efe50 23540@item no_long_calls
d77de738
ML
23541Set all subsequent functions to have the @code{short_call} attribute.
23542
d77de738 23543@cindex pragma, long_calls_off
f25efe50 23544@item long_calls_off
d77de738
ML
23545Do not affect the @code{long_call} or @code{short_call} attributes of
23546subsequent functions.
23547@end table
23548
23549@node M32C Pragmas
23550@subsection M32C Pragmas
23551
23552@table @code
d77de738 23553@cindex pragma, memregs
f25efe50 23554@item GCC memregs @var{number}
d77de738
ML
23555Overrides the command-line option @code{-memregs=} for the current
23556file. Use with care! This pragma must be before any function in the
23557file, and mixing different memregs values in different objects may
23558make them incompatible. This pragma is useful when a
23559performance-critical function uses a memreg for temporary values,
23560as it may allow you to reduce the number of memregs used.
23561
d77de738 23562@cindex pragma, address
f25efe50 23563@item ADDRESS @var{name} @var{address}
d77de738
ML
23564For any declared symbols matching @var{name}, this does three things
23565to that symbol: it forces the symbol to be located at the given
23566address (a number), it forces the symbol to be volatile, and it
23567changes the symbol's scope to be static. This pragma exists for
23568compatibility with other compilers, but note that the common
23569@code{1234H} numeric syntax is not supported (use @code{0x1234}
23570instead). Example:
23571
23572@smallexample
23573#pragma ADDRESS port3 0x103
23574char port3;
23575@end smallexample
23576
23577@end table
23578
d77de738
ML
23579@node PRU Pragmas
23580@subsection PRU Pragmas
23581
23582@table @code
23583
d77de738 23584@cindex pragma, ctable_entry
f25efe50 23585@item ctable_entry @var{index} @var{constant_address}
d77de738
ML
23586Specifies that the PRU CTABLE entry given by @var{index} has the value
23587@var{constant_address}. This enables GCC to emit LBCO/SBCO instructions
23588when the load/store address is known and can be addressed with some CTABLE
23589entry. For example:
23590
23591@smallexample
23592/* will compile to "sbco Rx, 2, 0x10, 4" */
23593#pragma ctable_entry 2 0x4802a000
23594*(unsigned int *)0x4802a010 = val;
23595@end smallexample
23596
23597@end table
23598
23599@node RS/6000 and PowerPC Pragmas
23600@subsection RS/6000 and PowerPC Pragmas
23601
23602The RS/6000 and PowerPC targets define one pragma for controlling
23603whether or not the @code{longcall} attribute is added to function
23604declarations by default. This pragma overrides the @option{-mlongcall}
23605option, but not the @code{longcall} and @code{shortcall} attributes.
23606@xref{RS/6000 and PowerPC Options}, for more information about when long
23607calls are and are not necessary.
23608
23609@table @code
d77de738 23610@cindex pragma, longcall
f25efe50 23611@item longcall (1)
d77de738
ML
23612Apply the @code{longcall} attribute to all subsequent function
23613declarations.
23614
23615@item longcall (0)
23616Do not apply the @code{longcall} attribute to subsequent function
23617declarations.
23618@end table
23619
23620@c Describe h8300 pragmas here.
23621@c Describe sh pragmas here.
23622@c Describe v850 pragmas here.
23623
23624@node S/390 Pragmas
23625@subsection S/390 Pragmas
23626
23627The pragmas defined by the S/390 target correspond to the S/390
23628target function attributes and some the additional options:
23629
23630@table @samp
23631@item zvector
23632@itemx no-zvector
23633@end table
23634
23635Note that options of the pragma, unlike options of the target
23636attribute, do change the value of preprocessor macros like
23637@code{__VEC__}. They can be specified as below:
23638
23639@smallexample
23640#pragma GCC target("string[,string]...")
23641#pragma GCC target("string"[,"string"]...)
23642@end smallexample
23643
23644@node Darwin Pragmas
23645@subsection Darwin Pragmas
23646
23647The following pragmas are available for all architectures running the
23648Darwin operating system. These are useful for compatibility with other
23649Mac OS compilers.
23650
23651@table @code
d77de738 23652@cindex pragma, mark
f25efe50 23653@item mark @var{tokens}@dots{}
d77de738
ML
23654This pragma is accepted, but has no effect.
23655
d77de738 23656@cindex pragma, options align
f25efe50 23657@item options align=@var{alignment}
d77de738
ML
23658This pragma sets the alignment of fields in structures. The values of
23659@var{alignment} may be @code{mac68k}, to emulate m68k alignment, or
23660@code{power}, to emulate PowerPC alignment. Uses of this pragma nest
23661properly; to restore the previous setting, use @code{reset} for the
23662@var{alignment}.
23663
d77de738 23664@cindex pragma, segment
f25efe50 23665@item segment @var{tokens}@dots{}
d77de738
ML
23666This pragma is accepted, but has no effect.
23667
d77de738 23668@cindex pragma, unused
f25efe50 23669@item unused (@var{var} [, @var{var}]@dots{})
d77de738
ML
23670This pragma declares variables to be possibly unused. GCC does not
23671produce warnings for the listed variables. The effect is similar to
23672that of the @code{unused} attribute, except that this pragma may appear
23673anywhere within the variables' scopes.
23674@end table
23675
23676@node Solaris Pragmas
23677@subsection Solaris Pragmas
23678
23679The Solaris target supports @code{#pragma redefine_extname}
23680(@pxref{Symbol-Renaming Pragmas}). It also supports additional
23681@code{#pragma} directives for compatibility with the system compiler.
23682
23683@table @code
d77de738 23684@cindex pragma, align
f25efe50 23685@item align @var{alignment} (@var{variable} [, @var{variable}]...)
d77de738
ML
23686
23687Increase the minimum alignment of each @var{variable} to @var{alignment}.
23688This is the same as GCC's @code{aligned} attribute @pxref{Variable
23689Attributes}). Macro expansion occurs on the arguments to this pragma
23690when compiling C and Objective-C@. It does not currently occur when
23691compiling C++, but this is a bug which may be fixed in a future
23692release.
23693
d77de738 23694@cindex pragma, fini
f25efe50 23695@item fini (@var{function} [, @var{function}]...)
d77de738
ML
23696
23697This pragma causes each listed @var{function} to be called after
23698main, or during shared module unloading, by adding a call to the
23699@code{.fini} section.
23700
d77de738 23701@cindex pragma, init
f25efe50 23702@item init (@var{function} [, @var{function}]...)
d77de738
ML
23703
23704This pragma causes each listed @var{function} to be called during
23705initialization (before @code{main}) or during shared module loading, by
23706adding a call to the @code{.init} section.
23707
23708@end table
23709
23710@node Symbol-Renaming Pragmas
23711@subsection Symbol-Renaming Pragmas
23712
23713GCC supports a @code{#pragma} directive that changes the name used in
23714assembly for a given declaration. While this pragma is supported on all
23715platforms, it is intended primarily to provide compatibility with the
23716Solaris system headers. This effect can also be achieved using the asm
23717labels extension (@pxref{Asm Labels}).
23718
23719@table @code
d77de738 23720@cindex pragma, redefine_extname
f25efe50 23721@item redefine_extname @var{oldname} @var{newname}
d77de738
ML
23722
23723This pragma gives the C function @var{oldname} the assembly symbol
23724@var{newname}. The preprocessor macro @code{__PRAGMA_REDEFINE_EXTNAME}
23725is defined if this pragma is available (currently on all platforms).
23726@end table
23727
23728This pragma and the @code{asm} labels extension interact in a complicated
23729manner. Here are some corner cases you may want to be aware of:
23730
23731@enumerate
23732@item This pragma silently applies only to declarations with external
23733linkage. The @code{asm} label feature does not have this restriction.
23734
23735@item In C++, this pragma silently applies only to declarations with
23736``C'' linkage. Again, @code{asm} labels do not have this restriction.
23737
23738@item If either of the ways of changing the assembly name of a
23739declaration are applied to a declaration whose assembly name has
23740already been determined (either by a previous use of one of these
23741features, or because the compiler needed the assembly name in order to
23742generate code), and the new name is different, a warning issues and
23743the name does not change.
23744
23745@item The @var{oldname} used by @code{#pragma redefine_extname} is
23746always the C-language name.
23747@end enumerate
23748
23749@node Structure-Layout Pragmas
23750@subsection Structure-Layout Pragmas
23751
23752For compatibility with Microsoft Windows compilers, GCC supports a
23753set of @code{#pragma} directives that change the maximum alignment of
23754members of structures (other than zero-width bit-fields), unions, and
23755classes subsequently defined. The @var{n} value below always is required
23756to be a small power of two and specifies the new alignment in bytes.
23757
23758@enumerate
23759@item @code{#pragma pack(@var{n})} simply sets the new alignment.
23760@item @code{#pragma pack()} sets the alignment to the one that was in
23761effect when compilation started (see also command-line option
23762@option{-fpack-struct[=@var{n}]} @pxref{Code Gen Options}).
23763@item @code{#pragma pack(push[,@var{n}])} pushes the current alignment
23764setting on an internal stack and then optionally sets the new alignment.
23765@item @code{#pragma pack(pop)} restores the alignment setting to the one
23766saved at the top of the internal stack (and removes that stack entry).
23767Note that @code{#pragma pack([@var{n}])} does not influence this internal
23768stack; thus it is possible to have @code{#pragma pack(push)} followed by
23769multiple @code{#pragma pack(@var{n})} instances and finalized by a single
23770@code{#pragma pack(pop)}.
23771@end enumerate
23772
23773Some targets, e.g.@: x86 and PowerPC, support the @code{#pragma ms_struct}
23774directive which lays out structures and unions subsequently defined as the
23775documented @code{__attribute__ ((ms_struct))}.
23776
23777@enumerate
23778@item @code{#pragma ms_struct on} turns on the Microsoft layout.
23779@item @code{#pragma ms_struct off} turns off the Microsoft layout.
23780@item @code{#pragma ms_struct reset} goes back to the default layout.
23781@end enumerate
23782
23783Most targets also support the @code{#pragma scalar_storage_order} directive
23784which lays out structures and unions subsequently defined as the documented
23785@code{__attribute__ ((scalar_storage_order))}.
23786
23787@enumerate
23788@item @code{#pragma scalar_storage_order big-endian} sets the storage order
23789of the scalar fields to big-endian.
23790@item @code{#pragma scalar_storage_order little-endian} sets the storage order
23791of the scalar fields to little-endian.
23792@item @code{#pragma scalar_storage_order default} goes back to the endianness
23793that was in effect when compilation started (see also command-line option
23794@option{-fsso-struct=@var{endianness}} @pxref{C Dialect Options}).
23795@end enumerate
23796
23797@node Weak Pragmas
23798@subsection Weak Pragmas
23799
23800For compatibility with SVR4, GCC supports a set of @code{#pragma}
23801directives for declaring symbols to be weak, and defining weak
23802aliases.
23803
23804@table @code
d77de738 23805@cindex pragma, weak
f33d7a88 23806@item #pragma weak @var{symbol}
d77de738
ML
23807This pragma declares @var{symbol} to be weak, as if the declaration
23808had the attribute of the same name. The pragma may appear before
23809or after the declaration of @var{symbol}. It is not an error for
23810@var{symbol} to never be defined at all.
23811
23812@item #pragma weak @var{symbol1} = @var{symbol2}
23813This pragma declares @var{symbol1} to be a weak alias of @var{symbol2}.
23814It is an error if @var{symbol2} is not defined in the current
23815translation unit.
23816@end table
23817
23818@node Diagnostic Pragmas
23819@subsection Diagnostic Pragmas
23820
23821GCC allows the user to selectively enable or disable certain types of
23822diagnostics, and change the kind of the diagnostic. For example, a
23823project's policy might require that all sources compile with
23824@option{-Werror} but certain files might have exceptions allowing
23825specific types of warnings. Or, a project might selectively enable
23826diagnostics and treat them as errors depending on which preprocessor
23827macros are defined.
23828
23829@table @code
d77de738 23830@cindex pragma, diagnostic
f25efe50 23831@item #pragma GCC diagnostic @var{kind} @var{option}
d77de738
ML
23832
23833Modifies the disposition of a diagnostic. Note that not all
23834diagnostics are modifiable; at the moment only warnings (normally
23835controlled by @samp{-W@dots{}}) can be controlled, and not all of them.
23836Use @option{-fdiagnostics-show-option} to determine which diagnostics
23837are controllable and which option controls them.
23838
23839@var{kind} is @samp{error} to treat this diagnostic as an error,
23840@samp{warning} to treat it like a warning (even if @option{-Werror} is
23841in effect), or @samp{ignored} if the diagnostic is to be ignored.
23842@var{option} is a double quoted string that matches the command-line
23843option.
23844
23845@smallexample
23846#pragma GCC diagnostic warning "-Wformat"
23847#pragma GCC diagnostic error "-Wformat"
23848#pragma GCC diagnostic ignored "-Wformat"
23849@end smallexample
23850
23851Note that these pragmas override any command-line options. GCC keeps
23852track of the location of each pragma, and issues diagnostics according
23853to the state as of that point in the source file. Thus, pragmas occurring
23854after a line do not affect diagnostics caused by that line.
23855
23856@item #pragma GCC diagnostic push
23857@itemx #pragma GCC diagnostic pop
23858
23859Causes GCC to remember the state of the diagnostics as of each
23860@code{push}, and restore to that point at each @code{pop}. If a
23861@code{pop} has no matching @code{push}, the command-line options are
23862restored.
23863
23864@smallexample
23865#pragma GCC diagnostic error "-Wuninitialized"
23866 foo(a); /* error is given for this one */
23867#pragma GCC diagnostic push
23868#pragma GCC diagnostic ignored "-Wuninitialized"
23869 foo(b); /* no diagnostic for this one */
23870#pragma GCC diagnostic pop
23871 foo(c); /* error is given for this one */
23872#pragma GCC diagnostic pop
23873 foo(d); /* depends on command-line options */
23874@end smallexample
23875
23876@item #pragma GCC diagnostic ignored_attributes
23877
23878Similarly to @option{-Wno-attributes=}, this pragma allows users to suppress
23879warnings about unknown scoped attributes (in C++11 and C2X). For example,
23880@code{#pragma GCC diagnostic ignored_attributes "vendor::attr"} disables
23881warning about the following declaration:
23882
23883@smallexample
23884[[vendor::attr]] void f();
23885@end smallexample
23886
23887whereas @code{#pragma GCC diagnostic ignored_attributes "vendor::"} prevents
23888warning about both of these declarations:
23889
23890@smallexample
23891[[vendor::safe]] void f();
23892[[vendor::unsafe]] void f2();
23893@end smallexample
23894
23895@end table
23896
23897GCC also offers a simple mechanism for printing messages during
23898compilation.
23899
23900@table @code
d77de738 23901@cindex pragma, diagnostic
f25efe50 23902@item #pragma message @var{string}
d77de738
ML
23903
23904Prints @var{string} as a compiler message on compilation. The message
23905is informational only, and is neither a compilation warning nor an
23906error. Newlines can be included in the string by using the @samp{\n}
23907escape sequence.
23908
23909@smallexample
23910#pragma message "Compiling " __FILE__ "..."
23911@end smallexample
23912
23913@var{string} may be parenthesized, and is printed with location
23914information. For example,
23915
23916@smallexample
23917#define DO_PRAGMA(x) _Pragma (#x)
23918#define TODO(x) DO_PRAGMA(message ("TODO - " #x))
23919
23920TODO(Remember to fix this)
23921@end smallexample
23922
23923@noindent
23924prints @samp{/tmp/file.c:4: note: #pragma message:
23925TODO - Remember to fix this}.
23926
d77de738 23927@cindex pragma, diagnostic
f25efe50 23928@item #pragma GCC error @var{message}
d77de738
ML
23929Generates an error message. This pragma @emph{is} considered to
23930indicate an error in the compilation, and it will be treated as such.
23931
23932Newlines can be included in the string by using the @samp{\n}
23933escape sequence. They will be displayed as newlines even if the
23934@option{-fmessage-length} option is set to zero.
23935
23936The error is only generated if the pragma is present in the code after
23937pre-processing has been completed. It does not matter however if the
23938code containing the pragma is unreachable:
23939
23940@smallexample
23941#if 0
23942#pragma GCC error "this error is not seen"
23943#endif
23944void foo (void)
23945@{
23946 return;
23947#pragma GCC error "this error is seen"
23948@}
23949@end smallexample
23950
d77de738 23951@cindex pragma, diagnostic
f25efe50 23952@item #pragma GCC warning @var{message}
d77de738
ML
23953This is just like @samp{pragma GCC error} except that a warning
23954message is issued instead of an error message. Unless
23955@option{-Werror} is in effect, in which case this pragma will generate
23956an error as well.
23957
23958@end table
23959
23960@node Visibility Pragmas
23961@subsection Visibility Pragmas
23962
23963@table @code
f25efe50 23964@cindex pragma, visibility
d77de738
ML
23965@item #pragma GCC visibility push(@var{visibility})
23966@itemx #pragma GCC visibility pop
d77de738
ML
23967
23968This pragma allows the user to set the visibility for multiple
23969declarations without having to give each a visibility attribute
23970(@pxref{Function Attributes}).
23971
23972In C++, @samp{#pragma GCC visibility} affects only namespace-scope
23973declarations. Class members and template specializations are not
23974affected; if you want to override the visibility for a particular
23975member or instantiation, you must use an attribute.
23976
23977@end table
23978
23979
23980@node Push/Pop Macro Pragmas
23981@subsection Push/Pop Macro Pragmas
23982
23983For compatibility with Microsoft Windows compilers, GCC supports
23984@samp{#pragma push_macro(@var{"macro_name"})}
23985and @samp{#pragma pop_macro(@var{"macro_name"})}.
23986
23987@table @code
d77de738 23988@cindex pragma, push_macro
f25efe50 23989@item #pragma push_macro(@var{"macro_name"})
d77de738
ML
23990This pragma saves the value of the macro named as @var{macro_name} to
23991the top of the stack for this macro.
23992
d77de738 23993@cindex pragma, pop_macro
f25efe50 23994@item #pragma pop_macro(@var{"macro_name"})
d77de738
ML
23995This pragma sets the value of the macro named as @var{macro_name} to
23996the value on top of the stack for this macro. If the stack for
23997@var{macro_name} is empty, the value of the macro remains unchanged.
23998@end table
23999
24000For example:
24001
24002@smallexample
24003#define X 1
24004#pragma push_macro("X")
24005#undef X
24006#define X -1
24007#pragma pop_macro("X")
24008int x [X];
24009@end smallexample
24010
24011@noindent
24012In this example, the definition of X as 1 is saved by @code{#pragma
24013push_macro} and restored by @code{#pragma pop_macro}.
24014
24015@node Function Specific Option Pragmas
24016@subsection Function Specific Option Pragmas
24017
24018@table @code
d77de738 24019@cindex pragma GCC target
f25efe50 24020@item #pragma GCC target (@var{string}, @dots{})
d77de738
ML
24021
24022This pragma allows you to set target-specific options for functions
24023defined later in the source file. One or more strings can be
24024specified. Each function that is defined after this point is treated
24025as if it had been declared with one @code{target(}@var{string}@code{)}
24026attribute for each @var{string} argument. The parentheses around
24027the strings in the pragma are optional. @xref{Function Attributes},
24028for more information about the @code{target} attribute and the attribute
24029syntax.
24030
24031The @code{#pragma GCC target} pragma is presently implemented for
24032x86, ARM, AArch64, PowerPC, S/390, and Nios II targets only.
24033
d77de738 24034@cindex pragma GCC optimize
f25efe50 24035@item #pragma GCC optimize (@var{string}, @dots{})
d77de738
ML
24036
24037This pragma allows you to set global optimization options for functions
24038defined later in the source file. One or more strings can be
24039specified. Each function that is defined after this point is treated
24040as if it had been declared with one @code{optimize(}@var{string}@code{)}
24041attribute for each @var{string} argument. The parentheses around
24042the strings in the pragma are optional. @xref{Function Attributes},
24043for more information about the @code{optimize} attribute and the attribute
24044syntax.
24045
d77de738
ML
24046@cindex pragma GCC push_options
24047@cindex pragma GCC pop_options
f25efe50
AA
24048@item #pragma GCC push_options
24049@itemx #pragma GCC pop_options
d77de738
ML
24050
24051These pragmas maintain a stack of the current target and optimization
24052options. It is intended for include files where you temporarily want
24053to switch to using a different @samp{#pragma GCC target} or
24054@samp{#pragma GCC optimize} and then to pop back to the previous
24055options.
24056
d77de738 24057@cindex pragma GCC reset_options
f25efe50 24058@item #pragma GCC reset_options
d77de738
ML
24059
24060This pragma clears the current @code{#pragma GCC target} and
24061@code{#pragma GCC optimize} to use the default switches as specified
24062on the command line.
24063
24064@end table
24065
24066@node Loop-Specific Pragmas
24067@subsection Loop-Specific Pragmas
24068
24069@table @code
d77de738 24070@cindex pragma GCC ivdep
f25efe50 24071@item #pragma GCC ivdep
d77de738
ML
24072
24073With this pragma, the programmer asserts that there are no loop-carried
24074dependencies which would prevent consecutive iterations of
24075the following loop from executing concurrently with SIMD
24076(single instruction multiple data) instructions.
24077
24078For example, the compiler can only unconditionally vectorize the following
24079loop with the pragma:
24080
24081@smallexample
24082void foo (int n, int *a, int *b, int *c)
24083@{
24084 int i, j;
24085#pragma GCC ivdep
24086 for (i = 0; i < n; ++i)
24087 a[i] = b[i] + c[i];
24088@}
24089@end smallexample
24090
24091@noindent
24092In this example, using the @code{restrict} qualifier had the same
24093effect. In the following example, that would not be possible. Assume
24094@math{k < -m} or @math{k >= m}. Only with the pragma, the compiler knows
24095that it can unconditionally vectorize the following loop:
24096
24097@smallexample
24098void ignore_vec_dep (int *a, int k, int c, int m)
24099@{
24100#pragma GCC ivdep
24101 for (int i = 0; i < m; i++)
24102 a[i] = a[i + k] * c;
24103@}
24104@end smallexample
24105
d77de738 24106@cindex pragma GCC unroll @var{n}
f25efe50 24107@item #pragma GCC unroll @var{n}
d77de738
ML
24108
24109You can use this pragma to control how many times a loop should be unrolled.
24110It must be placed immediately before a @code{for}, @code{while} or @code{do}
24111loop or a @code{#pragma GCC ivdep}, and applies only to the loop that follows.
24112@var{n} is an integer constant expression specifying the unrolling factor.
24113The values of @math{0} and @math{1} block any unrolling of the loop.
24114
24115@end table
24116
24117@node Unnamed Fields
24118@section Unnamed Structure and Union Fields
24119@cindex @code{struct}
24120@cindex @code{union}
24121
24122As permitted by ISO C11 and for compatibility with other compilers,
24123GCC allows you to define
24124a structure or union that contains, as fields, structures and unions
24125without names. For example:
24126
24127@smallexample
24128struct @{
24129 int a;
24130 union @{
24131 int b;
24132 float c;
24133 @};
24134 int d;
24135@} foo;
24136@end smallexample
24137
24138@noindent
24139In this example, you are able to access members of the unnamed
24140union with code like @samp{foo.b}. Note that only unnamed structs and
24141unions are allowed, you may not have, for example, an unnamed
24142@code{int}.
24143
24144You must never create such structures that cause ambiguous field definitions.
24145For example, in this structure:
24146
24147@smallexample
24148struct @{
24149 int a;
24150 struct @{
24151 int a;
24152 @};
24153@} foo;
24154@end smallexample
24155
24156@noindent
24157it is ambiguous which @code{a} is being referred to with @samp{foo.a}.
24158The compiler gives errors for such constructs.
24159
24160@opindex fms-extensions
24161Unless @option{-fms-extensions} is used, the unnamed field must be a
24162structure or union definition without a tag (for example, @samp{struct
24163@{ int a; @};}). If @option{-fms-extensions} is used, the field may
24164also be a definition with a tag such as @samp{struct foo @{ int a;
24165@};}, a reference to a previously defined structure or union such as
24166@samp{struct foo;}, or a reference to a @code{typedef} name for a
24167previously defined structure or union type.
24168
24169@opindex fplan9-extensions
24170The option @option{-fplan9-extensions} enables
24171@option{-fms-extensions} as well as two other extensions. First, a
24172pointer to a structure is automatically converted to a pointer to an
24173anonymous field for assignments and function calls. For example:
24174
24175@smallexample
24176struct s1 @{ int a; @};
24177struct s2 @{ struct s1; @};
24178extern void f1 (struct s1 *);
24179void f2 (struct s2 *p) @{ f1 (p); @}
24180@end smallexample
24181
24182@noindent
24183In the call to @code{f1} inside @code{f2}, the pointer @code{p} is
24184converted into a pointer to the anonymous field.
24185
24186Second, when the type of an anonymous field is a @code{typedef} for a
24187@code{struct} or @code{union}, code may refer to the field using the
24188name of the @code{typedef}.
24189
24190@smallexample
24191typedef struct @{ int a; @} s1;
24192struct s2 @{ s1; @};
24193s1 f1 (struct s2 *p) @{ return p->s1; @}
24194@end smallexample
24195
24196These usages are only permitted when they are not ambiguous.
24197
24198@node Thread-Local
24199@section Thread-Local Storage
24200@cindex Thread-Local Storage
24201@cindex @acronym{TLS}
24202@cindex @code{__thread}
24203
24204Thread-local storage (@acronym{TLS}) is a mechanism by which variables
24205are allocated such that there is one instance of the variable per extant
24206thread. The runtime model GCC uses to implement this originates
24207in the IA-64 processor-specific ABI, but has since been migrated
24208to other processors as well. It requires significant support from
24209the linker (@command{ld}), dynamic linker (@command{ld.so}), and
24210system libraries (@file{libc.so} and @file{libpthread.so}), so it
24211is not available everywhere.
24212
24213At the user level, the extension is visible with a new storage
24214class keyword: @code{__thread}. For example:
24215
24216@smallexample
24217__thread int i;
24218extern __thread struct state s;
24219static __thread char *p;
24220@end smallexample
24221
24222The @code{__thread} specifier may be used alone, with the @code{extern}
24223or @code{static} specifiers, but with no other storage class specifier.
24224When used with @code{extern} or @code{static}, @code{__thread} must appear
24225immediately after the other storage class specifier.
24226
24227The @code{__thread} specifier may be applied to any global, file-scoped
24228static, function-scoped static, or static data member of a class. It may
24229not be applied to block-scoped automatic or non-static data member.
24230
24231When the address-of operator is applied to a thread-local variable, it is
24232evaluated at run time and returns the address of the current thread's
24233instance of that variable. An address so obtained may be used by any
24234thread. When a thread terminates, any pointers to thread-local variables
24235in that thread become invalid.
24236
24237No static initialization may refer to the address of a thread-local variable.
24238
24239In C++, if an initializer is present for a thread-local variable, it must
24240be a @var{constant-expression}, as defined in 5.19.2 of the ANSI/ISO C++
24241standard.
24242
24243See @uref{https://www.akkadia.org/drepper/tls.pdf,
24244ELF Handling For Thread-Local Storage} for a detailed explanation of
24245the four thread-local storage addressing models, and how the runtime
24246is expected to function.
24247
24248@menu
24249* C99 Thread-Local Edits::
24250* C++98 Thread-Local Edits::
24251@end menu
24252
24253@node C99 Thread-Local Edits
24254@subsection ISO/IEC 9899:1999 Edits for Thread-Local Storage
24255
24256The following are a set of changes to ISO/IEC 9899:1999 (aka C99)
24257that document the exact semantics of the language extension.
24258
24259@itemize @bullet
24260@item
24261@cite{5.1.2 Execution environments}
24262
24263Add new text after paragraph 1
24264
24265@quotation
24266Within either execution environment, a @dfn{thread} is a flow of
24267control within a program. It is implementation defined whether
24268or not there may be more than one thread associated with a program.
24269It is implementation defined how threads beyond the first are
24270created, the name and type of the function called at thread
24271startup, and how threads may be terminated. However, objects
24272with thread storage duration shall be initialized before thread
24273startup.
24274@end quotation
24275
24276@item
24277@cite{6.2.4 Storage durations of objects}
24278
24279Add new text before paragraph 3
24280
24281@quotation
24282An object whose identifier is declared with the storage-class
24283specifier @w{@code{__thread}} has @dfn{thread storage duration}.
24284Its lifetime is the entire execution of the thread, and its
24285stored value is initialized only once, prior to thread startup.
24286@end quotation
24287
24288@item
24289@cite{6.4.1 Keywords}
24290
24291Add @code{__thread}.
24292
24293@item
24294@cite{6.7.1 Storage-class specifiers}
24295
24296Add @code{__thread} to the list of storage class specifiers in
24297paragraph 1.
24298
24299Change paragraph 2 to
24300
24301@quotation
24302With the exception of @code{__thread}, at most one storage-class
24303specifier may be given [@dots{}]. The @code{__thread} specifier may
24304be used alone, or immediately following @code{extern} or
24305@code{static}.
24306@end quotation
24307
24308Add new text after paragraph 6
24309
24310@quotation
24311The declaration of an identifier for a variable that has
24312block scope that specifies @code{__thread} shall also
24313specify either @code{extern} or @code{static}.
24314
24315The @code{__thread} specifier shall be used only with
24316variables.
24317@end quotation
24318@end itemize
24319
24320@node C++98 Thread-Local Edits
24321@subsection ISO/IEC 14882:1998 Edits for Thread-Local Storage
24322
24323The following are a set of changes to ISO/IEC 14882:1998 (aka C++98)
24324that document the exact semantics of the language extension.
24325
24326@itemize @bullet
24327@item
24328@b{[intro.execution]}
24329
24330New text after paragraph 4
24331
24332@quotation
24333A @dfn{thread} is a flow of control within the abstract machine.
24334It is implementation defined whether or not there may be more than
24335one thread.
24336@end quotation
24337
24338New text after paragraph 7
24339
24340@quotation
24341It is unspecified whether additional action must be taken to
24342ensure when and whether side effects are visible to other threads.
24343@end quotation
24344
24345@item
24346@b{[lex.key]}
24347
24348Add @code{__thread}.
24349
24350@item
24351@b{[basic.start.main]}
24352
24353Add after paragraph 5
24354
24355@quotation
24356The thread that begins execution at the @code{main} function is called
24357the @dfn{main thread}. It is implementation defined how functions
24358beginning threads other than the main thread are designated or typed.
24359A function so designated, as well as the @code{main} function, is called
24360a @dfn{thread startup function}. It is implementation defined what
24361happens if a thread startup function returns. It is implementation
24362defined what happens to other threads when any thread calls @code{exit}.
24363@end quotation
24364
24365@item
24366@b{[basic.start.init]}
24367
24368Add after paragraph 4
24369
24370@quotation
24371The storage for an object of thread storage duration shall be
24372statically initialized before the first statement of the thread startup
24373function. An object of thread storage duration shall not require
24374dynamic initialization.
24375@end quotation
24376
24377@item
24378@b{[basic.start.term]}
24379
24380Add after paragraph 3
24381
24382@quotation
24383The type of an object with thread storage duration shall not have a
24384non-trivial destructor, nor shall it be an array type whose elements
24385(directly or indirectly) have non-trivial destructors.
24386@end quotation
24387
24388@item
24389@b{[basic.stc]}
24390
24391Add ``thread storage duration'' to the list in paragraph 1.
24392
24393Change paragraph 2
24394
24395@quotation
24396Thread, static, and automatic storage durations are associated with
24397objects introduced by declarations [@dots{}].
24398@end quotation
24399
24400Add @code{__thread} to the list of specifiers in paragraph 3.
24401
24402@item
24403@b{[basic.stc.thread]}
24404
24405New section before @b{[basic.stc.static]}
24406
24407@quotation
24408The keyword @code{__thread} applied to a non-local object gives the
24409object thread storage duration.
24410
24411A local variable or class data member declared both @code{static}
24412and @code{__thread} gives the variable or member thread storage
24413duration.
24414@end quotation
24415
24416@item
24417@b{[basic.stc.static]}
24418
24419Change paragraph 1
24420
24421@quotation
24422All objects that have neither thread storage duration, dynamic
24423storage duration nor are local [@dots{}].
24424@end quotation
24425
24426@item
24427@b{[dcl.stc]}
24428
24429Add @code{__thread} to the list in paragraph 1.
24430
24431Change paragraph 1
24432
24433@quotation
24434With the exception of @code{__thread}, at most one
24435@var{storage-class-specifier} shall appear in a given
24436@var{decl-specifier-seq}. The @code{__thread} specifier may
24437be used alone, or immediately following the @code{extern} or
24438@code{static} specifiers. [@dots{}]
24439@end quotation
24440
24441Add after paragraph 5
24442
24443@quotation
24444The @code{__thread} specifier can be applied only to the names of objects
24445and to anonymous unions.
24446@end quotation
24447
24448@item
24449@b{[class.mem]}
24450
24451Add after paragraph 6
24452
24453@quotation
24454Non-@code{static} members shall not be @code{__thread}.
24455@end quotation
24456@end itemize
24457
24458@node Binary constants
24459@section Binary Constants using the @samp{0b} Prefix
24460@cindex Binary constants using the @samp{0b} prefix
24461
24462Integer constants can be written as binary constants, consisting of a
24463sequence of @samp{0} and @samp{1} digits, prefixed by @samp{0b} or
24464@samp{0B}. This is particularly useful in environments that operate a
24465lot on the bit level (like microcontrollers).
24466
24467The following statements are identical:
24468
24469@smallexample
24470i = 42;
24471i = 0x2a;
24472i = 052;
24473i = 0b101010;
24474@end smallexample
24475
24476The type of these constants follows the same rules as for octal or
24477hexadecimal integer constants, so suffixes like @samp{L} or @samp{UL}
24478can be applied.
24479
24480@node C++ Extensions
24481@chapter Extensions to the C++ Language
24482@cindex extensions, C++ language
24483@cindex C++ language extensions
24484
24485The GNU compiler provides these extensions to the C++ language (and you
24486can also use most of the C language extensions in your C++ programs). If you
24487want to write code that checks whether these features are available, you can
24488test for the GNU compiler the same way as for C programs: check for a
24489predefined macro @code{__GNUC__}. You can also use @code{__GNUG__} to
24490test specifically for GNU C++ (@pxref{Common Predefined Macros,,
24491Predefined Macros,cpp,The GNU C Preprocessor}).
24492
24493@menu
24494* C++ Volatiles:: What constitutes an access to a volatile object.
24495* Restricted Pointers:: C99 restricted pointers and references.
24496* Vague Linkage:: Where G++ puts inlines, vtables and such.
24497* C++ Interface:: You can use a single C++ header file for both
24498 declarations and definitions.
24499* Template Instantiation:: Methods for ensuring that exactly one copy of
24500 each needed template instantiation is emitted.
24501* Bound member functions:: You can extract a function pointer to the
24502 method denoted by a @samp{->*} or @samp{.*} expression.
24503* C++ Attributes:: Variable, function, and type attributes for C++ only.
24504* Function Multiversioning:: Declaring multiple function versions.
24505* Type Traits:: Compiler support for type traits.
24506* C++ Concepts:: Improved support for generic programming.
24507* Deprecated Features:: Things will disappear from G++.
24508* Backwards Compatibility:: Compatibilities with earlier definitions of C++.
24509@end menu
24510
24511@node C++ Volatiles
24512@section When is a Volatile C++ Object Accessed?
24513@cindex accessing volatiles
24514@cindex volatile read
24515@cindex volatile write
24516@cindex volatile access
24517
24518The C++ standard differs from the C standard in its treatment of
24519volatile objects. It fails to specify what constitutes a volatile
24520access, except to say that C++ should behave in a similar manner to C
24521with respect to volatiles, where possible. However, the different
24522lvalueness of expressions between C and C++ complicate the behavior.
24523G++ behaves the same as GCC for volatile access, @xref{C
24524Extensions,,Volatiles}, for a description of GCC's behavior.
24525
24526The C and C++ language specifications differ when an object is
24527accessed in a void context:
24528
24529@smallexample
24530volatile int *src = @var{somevalue};
24531*src;
24532@end smallexample
24533
24534The C++ standard specifies that such expressions do not undergo lvalue
24535to rvalue conversion, and that the type of the dereferenced object may
24536be incomplete. The C++ standard does not specify explicitly that it
24537is lvalue to rvalue conversion that is responsible for causing an
24538access. There is reason to believe that it is, because otherwise
24539certain simple expressions become undefined. However, because it
24540would surprise most programmers, G++ treats dereferencing a pointer to
24541volatile object of complete type as GCC would do for an equivalent
24542type in C@. When the object has incomplete type, G++ issues a
24543warning; if you wish to force an error, you must force a conversion to
24544rvalue with, for instance, a static cast.
24545
24546When using a reference to volatile, G++ does not treat equivalent
24547expressions as accesses to volatiles, but instead issues a warning that
24548no volatile is accessed. The rationale for this is that otherwise it
24549becomes difficult to determine where volatile access occur, and not
24550possible to ignore the return value from functions returning volatile
24551references. Again, if you wish to force a read, cast the reference to
24552an rvalue.
24553
24554G++ implements the same behavior as GCC does when assigning to a
24555volatile object---there is no reread of the assigned-to object, the
24556assigned rvalue is reused. Note that in C++ assignment expressions
24557are lvalues, and if used as an lvalue, the volatile object is
24558referred to. For instance, @var{vref} refers to @var{vobj}, as
24559expected, in the following example:
24560
24561@smallexample
24562volatile int vobj;
24563volatile int &vref = vobj = @var{something};
24564@end smallexample
24565
24566@node Restricted Pointers
24567@section Restricting Pointer Aliasing
24568@cindex restricted pointers
24569@cindex restricted references
24570@cindex restricted this pointer
24571
24572As with the C front end, G++ understands the C99 feature of restricted pointers,
24573specified with the @code{__restrict__}, or @code{__restrict} type
24574qualifier. Because you cannot compile C++ by specifying the @option{-std=c99}
24575language flag, @code{restrict} is not a keyword in C++.
24576
24577In addition to allowing restricted pointers, you can specify restricted
24578references, which indicate that the reference is not aliased in the local
24579context.
24580
24581@smallexample
24582void fn (int *__restrict__ rptr, int &__restrict__ rref)
24583@{
24584 /* @r{@dots{}} */
24585@}
24586@end smallexample
24587
24588@noindent
24589In the body of @code{fn}, @var{rptr} points to an unaliased integer and
24590@var{rref} refers to a (different) unaliased integer.
24591
24592You may also specify whether a member function's @var{this} pointer is
24593unaliased by using @code{__restrict__} as a member function qualifier.
24594
24595@smallexample
24596void T::fn () __restrict__
24597@{
24598 /* @r{@dots{}} */
24599@}
24600@end smallexample
24601
24602@noindent
24603Within the body of @code{T::fn}, @var{this} has the effective
24604definition @code{T *__restrict__ const this}. Notice that the
24605interpretation of a @code{__restrict__} member function qualifier is
24606different to that of @code{const} or @code{volatile} qualifier, in that it
24607is applied to the pointer rather than the object. This is consistent with
24608other compilers that implement restricted pointers.
24609
24610As with all outermost parameter qualifiers, @code{__restrict__} is
24611ignored in function definition matching. This means you only need to
24612specify @code{__restrict__} in a function definition, rather than
24613in a function prototype as well.
24614
24615@node Vague Linkage
24616@section Vague Linkage
24617@cindex vague linkage
24618
24619There are several constructs in C++ that require space in the object
24620file but are not clearly tied to a single translation unit. We say that
24621these constructs have ``vague linkage''. Typically such constructs are
24622emitted wherever they are needed, though sometimes we can be more
24623clever.
24624
24625@table @asis
24626@item Inline Functions
24627Inline functions are typically defined in a header file which can be
24628included in many different compilations. Hopefully they can usually be
24629inlined, but sometimes an out-of-line copy is necessary, if the address
24630of the function is taken or if inlining fails. In general, we emit an
24631out-of-line copy in all translation units where one is needed. As an
24632exception, we only emit inline virtual functions with the vtable, since
24633it always requires a copy.
24634
24635Local static variables and string constants used in an inline function
24636are also considered to have vague linkage, since they must be shared
24637between all inlined and out-of-line instances of the function.
24638
d77de738 24639@cindex vtable
f25efe50 24640@item VTables
d77de738
ML
24641C++ virtual functions are implemented in most compilers using a lookup
24642table, known as a vtable. The vtable contains pointers to the virtual
24643functions provided by a class, and each object of the class contains a
24644pointer to its vtable (or vtables, in some multiple-inheritance
24645situations). If the class declares any non-inline, non-pure virtual
24646functions, the first one is chosen as the ``key method'' for the class,
24647and the vtable is only emitted in the translation unit where the key
24648method is defined.
24649
24650@emph{Note:} If the chosen key method is later defined as inline, the
24651vtable is still emitted in every translation unit that defines it.
24652Make sure that any inline virtuals are declared inline in the class
24653body, even if they are not defined there.
24654
d77de738
ML
24655@cindex @code{type_info}
24656@cindex RTTI
f25efe50 24657@item @code{type_info} objects
d77de738
ML
24658C++ requires information about types to be written out in order to
24659implement @samp{dynamic_cast}, @samp{typeid} and exception handling.
24660For polymorphic classes (classes with virtual functions), the @samp{type_info}
24661object is written out along with the vtable so that @samp{dynamic_cast}
24662can determine the dynamic type of a class object at run time. For all
24663other types, we write out the @samp{type_info} object when it is used: when
24664applying @samp{typeid} to an expression, throwing an object, or
24665referring to a type in a catch clause or exception specification.
24666
24667@item Template Instantiations
24668Most everything in this section also applies to template instantiations,
24669but there are other options as well.
24670@xref{Template Instantiation,,Where's the Template?}.
24671
24672@end table
24673
24674When used with GNU ld version 2.8 or later on an ELF system such as
24675GNU/Linux or Solaris 2, or on Microsoft Windows, duplicate copies of
24676these constructs will be discarded at link time. This is known as
24677COMDAT support.
24678
24679On targets that don't support COMDAT, but do support weak symbols, GCC
24680uses them. This way one copy overrides all the others, but
24681the unused copies still take up space in the executable.
24682
24683For targets that do not support either COMDAT or weak symbols,
24684most entities with vague linkage are emitted as local symbols to
24685avoid duplicate definition errors from the linker. This does not happen
24686for local statics in inlines, however, as having multiple copies
24687almost certainly breaks things.
24688
24689@xref{C++ Interface,,Declarations and Definitions in One Header}, for
24690another way to control placement of these constructs.
24691
24692@node C++ Interface
24693@section C++ Interface and Implementation Pragmas
24694
24695@cindex interface and implementation headers, C++
24696@cindex C++ interface and implementation headers
24697@cindex pragmas, interface and implementation
24698
24699@code{#pragma interface} and @code{#pragma implementation} provide the
24700user with a way of explicitly directing the compiler to emit entities
24701with vague linkage (and debugging information) in a particular
24702translation unit.
24703
24704@emph{Note:} These @code{#pragma}s have been superceded as of GCC 2.7.2
24705by COMDAT support and the ``key method'' heuristic
24706mentioned in @ref{Vague Linkage}. Using them can actually cause your
24707program to grow due to unnecessary out-of-line copies of inline
24708functions.
24709
24710@table @code
f25efe50 24711@kindex #pragma interface
d77de738
ML
24712@item #pragma interface
24713@itemx #pragma interface "@var{subdir}/@var{objects}.h"
d77de738
ML
24714Use this directive in @emph{header files} that define object classes, to save
24715space in most of the object files that use those classes. Normally,
24716local copies of certain information (backup copies of inline member
24717functions, debugging information, and the internal tables that implement
24718virtual functions) must be kept in each object file that includes class
24719definitions. You can use this pragma to avoid such duplication. When a
24720header file containing @samp{#pragma interface} is included in a
24721compilation, this auxiliary information is not generated (unless
24722the main input source file itself uses @samp{#pragma implementation}).
24723Instead, the object files contain references to be resolved at link
24724time.
24725
24726The second form of this directive is useful for the case where you have
24727multiple headers with the same name in different directories. If you
24728use this form, you must specify the same string to @samp{#pragma
24729implementation}.
24730
f25efe50 24731@kindex #pragma implementation
d77de738
ML
24732@item #pragma implementation
24733@itemx #pragma implementation "@var{objects}.h"
d77de738
ML
24734Use this pragma in a @emph{main input file}, when you want full output from
24735included header files to be generated (and made globally visible). The
24736included header file, in turn, should use @samp{#pragma interface}.
24737Backup copies of inline member functions, debugging information, and the
24738internal tables used to implement virtual functions are all generated in
24739implementation files.
24740
24741@cindex implied @code{#pragma implementation}
24742@cindex @code{#pragma implementation}, implied
24743@cindex naming convention, implementation headers
24744If you use @samp{#pragma implementation} with no argument, it applies to
24745an include file with the same basename@footnote{A file's @dfn{basename}
24746is the name stripped of all leading path information and of trailing
24747suffixes, such as @samp{.h} or @samp{.C} or @samp{.cc}.} as your source
24748file. For example, in @file{allclass.cc}, giving just
24749@samp{#pragma implementation}
24750by itself is equivalent to @samp{#pragma implementation "allclass.h"}.
24751
24752Use the string argument if you want a single implementation file to
24753include code from multiple header files. (You must also use
24754@samp{#include} to include the header file; @samp{#pragma
24755implementation} only specifies how to use the file---it doesn't actually
24756include it.)
24757
24758There is no way to split up the contents of a single header file into
24759multiple implementation files.
24760@end table
24761
24762@cindex inlining and C++ pragmas
24763@cindex C++ pragmas, effect on inlining
24764@cindex pragmas in C++, effect on inlining
24765@samp{#pragma implementation} and @samp{#pragma interface} also have an
24766effect on function inlining.
24767
24768If you define a class in a header file marked with @samp{#pragma
24769interface}, the effect on an inline function defined in that class is
24770similar to an explicit @code{extern} declaration---the compiler emits
24771no code at all to define an independent version of the function. Its
24772definition is used only for inlining with its callers.
24773
24774@opindex fno-implement-inlines
24775Conversely, when you include the same header file in a main source file
24776that declares it as @samp{#pragma implementation}, the compiler emits
24777code for the function itself; this defines a version of the function
24778that can be found via pointers (or by callers compiled without
24779inlining). If all calls to the function can be inlined, you can avoid
24780emitting the function by compiling with @option{-fno-implement-inlines}.
24781If any calls are not inlined, you will get linker errors.
24782
24783@node Template Instantiation
24784@section Where's the Template?
24785@cindex template instantiation
24786
24787C++ templates were the first language feature to require more
24788intelligence from the environment than was traditionally found on a UNIX
24789system. Somehow the compiler and linker have to make sure that each
24790template instance occurs exactly once in the executable if it is needed,
24791and not at all otherwise. There are two basic approaches to this
24792problem, which are referred to as the Borland model and the Cfront model.
24793
24794@table @asis
24795@item Borland model
24796Borland C++ solved the template instantiation problem by adding the code
24797equivalent of common blocks to their linker; the compiler emits template
24798instances in each translation unit that uses them, and the linker
24799collapses them together. The advantage of this model is that the linker
24800only has to consider the object files themselves; there is no external
24801complexity to worry about. The disadvantage is that compilation time
24802is increased because the template code is being compiled repeatedly.
24803Code written for this model tends to include definitions of all
24804templates in the header file, since they must be seen to be
24805instantiated.
24806
24807@item Cfront model
24808The AT&T C++ translator, Cfront, solved the template instantiation
24809problem by creating the notion of a template repository, an
24810automatically maintained place where template instances are stored. A
24811more modern version of the repository works as follows: As individual
24812object files are built, the compiler places any template definitions and
24813instantiations encountered in the repository. At link time, the link
24814wrapper adds in the objects in the repository and compiles any needed
24815instances that were not previously emitted. The advantages of this
24816model are more optimal compilation speed and the ability to use the
24817system linker; to implement the Borland model a compiler vendor also
24818needs to replace the linker. The disadvantages are vastly increased
24819complexity, and thus potential for error; for some code this can be
24820just as transparent, but in practice it can been very difficult to build
24821multiple programs in one directory and one program in multiple
24822directories. Code written for this model tends to separate definitions
24823of non-inline member templates into a separate file, which should be
24824compiled separately.
24825@end table
24826
24827G++ implements the Borland model on targets where the linker supports it,
24828including ELF targets (such as GNU/Linux), Mac OS X and Microsoft Windows.
24829Otherwise G++ implements neither automatic model.
24830
24831You have the following options for dealing with template instantiations:
24832
24833@enumerate
24834@item
24835Do nothing. Code written for the Borland model works fine, but
24836each translation unit contains instances of each of the templates it
24837uses. The duplicate instances will be discarded by the linker, but in
24838a large program, this can lead to an unacceptable amount of code
24839duplication in object files or shared libraries.
24840
24841Duplicate instances of a template can be avoided by defining an explicit
24842instantiation in one object file, and preventing the compiler from doing
24843implicit instantiations in any other object files by using an explicit
24844instantiation declaration, using the @code{extern template} syntax:
24845
24846@smallexample
24847extern template int max (int, int);
24848@end smallexample
24849
24850This syntax is defined in the C++ 2011 standard, but has been supported by
24851G++ and other compilers since well before 2011.
24852
24853Explicit instantiations can be used for the largest or most frequently
24854duplicated instances, without having to know exactly which other instances
24855are used in the rest of the program. You can scatter the explicit
24856instantiations throughout your program, perhaps putting them in the
24857translation units where the instances are used or the translation units
24858that define the templates themselves; you can put all of the explicit
24859instantiations you need into one big file; or you can create small files
24860like
24861
24862@smallexample
24863#include "Foo.h"
24864#include "Foo.cc"
24865
24866template class Foo<int>;
24867template ostream& operator <<
24868 (ostream&, const Foo<int>&);
24869@end smallexample
24870
24871@noindent
24872for each of the instances you need, and create a template instantiation
24873library from those.
24874
24875This is the simplest option, but also offers flexibility and
24876fine-grained control when necessary. It is also the most portable
24877alternative and programs using this approach will work with most modern
24878compilers.
24879
24880@item
24881@opindex fno-implicit-templates
24882Compile your code with @option{-fno-implicit-templates} to disable the
24883implicit generation of template instances, and explicitly instantiate
24884all the ones you use. This approach requires more knowledge of exactly
24885which instances you need than do the others, but it's less
24886mysterious and allows greater control if you want to ensure that only
24887the intended instances are used.
24888
24889If you are using Cfront-model code, you can probably get away with not
24890using @option{-fno-implicit-templates} when compiling files that don't
24891@samp{#include} the member template definitions.
24892
24893If you use one big file to do the instantiations, you may want to
24894compile it without @option{-fno-implicit-templates} so you get all of the
24895instances required by your explicit instantiations (but not by any
24896other files) without having to specify them as well.
24897
24898In addition to forward declaration of explicit instantiations
24899(with @code{extern}), G++ has extended the template instantiation
24900syntax to support instantiation of the compiler support data for a
24901template class (i.e.@: the vtable) without instantiating any of its
24902members (with @code{inline}), and instantiation of only the static data
24903members of a template class, without the support data or member
24904functions (with @code{static}):
24905
24906@smallexample
24907inline template class Foo<int>;
24908static template class Foo<int>;
24909@end smallexample
24910@end enumerate
24911
24912@node Bound member functions
24913@section Extracting the Function Pointer from a Bound Pointer to Member Function
24914@cindex pmf
24915@cindex pointer to member function
24916@cindex bound pointer to member function
24917
24918In C++, pointer to member functions (PMFs) are implemented using a wide
24919pointer of sorts to handle all the possible call mechanisms; the PMF
24920needs to store information about how to adjust the @samp{this} pointer,
24921and if the function pointed to is virtual, where to find the vtable, and
24922where in the vtable to look for the member function. If you are using
24923PMFs in an inner loop, you should really reconsider that decision. If
24924that is not an option, you can extract the pointer to the function that
24925would be called for a given object/PMF pair and call it directly inside
24926the inner loop, to save a bit of time.
24927
24928Note that you still pay the penalty for the call through a
24929function pointer; on most modern architectures, such a call defeats the
24930branch prediction features of the CPU@. This is also true of normal
24931virtual function calls.
24932
24933The syntax for this extension is
24934
24935@smallexample
24936extern A a;
24937extern int (A::*fp)();
24938typedef int (*fptr)(A *);
24939
24940fptr p = (fptr)(a.*fp);
24941@end smallexample
24942
24943For PMF constants (i.e.@: expressions of the form @samp{&Klasse::Member}),
24944no object is needed to obtain the address of the function. They can be
24945converted to function pointers directly:
24946
24947@smallexample
24948fptr p1 = (fptr)(&A::foo);
24949@end smallexample
24950
24951@opindex Wno-pmf-conversions
24952You must specify @option{-Wno-pmf-conversions} to use this extension.
24953
24954@node C++ Attributes
24955@section C++-Specific Variable, Function, and Type Attributes
24956
24957Some attributes only make sense for C++ programs.
24958
24959@table @code
d77de738
ML
24960@cindex @code{abi_tag} function attribute
24961@cindex @code{abi_tag} variable attribute
24962@cindex @code{abi_tag} type attribute
f25efe50 24963@item abi_tag ("@var{tag}", ...)
d77de738
ML
24964The @code{abi_tag} attribute can be applied to a function, variable, or class
24965declaration. It modifies the mangled name of the entity to
24966incorporate the tag name, in order to distinguish the function or
24967class from an earlier version with a different ABI; perhaps the class
24968has changed size, or the function has a different return type that is
24969not encoded in the mangled name.
24970
24971The attribute can also be applied to an inline namespace, but does not
24972affect the mangled name of the namespace; in this case it is only used
24973for @option{-Wabi-tag} warnings and automatic tagging of functions and
24974variables. Tagging inline namespaces is generally preferable to
24975tagging individual declarations, but the latter is sometimes
24976necessary, such as when only certain members of a class need to be
24977tagged.
24978
24979The argument can be a list of strings of arbitrary length. The
24980strings are sorted on output, so the order of the list is
24981unimportant.
24982
24983A redeclaration of an entity must not add new ABI tags,
24984since doing so would change the mangled name.
24985
24986The ABI tags apply to a name, so all instantiations and
24987specializations of a template have the same tags. The attribute will
24988be ignored if applied to an explicit specialization or instantiation.
24989
24990The @option{-Wabi-tag} flag enables a warning about a class which does
24991not have all the ABI tags used by its subobjects and virtual functions; for users with code
24992that needs to coexist with an earlier ABI, using this option can help
24993to find all affected types that need to be tagged.
24994
24995When a type involving an ABI tag is used as the type of a variable or
24996return type of a function where that tag is not already present in the
24997signature of the function, the tag is automatically applied to the
24998variable or function. @option{-Wabi-tag} also warns about this
24999situation; this warning can be avoided by explicitly tagging the
25000variable or function or moving it into a tagged inline namespace.
25001
d77de738 25002@cindex @code{init_priority} variable attribute
f25efe50 25003@item init_priority (@var{priority})
d77de738
ML
25004
25005In Standard C++, objects defined at namespace scope are guaranteed to be
25006initialized in an order in strict accordance with that of their definitions
25007@emph{in a given translation unit}. No guarantee is made for initializations
25008across translation units. However, GNU C++ allows users to control the
25009order of initialization of objects defined at namespace scope with the
25010@code{init_priority} attribute by specifying a relative @var{priority},
25011a constant integral expression currently bounded between 101 and 65535
25012inclusive. Lower numbers indicate a higher priority.
25013
25014In the following example, @code{A} would normally be created before
25015@code{B}, but the @code{init_priority} attribute reverses that order:
25016
25017@smallexample
25018Some_Class A __attribute__ ((init_priority (2000)));
25019Some_Class B __attribute__ ((init_priority (543)));
25020@end smallexample
25021
25022@noindent
25023Note that the particular values of @var{priority} do not matter; only their
25024relative ordering.
25025
d77de738 25026@cindex @code{warn_unused} type attribute
f25efe50 25027@item warn_unused
d77de738
ML
25028
25029For C++ types with non-trivial constructors and/or destructors it is
25030impossible for the compiler to determine whether a variable of this
25031type is truly unused if it is not referenced. This type attribute
25032informs the compiler that variables of this type should be warned
25033about if they appear to be unused, just like variables of fundamental
25034types.
25035
25036This attribute is appropriate for types which just represent a value,
25037such as @code{std::string}; it is not appropriate for types which
25038control a resource, such as @code{std::lock_guard}.
25039
25040This attribute is also accepted in C, but it is unnecessary because C
25041does not have constructors or destructors.
25042
25043@end table
25044
25045@node Function Multiversioning
25046@section Function Multiversioning
25047@cindex function versions
25048
25049With the GNU C++ front end, for x86 targets, you may specify multiple
25050versions of a function, where each function is specialized for a
25051specific target feature. At runtime, the appropriate version of the
25052function is automatically executed depending on the characteristics of
25053the execution platform. Here is an example.
25054
25055@smallexample
25056__attribute__ ((target ("default")))
25057int foo ()
25058@{
25059 // The default version of foo.
25060 return 0;
25061@}
25062
25063__attribute__ ((target ("sse4.2")))
25064int foo ()
25065@{
25066 // foo version for SSE4.2
25067 return 1;
25068@}
25069
25070__attribute__ ((target ("arch=atom")))
25071int foo ()
25072@{
25073 // foo version for the Intel ATOM processor
25074 return 2;
25075@}
25076
25077__attribute__ ((target ("arch=amdfam10")))
25078int foo ()
25079@{
25080 // foo version for the AMD Family 0x10 processors.
25081 return 3;
25082@}
25083
25084int main ()
25085@{
25086 int (*p)() = &foo;
25087 assert ((*p) () == foo ());
25088 return 0;
25089@}
25090@end smallexample
25091
25092In the above example, four versions of function foo are created. The
25093first version of foo with the target attribute "default" is the default
25094version. This version gets executed when no other target specific
25095version qualifies for execution on a particular platform. A new version
25096of foo is created by using the same function signature but with a
25097different target string. Function foo is called or a pointer to it is
25098taken just like a regular function. GCC takes care of doing the
25099dispatching to call the right version at runtime. Refer to the
25100@uref{https://gcc.gnu.org/wiki/FunctionMultiVersioning, GCC wiki on
25101Function Multiversioning} for more details.
25102
25103@node Type Traits
25104@section Type Traits
25105
25106The C++ front end implements syntactic extensions that allow
25107compile-time determination of
25108various characteristics of a type (or of a
25109pair of types).
25110
f25efe50
AA
25111@defbuiltin{bool __has_nothrow_assign (@var{type})}
25112If @var{type} is @code{const}-qualified or is a reference type then
d77de738 25113the trait is @code{false}. Otherwise if @code{__has_trivial_assign (type)}
f25efe50 25114is @code{true} then the trait is @code{true}, else if @var{type} is
d77de738
ML
25115a cv-qualified class or union type with copy assignment operators that are
25116known not to throw an exception then the trait is @code{true}, else it is
25117@code{false}.
f25efe50 25118Requires: @var{type} shall be a complete type, (possibly cv-qualified)
d77de738 25119@code{void}, or an array of unknown bound.
f25efe50 25120@enddefbuiltin
d77de738 25121
f25efe50 25122@defbuiltin{bool __has_nothrow_copy (@var{type})}
d77de738 25123If @code{__has_trivial_copy (type)} is @code{true} then the trait is
f25efe50 25124@code{true}, else if @var{type} is a cv-qualified class or union type
d77de738
ML
25125with copy constructors that are known not to throw an exception then
25126the trait is @code{true}, else it is @code{false}.
f25efe50 25127Requires: @var{type} shall be a complete type, (possibly cv-qualified)
d77de738 25128@code{void}, or an array of unknown bound.
f25efe50 25129@enddefbuiltin
d77de738 25130
f25efe50 25131@defbuiltin{bool __has_nothrow_constructor (@var{type})}
d77de738 25132If @code{__has_trivial_constructor (type)} is @code{true} then the trait
f25efe50 25133is @code{true}, else if @var{type} is a cv class or union type (or array
d77de738
ML
25134thereof) with a default constructor that is known not to throw an
25135exception then the trait is @code{true}, else it is @code{false}.
f25efe50 25136Requires: @var{type} shall be a complete type, (possibly cv-qualified)
d77de738 25137@code{void}, or an array of unknown bound.
f25efe50 25138@enddefbuiltin
d77de738 25139
f25efe50
AA
25140@defbuiltin{bool __has_trivial_assign (@var{type})}
25141If @var{type} is @code{const}- qualified or is a reference type then
d77de738 25142the trait is @code{false}. Otherwise if @code{__is_trivial (type)} is
f25efe50 25143@code{true} then the trait is @code{true}, else if @var{type} is
d77de738
ML
25144a cv-qualified class or union type with a trivial copy assignment
25145([class.copy]) then the trait is @code{true}, else it is @code{false}.
f25efe50 25146Requires: @var{type} shall be a complete type, (possibly cv-qualified)
d77de738 25147@code{void}, or an array of unknown bound.
f25efe50 25148@enddefbuiltin
d77de738 25149
f25efe50
AA
25150@defbuiltin{bool __has_trivial_copy (@var{type})}
25151If @code{__is_trivial (type)} is @code{true} or @var{type} is a reference
25152type then the trait is @code{true}, else if @var{type} is a cv class
d77de738 25153or union type with a trivial copy constructor ([class.copy]) then the trait
f25efe50 25154is @code{true}, else it is @code{false}. Requires: @var{type} shall be
d77de738
ML
25155a complete type, (possibly cv-qualified) @code{void}, or an array of unknown
25156bound.
f25efe50 25157@enddefbuiltin
d77de738 25158
f25efe50 25159@defbuiltin{bool __has_trivial_constructor (@var{type})}
d77de738 25160If @code{__is_trivial (type)} is @code{true} then the trait is @code{true},
f25efe50 25161else if @var{type} is a cv-qualified class or union type (or array thereof)
d77de738
ML
25162with a trivial default constructor ([class.ctor]) then the trait is @code{true},
25163else it is @code{false}.
f25efe50 25164Requires: @var{type} shall be a complete type, (possibly cv-qualified)
d77de738 25165@code{void}, or an array of unknown bound.
f25efe50 25166@enddefbuiltin
d77de738 25167
f25efe50
AA
25168@defbuiltin{bool __has_trivial_destructor (@var{type})}
25169If @code{__is_trivial (type)} is @code{true} or @var{type} is a reference type
25170then the trait is @code{true}, else if @var{type} is a cv class or union
d77de738
ML
25171type (or array thereof) with a trivial destructor ([class.dtor]) then
25172the trait is @code{true}, else it is @code{false}.
f25efe50 25173Requires: @var{type} shall be a complete type, (possibly cv-qualified)
d77de738 25174@code{void}, or an array of unknown bound.
f25efe50 25175@enddefbuiltin
d77de738 25176
f25efe50
AA
25177@defbuiltin{bool __has_virtual_destructor (@var{type})}
25178If @var{type} is a class type with a virtual destructor
d77de738 25179([class.dtor]) then the trait is @code{true}, else it is @code{false}.
f25efe50
AA
25180Requires: If @var{type} is a non-union class type, it shall be a complete type.
25181@enddefbuiltin
d77de738 25182
f25efe50
AA
25183@defbuiltin{bool __is_abstract (@var{type})}
25184If @var{type} is an abstract class ([class.abstract]) then the trait
d77de738 25185is @code{true}, else it is @code{false}.
f25efe50
AA
25186Requires: If @var{type} is a non-union class type, it shall be a complete type.
25187@enddefbuiltin
d77de738 25188
f25efe50
AA
25189@defbuiltin{bool __is_aggregate (@var{type})}
25190If @var{type} is an aggregate type ([dcl.init.aggr]) the trait is
d77de738 25191@code{true}, else it is @code{false}.
f25efe50
AA
25192Requires: If @var{type} is a class type, it shall be a complete type.
25193@enddefbuiltin
d77de738 25194
f25efe50
AA
25195@defbuiltin{bool __is_base_of (@var{base_type}, @var{derived_type})}
25196If @var{base_type} is a base class of @var{derived_type}
d77de738 25197([class.derived]) then the trait is @code{true}, otherwise it is @code{false}.
f25efe50
AA
25198Top-level cv-qualifications of @var{base_type} and
25199@var{derived_type} are ignored. For the purposes of this trait, a
d77de738
ML
25200class type is considered is own base.
25201Requires: if @code{__is_class (base_type)} and @code{__is_class (derived_type)}
f25efe50
AA
25202are @code{true} and @var{base_type} and @var{derived_type} are not the same
25203type (disregarding cv-qualifiers), @var{derived_type} shall be a complete
d77de738 25204type. A diagnostic is produced if this requirement is not met.
f25efe50 25205@enddefbuiltin
d77de738 25206
f25efe50
AA
25207@defbuiltin{bool __is_class (@var{type})}
25208If @var{type} is a cv-qualified class type, and not a union type
d77de738 25209([basic.compound]) the trait is @code{true}, else it is @code{false}.
f25efe50 25210@enddefbuiltin
d77de738 25211
30556bf8 25212@c FIXME Commented out for GCC 13, discuss user interface for GCC 14.
f25efe50 25213@c @defbuiltin{bool __is_deducible (@var{template}, @var{type})}
30556bf8
JM
25214@c If template arguments for @code{template} can be deduced from
25215@c @code{type} or obtained from default template arguments.
f25efe50 25216@c @enddefbuiltin
148cbb15 25217
f25efe50 25218@defbuiltin{bool __is_empty (@var{type})}
d77de738 25219If @code{__is_class (type)} is @code{false} then the trait is @code{false}.
f25efe50 25220Otherwise @var{type} is considered empty if and only if: @var{type}
d77de738 25221has no non-static data members, or all non-static data members, if
f25efe50
AA
25222any, are bit-fields of length 0, and @var{type} has no virtual
25223members, and @var{type} has no virtual base classes, and @var{type}
25224has no base classes @var{base_type} for which
d77de738 25225@code{__is_empty (base_type)} is @code{false}.
f25efe50
AA
25226Requires: If @var{type} is a non-union class type, it shall be a complete type.
25227@enddefbuiltin
d77de738 25228
f25efe50
AA
25229@defbuiltin{bool __is_enum (@var{type})}
25230If @var{type} is a cv enumeration type ([basic.compound]) the trait is
d77de738 25231@code{true}, else it is @code{false}.
f25efe50 25232@enddefbuiltin
d77de738 25233
f25efe50
AA
25234@defbuiltin{bool __is_final (@var{type})}
25235If @var{type} is a class or union type marked @code{final}, then the trait
d77de738 25236is @code{true}, else it is @code{false}.
f25efe50
AA
25237Requires: If @var{type} is a class type, it shall be a complete type.
25238@enddefbuiltin
d77de738 25239
f25efe50
AA
25240@defbuiltin{bool __is_literal_type (@var{type})}
25241If @var{type} is a literal type ([basic.types]) the trait is
d77de738 25242@code{true}, else it is @code{false}.
f25efe50 25243Requires: @var{type} shall be a complete type, (possibly cv-qualified)
d77de738 25244@code{void}, or an array of unknown bound.
f25efe50 25245@enddefbuiltin
d77de738 25246
f25efe50
AA
25247@defbuiltin{bool __is_pod (@var{type})}
25248If @var{type} is a cv POD type ([basic.types]) then the trait is @code{true},
d77de738 25249else it is @code{false}.
f25efe50 25250Requires: @var{type} shall be a complete type, (possibly cv-qualified)
d77de738 25251@code{void}, or an array of unknown bound.
f25efe50 25252@enddefbuiltin
d77de738 25253
f25efe50
AA
25254@defbuiltin{bool __is_polymorphic (@var{type})}
25255If @var{type} is a polymorphic class ([class.virtual]) then the trait
d77de738 25256is @code{true}, else it is @code{false}.
f25efe50
AA
25257Requires: If @var{type} is a non-union class type, it shall be a complete type.
25258@enddefbuiltin
d77de738 25259
f25efe50
AA
25260@defbuiltin{bool __is_standard_layout (@var{type})}
25261If @var{type} is a standard-layout type ([basic.types]) the trait is
d77de738 25262@code{true}, else it is @code{false}.
f25efe50 25263Requires: @var{type} shall be a complete type, an array of complete types,
d77de738 25264or (possibly cv-qualified) @code{void}.
f25efe50 25265@enddefbuiltin
d77de738 25266
f25efe50
AA
25267@defbuiltin{bool __is_trivial (@var{type})}
25268If @var{type} is a trivial type ([basic.types]) the trait is
d77de738 25269@code{true}, else it is @code{false}.
f25efe50 25270Requires: @var{type} shall be a complete type, an array of complete types,
d77de738 25271or (possibly cv-qualified) @code{void}.
f25efe50 25272@enddefbuiltin
d77de738 25273
f25efe50
AA
25274@defbuiltin{bool __is_union (@var{type})}
25275If @var{type} is a cv union type ([basic.compound]) the trait is
d77de738 25276@code{true}, else it is @code{false}.
f25efe50 25277@enddefbuiltin
d77de738 25278
f25efe50
AA
25279@defbuiltin{bool __underlying_type (@var{type})}
25280The underlying type of @var{type}.
25281Requires: @var{type} shall be an enumeration type ([dcl.enum]).
25282@enddefbuiltin
d77de738 25283
f25efe50 25284@defbuiltin{bool __integer_pack (@var{length})}
d77de738
ML
25285When used as the pattern of a pack expansion within a template
25286definition, expands to a template argument pack containing integers
f25efe50
AA
25287from @code{0} to @code{@var{length}-1}. This is provided for
25288efficient implementation of @code{std::make_integer_sequence}.
25289@enddefbuiltin
d77de738
ML
25290
25291
25292@node C++ Concepts
25293@section C++ Concepts
25294
25295C++ concepts provide much-improved support for generic programming. In
25296particular, they allow the specification of constraints on template arguments.
25297The constraints are used to extend the usual overloading and partial
25298specialization capabilities of the language, allowing generic data structures
25299and algorithms to be ``refined'' based on their properties rather than their
25300type names.
25301
25302The following keywords are reserved for concepts.
25303
25304@table @code
f25efe50 25305@kindex assumes
d77de738
ML
25306@item assumes
25307States an expression as an assumption, and if possible, verifies that the
25308assumption is valid. For example, @code{assume(n > 0)}.
25309
f25efe50 25310@kindex axiom
d77de738
ML
25311@item axiom
25312Introduces an axiom definition. Axioms introduce requirements on values.
25313
f25efe50 25314@kindex axiom
d77de738
ML
25315@item forall
25316Introduces a universally quantified object in an axiom. For example,
25317@code{forall (int n) n + 0 == n}).
25318
f25efe50 25319@kindex axiom
d77de738
ML
25320@item concept
25321Introduces a concept definition. Concepts are sets of syntactic and semantic
25322requirements on types and their values.
25323
f25efe50 25324@kindex requires
d77de738
ML
25325@item requires
25326Introduces constraints on template arguments or requirements for a member
25327function of a class template.
d77de738
ML
25328@end table
25329
25330The front end also exposes a number of internal mechanism that can be used
25331to simplify the writing of type traits. Note that some of these traits are
25332likely to be removed in the future.
25333
f25efe50
AA
25334@defbuiltin{bool __is_same (@var{type1}, @var{type2})}
25335A binary type trait: @code{true} whenever the @var{type1} and
25336@var{type2} refer to the same type.
25337@enddefbuiltin
d77de738
ML
25338
25339
25340@node Deprecated Features
25341@section Deprecated Features
25342
25343In the past, the GNU C++ compiler was extended to experiment with new
25344features, at a time when the C++ language was still evolving. Now that
25345the C++ standard is complete, some of those features are superseded by
25346superior alternatives. Using the old features might cause a warning in
25347some cases that the feature will be dropped in the future. In other
25348cases, the feature might be gone already.
25349
25350G++ allows a virtual function returning @samp{void *} to be overridden
25351by one returning a different pointer type. This extension to the
25352covariant return type rules is now deprecated and will be removed from a
25353future version.
25354
25355The use of default arguments in function pointers, function typedefs
25356and other places where they are not permitted by the standard is
25357deprecated and will be removed from a future version of G++.
25358
25359G++ allows floating-point literals to appear in integral constant expressions,
25360e.g.@: @samp{ enum E @{ e = int(2.2 * 3.7) @} }
25361This extension is deprecated and will be removed from a future version.
25362
25363G++ allows static data members of const floating-point type to be declared
25364with an initializer in a class definition. The standard only allows
25365initializers for static members of const integral types and const
25366enumeration types so this extension has been deprecated and will be removed
25367from a future version.
25368
25369G++ allows attributes to follow a parenthesized direct initializer,
25370e.g.@: @samp{ int f (0) __attribute__ ((something)); } This extension
25371has been ignored since G++ 3.3 and is deprecated.
25372
25373G++ allows anonymous structs and unions to have members that are not
25374public non-static data members (i.e.@: fields). These extensions are
25375deprecated.
25376
25377@node Backwards Compatibility
25378@section Backwards Compatibility
25379@cindex Backwards Compatibility
25380@cindex ARM [Annotated C++ Reference Manual]
25381
25382Now that there is a definitive ISO standard C++, G++ has a specification
25383to adhere to. The C++ language evolved over time, and features that
25384used to be acceptable in previous drafts of the standard, such as the ARM
25385[Annotated C++ Reference Manual], are no longer accepted. In order to allow
25386compilation of C++ written to such drafts, G++ contains some backwards
25387compatibilities. @emph{All such backwards compatibility features are
25388liable to disappear in future versions of G++.} They should be considered
25389deprecated. @xref{Deprecated Features}.
25390
25391@table @code
25392
25393@item Implicit C language
25394Old C system header files did not contain an @code{extern "C" @{@dots{}@}}
25395scope to set the language. On such systems, all system header files are
25396implicitly scoped inside a C language scope. Such headers must
25397correctly prototype function argument types, there is no leeway for
25398@code{()} to indicate an unspecified set of arguments.
25399
25400@end table
25401
25402@c LocalWords: emph deftypefn builtin ARCv2EM SIMD builtins msimd
25403@c LocalWords: typedef v4si v8hi DMA dma vdiwr vdowr