]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/doc/extend.texi
Update copyright years.
[thirdparty/gcc.git] / gcc / doc / extend.texi
CommitLineData
a945c346 1@c Copyright (C) 1988-2024 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.
f0a90c7d 80* Stack Scrubbing:: Stack scrubbing internal interfaces.
d77de738
ML
81* Vector Extensions:: Using vector instructions through built-in functions.
82* Offsetof:: Special syntax for implementing @code{offsetof}.
83* __sync Builtins:: Legacy built-in functions for atomic memory access.
84* __atomic Builtins:: Atomic built-in functions with memory model.
85* Integer Overflow Builtins:: Built-in functions to perform arithmetics and
86 arithmetic overflow checking.
87* x86 specific memory model extensions for transactional memory:: x86 memory models.
88* Object Size Checking:: Built-in functions for limited buffer overflow
89 checking.
90* Other Builtins:: Other built-in functions.
91* Target Builtins:: Built-in functions specific to particular targets.
92* Target Format Checks:: Format checks specific to particular targets.
93* Pragmas:: Pragmas accepted by GCC.
94* Unnamed Fields:: Unnamed struct/union fields within structs/unions.
95* Thread-Local:: Per-thread variables.
96* Binary constants:: Binary constants using the @samp{0b} prefix.
97@end menu
98
99@node Statement Exprs
100@section Statements and Declarations in Expressions
101@cindex statements inside expressions
102@cindex declarations inside expressions
103@cindex expressions containing statements
104@cindex macros, statements in expressions
105
106@c the above section title wrapped and causes an underfull hbox.. i
107@c changed it from "within" to "in". --mew 4feb93
108A compound statement enclosed in parentheses may appear as an expression
109in GNU C@. This allows you to use loops, switches, and local variables
110within an expression.
111
112Recall that a compound statement is a sequence of statements surrounded
113by braces; in this construct, parentheses go around the braces. For
114example:
115
116@smallexample
117(@{ int y = foo (); int z;
118 if (y > 0) z = y;
119 else z = - y;
120 z; @})
121@end smallexample
122
123@noindent
124is a valid (though slightly more complex than necessary) expression
125for the absolute value of @code{foo ()}.
126
127The last thing in the compound statement should be an expression
128followed by a semicolon; the value of this subexpression serves as the
129value of the entire construct. (If you use some other kind of statement
130last within the braces, the construct has type @code{void}, and thus
131effectively no value.)
132
133This feature is especially useful in making macro definitions ``safe'' (so
134that they evaluate each operand exactly once). For example, the
135``maximum'' function is commonly defined as a macro in standard C as
136follows:
137
138@smallexample
139#define max(a,b) ((a) > (b) ? (a) : (b))
140@end smallexample
141
142@noindent
143@cindex side effects, macro argument
144But this definition computes either @var{a} or @var{b} twice, with bad
145results if the operand has side effects. In GNU C, if you know the
146type of the operands (here taken as @code{int}), you can avoid this
147problem by defining the macro as follows:
148
149@smallexample
150#define maxint(a,b) \
151 (@{int _a = (a), _b = (b); _a > _b ? _a : _b; @})
152@end smallexample
153
154Note that introducing variable declarations (as we do in @code{maxint}) can
155cause variable shadowing, so while this example using the @code{max} macro
156produces correct results:
157@smallexample
158int _a = 1, _b = 2, c;
159c = max (_a, _b);
160@end smallexample
161@noindent
162this example using maxint will not:
163@smallexample
164int _a = 1, _b = 2, c;
165c = maxint (_a, _b);
166@end smallexample
167
168This problem may for instance occur when we use this pattern recursively, like
169so:
170
171@smallexample
172#define maxint3(a, b, c) \
173 (@{int _a = (a), _b = (b), _c = (c); maxint (maxint (_a, _b), _c); @})
174@end smallexample
175
176Embedded statements are not allowed in constant expressions, such as
177the value of an enumeration constant, the width of a bit-field, or
178the initial value of a static variable.
179
180If you don't know the type of the operand, you can still do this, but you
181must use @code{typeof} or @code{__auto_type} (@pxref{Typeof}).
182
183In G++, the result value of a statement expression undergoes array and
184function pointer decay, and is returned by value to the enclosing
185expression. For instance, if @code{A} is a class, then
186
187@smallexample
188 A a;
189
190 (@{a;@}).Foo ()
191@end smallexample
192
193@noindent
194constructs a temporary @code{A} object to hold the result of the
195statement expression, and that is used to invoke @code{Foo}.
196Therefore the @code{this} pointer observed by @code{Foo} is not the
197address of @code{a}.
198
199In a statement expression, any temporaries created within a statement
200are destroyed at that statement's end. This makes statement
201expressions inside macros slightly different from function calls. In
202the latter case temporaries introduced during argument evaluation are
203destroyed at the end of the statement that includes the function
204call. In the statement expression case they are destroyed during
205the statement expression. For instance,
206
207@smallexample
208#define macro(a) (@{__typeof__(a) b = (a); b + 3; @})
209template<typename T> T function(T a) @{ T b = a; return b + 3; @}
210
211void foo ()
212@{
213 macro (X ());
214 function (X ());
215@}
216@end smallexample
217
218@noindent
219has different places where temporaries are destroyed. For the
220@code{macro} case, the temporary @code{X} is destroyed just after
221the initialization of @code{b}. In the @code{function} case that
222temporary is destroyed when the function returns.
223
224These considerations mean that it is probably a bad idea to use
225statement expressions of this form in header files that are designed to
226work with C++. (Note that some versions of the GNU C Library contained
227header files using statement expressions that lead to precisely this
228bug.)
229
230Jumping into a statement expression with @code{goto} or using a
231@code{switch} statement outside the statement expression with a
232@code{case} or @code{default} label inside the statement expression is
233not permitted. Jumping into a statement expression with a computed
234@code{goto} (@pxref{Labels as Values}) has undefined behavior.
235Jumping out of a statement expression is permitted, but if the
236statement expression is part of a larger expression then it is
237unspecified which other subexpressions of that expression have been
238evaluated except where the language definition requires certain
239subexpressions to be evaluated before or after the statement
240expression. A @code{break} or @code{continue} statement inside of
241a statement expression used in @code{while}, @code{do} or @code{for}
242loop or @code{switch} statement condition
243or @code{for} statement init or increment expressions jumps to an
244outer loop or @code{switch} statement if any (otherwise it is an error),
245rather than to the loop or @code{switch} statement in whose condition
246or init or increment expression it appears.
247In any case, as with a function call, the evaluation of a
248statement expression is not interleaved with the evaluation of other
249parts of the containing expression. For example,
250
251@smallexample
252 foo (), ((@{ bar1 (); goto a; 0; @}) + bar2 ()), baz();
253@end smallexample
254
255@noindent
256calls @code{foo} and @code{bar1} and does not call @code{baz} but
257may or may not call @code{bar2}. If @code{bar2} is called, it is
258called after @code{foo} and before @code{bar1}.
259
260@node Local Labels
261@section Locally Declared Labels
262@cindex local labels
263@cindex macros, local labels
264
265GCC allows you to declare @dfn{local labels} in any nested block
266scope. A local label is just like an ordinary label, but you can
267only reference it (with a @code{goto} statement, or by taking its
268address) within the block in which it is declared.
269
270A local label declaration looks like this:
271
272@smallexample
273__label__ @var{label};
274@end smallexample
275
276@noindent
277or
278
279@smallexample
280__label__ @var{label1}, @var{label2}, /* @r{@dots{}} */;
281@end smallexample
282
283Local label declarations must come at the beginning of the block,
284before any ordinary declarations or statements.
285
286The label declaration defines the label @emph{name}, but does not define
287the label itself. You must do this in the usual way, with
288@code{@var{label}:}, within the statements of the statement expression.
289
290The local label feature is useful for complex macros. If a macro
291contains nested loops, a @code{goto} can be useful for breaking out of
292them. However, an ordinary label whose scope is the whole function
293cannot be used: if the macro can be expanded several times in one
294function, the label is multiply defined in that function. A
295local label avoids this problem. For example:
296
297@smallexample
298#define SEARCH(value, array, target) \
299do @{ \
300 __label__ found; \
301 typeof (target) _SEARCH_target = (target); \
302 typeof (*(array)) *_SEARCH_array = (array); \
303 int i, j; \
304 int value; \
305 for (i = 0; i < max; i++) \
306 for (j = 0; j < max; j++) \
307 if (_SEARCH_array[i][j] == _SEARCH_target) \
308 @{ (value) = i; goto found; @} \
309 (value) = -1; \
310 found:; \
311@} while (0)
312@end smallexample
313
314This could also be written using a statement expression:
315
316@smallexample
317#define SEARCH(array, target) \
318(@{ \
319 __label__ found; \
320 typeof (target) _SEARCH_target = (target); \
321 typeof (*(array)) *_SEARCH_array = (array); \
322 int i, j; \
323 int value; \
324 for (i = 0; i < max; i++) \
325 for (j = 0; j < max; j++) \
326 if (_SEARCH_array[i][j] == _SEARCH_target) \
327 @{ value = i; goto found; @} \
328 value = -1; \
329 found: \
330 value; \
331@})
332@end smallexample
333
334Local label declarations also make the labels they declare visible to
335nested functions, if there are any. @xref{Nested Functions}, for details.
336
337@node Labels as Values
338@section Labels as Values
339@cindex labels as values
340@cindex computed gotos
341@cindex goto with computed label
342@cindex address of a label
343
344You can get the address of a label defined in the current function
345(or a containing function) with the unary operator @samp{&&}. The
346value has type @code{void *}. This value is a constant and can be used
347wherever a constant of that type is valid. For example:
348
349@smallexample
350void *ptr;
351/* @r{@dots{}} */
352ptr = &&foo;
353@end smallexample
354
355To use these values, you need to be able to jump to one. This is done
356with the computed goto statement@footnote{The analogous feature in
357Fortran is called an assigned goto, but that name seems inappropriate in
358C, where one can do more than simply store label addresses in label
359variables.}, @code{goto *@var{exp};}. For example,
360
361@smallexample
362goto *ptr;
363@end smallexample
364
365@noindent
366Any expression of type @code{void *} is allowed.
367
368One way of using these constants is in initializing a static array that
369serves as a jump table:
370
371@smallexample
372static void *array[] = @{ &&foo, &&bar, &&hack @};
373@end smallexample
374
375@noindent
376Then you can select a label with indexing, like this:
377
378@smallexample
379goto *array[i];
380@end smallexample
381
382@noindent
383Note that this does not check whether the subscript is in bounds---array
384indexing in C never does that.
385
386Such an array of label values serves a purpose much like that of the
387@code{switch} statement. The @code{switch} statement is cleaner, so
388use that rather than an array unless the problem does not fit a
389@code{switch} statement very well.
390
391Another use of label values is in an interpreter for threaded code.
392The labels within the interpreter function can be stored in the
393threaded code for super-fast dispatching.
394
395You may not use this mechanism to jump to code in a different function.
396If you do that, totally unpredictable things happen. The best way to
397avoid this is to store the label address only in automatic variables and
398never pass it as an argument.
399
400An alternate way to write the above example is
401
402@smallexample
403static const int array[] = @{ &&foo - &&foo, &&bar - &&foo,
404 &&hack - &&foo @};
405goto *(&&foo + array[i]);
406@end smallexample
407
408@noindent
409This is more friendly to code living in shared libraries, as it reduces
410the number of dynamic relocations that are needed, and by consequence,
411allows the data to be read-only.
412This alternative with label differences is not supported for the AVR target,
413please use the first approach for AVR programs.
414
415The @code{&&foo} expressions for the same label might have different
416values if the containing function is inlined or cloned. If a program
417relies on them being always the same,
418@code{__attribute__((__noinline__,__noclone__))} should be used to
419prevent inlining and cloning. If @code{&&foo} is used in a static
420variable initializer, inlining and cloning is forbidden.
421
4d9e0f3f
JM
422Unlike a normal goto, in GNU C++ a computed goto will not call
423destructors for objects that go out of scope.
424
d77de738
ML
425@node Nested Functions
426@section Nested Functions
427@cindex nested functions
428@cindex downward funargs
429@cindex thunks
430
431A @dfn{nested function} is a function defined inside another function.
432Nested functions are supported as an extension in GNU C, but are not
433supported by GNU C++.
434
435The nested function's name is local to the block where it is defined.
436For example, here we define a nested function named @code{square}, and
437call it twice:
438
439@smallexample
440@group
441foo (double a, double b)
442@{
443 double square (double z) @{ return z * z; @}
444
445 return square (a) + square (b);
446@}
447@end group
448@end smallexample
449
450The nested function can access all the variables of the containing
451function that are visible at the point of its definition. This is
452called @dfn{lexical scoping}. For example, here we show a nested
453function which uses an inherited variable named @code{offset}:
454
455@smallexample
456@group
457bar (int *array, int offset, int size)
458@{
459 int access (int *array, int index)
460 @{ return array[index + offset]; @}
461 int i;
462 /* @r{@dots{}} */
463 for (i = 0; i < size; i++)
464 /* @r{@dots{}} */ access (array, i) /* @r{@dots{}} */
465@}
466@end group
467@end smallexample
468
469Nested function definitions are permitted within functions in the places
470where variable definitions are allowed; that is, in any block, mixed
471with the other declarations and statements in the block.
472
473It is possible to call the nested function from outside the scope of its
474name by storing its address or passing the address to another function:
475
476@smallexample
477hack (int *array, int size)
478@{
479 void store (int index, int value)
480 @{ array[index] = value; @}
481
482 intermediate (store, size);
483@}
484@end smallexample
485
486Here, the function @code{intermediate} receives the address of
487@code{store} as an argument. If @code{intermediate} calls @code{store},
488the arguments given to @code{store} are used to store into @code{array}.
489But this technique works only so long as the containing function
490(@code{hack}, in this example) does not exit.
491
492If you try to call the nested function through its address after the
493containing function exits, all hell breaks loose. If you try
494to call it after a containing scope level exits, and if it refers
495to some of the variables that are no longer in scope, you may be lucky,
496but it's not wise to take the risk. If, however, the nested function
497does not refer to anything that has gone out of scope, you should be
498safe.
499
500GCC implements taking the address of a nested function using a technique
501called @dfn{trampolines}. This technique was described in
502@cite{Lexical Closures for C++} (Thomas M. Breuel, USENIX
503C++ Conference Proceedings, October 17-21, 1988).
504
505A nested function can jump to a label inherited from a containing
506function, provided the label is explicitly declared in the containing
507function (@pxref{Local Labels}). Such a jump returns instantly to the
508containing function, exiting the nested function that did the
509@code{goto} and any intermediate functions as well. Here is an example:
510
511@smallexample
512@group
513bar (int *array, int offset, int size)
514@{
515 __label__ failure;
516 int access (int *array, int index)
517 @{
518 if (index > size)
519 goto failure;
520 return array[index + offset];
521 @}
522 int i;
523 /* @r{@dots{}} */
524 for (i = 0; i < size; i++)
525 /* @r{@dots{}} */ access (array, i) /* @r{@dots{}} */
526 /* @r{@dots{}} */
527 return 0;
528
529 /* @r{Control comes here from @code{access}
530 if it detects an error.} */
531 failure:
532 return -1;
533@}
534@end group
535@end smallexample
536
537A nested function always has no linkage. Declaring one with
538@code{extern} or @code{static} is erroneous. If you need to declare the nested function
539before its definition, use @code{auto} (which is otherwise meaningless
540for function declarations).
541
542@smallexample
543bar (int *array, int offset, int size)
544@{
545 __label__ failure;
546 auto int access (int *, int);
547 /* @r{@dots{}} */
548 int access (int *array, int index)
549 @{
550 if (index > size)
551 goto failure;
552 return array[index + offset];
553 @}
554 /* @r{@dots{}} */
555@}
556@end smallexample
557
558@node Nonlocal Gotos
559@section Nonlocal Gotos
560@cindex nonlocal gotos
561
562GCC provides the built-in functions @code{__builtin_setjmp} and
563@code{__builtin_longjmp} which are similar to, but not interchangeable
564with, the C library functions @code{setjmp} and @code{longjmp}.
565The built-in versions are used internally by GCC's libraries
566to implement exception handling on some targets. You should use the
567standard C library functions declared in @code{<setjmp.h>} in user code
568instead of the builtins.
569
570The built-in versions of these functions use GCC's normal
571mechanisms to save and restore registers using the stack on function
572entry and exit. The jump buffer argument @var{buf} holds only the
573information needed to restore the stack frame, rather than the entire
574set of saved register values.
575
576An important caveat is that GCC arranges to save and restore only
577those registers known to the specific architecture variant being
578compiled for. This can make @code{__builtin_setjmp} and
579@code{__builtin_longjmp} more efficient than their library
580counterparts in some cases, but it can also cause incorrect and
581mysterious behavior when mixing with code that uses the full register
582set.
583
584You should declare the jump buffer argument @var{buf} to the
585built-in functions as:
586
587@smallexample
588#include <stdint.h>
589intptr_t @var{buf}[5];
590@end smallexample
591
f25efe50 592@defbuiltin{{int} __builtin_setjmp (intptr_t *@var{buf})}
d77de738
ML
593This function saves the current stack context in @var{buf}.
594@code{__builtin_setjmp} returns 0 when returning directly,
595and 1 when returning from @code{__builtin_longjmp} using the same
596@var{buf}.
f25efe50 597@enddefbuiltin
d77de738 598
f25efe50 599@defbuiltin{{void} __builtin_longjmp (intptr_t *@var{buf}, int @var{val})}
d77de738
ML
600This function restores the stack context in @var{buf},
601saved by a previous call to @code{__builtin_setjmp}. After
602@code{__builtin_longjmp} is finished, the program resumes execution as
603if the matching @code{__builtin_setjmp} returns the value @var{val},
604which must be 1.
605
606Because @code{__builtin_longjmp} depends on the function return
607mechanism to restore the stack context, it cannot be called
608from the same function calling @code{__builtin_setjmp} to
609initialize @var{buf}. It can only be called from a function called
610(directly or indirectly) from the function calling @code{__builtin_setjmp}.
f25efe50 611@enddefbuiltin
d77de738
ML
612
613@node Constructing Calls
614@section Constructing Function Calls
615@cindex constructing calls
616@cindex forwarding calls
617
618Using the built-in functions described below, you can record
619the arguments a function received, and call another function
620with the same arguments, without knowing the number or types
621of the arguments.
622
623You can also record the return value of that function call,
624and later return that value, without knowing what data type
625the function tried to return (as long as your caller expects
626that data type).
627
628However, these built-in functions may interact badly with some
629sophisticated features or other extensions of the language. It
630is, therefore, not recommended to use them outside very simple
631functions acting as mere forwarders for their arguments.
632
f25efe50 633@defbuiltin{{void *} __builtin_apply_args ()}
d77de738
ML
634This built-in function returns a pointer to data
635describing how to perform a call with the same arguments as are passed
636to the current function.
637
638The function saves the arg pointer register, structure value address,
639and all registers that might be used to pass arguments to a function
640into a block of memory allocated on the stack. Then it returns the
641address of that block.
f25efe50 642@enddefbuiltin
d77de738 643
f25efe50 644@defbuiltin{{void *} __builtin_apply (void (*@var{function})(), void *@var{arguments}, size_t @var{size})}
d77de738
ML
645This built-in function invokes @var{function}
646with a copy of the parameters described by @var{arguments}
647and @var{size}.
648
649The value of @var{arguments} should be the value returned by
650@code{__builtin_apply_args}. The argument @var{size} specifies the size
651of the stack argument data, in bytes.
652
653This function returns a pointer to data describing
654how to return whatever value is returned by @var{function}. The data
655is saved in a block of memory allocated on the stack.
656
657It is not always simple to compute the proper value for @var{size}. The
658value is used by @code{__builtin_apply} to compute the amount of data
659that should be pushed on the stack and copied from the incoming argument
660area.
f25efe50 661@enddefbuiltin
d77de738 662
f25efe50 663@defbuiltin{{void} __builtin_return (void *@var{result})}
d77de738
ML
664This built-in function returns the value described by @var{result} from
665the containing function. You should specify, for @var{result}, a value
666returned by @code{__builtin_apply}.
f25efe50 667@enddefbuiltin
d77de738 668
f25efe50 669@defbuiltin{{} __builtin_va_arg_pack ()}
d77de738
ML
670This built-in function represents all anonymous arguments of an inline
671function. It can be used only in inline functions that are always
672inlined, never compiled as a separate function, such as those using
673@code{__attribute__ ((__always_inline__))} or
674@code{__attribute__ ((__gnu_inline__))} extern inline functions.
675It must be only passed as last argument to some other function
676with variable arguments. This is useful for writing small wrapper
677inlines for variable argument functions, when using preprocessor
678macros is undesirable. For example:
679@smallexample
680extern int myprintf (FILE *f, const char *format, ...);
681extern inline __attribute__ ((__gnu_inline__)) int
682myprintf (FILE *f, const char *format, ...)
683@{
684 int r = fprintf (f, "myprintf: ");
685 if (r < 0)
686 return r;
687 int s = fprintf (f, format, __builtin_va_arg_pack ());
688 if (s < 0)
689 return s;
690 return r + s;
691@}
692@end smallexample
f25efe50 693@enddefbuiltin
d77de738 694
f25efe50 695@defbuiltin{int __builtin_va_arg_pack_len ()}
d77de738
ML
696This built-in function returns the number of anonymous arguments of
697an inline function. It can be used only in inline functions that
698are always inlined, never compiled as a separate function, such
699as those using @code{__attribute__ ((__always_inline__))} or
700@code{__attribute__ ((__gnu_inline__))} extern inline functions.
701For example following does link- or run-time checking of open
702arguments for optimized code:
703@smallexample
704#ifdef __OPTIMIZE__
705extern inline __attribute__((__gnu_inline__)) int
706myopen (const char *path, int oflag, ...)
707@{
708 if (__builtin_va_arg_pack_len () > 1)
709 warn_open_too_many_arguments ();
710
711 if (__builtin_constant_p (oflag))
712 @{
713 if ((oflag & O_CREAT) != 0 && __builtin_va_arg_pack_len () < 1)
714 @{
715 warn_open_missing_mode ();
716 return __open_2 (path, oflag);
717 @}
718 return open (path, oflag, __builtin_va_arg_pack ());
719 @}
720
721 if (__builtin_va_arg_pack_len () < 1)
722 return __open_2 (path, oflag);
723
724 return open (path, oflag, __builtin_va_arg_pack ());
725@}
726#endif
727@end smallexample
f25efe50 728@enddefbuiltin
d77de738
ML
729
730@node Typeof
731@section Referring to a Type with @code{typeof}
732@findex typeof
733@findex sizeof
734@cindex macros, types of arguments
735
736Another way to refer to the type of an expression is with @code{typeof}.
737The syntax of using of this keyword looks like @code{sizeof}, but the
738construct acts semantically like a type name defined with @code{typedef}.
739
740There are two ways of writing the argument to @code{typeof}: with an
741expression or with a type. Here is an example with an expression:
742
743@smallexample
744typeof (x[0](1))
745@end smallexample
746
747@noindent
748This assumes that @code{x} is an array of pointers to functions;
749the type described is that of the values of the functions.
750
751Here is an example with a typename as the argument:
752
753@smallexample
754typeof (int *)
755@end smallexample
756
757@noindent
758Here the type described is that of pointers to @code{int}.
759
760If you are writing a header file that must work when included in ISO C
761programs, write @code{__typeof__} instead of @code{typeof}.
762@xref{Alternate Keywords}.
763
764A @code{typeof} construct can be used anywhere a typedef name can be
765used. For example, you can use it in a declaration, in a cast, or inside
766of @code{sizeof} or @code{typeof}.
767
768The operand of @code{typeof} is evaluated for its side effects if and
769only if it is an expression of variably modified type or the name of
770such a type.
771
772@code{typeof} is often useful in conjunction with
773statement expressions (@pxref{Statement Exprs}).
774Here is how the two together can
775be used to define a safe ``maximum'' macro which operates on any
776arithmetic type and evaluates each of its arguments exactly once:
777
778@smallexample
779#define max(a,b) \
780 (@{ typeof (a) _a = (a); \
781 typeof (b) _b = (b); \
782 _a > _b ? _a : _b; @})
783@end smallexample
784
785@cindex underscores in variables in macros
786@cindex @samp{_} in variables in macros
787@cindex local variables in macros
788@cindex variables, local, in macros
789@cindex macros, local variables in
790
791The reason for using names that start with underscores for the local
792variables is to avoid conflicts with variable names that occur within the
793expressions that are substituted for @code{a} and @code{b}. Eventually we
794hope to design a new form of declaration syntax that allows you to declare
795variables whose scopes start only after their initializers; this will be a
796more reliable way to prevent such conflicts.
797
798@noindent
799Some more examples of the use of @code{typeof}:
800
801@itemize @bullet
802@item
803This declares @code{y} with the type of what @code{x} points to.
804
805@smallexample
806typeof (*x) y;
807@end smallexample
808
809@item
810This declares @code{y} as an array of such values.
811
812@smallexample
813typeof (*x) y[4];
814@end smallexample
815
816@item
817This declares @code{y} as an array of pointers to characters:
818
819@smallexample
820typeof (typeof (char *)[4]) y;
821@end smallexample
822
823@noindent
824It is equivalent to the following traditional C declaration:
825
826@smallexample
827char *y[4];
828@end smallexample
829
830To see the meaning of the declaration using @code{typeof}, and why it
831might be a useful way to write, rewrite it with these macros:
832
833@smallexample
834#define pointer(T) typeof(T *)
835#define array(T, N) typeof(T [N])
836@end smallexample
837
838@noindent
839Now the declaration can be rewritten this way:
840
841@smallexample
842array (pointer (char), 4) y;
843@end smallexample
844
845@noindent
846Thus, @code{array (pointer (char), 4)} is the type of arrays of 4
847pointers to @code{char}.
848@end itemize
849
094a609c 850The ISO C23 operator @code{typeof_unqual} is available in ISO C23 mode
607d9d50
JJ
851and its result is the non-atomic unqualified version of what @code{typeof}
852operator returns. Alternate spelling @code{__typeof_unqual__} is
853available in all C modes and provides non-atomic unqualified version of
854what @code{__typeof__} operator returns.
855@xref{Alternate Keywords}.
856
790fef14 857@cindex @code{__auto_type} in GNU C
d77de738
ML
858In GNU C, but not GNU C++, you may also declare the type of a variable
859as @code{__auto_type}. In that case, the declaration must declare
860only one variable, whose declarator must just be an identifier, the
861declaration must be initialized, and the type of the variable is
862determined by the initializer; the name of the variable is not in
863scope until after the initializer. (In C++, you should use C++11
864@code{auto} for this purpose.) Using @code{__auto_type}, the
865``maximum'' macro above could be written as:
866
867@smallexample
868#define max(a,b) \
869 (@{ __auto_type _a = (a); \
870 __auto_type _b = (b); \
871 _a > _b ? _a : _b; @})
872@end smallexample
873
874Using @code{__auto_type} instead of @code{typeof} has two advantages:
875
876@itemize @bullet
877@item Each argument to the macro appears only once in the expansion of
878the macro. This prevents the size of the macro expansion growing
879exponentially when calls to such macros are nested inside arguments of
880such macros.
881
882@item If the argument to the macro has variably modified type, it is
883evaluated only once when using @code{__auto_type}, but twice if
884@code{typeof} is used.
885@end itemize
886
887@node Conditionals
888@section Conditionals with Omitted Operands
889@cindex conditional expressions, extensions
890@cindex omitted middle-operands
891@cindex middle-operands, omitted
892@cindex extensions, @code{?:}
893@cindex @code{?:} extensions
894
895The middle operand in a conditional expression may be omitted. Then
896if the first operand is nonzero, its value is the value of the conditional
897expression.
898
899Therefore, the expression
900
901@smallexample
902x ? : y
903@end smallexample
904
905@noindent
906has the value of @code{x} if that is nonzero; otherwise, the value of
907@code{y}.
908
909This example is perfectly equivalent to
910
911@smallexample
912x ? x : y
913@end smallexample
914
915@cindex side effect in @code{?:}
916@cindex @code{?:} side effect
917@noindent
918In this simple case, the ability to omit the middle operand is not
919especially useful. When it becomes useful is when the first operand does,
920or may (if it is a macro argument), contain a side effect. Then repeating
921the operand in the middle would perform the side effect twice. Omitting
922the middle operand uses the value already computed without the undesirable
923effects of recomputing it.
924
925@node __int128
926@section 128-bit Integers
927@cindex @code{__int128} data types
928
929As an extension the integer scalar type @code{__int128} is supported for
930targets which have an integer mode wide enough to hold 128 bits.
931Simply write @code{__int128} for a signed 128-bit integer, or
932@code{unsigned __int128} for an unsigned 128-bit integer. There is no
933support in GCC for expressing an integer constant of type @code{__int128}
934for targets with @code{long long} integer less than 128 bits wide.
935
936@node Long Long
937@section Double-Word Integers
938@cindex @code{long long} data types
939@cindex double-word arithmetic
940@cindex multiprecision arithmetic
941@cindex @code{LL} integer suffix
942@cindex @code{ULL} integer suffix
943
944ISO C99 and ISO C++11 support data types for integers that are at least
94564 bits wide, and as an extension GCC supports them in C90 and C++98 modes.
946Simply write @code{long long int} for a signed integer, or
947@code{unsigned long long int} for an unsigned integer. To make an
948integer constant of type @code{long long int}, add the suffix @samp{LL}
949to the integer. To make an integer constant of type @code{unsigned long
950long int}, add the suffix @samp{ULL} to the integer.
951
952You can use these types in arithmetic like any other integer types.
953Addition, subtraction, and bitwise boolean operations on these types
954are open-coded on all types of machines. Multiplication is open-coded
955if the machine supports a fullword-to-doubleword widening multiply
956instruction. Division and shifts are open-coded only on machines that
957provide special support. The operations that are not open-coded use
958special library routines that come with GCC@.
959
960There may be pitfalls when you use @code{long long} types for function
961arguments without function prototypes. If a function
962expects type @code{int} for its argument, and you pass a value of type
963@code{long long int}, confusion results because the caller and the
964subroutine disagree about the number of bytes for the argument.
965Likewise, if the function expects @code{long long int} and you pass
966@code{int}. The best way to avoid such problems is to use prototypes.
967
968@node Complex
969@section Complex Numbers
970@cindex complex numbers
971@cindex @code{_Complex} keyword
972@cindex @code{__complex__} keyword
973
974ISO C99 supports complex floating data types, and as an extension GCC
975supports them in C90 mode and in C++. GCC also supports complex integer data
976types which are not part of ISO C99. You can declare complex types
977using the keyword @code{_Complex}. As an extension, the older GNU
978keyword @code{__complex__} is also supported.
979
980For example, @samp{_Complex double x;} declares @code{x} as a
981variable whose real part and imaginary part are both of type
982@code{double}. @samp{_Complex short int y;} declares @code{y} to
983have real and imaginary parts of type @code{short int}; this is not
984likely to be useful, but it shows that the set of complex types is
985complete.
986
987To write a constant with a complex data type, use the suffix @samp{i} or
988@samp{j} (either one; they are equivalent). For example, @code{2.5fi}
989has type @code{_Complex float} and @code{3i} has type
990@code{_Complex int}. Such a constant always has a pure imaginary
991value, but you can form any complex value you like by adding one to a
992real constant. This is a GNU extension; if you have an ISO C99
993conforming C library (such as the GNU C Library), and want to construct complex
994constants of floating type, you should include @code{<complex.h>} and
995use the macros @code{I} or @code{_Complex_I} instead.
996
997The ISO C++14 library also defines the @samp{i} suffix, so C++14 code
998that includes the @samp{<complex>} header cannot use @samp{i} for the
999GNU extension. The @samp{j} suffix still has the GNU meaning.
1000
1001GCC can handle both implicit and explicit casts between the @code{_Complex}
1002types and other @code{_Complex} types as casting both the real and imaginary
1003parts to the scalar type.
1004GCC can handle implicit and explicit casts from a scalar type to a @code{_Complex}
1005type and where the imaginary part will be considered zero.
1006The C front-end can handle implicit and explicit casts from a @code{_Complex} type
1007to a scalar type where the imaginary part will be ignored. In C++ code, this cast
1008is considered illformed and G++ will error out.
1009
1010GCC provides a built-in function @code{__builtin_complex} will can be used to
1011construct a complex value.
1012
1013@cindex @code{__real__} keyword
1014@cindex @code{__imag__} keyword
1015
1016GCC has a few extensions which can be used to extract the real
1017and the imaginary part of the complex-valued expression. Note
1018these expressions are lvalues if the @var{exp} is an lvalue.
1019These expressions operands have the type of a complex type
1020which might get prompoted to a complex type from a scalar type.
1021E.g. @code{__real__ (int)@var{x}} is the same as casting to
1022@code{_Complex int} before @code{__real__} is done.
1023
1024@multitable @columnfractions .4 .6
1025@headitem Expression @tab Description
1026@item @code{__real__ @var{exp}}
1027@tab Extract the real part of @var{exp}.
1028@item @code{__imag__ @var{exp}}
1029@tab Extract the imaginary part of @var{exp}.
1030@end multitable
1031
1032For values of floating point, you should use the ISO C99
1033functions, declared in @code{<complex.h>} and also provided as
1034built-in functions by GCC@.
1035
1036@multitable @columnfractions .4 .2 .2 .2
1037@headitem Expression @tab float @tab double @tab long double
1038@item @code{__real__ @var{exp}}
1039@tab @code{crealf} @tab @code{creal} @tab @code{creall}
1040@item @code{__imag__ @var{exp}}
1041@tab @code{cimagf} @tab @code{cimag} @tab @code{cimagl}
1042@end multitable
1043
1044@cindex complex conjugation
1045The operator @samp{~} performs complex conjugation when used on a value
1046with a complex type. This is a GNU extension; for values of
1047floating type, you should use the ISO C99 functions @code{conjf},
1048@code{conj} and @code{conjl}, declared in @code{<complex.h>} and also
1049provided as built-in functions by GCC@. Note unlike the @code{__real__}
1050and @code{__imag__} operators, this operator will not do an implicit cast
1051to the complex type because the @samp{~} is already a normal operator.
1052
1053GCC can allocate complex automatic variables in a noncontiguous
1054fashion; it's even possible for the real part to be in a register while
1055the imaginary part is on the stack (or vice versa). Only the DWARF
1056debug info format can represent this, so use of DWARF is recommended.
1057If you are using the stabs debug info format, GCC describes a noncontiguous
1058complex variable as if it were two separate variables of noncomplex type.
1059If the variable's actual name is @code{foo}, the two fictitious
1060variables are named @code{foo$real} and @code{foo$imag}. You can
1061examine and set these two fictitious variables with your debugger.
1062
f25efe50 1063@defbuiltin{@var{type} __builtin_complex (@var{real}, @var{imag})}
d77de738
ML
1064
1065The built-in function @code{__builtin_complex} is provided for use in
1066implementing the ISO C11 macros @code{CMPLXF}, @code{CMPLX} and
1067@code{CMPLXL}. @var{real} and @var{imag} must have the same type, a
1068real binary floating-point type, and the result has the corresponding
1069complex type with real and imaginary parts @var{real} and @var{imag}.
1070Unlike @samp{@var{real} + I * @var{imag}}, this works even when
1071infinities, NaNs and negative zeros are involved.
1072
f25efe50 1073@enddefbuiltin
d77de738
ML
1074
1075@node Floating Types
1076@section Additional Floating Types
1077@cindex additional floating types
1078@cindex @code{_Float@var{n}} data types
1079@cindex @code{_Float@var{n}x} data types
1080@cindex @code{__float80} data type
1081@cindex @code{__float128} data type
1082@cindex @code{__ibm128} data type
1083@cindex @code{w} floating point suffix
1084@cindex @code{q} floating point suffix
1085@cindex @code{W} floating point suffix
1086@cindex @code{Q} floating point suffix
1087
1088ISO/IEC TS 18661-3:2015 defines C support for additional floating
1089types @code{_Float@var{n}} and @code{_Float@var{n}x}, and GCC supports
1090these type names; the set of types supported depends on the target
145da6a8 1091architecture.
d77de738
ML
1092Constants with these types use suffixes @code{f@var{n}} or
1093@code{F@var{n}} and @code{f@var{n}x} or @code{F@var{n}x}. These type
1094names can be used together with @code{_Complex} to declare complex
1095types.
1096
1097As an extension, GNU C and GNU C++ support additional floating
1098types, which are not supported by all targets.
1099@itemize @bullet
4e2d53c9 1100@item @code{__float128} is available on i386, x86_64, IA-64, LoongArch
1101and hppa HP-UX, as well as on PowerPC GNU/Linux targets that enable
d77de738 1102the vector scalar (VSX) instruction set. @code{__float128} supports
4e2d53c9 1103the 128-bit floating type. On i386, x86_64, PowerPC, LoongArch and IA-64,
d77de738
ML
1104other than HP-UX, @code{__float128} is an alias for @code{_Float128}.
1105On hppa and IA-64 HP-UX, @code{__float128} is an alias for @code{long
1106double}.
1107
1108@item @code{__float80} is available on the i386, x86_64, and IA-64
1109targets, and supports the 80-bit (@code{XFmode}) floating type. It is
1110an alias for the type name @code{_Float64x} on these targets.
1111
1112@item @code{__ibm128} is available on PowerPC targets, and provides
1113access to the IBM extended double format which is the current format
1114used for @code{long double}. When @code{long double} transitions to
1115@code{__float128} on PowerPC in the future, @code{__ibm128} will remain
1116for use in conversions between the two types.
1117@end itemize
1118
1119Support for these additional types includes the arithmetic operators:
1120add, subtract, multiply, divide; unary arithmetic operators;
1121relational operators; equality operators; and conversions to and from
1122integer and other floating types. Use a suffix @samp{w} or @samp{W}
1123in a literal constant of type @code{__float80} or type
1124@code{__ibm128}. Use a suffix @samp{q} or @samp{Q} for @code{__float128}.
1125
1126In order to use @code{_Float128}, @code{__float128}, and @code{__ibm128}
1127on PowerPC Linux systems, you must use the @option{-mfloat128} option. It is
1128expected in future versions of GCC that @code{_Float128} and @code{__float128}
1129will be enabled automatically.
1130
1131The @code{_Float128} type is supported on all systems where
1132@code{__float128} is supported or where @code{long double} has the
1133IEEE binary128 format. The @code{_Float64x} type is supported on all
1134systems where @code{__float128} is supported. The @code{_Float32}
1135type is supported on all systems supporting IEEE binary32; the
1136@code{_Float64} and @code{_Float32x} types are supported on all systems
1137supporting IEEE binary64. The @code{_Float16} type is supported on AArch64
1138systems by default, on ARM systems when the IEEE format for 16-bit
1139floating-point types is selected with @option{-mfp16-format=ieee} and,
1140for both C and C++, on x86 systems with SSE2 enabled. GCC does not currently
1141support @code{_Float128x} on any systems.
1142
1143On the i386, x86_64, IA-64, and HP-UX targets, you can declare complex
1144types using the corresponding internal complex type, @code{XCmode} for
1145@code{__float80} type and @code{TCmode} for @code{__float128} type:
1146
1147@smallexample
1148typedef _Complex float __attribute__((mode(TC))) _Complex128;
1149typedef _Complex float __attribute__((mode(XC))) _Complex80;
1150@end smallexample
1151
1152On the PowerPC Linux VSX targets, you can declare complex types using
1153the corresponding internal complex type, @code{KCmode} for
1154@code{__float128} type and @code{ICmode} for @code{__ibm128} type:
1155
1156@smallexample
1157typedef _Complex float __attribute__((mode(KC))) _Complex_float128;
1158typedef _Complex float __attribute__((mode(IC))) _Complex_ibm128;
1159@end smallexample
1160
1161@node Half-Precision
1162@section Half-Precision Floating Point
1163@cindex half-precision floating point
1164@cindex @code{__fp16} data type
1165@cindex @code{__Float16} data type
1166
1167On ARM and AArch64 targets, GCC supports half-precision (16-bit) floating
1168point via the @code{__fp16} type defined in the ARM C Language Extensions.
1169On ARM systems, you must enable this type explicitly with the
1170@option{-mfp16-format} command-line option in order to use it.
1171On x86 targets with SSE2 enabled, GCC supports half-precision (16-bit)
1172floating point via the @code{_Float16} type. For C++, x86 provides a builtin
1173type named @code{_Float16} which contains same data format as C.
1174
1175ARM targets support two incompatible representations for half-precision
1176floating-point values. You must choose one of the representations and
1177use it consistently in your program.
1178
1179Specifying @option{-mfp16-format=ieee} selects the IEEE 754-2008 format.
1180This format can represent normalized values in the range of @math{2^{-14}} to 65504.
1181There are 11 bits of significand precision, approximately 3
1182decimal digits.
1183
1184Specifying @option{-mfp16-format=alternative} selects the ARM
1185alternative format. This representation is similar to the IEEE
1186format, but does not support infinities or NaNs. Instead, the range
1187of exponents is extended, so that this format can represent normalized
1188values in the range of @math{2^{-14}} to 131008.
1189
1190The GCC port for AArch64 only supports the IEEE 754-2008 format, and does
1191not require use of the @option{-mfp16-format} command-line option.
1192
1193The @code{__fp16} type may only be used as an argument to intrinsics defined
1194in @code{<arm_fp16.h>}, or as a storage format. For purposes of
1195arithmetic and other operations, @code{__fp16} values in C or C++
1196expressions are automatically promoted to @code{float}.
1197
1198The ARM target provides hardware support for conversions between
1199@code{__fp16} and @code{float} values
1200as an extension to VFP and NEON (Advanced SIMD), and from ARMv8-A provides
1201hardware support for conversions between @code{__fp16} and @code{double}
1202values. GCC generates code using these hardware instructions if you
1203compile with options to select an FPU that provides them;
1204for example, @option{-mfpu=neon-fp16 -mfloat-abi=softfp},
1205in addition to the @option{-mfp16-format} option to select
1206a half-precision format.
1207
1208Language-level support for the @code{__fp16} data type is
1209independent of whether GCC generates code using hardware floating-point
1210instructions. In cases where hardware support is not specified, GCC
1211implements conversions between @code{__fp16} and other types as library
1212calls.
1213
1214It is recommended that portable code use the @code{_Float16} type defined
1215by ISO/IEC TS 18661-3:2015. @xref{Floating Types}.
1216
1217On x86 targets with SSE2 enabled, without @option{-mavx512fp16},
1218all operations will be emulated by software emulation and the @code{float}
1219instructions. The default behavior for @code{FLT_EVAL_METHOD} is to keep the
1220intermediate result of the operation as 32-bit precision. This may lead to
1221inconsistent behavior between software emulation and AVX512-FP16 instructions.
1222Using @option{-fexcess-precision=16} will force round back after each operation.
1223
1224Using @option{-mavx512fp16} will generate AVX512-FP16 instructions instead of
1225software emulation. The default behavior of @code{FLT_EVAL_METHOD} is to round
1226after each operation. The same is true with @option{-fexcess-precision=standard}
1227and @option{-mfpmath=sse}. If there is no @option{-mfpmath=sse},
1228@option{-fexcess-precision=standard} alone does the same thing as before,
1229It is useful for code that does not have @code{_Float16} and runs on the x87
1230FPU.
1231
1232@node Decimal Float
1233@section Decimal Floating Types
1234@cindex decimal floating types
1235@cindex @code{_Decimal32} data type
1236@cindex @code{_Decimal64} data type
1237@cindex @code{_Decimal128} data type
1238@cindex @code{df} integer suffix
1239@cindex @code{dd} integer suffix
1240@cindex @code{dl} integer suffix
1241@cindex @code{DF} integer suffix
1242@cindex @code{DD} integer suffix
1243@cindex @code{DL} integer suffix
1244
1245As an extension, GNU C supports decimal floating types as
1246defined in the N1312 draft of ISO/IEC WDTR24732. Support for decimal
1247floating types in GCC will evolve as the draft technical report changes.
1248Calling conventions for any target might also change. Not all targets
1249support decimal floating types.
1250
1251The decimal floating types are @code{_Decimal32}, @code{_Decimal64}, and
1252@code{_Decimal128}. They use a radix of ten, unlike the floating types
1253@code{float}, @code{double}, and @code{long double} whose radix is not
1254specified by the C standard but is usually two.
1255
1256Support for decimal floating types includes the arithmetic operators
1257add, subtract, multiply, divide; unary arithmetic operators;
1258relational operators; equality operators; and conversions to and from
1259integer and other floating types. Use a suffix @samp{df} or
1260@samp{DF} in a literal constant of type @code{_Decimal32}, @samp{dd}
1261or @samp{DD} for @code{_Decimal64}, and @samp{dl} or @samp{DL} for
1262@code{_Decimal128}.
1263
1264GCC support of decimal float as specified by the draft technical report
1265is incomplete:
1266
1267@itemize @bullet
1268@item
1269When the value of a decimal floating type cannot be represented in the
1270integer type to which it is being converted, the result is undefined
1271rather than the result value specified by the draft technical report.
1272
1273@item
1274GCC does not provide the C library functionality associated with
1275@file{math.h}, @file{fenv.h}, @file{stdio.h}, @file{stdlib.h}, and
1276@file{wchar.h}, which must come from a separate C library implementation.
1277Because of this the GNU C compiler does not define macro
1278@code{__STDC_DEC_FP__} to indicate that the implementation conforms to
1279the technical report.
1280@end itemize
1281
1282Types @code{_Decimal32}, @code{_Decimal64}, and @code{_Decimal128}
1283are supported by the DWARF debug information format.
1284
1285@node Hex Floats
1286@section Hex Floats
1287@cindex hex floats
1288
1289ISO C99 and ISO C++17 support floating-point numbers written not only in
1290the usual decimal notation, such as @code{1.55e1}, but also numbers such as
1291@code{0x1.fp3} written in hexadecimal format. As a GNU extension, GCC
1292supports this in C90 mode (except in some cases when strictly
1293conforming) and in C++98, C++11 and C++14 modes. In that format the
1294@samp{0x} hex introducer and the @samp{p} or @samp{P} exponent field are
1295mandatory. The exponent is a decimal number that indicates the power of
12962 by which the significant part is multiplied. Thus @samp{0x1.f} is
1297@tex
1298$1 {15\over16}$,
1299@end tex
1300@ifnottex
13011 15/16,
1302@end ifnottex
1303@samp{p3} multiplies it by 8, and the value of @code{0x1.fp3}
1304is the same as @code{1.55e1}.
1305
1306Unlike for floating-point numbers in the decimal notation the exponent
1307is always required in the hexadecimal notation. Otherwise the compiler
1308would not be able to resolve the ambiguity of, e.g., @code{0x1.f}. This
1309could mean @code{1.0f} or @code{1.9375} since @samp{f} is also the
1310extension for floating-point constants of type @code{float}.
1311
1312@node Fixed-Point
1313@section Fixed-Point Types
1314@cindex fixed-point types
1315@cindex @code{_Fract} data type
1316@cindex @code{_Accum} data type
1317@cindex @code{_Sat} data type
1318@cindex @code{hr} fixed-suffix
1319@cindex @code{r} fixed-suffix
1320@cindex @code{lr} fixed-suffix
1321@cindex @code{llr} fixed-suffix
1322@cindex @code{uhr} fixed-suffix
1323@cindex @code{ur} fixed-suffix
1324@cindex @code{ulr} fixed-suffix
1325@cindex @code{ullr} fixed-suffix
1326@cindex @code{hk} fixed-suffix
1327@cindex @code{k} fixed-suffix
1328@cindex @code{lk} fixed-suffix
1329@cindex @code{llk} fixed-suffix
1330@cindex @code{uhk} fixed-suffix
1331@cindex @code{uk} fixed-suffix
1332@cindex @code{ulk} fixed-suffix
1333@cindex @code{ullk} fixed-suffix
1334@cindex @code{HR} fixed-suffix
1335@cindex @code{R} fixed-suffix
1336@cindex @code{LR} fixed-suffix
1337@cindex @code{LLR} fixed-suffix
1338@cindex @code{UHR} fixed-suffix
1339@cindex @code{UR} fixed-suffix
1340@cindex @code{ULR} fixed-suffix
1341@cindex @code{ULLR} fixed-suffix
1342@cindex @code{HK} fixed-suffix
1343@cindex @code{K} fixed-suffix
1344@cindex @code{LK} fixed-suffix
1345@cindex @code{LLK} fixed-suffix
1346@cindex @code{UHK} fixed-suffix
1347@cindex @code{UK} fixed-suffix
1348@cindex @code{ULK} fixed-suffix
1349@cindex @code{ULLK} fixed-suffix
1350
1351As an extension, GNU C supports fixed-point types as
1352defined in the N1169 draft of ISO/IEC DTR 18037. Support for fixed-point
1353types in GCC will evolve as the draft technical report changes.
1354Calling conventions for any target might also change. Not all targets
1355support fixed-point types.
1356
1357The fixed-point types are
1358@code{short _Fract},
1359@code{_Fract},
1360@code{long _Fract},
1361@code{long long _Fract},
1362@code{unsigned short _Fract},
1363@code{unsigned _Fract},
1364@code{unsigned long _Fract},
1365@code{unsigned long long _Fract},
1366@code{_Sat short _Fract},
1367@code{_Sat _Fract},
1368@code{_Sat long _Fract},
1369@code{_Sat long long _Fract},
1370@code{_Sat unsigned short _Fract},
1371@code{_Sat unsigned _Fract},
1372@code{_Sat unsigned long _Fract},
1373@code{_Sat unsigned long long _Fract},
1374@code{short _Accum},
1375@code{_Accum},
1376@code{long _Accum},
1377@code{long long _Accum},
1378@code{unsigned short _Accum},
1379@code{unsigned _Accum},
1380@code{unsigned long _Accum},
1381@code{unsigned long long _Accum},
1382@code{_Sat short _Accum},
1383@code{_Sat _Accum},
1384@code{_Sat long _Accum},
1385@code{_Sat long long _Accum},
1386@code{_Sat unsigned short _Accum},
1387@code{_Sat unsigned _Accum},
1388@code{_Sat unsigned long _Accum},
1389@code{_Sat unsigned long long _Accum}.
1390
1391Fixed-point data values contain fractional and optional integral parts.
1392The format of fixed-point data varies and depends on the target machine.
1393
1394Support for fixed-point types includes:
1395@itemize @bullet
1396@item
1397prefix and postfix increment and decrement operators (@code{++}, @code{--})
1398@item
1399unary arithmetic operators (@code{+}, @code{-}, @code{!})
1400@item
1401binary arithmetic operators (@code{+}, @code{-}, @code{*}, @code{/})
1402@item
1403binary shift operators (@code{<<}, @code{>>})
1404@item
1405relational operators (@code{<}, @code{<=}, @code{>=}, @code{>})
1406@item
1407equality operators (@code{==}, @code{!=})
1408@item
1409assignment operators (@code{+=}, @code{-=}, @code{*=}, @code{/=},
1410@code{<<=}, @code{>>=})
1411@item
1412conversions to and from integer, floating-point, or fixed-point types
1413@end itemize
1414
1415Use a suffix in a fixed-point literal constant:
1416@itemize
1417@item @samp{hr} or @samp{HR} for @code{short _Fract} and
1418@code{_Sat short _Fract}
1419@item @samp{r} or @samp{R} for @code{_Fract} and @code{_Sat _Fract}
1420@item @samp{lr} or @samp{LR} for @code{long _Fract} and
1421@code{_Sat long _Fract}
1422@item @samp{llr} or @samp{LLR} for @code{long long _Fract} and
1423@code{_Sat long long _Fract}
1424@item @samp{uhr} or @samp{UHR} for @code{unsigned short _Fract} and
1425@code{_Sat unsigned short _Fract}
1426@item @samp{ur} or @samp{UR} for @code{unsigned _Fract} and
1427@code{_Sat unsigned _Fract}
1428@item @samp{ulr} or @samp{ULR} for @code{unsigned long _Fract} and
1429@code{_Sat unsigned long _Fract}
1430@item @samp{ullr} or @samp{ULLR} for @code{unsigned long long _Fract}
1431and @code{_Sat unsigned long long _Fract}
1432@item @samp{hk} or @samp{HK} for @code{short _Accum} and
1433@code{_Sat short _Accum}
1434@item @samp{k} or @samp{K} for @code{_Accum} and @code{_Sat _Accum}
1435@item @samp{lk} or @samp{LK} for @code{long _Accum} and
1436@code{_Sat long _Accum}
1437@item @samp{llk} or @samp{LLK} for @code{long long _Accum} and
1438@code{_Sat long long _Accum}
1439@item @samp{uhk} or @samp{UHK} for @code{unsigned short _Accum} and
1440@code{_Sat unsigned short _Accum}
1441@item @samp{uk} or @samp{UK} for @code{unsigned _Accum} and
1442@code{_Sat unsigned _Accum}
1443@item @samp{ulk} or @samp{ULK} for @code{unsigned long _Accum} and
1444@code{_Sat unsigned long _Accum}
1445@item @samp{ullk} or @samp{ULLK} for @code{unsigned long long _Accum}
1446and @code{_Sat unsigned long long _Accum}
1447@end itemize
1448
1449GCC support of fixed-point types as specified by the draft technical report
1450is incomplete:
1451
1452@itemize @bullet
1453@item
1454Pragmas to control overflow and rounding behaviors are not implemented.
1455@end itemize
1456
1457Fixed-point types are supported by the DWARF debug information format.
1458
1459@node Named Address Spaces
1460@section Named Address Spaces
1461@cindex Named Address Spaces
1462
1463As an extension, GNU C supports named address spaces as
1464defined in the N1275 draft of ISO/IEC DTR 18037. Support for named
1465address spaces in GCC will evolve as the draft technical report
1466changes. Calling conventions for any target might also change. At
1467present, only the AVR, M32C, PRU, RL78, and x86 targets support
1468address spaces other than the generic address space.
1469
1470Address space identifiers may be used exactly like any other C type
1471qualifier (e.g., @code{const} or @code{volatile}). See the N1275
1472document for more details.
1473
1474@anchor{AVR Named Address Spaces}
1475@subsection AVR Named Address Spaces
1476
1477On the AVR target, there are several address spaces that can be used
1478in order to put read-only data into the flash memory and access that
1479data by means of the special instructions @code{LPM} or @code{ELPM}
1480needed to read from flash.
1481
1482Devices belonging to @code{avrtiny} and @code{avrxmega3} can access
1483flash memory by means of @code{LD*} instructions because the flash
1484memory is mapped into the RAM address space. There is @emph{no need}
1485for language extensions like @code{__flash} or attribute
1486@ref{AVR Variable Attributes,,@code{progmem}}.
1487The default linker description files for these devices cater for that
1488feature and @code{.rodata} stays in flash: The compiler just generates
1489@code{LD*} instructions, and the linker script adds core specific
1490offsets to all @code{.rodata} symbols: @code{0x4000} in the case of
1491@code{avrtiny} and @code{0x8000} in the case of @code{avrxmega3}.
1492See @ref{AVR Options} for a list of respective devices.
1493
1494For devices not in @code{avrtiny} or @code{avrxmega3},
1495any data including read-only data is located in RAM (the generic
1496address space) because flash memory is not visible in the RAM address
1497space. In order to locate read-only data in flash memory @emph{and}
1498to generate the right instructions to access this data without
1499using (inline) assembler code, special address spaces are needed.
1500
1501@table @code
d77de738 1502@cindex @code{__flash} AVR Named Address Spaces
f33d7a88 1503@item __flash
d77de738
ML
1504The @code{__flash} qualifier locates data in the
1505@code{.progmem.data} section. Data is read using the @code{LPM}
1506instruction. Pointers to this address space are 16 bits wide.
1507
d77de738
ML
1508@cindex @code{__flash1} AVR Named Address Spaces
1509@cindex @code{__flash2} AVR Named Address Spaces
1510@cindex @code{__flash3} AVR Named Address Spaces
1511@cindex @code{__flash4} AVR Named Address Spaces
1512@cindex @code{__flash5} AVR Named Address Spaces
f33d7a88
AA
1513@item __flash1
1514@itemx __flash2
1515@itemx __flash3
1516@itemx __flash4
1517@itemx __flash5
d77de738
ML
1518These are 16-bit address spaces locating data in section
1519@code{.progmem@var{N}.data} where @var{N} refers to
1520address space @code{__flash@var{N}}.
1521The compiler sets the @code{RAMPZ} segment register appropriately
1522before reading data by means of the @code{ELPM} instruction.
1523
d77de738 1524@cindex @code{__memx} AVR Named Address Spaces
f33d7a88 1525@item __memx
d77de738
ML
1526This is a 24-bit address space that linearizes flash and RAM:
1527If the high bit of the address is set, data is read from
1528RAM using the lower two bytes as RAM address.
1529If the high bit of the address is clear, data is read from flash
1530with @code{RAMPZ} set according to the high byte of the address.
1531@xref{AVR Built-in Functions,,@code{__builtin_avr_flash_segment}}.
1532
1533Objects in this address space are located in @code{.progmemx.data}.
1534@end table
1535
1536@b{Example}
1537
1538@smallexample
1539char my_read (const __flash char ** p)
1540@{
1541 /* p is a pointer to RAM that points to a pointer to flash.
1542 The first indirection of p reads that flash pointer
1543 from RAM and the second indirection reads a char from this
1544 flash address. */
1545
1546 return **p;
1547@}
1548
1549/* Locate array[] in flash memory */
1550const __flash int array[] = @{ 3, 5, 7, 11, 13, 17, 19 @};
1551
1552int i = 1;
1553
1554int main (void)
1555@{
1556 /* Return 17 by reading from flash memory */
1557 return array[array[i]];
1558@}
1559@end smallexample
1560
1561@noindent
1562For each named address space supported by avr-gcc there is an equally
1563named but uppercase built-in macro defined.
1564The purpose is to facilitate testing if respective address space
1565support is available or not:
1566
1567@smallexample
1568#ifdef __FLASH
1569const __flash int var = 1;
1570
1571int read_var (void)
1572@{
1573 return var;
1574@}
1575#else
1576#include <avr/pgmspace.h> /* From AVR-LibC */
1577
1578const int var PROGMEM = 1;
1579
1580int read_var (void)
1581@{
1582 return (int) pgm_read_word (&var);
1583@}
1584#endif /* __FLASH */
1585@end smallexample
1586
1587@noindent
1588Notice that attribute @ref{AVR Variable Attributes,,@code{progmem}}
1589locates data in flash but
1590accesses to these data read from generic address space, i.e.@:
1591from RAM,
1592so that you need special accessors like @code{pgm_read_byte}
38bce6ff 1593from @w{@uref{https://www.nongnu.org/avr-libc/user-manual/,AVR-LibC}}
d77de738
ML
1594together with attribute @code{progmem}.
1595
1596@noindent
1597@b{Limitations and caveats}
1598
1599@itemize
1600@item
1601Reading across the 64@tie{}KiB section boundary of
1602the @code{__flash} or @code{__flash@var{N}} address spaces
1603shows undefined behavior. The only address space that
1604supports reading across the 64@tie{}KiB flash segment boundaries is
1605@code{__memx}.
1606
1607@item
1608If you use one of the @code{__flash@var{N}} address spaces
1609you must arrange your linker script to locate the
1610@code{.progmem@var{N}.data} sections according to your needs.
1611
1612@item
1613Any data or pointers to the non-generic address spaces must
1614be qualified as @code{const}, i.e.@: as read-only data.
1615This still applies if the data in one of these address
1616spaces like software version number or calibration lookup table are intended to
1617be changed after load time by, say, a boot loader. In this case
1618the right qualification is @code{const} @code{volatile} so that the compiler
1619must not optimize away known values or insert them
1620as immediates into operands of instructions.
1621
1622@item
1623The following code initializes a variable @code{pfoo}
1624located in static storage with a 24-bit address:
1625@smallexample
1626extern const __memx char foo;
1627const __memx void *pfoo = &foo;
1628@end smallexample
1629
1630@item
1631On the reduced Tiny devices like ATtiny40, no address spaces are supported.
1632Just use vanilla C / C++ code without overhead as outlined above.
1633Attribute @code{progmem} is supported but works differently,
1634see @ref{AVR Variable Attributes}.
1635
1636@end itemize
1637
1638@subsection M32C Named Address Spaces
1639@cindex @code{__far} M32C Named Address Spaces
1640
1641On the M32C target, with the R8C and M16C CPU variants, variables
1642qualified with @code{__far} are accessed using 32-bit addresses in
1643order to access memory beyond the first 64@tie{}Ki bytes. If
1644@code{__far} is used with the M32CM or M32C CPU variants, it has no
1645effect.
1646
1647@subsection PRU Named Address Spaces
1648@cindex @code{__regio_symbol} PRU Named Address Spaces
1649
1650On the PRU target, variables qualified with @code{__regio_symbol} are
1651aliases used to access the special I/O CPU registers. They must be
1652declared as @code{extern} because such variables will not be allocated in
1653any data memory. They must also be marked as @code{volatile}, and can
1654only be 32-bit integer types. The only names those variables can have
1655are @code{__R30} and @code{__R31}, representing respectively the
1656@code{R30} and @code{R31} special I/O CPU registers. Hence the following
1657example is the only valid usage of @code{__regio_symbol}:
1658
1659@smallexample
1660extern volatile __regio_symbol uint32_t __R30;
1661extern volatile __regio_symbol uint32_t __R31;
1662@end smallexample
1663
1664@subsection RL78 Named Address Spaces
1665@cindex @code{__far} RL78 Named Address Spaces
1666
1667On the RL78 target, variables qualified with @code{__far} are accessed
1668with 32-bit pointers (20-bit addresses) rather than the default 16-bit
1669addresses. Non-far variables are assumed to appear in the topmost
167064@tie{}KiB of the address space.
1671
1672@subsection x86 Named Address Spaces
1673@cindex x86 named address spaces
1674
1675On the x86 target, variables may be declared as being relative
1676to the @code{%fs} or @code{%gs} segments.
1677
1678@table @code
d77de738
ML
1679@cindex @code{__seg_fs} x86 named address space
1680@cindex @code{__seg_gs} x86 named address space
f33d7a88
AA
1681@item __seg_fs
1682@itemx __seg_gs
d77de738
ML
1683The object is accessed with the respective segment override prefix.
1684
1685The respective segment base must be set via some method specific to
1686the operating system. Rather than require an expensive system call
1687to retrieve the segment base, these address spaces are not considered
1688to be subspaces of the generic (flat) address space. This means that
1689explicit casts are required to convert pointers between these address
1690spaces and the generic address space. In practice the application
1691should cast to @code{uintptr_t} and apply the segment base offset
1692that it installed previously.
1693
1694The preprocessor symbols @code{__SEG_FS} and @code{__SEG_GS} are
1695defined when these address spaces are supported.
1696@end table
1697
1698@node Zero Length
1699@section Arrays of Length Zero
1700@cindex arrays of length zero
1701@cindex zero-length arrays
1702@cindex length-zero arrays
1703@cindex flexible array members
1704
1705Declaring zero-length arrays is allowed in GNU C as an extension.
1706A zero-length array can be useful as the last element of a structure
1707that is really a header for a variable-length object:
1708
1709@smallexample
1710struct line @{
1711 int length;
1712 char contents[0];
1713@};
1714
1715struct line *thisline = (struct line *)
1716 malloc (sizeof (struct line) + this_length);
1717thisline->length = this_length;
1718@end smallexample
1719
429c72eb
JW
1720In this example, @code{thisline->contents} is an array of @code{char} that
1721can hold up to @code{thisline->length} bytes.
1722
d77de738
ML
1723Although the size of a zero-length array is zero, an array member of
1724this kind may increase the size of the enclosing type as a result of tail
1725padding. The offset of a zero-length array member from the beginning
1726of the enclosing structure is the same as the offset of an array with
1727one or more elements of the same type. The alignment of a zero-length
1728array is the same as the alignment of its elements.
1729
1730Declaring zero-length arrays in other contexts, including as interior
1731members of structure objects or as non-member objects, is discouraged.
1732Accessing elements of zero-length arrays declared in such contexts is
1733undefined and may be diagnosed.
1734
1735In the absence of the zero-length array extension, in ISO C90
1736the @code{contents} array in the example above would typically be declared
1737to have a single element. Unlike a zero-length array which only contributes
1738to the size of the enclosing structure for the purposes of alignment,
1739a one-element array always occupies at least as much space as a single
1740object of the type. Although using one-element arrays this way is
1741discouraged, GCC handles accesses to trailing one-element array members
1742analogously to zero-length arrays.
1743
1744The preferred mechanism to declare variable-length types like
1745@code{struct line} above is the ISO C99 @dfn{flexible array member},
1746with slightly different syntax and semantics:
1747
1748@itemize @bullet
1749@item
1750Flexible array members are written as @code{contents[]} without
1751the @code{0}.
1752
1753@item
1754Flexible array members have incomplete type, and so the @code{sizeof}
1755operator may not be applied. As a quirk of the original implementation
1756of zero-length arrays, @code{sizeof} evaluates to zero.
1757
1758@item
1759Flexible array members may only appear as the last member of a
1760@code{struct} that is otherwise non-empty.
1761
1762@item
1763A structure containing a flexible array member, or a union containing
1764such a structure (possibly recursively), may not be a member of a
1765structure or an element of an array. (However, these uses are
070a6bf0
QZ
1766permitted by GCC as extensions, see details below.)
1767@end itemize
1768
1769The GCC extension accepts a structure containing an ISO C99 @dfn{flexible array
1770member}, or a union containing such a structure (possibly recursively)
1771to be a member of a structure.
1772
1773There are two situations:
1774
1775@itemize @bullet
1776@item
1777A structure containing a C99 flexible array member, or a union containing
1778such a structure, is the last field of another structure, for example:
1779
1780@smallexample
1781struct flex @{ int length; char data[]; @};
1782union union_flex @{ int others; struct flex f; @};
1783
1784struct out_flex_struct @{ int m; struct flex flex_data; @};
1785struct out_flex_union @{ int n; union union_flex flex_data; @};
1786@end smallexample
1787
1788In the above, both @code{out_flex_struct.flex_data.data[]} and
1789@code{out_flex_union.flex_data.f.data[]} are considered as flexible arrays too.
1790
1791@item
1792A structure containing a C99 flexible array member, or a union containing
1793such a structure, is not the last field of another structure, for example:
1794
1795@smallexample
1796struct flex @{ int length; char data[]; @};
1797
1798struct mid_flex @{ int m; struct flex flex_data; int n; @};
1799@end smallexample
1800
1801In the above, accessing a member of the array @code{mid_flex.flex_data.data[]}
1802might have undefined behavior. Compilers do not handle such a case
1803consistently. Any code relying on this case should be modified to ensure
1804that flexible array members only end up at the ends of structures.
1805
1806Please use the warning option @option{-Wflex-array-member-not-at-end} to
1807identify all such cases in the source code and modify them. This extension
1808is now deprecated.
d77de738
ML
1809@end itemize
1810
1811Non-empty initialization of zero-length
1812arrays is treated like any case where there are more initializer
1813elements than the array holds, in that a suitable warning about ``excess
1814elements in array'' is given, and the excess elements (all of them, in
1815this case) are ignored.
1816
1817GCC allows static initialization of flexible array members.
1818This is equivalent to defining a new structure containing the original
1819structure followed by an array of sufficient size to contain the data.
1820E.g.@: in the following, @code{f1} is constructed as if it were declared
1821like @code{f2}.
1822
1823@smallexample
1824struct f1 @{
1825 int x; int y[];
1826@} f1 = @{ 1, @{ 2, 3, 4 @} @};
1827
1828struct f2 @{
1829 struct f1 f1; int data[3];
1830@} f2 = @{ @{ 1 @}, @{ 2, 3, 4 @} @};
1831@end smallexample
1832
1833@noindent
1834The convenience of this extension is that @code{f1} has the desired
1835type, eliminating the need to consistently refer to @code{f2.f1}.
1836
1837This has symmetry with normal static arrays, in that an array of
1838unknown size is also written with @code{[]}.
1839
1840Of course, this extension only makes sense if the extra data comes at
1841the end of a top-level object, as otherwise we would be overwriting
1842data at subsequent offsets. To avoid undue complication and confusion
1843with initialization of deeply nested arrays, we simply disallow any
1844non-empty initialization except when the structure is the top-level
1845object. For example:
1846
1847@smallexample
1848struct foo @{ int x; int y[]; @};
1849struct bar @{ struct foo z; @};
1850
1851struct foo a = @{ 1, @{ 2, 3, 4 @} @}; // @r{Valid.}
1852struct bar b = @{ @{ 1, @{ 2, 3, 4 @} @} @}; // @r{Invalid.}
1853struct bar c = @{ @{ 1, @{ @} @} @}; // @r{Valid.}
1854struct foo d[1] = @{ @{ 1, @{ 2, 3, 4 @} @} @}; // @r{Invalid.}
1855@end smallexample
1856
1857@node Empty Structures
1858@section Structures with No Members
1859@cindex empty structures
1860@cindex zero-size structures
1861
1862GCC permits a C structure to have no members:
1863
1864@smallexample
1865struct empty @{
1866@};
1867@end smallexample
1868
1869The structure has size zero. In C++, empty structures are part
1870of the language. G++ treats empty structures as if they had a single
1871member of type @code{char}.
1872
1873@node Variable Length
1874@section Arrays of Variable Length
1875@cindex variable-length arrays
1876@cindex arrays of variable length
1877@cindex VLAs
1878
1879Variable-length automatic arrays are allowed in ISO C99, and as an
1880extension GCC accepts them in C90 mode and in C++. These arrays are
1881declared like any other automatic arrays, but with a length that is not
1882a constant expression. The storage is allocated at the point of
1883declaration and deallocated when the block scope containing the declaration
1884exits. For
1885example:
1886
1887@smallexample
1888FILE *
1889concat_fopen (char *s1, char *s2, char *mode)
1890@{
1891 char str[strlen (s1) + strlen (s2) + 1];
1892 strcpy (str, s1);
1893 strcat (str, s2);
1894 return fopen (str, mode);
1895@}
1896@end smallexample
1897
1898@cindex scope of a variable length array
1899@cindex variable-length array scope
1900@cindex deallocating variable length arrays
1901Jumping or breaking out of the scope of the array name deallocates the
1902storage. Jumping into the scope is not allowed; you get an error
1903message for it.
1904
1905@cindex variable-length array in a structure
1906As an extension, GCC accepts variable-length arrays as a member of
1907a structure or a union. For example:
1908
1909@smallexample
1910void
1911foo (int n)
1912@{
1913 struct S @{ int x[n]; @};
1914@}
1915@end smallexample
1916
1917@cindex @code{alloca} vs variable-length arrays
1918You can use the function @code{alloca} to get an effect much like
1919variable-length arrays. The function @code{alloca} is available in
1920many other C implementations (but not in all). On the other hand,
1921variable-length arrays are more elegant.
1922
1923There are other differences between these two methods. Space allocated
1924with @code{alloca} exists until the containing @emph{function} returns.
1925The space for a variable-length array is deallocated as soon as the array
1926name's scope ends, unless you also use @code{alloca} in this scope.
1927
1928You can also use variable-length arrays as arguments to functions:
1929
1930@smallexample
1931struct entry
1932tester (int len, char data[len][len])
1933@{
1934 /* @r{@dots{}} */
1935@}
1936@end smallexample
1937
1938The length of an array is computed once when the storage is allocated
1939and is remembered for the scope of the array in case you access it with
1940@code{sizeof}.
1941
1942If you want to pass the array first and the length afterward, you can
1943use a forward declaration in the parameter list---another GNU extension.
1944
1945@smallexample
1946struct entry
1947tester (int len; char data[len][len], int len)
1948@{
1949 /* @r{@dots{}} */
1950@}
1951@end smallexample
1952
1953@cindex parameter forward declaration
1954The @samp{int len} before the semicolon is a @dfn{parameter forward
1955declaration}, and it serves the purpose of making the name @code{len}
1956known when the declaration of @code{data} is parsed.
1957
1958You can write any number of such parameter forward declarations in the
1959parameter list. They can be separated by commas or semicolons, but the
1960last one must end with a semicolon, which is followed by the ``real''
1961parameter declarations. Each forward declaration must match a ``real''
1962declaration in parameter name and data type. ISO C99 does not support
1963parameter forward declarations.
1964
1965@node Variadic Macros
1966@section Macros with a Variable Number of Arguments.
1967@cindex variable number of arguments
1968@cindex macro with variable arguments
1969@cindex rest argument (in macro)
1970@cindex variadic macros
1971
1972In the ISO C standard of 1999, a macro can be declared to accept a
1973variable number of arguments much as a function can. The syntax for
1974defining the macro is similar to that of a function. Here is an
1975example:
1976
1977@smallexample
1978#define debug(format, ...) fprintf (stderr, format, __VA_ARGS__)
1979@end smallexample
1980
1981@noindent
1982Here @samp{@dots{}} is a @dfn{variable argument}. In the invocation of
1983such a macro, it represents the zero or more tokens until the closing
1984parenthesis that ends the invocation, including any commas. This set of
1985tokens replaces the identifier @code{__VA_ARGS__} in the macro body
1986wherever it appears. See the CPP manual for more information.
1987
1988GCC has long supported variadic macros, and used a different syntax that
1989allowed you to give a name to the variable arguments just like any other
1990argument. Here is an example:
1991
1992@smallexample
1993#define debug(format, args...) fprintf (stderr, format, args)
1994@end smallexample
1995
1996@noindent
1997This is in all ways equivalent to the ISO C example above, but arguably
1998more readable and descriptive.
1999
2000GNU CPP has two further variadic macro extensions, and permits them to
2001be used with either of the above forms of macro definition.
2002
2003In standard C, you are not allowed to leave the variable argument out
2004entirely; but you are allowed to pass an empty argument. For example,
2005this invocation is invalid in ISO C, because there is no comma after
2006the string:
2007
2008@smallexample
2009debug ("A message")
2010@end smallexample
2011
2012GNU CPP permits you to completely omit the variable arguments in this
2013way. In the above examples, the compiler would complain, though since
2014the expansion of the macro still has the extra comma after the format
2015string.
2016
2017To help solve this problem, CPP behaves specially for variable arguments
2018used with the token paste operator, @samp{##}. If instead you write
2019
2020@smallexample
2021#define debug(format, ...) fprintf (stderr, format, ## __VA_ARGS__)
2022@end smallexample
2023
2024@noindent
2025and if the variable arguments are omitted or empty, the @samp{##}
2026operator causes the preprocessor to remove the comma before it. If you
2027do provide some variable arguments in your macro invocation, GNU CPP
2028does not complain about the paste operation and instead places the
2029variable arguments after the comma. Just like any other pasted macro
2030argument, these arguments are not macro expanded.
2031
2032@node Escaped Newlines
2033@section Slightly Looser Rules for Escaped Newlines
2034@cindex escaped newlines
2035@cindex newlines (escaped)
2036
2037The preprocessor treatment of escaped newlines is more relaxed
2038than that specified by the C90 standard, which requires the newline
2039to immediately follow a backslash.
2040GCC's implementation allows whitespace in the form
2041of spaces, horizontal and vertical tabs, and form feeds between the
2042backslash and the subsequent newline. The preprocessor issues a
2043warning, but treats it as a valid escaped newline and combines the two
2044lines to form a single logical line. This works within comments and
2045tokens, as well as between tokens. Comments are @emph{not} treated as
2046whitespace for the purposes of this relaxation, since they have not
2047yet been replaced with spaces.
2048
2049@node Subscripting
2050@section Non-Lvalue Arrays May Have Subscripts
2051@cindex subscripting
2052@cindex arrays, non-lvalue
2053
2054@cindex subscripting and function values
2055In ISO C99, arrays that are not lvalues still decay to pointers, and
2056may be subscripted, although they may not be modified or used after
2057the next sequence point and the unary @samp{&} operator may not be
2058applied to them. As an extension, GNU C allows such arrays to be
2059subscripted in C90 mode, though otherwise they do not decay to
2060pointers outside C99 mode. For example,
2061this is valid in GNU C though not valid in C90:
2062
2063@smallexample
2064@group
2065struct foo @{int a[4];@};
2066
2067struct foo f();
2068
2069bar (int index)
2070@{
2071 return f().a[index];
2072@}
2073@end group
2074@end smallexample
2075
2076@node Pointer Arith
2077@section Arithmetic on @code{void}- and Function-Pointers
2078@cindex void pointers, arithmetic
2079@cindex void, size of pointer to
2080@cindex function pointers, arithmetic
2081@cindex function, size of pointer to
2082
2083In GNU C, addition and subtraction operations are supported on pointers to
2084@code{void} and on pointers to functions. This is done by treating the
2085size of a @code{void} or of a function as 1.
2086
2087A consequence of this is that @code{sizeof} is also allowed on @code{void}
2088and on function types, and returns 1.
2089
2090@opindex Wpointer-arith
2091The option @option{-Wpointer-arith} requests a warning if these extensions
2092are used.
2093
2094@node Variadic Pointer Args
2095@section Pointer Arguments in Variadic Functions
2096@cindex pointer arguments in variadic functions
2097@cindex variadic functions, pointer arguments
2098
2099Standard C requires that pointer types used with @code{va_arg} in
2100functions with variable argument lists either must be compatible with
2101that of the actual argument, or that one type must be a pointer to
2102@code{void} and the other a pointer to a character type. GNU C
2103implements the POSIX XSI extension that additionally permits the use
2104of @code{va_arg} with a pointer type to receive arguments of any other
2105pointer type.
2106
2107In particular, in GNU C @samp{va_arg (ap, void *)} can safely be used
2108to consume an argument of any pointer type.
2109
2110@node Pointers to Arrays
2111@section Pointers to Arrays with Qualifiers Work as Expected
2112@cindex pointers to arrays
2113@cindex const qualifier
2114
2115In GNU C, pointers to arrays with qualifiers work similar to pointers
2116to other qualified types. For example, a value of type @code{int (*)[5]}
2117can be used to initialize a variable of type @code{const int (*)[5]}.
2118These types are incompatible in ISO C because the @code{const} qualifier
2119is formally attached to the element type of the array and not the
2120array itself.
2121
2122@smallexample
2123extern void
2124transpose (int N, int M, double out[M][N], const double in[N][M]);
2125double x[3][2];
2126double y[2][3];
2127@r{@dots{}}
2128transpose(3, 2, y, x);
2129@end smallexample
2130
2131@node Initializers
2132@section Non-Constant Initializers
2133@cindex initializers, non-constant
2134@cindex non-constant initializers
2135
2136As in standard C++ and ISO C99, the elements of an aggregate initializer for an
2137automatic variable are not required to be constant expressions in GNU C@.
2138Here is an example of an initializer with run-time varying elements:
2139
2140@smallexample
2141foo (float f, float g)
2142@{
2143 float beat_freqs[2] = @{ f-g, f+g @};
2144 /* @r{@dots{}} */
2145@}
2146@end smallexample
2147
2148@node Compound Literals
2149@section Compound Literals
2150@cindex constructor expressions
2151@cindex initializations in expressions
2152@cindex structures, constructor expression
2153@cindex expressions, constructor
2154@cindex compound literals
2155@c The GNU C name for what C99 calls compound literals was "constructor expressions".
2156
2157A compound literal looks like a cast of a brace-enclosed aggregate
2158initializer list. Its value is an object of the type specified in
2159the cast, containing the elements specified in the initializer.
2160Unlike the result of a cast, a compound literal is an lvalue. ISO
2161C99 and later support compound literals. As an extension, GCC
2162supports compound literals also in C90 mode and in C++, although
2163as explained below, the C++ semantics are somewhat different.
2164
2165Usually, the specified type of a compound literal is a structure. Assume
2166that @code{struct foo} and @code{structure} are declared as shown:
2167
2168@smallexample
2169struct foo @{int a; char b[2];@} structure;
2170@end smallexample
2171
2172@noindent
2173Here is an example of constructing a @code{struct foo} with a compound literal:
2174
2175@smallexample
2176structure = ((struct foo) @{x + y, 'a', 0@});
2177@end smallexample
2178
2179@noindent
2180This is equivalent to writing the following:
2181
2182@smallexample
2183@{
2184 struct foo temp = @{x + y, 'a', 0@};
2185 structure = temp;
2186@}
2187@end smallexample
2188
2189You can also construct an array, though this is dangerous in C++, as
2190explained below. If all the elements of the compound literal are
2191(made up of) simple constant expressions suitable for use in
2192initializers of objects of static storage duration, then the compound
2193literal can be coerced to a pointer to its first element and used in
2194such an initializer, as shown here:
2195
2196@smallexample
2197char **foo = (char *[]) @{ "x", "y", "z" @};
2198@end smallexample
2199
2200Compound literals for scalar types and union types are also allowed. In
2201the following example the variable @code{i} is initialized to the value
2202@code{2}, the result of incrementing the unnamed object created by
2203the compound literal.
2204
2205@smallexample
2206int i = ++(int) @{ 1 @};
2207@end smallexample
2208
2209As a GNU extension, GCC allows initialization of objects with static storage
2210duration by compound literals (which is not possible in ISO C99 because
2211the initializer is not a constant).
2212It is handled as if the object were initialized only with the brace-enclosed
2213list if the types of the compound literal and the object match.
2214The elements of the compound literal must be constant.
2215If the object being initialized has array type of unknown size, the size is
2216determined by the size of the compound literal.
2217
2218@smallexample
2219static struct foo x = (struct foo) @{1, 'a', 'b'@};
2220static int y[] = (int []) @{1, 2, 3@};
2221static int z[] = (int [3]) @{1@};
2222@end smallexample
2223
2224@noindent
2225The above lines are equivalent to the following:
2226@smallexample
2227static struct foo x = @{1, 'a', 'b'@};
2228static int y[] = @{1, 2, 3@};
2229static int z[] = @{1, 0, 0@};
2230@end smallexample
2231
2232In C, a compound literal designates an unnamed object with static or
2233automatic storage duration. In C++, a compound literal designates a
2234temporary object that only lives until the end of its full-expression.
2235As a result, well-defined C code that takes the address of a subobject
2236of a compound literal can be undefined in C++, so G++ rejects
2237the conversion of a temporary array to a pointer. For instance, if
2238the array compound literal example above appeared inside a function,
2239any subsequent use of @code{foo} in C++ would have undefined behavior
2240because the lifetime of the array ends after the declaration of @code{foo}.
2241
2242As an optimization, G++ sometimes gives array compound literals longer
2243lifetimes: when the array either appears outside a function or has
2244a @code{const}-qualified type. If @code{foo} and its initializer had
2245elements of type @code{char *const} rather than @code{char *}, or if
2246@code{foo} were a global variable, the array would have static storage
2247duration. But it is probably safest just to avoid the use of array
2248compound literals in C++ code.
2249
2250@node Designated Inits
2251@section Designated Initializers
2252@cindex initializers with labeled elements
2253@cindex labeled elements in initializers
2254@cindex case labels in initializers
2255@cindex designated initializers
2256
2257Standard C90 requires the elements of an initializer to appear in a fixed
2258order, the same as the order of the elements in the array or structure
2259being initialized.
2260
2261In ISO C99 you can give the elements in any order, specifying the array
2262indices or structure field names they apply to, and GNU C allows this as
2263an extension in C90 mode as well. This extension is not
2264implemented in GNU C++.
2265
2266To specify an array index, write
2267@samp{[@var{index}] =} before the element value. For example,
2268
2269@smallexample
2270int a[6] = @{ [4] = 29, [2] = 15 @};
2271@end smallexample
2272
2273@noindent
2274is equivalent to
2275
2276@smallexample
2277int a[6] = @{ 0, 0, 15, 0, 29, 0 @};
2278@end smallexample
2279
2280@noindent
2281The index values must be constant expressions, even if the array being
2282initialized is automatic.
2283
2284An alternative syntax for this that has been obsolete since GCC 2.5 but
2285GCC still accepts is to write @samp{[@var{index}]} before the element
2286value, with no @samp{=}.
2287
2288To initialize a range of elements to the same value, write
2289@samp{[@var{first} ... @var{last}] = @var{value}}. This is a GNU
2290extension. For example,
2291
2292@smallexample
2293int widths[] = @{ [0 ... 9] = 1, [10 ... 99] = 2, [100] = 3 @};
2294@end smallexample
2295
2296@noindent
2297If the value in it has side effects, the side effects happen only once,
2298not for each initialized field by the range initializer.
2299
2300@noindent
2301Note that the length of the array is the highest value specified
2302plus one.
2303
2304In a structure initializer, specify the name of a field to initialize
2305with @samp{.@var{fieldname} =} before the element value. For example,
2306given the following structure,
2307
2308@smallexample
2309struct point @{ int x, y; @};
2310@end smallexample
2311
2312@noindent
2313the following initialization
2314
2315@smallexample
2316struct point p = @{ .y = yvalue, .x = xvalue @};
2317@end smallexample
2318
2319@noindent
2320is equivalent to
2321
2322@smallexample
2323struct point p = @{ xvalue, yvalue @};
2324@end smallexample
2325
2326Another syntax that has the same meaning, obsolete since GCC 2.5, is
2327@samp{@var{fieldname}:}, as shown here:
2328
2329@smallexample
2330struct point p = @{ y: yvalue, x: xvalue @};
2331@end smallexample
2332
2333Omitted fields are implicitly initialized the same as for objects
2334that have static storage duration.
2335
2336@cindex designators
2337The @samp{[@var{index}]} or @samp{.@var{fieldname}} is known as a
2338@dfn{designator}. You can also use a designator (or the obsolete colon
2339syntax) when initializing a union, to specify which element of the union
2340should be used. For example,
2341
2342@smallexample
2343union foo @{ int i; double d; @};
2344
2345union foo f = @{ .d = 4 @};
2346@end smallexample
2347
2348@noindent
2349converts 4 to a @code{double} to store it in the union using
2350the second element. By contrast, casting 4 to type @code{union foo}
2351stores it into the union as the integer @code{i}, since it is
2352an integer. @xref{Cast to Union}.
2353
2354You can combine this technique of naming elements with ordinary C
2355initialization of successive elements. Each initializer element that
2356does not have a designator applies to the next consecutive element of the
2357array or structure. For example,
2358
2359@smallexample
2360int a[6] = @{ [1] = v1, v2, [4] = v4 @};
2361@end smallexample
2362
2363@noindent
2364is equivalent to
2365
2366@smallexample
2367int a[6] = @{ 0, v1, v2, 0, v4, 0 @};
2368@end smallexample
2369
2370Labeling the elements of an array initializer is especially useful
2371when the indices are characters or belong to an @code{enum} type.
2372For example:
2373
2374@smallexample
2375int whitespace[256]
2376 = @{ [' '] = 1, ['\t'] = 1, ['\h'] = 1,
2377 ['\f'] = 1, ['\n'] = 1, ['\r'] = 1 @};
2378@end smallexample
2379
2380@cindex designator lists
2381You can also write a series of @samp{.@var{fieldname}} and
2382@samp{[@var{index}]} designators before an @samp{=} to specify a
2383nested subobject to initialize; the list is taken relative to the
2384subobject corresponding to the closest surrounding brace pair. For
2385example, with the @samp{struct point} declaration above:
2386
2387@smallexample
2388struct point ptarray[10] = @{ [2].y = yv2, [2].x = xv2, [0].x = xv0 @};
2389@end smallexample
2390
2391If the same field is initialized multiple times, or overlapping
2392fields of a union are initialized, the value from the last
2393initialization is used. When a field of a union is itself a structure,
2394the entire structure from the last field initialized is used. If any previous
2395initializer has side effect, it is unspecified whether the side effect
2396happens or not. Currently, GCC discards the side-effecting
2397initializer expressions and issues a warning.
2398
2399@node Case Ranges
2400@section Case Ranges
2401@cindex case ranges
2402@cindex ranges in case statements
2403
2404You can specify a range of consecutive values in a single @code{case} label,
2405like this:
2406
2407@smallexample
2408case @var{low} ... @var{high}:
2409@end smallexample
2410
2411@noindent
2412This has the same effect as the proper number of individual @code{case}
2413labels, one for each integer value from @var{low} to @var{high}, inclusive.
2414
2415This feature is especially useful for ranges of ASCII character codes:
2416
2417@smallexample
2418case 'A' ... 'Z':
2419@end smallexample
2420
2421@strong{Be careful:} Write spaces around the @code{...}, for otherwise
2422it may be parsed wrong when you use it with integer values. For example,
2423write this:
2424
2425@smallexample
2426case 1 ... 5:
2427@end smallexample
2428
2429@noindent
2430rather than this:
2431
2432@smallexample
2433case 1...5:
2434@end smallexample
2435
2436@node Cast to Union
2437@section Cast to a Union Type
2438@cindex cast to a union
2439@cindex union, casting to a
2440
2441A cast to a union type is a C extension not available in C++. It looks
2442just like ordinary casts with the constraint that the type specified is
2443a union type. You can specify the type either with the @code{union}
2444keyword or with a @code{typedef} name that refers to a union. The result
2445of a cast to a union is a temporary rvalue of the union type with a member
2446whose type matches that of the operand initialized to the value of
2447the operand. The effect of a cast to a union is similar to a compound
2448literal except that it yields an rvalue like standard casts do.
2449@xref{Compound Literals}.
2450
2451Expressions that may be cast to the union type are those whose type matches
2452at least one of the members of the union. Thus, given the following union
2453and variables:
2454
2455@smallexample
2456union foo @{ int i; double d; @};
2457int x;
2458double y;
2459union foo z;
2460@end smallexample
2461
2462@noindent
2463both @code{x} and @code{y} can be cast to type @code{union foo} and
2464the following assignments
2465@smallexample
2466 z = (union foo) x;
2467 z = (union foo) y;
2468@end smallexample
2469are shorthand equivalents of these
2470@smallexample
2471 z = (union foo) @{ .i = x @};
2472 z = (union foo) @{ .d = y @};
2473@end smallexample
2474
2475However, @code{(union foo) FLT_MAX;} is not a valid cast because the union
2476has no member of type @code{float}.
2477
2478Using the cast as the right-hand side of an assignment to a variable of
2479union type is equivalent to storing in a member of the union with
2480the same type
2481
2482@smallexample
2483union foo u;
2484/* @r{@dots{}} */
2485u = (union foo) x @equiv{} u.i = x
2486u = (union foo) y @equiv{} u.d = y
2487@end smallexample
2488
2489You can also use the union cast as a function argument:
2490
2491@smallexample
2492void hack (union foo);
2493/* @r{@dots{}} */
2494hack ((union foo) x);
2495@end smallexample
2496
2497@node Mixed Labels and Declarations
2498@section Mixed Declarations, Labels and Code
2499@cindex mixed declarations and code
2500@cindex declarations, mixed with code
2501@cindex code, mixed with declarations
2502
2503ISO C99 and ISO C++ allow declarations and code to be freely mixed
094a609c 2504within compound statements. ISO C23 allows labels to be
d77de738
ML
2505placed before declarations and at the end of a compound statement.
2506As an extension, GNU C also allows all this in C90 mode. For example,
2507you could do:
2508
2509@smallexample
2510int i;
2511/* @r{@dots{}} */
2512i++;
2513int j = i + 2;
2514@end smallexample
2515
2516Each identifier is visible from where it is declared until the end of
2517the enclosing block.
2518
2519@node Function Attributes
2520@section Declaring Attributes of Functions
2521@cindex function attributes
2522@cindex declaring attributes of functions
2523@cindex @code{volatile} applied to function
2524@cindex @code{const} applied to function
2525
2526In GNU C and C++, you can use function attributes to specify certain
2527function properties that may help the compiler optimize calls or
2528check code more carefully for correctness. For example, you
2529can use attributes to specify that a function never returns
2530(@code{noreturn}), returns a value depending only on the values of
2531its arguments (@code{const}), or has @code{printf}-style arguments
2532(@code{format}).
2533
2534You can also use attributes to control memory placement, code
2535generation options or call/return conventions within the function
2536being annotated. Many of these attributes are target-specific. For
2537example, many targets support attributes for defining interrupt
2538handler functions, which typically must follow special register usage
2539and return conventions. Such attributes are described in the subsection
2540for each target. However, a considerable number of attributes are
2541supported by most, if not all targets. Those are described in
2542the @ref{Common Function Attributes} section.
2543
837a12a2
SL
2544GCC provides two different ways to specify attributes: the traditional
2545GNU syntax using @samp{__attribute__ ((...))} annotations, and the
2546newer standard C and C++ syntax using @samp{[[...]]} with the
2547@samp{gnu::} prefix on attribute names. Note that the exact rules for
2548placement of attributes in your source code are different depending on
2549which syntax you use. @xref{Attribute Syntax}, for details.
2550
2551Compatible attribute specifications on distinct declarations
d77de738
ML
2552of the same function are merged. An attribute specification that is not
2553compatible with attributes already applied to a declaration of the same
2554function is ignored with a warning.
2555
2556Some function attributes take one or more arguments that refer to
2557the function's parameters by their positions within the function parameter
2558list. Such attribute arguments are referred to as @dfn{positional arguments}.
2559Unless specified otherwise, positional arguments that specify properties
2560of parameters with pointer types can also specify the same properties of
2561the implicit C++ @code{this} argument in non-static member functions, and
2562of parameters of reference to a pointer type. For ordinary functions,
2563position one refers to the first parameter on the list. In C++ non-static
2564member functions, position one refers to the implicit @code{this} pointer.
2565The same restrictions and effects apply to function attributes used with
2566ordinary functions or C++ member functions.
2567
2568GCC also supports attributes on
2569variable declarations (@pxref{Variable Attributes}),
2570labels (@pxref{Label Attributes}),
2571enumerators (@pxref{Enumerator Attributes}),
2572statements (@pxref{Statement Attributes}),
2573types (@pxref{Type Attributes}),
2574and on field declarations (for @code{tainted_args}).
2575
2576There is some overlap between the purposes of attributes and pragmas
2577(@pxref{Pragmas,,Pragmas Accepted by GCC}). It has been
2578found convenient to use @code{__attribute__} to achieve a natural
2579attachment of attributes to their corresponding declarations, whereas
2580@code{#pragma} is of use for compatibility with other compilers
2581or constructs that do not naturally form part of the grammar.
2582
2583In addition to the attributes documented here,
2584GCC plugins may provide their own attributes.
2585
2586@menu
2587* Common Function Attributes::
2588* AArch64 Function Attributes::
2589* AMD GCN Function Attributes::
2590* ARC Function Attributes::
2591* ARM Function Attributes::
2592* AVR Function Attributes::
2593* Blackfin Function Attributes::
2594* BPF Function Attributes::
2595* C-SKY Function Attributes::
2596* Epiphany Function Attributes::
2597* H8/300 Function Attributes::
2598* IA-64 Function Attributes::
2599* M32C Function Attributes::
2600* M32R/D Function Attributes::
2601* m68k Function Attributes::
2602* MCORE Function Attributes::
d77de738
ML
2603* MicroBlaze Function Attributes::
2604* Microsoft Windows Function Attributes::
2605* MIPS Function Attributes::
2606* MSP430 Function Attributes::
2607* NDS32 Function Attributes::
2608* Nios II Function Attributes::
2609* Nvidia PTX Function Attributes::
2610* PowerPC Function Attributes::
2611* RISC-V Function Attributes::
2612* RL78 Function Attributes::
2613* RX Function Attributes::
2614* S/390 Function Attributes::
2615* SH Function Attributes::
2616* Symbian OS Function Attributes::
2617* V850 Function Attributes::
2618* Visium Function Attributes::
2619* x86 Function Attributes::
2620* Xstormy16 Function Attributes::
2621@end menu
2622
2623@node Common Function Attributes
2624@subsection Common Function Attributes
2625
2626The following attributes are supported on most targets.
2627
2628@table @code
2629@c Keep this table alphabetized by attribute name. Treat _ as space.
2630
0aad1da6 2631@cindex @code{access} function attribute
d77de738
ML
2632@item access (@var{access-mode}, @var{ref-index})
2633@itemx access (@var{access-mode}, @var{ref-index}, @var{size-index})
2634
2635The @code{access} attribute enables the detection of invalid or unsafe
2636accesses by functions to which they apply or their callers, as well as
2637write-only accesses to objects that are never read from. Such accesses
2638may be diagnosed by warnings such as @option{-Wstringop-overflow},
2639@option{-Wuninitialized}, @option{-Wunused}, and others.
2640
2641The @code{access} attribute specifies that a function to whose by-reference
2642arguments the attribute applies accesses the referenced object according to
2643@var{access-mode}. The @var{access-mode} argument is required and must be
2644one of four names: @code{read_only}, @code{read_write}, @code{write_only},
2645or @code{none}. The remaining two are positional arguments.
2646
2647The required @var{ref-index} positional argument denotes a function
2648argument of pointer (or in C++, reference) type that is subject to
2649the access. The same pointer argument can be referenced by at most one
2650distinct @code{access} attribute.
2651
2652The optional @var{size-index} positional argument denotes a function
2653argument of integer type that specifies the maximum size of the access.
2654The size is the number of elements of the type referenced by @var{ref-index},
2655or the number of bytes when the pointer type is @code{void*}. When no
2656@var{size-index} argument is specified, the pointer argument must be either
2657null or point to a space that is suitably aligned and large for at least one
2658object of the referenced type (this implies that a past-the-end pointer is
2659not a valid argument). The actual size of the access may be less but it
2660must not be more.
2661
2662The @code{read_only} access mode specifies that the pointer to which it
2663applies is used to read the referenced object but not write to it. Unless
2664the argument specifying the size of the access denoted by @var{size-index}
2665is zero, the referenced object must be initialized. The mode implies
2666a stronger guarantee than the @code{const} qualifier which, when cast away
2667from a pointer, does not prevent the pointed-to object from being modified.
2668Examples of the use of the @code{read_only} access mode is the argument to
2669the @code{puts} function, or the second and third arguments to
2670the @code{memcpy} function.
2671
2672@smallexample
4ace81b6
SL
2673__attribute__ ((access (read_only, 1)))
2674int puts (const char*);
2675
2676__attribute__ ((access (read_only, 2, 3)))
2677void* memcpy (void*, const void*, size_t);
d77de738
ML
2678@end smallexample
2679
2680The @code{read_write} access mode applies to arguments of pointer types
2681without the @code{const} qualifier. It specifies that the pointer to which
2682it applies is used to both read and write the referenced object. Unless
2683the argument specifying the size of the access denoted by @var{size-index}
2684is zero, the object referenced by the pointer must be initialized. An example
2685of the use of the @code{read_write} access mode is the first argument to
2686the @code{strcat} function.
2687
2688@smallexample
4ace81b6
SL
2689__attribute__ ((access (read_write, 1), access (read_only, 2)))
2690char* strcat (char*, const char*);
d77de738
ML
2691@end smallexample
2692
2693The @code{write_only} access mode applies to arguments of pointer types
2694without the @code{const} qualifier. It specifies that the pointer to which
2695it applies is used to write to the referenced object but not read from it.
2696The object referenced by the pointer need not be initialized. An example
2697of the use of the @code{write_only} access mode is the first argument to
2698the @code{strcpy} function, or the first two arguments to the @code{fgets}
2699function.
2700
2701@smallexample
4ace81b6
SL
2702__attribute__ ((access (write_only, 1), access (read_only, 2)))
2703char* strcpy (char*, const char*);
2704
2705__attribute__ ((access (write_only, 1, 2), access (read_write, 3)))
2706int fgets (char*, int, FILE*);
d77de738
ML
2707@end smallexample
2708
2709The access mode @code{none} specifies that the pointer to which it applies
2710is not used to access the referenced object at all. Unless the pointer is
2711null the pointed-to object must exist and have at least the size as denoted
2712by the @var{size-index} argument. When the optional @var{size-index}
2713argument is omitted for an argument of @code{void*} type the actual pointer
2714agument is ignored. The referenced object need not be initialized.
2715The mode is intended to be used as a means to help validate the expected
2716object size, for example in functions that call @code{__builtin_object_size}.
2717@xref{Object Size Checking}.
2718
2719Note that the @code{access} attribute merely specifies how an object
2720referenced by the pointer argument can be accessed; it does not imply that
2721an access @strong{will} happen. Also, the @code{access} attribute does not
2722imply the attribute @code{nonnull}; it may be appropriate to add both attributes
2723at the declaration of a function that unconditionally manipulates a buffer via
2724a pointer argument. See the @code{nonnull} attribute for more information and
2725caveats.
2726
d77de738 2727@cindex @code{alias} function attribute
f33d7a88 2728@item alias ("@var{target}")
d77de738
ML
2729The @code{alias} attribute causes the declaration to be emitted as an alias
2730for another symbol, which must have been previously declared with the same
2731type, and for variables, also the same size and alignment. Declaring an alias
2732with a different type than the target is undefined and may be diagnosed. As
2733an example, the following declarations:
2734
2735@smallexample
2736void __f () @{ /* @r{Do something.} */; @}
2737void f () __attribute__ ((weak, alias ("__f")));
2738@end smallexample
2739
2740@noindent
2741define @samp{f} to be a weak alias for @samp{__f}. In C++, the mangled name
2742for the target must be used. It is an error if @samp{__f} is not defined in
2743the same translation unit.
2744
2745This attribute requires assembler and object file support,
2746and may not be available on all targets.
2747
f33d7a88 2748@cindex @code{aligned} function attribute
d77de738
ML
2749@item aligned
2750@itemx aligned (@var{alignment})
d77de738
ML
2751The @code{aligned} attribute specifies a minimum alignment for
2752the first instruction of the function, measured in bytes. When specified,
2753@var{alignment} must be an integer constant power of 2. Specifying no
2754@var{alignment} argument implies the ideal alignment for the target.
2755The @code{__alignof__} operator can be used to determine what that is
2756(@pxref{Alignment}). The attribute has no effect when a definition for
2757the function is not provided in the same translation unit.
2758
2759The attribute cannot be used to decrease the alignment of a function
2760previously declared with a more restrictive alignment; only to increase
2761it. Attempts to do otherwise are diagnosed. Some targets specify
2762a minimum default alignment for functions that is greater than 1. On
2763such targets, specifying a less restrictive alignment is silently ignored.
2764Using the attribute overrides the effect of the @option{-falign-functions}
2765(@pxref{Optimize Options}) option for this function.
2766
2767Note that the effectiveness of @code{aligned} attributes may be
2768limited by inherent limitations in the system linker
2769and/or object file format. On some systems, the
2770linker is only able to arrange for functions to be aligned up to a
2771certain maximum alignment. (For some linkers, the maximum supported
2772alignment may be very very small.) See your linker documentation for
2773further information.
2774
2775The @code{aligned} attribute can also be used for variables and fields
2776(@pxref{Variable Attributes}.)
2777
d77de738 2778@cindex @code{alloc_align} function attribute
f33d7a88 2779@item alloc_align (@var{position})
d77de738
ML
2780The @code{alloc_align} attribute may be applied to a function that
2781returns a pointer and takes at least one argument of an integer or
2782enumerated type.
2783It indicates that the returned pointer is aligned on a boundary given
2784by the function argument at @var{position}. Meaningful alignments are
2785powers of 2 greater than one. GCC uses this information to improve
2786pointer alignment analysis.
2787
2788The function parameter denoting the allocated alignment is specified by
2789one constant integer argument whose number is the argument of the attribute.
2790Argument numbering starts at one.
2791
2792For instance,
2793
2794@smallexample
2795void* my_memalign (size_t, size_t) __attribute__ ((alloc_align (1)));
2796@end smallexample
2797
2798@noindent
2799declares that @code{my_memalign} returns memory with minimum alignment
2800given by parameter 1.
2801
f33d7a88 2802@cindex @code{alloc_size} function attribute
d77de738
ML
2803@item alloc_size (@var{position})
2804@itemx alloc_size (@var{position-1}, @var{position-2})
d77de738
ML
2805The @code{alloc_size} attribute may be applied to a function that
2806returns a pointer and takes at least one argument of an integer or
2807enumerated type.
2808It indicates that the returned pointer points to memory whose size is
2809given by the function argument at @var{position-1}, or by the product
2810of the arguments at @var{position-1} and @var{position-2}. Meaningful
2811sizes are positive values less than @code{PTRDIFF_MAX}. GCC uses this
2812information to improve the results of @code{__builtin_object_size}.
2813
2814The function parameter(s) denoting the allocated size are specified by
2815one or two integer arguments supplied to the attribute. The allocated size
2816is either the value of the single function argument specified or the product
2817of the two function arguments specified. Argument numbering starts at
2818one for ordinary functions, and at two for C++ non-static member functions.
2819
2820For instance,
2821
2822@smallexample
2823void* my_calloc (size_t, size_t) __attribute__ ((alloc_size (1, 2)));
2824void* my_realloc (void*, size_t) __attribute__ ((alloc_size (2)));
2825@end smallexample
2826
2827@noindent
2828declares that @code{my_calloc} returns memory of the size given by
2829the product of parameter 1 and 2 and that @code{my_realloc} returns memory
2830of the size given by parameter 2.
2831
d77de738 2832@cindex @code{always_inline} function attribute
f33d7a88 2833@item always_inline
d77de738
ML
2834Generally, functions are not inlined unless optimization is specified.
2835For functions declared inline, this attribute inlines the function
2836independent of any restrictions that otherwise apply to inlining.
2837Failure to inline such a function is diagnosed as an error.
2838Note that if such a function is called indirectly the compiler may
2839or may not inline it depending on optimization level and a failure
2840to inline an indirect call may or may not be diagnosed.
2841
d77de738 2842@cindex @code{artificial} function attribute
f33d7a88 2843@item artificial
d77de738
ML
2844This attribute is useful for small inline wrappers that if possible
2845should appear during debugging as a unit. Depending on the debug
2846info format it either means marking the function as artificial
2847or using the caller location for all instructions within the inlined
2848body.
2849
f33d7a88 2850@cindex @code{assume_aligned} function attribute
d77de738
ML
2851@item assume_aligned (@var{alignment})
2852@itemx assume_aligned (@var{alignment}, @var{offset})
d77de738
ML
2853The @code{assume_aligned} attribute may be applied to a function that
2854returns a pointer. It indicates that the returned pointer is aligned
2855on a boundary given by @var{alignment}. If the attribute has two
2856arguments, the second argument is misalignment @var{offset}. Meaningful
2857values of @var{alignment} are powers of 2 greater than one. Meaningful
2858values of @var{offset} are greater than zero and less than @var{alignment}.
2859
2860For instance
2861
2862@smallexample
2863void* my_alloc1 (size_t) __attribute__((assume_aligned (16)));
2864void* my_alloc2 (size_t) __attribute__((assume_aligned (32, 8)));
2865@end smallexample
2866
2867@noindent
2868declares that @code{my_alloc1} returns 16-byte aligned pointers and
2869that @code{my_alloc2} returns a pointer whose value modulo 32 is equal
2870to 8.
2871
d77de738 2872@cindex @code{cold} function attribute
f33d7a88 2873@item cold
d77de738
ML
2874The @code{cold} attribute on functions is used to inform the compiler that
2875the function is unlikely to be executed. The function is optimized for
2876size rather than speed and on many targets it is placed into a special
2877subsection of the text section so all cold functions appear close together,
2878improving code locality of non-cold parts of program. The paths leading
2879to calls of cold functions within code are marked as unlikely by the branch
2880prediction mechanism. It is thus useful to mark functions used to handle
2881unlikely conditions, such as @code{perror}, as cold to improve optimization
4f52e61e
JM
2882of hot functions that do call marked functions in rare occasions. In C++,
2883the @code{cold} attribute can be applied to types with the effect of being
2884propagated to member functions. See
2885@ref{C++ Attributes}.
d77de738
ML
2886
2887When profile feedback is available, via @option{-fprofile-use}, cold functions
2888are automatically detected and this attribute is ignored.
2889
d77de738
ML
2890@cindex @code{const} function attribute
2891@cindex functions that have no side effects
f33d7a88 2892@item const
d77de738
ML
2893Calls to functions whose return value is not affected by changes to
2894the observable state of the program and that have no observable effects
2895on such state other than to return a value may lend themselves to
2896optimizations such as common subexpression elimination. Declaring such
2897functions with the @code{const} attribute allows GCC to avoid emitting
2898some calls in repeated invocations of the function with the same argument
2899values.
2900
2901For example,
2902
2903@smallexample
2904int square (int) __attribute__ ((const));
2905@end smallexample
2906
2907@noindent
2908tells GCC that subsequent calls to function @code{square} with the same
2909argument value can be replaced by the result of the first call regardless
2910of the statements in between.
2911
2912The @code{const} attribute prohibits a function from reading objects
2913that affect its return value between successive invocations. However,
2914functions declared with the attribute can safely read objects that do
2915not change their return value, such as non-volatile constants.
2916
2917The @code{const} attribute imposes greater restrictions on a function's
2918definition than the similar @code{pure} attribute. Declaring the same
2919function with both the @code{const} and the @code{pure} attribute is
2920diagnosed. Because a const function cannot have any observable side
2921effects it does not make sense for it to return @code{void}. Declaring
2922such a function is diagnosed.
2923
2924@cindex pointer arguments
2925Note that a function that has pointer arguments and examines the data
2926pointed to must @emph{not} be declared @code{const} if the pointed-to
2927data might change between successive invocations of the function. In
2928general, since a function cannot distinguish data that might change
2929from data that cannot, const functions should never take pointer or,
2930in C++, reference arguments. Likewise, a function that calls a non-const
2931function usually must not be const itself.
2932
f33d7a88
AA
2933@cindex @code{constructor} function attribute
2934@cindex @code{destructor} function attribute
d77de738
ML
2935@item constructor
2936@itemx destructor
2937@itemx constructor (@var{priority})
2938@itemx destructor (@var{priority})
d77de738
ML
2939The @code{constructor} attribute causes the function to be called
2940automatically before execution enters @code{main ()}. Similarly, the
2941@code{destructor} attribute causes the function to be called
2942automatically after @code{main ()} completes or @code{exit ()} is
2943called. Functions with these attributes are useful for
2944initializing data that is used implicitly during the execution of
2945the program.
2946
2947On some targets the attributes also accept an integer argument to
2948specify a priority to control the order in which constructor and
2949destructor functions are run. A constructor
2950with a smaller priority number runs before a constructor with a larger
2951priority number; the opposite relationship holds for destructors. Note
2952that priorities 0-100 are reserved. So, if you have a constructor that
2953allocates a resource and a destructor that deallocates the same
2954resource, both functions typically have the same priority. The
2955priorities for constructor and destructor functions are the same as
2956those specified for namespace-scope C++ objects (@pxref{C++ Attributes}).
2957However, at present, the order in which constructors for C++ objects
2958with static storage duration and functions decorated with attribute
2959@code{constructor} are invoked is unspecified. In mixed declarations,
2960attribute @code{init_priority} can be used to impose a specific ordering.
2961
2962Using the argument forms of the @code{constructor} and @code{destructor}
2963attributes on targets where the feature is not supported is rejected with
2964an error.
2965
f33d7a88 2966@cindex @code{copy} function attribute
d77de738
ML
2967@item copy
2968@itemx copy (@var{function})
d77de738
ML
2969The @code{copy} attribute applies the set of attributes with which
2970@var{function} has been declared to the declaration of the function
2971to which the attribute is applied. The attribute is designed for
2972libraries that define aliases or function resolvers that are expected
2973to specify the same set of attributes as their targets. The @code{copy}
2974attribute can be used with functions, variables, or types. However,
2975the kind of symbol to which the attribute is applied (either function
2976or variable) must match the kind of symbol to which the argument refers.
2977The @code{copy} attribute copies only syntactic and semantic attributes
2978but not attributes that affect a symbol's linkage or visibility such as
2979@code{alias}, @code{visibility}, or @code{weak}. The @code{deprecated}
2980and @code{target_clones} attribute are also not copied.
2981@xref{Common Type Attributes}.
2982@xref{Common Variable Attributes}.
2983
2984For example, the @var{StrongAlias} macro below makes use of the @code{alias}
2985and @code{copy} attributes to define an alias named @var{alloc} for function
2986@var{allocate} declared with attributes @var{alloc_size}, @var{malloc}, and
2987@var{nothrow}. Thanks to the @code{__typeof__} operator the alias has
2988the same type as the target function. As a result of the @code{copy}
2989attribute the alias also shares the same attributes as the target.
2990
2991@smallexample
2992#define StrongAlias(TargetFunc, AliasDecl) \
2993 extern __typeof__ (TargetFunc) AliasDecl \
2994 __attribute__ ((alias (#TargetFunc), copy (TargetFunc)));
2995
2996extern __attribute__ ((alloc_size (1), malloc, nothrow))
2997 void* allocate (size_t);
2998StrongAlias (allocate, alloc);
2999@end smallexample
3000
f33d7a88 3001@cindex @code{deprecated} function attribute
d77de738
ML
3002@item deprecated
3003@itemx deprecated (@var{msg})
d77de738
ML
3004The @code{deprecated} attribute results in a warning if the function
3005is used anywhere in the source file. This is useful when identifying
3006functions that are expected to be removed in a future version of a
3007program. The warning also includes the location of the declaration
3008of the deprecated function, to enable users to easily find further
3009information about why the function is deprecated, or what they should
3010do instead. Note that the warnings only occurs for uses:
3011
3012@smallexample
3013int old_fn () __attribute__ ((deprecated));
3014int old_fn ();
3015int (*fn_ptr)() = old_fn;
3016@end smallexample
3017
3018@noindent
3019results in a warning on line 3 but not line 2. The optional @var{msg}
3020argument, which must be a string, is printed in the warning if
3021present.
3022
3023The @code{deprecated} attribute can also be used for variables and
3024types (@pxref{Variable Attributes}, @pxref{Type Attributes}.)
3025
3026The message attached to the attribute is affected by the setting of
3027the @option{-fmessage-length} option.
3028
f33d7a88 3029@cindex @code{unavailable} function attribute
d77de738
ML
3030@item unavailable
3031@itemx unavailable (@var{msg})
d77de738
ML
3032The @code{unavailable} attribute results in an error if the function
3033is used anywhere in the source file. This is useful when identifying
3034functions that have been removed from a particular variation of an
3035interface. Other than emitting an error rather than a warning, the
3036@code{unavailable} attribute behaves in the same manner as
3037@code{deprecated}.
3038
3039The @code{unavailable} attribute can also be used for variables and
3040types (@pxref{Variable Attributes}, @pxref{Type Attributes}.)
3041
d77de738
ML
3042@cindex @code{error} function attribute
3043@cindex @code{warning} function attribute
f33d7a88
AA
3044@item error ("@var{message}")
3045@itemx warning ("@var{message}")
d77de738
ML
3046If the @code{error} or @code{warning} attribute
3047is used on a function declaration and a call to such a function
3048is not eliminated through dead code elimination or other optimizations,
3049an error or warning (respectively) that includes @var{message} is diagnosed.
3050This is useful
3051for compile-time checking, especially together with @code{__builtin_constant_p}
3052and inline functions where checking the inline function arguments is not
3053possible through @code{extern char [(condition) ? 1 : -1];} tricks.
3054
3055While it is possible to leave the function undefined and thus invoke
3056a link failure (to define the function with
3057a message in @code{.gnu.warning*} section),
3058when using these attributes the problem is diagnosed
3059earlier and with exact location of the call even in presence of inline
3060functions or when not emitting debugging information.
551935d1
AO
3061
3062@cindex @code{expected_throw} function attribute
3063@item expected_throw
3064This attribute, attached to a function, tells the compiler the function
3065is more likely to raise or propagate an exception than to return, loop
3066forever, or terminate the program.
3067
3068This hint is mostly ignored by the compiler. The only effect is when
3069it's applied to @code{noreturn} functions and
3070@samp{-fharden-control-flow-redundancy} is enabled, and
3071@samp{-fhardcfr-check-noreturn-calls=not-always} is not overridden.
d77de738 3072
d77de738 3073@cindex @code{externally_visible} function attribute
f33d7a88 3074@item externally_visible
d77de738
ML
3075This attribute, attached to a global variable or function, nullifies
3076the effect of the @option{-fwhole-program} command-line option, so the
3077object remains visible outside the current compilation unit.
3078
3079If @option{-fwhole-program} is used together with @option{-flto} and
3080@command{gold} is used as the linker plugin,
3081@code{externally_visible} attributes are automatically added to functions
3082(not variable yet due to a current @command{gold} issue)
3083that are accessed outside of LTO objects according to resolution file
3084produced by @command{gold}.
3085For other linkers that cannot generate resolution file,
3086explicit @code{externally_visible} attributes are still necessary.
3087
f33d7a88 3088@cindex @code{fd_arg} function attribute
d77de738
ML
3089@item fd_arg
3090@itemx fd_arg (@var{N})
d77de738
ML
3091The @code{fd_arg} attribute may be applied to a function that takes an open
3092file descriptor at referenced argument @var{N}.
3093
3094It indicates that the passed filedescriptor must not have been closed.
3095Therefore, when the analyzer is enabled with @option{-fanalyzer}, the
3096analyzer may emit a @option{-Wanalyzer-fd-use-after-close} diagnostic
3097if it detects a code path in which a function with this attribute is
3098called with a closed file descriptor.
3099
3100The attribute also indicates that the file descriptor must have been checked for
3101validity before usage. Therefore, analyzer may emit
3102@option{-Wanalyzer-fd-use-without-check} diagnostic if it detects a code path in
3103which a function with this attribute is called with a file descriptor that has
3104not been checked for validity.
3105
f33d7a88 3106@cindex @code{fd_arg_read} function attribute
d77de738
ML
3107@item fd_arg_read
3108@itemx fd_arg_read (@var{N})
d77de738
ML
3109The @code{fd_arg_read} is identical to @code{fd_arg}, but with the additional
3110requirement that it might read from the file descriptor, and thus, the file
3111descriptor must not have been opened as write-only.
3112
3113The analyzer may emit a @option{-Wanalyzer-access-mode-mismatch}
3114diagnostic if it detects a code path in which a function with this
3115attribute is called on a file descriptor opened with @code{O_WRONLY}.
3116
f33d7a88 3117@cindex @code{fd_arg_write} function attribute
d77de738
ML
3118@item fd_arg_write
3119@itemx fd_arg_write (@var{N})
d77de738
ML
3120The @code{fd_arg_write} is identical to @code{fd_arg_read} except that the
3121analyzer may emit a @option{-Wanalyzer-access-mode-mismatch} diagnostic if
3122it detects a code path in which a function with this attribute is called on a
3123file descriptor opened with @code{O_RDONLY}.
3124
d77de738 3125@cindex @code{flatten} function attribute
f33d7a88 3126@item flatten
d77de738 3127Generally, inlining into a function is limited. For a function marked with
ffbd7c3d
RB
3128this attribute, every call inside this function is inlined including the
3129calls such inlining introduces to the function (but not recursive calls
3130to the function itself), if possible.
d77de738
ML
3131Functions declared with attribute @code{noinline} and similar are not
3132inlined. Whether the function itself is considered for inlining depends
3133on its size and the current inlining parameters.
3134
d77de738
ML
3135@cindex @code{format} function attribute
3136@cindex functions with @code{printf}, @code{scanf}, @code{strftime} or @code{strfmon} style arguments
3137@opindex Wformat
f33d7a88 3138@item format (@var{archetype}, @var{string-index}, @var{first-to-check})
d77de738
ML
3139The @code{format} attribute specifies that a function takes @code{printf},
3140@code{scanf}, @code{strftime} or @code{strfmon} style arguments that
3141should be type-checked against a format string. For example, the
3142declaration:
3143
3144@smallexample
3145extern int
3146my_printf (void *my_object, const char *my_format, ...)
3147 __attribute__ ((format (printf, 2, 3)));
3148@end smallexample
3149
3150@noindent
3151causes the compiler to check the arguments in calls to @code{my_printf}
3152for consistency with the @code{printf} style format string argument
3153@code{my_format}.
3154
3155The parameter @var{archetype} determines how the format string is
3156interpreted, and should be @code{printf}, @code{scanf}, @code{strftime},
3157@code{gnu_printf}, @code{gnu_scanf}, @code{gnu_strftime} or
3158@code{strfmon}. (You can also use @code{__printf__},
3159@code{__scanf__}, @code{__strftime__} or @code{__strfmon__}.) On
3160MinGW targets, @code{ms_printf}, @code{ms_scanf}, and
3161@code{ms_strftime} are also present.
3162@var{archetype} values such as @code{printf} refer to the formats accepted
3163by the system's C runtime library,
3164while values prefixed with @samp{gnu_} always refer
3165to the formats accepted by the GNU C Library. On Microsoft Windows
3166targets, values prefixed with @samp{ms_} refer to the formats accepted by the
3167@file{msvcrt.dll} library.
3168The parameter @var{string-index}
3169specifies which argument is the format string argument (starting
3170from 1), while @var{first-to-check} is the number of the first
3171argument to check against the format string. For functions
3172where the arguments are not available to be checked (such as
3173@code{vprintf}), specify the third parameter as zero. In this case the
3174compiler only checks the format string for consistency. For
3175@code{strftime} formats, the third parameter is required to be zero.
3176Since non-static C++ methods have an implicit @code{this} argument, the
3177arguments of such methods should be counted from two, not one, when
3178giving values for @var{string-index} and @var{first-to-check}.
3179
3180In the example above, the format string (@code{my_format}) is the second
3181argument of the function @code{my_print}, and the arguments to check
3182start with the third argument, so the correct parameters for the format
3183attribute are 2 and 3.
3184
3185@opindex ffreestanding
3186@opindex fno-builtin
3187The @code{format} attribute allows you to identify your own functions
3188that take format strings as arguments, so that GCC can check the
3189calls to these functions for errors. The compiler always (unless
3190@option{-ffreestanding} or @option{-fno-builtin} is used) checks formats
3191for the standard library functions @code{printf}, @code{fprintf},
3192@code{sprintf}, @code{scanf}, @code{fscanf}, @code{sscanf}, @code{strftime},
3193@code{vprintf}, @code{vfprintf} and @code{vsprintf} whenever such
3194warnings are requested (using @option{-Wformat}), so there is no need to
3195modify the header file @file{stdio.h}. In C99 mode, the functions
3196@code{snprintf}, @code{vsnprintf}, @code{vscanf}, @code{vfscanf} and
3197@code{vsscanf} are also checked. Except in strictly conforming C
3198standard modes, the X/Open function @code{strfmon} is also checked as
3199are @code{printf_unlocked} and @code{fprintf_unlocked}.
3200@xref{C Dialect Options,,Options Controlling C Dialect}.
3201
3202For Objective-C dialects, @code{NSString} (or @code{__NSString__}) is
3203recognized in the same context. Declarations including these format attributes
3204are parsed for correct syntax, however the result of checking of such format
3205strings is not yet defined, and is not carried out by this version of the
3206compiler.
3207
3208The target may also provide additional types of format checks.
3209@xref{Target Format Checks,,Format Checks Specific to Particular
3210Target Machines}.
3211
d77de738
ML
3212@cindex @code{format_arg} function attribute
3213@opindex Wformat-nonliteral
f33d7a88 3214@item format_arg (@var{string-index})
d77de738
ML
3215The @code{format_arg} attribute specifies that a function takes one or
3216more format strings for a @code{printf}, @code{scanf}, @code{strftime} or
3217@code{strfmon} style function and modifies it (for example, to translate
3218it into another language), so the result can be passed to a
3219@code{printf}, @code{scanf}, @code{strftime} or @code{strfmon} style
3220function (with the remaining arguments to the format function the same
3221as they would have been for the unmodified string). Multiple
3222@code{format_arg} attributes may be applied to the same function, each
3223designating a distinct parameter as a format string. For example, the
3224declaration:
3225
3226@smallexample
3227extern char *
3228my_dgettext (char *my_domain, const char *my_format)
3229 __attribute__ ((format_arg (2)));
3230@end smallexample
3231
3232@noindent
3233causes the compiler to check the arguments in calls to a @code{printf},
3234@code{scanf}, @code{strftime} or @code{strfmon} type function, whose
3235format string argument is a call to the @code{my_dgettext} function, for
3236consistency with the format string argument @code{my_format}. If the
3237@code{format_arg} attribute had not been specified, all the compiler
3238could tell in such calls to format functions would be that the format
3239string argument is not constant; this would generate a warning when
3240@option{-Wformat-nonliteral} is used, but the calls could not be checked
3241without the attribute.
3242
3243In calls to a function declared with more than one @code{format_arg}
3244attribute, each with a distinct argument value, the corresponding
3245actual function arguments are checked against all format strings
3246designated by the attributes. This capability is designed to support
3247the GNU @code{ngettext} family of functions.
3248
3249The parameter @var{string-index} specifies which argument is the format
3250string argument (starting from one). Since non-static C++ methods have
3251an implicit @code{this} argument, the arguments of such methods should
3252be counted from two.
3253
3254The @code{format_arg} attribute allows you to identify your own
3255functions that modify format strings, so that GCC can check the
3256calls to @code{printf}, @code{scanf}, @code{strftime} or @code{strfmon}
3257type function whose operands are a call to one of your own function.
3258The compiler always treats @code{gettext}, @code{dgettext}, and
3259@code{dcgettext} in this manner except when strict ISO C support is
3260requested by @option{-ansi} or an appropriate @option{-std} option, or
3261@option{-ffreestanding} or @option{-fno-builtin}
3262is used. @xref{C Dialect Options,,Options
3263Controlling C Dialect}.
3264
3265For Objective-C dialects, the @code{format-arg} attribute may refer to an
3266@code{NSString} reference for compatibility with the @code{format} attribute
3267above.
3268
3269The target may also allow additional types in @code{format-arg} attributes.
3270@xref{Target Format Checks,,Format Checks Specific to Particular
3271Target Machines}.
3272
d77de738 3273@cindex @code{gnu_inline} function attribute
f33d7a88 3274@item gnu_inline
d77de738
ML
3275This attribute should be used with a function that is also declared
3276with the @code{inline} keyword. It directs GCC to treat the function
3277as if it were defined in gnu90 mode even when compiling in C99 or
3278gnu99 mode.
3279
3280If the function is declared @code{extern}, then this definition of the
3281function is used only for inlining. In no case is the function
3282compiled as a standalone function, not even if you take its address
3283explicitly. Such an address becomes an external reference, as if you
3284had only declared the function, and had not defined it. This has
3285almost the effect of a macro. The way to use this is to put a
3286function definition in a header file with this attribute, and put
3287another copy of the function, without @code{extern}, in a library
3288file. The definition in the header file causes most calls to the
3289function to be inlined. If any uses of the function remain, they
3290refer to the single copy in the library. Note that the two
3291definitions of the functions need not be precisely the same, although
3292if they do not have the same effect your program may behave oddly.
3293
3294In C, if the function is neither @code{extern} nor @code{static}, then
3295the function is compiled as a standalone function, as well as being
3296inlined where possible.
3297
3298This is how GCC traditionally handled functions declared
3299@code{inline}. Since ISO C99 specifies a different semantics for
3300@code{inline}, this function attribute is provided as a transition
3301measure and as a useful feature in its own right. This attribute is
3302available in GCC 4.1.3 and later. It is available if either of the
3303preprocessor macros @code{__GNUC_GNU_INLINE__} or
3304@code{__GNUC_STDC_INLINE__} are defined. @xref{Inline,,An Inline
3305Function is As Fast As a Macro}.
3306
3307In C++, this attribute does not depend on @code{extern} in any way,
3308but it still requires the @code{inline} keyword to enable its special
3309behavior.
3310
d77de738 3311@cindex @code{hot} function attribute
f33d7a88 3312@item hot
d77de738
ML
3313The @code{hot} attribute on a function is used to inform the compiler that
3314the function is a hot spot of the compiled program. The function is
3315optimized more aggressively and on many targets it is placed into a special
3316subsection of the text section so all hot functions appear close together,
4f52e61e
JM
3317improving locality. In C++, the @code{hot} attribute can be applied to types
3318with the effect of being propagated to member functions. See
3319@ref{C++ Attributes}.
d77de738
ML
3320
3321When profile feedback is available, via @option{-fprofile-use}, hot functions
3322are automatically detected and this attribute is ignored.
3323
d77de738
ML
3324@cindex @code{ifunc} function attribute
3325@cindex indirect functions
3326@cindex functions that are dynamically resolved
f33d7a88 3327@item ifunc ("@var{resolver}")
d77de738
ML
3328The @code{ifunc} attribute is used to mark a function as an indirect
3329function using the STT_GNU_IFUNC symbol type extension to the ELF
3330standard. This allows the resolution of the symbol value to be
3331determined dynamically at load time, and an optimized version of the
3332routine to be selected for the particular processor or other system
3333characteristics determined then. To use this attribute, first define
3334the implementation functions available, and a resolver function that
3335returns a pointer to the selected implementation function. The
3336implementation functions' declarations must match the API of the
3337function being implemented. The resolver should be declared to
3338be a function taking no arguments and returning a pointer to
3339a function of the same type as the implementation. For example:
3340
3341@smallexample
3342void *my_memcpy (void *dst, const void *src, size_t len)
3343@{
3344 @dots{}
3345 return dst;
3346@}
3347
3348static void * (*resolve_memcpy (void))(void *, const void *, size_t)
3349@{
3350 return my_memcpy; // we will just always select this routine
3351@}
3352@end smallexample
3353
3354@noindent
3355The exported header file declaring the function the user calls would
3356contain:
3357
3358@smallexample
3359extern void *memcpy (void *, const void *, size_t);
3360@end smallexample
3361
3362@noindent
3363allowing the user to call @code{memcpy} as a regular function, unaware of
3364the actual implementation. Finally, the indirect function needs to be
3365defined in the same translation unit as the resolver function:
3366
3367@smallexample
3368void *memcpy (void *, const void *, size_t)
3369 __attribute__ ((ifunc ("resolve_memcpy")));
3370@end smallexample
3371
3372In C++, the @code{ifunc} attribute takes a string that is the mangled name
3373of the resolver function. A C++ resolver for a non-static member function
3374of class @code{C} should be declared to return a pointer to a non-member
3375function taking pointer to @code{C} as the first argument, followed by
3376the same arguments as of the implementation function. G++ checks
3377the signatures of the two functions and issues
3378a @option{-Wattribute-alias} warning for mismatches. To suppress a warning
3379for the necessary cast from a pointer to the implementation member function
3380to the type of the corresponding non-member function use
3381the @option{-Wno-pmf-conversions} option. For example:
3382
3383@smallexample
3384class S
3385@{
3386private:
3387 int debug_impl (int);
3388 int optimized_impl (int);
3389
3390 typedef int Func (S*, int);
3391
3392 static Func* resolver ();
3393public:
3394
3395 int interface (int);
3396@};
3397
3398int S::debug_impl (int) @{ /* @r{@dots{}} */ @}
3399int S::optimized_impl (int) @{ /* @r{@dots{}} */ @}
3400
3401S::Func* S::resolver ()
3402@{
3403 int (S::*pimpl) (int)
3404 = getenv ("DEBUG") ? &S::debug_impl : &S::optimized_impl;
3405
3406 // Cast triggers -Wno-pmf-conversions.
3407 return reinterpret_cast<Func*>(pimpl);
3408@}
3409
3410int S::interface (int) __attribute__ ((ifunc ("_ZN1S8resolverEv")));
3411@end smallexample
3412
3413Indirect functions cannot be weak. Binutils version 2.20.1 or higher
3414and GNU C Library version 2.11.1 are required to use this feature.
3415
0aad1da6
AP
3416@cindex @code{interrupt_handler} function attribute
3417@cindex @code{interrupt} function attribute
d77de738
ML
3418@item interrupt
3419@itemx interrupt_handler
3420Many GCC back ends support attributes to indicate that a function is
3421an interrupt handler, which tells the compiler to generate function
3422entry and exit sequences that differ from those from regular
3423functions. The exact syntax and behavior are target-specific;
3424refer to the following subsections for details.
3425
d77de738 3426@cindex @code{leaf} function attribute
f33d7a88 3427@item leaf
d77de738
ML
3428Calls to external functions with this attribute must return to the
3429current compilation unit only by return or by exception handling. In
3430particular, a leaf function is not allowed to invoke callback functions
3431passed to it from the current compilation unit, directly call functions
3432exported by the unit, or @code{longjmp} into the unit. Leaf functions
3433might still call functions from other compilation units and thus they
3434are not necessarily leaf in the sense that they contain no function
3435calls at all.
3436
3437The attribute is intended for library functions to improve dataflow
3438analysis. The compiler takes the hint that any data not escaping the
3439current compilation unit cannot be used or modified by the leaf
3440function. For example, the @code{sin} function is a leaf function, but
3441@code{qsort} is not.
3442
3443Note that leaf functions might indirectly run a signal handler defined
3444in the current compilation unit that uses static variables. Similarly,
3445when lazy symbol resolution is in effect, leaf functions might invoke
3446indirect functions whose resolver function or implementation function is
3447defined in the current compilation unit and uses static variables. There
3448is no standard-compliant way to write such a signal handler, resolver
3449function, or implementation function, and the best that you can do is to
3450remove the @code{leaf} attribute or mark all such static variables
3451@code{volatile}. Lastly, for ELF-based systems that support symbol
3452interposition, care should be taken that functions defined in the
3453current compilation unit do not unexpectedly interpose other symbols
3454based on the defined standards mode and defined feature test macros;
3455otherwise an inadvertent callback would be added.
3456
3457The attribute has no effect on functions defined within the current
3458compilation unit. This is to allow easy merging of multiple compilation
3459units into one, for example, by using the link-time optimization. For
3460this reason the attribute is not allowed on types to annotate indirect
3461calls.
3462
f33d7a88
AA
3463@cindex @code{malloc} function attribute
3464@cindex functions that behave like malloc
d77de738
ML
3465@item malloc
3466@item malloc (@var{deallocator})
3467@item malloc (@var{deallocator}, @var{ptr-index})
d77de738
ML
3468Attribute @code{malloc} indicates that a function is @code{malloc}-like,
3469i.e., that the pointer @var{P} returned by the function cannot alias any
3470other pointer valid when the function returns, and moreover no
3471pointers to valid objects occur in any storage addressed by @var{P}. In
dfc5ea6b 3472addition, GCC predicts that a function with the attribute returns
d77de738
ML
3473non-null in most cases.
3474
3475Independently, the form of the attribute with one or two arguments
3476associates @code{deallocator} as a suitable deallocation function for
3477pointers returned from the @code{malloc}-like function. @var{ptr-index}
3478denotes the positional argument to which when the pointer is passed in
3479calls to @code{deallocator} has the effect of deallocating it.
3480
3481Using the attribute with no arguments is designed to improve optimization
3482by relying on the aliasing property it implies. Functions like @code{malloc}
3483and @code{calloc} have this property because they return a pointer to
3484uninitialized or zeroed-out, newly obtained storage. However, functions
3485like @code{realloc} do not have this property, as they may return pointers
3486to storage containing pointers to existing objects. Additionally, since
3487all such functions are assumed to return null only infrequently, callers
3488can be optimized based on that assumption.
3489
3490Associating a function with a @var{deallocator} helps detect calls to
3491mismatched allocation and deallocation functions and diagnose them under
3492the control of options such as @option{-Wmismatched-dealloc}. It also
3493makes it possible to diagnose attempts to deallocate objects that were not
3494allocated dynamically, by @option{-Wfree-nonheap-object}. To indicate
3495that an allocation function both satisifies the nonaliasing property and
3496has a deallocator associated with it, both the plain form of the attribute
3497and the one with the @var{deallocator} argument must be used. The same
3498function can be both an allocator and a deallocator. Since inlining one
3499of the associated functions but not the other could result in apparent
3500mismatches, this form of attribute @code{malloc} is not accepted on inline
3501functions. For the same reason, using the attribute prevents both
3502the allocation and deallocation functions from being expanded inline.
3503
3504For example, besides stating that the functions return pointers that do
3505not alias any others, the following declarations make @code{fclose}
3506a suitable deallocator for pointers returned from all functions except
3507@code{popen}, and @code{pclose} as the only suitable deallocator for
3508pointers returned from @code{popen}. The deallocator functions must
3509be declared before they can be referenced in the attribute.
3510
3511@smallexample
3512int fclose (FILE*);
3513int pclose (FILE*);
3514
3515__attribute__ ((malloc, malloc (fclose, 1)))
3516 FILE* fdopen (int, const char*);
3517__attribute__ ((malloc, malloc (fclose, 1)))
3518 FILE* fopen (const char*, const char*);
3519__attribute__ ((malloc, malloc (fclose, 1)))
3520 FILE* fmemopen(void *, size_t, const char *);
3521__attribute__ ((malloc, malloc (pclose, 1)))
3522 FILE* popen (const char*, const char*);
3523__attribute__ ((malloc, malloc (fclose, 1)))
3524 FILE* tmpfile (void);
3525@end smallexample
3526
3527The warnings guarded by @option{-fanalyzer} respect allocation and
3528deallocation pairs marked with the @code{malloc}. In particular:
3529
3530@itemize @bullet
3531
3532@item
4ace81b6 3533The analyzer emits a @option{-Wanalyzer-mismatching-deallocation}
d77de738
ML
3534diagnostic if there is an execution path in which the result of an
3535allocation call is passed to a different deallocator.
3536
3537@item
4ace81b6 3538The analyzer emits a @option{-Wanalyzer-double-free}
d77de738
ML
3539diagnostic if there is an execution path in which a value is passed
3540more than once to a deallocation call.
3541
3542@item
4ace81b6
SL
3543The analyzer considers the possibility that an allocation function
3544could fail and return null. If there are
d77de738 3545execution paths in which an unchecked result of an allocation call is
4ace81b6
SL
3546dereferenced or passed to a function requiring a non-null argument,
3547it emits
3548@option{-Wanalyzer-possible-null-dereference} and
3549@option{-Wanalyzer-possible-null-argument} diagnostics.
d77de738
ML
3550If the allocator always returns non-null, use
3551@code{__attribute__ ((returns_nonnull))} to suppress these warnings.
3552For example:
3553@smallexample
3554char *xstrdup (const char *)
3555 __attribute__((malloc (free), returns_nonnull));
3556@end smallexample
3557
3558@item
4ace81b6 3559The analyzer emits a @option{-Wanalyzer-use-after-free}
d77de738
ML
3560diagnostic if there is an execution path in which the memory passed
3561by pointer to a deallocation call is used after the deallocation.
3562
3563@item
4ace81b6 3564The analyzer emits a @option{-Wanalyzer-malloc-leak} diagnostic if
d77de738
ML
3565there is an execution path in which the result of an allocation call
3566is leaked (without being passed to the deallocation function).
3567
3568@item
4ace81b6 3569The analyzer emits a @option{-Wanalyzer-free-of-non-heap} diagnostic
d77de738
ML
3570if a deallocation function is used on a global or on-stack variable.
3571
3572@end itemize
3573
4ace81b6 3574The analyzer assumes that deallocators can gracefully handle the null
d77de738
ML
3575pointer. If this is not the case, the deallocator can be marked with
3576@code{__attribute__((nonnull))} so that @option{-fanalyzer} can emit
3577a @option{-Wanalyzer-possible-null-argument} diagnostic for code paths
4ace81b6 3578in which the deallocator is called with null.
d77de738 3579
d77de738 3580@cindex @code{no_icf} function attribute
f33d7a88 3581@item no_icf
d77de738
ML
3582This function attribute prevents a functions from being merged with another
3583semantically equivalent function.
3584
d77de738
ML
3585@cindex @code{no_instrument_function} function attribute
3586@opindex finstrument-functions
3587@opindex p
3588@opindex pg
f33d7a88 3589@item no_instrument_function
d77de738
ML
3590If any of @option{-finstrument-functions}, @option{-p}, or @option{-pg} are
3591given, profiling function calls are
3592generated at entry and exit of most user-compiled functions.
3593Functions with this attribute are not so instrumented.
3594
d77de738 3595@cindex @code{no_profile_instrument_function} function attribute
f33d7a88 3596@item no_profile_instrument_function
d77de738
ML
3597The @code{no_profile_instrument_function} attribute on functions is used
3598to inform the compiler that it should not process any profile feedback based
3599optimization code instrumentation.
3600
d77de738 3601@cindex @code{no_reorder} function attribute
f33d7a88 3602@item no_reorder
d77de738
ML
3603Do not reorder functions or variables marked @code{no_reorder}
3604against each other or top level assembler statements the executable.
3605The actual order in the program will depend on the linker command
3606line. Static variables marked like this are also not removed.
3607This has a similar effect
3608as the @option{-fno-toplevel-reorder} option, but only applies to the
3609marked symbols.
3610
d77de738 3611@cindex @code{no_sanitize} function attribute
f33d7a88 3612@item no_sanitize ("@var{sanitize_option}")
d77de738
ML
3613The @code{no_sanitize} attribute on functions is used
3614to inform the compiler that it should not do sanitization of any option
3615mentioned in @var{sanitize_option}. A list of values acceptable by
3616the @option{-fsanitize} option can be provided.
3617
3618@smallexample
3619void __attribute__ ((no_sanitize ("alignment", "object-size")))
3620f () @{ /* @r{Do something.} */; @}
3621void __attribute__ ((no_sanitize ("alignment,object-size")))
3622g () @{ /* @r{Do something.} */; @}
3623@end smallexample
3624
f33d7a88 3625@cindex @code{no_sanitize_address} function attribute
d77de738
ML
3626@item no_sanitize_address
3627@itemx no_address_safety_analysis
d77de738
ML
3628The @code{no_sanitize_address} attribute on functions is used
3629to inform the compiler that it should not instrument memory accesses
3630in the function when compiling with the @option{-fsanitize=address} option.
3631The @code{no_address_safety_analysis} is a deprecated alias of the
3632@code{no_sanitize_address} attribute, new code should use
3633@code{no_sanitize_address}.
3634
d77de738 3635@cindex @code{no_sanitize_thread} function attribute
f33d7a88 3636@item no_sanitize_thread
d77de738
ML
3637The @code{no_sanitize_thread} attribute on functions is used
3638to inform the compiler that it should not instrument memory accesses
3639in the function when compiling with the @option{-fsanitize=thread} option.
3640
d77de738 3641@cindex @code{no_sanitize_undefined} function attribute
f33d7a88 3642@item no_sanitize_undefined
d77de738
ML
3643The @code{no_sanitize_undefined} attribute on functions is used
3644to inform the compiler that it should not check for undefined behavior
3645in the function when compiling with the @option{-fsanitize=undefined} option.
3646
d77de738 3647@cindex @code{no_sanitize_coverage} function attribute
f33d7a88 3648@item no_sanitize_coverage
d77de738
ML
3649The @code{no_sanitize_coverage} attribute on functions is used
3650to inform the compiler that it should not do coverage-guided
3651fuzzing code instrumentation (@option{-fsanitize-coverage}).
3652
d77de738
ML
3653@cindex @code{no_split_stack} function attribute
3654@opindex fsplit-stack
f33d7a88 3655@item no_split_stack
d77de738
ML
3656If @option{-fsplit-stack} is given, functions have a small
3657prologue which decides whether to split the stack. Functions with the
3658@code{no_split_stack} attribute do not have that prologue, and thus
3659may run with only a small amount of stack space available.
3660
d77de738 3661@cindex @code{no_stack_limit} function attribute
f33d7a88 3662@item no_stack_limit
d77de738
ML
3663This attribute locally overrides the @option{-fstack-limit-register}
3664and @option{-fstack-limit-symbol} command-line options; it has the effect
3665of disabling stack limit checking in the function it applies to.
3666
d77de738 3667@cindex @code{noclone} function attribute
f33d7a88 3668@item noclone
d77de738
ML
3669This function attribute prevents a function from being considered for
3670cloning---a mechanism that produces specialized copies of functions
3671and which is (currently) performed by interprocedural constant
3672propagation.
3673
d77de738 3674@cindex @code{noinline} function attribute
f33d7a88 3675@item noinline
d77de738
ML
3676This function attribute prevents a function from being considered for
3677inlining.
3678@c Don't enumerate the optimizations by name here; we try to be
3679@c future-compatible with this mechanism.
3680If the function does not have side effects, there are optimizations
3681other than inlining that cause function calls to be optimized away,
3682although the function call is live. To keep such calls from being
3683optimized away, put
3684@smallexample
3685asm ("");
3686@end smallexample
3687
3688@noindent
3689(@pxref{Extended Asm}) in the called function, to serve as a special
3690side effect.
3691
d77de738 3692@cindex @code{noipa} function attribute
f33d7a88 3693@item noipa
d77de738
ML
3694Disable interprocedural optimizations between the function with this
3695attribute and its callers, as if the body of the function is not available
3696when optimizing callers and the callers are unavailable when optimizing
3697the body. This attribute implies @code{noinline}, @code{noclone} and
3698@code{no_icf} attributes. However, this attribute is not equivalent
3699to a combination of other attributes, because its purpose is to suppress
3700existing and future optimizations employing interprocedural analysis,
3701including those that do not have an attribute suitable for disabling
3702them individually. This attribute is supported mainly for the purpose
3703of testing the compiler.
3704
d77de738
ML
3705@cindex @code{nonnull} function attribute
3706@cindex functions with non-null pointer arguments
f33d7a88
AA
3707@item nonnull
3708@itemx nonnull (@var{arg-index}, @dots{})
d77de738
ML
3709The @code{nonnull} attribute may be applied to a function that takes at
3710least one argument of a pointer type. It indicates that the referenced
3711arguments must be non-null pointers. For instance, the declaration:
3712
3713@smallexample
3714extern void *
3715my_memcpy (void *dest, const void *src, size_t len)
3716 __attribute__((nonnull (1, 2)));
3717@end smallexample
3718
3719@noindent
3720informs the compiler that, in calls to @code{my_memcpy}, arguments
3721@var{dest} and @var{src} must be non-null.
3722
3723The attribute has an effect both on functions calls and function definitions.
3724
3725For function calls:
3726@itemize @bullet
3727@item If the compiler determines that a null pointer is
3728passed in an argument slot marked as non-null, and the
3729@option{-Wnonnull} option is enabled, a warning is issued.
3730@xref{Warning Options}.
3731@item The @option{-fisolate-erroneous-paths-attribute} option can be
3732specified to have GCC transform calls with null arguments to non-null
3733functions into traps. @xref{Optimize Options}.
3734@item The compiler may also perform optimizations based on the
3735knowledge that certain function arguments cannot be null. These
3736optimizations can be disabled by the
3737@option{-fno-delete-null-pointer-checks} option. @xref{Optimize Options}.
3738@end itemize
3739
3740For function definitions:
3741@itemize @bullet
3742@item If the compiler determines that a function parameter that is
3743marked with nonnull is compared with null, and
3744@option{-Wnonnull-compare} option is enabled, a warning is issued.
3745@xref{Warning Options}.
3746@item The compiler may also perform optimizations based on the
0e38aedc 3747knowledge that @code{nonnull} parameters cannot be null. This can
d77de738
ML
3748currently not be disabled other than by removing the nonnull
3749attribute.
3750@end itemize
3751
3752If no @var{arg-index} is given to the @code{nonnull} attribute,
3753all pointer arguments are marked as non-null. To illustrate, the
3754following declaration is equivalent to the previous example:
3755
3756@smallexample
3757extern void *
3758my_memcpy (void *dest, const void *src, size_t len)
3759 __attribute__((nonnull));
3760@end smallexample
3761
cd7dadcd
DM
3762@cindex @code{null_terminated_string_arg} function attribute
3763@item null_terminated_string_arg
3764@itemx null_terminated_string_arg (@var{N})
3765The @code{null_terminated_string_arg} attribute may be applied to a
3766function that takes a @code{char *} or @code{const char *} at
3767referenced argument @var{N}.
3768
3769It indicates that the passed argument must be a C-style null-terminated
3770string. Specifically, the presence of the attribute implies that, if
3771the pointer is non-null, the function may scan through the referenced
3772buffer looking for the first zero byte.
3773
3774In particular, when the analyzer is enabled (via @option{-fanalyzer}),
3775if the pointer is non-null, it will simulate scanning for the first
3776zero byte in the referenced buffer, and potentially emit
3777@option{-Wanalyzer-use-of-uninitialized-value}
3778or @option{-Wanalyzer-out-of-bounds} on improperly terminated buffers.
3779
3780For example, given the following:
3781
3782@smallexample
3783char *example_1 (const char *p)
3784 __attribute__((null_terminated_string_arg (1)));
3785@end smallexample
3786
3787the analyzer will check that any non-null pointers passed to the function
3788are validly terminated.
3789
3790If the parameter must be non-null, it is appropriate to use both this
3791attribute and the attribute @code{nonnull}, such as in:
3792
3793@smallexample
3794extern char *example_2 (const char *p)
3795 __attribute__((null_terminated_string_arg (1),
3796 nonnull (1)));
3797@end smallexample
3798
3799See the @code{nonnull} attribute for more information and
3800caveats.
3801
3802If the pointer argument is also referred to by an @code{access} attribute on the
3803function with @var{access-mode} either @code{read_only} or @code{read_write}
3804and the latter attribute has the optional @var{size-index} argument
3805referring to a size argument, this expressses the maximum size of the access.
3806For example, given:
3807
3808@smallexample
3809extern char *example_fn (const char *p, size_t n)
3810 __attribute__((null_terminated_string_arg (1),
3811 access (read_only, 1, 2),
3812 nonnull (1)));
3813@end smallexample
3814
3815the analyzer will require the first parameter to be non-null, and either
3816be validly null-terminated, or validly readable up to the size specified by
3817the second parameter.
3818
d77de738 3819@cindex @code{noplt} function attribute
f33d7a88 3820@item noplt
d77de738
ML
3821The @code{noplt} attribute is the counterpart to option @option{-fno-plt}.
3822Calls to functions marked with this attribute in position-independent code
3823do not use the PLT.
3824
3825@smallexample
3826@group
3827/* Externally defined function foo. */
3828int foo () __attribute__ ((noplt));
3829
3830int
3831main (/* @r{@dots{}} */)
3832@{
3833 /* @r{@dots{}} */
3834 foo ();
3835 /* @r{@dots{}} */
3836@}
3837@end group
3838@end smallexample
3839
3840The @code{noplt} attribute on function @code{foo}
3841tells the compiler to assume that
3842the function @code{foo} is externally defined and that the call to
3843@code{foo} must avoid the PLT
3844in position-independent code.
3845
3846In position-dependent code, a few targets also convert calls to
3847functions that are marked to not use the PLT to use the GOT instead.
3848
d77de738
ML
3849@cindex @code{noreturn} function attribute
3850@cindex functions that never return
f33d7a88 3851@item noreturn
d77de738
ML
3852A few standard library functions, such as @code{abort} and @code{exit},
3853cannot return. GCC knows this automatically. Some programs define
3854their own functions that never return. You can declare them
3855@code{noreturn} to tell the compiler this fact. For example,
3856
3857@smallexample
3858@group
3859void fatal () __attribute__ ((noreturn));
3860
3861void
3862fatal (/* @r{@dots{}} */)
3863@{
3864 /* @r{@dots{}} */ /* @r{Print error message.} */ /* @r{@dots{}} */
3865 exit (1);
3866@}
3867@end group
3868@end smallexample
3869
3870The @code{noreturn} keyword tells the compiler to assume that
3871@code{fatal} cannot return. It can then optimize without regard to what
3872would happen if @code{fatal} ever did return. This makes slightly
3873better code. More importantly, it helps avoid spurious warnings of
3874uninitialized variables.
3875
3876The @code{noreturn} keyword does not affect the exceptional path when that
3877applies: a @code{noreturn}-marked function may still return to the caller
3878by throwing an exception or calling @code{longjmp}.
3879
3880In order to preserve backtraces, GCC will never turn calls to
3881@code{noreturn} functions into tail calls.
3882
3883Do not assume that registers saved by the calling function are
3884restored before calling the @code{noreturn} function.
3885
3886It does not make sense for a @code{noreturn} function to have a return
3887type other than @code{void}.
3888
d77de738 3889@cindex @code{nothrow} function attribute
f33d7a88 3890@item nothrow
d77de738
ML
3891The @code{nothrow} attribute is used to inform the compiler that a
3892function cannot throw an exception. For example, most functions in
3893the standard C library can be guaranteed not to throw an exception
3894with the notable exceptions of @code{qsort} and @code{bsearch} that
3895take function pointer arguments.
3896
f33d7a88 3897@cindex @code{optimize} function attribute
d77de738
ML
3898@item optimize (@var{level}, @dots{})
3899@item optimize (@var{string}, @dots{})
d77de738
ML
3900The @code{optimize} attribute is used to specify that a function is to
3901be compiled with different optimization options than specified on the
3902command line. The optimize attribute arguments of a function behave
d4e8523b 3903as if appended to the command-line.
d77de738
ML
3904
3905Valid arguments are constant non-negative integers and
3906strings. Each numeric argument specifies an optimization @var{level}.
3907Each @var{string} argument consists of one or more comma-separated
3908substrings. Each substring that begins with the letter @code{O} refers
3909to an optimization option such as @option{-O0} or @option{-Os}. Other
3910substrings are taken as suffixes to the @code{-f} prefix jointly
3911forming the name of an optimization option. @xref{Optimize Options}.
3912
3913@samp{#pragma GCC optimize} can be used to set optimization options
3914for more than one function. @xref{Function Specific Option Pragmas},
3915for details about the pragma.
3916
3917Providing multiple strings as arguments separated by commas to specify
3918multiple options is equivalent to separating the option suffixes with
3919a comma (@samp{,}) within a single string. Spaces are not permitted
3920within the strings.
3921
3922Not every optimization option that starts with the @var{-f} prefix
3923specified by the attribute necessarily has an effect on the function.
3924The @code{optimize} attribute should be used for debugging purposes only.
3925It is not suitable in production code.
3926
d77de738
ML
3927@cindex @code{patchable_function_entry} function attribute
3928@cindex extra NOP instructions at the function entry point
f33d7a88 3929@item patchable_function_entry
d77de738
ML
3930In case the target's text segment can be made writable at run time by
3931any means, padding the function entry with a number of NOPs can be
3932used to provide a universal tool for instrumentation.
3933
3934The @code{patchable_function_entry} function attribute can be used to
3935change the number of NOPs to any desired value. The two-value syntax
3936is the same as for the command-line switch
3937@option{-fpatchable-function-entry=N,M}, generating @var{N} NOPs, with
3938the function entry point before the @var{M}th NOP instruction.
3939@var{M} defaults to 0 if omitted e.g.@: function entry point is before
3940the first NOP.
3941
3942If patchable function entries are enabled globally using the command-line
3943option @option{-fpatchable-function-entry=N,M}, then you must disable
3944instrumentation on all functions that are part of the instrumentation
3945framework with the attribute @code{patchable_function_entry (0)}
3946to prevent recursion.
3947
d77de738
ML
3948@cindex @code{pure} function attribute
3949@cindex functions that have no side effects
f33d7a88 3950@item pure
d77de738
ML
3951
3952Calls to functions that have no observable effects on the state of
3953the program other than to return a value may lend themselves to optimizations
3954such as common subexpression elimination. Declaring such functions with
3955the @code{pure} attribute allows GCC to avoid emitting some calls in repeated
3956invocations of the function with the same argument values.
3957
3958The @code{pure} attribute prohibits a function from modifying the state
3959of the program that is observable by means other than inspecting
3960the function's return value. However, functions declared with the @code{pure}
3961attribute can safely read any non-volatile objects, and modify the value of
3962objects in a way that does not affect their return value or the observable
3963state of the program.
3964
3965For example,
3966
3967@smallexample
3968int hash (char *) __attribute__ ((pure));
3969@end smallexample
3970
3971@noindent
3972tells GCC that subsequent calls to the function @code{hash} with the same
3973string can be replaced by the result of the first call provided the state
3974of the program observable by @code{hash}, including the contents of the array
3975itself, does not change in between. Even though @code{hash} takes a non-const
3976pointer argument it must not modify the array it points to, or any other object
3977whose value the rest of the program may depend on. However, the caller may
3978safely change the contents of the array between successive calls to
3979the function (doing so disables the optimization). The restriction also
3980applies to member objects referenced by the @code{this} pointer in C++
3981non-static member functions.
3982
3983Some common examples of pure functions are @code{strlen} or @code{memcmp}.
3984Interesting non-pure functions are functions with infinite loops or those
3985depending on volatile memory or other system resource, that may change between
3986consecutive calls (such as the standard C @code{feof} function in
3987a multithreading environment).
3988
3989The @code{pure} attribute imposes similar but looser restrictions on
3990a function's definition than the @code{const} attribute: @code{pure}
3991allows the function to read any non-volatile memory, even if it changes
3992in between successive invocations of the function. Declaring the same
3993function with both the @code{pure} and the @code{const} attribute is
3994diagnosed. Because a pure function cannot have any observable side
3995effects it does not make sense for such a function to return @code{void}.
3996Declaring such a function is diagnosed.
3997
d77de738 3998@cindex @code{returns_nonnull} function attribute
f33d7a88 3999@item returns_nonnull
d77de738
ML
4000The @code{returns_nonnull} attribute specifies that the function
4001return value should be a non-null pointer. For instance, the declaration:
4002
4003@smallexample
4004extern void *
4005mymalloc (size_t len) __attribute__((returns_nonnull));
4006@end smallexample
4007
4008@noindent
4009lets the compiler optimize callers based on the knowledge
4010that the return value will never be null.
4011
d77de738
ML
4012@cindex @code{returns_twice} function attribute
4013@cindex functions that return more than once
f33d7a88 4014@item returns_twice
d77de738
ML
4015The @code{returns_twice} attribute tells the compiler that a function may
4016return more than one time. The compiler ensures that all registers
4017are dead before calling such a function and emits a warning about
4018the variables that may be clobbered after the second return from the
4019function. Examples of such functions are @code{setjmp} and @code{vfork}.
4020The @code{longjmp}-like counterpart of such function, if any, might need
4021to be marked with the @code{noreturn} attribute.
4022
d77de738
ML
4023@cindex @code{section} function attribute
4024@cindex functions in arbitrary sections
f33d7a88 4025@item section ("@var{section-name}")
d77de738
ML
4026Normally, the compiler places the code it generates in the @code{text} section.
4027Sometimes, however, you need additional sections, or you need certain
4028particular functions to appear in special sections. The @code{section}
4029attribute specifies that a function lives in a particular section.
4030For example, the declaration:
4031
4032@smallexample
4033extern void foobar (void) __attribute__ ((section ("bar")));
4034@end smallexample
4035
4036@noindent
4037puts the function @code{foobar} in the @code{bar} section.
4038
4039Some file formats do not support arbitrary sections so the @code{section}
4040attribute is not available on all platforms.
4041If you need to map the entire contents of a module to a particular
4042section, consider using the facilities of the linker instead.
4043
f33d7a88 4044@cindex @code{sentinel} function attribute
d77de738
ML
4045@item sentinel
4046@itemx sentinel (@var{position})
d77de738
ML
4047This function attribute indicates that an argument in a call to the function
4048is expected to be an explicit @code{NULL}. The attribute is only valid on
4049variadic functions. By default, the sentinel is expected to be the last
4050argument of the function call. If the optional @var{position} argument
4051is specified to the attribute, the sentinel must be located at
4052@var{position} counting backwards from the end of the argument list.
4053
4054@smallexample
4055__attribute__ ((sentinel))
4056is equivalent to
4057__attribute__ ((sentinel(0)))
4058@end smallexample
4059
4060The attribute is automatically set with a position of 0 for the built-in
4061functions @code{execl} and @code{execlp}. The built-in function
4062@code{execle} has the attribute set with a position of 1.
4063
4064A valid @code{NULL} in this context is defined as zero with any object
4065pointer type. If your system defines the @code{NULL} macro with
4066an integer type then you need to add an explicit cast. During
4067installation GCC replaces the system @code{<stddef.h>} header with
4068a copy that redefines NULL appropriately.
4069
4070The warnings for missing or incorrect sentinels are enabled with
4071@option{-Wformat}.
4072
f33d7a88 4073@cindex @code{simd} function attribute
d77de738
ML
4074@item simd
4075@itemx simd("@var{mask}")
d77de738
ML
4076This attribute enables creation of one or more function versions that
4077can process multiple arguments using SIMD instructions from a
4078single invocation. Specifying this attribute allows compiler to
4079assume that such versions are available at link time (provided
4080in the same or another translation unit). Generated versions are
4081target-dependent and described in the corresponding Vector ABI document. For
4082x86_64 target this document can be found
4083@w{@uref{https://sourceware.org/glibc/wiki/libmvec?action=AttachFile&do=view&target=VectorABI.txt,here}}.
4084
4085The optional argument @var{mask} may have the value
4086@code{notinbranch} or @code{inbranch},
4087and instructs the compiler to generate non-masked or masked
4088clones correspondingly. By default, all clones are generated.
4089
4090If the attribute is specified and @code{#pragma omp declare simd} is
4091present on a declaration and the @option{-fopenmp} or @option{-fopenmp-simd}
4092switch is specified, then the attribute is ignored.
4093
d77de738 4094@cindex @code{stack_protect} function attribute
f33d7a88 4095@item stack_protect
d77de738
ML
4096This attribute adds stack protection code to the function if
4097flags @option{-fstack-protector}, @option{-fstack-protector-strong}
4098or @option{-fstack-protector-explicit} are set.
4099
d77de738 4100@cindex @code{no_stack_protector} function attribute
f33d7a88 4101@item no_stack_protector
d77de738
ML
4102This attribute prevents stack protection code for the function.
4103
d77de738 4104@cindex @code{target} function attribute
f33d7a88 4105@item target (@var{string}, @dots{})
d77de738
ML
4106Multiple target back ends implement the @code{target} attribute
4107to specify that a function is to
4108be compiled with different target options than specified on the
4109command line. The original target command-line options are ignored.
4110One or more strings can be provided as arguments.
4111Each string consists of one or more comma-separated suffixes to
4112the @code{-m} prefix jointly forming the name of a machine-dependent
4113option. @xref{Submodel Options,,Machine-Dependent Options}.
4114
4115The @code{target} attribute can be used for instance to have a function
4116compiled with a different ISA (instruction set architecture) than the
4117default. @samp{#pragma GCC target} can be used to specify target-specific
4118options for more than one function. @xref{Function Specific Option Pragmas},
4119for details about the pragma.
4120
4121For instance, on an x86, you could declare one function with the
4122@code{target("sse4.1,arch=core2")} attribute and another with
4123@code{target("sse4a,arch=amdfam10")}. This is equivalent to
4124compiling the first function with @option{-msse4.1} and
4125@option{-march=core2} options, and the second function with
4126@option{-msse4a} and @option{-march=amdfam10} options. It is up to you
4127to make sure that a function is only invoked on a machine that
4128supports the particular ISA it is compiled for (for example by using
4129@code{cpuid} on x86 to determine what feature bits and architecture
4130family are used).
4131
4132@smallexample
4133int core2_func (void) __attribute__ ((__target__ ("arch=core2")));
4134int sse3_func (void) __attribute__ ((__target__ ("sse3")));
4135@end smallexample
4136
4137Providing multiple strings as arguments separated by commas to specify
4138multiple options is equivalent to separating the option suffixes with
4139a comma (@samp{,}) within a single string. Spaces are not permitted
4140within the strings.
4141
4142The options supported are specific to each target; refer to @ref{x86
4143Function Attributes}, @ref{PowerPC Function Attributes},
4144@ref{ARM Function Attributes}, @ref{AArch64 Function Attributes},
4145@ref{Nios II Function Attributes}, and @ref{S/390 Function Attributes}
4146for details.
4147
d77de738 4148@cindex @code{symver} function attribute
f33d7a88 4149@item symver ("@var{name2}@@@var{nodename}")
d77de738
ML
4150On ELF targets this attribute creates a symbol version. The @var{name2} part
4151of the parameter is the actual name of the symbol by which it will be
4152externally referenced. The @code{nodename} portion should be the name of a
4153node specified in the version script supplied to the linker when building a
4154shared library. Versioned symbol must be defined and must be exported with
4155default visibility.
4156
4157@smallexample
4158__attribute__ ((__symver__ ("foo@@VERS_1"))) int
4159foo_v1 (void)
4160@{
4161@}
4162@end smallexample
4163
4164Will produce a @code{.symver foo_v1, foo@@VERS_1} directive in the assembler
4165output.
4166
4167One can also define multiple version for a given symbol
4168(starting from binutils 2.35).
4169
4170@smallexample
4171__attribute__ ((__symver__ ("foo@@VERS_2"), __symver__ ("foo@@VERS_3")))
4172int symver_foo_v1 (void)
4173@{
4174@}
4175@end smallexample
4176
4177This example creates a symbol name @code{symver_foo_v1}
4178which will be version @code{VERS_2} and @code{VERS_3} of @code{foo}.
4179
4180If you have an older release of binutils, then symbol alias needs to
4181be used:
4182
4183@smallexample
4184__attribute__ ((__symver__ ("foo@@VERS_2")))
4185int foo_v1 (void)
4186@{
4187 return 0;
4188@}
4189
4190__attribute__ ((__symver__ ("foo@@VERS_3")))
4191__attribute__ ((alias ("foo_v1")))
4192int symver_foo_v1 (void);
4193@end smallexample
4194
4195Finally if the parameter is @code{"@var{name2}@@@@@var{nodename}"} then in
4196addition to creating a symbol version (as if
4197@code{"@var{name2}@@@var{nodename}"} was used) the version will be also used
4198to resolve @var{name2} by the linker.
4199
d77de738 4200@cindex @code{tainted_args} function attribute
f33d7a88 4201@item tainted_args
d77de738
ML
4202The @code{tainted_args} attribute is used to specify that a function is called
4203in a way that requires sanitization of its arguments, such as a system
4204call in an operating system kernel. Such a function can be considered part
4205of the ``attack surface'' of the program. The attribute can be used both
4206on function declarations, and on field declarations containing function
4207pointers. In the latter case, any function used as an initializer of
4208such a callback field will be treated as being called with tainted
4209arguments.
4210
83b210d5
DM
4211The analyzer will pay particular attention to such functions when
4212@option{-fanalyzer} is supplied, potentially issuing warnings guarded by
d77de738
ML
4213@option{-Wanalyzer-tainted-allocation-size},
4214@option{-Wanalyzer-tainted-array-index},
4215@option{-Wanalyzer-tainted-divisor},
4216@option{-Wanalyzer-tainted-offset},
4217and @option{-Wanalyzer-tainted-size}.
4218
d77de738 4219@cindex @code{target_clones} function attribute
f33d7a88 4220@item target_clones (@var{options})
d77de738
ML
4221The @code{target_clones} attribute is used to specify that a function
4222be cloned into multiple versions compiled with different target options
4223than specified on the command line. The supported options and restrictions
4224are the same as for @code{target} attribute.
4225
4226For instance, on an x86, you could compile a function with
4227@code{target_clones("sse4.1,avx")}. GCC creates two function clones,
4228one compiled with @option{-msse4.1} and another with @option{-mavx}.
4229
4230On a PowerPC, you can compile a function with
4231@code{target_clones("cpu=power9,default")}. GCC will create two
4232function clones, one compiled with @option{-mcpu=power9} and another
4233with the default options. GCC must be configured to use GLIBC 2.23 or
4234newer in order to use the @code{target_clones} attribute.
4235
4236It also creates a resolver function (see
4237the @code{ifunc} attribute above) that dynamically selects a clone
4238suitable for current architecture. The resolver is created only if there
4239is a usage of a function with @code{target_clones} attribute.
4240
4241Note that any subsequent call of a function without @code{target_clone}
4242from a @code{target_clone} caller will not lead to copying
4243(target clone) of the called function.
4244If you want to enforce such behaviour,
4245we recommend declaring the calling function with the @code{flatten} attribute?
4246
d77de738 4247@cindex @code{unused} function attribute
f33d7a88 4248@item unused
d77de738
ML
4249This attribute, attached to a function, means that the function is meant
4250to be possibly unused. GCC does not produce a warning for this
4251function.
4252
d77de738 4253@cindex @code{used} function attribute
f33d7a88 4254@item used
d77de738
ML
4255This attribute, attached to a function, means that code must be emitted
4256for the function even if it appears that the function is not referenced.
4257This is useful, for example, when the function is referenced only in
4258inline assembly.
4259
4260When applied to a member function of a C++ class template, the
4261attribute also means that the function is instantiated if the
4262class itself is instantiated.
4263
d77de738 4264@cindex @code{retain} function attribute
f33d7a88 4265@item retain
d77de738
ML
4266For ELF targets that support the GNU or FreeBSD OSABIs, this attribute
4267will save the function from linker garbage collection. To support
4268this behavior, functions that have not been placed in specific sections
4269(e.g. by the @code{section} attribute, or the @code{-ffunction-sections}
4270option), will be placed in new, unique sections.
4271
4272This additional functionality requires Binutils version 2.36 or later.
4273
d77de738 4274@cindex @code{visibility} function attribute
f33d7a88 4275@item visibility ("@var{visibility_type}")
d77de738
ML
4276This attribute affects the linkage of the declaration to which it is attached.
4277It can be applied to variables (@pxref{Common Variable Attributes}) and types
4278(@pxref{Common Type Attributes}) as well as functions.
4279
4280There are four supported @var{visibility_type} values: default,
4281hidden, protected or internal visibility.
4282
4283@smallexample
4284void __attribute__ ((visibility ("protected")))
4285f () @{ /* @r{Do something.} */; @}
4286int i __attribute__ ((visibility ("hidden")));
4287@end smallexample
4288
4289The possible values of @var{visibility_type} correspond to the
4290visibility settings in the ELF gABI.
4291
4292@table @code
4293@c keep this list of visibilities in alphabetical order.
4294
4295@item default
4296Default visibility is the normal case for the object file format.
4297This value is available for the visibility attribute to override other
4298options that may change the assumed visibility of entities.
4299
4300On ELF, default visibility means that the declaration is visible to other
4301modules and, in shared libraries, means that the declared entity may be
4302overridden.
4303
4304On Darwin, default visibility means that the declaration is visible to
4305other modules.
4306
4307Default visibility corresponds to ``external linkage'' in the language.
4308
4309@item hidden
4310Hidden visibility indicates that the entity declared has a new
4311form of linkage, which we call ``hidden linkage''. Two
4312declarations of an object with hidden linkage refer to the same object
4313if they are in the same shared object.
4314
4315@item internal
4316Internal visibility is like hidden visibility, but with additional
4317processor specific semantics. Unless otherwise specified by the
4318psABI, GCC defines internal visibility to mean that a function is
4319@emph{never} called from another module. Compare this with hidden
4320functions which, while they cannot be referenced directly by other
4321modules, can be referenced indirectly via function pointers. By
4322indicating that a function cannot be called from outside the module,
4323GCC may for instance omit the load of a PIC register since it is known
4324that the calling function loaded the correct value.
4325
4326@item protected
4327Protected visibility is like default visibility except that it
4328indicates that references within the defining module bind to the
4329definition in that module. That is, the declared entity cannot be
4330overridden by another module.
4331
4332@end table
4333
4334All visibilities are supported on many, but not all, ELF targets
4335(supported when the assembler supports the @samp{.visibility}
4336pseudo-op). Default visibility is supported everywhere. Hidden
4337visibility is supported on Darwin targets.
4338
4339The visibility attribute should be applied only to declarations that
4340would otherwise have external linkage. The attribute should be applied
4341consistently, so that the same entity should not be declared with
4342different settings of the attribute.
4343
4344In C++, the visibility attribute applies to types as well as functions
4345and objects, because in C++ types have linkage. A class must not have
4346greater visibility than its non-static data member types and bases,
4347and class members default to the visibility of their class. Also, a
4348declaration without explicit visibility is limited to the visibility
4349of its type.
4350
4351In C++, you can mark member functions and static member variables of a
4352class with the visibility attribute. This is useful if you know a
4353particular method or static member variable should only be used from
4354one shared object; then you can mark it hidden while the rest of the
4355class has default visibility. Care must be taken to avoid breaking
4356the One Definition Rule; for example, it is usually not useful to mark
4357an inline method as hidden without marking the whole class as hidden.
4358
4359A C++ namespace declaration can also have the visibility attribute.
4360
4361@smallexample
4362namespace nspace1 __attribute__ ((visibility ("protected")))
4363@{ /* @r{Do something.} */; @}
4364@end smallexample
4365
4366This attribute applies only to the particular namespace body, not to
4367other definitions of the same namespace; it is equivalent to using
4368@samp{#pragma GCC visibility} before and after the namespace
4369definition (@pxref{Visibility Pragmas}).
4370
4371In C++, if a template argument has limited visibility, this
4372restriction is implicitly propagated to the template instantiation.
4373Otherwise, template instantiations and specializations default to the
4374visibility of their template.
4375
4376If both the template and enclosing class have explicit visibility, the
4377visibility from the template is used.
4378
d77de738 4379@cindex @code{warn_unused_result} function attribute
f33d7a88 4380@item warn_unused_result
d77de738
ML
4381The @code{warn_unused_result} attribute causes a warning to be emitted
4382if a caller of the function with this attribute does not use its
4383return value. This is useful for functions where not checking
4384the result is either a security problem or always a bug, such as
4385@code{realloc}.
4386
4387@smallexample
4388int fn () __attribute__ ((warn_unused_result));
4389int foo ()
4390@{
4391 if (fn () < 0) return -1;
4392 fn ();
4393 return 0;
4394@}
4395@end smallexample
4396
4397@noindent
4398results in warning on line 5.
4399
d77de738 4400@cindex @code{weak} function attribute
f33d7a88 4401@item weak
d77de738
ML
4402The @code{weak} attribute causes a declaration of an external symbol
4403to be emitted as a weak symbol rather than a global. This is primarily
4404useful in defining library functions that can be overridden in user code,
4405though it can also be used with non-function declarations. The overriding
4406symbol must have the same type as the weak symbol. In addition, if it
4407designates a variable it must also have the same size and alignment as
4408the weak symbol. Weak symbols are supported for ELF targets, and also
4409for a.out targets when using the GNU assembler and linker.
4410
f33d7a88 4411@cindex @code{weakref} function attribute
d77de738
ML
4412@item weakref
4413@itemx weakref ("@var{target}")
d77de738
ML
4414The @code{weakref} attribute marks a declaration as a weak reference.
4415Without arguments, it should be accompanied by an @code{alias} attribute
4416naming the target symbol. Alternatively, @var{target} may be given as
4417an argument to @code{weakref} itself, naming the target definition of
4418the alias. The @var{target} must have the same type as the declaration.
4419In addition, if it designates a variable it must also have the same size
4420and alignment as the declaration. In either form of the declaration
4421@code{weakref} implicitly marks the declared symbol as @code{weak}. Without
4422a @var{target} given as an argument to @code{weakref} or to @code{alias},
4423@code{weakref} is equivalent to @code{weak} (in that case the declaration
4424may be @code{extern}).
4425
4426@smallexample
4427/* Given the declaration: */
4428extern int y (void);
4429
4430/* the following... */
4431static int x (void) __attribute__ ((weakref ("y")));
4432
4433/* is equivalent to... */
4434static int x (void) __attribute__ ((weakref, alias ("y")));
4435
4436/* or, alternatively, to... */
4437static int x (void) __attribute__ ((weakref));
4438static int x (void) __attribute__ ((alias ("y")));
4439@end smallexample
4440
4441A weak reference is an alias that does not by itself require a
4442definition to be given for the target symbol. If the target symbol is
4443only referenced through weak references, then it becomes a @code{weak}
4444undefined symbol. If it is directly referenced, however, then such
4445strong references prevail, and a definition is required for the
4446symbol, not necessarily in the same translation unit.
4447
4448The effect is equivalent to moving all references to the alias to a
4449separate translation unit, renaming the alias to the aliased symbol,
4450declaring it as weak, compiling the two separate translation units and
4451performing a link with relocatable output (i.e.@: @code{ld -r}) on them.
4452
4453A declaration to which @code{weakref} is attached and that is associated
4454with a named @code{target} must be @code{static}.
4455
d77de738 4456@cindex @code{zero_call_used_regs} function attribute
f33d7a88 4457@item zero_call_used_regs ("@var{choice}")
d77de738
ML
4458
4459The @code{zero_call_used_regs} attribute causes the compiler to zero
4460a subset of all call-used registers@footnote{A ``call-used'' register
4461is a register whose contents can be changed by a function call;
4462therefore, a caller cannot assume that the register has the same contents
4463on return from the function as it had before calling the function. Such
4464registers are also called ``call-clobbered'', ``caller-saved'', or
4465``volatile''.} at function return.
4466This is used to increase program security by either mitigating
4467Return-Oriented Programming (ROP) attacks or preventing information leakage
4468through registers.
4469
4470In order to satisfy users with different security needs and control the
4471run-time overhead at the same time, the @var{choice} parameter provides a
4472flexible way to choose the subset of the call-used registers to be zeroed.
83f69969 4473The four basic values of @var{choice} are:
d77de738
ML
4474
4475@itemize @bullet
4476@item
4477@samp{skip} doesn't zero any call-used registers.
4478
4479@item
4480@samp{used} only zeros call-used registers that are used in the function.
4481A ``used'' register is one whose content has been set or referenced in
4482the function.
4483
4484@item
4485@samp{all} zeros all call-used registers.
83f69969
AO
4486
4487@item
4488@samp{leafy} behaves like @samp{used} in a leaf function, and like
4489@samp{all} in a nonleaf function. This makes for leaner zeroing in leaf
4490functions, where the set of used registers is known, and that may be
4491enough for some purposes of register zeroing.
d77de738
ML
4492@end itemize
4493
4494In addition to these three basic choices, it is possible to modify
83f69969 4495@samp{used}, @samp{all}, and @samp{leafy} as follows:
d77de738
ML
4496
4497@itemize @bullet
4498@item
4499Adding @samp{-gpr} restricts the zeroing to general-purpose registers.
4500
4501@item
4502Adding @samp{-arg} restricts the zeroing to registers that can sometimes
4503be used to pass function arguments. This includes all argument registers
4504defined by the platform's calling conversion, regardless of whether the
4505function uses those registers for function arguments or not.
4506@end itemize
4507
4508The modifiers can be used individually or together. If they are used
4509together, they must appear in the order above.
4510
4511The full list of @var{choice}s is therefore:
4512
4513@table @code
4514@item skip
4515doesn't zero any call-used register.
4516
4517@item used
4518only zeros call-used registers that are used in the function.
4519
4520@item used-gpr
4521only zeros call-used general purpose registers that are used in the function.
4522
4523@item used-arg
4524only zeros call-used registers that are used in the function and pass arguments.
4525
4526@item used-gpr-arg
4527only zeros call-used general purpose registers that are used in the function
4528and pass arguments.
4529
4530@item all
4531zeros all call-used registers.
4532
4533@item all-gpr
4534zeros all call-used general purpose registers.
4535
4536@item all-arg
4537zeros all call-used registers that pass arguments.
4538
4539@item all-gpr-arg
4540zeros all call-used general purpose registers that pass
4541arguments.
83f69969
AO
4542
4543@item leafy
4544Same as @samp{used} in a leaf function, and same as @samp{all} in a
4545nonleaf function.
4546
4547@item leafy-gpr
4548Same as @samp{used-gpr} in a leaf function, and same as @samp{all-gpr}
4549in a nonleaf function.
4550
4551@item leafy-arg
4552Same as @samp{used-arg} in a leaf function, and same as @samp{all-arg}
4553in a nonleaf function.
4554
4555@item leafy-gpr-arg
4556Same as @samp{used-gpr-arg} in a leaf function, and same as
4557@samp{all-gpr-arg} in a nonleaf function.
4558
d77de738
ML
4559@end table
4560
4561Of this list, @samp{used-arg}, @samp{used-gpr-arg}, @samp{all-arg},
83f69969
AO
4562@samp{all-gpr-arg}, @samp{leafy-arg}, and @samp{leafy-gpr-arg} are
4563mainly used for ROP mitigation.
d77de738
ML
4564
4565The default for the attribute is controlled by @option{-fzero-call-used-regs}.
4566@end table
4567
4568@c This is the end of the target-independent attribute table
4569
4570@node AArch64 Function Attributes
4571@subsection AArch64 Function Attributes
4572
4573The following target-specific function attributes are available for the
4574AArch64 target. For the most part, these options mirror the behavior of
4575similar command-line options (@pxref{AArch64 Options}), but on a
4576per-function basis.
4577
4578@table @code
d77de738 4579@cindex @code{general-regs-only} function attribute, AArch64
f33d7a88 4580@item general-regs-only
d77de738
ML
4581Indicates that no floating-point or Advanced SIMD registers should be
4582used when generating code for this function. If the function explicitly
4583uses floating-point code, then the compiler gives an error. This is
4584the same behavior as that of the command-line option
4585@option{-mgeneral-regs-only}.
4586
d77de738 4587@cindex @code{fix-cortex-a53-835769} function attribute, AArch64
f33d7a88 4588@item fix-cortex-a53-835769
d77de738
ML
4589Indicates that the workaround for the Cortex-A53 erratum 835769 should be
4590applied to this function. To explicitly disable the workaround for this
4591function specify the negated form: @code{no-fix-cortex-a53-835769}.
4592This corresponds to the behavior of the command line options
4593@option{-mfix-cortex-a53-835769} and @option{-mno-fix-cortex-a53-835769}.
4594
d77de738 4595@cindex @code{cmodel=} function attribute, AArch64
f33d7a88 4596@item cmodel=
d77de738
ML
4597Indicates that code should be generated for a particular code model for
4598this function. The behavior and permissible arguments are the same as
4599for the command line option @option{-mcmodel=}.
4600
f33d7a88 4601@cindex @code{strict-align} function attribute, AArch64
d77de738
ML
4602@item strict-align
4603@itemx no-strict-align
d77de738
ML
4604@code{strict-align} indicates that the compiler should not assume that unaligned
4605memory references are handled by the system. To allow the compiler to assume
4606that aligned memory references are handled by the system, the inverse attribute
4607@code{no-strict-align} can be specified. The behavior is same as for the
4608command-line option @option{-mstrict-align} and @option{-mno-strict-align}.
4609
d77de738 4610@cindex @code{omit-leaf-frame-pointer} function attribute, AArch64
f33d7a88 4611@item omit-leaf-frame-pointer
d77de738
ML
4612Indicates that the frame pointer should be omitted for a leaf function call.
4613To keep the frame pointer, the inverse attribute
4614@code{no-omit-leaf-frame-pointer} can be specified. These attributes have
4615the same behavior as the command-line options @option{-momit-leaf-frame-pointer}
4616and @option{-mno-omit-leaf-frame-pointer}.
4617
d77de738 4618@cindex @code{tls-dialect=} function attribute, AArch64
f33d7a88 4619@item tls-dialect=
d77de738
ML
4620Specifies the TLS dialect to use for this function. The behavior and
4621permissible arguments are the same as for the command-line option
4622@option{-mtls-dialect=}.
4623
d77de738 4624@cindex @code{arch=} function attribute, AArch64
f33d7a88 4625@item arch=
d77de738
ML
4626Specifies the architecture version and architectural extensions to use
4627for this function. The behavior and permissible arguments are the same as
4628for the @option{-march=} command-line option.
4629
d77de738 4630@cindex @code{tune=} function attribute, AArch64
f33d7a88 4631@item tune=
d77de738
ML
4632Specifies the core for which to tune the performance of this function.
4633The behavior and permissible arguments are the same as for the @option{-mtune=}
4634command-line option.
4635
d77de738 4636@cindex @code{cpu=} function attribute, AArch64
f33d7a88 4637@item cpu=
d77de738
ML
4638Specifies the core for which to tune the performance of this function and also
4639whose architectural features to use. The behavior and valid arguments are the
4640same as for the @option{-mcpu=} command-line option.
4641
d77de738 4642@cindex @code{sign-return-address} function attribute, AArch64
f33d7a88 4643@item sign-return-address
d77de738
ML
4644Select the function scope on which return address signing will be applied. The
4645behavior and permissible arguments are the same as for the command-line option
4646@option{-msign-return-address=}. The default value is @code{none}. This
4647attribute is deprecated. The @code{branch-protection} attribute should
4648be used instead.
4649
d77de738 4650@cindex @code{branch-protection} function attribute, AArch64
f33d7a88 4651@item branch-protection
d77de738
ML
4652Select the function scope on which branch protection will be applied. The
4653behavior and permissible arguments are the same as for the command-line option
4654@option{-mbranch-protection=}. The default value is @code{none}.
4655
d77de738 4656@cindex @code{outline-atomics} function attribute, AArch64
f33d7a88 4657@item outline-atomics
d77de738
ML
4658Enable or disable calls to out-of-line helpers to implement atomic operations.
4659This corresponds to the behavior of the command line options
4660@option{-moutline-atomics} and @option{-mno-outline-atomics}.
4661
4662@end table
4663
4664The above target attributes can be specified as follows:
4665
4666@smallexample
4667__attribute__((target("@var{attr-string}")))
4668int
4669f (int a)
4670@{
4671 return a + 5;
4672@}
4673@end smallexample
4674
4675where @code{@var{attr-string}} is one of the attribute strings specified above.
4676
4677Additionally, the architectural extension string may be specified on its
4678own. This can be used to turn on and off particular architectural extensions
4679without having to specify a particular architecture version or core. Example:
4680
4681@smallexample
4682__attribute__((target("+crc+nocrypto")))
4683int
4684foo (int a)
4685@{
4686 return a + 5;
4687@}
4688@end smallexample
4689
4690In this example @code{target("+crc+nocrypto")} enables the @code{crc}
4691extension and disables the @code{crypto} extension for the function @code{foo}
4692without modifying an existing @option{-march=} or @option{-mcpu} option.
4693
4694Multiple target function attributes can be specified by separating them with
4695a comma. For example:
4696@smallexample
4697__attribute__((target("arch=armv8-a+crc+crypto,tune=cortex-a53")))
4698int
4699foo (int a)
4700@{
4701 return a + 5;
4702@}
4703@end smallexample
4704
4705is valid and compiles function @code{foo} for ARMv8-A with @code{crc}
4706and @code{crypto} extensions and tunes it for @code{cortex-a53}.
4707
4708@subsubsection Inlining rules
4709Specifying target attributes on individual functions or performing link-time
4710optimization across translation units compiled with different target options
4711can affect function inlining rules:
4712
4713In particular, a caller function can inline a callee function only if the
4714architectural features available to the callee are a subset of the features
4715available to the caller.
4716For example: A function @code{foo} compiled with @option{-march=armv8-a+crc},
4717or tagged with the equivalent @code{arch=armv8-a+crc} attribute,
4718can inline a function @code{bar} compiled with @option{-march=armv8-a+nocrc}
4719because the all the architectural features that function @code{bar} requires
4720are available to function @code{foo}. Conversely, function @code{bar} cannot
4721inline function @code{foo}.
4722
4723Additionally inlining a function compiled with @option{-mstrict-align} into a
4724function compiled without @code{-mstrict-align} is not allowed.
4725However, inlining a function compiled without @option{-mstrict-align} into a
4726function compiled with @option{-mstrict-align} is allowed.
4727
4728Note that CPU tuning options and attributes such as the @option{-mcpu=},
4729@option{-mtune=} do not inhibit inlining unless the CPU specified by the
4730@option{-mcpu=} option or the @code{cpu=} attribute conflicts with the
4731architectural feature rules specified above.
4732
4733@node AMD GCN Function Attributes
4734@subsection AMD GCN Function Attributes
4735
4736These function attributes are supported by the AMD GCN back end:
4737
4738@table @code
d77de738 4739@cindex @code{amdgpu_hsa_kernel} function attribute, AMD GCN
f33d7a88 4740@item amdgpu_hsa_kernel
d77de738
ML
4741This attribute indicates that the corresponding function should be compiled as
4742a kernel function, that is an entry point that can be invoked from the host
4743via the HSA runtime library. By default functions are only callable only from
4744other GCN functions.
4745
4746This attribute is implicitly applied to any function named @code{main}, using
4747default parameters.
4748
4749Kernel functions may return an integer value, which will be written to a
4750conventional place within the HSA "kernargs" region.
4751
4752The attribute parameters configure what values are passed into the kernel
4753function by the GPU drivers, via the initial register state. Some values are
4754used by the compiler, and therefore forced on. Enabling other options may
4755break assumptions in the compiler and/or run-time libraries.
4756
4757@table @code
4758@item private_segment_buffer
4759Set @code{enable_sgpr_private_segment_buffer} flag. Always on (required to
4760locate the stack).
4761
4762@item dispatch_ptr
4763Set @code{enable_sgpr_dispatch_ptr} flag. Always on (required to locate the
4764launch dimensions).
4765
4766@item queue_ptr
4767Set @code{enable_sgpr_queue_ptr} flag. Always on (required to convert address
4768spaces).
4769
4770@item kernarg_segment_ptr
4771Set @code{enable_sgpr_kernarg_segment_ptr} flag. Always on (required to
4772locate the kernel arguments, "kernargs").
4773
4774@item dispatch_id
4775Set @code{enable_sgpr_dispatch_id} flag.
4776
4777@item flat_scratch_init
4778Set @code{enable_sgpr_flat_scratch_init} flag.
4779
4780@item private_segment_size
4781Set @code{enable_sgpr_private_segment_size} flag.
4782
4783@item grid_workgroup_count_X
4784Set @code{enable_sgpr_grid_workgroup_count_x} flag. Always on (required to
4785use OpenACC/OpenMP).
4786
4787@item grid_workgroup_count_Y
4788Set @code{enable_sgpr_grid_workgroup_count_y} flag.
4789
4790@item grid_workgroup_count_Z
4791Set @code{enable_sgpr_grid_workgroup_count_z} flag.
4792
4793@item workgroup_id_X
4794Set @code{enable_sgpr_workgroup_id_x} flag.
4795
4796@item workgroup_id_Y
4797Set @code{enable_sgpr_workgroup_id_y} flag.
4798
4799@item workgroup_id_Z
4800Set @code{enable_sgpr_workgroup_id_z} flag.
4801
4802@item workgroup_info
4803Set @code{enable_sgpr_workgroup_info} flag.
4804
4805@item private_segment_wave_offset
4806Set @code{enable_sgpr_private_segment_wave_byte_offset} flag. Always on
4807(required to locate the stack).
4808
4809@item work_item_id_X
4810Set @code{enable_vgpr_workitem_id} parameter. Always on (can't be disabled).
4811
4812@item work_item_id_Y
4813Set @code{enable_vgpr_workitem_id} parameter. Always on (required to enable
4814vectorization.)
4815
4816@item work_item_id_Z
4817Set @code{enable_vgpr_workitem_id} parameter. Always on (required to use
4818OpenACC/OpenMP).
4819
4820@end table
4821@end table
4822
4823@node ARC Function Attributes
4824@subsection ARC Function Attributes
4825
4826These function attributes are supported by the ARC back end:
4827
4828@table @code
d77de738 4829@cindex @code{interrupt} function attribute, ARC
f33d7a88 4830@item interrupt
d77de738
ML
4831Use this attribute to indicate
4832that the specified function is an interrupt handler. The compiler generates
4833function entry and exit sequences suitable for use in an interrupt handler
4834when this attribute is present.
4835
4836On the ARC, you must specify the kind of interrupt to be handled
4837in a parameter to the interrupt attribute like this:
4838
4839@smallexample
4840void f () __attribute__ ((interrupt ("ilink1")));
4841@end smallexample
4842
4843Permissible values for this parameter are: @w{@code{ilink1}} and
4844@w{@code{ilink2}} for ARCv1 architecture, and @w{@code{ilink}} and
4845@w{@code{firq}} for ARCv2 architecture.
4846
d77de738
ML
4847@cindex @code{long_call} function attribute, ARC
4848@cindex @code{medium_call} function attribute, ARC
4849@cindex @code{short_call} function attribute, ARC
4850@cindex indirect calls, ARC
f33d7a88
AA
4851@item long_call
4852@itemx medium_call
4853@itemx short_call
d77de738
ML
4854These attributes specify how a particular function is called.
4855These attributes override the
4856@option{-mlong-calls} and @option{-mmedium-calls} (@pxref{ARC Options})
4857command-line switches and @code{#pragma long_calls} settings.
4858
4859For ARC, a function marked with the @code{long_call} attribute is
4860always called using register-indirect jump-and-link instructions,
4861thereby enabling the called function to be placed anywhere within the
486232-bit address space. A function marked with the @code{medium_call}
4863attribute will always be close enough to be called with an unconditional
4864branch-and-link instruction, which has a 25-bit offset from
4865the call site. A function marked with the @code{short_call}
4866attribute will always be close enough to be called with a conditional
4867branch-and-link instruction, which has a 21-bit offset from
4868the call site.
4869
d77de738 4870@cindex @code{jli_always} function attribute, ARC
f33d7a88 4871@item jli_always
d77de738
ML
4872Forces a particular function to be called using @code{jli}
4873instruction. The @code{jli} instruction makes use of a table stored
4874into @code{.jlitab} section, which holds the location of the functions
4875which are addressed using this instruction.
4876
d77de738 4877@cindex @code{jli_fixed} function attribute, ARC
f33d7a88 4878@item jli_fixed
d77de738
ML
4879Identical like the above one, but the location of the function in the
4880@code{jli} table is known and given as an attribute parameter.
4881
d77de738 4882@cindex @code{secure_call} function attribute, ARC
f33d7a88 4883@item secure_call
d77de738
ML
4884This attribute allows one to mark secure-code functions that are
4885callable from normal mode. The location of the secure call function
4886into the @code{sjli} table needs to be passed as argument.
4887
d77de738 4888@cindex @code{naked} function attribute, ARC
f33d7a88 4889@item naked
d77de738
ML
4890This attribute allows the compiler to construct the requisite function
4891declaration, while allowing the body of the function to be assembly
4892code. The specified function will not have prologue/epilogue
4893sequences generated by the compiler. Only basic @code{asm} statements
4894can safely be included in naked functions (@pxref{Basic Asm}). While
4895using extended @code{asm} or a mixture of basic @code{asm} and C code
4896may appear to work, they cannot be depended upon to work reliably and
4897are not supported.
4898
4899@end table
4900
4901@node ARM Function Attributes
4902@subsection ARM Function Attributes
4903
4904These function attributes are supported for ARM targets:
4905
4906@table @code
4907
d77de738 4908@cindex @code{general-regs-only} function attribute, ARM
f33d7a88 4909@item general-regs-only
d77de738
ML
4910Indicates that no floating-point or Advanced SIMD registers should be
4911used when generating code for this function. If the function explicitly
4912uses floating-point code, then the compiler gives an error. This is
4913the same behavior as that of the command-line option
4914@option{-mgeneral-regs-only}.
4915
d77de738 4916@cindex @code{interrupt} function attribute, ARM
f33d7a88 4917@item interrupt
d77de738
ML
4918Use this attribute to indicate
4919that the specified function is an interrupt handler. The compiler generates
4920function entry and exit sequences suitable for use in an interrupt handler
4921when this attribute is present.
4922
4923You can specify the kind of interrupt to be handled by
4924adding an optional parameter to the interrupt attribute like this:
4925
4926@smallexample
4927void f () __attribute__ ((interrupt ("IRQ")));
4928@end smallexample
4929
4930@noindent
4931Permissible values for this parameter are: @code{IRQ}, @code{FIQ},
4932@code{SWI}, @code{ABORT} and @code{UNDEF}.
4933
4934On ARMv7-M the interrupt type is ignored, and the attribute means the function
4935may be called with a word-aligned stack pointer.
4936
d77de738 4937@cindex @code{isr} function attribute, ARM
f33d7a88 4938@item isr
d77de738
ML
4939Use this attribute on ARM to write Interrupt Service Routines. This is an
4940alias to the @code{interrupt} attribute above.
4941
d77de738
ML
4942@cindex @code{long_call} function attribute, ARM
4943@cindex @code{short_call} function attribute, ARM
4944@cindex indirect calls, ARM
f33d7a88
AA
4945@item long_call
4946@itemx short_call
d77de738
ML
4947These attributes specify how a particular function is called.
4948These attributes override the
4949@option{-mlong-calls} (@pxref{ARM Options})
4950command-line switch and @code{#pragma long_calls} settings. For ARM, the
4951@code{long_call} attribute indicates that the function might be far
4952away from the call site and require a different (more expensive)
4953calling sequence. The @code{short_call} attribute always places
4954the offset to the function from the call site into the @samp{BL}
4955instruction directly.
4956
d77de738 4957@cindex @code{naked} function attribute, ARM
f33d7a88 4958@item naked
d77de738
ML
4959This attribute allows the compiler to construct the
4960requisite function declaration, while allowing the body of the
4961function to be assembly code. The specified function will not have
4962prologue/epilogue sequences generated by the compiler. Only basic
4963@code{asm} statements can safely be included in naked functions
4964(@pxref{Basic Asm}). While using extended @code{asm} or a mixture of
4965basic @code{asm} and C code may appear to work, they cannot be
4966depended upon to work reliably and are not supported.
4967
d77de738 4968@cindex @code{pcs} function attribute, ARM
f33d7a88 4969@item pcs
d77de738
ML
4970
4971The @code{pcs} attribute can be used to control the calling convention
4972used for a function on ARM. The attribute takes an argument that specifies
4973the calling convention to use.
4974
4975When compiling using the AAPCS ABI (or a variant of it) then valid
4976values for the argument are @code{"aapcs"} and @code{"aapcs-vfp"}. In
4977order to use a variant other than @code{"aapcs"} then the compiler must
4978be permitted to use the appropriate co-processor registers (i.e., the
4979VFP registers must be available in order to use @code{"aapcs-vfp"}).
4980For example,
4981
4982@smallexample
4983/* Argument passed in r0, and result returned in r0+r1. */
4984double f2d (float) __attribute__((pcs("aapcs")));
4985@end smallexample
4986
4987Variadic functions always use the @code{"aapcs"} calling convention and
4988the compiler rejects attempts to specify an alternative.
4989
d77de738 4990@cindex @code{target} function attribute
f33d7a88 4991@item target (@var{options})
d77de738
ML
4992As discussed in @ref{Common Function Attributes}, this attribute
4993allows specification of target-specific compilation options.
4994
4995On ARM, the following options are allowed:
4996
4997@table @samp
d77de738 4998@cindex @code{target("thumb")} function attribute, ARM
f33d7a88 4999@item thumb
d77de738
ML
5000Force code generation in the Thumb (T16/T32) ISA, depending on the
5001architecture level.
5002
d77de738 5003@cindex @code{target("arm")} function attribute, ARM
f33d7a88 5004@item arm
d77de738
ML
5005Force code generation in the ARM (A32) ISA.
5006
5007Functions from different modes can be inlined in the caller's mode.
5008
d77de738 5009@cindex @code{target("fpu=")} function attribute, ARM
f33d7a88 5010@item fpu=
d77de738
ML
5011Specifies the fpu for which to tune the performance of this function.
5012The behavior and permissible arguments are the same as for the @option{-mfpu=}
5013command-line option.
5014
d77de738 5015@cindex @code{arch=} function attribute, ARM
f33d7a88 5016@item arch=
d77de738
ML
5017Specifies the architecture version and architectural extensions to use
5018for this function. The behavior and permissible arguments are the same as
5019for the @option{-march=} command-line option.
5020
5021The above target attributes can be specified as follows:
5022
5023@smallexample
5024__attribute__((target("arch=armv8-a+crc")))
5025int
5026f (int a)
5027@{
5028 return a + 5;
5029@}
5030@end smallexample
5031
5032Additionally, the architectural extension string may be specified on its
5033own. This can be used to turn on and off particular architectural extensions
5034without having to specify a particular architecture version or core. Example:
5035
5036@smallexample
5037__attribute__((target("+crc+nocrypto")))
5038int
5039foo (int a)
5040@{
5041 return a + 5;
5042@}
5043@end smallexample
5044
5045In this example @code{target("+crc+nocrypto")} enables the @code{crc}
5046extension and disables the @code{crypto} extension for the function @code{foo}
5047without modifying an existing @option{-march=} or @option{-mcpu} option.
5048
5049@end table
5050
5051@end table
5052
5053@node AVR Function Attributes
5054@subsection AVR Function Attributes
5055
5056These function attributes are supported by the AVR back end:
5057
5058@table @code
d77de738 5059@cindex @code{interrupt} function attribute, AVR
f33d7a88 5060@item interrupt
d77de738
ML
5061Use this attribute to indicate
5062that the specified function is an interrupt handler. The compiler generates
5063function entry and exit sequences suitable for use in an interrupt handler
5064when this attribute is present.
5065
5066On the AVR, the hardware globally disables interrupts when an
5067interrupt is executed. The first instruction of an interrupt handler
5068declared with this attribute is a @code{SEI} instruction to
5069re-enable interrupts. See also the @code{signal} function attribute
5070that does not insert a @code{SEI} instruction. If both @code{signal} and
5071@code{interrupt} are specified for the same function, @code{signal}
5072is silently ignored.
5073
d77de738 5074@cindex @code{naked} function attribute, AVR
f33d7a88 5075@item naked
d77de738
ML
5076This attribute allows the compiler to construct the
5077requisite function declaration, while allowing the body of the
5078function to be assembly code. The specified function will not have
5079prologue/epilogue sequences generated by the compiler. Only basic
5080@code{asm} statements can safely be included in naked functions
5081(@pxref{Basic Asm}). While using extended @code{asm} or a mixture of
5082basic @code{asm} and C code may appear to work, they cannot be
5083depended upon to work reliably and are not supported.
5084
d77de738 5085@cindex @code{no_gccisr} function attribute, AVR
f33d7a88 5086@item no_gccisr
d77de738
ML
5087Do not use @code{__gcc_isr} pseudo instructions in a function with
5088the @code{interrupt} or @code{signal} attribute aka. interrupt
5089service routine (ISR).
5090Use this attribute if the preamble of the ISR prologue should always read
5091@example
5092push __zero_reg__
5093push __tmp_reg__
5094in __tmp_reg__, __SREG__
5095push __tmp_reg__
5096clr __zero_reg__
5097@end example
5098and accordingly for the postamble of the epilogue --- no matter whether
5099the mentioned registers are actually used in the ISR or not.
5100Situations where you might want to use this attribute include:
5101@itemize @bullet
5102@item
5103Code that (effectively) clobbers bits of @code{SREG} other than the
5104@code{I}-flag by writing to the memory location of @code{SREG}.
5105@item
5106Code that uses inline assembler to jump to a different function which
5107expects (parts of) the prologue code as outlined above to be present.
5108@end itemize
5109To disable @code{__gcc_isr} generation for the whole compilation unit,
5110there is option @option{-mno-gas-isr-prologues}, @pxref{AVR Options}.
5111
d77de738
ML
5112@cindex @code{OS_main} function attribute, AVR
5113@cindex @code{OS_task} function attribute, AVR
f33d7a88
AA
5114@item OS_main
5115@itemx OS_task
d77de738
ML
5116On AVR, functions with the @code{OS_main} or @code{OS_task} attribute
5117do not save/restore any call-saved register in their prologue/epilogue.
5118
5119The @code{OS_main} attribute can be used when there @emph{is
5120guarantee} that interrupts are disabled at the time when the function
5121is entered. This saves resources when the stack pointer has to be
5122changed to set up a frame for local variables.
5123
5124The @code{OS_task} attribute can be used when there is @emph{no
5125guarantee} that interrupts are disabled at that time when the function
5126is entered like for, e@.g@. task functions in a multi-threading operating
5127system. In that case, changing the stack pointer register is
5128guarded by save/clear/restore of the global interrupt enable flag.
5129
5130The differences to the @code{naked} function attribute are:
5131@itemize @bullet
5132@item @code{naked} functions do not have a return instruction whereas
5133@code{OS_main} and @code{OS_task} functions have a @code{RET} or
5134@code{RETI} return instruction.
5135@item @code{naked} functions do not set up a frame for local variables
5136or a frame pointer whereas @code{OS_main} and @code{OS_task} do this
5137as needed.
5138@end itemize
5139
d77de738 5140@cindex @code{signal} function attribute, AVR
f33d7a88 5141@item signal
d77de738
ML
5142Use this attribute on the AVR to indicate that the specified
5143function is an interrupt handler. The compiler generates function
5144entry and exit sequences suitable for use in an interrupt handler when this
5145attribute is present.
5146
5147See also the @code{interrupt} function attribute.
5148
5149The AVR hardware globally disables interrupts when an interrupt is executed.
5150Interrupt handler functions defined with the @code{signal} attribute
5151do not re-enable interrupts. It is save to enable interrupts in a
5152@code{signal} handler. This ``save'' only applies to the code
5153generated by the compiler and not to the IRQ layout of the
5154application which is responsibility of the application.
5155
5156If both @code{signal} and @code{interrupt} are specified for the same
5157function, @code{signal} is silently ignored.
5158@end table
5159
5160@node Blackfin Function Attributes
5161@subsection Blackfin Function Attributes
5162
5163These function attributes are supported by the Blackfin back end:
5164
5165@table @code
5166
d77de738
ML
5167@cindex @code{exception_handler} function attribute
5168@cindex exception handler functions, Blackfin
f33d7a88 5169@item exception_handler
d77de738
ML
5170Use this attribute on the Blackfin to indicate that the specified function
5171is an exception handler. The compiler generates function entry and
5172exit sequences suitable for use in an exception handler when this
5173attribute is present.
5174
d77de738 5175@cindex @code{interrupt_handler} function attribute, Blackfin
f33d7a88 5176@item interrupt_handler
d77de738
ML
5177Use this attribute to
5178indicate that the specified function is an interrupt handler. The compiler
5179generates function entry and exit sequences suitable for use in an
5180interrupt handler when this attribute is present.
5181
d77de738
ML
5182@cindex @code{kspisusp} function attribute, Blackfin
5183@cindex User stack pointer in interrupts on the Blackfin
f33d7a88 5184@item kspisusp
d77de738
ML
5185When used together with @code{interrupt_handler}, @code{exception_handler}
5186or @code{nmi_handler}, code is generated to load the stack pointer
5187from the USP register in the function prologue.
5188
d77de738 5189@cindex @code{l1_text} function attribute, Blackfin
f33d7a88 5190@item l1_text
d77de738
ML
5191This attribute specifies a function to be placed into L1 Instruction
5192SRAM@. The function is put into a specific section named @code{.l1.text}.
5193With @option{-mfdpic}, function calls with a such function as the callee
5194or caller uses inlined PLT.
5195
d77de738 5196@cindex @code{l2} function attribute, Blackfin
f33d7a88 5197@item l2
d77de738
ML
5198This attribute specifies a function to be placed into L2
5199SRAM. The function is put into a specific section named
5200@code{.l2.text}. With @option{-mfdpic}, callers of such functions use
5201an inlined PLT.
5202
d77de738
ML
5203@cindex indirect calls, Blackfin
5204@cindex @code{longcall} function attribute, Blackfin
5205@cindex @code{shortcall} function attribute, Blackfin
f33d7a88
AA
5206@item longcall
5207@itemx shortcall
d77de738
ML
5208The @code{longcall} attribute
5209indicates that the function might be far away from the call site and
5210require a different (more expensive) calling sequence. The
5211@code{shortcall} attribute indicates that the function is always close
5212enough for the shorter calling sequence to be used. These attributes
5213override the @option{-mlongcall} switch.
5214
d77de738
ML
5215@cindex @code{nesting} function attribute, Blackfin
5216@cindex Allow nesting in an interrupt handler on the Blackfin processor
f33d7a88 5217@item nesting
d77de738
ML
5218Use this attribute together with @code{interrupt_handler},
5219@code{exception_handler} or @code{nmi_handler} to indicate that the function
5220entry code should enable nested interrupts or exceptions.
5221
d77de738
ML
5222@cindex @code{nmi_handler} function attribute, Blackfin
5223@cindex NMI handler functions on the Blackfin processor
f33d7a88 5224@item nmi_handler
d77de738
ML
5225Use this attribute on the Blackfin to indicate that the specified function
5226is an NMI handler. The compiler generates function entry and
5227exit sequences suitable for use in an NMI handler when this
5228attribute is present.
5229
d77de738
ML
5230@cindex @code{saveall} function attribute, Blackfin
5231@cindex save all registers on the Blackfin
f33d7a88 5232@item saveall
d77de738
ML
5233Use this attribute to indicate that
5234all registers except the stack pointer should be saved in the prologue
5235regardless of whether they are used or not.
5236@end table
5237
5238@node BPF Function Attributes
5239@subsection BPF Function Attributes
5240
5241These function attributes are supported by the BPF back end:
5242
5243@table @code
d77de738 5244@cindex @code{kernel helper}, function attribute, BPF
f33d7a88 5245@item kernel_helper
d77de738
ML
5246use this attribute to indicate the specified function declaration is a
5247kernel helper. The helper function is passed as an argument to the
5248attribute. Example:
5249
5250@smallexample
5251int bpf_probe_read (void *dst, int size, const void *unsafe_ptr)
5252 __attribute__ ((kernel_helper (4)));
5253@end smallexample
b7c50f68
JM
5254
5255@cindex @code{naked} function attribute, BPF
5256@item naked
5257This attribute allows the compiler to construct the requisite function
5258declaration, while allowing the body of the function to be assembly
5259code. The specified function will not have prologue/epilogue
5260sequences generated by the compiler. Only basic @code{asm} statements
5261can safely be included in naked functions (@pxref{Basic Asm}). While
5262using extended @code{asm} or a mixture of basic @code{asm} and C code
5263may appear to work, they cannot be depended upon to work reliably and
5264are not supported.
d77de738
ML
5265@end table
5266
5267@node C-SKY Function Attributes
5268@subsection C-SKY Function Attributes
5269
5270These function attributes are supported by the C-SKY back end:
5271
5272@table @code
d77de738
ML
5273@cindex @code{interrupt} function attribute, C-SKY
5274@cindex @code{isr} function attribute, C-SKY
f33d7a88
AA
5275@item interrupt
5276@itemx isr
d77de738
ML
5277Use these attributes to indicate that the specified function
5278is an interrupt handler.
5279The compiler generates function entry and exit sequences suitable for
5280use in an interrupt handler when either of these attributes are present.
5281
5282Use of these options requires the @option{-mistack} command-line option
5283to enable support for the necessary interrupt stack instructions. They
5284are ignored with a warning otherwise. @xref{C-SKY Options}.
5285
d77de738 5286@cindex @code{naked} function attribute, C-SKY
f33d7a88 5287@item naked
d77de738
ML
5288This attribute allows the compiler to construct the
5289requisite function declaration, while allowing the body of the
5290function to be assembly code. The specified function will not have
5291prologue/epilogue sequences generated by the compiler. Only basic
5292@code{asm} statements can safely be included in naked functions
5293(@pxref{Basic Asm}). While using extended @code{asm} or a mixture of
5294basic @code{asm} and C code may appear to work, they cannot be
5295depended upon to work reliably and are not supported.
5296@end table
5297
5298
5299@node Epiphany Function Attributes
5300@subsection Epiphany Function Attributes
5301
5302These function attributes are supported by the Epiphany back end:
5303
5304@table @code
d77de738 5305@cindex @code{disinterrupt} function attribute, Epiphany
f33d7a88 5306@item disinterrupt
d77de738
ML
5307This attribute causes the compiler to emit
5308instructions to disable interrupts for the duration of the given
5309function.
5310
d77de738 5311@cindex @code{forwarder_section} function attribute, Epiphany
f33d7a88 5312@item forwarder_section
d77de738
ML
5313This attribute modifies the behavior of an interrupt handler.
5314The interrupt handler may be in external memory which cannot be
5315reached by a branch instruction, so generate a local memory trampoline
5316to transfer control. The single parameter identifies the section where
5317the trampoline is placed.
5318
d77de738 5319@cindex @code{interrupt} function attribute, Epiphany
f33d7a88 5320@item interrupt
d77de738
ML
5321Use this attribute to indicate
5322that the specified function is an interrupt handler. The compiler generates
5323function entry and exit sequences suitable for use in an interrupt handler
5324when this attribute is present. It may also generate
5325a special section with code to initialize the interrupt vector table.
5326
5327On Epiphany targets one or more optional parameters can be added like this:
5328
5329@smallexample
5330void __attribute__ ((interrupt ("dma0, dma1"))) universal_dma_handler ();
5331@end smallexample
5332
5333Permissible values for these parameters are: @w{@code{reset}},
5334@w{@code{software_exception}}, @w{@code{page_miss}},
5335@w{@code{timer0}}, @w{@code{timer1}}, @w{@code{message}},
5336@w{@code{dma0}}, @w{@code{dma1}}, @w{@code{wand}} and @w{@code{swi}}.
5337Multiple parameters indicate that multiple entries in the interrupt
5338vector table should be initialized for this function, i.e.@: for each
5339parameter @w{@var{name}}, a jump to the function is emitted in
5340the section @w{ivt_entry_@var{name}}. The parameter(s) may be omitted
5341entirely, in which case no interrupt vector table entry is provided.
5342
5343Note that interrupts are enabled inside the function
5344unless the @code{disinterrupt} attribute is also specified.
5345
5346The following examples are all valid uses of these attributes on
5347Epiphany targets:
5348@smallexample
5349void __attribute__ ((interrupt)) universal_handler ();
5350void __attribute__ ((interrupt ("dma1"))) dma1_handler ();
5351void __attribute__ ((interrupt ("dma0, dma1")))
5352 universal_dma_handler ();
5353void __attribute__ ((interrupt ("timer0"), disinterrupt))
5354 fast_timer_handler ();
5355void __attribute__ ((interrupt ("dma0, dma1"),
5356 forwarder_section ("tramp")))
5357 external_dma_handler ();
5358@end smallexample
5359
d77de738
ML
5360@cindex @code{long_call} function attribute, Epiphany
5361@cindex @code{short_call} function attribute, Epiphany
5362@cindex indirect calls, Epiphany
f33d7a88
AA
5363@item long_call
5364@itemx short_call
d77de738
ML
5365These attributes specify how a particular function is called.
5366These attributes override the
5367@option{-mlong-calls} (@pxref{Adapteva Epiphany Options})
5368command-line switch and @code{#pragma long_calls} settings.
5369@end table
5370
5371
5372@node H8/300 Function Attributes
5373@subsection H8/300 Function Attributes
5374
5375These function attributes are available for H8/300 targets:
5376
5377@table @code
d77de738 5378@cindex @code{function_vector} function attribute, H8/300
f33d7a88 5379@item function_vector
d77de738
ML
5380Use this attribute on the H8/300, H8/300H, and H8S to indicate
5381that the specified function should be called through the function vector.
5382Calling a function through the function vector reduces code size; however,
5383the function vector has a limited size (maximum 128 entries on the H8/300
5384and 64 entries on the H8/300H and H8S)
5385and shares space with the interrupt vector.
5386
d77de738 5387@cindex @code{interrupt_handler} function attribute, H8/300
f33d7a88 5388@item interrupt_handler
d77de738
ML
5389Use this attribute on the H8/300, H8/300H, and H8S to
5390indicate that the specified function is an interrupt handler. The compiler
5391generates function entry and exit sequences suitable for use in an
5392interrupt handler when this attribute is present.
5393
d77de738
ML
5394@cindex @code{saveall} function attribute, H8/300
5395@cindex save all registers on the H8/300, H8/300H, and H8S
f33d7a88 5396@item saveall
d77de738
ML
5397Use this attribute on the H8/300, H8/300H, and H8S to indicate that
5398all registers except the stack pointer should be saved in the prologue
5399regardless of whether they are used or not.
5400@end table
5401
5402@node IA-64 Function Attributes
5403@subsection IA-64 Function Attributes
5404
5405These function attributes are supported on IA-64 targets:
5406
5407@table @code
d77de738 5408@cindex @code{syscall_linkage} function attribute, IA-64
f33d7a88 5409@item syscall_linkage
d77de738
ML
5410This attribute is used to modify the IA-64 calling convention by marking
5411all input registers as live at all function exits. This makes it possible
5412to restart a system call after an interrupt without having to save/restore
5413the input registers. This also prevents kernel data from leaking into
5414application code.
5415
d77de738 5416@cindex @code{version_id} function attribute, IA-64
f33d7a88 5417@item version_id
d77de738
ML
5418This IA-64 HP-UX attribute, attached to a global variable or function, renames a
5419symbol to contain a version string, thus allowing for function level
5420versioning. HP-UX system header files may use function level versioning
5421for some system calls.
5422
5423@smallexample
5424extern int foo () __attribute__((version_id ("20040821")));
5425@end smallexample
5426
5427@noindent
5428Calls to @code{foo} are mapped to calls to @code{foo@{20040821@}}.
5429@end table
5430
5431@node M32C Function Attributes
5432@subsection M32C Function Attributes
5433
5434These function attributes are supported by the M32C back end:
5435
5436@table @code
d77de738 5437@cindex @code{bank_switch} function attribute, M32C
f33d7a88 5438@item bank_switch
d77de738
ML
5439When added to an interrupt handler with the M32C port, causes the
5440prologue and epilogue to use bank switching to preserve the registers
5441rather than saving them on the stack.
5442
d77de738 5443@cindex @code{fast_interrupt} function attribute, M32C
f33d7a88 5444@item fast_interrupt
d77de738
ML
5445Use this attribute on the M32C port to indicate that the specified
5446function is a fast interrupt handler. This is just like the
5447@code{interrupt} attribute, except that @code{freit} is used to return
5448instead of @code{reit}.
5449
d77de738 5450@cindex @code{function_vector} function attribute, M16C/M32C
f33d7a88 5451@item function_vector
d77de738
ML
5452On M16C/M32C targets, the @code{function_vector} attribute declares a
5453special page subroutine call function. Use of this attribute reduces
5454the code size by 2 bytes for each call generated to the
5455subroutine. The argument to the attribute is the vector number entry
5456from the special page vector table which contains the 16 low-order
5457bits of the subroutine's entry address. Each vector table has special
5458page number (18 to 255) that is used in @code{jsrs} instructions.
5459Jump addresses of the routines are generated by adding 0x0F0000 (in
5460case of M16C targets) or 0xFF0000 (in case of M32C targets), to the
54612-byte addresses set in the vector table. Therefore you need to ensure
5462that all the special page vector routines should get mapped within the
5463address range 0x0F0000 to 0x0FFFFF (for M16C) and 0xFF0000 to 0xFFFFFF
5464(for M32C).
5465
5466In the following example 2 bytes are saved for each call to
5467function @code{foo}.
5468
5469@smallexample
5470void foo (void) __attribute__((function_vector(0x18)));
5471void foo (void)
5472@{
5473@}
5474
5475void bar (void)
5476@{
5477 foo();
5478@}
5479@end smallexample
5480
5481If functions are defined in one file and are called in another file,
5482then be sure to write this declaration in both files.
5483
5484This attribute is ignored for R8C target.
5485
d77de738 5486@cindex @code{interrupt} function attribute, M32C
f33d7a88 5487@item interrupt
d77de738
ML
5488Use this attribute to indicate
5489that the specified function is an interrupt handler. The compiler generates
5490function entry and exit sequences suitable for use in an interrupt handler
5491when this attribute is present.
5492@end table
5493
5494@node M32R/D Function Attributes
5495@subsection M32R/D Function Attributes
5496
5497These function attributes are supported by the M32R/D back end:
5498
5499@table @code
d77de738 5500@cindex @code{interrupt} function attribute, M32R/D
f33d7a88 5501@item interrupt
d77de738
ML
5502Use this attribute to indicate
5503that the specified function is an interrupt handler. The compiler generates
5504function entry and exit sequences suitable for use in an interrupt handler
5505when this attribute is present.
5506
d77de738
ML
5507@cindex @code{model} function attribute, M32R/D
5508@cindex function addressability on the M32R/D
f33d7a88 5509@item model (@var{model-name})
d77de738
ML
5510
5511On the M32R/D, use this attribute to set the addressability of an
5512object, and of the code generated for a function. The identifier
5513@var{model-name} is one of @code{small}, @code{medium}, or
5514@code{large}, representing each of the code models.
5515
5516Small model objects live in the lower 16MB of memory (so that their
5517addresses can be loaded with the @code{ld24} instruction), and are
5518callable with the @code{bl} instruction.
5519
5520Medium model objects may live anywhere in the 32-bit address space (the
5521compiler generates @code{seth/add3} instructions to load their addresses),
5522and are callable with the @code{bl} instruction.
5523
5524Large model objects may live anywhere in the 32-bit address space (the
5525compiler generates @code{seth/add3} instructions to load their addresses),
5526and may not be reachable with the @code{bl} instruction (the compiler
5527generates the much slower @code{seth/add3/jl} instruction sequence).
5528@end table
5529
5530@node m68k Function Attributes
5531@subsection m68k Function Attributes
5532
5533These function attributes are supported by the m68k back end:
5534
5535@table @code
d77de738
ML
5536@cindex @code{interrupt} function attribute, m68k
5537@cindex @code{interrupt_handler} function attribute, m68k
f33d7a88
AA
5538@item interrupt
5539@itemx interrupt_handler
d77de738
ML
5540Use this attribute to
5541indicate that the specified function is an interrupt handler. The compiler
5542generates function entry and exit sequences suitable for use in an
5543interrupt handler when this attribute is present. Either name may be used.
5544
d77de738 5545@cindex @code{interrupt_thread} function attribute, fido
f33d7a88 5546@item interrupt_thread
d77de738
ML
5547Use this attribute on fido, a subarchitecture of the m68k, to indicate
5548that the specified function is an interrupt handler that is designed
5549to run as a thread. The compiler omits generate prologue/epilogue
5550sequences and replaces the return instruction with a @code{sleep}
5551instruction. This attribute is available only on fido.
5552@end table
5553
5554@node MCORE Function Attributes
5555@subsection MCORE Function Attributes
5556
5557These function attributes are supported by the MCORE back end:
5558
5559@table @code
d77de738 5560@cindex @code{naked} function attribute, MCORE
f33d7a88 5561@item naked
d77de738
ML
5562This attribute allows the compiler to construct the
5563requisite function declaration, while allowing the body of the
5564function to be assembly code. The specified function will not have
5565prologue/epilogue sequences generated by the compiler. Only basic
5566@code{asm} statements can safely be included in naked functions
5567(@pxref{Basic Asm}). While using extended @code{asm} or a mixture of
5568basic @code{asm} and C code may appear to work, they cannot be
5569depended upon to work reliably and are not supported.
5570@end table
5571
d77de738
ML
5572@node MicroBlaze Function Attributes
5573@subsection MicroBlaze Function Attributes
5574
5575These function attributes are supported on MicroBlaze targets:
5576
5577@table @code
d77de738 5578@cindex @code{save_volatiles} function attribute, MicroBlaze
f33d7a88 5579@item save_volatiles
d77de738
ML
5580Use this attribute to indicate that the function is
5581an interrupt handler. All volatile registers (in addition to non-volatile
5582registers) are saved in the function prologue. If the function is a leaf
5583function, only volatiles used by the function are saved. A normal function
5584return is generated instead of a return from interrupt.
5585
d77de738
ML
5586@cindex @code{break_handler} function attribute, MicroBlaze
5587@cindex break handler functions
f33d7a88 5588@item break_handler
d77de738
ML
5589Use this attribute to indicate that
5590the specified function is a break handler. The compiler generates function
5591entry and exit sequences suitable for use in an break handler when this
5592attribute is present. The return from @code{break_handler} is done through
5593the @code{rtbd} instead of @code{rtsd}.
5594
5595@smallexample
5596void f () __attribute__ ((break_handler));
5597@end smallexample
5598
d77de738
ML
5599@cindex @code{interrupt_handler} function attribute, MicroBlaze
5600@cindex @code{fast_interrupt} function attribute, MicroBlaze
f33d7a88
AA
5601@item interrupt_handler
5602@itemx fast_interrupt
d77de738
ML
5603These attributes indicate that the specified function is an interrupt
5604handler. Use the @code{fast_interrupt} attribute to indicate handlers
5605used in low-latency interrupt mode, and @code{interrupt_handler} for
5606interrupts that do not use low-latency handlers. In both cases, GCC
5607emits appropriate prologue code and generates a return from the handler
5608using @code{rtid} instead of @code{rtsd}.
5609@end table
5610
5611@node Microsoft Windows Function Attributes
5612@subsection Microsoft Windows Function Attributes
5613
5614The following attributes are available on Microsoft Windows and Symbian OS
5615targets.
5616
5617@table @code
d77de738
ML
5618@cindex @code{dllexport} function attribute
5619@cindex @code{__declspec(dllexport)}
f33d7a88 5620@item dllexport
d77de738
ML
5621On Microsoft Windows targets and Symbian OS targets the
5622@code{dllexport} attribute causes the compiler to provide a global
5623pointer to a pointer in a DLL, so that it can be referenced with the
5624@code{dllimport} attribute. On Microsoft Windows targets, the pointer
5625name is formed by combining @code{_imp__} and the function or variable
5626name.
5627
5628You can use @code{__declspec(dllexport)} as a synonym for
5629@code{__attribute__ ((dllexport))} for compatibility with other
5630compilers.
5631
5632On systems that support the @code{visibility} attribute, this
5633attribute also implies ``default'' visibility. It is an error to
5634explicitly specify any other visibility.
5635
5636GCC's default behavior is to emit all inline functions with the
5637@code{dllexport} attribute. Since this can cause object file-size bloat,
5638you can use @option{-fno-keep-inline-dllexport}, which tells GCC to
5639ignore the attribute for inlined functions unless the
5640@option{-fkeep-inline-functions} flag is used instead.
5641
5642The attribute is ignored for undefined symbols.
5643
5644When applied to C++ classes, the attribute marks defined non-inlined
5645member functions and static data members as exports. Static consts
5646initialized in-class are not marked unless they are also defined
5647out-of-class.
5648
5649For Microsoft Windows targets there are alternative methods for
5650including the symbol in the DLL's export table such as using a
5651@file{.def} file with an @code{EXPORTS} section or, with GNU ld, using
5652the @option{--export-all} linker flag.
5653
d77de738
ML
5654@cindex @code{dllimport} function attribute
5655@cindex @code{__declspec(dllimport)}
f33d7a88 5656@item dllimport
d77de738
ML
5657On Microsoft Windows and Symbian OS targets, the @code{dllimport}
5658attribute causes the compiler to reference a function or variable via
5659a global pointer to a pointer that is set up by the DLL exporting the
5660symbol. The attribute implies @code{extern}. On Microsoft Windows
5661targets, the pointer name is formed by combining @code{_imp__} and the
5662function or variable name.
5663
5664You can use @code{__declspec(dllimport)} as a synonym for
5665@code{__attribute__ ((dllimport))} for compatibility with other
5666compilers.
5667
5668On systems that support the @code{visibility} attribute, this
5669attribute also implies ``default'' visibility. It is an error to
5670explicitly specify any other visibility.
5671
5672Currently, the attribute is ignored for inlined functions. If the
5673attribute is applied to a symbol @emph{definition}, an error is reported.
5674If a symbol previously declared @code{dllimport} is later defined, the
5675attribute is ignored in subsequent references, and a warning is emitted.
5676The attribute is also overridden by a subsequent declaration as
5677@code{dllexport}.
5678
5679When applied to C++ classes, the attribute marks non-inlined
5680member functions and static data members as imports. However, the
5681attribute is ignored for virtual methods to allow creation of vtables
5682using thunks.
5683
5684On the SH Symbian OS target the @code{dllimport} attribute also has
5685another affect---it can cause the vtable and run-time type information
5686for a class to be exported. This happens when the class has a
5687dllimported constructor or a non-inline, non-pure virtual function
5688and, for either of those two conditions, the class also has an inline
5689constructor or destructor and has a key function that is defined in
5690the current translation unit.
5691
5692For Microsoft Windows targets the use of the @code{dllimport}
5693attribute on functions is not necessary, but provides a small
5694performance benefit by eliminating a thunk in the DLL@. The use of the
5695@code{dllimport} attribute on imported variables can be avoided by passing the
5696@option{--enable-auto-import} switch to the GNU linker. As with
5697functions, using the attribute for a variable eliminates a thunk in
5698the DLL@.
5699
5700One drawback to using this attribute is that a pointer to a
5701@emph{variable} marked as @code{dllimport} cannot be used as a constant
5702address. However, a pointer to a @emph{function} with the
5703@code{dllimport} attribute can be used as a constant initializer; in
5704this case, the address of a stub function in the import lib is
5705referenced. On Microsoft Windows targets, the attribute can be disabled
5706for functions by setting the @option{-mnop-fun-dllimport} flag.
5707@end table
5708
5709@node MIPS Function Attributes
5710@subsection MIPS Function Attributes
5711
5712These function attributes are supported by the MIPS back end:
5713
5714@table @code
d77de738 5715@cindex @code{interrupt} function attribute, MIPS
f33d7a88 5716@item interrupt
d77de738
ML
5717Use this attribute to indicate that the specified function is an interrupt
5718handler. The compiler generates function entry and exit sequences suitable
5719for use in an interrupt handler when this attribute is present.
5720An optional argument is supported for the interrupt attribute which allows
5721the interrupt mode to be described. By default GCC assumes the external
5722interrupt controller (EIC) mode is in use, this can be explicitly set using
5723@code{eic}. When interrupts are non-masked then the requested Interrupt
5724Priority Level (IPL) is copied to the current IPL which has the effect of only
5725enabling higher priority interrupts. To use vectored interrupt mode use
5726the argument @code{vector=[sw0|sw1|hw0|hw1|hw2|hw3|hw4|hw5]}, this will change
5727the behavior of the non-masked interrupt support and GCC will arrange to mask
5728all interrupts from sw0 up to and including the specified interrupt vector.
5729
5730You can use the following attributes to modify the behavior
5731of an interrupt handler:
5732@table @code
d77de738 5733@cindex @code{use_shadow_register_set} function attribute, MIPS
f33d7a88 5734@item use_shadow_register_set
d77de738
ML
5735Assume that the handler uses a shadow register set, instead of
5736the main general-purpose registers. An optional argument @code{intstack} is
5737supported to indicate that the shadow register set contains a valid stack
5738pointer.
5739
d77de738 5740@cindex @code{keep_interrupts_masked} function attribute, MIPS
f33d7a88 5741@item keep_interrupts_masked
d77de738
ML
5742Keep interrupts masked for the whole function. Without this attribute,
5743GCC tries to reenable interrupts for as much of the function as it can.
5744
d77de738 5745@cindex @code{use_debug_exception_return} function attribute, MIPS
f33d7a88 5746@item use_debug_exception_return
d77de738
ML
5747Return using the @code{deret} instruction. Interrupt handlers that don't
5748have this attribute return using @code{eret} instead.
5749@end table
5750
5751You can use any combination of these attributes, as shown below:
5752@smallexample
5753void __attribute__ ((interrupt)) v0 ();
5754void __attribute__ ((interrupt, use_shadow_register_set)) v1 ();
5755void __attribute__ ((interrupt, keep_interrupts_masked)) v2 ();
5756void __attribute__ ((interrupt, use_debug_exception_return)) v3 ();
5757void __attribute__ ((interrupt, use_shadow_register_set,
5758 keep_interrupts_masked)) v4 ();
5759void __attribute__ ((interrupt, use_shadow_register_set,
5760 use_debug_exception_return)) v5 ();
5761void __attribute__ ((interrupt, keep_interrupts_masked,
5762 use_debug_exception_return)) v6 ();
5763void __attribute__ ((interrupt, use_shadow_register_set,
5764 keep_interrupts_masked,
5765 use_debug_exception_return)) v7 ();
5766void __attribute__ ((interrupt("eic"))) v8 ();
5767void __attribute__ ((interrupt("vector=hw3"))) v9 ();
5768@end smallexample
5769
d77de738
ML
5770@cindex indirect calls, MIPS
5771@cindex @code{long_call} function attribute, MIPS
5772@cindex @code{short_call} function attribute, MIPS
5773@cindex @code{near} function attribute, MIPS
5774@cindex @code{far} function attribute, MIPS
f33d7a88
AA
5775@item long_call
5776@itemx short_call
5777@itemx near
5778@itemx far
d77de738
ML
5779These attributes specify how a particular function is called on MIPS@.
5780The attributes override the @option{-mlong-calls} (@pxref{MIPS Options})
5781command-line switch. The @code{long_call} and @code{far} attributes are
5782synonyms, and cause the compiler to always call
5783the function by first loading its address into a register, and then using
5784the contents of that register. The @code{short_call} and @code{near}
5785attributes are synonyms, and have the opposite
5786effect; they specify that non-PIC calls should be made using the more
5787efficient @code{jal} instruction.
5788
d77de738
ML
5789@cindex @code{mips16} function attribute, MIPS
5790@cindex @code{nomips16} function attribute, MIPS
f33d7a88
AA
5791@item mips16
5792@itemx nomips16
d77de738
ML
5793
5794On MIPS targets, you can use the @code{mips16} and @code{nomips16}
5795function attributes to locally select or turn off MIPS16 code generation.
5796A function with the @code{mips16} attribute is emitted as MIPS16 code,
5797while MIPS16 code generation is disabled for functions with the
5798@code{nomips16} attribute. These attributes override the
5799@option{-mips16} and @option{-mno-mips16} options on the command line
5800(@pxref{MIPS Options}).
5801
5802When compiling files containing mixed MIPS16 and non-MIPS16 code, the
5803preprocessor symbol @code{__mips16} reflects the setting on the command line,
5804not that within individual functions. Mixed MIPS16 and non-MIPS16 code
5805may interact badly with some GCC extensions such as @code{__builtin_apply}
5806(@pxref{Constructing Calls}).
5807
d77de738
ML
5808@cindex @code{micromips} function attribute
5809@cindex @code{nomicromips} function attribute
f33d7a88
AA
5810@item micromips, MIPS
5811@itemx nomicromips, MIPS
d77de738
ML
5812
5813On MIPS targets, you can use the @code{micromips} and @code{nomicromips}
5814function attributes to locally select or turn off microMIPS code generation.
5815A function with the @code{micromips} attribute is emitted as microMIPS code,
5816while microMIPS code generation is disabled for functions with the
5817@code{nomicromips} attribute. These attributes override the
5818@option{-mmicromips} and @option{-mno-micromips} options on the command line
5819(@pxref{MIPS Options}).
5820
5821When compiling files containing mixed microMIPS and non-microMIPS code, the
5822preprocessor symbol @code{__mips_micromips} reflects the setting on the
5823command line,
5824not that within individual functions. Mixed microMIPS and non-microMIPS code
5825may interact badly with some GCC extensions such as @code{__builtin_apply}
5826(@pxref{Constructing Calls}).
5827
d77de738 5828@cindex @code{nocompression} function attribute, MIPS
f33d7a88 5829@item nocompression
d77de738
ML
5830On MIPS targets, you can use the @code{nocompression} function attribute
5831to locally turn off MIPS16 and microMIPS code generation. This attribute
5832overrides the @option{-mips16} and @option{-mmicromips} options on the
5833command line (@pxref{MIPS Options}).
a3a45f0b 5834
a3a45f0b 5835@cindex @code{use_hazard_barrier_return} function attribute, MIPS
e54b01a1 5836@item use_hazard_barrier_return
a3a45f0b
JZ
5837This function attribute instructs the compiler to generate a hazard barrier
5838return that clears all execution and instruction hazards while returning,
5839instead of generating a normal return instruction.
65864221
SD
5840
5841@item code_readable
5842@cindex @code{code_readable} function attribute, MIPS
5843For MIPS targets that support PC-relative addressing modes, this attribute
5844can be used to control how an object is addressed. The attribute takes
5845a single optional argument:
5846
5847@table @samp
5848@item no
5849The function should not read the instruction stream as data.
5850@item yes
5851The function can read the instruction stream as data.
5852@item pcrel
5853The function can read the instruction stream in a pc-relative mode.
5854@end table
5855
5856If there is no argument supplied, the default of @code{"yes"} applies.
d77de738
ML
5857@end table
5858
5859@node MSP430 Function Attributes
5860@subsection MSP430 Function Attributes
5861
5862These function attributes are supported by the MSP430 back end:
5863
5864@table @code
d77de738 5865@cindex @code{critical} function attribute, MSP430
f33d7a88 5866@item critical
d77de738
ML
5867Critical functions disable interrupts upon entry and restore the
5868previous interrupt state upon exit. Critical functions cannot also
5869have the @code{naked}, @code{reentrant} or @code{interrupt} attributes.
5870
5871The MSP430 hardware ensures that interrupts are disabled on entry to
5872@code{interrupt} functions, and restores the previous interrupt state
5873on exit. The @code{critical} attribute is therefore redundant on
5874@code{interrupt} functions.
5875
d77de738 5876@cindex @code{interrupt} function attribute, MSP430
f33d7a88 5877@item interrupt
d77de738
ML
5878Use this attribute to indicate
5879that the specified function is an interrupt handler. The compiler generates
5880function entry and exit sequences suitable for use in an interrupt handler
5881when this attribute is present.
5882
5883You can provide an argument to the interrupt
5884attribute which specifies a name or number. If the argument is a
5885number it indicates the slot in the interrupt vector table (0 - 31) to
5886which this handler should be assigned. If the argument is a name it
5887is treated as a symbolic name for the vector slot. These names should
5888match up with appropriate entries in the linker script. By default
5889the names @code{watchdog} for vector 26, @code{nmi} for vector 30 and
5890@code{reset} for vector 31 are recognized.
5891
d77de738 5892@cindex @code{naked} function attribute, MSP430
f33d7a88 5893@item naked
d77de738
ML
5894This attribute allows the compiler to construct the
5895requisite function declaration, while allowing the body of the
5896function to be assembly code. The specified function will not have
5897prologue/epilogue sequences generated by the compiler. Only basic
5898@code{asm} statements can safely be included in naked functions
5899(@pxref{Basic Asm}). While using extended @code{asm} or a mixture of
5900basic @code{asm} and C code may appear to work, they cannot be
5901depended upon to work reliably and are not supported.
5902
d77de738 5903@cindex @code{reentrant} function attribute, MSP430
f33d7a88 5904@item reentrant
d77de738
ML
5905Reentrant functions disable interrupts upon entry and enable them
5906upon exit. Reentrant functions cannot also have the @code{naked}
5907or @code{critical} attributes. They can have the @code{interrupt}
5908attribute.
5909
d77de738 5910@cindex @code{wakeup} function attribute, MSP430
f33d7a88 5911@item wakeup
d77de738
ML
5912This attribute only applies to interrupt functions. It is silently
5913ignored if applied to a non-interrupt function. A wakeup interrupt
5914function will rouse the processor from any low-power state that it
5915might be in when the function exits.
5916
d77de738
ML
5917@cindex @code{lower} function attribute, MSP430
5918@cindex @code{upper} function attribute, MSP430
5919@cindex @code{either} function attribute, MSP430
f33d7a88
AA
5920@item lower
5921@itemx upper
5922@itemx either
d77de738
ML
5923On the MSP430 target these attributes can be used to specify whether
5924the function or variable should be placed into low memory, high
5925memory, or the placement should be left to the linker to decide. The
5926attributes are only significant if compiling for the MSP430X
5927architecture in the large memory model.
5928
5929The attributes work in conjunction with a linker script that has been
5930augmented to specify where to place sections with a @code{.lower} and
5931a @code{.upper} prefix. So, for example, as well as placing the
5932@code{.data} section, the script also specifies the placement of a
5933@code{.lower.data} and a @code{.upper.data} section. The intention
5934is that @code{lower} sections are placed into a small but easier to
5935access memory region and the upper sections are placed into a larger, but
5936slower to access, region.
5937
5938The @code{either} attribute is special. It tells the linker to place
5939the object into the corresponding @code{lower} section if there is
5940room for it. If there is insufficient room then the object is placed
5941into the corresponding @code{upper} section instead. Note that the
5942placement algorithm is not very sophisticated. It does not attempt to
5943find an optimal packing of the @code{lower} sections. It just makes
5944one pass over the objects and does the best that it can. Using the
5945@option{-ffunction-sections} and @option{-fdata-sections} command-line
5946options can help the packing, however, since they produce smaller,
5947easier to pack regions.
5948@end table
5949
5950@node NDS32 Function Attributes
5951@subsection NDS32 Function Attributes
5952
5953These function attributes are supported by the NDS32 back end:
5954
5955@table @code
d77de738
ML
5956@cindex @code{exception} function attribute
5957@cindex exception handler functions, NDS32
f33d7a88 5958@item exception
d77de738
ML
5959Use this attribute on the NDS32 target to indicate that the specified function
5960is an exception handler. The compiler will generate corresponding sections
5961for use in an exception handler.
5962
d77de738 5963@cindex @code{interrupt} function attribute, NDS32
f33d7a88 5964@item interrupt
d77de738
ML
5965On NDS32 target, this attribute indicates that the specified function
5966is an interrupt handler. The compiler generates corresponding sections
5967for use in an interrupt handler. You can use the following attributes
5968to modify the behavior:
5969@table @code
d77de738 5970@cindex @code{nested} function attribute, NDS32
f33d7a88 5971@item nested
d77de738 5972This interrupt service routine is interruptible.
d77de738 5973@cindex @code{not_nested} function attribute, NDS32
f33d7a88 5974@item not_nested
d77de738 5975This interrupt service routine is not interruptible.
d77de738 5976@cindex @code{nested_ready} function attribute, NDS32
f33d7a88 5977@item nested_ready
d77de738
ML
5978This interrupt service routine is interruptible after @code{PSW.GIE}
5979(global interrupt enable) is set. This allows interrupt service routine to
5980finish some short critical code before enabling interrupts.
d77de738 5981@cindex @code{save_all} function attribute, NDS32
f33d7a88 5982@item save_all
d77de738
ML
5983The system will help save all registers into stack before entering
5984interrupt handler.
d77de738 5985@cindex @code{partial_save} function attribute, NDS32
f33d7a88 5986@item partial_save
d77de738
ML
5987The system will help save caller registers into stack before entering
5988interrupt handler.
5989@end table
5990
d77de738 5991@cindex @code{naked} function attribute, NDS32
f33d7a88 5992@item naked
d77de738
ML
5993This attribute allows the compiler to construct the
5994requisite function declaration, while allowing the body of the
5995function to be assembly code. The specified function will not have
5996prologue/epilogue sequences generated by the compiler. Only basic
5997@code{asm} statements can safely be included in naked functions
5998(@pxref{Basic Asm}). While using extended @code{asm} or a mixture of
5999basic @code{asm} and C code may appear to work, they cannot be
6000depended upon to work reliably and are not supported.
6001
d77de738
ML
6002@cindex @code{reset} function attribute, NDS32
6003@cindex reset handler functions
f33d7a88 6004@item reset
d77de738
ML
6005Use this attribute on the NDS32 target to indicate that the specified function
6006is a reset handler. The compiler will generate corresponding sections
6007for use in a reset handler. You can use the following attributes
6008to provide extra exception handling:
6009@table @code
d77de738 6010@cindex @code{nmi} function attribute, NDS32
f33d7a88 6011@item nmi
d77de738 6012Provide a user-defined function to handle NMI exception.
d77de738 6013@cindex @code{warm} function attribute, NDS32
f33d7a88 6014@item warm
d77de738
ML
6015Provide a user-defined function to handle warm reset exception.
6016@end table
6017@end table
6018
6019@node Nios II Function Attributes
6020@subsection Nios II Function Attributes
6021
6022These function attributes are supported by the Nios II back end:
6023
6024@table @code
d77de738 6025@cindex @code{target} function attribute
f33d7a88 6026@item target (@var{options})
d77de738
ML
6027As discussed in @ref{Common Function Attributes}, this attribute
6028allows specification of target-specific compilation options.
6029
6030When compiling for Nios II, the following options are allowed:
6031
6032@table @samp
d77de738
ML
6033@cindex @code{target("custom-@var{insn}=@var{N}")} function attribute, Nios II
6034@cindex @code{target("no-custom-@var{insn}")} function attribute, Nios II
f33d7a88
AA
6035@item custom-@var{insn}=@var{N}
6036@itemx no-custom-@var{insn}
d77de738
ML
6037Each @samp{custom-@var{insn}=@var{N}} attribute locally enables use of a
6038custom instruction with encoding @var{N} when generating code that uses
6039@var{insn}. Similarly, @samp{no-custom-@var{insn}} locally inhibits use of
6040the custom instruction @var{insn}.
6041These target attributes correspond to the
6042@option{-mcustom-@var{insn}=@var{N}} and @option{-mno-custom-@var{insn}}
6043command-line options, and support the same set of @var{insn} keywords.
6044@xref{Nios II Options}, for more information.
6045
d77de738 6046@cindex @code{target("custom-fpu-cfg=@var{name}")} function attribute, Nios II
f33d7a88 6047@item custom-fpu-cfg=@var{name}
d77de738
ML
6048This attribute corresponds to the @option{-mcustom-fpu-cfg=@var{name}}
6049command-line option, to select a predefined set of custom instructions
6050named @var{name}.
6051@xref{Nios II Options}, for more information.
6052@end table
6053@end table
6054
6055@node Nvidia PTX Function Attributes
6056@subsection Nvidia PTX Function Attributes
6057
6058These function attributes are supported by the Nvidia PTX back end:
6059
6060@table @code
d77de738 6061@cindex @code{kernel} attribute, Nvidia PTX
f33d7a88 6062@item kernel
d77de738
ML
6063This attribute indicates that the corresponding function should be compiled
6064as a kernel function, which can be invoked from the host via the CUDA RT
6065library.
6066By default functions are only callable only from other PTX functions.
6067
6068Kernel functions must have @code{void} return type.
6069@end table
6070
6071@node PowerPC Function Attributes
6072@subsection PowerPC Function Attributes
6073
6074These function attributes are supported by the PowerPC back end:
6075
6076@table @code
d77de738
ML
6077@cindex indirect calls, PowerPC
6078@cindex @code{longcall} function attribute, PowerPC
6079@cindex @code{shortcall} function attribute, PowerPC
f33d7a88
AA
6080@item longcall
6081@itemx shortcall
d77de738
ML
6082The @code{longcall} attribute
6083indicates that the function might be far away from the call site and
6084require a different (more expensive) calling sequence. The
6085@code{shortcall} attribute indicates that the function is always close
6086enough for the shorter calling sequence to be used. These attributes
6087override both the @option{-mlongcall} switch and
6088the @code{#pragma longcall} setting.
6089
6090@xref{RS/6000 and PowerPC Options}, for more information on whether long
6091calls are necessary.
6092
d77de738 6093@cindex @code{target} function attribute
f33d7a88 6094@item target (@var{options})
d77de738
ML
6095As discussed in @ref{Common Function Attributes}, this attribute
6096allows specification of target-specific compilation options.
6097
6098On the PowerPC, the following options are allowed:
6099
6100@table @samp
f33d7a88 6101@cindex @code{target("altivec")} function attribute, PowerPC
d77de738
ML
6102@item altivec
6103@itemx no-altivec
d77de738
ML
6104Generate code that uses (does not use) AltiVec instructions. In
610532-bit code, you cannot enable AltiVec instructions unless
6106@option{-mabi=altivec} is used on the command line.
6107
f33d7a88 6108@cindex @code{target("cmpb")} function attribute, PowerPC
d77de738
ML
6109@item cmpb
6110@itemx no-cmpb
d77de738
ML
6111Generate code that uses (does not use) the compare bytes instruction
6112implemented on the POWER6 processor and other processors that support
6113the PowerPC V2.05 architecture.
6114
f33d7a88 6115@cindex @code{target("dlmzb")} function attribute, PowerPC
d77de738
ML
6116@item dlmzb
6117@itemx no-dlmzb
d77de738
ML
6118Generate code that uses (does not use) the string-search @samp{dlmzb}
6119instruction on the IBM 405, 440, 464 and 476 processors. This instruction is
6120generated by default when targeting those processors.
6121
f33d7a88 6122@cindex @code{target("fprnd")} function attribute, PowerPC
d77de738
ML
6123@item fprnd
6124@itemx no-fprnd
d77de738
ML
6125Generate code that uses (does not use) the FP round to integer
6126instructions implemented on the POWER5+ processor and other processors
6127that support the PowerPC V2.03 architecture.
6128
f33d7a88 6129@cindex @code{target("hard-dfp")} function attribute, PowerPC
d77de738
ML
6130@item hard-dfp
6131@itemx no-hard-dfp
d77de738
ML
6132Generate code that uses (does not use) the decimal floating-point
6133instructions implemented on some POWER processors.
6134
f33d7a88 6135@cindex @code{target("isel")} function attribute, PowerPC
d77de738
ML
6136@item isel
6137@itemx no-isel
d77de738
ML
6138Generate code that uses (does not use) ISEL instruction.
6139
f33d7a88 6140@cindex @code{target("mfcrf")} function attribute, PowerPC
d77de738
ML
6141@item mfcrf
6142@itemx no-mfcrf
d77de738
ML
6143Generate code that uses (does not use) the move from condition
6144register field instruction implemented on the POWER4 processor and
6145other processors that support the PowerPC V2.01 architecture.
6146
f33d7a88 6147@cindex @code{target("mulhw")} function attribute, PowerPC
d77de738
ML
6148@item mulhw
6149@itemx no-mulhw
d77de738
ML
6150Generate code that uses (does not use) the half-word multiply and
6151multiply-accumulate instructions on the IBM 405, 440, 464 and 476 processors.
6152These instructions are generated by default when targeting those
6153processors.
6154
f33d7a88 6155@cindex @code{target("multiple")} function attribute, PowerPC
d77de738
ML
6156@item multiple
6157@itemx no-multiple
d77de738
ML
6158Generate code that uses (does not use) the load multiple word
6159instructions and the store multiple word instructions.
6160
f33d7a88 6161@cindex @code{target("update")} function attribute, PowerPC
d77de738
ML
6162@item update
6163@itemx no-update
d77de738
ML
6164Generate code that uses (does not use) the load or store instructions
6165that update the base register to the address of the calculated memory
6166location.
6167
f33d7a88 6168@cindex @code{target("popcntb")} function attribute, PowerPC
d77de738
ML
6169@item popcntb
6170@itemx no-popcntb
d77de738
ML
6171Generate code that uses (does not use) the popcount and double-precision
6172FP reciprocal estimate instruction implemented on the POWER5
6173processor and other processors that support the PowerPC V2.02
6174architecture.
6175
f33d7a88 6176@cindex @code{target("popcntd")} function attribute, PowerPC
d77de738
ML
6177@item popcntd
6178@itemx no-popcntd
d77de738
ML
6179Generate code that uses (does not use) the popcount instruction
6180implemented on the POWER7 processor and other processors that support
6181the PowerPC V2.06 architecture.
6182
f33d7a88 6183@cindex @code{target("powerpc-gfxopt")} function attribute, PowerPC
d77de738
ML
6184@item powerpc-gfxopt
6185@itemx no-powerpc-gfxopt
d77de738
ML
6186Generate code that uses (does not use) the optional PowerPC
6187architecture instructions in the Graphics group, including
6188floating-point select.
6189
f33d7a88 6190@cindex @code{target("powerpc-gpopt")} function attribute, PowerPC
d77de738
ML
6191@item powerpc-gpopt
6192@itemx no-powerpc-gpopt
d77de738
ML
6193Generate code that uses (does not use) the optional PowerPC
6194architecture instructions in the General Purpose group, including
6195floating-point square root.
6196
f33d7a88 6197@cindex @code{target("recip-precision")} function attribute, PowerPC
d77de738
ML
6198@item recip-precision
6199@itemx no-recip-precision
d77de738
ML
6200Assume (do not assume) that the reciprocal estimate instructions
6201provide higher-precision estimates than is mandated by the PowerPC
6202ABI.
6203
f33d7a88 6204@cindex @code{target("string")} function attribute, PowerPC
d77de738
ML
6205@item string
6206@itemx no-string
d77de738
ML
6207Generate code that uses (does not use) the load string instructions
6208and the store string word instructions to save multiple registers and
6209do small block moves.
6210
f33d7a88 6211@cindex @code{target("vsx")} function attribute, PowerPC
d77de738
ML
6212@item vsx
6213@itemx no-vsx
d77de738
ML
6214Generate code that uses (does not use) vector/scalar (VSX)
6215instructions, and also enable the use of built-in functions that allow
6216more direct access to the VSX instruction set. In 32-bit code, you
6217cannot enable VSX or AltiVec instructions unless
6218@option{-mabi=altivec} is used on the command line.
6219
f33d7a88 6220@cindex @code{target("friz")} function attribute, PowerPC
d77de738
ML
6221@item friz
6222@itemx no-friz
d77de738
ML
6223Generate (do not generate) the @code{friz} instruction when the
6224@option{-funsafe-math-optimizations} option is used to optimize
6225rounding a floating-point value to 64-bit integer and back to floating
6226point. The @code{friz} instruction does not return the same value if
6227the floating-point number is too large to fit in an integer.
6228
f33d7a88 6229@cindex @code{target("avoid-indexed-addresses")} function attribute, PowerPC
d77de738
ML
6230@item avoid-indexed-addresses
6231@itemx no-avoid-indexed-addresses
d77de738
ML
6232Generate code that tries to avoid (not avoid) the use of indexed load
6233or store instructions.
6234
f33d7a88 6235@cindex @code{target("paired")} function attribute, PowerPC
d77de738
ML
6236@item paired
6237@itemx no-paired
d77de738
ML
6238Generate code that uses (does not use) the generation of PAIRED simd
6239instructions.
6240
f33d7a88 6241@cindex @code{target("longcall")} function attribute, PowerPC
d77de738
ML
6242@item longcall
6243@itemx no-longcall
d77de738
ML
6244Generate code that assumes (does not assume) that all calls are far
6245away so that a longer more expensive calling sequence is required.
6246
d77de738 6247@cindex @code{target("cpu=@var{CPU}")} function attribute, PowerPC
f33d7a88 6248@item cpu=@var{CPU}
d77de738
ML
6249Specify the architecture to generate code for when compiling the
6250function. If you select the @code{target("cpu=power7")} attribute when
6251generating 32-bit code, VSX and AltiVec instructions are not generated
6252unless you use the @option{-mabi=altivec} option on the command line.
6253
d77de738 6254@cindex @code{target("tune=@var{TUNE}")} function attribute, PowerPC
f33d7a88 6255@item tune=@var{TUNE}
d77de738
ML
6256Specify the architecture to tune for when compiling the function. If
6257you do not specify the @code{target("tune=@var{TUNE}")} attribute and
6258you do specify the @code{target("cpu=@var{CPU}")} attribute,
6259compilation tunes for the @var{CPU} architecture, and not the
6260default tuning specified on the command line.
6261@end table
6262
6263On the PowerPC, the inliner does not inline a
6264function that has different target options than the caller, unless the
6265callee has a subset of the target options of the caller.
6266@end table
6267
6268@node RISC-V Function Attributes
6269@subsection RISC-V Function Attributes
6270
6271These function attributes are supported by the RISC-V back end:
6272
6273@table @code
d77de738 6274@cindex @code{naked} function attribute, RISC-V
f33d7a88 6275@item naked
d77de738
ML
6276This attribute allows the compiler to construct the
6277requisite function declaration, while allowing the body of the
6278function to be assembly code. The specified function will not have
6279prologue/epilogue sequences generated by the compiler. Only basic
6280@code{asm} statements can safely be included in naked functions
6281(@pxref{Basic Asm}). While using extended @code{asm} or a mixture of
6282basic @code{asm} and C code may appear to work, they cannot be
6283depended upon to work reliably and are not supported.
6284
d77de738 6285@cindex @code{interrupt} function attribute, RISC-V
f33d7a88 6286@item interrupt
d77de738
ML
6287Use this attribute to indicate that the specified function is an interrupt
6288handler. The compiler generates function entry and exit sequences suitable
6289for use in an interrupt handler when this attribute is present.
6290
6291You can specify the kind of interrupt to be handled by adding an optional
6292parameter to the interrupt attribute like this:
6293
6294@smallexample
6295void f (void) __attribute__ ((interrupt ("user")));
6296@end smallexample
6297
6298Permissible values for this parameter are @code{user}, @code{supervisor},
6299and @code{machine}. If there is no parameter, then it defaults to
6300@code{machine}.
5f110561
KC
6301
6302@end table
6303
6304The following target-specific function attributes are available for the
6305RISC-V target. For the most part, these options mirror the behavior of
6306similar command-line options (@pxref{RISC-V Options}), but on a
6307per-function basis.
6308
6309@table @code
6310@cindex @code{arch=} function attribute, RISC-V
6311@item arch=
6312Specifies the architecture version and architectural extensions to use
6313for this function. The behavior and permissible arguments are the same as
6314for the @option{-march=} command-line option, in addtion, it also support
6315extension enablement list, a list of extension name and prefixed with @code{+},
6316like @code{arch=+zba} means enable @code{zba} extension.
6317Multiple extension can be enabled by separating them with a comma. For example:
6318@code{arch=+zba,+zbb}.
6319
6320@cindex @code{tune=} function attribute, RISC-V
6321@item tune=
6322Specifies the core for which to tune the performance of this function.
6323The behavior and permissible arguments are the same as for the @option{-mtune=}
6324command-line option.
6325
6326@cindex @code{cpu=} function attribute, RISC-V
6327@item cpu=
6328Specifies the core for which to tune the performance of this function and also
6329whose architectural features to use. The behavior and valid arguments are the
6330same as for the @option{-mcpu=} command-line option.
6331
d77de738
ML
6332@end table
6333
5f110561
KC
6334The above target attributes can be specified as follows:
6335
6336@smallexample
6337__attribute__((target("@var{attr-string}")))
6338int
6339f (int a)
6340@{
6341 return a + 5;
6342@}
6343@end smallexample
6344
6345where @code{@var{attr-string}} is one of the attribute strings specified above.
6346
6347Multiple target function attributes can be specified by separating them with
6348a semicolon. For example:
6349@smallexample
6350__attribute__((target("arch=+zba,+zbb;tune=rocket")))
6351int
6352foo (int a)
6353@{
6354 return a + 5;
6355@}
6356@end smallexample
6357
6358is valid and compiles function @code{foo} with @code{zba}
6359and @code{zbb} extensions and tunes it for @code{rocket}.
6360
d77de738
ML
6361@node RL78 Function Attributes
6362@subsection RL78 Function Attributes
6363
6364These function attributes are supported by the RL78 back end:
6365
6366@table @code
d77de738
ML
6367@cindex @code{interrupt} function attribute, RL78
6368@cindex @code{brk_interrupt} function attribute, RL78
f33d7a88
AA
6369@item interrupt
6370@itemx brk_interrupt
d77de738
ML
6371These attributes 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 this attribute is present.
6375
6376Use @code{brk_interrupt} instead of @code{interrupt} for
6377handlers intended to be used with the @code{BRK} opcode (i.e.@: those
6378that must end with @code{RETB} instead of @code{RETI}).
6379
d77de738 6380@cindex @code{naked} function attribute, RL78
f33d7a88 6381@item naked
d77de738
ML
6382This attribute allows the compiler to construct the
6383requisite function declaration, while allowing the body of the
6384function to be assembly code. The specified function will not have
6385prologue/epilogue sequences generated by the compiler. Only basic
6386@code{asm} statements can safely be included in naked functions
6387(@pxref{Basic Asm}). While using extended @code{asm} or a mixture of
6388basic @code{asm} and C code may appear to work, they cannot be
6389depended upon to work reliably and are not supported.
6390@end table
6391
6392@node RX Function Attributes
6393@subsection RX Function Attributes
6394
6395These function attributes are supported by the RX back end:
6396
6397@table @code
d77de738 6398@cindex @code{fast_interrupt} function attribute, RX
f33d7a88 6399@item fast_interrupt
d77de738
ML
6400Use this attribute on the RX port to indicate that the specified
6401function is a fast interrupt handler. This is just like the
6402@code{interrupt} attribute, except that @code{freit} is used to return
6403instead of @code{reit}.
6404
d77de738 6405@cindex @code{interrupt} function attribute, RX
f33d7a88 6406@item interrupt
d77de738
ML
6407Use this attribute to indicate
6408that the specified function is an interrupt handler. The compiler generates
6409function entry and exit sequences suitable for use in an interrupt handler
6410when this attribute is present.
6411
6412On RX and RL78 targets, you may specify one or more vector numbers as arguments
6413to the attribute, as well as naming an alternate table name.
6414Parameters are handled sequentially, so one handler can be assigned to
6415multiple entries in multiple tables. One may also pass the magic
6416string @code{"$default"} which causes the function to be used for any
6417unfilled slots in the current table.
6418
6419This example shows a simple assignment of a function to one vector in
6420the default table (note that preprocessor macros may be used for
6421chip-specific symbolic vector names):
6422@smallexample
6423void __attribute__ ((interrupt (5))) txd1_handler ();
6424@end smallexample
6425
6426This example assigns a function to two slots in the default table
6427(using preprocessor macros defined elsewhere) and makes it the default
6428for the @code{dct} table:
6429@smallexample
6430void __attribute__ ((interrupt (RXD1_VECT,RXD2_VECT,"dct","$default")))
6431 txd1_handler ();
6432@end smallexample
6433
d77de738 6434@cindex @code{naked} function attribute, RX
f33d7a88 6435@item naked
d77de738
ML
6436This attribute allows the compiler to construct the
6437requisite function declaration, while allowing the body of the
6438function to be assembly code. The specified function will not have
6439prologue/epilogue sequences generated by the compiler. Only basic
6440@code{asm} statements can safely be included in naked functions
6441(@pxref{Basic Asm}). While using extended @code{asm} or a mixture of
6442basic @code{asm} and C code may appear to work, they cannot be
6443depended upon to work reliably and are not supported.
6444
d77de738 6445@cindex @code{vector} function attribute, RX
f33d7a88 6446@item vector
d77de738
ML
6447This RX attribute is similar to the @code{interrupt} attribute, including its
6448parameters, but does not make the function an interrupt-handler type
6449function (i.e.@: it retains the normal C function calling ABI). See the
6450@code{interrupt} attribute for a description of its arguments.
6451@end table
6452
6453@node S/390 Function Attributes
6454@subsection S/390 Function Attributes
6455
6456These function attributes are supported on the S/390:
6457
6458@table @code
d77de738 6459@cindex @code{hotpatch} function attribute, S/390
f33d7a88 6460@item hotpatch (@var{halfwords-before-function-label},@var{halfwords-after-function-label})
d77de738
ML
6461
6462On S/390 System z targets, you can use this function attribute to
6463make GCC generate a ``hot-patching'' function prologue. If the
6464@option{-mhotpatch=} command-line option is used at the same time,
6465the @code{hotpatch} attribute takes precedence. The first of the
6466two arguments specifies the number of halfwords to be added before
6467the function label. A second argument can be used to specify the
6468number of halfwords to be added after the function label. For
6469both arguments the maximum allowed value is 1000000.
6470
6471If both arguments are zero, hotpatching is disabled.
6472
d77de738 6473@cindex @code{target} function attribute
f33d7a88 6474@item target (@var{options})
d77de738
ML
6475As discussed in @ref{Common Function Attributes}, this attribute
6476allows specification of target-specific compilation options.
6477
6478On S/390, the following options are supported:
6479
6480@table @samp
6481@item arch=
6482@item tune=
6483@item stack-guard=
6484@item stack-size=
6485@item branch-cost=
6486@item warn-framesize=
6487@item backchain
6488@itemx no-backchain
6489@item hard-dfp
6490@itemx no-hard-dfp
6491@item hard-float
6492@itemx soft-float
6493@item htm
6494@itemx no-htm
6495@item vx
6496@itemx no-vx
6497@item packed-stack
6498@itemx no-packed-stack
6499@item small-exec
6500@itemx no-small-exec
6501@item mvcle
6502@itemx no-mvcle
6503@item warn-dynamicstack
6504@itemx no-warn-dynamicstack
6505@end table
6506
6507The options work exactly like the S/390 specific command line
6508options (without the prefix @option{-m}) except that they do not
6509change any feature macros. For example,
6510
6511@smallexample
6512@code{target("no-vx")}
6513@end smallexample
6514
6515does not undefine the @code{__VEC__} macro.
6516@end table
6517
6518@node SH Function Attributes
6519@subsection SH Function Attributes
6520
6521These function attributes are supported on the SH family of processors:
6522
6523@table @code
d77de738
ML
6524@cindex @code{function_vector} function attribute, SH
6525@cindex calling functions through the function vector on SH2A
f33d7a88 6526@item function_vector
d77de738
ML
6527On SH2A targets, this attribute declares a function to be called using the
6528TBR relative addressing mode. The argument to this attribute is the entry
6529number of the same function in a vector table containing all the TBR
6530relative addressable functions. For correct operation the TBR must be setup
6531accordingly to point to the start of the vector table before any functions with
6532this attribute are invoked. Usually a good place to do the initialization is
6533the startup routine. The TBR relative vector table can have at max 256 function
6534entries. The jumps to these functions are generated using a SH2A specific,
6535non delayed branch instruction JSR/N @@(disp8,TBR). You must use GAS and GLD
6536from GNU binutils version 2.7 or later for this attribute to work correctly.
6537
6538In an application, for a function being called once, this attribute
6539saves at least 8 bytes of code; and if other successive calls are being
6540made to the same function, it saves 2 bytes of code per each of these
6541calls.
6542
d77de738 6543@cindex @code{interrupt_handler} function attribute, SH
f33d7a88 6544@item interrupt_handler
d77de738
ML
6545Use this attribute to
6546indicate that the specified function is an interrupt handler. The compiler
6547generates function entry and exit sequences suitable for use in an
6548interrupt handler when this attribute is present.
6549
d77de738 6550@cindex @code{nosave_low_regs} function attribute, SH
f33d7a88 6551@item nosave_low_regs
d77de738
ML
6552Use this attribute on SH targets to indicate that an @code{interrupt_handler}
6553function should not save and restore registers R0..R7. This can be used on SH3*
6554and SH4* targets that have a second R0..R7 register bank for non-reentrant
6555interrupt handlers.
6556
d77de738 6557@cindex @code{renesas} function attribute, SH
f33d7a88 6558@item renesas
d77de738
ML
6559On SH targets this attribute specifies that the function or struct follows the
6560Renesas ABI.
6561
d77de738 6562@cindex @code{resbank} function attribute, SH
f33d7a88 6563@item resbank
d77de738
ML
6564On the SH2A target, this attribute enables the high-speed register
6565saving and restoration using a register bank for @code{interrupt_handler}
6566routines. Saving to the bank is performed automatically after the CPU
6567accepts an interrupt that uses a register bank.
6568
6569The nineteen 32-bit registers comprising general register R0 to R14,
6570control register GBR, and system registers MACH, MACL, and PR and the
6571vector table address offset are saved into a register bank. Register
6572banks are stacked in first-in last-out (FILO) sequence. Restoration
6573from the bank is executed by issuing a RESBANK instruction.
6574
d77de738 6575@cindex @code{sp_switch} function attribute, SH
f33d7a88 6576@item sp_switch
d77de738
ML
6577Use this attribute on the SH to indicate an @code{interrupt_handler}
6578function should switch to an alternate stack. It expects a string
6579argument that names a global variable holding the address of the
6580alternate stack.
6581
6582@smallexample
6583void *alt_stack;
6584void f () __attribute__ ((interrupt_handler,
6585 sp_switch ("alt_stack")));
6586@end smallexample
6587
d77de738 6588@cindex @code{trap_exit} function attribute, SH
f33d7a88 6589@item trap_exit
d77de738
ML
6590Use this attribute on the SH for an @code{interrupt_handler} to return using
6591@code{trapa} instead of @code{rte}. This attribute expects an integer
6592argument specifying the trap number to be used.
6593
d77de738 6594@cindex @code{trapa_handler} function attribute, SH
f33d7a88 6595@item trapa_handler
d77de738
ML
6596On SH targets this function attribute is similar to @code{interrupt_handler}
6597but it does not save and restore all registers.
6598@end table
6599
6600@node Symbian OS Function Attributes
6601@subsection Symbian OS Function Attributes
6602
6603@xref{Microsoft Windows Function Attributes}, for discussion of the
6604@code{dllexport} and @code{dllimport} attributes.
6605
6606@node V850 Function Attributes
6607@subsection V850 Function Attributes
6608
6609The V850 back end supports these function attributes:
6610
6611@table @code
d77de738
ML
6612@cindex @code{interrupt} function attribute, V850
6613@cindex @code{interrupt_handler} function attribute, V850
f33d7a88
AA
6614@item interrupt
6615@itemx interrupt_handler
d77de738
ML
6616Use these attributes to indicate
6617that the specified function is an interrupt handler. The compiler generates
6618function entry and exit sequences suitable for use in an interrupt handler
6619when either attribute is present.
6620@end table
6621
6622@node Visium Function Attributes
6623@subsection Visium Function Attributes
6624
6625These function attributes are supported by the Visium back end:
6626
6627@table @code
d77de738 6628@cindex @code{interrupt} function attribute, Visium
f33d7a88 6629@item interrupt
d77de738
ML
6630Use this attribute to indicate
6631that the specified function is an interrupt handler. The compiler generates
6632function entry and exit sequences suitable for use in an interrupt handler
6633when this attribute is present.
6634@end table
6635
6636@node x86 Function Attributes
6637@subsection x86 Function Attributes
6638
6639These function attributes are supported by the x86 back end:
6640
6641@table @code
d77de738
ML
6642@cindex @code{cdecl} function attribute, x86-32
6643@cindex functions that pop the argument stack on x86-32
6644@opindex mrtd
f33d7a88 6645@item cdecl
d77de738
ML
6646On the x86-32 targets, the @code{cdecl} attribute causes the compiler to
6647assume that the calling function pops off the stack space used to
6648pass arguments. This is
6649useful to override the effects of the @option{-mrtd} switch.
6650
d77de738
ML
6651@cindex @code{fastcall} function attribute, x86-32
6652@cindex functions that pop the argument stack on x86-32
f33d7a88 6653@item fastcall
d77de738
ML
6654On x86-32 targets, the @code{fastcall} attribute causes the compiler to
6655pass the first argument (if of integral type) in the register ECX and
6656the second argument (if of integral type) in the register EDX@. Subsequent
6657and other typed arguments are passed on the stack. The called function
6658pops the arguments off the stack. If the number of arguments is variable all
6659arguments are pushed on the stack.
6660
d77de738
ML
6661@cindex @code{thiscall} function attribute, x86-32
6662@cindex functions that pop the argument stack on x86-32
f33d7a88 6663@item thiscall
d77de738
ML
6664On x86-32 targets, the @code{thiscall} attribute causes the compiler to
6665pass the first argument (if of integral type) in the register ECX.
6666Subsequent and other typed arguments are passed on the stack. The called
6667function pops the arguments off the stack.
6668If the number of arguments is variable all arguments are pushed on the
6669stack.
6670The @code{thiscall} attribute is intended for C++ non-static member functions.
6671As a GCC extension, this calling convention can be used for C functions
6672and for static member methods.
6673
d77de738
ML
6674@cindex @code{ms_abi} function attribute, x86
6675@cindex @code{sysv_abi} function attribute, x86
f33d7a88
AA
6676@item ms_abi
6677@itemx sysv_abi
d77de738
ML
6678
6679On 32-bit and 64-bit x86 targets, you can use an ABI attribute
6680to indicate which calling convention should be used for a function. The
6681@code{ms_abi} attribute tells the compiler to use the Microsoft ABI,
6682while the @code{sysv_abi} attribute tells the compiler to use the System V
6683ELF ABI, which is used on GNU/Linux and other systems. The default is to use
6684the Microsoft ABI when targeting Windows. On all other systems, the default
6685is the System V ELF ABI.
6686
6687Note, the @code{ms_abi} attribute for Microsoft Windows 64-bit targets currently
6688requires the @option{-maccumulate-outgoing-args} option.
6689
d77de738 6690@cindex @code{callee_pop_aggregate_return} function attribute, x86
f33d7a88 6691@item callee_pop_aggregate_return (@var{number})
d77de738
ML
6692
6693On x86-32 targets, you can use this attribute to control how
6694aggregates are returned in memory. If the caller is responsible for
6695popping the hidden pointer together with the rest of the arguments, specify
6696@var{number} equal to zero. If callee is responsible for popping the
6697hidden pointer, specify @var{number} equal to one.
6698
6699The default x86-32 ABI assumes that the callee pops the
6700stack for hidden pointer. However, on x86-32 Microsoft Windows targets,
6701the compiler assumes that the
6702caller pops the stack for hidden pointer.
6703
d77de738 6704@cindex @code{ms_hook_prologue} function attribute, x86
f33d7a88 6705@item ms_hook_prologue
d77de738
ML
6706
6707On 32-bit and 64-bit x86 targets, you can use
6708this function attribute to make GCC generate the ``hot-patching'' function
6709prologue used in Win32 API functions in Microsoft Windows XP Service Pack 2
6710and newer.
6711
d77de738 6712@cindex @code{naked} function attribute, x86
f33d7a88 6713@item naked
d77de738
ML
6714This attribute allows the compiler to construct the
6715requisite function declaration, while allowing the body of the
6716function to be assembly code. The specified function will not have
6717prologue/epilogue sequences generated by the compiler. Only basic
6718@code{asm} statements can safely be included in naked functions
6719(@pxref{Basic Asm}). While using extended @code{asm} or a mixture of
6720basic @code{asm} and C code may appear to work, they cannot be
6721depended upon to work reliably and are not supported.
6722
d77de738
ML
6723@cindex @code{regparm} function attribute, x86
6724@cindex functions that are passed arguments in registers on x86-32
f33d7a88 6725@item regparm (@var{number})
d77de738
ML
6726On x86-32 targets, the @code{regparm} attribute causes the compiler to
6727pass arguments number one to @var{number} if they are of integral type
6728in registers EAX, EDX, and ECX instead of on the stack. Functions that
6729take a variable number of arguments continue to be passed all of their
6730arguments on the stack.
6731
6732Beware that on some ELF systems this attribute is unsuitable for
6733global functions in shared libraries with lazy binding (which is the
6734default). Lazy binding sends the first call via resolving code in
6735the loader, which might assume EAX, EDX and ECX can be clobbered, as
6736per the standard calling conventions. Solaris 8 is affected by this.
6737Systems with the GNU C Library version 2.1 or higher
6738and FreeBSD are believed to be
6739safe since the loaders there save EAX, EDX and ECX. (Lazy binding can be
6740disabled with the linker or the loader if desired, to avoid the
6741problem.)
6742
d77de738 6743@cindex @code{sseregparm} function attribute, x86
f33d7a88 6744@item sseregparm
d77de738
ML
6745On x86-32 targets with SSE support, the @code{sseregparm} attribute
6746causes the compiler to pass up to 3 floating-point arguments in
6747SSE registers instead of on the stack. Functions that take a
6748variable number of arguments continue to pass all of their
6749floating-point arguments on the stack.
6750
d77de738 6751@cindex @code{force_align_arg_pointer} function attribute, x86
f33d7a88 6752@item force_align_arg_pointer
d77de738
ML
6753On x86 targets, the @code{force_align_arg_pointer} attribute may be
6754applied to individual function definitions, generating an alternate
6755prologue and epilogue that realigns the run-time stack if necessary.
6756This supports mixing legacy codes that run with a 4-byte aligned stack
6757with modern codes that keep a 16-byte stack for SSE compatibility.
6758
d77de738
ML
6759@cindex @code{stdcall} function attribute, x86-32
6760@cindex functions that pop the argument stack on x86-32
f33d7a88 6761@item stdcall
d77de738
ML
6762On x86-32 targets, the @code{stdcall} attribute causes the compiler to
6763assume that the called function pops off the stack space used to
6764pass arguments, unless it takes a variable number of arguments.
6765
d77de738 6766@cindex @code{no_caller_saved_registers} function attribute, x86
f33d7a88 6767@item no_caller_saved_registers
d77de738
ML
6768Use this attribute to indicate that the specified function has no
6769caller-saved registers. That is, all registers are callee-saved. For
6770example, this attribute can be used for a function called from an
6771interrupt handler. The compiler generates proper function entry and
6772exit sequences to save and restore any modified registers, except for
6773the EFLAGS register. Since GCC doesn't preserve SSE, MMX nor x87
6774states, the GCC option @option{-mgeneral-regs-only} should be used to
6775compile functions with @code{no_caller_saved_registers} attribute.
6776
d77de738 6777@cindex @code{interrupt} function attribute, x86
f33d7a88 6778@item interrupt
d77de738
ML
6779Use this attribute to indicate that the specified function is an
6780interrupt handler or an exception handler (depending on parameters passed
6781to the function, explained further). The compiler generates function
6782entry and exit sequences suitable for use in an interrupt handler when
6783this attribute is present. The @code{IRET} instruction, instead of the
6784@code{RET} instruction, is used to return from interrupt handlers. All
6785registers, except for the EFLAGS register which is restored by the
6786@code{IRET} instruction, are preserved by the compiler. Since GCC
6787doesn't preserve SSE, MMX nor x87 states, the GCC option
6788@option{-mgeneral-regs-only} should be used to compile interrupt and
6789exception handlers.
6790
6791Any interruptible-without-stack-switch code must be compiled with
6792@option{-mno-red-zone} since interrupt handlers can and will, because
6793of the hardware design, touch the red zone.
6794
6795An interrupt handler must be declared with a mandatory pointer
6796argument:
6797
6798@smallexample
6799struct interrupt_frame;
6800
6801__attribute__ ((interrupt))
6802void
6803f (struct interrupt_frame *frame)
6804@{
6805@}
6806@end smallexample
6807
6808@noindent
6809and you must define @code{struct interrupt_frame} as described in the
6810processor's manual.
6811
6812Exception handlers differ from interrupt handlers because the system
6813pushes an error code on the stack. An exception handler declaration is
6814similar to that for an interrupt handler, but with a different mandatory
6815function signature. The compiler arranges to pop the error code off the
6816stack before the @code{IRET} instruction.
6817
6818@smallexample
6819#ifdef __x86_64__
6820typedef unsigned long long int uword_t;
6821#else
6822typedef unsigned int uword_t;
6823#endif
6824
6825struct interrupt_frame;
6826
6827__attribute__ ((interrupt))
6828void
6829f (struct interrupt_frame *frame, uword_t error_code)
6830@{
6831 ...
6832@}
6833@end smallexample
6834
6835Exception handlers should only be used for exceptions that push an error
6836code; you should use an interrupt handler in other cases. The system
6837will crash if the wrong kind of handler is used.
6838
d77de738 6839@cindex @code{target} function attribute
f33d7a88 6840@item target (@var{options})
d77de738
ML
6841As discussed in @ref{Common Function Attributes}, this attribute
6842allows specification of target-specific compilation options.
6843
6844On the x86, the following options are allowed:
6845@table @samp
f33d7a88 6846@cindex @code{target("3dnow")} function attribute, x86
d77de738
ML
6847@item 3dnow
6848@itemx no-3dnow
d77de738
ML
6849Enable/disable the generation of the 3DNow!@: instructions.
6850
f33d7a88 6851@cindex @code{target("3dnowa")} function attribute, x86
d77de738
ML
6852@item 3dnowa
6853@itemx no-3dnowa
d77de738
ML
6854Enable/disable the generation of the enhanced 3DNow!@: instructions.
6855
f33d7a88 6856@cindex @code{target("abm")} function attribute, x86
d77de738
ML
6857@item abm
6858@itemx no-abm
d77de738
ML
6859Enable/disable the generation of the advanced bit instructions.
6860
f33d7a88 6861@cindex @code{target("adx")} function attribute, x86
d77de738
ML
6862@item adx
6863@itemx no-adx
d77de738
ML
6864Enable/disable the generation of the ADX instructions.
6865
f33d7a88 6866@cindex @code{target("aes")} function attribute, x86
d77de738
ML
6867@item aes
6868@itemx no-aes
d77de738
ML
6869Enable/disable the generation of the AES instructions.
6870
f33d7a88 6871@cindex @code{target("avx")} function attribute, x86
d77de738
ML
6872@item avx
6873@itemx no-avx
d77de738
ML
6874Enable/disable the generation of the AVX instructions.
6875
f33d7a88 6876@cindex @code{target("avx2")} function attribute, x86
d77de738
ML
6877@item avx2
6878@itemx no-avx2
d77de738
ML
6879Enable/disable the generation of the AVX2 instructions.
6880
f33d7a88 6881@cindex @code{target("avx5124fmaps")} function attribute, x86
d77de738
ML
6882@item avx5124fmaps
6883@itemx no-avx5124fmaps
d77de738
ML
6884Enable/disable the generation of the AVX5124FMAPS instructions.
6885
f33d7a88 6886@cindex @code{target("avx5124vnniw")} function attribute, x86
d77de738
ML
6887@item avx5124vnniw
6888@itemx no-avx5124vnniw
d77de738
ML
6889Enable/disable the generation of the AVX5124VNNIW instructions.
6890
f33d7a88 6891@cindex @code{target("avx512bitalg")} function attribute, x86
d77de738
ML
6892@item avx512bitalg
6893@itemx no-avx512bitalg
d77de738
ML
6894Enable/disable the generation of the AVX512BITALG instructions.
6895
f33d7a88 6896@cindex @code{target("avx512bw")} function attribute, x86
d77de738
ML
6897@item avx512bw
6898@itemx no-avx512bw
d77de738
ML
6899Enable/disable the generation of the AVX512BW instructions.
6900
f33d7a88 6901@cindex @code{target("avx512cd")} function attribute, x86
d77de738
ML
6902@item avx512cd
6903@itemx no-avx512cd
d77de738
ML
6904Enable/disable the generation of the AVX512CD instructions.
6905
f33d7a88 6906@cindex @code{target("avx512dq")} function attribute, x86
d77de738
ML
6907@item avx512dq
6908@itemx no-avx512dq
d77de738
ML
6909Enable/disable the generation of the AVX512DQ instructions.
6910
f33d7a88 6911@cindex @code{target("avx512er")} function attribute, x86
d77de738
ML
6912@item avx512er
6913@itemx no-avx512er
d77de738
ML
6914Enable/disable the generation of the AVX512ER instructions.
6915
f33d7a88 6916@cindex @code{target("avx512f")} function attribute, x86
d77de738
ML
6917@item avx512f
6918@itemx no-avx512f
d77de738
ML
6919Enable/disable the generation of the AVX512F instructions.
6920
f33d7a88 6921@cindex @code{target("avx512ifma")} function attribute, x86
d77de738
ML
6922@item avx512ifma
6923@itemx no-avx512ifma
d77de738
ML
6924Enable/disable the generation of the AVX512IFMA instructions.
6925
f33d7a88 6926@cindex @code{target("avx512pf")} function attribute, x86
d77de738
ML
6927@item avx512pf
6928@itemx no-avx512pf
d77de738
ML
6929Enable/disable the generation of the AVX512PF instructions.
6930
f33d7a88 6931@cindex @code{target("avx512vbmi")} function attribute, x86
d77de738
ML
6932@item avx512vbmi
6933@itemx no-avx512vbmi
d77de738
ML
6934Enable/disable the generation of the AVX512VBMI instructions.
6935
f33d7a88 6936@cindex @code{target("avx512vbmi2")} function attribute, x86
d77de738
ML
6937@item avx512vbmi2
6938@itemx no-avx512vbmi2
d77de738
ML
6939Enable/disable the generation of the AVX512VBMI2 instructions.
6940
f33d7a88 6941@cindex @code{target("avx512vl")} function attribute, x86
d77de738
ML
6942@item avx512vl
6943@itemx no-avx512vl
d77de738
ML
6944Enable/disable the generation of the AVX512VL instructions.
6945
f33d7a88 6946@cindex @code{target("avx512vnni")} function attribute, x86
d77de738
ML
6947@item avx512vnni
6948@itemx no-avx512vnni
d77de738
ML
6949Enable/disable the generation of the AVX512VNNI instructions.
6950
f33d7a88 6951@cindex @code{target("avx512vpopcntdq")} function attribute, x86
d77de738
ML
6952@item avx512vpopcntdq
6953@itemx no-avx512vpopcntdq
d77de738
ML
6954Enable/disable the generation of the AVX512VPOPCNTDQ instructions.
6955
f33d7a88 6956@cindex @code{target("bmi")} function attribute, x86
d77de738
ML
6957@item bmi
6958@itemx no-bmi
d77de738
ML
6959Enable/disable the generation of the BMI instructions.
6960
f33d7a88 6961@cindex @code{target("bmi2")} function attribute, x86
d77de738
ML
6962@item bmi2
6963@itemx no-bmi2
d77de738
ML
6964Enable/disable the generation of the BMI2 instructions.
6965
f33d7a88 6966@cindex @code{target("cldemote")} function attribute, x86
d77de738
ML
6967@item cldemote
6968@itemx no-cldemote
d77de738
ML
6969Enable/disable the generation of the CLDEMOTE instructions.
6970
f33d7a88 6971@cindex @code{target("clflushopt")} function attribute, x86
d77de738
ML
6972@item clflushopt
6973@itemx no-clflushopt
d77de738
ML
6974Enable/disable the generation of the CLFLUSHOPT instructions.
6975
f33d7a88 6976@cindex @code{target("clwb")} function attribute, x86
d77de738
ML
6977@item clwb
6978@itemx no-clwb
d77de738
ML
6979Enable/disable the generation of the CLWB instructions.
6980
f33d7a88 6981@cindex @code{target("clzero")} function attribute, x86
d77de738
ML
6982@item clzero
6983@itemx no-clzero
d77de738
ML
6984Enable/disable the generation of the CLZERO instructions.
6985
f33d7a88 6986@cindex @code{target("crc32")} function attribute, x86
d77de738
ML
6987@item crc32
6988@itemx no-crc32
d77de738
ML
6989Enable/disable the generation of the CRC32 instructions.
6990
f33d7a88 6991@cindex @code{target("cx16")} function attribute, x86
d77de738
ML
6992@item cx16
6993@itemx no-cx16
d77de738
ML
6994Enable/disable the generation of the CMPXCHG16B instructions.
6995
d77de738 6996@cindex @code{target("default")} function attribute, x86
f33d7a88 6997@item default
d77de738
ML
6998@xref{Function Multiversioning}, where it is used to specify the
6999default function version.
7000
f33d7a88 7001@cindex @code{target("f16c")} function attribute, x86
d77de738
ML
7002@item f16c
7003@itemx no-f16c
d77de738
ML
7004Enable/disable the generation of the F16C instructions.
7005
f33d7a88 7006@cindex @code{target("fma")} function attribute, x86
d77de738
ML
7007@item fma
7008@itemx no-fma
d77de738
ML
7009Enable/disable the generation of the FMA instructions.
7010
f33d7a88 7011@cindex @code{target("fma4")} function attribute, x86
d77de738
ML
7012@item fma4
7013@itemx no-fma4
d77de738
ML
7014Enable/disable the generation of the FMA4 instructions.
7015
f33d7a88 7016@cindex @code{target("fsgsbase")} function attribute, x86
d77de738
ML
7017@item fsgsbase
7018@itemx no-fsgsbase
d77de738
ML
7019Enable/disable the generation of the FSGSBASE instructions.
7020
f33d7a88 7021@cindex @code{target("fxsr")} function attribute, x86
d77de738
ML
7022@item fxsr
7023@itemx no-fxsr
d77de738
ML
7024Enable/disable the generation of the FXSR instructions.
7025
f33d7a88 7026@cindex @code{target("gfni")} function attribute, x86
d77de738
ML
7027@item gfni
7028@itemx no-gfni
d77de738
ML
7029Enable/disable the generation of the GFNI instructions.
7030
f33d7a88 7031@cindex @code{target("hle")} function attribute, x86
d77de738
ML
7032@item hle
7033@itemx no-hle
d77de738
ML
7034Enable/disable the generation of the HLE instruction prefixes.
7035
f33d7a88 7036@cindex @code{target("lwp")} function attribute, x86
d77de738
ML
7037@item lwp
7038@itemx no-lwp
d77de738
ML
7039Enable/disable the generation of the LWP instructions.
7040
f33d7a88 7041@cindex @code{target("lzcnt")} function attribute, x86
d77de738
ML
7042@item lzcnt
7043@itemx no-lzcnt
d77de738
ML
7044Enable/disable the generation of the LZCNT instructions.
7045
f33d7a88 7046@cindex @code{target("mmx")} function attribute, x86
d77de738
ML
7047@item mmx
7048@itemx no-mmx
d77de738
ML
7049Enable/disable the generation of the MMX instructions.
7050
f33d7a88 7051@cindex @code{target("movbe")} function attribute, x86
d77de738
ML
7052@item movbe
7053@itemx no-movbe
d77de738
ML
7054Enable/disable the generation of the MOVBE instructions.
7055
f33d7a88 7056@cindex @code{target("movdir64b")} function attribute, x86
d77de738
ML
7057@item movdir64b
7058@itemx no-movdir64b
d77de738
ML
7059Enable/disable the generation of the MOVDIR64B instructions.
7060
f33d7a88 7061@cindex @code{target("movdiri")} function attribute, x86
d77de738
ML
7062@item movdiri
7063@itemx no-movdiri
d77de738
ML
7064Enable/disable the generation of the MOVDIRI instructions.
7065
f33d7a88 7066@cindex @code{target("mwait")} function attribute, x86
d77de738
ML
7067@item mwait
7068@itemx no-mwait
d77de738
ML
7069Enable/disable the generation of the MWAIT and MONITOR instructions.
7070
f33d7a88 7071@cindex @code{target("mwaitx")} function attribute, x86
d77de738
ML
7072@item mwaitx
7073@itemx no-mwaitx
d77de738
ML
7074Enable/disable the generation of the MWAITX instructions.
7075
f33d7a88 7076@cindex @code{target("pclmul")} function attribute, x86
d77de738
ML
7077@item pclmul
7078@itemx no-pclmul
d77de738
ML
7079Enable/disable the generation of the PCLMUL instructions.
7080
f33d7a88 7081@cindex @code{target("pconfig")} function attribute, x86
d77de738
ML
7082@item pconfig
7083@itemx no-pconfig
d77de738
ML
7084Enable/disable the generation of the PCONFIG instructions.
7085
f33d7a88 7086@cindex @code{target("pku")} function attribute, x86
d77de738
ML
7087@item pku
7088@itemx no-pku
d77de738
ML
7089Enable/disable the generation of the PKU instructions.
7090
f33d7a88 7091@cindex @code{target("popcnt")} function attribute, x86
d77de738
ML
7092@item popcnt
7093@itemx no-popcnt
d77de738
ML
7094Enable/disable the generation of the POPCNT instruction.
7095
f33d7a88 7096@cindex @code{target("prefetchwt1")} function attribute, x86
d77de738
ML
7097@item prefetchwt1
7098@itemx no-prefetchwt1
d77de738
ML
7099Enable/disable the generation of the PREFETCHWT1 instructions.
7100
f33d7a88 7101@cindex @code{target("prfchw")} function attribute, x86
d77de738
ML
7102@item prfchw
7103@itemx no-prfchw
d77de738
ML
7104Enable/disable the generation of the PREFETCHW instruction.
7105
f33d7a88 7106@cindex @code{target("ptwrite")} function attribute, x86
d77de738
ML
7107@item ptwrite
7108@itemx no-ptwrite
d77de738
ML
7109Enable/disable the generation of the PTWRITE instructions.
7110
f33d7a88 7111@cindex @code{target("rdpid")} function attribute, x86
d77de738
ML
7112@item rdpid
7113@itemx no-rdpid
d77de738
ML
7114Enable/disable the generation of the RDPID instructions.
7115
f33d7a88 7116@cindex @code{target("rdrnd")} function attribute, x86
d77de738
ML
7117@item rdrnd
7118@itemx no-rdrnd
d77de738
ML
7119Enable/disable the generation of the RDRND instructions.
7120
f33d7a88 7121@cindex @code{target("rdseed")} function attribute, x86
d77de738
ML
7122@item rdseed
7123@itemx no-rdseed
d77de738
ML
7124Enable/disable the generation of the RDSEED instructions.
7125
f33d7a88 7126@cindex @code{target("rtm")} function attribute, x86
d77de738
ML
7127@item rtm
7128@itemx no-rtm
d77de738
ML
7129Enable/disable the generation of the RTM instructions.
7130
f33d7a88 7131@cindex @code{target("sahf")} function attribute, x86
d77de738
ML
7132@item sahf
7133@itemx no-sahf
d77de738
ML
7134Enable/disable the generation of the SAHF instructions.
7135
f33d7a88 7136@cindex @code{target("sgx")} function attribute, x86
d77de738
ML
7137@item sgx
7138@itemx no-sgx
d77de738
ML
7139Enable/disable the generation of the SGX instructions.
7140
f33d7a88 7141@cindex @code{target("sha")} function attribute, x86
d77de738
ML
7142@item sha
7143@itemx no-sha
d77de738
ML
7144Enable/disable the generation of the SHA instructions.
7145
f33d7a88 7146@cindex @code{target("shstk")} function attribute, x86
d77de738
ML
7147@item shstk
7148@itemx no-shstk
d77de738
ML
7149Enable/disable the shadow stack built-in functions from CET.
7150
f33d7a88 7151@cindex @code{target("sse")} function attribute, x86
d77de738
ML
7152@item sse
7153@itemx no-sse
d77de738
ML
7154Enable/disable the generation of the SSE instructions.
7155
f33d7a88 7156@cindex @code{target("sse2")} function attribute, x86
d77de738
ML
7157@item sse2
7158@itemx no-sse2
d77de738
ML
7159Enable/disable the generation of the SSE2 instructions.
7160
f33d7a88 7161@cindex @code{target("sse3")} function attribute, x86
d77de738
ML
7162@item sse3
7163@itemx no-sse3
d77de738
ML
7164Enable/disable the generation of the SSE3 instructions.
7165
f33d7a88 7166@cindex @code{target("sse4")} function attribute, x86
d77de738
ML
7167@item sse4
7168@itemx no-sse4
d77de738
ML
7169Enable/disable the generation of the SSE4 instructions (both SSE4.1
7170and SSE4.2).
7171
f33d7a88 7172@cindex @code{target("sse4.1")} function attribute, x86
d77de738
ML
7173@item sse4.1
7174@itemx no-sse4.1
d77de738
ML
7175Enable/disable the generation of the SSE4.1 instructions.
7176
f33d7a88 7177@cindex @code{target("sse4.2")} function attribute, x86
d77de738
ML
7178@item sse4.2
7179@itemx no-sse4.2
d77de738
ML
7180Enable/disable the generation of the SSE4.2 instructions.
7181
f33d7a88 7182@cindex @code{target("sse4a")} function attribute, x86
d77de738
ML
7183@item sse4a
7184@itemx no-sse4a
d77de738
ML
7185Enable/disable the generation of the SSE4A instructions.
7186
f33d7a88 7187@cindex @code{target("ssse3")} function attribute, x86
d77de738
ML
7188@item ssse3
7189@itemx no-ssse3
d77de738
ML
7190Enable/disable the generation of the SSSE3 instructions.
7191
f33d7a88 7192@cindex @code{target("tbm")} function attribute, x86
d77de738
ML
7193@item tbm
7194@itemx no-tbm
d77de738
ML
7195Enable/disable the generation of the TBM instructions.
7196
f33d7a88 7197@cindex @code{target("vaes")} function attribute, x86
d77de738
ML
7198@item vaes
7199@itemx no-vaes
d77de738
ML
7200Enable/disable the generation of the VAES instructions.
7201
f33d7a88 7202@cindex @code{target("vpclmulqdq")} function attribute, x86
d77de738
ML
7203@item vpclmulqdq
7204@itemx no-vpclmulqdq
d77de738
ML
7205Enable/disable the generation of the VPCLMULQDQ instructions.
7206
f33d7a88 7207@cindex @code{target("waitpkg")} function attribute, x86
d77de738
ML
7208@item waitpkg
7209@itemx no-waitpkg
d77de738
ML
7210Enable/disable the generation of the WAITPKG instructions.
7211
f33d7a88 7212@cindex @code{target("wbnoinvd")} function attribute, x86
d77de738
ML
7213@item wbnoinvd
7214@itemx no-wbnoinvd
d77de738
ML
7215Enable/disable the generation of the WBNOINVD instructions.
7216
f33d7a88 7217@cindex @code{target("xop")} function attribute, x86
d77de738
ML
7218@item xop
7219@itemx no-xop
d77de738
ML
7220Enable/disable the generation of the XOP instructions.
7221
f33d7a88 7222@cindex @code{target("xsave")} function attribute, x86
d77de738
ML
7223@item xsave
7224@itemx no-xsave
d77de738
ML
7225Enable/disable the generation of the XSAVE instructions.
7226
f33d7a88 7227@cindex @code{target("xsavec")} function attribute, x86
d77de738
ML
7228@item xsavec
7229@itemx no-xsavec
d77de738
ML
7230Enable/disable the generation of the XSAVEC instructions.
7231
f33d7a88 7232@cindex @code{target("xsaveopt")} function attribute, x86
d77de738
ML
7233@item xsaveopt
7234@itemx no-xsaveopt
d77de738
ML
7235Enable/disable the generation of the XSAVEOPT instructions.
7236
f33d7a88 7237@cindex @code{target("xsaves")} function attribute, x86
d77de738
ML
7238@item xsaves
7239@itemx no-xsaves
d77de738
ML
7240Enable/disable the generation of the XSAVES instructions.
7241
f33d7a88 7242@cindex @code{target("amx-tile")} function attribute, x86
d77de738
ML
7243@item amx-tile
7244@itemx no-amx-tile
d77de738
ML
7245Enable/disable the generation of the AMX-TILE instructions.
7246
f33d7a88 7247@cindex @code{target("amx-int8")} function attribute, x86
d77de738
ML
7248@item amx-int8
7249@itemx no-amx-int8
d77de738
ML
7250Enable/disable the generation of the AMX-INT8 instructions.
7251
f33d7a88 7252@cindex @code{target("amx-bf16")} function attribute, x86
d77de738
ML
7253@item amx-bf16
7254@itemx no-amx-bf16
d77de738
ML
7255Enable/disable the generation of the AMX-BF16 instructions.
7256
f33d7a88 7257@cindex @code{target("uintr")} function attribute, x86
d77de738
ML
7258@item uintr
7259@itemx no-uintr
d77de738
ML
7260Enable/disable the generation of the UINTR instructions.
7261
f33d7a88 7262@cindex @code{target("hreset")} function attribute, x86
d77de738
ML
7263@item hreset
7264@itemx no-hreset
d77de738
ML
7265Enable/disable the generation of the HRESET instruction.
7266
f33d7a88 7267@cindex @code{target("kl")} function attribute, x86
d77de738
ML
7268@item kl
7269@itemx no-kl
d77de738
ML
7270Enable/disable the generation of the KEYLOCKER instructions.
7271
f33d7a88 7272@cindex @code{target("widekl")} function attribute, x86
d77de738
ML
7273@item widekl
7274@itemx no-widekl
d77de738
ML
7275Enable/disable the generation of the WIDEKL instructions.
7276
f33d7a88 7277@cindex @code{target("avxvnni")} function attribute, x86
d77de738
ML
7278@item avxvnni
7279@itemx no-avxvnni
d77de738
ML
7280Enable/disable the generation of the AVXVNNI instructions.
7281
f33d7a88 7282@cindex @code{target("avxifma")} function attribute, x86
d77de738
ML
7283@item avxifma
7284@itemx no-avxifma
d77de738
ML
7285Enable/disable the generation of the AVXIFMA instructions.
7286
f33d7a88 7287@cindex @code{target("avxvnniint8")} function attribute, x86
d77de738
ML
7288@item avxvnniint8
7289@itemx no-avxvnniint8
d77de738
ML
7290Enable/disable the generation of the AVXVNNIINT8 instructions.
7291
f33d7a88 7292@cindex @code{target("avxneconvert")} function attribute, x86
d77de738
ML
7293@item avxneconvert
7294@itemx no-avxneconvert
d77de738
ML
7295Enable/disable the generation of the AVXNECONVERT instructions.
7296
f33d7a88 7297@cindex @code{target("cmpccxadd")} function attribute, x86
d77de738
ML
7298@item cmpccxadd
7299@itemx no-cmpccxadd
d77de738
ML
7300Enable/disable the generation of the CMPccXADD instructions.
7301
f33d7a88 7302@cindex @code{target("amx-fp16")} function attribute, x86
d77de738
ML
7303@item amx-fp16
7304@itemx no-amx-fp16
d77de738
ML
7305Enable/disable the generation of the AMX-FP16 instructions.
7306
f33d7a88 7307@cindex @code{target("prefetchi")} function attribute, x86
d77de738
ML
7308@item prefetchi
7309@itemx no-prefetchi
d77de738
ML
7310Enable/disable the generation of the PREFETCHI instructions.
7311
f33d7a88 7312@cindex @code{target("raoint")} function attribute, x86
d77de738
ML
7313@item raoint
7314@itemx no-raoint
d77de738
ML
7315Enable/disable the generation of the RAOINT instructions.
7316
efa6a82b
HJ
7317@cindex @code{target("amx-complex")} function attribute, x86
7318@item amx-complex
7319@itemx no-amx-complex
7320Enable/disable the generation of the AMX-COMPLEX instructions.
7321
1dbc1081
KL
7322@cindex @code{target("avxvnniint16")} function attribute, x86
7323@item avxvnniint16
7324@itemx no-avxvnniint16
7325Enable/disable the generation of the AVXVNNIINT16 instructions.
7326
8643bcba
HJ
7327@cindex @code{target("sm3")} function attribute, x86
7328@item sm3
7329@itemx no-sm3
7330Enable/disable the generation of the SM3 instructions.
7331
86446132
HJ
7332@cindex @code{target("sha512")} function attribute, x86
7333@item sha512
7334@itemx no-sha512
7335Enable/disable the generation of the SHA512 instructions.
7336
37bdeb8f
HJ
7337@cindex @code{target("sm4")} function attribute, x86
7338@item sm4
7339@itemx no-sm4
7340Enable/disable the generation of the SM4 instructions.
7341
5fbd91b1
HL
7342@cindex @code{target("usermsr")} function attribute, x86
7343@item usermsr
7344@itemx no-usermsr
7345Enable/disable the generation of the USER_MSR instructions.
7346
2f8f7ee2
HJ
7347@cindex @code{target("avx10.1")} function attribute, x86
7348@item avx10.1
7349@itemx no-avx10.1
7350Enable/disable the generation of the AVX10.1 instructions.
7351
7352@cindex @code{target("avx10.1-256")} function attribute, x86
7353@item avx10.1-256
7354@itemx no-avx10.1-256
7355Enable/disable the generation of the AVX10.1 instructions.
7356
7357@cindex @code{target("avx10.1-512")} function attribute, x86
7358@item avx10.1-512
7359@itemx no-avx10.1-512
7360Enable/disable the generation of the AVX10.1 512 bit instructions.
7361
f33d7a88 7362@cindex @code{target("cld")} function attribute, x86
d77de738
ML
7363@item cld
7364@itemx no-cld
d77de738
ML
7365Enable/disable the generation of the CLD before string moves.
7366
f33d7a88 7367@cindex @code{target("fancy-math-387")} function attribute, x86
d77de738
ML
7368@item fancy-math-387
7369@itemx no-fancy-math-387
d77de738
ML
7370Enable/disable the generation of the @code{sin}, @code{cos}, and
7371@code{sqrt} instructions on the 387 floating-point unit.
7372
f33d7a88 7373@cindex @code{target("ieee-fp")} function attribute, x86
d77de738
ML
7374@item ieee-fp
7375@itemx no-ieee-fp
d77de738
ML
7376Enable/disable the generation of floating point that depends on IEEE arithmetic.
7377
f33d7a88 7378@cindex @code{target("inline-all-stringops")} function attribute, x86
d77de738
ML
7379@item inline-all-stringops
7380@itemx no-inline-all-stringops
d77de738
ML
7381Enable/disable inlining of string operations.
7382
f33d7a88 7383@cindex @code{target("inline-stringops-dynamically")} function attribute, x86
d77de738
ML
7384@item inline-stringops-dynamically
7385@itemx no-inline-stringops-dynamically
d77de738
ML
7386Enable/disable the generation of the inline code to do small string
7387operations and calling the library routines for large operations.
7388
f33d7a88 7389@cindex @code{target("align-stringops")} function attribute, x86
d77de738
ML
7390@item align-stringops
7391@itemx no-align-stringops
d77de738
ML
7392Do/do not align destination of inlined string operations.
7393
f33d7a88 7394@cindex @code{target("recip")} function attribute, x86
d77de738
ML
7395@item recip
7396@itemx no-recip
d77de738
ML
7397Enable/disable the generation of RCPSS, RCPPS, RSQRTSS and RSQRTPS
7398instructions followed an additional Newton-Raphson step instead of
7399doing a floating-point division.
7400
d77de738 7401@cindex @code{target("general-regs-only")} function attribute, x86
f33d7a88 7402@item general-regs-only
d77de738
ML
7403Generate code which uses only the general registers.
7404
d77de738 7405@cindex @code{target("arch=@var{ARCH}")} function attribute, x86
f33d7a88 7406@item arch=@var{ARCH}
d77de738
ML
7407Specify the architecture to generate code for in compiling the function.
7408
d77de738 7409@cindex @code{target("tune=@var{TUNE}")} function attribute, x86
f33d7a88 7410@item tune=@var{TUNE}
d77de738
ML
7411Specify the architecture to tune for in compiling the function.
7412
d77de738 7413@cindex @code{target("fpmath=@var{FPMATH}")} function attribute, x86
f33d7a88 7414@item fpmath=@var{FPMATH}
d77de738
ML
7415Specify which floating-point unit to use. You must specify the
7416@code{target("fpmath=sse,387")} option as
7417@code{target("fpmath=sse+387")} because the comma would separate
7418different options.
7419
d77de738 7420@cindex @code{prefer-vector-width} function attribute, x86
f33d7a88 7421@item prefer-vector-width=@var{OPT}
d77de738
ML
7422On x86 targets, the @code{prefer-vector-width} attribute informs the
7423compiler to use @var{OPT}-bit vector width in instructions
7424instead of the default on the selected platform.
7425
7426Valid @var{OPT} values are:
7427
7428@table @samp
7429@item none
7430No extra limitations applied to GCC other than defined by the selected platform.
7431
7432@item 128
7433Prefer 128-bit vector width for instructions.
7434
7435@item 256
7436Prefer 256-bit vector width for instructions.
7437
7438@item 512
7439Prefer 512-bit vector width for instructions.
7440@end table
7441
d77de738
ML
7442@end table
7443
d77de738 7444@cindex @code{indirect_branch} function attribute, x86
f33d7a88 7445@item indirect_branch("@var{choice}")
d77de738
ML
7446On x86 targets, the @code{indirect_branch} attribute causes the compiler
7447to convert indirect call and jump with @var{choice}. @samp{keep}
7448keeps indirect call and jump unmodified. @samp{thunk} converts indirect
7449call and jump to call and return thunk. @samp{thunk-inline} converts
7450indirect call and jump to inlined call and return thunk.
7451@samp{thunk-extern} converts indirect call and jump to external call
7452and return thunk provided in a separate object file.
7453
d77de738 7454@cindex @code{function_return} function attribute, x86
f33d7a88 7455@item function_return("@var{choice}")
d77de738
ML
7456On x86 targets, the @code{function_return} attribute causes the compiler
7457to convert function return with @var{choice}. @samp{keep} keeps function
7458return unmodified. @samp{thunk} converts function return to call and
7459return thunk. @samp{thunk-inline} converts function return to inlined
7460call and return thunk. @samp{thunk-extern} converts function return to
7461external call and return thunk provided in a separate object file.
7462
d77de738 7463@cindex @code{nocf_check} function attribute
f33d7a88 7464@item nocf_check
d77de738
ML
7465The @code{nocf_check} attribute on a function is used to inform the
7466compiler that the function's prologue should not be instrumented when
7467compiled with the @option{-fcf-protection=branch} option. The
7468compiler assumes that the function's address is a valid target for a
7469control-flow transfer.
7470
7471The @code{nocf_check} attribute on a type of pointer to function is
7472used to inform the compiler that a call through the pointer should
7473not be instrumented when compiled with the
7474@option{-fcf-protection=branch} option. The compiler assumes
7475that the function's address from the pointer is a valid target for
7476a control-flow transfer. A direct function call through a function
7477name is assumed to be a safe call thus direct calls are not
7478instrumented by the compiler.
7479
7480The @code{nocf_check} attribute is applied to an object's type.
7481In case of assignment of a function address or a function pointer to
7482another pointer, the attribute is not carried over from the right-hand
7483object's type; the type of left-hand object stays unchanged. The
7484compiler checks for @code{nocf_check} attribute mismatch and reports
7485a warning in case of mismatch.
7486
7487@smallexample
7488@{
7489int foo (void) __attribute__(nocf_check);
7490void (*foo1)(void) __attribute__(nocf_check);
7491void (*foo2)(void);
7492
7493/* foo's address is assumed to be valid. */
7494int
7495foo (void)
7496
7497 /* This call site is not checked for control-flow
7498 validity. */
7499 (*foo1)();
7500
7501 /* A warning is issued about attribute mismatch. */
7502 foo1 = foo2;
7503
7504 /* This call site is still not checked. */
7505 (*foo1)();
7506
7507 /* This call site is checked. */
7508 (*foo2)();
7509
7510 /* A warning is issued about attribute mismatch. */
7511 foo2 = foo1;
7512
7513 /* This call site is still checked. */
7514 (*foo2)();
7515
7516 return 0;
7517@}
7518@end smallexample
7519
d77de738 7520@cindex @code{cf_check} function attribute, x86
f33d7a88 7521@item cf_check
d77de738
ML
7522
7523The @code{cf_check} attribute on a function is used to inform the
7524compiler that ENDBR instruction should be placed at the function
7525entry when @option{-fcf-protection=branch} is enabled.
7526
d77de738 7527@cindex @code{indirect_return} function attribute, x86
f33d7a88 7528@item indirect_return
d77de738
ML
7529
7530The @code{indirect_return} attribute can be applied to a function,
7531as well as variable or type of function pointer to inform the
7532compiler that the function may return via indirect branch.
7533
d77de738 7534@cindex @code{fentry_name} function attribute, x86
f33d7a88 7535@item fentry_name("@var{name}")
d77de738
ML
7536On x86 targets, the @code{fentry_name} attribute sets the function to
7537call on function entry when function instrumentation is enabled
7538with @option{-pg -mfentry}. When @var{name} is nop then a 5 byte
7539nop sequence is generated.
7540
d77de738 7541@cindex @code{fentry_section} function attribute, x86
f33d7a88 7542@item fentry_section("@var{name}")
d77de738
ML
7543On x86 targets, the @code{fentry_section} attribute sets the name
7544of the section to record function entry instrumentation calls in when
7545enabled with @option{-pg -mrecord-mcount}
7546
d77de738
ML
7547@cindex @code{nodirect_extern_access} function attribute
7548@opindex mno-direct-extern-access
f33d7a88 7549@item nodirect_extern_access
d77de738
ML
7550This attribute, attached to a global variable or function, is the
7551counterpart to option @option{-mno-direct-extern-access}.
7552
7553@end table
7554
6ded65b8
HW
7555@subsubsection Inlining rules
7556On the x86, the inliner does not inline a
7557function that has different target options than the caller, unless the
7558callee has a subset of the target options of the caller. For example
7559a function declared with @code{target("sse3")} can inline a function
7560with @code{target("sse2")}, since @code{-msse3} implies @code{-msse2}.
7561
7562Besides the basic rule, when a function specifies
7563@code{target("arch=@var{ARCH}")} or @code{target("tune=@var{TUNE}")}
7564attribute, the inlining rule will be different. It allows inlining of
7565a function with default @option{-march=x86-64} and
7566@option{-mtune=generic} specified, or a function that has a subset
7567of ISA features and marked with always_inline.
7568
d77de738
ML
7569@node Xstormy16 Function Attributes
7570@subsection Xstormy16 Function Attributes
7571
7572These function attributes are supported by the Xstormy16 back end:
7573
7574@table @code
d77de738 7575@cindex @code{interrupt} function attribute, Xstormy16
f33d7a88 7576@item interrupt
d77de738
ML
7577Use this attribute to indicate
7578that the specified function is an interrupt handler. The compiler generates
7579function entry and exit sequences suitable for use in an interrupt handler
7580when this attribute is present.
7581@end table
7582
7583@node Variable Attributes
7584@section Specifying Attributes of Variables
7585@cindex attribute of variables
7586@cindex variable attributes
7587
837a12a2 7588You can use attributes to specify special properties
d77de738 7589of variables, function parameters, or structure, union, and, in C++, class
837a12a2 7590members. Some attributes are currently
d77de738
ML
7591defined generically for variables. Other attributes are defined for
7592variables on particular target systems. Other attributes are available
7593for functions (@pxref{Function Attributes}), labels (@pxref{Label Attributes}),
7594enumerators (@pxref{Enumerator Attributes}), statements
7595(@pxref{Statement Attributes}), and for types (@pxref{Type Attributes}).
7596Other front ends might define more attributes
7597(@pxref{C++ Extensions,,Extensions to the C++ Language}).
7598
837a12a2
SL
7599GCC provides two different ways to specify attributes: the traditional
7600GNU syntax using @samp{__attribute__ ((...))} annotations, and the
7601newer standard C and C++ syntax using @samp{[[...]]} with the
7602@samp{gnu::} prefix on attribute names. Note that the exact rules for
7603placement of attributes in your source code are different depending on
7604which syntax you use. @xref{Attribute Syntax}, for details.
d77de738
ML
7605
7606@menu
7607* Common Variable Attributes::
7608* ARC Variable Attributes::
7609* AVR Variable Attributes::
7610* Blackfin Variable Attributes::
7611* H8/300 Variable Attributes::
7612* IA-64 Variable Attributes::
7613* LoongArch Variable Attributes::
7614* M32R/D Variable Attributes::
d77de738
ML
7615* Microsoft Windows Variable Attributes::
7616* MSP430 Variable Attributes::
7617* Nvidia PTX Variable Attributes::
7618* PowerPC Variable Attributes::
7619* RL78 Variable Attributes::
7620* V850 Variable Attributes::
7621* x86 Variable Attributes::
7622* Xstormy16 Variable Attributes::
7623@end menu
7624
7625@node Common Variable Attributes
7626@subsection Common Variable Attributes
7627
7628The following attributes are supported on most targets.
7629
7630@table @code
7631
d77de738 7632@cindex @code{alias} variable attribute
f33d7a88 7633@item alias ("@var{target}")
d77de738
ML
7634The @code{alias} variable attribute causes the declaration to be emitted
7635as an alias for another symbol known as an @dfn{alias target}. Except
7636for top-level qualifiers the alias target must have the same type as
7637the alias. For instance, the following
7638
7639@smallexample
7640int var_target;
7641extern int __attribute__ ((alias ("var_target"))) var_alias;
7642@end smallexample
7643
7644@noindent
7645defines @code{var_alias} to be an alias for the @code{var_target} variable.
7646
7647It is an error if the alias target is not defined in the same translation
7648unit as the alias.
7649
7650Note that in the absence of the attribute GCC assumes that distinct
7651declarations with external linkage denote distinct objects. Using both
7652the alias and the alias target to access the same object is undefined
7653in a translation unit without a declaration of the alias with the attribute.
7654
7655This attribute requires assembler and object file support, and may not be
7656available on all targets.
7657
7658@cindex @code{aligned} variable attribute
7659@item aligned
7660@itemx aligned (@var{alignment})
7661The @code{aligned} attribute specifies a minimum alignment for the variable
7662or structure field, measured in bytes. When specified, @var{alignment} must
7663be an integer constant power of 2. Specifying no @var{alignment} argument
7664implies the maximum alignment for the target, which is often, but by no
7665means always, 8 or 16 bytes.
7666
7667For example, the declaration:
7668
7669@smallexample
7670int x __attribute__ ((aligned (16))) = 0;
7671@end smallexample
7672
7673@noindent
7674causes the compiler to allocate the global variable @code{x} on a
767516-byte boundary. On a 68040, this could be used in conjunction with
7676an @code{asm} expression to access the @code{move16} instruction which
7677requires 16-byte aligned operands.
7678
7679You can also specify the alignment of structure fields. For example, to
7680create a double-word aligned @code{int} pair, you could write:
7681
7682@smallexample
7683struct foo @{ int x[2] __attribute__ ((aligned (8))); @};
7684@end smallexample
7685
7686@noindent
7687This is an alternative to creating a union with a @code{double} member,
7688which forces the union to be double-word aligned.
7689
7690As in the preceding examples, you can explicitly specify the alignment
7691(in bytes) that you wish the compiler to use for a given variable or
7692structure field. Alternatively, you can leave out the alignment factor
7693and just ask the compiler to align a variable or field to the
7694default alignment for the target architecture you are compiling for.
7695The default alignment is sufficient for all scalar types, but may not be
7696enough for all vector types on a target that supports vector operations.
7697The default alignment is fixed for a particular target ABI.
7698
7699GCC also provides a target specific macro @code{__BIGGEST_ALIGNMENT__},
7700which is the largest alignment ever used for any data type on the
7701target machine you are compiling for. For example, you could write:
7702
7703@smallexample
7704short array[3] __attribute__ ((aligned (__BIGGEST_ALIGNMENT__)));
7705@end smallexample
7706
7707The compiler automatically sets the alignment for the declared
7708variable or field to @code{__BIGGEST_ALIGNMENT__}. Doing this can
7709often make copy operations more efficient, because the compiler can
7710use whatever instructions copy the biggest chunks of memory when
7711performing copies to or from the variables or fields that you have
7712aligned this way. Note that the value of @code{__BIGGEST_ALIGNMENT__}
7713may change depending on command-line options.
7714
7715When used on a struct, or struct member, the @code{aligned} attribute can
7716only increase the alignment; in order to decrease it, the @code{packed}
7717attribute must be specified as well. When used as part of a typedef, the
7718@code{aligned} attribute can both increase and decrease alignment, and
7719specifying the @code{packed} attribute generates a warning.
7720
7721Note that the effectiveness of @code{aligned} attributes for static
7722variables may be limited by inherent limitations in the system linker
7723and/or object file format. On some systems, the linker is
7724only able to arrange for variables to be aligned up to a certain maximum
7725alignment. (For some linkers, the maximum supported alignment may
7726be very very small.) If your linker is only able to align variables
7727up to a maximum of 8-byte alignment, then specifying @code{aligned(16)}
7728in an @code{__attribute__} still only provides you with 8-byte
7729alignment. See your linker documentation for further information.
7730
7731Stack variables are not affected by linker restrictions; GCC can properly
7732align them on any target.
7733
7734The @code{aligned} attribute can also be used for functions
7735(@pxref{Common Function Attributes}.)
7736
7737@cindex @code{warn_if_not_aligned} variable attribute
7738@item warn_if_not_aligned (@var{alignment})
7739This attribute specifies a threshold for the structure field, measured
7740in bytes. If the structure field is aligned below the threshold, a
7741warning will be issued. For example, the declaration:
7742
7743@smallexample
7744struct foo
7745@{
7746 int i1;
7747 int i2;
7748 unsigned long long x __attribute__ ((warn_if_not_aligned (16)));
7749@};
7750@end smallexample
7751
7752@noindent
7753causes the compiler to issue an warning on @code{struct foo}, like
7754@samp{warning: alignment 8 of 'struct foo' is less than 16}.
7755The compiler also issues a warning, like @samp{warning: 'x' offset
77568 in 'struct foo' isn't aligned to 16}, when the structure field has
7757the misaligned offset:
7758
7759@smallexample
7760struct __attribute__ ((aligned (16))) foo
7761@{
7762 int i1;
7763 int i2;
7764 unsigned long long x __attribute__ ((warn_if_not_aligned (16)));
7765@};
7766@end smallexample
7767
7768This warning can be disabled by @option{-Wno-if-not-aligned}.
7769The @code{warn_if_not_aligned} attribute can also be used for types
7770(@pxref{Common Type Attributes}.)
7771
7772@cindex @code{strict_flex_array} variable attribute
7773@item strict_flex_array (@var{level})
7774The @code{strict_flex_array} attribute should be attached to the trailing
7775array field of a structure. It controls when to treat the trailing array
7776field of a structure as a flexible array member for the purposes of accessing
7777the elements of such an array.
7778@var{level} must be an integer betwen 0 to 3.
7779
7780@var{level}=0 is the least strict level, all trailing arrays of structures
7781are treated as flexible array members. @var{level}=3 is the strictest level,
7782only when the trailing array is declared as a flexible array member per C99
7783standard onwards (@samp{[]}), it is treated as a flexible array member.
7784
7785There are two more levels in between 0 and 3, which are provided to support
7786older codes that use GCC zero-length array extension (@samp{[0]}) or one-element
7787array as flexible array members (@samp{[1]}):
7788When @var{level} is 1, the trailing array is treated as a flexible array member
7789when it is declared as either @samp{[]}, @samp{[0]}, or @samp{[1]};
7790When @var{level} is 2, the trailing array is treated as a flexible array member
7791when it is declared as either @samp{[]}, or @samp{[0]}.
7792
7793This attribute can be used with or without the @option{-fstrict-flex-arrays}.
7794When both the attribute and the option present at the same time, the level of
7795the strictness for the specific trailing array field is determined by the
7796attribute.
7797
f33d7a88 7798@cindex @code{alloc_size} variable attribute
d77de738
ML
7799@item alloc_size (@var{position})
7800@itemx alloc_size (@var{position-1}, @var{position-2})
d77de738
ML
7801The @code{alloc_size} variable attribute may be applied to the declaration
7802of a pointer to a function that returns a pointer and takes at least one
7803argument of an integer type. It indicates that the returned pointer points
7804to an object whose size is given by the function argument at @var{position},
7805or by the product of the arguments at @var{position-1} and @var{position-2}.
7806Meaningful sizes are positive values less than @code{PTRDIFF_MAX}. Other
7807sizes are diagnosed when detected. GCC uses this information to improve
7808the results of @code{__builtin_object_size}.
7809
7810For instance, the following declarations
7811
7812@smallexample
7813typedef __attribute__ ((alloc_size (1, 2))) void*
7814 (*calloc_ptr) (size_t, size_t);
7815typedef __attribute__ ((alloc_size (1))) void*
7816 (*malloc_ptr) (size_t);
7817@end smallexample
7818
7819@noindent
7820specify that @code{calloc_ptr} is a pointer of a function that, like
7821the standard C function @code{calloc}, returns an object whose size
7822is given by the product of arguments 1 and 2, and similarly, that
7823@code{malloc_ptr}, like the standard C function @code{malloc},
7824returns an object whose size is given by argument 1 to the function.
7825
d77de738 7826@cindex @code{cleanup} variable attribute
f33d7a88 7827@item cleanup (@var{cleanup_function})
d77de738
ML
7828The @code{cleanup} attribute runs a function when the variable goes
7829out of scope. This attribute can only be applied to auto function
7830scope variables; it may not be applied to parameters or variables
7831with static storage duration. The function must take one parameter,
7832a pointer to a type compatible with the variable. The return value
7833of the function (if any) is ignored.
7834
7835If @option{-fexceptions} is enabled, then @var{cleanup_function}
7836is run during the stack unwinding that happens during the
7837processing of the exception. Note that the @code{cleanup} attribute
7838does not allow the exception to be caught, only to perform an action.
7839It is undefined what happens if @var{cleanup_function} does not
7840return normally.
7841
d77de738
ML
7842@cindex @code{common} variable attribute
7843@cindex @code{nocommon} variable attribute
7844@opindex fcommon
7845@opindex fno-common
f33d7a88
AA
7846@item common
7847@itemx nocommon
d77de738
ML
7848The @code{common} attribute requests GCC to place a variable in
7849``common'' storage. The @code{nocommon} attribute requests the
7850opposite---to allocate space for it directly.
7851
7852These attributes override the default chosen by the
7853@option{-fno-common} and @option{-fcommon} flags respectively.
7854
f33d7a88 7855@cindex @code{copy} variable attribute
d77de738
ML
7856@item copy
7857@itemx copy (@var{variable})
d77de738
ML
7858The @code{copy} attribute applies the set of attributes with which
7859@var{variable} has been declared to the declaration of the variable
7860to which the attribute is applied. The attribute is designed for
7861libraries that define aliases that are expected to specify the same
7862set of attributes as the aliased symbols. The @code{copy} attribute
7863can be used with variables, functions or types. However, the kind
7864of symbol to which the attribute is applied (either varible or
7865function) must match the kind of symbol to which the argument refers.
7866The @code{copy} attribute copies only syntactic and semantic attributes
7867but not attributes that affect a symbol's linkage or visibility such as
7868@code{alias}, @code{visibility}, or @code{weak}. The @code{deprecated}
7869attribute is also not copied. @xref{Common Function Attributes}.
7870@xref{Common Type Attributes}.
7871
f33d7a88 7872@cindex @code{deprecated} variable attribute
d77de738
ML
7873@item deprecated
7874@itemx deprecated (@var{msg})
d77de738
ML
7875The @code{deprecated} attribute results in a warning if the variable
7876is used anywhere in the source file. This is useful when identifying
7877variables that are expected to be removed in a future version of a
7878program. The warning also includes the location of the declaration
7879of the deprecated variable, to enable users to easily find further
7880information about why the variable is deprecated, or what they should
7881do instead. Note that the warning only occurs for uses:
7882
7883@smallexample
7884extern int old_var __attribute__ ((deprecated));
7885extern int old_var;
7886int new_fn () @{ return old_var; @}
7887@end smallexample
7888
7889@noindent
7890results in a warning on line 3 but not line 2. The optional @var{msg}
7891argument, which must be a string, is printed in the warning if
7892present.
7893
7894The @code{deprecated} attribute can also be used for functions and
7895types (@pxref{Common Function Attributes},
7896@pxref{Common Type Attributes}).
7897
7898The message attached to the attribute is affected by the setting of
7899the @option{-fmessage-length} option.
7900
f33d7a88 7901@cindex @code{unavailable} variable attribute
d77de738
ML
7902@item unavailable
7903@itemx unavailable (@var{msg})
d77de738
ML
7904The @code{unavailable} attribute indicates that the variable so marked
7905is not available, if it is used anywhere in the source file. It behaves
7906in the same manner as the @code{deprecated} attribute except that the
7907compiler will emit an error rather than a warning.
7908
7909It is expected that items marked as @code{deprecated} will eventually be
7910withdrawn from interfaces, and then become unavailable. This attribute
7911allows for marking them appropriately.
7912
7913The @code{unavailable} attribute can also be used for functions and
7914types (@pxref{Common Function Attributes},
7915@pxref{Common Type Attributes}).
7916
d77de738 7917@cindex @code{mode} variable attribute
f33d7a88 7918@item mode (@var{mode})
d77de738
ML
7919This attribute specifies the data type for the declaration---whichever
7920type corresponds to the mode @var{mode}. This in effect lets you
7921request an integer or floating-point type according to its width.
7922
7923@xref{Machine Modes,,, gccint, GNU Compiler Collection (GCC) Internals},
7924for a list of the possible keywords for @var{mode}.
7925You may also specify a mode of @code{byte} or @code{__byte__} to
7926indicate the mode corresponding to a one-byte integer, @code{word} or
7927@code{__word__} for the mode of a one-word integer, and @code{pointer}
7928or @code{__pointer__} for the mode used to represent pointers.
7929
d77de738 7930@cindex @code{nonstring} variable attribute
f33d7a88 7931@item nonstring
d77de738
ML
7932The @code{nonstring} variable attribute specifies that an object or member
7933declaration with type array of @code{char}, @code{signed char}, or
7934@code{unsigned char}, or pointer to such a type is intended to store
7935character arrays that do not necessarily contain a terminating @code{NUL}.
7936This is useful in detecting uses of such arrays or pointers with functions
7937that expect @code{NUL}-terminated strings, and to avoid warnings when such
7938an array or pointer is used as an argument to a bounded string manipulation
7939function such as @code{strncpy}. For example, without the attribute, GCC
7940will issue a warning for the @code{strncpy} call below because it may
7941truncate the copy without appending the terminating @code{NUL} character.
7942Using the attribute makes it possible to suppress the warning. However,
7943when the array is declared with the attribute the call to @code{strlen} is
7944diagnosed because when the array doesn't contain a @code{NUL}-terminated
7945string the call is undefined. To copy, compare, of search non-string
7946character arrays use the @code{memcpy}, @code{memcmp}, @code{memchr},
7947and other functions that operate on arrays of bytes. In addition,
7948calling @code{strnlen} and @code{strndup} with such arrays is safe
7949provided a suitable bound is specified, and not diagnosed.
7950
7951@smallexample
7952struct Data
7953@{
7954 char name [32] __attribute__ ((nonstring));
7955@};
7956
7957int f (struct Data *pd, const char *s)
7958@{
7959 strncpy (pd->name, s, sizeof pd->name);
7960 @dots{}
7961 return strlen (pd->name); // unsafe, gets a warning
7962@}
7963@end smallexample
7964
d77de738 7965@cindex @code{packed} variable attribute
f33d7a88 7966@item packed
d77de738
ML
7967The @code{packed} attribute specifies that a structure member should have
7968the smallest possible alignment---one bit for a bit-field and one byte
7969otherwise, unless a larger value is specified with the @code{aligned}
7970attribute. The attribute does not apply to non-member objects.
7971
7972For example in the structure below, the member array @code{x} is packed
7973so that it immediately follows @code{a} with no intervening padding:
7974
7975@smallexample
7976struct foo
7977@{
7978 char a;
7979 int x[2] __attribute__ ((packed));
7980@};
7981@end smallexample
7982
7983@emph{Note:} The 4.1, 4.2 and 4.3 series of GCC ignore the
7984@code{packed} attribute on bit-fields of type @code{char}. This has
7985been fixed in GCC 4.4 but the change can lead to differences in the
7986structure layout. See the documentation of
7987@option{-Wpacked-bitfield-compat} for more information.
7988
d77de738 7989@cindex @code{section} variable attribute
f33d7a88 7990@item section ("@var{section-name}")
d77de738
ML
7991Normally, the compiler places the objects it generates in sections like
7992@code{data} and @code{bss}. Sometimes, however, you need additional sections,
7993or you need certain particular variables to appear in special sections,
7994for example to map to special hardware. The @code{section}
7995attribute specifies that a variable (or function) lives in a particular
7996section. For example, this small program uses several specific section names:
7997
7998@smallexample
7999struct duart a __attribute__ ((section ("DUART_A"))) = @{ 0 @};
8000struct duart b __attribute__ ((section ("DUART_B"))) = @{ 0 @};
8001char stack[10000] __attribute__ ((section ("STACK"))) = @{ 0 @};
8002int init_data __attribute__ ((section ("INITDATA")));
8003
8004main()
8005@{
8006 /* @r{Initialize stack pointer} */
8007 init_sp (stack + sizeof (stack));
8008
8009 /* @r{Initialize initialized data} */
8010 memcpy (&init_data, &data, &edata - &data);
8011
8012 /* @r{Turn on the serial ports} */
8013 init_duart (&a);
8014 init_duart (&b);
8015@}
8016@end smallexample
8017
8018@noindent
8019Use the @code{section} attribute with
8020@emph{global} variables and not @emph{local} variables,
8021as shown in the example.
8022
8023You may use the @code{section} attribute with initialized or
8024uninitialized global variables but the linker requires
8025each object be defined once, with the exception that uninitialized
8026variables tentatively go in the @code{common} (or @code{bss}) section
8027and can be multiply ``defined''. Using the @code{section} attribute
8028changes what section the variable goes into and may cause the
8029linker to issue an error if an uninitialized variable has multiple
8030definitions. You can force a variable to be initialized with the
8031@option{-fno-common} flag or the @code{nocommon} attribute.
8032
8033Some file formats do not support arbitrary sections so the @code{section}
8034attribute is not available on all platforms.
8035If you need to map the entire contents of a module to a particular
8036section, consider using the facilities of the linker instead.
8037
d77de738 8038@cindex @code{tls_model} variable attribute
f33d7a88 8039@item tls_model ("@var{tls_model}")
d77de738
ML
8040The @code{tls_model} attribute sets thread-local storage model
8041(@pxref{Thread-Local}) of a particular @code{__thread} variable,
8042overriding @option{-ftls-model=} command-line switch on a per-variable
8043basis.
8044The @var{tls_model} argument should be one of @code{global-dynamic},
8045@code{local-dynamic}, @code{initial-exec} or @code{local-exec}.
8046
8047Not all targets support this attribute.
8048
d77de738 8049@cindex @code{unused} variable attribute
f33d7a88 8050@item unused
d77de738
ML
8051This attribute, attached to a variable or structure field, means that
8052the variable or field is meant to be possibly unused. GCC does not
8053produce a warning for this variable or field.
8054
d77de738 8055@cindex @code{used} variable attribute
f33d7a88 8056@item used
d77de738
ML
8057This attribute, attached to a variable with static storage, means that
8058the variable must be emitted even if it appears that the variable is not
8059referenced.
8060
8061When applied to a static data member of a C++ class template, the
8062attribute also means that the member is instantiated if the
8063class itself is instantiated.
8064
d77de738 8065@cindex @code{retain} variable attribute
f33d7a88 8066@item retain
d77de738
ML
8067For ELF targets that support the GNU or FreeBSD OSABIs, this attribute
8068will save the variable from linker garbage collection. To support
8069this behavior, variables that have not been placed in specific sections
8070(e.g. by the @code{section} attribute, or the @code{-fdata-sections} option),
8071will be placed in new, unique sections.
8072
8073This additional functionality requires Binutils version 2.36 or later.
8074
d77de738 8075@cindex @code{uninitialized} variable attribute
f33d7a88 8076@item uninitialized
d77de738
ML
8077This attribute, attached to a variable with automatic storage, means that
8078the variable should not be automatically initialized by the compiler when
8079the option @code{-ftrivial-auto-var-init} presents.
8080
8081With the option @code{-ftrivial-auto-var-init}, all the automatic variables
8082that do not have explicit initializers will be initialized by the compiler.
8083These additional compiler initializations might incur run-time overhead,
8084sometimes dramatically. This attribute can be used to mark some variables
8085to be excluded from such automatical initialization in order to reduce runtime
8086overhead.
8087
8088This attribute has no effect when the option @code{-ftrivial-auto-var-init}
8089does not present.
8090
d77de738 8091@cindex @code{vector_size} variable attribute
f33d7a88 8092@item vector_size (@var{bytes})
d77de738
ML
8093This attribute specifies the vector size for the type of the declared
8094variable, measured in bytes. The type to which it applies is known as
8095the @dfn{base type}. The @var{bytes} argument must be a positive
8096power-of-two multiple of the base type size. For example, the declaration:
8097
8098@smallexample
8099int foo __attribute__ ((vector_size (16)));
8100@end smallexample
8101
8102@noindent
8103causes the compiler to set the mode for @code{foo}, to be 16 bytes,
8104divided into @code{int} sized units. Assuming a 32-bit @code{int},
8105@code{foo}'s type is a vector of four units of four bytes each, and
8106the corresponding mode of @code{foo} is @code{V4SI}.
8107@xref{Vector Extensions}, for details of manipulating vector variables.
8108
8109This attribute is only applicable to integral and floating scalars,
8110although arrays, pointers, and function return values are allowed in
8111conjunction with this construct.
8112
8113Aggregates with this attribute are invalid, even if they are of the same
8114size as a corresponding scalar. For example, the declaration:
8115
8116@smallexample
8117struct S @{ int a; @};
8118struct S __attribute__ ((vector_size (16))) foo;
8119@end smallexample
8120
8121@noindent
8122is invalid even if the size of the structure is the same as the size of
8123the @code{int}.
8124
d77de738 8125@cindex @code{visibility} variable attribute
f33d7a88 8126@item visibility ("@var{visibility_type}")
d77de738
ML
8127This attribute affects the linkage of the declaration to which it is attached.
8128The @code{visibility} attribute is described in
8129@ref{Common Function Attributes}.
8130
d77de738 8131@cindex @code{weak} variable attribute
f33d7a88 8132@item weak
d77de738
ML
8133The @code{weak} attribute is described in
8134@ref{Common Function Attributes}.
8135
d77de738 8136@cindex @code{noinit} variable attribute
f33d7a88 8137@item noinit
d77de738
ML
8138Any data with the @code{noinit} attribute will not be initialized by
8139the C runtime startup code, or the program loader. Not initializing
8140data in this way can reduce program startup times.
8141
8142This attribute is specific to ELF targets and relies on the linker
8143script to place sections with the @code{.noinit} prefix in the right
8144location.
8145
d77de738 8146@cindex @code{persistent} variable attribute
f33d7a88 8147@item persistent
d77de738
ML
8148Any data with the @code{persistent} attribute will not be initialized by
8149the C runtime startup code, but will be initialized by the program
8150loader. This enables the value of the variable to @samp{persist}
8151between processor resets.
8152
8153This attribute is specific to ELF targets and relies on the linker
8154script to place the sections with the @code{.persistent} prefix in the
8155right location. Specifically, some type of non-volatile, writeable
8156memory is required.
8157
eee13a37
RB
8158@cindex @code{no_icf} variable attribute
8159@item no_icf
8160This variable attribute prevents a variable from being merged with another
8161equivalent variable.
8162
d77de738 8163@cindex @code{objc_nullability} variable attribute
f33d7a88 8164@item objc_nullability (@var{nullability kind}) @r{(Objective-C and Objective-C++ only)}
d77de738
ML
8165This attribute applies to pointer variables only. It allows marking the
8166pointer with one of four possible values describing the conditions under
8167which the pointer might have a @code{nil} value. In most cases, the
8168attribute is intended to be an internal representation for property and
8169method nullability (specified by language keywords); it is not recommended
8170to use it directly.
8171
8172When @var{nullability kind} is @code{"unspecified"} or @code{0}, nothing is
8173known about the conditions in which the pointer might be @code{nil}. Making
8174this state specific serves to avoid false positives in diagnostics.
8175
8176When @var{nullability kind} is @code{"nonnull"} or @code{1}, the pointer has
8177no meaning if it is @code{nil} and thus the compiler is free to emit
8178diagnostics if it can be determined that the value will be @code{nil}.
8179
8180When @var{nullability kind} is @code{"nullable"} or @code{2}, the pointer might
8181be @code{nil} and carry meaning as such.
8182
8183When @var{nullability kind} is @code{"resettable"} or @code{3} (used only in
8184the context of property attribute lists) this describes the case in which a
8185property setter may take the value @code{nil} (which perhaps causes the
8186property to be reset in some manner to a default) but for which the property
8187getter will never validly return @code{nil}.
8188
8189@end table
8190
8191@node ARC Variable Attributes
8192@subsection ARC Variable Attributes
8193
8194@table @code
d77de738 8195@cindex @code{aux} variable attribute, ARC
f33d7a88 8196@item aux
d77de738
ML
8197The @code{aux} attribute is used to directly access the ARC's
8198auxiliary register space from C. The auxilirary register number is
8199given via attribute argument.
8200
8201@end table
8202
8203@node AVR Variable Attributes
8204@subsection AVR Variable Attributes
8205
8206@table @code
d77de738 8207@cindex @code{progmem} variable attribute, AVR
f33d7a88 8208@item progmem
d77de738
ML
8209The @code{progmem} attribute is used on the AVR to place read-only
8210data in the non-volatile program memory (flash). The @code{progmem}
8211attribute accomplishes this by putting respective variables into a
8212section whose name starts with @code{.progmem}.
8213
8214This attribute works similar to the @code{section} attribute
8215but adds additional checking.
8216
8217@table @asis
8218@item @bullet{} Ordinary AVR cores with 32 general purpose registers:
8219@code{progmem} affects the location
8220of the data but not how this data is accessed.
8221In order to read data located with the @code{progmem} attribute
8222(inline) assembler must be used.
8223@smallexample
1be72408 8224/* Use custom macros from AVR-LibC */
d77de738
ML
8225#include <avr/pgmspace.h>
8226
8227/* Locate var in flash memory */
8228const int var[2] PROGMEM = @{ 1, 2 @};
8229
8230int read_var (int i)
8231@{
8232 /* Access var[] by accessor macro from avr/pgmspace.h */
8233 return (int) pgm_read_word (& var[i]);
8234@}
8235@end smallexample
8236
8237AVR is a Harvard architecture processor and data and read-only data
8238normally resides in the data memory (RAM).
8239
8240See also the @ref{AVR Named Address Spaces} section for
8241an alternate way to locate and access data in flash memory.
8242
8243@item @bullet{} AVR cores with flash memory visible in the RAM address range:
8244On such devices, there is no need for attribute @code{progmem} or
8245@ref{AVR Named Address Spaces,,@code{__flash}} qualifier at all.
8246Just use standard C / C++. The compiler will generate @code{LD*}
8247instructions. As flash memory is visible in the RAM address range,
8248and the default linker script does @emph{not} locate @code{.rodata} in
8249RAM, no special features are needed in order not to waste RAM for
8250read-only data or to read from flash. You might even get slightly better
8251performance by
8252avoiding @code{progmem} and @code{__flash}. This applies to devices from
8253families @code{avrtiny} and @code{avrxmega3}, see @ref{AVR Options} for
8254an overview.
8255
8256@item @bullet{} Reduced AVR Tiny cores like ATtiny40:
8257The compiler adds @code{0x4000}
8258to the addresses of objects and declarations in @code{progmem} and locates
8259the objects in flash memory, namely in section @code{.progmem.data}.
8260The offset is needed because the flash memory is visible in the RAM
8261address space starting at address @code{0x4000}.
8262
8263Data in @code{progmem} can be accessed by means of ordinary C@tie{}code,
8264no special functions or macros are needed.
8265
8266@smallexample
8267/* var is located in flash memory */
8268extern const int var[2] __attribute__((progmem));
8269
8270int read_var (int i)
8271@{
8272 return var[i];
8273@}
8274@end smallexample
8275
8276Please notice that on these devices, there is no need for @code{progmem}
8277at all.
8278
8279@end table
8280
f33d7a88 8281@cindex @code{io} variable attribute, AVR
d77de738
ML
8282@item io
8283@itemx io (@var{addr})
d77de738
ML
8284Variables with the @code{io} attribute are used to address
8285memory-mapped peripherals in the io address range.
8286If an address is specified, the variable
8287is assigned that address, and the value is interpreted as an
8288address in the data address space.
8289Example:
8290
8291@smallexample
8292volatile int porta __attribute__((io (0x22)));
8293@end smallexample
8294
8295The address specified in the address in the data address range.
8296
8297Otherwise, the variable it is not assigned an address, but the
8298compiler will still use in/out instructions where applicable,
8299assuming some other module assigns an address in the io address range.
8300Example:
8301
8302@smallexample
8303extern volatile int porta __attribute__((io));
8304@end smallexample
8305
f33d7a88 8306@cindex @code{io_low} variable attribute, AVR
d77de738
ML
8307@item io_low
8308@itemx io_low (@var{addr})
d77de738
ML
8309This is like the @code{io} attribute, but additionally it informs the
8310compiler that the object lies in the lower half of the I/O area,
8311allowing the use of @code{cbi}, @code{sbi}, @code{sbic} and @code{sbis}
8312instructions.
8313
f33d7a88 8314@cindex @code{address} variable attribute, AVR
d77de738
ML
8315@item address
8316@itemx address (@var{addr})
d77de738
ML
8317Variables with the @code{address} attribute are used to address
8318memory-mapped peripherals that may lie outside the io address range.
8319
8320@smallexample
8321volatile int porta __attribute__((address (0x600)));
8322@end smallexample
8323
d77de738 8324@cindex @code{absdata} variable attribute, AVR
f33d7a88 8325@item absdata
d77de738
ML
8326Variables in static storage and with the @code{absdata} attribute can
8327be accessed by the @code{LDS} and @code{STS} instructions which take
8328absolute addresses.
8329
8330@itemize @bullet
8331@item
8332This attribute is only supported for the reduced AVR Tiny core
8333like ATtiny40.
8334
8335@item
8336You must make sure that respective data is located in the
8337address range @code{0x40}@dots{}@code{0xbf} accessible by
8338@code{LDS} and @code{STS}. One way to achieve this as an
8339appropriate linker description file.
8340
8341@item
8342If the location does not fit the address range of @code{LDS}
8343and @code{STS}, there is currently (Binutils 2.26) just an unspecific
8344warning like
8345@quotation
8346@code{module.cc:(.text+0x1c): warning: internal error: out of range error}
8347@end quotation
8348
8349@end itemize
8350
8351See also the @option{-mabsdata} @ref{AVR Options,command-line option}.
8352
8353@end table
8354
8355@node Blackfin Variable Attributes
8356@subsection Blackfin Variable Attributes
8357
8358Three attributes are currently defined for the Blackfin.
8359
8360@table @code
d77de738
ML
8361@cindex @code{l1_data} variable attribute, Blackfin
8362@cindex @code{l1_data_A} variable attribute, Blackfin
8363@cindex @code{l1_data_B} variable attribute, Blackfin
f33d7a88
AA
8364@item l1_data
8365@itemx l1_data_A
8366@itemx l1_data_B
d77de738
ML
8367Use these attributes on the Blackfin to place the variable into L1 Data SRAM.
8368Variables with @code{l1_data} attribute are put into the specific section
8369named @code{.l1.data}. Those with @code{l1_data_A} attribute are put into
8370the specific section named @code{.l1.data.A}. Those with @code{l1_data_B}
8371attribute are put into the specific section named @code{.l1.data.B}.
8372
d77de738 8373@cindex @code{l2} variable attribute, Blackfin
f33d7a88 8374@item l2
d77de738
ML
8375Use this attribute on the Blackfin to place the variable into L2 SRAM.
8376Variables with @code{l2} attribute are put into the specific section
8377named @code{.l2.data}.
8378@end table
8379
8380@node H8/300 Variable Attributes
8381@subsection H8/300 Variable Attributes
8382
8383These variable attributes are available for H8/300 targets:
8384
8385@table @code
d77de738
ML
8386@cindex @code{eightbit_data} variable attribute, H8/300
8387@cindex eight-bit data on the H8/300, H8/300H, and H8S
f33d7a88 8388@item eightbit_data
d77de738
ML
8389Use this attribute on the H8/300, H8/300H, and H8S to indicate that the specified
8390variable should be placed into the eight-bit data section.
8391The compiler generates more efficient code for certain operations
8392on data in the eight-bit data area. Note the eight-bit data area is limited to
8393256 bytes of data.
8394
8395You must use GAS and GLD from GNU binutils version 2.7 or later for
8396this attribute to work correctly.
8397
d77de738
ML
8398@cindex @code{tiny_data} variable attribute, H8/300
8399@cindex tiny data section on the H8/300H and H8S
f33d7a88 8400@item tiny_data
d77de738
ML
8401Use this attribute on the H8/300H and H8S to indicate that the specified
8402variable should be placed into the tiny data section.
8403The compiler generates more efficient code for loads and stores
8404on data in the tiny data section. Note the tiny data area is limited to
8405slightly under 32KB of data.
8406
8407@end table
8408
8409@node IA-64 Variable Attributes
8410@subsection IA-64 Variable Attributes
8411
8412The IA-64 back end supports the following variable attribute:
8413
8414@table @code
d77de738 8415@cindex @code{model} variable attribute, IA-64
f33d7a88 8416@item model (@var{model-name})
d77de738
ML
8417
8418On IA-64, use this attribute to set the addressability of an object.
8419At present, the only supported identifier for @var{model-name} is
8420@code{small}, indicating addressability via ``small'' (22-bit)
8421addresses (so that their addresses can be loaded with the @code{addl}
8422instruction). Caveat: such addressing is by definition not position
8423independent and hence this attribute must not be used for objects
8424defined by shared libraries.
8425
8426@end table
8427
8428@node LoongArch Variable Attributes
8429@subsection LoongArch Variable Attributes
8430
8431One attribute is currently defined for the LoongArch.
8432
8433@table @code
d77de738 8434@cindex @code{model} variable attribute, LoongArch
f33d7a88 8435@item model("@var{name}")
d77de738
ML
8436Use this attribute on the LoongArch to use a different code model for
8437addressing this variable, than the code model specified by the global
8438@option{-mcmodel} option. This attribute is mostly useful if a
8439@code{section} attribute and/or a linker script will locate this object
8440specially. Currently the only supported values of @var{name} are
8441@code{normal} and @code{extreme}.
8442@end table
8443
8444@node M32R/D Variable Attributes
8445@subsection M32R/D Variable Attributes
8446
8447One attribute is currently defined for the M32R/D@.
8448
8449@table @code
d77de738
ML
8450@cindex @code{model-name} variable attribute, M32R/D
8451@cindex variable addressability on the M32R/D
f33d7a88 8452@item model (@var{model-name})
d77de738
ML
8453Use this attribute on the M32R/D to set the addressability of an object.
8454The identifier @var{model-name} is one of @code{small}, @code{medium},
8455or @code{large}, representing each of the code models.
8456
8457Small model objects live in the lower 16MB of memory (so that their
8458addresses can be loaded with the @code{ld24} instruction).
8459
8460Medium and large model objects may live anywhere in the 32-bit address space
8461(the compiler generates @code{seth/add3} instructions to load their
8462addresses).
8463@end table
8464
d77de738
ML
8465@node Microsoft Windows Variable Attributes
8466@subsection Microsoft Windows Variable Attributes
8467
8468You can use these attributes on Microsoft Windows targets.
8469@ref{x86 Variable Attributes} for additional Windows compatibility
8470attributes available on all x86 targets.
8471
8472@table @code
d77de738
ML
8473@cindex @code{dllimport} variable attribute
8474@cindex @code{dllexport} variable attribute
f33d7a88
AA
8475@item dllimport
8476@itemx dllexport
d77de738
ML
8477The @code{dllimport} and @code{dllexport} attributes are described in
8478@ref{Microsoft Windows Function Attributes}.
8479
d77de738 8480@cindex @code{selectany} variable attribute
f33d7a88 8481@item selectany
d77de738
ML
8482The @code{selectany} attribute causes an initialized global variable to
8483have link-once semantics. When multiple definitions of the variable are
8484encountered by the linker, the first is selected and the remainder are
8485discarded. Following usage by the Microsoft compiler, the linker is told
8486@emph{not} to warn about size or content differences of the multiple
8487definitions.
8488
8489Although the primary usage of this attribute is for POD types, the
8490attribute can also be applied to global C++ objects that are initialized
8491by a constructor. In this case, the static initialization and destruction
8492code for the object is emitted in each translation defining the object,
8493but the calls to the constructor and destructor are protected by a
8494link-once guard variable.
8495
8496The @code{selectany} attribute is only available on Microsoft Windows
8497targets. You can use @code{__declspec (selectany)} as a synonym for
8498@code{__attribute__ ((selectany))} for compatibility with other
8499compilers.
8500
d77de738 8501@cindex @code{shared} variable attribute
f33d7a88 8502@item shared
d77de738
ML
8503On Microsoft Windows, in addition to putting variable definitions in a named
8504section, the section can also be shared among all running copies of an
8505executable or DLL@. For example, this small program defines shared data
8506by putting it in a named section @code{shared} and marking the section
8507shareable:
8508
8509@smallexample
8510int foo __attribute__((section ("shared"), shared)) = 0;
8511
8512int
8513main()
8514@{
8515 /* @r{Read and write foo. All running
8516 copies see the same value.} */
8517 return 0;
8518@}
8519@end smallexample
8520
8521@noindent
8522You may only use the @code{shared} attribute along with @code{section}
8523attribute with a fully-initialized global definition because of the way
8524linkers work. See @code{section} attribute for more information.
8525
8526The @code{shared} attribute is only available on Microsoft Windows@.
8527
8528@end table
8529
8530@node MSP430 Variable Attributes
8531@subsection MSP430 Variable Attributes
8532
8533@table @code
d77de738
ML
8534@cindex @code{upper} variable attribute, MSP430
8535@cindex @code{either} variable attribute, MSP430
f33d7a88
AA
8536@item upper
8537@itemx either
d77de738
ML
8538These attributes are the same as the MSP430 function attributes of the
8539same name (@pxref{MSP430 Function Attributes}).
8540
d77de738 8541@cindex @code{lower} variable attribute, MSP430
f33d7a88 8542@item lower
d77de738
ML
8543This option behaves mostly the same as the MSP430 function attribute of the
8544same name (@pxref{MSP430 Function Attributes}), but it has some additional
8545functionality.
8546
8547If @option{-mdata-region=}@{@code{upper,either,none}@} has been passed, or
8548the @code{section} attribute is applied to a variable, the compiler will
8549generate 430X instructions to handle it. This is because the compiler has
8550to assume that the variable could get placed in the upper memory region
8551(above address 0xFFFF). Marking the variable with the @code{lower} attribute
8552informs the compiler that the variable will be placed in lower memory so it
8553is safe to use 430 instructions to handle it.
8554
8555In the case of the @code{section} attribute, the section name given
8556will be used, and the @code{.lower} prefix will not be added.
8557
8558@end table
8559
8560@node Nvidia PTX Variable Attributes
8561@subsection Nvidia PTX Variable Attributes
8562
8563These variable attributes are supported by the Nvidia PTX back end:
8564
8565@table @code
d77de738 8566@cindex @code{shared} attribute, Nvidia PTX
f33d7a88 8567@item shared
d77de738
ML
8568Use this attribute to place a variable in the @code{.shared} memory space.
8569This memory space is private to each cooperative thread array; only threads
8570within one thread block refer to the same instance of the variable.
8571The runtime does not initialize variables in this memory space.
8572@end table
8573
8574@node PowerPC Variable Attributes
8575@subsection PowerPC Variable Attributes
8576
8577Three attributes currently are defined for PowerPC configurations:
8578@code{altivec}, @code{ms_struct} and @code{gcc_struct}.
8579
8580@cindex @code{ms_struct} variable attribute, PowerPC
8581@cindex @code{gcc_struct} variable attribute, PowerPC
8582For full documentation of the struct attributes please see the
8583documentation in @ref{x86 Variable Attributes}.
8584
8585@cindex @code{altivec} variable attribute, PowerPC
8586For documentation of @code{altivec} attribute please see the
8587documentation in @ref{PowerPC Type Attributes}.
8588
8589@node RL78 Variable Attributes
8590@subsection RL78 Variable Attributes
8591
8592@cindex @code{saddr} variable attribute, RL78
8593The RL78 back end supports the @code{saddr} variable attribute. This
8594specifies placement of the corresponding variable in the SADDR area,
8595which can be accessed more efficiently than the default memory region.
8596
8597@node V850 Variable Attributes
8598@subsection V850 Variable Attributes
8599
8600These variable attributes are supported by the V850 back end:
8601
8602@table @code
8603
d77de738 8604@cindex @code{sda} variable attribute, V850
f33d7a88 8605@item sda
d77de738
ML
8606Use this attribute to explicitly place a variable in the small data area,
8607which can hold up to 64 kilobytes.
8608
d77de738 8609@cindex @code{tda} variable attribute, V850
f33d7a88 8610@item tda
d77de738
ML
8611Use this attribute to explicitly place a variable in the tiny data area,
8612which can hold up to 256 bytes in total.
8613
d77de738 8614@cindex @code{zda} variable attribute, V850
f33d7a88 8615@item zda
d77de738
ML
8616Use this attribute to explicitly place a variable in the first 32 kilobytes
8617of memory.
8618@end table
8619
8620@node x86 Variable Attributes
8621@subsection x86 Variable Attributes
8622
8623Two attributes are currently defined for x86 configurations:
8624@code{ms_struct} and @code{gcc_struct}.
8625
8626@table @code
d77de738
ML
8627@cindex @code{ms_struct} variable attribute, x86
8628@cindex @code{gcc_struct} variable attribute, x86
f33d7a88
AA
8629@item ms_struct
8630@itemx gcc_struct
d77de738
ML
8631
8632If @code{packed} is used on a structure, or if bit-fields are used,
8633it may be that the Microsoft ABI lays out the structure differently
8634than the way GCC normally does. Particularly when moving packed
8635data between functions compiled with GCC and the native Microsoft compiler
8636(either via function call or as data in a file), it may be necessary to access
8637either format.
8638
8639The @code{ms_struct} and @code{gcc_struct} attributes correspond
8640to the @option{-mms-bitfields} and @option{-mno-ms-bitfields}
8641command-line options, respectively;
8642see @ref{x86 Options}, for details of how structure layout is affected.
8643@xref{x86 Type Attributes}, for information about the corresponding
8644attributes on types.
8645
8646@end table
8647
8648@node Xstormy16 Variable Attributes
8649@subsection Xstormy16 Variable Attributes
8650
8651One attribute is currently defined for xstormy16 configurations:
8652@code{below100}.
8653
8654@table @code
d77de738 8655@cindex @code{below100} variable attribute, Xstormy16
f33d7a88 8656@item below100
d77de738
ML
8657
8658If a variable has the @code{below100} attribute (@code{BELOW100} is
8659allowed also), GCC places the variable in the first 0x100 bytes of
8660memory and use special opcodes to access it. Such variables are
8661placed in either the @code{.bss_below100} section or the
8662@code{.data_below100} section.
8663
8664@end table
8665
8666@node Type Attributes
8667@section Specifying Attributes of Types
8668@cindex attribute of types
8669@cindex type attributes
8670
837a12a2 8671You can use attributes to specify various special
d77de738
ML
8672properties of types. Some type attributes apply only to structure and
8673union types, and in C++, also class types, while others can apply to
8674any type defined via a @code{typedef} declaration. Unless otherwise
8675specified, the same restrictions and effects apply to attributes regardless
8676of whether a type is a trivial structure or a C++ class with user-defined
8677constructors, destructors, or a copy assignment.
8678
8679Other attributes are defined for functions (@pxref{Function Attributes}),
8680labels (@pxref{Label Attributes}), enumerators (@pxref{Enumerator
8681Attributes}), statements (@pxref{Statement Attributes}), and for variables
8682(@pxref{Variable Attributes}).
8683
837a12a2
SL
8684GCC provides two different ways to specify attributes: the traditional
8685GNU syntax using @samp{__attribute__ ((...))} annotations, and the
8686newer standard C and C++ syntax using @samp{[[...]]} with the
8687@samp{gnu::} prefix on attribute names. Note that the exact rules for
8688placement of attributes in your source code are different depending on
8689which syntax you use. @xref{Attribute Syntax}, for details.
d77de738
ML
8690
8691You may specify type attributes in an enum, struct or union type
8692declaration or definition by placing them immediately after the
8693@code{struct}, @code{union} or @code{enum} keyword. You can also place
8694them just past the closing curly brace of the definition, but this is less
8695preferred because logically the type should be fully defined at
837a12a2
SL
8696the closing brace. You can also include type attributes in a
8697@code{typedef} declaration.
d77de738
ML
8698
8699@menu
8700* Common Type Attributes::
8701* ARC Type Attributes::
8702* ARM Type Attributes::
8703* BPF Type Attributes::
d77de738
ML
8704* PowerPC Type Attributes::
8705* x86 Type Attributes::
8706@end menu
8707
8708@node Common Type Attributes
8709@subsection Common Type Attributes
8710
8711The following type attributes are supported on most targets.
8712
8713@table @code
8714@cindex @code{aligned} type attribute
8715@item aligned
8716@itemx aligned (@var{alignment})
8717The @code{aligned} attribute specifies a minimum alignment (in bytes) for
8718variables of the specified type. When specified, @var{alignment} must be
8719a power of 2. Specifying no @var{alignment} argument implies the maximum
8720alignment for the target, which is often, but by no means always, 8 or 16
8721bytes. For example, the declarations:
8722
8723@smallexample
8724struct __attribute__ ((aligned (8))) S @{ short f[3]; @};
8725typedef int more_aligned_int __attribute__ ((aligned (8)));
8726@end smallexample
8727
8728@noindent
8729force the compiler to ensure (as far as it can) that each variable whose
8730type is @code{struct S} or @code{more_aligned_int} is allocated and
8731aligned @emph{at least} on a 8-byte boundary. On a SPARC, having all
8732variables of type @code{struct S} aligned to 8-byte boundaries allows
8733the compiler to use the @code{ldd} and @code{std} (doubleword load and
8734store) instructions when copying one variable of type @code{struct S} to
8735another, thus improving run-time efficiency.
8736
8737Note that the alignment of any given @code{struct} or @code{union} type
8738is required by the ISO C standard to be at least a perfect multiple of
8739the lowest common multiple of the alignments of all of the members of
8740the @code{struct} or @code{union} in question. This means that you @emph{can}
8741effectively adjust the alignment of a @code{struct} or @code{union}
8742type by attaching an @code{aligned} attribute to any one of the members
8743of such a type, but the notation illustrated in the example above is a
8744more obvious, intuitive, and readable way to request the compiler to
8745adjust the alignment of an entire @code{struct} or @code{union} type.
8746
8747As in the preceding example, you can explicitly specify the alignment
8748(in bytes) that you wish the compiler to use for a given @code{struct}
8749or @code{union} type. Alternatively, you can leave out the alignment factor
8750and just ask the compiler to align a type to the maximum
8751useful alignment for the target machine you are compiling for. For
8752example, you could write:
8753
8754@smallexample
8755struct __attribute__ ((aligned)) S @{ short f[3]; @};
8756@end smallexample
8757
8758Whenever you leave out the alignment factor in an @code{aligned}
8759attribute specification, the compiler automatically sets the alignment
8760for the type to the largest alignment that is ever used for any data
8761type on the target machine you are compiling for. Doing this can often
8762make copy operations more efficient, because the compiler can use
8763whatever instructions copy the biggest chunks of memory when performing
8764copies to or from the variables that have types that you have aligned
8765this way.
8766
8767In the example above, if the size of each @code{short} is 2 bytes, then
8768the size of the entire @code{struct S} type is 6 bytes. The smallest
8769power of two that is greater than or equal to that is 8, so the
8770compiler sets the alignment for the entire @code{struct S} type to 8
8771bytes.
8772
8773Note that although you can ask the compiler to select a time-efficient
8774alignment for a given type and then declare only individual stand-alone
8775objects of that type, the compiler's ability to select a time-efficient
8776alignment is primarily useful only when you plan to create arrays of
8777variables having the relevant (efficiently aligned) type. If you
8778declare or use arrays of variables of an efficiently-aligned type, then
8779it is likely that your program also does pointer arithmetic (or
8780subscripting, which amounts to the same thing) on pointers to the
8781relevant type, and the code that the compiler generates for these
8782pointer arithmetic operations is often more efficient for
8783efficiently-aligned types than for other types.
8784
8785Note that the effectiveness of @code{aligned} attributes may be limited
8786by inherent limitations in your linker. On many systems, the linker is
8787only able to arrange for variables to be aligned up to a certain maximum
8788alignment. (For some linkers, the maximum supported alignment may
8789be very very small.) If your linker is only able to align variables
8790up to a maximum of 8-byte alignment, then specifying @code{aligned (16)}
8791in an @code{__attribute__} still only provides you with 8-byte
8792alignment. See your linker documentation for further information.
8793
8794When used on a struct, or struct member, the @code{aligned} attribute can
8795only increase the alignment; in order to decrease it, the @code{packed}
8796attribute must be specified as well. When used as part of a typedef, the
8797@code{aligned} attribute can both increase and decrease alignment, and
8798specifying the @code{packed} attribute generates a warning.
8799
8800@cindex @code{warn_if_not_aligned} type attribute
8801@item warn_if_not_aligned (@var{alignment})
8802This attribute specifies a threshold for the structure field, measured
8803in bytes. If the structure field is aligned below the threshold, a
8804warning will be issued. For example, the declaration:
8805
8806@smallexample
8807typedef unsigned long long __u64
8808 __attribute__((aligned (4), warn_if_not_aligned (8)));
8809
8810struct foo
8811@{
8812 int i1;
8813 int i2;
8814 __u64 x;
8815@};
8816@end smallexample
8817
8818@noindent
8819causes the compiler to issue an warning on @code{struct foo}, like
8820@samp{warning: alignment 4 of 'struct foo' is less than 8}.
8821It is used to define @code{struct foo} in such a way that
8822@code{struct foo} has the same layout and the structure field @code{x}
8823has the same alignment when @code{__u64} is aligned at either 4 or
88248 bytes. Align @code{struct foo} to 8 bytes:
8825
8826@smallexample
8827struct __attribute__ ((aligned (8))) foo
8828@{
8829 int i1;
8830 int i2;
8831 __u64 x;
8832@};
8833@end smallexample
8834
8835@noindent
8836silences the warning. The compiler also issues a warning, like
8837@samp{warning: 'x' offset 12 in 'struct foo' isn't aligned to 8},
8838when the structure field has the misaligned offset:
8839
8840@smallexample
8841struct __attribute__ ((aligned (8))) foo
8842@{
8843 int i1;
8844 int i2;
8845 int i3;
8846 __u64 x;
8847@};
8848@end smallexample
8849
8850This warning can be disabled by @option{-Wno-if-not-aligned}.
8851
f33d7a88 8852@cindex @code{alloc_size} type attribute
d77de738
ML
8853@item alloc_size (@var{position})
8854@itemx alloc_size (@var{position-1}, @var{position-2})
d77de738
ML
8855The @code{alloc_size} type attribute may be applied to the definition
8856of a type of a function that returns a pointer and takes at least one
8857argument of an integer type. It indicates that the returned pointer
8858points to an object whose size is given by the function argument at
8859@var{position-1}, or by the product of the arguments at @var{position-1}
8860and @var{position-2}. Meaningful sizes are positive values less than
8861@code{PTRDIFF_MAX}. Other sizes are disagnosed when detected. GCC uses
8862this information to improve the results of @code{__builtin_object_size}.
8863
8864For instance, the following declarations
8865
8866@smallexample
8867typedef __attribute__ ((alloc_size (1, 2))) void*
8868 calloc_type (size_t, size_t);
8869typedef __attribute__ ((alloc_size (1))) void*
8870 malloc_type (size_t);
8871@end smallexample
8872
8873@noindent
8874specify that @code{calloc_type} is a type of a function that, like
8875the standard C function @code{calloc}, returns an object whose size
8876is given by the product of arguments 1 and 2, and that
8877@code{malloc_type}, like the standard C function @code{malloc},
8878returns an object whose size is given by argument 1 to the function.
8879
f33d7a88 8880@cindex @code{copy} type attribute
d77de738
ML
8881@item copy
8882@itemx copy (@var{expression})
d77de738
ML
8883The @code{copy} attribute applies the set of attributes with which
8884the type of the @var{expression} has been declared to the declaration
8885of the type to which the attribute is applied. The attribute is
8886designed for libraries that define aliases that are expected to
8887specify the same set of attributes as the aliased symbols.
8888The @code{copy} attribute can be used with types, variables, or
8889functions. However, the kind of symbol to which the attribute is
8890applied (either varible or function) must match the kind of symbol
8891to which the argument refers.
8892The @code{copy} attribute copies only syntactic and semantic attributes
8893but not attributes that affect a symbol's linkage or visibility such as
8894@code{alias}, @code{visibility}, or @code{weak}. The @code{deprecated}
8895attribute is also not copied. @xref{Common Function Attributes}.
8896@xref{Common Variable Attributes}.
8897
8898For example, suppose @code{struct A} below is defined in some third
8899party library header to have the alignment requirement @code{N} and
8900to force a warning whenever a variable of the type is not so aligned
8901due to attribute @code{packed}. Specifying the @code{copy} attribute
8902on the definition on the unrelated @code{struct B} has the effect of
8903copying all relevant attributes from the type referenced by the pointer
8904expression to @code{struct B}.
8905
8906@smallexample
8907struct __attribute__ ((aligned (N), warn_if_not_aligned (N)))
8908A @{ /* @r{@dots{}} */ @};
8909struct __attribute__ ((copy ( (struct A *)0)) B @{ /* @r{@dots{}} */ @};
8910@end smallexample
8911
f33d7a88 8912@cindex @code{deprecated} type attribute
d77de738
ML
8913@item deprecated
8914@itemx deprecated (@var{msg})
d77de738
ML
8915The @code{deprecated} attribute results in a warning if the type
8916is used anywhere in the source file. This is useful when identifying
8917types that are expected to be removed in a future version of a program.
8918If possible, the warning also includes the location of the declaration
8919of the deprecated type, to enable users to easily find further
8920information about why the type is deprecated, or what they should do
8921instead. Note that the warnings only occur for uses and then only
8922if the type is being applied to an identifier that itself is not being
8923declared as deprecated.
8924
8925@smallexample
8926typedef int T1 __attribute__ ((deprecated));
8927T1 x;
8928typedef T1 T2;
8929T2 y;
8930typedef T1 T3 __attribute__ ((deprecated));
8931T3 z __attribute__ ((deprecated));
8932@end smallexample
8933
8934@noindent
8935results in a warning on line 2 and 3 but not lines 4, 5, or 6. No
8936warning is issued for line 4 because T2 is not explicitly
8937deprecated. Line 5 has no warning because T3 is explicitly
8938deprecated. Similarly for line 6. The optional @var{msg}
8939argument, which must be a string, is printed in the warning if
8940present. Control characters in the string will be replaced with
8941escape sequences, and if the @option{-fmessage-length} option is set
8942to 0 (its default value) then any newline characters will be ignored.
8943
8944The @code{deprecated} attribute can also be used for functions and
8945variables (@pxref{Function Attributes}, @pxref{Variable Attributes}.)
8946
8947The message attached to the attribute is affected by the setting of
8948the @option{-fmessage-length} option.
8949
f33d7a88 8950@cindex @code{unavailable} type attribute
d77de738
ML
8951@item unavailable
8952@itemx unavailable (@var{msg})
d77de738
ML
8953The @code{unavailable} attribute behaves in the same manner as the
8954@code{deprecated} one, but emits an error rather than a warning. It is
8955used to indicate that a (perhaps previously @code{deprecated}) type is
8956no longer usable.
8957
8958The @code{unavailable} attribute can also be used for functions and
8959variables (@pxref{Function Attributes}, @pxref{Variable Attributes}.)
8960
d77de738 8961@cindex @code{designated_init} type attribute
f33d7a88 8962@item designated_init
d77de738
ML
8963This attribute may only be applied to structure types. It indicates
8964that any initialization of an object of this type must use designated
8965initializers rather than positional initializers. The intent of this
8966attribute is to allow the programmer to indicate that a structure's
8967layout may change, and that therefore relying on positional
8968initialization will result in future breakage.
8969
8970GCC emits warnings based on this attribute by default; use
8971@option{-Wno-designated-init} to suppress them.
8972
862867ea
AO
8973@cindex @code{hardbool} type attribute
8974@item hardbool
8975@itemx hardbool (@var{false_value})
8976@itemx hardbool (@var{false_value}, @var{true_value})
8977This attribute may only be applied to integral types in C, to introduce
8978hardened boolean types. It turns the integral type into a boolean-like
8979type with the same size and precision, that uses the specified values as
8980representations for @code{false} and @code{true}. Underneath, it is
8981actually an enumerate type, but its observable behavior is like that of
8982@code{_Bool}, except for the strict internal representations, verified
8983by runtime checks.
8984
8985If @var{true_value} is omitted, the bitwise negation of
8986@var{false_value} is used. If @var{false_value} is omitted, zero is
8987used. The named representation values must be different when converted
8988to the original integral type. Narrower bitfields are rejected if the
8989representations become indistinguishable.
8990
8991Values of such types automatically decay to @code{_Bool}, at which
8992point, the selected representation values are mapped to the
8993corresponding @code{_Bool} values. When the represented value is not
8994determined, at compile time, to be either @var{false_value} or
8995@var{true_value}, runtime verification calls @code{__builtin_trap} if it
8996is neither. This is what makes them hardened boolean types.
8997
8998When converting scalar types to such hardened boolean types, implicitly
8999or explicitly, behavior corresponds to a conversion to @code{_Bool},
9000followed by a mapping from @code{false} and @code{true} to
9001@var{false_value} and @var{true_value}, respectively.
9002
9003@smallexample
9004typedef char __attribute__ ((__hardbool__ (0x5a))) hbool;
9005hbool first = 0; /* False, stored as (char)0x5a. */
9006hbool second = !first; /* True, stored as ~(char)0x5a. */
9007
9008static hbool zeroinit; /* False, stored as (char)0x5a. */
9009auto hbool uninit; /* Undefined, may trap. */
9010@end smallexample
9011
9012When zero-initializing a variable or field of hardened boolean type
9013(presumably held in static storage) the implied zero initializer gets
9014converted to @code{_Bool}, and then to the hardened boolean type, so
9015that the initial value is the hardened representation for @code{false}.
9016Using that value is well defined. This is @emph{not} the case when
9017variables and fields of such types are uninitialized (presumably held in
9018automatic or dynamic storage): their values are indeterminate, and using
9019them invokes undefined behavior. Using them may trap or not, depending
9020on the bits held in the storage (re)used for the variable, if any, and
9021on optimizations the compiler may perform on the grounds that using
9022uninitialized values invokes undefined behavior.
9023
9024Users of @option{-ftrivial-auto-var-init} should be aware that the bit
9025patterns used as initializers are @emph{not} converted to
9026@code{hardbool} types, so using a @code{hardbool} variable that is
9027implicitly initialized by the @option{-ftrivial-auto-var-init} may trap
9028if the representations values chosen for @code{false} and @code{true} do
9029not match the initializer.
9030
9031Since this is a language extension only available in C, interoperation
9032with other languages may pose difficulties. It should interoperate with
9033Ada Booleans defined with the same size and equivalent representation
9034clauses, and with enumerations or other languages' integral types that
9035correspond to C's chosen integral type.
9036
9037
d77de738 9038@cindex @code{may_alias} type attribute
f33d7a88 9039@item may_alias
d77de738
ML
9040Accesses through pointers to types with this attribute are not subject
9041to type-based alias analysis, but are instead assumed to be able to alias
9042any other type of objects.
9043In the context of section 6.5 paragraph 7 of the C99 standard,
9044an lvalue expression
9045dereferencing such a pointer is treated like having a character type.
9046See @option{-fstrict-aliasing} for more information on aliasing issues.
9047This extension exists to support some vector APIs, in which pointers to
9048one vector type are permitted to alias pointers to a different vector type.
9049
9050Note that an object of a type with this attribute does not have any
9051special semantics.
9052
9053Example of use:
9054
9055@smallexample
9056typedef short __attribute__ ((__may_alias__)) short_a;
9057
9058int
9059main (void)
9060@{
9061 int a = 0x12345678;
9062 short_a *b = (short_a *) &a;
9063
9064 b[1] = 0;
9065
9066 if (a == 0x12345678)
9067 abort();
9068
9069 exit(0);
9070@}
9071@end smallexample
9072
9073@noindent
9074If you replaced @code{short_a} with @code{short} in the variable
9075declaration, the above program would abort when compiled with
9076@option{-fstrict-aliasing}, which is on by default at @option{-O2} or
9077above.
9078
d77de738 9079@cindex @code{mode} type attribute
f33d7a88 9080@item mode (@var{mode})
d77de738
ML
9081This attribute specifies the data type for the declaration---whichever
9082type corresponds to the mode @var{mode}. This in effect lets you
9083request an integer or floating-point type according to its width.
9084
9085@xref{Machine Modes,,, gccint, GNU Compiler Collection (GCC) Internals},
9086for a list of the possible keywords for @var{mode}.
9087You may also specify a mode of @code{byte} or @code{__byte__} to
9088indicate the mode corresponding to a one-byte integer, @code{word} or
9089@code{__word__} for the mode of a one-word integer, and @code{pointer}
9090or @code{__pointer__} for the mode used to represent pointers.
9091
d77de738 9092@cindex @code{packed} type attribute
f33d7a88 9093@item packed
d77de738
ML
9094This attribute, attached to a @code{struct}, @code{union}, or C++ @code{class}
9095type definition, specifies that each of its members (other than zero-width
9096bit-fields) is placed to minimize the memory required. This is equivalent
9097to specifying the @code{packed} attribute on each of the members.
9098
9099@opindex fshort-enums
9100When attached to an @code{enum} definition, the @code{packed} attribute
9101indicates that the smallest integral type should be used.
9102Specifying the @option{-fshort-enums} flag on the command line
9103is equivalent to specifying the @code{packed}
9104attribute on all @code{enum} definitions.
9105
9106In the following example @code{struct my_packed_struct}'s members are
9107packed closely together, but the internal layout of its @code{s} member
9108is not packed---to do that, @code{struct my_unpacked_struct} needs to
9109be packed too.
9110
9111@smallexample
9112struct my_unpacked_struct
9113 @{
9114 char c;
9115 int i;
9116 @};
9117
9118struct __attribute__ ((__packed__)) my_packed_struct
9119 @{
9120 char c;
9121 int i;
9122 struct my_unpacked_struct s;
9123 @};
9124@end smallexample
9125
9126You may only specify the @code{packed} attribute on the definition
9127of an @code{enum}, @code{struct}, @code{union}, or @code{class},
9128not on a @code{typedef} that does not also define the enumerated type,
9129structure, union, or class.
9130
d77de738 9131@cindex @code{scalar_storage_order} type attribute
f33d7a88 9132@item scalar_storage_order ("@var{endianness}")
d77de738
ML
9133When attached to a @code{union} or a @code{struct}, this attribute sets
9134the storage order, aka endianness, of the scalar fields of the type, as
9135well as the array fields whose component is scalar. The supported
9136endiannesses are @code{big-endian} and @code{little-endian}. The attribute
9137has no effects on fields which are themselves a @code{union}, a @code{struct}
9138or an array whose component is a @code{union} or a @code{struct}, and it is
9139possible for these fields to have a different scalar storage order than the
9140enclosing type.
9141
9142Note that neither pointer nor vector fields are considered scalar fields in
9143this context, so the attribute has no effects on these fields.
9144
9145This attribute is supported only for targets that use a uniform default
9146scalar storage order (fortunately, most of them), i.e.@: targets that store
9147the scalars either all in big-endian or all in little-endian.
9148
9149Additional restrictions are enforced for types with the reverse scalar
9150storage order with regard to the scalar storage order of the target:
9151
9152@itemize
9153@item Taking the address of a scalar field of a @code{union} or a
9154@code{struct} with reverse scalar storage order is not permitted and yields
9155an error.
9156@item Taking the address of an array field, whose component is scalar, of
9157a @code{union} or a @code{struct} with reverse scalar storage order is
9158permitted but yields a warning, unless @option{-Wno-scalar-storage-order}
9159is specified.
9160@item Taking the address of a @code{union} or a @code{struct} with reverse
9161scalar storage order is permitted.
9162@end itemize
9163
9164These restrictions exist because the storage order attribute is lost when
9165the address of a scalar or the address of an array with scalar component is
9166taken, so storing indirectly through this address generally does not work.
9167The second case is nevertheless allowed to be able to perform a block copy
9168from or to the array.
9169
9170Moreover, the use of type punning or aliasing to toggle the storage order
9171is not supported; that is to say, if a given scalar object can be accessed
9172through distinct types that assign a different storage order to it, then the
9173behavior is undefined.
9174
d77de738 9175@cindex @code{transparent_union} type attribute
f33d7a88 9176@item transparent_union
d77de738
ML
9177
9178This attribute, attached to a @code{union} type definition, indicates
9179that any function parameter having that union type causes calls to that
9180function to be treated in a special way.
9181
9182First, the argument corresponding to a transparent union type can be of
9183any type in the union; no cast is required. Also, if the union contains
9184a pointer type, the corresponding argument can be a null pointer
9185constant or a void pointer expression; and if the union contains a void
9186pointer type, the corresponding argument can be any pointer expression.
9187If the union member type is a pointer, qualifiers like @code{const} on
9188the referenced type must be respected, just as with normal pointer
9189conversions.
9190
9191Second, the argument is passed to the function using the calling
9192conventions of the first member of the transparent union, not the calling
9193conventions of the union itself. All members of the union must have the
9194same machine representation; this is necessary for this argument passing
9195to work properly.
9196
9197Transparent unions are designed for library functions that have multiple
9198interfaces for compatibility reasons. For example, suppose the
9199@code{wait} function must accept either a value of type @code{int *} to
9200comply with POSIX, or a value of type @code{union wait *} to comply with
9201the 4.1BSD interface. If @code{wait}'s parameter were @code{void *},
9202@code{wait} would accept both kinds of arguments, but it would also
9203accept any other pointer type and this would make argument type checking
9204less useful. Instead, @code{<sys/wait.h>} might define the interface
9205as follows:
9206
9207@smallexample
9208typedef union __attribute__ ((__transparent_union__))
9209 @{
9210 int *__ip;
9211 union wait *__up;
9212 @} wait_status_ptr_t;
9213
9214pid_t wait (wait_status_ptr_t);
9215@end smallexample
9216
9217@noindent
9218This interface allows either @code{int *} or @code{union wait *}
9219arguments to be passed, using the @code{int *} calling convention.
9220The program can call @code{wait} with arguments of either type:
9221
9222@smallexample
9223int w1 () @{ int w; return wait (&w); @}
9224int w2 () @{ union wait w; return wait (&w); @}
9225@end smallexample
9226
9227@noindent
9228With this interface, @code{wait}'s implementation might look like this:
9229
9230@smallexample
9231pid_t wait (wait_status_ptr_t p)
9232@{
9233 return waitpid (-1, p.__ip, 0);
9234@}
9235@end smallexample
9236
f0a90c7d
AO
9237@cindex @code{strub} type attribute
9238@item strub
9239This attribute defines stack-scrubbing properties of functions and
9240variables, so that functions that access sensitive data can have their
9241stack frames zeroed-out upon returning or propagating exceptions. This
9242may be enabled explicitly, by selecting certain @code{strub} modes for
9243specific functions, or implicitly, by means of @code{strub} variables.
9244
9245Being a type attribute, it attaches to types, even when specified in
9246function and variable declarations. When applied to function types, it
9247takes an optional string argument. When applied to a
9248pointer-to-function type, if the optional argument is given, it gets
9249propagated to the function type.
9250
9251@smallexample
9252/* A strub variable. */
9253int __attribute__ ((strub)) var;
9254/* A strub variable that happens to be a pointer. */
9255__attribute__ ((strub)) int *strub_ptr_to_int;
9256/* A pointer type that may point to a strub variable. */
9257typedef int __attribute__ ((strub)) *ptr_to_strub_int_type;
9258
9259/* A declaration of a strub function. */
9260extern int __attribute__ ((strub)) foo (void);
9261/* A pointer to that strub function. */
9262int __attribute__ ((strub ("at-calls"))) (*ptr_to_strub_fn)(void) = foo;
9263@end smallexample
9264
9265A function associated with @code{at-calls} @code{strub} mode
9266(@code{strub("at-calls")}, or just @code{strub}) undergoes interface
9267changes. Its callers are adjusted to match the changes, and to scrub
9268(overwrite with zeros) the stack space used by the called function after
9269it returns. The interface change makes the function type incompatible
9270with an unadorned but otherwise equivalent type, so @emph{every}
9271declaration and every type that may be used to call the function must be
9272associated with this strub mode.
9273
9274A function associated with @code{internal} @code{strub} mode
9275(@code{strub("internal")}) retains an unmodified, type-compatible
9276interface, but it may be turned into a wrapper that calls the wrapped
9277body using a custom interface. The wrapper then scrubs the stack space
9278used by the wrapped body. Though the wrapped body has its stack space
9279scrubbed, the wrapper does not, so arguments and return values may
9280remain unscrubbed even when such a function is called by another
9281function that enables @code{strub}. This is why, when compiling with
9282@option{-fstrub=strict}, a @code{strub} context is not allowed to call
9283@code{internal} @code{strub} functions.
9284
9285@smallexample
9286/* A declaration of an internal-strub function. */
9287extern int __attribute__ ((strub ("internal"))) bar (void);
9288
9289int __attribute__ ((strub))
9290baz (void)
9291@{
9292 /* Ok, foo was declared above as an at-calls strub function. */
9293 foo ();
9294 /* Not allowed in strict mode, otherwise allowed. */
9295 bar ();
9296@}
9297@end smallexample
9298
9299An automatically-allocated variable associated with the @code{strub}
9300attribute causes the (immediately) enclosing function to have
9301@code{strub} enabled.
9302
9303A statically-allocated variable associated with the @code{strub}
9304attribute causes functions that @emph{read} it, through its @code{strub}
9305data type, to have @code{strub} enabled. Reading data by dereferencing
9306a pointer to a @code{strub} data type has the same effect. Note: The
9307attribute does not carry over from a composite type to the types of its
9308components, so the intended effect may not be obtained with non-scalar
9309types.
9310
9311When selecting a @code{strub}-enabled mode for a function that is not
9312explicitly associated with one, because of @code{strub} variables or
9313data pointers, the function must satisfy @code{internal} mode viability
9314requirements (see below), even when @code{at-calls} mode is also viable
9315and, being more efficient, ends up selected as an optimization.
9316
9317@smallexample
9318/* zapme is implicitly strub-enabled because of strub variables.
9319 Optimization may change its strub mode, but not the requirements. */
9320static int
9321zapme (int i)
9322@{
9323 /* A local strub variable enables strub. */
9324 int __attribute__ ((strub)) lvar;
9325 /* Reading strub data through a pointer-to-strub enables strub. */
9326 lvar = * (ptr_to_strub_int_type) &i;
9327 /* Writing to a global strub variable does not enable strub. */
9328 var = lvar;
9329 /* Reading from a global strub variable enables strub. */
9330 return var;
9331@}
9332@end smallexample
9333
9334A @code{strub} context is the body (as opposed to the interface) of a
9335function that has @code{strub} enabled, be it explicitly, by
9336@code{at-calls} or @code{internal} mode, or implicitly, due to
9337@code{strub} variables or command-line options.
9338
9339A function of a type associated with the @code{disabled} @code{strub}
9340mode (@code{strub("disabled")} will not have its own stack space
9341scrubbed. Such functions @emph{cannot} be called from within
9342@code{strub} contexts.
9343
9344In order to enable a function to be called from within @code{strub}
9345contexts without having its stack space scrubbed, associate it with the
9346@code{callable} @code{strub} mode (@code{strub("callable")}).
9347
9348When a function is not assigned a @code{strub} mode, explicitly or
9349implicitly, the mode defaults to @code{callable}, except when compiling
9350with @option{-fstrub=strict}, that causes @code{strub} mode to default
9351to @code{disabled}.
9352
9353@example
9354extern int __attribute__ ((strub ("callable"))) bac (void);
9355extern int __attribute__ ((strub ("disabled"))) bad (void);
9356 /* Implicitly disabled with -fstrub=strict, otherwise callable. */
9357extern int bah (void);
9358
9359int __attribute__ ((strub))
9360bal (void)
9361@{
9362 /* Not allowed, bad is not strub-callable. */
9363 bad ();
9364 /* Ok, bac is strub-callable. */
9365 bac ();
9366 /* Not allowed with -fstrub=strict, otherwise allowed. */
9367 bah ();
9368@}
9369@end example
9370
9371Function types marked @code{callable} and @code{disabled} are not
9372mutually compatible types, but the underlying interfaces are compatible,
9373so it is safe to convert pointers between them, and to use such pointers
9374or alternate declarations to call them. Interfaces are also
9375interchangeable between them and @code{internal} (but not
9376@code{at-calls}!), but adding @code{internal} to a pointer type will not
9377cause the pointed-to function to perform stack scrubbing.
9378
9379@example
9380void __attribute__ ((strub))
9381bap (void)
9382@{
9383 /* Assign a callable function to pointer-to-disabled.
9384 Flagged as not quite compatible with -Wpedantic. */
9385 int __attribute__ ((strub ("disabled"))) (*d_p) (void) = bac;
9386 /* Not allowed: calls disabled type in a strub context. */
9387 d_p ();
9388
9389 /* Assign a disabled function to pointer-to-callable.
9390 Flagged as not quite compatible with -Wpedantic. */
9391 int __attribute__ ((strub ("callable"))) (*c_p) (void) = bad;
9392 /* Ok, safe. */
9393 c_p ();
9394
9395 /* Assign an internal function to pointer-to-callable.
9396 Flagged as not quite compatible with -Wpedantic. */
9397 c_p = bar;
9398 /* Ok, safe. */
9399 c_p ();
9400
9401 /* Assign an at-calls function to pointer-to-callable.
9402 Flaggged as incompatible. */
9403 c_p = bal;
9404 /* The call through an interface-incompatible type will not use the
9405 modified interface expected by the at-calls function, so it is
9406 likely to misbehave at runtime. */
9407 c_p ();
9408@}
9409@end example
9410
9411@code{Strub} contexts are never inlined into non-@code{strub} contexts.
9412When an @code{internal}-strub function is split up, the wrapper can
9413often be inlined, but the wrapped body @emph{never} is. A function
9414marked as @code{always_inline}, even if explicitly assigned
9415@code{internal} strub mode, will not undergo wrapping, so its body gets
9416inlined as required.
9417
9418@example
9419inline int __attribute__ ((strub ("at-calls")))
9420inl_atc (void)
9421@{
9422 /* This body may get inlined into strub contexts. */
9423@}
9424
9425inline int __attribute__ ((strub ("internal")))
9426inl_int (void)
9427@{
9428 /* This body NEVER gets inlined, though its wrapper may. */
9429@}
9430
9431inline int __attribute__ ((strub ("internal"), always_inline))
9432inl_int_ali (void)
9433@{
9434 /* No internal wrapper, so this body ALWAYS gets inlined,
9435 but it cannot be called from non-strub contexts. */
9436@}
9437
9438void __attribute__ ((strub ("disabled")))
9439bat (void)
9440@{
9441 /* Not allowed, cannot inline into a non-strub context. */
9442 inl_int_ali ();
9443@}
9444@end example
9445
9446@cindex strub eligibility and viability
9447Some @option{-fstrub=*} command line options enable @code{strub} modes
9448implicitly where viable. A @code{strub} mode is only viable for a
9449function if the function is eligible for that mode, and if other
9450conditions, detailed below, are satisfied. If it's not eligible for a
9451mode, attempts to explicitly associate it with that mode are rejected
9452with an error message. If it is eligible, that mode may be assigned
9453explicitly through this attribute, but implicit assignment through
9454command-line options may involve additional viability requirements.
9455
9456A function is ineligible for @code{at-calls} @code{strub} mode if a
9457different @code{strub} mode is explicitly requested, if attribute
9458@code{noipa} is present, or if it calls @code{__builtin_apply_args}.
9459@code{At-calls} @code{strub} mode, if not requested through the function
9460type, is only viable for an eligible function if the function is not
9461visible to other translation units, if it doesn't have its address
9462taken, and if it is never called with a function type overrider.
9463
9464@smallexample
9465/* bar is eligible for at-calls strub mode,
9466 but not viable for that mode because it is visible to other units.
9467 It is eligible and viable for internal strub mode. */
9468void bav () @{@}
9469
9470/* setp is eligible for at-calls strub mode,
9471 but not viable for that mode because its address is taken.
9472 It is eligible and viable for internal strub mode. */
9473void setp (void) @{ static void (*p)(void); = setp; @}
9474@end smallexample
9475
9476A function is ineligible for @code{internal} @code{strub} mode if a
9477different @code{strub} mode is explicitly requested, or if attribute
9478@code{noipa} is present. For an @code{always_inline} function, meeting
9479these requirements is enough to make it eligible. Any function that has
9480attribute @code{noclone}, that uses such extensions as non-local labels,
9481computed gotos, alternate variable argument passing interfaces,
9482@code{__builtin_next_arg}, or @code{__builtin_return_address}, or that
9483takes too many (about 64Ki) arguments is ineligible, unless it is
9484@code{always_inline}. For @code{internal} @code{strub} mode, all
9485eligible functions are viable.
9486
9487@smallexample
9488/* flop is not eligible, thus not viable, for at-calls strub mode.
9489 Likewise for internal strub mode. */
9490__attribute__ ((noipa)) void flop (void) @{@}
9491
9492/* flip is eligible and viable for at-calls strub mode.
9493 It would be ineligible for internal strub mode, because of noclone,
9494 if it weren't for always_inline. With always_inline, noclone is not
9495 an obstacle, so it is also eligible and viable for internal strub mode. */
9496inline __attribute__ ((noclone, always_inline)) void flip (void) @{@}
9497@end smallexample
9498
d77de738 9499@cindex @code{unused} type attribute
f33d7a88 9500@item unused
d77de738
ML
9501When attached to a type (including a @code{union} or a @code{struct}),
9502this attribute means that variables of that type are meant to appear
9503possibly unused. GCC does not produce a warning for any variables of
9504that type, even if the variable appears to do nothing. This is often
9505the case with lock or thread classes, which are usually defined and then
9506not referenced, but contain constructors and destructors that have
9507nontrivial bookkeeping functions.
9508
d77de738 9509@cindex @code{vector_size} type attribute
f33d7a88 9510@item vector_size (@var{bytes})
d77de738
ML
9511This attribute specifies the vector size for the type, measured in bytes.
9512The type to which it applies is known as the @dfn{base type}. The @var{bytes}
9513argument must be a positive power-of-two multiple of the base type size. For
9514example, the following declarations:
9515
9516@smallexample
9517typedef __attribute__ ((vector_size (32))) int int_vec32_t ;
9518typedef __attribute__ ((vector_size (32))) int* int_vec32_ptr_t;
9519typedef __attribute__ ((vector_size (32))) int int_vec32_arr3_t[3];
9520@end smallexample
9521
9522@noindent
9523define @code{int_vec32_t} to be a 32-byte vector type composed of @code{int}
9524sized units. With @code{int} having a size of 4 bytes, the type defines
9525a vector of eight units, four bytes each. The mode of variables of type
9526@code{int_vec32_t} is @code{V8SI}. @code{int_vec32_ptr_t} is then defined
9527to be a pointer to such a vector type, and @code{int_vec32_arr3_t} to be
9528an array of three such vectors. @xref{Vector Extensions}, for details of
9529manipulating objects of vector types.
9530
9531This attribute is only applicable to integral and floating scalar types.
9532In function declarations the attribute applies to the function return
9533type.
9534
9535For example, the following:
9536@smallexample
9537__attribute__ ((vector_size (16))) float get_flt_vec16 (void);
9538@end smallexample
9539declares @code{get_flt_vec16} to be a function returning a 16-byte vector
9540with the base type @code{float}.
9541
d77de738 9542@cindex @code{visibility} type attribute
f33d7a88 9543@item visibility
d77de738
ML
9544In C++, attribute visibility (@pxref{Function Attributes}) can also be
9545applied to class, struct, union and enum types. Unlike other type
9546attributes, the attribute must appear between the initial keyword and
9547the name of the type; it cannot appear after the body of the type.
9548
9549Note that the type visibility is applied to vague linkage entities
9550associated with the class (vtable, typeinfo node, etc.). In
9551particular, if a class is thrown as an exception in one shared object
9552and caught in another, the class must have default visibility.
9553Otherwise the two shared objects are unable to use the same
9554typeinfo node and exception handling will break.
9555
d77de738 9556@cindex @code{objc_root_class} type attribute
f33d7a88 9557@item objc_root_class @r{(Objective-C and Objective-C++ only)}
d77de738
ML
9558This attribute marks a class as being a root class, and thus allows
9559the compiler to elide any warnings about a missing superclass and to
9560make additional checks for mandatory methods as needed.
9561
9562@end table
9563
9564To specify multiple attributes, separate them by commas within the
9565double parentheses: for example, @samp{__attribute__ ((aligned (16),
9566packed))}.
9567
9568@node ARC Type Attributes
9569@subsection ARC Type Attributes
9570
9571@cindex @code{uncached} type attribute, ARC
9572Declaring objects with @code{uncached} allows you to exclude
9573data-cache participation in load and store operations on those objects
9574without involving the additional semantic implications of
9575@code{volatile}. The @code{.di} instruction suffix is used for all
9576loads and stores of data declared @code{uncached}.
9577
9578@node ARM Type Attributes
9579@subsection ARM Type Attributes
9580
9581@cindex @code{notshared} type attribute, ARM
9582On those ARM targets that support @code{dllimport} (such as Symbian
9583OS), you can use the @code{notshared} attribute to indicate that the
9584virtual table and other similar data for a class should not be
9585exported from a DLL@. For example:
9586
9587@smallexample
9588class __declspec(notshared) C @{
9589public:
9590 __declspec(dllimport) C();
9591 virtual void f();
9592@}
9593
9594__declspec(dllexport)
9595C::C() @{@}
9596@end smallexample
9597
9598@noindent
9599In this code, @code{C::C} is exported from the current DLL, but the
9600virtual table for @code{C} is not exported. (You can use
9601@code{__attribute__} instead of @code{__declspec} if you prefer, but
9602most Symbian OS code uses @code{__declspec}.)
9603
9604@node BPF Type Attributes
9605@subsection BPF Type Attributes
9606
9607@cindex @code{preserve_access_index} type attribute, BPF
9608BPF Compile Once - Run Everywhere (CO-RE) support. When attached to a
9609@code{struct} or @code{union} type definition, indicates that CO-RE
9610relocation information should be generated for any access to a variable
9611of that type. The behavior is equivalent to the programmer manually
9612wrapping every such access with @code{__builtin_preserve_access_index}.
9613
9614
d77de738
ML
9615@node PowerPC Type Attributes
9616@subsection PowerPC Type Attributes
9617
9618Three attributes currently are defined for PowerPC configurations:
9619@code{altivec}, @code{ms_struct} and @code{gcc_struct}.
9620
9621@cindex @code{ms_struct} type attribute, PowerPC
9622@cindex @code{gcc_struct} type attribute, PowerPC
9623For full documentation of the @code{ms_struct} and @code{gcc_struct}
9624attributes please see the documentation in @ref{x86 Type Attributes}.
9625
9626@cindex @code{altivec} type attribute, PowerPC
9627The @code{altivec} attribute allows one to declare AltiVec vector data
9628types supported by the AltiVec Programming Interface Manual. The
9629attribute requires an argument to specify one of three vector types:
9630@code{vector__}, @code{pixel__} (always followed by unsigned short),
9631and @code{bool__} (always followed by unsigned).
9632
9633@smallexample
9634__attribute__((altivec(vector__)))
9635__attribute__((altivec(pixel__))) unsigned short
9636__attribute__((altivec(bool__))) unsigned
9637@end smallexample
9638
9639These attributes mainly are intended to support the @code{__vector},
9640@code{__pixel}, and @code{__bool} AltiVec keywords.
9641
9642@node x86 Type Attributes
9643@subsection x86 Type Attributes
9644
9645Two attributes are currently defined for x86 configurations:
9646@code{ms_struct} and @code{gcc_struct}.
9647
9648@table @code
9649
d77de738
ML
9650@cindex @code{ms_struct} type attribute, x86
9651@cindex @code{gcc_struct} type attribute, x86
f33d7a88
AA
9652@item ms_struct
9653@itemx gcc_struct
d77de738
ML
9654
9655If @code{packed} is used on a structure, or if bit-fields are used
9656it may be that the Microsoft ABI packs them differently
9657than GCC normally packs them. Particularly when moving packed
9658data between functions compiled with GCC and the native Microsoft compiler
9659(either via function call or as data in a file), it may be necessary to access
9660either format.
9661
9662The @code{ms_struct} and @code{gcc_struct} attributes correspond
9663to the @option{-mms-bitfields} and @option{-mno-ms-bitfields}
9664command-line options, respectively;
9665see @ref{x86 Options}, for details of how structure layout is affected.
9666@xref{x86 Variable Attributes}, for information about the corresponding
9667attributes on variables.
9668
9669@end table
9670
9671@node Label Attributes
9672@section Label Attributes
9673@cindex Label Attributes
9674
9675GCC allows attributes to be set on C labels. @xref{Attribute Syntax}, for
9676details of the exact syntax for using attributes. Other attributes are
9677available for functions (@pxref{Function Attributes}), variables
9678(@pxref{Variable Attributes}), enumerators (@pxref{Enumerator Attributes}),
9679statements (@pxref{Statement Attributes}), and for types
9680(@pxref{Type Attributes}). A label attribute followed
9681by a declaration appertains to the label and not the declaration.
9682
9683This example uses the @code{cold} label attribute to indicate the
9684@code{ErrorHandling} branch is unlikely to be taken and that the
9685@code{ErrorHandling} label is unused:
9686
9687@smallexample
9688
9689 asm goto ("some asm" : : : : NoError);
9690
9691/* This branch (the fall-through from the asm) is less commonly used */
9692ErrorHandling:
9693 __attribute__((cold, unused)); /* Semi-colon is required here */
9694 printf("error\n");
9695 return 0;
9696
9697NoError:
9698 printf("no error\n");
9699 return 1;
9700@end smallexample
9701
9702@table @code
d77de738 9703@cindex @code{unused} label attribute
f33d7a88 9704@item unused
d77de738
ML
9705This feature is intended for program-generated code that may contain
9706unused labels, but which is compiled with @option{-Wall}. It is
9707not normally appropriate to use in it human-written code, though it
9708could be useful in cases where the code that jumps to the label is
9709contained within an @code{#ifdef} conditional.
9710
d77de738 9711@cindex @code{hot} label attribute
f33d7a88 9712@item hot
d77de738
ML
9713The @code{hot} attribute on a label is used to inform the compiler that
9714the path following the label is more likely than paths that are not so
9715annotated. This attribute is used in cases where @code{__builtin_expect}
9716cannot be used, for instance with computed goto or @code{asm goto}.
9717
d77de738 9718@cindex @code{cold} label attribute
f33d7a88 9719@item cold
d77de738
ML
9720The @code{cold} attribute on labels is used to inform the compiler that
9721the path following the label is unlikely to be executed. This attribute
9722is used in cases where @code{__builtin_expect} cannot be used, for instance
9723with computed goto or @code{asm goto}.
9724
9725@end table
9726
9727@node Enumerator Attributes
9728@section Enumerator Attributes
9729@cindex Enumerator Attributes
9730
9731GCC allows attributes to be set on enumerators. @xref{Attribute Syntax}, for
9732details of the exact syntax for using attributes. Other attributes are
9733available for functions (@pxref{Function Attributes}), variables
9734(@pxref{Variable Attributes}), labels (@pxref{Label Attributes}), statements
9735(@pxref{Statement Attributes}), and for types (@pxref{Type Attributes}).
9736
9737This example uses the @code{deprecated} enumerator attribute to indicate the
9738@code{oldval} enumerator is deprecated:
9739
9740@smallexample
9741enum E @{
9742 oldval __attribute__((deprecated)),
9743 newval
9744@};
9745
9746int
9747fn (void)
9748@{
9749 return oldval;
9750@}
9751@end smallexample
9752
9753@table @code
d77de738 9754@cindex @code{deprecated} enumerator attribute
f33d7a88 9755@item deprecated
d77de738
ML
9756The @code{deprecated} attribute results in a warning if the enumerator
9757is used anywhere in the source file. This is useful when identifying
9758enumerators that are expected to be removed in a future version of a
9759program. The warning also includes the location of the declaration
9760of the deprecated enumerator, to enable users to easily find further
9761information about why the enumerator is deprecated, or what they should
9762do instead. Note that the warnings only occurs for uses.
9763
d77de738 9764@cindex @code{unavailable} enumerator attribute
f33d7a88 9765@item unavailable
d77de738
ML
9766The @code{unavailable} attribute results in an error if the enumerator
9767is used anywhere in the source file. In other respects it behaves in the
9768same manner as the @code{deprecated} attribute.
9769
9770@end table
9771
9772@node Statement Attributes
9773@section Statement Attributes
9774@cindex Statement Attributes
9775
9776GCC allows attributes to be set on null statements. @xref{Attribute Syntax},
9777for details of the exact syntax for using attributes. Other attributes are
9778available for functions (@pxref{Function Attributes}), variables
9779(@pxref{Variable Attributes}), labels (@pxref{Label Attributes}), enumerators
9780(@pxref{Enumerator Attributes}), and for types (@pxref{Type Attributes}).
9781
9782@table @code
d77de738 9783@cindex @code{fallthrough} statement attribute
f33d7a88 9784@item fallthrough
d77de738
ML
9785The @code{fallthrough} attribute with a null statement serves as a
9786fallthrough statement. It hints to the compiler that a statement
9787that falls through to another case label, or user-defined label
9788in a switch statement is intentional and thus the
9789@option{-Wimplicit-fallthrough} warning must not trigger. The
9790fallthrough attribute may appear at most once in each attribute
9791list, and may not be mixed with other attributes. It can only
9792be used in a switch statement (the compiler will issue an error
9793otherwise), after a preceding statement and before a logically
9794succeeding case label, or user-defined label.
9795
9796This example uses the @code{fallthrough} statement attribute to indicate that
9797the @option{-Wimplicit-fallthrough} warning should not be emitted:
9798
9799@smallexample
9800switch (cond)
9801 @{
9802 case 1:
9803 bar (1);
9804 __attribute__((fallthrough));
9805 case 2:
9806 @dots{}
9807 @}
9808@end smallexample
9809
d77de738 9810@cindex @code{assume} statement attribute
f33d7a88 9811@item assume
d77de738
ML
9812The @code{assume} attribute with a null statement serves as portable
9813assumption. It should have a single argument, a conditional expression,
9814which is not evaluated. If the argument would evaluate to true
9815at the point where it appears, it has no effect, otherwise there
9816is undefined behavior. This is a GNU variant of the ISO C++23
9817standard @code{assume} attribute, but it can be used in any version of
9818both C and C++.
9819
9820@smallexample
9821int
9822foo (int x, int y)
9823@{
9824 __attribute__((assume(x == 42)));
9825 __attribute__((assume(++y == 43)));
9826 return x + y;
9827@}
9828@end smallexample
9829
9830@code{y} is not actually incremented and the compiler can but does not
9831have to optimize it to just @code{return 42 + 42;}.
9832
9833@end table
9834
9835@node Attribute Syntax
9836@section Attribute Syntax
9837@cindex attribute syntax
837a12a2
SL
9838@cindex C standard attributes
9839@cindex C++ standard attributes
9840@cindex standard attribute syntax
9841@cindex GNU attribute syntax
9842
9843GCC provides two different ways to specify attributes: the standard C
9844and C++ syntax using double square brackets, and the older GNU
9845extension syntax using the @code{@w{__attribute__}} keyword, which predates
9846the adoption of the standard syntax and is still widely used in older
9847code.
9848
9849The standard @samp{[[]]} attribute syntax is recognized by GCC's
9850default language dialect for both C and C++. More specifically, this
9851syntax was first introduced in the C++11 language standard
9852(@pxref{Standards}), and is supported by GCC in C++ code with
9853@option{-std=c++11} or @option{-std=gnu++11} or later. It is also
fad61bf7
JM
9854part of the C23 language standard and is supported when compiling C
9855code with @option{-std=c23} or @option{-std=gnu17} or later.
837a12a2
SL
9856
9857When using GNU-specific attributes in the standard syntax, you must
9858prefix their names with @samp{gnu::}, such as @code{gnu::section}.
9859Refer to the relevant language standards for exact details on the
9860placement of @samp{[[]]} attributes within your code, as they differ
9861in some details from the rules for the GNU attribute syntax.
9862
9863The remainder of this section describes the details of the GNU extension
9864@code{__attribute__} syntax,
9865and the constructs to which attribute specifiers bind, for the C
d77de738 9866language. Some details may vary for C++ and Objective-C@. Because of
d9922e4b 9867limitations in the grammar for attributes, some forms described here
d77de738
ML
9868may not be successfully parsed in all cases.
9869
9870There are some problems with the semantics of attributes in C++. For
9871example, there are no manglings for attributes, although they may affect
9872code generation, so problems may arise when attributed types are used in
9873conjunction with templates or overloading. Similarly, @code{typeid}
9874does not distinguish between types with different attributes. Support
9875for attributes in C++ may be restricted in future to attributes on
9876declarations only, but not on nested declarators.
9877
9878@xref{Function Attributes}, for details of the semantics of attributes
9879applying to functions. @xref{Variable Attributes}, for details of the
9880semantics of attributes applying to variables. @xref{Type Attributes},
9881for details of the semantics of attributes applying to structure, union
9882and enumerated types.
9883@xref{Label Attributes}, for details of the semantics of attributes
9884applying to labels.
9885@xref{Enumerator Attributes}, for details of the semantics of attributes
9886applying to enumerators.
9887@xref{Statement Attributes}, for details of the semantics of attributes
9888applying to statements.
9889
9890An @dfn{attribute specifier} is of the form
9891@code{__attribute__ ((@var{attribute-list}))}. An @dfn{attribute list}
9892is a possibly empty comma-separated sequence of @dfn{attributes}, where
9893each attribute is one of the following:
9894
9895@itemize @bullet
9896@item
9897Empty. Empty attributes are ignored.
9898
9899@item
9900An attribute name
9901(which may be an identifier such as @code{unused}, or a reserved
9902word such as @code{const}).
9903
9904@item
9905An attribute name followed by a parenthesized list of
9906parameters for the attribute.
9907These parameters take one of the following forms:
9908
9909@itemize @bullet
9910@item
9911An identifier. For example, @code{mode} attributes use this form.
9912
9913@item
9914An identifier followed by a comma and a non-empty comma-separated list
9915of expressions. For example, @code{format} attributes use this form.
9916
9917@item
9918A possibly empty comma-separated list of expressions. For example,
9919@code{format_arg} attributes use this form with the list being a single
9920integer constant expression, and @code{alias} attributes use this form
9921with the list being a single string constant.
9922@end itemize
9923@end itemize
9924
9925An @dfn{attribute specifier list} is a sequence of one or more attribute
9926specifiers, not separated by any other tokens.
9927
9928You may optionally specify attribute names with @samp{__}
9929preceding and following the name.
9930This allows you to use them in header files without
9931being concerned about a possible macro of the same name. For example,
9932you may use the attribute name @code{__noreturn__} instead of @code{noreturn}.
9933
9934
9935@subsubheading Label Attributes
9936
9937In GNU C, an attribute specifier list may appear after the colon following a
9938label, other than a @code{case} or @code{default} label. GNU C++ only permits
9939attributes on labels if the attribute specifier is immediately
9940followed by a semicolon (i.e., the label applies to an empty
9941statement). If the semicolon is missing, C++ label attributes are
9942ambiguous, as it is permissible for a declaration, which could begin
9943with an attribute list, to be labelled in C++. Declarations cannot be
9944labelled in C90 or C99, so the ambiguity does not arise there.
9945
9946@subsubheading Enumerator Attributes
9947
9948In GNU C, an attribute specifier list may appear as part of an enumerator.
9949The attribute goes after the enumeration constant, before @code{=}, if
9950present. The optional attribute in the enumerator appertains to the
9951enumeration constant. It is not possible to place the attribute after
9952the constant expression, if present.
9953
9954@subsubheading Statement Attributes
9955In GNU C, an attribute specifier list may appear as part of a null
9956statement. The attribute goes before the semicolon.
9957
9958@subsubheading Type Attributes
9959
9960An attribute specifier list may appear as part of a @code{struct},
9961@code{union} or @code{enum} specifier. It may go either immediately
9962after the @code{struct}, @code{union} or @code{enum} keyword, or after
9963the closing brace. The former syntax is preferred.
9964Where attribute specifiers follow the closing brace, they are considered
9965to relate to the structure, union or enumerated type defined, not to any
9966enclosing declaration the type specifier appears in, and the type
9967defined is not complete until after the attribute specifiers.
9968@c Otherwise, there would be the following problems: a shift/reduce
9969@c conflict between attributes binding the struct/union/enum and
9970@c binding to the list of specifiers/qualifiers; and "aligned"
9971@c attributes could use sizeof for the structure, but the size could be
9972@c changed later by "packed" attributes.
9973
9974
9975@subsubheading All other attributes
9976
9977Otherwise, an attribute specifier appears as part of a declaration,
9978counting declarations of unnamed parameters and type names, and relates
9979to that declaration (which may be nested in another declaration, for
9980example in the case of a parameter declaration), or to a particular declarator
9981within a declaration. Where an
9982attribute specifier is applied to a parameter declared as a function or
9983an array, it should apply to the function or array rather than the
9984pointer to which the parameter is implicitly converted, but this is not
9985yet correctly implemented.
9986
9987Any list of specifiers and qualifiers at the start of a declaration may
9988contain attribute specifiers, whether or not such a list may in that
9989context contain storage class specifiers. (Some attributes, however,
9990are essentially in the nature of storage class specifiers, and only make
9991sense where storage class specifiers may be used; for example,
9992@code{section}.) There is one necessary limitation to this syntax: the
9993first old-style parameter declaration in a function definition cannot
9994begin with an attribute specifier, because such an attribute applies to
9995the function instead by syntax described below (which, however, is not
9996yet implemented in this case). In some other cases, attribute
9997specifiers are permitted by this grammar but not yet supported by the
9998compiler. All attribute specifiers in this place relate to the
9999declaration as a whole. In the obsolescent usage where a type of
10000@code{int} is implied by the absence of type specifiers, such a list of
10001specifiers and qualifiers may be an attribute specifier list with no
10002other specifiers or qualifiers.
10003
10004At present, the first parameter in a function prototype must have some
10005type specifier that is not an attribute specifier; this resolves an
10006ambiguity in the interpretation of @code{void f(int
10007(__attribute__((foo)) x))}, but is subject to change. At present, if
10008the parentheses of a function declarator contain only attributes then
10009those attributes are ignored, rather than yielding an error or warning
10010or implying a single parameter of type int, but this is subject to
10011change.
10012
10013An attribute specifier list may appear immediately before a declarator
10014(other than the first) in a comma-separated list of declarators in a
10015declaration of more than one identifier using a single list of
10016specifiers and qualifiers. Such attribute specifiers apply
10017only to the identifier before whose declarator they appear. For
10018example, in
10019
10020@smallexample
10021__attribute__((noreturn)) void d0 (void),
10022 __attribute__((format(printf, 1, 2))) d1 (const char *, ...),
10023 d2 (void);
10024@end smallexample
10025
10026@noindent
10027the @code{noreturn} attribute applies to all the functions
10028declared; the @code{format} attribute only applies to @code{d1}.
10029
10030An attribute specifier list may appear immediately before the comma,
10031@code{=} or semicolon terminating the declaration of an identifier other
10032than a function definition. Such attribute specifiers apply
10033to the declared object or function. Where an
10034assembler name for an object or function is specified (@pxref{Asm
10035Labels}), the attribute must follow the @code{asm}
10036specification.
10037
10038An attribute specifier list may, in future, be permitted to appear after
10039the declarator in a function definition (before any old-style parameter
10040declarations or the function body).
10041
10042Attribute specifiers may be mixed with type qualifiers appearing inside
10043the @code{[]} of a parameter array declarator, in the C99 construct by
10044which such qualifiers are applied to the pointer to which the array is
10045implicitly converted. Such attribute specifiers apply to the pointer,
10046not to the array, but at present this is not implemented and they are
10047ignored.
10048
10049An attribute specifier list may appear at the start of a nested
10050declarator. At present, there are some limitations in this usage: the
10051attributes correctly apply to the declarator, but for most individual
10052attributes the semantics this implies are not implemented.
10053When attribute specifiers follow the @code{*} of a pointer
10054declarator, they may be mixed with any type qualifiers present.
10055The following describes the formal semantics of this syntax. It makes the
10056most sense if you are familiar with the formal specification of
10057declarators in the ISO C standard.
10058
10059Consider (as in C99 subclause 6.7.5 paragraph 4) a declaration @code{T
10060D1}, where @code{T} contains declaration specifiers that specify a type
10061@var{Type} (such as @code{int}) and @code{D1} is a declarator that
10062contains an identifier @var{ident}. The type specified for @var{ident}
10063for derived declarators whose type does not include an attribute
10064specifier is as in the ISO C standard.
10065
10066If @code{D1} has the form @code{( @var{attribute-specifier-list} D )},
10067and the declaration @code{T D} specifies the type
10068``@var{derived-declarator-type-list} @var{Type}'' for @var{ident}, then
10069@code{T D1} specifies the type ``@var{derived-declarator-type-list}
10070@var{attribute-specifier-list} @var{Type}'' for @var{ident}.
10071
10072If @code{D1} has the form @code{*
10073@var{type-qualifier-and-attribute-specifier-list} D}, and the
10074declaration @code{T D} specifies the type
10075``@var{derived-declarator-type-list} @var{Type}'' for @var{ident}, then
10076@code{T D1} specifies the type ``@var{derived-declarator-type-list}
10077@var{type-qualifier-and-attribute-specifier-list} pointer to @var{Type}'' for
10078@var{ident}.
10079
10080For example,
10081
10082@smallexample
10083void (__attribute__((noreturn)) ****f) (void);
10084@end smallexample
10085
10086@noindent
10087specifies the type ``pointer to pointer to pointer to pointer to
10088non-returning function returning @code{void}''. As another example,
10089
10090@smallexample
10091char *__attribute__((aligned(8))) *f;
10092@end smallexample
10093
10094@noindent
10095specifies the type ``pointer to 8-byte-aligned pointer to @code{char}''.
10096Note again that this does not work with most attributes; for example,
10097the usage of @samp{aligned} and @samp{noreturn} attributes given above
10098is not yet supported.
10099
10100For compatibility with existing code written for compiler versions that
10101did not implement attributes on nested declarators, some laxity is
10102allowed in the placing of attributes. If an attribute that only applies
10103to types is applied to a declaration, it is treated as applying to
10104the type of that declaration. If an attribute that only applies to
10105declarations is applied to the type of a declaration, it is treated
10106as applying to that declaration; and, for compatibility with code
10107placing the attributes immediately before the identifier declared, such
10108an attribute applied to a function return type is treated as
10109applying to the function type, and such an attribute applied to an array
10110element type is treated as applying to the array type. If an
10111attribute that only applies to function types is applied to a
10112pointer-to-function type, it is treated as applying to the pointer
10113target type; if such an attribute is applied to a function return type
10114that is not a pointer-to-function type, it is treated as applying
10115to the function type.
10116
10117@node Function Prototypes
10118@section Prototypes and Old-Style Function Definitions
10119@cindex function prototype declarations
10120@cindex old-style function definitions
10121@cindex promotion of formal parameters
10122
10123GNU C extends ISO C to allow a function prototype to override a later
10124old-style non-prototype definition. Consider the following example:
10125
10126@smallexample
10127/* @r{Use prototypes unless the compiler is old-fashioned.} */
10128#ifdef __STDC__
10129#define P(x) x
10130#else
10131#define P(x) ()
10132#endif
10133
10134/* @r{Prototype function declaration.} */
10135int isroot P((uid_t));
10136
10137/* @r{Old-style function definition.} */
10138int
10139isroot (x) /* @r{??? lossage here ???} */
10140 uid_t x;
10141@{
10142 return x == 0;
10143@}
10144@end smallexample
10145
10146Suppose the type @code{uid_t} happens to be @code{short}. ISO C does
10147not allow this example, because subword arguments in old-style
10148non-prototype definitions are promoted. Therefore in this example the
10149function definition's argument is really an @code{int}, which does not
10150match the prototype argument type of @code{short}.
10151
10152This restriction of ISO C makes it hard to write code that is portable
10153to traditional C compilers, because the programmer does not know
10154whether the @code{uid_t} type is @code{short}, @code{int}, or
10155@code{long}. Therefore, in cases like these GNU C allows a prototype
10156to override a later old-style definition. More precisely, in GNU C, a
10157function prototype argument type overrides the argument type specified
10158by a later old-style definition if the former type is the same as the
10159latter type before promotion. Thus in GNU C the above example is
10160equivalent to the following:
10161
10162@smallexample
10163int isroot (uid_t);
10164
10165int
10166isroot (uid_t x)
10167@{
10168 return x == 0;
10169@}
10170@end smallexample
10171
10172@noindent
10173GNU C++ does not support old-style function definitions, so this
10174extension is irrelevant.
10175
10176@node C++ Comments
10177@section C++ Style Comments
10178@cindex @code{//}
10179@cindex C++ comments
10180@cindex comments, C++ style
10181
10182In GNU C, you may use C++ style comments, which start with @samp{//} and
10183continue until the end of the line. Many other C implementations allow
10184such comments, and they are included in the 1999 C standard. However,
10185C++ style comments are not recognized if you specify an @option{-std}
10186option specifying a version of ISO C before C99, or @option{-ansi}
10187(equivalent to @option{-std=c90}).
10188
10189@node Dollar Signs
10190@section Dollar Signs in Identifier Names
10191@cindex $
10192@cindex dollar signs in identifier names
10193@cindex identifier names, dollar signs in
10194
10195In GNU C, you may normally use dollar signs in identifier names.
10196This is because many traditional C implementations allow such identifiers.
10197However, dollar signs in identifiers are not supported on a few target
10198machines, typically because the target assembler does not allow them.
10199
10200@node Character Escapes
10201@section The Character @key{ESC} in Constants
10202
10203You can use the sequence @samp{\e} in a string or character constant to
10204stand for the ASCII character @key{ESC}.
10205
10206@node Alignment
10207@section Determining the Alignment of Functions, Types or Variables
10208@cindex alignment
10209@cindex type alignment
10210@cindex variable alignment
10211
10212The keyword @code{__alignof__} determines the alignment requirement of
10213a function, object, or a type, or the minimum alignment usually required
10214by a type. Its syntax is just like @code{sizeof} and C11 @code{_Alignof}.
10215
10216For example, if the target machine requires a @code{double} value to be
10217aligned on an 8-byte boundary, then @code{__alignof__ (double)} is 8.
10218This is true on many RISC machines. On more traditional machine
10219designs, @code{__alignof__ (double)} is 4 or even 2.
10220
10221Some machines never actually require alignment; they allow references to any
10222data type even at an odd address. For these machines, @code{__alignof__}
10223reports the smallest alignment that GCC gives the data type, usually as
10224mandated by the target ABI.
10225
10226If the operand of @code{__alignof__} is an lvalue rather than a type,
10227its value is the required alignment for its type, taking into account
10228any minimum alignment specified by attribute @code{aligned}
10229(@pxref{Common Variable Attributes}). For example, after this
10230declaration:
10231
10232@smallexample
10233struct foo @{ int x; char y; @} foo1;
10234@end smallexample
10235
10236@noindent
10237the value of @code{__alignof__ (foo1.y)} is 1, even though its actual
10238alignment is probably 2 or 4, the same as @code{__alignof__ (int)}.
10239It is an error to ask for the alignment of an incomplete type other
10240than @code{void}.
10241
10242If the operand of the @code{__alignof__} expression is a function,
10243the expression evaluates to the alignment of the function which may
10244be specified by attribute @code{aligned} (@pxref{Common Function Attributes}).
10245
10246@node Inline
10247@section An Inline Function is As Fast As a Macro
10248@cindex inline functions
10249@cindex integrating function code
10250@cindex open coding
10251@cindex macros, inline alternative
10252
10253By declaring a function inline, you can direct GCC to make
10254calls to that function faster. One way GCC can achieve this is to
10255integrate that function's code into the code for its callers. This
10256makes execution faster by eliminating the function-call overhead; in
10257addition, if any of the actual argument values are constant, their
10258known values may permit simplifications at compile time so that not
10259all of the inline function's code needs to be included. The effect on
10260code size is less predictable; object code may be larger or smaller
10261with function inlining, depending on the particular case. You can
10262also direct GCC to try to integrate all ``simple enough'' functions
10263into their callers with the option @option{-finline-functions}.
10264
10265GCC implements three different semantics of declaring a function
10266inline. One is available with @option{-std=gnu89} or
10267@option{-fgnu89-inline} or when @code{gnu_inline} attribute is present
10268on all inline declarations, another when
10269@option{-std=c99},
10270@option{-std=gnu99} or an option for a later C version is used
10271(without @option{-fgnu89-inline}), and the third
10272is used when compiling C++.
10273
10274To declare a function inline, use the @code{inline} keyword in its
10275declaration, like this:
10276
10277@smallexample
10278static inline int
10279inc (int *a)
10280@{
10281 return (*a)++;
10282@}
10283@end smallexample
10284
10285If you are writing a header file to be included in ISO C90 programs, write
10286@code{__inline__} instead of @code{inline}. @xref{Alternate Keywords}.
10287
10288The three types of inlining behave similarly in two important cases:
10289when the @code{inline} keyword is used on a @code{static} function,
10290like the example above, and when a function is first declared without
10291using the @code{inline} keyword and then is defined with
10292@code{inline}, like this:
10293
10294@smallexample
10295extern int inc (int *a);
10296inline int
10297inc (int *a)
10298@{
10299 return (*a)++;
10300@}
10301@end smallexample
10302
10303In both of these common cases, the program behaves the same as if you
10304had not used the @code{inline} keyword, except for its speed.
10305
10306@cindex inline functions, omission of
10307@opindex fkeep-inline-functions
10308When a function is both inline and @code{static}, if all calls to the
10309function are integrated into the caller, and the function's address is
10310never used, then the function's own assembler code is never referenced.
10311In this case, GCC does not actually output assembler code for the
10312function, unless you specify the option @option{-fkeep-inline-functions}.
10313If there is a nonintegrated call, then the function is compiled to
10314assembler code as usual. The function must also be compiled as usual if
10315the program refers to its address, because that cannot be inlined.
10316
10317@opindex Winline
10318Note that certain usages in a function definition can make it unsuitable
10319for inline substitution. Among these usages are: variadic functions,
10320use of @code{alloca}, use of computed goto (@pxref{Labels as Values}),
10321use of nonlocal goto, use of nested functions, use of @code{setjmp}, use
10322of @code{__builtin_longjmp} and use of @code{__builtin_return} or
10323@code{__builtin_apply_args}. Using @option{-Winline} warns when a
10324function marked @code{inline} could not be substituted, and gives the
10325reason for the failure.
10326
10327@cindex automatic @code{inline} for C++ member fns
10328@cindex @code{inline} automatic for C++ member fns
10329@cindex member fns, automatically @code{inline}
10330@cindex C++ member fns, automatically @code{inline}
10331@opindex fno-default-inline
10332As required by ISO C++, GCC considers member functions defined within
10333the body of a class to be marked inline even if they are
10334not explicitly declared with the @code{inline} keyword. You can
10335override this with @option{-fno-default-inline}; @pxref{C++ Dialect
10336Options,,Options Controlling C++ Dialect}.
10337
10338GCC does not inline any functions when not optimizing unless you specify
10339the @samp{always_inline} attribute for the function, like this:
10340
10341@smallexample
10342/* @r{Prototype.} */
10343inline void foo (const char) __attribute__((always_inline));
10344@end smallexample
10345
10346The remainder of this section is specific to GNU C90 inlining.
10347
10348@cindex non-static inline function
10349When an inline function is not @code{static}, then the compiler must assume
10350that there may be calls from other source files; since a global symbol can
10351be defined only once in any program, the function must not be defined in
10352the other source files, so the calls therein cannot be integrated.
10353Therefore, a non-@code{static} inline function is always compiled on its
10354own in the usual fashion.
10355
10356If you specify both @code{inline} and @code{extern} in the function
10357definition, then the definition is used only for inlining. In no case
10358is the function compiled on its own, not even if you refer to its
10359address explicitly. Such an address becomes an external reference, as
10360if you had only declared the function, and had not defined it.
10361
10362This combination of @code{inline} and @code{extern} has almost the
10363effect of a macro. The way to use it is to put a function definition in
10364a header file with these keywords, and put another copy of the
10365definition (lacking @code{inline} and @code{extern}) in a library file.
10366The definition in the header file causes most calls to the function
10367to be inlined. If any uses of the function remain, they refer to
10368the single copy in the library.
10369
10370@node Volatiles
10371@section When is a Volatile Object Accessed?
10372@cindex accessing volatiles
10373@cindex volatile read
10374@cindex volatile write
10375@cindex volatile access
10376
10377C has the concept of volatile objects. These are normally accessed by
10378pointers and used for accessing hardware or inter-thread
10379communication. The standard encourages compilers to refrain from
10380optimizations concerning accesses to volatile objects, but leaves it
10381implementation defined as to what constitutes a volatile access. The
10382minimum requirement is that at a sequence point all previous accesses
10383to volatile objects have stabilized and no subsequent accesses have
10384occurred. Thus an implementation is free to reorder and combine
10385volatile accesses that occur between sequence points, but cannot do
10386so for accesses across a sequence point. The use of volatile does
10387not allow you to violate the restriction on updating objects multiple
10388times between two sequence points.
10389
10390Accesses to non-volatile objects are not ordered with respect to
10391volatile accesses. You cannot use a volatile object as a memory
10392barrier to order a sequence of writes to non-volatile memory. For
10393instance:
10394
10395@smallexample
10396int *ptr = @var{something};
10397volatile int vobj;
10398*ptr = @var{something};
10399vobj = 1;
10400@end smallexample
10401
10402@noindent
10403Unless @var{*ptr} and @var{vobj} can be aliased, it is not guaranteed
10404that the write to @var{*ptr} occurs by the time the update
10405of @var{vobj} happens. If you need this guarantee, you must use
10406a stronger memory barrier such as:
10407
10408@smallexample
10409int *ptr = @var{something};
10410volatile int vobj;
10411*ptr = @var{something};
10412asm volatile ("" : : : "memory");
10413vobj = 1;
10414@end smallexample
10415
10416A scalar volatile object is read when it is accessed in a void context:
10417
10418@smallexample
10419volatile int *src = @var{somevalue};
10420*src;
10421@end smallexample
10422
10423Such expressions are rvalues, and GCC implements this as a
10424read of the volatile object being pointed to.
10425
10426Assignments are also expressions and have an rvalue. However when
10427assigning to a scalar volatile, the volatile object is not reread,
10428regardless of whether the assignment expression's rvalue is used or
10429not. If the assignment's rvalue is used, the value is that assigned
10430to the volatile object. For instance, there is no read of @var{vobj}
10431in all the following cases:
10432
10433@smallexample
10434int obj;
10435volatile int vobj;
10436vobj = @var{something};
10437obj = vobj = @var{something};
10438obj ? vobj = @var{onething} : vobj = @var{anotherthing};
10439obj = (@var{something}, vobj = @var{anotherthing});
10440@end smallexample
10441
10442If you need to read the volatile object after an assignment has
10443occurred, you must use a separate expression with an intervening
10444sequence point.
10445
10446As bit-fields are not individually addressable, volatile bit-fields may
10447be implicitly read when written to, or when adjacent bit-fields are
10448accessed. Bit-field operations may be optimized such that adjacent
10449bit-fields are only partially accessed, if they straddle a storage unit
10450boundary. For these reasons it is unwise to use volatile bit-fields to
10451access hardware.
10452
10453@node Using Assembly Language with C
10454@section How to Use Inline Assembly Language in C Code
10455@cindex @code{asm} keyword
10456@cindex assembly language in C
10457@cindex inline assembly language
10458@cindex mixing assembly language and C
10459
10460The @code{asm} keyword allows you to embed assembler instructions
10461within C code. GCC provides two forms of inline @code{asm}
10462statements. A @dfn{basic @code{asm}} statement is one with no
10463operands (@pxref{Basic Asm}), while an @dfn{extended @code{asm}}
10464statement (@pxref{Extended Asm}) includes one or more operands.
10465The extended form is preferred for mixing C and assembly language
10466within a function, but to include assembly language at
10467top level you must use basic @code{asm}.
10468
10469You can also use the @code{asm} keyword to override the assembler name
10470for a C symbol, or to place a C variable in a specific register.
10471
10472@menu
10473* Basic Asm:: Inline assembler without operands.
10474* Extended Asm:: Inline assembler with operands.
10475* Constraints:: Constraints for @code{asm} operands
10476* Asm Labels:: Specifying the assembler name to use for a C symbol.
10477* Explicit Register Variables:: Defining variables residing in specified
10478 registers.
10479* Size of an asm:: How GCC calculates the size of an @code{asm} block.
10480@end menu
10481
10482@node Basic Asm
10483@subsection Basic Asm --- Assembler Instructions Without Operands
10484@cindex basic @code{asm}
10485@cindex assembly language in C, basic
10486
10487A basic @code{asm} statement has the following syntax:
10488
10489@example
10490asm @var{asm-qualifiers} ( @var{AssemblerInstructions} )
10491@end example
10492
10493For the C language, the @code{asm} keyword is a GNU extension.
10494When writing C code that can be compiled with @option{-ansi} and the
10495@option{-std} options that select C dialects without GNU extensions, use
10496@code{__asm__} instead of @code{asm} (@pxref{Alternate Keywords}). For
10497the C++ language, @code{asm} is a standard keyword, but @code{__asm__}
10498can be used for code compiled with @option{-fno-asm}.
10499
10500@subsubheading Qualifiers
10501@table @code
10502@item volatile
10503The optional @code{volatile} qualifier has no effect.
10504All basic @code{asm} blocks are implicitly volatile.
10505
10506@item inline
10507If you use the @code{inline} qualifier, then for inlining purposes the size
10508of the @code{asm} statement is taken as the smallest size possible (@pxref{Size
10509of an asm}).
10510@end table
10511
10512@subsubheading Parameters
10513@table @var
10514
10515@item AssemblerInstructions
10516This is a literal string that specifies the assembler code. The string can
10517contain any instructions recognized by the assembler, including directives.
10518GCC does not parse the assembler instructions themselves and
10519does not know what they mean or even whether they are valid assembler input.
10520
10521You may place multiple assembler instructions together in a single @code{asm}
10522string, separated by the characters normally used in assembly code for the
10523system. A combination that works in most places is a newline to break the
10524line, plus a tab character (written as @samp{\n\t}).
10525Some assemblers allow semicolons as a line separator. However,
10526note that some assembler dialects use semicolons to start a comment.
10527@end table
10528
10529@subsubheading Remarks
10530Using extended @code{asm} (@pxref{Extended Asm}) typically produces
10531smaller, safer, and more efficient code, and in most cases it is a
10532better solution than basic @code{asm}. However, there are two
10533situations where only basic @code{asm} can be used:
10534
10535@itemize @bullet
10536@item
10537Extended @code{asm} statements have to be inside a C
10538function, so to write inline assembly language at file scope (``top-level''),
10539outside of C functions, you must use basic @code{asm}.
10540You can use this technique to emit assembler directives,
10541define assembly language macros that can be invoked elsewhere in the file,
10542or write entire functions in assembly language.
10543Basic @code{asm} statements outside of functions may not use any
10544qualifiers.
10545
10546@item
10547Functions declared
10548with the @code{naked} attribute also require basic @code{asm}
10549(@pxref{Function Attributes}).
10550@end itemize
10551
10552Safely accessing C data and calling functions from basic @code{asm} is more
10553complex than it may appear. To access C data, it is better to use extended
10554@code{asm}.
10555
10556Do not expect a sequence of @code{asm} statements to remain perfectly
10557consecutive after compilation. If certain instructions need to remain
10558consecutive in the output, put them in a single multi-instruction @code{asm}
10559statement. Note that GCC's optimizers can move @code{asm} statements
10560relative to other code, including across jumps.
10561
10562@code{asm} statements may not perform jumps into other @code{asm} statements.
10563GCC does not know about these jumps, and therefore cannot take
10564account of them when deciding how to optimize. Jumps from @code{asm} to C
10565labels are only supported in extended @code{asm}.
10566
10567Under certain circumstances, GCC may duplicate (or remove duplicates of) your
10568assembly code when optimizing. This can lead to unexpected duplicate
10569symbol errors during compilation if your assembly code defines symbols or
10570labels.
10571
10572@strong{Warning:} The C standards do not specify semantics for @code{asm},
10573making it a potential source of incompatibilities between compilers. These
10574incompatibilities may not produce compiler warnings/errors.
10575
10576GCC does not parse basic @code{asm}'s @var{AssemblerInstructions}, which
10577means there is no way to communicate to the compiler what is happening
10578inside them. GCC has no visibility of symbols in the @code{asm} and may
10579discard them as unreferenced. It also does not know about side effects of
10580the assembler code, such as modifications to memory or registers. Unlike
10581some compilers, GCC assumes that no changes to general purpose registers
10582occur. This assumption may change in a future release.
10583
10584To avoid complications from future changes to the semantics and the
10585compatibility issues between compilers, consider replacing basic @code{asm}
10586with extended @code{asm}. See
10587@uref{https://gcc.gnu.org/wiki/ConvertBasicAsmToExtended, How to convert
10588from basic asm to extended asm} for information about how to perform this
10589conversion.
10590
10591The compiler copies the assembler instructions in a basic @code{asm}
10592verbatim to the assembly language output file, without
10593processing dialects or any of the @samp{%} operators that are available with
10594extended @code{asm}. This results in minor differences between basic
10595@code{asm} strings and extended @code{asm} templates. For example, to refer to
10596registers you might use @samp{%eax} in basic @code{asm} and
10597@samp{%%eax} in extended @code{asm}.
10598
10599On targets such as x86 that support multiple assembler dialects,
10600all basic @code{asm} blocks use the assembler dialect specified by the
10601@option{-masm} command-line option (@pxref{x86 Options}).
10602Basic @code{asm} provides no
10603mechanism to provide different assembler strings for different dialects.
10604
10605For basic @code{asm} with non-empty assembler string GCC assumes
10606the assembler block does not change any general purpose registers,
10607but it may read or write any globally accessible variable.
10608
10609Here is an example of basic @code{asm} for i386:
10610
10611@example
10612/* Note that this code will not compile with -masm=intel */
10613#define DebugBreak() asm("int $3")
10614@end example
10615
10616@node Extended Asm
10617@subsection Extended Asm - Assembler Instructions with C Expression Operands
10618@cindex extended @code{asm}
10619@cindex assembly language in C, extended
10620
10621With extended @code{asm} you can read and write C variables from
10622assembler and perform jumps from assembler code to C labels.
10623Extended @code{asm} syntax uses colons (@samp{:}) to delimit
10624the operand parameters after the assembler template:
10625
10626@example
10627asm @var{asm-qualifiers} ( @var{AssemblerTemplate}
10628 : @var{OutputOperands}
10629 @r{[} : @var{InputOperands}
10630 @r{[} : @var{Clobbers} @r{]} @r{]})
10631
10632asm @var{asm-qualifiers} ( @var{AssemblerTemplate}
10633 : @var{OutputOperands}
10634 : @var{InputOperands}
10635 : @var{Clobbers}
10636 : @var{GotoLabels})
10637@end example
10638where in the last form, @var{asm-qualifiers} contains @code{goto} (and in the
10639first form, not).
10640
10641The @code{asm} keyword is a GNU extension.
10642When writing code that can be compiled with @option{-ansi} and the
10643various @option{-std} options, use @code{__asm__} instead of
10644@code{asm} (@pxref{Alternate Keywords}).
10645
10646@subsubheading Qualifiers
10647@table @code
10648
10649@item volatile
10650The typical use of extended @code{asm} statements is to manipulate input
10651values to produce output values. However, your @code{asm} statements may
10652also produce side effects. If so, you may need to use the @code{volatile}
10653qualifier to disable certain optimizations. @xref{Volatile}.
10654
10655@item inline
10656If you use the @code{inline} qualifier, then for inlining purposes the size
10657of the @code{asm} statement is taken as the smallest size possible
10658(@pxref{Size of an asm}).
10659
10660@item goto
10661This qualifier informs the compiler that the @code{asm} statement may
10662perform a jump to one of the labels listed in the @var{GotoLabels}.
10663@xref{GotoLabels}.
10664@end table
10665
10666@subsubheading Parameters
10667@table @var
10668@item AssemblerTemplate
10669This is a literal string that is the template for the assembler code. It is a
10670combination of fixed text and tokens that refer to the input, output,
10671and goto parameters. @xref{AssemblerTemplate}.
10672
10673@item OutputOperands
10674A comma-separated list of the C variables modified by the instructions in the
10675@var{AssemblerTemplate}. An empty list is permitted. @xref{OutputOperands}.
10676
10677@item InputOperands
10678A comma-separated list of C expressions read by the instructions in the
10679@var{AssemblerTemplate}. An empty list is permitted. @xref{InputOperands}.
10680
10681@item Clobbers
10682A comma-separated list of registers or other values changed by the
10683@var{AssemblerTemplate}, beyond those listed as outputs.
10684An empty list is permitted. @xref{Clobbers and Scratch Registers}.
10685
10686@item GotoLabels
10687When you are using the @code{goto} form of @code{asm}, this section contains
10688the list of all C labels to which the code in the
10689@var{AssemblerTemplate} may jump.
10690@xref{GotoLabels}.
10691
10692@code{asm} statements may not perform jumps into other @code{asm} statements,
10693only to the listed @var{GotoLabels}.
10694GCC's optimizers do not know about other jumps; therefore they cannot take
10695account of them when deciding how to optimize.
10696@end table
10697
10698The total number of input + output + goto operands is limited to 30.
10699
10700@subsubheading Remarks
10701The @code{asm} statement allows you to include assembly instructions directly
10702within C code. This may help you to maximize performance in time-sensitive
10703code or to access assembly instructions that are not readily available to C
10704programs.
10705
10706Note that extended @code{asm} statements must be inside a function. Only
10707basic @code{asm} may be outside functions (@pxref{Basic Asm}).
10708Functions declared with the @code{naked} attribute also require basic
10709@code{asm} (@pxref{Function Attributes}).
10710
10711While the uses of @code{asm} are many and varied, it may help to think of an
10712@code{asm} statement as a series of low-level instructions that convert input
10713parameters to output parameters. So a simple (if not particularly useful)
10714example for i386 using @code{asm} might look like this:
10715
10716@example
10717int src = 1;
10718int dst;
10719
10720asm ("mov %1, %0\n\t"
10721 "add $1, %0"
10722 : "=r" (dst)
10723 : "r" (src));
10724
10725printf("%d\n", dst);
10726@end example
10727
10728This code copies @code{src} to @code{dst} and add 1 to @code{dst}.
10729
10730@anchor{Volatile}
10731@subsubsection Volatile
10732@cindex volatile @code{asm}
10733@cindex @code{asm} volatile
10734
10735GCC's optimizers sometimes discard @code{asm} statements if they determine
10736there is no need for the output variables. Also, the optimizers may move
10737code out of loops if they believe that the code will always return the same
10738result (i.e.@: none of its input values change between calls). Using the
10739@code{volatile} qualifier disables these optimizations. @code{asm} statements
10740that have no output operands and @code{asm goto} statements,
10741are implicitly volatile.
10742
10743This i386 code demonstrates a case that does not use (or require) the
10744@code{volatile} qualifier. If it is performing assertion checking, this code
10745uses @code{asm} to perform the validation. Otherwise, @code{dwRes} is
10746unreferenced by any code. As a result, the optimizers can discard the
10747@code{asm} statement, which in turn removes the need for the entire
10748@code{DoCheck} routine. By omitting the @code{volatile} qualifier when it
10749isn't needed you allow the optimizers to produce the most efficient code
10750possible.
10751
10752@example
10753void DoCheck(uint32_t dwSomeValue)
10754@{
10755 uint32_t dwRes;
10756
10757 // Assumes dwSomeValue is not zero.
10758 asm ("bsfl %1,%0"
10759 : "=r" (dwRes)
10760 : "r" (dwSomeValue)
10761 : "cc");
10762
10763 assert(dwRes > 3);
10764@}
10765@end example
10766
10767The next example shows a case where the optimizers can recognize that the input
10768(@code{dwSomeValue}) never changes during the execution of the function and can
10769therefore move the @code{asm} outside the loop to produce more efficient code.
10770Again, using the @code{volatile} qualifier disables this type of optimization.
10771
10772@example
10773void do_print(uint32_t dwSomeValue)
10774@{
10775 uint32_t dwRes;
10776
10777 for (uint32_t x=0; x < 5; x++)
10778 @{
10779 // Assumes dwSomeValue is not zero.
10780 asm ("bsfl %1,%0"
10781 : "=r" (dwRes)
10782 : "r" (dwSomeValue)
10783 : "cc");
10784
10785 printf("%u: %u %u\n", x, dwSomeValue, dwRes);
10786 @}
10787@}
10788@end example
10789
10790The following example demonstrates a case where you need to use the
10791@code{volatile} qualifier.
10792It uses the x86 @code{rdtsc} instruction, which reads
10793the computer's time-stamp counter. Without the @code{volatile} qualifier,
10794the optimizers might assume that the @code{asm} block will always return the
10795same value and therefore optimize away the second call.
10796
10797@example
10798uint64_t msr;
10799
10800asm volatile ( "rdtsc\n\t" // Returns the time in EDX:EAX.
10801 "shl $32, %%rdx\n\t" // Shift the upper bits left.
10802 "or %%rdx, %0" // 'Or' in the lower bits.
10803 : "=a" (msr)
10804 :
10805 : "rdx");
10806
10807printf("msr: %llx\n", msr);
10808
10809// Do other work...
10810
10811// Reprint the timestamp
10812asm volatile ( "rdtsc\n\t" // Returns the time in EDX:EAX.
10813 "shl $32, %%rdx\n\t" // Shift the upper bits left.
10814 "or %%rdx, %0" // 'Or' in the lower bits.
10815 : "=a" (msr)
10816 :
10817 : "rdx");
10818
10819printf("msr: %llx\n", msr);
10820@end example
10821
10822GCC's optimizers do not treat this code like the non-volatile code in the
10823earlier examples. They do not move it out of loops or omit it on the
10824assumption that the result from a previous call is still valid.
10825
10826Note that the compiler can move even @code{volatile asm} instructions relative
10827to other code, including across jump instructions. For example, on many
10828targets there is a system register that controls the rounding mode of
10829floating-point operations. Setting it with a @code{volatile asm} statement,
10830as in the following PowerPC example, does not work reliably.
10831
10832@example
10833asm volatile("mtfsf 255, %0" : : "f" (fpenv));
10834sum = x + y;
10835@end example
10836
10837The compiler may move the addition back before the @code{volatile asm}
10838statement. To make it work as expected, add an artificial dependency to
10839the @code{asm} by referencing a variable in the subsequent code, for
10840example:
10841
10842@example
10843asm volatile ("mtfsf 255,%1" : "=X" (sum) : "f" (fpenv));
10844sum = x + y;
10845@end example
10846
10847Under certain circumstances, GCC may duplicate (or remove duplicates of) your
10848assembly code when optimizing. This can lead to unexpected duplicate symbol
10849errors during compilation if your @code{asm} code defines symbols or labels.
10850Using @samp{%=}
10851(@pxref{AssemblerTemplate}) may help resolve this problem.
10852
10853@anchor{AssemblerTemplate}
10854@subsubsection Assembler Template
10855@cindex @code{asm} assembler template
10856
10857An assembler template is a literal string containing assembler instructions.
10858The compiler replaces tokens in the template that refer
10859to inputs, outputs, and goto labels,
10860and then outputs the resulting string to the assembler. The
10861string can contain any instructions recognized by the assembler, including
10862directives. GCC does not parse the assembler instructions
10863themselves and does not know what they mean or even whether they are valid
10864assembler input. However, it does count the statements
10865(@pxref{Size of an asm}).
10866
10867You may place multiple assembler instructions together in a single @code{asm}
10868string, separated by the characters normally used in assembly code for the
10869system. A combination that works in most places is a newline to break the
10870line, plus a tab character to move to the instruction field (written as
10871@samp{\n\t}).
10872Some assemblers allow semicolons as a line separator. However, note
10873that some assembler dialects use semicolons to start a comment.
10874
10875Do not expect a sequence of @code{asm} statements to remain perfectly
10876consecutive after compilation, even when you are using the @code{volatile}
10877qualifier. If certain instructions need to remain consecutive in the output,
10878put them in a single multi-instruction @code{asm} statement.
10879
10880Accessing data from C programs without using input/output operands (such as
10881by using global symbols directly from the assembler template) may not work as
10882expected. Similarly, calling functions directly from an assembler template
10883requires a detailed understanding of the target assembler and ABI.
10884
10885Since GCC does not parse the assembler template,
10886it has no visibility of any
10887symbols it references. This may result in GCC discarding those symbols as
10888unreferenced unless they are also listed as input, output, or goto operands.
10889
10890@subsubheading Special format strings
10891
10892In addition to the tokens described by the input, output, and goto operands,
10893these tokens have special meanings in the assembler template:
10894
10895@table @samp
10896@item %%
10897Outputs a single @samp{%} into the assembler code.
10898
10899@item %=
10900Outputs a number that is unique to each instance of the @code{asm}
10901statement in the entire compilation. This option is useful when creating local
10902labels and referring to them multiple times in a single template that
10903generates multiple assembler instructions.
10904
10905@item %@{
10906@itemx %|
10907@itemx %@}
10908Outputs @samp{@{}, @samp{|}, and @samp{@}} characters (respectively)
10909into the assembler code. When unescaped, these characters have special
10910meaning to indicate multiple assembler dialects, as described below.
10911@end table
10912
10913@subsubheading Multiple assembler dialects in @code{asm} templates
10914
10915On targets such as x86, GCC supports multiple assembler dialects.
10916The @option{-masm} option controls which dialect GCC uses as its
10917default for inline assembler. The target-specific documentation for the
10918@option{-masm} option contains the list of supported dialects, as well as the
10919default dialect if the option is not specified. This information may be
10920important to understand, since assembler code that works correctly when
10921compiled using one dialect will likely fail if compiled using another.
10922@xref{x86 Options}.
10923
10924If your code needs to support multiple assembler dialects (for example, if
10925you are writing public headers that need to support a variety of compilation
10926options), use constructs of this form:
10927
10928@example
10929@{ dialect0 | dialect1 | dialect2... @}
10930@end example
10931
10932This construct outputs @code{dialect0}
10933when using dialect #0 to compile the code,
10934@code{dialect1} for dialect #1, etc. If there are fewer alternatives within the
10935braces than the number of dialects the compiler supports, the construct
10936outputs nothing.
10937
10938For example, if an x86 compiler supports two dialects
10939(@samp{att}, @samp{intel}), an
10940assembler template such as this:
10941
10942@example
10943"bt@{l %[Offset],%[Base] | %[Base],%[Offset]@}; jc %l2"
10944@end example
10945
10946@noindent
10947is equivalent to one of
10948
10949@example
10950"btl %[Offset],%[Base] ; jc %l2" @r{/* att dialect */}
10951"bt %[Base],%[Offset]; jc %l2" @r{/* intel dialect */}
10952@end example
10953
10954Using that same compiler, this code:
10955
10956@example
10957"xchg@{l@}\t@{%%@}ebx, %1"
10958@end example
10959
10960@noindent
10961corresponds to either
10962
10963@example
10964"xchgl\t%%ebx, %1" @r{/* att dialect */}
10965"xchg\tebx, %1" @r{/* intel dialect */}
10966@end example
10967
10968There is no support for nesting dialect alternatives.
10969
10970@anchor{OutputOperands}
10971@subsubsection Output Operands
10972@cindex @code{asm} output operands
10973
10974An @code{asm} statement has zero or more output operands indicating the names
10975of C variables modified by the assembler code.
10976
10977In this i386 example, @code{old} (referred to in the template string as
10978@code{%0}) and @code{*Base} (as @code{%1}) are outputs and @code{Offset}
10979(@code{%2}) is an input:
10980
10981@example
10982bool old;
10983
10984__asm__ ("btsl %2,%1\n\t" // Turn on zero-based bit #Offset in Base.
10985 "sbb %0,%0" // Use the CF to calculate old.
10986 : "=r" (old), "+rm" (*Base)
10987 : "Ir" (Offset)
10988 : "cc");
10989
10990return old;
10991@end example
10992
10993Operands are separated by commas. Each operand has this format:
10994
10995@example
10996@r{[} [@var{asmSymbolicName}] @r{]} @var{constraint} (@var{cvariablename})
10997@end example
10998
10999@table @var
11000@item asmSymbolicName
11001Specifies a symbolic name for the operand.
11002Reference the name in the assembler template
11003by enclosing it in square brackets
11004(i.e.@: @samp{%[Value]}). The scope of the name is the @code{asm} statement
11005that contains the definition. Any valid C variable name is acceptable,
11006including names already defined in the surrounding code. No two operands
11007within the same @code{asm} statement can use the same symbolic name.
11008
11009When not using an @var{asmSymbolicName}, use the (zero-based) position
11010of the operand
11011in the list of operands in the assembler template. For example if there are
11012three output operands, use @samp{%0} in the template to refer to the first,
11013@samp{%1} for the second, and @samp{%2} for the third.
11014
11015@item constraint
11016A string constant specifying constraints on the placement of the operand;
11017@xref{Constraints}, for details.
11018
11019Output constraints must begin with either @samp{=} (a variable overwriting an
11020existing value) or @samp{+} (when reading and writing). When using
11021@samp{=}, do not assume the location contains the existing value
11022on entry to the @code{asm}, except
11023when the operand is tied to an input; @pxref{InputOperands,,Input Operands}.
11024
11025After the prefix, there must be one or more additional constraints
11026(@pxref{Constraints}) that describe where the value resides. Common
11027constraints include @samp{r} for register and @samp{m} for memory.
11028When you list more than one possible location (for example, @code{"=rm"}),
11029the compiler chooses the most efficient one based on the current context.
11030If you list as many alternates as the @code{asm} statement allows, you permit
11031the optimizers to produce the best possible code.
11032If you must use a specific register, but your Machine Constraints do not
11033provide sufficient control to select the specific register you want,
11034local register variables may provide a solution (@pxref{Local Register
11035Variables}).
11036
11037@item cvariablename
11038Specifies a C lvalue expression to hold the output, typically a variable name.
11039The enclosing parentheses are a required part of the syntax.
11040
11041@end table
11042
11043When the compiler selects the registers to use to
11044represent the output operands, it does not use any of the clobbered registers
11045(@pxref{Clobbers and Scratch Registers}).
11046
11047Output operand expressions must be lvalues. The compiler cannot check whether
11048the operands have data types that are reasonable for the instruction being
11049executed. For output expressions that are not directly addressable (for
11050example a bit-field), the constraint must allow a register. In that case, GCC
11051uses the register as the output of the @code{asm}, and then stores that
11052register into the output.
11053
11054Operands using the @samp{+} constraint modifier count as two operands
11055(that is, both as input and output) towards the total maximum of 30 operands
11056per @code{asm} statement.
11057
11058Use the @samp{&} constraint modifier (@pxref{Modifiers}) on all output
11059operands that must not overlap an input. Otherwise,
11060GCC may allocate the output operand in the same register as an unrelated
11061input operand, on the assumption that the assembler code consumes its
11062inputs before producing outputs. This assumption may be false if the assembler
11063code actually consists of more than one instruction.
11064
11065The same problem can occur if one output parameter (@var{a}) allows a register
11066constraint and another output parameter (@var{b}) allows a memory constraint.
11067The code generated by GCC to access the memory address in @var{b} can contain
11068registers which @emph{might} be shared by @var{a}, and GCC considers those
11069registers to be inputs to the asm. As above, GCC assumes that such input
11070registers are consumed before any outputs are written. This assumption may
11071result in incorrect behavior if the @code{asm} statement writes to @var{a}
11072before using
11073@var{b}. Combining the @samp{&} modifier with the register constraint on @var{a}
11074ensures that modifying @var{a} does not affect the address referenced by
11075@var{b}. Otherwise, the location of @var{b}
11076is undefined if @var{a} is modified before using @var{b}.
11077
11078@code{asm} supports operand modifiers on operands (for example @samp{%k2}
b5ea0f07
LC
11079instead of simply @samp{%2}). @ref{GenericOperandmodifiers,
11080Generic Operand modifiers} lists the modifiers that are available
11081on all targets. Other modifiers are hardware dependent.
11082For example, the list of supported modifiers for x86 is found at
d77de738
ML
11083@ref{x86Operandmodifiers,x86 Operand modifiers}.
11084
11085If the C code that follows the @code{asm} makes no use of any of the output
11086operands, use @code{volatile} for the @code{asm} statement to prevent the
11087optimizers from discarding the @code{asm} statement as unneeded
11088(see @ref{Volatile}).
11089
11090This code makes no use of the optional @var{asmSymbolicName}. Therefore it
11091references the first output operand as @code{%0} (were there a second, it
11092would be @code{%1}, etc). The number of the first input operand is one greater
11093than that of the last output operand. In this i386 example, that makes
11094@code{Mask} referenced as @code{%1}:
11095
11096@example
11097uint32_t Mask = 1234;
11098uint32_t Index;
11099
11100 asm ("bsfl %1, %0"
11101 : "=r" (Index)
11102 : "r" (Mask)
11103 : "cc");
11104@end example
11105
11106That code overwrites the variable @code{Index} (@samp{=}),
11107placing the value in a register (@samp{r}).
11108Using the generic @samp{r} constraint instead of a constraint for a specific
11109register allows the compiler to pick the register to use, which can result
11110in more efficient code. This may not be possible if an assembler instruction
11111requires a specific register.
11112
11113The following i386 example uses the @var{asmSymbolicName} syntax.
11114It produces the
11115same result as the code above, but some may consider it more readable or more
11116maintainable since reordering index numbers is not necessary when adding or
11117removing operands. The names @code{aIndex} and @code{aMask}
11118are only used in this example to emphasize which
11119names get used where.
11120It is acceptable to reuse the names @code{Index} and @code{Mask}.
11121
11122@example
11123uint32_t Mask = 1234;
11124uint32_t Index;
11125
11126 asm ("bsfl %[aMask], %[aIndex]"
11127 : [aIndex] "=r" (Index)
11128 : [aMask] "r" (Mask)
11129 : "cc");
11130@end example
11131
11132Here are some more examples of output operands.
11133
11134@example
11135uint32_t c = 1;
11136uint32_t d;
11137uint32_t *e = &c;
11138
11139asm ("mov %[e], %[d]"
11140 : [d] "=rm" (d)
11141 : [e] "rm" (*e));
11142@end example
11143
11144Here, @code{d} may either be in a register or in memory. Since the compiler
11145might already have the current value of the @code{uint32_t} location
11146pointed to by @code{e}
11147in a register, you can enable it to choose the best location
11148for @code{d} by specifying both constraints.
11149
11150@anchor{FlagOutputOperands}
11151@subsubsection Flag Output Operands
11152@cindex @code{asm} flag output operands
11153
11154Some targets have a special register that holds the ``flags'' for the
11155result of an operation or comparison. Normally, the contents of that
11156register are either unmodifed by the asm, or the @code{asm} statement is
11157considered to clobber the contents.
11158
11159On some targets, a special form of output operand exists by which
11160conditions in the flags register may be outputs of the asm. The set of
11161conditions supported are target specific, but the general rule is that
11162the output variable must be a scalar integer, and the value is boolean.
11163When supported, the target defines the preprocessor symbol
11164@code{__GCC_ASM_FLAG_OUTPUTS__}.
11165
11166Because of the special nature of the flag output operands, the constraint
11167may not include alternatives.
11168
11169Most often, the target has only one flags register, and thus is an implied
11170operand of many instructions. In this case, the operand should not be
11171referenced within the assembler template via @code{%0} etc, as there's
11172no corresponding text in the assembly language.
11173
11174@table @asis
11175@item ARM
11176@itemx AArch64
11177The flag output constraints for the ARM family are of the form
11178@samp{=@@cc@var{cond}} where @var{cond} is one of the standard
11179conditions defined in the ARM ARM for @code{ConditionHolds}.
11180
11181@table @code
11182@item eq
11183Z flag set, or equal
11184@item ne
11185Z flag clear or not equal
11186@item cs
11187@itemx hs
11188C flag set or unsigned greater than equal
11189@item cc
11190@itemx lo
11191C flag clear or unsigned less than
11192@item mi
11193N flag set or ``minus''
11194@item pl
11195N flag clear or ``plus''
11196@item vs
11197V flag set or signed overflow
11198@item vc
11199V flag clear
11200@item hi
11201unsigned greater than
11202@item ls
11203unsigned less than equal
11204@item ge
11205signed greater than equal
11206@item lt
11207signed less than
11208@item gt
11209signed greater than
11210@item le
11211signed less than equal
11212@end table
11213
11214The flag output constraints are not supported in thumb1 mode.
11215
11216@item x86 family
11217The flag output constraints for the x86 family are of the form
11218@samp{=@@cc@var{cond}} where @var{cond} is one of the standard
11219conditions defined in the ISA manual for @code{j@var{cc}} or
11220@code{set@var{cc}}.
11221
11222@table @code
11223@item a
11224``above'' or unsigned greater than
11225@item ae
11226``above or equal'' or unsigned greater than or equal
11227@item b
11228``below'' or unsigned less than
11229@item be
11230``below or equal'' or unsigned less than or equal
11231@item c
11232carry flag set
11233@item e
11234@itemx z
11235``equal'' or zero flag set
11236@item g
11237signed greater than
11238@item ge
11239signed greater than or equal
11240@item l
11241signed less than
11242@item le
11243signed less than or equal
11244@item o
11245overflow flag set
11246@item p
11247parity flag set
11248@item s
11249sign flag set
11250@item na
11251@itemx nae
11252@itemx nb
11253@itemx nbe
11254@itemx nc
11255@itemx ne
11256@itemx ng
11257@itemx nge
11258@itemx nl
11259@itemx nle
11260@itemx no
11261@itemx np
11262@itemx ns
11263@itemx nz
11264``not'' @var{flag}, or inverted versions of those above
11265@end table
11266
466b100e
JC
11267@item s390
11268The flag output constraint for s390 is @samp{=@@cc}. Only one such
11269constraint is allowed. The variable has to be stored in a @samp{int}
11270variable.
11271
d77de738
ML
11272@end table
11273
11274@anchor{InputOperands}
11275@subsubsection Input Operands
11276@cindex @code{asm} input operands
11277@cindex @code{asm} expressions
11278
11279Input operands make values from C variables and expressions available to the
11280assembly code.
11281
11282Operands are separated by commas. Each operand has this format:
11283
11284@example
11285@r{[} [@var{asmSymbolicName}] @r{]} @var{constraint} (@var{cexpression})
11286@end example
11287
11288@table @var
11289@item asmSymbolicName
11290Specifies a symbolic name for the operand.
11291Reference the name in the assembler template
11292by enclosing it in square brackets
11293(i.e.@: @samp{%[Value]}). The scope of the name is the @code{asm} statement
11294that contains the definition. Any valid C variable name is acceptable,
11295including names already defined in the surrounding code. No two operands
11296within the same @code{asm} statement can use the same symbolic name.
11297
11298When not using an @var{asmSymbolicName}, use the (zero-based) position
11299of the operand
11300in the list of operands in the assembler template. For example if there are
11301two output operands and three inputs,
11302use @samp{%2} in the template to refer to the first input operand,
11303@samp{%3} for the second, and @samp{%4} for the third.
11304
11305@item constraint
11306A string constant specifying constraints on the placement of the operand;
11307@xref{Constraints}, for details.
11308
11309Input constraint strings may not begin with either @samp{=} or @samp{+}.
11310When you list more than one possible location (for example, @samp{"irm"}),
11311the compiler chooses the most efficient one based on the current context.
11312If you must use a specific register, but your Machine Constraints do not
11313provide sufficient control to select the specific register you want,
11314local register variables may provide a solution (@pxref{Local Register
11315Variables}).
11316
11317Input constraints can also be digits (for example, @code{"0"}). This indicates
11318that the specified input must be in the same place as the output constraint
11319at the (zero-based) index in the output constraint list.
11320When using @var{asmSymbolicName} syntax for the output operands,
11321you may use these names (enclosed in brackets @samp{[]}) instead of digits.
11322
11323@item cexpression
11324This is the C variable or expression being passed to the @code{asm} statement
11325as input. The enclosing parentheses are a required part of the syntax.
11326
11327@end table
11328
11329When the compiler selects the registers to use to represent the input
11330operands, it does not use any of the clobbered registers
11331(@pxref{Clobbers and Scratch Registers}).
11332
11333If there are no output operands but there are input operands, place two
11334consecutive colons where the output operands would go:
11335
11336@example
11337__asm__ ("some instructions"
11338 : /* No outputs. */
11339 : "r" (Offset / 8));
11340@end example
11341
11342@strong{Warning:} Do @emph{not} modify the contents of input-only operands
11343(except for inputs tied to outputs). The compiler assumes that on exit from
11344the @code{asm} statement these operands contain the same values as they
11345had before executing the statement.
11346It is @emph{not} possible to use clobbers
11347to inform the compiler that the values in these inputs are changing. One
11348common work-around is to tie the changing input variable to an output variable
11349that never gets used. Note, however, that if the code that follows the
11350@code{asm} statement makes no use of any of the output operands, the GCC
11351optimizers may discard the @code{asm} statement as unneeded
11352(see @ref{Volatile}).
11353
11354@code{asm} supports operand modifiers on operands (for example @samp{%k2}
b5ea0f07
LC
11355instead of simply @samp{%2}). @ref{GenericOperandmodifiers,
11356Generic Operand modifiers} lists the modifiers that are available
11357on all targets. Other modifiers are hardware dependent.
11358For example, the list of supported modifiers for x86 is found at
d77de738
ML
11359@ref{x86Operandmodifiers,x86 Operand modifiers}.
11360
11361In this example using the fictitious @code{combine} instruction, the
11362constraint @code{"0"} for input operand 1 says that it must occupy the same
11363location as output operand 0. Only input operands may use numbers in
11364constraints, and they must each refer to an output operand. Only a number (or
11365the symbolic assembler name) in the constraint can guarantee that one operand
11366is in the same place as another. The mere fact that @code{foo} is the value of
11367both operands is not enough to guarantee that they are in the same place in
11368the generated assembler code.
11369
11370@example
11371asm ("combine %2, %0"
11372 : "=r" (foo)
11373 : "0" (foo), "g" (bar));
11374@end example
11375
11376Here is an example using symbolic names.
11377
11378@example
11379asm ("cmoveq %1, %2, %[result]"
11380 : [result] "=r"(result)
11381 : "r" (test), "r" (new), "[result]" (old));
11382@end example
11383
11384@anchor{Clobbers and Scratch Registers}
11385@subsubsection Clobbers and Scratch Registers
11386@cindex @code{asm} clobbers
11387@cindex @code{asm} scratch registers
11388
11389While the compiler is aware of changes to entries listed in the output
11390operands, the inline @code{asm} code may modify more than just the outputs. For
11391example, calculations may require additional registers, or the processor may
11392overwrite a register as a side effect of a particular assembler instruction.
11393In order to inform the compiler of these changes, list them in the clobber
11394list. Clobber list items are either register names or the special clobbers
11395(listed below). Each clobber list item is a string constant
11396enclosed in double quotes and separated by commas.
11397
11398Clobber descriptions may not in any way overlap with an input or output
11399operand. For example, you may not have an operand describing a register class
11400with one member when listing that register in the clobber list. Variables
11401declared to live in specific registers (@pxref{Explicit Register
11402Variables}) and used
11403as @code{asm} input or output operands must have no part mentioned in the
11404clobber description. In particular, there is no way to specify that input
11405operands get modified without also specifying them as output operands.
11406
11407When the compiler selects which registers to use to represent input and output
11408operands, it does not use any of the clobbered registers. As a result,
11409clobbered registers are available for any use in the assembler code.
11410
11411Another restriction is that the clobber list should not contain the
11412stack pointer register. This is because the compiler requires the
11413value of the stack pointer to be the same after an @code{asm}
11414statement as it was on entry to the statement. However, previous
11415versions of GCC did not enforce this rule and allowed the stack
11416pointer to appear in the list, with unclear semantics. This behavior
11417is deprecated and listing the stack pointer may become an error in
11418future versions of GCC@.
11419
11420Here is a realistic example for the VAX showing the use of clobbered
11421registers:
11422
11423@example
11424asm volatile ("movc3 %0, %1, %2"
11425 : /* No outputs. */
11426 : "g" (from), "g" (to), "g" (count)
11427 : "r0", "r1", "r2", "r3", "r4", "r5", "memory");
11428@end example
11429
11430Also, there are two special clobber arguments:
11431
11432@table @code
11433@item "cc"
11434The @code{"cc"} clobber indicates that the assembler code modifies the flags
11435register. On some machines, GCC represents the condition codes as a specific
11436hardware register; @code{"cc"} serves to name this register.
11437On other machines, condition code handling is different,
11438and specifying @code{"cc"} has no effect. But
11439it is valid no matter what the target.
11440
11441@item "memory"
11442The @code{"memory"} clobber tells the compiler that the assembly code
11443performs memory
11444reads or writes to items other than those listed in the input and output
11445operands (for example, accessing the memory pointed to by one of the input
11446parameters). To ensure memory contains correct values, GCC may need to flush
11447specific register values to memory before executing the @code{asm}. Further,
11448the compiler does not assume that any values read from memory before an
11449@code{asm} remain unchanged after that @code{asm}; it reloads them as
11450needed.
11451Using the @code{"memory"} clobber effectively forms a read/write
11452memory barrier for the compiler.
11453
11454Note that this clobber does not prevent the @emph{processor} from doing
11455speculative reads past the @code{asm} statement. To prevent that, you need
11456processor-specific fence instructions.
11457
11458@end table
11459
11460Flushing registers to memory has performance implications and may be
11461an issue for time-sensitive code. You can provide better information
11462to GCC to avoid this, as shown in the following examples. At a
11463minimum, aliasing rules allow GCC to know what memory @emph{doesn't}
11464need to be flushed.
11465
11466Here is a fictitious sum of squares instruction, that takes two
11467pointers to floating point values in memory and produces a floating
11468point register output.
11469Notice that @code{x}, and @code{y} both appear twice in the @code{asm}
11470parameters, once to specify memory accessed, and once to specify a
11471base register used by the @code{asm}. You won't normally be wasting a
11472register by doing this as GCC can use the same register for both
11473purposes. However, it would be foolish to use both @code{%1} and
11474@code{%3} for @code{x} in this @code{asm} and expect them to be the
11475same. In fact, @code{%3} may well not be a register. It might be a
11476symbolic memory reference to the object pointed to by @code{x}.
11477
11478@smallexample
11479asm ("sumsq %0, %1, %2"
11480 : "+f" (result)
11481 : "r" (x), "r" (y), "m" (*x), "m" (*y));
11482@end smallexample
11483
11484Here is a fictitious @code{*z++ = *x++ * *y++} instruction.
11485Notice that the @code{x}, @code{y} and @code{z} pointer registers
11486must be specified as input/output because the @code{asm} modifies
11487them.
11488
11489@smallexample
11490asm ("vecmul %0, %1, %2"
11491 : "+r" (z), "+r" (x), "+r" (y), "=m" (*z)
11492 : "m" (*x), "m" (*y));
11493@end smallexample
11494
11495An x86 example where the string memory argument is of unknown length.
11496
11497@smallexample
11498asm("repne scasb"
11499 : "=c" (count), "+D" (p)
11500 : "m" (*(const char (*)[]) p), "0" (-1), "a" (0));
11501@end smallexample
11502
11503If you know the above will only be reading a ten byte array then you
11504could instead use a memory input like:
11505@code{"m" (*(const char (*)[10]) p)}.
11506
11507Here is an example of a PowerPC vector scale implemented in assembly,
11508complete with vector and condition code clobbers, and some initialized
11509offset registers that are unchanged by the @code{asm}.
11510
11511@smallexample
11512void
11513dscal (size_t n, double *x, double alpha)
11514@{
11515 asm ("/* lots of asm here */"
11516 : "+m" (*(double (*)[n]) x), "+&r" (n), "+b" (x)
11517 : "d" (alpha), "b" (32), "b" (48), "b" (64),
11518 "b" (80), "b" (96), "b" (112)
11519 : "cr0",
11520 "vs32","vs33","vs34","vs35","vs36","vs37","vs38","vs39",
11521 "vs40","vs41","vs42","vs43","vs44","vs45","vs46","vs47");
11522@}
11523@end smallexample
11524
11525Rather than allocating fixed registers via clobbers to provide scratch
11526registers for an @code{asm} statement, an alternative is to define a
11527variable and make it an early-clobber output as with @code{a2} and
11528@code{a3} in the example below. This gives the compiler register
11529allocator more freedom. You can also define a variable and make it an
11530output tied to an input as with @code{a0} and @code{a1}, tied
11531respectively to @code{ap} and @code{lda}. Of course, with tied
11532outputs your @code{asm} can't use the input value after modifying the
11533output register since they are one and the same register. What's
11534more, if you omit the early-clobber on the output, it is possible that
11535GCC might allocate the same register to another of the inputs if GCC
11536could prove they had the same value on entry to the @code{asm}. This
11537is why @code{a1} has an early-clobber. Its tied input, @code{lda}
11538might conceivably be known to have the value 16 and without an
11539early-clobber share the same register as @code{%11}. On the other
11540hand, @code{ap} can't be the same as any of the other inputs, so an
11541early-clobber on @code{a0} is not needed. It is also not desirable in
11542this case. An early-clobber on @code{a0} would cause GCC to allocate
11543a separate register for the @code{"m" (*(const double (*)[]) ap)}
11544input. Note that tying an input to an output is the way to set up an
11545initialized temporary register modified by an @code{asm} statement.
11546An input not tied to an output is assumed by GCC to be unchanged, for
11547example @code{"b" (16)} below sets up @code{%11} to 16, and GCC might
11548use that register in following code if the value 16 happened to be
11549needed. You can even use a normal @code{asm} output for a scratch if
11550all inputs that might share the same register are consumed before the
11551scratch is used. The VSX registers clobbered by the @code{asm}
11552statement could have used this technique except for GCC's limit on the
11553number of @code{asm} parameters.
11554
11555@smallexample
11556static void
11557dgemv_kernel_4x4 (long n, const double *ap, long lda,
11558 const double *x, double *y, double alpha)
11559@{
11560 double *a0;
11561 double *a1;
11562 double *a2;
11563 double *a3;
11564
11565 __asm__
11566 (
11567 /* lots of asm here */
11568 "#n=%1 ap=%8=%12 lda=%13 x=%7=%10 y=%0=%2 alpha=%9 o16=%11\n"
11569 "#a0=%3 a1=%4 a2=%5 a3=%6"
11570 :
11571 "+m" (*(double (*)[n]) y),
11572 "+&r" (n), // 1
11573 "+b" (y), // 2
11574 "=b" (a0), // 3
11575 "=&b" (a1), // 4
11576 "=&b" (a2), // 5
11577 "=&b" (a3) // 6
11578 :
11579 "m" (*(const double (*)[n]) x),
11580 "m" (*(const double (*)[]) ap),
11581 "d" (alpha), // 9
11582 "r" (x), // 10
11583 "b" (16), // 11
11584 "3" (ap), // 12
11585 "4" (lda) // 13
11586 :
11587 "cr0",
11588 "vs32","vs33","vs34","vs35","vs36","vs37",
11589 "vs40","vs41","vs42","vs43","vs44","vs45","vs46","vs47"
11590 );
11591@}
11592@end smallexample
11593
11594@anchor{GotoLabels}
11595@subsubsection Goto Labels
11596@cindex @code{asm} goto labels
11597
11598@code{asm goto} allows assembly code to jump to one or more C labels. The
11599@var{GotoLabels} section in an @code{asm goto} statement contains
11600a comma-separated
11601list of all C labels to which the assembler code may jump. GCC assumes that
11602@code{asm} execution falls through to the next statement (if this is not the
11603case, consider using the @code{__builtin_unreachable} intrinsic after the
11604@code{asm} statement). Optimization of @code{asm goto} may be improved by
11605using the @code{hot} and @code{cold} label attributes (@pxref{Label
11606Attributes}).
11607
11608If the assembler code does modify anything, use the @code{"memory"} clobber
11609to force the
11610optimizers to flush all register values to memory and reload them if
11611necessary after the @code{asm} statement.
11612
11613Also note that an @code{asm goto} statement is always implicitly
11614considered volatile.
11615
11616Be careful when you set output operands inside @code{asm goto} only on
11617some possible control flow paths. If you don't set up the output on
11618given path and never use it on this path, it is okay. Otherwise, you
11619should use @samp{+} constraint modifier meaning that the operand is
11620input and output one. With this modifier you will have the correct
11621values on all possible paths from the @code{asm goto}.
11622
11623To reference a label in the assembler template, prefix it with
11624@samp{%l} (lowercase @samp{L}) followed by its (zero-based) position
11625in @var{GotoLabels} plus the number of input and output operands.
11626Output operand with constraint modifier @samp{+} is counted as two
11627operands because it is considered as one output and one input operand.
11628For example, if the @code{asm} has three inputs, one output operand
11629with constraint modifier @samp{+} and one output operand with
11630constraint modifier @samp{=} and references two labels, refer to the
11631first label as @samp{%l6} and the second as @samp{%l7}).
11632
11633Alternately, you can reference labels using the actual C label name
11634enclosed in brackets. For example, to reference a label named
11635@code{carry}, you can use @samp{%l[carry]}. The label must still be
11636listed in the @var{GotoLabels} section when using this approach. It
11637is better to use the named references for labels as in this case you
11638can avoid counting input and output operands and special treatment of
11639output operands with constraint modifier @samp{+}.
11640
11641Here is an example of @code{asm goto} for i386:
11642
11643@example
11644asm goto (
11645 "btl %1, %0\n\t"
11646 "jc %l2"
11647 : /* No outputs. */
11648 : "r" (p1), "r" (p2)
11649 : "cc"
11650 : carry);
11651
11652return 0;
11653
11654carry:
11655return 1;
11656@end example
11657
11658The following example shows an @code{asm goto} that uses a memory clobber.
11659
11660@example
11661int frob(int x)
11662@{
11663 int y;
11664 asm goto ("frob %%r5, %1; jc %l[error]; mov (%2), %%r5"
11665 : /* No outputs. */
11666 : "r"(x), "r"(&y)
11667 : "r5", "memory"
11668 : error);
11669 return y;
11670error:
11671 return -1;
11672@}
11673@end example
11674
11675The following example shows an @code{asm goto} that uses an output.
11676
11677@example
11678int foo(int count)
11679@{
11680 asm goto ("dec %0; jb %l[stop]"
11681 : "+r" (count)
11682 :
11683 :
11684 : stop);
11685 return count;
11686stop:
11687 return 0;
11688@}
11689@end example
11690
11691The following artificial example shows an @code{asm goto} that sets
11692up an output only on one path inside the @code{asm goto}. Usage of
11693constraint modifier @code{=} instead of @code{+} would be wrong as
11694@code{factor} is used on all paths from the @code{asm goto}.
11695
11696@example
11697int foo(int inp)
11698@{
11699 int factor = 0;
11700 asm goto ("cmp %1, 10; jb %l[lab]; mov 2, %0"
11701 : "+r" (factor)
11702 : "r" (inp)
11703 :
11704 : lab);
11705lab:
11706 return inp * factor; /* return 2 * inp or 0 if inp < 10 */
11707@}
11708@end example
11709
b5ea0f07
LC
11710@anchor{GenericOperandmodifiers}
11711@subsubsection Generic Operand Modifiers
11712@noindent
11713The following table shows the modifiers supported by all targets and their effects:
11714
4ace81b6 11715@multitable @columnfractions 0.15 0.7 0.15
b5ea0f07
LC
11716@headitem Modifier @tab Description @tab Example
11717@item @code{c}
11718@tab Require a constant operand and print the constant expression with no punctuation.
11719@tab @code{%c0}
11720@item @code{n}
11721@tab Like @samp{%c} except that the value of the constant is negated before printing.
11722@tab @code{%n0}
11723@item @code{a}
11724@tab Substitute a memory reference, with the actual operand treated as the address.
11725This may be useful when outputting a ``load address'' instruction, because
11726often the assembler syntax for such an instruction requires you to write the
11727operand as if it were a memory reference.
11728@tab @code{%a0}
11729@item @code{l}
11730@tab Print the label name with no punctuation.
11731@tab @code{%l0}
11732@end multitable
11733
8cfc2804
AC
11734@anchor{aarch64Operandmodifiers}
11735@subsubsection AArch64 Operand Modifiers
11736
11737The following table shows the modifiers supported by AArch64 and their effects:
11738
11739@multitable @columnfractions .10 .90
11740@headitem Modifier @tab Description
11741@item @code{w} @tab Print a 32-bit general-purpose register name or, given a
11742constant zero operand, the 32-bit zero register (@code{wzr}).
11743@item @code{x} @tab Print a 64-bit general-purpose register name or, given a
11744constant zero operand, the 64-bit zero register (@code{xzr}).
11745@item @code{b} @tab Print an FP/SIMD register name with a @code{b} (byte, 8-bit)
11746prefix.
11747@item @code{h} @tab Print an FP/SIMD register name with an @code{h} (halfword,
1174816-bit) prefix.
11749@item @code{s} @tab Print an FP/SIMD register name with an @code{s} (single
11750word, 32-bit) prefix.
11751@item @code{d} @tab Print an FP/SIMD register name with a @code{d} (doubleword,
1175264-bit) prefix.
11753@item @code{q} @tab Print an FP/SIMD register name with a @code{q} (quadword,
11754128-bit) prefix.
11755@item @code{Z} @tab Print an FP/SIMD register name as an SVE register (i.e. with
11756a @code{z} prefix). This is a no-op for SVE register operands.
11757@end multitable
11758
d77de738
ML
11759@anchor{x86Operandmodifiers}
11760@subsubsection x86 Operand Modifiers
11761
11762References to input, output, and goto operands in the assembler template
11763of extended @code{asm} statements can use
11764modifiers to affect the way the operands are formatted in
11765the code output to the assembler. For example, the
11766following code uses the @samp{h} and @samp{b} modifiers for x86:
11767
11768@example
11769uint16_t num;
11770asm volatile ("xchg %h0, %b0" : "+a" (num) );
11771@end example
11772
11773@noindent
11774These modifiers generate this assembler code:
11775
11776@example
11777xchg %ah, %al
11778@end example
11779
11780The rest of this discussion uses the following code for illustrative purposes.
11781
11782@example
11783int main()
11784@{
11785 int iInt = 1;
11786
11787top:
11788
11789 asm volatile goto ("some assembler instructions here"
11790 : /* No outputs. */
11791 : "q" (iInt), "X" (sizeof(unsigned char) + 1), "i" (42)
11792 : /* No clobbers. */
11793 : top);
11794@}
11795@end example
11796
11797With no modifiers, this is what the output from the operands would be
11798for the @samp{att} and @samp{intel} dialects of assembler:
11799
11800@multitable {Operand} {$.L2} {OFFSET FLAT:.L2}
11801@headitem Operand @tab @samp{att} @tab @samp{intel}
11802@item @code{%0}
11803@tab @code{%eax}
11804@tab @code{eax}
11805@item @code{%1}
11806@tab @code{$2}
11807@tab @code{2}
11808@item @code{%3}
11809@tab @code{$.L3}
11810@tab @code{OFFSET FLAT:.L3}
11811@item @code{%4}
11812@tab @code{$8}
11813@tab @code{8}
11814@item @code{%5}
11815@tab @code{%xmm0}
11816@tab @code{xmm0}
11817@item @code{%7}
11818@tab @code{$0}
11819@tab @code{0}
11820@end multitable
11821
11822The table below shows the list of supported modifiers and their effects.
11823
11824@multitable {Modifier} {Print the opcode suffix for the size of th} {Operand} {@samp{att}} {@samp{intel}}
11825@headitem Modifier @tab Description @tab Operand @tab @samp{att} @tab @samp{intel}
11826@item @code{A}
11827@tab Print an absolute memory reference.
11828@tab @code{%A0}
11829@tab @code{*%rax}
11830@tab @code{rax}
11831@item @code{b}
11832@tab Print the QImode name of the register.
11833@tab @code{%b0}
11834@tab @code{%al}
11835@tab @code{al}
11836@item @code{B}
11837@tab print the opcode suffix of b.
11838@tab @code{%B0}
11839@tab @code{b}
11840@tab
11841@item @code{c}
11842@tab Require a constant operand and print the constant expression with no punctuation.
11843@tab @code{%c1}
11844@tab @code{2}
11845@tab @code{2}
11846@item @code{d}
11847@tab print duplicated register operand for AVX instruction.
11848@tab @code{%d5}
11849@tab @code{%xmm0, %xmm0}
11850@tab @code{xmm0, xmm0}
11851@item @code{E}
11852@tab Print the address in Double Integer (DImode) mode (8 bytes) when the target is 64-bit.
11853Otherwise mode is unspecified (VOIDmode).
11854@tab @code{%E1}
11855@tab @code{%(rax)}
11856@tab @code{[rax]}
11857@item @code{g}
11858@tab Print the V16SFmode name of the register.
11859@tab @code{%g0}
11860@tab @code{%zmm0}
11861@tab @code{zmm0}
11862@item @code{h}
11863@tab Print the QImode name for a ``high'' register.
11864@tab @code{%h0}
11865@tab @code{%ah}
11866@tab @code{ah}
11867@item @code{H}
11868@tab Add 8 bytes to an offsettable memory reference. Useful when accessing the
11869high 8 bytes of SSE values. For a memref in (%rax), it generates
11870@tab @code{%H0}
11871@tab @code{8(%rax)}
11872@tab @code{8[rax]}
11873@item @code{k}
11874@tab Print the SImode name of the register.
11875@tab @code{%k0}
11876@tab @code{%eax}
11877@tab @code{eax}
11878@item @code{l}
11879@tab Print the label name with no punctuation.
11880@tab @code{%l3}
11881@tab @code{.L3}
11882@tab @code{.L3}
11883@item @code{L}
11884@tab print the opcode suffix of l.
11885@tab @code{%L0}
11886@tab @code{l}
11887@tab
11888@item @code{N}
11889@tab print maskz.
11890@tab @code{%N7}
11891@tab @code{@{z@}}
11892@tab @code{@{z@}}
11893@item @code{p}
11894@tab Print raw symbol name (without syntax-specific prefixes).
11895@tab @code{%p2}
11896@tab @code{42}
11897@tab @code{42}
11898@item @code{P}
11899@tab If used for a function, print the PLT suffix and generate PIC code.
11900For example, emit @code{foo@@PLT} instead of 'foo' for the function
11901foo(). If used for a constant, drop all syntax-specific prefixes and
11902issue the bare constant. See @code{p} above.
11903@item @code{q}
11904@tab Print the DImode name of the register.
11905@tab @code{%q0}
11906@tab @code{%rax}
11907@tab @code{rax}
11908@item @code{Q}
11909@tab print the opcode suffix of q.
11910@tab @code{%Q0}
11911@tab @code{q}
11912@tab
11913@item @code{R}
11914@tab print embedded rounding and sae.
11915@tab @code{%R4}
11916@tab @code{@{rn-sae@}, }
11917@tab @code{, @{rn-sae@}}
11918@item @code{r}
11919@tab print only sae.
11920@tab @code{%r4}
11921@tab @code{@{sae@}, }
11922@tab @code{, @{sae@}}
11923@item @code{s}
11924@tab print a shift double count, followed by the assemblers argument
11925delimiterprint the opcode suffix of s.
11926@tab @code{%s1}
11927@tab @code{$2, }
11928@tab @code{2, }
11929@item @code{S}
11930@tab print the opcode suffix of s.
11931@tab @code{%S0}
11932@tab @code{s}
11933@tab
11934@item @code{t}
11935@tab print the V8SFmode name of the register.
11936@tab @code{%t5}
11937@tab @code{%ymm0}
11938@tab @code{ymm0}
11939@item @code{T}
11940@tab print the opcode suffix of t.
11941@tab @code{%T0}
11942@tab @code{t}
11943@tab
11944@item @code{V}
11945@tab print naked full integer register name without %.
11946@tab @code{%V0}
11947@tab @code{eax}
11948@tab @code{eax}
11949@item @code{w}
11950@tab Print the HImode name of the register.
11951@tab @code{%w0}
11952@tab @code{%ax}
11953@tab @code{ax}
11954@item @code{W}
11955@tab print the opcode suffix of w.
11956@tab @code{%W0}
11957@tab @code{w}
11958@tab
11959@item @code{x}
11960@tab print the V4SFmode name of the register.
11961@tab @code{%x5}
11962@tab @code{%xmm0}
11963@tab @code{xmm0}
11964@item @code{y}
11965@tab print "st(0)" instead of "st" as a register.
11966@tab @code{%y6}
11967@tab @code{%st(0)}
11968@tab @code{st(0)}
11969@item @code{z}
11970@tab Print the opcode suffix for the size of the current integer operand (one of @code{b}/@code{w}/@code{l}/@code{q}).
11971@tab @code{%z0}
11972@tab @code{l}
11973@tab
11974@item @code{Z}
11975@tab Like @code{z}, with special suffixes for x87 instructions.
11976@end multitable
11977
11978
11979@anchor{x86floatingpointasmoperands}
11980@subsubsection x86 Floating-Point @code{asm} Operands
11981
11982On x86 targets, there are several rules on the usage of stack-like registers
11983in the operands of an @code{asm}. These rules apply only to the operands
11984that are stack-like registers:
11985
11986@enumerate
11987@item
11988Given a set of input registers that die in an @code{asm}, it is
11989necessary to know which are implicitly popped by the @code{asm}, and
11990which must be explicitly popped by GCC@.
11991
11992An input register that is implicitly popped by the @code{asm} must be
11993explicitly clobbered, unless it is constrained to match an
11994output operand.
11995
11996@item
11997For any input register that is implicitly popped by an @code{asm}, it is
11998necessary to know how to adjust the stack to compensate for the pop.
11999If any non-popped input is closer to the top of the reg-stack than
12000the implicitly popped register, it would not be possible to know what the
12001stack looked like---it's not clear how the rest of the stack ``slides
12002up''.
12003
12004All implicitly popped input registers must be closer to the top of
12005the reg-stack than any input that is not implicitly popped.
12006
12007It is possible that if an input dies in an @code{asm}, the compiler might
12008use the input register for an output reload. Consider this example:
12009
12010@smallexample
12011asm ("foo" : "=t" (a) : "f" (b));
12012@end smallexample
12013
12014@noindent
12015This code says that input @code{b} is not popped by the @code{asm}, and that
12016the @code{asm} pushes a result onto the reg-stack, i.e., the stack is one
12017deeper after the @code{asm} than it was before. But, it is possible that
12018reload may think that it can use the same register for both the input and
12019the output.
12020
12021To prevent this from happening,
12022if any input operand uses the @samp{f} constraint, all output register
12023constraints must use the @samp{&} early-clobber modifier.
12024
12025The example above is correctly written as:
12026
12027@smallexample
12028asm ("foo" : "=&t" (a) : "f" (b));
12029@end smallexample
12030
12031@item
12032Some operands need to be in particular places on the stack. All
12033output operands fall in this category---GCC has no other way to
12034know which registers the outputs appear in unless you indicate
12035this in the constraints.
12036
12037Output operands must specifically indicate which register an output
12038appears in after an @code{asm}. @samp{=f} is not allowed: the operand
12039constraints must select a class with a single register.
12040
12041@item
12042Output operands may not be ``inserted'' between existing stack registers.
12043Since no 387 opcode uses a read/write operand, all output operands
12044are dead before the @code{asm}, and are pushed by the @code{asm}.
12045It makes no sense to push anywhere but the top of the reg-stack.
12046
12047Output operands must start at the top of the reg-stack: output
12048operands may not ``skip'' a register.
12049
12050@item
12051Some @code{asm} statements may need extra stack space for internal
12052calculations. This can be guaranteed by clobbering stack registers
12053unrelated to the inputs and outputs.
12054
12055@end enumerate
12056
12057This @code{asm}
12058takes one input, which is internally popped, and produces two outputs.
12059
12060@smallexample
12061asm ("fsincos" : "=t" (cos), "=u" (sin) : "0" (inp));
12062@end smallexample
12063
12064@noindent
12065This @code{asm} takes two inputs, which are popped by the @code{fyl2xp1} opcode,
12066and replaces them with one output. The @code{st(1)} clobber is necessary
12067for the compiler to know that @code{fyl2xp1} pops both inputs.
12068
12069@smallexample
12070asm ("fyl2xp1" : "=t" (result) : "0" (x), "u" (y) : "st(1)");
12071@end smallexample
12072
12073@anchor{msp430Operandmodifiers}
12074@subsubsection MSP430 Operand Modifiers
12075
12076The list below describes the supported modifiers and their effects for MSP430.
12077
12078@multitable @columnfractions .10 .90
12079@headitem Modifier @tab Description
12080@item @code{A} @tab Select low 16-bits of the constant/register/memory operand.
12081@item @code{B} @tab Select high 16-bits of the constant/register/memory
12082operand.
12083@item @code{C} @tab Select bits 32-47 of the constant/register/memory operand.
12084@item @code{D} @tab Select bits 48-63 of the constant/register/memory operand.
12085@item @code{H} @tab Equivalent to @code{B} (for backwards compatibility).
12086@item @code{I} @tab Print the inverse (logical @code{NOT}) of the constant
12087value.
12088@item @code{J} @tab Print an integer without a @code{#} prefix.
12089@item @code{L} @tab Equivalent to @code{A} (for backwards compatibility).
12090@item @code{O} @tab Offset of the current frame from the top of the stack.
12091@item @code{Q} @tab Use the @code{A} instruction postfix.
12092@item @code{R} @tab Inverse of condition code, for unsigned comparisons.
12093@item @code{W} @tab Subtract 16 from the constant value.
12094@item @code{X} @tab Use the @code{X} instruction postfix.
12095@item @code{Y} @tab Subtract 4 from the constant value.
12096@item @code{Z} @tab Subtract 1 from the constant value.
12097@item @code{b} @tab Append @code{.B}, @code{.W} or @code{.A} to the
12098instruction, depending on the mode.
12099@item @code{d} @tab Offset 1 byte of a memory reference or constant value.
12100@item @code{e} @tab Offset 3 bytes of a memory reference or constant value.
12101@item @code{f} @tab Offset 5 bytes of a memory reference or constant value.
12102@item @code{g} @tab Offset 7 bytes of a memory reference or constant value.
12103@item @code{p} @tab Print the value of 2, raised to the power of the given
12104constant. Used to select the specified bit position.
12105@item @code{r} @tab Inverse of condition code, for signed comparisons.
12106@item @code{x} @tab Equivialent to @code{X}, but only for pointers.
12107@end multitable
12108
b5ea0f07
LC
12109@anchor{loongarchOperandmodifiers}
12110@subsubsection LoongArch Operand Modifiers
12111
12112The list below describes the supported modifiers and their effects for LoongArch.
12113
12114@multitable @columnfractions .10 .90
12115@headitem Modifier @tab Description
12116@item @code{d} @tab Same as @code{c}.
12117@item @code{i} @tab Print the character ''@code{i}'' if the operand is not a register.
12118@item @code{m} @tab Same as @code{c}, but the printed value is @code{operand - 1}.
5bd5ef99 12119@item @code{u} @tab Print a LASX register.
12120@item @code{w} @tab Print a LSX register.
b5ea0f07
LC
12121@item @code{X} @tab Print a constant integer operand in hexadecimal.
12122@item @code{z} @tab Print the operand in its unmodified form, followed by a comma.
12123@end multitable
12124
5bd5ef99 12125References to input and output operands in the assembler template of extended
12126asm statements can use modifiers to affect the way the operands are formatted
12127in the code output to the assembler. For example, the following code uses the
12128'w' modifier for LoongArch:
12129
12130@example
12131test-asm.c:
12132
12133#include <lsxintrin.h>
12134
12135__m128i foo (void)
12136@{
12137__m128i a,b,c;
12138__asm__ ("vadd.d %w0,%w1,%w2\n\t"
12139 :"=f" (c)
12140 :"f" (a),"f" (b));
12141
12142return c;
12143@}
12144
12145@end example
12146
12147@noindent
12148The compile command for the test case is as follows:
12149
12150@example
12151gcc test-asm.c -mlsx -S -o test-asm.s
12152@end example
12153
12154@noindent
12155The assembly statement produces the following assembly code:
12156
12157@example
12158vadd.d $vr0,$vr0,$vr1
12159@end example
12160
12161This is a 128-bit vector addition instruction, @code{c} (referred to in the
12162template string as %0) is the output, and @code{a} (%1) and @code{b} (%2) are
12163the inputs. @code{__m128i} is a vector data type defined in the file
12164@code{lsxintrin.h} (@xref{LoongArch SX Vector Intrinsics}). The symbol '=f'
12165represents a constraint using a floating-point register as an output type, and
12166the 'f' in the input operand represents a constraint using a floating-point
12167register operand, which can refer to the definition of a constraint
12168(@xref{Constraints}) in gcc.
12169
1e2e5713
KC
12170@anchor{riscvOperandmodifiers}
12171@subsubsection RISC-V Operand Modifiers
12172
12173The list below describes the supported modifiers and their effects for RISC-V.
12174
12175@multitable @columnfractions .10 .90
12176@headitem Modifier @tab Description
12177@item @code{z} @tab Print ''@code{zero}'' instead of 0 if the operand is an immediate with a value of zero.
12178@item @code{i} @tab Print the character ''@code{i}'' if the operand is an immediate.
12179@end multitable
b5ea0f07 12180
d77de738
ML
12181@lowersections
12182@include md.texi
12183@raisesections
12184
12185@node Asm Labels
12186@subsection Controlling Names Used in Assembler Code
12187@cindex assembler names for identifiers
12188@cindex names used in assembler code
12189@cindex identifiers, names in assembler code
12190
12191You can specify the name to be used in the assembler code for a C
12192function or variable by writing the @code{asm} (or @code{__asm__})
12193keyword after the declarator.
12194It is up to you to make sure that the assembler names you choose do not
12195conflict with any other assembler symbols, or reference registers.
12196
12197@subsubheading Assembler names for data
12198
12199This sample shows how to specify the assembler name for data:
12200
12201@smallexample
12202int foo asm ("myfoo") = 2;
12203@end smallexample
12204
12205@noindent
12206This specifies that the name to be used for the variable @code{foo} in
12207the assembler code should be @samp{myfoo} rather than the usual
12208@samp{_foo}.
12209
12210On systems where an underscore is normally prepended to the name of a C
12211variable, this feature allows you to define names for the
12212linker that do not start with an underscore.
12213
12214GCC does not support using this feature with a non-static local variable
12215since such variables do not have assembler names. If you are
12216trying to put the variable in a particular register, see
12217@ref{Explicit Register Variables}.
12218
12219@subsubheading Assembler names for functions
12220
12221To specify the assembler name for functions, write a declaration for the
12222function before its definition and put @code{asm} there, like this:
12223
12224@smallexample
12225int func (int x, int y) asm ("MYFUNC");
12226
12227int func (int x, int y)
12228@{
12229 /* @r{@dots{}} */
12230@end smallexample
12231
12232@noindent
12233This specifies that the name to be used for the function @code{func} in
12234the assembler code should be @code{MYFUNC}.
12235
12236@node Explicit Register Variables
12237@subsection Variables in Specified Registers
12238@anchor{Explicit Reg Vars}
12239@cindex explicit register variables
12240@cindex variables in specified registers
12241@cindex specified registers
12242
12243GNU C allows you to associate specific hardware registers with C
12244variables. In almost all cases, allowing the compiler to assign
12245registers produces the best code. However under certain unusual
12246circumstances, more precise control over the variable storage is
12247required.
12248
12249Both global and local variables can be associated with a register. The
12250consequences of performing this association are very different between
12251the two, as explained in the sections below.
12252
12253@menu
12254* Global Register Variables:: Variables declared at global scope.
12255* Local Register Variables:: Variables declared within a function.
12256@end menu
12257
12258@node Global Register Variables
12259@subsubsection Defining Global Register Variables
12260@anchor{Global Reg Vars}
12261@cindex global register variables
12262@cindex registers, global variables in
12263@cindex registers, global allocation
12264
12265You can define a global register variable and associate it with a specified
12266register like this:
12267
12268@smallexample
12269register int *foo asm ("r12");
12270@end smallexample
12271
12272@noindent
12273Here @code{r12} is the name of the register that should be used. Note that
12274this is the same syntax used for defining local register variables, but for
12275a global variable the declaration appears outside a function. The
12276@code{register} keyword is required, and cannot be combined with
12277@code{static}. The register name must be a valid register name for the
12278target platform.
12279
12280Do not use type qualifiers such as @code{const} and @code{volatile}, as
12281the outcome may be contrary to expectations. In particular, using the
12282@code{volatile} qualifier does not fully prevent the compiler from
12283optimizing accesses to the register.
12284
12285Registers are a scarce resource on most systems and allowing the
12286compiler to manage their usage usually results in the best code. However,
12287under special circumstances it can make sense to reserve some globally.
12288For example this may be useful in programs such as programming language
12289interpreters that have a couple of global variables that are accessed
12290very often.
12291
12292After defining a global register variable, for the current compilation
12293unit:
12294
12295@itemize @bullet
12296@item If the register is a call-saved register, call ABI is affected:
12297the register will not be restored in function epilogue sequences after
12298the variable has been assigned. Therefore, functions cannot safely
12299return to callers that assume standard ABI.
12300@item Conversely, if the register is a call-clobbered register, making
12301calls to functions that use standard ABI may lose contents of the variable.
12302Such calls may be created by the compiler even if none are evident in
12303the original program, for example when libgcc functions are used to
12304make up for unavailable instructions.
12305@item Accesses to the variable may be optimized as usual and the register
12306remains available for allocation and use in any computations, provided that
12307observable values of the variable are not affected.
12308@item If the variable is referenced in inline assembly, the type of access
12309must be provided to the compiler via constraints (@pxref{Constraints}).
12310Accesses from basic asms are not supported.
12311@end itemize
12312
12313Note that these points @emph{only} apply to code that is compiled with the
12314definition. The behavior of code that is merely linked in (for example
12315code from libraries) is not affected.
12316
12317If you want to recompile source files that do not actually use your global
12318register variable so they do not use the specified register for any other
12319purpose, you need not actually add the global register declaration to
12320their source code. It suffices to specify the compiler option
12321@option{-ffixed-@var{reg}} (@pxref{Code Gen Options}) to reserve the
12322register.
12323
12324@subsubheading Declaring the variable
12325
12326Global register variables cannot have initial values, because an
12327executable file has no means to supply initial contents for a register.
12328
12329When selecting a register, choose one that is normally saved and
12330restored by function calls on your machine. This ensures that code
12331which is unaware of this reservation (such as library routines) will
12332restore it before returning.
12333
12334On machines with register windows, be sure to choose a global
12335register that is not affected magically by the function call mechanism.
12336
12337@subsubheading Using the variable
12338
12339@cindex @code{qsort}, and global register variables
12340When calling routines that are not aware of the reservation, be
12341cautious if those routines call back into code which uses them. As an
12342example, if you call the system library version of @code{qsort}, it may
12343clobber your registers during execution, but (if you have selected
12344appropriate registers) it will restore them before returning. However
12345it will @emph{not} restore them before calling @code{qsort}'s comparison
12346function. As a result, global values will not reliably be available to
12347the comparison function unless the @code{qsort} function itself is rebuilt.
12348
12349Similarly, it is not safe to access the global register variables from signal
12350handlers or from more than one thread of control. Unless you recompile
12351them specially for the task at hand, the system library routines may
12352temporarily use the register for other things. Furthermore, since the register
12353is not reserved exclusively for the variable, accessing it from handlers of
12354asynchronous signals may observe unrelated temporary values residing in the
12355register.
12356
12357@cindex register variable after @code{longjmp}
12358@cindex global register after @code{longjmp}
12359@cindex value after @code{longjmp}
12360@findex longjmp
12361@findex setjmp
12362On most machines, @code{longjmp} restores to each global register
12363variable the value it had at the time of the @code{setjmp}. On some
12364machines, however, @code{longjmp} does not change the value of global
12365register variables. To be portable, the function that called @code{setjmp}
12366should make other arrangements to save the values of the global register
12367variables, and to restore them in a @code{longjmp}. This way, the same
12368thing happens regardless of what @code{longjmp} does.
12369
12370@node Local Register Variables
12371@subsubsection Specifying Registers for Local Variables
12372@anchor{Local Reg Vars}
12373@cindex local variables, specifying registers
12374@cindex specifying registers for local variables
12375@cindex registers for local variables
12376
12377You can define a local register variable and associate it with a specified
12378register like this:
12379
12380@smallexample
12381register int *foo asm ("r12");
12382@end smallexample
12383
12384@noindent
12385Here @code{r12} is the name of the register that should be used. Note
12386that this is the same syntax used for defining global register variables,
12387but for a local variable the declaration appears within a function. The
12388@code{register} keyword is required, and cannot be combined with
12389@code{static}. The register name must be a valid register name for the
12390target platform.
12391
12392Do not use type qualifiers such as @code{const} and @code{volatile}, as
12393the outcome may be contrary to expectations. In particular, when the
12394@code{const} qualifier is used, the compiler may substitute the
12395variable with its initializer in @code{asm} statements, which may cause
12396the corresponding operand to appear in a different register.
12397
12398As with global register variables, it is recommended that you choose
12399a register that is normally saved and restored by function calls on your
12400machine, so that calls to library routines will not clobber it.
12401
12402The only supported use for this feature is to specify registers
12403for input and output operands when calling Extended @code{asm}
12404(@pxref{Extended Asm}). This may be necessary if the constraints for a
12405particular machine don't provide sufficient control to select the desired
12406register. To force an operand into a register, create a local variable
12407and specify the register name after the variable's declaration. Then use
12408the local variable for the @code{asm} operand and specify any constraint
12409letter that matches the register:
12410
12411@smallexample
12412register int *p1 asm ("r0") = @dots{};
12413register int *p2 asm ("r1") = @dots{};
12414register int *result asm ("r0");
12415asm ("sysint" : "=r" (result) : "0" (p1), "r" (p2));
12416@end smallexample
12417
12418@emph{Warning:} In the above example, be aware that a register (for example
12419@code{r0}) can be call-clobbered by subsequent code, including function
12420calls and library calls for arithmetic operators on other variables (for
12421example the initialization of @code{p2}). In this case, use temporary
12422variables for expressions between the register assignments:
12423
12424@smallexample
12425int t1 = @dots{};
12426register int *p1 asm ("r0") = @dots{};
12427register int *p2 asm ("r1") = t1;
12428register int *result asm ("r0");
12429asm ("sysint" : "=r" (result) : "0" (p1), "r" (p2));
12430@end smallexample
12431
12432Defining a register variable does not reserve the register. Other than
12433when invoking the Extended @code{asm}, the contents of the specified
12434register are not guaranteed. For this reason, the following uses
12435are explicitly @emph{not} supported. If they appear to work, it is only
12436happenstance, and may stop working as intended due to (seemingly)
12437unrelated changes in surrounding code, or even minor changes in the
12438optimization of a future version of gcc:
12439
12440@itemize @bullet
12441@item Passing parameters to or from Basic @code{asm}
12442@item Passing parameters to or from Extended @code{asm} without using input
12443or output operands.
12444@item Passing parameters to or from routines written in assembler (or
12445other languages) using non-standard calling conventions.
12446@end itemize
12447
12448Some developers use Local Register Variables in an attempt to improve
12449gcc's allocation of registers, especially in large functions. In this
12450case the register name is essentially a hint to the register allocator.
12451While in some instances this can generate better code, improvements are
12452subject to the whims of the allocator/optimizers. Since there are no
12453guarantees that your improvements won't be lost, this usage of Local
12454Register Variables is discouraged.
12455
12456On the MIPS platform, there is related use for local register variables
12457with slightly different characteristics (@pxref{MIPS Coprocessors,,
12458Defining coprocessor specifics for MIPS targets, gccint,
12459GNU Compiler Collection (GCC) Internals}).
12460
12461@node Size of an asm
12462@subsection Size of an @code{asm}
12463
12464Some targets require that GCC track the size of each instruction used
12465in order to generate correct code. Because the final length of the
12466code produced by an @code{asm} statement is only known by the
12467assembler, GCC must make an estimate as to how big it will be. It
12468does this by counting the number of instructions in the pattern of the
12469@code{asm} and multiplying that by the length of the longest
12470instruction supported by that processor. (When working out the number
12471of instructions, it assumes that any occurrence of a newline or of
12472whatever statement separator character is supported by the assembler ---
12473typically @samp{;} --- indicates the end of an instruction.)
12474
12475Normally, GCC's estimate is adequate to ensure that correct
12476code is generated, but it is possible to confuse the compiler if you use
12477pseudo instructions or assembler macros that expand into multiple real
12478instructions, or if you use assembler directives that expand to more
12479space in the object file than is needed for a single instruction.
12480If this happens then the assembler may produce a diagnostic saying that
12481a label is unreachable.
12482
12483@cindex @code{asm inline}
12484This size is also used for inlining decisions. If you use @code{asm inline}
12485instead of just @code{asm}, then for inlining purposes the size of the asm
12486is taken as the minimum size, ignoring how many instructions GCC thinks it is.
12487
12488@node Alternate Keywords
12489@section Alternate Keywords
12490@cindex alternate keywords
12491@cindex keywords, alternate
12492
12493@option{-ansi} and the various @option{-std} options disable certain
12494keywords. This causes trouble when you want to use GNU C extensions, or
12495a general-purpose header file that should be usable by all programs,
12496including ISO C programs. The keywords @code{asm}, @code{typeof} and
12497@code{inline} are not available in programs compiled with
12498@option{-ansi} or @option{-std} (although @code{inline} can be used in a
12499program compiled with @option{-std=c99} or a later standard). The
12500ISO C99 keyword
12501@code{restrict} is only available when @option{-std=gnu99} (which will
12502eventually be the default) or @option{-std=c99} (or the equivalent
12503@option{-std=iso9899:1999}), or an option for a later standard
12504version, is used.
12505
12506The way to solve these problems is to put @samp{__} at the beginning and
12507end of each problematical keyword. For example, use @code{__asm__}
12508instead of @code{asm}, and @code{__inline__} instead of @code{inline}.
12509
12510Other C compilers won't accept these alternative keywords; if you want to
12511compile with another compiler, you can define the alternate keywords as
12512macros to replace them with the customary keywords. It looks like this:
12513
12514@smallexample
12515#ifndef __GNUC__
12516#define __asm__ asm
12517#endif
12518@end smallexample
12519
12520@findex __extension__
12521@opindex pedantic
12522@option{-pedantic} and other options cause warnings for many GNU C extensions.
207a5daa
RS
12523You can suppress such warnings using the keyword @code{__extension__}.
12524Specifically:
12525
12526@itemize @bullet
12527@item
12528Writing @code{__extension__} before an expression prevents warnings
12529about extensions within that expression.
12530
12531@item
12532In C, writing:
12533
12534@smallexample
12535[[__extension__ @dots{}]]
12536@end smallexample
12537
12538suppresses warnings about using @samp{[[]]} attributes in C versions
094a609c 12539that predate C23@. Since the scope token @samp{::} is not a single
207a5daa
RS
12540lexing token in earlier versions of C, this construct also allows two colons
12541to be used in place of @code{::}. GCC does not check whether the two
12542colons are immediately adjacent.
12543@end itemize
12544
12545@code{__extension__} has no effect aside from this.
d77de738
ML
12546
12547@node Incomplete Enums
12548@section Incomplete @code{enum} Types
12549
12550You can define an @code{enum} tag without specifying its possible values.
12551This results in an incomplete type, much like what you get if you write
12552@code{struct foo} without describing the elements. A later declaration
12553that does specify the possible values completes the type.
12554
12555You cannot allocate variables or storage using the type while it is
12556incomplete. However, you can work with pointers to that type.
12557
12558This extension may not be very useful, but it makes the handling of
12559@code{enum} more consistent with the way @code{struct} and @code{union}
12560are handled.
12561
12562This extension is not supported by GNU C++.
12563
12564@node Function Names
12565@section Function Names as Strings
12566@cindex @code{__func__} identifier
12567@cindex @code{__FUNCTION__} identifier
12568@cindex @code{__PRETTY_FUNCTION__} identifier
12569
12570GCC provides three magic constants that hold the name of the current
12571function as a string. In C++11 and later modes, all three are treated
12572as constant expressions and can be used in @code{constexpr} constexts.
12573The first of these constants is @code{__func__}, which is part of
12574the C99 standard:
12575
12576The identifier @code{__func__} is implicitly declared by the translator
12577as if, immediately following the opening brace of each function
12578definition, the declaration
12579
12580@smallexample
12581static const char __func__[] = "function-name";
12582@end smallexample
12583
12584@noindent
12585appeared, where function-name is the name of the lexically-enclosing
12586function. This name is the unadorned name of the function. As an
12587extension, at file (or, in C++, namespace scope), @code{__func__}
12588evaluates to the empty string.
12589
12590@code{__FUNCTION__} is another name for @code{__func__}, provided for
12591backward compatibility with old versions of GCC.
12592
12593In C, @code{__PRETTY_FUNCTION__} is yet another name for
12594@code{__func__}, except that at file scope (or, in C++, namespace scope),
12595it evaluates to the string @code{"top level"}. In addition, in C++,
12596@code{__PRETTY_FUNCTION__} contains the signature of the function as
12597well as its bare name. For example, this program:
12598
12599@smallexample
12600extern "C" int printf (const char *, ...);
12601
12602class a @{
12603 public:
12604 void sub (int i)
12605 @{
12606 printf ("__FUNCTION__ = %s\n", __FUNCTION__);
12607 printf ("__PRETTY_FUNCTION__ = %s\n", __PRETTY_FUNCTION__);
12608 @}
12609@};
12610
12611int
12612main (void)
12613@{
12614 a ax;
12615 ax.sub (0);
12616 return 0;
12617@}
12618@end smallexample
12619
12620@noindent
12621gives this output:
12622
12623@smallexample
12624__FUNCTION__ = sub
12625__PRETTY_FUNCTION__ = void a::sub(int)
12626@end smallexample
12627
12628These identifiers are variables, not preprocessor macros, and may not
12629be used to initialize @code{char} arrays or be concatenated with string
12630literals.
12631
12632@node Return Address
12633@section Getting the Return or Frame Address of a Function
12634
12635These functions may be used to get information about the callers of a
12636function.
12637
f25efe50 12638@defbuiltin{{void *} __builtin_return_address (unsigned int @var{level})}
d77de738
ML
12639This function returns the return address of the current function, or of
12640one of its callers. The @var{level} argument is number of frames to
12641scan up the call stack. A value of @code{0} yields the return address
12642of the current function, a value of @code{1} yields the return address
12643of the caller of the current function, and so forth. When inlining
12644the expected behavior is that the function returns the address of
12645the function that is returned to. To work around this behavior use
12646the @code{noinline} function attribute.
12647
12648The @var{level} argument must be a constant integer.
12649
12650On some machines it may be impossible to determine the return address of
12651any function other than the current one; in such cases, or when the top
12652of the stack has been reached, this function returns an unspecified
12653value. In addition, @code{__builtin_frame_address} may be used
12654to determine if the top of the stack has been reached.
12655
12656Additional post-processing of the returned value may be needed, see
12657@code{__builtin_extract_return_addr}.
12658
12659The stored representation of the return address in memory may be different
12660from the address returned by @code{__builtin_return_address}. For example,
12661on AArch64 the stored address may be mangled with return address signing
12662whereas the address returned by @code{__builtin_return_address} is not.
12663
12664Calling this function with a nonzero argument can have unpredictable
12665effects, including crashing the calling program. As a result, calls
12666that are considered unsafe are diagnosed when the @option{-Wframe-address}
12667option is in effect. Such calls should only be made in debugging
12668situations.
12669
12670On targets where code addresses are representable as @code{void *},
12671@smallexample
12672void *addr = __builtin_extract_return_addr (__builtin_return_address (0));
12673@end smallexample
12674gives the code address where the current function would return. For example,
12675such an address may be used with @code{dladdr} or other interfaces that work
12676with code addresses.
f25efe50 12677@enddefbuiltin
d77de738 12678
f25efe50 12679@defbuiltin{{void *} __builtin_extract_return_addr (void *@var{addr})}
d77de738
ML
12680The address as returned by @code{__builtin_return_address} may have to be fed
12681through this function to get the actual encoded address. For example, on the
1268231-bit S/390 platform the highest bit has to be masked out, or on SPARC
12683platforms an offset has to be added for the true next instruction to be
12684executed.
12685
12686If no fixup is needed, this function simply passes through @var{addr}.
f25efe50 12687@enddefbuiltin
d77de738 12688
f25efe50 12689@defbuiltin{{void *} __builtin_frob_return_addr (void *@var{addr})}
d77de738 12690This function does the reverse of @code{__builtin_extract_return_addr}.
f25efe50 12691@enddefbuiltin
d77de738 12692
f25efe50 12693@defbuiltin{{void *} __builtin_frame_address (unsigned int @var{level})}
d77de738
ML
12694This function is similar to @code{__builtin_return_address}, but it
12695returns the address of the function frame rather than the return address
12696of the function. Calling @code{__builtin_frame_address} with a value of
12697@code{0} yields the frame address of the current function, a value of
12698@code{1} yields the frame address of the caller of the current function,
12699and so forth.
12700
12701The frame is the area on the stack that holds local variables and saved
12702registers. The frame address is normally the address of the first word
12703pushed on to the stack by the function. However, the exact definition
12704depends upon the processor and the calling convention. If the processor
12705has a dedicated frame pointer register, and the function has a frame,
12706then @code{__builtin_frame_address} returns the value of the frame
12707pointer register.
12708
12709On some machines it may be impossible to determine the frame address of
12710any function other than the current one; in such cases, or when the top
12711of the stack has been reached, this function returns @code{0} if
12712the first frame pointer is properly initialized by the startup code.
12713
12714Calling this function with a nonzero argument can have unpredictable
12715effects, including crashing the calling program. As a result, calls
12716that are considered unsafe are diagnosed when the @option{-Wframe-address}
12717option is in effect. Such calls should only be made in debugging
12718situations.
f25efe50 12719@enddefbuiltin
d77de738 12720
f0a90c7d 12721@deftypefn {Built-in Function} {void *} __builtin_stack_address ()
4e0a4673
AO
12722This function returns the stack pointer register, offset by
12723@code{STACK_POINTER_OFFSET}.
12724
12725Conceptually, the returned address returned by this built-in function is
12726the boundary between the stack area allocated for use by its caller, and
12727the area that could be modified by a function call, that the caller
12728could safely zero-out before or after (but not during) the call
12729sequence.
12730
12731Arguments for a callee may be preallocated as part of the caller's stack
12732frame, or allocated on a per-call basis, depending on the target, so
12733they may be on either side of this boundary.
12734
12735Even if the stack pointer is biased, the result is not. The register
12736save area on SPARC is regarded as modifiable by calls, rather than as
12737allocated for use by the caller function, since it is never in use while
12738the caller function itself is running.
12739
12740Red zones that only leaf functions could use are also regarded as
12741modifiable by calls, rather than as allocated for use by the caller.
12742This is only theoretical, since leaf functions do not issue calls, but a
12743constant offset makes this built-in function more predictable.
f0a90c7d
AO
12744@end deftypefn
12745
12746@node Stack Scrubbing
12747@section Stack scrubbing internal interfaces
12748
12749Stack scrubbing involves cooperation between a @code{strub} context,
12750i.e., a function whose stack frame is to be zeroed-out, and its callers.
12751The caller initializes a stack watermark, the @code{strub} context
12752updates the watermark according to its stack use, and the caller zeroes
12753it out once it regains control, whether by the callee's returning or by
12754an exception.
12755
12756Each of these steps is performed by a different builtin function call.
12757Calls to these builtins are introduced automatically, in response to
12758@code{strub} attributes and command-line options; they are not expected
12759to be explicitly called by source code.
12760
12761The functions that implement the builtins are available in libgcc but,
12762depending on optimization levels, they are expanded internally, adjusted
12763to account for inlining, and sometimes combined/deferred (e.g. passing
12764the caller-supplied watermark on to callees, refraining from erasing
12765stack areas that the caller will) to enable tail calls and to optimize
12766for code size.
12767
12768@deftypefn {Built-in Function} {void} __builtin___strub_enter (void **@var{wmptr})
12769This function initializes a stack @var{watermark} variable with the
12770current top of the stack. A call to this builtin function is introduced
12771before entering a @code{strub} context. It remains as a function call
12772if optimization is not enabled.
12773@end deftypefn
12774
12775@deftypefn {Built-in Function} {void} __builtin___strub_update (void **@var{wmptr})
12776This function updates a stack @var{watermark} variable with the current
12777top of the stack, if it tops the previous watermark. A call to this
12778builtin function is inserted within @code{strub} contexts, whenever
12779additional stack space may have been used. It remains as a function
12780call at optimization levels lower than 2.
12781@end deftypefn
12782
12783@deftypefn {Built-in Function} {void} __builtin___strub_leave (void **@var{wmptr})
12784This function overwrites the memory area between the current top of the
12785stack, and the @var{watermark}ed address. A call to this builtin
12786function is inserted after leaving a @code{strub} context. It remains
12787as a function call at optimization levels lower than 3, and it is guarded by
12788a condition at level 2.
12789@end deftypefn
12790
d77de738
ML
12791@node Vector Extensions
12792@section Using Vector Instructions through Built-in Functions
12793
12794On some targets, the instruction set contains SIMD vector instructions which
12795operate on multiple values contained in one large register at the same time.
12796For example, on the x86 the MMX, 3DNow!@: and SSE extensions can be used
12797this way.
12798
12799The first step in using these extensions is to provide the necessary data
12800types. This should be done using an appropriate @code{typedef}:
12801
12802@smallexample
12803typedef int v4si __attribute__ ((vector_size (16)));
12804@end smallexample
12805
12806@noindent
12807The @code{int} type specifies the @dfn{base type}, while the attribute specifies
12808the vector size for the variable, measured in bytes. For example, the
12809declaration above causes the compiler to set the mode for the @code{v4si}
12810type to be 16 bytes wide and divided into @code{int} sized units. For
12811a 32-bit @code{int} this means a vector of 4 units of 4 bytes, and the
12812corresponding mode of @code{foo} is @acronym{V4SI}.
12813
12814The @code{vector_size} attribute is only applicable to integral and
12815floating scalars, although arrays, pointers, and function return values
12816are allowed in conjunction with this construct. Only sizes that are
12817positive power-of-two multiples of the base type size are currently allowed.
12818
12819All the basic integer types can be used as base types, both as signed
12820and as unsigned: @code{char}, @code{short}, @code{int}, @code{long},
12821@code{long long}. In addition, @code{float} and @code{double} can be
12822used to build floating-point vector types.
12823
12824Specifying a combination that is not valid for the current architecture
12825causes GCC to synthesize the instructions using a narrower mode.
12826For example, if you specify a variable of type @code{V4SI} and your
12827architecture does not allow for this specific SIMD type, GCC
12828produces code that uses 4 @code{SIs}.
12829
12830The types defined in this manner can be used with a subset of normal C
12831operations. Currently, GCC allows using the following operators
12832on these types: @code{+, -, *, /, unary minus, ^, |, &, ~, %}@.
12833
12834The operations behave like C++ @code{valarrays}. Addition is defined as
12835the addition of the corresponding elements of the operands. For
12836example, in the code below, each of the 4 elements in @var{a} is
12837added to the corresponding 4 elements in @var{b} and the resulting
12838vector is stored in @var{c}.
12839
12840@smallexample
12841typedef int v4si __attribute__ ((vector_size (16)));
12842
12843v4si a, b, c;
12844
12845c = a + b;
12846@end smallexample
12847
12848Subtraction, multiplication, division, and the logical operations
12849operate in a similar manner. Likewise, the result of using the unary
12850minus or complement operators on a vector type is a vector whose
12851elements are the negative or complemented values of the corresponding
12852elements in the operand.
12853
12854It is possible to use shifting operators @code{<<}, @code{>>} on
12855integer-type vectors. The operation is defined as following: @code{@{a0,
12856a1, @dots{}, an@} >> @{b0, b1, @dots{}, bn@} == @{a0 >> b0, a1 >> b1,
9f926f3a
AM
12857@dots{}, an >> bn@}}@. Unlike OpenCL, values of @code{b} are not
12858implicitly taken modulo bit width of the base type @code{B}, and the behavior
12859is undefined if any @code{bi} is greater than or equal to @code{B}.
12860
12861In contrast to scalar operations in C and C++, operands of integer vector
12862operations do not undergo integer promotions.
12863
12864Operands of binary vector operations must have the same number of
d77de738
ML
12865elements.
12866
12867For convenience, it is allowed to use a binary vector operation
12868where one operand is a scalar. In that case the compiler transforms
12869the scalar operand into a vector where each element is the scalar from
12870the operation. The transformation happens only if the scalar could be
12871safely converted to the vector-element type.
12872Consider the following code.
12873
12874@smallexample
12875typedef int v4si __attribute__ ((vector_size (16)));
12876
12877v4si a, b, c;
12878long l;
12879
12880a = b + 1; /* a = b + @{1,1,1,1@}; */
12881a = 2 * b; /* a = @{2,2,2,2@} * b; */
12882
12883a = l + a; /* Error, cannot convert long to int. */
12884@end smallexample
12885
12886Vectors can be subscripted as if the vector were an array with
12887the same number of elements and base type. Out of bound accesses
12888invoke undefined behavior at run time. Warnings for out of bound
12889accesses for vector subscription can be enabled with
12890@option{-Warray-bounds}.
12891
12892Vector comparison is supported with standard comparison
12893operators: @code{==, !=, <, <=, >, >=}. Comparison operands can be
12894vector expressions of integer-type or real-type. Comparison between
12895integer-type vectors and real-type vectors are not supported. The
12896result of the comparison is a vector of the same width and number of
12897elements as the comparison operands with a signed integral element
12898type.
12899
12900Vectors are compared element-wise producing 0 when comparison is false
12901and -1 (constant of the appropriate type where all bits are set)
12902otherwise. Consider the following example.
12903
12904@smallexample
12905typedef int v4si __attribute__ ((vector_size (16)));
12906
12907v4si a = @{1,2,3,4@};
12908v4si b = @{3,2,1,4@};
12909v4si c;
12910
12911c = a > b; /* The result would be @{0, 0,-1, 0@} */
12912c = a == b; /* The result would be @{0,-1, 0,-1@} */
12913@end smallexample
12914
12915In C++, the ternary operator @code{?:} is available. @code{a?b:c}, where
12916@code{b} and @code{c} are vectors of the same type and @code{a} is an
12917integer vector with the same number of elements of the same size as @code{b}
12918and @code{c}, computes all three arguments and creates a vector
12919@code{@{a[0]?b[0]:c[0], a[1]?b[1]:c[1], @dots{}@}}. Note that unlike in
12920OpenCL, @code{a} is thus interpreted as @code{a != 0} and not @code{a < 0}.
12921As in the case of binary operations, this syntax is also accepted when
12922one of @code{b} or @code{c} is a scalar that is then transformed into a
12923vector. If both @code{b} and @code{c} are scalars and the type of
12924@code{true?b:c} has the same size as the element type of @code{a}, then
12925@code{b} and @code{c} are converted to a vector type whose elements have
12926this type and with the same number of elements as @code{a}.
12927
12928In C++, the logic operators @code{!, &&, ||} are available for vectors.
12929@code{!v} is equivalent to @code{v == 0}, @code{a && b} is equivalent to
12930@code{a!=0 & b!=0} and @code{a || b} is equivalent to @code{a!=0 | b!=0}.
12931For mixed operations between a scalar @code{s} and a vector @code{v},
12932@code{s && v} is equivalent to @code{s?v!=0:0} (the evaluation is
12933short-circuit) and @code{v && s} is equivalent to @code{v!=0 & (s?-1:0)}.
12934
12935@findex __builtin_shuffle
12936Vector shuffling is available using functions
12937@code{__builtin_shuffle (vec, mask)} and
12938@code{__builtin_shuffle (vec0, vec1, mask)}.
12939Both functions construct a permutation of elements from one or two
12940vectors and return a vector of the same type as the input vector(s).
12941The @var{mask} is an integral vector with the same width (@var{W})
12942and element count (@var{N}) as the output vector.
12943
12944The elements of the input vectors are numbered in memory ordering of
12945@var{vec0} beginning at 0 and @var{vec1} beginning at @var{N}. The
12946elements of @var{mask} are considered modulo @var{N} in the single-operand
12947case and modulo @math{2*@var{N}} in the two-operand case.
12948
12949Consider the following example,
12950
12951@smallexample
12952typedef int v4si __attribute__ ((vector_size (16)));
12953
12954v4si a = @{1,2,3,4@};
12955v4si b = @{5,6,7,8@};
12956v4si mask1 = @{0,1,1,3@};
12957v4si mask2 = @{0,4,2,5@};
12958v4si res;
12959
12960res = __builtin_shuffle (a, mask1); /* res is @{1,2,2,4@} */
12961res = __builtin_shuffle (a, b, mask2); /* res is @{1,5,3,6@} */
12962@end smallexample
12963
12964Note that @code{__builtin_shuffle} is intentionally semantically
12965compatible with the OpenCL @code{shuffle} and @code{shuffle2} functions.
12966
12967You can declare variables and use them in function calls and returns, as
12968well as in assignments and some casts. You can specify a vector type as
12969a return type for a function. Vector types can also be used as function
12970arguments. It is possible to cast from one vector type to another,
12971provided they are of the same size (in fact, you can also cast vectors
12972to and from other datatypes of the same size).
12973
12974You cannot operate between vectors of different lengths or different
12975signedness without a cast.
12976
12977@findex __builtin_shufflevector
12978Vector shuffling is available using the
12979@code{__builtin_shufflevector (vec1, vec2, index...)}
12980function. @var{vec1} and @var{vec2} must be expressions with
12981vector type with a compatible element type. The result of
12982@code{__builtin_shufflevector} is a vector with the same element type
12983as @var{vec1} and @var{vec2} but that has an element count equal to
12984the number of indices specified.
12985
12986The @var{index} arguments are a list of integers that specify the
12987elements indices of the first two vectors that should be extracted and
12988returned in a new vector. These element indices are numbered sequentially
12989starting with the first vector, continuing into the second vector.
12990An index of -1 can be used to indicate that the corresponding element in
12991the returned vector is a don't care and can be freely chosen to optimized
12992the generated code sequence performing the shuffle operation.
12993
12994Consider the following example,
12995@smallexample
12996typedef int v4si __attribute__ ((vector_size (16)));
12997typedef int v8si __attribute__ ((vector_size (32)));
12998
12999v8si a = @{1,-2,3,-4,5,-6,7,-8@};
13000v4si b = __builtin_shufflevector (a, a, 0, 2, 4, 6); /* b is @{1,3,5,7@} */
13001v4si c = @{-2,-4,-6,-8@};
13002v8si d = __builtin_shufflevector (c, b, 4, 0, 5, 1, 6, 2, 7, 3); /* d is a */
13003@end smallexample
13004
13005@findex __builtin_convertvector
13006Vector conversion is available using the
13007@code{__builtin_convertvector (vec, vectype)}
13008function. @var{vec} must be an expression with integral or floating
13009vector type and @var{vectype} an integral or floating vector type with the
13010same number of elements. The result has @var{vectype} type and value of
13011a C cast of every element of @var{vec} to the element type of @var{vectype}.
13012
13013Consider the following example,
13014@smallexample
13015typedef int v4si __attribute__ ((vector_size (16)));
13016typedef float v4sf __attribute__ ((vector_size (16)));
13017typedef double v4df __attribute__ ((vector_size (32)));
13018typedef unsigned long long v4di __attribute__ ((vector_size (32)));
13019
13020v4si a = @{1,-2,3,-4@};
13021v4sf b = @{1.5f,-2.5f,3.f,7.f@};
13022v4di c = @{1ULL,5ULL,0ULL,10ULL@};
13023v4sf d = __builtin_convertvector (a, v4sf); /* d is @{1.f,-2.f,3.f,-4.f@} */
13024/* Equivalent of:
13025 v4sf d = @{ (float)a[0], (float)a[1], (float)a[2], (float)a[3] @}; */
13026v4df e = __builtin_convertvector (a, v4df); /* e is @{1.,-2.,3.,-4.@} */
13027v4df f = __builtin_convertvector (b, v4df); /* f is @{1.5,-2.5,3.,7.@} */
13028v4si g = __builtin_convertvector (f, v4si); /* g is @{1,-2,3,7@} */
13029v4si h = __builtin_convertvector (c, v4si); /* h is @{1,5,0,10@} */
13030@end smallexample
13031
13032@cindex vector types, using with x86 intrinsics
13033Sometimes it is desirable to write code using a mix of generic vector
13034operations (for clarity) and machine-specific vector intrinsics (to
13035access vector instructions that are not exposed via generic built-ins).
13036On x86, intrinsic functions for integer vectors typically use the same
13037vector type @code{__m128i} irrespective of how they interpret the vector,
13038making it necessary to cast their arguments and return values from/to
13039other vector types. In C, you can make use of a @code{union} type:
13040@c In C++ such type punning via a union is not allowed by the language
13041@smallexample
13042#include <immintrin.h>
13043
13044typedef unsigned char u8x16 __attribute__ ((vector_size (16)));
13045typedef unsigned int u32x4 __attribute__ ((vector_size (16)));
13046
13047typedef union @{
13048 __m128i mm;
13049 u8x16 u8;
13050 u32x4 u32;
13051@} v128;
13052@end smallexample
13053
13054@noindent
13055for variables that can be used with both built-in operators and x86
13056intrinsics:
13057
13058@smallexample
13059v128 x, y = @{ 0 @};
13060memcpy (&x, ptr, sizeof x);
13061y.u8 += 0x80;
13062x.mm = _mm_adds_epu8 (x.mm, y.mm);
13063x.u32 &= 0xffffff;
13064
13065/* Instead of a variable, a compound literal may be used to pass the
13066 return value of an intrinsic call to a function expecting the union: */
13067v128 foo (v128);
13068x = foo ((v128) @{_mm_adds_epu8 (x.mm, y.mm)@});
13069@c This could be done implicitly with __attribute__((transparent_union)),
13070@c but GCC does not accept it for unions of vector types (PR 88955).
13071@end smallexample
13072
13073@node Offsetof
13074@section Support for @code{offsetof}
13075@findex __builtin_offsetof
13076
13077GCC implements for both C and C++ a syntactic extension to implement
13078the @code{offsetof} macro.
13079
13080@smallexample
13081primary:
13082 "__builtin_offsetof" "(" @code{typename} "," offsetof_member_designator ")"
13083
13084offsetof_member_designator:
13085 @code{identifier}
13086 | offsetof_member_designator "." @code{identifier}
13087 | offsetof_member_designator "[" @code{expr} "]"
13088@end smallexample
13089
13090This extension is sufficient such that
13091
13092@smallexample
13093#define offsetof(@var{type}, @var{member}) __builtin_offsetof (@var{type}, @var{member})
13094@end smallexample
13095
13096@noindent
13097is a suitable definition of the @code{offsetof} macro. In C++, @var{type}
13098may be dependent. In either case, @var{member} may consist of a single
13099identifier, or a sequence of member accesses and array references.
13100
13101@node __sync Builtins
13102@section Legacy @code{__sync} Built-in Functions for Atomic Memory Access
13103
13104The following built-in functions
13105are intended to be compatible with those described
13106in the @cite{Intel Itanium Processor-specific Application Binary Interface},
13107section 7.4. As such, they depart from normal GCC practice by not using
13108the @samp{__builtin_} prefix and also by being overloaded so that they
13109work on multiple types.
13110
13111The definition given in the Intel documentation allows only for the use of
13112the types @code{int}, @code{long}, @code{long long} or their unsigned
13113counterparts. GCC allows any scalar type that is 1, 2, 4 or 8 bytes in
13114size other than the C type @code{_Bool} or the C++ type @code{bool}.
13115Operations on pointer arguments are performed as if the operands were
13116of the @code{uintptr_t} type. That is, they are not scaled by the size
13117of the type to which the pointer points.
13118
13119These functions are implemented in terms of the @samp{__atomic}
13120builtins (@pxref{__atomic Builtins}). They should not be used for new
13121code which should use the @samp{__atomic} builtins instead.
13122
13123Not all operations are supported by all target processors. If a particular
13124operation cannot be implemented on the target processor, a warning is
13125generated and a call to an external function is generated. The external
13126function carries the same name as the built-in version,
13127with an additional suffix
13128@samp{_@var{n}} where @var{n} is the size of the data type.
13129
13130@c ??? Should we have a mechanism to suppress this warning? This is almost
13131@c useful for implementing the operation under the control of an external
13132@c mutex.
13133
13134In most cases, these built-in functions are considered a @dfn{full barrier}.
13135That is,
13136no memory operand is moved across the operation, either forward or
13137backward. Further, instructions are issued as necessary to prevent the
13138processor from speculating loads across the operation and from queuing stores
13139after the operation.
13140
13141All of the routines are described in the Intel documentation to take
13142``an optional list of variables protected by the memory barrier''. It's
13143not clear what is meant by that; it could mean that @emph{only} the
13144listed variables are protected, or it could mean a list of additional
13145variables to be protected. The list is ignored by GCC which treats it as
13146empty. GCC interprets an empty list as meaning that all globally
13147accessible variables should be protected.
13148
23795106
JJ
13149@defbuiltin{@var{type} __sync_fetch_and_add (@var{type} *@var{ptr}, @var{type} @var{value}, ...)}
13150@defbuiltinx{@var{type} __sync_fetch_and_sub (@var{type} *@var{ptr}, @var{type} @var{value}, ...)}
13151@defbuiltinx{@var{type} __sync_fetch_and_or (@var{type} *@var{ptr}, @var{type} @var{value}, ...)}
13152@defbuiltinx{@var{type} __sync_fetch_and_and (@var{type} *@var{ptr}, @var{type} @var{value}, ...)}
13153@defbuiltinx{@var{type} __sync_fetch_and_xor (@var{type} *@var{ptr}, @var{type} @var{value}, ...)}
13154@defbuiltinx{@var{type} __sync_fetch_and_nand (@var{type} *@var{ptr}, @var{type} @var{value}, ...)}
d77de738
ML
13155These built-in functions perform the operation suggested by the name, and
13156returns the value that had previously been in memory. That is, operations
13157on integer operands have the following semantics. Operations on pointer
13158arguments are performed as if the operands were of the @code{uintptr_t}
13159type. That is, they are not scaled by the size of the type to which
13160the pointer points.
13161
13162@smallexample
13163@{ tmp = *ptr; *ptr @var{op}= value; return tmp; @}
13164@{ tmp = *ptr; *ptr = ~(tmp & value); return tmp; @} // nand
13165@end smallexample
13166
13167The object pointed to by the first argument must be of integer or pointer
13168type. It must not be a boolean type.
13169
13170@emph{Note:} GCC 4.4 and later implement @code{__sync_fetch_and_nand}
13171as @code{*ptr = ~(tmp & value)} instead of @code{*ptr = ~tmp & value}.
f25efe50
AA
13172@enddefbuiltin
13173
23795106
JJ
13174@defbuiltin{@var{type} __sync_add_and_fetch (@var{type} *@var{ptr}, @
13175 @var{type} @var{value}, ...)}
13176@defbuiltinx{@var{type} __sync_sub_and_fetch (@var{type} *@var{ptr}, @var{type} @var{value}, ...)}
13177@defbuiltinx{@var{type} __sync_or_and_fetch (@var{type} *@var{ptr}, @var{type} @var{value}, ...)}
13178@defbuiltinx{@var{type} __sync_and_and_fetch (@var{type} *@var{ptr}, @var{type} @var{value}, ...)}
13179@defbuiltinx{@var{type} __sync_xor_and_fetch (@var{type} *@var{ptr}, @var{type} @var{value}, ...)}
13180@defbuiltinx{@var{type} __sync_nand_and_fetch (@var{type} *@var{ptr}, @var{type} @var{value}, ...)}
d77de738
ML
13181These built-in functions perform the operation suggested by the name, and
13182return the new value. That is, operations on integer operands have
13183the following semantics. Operations on pointer operands are performed as
13184if the operand's type were @code{uintptr_t}.
13185
13186@smallexample
13187@{ *ptr @var{op}= value; return *ptr; @}
13188@{ *ptr = ~(*ptr & value); return *ptr; @} // nand
13189@end smallexample
13190
13191The same constraints on arguments apply as for the corresponding
13192@code{__sync_op_and_fetch} built-in functions.
13193
13194@emph{Note:} GCC 4.4 and later implement @code{__sync_nand_and_fetch}
13195as @code{*ptr = ~(*ptr & value)} instead of
13196@code{*ptr = ~*ptr & value}.
f25efe50 13197@enddefbuiltin
d77de738 13198
23795106
JJ
13199@defbuiltin{bool __sync_bool_compare_and_swap (@var{type} *@var{ptr}, @var{type} @var{oldval}, @var{type} @var{newval}, ...)}
13200@defbuiltinx{@var{type} __sync_val_compare_and_swap (@var{type} *@var{ptr}, @var{type} @var{oldval}, @var{type} @var{newval}, ...)}
d77de738
ML
13201These built-in functions perform an atomic compare and swap.
13202That is, if the current
13203value of @code{*@var{ptr}} is @var{oldval}, then write @var{newval} into
13204@code{*@var{ptr}}.
13205
13206The ``bool'' version returns @code{true} if the comparison is successful and
13207@var{newval} is written. The ``val'' version returns the contents
13208of @code{*@var{ptr}} before the operation.
f25efe50 13209@enddefbuiltin
d77de738 13210
f25efe50 13211@defbuiltin{void __sync_synchronize (...)}
d77de738 13212This built-in function issues a full memory barrier.
f25efe50 13213@enddefbuiltin
d77de738 13214
23795106 13215@defbuiltin{@var{type} __sync_lock_test_and_set (@var{type} *@var{ptr}, @var{type} @var{value}, ...)}
d77de738
ML
13216This built-in function, as described by Intel, is not a traditional test-and-set
13217operation, but rather an atomic exchange operation. It writes @var{value}
13218into @code{*@var{ptr}}, and returns the previous contents of
13219@code{*@var{ptr}}.
13220
13221Many targets have only minimal support for such locks, and do not support
13222a full exchange operation. In this case, a target may support reduced
13223functionality here by which the @emph{only} valid value to store is the
13224immediate constant 1. The exact value actually stored in @code{*@var{ptr}}
13225is implementation defined.
13226
13227This built-in function is not a full barrier,
13228but rather an @dfn{acquire barrier}.
13229This means that references after the operation cannot move to (or be
13230speculated to) before the operation, but previous memory stores may not
13231be globally visible yet, and previous memory loads may not yet be
13232satisfied.
f25efe50 13233@enddefbuiltin
d77de738 13234
23795106 13235@defbuiltin{void __sync_lock_release (@var{type} *@var{ptr}, ...)}
d77de738
ML
13236This built-in function releases the lock acquired by
13237@code{__sync_lock_test_and_set}.
13238Normally this means writing the constant 0 to @code{*@var{ptr}}.
13239
13240This built-in function is not a full barrier,
13241but rather a @dfn{release barrier}.
13242This means that all previous memory stores are globally visible, and all
13243previous memory loads have been satisfied, but following memory reads
13244are not prevented from being speculated to before the barrier.
f25efe50 13245@enddefbuiltin
d77de738
ML
13246
13247@node __atomic Builtins
13248@section Built-in Functions for Memory Model Aware Atomic Operations
13249
13250The following built-in functions approximately match the requirements
13251for the C++11 memory model. They are all
13252identified by being prefixed with @samp{__atomic} and most are
13253overloaded so that they work with multiple types.
13254
13255These functions are intended to replace the legacy @samp{__sync}
13256builtins. The main difference is that the memory order that is requested
13257is a parameter to the functions. New code should always use the
13258@samp{__atomic} builtins rather than the @samp{__sync} builtins.
13259
13260Note that the @samp{__atomic} builtins assume that programs will
13261conform to the C++11 memory model. In particular, they assume
13262that programs are free of data races. See the C++11 standard for
13263detailed requirements.
13264
13265The @samp{__atomic} builtins can be used with any integral scalar or
13266pointer type that is 1, 2, 4, or 8 bytes in length. 16-byte integral
13267types are also allowed if @samp{__int128} (@pxref{__int128}) is
13268supported by the architecture.
13269
13270The four non-arithmetic functions (load, store, exchange, and
13271compare_exchange) all have a generic version as well. This generic
13272version works on any data type. It uses the lock-free built-in function
13273if the specific data type size makes that possible; otherwise, an
13274external call is left to be resolved at run time. This external call is
13275the same format with the addition of a @samp{size_t} parameter inserted
13276as the first parameter indicating the size of the object being pointed to.
13277All objects must be the same size.
13278
13279There are 6 different memory orders that can be specified. These map
13280to the C++11 memory orders with the same names, see the C++11 standard
13281or the @uref{https://gcc.gnu.org/wiki/Atomic/GCCMM/AtomicSync,GCC wiki
13282on atomic synchronization} for detailed definitions. Individual
13283targets may also support additional memory orders for use on specific
13284architectures. Refer to the target documentation for details of
13285these.
13286
13287An atomic operation can both constrain code motion and
13288be mapped to hardware instructions for synchronization between threads
13289(e.g., a fence). To which extent this happens is controlled by the
13290memory orders, which are listed here in approximately ascending order of
13291strength. The description of each memory order is only meant to roughly
13292illustrate the effects and is not a specification; see the C++11
13293memory model for precise semantics.
13294
13295@table @code
13296@item __ATOMIC_RELAXED
13297Implies no inter-thread ordering constraints.
13298@item __ATOMIC_CONSUME
13299This is currently implemented using the stronger @code{__ATOMIC_ACQUIRE}
13300memory order because of a deficiency in C++11's semantics for
13301@code{memory_order_consume}.
13302@item __ATOMIC_ACQUIRE
13303Creates an inter-thread happens-before constraint from the release (or
13304stronger) semantic store to this acquire load. Can prevent hoisting
13305of code to before the operation.
13306@item __ATOMIC_RELEASE
13307Creates an inter-thread happens-before constraint to acquire (or stronger)
13308semantic loads that read from this release store. Can prevent sinking
13309of code to after the operation.
13310@item __ATOMIC_ACQ_REL
13311Combines the effects of both @code{__ATOMIC_ACQUIRE} and
13312@code{__ATOMIC_RELEASE}.
13313@item __ATOMIC_SEQ_CST
13314Enforces total ordering with all other @code{__ATOMIC_SEQ_CST} operations.
13315@end table
13316
13317Note that in the C++11 memory model, @emph{fences} (e.g.,
13318@samp{__atomic_thread_fence}) take effect in combination with other
13319atomic operations on specific memory locations (e.g., atomic loads);
13320operations on specific memory locations do not necessarily affect other
13321operations in the same way.
13322
13323Target architectures are encouraged to provide their own patterns for
13324each of the atomic built-in functions. If no target is provided, the original
13325non-memory model set of @samp{__sync} atomic built-in functions are
13326used, along with any required synchronization fences surrounding it in
13327order to achieve the proper behavior. Execution in this case is subject
13328to the same restrictions as those built-in functions.
13329
13330If there is no pattern or mechanism to provide a lock-free instruction
13331sequence, a call is made to an external routine with the same parameters
13332to be resolved at run time.
13333
13334When implementing patterns for these built-in functions, the memory order
13335parameter can be ignored as long as the pattern implements the most
13336restrictive @code{__ATOMIC_SEQ_CST} memory order. Any of the other memory
13337orders execute correctly with this memory order but they may not execute as
13338efficiently as they could with a more appropriate implementation of the
13339relaxed requirements.
13340
13341Note that the C++11 standard allows for the memory order parameter to be
13342determined at run time rather than at compile time. These built-in
13343functions map any run-time value to @code{__ATOMIC_SEQ_CST} rather
13344than invoke a runtime library call or inline a switch statement. This is
13345standard compliant, safe, and the simplest approach for now.
13346
13347The memory order parameter is a signed int, but only the lower 16 bits are
13348reserved for the memory order. The remainder of the signed int is reserved
13349for target use and should be 0. Use of the predefined atomic values
13350ensures proper usage.
13351
23795106 13352@defbuiltin{@var{type} __atomic_load_n (@var{type} *@var{ptr}, int @var{memorder})}
d77de738
ML
13353This built-in function implements an atomic load operation. It returns the
13354contents of @code{*@var{ptr}}.
13355
13356The valid memory order variants are
13357@code{__ATOMIC_RELAXED}, @code{__ATOMIC_SEQ_CST}, @code{__ATOMIC_ACQUIRE},
13358and @code{__ATOMIC_CONSUME}.
13359
f25efe50 13360@enddefbuiltin
d77de738 13361
23795106 13362@defbuiltin{void __atomic_load (@var{type} *@var{ptr}, @var{type} *@var{ret}, int @var{memorder})}
d77de738
ML
13363This is the generic version of an atomic load. It returns the
13364contents of @code{*@var{ptr}} in @code{*@var{ret}}.
13365
f25efe50 13366@enddefbuiltin
d77de738 13367
23795106 13368@defbuiltin{void __atomic_store_n (@var{type} *@var{ptr}, @var{type} @var{val}, int @var{memorder})}
d77de738
ML
13369This built-in function implements an atomic store operation. It writes
13370@code{@var{val}} into @code{*@var{ptr}}.
13371
13372The valid memory order variants are
13373@code{__ATOMIC_RELAXED}, @code{__ATOMIC_SEQ_CST}, and @code{__ATOMIC_RELEASE}.
13374
f25efe50 13375@enddefbuiltin
d77de738 13376
23795106 13377@defbuiltin{void __atomic_store (@var{type} *@var{ptr}, @var{type} *@var{val}, int @var{memorder})}
d77de738
ML
13378This is the generic version of an atomic store. It stores the value
13379of @code{*@var{val}} into @code{*@var{ptr}}.
13380
f25efe50 13381@enddefbuiltin
d77de738 13382
23795106 13383@defbuiltin{@var{type} __atomic_exchange_n (@var{type} *@var{ptr}, @var{type} @var{val}, int @var{memorder})}
d77de738
ML
13384This built-in function implements an atomic exchange operation. It writes
13385@var{val} into @code{*@var{ptr}}, and returns the previous contents of
13386@code{*@var{ptr}}.
13387
13388All memory order variants are valid.
13389
f25efe50 13390@enddefbuiltin
d77de738 13391
23795106 13392@defbuiltin{void __atomic_exchange (@var{type} *@var{ptr}, @var{type} *@var{val}, @var{type} *@var{ret}, int @var{memorder})}
d77de738
ML
13393This is the generic version of an atomic exchange. It stores the
13394contents of @code{*@var{val}} into @code{*@var{ptr}}. The original value
13395of @code{*@var{ptr}} is copied into @code{*@var{ret}}.
13396
f25efe50 13397@enddefbuiltin
d77de738 13398
23795106 13399@defbuiltin{bool __atomic_compare_exchange_n (@var{type} *@var{ptr}, @var{type} *@var{expected}, @var{type} @var{desired}, bool @var{weak}, int @var{success_memorder}, int @var{failure_memorder})}
d77de738
ML
13400This built-in function implements an atomic compare and exchange operation.
13401This compares the contents of @code{*@var{ptr}} with the contents of
13402@code{*@var{expected}}. If equal, the operation is a @emph{read-modify-write}
13403operation that writes @var{desired} into @code{*@var{ptr}}. If they are not
13404equal, the operation is a @emph{read} and the current contents of
13405@code{*@var{ptr}} are written into @code{*@var{expected}}. @var{weak} is @code{true}
13406for weak compare_exchange, which may fail spuriously, and @code{false} for
13407the strong variation, which never fails spuriously. Many targets
13408only offer the strong variation and ignore the parameter. When in doubt, use
13409the strong variation.
13410
13411If @var{desired} is written into @code{*@var{ptr}} then @code{true} is returned
13412and memory is affected according to the
13413memory order specified by @var{success_memorder}. There are no
13414restrictions on what memory order can be used here.
13415
13416Otherwise, @code{false} is returned and memory is affected according
13417to @var{failure_memorder}. This memory order cannot be
13418@code{__ATOMIC_RELEASE} nor @code{__ATOMIC_ACQ_REL}. It also cannot be a
13419stronger order than that specified by @var{success_memorder}.
13420
f25efe50 13421@enddefbuiltin
d77de738 13422
23795106 13423@defbuiltin{bool __atomic_compare_exchange (@var{type} *@var{ptr}, @var{type} *@var{expected}, @var{type} *@var{desired}, bool @var{weak}, int @var{success_memorder}, int @var{failure_memorder})}
d77de738
ML
13424This built-in function implements the generic version of
13425@code{__atomic_compare_exchange}. The function is virtually identical to
13426@code{__atomic_compare_exchange_n}, except the desired value is also a
13427pointer.
13428
f25efe50 13429@enddefbuiltin
d77de738 13430
23795106
JJ
13431@defbuiltin{@var{type} __atomic_add_fetch (@var{type} *@var{ptr}, @var{type} @var{val}, int @var{memorder})}
13432@defbuiltinx{@var{type} __atomic_sub_fetch (@var{type} *@var{ptr}, @var{type} @var{val}, int @var{memorder})}
13433@defbuiltinx{@var{type} __atomic_and_fetch (@var{type} *@var{ptr}, @var{type} @var{val}, int @var{memorder})}
13434@defbuiltinx{@var{type} __atomic_xor_fetch (@var{type} *@var{ptr}, @var{type} @var{val}, int @var{memorder})}
13435@defbuiltinx{@var{type} __atomic_or_fetch (@var{type} *@var{ptr}, @var{type} @var{val}, int @var{memorder})}
13436@defbuiltinx{@var{type} __atomic_nand_fetch (@var{type} *@var{ptr}, @var{type} @var{val}, int @var{memorder})}
d77de738
ML
13437These built-in functions perform the operation suggested by the name, and
13438return the result of the operation. Operations on pointer arguments are
13439performed as if the operands were of the @code{uintptr_t} type. That is,
13440they are not scaled by the size of the type to which the pointer points.
13441
13442@smallexample
13443@{ *ptr @var{op}= val; return *ptr; @}
13444@{ *ptr = ~(*ptr & val); return *ptr; @} // nand
13445@end smallexample
13446
13447The object pointed to by the first argument must be of integer or pointer
13448type. It must not be a boolean type. All memory orders are valid.
13449
f25efe50 13450@enddefbuiltin
d77de738 13451
23795106
JJ
13452@defbuiltin{@var{type} __atomic_fetch_add (@var{type} *@var{ptr}, @var{type} @var{val}, int @var{memorder})}
13453@defbuiltinx{@var{type} __atomic_fetch_sub (@var{type} *@var{ptr}, @var{type} @var{val}, int @var{memorder})}
13454@defbuiltinx{@var{type} __atomic_fetch_and (@var{type} *@var{ptr}, @var{type} @var{val}, int @var{memorder})}
13455@defbuiltinx{@var{type} __atomic_fetch_xor (@var{type} *@var{ptr}, @var{type} @var{val}, int @var{memorder})}
13456@defbuiltinx{@var{type} __atomic_fetch_or (@var{type} *@var{ptr}, @var{type} @var{val}, int @var{memorder})}
13457@defbuiltinx{@var{type} __atomic_fetch_nand (@var{type} *@var{ptr}, @var{type} @var{val}, int @var{memorder})}
d77de738
ML
13458These built-in functions perform the operation suggested by the name, and
13459return the value that had previously been in @code{*@var{ptr}}. Operations
13460on pointer arguments are performed as if the operands were of
13461the @code{uintptr_t} type. That is, they are not scaled by the size of
13462the type to which the pointer points.
13463
13464@smallexample
13465@{ tmp = *ptr; *ptr @var{op}= val; return tmp; @}
13466@{ tmp = *ptr; *ptr = ~(*ptr & val); return tmp; @} // nand
13467@end smallexample
13468
13469The same constraints on arguments apply as for the corresponding
13470@code{__atomic_op_fetch} built-in functions. All memory orders are valid.
13471
f25efe50 13472@enddefbuiltin
d77de738 13473
23795106 13474@defbuiltin{bool __atomic_test_and_set (void *@var{ptr}, int @var{memorder})}
d77de738
ML
13475
13476This built-in function performs an atomic test-and-set operation on
13477the byte at @code{*@var{ptr}}. The byte is set to some implementation
13478defined nonzero ``set'' value and the return value is @code{true} if and only
13479if the previous contents were ``set''.
13480It should be only used for operands of type @code{bool} or @code{char}. For
13481other types only part of the value may be set.
13482
13483All memory orders are valid.
13484
f25efe50 13485@enddefbuiltin
d77de738 13486
23795106 13487@defbuiltin{void __atomic_clear (bool *@var{ptr}, int @var{memorder})}
d77de738
ML
13488
13489This built-in function performs an atomic clear operation on
13490@code{*@var{ptr}}. After the operation, @code{*@var{ptr}} contains 0.
13491It should be only used for operands of type @code{bool} or @code{char} and
13492in conjunction with @code{__atomic_test_and_set}.
13493For other types it may only clear partially. If the type is not @code{bool}
13494prefer using @code{__atomic_store}.
13495
13496The valid memory order variants are
13497@code{__ATOMIC_RELAXED}, @code{__ATOMIC_SEQ_CST}, and
13498@code{__ATOMIC_RELEASE}.
13499
f25efe50 13500@enddefbuiltin
d77de738 13501
23795106 13502@defbuiltin{void __atomic_thread_fence (int @var{memorder})}
d77de738
ML
13503
13504This built-in function acts as a synchronization fence between threads
13505based on the specified memory order.
13506
13507All memory orders are valid.
13508
f25efe50 13509@enddefbuiltin
d77de738 13510
23795106 13511@defbuiltin{void __atomic_signal_fence (int @var{memorder})}
d77de738
ML
13512
13513This built-in function acts as a synchronization fence between a thread
13514and signal handlers based in the same thread.
13515
13516All memory orders are valid.
13517
f25efe50 13518@enddefbuiltin
d77de738 13519
23795106 13520@defbuiltin{bool __atomic_always_lock_free (size_t @var{size}, void *@var{ptr})}
d77de738
ML
13521
13522This built-in function returns @code{true} if objects of @var{size} bytes always
13523generate lock-free atomic instructions for the target architecture.
13524@var{size} must resolve to a compile-time constant and the result also
13525resolves to a compile-time constant.
13526
13527@var{ptr} is an optional pointer to the object that may be used to determine
13528alignment. A value of 0 indicates typical alignment should be used. The
13529compiler may also ignore this parameter.
13530
13531@smallexample
13532if (__atomic_always_lock_free (sizeof (long long), 0))
13533@end smallexample
13534
f25efe50 13535@enddefbuiltin
d77de738 13536
23795106 13537@defbuiltin{bool __atomic_is_lock_free (size_t @var{size}, void *@var{ptr})}
d77de738
ML
13538
13539This built-in function returns @code{true} if objects of @var{size} bytes always
13540generate lock-free atomic instructions for the target architecture. If
13541the built-in function is not known to be lock-free, a call is made to a
13542runtime routine named @code{__atomic_is_lock_free}.
13543
13544@var{ptr} is an optional pointer to the object that may be used to determine
13545alignment. A value of 0 indicates typical alignment should be used. The
13546compiler may also ignore this parameter.
f25efe50 13547@enddefbuiltin
d77de738
ML
13548
13549@node Integer Overflow Builtins
13550@section Built-in Functions to Perform Arithmetic with Overflow Checking
13551
13552The following built-in functions allow performing simple arithmetic operations
13553together with checking whether the operations overflowed.
13554
23795106
JJ
13555@defbuiltin{bool __builtin_add_overflow (@var{type1} @var{a}, @var{type2} @var{b}, @var{type3} *@var{res})}
13556@defbuiltinx{bool __builtin_sadd_overflow (int @var{a}, int @var{b}, int *@var{res})}
13557@defbuiltinx{bool __builtin_saddl_overflow (long int @var{a}, long int @var{b}, long int *@var{res})}
13558@defbuiltinx{bool __builtin_saddll_overflow (long long int @var{a}, long long int @var{b}, long long int *@var{res})}
13559@defbuiltinx{bool __builtin_uadd_overflow (unsigned int @var{a}, unsigned int @var{b}, unsigned int *@var{res})}
13560@defbuiltinx{bool __builtin_uaddl_overflow (unsigned long int @var{a}, unsigned long int @var{b}, unsigned long int *@var{res})}
13561@defbuiltinx{bool __builtin_uaddll_overflow (unsigned long long int @var{a}, unsigned long long int @var{b}, unsigned long long int *@var{res})}
d77de738
ML
13562
13563These built-in functions promote the first two operands into infinite precision signed
13564type and perform addition on those promoted operands. The result is then
13565cast to the type the third pointer argument points to and stored there.
13566If the stored result is equal to the infinite precision result, the built-in
13567functions return @code{false}, otherwise they return @code{true}. As the addition is
13568performed in infinite signed precision, these built-in functions have fully defined
13569behavior for all argument values.
13570
13571The first built-in function allows arbitrary integral types for operands and
13572the result type must be pointer to some integral type other than enumerated or
13573boolean type, the rest of the built-in functions have explicit integer types.
13574
13575The compiler will attempt to use hardware instructions to implement
13576these built-in functions where possible, like conditional jump on overflow
13577after addition, conditional jump on carry etc.
13578
f25efe50 13579@enddefbuiltin
d77de738 13580
23795106
JJ
13581@defbuiltin{bool __builtin_sub_overflow (@var{type1} @var{a}, @var{type2} @var{b}, @var{type3} *@var{res})}
13582@defbuiltinx{bool __builtin_ssub_overflow (int @var{a}, int @var{b}, int *@var{res})}
13583@defbuiltinx{bool __builtin_ssubl_overflow (long int @var{a}, long int @var{b}, long int *@var{res})}
13584@defbuiltinx{bool __builtin_ssubll_overflow (long long int @var{a}, long long int @var{b}, long long int *@var{res})}
13585@defbuiltinx{bool __builtin_usub_overflow (unsigned int @var{a}, unsigned int @var{b}, unsigned int *@var{res})}
13586@defbuiltinx{bool __builtin_usubl_overflow (unsigned long int @var{a}, unsigned long int @var{b}, unsigned long int *@var{res})}
13587@defbuiltinx{bool __builtin_usubll_overflow (unsigned long long int @var{a}, unsigned long long int @var{b}, unsigned long long int *@var{res})}
d77de738
ML
13588
13589These built-in functions are similar to the add overflow checking built-in
13590functions above, except they perform subtraction, subtract the second argument
13591from the first one, instead of addition.
13592
f25efe50 13593@enddefbuiltin
d77de738 13594
23795106
JJ
13595@defbuiltin{bool __builtin_mul_overflow (@var{type1} @var{a}, @var{type2} @var{b}, @var{type3} *@var{res})}
13596@defbuiltinx{bool __builtin_smul_overflow (int @var{a}, int @var{b}, int *@var{res})}
13597@defbuiltinx{bool __builtin_smull_overflow (long int @var{a}, long int @var{b}, long int *@var{res})}
13598@defbuiltinx{bool __builtin_smulll_overflow (long long int @var{a}, long long int @var{b}, long long int *@var{res})}
13599@defbuiltinx{bool __builtin_umul_overflow (unsigned int @var{a}, unsigned int @var{b}, unsigned int *@var{res})}
13600@defbuiltinx{bool __builtin_umull_overflow (unsigned long int @var{a}, unsigned long int @var{b}, unsigned long int *@var{res})}
13601@defbuiltinx{bool __builtin_umulll_overflow (unsigned long long int @var{a}, unsigned long long int @var{b}, unsigned long long int *@var{res})}
d77de738
ML
13602
13603These built-in functions are similar to the add overflow checking built-in
13604functions above, except they perform multiplication, instead of addition.
13605
f25efe50 13606@enddefbuiltin
d77de738
ML
13607
13608The following built-in functions allow checking if simple arithmetic operation
13609would overflow.
13610
23795106
JJ
13611@defbuiltin{bool __builtin_add_overflow_p (@var{type1} @var{a}, @var{type2} @var{b}, @var{type3} @var{c})}
13612@defbuiltinx{bool __builtin_sub_overflow_p (@var{type1} @var{a}, @var{type2} @var{b}, @var{type3} @var{c})}
13613@defbuiltinx{bool __builtin_mul_overflow_p (@var{type1} @var{a}, @var{type2} @var{b}, @var{type3} @var{c})}
d77de738
ML
13614
13615These built-in functions are similar to @code{__builtin_add_overflow},
13616@code{__builtin_sub_overflow}, or @code{__builtin_mul_overflow}, except that
13617they don't store the result of the arithmetic operation anywhere and the
13618last argument is not a pointer, but some expression with integral type other
13619than enumerated or boolean type.
13620
13621The built-in functions promote the first two operands into infinite precision signed type
13622and perform addition on those promoted operands. The result is then
13623cast to the type of the third argument. If the cast result is equal to the infinite
13624precision result, the built-in functions return @code{false}, otherwise they return @code{true}.
13625The value of the third argument is ignored, just the side effects in the third argument
13626are evaluated, and no integral argument promotions are performed on the last argument.
13627If the third argument is a bit-field, the type used for the result cast has the
13628precision and signedness of the given bit-field, rather than precision and signedness
13629of the underlying type.
13630
13631For example, the following macro can be used to portably check, at
13632compile-time, whether or not adding two constant integers will overflow,
13633and perform the addition only when it is known to be safe and not to trigger
13634a @option{-Woverflow} warning.
13635
13636@smallexample
13637#define INT_ADD_OVERFLOW_P(a, b) \
13638 __builtin_add_overflow_p (a, b, (__typeof__ ((a) + (b))) 0)
13639
13640enum @{
13641 A = INT_MAX, B = 3,
13642 C = INT_ADD_OVERFLOW_P (A, B) ? 0 : A + B,
13643 D = __builtin_add_overflow_p (1, SCHAR_MAX, (signed char) 0)
13644@};
13645@end smallexample
13646
13647The compiler will attempt to use hardware instructions to implement
13648these built-in functions where possible, like conditional jump on overflow
13649after addition, conditional jump on carry etc.
13650
f25efe50 13651@enddefbuiltin
d77de738 13652
23795106
JJ
13653@defbuiltin{{unsigned int} __builtin_addc (unsigned int @var{a}, unsigned int @var{b}, unsigned int @var{carry_in}, unsigned int *@var{carry_out})}
13654@defbuiltinx{{unsigned long int} __builtin_addcl (unsigned long int @var{a}, unsigned long int @var{b}, unsigned int @var{carry_in}, unsigned long int *@var{carry_out})}
13655@defbuiltinx{{unsigned long long int} __builtin_addcll (unsigned long long int @var{a}, unsigned long long int @var{b}, unsigned long long int @var{carry_in}, unsigned long long int *@var{carry_out})}
2b4e0415
JJ
13656
13657These built-in functions are equivalent to:
13658@smallexample
13659 (@{ __typeof__ (@var{a}) s; \
13660 __typeof__ (@var{a}) c1 = __builtin_add_overflow (@var{a}, @var{b}, &s); \
13661 __typeof__ (@var{a}) c2 = __builtin_add_overflow (s, @var{carry_in}, &s); \
13662 *(@var{carry_out}) = c1 | c2; \
13663 s; @})
13664@end smallexample
13665
13666i.e.@: they add 3 unsigned values, set what the last argument
13667points to to 1 if any of the two additions overflowed (otherwise 0)
13668and return the sum of those 3 unsigned values. Note, while all
13669the first 3 arguments can have arbitrary values, better code will be
13670emitted if one of them (preferrably the third one) has only values
136710 or 1 (i.e.@: carry-in).
13672
13673@enddefbuiltin
13674
23795106
JJ
13675@defbuiltin{{unsigned int} __builtin_subc (unsigned int @var{a}, unsigned int @var{b}, unsigned int @var{carry_in}, unsigned int *@var{carry_out})}
13676@defbuiltinx{{unsigned long int} __builtin_subcl (unsigned long int @var{a}, unsigned long int @var{b}, unsigned int @var{carry_in}, unsigned long int *@var{carry_out})}
13677@defbuiltinx{{unsigned long long int} __builtin_subcll (unsigned long long int @var{a}, unsigned long long int @var{b}, unsigned long long int @var{carry_in}, unsigned long long int *@var{carry_out})}
2b4e0415
JJ
13678
13679These built-in functions are equivalent to:
13680@smallexample
13681 (@{ __typeof__ (@var{a}) s; \
13682 __typeof__ (@var{a}) c1 = __builtin_sub_overflow (@var{a}, @var{b}, &s); \
13683 __typeof__ (@var{a}) c2 = __builtin_sub_overflow (s, @var{carry_in}, &s); \
13684 *(@var{carry_out}) = c1 | c2; \
13685 s; @})
13686@end smallexample
13687
13688i.e.@: they subtract 2 unsigned values from the first unsigned value,
13689set what the last argument points to to 1 if any of the two subtractions
13690overflowed (otherwise 0) and return the result of the subtractions.
13691Note, while all the first 3 arguments can have arbitrary values, better code
13692will be emitted if one of them (preferrably the third one) has only values
136930 or 1 (i.e.@: carry-in).
13694
13695@enddefbuiltin
13696
d77de738
ML
13697@node x86 specific memory model extensions for transactional memory
13698@section x86-Specific Memory Model Extensions for Transactional Memory
13699
13700The x86 architecture supports additional memory ordering flags
13701to mark critical sections for hardware lock elision.
13702These must be specified in addition to an existing memory order to
13703atomic intrinsics.
13704
13705@table @code
13706@item __ATOMIC_HLE_ACQUIRE
13707Start lock elision on a lock variable.
13708Memory order must be @code{__ATOMIC_ACQUIRE} or stronger.
13709@item __ATOMIC_HLE_RELEASE
13710End lock elision on a lock variable.
13711Memory order must be @code{__ATOMIC_RELEASE} or stronger.
13712@end table
13713
13714When a lock acquire fails, it is required for good performance to abort
13715the transaction quickly. This can be done with a @code{_mm_pause}.
13716
13717@smallexample
13718#include <immintrin.h> // For _mm_pause
13719
13720int lockvar;
13721
13722/* Acquire lock with lock elision */
13723while (__atomic_exchange_n(&lockvar, 1, __ATOMIC_ACQUIRE|__ATOMIC_HLE_ACQUIRE))
13724 _mm_pause(); /* Abort failed transaction */
13725...
13726/* Free lock with lock elision */
13727__atomic_store_n(&lockvar, 0, __ATOMIC_RELEASE|__ATOMIC_HLE_RELEASE);
13728@end smallexample
13729
13730@node Object Size Checking
b3009222
SP
13731@section Object Size Checking
13732
13733@subsection Object Size Checking Built-in Functions
d77de738
ML
13734@findex __builtin___memcpy_chk
13735@findex __builtin___mempcpy_chk
13736@findex __builtin___memmove_chk
13737@findex __builtin___memset_chk
13738@findex __builtin___strcpy_chk
13739@findex __builtin___stpcpy_chk
13740@findex __builtin___strncpy_chk
13741@findex __builtin___strcat_chk
13742@findex __builtin___strncat_chk
d77de738
ML
13743
13744GCC implements a limited buffer overflow protection mechanism that can
13745prevent some buffer overflow attacks by determining the sizes of objects
13746into which data is about to be written and preventing the writes when
13747the size isn't sufficient. The built-in functions described below yield
13748the best results when used together and when optimization is enabled.
13749For example, to detect object sizes across function boundaries or to
13750follow pointer assignments through non-trivial control flow they rely
13751on various optimization passes enabled with @option{-O2}. However, to
13752a limited extent, they can be used without optimization as well.
13753
f25efe50 13754@defbuiltin{size_t __builtin_object_size (const void * @var{ptr}, int @var{type})}
d77de738
ML
13755is a built-in construct that returns a constant number of bytes from
13756@var{ptr} to the end of the object @var{ptr} pointer points to
13757(if known at compile time). To determine the sizes of dynamically allocated
13758objects the function relies on the allocation functions called to obtain
13759the storage to be declared with the @code{alloc_size} attribute (@pxref{Common
13760Function Attributes}). @code{__builtin_object_size} never evaluates
13761its arguments for side effects. If there are any side effects in them, it
13762returns @code{(size_t) -1} for @var{type} 0 or 1 and @code{(size_t) 0}
13763for @var{type} 2 or 3. If there are multiple objects @var{ptr} can
13764point to and all of them are known at compile time, the returned number
13765is the maximum of remaining byte counts in those objects if @var{type} & 2 is
137660 and minimum if nonzero. If it is not possible to determine which objects
13767@var{ptr} points to at compile time, @code{__builtin_object_size} should
13768return @code{(size_t) -1} for @var{type} 0 or 1 and @code{(size_t) 0}
13769for @var{type} 2 or 3.
13770
13771@var{type} is an integer constant from 0 to 3. If the least significant
13772bit is clear, objects are whole variables, if it is set, a closest
13773surrounding subobject is considered the object a pointer points to.
13774The second bit determines if maximum or minimum of remaining bytes
13775is computed.
13776
13777@smallexample
13778struct V @{ char buf1[10]; int b; char buf2[10]; @} var;
13779char *p = &var.buf1[1], *q = &var.b;
13780
13781/* Here the object p points to is var. */
13782assert (__builtin_object_size (p, 0) == sizeof (var) - 1);
13783/* The subobject p points to is var.buf1. */
13784assert (__builtin_object_size (p, 1) == sizeof (var.buf1) - 1);
13785/* The object q points to is var. */
13786assert (__builtin_object_size (q, 0)
13787 == (char *) (&var + 1) - (char *) &var.b);
13788/* The subobject q points to is var.b. */
13789assert (__builtin_object_size (q, 1) == sizeof (var.b));
13790@end smallexample
f25efe50 13791@enddefbuiltin
d77de738 13792
f25efe50 13793@defbuiltin{{size_t} __builtin_dynamic_object_size (const void * @var{ptr}, int @var{type})}
d77de738
ML
13794is similar to @code{__builtin_object_size} in that it returns a number of bytes
13795from @var{ptr} to the end of the object @var{ptr} pointer points to, except
13796that the size returned may not be a constant. This results in successful
13797evaluation of object size estimates in a wider range of use cases and can be
13798more precise than @code{__builtin_object_size}, but it incurs a performance
13799penalty since it may add a runtime overhead on size computation. Semantics of
13800@var{type} as well as return values in case it is not possible to determine
13801which objects @var{ptr} points to at compile time are the same as in the case
13802of @code{__builtin_object_size}.
f25efe50 13803@enddefbuiltin
d77de738 13804
b3009222
SP
13805@subsection Object Size Checking and Source Fortification
13806
13807Hardening of function calls using the @code{_FORTIFY_SOURCE} macro is
13808one of the key uses of the object size checking built-in functions. To
13809make implementation of these features more convenient and improve
13810optimization and diagnostics, there are built-in functions added for
13811many common string operation functions, e.g., for @code{memcpy}
13812@code{__builtin___memcpy_chk} built-in is provided. This built-in has
13813an additional last argument, which is the number of bytes remaining in
13814the object the @var{dest} argument points to or @code{(size_t) -1} if
13815the size is not known.
d77de738
ML
13816
13817The built-in functions are optimized into the normal string functions
13818like @code{memcpy} if the last argument is @code{(size_t) -1} or if
13819it is known at compile time that the destination object will not
13820be overflowed. If the compiler can determine at compile time that the
13821object will always be overflowed, it issues a warning.
13822
13823The intended use can be e.g.@:
13824
13825@smallexample
13826#undef memcpy
13827#define bos0(dest) __builtin_object_size (dest, 0)
13828#define memcpy(dest, src, n) \
13829 __builtin___memcpy_chk (dest, src, n, bos0 (dest))
13830
13831char *volatile p;
13832char buf[10];
13833/* It is unknown what object p points to, so this is optimized
13834 into plain memcpy - no checking is possible. */
13835memcpy (p, "abcde", n);
13836/* Destination is known and length too. It is known at compile
13837 time there will be no overflow. */
13838memcpy (&buf[5], "abcde", 5);
13839/* Destination is known, but the length is not known at compile time.
13840 This will result in __memcpy_chk call that can check for overflow
13841 at run time. */
13842memcpy (&buf[5], "abcde", n);
13843/* Destination is known and it is known at compile time there will
13844 be overflow. There will be a warning and __memcpy_chk call that
13845 will abort the program at run time. */
13846memcpy (&buf[6], "abcde", 5);
13847@end smallexample
13848
13849Such built-in functions are provided for @code{memcpy}, @code{mempcpy},
13850@code{memmove}, @code{memset}, @code{strcpy}, @code{stpcpy}, @code{strncpy},
13851@code{strcat} and @code{strncat}.
13852
e1e5ecb2 13853@subsubsection Formatted Output Function Checking
f25efe50
AA
13854@defbuiltin{int __builtin___sprintf_chk @
13855 (char *@var{s}, int @var{flag}, size_t @var{os}, @
13856 const char *@var{fmt}, ...)}
13857@defbuiltinx{int __builtin___snprintf_chk @
13858 (char *@var{s}, size_t @var{maxlen}, int @var{flag}, @
13859 size_t @var{os}, const char *@var{fmt}, ...)}
13860@defbuiltinx{int __builtin___vsprintf_chk @
13861 (char *@var{s}, int @var{flag}, size_t @var{os}, @
13862 const char *@var{fmt}, va_list @var{ap})}
13863@defbuiltinx{int __builtin___vsnprintf_chk @
13864 (char *@var{s}, size_t @var{maxlen}, int @var{flag}, @
13865 size_t @var{os}, const char *@var{fmt}, @
13866 va_list @var{ap})}
d77de738
ML
13867
13868The added @var{flag} argument is passed unchanged to @code{__sprintf_chk}
13869etc.@: functions and can contain implementation specific flags on what
13870additional security measures the checking function might take, such as
13871handling @code{%n} differently.
13872
13873The @var{os} argument is the object size @var{s} points to, like in the
13874other built-in functions. There is a small difference in the behavior
13875though, if @var{os} is @code{(size_t) -1}, the built-in functions are
13876optimized into the non-checking functions only if @var{flag} is 0, otherwise
13877the checking function is called with @var{os} argument set to
13878@code{(size_t) -1}.
13879
13880In addition to this, there are checking built-in functions
13881@code{__builtin___printf_chk}, @code{__builtin___vprintf_chk},
13882@code{__builtin___fprintf_chk} and @code{__builtin___vfprintf_chk}.
13883These have just one additional argument, @var{flag}, right before
13884format string @var{fmt}. If the compiler is able to optimize them to
13885@code{fputc} etc.@: functions, it does, otherwise the checking function
13886is called and the @var{flag} argument passed to it.
f25efe50 13887@enddefbuiltin
d77de738
ML
13888
13889@node Other Builtins
13890@section Other Built-in Functions Provided by GCC
13891@cindex built-in functions
34cf27a6 13892@findex __builtin_iseqsig
d77de738
ML
13893@findex __builtin_isfinite
13894@findex __builtin_isnormal
13895@findex __builtin_isgreater
13896@findex __builtin_isgreaterequal
d77de738 13897@findex __builtin_isunordered
d77de738
ML
13898@findex __builtin_speculation_safe_value
13899@findex _Exit
13900@findex _exit
13901@findex abort
13902@findex abs
13903@findex acos
13904@findex acosf
13905@findex acosh
13906@findex acoshf
13907@findex acoshl
13908@findex acosl
13909@findex alloca
13910@findex asin
13911@findex asinf
13912@findex asinh
13913@findex asinhf
13914@findex asinhl
13915@findex asinl
13916@findex atan
13917@findex atan2
13918@findex atan2f
13919@findex atan2l
13920@findex atanf
13921@findex atanh
13922@findex atanhf
13923@findex atanhl
13924@findex atanl
13925@findex bcmp
13926@findex bzero
13927@findex cabs
13928@findex cabsf
13929@findex cabsl
13930@findex cacos
13931@findex cacosf
13932@findex cacosh
13933@findex cacoshf
13934@findex cacoshl
13935@findex cacosl
13936@findex calloc
13937@findex carg
13938@findex cargf
13939@findex cargl
13940@findex casin
13941@findex casinf
13942@findex casinh
13943@findex casinhf
13944@findex casinhl
13945@findex casinl
13946@findex catan
13947@findex catanf
13948@findex catanh
13949@findex catanhf
13950@findex catanhl
13951@findex catanl
13952@findex cbrt
13953@findex cbrtf
13954@findex cbrtl
13955@findex ccos
13956@findex ccosf
13957@findex ccosh
13958@findex ccoshf
13959@findex ccoshl
13960@findex ccosl
13961@findex ceil
13962@findex ceilf
13963@findex ceill
13964@findex cexp
13965@findex cexpf
13966@findex cexpl
13967@findex cimag
13968@findex cimagf
13969@findex cimagl
13970@findex clog
13971@findex clogf
13972@findex clogl
13973@findex clog10
13974@findex clog10f
13975@findex clog10l
13976@findex conj
13977@findex conjf
13978@findex conjl
13979@findex copysign
13980@findex copysignf
13981@findex copysignl
13982@findex cos
13983@findex cosf
13984@findex cosh
13985@findex coshf
13986@findex coshl
13987@findex cosl
13988@findex cpow
13989@findex cpowf
13990@findex cpowl
13991@findex cproj
13992@findex cprojf
13993@findex cprojl
13994@findex creal
13995@findex crealf
13996@findex creall
13997@findex csin
13998@findex csinf
13999@findex csinh
14000@findex csinhf
14001@findex csinhl
14002@findex csinl
14003@findex csqrt
14004@findex csqrtf
14005@findex csqrtl
14006@findex ctan
14007@findex ctanf
14008@findex ctanh
14009@findex ctanhf
14010@findex ctanhl
14011@findex ctanl
14012@findex dcgettext
14013@findex dgettext
14014@findex drem
14015@findex dremf
14016@findex dreml
14017@findex erf
14018@findex erfc
14019@findex erfcf
14020@findex erfcl
14021@findex erff
14022@findex erfl
14023@findex exit
14024@findex exp
14025@findex exp10
14026@findex exp10f
14027@findex exp10l
14028@findex exp2
14029@findex exp2f
14030@findex exp2l
14031@findex expf
14032@findex expl
14033@findex expm1
14034@findex expm1f
14035@findex expm1l
14036@findex fabs
14037@findex fabsf
14038@findex fabsl
14039@findex fdim
14040@findex fdimf
14041@findex fdiml
14042@findex ffs
14043@findex floor
14044@findex floorf
14045@findex floorl
14046@findex fma
14047@findex fmaf
14048@findex fmal
14049@findex fmax
14050@findex fmaxf
14051@findex fmaxl
14052@findex fmin
14053@findex fminf
14054@findex fminl
14055@findex fmod
14056@findex fmodf
14057@findex fmodl
14058@findex fprintf
14059@findex fprintf_unlocked
14060@findex fputs
14061@findex fputs_unlocked
14062@findex free
14063@findex frexp
14064@findex frexpf
14065@findex frexpl
14066@findex fscanf
14067@findex gamma
14068@findex gammaf
14069@findex gammal
14070@findex gamma_r
14071@findex gammaf_r
14072@findex gammal_r
14073@findex gettext
14074@findex hypot
14075@findex hypotf
14076@findex hypotl
14077@findex ilogb
14078@findex ilogbf
14079@findex ilogbl
14080@findex imaxabs
14081@findex index
14082@findex isalnum
14083@findex isalpha
14084@findex isascii
14085@findex isblank
14086@findex iscntrl
14087@findex isdigit
14088@findex isgraph
14089@findex islower
14090@findex isprint
14091@findex ispunct
14092@findex isspace
14093@findex isupper
14094@findex iswalnum
14095@findex iswalpha
14096@findex iswblank
14097@findex iswcntrl
14098@findex iswdigit
14099@findex iswgraph
14100@findex iswlower
14101@findex iswprint
14102@findex iswpunct
14103@findex iswspace
14104@findex iswupper
14105@findex iswxdigit
14106@findex isxdigit
14107@findex j0
14108@findex j0f
14109@findex j0l
14110@findex j1
14111@findex j1f
14112@findex j1l
14113@findex jn
14114@findex jnf
14115@findex jnl
14116@findex labs
14117@findex ldexp
14118@findex ldexpf
14119@findex ldexpl
14120@findex lgamma
14121@findex lgammaf
14122@findex lgammal
14123@findex lgamma_r
14124@findex lgammaf_r
14125@findex lgammal_r
14126@findex llabs
14127@findex llrint
14128@findex llrintf
14129@findex llrintl
14130@findex llround
14131@findex llroundf
14132@findex llroundl
14133@findex log
14134@findex log10
14135@findex log10f
14136@findex log10l
14137@findex log1p
14138@findex log1pf
14139@findex log1pl
14140@findex log2
14141@findex log2f
14142@findex log2l
14143@findex logb
14144@findex logbf
14145@findex logbl
14146@findex logf
14147@findex logl
14148@findex lrint
14149@findex lrintf
14150@findex lrintl
14151@findex lround
14152@findex lroundf
14153@findex lroundl
14154@findex malloc
14155@findex memchr
14156@findex memcmp
14157@findex memcpy
14158@findex mempcpy
14159@findex memset
14160@findex modf
14161@findex modff
14162@findex modfl
14163@findex nearbyint
14164@findex nearbyintf
14165@findex nearbyintl
14166@findex nextafter
14167@findex nextafterf
14168@findex nextafterl
14169@findex nexttoward
14170@findex nexttowardf
14171@findex nexttowardl
14172@findex pow
14173@findex pow10
14174@findex pow10f
14175@findex pow10l
14176@findex powf
14177@findex powl
14178@findex printf
14179@findex printf_unlocked
14180@findex putchar
14181@findex puts
14182@findex realloc
14183@findex remainder
14184@findex remainderf
14185@findex remainderl
14186@findex remquo
14187@findex remquof
14188@findex remquol
14189@findex rindex
14190@findex rint
14191@findex rintf
14192@findex rintl
14193@findex round
14194@findex roundf
14195@findex roundl
14196@findex scalb
14197@findex scalbf
14198@findex scalbl
14199@findex scalbln
14200@findex scalblnf
14201@findex scalblnf
14202@findex scalbn
14203@findex scalbnf
14204@findex scanfnl
14205@findex signbit
14206@findex signbitf
14207@findex signbitl
14208@findex signbitd32
14209@findex signbitd64
14210@findex signbitd128
14211@findex significand
14212@findex significandf
14213@findex significandl
14214@findex sin
14215@findex sincos
14216@findex sincosf
14217@findex sincosl
14218@findex sinf
14219@findex sinh
14220@findex sinhf
14221@findex sinhl
14222@findex sinl
14223@findex snprintf
14224@findex sprintf
14225@findex sqrt
14226@findex sqrtf
14227@findex sqrtl
14228@findex sscanf
14229@findex stpcpy
14230@findex stpncpy
14231@findex strcasecmp
14232@findex strcat
14233@findex strchr
14234@findex strcmp
14235@findex strcpy
14236@findex strcspn
14237@findex strdup
14238@findex strfmon
14239@findex strftime
14240@findex strlen
14241@findex strncasecmp
14242@findex strncat
14243@findex strncmp
14244@findex strncpy
14245@findex strndup
14246@findex strnlen
14247@findex strpbrk
14248@findex strrchr
14249@findex strspn
14250@findex strstr
14251@findex tan
14252@findex tanf
14253@findex tanh
14254@findex tanhf
14255@findex tanhl
14256@findex tanl
14257@findex tgamma
14258@findex tgammaf
14259@findex tgammal
14260@findex toascii
14261@findex tolower
14262@findex toupper
14263@findex towlower
14264@findex towupper
14265@findex trunc
14266@findex truncf
14267@findex truncl
14268@findex vfprintf
14269@findex vfscanf
14270@findex vprintf
14271@findex vscanf
14272@findex vsnprintf
14273@findex vsprintf
14274@findex vsscanf
14275@findex y0
14276@findex y0f
14277@findex y0l
14278@findex y1
14279@findex y1f
14280@findex y1l
14281@findex yn
14282@findex ynf
14283@findex ynl
14284
14285GCC provides a large number of built-in functions other than the ones
14286mentioned above. Some of these are for internal use in the processing
14287of exceptions or variable-length argument lists and are not
14288documented here because they may change from time to time; we do not
14289recommend general use of these functions.
14290
14291The remaining functions are provided for optimization purposes.
14292
14293With the exception of built-ins that have library equivalents such as
14294the standard C library functions discussed below, or that expand to
14295library calls, GCC built-in functions are always expanded inline and
14296thus do not have corresponding entry points and their address cannot
14297be obtained. Attempting to use them in an expression other than
14298a function call results in a compile-time error.
14299
14300@opindex fno-builtin
14301GCC includes built-in versions of many of the functions in the standard
14302C library. These functions come in two forms: one whose names start with
14303the @code{__builtin_} prefix, and the other without. Both forms have the
14304same type (including prototype), the same address (when their address is
14305taken), and the same meaning as the C library functions even if you specify
14306the @option{-fno-builtin} option @pxref{C Dialect Options}). Many of these
14307functions are only optimized in certain cases; if they are not optimized in
14308a particular case, a call to the library function is emitted.
14309
14310@opindex ansi
14311@opindex std
14312Outside strict ISO C mode (@option{-ansi}, @option{-std=c90},
14313@option{-std=c99} or @option{-std=c11}), the functions
14314@code{_exit}, @code{alloca}, @code{bcmp}, @code{bzero},
14315@code{dcgettext}, @code{dgettext}, @code{dremf}, @code{dreml},
14316@code{drem}, @code{exp10f}, @code{exp10l}, @code{exp10}, @code{ffsll},
14317@code{ffsl}, @code{ffs}, @code{fprintf_unlocked},
14318@code{fputs_unlocked}, @code{gammaf}, @code{gammal}, @code{gamma},
14319@code{gammaf_r}, @code{gammal_r}, @code{gamma_r}, @code{gettext},
14320@code{index}, @code{isascii}, @code{j0f}, @code{j0l}, @code{j0},
14321@code{j1f}, @code{j1l}, @code{j1}, @code{jnf}, @code{jnl}, @code{jn},
14322@code{lgammaf_r}, @code{lgammal_r}, @code{lgamma_r}, @code{mempcpy},
14323@code{pow10f}, @code{pow10l}, @code{pow10}, @code{printf_unlocked},
14324@code{rindex}, @code{roundeven}, @code{roundevenf}, @code{roundevenl},
14325@code{scalbf}, @code{scalbl}, @code{scalb},
14326@code{signbit}, @code{signbitf}, @code{signbitl}, @code{signbitd32},
14327@code{signbitd64}, @code{signbitd128}, @code{significandf},
14328@code{significandl}, @code{significand}, @code{sincosf},
14329@code{sincosl}, @code{sincos}, @code{stpcpy}, @code{stpncpy},
14330@code{strcasecmp}, @code{strdup}, @code{strfmon}, @code{strncasecmp},
14331@code{strndup}, @code{strnlen}, @code{toascii}, @code{y0f}, @code{y0l},
14332@code{y0}, @code{y1f}, @code{y1l}, @code{y1}, @code{ynf}, @code{ynl} and
14333@code{yn}
14334may be handled as built-in functions.
14335All these functions have corresponding versions
14336prefixed with @code{__builtin_}, which may be used even in strict C90
14337mode.
14338
14339The ISO C99 functions
14340@code{_Exit}, @code{acoshf}, @code{acoshl}, @code{acosh}, @code{asinhf},
14341@code{asinhl}, @code{asinh}, @code{atanhf}, @code{atanhl}, @code{atanh},
14342@code{cabsf}, @code{cabsl}, @code{cabs}, @code{cacosf}, @code{cacoshf},
14343@code{cacoshl}, @code{cacosh}, @code{cacosl}, @code{cacos},
14344@code{cargf}, @code{cargl}, @code{carg}, @code{casinf}, @code{casinhf},
14345@code{casinhl}, @code{casinh}, @code{casinl}, @code{casin},
14346@code{catanf}, @code{catanhf}, @code{catanhl}, @code{catanh},
14347@code{catanl}, @code{catan}, @code{cbrtf}, @code{cbrtl}, @code{cbrt},
14348@code{ccosf}, @code{ccoshf}, @code{ccoshl}, @code{ccosh}, @code{ccosl},
14349@code{ccos}, @code{cexpf}, @code{cexpl}, @code{cexp}, @code{cimagf},
14350@code{cimagl}, @code{cimag}, @code{clogf}, @code{clogl}, @code{clog},
14351@code{conjf}, @code{conjl}, @code{conj}, @code{copysignf}, @code{copysignl},
14352@code{copysign}, @code{cpowf}, @code{cpowl}, @code{cpow}, @code{cprojf},
14353@code{cprojl}, @code{cproj}, @code{crealf}, @code{creall}, @code{creal},
14354@code{csinf}, @code{csinhf}, @code{csinhl}, @code{csinh}, @code{csinl},
14355@code{csin}, @code{csqrtf}, @code{csqrtl}, @code{csqrt}, @code{ctanf},
14356@code{ctanhf}, @code{ctanhl}, @code{ctanh}, @code{ctanl}, @code{ctan},
14357@code{erfcf}, @code{erfcl}, @code{erfc}, @code{erff}, @code{erfl},
14358@code{erf}, @code{exp2f}, @code{exp2l}, @code{exp2}, @code{expm1f},
14359@code{expm1l}, @code{expm1}, @code{fdimf}, @code{fdiml}, @code{fdim},
14360@code{fmaf}, @code{fmal}, @code{fmaxf}, @code{fmaxl}, @code{fmax},
14361@code{fma}, @code{fminf}, @code{fminl}, @code{fmin}, @code{hypotf},
14362@code{hypotl}, @code{hypot}, @code{ilogbf}, @code{ilogbl}, @code{ilogb},
14363@code{imaxabs}, @code{isblank}, @code{iswblank}, @code{lgammaf},
14364@code{lgammal}, @code{lgamma}, @code{llabs}, @code{llrintf}, @code{llrintl},
14365@code{llrint}, @code{llroundf}, @code{llroundl}, @code{llround},
14366@code{log1pf}, @code{log1pl}, @code{log1p}, @code{log2f}, @code{log2l},
14367@code{log2}, @code{logbf}, @code{logbl}, @code{logb}, @code{lrintf},
14368@code{lrintl}, @code{lrint}, @code{lroundf}, @code{lroundl},
14369@code{lround}, @code{nearbyintf}, @code{nearbyintl}, @code{nearbyint},
14370@code{nextafterf}, @code{nextafterl}, @code{nextafter},
14371@code{nexttowardf}, @code{nexttowardl}, @code{nexttoward},
14372@code{remainderf}, @code{remainderl}, @code{remainder}, @code{remquof},
14373@code{remquol}, @code{remquo}, @code{rintf}, @code{rintl}, @code{rint},
14374@code{roundf}, @code{roundl}, @code{round}, @code{scalblnf},
14375@code{scalblnl}, @code{scalbln}, @code{scalbnf}, @code{scalbnl},
14376@code{scalbn}, @code{snprintf}, @code{tgammaf}, @code{tgammal},
14377@code{tgamma}, @code{truncf}, @code{truncl}, @code{trunc},
14378@code{vfscanf}, @code{vscanf}, @code{vsnprintf} and @code{vsscanf}
14379are handled as built-in functions
14380except in strict ISO C90 mode (@option{-ansi} or @option{-std=c90}).
14381
14382There are also built-in versions of the ISO C99 functions
14383@code{acosf}, @code{acosl}, @code{asinf}, @code{asinl}, @code{atan2f},
14384@code{atan2l}, @code{atanf}, @code{atanl}, @code{ceilf}, @code{ceill},
14385@code{cosf}, @code{coshf}, @code{coshl}, @code{cosl}, @code{expf},
14386@code{expl}, @code{fabsf}, @code{fabsl}, @code{floorf}, @code{floorl},
14387@code{fmodf}, @code{fmodl}, @code{frexpf}, @code{frexpl}, @code{ldexpf},
14388@code{ldexpl}, @code{log10f}, @code{log10l}, @code{logf}, @code{logl},
14389@code{modfl}, @code{modff}, @code{powf}, @code{powl}, @code{sinf},
14390@code{sinhf}, @code{sinhl}, @code{sinl}, @code{sqrtf}, @code{sqrtl},
14391@code{tanf}, @code{tanhf}, @code{tanhl} and @code{tanl}
14392that are recognized in any mode since ISO C90 reserves these names for
14393the purpose to which ISO C99 puts them. All these functions have
14394corresponding versions prefixed with @code{__builtin_}.
14395
14396There are also built-in functions @code{__builtin_fabsf@var{n}},
14397@code{__builtin_fabsf@var{n}x}, @code{__builtin_copysignf@var{n}} and
14398@code{__builtin_copysignf@var{n}x}, corresponding to the TS 18661-3
14399functions @code{fabsf@var{n}}, @code{fabsf@var{n}x},
14400@code{copysignf@var{n}} and @code{copysignf@var{n}x}, for supported
14401types @code{_Float@var{n}} and @code{_Float@var{n}x}.
14402
14403There are also GNU extension functions @code{clog10}, @code{clog10f} and
14404@code{clog10l} which names are reserved by ISO C99 for future use.
14405All these functions have versions prefixed with @code{__builtin_}.
14406
14407The ISO C94 functions
14408@code{iswalnum}, @code{iswalpha}, @code{iswcntrl}, @code{iswdigit},
14409@code{iswgraph}, @code{iswlower}, @code{iswprint}, @code{iswpunct},
14410@code{iswspace}, @code{iswupper}, @code{iswxdigit}, @code{towlower} and
14411@code{towupper}
14412are handled as built-in functions
14413except in strict ISO C90 mode (@option{-ansi} or @option{-std=c90}).
14414
14415The ISO C90 functions
14416@code{abort}, @code{abs}, @code{acos}, @code{asin}, @code{atan2},
14417@code{atan}, @code{calloc}, @code{ceil}, @code{cosh}, @code{cos},
14418@code{exit}, @code{exp}, @code{fabs}, @code{floor}, @code{fmod},
14419@code{fprintf}, @code{fputs}, @code{free}, @code{frexp}, @code{fscanf},
14420@code{isalnum}, @code{isalpha}, @code{iscntrl}, @code{isdigit},
14421@code{isgraph}, @code{islower}, @code{isprint}, @code{ispunct},
14422@code{isspace}, @code{isupper}, @code{isxdigit}, @code{tolower},
14423@code{toupper}, @code{labs}, @code{ldexp}, @code{log10}, @code{log},
14424@code{malloc}, @code{memchr}, @code{memcmp}, @code{memcpy},
14425@code{memset}, @code{modf}, @code{pow}, @code{printf}, @code{putchar},
14426@code{puts}, @code{realloc}, @code{scanf}, @code{sinh}, @code{sin},
14427@code{snprintf}, @code{sprintf}, @code{sqrt}, @code{sscanf}, @code{strcat},
14428@code{strchr}, @code{strcmp}, @code{strcpy}, @code{strcspn},
14429@code{strlen}, @code{strncat}, @code{strncmp}, @code{strncpy},
14430@code{strpbrk}, @code{strrchr}, @code{strspn}, @code{strstr},
14431@code{tanh}, @code{tan}, @code{vfprintf}, @code{vprintf} and @code{vsprintf}
14432are all recognized as built-in functions unless
14433@option{-fno-builtin} is specified (or @option{-fno-builtin-@var{function}}
14434is specified for an individual function). All of these functions have
14435corresponding versions prefixed with @code{__builtin_}.
14436
14437GCC provides built-in versions of the ISO C99 floating-point comparison
14438macros that avoid raising exceptions for unordered operands. They have
14439the same names as the standard macros ( @code{isgreater},
14440@code{isgreaterequal}, @code{isless}, @code{islessequal},
14441@code{islessgreater}, and @code{isunordered}) , with @code{__builtin_}
14442prefixed. We intend for a library implementor to be able to simply
14443@code{#define} each standard macro to its built-in equivalent.
34cf27a6
FXC
14444In the same fashion, GCC provides @code{fpclassify}, @code{iseqsig},
14445@code{isfinite}, @code{isinf_sign}, @code{isnormal} and @code{signbit} built-ins
14446used with @code{__builtin_} prefixed. The @code{isinf} and @code{isnan}
d77de738
ML
14447built-in functions appear both with and without the @code{__builtin_} prefix.
14448With @code{-ffinite-math-only} option the @code{isinf} and @code{isnan}
14449built-in functions will always return 0.
14450
14451GCC provides built-in versions of the ISO C99 floating-point rounding and
14452exceptions handling functions @code{fegetround}, @code{feclearexcept} and
14453@code{feraiseexcept}. They may not be available for all targets, and because
14454they need close interaction with libc internal values, they may not be available
14455for all target libcs, but in all cases they will gracefully fallback to libc
14456calls. These built-in functions appear both with and without the
14457@code{__builtin_} prefix.
14458
23795106 14459@defbuiltin{{void *} __builtin_alloca (size_t @var{size})}
d77de738
ML
14460The @code{__builtin_alloca} function must be called at block scope.
14461The function allocates an object @var{size} bytes large on the stack
14462of the calling function. The object is aligned on the default stack
14463alignment boundary for the target determined by the
14464@code{__BIGGEST_ALIGNMENT__} macro. The @code{__builtin_alloca}
14465function returns a pointer to the first byte of the allocated object.
14466The lifetime of the allocated object ends just before the calling
14467function returns to its caller. This is so even when
14468@code{__builtin_alloca} is called within a nested block.
14469
14470For example, the following function allocates eight objects of @code{n}
14471bytes each on the stack, storing a pointer to each in consecutive elements
14472of the array @code{a}. It then passes the array to function @code{g}
14473which can safely use the storage pointed to by each of the array elements.
14474
14475@smallexample
14476void f (unsigned n)
14477@{
14478 void *a [8];
14479 for (int i = 0; i != 8; ++i)
14480 a [i] = __builtin_alloca (n);
14481
14482 g (a, n); // @r{safe}
14483@}
14484@end smallexample
14485
14486Since the @code{__builtin_alloca} function doesn't validate its argument
14487it is the responsibility of its caller to make sure the argument doesn't
14488cause it to exceed the stack size limit.
14489The @code{__builtin_alloca} function is provided to make it possible to
14490allocate on the stack arrays of bytes with an upper bound that may be
14491computed at run time. Since C99 Variable Length Arrays offer
14492similar functionality under a portable, more convenient, and safer
14493interface they are recommended instead, in both C99 and C++ programs
14494where GCC provides them as an extension.
14495@xref{Variable Length}, for details.
14496
f25efe50 14497@enddefbuiltin
d77de738 14498
23795106 14499@defbuiltin{{void *} __builtin_alloca_with_align (size_t @var{size}, size_t @var{alignment})}
d77de738
ML
14500The @code{__builtin_alloca_with_align} function must be called at block
14501scope. The function allocates an object @var{size} bytes large on
14502the stack of the calling function. The allocated object is aligned on
14503the boundary specified by the argument @var{alignment} whose unit is given
14504in bits (not bytes). The @var{size} argument must be positive and not
14505exceed the stack size limit. The @var{alignment} argument must be a constant
14506integer expression that evaluates to a power of 2 greater than or equal to
14507@code{CHAR_BIT} and less than some unspecified maximum. Invocations
14508with other values are rejected with an error indicating the valid bounds.
14509The function returns a pointer to the first byte of the allocated object.
14510The lifetime of the allocated object ends at the end of the block in which
14511the function was called. The allocated storage is released no later than
14512just before the calling function returns to its caller, but may be released
14513at the end of the block in which the function was called.
14514
14515For example, in the following function the call to @code{g} is unsafe
14516because when @code{overalign} is non-zero, the space allocated by
14517@code{__builtin_alloca_with_align} may have been released at the end
14518of the @code{if} statement in which it was called.
14519
14520@smallexample
14521void f (unsigned n, bool overalign)
14522@{
14523 void *p;
14524 if (overalign)
14525 p = __builtin_alloca_with_align (n, 64 /* bits */);
14526 else
14527 p = __builtin_alloc (n);
14528
14529 g (p, n); // @r{unsafe}
14530@}
14531@end smallexample
14532
14533Since the @code{__builtin_alloca_with_align} function doesn't validate its
14534@var{size} argument it is the responsibility of its caller to make sure
14535the argument doesn't cause it to exceed the stack size limit.
14536The @code{__builtin_alloca_with_align} function is provided to make
14537it possible to allocate on the stack overaligned arrays of bytes with
14538an upper bound that may be computed at run time. Since C99
14539Variable Length Arrays offer the same functionality under
14540a portable, more convenient, and safer interface they are recommended
14541instead, in both C99 and C++ programs where GCC provides them as
14542an extension. @xref{Variable Length}, for details.
14543
f25efe50 14544@enddefbuiltin
d77de738 14545
23795106 14546@defbuiltin{{void *} __builtin_alloca_with_align_and_max (size_t @var{size}, size_t @var{alignment}, size_t @var{max_size})}
d77de738
ML
14547Similar to @code{__builtin_alloca_with_align} but takes an extra argument
14548specifying an upper bound for @var{size} in case its value cannot be computed
14549at compile time, for use by @option{-fstack-usage}, @option{-Wstack-usage}
14550and @option{-Walloca-larger-than}. @var{max_size} must be a constant integer
14551expression, it has no effect on code generation and no attempt is made to
14552check its compatibility with @var{size}.
14553
f25efe50 14554@enddefbuiltin
d77de738 14555
f25efe50 14556@defbuiltin{bool __builtin_has_attribute (@var{type-or-expression}, @var{attribute})}
d77de738
ML
14557The @code{__builtin_has_attribute} function evaluates to an integer constant
14558expression equal to @code{true} if the symbol or type referenced by
14559the @var{type-or-expression} argument has been declared with
14560the @var{attribute} referenced by the second argument. For
14561an @var{type-or-expression} argument that does not reference a symbol,
14562since attributes do not apply to expressions the built-in consider
14563the type of the argument. Neither argument is evaluated.
14564The @var{type-or-expression} argument is subject to the same
14565restrictions as the argument to @code{typeof} (@pxref{Typeof}). The
14566@var{attribute} argument is an attribute name optionally followed by
14567a comma-separated list of arguments enclosed in parentheses. Both forms
14568of attribute names---with and without double leading and trailing
14569underscores---are recognized. @xref{Attribute Syntax}, for details.
14570When no attribute arguments are specified for an attribute that expects
14571one or more arguments the function returns @code{true} if
14572@var{type-or-expression} has been declared with the attribute regardless
14573of the attribute argument values. Arguments provided for an attribute
14574that expects some are validated and matched up to the provided number.
14575The function returns @code{true} if all provided arguments match. For
14576example, the first call to the function below evaluates to @code{true}
14577because @code{x} is declared with the @code{aligned} attribute but
14578the second call evaluates to @code{false} because @code{x} is declared
14579@code{aligned (8)} and not @code{aligned (4)}.
14580
14581@smallexample
14582__attribute__ ((aligned (8))) int x;
14583_Static_assert (__builtin_has_attribute (x, aligned), "aligned");
14584_Static_assert (!__builtin_has_attribute (x, aligned (4)), "aligned (4)");
14585@end smallexample
14586
14587Due to a limitation the @code{__builtin_has_attribute} function returns
14588@code{false} for the @code{mode} attribute even if the type or variable
14589referenced by the @var{type-or-expression} argument was declared with one.
14590The function is also not supported with labels, and in C with enumerators.
14591
14592Note that unlike the @code{__has_attribute} preprocessor operator which
14593is suitable for use in @code{#if} preprocessing directives
14594@code{__builtin_has_attribute} is an intrinsic function that is not
14595recognized in such contexts.
14596
f25efe50 14597@enddefbuiltin
d77de738 14598
23795106 14599@defbuiltin{@var{type} __builtin_speculation_safe_value (@var{type} @var{val}, @var{type} @var{failval})}
d77de738
ML
14600
14601This built-in function can be used to help mitigate against unsafe
14602speculative execution. @var{type} may be any integral type or any
14603pointer type.
14604
14605@enumerate
14606@item
14607If the CPU is not speculatively executing the code, then @var{val}
14608is returned.
14609@item
14610If the CPU is executing speculatively then either:
14611@itemize
14612@item
14613The function may cause execution to pause until it is known that the
14614code is no-longer being executed speculatively (in which case
14615@var{val} can be returned, as above); or
14616@item
14617The function may use target-dependent speculation tracking state to cause
14618@var{failval} to be returned when it is known that speculative
14619execution has incorrectly predicted a conditional branch operation.
14620@end itemize
14621@end enumerate
14622
14623The second argument, @var{failval}, is optional and defaults to zero
14624if omitted.
14625
14626GCC defines the preprocessor macro
14627@code{__HAVE_BUILTIN_SPECULATION_SAFE_VALUE} for targets that have been
14628updated to support this builtin.
14629
14630The built-in function can be used where a variable appears to be used in a
14631safe way, but the CPU, due to speculative execution may temporarily ignore
14632the bounds checks. Consider, for example, the following function:
14633
14634@smallexample
14635int array[500];
14636int f (unsigned untrusted_index)
14637@{
14638 if (untrusted_index < 500)
14639 return array[untrusted_index];
14640 return 0;
14641@}
14642@end smallexample
14643
14644If the function is called repeatedly with @code{untrusted_index} less
14645than the limit of 500, then a branch predictor will learn that the
14646block of code that returns a value stored in @code{array} will be
14647executed. If the function is subsequently called with an
14648out-of-range value it will still try to execute that block of code
14649first until the CPU determines that the prediction was incorrect
14650(the CPU will unwind any incorrect operations at that point).
14651However, depending on how the result of the function is used, it might be
14652possible to leave traces in the cache that can reveal what was stored
14653at the out-of-bounds location. The built-in function can be used to
14654provide some protection against leaking data in this way by changing
14655the code to:
14656
14657@smallexample
14658int array[500];
14659int f (unsigned untrusted_index)
14660@{
14661 if (untrusted_index < 500)
14662 return array[__builtin_speculation_safe_value (untrusted_index)];
14663 return 0;
14664@}
14665@end smallexample
14666
14667The built-in function will either cause execution to stall until the
14668conditional branch has been fully resolved, or it may permit
14669speculative execution to continue, but using 0 instead of
14670@code{untrusted_value} if that exceeds the limit.
14671
14672If accessing any memory location is potentially unsafe when speculative
14673execution is incorrect, then the code can be rewritten as
14674
14675@smallexample
14676int array[500];
14677int f (unsigned untrusted_index)
14678@{
14679 if (untrusted_index < 500)
14680 return *__builtin_speculation_safe_value (&array[untrusted_index], NULL);
14681 return 0;
14682@}
14683@end smallexample
14684
14685which will cause a @code{NULL} pointer to be used for the unsafe case.
14686
f25efe50 14687@enddefbuiltin
d77de738 14688
f25efe50 14689@defbuiltin{int __builtin_types_compatible_p (@var{type1}, @var{type2})}
d77de738
ML
14690
14691You can use the built-in function @code{__builtin_types_compatible_p} to
14692determine whether two types are the same.
14693
14694This built-in function returns 1 if the unqualified versions of the
14695types @var{type1} and @var{type2} (which are types, not expressions) are
14696compatible, 0 otherwise. The result of this built-in function can be
14697used in integer constant expressions.
14698
14699This built-in function ignores top level qualifiers (e.g., @code{const},
14700@code{volatile}). For example, @code{int} is equivalent to @code{const
14701int}.
14702
14703The type @code{int[]} and @code{int[5]} are compatible. On the other
14704hand, @code{int} and @code{char *} are not compatible, even if the size
14705of their types, on the particular architecture are the same. Also, the
14706amount of pointer indirection is taken into account when determining
14707similarity. Consequently, @code{short *} is not similar to
14708@code{short **}. Furthermore, two types that are typedefed are
14709considered compatible if their underlying types are compatible.
14710
14711An @code{enum} type is not considered to be compatible with another
14712@code{enum} type even if both are compatible with the same integer
14713type; this is what the C standard specifies.
14714For example, @code{enum @{foo, bar@}} is not similar to
14715@code{enum @{hot, dog@}}.
14716
14717You typically use this function in code whose execution varies
14718depending on the arguments' types. For example:
14719
14720@smallexample
14721#define foo(x) \
14722 (@{ \
14723 typeof (x) tmp = (x); \
14724 if (__builtin_types_compatible_p (typeof (x), long double)) \
14725 tmp = foo_long_double (tmp); \
14726 else if (__builtin_types_compatible_p (typeof (x), double)) \
14727 tmp = foo_double (tmp); \
14728 else if (__builtin_types_compatible_p (typeof (x), float)) \
14729 tmp = foo_float (tmp); \
14730 else \
14731 abort (); \
14732 tmp; \
14733 @})
14734@end smallexample
14735
14736@emph{Note:} This construct is only available for C@.
14737
f25efe50 14738@enddefbuiltin
d77de738 14739
f25efe50 14740@defbuiltin{@var{type} __builtin_call_with_static_chain (@var{call_exp}, @var{pointer_exp})}
d77de738
ML
14741
14742The @var{call_exp} expression must be a function call, and the
14743@var{pointer_exp} expression must be a pointer. The @var{pointer_exp}
14744is passed to the function call in the target's static chain location.
14745The result of builtin is the result of the function call.
14746
14747@emph{Note:} This builtin is only available for C@.
14748This builtin can be used to call Go closures from C.
14749
f25efe50 14750@enddefbuiltin
d77de738 14751
f25efe50 14752@defbuiltin{@var{type} __builtin_choose_expr (@var{const_exp}, @var{exp1}, @var{exp2})}
d77de738
ML
14753
14754You can use the built-in function @code{__builtin_choose_expr} to
14755evaluate code depending on the value of a constant expression. This
14756built-in function returns @var{exp1} if @var{const_exp}, which is an
14757integer constant expression, is nonzero. Otherwise it returns @var{exp2}.
14758
14759This built-in function is analogous to the @samp{? :} operator in C,
14760except that the expression returned has its type unaltered by promotion
14761rules. Also, the built-in function does not evaluate the expression
14762that is not chosen. For example, if @var{const_exp} evaluates to @code{true},
14763@var{exp2} is not evaluated even if it has side effects.
14764
14765This built-in function can return an lvalue if the chosen argument is an
14766lvalue.
14767
14768If @var{exp1} is returned, the return type is the same as @var{exp1}'s
14769type. Similarly, if @var{exp2} is returned, its return type is the same
14770as @var{exp2}.
14771
14772Example:
14773
14774@smallexample
14775#define foo(x) \
14776 __builtin_choose_expr ( \
14777 __builtin_types_compatible_p (typeof (x), double), \
14778 foo_double (x), \
14779 __builtin_choose_expr ( \
14780 __builtin_types_compatible_p (typeof (x), float), \
14781 foo_float (x), \
14782 /* @r{The void expression results in a compile-time error} \
14783 @r{when assigning the result to something.} */ \
14784 (void)0))
14785@end smallexample
14786
14787@emph{Note:} This construct is only available for C@. Furthermore, the
14788unused expression (@var{exp1} or @var{exp2} depending on the value of
14789@var{const_exp}) may still generate syntax errors. This may change in
14790future revisions.
14791
f25efe50 14792@enddefbuiltin
d77de738 14793
f25efe50 14794@defbuiltin{@var{type} __builtin_tgmath (@var{functions}, @var{arguments})}
d77de738
ML
14795
14796The built-in function @code{__builtin_tgmath}, available only for C
14797and Objective-C, calls a function determined according to the rules of
14798@code{<tgmath.h>} macros. It is intended to be used in
14799implementations of that header, so that expansions of macros from that
14800header only expand each of their arguments once, to avoid problems
14801when calls to such macros are nested inside the arguments of other
14802calls to such macros; in addition, it results in better diagnostics
14803for invalid calls to @code{<tgmath.h>} macros than implementations
14804using other GNU C language features. For example, the @code{pow}
14805type-generic macro might be defined as:
14806
14807@smallexample
14808#define pow(a, b) __builtin_tgmath (powf, pow, powl, \
14809 cpowf, cpow, cpowl, a, b)
14810@end smallexample
14811
14812The arguments to @code{__builtin_tgmath} are at least two pointers to
14813functions, followed by the arguments to the type-generic macro (which
14814will be passed as arguments to the selected function). All the
14815pointers to functions must be pointers to prototyped functions, none
14816of which may have variable arguments, and all of which must have the
14817same number of parameters; the number of parameters of the first
14818function determines how many arguments to @code{__builtin_tgmath} are
14819interpreted as function pointers, and how many as the arguments to the
14820called function.
14821
14822The types of the specified functions must all be different, but
14823related to each other in the same way as a set of functions that may
14824be selected between by a macro in @code{<tgmath.h>}. This means that
14825the functions are parameterized by a floating-point type @var{t},
14826different for each such function. The function return types may all
14827be the same type, or they may be @var{t} for each function, or they
14828may be the real type corresponding to @var{t} for each function (if
14829some of the types @var{t} are complex). Likewise, for each parameter
14830position, the type of the parameter in that position may always be the
14831same type, or may be @var{t} for each function (this case must apply
14832for at least one parameter position), or may be the real type
14833corresponding to @var{t} for each function.
14834
14835The standard rules for @code{<tgmath.h>} macros are used to find a
14836common type @var{u} from the types of the arguments for parameters
14837whose types vary between the functions; complex integer types (a GNU
5b68fb47
JM
14838extension) are treated like the complex type corresponding to the real
14839floating type that would be chosen for the corresponding real integer type.
d77de738
ML
14840If the function return types vary, or are all the same integer type,
14841the function called is the one for which @var{t} is @var{u}, and it is
14842an error if there is no such function. If the function return types
14843are all the same floating-point type, the type-generic macro is taken
14844to be one of those from TS 18661 that rounds the result to a narrower
14845type; if there is a function for which @var{t} is @var{u}, it is
14846called, and otherwise the first function, if any, for which @var{t}
14847has at least the range and precision of @var{u} is called, and it is
14848an error if there is no such function.
14849
f25efe50 14850@enddefbuiltin
d77de738 14851
f25efe50 14852@defbuiltin{int __builtin_constant_p (@var{exp})}
d77de738 14853You can use the built-in function @code{__builtin_constant_p} to
44271570
RB
14854determine if the expression @var{exp} is known to be constant at
14855compile time and hence that GCC can perform constant-folding on expressions
14856involving that value. The argument of the function is the expression to test.
14857The expression is not evaluated, side-effects are discarded. The function
d77de738 14858returns the integer 1 if the argument is known to be a compile-time
44271570
RB
14859constant and 0 if it is not known to be a compile-time constant.
14860Any expression that has side-effects makes the function return 0.
14861A return of 0 does not indicate that the expression is @emph{not} a constant,
14862but merely that GCC cannot prove it is a constant within the constraints
14863of the active set of optimization options.
d77de738
ML
14864
14865You typically use this function in an embedded application where
14866memory is a critical resource. If you have some complex calculation,
14867you may want it to be folded if it involves constants, but need to call
14868a function if it does not. For example:
14869
14870@smallexample
14871#define Scale_Value(X) \
14872 (__builtin_constant_p (X) \
14873 ? ((X) * SCALE + OFFSET) : Scale (X))
14874@end smallexample
14875
14876You may use this built-in function in either a macro or an inline
14877function. However, if you use it in an inlined function and pass an
14878argument of the function as the argument to the built-in, GCC
14879never returns 1 when you call the inline function with a string constant
14880or compound literal (@pxref{Compound Literals}) and does not return 1
14881when you pass a constant numeric value to the inline function unless you
14882specify the @option{-O} option.
14883
14884You may also use @code{__builtin_constant_p} in initializers for static
14885data. For instance, you can write
14886
14887@smallexample
14888static const int table[] = @{
14889 __builtin_constant_p (EXPRESSION) ? (EXPRESSION) : -1,
14890 /* @r{@dots{}} */
14891@};
14892@end smallexample
14893
14894@noindent
14895This is an acceptable initializer even if @var{EXPRESSION} is not a
14896constant expression, including the case where
14897@code{__builtin_constant_p} returns 1 because @var{EXPRESSION} can be
14898folded to a constant but @var{EXPRESSION} contains operands that are
14899not otherwise permitted in a static initializer (for example,
14900@code{0 && foo ()}). GCC must be more conservative about evaluating the
14901built-in in this case, because it has no opportunity to perform
14902optimization.
f25efe50 14903@enddefbuiltin
d77de738 14904
f25efe50 14905@defbuiltin{bool __builtin_is_constant_evaluated (void)}
d77de738
ML
14906The @code{__builtin_is_constant_evaluated} function is available only
14907in C++. The built-in is intended to be used by implementations of
14908the @code{std::is_constant_evaluated} C++ function. Programs should make
14909use of the latter function rather than invoking the built-in directly.
14910
14911The main use case of the built-in is to determine whether a @code{constexpr}
14912function is being called in a @code{constexpr} context. A call to
14913the function evaluates to a core constant expression with the value
14914@code{true} if and only if it occurs within the evaluation of an expression
14915or conversion that is manifestly constant-evaluated as defined in the C++
14916standard. Manifestly constant-evaluated contexts include constant-expressions,
14917the conditions of @code{constexpr if} statements, constraint-expressions, and
14918initializers of variables usable in constant expressions. For more details
14919refer to the latest revision of the C++ standard.
f25efe50 14920@enddefbuiltin
d77de738 14921
f25efe50 14922@defbuiltin{void __builtin_clear_padding (@var{ptr})}
d77de738
ML
14923The built-in function @code{__builtin_clear_padding} function clears
14924padding bits inside of the object representation of object pointed by
14925@var{ptr}, which has to be a pointer. The value representation of the
14926object is not affected. The type of the object is assumed to be the type
14927the pointer points to. Inside of a union, the only cleared bits are
14928bits that are padding bits for all the union members.
14929
14930This built-in-function is useful if the padding bits of an object might
14931have intederminate values and the object representation needs to be
14932bitwise compared to some other object, for example for atomic operations.
14933
14934For C++, @var{ptr} argument type should be pointer to trivially-copyable
14935type, unless the argument is address of a variable or parameter, because
14936otherwise it isn't known if the type isn't just a base class whose padding
14937bits are reused or laid out differently in a derived class.
f25efe50 14938@enddefbuiltin
d77de738 14939
f25efe50 14940@defbuiltin{@var{type} __builtin_bit_cast (@var{type}, @var{arg})}
d77de738
ML
14941The @code{__builtin_bit_cast} function is available only
14942in C++. The built-in is intended to be used by implementations of
14943the @code{std::bit_cast} C++ template function. Programs should make
14944use of the latter function rather than invoking the built-in directly.
14945
14946This built-in function allows reinterpreting the bits of the @var{arg}
14947argument as if it had type @var{type}. @var{type} and the type of the
14948@var{arg} argument need to be trivially copyable types with the same size.
14949When manifestly constant-evaluated, it performs extra diagnostics required
14950for @code{std::bit_cast} and returns a constant expression if @var{arg}
14951is a constant expression. For more details
14952refer to the latest revision of the C++ standard.
f25efe50 14953@enddefbuiltin
d77de738 14954
f25efe50 14955@defbuiltin{long __builtin_expect (long @var{exp}, long @var{c})}
d77de738
ML
14956@opindex fprofile-arcs
14957You may use @code{__builtin_expect} to provide the compiler with
14958branch prediction information. In general, you should prefer to
14959use actual profile feedback for this (@option{-fprofile-arcs}), as
14960programmers are notoriously bad at predicting how their programs
14961actually perform. However, there are applications in which this
14962data is hard to collect.
14963
14964The return value is the value of @var{exp}, which should be an integral
14965expression. The semantics of the built-in are that it is expected that
14966@var{exp} == @var{c}. For example:
14967
14968@smallexample
14969if (__builtin_expect (x, 0))
14970 foo ();
14971@end smallexample
14972
14973@noindent
14974indicates that we do not expect to call @code{foo}, since
14975we expect @code{x} to be zero. Since you are limited to integral
14976expressions for @var{exp}, you should use constructions such as
14977
14978@smallexample
14979if (__builtin_expect (ptr != NULL, 1))
14980 foo (*ptr);
14981@end smallexample
14982
14983@noindent
14984when testing pointer or floating-point values.
14985
14986For the purposes of branch prediction optimizations, the probability that
14987a @code{__builtin_expect} expression is @code{true} is controlled by GCC's
14988@code{builtin-expect-probability} parameter, which defaults to 90%.
14989
14990You can also use @code{__builtin_expect_with_probability} to explicitly
14991assign a probability value to individual expressions. If the built-in
14992is used in a loop construct, the provided probability will influence
14993the expected number of iterations made by loop optimizations.
f25efe50 14994@enddefbuiltin
d77de738 14995
f25efe50 14996@defbuiltin{long __builtin_expect_with_probability}
d77de738
ML
14997(long @var{exp}, long @var{c}, double @var{probability})
14998
14999This function has the same semantics as @code{__builtin_expect},
15000but the caller provides the expected probability that @var{exp} == @var{c}.
15001The last argument, @var{probability}, is a floating-point value in the
15002range 0.0 to 1.0, inclusive. The @var{probability} argument must be
15003constant floating-point expression.
f25efe50 15004@enddefbuiltin
d77de738 15005
f25efe50 15006@defbuiltin{void __builtin_trap (void)}
d77de738
ML
15007This function causes the program to exit abnormally. GCC implements
15008this function by using a target-dependent mechanism (such as
15009intentionally executing an illegal instruction) or by calling
15010@code{abort}. The mechanism used may vary from release to release so
15011you should not rely on any particular implementation.
f25efe50 15012@enddefbuiltin
d77de738 15013
f25efe50 15014@defbuiltin{void __builtin_unreachable (void)}
d77de738
ML
15015If control flow reaches the point of the @code{__builtin_unreachable},
15016the program is undefined. It is useful in situations where the
15017compiler cannot deduce the unreachability of the code.
15018
15019One such case is immediately following an @code{asm} statement that
15020either never terminates, or one that transfers control elsewhere
15021and never returns. In this example, without the
15022@code{__builtin_unreachable}, GCC issues a warning that control
15023reaches the end of a non-void function. It also generates code
15024to return after the @code{asm}.
15025
15026@smallexample
15027int f (int c, int v)
15028@{
15029 if (c)
15030 @{
15031 return v;
15032 @}
15033 else
15034 @{
15035 asm("jmp error_handler");
15036 __builtin_unreachable ();
15037 @}
15038@}
15039@end smallexample
15040
15041@noindent
15042Because the @code{asm} statement unconditionally transfers control out
15043of the function, control never reaches the end of the function
15044body. The @code{__builtin_unreachable} is in fact unreachable and
15045communicates this fact to the compiler.
15046
15047Another use for @code{__builtin_unreachable} is following a call a
15048function that never returns but that is not declared
15049@code{__attribute__((noreturn))}, as in this example:
15050
15051@smallexample
15052void function_that_never_returns (void);
15053
15054int g (int c)
15055@{
15056 if (c)
15057 @{
15058 return 1;
15059 @}
15060 else
15061 @{
15062 function_that_never_returns ();
15063 __builtin_unreachable ();
15064 @}
15065@}
15066@end smallexample
15067
f25efe50 15068@enddefbuiltin
d77de738 15069
f25efe50 15070@defbuiltin{@var{type} __builtin_assoc_barrier (@var{type} @var{expr})}
d77de738
ML
15071This built-in inhibits re-association of the floating-point expression
15072@var{expr} with expressions consuming the return value of the built-in. The
15073expression @var{expr} itself can be reordered, and the whole expression
15074@var{expr} can be reordered with operands after the barrier. The barrier is
15075only relevant when @code{-fassociative-math} is active, since otherwise
15076floating-point is not treated as associative.
15077
15078@smallexample
15079float x0 = a + b - b;
15080float x1 = __builtin_assoc_barrier(a + b) - b;
15081@end smallexample
15082
15083@noindent
15084means that, with @code{-fassociative-math}, @code{x0} can be optimized to
15085@code{x0 = a} but @code{x1} cannot.
f25efe50 15086@enddefbuiltin
d77de738 15087
f25efe50 15088@defbuiltin{{void *} __builtin_assume_aligned (const void *@var{exp}, size_t @var{align}, ...)}
d77de738
ML
15089This function returns its first argument, and allows the compiler
15090to assume that the returned pointer is at least @var{align} bytes
15091aligned. This built-in can have either two or three arguments,
15092if it has three, the third argument should have integer type, and
15093if it is nonzero means misalignment offset. For example:
15094
15095@smallexample
15096void *x = __builtin_assume_aligned (arg, 16);
15097@end smallexample
15098
15099@noindent
15100means that the compiler can assume @code{x}, set to @code{arg}, is at least
1510116-byte aligned, while:
15102
15103@smallexample
15104void *x = __builtin_assume_aligned (arg, 32, 8);
15105@end smallexample
15106
15107@noindent
15108means that the compiler can assume for @code{x}, set to @code{arg}, that
15109@code{(char *) x - 8} is 32-byte aligned.
f25efe50 15110@enddefbuiltin
d77de738 15111
f25efe50 15112@defbuiltin{int __builtin_LINE ()}
d77de738
ML
15113This function is the equivalent of the preprocessor @code{__LINE__}
15114macro and returns a constant integer expression that evaluates to
15115the line number of the invocation of the built-in. When used as a C++
15116default argument for a function @var{F}, it returns the line number
15117of the call to @var{F}.
f25efe50 15118@enddefbuiltin
d77de738 15119
f25efe50 15120@defbuiltin{{const char *} __builtin_FUNCTION ()}
d77de738
ML
15121This function is the equivalent of the @code{__FUNCTION__} symbol
15122and returns an address constant pointing to the name of the function
15123from which the built-in was invoked, or the empty string if
15124the invocation is not at function scope. When used as a C++ default
15125argument for a function @var{F}, it returns the name of @var{F}'s
15126caller or the empty string if the call was not made at function
15127scope.
f25efe50 15128@enddefbuiltin
d77de738 15129
f25efe50 15130@defbuiltin{{const char *} __builtin_FILE ()}
d77de738
ML
15131This function is the equivalent of the preprocessor @code{__FILE__}
15132macro and returns an address constant pointing to the file name
15133containing the invocation of the built-in, or the empty string if
15134the invocation is not at function scope. When used as a C++ default
15135argument for a function @var{F}, it returns the file name of the call
15136to @var{F} or the empty string if the call was not made at function
15137scope.
15138
15139For example, in the following, each call to function @code{foo} will
15140print a line similar to @code{"file.c:123: foo: message"} with the name
15141of the file and the line number of the @code{printf} call, the name of
15142the function @code{foo}, followed by the word @code{message}.
15143
15144@smallexample
15145const char*
15146function (const char *func = __builtin_FUNCTION ())
15147@{
15148 return func;
15149@}
15150
15151void foo (void)
15152@{
15153 printf ("%s:%i: %s: message\n", file (), line (), function ());
15154@}
15155@end smallexample
15156
f25efe50 15157@enddefbuiltin
d77de738 15158
f25efe50 15159@defbuiltin{void __builtin___clear_cache (void *@var{begin}, void *@var{end})}
d77de738
ML
15160This function is used to flush the processor's instruction cache for
15161the region of memory between @var{begin} inclusive and @var{end}
15162exclusive. Some targets require that the instruction cache be
15163flushed, after modifying memory containing code, in order to obtain
15164deterministic behavior.
15165
15166If the target does not require instruction cache flushes,
15167@code{__builtin___clear_cache} has no effect. Otherwise either
15168instructions are emitted in-line to clear the instruction cache or a
15169call to the @code{__clear_cache} function in libgcc is made.
f25efe50 15170@enddefbuiltin
d77de738 15171
f25efe50 15172@defbuiltin{void __builtin_prefetch (const void *@var{addr}, ...)}
d77de738
ML
15173This function is used to minimize cache-miss latency by moving data into
15174a cache before it is accessed.
15175You can insert calls to @code{__builtin_prefetch} into code for which
15176you know addresses of data in memory that is likely to be accessed soon.
15177If the target supports them, data prefetch instructions are generated.
15178If the prefetch is done early enough before the access then the data will
15179be in the cache by the time it is accessed.
15180
15181The value of @var{addr} is the address of the memory to prefetch.
15182There are two optional arguments, @var{rw} and @var{locality}.
15183The value of @var{rw} is a compile-time constant one or zero; one
15184means that the prefetch is preparing for a write to the memory address
15185and zero, the default, means that the prefetch is preparing for a read.
15186The value @var{locality} must be a compile-time constant integer between
15187zero and three. A value of zero means that the data has no temporal
15188locality, so it need not be left in the cache after the access. A value
15189of three means that the data has a high degree of temporal locality and
15190should be left in all levels of cache possible. Values of one and two
15191mean, respectively, a low or moderate degree of temporal locality. The
15192default is three.
15193
15194@smallexample
15195for (i = 0; i < n; i++)
15196 @{
15197 a[i] = a[i] + b[i];
15198 __builtin_prefetch (&a[i+j], 1, 1);
15199 __builtin_prefetch (&b[i+j], 0, 1);
15200 /* @r{@dots{}} */
15201 @}
15202@end smallexample
15203
15204Data prefetch does not generate faults if @var{addr} is invalid, but
15205the address expression itself must be valid. For example, a prefetch
15206of @code{p->next} does not fault if @code{p->next} is not a valid
15207address, but evaluation faults if @code{p} is not a valid address.
15208
15209If the target does not support data prefetch, the address expression
15210is evaluated if it includes side effects but no other code is generated
15211and GCC does not issue a warning.
f25efe50 15212@enddefbuiltin
d77de738 15213
f25efe50 15214@defbuiltin{{size_t} __builtin_object_size (const void * @var{ptr}, int @var{type})}
f5300d28
SP
15215Returns a constant size estimate of an object pointed to by @var{ptr}.
15216@xref{Object Size Checking}, for a detailed description of the function.
f25efe50 15217@enddefbuiltin
f5300d28 15218
f25efe50 15219@defbuiltin{{size_t} __builtin_dynamic_object_size (const void * @var{ptr}, int @var{type})}
f5300d28
SP
15220Similar to @code{__builtin_object_size} except that the return value
15221need not be a constant. @xref{Object Size Checking}, for a detailed
15222description of the function.
f25efe50 15223@enddefbuiltin
d77de738 15224
53d834a7
JJ
15225@defbuiltin{int __builtin_classify_type (@var{arg})}
15226@defbuiltinx{int __builtin_classify_type (@var{type})}
15227The @code{__builtin_classify_type} returns a small integer with a category
15228of @var{arg} argument's type, like void type, integer type, enumeral type,
15229boolean type, pointer type, reference type, offset type, real type, complex
15230type, function type, method type, record type, union type, array type,
509b470d
JJ
15231string type, bit-precise integer type, vector type, etc. When the argument
15232is an expression, for backwards compatibility reason the argument is promoted
15233like arguments passed to @code{...} in varargs function, so some classes are
15234never returned in certain languages. Alternatively, the argument of the
15235built-in function can be a typename, such as the @code{typeof} specifier.
53d834a7
JJ
15236
15237@smallexample
15238int a[2];
15239__builtin_classify_type (a) == __builtin_classify_type (int[5]);
15240__builtin_classify_type (a) == __builtin_classify_type (void*);
15241__builtin_classify_type (typeof (a)) == __builtin_classify_type (int[5]);
15242@end smallexample
15243
15244The first comparison will never be true, as @var{a} is implicitly converted
15245to pointer. The last two comparisons will be true as they classify
15246pointers in the second case and arrays in the last case.
15247@enddefbuiltin
15248
f25efe50 15249@defbuiltin{double __builtin_huge_val (void)}
d77de738
ML
15250Returns a positive infinity, if supported by the floating-point format,
15251else @code{DBL_MAX}. This function is suitable for implementing the
15252ISO C macro @code{HUGE_VAL}.
f25efe50 15253@enddefbuiltin
d77de738 15254
f25efe50 15255@defbuiltin{float __builtin_huge_valf (void)}
d77de738 15256Similar to @code{__builtin_huge_val}, except the return type is @code{float}.
f25efe50 15257@enddefbuiltin
d77de738 15258
f25efe50 15259@defbuiltin{{long double} __builtin_huge_vall (void)}
d77de738
ML
15260Similar to @code{__builtin_huge_val}, except the return
15261type is @code{long double}.
f25efe50 15262@enddefbuiltin
d77de738 15263
f25efe50 15264@defbuiltin{_Float@var{n} __builtin_huge_valf@var{n} (void)}
d77de738
ML
15265Similar to @code{__builtin_huge_val}, except the return type is
15266@code{_Float@var{n}}.
f25efe50 15267@enddefbuiltin
d77de738 15268
f25efe50 15269@defbuiltin{_Float@var{n}x __builtin_huge_valf@var{n}x (void)}
d77de738
ML
15270Similar to @code{__builtin_huge_val}, except the return type is
15271@code{_Float@var{n}x}.
f25efe50 15272@enddefbuiltin
d77de738 15273
f25efe50 15274@defbuiltin{int __builtin_fpclassify (int, int, int, int, int, ...)}
d77de738
ML
15275This built-in implements the C99 fpclassify functionality. The first
15276five int arguments should be the target library's notion of the
15277possible FP classes and are used for return values. They must be
15278constant values and they must appear in this order: @code{FP_NAN},
15279@code{FP_INFINITE}, @code{FP_NORMAL}, @code{FP_SUBNORMAL} and
15280@code{FP_ZERO}. The ellipsis is for exactly one floating-point value
15281to classify. GCC treats the last argument as type-generic, which
15282means it does not do default promotion from float to double.
f25efe50 15283@enddefbuiltin
d77de738 15284
f25efe50 15285@defbuiltin{double __builtin_inf (void)}
d77de738
ML
15286Similar to @code{__builtin_huge_val}, except a warning is generated
15287if the target floating-point format does not support infinities.
f25efe50 15288@enddefbuiltin
d77de738 15289
f25efe50 15290@defbuiltin{_Decimal32 __builtin_infd32 (void)}
d77de738 15291Similar to @code{__builtin_inf}, except the return type is @code{_Decimal32}.
f25efe50 15292@enddefbuiltin
d77de738 15293
f25efe50 15294@defbuiltin{_Decimal64 __builtin_infd64 (void)}
d77de738 15295Similar to @code{__builtin_inf}, except the return type is @code{_Decimal64}.
f25efe50 15296@enddefbuiltin
d77de738 15297
f25efe50 15298@defbuiltin{_Decimal128 __builtin_infd128 (void)}
d77de738 15299Similar to @code{__builtin_inf}, except the return type is @code{_Decimal128}.
f25efe50 15300@enddefbuiltin
d77de738 15301
f25efe50 15302@defbuiltin{float __builtin_inff (void)}
d77de738
ML
15303Similar to @code{__builtin_inf}, except the return type is @code{float}.
15304This function is suitable for implementing the ISO C99 macro @code{INFINITY}.
f25efe50 15305@enddefbuiltin
d77de738 15306
f25efe50 15307@defbuiltin{{long double} __builtin_infl (void)}
d77de738
ML
15308Similar to @code{__builtin_inf}, except the return
15309type is @code{long double}.
f25efe50 15310@enddefbuiltin
d77de738 15311
f25efe50 15312@defbuiltin{_Float@var{n} __builtin_inff@var{n} (void)}
d77de738
ML
15313Similar to @code{__builtin_inf}, except the return
15314type is @code{_Float@var{n}}.
f25efe50 15315@enddefbuiltin
d77de738 15316
f25efe50 15317@defbuiltin{_Float@var{n} __builtin_inff@var{n}x (void)}
d77de738
ML
15318Similar to @code{__builtin_inf}, except the return
15319type is @code{_Float@var{n}x}.
f25efe50 15320@enddefbuiltin
d77de738 15321
f25efe50 15322@defbuiltin{int __builtin_isinf_sign (...)}
d77de738
ML
15323Similar to @code{isinf}, except the return value is -1 for
15324an argument of @code{-Inf} and 1 for an argument of @code{+Inf}.
15325Note while the parameter list is an
15326ellipsis, this function only accepts exactly one floating-point
15327argument. GCC treats this parameter as type-generic, which means it
15328does not do default promotion from float to double.
f25efe50 15329@enddefbuiltin
d77de738 15330
23795106 15331@defbuiltin{double __builtin_nan (const char *@var{str})}
d77de738
ML
15332This is an implementation of the ISO C99 function @code{nan}.
15333
15334Since ISO C99 defines this function in terms of @code{strtod}, which we
15335do not implement, a description of the parsing is in order. The string
15336is parsed as by @code{strtol}; that is, the base is recognized by
15337leading @samp{0} or @samp{0x} prefixes. The number parsed is placed
15338in the significand such that the least significant bit of the number
15339is at the least significant bit of the significand. The number is
15340truncated to fit the significand field provided. The significand is
15341forced to be a quiet NaN@.
15342
15343This function, if given a string literal all of which would have been
15344consumed by @code{strtol}, is evaluated early enough that it is considered a
15345compile-time constant.
f25efe50 15346@enddefbuiltin
d77de738 15347
23795106 15348@defbuiltin{_Decimal32 __builtin_nand32 (const char *@var{str})}
d77de738 15349Similar to @code{__builtin_nan}, except the return type is @code{_Decimal32}.
f25efe50 15350@enddefbuiltin
d77de738 15351
23795106 15352@defbuiltin{_Decimal64 __builtin_nand64 (const char *@var{str})}
d77de738 15353Similar to @code{__builtin_nan}, except the return type is @code{_Decimal64}.
f25efe50 15354@enddefbuiltin
d77de738 15355
23795106 15356@defbuiltin{_Decimal128 __builtin_nand128 (const char *@var{str})}
d77de738 15357Similar to @code{__builtin_nan}, except the return type is @code{_Decimal128}.
f25efe50 15358@enddefbuiltin
d77de738 15359
23795106 15360@defbuiltin{float __builtin_nanf (const char *@var{str})}
d77de738 15361Similar to @code{__builtin_nan}, except the return type is @code{float}.
f25efe50 15362@enddefbuiltin
d77de738 15363
23795106 15364@defbuiltin{{long double} __builtin_nanl (const char *@var{str})}
d77de738 15365Similar to @code{__builtin_nan}, except the return type is @code{long double}.
f25efe50 15366@enddefbuiltin
d77de738 15367
23795106 15368@defbuiltin{_Float@var{n} __builtin_nanf@var{n} (const char *@var{str})}
d77de738
ML
15369Similar to @code{__builtin_nan}, except the return type is
15370@code{_Float@var{n}}.
f25efe50 15371@enddefbuiltin
d77de738 15372
23795106 15373@defbuiltin{_Float@var{n}x __builtin_nanf@var{n}x (const char *@var{str})}
d77de738
ML
15374Similar to @code{__builtin_nan}, except the return type is
15375@code{_Float@var{n}x}.
f25efe50 15376@enddefbuiltin
d77de738 15377
23795106 15378@defbuiltin{double __builtin_nans (const char *@var{str})}
d77de738
ML
15379Similar to @code{__builtin_nan}, except the significand is forced
15380to be a signaling NaN@. The @code{nans} function is proposed by
d1bf1c97 15381@uref{https://www.open-std.org/jtc1/sc22/wg14/www/docs/n965.htm,,WG14 N965}.
f25efe50 15382@enddefbuiltin
d77de738 15383
23795106 15384@defbuiltin{_Decimal32 __builtin_nansd32 (const char *@var{str})}
d77de738 15385Similar to @code{__builtin_nans}, except the return type is @code{_Decimal32}.
f25efe50 15386@enddefbuiltin
d77de738 15387
23795106 15388@defbuiltin{_Decimal64 __builtin_nansd64 (const char *@var{str})}
d77de738 15389Similar to @code{__builtin_nans}, except the return type is @code{_Decimal64}.
f25efe50 15390@enddefbuiltin
d77de738 15391
23795106 15392@defbuiltin{_Decimal128 __builtin_nansd128 (const char *@var{str})}
d77de738 15393Similar to @code{__builtin_nans}, except the return type is @code{_Decimal128}.
f25efe50 15394@enddefbuiltin
d77de738 15395
23795106 15396@defbuiltin{float __builtin_nansf (const char *@var{str})}
d77de738 15397Similar to @code{__builtin_nans}, except the return type is @code{float}.
f25efe50 15398@enddefbuiltin
d77de738 15399
23795106 15400@defbuiltin{{long double} __builtin_nansl (const char *@var{str})}
d77de738 15401Similar to @code{__builtin_nans}, except the return type is @code{long double}.
f25efe50 15402@enddefbuiltin
d77de738 15403
23795106 15404@defbuiltin{_Float@var{n} __builtin_nansf@var{n} (const char *@var{str})}
d77de738
ML
15405Similar to @code{__builtin_nans}, except the return type is
15406@code{_Float@var{n}}.
f25efe50 15407@enddefbuiltin
d77de738 15408
23795106 15409@defbuiltin{_Float@var{n}x __builtin_nansf@var{n}x (const char *@var{str})}
d77de738
ML
15410Similar to @code{__builtin_nans}, except the return type is
15411@code{_Float@var{n}x}.
f25efe50 15412@enddefbuiltin
d77de738 15413
f25efe50 15414@defbuiltin{int __builtin_issignaling (...)}
d77de738
ML
15415Return non-zero if the argument is a signaling NaN and zero otherwise.
15416Note while the parameter list is an
15417ellipsis, this function only accepts exactly one floating-point
15418argument. GCC treats this parameter as type-generic, which means it
15419does not do default promotion from float to double.
15420This built-in function can work even without the non-default
15421@code{-fsignaling-nans} option, although if a signaling NaN is computed,
15422stored or passed as argument to some function other than this built-in
15423in the current translation unit, it is safer to use @code{-fsignaling-nans}.
15424With @code{-ffinite-math-only} option this built-in function will always
15425return 0.
f25efe50 15426@enddefbuiltin
d77de738 15427
23795106 15428@defbuiltin{int __builtin_ffs (int @var{x})}
d77de738
ML
15429Returns one plus the index of the least significant 1-bit of @var{x}, or
15430if @var{x} is zero, returns zero.
f25efe50 15431@enddefbuiltin
d77de738 15432
23795106 15433@defbuiltin{int __builtin_clz (unsigned int @var{x})}
d77de738
ML
15434Returns the number of leading 0-bits in @var{x}, starting at the most
15435significant bit position. If @var{x} is 0, the result is undefined.
f25efe50 15436@enddefbuiltin
d77de738 15437
23795106 15438@defbuiltin{int __builtin_ctz (unsigned int @var{x})}
d77de738
ML
15439Returns the number of trailing 0-bits in @var{x}, starting at the least
15440significant bit position. If @var{x} is 0, the result is undefined.
f25efe50 15441@enddefbuiltin
d77de738 15442
23795106 15443@defbuiltin{int __builtin_clrsb (int @var{x})}
d77de738
ML
15444Returns the number of leading redundant sign bits in @var{x}, i.e.@: the
15445number of bits following the most significant bit that are identical
15446to it. There are no special cases for 0 or other values.
f25efe50 15447@enddefbuiltin
d77de738 15448
23795106 15449@defbuiltin{int __builtin_popcount (unsigned int @var{x})}
d77de738 15450Returns the number of 1-bits in @var{x}.
f25efe50 15451@enddefbuiltin
d77de738 15452
23795106 15453@defbuiltin{int __builtin_parity (unsigned int @var{x})}
d77de738
ML
15454Returns the parity of @var{x}, i.e.@: the number of 1-bits in @var{x}
15455modulo 2.
f25efe50 15456@enddefbuiltin
d77de738 15457
f25efe50 15458@defbuiltin{int __builtin_ffsl (long)}
d77de738
ML
15459Similar to @code{__builtin_ffs}, except the argument type is
15460@code{long}.
f25efe50 15461@enddefbuiltin
d77de738 15462
f25efe50 15463@defbuiltin{int __builtin_clzl (unsigned long)}
d77de738
ML
15464Similar to @code{__builtin_clz}, except the argument type is
15465@code{unsigned long}.
f25efe50 15466@enddefbuiltin
d77de738 15467
f25efe50 15468@defbuiltin{int __builtin_ctzl (unsigned long)}
d77de738
ML
15469Similar to @code{__builtin_ctz}, except the argument type is
15470@code{unsigned long}.
f25efe50 15471@enddefbuiltin
d77de738 15472
f25efe50 15473@defbuiltin{int __builtin_clrsbl (long)}
d77de738
ML
15474Similar to @code{__builtin_clrsb}, except the argument type is
15475@code{long}.
f25efe50 15476@enddefbuiltin
d77de738 15477
f25efe50 15478@defbuiltin{int __builtin_popcountl (unsigned long)}
d77de738
ML
15479Similar to @code{__builtin_popcount}, except the argument type is
15480@code{unsigned long}.
f25efe50 15481@enddefbuiltin
d77de738 15482
f25efe50 15483@defbuiltin{int __builtin_parityl (unsigned long)}
d77de738
ML
15484Similar to @code{__builtin_parity}, except the argument type is
15485@code{unsigned long}.
f25efe50 15486@enddefbuiltin
d77de738 15487
f25efe50 15488@defbuiltin{int __builtin_ffsll (long long)}
d77de738
ML
15489Similar to @code{__builtin_ffs}, except the argument type is
15490@code{long long}.
f25efe50 15491@enddefbuiltin
d77de738 15492
f25efe50 15493@defbuiltin{int __builtin_clzll (unsigned long long)}
d77de738
ML
15494Similar to @code{__builtin_clz}, except the argument type is
15495@code{unsigned long long}.
f25efe50 15496@enddefbuiltin
d77de738 15497
f25efe50 15498@defbuiltin{int __builtin_ctzll (unsigned long long)}
d77de738
ML
15499Similar to @code{__builtin_ctz}, except the argument type is
15500@code{unsigned long long}.
f25efe50 15501@enddefbuiltin
d77de738 15502
f25efe50 15503@defbuiltin{int __builtin_clrsbll (long long)}
d77de738
ML
15504Similar to @code{__builtin_clrsb}, except the argument type is
15505@code{long long}.
f25efe50 15506@enddefbuiltin
d77de738 15507
f25efe50 15508@defbuiltin{int __builtin_popcountll (unsigned long long)}
d77de738
ML
15509Similar to @code{__builtin_popcount}, except the argument type is
15510@code{unsigned long long}.
f25efe50 15511@enddefbuiltin
d77de738 15512
f25efe50 15513@defbuiltin{int __builtin_parityll (unsigned long long)}
d77de738
ML
15514Similar to @code{__builtin_parity}, except the argument type is
15515@code{unsigned long long}.
f25efe50 15516@enddefbuiltin
d77de738 15517
7383cb56
JJ
15518@defbuiltin{int __builtin_ffsg (...)}
15519Similar to @code{__builtin_ffs}, except the argument is type-generic
15520signed integer (standard, extended or bit-precise). No integral argument
15521promotions are performed on the argument.
15522@enddefbuiltin
15523
15524@defbuiltin{int __builtin_clzg (...)}
15525Similar to @code{__builtin_clz}, except the argument is type-generic
15526unsigned integer (standard, extended or bit-precise) and there is
15527optional second argument with int type. No integral argument promotions
15528are performed on the first argument. If two arguments are specified,
15529and first argument is 0, the result is the second argument. If only
15530one argument is specified and it is 0, the result is undefined.
15531@enddefbuiltin
15532
15533@defbuiltin{int __builtin_ctzg (...)}
15534Similar to @code{__builtin_ctz}, except the argument is type-generic
15535unsigned integer (standard, extended or bit-precise) and there is
15536optional second argument with int type. No integral argument promotions
15537are performed on the first argument. If two arguments are specified,
15538and first argument is 0, the result is the second argument. If only
15539one argument is specified and it is 0, the result is undefined.
15540@enddefbuiltin
15541
15542@defbuiltin{int __builtin_clrsbg (...)}
15543Similar to @code{__builtin_clrsb}, except the argument is type-generic
15544signed integer (standard, extended or bit-precise). No integral argument
15545promotions are performed on the argument.
15546@enddefbuiltin
15547
15548@defbuiltin{int __builtin_popcountg (...)}
15549Similar to @code{__builtin_popcount}, except the argument is type-generic
15550unsigned integer (standard, extended or bit-precise). No integral argument
15551promotions are performed on the argument.
15552@enddefbuiltin
15553
15554@defbuiltin{int __builtin_parityg (...)}
15555Similar to @code{__builtin_parity}, except the argument is type-generic
15556unsigned integer (standard, extended or bit-precise). No integral argument
15557promotions are performed on the argument.
15558@enddefbuiltin
15559
03c7149d
JJ
15560@defbuiltin{@var{type} __builtin_stdc_bit_ceil (@var{type} @var{arg})}
15561The @code{__builtin_stdc_bit_ceil} function is available only
15562in C. It is type-generic, the argument can be any unsigned integer
15563(standard, extended or bit-precise). No integral argument promotions are
15564performed on the argument. It is equivalent to
15565@code{@var{arg} <= 1 ? (@var{type}) 1
15566: (@var{type}) 2 << (@var{prec} - 1 - __builtin_clzg ((@var{type}) (@var{arg} - 1)))}
15567where @var{prec} is bit width of @var{type}, except that side-effects
15568in @var{arg} are evaluated just once.
15569@enddefbuiltin
15570
15571@defbuiltin{@var{type} __builtin_stdc_bit_floor (@var{type} @var{arg})}
15572The @code{__builtin_stdc_bit_floor} function is available only
15573in C. It is type-generic, the argument can be any unsigned integer
15574(standard, extended or bit-precise). No integral argument promotions are
15575performed on the argument. It is equivalent to
15576@code{@var{arg} == 0 ? (@var{type}) 0
15577: (@var{type}) 1 << (@var{prec} - 1 - __builtin_clzg (@var{arg}))}
15578where @var{prec} is bit width of @var{type}, except that side-effects
15579in @var{arg} are evaluated just once.
15580@enddefbuiltin
15581
ff99671a 15582@defbuiltin{{unsigned int} __builtin_stdc_bit_width (@var{type} @var{arg})}
03c7149d
JJ
15583The @code{__builtin_stdc_bit_width} function is available only
15584in C. It is type-generic, the argument can be any unsigned integer
15585(standard, extended or bit-precise). No integral argument promotions are
15586performed on the argument. It is equivalent to
15587@code{(unsigned int) (@var{prec} - __builtin_clzg (@var{arg}, @var{prec}))}
15588where @var{prec} is bit width of @var{type}.
15589@enddefbuiltin
15590
ff99671a 15591@defbuiltin{{unsigned int} __builtin_stdc_count_ones (@var{type} @var{arg})}
03c7149d
JJ
15592The @code{__builtin_stdc_count_ones} function is available only
15593in C. It is type-generic, the argument can be any unsigned integer
15594(standard, extended or bit-precise). No integral argument promotions are
15595performed on the argument. It is equivalent to
15596@code{(unsigned int) __builtin_popcountg (@var{arg})}
15597@enddefbuiltin
15598
ff99671a 15599@defbuiltin{{unsigned int} __builtin_stdc_count_zeros (@var{type} @var{arg})}
03c7149d
JJ
15600The @code{__builtin_stdc_count_zeros} function is available only
15601in C. It is type-generic, the argument can be any unsigned integer
15602(standard, extended or bit-precise). No integral argument promotions are
15603performed on the argument. It is equivalent to
15604@code{(unsigned int) __builtin_popcountg ((@var{type}) ~@var{arg})}
15605@enddefbuiltin
15606
ff99671a 15607@defbuiltin{{unsigned int} __builtin_stdc_first_leading_one (@var{type} @var{arg})}
03c7149d
JJ
15608The @code{__builtin_stdc_first_leading_one} function is available only
15609in C. It is type-generic, the argument can be any unsigned integer
15610(standard, extended or bit-precise). No integral argument promotions are
15611performed on the argument. It is equivalent to
15612@code{__builtin_clzg (@var{arg}, -1) + 1U}
15613@enddefbuiltin
15614
ff99671a 15615@defbuiltin{{unsigned int} __builtin_stdc_first_leading_zero (@var{type} @var{arg})}
03c7149d
JJ
15616The @code{__builtin_stdc_first_leading_zero} function is available only
15617in C. It is type-generic, the argument can be any unsigned integer
15618(standard, extended or bit-precise). No integral argument promotions are
15619performed on the argument. It is equivalent to
15620@code{__builtin_clzg ((@var{type}) ~@var{arg}, -1) + 1U}
15621@enddefbuiltin
15622
ff99671a 15623@defbuiltin{{unsigned int} __builtin_stdc_first_trailing_one (@var{type} @var{arg})}
03c7149d
JJ
15624The @code{__builtin_stdc_first_trailing_one} function is available only
15625in C. It is type-generic, the argument can be any unsigned integer
15626(standard, extended or bit-precise). No integral argument promotions are
15627performed on the argument. It is equivalent to
15628@code{__builtin_ctzg (@var{arg}, -1) + 1U}
15629@enddefbuiltin
15630
ff99671a 15631@defbuiltin{{unsigned int} __builtin_stdc_first_trailing_zero (@var{type} @var{arg})}
03c7149d
JJ
15632The @code{__builtin_stdc_first_trailing_zero} function is available only
15633in C. It is type-generic, the argument can be any unsigned integer
15634(standard, extended or bit-precise). No integral argument promotions are
15635performed on the argument. It is equivalent to
15636@code{__builtin_ctzg ((@var{type}) ~@var{arg}, -1) + 1U}
15637@enddefbuiltin
15638
ff99671a 15639@defbuiltin{{unsigned int} __builtin_stdc_has_single_bit (@var{type} @var{arg})}
03c7149d
JJ
15640The @code{__builtin_stdc_has_single_bit} function is available only
15641in C. It is type-generic, the argument can be any unsigned integer
15642(standard, extended or bit-precise). No integral argument promotions are
15643performed on the argument. It is equivalent to
15644@code{(_Bool) (__builtin_popcountg (@var{arg}) == 1)}
15645@enddefbuiltin
15646
ff99671a 15647@defbuiltin{{unsigned int} __builtin_stdc_leading_ones (@var{type} @var{arg})}
03c7149d
JJ
15648The @code{__builtin_stdc_leading_ones} function is available only
15649in C. It is type-generic, the argument can be any unsigned integer
15650(standard, extended or bit-precise). No integral argument promotions are
15651performed on the argument. It is equivalent to
15652@code{(unsigned int) __builtin_clzg ((@var{type}) ~@var{arg}, @var{prec})}
15653@enddefbuiltin
15654
ff99671a 15655@defbuiltin{{unsigned int} __builtin_stdc_leading_zeros (@var{type} @var{arg})}
03c7149d
JJ
15656The @code{__builtin_stdc_leading_zeros} function is available only
15657in C. It is type-generic, the argument can be any unsigned integer
15658(standard, extended or bit-precise). No integral argument promotions are
15659performed on the argument. It is equivalent to
15660@code{(unsigned int) __builtin_clzg (@var{arg}, @var{prec})}
15661@enddefbuiltin
15662
ff99671a 15663@defbuiltin{{unsigned int} __builtin_stdc_trailing_ones (@var{type} @var{arg})}
03c7149d
JJ
15664The @code{__builtin_stdc_trailing_ones} function is available only
15665in C. It is type-generic, the argument can be any unsigned integer
15666(standard, extended or bit-precise). No integral argument promotions are
15667performed on the argument. It is equivalent to
15668@code{(unsigned int) __builtin_ctzg ((@var{type}) ~@var{arg}, @var{prec})}
15669@enddefbuiltin
15670
ff99671a 15671@defbuiltin{{unsigned int} __builtin_stdc_trailing_zeros (@var{type} @var{arg})}
03c7149d
JJ
15672The @code{__builtin_stdc_trailing_zeros} function is available only
15673in C. It is type-generic, the argument can be any unsigned integer
15674(standard, extended or bit-precise). No integral argument promotions are
15675performed on the argument. It is equivalent to
15676@code{(unsigned int) __builtin_ctzg (@var{arg}, @var{prec})}
15677@enddefbuiltin
15678
f25efe50
AA
15679@defbuiltin{double __builtin_powi (double, int)}
15680@defbuiltinx{float __builtin_powif (float, int)}
15681@defbuiltinx{{long double} __builtin_powil (long double, int)}
d77de738
ML
15682Returns the first argument raised to the power of the second. Unlike the
15683@code{pow} function no guarantees about precision and rounding are made.
f25efe50 15684@enddefbuiltin
d77de738 15685
23795106 15686@defbuiltin{uint16_t __builtin_bswap16 (uint16_t @var{x})}
d77de738
ML
15687Returns @var{x} with the order of the bytes reversed; for example,
15688@code{0xaabb} becomes @code{0xbbaa}. Byte here always means
15689exactly 8 bits.
f25efe50 15690@enddefbuiltin
d77de738 15691
23795106 15692@defbuiltin{uint32_t __builtin_bswap32 (uint32_t @var{x})}
d77de738
ML
15693Similar to @code{__builtin_bswap16}, except the argument and return types
15694are 32-bit.
f25efe50 15695@enddefbuiltin
d77de738 15696
23795106 15697@defbuiltin{uint64_t __builtin_bswap64 (uint64_t @var{x})}
d77de738
ML
15698Similar to @code{__builtin_bswap32}, except the argument and return types
15699are 64-bit.
f25efe50 15700@enddefbuiltin
d77de738 15701
23795106 15702@defbuiltin{uint128_t __builtin_bswap128 (uint128_t @var{x})}
d77de738
ML
15703Similar to @code{__builtin_bswap64}, except the argument and return types
15704are 128-bit. Only supported on targets when 128-bit types are supported.
f25efe50 15705@enddefbuiltin
d77de738
ML
15706
15707
23795106 15708@defbuiltin{Pmode __builtin_extend_pointer (void * @var{x})}
d77de738
ML
15709On targets where the user visible pointer size is smaller than the size
15710of an actual hardware address this function returns the extended user
15711pointer. Targets where this is true included ILP32 mode on x86_64 or
15712Aarch64. This function is mainly useful when writing inline assembly
15713code.
f25efe50 15714@enddefbuiltin
d77de738 15715
23795106 15716@defbuiltin{int __builtin_goacc_parlevel_id (int @var{x})}
d77de738
ML
15717Returns the openacc gang, worker or vector id depending on whether @var{x} is
157180, 1 or 2.
f25efe50 15719@enddefbuiltin
d77de738 15720
23795106 15721@defbuiltin{int __builtin_goacc_parlevel_size (int @var{x})}
d77de738
ML
15722Returns the openacc gang, worker or vector size depending on whether @var{x} is
157230, 1 or 2.
f25efe50 15724@enddefbuiltin
d77de738
ML
15725
15726@node Target Builtins
15727@section Built-in Functions Specific to Particular Target Machines
15728
15729On some target machines, GCC supports many built-in functions specific
15730to those machines. Generally these generate calls to specific machine
15731instructions, but allow the compiler to schedule those calls.
15732
15733@menu
15734* AArch64 Built-in Functions::
15735* Alpha Built-in Functions::
15736* Altera Nios II Built-in Functions::
15737* ARC Built-in Functions::
15738* ARC SIMD Built-in Functions::
15739* ARM iWMMXt Built-in Functions::
15740* ARM C Language Extensions (ACLE)::
15741* ARM Floating Point Status and Control Intrinsics::
15742* ARM ARMv8-M Security Extensions::
15743* AVR Built-in Functions::
15744* Blackfin Built-in Functions::
15745* BPF Built-in Functions::
15746* FR-V Built-in Functions::
5015cdf3 15747* LoongArch Base Built-in Functions::
1f48786d 15748* LoongArch SX Vector Intrinsics::
15749* LoongArch ASX Vector Intrinsics::
d77de738
ML
15750* MIPS DSP Built-in Functions::
15751* MIPS Paired-Single Support::
15752* MIPS Loongson Built-in Functions::
15753* MIPS SIMD Architecture (MSA) Support::
15754* Other MIPS Built-in Functions::
15755* MSP430 Built-in Functions::
15756* NDS32 Built-in Functions::
c09471fb 15757* Nvidia PTX Built-in Functions::
d77de738
ML
15758* Basic PowerPC Built-in Functions::
15759* PowerPC AltiVec/VSX Built-in Functions::
15760* PowerPC Hardware Transactional Memory Built-in Functions::
15761* PowerPC Atomic Memory Operation Functions::
15762* PowerPC Matrix-Multiply Assist Built-in Functions::
15763* PRU Built-in Functions::
15764* RISC-V Built-in Functions::
14c1a8df 15765* RISC-V Vector Intrinsics::
400efddd 15766* CORE-V Built-in Functions::
d77de738
ML
15767* RX Built-in Functions::
15768* S/390 System z Built-in Functions::
15769* SH Built-in Functions::
15770* SPARC VIS Built-in Functions::
15771* TI C6X Built-in Functions::
15772* x86 Built-in Functions::
15773* x86 transactional memory intrinsics::
15774* x86 control-flow protection intrinsics::
15775@end menu
15776
15777@node AArch64 Built-in Functions
15778@subsection AArch64 Built-in Functions
15779
15780These built-in functions are available for the AArch64 family of
15781processors.
15782@smallexample
15783unsigned int __builtin_aarch64_get_fpcr ();
15784void __builtin_aarch64_set_fpcr (unsigned int);
15785unsigned int __builtin_aarch64_get_fpsr ();
15786void __builtin_aarch64_set_fpsr (unsigned int);
15787
15788unsigned long long __builtin_aarch64_get_fpcr64 ();
15789void __builtin_aarch64_set_fpcr64 (unsigned long long);
15790unsigned long long __builtin_aarch64_get_fpsr64 ();
15791void __builtin_aarch64_set_fpsr64 (unsigned long long);
15792@end smallexample
15793
15794@node Alpha Built-in Functions
15795@subsection Alpha Built-in Functions
15796
15797These built-in functions are available for the Alpha family of
15798processors, depending on the command-line switches used.
15799
15800The following built-in functions are always available. They
15801all generate the machine instruction that is part of the name.
15802
15803@smallexample
15804long __builtin_alpha_implver (void);
15805long __builtin_alpha_rpcc (void);
15806long __builtin_alpha_amask (long);
15807long __builtin_alpha_cmpbge (long, long);
15808long __builtin_alpha_extbl (long, long);
15809long __builtin_alpha_extwl (long, long);
15810long __builtin_alpha_extll (long, long);
15811long __builtin_alpha_extql (long, long);
15812long __builtin_alpha_extwh (long, long);
15813long __builtin_alpha_extlh (long, long);
15814long __builtin_alpha_extqh (long, long);
15815long __builtin_alpha_insbl (long, long);
15816long __builtin_alpha_inswl (long, long);
15817long __builtin_alpha_insll (long, long);
15818long __builtin_alpha_insql (long, long);
15819long __builtin_alpha_inswh (long, long);
15820long __builtin_alpha_inslh (long, long);
15821long __builtin_alpha_insqh (long, long);
15822long __builtin_alpha_mskbl (long, long);
15823long __builtin_alpha_mskwl (long, long);
15824long __builtin_alpha_mskll (long, long);
15825long __builtin_alpha_mskql (long, long);
15826long __builtin_alpha_mskwh (long, long);
15827long __builtin_alpha_msklh (long, long);
15828long __builtin_alpha_mskqh (long, long);
15829long __builtin_alpha_umulh (long, long);
15830long __builtin_alpha_zap (long, long);
15831long __builtin_alpha_zapnot (long, long);
15832@end smallexample
15833
15834The following built-in functions are always with @option{-mmax}
15835or @option{-mcpu=@var{cpu}} where @var{cpu} is @code{pca56} or
15836later. They all generate the machine instruction that is part
15837of the name.
15838
15839@smallexample
15840long __builtin_alpha_pklb (long);
15841long __builtin_alpha_pkwb (long);
15842long __builtin_alpha_unpkbl (long);
15843long __builtin_alpha_unpkbw (long);
15844long __builtin_alpha_minub8 (long, long);
15845long __builtin_alpha_minsb8 (long, long);
15846long __builtin_alpha_minuw4 (long, long);
15847long __builtin_alpha_minsw4 (long, long);
15848long __builtin_alpha_maxub8 (long, long);
15849long __builtin_alpha_maxsb8 (long, long);
15850long __builtin_alpha_maxuw4 (long, long);
15851long __builtin_alpha_maxsw4 (long, long);
15852long __builtin_alpha_perr (long, long);
15853@end smallexample
15854
15855The following built-in functions are always with @option{-mcix}
15856or @option{-mcpu=@var{cpu}} where @var{cpu} is @code{ev67} or
15857later. They all generate the machine instruction that is part
15858of the name.
15859
15860@smallexample
15861long __builtin_alpha_cttz (long);
15862long __builtin_alpha_ctlz (long);
15863long __builtin_alpha_ctpop (long);
15864@end smallexample
15865
15866The following built-in functions are available on systems that use the OSF/1
15867PALcode. Normally they invoke the @code{rduniq} and @code{wruniq}
15868PAL calls, but when invoked with @option{-mtls-kernel}, they invoke
15869@code{rdval} and @code{wrval}.
15870
15871@smallexample
15872void *__builtin_thread_pointer (void);
15873void __builtin_set_thread_pointer (void *);
15874@end smallexample
15875
15876@node Altera Nios II Built-in Functions
15877@subsection Altera Nios II Built-in Functions
15878
15879These built-in functions are available for the Altera Nios II
15880family of processors.
15881
15882The following built-in functions are always available. They
15883all generate the machine instruction that is part of the name.
15884
15885@example
15886int __builtin_ldbio (volatile const void *);
15887int __builtin_ldbuio (volatile const void *);
15888int __builtin_ldhio (volatile const void *);
15889int __builtin_ldhuio (volatile const void *);
15890int __builtin_ldwio (volatile const void *);
15891void __builtin_stbio (volatile void *, int);
15892void __builtin_sthio (volatile void *, int);
15893void __builtin_stwio (volatile void *, int);
15894void __builtin_sync (void);
15895int __builtin_rdctl (int);
15896int __builtin_rdprs (int, int);
15897void __builtin_wrctl (int, int);
15898void __builtin_flushd (volatile void *);
15899void __builtin_flushda (volatile void *);
15900int __builtin_wrpie (int);
15901void __builtin_eni (int);
15902int __builtin_ldex (volatile const void *);
15903int __builtin_stex (volatile void *, int);
15904int __builtin_ldsex (volatile const void *);
15905int __builtin_stsex (volatile void *, int);
15906@end example
15907
15908The following built-in functions are always available. They
15909all generate a Nios II Custom Instruction. The name of the
15910function represents the types that the function takes and
15911returns. The letter before the @code{n} is the return type
15912or void if absent. The @code{n} represents the first parameter
15913to all the custom instructions, the custom instruction number.
15914The two letters after the @code{n} represent the up to two
15915parameters to the function.
15916
15917The letters represent the following data types:
15918@table @code
15919@item <no letter>
15920@code{void} for return type and no parameter for parameter types.
15921
15922@item i
15923@code{int} for return type and parameter type
15924
15925@item f
15926@code{float} for return type and parameter type
15927
15928@item p
15929@code{void *} for return type and parameter type
15930
15931@end table
15932
15933And the function names are:
15934@example
15935void __builtin_custom_n (void);
15936void __builtin_custom_ni (int);
15937void __builtin_custom_nf (float);
15938void __builtin_custom_np (void *);
15939void __builtin_custom_nii (int, int);
15940void __builtin_custom_nif (int, float);
15941void __builtin_custom_nip (int, void *);
15942void __builtin_custom_nfi (float, int);
15943void __builtin_custom_nff (float, float);
15944void __builtin_custom_nfp (float, void *);
15945void __builtin_custom_npi (void *, int);
15946void __builtin_custom_npf (void *, float);
15947void __builtin_custom_npp (void *, void *);
15948int __builtin_custom_in (void);
15949int __builtin_custom_ini (int);
15950int __builtin_custom_inf (float);
15951int __builtin_custom_inp (void *);
15952int __builtin_custom_inii (int, int);
15953int __builtin_custom_inif (int, float);
15954int __builtin_custom_inip (int, void *);
15955int __builtin_custom_infi (float, int);
15956int __builtin_custom_inff (float, float);
15957int __builtin_custom_infp (float, void *);
15958int __builtin_custom_inpi (void *, int);
15959int __builtin_custom_inpf (void *, float);
15960int __builtin_custom_inpp (void *, void *);
15961float __builtin_custom_fn (void);
15962float __builtin_custom_fni (int);
15963float __builtin_custom_fnf (float);
15964float __builtin_custom_fnp (void *);
15965float __builtin_custom_fnii (int, int);
15966float __builtin_custom_fnif (int, float);
15967float __builtin_custom_fnip (int, void *);
15968float __builtin_custom_fnfi (float, int);
15969float __builtin_custom_fnff (float, float);
15970float __builtin_custom_fnfp (float, void *);
15971float __builtin_custom_fnpi (void *, int);
15972float __builtin_custom_fnpf (void *, float);
15973float __builtin_custom_fnpp (void *, void *);
15974void * __builtin_custom_pn (void);
15975void * __builtin_custom_pni (int);
15976void * __builtin_custom_pnf (float);
15977void * __builtin_custom_pnp (void *);
15978void * __builtin_custom_pnii (int, int);
15979void * __builtin_custom_pnif (int, float);
15980void * __builtin_custom_pnip (int, void *);
15981void * __builtin_custom_pnfi (float, int);
15982void * __builtin_custom_pnff (float, float);
15983void * __builtin_custom_pnfp (float, void *);
15984void * __builtin_custom_pnpi (void *, int);
15985void * __builtin_custom_pnpf (void *, float);
15986void * __builtin_custom_pnpp (void *, void *);
15987@end example
15988
15989@node ARC Built-in Functions
15990@subsection ARC Built-in Functions
15991
15992The following built-in functions are provided for ARC targets. The
15993built-ins generate the corresponding assembly instructions. In the
15994examples given below, the generated code often requires an operand or
15995result to be in a register. Where necessary further code will be
15996generated to ensure this is true, but for brevity this is not
15997described in each case.
15998
15999@emph{Note:} Using a built-in to generate an instruction not supported
16000by a target may cause problems. At present the compiler is not
16001guaranteed to detect such misuse, and as a result an internal compiler
16002error may be generated.
16003
f25efe50 16004@defbuiltin{int __builtin_arc_aligned (void *@var{val}, int @var{alignval})}
d77de738
ML
16005Return 1 if @var{val} is known to have the byte alignment given
16006by @var{alignval}, otherwise return 0.
16007Note that this is different from
16008@smallexample
16009__alignof__(*(char *)@var{val}) >= alignval
16010@end smallexample
16011because __alignof__ sees only the type of the dereference, whereas
16012__builtin_arc_align uses alignment information from the pointer
16013as well as from the pointed-to type.
16014The information available will depend on optimization level.
f25efe50 16015@enddefbuiltin
d77de738 16016
f25efe50 16017@defbuiltin{void __builtin_arc_brk (void)}
d77de738
ML
16018Generates
16019@example
16020brk
16021@end example
f25efe50 16022@enddefbuiltin
d77de738 16023
f25efe50 16024@defbuiltin{{unsigned int} __builtin_arc_core_read (unsigned int @var{regno})}
d77de738
ML
16025The operand is the number of a register to be read. Generates:
16026@example
16027mov @var{dest}, r@var{regno}
16028@end example
16029where the value in @var{dest} will be the result returned from the
16030built-in.
f25efe50 16031@enddefbuiltin
d77de738 16032
f25efe50 16033@defbuiltin{void __builtin_arc_core_write (unsigned int @var{regno}, unsigned int @var{val})}
d77de738
ML
16034The first operand is the number of a register to be written, the
16035second operand is a compile time constant to write into that
16036register. Generates:
16037@example
16038mov r@var{regno}, @var{val}
16039@end example
f25efe50 16040@enddefbuiltin
d77de738 16041
f25efe50 16042@defbuiltin{int __builtin_arc_divaw (int @var{a}, int @var{b})}
d77de738
ML
16043Only available if either @option{-mcpu=ARC700} or @option{-meA} is set.
16044Generates:
16045@example
16046divaw @var{dest}, @var{a}, @var{b}
16047@end example
16048where the value in @var{dest} will be the result returned from the
16049built-in.
f25efe50 16050@enddefbuiltin
d77de738 16051
f25efe50 16052@defbuiltin{void __builtin_arc_flag (unsigned int @var{a})}
d77de738
ML
16053Generates
16054@example
16055flag @var{a}
16056@end example
f25efe50 16057@enddefbuiltin
d77de738 16058
f25efe50 16059@defbuiltin{{unsigned int} __builtin_arc_lr (unsigned int @var{auxr})}
d77de738
ML
16060The operand, @var{auxv}, is the address of an auxiliary register and
16061must be a compile time constant. Generates:
16062@example
16063lr @var{dest}, [@var{auxr}]
16064@end example
16065Where the value in @var{dest} will be the result returned from the
16066built-in.
f25efe50 16067@enddefbuiltin
d77de738 16068
f25efe50 16069@defbuiltin{void __builtin_arc_mul64 (int @var{a}, int @var{b})}
d77de738
ML
16070Only available with @option{-mmul64}. Generates:
16071@example
16072mul64 @var{a}, @var{b}
16073@end example
f25efe50 16074@enddefbuiltin
d77de738 16075
f25efe50 16076@defbuiltin{void __builtin_arc_mulu64 (unsigned int @var{a}, unsigned int @var{b})}
d77de738
ML
16077Only available with @option{-mmul64}. Generates:
16078@example
16079mulu64 @var{a}, @var{b}
16080@end example
f25efe50 16081@enddefbuiltin
d77de738 16082
f25efe50 16083@defbuiltin{void __builtin_arc_nop (void)}
d77de738
ML
16084Generates:
16085@example
16086nop
16087@end example
f25efe50 16088@enddefbuiltin
d77de738 16089
f25efe50 16090@defbuiltin{int __builtin_arc_norm (int @var{src})}
d77de738
ML
16091Only valid if the @samp{norm} instruction is available through the
16092@option{-mnorm} option or by default with @option{-mcpu=ARC700}.
16093Generates:
16094@example
16095norm @var{dest}, @var{src}
16096@end example
16097Where the value in @var{dest} will be the result returned from the
16098built-in.
f25efe50 16099@enddefbuiltin
d77de738 16100
f25efe50 16101@defbuiltin{{short int} __builtin_arc_normw (short int @var{src})}
d77de738
ML
16102Only valid if the @samp{normw} instruction is available through the
16103@option{-mnorm} option or by default with @option{-mcpu=ARC700}.
16104Generates:
16105@example
16106normw @var{dest}, @var{src}
16107@end example
16108Where the value in @var{dest} will be the result returned from the
16109built-in.
f25efe50 16110@enddefbuiltin
d77de738 16111
f25efe50 16112@defbuiltin{void __builtin_arc_rtie (void)}
d77de738
ML
16113Generates:
16114@example
16115rtie
16116@end example
f25efe50 16117@enddefbuiltin
d77de738 16118
f25efe50 16119@defbuiltin{void __builtin_arc_sleep (int @var{a}}
d77de738
ML
16120Generates:
16121@example
16122sleep @var{a}
16123@end example
f25efe50 16124@enddefbuiltin
d77de738 16125
f25efe50 16126@defbuiltin{void __builtin_arc_sr (unsigned int @var{val}, unsigned int @var{auxr})}
d77de738
ML
16127The first argument, @var{val}, is a compile time constant to be
16128written to the register, the second argument, @var{auxr}, is the
16129address of an auxiliary register. Generates:
16130@example
16131sr @var{val}, [@var{auxr}]
16132@end example
f25efe50 16133@enddefbuiltin
d77de738 16134
f25efe50 16135@defbuiltin{int __builtin_arc_swap (int @var{src})}
d77de738
ML
16136Only valid with @option{-mswap}. Generates:
16137@example
16138swap @var{dest}, @var{src}
16139@end example
16140Where the value in @var{dest} will be the result returned from the
16141built-in.
f25efe50 16142@enddefbuiltin
d77de738 16143
f25efe50 16144@defbuiltin{void __builtin_arc_swi (void)}
d77de738
ML
16145Generates:
16146@example
16147swi
16148@end example
f25efe50 16149@enddefbuiltin
d77de738 16150
f25efe50 16151@defbuiltin{void __builtin_arc_sync (void)}
d77de738
ML
16152Only available with @option{-mcpu=ARC700}. Generates:
16153@example
16154sync
16155@end example
f25efe50 16156@enddefbuiltin
d77de738 16157
f25efe50 16158@defbuiltin{void __builtin_arc_trap_s (unsigned int @var{c})}
d77de738
ML
16159Only available with @option{-mcpu=ARC700}. Generates:
16160@example
16161trap_s @var{c}
16162@end example
f25efe50 16163@enddefbuiltin
d77de738 16164
f25efe50 16165@defbuiltin{void __builtin_arc_unimp_s (void)}
d77de738
ML
16166Only available with @option{-mcpu=ARC700}. Generates:
16167@example
16168unimp_s
16169@end example
f25efe50 16170@enddefbuiltin
d77de738
ML
16171
16172The instructions generated by the following builtins are not
16173considered as candidates for scheduling. They are not moved around by
16174the compiler during scheduling, and thus can be expected to appear
16175where they are put in the C code:
16176@example
16177__builtin_arc_brk()
16178__builtin_arc_core_read()
16179__builtin_arc_core_write()
16180__builtin_arc_flag()
16181__builtin_arc_lr()
16182__builtin_arc_sleep()
16183__builtin_arc_sr()
16184__builtin_arc_swi()
16185@end example
16186
b74e4cab
CZ
16187The following built-in functions are available for the ARCv2 family of
16188processors.
16189
16190@example
16191int __builtin_arc_clri ();
16192void __builtin_arc_kflag (unsigned);
16193void __builtin_arc_seti (int);
16194@end example
16195
16196The following built-in functions are available for the ARCv2 family
16197and uses @option{-mnorm}.
16198
16199@example
16200int __builtin_arc_ffs (int);
16201int __builtin_arc_fls (int);
16202@end example
16203
d77de738
ML
16204@node ARC SIMD Built-in Functions
16205@subsection ARC SIMD Built-in Functions
16206
16207SIMD builtins provided by the compiler can be used to generate the
16208vector instructions. This section describes the available builtins
16209and their usage in programs. With the @option{-msimd} option, the
16210compiler provides 128-bit vector types, which can be specified using
16211the @code{vector_size} attribute. The header file @file{arc-simd.h}
16212can be included to use the following predefined types:
16213@example
16214typedef int __v4si __attribute__((vector_size(16)));
16215typedef short __v8hi __attribute__((vector_size(16)));
16216@end example
16217
16218These types can be used to define 128-bit variables. The built-in
16219functions listed in the following section can be used on these
16220variables to generate the vector operations.
16221
16222For all builtins, @code{__builtin_arc_@var{someinsn}}, the header file
16223@file{arc-simd.h} also provides equivalent macros called
16224@code{_@var{someinsn}} that can be used for programming ease and
16225improved readability. The following macros for DMA control are also
16226provided:
16227@example
16228#define _setup_dma_in_channel_reg _vdiwr
16229#define _setup_dma_out_channel_reg _vdowr
16230@end example
16231
16232The following is a complete list of all the SIMD built-ins provided
16233for ARC, grouped by calling signature.
16234
16235The following take two @code{__v8hi} arguments and return a
16236@code{__v8hi} result:
16237@example
16238__v8hi __builtin_arc_vaddaw (__v8hi, __v8hi);
16239__v8hi __builtin_arc_vaddw (__v8hi, __v8hi);
16240__v8hi __builtin_arc_vand (__v8hi, __v8hi);
16241__v8hi __builtin_arc_vandaw (__v8hi, __v8hi);
16242__v8hi __builtin_arc_vavb (__v8hi, __v8hi);
16243__v8hi __builtin_arc_vavrb (__v8hi, __v8hi);
16244__v8hi __builtin_arc_vbic (__v8hi, __v8hi);
16245__v8hi __builtin_arc_vbicaw (__v8hi, __v8hi);
16246__v8hi __builtin_arc_vdifaw (__v8hi, __v8hi);
16247__v8hi __builtin_arc_vdifw (__v8hi, __v8hi);
16248__v8hi __builtin_arc_veqw (__v8hi, __v8hi);
16249__v8hi __builtin_arc_vh264f (__v8hi, __v8hi);
16250__v8hi __builtin_arc_vh264ft (__v8hi, __v8hi);
16251__v8hi __builtin_arc_vh264fw (__v8hi, __v8hi);
16252__v8hi __builtin_arc_vlew (__v8hi, __v8hi);
16253__v8hi __builtin_arc_vltw (__v8hi, __v8hi);
16254__v8hi __builtin_arc_vmaxaw (__v8hi, __v8hi);
16255__v8hi __builtin_arc_vmaxw (__v8hi, __v8hi);
16256__v8hi __builtin_arc_vminaw (__v8hi, __v8hi);
16257__v8hi __builtin_arc_vminw (__v8hi, __v8hi);
16258__v8hi __builtin_arc_vmr1aw (__v8hi, __v8hi);
16259__v8hi __builtin_arc_vmr1w (__v8hi, __v8hi);
16260__v8hi __builtin_arc_vmr2aw (__v8hi, __v8hi);
16261__v8hi __builtin_arc_vmr2w (__v8hi, __v8hi);
16262__v8hi __builtin_arc_vmr3aw (__v8hi, __v8hi);
16263__v8hi __builtin_arc_vmr3w (__v8hi, __v8hi);
16264__v8hi __builtin_arc_vmr4aw (__v8hi, __v8hi);
16265__v8hi __builtin_arc_vmr4w (__v8hi, __v8hi);
16266__v8hi __builtin_arc_vmr5aw (__v8hi, __v8hi);
16267__v8hi __builtin_arc_vmr5w (__v8hi, __v8hi);
16268__v8hi __builtin_arc_vmr6aw (__v8hi, __v8hi);
16269__v8hi __builtin_arc_vmr6w (__v8hi, __v8hi);
16270__v8hi __builtin_arc_vmr7aw (__v8hi, __v8hi);
16271__v8hi __builtin_arc_vmr7w (__v8hi, __v8hi);
16272__v8hi __builtin_arc_vmrb (__v8hi, __v8hi);
16273__v8hi __builtin_arc_vmulaw (__v8hi, __v8hi);
16274__v8hi __builtin_arc_vmulfaw (__v8hi, __v8hi);
16275__v8hi __builtin_arc_vmulfw (__v8hi, __v8hi);
16276__v8hi __builtin_arc_vmulw (__v8hi, __v8hi);
16277__v8hi __builtin_arc_vnew (__v8hi, __v8hi);
16278__v8hi __builtin_arc_vor (__v8hi, __v8hi);
16279__v8hi __builtin_arc_vsubaw (__v8hi, __v8hi);
16280__v8hi __builtin_arc_vsubw (__v8hi, __v8hi);
16281__v8hi __builtin_arc_vsummw (__v8hi, __v8hi);
16282__v8hi __builtin_arc_vvc1f (__v8hi, __v8hi);
16283__v8hi __builtin_arc_vvc1ft (__v8hi, __v8hi);
16284__v8hi __builtin_arc_vxor (__v8hi, __v8hi);
16285__v8hi __builtin_arc_vxoraw (__v8hi, __v8hi);
16286@end example
16287
16288The following take one @code{__v8hi} and one @code{int} argument and return a
16289@code{__v8hi} result:
16290
16291@example
16292__v8hi __builtin_arc_vbaddw (__v8hi, int);
16293__v8hi __builtin_arc_vbmaxw (__v8hi, int);
16294__v8hi __builtin_arc_vbminw (__v8hi, int);
16295__v8hi __builtin_arc_vbmulaw (__v8hi, int);
16296__v8hi __builtin_arc_vbmulfw (__v8hi, int);
16297__v8hi __builtin_arc_vbmulw (__v8hi, int);
16298__v8hi __builtin_arc_vbrsubw (__v8hi, int);
16299__v8hi __builtin_arc_vbsubw (__v8hi, int);
16300@end example
16301
16302The following take one @code{__v8hi} argument and one @code{int} argument which
16303must be a 3-bit compile time constant indicating a register number
16304I0-I7. They return a @code{__v8hi} result.
16305@example
16306__v8hi __builtin_arc_vasrw (__v8hi, const int);
16307__v8hi __builtin_arc_vsr8 (__v8hi, const int);
16308__v8hi __builtin_arc_vsr8aw (__v8hi, const int);
16309@end example
16310
16311The following take one @code{__v8hi} argument and one @code{int}
16312argument which must be a 6-bit compile time constant. They return a
16313@code{__v8hi} result.
16314@example
16315__v8hi __builtin_arc_vasrpwbi (__v8hi, const int);
16316__v8hi __builtin_arc_vasrrpwbi (__v8hi, const int);
16317__v8hi __builtin_arc_vasrrwi (__v8hi, const int);
16318__v8hi __builtin_arc_vasrsrwi (__v8hi, const int);
16319__v8hi __builtin_arc_vasrwi (__v8hi, const int);
16320__v8hi __builtin_arc_vsr8awi (__v8hi, const int);
16321__v8hi __builtin_arc_vsr8i (__v8hi, const int);
16322@end example
16323
16324The following take one @code{__v8hi} argument and one @code{int} argument which
16325must be a 8-bit compile time constant. They return a @code{__v8hi}
16326result.
16327@example
16328__v8hi __builtin_arc_vd6tapf (__v8hi, const int);
16329__v8hi __builtin_arc_vmvaw (__v8hi, const int);
16330__v8hi __builtin_arc_vmvw (__v8hi, const int);
16331__v8hi __builtin_arc_vmvzw (__v8hi, const int);
16332@end example
16333
16334The following take two @code{int} arguments, the second of which which
16335must be a 8-bit compile time constant. They return a @code{__v8hi}
16336result:
16337@example
16338__v8hi __builtin_arc_vmovaw (int, const int);
16339__v8hi __builtin_arc_vmovw (int, const int);
16340__v8hi __builtin_arc_vmovzw (int, const int);
16341@end example
16342
16343The following take a single @code{__v8hi} argument and return a
16344@code{__v8hi} result:
16345@example
16346__v8hi __builtin_arc_vabsaw (__v8hi);
16347__v8hi __builtin_arc_vabsw (__v8hi);
16348__v8hi __builtin_arc_vaddsuw (__v8hi);
16349__v8hi __builtin_arc_vexch1 (__v8hi);
16350__v8hi __builtin_arc_vexch2 (__v8hi);
16351__v8hi __builtin_arc_vexch4 (__v8hi);
16352__v8hi __builtin_arc_vsignw (__v8hi);
16353__v8hi __builtin_arc_vupbaw (__v8hi);
16354__v8hi __builtin_arc_vupbw (__v8hi);
16355__v8hi __builtin_arc_vupsbaw (__v8hi);
16356__v8hi __builtin_arc_vupsbw (__v8hi);
16357@end example
16358
16359The following take two @code{int} arguments and return no result:
16360@example
16361void __builtin_arc_vdirun (int, int);
16362void __builtin_arc_vdorun (int, int);
16363@end example
16364
16365The following take two @code{int} arguments and return no result. The
16366first argument must a 3-bit compile time constant indicating one of
16367the DR0-DR7 DMA setup channels:
16368@example
16369void __builtin_arc_vdiwr (const int, int);
16370void __builtin_arc_vdowr (const int, int);
16371@end example
16372
16373The following take an @code{int} argument and return no result:
16374@example
16375void __builtin_arc_vendrec (int);
16376void __builtin_arc_vrec (int);
16377void __builtin_arc_vrecrun (int);
16378void __builtin_arc_vrun (int);
16379@end example
16380
16381The following take a @code{__v8hi} argument and two @code{int}
16382arguments and return a @code{__v8hi} result. The second argument must
16383be a 3-bit compile time constants, indicating one the registers I0-I7,
16384and the third argument must be an 8-bit compile time constant.
16385
16386@emph{Note:} Although the equivalent hardware instructions do not take
16387an SIMD register as an operand, these builtins overwrite the relevant
16388bits of the @code{__v8hi} register provided as the first argument with
16389the value loaded from the @code{[Ib, u8]} location in the SDM.
16390
16391@example
16392__v8hi __builtin_arc_vld32 (__v8hi, const int, const int);
16393__v8hi __builtin_arc_vld32wh (__v8hi, const int, const int);
16394__v8hi __builtin_arc_vld32wl (__v8hi, const int, const int);
16395__v8hi __builtin_arc_vld64 (__v8hi, const int, const int);
16396@end example
16397
16398The following take two @code{int} arguments and return a @code{__v8hi}
16399result. The first argument must be a 3-bit compile time constants,
16400indicating one the registers I0-I7, and the second argument must be an
164018-bit compile time constant.
16402
16403@example
16404__v8hi __builtin_arc_vld128 (const int, const int);
16405__v8hi __builtin_arc_vld64w (const int, const int);
16406@end example
16407
16408The following take a @code{__v8hi} argument and two @code{int}
16409arguments and return no result. The second argument must be a 3-bit
16410compile time constants, indicating one the registers I0-I7, and the
16411third argument must be an 8-bit compile time constant.
16412
16413@example
16414void __builtin_arc_vst128 (__v8hi, const int, const int);
16415void __builtin_arc_vst64 (__v8hi, const int, const int);
16416@end example
16417
16418The following take a @code{__v8hi} argument and three @code{int}
16419arguments and return no result. The second argument must be a 3-bit
16420compile-time constant, identifying the 16-bit sub-register to be
16421stored, the third argument must be a 3-bit compile time constants,
16422indicating one the registers I0-I7, and the fourth argument must be an
164238-bit compile time constant.
16424
16425@example
16426void __builtin_arc_vst16_n (__v8hi, const int, const int, const int);
16427void __builtin_arc_vst32_n (__v8hi, const int, const int, const int);
16428@end example
16429
b74e4cab
CZ
16430The following built-in functions are available on systems that uses
16431@option{-mmpy-option=6} or higher.
16432
16433@example
16434__v2hi __builtin_arc_dmach (__v2hi, __v2hi);
16435__v2hi __builtin_arc_dmachu (__v2hi, __v2hi);
16436__v2hi __builtin_arc_dmpyh (__v2hi, __v2hi);
16437__v2hi __builtin_arc_dmpyhu (__v2hi, __v2hi);
16438__v2hi __builtin_arc_vaddsub2h (__v2hi, __v2hi);
16439__v2hi __builtin_arc_vsubadd2h (__v2hi, __v2hi);
16440@end example
16441
16442The following built-in functions are available on systems that uses
16443@option{-mmpy-option=7} or higher.
16444
16445@example
16446__v2si __builtin_arc_vmac2h (__v2hi, __v2hi);
16447__v2si __builtin_arc_vmac2hu (__v2hi, __v2hi);
16448__v2si __builtin_arc_vmpy2h (__v2hi, __v2hi);
16449__v2si __builtin_arc_vmpy2hu (__v2hi, __v2hi);
16450@end example
16451
16452The following built-in functions are available on systems that uses
16453@option{-mmpy-option=8} or higher.
16454
16455@example
16456long long __builtin_arc_qmach (__v4hi, __v4hi);
16457long long __builtin_arc_qmachu (__v4hi, __v4hi);
16458long long __builtin_arc_qmpyh (__v4hi, __v4hi);
16459long long __builtin_arc_qmpyhu (__v4hi, __v4hi);
16460long long __builtin_arc_dmacwh (__v2si, __v2hi);
16461long long __builtin_arc_dmacwhu (__v2si, __v2hi);
16462_v2si __builtin_arc_vaddsub (__v2si, __v2si);
16463_v2si __builtin_arc_vsubadd (__v2si, __v2si);
16464_v4hi __builtin_arc_vaddsub4h (__v4hi, __v4hi);
16465_v4hi __builtin_arc_vsubadd4h (__v4hi, __v4hi);
16466@end example
16467
d77de738
ML
16468@node ARM iWMMXt Built-in Functions
16469@subsection ARM iWMMXt Built-in Functions
16470
16471These built-in functions are available for the ARM family of
16472processors when the @option{-mcpu=iwmmxt} switch is used:
16473
16474@smallexample
16475typedef int v2si __attribute__ ((vector_size (8)));
16476typedef short v4hi __attribute__ ((vector_size (8)));
16477typedef char v8qi __attribute__ ((vector_size (8)));
16478
16479int __builtin_arm_getwcgr0 (void);
16480void __builtin_arm_setwcgr0 (int);
16481int __builtin_arm_getwcgr1 (void);
16482void __builtin_arm_setwcgr1 (int);
16483int __builtin_arm_getwcgr2 (void);
16484void __builtin_arm_setwcgr2 (int);
16485int __builtin_arm_getwcgr3 (void);
16486void __builtin_arm_setwcgr3 (int);
16487int __builtin_arm_textrmsb (v8qi, int);
16488int __builtin_arm_textrmsh (v4hi, int);
16489int __builtin_arm_textrmsw (v2si, int);
16490int __builtin_arm_textrmub (v8qi, int);
16491int __builtin_arm_textrmuh (v4hi, int);
16492int __builtin_arm_textrmuw (v2si, int);
16493v8qi __builtin_arm_tinsrb (v8qi, int, int);
16494v4hi __builtin_arm_tinsrh (v4hi, int, int);
16495v2si __builtin_arm_tinsrw (v2si, int, int);
16496long long __builtin_arm_tmia (long long, int, int);
16497long long __builtin_arm_tmiabb (long long, int, int);
16498long long __builtin_arm_tmiabt (long long, int, int);
16499long long __builtin_arm_tmiaph (long long, int, int);
16500long long __builtin_arm_tmiatb (long long, int, int);
16501long long __builtin_arm_tmiatt (long long, int, int);
16502int __builtin_arm_tmovmskb (v8qi);
16503int __builtin_arm_tmovmskh (v4hi);
16504int __builtin_arm_tmovmskw (v2si);
16505long long __builtin_arm_waccb (v8qi);
16506long long __builtin_arm_wacch (v4hi);
16507long long __builtin_arm_waccw (v2si);
16508v8qi __builtin_arm_waddb (v8qi, v8qi);
16509v8qi __builtin_arm_waddbss (v8qi, v8qi);
16510v8qi __builtin_arm_waddbus (v8qi, v8qi);
16511v4hi __builtin_arm_waddh (v4hi, v4hi);
16512v4hi __builtin_arm_waddhss (v4hi, v4hi);
16513v4hi __builtin_arm_waddhus (v4hi, v4hi);
16514v2si __builtin_arm_waddw (v2si, v2si);
16515v2si __builtin_arm_waddwss (v2si, v2si);
16516v2si __builtin_arm_waddwus (v2si, v2si);
16517v8qi __builtin_arm_walign (v8qi, v8qi, int);
16518long long __builtin_arm_wand(long long, long long);
16519long long __builtin_arm_wandn (long long, long long);
16520v8qi __builtin_arm_wavg2b (v8qi, v8qi);
16521v8qi __builtin_arm_wavg2br (v8qi, v8qi);
16522v4hi __builtin_arm_wavg2h (v4hi, v4hi);
16523v4hi __builtin_arm_wavg2hr (v4hi, v4hi);
16524v8qi __builtin_arm_wcmpeqb (v8qi, v8qi);
16525v4hi __builtin_arm_wcmpeqh (v4hi, v4hi);
16526v2si __builtin_arm_wcmpeqw (v2si, v2si);
16527v8qi __builtin_arm_wcmpgtsb (v8qi, v8qi);
16528v4hi __builtin_arm_wcmpgtsh (v4hi, v4hi);
16529v2si __builtin_arm_wcmpgtsw (v2si, v2si);
16530v8qi __builtin_arm_wcmpgtub (v8qi, v8qi);
16531v4hi __builtin_arm_wcmpgtuh (v4hi, v4hi);
16532v2si __builtin_arm_wcmpgtuw (v2si, v2si);
16533long long __builtin_arm_wmacs (long long, v4hi, v4hi);
16534long long __builtin_arm_wmacsz (v4hi, v4hi);
16535long long __builtin_arm_wmacu (long long, v4hi, v4hi);
16536long long __builtin_arm_wmacuz (v4hi, v4hi);
16537v4hi __builtin_arm_wmadds (v4hi, v4hi);
16538v4hi __builtin_arm_wmaddu (v4hi, v4hi);
16539v8qi __builtin_arm_wmaxsb (v8qi, v8qi);
16540v4hi __builtin_arm_wmaxsh (v4hi, v4hi);
16541v2si __builtin_arm_wmaxsw (v2si, v2si);
16542v8qi __builtin_arm_wmaxub (v8qi, v8qi);
16543v4hi __builtin_arm_wmaxuh (v4hi, v4hi);
16544v2si __builtin_arm_wmaxuw (v2si, v2si);
16545v8qi __builtin_arm_wminsb (v8qi, v8qi);
16546v4hi __builtin_arm_wminsh (v4hi, v4hi);
16547v2si __builtin_arm_wminsw (v2si, v2si);
16548v8qi __builtin_arm_wminub (v8qi, v8qi);
16549v4hi __builtin_arm_wminuh (v4hi, v4hi);
16550v2si __builtin_arm_wminuw (v2si, v2si);
16551v4hi __builtin_arm_wmulsm (v4hi, v4hi);
16552v4hi __builtin_arm_wmulul (v4hi, v4hi);
16553v4hi __builtin_arm_wmulum (v4hi, v4hi);
16554long long __builtin_arm_wor (long long, long long);
16555v2si __builtin_arm_wpackdss (long long, long long);
16556v2si __builtin_arm_wpackdus (long long, long long);
16557v8qi __builtin_arm_wpackhss (v4hi, v4hi);
16558v8qi __builtin_arm_wpackhus (v4hi, v4hi);
16559v4hi __builtin_arm_wpackwss (v2si, v2si);
16560v4hi __builtin_arm_wpackwus (v2si, v2si);
16561long long __builtin_arm_wrord (long long, long long);
16562long long __builtin_arm_wrordi (long long, int);
16563v4hi __builtin_arm_wrorh (v4hi, long long);
16564v4hi __builtin_arm_wrorhi (v4hi, int);
16565v2si __builtin_arm_wrorw (v2si, long long);
16566v2si __builtin_arm_wrorwi (v2si, int);
16567v2si __builtin_arm_wsadb (v2si, v8qi, v8qi);
16568v2si __builtin_arm_wsadbz (v8qi, v8qi);
16569v2si __builtin_arm_wsadh (v2si, v4hi, v4hi);
16570v2si __builtin_arm_wsadhz (v4hi, v4hi);
16571v4hi __builtin_arm_wshufh (v4hi, int);
16572long long __builtin_arm_wslld (long long, long long);
16573long long __builtin_arm_wslldi (long long, int);
16574v4hi __builtin_arm_wsllh (v4hi, long long);
16575v4hi __builtin_arm_wsllhi (v4hi, int);
16576v2si __builtin_arm_wsllw (v2si, long long);
16577v2si __builtin_arm_wsllwi (v2si, int);
16578long long __builtin_arm_wsrad (long long, long long);
16579long long __builtin_arm_wsradi (long long, int);
16580v4hi __builtin_arm_wsrah (v4hi, long long);
16581v4hi __builtin_arm_wsrahi (v4hi, int);
16582v2si __builtin_arm_wsraw (v2si, long long);
16583v2si __builtin_arm_wsrawi (v2si, int);
16584long long __builtin_arm_wsrld (long long, long long);
16585long long __builtin_arm_wsrldi (long long, int);
16586v4hi __builtin_arm_wsrlh (v4hi, long long);
16587v4hi __builtin_arm_wsrlhi (v4hi, int);
16588v2si __builtin_arm_wsrlw (v2si, long long);
16589v2si __builtin_arm_wsrlwi (v2si, int);
16590v8qi __builtin_arm_wsubb (v8qi, v8qi);
16591v8qi __builtin_arm_wsubbss (v8qi, v8qi);
16592v8qi __builtin_arm_wsubbus (v8qi, v8qi);
16593v4hi __builtin_arm_wsubh (v4hi, v4hi);
16594v4hi __builtin_arm_wsubhss (v4hi, v4hi);
16595v4hi __builtin_arm_wsubhus (v4hi, v4hi);
16596v2si __builtin_arm_wsubw (v2si, v2si);
16597v2si __builtin_arm_wsubwss (v2si, v2si);
16598v2si __builtin_arm_wsubwus (v2si, v2si);
16599v4hi __builtin_arm_wunpckehsb (v8qi);
16600v2si __builtin_arm_wunpckehsh (v4hi);
16601long long __builtin_arm_wunpckehsw (v2si);
16602v4hi __builtin_arm_wunpckehub (v8qi);
16603v2si __builtin_arm_wunpckehuh (v4hi);
16604long long __builtin_arm_wunpckehuw (v2si);
16605v4hi __builtin_arm_wunpckelsb (v8qi);
16606v2si __builtin_arm_wunpckelsh (v4hi);
16607long long __builtin_arm_wunpckelsw (v2si);
16608v4hi __builtin_arm_wunpckelub (v8qi);
16609v2si __builtin_arm_wunpckeluh (v4hi);
16610long long __builtin_arm_wunpckeluw (v2si);
16611v8qi __builtin_arm_wunpckihb (v8qi, v8qi);
16612v4hi __builtin_arm_wunpckihh (v4hi, v4hi);
16613v2si __builtin_arm_wunpckihw (v2si, v2si);
16614v8qi __builtin_arm_wunpckilb (v8qi, v8qi);
16615v4hi __builtin_arm_wunpckilh (v4hi, v4hi);
16616v2si __builtin_arm_wunpckilw (v2si, v2si);
16617long long __builtin_arm_wxor (long long, long long);
16618long long __builtin_arm_wzero ();
16619@end smallexample
16620
16621
16622@node ARM C Language Extensions (ACLE)
16623@subsection ARM C Language Extensions (ACLE)
16624
16625GCC implements extensions for C as described in the ARM C Language
16626Extensions (ACLE) specification, which can be found at
16627@uref{https://developer.arm.com/documentation/ihi0053/latest/}.
16628
16629As a part of ACLE, GCC implements extensions for Advanced SIMD as described in
16630the ARM C Language Extensions Specification. The complete list of Advanced SIMD
16631intrinsics can be found at
16632@uref{https://developer.arm.com/documentation/ihi0073/latest/}.
16633The built-in intrinsics for the Advanced SIMD extension are available when
16634NEON is enabled.
16635
16636Currently, ARM and AArch64 back ends do not support ACLE 2.0 fully. Both
16637back ends support CRC32 intrinsics and the ARM back end supports the
16638Coprocessor intrinsics, all from @file{arm_acle.h}. The ARM back end's 16-bit
16639floating-point Advanced SIMD intrinsics currently comply to ACLE v1.1.
16640AArch64's back end does not have support for 16-bit floating point Advanced SIMD
16641intrinsics yet.
16642
16643See @ref{ARM Options} and @ref{AArch64 Options} for more information on the
16644availability of extensions.
16645
16646@node ARM Floating Point Status and Control Intrinsics
16647@subsection ARM Floating Point Status and Control Intrinsics
16648
16649These built-in functions are available for the ARM family of
16650processors with floating-point unit.
16651
16652@smallexample
16653unsigned int __builtin_arm_get_fpscr ();
16654void __builtin_arm_set_fpscr (unsigned int);
16655@end smallexample
16656
16657@node ARM ARMv8-M Security Extensions
16658@subsection ARM ARMv8-M Security Extensions
16659
16660GCC implements the ARMv8-M Security Extensions as described in the ARMv8-M
16661Security Extensions: Requirements on Development Tools Engineering
16662Specification, which can be found at
16663@uref{https://developer.arm.com/documentation/ecm0359818/latest/}.
16664
16665As part of the Security Extensions GCC implements two new function attributes:
16666@code{cmse_nonsecure_entry} and @code{cmse_nonsecure_call}.
16667
16668As part of the Security Extensions GCC implements the intrinsics below. FPTR
16669is used here to mean any function pointer type.
16670
16671@smallexample
16672cmse_address_info_t cmse_TT (void *);
16673cmse_address_info_t cmse_TT_fptr (FPTR);
16674cmse_address_info_t cmse_TTT (void *);
16675cmse_address_info_t cmse_TTT_fptr (FPTR);
16676cmse_address_info_t cmse_TTA (void *);
16677cmse_address_info_t cmse_TTA_fptr (FPTR);
16678cmse_address_info_t cmse_TTAT (void *);
16679cmse_address_info_t cmse_TTAT_fptr (FPTR);
16680void * cmse_check_address_range (void *, size_t, int);
16681typeof(p) cmse_nsfptr_create (FPTR p);
16682intptr_t cmse_is_nsfptr (FPTR);
16683int cmse_nonsecure_caller (void);
16684@end smallexample
16685
16686@node AVR Built-in Functions
16687@subsection AVR Built-in Functions
16688
16689For each built-in function for AVR, there is an equally named,
16690uppercase built-in macro defined. That way users can easily query if
16691or if not a specific built-in is implemented or not. For example, if
16692@code{__builtin_avr_nop} is available the macro
16693@code{__BUILTIN_AVR_NOP} is defined to @code{1} and undefined otherwise.
16694
16695@table @code
16696
16697@item void __builtin_avr_nop (void)
16698@itemx void __builtin_avr_sei (void)
16699@itemx void __builtin_avr_cli (void)
16700@itemx void __builtin_avr_sleep (void)
16701@itemx void __builtin_avr_wdr (void)
16702@itemx unsigned char __builtin_avr_swap (unsigned char)
16703@itemx unsigned int __builtin_avr_fmul (unsigned char, unsigned char)
16704@itemx int __builtin_avr_fmuls (char, char)
16705@itemx int __builtin_avr_fmulsu (char, unsigned char)
16706These built-in functions map to the respective machine
16707instruction, i.e.@: @code{nop}, @code{sei}, @code{cli}, @code{sleep},
16708@code{wdr}, @code{swap}, @code{fmul}, @code{fmuls}
16709resp. @code{fmulsu}. The three @code{fmul*} built-ins are implemented
16710as library call if no hardware multiplier is available.
16711
16712@item void __builtin_avr_delay_cycles (unsigned long ticks)
16713Delay execution for @var{ticks} cycles. Note that this
16714built-in does not take into account the effect of interrupts that
16715might increase delay time. @var{ticks} must be a compile-time
16716integer constant; delays with a variable number of cycles are not supported.
16717
16718@item char __builtin_avr_flash_segment (const __memx void*)
16719This built-in takes a byte address to the 24-bit
16720@ref{AVR Named Address Spaces,address space} @code{__memx} and returns
16721the number of the flash segment (the 64 KiB chunk) where the address
16722points to. Counting starts at @code{0}.
16723If the address does not point to flash memory, return @code{-1}.
16724
16725@item uint8_t __builtin_avr_insert_bits (uint32_t map, uint8_t bits, uint8_t val)
16726Insert bits from @var{bits} into @var{val} and return the resulting
16727value. The nibbles of @var{map} determine how the insertion is
16728performed: Let @var{X} be the @var{n}-th nibble of @var{map}
16729@enumerate
16730@item If @var{X} is @code{0xf},
16731then the @var{n}-th bit of @var{val} is returned unaltered.
16732
16733@item If X is in the range 0@dots{}7,
16734then the @var{n}-th result bit is set to the @var{X}-th bit of @var{bits}
16735
16736@item If X is in the range 8@dots{}@code{0xe},
16737then the @var{n}-th result bit is undefined.
16738@end enumerate
16739
16740@noindent
16741One typical use case for this built-in is adjusting input and
16742output values to non-contiguous port layouts. Some examples:
16743
16744@smallexample
16745// same as val, bits is unused
16746__builtin_avr_insert_bits (0xffffffff, bits, val);
16747@end smallexample
16748
16749@smallexample
16750// same as bits, val is unused
16751__builtin_avr_insert_bits (0x76543210, bits, val);
16752@end smallexample
16753
16754@smallexample
16755// same as rotating bits by 4
16756__builtin_avr_insert_bits (0x32107654, bits, 0);
16757@end smallexample
16758
16759@smallexample
16760// high nibble of result is the high nibble of val
16761// low nibble of result is the low nibble of bits
16762__builtin_avr_insert_bits (0xffff3210, bits, val);
16763@end smallexample
16764
16765@smallexample
16766// reverse the bit order of bits
16767__builtin_avr_insert_bits (0x01234567, bits, 0);
16768@end smallexample
16769
16770@item void __builtin_avr_nops (unsigned count)
16771Insert @var{count} @code{NOP} instructions.
16772The number of instructions must be a compile-time integer constant.
16773
16774@end table
16775
16776@noindent
16777There are many more AVR-specific built-in functions that are used to
16778implement the ISO/IEC TR 18037 ``Embedded C'' fixed-point functions of
16779section 7.18a.6. You don't need to use these built-ins directly.
16780Instead, use the declarations as supplied by the @code{stdfix.h} header
16781with GNU-C99:
16782
16783@smallexample
16784#include <stdfix.h>
16785
16786// Re-interpret the bit representation of unsigned 16-bit
16787// integer @var{uval} as Q-format 0.16 value.
16788unsigned fract get_bits (uint_ur_t uval)
16789@{
16790 return urbits (uval);
16791@}
16792@end smallexample
16793
16794@node Blackfin Built-in Functions
16795@subsection Blackfin Built-in Functions
16796
16797Currently, there are two Blackfin-specific built-in functions. These are
16798used for generating @code{CSYNC} and @code{SSYNC} machine insns without
16799using inline assembly; by using these built-in functions the compiler can
16800automatically add workarounds for hardware errata involving these
16801instructions. These functions are named as follows:
16802
16803@smallexample
16804void __builtin_bfin_csync (void);
16805void __builtin_bfin_ssync (void);
16806@end smallexample
16807
16808@node BPF Built-in Functions
16809@subsection BPF Built-in Functions
16810
16811The following built-in functions are available for eBPF targets.
16812
f25efe50 16813@defbuiltin{{unsigned long long} __builtin_bpf_load_byte (unsigned long long @var{offset})}
d77de738 16814Load a byte from the @code{struct sk_buff} packet data pointed by the register @code{%r6} and return it.
f25efe50 16815@enddefbuiltin
d77de738 16816
f25efe50 16817@defbuiltin{{unsigned long long} __builtin_bpf_load_half (unsigned long long @var{offset})}
7ffbc74c 16818Load 16 bits from the @code{struct sk_buff} packet data pointed by the register @code{%r6} and return it.
f25efe50 16819@enddefbuiltin
d77de738 16820
f25efe50 16821@defbuiltin{{unsigned long long} __builtin_bpf_load_word (unsigned long long @var{offset})}
7ffbc74c 16822Load 32 bits from the @code{struct sk_buff} packet data pointed by the register @code{%r6} and return it.
f25efe50 16823@enddefbuiltin
d77de738 16824
f25efe50 16825@defbuiltin{{void *} __builtin_preserve_access_index (@var{expr})}
d77de738 16826BPF 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 16827@enddefbuiltin
d77de738 16828
f25efe50 16829@defbuiltin{{unsigned int} __builtin_preserve_field_info (@var{expr}, unsigned int @var{kind})}
d77de738
ML
16830BPF Compile Once-Run Everywhere (CO-RE) support. This builtin is used to
16831extract information to aid in struct/union relocations. @var{expr} is
16832an access to a field of a struct or union. Depending on @var{kind}, different
16833information is returned to the program. A CO-RE relocation for the access in
16834@var{expr} with kind @var{kind} is recorded if @code{-mco-re} is in effect.
16835
16836The following values are supported for @var{kind}:
7ffbc74c 16837@table @code
d77de738
ML
16838@item FIELD_BYTE_OFFSET = 0
16839The returned value is the offset, in bytes, of the field from the
7ffbc74c 16840beginning of the containing structure. For bit-fields, this is the byte offset
d77de738
ML
16841of the containing word.
16842
16843@item FIELD_BYTE_SIZE = 1
7ffbc74c
SL
16844The returned value is the size, in bytes, of the field. For bit-fields,
16845this is the size in bytes of the containing word.
d77de738
ML
16846
16847@item FIELD_EXISTENCE = 2
16848The returned value is 1 if the field exists, 0 otherwise. Always 1 at
16849compile time.
16850
16851@item FIELD_SIGNEDNESS = 3
16852The returned value is 1 if the field is signed, 0 otherwise.
16853
16854@item FIELD_LSHIFT_U64 = 4
16855@itemx FIELD_RSHIFT_U64 = 5
16856The returned value is the number of bits of left- or right-shifting
7ffbc74c
SL
16857(respectively) needed in order to recover the original value of the field,
16858after it has been loaded by a read of @code{FIELD_BYTE_SIZE} bytes into an
16859unsigned 64-bit value. Primarily useful for reading bit-field values
16860from structures that may change between kernel versions.
d77de738
ML
16861
16862@end table
16863
16864Note that the return value is a constant which is known at
7ffbc74c
SL
16865compile time. If the field has a variable offset then
16866@code{FIELD_BYTE_OFFSET}, @code{FIELD_LSHIFT_U64},
16867and @code{FIELD_RSHIFT_U64} are not supported.
16868Similarly, if the field has a variable size then
16869@code{FIELD_BYTE_SIZE}, @code{FIELD_LSHIFT_U64},
16870and @code{FIELD_RSHIFT_U64} are not supported.
16871
16872For example, @code{__builtin_preserve_field_info} can be used to reliably
16873extract bit-field values from a structure that may change between
d77de738
ML
16874kernel versions:
16875
7ffbc74c 16876@smallexample
d77de738
ML
16877struct S
16878@{
16879 short a;
16880 int x:7;
16881 int y:5;
16882@};
16883
16884int
16885read_y (struct S *arg)
16886@{
16887 unsigned long long val;
7ffbc74c
SL
16888 unsigned int offset
16889 = __builtin_preserve_field_info (arg->y, FIELD_BYTE_OFFSET);
16890 unsigned int size
16891 = __builtin_preserve_field_info (arg->y, FIELD_BYTE_SIZE);
d77de738
ML
16892
16893 /* Read size bytes from arg + offset into val. */
16894 bpf_probe_read (&val, size, arg + offset);
16895
16896 val <<= __builtin_preserve_field_info (arg->y, FIELD_LSHIFT_U64);
16897
16898 if (__builtin_preserve_field_info (arg->y, FIELD_SIGNEDNESS))
7ffbc74c
SL
16899 val = ((long long) val
16900 >> __builtin_preserve_field_info (arg->y, FIELD_RSHIFT_U64));
d77de738
ML
16901 else
16902 val >>= __builtin_preserve_field_info (arg->y, FIELD_RSHIFT_U64);
16903
16904 return val;
16905@}
16906
7ffbc74c 16907@end smallexample
f25efe50 16908@enddefbuiltin
d77de738 16909
e0a81559
CM
16910@defbuiltin{{unsigned int} __builtin_preserve_enum_value (@var{type}, @var{enum}, unsigned int @var{kind})}
16911BPF Compile Once-Run Everywhere (CO-RE) support. This builtin collects enum
16912information and creates a CO-RE relocation relative to @var{enum} that should
16913be of @var{type}. The @var{kind} specifies the action performed.
16914
16915The following values are supported for @var{kind}:
16916@table @code
16917@item ENUM_VALUE_EXISTS = 0
16918The return value is either 0 or 1 depending if the enum value exists in the
16919target.
16920
16921@item ENUM_VALUE = 1
16922The return value is the enum value in the target kernel.
16923@end table
16924@enddefbuiltin
16925
16926@defbuiltin{{unsigned int} __builtin_btf_type_id (@var{type}, unsigned int @var{kind})}
16927BPF Compile Once-Run Everywhere (CO-RE) support. This builtin is used to get
16928the BTF type ID of a specified type. Depending on the @var{kind} argument, it
16929will either return the ID of the local BTF information, or the BTF type ID in
16930the target kernel.
16931
16932The following values are supported for @var{kind}:
16933@table @code
16934@item BTF_TYPE_ID_LOCAL = 0
16935Return the local BTF type ID. Always succeeds.
16936
16937@item BTF_TYPE_ID_TARGET = 1
16938Return the target BTF type ID. If type does not exist in the target, returns 0.
16939@end table
16940@enddefbuiltin
16941
16942@defbuiltin{{unsigned int} __builtin_preserve_type_info (@var{type}, unsigned int @var{kind})}
16943BPF Compile Once-Run Everywhere (CO-RE) support. This builtin performs named
16944type (struct/union/enum/typedef) verifications. The type of verification
16945dependents on the @var{kind} argument provided. This builtin will always
16946return 0 if type does not exists in the target kernel.
16947
16948The following values are supported for @var{kind}:
16949@table @code
16950@item BTF_TYPE_EXISTS = 0
16951Checks if type exists in the target.
16952
16953@item BTF_TYPE_MATCHES = 1
16954Checks if type matches the local definition in the target kernel.
16955
16956@item BTF_TYPE_SIZE = 2
16957Returns the size of the type within the target.
16958@end table
16959@enddefbuiltin
16960
d77de738
ML
16961@node FR-V Built-in Functions
16962@subsection FR-V Built-in Functions
16963
16964GCC provides many FR-V-specific built-in functions. In general,
16965these functions are intended to be compatible with those described
16966by @cite{FR-V Family, Softune C/C++ Compiler Manual (V6), Fujitsu
16967Semiconductor}. The two exceptions are @code{__MDUNPACKH} and
16968@code{__MBTOHE}, the GCC forms of which pass 128-bit values by
16969pointer rather than by value.
16970
16971Most of the functions are named after specific FR-V instructions.
16972Such functions are said to be ``directly mapped'' and are summarized
16973here in tabular form.
16974
16975@menu
16976* Argument Types::
16977* Directly-mapped Integer Functions::
16978* Directly-mapped Media Functions::
16979* Raw read/write Functions::
16980* Other Built-in Functions::
16981@end menu
16982
16983@node Argument Types
16984@subsubsection Argument Types
16985
16986The arguments to the built-in functions can be divided into three groups:
16987register numbers, compile-time constants and run-time values. In order
16988to make this classification clear at a glance, the arguments and return
16989values are given the following pseudo types:
16990
16991@multitable @columnfractions .20 .30 .15 .35
16992@headitem Pseudo type @tab Real C type @tab Constant? @tab Description
16993@item @code{uh} @tab @code{unsigned short} @tab No @tab an unsigned halfword
16994@item @code{uw1} @tab @code{unsigned int} @tab No @tab an unsigned word
16995@item @code{sw1} @tab @code{int} @tab No @tab a signed word
16996@item @code{uw2} @tab @code{unsigned long long} @tab No
16997@tab an unsigned doubleword
16998@item @code{sw2} @tab @code{long long} @tab No @tab a signed doubleword
16999@item @code{const} @tab @code{int} @tab Yes @tab an integer constant
17000@item @code{acc} @tab @code{int} @tab Yes @tab an ACC register number
17001@item @code{iacc} @tab @code{int} @tab Yes @tab an IACC register number
17002@end multitable
17003
17004These pseudo types are not defined by GCC, they are simply a notational
17005convenience used in this manual.
17006
17007Arguments of type @code{uh}, @code{uw1}, @code{sw1}, @code{uw2}
17008and @code{sw2} are evaluated at run time. They correspond to
17009register operands in the underlying FR-V instructions.
17010
17011@code{const} arguments represent immediate operands in the underlying
17012FR-V instructions. They must be compile-time constants.
17013
17014@code{acc} arguments are evaluated at compile time and specify the number
17015of an accumulator register. For example, an @code{acc} argument of 2
17016selects the ACC2 register.
17017
17018@code{iacc} arguments are similar to @code{acc} arguments but specify the
17019number of an IACC register. See @pxref{Other Built-in Functions}
17020for more details.
17021
17022@node Directly-mapped Integer Functions
17023@subsubsection Directly-Mapped Integer Functions
17024
17025The functions listed below map directly to FR-V I-type instructions.
17026
17027@multitable @columnfractions .45 .32 .23
17028@headitem Function prototype @tab Example usage @tab Assembly output
17029@item @code{sw1 __ADDSS (sw1, sw1)}
17030@tab @code{@var{c} = __ADDSS (@var{a}, @var{b})}
17031@tab @code{ADDSS @var{a},@var{b},@var{c}}
17032@item @code{sw1 __SCAN (sw1, sw1)}
17033@tab @code{@var{c} = __SCAN (@var{a}, @var{b})}
17034@tab @code{SCAN @var{a},@var{b},@var{c}}
17035@item @code{sw1 __SCUTSS (sw1)}
17036@tab @code{@var{b} = __SCUTSS (@var{a})}
17037@tab @code{SCUTSS @var{a},@var{b}}
17038@item @code{sw1 __SLASS (sw1, sw1)}
17039@tab @code{@var{c} = __SLASS (@var{a}, @var{b})}
17040@tab @code{SLASS @var{a},@var{b},@var{c}}
17041@item @code{void __SMASS (sw1, sw1)}
17042@tab @code{__SMASS (@var{a}, @var{b})}
17043@tab @code{SMASS @var{a},@var{b}}
17044@item @code{void __SMSSS (sw1, sw1)}
17045@tab @code{__SMSSS (@var{a}, @var{b})}
17046@tab @code{SMSSS @var{a},@var{b}}
17047@item @code{void __SMU (sw1, sw1)}
17048@tab @code{__SMU (@var{a}, @var{b})}
17049@tab @code{SMU @var{a},@var{b}}
17050@item @code{sw2 __SMUL (sw1, sw1)}
17051@tab @code{@var{c} = __SMUL (@var{a}, @var{b})}
17052@tab @code{SMUL @var{a},@var{b},@var{c}}
17053@item @code{sw1 __SUBSS (sw1, sw1)}
17054@tab @code{@var{c} = __SUBSS (@var{a}, @var{b})}
17055@tab @code{SUBSS @var{a},@var{b},@var{c}}
17056@item @code{uw2 __UMUL (uw1, uw1)}
17057@tab @code{@var{c} = __UMUL (@var{a}, @var{b})}
17058@tab @code{UMUL @var{a},@var{b},@var{c}}
17059@end multitable
17060
17061@node Directly-mapped Media Functions
17062@subsubsection Directly-Mapped Media Functions
17063
17064The functions listed below map directly to FR-V M-type instructions.
17065
17066@multitable @columnfractions .45 .32 .23
17067@headitem Function prototype @tab Example usage @tab Assembly output
17068@item @code{uw1 __MABSHS (sw1)}
17069@tab @code{@var{b} = __MABSHS (@var{a})}
17070@tab @code{MABSHS @var{a},@var{b}}
17071@item @code{void __MADDACCS (acc, acc)}
17072@tab @code{__MADDACCS (@var{b}, @var{a})}
17073@tab @code{MADDACCS @var{a},@var{b}}
17074@item @code{sw1 __MADDHSS (sw1, sw1)}
17075@tab @code{@var{c} = __MADDHSS (@var{a}, @var{b})}
17076@tab @code{MADDHSS @var{a},@var{b},@var{c}}
17077@item @code{uw1 __MADDHUS (uw1, uw1)}
17078@tab @code{@var{c} = __MADDHUS (@var{a}, @var{b})}
17079@tab @code{MADDHUS @var{a},@var{b},@var{c}}
17080@item @code{uw1 __MAND (uw1, uw1)}
17081@tab @code{@var{c} = __MAND (@var{a}, @var{b})}
17082@tab @code{MAND @var{a},@var{b},@var{c}}
17083@item @code{void __MASACCS (acc, acc)}
17084@tab @code{__MASACCS (@var{b}, @var{a})}
17085@tab @code{MASACCS @var{a},@var{b}}
17086@item @code{uw1 __MAVEH (uw1, uw1)}
17087@tab @code{@var{c} = __MAVEH (@var{a}, @var{b})}
17088@tab @code{MAVEH @var{a},@var{b},@var{c}}
17089@item @code{uw2 __MBTOH (uw1)}
17090@tab @code{@var{b} = __MBTOH (@var{a})}
17091@tab @code{MBTOH @var{a},@var{b}}
17092@item @code{void __MBTOHE (uw1 *, uw1)}
17093@tab @code{__MBTOHE (&@var{b}, @var{a})}
17094@tab @code{MBTOHE @var{a},@var{b}}
17095@item @code{void __MCLRACC (acc)}
17096@tab @code{__MCLRACC (@var{a})}
17097@tab @code{MCLRACC @var{a}}
17098@item @code{void __MCLRACCA (void)}
17099@tab @code{__MCLRACCA ()}
17100@tab @code{MCLRACCA}
17101@item @code{uw1 __Mcop1 (uw1, uw1)}
17102@tab @code{@var{c} = __Mcop1 (@var{a}, @var{b})}
17103@tab @code{Mcop1 @var{a},@var{b},@var{c}}
17104@item @code{uw1 __Mcop2 (uw1, uw1)}
17105@tab @code{@var{c} = __Mcop2 (@var{a}, @var{b})}
17106@tab @code{Mcop2 @var{a},@var{b},@var{c}}
17107@item @code{uw1 __MCPLHI (uw2, const)}
17108@tab @code{@var{c} = __MCPLHI (@var{a}, @var{b})}
17109@tab @code{MCPLHI @var{a},#@var{b},@var{c}}
17110@item @code{uw1 __MCPLI (uw2, const)}
17111@tab @code{@var{c} = __MCPLI (@var{a}, @var{b})}
17112@tab @code{MCPLI @var{a},#@var{b},@var{c}}
17113@item @code{void __MCPXIS (acc, sw1, sw1)}
17114@tab @code{__MCPXIS (@var{c}, @var{a}, @var{b})}
17115@tab @code{MCPXIS @var{a},@var{b},@var{c}}
17116@item @code{void __MCPXIU (acc, uw1, uw1)}
17117@tab @code{__MCPXIU (@var{c}, @var{a}, @var{b})}
17118@tab @code{MCPXIU @var{a},@var{b},@var{c}}
17119@item @code{void __MCPXRS (acc, sw1, sw1)}
17120@tab @code{__MCPXRS (@var{c}, @var{a}, @var{b})}
17121@tab @code{MCPXRS @var{a},@var{b},@var{c}}
17122@item @code{void __MCPXRU (acc, uw1, uw1)}
17123@tab @code{__MCPXRU (@var{c}, @var{a}, @var{b})}
17124@tab @code{MCPXRU @var{a},@var{b},@var{c}}
17125@item @code{uw1 __MCUT (acc, uw1)}
17126@tab @code{@var{c} = __MCUT (@var{a}, @var{b})}
17127@tab @code{MCUT @var{a},@var{b},@var{c}}
17128@item @code{uw1 __MCUTSS (acc, sw1)}
17129@tab @code{@var{c} = __MCUTSS (@var{a}, @var{b})}
17130@tab @code{MCUTSS @var{a},@var{b},@var{c}}
17131@item @code{void __MDADDACCS (acc, acc)}
17132@tab @code{__MDADDACCS (@var{b}, @var{a})}
17133@tab @code{MDADDACCS @var{a},@var{b}}
17134@item @code{void __MDASACCS (acc, acc)}
17135@tab @code{__MDASACCS (@var{b}, @var{a})}
17136@tab @code{MDASACCS @var{a},@var{b}}
17137@item @code{uw2 __MDCUTSSI (acc, const)}
17138@tab @code{@var{c} = __MDCUTSSI (@var{a}, @var{b})}
17139@tab @code{MDCUTSSI @var{a},#@var{b},@var{c}}
17140@item @code{uw2 __MDPACKH (uw2, uw2)}
17141@tab @code{@var{c} = __MDPACKH (@var{a}, @var{b})}
17142@tab @code{MDPACKH @var{a},@var{b},@var{c}}
17143@item @code{uw2 __MDROTLI (uw2, const)}
17144@tab @code{@var{c} = __MDROTLI (@var{a}, @var{b})}
17145@tab @code{MDROTLI @var{a},#@var{b},@var{c}}
17146@item @code{void __MDSUBACCS (acc, acc)}
17147@tab @code{__MDSUBACCS (@var{b}, @var{a})}
17148@tab @code{MDSUBACCS @var{a},@var{b}}
17149@item @code{void __MDUNPACKH (uw1 *, uw2)}
17150@tab @code{__MDUNPACKH (&@var{b}, @var{a})}
17151@tab @code{MDUNPACKH @var{a},@var{b}}
17152@item @code{uw2 __MEXPDHD (uw1, const)}
17153@tab @code{@var{c} = __MEXPDHD (@var{a}, @var{b})}
17154@tab @code{MEXPDHD @var{a},#@var{b},@var{c}}
17155@item @code{uw1 __MEXPDHW (uw1, const)}
17156@tab @code{@var{c} = __MEXPDHW (@var{a}, @var{b})}
17157@tab @code{MEXPDHW @var{a},#@var{b},@var{c}}
17158@item @code{uw1 __MHDSETH (uw1, const)}
17159@tab @code{@var{c} = __MHDSETH (@var{a}, @var{b})}
17160@tab @code{MHDSETH @var{a},#@var{b},@var{c}}
17161@item @code{sw1 __MHDSETS (const)}
17162@tab @code{@var{b} = __MHDSETS (@var{a})}
17163@tab @code{MHDSETS #@var{a},@var{b}}
17164@item @code{uw1 __MHSETHIH (uw1, const)}
17165@tab @code{@var{b} = __MHSETHIH (@var{b}, @var{a})}
17166@tab @code{MHSETHIH #@var{a},@var{b}}
17167@item @code{sw1 __MHSETHIS (sw1, const)}
17168@tab @code{@var{b} = __MHSETHIS (@var{b}, @var{a})}
17169@tab @code{MHSETHIS #@var{a},@var{b}}
17170@item @code{uw1 __MHSETLOH (uw1, const)}
17171@tab @code{@var{b} = __MHSETLOH (@var{b}, @var{a})}
17172@tab @code{MHSETLOH #@var{a},@var{b}}
17173@item @code{sw1 __MHSETLOS (sw1, const)}
17174@tab @code{@var{b} = __MHSETLOS (@var{b}, @var{a})}
17175@tab @code{MHSETLOS #@var{a},@var{b}}
17176@item @code{uw1 __MHTOB (uw2)}
17177@tab @code{@var{b} = __MHTOB (@var{a})}
17178@tab @code{MHTOB @var{a},@var{b}}
17179@item @code{void __MMACHS (acc, sw1, sw1)}
17180@tab @code{__MMACHS (@var{c}, @var{a}, @var{b})}
17181@tab @code{MMACHS @var{a},@var{b},@var{c}}
17182@item @code{void __MMACHU (acc, uw1, uw1)}
17183@tab @code{__MMACHU (@var{c}, @var{a}, @var{b})}
17184@tab @code{MMACHU @var{a},@var{b},@var{c}}
17185@item @code{void __MMRDHS (acc, sw1, sw1)}
17186@tab @code{__MMRDHS (@var{c}, @var{a}, @var{b})}
17187@tab @code{MMRDHS @var{a},@var{b},@var{c}}
17188@item @code{void __MMRDHU (acc, uw1, uw1)}
17189@tab @code{__MMRDHU (@var{c}, @var{a}, @var{b})}
17190@tab @code{MMRDHU @var{a},@var{b},@var{c}}
17191@item @code{void __MMULHS (acc, sw1, sw1)}
17192@tab @code{__MMULHS (@var{c}, @var{a}, @var{b})}
17193@tab @code{MMULHS @var{a},@var{b},@var{c}}
17194@item @code{void __MMULHU (acc, uw1, uw1)}
17195@tab @code{__MMULHU (@var{c}, @var{a}, @var{b})}
17196@tab @code{MMULHU @var{a},@var{b},@var{c}}
17197@item @code{void __MMULXHS (acc, sw1, sw1)}
17198@tab @code{__MMULXHS (@var{c}, @var{a}, @var{b})}
17199@tab @code{MMULXHS @var{a},@var{b},@var{c}}
17200@item @code{void __MMULXHU (acc, uw1, uw1)}
17201@tab @code{__MMULXHU (@var{c}, @var{a}, @var{b})}
17202@tab @code{MMULXHU @var{a},@var{b},@var{c}}
17203@item @code{uw1 __MNOT (uw1)}
17204@tab @code{@var{b} = __MNOT (@var{a})}
17205@tab @code{MNOT @var{a},@var{b}}
17206@item @code{uw1 __MOR (uw1, uw1)}
17207@tab @code{@var{c} = __MOR (@var{a}, @var{b})}
17208@tab @code{MOR @var{a},@var{b},@var{c}}
17209@item @code{uw1 __MPACKH (uh, uh)}
17210@tab @code{@var{c} = __MPACKH (@var{a}, @var{b})}
17211@tab @code{MPACKH @var{a},@var{b},@var{c}}
17212@item @code{sw2 __MQADDHSS (sw2, sw2)}
17213@tab @code{@var{c} = __MQADDHSS (@var{a}, @var{b})}
17214@tab @code{MQADDHSS @var{a},@var{b},@var{c}}
17215@item @code{uw2 __MQADDHUS (uw2, uw2)}
17216@tab @code{@var{c} = __MQADDHUS (@var{a}, @var{b})}
17217@tab @code{MQADDHUS @var{a},@var{b},@var{c}}
17218@item @code{void __MQCPXIS (acc, sw2, sw2)}
17219@tab @code{__MQCPXIS (@var{c}, @var{a}, @var{b})}
17220@tab @code{MQCPXIS @var{a},@var{b},@var{c}}
17221@item @code{void __MQCPXIU (acc, uw2, uw2)}
17222@tab @code{__MQCPXIU (@var{c}, @var{a}, @var{b})}
17223@tab @code{MQCPXIU @var{a},@var{b},@var{c}}
17224@item @code{void __MQCPXRS (acc, sw2, sw2)}
17225@tab @code{__MQCPXRS (@var{c}, @var{a}, @var{b})}
17226@tab @code{MQCPXRS @var{a},@var{b},@var{c}}
17227@item @code{void __MQCPXRU (acc, uw2, uw2)}
17228@tab @code{__MQCPXRU (@var{c}, @var{a}, @var{b})}
17229@tab @code{MQCPXRU @var{a},@var{b},@var{c}}
17230@item @code{sw2 __MQLCLRHS (sw2, sw2)}
17231@tab @code{@var{c} = __MQLCLRHS (@var{a}, @var{b})}
17232@tab @code{MQLCLRHS @var{a},@var{b},@var{c}}
17233@item @code{sw2 __MQLMTHS (sw2, sw2)}
17234@tab @code{@var{c} = __MQLMTHS (@var{a}, @var{b})}
17235@tab @code{MQLMTHS @var{a},@var{b},@var{c}}
17236@item @code{void __MQMACHS (acc, sw2, sw2)}
17237@tab @code{__MQMACHS (@var{c}, @var{a}, @var{b})}
17238@tab @code{MQMACHS @var{a},@var{b},@var{c}}
17239@item @code{void __MQMACHU (acc, uw2, uw2)}
17240@tab @code{__MQMACHU (@var{c}, @var{a}, @var{b})}
17241@tab @code{MQMACHU @var{a},@var{b},@var{c}}
17242@item @code{void __MQMACXHS (acc, sw2, sw2)}
17243@tab @code{__MQMACXHS (@var{c}, @var{a}, @var{b})}
17244@tab @code{MQMACXHS @var{a},@var{b},@var{c}}
17245@item @code{void __MQMULHS (acc, sw2, sw2)}
17246@tab @code{__MQMULHS (@var{c}, @var{a}, @var{b})}
17247@tab @code{MQMULHS @var{a},@var{b},@var{c}}
17248@item @code{void __MQMULHU (acc, uw2, uw2)}
17249@tab @code{__MQMULHU (@var{c}, @var{a}, @var{b})}
17250@tab @code{MQMULHU @var{a},@var{b},@var{c}}
17251@item @code{void __MQMULXHS (acc, sw2, sw2)}
17252@tab @code{__MQMULXHS (@var{c}, @var{a}, @var{b})}
17253@tab @code{MQMULXHS @var{a},@var{b},@var{c}}
17254@item @code{void __MQMULXHU (acc, uw2, uw2)}
17255@tab @code{__MQMULXHU (@var{c}, @var{a}, @var{b})}
17256@tab @code{MQMULXHU @var{a},@var{b},@var{c}}
17257@item @code{sw2 __MQSATHS (sw2, sw2)}
17258@tab @code{@var{c} = __MQSATHS (@var{a}, @var{b})}
17259@tab @code{MQSATHS @var{a},@var{b},@var{c}}
17260@item @code{uw2 __MQSLLHI (uw2, int)}
17261@tab @code{@var{c} = __MQSLLHI (@var{a}, @var{b})}
17262@tab @code{MQSLLHI @var{a},@var{b},@var{c}}
17263@item @code{sw2 __MQSRAHI (sw2, int)}
17264@tab @code{@var{c} = __MQSRAHI (@var{a}, @var{b})}
17265@tab @code{MQSRAHI @var{a},@var{b},@var{c}}
17266@item @code{sw2 __MQSUBHSS (sw2, sw2)}
17267@tab @code{@var{c} = __MQSUBHSS (@var{a}, @var{b})}
17268@tab @code{MQSUBHSS @var{a},@var{b},@var{c}}
17269@item @code{uw2 __MQSUBHUS (uw2, uw2)}
17270@tab @code{@var{c} = __MQSUBHUS (@var{a}, @var{b})}
17271@tab @code{MQSUBHUS @var{a},@var{b},@var{c}}
17272@item @code{void __MQXMACHS (acc, sw2, sw2)}
17273@tab @code{__MQXMACHS (@var{c}, @var{a}, @var{b})}
17274@tab @code{MQXMACHS @var{a},@var{b},@var{c}}
17275@item @code{void __MQXMACXHS (acc, sw2, sw2)}
17276@tab @code{__MQXMACXHS (@var{c}, @var{a}, @var{b})}
17277@tab @code{MQXMACXHS @var{a},@var{b},@var{c}}
17278@item @code{uw1 __MRDACC (acc)}
17279@tab @code{@var{b} = __MRDACC (@var{a})}
17280@tab @code{MRDACC @var{a},@var{b}}
17281@item @code{uw1 __MRDACCG (acc)}
17282@tab @code{@var{b} = __MRDACCG (@var{a})}
17283@tab @code{MRDACCG @var{a},@var{b}}
17284@item @code{uw1 __MROTLI (uw1, const)}
17285@tab @code{@var{c} = __MROTLI (@var{a}, @var{b})}
17286@tab @code{MROTLI @var{a},#@var{b},@var{c}}
17287@item @code{uw1 __MROTRI (uw1, const)}
17288@tab @code{@var{c} = __MROTRI (@var{a}, @var{b})}
17289@tab @code{MROTRI @var{a},#@var{b},@var{c}}
17290@item @code{sw1 __MSATHS (sw1, sw1)}
17291@tab @code{@var{c} = __MSATHS (@var{a}, @var{b})}
17292@tab @code{MSATHS @var{a},@var{b},@var{c}}
17293@item @code{uw1 __MSATHU (uw1, uw1)}
17294@tab @code{@var{c} = __MSATHU (@var{a}, @var{b})}
17295@tab @code{MSATHU @var{a},@var{b},@var{c}}
17296@item @code{uw1 __MSLLHI (uw1, const)}
17297@tab @code{@var{c} = __MSLLHI (@var{a}, @var{b})}
17298@tab @code{MSLLHI @var{a},#@var{b},@var{c}}
17299@item @code{sw1 __MSRAHI (sw1, const)}
17300@tab @code{@var{c} = __MSRAHI (@var{a}, @var{b})}
17301@tab @code{MSRAHI @var{a},#@var{b},@var{c}}
17302@item @code{uw1 __MSRLHI (uw1, const)}
17303@tab @code{@var{c} = __MSRLHI (@var{a}, @var{b})}
17304@tab @code{MSRLHI @var{a},#@var{b},@var{c}}
17305@item @code{void __MSUBACCS (acc, acc)}
17306@tab @code{__MSUBACCS (@var{b}, @var{a})}
17307@tab @code{MSUBACCS @var{a},@var{b}}
17308@item @code{sw1 __MSUBHSS (sw1, sw1)}
17309@tab @code{@var{c} = __MSUBHSS (@var{a}, @var{b})}
17310@tab @code{MSUBHSS @var{a},@var{b},@var{c}}
17311@item @code{uw1 __MSUBHUS (uw1, uw1)}
17312@tab @code{@var{c} = __MSUBHUS (@var{a}, @var{b})}
17313@tab @code{MSUBHUS @var{a},@var{b},@var{c}}
17314@item @code{void __MTRAP (void)}
17315@tab @code{__MTRAP ()}
17316@tab @code{MTRAP}
17317@item @code{uw2 __MUNPACKH (uw1)}
17318@tab @code{@var{b} = __MUNPACKH (@var{a})}
17319@tab @code{MUNPACKH @var{a},@var{b}}
17320@item @code{uw1 __MWCUT (uw2, uw1)}
17321@tab @code{@var{c} = __MWCUT (@var{a}, @var{b})}
17322@tab @code{MWCUT @var{a},@var{b},@var{c}}
17323@item @code{void __MWTACC (acc, uw1)}
17324@tab @code{__MWTACC (@var{b}, @var{a})}
17325@tab @code{MWTACC @var{a},@var{b}}
17326@item @code{void __MWTACCG (acc, uw1)}
17327@tab @code{__MWTACCG (@var{b}, @var{a})}
17328@tab @code{MWTACCG @var{a},@var{b}}
17329@item @code{uw1 __MXOR (uw1, uw1)}
17330@tab @code{@var{c} = __MXOR (@var{a}, @var{b})}
17331@tab @code{MXOR @var{a},@var{b},@var{c}}
17332@end multitable
17333
17334@node Raw read/write Functions
17335@subsubsection Raw Read/Write Functions
17336
17337This sections describes built-in functions related to read and write
17338instructions to access memory. These functions generate
17339@code{membar} instructions to flush the I/O load and stores where
17340appropriate, as described in Fujitsu's manual described above.
17341
17342@table @code
17343
17344@item unsigned char __builtin_read8 (void *@var{data})
17345@item unsigned short __builtin_read16 (void *@var{data})
17346@item unsigned long __builtin_read32 (void *@var{data})
17347@item unsigned long long __builtin_read64 (void *@var{data})
17348
17349@item void __builtin_write8 (void *@var{data}, unsigned char @var{datum})
17350@item void __builtin_write16 (void *@var{data}, unsigned short @var{datum})
17351@item void __builtin_write32 (void *@var{data}, unsigned long @var{datum})
17352@item void __builtin_write64 (void *@var{data}, unsigned long long @var{datum})
17353@end table
17354
17355@node Other Built-in Functions
17356@subsubsection Other Built-in Functions
17357
17358This section describes built-in functions that are not named after
17359a specific FR-V instruction.
17360
17361@table @code
17362@item sw2 __IACCreadll (iacc @var{reg})
17363Return the full 64-bit value of IACC0@. The @var{reg} argument is reserved
17364for future expansion and must be 0.
17365
17366@item sw1 __IACCreadl (iacc @var{reg})
17367Return the value of IACC0H if @var{reg} is 0 and IACC0L if @var{reg} is 1.
17368Other values of @var{reg} are rejected as invalid.
17369
17370@item void __IACCsetll (iacc @var{reg}, sw2 @var{x})
17371Set the full 64-bit value of IACC0 to @var{x}. The @var{reg} argument
17372is reserved for future expansion and must be 0.
17373
17374@item void __IACCsetl (iacc @var{reg}, sw1 @var{x})
17375Set IACC0H to @var{x} if @var{reg} is 0 and IACC0L to @var{x} if @var{reg}
17376is 1. Other values of @var{reg} are rejected as invalid.
17377
17378@item void __data_prefetch0 (const void *@var{x})
17379Use the @code{dcpl} instruction to load the contents of address @var{x}
17380into the data cache.
17381
17382@item void __data_prefetch (const void *@var{x})
17383Use the @code{nldub} instruction to load the contents of address @var{x}
17384into the data cache. The instruction is issued in slot I1@.
17385@end table
17386
5015cdf3
LC
17387@node LoongArch Base Built-in Functions
17388@subsection LoongArch Base Built-in Functions
17389
17390These built-in functions are available for LoongArch.
17391
17392Data Type Description:
17393@itemize
17394@item @code{imm0_31}, a compile-time constant in range 0 to 31;
17395@item @code{imm0_16383}, a compile-time constant in range 0 to 16383;
17396@item @code{imm0_32767}, a compile-time constant in range 0 to 32767;
17397@item @code{imm_n2048_2047}, a compile-time constant in range -2048 to 2047;
17398@end itemize
17399
17400The intrinsics provided are listed below:
17401@smallexample
17402 unsigned int __builtin_loongarch_movfcsr2gr (imm0_31)
17403 void __builtin_loongarch_movgr2fcsr (imm0_31, unsigned int)
17404 void __builtin_loongarch_cacop_d (imm0_31, unsigned long int, imm_n2048_2047)
17405 unsigned int __builtin_loongarch_cpucfg (unsigned int)
17406 void __builtin_loongarch_asrtle_d (long int, long int)
17407 void __builtin_loongarch_asrtgt_d (long int, long int)
17408 long int __builtin_loongarch_lddir_d (long int, imm0_31)
17409 void __builtin_loongarch_ldpte_d (long int, imm0_31)
17410
17411 int __builtin_loongarch_crc_w_b_w (char, int)
17412 int __builtin_loongarch_crc_w_h_w (short, int)
17413 int __builtin_loongarch_crc_w_w_w (int, int)
17414 int __builtin_loongarch_crc_w_d_w (long int, int)
17415 int __builtin_loongarch_crcc_w_b_w (char, int)
17416 int __builtin_loongarch_crcc_w_h_w (short, int)
17417 int __builtin_loongarch_crcc_w_w_w (int, int)
17418 int __builtin_loongarch_crcc_w_d_w (long int, int)
17419
17420 unsigned int __builtin_loongarch_csrrd_w (imm0_16383)
17421 unsigned int __builtin_loongarch_csrwr_w (unsigned int, imm0_16383)
17422 unsigned int __builtin_loongarch_csrxchg_w (unsigned int, unsigned int, imm0_16383)
17423 unsigned long int __builtin_loongarch_csrrd_d (imm0_16383)
17424 unsigned long int __builtin_loongarch_csrwr_d (unsigned long int, imm0_16383)
17425 unsigned long int __builtin_loongarch_csrxchg_d (unsigned long int, unsigned long int, imm0_16383)
17426
17427 unsigned char __builtin_loongarch_iocsrrd_b (unsigned int)
17428 unsigned short __builtin_loongarch_iocsrrd_h (unsigned int)
17429 unsigned int __builtin_loongarch_iocsrrd_w (unsigned int)
17430 unsigned long int __builtin_loongarch_iocsrrd_d (unsigned int)
17431 void __builtin_loongarch_iocsrwr_b (unsigned char, unsigned int)
17432 void __builtin_loongarch_iocsrwr_h (unsigned short, unsigned int)
17433 void __builtin_loongarch_iocsrwr_w (unsigned int, unsigned int)
17434 void __builtin_loongarch_iocsrwr_d (unsigned long int, unsigned int)
17435
17436 void __builtin_loongarch_dbar (imm0_32767)
17437 void __builtin_loongarch_ibar (imm0_32767)
17438
17439 void __builtin_loongarch_syscall (imm0_32767)
17440 void __builtin_loongarch_break (imm0_32767)
17441@end smallexample
17442
61f1001f
JX
17443These instrisic functions are available by using @option{-mfrecipe}.
17444@smallexample
17445 float __builtin_loongarch_frecipe_s (float);
17446 double __builtin_loongarch_frecipe_d (double);
17447 float __builtin_loongarch_frsqrte_s (float);
17448 double __builtin_loongarch_frsqrte_d (double);
17449@end smallexample
17450
5015cdf3
LC
17451@emph{Note:}Since the control register is divided into 32-bit and 64-bit,
17452but the access instruction is not distinguished. So GCC renames the control
17453instructions when implementing intrinsics.
17454
17455Take the csrrd instruction as an example, built-in functions are implemented as follows:
17456@smallexample
17457 __builtin_loongarch_csrrd_w // When reading the 32-bit control register use.
17458 __builtin_loongarch_csrrd_d // When reading the 64-bit control register use.
17459@end smallexample
17460
17461For the convenience of use, the built-in functions are encapsulated,
17462the encapsulated functions and @code{__drdtime_t, __rdtime_t} are
17463defined in the @code{larchintrin.h}. So if you call the following
17464function you need to include @code{larchintrin.h}.
17465
17466@smallexample
17467 typedef struct drdtime@{
17468 unsigned long dvalue;
17469 unsigned long dtimeid;
17470 @} __drdtime_t;
17471
17472 typedef struct rdtime@{
17473 unsigned int value;
17474 unsigned int timeid;
17475 @} __rdtime_t;
17476@end smallexample
17477
17478@smallexample
17479 __drdtime_t __rdtime_d (void)
17480 __rdtime_t __rdtimel_w (void)
17481 __rdtime_t __rdtimeh_w (void)
17482 unsigned int __movfcsr2gr (imm0_31)
17483 void __movgr2fcsr (imm0_31, unsigned int)
17484 void __cacop_d (imm0_31, unsigned long, imm_n2048_2047)
17485 unsigned int __cpucfg (unsigned int)
17486 void __asrtle_d (long int, long int)
17487 void __asrtgt_d (long int, long int)
17488 long int __lddir_d (long int, imm0_31)
17489 void __ldpte_d (long int, imm0_31)
17490
17491 int __crc_w_b_w (char, int)
17492 int __crc_w_h_w (short, int)
17493 int __crc_w_w_w (int, int)
17494 int __crc_w_d_w (long int, int)
17495 int __crcc_w_b_w (char, int)
17496 int __crcc_w_h_w (short, int)
17497 int __crcc_w_w_w (int, int)
17498 int __crcc_w_d_w (long int, int)
17499
17500 unsigned int __csrrd_w (imm0_16383)
17501 unsigned int __csrwr_w (unsigned int, imm0_16383)
17502 unsigned int __csrxchg_w (unsigned int, unsigned int, imm0_16383)
17503 unsigned long __csrrd_d (imm0_16383)
17504 unsigned long __csrwr_d (unsigned long, imm0_16383)
17505 unsigned long __csrxchg_d (unsigned long, unsigned long, imm0_16383)
17506
17507 unsigned char __iocsrrd_b (unsigned int)
17508 unsigned short __iocsrrd_h (unsigned int)
17509 unsigned int __iocsrrd_w (unsigned int)
17510 unsigned long __iocsrrd_d (unsigned int)
17511 void __iocsrwr_b (unsigned char, unsigned int)
17512 void __iocsrwr_h (unsigned short, unsigned int)
17513 void __iocsrwr_w (unsigned int, unsigned int)
17514 void __iocsrwr_d (unsigned long, unsigned int)
17515
17516 void __dbar (imm0_32767)
17517 void __ibar (imm0_32767)
17518
17519 void __syscall (imm0_32767)
17520 void __break (imm0_32767)
17521@end smallexample
17522
61f1001f
JX
17523These instrisic functions are available by including @code{larchintrin.h} and
17524using @option{-mfrecipe}.
17525@smallexample
17526 float __frecipe_s (float);
17527 double __frecipe_d (double);
17528 float __frsqrte_s (float);
17529 double __frsqrte_d (double);
17530@end smallexample
17531
4e2d53c9 17532Additional built-in functions are available for LoongArch family
17533processors to efficiently use 128-bit floating-point (__float128)
17534values.
17535
17536The following are the basic built-in functions supported.
17537@smallexample
17538__float128 __builtin_fabsq (__float128);
17539__float128 __builtin_copysignq (__float128, __float128);
17540__float128 __builtin_infq (void);
17541__float128 __builtin_huge_valq (void);
17542__float128 __builtin_nanq (void);
17543__float128 __builtin_nansq (void);
17544@end smallexample
17545
1b30ef7c 17546Returns the value that is currently set in the @samp{tp} register.
17547@smallexample
17548 void * __builtin_thread_pointer (void)
17549@end smallexample
17550
1f48786d 17551@node LoongArch SX Vector Intrinsics
17552@subsection LoongArch SX Vector Intrinsics
17553
17554GCC provides intrinsics to access the LSX (Loongson SIMD Extension) instructions.
17555The interface is made available by including @code{<lsxintrin.h>} and using
17556@option{-mlsx}.
17557
17558The following vectors typedefs are included in @code{lsxintrin.h}:
17559
17560@itemize
17561@item @code{__m128i}, a 128-bit vector of fixed point;
17562@item @code{__m128}, a 128-bit vector of single precision floating point;
17563@item @code{__m128d}, a 128-bit vector of double precision floating point.
17564@end itemize
17565
17566Instructions and corresponding built-ins may have additional restrictions and/or
17567input/output values manipulated:
17568@itemize
17569@item @code{imm0_1}, an integer literal in range 0 to 1;
17570@item @code{imm0_3}, an integer literal in range 0 to 3;
17571@item @code{imm0_7}, an integer literal in range 0 to 7;
17572@item @code{imm0_15}, an integer literal in range 0 to 15;
17573@item @code{imm0_31}, an integer literal in range 0 to 31;
17574@item @code{imm0_63}, an integer literal in range 0 to 63;
17575@item @code{imm0_127}, an integer literal in range 0 to 127;
17576@item @code{imm0_255}, an integer literal in range 0 to 255;
17577@item @code{imm_n16_15}, an integer literal in range -16 to 15;
17578@item @code{imm_n128_127}, an integer literal in range -128 to 127;
17579@item @code{imm_n256_255}, an integer literal in range -256 to 255;
17580@item @code{imm_n512_511}, an integer literal in range -512 to 511;
17581@item @code{imm_n1024_1023}, an integer literal in range -1024 to 1023;
17582@item @code{imm_n2048_2047}, an integer literal in range -2048 to 2047.
17583@end itemize
17584
17585For convenience, GCC defines functions @code{__lsx_vrepli_@{b/h/w/d@}} and
17586@code{__lsx_b[n]z_@{v/b/h/w/d@}}, which are implemented as follows:
17587
17588@smallexample
17589a. @code{__lsx_vrepli_@{b/h/w/d@}}: Implemented the case where the highest
17590 bit of @code{vldi} instruction @code{i13} is 1.
17591
17592 i13[12] == 1'b0
17593 case i13[11:10] of :
17594 2'b00: __lsx_vrepli_b (imm_n512_511)
17595 2'b01: __lsx_vrepli_h (imm_n512_511)
17596 2'b10: __lsx_vrepli_w (imm_n512_511)
17597 2'b11: __lsx_vrepli_d (imm_n512_511)
17598
17599b. @code{__lsx_b[n]z_@{v/b/h/w/d@}}: Since the @code{vseteqz} class directive
17600 cannot be used on its own, this function is defined.
17601
17602 _lsx_bz_v => vseteqz.v + bcnez
17603 _lsx_bnz_v => vsetnez.v + bcnez
17604 _lsx_bz_b => vsetanyeqz.b + bcnez
17605 _lsx_bz_h => vsetanyeqz.h + bcnez
17606 _lsx_bz_w => vsetanyeqz.w + bcnez
17607 _lsx_bz_d => vsetanyeqz.d + bcnez
17608 _lsx_bnz_b => vsetallnez.b + bcnez
17609 _lsx_bnz_h => vsetallnez.h + bcnez
17610 _lsx_bnz_w => vsetallnez.w + bcnez
17611 _lsx_bnz_d => vsetallnez.d + bcnez
17612@end smallexample
17613
17614@smallexample
17615eg:
17616 #include <lsxintrin.h>
17617
17618 extern __m128i @var{a};
17619
17620 void
17621 test (void)
17622 @{
17623 if (__lsx_bz_v (@var{a}))
17624 printf ("1\n");
17625 else
17626 printf ("2\n");
17627 @}
17628@end smallexample
17629
17630@emph{Note:} For directives where the intent operand is also the source operand
17631(modifying only part of the bitfield of the intent register), the first parameter
17632in the builtin call function is used as the intent operand.
17633
17634@smallexample
17635eg:
17636 #include <lsxintrin.h>
17637
17638 extern __m128i @var{dst};
17639 extern int @var{src};
17640
17641 void
17642 test (void)
17643 @{
17644 @var{dst} = __lsx_vinsgr2vr_b (@var{dst}, @var{src}, 3);
17645 @}
17646@end smallexample
17647
17648The intrinsics provided are listed below:
17649@smallexample
17650int __lsx_bnz_b (__m128i);
17651int __lsx_bnz_d (__m128i);
17652int __lsx_bnz_h (__m128i);
17653int __lsx_bnz_v (__m128i);
17654int __lsx_bnz_w (__m128i);
17655int __lsx_bz_b (__m128i);
17656int __lsx_bz_d (__m128i);
17657int __lsx_bz_h (__m128i);
17658int __lsx_bz_v (__m128i);
17659int __lsx_bz_w (__m128i);
17660__m128i __lsx_vabsd_b (__m128i, __m128i);
17661__m128i __lsx_vabsd_bu (__m128i, __m128i);
84ad1b53 17662__m128i __lsx_vabsd_d (__m128i, __m128i);
1f48786d 17663__m128i __lsx_vabsd_du (__m128i, __m128i);
17664__m128i __lsx_vabsd_h (__m128i, __m128i);
17665__m128i __lsx_vabsd_hu (__m128i, __m128i);
17666__m128i __lsx_vabsd_w (__m128i, __m128i);
17667__m128i __lsx_vabsd_wu (__m128i, __m128i);
17668__m128i __lsx_vadda_b (__m128i, __m128i);
17669__m128i __lsx_vadda_d (__m128i, __m128i);
17670__m128i __lsx_vadda_h (__m128i, __m128i);
17671__m128i __lsx_vadda_w (__m128i, __m128i);
17672__m128i __lsx_vadd_b (__m128i, __m128i);
17673__m128i __lsx_vadd_d (__m128i, __m128i);
17674__m128i __lsx_vadd_h (__m128i, __m128i);
17675__m128i __lsx_vaddi_bu (__m128i, imm0_31);
17676__m128i __lsx_vaddi_du (__m128i, imm0_31);
17677__m128i __lsx_vaddi_hu (__m128i, imm0_31);
17678__m128i __lsx_vaddi_wu (__m128i, imm0_31);
17679__m128i __lsx_vadd_q (__m128i, __m128i);
17680__m128i __lsx_vadd_w (__m128i, __m128i);
17681__m128i __lsx_vaddwev_d_w (__m128i, __m128i);
17682__m128i __lsx_vaddwev_d_wu (__m128i, __m128i);
17683__m128i __lsx_vaddwev_d_wu_w (__m128i, __m128i);
17684__m128i __lsx_vaddwev_h_b (__m128i, __m128i);
17685__m128i __lsx_vaddwev_h_bu (__m128i, __m128i);
17686__m128i __lsx_vaddwev_h_bu_b (__m128i, __m128i);
17687__m128i __lsx_vaddwev_q_d (__m128i, __m128i);
17688__m128i __lsx_vaddwev_q_du (__m128i, __m128i);
17689__m128i __lsx_vaddwev_q_du_d (__m128i, __m128i);
17690__m128i __lsx_vaddwev_w_h (__m128i, __m128i);
17691__m128i __lsx_vaddwev_w_hu (__m128i, __m128i);
17692__m128i __lsx_vaddwev_w_hu_h (__m128i, __m128i);
17693__m128i __lsx_vaddwod_d_w (__m128i, __m128i);
17694__m128i __lsx_vaddwod_d_wu (__m128i, __m128i);
17695__m128i __lsx_vaddwod_d_wu_w (__m128i, __m128i);
17696__m128i __lsx_vaddwod_h_b (__m128i, __m128i);
17697__m128i __lsx_vaddwod_h_bu (__m128i, __m128i);
17698__m128i __lsx_vaddwod_h_bu_b (__m128i, __m128i);
17699__m128i __lsx_vaddwod_q_d (__m128i, __m128i);
17700__m128i __lsx_vaddwod_q_du (__m128i, __m128i);
17701__m128i __lsx_vaddwod_q_du_d (__m128i, __m128i);
17702__m128i __lsx_vaddwod_w_h (__m128i, __m128i);
17703__m128i __lsx_vaddwod_w_hu (__m128i, __m128i);
17704__m128i __lsx_vaddwod_w_hu_h (__m128i, __m128i);
17705__m128i __lsx_vandi_b (__m128i, imm0_255);
17706__m128i __lsx_vandn_v (__m128i, __m128i);
17707__m128i __lsx_vand_v (__m128i, __m128i);
17708__m128i __lsx_vavg_b (__m128i, __m128i);
17709__m128i __lsx_vavg_bu (__m128i, __m128i);
17710__m128i __lsx_vavg_d (__m128i, __m128i);
17711__m128i __lsx_vavg_du (__m128i, __m128i);
17712__m128i __lsx_vavg_h (__m128i, __m128i);
17713__m128i __lsx_vavg_hu (__m128i, __m128i);
17714__m128i __lsx_vavgr_b (__m128i, __m128i);
17715__m128i __lsx_vavgr_bu (__m128i, __m128i);
17716__m128i __lsx_vavgr_d (__m128i, __m128i);
17717__m128i __lsx_vavgr_du (__m128i, __m128i);
17718__m128i __lsx_vavgr_h (__m128i, __m128i);
17719__m128i __lsx_vavgr_hu (__m128i, __m128i);
17720__m128i __lsx_vavgr_w (__m128i, __m128i);
17721__m128i __lsx_vavgr_wu (__m128i, __m128i);
17722__m128i __lsx_vavg_w (__m128i, __m128i);
17723__m128i __lsx_vavg_wu (__m128i, __m128i);
17724__m128i __lsx_vbitclr_b (__m128i, __m128i);
17725__m128i __lsx_vbitclr_d (__m128i, __m128i);
17726__m128i __lsx_vbitclr_h (__m128i, __m128i);
17727__m128i __lsx_vbitclri_b (__m128i, imm0_7);
17728__m128i __lsx_vbitclri_d (__m128i, imm0_63);
17729__m128i __lsx_vbitclri_h (__m128i, imm0_15);
17730__m128i __lsx_vbitclri_w (__m128i, imm0_31);
17731__m128i __lsx_vbitclr_w (__m128i, __m128i);
17732__m128i __lsx_vbitrev_b (__m128i, __m128i);
17733__m128i __lsx_vbitrev_d (__m128i, __m128i);
17734__m128i __lsx_vbitrev_h (__m128i, __m128i);
17735__m128i __lsx_vbitrevi_b (__m128i, imm0_7);
17736__m128i __lsx_vbitrevi_d (__m128i, imm0_63);
17737__m128i __lsx_vbitrevi_h (__m128i, imm0_15);
17738__m128i __lsx_vbitrevi_w (__m128i, imm0_31);
17739__m128i __lsx_vbitrev_w (__m128i, __m128i);
17740__m128i __lsx_vbitseli_b (__m128i, __m128i, imm0_255);
17741__m128i __lsx_vbitsel_v (__m128i, __m128i, __m128i);
17742__m128i __lsx_vbitset_b (__m128i, __m128i);
17743__m128i __lsx_vbitset_d (__m128i, __m128i);
17744__m128i __lsx_vbitset_h (__m128i, __m128i);
17745__m128i __lsx_vbitseti_b (__m128i, imm0_7);
17746__m128i __lsx_vbitseti_d (__m128i, imm0_63);
17747__m128i __lsx_vbitseti_h (__m128i, imm0_15);
17748__m128i __lsx_vbitseti_w (__m128i, imm0_31);
17749__m128i __lsx_vbitset_w (__m128i, __m128i);
17750__m128i __lsx_vbsll_v (__m128i, imm0_31);
17751__m128i __lsx_vbsrl_v (__m128i, imm0_31);
17752__m128i __lsx_vclo_b (__m128i);
17753__m128i __lsx_vclo_d (__m128i);
17754__m128i __lsx_vclo_h (__m128i);
17755__m128i __lsx_vclo_w (__m128i);
17756__m128i __lsx_vclz_b (__m128i);
17757__m128i __lsx_vclz_d (__m128i);
17758__m128i __lsx_vclz_h (__m128i);
17759__m128i __lsx_vclz_w (__m128i);
17760__m128i __lsx_vdiv_b (__m128i, __m128i);
17761__m128i __lsx_vdiv_bu (__m128i, __m128i);
17762__m128i __lsx_vdiv_d (__m128i, __m128i);
17763__m128i __lsx_vdiv_du (__m128i, __m128i);
17764__m128i __lsx_vdiv_h (__m128i, __m128i);
17765__m128i __lsx_vdiv_hu (__m128i, __m128i);
17766__m128i __lsx_vdiv_w (__m128i, __m128i);
17767__m128i __lsx_vdiv_wu (__m128i, __m128i);
17768__m128i __lsx_vexth_du_wu (__m128i);
17769__m128i __lsx_vexth_d_w (__m128i);
17770__m128i __lsx_vexth_h_b (__m128i);
17771__m128i __lsx_vexth_hu_bu (__m128i);
17772__m128i __lsx_vexth_q_d (__m128i);
17773__m128i __lsx_vexth_qu_du (__m128i);
17774__m128i __lsx_vexth_w_h (__m128i);
17775__m128i __lsx_vexth_wu_hu (__m128i);
17776__m128i __lsx_vextl_q_d (__m128i);
17777__m128i __lsx_vextl_qu_du (__m128i);
17778__m128i __lsx_vextrins_b (__m128i, __m128i, imm0_255);
17779__m128i __lsx_vextrins_d (__m128i, __m128i, imm0_255);
17780__m128i __lsx_vextrins_h (__m128i, __m128i, imm0_255);
17781__m128i __lsx_vextrins_w (__m128i, __m128i, imm0_255);
17782__m128d __lsx_vfadd_d (__m128d, __m128d);
17783__m128 __lsx_vfadd_s (__m128, __m128);
17784__m128i __lsx_vfclass_d (__m128d);
17785__m128i __lsx_vfclass_s (__m128);
17786__m128i __lsx_vfcmp_caf_d (__m128d, __m128d);
17787__m128i __lsx_vfcmp_caf_s (__m128, __m128);
17788__m128i __lsx_vfcmp_ceq_d (__m128d, __m128d);
17789__m128i __lsx_vfcmp_ceq_s (__m128, __m128);
17790__m128i __lsx_vfcmp_cle_d (__m128d, __m128d);
17791__m128i __lsx_vfcmp_cle_s (__m128, __m128);
17792__m128i __lsx_vfcmp_clt_d (__m128d, __m128d);
17793__m128i __lsx_vfcmp_clt_s (__m128, __m128);
17794__m128i __lsx_vfcmp_cne_d (__m128d, __m128d);
17795__m128i __lsx_vfcmp_cne_s (__m128, __m128);
17796__m128i __lsx_vfcmp_cor_d (__m128d, __m128d);
17797__m128i __lsx_vfcmp_cor_s (__m128, __m128);
17798__m128i __lsx_vfcmp_cueq_d (__m128d, __m128d);
17799__m128i __lsx_vfcmp_cueq_s (__m128, __m128);
17800__m128i __lsx_vfcmp_cule_d (__m128d, __m128d);
17801__m128i __lsx_vfcmp_cule_s (__m128, __m128);
17802__m128i __lsx_vfcmp_cult_d (__m128d, __m128d);
17803__m128i __lsx_vfcmp_cult_s (__m128, __m128);
17804__m128i __lsx_vfcmp_cun_d (__m128d, __m128d);
17805__m128i __lsx_vfcmp_cune_d (__m128d, __m128d);
17806__m128i __lsx_vfcmp_cune_s (__m128, __m128);
17807__m128i __lsx_vfcmp_cun_s (__m128, __m128);
17808__m128i __lsx_vfcmp_saf_d (__m128d, __m128d);
17809__m128i __lsx_vfcmp_saf_s (__m128, __m128);
17810__m128i __lsx_vfcmp_seq_d (__m128d, __m128d);
17811__m128i __lsx_vfcmp_seq_s (__m128, __m128);
17812__m128i __lsx_vfcmp_sle_d (__m128d, __m128d);
17813__m128i __lsx_vfcmp_sle_s (__m128, __m128);
17814__m128i __lsx_vfcmp_slt_d (__m128d, __m128d);
17815__m128i __lsx_vfcmp_slt_s (__m128, __m128);
17816__m128i __lsx_vfcmp_sne_d (__m128d, __m128d);
17817__m128i __lsx_vfcmp_sne_s (__m128, __m128);
17818__m128i __lsx_vfcmp_sor_d (__m128d, __m128d);
17819__m128i __lsx_vfcmp_sor_s (__m128, __m128);
17820__m128i __lsx_vfcmp_sueq_d (__m128d, __m128d);
17821__m128i __lsx_vfcmp_sueq_s (__m128, __m128);
17822__m128i __lsx_vfcmp_sule_d (__m128d, __m128d);
17823__m128i __lsx_vfcmp_sule_s (__m128, __m128);
17824__m128i __lsx_vfcmp_sult_d (__m128d, __m128d);
17825__m128i __lsx_vfcmp_sult_s (__m128, __m128);
17826__m128i __lsx_vfcmp_sun_d (__m128d, __m128d);
17827__m128i __lsx_vfcmp_sune_d (__m128d, __m128d);
17828__m128i __lsx_vfcmp_sune_s (__m128, __m128);
17829__m128i __lsx_vfcmp_sun_s (__m128, __m128);
17830__m128d __lsx_vfcvth_d_s (__m128);
17831__m128i __lsx_vfcvt_h_s (__m128, __m128);
17832__m128 __lsx_vfcvth_s_h (__m128i);
17833__m128d __lsx_vfcvtl_d_s (__m128);
17834__m128 __lsx_vfcvtl_s_h (__m128i);
17835__m128 __lsx_vfcvt_s_d (__m128d, __m128d);
17836__m128d __lsx_vfdiv_d (__m128d, __m128d);
17837__m128 __lsx_vfdiv_s (__m128, __m128);
17838__m128d __lsx_vffint_d_l (__m128i);
17839__m128d __lsx_vffint_d_lu (__m128i);
17840__m128d __lsx_vffinth_d_w (__m128i);
17841__m128d __lsx_vffintl_d_w (__m128i);
17842__m128 __lsx_vffint_s_l (__m128i, __m128i);
17843__m128 __lsx_vffint_s_w (__m128i);
17844__m128 __lsx_vffint_s_wu (__m128i);
17845__m128d __lsx_vflogb_d (__m128d);
17846__m128 __lsx_vflogb_s (__m128);
17847__m128d __lsx_vfmadd_d (__m128d, __m128d, __m128d);
17848__m128 __lsx_vfmadd_s (__m128, __m128, __m128);
17849__m128d __lsx_vfmaxa_d (__m128d, __m128d);
17850__m128 __lsx_vfmaxa_s (__m128, __m128);
17851__m128d __lsx_vfmax_d (__m128d, __m128d);
17852__m128 __lsx_vfmax_s (__m128, __m128);
17853__m128d __lsx_vfmina_d (__m128d, __m128d);
17854__m128 __lsx_vfmina_s (__m128, __m128);
17855__m128d __lsx_vfmin_d (__m128d, __m128d);
17856__m128 __lsx_vfmin_s (__m128, __m128);
17857__m128d __lsx_vfmsub_d (__m128d, __m128d, __m128d);
17858__m128 __lsx_vfmsub_s (__m128, __m128, __m128);
17859__m128d __lsx_vfmul_d (__m128d, __m128d);
17860__m128 __lsx_vfmul_s (__m128, __m128);
17861__m128d __lsx_vfnmadd_d (__m128d, __m128d, __m128d);
17862__m128 __lsx_vfnmadd_s (__m128, __m128, __m128);
17863__m128d __lsx_vfnmsub_d (__m128d, __m128d, __m128d);
17864__m128 __lsx_vfnmsub_s (__m128, __m128, __m128);
17865__m128d __lsx_vfrecip_d (__m128d);
17866__m128 __lsx_vfrecip_s (__m128);
17867__m128d __lsx_vfrint_d (__m128d);
84ad1b53
JC
17868__m128d __lsx_vfrintrm_d (__m128d);
17869__m128 __lsx_vfrintrm_s (__m128);
17870__m128d __lsx_vfrintrne_d (__m128d);
17871__m128 __lsx_vfrintrne_s (__m128);
17872__m128d __lsx_vfrintrp_d (__m128d);
17873__m128 __lsx_vfrintrp_s (__m128);
17874__m128d __lsx_vfrintrz_d (__m128d);
17875__m128 __lsx_vfrintrz_s (__m128);
1f48786d 17876__m128 __lsx_vfrint_s (__m128);
17877__m128d __lsx_vfrsqrt_d (__m128d);
17878__m128 __lsx_vfrsqrt_s (__m128);
17879__m128i __lsx_vfrstp_b (__m128i, __m128i, __m128i);
17880__m128i __lsx_vfrstp_h (__m128i, __m128i, __m128i);
17881__m128i __lsx_vfrstpi_b (__m128i, __m128i, imm0_31);
17882__m128i __lsx_vfrstpi_h (__m128i, __m128i, imm0_31);
17883__m128d __lsx_vfsqrt_d (__m128d);
17884__m128 __lsx_vfsqrt_s (__m128);
17885__m128d __lsx_vfsub_d (__m128d, __m128d);
17886__m128 __lsx_vfsub_s (__m128, __m128);
17887__m128i __lsx_vftinth_l_s (__m128);
17888__m128i __lsx_vftint_l_d (__m128d);
17889__m128i __lsx_vftintl_l_s (__m128);
17890__m128i __lsx_vftint_lu_d (__m128d);
17891__m128i __lsx_vftintrmh_l_s (__m128);
17892__m128i __lsx_vftintrm_l_d (__m128d);
17893__m128i __lsx_vftintrml_l_s (__m128);
17894__m128i __lsx_vftintrm_w_d (__m128d, __m128d);
17895__m128i __lsx_vftintrm_w_s (__m128);
17896__m128i __lsx_vftintrneh_l_s (__m128);
17897__m128i __lsx_vftintrne_l_d (__m128d);
17898__m128i __lsx_vftintrnel_l_s (__m128);
17899__m128i __lsx_vftintrne_w_d (__m128d, __m128d);
17900__m128i __lsx_vftintrne_w_s (__m128);
17901__m128i __lsx_vftintrph_l_s (__m128);
17902__m128i __lsx_vftintrp_l_d (__m128d);
17903__m128i __lsx_vftintrpl_l_s (__m128);
17904__m128i __lsx_vftintrp_w_d (__m128d, __m128d);
17905__m128i __lsx_vftintrp_w_s (__m128);
17906__m128i __lsx_vftintrzh_l_s (__m128);
17907__m128i __lsx_vftintrz_l_d (__m128d);
17908__m128i __lsx_vftintrzl_l_s (__m128);
17909__m128i __lsx_vftintrz_lu_d (__m128d);
17910__m128i __lsx_vftintrz_w_d (__m128d, __m128d);
17911__m128i __lsx_vftintrz_w_s (__m128);
17912__m128i __lsx_vftintrz_wu_s (__m128);
17913__m128i __lsx_vftint_w_d (__m128d, __m128d);
17914__m128i __lsx_vftint_w_s (__m128);
17915__m128i __lsx_vftint_wu_s (__m128);
17916__m128i __lsx_vhaddw_du_wu (__m128i, __m128i);
17917__m128i __lsx_vhaddw_d_w (__m128i, __m128i);
17918__m128i __lsx_vhaddw_h_b (__m128i, __m128i);
17919__m128i __lsx_vhaddw_hu_bu (__m128i, __m128i);
17920__m128i __lsx_vhaddw_q_d (__m128i, __m128i);
17921__m128i __lsx_vhaddw_qu_du (__m128i, __m128i);
17922__m128i __lsx_vhaddw_w_h (__m128i, __m128i);
17923__m128i __lsx_vhaddw_wu_hu (__m128i, __m128i);
17924__m128i __lsx_vhsubw_du_wu (__m128i, __m128i);
17925__m128i __lsx_vhsubw_d_w (__m128i, __m128i);
17926__m128i __lsx_vhsubw_h_b (__m128i, __m128i);
17927__m128i __lsx_vhsubw_hu_bu (__m128i, __m128i);
17928__m128i __lsx_vhsubw_q_d (__m128i, __m128i);
17929__m128i __lsx_vhsubw_qu_du (__m128i, __m128i);
17930__m128i __lsx_vhsubw_w_h (__m128i, __m128i);
17931__m128i __lsx_vhsubw_wu_hu (__m128i, __m128i);
17932__m128i __lsx_vilvh_b (__m128i, __m128i);
17933__m128i __lsx_vilvh_d (__m128i, __m128i);
17934__m128i __lsx_vilvh_h (__m128i, __m128i);
17935__m128i __lsx_vilvh_w (__m128i, __m128i);
17936__m128i __lsx_vilvl_b (__m128i, __m128i);
17937__m128i __lsx_vilvl_d (__m128i, __m128i);
17938__m128i __lsx_vilvl_h (__m128i, __m128i);
17939__m128i __lsx_vilvl_w (__m128i, __m128i);
17940__m128i __lsx_vinsgr2vr_b (__m128i, int, imm0_15);
17941__m128i __lsx_vinsgr2vr_d (__m128i, long int, imm0_1);
17942__m128i __lsx_vinsgr2vr_h (__m128i, int, imm0_7);
17943__m128i __lsx_vinsgr2vr_w (__m128i, int, imm0_3);
84ad1b53
JC
17944__m128i __lsx_vld (void *, imm_n2048_2047);
17945__m128i __lsx_vldi (imm_n1024_1023);
17946__m128i __lsx_vldrepl_b (void *, imm_n2048_2047);
17947__m128i __lsx_vldrepl_d (void *, imm_n256_255);
17948__m128i __lsx_vldrepl_h (void *, imm_n1024_1023);
17949__m128i __lsx_vldrepl_w (void *, imm_n512_511);
1f48786d 17950__m128i __lsx_vldx (void *, long int);
17951__m128i __lsx_vmadd_b (__m128i, __m128i, __m128i);
17952__m128i __lsx_vmadd_d (__m128i, __m128i, __m128i);
17953__m128i __lsx_vmadd_h (__m128i, __m128i, __m128i);
17954__m128i __lsx_vmadd_w (__m128i, __m128i, __m128i);
17955__m128i __lsx_vmaddwev_d_w (__m128i, __m128i, __m128i);
17956__m128i __lsx_vmaddwev_d_wu (__m128i, __m128i, __m128i);
17957__m128i __lsx_vmaddwev_d_wu_w (__m128i, __m128i, __m128i);
17958__m128i __lsx_vmaddwev_h_b (__m128i, __m128i, __m128i);
17959__m128i __lsx_vmaddwev_h_bu (__m128i, __m128i, __m128i);
17960__m128i __lsx_vmaddwev_h_bu_b (__m128i, __m128i, __m128i);
17961__m128i __lsx_vmaddwev_q_d (__m128i, __m128i, __m128i);
17962__m128i __lsx_vmaddwev_q_du (__m128i, __m128i, __m128i);
17963__m128i __lsx_vmaddwev_q_du_d (__m128i, __m128i, __m128i);
17964__m128i __lsx_vmaddwev_w_h (__m128i, __m128i, __m128i);
17965__m128i __lsx_vmaddwev_w_hu (__m128i, __m128i, __m128i);
17966__m128i __lsx_vmaddwev_w_hu_h (__m128i, __m128i, __m128i);
17967__m128i __lsx_vmaddwod_d_w (__m128i, __m128i, __m128i);
17968__m128i __lsx_vmaddwod_d_wu (__m128i, __m128i, __m128i);
17969__m128i __lsx_vmaddwod_d_wu_w (__m128i, __m128i, __m128i);
17970__m128i __lsx_vmaddwod_h_b (__m128i, __m128i, __m128i);
17971__m128i __lsx_vmaddwod_h_bu (__m128i, __m128i, __m128i);
17972__m128i __lsx_vmaddwod_h_bu_b (__m128i, __m128i, __m128i);
17973__m128i __lsx_vmaddwod_q_d (__m128i, __m128i, __m128i);
17974__m128i __lsx_vmaddwod_q_du (__m128i, __m128i, __m128i);
17975__m128i __lsx_vmaddwod_q_du_d (__m128i, __m128i, __m128i);
17976__m128i __lsx_vmaddwod_w_h (__m128i, __m128i, __m128i);
17977__m128i __lsx_vmaddwod_w_hu (__m128i, __m128i, __m128i);
17978__m128i __lsx_vmaddwod_w_hu_h (__m128i, __m128i, __m128i);
17979__m128i __lsx_vmax_b (__m128i, __m128i);
17980__m128i __lsx_vmax_bu (__m128i, __m128i);
17981__m128i __lsx_vmax_d (__m128i, __m128i);
17982__m128i __lsx_vmax_du (__m128i, __m128i);
17983__m128i __lsx_vmax_h (__m128i, __m128i);
17984__m128i __lsx_vmax_hu (__m128i, __m128i);
84ad1b53 17985__m128i __lsx_vmaxi_b (__m128i, imm_n16_15);
1f48786d 17986__m128i __lsx_vmaxi_bu (__m128i, imm0_31);
84ad1b53 17987__m128i __lsx_vmaxi_d (__m128i, imm_n16_15);
1f48786d 17988__m128i __lsx_vmaxi_du (__m128i, imm0_31);
84ad1b53 17989__m128i __lsx_vmaxi_h (__m128i, imm_n16_15);
1f48786d 17990__m128i __lsx_vmaxi_hu (__m128i, imm0_31);
84ad1b53 17991__m128i __lsx_vmaxi_w (__m128i, imm_n16_15);
1f48786d 17992__m128i __lsx_vmaxi_wu (__m128i, imm0_31);
17993__m128i __lsx_vmax_w (__m128i, __m128i);
17994__m128i __lsx_vmax_wu (__m128i, __m128i);
17995__m128i __lsx_vmin_b (__m128i, __m128i);
17996__m128i __lsx_vmin_bu (__m128i, __m128i);
17997__m128i __lsx_vmin_d (__m128i, __m128i);
17998__m128i __lsx_vmin_du (__m128i, __m128i);
17999__m128i __lsx_vmin_h (__m128i, __m128i);
18000__m128i __lsx_vmin_hu (__m128i, __m128i);
84ad1b53 18001__m128i __lsx_vmini_b (__m128i, imm_n16_15);
1f48786d 18002__m128i __lsx_vmini_bu (__m128i, imm0_31);
84ad1b53 18003__m128i __lsx_vmini_d (__m128i, imm_n16_15);
1f48786d 18004__m128i __lsx_vmini_du (__m128i, imm0_31);
84ad1b53 18005__m128i __lsx_vmini_h (__m128i, imm_n16_15);
1f48786d 18006__m128i __lsx_vmini_hu (__m128i, imm0_31);
84ad1b53 18007__m128i __lsx_vmini_w (__m128i, imm_n16_15);
1f48786d 18008__m128i __lsx_vmini_wu (__m128i, imm0_31);
18009__m128i __lsx_vmin_w (__m128i, __m128i);
18010__m128i __lsx_vmin_wu (__m128i, __m128i);
18011__m128i __lsx_vmod_b (__m128i, __m128i);
18012__m128i __lsx_vmod_bu (__m128i, __m128i);
18013__m128i __lsx_vmod_d (__m128i, __m128i);
18014__m128i __lsx_vmod_du (__m128i, __m128i);
18015__m128i __lsx_vmod_h (__m128i, __m128i);
18016__m128i __lsx_vmod_hu (__m128i, __m128i);
18017__m128i __lsx_vmod_w (__m128i, __m128i);
18018__m128i __lsx_vmod_wu (__m128i, __m128i);
18019__m128i __lsx_vmskgez_b (__m128i);
18020__m128i __lsx_vmskltz_b (__m128i);
18021__m128i __lsx_vmskltz_d (__m128i);
18022__m128i __lsx_vmskltz_h (__m128i);
18023__m128i __lsx_vmskltz_w (__m128i);
18024__m128i __lsx_vmsknz_b (__m128i);
18025__m128i __lsx_vmsub_b (__m128i, __m128i, __m128i);
18026__m128i __lsx_vmsub_d (__m128i, __m128i, __m128i);
18027__m128i __lsx_vmsub_h (__m128i, __m128i, __m128i);
18028__m128i __lsx_vmsub_w (__m128i, __m128i, __m128i);
18029__m128i __lsx_vmuh_b (__m128i, __m128i);
18030__m128i __lsx_vmuh_bu (__m128i, __m128i);
18031__m128i __lsx_vmuh_d (__m128i, __m128i);
18032__m128i __lsx_vmuh_du (__m128i, __m128i);
18033__m128i __lsx_vmuh_h (__m128i, __m128i);
18034__m128i __lsx_vmuh_hu (__m128i, __m128i);
18035__m128i __lsx_vmuh_w (__m128i, __m128i);
18036__m128i __lsx_vmuh_wu (__m128i, __m128i);
18037__m128i __lsx_vmul_b (__m128i, __m128i);
18038__m128i __lsx_vmul_d (__m128i, __m128i);
18039__m128i __lsx_vmul_h (__m128i, __m128i);
18040__m128i __lsx_vmul_w (__m128i, __m128i);
18041__m128i __lsx_vmulwev_d_w (__m128i, __m128i);
18042__m128i __lsx_vmulwev_d_wu (__m128i, __m128i);
18043__m128i __lsx_vmulwev_d_wu_w (__m128i, __m128i);
18044__m128i __lsx_vmulwev_h_b (__m128i, __m128i);
18045__m128i __lsx_vmulwev_h_bu (__m128i, __m128i);
18046__m128i __lsx_vmulwev_h_bu_b (__m128i, __m128i);
18047__m128i __lsx_vmulwev_q_d (__m128i, __m128i);
18048__m128i __lsx_vmulwev_q_du (__m128i, __m128i);
18049__m128i __lsx_vmulwev_q_du_d (__m128i, __m128i);
18050__m128i __lsx_vmulwev_w_h (__m128i, __m128i);
18051__m128i __lsx_vmulwev_w_hu (__m128i, __m128i);
18052__m128i __lsx_vmulwev_w_hu_h (__m128i, __m128i);
18053__m128i __lsx_vmulwod_d_w (__m128i, __m128i);
18054__m128i __lsx_vmulwod_d_wu (__m128i, __m128i);
18055__m128i __lsx_vmulwod_d_wu_w (__m128i, __m128i);
18056__m128i __lsx_vmulwod_h_b (__m128i, __m128i);
18057__m128i __lsx_vmulwod_h_bu (__m128i, __m128i);
18058__m128i __lsx_vmulwod_h_bu_b (__m128i, __m128i);
18059__m128i __lsx_vmulwod_q_d (__m128i, __m128i);
18060__m128i __lsx_vmulwod_q_du (__m128i, __m128i);
18061__m128i __lsx_vmulwod_q_du_d (__m128i, __m128i);
18062__m128i __lsx_vmulwod_w_h (__m128i, __m128i);
18063__m128i __lsx_vmulwod_w_hu (__m128i, __m128i);
18064__m128i __lsx_vmulwod_w_hu_h (__m128i, __m128i);
18065__m128i __lsx_vneg_b (__m128i);
18066__m128i __lsx_vneg_d (__m128i);
18067__m128i __lsx_vneg_h (__m128i);
18068__m128i __lsx_vneg_w (__m128i);
18069__m128i __lsx_vnori_b (__m128i, imm0_255);
18070__m128i __lsx_vnor_v (__m128i, __m128i);
18071__m128i __lsx_vori_b (__m128i, imm0_255);
18072__m128i __lsx_vorn_v (__m128i, __m128i);
18073__m128i __lsx_vor_v (__m128i, __m128i);
18074__m128i __lsx_vpackev_b (__m128i, __m128i);
18075__m128i __lsx_vpackev_d (__m128i, __m128i);
18076__m128i __lsx_vpackev_h (__m128i, __m128i);
18077__m128i __lsx_vpackev_w (__m128i, __m128i);
18078__m128i __lsx_vpackod_b (__m128i, __m128i);
18079__m128i __lsx_vpackod_d (__m128i, __m128i);
18080__m128i __lsx_vpackod_h (__m128i, __m128i);
18081__m128i __lsx_vpackod_w (__m128i, __m128i);
18082__m128i __lsx_vpcnt_b (__m128i);
18083__m128i __lsx_vpcnt_d (__m128i);
18084__m128i __lsx_vpcnt_h (__m128i);
18085__m128i __lsx_vpcnt_w (__m128i);
18086__m128i __lsx_vpermi_w (__m128i, __m128i, imm0_255);
18087__m128i __lsx_vpickev_b (__m128i, __m128i);
18088__m128i __lsx_vpickev_d (__m128i, __m128i);
18089__m128i __lsx_vpickev_h (__m128i, __m128i);
18090__m128i __lsx_vpickev_w (__m128i, __m128i);
18091__m128i __lsx_vpickod_b (__m128i, __m128i);
18092__m128i __lsx_vpickod_d (__m128i, __m128i);
18093__m128i __lsx_vpickod_h (__m128i, __m128i);
18094__m128i __lsx_vpickod_w (__m128i, __m128i);
18095int __lsx_vpickve2gr_b (__m128i, imm0_15);
84ad1b53 18096unsigned int __lsx_vpickve2gr_bu (__m128i, imm0_15);
1f48786d 18097long int __lsx_vpickve2gr_d (__m128i, imm0_1);
18098unsigned long int __lsx_vpickve2gr_du (__m128i, imm0_1);
18099int __lsx_vpickve2gr_h (__m128i, imm0_7);
84ad1b53 18100unsigned int __lsx_vpickve2gr_hu (__m128i, imm0_7);
1f48786d 18101int __lsx_vpickve2gr_w (__m128i, imm0_3);
18102unsigned int __lsx_vpickve2gr_wu (__m128i, imm0_3);
18103__m128i __lsx_vreplgr2vr_b (int);
18104__m128i __lsx_vreplgr2vr_d (long int);
18105__m128i __lsx_vreplgr2vr_h (int);
18106__m128i __lsx_vreplgr2vr_w (int);
18107__m128i __lsx_vrepli_b (imm_n512_511);
18108__m128i __lsx_vrepli_d (imm_n512_511);
18109__m128i __lsx_vrepli_h (imm_n512_511);
18110__m128i __lsx_vrepli_w (imm_n512_511);
18111__m128i __lsx_vreplve_b (__m128i, int);
18112__m128i __lsx_vreplve_d (__m128i, int);
18113__m128i __lsx_vreplve_h (__m128i, int);
18114__m128i __lsx_vreplvei_b (__m128i, imm0_15);
18115__m128i __lsx_vreplvei_d (__m128i, imm0_1);
18116__m128i __lsx_vreplvei_h (__m128i, imm0_7);
18117__m128i __lsx_vreplvei_w (__m128i, imm0_3);
18118__m128i __lsx_vreplve_w (__m128i, int);
18119__m128i __lsx_vrotr_b (__m128i, __m128i);
18120__m128i __lsx_vrotr_d (__m128i, __m128i);
18121__m128i __lsx_vrotr_h (__m128i, __m128i);
18122__m128i __lsx_vrotri_b (__m128i, imm0_7);
18123__m128i __lsx_vrotri_d (__m128i, imm0_63);
18124__m128i __lsx_vrotri_h (__m128i, imm0_15);
18125__m128i __lsx_vrotri_w (__m128i, imm0_31);
18126__m128i __lsx_vrotr_w (__m128i, __m128i);
18127__m128i __lsx_vsadd_b (__m128i, __m128i);
18128__m128i __lsx_vsadd_bu (__m128i, __m128i);
18129__m128i __lsx_vsadd_d (__m128i, __m128i);
18130__m128i __lsx_vsadd_du (__m128i, __m128i);
18131__m128i __lsx_vsadd_h (__m128i, __m128i);
18132__m128i __lsx_vsadd_hu (__m128i, __m128i);
18133__m128i __lsx_vsadd_w (__m128i, __m128i);
18134__m128i __lsx_vsadd_wu (__m128i, __m128i);
18135__m128i __lsx_vsat_b (__m128i, imm0_7);
18136__m128i __lsx_vsat_bu (__m128i, imm0_7);
18137__m128i __lsx_vsat_d (__m128i, imm0_63);
18138__m128i __lsx_vsat_du (__m128i, imm0_63);
18139__m128i __lsx_vsat_h (__m128i, imm0_15);
18140__m128i __lsx_vsat_hu (__m128i, imm0_15);
18141__m128i __lsx_vsat_w (__m128i, imm0_31);
18142__m128i __lsx_vsat_wu (__m128i, imm0_31);
18143__m128i __lsx_vseq_b (__m128i, __m128i);
18144__m128i __lsx_vseq_d (__m128i, __m128i);
18145__m128i __lsx_vseq_h (__m128i, __m128i);
18146__m128i __lsx_vseqi_b (__m128i, imm_n16_15);
18147__m128i __lsx_vseqi_d (__m128i, imm_n16_15);
18148__m128i __lsx_vseqi_h (__m128i, imm_n16_15);
18149__m128i __lsx_vseqi_w (__m128i, imm_n16_15);
18150__m128i __lsx_vseq_w (__m128i, __m128i);
18151__m128i __lsx_vshuf4i_b (__m128i, imm0_255);
18152__m128i __lsx_vshuf4i_d (__m128i, __m128i, imm0_255);
18153__m128i __lsx_vshuf4i_h (__m128i, imm0_255);
18154__m128i __lsx_vshuf4i_w (__m128i, imm0_255);
18155__m128i __lsx_vshuf_b (__m128i, __m128i, __m128i);
18156__m128i __lsx_vshuf_d (__m128i, __m128i, __m128i);
18157__m128i __lsx_vshuf_h (__m128i, __m128i, __m128i);
18158__m128i __lsx_vshuf_w (__m128i, __m128i, __m128i);
18159__m128i __lsx_vsigncov_b (__m128i, __m128i);
18160__m128i __lsx_vsigncov_d (__m128i, __m128i);
18161__m128i __lsx_vsigncov_h (__m128i, __m128i);
18162__m128i __lsx_vsigncov_w (__m128i, __m128i);
1f48786d 18163__m128i __lsx_vsle_b (__m128i, __m128i);
18164__m128i __lsx_vsle_bu (__m128i, __m128i);
18165__m128i __lsx_vsle_d (__m128i, __m128i);
18166__m128i __lsx_vsle_du (__m128i, __m128i);
18167__m128i __lsx_vsle_h (__m128i, __m128i);
18168__m128i __lsx_vsle_hu (__m128i, __m128i);
18169__m128i __lsx_vslei_b (__m128i, imm_n16_15);
18170__m128i __lsx_vslei_bu (__m128i, imm0_31);
18171__m128i __lsx_vslei_d (__m128i, imm_n16_15);
18172__m128i __lsx_vslei_du (__m128i, imm0_31);
18173__m128i __lsx_vslei_h (__m128i, imm_n16_15);
18174__m128i __lsx_vslei_hu (__m128i, imm0_31);
18175__m128i __lsx_vslei_w (__m128i, imm_n16_15);
18176__m128i __lsx_vslei_wu (__m128i, imm0_31);
18177__m128i __lsx_vsle_w (__m128i, __m128i);
18178__m128i __lsx_vsle_wu (__m128i, __m128i);
18179__m128i __lsx_vsll_b (__m128i, __m128i);
18180__m128i __lsx_vsll_d (__m128i, __m128i);
18181__m128i __lsx_vsll_h (__m128i, __m128i);
18182__m128i __lsx_vslli_b (__m128i, imm0_7);
18183__m128i __lsx_vslli_d (__m128i, imm0_63);
18184__m128i __lsx_vslli_h (__m128i, imm0_15);
18185__m128i __lsx_vslli_w (__m128i, imm0_31);
18186__m128i __lsx_vsll_w (__m128i, __m128i);
18187__m128i __lsx_vsllwil_du_wu (__m128i, imm0_31);
18188__m128i __lsx_vsllwil_d_w (__m128i, imm0_31);
18189__m128i __lsx_vsllwil_h_b (__m128i, imm0_7);
18190__m128i __lsx_vsllwil_hu_bu (__m128i, imm0_7);
18191__m128i __lsx_vsllwil_w_h (__m128i, imm0_15);
18192__m128i __lsx_vsllwil_wu_hu (__m128i, imm0_15);
18193__m128i __lsx_vslt_b (__m128i, __m128i);
18194__m128i __lsx_vslt_bu (__m128i, __m128i);
18195__m128i __lsx_vslt_d (__m128i, __m128i);
18196__m128i __lsx_vslt_du (__m128i, __m128i);
18197__m128i __lsx_vslt_h (__m128i, __m128i);
18198__m128i __lsx_vslt_hu (__m128i, __m128i);
18199__m128i __lsx_vslti_b (__m128i, imm_n16_15);
18200__m128i __lsx_vslti_bu (__m128i, imm0_31);
18201__m128i __lsx_vslti_d (__m128i, imm_n16_15);
18202__m128i __lsx_vslti_du (__m128i, imm0_31);
18203__m128i __lsx_vslti_h (__m128i, imm_n16_15);
18204__m128i __lsx_vslti_hu (__m128i, imm0_31);
18205__m128i __lsx_vslti_w (__m128i, imm_n16_15);
18206__m128i __lsx_vslti_wu (__m128i, imm0_31);
18207__m128i __lsx_vslt_w (__m128i, __m128i);
18208__m128i __lsx_vslt_wu (__m128i, __m128i);
18209__m128i __lsx_vsra_b (__m128i, __m128i);
18210__m128i __lsx_vsra_d (__m128i, __m128i);
18211__m128i __lsx_vsra_h (__m128i, __m128i);
18212__m128i __lsx_vsrai_b (__m128i, imm0_7);
18213__m128i __lsx_vsrai_d (__m128i, imm0_63);
18214__m128i __lsx_vsrai_h (__m128i, imm0_15);
18215__m128i __lsx_vsrai_w (__m128i, imm0_31);
18216__m128i __lsx_vsran_b_h (__m128i, __m128i);
18217__m128i __lsx_vsran_h_w (__m128i, __m128i);
18218__m128i __lsx_vsrani_b_h (__m128i, __m128i, imm0_15);
84ad1b53 18219__m128i __lsx_vsrani_d_q (__m128i, __m128i, imm0_127);
1f48786d 18220__m128i __lsx_vsrani_h_w (__m128i, __m128i, imm0_31);
18221__m128i __lsx_vsrani_w_d (__m128i, __m128i, imm0_63);
18222__m128i __lsx_vsran_w_d (__m128i, __m128i);
18223__m128i __lsx_vsrar_b (__m128i, __m128i);
18224__m128i __lsx_vsrar_d (__m128i, __m128i);
18225__m128i __lsx_vsrar_h (__m128i, __m128i);
18226__m128i __lsx_vsrari_b (__m128i, imm0_7);
18227__m128i __lsx_vsrari_d (__m128i, imm0_63);
18228__m128i __lsx_vsrari_h (__m128i, imm0_15);
18229__m128i __lsx_vsrari_w (__m128i, imm0_31);
18230__m128i __lsx_vsrarn_b_h (__m128i, __m128i);
18231__m128i __lsx_vsrarn_h_w (__m128i, __m128i);
18232__m128i __lsx_vsrarni_b_h (__m128i, __m128i, imm0_15);
84ad1b53 18233__m128i __lsx_vsrarni_d_q (__m128i, __m128i, imm0_127);
1f48786d 18234__m128i __lsx_vsrarni_h_w (__m128i, __m128i, imm0_31);
18235__m128i __lsx_vsrarni_w_d (__m128i, __m128i, imm0_63);
18236__m128i __lsx_vsrarn_w_d (__m128i, __m128i);
18237__m128i __lsx_vsrar_w (__m128i, __m128i);
18238__m128i __lsx_vsra_w (__m128i, __m128i);
18239__m128i __lsx_vsrl_b (__m128i, __m128i);
18240__m128i __lsx_vsrl_d (__m128i, __m128i);
18241__m128i __lsx_vsrl_h (__m128i, __m128i);
18242__m128i __lsx_vsrli_b (__m128i, imm0_7);
18243__m128i __lsx_vsrli_d (__m128i, imm0_63);
18244__m128i __lsx_vsrli_h (__m128i, imm0_15);
18245__m128i __lsx_vsrli_w (__m128i, imm0_31);
18246__m128i __lsx_vsrln_b_h (__m128i, __m128i);
18247__m128i __lsx_vsrln_h_w (__m128i, __m128i);
18248__m128i __lsx_vsrlni_b_h (__m128i, __m128i, imm0_15);
84ad1b53 18249__m128i __lsx_vsrlni_d_q (__m128i, __m128i, imm0_127);
1f48786d 18250__m128i __lsx_vsrlni_h_w (__m128i, __m128i, imm0_31);
18251__m128i __lsx_vsrlni_w_d (__m128i, __m128i, imm0_63);
18252__m128i __lsx_vsrln_w_d (__m128i, __m128i);
18253__m128i __lsx_vsrlr_b (__m128i, __m128i);
18254__m128i __lsx_vsrlr_d (__m128i, __m128i);
18255__m128i __lsx_vsrlr_h (__m128i, __m128i);
18256__m128i __lsx_vsrlri_b (__m128i, imm0_7);
18257__m128i __lsx_vsrlri_d (__m128i, imm0_63);
18258__m128i __lsx_vsrlri_h (__m128i, imm0_15);
18259__m128i __lsx_vsrlri_w (__m128i, imm0_31);
18260__m128i __lsx_vsrlrn_b_h (__m128i, __m128i);
18261__m128i __lsx_vsrlrn_h_w (__m128i, __m128i);
18262__m128i __lsx_vsrlrni_b_h (__m128i, __m128i, imm0_15);
84ad1b53 18263__m128i __lsx_vsrlrni_d_q (__m128i, __m128i, imm0_127);
1f48786d 18264__m128i __lsx_vsrlrni_h_w (__m128i, __m128i, imm0_31);
18265__m128i __lsx_vsrlrni_w_d (__m128i, __m128i, imm0_63);
18266__m128i __lsx_vsrlrn_w_d (__m128i, __m128i);
18267__m128i __lsx_vsrlr_w (__m128i, __m128i);
18268__m128i __lsx_vsrl_w (__m128i, __m128i);
18269__m128i __lsx_vssran_b_h (__m128i, __m128i);
18270__m128i __lsx_vssran_bu_h (__m128i, __m128i);
18271__m128i __lsx_vssran_hu_w (__m128i, __m128i);
18272__m128i __lsx_vssran_h_w (__m128i, __m128i);
18273__m128i __lsx_vssrani_b_h (__m128i, __m128i, imm0_15);
18274__m128i __lsx_vssrani_bu_h (__m128i, __m128i, imm0_15);
84ad1b53
JC
18275__m128i __lsx_vssrani_d_q (__m128i, __m128i, imm0_127);
18276__m128i __lsx_vssrani_du_q (__m128i, __m128i, imm0_127);
1f48786d 18277__m128i __lsx_vssrani_hu_w (__m128i, __m128i, imm0_31);
18278__m128i __lsx_vssrani_h_w (__m128i, __m128i, imm0_31);
18279__m128i __lsx_vssrani_w_d (__m128i, __m128i, imm0_63);
18280__m128i __lsx_vssrani_wu_d (__m128i, __m128i, imm0_63);
18281__m128i __lsx_vssran_w_d (__m128i, __m128i);
18282__m128i __lsx_vssran_wu_d (__m128i, __m128i);
18283__m128i __lsx_vssrarn_b_h (__m128i, __m128i);
18284__m128i __lsx_vssrarn_bu_h (__m128i, __m128i);
18285__m128i __lsx_vssrarn_hu_w (__m128i, __m128i);
18286__m128i __lsx_vssrarn_h_w (__m128i, __m128i);
18287__m128i __lsx_vssrarni_b_h (__m128i, __m128i, imm0_15);
18288__m128i __lsx_vssrarni_bu_h (__m128i, __m128i, imm0_15);
84ad1b53
JC
18289__m128i __lsx_vssrarni_d_q (__m128i, __m128i, imm0_127);
18290__m128i __lsx_vssrarni_du_q (__m128i, __m128i, imm0_127);
1f48786d 18291__m128i __lsx_vssrarni_hu_w (__m128i, __m128i, imm0_31);
18292__m128i __lsx_vssrarni_h_w (__m128i, __m128i, imm0_31);
18293__m128i __lsx_vssrarni_w_d (__m128i, __m128i, imm0_63);
18294__m128i __lsx_vssrarni_wu_d (__m128i, __m128i, imm0_63);
18295__m128i __lsx_vssrarn_w_d (__m128i, __m128i);
18296__m128i __lsx_vssrarn_wu_d (__m128i, __m128i);
18297__m128i __lsx_vssrln_b_h (__m128i, __m128i);
18298__m128i __lsx_vssrln_bu_h (__m128i, __m128i);
18299__m128i __lsx_vssrln_hu_w (__m128i, __m128i);
18300__m128i __lsx_vssrln_h_w (__m128i, __m128i);
18301__m128i __lsx_vssrlni_b_h (__m128i, __m128i, imm0_15);
18302__m128i __lsx_vssrlni_bu_h (__m128i, __m128i, imm0_15);
84ad1b53
JC
18303__m128i __lsx_vssrlni_d_q (__m128i, __m128i, imm0_127);
18304__m128i __lsx_vssrlni_du_q (__m128i, __m128i, imm0_127);
1f48786d 18305__m128i __lsx_vssrlni_hu_w (__m128i, __m128i, imm0_31);
18306__m128i __lsx_vssrlni_h_w (__m128i, __m128i, imm0_31);
18307__m128i __lsx_vssrlni_w_d (__m128i, __m128i, imm0_63);
18308__m128i __lsx_vssrlni_wu_d (__m128i, __m128i, imm0_63);
18309__m128i __lsx_vssrln_w_d (__m128i, __m128i);
18310__m128i __lsx_vssrln_wu_d (__m128i, __m128i);
18311__m128i __lsx_vssrlrn_b_h (__m128i, __m128i);
18312__m128i __lsx_vssrlrn_bu_h (__m128i, __m128i);
18313__m128i __lsx_vssrlrn_hu_w (__m128i, __m128i);
18314__m128i __lsx_vssrlrn_h_w (__m128i, __m128i);
18315__m128i __lsx_vssrlrni_b_h (__m128i, __m128i, imm0_15);
18316__m128i __lsx_vssrlrni_bu_h (__m128i, __m128i, imm0_15);
84ad1b53
JC
18317__m128i __lsx_vssrlrni_d_q (__m128i, __m128i, imm0_127);
18318__m128i __lsx_vssrlrni_du_q (__m128i, __m128i, imm0_127);
1f48786d 18319__m128i __lsx_vssrlrni_hu_w (__m128i, __m128i, imm0_31);
18320__m128i __lsx_vssrlrni_h_w (__m128i, __m128i, imm0_31);
18321__m128i __lsx_vssrlrni_w_d (__m128i, __m128i, imm0_63);
18322__m128i __lsx_vssrlrni_wu_d (__m128i, __m128i, imm0_63);
18323__m128i __lsx_vssrlrn_w_d (__m128i, __m128i);
18324__m128i __lsx_vssrlrn_wu_d (__m128i, __m128i);
18325__m128i __lsx_vssub_b (__m128i, __m128i);
18326__m128i __lsx_vssub_bu (__m128i, __m128i);
18327__m128i __lsx_vssub_d (__m128i, __m128i);
18328__m128i __lsx_vssub_du (__m128i, __m128i);
18329__m128i __lsx_vssub_h (__m128i, __m128i);
18330__m128i __lsx_vssub_hu (__m128i, __m128i);
18331__m128i __lsx_vssub_w (__m128i, __m128i);
18332__m128i __lsx_vssub_wu (__m128i, __m128i);
84ad1b53
JC
18333void __lsx_vst (__m128i, void *, imm_n2048_2047);
18334void __lsx_vstelm_b (__m128i, void *, imm_n128_127, imm0_15);
18335void __lsx_vstelm_d (__m128i, void *, imm_n128_127, imm0_1);
18336void __lsx_vstelm_h (__m128i, void *, imm_n128_127, imm0_7);
18337void __lsx_vstelm_w (__m128i, void *, imm_n128_127, imm0_3);
18338void __lsx_vstx (__m128i, void *, long int);
1f48786d 18339__m128i __lsx_vsub_b (__m128i, __m128i);
18340__m128i __lsx_vsub_d (__m128i, __m128i);
18341__m128i __lsx_vsub_h (__m128i, __m128i);
18342__m128i __lsx_vsubi_bu (__m128i, imm0_31);
18343__m128i __lsx_vsubi_du (__m128i, imm0_31);
18344__m128i __lsx_vsubi_hu (__m128i, imm0_31);
18345__m128i __lsx_vsubi_wu (__m128i, imm0_31);
18346__m128i __lsx_vsub_q (__m128i, __m128i);
18347__m128i __lsx_vsub_w (__m128i, __m128i);
18348__m128i __lsx_vsubwev_d_w (__m128i, __m128i);
18349__m128i __lsx_vsubwev_d_wu (__m128i, __m128i);
18350__m128i __lsx_vsubwev_h_b (__m128i, __m128i);
18351__m128i __lsx_vsubwev_h_bu (__m128i, __m128i);
18352__m128i __lsx_vsubwev_q_d (__m128i, __m128i);
18353__m128i __lsx_vsubwev_q_du (__m128i, __m128i);
18354__m128i __lsx_vsubwev_w_h (__m128i, __m128i);
18355__m128i __lsx_vsubwev_w_hu (__m128i, __m128i);
18356__m128i __lsx_vsubwod_d_w (__m128i, __m128i);
18357__m128i __lsx_vsubwod_d_wu (__m128i, __m128i);
18358__m128i __lsx_vsubwod_h_b (__m128i, __m128i);
18359__m128i __lsx_vsubwod_h_bu (__m128i, __m128i);
18360__m128i __lsx_vsubwod_q_d (__m128i, __m128i);
18361__m128i __lsx_vsubwod_q_du (__m128i, __m128i);
18362__m128i __lsx_vsubwod_w_h (__m128i, __m128i);
18363__m128i __lsx_vsubwod_w_hu (__m128i, __m128i);
18364__m128i __lsx_vxori_b (__m128i, imm0_255);
18365__m128i __lsx_vxor_v (__m128i, __m128i);
18366@end smallexample
18367
61f1001f
JX
18368These instrisic functions are available by including @code{lsxintrin.h} and
18369using @option{-mfrecipe} and @option{-mlsx}.
18370@smallexample
18371__m128d __lsx_vfrecipe_d (__m128d);
18372__m128 __lsx_vfrecipe_s (__m128);
18373__m128d __lsx_vfrsqrte_d (__m128d);
18374__m128 __lsx_vfrsqrte_s (__m128);
18375@end smallexample
18376
1f48786d 18377@node LoongArch ASX Vector Intrinsics
18378@subsection LoongArch ASX Vector Intrinsics
18379
18380GCC provides intrinsics to access the LASX (Loongson Advanced SIMD Extension)
18381instructions. The interface is made available by including @code{<lasxintrin.h>}
18382and using @option{-mlasx}.
18383
18384The following vectors typedefs are included in @code{lasxintrin.h}:
18385
18386@itemize
18387@item @code{__m256i}, a 256-bit vector of fixed point;
18388@item @code{__m256}, a 256-bit vector of single precision floating point;
18389@item @code{__m256d}, a 256-bit vector of double precision floating point.
18390@end itemize
18391
18392Instructions and corresponding built-ins may have additional restrictions and/or
18393input/output values manipulated:
18394
18395@itemize
18396@item @code{imm0_1}, an integer literal in range 0 to 1.
18397@item @code{imm0_3}, an integer literal in range 0 to 3.
18398@item @code{imm0_7}, an integer literal in range 0 to 7.
18399@item @code{imm0_15}, an integer literal in range 0 to 15.
18400@item @code{imm0_31}, an integer literal in range 0 to 31.
18401@item @code{imm0_63}, an integer literal in range 0 to 63.
18402@item @code{imm0_127}, an integer literal in range 0 to 127.
18403@item @code{imm0_255}, an integer literal in range 0 to 255.
18404@item @code{imm_n16_15}, an integer literal in range -16 to 15.
18405@item @code{imm_n128_127}, an integer literal in range -128 to 127.
18406@item @code{imm_n256_255}, an integer literal in range -256 to 255.
18407@item @code{imm_n512_511}, an integer literal in range -512 to 511.
18408@item @code{imm_n1024_1023}, an integer literal in range -1024 to 1023.
18409@item @code{imm_n2048_2047}, an integer literal in range -2048 to 2047.
18410@end itemize
18411
18412For convenience, GCC defines functions @code{__lasx_xvrepli_@{b/h/w/d@}} and
18413@code{__lasx_b[n]z_@{v/b/h/w/d@}}, which are implemented as follows:
18414
18415@smallexample
18416a. @code{__lasx_xvrepli_@{b/h/w/d@}}: Implemented the case where the highest
18417 bit of @code{xvldi} instruction @code{i13} is 1.
18418
18419 i13[12] == 1'b0
18420 case i13[11:10] of :
18421 2'b00: __lasx_xvrepli_b (imm_n512_511)
18422 2'b01: __lasx_xvrepli_h (imm_n512_511)
18423 2'b10: __lasx_xvrepli_w (imm_n512_511)
18424 2'b11: __lasx_xvrepli_d (imm_n512_511)
18425
18426b. @code{__lasx_b[n]z_@{v/b/h/w/d@}}: Since the @code{xvseteqz} class directive
18427 cannot be used on its own, this function is defined.
18428
18429 __lasx_xbz_v => xvseteqz.v + bcnez
18430 __lasx_xbnz_v => xvsetnez.v + bcnez
18431 __lasx_xbz_b => xvsetanyeqz.b + bcnez
18432 __lasx_xbz_h => xvsetanyeqz.h + bcnez
18433 __lasx_xbz_w => xvsetanyeqz.w + bcnez
18434 __lasx_xbz_d => xvsetanyeqz.d + bcnez
18435 __lasx_xbnz_b => xvsetallnez.b + bcnez
18436 __lasx_xbnz_h => xvsetallnez.h + bcnez
18437 __lasx_xbnz_w => xvsetallnez.w + bcnez
18438 __lasx_xbnz_d => xvsetallnez.d + bcnez
18439@end smallexample
18440
18441@smallexample
18442eg:
18443 #include <lasxintrin.h>
18444
18445 extern __m256i @var{a};
18446
18447 void
18448 test (void)
18449 @{
18450 if (__lasx_xbz_v (@var{a}))
18451 printf ("1\n");
18452 else
18453 printf ("2\n");
18454 @}
18455@end smallexample
18456
18457@emph{Note:} For directives where the intent operand is also the source operand
18458(modifying only part of the bitfield of the intent register), the first parameter
18459in the builtin call function is used as the intent operand.
18460
18461@smallexample
18462eg:
18463 #include <lasxintrin.h>
18464 extern __m256i @var{dst};
18465 int @var{src};
18466
18467 void
18468 test (void)
18469 @{
18470 @var{dst} = __lasx_xvinsgr2vr_w (@var{dst}, @var{src}, 3);
18471 @}
18472@end smallexample
18473
18474
18475The intrinsics provided are listed below:
18476
18477@smallexample
18478__m256i __lasx_vext2xv_d_b (__m256i);
18479__m256i __lasx_vext2xv_d_h (__m256i);
18480__m256i __lasx_vext2xv_du_bu (__m256i);
18481__m256i __lasx_vext2xv_du_hu (__m256i);
18482__m256i __lasx_vext2xv_du_wu (__m256i);
18483__m256i __lasx_vext2xv_d_w (__m256i);
18484__m256i __lasx_vext2xv_h_b (__m256i);
18485__m256i __lasx_vext2xv_hu_bu (__m256i);
18486__m256i __lasx_vext2xv_w_b (__m256i);
18487__m256i __lasx_vext2xv_w_h (__m256i);
18488__m256i __lasx_vext2xv_wu_bu (__m256i);
18489__m256i __lasx_vext2xv_wu_hu (__m256i);
18490int __lasx_xbnz_b (__m256i);
18491int __lasx_xbnz_d (__m256i);
18492int __lasx_xbnz_h (__m256i);
18493int __lasx_xbnz_v (__m256i);
18494int __lasx_xbnz_w (__m256i);
18495int __lasx_xbz_b (__m256i);
18496int __lasx_xbz_d (__m256i);
18497int __lasx_xbz_h (__m256i);
18498int __lasx_xbz_v (__m256i);
18499int __lasx_xbz_w (__m256i);
18500__m256i __lasx_xvabsd_b (__m256i, __m256i);
18501__m256i __lasx_xvabsd_bu (__m256i, __m256i);
18502__m256i __lasx_xvabsd_d (__m256i, __m256i);
18503__m256i __lasx_xvabsd_du (__m256i, __m256i);
18504__m256i __lasx_xvabsd_h (__m256i, __m256i);
18505__m256i __lasx_xvabsd_hu (__m256i, __m256i);
18506__m256i __lasx_xvabsd_w (__m256i, __m256i);
18507__m256i __lasx_xvabsd_wu (__m256i, __m256i);
18508__m256i __lasx_xvadda_b (__m256i, __m256i);
18509__m256i __lasx_xvadda_d (__m256i, __m256i);
18510__m256i __lasx_xvadda_h (__m256i, __m256i);
18511__m256i __lasx_xvadda_w (__m256i, __m256i);
18512__m256i __lasx_xvadd_b (__m256i, __m256i);
18513__m256i __lasx_xvadd_d (__m256i, __m256i);
18514__m256i __lasx_xvadd_h (__m256i, __m256i);
18515__m256i __lasx_xvaddi_bu (__m256i, imm0_31);
18516__m256i __lasx_xvaddi_du (__m256i, imm0_31);
18517__m256i __lasx_xvaddi_hu (__m256i, imm0_31);
18518__m256i __lasx_xvaddi_wu (__m256i, imm0_31);
18519__m256i __lasx_xvadd_q (__m256i, __m256i);
18520__m256i __lasx_xvadd_w (__m256i, __m256i);
18521__m256i __lasx_xvaddwev_d_w (__m256i, __m256i);
18522__m256i __lasx_xvaddwev_d_wu (__m256i, __m256i);
18523__m256i __lasx_xvaddwev_d_wu_w (__m256i, __m256i);
18524__m256i __lasx_xvaddwev_h_b (__m256i, __m256i);
18525__m256i __lasx_xvaddwev_h_bu (__m256i, __m256i);
18526__m256i __lasx_xvaddwev_h_bu_b (__m256i, __m256i);
18527__m256i __lasx_xvaddwev_q_d (__m256i, __m256i);
18528__m256i __lasx_xvaddwev_q_du (__m256i, __m256i);
18529__m256i __lasx_xvaddwev_q_du_d (__m256i, __m256i);
18530__m256i __lasx_xvaddwev_w_h (__m256i, __m256i);
18531__m256i __lasx_xvaddwev_w_hu (__m256i, __m256i);
18532__m256i __lasx_xvaddwev_w_hu_h (__m256i, __m256i);
18533__m256i __lasx_xvaddwod_d_w (__m256i, __m256i);
18534__m256i __lasx_xvaddwod_d_wu (__m256i, __m256i);
18535__m256i __lasx_xvaddwod_d_wu_w (__m256i, __m256i);
18536__m256i __lasx_xvaddwod_h_b (__m256i, __m256i);
18537__m256i __lasx_xvaddwod_h_bu (__m256i, __m256i);
18538__m256i __lasx_xvaddwod_h_bu_b (__m256i, __m256i);
18539__m256i __lasx_xvaddwod_q_d (__m256i, __m256i);
18540__m256i __lasx_xvaddwod_q_du (__m256i, __m256i);
18541__m256i __lasx_xvaddwod_q_du_d (__m256i, __m256i);
18542__m256i __lasx_xvaddwod_w_h (__m256i, __m256i);
18543__m256i __lasx_xvaddwod_w_hu (__m256i, __m256i);
18544__m256i __lasx_xvaddwod_w_hu_h (__m256i, __m256i);
18545__m256i __lasx_xvandi_b (__m256i, imm0_255);
18546__m256i __lasx_xvandn_v (__m256i, __m256i);
18547__m256i __lasx_xvand_v (__m256i, __m256i);
18548__m256i __lasx_xvavg_b (__m256i, __m256i);
18549__m256i __lasx_xvavg_bu (__m256i, __m256i);
18550__m256i __lasx_xvavg_d (__m256i, __m256i);
18551__m256i __lasx_xvavg_du (__m256i, __m256i);
18552__m256i __lasx_xvavg_h (__m256i, __m256i);
18553__m256i __lasx_xvavg_hu (__m256i, __m256i);
18554__m256i __lasx_xvavgr_b (__m256i, __m256i);
18555__m256i __lasx_xvavgr_bu (__m256i, __m256i);
18556__m256i __lasx_xvavgr_d (__m256i, __m256i);
18557__m256i __lasx_xvavgr_du (__m256i, __m256i);
18558__m256i __lasx_xvavgr_h (__m256i, __m256i);
18559__m256i __lasx_xvavgr_hu (__m256i, __m256i);
18560__m256i __lasx_xvavgr_w (__m256i, __m256i);
18561__m256i __lasx_xvavgr_wu (__m256i, __m256i);
18562__m256i __lasx_xvavg_w (__m256i, __m256i);
18563__m256i __lasx_xvavg_wu (__m256i, __m256i);
18564__m256i __lasx_xvbitclr_b (__m256i, __m256i);
18565__m256i __lasx_xvbitclr_d (__m256i, __m256i);
18566__m256i __lasx_xvbitclr_h (__m256i, __m256i);
18567__m256i __lasx_xvbitclri_b (__m256i, imm0_7);
18568__m256i __lasx_xvbitclri_d (__m256i, imm0_63);
18569__m256i __lasx_xvbitclri_h (__m256i, imm0_15);
18570__m256i __lasx_xvbitclri_w (__m256i, imm0_31);
18571__m256i __lasx_xvbitclr_w (__m256i, __m256i);
18572__m256i __lasx_xvbitrev_b (__m256i, __m256i);
18573__m256i __lasx_xvbitrev_d (__m256i, __m256i);
18574__m256i __lasx_xvbitrev_h (__m256i, __m256i);
18575__m256i __lasx_xvbitrevi_b (__m256i, imm0_7);
18576__m256i __lasx_xvbitrevi_d (__m256i, imm0_63);
18577__m256i __lasx_xvbitrevi_h (__m256i, imm0_15);
18578__m256i __lasx_xvbitrevi_w (__m256i, imm0_31);
18579__m256i __lasx_xvbitrev_w (__m256i, __m256i);
18580__m256i __lasx_xvbitseli_b (__m256i, __m256i, imm0_255);
18581__m256i __lasx_xvbitsel_v (__m256i, __m256i, __m256i);
18582__m256i __lasx_xvbitset_b (__m256i, __m256i);
18583__m256i __lasx_xvbitset_d (__m256i, __m256i);
18584__m256i __lasx_xvbitset_h (__m256i, __m256i);
18585__m256i __lasx_xvbitseti_b (__m256i, imm0_7);
18586__m256i __lasx_xvbitseti_d (__m256i, imm0_63);
18587__m256i __lasx_xvbitseti_h (__m256i, imm0_15);
18588__m256i __lasx_xvbitseti_w (__m256i, imm0_31);
18589__m256i __lasx_xvbitset_w (__m256i, __m256i);
18590__m256i __lasx_xvbsll_v (__m256i, imm0_31);
18591__m256i __lasx_xvbsrl_v (__m256i, imm0_31);
18592__m256i __lasx_xvclo_b (__m256i);
18593__m256i __lasx_xvclo_d (__m256i);
18594__m256i __lasx_xvclo_h (__m256i);
18595__m256i __lasx_xvclo_w (__m256i);
18596__m256i __lasx_xvclz_b (__m256i);
18597__m256i __lasx_xvclz_d (__m256i);
18598__m256i __lasx_xvclz_h (__m256i);
18599__m256i __lasx_xvclz_w (__m256i);
18600__m256i __lasx_xvdiv_b (__m256i, __m256i);
18601__m256i __lasx_xvdiv_bu (__m256i, __m256i);
18602__m256i __lasx_xvdiv_d (__m256i, __m256i);
18603__m256i __lasx_xvdiv_du (__m256i, __m256i);
18604__m256i __lasx_xvdiv_h (__m256i, __m256i);
18605__m256i __lasx_xvdiv_hu (__m256i, __m256i);
18606__m256i __lasx_xvdiv_w (__m256i, __m256i);
18607__m256i __lasx_xvdiv_wu (__m256i, __m256i);
18608__m256i __lasx_xvexth_du_wu (__m256i);
18609__m256i __lasx_xvexth_d_w (__m256i);
18610__m256i __lasx_xvexth_h_b (__m256i);
18611__m256i __lasx_xvexth_hu_bu (__m256i);
18612__m256i __lasx_xvexth_q_d (__m256i);
18613__m256i __lasx_xvexth_qu_du (__m256i);
18614__m256i __lasx_xvexth_w_h (__m256i);
18615__m256i __lasx_xvexth_wu_hu (__m256i);
18616__m256i __lasx_xvextl_q_d (__m256i);
18617__m256i __lasx_xvextl_qu_du (__m256i);
18618__m256i __lasx_xvextrins_b (__m256i, __m256i, imm0_255);
18619__m256i __lasx_xvextrins_d (__m256i, __m256i, imm0_255);
18620__m256i __lasx_xvextrins_h (__m256i, __m256i, imm0_255);
18621__m256i __lasx_xvextrins_w (__m256i, __m256i, imm0_255);
18622__m256d __lasx_xvfadd_d (__m256d, __m256d);
18623__m256 __lasx_xvfadd_s (__m256, __m256);
18624__m256i __lasx_xvfclass_d (__m256d);
18625__m256i __lasx_xvfclass_s (__m256);
18626__m256i __lasx_xvfcmp_caf_d (__m256d, __m256d);
18627__m256i __lasx_xvfcmp_caf_s (__m256, __m256);
18628__m256i __lasx_xvfcmp_ceq_d (__m256d, __m256d);
18629__m256i __lasx_xvfcmp_ceq_s (__m256, __m256);
18630__m256i __lasx_xvfcmp_cle_d (__m256d, __m256d);
18631__m256i __lasx_xvfcmp_cle_s (__m256, __m256);
18632__m256i __lasx_xvfcmp_clt_d (__m256d, __m256d);
18633__m256i __lasx_xvfcmp_clt_s (__m256, __m256);
18634__m256i __lasx_xvfcmp_cne_d (__m256d, __m256d);
18635__m256i __lasx_xvfcmp_cne_s (__m256, __m256);
18636__m256i __lasx_xvfcmp_cor_d (__m256d, __m256d);
18637__m256i __lasx_xvfcmp_cor_s (__m256, __m256);
18638__m256i __lasx_xvfcmp_cueq_d (__m256d, __m256d);
18639__m256i __lasx_xvfcmp_cueq_s (__m256, __m256);
18640__m256i __lasx_xvfcmp_cule_d (__m256d, __m256d);
18641__m256i __lasx_xvfcmp_cule_s (__m256, __m256);
18642__m256i __lasx_xvfcmp_cult_d (__m256d, __m256d);
18643__m256i __lasx_xvfcmp_cult_s (__m256, __m256);
18644__m256i __lasx_xvfcmp_cun_d (__m256d, __m256d);
18645__m256i __lasx_xvfcmp_cune_d (__m256d, __m256d);
18646__m256i __lasx_xvfcmp_cune_s (__m256, __m256);
18647__m256i __lasx_xvfcmp_cun_s (__m256, __m256);
18648__m256i __lasx_xvfcmp_saf_d (__m256d, __m256d);
18649__m256i __lasx_xvfcmp_saf_s (__m256, __m256);
18650__m256i __lasx_xvfcmp_seq_d (__m256d, __m256d);
18651__m256i __lasx_xvfcmp_seq_s (__m256, __m256);
18652__m256i __lasx_xvfcmp_sle_d (__m256d, __m256d);
18653__m256i __lasx_xvfcmp_sle_s (__m256, __m256);
18654__m256i __lasx_xvfcmp_slt_d (__m256d, __m256d);
18655__m256i __lasx_xvfcmp_slt_s (__m256, __m256);
18656__m256i __lasx_xvfcmp_sne_d (__m256d, __m256d);
18657__m256i __lasx_xvfcmp_sne_s (__m256, __m256);
18658__m256i __lasx_xvfcmp_sor_d (__m256d, __m256d);
18659__m256i __lasx_xvfcmp_sor_s (__m256, __m256);
18660__m256i __lasx_xvfcmp_sueq_d (__m256d, __m256d);
18661__m256i __lasx_xvfcmp_sueq_s (__m256, __m256);
18662__m256i __lasx_xvfcmp_sule_d (__m256d, __m256d);
18663__m256i __lasx_xvfcmp_sule_s (__m256, __m256);
18664__m256i __lasx_xvfcmp_sult_d (__m256d, __m256d);
18665__m256i __lasx_xvfcmp_sult_s (__m256, __m256);
18666__m256i __lasx_xvfcmp_sun_d (__m256d, __m256d);
18667__m256i __lasx_xvfcmp_sune_d (__m256d, __m256d);
18668__m256i __lasx_xvfcmp_sune_s (__m256, __m256);
18669__m256i __lasx_xvfcmp_sun_s (__m256, __m256);
18670__m256d __lasx_xvfcvth_d_s (__m256);
18671__m256i __lasx_xvfcvt_h_s (__m256, __m256);
18672__m256 __lasx_xvfcvth_s_h (__m256i);
18673__m256d __lasx_xvfcvtl_d_s (__m256);
18674__m256 __lasx_xvfcvtl_s_h (__m256i);
18675__m256 __lasx_xvfcvt_s_d (__m256d, __m256d);
18676__m256d __lasx_xvfdiv_d (__m256d, __m256d);
18677__m256 __lasx_xvfdiv_s (__m256, __m256);
18678__m256d __lasx_xvffint_d_l (__m256i);
18679__m256d __lasx_xvffint_d_lu (__m256i);
18680__m256d __lasx_xvffinth_d_w (__m256i);
18681__m256d __lasx_xvffintl_d_w (__m256i);
18682__m256 __lasx_xvffint_s_l (__m256i, __m256i);
18683__m256 __lasx_xvffint_s_w (__m256i);
18684__m256 __lasx_xvffint_s_wu (__m256i);
18685__m256d __lasx_xvflogb_d (__m256d);
18686__m256 __lasx_xvflogb_s (__m256);
18687__m256d __lasx_xvfmadd_d (__m256d, __m256d, __m256d);
18688__m256 __lasx_xvfmadd_s (__m256, __m256, __m256);
18689__m256d __lasx_xvfmaxa_d (__m256d, __m256d);
18690__m256 __lasx_xvfmaxa_s (__m256, __m256);
18691__m256d __lasx_xvfmax_d (__m256d, __m256d);
18692__m256 __lasx_xvfmax_s (__m256, __m256);
18693__m256d __lasx_xvfmina_d (__m256d, __m256d);
18694__m256 __lasx_xvfmina_s (__m256, __m256);
18695__m256d __lasx_xvfmin_d (__m256d, __m256d);
18696__m256 __lasx_xvfmin_s (__m256, __m256);
18697__m256d __lasx_xvfmsub_d (__m256d, __m256d, __m256d);
18698__m256 __lasx_xvfmsub_s (__m256, __m256, __m256);
18699__m256d __lasx_xvfmul_d (__m256d, __m256d);
18700__m256 __lasx_xvfmul_s (__m256, __m256);
18701__m256d __lasx_xvfnmadd_d (__m256d, __m256d, __m256d);
18702__m256 __lasx_xvfnmadd_s (__m256, __m256, __m256);
18703__m256d __lasx_xvfnmsub_d (__m256d, __m256d, __m256d);
18704__m256 __lasx_xvfnmsub_s (__m256, __m256, __m256);
18705__m256d __lasx_xvfrecip_d (__m256d);
18706__m256 __lasx_xvfrecip_s (__m256);
18707__m256d __lasx_xvfrint_d (__m256d);
297ed1ac 18708__m256d __lasx_xvfrintrm_d (__m256d);
18709__m256 __lasx_xvfrintrm_s (__m256);
18710__m256d __lasx_xvfrintrne_d (__m256d);
18711__m256 __lasx_xvfrintrne_s (__m256);
18712__m256d __lasx_xvfrintrp_d (__m256d);
18713__m256 __lasx_xvfrintrp_s (__m256);
18714__m256d __lasx_xvfrintrz_d (__m256d);
18715__m256 __lasx_xvfrintrz_s (__m256);
1f48786d 18716__m256 __lasx_xvfrint_s (__m256);
18717__m256d __lasx_xvfrsqrt_d (__m256d);
18718__m256 __lasx_xvfrsqrt_s (__m256);
18719__m256i __lasx_xvfrstp_b (__m256i, __m256i, __m256i);
18720__m256i __lasx_xvfrstp_h (__m256i, __m256i, __m256i);
18721__m256i __lasx_xvfrstpi_b (__m256i, __m256i, imm0_31);
18722__m256i __lasx_xvfrstpi_h (__m256i, __m256i, imm0_31);
18723__m256d __lasx_xvfsqrt_d (__m256d);
18724__m256 __lasx_xvfsqrt_s (__m256);
18725__m256d __lasx_xvfsub_d (__m256d, __m256d);
18726__m256 __lasx_xvfsub_s (__m256, __m256);
18727__m256i __lasx_xvftinth_l_s (__m256);
18728__m256i __lasx_xvftint_l_d (__m256d);
18729__m256i __lasx_xvftintl_l_s (__m256);
18730__m256i __lasx_xvftint_lu_d (__m256d);
18731__m256i __lasx_xvftintrmh_l_s (__m256);
18732__m256i __lasx_xvftintrm_l_d (__m256d);
18733__m256i __lasx_xvftintrml_l_s (__m256);
18734__m256i __lasx_xvftintrm_w_d (__m256d, __m256d);
18735__m256i __lasx_xvftintrm_w_s (__m256);
18736__m256i __lasx_xvftintrneh_l_s (__m256);
18737__m256i __lasx_xvftintrne_l_d (__m256d);
18738__m256i __lasx_xvftintrnel_l_s (__m256);
18739__m256i __lasx_xvftintrne_w_d (__m256d, __m256d);
18740__m256i __lasx_xvftintrne_w_s (__m256);
18741__m256i __lasx_xvftintrph_l_s (__m256);
18742__m256i __lasx_xvftintrp_l_d (__m256d);
18743__m256i __lasx_xvftintrpl_l_s (__m256);
18744__m256i __lasx_xvftintrp_w_d (__m256d, __m256d);
18745__m256i __lasx_xvftintrp_w_s (__m256);
18746__m256i __lasx_xvftintrzh_l_s (__m256);
18747__m256i __lasx_xvftintrz_l_d (__m256d);
18748__m256i __lasx_xvftintrzl_l_s (__m256);
18749__m256i __lasx_xvftintrz_lu_d (__m256d);
18750__m256i __lasx_xvftintrz_w_d (__m256d, __m256d);
18751__m256i __lasx_xvftintrz_w_s (__m256);
18752__m256i __lasx_xvftintrz_wu_s (__m256);
18753__m256i __lasx_xvftint_w_d (__m256d, __m256d);
18754__m256i __lasx_xvftint_w_s (__m256);
18755__m256i __lasx_xvftint_wu_s (__m256);
18756__m256i __lasx_xvhaddw_du_wu (__m256i, __m256i);
18757__m256i __lasx_xvhaddw_d_w (__m256i, __m256i);
18758__m256i __lasx_xvhaddw_h_b (__m256i, __m256i);
18759__m256i __lasx_xvhaddw_hu_bu (__m256i, __m256i);
18760__m256i __lasx_xvhaddw_q_d (__m256i, __m256i);
18761__m256i __lasx_xvhaddw_qu_du (__m256i, __m256i);
18762__m256i __lasx_xvhaddw_w_h (__m256i, __m256i);
18763__m256i __lasx_xvhaddw_wu_hu (__m256i, __m256i);
18764__m256i __lasx_xvhsubw_du_wu (__m256i, __m256i);
18765__m256i __lasx_xvhsubw_d_w (__m256i, __m256i);
18766__m256i __lasx_xvhsubw_h_b (__m256i, __m256i);
18767__m256i __lasx_xvhsubw_hu_bu (__m256i, __m256i);
18768__m256i __lasx_xvhsubw_q_d (__m256i, __m256i);
18769__m256i __lasx_xvhsubw_qu_du (__m256i, __m256i);
18770__m256i __lasx_xvhsubw_w_h (__m256i, __m256i);
18771__m256i __lasx_xvhsubw_wu_hu (__m256i, __m256i);
18772__m256i __lasx_xvilvh_b (__m256i, __m256i);
18773__m256i __lasx_xvilvh_d (__m256i, __m256i);
18774__m256i __lasx_xvilvh_h (__m256i, __m256i);
18775__m256i __lasx_xvilvh_w (__m256i, __m256i);
18776__m256i __lasx_xvilvl_b (__m256i, __m256i);
18777__m256i __lasx_xvilvl_d (__m256i, __m256i);
18778__m256i __lasx_xvilvl_h (__m256i, __m256i);
18779__m256i __lasx_xvilvl_w (__m256i, __m256i);
18780__m256i __lasx_xvinsgr2vr_d (__m256i, long int, imm0_3);
18781__m256i __lasx_xvinsgr2vr_w (__m256i, int, imm0_7);
18782__m256i __lasx_xvinsve0_d (__m256i, __m256i, imm0_3);
18783__m256i __lasx_xvinsve0_w (__m256i, __m256i, imm0_7);
18784__m256i __lasx_xvld (void *, imm_n2048_2047);
18785__m256i __lasx_xvldi (imm_n1024_1023);
18786__m256i __lasx_xvldrepl_b (void *, imm_n2048_2047);
18787__m256i __lasx_xvldrepl_d (void *, imm_n256_255);
18788__m256i __lasx_xvldrepl_h (void *, imm_n1024_1023);
18789__m256i __lasx_xvldrepl_w (void *, imm_n512_511);
18790__m256i __lasx_xvldx (void *, long int);
18791__m256i __lasx_xvmadd_b (__m256i, __m256i, __m256i);
18792__m256i __lasx_xvmadd_d (__m256i, __m256i, __m256i);
18793__m256i __lasx_xvmadd_h (__m256i, __m256i, __m256i);
18794__m256i __lasx_xvmadd_w (__m256i, __m256i, __m256i);
18795__m256i __lasx_xvmaddwev_d_w (__m256i, __m256i, __m256i);
18796__m256i __lasx_xvmaddwev_d_wu (__m256i, __m256i, __m256i);
18797__m256i __lasx_xvmaddwev_d_wu_w (__m256i, __m256i, __m256i);
18798__m256i __lasx_xvmaddwev_h_b (__m256i, __m256i, __m256i);
18799__m256i __lasx_xvmaddwev_h_bu (__m256i, __m256i, __m256i);
18800__m256i __lasx_xvmaddwev_h_bu_b (__m256i, __m256i, __m256i);
18801__m256i __lasx_xvmaddwev_q_d (__m256i, __m256i, __m256i);
18802__m256i __lasx_xvmaddwev_q_du (__m256i, __m256i, __m256i);
18803__m256i __lasx_xvmaddwev_q_du_d (__m256i, __m256i, __m256i);
18804__m256i __lasx_xvmaddwev_w_h (__m256i, __m256i, __m256i);
18805__m256i __lasx_xvmaddwev_w_hu (__m256i, __m256i, __m256i);
18806__m256i __lasx_xvmaddwev_w_hu_h (__m256i, __m256i, __m256i);
18807__m256i __lasx_xvmaddwod_d_w (__m256i, __m256i, __m256i);
18808__m256i __lasx_xvmaddwod_d_wu (__m256i, __m256i, __m256i);
18809__m256i __lasx_xvmaddwod_d_wu_w (__m256i, __m256i, __m256i);
18810__m256i __lasx_xvmaddwod_h_b (__m256i, __m256i, __m256i);
18811__m256i __lasx_xvmaddwod_h_bu (__m256i, __m256i, __m256i);
18812__m256i __lasx_xvmaddwod_h_bu_b (__m256i, __m256i, __m256i);
18813__m256i __lasx_xvmaddwod_q_d (__m256i, __m256i, __m256i);
18814__m256i __lasx_xvmaddwod_q_du (__m256i, __m256i, __m256i);
18815__m256i __lasx_xvmaddwod_q_du_d (__m256i, __m256i, __m256i);
18816__m256i __lasx_xvmaddwod_w_h (__m256i, __m256i, __m256i);
18817__m256i __lasx_xvmaddwod_w_hu (__m256i, __m256i, __m256i);
18818__m256i __lasx_xvmaddwod_w_hu_h (__m256i, __m256i, __m256i);
18819__m256i __lasx_xvmax_b (__m256i, __m256i);
18820__m256i __lasx_xvmax_bu (__m256i, __m256i);
18821__m256i __lasx_xvmax_d (__m256i, __m256i);
18822__m256i __lasx_xvmax_du (__m256i, __m256i);
18823__m256i __lasx_xvmax_h (__m256i, __m256i);
18824__m256i __lasx_xvmax_hu (__m256i, __m256i);
18825__m256i __lasx_xvmaxi_b (__m256i, imm_n16_15);
18826__m256i __lasx_xvmaxi_bu (__m256i, imm0_31);
18827__m256i __lasx_xvmaxi_d (__m256i, imm_n16_15);
18828__m256i __lasx_xvmaxi_du (__m256i, imm0_31);
18829__m256i __lasx_xvmaxi_h (__m256i, imm_n16_15);
18830__m256i __lasx_xvmaxi_hu (__m256i, imm0_31);
18831__m256i __lasx_xvmaxi_w (__m256i, imm_n16_15);
18832__m256i __lasx_xvmaxi_wu (__m256i, imm0_31);
18833__m256i __lasx_xvmax_w (__m256i, __m256i);
18834__m256i __lasx_xvmax_wu (__m256i, __m256i);
18835__m256i __lasx_xvmin_b (__m256i, __m256i);
18836__m256i __lasx_xvmin_bu (__m256i, __m256i);
18837__m256i __lasx_xvmin_d (__m256i, __m256i);
18838__m256i __lasx_xvmin_du (__m256i, __m256i);
18839__m256i __lasx_xvmin_h (__m256i, __m256i);
18840__m256i __lasx_xvmin_hu (__m256i, __m256i);
18841__m256i __lasx_xvmini_b (__m256i, imm_n16_15);
18842__m256i __lasx_xvmini_bu (__m256i, imm0_31);
18843__m256i __lasx_xvmini_d (__m256i, imm_n16_15);
18844__m256i __lasx_xvmini_du (__m256i, imm0_31);
18845__m256i __lasx_xvmini_h (__m256i, imm_n16_15);
18846__m256i __lasx_xvmini_hu (__m256i, imm0_31);
18847__m256i __lasx_xvmini_w (__m256i, imm_n16_15);
18848__m256i __lasx_xvmini_wu (__m256i, imm0_31);
18849__m256i __lasx_xvmin_w (__m256i, __m256i);
18850__m256i __lasx_xvmin_wu (__m256i, __m256i);
18851__m256i __lasx_xvmod_b (__m256i, __m256i);
18852__m256i __lasx_xvmod_bu (__m256i, __m256i);
18853__m256i __lasx_xvmod_d (__m256i, __m256i);
18854__m256i __lasx_xvmod_du (__m256i, __m256i);
18855__m256i __lasx_xvmod_h (__m256i, __m256i);
18856__m256i __lasx_xvmod_hu (__m256i, __m256i);
18857__m256i __lasx_xvmod_w (__m256i, __m256i);
18858__m256i __lasx_xvmod_wu (__m256i, __m256i);
18859__m256i __lasx_xvmskgez_b (__m256i);
18860__m256i __lasx_xvmskltz_b (__m256i);
18861__m256i __lasx_xvmskltz_d (__m256i);
18862__m256i __lasx_xvmskltz_h (__m256i);
18863__m256i __lasx_xvmskltz_w (__m256i);
18864__m256i __lasx_xvmsknz_b (__m256i);
18865__m256i __lasx_xvmsub_b (__m256i, __m256i, __m256i);
18866__m256i __lasx_xvmsub_d (__m256i, __m256i, __m256i);
18867__m256i __lasx_xvmsub_h (__m256i, __m256i, __m256i);
18868__m256i __lasx_xvmsub_w (__m256i, __m256i, __m256i);
18869__m256i __lasx_xvmuh_b (__m256i, __m256i);
18870__m256i __lasx_xvmuh_bu (__m256i, __m256i);
18871__m256i __lasx_xvmuh_d (__m256i, __m256i);
18872__m256i __lasx_xvmuh_du (__m256i, __m256i);
18873__m256i __lasx_xvmuh_h (__m256i, __m256i);
18874__m256i __lasx_xvmuh_hu (__m256i, __m256i);
18875__m256i __lasx_xvmuh_w (__m256i, __m256i);
18876__m256i __lasx_xvmuh_wu (__m256i, __m256i);
18877__m256i __lasx_xvmul_b (__m256i, __m256i);
18878__m256i __lasx_xvmul_d (__m256i, __m256i);
18879__m256i __lasx_xvmul_h (__m256i, __m256i);
18880__m256i __lasx_xvmul_w (__m256i, __m256i);
18881__m256i __lasx_xvmulwev_d_w (__m256i, __m256i);
18882__m256i __lasx_xvmulwev_d_wu (__m256i, __m256i);
18883__m256i __lasx_xvmulwev_d_wu_w (__m256i, __m256i);
18884__m256i __lasx_xvmulwev_h_b (__m256i, __m256i);
18885__m256i __lasx_xvmulwev_h_bu (__m256i, __m256i);
18886__m256i __lasx_xvmulwev_h_bu_b (__m256i, __m256i);
18887__m256i __lasx_xvmulwev_q_d (__m256i, __m256i);
18888__m256i __lasx_xvmulwev_q_du (__m256i, __m256i);
18889__m256i __lasx_xvmulwev_q_du_d (__m256i, __m256i);
18890__m256i __lasx_xvmulwev_w_h (__m256i, __m256i);
18891__m256i __lasx_xvmulwev_w_hu (__m256i, __m256i);
18892__m256i __lasx_xvmulwev_w_hu_h (__m256i, __m256i);
18893__m256i __lasx_xvmulwod_d_w (__m256i, __m256i);
18894__m256i __lasx_xvmulwod_d_wu (__m256i, __m256i);
18895__m256i __lasx_xvmulwod_d_wu_w (__m256i, __m256i);
18896__m256i __lasx_xvmulwod_h_b (__m256i, __m256i);
18897__m256i __lasx_xvmulwod_h_bu (__m256i, __m256i);
18898__m256i __lasx_xvmulwod_h_bu_b (__m256i, __m256i);
18899__m256i __lasx_xvmulwod_q_d (__m256i, __m256i);
18900__m256i __lasx_xvmulwod_q_du (__m256i, __m256i);
18901__m256i __lasx_xvmulwod_q_du_d (__m256i, __m256i);
18902__m256i __lasx_xvmulwod_w_h (__m256i, __m256i);
18903__m256i __lasx_xvmulwod_w_hu (__m256i, __m256i);
18904__m256i __lasx_xvmulwod_w_hu_h (__m256i, __m256i);
18905__m256i __lasx_xvneg_b (__m256i);
18906__m256i __lasx_xvneg_d (__m256i);
18907__m256i __lasx_xvneg_h (__m256i);
18908__m256i __lasx_xvneg_w (__m256i);
18909__m256i __lasx_xvnori_b (__m256i, imm0_255);
18910__m256i __lasx_xvnor_v (__m256i, __m256i);
18911__m256i __lasx_xvori_b (__m256i, imm0_255);
18912__m256i __lasx_xvorn_v (__m256i, __m256i);
18913__m256i __lasx_xvor_v (__m256i, __m256i);
18914__m256i __lasx_xvpackev_b (__m256i, __m256i);
18915__m256i __lasx_xvpackev_d (__m256i, __m256i);
18916__m256i __lasx_xvpackev_h (__m256i, __m256i);
18917__m256i __lasx_xvpackev_w (__m256i, __m256i);
18918__m256i __lasx_xvpackod_b (__m256i, __m256i);
18919__m256i __lasx_xvpackod_d (__m256i, __m256i);
18920__m256i __lasx_xvpackod_h (__m256i, __m256i);
18921__m256i __lasx_xvpackod_w (__m256i, __m256i);
18922__m256i __lasx_xvpcnt_b (__m256i);
18923__m256i __lasx_xvpcnt_d (__m256i);
18924__m256i __lasx_xvpcnt_h (__m256i);
18925__m256i __lasx_xvpcnt_w (__m256i);
18926__m256i __lasx_xvpermi_d (__m256i, imm0_255);
18927__m256i __lasx_xvpermi_q (__m256i, __m256i, imm0_255);
18928__m256i __lasx_xvpermi_w (__m256i, __m256i, imm0_255);
18929__m256i __lasx_xvperm_w (__m256i, __m256i);
18930__m256i __lasx_xvpickev_b (__m256i, __m256i);
18931__m256i __lasx_xvpickev_d (__m256i, __m256i);
18932__m256i __lasx_xvpickev_h (__m256i, __m256i);
18933__m256i __lasx_xvpickev_w (__m256i, __m256i);
18934__m256i __lasx_xvpickod_b (__m256i, __m256i);
18935__m256i __lasx_xvpickod_d (__m256i, __m256i);
18936__m256i __lasx_xvpickod_h (__m256i, __m256i);
18937__m256i __lasx_xvpickod_w (__m256i, __m256i);
18938long int __lasx_xvpickve2gr_d (__m256i, imm0_3);
18939unsigned long int __lasx_xvpickve2gr_du (__m256i, imm0_3);
18940int __lasx_xvpickve2gr_w (__m256i, imm0_7);
18941unsigned int __lasx_xvpickve2gr_wu (__m256i, imm0_7);
18942__m256i __lasx_xvpickve_d (__m256i, imm0_3);
18943__m256d __lasx_xvpickve_d_f (__m256d, imm0_3);
18944__m256i __lasx_xvpickve_w (__m256i, imm0_7);
18945__m256 __lasx_xvpickve_w_f (__m256, imm0_7);
18946__m256i __lasx_xvrepl128vei_b (__m256i, imm0_15);
18947__m256i __lasx_xvrepl128vei_d (__m256i, imm0_1);
18948__m256i __lasx_xvrepl128vei_h (__m256i, imm0_7);
18949__m256i __lasx_xvrepl128vei_w (__m256i, imm0_3);
18950__m256i __lasx_xvreplgr2vr_b (int);
18951__m256i __lasx_xvreplgr2vr_d (long int);
18952__m256i __lasx_xvreplgr2vr_h (int);
18953__m256i __lasx_xvreplgr2vr_w (int);
18954__m256i __lasx_xvrepli_b (imm_n512_511);
18955__m256i __lasx_xvrepli_d (imm_n512_511);
18956__m256i __lasx_xvrepli_h (imm_n512_511);
18957__m256i __lasx_xvrepli_w (imm_n512_511);
18958__m256i __lasx_xvreplve0_b (__m256i);
18959__m256i __lasx_xvreplve0_d (__m256i);
18960__m256i __lasx_xvreplve0_h (__m256i);
18961__m256i __lasx_xvreplve0_q (__m256i);
18962__m256i __lasx_xvreplve0_w (__m256i);
18963__m256i __lasx_xvreplve_b (__m256i, int);
18964__m256i __lasx_xvreplve_d (__m256i, int);
18965__m256i __lasx_xvreplve_h (__m256i, int);
18966__m256i __lasx_xvreplve_w (__m256i, int);
18967__m256i __lasx_xvrotr_b (__m256i, __m256i);
18968__m256i __lasx_xvrotr_d (__m256i, __m256i);
18969__m256i __lasx_xvrotr_h (__m256i, __m256i);
18970__m256i __lasx_xvrotri_b (__m256i, imm0_7);
18971__m256i __lasx_xvrotri_d (__m256i, imm0_63);
18972__m256i __lasx_xvrotri_h (__m256i, imm0_15);
18973__m256i __lasx_xvrotri_w (__m256i, imm0_31);
18974__m256i __lasx_xvrotr_w (__m256i, __m256i);
18975__m256i __lasx_xvsadd_b (__m256i, __m256i);
18976__m256i __lasx_xvsadd_bu (__m256i, __m256i);
18977__m256i __lasx_xvsadd_d (__m256i, __m256i);
18978__m256i __lasx_xvsadd_du (__m256i, __m256i);
18979__m256i __lasx_xvsadd_h (__m256i, __m256i);
18980__m256i __lasx_xvsadd_hu (__m256i, __m256i);
18981__m256i __lasx_xvsadd_w (__m256i, __m256i);
18982__m256i __lasx_xvsadd_wu (__m256i, __m256i);
18983__m256i __lasx_xvsat_b (__m256i, imm0_7);
18984__m256i __lasx_xvsat_bu (__m256i, imm0_7);
18985__m256i __lasx_xvsat_d (__m256i, imm0_63);
18986__m256i __lasx_xvsat_du (__m256i, imm0_63);
18987__m256i __lasx_xvsat_h (__m256i, imm0_15);
18988__m256i __lasx_xvsat_hu (__m256i, imm0_15);
18989__m256i __lasx_xvsat_w (__m256i, imm0_31);
18990__m256i __lasx_xvsat_wu (__m256i, imm0_31);
18991__m256i __lasx_xvseq_b (__m256i, __m256i);
18992__m256i __lasx_xvseq_d (__m256i, __m256i);
18993__m256i __lasx_xvseq_h (__m256i, __m256i);
18994__m256i __lasx_xvseqi_b (__m256i, imm_n16_15);
18995__m256i __lasx_xvseqi_d (__m256i, imm_n16_15);
18996__m256i __lasx_xvseqi_h (__m256i, imm_n16_15);
18997__m256i __lasx_xvseqi_w (__m256i, imm_n16_15);
18998__m256i __lasx_xvseq_w (__m256i, __m256i);
18999__m256i __lasx_xvshuf4i_b (__m256i, imm0_255);
19000__m256i __lasx_xvshuf4i_d (__m256i, __m256i, imm0_255);
19001__m256i __lasx_xvshuf4i_h (__m256i, imm0_255);
19002__m256i __lasx_xvshuf4i_w (__m256i, imm0_255);
19003__m256i __lasx_xvshuf_b (__m256i, __m256i, __m256i);
19004__m256i __lasx_xvshuf_d (__m256i, __m256i, __m256i);
19005__m256i __lasx_xvshuf_h (__m256i, __m256i, __m256i);
19006__m256i __lasx_xvshuf_w (__m256i, __m256i, __m256i);
19007__m256i __lasx_xvsigncov_b (__m256i, __m256i);
19008__m256i __lasx_xvsigncov_d (__m256i, __m256i);
19009__m256i __lasx_xvsigncov_h (__m256i, __m256i);
19010__m256i __lasx_xvsigncov_w (__m256i, __m256i);
19011__m256i __lasx_xvsle_b (__m256i, __m256i);
19012__m256i __lasx_xvsle_bu (__m256i, __m256i);
19013__m256i __lasx_xvsle_d (__m256i, __m256i);
19014__m256i __lasx_xvsle_du (__m256i, __m256i);
19015__m256i __lasx_xvsle_h (__m256i, __m256i);
19016__m256i __lasx_xvsle_hu (__m256i, __m256i);
19017__m256i __lasx_xvslei_b (__m256i, imm_n16_15);
19018__m256i __lasx_xvslei_bu (__m256i, imm0_31);
19019__m256i __lasx_xvslei_d (__m256i, imm_n16_15);
19020__m256i __lasx_xvslei_du (__m256i, imm0_31);
19021__m256i __lasx_xvslei_h (__m256i, imm_n16_15);
19022__m256i __lasx_xvslei_hu (__m256i, imm0_31);
19023__m256i __lasx_xvslei_w (__m256i, imm_n16_15);
19024__m256i __lasx_xvslei_wu (__m256i, imm0_31);
19025__m256i __lasx_xvsle_w (__m256i, __m256i);
19026__m256i __lasx_xvsle_wu (__m256i, __m256i);
19027__m256i __lasx_xvsll_b (__m256i, __m256i);
19028__m256i __lasx_xvsll_d (__m256i, __m256i);
19029__m256i __lasx_xvsll_h (__m256i, __m256i);
19030__m256i __lasx_xvslli_b (__m256i, imm0_7);
19031__m256i __lasx_xvslli_d (__m256i, imm0_63);
19032__m256i __lasx_xvslli_h (__m256i, imm0_15);
19033__m256i __lasx_xvslli_w (__m256i, imm0_31);
19034__m256i __lasx_xvsll_w (__m256i, __m256i);
19035__m256i __lasx_xvsllwil_du_wu (__m256i, imm0_31);
19036__m256i __lasx_xvsllwil_d_w (__m256i, imm0_31);
19037__m256i __lasx_xvsllwil_h_b (__m256i, imm0_7);
19038__m256i __lasx_xvsllwil_hu_bu (__m256i, imm0_7);
19039__m256i __lasx_xvsllwil_w_h (__m256i, imm0_15);
19040__m256i __lasx_xvsllwil_wu_hu (__m256i, imm0_15);
19041__m256i __lasx_xvslt_b (__m256i, __m256i);
19042__m256i __lasx_xvslt_bu (__m256i, __m256i);
19043__m256i __lasx_xvslt_d (__m256i, __m256i);
19044__m256i __lasx_xvslt_du (__m256i, __m256i);
19045__m256i __lasx_xvslt_h (__m256i, __m256i);
19046__m256i __lasx_xvslt_hu (__m256i, __m256i);
19047__m256i __lasx_xvslti_b (__m256i, imm_n16_15);
19048__m256i __lasx_xvslti_bu (__m256i, imm0_31);
19049__m256i __lasx_xvslti_d (__m256i, imm_n16_15);
19050__m256i __lasx_xvslti_du (__m256i, imm0_31);
19051__m256i __lasx_xvslti_h (__m256i, imm_n16_15);
19052__m256i __lasx_xvslti_hu (__m256i, imm0_31);
19053__m256i __lasx_xvslti_w (__m256i, imm_n16_15);
19054__m256i __lasx_xvslti_wu (__m256i, imm0_31);
19055__m256i __lasx_xvslt_w (__m256i, __m256i);
19056__m256i __lasx_xvslt_wu (__m256i, __m256i);
19057__m256i __lasx_xvsra_b (__m256i, __m256i);
19058__m256i __lasx_xvsra_d (__m256i, __m256i);
19059__m256i __lasx_xvsra_h (__m256i, __m256i);
19060__m256i __lasx_xvsrai_b (__m256i, imm0_7);
19061__m256i __lasx_xvsrai_d (__m256i, imm0_63);
19062__m256i __lasx_xvsrai_h (__m256i, imm0_15);
19063__m256i __lasx_xvsrai_w (__m256i, imm0_31);
19064__m256i __lasx_xvsran_b_h (__m256i, __m256i);
19065__m256i __lasx_xvsran_h_w (__m256i, __m256i);
19066__m256i __lasx_xvsrani_b_h (__m256i, __m256i, imm0_15);
19067__m256i __lasx_xvsrani_d_q (__m256i, __m256i, imm0_127);
19068__m256i __lasx_xvsrani_h_w (__m256i, __m256i, imm0_31);
19069__m256i __lasx_xvsrani_w_d (__m256i, __m256i, imm0_63);
19070__m256i __lasx_xvsran_w_d (__m256i, __m256i);
19071__m256i __lasx_xvsrar_b (__m256i, __m256i);
19072__m256i __lasx_xvsrar_d (__m256i, __m256i);
19073__m256i __lasx_xvsrar_h (__m256i, __m256i);
19074__m256i __lasx_xvsrari_b (__m256i, imm0_7);
19075__m256i __lasx_xvsrari_d (__m256i, imm0_63);
19076__m256i __lasx_xvsrari_h (__m256i, imm0_15);
19077__m256i __lasx_xvsrari_w (__m256i, imm0_31);
19078__m256i __lasx_xvsrarn_b_h (__m256i, __m256i);
19079__m256i __lasx_xvsrarn_h_w (__m256i, __m256i);
19080__m256i __lasx_xvsrarni_b_h (__m256i, __m256i, imm0_15);
19081__m256i __lasx_xvsrarni_d_q (__m256i, __m256i, imm0_127);
19082__m256i __lasx_xvsrarni_h_w (__m256i, __m256i, imm0_31);
19083__m256i __lasx_xvsrarni_w_d (__m256i, __m256i, imm0_63);
19084__m256i __lasx_xvsrarn_w_d (__m256i, __m256i);
19085__m256i __lasx_xvsrar_w (__m256i, __m256i);
19086__m256i __lasx_xvsra_w (__m256i, __m256i);
19087__m256i __lasx_xvsrl_b (__m256i, __m256i);
19088__m256i __lasx_xvsrl_d (__m256i, __m256i);
19089__m256i __lasx_xvsrl_h (__m256i, __m256i);
19090__m256i __lasx_xvsrli_b (__m256i, imm0_7);
19091__m256i __lasx_xvsrli_d (__m256i, imm0_63);
19092__m256i __lasx_xvsrli_h (__m256i, imm0_15);
19093__m256i __lasx_xvsrli_w (__m256i, imm0_31);
19094__m256i __lasx_xvsrln_b_h (__m256i, __m256i);
19095__m256i __lasx_xvsrln_h_w (__m256i, __m256i);
19096__m256i __lasx_xvsrlni_b_h (__m256i, __m256i, imm0_15);
19097__m256i __lasx_xvsrlni_d_q (__m256i, __m256i, imm0_127);
19098__m256i __lasx_xvsrlni_h_w (__m256i, __m256i, imm0_31);
19099__m256i __lasx_xvsrlni_w_d (__m256i, __m256i, imm0_63);
19100__m256i __lasx_xvsrln_w_d (__m256i, __m256i);
19101__m256i __lasx_xvsrlr_b (__m256i, __m256i);
19102__m256i __lasx_xvsrlr_d (__m256i, __m256i);
19103__m256i __lasx_xvsrlr_h (__m256i, __m256i);
19104__m256i __lasx_xvsrlri_b (__m256i, imm0_7);
19105__m256i __lasx_xvsrlri_d (__m256i, imm0_63);
19106__m256i __lasx_xvsrlri_h (__m256i, imm0_15);
19107__m256i __lasx_xvsrlri_w (__m256i, imm0_31);
19108__m256i __lasx_xvsrlrn_b_h (__m256i, __m256i);
19109__m256i __lasx_xvsrlrn_h_w (__m256i, __m256i);
19110__m256i __lasx_xvsrlrni_b_h (__m256i, __m256i, imm0_15);
19111__m256i __lasx_xvsrlrni_d_q (__m256i, __m256i, imm0_127);
19112__m256i __lasx_xvsrlrni_h_w (__m256i, __m256i, imm0_31);
19113__m256i __lasx_xvsrlrni_w_d (__m256i, __m256i, imm0_63);
19114__m256i __lasx_xvsrlrn_w_d (__m256i, __m256i);
19115__m256i __lasx_xvsrlr_w (__m256i, __m256i);
19116__m256i __lasx_xvsrl_w (__m256i, __m256i);
19117__m256i __lasx_xvssran_b_h (__m256i, __m256i);
19118__m256i __lasx_xvssran_bu_h (__m256i, __m256i);
19119__m256i __lasx_xvssran_hu_w (__m256i, __m256i);
19120__m256i __lasx_xvssran_h_w (__m256i, __m256i);
19121__m256i __lasx_xvssrani_b_h (__m256i, __m256i, imm0_15);
19122__m256i __lasx_xvssrani_bu_h (__m256i, __m256i, imm0_15);
19123__m256i __lasx_xvssrani_d_q (__m256i, __m256i, imm0_127);
19124__m256i __lasx_xvssrani_du_q (__m256i, __m256i, imm0_127);
19125__m256i __lasx_xvssrani_hu_w (__m256i, __m256i, imm0_31);
19126__m256i __lasx_xvssrani_h_w (__m256i, __m256i, imm0_31);
19127__m256i __lasx_xvssrani_w_d (__m256i, __m256i, imm0_63);
19128__m256i __lasx_xvssrani_wu_d (__m256i, __m256i, imm0_63);
19129__m256i __lasx_xvssran_w_d (__m256i, __m256i);
19130__m256i __lasx_xvssran_wu_d (__m256i, __m256i);
19131__m256i __lasx_xvssrarn_b_h (__m256i, __m256i);
19132__m256i __lasx_xvssrarn_bu_h (__m256i, __m256i);
19133__m256i __lasx_xvssrarn_hu_w (__m256i, __m256i);
19134__m256i __lasx_xvssrarn_h_w (__m256i, __m256i);
19135__m256i __lasx_xvssrarni_b_h (__m256i, __m256i, imm0_15);
19136__m256i __lasx_xvssrarni_bu_h (__m256i, __m256i, imm0_15);
19137__m256i __lasx_xvssrarni_d_q (__m256i, __m256i, imm0_127);
19138__m256i __lasx_xvssrarni_du_q (__m256i, __m256i, imm0_127);
19139__m256i __lasx_xvssrarni_hu_w (__m256i, __m256i, imm0_31);
19140__m256i __lasx_xvssrarni_h_w (__m256i, __m256i, imm0_31);
19141__m256i __lasx_xvssrarni_w_d (__m256i, __m256i, imm0_63);
19142__m256i __lasx_xvssrarni_wu_d (__m256i, __m256i, imm0_63);
19143__m256i __lasx_xvssrarn_w_d (__m256i, __m256i);
19144__m256i __lasx_xvssrarn_wu_d (__m256i, __m256i);
19145__m256i __lasx_xvssrln_b_h (__m256i, __m256i);
19146__m256i __lasx_xvssrln_bu_h (__m256i, __m256i);
19147__m256i __lasx_xvssrln_hu_w (__m256i, __m256i);
19148__m256i __lasx_xvssrln_h_w (__m256i, __m256i);
19149__m256i __lasx_xvssrlni_b_h (__m256i, __m256i, imm0_15);
19150__m256i __lasx_xvssrlni_bu_h (__m256i, __m256i, imm0_15);
19151__m256i __lasx_xvssrlni_d_q (__m256i, __m256i, imm0_127);
19152__m256i __lasx_xvssrlni_du_q (__m256i, __m256i, imm0_127);
19153__m256i __lasx_xvssrlni_hu_w (__m256i, __m256i, imm0_31);
19154__m256i __lasx_xvssrlni_h_w (__m256i, __m256i, imm0_31);
19155__m256i __lasx_xvssrlni_w_d (__m256i, __m256i, imm0_63);
19156__m256i __lasx_xvssrlni_wu_d (__m256i, __m256i, imm0_63);
19157__m256i __lasx_xvssrln_w_d (__m256i, __m256i);
19158__m256i __lasx_xvssrln_wu_d (__m256i, __m256i);
19159__m256i __lasx_xvssrlrn_b_h (__m256i, __m256i);
19160__m256i __lasx_xvssrlrn_bu_h (__m256i, __m256i);
19161__m256i __lasx_xvssrlrn_hu_w (__m256i, __m256i);
19162__m256i __lasx_xvssrlrn_h_w (__m256i, __m256i);
19163__m256i __lasx_xvssrlrni_b_h (__m256i, __m256i, imm0_15);
19164__m256i __lasx_xvssrlrni_bu_h (__m256i, __m256i, imm0_15);
19165__m256i __lasx_xvssrlrni_d_q (__m256i, __m256i, imm0_127);
19166__m256i __lasx_xvssrlrni_du_q (__m256i, __m256i, imm0_127);
19167__m256i __lasx_xvssrlrni_hu_w (__m256i, __m256i, imm0_31);
19168__m256i __lasx_xvssrlrni_h_w (__m256i, __m256i, imm0_31);
19169__m256i __lasx_xvssrlrni_w_d (__m256i, __m256i, imm0_63);
19170__m256i __lasx_xvssrlrni_wu_d (__m256i, __m256i, imm0_63);
19171__m256i __lasx_xvssrlrn_w_d (__m256i, __m256i);
19172__m256i __lasx_xvssrlrn_wu_d (__m256i, __m256i);
19173__m256i __lasx_xvssub_b (__m256i, __m256i);
19174__m256i __lasx_xvssub_bu (__m256i, __m256i);
19175__m256i __lasx_xvssub_d (__m256i, __m256i);
19176__m256i __lasx_xvssub_du (__m256i, __m256i);
19177__m256i __lasx_xvssub_h (__m256i, __m256i);
19178__m256i __lasx_xvssub_hu (__m256i, __m256i);
19179__m256i __lasx_xvssub_w (__m256i, __m256i);
19180__m256i __lasx_xvssub_wu (__m256i, __m256i);
19181void __lasx_xvst (__m256i, void *, imm_n2048_2047);
297ed1ac 19182void __lasx_xvstelm_b (__m256i, void *, imm_n128_127, imm0_31);
19183void __lasx_xvstelm_d (__m256i, void *, imm_n128_127, imm0_3);
19184void __lasx_xvstelm_h (__m256i, void *, imm_n128_127, imm0_15);
19185void __lasx_xvstelm_w (__m256i, void *, imm_n128_127, imm0_7);
1f48786d 19186void __lasx_xvstx (__m256i, void *, long int);
19187__m256i __lasx_xvsub_b (__m256i, __m256i);
19188__m256i __lasx_xvsub_d (__m256i, __m256i);
19189__m256i __lasx_xvsub_h (__m256i, __m256i);
19190__m256i __lasx_xvsubi_bu (__m256i, imm0_31);
19191__m256i __lasx_xvsubi_du (__m256i, imm0_31);
19192__m256i __lasx_xvsubi_hu (__m256i, imm0_31);
19193__m256i __lasx_xvsubi_wu (__m256i, imm0_31);
19194__m256i __lasx_xvsub_q (__m256i, __m256i);
19195__m256i __lasx_xvsub_w (__m256i, __m256i);
19196__m256i __lasx_xvsubwev_d_w (__m256i, __m256i);
19197__m256i __lasx_xvsubwev_d_wu (__m256i, __m256i);
19198__m256i __lasx_xvsubwev_h_b (__m256i, __m256i);
19199__m256i __lasx_xvsubwev_h_bu (__m256i, __m256i);
19200__m256i __lasx_xvsubwev_q_d (__m256i, __m256i);
19201__m256i __lasx_xvsubwev_q_du (__m256i, __m256i);
19202__m256i __lasx_xvsubwev_w_h (__m256i, __m256i);
19203__m256i __lasx_xvsubwev_w_hu (__m256i, __m256i);
19204__m256i __lasx_xvsubwod_d_w (__m256i, __m256i);
19205__m256i __lasx_xvsubwod_d_wu (__m256i, __m256i);
19206__m256i __lasx_xvsubwod_h_b (__m256i, __m256i);
19207__m256i __lasx_xvsubwod_h_bu (__m256i, __m256i);
19208__m256i __lasx_xvsubwod_q_d (__m256i, __m256i);
19209__m256i __lasx_xvsubwod_q_du (__m256i, __m256i);
19210__m256i __lasx_xvsubwod_w_h (__m256i, __m256i);
19211__m256i __lasx_xvsubwod_w_hu (__m256i, __m256i);
19212__m256i __lasx_xvxori_b (__m256i, imm0_255);
19213__m256i __lasx_xvxor_v (__m256i, __m256i);
19214@end smallexample
19215
61f1001f
JX
19216These instrisic functions are available by including @code{lasxintrin.h} and
19217using @option{-mfrecipe} and @option{-mlasx}.
19218@smallexample
19219__m256d __lasx_xvfrecipe_d (__m256d);
19220__m256 __lasx_xvfrecipe_s (__m256);
19221__m256d __lasx_xvfrsqrte_d (__m256d);
19222__m256 __lasx_xvfrsqrte_s (__m256);
19223@end smallexample
19224
d77de738
ML
19225@node MIPS DSP Built-in Functions
19226@subsection MIPS DSP Built-in Functions
19227
19228The MIPS DSP Application-Specific Extension (ASE) includes new
19229instructions that are designed to improve the performance of DSP and
19230media applications. It provides instructions that operate on packed
192318-bit/16-bit integer data, Q7, Q15 and Q31 fractional data.
19232
19233GCC supports MIPS DSP operations using both the generic
19234vector extensions (@pxref{Vector Extensions}) and a collection of
19235MIPS-specific built-in functions. Both kinds of support are
19236enabled by the @option{-mdsp} command-line option.
19237
19238Revision 2 of the ASE was introduced in the second half of 2006.
19239This revision adds extra instructions to the original ASE, but is
19240otherwise backwards-compatible with it. You can select revision 2
19241using the command-line option @option{-mdspr2}; this option implies
19242@option{-mdsp}.
19243
19244The SCOUNT and POS bits of the DSP control register are global. The
19245WRDSP, EXTPDP, EXTPDPV and MTHLIP instructions modify the SCOUNT and
19246POS bits. During optimization, the compiler does not delete these
19247instructions and it does not delete calls to functions containing
19248these instructions.
19249
19250At present, GCC only provides support for operations on 32-bit
19251vectors. The vector type associated with 8-bit integer data is
19252usually called @code{v4i8}, the vector type associated with Q7
19253is usually called @code{v4q7}, the vector type associated with 16-bit
19254integer data is usually called @code{v2i16}, and the vector type
19255associated with Q15 is usually called @code{v2q15}. They can be
19256defined in C as follows:
19257
19258@smallexample
19259typedef signed char v4i8 __attribute__ ((vector_size(4)));
19260typedef signed char v4q7 __attribute__ ((vector_size(4)));
19261typedef short v2i16 __attribute__ ((vector_size(4)));
19262typedef short v2q15 __attribute__ ((vector_size(4)));
19263@end smallexample
19264
19265@code{v4i8}, @code{v4q7}, @code{v2i16} and @code{v2q15} values are
19266initialized in the same way as aggregates. For example:
19267
19268@smallexample
19269v4i8 a = @{1, 2, 3, 4@};
19270v4i8 b;
19271b = (v4i8) @{5, 6, 7, 8@};
19272
19273v2q15 c = @{0x0fcb, 0x3a75@};
19274v2q15 d;
19275d = (v2q15) @{0.1234 * 0x1.0p15, 0.4567 * 0x1.0p15@};
19276@end smallexample
19277
19278@emph{Note:} The CPU's endianness determines the order in which values
19279are packed. On little-endian targets, the first value is the least
19280significant and the last value is the most significant. The opposite
19281order applies to big-endian targets. For example, the code above
19282sets the lowest byte of @code{a} to @code{1} on little-endian targets
19283and @code{4} on big-endian targets.
19284
19285@emph{Note:} Q7, Q15 and Q31 values must be initialized with their integer
19286representation. As shown in this example, the integer representation
19287of a Q7 value can be obtained by multiplying the fractional value by
19288@code{0x1.0p7}. The equivalent for Q15 values is to multiply by
19289@code{0x1.0p15}. The equivalent for Q31 values is to multiply by
19290@code{0x1.0p31}.
19291
19292The table below lists the @code{v4i8} and @code{v2q15} operations for which
19293hardware support exists. @code{a} and @code{b} are @code{v4i8} values,
19294and @code{c} and @code{d} are @code{v2q15} values.
19295
19296@multitable @columnfractions .50 .50
19297@headitem C code @tab MIPS instruction
19298@item @code{a + b} @tab @code{addu.qb}
19299@item @code{c + d} @tab @code{addq.ph}
19300@item @code{a - b} @tab @code{subu.qb}
19301@item @code{c - d} @tab @code{subq.ph}
19302@end multitable
19303
19304The table below lists the @code{v2i16} operation for which
19305hardware support exists for the DSP ASE REV 2. @code{e} and @code{f} are
19306@code{v2i16} values.
19307
19308@multitable @columnfractions .50 .50
19309@headitem C code @tab MIPS instruction
19310@item @code{e * f} @tab @code{mul.ph}
19311@end multitable
19312
19313It is easier to describe the DSP built-in functions if we first define
19314the following types:
19315
19316@smallexample
19317typedef int q31;
19318typedef int i32;
19319typedef unsigned int ui32;
19320typedef long long a64;
19321@end smallexample
19322
19323@code{q31} and @code{i32} are actually the same as @code{int}, but we
19324use @code{q31} to indicate a Q31 fractional value and @code{i32} to
19325indicate a 32-bit integer value. Similarly, @code{a64} is the same as
19326@code{long long}, but we use @code{a64} to indicate values that are
19327placed in one of the four DSP accumulators (@code{$ac0},
19328@code{$ac1}, @code{$ac2} or @code{$ac3}).
19329
19330Also, some built-in functions prefer or require immediate numbers as
19331parameters, because the corresponding DSP instructions accept both immediate
19332numbers and register operands, or accept immediate numbers only. The
19333immediate parameters are listed as follows.
19334
19335@smallexample
19336imm0_3: 0 to 3.
19337imm0_7: 0 to 7.
19338imm0_15: 0 to 15.
19339imm0_31: 0 to 31.
19340imm0_63: 0 to 63.
19341imm0_255: 0 to 255.
19342imm_n32_31: -32 to 31.
19343imm_n512_511: -512 to 511.
19344@end smallexample
19345
19346The following built-in functions map directly to a particular MIPS DSP
19347instruction. Please refer to the architecture specification
19348for details on what each instruction does.
19349
19350@smallexample
19351v2q15 __builtin_mips_addq_ph (v2q15, v2q15);
19352v2q15 __builtin_mips_addq_s_ph (v2q15, v2q15);
19353q31 __builtin_mips_addq_s_w (q31, q31);
19354v4i8 __builtin_mips_addu_qb (v4i8, v4i8);
19355v4i8 __builtin_mips_addu_s_qb (v4i8, v4i8);
19356v2q15 __builtin_mips_subq_ph (v2q15, v2q15);
19357v2q15 __builtin_mips_subq_s_ph (v2q15, v2q15);
19358q31 __builtin_mips_subq_s_w (q31, q31);
19359v4i8 __builtin_mips_subu_qb (v4i8, v4i8);
19360v4i8 __builtin_mips_subu_s_qb (v4i8, v4i8);
19361i32 __builtin_mips_addsc (i32, i32);
19362i32 __builtin_mips_addwc (i32, i32);
19363i32 __builtin_mips_modsub (i32, i32);
19364i32 __builtin_mips_raddu_w_qb (v4i8);
19365v2q15 __builtin_mips_absq_s_ph (v2q15);
19366q31 __builtin_mips_absq_s_w (q31);
19367v4i8 __builtin_mips_precrq_qb_ph (v2q15, v2q15);
19368v2q15 __builtin_mips_precrq_ph_w (q31, q31);
19369v2q15 __builtin_mips_precrq_rs_ph_w (q31, q31);
19370v4i8 __builtin_mips_precrqu_s_qb_ph (v2q15, v2q15);
19371q31 __builtin_mips_preceq_w_phl (v2q15);
19372q31 __builtin_mips_preceq_w_phr (v2q15);
19373v2q15 __builtin_mips_precequ_ph_qbl (v4i8);
19374v2q15 __builtin_mips_precequ_ph_qbr (v4i8);
19375v2q15 __builtin_mips_precequ_ph_qbla (v4i8);
19376v2q15 __builtin_mips_precequ_ph_qbra (v4i8);
19377v2q15 __builtin_mips_preceu_ph_qbl (v4i8);
19378v2q15 __builtin_mips_preceu_ph_qbr (v4i8);
19379v2q15 __builtin_mips_preceu_ph_qbla (v4i8);
19380v2q15 __builtin_mips_preceu_ph_qbra (v4i8);
19381v4i8 __builtin_mips_shll_qb (v4i8, imm0_7);
19382v4i8 __builtin_mips_shll_qb (v4i8, i32);
19383v2q15 __builtin_mips_shll_ph (v2q15, imm0_15);
19384v2q15 __builtin_mips_shll_ph (v2q15, i32);
19385v2q15 __builtin_mips_shll_s_ph (v2q15, imm0_15);
19386v2q15 __builtin_mips_shll_s_ph (v2q15, i32);
19387q31 __builtin_mips_shll_s_w (q31, imm0_31);
19388q31 __builtin_mips_shll_s_w (q31, i32);
19389v4i8 __builtin_mips_shrl_qb (v4i8, imm0_7);
19390v4i8 __builtin_mips_shrl_qb (v4i8, i32);
19391v2q15 __builtin_mips_shra_ph (v2q15, imm0_15);
19392v2q15 __builtin_mips_shra_ph (v2q15, i32);
19393v2q15 __builtin_mips_shra_r_ph (v2q15, imm0_15);
19394v2q15 __builtin_mips_shra_r_ph (v2q15, i32);
19395q31 __builtin_mips_shra_r_w (q31, imm0_31);
19396q31 __builtin_mips_shra_r_w (q31, i32);
19397v2q15 __builtin_mips_muleu_s_ph_qbl (v4i8, v2q15);
19398v2q15 __builtin_mips_muleu_s_ph_qbr (v4i8, v2q15);
19399v2q15 __builtin_mips_mulq_rs_ph (v2q15, v2q15);
19400q31 __builtin_mips_muleq_s_w_phl (v2q15, v2q15);
19401q31 __builtin_mips_muleq_s_w_phr (v2q15, v2q15);
19402a64 __builtin_mips_dpau_h_qbl (a64, v4i8, v4i8);
19403a64 __builtin_mips_dpau_h_qbr (a64, v4i8, v4i8);
19404a64 __builtin_mips_dpsu_h_qbl (a64, v4i8, v4i8);
19405a64 __builtin_mips_dpsu_h_qbr (a64, v4i8, v4i8);
19406a64 __builtin_mips_dpaq_s_w_ph (a64, v2q15, v2q15);
19407a64 __builtin_mips_dpaq_sa_l_w (a64, q31, q31);
19408a64 __builtin_mips_dpsq_s_w_ph (a64, v2q15, v2q15);
19409a64 __builtin_mips_dpsq_sa_l_w (a64, q31, q31);
19410a64 __builtin_mips_mulsaq_s_w_ph (a64, v2q15, v2q15);
19411a64 __builtin_mips_maq_s_w_phl (a64, v2q15, v2q15);
19412a64 __builtin_mips_maq_s_w_phr (a64, v2q15, v2q15);
19413a64 __builtin_mips_maq_sa_w_phl (a64, v2q15, v2q15);
19414a64 __builtin_mips_maq_sa_w_phr (a64, v2q15, v2q15);
19415i32 __builtin_mips_bitrev (i32);
19416i32 __builtin_mips_insv (i32, i32);
19417v4i8 __builtin_mips_repl_qb (imm0_255);
19418v4i8 __builtin_mips_repl_qb (i32);
19419v2q15 __builtin_mips_repl_ph (imm_n512_511);
19420v2q15 __builtin_mips_repl_ph (i32);
19421void __builtin_mips_cmpu_eq_qb (v4i8, v4i8);
19422void __builtin_mips_cmpu_lt_qb (v4i8, v4i8);
19423void __builtin_mips_cmpu_le_qb (v4i8, v4i8);
19424i32 __builtin_mips_cmpgu_eq_qb (v4i8, v4i8);
19425i32 __builtin_mips_cmpgu_lt_qb (v4i8, v4i8);
19426i32 __builtin_mips_cmpgu_le_qb (v4i8, v4i8);
19427void __builtin_mips_cmp_eq_ph (v2q15, v2q15);
19428void __builtin_mips_cmp_lt_ph (v2q15, v2q15);
19429void __builtin_mips_cmp_le_ph (v2q15, v2q15);
19430v4i8 __builtin_mips_pick_qb (v4i8, v4i8);
19431v2q15 __builtin_mips_pick_ph (v2q15, v2q15);
19432v2q15 __builtin_mips_packrl_ph (v2q15, v2q15);
19433i32 __builtin_mips_extr_w (a64, imm0_31);
19434i32 __builtin_mips_extr_w (a64, i32);
19435i32 __builtin_mips_extr_r_w (a64, imm0_31);
19436i32 __builtin_mips_extr_s_h (a64, i32);
19437i32 __builtin_mips_extr_rs_w (a64, imm0_31);
19438i32 __builtin_mips_extr_rs_w (a64, i32);
19439i32 __builtin_mips_extr_s_h (a64, imm0_31);
19440i32 __builtin_mips_extr_r_w (a64, i32);
19441i32 __builtin_mips_extp (a64, imm0_31);
19442i32 __builtin_mips_extp (a64, i32);
19443i32 __builtin_mips_extpdp (a64, imm0_31);
19444i32 __builtin_mips_extpdp (a64, i32);
19445a64 __builtin_mips_shilo (a64, imm_n32_31);
19446a64 __builtin_mips_shilo (a64, i32);
19447a64 __builtin_mips_mthlip (a64, i32);
19448void __builtin_mips_wrdsp (i32, imm0_63);
19449i32 __builtin_mips_rddsp (imm0_63);
19450i32 __builtin_mips_lbux (void *, i32);
19451i32 __builtin_mips_lhx (void *, i32);
19452i32 __builtin_mips_lwx (void *, i32);
19453a64 __builtin_mips_ldx (void *, i32); /* MIPS64 only */
19454i32 __builtin_mips_bposge32 (void);
19455a64 __builtin_mips_madd (a64, i32, i32);
19456a64 __builtin_mips_maddu (a64, ui32, ui32);
19457a64 __builtin_mips_msub (a64, i32, i32);
19458a64 __builtin_mips_msubu (a64, ui32, ui32);
19459a64 __builtin_mips_mult (i32, i32);
19460a64 __builtin_mips_multu (ui32, ui32);
19461@end smallexample
19462
19463The following built-in functions map directly to a particular MIPS DSP REV 2
19464instruction. Please refer to the architecture specification
19465for details on what each instruction does.
19466
19467@smallexample
19468v4q7 __builtin_mips_absq_s_qb (v4q7);
19469v2i16 __builtin_mips_addu_ph (v2i16, v2i16);
19470v2i16 __builtin_mips_addu_s_ph (v2i16, v2i16);
19471v4i8 __builtin_mips_adduh_qb (v4i8, v4i8);
19472v4i8 __builtin_mips_adduh_r_qb (v4i8, v4i8);
19473i32 __builtin_mips_append (i32, i32, imm0_31);
19474i32 __builtin_mips_balign (i32, i32, imm0_3);
19475i32 __builtin_mips_cmpgdu_eq_qb (v4i8, v4i8);
19476i32 __builtin_mips_cmpgdu_lt_qb (v4i8, v4i8);
19477i32 __builtin_mips_cmpgdu_le_qb (v4i8, v4i8);
19478a64 __builtin_mips_dpa_w_ph (a64, v2i16, v2i16);
19479a64 __builtin_mips_dps_w_ph (a64, v2i16, v2i16);
19480v2i16 __builtin_mips_mul_ph (v2i16, v2i16);
19481v2i16 __builtin_mips_mul_s_ph (v2i16, v2i16);
19482q31 __builtin_mips_mulq_rs_w (q31, q31);
19483v2q15 __builtin_mips_mulq_s_ph (v2q15, v2q15);
19484q31 __builtin_mips_mulq_s_w (q31, q31);
19485a64 __builtin_mips_mulsa_w_ph (a64, v2i16, v2i16);
19486v4i8 __builtin_mips_precr_qb_ph (v2i16, v2i16);
19487v2i16 __builtin_mips_precr_sra_ph_w (i32, i32, imm0_31);
19488v2i16 __builtin_mips_precr_sra_r_ph_w (i32, i32, imm0_31);
19489i32 __builtin_mips_prepend (i32, i32, imm0_31);
19490v4i8 __builtin_mips_shra_qb (v4i8, imm0_7);
19491v4i8 __builtin_mips_shra_r_qb (v4i8, imm0_7);
19492v4i8 __builtin_mips_shra_qb (v4i8, i32);
19493v4i8 __builtin_mips_shra_r_qb (v4i8, i32);
19494v2i16 __builtin_mips_shrl_ph (v2i16, imm0_15);
19495v2i16 __builtin_mips_shrl_ph (v2i16, i32);
19496v2i16 __builtin_mips_subu_ph (v2i16, v2i16);
19497v2i16 __builtin_mips_subu_s_ph (v2i16, v2i16);
19498v4i8 __builtin_mips_subuh_qb (v4i8, v4i8);
19499v4i8 __builtin_mips_subuh_r_qb (v4i8, v4i8);
19500v2q15 __builtin_mips_addqh_ph (v2q15, v2q15);
19501v2q15 __builtin_mips_addqh_r_ph (v2q15, v2q15);
19502q31 __builtin_mips_addqh_w (q31, q31);
19503q31 __builtin_mips_addqh_r_w (q31, q31);
19504v2q15 __builtin_mips_subqh_ph (v2q15, v2q15);
19505v2q15 __builtin_mips_subqh_r_ph (v2q15, v2q15);
19506q31 __builtin_mips_subqh_w (q31, q31);
19507q31 __builtin_mips_subqh_r_w (q31, q31);
19508a64 __builtin_mips_dpax_w_ph (a64, v2i16, v2i16);
19509a64 __builtin_mips_dpsx_w_ph (a64, v2i16, v2i16);
19510a64 __builtin_mips_dpaqx_s_w_ph (a64, v2q15, v2q15);
19511a64 __builtin_mips_dpaqx_sa_w_ph (a64, v2q15, v2q15);
19512a64 __builtin_mips_dpsqx_s_w_ph (a64, v2q15, v2q15);
19513a64 __builtin_mips_dpsqx_sa_w_ph (a64, v2q15, v2q15);
19514@end smallexample
19515
19516
19517@node MIPS Paired-Single Support
19518@subsection MIPS Paired-Single Support
19519
19520The MIPS64 architecture includes a number of instructions that
19521operate on pairs of single-precision floating-point values.
19522Each pair is packed into a 64-bit floating-point register,
19523with one element being designated the ``upper half'' and
19524the other being designated the ``lower half''.
19525
19526GCC supports paired-single operations using both the generic
19527vector extensions (@pxref{Vector Extensions}) and a collection of
19528MIPS-specific built-in functions. Both kinds of support are
19529enabled by the @option{-mpaired-single} command-line option.
19530
19531The vector type associated with paired-single values is usually
19532called @code{v2sf}. It can be defined in C as follows:
19533
19534@smallexample
19535typedef float v2sf __attribute__ ((vector_size (8)));
19536@end smallexample
19537
19538@code{v2sf} values are initialized in the same way as aggregates.
19539For example:
19540
19541@smallexample
19542v2sf a = @{1.5, 9.1@};
19543v2sf b;
19544float e, f;
19545b = (v2sf) @{e, f@};
19546@end smallexample
19547
19548@emph{Note:} The CPU's endianness determines which value is stored in
19549the upper half of a register and which value is stored in the lower half.
19550On little-endian targets, the first value is the lower one and the second
19551value is the upper one. The opposite order applies to big-endian targets.
19552For example, the code above sets the lower half of @code{a} to
19553@code{1.5} on little-endian targets and @code{9.1} on big-endian targets.
19554
19555@node MIPS Loongson Built-in Functions
19556@subsection MIPS Loongson Built-in Functions
19557
19558GCC provides intrinsics to access the SIMD instructions provided by the
19559ST Microelectronics Loongson-2E and -2F processors. These intrinsics,
19560available after inclusion of the @code{loongson.h} header file,
19561operate on the following 64-bit vector types:
19562
19563@itemize
19564@item @code{uint8x8_t}, a vector of eight unsigned 8-bit integers;
19565@item @code{uint16x4_t}, a vector of four unsigned 16-bit integers;
19566@item @code{uint32x2_t}, a vector of two unsigned 32-bit integers;
19567@item @code{int8x8_t}, a vector of eight signed 8-bit integers;
19568@item @code{int16x4_t}, a vector of four signed 16-bit integers;
19569@item @code{int32x2_t}, a vector of two signed 32-bit integers.
19570@end itemize
19571
19572The intrinsics provided are listed below; each is named after the
19573machine instruction to which it corresponds, with suffixes added as
19574appropriate to distinguish intrinsics that expand to the same machine
19575instruction yet have different argument types. Refer to the architecture
19576documentation for a description of the functionality of each
19577instruction.
19578
19579@smallexample
19580int16x4_t packsswh (int32x2_t s, int32x2_t t);
19581int8x8_t packsshb (int16x4_t s, int16x4_t t);
19582uint8x8_t packushb (uint16x4_t s, uint16x4_t t);
19583uint32x2_t paddw_u (uint32x2_t s, uint32x2_t t);
19584uint16x4_t paddh_u (uint16x4_t s, uint16x4_t t);
19585uint8x8_t paddb_u (uint8x8_t s, uint8x8_t t);
19586int32x2_t paddw_s (int32x2_t s, int32x2_t t);
19587int16x4_t paddh_s (int16x4_t s, int16x4_t t);
19588int8x8_t paddb_s (int8x8_t s, int8x8_t t);
19589uint64_t paddd_u (uint64_t s, uint64_t t);
19590int64_t paddd_s (int64_t s, int64_t t);
19591int16x4_t paddsh (int16x4_t s, int16x4_t t);
19592int8x8_t paddsb (int8x8_t s, int8x8_t t);
19593uint16x4_t paddush (uint16x4_t s, uint16x4_t t);
19594uint8x8_t paddusb (uint8x8_t s, uint8x8_t t);
19595uint64_t pandn_ud (uint64_t s, uint64_t t);
19596uint32x2_t pandn_uw (uint32x2_t s, uint32x2_t t);
19597uint16x4_t pandn_uh (uint16x4_t s, uint16x4_t t);
19598uint8x8_t pandn_ub (uint8x8_t s, uint8x8_t t);
19599int64_t pandn_sd (int64_t s, int64_t t);
19600int32x2_t pandn_sw (int32x2_t s, int32x2_t t);
19601int16x4_t pandn_sh (int16x4_t s, int16x4_t t);
19602int8x8_t pandn_sb (int8x8_t s, int8x8_t t);
19603uint16x4_t pavgh (uint16x4_t s, uint16x4_t t);
19604uint8x8_t pavgb (uint8x8_t s, uint8x8_t t);
19605uint32x2_t pcmpeqw_u (uint32x2_t s, uint32x2_t t);
19606uint16x4_t pcmpeqh_u (uint16x4_t s, uint16x4_t t);
19607uint8x8_t pcmpeqb_u (uint8x8_t s, uint8x8_t t);
19608int32x2_t pcmpeqw_s (int32x2_t s, int32x2_t t);
19609int16x4_t pcmpeqh_s (int16x4_t s, int16x4_t t);
19610int8x8_t pcmpeqb_s (int8x8_t s, int8x8_t t);
19611uint32x2_t pcmpgtw_u (uint32x2_t s, uint32x2_t t);
19612uint16x4_t pcmpgth_u (uint16x4_t s, uint16x4_t t);
19613uint8x8_t pcmpgtb_u (uint8x8_t s, uint8x8_t t);
19614int32x2_t pcmpgtw_s (int32x2_t s, int32x2_t t);
19615int16x4_t pcmpgth_s (int16x4_t s, int16x4_t t);
19616int8x8_t pcmpgtb_s (int8x8_t s, int8x8_t t);
19617uint16x4_t pextrh_u (uint16x4_t s, int field);
19618int16x4_t pextrh_s (int16x4_t s, int field);
19619uint16x4_t pinsrh_0_u (uint16x4_t s, uint16x4_t t);
19620uint16x4_t pinsrh_1_u (uint16x4_t s, uint16x4_t t);
19621uint16x4_t pinsrh_2_u (uint16x4_t s, uint16x4_t t);
19622uint16x4_t pinsrh_3_u (uint16x4_t s, uint16x4_t t);
19623int16x4_t pinsrh_0_s (int16x4_t s, int16x4_t t);
19624int16x4_t pinsrh_1_s (int16x4_t s, int16x4_t t);
19625int16x4_t pinsrh_2_s (int16x4_t s, int16x4_t t);
19626int16x4_t pinsrh_3_s (int16x4_t s, int16x4_t t);
19627int32x2_t pmaddhw (int16x4_t s, int16x4_t t);
19628int16x4_t pmaxsh (int16x4_t s, int16x4_t t);
19629uint8x8_t pmaxub (uint8x8_t s, uint8x8_t t);
19630int16x4_t pminsh (int16x4_t s, int16x4_t t);
19631uint8x8_t pminub (uint8x8_t s, uint8x8_t t);
19632uint8x8_t pmovmskb_u (uint8x8_t s);
19633int8x8_t pmovmskb_s (int8x8_t s);
19634uint16x4_t pmulhuh (uint16x4_t s, uint16x4_t t);
19635int16x4_t pmulhh (int16x4_t s, int16x4_t t);
19636int16x4_t pmullh (int16x4_t s, int16x4_t t);
19637int64_t pmuluw (uint32x2_t s, uint32x2_t t);
19638uint8x8_t pasubub (uint8x8_t s, uint8x8_t t);
19639uint16x4_t biadd (uint8x8_t s);
19640uint16x4_t psadbh (uint8x8_t s, uint8x8_t t);
19641uint16x4_t pshufh_u (uint16x4_t dest, uint16x4_t s, uint8_t order);
19642int16x4_t pshufh_s (int16x4_t dest, int16x4_t s, uint8_t order);
19643uint16x4_t psllh_u (uint16x4_t s, uint8_t amount);
19644int16x4_t psllh_s (int16x4_t s, uint8_t amount);
19645uint32x2_t psllw_u (uint32x2_t s, uint8_t amount);
19646int32x2_t psllw_s (int32x2_t s, uint8_t amount);
19647uint16x4_t psrlh_u (uint16x4_t s, uint8_t amount);
19648int16x4_t psrlh_s (int16x4_t s, uint8_t amount);
19649uint32x2_t psrlw_u (uint32x2_t s, uint8_t amount);
19650int32x2_t psrlw_s (int32x2_t s, uint8_t amount);
19651uint16x4_t psrah_u (uint16x4_t s, uint8_t amount);
19652int16x4_t psrah_s (int16x4_t s, uint8_t amount);
19653uint32x2_t psraw_u (uint32x2_t s, uint8_t amount);
19654int32x2_t psraw_s (int32x2_t s, uint8_t amount);
19655uint32x2_t psubw_u (uint32x2_t s, uint32x2_t t);
19656uint16x4_t psubh_u (uint16x4_t s, uint16x4_t t);
19657uint8x8_t psubb_u (uint8x8_t s, uint8x8_t t);
19658int32x2_t psubw_s (int32x2_t s, int32x2_t t);
19659int16x4_t psubh_s (int16x4_t s, int16x4_t t);
19660int8x8_t psubb_s (int8x8_t s, int8x8_t t);
19661uint64_t psubd_u (uint64_t s, uint64_t t);
19662int64_t psubd_s (int64_t s, int64_t t);
19663int16x4_t psubsh (int16x4_t s, int16x4_t t);
19664int8x8_t psubsb (int8x8_t s, int8x8_t t);
19665uint16x4_t psubush (uint16x4_t s, uint16x4_t t);
19666uint8x8_t psubusb (uint8x8_t s, uint8x8_t t);
19667uint32x2_t punpckhwd_u (uint32x2_t s, uint32x2_t t);
19668uint16x4_t punpckhhw_u (uint16x4_t s, uint16x4_t t);
19669uint8x8_t punpckhbh_u (uint8x8_t s, uint8x8_t t);
19670int32x2_t punpckhwd_s (int32x2_t s, int32x2_t t);
19671int16x4_t punpckhhw_s (int16x4_t s, int16x4_t t);
19672int8x8_t punpckhbh_s (int8x8_t s, int8x8_t t);
19673uint32x2_t punpcklwd_u (uint32x2_t s, uint32x2_t t);
19674uint16x4_t punpcklhw_u (uint16x4_t s, uint16x4_t t);
19675uint8x8_t punpcklbh_u (uint8x8_t s, uint8x8_t t);
19676int32x2_t punpcklwd_s (int32x2_t s, int32x2_t t);
19677int16x4_t punpcklhw_s (int16x4_t s, int16x4_t t);
19678int8x8_t punpcklbh_s (int8x8_t s, int8x8_t t);
19679@end smallexample
19680
19681@menu
19682* Paired-Single Arithmetic::
19683* Paired-Single Built-in Functions::
19684* MIPS-3D Built-in Functions::
19685@end menu
19686
19687@node Paired-Single Arithmetic
19688@subsubsection Paired-Single Arithmetic
19689
19690The table below lists the @code{v2sf} operations for which hardware
19691support exists. @code{a}, @code{b} and @code{c} are @code{v2sf}
19692values and @code{x} is an integral value.
19693
19694@multitable @columnfractions .50 .50
19695@headitem C code @tab MIPS instruction
19696@item @code{a + b} @tab @code{add.ps}
19697@item @code{a - b} @tab @code{sub.ps}
19698@item @code{-a} @tab @code{neg.ps}
19699@item @code{a * b} @tab @code{mul.ps}
19700@item @code{a * b + c} @tab @code{madd.ps}
19701@item @code{a * b - c} @tab @code{msub.ps}
19702@item @code{-(a * b + c)} @tab @code{nmadd.ps}
19703@item @code{-(a * b - c)} @tab @code{nmsub.ps}
19704@item @code{x ? a : b} @tab @code{movn.ps}/@code{movz.ps}
19705@end multitable
19706
19707Note that the multiply-accumulate instructions can be disabled
19708using the command-line option @code{-mno-fused-madd}.
19709
19710@node Paired-Single Built-in Functions
19711@subsubsection Paired-Single Built-in Functions
19712
19713The following paired-single functions map directly to a particular
19714MIPS instruction. Please refer to the architecture specification
19715for details on what each instruction does.
19716
19717@table @code
19718@item v2sf __builtin_mips_pll_ps (v2sf, v2sf)
19719Pair lower lower (@code{pll.ps}).
19720
19721@item v2sf __builtin_mips_pul_ps (v2sf, v2sf)
19722Pair upper lower (@code{pul.ps}).
19723
19724@item v2sf __builtin_mips_plu_ps (v2sf, v2sf)
19725Pair lower upper (@code{plu.ps}).
19726
19727@item v2sf __builtin_mips_puu_ps (v2sf, v2sf)
19728Pair upper upper (@code{puu.ps}).
19729
19730@item v2sf __builtin_mips_cvt_ps_s (float, float)
19731Convert pair to paired single (@code{cvt.ps.s}).
19732
19733@item float __builtin_mips_cvt_s_pl (v2sf)
19734Convert pair lower to single (@code{cvt.s.pl}).
19735
19736@item float __builtin_mips_cvt_s_pu (v2sf)
19737Convert pair upper to single (@code{cvt.s.pu}).
19738
19739@item v2sf __builtin_mips_abs_ps (v2sf)
19740Absolute value (@code{abs.ps}).
19741
19742@item v2sf __builtin_mips_alnv_ps (v2sf, v2sf, int)
19743Align variable (@code{alnv.ps}).
19744
19745@emph{Note:} The value of the third parameter must be 0 or 4
19746modulo 8, otherwise the result is unpredictable. Please read the
19747instruction description for details.
19748@end table
19749
19750The following multi-instruction functions are also available.
19751In each case, @var{cond} can be any of the 16 floating-point conditions:
19752@code{f}, @code{un}, @code{eq}, @code{ueq}, @code{olt}, @code{ult},
19753@code{ole}, @code{ule}, @code{sf}, @code{ngle}, @code{seq}, @code{ngl},
19754@code{lt}, @code{nge}, @code{le} or @code{ngt}.
19755
19756@table @code
19757@item v2sf __builtin_mips_movt_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
19758@itemx v2sf __builtin_mips_movf_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
19759Conditional move based on floating-point comparison (@code{c.@var{cond}.ps},
19760@code{movt.ps}/@code{movf.ps}).
19761
19762The @code{movt} functions return the value @var{x} computed by:
19763
19764@smallexample
19765c.@var{cond}.ps @var{cc},@var{a},@var{b}
19766mov.ps @var{x},@var{c}
19767movt.ps @var{x},@var{d},@var{cc}
19768@end smallexample
19769
19770The @code{movf} functions are similar but use @code{movf.ps} instead
19771of @code{movt.ps}.
19772
19773@item int __builtin_mips_upper_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
19774@itemx int __builtin_mips_lower_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
19775Comparison of two paired-single values (@code{c.@var{cond}.ps},
19776@code{bc1t}/@code{bc1f}).
19777
19778These functions compare @var{a} and @var{b} using @code{c.@var{cond}.ps}
19779and return either the upper or lower half of the result. For example:
19780
19781@smallexample
19782v2sf a, b;
19783if (__builtin_mips_upper_c_eq_ps (a, b))
19784 upper_halves_are_equal ();
19785else
19786 upper_halves_are_unequal ();
19787
19788if (__builtin_mips_lower_c_eq_ps (a, b))
19789 lower_halves_are_equal ();
19790else
19791 lower_halves_are_unequal ();
19792@end smallexample
19793@end table
19794
19795@node MIPS-3D Built-in Functions
19796@subsubsection MIPS-3D Built-in Functions
19797
19798The MIPS-3D Application-Specific Extension (ASE) includes additional
19799paired-single instructions that are designed to improve the performance
19800of 3D graphics operations. Support for these instructions is controlled
19801by the @option{-mips3d} command-line option.
19802
19803The functions listed below map directly to a particular MIPS-3D
19804instruction. Please refer to the architecture specification for
19805more details on what each instruction does.
19806
19807@table @code
19808@item v2sf __builtin_mips_addr_ps (v2sf, v2sf)
19809Reduction add (@code{addr.ps}).
19810
19811@item v2sf __builtin_mips_mulr_ps (v2sf, v2sf)
19812Reduction multiply (@code{mulr.ps}).
19813
19814@item v2sf __builtin_mips_cvt_pw_ps (v2sf)
19815Convert paired single to paired word (@code{cvt.pw.ps}).
19816
19817@item v2sf __builtin_mips_cvt_ps_pw (v2sf)
19818Convert paired word to paired single (@code{cvt.ps.pw}).
19819
19820@item float __builtin_mips_recip1_s (float)
19821@itemx double __builtin_mips_recip1_d (double)
19822@itemx v2sf __builtin_mips_recip1_ps (v2sf)
19823Reduced-precision reciprocal (sequence step 1) (@code{recip1.@var{fmt}}).
19824
19825@item float __builtin_mips_recip2_s (float, float)
19826@itemx double __builtin_mips_recip2_d (double, double)
19827@itemx v2sf __builtin_mips_recip2_ps (v2sf, v2sf)
19828Reduced-precision reciprocal (sequence step 2) (@code{recip2.@var{fmt}}).
19829
19830@item float __builtin_mips_rsqrt1_s (float)
19831@itemx double __builtin_mips_rsqrt1_d (double)
19832@itemx v2sf __builtin_mips_rsqrt1_ps (v2sf)
19833Reduced-precision reciprocal square root (sequence step 1)
19834(@code{rsqrt1.@var{fmt}}).
19835
19836@item float __builtin_mips_rsqrt2_s (float, float)
19837@itemx double __builtin_mips_rsqrt2_d (double, double)
19838@itemx v2sf __builtin_mips_rsqrt2_ps (v2sf, v2sf)
19839Reduced-precision reciprocal square root (sequence step 2)
19840(@code{rsqrt2.@var{fmt}}).
19841@end table
19842
19843The following multi-instruction functions are also available.
19844In each case, @var{cond} can be any of the 16 floating-point conditions:
19845@code{f}, @code{un}, @code{eq}, @code{ueq}, @code{olt}, @code{ult},
19846@code{ole}, @code{ule}, @code{sf}, @code{ngle}, @code{seq},
19847@code{ngl}, @code{lt}, @code{nge}, @code{le} or @code{ngt}.
19848
19849@table @code
19850@item int __builtin_mips_cabs_@var{cond}_s (float @var{a}, float @var{b})
19851@itemx int __builtin_mips_cabs_@var{cond}_d (double @var{a}, double @var{b})
19852Absolute comparison of two scalar values (@code{cabs.@var{cond}.@var{fmt}},
19853@code{bc1t}/@code{bc1f}).
19854
19855These functions compare @var{a} and @var{b} using @code{cabs.@var{cond}.s}
19856or @code{cabs.@var{cond}.d} and return the result as a boolean value.
19857For example:
19858
19859@smallexample
19860float a, b;
19861if (__builtin_mips_cabs_eq_s (a, b))
19862 true ();
19863else
19864 false ();
19865@end smallexample
19866
19867@item int __builtin_mips_upper_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
19868@itemx int __builtin_mips_lower_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
19869Absolute comparison of two paired-single values (@code{cabs.@var{cond}.ps},
19870@code{bc1t}/@code{bc1f}).
19871
19872These functions compare @var{a} and @var{b} using @code{cabs.@var{cond}.ps}
19873and return either the upper or lower half of the result. For example:
19874
19875@smallexample
19876v2sf a, b;
19877if (__builtin_mips_upper_cabs_eq_ps (a, b))
19878 upper_halves_are_equal ();
19879else
19880 upper_halves_are_unequal ();
19881
19882if (__builtin_mips_lower_cabs_eq_ps (a, b))
19883 lower_halves_are_equal ();
19884else
19885 lower_halves_are_unequal ();
19886@end smallexample
19887
19888@item v2sf __builtin_mips_movt_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
19889@itemx v2sf __builtin_mips_movf_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
19890Conditional move based on absolute comparison (@code{cabs.@var{cond}.ps},
19891@code{movt.ps}/@code{movf.ps}).
19892
19893The @code{movt} functions return the value @var{x} computed by:
19894
19895@smallexample
19896cabs.@var{cond}.ps @var{cc},@var{a},@var{b}
19897mov.ps @var{x},@var{c}
19898movt.ps @var{x},@var{d},@var{cc}
19899@end smallexample
19900
19901The @code{movf} functions are similar but use @code{movf.ps} instead
19902of @code{movt.ps}.
19903
19904@item int __builtin_mips_any_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
19905@itemx int __builtin_mips_all_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
19906@itemx int __builtin_mips_any_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
19907@itemx int __builtin_mips_all_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
19908Comparison of two paired-single values
19909(@code{c.@var{cond}.ps}/@code{cabs.@var{cond}.ps},
19910@code{bc1any2t}/@code{bc1any2f}).
19911
19912These functions compare @var{a} and @var{b} using @code{c.@var{cond}.ps}
19913or @code{cabs.@var{cond}.ps}. The @code{any} forms return @code{true} if either
19914result is @code{true} and the @code{all} forms return @code{true} if both results are @code{true}.
19915For example:
19916
19917@smallexample
19918v2sf a, b;
19919if (__builtin_mips_any_c_eq_ps (a, b))
19920 one_is_true ();
19921else
19922 both_are_false ();
19923
19924if (__builtin_mips_all_c_eq_ps (a, b))
19925 both_are_true ();
19926else
19927 one_is_false ();
19928@end smallexample
19929
19930@item int __builtin_mips_any_c_@var{cond}_4s (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
19931@itemx int __builtin_mips_all_c_@var{cond}_4s (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
19932@itemx int __builtin_mips_any_cabs_@var{cond}_4s (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
19933@itemx int __builtin_mips_all_cabs_@var{cond}_4s (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
19934Comparison of four paired-single values
19935(@code{c.@var{cond}.ps}/@code{cabs.@var{cond}.ps},
19936@code{bc1any4t}/@code{bc1any4f}).
19937
19938These functions use @code{c.@var{cond}.ps} or @code{cabs.@var{cond}.ps}
19939to compare @var{a} with @var{b} and to compare @var{c} with @var{d}.
19940The @code{any} forms return @code{true} if any of the four results are @code{true}
19941and the @code{all} forms return @code{true} if all four results are @code{true}.
19942For example:
19943
19944@smallexample
19945v2sf a, b, c, d;
19946if (__builtin_mips_any_c_eq_4s (a, b, c, d))
19947 some_are_true ();
19948else
19949 all_are_false ();
19950
19951if (__builtin_mips_all_c_eq_4s (a, b, c, d))
19952 all_are_true ();
19953else
19954 some_are_false ();
19955@end smallexample
19956@end table
19957
19958@node MIPS SIMD Architecture (MSA) Support
19959@subsection MIPS SIMD Architecture (MSA) Support
19960
19961@menu
19962* MIPS SIMD Architecture Built-in Functions::
19963@end menu
19964
19965GCC provides intrinsics to access the SIMD instructions provided by the
19966MSA MIPS SIMD Architecture. The interface is made available by including
19967@code{<msa.h>} and using @option{-mmsa -mhard-float -mfp64 -mnan=2008}.
19968For each @code{__builtin_msa_*}, there is a shortened name of the intrinsic,
19969@code{__msa_*}.
19970
19971MSA implements 128-bit wide vector registers, operating on 8-, 16-, 32- and
1997264-bit integer, 16- and 32-bit fixed-point, or 32- and 64-bit floating point
19973data elements. The following vectors typedefs are included in @code{msa.h}:
19974@itemize
19975@item @code{v16i8}, a vector of sixteen signed 8-bit integers;
19976@item @code{v16u8}, a vector of sixteen unsigned 8-bit integers;
19977@item @code{v8i16}, a vector of eight signed 16-bit integers;
19978@item @code{v8u16}, a vector of eight unsigned 16-bit integers;
19979@item @code{v4i32}, a vector of four signed 32-bit integers;
19980@item @code{v4u32}, a vector of four unsigned 32-bit integers;
19981@item @code{v2i64}, a vector of two signed 64-bit integers;
19982@item @code{v2u64}, a vector of two unsigned 64-bit integers;
19983@item @code{v4f32}, a vector of four 32-bit floats;
19984@item @code{v2f64}, a vector of two 64-bit doubles.
19985@end itemize
19986
19987Instructions and corresponding built-ins may have additional restrictions and/or
19988input/output values manipulated:
19989@itemize
19990@item @code{imm0_1}, an integer literal in range 0 to 1;
19991@item @code{imm0_3}, an integer literal in range 0 to 3;
19992@item @code{imm0_7}, an integer literal in range 0 to 7;
19993@item @code{imm0_15}, an integer literal in range 0 to 15;
19994@item @code{imm0_31}, an integer literal in range 0 to 31;
19995@item @code{imm0_63}, an integer literal in range 0 to 63;
19996@item @code{imm0_255}, an integer literal in range 0 to 255;
19997@item @code{imm_n16_15}, an integer literal in range -16 to 15;
19998@item @code{imm_n512_511}, an integer literal in range -512 to 511;
19999@item @code{imm_n1024_1022}, an integer literal in range -512 to 511 left
20000shifted by 1 bit, i.e., -1024, -1022, @dots{}, 1020, 1022;
20001@item @code{imm_n2048_2044}, an integer literal in range -512 to 511 left
20002shifted by 2 bits, i.e., -2048, -2044, @dots{}, 2040, 2044;
20003@item @code{imm_n4096_4088}, an integer literal in range -512 to 511 left
20004shifted by 3 bits, i.e., -4096, -4088, @dots{}, 4080, 4088;
20005@item @code{imm1_4}, an integer literal in range 1 to 4;
20006@item @code{i32, i64, u32, u64, f32, f64}, defined as follows:
20007@end itemize
20008
20009@smallexample
20010@{
20011typedef int i32;
20012#if __LONG_MAX__ == __LONG_LONG_MAX__
20013typedef long i64;
20014#else
20015typedef long long i64;
20016#endif
20017
20018typedef unsigned int u32;
20019#if __LONG_MAX__ == __LONG_LONG_MAX__
20020typedef unsigned long u64;
20021#else
20022typedef unsigned long long u64;
20023#endif
20024
20025typedef double f64;
20026typedef float f32;
20027@}
20028@end smallexample
20029
20030@node MIPS SIMD Architecture Built-in Functions
20031@subsubsection MIPS SIMD Architecture Built-in Functions
20032
20033The intrinsics provided are listed below; each is named after the
20034machine instruction.
20035
20036@smallexample
20037v16i8 __builtin_msa_add_a_b (v16i8, v16i8);
20038v8i16 __builtin_msa_add_a_h (v8i16, v8i16);
20039v4i32 __builtin_msa_add_a_w (v4i32, v4i32);
20040v2i64 __builtin_msa_add_a_d (v2i64, v2i64);
20041
20042v16i8 __builtin_msa_adds_a_b (v16i8, v16i8);
20043v8i16 __builtin_msa_adds_a_h (v8i16, v8i16);
20044v4i32 __builtin_msa_adds_a_w (v4i32, v4i32);
20045v2i64 __builtin_msa_adds_a_d (v2i64, v2i64);
20046
20047v16i8 __builtin_msa_adds_s_b (v16i8, v16i8);
20048v8i16 __builtin_msa_adds_s_h (v8i16, v8i16);
20049v4i32 __builtin_msa_adds_s_w (v4i32, v4i32);
20050v2i64 __builtin_msa_adds_s_d (v2i64, v2i64);
20051
20052v16u8 __builtin_msa_adds_u_b (v16u8, v16u8);
20053v8u16 __builtin_msa_adds_u_h (v8u16, v8u16);
20054v4u32 __builtin_msa_adds_u_w (v4u32, v4u32);
20055v2u64 __builtin_msa_adds_u_d (v2u64, v2u64);
20056
20057v16i8 __builtin_msa_addv_b (v16i8, v16i8);
20058v8i16 __builtin_msa_addv_h (v8i16, v8i16);
20059v4i32 __builtin_msa_addv_w (v4i32, v4i32);
20060v2i64 __builtin_msa_addv_d (v2i64, v2i64);
20061
20062v16i8 __builtin_msa_addvi_b (v16i8, imm0_31);
20063v8i16 __builtin_msa_addvi_h (v8i16, imm0_31);
20064v4i32 __builtin_msa_addvi_w (v4i32, imm0_31);
20065v2i64 __builtin_msa_addvi_d (v2i64, imm0_31);
20066
20067v16u8 __builtin_msa_and_v (v16u8, v16u8);
20068
20069v16u8 __builtin_msa_andi_b (v16u8, imm0_255);
20070
20071v16i8 __builtin_msa_asub_s_b (v16i8, v16i8);
20072v8i16 __builtin_msa_asub_s_h (v8i16, v8i16);
20073v4i32 __builtin_msa_asub_s_w (v4i32, v4i32);
20074v2i64 __builtin_msa_asub_s_d (v2i64, v2i64);
20075
20076v16u8 __builtin_msa_asub_u_b (v16u8, v16u8);
20077v8u16 __builtin_msa_asub_u_h (v8u16, v8u16);
20078v4u32 __builtin_msa_asub_u_w (v4u32, v4u32);
20079v2u64 __builtin_msa_asub_u_d (v2u64, v2u64);
20080
20081v16i8 __builtin_msa_ave_s_b (v16i8, v16i8);
20082v8i16 __builtin_msa_ave_s_h (v8i16, v8i16);
20083v4i32 __builtin_msa_ave_s_w (v4i32, v4i32);
20084v2i64 __builtin_msa_ave_s_d (v2i64, v2i64);
20085
20086v16u8 __builtin_msa_ave_u_b (v16u8, v16u8);
20087v8u16 __builtin_msa_ave_u_h (v8u16, v8u16);
20088v4u32 __builtin_msa_ave_u_w (v4u32, v4u32);
20089v2u64 __builtin_msa_ave_u_d (v2u64, v2u64);
20090
20091v16i8 __builtin_msa_aver_s_b (v16i8, v16i8);
20092v8i16 __builtin_msa_aver_s_h (v8i16, v8i16);
20093v4i32 __builtin_msa_aver_s_w (v4i32, v4i32);
20094v2i64 __builtin_msa_aver_s_d (v2i64, v2i64);
20095
20096v16u8 __builtin_msa_aver_u_b (v16u8, v16u8);
20097v8u16 __builtin_msa_aver_u_h (v8u16, v8u16);
20098v4u32 __builtin_msa_aver_u_w (v4u32, v4u32);
20099v2u64 __builtin_msa_aver_u_d (v2u64, v2u64);
20100
20101v16u8 __builtin_msa_bclr_b (v16u8, v16u8);
20102v8u16 __builtin_msa_bclr_h (v8u16, v8u16);
20103v4u32 __builtin_msa_bclr_w (v4u32, v4u32);
20104v2u64 __builtin_msa_bclr_d (v2u64, v2u64);
20105
20106v16u8 __builtin_msa_bclri_b (v16u8, imm0_7);
20107v8u16 __builtin_msa_bclri_h (v8u16, imm0_15);
20108v4u32 __builtin_msa_bclri_w (v4u32, imm0_31);
20109v2u64 __builtin_msa_bclri_d (v2u64, imm0_63);
20110
20111v16u8 __builtin_msa_binsl_b (v16u8, v16u8, v16u8);
20112v8u16 __builtin_msa_binsl_h (v8u16, v8u16, v8u16);
20113v4u32 __builtin_msa_binsl_w (v4u32, v4u32, v4u32);
20114v2u64 __builtin_msa_binsl_d (v2u64, v2u64, v2u64);
20115
20116v16u8 __builtin_msa_binsli_b (v16u8, v16u8, imm0_7);
20117v8u16 __builtin_msa_binsli_h (v8u16, v8u16, imm0_15);
20118v4u32 __builtin_msa_binsli_w (v4u32, v4u32, imm0_31);
20119v2u64 __builtin_msa_binsli_d (v2u64, v2u64, imm0_63);
20120
20121v16u8 __builtin_msa_binsr_b (v16u8, v16u8, v16u8);
20122v8u16 __builtin_msa_binsr_h (v8u16, v8u16, v8u16);
20123v4u32 __builtin_msa_binsr_w (v4u32, v4u32, v4u32);
20124v2u64 __builtin_msa_binsr_d (v2u64, v2u64, v2u64);
20125
20126v16u8 __builtin_msa_binsri_b (v16u8, v16u8, imm0_7);
20127v8u16 __builtin_msa_binsri_h (v8u16, v8u16, imm0_15);
20128v4u32 __builtin_msa_binsri_w (v4u32, v4u32, imm0_31);
20129v2u64 __builtin_msa_binsri_d (v2u64, v2u64, imm0_63);
20130
20131v16u8 __builtin_msa_bmnz_v (v16u8, v16u8, v16u8);
20132
20133v16u8 __builtin_msa_bmnzi_b (v16u8, v16u8, imm0_255);
20134
20135v16u8 __builtin_msa_bmz_v (v16u8, v16u8, v16u8);
20136
20137v16u8 __builtin_msa_bmzi_b (v16u8, v16u8, imm0_255);
20138
20139v16u8 __builtin_msa_bneg_b (v16u8, v16u8);
20140v8u16 __builtin_msa_bneg_h (v8u16, v8u16);
20141v4u32 __builtin_msa_bneg_w (v4u32, v4u32);
20142v2u64 __builtin_msa_bneg_d (v2u64, v2u64);
20143
20144v16u8 __builtin_msa_bnegi_b (v16u8, imm0_7);
20145v8u16 __builtin_msa_bnegi_h (v8u16, imm0_15);
20146v4u32 __builtin_msa_bnegi_w (v4u32, imm0_31);
20147v2u64 __builtin_msa_bnegi_d (v2u64, imm0_63);
20148
20149i32 __builtin_msa_bnz_b (v16u8);
20150i32 __builtin_msa_bnz_h (v8u16);
20151i32 __builtin_msa_bnz_w (v4u32);
20152i32 __builtin_msa_bnz_d (v2u64);
20153
20154i32 __builtin_msa_bnz_v (v16u8);
20155
20156v16u8 __builtin_msa_bsel_v (v16u8, v16u8, v16u8);
20157
20158v16u8 __builtin_msa_bseli_b (v16u8, v16u8, imm0_255);
20159
20160v16u8 __builtin_msa_bset_b (v16u8, v16u8);
20161v8u16 __builtin_msa_bset_h (v8u16, v8u16);
20162v4u32 __builtin_msa_bset_w (v4u32, v4u32);
20163v2u64 __builtin_msa_bset_d (v2u64, v2u64);
20164
20165v16u8 __builtin_msa_bseti_b (v16u8, imm0_7);
20166v8u16 __builtin_msa_bseti_h (v8u16, imm0_15);
20167v4u32 __builtin_msa_bseti_w (v4u32, imm0_31);
20168v2u64 __builtin_msa_bseti_d (v2u64, imm0_63);
20169
20170i32 __builtin_msa_bz_b (v16u8);
20171i32 __builtin_msa_bz_h (v8u16);
20172i32 __builtin_msa_bz_w (v4u32);
20173i32 __builtin_msa_bz_d (v2u64);
20174
20175i32 __builtin_msa_bz_v (v16u8);
20176
20177v16i8 __builtin_msa_ceq_b (v16i8, v16i8);
20178v8i16 __builtin_msa_ceq_h (v8i16, v8i16);
20179v4i32 __builtin_msa_ceq_w (v4i32, v4i32);
20180v2i64 __builtin_msa_ceq_d (v2i64, v2i64);
20181
20182v16i8 __builtin_msa_ceqi_b (v16i8, imm_n16_15);
20183v8i16 __builtin_msa_ceqi_h (v8i16, imm_n16_15);
20184v4i32 __builtin_msa_ceqi_w (v4i32, imm_n16_15);
20185v2i64 __builtin_msa_ceqi_d (v2i64, imm_n16_15);
20186
20187i32 __builtin_msa_cfcmsa (imm0_31);
20188
20189v16i8 __builtin_msa_cle_s_b (v16i8, v16i8);
20190v8i16 __builtin_msa_cle_s_h (v8i16, v8i16);
20191v4i32 __builtin_msa_cle_s_w (v4i32, v4i32);
20192v2i64 __builtin_msa_cle_s_d (v2i64, v2i64);
20193
20194v16i8 __builtin_msa_cle_u_b (v16u8, v16u8);
20195v8i16 __builtin_msa_cle_u_h (v8u16, v8u16);
20196v4i32 __builtin_msa_cle_u_w (v4u32, v4u32);
20197v2i64 __builtin_msa_cle_u_d (v2u64, v2u64);
20198
20199v16i8 __builtin_msa_clei_s_b (v16i8, imm_n16_15);
20200v8i16 __builtin_msa_clei_s_h (v8i16, imm_n16_15);
20201v4i32 __builtin_msa_clei_s_w (v4i32, imm_n16_15);
20202v2i64 __builtin_msa_clei_s_d (v2i64, imm_n16_15);
20203
20204v16i8 __builtin_msa_clei_u_b (v16u8, imm0_31);
20205v8i16 __builtin_msa_clei_u_h (v8u16, imm0_31);
20206v4i32 __builtin_msa_clei_u_w (v4u32, imm0_31);
20207v2i64 __builtin_msa_clei_u_d (v2u64, imm0_31);
20208
20209v16i8 __builtin_msa_clt_s_b (v16i8, v16i8);
20210v8i16 __builtin_msa_clt_s_h (v8i16, v8i16);
20211v4i32 __builtin_msa_clt_s_w (v4i32, v4i32);
20212v2i64 __builtin_msa_clt_s_d (v2i64, v2i64);
20213
20214v16i8 __builtin_msa_clt_u_b (v16u8, v16u8);
20215v8i16 __builtin_msa_clt_u_h (v8u16, v8u16);
20216v4i32 __builtin_msa_clt_u_w (v4u32, v4u32);
20217v2i64 __builtin_msa_clt_u_d (v2u64, v2u64);
20218
20219v16i8 __builtin_msa_clti_s_b (v16i8, imm_n16_15);
20220v8i16 __builtin_msa_clti_s_h (v8i16, imm_n16_15);
20221v4i32 __builtin_msa_clti_s_w (v4i32, imm_n16_15);
20222v2i64 __builtin_msa_clti_s_d (v2i64, imm_n16_15);
20223
20224v16i8 __builtin_msa_clti_u_b (v16u8, imm0_31);
20225v8i16 __builtin_msa_clti_u_h (v8u16, imm0_31);
20226v4i32 __builtin_msa_clti_u_w (v4u32, imm0_31);
20227v2i64 __builtin_msa_clti_u_d (v2u64, imm0_31);
20228
20229i32 __builtin_msa_copy_s_b (v16i8, imm0_15);
20230i32 __builtin_msa_copy_s_h (v8i16, imm0_7);
20231i32 __builtin_msa_copy_s_w (v4i32, imm0_3);
20232i64 __builtin_msa_copy_s_d (v2i64, imm0_1);
20233
20234u32 __builtin_msa_copy_u_b (v16i8, imm0_15);
20235u32 __builtin_msa_copy_u_h (v8i16, imm0_7);
20236u32 __builtin_msa_copy_u_w (v4i32, imm0_3);
20237u64 __builtin_msa_copy_u_d (v2i64, imm0_1);
20238
20239void __builtin_msa_ctcmsa (imm0_31, i32);
20240
20241v16i8 __builtin_msa_div_s_b (v16i8, v16i8);
20242v8i16 __builtin_msa_div_s_h (v8i16, v8i16);
20243v4i32 __builtin_msa_div_s_w (v4i32, v4i32);
20244v2i64 __builtin_msa_div_s_d (v2i64, v2i64);
20245
20246v16u8 __builtin_msa_div_u_b (v16u8, v16u8);
20247v8u16 __builtin_msa_div_u_h (v8u16, v8u16);
20248v4u32 __builtin_msa_div_u_w (v4u32, v4u32);
20249v2u64 __builtin_msa_div_u_d (v2u64, v2u64);
20250
20251v8i16 __builtin_msa_dotp_s_h (v16i8, v16i8);
20252v4i32 __builtin_msa_dotp_s_w (v8i16, v8i16);
20253v2i64 __builtin_msa_dotp_s_d (v4i32, v4i32);
20254
20255v8u16 __builtin_msa_dotp_u_h (v16u8, v16u8);
20256v4u32 __builtin_msa_dotp_u_w (v8u16, v8u16);
20257v2u64 __builtin_msa_dotp_u_d (v4u32, v4u32);
20258
20259v8i16 __builtin_msa_dpadd_s_h (v8i16, v16i8, v16i8);
20260v4i32 __builtin_msa_dpadd_s_w (v4i32, v8i16, v8i16);
20261v2i64 __builtin_msa_dpadd_s_d (v2i64, v4i32, v4i32);
20262
20263v8u16 __builtin_msa_dpadd_u_h (v8u16, v16u8, v16u8);
20264v4u32 __builtin_msa_dpadd_u_w (v4u32, v8u16, v8u16);
20265v2u64 __builtin_msa_dpadd_u_d (v2u64, v4u32, v4u32);
20266
20267v8i16 __builtin_msa_dpsub_s_h (v8i16, v16i8, v16i8);
20268v4i32 __builtin_msa_dpsub_s_w (v4i32, v8i16, v8i16);
20269v2i64 __builtin_msa_dpsub_s_d (v2i64, v4i32, v4i32);
20270
20271v8i16 __builtin_msa_dpsub_u_h (v8i16, v16u8, v16u8);
20272v4i32 __builtin_msa_dpsub_u_w (v4i32, v8u16, v8u16);
20273v2i64 __builtin_msa_dpsub_u_d (v2i64, v4u32, v4u32);
20274
20275v4f32 __builtin_msa_fadd_w (v4f32, v4f32);
20276v2f64 __builtin_msa_fadd_d (v2f64, v2f64);
20277
20278v4i32 __builtin_msa_fcaf_w (v4f32, v4f32);
20279v2i64 __builtin_msa_fcaf_d (v2f64, v2f64);
20280
20281v4i32 __builtin_msa_fceq_w (v4f32, v4f32);
20282v2i64 __builtin_msa_fceq_d (v2f64, v2f64);
20283
20284v4i32 __builtin_msa_fclass_w (v4f32);
20285v2i64 __builtin_msa_fclass_d (v2f64);
20286
20287v4i32 __builtin_msa_fcle_w (v4f32, v4f32);
20288v2i64 __builtin_msa_fcle_d (v2f64, v2f64);
20289
20290v4i32 __builtin_msa_fclt_w (v4f32, v4f32);
20291v2i64 __builtin_msa_fclt_d (v2f64, v2f64);
20292
20293v4i32 __builtin_msa_fcne_w (v4f32, v4f32);
20294v2i64 __builtin_msa_fcne_d (v2f64, v2f64);
20295
20296v4i32 __builtin_msa_fcor_w (v4f32, v4f32);
20297v2i64 __builtin_msa_fcor_d (v2f64, v2f64);
20298
20299v4i32 __builtin_msa_fcueq_w (v4f32, v4f32);
20300v2i64 __builtin_msa_fcueq_d (v2f64, v2f64);
20301
20302v4i32 __builtin_msa_fcule_w (v4f32, v4f32);
20303v2i64 __builtin_msa_fcule_d (v2f64, v2f64);
20304
20305v4i32 __builtin_msa_fcult_w (v4f32, v4f32);
20306v2i64 __builtin_msa_fcult_d (v2f64, v2f64);
20307
20308v4i32 __builtin_msa_fcun_w (v4f32, v4f32);
20309v2i64 __builtin_msa_fcun_d (v2f64, v2f64);
20310
20311v4i32 __builtin_msa_fcune_w (v4f32, v4f32);
20312v2i64 __builtin_msa_fcune_d (v2f64, v2f64);
20313
20314v4f32 __builtin_msa_fdiv_w (v4f32, v4f32);
20315v2f64 __builtin_msa_fdiv_d (v2f64, v2f64);
20316
20317v8i16 __builtin_msa_fexdo_h (v4f32, v4f32);
20318v4f32 __builtin_msa_fexdo_w (v2f64, v2f64);
20319
20320v4f32 __builtin_msa_fexp2_w (v4f32, v4i32);
20321v2f64 __builtin_msa_fexp2_d (v2f64, v2i64);
20322
20323v4f32 __builtin_msa_fexupl_w (v8i16);
20324v2f64 __builtin_msa_fexupl_d (v4f32);
20325
20326v4f32 __builtin_msa_fexupr_w (v8i16);
20327v2f64 __builtin_msa_fexupr_d (v4f32);
20328
20329v4f32 __builtin_msa_ffint_s_w (v4i32);
20330v2f64 __builtin_msa_ffint_s_d (v2i64);
20331
20332v4f32 __builtin_msa_ffint_u_w (v4u32);
20333v2f64 __builtin_msa_ffint_u_d (v2u64);
20334
20335v4f32 __builtin_msa_ffql_w (v8i16);
20336v2f64 __builtin_msa_ffql_d (v4i32);
20337
20338v4f32 __builtin_msa_ffqr_w (v8i16);
20339v2f64 __builtin_msa_ffqr_d (v4i32);
20340
20341v16i8 __builtin_msa_fill_b (i32);
20342v8i16 __builtin_msa_fill_h (i32);
20343v4i32 __builtin_msa_fill_w (i32);
20344v2i64 __builtin_msa_fill_d (i64);
20345
20346v4f32 __builtin_msa_flog2_w (v4f32);
20347v2f64 __builtin_msa_flog2_d (v2f64);
20348
20349v4f32 __builtin_msa_fmadd_w (v4f32, v4f32, v4f32);
20350v2f64 __builtin_msa_fmadd_d (v2f64, v2f64, v2f64);
20351
20352v4f32 __builtin_msa_fmax_w (v4f32, v4f32);
20353v2f64 __builtin_msa_fmax_d (v2f64, v2f64);
20354
20355v4f32 __builtin_msa_fmax_a_w (v4f32, v4f32);
20356v2f64 __builtin_msa_fmax_a_d (v2f64, v2f64);
20357
20358v4f32 __builtin_msa_fmin_w (v4f32, v4f32);
20359v2f64 __builtin_msa_fmin_d (v2f64, v2f64);
20360
20361v4f32 __builtin_msa_fmin_a_w (v4f32, v4f32);
20362v2f64 __builtin_msa_fmin_a_d (v2f64, v2f64);
20363
20364v4f32 __builtin_msa_fmsub_w (v4f32, v4f32, v4f32);
20365v2f64 __builtin_msa_fmsub_d (v2f64, v2f64, v2f64);
20366
20367v4f32 __builtin_msa_fmul_w (v4f32, v4f32);
20368v2f64 __builtin_msa_fmul_d (v2f64, v2f64);
20369
20370v4f32 __builtin_msa_frint_w (v4f32);
20371v2f64 __builtin_msa_frint_d (v2f64);
20372
20373v4f32 __builtin_msa_frcp_w (v4f32);
20374v2f64 __builtin_msa_frcp_d (v2f64);
20375
20376v4f32 __builtin_msa_frsqrt_w (v4f32);
20377v2f64 __builtin_msa_frsqrt_d (v2f64);
20378
20379v4i32 __builtin_msa_fsaf_w (v4f32, v4f32);
20380v2i64 __builtin_msa_fsaf_d (v2f64, v2f64);
20381
20382v4i32 __builtin_msa_fseq_w (v4f32, v4f32);
20383v2i64 __builtin_msa_fseq_d (v2f64, v2f64);
20384
20385v4i32 __builtin_msa_fsle_w (v4f32, v4f32);
20386v2i64 __builtin_msa_fsle_d (v2f64, v2f64);
20387
20388v4i32 __builtin_msa_fslt_w (v4f32, v4f32);
20389v2i64 __builtin_msa_fslt_d (v2f64, v2f64);
20390
20391v4i32 __builtin_msa_fsne_w (v4f32, v4f32);
20392v2i64 __builtin_msa_fsne_d (v2f64, v2f64);
20393
20394v4i32 __builtin_msa_fsor_w (v4f32, v4f32);
20395v2i64 __builtin_msa_fsor_d (v2f64, v2f64);
20396
20397v4f32 __builtin_msa_fsqrt_w (v4f32);
20398v2f64 __builtin_msa_fsqrt_d (v2f64);
20399
20400v4f32 __builtin_msa_fsub_w (v4f32, v4f32);
20401v2f64 __builtin_msa_fsub_d (v2f64, v2f64);
20402
20403v4i32 __builtin_msa_fsueq_w (v4f32, v4f32);
20404v2i64 __builtin_msa_fsueq_d (v2f64, v2f64);
20405
20406v4i32 __builtin_msa_fsule_w (v4f32, v4f32);
20407v2i64 __builtin_msa_fsule_d (v2f64, v2f64);
20408
20409v4i32 __builtin_msa_fsult_w (v4f32, v4f32);
20410v2i64 __builtin_msa_fsult_d (v2f64, v2f64);
20411
20412v4i32 __builtin_msa_fsun_w (v4f32, v4f32);
20413v2i64 __builtin_msa_fsun_d (v2f64, v2f64);
20414
20415v4i32 __builtin_msa_fsune_w (v4f32, v4f32);
20416v2i64 __builtin_msa_fsune_d (v2f64, v2f64);
20417
20418v4i32 __builtin_msa_ftint_s_w (v4f32);
20419v2i64 __builtin_msa_ftint_s_d (v2f64);
20420
20421v4u32 __builtin_msa_ftint_u_w (v4f32);
20422v2u64 __builtin_msa_ftint_u_d (v2f64);
20423
20424v8i16 __builtin_msa_ftq_h (v4f32, v4f32);
20425v4i32 __builtin_msa_ftq_w (v2f64, v2f64);
20426
20427v4i32 __builtin_msa_ftrunc_s_w (v4f32);
20428v2i64 __builtin_msa_ftrunc_s_d (v2f64);
20429
20430v4u32 __builtin_msa_ftrunc_u_w (v4f32);
20431v2u64 __builtin_msa_ftrunc_u_d (v2f64);
20432
20433v8i16 __builtin_msa_hadd_s_h (v16i8, v16i8);
20434v4i32 __builtin_msa_hadd_s_w (v8i16, v8i16);
20435v2i64 __builtin_msa_hadd_s_d (v4i32, v4i32);
20436
20437v8u16 __builtin_msa_hadd_u_h (v16u8, v16u8);
20438v4u32 __builtin_msa_hadd_u_w (v8u16, v8u16);
20439v2u64 __builtin_msa_hadd_u_d (v4u32, v4u32);
20440
20441v8i16 __builtin_msa_hsub_s_h (v16i8, v16i8);
20442v4i32 __builtin_msa_hsub_s_w (v8i16, v8i16);
20443v2i64 __builtin_msa_hsub_s_d (v4i32, v4i32);
20444
20445v8i16 __builtin_msa_hsub_u_h (v16u8, v16u8);
20446v4i32 __builtin_msa_hsub_u_w (v8u16, v8u16);
20447v2i64 __builtin_msa_hsub_u_d (v4u32, v4u32);
20448
20449v16i8 __builtin_msa_ilvev_b (v16i8, v16i8);
20450v8i16 __builtin_msa_ilvev_h (v8i16, v8i16);
20451v4i32 __builtin_msa_ilvev_w (v4i32, v4i32);
20452v2i64 __builtin_msa_ilvev_d (v2i64, v2i64);
20453
20454v16i8 __builtin_msa_ilvl_b (v16i8, v16i8);
20455v8i16 __builtin_msa_ilvl_h (v8i16, v8i16);
20456v4i32 __builtin_msa_ilvl_w (v4i32, v4i32);
20457v2i64 __builtin_msa_ilvl_d (v2i64, v2i64);
20458
20459v16i8 __builtin_msa_ilvod_b (v16i8, v16i8);
20460v8i16 __builtin_msa_ilvod_h (v8i16, v8i16);
20461v4i32 __builtin_msa_ilvod_w (v4i32, v4i32);
20462v2i64 __builtin_msa_ilvod_d (v2i64, v2i64);
20463
20464v16i8 __builtin_msa_ilvr_b (v16i8, v16i8);
20465v8i16 __builtin_msa_ilvr_h (v8i16, v8i16);
20466v4i32 __builtin_msa_ilvr_w (v4i32, v4i32);
20467v2i64 __builtin_msa_ilvr_d (v2i64, v2i64);
20468
20469v16i8 __builtin_msa_insert_b (v16i8, imm0_15, i32);
20470v8i16 __builtin_msa_insert_h (v8i16, imm0_7, i32);
20471v4i32 __builtin_msa_insert_w (v4i32, imm0_3, i32);
20472v2i64 __builtin_msa_insert_d (v2i64, imm0_1, i64);
20473
20474v16i8 __builtin_msa_insve_b (v16i8, imm0_15, v16i8);
20475v8i16 __builtin_msa_insve_h (v8i16, imm0_7, v8i16);
20476v4i32 __builtin_msa_insve_w (v4i32, imm0_3, v4i32);
20477v2i64 __builtin_msa_insve_d (v2i64, imm0_1, v2i64);
20478
20479v16i8 __builtin_msa_ld_b (const void *, imm_n512_511);
20480v8i16 __builtin_msa_ld_h (const void *, imm_n1024_1022);
20481v4i32 __builtin_msa_ld_w (const void *, imm_n2048_2044);
20482v2i64 __builtin_msa_ld_d (const void *, imm_n4096_4088);
20483
20484v16i8 __builtin_msa_ldi_b (imm_n512_511);
20485v8i16 __builtin_msa_ldi_h (imm_n512_511);
20486v4i32 __builtin_msa_ldi_w (imm_n512_511);
20487v2i64 __builtin_msa_ldi_d (imm_n512_511);
20488
20489v8i16 __builtin_msa_madd_q_h (v8i16, v8i16, v8i16);
20490v4i32 __builtin_msa_madd_q_w (v4i32, v4i32, v4i32);
20491
20492v8i16 __builtin_msa_maddr_q_h (v8i16, v8i16, v8i16);
20493v4i32 __builtin_msa_maddr_q_w (v4i32, v4i32, v4i32);
20494
20495v16i8 __builtin_msa_maddv_b (v16i8, v16i8, v16i8);
20496v8i16 __builtin_msa_maddv_h (v8i16, v8i16, v8i16);
20497v4i32 __builtin_msa_maddv_w (v4i32, v4i32, v4i32);
20498v2i64 __builtin_msa_maddv_d (v2i64, v2i64, v2i64);
20499
20500v16i8 __builtin_msa_max_a_b (v16i8, v16i8);
20501v8i16 __builtin_msa_max_a_h (v8i16, v8i16);
20502v4i32 __builtin_msa_max_a_w (v4i32, v4i32);
20503v2i64 __builtin_msa_max_a_d (v2i64, v2i64);
20504
20505v16i8 __builtin_msa_max_s_b (v16i8, v16i8);
20506v8i16 __builtin_msa_max_s_h (v8i16, v8i16);
20507v4i32 __builtin_msa_max_s_w (v4i32, v4i32);
20508v2i64 __builtin_msa_max_s_d (v2i64, v2i64);
20509
20510v16u8 __builtin_msa_max_u_b (v16u8, v16u8);
20511v8u16 __builtin_msa_max_u_h (v8u16, v8u16);
20512v4u32 __builtin_msa_max_u_w (v4u32, v4u32);
20513v2u64 __builtin_msa_max_u_d (v2u64, v2u64);
20514
20515v16i8 __builtin_msa_maxi_s_b (v16i8, imm_n16_15);
20516v8i16 __builtin_msa_maxi_s_h (v8i16, imm_n16_15);
20517v4i32 __builtin_msa_maxi_s_w (v4i32, imm_n16_15);
20518v2i64 __builtin_msa_maxi_s_d (v2i64, imm_n16_15);
20519
20520v16u8 __builtin_msa_maxi_u_b (v16u8, imm0_31);
20521v8u16 __builtin_msa_maxi_u_h (v8u16, imm0_31);
20522v4u32 __builtin_msa_maxi_u_w (v4u32, imm0_31);
20523v2u64 __builtin_msa_maxi_u_d (v2u64, imm0_31);
20524
20525v16i8 __builtin_msa_min_a_b (v16i8, v16i8);
20526v8i16 __builtin_msa_min_a_h (v8i16, v8i16);
20527v4i32 __builtin_msa_min_a_w (v4i32, v4i32);
20528v2i64 __builtin_msa_min_a_d (v2i64, v2i64);
20529
20530v16i8 __builtin_msa_min_s_b (v16i8, v16i8);
20531v8i16 __builtin_msa_min_s_h (v8i16, v8i16);
20532v4i32 __builtin_msa_min_s_w (v4i32, v4i32);
20533v2i64 __builtin_msa_min_s_d (v2i64, v2i64);
20534
20535v16u8 __builtin_msa_min_u_b (v16u8, v16u8);
20536v8u16 __builtin_msa_min_u_h (v8u16, v8u16);
20537v4u32 __builtin_msa_min_u_w (v4u32, v4u32);
20538v2u64 __builtin_msa_min_u_d (v2u64, v2u64);
20539
20540v16i8 __builtin_msa_mini_s_b (v16i8, imm_n16_15);
20541v8i16 __builtin_msa_mini_s_h (v8i16, imm_n16_15);
20542v4i32 __builtin_msa_mini_s_w (v4i32, imm_n16_15);
20543v2i64 __builtin_msa_mini_s_d (v2i64, imm_n16_15);
20544
20545v16u8 __builtin_msa_mini_u_b (v16u8, imm0_31);
20546v8u16 __builtin_msa_mini_u_h (v8u16, imm0_31);
20547v4u32 __builtin_msa_mini_u_w (v4u32, imm0_31);
20548v2u64 __builtin_msa_mini_u_d (v2u64, imm0_31);
20549
20550v16i8 __builtin_msa_mod_s_b (v16i8, v16i8);
20551v8i16 __builtin_msa_mod_s_h (v8i16, v8i16);
20552v4i32 __builtin_msa_mod_s_w (v4i32, v4i32);
20553v2i64 __builtin_msa_mod_s_d (v2i64, v2i64);
20554
20555v16u8 __builtin_msa_mod_u_b (v16u8, v16u8);
20556v8u16 __builtin_msa_mod_u_h (v8u16, v8u16);
20557v4u32 __builtin_msa_mod_u_w (v4u32, v4u32);
20558v2u64 __builtin_msa_mod_u_d (v2u64, v2u64);
20559
20560v16i8 __builtin_msa_move_v (v16i8);
20561
20562v8i16 __builtin_msa_msub_q_h (v8i16, v8i16, v8i16);
20563v4i32 __builtin_msa_msub_q_w (v4i32, v4i32, v4i32);
20564
20565v8i16 __builtin_msa_msubr_q_h (v8i16, v8i16, v8i16);
20566v4i32 __builtin_msa_msubr_q_w (v4i32, v4i32, v4i32);
20567
20568v16i8 __builtin_msa_msubv_b (v16i8, v16i8, v16i8);
20569v8i16 __builtin_msa_msubv_h (v8i16, v8i16, v8i16);
20570v4i32 __builtin_msa_msubv_w (v4i32, v4i32, v4i32);
20571v2i64 __builtin_msa_msubv_d (v2i64, v2i64, v2i64);
20572
20573v8i16 __builtin_msa_mul_q_h (v8i16, v8i16);
20574v4i32 __builtin_msa_mul_q_w (v4i32, v4i32);
20575
20576v8i16 __builtin_msa_mulr_q_h (v8i16, v8i16);
20577v4i32 __builtin_msa_mulr_q_w (v4i32, v4i32);
20578
20579v16i8 __builtin_msa_mulv_b (v16i8, v16i8);
20580v8i16 __builtin_msa_mulv_h (v8i16, v8i16);
20581v4i32 __builtin_msa_mulv_w (v4i32, v4i32);
20582v2i64 __builtin_msa_mulv_d (v2i64, v2i64);
20583
20584v16i8 __builtin_msa_nloc_b (v16i8);
20585v8i16 __builtin_msa_nloc_h (v8i16);
20586v4i32 __builtin_msa_nloc_w (v4i32);
20587v2i64 __builtin_msa_nloc_d (v2i64);
20588
20589v16i8 __builtin_msa_nlzc_b (v16i8);
20590v8i16 __builtin_msa_nlzc_h (v8i16);
20591v4i32 __builtin_msa_nlzc_w (v4i32);
20592v2i64 __builtin_msa_nlzc_d (v2i64);
20593
20594v16u8 __builtin_msa_nor_v (v16u8, v16u8);
20595
20596v16u8 __builtin_msa_nori_b (v16u8, imm0_255);
20597
20598v16u8 __builtin_msa_or_v (v16u8, v16u8);
20599
20600v16u8 __builtin_msa_ori_b (v16u8, imm0_255);
20601
20602v16i8 __builtin_msa_pckev_b (v16i8, v16i8);
20603v8i16 __builtin_msa_pckev_h (v8i16, v8i16);
20604v4i32 __builtin_msa_pckev_w (v4i32, v4i32);
20605v2i64 __builtin_msa_pckev_d (v2i64, v2i64);
20606
20607v16i8 __builtin_msa_pckod_b (v16i8, v16i8);
20608v8i16 __builtin_msa_pckod_h (v8i16, v8i16);
20609v4i32 __builtin_msa_pckod_w (v4i32, v4i32);
20610v2i64 __builtin_msa_pckod_d (v2i64, v2i64);
20611
20612v16i8 __builtin_msa_pcnt_b (v16i8);
20613v8i16 __builtin_msa_pcnt_h (v8i16);
20614v4i32 __builtin_msa_pcnt_w (v4i32);
20615v2i64 __builtin_msa_pcnt_d (v2i64);
20616
20617v16i8 __builtin_msa_sat_s_b (v16i8, imm0_7);
20618v8i16 __builtin_msa_sat_s_h (v8i16, imm0_15);
20619v4i32 __builtin_msa_sat_s_w (v4i32, imm0_31);
20620v2i64 __builtin_msa_sat_s_d (v2i64, imm0_63);
20621
20622v16u8 __builtin_msa_sat_u_b (v16u8, imm0_7);
20623v8u16 __builtin_msa_sat_u_h (v8u16, imm0_15);
20624v4u32 __builtin_msa_sat_u_w (v4u32, imm0_31);
20625v2u64 __builtin_msa_sat_u_d (v2u64, imm0_63);
20626
20627v16i8 __builtin_msa_shf_b (v16i8, imm0_255);
20628v8i16 __builtin_msa_shf_h (v8i16, imm0_255);
20629v4i32 __builtin_msa_shf_w (v4i32, imm0_255);
20630
20631v16i8 __builtin_msa_sld_b (v16i8, v16i8, i32);
20632v8i16 __builtin_msa_sld_h (v8i16, v8i16, i32);
20633v4i32 __builtin_msa_sld_w (v4i32, v4i32, i32);
20634v2i64 __builtin_msa_sld_d (v2i64, v2i64, i32);
20635
20636v16i8 __builtin_msa_sldi_b (v16i8, v16i8, imm0_15);
20637v8i16 __builtin_msa_sldi_h (v8i16, v8i16, imm0_7);
20638v4i32 __builtin_msa_sldi_w (v4i32, v4i32, imm0_3);
20639v2i64 __builtin_msa_sldi_d (v2i64, v2i64, imm0_1);
20640
20641v16i8 __builtin_msa_sll_b (v16i8, v16i8);
20642v8i16 __builtin_msa_sll_h (v8i16, v8i16);
20643v4i32 __builtin_msa_sll_w (v4i32, v4i32);
20644v2i64 __builtin_msa_sll_d (v2i64, v2i64);
20645
20646v16i8 __builtin_msa_slli_b (v16i8, imm0_7);
20647v8i16 __builtin_msa_slli_h (v8i16, imm0_15);
20648v4i32 __builtin_msa_slli_w (v4i32, imm0_31);
20649v2i64 __builtin_msa_slli_d (v2i64, imm0_63);
20650
20651v16i8 __builtin_msa_splat_b (v16i8, i32);
20652v8i16 __builtin_msa_splat_h (v8i16, i32);
20653v4i32 __builtin_msa_splat_w (v4i32, i32);
20654v2i64 __builtin_msa_splat_d (v2i64, i32);
20655
20656v16i8 __builtin_msa_splati_b (v16i8, imm0_15);
20657v8i16 __builtin_msa_splati_h (v8i16, imm0_7);
20658v4i32 __builtin_msa_splati_w (v4i32, imm0_3);
20659v2i64 __builtin_msa_splati_d (v2i64, imm0_1);
20660
20661v16i8 __builtin_msa_sra_b (v16i8, v16i8);
20662v8i16 __builtin_msa_sra_h (v8i16, v8i16);
20663v4i32 __builtin_msa_sra_w (v4i32, v4i32);
20664v2i64 __builtin_msa_sra_d (v2i64, v2i64);
20665
20666v16i8 __builtin_msa_srai_b (v16i8, imm0_7);
20667v8i16 __builtin_msa_srai_h (v8i16, imm0_15);
20668v4i32 __builtin_msa_srai_w (v4i32, imm0_31);
20669v2i64 __builtin_msa_srai_d (v2i64, imm0_63);
20670
20671v16i8 __builtin_msa_srar_b (v16i8, v16i8);
20672v8i16 __builtin_msa_srar_h (v8i16, v8i16);
20673v4i32 __builtin_msa_srar_w (v4i32, v4i32);
20674v2i64 __builtin_msa_srar_d (v2i64, v2i64);
20675
20676v16i8 __builtin_msa_srari_b (v16i8, imm0_7);
20677v8i16 __builtin_msa_srari_h (v8i16, imm0_15);
20678v4i32 __builtin_msa_srari_w (v4i32, imm0_31);
20679v2i64 __builtin_msa_srari_d (v2i64, imm0_63);
20680
20681v16i8 __builtin_msa_srl_b (v16i8, v16i8);
20682v8i16 __builtin_msa_srl_h (v8i16, v8i16);
20683v4i32 __builtin_msa_srl_w (v4i32, v4i32);
20684v2i64 __builtin_msa_srl_d (v2i64, v2i64);
20685
20686v16i8 __builtin_msa_srli_b (v16i8, imm0_7);
20687v8i16 __builtin_msa_srli_h (v8i16, imm0_15);
20688v4i32 __builtin_msa_srli_w (v4i32, imm0_31);
20689v2i64 __builtin_msa_srli_d (v2i64, imm0_63);
20690
20691v16i8 __builtin_msa_srlr_b (v16i8, v16i8);
20692v8i16 __builtin_msa_srlr_h (v8i16, v8i16);
20693v4i32 __builtin_msa_srlr_w (v4i32, v4i32);
20694v2i64 __builtin_msa_srlr_d (v2i64, v2i64);
20695
20696v16i8 __builtin_msa_srlri_b (v16i8, imm0_7);
20697v8i16 __builtin_msa_srlri_h (v8i16, imm0_15);
20698v4i32 __builtin_msa_srlri_w (v4i32, imm0_31);
20699v2i64 __builtin_msa_srlri_d (v2i64, imm0_63);
20700
20701void __builtin_msa_st_b (v16i8, void *, imm_n512_511);
20702void __builtin_msa_st_h (v8i16, void *, imm_n1024_1022);
20703void __builtin_msa_st_w (v4i32, void *, imm_n2048_2044);
20704void __builtin_msa_st_d (v2i64, void *, imm_n4096_4088);
20705
20706v16i8 __builtin_msa_subs_s_b (v16i8, v16i8);
20707v8i16 __builtin_msa_subs_s_h (v8i16, v8i16);
20708v4i32 __builtin_msa_subs_s_w (v4i32, v4i32);
20709v2i64 __builtin_msa_subs_s_d (v2i64, v2i64);
20710
20711v16u8 __builtin_msa_subs_u_b (v16u8, v16u8);
20712v8u16 __builtin_msa_subs_u_h (v8u16, v8u16);
20713v4u32 __builtin_msa_subs_u_w (v4u32, v4u32);
20714v2u64 __builtin_msa_subs_u_d (v2u64, v2u64);
20715
20716v16u8 __builtin_msa_subsus_u_b (v16u8, v16i8);
20717v8u16 __builtin_msa_subsus_u_h (v8u16, v8i16);
20718v4u32 __builtin_msa_subsus_u_w (v4u32, v4i32);
20719v2u64 __builtin_msa_subsus_u_d (v2u64, v2i64);
20720
20721v16i8 __builtin_msa_subsuu_s_b (v16u8, v16u8);
20722v8i16 __builtin_msa_subsuu_s_h (v8u16, v8u16);
20723v4i32 __builtin_msa_subsuu_s_w (v4u32, v4u32);
20724v2i64 __builtin_msa_subsuu_s_d (v2u64, v2u64);
20725
20726v16i8 __builtin_msa_subv_b (v16i8, v16i8);
20727v8i16 __builtin_msa_subv_h (v8i16, v8i16);
20728v4i32 __builtin_msa_subv_w (v4i32, v4i32);
20729v2i64 __builtin_msa_subv_d (v2i64, v2i64);
20730
20731v16i8 __builtin_msa_subvi_b (v16i8, imm0_31);
20732v8i16 __builtin_msa_subvi_h (v8i16, imm0_31);
20733v4i32 __builtin_msa_subvi_w (v4i32, imm0_31);
20734v2i64 __builtin_msa_subvi_d (v2i64, imm0_31);
20735
20736v16i8 __builtin_msa_vshf_b (v16i8, v16i8, v16i8);
20737v8i16 __builtin_msa_vshf_h (v8i16, v8i16, v8i16);
20738v4i32 __builtin_msa_vshf_w (v4i32, v4i32, v4i32);
20739v2i64 __builtin_msa_vshf_d (v2i64, v2i64, v2i64);
20740
20741v16u8 __builtin_msa_xor_v (v16u8, v16u8);
20742
20743v16u8 __builtin_msa_xori_b (v16u8, imm0_255);
20744@end smallexample
20745
20746@node Other MIPS Built-in Functions
20747@subsection Other MIPS Built-in Functions
20748
20749GCC provides other MIPS-specific built-in functions:
20750
20751@table @code
20752@item void __builtin_mips_cache (int @var{op}, const volatile void *@var{addr})
20753Insert a @samp{cache} instruction with operands @var{op} and @var{addr}.
20754GCC defines the preprocessor macro @code{___GCC_HAVE_BUILTIN_MIPS_CACHE}
20755when this function is available.
20756
20757@item unsigned int __builtin_mips_get_fcsr (void)
20758@itemx void __builtin_mips_set_fcsr (unsigned int @var{value})
20759Get and set the contents of the floating-point control and status register
20760(FPU control register 31). These functions are only available in hard-float
20761code but can be called in both MIPS16 and non-MIPS16 contexts.
20762
20763@code{__builtin_mips_set_fcsr} can be used to change any bit of the
20764register except the condition codes, which GCC assumes are preserved.
20765@end table
20766
20767@node MSP430 Built-in Functions
20768@subsection MSP430 Built-in Functions
20769
20770GCC provides a couple of special builtin functions to aid in the
20771writing of interrupt handlers in C.
20772
20773@table @code
20774@item __bic_SR_register_on_exit (int @var{mask})
20775This clears the indicated bits in the saved copy of the status register
20776currently residing on the stack. This only works inside interrupt
20777handlers and the changes to the status register will only take affect
20778once the handler returns.
20779
20780@item __bis_SR_register_on_exit (int @var{mask})
20781This sets the indicated bits in the saved copy of the status register
20782currently residing on the stack. This only works inside interrupt
20783handlers and the changes to the status register will only take affect
20784once the handler returns.
20785
20786@item __delay_cycles (long long @var{cycles})
20787This inserts an instruction sequence that takes exactly @var{cycles}
20788cycles (between 0 and about 17E9) to complete. The inserted sequence
20789may use jumps, loops, or no-ops, and does not interfere with any other
20790instructions. Note that @var{cycles} must be a compile-time constant
20791integer - that is, you must pass a number, not a variable that may be
20792optimized to a constant later. The number of cycles delayed by this
20793builtin is exact.
20794@end table
20795
20796@node NDS32 Built-in Functions
20797@subsection NDS32 Built-in Functions
20798
20799These built-in functions are available for the NDS32 target:
20800
f25efe50 20801@defbuiltin{void __builtin_nds32_isync (int *@var{addr})}
d77de738
ML
20802Insert an ISYNC instruction into the instruction stream where
20803@var{addr} is an instruction address for serialization.
f25efe50 20804@enddefbuiltin
d77de738 20805
f25efe50 20806@defbuiltin{void __builtin_nds32_isb (void)}
d77de738 20807Insert an ISB instruction into the instruction stream.
f25efe50 20808@enddefbuiltin
d77de738 20809
f25efe50 20810@defbuiltin{int __builtin_nds32_mfsr (int @var{sr})}
d77de738 20811Return the content of a system register which is mapped by @var{sr}.
f25efe50 20812@enddefbuiltin
d77de738 20813
f25efe50 20814@defbuiltin{int __builtin_nds32_mfusr (int @var{usr})}
d77de738 20815Return the content of a user space register which is mapped by @var{usr}.
f25efe50 20816@enddefbuiltin
d77de738 20817
f25efe50 20818@defbuiltin{void __builtin_nds32_mtsr (int @var{value}, int @var{sr})}
d77de738 20819Move the @var{value} to a system register which is mapped by @var{sr}.
f25efe50 20820@enddefbuiltin
d77de738 20821
f25efe50 20822@defbuiltin{void __builtin_nds32_mtusr (int @var{value}, int @var{usr})}
d77de738 20823Move the @var{value} to a user space register which is mapped by @var{usr}.
f25efe50 20824@enddefbuiltin
d77de738 20825
f25efe50 20826@defbuiltin{void __builtin_nds32_setgie_en (void)}
d77de738 20827Enable global interrupt.
f25efe50 20828@enddefbuiltin
d77de738 20829
f25efe50 20830@defbuiltin{void __builtin_nds32_setgie_dis (void)}
d77de738 20831Disable global interrupt.
f25efe50 20832@enddefbuiltin
d77de738 20833
c09471fb
RS
20834@node Nvidia PTX Built-in Functions
20835@subsection Nvidia PTX Built-in Functions
20836
20837These built-in functions are available for the Nvidia PTX target:
20838
ff99671a 20839@defbuiltin{{unsigned int} __builtin_nvptx_brev (unsigned int @var{x})}
c09471fb 20840Reverse the bit order of a 32-bit unsigned integer.
c09471fb
RS
20841@enddefbuiltin
20842
ff99671a 20843@defbuiltin{{unsigned long long} __builtin_nvptx_brevll (unsigned long long @var{x})}
c09471fb
RS
20844Reverse the bit order of a 64-bit unsigned integer.
20845@enddefbuiltin
20846
d77de738
ML
20847@node Basic PowerPC Built-in Functions
20848@subsection Basic PowerPC Built-in Functions
20849
20850@menu
20851* Basic PowerPC Built-in Functions Available on all Configurations::
20852* Basic PowerPC Built-in Functions Available on ISA 2.05::
20853* Basic PowerPC Built-in Functions Available on ISA 2.06::
20854* Basic PowerPC Built-in Functions Available on ISA 2.07::
20855* Basic PowerPC Built-in Functions Available on ISA 3.0::
20856* Basic PowerPC Built-in Functions Available on ISA 3.1::
20857@end menu
20858
20859This section describes PowerPC built-in functions that do not require
20860the inclusion of any special header files to declare prototypes or
20861provide macro definitions. The sections that follow describe
20862additional PowerPC built-in functions.
20863
20864@node Basic PowerPC Built-in Functions Available on all Configurations
20865@subsubsection Basic PowerPC Built-in Functions Available on all Configurations
20866
f25efe50 20867@defbuiltin{void __builtin_cpu_init (void)}
d77de738
ML
20868This function is a @code{nop} on the PowerPC platform and is included solely
20869to maintain API compatibility with the x86 builtins.
f25efe50 20870@enddefbuiltin
d77de738 20871
f25efe50 20872@defbuiltin{int __builtin_cpu_is (const char *@var{cpuname})}
d77de738
ML
20873This function returns a value of @code{1} if the run-time CPU is of type
20874@var{cpuname} and returns @code{0} otherwise
20875
20876The @code{__builtin_cpu_is} function requires GLIBC 2.23 or newer
20877which exports the hardware capability bits. GCC defines the macro
20878@code{__BUILTIN_CPU_SUPPORTS__} if the @code{__builtin_cpu_supports}
20879built-in function is fully supported.
20880
20881If GCC was configured to use a GLIBC before 2.23, the built-in
20882function @code{__builtin_cpu_is} always returns a 0 and the compiler
20883issues a warning.
20884
20885The following CPU names can be detected:
20886
20887@table @samp
20888@item power10
20889IBM POWER10 Server CPU.
20890@item power9
20891IBM POWER9 Server CPU.
20892@item power8
20893IBM POWER8 Server CPU.
20894@item power7
20895IBM POWER7 Server CPU.
20896@item power6x
20897IBM POWER6 Server CPU (RAW mode).
20898@item power6
20899IBM POWER6 Server CPU (Architected mode).
20900@item power5+
20901IBM POWER5+ Server CPU.
20902@item power5
20903IBM POWER5 Server CPU.
20904@item ppc970
20905IBM 970 Server CPU (ie, Apple G5).
20906@item power4
20907IBM POWER4 Server CPU.
20908@item ppca2
20909IBM A2 64-bit Embedded CPU
20910@item ppc476
20911IBM PowerPC 476FP 32-bit Embedded CPU.
20912@item ppc464
20913IBM PowerPC 464 32-bit Embedded CPU.
20914@item ppc440
20915PowerPC 440 32-bit Embedded CPU.
20916@item ppc405
20917PowerPC 405 32-bit Embedded CPU.
20918@item ppc-cell-be
20919IBM PowerPC Cell Broadband Engine Architecture CPU.
20920@end table
20921
20922Here is an example:
20923@smallexample
20924#ifdef __BUILTIN_CPU_SUPPORTS__
20925 if (__builtin_cpu_is ("power8"))
20926 @{
20927 do_power8 (); // POWER8 specific implementation.
20928 @}
20929 else
20930#endif
20931 @{
20932 do_generic (); // Generic implementation.
20933 @}
20934@end smallexample
f25efe50 20935@enddefbuiltin
d77de738 20936
f25efe50 20937@defbuiltin{int __builtin_cpu_supports (const char *@var{feature})}
d77de738
ML
20938This function returns a value of @code{1} if the run-time CPU supports the HWCAP
20939feature @var{feature} and returns @code{0} otherwise.
20940
20941The @code{__builtin_cpu_supports} function requires GLIBC 2.23 or
20942newer which exports the hardware capability bits. GCC defines the
20943macro @code{__BUILTIN_CPU_SUPPORTS__} if the
20944@code{__builtin_cpu_supports} built-in function is fully supported.
20945
20946If GCC was configured to use a GLIBC before 2.23, the built-in
20947function @code{__builtin_cpu_supports} always returns a 0 and the
20948compiler issues a warning.
20949
20950The following features can be
20951detected:
20952
20953@table @samp
20954@item 4xxmac
209554xx CPU has a Multiply Accumulator.
20956@item altivec
20957CPU has a SIMD/Vector Unit.
20958@item arch_2_05
20959CPU supports ISA 2.05 (eg, POWER6)
20960@item arch_2_06
20961CPU supports ISA 2.06 (eg, POWER7)
20962@item arch_2_07
20963CPU supports ISA 2.07 (eg, POWER8)
20964@item arch_3_00
20965CPU supports ISA 3.0 (eg, POWER9)
20966@item arch_3_1
20967CPU supports ISA 3.1 (eg, POWER10)
20968@item archpmu
20969CPU supports the set of compatible performance monitoring events.
20970@item booke
20971CPU supports the Embedded ISA category.
20972@item cellbe
20973CPU has a CELL broadband engine.
20974@item darn
20975CPU supports the @code{darn} (deliver a random number) instruction.
20976@item dfp
20977CPU has a decimal floating point unit.
20978@item dscr
20979CPU supports the data stream control register.
20980@item ebb
20981CPU supports event base branching.
20982@item efpdouble
20983CPU has a SPE double precision floating point unit.
20984@item efpsingle
20985CPU has a SPE single precision floating point unit.
20986@item fpu
20987CPU has a floating point unit.
20988@item htm
20989CPU has hardware transaction memory instructions.
20990@item htm-nosc
20991Kernel aborts hardware transactions when a syscall is made.
20992@item htm-no-suspend
20993CPU supports hardware transaction memory but does not support the
20994@code{tsuspend.} instruction.
20995@item ic_snoop
20996CPU supports icache snooping capabilities.
20997@item ieee128
20998CPU supports 128-bit IEEE binary floating point instructions.
20999@item isel
21000CPU supports the integer select instruction.
21001@item mma
21002CPU supports the matrix-multiply assist instructions.
21003@item mmu
21004CPU has a memory management unit.
21005@item notb
21006CPU does not have a timebase (eg, 601 and 403gx).
21007@item pa6t
21008CPU supports the PA Semi 6T CORE ISA.
21009@item power4
21010CPU supports ISA 2.00 (eg, POWER4)
21011@item power5
21012CPU supports ISA 2.02 (eg, POWER5)
21013@item power5+
21014CPU supports ISA 2.03 (eg, POWER5+)
21015@item power6x
21016CPU supports ISA 2.05 (eg, POWER6) extended opcodes mffgpr and mftgpr.
21017@item ppc32
21018CPU supports 32-bit mode execution.
21019@item ppc601
21020CPU supports the old POWER ISA (eg, 601)
21021@item ppc64
21022CPU supports 64-bit mode execution.
21023@item ppcle
21024CPU supports a little-endian mode that uses address swizzling.
21025@item scv
21026Kernel supports system call vectored.
21027@item smt
21028CPU support simultaneous multi-threading.
21029@item spe
21030CPU has a signal processing extension unit.
21031@item tar
21032CPU supports the target address register.
21033@item true_le
21034CPU supports true little-endian mode.
21035@item ucache
21036CPU has unified I/D cache.
21037@item vcrypto
21038CPU supports the vector cryptography instructions.
21039@item vsx
21040CPU supports the vector-scalar extension.
21041@end table
21042
21043Here is an example:
21044@smallexample
21045#ifdef __BUILTIN_CPU_SUPPORTS__
21046 if (__builtin_cpu_supports ("fpu"))
21047 @{
21048 asm("fadd %0,%1,%2" : "=d"(dst) : "d"(src1), "d"(src2));
21049 @}
21050 else
21051#endif
21052 @{
21053 dst = __fadd (src1, src2); // Software FP addition function.
21054 @}
21055@end smallexample
f25efe50 21056@enddefbuiltin
d77de738
ML
21057
21058The following built-in functions are also available on all PowerPC
21059processors:
21060@smallexample
21061uint64_t __builtin_ppc_get_timebase ();
21062unsigned long __builtin_ppc_mftb ();
21063double __builtin_unpack_ibm128 (__ibm128, int);
21064__ibm128 __builtin_pack_ibm128 (double, double);
21065double __builtin_mffs (void);
21066void __builtin_mtfsf (const int, double);
21067void __builtin_mtfsb0 (const int);
21068void __builtin_mtfsb1 (const int);
ef3bbc69 21069double __builtin_set_fpscr_rn (int);
d77de738
ML
21070@end smallexample
21071
21072The @code{__builtin_ppc_get_timebase} and @code{__builtin_ppc_mftb}
21073functions generate instructions to read the Time Base Register. The
21074@code{__builtin_ppc_get_timebase} function may generate multiple
21075instructions and always returns the 64 bits of the Time Base Register.
21076The @code{__builtin_ppc_mftb} function always generates one instruction and
21077returns the Time Base Register value as an unsigned long, throwing away
21078the most significant word on 32-bit environments. The @code{__builtin_mffs}
21079return the value of the FPSCR register. Note, ISA 3.0 supports the
21080@code{__builtin_mffsl()} which permits software to read the control and
21081non-sticky status bits in the FSPCR without the higher latency associated with
21082accessing the sticky status bits. The @code{__builtin_mtfsf} takes a constant
210838-bit integer field mask and a double precision floating point argument
21084and generates the @code{mtfsf} (extended mnemonic) instruction to write new
21085values to selected fields of the FPSCR. The
21086@code{__builtin_mtfsb0} and @code{__builtin_mtfsb1} take the bit to change
21087as an argument. The valid bit range is between 0 and 31. The builtins map to
21088the @code{mtfsb0} and @code{mtfsb1} instructions which take the argument and
21089add 32. Hence these instructions only modify the FPSCR[32:63] bits by
ef3bbc69
CL
21090changing the specified bit to a zero or one respectively.
21091
21092The @code{__builtin_set_fpscr_rn} built-in allows changing both of the floating
21093point rounding mode bits and returning the various FPSCR fields before the RN
21094field is updated. The built-in returns a double consisting of the initial
21095value of the FPSCR fields DRN, VE, OE, UE, ZE, XE, NI, and RN bit positions
21096with all other bits set to zero. The built-in argument is a 2-bit value for the
21097new RN field value. The argument can either be an @code{const int} or stored
21098in a variable. Earlier versions of @code{__builtin_set_fpscr_rn} returned
21099void. A @code{__SET_FPSCR_RN_RETURNS_FPSCR__} macro has been added. If
21100defined, then the @code{__builtin_set_fpscr_rn} built-in returns the FPSCR
21101fields. If not defined, the @code{__builtin_set_fpscr_rn} does not return a
21102value. If the @option{-msoft-float} option is used, the
21103@code{__builtin_set_fpscr_rn} built-in will not return a value.
d77de738
ML
21104
21105@node Basic PowerPC Built-in Functions Available on ISA 2.05
21106@subsubsection Basic PowerPC Built-in Functions Available on ISA 2.05
21107
21108The basic built-in functions described in this section are
21109available on the PowerPC family of processors starting with ISA 2.05
21110or later. Unless specific options are explicitly disabled on the
21111command line, specifying option @option{-mcpu=power6} has the effect of
21112enabling the @option{-mpowerpc64}, @option{-mpowerpc-gpopt},
21113@option{-mpowerpc-gfxopt}, @option{-mmfcrf}, @option{-mpopcntb},
21114@option{-mfprnd}, @option{-mcmpb}, @option{-mhard-dfp}, and
21115@option{-mrecip-precision} options. Specify the
21116@option{-maltivec} option explicitly in
21117combination with the above options if desired.
21118
21119The following functions require option @option{-mcmpb}.
21120@smallexample
21121unsigned long long __builtin_cmpb (unsigned long long int, unsigned long long int);
21122unsigned int __builtin_cmpb (unsigned int, unsigned int);
21123@end smallexample
21124
21125The @code{__builtin_cmpb} function
21126performs a byte-wise compare on the contents of its two arguments,
21127returning the result of the byte-wise comparison as the returned
21128value. For each byte comparison, the corresponding byte of the return
21129value holds 0xff if the input bytes are equal and 0 if the input bytes
21130are not equal. If either of the arguments to this built-in function
21131is wider than 32 bits, the function call expands into the form that
21132expects @code{unsigned long long int} arguments
21133which is only available on 64-bit targets.
21134
21135The following built-in functions are available
21136when hardware decimal floating point
21137(@option{-mhard-dfp}) is available:
21138@smallexample
21139void __builtin_set_fpscr_drn(int);
21140_Decimal64 __builtin_ddedpd (int, _Decimal64);
21141_Decimal128 __builtin_ddedpdq (int, _Decimal128);
21142_Decimal64 __builtin_denbcd (int, _Decimal64);
21143_Decimal128 __builtin_denbcdq (int, _Decimal128);
21144_Decimal64 __builtin_diex (long long, _Decimal64);
21145_Decimal128 _builtin_diexq (long long, _Decimal128);
21146_Decimal64 __builtin_dscli (_Decimal64, int);
21147_Decimal128 __builtin_dscliq (_Decimal128, int);
21148_Decimal64 __builtin_dscri (_Decimal64, int);
21149_Decimal128 __builtin_dscriq (_Decimal128, int);
21150long long __builtin_dxex (_Decimal64);
21151long long __builtin_dxexq (_Decimal128);
21152_Decimal128 __builtin_pack_dec128 (unsigned long long, unsigned long long);
21153unsigned long long __builtin_unpack_dec128 (_Decimal128, int);
21154
21155The @code{__builtin_set_fpscr_drn} builtin allows changing the three decimal
21156floating point rounding mode bits. The argument is a 3-bit value. The
21157argument can either be a @code{const int} or the value can be stored in
21158a variable.
21159The builtin uses the ISA 3.0 instruction @code{mffscdrn} if available.
21160Otherwise the builtin reads the FPSCR, masks the current decimal rounding
21161mode bits out and OR's in the new value.
21162
14a3839c
CL
21163_Decimal64 __builtin_dfp_quantize (_Decimal64, _Decimal64, const int);
21164_Decimal64 __builtin_dfp_quantize (const int, _Decimal64, const int);
21165_Decimal128 __builtin_dfp_quantize (_Decimal128, _Decimal128, const int);
21166_Decimal128 __builtin_dfp_quantize (const int, _Decimal128, const int);
21167
21168The @code{__builtin_dfp_quantize} built-in, converts and rounds the second
21169argument to the form with the exponent as specified by the first
21170argument based on the rounding mode specified by the third argument.
21171If the first argument is a decimal floating point value, its exponent is used
21172for converting and rounding of the second argument. If the first argument is a
211735-bit constant integer value, then the value specifies the exponent to be used
21174when rounding and converting the second argument. The third argument is a
21175two bit constant integer that specifies the rounding mode. The possible modes
21176are: 00 Round to nearest, ties to even; 01 Round toward 0; 10 Round to nearest,
21177ties away from 0; 11 Round according to DRN where DRN is the Decimal Floating
21178point field of the FPSCR.
21179
d77de738
ML
21180@end smallexample
21181
21182The following functions require @option{-mhard-float},
21183@option{-mpowerpc-gfxopt}, and @option{-mpopcntb} options.
21184
21185@smallexample
21186double __builtin_recipdiv (double, double);
21187float __builtin_recipdivf (float, float);
21188double __builtin_rsqrt (double);
21189float __builtin_rsqrtf (float);
21190@end smallexample
21191
21192The @code{vec_rsqrt}, @code{__builtin_rsqrt}, and
21193@code{__builtin_rsqrtf} functions generate multiple instructions to
21194implement the reciprocal sqrt functionality using reciprocal sqrt
21195estimate instructions.
21196
21197The @code{__builtin_recipdiv}, and @code{__builtin_recipdivf}
21198functions generate multiple instructions to implement division using
21199the reciprocal estimate instructions.
21200
21201The following functions require @option{-mhard-float} and
21202@option{-mmultiple} options.
21203
21204The @code{__builtin_unpack_longdouble} function takes a
21205@code{long double} argument and a compile time constant of 0 or 1. If
21206the constant is 0, the first @code{double} within the
21207@code{long double} is returned, otherwise the second @code{double}
21208is returned. The @code{__builtin_unpack_longdouble} function is only
21209available if @code{long double} uses the IBM extended double
21210representation.
21211
21212The @code{__builtin_pack_longdouble} function takes two @code{double}
21213arguments and returns a @code{long double} value that combines the two
21214arguments. The @code{__builtin_pack_longdouble} function is only
21215available if @code{long double} uses the IBM extended double
21216representation.
21217
21218The @code{__builtin_unpack_ibm128} function takes a @code{__ibm128}
21219argument and a compile time constant of 0 or 1. If the constant is 0,
21220the first @code{double} within the @code{__ibm128} is returned,
21221otherwise the second @code{double} is returned.
21222
21223The @code{__builtin_pack_ibm128} function takes two @code{double}
21224arguments and returns a @code{__ibm128} value that combines the two
21225arguments.
21226
21227Additional built-in functions are available for the 64-bit PowerPC
21228family of processors, for efficient use of 128-bit floating point
21229(@code{__float128}) values.
21230
21231@node Basic PowerPC Built-in Functions Available on ISA 2.06
21232@subsubsection Basic PowerPC Built-in Functions Available on ISA 2.06
21233
21234The basic built-in functions described in this section are
21235available on the PowerPC family of processors starting with ISA 2.05
21236or later. Unless specific options are explicitly disabled on the
21237command line, specifying option @option{-mcpu=power7} has the effect of
21238enabling all the same options as for @option{-mcpu=power6} in
21239addition to the @option{-maltivec}, @option{-mpopcntd}, and
21240@option{-mvsx} options.
21241
21242The following basic built-in functions require @option{-mpopcntd}:
21243@smallexample
21244unsigned int __builtin_addg6s (unsigned int, unsigned int);
21245long long __builtin_bpermd (long long, long long);
21246unsigned int __builtin_cbcdtd (unsigned int);
21247unsigned int __builtin_cdtbcd (unsigned int);
21248long long __builtin_divde (long long, long long);
21249unsigned long long __builtin_divdeu (unsigned long long, unsigned long long);
21250int __builtin_divwe (int, int);
21251unsigned int __builtin_divweu (unsigned int, unsigned int);
21252vector __int128 __builtin_pack_vector_int128 (long long, long long);
21253void __builtin_rs6000_speculation_barrier (void);
21254long long __builtin_unpack_vector_int128 (vector __int128, signed char);
21255@end smallexample
21256
21257Of these, the @code{__builtin_divde} and @code{__builtin_divdeu} functions
21258require a 64-bit environment.
21259
21260The following basic built-in functions, which are also supported on
21261x86 targets, require @option{-mfloat128}.
21262@smallexample
21263__float128 __builtin_fabsq (__float128);
21264__float128 __builtin_copysignq (__float128, __float128);
21265__float128 __builtin_infq (void);
21266__float128 __builtin_huge_valq (void);
21267__float128 __builtin_nanq (void);
21268__float128 __builtin_nansq (void);
21269
21270__float128 __builtin_sqrtf128 (__float128);
21271__float128 __builtin_fmaf128 (__float128, __float128, __float128);
21272@end smallexample
21273
21274@node Basic PowerPC Built-in Functions Available on ISA 2.07
21275@subsubsection Basic PowerPC Built-in Functions Available on ISA 2.07
21276
21277The basic built-in functions described in this section are
21278available on the PowerPC family of processors starting with ISA 2.07
21279or later. Unless specific options are explicitly disabled on the
21280command line, specifying option @option{-mcpu=power8} has the effect of
21281enabling all the same options as for @option{-mcpu=power7} in
21282addition to the @option{-mpower8-fusion}, @option{-mpower8-vector},
21283@option{-mcrypto}, @option{-mhtm}, @option{-mquad-memory}, and
21284@option{-mquad-memory-atomic} options.
21285
21286This section intentionally empty.
21287
21288@node Basic PowerPC Built-in Functions Available on ISA 3.0
21289@subsubsection Basic PowerPC Built-in Functions Available on ISA 3.0
21290
21291The basic built-in functions described in this section are
21292available on the PowerPC family of processors starting with ISA 3.0
21293or later. Unless specific options are explicitly disabled on the
21294command line, specifying option @option{-mcpu=power9} has the effect of
21295enabling all the same options as for @option{-mcpu=power8} in
21296addition to the @option{-misel} option.
21297
21298The following built-in functions are available on Linux 64-bit systems
21299that use the ISA 3.0 instruction set (@option{-mcpu=power9}):
21300
f25efe50 21301@defbuiltin{__float128 __builtin_addf128_round_to_odd (__float128, __float128)}
d77de738
ML
21302Perform a 128-bit IEEE floating point add using round to odd as the
21303rounding mode.
f25efe50 21304@enddefbuiltin
d77de738 21305
f25efe50 21306@defbuiltin{__float128 __builtin_subf128_round_to_odd (__float128, __float128)}
d77de738
ML
21307Perform a 128-bit IEEE floating point subtract using round to odd as
21308the rounding mode.
f25efe50 21309@enddefbuiltin
d77de738 21310
f25efe50 21311@defbuiltin{__float128 __builtin_mulf128_round_to_odd (__float128, __float128)}
d77de738
ML
21312Perform a 128-bit IEEE floating point multiply using round to odd as
21313the rounding mode.
f25efe50 21314@enddefbuiltin
d77de738 21315
f25efe50 21316@defbuiltin{__float128 __builtin_divf128_round_to_odd (__float128, __float128)}
d77de738
ML
21317Perform a 128-bit IEEE floating point divide using round to odd as
21318the rounding mode.
f25efe50 21319@enddefbuiltin
d77de738 21320
f25efe50 21321@defbuiltin{__float128 __builtin_sqrtf128_round_to_odd (__float128)}
d77de738
ML
21322Perform a 128-bit IEEE floating point square root using round to odd
21323as the rounding mode.
f25efe50 21324@enddefbuiltin
d77de738 21325
f25efe50 21326@defbuiltin{__float128 __builtin_fmaf128_round_to_odd (__float128, __float128, __float128)}
d77de738
ML
21327Perform a 128-bit IEEE floating point fused multiply and add operation
21328using round to odd as the rounding mode.
f25efe50 21329@enddefbuiltin
d77de738 21330
f25efe50 21331@defbuiltin{double __builtin_truncf128_round_to_odd (__float128)}
d77de738
ML
21332Convert a 128-bit IEEE floating point value to @code{double} using
21333round to odd as the rounding mode.
f25efe50
AA
21334@enddefbuiltin
21335
d77de738
ML
21336
21337The following additional built-in functions are also available for the
21338PowerPC family of processors, starting with ISA 3.0 or later:
d77de738 21339
ff99671a
JJ
21340@defbuiltin{{long long} __builtin_darn (void)}
21341@defbuiltinx{{long long} __builtin_darn_raw (void)}
f25efe50 21342@defbuiltinx{int __builtin_darn_32 (void)}
d77de738
ML
21343The @code{__builtin_darn} and @code{__builtin_darn_raw}
21344functions require a
2134564-bit environment supporting ISA 3.0 or later.
21346The @code{__builtin_darn} function provides a 64-bit conditioned
21347random number. The @code{__builtin_darn_raw} function provides a
2134864-bit raw random number. The @code{__builtin_darn_32} function
21349provides a 32-bit conditioned random number.
f25efe50 21350@enddefbuiltin
d77de738
ML
21351
21352The following additional built-in functions are also available for the
21353PowerPC family of processors, starting with ISA 3.0 or later:
21354
21355@smallexample
21356int __builtin_byte_in_set (unsigned char u, unsigned long long set);
21357int __builtin_byte_in_range (unsigned char u, unsigned int range);
21358int __builtin_byte_in_either_range (unsigned char u, unsigned int ranges);
21359
21360int __builtin_dfp_dtstsfi_lt (unsigned int comparison, _Decimal64 value);
21361int __builtin_dfp_dtstsfi_lt (unsigned int comparison, _Decimal128 value);
21362int __builtin_dfp_dtstsfi_lt_dd (unsigned int comparison, _Decimal64 value);
21363int __builtin_dfp_dtstsfi_lt_td (unsigned int comparison, _Decimal128 value);
21364
21365int __builtin_dfp_dtstsfi_gt (unsigned int comparison, _Decimal64 value);
21366int __builtin_dfp_dtstsfi_gt (unsigned int comparison, _Decimal128 value);
21367int __builtin_dfp_dtstsfi_gt_dd (unsigned int comparison, _Decimal64 value);
21368int __builtin_dfp_dtstsfi_gt_td (unsigned int comparison, _Decimal128 value);
21369
21370int __builtin_dfp_dtstsfi_eq (unsigned int comparison, _Decimal64 value);
21371int __builtin_dfp_dtstsfi_eq (unsigned int comparison, _Decimal128 value);
21372int __builtin_dfp_dtstsfi_eq_dd (unsigned int comparison, _Decimal64 value);
21373int __builtin_dfp_dtstsfi_eq_td (unsigned int comparison, _Decimal128 value);
21374
21375int __builtin_dfp_dtstsfi_ov (unsigned int comparison, _Decimal64 value);
21376int __builtin_dfp_dtstsfi_ov (unsigned int comparison, _Decimal128 value);
21377int __builtin_dfp_dtstsfi_ov_dd (unsigned int comparison, _Decimal64 value);
21378int __builtin_dfp_dtstsfi_ov_td (unsigned int comparison, _Decimal128 value);
21379
21380double __builtin_mffsl(void);
21381
21382@end smallexample
21383The @code{__builtin_byte_in_set} function requires a
2138464-bit environment supporting ISA 3.0 or later. This function returns
21385a non-zero value if and only if its @code{u} argument exactly equals one of
21386the eight bytes contained within its 64-bit @code{set} argument.
21387
21388The @code{__builtin_byte_in_range} and
21389@code{__builtin_byte_in_either_range} require an environment
21390supporting ISA 3.0 or later. For these two functions, the
21391@code{range} argument is encoded as 4 bytes, organized as
21392@code{hi_1:lo_1:hi_2:lo_2}.
21393The @code{__builtin_byte_in_range} function returns a
21394non-zero value if and only if its @code{u} argument is within the
21395range bounded between @code{lo_2} and @code{hi_2} inclusive.
21396The @code{__builtin_byte_in_either_range} function returns non-zero if
21397and only if its @code{u} argument is within either the range bounded
21398between @code{lo_1} and @code{hi_1} inclusive or the range bounded
21399between @code{lo_2} and @code{hi_2} inclusive.
21400
21401The @code{__builtin_dfp_dtstsfi_lt} function returns a non-zero value
21402if and only if the number of signficant digits of its @code{value} argument
21403is less than its @code{comparison} argument. The
21404@code{__builtin_dfp_dtstsfi_lt_dd} and
21405@code{__builtin_dfp_dtstsfi_lt_td} functions behave similarly, but
21406require that the type of the @code{value} argument be
21407@code{__Decimal64} and @code{__Decimal128} respectively.
21408
21409The @code{__builtin_dfp_dtstsfi_gt} function returns a non-zero value
21410if and only if the number of signficant digits of its @code{value} argument
21411is greater than its @code{comparison} argument. The
21412@code{__builtin_dfp_dtstsfi_gt_dd} and
21413@code{__builtin_dfp_dtstsfi_gt_td} functions behave similarly, but
21414require that the type of the @code{value} argument be
21415@code{__Decimal64} and @code{__Decimal128} respectively.
21416
21417The @code{__builtin_dfp_dtstsfi_eq} function returns a non-zero value
21418if and only if the number of signficant digits of its @code{value} argument
21419equals its @code{comparison} argument. The
21420@code{__builtin_dfp_dtstsfi_eq_dd} and
21421@code{__builtin_dfp_dtstsfi_eq_td} functions behave similarly, but
21422require that the type of the @code{value} argument be
21423@code{__Decimal64} and @code{__Decimal128} respectively.
21424
21425The @code{__builtin_dfp_dtstsfi_ov} function returns a non-zero value
21426if and only if its @code{value} argument has an undefined number of
21427significant digits, such as when @code{value} is an encoding of @code{NaN}.
21428The @code{__builtin_dfp_dtstsfi_ov_dd} and
21429@code{__builtin_dfp_dtstsfi_ov_td} functions behave similarly, but
21430require that the type of the @code{value} argument be
21431@code{__Decimal64} and @code{__Decimal128} respectively.
21432
21433The @code{__builtin_mffsl} uses the ISA 3.0 @code{mffsl} instruction to read
21434the FPSCR. The instruction is a lower latency version of the @code{mffs}
21435instruction. If the @code{mffsl} instruction is not available, then the
21436builtin uses the older @code{mffs} instruction to read the FPSCR.
21437
21438@node Basic PowerPC Built-in Functions Available on ISA 3.1
21439@subsubsection Basic PowerPC Built-in Functions Available on ISA 3.1
21440
21441The basic built-in functions described in this section are
21442available on the PowerPC family of processors starting with ISA 3.1.
21443Unless specific options are explicitly disabled on the
21444command line, specifying option @option{-mcpu=power10} has the effect of
21445enabling all the same options as for @option{-mcpu=power9}.
21446
21447The following built-in functions are available on Linux 64-bit systems
21448that use a future architecture instruction set (@option{-mcpu=power10}):
21449
f25efe50
AA
21450@defbuiltin{{unsigned long long} @
21451 __builtin_cfuged (unsigned long long, unsigned long long)}
d77de738
ML
21452Perform a 64-bit centrifuge operation, as if implemented by the
21453@code{cfuged} instruction.
f25efe50 21454@enddefbuiltin
d77de738 21455
f25efe50
AA
21456@defbuiltin{{unsigned long long} @
21457 __builtin_cntlzdm (unsigned long long, unsigned long long)}
d77de738
ML
21458Perform a 64-bit count leading zeros operation under mask, as if
21459implemented by the @code{cntlzdm} instruction.
f25efe50 21460@enddefbuiltin
d77de738 21461
f25efe50
AA
21462@defbuiltin{{unsigned long long} @
21463 __builtin_cnttzdm (unsigned long long, unsigned long long)}
d77de738
ML
21464Perform a 64-bit count trailing zeros operation under mask, as if
21465implemented by the @code{cnttzdm} instruction.
f25efe50 21466@enddefbuiltin
d77de738 21467
f25efe50
AA
21468@defbuiltin{{unsigned long long} @
21469 __builtin_pdepd (unsigned long long, unsigned long long)}
d77de738
ML
21470Perform a 64-bit parallel bits deposit operation, as if implemented by the
21471@code{pdepd} instruction.
f25efe50 21472@enddefbuiltin
d77de738 21473
f25efe50
AA
21474@defbuiltin{{unsigned long long} @
21475 __builtin_pextd (unsigned long long, unsigned long long)}
d77de738
ML
21476Perform a 64-bit parallel bits extract operation, as if implemented by the
21477@code{pextd} instruction.
f25efe50 21478@enddefbuiltin
d77de738 21479
f25efe50
AA
21480@defbuiltin{{vector signed __int128} vsx_xl_sext (signed long long, signed char *)}
21481@defbuiltinx{{vector signed __int128} vsx_xl_sext (signed long long, signed short *)}
21482@defbuiltinx{{vector signed __int128} vsx_xl_sext (signed long long, signed int *)}
21483@defbuiltinx{{vector signed __int128} vsx_xl_sext (signed long long, signed long long *)}
21484@defbuiltinx{{vector unsigned __int128} vsx_xl_zext (signed long long, unsigned char *)}
21485@defbuiltinx{{vector unsigned __int128} vsx_xl_zext (signed long long, unsigned short *)}
21486@defbuiltinx{{vector unsigned __int128} vsx_xl_zext (signed long long, unsigned int *)}
21487@defbuiltinx{{vector unsigned __int128} vsx_xl_zext (signed long long, unsigned long long *)}
d77de738
ML
21488
21489Load (and sign extend) to an __int128 vector, as if implemented by the ISA 3.1
f25efe50
AA
21490@code{lxvrbx}, @code{lxvrhx}, @code{lxvrwx}, and @code{lxvrdx}
21491instructions.
21492@enddefbuiltin
d77de738 21493
f25efe50
AA
21494@defbuiltin{{void} vec_xst_trunc (vector signed __int128, signed long long, signed char *)}
21495@defbuiltinx{{void} vec_xst_trunc (vector signed __int128, signed long long, signed short *)}
21496@defbuiltinx{{void} vec_xst_trunc (vector signed __int128, signed long long, signed int *)}
21497@defbuiltinx{{void} vec_xst_trunc (vector signed __int128, signed long long, signed long long *)}
21498@defbuiltinx{{void} vec_xst_trunc (vector unsigned __int128, signed long long, unsigned char *)}
21499@defbuiltinx{{void} vec_xst_trunc (vector unsigned __int128, signed long long, unsigned short *)}
21500@defbuiltinx{{void} vec_xst_trunc (vector unsigned __int128, signed long long, unsigned int *)}
21501@defbuiltinx{{void} vec_xst_trunc (vector unsigned __int128, signed long long, unsigned long long *)}
d77de738
ML
21502
21503Truncate and store the rightmost element of a vector, as if implemented by the
21504ISA 3.1 @code{stxvrbx}, @code{stxvrhx}, @code{stxvrwx}, and @code{stxvrdx}
21505instructions.
f25efe50 21506@enddefbuiltin
d77de738
ML
21507
21508@node PowerPC AltiVec/VSX Built-in Functions
21509@subsection PowerPC AltiVec/VSX Built-in Functions
21510
21511GCC provides an interface for the PowerPC family of processors to access
21512the AltiVec operations described in Motorola's AltiVec Programming
21513Interface Manual. The interface is made available by including
21514@code{<altivec.h>} and using @option{-maltivec} and
21515@option{-mabi=altivec}. The interface supports the following vector
21516types.
21517
21518@smallexample
21519vector unsigned char
21520vector signed char
21521vector bool char
21522
21523vector unsigned short
21524vector signed short
21525vector bool short
21526vector pixel
21527
21528vector unsigned int
21529vector signed int
21530vector bool int
21531vector float
21532@end smallexample
21533
21534GCC's implementation of the high-level language interface available from
21535C and C++ code differs from Motorola's documentation in several ways.
21536
21537@itemize @bullet
21538
21539@item
21540A vector constant is a list of constant expressions within curly braces.
21541
21542@item
21543A vector initializer requires no cast if the vector constant is of the
21544same type as the variable it is initializing.
21545
21546@item
21547If @code{signed} or @code{unsigned} is omitted, the signedness of the
21548vector type is the default signedness of the base type. The default
21549varies depending on the operating system, so a portable program should
21550always specify the signedness.
21551
21552@item
21553Compiling with @option{-maltivec} adds keywords @code{__vector},
21554@code{vector}, @code{__pixel}, @code{pixel}, @code{__bool} and
21555@code{bool}. When compiling ISO C, the context-sensitive substitution
21556of the keywords @code{vector}, @code{pixel} and @code{bool} is
21557disabled. To use them, you must include @code{<altivec.h>} instead.
21558
21559@item
21560GCC allows using a @code{typedef} name as the type specifier for a
21561vector type, but only under the following circumstances:
21562
21563@itemize @bullet
21564
21565@item
21566When using @code{__vector} instead of @code{vector}; for example,
21567
21568@smallexample
21569typedef signed short int16;
21570__vector int16 data;
21571@end smallexample
21572
21573@item
21574When using @code{vector} in keyword-and-predefine mode; for example,
21575
21576@smallexample
21577typedef signed short int16;
21578vector int16 data;
21579@end smallexample
21580
21581Note that keyword-and-predefine mode is enabled by disabling GNU
21582extensions (e.g., by using @code{-std=c11}) and including
21583@code{<altivec.h>}.
21584@end itemize
21585
21586@item
21587For C, overloaded functions are implemented with macros so the following
21588does not work:
21589
21590@smallexample
21591 vec_add ((vector signed int)@{1, 2, 3, 4@}, foo);
21592@end smallexample
21593
21594@noindent
21595Since @code{vec_add} is a macro, the vector constant in the example
21596is treated as four separate arguments. Wrap the entire argument in
21597parentheses for this to work.
21598@end itemize
21599
21600@emph{Note:} Only the @code{<altivec.h>} interface is supported.
21601Internally, GCC uses built-in functions to achieve the functionality in
21602the aforementioned header file, but they are not supported and are
21603subject to change without notice.
21604
21605GCC complies with the Power Vector Intrinsic Programming Reference (PVIPR),
21606which may be found at
21607@uref{https://openpowerfoundation.org/?resource_lib=power-vector-intrinsic-programming-reference}.
21608Chapter 4 of this document fully documents the vector API interfaces
21609that must be
21610provided by compliant compilers. Programmers should preferentially use
21611the interfaces described therein. However, historically GCC has provided
21612additional interfaces for access to vector instructions. These are
21613briefly described below. Where the PVIPR provides a portable interface,
21614other functions in GCC that provide the same capabilities should be
21615considered deprecated.
21616
21617The PVIPR documents the following overloaded functions:
21618
21619@multitable @columnfractions 0.33 0.33 0.33
21620
21621@item @code{vec_abs}
21622@tab @code{vec_absd}
21623@tab @code{vec_abss}
21624@item @code{vec_add}
21625@tab @code{vec_addc}
21626@tab @code{vec_adde}
21627@item @code{vec_addec}
21628@tab @code{vec_adds}
21629@tab @code{vec_all_eq}
21630@item @code{vec_all_ge}
21631@tab @code{vec_all_gt}
21632@tab @code{vec_all_in}
21633@item @code{vec_all_le}
21634@tab @code{vec_all_lt}
21635@tab @code{vec_all_nan}
21636@item @code{vec_all_ne}
21637@tab @code{vec_all_nge}
21638@tab @code{vec_all_ngt}
21639@item @code{vec_all_nle}
21640@tab @code{vec_all_nlt}
21641@tab @code{vec_all_numeric}
21642@item @code{vec_and}
21643@tab @code{vec_andc}
21644@tab @code{vec_any_eq}
21645@item @code{vec_any_ge}
21646@tab @code{vec_any_gt}
21647@tab @code{vec_any_le}
21648@item @code{vec_any_lt}
21649@tab @code{vec_any_nan}
21650@tab @code{vec_any_ne}
21651@item @code{vec_any_nge}
21652@tab @code{vec_any_ngt}
21653@tab @code{vec_any_nle}
21654@item @code{vec_any_nlt}
21655@tab @code{vec_any_numeric}
21656@tab @code{vec_any_out}
21657@item @code{vec_avg}
21658@tab @code{vec_bperm}
21659@tab @code{vec_ceil}
21660@item @code{vec_cipher_be}
21661@tab @code{vec_cipherlast_be}
21662@tab @code{vec_cmpb}
21663@item @code{vec_cmpeq}
21664@tab @code{vec_cmpge}
21665@tab @code{vec_cmpgt}
21666@item @code{vec_cmple}
21667@tab @code{vec_cmplt}
21668@tab @code{vec_cmpne}
21669@item @code{vec_cmpnez}
21670@tab @code{vec_cntlz}
21671@tab @code{vec_cntlz_lsbb}
21672@item @code{vec_cnttz}
21673@tab @code{vec_cnttz_lsbb}
21674@tab @code{vec_cpsgn}
21675@item @code{vec_ctf}
21676@tab @code{vec_cts}
21677@tab @code{vec_ctu}
21678@item @code{vec_div}
21679@tab @code{vec_double}
21680@tab @code{vec_doublee}
21681@item @code{vec_doubleh}
21682@tab @code{vec_doublel}
21683@tab @code{vec_doubleo}
21684@item @code{vec_eqv}
21685@tab @code{vec_expte}
21686@tab @code{vec_extract}
21687@item @code{vec_extract_exp}
21688@tab @code{vec_extract_fp32_from_shorth}
21689@tab @code{vec_extract_fp32_from_shortl}
21690@item @code{vec_extract_sig}
21691@tab @code{vec_extract_4b}
21692@tab @code{vec_first_match_index}
21693@item @code{vec_first_match_or_eos_index}
21694@tab @code{vec_first_mismatch_index}
21695@tab @code{vec_first_mismatch_or_eos_index}
21696@item @code{vec_float}
21697@tab @code{vec_float2}
21698@tab @code{vec_floate}
21699@item @code{vec_floato}
21700@tab @code{vec_floor}
21701@tab @code{vec_gb}
21702@item @code{vec_insert}
21703@tab @code{vec_insert_exp}
21704@tab @code{vec_insert4b}
21705@item @code{vec_ld}
21706@tab @code{vec_lde}
21707@tab @code{vec_ldl}
21708@item @code{vec_loge}
21709@tab @code{vec_madd}
21710@tab @code{vec_madds}
21711@item @code{vec_max}
21712@tab @code{vec_mergee}
21713@tab @code{vec_mergeh}
21714@item @code{vec_mergel}
21715@tab @code{vec_mergeo}
21716@tab @code{vec_mfvscr}
21717@item @code{vec_min}
21718@tab @code{vec_mradds}
21719@tab @code{vec_msub}
21720@item @code{vec_msum}
21721@tab @code{vec_msums}
21722@tab @code{vec_mtvscr}
21723@item @code{vec_mul}
21724@tab @code{vec_mule}
21725@tab @code{vec_mulo}
21726@item @code{vec_nabs}
21727@tab @code{vec_nand}
21728@tab @code{vec_ncipher_be}
21729@item @code{vec_ncipherlast_be}
21730@tab @code{vec_nearbyint}
21731@tab @code{vec_neg}
21732@item @code{vec_nmadd}
21733@tab @code{vec_nmsub}
21734@tab @code{vec_nor}
21735@item @code{vec_or}
21736@tab @code{vec_orc}
21737@tab @code{vec_pack}
21738@item @code{vec_pack_to_short_fp32}
21739@tab @code{vec_packpx}
21740@tab @code{vec_packs}
21741@item @code{vec_packsu}
21742@tab @code{vec_parity_lsbb}
21743@tab @code{vec_perm}
21744@item @code{vec_permxor}
21745@tab @code{vec_pmsum_be}
21746@tab @code{vec_popcnt}
21747@item @code{vec_re}
21748@tab @code{vec_recipdiv}
21749@tab @code{vec_revb}
21750@item @code{vec_reve}
21751@tab @code{vec_rint}
21752@tab @code{vec_rl}
21753@item @code{vec_rlmi}
21754@tab @code{vec_rlnm}
21755@tab @code{vec_round}
21756@item @code{vec_rsqrt}
21757@tab @code{vec_rsqrte}
21758@tab @code{vec_sbox_be}
21759@item @code{vec_sel}
21760@tab @code{vec_shasigma_be}
21761@tab @code{vec_signed}
21762@item @code{vec_signed2}
21763@tab @code{vec_signede}
21764@tab @code{vec_signedo}
21765@item @code{vec_sl}
21766@tab @code{vec_sld}
21767@tab @code{vec_sldw}
21768@item @code{vec_sll}
21769@tab @code{vec_slo}
21770@tab @code{vec_slv}
21771@item @code{vec_splat}
21772@tab @code{vec_splat_s8}
21773@tab @code{vec_splat_s16}
21774@item @code{vec_splat_s32}
21775@tab @code{vec_splat_u8}
21776@tab @code{vec_splat_u16}
21777@item @code{vec_splat_u32}
21778@tab @code{vec_splats}
21779@tab @code{vec_sqrt}
21780@item @code{vec_sr}
21781@tab @code{vec_sra}
21782@tab @code{vec_srl}
21783@item @code{vec_sro}
21784@tab @code{vec_srv}
21785@tab @code{vec_st}
21786@item @code{vec_ste}
21787@tab @code{vec_stl}
21788@tab @code{vec_sub}
21789@item @code{vec_subc}
21790@tab @code{vec_sube}
21791@tab @code{vec_subec}
21792@item @code{vec_subs}
21793@tab @code{vec_sum2s}
21794@tab @code{vec_sum4s}
21795@item @code{vec_sums}
21796@tab @code{vec_test_data_class}
21797@tab @code{vec_trunc}
21798@item @code{vec_unpackh}
21799@tab @code{vec_unpackl}
21800@tab @code{vec_unsigned}
21801@item @code{vec_unsigned2}
21802@tab @code{vec_unsignede}
21803@tab @code{vec_unsignedo}
21804@item @code{vec_xl}
21805@tab @code{vec_xl_be}
21806@tab @code{vec_xl_len}
21807@item @code{vec_xl_len_r}
21808@tab @code{vec_xor}
21809@tab @code{vec_xst}
21810@item @code{vec_xst_be}
21811@tab @code{vec_xst_len}
21812@tab @code{vec_xst_len_r}
21813
21814@end multitable
21815
21816@menu
21817* PowerPC AltiVec Built-in Functions on ISA 2.05::
21818* PowerPC AltiVec Built-in Functions Available on ISA 2.06::
21819* PowerPC AltiVec Built-in Functions Available on ISA 2.07::
21820* PowerPC AltiVec Built-in Functions Available on ISA 3.0::
21821* PowerPC AltiVec Built-in Functions Available on ISA 3.1::
21822@end menu
21823
21824@node PowerPC AltiVec Built-in Functions on ISA 2.05
21825@subsubsection PowerPC AltiVec Built-in Functions on ISA 2.05
21826
21827The following interfaces are supported for the generic and specific
21828AltiVec operations and the AltiVec predicates. In cases where there
21829is a direct mapping between generic and specific operations, only the
21830generic names are shown here, although the specific operations can also
21831be used.
21832
21833Arguments that are documented as @code{const int} require literal
21834integral values within the range required for that operation.
21835
21836Only functions excluded from the PVIPR are listed here.
21837
21838@smallexample
21839void vec_dss (const int);
21840
21841void vec_dssall (void);
21842
21843void vec_dst (const vector unsigned char *, int, const int);
21844void vec_dst (const vector signed char *, int, const int);
21845void vec_dst (const vector bool char *, int, const int);
21846void vec_dst (const vector unsigned short *, int, const int);
21847void vec_dst (const vector signed short *, int, const int);
21848void vec_dst (const vector bool short *, int, const int);
21849void vec_dst (const vector pixel *, int, const int);
21850void vec_dst (const vector unsigned int *, int, const int);
21851void vec_dst (const vector signed int *, int, const int);
21852void vec_dst (const vector bool int *, int, const int);
21853void vec_dst (const vector float *, int, const int);
21854void vec_dst (const unsigned char *, int, const int);
21855void vec_dst (const signed char *, int, const int);
21856void vec_dst (const unsigned short *, int, const int);
21857void vec_dst (const short *, int, const int);
21858void vec_dst (const unsigned int *, int, const int);
21859void vec_dst (const int *, int, const int);
21860void vec_dst (const float *, int, const int);
21861
21862void vec_dstst (const vector unsigned char *, int, const int);
21863void vec_dstst (const vector signed char *, int, const int);
21864void vec_dstst (const vector bool char *, int, const int);
21865void vec_dstst (const vector unsigned short *, int, const int);
21866void vec_dstst (const vector signed short *, int, const int);
21867void vec_dstst (const vector bool short *, int, const int);
21868void vec_dstst (const vector pixel *, int, const int);
21869void vec_dstst (const vector unsigned int *, int, const int);
21870void vec_dstst (const vector signed int *, int, const int);
21871void vec_dstst (const vector bool int *, int, const int);
21872void vec_dstst (const vector float *, int, const int);
21873void vec_dstst (const unsigned char *, int, const int);
21874void vec_dstst (const signed char *, int, const int);
21875void vec_dstst (const unsigned short *, int, const int);
21876void vec_dstst (const short *, int, const int);
21877void vec_dstst (const unsigned int *, int, const int);
21878void vec_dstst (const int *, int, const int);
21879void vec_dstst (const unsigned long *, int, const int);
21880void vec_dstst (const long *, int, const int);
21881void vec_dstst (const float *, int, const int);
21882
21883void vec_dststt (const vector unsigned char *, int, const int);
21884void vec_dststt (const vector signed char *, int, const int);
21885void vec_dststt (const vector bool char *, int, const int);
21886void vec_dststt (const vector unsigned short *, int, const int);
21887void vec_dststt (const vector signed short *, int, const int);
21888void vec_dststt (const vector bool short *, int, const int);
21889void vec_dststt (const vector pixel *, int, const int);
21890void vec_dststt (const vector unsigned int *, int, const int);
21891void vec_dststt (const vector signed int *, int, const int);
21892void vec_dststt (const vector bool int *, int, const int);
21893void vec_dststt (const vector float *, int, const int);
21894void vec_dststt (const unsigned char *, int, const int);
21895void vec_dststt (const signed char *, int, const int);
21896void vec_dststt (const unsigned short *, int, const int);
21897void vec_dststt (const short *, int, const int);
21898void vec_dststt (const unsigned int *, int, const int);
21899void vec_dststt (const int *, int, const int);
21900void vec_dststt (const float *, int, const int);
21901
21902void vec_dstt (const vector unsigned char *, int, const int);
21903void vec_dstt (const vector signed char *, int, const int);
21904void vec_dstt (const vector bool char *, int, const int);
21905void vec_dstt (const vector unsigned short *, int, const int);
21906void vec_dstt (const vector signed short *, int, const int);
21907void vec_dstt (const vector bool short *, int, const int);
21908void vec_dstt (const vector pixel *, int, const int);
21909void vec_dstt (const vector unsigned int *, int, const int);
21910void vec_dstt (const vector signed int *, int, const int);
21911void vec_dstt (const vector bool int *, int, const int);
21912void vec_dstt (const vector float *, int, const int);
21913void vec_dstt (const unsigned char *, int, const int);
21914void vec_dstt (const signed char *, int, const int);
21915void vec_dstt (const unsigned short *, int, const int);
21916void vec_dstt (const short *, int, const int);
21917void vec_dstt (const unsigned int *, int, const int);
21918void vec_dstt (const int *, int, const int);
21919void vec_dstt (const float *, int, const int);
21920
21921vector signed char vec_lvebx (int, char *);
21922vector unsigned char vec_lvebx (int, unsigned char *);
21923
21924vector signed short vec_lvehx (int, short *);
21925vector unsigned short vec_lvehx (int, unsigned short *);
21926
21927vector float vec_lvewx (int, float *);
21928vector signed int vec_lvewx (int, int *);
21929vector unsigned int vec_lvewx (int, unsigned int *);
21930
21931vector unsigned char vec_lvsl (int, const unsigned char *);
21932vector unsigned char vec_lvsl (int, const signed char *);
21933vector unsigned char vec_lvsl (int, const unsigned short *);
21934vector unsigned char vec_lvsl (int, const short *);
21935vector unsigned char vec_lvsl (int, const unsigned int *);
21936vector unsigned char vec_lvsl (int, const int *);
21937vector unsigned char vec_lvsl (int, const float *);
21938
21939vector unsigned char vec_lvsr (int, const unsigned char *);
21940vector unsigned char vec_lvsr (int, const signed char *);
21941vector unsigned char vec_lvsr (int, const unsigned short *);
21942vector unsigned char vec_lvsr (int, const short *);
21943vector unsigned char vec_lvsr (int, const unsigned int *);
21944vector unsigned char vec_lvsr (int, const int *);
21945vector unsigned char vec_lvsr (int, const float *);
21946
21947void vec_stvebx (vector signed char, int, signed char *);
21948void vec_stvebx (vector unsigned char, int, unsigned char *);
21949void vec_stvebx (vector bool char, int, signed char *);
21950void vec_stvebx (vector bool char, int, unsigned char *);
21951
21952void vec_stvehx (vector signed short, int, short *);
21953void vec_stvehx (vector unsigned short, int, unsigned short *);
21954void vec_stvehx (vector bool short, int, short *);
21955void vec_stvehx (vector bool short, int, unsigned short *);
21956
21957void vec_stvewx (vector float, int, float *);
21958void vec_stvewx (vector signed int, int, int *);
21959void vec_stvewx (vector unsigned int, int, unsigned int *);
21960void vec_stvewx (vector bool int, int, int *);
21961void vec_stvewx (vector bool int, int, unsigned int *);
21962
21963vector float vec_vaddfp (vector float, vector float);
21964
21965vector signed char vec_vaddsbs (vector bool char, vector signed char);
21966vector signed char vec_vaddsbs (vector signed char, vector bool char);
21967vector signed char vec_vaddsbs (vector signed char, vector signed char);
21968
21969vector signed short vec_vaddshs (vector bool short, vector signed short);
21970vector signed short vec_vaddshs (vector signed short, vector bool short);
21971vector signed short vec_vaddshs (vector signed short, vector signed short);
21972
21973vector signed int vec_vaddsws (vector bool int, vector signed int);
21974vector signed int vec_vaddsws (vector signed int, vector bool int);
21975vector signed int vec_vaddsws (vector signed int, vector signed int);
21976
21977vector signed char vec_vaddubm (vector bool char, vector signed char);
21978vector signed char vec_vaddubm (vector signed char, vector bool char);
21979vector signed char vec_vaddubm (vector signed char, vector signed char);
21980vector unsigned char vec_vaddubm (vector bool char, vector unsigned char);
21981vector unsigned char vec_vaddubm (vector unsigned char, vector bool char);
21982vector unsigned char vec_vaddubm (vector unsigned char, vector unsigned char);
21983
21984vector unsigned char vec_vaddubs (vector bool char, vector unsigned char);
21985vector unsigned char vec_vaddubs (vector unsigned char, vector bool char);
21986vector unsigned char vec_vaddubs (vector unsigned char, vector unsigned char);
21987
21988vector signed short vec_vadduhm (vector bool short, vector signed short);
21989vector signed short vec_vadduhm (vector signed short, vector bool short);
21990vector signed short vec_vadduhm (vector signed short, vector signed short);
21991vector unsigned short vec_vadduhm (vector bool short, vector unsigned short);
21992vector unsigned short vec_vadduhm (vector unsigned short, vector bool short);
21993vector unsigned short vec_vadduhm (vector unsigned short, vector unsigned short);
21994
21995vector unsigned short vec_vadduhs (vector bool short, vector unsigned short);
21996vector unsigned short vec_vadduhs (vector unsigned short, vector bool short);
21997vector unsigned short vec_vadduhs (vector unsigned short, vector unsigned short);
21998
21999vector signed int vec_vadduwm (vector bool int, vector signed int);
22000vector signed int vec_vadduwm (vector signed int, vector bool int);
22001vector signed int vec_vadduwm (vector signed int, vector signed int);
22002vector unsigned int vec_vadduwm (vector bool int, vector unsigned int);
22003vector unsigned int vec_vadduwm (vector unsigned int, vector bool int);
22004vector unsigned int vec_vadduwm (vector unsigned int, vector unsigned int);
22005
22006vector unsigned int vec_vadduws (vector bool int, vector unsigned int);
22007vector unsigned int vec_vadduws (vector unsigned int, vector bool int);
22008vector unsigned int vec_vadduws (vector unsigned int, vector unsigned int);
22009
22010vector signed char vec_vavgsb (vector signed char, vector signed char);
22011
22012vector signed short vec_vavgsh (vector signed short, vector signed short);
22013
22014vector signed int vec_vavgsw (vector signed int, vector signed int);
22015
22016vector unsigned char vec_vavgub (vector unsigned char, vector unsigned char);
22017
22018vector unsigned short vec_vavguh (vector unsigned short, vector unsigned short);
22019
22020vector unsigned int vec_vavguw (vector unsigned int, vector unsigned int);
22021
22022vector float vec_vcfsx (vector signed int, const int);
22023
22024vector float vec_vcfux (vector unsigned int, const int);
22025
22026vector bool int vec_vcmpeqfp (vector float, vector float);
22027
22028vector bool char vec_vcmpequb (vector signed char, vector signed char);
22029vector bool char vec_vcmpequb (vector unsigned char, vector unsigned char);
22030
22031vector bool short vec_vcmpequh (vector signed short, vector signed short);
22032vector bool short vec_vcmpequh (vector unsigned short, vector unsigned short);
22033
22034vector bool int vec_vcmpequw (vector signed int, vector signed int);
22035vector bool int vec_vcmpequw (vector unsigned int, vector unsigned int);
22036
22037vector bool int vec_vcmpgtfp (vector float, vector float);
22038
22039vector bool char vec_vcmpgtsb (vector signed char, vector signed char);
22040
22041vector bool short vec_vcmpgtsh (vector signed short, vector signed short);
22042
22043vector bool int vec_vcmpgtsw (vector signed int, vector signed int);
22044
22045vector bool char vec_vcmpgtub (vector unsigned char, vector unsigned char);
22046
22047vector bool short vec_vcmpgtuh (vector unsigned short, vector unsigned short);
22048
22049vector bool int vec_vcmpgtuw (vector unsigned int, vector unsigned int);
22050
22051vector float vec_vmaxfp (vector float, vector float);
22052
22053vector signed char vec_vmaxsb (vector bool char, vector signed char);
22054vector signed char vec_vmaxsb (vector signed char, vector bool char);
22055vector signed char vec_vmaxsb (vector signed char, vector signed char);
22056
22057vector signed short vec_vmaxsh (vector bool short, vector signed short);
22058vector signed short vec_vmaxsh (vector signed short, vector bool short);
22059vector signed short vec_vmaxsh (vector signed short, vector signed short);
22060
22061vector signed int vec_vmaxsw (vector bool int, vector signed int);
22062vector signed int vec_vmaxsw (vector signed int, vector bool int);
22063vector signed int vec_vmaxsw (vector signed int, vector signed int);
22064
22065vector unsigned char vec_vmaxub (vector bool char, vector unsigned char);
22066vector unsigned char vec_vmaxub (vector unsigned char, vector bool char);
22067vector unsigned char vec_vmaxub (vector unsigned char, vector unsigned char);
22068
22069vector unsigned short vec_vmaxuh (vector bool short, vector unsigned short);
22070vector unsigned short vec_vmaxuh (vector unsigned short, vector bool short);
22071vector unsigned short vec_vmaxuh (vector unsigned short, vector unsigned short);
22072
22073vector unsigned int vec_vmaxuw (vector bool int, vector unsigned int);
22074vector unsigned int vec_vmaxuw (vector unsigned int, vector bool int);
22075vector unsigned int vec_vmaxuw (vector unsigned int, vector unsigned int);
22076
22077vector float vec_vminfp (vector float, vector float);
22078
22079vector signed char vec_vminsb (vector bool char, vector signed char);
22080vector signed char vec_vminsb (vector signed char, vector bool char);
22081vector signed char vec_vminsb (vector signed char, vector signed char);
22082
22083vector signed short vec_vminsh (vector bool short, vector signed short);
22084vector signed short vec_vminsh (vector signed short, vector bool short);
22085vector signed short vec_vminsh (vector signed short, vector signed short);
22086
22087vector signed int vec_vminsw (vector bool int, vector signed int);
22088vector signed int vec_vminsw (vector signed int, vector bool int);
22089vector signed int vec_vminsw (vector signed int, vector signed int);
22090
22091vector unsigned char vec_vminub (vector bool char, vector unsigned char);
22092vector unsigned char vec_vminub (vector unsigned char, vector bool char);
22093vector unsigned char vec_vminub (vector unsigned char, vector unsigned char);
22094
22095vector unsigned short vec_vminuh (vector bool short, vector unsigned short);
22096vector unsigned short vec_vminuh (vector unsigned short, vector bool short);
22097vector unsigned short vec_vminuh (vector unsigned short, vector unsigned short);
22098
22099vector unsigned int vec_vminuw (vector bool int, vector unsigned int);
22100vector unsigned int vec_vminuw (vector unsigned int, vector bool int);
22101vector unsigned int vec_vminuw (vector unsigned int, vector unsigned int);
22102
22103vector bool char vec_vmrghb (vector bool char, vector bool char);
22104vector signed char vec_vmrghb (vector signed char, vector signed char);
22105vector unsigned char vec_vmrghb (vector unsigned char, vector unsigned char);
22106
22107vector bool short vec_vmrghh (vector bool short, vector bool short);
22108vector signed short vec_vmrghh (vector signed short, vector signed short);
22109vector unsigned short vec_vmrghh (vector unsigned short, vector unsigned short);
22110vector pixel vec_vmrghh (vector pixel, vector pixel);
22111
22112vector float vec_vmrghw (vector float, vector float);
22113vector bool int vec_vmrghw (vector bool int, vector bool int);
22114vector signed int vec_vmrghw (vector signed int, vector signed int);
22115vector unsigned int vec_vmrghw (vector unsigned int, vector unsigned int);
22116
22117vector bool char vec_vmrglb (vector bool char, vector bool char);
22118vector signed char vec_vmrglb (vector signed char, vector signed char);
22119vector unsigned char vec_vmrglb (vector unsigned char, vector unsigned char);
22120
22121vector bool short vec_vmrglh (vector bool short, vector bool short);
22122vector signed short vec_vmrglh (vector signed short, vector signed short);
22123vector unsigned short vec_vmrglh (vector unsigned short, vector unsigned short);
22124vector pixel vec_vmrglh (vector pixel, vector pixel);
22125
22126vector float vec_vmrglw (vector float, vector float);
22127vector signed int vec_vmrglw (vector signed int, vector signed int);
22128vector unsigned int vec_vmrglw (vector unsigned int, vector unsigned int);
22129vector bool int vec_vmrglw (vector bool int, vector bool int);
22130
22131vector signed int vec_vmsummbm (vector signed char, vector unsigned char,
22132 vector signed int);
22133
22134vector signed int vec_vmsumshm (vector signed short, vector signed short,
22135 vector signed int);
22136
22137vector signed int vec_vmsumshs (vector signed short, vector signed short,
22138 vector signed int);
22139
22140vector unsigned int vec_vmsumubm (vector unsigned char, vector unsigned char,
22141 vector unsigned int);
22142
22143vector unsigned int vec_vmsumuhm (vector unsigned short, vector unsigned short,
22144 vector unsigned int);
22145
22146vector unsigned int vec_vmsumuhs (vector unsigned short, vector unsigned short,
22147 vector unsigned int);
22148
22149vector signed short vec_vmulesb (vector signed char, vector signed char);
22150
22151vector signed int vec_vmulesh (vector signed short, vector signed short);
22152
22153vector unsigned short vec_vmuleub (vector unsigned char, vector unsigned char);
22154
22155vector unsigned int vec_vmuleuh (vector unsigned short, vector unsigned short);
22156
22157vector signed short vec_vmulosb (vector signed char, vector signed char);
22158
22159vector signed int vec_vmulosh (vector signed short, vector signed short);
22160
22161vector unsigned short vec_vmuloub (vector unsigned char, vector unsigned char);
22162
22163vector unsigned int vec_vmulouh (vector unsigned short, vector unsigned short);
22164
22165vector signed char vec_vpkshss (vector signed short, vector signed short);
22166
22167vector unsigned char vec_vpkshus (vector signed short, vector signed short);
22168
22169vector signed short vec_vpkswss (vector signed int, vector signed int);
22170
22171vector unsigned short vec_vpkswus (vector signed int, vector signed int);
22172
22173vector bool char vec_vpkuhum (vector bool short, vector bool short);
22174vector signed char vec_vpkuhum (vector signed short, vector signed short);
22175vector unsigned char vec_vpkuhum (vector unsigned short, vector unsigned short);
22176
22177vector unsigned char vec_vpkuhus (vector unsigned short, vector unsigned short);
22178
22179vector bool short vec_vpkuwum (vector bool int, vector bool int);
22180vector signed short vec_vpkuwum (vector signed int, vector signed int);
22181vector unsigned short vec_vpkuwum (vector unsigned int, vector unsigned int);
22182
22183vector unsigned short vec_vpkuwus (vector unsigned int, vector unsigned int);
22184
22185vector signed char vec_vrlb (vector signed char, vector unsigned char);
22186vector unsigned char vec_vrlb (vector unsigned char, vector unsigned char);
22187
22188vector signed short vec_vrlh (vector signed short, vector unsigned short);
22189vector unsigned short vec_vrlh (vector unsigned short, vector unsigned short);
22190
22191vector signed int vec_vrlw (vector signed int, vector unsigned int);
22192vector unsigned int vec_vrlw (vector unsigned int, vector unsigned int);
22193
22194vector signed char vec_vslb (vector signed char, vector unsigned char);
22195vector unsigned char vec_vslb (vector unsigned char, vector unsigned char);
22196
22197vector signed short vec_vslh (vector signed short, vector unsigned short);
22198vector unsigned short vec_vslh (vector unsigned short, vector unsigned short);
22199
22200vector signed int vec_vslw (vector signed int, vector unsigned int);
22201vector unsigned int vec_vslw (vector unsigned int, vector unsigned int);
22202
22203vector signed char vec_vspltb (vector signed char, const int);
22204vector unsigned char vec_vspltb (vector unsigned char, const int);
22205vector bool char vec_vspltb (vector bool char, const int);
22206
22207vector bool short vec_vsplth (vector bool short, const int);
22208vector signed short vec_vsplth (vector signed short, const int);
22209vector unsigned short vec_vsplth (vector unsigned short, const int);
22210vector pixel vec_vsplth (vector pixel, const int);
22211
22212vector float vec_vspltw (vector float, const int);
22213vector signed int vec_vspltw (vector signed int, const int);
22214vector unsigned int vec_vspltw (vector unsigned int, const int);
22215vector bool int vec_vspltw (vector bool int, const int);
22216
22217vector signed char vec_vsrab (vector signed char, vector unsigned char);
22218vector unsigned char vec_vsrab (vector unsigned char, vector unsigned char);
22219
22220vector signed short vec_vsrah (vector signed short, vector unsigned short);
22221vector unsigned short vec_vsrah (vector unsigned short, vector unsigned short);
22222
22223vector signed int vec_vsraw (vector signed int, vector unsigned int);
22224vector unsigned int vec_vsraw (vector unsigned int, vector unsigned int);
22225
22226vector signed char vec_vsrb (vector signed char, vector unsigned char);
22227vector unsigned char vec_vsrb (vector unsigned char, vector unsigned char);
22228
22229vector signed short vec_vsrh (vector signed short, vector unsigned short);
22230vector unsigned short vec_vsrh (vector unsigned short, vector unsigned short);
22231
22232vector signed int vec_vsrw (vector signed int, vector unsigned int);
22233vector unsigned int vec_vsrw (vector unsigned int, vector unsigned int);
22234
22235vector float vec_vsubfp (vector float, vector float);
22236
22237vector signed char vec_vsubsbs (vector bool char, vector signed char);
22238vector signed char vec_vsubsbs (vector signed char, vector bool char);
22239vector signed char vec_vsubsbs (vector signed char, vector signed char);
22240
22241vector signed short vec_vsubshs (vector bool short, vector signed short);
22242vector signed short vec_vsubshs (vector signed short, vector bool short);
22243vector signed short vec_vsubshs (vector signed short, vector signed short);
22244
22245vector signed int vec_vsubsws (vector bool int, vector signed int);
22246vector signed int vec_vsubsws (vector signed int, vector bool int);
22247vector signed int vec_vsubsws (vector signed int, vector signed int);
22248
22249vector signed char vec_vsububm (vector bool char, vector signed char);
22250vector signed char vec_vsububm (vector signed char, vector bool char);
22251vector signed char vec_vsububm (vector signed char, vector signed char);
22252vector unsigned char vec_vsububm (vector bool char, vector unsigned char);
22253vector unsigned char vec_vsububm (vector unsigned char, vector bool char);
22254vector unsigned char vec_vsububm (vector unsigned char, vector unsigned char);
22255
22256vector unsigned char vec_vsububs (vector bool char, vector unsigned char);
22257vector unsigned char vec_vsububs (vector unsigned char, vector bool char);
22258vector unsigned char vec_vsububs (vector unsigned char, vector unsigned char);
22259
22260vector signed short vec_vsubuhm (vector bool short, vector signed short);
22261vector signed short vec_vsubuhm (vector signed short, vector bool short);
22262vector signed short vec_vsubuhm (vector signed short, vector signed short);
22263vector unsigned short vec_vsubuhm (vector bool short, vector unsigned short);
22264vector unsigned short vec_vsubuhm (vector unsigned short, vector bool short);
22265vector unsigned short vec_vsubuhm (vector unsigned short, vector unsigned short);
22266
22267vector unsigned short vec_vsubuhs (vector bool short, vector unsigned short);
22268vector unsigned short vec_vsubuhs (vector unsigned short, vector bool short);
22269vector unsigned short vec_vsubuhs (vector unsigned short, vector unsigned short);
22270
22271vector signed int vec_vsubuwm (vector bool int, vector signed int);
22272vector signed int vec_vsubuwm (vector signed int, vector bool int);
22273vector signed int vec_vsubuwm (vector signed int, vector signed int);
22274vector unsigned int vec_vsubuwm (vector bool int, vector unsigned int);
22275vector unsigned int vec_vsubuwm (vector unsigned int, vector bool int);
22276vector unsigned int vec_vsubuwm (vector unsigned int, vector unsigned int);
22277
22278vector unsigned int vec_vsubuws (vector bool int, vector unsigned int);
22279vector unsigned int vec_vsubuws (vector unsigned int, vector bool int);
22280vector unsigned int vec_vsubuws (vector unsigned int, vector unsigned int);
22281
22282vector signed int vec_vsum4sbs (vector signed char, vector signed int);
22283
22284vector signed int vec_vsum4shs (vector signed short, vector signed int);
22285
22286vector unsigned int vec_vsum4ubs (vector unsigned char, vector unsigned int);
22287
22288vector unsigned int vec_vupkhpx (vector pixel);
22289
22290vector bool short vec_vupkhsb (vector bool char);
22291vector signed short vec_vupkhsb (vector signed char);
22292
22293vector bool int vec_vupkhsh (vector bool short);
22294vector signed int vec_vupkhsh (vector signed short);
22295
22296vector unsigned int vec_vupklpx (vector pixel);
22297
22298vector bool short vec_vupklsb (vector bool char);
22299vector signed short vec_vupklsb (vector signed char);
22300
22301vector bool int vec_vupklsh (vector bool short);
22302vector signed int vec_vupklsh (vector signed short);
22303@end smallexample
22304
22305@node PowerPC AltiVec Built-in Functions Available on ISA 2.06
22306@subsubsection PowerPC AltiVec Built-in Functions Available on ISA 2.06
22307
22308The AltiVec built-in functions described in this section are
22309available on the PowerPC family of processors starting with ISA 2.06
22310or later. These are normally enabled by adding @option{-mvsx} to the
22311command line.
22312
22313When @option{-mvsx} is used, the following additional vector types are
22314implemented.
22315
22316@smallexample
22317vector unsigned __int128
22318vector signed __int128
22319vector unsigned long long int
22320vector signed long long int
22321vector double
22322@end smallexample
22323
22324The long long types are only implemented for 64-bit code generation.
22325
22326Only functions excluded from the PVIPR are listed here.
22327
22328@smallexample
22329void vec_dst (const unsigned long *, int, const int);
22330void vec_dst (const long *, int, const int);
22331
22332void vec_dststt (const unsigned long *, int, const int);
22333void vec_dststt (const long *, int, const int);
22334
22335void vec_dstt (const unsigned long *, int, const int);
22336void vec_dstt (const long *, int, const int);
22337
22338vector unsigned char vec_lvsl (int, const unsigned long *);
22339vector unsigned char vec_lvsl (int, const long *);
22340
22341vector unsigned char vec_lvsr (int, const unsigned long *);
22342vector unsigned char vec_lvsr (int, const long *);
22343
22344vector unsigned char vec_lvsl (int, const double *);
22345vector unsigned char vec_lvsr (int, const double *);
22346
22347vector double vec_vsx_ld (int, const vector double *);
22348vector double vec_vsx_ld (int, const double *);
22349vector float vec_vsx_ld (int, const vector float *);
22350vector float vec_vsx_ld (int, const float *);
22351vector bool int vec_vsx_ld (int, const vector bool int *);
22352vector signed int vec_vsx_ld (int, const vector signed int *);
22353vector signed int vec_vsx_ld (int, const int *);
22354vector signed int vec_vsx_ld (int, const long *);
22355vector unsigned int vec_vsx_ld (int, const vector unsigned int *);
22356vector unsigned int vec_vsx_ld (int, const unsigned int *);
22357vector unsigned int vec_vsx_ld (int, const unsigned long *);
22358vector bool short vec_vsx_ld (int, const vector bool short *);
22359vector pixel vec_vsx_ld (int, const vector pixel *);
22360vector signed short vec_vsx_ld (int, const vector signed short *);
22361vector signed short vec_vsx_ld (int, const short *);
22362vector unsigned short vec_vsx_ld (int, const vector unsigned short *);
22363vector unsigned short vec_vsx_ld (int, const unsigned short *);
22364vector bool char vec_vsx_ld (int, const vector bool char *);
22365vector signed char vec_vsx_ld (int, const vector signed char *);
22366vector signed char vec_vsx_ld (int, const signed char *);
22367vector unsigned char vec_vsx_ld (int, const vector unsigned char *);
22368vector unsigned char vec_vsx_ld (int, const unsigned char *);
22369
22370void vec_vsx_st (vector double, int, vector double *);
22371void vec_vsx_st (vector double, int, double *);
22372void vec_vsx_st (vector float, int, vector float *);
22373void vec_vsx_st (vector float, int, float *);
22374void vec_vsx_st (vector signed int, int, vector signed int *);
22375void vec_vsx_st (vector signed int, int, int *);
22376void vec_vsx_st (vector unsigned int, int, vector unsigned int *);
22377void vec_vsx_st (vector unsigned int, int, unsigned int *);
22378void vec_vsx_st (vector bool int, int, vector bool int *);
22379void vec_vsx_st (vector bool int, int, unsigned int *);
22380void vec_vsx_st (vector bool int, int, int *);
22381void vec_vsx_st (vector signed short, int, vector signed short *);
22382void vec_vsx_st (vector signed short, int, short *);
22383void vec_vsx_st (vector unsigned short, int, vector unsigned short *);
22384void vec_vsx_st (vector unsigned short, int, unsigned short *);
22385void vec_vsx_st (vector bool short, int, vector bool short *);
22386void vec_vsx_st (vector bool short, int, unsigned short *);
22387void vec_vsx_st (vector pixel, int, vector pixel *);
22388void vec_vsx_st (vector pixel, int, unsigned short *);
22389void vec_vsx_st (vector pixel, int, short *);
22390void vec_vsx_st (vector bool short, int, short *);
22391void vec_vsx_st (vector signed char, int, vector signed char *);
22392void vec_vsx_st (vector signed char, int, signed char *);
22393void vec_vsx_st (vector unsigned char, int, vector unsigned char *);
22394void vec_vsx_st (vector unsigned char, int, unsigned char *);
22395void vec_vsx_st (vector bool char, int, vector bool char *);
22396void vec_vsx_st (vector bool char, int, unsigned char *);
22397void vec_vsx_st (vector bool char, int, signed char *);
22398
22399vector double vec_xxpermdi (vector double, vector double, const int);
22400vector float vec_xxpermdi (vector float, vector float, const int);
22401vector long long vec_xxpermdi (vector long long, vector long long, const int);
22402vector unsigned long long vec_xxpermdi (vector unsigned long long,
22403 vector unsigned long long, const int);
22404vector int vec_xxpermdi (vector int, vector int, const int);
22405vector unsigned int vec_xxpermdi (vector unsigned int,
22406 vector unsigned int, const int);
22407vector short vec_xxpermdi (vector short, vector short, const int);
22408vector unsigned short vec_xxpermdi (vector unsigned short,
22409 vector unsigned short, const int);
22410vector signed char vec_xxpermdi (vector signed char, vector signed char,
22411 const int);
22412vector unsigned char vec_xxpermdi (vector unsigned char,
22413 vector unsigned char, const int);
22414
22415vector double vec_xxsldi (vector double, vector double, int);
22416vector float vec_xxsldi (vector float, vector float, int);
22417vector long long vec_xxsldi (vector long long, vector long long, int);
22418vector unsigned long long vec_xxsldi (vector unsigned long long,
22419 vector unsigned long long, int);
22420vector int vec_xxsldi (vector int, vector int, int);
22421vector unsigned int vec_xxsldi (vector unsigned int, vector unsigned int, int);
22422vector short vec_xxsldi (vector short, vector short, int);
22423vector unsigned short vec_xxsldi (vector unsigned short,
22424 vector unsigned short, int);
22425vector signed char vec_xxsldi (vector signed char, vector signed char, int);
22426vector unsigned char vec_xxsldi (vector unsigned char,
22427 vector unsigned char, int);
22428@end smallexample
22429
22430Note that the @samp{vec_ld} and @samp{vec_st} built-in functions always
22431generate the AltiVec @samp{LVX} and @samp{STVX} instructions even
22432if the VSX instruction set is available. The @samp{vec_vsx_ld} and
22433@samp{vec_vsx_st} built-in functions always generate the VSX @samp{LXVD2X},
22434@samp{LXVW4X}, @samp{STXVD2X}, and @samp{STXVW4X} instructions.
22435
22436@node PowerPC AltiVec Built-in Functions Available on ISA 2.07
22437@subsubsection PowerPC AltiVec Built-in Functions Available on ISA 2.07
22438
22439If the ISA 2.07 additions to the vector/scalar (power8-vector)
22440instruction set are available, the following additional functions are
22441available for both 32-bit and 64-bit targets. For 64-bit targets, you
22442can use @var{vector long} instead of @var{vector long long},
22443@var{vector bool long} instead of @var{vector bool long long}, and
22444@var{vector unsigned long} instead of @var{vector unsigned long long}.
22445
22446Only functions excluded from the PVIPR are listed here.
22447
22448@smallexample
22449vector long long vec_vaddudm (vector long long, vector long long);
22450vector long long vec_vaddudm (vector bool long long, vector long long);
22451vector long long vec_vaddudm (vector long long, vector bool long long);
22452vector unsigned long long vec_vaddudm (vector unsigned long long,
22453 vector unsigned long long);
22454vector unsigned long long vec_vaddudm (vector bool unsigned long long,
22455 vector unsigned long long);
22456vector unsigned long long vec_vaddudm (vector unsigned long long,
22457 vector bool unsigned long long);
22458
22459vector long long vec_vclz (vector long long);
22460vector unsigned long long vec_vclz (vector unsigned long long);
22461vector int vec_vclz (vector int);
22462vector unsigned int vec_vclz (vector int);
22463vector short vec_vclz (vector short);
22464vector unsigned short vec_vclz (vector unsigned short);
22465vector signed char vec_vclz (vector signed char);
22466vector unsigned char vec_vclz (vector unsigned char);
22467
22468vector signed char vec_vclzb (vector signed char);
22469vector unsigned char vec_vclzb (vector unsigned char);
22470
22471vector long long vec_vclzd (vector long long);
22472vector unsigned long long vec_vclzd (vector unsigned long long);
22473
22474vector short vec_vclzh (vector short);
22475vector unsigned short vec_vclzh (vector unsigned short);
22476
22477vector int vec_vclzw (vector int);
22478vector unsigned int vec_vclzw (vector int);
22479
22480vector signed char vec_vgbbd (vector signed char);
22481vector unsigned char vec_vgbbd (vector unsigned char);
22482
22483vector long long vec_vmaxsd (vector long long, vector long long);
22484
22485vector unsigned long long vec_vmaxud (vector unsigned long long,
22486 unsigned vector long long);
22487
22488vector long long vec_vminsd (vector long long, vector long long);
22489
22490vector unsigned long long vec_vminud (vector long long, vector long long);
22491
22492vector int vec_vpksdss (vector long long, vector long long);
22493vector unsigned int vec_vpksdss (vector long long, vector long long);
22494
22495vector unsigned int vec_vpkudus (vector unsigned long long,
22496 vector unsigned long long);
22497
22498vector int vec_vpkudum (vector long long, vector long long);
22499vector unsigned int vec_vpkudum (vector unsigned long long,
22500 vector unsigned long long);
22501vector bool int vec_vpkudum (vector bool long long, vector bool long long);
22502
22503vector long long vec_vpopcnt (vector long long);
22504vector unsigned long long vec_vpopcnt (vector unsigned long long);
22505vector int vec_vpopcnt (vector int);
22506vector unsigned int vec_vpopcnt (vector int);
22507vector short vec_vpopcnt (vector short);
22508vector unsigned short vec_vpopcnt (vector unsigned short);
22509vector signed char vec_vpopcnt (vector signed char);
22510vector unsigned char vec_vpopcnt (vector unsigned char);
22511
22512vector signed char vec_vpopcntb (vector signed char);
22513vector unsigned char vec_vpopcntb (vector unsigned char);
22514
22515vector long long vec_vpopcntd (vector long long);
22516vector unsigned long long vec_vpopcntd (vector unsigned long long);
22517
22518vector short vec_vpopcnth (vector short);
22519vector unsigned short vec_vpopcnth (vector unsigned short);
22520
22521vector int vec_vpopcntw (vector int);
22522vector unsigned int vec_vpopcntw (vector int);
22523
22524vector long long vec_vrld (vector long long, vector unsigned long long);
22525vector unsigned long long vec_vrld (vector unsigned long long,
22526 vector unsigned long long);
22527
22528vector long long vec_vsld (vector long long, vector unsigned long long);
22529vector long long vec_vsld (vector unsigned long long,
22530 vector unsigned long long);
22531
22532vector long long vec_vsrad (vector long long, vector unsigned long long);
22533vector unsigned long long vec_vsrad (vector unsigned long long,
22534 vector unsigned long long);
22535
22536vector long long vec_vsrd (vector long long, vector unsigned long long);
22537vector unsigned long long char vec_vsrd (vector unsigned long long,
22538 vector unsigned long long);
22539
22540vector long long vec_vsubudm (vector long long, vector long long);
22541vector long long vec_vsubudm (vector bool long long, vector long long);
22542vector long long vec_vsubudm (vector long long, vector bool long long);
22543vector unsigned long long vec_vsubudm (vector unsigned long long,
22544 vector unsigned long long);
22545vector unsigned long long vec_vsubudm (vector bool long long,
22546 vector unsigned long long);
22547vector unsigned long long vec_vsubudm (vector unsigned long long,
22548 vector bool long long);
22549
22550vector long long vec_vupkhsw (vector int);
22551vector unsigned long long vec_vupkhsw (vector unsigned int);
22552
22553vector long long vec_vupklsw (vector int);
22554vector unsigned long long vec_vupklsw (vector int);
22555@end smallexample
22556
22557If the ISA 2.07 additions to the vector/scalar (power8-vector)
22558instruction set are available, the following additional functions are
22559available for 64-bit targets. New vector types
22560(@var{vector __int128} and @var{vector __uint128}) are available
22561to hold the @var{__int128} and @var{__uint128} types to use these
22562builtins.
22563
22564The normal vector extract, and set operations work on
22565@var{vector __int128} and @var{vector __uint128} types,
22566but the index value must be 0.
22567
22568Only functions excluded from the PVIPR are listed here.
22569
22570@smallexample
22571vector __int128 vec_vaddcuq (vector __int128, vector __int128);
22572vector __uint128 vec_vaddcuq (vector __uint128, vector __uint128);
22573
22574vector __int128 vec_vadduqm (vector __int128, vector __int128);
22575vector __uint128 vec_vadduqm (vector __uint128, vector __uint128);
22576
22577vector __int128 vec_vaddecuq (vector __int128, vector __int128,
22578 vector __int128);
22579vector __uint128 vec_vaddecuq (vector __uint128, vector __uint128,
22580 vector __uint128);
22581
22582vector __int128 vec_vaddeuqm (vector __int128, vector __int128,
22583 vector __int128);
22584vector __uint128 vec_vaddeuqm (vector __uint128, vector __uint128,
22585 vector __uint128);
22586
22587vector __int128 vec_vsubecuq (vector __int128, vector __int128,
22588 vector __int128);
22589vector __uint128 vec_vsubecuq (vector __uint128, vector __uint128,
22590 vector __uint128);
22591
22592vector __int128 vec_vsubeuqm (vector __int128, vector __int128,
22593 vector __int128);
22594vector __uint128 vec_vsubeuqm (vector __uint128, vector __uint128,
22595 vector __uint128);
22596
22597vector __int128 vec_vsubcuq (vector __int128, vector __int128);
22598vector __uint128 vec_vsubcuq (vector __uint128, vector __uint128);
22599
22600__int128 vec_vsubuqm (__int128, __int128);
22601__uint128 vec_vsubuqm (__uint128, __uint128);
22602
22603vector __int128 __builtin_bcdadd (vector __int128, vector __int128, const int);
22604vector unsigned char __builtin_bcdadd (vector unsigned char, vector unsigned char,
22605 const int);
22606int __builtin_bcdadd_lt (vector __int128, vector __int128, const int);
22607int __builtin_bcdadd_lt (vector unsigned char, vector unsigned char, const int);
22608int __builtin_bcdadd_eq (vector __int128, vector __int128, const int);
22609int __builtin_bcdadd_eq (vector unsigned char, vector unsigned char, const int);
22610int __builtin_bcdadd_gt (vector __int128, vector __int128, const int);
22611int __builtin_bcdadd_gt (vector unsigned char, vector unsigned char, const int);
22612int __builtin_bcdadd_ov (vector __int128, vector __int128, const int);
22613int __builtin_bcdadd_ov (vector unsigned char, vector unsigned char, const int);
22614
22615vector __int128 __builtin_bcdsub (vector __int128, vector __int128, const int);
22616vector unsigned char __builtin_bcdsub (vector unsigned char, vector unsigned char,
22617 const int);
c82f123d
CL
22618int __builtin_bcdsub_le (vector __int128, vector __int128, const int);
22619int __builtin_bcdsub_le (vector unsigned char, vector unsigned char, const int);
d77de738
ML
22620int __builtin_bcdsub_lt (vector __int128, vector __int128, const int);
22621int __builtin_bcdsub_lt (vector unsigned char, vector unsigned char, const int);
22622int __builtin_bcdsub_eq (vector __int128, vector __int128, const int);
22623int __builtin_bcdsub_eq (vector unsigned char, vector unsigned char, const int);
22624int __builtin_bcdsub_gt (vector __int128, vector __int128, const int);
22625int __builtin_bcdsub_gt (vector unsigned char, vector unsigned char, const int);
c82f123d
CL
22626int __builtin_bcdsub_ge (vector __int128, vector __int128, const int);
22627int __builtin_bcdsub_ge (vector unsigned char, vector unsigned char, const int);
d77de738
ML
22628int __builtin_bcdsub_ov (vector __int128, vector __int128, const int);
22629int __builtin_bcdsub_ov (vector unsigned char, vector unsigned char, const int);
22630@end smallexample
22631
22632@node PowerPC AltiVec Built-in Functions Available on ISA 3.0
22633@subsubsection PowerPC AltiVec Built-in Functions Available on ISA 3.0
22634
22635The following additional built-in functions are also available for the
22636PowerPC family of processors, starting with ISA 3.0
22637(@option{-mcpu=power9}) or later.
22638
22639Only instructions excluded from the PVIPR are listed here.
22640
22641@smallexample
22642unsigned int scalar_extract_exp (double source);
22643unsigned long long int scalar_extract_exp (__ieee128 source);
22644
22645unsigned long long int scalar_extract_sig (double source);
22646unsigned __int128 scalar_extract_sig (__ieee128 source);
22647
22648double scalar_insert_exp (unsigned long long int significand,
22649 unsigned long long int exponent);
22650double scalar_insert_exp (double significand, unsigned long long int exponent);
22651
22652ieee_128 scalar_insert_exp (unsigned __int128 significand,
22653 unsigned long long int exponent);
22654ieee_128 scalar_insert_exp (ieee_128 significand, unsigned long long int exponent);
86df278d
CL
22655vector ieee_128 scalar_insert_exp (vector unsigned __int128 significand,
22656 vector unsigned long long exponent);
22657vector unsigned long long scalar_extract_exp_to_vec (ieee_128);
22658vector unsigned __int128 scalar_extract_sig_to_vec (ieee_128);
d77de738
ML
22659
22660int scalar_cmp_exp_gt (double arg1, double arg2);
22661int scalar_cmp_exp_lt (double arg1, double arg2);
22662int scalar_cmp_exp_eq (double arg1, double arg2);
22663int scalar_cmp_exp_unordered (double arg1, double arg2);
22664
22665bool scalar_test_data_class (float source, const int condition);
22666bool scalar_test_data_class (double source, const int condition);
22667bool scalar_test_data_class (__ieee128 source, const int condition);
22668
22669bool scalar_test_neg (float source);
22670bool scalar_test_neg (double source);
22671bool scalar_test_neg (__ieee128 source);
22672@end smallexample
22673
e25dc59d
HG
22674The @code{scalar_extract_exp} with a 64-bit source argument
22675function requires an environment supporting ISA 3.0 or later.
22676The @code{scalar_extract_exp} with a 128-bit source argument
22677and @code{scalar_extract_sig}
d77de738
ML
22678functions require a 64-bit environment supporting ISA 3.0 or later.
22679The @code{scalar_extract_exp} and @code{scalar_extract_sig} built-in
22680functions return the significand and the biased exponent value
22681respectively of their @code{source} arguments.
22682When supplied with a 64-bit @code{source} argument, the
22683result returned by @code{scalar_extract_sig} has
22684the @code{0x0010000000000000} bit set if the
22685function's @code{source} argument is in normalized form.
22686Otherwise, this bit is set to 0.
22687When supplied with a 128-bit @code{source} argument, the
22688@code{0x00010000000000000000000000000000} bit of the result is
22689treated similarly.
22690Note that the sign of the significand is not represented in the result
22691returned from the @code{scalar_extract_sig} function. Use the
22692@code{scalar_test_neg} function to test the sign of its @code{double}
22693argument.
22694
22695The @code{scalar_insert_exp}
22696functions require a 64-bit environment supporting ISA 3.0 or later.
22697When supplied with a 64-bit first argument, the
22698@code{scalar_insert_exp} built-in function returns a double-precision
22699floating point value that is constructed by assembling the values of its
22700@code{significand} and @code{exponent} arguments. The sign of the
22701result is copied from the most significant bit of the
22702@code{significand} argument. The significand and exponent components
22703of the result are composed of the least significant 11 bits of the
22704@code{exponent} argument and the least significant 52 bits of the
22705@code{significand} argument respectively.
22706
22707When supplied with a 128-bit first argument, the
22708@code{scalar_insert_exp} built-in function returns a quad-precision
86df278d
CL
22709IEEE floating point value if the two arguments were scalar. If the two
22710arguments are vectors, the return value is a vector IEEE floating point value.
22711The sign bit of the result is copied from the most significant bit of the
22712@code{significand} argument. The significand and exponent components of the
22713result are composed of the least significant 15 bits of the @code{exponent}
22714argument (element 0 on big-endian and element 1 on little-endian) and the
22715least significant 112 bits of the @code{significand} argument
22716respectively. Note, the @code{significand} is the scalar argument or in the
22717case of vector arguments, @code{significand} is element 0 for big-endian and
22718element 1 for little-endian.
22719
22720The @code{scalar_extract_exp_to_vec},
22721and @code{scalar_extract_sig_to_vec} are similar to
22722@code{scalar_extract_exp}, @code{scalar_extract_sig} except they return
22723a vector result of type unsigned long long and unsigned __int128 respectively.
d77de738
ML
22724
22725The @code{scalar_cmp_exp_gt}, @code{scalar_cmp_exp_lt},
22726@code{scalar_cmp_exp_eq}, and @code{scalar_cmp_exp_unordered} built-in
22727functions return a non-zero value if @code{arg1} is greater than, less
22728than, equal to, or not comparable to @code{arg2} respectively. The
22729arguments are not comparable if one or the other equals NaN (not a
22730number).
22731
22732The @code{scalar_test_data_class} built-in function returns 1
22733if any of the condition tests enabled by the value of the
22734@code{condition} variable are true, and 0 otherwise. The
22735@code{condition} argument must be a compile-time constant integer with
22736value not exceeding 127. The
22737@code{condition} argument is encoded as a bitmask with each bit
22738enabling the testing of a different condition, as characterized by the
22739following:
22740@smallexample
227410x40 Test for NaN
227420x20 Test for +Infinity
227430x10 Test for -Infinity
227440x08 Test for +Zero
227450x04 Test for -Zero
227460x02 Test for +Denormal
227470x01 Test for -Denormal
22748@end smallexample
22749
22750The @code{scalar_test_neg} built-in function returns 1 if its
22751@code{source} argument holds a negative value, 0 otherwise.
22752
22753The following built-in functions are also available for the PowerPC family
22754of processors, starting with ISA 3.0 or later
22755(@option{-mcpu=power9}). These string functions are described
22756separately in order to group the descriptions closer to the function
22757prototypes.
22758
22759Only functions excluded from the PVIPR are listed here.
22760
22761@smallexample
22762int vec_all_nez (vector signed char, vector signed char);
22763int vec_all_nez (vector unsigned char, vector unsigned char);
22764int vec_all_nez (vector signed short, vector signed short);
22765int vec_all_nez (vector unsigned short, vector unsigned short);
22766int vec_all_nez (vector signed int, vector signed int);
22767int vec_all_nez (vector unsigned int, vector unsigned int);
22768
22769int vec_any_eqz (vector signed char, vector signed char);
22770int vec_any_eqz (vector unsigned char, vector unsigned char);
22771int vec_any_eqz (vector signed short, vector signed short);
22772int vec_any_eqz (vector unsigned short, vector unsigned short);
22773int vec_any_eqz (vector signed int, vector signed int);
22774int vec_any_eqz (vector unsigned int, vector unsigned int);
22775
22776signed char vec_xlx (unsigned int index, vector signed char data);
22777unsigned char vec_xlx (unsigned int index, vector unsigned char data);
22778signed short vec_xlx (unsigned int index, vector signed short data);
22779unsigned short vec_xlx (unsigned int index, vector unsigned short data);
22780signed int vec_xlx (unsigned int index, vector signed int data);
22781unsigned int vec_xlx (unsigned int index, vector unsigned int data);
22782float vec_xlx (unsigned int index, vector float data);
22783
22784signed char vec_xrx (unsigned int index, vector signed char data);
22785unsigned char vec_xrx (unsigned int index, vector unsigned char data);
22786signed short vec_xrx (unsigned int index, vector signed short data);
22787unsigned short vec_xrx (unsigned int index, vector unsigned short data);
22788signed int vec_xrx (unsigned int index, vector signed int data);
22789unsigned int vec_xrx (unsigned int index, vector unsigned int data);
22790float vec_xrx (unsigned int index, vector float data);
22791@end smallexample
22792
22793The @code{vec_all_nez}, @code{vec_any_eqz}, and @code{vec_cmpnez}
22794perform pairwise comparisons between the elements at the same
22795positions within their two vector arguments.
22796The @code{vec_all_nez} function returns a
22797non-zero value if and only if all pairwise comparisons are not
22798equal and no element of either vector argument contains a zero.
22799The @code{vec_any_eqz} function returns a
22800non-zero value if and only if at least one pairwise comparison is equal
22801or if at least one element of either vector argument contains a zero.
22802The @code{vec_cmpnez} function returns a vector of the same type as
22803its two arguments, within which each element consists of all ones to
22804denote that either the corresponding elements of the incoming arguments are
22805not equal or that at least one of the corresponding elements contains
22806zero. Otherwise, the element of the returned vector contains all zeros.
22807
22808The @code{vec_xlx} and @code{vec_xrx} functions extract the single
22809element selected by the @code{index} argument from the vector
22810represented by the @code{data} argument. The @code{index} argument
22811always specifies a byte offset, regardless of the size of the vector
22812element. With @code{vec_xlx}, @code{index} is the offset of the first
22813byte of the element to be extracted. With @code{vec_xrx}, @code{index}
22814represents the last byte of the element to be extracted, measured
22815from the right end of the vector. In other words, the last byte of
22816the element to be extracted is found at position @code{(15 - index)}.
22817There is no requirement that @code{index} be a multiple of the vector
22818element size. However, if the size of the vector element added to
22819@code{index} is greater than 15, the content of the returned value is
22820undefined.
22821
22822The following functions are also available if the ISA 3.0 instruction
22823set additions (@option{-mcpu=power9}) are available.
22824
22825Only functions excluded from the PVIPR are listed here.
22826
22827@smallexample
22828vector long long vec_vctz (vector long long);
22829vector unsigned long long vec_vctz (vector unsigned long long);
22830vector int vec_vctz (vector int);
22831vector unsigned int vec_vctz (vector int);
22832vector short vec_vctz (vector short);
22833vector unsigned short vec_vctz (vector unsigned short);
22834vector signed char vec_vctz (vector signed char);
22835vector unsigned char vec_vctz (vector unsigned char);
22836
22837vector signed char vec_vctzb (vector signed char);
22838vector unsigned char vec_vctzb (vector unsigned char);
22839
22840vector long long vec_vctzd (vector long long);
22841vector unsigned long long vec_vctzd (vector unsigned long long);
22842
22843vector short vec_vctzh (vector short);
22844vector unsigned short vec_vctzh (vector unsigned short);
22845
22846vector int vec_vctzw (vector int);
22847vector unsigned int vec_vctzw (vector int);
22848
22849vector int vec_vprtyb (vector int);
22850vector unsigned int vec_vprtyb (vector unsigned int);
22851vector long long vec_vprtyb (vector long long);
22852vector unsigned long long vec_vprtyb (vector unsigned long long);
22853
22854vector int vec_vprtybw (vector int);
22855vector unsigned int vec_vprtybw (vector unsigned int);
22856
22857vector long long vec_vprtybd (vector long long);
22858vector unsigned long long vec_vprtybd (vector unsigned long long);
22859@end smallexample
22860
22861On 64-bit targets, if the ISA 3.0 additions (@option{-mcpu=power9})
22862are available:
22863
22864@smallexample
22865vector long vec_vprtyb (vector long);
22866vector unsigned long vec_vprtyb (vector unsigned long);
22867vector __int128 vec_vprtyb (vector __int128);
22868vector __uint128 vec_vprtyb (vector __uint128);
22869
22870vector long vec_vprtybd (vector long);
22871vector unsigned long vec_vprtybd (vector unsigned long);
22872
22873vector __int128 vec_vprtybq (vector __int128);
22874vector __uint128 vec_vprtybd (vector __uint128);
22875@end smallexample
22876
22877The following built-in functions are available for the PowerPC family
22878of processors, starting with ISA 3.0 or later (@option{-mcpu=power9}).
22879
22880Only functions excluded from the PVIPR are listed here.
22881
22882@smallexample
22883__vector unsigned char
22884vec_absdb (__vector unsigned char arg1, __vector unsigned char arg2);
22885__vector unsigned short
22886vec_absdh (__vector unsigned short arg1, __vector unsigned short arg2);
22887__vector unsigned int
22888vec_absdw (__vector unsigned int arg1, __vector unsigned int arg2);
22889@end smallexample
22890
22891The @code{vec_absd}, @code{vec_absdb}, @code{vec_absdh}, and
22892@code{vec_absdw} built-in functions each computes the absolute
22893differences of the pairs of vector elements supplied in its two vector
22894arguments, placing the absolute differences into the corresponding
22895elements of the vector result.
22896
22897The following built-in functions are available for the PowerPC family
22898of processors, starting with ISA 3.0 or later (@option{-mcpu=power9}):
22899@smallexample
22900vector unsigned int vec_vrlnm (vector unsigned int, vector unsigned int);
22901vector unsigned long long vec_vrlnm (vector unsigned long long,
22902 vector unsigned long long);
22903@end smallexample
22904
22905The result of @code{vec_vrlnm} is obtained by rotating each element
22906of the first argument vector left and ANDing it with a mask. The
22907second argument vector contains the mask beginning in bits 11:15,
22908the mask end in bits 19:23, and the shift count in bits 27:31,
22909of each element.
22910
22911If the cryptographic instructions are enabled (@option{-mcrypto} or
22912@option{-mcpu=power8}), the following builtins are enabled.
22913
22914Only functions excluded from the PVIPR are listed here.
22915
22916@smallexample
22917vector unsigned long long __builtin_crypto_vsbox (vector unsigned long long);
22918
22919vector unsigned long long __builtin_crypto_vcipher (vector unsigned long long,
22920 vector unsigned long long);
22921
22922vector unsigned long long __builtin_crypto_vcipherlast
22923 (vector unsigned long long,
22924 vector unsigned long long);
22925
22926vector unsigned long long __builtin_crypto_vncipher (vector unsigned long long,
22927 vector unsigned long long);
22928
22929vector unsigned long long __builtin_crypto_vncipherlast (vector unsigned long long,
22930 vector unsigned long long);
22931
22932vector unsigned char __builtin_crypto_vpermxor (vector unsigned char,
22933 vector unsigned char,
22934 vector unsigned char);
22935
22936vector unsigned short __builtin_crypto_vpermxor (vector unsigned short,
22937 vector unsigned short,
22938 vector unsigned short);
22939
22940vector unsigned int __builtin_crypto_vpermxor (vector unsigned int,
22941 vector unsigned int,
22942 vector unsigned int);
22943
22944vector unsigned long long __builtin_crypto_vpermxor (vector unsigned long long,
22945 vector unsigned long long,
22946 vector unsigned long long);
22947
22948vector unsigned char __builtin_crypto_vpmsumb (vector unsigned char,
22949 vector unsigned char);
22950
22951vector unsigned short __builtin_crypto_vpmsumh (vector unsigned short,
22952 vector unsigned short);
22953
22954vector unsigned int __builtin_crypto_vpmsumw (vector unsigned int,
22955 vector unsigned int);
22956
22957vector unsigned long long __builtin_crypto_vpmsumd (vector unsigned long long,
22958 vector unsigned long long);
22959
22960vector unsigned long long __builtin_crypto_vshasigmad (vector unsigned long long,
22961 int, int);
22962
22963vector unsigned int __builtin_crypto_vshasigmaw (vector unsigned int, int, int);
22964@end smallexample
22965
22966The second argument to @var{__builtin_crypto_vshasigmad} and
22967@var{__builtin_crypto_vshasigmaw} must be a constant
22968integer that is 0 or 1. The third argument to these built-in functions
22969must be a constant integer in the range of 0 to 15.
22970
22971The following sign extension builtins are provided:
22972
22973@smallexample
22974vector signed int vec_signexti (vector signed char a);
22975vector signed long long vec_signextll (vector signed char a);
22976vector signed int vec_signexti (vector signed short a);
22977vector signed long long vec_signextll (vector signed short a);
22978vector signed long long vec_signextll (vector signed int a);
22979vector signed long long vec_signextq (vector signed long long a);
22980@end smallexample
22981
22982Each element of the result is produced by sign-extending the element of the
22983input vector that would fall in the least significant portion of the result
22984element. For example, a sign-extension of a vector signed char to a vector
22985signed long long will sign extend the rightmost byte of each doubleword.
22986
22987@node PowerPC AltiVec Built-in Functions Available on ISA 3.1
22988@subsubsection PowerPC AltiVec Built-in Functions Available on ISA 3.1
22989
22990The following additional built-in functions are also available for the
22991PowerPC family of processors, starting with ISA 3.1 (@option{-mcpu=power10}):
22992
22993
22994@smallexample
22995@exdent vector unsigned long long int
22996@exdent vec_cfuge (vector unsigned long long int, vector unsigned long long int);
22997@end smallexample
22998Perform a vector centrifuge operation, as if implemented by the
22999@code{vcfuged} instruction.
23000@findex vec_cfuge
23001
23002@smallexample
23003@exdent vector unsigned long long int
23004@exdent vec_cntlzm (vector unsigned long long int, vector unsigned long long int);
23005@end smallexample
23006Perform a vector count leading zeros under bit mask operation, as if
23007implemented by the @code{vclzdm} instruction.
23008@findex vec_cntlzm
23009
23010@smallexample
23011@exdent vector unsigned long long int
23012@exdent vec_cnttzm (vector unsigned long long int, vector unsigned long long int);
23013@end smallexample
23014Perform a vector count trailing zeros under bit mask operation, as if
23015implemented by the @code{vctzdm} instruction.
23016@findex vec_cnttzm
23017
23018@smallexample
23019@exdent vector signed char
23795106 23020@exdent vec_clrl (vector signed char @var{a}, unsigned int @var{n});
d77de738 23021@exdent vector unsigned char
23795106 23022@exdent vec_clrl (vector unsigned char @var{a}, unsigned int @var{n});
d77de738
ML
23023@end smallexample
23024Clear the left-most @code{(16 - n)} bytes of vector argument @code{a}, as if
23025implemented by the @code{vclrlb} instruction on a big-endian target
23026and by the @code{vclrrb} instruction on a little-endian target. A
23027value of @code{n} that is greater than 16 is treated as if it equaled 16.
23028@findex vec_clrl
23029
23030@smallexample
23031@exdent vector signed char
23795106 23032@exdent vec_clrr (vector signed char @var{a}, unsigned int @var{n});
d77de738 23033@exdent vector unsigned char
23795106 23034@exdent vec_clrr (vector unsigned char @var{a}, unsigned int @var{n});
d77de738
ML
23035@end smallexample
23036Clear the right-most @code{(16 - n)} bytes of vector argument @code{a}, as if
23037implemented by the @code{vclrrb} instruction on a big-endian target
23038and by the @code{vclrlb} instruction on a little-endian target. A
23039value of @code{n} that is greater than 16 is treated as if it equaled 16.
23040@findex vec_clrr
23041
23042@smallexample
23043@exdent vector unsigned long long int
23044@exdent vec_gnb (vector unsigned __int128, const unsigned char);
23045@end smallexample
23046Perform a 128-bit vector gather operation, as if implemented by the
23047@code{vgnb} instruction. The second argument must be a literal
23048integer value between 2 and 7 inclusive.
23049@findex vec_gnb
23050
23051
23052Vector Extract
23053
23054@smallexample
23055@exdent vector unsigned long long int
23056@exdent vec_extractl (vector unsigned char, vector unsigned char, unsigned int);
23057@exdent vector unsigned long long int
23058@exdent vec_extractl (vector unsigned short, vector unsigned short, unsigned int);
23059@exdent vector unsigned long long int
23060@exdent vec_extractl (vector unsigned int, vector unsigned int, unsigned int);
23061@exdent vector unsigned long long int
23062@exdent vec_extractl (vector unsigned long long, vector unsigned long long, unsigned int);
23063@end smallexample
23064Extract an element from two concatenated vectors starting at the given byte index
23065in natural-endian order, and place it zero-extended in doubleword 1 of the result
23066according to natural element order. If the byte index is out of range for the
23067data type, the intrinsic will be rejected.
23068For little-endian, this output will match the placement by the hardware
23069instruction, i.e., dword[0] in RTL notation. For big-endian, an additional
23070instruction is needed to move it from the "left" doubleword to the "right" one.
23071For little-endian, semantics matching the @code{vextdubvrx},
23072@code{vextduhvrx}, @code{vextduwvrx} instruction will be generated, while for
23073big-endian, semantics matching the @code{vextdubvlx}, @code{vextduhvlx},
23074@code{vextduwvlx} instructions
23075will be generated. Note that some fairly anomalous results can be generated if
23076the byte index is not aligned on an element boundary for the element being
23077extracted. This is a limitation of the bi-endian vector programming model is
23078consistent with the limitation on @code{vec_perm}.
23079@findex vec_extractl
23080
23081@smallexample
23082@exdent vector unsigned long long int
23083@exdent vec_extracth (vector unsigned char, vector unsigned char, unsigned int);
23084@exdent vector unsigned long long int
23085@exdent vec_extracth (vector unsigned short, vector unsigned short,
23086unsigned int);
23087@exdent vector unsigned long long int
23088@exdent vec_extracth (vector unsigned int, vector unsigned int, unsigned int);
23089@exdent vector unsigned long long int
23090@exdent vec_extracth (vector unsigned long long, vector unsigned long long,
23091unsigned int);
23092@end smallexample
23093Extract an element from two concatenated vectors starting at the given byte
23094index. The index is based on big endian order for a little endian system.
23095Similarly, the index is based on little endian order for a big endian system.
23096The extraced elements are zero-extended and put in doubleword 1
23097according to natural element order. If the byte index is out of range for the
23098data type, the intrinsic will be rejected. For little-endian, this output
23099will match the placement by the hardware instruction (vextdubvrx, vextduhvrx,
23100vextduwvrx, vextddvrx) i.e., dword[0] in RTL
23101notation. For big-endian, an additional instruction is needed to move it
23102from the "left" doubleword to the "right" one. For little-endian, semantics
23103matching the @code{vextdubvlx}, @code{vextduhvlx}, @code{vextduwvlx}
23104instructions will be generated, while for big-endian, semantics matching the
23105@code{vextdubvrx}, @code{vextduhvrx}, @code{vextduwvrx} instructions will
23106be generated. Note that some fairly anomalous
23107results can be generated if the byte index is not aligned on the
23108element boundary for the element being extracted. This is a
23109limitation of the bi-endian vector programming model consistent with the
23110limitation on @code{vec_perm}.
23111@findex vec_extracth
23112@smallexample
23113@exdent vector unsigned long long int
23114@exdent vec_pdep (vector unsigned long long int, vector unsigned long long int);
23115@end smallexample
23116Perform a vector parallel bits deposit operation, as if implemented by
23117the @code{vpdepd} instruction.
23118@findex vec_pdep
23119
23120Vector Insert
23121
23122@smallexample
23123@exdent vector unsigned char
23124@exdent vec_insertl (unsigned char, vector unsigned char, unsigned int);
23125@exdent vector unsigned short
23126@exdent vec_insertl (unsigned short, vector unsigned short, unsigned int);
23127@exdent vector unsigned int
23128@exdent vec_insertl (unsigned int, vector unsigned int, unsigned int);
23129@exdent vector unsigned long long
23130@exdent vec_insertl (unsigned long long, vector unsigned long long,
23131unsigned int);
23132@exdent vector unsigned char
23133@exdent vec_insertl (vector unsigned char, vector unsigned char, unsigned int;
23134@exdent vector unsigned short
23135@exdent vec_insertl (vector unsigned short, vector unsigned short,
23136unsigned int);
23137@exdent vector unsigned int
23138@exdent vec_insertl (vector unsigned int, vector unsigned int, unsigned int);
23139@end smallexample
23140
23141Let src be the first argument, when the first argument is a scalar, or the
23142rightmost element of the left doubleword of the first argument, when the first
23143argument is a vector. Insert the source into the destination at the position
23144given by the third argument, using natural element order in the second
23145argument. The rest of the second argument is unchanged. If the byte
23146index is greater than 14 for halfwords, greater than 12 for words, or
23147greater than 8 for doublewords the result is undefined. For little-endian,
23148the generated code will be semantically equivalent to @code{vins[bhwd]rx}
23149instructions. Similarly for big-endian it will be semantically equivalent
23150to @code{vins[bhwd]lx}. Note that some fairly anomalous results can be
23151generated if the byte index is not aligned on an element boundary for the
23152type of element being inserted.
23153@findex vec_insertl
23154
23155@smallexample
23156@exdent vector unsigned char
23157@exdent vec_inserth (unsigned char, vector unsigned char, unsigned int);
23158@exdent vector unsigned short
23159@exdent vec_inserth (unsigned short, vector unsigned short, unsigned int);
23160@exdent vector unsigned int
23161@exdent vec_inserth (unsigned int, vector unsigned int, unsigned int);
23162@exdent vector unsigned long long
23163@exdent vec_inserth (unsigned long long, vector unsigned long long,
23164unsigned int);
23165@exdent vector unsigned char
23166@exdent vec_inserth (vector unsigned char, vector unsigned char, unsigned int);
23167@exdent vector unsigned short
23168@exdent vec_inserth (vector unsigned short, vector unsigned short,
23169unsigned int);
23170@exdent vector unsigned int
23171@exdent vec_inserth (vector unsigned int, vector unsigned int, unsigned int);
23172@end smallexample
23173
23174Let src be the first argument, when the first argument is a scalar, or the
23175rightmost element of the first argument, when the first argument is a vector.
23176Insert src into the second argument at the position identified by the third
23177argument, using opposite element order in the second argument, and leaving the
23178rest of the second argument unchanged. If the byte index is greater than 14
23179for halfwords, 12 for words, or 8 for doublewords, the intrinsic will be
23180rejected. Note that the underlying hardware instruction uses the same register
23181for the second argument and the result.
23182For little-endian, the code generation will be semantically equivalent to
23183@code{vins[bhwd]lx}, while for big-endian it will be semantically equivalent to
23184@code{vins[bhwd]rx}.
23185Note that some fairly anomalous results can be generated if the byte index is
23186not aligned on an element boundary for the sort of element being inserted.
23187@findex vec_inserth
23188
23189Vector Replace Element
23190@smallexample
23191@exdent vector signed int vec_replace_elt (vector signed int, signed int,
23192const int);
23193@exdent vector unsigned int vec_replace_elt (vector unsigned int,
23194unsigned int, const int);
23195@exdent vector float vec_replace_elt (vector float, float, const int);
23196@exdent vector signed long long vec_replace_elt (vector signed long long,
23197signed long long, const int);
23198@exdent vector unsigned long long vec_replace_elt (vector unsigned long long,
23199unsigned long long, const int);
23200@exdent vector double rec_replace_elt (vector double, double, const int);
23201@end smallexample
23202The third argument (constrained to [0,3]) identifies the natural-endian
23203element number of the first argument that will be replaced by the second
23204argument to produce the result. The other elements of the first argument will
23205remain unchanged in the result.
23206
23207If it's desirable to insert a word at an unaligned position, use
23208vec_replace_unaligned instead.
23209
23210@findex vec_replace_element
23211
23212Vector Replace Unaligned
23213@smallexample
23214@exdent vector unsigned char vec_replace_unaligned (vector unsigned char,
23215signed int, const int);
23216@exdent vector unsigned char vec_replace_unaligned (vector unsigned char,
23217unsigned int, const int);
23218@exdent vector unsigned char vec_replace_unaligned (vector unsigned char,
23219float, const int);
23220@exdent vector unsigned char vec_replace_unaligned (vector unsigned char,
23221signed long long, const int);
23222@exdent vector unsigned char vec_replace_unaligned (vector unsigned char,
23223unsigned long long, const int);
23224@exdent vector unsigned char vec_replace_unaligned (vector unsigned char,
23225double, const int);
23226@end smallexample
23227
23228The second argument replaces a portion of the first argument to produce the
23229result, with the rest of the first argument unchanged in the result. The
23230third argument identifies the byte index (using left-to-right, or big-endian
23231order) where the high-order byte of the second argument will be placed, with
23232the remaining bytes of the second argument placed naturally "to the right"
23233of the high-order byte.
23234
23235The programmer is responsible for understanding the endianness issues involved
23236with the first argument and the result.
23237@findex vec_replace_unaligned
23238
23239Vector Shift Left Double Bit Immediate
23240@smallexample
23241@exdent vector signed char vec_sldb (vector signed char, vector signed char,
23242const unsigned int);
23243@exdent vector unsigned char vec_sldb (vector unsigned char,
23244vector unsigned char, const unsigned int);
23245@exdent vector signed short vec_sldb (vector signed short, vector signed short,
23246const unsigned int);
23247@exdent vector unsigned short vec_sldb (vector unsigned short,
23248vector unsigned short, const unsigned int);
23249@exdent vector signed int vec_sldb (vector signed int, vector signed int,
23250const unsigned int);
23251@exdent vector unsigned int vec_sldb (vector unsigned int, vector unsigned int,
23252const unsigned int);
23253@exdent vector signed long long vec_sldb (vector signed long long,
23254vector signed long long, const unsigned int);
23255@exdent vector unsigned long long vec_sldb (vector unsigned long long,
23256vector unsigned long long, const unsigned int);
23257@end smallexample
23258
23259Shift the combined input vectors left by the amount specified by the low-order
23260three bits of the third argument, and return the leftmost remaining 128 bits.
23261Code using this instruction must be endian-aware.
23262
23263@findex vec_sldb
23264
23265Vector Shift Right Double Bit Immediate
23266
23267@smallexample
23268@exdent vector signed char vec_srdb (vector signed char, vector signed char,
23269const unsigned int);
23270@exdent vector unsigned char vec_srdb (vector unsigned char, vector unsigned char,
23271const unsigned int);
23272@exdent vector signed short vec_srdb (vector signed short, vector signed short,
23273const unsigned int);
23274@exdent vector unsigned short vec_srdb (vector unsigned short, vector unsigned short,
23275const unsigned int);
23276@exdent vector signed int vec_srdb (vector signed int, vector signed int,
23277const unsigned int);
23278@exdent vector unsigned int vec_srdb (vector unsigned int, vector unsigned int,
23279const unsigned int);
23280@exdent vector signed long long vec_srdb (vector signed long long,
23281vector signed long long, const unsigned int);
23282@exdent vector unsigned long long vec_srdb (vector unsigned long long,
23283vector unsigned long long, const unsigned int);
23284@end smallexample
23285
23286Shift the combined input vectors right by the amount specified by the low-order
23287three bits of the third argument, and return the remaining 128 bits. Code
23288using this built-in must be endian-aware.
23289
23290@findex vec_srdb
23291
23292Vector Splat
23293
23294@smallexample
23295@exdent vector signed int vec_splati (const signed int);
23296@exdent vector float vec_splati (const float);
23297@end smallexample
23298
23299Splat a 32-bit immediate into a vector of words.
23300
23301@findex vec_splati
23302
23303@smallexample
23304@exdent vector double vec_splatid (const float);
23305@end smallexample
23306
23307Convert a single precision floating-point value to double-precision and splat
23308the result to a vector of double-precision floats.
23309
23310@findex vec_splatid
23311
23312@smallexample
23313@exdent vector signed int vec_splati_ins (vector signed int,
23314const unsigned int, const signed int);
23315@exdent vector unsigned int vec_splati_ins (vector unsigned int,
23316const unsigned int, const unsigned int);
23317@exdent vector float vec_splati_ins (vector float, const unsigned int,
23318const float);
23319@end smallexample
23320
23321Argument 2 must be either 0 or 1. Splat the value of argument 3 into the word
23322identified by argument 2 of each doubleword of argument 1 and return the
23323result. The other words of argument 1 are unchanged.
23324
23325@findex vec_splati_ins
23326
23327Vector Blend Variable
23328
23329@smallexample
23330@exdent vector signed char vec_blendv (vector signed char, vector signed char,
23331vector unsigned char);
23332@exdent vector unsigned char vec_blendv (vector unsigned char,
23333vector unsigned char, vector unsigned char);
23334@exdent vector signed short vec_blendv (vector signed short,
23335vector signed short, vector unsigned short);
23336@exdent vector unsigned short vec_blendv (vector unsigned short,
23337vector unsigned short, vector unsigned short);
23338@exdent vector signed int vec_blendv (vector signed int, vector signed int,
23339vector unsigned int);
23340@exdent vector unsigned int vec_blendv (vector unsigned int,
23341vector unsigned int, vector unsigned int);
23342@exdent vector signed long long vec_blendv (vector signed long long,
23343vector signed long long, vector unsigned long long);
23344@exdent vector unsigned long long vec_blendv (vector unsigned long long,
23345vector unsigned long long, vector unsigned long long);
23346@exdent vector float vec_blendv (vector float, vector float,
23347vector unsigned int);
23348@exdent vector double vec_blendv (vector double, vector double,
23349vector unsigned long long);
23350@end smallexample
23351
23352Blend the first and second argument vectors according to the sign bits of the
23353corresponding elements of the third argument vector. This is similar to the
23354@code{vsel} and @code{xxsel} instructions but for bigger elements.
23355
23356@findex vec_blendv
23357
23358Vector Permute Extended
23359
23360@smallexample
23361@exdent vector signed char vec_permx (vector signed char, vector signed char,
23362vector unsigned char, const int);
23363@exdent vector unsigned char vec_permx (vector unsigned char,
23364vector unsigned char, vector unsigned char, const int);
23365@exdent vector signed short vec_permx (vector signed short,
23366vector signed short, vector unsigned char, const int);
23367@exdent vector unsigned short vec_permx (vector unsigned short,
23368vector unsigned short, vector unsigned char, const int);
23369@exdent vector signed int vec_permx (vector signed int, vector signed int,
23370vector unsigned char, const int);
23371@exdent vector unsigned int vec_permx (vector unsigned int,
23372vector unsigned int, vector unsigned char, const int);
23373@exdent vector signed long long vec_permx (vector signed long long,
23374vector signed long long, vector unsigned char, const int);
23375@exdent vector unsigned long long vec_permx (vector unsigned long long,
23376vector unsigned long long, vector unsigned char, const int);
23377@exdent vector float (vector float, vector float, vector unsigned char,
23378const int);
23379@exdent vector double (vector double, vector double, vector unsigned char,
23380const int);
23381@end smallexample
23382
23383Perform a partial permute of the first two arguments, which form a 32-byte
23384section of an emulated vector up to 256 bytes wide, using the partial permute
23385control vector in the third argument. The fourth argument (constrained to
23386values of 0-7) identifies which 32-byte section of the emulated vector is
23387contained in the first two arguments.
23388@findex vec_permx
23389
23390@smallexample
23391@exdent vector unsigned long long int
23392@exdent vec_pext (vector unsigned long long int, vector unsigned long long int);
23393@end smallexample
23394Perform a vector parallel bit extract operation, as if implemented by
23395the @code{vpextd} instruction.
23396@findex vec_pext
23397
23398@smallexample
23399@exdent vector unsigned char vec_stril (vector unsigned char);
23400@exdent vector signed char vec_stril (vector signed char);
23401@exdent vector unsigned short vec_stril (vector unsigned short);
23402@exdent vector signed short vec_stril (vector signed short);
23403@end smallexample
23404Isolate the left-most non-zero elements of the incoming vector argument,
23405replacing all elements to the right of the left-most zero element
23406found within the argument with zero. The typical implementation uses
23407the @code{vstribl} or @code{vstrihl} instruction on big-endian targets
23408and uses the @code{vstribr} or @code{vstrihr} instruction on
23409little-endian targets.
23410@findex vec_stril
23411
23412@smallexample
23413@exdent int vec_stril_p (vector unsigned char);
23414@exdent int vec_stril_p (vector signed char);
23415@exdent int short vec_stril_p (vector unsigned short);
23416@exdent int vec_stril_p (vector signed short);
23417@end smallexample
23418Return a non-zero value if and only if the argument contains a zero
23419element. The typical implementation uses
23420the @code{vstribl.} or @code{vstrihl.} instruction on big-endian targets
23421and uses the @code{vstribr.} or @code{vstrihr.} instruction on
23422little-endian targets. Choose this built-in to check for presence of
23423zero element if the same argument is also passed to @code{vec_stril}.
23424@findex vec_stril_p
23425
23426@smallexample
23427@exdent vector unsigned char vec_strir (vector unsigned char);
23428@exdent vector signed char vec_strir (vector signed char);
23429@exdent vector unsigned short vec_strir (vector unsigned short);
23430@exdent vector signed short vec_strir (vector signed short);
23431@end smallexample
23432Isolate the right-most non-zero elements of the incoming vector argument,
23433replacing all elements to the left of the right-most zero element
23434found within the argument with zero. The typical implementation uses
23435the @code{vstribr} or @code{vstrihr} instruction on big-endian targets
23436and uses the @code{vstribl} or @code{vstrihl} instruction on
23437little-endian targets.
23438@findex vec_strir
23439
23440@smallexample
23441@exdent int vec_strir_p (vector unsigned char);
23442@exdent int vec_strir_p (vector signed char);
23443@exdent int short vec_strir_p (vector unsigned short);
23444@exdent int vec_strir_p (vector signed short);
23445@end smallexample
23446Return a non-zero value if and only if the argument contains a zero
23447element. The typical implementation uses
23448the @code{vstribr.} or @code{vstrihr.} instruction on big-endian targets
23449and uses the @code{vstribl.} or @code{vstrihl.} instruction on
23450little-endian targets. Choose this built-in to check for presence of
23451zero element if the same argument is also passed to @code{vec_strir}.
23452@findex vec_strir_p
23453
23454@smallexample
23455@exdent vector unsigned char
23456@exdent vec_ternarylogic (vector unsigned char, vector unsigned char,
23457 vector unsigned char, const unsigned int);
23458@exdent vector unsigned short
23459@exdent vec_ternarylogic (vector unsigned short, vector unsigned short,
23460 vector unsigned short, const unsigned int);
23461@exdent vector unsigned int
23462@exdent vec_ternarylogic (vector unsigned int, vector unsigned int,
23463 vector unsigned int, const unsigned int);
23464@exdent vector unsigned long long int
23465@exdent vec_ternarylogic (vector unsigned long long int, vector unsigned long long int,
23466 vector unsigned long long int, const unsigned int);
23467@exdent vector unsigned __int128
23468@exdent vec_ternarylogic (vector unsigned __int128, vector unsigned __int128,
23469 vector unsigned __int128, const unsigned int);
23470@end smallexample
23471Perform a 128-bit vector evaluate operation, as if implemented by the
23472@code{xxeval} instruction. The fourth argument must be a literal
23473integer value between 0 and 255 inclusive.
23474@findex vec_ternarylogic
23475
23476@smallexample
23477@exdent vector unsigned char vec_genpcvm (vector unsigned char, const int);
23478@exdent vector unsigned short vec_genpcvm (vector unsigned short, const int);
23479@exdent vector unsigned int vec_genpcvm (vector unsigned int, const int);
23480@exdent vector unsigned int vec_genpcvm (vector unsigned long long int,
23481 const int);
23482@end smallexample
23483
23484Vector Integer Multiply/Divide/Modulo
23485
23486@smallexample
23487@exdent vector signed int
23795106 23488@exdent vec_mulh (vector signed int @var{a}, vector signed int @var{b});
d77de738 23489@exdent vector unsigned int
23795106 23490@exdent vec_mulh (vector unsigned int @var{a}, vector unsigned int @var{b});
d77de738
ML
23491@end smallexample
23492
23493For each integer value @code{i} from 0 to 3, do the following. The integer
23494value in word element @code{i} of a is multiplied by the integer value in word
23495element @code{i} of b. The high-order 32 bits of the 64-bit product are placed
23496into word element @code{i} of the vector returned.
23497
23498@smallexample
23499@exdent vector signed long long
23795106 23500@exdent vec_mulh (vector signed long long @var{a}, vector signed long long @var{b});
d77de738 23501@exdent vector unsigned long long
23795106 23502@exdent vec_mulh (vector unsigned long long @var{a}, vector unsigned long long @var{b});
d77de738
ML
23503@end smallexample
23504
23505For each integer value @code{i} from 0 to 1, do the following. The integer
23506value in doubleword element @code{i} of a is multiplied by the integer value in
23507doubleword element @code{i} of b. The high-order 64 bits of the 128-bit product
23508are placed into doubleword element @code{i} of the vector returned.
23509
23510@smallexample
23511@exdent vector unsigned long long
23795106 23512@exdent vec_mul (vector unsigned long long @var{a}, vector unsigned long long @var{b});
d77de738 23513@exdent vector signed long long
23795106 23514@exdent vec_mul (vector signed long long @var{a}, vector signed long long @var{b});
d77de738
ML
23515@end smallexample
23516
23517For each integer value @code{i} from 0 to 1, do the following. The integer
23518value in doubleword element @code{i} of a is multiplied by the integer value in
23519doubleword element @code{i} of b. The low-order 64 bits of the 128-bit product
23520are placed into doubleword element @code{i} of the vector returned.
23521
23522@smallexample
23523@exdent vector signed int
23795106 23524@exdent vec_div (vector signed int @var{a}, vector signed int @var{b});
d77de738 23525@exdent vector unsigned int
23795106 23526@exdent vec_div (vector unsigned int @var{a}, vector unsigned int @var{b});
d77de738
ML
23527@end smallexample
23528
23529For each integer value @code{i} from 0 to 3, do the following. The integer in
23530word element @code{i} of a is divided by the integer in word element @code{i}
23531of b. The unique integer quotient is placed into the word element @code{i} of
23532the vector returned. If an attempt is made to perform any of the divisions
23533<anything> ÷ 0 then the quotient is undefined.
23534
23535@smallexample
23536@exdent vector signed long long
23795106 23537@exdent vec_div (vector signed long long @var{a}, vector signed long long @var{b});
d77de738 23538@exdent vector unsigned long long
23795106 23539@exdent vec_div (vector unsigned long long @var{a}, vector unsigned long long @var{b});
d77de738
ML
23540@end smallexample
23541
23542For each integer value @code{i} from 0 to 1, do the following. The integer in
23543doubleword element @code{i} of a is divided by the integer in doubleword
23544element @code{i} of b. The unique integer quotient is placed into the
23545doubleword element @code{i} of the vector returned. If an attempt is made to
23546perform any of the divisions 0x8000_0000_0000_0000 ÷ -1 or <anything> ÷ 0 then
23547the quotient is undefined.
23548
23549@smallexample
23550@exdent vector signed int
23795106 23551@exdent vec_dive (vector signed int @var{a}, vector signed int @var{b});
d77de738 23552@exdent vector unsigned int
23795106 23553@exdent vec_dive (vector unsigned int @var{a}, vector unsigned int @var{b});
d77de738
ML
23554@end smallexample
23555
23556For each integer value @code{i} from 0 to 3, do the following. The integer in
23557word element @code{i} of a is shifted left by 32 bits, then divided by the
23558integer in word element @code{i} of b. The unique integer quotient is placed
23559into the word element @code{i} of the vector returned. If the quotient cannot
23560be represented in 32 bits, or if an attempt is made to perform any of the
23561divisions <anything> ÷ 0 then the quotient is undefined.
23562
23563@smallexample
23564@exdent vector signed long long
23795106 23565@exdent vec_dive (vector signed long long @var{a}, vector signed long long @var{b});
d77de738 23566@exdent vector unsigned long long
23795106 23567@exdent vec_dive (vector unsigned long long @var{a}, vector unsigned long long @var{b});
d77de738
ML
23568@end smallexample
23569
23570For each integer value @code{i} from 0 to 1, do the following. The integer in
23571doubleword element @code{i} of a is shifted left by 64 bits, then divided by
23572the integer in doubleword element @code{i} of b. The unique integer quotient is
23573placed into the doubleword element @code{i} of the vector returned. If the
23574quotient cannot be represented in 64 bits, or if an attempt is made to perform
23575<anything> ÷ 0 then the quotient is undefined.
23576
23577@smallexample
23578@exdent vector signed int
23795106 23579@exdent vec_mod (vector signed int @var{a}, vector signed int @var{b});
d77de738 23580@exdent vector unsigned int
23795106 23581@exdent vec_mod (vector unsigned int @var{a}, vector unsigned int @var{b});
d77de738
ML
23582@end smallexample
23583
23584For each integer value @code{i} from 0 to 3, do the following. The integer in
23585word element @code{i} of a is divided by the integer in word element @code{i}
23586of b. The unique integer remainder is placed into the word element @code{i} of
23587the vector returned. If an attempt is made to perform any of the divisions
235880x8000_0000 ÷ -1 or <anything> ÷ 0 then the remainder is undefined.
23589
23590@smallexample
23591@exdent vector signed long long
23795106 23592@exdent vec_mod (vector signed long long @var{a}, vector signed long long @var{b});
d77de738 23593@exdent vector unsigned long long
23795106 23594@exdent vec_mod (vector unsigned long long @var{a}, vector unsigned long long @var{b});
d77de738
ML
23595@end smallexample
23596
23597For each integer value @code{i} from 0 to 1, do the following. The integer in
23598doubleword element @code{i} of a is divided by the integer in doubleword
23599element @code{i} of b. The unique integer remainder is placed into the
23600doubleword element @code{i} of the vector returned. If an attempt is made to
23601perform <anything> ÷ 0 then the remainder is undefined.
23602
23603Generate PCV from specified Mask size, as if implemented by the
23604@code{xxgenpcvbm}, @code{xxgenpcvhm}, @code{xxgenpcvwm} instructions, where
23605immediate value is either 0, 1, 2 or 3.
23606@findex vec_genpcvm
23607
23608@smallexample
23795106
JJ
23609@exdent vector unsigned __int128 vec_rl (vector unsigned __int128 @var{A},
23610 vector unsigned __int128 @var{B});
23611@exdent vector signed __int128 vec_rl (vector signed __int128 @var{A},
23612 vector unsigned __int128 @var{B});
d77de738
ML
23613@end smallexample
23614
23795106
JJ
23615Result value: Each element of @var{R} is obtained by rotating the corresponding element
23616of @var{A} left by the number of bits specified by the corresponding element of @var{B}.
d77de738
ML
23617
23618
23619@smallexample
23620@exdent vector unsigned __int128 vec_rlmi (vector unsigned __int128,
23621 vector unsigned __int128,
23622 vector unsigned __int128);
23623@exdent vector signed __int128 vec_rlmi (vector signed __int128,
23624 vector signed __int128,
23625 vector unsigned __int128);
23626@end smallexample
23627
23628Returns the result of rotating the first input and inserting it under mask
23629into the second input. The first bit in the mask, the last bit in the mask are
23630obtained from the two 7-bit fields bits [108:115] and bits [117:123]
23631respectively of the second input. The shift is obtained from the third input
23632in the 7-bit field [125:131] where all bits counted from zero at the left.
23633
23634@smallexample
23635@exdent vector unsigned __int128 vec_rlnm (vector unsigned __int128,
23636 vector unsigned __int128,
23637 vector unsigned __int128);
23638@exdent vector signed __int128 vec_rlnm (vector signed __int128,
23639 vector unsigned __int128,
23640 vector unsigned __int128);
23641@end smallexample
23642
23643Returns the result of rotating the first input and ANDing it with a mask. The
23644first bit in the mask and the last bit in the mask are obtained from the two
236457-bit fields bits [117:123] and bits [125:131] respectively of the second
23646input. The shift is obtained from the third input in the 7-bit field bits
23647[125:131] where all bits counted from zero at the left.
23648
23649@smallexample
23795106
JJ
23650@exdent vector unsigned __int128 vec_sl(vector unsigned __int128 @var{A}, vector unsigned __int128 @var{B});
23651@exdent vector signed __int128 vec_sl(vector signed __int128 @var{A}, vector unsigned __int128 @var{B});
d77de738
ML
23652@end smallexample
23653
23795106
JJ
23654Result value: Each element of @var{R} is obtained by shifting the corresponding element of
23655@var{A} left by the number of bits specified by the corresponding element of @var{B}.
d77de738
ML
23656
23657@smallexample
23795106
JJ
23658@exdent vector unsigned __int128 vec_sr(vector unsigned __int128 @var{A}, vector unsigned __int128 @var{B});
23659@exdent vector signed __int128 vec_sr(vector signed __int128 @var{A}, vector unsigned __int128 @var{B});
d77de738
ML
23660@end smallexample
23661
23795106
JJ
23662Result value: Each element of @var{R} is obtained by shifting the corresponding element of
23663@var{A} right by the number of bits specified by the corresponding element of @var{B}.
d77de738
ML
23664
23665@smallexample
23795106
JJ
23666@exdent vector unsigned __int128 vec_sra(vector unsigned __int128 @var{A}, vector unsigned __int128 @var{B});
23667@exdent vector signed __int128 vec_sra(vector signed __int128 @var{A}, vector unsigned __int128 @var{B});
d77de738
ML
23668@end smallexample
23669
23795106
JJ
23670Result value: Each element of @var{R} is obtained by arithmetic shifting the corresponding
23671element of @var{A} right by the number of bits specified by the corresponding element of @var{B}.
d77de738
ML
23672
23673@smallexample
23674@exdent vector unsigned __int128 vec_mule (vector unsigned long long,
23675 vector unsigned long long);
23676@exdent vector signed __int128 vec_mule (vector signed long long,
23677 vector signed long long);
23678@end smallexample
23679
23680Returns a vector containing a 128-bit integer result of multiplying the even
23681doubleword elements of the two inputs.
23682
23683@smallexample
23684@exdent vector unsigned __int128 vec_mulo (vector unsigned long long,
23685 vector unsigned long long);
23686@exdent vector signed __int128 vec_mulo (vector signed long long,
23687 vector signed long long);
23688@end smallexample
23689
23690Returns a vector containing a 128-bit integer result of multiplying the odd
23691doubleword elements of the two inputs.
23692
23693@smallexample
23694@exdent vector unsigned __int128 vec_div (vector unsigned __int128,
23695 vector unsigned __int128);
23696@exdent vector signed __int128 vec_div (vector signed __int128,
23697 vector signed __int128);
23698@end smallexample
23699
23700Returns the result of dividing the first operand by the second operand. An
23701attempt to divide any value by zero or to divide the most negative signed
23702128-bit integer by negative one results in an undefined value.
23703
23704@smallexample
23705@exdent vector unsigned __int128 vec_dive (vector unsigned __int128,
23706 vector unsigned __int128);
23707@exdent vector signed __int128 vec_dive (vector signed __int128,
23708 vector signed __int128);
23709@end smallexample
23710
23711The result is produced by shifting the first input left by 128 bits and
23712dividing by the second. If an attempt is made to divide by zero or the result
23713is larger than 128 bits, the result is undefined.
23714
23715@smallexample
23716@exdent vector unsigned __int128 vec_mod (vector unsigned __int128,
23717 vector unsigned __int128);
23718@exdent vector signed __int128 vec_mod (vector signed __int128,
23719 vector signed __int128);
23720@end smallexample
23721
23722The result is the modulo result of dividing the first input by the second
23723input.
23724
23725The following builtins perform 128-bit vector comparisons. The
23726@code{vec_all_xx}, @code{vec_any_xx}, and @code{vec_cmpxx}, where @code{xx} is
23727one of the operations @code{eq, ne, gt, lt, ge, le} perform pairwise
23728comparisons between the elements at the same positions within their two vector
23729arguments. The @code{vec_all_xx}function returns a non-zero value if and only
23730if all pairwise comparisons are true. The @code{vec_any_xx} function returns
23731a non-zero value if and only if at least one pairwise comparison is true. The
23732@code{vec_cmpxx}function returns a vector of the same type as its two
23733arguments, within which each element consists of all ones to denote that
23734specified logical comparison of the corresponding elements was true.
23735Otherwise, the element of the returned vector contains all zeros.
23736
23737@smallexample
23738vector bool __int128 vec_cmpeq (vector signed __int128, vector signed __int128);
23739vector bool __int128 vec_cmpeq (vector unsigned __int128, vector unsigned __int128);
23740vector bool __int128 vec_cmpne (vector signed __int128, vector signed __int128);
23741vector bool __int128 vec_cmpne (vector unsigned __int128, vector unsigned __int128);
23742vector bool __int128 vec_cmpgt (vector signed __int128, vector signed __int128);
23743vector bool __int128 vec_cmpgt (vector unsigned __int128, vector unsigned __int128);
23744vector bool __int128 vec_cmplt (vector signed __int128, vector signed __int128);
23745vector bool __int128 vec_cmplt (vector unsigned __int128, vector unsigned __int128);
23746vector bool __int128 vec_cmpge (vector signed __int128, vector signed __int128);
23747vector bool __int128 vec_cmpge (vector unsigned __int128, vector unsigned __int128);
23748vector bool __int128 vec_cmple (vector signed __int128, vector signed __int128);
23749vector bool __int128 vec_cmple (vector unsigned __int128, vector unsigned __int128);
23750
23751int vec_all_eq (vector signed __int128, vector signed __int128);
23752int vec_all_eq (vector unsigned __int128, vector unsigned __int128);
23753int vec_all_ne (vector signed __int128, vector signed __int128);
23754int vec_all_ne (vector unsigned __int128, vector unsigned __int128);
23755int vec_all_gt (vector signed __int128, vector signed __int128);
23756int vec_all_gt (vector unsigned __int128, vector unsigned __int128);
23757int vec_all_lt (vector signed __int128, vector signed __int128);
23758int vec_all_lt (vector unsigned __int128, vector unsigned __int128);
23759int vec_all_ge (vector signed __int128, vector signed __int128);
23760int vec_all_ge (vector unsigned __int128, vector unsigned __int128);
23761int vec_all_le (vector signed __int128, vector signed __int128);
23762int vec_all_le (vector unsigned __int128, vector unsigned __int128);
23763
23764int vec_any_eq (vector signed __int128, vector signed __int128);
23765int vec_any_eq (vector unsigned __int128, vector unsigned __int128);
23766int vec_any_ne (vector signed __int128, vector signed __int128);
23767int vec_any_ne (vector unsigned __int128, vector unsigned __int128);
23768int vec_any_gt (vector signed __int128, vector signed __int128);
23769int vec_any_gt (vector unsigned __int128, vector unsigned __int128);
23770int vec_any_lt (vector signed __int128, vector signed __int128);
23771int vec_any_lt (vector unsigned __int128, vector unsigned __int128);
23772int vec_any_ge (vector signed __int128, vector signed __int128);
23773int vec_any_ge (vector unsigned __int128, vector unsigned __int128);
23774int vec_any_le (vector signed __int128, vector signed __int128);
23775int vec_any_le (vector unsigned __int128, vector unsigned __int128);
23776@end smallexample
23777
23778
23779@node PowerPC Hardware Transactional Memory Built-in Functions
23780@subsection PowerPC Hardware Transactional Memory Built-in Functions
23781GCC provides two interfaces for accessing the Hardware Transactional
23782Memory (HTM) instructions available on some of the PowerPC family
23783of processors (eg, POWER8). The two interfaces come in a low level
23784interface, consisting of built-in functions specific to PowerPC and a
23785higher level interface consisting of inline functions that are common
23786between PowerPC and S/390.
23787
23788@subsubsection PowerPC HTM Low Level Built-in Functions
23789
23790The following low level built-in functions are available with
23791@option{-mhtm} or @option{-mcpu=CPU} where CPU is `power8' or later.
23792They all generate the machine instruction that is part of the name.
23793
23794The HTM builtins (with the exception of @code{__builtin_tbegin}) return
23795the full 4-bit condition register value set by their associated hardware
23796instruction. The header file @code{htmintrin.h} defines some macros that can
23797be used to decipher the return value. The @code{__builtin_tbegin} builtin
23798returns a simple @code{true} or @code{false} value depending on whether a transaction was
23799successfully started or not. The arguments of the builtins match exactly the
23800type and order of the associated hardware instruction's operands, except for
23801the @code{__builtin_tcheck} builtin, which does not take any input arguments.
23802Refer to the ISA manual for a description of each instruction's operands.
23803
23804@smallexample
23805unsigned int __builtin_tbegin (unsigned int);
23806unsigned int __builtin_tend (unsigned int);
23807
23808unsigned int __builtin_tabort (unsigned int);
23809unsigned int __builtin_tabortdc (unsigned int, unsigned int, unsigned int);
23810unsigned int __builtin_tabortdci (unsigned int, unsigned int, int);
23811unsigned int __builtin_tabortwc (unsigned int, unsigned int, unsigned int);
23812unsigned int __builtin_tabortwci (unsigned int, unsigned int, int);
23813
23814unsigned int __builtin_tcheck (void);
23815unsigned int __builtin_treclaim (unsigned int);
23816unsigned int __builtin_trechkpt (void);
23817unsigned int __builtin_tsr (unsigned int);
23818@end smallexample
23819
23820In addition to the above HTM built-ins, we have added built-ins for
23821some common extended mnemonics of the HTM instructions:
23822
23823@smallexample
23824unsigned int __builtin_tendall (void);
23825unsigned int __builtin_tresume (void);
23826unsigned int __builtin_tsuspend (void);
23827@end smallexample
23828
23829Note that the semantics of the above HTM builtins are required to mimic
23830the locking semantics used for critical sections. Builtins that are used
23831to create a new transaction or restart a suspended transaction must have
23832lock acquisition like semantics while those builtins that end or suspend a
23833transaction must have lock release like semantics. Specifically, this must
23834mimic lock semantics as specified by C++11, for example: Lock acquisition is
23835as-if an execution of __atomic_exchange_n(&globallock,1,__ATOMIC_ACQUIRE)
23836that returns 0, and lock release is as-if an execution of
23837__atomic_store(&globallock,0,__ATOMIC_RELEASE), with globallock being an
23838implicit implementation-defined lock used for all transactions. The HTM
23839instructions associated with with the builtins inherently provide the
23840correct acquisition and release hardware barriers required. However,
23841the compiler must also be prohibited from moving loads and stores across
23842the builtins in a way that would violate their semantics. This has been
23843accomplished by adding memory barriers to the associated HTM instructions
23844(which is a conservative approach to provide acquire and release semantics).
23845Earlier versions of the compiler did not treat the HTM instructions as
23846memory barriers. A @code{__TM_FENCE__} macro has been added, which can
23847be used to determine whether the current compiler treats HTM instructions
23848as memory barriers or not. This allows the user to explicitly add memory
23849barriers to their code when using an older version of the compiler.
23850
23851The following set of built-in functions are available to gain access
23852to the HTM specific special purpose registers.
23853
23854@smallexample
23855unsigned long __builtin_get_texasr (void);
23856unsigned long __builtin_get_texasru (void);
23857unsigned long __builtin_get_tfhar (void);
23858unsigned long __builtin_get_tfiar (void);
23859
23860void __builtin_set_texasr (unsigned long);
23861void __builtin_set_texasru (unsigned long);
23862void __builtin_set_tfhar (unsigned long);
23863void __builtin_set_tfiar (unsigned long);
23864@end smallexample
23865
23866Example usage of these low level built-in functions may look like:
23867
23868@smallexample
23869#include <htmintrin.h>
23870
23871int num_retries = 10;
23872
23873while (1)
23874 @{
23875 if (__builtin_tbegin (0))
23876 @{
23877 /* Transaction State Initiated. */
23878 if (is_locked (lock))
23879 __builtin_tabort (0);
23880 ... transaction code...
23881 __builtin_tend (0);
23882 break;
23883 @}
23884 else
23885 @{
23886 /* Transaction State Failed. Use locks if the transaction
23887 failure is "persistent" or we've tried too many times. */
23888 if (num_retries-- <= 0
23889 || _TEXASRU_FAILURE_PERSISTENT (__builtin_get_texasru ()))
23890 @{
23891 acquire_lock (lock);
23892 ... non transactional fallback path...
23893 release_lock (lock);
23894 break;
23895 @}
23896 @}
23897 @}
23898@end smallexample
23899
23900One final built-in function has been added that returns the value of
23901the 2-bit Transaction State field of the Machine Status Register (MSR)
23902as stored in @code{CR0}.
23903
23904@smallexample
23905unsigned long __builtin_ttest (void)
23906@end smallexample
23907
23908This built-in can be used to determine the current transaction state
23909using the following code example:
23910
23911@smallexample
23912#include <htmintrin.h>
23913
23914unsigned char tx_state = _HTM_STATE (__builtin_ttest ());
23915
23916if (tx_state == _HTM_TRANSACTIONAL)
23917 @{
23918 /* Code to use in transactional state. */
23919 @}
23920else if (tx_state == _HTM_NONTRANSACTIONAL)
23921 @{
23922 /* Code to use in non-transactional state. */
23923 @}
23924else if (tx_state == _HTM_SUSPENDED)
23925 @{
23926 /* Code to use in transaction suspended state. */
23927 @}
23928@end smallexample
23929
23930@subsubsection PowerPC HTM High Level Inline Functions
23931
23932The following high level HTM interface is made available by including
23933@code{<htmxlintrin.h>} and using @option{-mhtm} or @option{-mcpu=CPU}
23934where CPU is `power8' or later. This interface is common between PowerPC
23935and S/390, allowing users to write one HTM source implementation that
23936can be compiled and executed on either system.
23937
23938@smallexample
23939long __TM_simple_begin (void);
23940long __TM_begin (void* const TM_buff);
23941long __TM_end (void);
23942void __TM_abort (void);
23943void __TM_named_abort (unsigned char const code);
23944void __TM_resume (void);
23945void __TM_suspend (void);
23946
23947long __TM_is_user_abort (void* const TM_buff);
23948long __TM_is_named_user_abort (void* const TM_buff, unsigned char *code);
23949long __TM_is_illegal (void* const TM_buff);
23950long __TM_is_footprint_exceeded (void* const TM_buff);
23951long __TM_nesting_depth (void* const TM_buff);
23952long __TM_is_nested_too_deep(void* const TM_buff);
23953long __TM_is_conflict(void* const TM_buff);
23954long __TM_is_failure_persistent(void* const TM_buff);
23955long __TM_failure_address(void* const TM_buff);
23956long long __TM_failure_code(void* const TM_buff);
23957@end smallexample
23958
23959Using these common set of HTM inline functions, we can create
23960a more portable version of the HTM example in the previous
23961section that will work on either PowerPC or S/390:
23962
23963@smallexample
23964#include <htmxlintrin.h>
23965
23966int num_retries = 10;
23967TM_buff_type TM_buff;
23968
23969while (1)
23970 @{
23971 if (__TM_begin (TM_buff) == _HTM_TBEGIN_STARTED)
23972 @{
23973 /* Transaction State Initiated. */
23974 if (is_locked (lock))
23975 __TM_abort ();
23976 ... transaction code...
23977 __TM_end ();
23978 break;
23979 @}
23980 else
23981 @{
23982 /* Transaction State Failed. Use locks if the transaction
23983 failure is "persistent" or we've tried too many times. */
23984 if (num_retries-- <= 0
23985 || __TM_is_failure_persistent (TM_buff))
23986 @{
23987 acquire_lock (lock);
23988 ... non transactional fallback path...
23989 release_lock (lock);
23990 break;
23991 @}
23992 @}
23993 @}
23994@end smallexample
23995
23996@node PowerPC Atomic Memory Operation Functions
23997@subsection PowerPC Atomic Memory Operation Functions
23998ISA 3.0 of the PowerPC added new atomic memory operation (amo)
23999instructions. GCC provides support for these instructions in 64-bit
24000environments. All of the functions are declared in the include file
24001@code{amo.h}.
24002
24003The functions supported are:
24004
24005@smallexample
24006#include <amo.h>
24007
24008uint32_t amo_lwat_add (uint32_t *, uint32_t);
24009uint32_t amo_lwat_xor (uint32_t *, uint32_t);
24010uint32_t amo_lwat_ior (uint32_t *, uint32_t);
24011uint32_t amo_lwat_and (uint32_t *, uint32_t);
24012uint32_t amo_lwat_umax (uint32_t *, uint32_t);
24013uint32_t amo_lwat_umin (uint32_t *, uint32_t);
24014uint32_t amo_lwat_swap (uint32_t *, uint32_t);
24015
24016int32_t amo_lwat_sadd (int32_t *, int32_t);
24017int32_t amo_lwat_smax (int32_t *, int32_t);
24018int32_t amo_lwat_smin (int32_t *, int32_t);
24019int32_t amo_lwat_sswap (int32_t *, int32_t);
24020
24021uint64_t amo_ldat_add (uint64_t *, uint64_t);
24022uint64_t amo_ldat_xor (uint64_t *, uint64_t);
24023uint64_t amo_ldat_ior (uint64_t *, uint64_t);
24024uint64_t amo_ldat_and (uint64_t *, uint64_t);
24025uint64_t amo_ldat_umax (uint64_t *, uint64_t);
24026uint64_t amo_ldat_umin (uint64_t *, uint64_t);
24027uint64_t amo_ldat_swap (uint64_t *, uint64_t);
24028
24029int64_t amo_ldat_sadd (int64_t *, int64_t);
24030int64_t amo_ldat_smax (int64_t *, int64_t);
24031int64_t amo_ldat_smin (int64_t *, int64_t);
24032int64_t amo_ldat_sswap (int64_t *, int64_t);
24033
24034void amo_stwat_add (uint32_t *, uint32_t);
24035void amo_stwat_xor (uint32_t *, uint32_t);
24036void amo_stwat_ior (uint32_t *, uint32_t);
24037void amo_stwat_and (uint32_t *, uint32_t);
24038void amo_stwat_umax (uint32_t *, uint32_t);
24039void amo_stwat_umin (uint32_t *, uint32_t);
24040
24041void amo_stwat_sadd (int32_t *, int32_t);
24042void amo_stwat_smax (int32_t *, int32_t);
24043void amo_stwat_smin (int32_t *, int32_t);
24044
24045void amo_stdat_add (uint64_t *, uint64_t);
24046void amo_stdat_xor (uint64_t *, uint64_t);
24047void amo_stdat_ior (uint64_t *, uint64_t);
24048void amo_stdat_and (uint64_t *, uint64_t);
24049void amo_stdat_umax (uint64_t *, uint64_t);
24050void amo_stdat_umin (uint64_t *, uint64_t);
24051
24052void amo_stdat_sadd (int64_t *, int64_t);
24053void amo_stdat_smax (int64_t *, int64_t);
24054void amo_stdat_smin (int64_t *, int64_t);
24055@end smallexample
24056
24057@node PowerPC Matrix-Multiply Assist Built-in Functions
24058@subsection PowerPC Matrix-Multiply Assist Built-in Functions
24059ISA 3.1 of the PowerPC added new Matrix-Multiply Assist (MMA) instructions.
24060GCC provides support for these instructions through the following built-in
24061functions which are enabled with the @code{-mmma} option. The vec_t type
24062below is defined to be a normal vector unsigned char type. The uint2, uint4
24063and uint8 parameters are 2-bit, 4-bit and 8-bit unsigned integer constants
24064respectively. The compiler will verify that they are constants and that
24065their values are within range.
24066
24067The built-in functions supported are:
24068
24069@smallexample
24070void __builtin_mma_xvi4ger8 (__vector_quad *, vec_t, vec_t);
24071void __builtin_mma_xvi8ger4 (__vector_quad *, vec_t, vec_t);
24072void __builtin_mma_xvi16ger2 (__vector_quad *, vec_t, vec_t);
24073void __builtin_mma_xvi16ger2s (__vector_quad *, vec_t, vec_t);
24074void __builtin_mma_xvf16ger2 (__vector_quad *, vec_t, vec_t);
24075void __builtin_mma_xvbf16ger2 (__vector_quad *, vec_t, vec_t);
24076void __builtin_mma_xvf32ger (__vector_quad *, vec_t, vec_t);
24077
24078void __builtin_mma_xvi4ger8pp (__vector_quad *, vec_t, vec_t);
24079void __builtin_mma_xvi8ger4pp (__vector_quad *, vec_t, vec_t);
24080void __builtin_mma_xvi8ger4spp(__vector_quad *, vec_t, vec_t);
24081void __builtin_mma_xvi16ger2pp (__vector_quad *, vec_t, vec_t);
24082void __builtin_mma_xvi16ger2spp (__vector_quad *, vec_t, vec_t);
24083void __builtin_mma_xvf16ger2pp (__vector_quad *, vec_t, vec_t);
24084void __builtin_mma_xvf16ger2pn (__vector_quad *, vec_t, vec_t);
24085void __builtin_mma_xvf16ger2np (__vector_quad *, vec_t, vec_t);
24086void __builtin_mma_xvf16ger2nn (__vector_quad *, vec_t, vec_t);
24087void __builtin_mma_xvbf16ger2pp (__vector_quad *, vec_t, vec_t);
24088void __builtin_mma_xvbf16ger2pn (__vector_quad *, vec_t, vec_t);
24089void __builtin_mma_xvbf16ger2np (__vector_quad *, vec_t, vec_t);
24090void __builtin_mma_xvbf16ger2nn (__vector_quad *, vec_t, vec_t);
24091void __builtin_mma_xvf32gerpp (__vector_quad *, vec_t, vec_t);
24092void __builtin_mma_xvf32gerpn (__vector_quad *, vec_t, vec_t);
24093void __builtin_mma_xvf32gernp (__vector_quad *, vec_t, vec_t);
24094void __builtin_mma_xvf32gernn (__vector_quad *, vec_t, vec_t);
24095
24096void __builtin_mma_pmxvi4ger8 (__vector_quad *, vec_t, vec_t, uint4, uint4, uint8);
24097void __builtin_mma_pmxvi4ger8pp (__vector_quad *, vec_t, vec_t, uint4, uint4, uint8);
24098
24099void __builtin_mma_pmxvi8ger4 (__vector_quad *, vec_t, vec_t, uint4, uint4, uint4);
24100void __builtin_mma_pmxvi8ger4pp (__vector_quad *, vec_t, vec_t, uint4, uint4, uint4);
24101void __builtin_mma_pmxvi8ger4spp(__vector_quad *, vec_t, vec_t, uint4, uint4, uint4);
24102
24103void __builtin_mma_pmxvi16ger2 (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2);
24104void __builtin_mma_pmxvi16ger2s (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2);
24105void __builtin_mma_pmxvf16ger2 (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2);
24106void __builtin_mma_pmxvbf16ger2 (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2);
24107
24108void __builtin_mma_pmxvi16ger2pp (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2);
24109void __builtin_mma_pmxvi16ger2spp (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2);
24110void __builtin_mma_pmxvf16ger2pp (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2);
24111void __builtin_mma_pmxvf16ger2pn (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2);
24112void __builtin_mma_pmxvf16ger2np (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2);
24113void __builtin_mma_pmxvf16ger2nn (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2);
24114void __builtin_mma_pmxvbf16ger2pp (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2);
24115void __builtin_mma_pmxvbf16ger2pn (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2);
24116void __builtin_mma_pmxvbf16ger2np (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2);
24117void __builtin_mma_pmxvbf16ger2nn (__vector_quad *, vec_t, vec_t, uint4, uint4, uint2);
24118
24119void __builtin_mma_pmxvf32ger (__vector_quad *, vec_t, vec_t, uint4, uint4);
24120void __builtin_mma_pmxvf32gerpp (__vector_quad *, vec_t, vec_t, uint4, uint4);
24121void __builtin_mma_pmxvf32gerpn (__vector_quad *, vec_t, vec_t, uint4, uint4);
24122void __builtin_mma_pmxvf32gernp (__vector_quad *, vec_t, vec_t, uint4, uint4);
24123void __builtin_mma_pmxvf32gernn (__vector_quad *, vec_t, vec_t, uint4, uint4);
24124
24125void __builtin_mma_xvf64ger (__vector_quad *, __vector_pair, vec_t);
24126void __builtin_mma_xvf64gerpp (__vector_quad *, __vector_pair, vec_t);
24127void __builtin_mma_xvf64gerpn (__vector_quad *, __vector_pair, vec_t);
24128void __builtin_mma_xvf64gernp (__vector_quad *, __vector_pair, vec_t);
24129void __builtin_mma_xvf64gernn (__vector_quad *, __vector_pair, vec_t);
24130
24131void __builtin_mma_pmxvf64ger (__vector_quad *, __vector_pair, vec_t, uint4, uint2);
24132void __builtin_mma_pmxvf64gerpp (__vector_quad *, __vector_pair, vec_t, uint4, uint2);
24133void __builtin_mma_pmxvf64gerpn (__vector_quad *, __vector_pair, vec_t, uint4, uint2);
24134void __builtin_mma_pmxvf64gernp (__vector_quad *, __vector_pair, vec_t, uint4, uint2);
24135void __builtin_mma_pmxvf64gernn (__vector_quad *, __vector_pair, vec_t, uint4, uint2);
24136
24137void __builtin_mma_xxmtacc (__vector_quad *);
24138void __builtin_mma_xxmfacc (__vector_quad *);
24139void __builtin_mma_xxsetaccz (__vector_quad *);
24140
24141void __builtin_mma_build_acc (__vector_quad *, vec_t, vec_t, vec_t, vec_t);
24142void __builtin_mma_disassemble_acc (void *, __vector_quad *);
24143
24144void __builtin_vsx_build_pair (__vector_pair *, vec_t, vec_t);
24145void __builtin_vsx_disassemble_pair (void *, __vector_pair *);
24146
24147vec_t __builtin_vsx_xvcvspbf16 (vec_t);
24148vec_t __builtin_vsx_xvcvbf16spn (vec_t);
24149
24150__vector_pair __builtin_vsx_lxvp (size_t, __vector_pair *);
24151void __builtin_vsx_stxvp (__vector_pair, size_t, __vector_pair *);
24152@end smallexample
24153
24154@node PRU Built-in Functions
24155@subsection PRU Built-in Functions
24156
24157GCC provides a couple of special builtin functions to aid in utilizing
24158special PRU instructions.
24159
24160The built-in functions supported are:
24161
f25efe50 24162@defbuiltin{void __delay_cycles (constant long long @var{cycles})}
d77de738
ML
24163This inserts an instruction sequence that takes exactly @var{cycles}
24164cycles (between 0 and 0xffffffff) to complete. The inserted sequence
24165may use jumps, loops, or no-ops, and does not interfere with any other
24166instructions. Note that @var{cycles} must be a compile-time constant
24167integer - that is, you must pass a number, not a variable that may be
24168optimized to a constant later. The number of cycles delayed by this
24169builtin is exact.
f25efe50 24170@enddefbuiltin
d77de738 24171
f25efe50 24172@defbuiltin{void __halt (void)}
d77de738 24173This inserts a HALT instruction to stop processor execution.
f25efe50 24174@enddefbuiltin
d77de738 24175
f25efe50
AA
24176@defbuiltin{{unsigned int} @
24177 __lmbd (unsigned int @var{wordval}, @
24178 unsigned int @var{bitval})}
d77de738
ML
24179This inserts LMBD instruction to calculate the left-most bit with value
24180@var{bitval} in value @var{wordval}. Only the least significant bit
24181of @var{bitval} is taken into account.
f25efe50 24182@enddefbuiltin
d77de738
ML
24183
24184@node RISC-V Built-in Functions
24185@subsection RISC-V Built-in Functions
24186
24187These built-in functions are available for the RISC-V family of
24188processors.
24189
f25efe50 24190@defbuiltin{{void *} __builtin_thread_pointer (void)}
d77de738 24191Returns the value that is currently set in the @samp{tp} register.
f25efe50 24192@enddefbuiltin
d77de738 24193
f25efe50 24194@defbuiltin{void __builtin_riscv_pause (void)}
cf64ab18
TO
24195Generates the @code{pause} (hint) machine instruction. If the target implements
24196the Zihintpause extension, it indicates that the current hart should be
24197temporarily paused or slowed down.
f25efe50 24198@enddefbuiltin
c717a92d 24199
14c1a8df
KC
24200@node RISC-V Vector Intrinsics
24201@subsection RISC-V Vector Intrinsics
24202
24203GCC supports vector intrinsics as specified in version 0.11 of the RISC-V
24204vector intrinsic specification, which is available at the following link:
24205@uref{https://github.com/riscv-non-isa/rvv-intrinsic-doc/tree/v0.11.x}.
24206All of these functions are declared in the include file @file{riscv_vector.h}.
24207
400efddd 24208@node CORE-V Built-in Functions
e99ad401 24209@subsection CORE-V Built-in Functions
400efddd
MB
24210
24211These built-in functions are available for the CORE-V MAC machine
24212architecture. For more information on CORE-V built-ins, please see
24213@uref{https://github.com/openhwgroup/core-v-sw/blob/master/specifications/corev-builtin-spec.md#listing-of-multiply-accumulate-builtins-xcvmac}.
24214
24215@deftypefn {Built-in Function} {int32_t} __builtin_riscv_cv_mac_mac (int32_t, int32_t, int32_t)
24216Generated assembler @code{cv.mac}
24217@end deftypefn
24218
24219@deftypefn {Built-in Function} {int32_t} __builtin_riscv_cv_mac_msu (int32_t, int32_t, int32_t)
24220Generates the @code{cv.msu} machine instruction.
24221@end deftypefn
24222
24223@deftypefn {Built-in Function} {uint32_t} __builtin_riscv_cv_mac_muluN (uint32_t, uint32_t, uint8_t)
24224Generates the @code{cv.muluN} machine instruction.
24225@end deftypefn
24226
24227@deftypefn {Built-in Function} {uint32_t} __builtin_riscv_cv_mac_mulhhuN (uint32_t, uint32_t, uint8_t)
24228Generates the @code{cv.mulhhuN} machine instruction.
24229@end deftypefn
24230
24231@deftypefn {Built-in Function} {int32_t} __builtin_riscv_cv_mac_mulsN (int32_t, int32_t, uint8_t)
24232Generates the @code{cv.mulsN} machine instruction.
24233@end deftypefn
24234
24235@deftypefn {Built-in Function} {int32_t} __builtin_riscv_cv_mac_mulhhsN (int32_t, int32_t, uint8_t)
24236Generates the @code{cv.mulhhsN} machine instruction.
24237@end deftypefn
24238
24239@deftypefn {Built-in Function} {uint32_t} __builtin_riscv_cv_mac_muluRN (uint32_t, uint32_t, uint8_t)
24240Generates the @code{cv.muluRN} machine instruction.
24241@end deftypefn
24242
24243@deftypefn {Built-in Function} {uint32_t} __builtin_riscv_cv_mac_mulhhuRN (uint32_t, uint32_t, uint8_t)
24244Generates the @code{cv.mulhhuRN} machine instruction.
24245@end deftypefn
24246
24247@deftypefn {Built-in Function} {int32_t} __builtin_riscv_cv_mac_mulsRN (int32_t, int32_t, uint8_t)
24248Generates the @code{cv.mulsRN} machine instruction.
24249@end deftypefn
24250
24251@deftypefn {Built-in Function} {int32_t} __builtin_riscv_cv_mac_mulhhsRN (int32_t, int32_t, uint8_t)
24252Generates the @code{cv.mulhhsRN} machine instruction.
24253@end deftypefn
24254
24255@deftypefn {Built-in Function} {uint32_t} __builtin_riscv_cv_mac_macuN (uint32_t, uint32_t, uint8_t)
24256Generates the @code{cv.macuN} machine instruction.
24257@end deftypefn
24258
24259@deftypefn {Built-in Function} {uint32_t} __builtin_riscv_cv_mac_machhuN (uint32_t, uint32_t, uint8_t)
24260Generates the @code{cv.machhuN} machine instruction.
24261@end deftypefn
24262
24263@deftypefn {Built-in Function} {int32_t} __builtin_riscv_cv_mac_macsN (int32_t, int32_t, uint8_t)
24264Generates the @code{cv.macsN} machine instruction.
24265@end deftypefn
24266
24267@deftypefn {Built-in Function} {int32_t} __builtin_riscv_cv_mac_machhsN (int32_t, int32_t, uint8_t)
24268Generates the @code{cv.machhsN} machine instruction.
24269@end deftypefn
24270
24271@deftypefn {Built-in Function} {uint32_t} __builtin_riscv_cv_mac_macuRN (uint32_t, uint32_t, uint8_t)
24272Generates the @code{cv.macuRN} machine instruction.
24273@end deftypefn
24274
24275@deftypefn {Built-in Function} {uint32_t} __builtin_riscv_cv_mac_machhuRN (uint32_t, uint32_t, uint8_t)
24276Generates the @code{cv.machhuRN} machine instruction.
24277@end deftypefn
24278
24279@deftypefn {Built-in Function} {int32_t} __builtin_riscv_cv_mac_macsRN (int32_t, int32_t, uint8_t)
24280Generates the @code{cv.macsRN} machine instruction.
24281@end deftypefn
24282
24283@deftypefn {Built-in Function} {int32_t} __builtin_riscv_cv_mac_machhsRN (int32_t, int32_t, uint8_t)
24284Generates the @code{cv.machhsRN} machine instruction.
24285@end deftypefn
24286
5ef248c1
MB
24287These built-in functions are available for the CORE-V ALU machine
24288architecture. For more information on CORE-V built-ins, please see
24289@uref{https://github.com/openhwgroup/core-v-sw/blob/master/specifications/corev-builtin-spec.md#listing-of-miscellaneous-alu-builtins-xcvalu}
24290
24291@deftypefn {Built-in Function} {int} __builtin_riscv_cv_alu_slet (int32_t, int32_t)
24292Generated assembler @code{cv.slet}
24293@end deftypefn
24294
24295@deftypefn {Built-in Function} {int} __builtin_riscv_cv_alu_sletu (uint32_t, uint32_t)
24296Generated assembler @code{cv.sletu}
24297@end deftypefn
24298
24299@deftypefn {Built-in Function} {int32_t} __builtin_riscv_cv_alu_min (int32_t, int32_t)
24300Generated assembler @code{cv.min}
24301@end deftypefn
24302
24303@deftypefn {Built-in Function} {uint32_t} __builtin_riscv_cv_alu_minu (uint32_t, uint32_t)
24304Generated assembler @code{cv.minu}
24305@end deftypefn
24306
24307@deftypefn {Built-in Function} {int32_t} __builtin_riscv_cv_alu_max (int32_t, int32_t)
24308Generated assembler @code{cv.max}
24309@end deftypefn
24310
24311@deftypefn {Built-in Function} {uint32_tnt} __builtin_riscv_cv_alu_maxu (uint32_t, uint32_t)
24312Generated assembler @code{cv.maxu}
24313@end deftypefn
24314
24315@deftypefn {Built-in Function} {int32_t} __builtin_riscv_cv_alu_exths (int16_t)
24316Generated assembler @code{cv.exths}
24317@end deftypefn
24318
24319@deftypefn {Built-in Function} {uint32_t} __builtin_riscv_cv_alu_exthz (uint16_t)
24320Generated assembler @code{cv.exthz}
24321@end deftypefn
24322
24323@deftypefn {Built-in Function} {int32_t} __builtin_riscv_cv_alu_extbs (int8_t)
24324Generated assembler @code{cv.extbs}
24325@end deftypefn
24326
24327@deftypefn {Built-in Function} {uint32_t} __builtin_riscv_cv_alu_extbz (uint8_t)
24328Generated assembler @code{cv.extbz}
24329@end deftypefn
24330
24331@deftypefn {Built-in Function} {int32_t} __builtin_riscv_cv_alu_clip (int32_t, uint32_t)
24332Generated assembler @code{cv.clip} if the uint32_t operand is a constant and an exact power of 2.
24333Generated assembler @code{cv.clipr} if the it is a register.
24334@end deftypefn
24335
24336@deftypefn {Built-in Function} {uint32_t} __builtin_riscv_cv_alu_clipu (uint32_t, uint32_t)
24337Generated assembler @code{cv.clipu} if the uint32_t operand is a constant and an exact power of 2.
24338Generated assembler @code{cv.clipur} if the it is a register.
24339@end deftypefn
24340
24341@deftypefn {Built-in Function} {int32_t} __builtin_riscv_cv_alu_addN (int32_t, int32_t, uint8_t)
24342Generated assembler @code{cv.addN} if the uint8_t operand is a constant and in the range 0 <= shft <= 31.
24343Generated assembler @code{cv.addNr} if the it is a register.
24344@end deftypefn
24345
24346@deftypefn {Built-in Function} {uint32_t} __builtin_riscv_cv_alu_adduN (uint32_t, uint32_t, uint8_t)
24347Generated assembler @code{cv.adduN} if the uint8_t operand is a constant and in the range 0 <= shft <= 31.
24348Generated assembler @code{cv.adduNr} if the it is a register.
24349@end deftypefn
24350
24351@deftypefn {Built-in Function} {int32_t} __builtin_riscv_cv_alu_addRN (int32_t, int32_t, uint8_t)
24352Generated assembler @code{cv.addRN} if the uint8_t operand is a constant and in the range 0 <= shft <= 31.
24353Generated assembler @code{cv.addRNr} if the it is a register.
24354@end deftypefn
24355
24356@deftypefn {Built-in Function} {uint32_t} __builtin_riscv_cv_alu_adduRN (uint32_t, uint32_t, uint8_t)
24357Generated assembler @code{cv.adduRN} if the uint8_t operand is a constant and in the range 0 <= shft <= 31.
24358Generated assembler @code{cv.adduRNr} if the it is a register.
24359@end deftypefn
24360
24361@deftypefn {Built-in Function} {int32_t} __builtin_riscv_cv_alu_subN (int32_t, int32_t, uint8_t)
24362Generated assembler @code{cv.subN} if the uint8_t operand is a constant and in the range 0 <= shft <= 31.
24363Generated assembler @code{cv.subNr} if the it is a register.
24364@end deftypefn
24365
24366@deftypefn {Built-in Function} {uint32_t} __builtin_riscv_cv_alu_subuN (uint32_t, uint32_t, uint8_t)
24367Generated assembler @code{cv.subuN} if the uint8_t operand is a constant and in the range 0 <= shft <= 31.
24368Generated assembler @code{cv.subuNr} if the it is a register.
24369@end deftypefn
24370
24371@deftypefn {Built-in Function} {int32_t} __builtin_riscv_cv_alu_subRN (int32_t, int32_t, uint8_t)
24372Generated assembler @code{cv.subRN} if the uint8_t operand is a constant and in the range 0 <= shft <= 31.
24373Generated assembler @code{cv.subRNr} if the it is a register.
24374@end deftypefn
24375
24376@deftypefn {Built-in Function} {uint32_t} __builtin_riscv_cv_alu_subuRN (uint32_t, uint32_t, uint8_t)
24377Generated assembler @code{cv.subuRN} if the uint8_t operand is a constant and in the range 0 <= shft <= 31.
24378Generated assembler @code{cv.subuRNr} if the it is a register.
24379@end deftypefn
24380
14876d6a
MB
24381These built-in functions are available for the CORE-V Event Load machine
24382architecture. For more information on CORE-V ELW builtins, please see
24383@uref{https://github.com/openhwgroup/core-v-sw/blob/master/specifications/corev-builtin-spec.md#listing-of-event-load-word-builtins-xcvelw}
24384
24385@deftypefn {Built-in Function} {uint32_t} __builtin_riscv_cv_elw_elw (uint32_t *)
24386Generated assembler @code{cv.elw}
24387@end deftypefn
24388
d77de738
ML
24389@node RX Built-in Functions
24390@subsection RX Built-in Functions
24391GCC supports some of the RX instructions which cannot be expressed in
24392the C programming language via the use of built-in functions. The
24393following functions are supported:
24394
f25efe50 24395@defbuiltin{void __builtin_rx_brk (void)}
d77de738 24396Generates the @code{brk} machine instruction.
f25efe50 24397@enddefbuiltin
d77de738 24398
f25efe50 24399@defbuiltin{void __builtin_rx_clrpsw (int)}
d77de738
ML
24400Generates the @code{clrpsw} machine instruction to clear the specified
24401bit in the processor status word.
f25efe50 24402@enddefbuiltin
d77de738 24403
f25efe50 24404@defbuiltin{void __builtin_rx_int (int)}
d77de738
ML
24405Generates the @code{int} machine instruction to generate an interrupt
24406with the specified value.
f25efe50 24407@enddefbuiltin
d77de738 24408
f25efe50 24409@defbuiltin{void __builtin_rx_machi (int, int)}
d77de738
ML
24410Generates the @code{machi} machine instruction to add the result of
24411multiplying the top 16 bits of the two arguments into the
24412accumulator.
f25efe50 24413@enddefbuiltin
d77de738 24414
f25efe50 24415@defbuiltin{void __builtin_rx_maclo (int, int)}
d77de738
ML
24416Generates the @code{maclo} machine instruction to add the result of
24417multiplying the bottom 16 bits of the two arguments into the
24418accumulator.
f25efe50 24419@enddefbuiltin
d77de738 24420
f25efe50 24421@defbuiltin{void __builtin_rx_mulhi (int, int)}
d77de738
ML
24422Generates the @code{mulhi} machine instruction to place the result of
24423multiplying the top 16 bits of the two arguments into the
24424accumulator.
f25efe50 24425@enddefbuiltin
d77de738 24426
f25efe50 24427@defbuiltin{void __builtin_rx_mullo (int, int)}
d77de738
ML
24428Generates the @code{mullo} machine instruction to place the result of
24429multiplying the bottom 16 bits of the two arguments into the
24430accumulator.
f25efe50 24431@enddefbuiltin
d77de738 24432
ff99671a 24433@defbuiltin{int __builtin_rx_mvfachi (void)}
d77de738
ML
24434Generates the @code{mvfachi} machine instruction to read the top
2443532 bits of the accumulator.
f25efe50 24436@enddefbuiltin
d77de738 24437
ff99671a 24438@defbuiltin{int __builtin_rx_mvfacmi (void)}
d77de738
ML
24439Generates the @code{mvfacmi} machine instruction to read the middle
2444032 bits of the accumulator.
f25efe50 24441@enddefbuiltin
d77de738 24442
f25efe50 24443@defbuiltin{int __builtin_rx_mvfc (int)}
d77de738
ML
24444Generates the @code{mvfc} machine instruction which reads the control
24445register specified in its argument and returns its value.
f25efe50 24446@enddefbuiltin
d77de738 24447
f25efe50 24448@defbuiltin{void __builtin_rx_mvtachi (int)}
d77de738
ML
24449Generates the @code{mvtachi} machine instruction to set the top
2445032 bits of the accumulator.
f25efe50 24451@enddefbuiltin
d77de738 24452
f25efe50 24453@defbuiltin{void __builtin_rx_mvtaclo (int)}
d77de738
ML
24454Generates the @code{mvtaclo} machine instruction to set the bottom
2445532 bits of the accumulator.
f25efe50 24456@enddefbuiltin
d77de738 24457
23795106 24458@defbuiltin{void __builtin_rx_mvtc (int @var{reg}, int @var{val})}
d77de738
ML
24459Generates the @code{mvtc} machine instruction which sets control
24460register number @code{reg} to @code{val}.
f25efe50 24461@enddefbuiltin
d77de738 24462
f25efe50 24463@defbuiltin{void __builtin_rx_mvtipl (int)}
d77de738
ML
24464Generates the @code{mvtipl} machine instruction set the interrupt
24465priority level.
f25efe50 24466@enddefbuiltin
d77de738 24467
f25efe50 24468@defbuiltin{void __builtin_rx_racw (int)}
d77de738
ML
24469Generates the @code{racw} machine instruction to round the accumulator
24470according to the specified mode.
f25efe50 24471@enddefbuiltin
d77de738 24472
f25efe50 24473@defbuiltin{int __builtin_rx_revw (int)}
d77de738
ML
24474Generates the @code{revw} machine instruction which swaps the bytes in
24475the argument so that bits 0--7 now occupy bits 8--15 and vice versa,
24476and also bits 16--23 occupy bits 24--31 and vice versa.
f25efe50 24477@enddefbuiltin
d77de738 24478
f25efe50 24479@defbuiltin{void __builtin_rx_rmpa (void)}
d77de738
ML
24480Generates the @code{rmpa} machine instruction which initiates a
24481repeated multiply and accumulate sequence.
f25efe50 24482@enddefbuiltin
d77de738 24483
f25efe50 24484@defbuiltin{void __builtin_rx_round (float)}
d77de738
ML
24485Generates the @code{round} machine instruction which returns the
24486floating-point argument rounded according to the current rounding mode
24487set in the floating-point status word register.
f25efe50 24488@enddefbuiltin
d77de738 24489
f25efe50 24490@defbuiltin{int __builtin_rx_sat (int)}
d77de738
ML
24491Generates the @code{sat} machine instruction which returns the
24492saturated value of the argument.
f25efe50 24493@enddefbuiltin
d77de738 24494
f25efe50 24495@defbuiltin{void __builtin_rx_setpsw (int)}
d77de738
ML
24496Generates the @code{setpsw} machine instruction to set the specified
24497bit in the processor status word.
f25efe50 24498@enddefbuiltin
d77de738 24499
f25efe50 24500@defbuiltin{void __builtin_rx_wait (void)}
d77de738 24501Generates the @code{wait} machine instruction.
f25efe50 24502@enddefbuiltin
d77de738
ML
24503
24504@node S/390 System z Built-in Functions
24505@subsection S/390 System z Built-in Functions
f25efe50 24506@defbuiltin{int __builtin_tbegin (void*)}
d77de738
ML
24507Generates the @code{tbegin} machine instruction starting a
24508non-constrained hardware transaction. If the parameter is non-NULL the
24509memory area is used to store the transaction diagnostic buffer and
24510will be passed as first operand to @code{tbegin}. This buffer can be
24511defined using the @code{struct __htm_tdb} C struct defined in
24512@code{htmintrin.h} and must reside on a double-word boundary. The
24513second tbegin operand is set to @code{0xff0c}. This enables
24514save/restore of all GPRs and disables aborts for FPR and AR
24515manipulations inside the transaction body. The condition code set by
24516the tbegin instruction is returned as integer value. The tbegin
24517instruction by definition overwrites the content of all FPRs. The
24518compiler will generate code which saves and restores the FPRs. For
24519soft-float code it is recommended to used the @code{*_nofloat}
24520variant. In order to prevent a TDB from being written it is required
24521to pass a constant zero value as parameter. Passing a zero value
24522through a variable is not sufficient. Although modifications of
24523access registers inside the transaction will not trigger an
24524transaction abort it is not supported to actually modify them. Access
24525registers do not get saved when entering a transaction. They will have
24526undefined state when reaching the abort code.
f25efe50 24527@enddefbuiltin
d77de738
ML
24528
24529Macros for the possible return codes of tbegin are defined in the
24530@code{htmintrin.h} header file:
24531
f25efe50 24532@defmac _HTM_TBEGIN_STARTED
d77de738
ML
24533@code{tbegin} has been executed as part of normal processing. The
24534transaction body is supposed to be executed.
f25efe50
AA
24535@end defmac
24536
24537@defmac _HTM_TBEGIN_INDETERMINATE
d77de738
ML
24538The transaction was aborted due to an indeterminate condition which
24539might be persistent.
f25efe50
AA
24540@end defmac
24541
24542@defmac _HTM_TBEGIN_TRANSIENT
d77de738
ML
24543The transaction aborted due to a transient failure. The transaction
24544should be re-executed in that case.
f25efe50
AA
24545@end defmac
24546
24547@defmac _HTM_TBEGIN_PERSISTENT
d77de738
ML
24548The transaction aborted due to a persistent failure. Re-execution
24549under same circumstances will not be productive.
f25efe50 24550@end defmac
d77de738
ML
24551
24552@defmac _HTM_FIRST_USER_ABORT_CODE
24553The @code{_HTM_FIRST_USER_ABORT_CODE} defined in @code{htmintrin.h}
24554specifies the first abort code which can be used for
24555@code{__builtin_tabort}. Values below this threshold are reserved for
24556machine use.
24557@end defmac
24558
24559@deftp {Data type} {struct __htm_tdb}
24560The @code{struct __htm_tdb} defined in @code{htmintrin.h} describes
24561the structure of the transaction diagnostic block as specified in the
24562Principles of Operation manual chapter 5-91.
24563@end deftp
24564
f25efe50 24565@defbuiltin{int __builtin_tbegin_nofloat (void*)}
d77de738
ML
24566Same as @code{__builtin_tbegin} but without FPR saves and restores.
24567Using this variant in code making use of FPRs will leave the FPRs in
24568undefined state when entering the transaction abort handler code.
f25efe50 24569@enddefbuiltin
d77de738 24570
f25efe50 24571@defbuiltin{int __builtin_tbegin_retry (void*, int)}
d77de738
ML
24572In addition to @code{__builtin_tbegin} a loop for transient failures
24573is generated. If tbegin returns a condition code of 2 the transaction
24574will be retried as often as specified in the second argument. The
24575perform processor assist instruction is used to tell the CPU about the
24576number of fails so far.
f25efe50 24577@enddefbuiltin
d77de738 24578
f25efe50 24579@defbuiltin{int __builtin_tbegin_retry_nofloat (void*, int)}
d77de738
ML
24580Same as @code{__builtin_tbegin_retry} but without FPR saves and
24581restores. Using this variant in code making use of FPRs will leave
24582the FPRs in undefined state when entering the transaction abort
24583handler code.
f25efe50 24584@enddefbuiltin
d77de738 24585
f25efe50 24586@defbuiltin{void __builtin_tbeginc (void)}
d77de738
ML
24587Generates the @code{tbeginc} machine instruction starting a constrained
24588hardware transaction. The second operand is set to @code{0xff08}.
f25efe50 24589@enddefbuiltin
d77de738 24590
f25efe50 24591@defbuiltin{int __builtin_tend (void)}
d77de738
ML
24592Generates the @code{tend} machine instruction finishing a transaction
24593and making the changes visible to other threads. The condition code
24594generated by tend is returned as integer value.
f25efe50 24595@enddefbuiltin
d77de738 24596
f25efe50 24597@defbuiltin{void __builtin_tabort (int)}
d77de738
ML
24598Generates the @code{tabort} machine instruction with the specified
24599abort code. Abort codes from 0 through 255 are reserved and will
24600result in an error message.
f25efe50 24601@enddefbuiltin
d77de738 24602
f25efe50 24603@defbuiltin{void __builtin_tx_assist (int)}
d77de738
ML
24604Generates the @code{ppa rX,rY,1} machine instruction. Where the
24605integer parameter is loaded into rX and a value of zero is loaded into
24606rY. The integer parameter specifies the number of times the
24607transaction repeatedly aborted.
f25efe50 24608@enddefbuiltin
d77de738 24609
f25efe50 24610@defbuiltin{int __builtin_tx_nesting_depth (void)}
d77de738
ML
24611Generates the @code{etnd} machine instruction. The current nesting
24612depth is returned as integer value. For a nesting depth of 0 the code
24613is not executed as part of an transaction.
f25efe50 24614@enddefbuiltin
d77de738 24615
f25efe50 24616@defbuiltin{void __builtin_non_tx_store (uint64_t *, uint64_t)}
d77de738
ML
24617
24618Generates the @code{ntstg} machine instruction. The second argument
24619is written to the first arguments location. The store operation will
24620not be rolled-back in case of an transaction abort.
f25efe50 24621@enddefbuiltin
d77de738
ML
24622
24623@node SH Built-in Functions
24624@subsection SH Built-in Functions
24625The following built-in functions are supported on the SH1, SH2, SH3 and SH4
24626families of processors:
24627
f25efe50 24628@defbuiltin{{void} __builtin_set_thread_pointer (void *@var{ptr})}
d77de738
ML
24629Sets the @samp{GBR} register to the specified value @var{ptr}. This is usually
24630used by system code that manages threads and execution contexts. The compiler
24631normally does not generate code that modifies the contents of @samp{GBR} and
24632thus the value is preserved across function calls. Changing the @samp{GBR}
24633value in user code must be done with caution, since the compiler might use
24634@samp{GBR} in order to access thread local variables.
24635
f25efe50 24636@enddefbuiltin
d77de738 24637
f25efe50 24638@defbuiltin{{void *} __builtin_thread_pointer (void)}
d77de738
ML
24639Returns the value that is currently set in the @samp{GBR} register.
24640Memory loads and stores that use the thread pointer as a base address are
24641turned into @samp{GBR} based displacement loads and stores, if possible.
24642For example:
24643@smallexample
24644struct my_tcb
24645@{
24646 int a, b, c, d, e;
24647@};
24648
24649int get_tcb_value (void)
24650@{
24651 // Generate @samp{mov.l @@(8,gbr),r0} instruction
24652 return ((my_tcb*)__builtin_thread_pointer ())->c;
24653@}
24654
24655@end smallexample
f25efe50 24656@enddefbuiltin
d77de738 24657
f25efe50 24658@defbuiltin{{unsigned int} __builtin_sh_get_fpscr (void)}
d77de738 24659Returns the value that is currently set in the @samp{FPSCR} register.
f25efe50 24660@enddefbuiltin
d77de738 24661
f25efe50 24662@defbuiltin{{void} __builtin_sh_set_fpscr (unsigned int @var{val})}
d77de738
ML
24663Sets the @samp{FPSCR} register to the specified value @var{val}, while
24664preserving the current values of the FR, SZ and PR bits.
f25efe50 24665@enddefbuiltin
d77de738
ML
24666
24667@node SPARC VIS Built-in Functions
24668@subsection SPARC VIS Built-in Functions
24669
24670GCC supports SIMD operations on the SPARC using both the generic vector
24671extensions (@pxref{Vector Extensions}) as well as built-in functions for
24672the SPARC Visual Instruction Set (VIS). When you use the @option{-mvis}
24673switch, the VIS extension is exposed as the following built-in functions:
24674
24675@smallexample
24676typedef int v1si __attribute__ ((vector_size (4)));
24677typedef int v2si __attribute__ ((vector_size (8)));
24678typedef short v4hi __attribute__ ((vector_size (8)));
24679typedef short v2hi __attribute__ ((vector_size (4)));
24680typedef unsigned char v8qi __attribute__ ((vector_size (8)));
24681typedef unsigned char v4qi __attribute__ ((vector_size (4)));
24682
24683void __builtin_vis_write_gsr (int64_t);
24684int64_t __builtin_vis_read_gsr (void);
24685
24686void * __builtin_vis_alignaddr (void *, long);
24687void * __builtin_vis_alignaddrl (void *, long);
24688int64_t __builtin_vis_faligndatadi (int64_t, int64_t);
24689v2si __builtin_vis_faligndatav2si (v2si, v2si);
24690v4hi __builtin_vis_faligndatav4hi (v4si, v4si);
24691v8qi __builtin_vis_faligndatav8qi (v8qi, v8qi);
24692
24693v4hi __builtin_vis_fexpand (v4qi);
24694
24695v4hi __builtin_vis_fmul8x16 (v4qi, v4hi);
24696v4hi __builtin_vis_fmul8x16au (v4qi, v2hi);
24697v4hi __builtin_vis_fmul8x16al (v4qi, v2hi);
24698v4hi __builtin_vis_fmul8sux16 (v8qi, v4hi);
24699v4hi __builtin_vis_fmul8ulx16 (v8qi, v4hi);
24700v2si __builtin_vis_fmuld8sux16 (v4qi, v2hi);
24701v2si __builtin_vis_fmuld8ulx16 (v4qi, v2hi);
24702
24703v4qi __builtin_vis_fpack16 (v4hi);
24704v8qi __builtin_vis_fpack32 (v2si, v8qi);
24705v2hi __builtin_vis_fpackfix (v2si);
24706v8qi __builtin_vis_fpmerge (v4qi, v4qi);
24707
24708int64_t __builtin_vis_pdist (v8qi, v8qi, int64_t);
24709
24710long __builtin_vis_edge8 (void *, void *);
24711long __builtin_vis_edge8l (void *, void *);
24712long __builtin_vis_edge16 (void *, void *);
24713long __builtin_vis_edge16l (void *, void *);
24714long __builtin_vis_edge32 (void *, void *);
24715long __builtin_vis_edge32l (void *, void *);
24716
24717long __builtin_vis_fcmple16 (v4hi, v4hi);
24718long __builtin_vis_fcmple32 (v2si, v2si);
24719long __builtin_vis_fcmpne16 (v4hi, v4hi);
24720long __builtin_vis_fcmpne32 (v2si, v2si);
24721long __builtin_vis_fcmpgt16 (v4hi, v4hi);
24722long __builtin_vis_fcmpgt32 (v2si, v2si);
24723long __builtin_vis_fcmpeq16 (v4hi, v4hi);
24724long __builtin_vis_fcmpeq32 (v2si, v2si);
24725
24726v4hi __builtin_vis_fpadd16 (v4hi, v4hi);
24727v2hi __builtin_vis_fpadd16s (v2hi, v2hi);
24728v2si __builtin_vis_fpadd32 (v2si, v2si);
24729v1si __builtin_vis_fpadd32s (v1si, v1si);
24730v4hi __builtin_vis_fpsub16 (v4hi, v4hi);
24731v2hi __builtin_vis_fpsub16s (v2hi, v2hi);
24732v2si __builtin_vis_fpsub32 (v2si, v2si);
24733v1si __builtin_vis_fpsub32s (v1si, v1si);
24734
24735long __builtin_vis_array8 (long, long);
24736long __builtin_vis_array16 (long, long);
24737long __builtin_vis_array32 (long, long);
24738@end smallexample
24739
24740When you use the @option{-mvis2} switch, the VIS version 2.0 built-in
24741functions also become available:
24742
24743@smallexample
24744long __builtin_vis_bmask (long, long);
24745int64_t __builtin_vis_bshuffledi (int64_t, int64_t);
24746v2si __builtin_vis_bshufflev2si (v2si, v2si);
24747v4hi __builtin_vis_bshufflev2si (v4hi, v4hi);
24748v8qi __builtin_vis_bshufflev2si (v8qi, v8qi);
24749
24750long __builtin_vis_edge8n (void *, void *);
24751long __builtin_vis_edge8ln (void *, void *);
24752long __builtin_vis_edge16n (void *, void *);
24753long __builtin_vis_edge16ln (void *, void *);
24754long __builtin_vis_edge32n (void *, void *);
24755long __builtin_vis_edge32ln (void *, void *);
24756@end smallexample
24757
24758When you use the @option{-mvis3} switch, the VIS version 3.0 built-in
24759functions also become available:
24760
24761@smallexample
24762void __builtin_vis_cmask8 (long);
24763void __builtin_vis_cmask16 (long);
24764void __builtin_vis_cmask32 (long);
24765
24766v4hi __builtin_vis_fchksm16 (v4hi, v4hi);
24767
24768v4hi __builtin_vis_fsll16 (v4hi, v4hi);
24769v4hi __builtin_vis_fslas16 (v4hi, v4hi);
24770v4hi __builtin_vis_fsrl16 (v4hi, v4hi);
24771v4hi __builtin_vis_fsra16 (v4hi, v4hi);
24772v2si __builtin_vis_fsll16 (v2si, v2si);
24773v2si __builtin_vis_fslas16 (v2si, v2si);
24774v2si __builtin_vis_fsrl16 (v2si, v2si);
24775v2si __builtin_vis_fsra16 (v2si, v2si);
24776
24777long __builtin_vis_pdistn (v8qi, v8qi);
24778
24779v4hi __builtin_vis_fmean16 (v4hi, v4hi);
24780
24781int64_t __builtin_vis_fpadd64 (int64_t, int64_t);
24782int64_t __builtin_vis_fpsub64 (int64_t, int64_t);
24783
24784v4hi __builtin_vis_fpadds16 (v4hi, v4hi);
24785v2hi __builtin_vis_fpadds16s (v2hi, v2hi);
24786v4hi __builtin_vis_fpsubs16 (v4hi, v4hi);
24787v2hi __builtin_vis_fpsubs16s (v2hi, v2hi);
24788v2si __builtin_vis_fpadds32 (v2si, v2si);
24789v1si __builtin_vis_fpadds32s (v1si, v1si);
24790v2si __builtin_vis_fpsubs32 (v2si, v2si);
24791v1si __builtin_vis_fpsubs32s (v1si, v1si);
24792
24793long __builtin_vis_fucmple8 (v8qi, v8qi);
24794long __builtin_vis_fucmpne8 (v8qi, v8qi);
24795long __builtin_vis_fucmpgt8 (v8qi, v8qi);
24796long __builtin_vis_fucmpeq8 (v8qi, v8qi);
24797
24798float __builtin_vis_fhadds (float, float);
24799double __builtin_vis_fhaddd (double, double);
24800float __builtin_vis_fhsubs (float, float);
24801double __builtin_vis_fhsubd (double, double);
24802float __builtin_vis_fnhadds (float, float);
24803double __builtin_vis_fnhaddd (double, double);
24804
24805int64_t __builtin_vis_umulxhi (int64_t, int64_t);
24806int64_t __builtin_vis_xmulx (int64_t, int64_t);
24807int64_t __builtin_vis_xmulxhi (int64_t, int64_t);
24808@end smallexample
24809
24810When you use the @option{-mvis4} switch, the VIS version 4.0 built-in
24811functions also become available:
24812
24813@smallexample
24814v8qi __builtin_vis_fpadd8 (v8qi, v8qi);
24815v8qi __builtin_vis_fpadds8 (v8qi, v8qi);
24816v8qi __builtin_vis_fpaddus8 (v8qi, v8qi);
24817v4hi __builtin_vis_fpaddus16 (v4hi, v4hi);
24818
24819v8qi __builtin_vis_fpsub8 (v8qi, v8qi);
24820v8qi __builtin_vis_fpsubs8 (v8qi, v8qi);
24821v8qi __builtin_vis_fpsubus8 (v8qi, v8qi);
24822v4hi __builtin_vis_fpsubus16 (v4hi, v4hi);
24823
24824long __builtin_vis_fpcmple8 (v8qi, v8qi);
24825long __builtin_vis_fpcmpgt8 (v8qi, v8qi);
24826long __builtin_vis_fpcmpule16 (v4hi, v4hi);
24827long __builtin_vis_fpcmpugt16 (v4hi, v4hi);
24828long __builtin_vis_fpcmpule32 (v2si, v2si);
24829long __builtin_vis_fpcmpugt32 (v2si, v2si);
24830
24831v8qi __builtin_vis_fpmax8 (v8qi, v8qi);
24832v4hi __builtin_vis_fpmax16 (v4hi, v4hi);
24833v2si __builtin_vis_fpmax32 (v2si, v2si);
24834
24835v8qi __builtin_vis_fpmaxu8 (v8qi, v8qi);
24836v4hi __builtin_vis_fpmaxu16 (v4hi, v4hi);
24837v2si __builtin_vis_fpmaxu32 (v2si, v2si);
24838
24839v8qi __builtin_vis_fpmin8 (v8qi, v8qi);
24840v4hi __builtin_vis_fpmin16 (v4hi, v4hi);
24841v2si __builtin_vis_fpmin32 (v2si, v2si);
24842
24843v8qi __builtin_vis_fpminu8 (v8qi, v8qi);
24844v4hi __builtin_vis_fpminu16 (v4hi, v4hi);
24845v2si __builtin_vis_fpminu32 (v2si, v2si);
24846@end smallexample
24847
24848When you use the @option{-mvis4b} switch, the VIS version 4.0B
24849built-in functions also become available:
24850
24851@smallexample
24852v8qi __builtin_vis_dictunpack8 (double, int);
24853v4hi __builtin_vis_dictunpack16 (double, int);
24854v2si __builtin_vis_dictunpack32 (double, int);
24855
24856long __builtin_vis_fpcmple8shl (v8qi, v8qi, int);
24857long __builtin_vis_fpcmpgt8shl (v8qi, v8qi, int);
24858long __builtin_vis_fpcmpeq8shl (v8qi, v8qi, int);
24859long __builtin_vis_fpcmpne8shl (v8qi, v8qi, int);
24860
24861long __builtin_vis_fpcmple16shl (v4hi, v4hi, int);
24862long __builtin_vis_fpcmpgt16shl (v4hi, v4hi, int);
24863long __builtin_vis_fpcmpeq16shl (v4hi, v4hi, int);
24864long __builtin_vis_fpcmpne16shl (v4hi, v4hi, int);
24865
24866long __builtin_vis_fpcmple32shl (v2si, v2si, int);
24867long __builtin_vis_fpcmpgt32shl (v2si, v2si, int);
24868long __builtin_vis_fpcmpeq32shl (v2si, v2si, int);
24869long __builtin_vis_fpcmpne32shl (v2si, v2si, int);
24870
24871long __builtin_vis_fpcmpule8shl (v8qi, v8qi, int);
24872long __builtin_vis_fpcmpugt8shl (v8qi, v8qi, int);
24873long __builtin_vis_fpcmpule16shl (v4hi, v4hi, int);
24874long __builtin_vis_fpcmpugt16shl (v4hi, v4hi, int);
24875long __builtin_vis_fpcmpule32shl (v2si, v2si, int);
24876long __builtin_vis_fpcmpugt32shl (v2si, v2si, int);
24877
24878long __builtin_vis_fpcmpde8shl (v8qi, v8qi, int);
24879long __builtin_vis_fpcmpde16shl (v4hi, v4hi, int);
24880long __builtin_vis_fpcmpde32shl (v2si, v2si, int);
24881
24882long __builtin_vis_fpcmpur8shl (v8qi, v8qi, int);
24883long __builtin_vis_fpcmpur16shl (v4hi, v4hi, int);
24884long __builtin_vis_fpcmpur32shl (v2si, v2si, int);
24885@end smallexample
24886
24887@node TI C6X Built-in Functions
24888@subsection TI C6X Built-in Functions
24889
24890GCC provides intrinsics to access certain instructions of the TI C6X
24891processors. These intrinsics, listed below, are available after
24892inclusion of the @code{c6x_intrinsics.h} header file. They map directly
24893to C6X instructions.
24894
24895@smallexample
24896int _sadd (int, int);
24897int _ssub (int, int);
24898int _sadd2 (int, int);
24899int _ssub2 (int, int);
24900long long _mpy2 (int, int);
24901long long _smpy2 (int, int);
24902int _add4 (int, int);
24903int _sub4 (int, int);
24904int _saddu4 (int, int);
24905
24906int _smpy (int, int);
24907int _smpyh (int, int);
24908int _smpyhl (int, int);
24909int _smpylh (int, int);
24910
24911int _sshl (int, int);
24912int _subc (int, int);
24913
24914int _avg2 (int, int);
24915int _avgu4 (int, int);
24916
24917int _clrr (int, int);
24918int _extr (int, int);
24919int _extru (int, int);
24920int _abs (int);
24921int _abs2 (int);
24922@end smallexample
24923
24924@node x86 Built-in Functions
24925@subsection x86 Built-in Functions
24926
24927These built-in functions are available for the x86-32 and x86-64 family
24928of computers, depending on the command-line switches used.
24929
24930If you specify command-line switches such as @option{-msse},
24931the compiler could use the extended instruction sets even if the built-ins
24932are not used explicitly in the program. For this reason, applications
24933that perform run-time CPU detection must compile separate files for each
24934supported architecture, using the appropriate flags. In particular,
24935the file containing the CPU detection code should be compiled without
24936these options.
24937
24938The following machine modes are available for use with MMX built-in functions
24939(@pxref{Vector Extensions}): @code{V2SI} for a vector of two 32-bit integers,
24940@code{V4HI} for a vector of four 16-bit integers, and @code{V8QI} for a
24941vector of eight 8-bit integers. Some of the built-in functions operate on
24942MMX registers as a whole 64-bit entity, these use @code{V1DI} as their mode.
24943
24944If 3DNow!@: extensions are enabled, @code{V2SF} is used as a mode for a vector
24945of two 32-bit floating-point values.
24946
24947If SSE extensions are enabled, @code{V4SF} is used for a vector of four 32-bit
24948floating-point values. Some instructions use a vector of four 32-bit
24949integers, these use @code{V4SI}. Finally, some instructions operate on an
24950entire vector register, interpreting it as a 128-bit integer, these use mode
24951@code{TI}.
24952
24953The x86-32 and x86-64 family of processors use additional built-in
24954functions for efficient use of @code{TF} (@code{__float128}) 128-bit
24955floating point and @code{TC} 128-bit complex floating-point values.
24956
f25efe50 24957The following floating-point built-in functions are always available:
d77de738 24958
f25efe50
AA
24959@defbuiltin{__float128 __builtin_fabsq (__float128 @var{x}))}
24960Computes the absolute value of @var{x}.
24961@enddefbuiltin
d77de738 24962
f25efe50
AA
24963@defbuiltin{__float128 __builtin_copysignq (__float128 @var{x}, @
24964 __float128 @var{y})}
24965Copies the sign of @var{y} into @var{x} and returns the new value of
24966@var{x}.
24967@enddefbuiltin
d77de738 24968
f25efe50 24969@defbuiltin{__float128 __builtin_infq (void)}
d77de738 24970Similar to @code{__builtin_inf}, except the return type is @code{__float128}.
f25efe50 24971@enddefbuiltin
d77de738 24972
f25efe50 24973@defbuiltin{__float128 __builtin_huge_valq (void)}
d77de738 24974Similar to @code{__builtin_huge_val}, except the return type is @code{__float128}.
f25efe50 24975@enddefbuiltin
d77de738 24976
f25efe50 24977@defbuiltin{__float128 __builtin_nanq (void)}
d77de738 24978Similar to @code{__builtin_nan}, except the return type is @code{__float128}.
f25efe50 24979@enddefbuiltin
d77de738 24980
f25efe50 24981@defbuiltin{__float128 __builtin_nansq (void)}
d77de738 24982Similar to @code{__builtin_nans}, except the return type is @code{__float128}.
f25efe50 24983@enddefbuiltin
d77de738
ML
24984
24985The following built-in function is always available.
24986
f25efe50 24987@defbuiltin{void __builtin_ia32_pause (void)}
d77de738
ML
24988Generates the @code{pause} machine instruction with a compiler memory
24989barrier.
f25efe50 24990@enddefbuiltin
d77de738
ML
24991
24992The following built-in functions are always available and can be used to
24993check the target platform type.
24994
f25efe50 24995@defbuiltin{void __builtin_cpu_init (void)}
d77de738
ML
24996This function runs the CPU detection code to check the type of CPU and the
24997features supported. This built-in function needs to be invoked along with the built-in functions
24998to check CPU type and features, @code{__builtin_cpu_is} and
24999@code{__builtin_cpu_supports}, only when used in a function that is
25000executed before any constructors are called. The CPU detection code is
25001automatically executed in a very high priority constructor.
25002
25003For example, this function has to be used in @code{ifunc} resolvers that
25004check for CPU type using the built-in functions @code{__builtin_cpu_is}
25005and @code{__builtin_cpu_supports}, or in constructors on targets that
25006don't support constructor priority.
25007@smallexample
25008
25009static void (*resolve_memcpy (void)) (void)
25010@{
25011 // ifunc resolvers fire before constructors, explicitly call the init
25012 // function.
25013 __builtin_cpu_init ();
25014 if (__builtin_cpu_supports ("ssse3"))
25015 return ssse3_memcpy; // super fast memcpy with ssse3 instructions.
25016 else
25017 return default_memcpy;
25018@}
25019
25020void *memcpy (void *, const void *, size_t)
25021 __attribute__ ((ifunc ("resolve_memcpy")));
25022@end smallexample
25023
f25efe50 25024@enddefbuiltin
d77de738 25025
f25efe50 25026@defbuiltin{int __builtin_cpu_is (const char *@var{cpuname})}
d77de738
ML
25027This function returns a positive integer if the run-time CPU
25028is of type @var{cpuname}
25029and returns @code{0} otherwise. The following CPU names can be detected:
25030
25031@table @samp
25032@item amd
25033AMD CPU.
25034
25035@item intel
25036Intel CPU.
25037
25038@item atom
25039Intel Atom CPU.
25040
25041@item slm
25042Intel Silvermont CPU.
25043
25044@item core2
25045Intel Core 2 CPU.
25046
25047@item corei7
25048Intel Core i7 CPU.
25049
25050@item nehalem
25051Intel Core i7 Nehalem CPU.
25052
25053@item westmere
25054Intel Core i7 Westmere CPU.
25055
25056@item sandybridge
25057Intel Core i7 Sandy Bridge CPU.
25058
25059@item ivybridge
25060Intel Core i7 Ivy Bridge CPU.
25061
25062@item haswell
25063Intel Core i7 Haswell CPU.
25064
25065@item broadwell
25066Intel Core i7 Broadwell CPU.
25067
25068@item skylake
25069Intel Core i7 Skylake CPU.
25070
25071@item skylake-avx512
25072Intel Core i7 Skylake AVX512 CPU.
25073
25074@item cannonlake
25075Intel Core i7 Cannon Lake CPU.
25076
25077@item icelake-client
25078Intel Core i7 Ice Lake Client CPU.
25079
25080@item icelake-server
25081Intel Core i7 Ice Lake Server CPU.
25082
25083@item cascadelake
25084Intel Core i7 Cascadelake CPU.
25085
25086@item tigerlake
25087Intel Core i7 Tigerlake CPU.
25088
25089@item cooperlake
25090Intel Core i7 Cooperlake CPU.
25091
25092@item sapphirerapids
25093Intel Core i7 sapphirerapids CPU.
25094
25095@item alderlake
25096Intel Core i7 Alderlake CPU.
25097
25098@item rocketlake
25099Intel Core i7 Rocketlake CPU.
25100
25101@item graniterapids
25102Intel Core i7 graniterapids CPU.
25103
a0cb65d3
MZ
25104@item graniterapids-d
25105Intel Core i7 graniterapids D CPU.
25106
faa0e82b
HJ
25107@item arrowlake
25108Intel Core i7 Arrow Lake CPU.
25109
25110@item arrowlake-s
25111Intel Core i7 Arrow Lake S CPU.
25112
25113@item pantherlake
25114Intel Core i7 Panther Lake CPU.
25115
d77de738
ML
25116@item bonnell
25117Intel Atom Bonnell CPU.
25118
25119@item silvermont
25120Intel Atom Silvermont CPU.
25121
25122@item goldmont
25123Intel Atom Goldmont CPU.
25124
25125@item goldmont-plus
25126Intel Atom Goldmont Plus CPU.
25127
25128@item tremont
25129Intel Atom Tremont CPU.
25130
25131@item sierraforest
25132Intel Atom Sierra Forest CPU.
25133
25134@item grandridge
25135Intel Atom Grand Ridge CPU.
25136
7370c479
HJ
25137@item clearwaterforest
25138Intel Atom Clearwater Forest CPU.
25139
d77de738
ML
25140@item knl
25141Intel Knights Landing CPU.
25142
25143@item knm
25144Intel Knights Mill CPU.
25145
25146@item lujiazui
25147ZHAOXIN lujiazui CPU.
25148
94c0b26f
M
25149@item yongfeng
25150ZHAOXIN yongfeng CPU.
25151
d77de738
ML
25152@item amdfam10h
25153AMD Family 10h CPU.
25154
25155@item barcelona
25156AMD Family 10h Barcelona CPU.
25157
25158@item shanghai
25159AMD Family 10h Shanghai CPU.
25160
25161@item istanbul
25162AMD Family 10h Istanbul CPU.
25163
25164@item btver1
25165AMD Family 14h CPU.
25166
25167@item amdfam15h
25168AMD Family 15h CPU.
25169
25170@item bdver1
25171AMD Family 15h Bulldozer version 1.
25172
25173@item bdver2
25174AMD Family 15h Bulldozer version 2.
25175
25176@item bdver3
25177AMD Family 15h Bulldozer version 3.
25178
25179@item bdver4
25180AMD Family 15h Bulldozer version 4.
25181
25182@item btver2
25183AMD Family 16h CPU.
25184
25185@item amdfam17h
25186AMD Family 17h CPU.
25187
25188@item znver1
25189AMD Family 17h Zen version 1.
25190
25191@item znver2
25192AMD Family 17h Zen version 2.
25193
25194@item amdfam19h
25195AMD Family 19h CPU.
25196
25197@item znver3
25198AMD Family 19h Zen version 3.
25199
25200@item znver4
25201AMD Family 19h Zen version 4.
d77de738
ML
25202@end table
25203
25204Here is an example:
25205@smallexample
25206if (__builtin_cpu_is ("corei7"))
25207 @{
25208 do_corei7 (); // Core i7 specific implementation.
25209 @}
25210else
25211 @{
25212 do_generic (); // Generic implementation.
25213 @}
25214@end smallexample
f25efe50 25215@enddefbuiltin
d77de738 25216
f25efe50 25217@defbuiltin{int __builtin_cpu_supports (const char *@var{feature})}
d77de738
ML
25218This function returns a positive integer if the run-time CPU
25219supports @var{feature}
25220and returns @code{0} otherwise. The following features can be detected:
25221
25222@table @samp
25223@item cmov
25224CMOV instruction.
25225@item mmx
25226MMX instructions.
25227@item popcnt
25228POPCNT instruction.
25229@item sse
25230SSE instructions.
25231@item sse2
25232SSE2 instructions.
25233@item sse3
25234SSE3 instructions.
25235@item ssse3
25236SSSE3 instructions.
25237@item sse4.1
25238SSE4.1 instructions.
25239@item sse4.2
25240SSE4.2 instructions.
25241@item avx
25242AVX instructions.
25243@item avx2
25244AVX2 instructions.
25245@item sse4a
25246SSE4A instructions.
25247@item fma4
25248FMA4 instructions.
25249@item xop
25250XOP instructions.
25251@item fma
25252FMA instructions.
25253@item avx512f
25254AVX512F instructions.
25255@item bmi
25256BMI instructions.
25257@item bmi2
25258BMI2 instructions.
25259@item aes
25260AES instructions.
25261@item pclmul
25262PCLMUL instructions.
25263@item avx512vl
25264AVX512VL instructions.
25265@item avx512bw
25266AVX512BW instructions.
25267@item avx512dq
25268AVX512DQ instructions.
25269@item avx512cd
25270AVX512CD instructions.
25271@item avx512er
25272AVX512ER instructions.
25273@item avx512pf
25274AVX512PF instructions.
25275@item avx512vbmi
25276AVX512VBMI instructions.
25277@item avx512ifma
25278AVX512IFMA instructions.
25279@item avx5124vnniw
25280AVX5124VNNIW instructions.
25281@item avx5124fmaps
25282AVX5124FMAPS instructions.
25283@item avx512vpopcntdq
25284AVX512VPOPCNTDQ instructions.
25285@item avx512vbmi2
25286AVX512VBMI2 instructions.
25287@item gfni
25288GFNI instructions.
25289@item vpclmulqdq
25290VPCLMULQDQ instructions.
25291@item avx512vnni
25292AVX512VNNI instructions.
25293@item avx512bitalg
25294AVX512BITALG instructions.
d71b20fc
ML
25295@item x86-64
25296Baseline x86-64 microarchitecture level (as defined in x86-64 psABI).
25297@item x86-64-v2
25298x86-64-v2 microarchitecture level.
25299@item x86-64-v3
25300x86-64-v3 microarchitecture level.
25301@item x86-64-v4
25302x86-64-v4 microarchitecture level.
25303
25304
d77de738
ML
25305@end table
25306
25307Here is an example:
25308@smallexample
25309if (__builtin_cpu_supports ("popcnt"))
25310 @{
25311 asm("popcnt %1,%0" : "=r"(count) : "rm"(n) : "cc");
25312 @}
25313else
25314 @{
25315 count = generic_countbits (n); //generic implementation.
25316 @}
25317@end smallexample
f25efe50 25318@enddefbuiltin
d77de738
ML
25319
25320The following built-in functions are made available by @option{-mmmx}.
25321All of them generate the machine instruction that is part of the name.
25322
25323@smallexample
25324v8qi __builtin_ia32_paddb (v8qi, v8qi);
25325v4hi __builtin_ia32_paddw (v4hi, v4hi);
25326v2si __builtin_ia32_paddd (v2si, v2si);
25327v8qi __builtin_ia32_psubb (v8qi, v8qi);
25328v4hi __builtin_ia32_psubw (v4hi, v4hi);
25329v2si __builtin_ia32_psubd (v2si, v2si);
25330v8qi __builtin_ia32_paddsb (v8qi, v8qi);
25331v4hi __builtin_ia32_paddsw (v4hi, v4hi);
25332v8qi __builtin_ia32_psubsb (v8qi, v8qi);
25333v4hi __builtin_ia32_psubsw (v4hi, v4hi);
25334v8qi __builtin_ia32_paddusb (v8qi, v8qi);
25335v4hi __builtin_ia32_paddusw (v4hi, v4hi);
25336v8qi __builtin_ia32_psubusb (v8qi, v8qi);
25337v4hi __builtin_ia32_psubusw (v4hi, v4hi);
25338v4hi __builtin_ia32_pmullw (v4hi, v4hi);
25339v4hi __builtin_ia32_pmulhw (v4hi, v4hi);
25340di __builtin_ia32_pand (di, di);
25341di __builtin_ia32_pandn (di,di);
25342di __builtin_ia32_por (di, di);
25343di __builtin_ia32_pxor (di, di);
25344v8qi __builtin_ia32_pcmpeqb (v8qi, v8qi);
25345v4hi __builtin_ia32_pcmpeqw (v4hi, v4hi);
25346v2si __builtin_ia32_pcmpeqd (v2si, v2si);
25347v8qi __builtin_ia32_pcmpgtb (v8qi, v8qi);
25348v4hi __builtin_ia32_pcmpgtw (v4hi, v4hi);
25349v2si __builtin_ia32_pcmpgtd (v2si, v2si);
25350v8qi __builtin_ia32_punpckhbw (v8qi, v8qi);
25351v4hi __builtin_ia32_punpckhwd (v4hi, v4hi);
25352v2si __builtin_ia32_punpckhdq (v2si, v2si);
25353v8qi __builtin_ia32_punpcklbw (v8qi, v8qi);
25354v4hi __builtin_ia32_punpcklwd (v4hi, v4hi);
25355v2si __builtin_ia32_punpckldq (v2si, v2si);
25356v8qi __builtin_ia32_packsswb (v4hi, v4hi);
25357v4hi __builtin_ia32_packssdw (v2si, v2si);
25358v8qi __builtin_ia32_packuswb (v4hi, v4hi);
25359
25360v4hi __builtin_ia32_psllw (v4hi, v4hi);
25361v2si __builtin_ia32_pslld (v2si, v2si);
25362v1di __builtin_ia32_psllq (v1di, v1di);
25363v4hi __builtin_ia32_psrlw (v4hi, v4hi);
25364v2si __builtin_ia32_psrld (v2si, v2si);
25365v1di __builtin_ia32_psrlq (v1di, v1di);
25366v4hi __builtin_ia32_psraw (v4hi, v4hi);
25367v2si __builtin_ia32_psrad (v2si, v2si);
25368v4hi __builtin_ia32_psllwi (v4hi, int);
25369v2si __builtin_ia32_pslldi (v2si, int);
25370v1di __builtin_ia32_psllqi (v1di, int);
25371v4hi __builtin_ia32_psrlwi (v4hi, int);
25372v2si __builtin_ia32_psrldi (v2si, int);
25373v1di __builtin_ia32_psrlqi (v1di, int);
25374v4hi __builtin_ia32_psrawi (v4hi, int);
25375v2si __builtin_ia32_psradi (v2si, int);
25376@end smallexample
25377
25378The following built-in functions are made available either with
25379@option{-msse}, or with @option{-m3dnowa}. All of them generate
25380the machine instruction that is part of the name.
25381
25382@smallexample
25383v4hi __builtin_ia32_pmulhuw (v4hi, v4hi);
25384v8qi __builtin_ia32_pavgb (v8qi, v8qi);
25385v4hi __builtin_ia32_pavgw (v4hi, v4hi);
25386v1di __builtin_ia32_psadbw (v8qi, v8qi);
25387v8qi __builtin_ia32_pmaxub (v8qi, v8qi);
25388v4hi __builtin_ia32_pmaxsw (v4hi, v4hi);
25389v8qi __builtin_ia32_pminub (v8qi, v8qi);
25390v4hi __builtin_ia32_pminsw (v4hi, v4hi);
25391int __builtin_ia32_pmovmskb (v8qi);
25392void __builtin_ia32_maskmovq (v8qi, v8qi, char *);
25393void __builtin_ia32_movntq (di *, di);
25394void __builtin_ia32_sfence (void);
25395@end smallexample
25396
25397The following built-in functions are available when @option{-msse} is used.
25398All of them generate the machine instruction that is part of the name.
25399
25400@smallexample
25401int __builtin_ia32_comieq (v4sf, v4sf);
25402int __builtin_ia32_comineq (v4sf, v4sf);
25403int __builtin_ia32_comilt (v4sf, v4sf);
25404int __builtin_ia32_comile (v4sf, v4sf);
25405int __builtin_ia32_comigt (v4sf, v4sf);
25406int __builtin_ia32_comige (v4sf, v4sf);
25407int __builtin_ia32_ucomieq (v4sf, v4sf);
25408int __builtin_ia32_ucomineq (v4sf, v4sf);
25409int __builtin_ia32_ucomilt (v4sf, v4sf);
25410int __builtin_ia32_ucomile (v4sf, v4sf);
25411int __builtin_ia32_ucomigt (v4sf, v4sf);
25412int __builtin_ia32_ucomige (v4sf, v4sf);
25413v4sf __builtin_ia32_addps (v4sf, v4sf);
25414v4sf __builtin_ia32_subps (v4sf, v4sf);
25415v4sf __builtin_ia32_mulps (v4sf, v4sf);
25416v4sf __builtin_ia32_divps (v4sf, v4sf);
25417v4sf __builtin_ia32_addss (v4sf, v4sf);
25418v4sf __builtin_ia32_subss (v4sf, v4sf);
25419v4sf __builtin_ia32_mulss (v4sf, v4sf);
25420v4sf __builtin_ia32_divss (v4sf, v4sf);
25421v4sf __builtin_ia32_cmpeqps (v4sf, v4sf);
25422v4sf __builtin_ia32_cmpltps (v4sf, v4sf);
25423v4sf __builtin_ia32_cmpleps (v4sf, v4sf);
25424v4sf __builtin_ia32_cmpgtps (v4sf, v4sf);
25425v4sf __builtin_ia32_cmpgeps (v4sf, v4sf);
25426v4sf __builtin_ia32_cmpunordps (v4sf, v4sf);
25427v4sf __builtin_ia32_cmpneqps (v4sf, v4sf);
25428v4sf __builtin_ia32_cmpnltps (v4sf, v4sf);
25429v4sf __builtin_ia32_cmpnleps (v4sf, v4sf);
25430v4sf __builtin_ia32_cmpngtps (v4sf, v4sf);
25431v4sf __builtin_ia32_cmpngeps (v4sf, v4sf);
25432v4sf __builtin_ia32_cmpordps (v4sf, v4sf);
25433v4sf __builtin_ia32_cmpeqss (v4sf, v4sf);
25434v4sf __builtin_ia32_cmpltss (v4sf, v4sf);
25435v4sf __builtin_ia32_cmpless (v4sf, v4sf);
25436v4sf __builtin_ia32_cmpunordss (v4sf, v4sf);
25437v4sf __builtin_ia32_cmpneqss (v4sf, v4sf);
25438v4sf __builtin_ia32_cmpnltss (v4sf, v4sf);
25439v4sf __builtin_ia32_cmpnless (v4sf, v4sf);
25440v4sf __builtin_ia32_cmpordss (v4sf, v4sf);
25441v4sf __builtin_ia32_maxps (v4sf, v4sf);
25442v4sf __builtin_ia32_maxss (v4sf, v4sf);
25443v4sf __builtin_ia32_minps (v4sf, v4sf);
25444v4sf __builtin_ia32_minss (v4sf, v4sf);
25445v4sf __builtin_ia32_andps (v4sf, v4sf);
25446v4sf __builtin_ia32_andnps (v4sf, v4sf);
25447v4sf __builtin_ia32_orps (v4sf, v4sf);
25448v4sf __builtin_ia32_xorps (v4sf, v4sf);
25449v4sf __builtin_ia32_movss (v4sf, v4sf);
25450v4sf __builtin_ia32_movhlps (v4sf, v4sf);
25451v4sf __builtin_ia32_movlhps (v4sf, v4sf);
25452v4sf __builtin_ia32_unpckhps (v4sf, v4sf);
25453v4sf __builtin_ia32_unpcklps (v4sf, v4sf);
25454v4sf __builtin_ia32_cvtpi2ps (v4sf, v2si);
25455v4sf __builtin_ia32_cvtsi2ss (v4sf, int);
25456v2si __builtin_ia32_cvtps2pi (v4sf);
25457int __builtin_ia32_cvtss2si (v4sf);
25458v2si __builtin_ia32_cvttps2pi (v4sf);
25459int __builtin_ia32_cvttss2si (v4sf);
25460v4sf __builtin_ia32_rcpps (v4sf);
25461v4sf __builtin_ia32_rsqrtps (v4sf);
25462v4sf __builtin_ia32_sqrtps (v4sf);
25463v4sf __builtin_ia32_rcpss (v4sf);
25464v4sf __builtin_ia32_rsqrtss (v4sf);
25465v4sf __builtin_ia32_sqrtss (v4sf);
25466v4sf __builtin_ia32_shufps (v4sf, v4sf, int);
25467void __builtin_ia32_movntps (float *, v4sf);
25468int __builtin_ia32_movmskps (v4sf);
25469@end smallexample
25470
25471The following built-in functions are available when @option{-msse} is used.
25472
f25efe50 25473@defbuiltin{v4sf __builtin_ia32_loadups (float *)}
d77de738 25474Generates the @code{movups} machine instruction as a load from memory.
f25efe50
AA
25475@enddefbuiltin
25476
25477@defbuiltin{void __builtin_ia32_storeups (float *, v4sf)}
d77de738 25478Generates the @code{movups} machine instruction as a store to memory.
f25efe50
AA
25479@enddefbuiltin
25480
25481@defbuiltin{v4sf __builtin_ia32_loadss (float *)}
d77de738 25482Generates the @code{movss} machine instruction as a load from memory.
f25efe50
AA
25483@enddefbuiltin
25484
25485@defbuiltin{v4sf __builtin_ia32_loadhps (v4sf, const v2sf *)}
d77de738 25486Generates the @code{movhps} machine instruction as a load from memory.
f25efe50
AA
25487@enddefbuiltin
25488
25489@defbuiltin{v4sf __builtin_ia32_loadlps (v4sf, const v2sf *)}
d77de738 25490Generates the @code{movlps} machine instruction as a load from memory
f25efe50
AA
25491@enddefbuiltin
25492
25493@defbuiltin{void __builtin_ia32_storehps (v2sf *, v4sf)}
d77de738 25494Generates the @code{movhps} machine instruction as a store to memory.
f25efe50
AA
25495@enddefbuiltin
25496
25497@defbuiltin{void __builtin_ia32_storelps (v2sf *, v4sf)}
d77de738 25498Generates the @code{movlps} machine instruction as a store to memory.
f25efe50 25499@enddefbuiltin
d77de738
ML
25500
25501The following built-in functions are available when @option{-msse2} is used.
25502All of them generate the machine instruction that is part of the name.
25503
25504@smallexample
25505int __builtin_ia32_comisdeq (v2df, v2df);
25506int __builtin_ia32_comisdlt (v2df, v2df);
25507int __builtin_ia32_comisdle (v2df, v2df);
25508int __builtin_ia32_comisdgt (v2df, v2df);
25509int __builtin_ia32_comisdge (v2df, v2df);
25510int __builtin_ia32_comisdneq (v2df, v2df);
25511int __builtin_ia32_ucomisdeq (v2df, v2df);
25512int __builtin_ia32_ucomisdlt (v2df, v2df);
25513int __builtin_ia32_ucomisdle (v2df, v2df);
25514int __builtin_ia32_ucomisdgt (v2df, v2df);
25515int __builtin_ia32_ucomisdge (v2df, v2df);
25516int __builtin_ia32_ucomisdneq (v2df, v2df);
25517v2df __builtin_ia32_cmpeqpd (v2df, v2df);
25518v2df __builtin_ia32_cmpltpd (v2df, v2df);
25519v2df __builtin_ia32_cmplepd (v2df, v2df);
25520v2df __builtin_ia32_cmpgtpd (v2df, v2df);
25521v2df __builtin_ia32_cmpgepd (v2df, v2df);
25522v2df __builtin_ia32_cmpunordpd (v2df, v2df);
25523v2df __builtin_ia32_cmpneqpd (v2df, v2df);
25524v2df __builtin_ia32_cmpnltpd (v2df, v2df);
25525v2df __builtin_ia32_cmpnlepd (v2df, v2df);
25526v2df __builtin_ia32_cmpngtpd (v2df, v2df);
25527v2df __builtin_ia32_cmpngepd (v2df, v2df);
25528v2df __builtin_ia32_cmpordpd (v2df, v2df);
25529v2df __builtin_ia32_cmpeqsd (v2df, v2df);
25530v2df __builtin_ia32_cmpltsd (v2df, v2df);
25531v2df __builtin_ia32_cmplesd (v2df, v2df);
25532v2df __builtin_ia32_cmpunordsd (v2df, v2df);
25533v2df __builtin_ia32_cmpneqsd (v2df, v2df);
25534v2df __builtin_ia32_cmpnltsd (v2df, v2df);
25535v2df __builtin_ia32_cmpnlesd (v2df, v2df);
25536v2df __builtin_ia32_cmpordsd (v2df, v2df);
25537v2di __builtin_ia32_paddq (v2di, v2di);
25538v2di __builtin_ia32_psubq (v2di, v2di);
25539v2df __builtin_ia32_addpd (v2df, v2df);
25540v2df __builtin_ia32_subpd (v2df, v2df);
25541v2df __builtin_ia32_mulpd (v2df, v2df);
25542v2df __builtin_ia32_divpd (v2df, v2df);
25543v2df __builtin_ia32_addsd (v2df, v2df);
25544v2df __builtin_ia32_subsd (v2df, v2df);
25545v2df __builtin_ia32_mulsd (v2df, v2df);
25546v2df __builtin_ia32_divsd (v2df, v2df);
25547v2df __builtin_ia32_minpd (v2df, v2df);
25548v2df __builtin_ia32_maxpd (v2df, v2df);
25549v2df __builtin_ia32_minsd (v2df, v2df);
25550v2df __builtin_ia32_maxsd (v2df, v2df);
25551v2df __builtin_ia32_andpd (v2df, v2df);
25552v2df __builtin_ia32_andnpd (v2df, v2df);
25553v2df __builtin_ia32_orpd (v2df, v2df);
25554v2df __builtin_ia32_xorpd (v2df, v2df);
25555v2df __builtin_ia32_movsd (v2df, v2df);
25556v2df __builtin_ia32_unpckhpd (v2df, v2df);
25557v2df __builtin_ia32_unpcklpd (v2df, v2df);
25558v16qi __builtin_ia32_paddb128 (v16qi, v16qi);
25559v8hi __builtin_ia32_paddw128 (v8hi, v8hi);
25560v4si __builtin_ia32_paddd128 (v4si, v4si);
25561v2di __builtin_ia32_paddq128 (v2di, v2di);
25562v16qi __builtin_ia32_psubb128 (v16qi, v16qi);
25563v8hi __builtin_ia32_psubw128 (v8hi, v8hi);
25564v4si __builtin_ia32_psubd128 (v4si, v4si);
25565v2di __builtin_ia32_psubq128 (v2di, v2di);
25566v8hi __builtin_ia32_pmullw128 (v8hi, v8hi);
25567v8hi __builtin_ia32_pmulhw128 (v8hi, v8hi);
25568v2di __builtin_ia32_pand128 (v2di, v2di);
25569v2di __builtin_ia32_pandn128 (v2di, v2di);
25570v2di __builtin_ia32_por128 (v2di, v2di);
25571v2di __builtin_ia32_pxor128 (v2di, v2di);
25572v16qi __builtin_ia32_pavgb128 (v16qi, v16qi);
25573v8hi __builtin_ia32_pavgw128 (v8hi, v8hi);
25574v16qi __builtin_ia32_pcmpeqb128 (v16qi, v16qi);
25575v8hi __builtin_ia32_pcmpeqw128 (v8hi, v8hi);
25576v4si __builtin_ia32_pcmpeqd128 (v4si, v4si);
25577v16qi __builtin_ia32_pcmpgtb128 (v16qi, v16qi);
25578v8hi __builtin_ia32_pcmpgtw128 (v8hi, v8hi);
25579v4si __builtin_ia32_pcmpgtd128 (v4si, v4si);
25580v16qi __builtin_ia32_pmaxub128 (v16qi, v16qi);
25581v8hi __builtin_ia32_pmaxsw128 (v8hi, v8hi);
25582v16qi __builtin_ia32_pminub128 (v16qi, v16qi);
25583v8hi __builtin_ia32_pminsw128 (v8hi, v8hi);
25584v16qi __builtin_ia32_punpckhbw128 (v16qi, v16qi);
25585v8hi __builtin_ia32_punpckhwd128 (v8hi, v8hi);
25586v4si __builtin_ia32_punpckhdq128 (v4si, v4si);
25587v2di __builtin_ia32_punpckhqdq128 (v2di, v2di);
25588v16qi __builtin_ia32_punpcklbw128 (v16qi, v16qi);
25589v8hi __builtin_ia32_punpcklwd128 (v8hi, v8hi);
25590v4si __builtin_ia32_punpckldq128 (v4si, v4si);
25591v2di __builtin_ia32_punpcklqdq128 (v2di, v2di);
25592v16qi __builtin_ia32_packsswb128 (v8hi, v8hi);
25593v8hi __builtin_ia32_packssdw128 (v4si, v4si);
25594v16qi __builtin_ia32_packuswb128 (v8hi, v8hi);
25595v8hi __builtin_ia32_pmulhuw128 (v8hi, v8hi);
25596void __builtin_ia32_maskmovdqu (v16qi, v16qi);
25597v2df __builtin_ia32_loadupd (double *);
25598void __builtin_ia32_storeupd (double *, v2df);
25599v2df __builtin_ia32_loadhpd (v2df, double const *);
25600v2df __builtin_ia32_loadlpd (v2df, double const *);
25601int __builtin_ia32_movmskpd (v2df);
25602int __builtin_ia32_pmovmskb128 (v16qi);
25603void __builtin_ia32_movnti (int *, int);
25604void __builtin_ia32_movnti64 (long long int *, long long int);
25605void __builtin_ia32_movntpd (double *, v2df);
25606void __builtin_ia32_movntdq (v2df *, v2df);
25607v4si __builtin_ia32_pshufd (v4si, int);
25608v8hi __builtin_ia32_pshuflw (v8hi, int);
25609v8hi __builtin_ia32_pshufhw (v8hi, int);
25610v2di __builtin_ia32_psadbw128 (v16qi, v16qi);
25611v2df __builtin_ia32_sqrtpd (v2df);
25612v2df __builtin_ia32_sqrtsd (v2df);
25613v2df __builtin_ia32_shufpd (v2df, v2df, int);
25614v2df __builtin_ia32_cvtdq2pd (v4si);
25615v4sf __builtin_ia32_cvtdq2ps (v4si);
25616v4si __builtin_ia32_cvtpd2dq (v2df);
25617v2si __builtin_ia32_cvtpd2pi (v2df);
25618v4sf __builtin_ia32_cvtpd2ps (v2df);
25619v4si __builtin_ia32_cvttpd2dq (v2df);
25620v2si __builtin_ia32_cvttpd2pi (v2df);
25621v2df __builtin_ia32_cvtpi2pd (v2si);
25622int __builtin_ia32_cvtsd2si (v2df);
25623int __builtin_ia32_cvttsd2si (v2df);
25624long long __builtin_ia32_cvtsd2si64 (v2df);
25625long long __builtin_ia32_cvttsd2si64 (v2df);
25626v4si __builtin_ia32_cvtps2dq (v4sf);
25627v2df __builtin_ia32_cvtps2pd (v4sf);
25628v4si __builtin_ia32_cvttps2dq (v4sf);
25629v2df __builtin_ia32_cvtsi2sd (v2df, int);
25630v2df __builtin_ia32_cvtsi642sd (v2df, long long);
25631v4sf __builtin_ia32_cvtsd2ss (v4sf, v2df);
25632v2df __builtin_ia32_cvtss2sd (v2df, v4sf);
25633void __builtin_ia32_clflush (const void *);
25634void __builtin_ia32_lfence (void);
25635void __builtin_ia32_mfence (void);
25636v16qi __builtin_ia32_loaddqu (const char *);
25637void __builtin_ia32_storedqu (char *, v16qi);
25638v1di __builtin_ia32_pmuludq (v2si, v2si);
25639v2di __builtin_ia32_pmuludq128 (v4si, v4si);
25640v8hi __builtin_ia32_psllw128 (v8hi, v8hi);
25641v4si __builtin_ia32_pslld128 (v4si, v4si);
25642v2di __builtin_ia32_psllq128 (v2di, v2di);
25643v8hi __builtin_ia32_psrlw128 (v8hi, v8hi);
25644v4si __builtin_ia32_psrld128 (v4si, v4si);
25645v2di __builtin_ia32_psrlq128 (v2di, v2di);
25646v8hi __builtin_ia32_psraw128 (v8hi, v8hi);
25647v4si __builtin_ia32_psrad128 (v4si, v4si);
25648v2di __builtin_ia32_pslldqi128 (v2di, int);
25649v8hi __builtin_ia32_psllwi128 (v8hi, int);
25650v4si __builtin_ia32_pslldi128 (v4si, int);
25651v2di __builtin_ia32_psllqi128 (v2di, int);
25652v2di __builtin_ia32_psrldqi128 (v2di, int);
25653v8hi __builtin_ia32_psrlwi128 (v8hi, int);
25654v4si __builtin_ia32_psrldi128 (v4si, int);
25655v2di __builtin_ia32_psrlqi128 (v2di, int);
25656v8hi __builtin_ia32_psrawi128 (v8hi, int);
25657v4si __builtin_ia32_psradi128 (v4si, int);
25658v4si __builtin_ia32_pmaddwd128 (v8hi, v8hi);
25659v2di __builtin_ia32_movq128 (v2di);
25660@end smallexample
25661
25662The following built-in functions are available when @option{-msse3} is used.
25663All of them generate the machine instruction that is part of the name.
25664
25665@smallexample
25666v2df __builtin_ia32_addsubpd (v2df, v2df);
25667v4sf __builtin_ia32_addsubps (v4sf, v4sf);
25668v2df __builtin_ia32_haddpd (v2df, v2df);
25669v4sf __builtin_ia32_haddps (v4sf, v4sf);
25670v2df __builtin_ia32_hsubpd (v2df, v2df);
25671v4sf __builtin_ia32_hsubps (v4sf, v4sf);
25672v16qi __builtin_ia32_lddqu (char const *);
25673void __builtin_ia32_monitor (void *, unsigned int, unsigned int);
25674v4sf __builtin_ia32_movshdup (v4sf);
25675v4sf __builtin_ia32_movsldup (v4sf);
25676void __builtin_ia32_mwait (unsigned int, unsigned int);
25677@end smallexample
25678
25679The following built-in functions are available when @option{-mssse3} is used.
25680All of them generate the machine instruction that is part of the name.
25681
25682@smallexample
25683v2si __builtin_ia32_phaddd (v2si, v2si);
25684v4hi __builtin_ia32_phaddw (v4hi, v4hi);
25685v4hi __builtin_ia32_phaddsw (v4hi, v4hi);
25686v2si __builtin_ia32_phsubd (v2si, v2si);
25687v4hi __builtin_ia32_phsubw (v4hi, v4hi);
25688v4hi __builtin_ia32_phsubsw (v4hi, v4hi);
25689v4hi __builtin_ia32_pmaddubsw (v8qi, v8qi);
25690v4hi __builtin_ia32_pmulhrsw (v4hi, v4hi);
25691v8qi __builtin_ia32_pshufb (v8qi, v8qi);
25692v8qi __builtin_ia32_psignb (v8qi, v8qi);
25693v2si __builtin_ia32_psignd (v2si, v2si);
25694v4hi __builtin_ia32_psignw (v4hi, v4hi);
25695v1di __builtin_ia32_palignr (v1di, v1di, int);
25696v8qi __builtin_ia32_pabsb (v8qi);
25697v2si __builtin_ia32_pabsd (v2si);
25698v4hi __builtin_ia32_pabsw (v4hi);
25699@end smallexample
25700
25701The following built-in functions are available when @option{-mssse3} is used.
25702All of them generate the machine instruction that is part of the name.
25703
25704@smallexample
25705v4si __builtin_ia32_phaddd128 (v4si, v4si);
25706v8hi __builtin_ia32_phaddw128 (v8hi, v8hi);
25707v8hi __builtin_ia32_phaddsw128 (v8hi, v8hi);
25708v4si __builtin_ia32_phsubd128 (v4si, v4si);
25709v8hi __builtin_ia32_phsubw128 (v8hi, v8hi);
25710v8hi __builtin_ia32_phsubsw128 (v8hi, v8hi);
25711v8hi __builtin_ia32_pmaddubsw128 (v16qi, v16qi);
25712v8hi __builtin_ia32_pmulhrsw128 (v8hi, v8hi);
25713v16qi __builtin_ia32_pshufb128 (v16qi, v16qi);
25714v16qi __builtin_ia32_psignb128 (v16qi, v16qi);
25715v4si __builtin_ia32_psignd128 (v4si, v4si);
25716v8hi __builtin_ia32_psignw128 (v8hi, v8hi);
25717v2di __builtin_ia32_palignr128 (v2di, v2di, int);
25718v16qi __builtin_ia32_pabsb128 (v16qi);
25719v4si __builtin_ia32_pabsd128 (v4si);
25720v8hi __builtin_ia32_pabsw128 (v8hi);
25721@end smallexample
25722
25723The following built-in functions are available when @option{-msse4.1} is
25724used. All of them generate the machine instruction that is part of the
25725name.
25726
25727@smallexample
25728v2df __builtin_ia32_blendpd (v2df, v2df, const int);
25729v4sf __builtin_ia32_blendps (v4sf, v4sf, const int);
25730v2df __builtin_ia32_blendvpd (v2df, v2df, v2df);
25731v4sf __builtin_ia32_blendvps (v4sf, v4sf, v4sf);
25732v2df __builtin_ia32_dppd (v2df, v2df, const int);
25733v4sf __builtin_ia32_dpps (v4sf, v4sf, const int);
25734v4sf __builtin_ia32_insertps128 (v4sf, v4sf, const int);
25735v2di __builtin_ia32_movntdqa (v2di *);
25736v16qi __builtin_ia32_mpsadbw128 (v16qi, v16qi, const int);
25737v8hi __builtin_ia32_packusdw128 (v4si, v4si);
25738v16qi __builtin_ia32_pblendvb128 (v16qi, v16qi, v16qi);
25739v8hi __builtin_ia32_pblendw128 (v8hi, v8hi, const int);
25740v2di __builtin_ia32_pcmpeqq (v2di, v2di);
25741v8hi __builtin_ia32_phminposuw128 (v8hi);
25742v16qi __builtin_ia32_pmaxsb128 (v16qi, v16qi);
25743v4si __builtin_ia32_pmaxsd128 (v4si, v4si);
25744v4si __builtin_ia32_pmaxud128 (v4si, v4si);
25745v8hi __builtin_ia32_pmaxuw128 (v8hi, v8hi);
25746v16qi __builtin_ia32_pminsb128 (v16qi, v16qi);
25747v4si __builtin_ia32_pminsd128 (v4si, v4si);
25748v4si __builtin_ia32_pminud128 (v4si, v4si);
25749v8hi __builtin_ia32_pminuw128 (v8hi, v8hi);
25750v4si __builtin_ia32_pmovsxbd128 (v16qi);
25751v2di __builtin_ia32_pmovsxbq128 (v16qi);
25752v8hi __builtin_ia32_pmovsxbw128 (v16qi);
25753v2di __builtin_ia32_pmovsxdq128 (v4si);
25754v4si __builtin_ia32_pmovsxwd128 (v8hi);
25755v2di __builtin_ia32_pmovsxwq128 (v8hi);
25756v4si __builtin_ia32_pmovzxbd128 (v16qi);
25757v2di __builtin_ia32_pmovzxbq128 (v16qi);
25758v8hi __builtin_ia32_pmovzxbw128 (v16qi);
25759v2di __builtin_ia32_pmovzxdq128 (v4si);
25760v4si __builtin_ia32_pmovzxwd128 (v8hi);
25761v2di __builtin_ia32_pmovzxwq128 (v8hi);
25762v2di __builtin_ia32_pmuldq128 (v4si, v4si);
25763v4si __builtin_ia32_pmulld128 (v4si, v4si);
25764int __builtin_ia32_ptestc128 (v2di, v2di);
25765int __builtin_ia32_ptestnzc128 (v2di, v2di);
25766int __builtin_ia32_ptestz128 (v2di, v2di);
25767v2df __builtin_ia32_roundpd (v2df, const int);
25768v4sf __builtin_ia32_roundps (v4sf, const int);
25769v2df __builtin_ia32_roundsd (v2df, v2df, const int);
25770v4sf __builtin_ia32_roundss (v4sf, v4sf, const int);
25771@end smallexample
25772
25773The following built-in functions are available when @option{-msse4.1} is
25774used.
25775
f25efe50 25776@defbuiltin{v4sf __builtin_ia32_vec_set_v4sf (v4sf, float, const int)}
d77de738 25777Generates the @code{insertps} machine instruction.
f25efe50
AA
25778@enddefbuiltin
25779
25780@defbuiltin{int __builtin_ia32_vec_ext_v16qi (v16qi, const int)}
d77de738 25781Generates the @code{pextrb} machine instruction.
f25efe50
AA
25782@enddefbuiltin
25783
25784@defbuiltin{v16qi __builtin_ia32_vec_set_v16qi (v16qi, int, const int)}
d77de738 25785Generates the @code{pinsrb} machine instruction.
f25efe50
AA
25786@enddefbuiltin
25787
25788@defbuiltin{v4si __builtin_ia32_vec_set_v4si (v4si, int, const int)}
d77de738 25789Generates the @code{pinsrd} machine instruction.
f25efe50
AA
25790@enddefbuiltin
25791
25792@defbuiltin{v2di __builtin_ia32_vec_set_v2di (v2di, long long, const int)}
d77de738 25793Generates the @code{pinsrq} machine instruction in 64bit mode.
f25efe50 25794@enddefbuiltin
d77de738
ML
25795
25796The following built-in functions are changed to generate new SSE4.1
25797instructions when @option{-msse4.1} is used.
25798
f25efe50 25799@defbuiltin{float __builtin_ia32_vec_ext_v4sf (v4sf, const int)}
d77de738 25800Generates the @code{extractps} machine instruction.
f25efe50
AA
25801@enddefbuiltin
25802
25803@defbuiltin{int __builtin_ia32_vec_ext_v4si (v4si, const int)}
d77de738 25804Generates the @code{pextrd} machine instruction.
f25efe50
AA
25805@enddefbuiltin
25806
ff99671a 25807@defbuiltin{{long long} __builtin_ia32_vec_ext_v2di (v2di, const int)}
d77de738 25808Generates the @code{pextrq} machine instruction in 64bit mode.
f25efe50 25809@enddefbuiltin
d77de738
ML
25810
25811The following built-in functions are available when @option{-msse4.2} is
25812used. All of them generate the machine instruction that is part of the
25813name.
25814
25815@smallexample
25816v16qi __builtin_ia32_pcmpestrm128 (v16qi, int, v16qi, int, const int);
25817int __builtin_ia32_pcmpestri128 (v16qi, int, v16qi, int, const int);
25818int __builtin_ia32_pcmpestria128 (v16qi, int, v16qi, int, const int);
25819int __builtin_ia32_pcmpestric128 (v16qi, int, v16qi, int, const int);
25820int __builtin_ia32_pcmpestrio128 (v16qi, int, v16qi, int, const int);
25821int __builtin_ia32_pcmpestris128 (v16qi, int, v16qi, int, const int);
25822int __builtin_ia32_pcmpestriz128 (v16qi, int, v16qi, int, const int);
25823v16qi __builtin_ia32_pcmpistrm128 (v16qi, v16qi, const int);
25824int __builtin_ia32_pcmpistri128 (v16qi, v16qi, const int);
25825int __builtin_ia32_pcmpistria128 (v16qi, v16qi, const int);
25826int __builtin_ia32_pcmpistric128 (v16qi, v16qi, const int);
25827int __builtin_ia32_pcmpistrio128 (v16qi, v16qi, const int);
25828int __builtin_ia32_pcmpistris128 (v16qi, v16qi, const int);
25829int __builtin_ia32_pcmpistriz128 (v16qi, v16qi, const int);
25830v2di __builtin_ia32_pcmpgtq (v2di, v2di);
25831@end smallexample
25832
25833The following built-in functions are available when @option{-msse4.2} is
25834used.
25835
ff99671a 25836@defbuiltin{{unsigned int} __builtin_ia32_crc32qi (unsigned int, unsigned char)}
d77de738 25837Generates the @code{crc32b} machine instruction.
f25efe50
AA
25838@enddefbuiltin
25839
ff99671a 25840@defbuiltin{{unsigned int} __builtin_ia32_crc32hi (unsigned int, unsigned short)}
d77de738 25841Generates the @code{crc32w} machine instruction.
f25efe50
AA
25842@enddefbuiltin
25843
ff99671a 25844@defbuiltin{{unsigned int} __builtin_ia32_crc32si (unsigned int, unsigned int)}
d77de738 25845Generates the @code{crc32l} machine instruction.
f25efe50
AA
25846@enddefbuiltin
25847
ff99671a 25848@defbuiltin{{unsigned long long} __builtin_ia32_crc32di (unsigned long long, unsigned long long)}
d77de738 25849Generates the @code{crc32q} machine instruction.
f25efe50 25850@enddefbuiltin
d77de738
ML
25851
25852The following built-in functions are changed to generate new SSE4.2
25853instructions when @option{-msse4.2} is used.
25854
f25efe50 25855@defbuiltin{int __builtin_popcount (unsigned int)}
d77de738 25856Generates the @code{popcntl} machine instruction.
f25efe50
AA
25857@enddefbuiltin
25858
25859@defbuiltin{int __builtin_popcountl (unsigned long)}
d77de738
ML
25860Generates the @code{popcntl} or @code{popcntq} machine instruction,
25861depending on the size of @code{unsigned long}.
f25efe50
AA
25862@enddefbuiltin
25863
25864@defbuiltin{int __builtin_popcountll (unsigned long long)}
d77de738 25865Generates the @code{popcntq} machine instruction.
f25efe50 25866@enddefbuiltin
d77de738
ML
25867
25868The following built-in functions are available when @option{-mavx} is
25869used. All of them generate the machine instruction that is part of the
25870name.
25871
25872@smallexample
25873v4df __builtin_ia32_addpd256 (v4df,v4df);
25874v8sf __builtin_ia32_addps256 (v8sf,v8sf);
25875v4df __builtin_ia32_addsubpd256 (v4df,v4df);
25876v8sf __builtin_ia32_addsubps256 (v8sf,v8sf);
25877v4df __builtin_ia32_andnpd256 (v4df,v4df);
25878v8sf __builtin_ia32_andnps256 (v8sf,v8sf);
25879v4df __builtin_ia32_andpd256 (v4df,v4df);
25880v8sf __builtin_ia32_andps256 (v8sf,v8sf);
25881v4df __builtin_ia32_blendpd256 (v4df,v4df,int);
25882v8sf __builtin_ia32_blendps256 (v8sf,v8sf,int);
25883v4df __builtin_ia32_blendvpd256 (v4df,v4df,v4df);
25884v8sf __builtin_ia32_blendvps256 (v8sf,v8sf,v8sf);
25885v2df __builtin_ia32_cmppd (v2df,v2df,int);
25886v4df __builtin_ia32_cmppd256 (v4df,v4df,int);
25887v4sf __builtin_ia32_cmpps (v4sf,v4sf,int);
25888v8sf __builtin_ia32_cmpps256 (v8sf,v8sf,int);
25889v2df __builtin_ia32_cmpsd (v2df,v2df,int);
25890v4sf __builtin_ia32_cmpss (v4sf,v4sf,int);
25891v4df __builtin_ia32_cvtdq2pd256 (v4si);
25892v8sf __builtin_ia32_cvtdq2ps256 (v8si);
25893v4si __builtin_ia32_cvtpd2dq256 (v4df);
25894v4sf __builtin_ia32_cvtpd2ps256 (v4df);
25895v8si __builtin_ia32_cvtps2dq256 (v8sf);
25896v4df __builtin_ia32_cvtps2pd256 (v4sf);
25897v4si __builtin_ia32_cvttpd2dq256 (v4df);
25898v8si __builtin_ia32_cvttps2dq256 (v8sf);
25899v4df __builtin_ia32_divpd256 (v4df,v4df);
25900v8sf __builtin_ia32_divps256 (v8sf,v8sf);
25901v8sf __builtin_ia32_dpps256 (v8sf,v8sf,int);
25902v4df __builtin_ia32_haddpd256 (v4df,v4df);
25903v8sf __builtin_ia32_haddps256 (v8sf,v8sf);
25904v4df __builtin_ia32_hsubpd256 (v4df,v4df);
25905v8sf __builtin_ia32_hsubps256 (v8sf,v8sf);
25906v32qi __builtin_ia32_lddqu256 (pcchar);
25907v32qi __builtin_ia32_loaddqu256 (pcchar);
25908v4df __builtin_ia32_loadupd256 (pcdouble);
25909v8sf __builtin_ia32_loadups256 (pcfloat);
25910v2df __builtin_ia32_maskloadpd (pcv2df,v2df);
25911v4df __builtin_ia32_maskloadpd256 (pcv4df,v4df);
25912v4sf __builtin_ia32_maskloadps (pcv4sf,v4sf);
25913v8sf __builtin_ia32_maskloadps256 (pcv8sf,v8sf);
25914void __builtin_ia32_maskstorepd (pv2df,v2df,v2df);
25915void __builtin_ia32_maskstorepd256 (pv4df,v4df,v4df);
25916void __builtin_ia32_maskstoreps (pv4sf,v4sf,v4sf);
25917void __builtin_ia32_maskstoreps256 (pv8sf,v8sf,v8sf);
25918v4df __builtin_ia32_maxpd256 (v4df,v4df);
25919v8sf __builtin_ia32_maxps256 (v8sf,v8sf);
25920v4df __builtin_ia32_minpd256 (v4df,v4df);
25921v8sf __builtin_ia32_minps256 (v8sf,v8sf);
25922v4df __builtin_ia32_movddup256 (v4df);
25923int __builtin_ia32_movmskpd256 (v4df);
25924int __builtin_ia32_movmskps256 (v8sf);
25925v8sf __builtin_ia32_movshdup256 (v8sf);
25926v8sf __builtin_ia32_movsldup256 (v8sf);
25927v4df __builtin_ia32_mulpd256 (v4df,v4df);
25928v8sf __builtin_ia32_mulps256 (v8sf,v8sf);
25929v4df __builtin_ia32_orpd256 (v4df,v4df);
25930v8sf __builtin_ia32_orps256 (v8sf,v8sf);
25931v2df __builtin_ia32_pd_pd256 (v4df);
25932v4df __builtin_ia32_pd256_pd (v2df);
25933v4sf __builtin_ia32_ps_ps256 (v8sf);
25934v8sf __builtin_ia32_ps256_ps (v4sf);
25935int __builtin_ia32_ptestc256 (v4di,v4di,ptest);
25936int __builtin_ia32_ptestnzc256 (v4di,v4di,ptest);
25937int __builtin_ia32_ptestz256 (v4di,v4di,ptest);
25938v8sf __builtin_ia32_rcpps256 (v8sf);
25939v4df __builtin_ia32_roundpd256 (v4df,int);
25940v8sf __builtin_ia32_roundps256 (v8sf,int);
25941v8sf __builtin_ia32_rsqrtps_nr256 (v8sf);
25942v8sf __builtin_ia32_rsqrtps256 (v8sf);
25943v4df __builtin_ia32_shufpd256 (v4df,v4df,int);
25944v8sf __builtin_ia32_shufps256 (v8sf,v8sf,int);
25945v4si __builtin_ia32_si_si256 (v8si);
25946v8si __builtin_ia32_si256_si (v4si);
25947v4df __builtin_ia32_sqrtpd256 (v4df);
25948v8sf __builtin_ia32_sqrtps_nr256 (v8sf);
25949v8sf __builtin_ia32_sqrtps256 (v8sf);
25950void __builtin_ia32_storedqu256 (pchar,v32qi);
25951void __builtin_ia32_storeupd256 (pdouble,v4df);
25952void __builtin_ia32_storeups256 (pfloat,v8sf);
25953v4df __builtin_ia32_subpd256 (v4df,v4df);
25954v8sf __builtin_ia32_subps256 (v8sf,v8sf);
25955v4df __builtin_ia32_unpckhpd256 (v4df,v4df);
25956v8sf __builtin_ia32_unpckhps256 (v8sf,v8sf);
25957v4df __builtin_ia32_unpcklpd256 (v4df,v4df);
25958v8sf __builtin_ia32_unpcklps256 (v8sf,v8sf);
25959v4df __builtin_ia32_vbroadcastf128_pd256 (pcv2df);
25960v8sf __builtin_ia32_vbroadcastf128_ps256 (pcv4sf);
25961v4df __builtin_ia32_vbroadcastsd256 (pcdouble);
25962v4sf __builtin_ia32_vbroadcastss (pcfloat);
25963v8sf __builtin_ia32_vbroadcastss256 (pcfloat);
25964v2df __builtin_ia32_vextractf128_pd256 (v4df,int);
25965v4sf __builtin_ia32_vextractf128_ps256 (v8sf,int);
25966v4si __builtin_ia32_vextractf128_si256 (v8si,int);
25967v4df __builtin_ia32_vinsertf128_pd256 (v4df,v2df,int);
25968v8sf __builtin_ia32_vinsertf128_ps256 (v8sf,v4sf,int);
25969v8si __builtin_ia32_vinsertf128_si256 (v8si,v4si,int);
25970v4df __builtin_ia32_vperm2f128_pd256 (v4df,v4df,int);
25971v8sf __builtin_ia32_vperm2f128_ps256 (v8sf,v8sf,int);
25972v8si __builtin_ia32_vperm2f128_si256 (v8si,v8si,int);
25973v2df __builtin_ia32_vpermil2pd (v2df,v2df,v2di,int);
25974v4df __builtin_ia32_vpermil2pd256 (v4df,v4df,v4di,int);
25975v4sf __builtin_ia32_vpermil2ps (v4sf,v4sf,v4si,int);
25976v8sf __builtin_ia32_vpermil2ps256 (v8sf,v8sf,v8si,int);
25977v2df __builtin_ia32_vpermilpd (v2df,int);
25978v4df __builtin_ia32_vpermilpd256 (v4df,int);
25979v4sf __builtin_ia32_vpermilps (v4sf,int);
25980v8sf __builtin_ia32_vpermilps256 (v8sf,int);
25981v2df __builtin_ia32_vpermilvarpd (v2df,v2di);
25982v4df __builtin_ia32_vpermilvarpd256 (v4df,v4di);
25983v4sf __builtin_ia32_vpermilvarps (v4sf,v4si);
25984v8sf __builtin_ia32_vpermilvarps256 (v8sf,v8si);
25985int __builtin_ia32_vtestcpd (v2df,v2df,ptest);
25986int __builtin_ia32_vtestcpd256 (v4df,v4df,ptest);
25987int __builtin_ia32_vtestcps (v4sf,v4sf,ptest);
25988int __builtin_ia32_vtestcps256 (v8sf,v8sf,ptest);
25989int __builtin_ia32_vtestnzcpd (v2df,v2df,ptest);
25990int __builtin_ia32_vtestnzcpd256 (v4df,v4df,ptest);
25991int __builtin_ia32_vtestnzcps (v4sf,v4sf,ptest);
25992int __builtin_ia32_vtestnzcps256 (v8sf,v8sf,ptest);
25993int __builtin_ia32_vtestzpd (v2df,v2df,ptest);
25994int __builtin_ia32_vtestzpd256 (v4df,v4df,ptest);
25995int __builtin_ia32_vtestzps (v4sf,v4sf,ptest);
25996int __builtin_ia32_vtestzps256 (v8sf,v8sf,ptest);
25997void __builtin_ia32_vzeroall (void);
25998void __builtin_ia32_vzeroupper (void);
25999v4df __builtin_ia32_xorpd256 (v4df,v4df);
26000v8sf __builtin_ia32_xorps256 (v8sf,v8sf);
26001@end smallexample
26002
26003The following built-in functions are available when @option{-mavx2} is
26004used. All of them generate the machine instruction that is part of the
26005name.
26006
26007@smallexample
26008v32qi __builtin_ia32_mpsadbw256 (v32qi,v32qi,int);
26009v32qi __builtin_ia32_pabsb256 (v32qi);
26010v16hi __builtin_ia32_pabsw256 (v16hi);
26011v8si __builtin_ia32_pabsd256 (v8si);
26012v16hi __builtin_ia32_packssdw256 (v8si,v8si);
26013v32qi __builtin_ia32_packsswb256 (v16hi,v16hi);
26014v16hi __builtin_ia32_packusdw256 (v8si,v8si);
26015v32qi __builtin_ia32_packuswb256 (v16hi,v16hi);
26016v32qi __builtin_ia32_paddb256 (v32qi,v32qi);
26017v16hi __builtin_ia32_paddw256 (v16hi,v16hi);
26018v8si __builtin_ia32_paddd256 (v8si,v8si);
26019v4di __builtin_ia32_paddq256 (v4di,v4di);
26020v32qi __builtin_ia32_paddsb256 (v32qi,v32qi);
26021v16hi __builtin_ia32_paddsw256 (v16hi,v16hi);
26022v32qi __builtin_ia32_paddusb256 (v32qi,v32qi);
26023v16hi __builtin_ia32_paddusw256 (v16hi,v16hi);
26024v4di __builtin_ia32_palignr256 (v4di,v4di,int);
26025v4di __builtin_ia32_andsi256 (v4di,v4di);
26026v4di __builtin_ia32_andnotsi256 (v4di,v4di);
26027v32qi __builtin_ia32_pavgb256 (v32qi,v32qi);
26028v16hi __builtin_ia32_pavgw256 (v16hi,v16hi);
26029v32qi __builtin_ia32_pblendvb256 (v32qi,v32qi,v32qi);
26030v16hi __builtin_ia32_pblendw256 (v16hi,v16hi,int);
26031v32qi __builtin_ia32_pcmpeqb256 (v32qi,v32qi);
26032v16hi __builtin_ia32_pcmpeqw256 (v16hi,v16hi);
26033v8si __builtin_ia32_pcmpeqd256 (c8si,v8si);
26034v4di __builtin_ia32_pcmpeqq256 (v4di,v4di);
26035v32qi __builtin_ia32_pcmpgtb256 (v32qi,v32qi);
26036v16hi __builtin_ia32_pcmpgtw256 (16hi,v16hi);
26037v8si __builtin_ia32_pcmpgtd256 (v8si,v8si);
26038v4di __builtin_ia32_pcmpgtq256 (v4di,v4di);
26039v16hi __builtin_ia32_phaddw256 (v16hi,v16hi);
26040v8si __builtin_ia32_phaddd256 (v8si,v8si);
26041v16hi __builtin_ia32_phaddsw256 (v16hi,v16hi);
26042v16hi __builtin_ia32_phsubw256 (v16hi,v16hi);
26043v8si __builtin_ia32_phsubd256 (v8si,v8si);
26044v16hi __builtin_ia32_phsubsw256 (v16hi,v16hi);
26045v32qi __builtin_ia32_pmaddubsw256 (v32qi,v32qi);
26046v16hi __builtin_ia32_pmaddwd256 (v16hi,v16hi);
26047v32qi __builtin_ia32_pmaxsb256 (v32qi,v32qi);
26048v16hi __builtin_ia32_pmaxsw256 (v16hi,v16hi);
26049v8si __builtin_ia32_pmaxsd256 (v8si,v8si);
26050v32qi __builtin_ia32_pmaxub256 (v32qi,v32qi);
26051v16hi __builtin_ia32_pmaxuw256 (v16hi,v16hi);
26052v8si __builtin_ia32_pmaxud256 (v8si,v8si);
26053v32qi __builtin_ia32_pminsb256 (v32qi,v32qi);
26054v16hi __builtin_ia32_pminsw256 (v16hi,v16hi);
26055v8si __builtin_ia32_pminsd256 (v8si,v8si);
26056v32qi __builtin_ia32_pminub256 (v32qi,v32qi);
26057v16hi __builtin_ia32_pminuw256 (v16hi,v16hi);
26058v8si __builtin_ia32_pminud256 (v8si,v8si);
26059int __builtin_ia32_pmovmskb256 (v32qi);
26060v16hi __builtin_ia32_pmovsxbw256 (v16qi);
26061v8si __builtin_ia32_pmovsxbd256 (v16qi);
26062v4di __builtin_ia32_pmovsxbq256 (v16qi);
26063v8si __builtin_ia32_pmovsxwd256 (v8hi);
26064v4di __builtin_ia32_pmovsxwq256 (v8hi);
26065v4di __builtin_ia32_pmovsxdq256 (v4si);
26066v16hi __builtin_ia32_pmovzxbw256 (v16qi);
26067v8si __builtin_ia32_pmovzxbd256 (v16qi);
26068v4di __builtin_ia32_pmovzxbq256 (v16qi);
26069v8si __builtin_ia32_pmovzxwd256 (v8hi);
26070v4di __builtin_ia32_pmovzxwq256 (v8hi);
26071v4di __builtin_ia32_pmovzxdq256 (v4si);
26072v4di __builtin_ia32_pmuldq256 (v8si,v8si);
26073v16hi __builtin_ia32_pmulhrsw256 (v16hi, v16hi);
26074v16hi __builtin_ia32_pmulhuw256 (v16hi,v16hi);
26075v16hi __builtin_ia32_pmulhw256 (v16hi,v16hi);
26076v16hi __builtin_ia32_pmullw256 (v16hi,v16hi);
26077v8si __builtin_ia32_pmulld256 (v8si,v8si);
26078v4di __builtin_ia32_pmuludq256 (v8si,v8si);
26079v4di __builtin_ia32_por256 (v4di,v4di);
26080v16hi __builtin_ia32_psadbw256 (v32qi,v32qi);
26081v32qi __builtin_ia32_pshufb256 (v32qi,v32qi);
26082v8si __builtin_ia32_pshufd256 (v8si,int);
26083v16hi __builtin_ia32_pshufhw256 (v16hi,int);
26084v16hi __builtin_ia32_pshuflw256 (v16hi,int);
26085v32qi __builtin_ia32_psignb256 (v32qi,v32qi);
26086v16hi __builtin_ia32_psignw256 (v16hi,v16hi);
26087v8si __builtin_ia32_psignd256 (v8si,v8si);
26088v4di __builtin_ia32_pslldqi256 (v4di,int);
26089v16hi __builtin_ia32_psllwi256 (16hi,int);
26090v16hi __builtin_ia32_psllw256(v16hi,v8hi);
26091v8si __builtin_ia32_pslldi256 (v8si,int);
26092v8si __builtin_ia32_pslld256(v8si,v4si);
26093v4di __builtin_ia32_psllqi256 (v4di,int);
26094v4di __builtin_ia32_psllq256(v4di,v2di);
26095v16hi __builtin_ia32_psrawi256 (v16hi,int);
26096v16hi __builtin_ia32_psraw256 (v16hi,v8hi);
26097v8si __builtin_ia32_psradi256 (v8si,int);
26098v8si __builtin_ia32_psrad256 (v8si,v4si);
26099v4di __builtin_ia32_psrldqi256 (v4di, int);
26100v16hi __builtin_ia32_psrlwi256 (v16hi,int);
26101v16hi __builtin_ia32_psrlw256 (v16hi,v8hi);
26102v8si __builtin_ia32_psrldi256 (v8si,int);
26103v8si __builtin_ia32_psrld256 (v8si,v4si);
26104v4di __builtin_ia32_psrlqi256 (v4di,int);
26105v4di __builtin_ia32_psrlq256(v4di,v2di);
26106v32qi __builtin_ia32_psubb256 (v32qi,v32qi);
26107v32hi __builtin_ia32_psubw256 (v16hi,v16hi);
26108v8si __builtin_ia32_psubd256 (v8si,v8si);
26109v4di __builtin_ia32_psubq256 (v4di,v4di);
26110v32qi __builtin_ia32_psubsb256 (v32qi,v32qi);
26111v16hi __builtin_ia32_psubsw256 (v16hi,v16hi);
26112v32qi __builtin_ia32_psubusb256 (v32qi,v32qi);
26113v16hi __builtin_ia32_psubusw256 (v16hi,v16hi);
26114v32qi __builtin_ia32_punpckhbw256 (v32qi,v32qi);
26115v16hi __builtin_ia32_punpckhwd256 (v16hi,v16hi);
26116v8si __builtin_ia32_punpckhdq256 (v8si,v8si);
26117v4di __builtin_ia32_punpckhqdq256 (v4di,v4di);
26118v32qi __builtin_ia32_punpcklbw256 (v32qi,v32qi);
26119v16hi __builtin_ia32_punpcklwd256 (v16hi,v16hi);
26120v8si __builtin_ia32_punpckldq256 (v8si,v8si);
26121v4di __builtin_ia32_punpcklqdq256 (v4di,v4di);
26122v4di __builtin_ia32_pxor256 (v4di,v4di);
26123v4di __builtin_ia32_movntdqa256 (pv4di);
26124v4sf __builtin_ia32_vbroadcastss_ps (v4sf);
26125v8sf __builtin_ia32_vbroadcastss_ps256 (v4sf);
26126v4df __builtin_ia32_vbroadcastsd_pd256 (v2df);
26127v4di __builtin_ia32_vbroadcastsi256 (v2di);
26128v4si __builtin_ia32_pblendd128 (v4si,v4si);
26129v8si __builtin_ia32_pblendd256 (v8si,v8si);
26130v32qi __builtin_ia32_pbroadcastb256 (v16qi);
26131v16hi __builtin_ia32_pbroadcastw256 (v8hi);
26132v8si __builtin_ia32_pbroadcastd256 (v4si);
26133v4di __builtin_ia32_pbroadcastq256 (v2di);
26134v16qi __builtin_ia32_pbroadcastb128 (v16qi);
26135v8hi __builtin_ia32_pbroadcastw128 (v8hi);
26136v4si __builtin_ia32_pbroadcastd128 (v4si);
26137v2di __builtin_ia32_pbroadcastq128 (v2di);
26138v8si __builtin_ia32_permvarsi256 (v8si,v8si);
26139v4df __builtin_ia32_permdf256 (v4df,int);
26140v8sf __builtin_ia32_permvarsf256 (v8sf,v8sf);
26141v4di __builtin_ia32_permdi256 (v4di,int);
26142v4di __builtin_ia32_permti256 (v4di,v4di,int);
26143v4di __builtin_ia32_extract128i256 (v4di,int);
26144v4di __builtin_ia32_insert128i256 (v4di,v2di,int);
26145v8si __builtin_ia32_maskloadd256 (pcv8si,v8si);
26146v4di __builtin_ia32_maskloadq256 (pcv4di,v4di);
26147v4si __builtin_ia32_maskloadd (pcv4si,v4si);
26148v2di __builtin_ia32_maskloadq (pcv2di,v2di);
26149void __builtin_ia32_maskstored256 (pv8si,v8si,v8si);
26150void __builtin_ia32_maskstoreq256 (pv4di,v4di,v4di);
26151void __builtin_ia32_maskstored (pv4si,v4si,v4si);
26152void __builtin_ia32_maskstoreq (pv2di,v2di,v2di);
26153v8si __builtin_ia32_psllv8si (v8si,v8si);
26154v4si __builtin_ia32_psllv4si (v4si,v4si);
26155v4di __builtin_ia32_psllv4di (v4di,v4di);
26156v2di __builtin_ia32_psllv2di (v2di,v2di);
26157v8si __builtin_ia32_psrav8si (v8si,v8si);
26158v4si __builtin_ia32_psrav4si (v4si,v4si);
26159v8si __builtin_ia32_psrlv8si (v8si,v8si);
26160v4si __builtin_ia32_psrlv4si (v4si,v4si);
26161v4di __builtin_ia32_psrlv4di (v4di,v4di);
26162v2di __builtin_ia32_psrlv2di (v2di,v2di);
26163v2df __builtin_ia32_gathersiv2df (v2df, pcdouble,v4si,v2df,int);
26164v4df __builtin_ia32_gathersiv4df (v4df, pcdouble,v4si,v4df,int);
26165v2df __builtin_ia32_gatherdiv2df (v2df, pcdouble,v2di,v2df,int);
26166v4df __builtin_ia32_gatherdiv4df (v4df, pcdouble,v4di,v4df,int);
26167v4sf __builtin_ia32_gathersiv4sf (v4sf, pcfloat,v4si,v4sf,int);
26168v8sf __builtin_ia32_gathersiv8sf (v8sf, pcfloat,v8si,v8sf,int);
26169v4sf __builtin_ia32_gatherdiv4sf (v4sf, pcfloat,v2di,v4sf,int);
26170v4sf __builtin_ia32_gatherdiv4sf256 (v4sf, pcfloat,v4di,v4sf,int);
26171v2di __builtin_ia32_gathersiv2di (v2di, pcint64,v4si,v2di,int);
26172v4di __builtin_ia32_gathersiv4di (v4di, pcint64,v4si,v4di,int);
26173v2di __builtin_ia32_gatherdiv2di (v2di, pcint64,v2di,v2di,int);
26174v4di __builtin_ia32_gatherdiv4di (v4di, pcint64,v4di,v4di,int);
26175v4si __builtin_ia32_gathersiv4si (v4si, pcint,v4si,v4si,int);
26176v8si __builtin_ia32_gathersiv8si (v8si, pcint,v8si,v8si,int);
26177v4si __builtin_ia32_gatherdiv4si (v4si, pcint,v2di,v4si,int);
26178v4si __builtin_ia32_gatherdiv4si256 (v4si, pcint,v4di,v4si,int);
26179@end smallexample
26180
26181The following built-in functions are available when @option{-maes} is
26182used. All of them generate the machine instruction that is part of the
26183name.
26184
26185@smallexample
26186v2di __builtin_ia32_aesenc128 (v2di, v2di);
26187v2di __builtin_ia32_aesenclast128 (v2di, v2di);
26188v2di __builtin_ia32_aesdec128 (v2di, v2di);
26189v2di __builtin_ia32_aesdeclast128 (v2di, v2di);
26190v2di __builtin_ia32_aeskeygenassist128 (v2di, const int);
26191v2di __builtin_ia32_aesimc128 (v2di);
26192@end smallexample
26193
26194The following built-in function is available when @option{-mpclmul} is
26195used.
26196
f25efe50 26197@defbuiltin{v2di __builtin_ia32_pclmulqdq128 (v2di, v2di, const int)}
d77de738 26198Generates the @code{pclmulqdq} machine instruction.
f25efe50 26199@enddefbuiltin
d77de738
ML
26200
26201The following built-in function is available when @option{-mfsgsbase} is
26202used. All of them generate the machine instruction that is part of the
26203name.
26204
26205@smallexample
26206unsigned int __builtin_ia32_rdfsbase32 (void);
26207unsigned long long __builtin_ia32_rdfsbase64 (void);
26208unsigned int __builtin_ia32_rdgsbase32 (void);
26209unsigned long long __builtin_ia32_rdgsbase64 (void);
26210void _writefsbase_u32 (unsigned int);
26211void _writefsbase_u64 (unsigned long long);
26212void _writegsbase_u32 (unsigned int);
26213void _writegsbase_u64 (unsigned long long);
26214@end smallexample
26215
26216The following built-in function is available when @option{-mrdrnd} is
26217used. All of them generate the machine instruction that is part of the
26218name.
26219
26220@smallexample
26221unsigned int __builtin_ia32_rdrand16_step (unsigned short *);
26222unsigned int __builtin_ia32_rdrand32_step (unsigned int *);
26223unsigned int __builtin_ia32_rdrand64_step (unsigned long long *);
26224@end smallexample
26225
26226The following built-in function is available when @option{-mptwrite} is
26227used. All of them generate the machine instruction that is part of the
26228name.
26229
26230@smallexample
26231void __builtin_ia32_ptwrite32 (unsigned);
26232void __builtin_ia32_ptwrite64 (unsigned long long);
26233@end smallexample
26234
26235The following built-in functions are available when @option{-msse4a} is used.
26236All of them generate the machine instruction that is part of the name.
26237
26238@smallexample
26239void __builtin_ia32_movntsd (double *, v2df);
26240void __builtin_ia32_movntss (float *, v4sf);
26241v2di __builtin_ia32_extrq (v2di, v16qi);
26242v2di __builtin_ia32_extrqi (v2di, const unsigned int, const unsigned int);
26243v2di __builtin_ia32_insertq (v2di, v2di);
26244v2di __builtin_ia32_insertqi (v2di, v2di, const unsigned int, const unsigned int);
26245@end smallexample
26246
26247The following built-in functions are available when @option{-mxop} is used.
26248@smallexample
26249v2df __builtin_ia32_vfrczpd (v2df);
26250v4sf __builtin_ia32_vfrczps (v4sf);
26251v2df __builtin_ia32_vfrczsd (v2df);
26252v4sf __builtin_ia32_vfrczss (v4sf);
26253v4df __builtin_ia32_vfrczpd256 (v4df);
26254v8sf __builtin_ia32_vfrczps256 (v8sf);
26255v2di __builtin_ia32_vpcmov (v2di, v2di, v2di);
26256v2di __builtin_ia32_vpcmov_v2di (v2di, v2di, v2di);
26257v4si __builtin_ia32_vpcmov_v4si (v4si, v4si, v4si);
26258v8hi __builtin_ia32_vpcmov_v8hi (v8hi, v8hi, v8hi);
26259v16qi __builtin_ia32_vpcmov_v16qi (v16qi, v16qi, v16qi);
26260v2df __builtin_ia32_vpcmov_v2df (v2df, v2df, v2df);
26261v4sf __builtin_ia32_vpcmov_v4sf (v4sf, v4sf, v4sf);
26262v4di __builtin_ia32_vpcmov_v4di256 (v4di, v4di, v4di);
26263v8si __builtin_ia32_vpcmov_v8si256 (v8si, v8si, v8si);
26264v16hi __builtin_ia32_vpcmov_v16hi256 (v16hi, v16hi, v16hi);
26265v32qi __builtin_ia32_vpcmov_v32qi256 (v32qi, v32qi, v32qi);
26266v4df __builtin_ia32_vpcmov_v4df256 (v4df, v4df, v4df);
26267v8sf __builtin_ia32_vpcmov_v8sf256 (v8sf, v8sf, v8sf);
26268v16qi __builtin_ia32_vpcomeqb (v16qi, v16qi);
26269v8hi __builtin_ia32_vpcomeqw (v8hi, v8hi);
26270v4si __builtin_ia32_vpcomeqd (v4si, v4si);
26271v2di __builtin_ia32_vpcomeqq (v2di, v2di);
26272v16qi __builtin_ia32_vpcomequb (v16qi, v16qi);
26273v4si __builtin_ia32_vpcomequd (v4si, v4si);
26274v2di __builtin_ia32_vpcomequq (v2di, v2di);
26275v8hi __builtin_ia32_vpcomequw (v8hi, v8hi);
26276v8hi __builtin_ia32_vpcomeqw (v8hi, v8hi);
26277v16qi __builtin_ia32_vpcomfalseb (v16qi, v16qi);
26278v4si __builtin_ia32_vpcomfalsed (v4si, v4si);
26279v2di __builtin_ia32_vpcomfalseq (v2di, v2di);
26280v16qi __builtin_ia32_vpcomfalseub (v16qi, v16qi);
26281v4si __builtin_ia32_vpcomfalseud (v4si, v4si);
26282v2di __builtin_ia32_vpcomfalseuq (v2di, v2di);
26283v8hi __builtin_ia32_vpcomfalseuw (v8hi, v8hi);
26284v8hi __builtin_ia32_vpcomfalsew (v8hi, v8hi);
26285v16qi __builtin_ia32_vpcomgeb (v16qi, v16qi);
26286v4si __builtin_ia32_vpcomged (v4si, v4si);
26287v2di __builtin_ia32_vpcomgeq (v2di, v2di);
26288v16qi __builtin_ia32_vpcomgeub (v16qi, v16qi);
26289v4si __builtin_ia32_vpcomgeud (v4si, v4si);
26290v2di __builtin_ia32_vpcomgeuq (v2di, v2di);
26291v8hi __builtin_ia32_vpcomgeuw (v8hi, v8hi);
26292v8hi __builtin_ia32_vpcomgew (v8hi, v8hi);
26293v16qi __builtin_ia32_vpcomgtb (v16qi, v16qi);
26294v4si __builtin_ia32_vpcomgtd (v4si, v4si);
26295v2di __builtin_ia32_vpcomgtq (v2di, v2di);
26296v16qi __builtin_ia32_vpcomgtub (v16qi, v16qi);
26297v4si __builtin_ia32_vpcomgtud (v4si, v4si);
26298v2di __builtin_ia32_vpcomgtuq (v2di, v2di);
26299v8hi __builtin_ia32_vpcomgtuw (v8hi, v8hi);
26300v8hi __builtin_ia32_vpcomgtw (v8hi, v8hi);
26301v16qi __builtin_ia32_vpcomleb (v16qi, v16qi);
26302v4si __builtin_ia32_vpcomled (v4si, v4si);
26303v2di __builtin_ia32_vpcomleq (v2di, v2di);
26304v16qi __builtin_ia32_vpcomleub (v16qi, v16qi);
26305v4si __builtin_ia32_vpcomleud (v4si, v4si);
26306v2di __builtin_ia32_vpcomleuq (v2di, v2di);
26307v8hi __builtin_ia32_vpcomleuw (v8hi, v8hi);
26308v8hi __builtin_ia32_vpcomlew (v8hi, v8hi);
26309v16qi __builtin_ia32_vpcomltb (v16qi, v16qi);
26310v4si __builtin_ia32_vpcomltd (v4si, v4si);
26311v2di __builtin_ia32_vpcomltq (v2di, v2di);
26312v16qi __builtin_ia32_vpcomltub (v16qi, v16qi);
26313v4si __builtin_ia32_vpcomltud (v4si, v4si);
26314v2di __builtin_ia32_vpcomltuq (v2di, v2di);
26315v8hi __builtin_ia32_vpcomltuw (v8hi, v8hi);
26316v8hi __builtin_ia32_vpcomltw (v8hi, v8hi);
26317v16qi __builtin_ia32_vpcomneb (v16qi, v16qi);
26318v4si __builtin_ia32_vpcomned (v4si, v4si);
26319v2di __builtin_ia32_vpcomneq (v2di, v2di);
26320v16qi __builtin_ia32_vpcomneub (v16qi, v16qi);
26321v4si __builtin_ia32_vpcomneud (v4si, v4si);
26322v2di __builtin_ia32_vpcomneuq (v2di, v2di);
26323v8hi __builtin_ia32_vpcomneuw (v8hi, v8hi);
26324v8hi __builtin_ia32_vpcomnew (v8hi, v8hi);
26325v16qi __builtin_ia32_vpcomtrueb (v16qi, v16qi);
26326v4si __builtin_ia32_vpcomtrued (v4si, v4si);
26327v2di __builtin_ia32_vpcomtrueq (v2di, v2di);
26328v16qi __builtin_ia32_vpcomtrueub (v16qi, v16qi);
26329v4si __builtin_ia32_vpcomtrueud (v4si, v4si);
26330v2di __builtin_ia32_vpcomtrueuq (v2di, v2di);
26331v8hi __builtin_ia32_vpcomtrueuw (v8hi, v8hi);
26332v8hi __builtin_ia32_vpcomtruew (v8hi, v8hi);
26333v4si __builtin_ia32_vphaddbd (v16qi);
26334v2di __builtin_ia32_vphaddbq (v16qi);
26335v8hi __builtin_ia32_vphaddbw (v16qi);
26336v2di __builtin_ia32_vphadddq (v4si);
26337v4si __builtin_ia32_vphaddubd (v16qi);
26338v2di __builtin_ia32_vphaddubq (v16qi);
26339v8hi __builtin_ia32_vphaddubw (v16qi);
26340v2di __builtin_ia32_vphaddudq (v4si);
26341v4si __builtin_ia32_vphadduwd (v8hi);
26342v2di __builtin_ia32_vphadduwq (v8hi);
26343v4si __builtin_ia32_vphaddwd (v8hi);
26344v2di __builtin_ia32_vphaddwq (v8hi);
26345v8hi __builtin_ia32_vphsubbw (v16qi);
26346v2di __builtin_ia32_vphsubdq (v4si);
26347v4si __builtin_ia32_vphsubwd (v8hi);
26348v4si __builtin_ia32_vpmacsdd (v4si, v4si, v4si);
26349v2di __builtin_ia32_vpmacsdqh (v4si, v4si, v2di);
26350v2di __builtin_ia32_vpmacsdql (v4si, v4si, v2di);
26351v4si __builtin_ia32_vpmacssdd (v4si, v4si, v4si);
26352v2di __builtin_ia32_vpmacssdqh (v4si, v4si, v2di);
26353v2di __builtin_ia32_vpmacssdql (v4si, v4si, v2di);
26354v4si __builtin_ia32_vpmacsswd (v8hi, v8hi, v4si);
26355v8hi __builtin_ia32_vpmacssww (v8hi, v8hi, v8hi);
26356v4si __builtin_ia32_vpmacswd (v8hi, v8hi, v4si);
26357v8hi __builtin_ia32_vpmacsww (v8hi, v8hi, v8hi);
26358v4si __builtin_ia32_vpmadcsswd (v8hi, v8hi, v4si);
26359v4si __builtin_ia32_vpmadcswd (v8hi, v8hi, v4si);
26360v16qi __builtin_ia32_vpperm (v16qi, v16qi, v16qi);
26361v16qi __builtin_ia32_vprotb (v16qi, v16qi);
26362v4si __builtin_ia32_vprotd (v4si, v4si);
26363v2di __builtin_ia32_vprotq (v2di, v2di);
26364v8hi __builtin_ia32_vprotw (v8hi, v8hi);
26365v16qi __builtin_ia32_vpshab (v16qi, v16qi);
26366v4si __builtin_ia32_vpshad (v4si, v4si);
26367v2di __builtin_ia32_vpshaq (v2di, v2di);
26368v8hi __builtin_ia32_vpshaw (v8hi, v8hi);
26369v16qi __builtin_ia32_vpshlb (v16qi, v16qi);
26370v4si __builtin_ia32_vpshld (v4si, v4si);
26371v2di __builtin_ia32_vpshlq (v2di, v2di);
26372v8hi __builtin_ia32_vpshlw (v8hi, v8hi);
26373@end smallexample
26374
26375The following built-in functions are available when @option{-mfma4} is used.
26376All of them generate the machine instruction that is part of the name.
26377
26378@smallexample
26379v2df __builtin_ia32_vfmaddpd (v2df, v2df, v2df);
26380v4sf __builtin_ia32_vfmaddps (v4sf, v4sf, v4sf);
26381v2df __builtin_ia32_vfmaddsd (v2df, v2df, v2df);
26382v4sf __builtin_ia32_vfmaddss (v4sf, v4sf, v4sf);
26383v2df __builtin_ia32_vfmsubpd (v2df, v2df, v2df);
26384v4sf __builtin_ia32_vfmsubps (v4sf, v4sf, v4sf);
26385v2df __builtin_ia32_vfmsubsd (v2df, v2df, v2df);
26386v4sf __builtin_ia32_vfmsubss (v4sf, v4sf, v4sf);
26387v2df __builtin_ia32_vfnmaddpd (v2df, v2df, v2df);
26388v4sf __builtin_ia32_vfnmaddps (v4sf, v4sf, v4sf);
26389v2df __builtin_ia32_vfnmaddsd (v2df, v2df, v2df);
26390v4sf __builtin_ia32_vfnmaddss (v4sf, v4sf, v4sf);
26391v2df __builtin_ia32_vfnmsubpd (v2df, v2df, v2df);
26392v4sf __builtin_ia32_vfnmsubps (v4sf, v4sf, v4sf);
26393v2df __builtin_ia32_vfnmsubsd (v2df, v2df, v2df);
26394v4sf __builtin_ia32_vfnmsubss (v4sf, v4sf, v4sf);
26395v2df __builtin_ia32_vfmaddsubpd (v2df, v2df, v2df);
26396v4sf __builtin_ia32_vfmaddsubps (v4sf, v4sf, v4sf);
26397v2df __builtin_ia32_vfmsubaddpd (v2df, v2df, v2df);
26398v4sf __builtin_ia32_vfmsubaddps (v4sf, v4sf, v4sf);
26399v4df __builtin_ia32_vfmaddpd256 (v4df, v4df, v4df);
26400v8sf __builtin_ia32_vfmaddps256 (v8sf, v8sf, v8sf);
26401v4df __builtin_ia32_vfmsubpd256 (v4df, v4df, v4df);
26402v8sf __builtin_ia32_vfmsubps256 (v8sf, v8sf, v8sf);
26403v4df __builtin_ia32_vfnmaddpd256 (v4df, v4df, v4df);
26404v8sf __builtin_ia32_vfnmaddps256 (v8sf, v8sf, v8sf);
26405v4df __builtin_ia32_vfnmsubpd256 (v4df, v4df, v4df);
26406v8sf __builtin_ia32_vfnmsubps256 (v8sf, v8sf, v8sf);
26407v4df __builtin_ia32_vfmaddsubpd256 (v4df, v4df, v4df);
26408v8sf __builtin_ia32_vfmaddsubps256 (v8sf, v8sf, v8sf);
26409v4df __builtin_ia32_vfmsubaddpd256 (v4df, v4df, v4df);
26410v8sf __builtin_ia32_vfmsubaddps256 (v8sf, v8sf, v8sf);
26411
26412@end smallexample
26413
26414The following built-in functions are available when @option{-mlwp} is used.
26415
26416@smallexample
26417void __builtin_ia32_llwpcb16 (void *);
26418void __builtin_ia32_llwpcb32 (void *);
26419void __builtin_ia32_llwpcb64 (void *);
26420void * __builtin_ia32_llwpcb16 (void);
26421void * __builtin_ia32_llwpcb32 (void);
26422void * __builtin_ia32_llwpcb64 (void);
26423void __builtin_ia32_lwpval16 (unsigned short, unsigned int, unsigned short);
26424void __builtin_ia32_lwpval32 (unsigned int, unsigned int, unsigned int);
26425void __builtin_ia32_lwpval64 (unsigned __int64, unsigned int, unsigned int);
26426unsigned char __builtin_ia32_lwpins16 (unsigned short, unsigned int, unsigned short);
26427unsigned char __builtin_ia32_lwpins32 (unsigned int, unsigned int, unsigned int);
26428unsigned char __builtin_ia32_lwpins64 (unsigned __int64, unsigned int, unsigned int);
26429@end smallexample
26430
26431The following built-in functions are available when @option{-mbmi} is used.
26432All of them generate the machine instruction that is part of the name.
26433@smallexample
26434unsigned int __builtin_ia32_bextr_u32(unsigned int, unsigned int);
26435unsigned long long __builtin_ia32_bextr_u64 (unsigned long long, unsigned long long);
26436@end smallexample
26437
26438The following built-in functions are available when @option{-mbmi2} is used.
26439All of them generate the machine instruction that is part of the name.
26440@smallexample
26441unsigned int _bzhi_u32 (unsigned int, unsigned int);
26442unsigned int _pdep_u32 (unsigned int, unsigned int);
26443unsigned int _pext_u32 (unsigned int, unsigned int);
26444unsigned long long _bzhi_u64 (unsigned long long, unsigned long long);
26445unsigned long long _pdep_u64 (unsigned long long, unsigned long long);
26446unsigned long long _pext_u64 (unsigned long long, unsigned long long);
26447@end smallexample
26448
26449The following built-in functions are available when @option{-mlzcnt} is used.
26450All of them generate the machine instruction that is part of the name.
26451@smallexample
26452unsigned short __builtin_ia32_lzcnt_u16(unsigned short);
26453unsigned int __builtin_ia32_lzcnt_u32(unsigned int);
26454unsigned long long __builtin_ia32_lzcnt_u64 (unsigned long long);
26455@end smallexample
26456
26457The following built-in functions are available when @option{-mfxsr} is used.
26458All of them generate the machine instruction that is part of the name.
26459@smallexample
26460void __builtin_ia32_fxsave (void *);
26461void __builtin_ia32_fxrstor (void *);
26462void __builtin_ia32_fxsave64 (void *);
26463void __builtin_ia32_fxrstor64 (void *);
26464@end smallexample
26465
26466The following built-in functions are available when @option{-mxsave} is used.
26467All of them generate the machine instruction that is part of the name.
26468@smallexample
26469void __builtin_ia32_xsave (void *, long long);
26470void __builtin_ia32_xrstor (void *, long long);
26471void __builtin_ia32_xsave64 (void *, long long);
26472void __builtin_ia32_xrstor64 (void *, long long);
26473@end smallexample
26474
26475The following built-in functions are available when @option{-mxsaveopt} is used.
26476All of them generate the machine instruction that is part of the name.
26477@smallexample
26478void __builtin_ia32_xsaveopt (void *, long long);
26479void __builtin_ia32_xsaveopt64 (void *, long long);
26480@end smallexample
26481
26482The following built-in functions are available when @option{-mtbm} is used.
26483Both of them generate the immediate form of the bextr machine instruction.
26484@smallexample
26485unsigned int __builtin_ia32_bextri_u32 (unsigned int,
26486 const unsigned int);
26487unsigned long long __builtin_ia32_bextri_u64 (unsigned long long,
26488 const unsigned long long);
26489@end smallexample
26490
26491
26492The following built-in functions are available when @option{-m3dnow} is used.
26493All of them generate the machine instruction that is part of the name.
26494
26495@smallexample
26496void __builtin_ia32_femms (void);
26497v8qi __builtin_ia32_pavgusb (v8qi, v8qi);
26498v2si __builtin_ia32_pf2id (v2sf);
26499v2sf __builtin_ia32_pfacc (v2sf, v2sf);
26500v2sf __builtin_ia32_pfadd (v2sf, v2sf);
26501v2si __builtin_ia32_pfcmpeq (v2sf, v2sf);
26502v2si __builtin_ia32_pfcmpge (v2sf, v2sf);
26503v2si __builtin_ia32_pfcmpgt (v2sf, v2sf);
26504v2sf __builtin_ia32_pfmax (v2sf, v2sf);
26505v2sf __builtin_ia32_pfmin (v2sf, v2sf);
26506v2sf __builtin_ia32_pfmul (v2sf, v2sf);
26507v2sf __builtin_ia32_pfrcp (v2sf);
26508v2sf __builtin_ia32_pfrcpit1 (v2sf, v2sf);
26509v2sf __builtin_ia32_pfrcpit2 (v2sf, v2sf);
26510v2sf __builtin_ia32_pfrsqrt (v2sf);
26511v2sf __builtin_ia32_pfsub (v2sf, v2sf);
26512v2sf __builtin_ia32_pfsubr (v2sf, v2sf);
26513v2sf __builtin_ia32_pi2fd (v2si);
26514v4hi __builtin_ia32_pmulhrw (v4hi, v4hi);
26515@end smallexample
26516
26517The following built-in functions are available when @option{-m3dnowa} is used.
26518All of them generate the machine instruction that is part of the name.
26519
26520@smallexample
26521v2si __builtin_ia32_pf2iw (v2sf);
26522v2sf __builtin_ia32_pfnacc (v2sf, v2sf);
26523v2sf __builtin_ia32_pfpnacc (v2sf, v2sf);
26524v2sf __builtin_ia32_pi2fw (v2si);
26525v2sf __builtin_ia32_pswapdsf (v2sf);
26526v2si __builtin_ia32_pswapdsi (v2si);
26527@end smallexample
26528
26529The following built-in functions are available when @option{-mrtm} is used
26530They are used for restricted transactional memory. These are the internal
26531low level functions. Normally the functions in
26532@ref{x86 transactional memory intrinsics} should be used instead.
26533
26534@smallexample
26535int __builtin_ia32_xbegin ();
26536void __builtin_ia32_xend ();
26537void __builtin_ia32_xabort (status);
26538int __builtin_ia32_xtest ();
26539@end smallexample
26540
26541The following built-in functions are available when @option{-mmwaitx} is used.
26542All of them generate the machine instruction that is part of the name.
26543@smallexample
26544void __builtin_ia32_monitorx (void *, unsigned int, unsigned int);
26545void __builtin_ia32_mwaitx (unsigned int, unsigned int, unsigned int);
26546@end smallexample
26547
26548The following built-in functions are available when @option{-mclzero} is used.
26549All of them generate the machine instruction that is part of the name.
26550@smallexample
26551void __builtin_i32_clzero (void *);
26552@end smallexample
26553
26554The following built-in functions are available when @option{-mpku} is used.
26555They generate reads and writes to PKRU.
26556@smallexample
26557void __builtin_ia32_wrpkru (unsigned int);
26558unsigned int __builtin_ia32_rdpkru ();
26559@end smallexample
26560
26561The following built-in functions are available when
26562@option{-mshstk} option is used. They support shadow stack
26563machine instructions from Intel Control-flow Enforcement Technology (CET).
26564Each built-in function generates the machine instruction that is part
26565of the function's name. These are the internal low-level functions.
26566Normally the functions in @ref{x86 control-flow protection intrinsics}
26567should be used instead.
26568
26569@smallexample
26570unsigned int __builtin_ia32_rdsspd (void);
26571unsigned long long __builtin_ia32_rdsspq (void);
26572void __builtin_ia32_incsspd (unsigned int);
26573void __builtin_ia32_incsspq (unsigned long long);
26574void __builtin_ia32_saveprevssp(void);
26575void __builtin_ia32_rstorssp(void *);
26576void __builtin_ia32_wrssd(unsigned int, void *);
26577void __builtin_ia32_wrssq(unsigned long long, void *);
26578void __builtin_ia32_wrussd(unsigned int, void *);
26579void __builtin_ia32_wrussq(unsigned long long, void *);
26580void __builtin_ia32_setssbsy(void);
26581void __builtin_ia32_clrssbsy(void *);
26582@end smallexample
26583
26584@node x86 transactional memory intrinsics
26585@subsection x86 Transactional Memory Intrinsics
26586
26587These hardware transactional memory intrinsics for x86 allow you to use
26588memory transactions with RTM (Restricted Transactional Memory).
26589This support is enabled with the @option{-mrtm} option.
26590For using HLE (Hardware Lock Elision) see
26591@ref{x86 specific memory model extensions for transactional memory} instead.
26592
26593A memory transaction commits all changes to memory in an atomic way,
26594as visible to other threads. If the transaction fails it is rolled back
26595and all side effects discarded.
26596
26597Generally there is no guarantee that a memory transaction ever succeeds
26598and suitable fallback code always needs to be supplied.
26599
26600@deftypefn {RTM Function} {unsigned} _xbegin ()
26601Start a RTM (Restricted Transactional Memory) transaction.
26602Returns @code{_XBEGIN_STARTED} when the transaction
26603started successfully (note this is not 0, so the constant has to be
26604explicitly tested).
26605
26606If the transaction aborts, all side effects
26607are undone and an abort code encoded as a bit mask is returned.
26608The following macros are defined:
26609
f25efe50 26610@defmac{_XABORT_EXPLICIT}
d77de738
ML
26611Transaction was explicitly aborted with @code{_xabort}. The parameter passed
26612to @code{_xabort} is available with @code{_XABORT_CODE(status)}.
f25efe50
AA
26613@end defmac
26614
26615@defmac{_XABORT_RETRY}
d77de738 26616Transaction retry is possible.
f25efe50
AA
26617@end defmac
26618
26619@defmac{_XABORT_CONFLICT}
d77de738 26620Transaction abort due to a memory conflict with another thread.
f25efe50
AA
26621@end defmac
26622
26623@defmac{_XABORT_CAPACITY}
d77de738 26624Transaction abort due to the transaction using too much memory.
f25efe50
AA
26625@end defmac
26626
26627@defmac{_XABORT_DEBUG}
d77de738 26628Transaction abort due to a debug trap.
f25efe50
AA
26629@end defmac
26630
26631@defmac{_XABORT_NESTED}
d77de738 26632Transaction abort in an inner nested transaction.
f25efe50 26633@end defmac
d77de738
ML
26634
26635There is no guarantee
26636any transaction ever succeeds, so there always needs to be a valid
26637fallback path.
26638@end deftypefn
26639
26640@deftypefn {RTM Function} {void} _xend ()
26641Commit the current transaction. When no transaction is active this faults.
26642All memory side effects of the transaction become visible
26643to other threads in an atomic manner.
26644@end deftypefn
26645
26646@deftypefn {RTM Function} {int} _xtest ()
26647Return a nonzero value if a transaction is currently active, otherwise 0.
26648@end deftypefn
26649
26650@deftypefn {RTM Function} {void} _xabort (status)
26651Abort the current transaction. When no transaction is active this is a no-op.
26652The @var{status} is an 8-bit constant; its value is encoded in the return
26653value from @code{_xbegin}.
26654@end deftypefn
26655
26656Here is an example showing handling for @code{_XABORT_RETRY}
26657and a fallback path for other failures:
26658
26659@smallexample
26660#include <immintrin.h>
26661
26662int n_tries, max_tries;
26663unsigned status = _XABORT_EXPLICIT;
26664...
26665
26666for (n_tries = 0; n_tries < max_tries; n_tries++)
26667 @{
26668 status = _xbegin ();
26669 if (status == _XBEGIN_STARTED || !(status & _XABORT_RETRY))
26670 break;
26671 @}
26672if (status == _XBEGIN_STARTED)
26673 @{
26674 ... transaction code...
26675 _xend ();
26676 @}
26677else
26678 @{
26679 ... non-transactional fallback path...
26680 @}
26681@end smallexample
26682
26683@noindent
26684Note that, in most cases, the transactional and non-transactional code
26685must synchronize together to ensure consistency.
26686
26687@node x86 control-flow protection intrinsics
26688@subsection x86 Control-Flow Protection Intrinsics
26689
26690@deftypefn {CET Function} {ret_type} _get_ssp (void)
26691Get the current value of shadow stack pointer if shadow stack support
26692from Intel CET is enabled in the hardware or @code{0} otherwise.
26693The @code{ret_type} is @code{unsigned long long} for 64-bit targets
26694and @code{unsigned int} for 32-bit targets.
26695@end deftypefn
26696
26697@deftypefn {CET Function} void _inc_ssp (unsigned int)
26698Increment the current shadow stack pointer by the size specified by the
26699function argument. The argument is masked to a byte value for security
26700reasons, so to increment by more than 255 bytes you must call the function
26701multiple times.
26702@end deftypefn
26703
26704The shadow stack unwind code looks like:
26705
26706@smallexample
26707#include <immintrin.h>
26708
26709/* Unwind the shadow stack for EH. */
26710#define _Unwind_Frames_Extra(x) \
26711 do \
26712 @{ \
26713 _Unwind_Word ssp = _get_ssp (); \
26714 if (ssp != 0) \
26715 @{ \
26716 _Unwind_Word tmp = (x); \
26717 while (tmp > 255) \
26718 @{ \
26719 _inc_ssp (tmp); \
26720 tmp -= 255; \
26721 @} \
26722 _inc_ssp (tmp); \
26723 @} \
26724 @} \
26725 while (0)
26726@end smallexample
26727
26728@noindent
26729This code runs unconditionally on all 64-bit processors. For 32-bit
26730processors the code runs on those that support multi-byte NOP instructions.
26731
26732@node Target Format Checks
26733@section Format Checks Specific to Particular Target Machines
26734
26735For some target machines, GCC supports additional options to the
26736format attribute
26737(@pxref{Function Attributes,,Declaring Attributes of Functions}).
26738
26739@menu
26740* Solaris Format Checks::
26741* Darwin Format Checks::
26742@end menu
26743
26744@node Solaris Format Checks
26745@subsection Solaris Format Checks
26746
26747Solaris targets support the @code{cmn_err} (or @code{__cmn_err__}) format
26748check. @code{cmn_err} accepts a subset of the standard @code{printf}
26749conversions, and the two-argument @code{%b} conversion for displaying
26750bit-fields. See the Solaris man page for @code{cmn_err} for more information.
26751
26752@node Darwin Format Checks
26753@subsection Darwin Format Checks
26754
26755In addition to the full set of format archetypes (attribute format style
26756arguments such as @code{printf}, @code{scanf}, @code{strftime}, and
26757@code{strfmon}), Darwin targets also support the @code{CFString} (or
26758@code{__CFString__}) archetype in the @code{format} attribute.
26759Declarations with this archetype are parsed for correct syntax
26760and argument types. However, parsing of the format string itself and
26761validating arguments against it in calls to such functions is currently
26762not performed.
26763
26764Additionally, @code{CFStringRefs} (defined by the @code{CoreFoundation} headers) may
26765also be used as format arguments. Note that the relevant headers are only likely to be
26766available on Darwin (OSX) installations. On such installations, the XCode and system
26767documentation provide descriptions of @code{CFString}, @code{CFStringRefs} and
26768associated functions.
26769
26770@node Pragmas
26771@section Pragmas Accepted by GCC
26772@cindex pragmas
26773@cindex @code{#pragma}
26774
26775GCC supports several types of pragmas, primarily in order to compile
26776code originally written for other compilers. Note that in general
26777we do not recommend the use of pragmas; @xref{Function Attributes},
26778for further explanation.
26779
26780The GNU C preprocessor recognizes several pragmas in addition to the
26781compiler pragmas documented here. Refer to the CPP manual for more
26782information.
26783
26784@menu
26785* AArch64 Pragmas::
26786* ARM Pragmas::
26787* M32C Pragmas::
d77de738
ML
26788* PRU Pragmas::
26789* RS/6000 and PowerPC Pragmas::
26790* S/390 Pragmas::
26791* Darwin Pragmas::
26792* Solaris Pragmas::
26793* Symbol-Renaming Pragmas::
26794* Structure-Layout Pragmas::
26795* Weak Pragmas::
26796* Diagnostic Pragmas::
26797* Visibility Pragmas::
26798* Push/Pop Macro Pragmas::
26799* Function Specific Option Pragmas::
26800* Loop-Specific Pragmas::
26801@end menu
26802
26803@node AArch64 Pragmas
26804@subsection AArch64 Pragmas
26805
26806The pragmas defined by the AArch64 target correspond to the AArch64
26807target function attributes. They can be specified as below:
26808@smallexample
26809#pragma GCC target("string")
26810@end smallexample
26811
26812where @code{@var{string}} can be any string accepted as an AArch64 target
26813attribute. @xref{AArch64 Function Attributes}, for more details
26814on the permissible values of @code{string}.
26815
26816@node ARM Pragmas
26817@subsection ARM Pragmas
26818
26819The ARM target defines pragmas for controlling the default addition of
26820@code{long_call} and @code{short_call} attributes to functions.
26821@xref{Function Attributes}, for information about the effects of these
26822attributes.
26823
26824@table @code
d77de738 26825@cindex pragma, long_calls
f25efe50 26826@item long_calls
d77de738
ML
26827Set all subsequent functions to have the @code{long_call} attribute.
26828
d77de738 26829@cindex pragma, no_long_calls
f25efe50 26830@item no_long_calls
d77de738
ML
26831Set all subsequent functions to have the @code{short_call} attribute.
26832
d77de738 26833@cindex pragma, long_calls_off
f25efe50 26834@item long_calls_off
d77de738
ML
26835Do not affect the @code{long_call} or @code{short_call} attributes of
26836subsequent functions.
26837@end table
26838
26839@node M32C Pragmas
26840@subsection M32C Pragmas
26841
26842@table @code
d77de738 26843@cindex pragma, memregs
f25efe50 26844@item GCC memregs @var{number}
d77de738
ML
26845Overrides the command-line option @code{-memregs=} for the current
26846file. Use with care! This pragma must be before any function in the
26847file, and mixing different memregs values in different objects may
26848make them incompatible. This pragma is useful when a
26849performance-critical function uses a memreg for temporary values,
26850as it may allow you to reduce the number of memregs used.
26851
d77de738 26852@cindex pragma, address
f25efe50 26853@item ADDRESS @var{name} @var{address}
d77de738
ML
26854For any declared symbols matching @var{name}, this does three things
26855to that symbol: it forces the symbol to be located at the given
26856address (a number), it forces the symbol to be volatile, and it
26857changes the symbol's scope to be static. This pragma exists for
26858compatibility with other compilers, but note that the common
26859@code{1234H} numeric syntax is not supported (use @code{0x1234}
26860instead). Example:
26861
26862@smallexample
26863#pragma ADDRESS port3 0x103
26864char port3;
26865@end smallexample
26866
26867@end table
26868
d77de738
ML
26869@node PRU Pragmas
26870@subsection PRU Pragmas
26871
26872@table @code
26873
d77de738 26874@cindex pragma, ctable_entry
f25efe50 26875@item ctable_entry @var{index} @var{constant_address}
d77de738
ML
26876Specifies that the PRU CTABLE entry given by @var{index} has the value
26877@var{constant_address}. This enables GCC to emit LBCO/SBCO instructions
26878when the load/store address is known and can be addressed with some CTABLE
26879entry. For example:
26880
26881@smallexample
26882/* will compile to "sbco Rx, 2, 0x10, 4" */
26883#pragma ctable_entry 2 0x4802a000
26884*(unsigned int *)0x4802a010 = val;
26885@end smallexample
26886
26887@end table
26888
26889@node RS/6000 and PowerPC Pragmas
26890@subsection RS/6000 and PowerPC Pragmas
26891
26892The RS/6000 and PowerPC targets define one pragma for controlling
26893whether or not the @code{longcall} attribute is added to function
26894declarations by default. This pragma overrides the @option{-mlongcall}
26895option, but not the @code{longcall} and @code{shortcall} attributes.
26896@xref{RS/6000 and PowerPC Options}, for more information about when long
26897calls are and are not necessary.
26898
26899@table @code
d77de738 26900@cindex pragma, longcall
f25efe50 26901@item longcall (1)
d77de738
ML
26902Apply the @code{longcall} attribute to all subsequent function
26903declarations.
26904
26905@item longcall (0)
26906Do not apply the @code{longcall} attribute to subsequent function
26907declarations.
26908@end table
26909
26910@c Describe h8300 pragmas here.
26911@c Describe sh pragmas here.
26912@c Describe v850 pragmas here.
26913
26914@node S/390 Pragmas
26915@subsection S/390 Pragmas
26916
26917The pragmas defined by the S/390 target correspond to the S/390
26918target function attributes and some the additional options:
26919
26920@table @samp
26921@item zvector
26922@itemx no-zvector
26923@end table
26924
26925Note that options of the pragma, unlike options of the target
26926attribute, do change the value of preprocessor macros like
26927@code{__VEC__}. They can be specified as below:
26928
26929@smallexample
26930#pragma GCC target("string[,string]...")
26931#pragma GCC target("string"[,"string"]...)
26932@end smallexample
26933
26934@node Darwin Pragmas
26935@subsection Darwin Pragmas
26936
26937The following pragmas are available for all architectures running the
26938Darwin operating system. These are useful for compatibility with other
a335cf24 26939macOS compilers.
d77de738
ML
26940
26941@table @code
d77de738 26942@cindex pragma, mark
f25efe50 26943@item mark @var{tokens}@dots{}
d77de738
ML
26944This pragma is accepted, but has no effect.
26945
d77de738 26946@cindex pragma, options align
f25efe50 26947@item options align=@var{alignment}
d77de738
ML
26948This pragma sets the alignment of fields in structures. The values of
26949@var{alignment} may be @code{mac68k}, to emulate m68k alignment, or
26950@code{power}, to emulate PowerPC alignment. Uses of this pragma nest
26951properly; to restore the previous setting, use @code{reset} for the
26952@var{alignment}.
26953
d77de738 26954@cindex pragma, segment
f25efe50 26955@item segment @var{tokens}@dots{}
d77de738
ML
26956This pragma is accepted, but has no effect.
26957
d77de738 26958@cindex pragma, unused
f25efe50 26959@item unused (@var{var} [, @var{var}]@dots{})
d77de738
ML
26960This pragma declares variables to be possibly unused. GCC does not
26961produce warnings for the listed variables. The effect is similar to
26962that of the @code{unused} attribute, except that this pragma may appear
26963anywhere within the variables' scopes.
26964@end table
26965
26966@node Solaris Pragmas
26967@subsection Solaris Pragmas
26968
26969The Solaris target supports @code{#pragma redefine_extname}
26970(@pxref{Symbol-Renaming Pragmas}). It also supports additional
26971@code{#pragma} directives for compatibility with the system compiler.
26972
26973@table @code
d77de738 26974@cindex pragma, align
f25efe50 26975@item align @var{alignment} (@var{variable} [, @var{variable}]...)
d77de738
ML
26976
26977Increase the minimum alignment of each @var{variable} to @var{alignment}.
26978This is the same as GCC's @code{aligned} attribute @pxref{Variable
26979Attributes}). Macro expansion occurs on the arguments to this pragma
26980when compiling C and Objective-C@. It does not currently occur when
26981compiling C++, but this is a bug which may be fixed in a future
26982release.
26983
d77de738 26984@cindex pragma, fini
f25efe50 26985@item fini (@var{function} [, @var{function}]...)
d77de738
ML
26986
26987This pragma causes each listed @var{function} to be called after
26988main, or during shared module unloading, by adding a call to the
26989@code{.fini} section.
26990
d77de738 26991@cindex pragma, init
f25efe50 26992@item init (@var{function} [, @var{function}]...)
d77de738
ML
26993
26994This pragma causes each listed @var{function} to be called during
26995initialization (before @code{main}) or during shared module loading, by
26996adding a call to the @code{.init} section.
26997
26998@end table
26999
27000@node Symbol-Renaming Pragmas
27001@subsection Symbol-Renaming Pragmas
27002
27003GCC supports a @code{#pragma} directive that changes the name used in
27004assembly for a given declaration. While this pragma is supported on all
27005platforms, it is intended primarily to provide compatibility with the
27006Solaris system headers. This effect can also be achieved using the asm
27007labels extension (@pxref{Asm Labels}).
27008
27009@table @code
d77de738 27010@cindex pragma, redefine_extname
f25efe50 27011@item redefine_extname @var{oldname} @var{newname}
d77de738
ML
27012
27013This pragma gives the C function @var{oldname} the assembly symbol
27014@var{newname}. The preprocessor macro @code{__PRAGMA_REDEFINE_EXTNAME}
27015is defined if this pragma is available (currently on all platforms).
27016@end table
27017
27018This pragma and the @code{asm} labels extension interact in a complicated
27019manner. Here are some corner cases you may want to be aware of:
27020
27021@enumerate
27022@item This pragma silently applies only to declarations with external
27023linkage. The @code{asm} label feature does not have this restriction.
27024
27025@item In C++, this pragma silently applies only to declarations with
27026``C'' linkage. Again, @code{asm} labels do not have this restriction.
27027
27028@item If either of the ways of changing the assembly name of a
27029declaration are applied to a declaration whose assembly name has
27030already been determined (either by a previous use of one of these
27031features, or because the compiler needed the assembly name in order to
27032generate code), and the new name is different, a warning issues and
27033the name does not change.
27034
27035@item The @var{oldname} used by @code{#pragma redefine_extname} is
27036always the C-language name.
27037@end enumerate
27038
27039@node Structure-Layout Pragmas
27040@subsection Structure-Layout Pragmas
27041
27042For compatibility with Microsoft Windows compilers, GCC supports a
27043set of @code{#pragma} directives that change the maximum alignment of
27044members of structures (other than zero-width bit-fields), unions, and
27045classes subsequently defined. The @var{n} value below always is required
27046to be a small power of two and specifies the new alignment in bytes.
27047
27048@enumerate
27049@item @code{#pragma pack(@var{n})} simply sets the new alignment.
27050@item @code{#pragma pack()} sets the alignment to the one that was in
27051effect when compilation started (see also command-line option
27052@option{-fpack-struct[=@var{n}]} @pxref{Code Gen Options}).
27053@item @code{#pragma pack(push[,@var{n}])} pushes the current alignment
27054setting on an internal stack and then optionally sets the new alignment.
27055@item @code{#pragma pack(pop)} restores the alignment setting to the one
27056saved at the top of the internal stack (and removes that stack entry).
27057Note that @code{#pragma pack([@var{n}])} does not influence this internal
27058stack; thus it is possible to have @code{#pragma pack(push)} followed by
27059multiple @code{#pragma pack(@var{n})} instances and finalized by a single
27060@code{#pragma pack(pop)}.
27061@end enumerate
27062
27063Some targets, e.g.@: x86 and PowerPC, support the @code{#pragma ms_struct}
27064directive which lays out structures and unions subsequently defined as the
27065documented @code{__attribute__ ((ms_struct))}.
27066
27067@enumerate
27068@item @code{#pragma ms_struct on} turns on the Microsoft layout.
27069@item @code{#pragma ms_struct off} turns off the Microsoft layout.
27070@item @code{#pragma ms_struct reset} goes back to the default layout.
27071@end enumerate
27072
27073Most targets also support the @code{#pragma scalar_storage_order} directive
27074which lays out structures and unions subsequently defined as the documented
27075@code{__attribute__ ((scalar_storage_order))}.
27076
27077@enumerate
27078@item @code{#pragma scalar_storage_order big-endian} sets the storage order
27079of the scalar fields to big-endian.
27080@item @code{#pragma scalar_storage_order little-endian} sets the storage order
27081of the scalar fields to little-endian.
27082@item @code{#pragma scalar_storage_order default} goes back to the endianness
27083that was in effect when compilation started (see also command-line option
27084@option{-fsso-struct=@var{endianness}} @pxref{C Dialect Options}).
27085@end enumerate
27086
27087@node Weak Pragmas
27088@subsection Weak Pragmas
27089
27090For compatibility with SVR4, GCC supports a set of @code{#pragma}
27091directives for declaring symbols to be weak, and defining weak
27092aliases.
27093
27094@table @code
d77de738 27095@cindex pragma, weak
f33d7a88 27096@item #pragma weak @var{symbol}
d77de738
ML
27097This pragma declares @var{symbol} to be weak, as if the declaration
27098had the attribute of the same name. The pragma may appear before
27099or after the declaration of @var{symbol}. It is not an error for
27100@var{symbol} to never be defined at all.
27101
27102@item #pragma weak @var{symbol1} = @var{symbol2}
27103This pragma declares @var{symbol1} to be a weak alias of @var{symbol2}.
27104It is an error if @var{symbol2} is not defined in the current
27105translation unit.
27106@end table
27107
27108@node Diagnostic Pragmas
27109@subsection Diagnostic Pragmas
27110
27111GCC allows the user to selectively enable or disable certain types of
27112diagnostics, and change the kind of the diagnostic. For example, a
27113project's policy might require that all sources compile with
27114@option{-Werror} but certain files might have exceptions allowing
27115specific types of warnings. Or, a project might selectively enable
27116diagnostics and treat them as errors depending on which preprocessor
27117macros are defined.
27118
27119@table @code
d77de738 27120@cindex pragma, diagnostic
f25efe50 27121@item #pragma GCC diagnostic @var{kind} @var{option}
d77de738
ML
27122
27123Modifies the disposition of a diagnostic. Note that not all
27124diagnostics are modifiable; at the moment only warnings (normally
27125controlled by @samp{-W@dots{}}) can be controlled, and not all of them.
27126Use @option{-fdiagnostics-show-option} to determine which diagnostics
27127are controllable and which option controls them.
27128
27129@var{kind} is @samp{error} to treat this diagnostic as an error,
27130@samp{warning} to treat it like a warning (even if @option{-Werror} is
27131in effect), or @samp{ignored} if the diagnostic is to be ignored.
27132@var{option} is a double quoted string that matches the command-line
27133option.
27134
27135@smallexample
27136#pragma GCC diagnostic warning "-Wformat"
27137#pragma GCC diagnostic error "-Wformat"
27138#pragma GCC diagnostic ignored "-Wformat"
27139@end smallexample
27140
27141Note that these pragmas override any command-line options. GCC keeps
27142track of the location of each pragma, and issues diagnostics according
27143to the state as of that point in the source file. Thus, pragmas occurring
27144after a line do not affect diagnostics caused by that line.
27145
27146@item #pragma GCC diagnostic push
27147@itemx #pragma GCC diagnostic pop
27148
27149Causes GCC to remember the state of the diagnostics as of each
27150@code{push}, and restore to that point at each @code{pop}. If a
27151@code{pop} has no matching @code{push}, the command-line options are
27152restored.
27153
27154@smallexample
27155#pragma GCC diagnostic error "-Wuninitialized"
27156 foo(a); /* error is given for this one */
27157#pragma GCC diagnostic push
27158#pragma GCC diagnostic ignored "-Wuninitialized"
27159 foo(b); /* no diagnostic for this one */
27160#pragma GCC diagnostic pop
27161 foo(c); /* error is given for this one */
27162#pragma GCC diagnostic pop
27163 foo(d); /* depends on command-line options */
27164@end smallexample
27165
27166@item #pragma GCC diagnostic ignored_attributes
27167
27168Similarly to @option{-Wno-attributes=}, this pragma allows users to suppress
094a609c 27169warnings about unknown scoped attributes (in C++11 and C23). For example,
d77de738
ML
27170@code{#pragma GCC diagnostic ignored_attributes "vendor::attr"} disables
27171warning about the following declaration:
27172
27173@smallexample
27174[[vendor::attr]] void f();
27175@end smallexample
27176
27177whereas @code{#pragma GCC diagnostic ignored_attributes "vendor::"} prevents
27178warning about both of these declarations:
27179
27180@smallexample
27181[[vendor::safe]] void f();
27182[[vendor::unsafe]] void f2();
27183@end smallexample
27184
27185@end table
27186
27187GCC also offers a simple mechanism for printing messages during
27188compilation.
27189
27190@table @code
d77de738 27191@cindex pragma, diagnostic
f25efe50 27192@item #pragma message @var{string}
d77de738
ML
27193
27194Prints @var{string} as a compiler message on compilation. The message
27195is informational only, and is neither a compilation warning nor an
27196error. Newlines can be included in the string by using the @samp{\n}
27197escape sequence.
27198
27199@smallexample
27200#pragma message "Compiling " __FILE__ "..."
27201@end smallexample
27202
27203@var{string} may be parenthesized, and is printed with location
27204information. For example,
27205
27206@smallexample
27207#define DO_PRAGMA(x) _Pragma (#x)
27208#define TODO(x) DO_PRAGMA(message ("TODO - " #x))
27209
27210TODO(Remember to fix this)
27211@end smallexample
27212
27213@noindent
27214prints @samp{/tmp/file.c:4: note: #pragma message:
27215TODO - Remember to fix this}.
27216
d77de738 27217@cindex pragma, diagnostic
f25efe50 27218@item #pragma GCC error @var{message}
d77de738
ML
27219Generates an error message. This pragma @emph{is} considered to
27220indicate an error in the compilation, and it will be treated as such.
27221
27222Newlines can be included in the string by using the @samp{\n}
27223escape sequence. They will be displayed as newlines even if the
27224@option{-fmessage-length} option is set to zero.
27225
27226The error is only generated if the pragma is present in the code after
27227pre-processing has been completed. It does not matter however if the
27228code containing the pragma is unreachable:
27229
27230@smallexample
27231#if 0
27232#pragma GCC error "this error is not seen"
27233#endif
27234void foo (void)
27235@{
27236 return;
27237#pragma GCC error "this error is seen"
27238@}
27239@end smallexample
27240
d77de738 27241@cindex pragma, diagnostic
f25efe50 27242@item #pragma GCC warning @var{message}
d77de738
ML
27243This is just like @samp{pragma GCC error} except that a warning
27244message is issued instead of an error message. Unless
27245@option{-Werror} is in effect, in which case this pragma will generate
27246an error as well.
27247
27248@end table
27249
27250@node Visibility Pragmas
27251@subsection Visibility Pragmas
27252
27253@table @code
f25efe50 27254@cindex pragma, visibility
d77de738
ML
27255@item #pragma GCC visibility push(@var{visibility})
27256@itemx #pragma GCC visibility pop
d77de738
ML
27257
27258This pragma allows the user to set the visibility for multiple
27259declarations without having to give each a visibility attribute
27260(@pxref{Function Attributes}).
27261
27262In C++, @samp{#pragma GCC visibility} affects only namespace-scope
27263declarations. Class members and template specializations are not
27264affected; if you want to override the visibility for a particular
27265member or instantiation, you must use an attribute.
27266
27267@end table
27268
27269
27270@node Push/Pop Macro Pragmas
27271@subsection Push/Pop Macro Pragmas
27272
27273For compatibility with Microsoft Windows compilers, GCC supports
27274@samp{#pragma push_macro(@var{"macro_name"})}
27275and @samp{#pragma pop_macro(@var{"macro_name"})}.
27276
27277@table @code
d77de738 27278@cindex pragma, push_macro
f25efe50 27279@item #pragma push_macro(@var{"macro_name"})
d77de738
ML
27280This pragma saves the value of the macro named as @var{macro_name} to
27281the top of the stack for this macro.
27282
d77de738 27283@cindex pragma, pop_macro
f25efe50 27284@item #pragma pop_macro(@var{"macro_name"})
d77de738
ML
27285This pragma sets the value of the macro named as @var{macro_name} to
27286the value on top of the stack for this macro. If the stack for
27287@var{macro_name} is empty, the value of the macro remains unchanged.
27288@end table
27289
27290For example:
27291
27292@smallexample
27293#define X 1
27294#pragma push_macro("X")
27295#undef X
27296#define X -1
27297#pragma pop_macro("X")
27298int x [X];
27299@end smallexample
27300
27301@noindent
27302In this example, the definition of X as 1 is saved by @code{#pragma
27303push_macro} and restored by @code{#pragma pop_macro}.
27304
27305@node Function Specific Option Pragmas
27306@subsection Function Specific Option Pragmas
27307
27308@table @code
d77de738 27309@cindex pragma GCC target
f25efe50 27310@item #pragma GCC target (@var{string}, @dots{})
d77de738
ML
27311
27312This pragma allows you to set target-specific options for functions
27313defined later in the source file. One or more strings can be
27314specified. Each function that is defined after this point is treated
27315as if it had been declared with one @code{target(}@var{string}@code{)}
27316attribute for each @var{string} argument. The parentheses around
27317the strings in the pragma are optional. @xref{Function Attributes},
27318for more information about the @code{target} attribute and the attribute
27319syntax.
27320
27321The @code{#pragma GCC target} pragma is presently implemented for
27322x86, ARM, AArch64, PowerPC, S/390, and Nios II targets only.
27323
d77de738 27324@cindex pragma GCC optimize
f25efe50 27325@item #pragma GCC optimize (@var{string}, @dots{})
d77de738
ML
27326
27327This pragma allows you to set global optimization options for functions
27328defined later in the source file. One or more strings can be
27329specified. Each function that is defined after this point is treated
27330as if it had been declared with one @code{optimize(}@var{string}@code{)}
27331attribute for each @var{string} argument. The parentheses around
27332the strings in the pragma are optional. @xref{Function Attributes},
27333for more information about the @code{optimize} attribute and the attribute
27334syntax.
27335
d77de738
ML
27336@cindex pragma GCC push_options
27337@cindex pragma GCC pop_options
f25efe50
AA
27338@item #pragma GCC push_options
27339@itemx #pragma GCC pop_options
d77de738
ML
27340
27341These pragmas maintain a stack of the current target and optimization
27342options. It is intended for include files where you temporarily want
27343to switch to using a different @samp{#pragma GCC target} or
27344@samp{#pragma GCC optimize} and then to pop back to the previous
27345options.
27346
d77de738 27347@cindex pragma GCC reset_options
f25efe50 27348@item #pragma GCC reset_options
d77de738
ML
27349
27350This pragma clears the current @code{#pragma GCC target} and
27351@code{#pragma GCC optimize} to use the default switches as specified
27352on the command line.
27353
27354@end table
27355
27356@node Loop-Specific Pragmas
27357@subsection Loop-Specific Pragmas
27358
27359@table @code
d77de738 27360@cindex pragma GCC ivdep
f25efe50 27361@item #pragma GCC ivdep
d77de738
ML
27362
27363With this pragma, the programmer asserts that there are no loop-carried
27364dependencies which would prevent consecutive iterations of
27365the following loop from executing concurrently with SIMD
27366(single instruction multiple data) instructions.
27367
27368For example, the compiler can only unconditionally vectorize the following
27369loop with the pragma:
27370
27371@smallexample
27372void foo (int n, int *a, int *b, int *c)
27373@{
27374 int i, j;
27375#pragma GCC ivdep
27376 for (i = 0; i < n; ++i)
27377 a[i] = b[i] + c[i];
27378@}
27379@end smallexample
27380
27381@noindent
27382In this example, using the @code{restrict} qualifier had the same
27383effect. In the following example, that would not be possible. Assume
27384@math{k < -m} or @math{k >= m}. Only with the pragma, the compiler knows
27385that it can unconditionally vectorize the following loop:
27386
27387@smallexample
27388void ignore_vec_dep (int *a, int k, int c, int m)
27389@{
27390#pragma GCC ivdep
27391 for (int i = 0; i < m; i++)
27392 a[i] = a[i + k] * c;
27393@}
27394@end smallexample
27395
73b98860
TC
27396@cindex pragma GCC novector
27397@item #pragma GCC novector
27398
27399With this pragma, the programmer asserts that the following loop should be
27400prevented from executing concurrently with SIMD (single instruction multiple
27401data) instructions.
27402
27403For example, the compiler cannot vectorize the following loop with the pragma:
27404
27405@smallexample
27406void foo (int n, int *a, int *b, int *c)
27407@{
27408 int i, j;
27409#pragma GCC novector
27410 for (i = 0; i < n; ++i)
27411 a[i] = b[i] + c[i];
27412@}
27413@end smallexample
27414
d77de738 27415@cindex pragma GCC unroll @var{n}
f25efe50 27416@item #pragma GCC unroll @var{n}
d77de738
ML
27417
27418You can use this pragma to control how many times a loop should be unrolled.
27419It must be placed immediately before a @code{for}, @code{while} or @code{do}
27420loop or a @code{#pragma GCC ivdep}, and applies only to the loop that follows.
27421@var{n} is an integer constant expression specifying the unrolling factor.
27422The values of @math{0} and @math{1} block any unrolling of the loop.
27423
27424@end table
27425
27426@node Unnamed Fields
27427@section Unnamed Structure and Union Fields
27428@cindex @code{struct}
27429@cindex @code{union}
27430
27431As permitted by ISO C11 and for compatibility with other compilers,
27432GCC allows you to define
27433a structure or union that contains, as fields, structures and unions
27434without names. For example:
27435
27436@smallexample
27437struct @{
27438 int a;
27439 union @{
27440 int b;
27441 float c;
27442 @};
27443 int d;
27444@} foo;
27445@end smallexample
27446
27447@noindent
27448In this example, you are able to access members of the unnamed
27449union with code like @samp{foo.b}. Note that only unnamed structs and
27450unions are allowed, you may not have, for example, an unnamed
27451@code{int}.
27452
27453You must never create such structures that cause ambiguous field definitions.
27454For example, in this structure:
27455
27456@smallexample
27457struct @{
27458 int a;
27459 struct @{
27460 int a;
27461 @};
27462@} foo;
27463@end smallexample
27464
27465@noindent
27466it is ambiguous which @code{a} is being referred to with @samp{foo.a}.
27467The compiler gives errors for such constructs.
27468
27469@opindex fms-extensions
27470Unless @option{-fms-extensions} is used, the unnamed field must be a
27471structure or union definition without a tag (for example, @samp{struct
27472@{ int a; @};}). If @option{-fms-extensions} is used, the field may
27473also be a definition with a tag such as @samp{struct foo @{ int a;
27474@};}, a reference to a previously defined structure or union such as
27475@samp{struct foo;}, or a reference to a @code{typedef} name for a
27476previously defined structure or union type.
27477
27478@opindex fplan9-extensions
27479The option @option{-fplan9-extensions} enables
27480@option{-fms-extensions} as well as two other extensions. First, a
27481pointer to a structure is automatically converted to a pointer to an
27482anonymous field for assignments and function calls. For example:
27483
27484@smallexample
27485struct s1 @{ int a; @};
27486struct s2 @{ struct s1; @};
27487extern void f1 (struct s1 *);
27488void f2 (struct s2 *p) @{ f1 (p); @}
27489@end smallexample
27490
27491@noindent
27492In the call to @code{f1} inside @code{f2}, the pointer @code{p} is
27493converted into a pointer to the anonymous field.
27494
27495Second, when the type of an anonymous field is a @code{typedef} for a
27496@code{struct} or @code{union}, code may refer to the field using the
27497name of the @code{typedef}.
27498
27499@smallexample
27500typedef struct @{ int a; @} s1;
27501struct s2 @{ s1; @};
27502s1 f1 (struct s2 *p) @{ return p->s1; @}
27503@end smallexample
27504
27505These usages are only permitted when they are not ambiguous.
27506
27507@node Thread-Local
27508@section Thread-Local Storage
27509@cindex Thread-Local Storage
27510@cindex @acronym{TLS}
27511@cindex @code{__thread}
27512
27513Thread-local storage (@acronym{TLS}) is a mechanism by which variables
27514are allocated such that there is one instance of the variable per extant
27515thread. The runtime model GCC uses to implement this originates
27516in the IA-64 processor-specific ABI, but has since been migrated
27517to other processors as well. It requires significant support from
27518the linker (@command{ld}), dynamic linker (@command{ld.so}), and
27519system libraries (@file{libc.so} and @file{libpthread.so}), so it
27520is not available everywhere.
27521
27522At the user level, the extension is visible with a new storage
27523class keyword: @code{__thread}. For example:
27524
27525@smallexample
27526__thread int i;
27527extern __thread struct state s;
27528static __thread char *p;
27529@end smallexample
27530
27531The @code{__thread} specifier may be used alone, with the @code{extern}
27532or @code{static} specifiers, but with no other storage class specifier.
27533When used with @code{extern} or @code{static}, @code{__thread} must appear
27534immediately after the other storage class specifier.
27535
27536The @code{__thread} specifier may be applied to any global, file-scoped
27537static, function-scoped static, or static data member of a class. It may
27538not be applied to block-scoped automatic or non-static data member.
27539
27540When the address-of operator is applied to a thread-local variable, it is
27541evaluated at run time and returns the address of the current thread's
27542instance of that variable. An address so obtained may be used by any
27543thread. When a thread terminates, any pointers to thread-local variables
27544in that thread become invalid.
27545
27546No static initialization may refer to the address of a thread-local variable.
27547
27548In C++, if an initializer is present for a thread-local variable, it must
27549be a @var{constant-expression}, as defined in 5.19.2 of the ANSI/ISO C++
27550standard.
27551
27552See @uref{https://www.akkadia.org/drepper/tls.pdf,
27553ELF Handling For Thread-Local Storage} for a detailed explanation of
27554the four thread-local storage addressing models, and how the runtime
27555is expected to function.
27556
27557@menu
27558* C99 Thread-Local Edits::
27559* C++98 Thread-Local Edits::
27560@end menu
27561
27562@node C99 Thread-Local Edits
27563@subsection ISO/IEC 9899:1999 Edits for Thread-Local Storage
27564
27565The following are a set of changes to ISO/IEC 9899:1999 (aka C99)
27566that document the exact semantics of the language extension.
27567
27568@itemize @bullet
27569@item
27570@cite{5.1.2 Execution environments}
27571
27572Add new text after paragraph 1
27573
27574@quotation
27575Within either execution environment, a @dfn{thread} is a flow of
27576control within a program. It is implementation defined whether
27577or not there may be more than one thread associated with a program.
27578It is implementation defined how threads beyond the first are
27579created, the name and type of the function called at thread
27580startup, and how threads may be terminated. However, objects
27581with thread storage duration shall be initialized before thread
27582startup.
27583@end quotation
27584
27585@item
27586@cite{6.2.4 Storage durations of objects}
27587
27588Add new text before paragraph 3
27589
27590@quotation
27591An object whose identifier is declared with the storage-class
27592specifier @w{@code{__thread}} has @dfn{thread storage duration}.
27593Its lifetime is the entire execution of the thread, and its
27594stored value is initialized only once, prior to thread startup.
27595@end quotation
27596
27597@item
27598@cite{6.4.1 Keywords}
27599
27600Add @code{__thread}.
27601
27602@item
27603@cite{6.7.1 Storage-class specifiers}
27604
27605Add @code{__thread} to the list of storage class specifiers in
27606paragraph 1.
27607
27608Change paragraph 2 to
27609
27610@quotation
27611With the exception of @code{__thread}, at most one storage-class
27612specifier may be given [@dots{}]. The @code{__thread} specifier may
27613be used alone, or immediately following @code{extern} or
27614@code{static}.
27615@end quotation
27616
27617Add new text after paragraph 6
27618
27619@quotation
27620The declaration of an identifier for a variable that has
27621block scope that specifies @code{__thread} shall also
27622specify either @code{extern} or @code{static}.
27623
27624The @code{__thread} specifier shall be used only with
27625variables.
27626@end quotation
27627@end itemize
27628
27629@node C++98 Thread-Local Edits
27630@subsection ISO/IEC 14882:1998 Edits for Thread-Local Storage
27631
27632The following are a set of changes to ISO/IEC 14882:1998 (aka C++98)
27633that document the exact semantics of the language extension.
27634
27635@itemize @bullet
27636@item
27637@b{[intro.execution]}
27638
27639New text after paragraph 4
27640
27641@quotation
27642A @dfn{thread} is a flow of control within the abstract machine.
27643It is implementation defined whether or not there may be more than
27644one thread.
27645@end quotation
27646
27647New text after paragraph 7
27648
27649@quotation
27650It is unspecified whether additional action must be taken to
27651ensure when and whether side effects are visible to other threads.
27652@end quotation
27653
27654@item
27655@b{[lex.key]}
27656
27657Add @code{__thread}.
27658
27659@item
27660@b{[basic.start.main]}
27661
27662Add after paragraph 5
27663
27664@quotation
27665The thread that begins execution at the @code{main} function is called
27666the @dfn{main thread}. It is implementation defined how functions
27667beginning threads other than the main thread are designated or typed.
27668A function so designated, as well as the @code{main} function, is called
27669a @dfn{thread startup function}. It is implementation defined what
27670happens if a thread startup function returns. It is implementation
27671defined what happens to other threads when any thread calls @code{exit}.
27672@end quotation
27673
27674@item
27675@b{[basic.start.init]}
27676
27677Add after paragraph 4
27678
27679@quotation
27680The storage for an object of thread storage duration shall be
27681statically initialized before the first statement of the thread startup
27682function. An object of thread storage duration shall not require
27683dynamic initialization.
27684@end quotation
27685
27686@item
27687@b{[basic.start.term]}
27688
27689Add after paragraph 3
27690
27691@quotation
27692The type of an object with thread storage duration shall not have a
27693non-trivial destructor, nor shall it be an array type whose elements
27694(directly or indirectly) have non-trivial destructors.
27695@end quotation
27696
27697@item
27698@b{[basic.stc]}
27699
27700Add ``thread storage duration'' to the list in paragraph 1.
27701
27702Change paragraph 2
27703
27704@quotation
27705Thread, static, and automatic storage durations are associated with
27706objects introduced by declarations [@dots{}].
27707@end quotation
27708
27709Add @code{__thread} to the list of specifiers in paragraph 3.
27710
27711@item
27712@b{[basic.stc.thread]}
27713
27714New section before @b{[basic.stc.static]}
27715
27716@quotation
27717The keyword @code{__thread} applied to a non-local object gives the
27718object thread storage duration.
27719
27720A local variable or class data member declared both @code{static}
27721and @code{__thread} gives the variable or member thread storage
27722duration.
27723@end quotation
27724
27725@item
27726@b{[basic.stc.static]}
27727
27728Change paragraph 1
27729
27730@quotation
27731All objects that have neither thread storage duration, dynamic
27732storage duration nor are local [@dots{}].
27733@end quotation
27734
27735@item
27736@b{[dcl.stc]}
27737
27738Add @code{__thread} to the list in paragraph 1.
27739
27740Change paragraph 1
27741
27742@quotation
27743With the exception of @code{__thread}, at most one
27744@var{storage-class-specifier} shall appear in a given
27745@var{decl-specifier-seq}. The @code{__thread} specifier may
27746be used alone, or immediately following the @code{extern} or
27747@code{static} specifiers. [@dots{}]
27748@end quotation
27749
27750Add after paragraph 5
27751
27752@quotation
27753The @code{__thread} specifier can be applied only to the names of objects
27754and to anonymous unions.
27755@end quotation
27756
27757@item
27758@b{[class.mem]}
27759
27760Add after paragraph 6
27761
27762@quotation
27763Non-@code{static} members shall not be @code{__thread}.
27764@end quotation
27765@end itemize
27766
27767@node Binary constants
27768@section Binary Constants using the @samp{0b} Prefix
27769@cindex Binary constants using the @samp{0b} prefix
27770
27771Integer constants can be written as binary constants, consisting of a
27772sequence of @samp{0} and @samp{1} digits, prefixed by @samp{0b} or
27773@samp{0B}. This is particularly useful in environments that operate a
27774lot on the bit level (like microcontrollers).
27775
27776The following statements are identical:
27777
27778@smallexample
27779i = 42;
27780i = 0x2a;
27781i = 052;
27782i = 0b101010;
27783@end smallexample
27784
27785The type of these constants follows the same rules as for octal or
27786hexadecimal integer constants, so suffixes like @samp{L} or @samp{UL}
27787can be applied.
27788
27789@node C++ Extensions
27790@chapter Extensions to the C++ Language
27791@cindex extensions, C++ language
27792@cindex C++ language extensions
27793
27794The GNU compiler provides these extensions to the C++ language (and you
27795can also use most of the C language extensions in your C++ programs). If you
27796want to write code that checks whether these features are available, you can
27797test for the GNU compiler the same way as for C programs: check for a
27798predefined macro @code{__GNUC__}. You can also use @code{__GNUG__} to
27799test specifically for GNU C++ (@pxref{Common Predefined Macros,,
27800Predefined Macros,cpp,The GNU C Preprocessor}).
27801
27802@menu
27803* C++ Volatiles:: What constitutes an access to a volatile object.
27804* Restricted Pointers:: C99 restricted pointers and references.
27805* Vague Linkage:: Where G++ puts inlines, vtables and such.
27806* C++ Interface:: You can use a single C++ header file for both
27807 declarations and definitions.
27808* Template Instantiation:: Methods for ensuring that exactly one copy of
27809 each needed template instantiation is emitted.
27810* Bound member functions:: You can extract a function pointer to the
27811 method denoted by a @samp{->*} or @samp{.*} expression.
27812* C++ Attributes:: Variable, function, and type attributes for C++ only.
27813* Function Multiversioning:: Declaring multiple function versions.
27814* Type Traits:: Compiler support for type traits.
27815* C++ Concepts:: Improved support for generic programming.
27816* Deprecated Features:: Things will disappear from G++.
27817* Backwards Compatibility:: Compatibilities with earlier definitions of C++.
27818@end menu
27819
27820@node C++ Volatiles
27821@section When is a Volatile C++ Object Accessed?
27822@cindex accessing volatiles
27823@cindex volatile read
27824@cindex volatile write
27825@cindex volatile access
27826
27827The C++ standard differs from the C standard in its treatment of
27828volatile objects. It fails to specify what constitutes a volatile
27829access, except to say that C++ should behave in a similar manner to C
27830with respect to volatiles, where possible. However, the different
27831lvalueness of expressions between C and C++ complicate the behavior.
27832G++ behaves the same as GCC for volatile access, @xref{C
27833Extensions,,Volatiles}, for a description of GCC's behavior.
27834
27835The C and C++ language specifications differ when an object is
27836accessed in a void context:
27837
27838@smallexample
27839volatile int *src = @var{somevalue};
27840*src;
27841@end smallexample
27842
27843The C++ standard specifies that such expressions do not undergo lvalue
27844to rvalue conversion, and that the type of the dereferenced object may
27845be incomplete. The C++ standard does not specify explicitly that it
27846is lvalue to rvalue conversion that is responsible for causing an
27847access. There is reason to believe that it is, because otherwise
27848certain simple expressions become undefined. However, because it
27849would surprise most programmers, G++ treats dereferencing a pointer to
27850volatile object of complete type as GCC would do for an equivalent
27851type in C@. When the object has incomplete type, G++ issues a
27852warning; if you wish to force an error, you must force a conversion to
27853rvalue with, for instance, a static cast.
27854
27855When using a reference to volatile, G++ does not treat equivalent
27856expressions as accesses to volatiles, but instead issues a warning that
27857no volatile is accessed. The rationale for this is that otherwise it
27858becomes difficult to determine where volatile access occur, and not
27859possible to ignore the return value from functions returning volatile
27860references. Again, if you wish to force a read, cast the reference to
27861an rvalue.
27862
27863G++ implements the same behavior as GCC does when assigning to a
27864volatile object---there is no reread of the assigned-to object, the
27865assigned rvalue is reused. Note that in C++ assignment expressions
27866are lvalues, and if used as an lvalue, the volatile object is
27867referred to. For instance, @var{vref} refers to @var{vobj}, as
27868expected, in the following example:
27869
27870@smallexample
27871volatile int vobj;
27872volatile int &vref = vobj = @var{something};
27873@end smallexample
27874
27875@node Restricted Pointers
27876@section Restricting Pointer Aliasing
27877@cindex restricted pointers
27878@cindex restricted references
27879@cindex restricted this pointer
27880
27881As with the C front end, G++ understands the C99 feature of restricted pointers,
27882specified with the @code{__restrict__}, or @code{__restrict} type
27883qualifier. Because you cannot compile C++ by specifying the @option{-std=c99}
27884language flag, @code{restrict} is not a keyword in C++.
27885
27886In addition to allowing restricted pointers, you can specify restricted
27887references, which indicate that the reference is not aliased in the local
27888context.
27889
27890@smallexample
27891void fn (int *__restrict__ rptr, int &__restrict__ rref)
27892@{
27893 /* @r{@dots{}} */
27894@}
27895@end smallexample
27896
27897@noindent
27898In the body of @code{fn}, @var{rptr} points to an unaliased integer and
27899@var{rref} refers to a (different) unaliased integer.
27900
27901You may also specify whether a member function's @var{this} pointer is
27902unaliased by using @code{__restrict__} as a member function qualifier.
27903
27904@smallexample
27905void T::fn () __restrict__
27906@{
27907 /* @r{@dots{}} */
27908@}
27909@end smallexample
27910
27911@noindent
27912Within the body of @code{T::fn}, @var{this} has the effective
27913definition @code{T *__restrict__ const this}. Notice that the
27914interpretation of a @code{__restrict__} member function qualifier is
27915different to that of @code{const} or @code{volatile} qualifier, in that it
27916is applied to the pointer rather than the object. This is consistent with
27917other compilers that implement restricted pointers.
27918
27919As with all outermost parameter qualifiers, @code{__restrict__} is
27920ignored in function definition matching. This means you only need to
27921specify @code{__restrict__} in a function definition, rather than
27922in a function prototype as well.
27923
27924@node Vague Linkage
27925@section Vague Linkage
27926@cindex vague linkage
27927
27928There are several constructs in C++ that require space in the object
27929file but are not clearly tied to a single translation unit. We say that
27930these constructs have ``vague linkage''. Typically such constructs are
27931emitted wherever they are needed, though sometimes we can be more
27932clever.
27933
27934@table @asis
27935@item Inline Functions
27936Inline functions are typically defined in a header file which can be
27937included in many different compilations. Hopefully they can usually be
27938inlined, but sometimes an out-of-line copy is necessary, if the address
27939of the function is taken or if inlining fails. In general, we emit an
27940out-of-line copy in all translation units where one is needed. As an
27941exception, we only emit inline virtual functions with the vtable, since
27942it always requires a copy.
27943
27944Local static variables and string constants used in an inline function
27945are also considered to have vague linkage, since they must be shared
27946between all inlined and out-of-line instances of the function.
27947
d77de738 27948@cindex vtable
f25efe50 27949@item VTables
d77de738
ML
27950C++ virtual functions are implemented in most compilers using a lookup
27951table, known as a vtable. The vtable contains pointers to the virtual
27952functions provided by a class, and each object of the class contains a
27953pointer to its vtable (or vtables, in some multiple-inheritance
27954situations). If the class declares any non-inline, non-pure virtual
27955functions, the first one is chosen as the ``key method'' for the class,
27956and the vtable is only emitted in the translation unit where the key
27957method is defined.
27958
27959@emph{Note:} If the chosen key method is later defined as inline, the
27960vtable is still emitted in every translation unit that defines it.
27961Make sure that any inline virtuals are declared inline in the class
27962body, even if they are not defined there.
27963
d77de738
ML
27964@cindex @code{type_info}
27965@cindex RTTI
f25efe50 27966@item @code{type_info} objects
d77de738
ML
27967C++ requires information about types to be written out in order to
27968implement @samp{dynamic_cast}, @samp{typeid} and exception handling.
27969For polymorphic classes (classes with virtual functions), the @samp{type_info}
27970object is written out along with the vtable so that @samp{dynamic_cast}
27971can determine the dynamic type of a class object at run time. For all
27972other types, we write out the @samp{type_info} object when it is used: when
27973applying @samp{typeid} to an expression, throwing an object, or
27974referring to a type in a catch clause or exception specification.
27975
27976@item Template Instantiations
27977Most everything in this section also applies to template instantiations,
27978but there are other options as well.
27979@xref{Template Instantiation,,Where's the Template?}.
27980
27981@end table
27982
27983When used with GNU ld version 2.8 or later on an ELF system such as
27984GNU/Linux or Solaris 2, or on Microsoft Windows, duplicate copies of
27985these constructs will be discarded at link time. This is known as
27986COMDAT support.
27987
27988On targets that don't support COMDAT, but do support weak symbols, GCC
27989uses them. This way one copy overrides all the others, but
27990the unused copies still take up space in the executable.
27991
27992For targets that do not support either COMDAT or weak symbols,
27993most entities with vague linkage are emitted as local symbols to
27994avoid duplicate definition errors from the linker. This does not happen
27995for local statics in inlines, however, as having multiple copies
27996almost certainly breaks things.
27997
27998@xref{C++ Interface,,Declarations and Definitions in One Header}, for
27999another way to control placement of these constructs.
28000
28001@node C++ Interface
28002@section C++ Interface and Implementation Pragmas
28003
28004@cindex interface and implementation headers, C++
28005@cindex C++ interface and implementation headers
28006@cindex pragmas, interface and implementation
28007
28008@code{#pragma interface} and @code{#pragma implementation} provide the
28009user with a way of explicitly directing the compiler to emit entities
28010with vague linkage (and debugging information) in a particular
28011translation unit.
28012
28013@emph{Note:} These @code{#pragma}s have been superceded as of GCC 2.7.2
28014by COMDAT support and the ``key method'' heuristic
28015mentioned in @ref{Vague Linkage}. Using them can actually cause your
28016program to grow due to unnecessary out-of-line copies of inline
28017functions.
28018
28019@table @code
f25efe50 28020@kindex #pragma interface
d77de738
ML
28021@item #pragma interface
28022@itemx #pragma interface "@var{subdir}/@var{objects}.h"
d77de738
ML
28023Use this directive in @emph{header files} that define object classes, to save
28024space in most of the object files that use those classes. Normally,
28025local copies of certain information (backup copies of inline member
28026functions, debugging information, and the internal tables that implement
28027virtual functions) must be kept in each object file that includes class
28028definitions. You can use this pragma to avoid such duplication. When a
28029header file containing @samp{#pragma interface} is included in a
28030compilation, this auxiliary information is not generated (unless
28031the main input source file itself uses @samp{#pragma implementation}).
28032Instead, the object files contain references to be resolved at link
28033time.
28034
28035The second form of this directive is useful for the case where you have
28036multiple headers with the same name in different directories. If you
28037use this form, you must specify the same string to @samp{#pragma
28038implementation}.
28039
f25efe50 28040@kindex #pragma implementation
d77de738
ML
28041@item #pragma implementation
28042@itemx #pragma implementation "@var{objects}.h"
d77de738
ML
28043Use this pragma in a @emph{main input file}, when you want full output from
28044included header files to be generated (and made globally visible). The
28045included header file, in turn, should use @samp{#pragma interface}.
28046Backup copies of inline member functions, debugging information, and the
28047internal tables used to implement virtual functions are all generated in
28048implementation files.
28049
28050@cindex implied @code{#pragma implementation}
28051@cindex @code{#pragma implementation}, implied
28052@cindex naming convention, implementation headers
28053If you use @samp{#pragma implementation} with no argument, it applies to
28054an include file with the same basename@footnote{A file's @dfn{basename}
28055is the name stripped of all leading path information and of trailing
28056suffixes, such as @samp{.h} or @samp{.C} or @samp{.cc}.} as your source
28057file. For example, in @file{allclass.cc}, giving just
28058@samp{#pragma implementation}
28059by itself is equivalent to @samp{#pragma implementation "allclass.h"}.
28060
28061Use the string argument if you want a single implementation file to
28062include code from multiple header files. (You must also use
28063@samp{#include} to include the header file; @samp{#pragma
28064implementation} only specifies how to use the file---it doesn't actually
28065include it.)
28066
28067There is no way to split up the contents of a single header file into
28068multiple implementation files.
28069@end table
28070
28071@cindex inlining and C++ pragmas
28072@cindex C++ pragmas, effect on inlining
28073@cindex pragmas in C++, effect on inlining
28074@samp{#pragma implementation} and @samp{#pragma interface} also have an
28075effect on function inlining.
28076
28077If you define a class in a header file marked with @samp{#pragma
28078interface}, the effect on an inline function defined in that class is
28079similar to an explicit @code{extern} declaration---the compiler emits
28080no code at all to define an independent version of the function. Its
28081definition is used only for inlining with its callers.
28082
28083@opindex fno-implement-inlines
28084Conversely, when you include the same header file in a main source file
28085that declares it as @samp{#pragma implementation}, the compiler emits
28086code for the function itself; this defines a version of the function
28087that can be found via pointers (or by callers compiled without
28088inlining). If all calls to the function can be inlined, you can avoid
28089emitting the function by compiling with @option{-fno-implement-inlines}.
28090If any calls are not inlined, you will get linker errors.
28091
28092@node Template Instantiation
28093@section Where's the Template?
28094@cindex template instantiation
28095
28096C++ templates were the first language feature to require more
28097intelligence from the environment than was traditionally found on a UNIX
28098system. Somehow the compiler and linker have to make sure that each
28099template instance occurs exactly once in the executable if it is needed,
28100and not at all otherwise. There are two basic approaches to this
28101problem, which are referred to as the Borland model and the Cfront model.
28102
28103@table @asis
28104@item Borland model
28105Borland C++ solved the template instantiation problem by adding the code
28106equivalent of common blocks to their linker; the compiler emits template
28107instances in each translation unit that uses them, and the linker
28108collapses them together. The advantage of this model is that the linker
28109only has to consider the object files themselves; there is no external
28110complexity to worry about. The disadvantage is that compilation time
28111is increased because the template code is being compiled repeatedly.
28112Code written for this model tends to include definitions of all
28113templates in the header file, since they must be seen to be
28114instantiated.
28115
28116@item Cfront model
28117The AT&T C++ translator, Cfront, solved the template instantiation
28118problem by creating the notion of a template repository, an
28119automatically maintained place where template instances are stored. A
28120more modern version of the repository works as follows: As individual
28121object files are built, the compiler places any template definitions and
28122instantiations encountered in the repository. At link time, the link
28123wrapper adds in the objects in the repository and compiles any needed
28124instances that were not previously emitted. The advantages of this
28125model are more optimal compilation speed and the ability to use the
28126system linker; to implement the Borland model a compiler vendor also
28127needs to replace the linker. The disadvantages are vastly increased
28128complexity, and thus potential for error; for some code this can be
28129just as transparent, but in practice it can been very difficult to build
28130multiple programs in one directory and one program in multiple
28131directories. Code written for this model tends to separate definitions
28132of non-inline member templates into a separate file, which should be
28133compiled separately.
28134@end table
28135
28136G++ implements the Borland model on targets where the linker supports it,
a335cf24 28137including ELF targets (such as GNU/Linux), macOS and Microsoft Windows.
d77de738
ML
28138Otherwise G++ implements neither automatic model.
28139
28140You have the following options for dealing with template instantiations:
28141
28142@enumerate
28143@item
28144Do nothing. Code written for the Borland model works fine, but
28145each translation unit contains instances of each of the templates it
28146uses. The duplicate instances will be discarded by the linker, but in
28147a large program, this can lead to an unacceptable amount of code
28148duplication in object files or shared libraries.
28149
28150Duplicate instances of a template can be avoided by defining an explicit
28151instantiation in one object file, and preventing the compiler from doing
28152implicit instantiations in any other object files by using an explicit
28153instantiation declaration, using the @code{extern template} syntax:
28154
28155@smallexample
28156extern template int max (int, int);
28157@end smallexample
28158
28159This syntax is defined in the C++ 2011 standard, but has been supported by
28160G++ and other compilers since well before 2011.
28161
28162Explicit instantiations can be used for the largest or most frequently
28163duplicated instances, without having to know exactly which other instances
28164are used in the rest of the program. You can scatter the explicit
28165instantiations throughout your program, perhaps putting them in the
28166translation units where the instances are used or the translation units
28167that define the templates themselves; you can put all of the explicit
28168instantiations you need into one big file; or you can create small files
28169like
28170
28171@smallexample
28172#include "Foo.h"
28173#include "Foo.cc"
28174
28175template class Foo<int>;
28176template ostream& operator <<
28177 (ostream&, const Foo<int>&);
28178@end smallexample
28179
28180@noindent
28181for each of the instances you need, and create a template instantiation
28182library from those.
28183
28184This is the simplest option, but also offers flexibility and
28185fine-grained control when necessary. It is also the most portable
28186alternative and programs using this approach will work with most modern
28187compilers.
28188
d77de738 28189@opindex fno-implicit-templates
e54b01a1 28190@item
d77de738
ML
28191Compile your code with @option{-fno-implicit-templates} to disable the
28192implicit generation of template instances, and explicitly instantiate
28193all the ones you use. This approach requires more knowledge of exactly
28194which instances you need than do the others, but it's less
28195mysterious and allows greater control if you want to ensure that only
28196the intended instances are used.
28197
28198If you are using Cfront-model code, you can probably get away with not
28199using @option{-fno-implicit-templates} when compiling files that don't
28200@samp{#include} the member template definitions.
28201
28202If you use one big file to do the instantiations, you may want to
28203compile it without @option{-fno-implicit-templates} so you get all of the
28204instances required by your explicit instantiations (but not by any
28205other files) without having to specify them as well.
28206
28207In addition to forward declaration of explicit instantiations
28208(with @code{extern}), G++ has extended the template instantiation
28209syntax to support instantiation of the compiler support data for a
28210template class (i.e.@: the vtable) without instantiating any of its
28211members (with @code{inline}), and instantiation of only the static data
28212members of a template class, without the support data or member
28213functions (with @code{static}):
28214
28215@smallexample
28216inline template class Foo<int>;
28217static template class Foo<int>;
28218@end smallexample
28219@end enumerate
28220
28221@node Bound member functions
28222@section Extracting the Function Pointer from a Bound Pointer to Member Function
28223@cindex pmf
28224@cindex pointer to member function
28225@cindex bound pointer to member function
28226
28227In C++, pointer to member functions (PMFs) are implemented using a wide
28228pointer of sorts to handle all the possible call mechanisms; the PMF
28229needs to store information about how to adjust the @samp{this} pointer,
28230and if the function pointed to is virtual, where to find the vtable, and
28231where in the vtable to look for the member function. If you are using
28232PMFs in an inner loop, you should really reconsider that decision. If
28233that is not an option, you can extract the pointer to the function that
28234would be called for a given object/PMF pair and call it directly inside
28235the inner loop, to save a bit of time.
28236
28237Note that you still pay the penalty for the call through a
28238function pointer; on most modern architectures, such a call defeats the
28239branch prediction features of the CPU@. This is also true of normal
28240virtual function calls.
28241
28242The syntax for this extension is
28243
28244@smallexample
28245extern A a;
28246extern int (A::*fp)();
28247typedef int (*fptr)(A *);
28248
28249fptr p = (fptr)(a.*fp);
28250@end smallexample
28251
28252For PMF constants (i.e.@: expressions of the form @samp{&Klasse::Member}),
28253no object is needed to obtain the address of the function. They can be
28254converted to function pointers directly:
28255
28256@smallexample
28257fptr p1 = (fptr)(&A::foo);
28258@end smallexample
28259
28260@opindex Wno-pmf-conversions
28261You must specify @option{-Wno-pmf-conversions} to use this extension.
28262
28263@node C++ Attributes
28264@section C++-Specific Variable, Function, and Type Attributes
28265
28266Some attributes only make sense for C++ programs.
28267
28268@table @code
d77de738
ML
28269@cindex @code{abi_tag} function attribute
28270@cindex @code{abi_tag} variable attribute
28271@cindex @code{abi_tag} type attribute
f25efe50 28272@item abi_tag ("@var{tag}", ...)
d77de738
ML
28273The @code{abi_tag} attribute can be applied to a function, variable, or class
28274declaration. It modifies the mangled name of the entity to
28275incorporate the tag name, in order to distinguish the function or
28276class from an earlier version with a different ABI; perhaps the class
28277has changed size, or the function has a different return type that is
28278not encoded in the mangled name.
28279
28280The attribute can also be applied to an inline namespace, but does not
28281affect the mangled name of the namespace; in this case it is only used
28282for @option{-Wabi-tag} warnings and automatic tagging of functions and
28283variables. Tagging inline namespaces is generally preferable to
28284tagging individual declarations, but the latter is sometimes
28285necessary, such as when only certain members of a class need to be
28286tagged.
28287
28288The argument can be a list of strings of arbitrary length. The
28289strings are sorted on output, so the order of the list is
28290unimportant.
28291
28292A redeclaration of an entity must not add new ABI tags,
28293since doing so would change the mangled name.
28294
28295The ABI tags apply to a name, so all instantiations and
28296specializations of a template have the same tags. The attribute will
28297be ignored if applied to an explicit specialization or instantiation.
28298
28299The @option{-Wabi-tag} flag enables a warning about a class which does
28300not have all the ABI tags used by its subobjects and virtual functions; for users with code
28301that needs to coexist with an earlier ABI, using this option can help
28302to find all affected types that need to be tagged.
28303
28304When a type involving an ABI tag is used as the type of a variable or
28305return type of a function where that tag is not already present in the
28306signature of the function, the tag is automatically applied to the
28307variable or function. @option{-Wabi-tag} also warns about this
28308situation; this warning can be avoided by explicitly tagging the
28309variable or function or moving it into a tagged inline namespace.
28310
d77de738 28311@cindex @code{init_priority} variable attribute
f25efe50 28312@item init_priority (@var{priority})
d77de738
ML
28313
28314In Standard C++, objects defined at namespace scope are guaranteed to be
28315initialized in an order in strict accordance with that of their definitions
28316@emph{in a given translation unit}. No guarantee is made for initializations
28317across translation units. However, GNU C++ allows users to control the
28318order of initialization of objects defined at namespace scope with the
28319@code{init_priority} attribute by specifying a relative @var{priority},
28320a constant integral expression currently bounded between 101 and 65535
28321inclusive. Lower numbers indicate a higher priority.
28322
28323In the following example, @code{A} would normally be created before
28324@code{B}, but the @code{init_priority} attribute reverses that order:
28325
28326@smallexample
28327Some_Class A __attribute__ ((init_priority (2000)));
28328Some_Class B __attribute__ ((init_priority (543)));
28329@end smallexample
28330
28331@noindent
28332Note that the particular values of @var{priority} do not matter; only their
28333relative ordering.
28334
d77de738 28335@cindex @code{warn_unused} type attribute
f25efe50 28336@item warn_unused
d77de738
ML
28337
28338For C++ types with non-trivial constructors and/or destructors it is
28339impossible for the compiler to determine whether a variable of this
28340type is truly unused if it is not referenced. This type attribute
28341informs the compiler that variables of this type should be warned
28342about if they appear to be unused, just like variables of fundamental
28343types.
28344
28345This attribute is appropriate for types which just represent a value,
28346such as @code{std::string}; it is not appropriate for types which
28347control a resource, such as @code{std::lock_guard}.
28348
28349This attribute is also accepted in C, but it is unnecessary because C
28350does not have constructors or destructors.
28351
4f52e61e
JM
28352@cindex @code{cold} type attribute
28353@item cold
28354
28355In addition to functions and labels, GNU C++ allows the @code{cold}
28356attribute to be used on C++ classes, structs, or unions. Applying
28357the @code{cold} attribute on a type has the effect of treating every
28358member function of the type, including implicit special member
28359functions, as cold. If a member function is marked with the
28360@code{hot} function attribute, the @code{hot} attribute takes
28361precedence and the @code{cold} attribute is not propagated.
28362
28363For the effects of the @code{cold} attribute on functions, see
28364@ref{Common Function Attributes}.
28365
28366@cindex @code{hot} type attribute
28367@item hot
28368
28369In addition to functions and labels, GNU C++ allows the @code{hot}
28370attribute to be used on C++ classes, structs, or unions. Applying
28371the @code{hot} attribute on a type has the effect of treating every
28372member function of the type, including implicit special member
28373functions, as hot. If a member function is marked with the
28374@code{cold} function attribute, the @code{cold} attribute takes
28375precedence and the @code{hot} attribute is not propagated.
28376
28377For the effects of the @code{hot} attribute on functions, see
28378@ref{Common Function Attributes}.
28379
d77de738
ML
28380@end table
28381
28382@node Function Multiversioning
28383@section Function Multiversioning
28384@cindex function versions
28385
28386With the GNU C++ front end, for x86 targets, you may specify multiple
28387versions of a function, where each function is specialized for a
28388specific target feature. At runtime, the appropriate version of the
28389function is automatically executed depending on the characteristics of
28390the execution platform. Here is an example.
28391
28392@smallexample
28393__attribute__ ((target ("default")))
28394int foo ()
28395@{
28396 // The default version of foo.
28397 return 0;
28398@}
28399
28400__attribute__ ((target ("sse4.2")))
28401int foo ()
28402@{
28403 // foo version for SSE4.2
28404 return 1;
28405@}
28406
28407__attribute__ ((target ("arch=atom")))
28408int foo ()
28409@{
28410 // foo version for the Intel ATOM processor
28411 return 2;
28412@}
28413
28414__attribute__ ((target ("arch=amdfam10")))
28415int foo ()
28416@{
28417 // foo version for the AMD Family 0x10 processors.
28418 return 3;
28419@}
28420
28421int main ()
28422@{
28423 int (*p)() = &foo;
28424 assert ((*p) () == foo ());
28425 return 0;
28426@}
28427@end smallexample
28428
28429In the above example, four versions of function foo are created. The
28430first version of foo with the target attribute "default" is the default
28431version. This version gets executed when no other target specific
28432version qualifies for execution on a particular platform. A new version
28433of foo is created by using the same function signature but with a
28434different target string. Function foo is called or a pointer to it is
28435taken just like a regular function. GCC takes care of doing the
28436dispatching to call the right version at runtime. Refer to the
28437@uref{https://gcc.gnu.org/wiki/FunctionMultiVersioning, GCC wiki on
28438Function Multiversioning} for more details.
28439
28440@node Type Traits
28441@section Type Traits
28442
28443The C++ front end implements syntactic extensions that allow
28444compile-time determination of
28445various characteristics of a type (or of a
28446pair of types).
28447
f25efe50
AA
28448@defbuiltin{bool __has_nothrow_assign (@var{type})}
28449If @var{type} is @code{const}-qualified or is a reference type then
d77de738 28450the trait is @code{false}. Otherwise if @code{__has_trivial_assign (type)}
f25efe50 28451is @code{true} then the trait is @code{true}, else if @var{type} is
d77de738
ML
28452a cv-qualified class or union type with copy assignment operators that are
28453known not to throw an exception then the trait is @code{true}, else it is
28454@code{false}.
f25efe50 28455Requires: @var{type} shall be a complete type, (possibly cv-qualified)
d77de738 28456@code{void}, or an array of unknown bound.
f25efe50 28457@enddefbuiltin
d77de738 28458
f25efe50 28459@defbuiltin{bool __has_nothrow_copy (@var{type})}
d77de738 28460If @code{__has_trivial_copy (type)} is @code{true} then the trait is
f25efe50 28461@code{true}, else if @var{type} is a cv-qualified class or union type
d77de738
ML
28462with copy constructors that are known not to throw an exception then
28463the trait is @code{true}, else it is @code{false}.
f25efe50 28464Requires: @var{type} shall be a complete type, (possibly cv-qualified)
d77de738 28465@code{void}, or an array of unknown bound.
f25efe50 28466@enddefbuiltin
d77de738 28467
f25efe50 28468@defbuiltin{bool __has_nothrow_constructor (@var{type})}
d77de738 28469If @code{__has_trivial_constructor (type)} is @code{true} then the trait
f25efe50 28470is @code{true}, else if @var{type} is a cv class or union type (or array
d77de738
ML
28471thereof) with a default constructor that is known not to throw an
28472exception then the trait is @code{true}, else it is @code{false}.
f25efe50 28473Requires: @var{type} shall be a complete type, (possibly cv-qualified)
d77de738 28474@code{void}, or an array of unknown bound.
f25efe50 28475@enddefbuiltin
d77de738 28476
f25efe50
AA
28477@defbuiltin{bool __has_trivial_assign (@var{type})}
28478If @var{type} is @code{const}- qualified or is a reference type then
d77de738 28479the trait is @code{false}. Otherwise if @code{__is_trivial (type)} is
f25efe50 28480@code{true} then the trait is @code{true}, else if @var{type} is
d77de738
ML
28481a cv-qualified class or union type with a trivial copy assignment
28482([class.copy]) then the trait is @code{true}, else it is @code{false}.
f25efe50 28483Requires: @var{type} shall be a complete type, (possibly cv-qualified)
d77de738 28484@code{void}, or an array of unknown bound.
f25efe50 28485@enddefbuiltin
d77de738 28486
f25efe50
AA
28487@defbuiltin{bool __has_trivial_copy (@var{type})}
28488If @code{__is_trivial (type)} is @code{true} or @var{type} is a reference
28489type then the trait is @code{true}, else if @var{type} is a cv class
d77de738 28490or union type with a trivial copy constructor ([class.copy]) then the trait
f25efe50 28491is @code{true}, else it is @code{false}. Requires: @var{type} shall be
d77de738
ML
28492a complete type, (possibly cv-qualified) @code{void}, or an array of unknown
28493bound.
f25efe50 28494@enddefbuiltin
d77de738 28495
f25efe50 28496@defbuiltin{bool __has_trivial_constructor (@var{type})}
d77de738 28497If @code{__is_trivial (type)} is @code{true} then the trait is @code{true},
f25efe50 28498else if @var{type} is a cv-qualified class or union type (or array thereof)
d77de738
ML
28499with a trivial default constructor ([class.ctor]) then the trait is @code{true},
28500else it is @code{false}.
f25efe50 28501Requires: @var{type} shall be a complete type, (possibly cv-qualified)
d77de738 28502@code{void}, or an array of unknown bound.
f25efe50 28503@enddefbuiltin
d77de738 28504
f25efe50
AA
28505@defbuiltin{bool __has_trivial_destructor (@var{type})}
28506If @code{__is_trivial (type)} is @code{true} or @var{type} is a reference type
28507then the trait is @code{true}, else if @var{type} is a cv class or union
d77de738
ML
28508type (or array thereof) with a trivial destructor ([class.dtor]) then
28509the trait is @code{true}, else it is @code{false}.
f25efe50 28510Requires: @var{type} shall be a complete type, (possibly cv-qualified)
d77de738 28511@code{void}, or an array of unknown bound.
f25efe50 28512@enddefbuiltin
d77de738 28513
f25efe50
AA
28514@defbuiltin{bool __has_virtual_destructor (@var{type})}
28515If @var{type} is a class type with a virtual destructor
d77de738 28516([class.dtor]) then the trait is @code{true}, else it is @code{false}.
f25efe50
AA
28517Requires: If @var{type} is a non-union class type, it shall be a complete type.
28518@enddefbuiltin
d77de738 28519
f25efe50
AA
28520@defbuiltin{bool __is_abstract (@var{type})}
28521If @var{type} is an abstract class ([class.abstract]) then the trait
d77de738 28522is @code{true}, else it is @code{false}.
f25efe50
AA
28523Requires: If @var{type} is a non-union class type, it shall be a complete type.
28524@enddefbuiltin
d77de738 28525
f25efe50
AA
28526@defbuiltin{bool __is_aggregate (@var{type})}
28527If @var{type} is an aggregate type ([dcl.init.aggr]) the trait is
d77de738 28528@code{true}, else it is @code{false}.
f25efe50
AA
28529Requires: If @var{type} is a class type, it shall be a complete type.
28530@enddefbuiltin
d77de738 28531
f25efe50
AA
28532@defbuiltin{bool __is_base_of (@var{base_type}, @var{derived_type})}
28533If @var{base_type} is a base class of @var{derived_type}
d77de738 28534([class.derived]) then the trait is @code{true}, otherwise it is @code{false}.
f25efe50
AA
28535Top-level cv-qualifications of @var{base_type} and
28536@var{derived_type} are ignored. For the purposes of this trait, a
d77de738
ML
28537class type is considered is own base.
28538Requires: if @code{__is_class (base_type)} and @code{__is_class (derived_type)}
f25efe50
AA
28539are @code{true} and @var{base_type} and @var{derived_type} are not the same
28540type (disregarding cv-qualifiers), @var{derived_type} shall be a complete
d77de738 28541type. A diagnostic is produced if this requirement is not met.
f25efe50 28542@enddefbuiltin
d77de738 28543
f25efe50
AA
28544@defbuiltin{bool __is_class (@var{type})}
28545If @var{type} is a cv-qualified class type, and not a union type
d77de738 28546([basic.compound]) the trait is @code{true}, else it is @code{false}.
f25efe50 28547@enddefbuiltin
d77de738 28548
30556bf8 28549@c FIXME Commented out for GCC 13, discuss user interface for GCC 14.
f25efe50 28550@c @defbuiltin{bool __is_deducible (@var{template}, @var{type})}
30556bf8
JM
28551@c If template arguments for @code{template} can be deduced from
28552@c @code{type} or obtained from default template arguments.
f25efe50 28553@c @enddefbuiltin
148cbb15 28554
f25efe50 28555@defbuiltin{bool __is_empty (@var{type})}
d77de738 28556If @code{__is_class (type)} is @code{false} then the trait is @code{false}.
f25efe50 28557Otherwise @var{type} is considered empty if and only if: @var{type}
d77de738 28558has no non-static data members, or all non-static data members, if
f25efe50
AA
28559any, are bit-fields of length 0, and @var{type} has no virtual
28560members, and @var{type} has no virtual base classes, and @var{type}
28561has no base classes @var{base_type} for which
d77de738 28562@code{__is_empty (base_type)} is @code{false}.
f25efe50
AA
28563Requires: If @var{type} is a non-union class type, it shall be a complete type.
28564@enddefbuiltin
d77de738 28565
f25efe50
AA
28566@defbuiltin{bool __is_enum (@var{type})}
28567If @var{type} is a cv enumeration type ([basic.compound]) the trait is
d77de738 28568@code{true}, else it is @code{false}.
f25efe50 28569@enddefbuiltin
d77de738 28570
f25efe50
AA
28571@defbuiltin{bool __is_final (@var{type})}
28572If @var{type} is a class or union type marked @code{final}, then the trait
d77de738 28573is @code{true}, else it is @code{false}.
f25efe50
AA
28574Requires: If @var{type} is a class type, it shall be a complete type.
28575@enddefbuiltin
d77de738 28576
f25efe50
AA
28577@defbuiltin{bool __is_literal_type (@var{type})}
28578If @var{type} is a literal type ([basic.types]) the trait is
d77de738 28579@code{true}, else it is @code{false}.
f25efe50 28580Requires: @var{type} shall be a complete type, (possibly cv-qualified)
d77de738 28581@code{void}, or an array of unknown bound.
f25efe50 28582@enddefbuiltin
d77de738 28583
f25efe50
AA
28584@defbuiltin{bool __is_pod (@var{type})}
28585If @var{type} is a cv POD type ([basic.types]) then the trait is @code{true},
d77de738 28586else it is @code{false}.
f25efe50 28587Requires: @var{type} shall be a complete type, (possibly cv-qualified)
d77de738 28588@code{void}, or an array of unknown bound.
f25efe50 28589@enddefbuiltin
d77de738 28590
f25efe50
AA
28591@defbuiltin{bool __is_polymorphic (@var{type})}
28592If @var{type} is a polymorphic class ([class.virtual]) then the trait
d77de738 28593is @code{true}, else it is @code{false}.
f25efe50
AA
28594Requires: If @var{type} is a non-union class type, it shall be a complete type.
28595@enddefbuiltin
d77de738 28596
f25efe50
AA
28597@defbuiltin{bool __is_standard_layout (@var{type})}
28598If @var{type} is a standard-layout type ([basic.types]) the trait is
d77de738 28599@code{true}, else it is @code{false}.
f25efe50 28600Requires: @var{type} shall be a complete type, an array of complete types,
d77de738 28601or (possibly cv-qualified) @code{void}.
f25efe50 28602@enddefbuiltin
d77de738 28603
f25efe50
AA
28604@defbuiltin{bool __is_trivial (@var{type})}
28605If @var{type} is a trivial type ([basic.types]) the trait is
d77de738 28606@code{true}, else it is @code{false}.
f25efe50 28607Requires: @var{type} shall be a complete type, an array of complete types,
d77de738 28608or (possibly cv-qualified) @code{void}.
f25efe50 28609@enddefbuiltin
d77de738 28610
f25efe50
AA
28611@defbuiltin{bool __is_union (@var{type})}
28612If @var{type} is a cv union type ([basic.compound]) the trait is
d77de738 28613@code{true}, else it is @code{false}.
f25efe50 28614@enddefbuiltin
d77de738 28615
f25efe50
AA
28616@defbuiltin{bool __underlying_type (@var{type})}
28617The underlying type of @var{type}.
28618Requires: @var{type} shall be an enumeration type ([dcl.enum]).
28619@enddefbuiltin
d77de738 28620
f25efe50 28621@defbuiltin{bool __integer_pack (@var{length})}
d77de738
ML
28622When used as the pattern of a pack expansion within a template
28623definition, expands to a template argument pack containing integers
f25efe50
AA
28624from @code{0} to @code{@var{length}-1}. This is provided for
28625efficient implementation of @code{std::make_integer_sequence}.
28626@enddefbuiltin
d77de738
ML
28627
28628
28629@node C++ Concepts
28630@section C++ Concepts
28631
28632C++ concepts provide much-improved support for generic programming. In
28633particular, they allow the specification of constraints on template arguments.
28634The constraints are used to extend the usual overloading and partial
28635specialization capabilities of the language, allowing generic data structures
28636and algorithms to be ``refined'' based on their properties rather than their
28637type names.
28638
28639The following keywords are reserved for concepts.
28640
28641@table @code
f25efe50 28642@kindex assumes
d77de738
ML
28643@item assumes
28644States an expression as an assumption, and if possible, verifies that the
28645assumption is valid. For example, @code{assume(n > 0)}.
28646
f25efe50 28647@kindex axiom
d77de738
ML
28648@item axiom
28649Introduces an axiom definition. Axioms introduce requirements on values.
28650
da9140b9 28651@kindex forall
d77de738
ML
28652@item forall
28653Introduces a universally quantified object in an axiom. For example,
da9140b9 28654@code{forall (int n) n + 0 == n}.
d77de738 28655
da9140b9 28656@kindex concept
d77de738
ML
28657@item concept
28658Introduces a concept definition. Concepts are sets of syntactic and semantic
28659requirements on types and their values.
28660
f25efe50 28661@kindex requires
d77de738
ML
28662@item requires
28663Introduces constraints on template arguments or requirements for a member
28664function of a class template.
d77de738
ML
28665@end table
28666
28667The front end also exposes a number of internal mechanism that can be used
28668to simplify the writing of type traits. Note that some of these traits are
28669likely to be removed in the future.
28670
f25efe50
AA
28671@defbuiltin{bool __is_same (@var{type1}, @var{type2})}
28672A binary type trait: @code{true} whenever the @var{type1} and
28673@var{type2} refer to the same type.
28674@enddefbuiltin
d77de738
ML
28675
28676
28677@node Deprecated Features
28678@section Deprecated Features
28679
28680In the past, the GNU C++ compiler was extended to experiment with new
28681features, at a time when the C++ language was still evolving. Now that
28682the C++ standard is complete, some of those features are superseded by
28683superior alternatives. Using the old features might cause a warning in
28684some cases that the feature will be dropped in the future. In other
28685cases, the feature might be gone already.
28686
28687G++ allows a virtual function returning @samp{void *} to be overridden
28688by one returning a different pointer type. This extension to the
28689covariant return type rules is now deprecated and will be removed from a
28690future version.
28691
28692The use of default arguments in function pointers, function typedefs
28693and other places where they are not permitted by the standard is
28694deprecated and will be removed from a future version of G++.
28695
28696G++ allows floating-point literals to appear in integral constant expressions,
28697e.g.@: @samp{ enum E @{ e = int(2.2 * 3.7) @} }
28698This extension is deprecated and will be removed from a future version.
28699
28700G++ allows static data members of const floating-point type to be declared
28701with an initializer in a class definition. The standard only allows
28702initializers for static members of const integral types and const
28703enumeration types so this extension has been deprecated and will be removed
28704from a future version.
28705
28706G++ allows attributes to follow a parenthesized direct initializer,
28707e.g.@: @samp{ int f (0) __attribute__ ((something)); } This extension
28708has been ignored since G++ 3.3 and is deprecated.
28709
28710G++ allows anonymous structs and unions to have members that are not
28711public non-static data members (i.e.@: fields). These extensions are
28712deprecated.
28713
28714@node Backwards Compatibility
28715@section Backwards Compatibility
28716@cindex Backwards Compatibility
28717@cindex ARM [Annotated C++ Reference Manual]
28718
28719Now that there is a definitive ISO standard C++, G++ has a specification
28720to adhere to. The C++ language evolved over time, and features that
28721used to be acceptable in previous drafts of the standard, such as the ARM
28722[Annotated C++ Reference Manual], are no longer accepted. In order to allow
28723compilation of C++ written to such drafts, G++ contains some backwards
28724compatibilities. @emph{All such backwards compatibility features are
28725liable to disappear in future versions of G++.} They should be considered
28726deprecated. @xref{Deprecated Features}.
28727
28728@table @code
28729
28730@item Implicit C language
28731Old C system header files did not contain an @code{extern "C" @{@dots{}@}}
28732scope to set the language. On such systems, all system header files are
28733implicitly scoped inside a C language scope. Such headers must
28734correctly prototype function argument types, there is no leeway for
28735@code{()} to indicate an unspecified set of arguments.
28736
28737@end table
28738
28739@c LocalWords: emph deftypefn builtin ARCv2EM SIMD builtins msimd
28740@c LocalWords: typedef v4si v8hi DMA dma vdiwr vdowr