]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/doc/extend.texi
re PR c/59708 (clang-compatible checked arithmetic builtins)
[thirdparty/gcc.git] / gcc / doc / extend.texi
CommitLineData
23a5b65a 1@c Copyright (C) 1988-2014 Free Software Foundation, Inc.
9a8ce21f 2
c1f7febf
RK
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
84330467 11@opindex pedantic
161d7b59 12GNU C provides several language features not found in ISO standard C@.
f0523f02 13(The @option{-pedantic} option directs GCC to print a warning message if
c1f7febf
RK
14any of these features is used.) To test for the availability of these
15features in conditional compilation, check for a predefined macro
161d7b59 16@code{__GNUC__}, which is always defined under GCC@.
c1f7febf 17
161d7b59 18These extensions are available in C and Objective-C@. Most of them are
c1f7febf
RK
19also available in C++. @xref{C++ Extensions,,Extensions to the
20C++ Language}, for extensions that apply @emph{only} to C++.
21
7e1542b9
MLI
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++.
5490d604 24
c1f7febf
RK
25@menu
26* Statement Exprs:: Putting statements and declarations inside expressions.
14e33ee8 27* Local Labels:: Labels local to a block.
c1f7febf
RK
28* Labels as Values:: Getting pointers to labels, and computed gotos.
29* Nested Functions:: As in Algol and Pascal, lexical scoping of functions.
6ccde948 30* Constructing Calls:: Dispatching a call to another function.
c1f7febf 31* Typeof:: @code{typeof}: referring to the type of an expression.
c1f7febf 32* Conditionals:: Omitting the middle operand of a @samp{?:} expression.
cad055a4 33* __int128:: 128-bit integers---@code{__int128}.
40bf31ed 34* Long Long:: Double-word integers---@code{long long int}.
c1f7febf 35* Complex:: Data types for complex numbers.
c77cd3d1 36* Floating Types:: Additional Floating Types.
0fd8c3ad 37* Half-Precision:: Half-Precision Floating Point.
ff2ce160 38* Decimal Float:: Decimal Floating Types.
6f4d7222 39* Hex Floats:: Hexadecimal floating-point constants.
0f996086 40* Fixed-Point:: Fixed-Point Types.
09e881c9 41* Named Address Spaces::Named address spaces.
c1f7febf 42* Zero Length:: Zero-length arrays.
ba05abd3 43* Empty Structures:: Structures with no members.
40bf31ed 44* Variable Length:: Arrays whose length is computed at run time.
6ccde948 45* Variadic Macros:: Macros with a variable number of arguments.
ccd96f0a 46* Escaped Newlines:: Slightly looser rules for escaped newlines.
c1f7febf
RK
47* Subscripting:: Any array can be subscripted, even if not an lvalue.
48* Pointer Arith:: Arithmetic on @code{void}-pointers and function pointers.
49* Initializers:: Non-constant initializers.
4b404517 50* Compound Literals:: Compound literals give structures, unions
6ccde948
RW
51 or arrays as values.
52* Designated Inits:: Labeling elements of initializers.
6ccde948 53* Case Ranges:: `case 1 ... 9' and such.
40bf31ed 54* Cast to Union:: Casting to union type from any member of the union.
6ccde948 55* Mixed Declarations:: Mixing declarations and code.
c1f7febf 56* Function Attributes:: Declaring that functions have no side effects,
6ccde948 57 or that they can never return.
883755a1 58* Label Attributes:: Specifying attributes on labels.
2c5e91d2 59* Attribute Syntax:: Formal syntax for attributes.
c1f7febf
RK
60* Function Prototypes:: Prototype declarations and old-style definitions.
61* C++ Comments:: C++ comments are recognized.
62* Dollar Signs:: Dollar sign is allowed in identifiers.
63* Character Escapes:: @samp{\e} stands for the character @key{ESC}.
6ccde948
RW
64* Variable Attributes:: Specifying attributes of variables.
65* Type Attributes:: Specifying attributes of types.
c1f7febf
RK
66* Alignment:: Inquiring about the alignment of a type or variable.
67* Inline:: Defining inline functions (as fast as macros).
8f0fe813 68* Volatiles:: What constitutes an access to a volatile object.
04e137a1 69* Using Assembly Language with C:: Instructions and extensions for interfacing C with assembler.
c1f7febf
RK
70* Alternate Keywords:: @code{__const__}, @code{__asm__}, etc., for header files.
71* Incomplete Enums:: @code{enum foo;}, with details to follow.
6ccde948
RW
72* Function Names:: Printable strings which are the name of the current
73 function.
c1f7febf 74* Return Address:: Getting the return or frame address of a function.
1255c85c 75* Vector Extensions:: Using vector instructions through built-in functions.
7a3ea201 76* Offsetof:: Special syntax for implementing @code{offsetof}.
86951993
AM
77* __sync Builtins:: Legacy built-in functions for atomic memory access.
78* __atomic Builtins:: Atomic built-in functions with memory model.
1304953e
JJ
79* Integer Overflow Builtins:: Built-in functions to perform arithmetics and
80 arithmetic overflow checking.
4323afa0 81* x86 specific memory model extensions for transactional memory:: x86 memory models.
10a0d495
JJ
82* Object Size Checking:: Built-in functions for limited buffer overflow
83 checking.
d5e254e1 84* Pointer Bounds Checker builtins:: Built-in functions for Pointer Bounds Checker.
36536d79 85* Cilk Plus Builtins:: Built-in functions for the Cilk Plus language extension.
c5c76735 86* Other Builtins:: Other built-in functions.
0975678f 87* Target Builtins:: Built-in functions specific to particular targets.
a2bec818 88* Target Format Checks:: Format checks specific to particular targets.
0168a849 89* Pragmas:: Pragmas accepted by GCC.
b11cc610 90* Unnamed Fields:: Unnamed struct/union fields within structs/unions.
3d78f2e9 91* Thread-Local:: Per-thread variables.
f7fd775f 92* Binary constants:: Binary constants using the @samp{0b} prefix.
c1f7febf 93@end menu
c1f7febf
RK
94
95@node Statement Exprs
96@section Statements and Declarations in Expressions
97@cindex statements inside expressions
98@cindex declarations inside expressions
99@cindex expressions containing statements
100@cindex macros, statements in expressions
101
102@c the above section title wrapped and causes an underfull hbox.. i
103@c changed it from "within" to "in". --mew 4feb93
c1f7febf 104A compound statement enclosed in parentheses may appear as an expression
161d7b59 105in GNU C@. This allows you to use loops, switches, and local variables
c1f7febf
RK
106within an expression.
107
108Recall that a compound statement is a sequence of statements surrounded
109by braces; in this construct, parentheses go around the braces. For
110example:
111
3ab51846 112@smallexample
c1f7febf
RK
113(@{ int y = foo (); int z;
114 if (y > 0) z = y;
115 else z = - y;
116 z; @})
3ab51846 117@end smallexample
c1f7febf
RK
118
119@noindent
120is a valid (though slightly more complex than necessary) expression
121for the absolute value of @code{foo ()}.
122
123The last thing in the compound statement should be an expression
124followed by a semicolon; the value of this subexpression serves as the
125value of the entire construct. (If you use some other kind of statement
126last within the braces, the construct has type @code{void}, and thus
127effectively no value.)
128
129This feature is especially useful in making macro definitions ``safe'' (so
130that they evaluate each operand exactly once). For example, the
131``maximum'' function is commonly defined as a macro in standard C as
132follows:
133
3ab51846 134@smallexample
c1f7febf 135#define max(a,b) ((a) > (b) ? (a) : (b))
3ab51846 136@end smallexample
c1f7febf
RK
137
138@noindent
139@cindex side effects, macro argument
140But this definition computes either @var{a} or @var{b} twice, with bad
141results if the operand has side effects. In GNU C, if you know the
962e6e00 142type of the operands (here taken as @code{int}), you can define
c1f7febf
RK
143the macro safely as follows:
144
3ab51846 145@smallexample
c1f7febf
RK
146#define maxint(a,b) \
147 (@{int _a = (a), _b = (b); _a > _b ? _a : _b; @})
3ab51846 148@end smallexample
c1f7febf
RK
149
150Embedded statements are not allowed in constant expressions, such as
c771326b 151the value of an enumeration constant, the width of a bit-field, or
c1f7febf
RK
152the initial value of a static variable.
153
154If you don't know the type of the operand, you can still do this, but you
38b7bc7f 155must use @code{typeof} or @code{__auto_type} (@pxref{Typeof}).
c1f7febf 156
a5bcc582
NS
157In G++, the result value of a statement expression undergoes array and
158function pointer decay, and is returned by value to the enclosing
8a36672b 159expression. For instance, if @code{A} is a class, then
b98e139b 160
a5bcc582
NS
161@smallexample
162 A a;
b98e139b 163
a5bcc582
NS
164 (@{a;@}).Foo ()
165@end smallexample
b98e139b
MM
166
167@noindent
358a3dbc
SL
168constructs a temporary @code{A} object to hold the result of the
169statement expression, and that is used to invoke @code{Foo}.
170Therefore the @code{this} pointer observed by @code{Foo} is not the
a5bcc582
NS
171address of @code{a}.
172
bafa88c2
SL
173In a statement expression, any temporaries created within a statement
174are destroyed at that statement's end. This makes statement
a5bcc582 175expressions inside macros slightly different from function calls. In
358a3dbc
SL
176the latter case temporaries introduced during argument evaluation are
177destroyed at the end of the statement that includes the function
178call. In the statement expression case they are destroyed during
a5bcc582 179the statement expression. For instance,
b98e139b 180
a5bcc582
NS
181@smallexample
182#define macro(a) (@{__typeof__(a) b = (a); b + 3; @})
183template<typename T> T function(T a) @{ T b = a; return b + 3; @}
184
185void foo ()
186@{
187 macro (X ());
188 function (X ());
189@}
190@end smallexample
b98e139b
MM
191
192@noindent
358a3dbc
SL
193has different places where temporaries are destroyed. For the
194@code{macro} case, the temporary @code{X} is destroyed just after
a5bcc582 195the initialization of @code{b}. In the @code{function} case that
358a3dbc 196temporary is destroyed when the function returns.
b98e139b
MM
197
198These considerations mean that it is probably a bad idea to use
bafa88c2 199statement expressions of this form in header files that are designed to
54e1d3a6 200work with C++. (Note that some versions of the GNU C Library contained
bafa88c2 201header files using statement expressions that lead to precisely this
54e1d3a6 202bug.)
b98e139b 203
16ef3acc
JM
204Jumping into a statement expression with @code{goto} or using a
205@code{switch} statement outside the statement expression with a
206@code{case} or @code{default} label inside the statement expression is
207not permitted. Jumping into a statement expression with a computed
bafa88c2 208@code{goto} (@pxref{Labels as Values}) has undefined behavior.
16ef3acc
JM
209Jumping out of a statement expression is permitted, but if the
210statement expression is part of a larger expression then it is
211unspecified which other subexpressions of that expression have been
212evaluated except where the language definition requires certain
213subexpressions to be evaluated before or after the statement
bafa88c2 214expression. In any case, as with a function call, the evaluation of a
16ef3acc
JM
215statement expression is not interleaved with the evaluation of other
216parts of the containing expression. For example,
217
218@smallexample
219 foo (), ((@{ bar1 (); goto a; 0; @}) + bar2 ()), baz();
220@end smallexample
221
222@noindent
358a3dbc
SL
223calls @code{foo} and @code{bar1} and does not call @code{baz} but
224may or may not call @code{bar2}. If @code{bar2} is called, it is
225called after @code{foo} and before @code{bar1}.
16ef3acc 226
c1f7febf
RK
227@node Local Labels
228@section Locally Declared Labels
229@cindex local labels
230@cindex macros, local labels
231
14e33ee8 232GCC allows you to declare @dfn{local labels} in any nested block
8a36672b 233scope. A local label is just like an ordinary label, but you can
14e33ee8 234only reference it (with a @code{goto} statement, or by taking its
358a3dbc 235address) within the block in which it is declared.
c1f7febf
RK
236
237A local label declaration looks like this:
238
3ab51846 239@smallexample
c1f7febf 240__label__ @var{label};
3ab51846 241@end smallexample
c1f7febf
RK
242
243@noindent
244or
245
3ab51846 246@smallexample
0d893a63 247__label__ @var{label1}, @var{label2}, /* @r{@dots{}} */;
3ab51846 248@end smallexample
c1f7febf 249
14e33ee8
ZW
250Local label declarations must come at the beginning of the block,
251before any ordinary declarations or statements.
c1f7febf
RK
252
253The label declaration defines the label @emph{name}, but does not define
254the label itself. You must do this in the usual way, with
255@code{@var{label}:}, within the statements of the statement expression.
256
14e33ee8
ZW
257The local label feature is useful for complex macros. If a macro
258contains nested loops, a @code{goto} can be useful for breaking out of
259them. However, an ordinary label whose scope is the whole function
260cannot be used: if the macro can be expanded several times in one
358a3dbc 261function, the label is multiply defined in that function. A
14e33ee8
ZW
262local label avoids this problem. For example:
263
3ab51846 264@smallexample
14e33ee8
ZW
265#define SEARCH(value, array, target) \
266do @{ \
267 __label__ found; \
268 typeof (target) _SEARCH_target = (target); \
269 typeof (*(array)) *_SEARCH_array = (array); \
270 int i, j; \
271 int value; \
272 for (i = 0; i < max; i++) \
273 for (j = 0; j < max; j++) \
274 if (_SEARCH_array[i][j] == _SEARCH_target) \
275 @{ (value) = i; goto found; @} \
276 (value) = -1; \
277 found:; \
278@} while (0)
3ab51846 279@end smallexample
14e33ee8 280
bafa88c2 281This could also be written using a statement expression:
c1f7febf 282
3ab51846 283@smallexample
c1f7febf 284#define SEARCH(array, target) \
310668e8 285(@{ \
c1f7febf
RK
286 __label__ found; \
287 typeof (target) _SEARCH_target = (target); \
288 typeof (*(array)) *_SEARCH_array = (array); \
289 int i, j; \
290 int value; \
291 for (i = 0; i < max; i++) \
292 for (j = 0; j < max; j++) \
293 if (_SEARCH_array[i][j] == _SEARCH_target) \
310668e8 294 @{ value = i; goto found; @} \
c1f7febf
RK
295 value = -1; \
296 found: \
297 value; \
298@})
3ab51846 299@end smallexample
c1f7febf 300
14e33ee8
ZW
301Local label declarations also make the labels they declare visible to
302nested functions, if there are any. @xref{Nested Functions}, for details.
303
c1f7febf
RK
304@node Labels as Values
305@section Labels as Values
306@cindex labels as values
307@cindex computed gotos
308@cindex goto with computed label
309@cindex address of a label
310
311You can get the address of a label defined in the current function
312(or a containing function) with the unary operator @samp{&&}. The
313value has type @code{void *}. This value is a constant and can be used
314wherever a constant of that type is valid. For example:
315
3ab51846 316@smallexample
c1f7febf 317void *ptr;
0d893a63 318/* @r{@dots{}} */
c1f7febf 319ptr = &&foo;
3ab51846 320@end smallexample
c1f7febf
RK
321
322To use these values, you need to be able to jump to one. This is done
323with the computed goto statement@footnote{The analogous feature in
324Fortran is called an assigned goto, but that name seems inappropriate in
325C, where one can do more than simply store label addresses in label
326variables.}, @code{goto *@var{exp};}. For example,
327
3ab51846 328@smallexample
c1f7febf 329goto *ptr;
3ab51846 330@end smallexample
c1f7febf
RK
331
332@noindent
333Any expression of type @code{void *} is allowed.
334
335One way of using these constants is in initializing a static array that
358a3dbc 336serves as a jump table:
c1f7febf 337
3ab51846 338@smallexample
c1f7febf 339static void *array[] = @{ &&foo, &&bar, &&hack @};
3ab51846 340@end smallexample
c1f7febf 341
c513ecbf 342@noindent
c1f7febf
RK
343Then you can select a label with indexing, like this:
344
3ab51846 345@smallexample
c1f7febf 346goto *array[i];
3ab51846 347@end smallexample
c1f7febf
RK
348
349@noindent
350Note that this does not check whether the subscript is in bounds---array
351indexing in C never does that.
352
353Such an array of label values serves a purpose much like that of the
354@code{switch} statement. The @code{switch} statement is cleaner, so
355use that rather than an array unless the problem does not fit a
356@code{switch} statement very well.
357
358Another use of label values is in an interpreter for threaded code.
359The labels within the interpreter function can be stored in the
360threaded code for super-fast dispatching.
361
02f52e19 362You may not use this mechanism to jump to code in a different function.
358a3dbc 363If you do that, totally unpredictable things happen. The best way to
c1f7febf
RK
364avoid this is to store the label address only in automatic variables and
365never pass it as an argument.
366
47620e09
RH
367An alternate way to write the above example is
368
3ab51846 369@smallexample
310668e8
JM
370static const int array[] = @{ &&foo - &&foo, &&bar - &&foo,
371 &&hack - &&foo @};
47620e09 372goto *(&&foo + array[i]);
3ab51846 373@end smallexample
47620e09
RH
374
375@noindent
376This is more friendly to code living in shared libraries, as it reduces
377the number of dynamic relocations that are needed, and by consequence,
378allows the data to be read-only.
92747f7d
GJL
379This alternative with label differences is not supported for the AVR target,
380please use the first approach for AVR programs.
47620e09 381
86631ea3
MJ
382The @code{&&foo} expressions for the same label might have different
383values if the containing function is inlined or cloned. If a program
384relies on them being always the same,
385@code{__attribute__((__noinline__,__noclone__))} should be used to
386prevent inlining and cloning. If @code{&&foo} is used in a static
387variable initializer, inlining and cloning is forbidden.
2092ee7d 388
c1f7febf
RK
389@node Nested Functions
390@section Nested Functions
391@cindex nested functions
392@cindex downward funargs
393@cindex thunks
394
395A @dfn{nested function} is a function defined inside another function.
bafa88c2
SL
396Nested functions are supported as an extension in GNU C, but are not
397supported by GNU C++.
398
399The nested function's name is local to the block where it is defined.
400For example, here we define a nested function named @code{square}, and
401call it twice:
c1f7febf 402
3ab51846 403@smallexample
c1f7febf
RK
404@group
405foo (double a, double b)
406@{
407 double square (double z) @{ return z * z; @}
408
409 return square (a) + square (b);
410@}
411@end group
3ab51846 412@end smallexample
c1f7febf
RK
413
414The nested function can access all the variables of the containing
415function that are visible at the point of its definition. This is
416called @dfn{lexical scoping}. For example, here we show a nested
417function which uses an inherited variable named @code{offset}:
418
3ab51846 419@smallexample
aee96fe9 420@group
c1f7febf
RK
421bar (int *array, int offset, int size)
422@{
423 int access (int *array, int index)
424 @{ return array[index + offset]; @}
425 int i;
0d893a63 426 /* @r{@dots{}} */
c1f7febf 427 for (i = 0; i < size; i++)
0d893a63 428 /* @r{@dots{}} */ access (array, i) /* @r{@dots{}} */
c1f7febf 429@}
aee96fe9 430@end group
3ab51846 431@end smallexample
c1f7febf
RK
432
433Nested function definitions are permitted within functions in the places
475b6e22
JM
434where variable definitions are allowed; that is, in any block, mixed
435with the other declarations and statements in the block.
c1f7febf
RK
436
437It is possible to call the nested function from outside the scope of its
438name by storing its address or passing the address to another function:
439
3ab51846 440@smallexample
c1f7febf
RK
441hack (int *array, int size)
442@{
443 void store (int index, int value)
444 @{ array[index] = value; @}
445
446 intermediate (store, size);
447@}
3ab51846 448@end smallexample
c1f7febf
RK
449
450Here, the function @code{intermediate} receives the address of
451@code{store} as an argument. If @code{intermediate} calls @code{store},
452the arguments given to @code{store} are used to store into @code{array}.
453But this technique works only so long as the containing function
454(@code{hack}, in this example) does not exit.
455
456If you try to call the nested function through its address after the
358a3dbc
SL
457containing function exits, all hell breaks loose. If you try
458to call it after a containing scope level exits, and if it refers
c1f7febf
RK
459to some of the variables that are no longer in scope, you may be lucky,
460but it's not wise to take the risk. If, however, the nested function
461does not refer to anything that has gone out of scope, you should be
462safe.
463
9c34dbbf 464GCC implements taking the address of a nested function using a technique
ff2ce160 465called @dfn{trampolines}. This technique was described in
63a26b78
SL
466@cite{Lexical Closures for C++} (Thomas M. Breuel, USENIX
467C++ Conference Proceedings, October 17-21, 1988).
c1f7febf
RK
468
469A nested function can jump to a label inherited from a containing
358a3dbc 470function, provided the label is explicitly declared in the containing
c1f7febf 471function (@pxref{Local Labels}). Such a jump returns instantly to the
c417597c 472containing function, exiting the nested function that did the
c1f7febf
RK
473@code{goto} and any intermediate functions as well. Here is an example:
474
3ab51846 475@smallexample
c1f7febf
RK
476@group
477bar (int *array, int offset, int size)
478@{
479 __label__ failure;
480 int access (int *array, int index)
481 @{
482 if (index > size)
483 goto failure;
484 return array[index + offset];
485 @}
486 int i;
0d893a63 487 /* @r{@dots{}} */
c1f7febf 488 for (i = 0; i < size; i++)
0d893a63
MK
489 /* @r{@dots{}} */ access (array, i) /* @r{@dots{}} */
490 /* @r{@dots{}} */
c1f7febf
RK
491 return 0;
492
493 /* @r{Control comes here from @code{access}
494 if it detects an error.} */
495 failure:
496 return -1;
497@}
498@end group
3ab51846 499@end smallexample
c1f7febf 500
28697267
DJ
501A nested function always has no linkage. Declaring one with
502@code{extern} or @code{static} is erroneous. If you need to declare the nested function
c1f7febf
RK
503before its definition, use @code{auto} (which is otherwise meaningless
504for function declarations).
505
3ab51846 506@smallexample
c1f7febf
RK
507bar (int *array, int offset, int size)
508@{
509 __label__ failure;
510 auto int access (int *, int);
0d893a63 511 /* @r{@dots{}} */
c1f7febf
RK
512 int access (int *array, int index)
513 @{
514 if (index > size)
515 goto failure;
516 return array[index + offset];
517 @}
0d893a63 518 /* @r{@dots{}} */
c1f7febf 519@}
3ab51846 520@end smallexample
c1f7febf
RK
521
522@node Constructing Calls
523@section Constructing Function Calls
524@cindex constructing calls
525@cindex forwarding calls
526
527Using the built-in functions described below, you can record
528the arguments a function received, and call another function
529with the same arguments, without knowing the number or types
530of the arguments.
531
532You can also record the return value of that function call,
533and later return that value, without knowing what data type
534the function tried to return (as long as your caller expects
535that data type).
536
6429bc7c
EB
537However, these built-in functions may interact badly with some
538sophisticated features or other extensions of the language. It
539is, therefore, not recommended to use them outside very simple
540functions acting as mere forwarders for their arguments.
541
84330467
JM
542@deftypefn {Built-in Function} {void *} __builtin_apply_args ()
543This built-in function returns a pointer to data
358a3dbc 544describing how to perform a call with the same arguments as are passed
c1f7febf
RK
545to the current function.
546
547The function saves the arg pointer register, structure value address,
548and all registers that might be used to pass arguments to a function
549into a block of memory allocated on the stack. Then it returns the
550address of that block.
84330467 551@end deftypefn
c1f7febf 552
84330467
JM
553@deftypefn {Built-in Function} {void *} __builtin_apply (void (*@var{function})(), void *@var{arguments}, size_t @var{size})
554This built-in function invokes @var{function}
555with a copy of the parameters described by @var{arguments}
556and @var{size}.
c1f7febf
RK
557
558The value of @var{arguments} should be the value returned by
559@code{__builtin_apply_args}. The argument @var{size} specifies the size
560of the stack argument data, in bytes.
561
84330467 562This function returns a pointer to data describing
358a3dbc 563how to return whatever value is returned by @var{function}. The data
c1f7febf
RK
564is saved in a block of memory allocated on the stack.
565
566It is not always simple to compute the proper value for @var{size}. The
567value is used by @code{__builtin_apply} to compute the amount of data
568that should be pushed on the stack and copied from the incoming argument
569area.
84330467 570@end deftypefn
c1f7febf 571
84330467 572@deftypefn {Built-in Function} {void} __builtin_return (void *@var{result})
c1f7febf
RK
573This built-in function returns the value described by @var{result} from
574the containing function. You should specify, for @var{result}, a value
575returned by @code{__builtin_apply}.
84330467 576@end deftypefn
c1f7febf 577
ab940b73 578@deftypefn {Built-in Function} {} __builtin_va_arg_pack ()
6ef5231b 579This built-in function represents all anonymous arguments of an inline
c417597c 580function. It can be used only in inline functions that are always
6ef5231b
JJ
581inlined, never compiled as a separate function, such as those using
582@code{__attribute__ ((__always_inline__))} or
583@code{__attribute__ ((__gnu_inline__))} extern inline functions.
584It must be only passed as last argument to some other function
585with variable arguments. This is useful for writing small wrapper
586inlines for variable argument functions, when using preprocessor
587macros is undesirable. For example:
588@smallexample
589extern int myprintf (FILE *f, const char *format, ...);
590extern inline __attribute__ ((__gnu_inline__)) int
591myprintf (FILE *f, const char *format, ...)
592@{
593 int r = fprintf (f, "myprintf: ");
594 if (r < 0)
595 return r;
596 int s = fprintf (f, format, __builtin_va_arg_pack ());
597 if (s < 0)
598 return s;
599 return r + s;
600@}
601@end smallexample
602@end deftypefn
603
ab940b73 604@deftypefn {Built-in Function} {size_t} __builtin_va_arg_pack_len ()
ab0e176c 605This built-in function returns the number of anonymous arguments of
c417597c 606an inline function. It can be used only in inline functions that
358a3dbc 607are always inlined, never compiled as a separate function, such
ab0e176c
JJ
608as those using @code{__attribute__ ((__always_inline__))} or
609@code{__attribute__ ((__gnu_inline__))} extern inline functions.
566fb011 610For example following does link- or run-time checking of open
ab0e176c
JJ
611arguments for optimized code:
612@smallexample
613#ifdef __OPTIMIZE__
614extern inline __attribute__((__gnu_inline__)) int
615myopen (const char *path, int oflag, ...)
616@{
617 if (__builtin_va_arg_pack_len () > 1)
618 warn_open_too_many_arguments ();
619
620 if (__builtin_constant_p (oflag))
621 @{
622 if ((oflag & O_CREAT) != 0 && __builtin_va_arg_pack_len () < 1)
623 @{
624 warn_open_missing_mode ();
625 return __open_2 (path, oflag);
626 @}
627 return open (path, oflag, __builtin_va_arg_pack ());
628 @}
ff2ce160 629
ab0e176c
JJ
630 if (__builtin_va_arg_pack_len () < 1)
631 return __open_2 (path, oflag);
632
633 return open (path, oflag, __builtin_va_arg_pack ());
634@}
635#endif
636@end smallexample
637@end deftypefn
638
c1f7febf
RK
639@node Typeof
640@section Referring to a Type with @code{typeof}
641@findex typeof
642@findex sizeof
643@cindex macros, types of arguments
644
645Another way to refer to the type of an expression is with @code{typeof}.
646The syntax of using of this keyword looks like @code{sizeof}, but the
647construct acts semantically like a type name defined with @code{typedef}.
648
649There are two ways of writing the argument to @code{typeof}: with an
650expression or with a type. Here is an example with an expression:
651
3ab51846 652@smallexample
c1f7febf 653typeof (x[0](1))
3ab51846 654@end smallexample
c1f7febf
RK
655
656@noindent
89aed483
JM
657This assumes that @code{x} is an array of pointers to functions;
658the type described is that of the values of the functions.
c1f7febf
RK
659
660Here is an example with a typename as the argument:
661
3ab51846 662@smallexample
c1f7febf 663typeof (int *)
3ab51846 664@end smallexample
c1f7febf
RK
665
666@noindent
667Here the type described is that of pointers to @code{int}.
668
5490d604 669If you are writing a header file that must work when included in ISO C
c1f7febf
RK
670programs, write @code{__typeof__} instead of @code{typeof}.
671@xref{Alternate Keywords}.
672
bafa88c2 673A @code{typeof} construct can be used anywhere a typedef name can be
c1f7febf
RK
674used. For example, you can use it in a declaration, in a cast, or inside
675of @code{sizeof} or @code{typeof}.
676
928c19bb
JM
677The operand of @code{typeof} is evaluated for its side effects if and
678only if it is an expression of variably modified type or the name of
679such a type.
680
bafa88c2
SL
681@code{typeof} is often useful in conjunction with
682statement expressions (@pxref{Statement Exprs}).
683Here is how the two together can
c417597c 684be used to define a safe ``maximum'' macro which operates on any
95f79357
ZW
685arithmetic type and evaluates each of its arguments exactly once:
686
3ab51846 687@smallexample
95f79357
ZW
688#define max(a,b) \
689 (@{ typeof (a) _a = (a); \
690 typeof (b) _b = (b); \
691 _a > _b ? _a : _b; @})
3ab51846 692@end smallexample
95f79357 693
526278c9
VR
694@cindex underscores in variables in macros
695@cindex @samp{_} in variables in macros
696@cindex local variables in macros
697@cindex variables, local, in macros
698@cindex macros, local variables in
699
700The reason for using names that start with underscores for the local
701variables is to avoid conflicts with variable names that occur within the
702expressions that are substituted for @code{a} and @code{b}. Eventually we
703hope to design a new form of declaration syntax that allows you to declare
704variables whose scopes start only after their initializers; this will be a
705more reliable way to prevent such conflicts.
706
95f79357
ZW
707@noindent
708Some more examples of the use of @code{typeof}:
709
c1f7febf
RK
710@itemize @bullet
711@item
712This declares @code{y} with the type of what @code{x} points to.
713
3ab51846 714@smallexample
c1f7febf 715typeof (*x) y;
3ab51846 716@end smallexample
c1f7febf
RK
717
718@item
719This declares @code{y} as an array of such values.
720
3ab51846 721@smallexample
c1f7febf 722typeof (*x) y[4];
3ab51846 723@end smallexample
c1f7febf
RK
724
725@item
726This declares @code{y} as an array of pointers to characters:
727
3ab51846 728@smallexample
c1f7febf 729typeof (typeof (char *)[4]) y;
3ab51846 730@end smallexample
c1f7febf
RK
731
732@noindent
733It is equivalent to the following traditional C declaration:
734
3ab51846 735@smallexample
c1f7febf 736char *y[4];
3ab51846 737@end smallexample
c1f7febf
RK
738
739To see the meaning of the declaration using @code{typeof}, and why it
962e6e00 740might be a useful way to write, rewrite it with these macros:
c1f7febf 741
3ab51846 742@smallexample
c1f7febf
RK
743#define pointer(T) typeof(T *)
744#define array(T, N) typeof(T [N])
3ab51846 745@end smallexample
c1f7febf
RK
746
747@noindent
748Now the declaration can be rewritten this way:
749
3ab51846 750@smallexample
c1f7febf 751array (pointer (char), 4) y;
3ab51846 752@end smallexample
c1f7febf
RK
753
754@noindent
755Thus, @code{array (pointer (char), 4)} is the type of arrays of 4
756pointers to @code{char}.
757@end itemize
758
38b7bc7f
JM
759In GNU C, but not GNU C++, you may also declare the type of a variable
760as @code{__auto_type}. In that case, the declaration must declare
761only one variable, whose declarator must just be an identifier, the
762declaration must be initialized, and the type of the variable is
763determined by the initializer; the name of the variable is not in
764scope until after the initializer. (In C++, you should use C++11
765@code{auto} for this purpose.) Using @code{__auto_type}, the
766``maximum'' macro above could be written as:
767
768@smallexample
769#define max(a,b) \
770 (@{ __auto_type _a = (a); \
771 __auto_type _b = (b); \
772 _a > _b ? _a : _b; @})
773@end smallexample
774
775Using @code{__auto_type} instead of @code{typeof} has two advantages:
776
777@itemize @bullet
778@item Each argument to the macro appears only once in the expansion of
779the macro. This prevents the size of the macro expansion growing
780exponentially when calls to such macros are nested inside arguments of
781such macros.
782
783@item If the argument to the macro has variably modified type, it is
784evaluated only once when using @code{__auto_type}, but twice if
785@code{typeof} is used.
786@end itemize
787
95f79357 788@emph{Compatibility Note:} In addition to @code{typeof}, GCC 2 supported
c417597c 789a more limited extension that permitted one to write
95f79357 790
3ab51846 791@smallexample
95f79357 792typedef @var{T} = @var{expr};
3ab51846 793@end smallexample
95f79357
ZW
794
795@noindent
796with the effect of declaring @var{T} to have the type of the expression
797@var{expr}. This extension does not work with GCC 3 (versions between
c417597c 7983.0 and 3.2 crash; 3.2.1 and later give an error). Code that
95f79357
ZW
799relies on it should be rewritten to use @code{typeof}:
800
3ab51846 801@smallexample
95f79357 802typedef typeof(@var{expr}) @var{T};
3ab51846 803@end smallexample
95f79357
ZW
804
805@noindent
358a3dbc 806This works with all versions of GCC@.
95f79357 807
c1f7febf
RK
808@node Conditionals
809@section Conditionals with Omitted Operands
810@cindex conditional expressions, extensions
811@cindex omitted middle-operands
812@cindex middle-operands, omitted
813@cindex extensions, @code{?:}
814@cindex @code{?:} extensions
815
816The middle operand in a conditional expression may be omitted. Then
817if the first operand is nonzero, its value is the value of the conditional
818expression.
819
820Therefore, the expression
821
3ab51846 822@smallexample
c1f7febf 823x ? : y
3ab51846 824@end smallexample
c1f7febf
RK
825
826@noindent
827has the value of @code{x} if that is nonzero; otherwise, the value of
828@code{y}.
829
830This example is perfectly equivalent to
831
3ab51846 832@smallexample
c1f7febf 833x ? x : y
3ab51846 834@end smallexample
c1f7febf 835
ab940b73
RW
836@cindex side effect in @code{?:}
837@cindex @code{?:} side effect
c1f7febf
RK
838@noindent
839In this simple case, the ability to omit the middle operand is not
840especially useful. When it becomes useful is when the first operand does,
841or may (if it is a macro argument), contain a side effect. Then repeating
842the operand in the middle would perform the side effect twice. Omitting
843the middle operand uses the value already computed without the undesirable
844effects of recomputing it.
845
a6766312 846@node __int128
4ebd56a5 847@section 128-bit integers
a6766312
KT
848@cindex @code{__int128} data types
849
850As an extension the integer scalar type @code{__int128} is supported for
4ebd56a5 851targets which have an integer mode wide enough to hold 128 bits.
a6766312
KT
852Simply write @code{__int128} for a signed 128-bit integer, or
853@code{unsigned __int128} for an unsigned 128-bit integer. There is no
4ebd56a5
JW
854support in GCC for expressing an integer constant of type @code{__int128}
855for targets with @code{long long} integer less than 128 bits wide.
a6766312 856
c1f7febf
RK
857@node Long Long
858@section Double-Word Integers
859@cindex @code{long long} data types
860@cindex double-word arithmetic
861@cindex multiprecision arithmetic
4b404517
JM
862@cindex @code{LL} integer suffix
863@cindex @code{ULL} integer suffix
c1f7febf 864
4b404517 865ISO C99 supports data types for integers that are at least 64 bits wide,
7e1542b9 866and as an extension GCC supports them in C90 mode and in C++.
4b404517 867Simply write @code{long long int} for a signed integer, or
c1f7febf 868@code{unsigned long long int} for an unsigned integer. To make an
84330467 869integer constant of type @code{long long int}, add the suffix @samp{LL}
c1f7febf 870to the integer. To make an integer constant of type @code{unsigned long
84330467 871long int}, add the suffix @samp{ULL} to the integer.
c1f7febf
RK
872
873You can use these types in arithmetic like any other integer types.
874Addition, subtraction, and bitwise boolean operations on these types
875are open-coded on all types of machines. Multiplication is open-coded
bafa88c2 876if the machine supports a fullword-to-doubleword widening multiply
c1f7febf
RK
877instruction. Division and shifts are open-coded only on machines that
878provide special support. The operations that are not open-coded use
161d7b59 879special library routines that come with GCC@.
c1f7febf
RK
880
881There may be pitfalls when you use @code{long long} types for function
bafa88c2 882arguments without function prototypes. If a function
c1f7febf 883expects type @code{int} for its argument, and you pass a value of type
358a3dbc
SL
884@code{long long int}, confusion results because the caller and the
885subroutine disagree about the number of bytes for the argument.
c1f7febf
RK
886Likewise, if the function expects @code{long long int} and you pass
887@code{int}. The best way to avoid such problems is to use prototypes.
888
889@node Complex
890@section Complex Numbers
891@cindex complex numbers
4b404517
JM
892@cindex @code{_Complex} keyword
893@cindex @code{__complex__} keyword
c1f7febf 894
4b404517 895ISO C99 supports complex floating data types, and as an extension GCC
bafa88c2 896supports them in C90 mode and in C++. GCC also supports complex integer data
4b404517
JM
897types which are not part of ISO C99. You can declare complex types
898using the keyword @code{_Complex}. As an extension, the older GNU
899keyword @code{__complex__} is also supported.
c1f7febf 900
4b404517 901For example, @samp{_Complex double x;} declares @code{x} as a
c1f7febf 902variable whose real part and imaginary part are both of type
4b404517 903@code{double}. @samp{_Complex short int y;} declares @code{y} to
c1f7febf
RK
904have real and imaginary parts of type @code{short int}; this is not
905likely to be useful, but it shows that the set of complex types is
906complete.
907
908To write a constant with a complex data type, use the suffix @samp{i} or
909@samp{j} (either one; they are equivalent). For example, @code{2.5fi}
4b404517
JM
910has type @code{_Complex float} and @code{3i} has type
911@code{_Complex int}. Such a constant always has a pure imaginary
c1f7febf 912value, but you can form any complex value you like by adding one to a
4b404517 913real constant. This is a GNU extension; if you have an ISO C99
bafa88c2 914conforming C library (such as the GNU C Library), and want to construct complex
4b404517
JM
915constants of floating type, you should include @code{<complex.h>} and
916use the macros @code{I} or @code{_Complex_I} instead.
c1f7febf 917
4b404517
JM
918@cindex @code{__real__} keyword
919@cindex @code{__imag__} keyword
c1f7febf
RK
920To extract the real part of a complex-valued expression @var{exp}, write
921@code{__real__ @var{exp}}. Likewise, use @code{__imag__} to
4b404517
JM
922extract the imaginary part. This is a GNU extension; for values of
923floating type, you should use the ISO C99 functions @code{crealf},
924@code{creal}, @code{creall}, @code{cimagf}, @code{cimag} and
925@code{cimagl}, declared in @code{<complex.h>} and also provided as
161d7b59 926built-in functions by GCC@.
c1f7febf 927
4b404517 928@cindex complex conjugation
c1f7febf 929The operator @samp{~} performs complex conjugation when used on a value
4b404517
JM
930with a complex type. This is a GNU extension; for values of
931floating type, you should use the ISO C99 functions @code{conjf},
932@code{conj} and @code{conjl}, declared in @code{<complex.h>} and also
161d7b59 933provided as built-in functions by GCC@.
c1f7febf 934
f0523f02 935GCC can allocate complex automatic variables in a noncontiguous
c1f7febf 936fashion; it's even possible for the real part to be in a register while
bafa88c2
SL
937the imaginary part is on the stack (or vice versa). Only the DWARF 2
938debug info format can represent this, so use of DWARF 2 is recommended.
580fb356
JW
939If you are using the stabs debug info format, GCC describes a noncontiguous
940complex variable as if it were two separate variables of noncomplex type.
c1f7febf
RK
941If the variable's actual name is @code{foo}, the two fictitious
942variables are named @code{foo$real} and @code{foo$imag}. You can
943examine and set these two fictitious variables with your debugger.
944
c77cd3d1
UB
945@node Floating Types
946@section Additional Floating Types
947@cindex additional floating types
948@cindex @code{__float80} data type
949@cindex @code{__float128} data type
950@cindex @code{w} floating point suffix
951@cindex @code{q} floating point suffix
952@cindex @code{W} floating point suffix
953@cindex @code{Q} floating point suffix
954
566fb011 955As an extension, GNU C supports additional floating
6f46cb63
SL
956types, @code{__float80} and @code{__float128} to support 80-bit
957(@code{XFmode}) and 128-bit (@code{TFmode}) floating types.
c77cd3d1
UB
958Support for additional types includes the arithmetic operators:
959add, subtract, multiply, divide; unary arithmetic operators;
960relational operators; equality operators; and conversions to and from
961integer and other floating types. Use a suffix @samp{w} or @samp{W}
962in a literal constant of type @code{__float80} and @samp{q} or @samp{Q}
963for @code{_float128}. You can declare complex types using the
964corresponding internal complex type, @code{XCmode} for @code{__float80}
965type and @code{TCmode} for @code{__float128} type:
966
967@smallexample
968typedef _Complex float __attribute__((mode(TC))) _Complex128;
969typedef _Complex float __attribute__((mode(XC))) _Complex80;
970@end smallexample
971
6f46cb63 972Not all targets support additional floating-point types. @code{__float80}
bafa88c2 973and @code{__float128} types are supported on i386, x86_64 and IA-64 targets.
41a1208a 974The @code{__float128} type is supported on hppa HP-UX targets.
c77cd3d1 975
0fd8c3ad
SL
976@node Half-Precision
977@section Half-Precision Floating Point
978@cindex half-precision floating point
979@cindex @code{__fp16} data type
980
981On ARM targets, GCC supports half-precision (16-bit) floating point via
ff2ce160 982the @code{__fp16} type. You must enable this type explicitly
0fd8c3ad
SL
983with the @option{-mfp16-format} command-line option in order to use it.
984
985ARM supports two incompatible representations for half-precision
986floating-point values. You must choose one of the representations and
987use it consistently in your program.
988
989Specifying @option{-mfp16-format=ieee} selects the IEEE 754-2008 format.
990This format can represent normalized values in the range of @math{2^{-14}} to 65504.
991There are 11 bits of significand precision, approximately 3
992decimal digits.
993
994Specifying @option{-mfp16-format=alternative} selects the ARM
995alternative format. This representation is similar to the IEEE
996format, but does not support infinities or NaNs. Instead, the range
997of exponents is extended, so that this format can represent normalized
998values in the range of @math{2^{-14}} to 131008.
999
1000The @code{__fp16} type is a storage format only. For purposes
1001of arithmetic and other operations, @code{__fp16} values in C or C++
1002expressions are automatically promoted to @code{float}. In addition,
ff2ce160 1003you cannot declare a function with a return value or parameters
0fd8c3ad
SL
1004of type @code{__fp16}.
1005
1006Note that conversions from @code{double} to @code{__fp16}
1007involve an intermediate conversion to @code{float}. Because
1008of rounding, this can sometimes produce a different result than a
1009direct conversion.
1010
ff2ce160 1011ARM provides hardware support for conversions between
0fd8c3ad
SL
1012@code{__fp16} and @code{float} values
1013as an extension to VFP and NEON (Advanced SIMD). GCC generates
e0dc3601 1014code using these hardware instructions if you compile with
ff2ce160 1015options to select an FPU that provides them;
e0dc3601 1016for example, @option{-mfpu=neon-fp16 -mfloat-abi=softfp},
0fd8c3ad 1017in addition to the @option{-mfp16-format} option to select
ff2ce160 1018a half-precision format.
0fd8c3ad
SL
1019
1020Language-level support for the @code{__fp16} data type is
1021independent of whether GCC generates code using hardware floating-point
1022instructions. In cases where hardware support is not specified, GCC
1023implements conversions between @code{__fp16} and @code{float} values
1024as library calls.
1025
9a8ce21f 1026@node Decimal Float
85a92f7e
JJ
1027@section Decimal Floating Types
1028@cindex decimal floating types
9a8ce21f
JG
1029@cindex @code{_Decimal32} data type
1030@cindex @code{_Decimal64} data type
1031@cindex @code{_Decimal128} data type
1032@cindex @code{df} integer suffix
1033@cindex @code{dd} integer suffix
1034@cindex @code{dl} integer suffix
1035@cindex @code{DF} integer suffix
1036@cindex @code{DD} integer suffix
1037@cindex @code{DL} integer suffix
1038
566fb011 1039As an extension, GNU C supports decimal floating types as
853eda8d 1040defined in the N1312 draft of ISO/IEC WDTR24732. Support for decimal
85a92f7e
JJ
1041floating types in GCC will evolve as the draft technical report changes.
1042Calling conventions for any target might also change. Not all targets
1043support decimal floating types.
9a8ce21f 1044
85a92f7e
JJ
1045The decimal floating types are @code{_Decimal32}, @code{_Decimal64}, and
1046@code{_Decimal128}. They use a radix of ten, unlike the floating types
1047@code{float}, @code{double}, and @code{long double} whose radix is not
1048specified by the C standard but is usually two.
1049
1050Support for decimal floating types includes the arithmetic operators
9a8ce21f
JG
1051add, subtract, multiply, divide; unary arithmetic operators;
1052relational operators; equality operators; and conversions to and from
85a92f7e 1053integer and other floating types. Use a suffix @samp{df} or
9a8ce21f
JG
1054@samp{DF} in a literal constant of type @code{_Decimal32}, @samp{dd}
1055or @samp{DD} for @code{_Decimal64}, and @samp{dl} or @samp{DL} for
1056@code{_Decimal128}.
1057
85a92f7e
JJ
1058GCC support of decimal float as specified by the draft technical report
1059is incomplete:
1060
1061@itemize @bullet
85a92f7e
JJ
1062@item
1063When the value of a decimal floating type cannot be represented in the
1064integer type to which it is being converted, the result is undefined
1065rather than the result value specified by the draft technical report.
853eda8d
JJ
1066
1067@item
1068GCC does not provide the C library functionality associated with
1069@file{math.h}, @file{fenv.h}, @file{stdio.h}, @file{stdlib.h}, and
1070@file{wchar.h}, which must come from a separate C library implementation.
1071Because of this the GNU C compiler does not define macro
1072@code{__STDC_DEC_FP__} to indicate that the implementation conforms to
1073the technical report.
85a92f7e 1074@end itemize
9a8ce21f
JG
1075
1076Types @code{_Decimal32}, @code{_Decimal64}, and @code{_Decimal128}
bafa88c2 1077are supported by the DWARF 2 debug information format.
9a8ce21f 1078
6f4d7222 1079@node Hex Floats
6b42b9ea
UD
1080@section Hex Floats
1081@cindex hex floats
c5c76735 1082
4b404517 1083ISO C99 supports floating-point numbers written not only in the usual
6f4d7222 1084decimal notation, such as @code{1.55e1}, but also numbers such as
4b404517 1085@code{0x1.fp3} written in hexadecimal format. As a GNU extension, GCC
7e1542b9 1086supports this in C90 mode (except in some cases when strictly
4b404517 1087conforming) and in C++. In that format the
84330467 1088@samp{0x} hex introducer and the @samp{p} or @samp{P} exponent field are
6f4d7222 1089mandatory. The exponent is a decimal number that indicates the power of
358a3dbc 10902 by which the significant part is multiplied. Thus @samp{0x1.f} is
aee96fe9
JM
1091@tex
1092$1 {15\over16}$,
1093@end tex
1094@ifnottex
10951 15/16,
1096@end ifnottex
1097@samp{p3} multiplies it by 8, and the value of @code{0x1.fp3}
6f4d7222
UD
1098is the same as @code{1.55e1}.
1099
1100Unlike for floating-point numbers in the decimal notation the exponent
1101is always required in the hexadecimal notation. Otherwise the compiler
1102would not be able to resolve the ambiguity of, e.g., @code{0x1.f}. This
84330467 1103could mean @code{1.0f} or @code{1.9375} since @samp{f} is also the
6f4d7222
UD
1104extension for floating-point constants of type @code{float}.
1105
0f996086
CF
1106@node Fixed-Point
1107@section Fixed-Point Types
1108@cindex fixed-point types
1109@cindex @code{_Fract} data type
1110@cindex @code{_Accum} data type
1111@cindex @code{_Sat} data type
1112@cindex @code{hr} fixed-suffix
1113@cindex @code{r} fixed-suffix
1114@cindex @code{lr} fixed-suffix
1115@cindex @code{llr} fixed-suffix
1116@cindex @code{uhr} fixed-suffix
1117@cindex @code{ur} fixed-suffix
1118@cindex @code{ulr} fixed-suffix
1119@cindex @code{ullr} fixed-suffix
1120@cindex @code{hk} fixed-suffix
1121@cindex @code{k} fixed-suffix
1122@cindex @code{lk} fixed-suffix
1123@cindex @code{llk} fixed-suffix
1124@cindex @code{uhk} fixed-suffix
1125@cindex @code{uk} fixed-suffix
1126@cindex @code{ulk} fixed-suffix
1127@cindex @code{ullk} fixed-suffix
1128@cindex @code{HR} fixed-suffix
1129@cindex @code{R} fixed-suffix
1130@cindex @code{LR} fixed-suffix
1131@cindex @code{LLR} fixed-suffix
1132@cindex @code{UHR} fixed-suffix
1133@cindex @code{UR} fixed-suffix
1134@cindex @code{ULR} fixed-suffix
1135@cindex @code{ULLR} fixed-suffix
1136@cindex @code{HK} fixed-suffix
1137@cindex @code{K} fixed-suffix
1138@cindex @code{LK} fixed-suffix
1139@cindex @code{LLK} fixed-suffix
1140@cindex @code{UHK} fixed-suffix
1141@cindex @code{UK} fixed-suffix
1142@cindex @code{ULK} fixed-suffix
1143@cindex @code{ULLK} fixed-suffix
1144
566fb011 1145As an extension, GNU C supports fixed-point types as
0f996086
CF
1146defined in the N1169 draft of ISO/IEC DTR 18037. Support for fixed-point
1147types in GCC will evolve as the draft technical report changes.
1148Calling conventions for any target might also change. Not all targets
1149support fixed-point types.
1150
1151The fixed-point types are
1152@code{short _Fract},
1153@code{_Fract},
1154@code{long _Fract},
1155@code{long long _Fract},
1156@code{unsigned short _Fract},
1157@code{unsigned _Fract},
1158@code{unsigned long _Fract},
1159@code{unsigned long long _Fract},
1160@code{_Sat short _Fract},
1161@code{_Sat _Fract},
1162@code{_Sat long _Fract},
1163@code{_Sat long long _Fract},
1164@code{_Sat unsigned short _Fract},
1165@code{_Sat unsigned _Fract},
1166@code{_Sat unsigned long _Fract},
1167@code{_Sat unsigned long long _Fract},
1168@code{short _Accum},
1169@code{_Accum},
1170@code{long _Accum},
1171@code{long long _Accum},
1172@code{unsigned short _Accum},
1173@code{unsigned _Accum},
1174@code{unsigned long _Accum},
1175@code{unsigned long long _Accum},
1176@code{_Sat short _Accum},
1177@code{_Sat _Accum},
1178@code{_Sat long _Accum},
1179@code{_Sat long long _Accum},
1180@code{_Sat unsigned short _Accum},
1181@code{_Sat unsigned _Accum},
1182@code{_Sat unsigned long _Accum},
1183@code{_Sat unsigned long long _Accum}.
8fd94bda 1184
0f996086
CF
1185Fixed-point data values contain fractional and optional integral parts.
1186The format of fixed-point data varies and depends on the target machine.
1187
8fd94bda
JJ
1188Support for fixed-point types includes:
1189@itemize @bullet
1190@item
1191prefix and postfix increment and decrement operators (@code{++}, @code{--})
1192@item
1193unary arithmetic operators (@code{+}, @code{-}, @code{!})
1194@item
1195binary arithmetic operators (@code{+}, @code{-}, @code{*}, @code{/})
1196@item
1197binary shift operators (@code{<<}, @code{>>})
1198@item
1199relational operators (@code{<}, @code{<=}, @code{>=}, @code{>})
1200@item
1201equality operators (@code{==}, @code{!=})
1202@item
1203assignment operators (@code{+=}, @code{-=}, @code{*=}, @code{/=},
1204@code{<<=}, @code{>>=})
1205@item
1206conversions to and from integer, floating-point, or fixed-point types
1207@end itemize
1208
1209Use a suffix in a fixed-point literal constant:
1210@itemize
1211@item @samp{hr} or @samp{HR} for @code{short _Fract} and
1212@code{_Sat short _Fract}
1213@item @samp{r} or @samp{R} for @code{_Fract} and @code{_Sat _Fract}
1214@item @samp{lr} or @samp{LR} for @code{long _Fract} and
1215@code{_Sat long _Fract}
1216@item @samp{llr} or @samp{LLR} for @code{long long _Fract} and
1217@code{_Sat long long _Fract}
1218@item @samp{uhr} or @samp{UHR} for @code{unsigned short _Fract} and
1219@code{_Sat unsigned short _Fract}
1220@item @samp{ur} or @samp{UR} for @code{unsigned _Fract} and
1221@code{_Sat unsigned _Fract}
1222@item @samp{ulr} or @samp{ULR} for @code{unsigned long _Fract} and
1223@code{_Sat unsigned long _Fract}
1224@item @samp{ullr} or @samp{ULLR} for @code{unsigned long long _Fract}
1225and @code{_Sat unsigned long long _Fract}
1226@item @samp{hk} or @samp{HK} for @code{short _Accum} and
1227@code{_Sat short _Accum}
1228@item @samp{k} or @samp{K} for @code{_Accum} and @code{_Sat _Accum}
1229@item @samp{lk} or @samp{LK} for @code{long _Accum} and
1230@code{_Sat long _Accum}
1231@item @samp{llk} or @samp{LLK} for @code{long long _Accum} and
1232@code{_Sat long long _Accum}
1233@item @samp{uhk} or @samp{UHK} for @code{unsigned short _Accum} and
1234@code{_Sat unsigned short _Accum}
1235@item @samp{uk} or @samp{UK} for @code{unsigned _Accum} and
1236@code{_Sat unsigned _Accum}
1237@item @samp{ulk} or @samp{ULK} for @code{unsigned long _Accum} and
1238@code{_Sat unsigned long _Accum}
1239@item @samp{ullk} or @samp{ULLK} for @code{unsigned long long _Accum}
1240and @code{_Sat unsigned long long _Accum}
1241@end itemize
0f996086
CF
1242
1243GCC support of fixed-point types as specified by the draft technical report
1244is incomplete:
1245
1246@itemize @bullet
1247@item
1248Pragmas to control overflow and rounding behaviors are not implemented.
1249@end itemize
1250
bafa88c2 1251Fixed-point types are supported by the DWARF 2 debug information format.
0f996086 1252
09e881c9 1253@node Named Address Spaces
542bf446
GJL
1254@section Named Address Spaces
1255@cindex Named Address Spaces
09e881c9 1256
566fb011 1257As an extension, GNU C supports named address spaces as
09e881c9 1258defined in the N1275 draft of ISO/IEC DTR 18037. Support for named
85b8555e
DD
1259address spaces in GCC will evolve as the draft technical report
1260changes. Calling conventions for any target might also change. At
542bf446
GJL
1261present, only the AVR, SPU, M32C, and RL78 targets support address
1262spaces other than the generic address space.
1263
1264Address space identifiers may be used exactly like any other C type
1265qualifier (e.g., @code{const} or @code{volatile}). See the N1275
1266document for more details.
1267
1268@anchor{AVR Named Address Spaces}
1269@subsection AVR Named Address Spaces
1270
1271On the AVR target, there are several address spaces that can be used
1272in order to put read-only data into the flash memory and access that
1273data by means of the special instructions @code{LPM} or @code{ELPM}
1274needed to read from flash.
1275
aa9ec4db
GJL
1276Per default, any data including read-only data is located in RAM
1277(the generic address space) so that non-generic address spaces are
1278needed to locate read-only data in flash memory
1279@emph{and} to generate the right instructions to access this data
542bf446
GJL
1280without using (inline) assembler code.
1281
1282@table @code
3a840863
GJL
1283@item __flash
1284@cindex @code{__flash} AVR Named Address Spaces
358a3dbc
SL
1285The @code{__flash} qualifier locates data in the
1286@code{.progmem.data} section. Data is read using the @code{LPM}
542bf446
GJL
1287instruction. Pointers to this address space are 16 bits wide.
1288
3a840863 1289@item __flash1
f457c50c
AS
1290@itemx __flash2
1291@itemx __flash3
1292@itemx __flash4
1293@itemx __flash5
3a840863
GJL
1294@cindex @code{__flash1} AVR Named Address Spaces
1295@cindex @code{__flash2} AVR Named Address Spaces
1296@cindex @code{__flash3} AVR Named Address Spaces
1297@cindex @code{__flash4} AVR Named Address Spaces
1298@cindex @code{__flash5} AVR Named Address Spaces
542bf446
GJL
1299These are 16-bit address spaces locating data in section
1300@code{.progmem@var{N}.data} where @var{N} refers to
3a840863 1301address space @code{__flash@var{N}}.
358a3dbc 1302The compiler sets the @code{RAMPZ} segment register appropriately
542bf446
GJL
1303before reading data by means of the @code{ELPM} instruction.
1304
3a840863
GJL
1305@item __memx
1306@cindex @code{__memx} AVR Named Address Spaces
542bf446
GJL
1307This is a 24-bit address space that linearizes flash and RAM:
1308If the high bit of the address is set, data is read from
1309RAM using the lower two bytes as RAM address.
1310If the high bit of the address is clear, data is read from flash
1311with @code{RAMPZ} set according to the high byte of the address.
5bb53d1a 1312@xref{AVR Built-in Functions,,@code{__builtin_avr_flash_segment}}.
542bf446 1313
35678514 1314Objects in this address space are located in @code{.progmemx.data}.
542bf446
GJL
1315@end table
1316
aa9ec4db
GJL
1317@b{Example}
1318
c513ecbf 1319@smallexample
3a840863 1320char my_read (const __flash char ** p)
aa9ec4db
GJL
1321@{
1322 /* p is a pointer to RAM that points to a pointer to flash.
358a3dbc 1323 The first indirection of p reads that flash pointer
aa9ec4db
GJL
1324 from RAM and the second indirection reads a char from this
1325 flash address. */
1326
1327 return **p;
1328@}
1329
1330/* Locate array[] in flash memory */
3a840863 1331const __flash int array[] = @{ 3, 5, 7, 11, 13, 17, 19 @};
aa9ec4db
GJL
1332
1333int i = 1;
1334
1335int main (void)
1336@{
1337 /* Return 17 by reading from flash memory */
1338 return array[array[i]];
1339@}
c513ecbf 1340@end smallexample
aa9ec4db 1341
5bb53d1a 1342@noindent
542bf446
GJL
1343For each named address space supported by avr-gcc there is an equally
1344named but uppercase built-in macro defined.
1345The purpose is to facilitate testing if respective address space
1346support is available or not:
1347
c513ecbf 1348@smallexample
3a840863
GJL
1349#ifdef __FLASH
1350const __flash int var = 1;
542bf446 1351
da4343c3 1352int read_var (void)
542bf446 1353@{
da4343c3 1354 return var;
542bf446
GJL
1355@}
1356#else
da4343c3 1357#include <avr/pgmspace.h> /* From AVR-LibC */
542bf446
GJL
1358
1359const int var PROGMEM = 1;
1360
da4343c3 1361int read_var (void)
542bf446 1362@{
da4343c3 1363 return (int) pgm_read_word (&var);
542bf446 1364@}
3a840863 1365#endif /* __FLASH */
c513ecbf 1366@end smallexample
542bf446 1367
5bb53d1a
GJL
1368@noindent
1369Notice that attribute @ref{AVR Variable Attributes,,@code{progmem}}
542bf446 1370locates data in flash but
358a3dbc 1371accesses to these data read from generic address space, i.e.@:
aa9ec4db
GJL
1372from RAM,
1373so that you need special accessors like @code{pgm_read_byte}
53cb97f9 1374from @w{@uref{http://nongnu.org/avr-libc/user-manual/,AVR-LibC}}
da4343c3 1375together with attribute @code{progmem}.
542bf446 1376
5bb53d1a 1377@noindent
542bf446
GJL
1378@b{Limitations and caveats}
1379
1380@itemize
1381@item
1382Reading across the 64@tie{}KiB section boundary of
3a840863 1383the @code{__flash} or @code{__flash@var{N}} address spaces
566fb011 1384shows undefined behavior. The only address space that
542bf446 1385supports reading across the 64@tie{}KiB flash segment boundaries is
3a840863 1386@code{__memx}.
542bf446
GJL
1387
1388@item
da4343c3 1389If you use one of the @code{__flash@var{N}} address spaces
358a3dbc 1390you must arrange your linker script to locate the
542bf446
GJL
1391@code{.progmem@var{N}.data} sections according to your needs.
1392
1393@item
aa9ec4db
GJL
1394Any data or pointers to the non-generic address spaces must
1395be qualified as @code{const}, i.e.@: as read-only data.
542bf446 1396This still applies if the data in one of these address
aa9ec4db 1397spaces like software version number or calibration lookup table are intended to
542bf446
GJL
1398be changed after load time by, say, a boot loader. In this case
1399the right qualification is @code{const} @code{volatile} so that the compiler
1400must not optimize away known values or insert them
1401as immediates into operands of instructions.
1402
1403@item
5bb53d1a
GJL
1404The following code initializes a variable @code{pfoo}
1405located in static storage with a 24-bit address:
c513ecbf 1406@smallexample
3a840863
GJL
1407extern const __memx char foo;
1408const __memx void *pfoo = &foo;
c513ecbf
SL
1409@end smallexample
1410
1411@noindent
5bb53d1a
GJL
1412Such code requires at least binutils 2.23, see
1413@w{@uref{http://sourceware.org/PR13503,PR13503}}.
542bf446 1414
542bf446
GJL
1415@end itemize
1416
542bf446
GJL
1417@subsection M32C Named Address Spaces
1418@cindex @code{__far} M32C Named Address Spaces
1419
bafa88c2 1420On the M32C target, with the R8C and M16C CPU variants, variables
542bf446
GJL
1421qualified with @code{__far} are accessed using 32-bit addresses in
1422order to access memory beyond the first 64@tie{}Ki bytes. If
bafa88c2 1423@code{__far} is used with the M32CM or M32C CPU variants, it has no
542bf446
GJL
1424effect.
1425
1426@subsection RL78 Named Address Spaces
1427@cindex @code{__far} RL78 Named Address Spaces
1428
1429On the RL78 target, variables qualified with @code{__far} are accessed
1430with 32-bit pointers (20-bit addresses) rather than the default 16-bit
1431addresses. Non-far variables are assumed to appear in the topmost
143264@tie{}KiB of the address space.
1433
1434@subsection SPU Named Address Spaces
1435@cindex @code{__ea} SPU Named Address Spaces
1436
1437On the SPU target variables may be declared as
85b8555e
DD
1438belonging to another address space by qualifying the type with the
1439@code{__ea} address space identifier:
09e881c9
BE
1440
1441@smallexample
1442extern int __ea i;
1443@end smallexample
1444
c513ecbf 1445@noindent
358a3dbc
SL
1446The compiler generates special code to access the variable @code{i}.
1447It may use runtime library
09e881c9
BE
1448support, or generate special machine instructions to access that address
1449space.
1450
c1f7febf
RK
1451@node Zero Length
1452@section Arrays of Length Zero
1453@cindex arrays of length zero
1454@cindex zero-length arrays
1455@cindex length-zero arrays
ffc5c6a9 1456@cindex flexible array members
c1f7febf 1457
161d7b59 1458Zero-length arrays are allowed in GNU C@. They are very useful as the
c417597c 1459last element of a structure that is really a header for a variable-length
c1f7febf
RK
1460object:
1461
3ab51846 1462@smallexample
c1f7febf
RK
1463struct line @{
1464 int length;
1465 char contents[0];
1466@};
1467
584ef5fe
RH
1468struct line *thisline = (struct line *)
1469 malloc (sizeof (struct line) + this_length);
1470thisline->length = this_length;
3ab51846 1471@end smallexample
c1f7febf 1472
3764f879 1473In ISO C90, you would have to give @code{contents} a length of 1, which
c1f7febf
RK
1474means either you waste space or complicate the argument to @code{malloc}.
1475
02f52e19 1476In ISO C99, you would use a @dfn{flexible array member}, which is
584ef5fe
RH
1477slightly different in syntax and semantics:
1478
1479@itemize @bullet
1480@item
1481Flexible array members are written as @code{contents[]} without
1482the @code{0}.
1483
1484@item
1485Flexible array members have incomplete type, and so the @code{sizeof}
1486operator may not be applied. As a quirk of the original implementation
1487of zero-length arrays, @code{sizeof} evaluates to zero.
1488
1489@item
1490Flexible array members may only appear as the last member of a
e7b6a0ee 1491@code{struct} that is otherwise non-empty.
2984fe64
JM
1492
1493@item
1494A structure containing a flexible array member, or a union containing
1495such a structure (possibly recursively), may not be a member of a
1496structure or an element of an array. (However, these uses are
1497permitted by GCC as extensions.)
ffc5c6a9 1498@end itemize
a25f1211 1499
ffc5c6a9 1500GCC versions before 3.0 allowed zero-length arrays to be statically
e7b6a0ee
DD
1501initialized, as if they were flexible arrays. In addition to those
1502cases that were useful, it also allowed initializations in situations
1503that would corrupt later data. Non-empty initialization of zero-length
1504arrays is now treated like any case where there are more initializer
566fb011
SL
1505elements than the array holds, in that a suitable warning about ``excess
1506elements in array'' is given, and the excess elements (all of them, in
e7b6a0ee 1507this case) are ignored.
ffc5c6a9
RH
1508
1509Instead GCC allows static initialization of flexible array members.
1510This is equivalent to defining a new structure containing the original
1511structure followed by an array of sufficient size to contain the data.
566fb011 1512E.g.@: in the following, @code{f1} is constructed as if it were declared
ffc5c6a9 1513like @code{f2}.
a25f1211 1514
3ab51846 1515@smallexample
ffc5c6a9
RH
1516struct f1 @{
1517 int x; int y[];
1518@} f1 = @{ 1, @{ 2, 3, 4 @} @};
1519
1520struct f2 @{
1521 struct f1 f1; int data[3];
1522@} f2 = @{ @{ 1 @}, @{ 2, 3, 4 @} @};
3ab51846 1523@end smallexample
584ef5fe 1524
ffc5c6a9
RH
1525@noindent
1526The convenience of this extension is that @code{f1} has the desired
1527type, eliminating the need to consistently refer to @code{f2.f1}.
1528
1529This has symmetry with normal static arrays, in that an array of
1530unknown size is also written with @code{[]}.
a25f1211 1531
ffc5c6a9
RH
1532Of course, this extension only makes sense if the extra data comes at
1533the end of a top-level object, as otherwise we would be overwriting
1534data at subsequent offsets. To avoid undue complication and confusion
1535with initialization of deeply nested arrays, we simply disallow any
1536non-empty initialization except when the structure is the top-level
1537object. For example:
584ef5fe 1538
3ab51846 1539@smallexample
ffc5c6a9
RH
1540struct foo @{ int x; int y[]; @};
1541struct bar @{ struct foo z; @};
1542
13ba36b4
JM
1543struct foo a = @{ 1, @{ 2, 3, 4 @} @}; // @r{Valid.}
1544struct bar b = @{ @{ 1, @{ 2, 3, 4 @} @} @}; // @r{Invalid.}
1545struct bar c = @{ @{ 1, @{ @} @} @}; // @r{Valid.}
1546struct foo d[1] = @{ @{ 1 @{ 2, 3, 4 @} @} @}; // @r{Invalid.}
3ab51846 1547@end smallexample
4b606faf 1548
ba05abd3
GK
1549@node Empty Structures
1550@section Structures With No Members
1551@cindex empty structures
1552@cindex zero-size structures
1553
1554GCC permits a C structure to have no members:
1555
3ab51846 1556@smallexample
ba05abd3
GK
1557struct empty @{
1558@};
3ab51846 1559@end smallexample
ba05abd3 1560
358a3dbc 1561The structure has size zero. In C++, empty structures are part
db0b376e
MM
1562of the language. G++ treats empty structures as if they had a single
1563member of type @code{char}.
ba05abd3 1564
c1f7febf
RK
1565@node Variable Length
1566@section Arrays of Variable Length
1567@cindex variable-length arrays
1568@cindex arrays of variable length
4b404517 1569@cindex VLAs
c1f7febf 1570
4b404517 1571Variable-length automatic arrays are allowed in ISO C99, and as an
fbdaa0b2 1572extension GCC accepts them in C90 mode and in C++. These arrays are
c1f7febf
RK
1573declared like any other automatic arrays, but with a length that is not
1574a constant expression. The storage is allocated at the point of
bafa88c2
SL
1575declaration and deallocated when the block scope containing the declaration
1576exits. For
c1f7febf
RK
1577example:
1578
3ab51846 1579@smallexample
c1f7febf
RK
1580FILE *
1581concat_fopen (char *s1, char *s2, char *mode)
1582@{
1583 char str[strlen (s1) + strlen (s2) + 1];
1584 strcpy (str, s1);
1585 strcat (str, s2);
1586 return fopen (str, mode);
1587@}
3ab51846 1588@end smallexample
c1f7febf
RK
1589
1590@cindex scope of a variable length array
1591@cindex variable-length array scope
1592@cindex deallocating variable length arrays
1593Jumping or breaking out of the scope of the array name deallocates the
1594storage. Jumping into the scope is not allowed; you get an error
1595message for it.
1596
d615d763
MP
1597@cindex variable-length array in a structure
1598As an extension, GCC accepts variable-length arrays as a member of
1599a structure or a union. For example:
1600
1601@smallexample
1602void
1603foo (int n)
1604@{
1605 struct S @{ int x[n]; @};
1606@}
1607@end smallexample
1608
c1f7febf
RK
1609@cindex @code{alloca} vs variable-length arrays
1610You can use the function @code{alloca} to get an effect much like
1611variable-length arrays. The function @code{alloca} is available in
1612many other C implementations (but not in all). On the other hand,
1613variable-length arrays are more elegant.
1614
1615There are other differences between these two methods. Space allocated
1616with @code{alloca} exists until the containing @emph{function} returns.
1617The space for a variable-length array is deallocated as soon as the array
1618name's scope ends. (If you use both variable-length arrays and
1619@code{alloca} in the same function, deallocation of a variable-length array
358a3dbc 1620also deallocates anything more recently allocated with @code{alloca}.)
c1f7febf
RK
1621
1622You can also use variable-length arrays as arguments to functions:
1623
3ab51846 1624@smallexample
c1f7febf
RK
1625struct entry
1626tester (int len, char data[len][len])
1627@{
0d893a63 1628 /* @r{@dots{}} */
c1f7febf 1629@}
3ab51846 1630@end smallexample
c1f7febf
RK
1631
1632The length of an array is computed once when the storage is allocated
1633and is remembered for the scope of the array in case you access it with
1634@code{sizeof}.
1635
1636If you want to pass the array first and the length afterward, you can
1637use a forward declaration in the parameter list---another GNU extension.
1638
3ab51846 1639@smallexample
c1f7febf
RK
1640struct entry
1641tester (int len; char data[len][len], int len)
1642@{
0d893a63 1643 /* @r{@dots{}} */
c1f7febf 1644@}
3ab51846 1645@end smallexample
c1f7febf
RK
1646
1647@cindex parameter forward declaration
1648The @samp{int len} before the semicolon is a @dfn{parameter forward
1649declaration}, and it serves the purpose of making the name @code{len}
1650known when the declaration of @code{data} is parsed.
1651
1652You can write any number of such parameter forward declarations in the
1653parameter list. They can be separated by commas or semicolons, but the
1654last one must end with a semicolon, which is followed by the ``real''
1655parameter declarations. Each forward declaration must match a ``real''
4b404517
JM
1656declaration in parameter name and data type. ISO C99 does not support
1657parameter forward declarations.
c1f7febf 1658
ccd96f0a
NB
1659@node Variadic Macros
1660@section Macros with a Variable Number of Arguments.
c1f7febf
RK
1661@cindex variable number of arguments
1662@cindex macro with variable arguments
1663@cindex rest argument (in macro)
ccd96f0a 1664@cindex variadic macros
c1f7febf 1665
ccd96f0a
NB
1666In the ISO C standard of 1999, a macro can be declared to accept a
1667variable number of arguments much as a function can. The syntax for
1668defining the macro is similar to that of a function. Here is an
1669example:
c1f7febf 1670
478c9e72 1671@smallexample
ccd96f0a 1672#define debug(format, ...) fprintf (stderr, format, __VA_ARGS__)
478c9e72 1673@end smallexample
c1f7febf 1674
c513ecbf 1675@noindent
ccd96f0a
NB
1676Here @samp{@dots{}} is a @dfn{variable argument}. In the invocation of
1677such a macro, it represents the zero or more tokens until the closing
1678parenthesis that ends the invocation, including any commas. This set of
1679tokens replaces the identifier @code{__VA_ARGS__} in the macro body
1680wherever it appears. See the CPP manual for more information.
1681
1682GCC has long supported variadic macros, and used a different syntax that
1683allowed you to give a name to the variable arguments just like any other
1684argument. Here is an example:
c1f7febf 1685
3ab51846 1686@smallexample
ccd96f0a 1687#define debug(format, args...) fprintf (stderr, format, args)
3ab51846 1688@end smallexample
c1f7febf 1689
c513ecbf 1690@noindent
ccd96f0a
NB
1691This is in all ways equivalent to the ISO C example above, but arguably
1692more readable and descriptive.
c1f7febf 1693
ccd96f0a
NB
1694GNU CPP has two further variadic macro extensions, and permits them to
1695be used with either of the above forms of macro definition.
1696
1697In standard C, you are not allowed to leave the variable argument out
1698entirely; but you are allowed to pass an empty argument. For example,
1699this invocation is invalid in ISO C, because there is no comma after
1700the string:
c1f7febf 1701
3ab51846 1702@smallexample
ccd96f0a 1703debug ("A message")
3ab51846 1704@end smallexample
c1f7febf 1705
ccd96f0a
NB
1706GNU CPP permits you to completely omit the variable arguments in this
1707way. In the above examples, the compiler would complain, though since
1708the expansion of the macro still has the extra comma after the format
1709string.
1710
1711To help solve this problem, CPP behaves specially for variable arguments
1712used with the token paste operator, @samp{##}. If instead you write
c1f7febf 1713
478c9e72 1714@smallexample
ccd96f0a 1715#define debug(format, ...) fprintf (stderr, format, ## __VA_ARGS__)
478c9e72 1716@end smallexample
c1f7febf 1717
c513ecbf 1718@noindent
ccd96f0a
NB
1719and if the variable arguments are omitted or empty, the @samp{##}
1720operator causes the preprocessor to remove the comma before it. If you
1721do provide some variable arguments in your macro invocation, GNU CPP
1722does not complain about the paste operation and instead places the
1723variable arguments after the comma. Just like any other pasted macro
1724argument, these arguments are not macro expanded.
1725
1726@node Escaped Newlines
1727@section Slightly Looser Rules for Escaped Newlines
1728@cindex escaped newlines
1729@cindex newlines (escaped)
1730
f458d1d5
ZW
1731Recently, the preprocessor has relaxed its treatment of escaped
1732newlines. Previously, the newline had to immediately follow a
e6cc3a24
ZW
1733backslash. The current implementation allows whitespace in the form
1734of spaces, horizontal and vertical tabs, and form feeds between the
ccd96f0a
NB
1735backslash and the subsequent newline. The preprocessor issues a
1736warning, but treats it as a valid escaped newline and combines the two
1737lines to form a single logical line. This works within comments and
e6cc3a24
ZW
1738tokens, as well as between tokens. Comments are @emph{not} treated as
1739whitespace for the purposes of this relaxation, since they have not
1740yet been replaced with spaces.
c1f7febf
RK
1741
1742@node Subscripting
1743@section Non-Lvalue Arrays May Have Subscripts
1744@cindex subscripting
1745@cindex arrays, non-lvalue
1746
1747@cindex subscripting and function values
207bf485
JM
1748In ISO C99, arrays that are not lvalues still decay to pointers, and
1749may be subscripted, although they may not be modified or used after
1750the next sequence point and the unary @samp{&} operator may not be
566fb011 1751applied to them. As an extension, GNU C allows such arrays to be
7e1542b9 1752subscripted in C90 mode, though otherwise they do not decay to
207bf485 1753pointers outside C99 mode. For example,
7e1542b9 1754this is valid in GNU C though not valid in C90:
c1f7febf 1755
3ab51846 1756@smallexample
c1f7febf
RK
1757@group
1758struct foo @{int a[4];@};
1759
1760struct foo f();
1761
1762bar (int index)
1763@{
1764 return f().a[index];
1765@}
1766@end group
3ab51846 1767@end smallexample
c1f7febf
RK
1768
1769@node Pointer Arith
1770@section Arithmetic on @code{void}- and Function-Pointers
1771@cindex void pointers, arithmetic
1772@cindex void, size of pointer to
1773@cindex function pointers, arithmetic
1774@cindex function, size of pointer to
1775
1776In GNU C, addition and subtraction operations are supported on pointers to
1777@code{void} and on pointers to functions. This is done by treating the
1778size of a @code{void} or of a function as 1.
1779
1780A consequence of this is that @code{sizeof} is also allowed on @code{void}
1781and on function types, and returns 1.
1782
84330467
JM
1783@opindex Wpointer-arith
1784The option @option{-Wpointer-arith} requests a warning if these extensions
c1f7febf
RK
1785are used.
1786
1787@node Initializers
1788@section Non-Constant Initializers
1789@cindex initializers, non-constant
1790@cindex non-constant initializers
1791
4b404517 1792As in standard C++ and ISO C99, the elements of an aggregate initializer for an
161d7b59 1793automatic variable are not required to be constant expressions in GNU C@.
c1f7febf
RK
1794Here is an example of an initializer with run-time varying elements:
1795
3ab51846 1796@smallexample
c1f7febf
RK
1797foo (float f, float g)
1798@{
1799 float beat_freqs[2] = @{ f-g, f+g @};
0d893a63 1800 /* @r{@dots{}} */
c1f7febf 1801@}
3ab51846 1802@end smallexample
c1f7febf 1803
4b404517
JM
1804@node Compound Literals
1805@section Compound Literals
c1f7febf
RK
1806@cindex constructor expressions
1807@cindex initializations in expressions
1808@cindex structures, constructor expression
1809@cindex expressions, constructor
4b404517
JM
1810@cindex compound literals
1811@c The GNU C name for what C99 calls compound literals was "constructor expressions".
c1f7febf 1812
4b404517 1813ISO C99 supports compound literals. A compound literal looks like
c1f7febf
RK
1814a cast containing an initializer. Its value is an object of the
1815type specified in the cast, containing the elements specified in
db3acfa5 1816the initializer; it is an lvalue. As an extension, GCC supports
1f37c583
JM
1817compound literals in C90 mode and in C++, though the semantics are
1818somewhat different in C++.
c1f7febf
RK
1819
1820Usually, the specified type is a structure. Assume that
1821@code{struct foo} and @code{structure} are declared as shown:
1822
3ab51846 1823@smallexample
c1f7febf 1824struct foo @{int a; char b[2];@} structure;
3ab51846 1825@end smallexample
c1f7febf
RK
1826
1827@noindent
4b404517 1828Here is an example of constructing a @code{struct foo} with a compound literal:
c1f7febf 1829
3ab51846 1830@smallexample
c1f7febf 1831structure = ((struct foo) @{x + y, 'a', 0@});
3ab51846 1832@end smallexample
c1f7febf
RK
1833
1834@noindent
1835This is equivalent to writing the following:
1836
3ab51846 1837@smallexample
c1f7febf
RK
1838@{
1839 struct foo temp = @{x + y, 'a', 0@};
1840 structure = temp;
1841@}
3ab51846 1842@end smallexample
c1f7febf 1843
1f37c583
JM
1844You can also construct an array, though this is dangerous in C++, as
1845explained below. If all the elements of the compound literal are
1846(made up of) simple constant expressions, suitable for use in
db3acfa5
JM
1847initializers of objects of static storage duration, then the compound
1848literal can be coerced to a pointer to its first element and used in
1849such an initializer, as shown here:
c1f7febf 1850
3ab51846 1851@smallexample
c1f7febf 1852char **foo = (char *[]) @{ "x", "y", "z" @};
3ab51846 1853@end smallexample
c1f7febf 1854
49d6830d 1855Compound literals for scalar types and union types are
4b404517 1856also allowed, but then the compound literal is equivalent
c1f7febf
RK
1857to a cast.
1858
59c83dbf
JJ
1859As a GNU extension, GCC allows initialization of objects with static storage
1860duration by compound literals (which is not possible in ISO C99, because
1861the initializer is not a constant).
358a3dbc 1862It is handled as if the object is initialized only with the bracket
1eaf20ec 1863enclosed list if the types of the compound literal and the object match.
59c83dbf
JJ
1864The initializer list of the compound literal must be constant.
1865If the object being initialized has array type of unknown size, the size is
ad47f1e5 1866determined by compound literal size.
59c83dbf 1867
3ab51846 1868@smallexample
59c83dbf
JJ
1869static struct foo x = (struct foo) @{1, 'a', 'b'@};
1870static int y[] = (int []) @{1, 2, 3@};
1871static int z[] = (int [3]) @{1@};
3ab51846 1872@end smallexample
59c83dbf
JJ
1873
1874@noindent
1875The above lines are equivalent to the following:
3ab51846 1876@smallexample
59c83dbf
JJ
1877static struct foo x = @{1, 'a', 'b'@};
1878static int y[] = @{1, 2, 3@};
ad47f1e5 1879static int z[] = @{1, 0, 0@};
3ab51846 1880@end smallexample
59c83dbf 1881
1f37c583
JM
1882In C, a compound literal designates an unnamed object with static or
1883automatic storage duration. In C++, a compound literal designates a
1884temporary object, which only lives until the end of its
1885full-expression. As a result, well-defined C code that takes the
1886address of a subobject of a compound literal can be undefined in C++.
1887For instance, if the array compound literal example above appeared
1888inside a function, any subsequent use of @samp{foo} in C++ has
1889undefined behavior because the lifetime of the array ends after the
1890declaration of @samp{foo}. As a result, the C++ compiler now rejects
1891the conversion of a temporary array to a pointer.
1892
1893As an optimization, the C++ compiler sometimes gives array compound
1894literals longer lifetimes: when the array either appears outside a
1895function or has const-qualified type. If @samp{foo} and its
1896initializer had elements of @samp{char *const} type rather than
1897@samp{char *}, or if @samp{foo} were a global variable, the array
1898would have static storage duration. But it is probably safest just to
1899avoid the use of array compound literals in code compiled as C++.
1900
4b404517
JM
1901@node Designated Inits
1902@section Designated Initializers
c1f7febf
RK
1903@cindex initializers with labeled elements
1904@cindex labeled elements in initializers
1905@cindex case labels in initializers
4b404517 1906@cindex designated initializers
c1f7febf 1907
7e1542b9 1908Standard C90 requires the elements of an initializer to appear in a fixed
c1f7febf
RK
1909order, the same as the order of the elements in the array or structure
1910being initialized.
1911
26d4fec7
JM
1912In ISO C99 you can give the elements in any order, specifying the array
1913indices or structure field names they apply to, and GNU C allows this as
7e1542b9 1914an extension in C90 mode as well. This extension is not
c1f7febf
RK
1915implemented in GNU C++.
1916
26d4fec7 1917To specify an array index, write
c1f7febf
RK
1918@samp{[@var{index}] =} before the element value. For example,
1919
3ab51846 1920@smallexample
26d4fec7 1921int a[6] = @{ [4] = 29, [2] = 15 @};
3ab51846 1922@end smallexample
c1f7febf
RK
1923
1924@noindent
1925is equivalent to
1926
3ab51846 1927@smallexample
c1f7febf 1928int a[6] = @{ 0, 0, 15, 0, 29, 0 @};
3ab51846 1929@end smallexample
c1f7febf
RK
1930
1931@noindent
1932The index values must be constant expressions, even if the array being
1933initialized is automatic.
1934
c417597c 1935An alternative syntax for this that has been obsolete since GCC 2.5 but
26d4fec7
JM
1936GCC still accepts is to write @samp{[@var{index}]} before the element
1937value, with no @samp{=}.
1938
c1f7febf 1939To initialize a range of elements to the same value, write
26d4fec7
JM
1940@samp{[@var{first} ... @var{last}] = @var{value}}. This is a GNU
1941extension. For example,
c1f7febf 1942
3ab51846 1943@smallexample
c1f7febf 1944int widths[] = @{ [0 ... 9] = 1, [10 ... 99] = 2, [100] = 3 @};
3ab51846 1945@end smallexample
c1f7febf 1946
8b6a5902 1947@noindent
358a3dbc 1948If the value in it has side-effects, the side-effects happen only once,
8b6a5902
JJ
1949not for each initialized field by the range initializer.
1950
c1f7febf
RK
1951@noindent
1952Note that the length of the array is the highest value specified
1953plus one.
1954
1955In a structure initializer, specify the name of a field to initialize
26d4fec7 1956with @samp{.@var{fieldname} =} before the element value. For example,
c1f7febf
RK
1957given the following structure,
1958
3ab51846 1959@smallexample
c1f7febf 1960struct point @{ int x, y; @};
3ab51846 1961@end smallexample
c1f7febf
RK
1962
1963@noindent
1964the following initialization
1965
3ab51846 1966@smallexample
26d4fec7 1967struct point p = @{ .y = yvalue, .x = xvalue @};
3ab51846 1968@end smallexample
c1f7febf
RK
1969
1970@noindent
1971is equivalent to
1972
3ab51846 1973@smallexample
c1f7febf 1974struct point p = @{ xvalue, yvalue @};
3ab51846 1975@end smallexample
c1f7febf 1976
c417597c 1977Another syntax that has the same meaning, obsolete since GCC 2.5, is
26d4fec7 1978@samp{@var{fieldname}:}, as shown here:
c1f7febf 1979
3ab51846 1980@smallexample
26d4fec7 1981struct point p = @{ y: yvalue, x: xvalue @};
3ab51846 1982@end smallexample
c1f7febf 1983
1b226529
MP
1984Omitted field members are implicitly initialized the same as objects
1985that have static storage duration.
1986
4b404517
JM
1987@cindex designators
1988The @samp{[@var{index}]} or @samp{.@var{fieldname}} is known as a
1989@dfn{designator}. You can also use a designator (or the obsolete colon
1990syntax) when initializing a union, to specify which element of the union
1991should be used. For example,
c1f7febf 1992
3ab51846 1993@smallexample
c1f7febf
RK
1994union foo @{ int i; double d; @};
1995
26d4fec7 1996union foo f = @{ .d = 4 @};
3ab51846 1997@end smallexample
c1f7febf
RK
1998
1999@noindent
358a3dbc 2000converts 4 to a @code{double} to store it in the union using
c1f7febf 2001the second element. By contrast, casting 4 to type @code{union foo}
358a3dbc 2002stores it into the union as the integer @code{i}, since it is
c1f7febf
RK
2003an integer. (@xref{Cast to Union}.)
2004
2005You can combine this technique of naming elements with ordinary C
2006initialization of successive elements. Each initializer element that
4b404517 2007does not have a designator applies to the next consecutive element of the
c1f7febf
RK
2008array or structure. For example,
2009
3ab51846 2010@smallexample
c1f7febf 2011int a[6] = @{ [1] = v1, v2, [4] = v4 @};
3ab51846 2012@end smallexample
c1f7febf
RK
2013
2014@noindent
2015is equivalent to
2016
3ab51846 2017@smallexample
c1f7febf 2018int a[6] = @{ 0, v1, v2, 0, v4, 0 @};
3ab51846 2019@end smallexample
c1f7febf
RK
2020
2021Labeling the elements of an array initializer is especially useful
2022when the indices are characters or belong to an @code{enum} type.
2023For example:
2024
3ab51846 2025@smallexample
c1f7febf
RK
2026int whitespace[256]
2027 = @{ [' '] = 1, ['\t'] = 1, ['\h'] = 1,
2028 ['\f'] = 1, ['\n'] = 1, ['\r'] = 1 @};
3ab51846 2029@end smallexample
c1f7febf 2030
4b404517 2031@cindex designator lists
26d4fec7 2032You can also write a series of @samp{.@var{fieldname}} and
4b404517 2033@samp{[@var{index}]} designators before an @samp{=} to specify a
26d4fec7
JM
2034nested subobject to initialize; the list is taken relative to the
2035subobject corresponding to the closest surrounding brace pair. For
2036example, with the @samp{struct point} declaration above:
2037
478c9e72 2038@smallexample
26d4fec7 2039struct point ptarray[10] = @{ [2].y = yv2, [2].x = xv2, [0].x = xv0 @};
478c9e72 2040@end smallexample
26d4fec7 2041
8b6a5902 2042@noindent
358a3dbc 2043If the same field is initialized multiple times, it has the value from
8b6a5902
JJ
2044the last initialization. If any such overridden initialization has
2045side-effect, it is unspecified whether the side-effect happens or not.
358a3dbc 2046Currently, GCC discards them and issues a warning.
8b6a5902 2047
c1f7febf
RK
2048@node Case Ranges
2049@section Case Ranges
2050@cindex case ranges
2051@cindex ranges in case statements
2052
2053You can specify a range of consecutive values in a single @code{case} label,
2054like this:
2055
3ab51846 2056@smallexample
c1f7febf 2057case @var{low} ... @var{high}:
3ab51846 2058@end smallexample
c1f7febf
RK
2059
2060@noindent
2061This has the same effect as the proper number of individual @code{case}
2062labels, one for each integer value from @var{low} to @var{high}, inclusive.
2063
2064This feature is especially useful for ranges of ASCII character codes:
2065
3ab51846 2066@smallexample
c1f7febf 2067case 'A' ... 'Z':
3ab51846 2068@end smallexample
c1f7febf
RK
2069
2070@strong{Be careful:} Write spaces around the @code{...}, for otherwise
2071it may be parsed wrong when you use it with integer values. For example,
2072write this:
2073
3ab51846 2074@smallexample
c1f7febf 2075case 1 ... 5:
3ab51846 2076@end smallexample
c1f7febf
RK
2077
2078@noindent
2079rather than this:
2080
3ab51846 2081@smallexample
c1f7febf 2082case 1...5:
3ab51846 2083@end smallexample
c1f7febf
RK
2084
2085@node Cast to Union
2086@section Cast to a Union Type
2087@cindex cast to a union
2088@cindex union, casting to a
2089
2090A cast to union type is similar to other casts, except that the type
2091specified is a union type. You can specify the type either with
2092@code{union @var{tag}} or with a typedef name. A cast to union is actually
bafa88c2 2093a constructor, not a cast, and hence does not yield an lvalue like
4b404517 2094normal casts. (@xref{Compound Literals}.)
c1f7febf
RK
2095
2096The types that may be cast to the union type are those of the members
2097of the union. Thus, given the following union and variables:
2098
3ab51846 2099@smallexample
c1f7febf
RK
2100union foo @{ int i; double d; @};
2101int x;
2102double y;
3ab51846 2103@end smallexample
c1f7febf
RK
2104
2105@noindent
aee96fe9 2106both @code{x} and @code{y} can be cast to type @code{union foo}.
c1f7febf
RK
2107
2108Using the cast as the right-hand side of an assignment to a variable of
2109union type is equivalent to storing in a member of the union:
2110
3ab51846 2111@smallexample
c1f7febf 2112union foo u;
0d893a63 2113/* @r{@dots{}} */
c1f7febf
RK
2114u = (union foo) x @equiv{} u.i = x
2115u = (union foo) y @equiv{} u.d = y
3ab51846 2116@end smallexample
c1f7febf
RK
2117
2118You can also use the union cast as a function argument:
2119
3ab51846 2120@smallexample
c1f7febf 2121void hack (union foo);
0d893a63 2122/* @r{@dots{}} */
c1f7febf 2123hack ((union foo) x);
3ab51846 2124@end smallexample
c1f7febf 2125
4b404517
JM
2126@node Mixed Declarations
2127@section Mixed Declarations and Code
2128@cindex mixed declarations and code
2129@cindex declarations, mixed with code
2130@cindex code, mixed with declarations
2131
2132ISO C99 and ISO C++ allow declarations and code to be freely mixed
566fb011 2133within compound statements. As an extension, GNU C also allows this in
7e1542b9 2134C90 mode. For example, you could do:
4b404517 2135
3ab51846 2136@smallexample
4b404517 2137int i;
0d893a63 2138/* @r{@dots{}} */
4b404517
JM
2139i++;
2140int j = i + 2;
3ab51846 2141@end smallexample
4b404517
JM
2142
2143Each identifier is visible from where it is declared until the end of
2144the enclosing block.
2145
c1f7febf
RK
2146@node Function Attributes
2147@section Declaring Attributes of Functions
2148@cindex function attributes
2149@cindex declaring attributes of functions
2150@cindex functions that never return
6e9a3221 2151@cindex functions that return more than once
c1f7febf
RK
2152@cindex functions that have no side effects
2153@cindex functions in arbitrary sections
2a59078d 2154@cindex functions that behave like malloc
c1f7febf
RK
2155@cindex @code{volatile} applied to function
2156@cindex @code{const} applied to function
26f6672d 2157@cindex functions with @code{printf}, @code{scanf}, @code{strftime} or @code{strfmon} style arguments
b34c7881 2158@cindex functions with non-null pointer arguments
c1f7febf
RK
2159@cindex functions that are passed arguments in registers on the 386
2160@cindex functions that pop the argument stack on the 386
2161@cindex functions that do not pop the argument stack on the 386
ab442df7
MM
2162@cindex functions that have different compilation options on the 386
2163@cindex functions that have different optimization options
ba885ec5 2164@cindex functions that are dynamically resolved
c1f7febf
RK
2165
2166In GNU C, you declare certain things about functions called in your program
2167which help the compiler optimize function calls and check your code more
2168carefully.
2169
2170The keyword @code{__attribute__} allows you to specify special
2171attributes when making a declaration. This keyword is followed by an
9162542e 2172attribute specification inside double parentheses. The following
eacecf96 2173attributes are currently defined for functions on all targets:
8fcbce72
JJ
2174@code{aligned}, @code{alloc_size}, @code{alloc_align}, @code{assume_aligned},
2175@code{noreturn}, @code{returns_twice}, @code{noinline}, @code{noclone},
86631ea3
MJ
2176@code{always_inline}, @code{flatten}, @code{pure}, @code{const},
2177@code{nothrow}, @code{sentinel}, @code{format}, @code{format_arg},
7458026b
ILT
2178@code{no_instrument_function}, @code{no_split_stack},
2179@code{section}, @code{constructor},
51bc54a6 2180@code{destructor}, @code{used}, @code{unused}, @code{deprecated},
ba885ec5 2181@code{weak}, @code{malloc}, @code{alias}, @code{ifunc},
826cacfe
MG
2182@code{warn_unused_result}, @code{nonnull},
2183@code{returns_nonnull}, @code{gnu_inline},
ba885ec5 2184@code{externally_visible}, @code{hot}, @code{cold}, @code{artificial},
e664c61c 2185@code{no_sanitize_address}, @code{no_address_safety_analysis},
d5e254e1
IE
2186@code{no_sanitize_undefined}, @code{no_reorder}, @code{bnd_legacy},
2187@code{bnd_instrument},
e664c61c 2188@code{error} and @code{warning}.
77bc5132
JJ
2189Several other attributes are defined for functions on particular
2190target systems. Other attributes, including @code{section} are
883755a1
DW
2191supported for variables declarations (@pxref{Variable Attributes}),
2192labels (@pxref{Label Attributes})
77bc5132 2193and for types (@pxref{Type Attributes}).
c1f7febf 2194
110532c8
BS
2195GCC plugins may provide their own attributes.
2196
c1f7febf
RK
2197You may also specify attributes with @samp{__} preceding and following
2198each keyword. This allows you to use them in header files without
2199being concerned about a possible macro of the same name. For example,
2200you may use @code{__noreturn__} instead of @code{noreturn}.
2201
2c5e91d2
JM
2202@xref{Attribute Syntax}, for details of the exact syntax for using
2203attributes.
2204
c1f7febf 2205@table @code
8a36672b 2206@c Keep this table alphabetized by attribute name. Treat _ as space.
c1f7febf 2207
c8619b90
NS
2208@item alias ("@var{target}")
2209@cindex @code{alias} attribute
2210The @code{alias} attribute causes the declaration to be emitted as an
2211alias for another symbol, which must be specified. For instance,
c1f7febf
RK
2212
2213@smallexample
c8619b90
NS
2214void __f () @{ /* @r{Do something.} */; @}
2215void f () __attribute__ ((weak, alias ("__f")));
c1f7febf
RK
2216@end smallexample
2217
c513ecbf 2218@noindent
a9b0b825 2219defines @samp{f} to be a weak alias for @samp{__f}. In C++, the
52eb57df
RH
2220mangled name for the target must be used. It is an error if @samp{__f}
2221is not defined in the same translation unit.
c8619b90
NS
2222
2223Not all target machines support this attribute.
9162542e 2224
837edd5f
GK
2225@item aligned (@var{alignment})
2226@cindex @code{aligned} attribute
2227This attribute specifies a minimum alignment for the function,
2228measured in bytes.
2229
2230You cannot use this attribute to decrease the alignment of a function,
2231only to increase it. However, when you explicitly specify a function
358a3dbc 2232alignment this overrides the effect of the
837edd5f
GK
2233@option{-falign-functions} (@pxref{Optimize Options}) option for this
2234function.
2235
2236Note that the effectiveness of @code{aligned} attributes may be
2237limited by inherent limitations in your linker. On many systems, the
2238linker is only able to arrange for functions to be aligned up to a
2239certain maximum alignment. (For some linkers, the maximum supported
2240alignment may be very very small.) See your linker documentation for
2241further information.
2242
2243The @code{aligned} attribute can also be used for variables and fields
2244(@pxref{Variable Attributes}.)
2245
51bc54a6
DM
2246@item alloc_size
2247@cindex @code{alloc_size} attribute
2248The @code{alloc_size} attribute is used to tell the compiler that the
2249function return value points to memory, where the size is given by
ff2ce160 2250one or two of the functions parameters. GCC uses this
51bc54a6
DM
2251information to improve the correctness of @code{__builtin_object_size}.
2252
2253The function parameter(s) denoting the allocated size are specified by
2254one or two integer arguments supplied to the attribute. The allocated size
2255is either the value of the single function argument specified or the product
2256of the two function arguments specified. Argument numbering starts at
2257one.
2258
ff2ce160 2259For instance,
51bc54a6
DM
2260
2261@smallexample
2262void* my_calloc(size_t, size_t) __attribute__((alloc_size(1,2)))
5d77fb19 2263void* my_realloc(void*, size_t) __attribute__((alloc_size(2)))
51bc54a6
DM
2264@end smallexample
2265
c513ecbf 2266@noindent
358a3dbc
SL
2267declares that @code{my_calloc} returns memory of the size given by
2268the product of parameter 1 and 2 and that @code{my_realloc} returns memory
51bc54a6
DM
2269of the size given by parameter 2.
2270
8fcbce72
JJ
2271@item alloc_align
2272@cindex @code{alloc_align} attribute
2273The @code{alloc_align} attribute is used to tell the compiler that the
2274function return value points to memory, where the returned pointer minimum
2275alignment is given by one of the functions parameters. GCC uses this
2276information to improve pointer alignment analysis.
2277
2278The function parameter denoting the allocated alignment is specified by
2279one integer argument, whose number is the argument of the attribute.
2280Argument numbering starts at one.
2281
2282For instance,
2283
2284@smallexample
2285void* my_memalign(size_t, size_t) __attribute__((alloc_align(1)))
2286@end smallexample
2287
2288@noindent
2289declares that @code{my_memalign} returns memory with minimum alignment
2290given by parameter 1.
2291
2292@item assume_aligned
2293@cindex @code{assume_aligned} attribute
2294The @code{assume_aligned} attribute is used to tell the compiler that the
2295function return value points to memory, where the returned pointer minimum
2296alignment is given by the first argument.
2297If the attribute has two arguments, the second argument is misalignment offset.
2298
2299For instance
2300
2301@smallexample
2302void* my_alloc1(size_t) __attribute__((assume_aligned(16)))
2303void* my_alloc2(size_t) __attribute__((assume_aligned(32, 8)))
2304@end smallexample
2305
2306@noindent
2307declares that @code{my_alloc1} returns 16-byte aligned pointer and
2308that @code{my_alloc2} returns a pointer whose value modulo 32 is equal
2309to 8.
2310
6aa77e6c 2311@item always_inline
c8619b90 2312@cindex @code{always_inline} function attribute
6aa77e6c 2313Generally, functions are not inlined unless optimization is specified.
3defdb14
RB
2314For functions declared inline, this attribute inlines the function
2315independent of any restrictions that otherwise apply to inlining.
2316Failure to inline such a function is diagnosed as an error.
2317Note that if such a function is called indirectly the compiler may
2318or may not inline it depending on optimization level and a failure
2319to inline an indirect call may or may not be diagnosed.
6aa77e6c 2320
4eb7fd83
JJ
2321@item gnu_inline
2322@cindex @code{gnu_inline} function attribute
c417597c 2323This attribute should be used with a function that is also declared
da1c7394 2324with the @code{inline} keyword. It directs GCC to treat the function
7e1542b9 2325as if it were defined in gnu90 mode even when compiling in C99 or
da1c7394
ILT
2326gnu99 mode.
2327
2328If the function is declared @code{extern}, then this definition of the
2329function is used only for inlining. In no case is the function
2330compiled as a standalone function, not even if you take its address
2331explicitly. Such an address becomes an external reference, as if you
2332had only declared the function, and had not defined it. This has
2333almost the effect of a macro. The way to use this is to put a
2334function definition in a header file with this attribute, and put
2335another copy of the function, without @code{extern}, in a library
358a3dbc
SL
2336file. The definition in the header file causes most calls to the
2337function to be inlined. If any uses of the function remain, they
da1c7394
ILT
2338refer to the single copy in the library. Note that the two
2339definitions of the functions need not be precisely the same, although
2340if they do not have the same effect your program may behave oddly.
2341
3a47c4e4
AO
2342In C, if the function is neither @code{extern} nor @code{static}, then
2343the function is compiled as a standalone function, as well as being
da1c7394
ILT
2344inlined where possible.
2345
2346This is how GCC traditionally handled functions declared
2347@code{inline}. Since ISO C99 specifies a different semantics for
2348@code{inline}, this function attribute is provided as a transition
2349measure and as a useful feature in its own right. This attribute is
2350available in GCC 4.1.3 and later. It is available if either of the
2351preprocessor macros @code{__GNUC_GNU_INLINE__} or
2352@code{__GNUC_STDC_INLINE__} are defined. @xref{Inline,,An Inline
2353Function is As Fast As a Macro}.
4eb7fd83 2354
3a47c4e4
AO
2355In C++, this attribute does not depend on @code{extern} in any way,
2356but it still requires the @code{inline} keyword to enable its special
2357behavior.
2358
d752cfdb 2359@item artificial
1df48f5c 2360@cindex @code{artificial} function attribute
c417597c 2361This attribute is useful for small inline wrappers that if possible
358a3dbc
SL
2362should appear during debugging as a unit. Depending on the debug
2363info format it either means marking the function as artificial
d752cfdb
JJ
2364or using the caller location for all instructions within the inlined
2365body.
2366
65655f79
DD
2367@item bank_switch
2368@cindex interrupt handler functions
2369When added to an interrupt handler with the M32C port, causes the
2370prologue and epilogue to use bank switching to preserve the registers
2371rather than saving them on the stack.
2372
0691d1d4 2373@item flatten
1df48f5c 2374@cindex @code{flatten} function attribute
0691d1d4 2375Generally, inlining into a function is limited. For a function marked with
358a3dbc 2376this attribute, every call inside this function is inlined, if possible.
0691d1d4 2377Whether the function itself is considered for inlining depends on its size and
d6cc6ec9 2378the current inlining parameters.
0691d1d4 2379
d2af6a68
JJ
2380@item error ("@var{message}")
2381@cindex @code{error} function attribute
2382If this attribute is used on a function declaration and a call to such a function
2383is not eliminated through dead code elimination or other optimizations, an error
c417597c 2384that includes @var{message} is diagnosed. This is useful
566fb011 2385for compile-time checking, especially together with @code{__builtin_constant_p}
d2af6a68
JJ
2386and inline functions where checking the inline function arguments is not
2387possible through @code{extern char [(condition) ? 1 : -1];} tricks.
2388While it is possible to leave the function undefined and thus invoke
358a3dbc 2389a link failure, when using this attribute the problem is diagnosed
d2af6a68
JJ
2390earlier and with exact location of the call even in presence of inline
2391functions or when not emitting debugging information.
2392
2393@item warning ("@var{message}")
2394@cindex @code{warning} function attribute
2395If this attribute is used on a function declaration and a call to such a function
2396is not eliminated through dead code elimination or other optimizations, a warning
c417597c 2397that includes @var{message} is diagnosed. This is useful
566fb011 2398for compile-time checking, especially together with @code{__builtin_constant_p}
d2af6a68
JJ
2399and inline functions. While it is possible to define the function with
2400a message in @code{.gnu.warning*} section, when using this attribute the problem
358a3dbc 2401is diagnosed earlier and with exact location of the call even in presence
d2af6a68
JJ
2402of inline functions or when not emitting debugging information.
2403
c8619b90
NS
2404@item cdecl
2405@cindex functions that do pop the argument stack on the 386
2406@opindex mrtd
2407On the Intel 386, the @code{cdecl} attribute causes the compiler to
358a3dbc 2408assume that the calling function pops off the stack space used to
c8619b90
NS
2409pass arguments. This is
2410useful to override the effects of the @option{-mrtd} switch.
2a8f6b90 2411
2a8f6b90 2412@item const
c8619b90 2413@cindex @code{const} function attribute
2a8f6b90
JH
2414Many functions do not examine any values except their arguments, and
2415have no effects except the return value. Basically this is just slightly
50c177f7 2416more strict class than the @code{pure} attribute below, since function is not
2a59078d 2417allowed to read global memory.
2a8f6b90
JH
2418
2419@cindex pointer arguments
2420Note that a function that has pointer arguments and examines the data
2421pointed to must @emph{not} be declared @code{const}. Likewise, a
2422function that calls a non-@code{const} function usually must not be
2423@code{const}. It does not make sense for a @code{const} function to
2424return @code{void}.
2425
f0523f02 2426The attribute @code{const} is not implemented in GCC versions earlier
c1f7febf
RK
2427than 2.5. An alternative way to declare that a function has no side
2428effects, which works in the current version and in some older versions,
2429is as follows:
2430
2431@smallexample
2432typedef int intfn ();
2433
2434extern const intfn square;
2435@end smallexample
2436
c513ecbf 2437@noindent
c1f7febf
RK
2438This approach does not work in GNU C++ from 2.6.0 on, since the language
2439specifies that the @samp{const} must be attached to the return value.
2440
c8619b90
NS
2441@item constructor
2442@itemx destructor
fc8600f9
MM
2443@itemx constructor (@var{priority})
2444@itemx destructor (@var{priority})
c8619b90
NS
2445@cindex @code{constructor} function attribute
2446@cindex @code{destructor} function attribute
2447The @code{constructor} attribute causes the function to be called
2448automatically before execution enters @code{main ()}. Similarly, the
2449@code{destructor} attribute causes the function to be called
358a3dbc
SL
2450automatically after @code{main ()} completes or @code{exit ()} is
2451called. Functions with these attributes are useful for
2452initializing data that is used implicitly during the execution of
c8619b90
NS
2453the program.
2454
fc8600f9
MM
2455You may provide an optional integer priority to control the order in
2456which constructor and destructor functions are run. A constructor
2457with a smaller priority number runs before a constructor with a larger
2458priority number; the opposite relationship holds for destructors. So,
2459if you have a constructor that allocates a resource and a destructor
2460that deallocates the same resource, both functions typically have the
2461same priority. The priorities for constructor and destructor
2462functions are the same as those specified for namespace-scope C++
2463objects (@pxref{C++ Attributes}).
2464
c8619b90
NS
2465These attributes are not currently implemented for Objective-C@.
2466
2467@item deprecated
9b86d6bb 2468@itemx deprecated (@var{msg})
c8619b90
NS
2469@cindex @code{deprecated} attribute.
2470The @code{deprecated} attribute results in a warning if the function
2471is used anywhere in the source file. This is useful when identifying
2472functions that are expected to be removed in a future version of a
2473program. The warning also includes the location of the declaration
2474of the deprecated function, to enable users to easily find further
2475information about why the function is deprecated, or what they should
2476do instead. Note that the warnings only occurs for uses:
2477
2478@smallexample
2479int old_fn () __attribute__ ((deprecated));
2480int old_fn ();
2481int (*fn_ptr)() = old_fn;
2482@end smallexample
2483
358a3dbc
SL
2484@noindent
2485results in a warning on line 3 but not line 2. The optional @var{msg}
2486argument, which must be a string, is printed in the warning if
9b86d6bb 2487present.
c8619b90
NS
2488
2489The @code{deprecated} attribute can also be used for variables and
2490types (@pxref{Variable Attributes}, @pxref{Type Attributes}.)
2491
e2491744
DD
2492@item disinterrupt
2493@cindex @code{disinterrupt} attribute
feeeff5c 2494On Epiphany and MeP targets, this attribute causes the compiler to emit
e2491744
DD
2495instructions to disable interrupts for the duration of the given
2496function.
2497
c8619b90
NS
2498@item dllexport
2499@cindex @code{__declspec(dllexport)}
b2ca3702
MM
2500On Microsoft Windows targets and Symbian OS targets the
2501@code{dllexport} attribute causes the compiler to provide a global
2502pointer to a pointer in a DLL, so that it can be referenced with the
2503@code{dllimport} attribute. On Microsoft Windows targets, the pointer
2504name is formed by combining @code{_imp__} and the function or variable
2505name.
2506
2507You can use @code{__declspec(dllexport)} as a synonym for
2508@code{__attribute__ ((dllexport))} for compatibility with other
2509compilers.
2510
2511On systems that support the @code{visibility} attribute, this
3a687f8b
MM
2512attribute also implies ``default'' visibility. It is an error to
2513explicitly specify any other visibility.
c8619b90 2514
ff2ce160 2515In previous versions of GCC, the @code{dllexport} attribute was ignored
47ea1edf 2516for inlined functions, unless the @option{-fkeep-inline-functions} flag
566fb011 2517had been used. The default behavior now is to emit all dllexported
47ea1edf 2518inline functions; however, this can cause object file-size bloat, in
566fb011 2519which case the old behavior can be restored by using
47ea1edf
DK
2520@option{-fno-keep-inline-dllexport}.
2521
2522The attribute is also ignored for undefined symbols.
c8619b90 2523
8a36672b
JM
2524When applied to C++ classes, the attribute marks defined non-inlined
2525member functions and static data members as exports. Static consts
c8619b90
NS
2526initialized in-class are not marked unless they are also defined
2527out-of-class.
2528
b55e3aad 2529For Microsoft Windows targets there are alternative methods for
b2ca3702 2530including the symbol in the DLL's export table such as using a
b55e3aad
NC
2531@file{.def} file with an @code{EXPORTS} section or, with GNU ld, using
2532the @option{--export-all} linker flag.
c8619b90
NS
2533
2534@item dllimport
2535@cindex @code{__declspec(dllimport)}
b2ca3702 2536On Microsoft Windows and Symbian OS targets, the @code{dllimport}
b55e3aad 2537attribute causes the compiler to reference a function or variable via
b2ca3702 2538a global pointer to a pointer that is set up by the DLL exporting the
3a687f8b
MM
2539symbol. The attribute implies @code{extern}. On Microsoft Windows
2540targets, the pointer name is formed by combining @code{_imp__} and the
2541function or variable name.
b2ca3702
MM
2542
2543You can use @code{__declspec(dllimport)} as a synonym for
2544@code{__attribute__ ((dllimport))} for compatibility with other
2545compilers.
c8619b90 2546
3a687f8b
MM
2547On systems that support the @code{visibility} attribute, this
2548attribute also implies ``default'' visibility. It is an error to
2549explicitly specify any other visibility.
2550
8a36672b 2551Currently, the attribute is ignored for inlined functions. If the
c8619b90
NS
2552attribute is applied to a symbol @emph{definition}, an error is reported.
2553If a symbol previously declared @code{dllimport} is later defined, the
2554attribute is ignored in subsequent references, and a warning is emitted.
2555The attribute is also overridden by a subsequent declaration as
2556@code{dllexport}.
2557
2558When applied to C++ classes, the attribute marks non-inlined
2559member functions and static data members as imports. However, the
2560attribute is ignored for virtual methods to allow creation of vtables
2561using thunks.
2562
b2ca3702 2563On the SH Symbian OS target the @code{dllimport} attribute also has
78466c0e 2564another affect---it can cause the vtable and run-time type information
b2ca3702 2565for a class to be exported. This happens when the class has a
bafa88c2 2566dllimported constructor or a non-inline, non-pure virtual function
e4ae5e77 2567and, for either of those two conditions, the class also has an inline
b2ca3702
MM
2568constructor or destructor and has a key function that is defined in
2569the current translation unit.
b55e3aad 2570
566fb011 2571For Microsoft Windows targets the use of the @code{dllimport}
b55e3aad 2572attribute on functions is not necessary, but provides a small
8a36672b 2573performance benefit by eliminating a thunk in the DLL@. The use of the
b55e3aad 2574@code{dllimport} attribute on imported variables was required on older
b2ca3702 2575versions of the GNU linker, but can now be avoided by passing the
8a36672b 2576@option{--enable-auto-import} switch to the GNU linker. As with
b2ca3702 2577functions, using the attribute for a variable eliminates a thunk in
8a36672b 2578the DLL@.
b2ca3702 2579
d32034a7
DS
2580One drawback to using this attribute is that a pointer to a
2581@emph{variable} marked as @code{dllimport} cannot be used as a constant
2582address. However, a pointer to a @emph{function} with the
2583@code{dllimport} attribute can be used as a constant initializer; in
2584this case, the address of a stub function in the import lib is
2585referenced. On Microsoft Windows targets, the attribute can be disabled
b2ca3702 2586for functions by setting the @option{-mnop-fun-dllimport} flag.
c8619b90
NS
2587
2588@item eightbit_data
6f46cb63 2589@cindex eight-bit data on the H8/300, H8/300H, and H8S
c8619b90 2590Use this attribute on the H8/300, H8/300H, and H8S to indicate that the specified
6f46cb63 2591variable should be placed into the eight-bit data section.
358a3dbc 2592The compiler generates more efficient code for certain operations
6f46cb63 2593on data in the eight-bit data area. Note the eight-bit data area is limited to
c8619b90
NS
2594256 bytes of data.
2595
2596You must use GAS and GLD from GNU binutils version 2.7 or later for
2597this attribute to work correctly.
2598
9304f876
CJW
2599@item exception
2600@cindex exception handler functions
2601Use this attribute on the NDS32 target to indicate that the specified function
2602is an exception handler. The compiler will generate corresponding sections
2603for use in an exception handler.
2604
0d4a78eb
BS
2605@item exception_handler
2606@cindex exception handler functions on the Blackfin processor
2607Use this attribute on the Blackfin to indicate that the specified function
358a3dbc 2608is an exception handler. The compiler generates function entry and
0d4a78eb
BS
2609exit sequences suitable for use in an exception handler when this
2610attribute is present.
2611
1df48f5c
JW
2612@item externally_visible
2613@cindex @code{externally_visible} attribute.
2614This attribute, attached to a global variable or function, nullifies
2615the effect of the @option{-fwhole-program} command-line option, so the
bafa88c2
SL
2616object remains visible outside the current compilation unit.
2617
2618If @option{-fwhole-program} is used together with @option{-flto} and
2619@command{gold} is used as the linker plugin,
2620@code{externally_visible} attributes are automatically added to functions
2621(not variable yet due to a current @command{gold} issue)
2622that are accessed outside of LTO objects according to resolution file
2623produced by @command{gold}.
2624For other linkers that cannot generate resolution file,
2625explicit @code{externally_visible} attributes are still necessary.
1df48f5c 2626
c8619b90 2627@item far
c417597c 2628@cindex functions that handle memory bank switching
c8619b90
NS
2629On 68HC11 and 68HC12 the @code{far} attribute causes the compiler to
2630use a calling convention that takes care of switching memory banks when
2631entering and leaving a function. This calling convention is also the
2632default when using the @option{-mlong-calls} option.
2633
358a3dbc 2634On 68HC12 the compiler uses the @code{call} and @code{rtc} instructions
c8619b90
NS
2635to call and return from a function.
2636
358a3dbc 2637On 68HC11 the compiler generates a sequence of instructions
c8619b90 2638to invoke a board-specific routine to switch the memory bank and call the
8a36672b 2639real function. The board-specific routine simulates a @code{call}.
358a3dbc 2640At the end of a function, it jumps to a board-specific routine
8a36672b 2641instead of using @code{rts}. The board-specific return routine simulates
c8619b90
NS
2642the @code{rtc}.
2643
e2491744 2644On MeP targets this causes the compiler to use a calling convention
c417597c 2645that assumes the called function is too far away for the built-in
e2491744
DD
2646addressing modes.
2647
65655f79
DD
2648@item fast_interrupt
2649@cindex interrupt handler functions
65a324b4 2650Use this attribute on the M32C and RX ports to indicate that the specified
65655f79
DD
2651function is a fast interrupt handler. This is just like the
2652@code{interrupt} attribute, except that @code{freit} is used to return
2653instead of @code{reit}.
2654
c8619b90
NS
2655@item fastcall
2656@cindex functions that pop the argument stack on the 386
2657On the Intel 386, the @code{fastcall} attribute causes the compiler to
2f84b963
RG
2658pass the first argument (if of integral type) in the register ECX and
2659the second argument (if of integral type) in the register EDX@. Subsequent
358a3dbc
SL
2660and other typed arguments are passed on the stack. The called function
2661pops the arguments off the stack. If the number of arguments is variable all
c8619b90 2662arguments are pushed on the stack.
c1f7febf 2663
3e65f251
KT
2664@item thiscall
2665@cindex functions that pop the argument stack on the 386
2666On the Intel 386, the @code{thiscall} attribute causes the compiler to
2667pass the first argument (if of integral type) in the register ECX.
2668Subsequent and other typed arguments are passed on the stack. The called
358a3dbc 2669function pops the arguments off the stack.
3e65f251
KT
2670If the number of arguments is variable all arguments are pushed on the
2671stack.
2672The @code{thiscall} attribute is intended for C++ non-static member functions.
566fb011 2673As a GCC extension, this calling convention can be used for C functions
3e65f251
KT
2674and for static member methods.
2675
c1f7febf
RK
2676@item format (@var{archetype}, @var{string-index}, @var{first-to-check})
2677@cindex @code{format} function attribute
84330467 2678@opindex Wformat
bb72a084 2679The @code{format} attribute specifies that a function takes @code{printf},
c417597c 2680@code{scanf}, @code{strftime} or @code{strfmon} style arguments that
26f6672d
JM
2681should be type-checked against a format string. For example, the
2682declaration:
c1f7febf
RK
2683
2684@smallexample
2685extern int
2686my_printf (void *my_object, const char *my_format, ...)
2687 __attribute__ ((format (printf, 2, 3)));
2688@end smallexample
2689
2690@noindent
2691causes the compiler to check the arguments in calls to @code{my_printf}
2692for consistency with the @code{printf} style format string argument
2693@code{my_format}.
2694
2695The parameter @var{archetype} determines how the format string is
6590fc9f
KT
2696interpreted, and should be @code{printf}, @code{scanf}, @code{strftime},
2697@code{gnu_printf}, @code{gnu_scanf}, @code{gnu_strftime} or
2698@code{strfmon}. (You can also use @code{__printf__},
2699@code{__scanf__}, @code{__strftime__} or @code{__strfmon__}.) On
2700MinGW targets, @code{ms_printf}, @code{ms_scanf}, and
2701@code{ms_strftime} are also present.
bafa88c2
SL
2702@var{archetype} values such as @code{printf} refer to the formats accepted
2703by the system's C runtime library,
2704while values prefixed with @samp{gnu_} always refer
6590fc9f 2705to the formats accepted by the GNU C Library. On Microsoft Windows
bafa88c2 2706targets, values prefixed with @samp{ms_} refer to the formats accepted by the
6590fc9f
KT
2707@file{msvcrt.dll} library.
2708The parameter @var{string-index}
2709specifies which argument is the format string argument (starting
2710from 1), while @var{first-to-check} is the number of the first
2711argument to check against the format string. For functions
2712where the arguments are not available to be checked (such as
c1f7febf 2713@code{vprintf}), specify the third parameter as zero. In this case the
b722c82c
JM
2714compiler only checks the format string for consistency. For
2715@code{strftime} formats, the third parameter is required to be zero.
f57a2e3a
BE
2716Since non-static C++ methods have an implicit @code{this} argument, the
2717arguments of such methods should be counted from two, not one, when
2718giving values for @var{string-index} and @var{first-to-check}.
c1f7febf
RK
2719
2720In the example above, the format string (@code{my_format}) is the second
2721argument of the function @code{my_print}, and the arguments to check
2722start with the third argument, so the correct parameters for the format
2723attribute are 2 and 3.
2724
84330467 2725@opindex ffreestanding
e6e931b7 2726@opindex fno-builtin
c1f7febf 2727The @code{format} attribute allows you to identify your own functions
c417597c 2728that take format strings as arguments, so that GCC can check the
b722c82c 2729calls to these functions for errors. The compiler always (unless
e6e931b7 2730@option{-ffreestanding} or @option{-fno-builtin} is used) checks formats
b722c82c 2731for the standard library functions @code{printf}, @code{fprintf},
bb72a084 2732@code{sprintf}, @code{scanf}, @code{fscanf}, @code{sscanf}, @code{strftime},
c1f7febf 2733@code{vprintf}, @code{vfprintf} and @code{vsprintf} whenever such
84330467 2734warnings are requested (using @option{-Wformat}), so there is no need to
b722c82c
JM
2735modify the header file @file{stdio.h}. In C99 mode, the functions
2736@code{snprintf}, @code{vsnprintf}, @code{vscanf}, @code{vfscanf} and
26f6672d 2737@code{vsscanf} are also checked. Except in strictly conforming C
b4c984fb
KG
2738standard modes, the X/Open function @code{strfmon} is also checked as
2739are @code{printf_unlocked} and @code{fprintf_unlocked}.
b722c82c 2740@xref{C Dialect Options,,Options Controlling C Dialect}.
c1f7febf 2741
ff2ce160 2742For Objective-C dialects, @code{NSString} (or @code{__NSString__}) is
91ebb981 2743recognized in the same context. Declarations including these format attributes
358a3dbc
SL
2744are parsed for correct syntax, however the result of checking of such format
2745strings is not yet defined, and is not carried out by this version of the
91ebb981
IS
2746compiler.
2747
2748The target may also provide additional types of format checks.
a2bec818
DJ
2749@xref{Target Format Checks,,Format Checks Specific to Particular
2750Target Machines}.
2751
c1f7febf
RK
2752@item format_arg (@var{string-index})
2753@cindex @code{format_arg} function attribute
84330467 2754@opindex Wformat-nonliteral
26f6672d
JM
2755The @code{format_arg} attribute specifies that a function takes a format
2756string for a @code{printf}, @code{scanf}, @code{strftime} or
2757@code{strfmon} style function and modifies it (for example, to translate
2758it into another language), so the result can be passed to a
2759@code{printf}, @code{scanf}, @code{strftime} or @code{strfmon} style
2760function (with the remaining arguments to the format function the same
2761as they would have been for the unmodified string). For example, the
2762declaration:
c1f7febf
RK
2763
2764@smallexample
2765extern char *
2766my_dgettext (char *my_domain, const char *my_format)
2767 __attribute__ ((format_arg (2)));
2768@end smallexample
2769
2770@noindent
26f6672d
JM
2771causes the compiler to check the arguments in calls to a @code{printf},
2772@code{scanf}, @code{strftime} or @code{strfmon} type function, whose
2773format string argument is a call to the @code{my_dgettext} function, for
2774consistency with the format string argument @code{my_format}. If the
2775@code{format_arg} attribute had not been specified, all the compiler
2776could tell in such calls to format functions would be that the format
2777string argument is not constant; this would generate a warning when
84330467 2778@option{-Wformat-nonliteral} is used, but the calls could not be checked
26f6672d 2779without the attribute.
c1f7febf
RK
2780
2781The parameter @var{string-index} specifies which argument is the format
f57a2e3a
BE
2782string argument (starting from one). Since non-static C++ methods have
2783an implicit @code{this} argument, the arguments of such methods should
2784be counted from two.
c1f7febf 2785
bafa88c2 2786The @code{format_arg} attribute allows you to identify your own
c417597c 2787functions that modify format strings, so that GCC can check the
26f6672d
JM
2788calls to @code{printf}, @code{scanf}, @code{strftime} or @code{strfmon}
2789type function whose operands are a call to one of your own function.
2790The compiler always treats @code{gettext}, @code{dgettext}, and
2791@code{dcgettext} in this manner except when strict ISO C support is
84330467 2792requested by @option{-ansi} or an appropriate @option{-std} option, or
e6e931b7
JM
2793@option{-ffreestanding} or @option{-fno-builtin}
2794is used. @xref{C Dialect Options,,Options
26f6672d 2795Controlling C Dialect}.
c1f7febf 2796
91ebb981
IS
2797For Objective-C dialects, the @code{format-arg} attribute may refer to an
2798@code{NSString} reference for compatibility with the @code{format} attribute
2799above.
2800
2801The target may also allow additional types in @code{format-arg} attributes.
2802@xref{Target Format Checks,,Format Checks Specific to Particular
2803Target Machines}.
2804
c8619b90 2805@item function_vector
561642fa 2806@cindex calling functions through the function vector on H8/300, M16C, M32C and SH2A processors
c8619b90
NS
2807Use this attribute on the H8/300, H8/300H, and H8S to indicate that the specified
2808function should be called through the function vector. Calling a
358a3dbc 2809function through the function vector reduces code size, however;
c8619b90
NS
2810the function vector has a limited size (maximum 128 entries on the H8/300
2811and 64 entries on the H8/300H and H8S) and shares space with the interrupt vector.
b34c7881 2812
845f4111 2813On SH2A targets, this attribute declares a function to be called using the
561642fa
AP
2814TBR relative addressing mode. The argument to this attribute is the entry
2815number of the same function in a vector table containing all the TBR
845f4111
OE
2816relative addressable functions. For correct operation the TBR must be setup
2817accordingly to point to the start of the vector table before any functions with
2818this attribute are invoked. Usually a good place to do the initialization is
2819the startup routine. The TBR relative vector table can have at max 256 function
358a3dbc 2820entries. The jumps to these functions are generated using a SH2A specific,
845f4111
OE
2821non delayed branch instruction JSR/N @@(disp8,TBR). You must use GAS and GLD
2822from GNU binutils version 2.7 or later for this attribute to work correctly.
b34c7881 2823
561642fa
AP
2824Please refer the example of M16C target, to see the use of this
2825attribute while declaring a function,
2826
358a3dbc
SL
2827In an application, for a function being called once, this attribute
2828saves at least 8 bytes of code; and if other successive calls are being
2829made to the same function, it saves 2 bytes of code per each of these
561642fa
AP
2830calls.
2831
5abd2125
JS
2832On M16C/M32C targets, the @code{function_vector} attribute declares a
2833special page subroutine call function. Use of this attribute reduces
2834the code size by 2 bytes for each call generated to the
2835subroutine. The argument to the attribute is the vector number entry
2836from the special page vector table which contains the 16 low-order
2837bits of the subroutine's entry address. Each vector table has special
c417597c 2838page number (18 to 255) that is used in @code{jsrs} instructions.
5abd2125 2839Jump addresses of the routines are generated by adding 0x0F0000 (in
6f46cb63
SL
2840case of M16C targets) or 0xFF0000 (in case of M32C targets), to the
28412-byte addresses set in the vector table. Therefore you need to ensure
5abd2125
JS
2842that all the special page vector routines should get mapped within the
2843address range 0x0F0000 to 0x0FFFFF (for M16C) and 0xFF0000 to 0xFFFFFF
2844(for M32C).
2845
358a3dbc 2846In the following example 2 bytes are saved for each call to
5abd2125
JS
2847function @code{foo}.
2848
2849@smallexample
2850void foo (void) __attribute__((function_vector(0x18)));
2851void foo (void)
2852@{
2853@}
2854
2855void bar (void)
2856@{
2857 foo();
2858@}
2859@end smallexample
2860
2861If functions are defined in one file and are called in another file,
2862then be sure to write this declaration in both files.
2863
2864This attribute is ignored for R8C target.
2865
eac188c5
GJL
2866@item ifunc ("@var{resolver}")
2867@cindex @code{ifunc} attribute
2868The @code{ifunc} attribute is used to mark a function as an indirect
2869function using the STT_GNU_IFUNC symbol type extension to the ELF
2870standard. This allows the resolution of the symbol value to be
2871determined dynamically at load time, and an optimized version of the
2872routine can be selected for the particular processor or other system
2873characteristics determined then. To use this attribute, first define
2874the implementation functions available, and a resolver function that
2875returns a pointer to the selected implementation function. The
2876implementation functions' declarations must match the API of the
2877function being implemented, the resolver's declaration is be a
2878function returning pointer to void function returning void:
2879
2880@smallexample
2881void *my_memcpy (void *dst, const void *src, size_t len)
2882@{
2883 @dots{}
2884@}
2885
2886static void (*resolve_memcpy (void)) (void)
2887@{
2888 return my_memcpy; // we'll just always select this routine
2889@}
2890@end smallexample
2891
c513ecbf 2892@noindent
eac188c5
GJL
2893The exported header file declaring the function the user calls would
2894contain:
2895
2896@smallexample
2897extern void *memcpy (void *, const void *, size_t);
2898@end smallexample
2899
c513ecbf 2900@noindent
eac188c5
GJL
2901allowing the user to call this as a regular function, unaware of the
2902implementation. Finally, the indirect function needs to be defined in
2903the same translation unit as the resolver function:
2904
2905@smallexample
2906void *memcpy (void *, const void *, size_t)
2907 __attribute__ ((ifunc ("resolve_memcpy")));
2908@end smallexample
2909
2910Indirect functions cannot be weak, and require a recent binutils (at
2911least version 2.20.1), and GNU C library (at least version 2.11.1).
2912
c8619b90
NS
2913@item interrupt
2914@cindex interrupt handler functions
5d5f6720
JR
2915Use this attribute on the ARC, ARM, AVR, CR16, Epiphany, M32C, M32R/D,
2916m68k, MeP, MIPS, MSP430, RL78, RX and Xstormy16 ports to indicate that
2917the specified function is an
358a3dbc 2918interrupt handler. The compiler generates function entry and exit
2bccb817 2919sequences suitable for use in an interrupt handler when this attribute
08b03910
JB
2920is present. With Epiphany targets it may also generate a special section with
2921code to initialize the interrupt vector table.
b34c7881 2922
80920132
ME
2923Note, interrupt handlers for the Blackfin, H8/300, H8/300H, H8S, MicroBlaze,
2924and SH processors can be specified via the @code{interrupt_handler} attribute.
b34c7881 2925
5d5f6720
JR
2926Note, on the ARC, you must specify the kind of interrupt to be handled
2927in a parameter to the interrupt attribute like this:
2928
2929@smallexample
2930void f () __attribute__ ((interrupt ("ilink1")));
2931@end smallexample
2932
2933Permissible values for this parameter are: @w{@code{ilink1}} and
2934@w{@code{ilink2}}.
2935
eac188c5
GJL
2936Note, on the AVR, the hardware globally disables interrupts when an
2937interrupt is executed. The first instruction of an interrupt handler
358a3dbc 2938declared with this attribute is a @code{SEI} instruction to
eac188c5 2939re-enable interrupts. See also the @code{signal} function attribute
bafa88c2 2940that does not insert a @code{SEI} instruction. If both @code{signal} and
eac188c5 2941@code{interrupt} are specified for the same function, @code{signal}
358a3dbc 2942is silently ignored.
9162542e 2943
c8619b90
NS
2944Note, for the ARM, you can specify the kind of interrupt to be handled by
2945adding an optional parameter to the interrupt attribute like this:
e23bd218
IR
2946
2947@smallexample
c8619b90 2948void f () __attribute__ ((interrupt ("IRQ")));
e23bd218
IR
2949@end smallexample
2950
bafa88c2
SL
2951@noindent
2952Permissible values for this parameter are: @code{IRQ}, @code{FIQ},
2953@code{SWI}, @code{ABORT} and @code{UNDEF}.
e23bd218 2954
7a085dce 2955On ARMv7-M the interrupt type is ignored, and the attribute means the function
6f46cb63 2956may be called with a word-aligned stack pointer.
5b3e6663 2957
cad055a4
NC
2958Note, for the MSP430 you can provide an argument to the interrupt
2959attribute which specifies a name or number. If the argument is a
2960number it indicates the slot in the interrupt vector table (0 - 31) to
2961which this handler should be assigned. If the argument is a name it
2962is treated as a symbolic name for the vector slot. These names should
2963match up with appropriate entries in the linker script. By default
2964the names @code{watchdog} for vector 26, @code{nmi} for vector 30 and
2965@code{reset} for vector 31 are recognised.
2966
2967You can also use the following function attributes to modify how
2968normal functions interact with interrupt functions:
2969
2970@table @code
2971@item critical
2972@cindex @code{critical} attribute
2973Critical functions disable interrupts upon entry and restore the
2974previous interrupt state upon exit. Critical functions cannot also
2975have the @code{naked} or @code{reentrant} attributes. They can have
2976the @code{interrupt} attribute.
2977
2978@item reentrant
2979@cindex @code{reentrant} attribute
2980Reentrant functions disable interrupts upon entry and enable them
2981upon exit. Reentrant functions cannot also have the @code{naked}
2982or @code{critical} attributes. They can have the @code{interrupt}
2983attribute.
2984
a005b5be
NC
2985@item wakeup
2986@cindex @code{wakeup} attribute
2987This attribute only applies to interrupt functions. It is silently
2988ignored if applied to a non-interrupt function. A wakeup interrupt
2989function will rouse the processor from any low-power state that it
2990might be in when the function exits.
2991
cad055a4
NC
2992@end table
2993
08b03910
JB
2994On Epiphany targets one or more optional parameters can be added like this:
2995
2996@smallexample
2997void __attribute__ ((interrupt ("dma0, dma1"))) universal_dma_handler ();
2998@end smallexample
2999
3000Permissible values for these parameters are: @w{@code{reset}},
3001@w{@code{software_exception}}, @w{@code{page_miss}},
3002@w{@code{timer0}}, @w{@code{timer1}}, @w{@code{message}},
3003@w{@code{dma0}}, @w{@code{dma1}}, @w{@code{wand}} and @w{@code{swi}}.
3004Multiple parameters indicate that multiple entries in the interrupt
566fb011 3005vector table should be initialized for this function, i.e.@: for each
358a3dbc 3006parameter @w{@var{name}}, a jump to the function is emitted in
08b03910 3007the section @w{ivt_entry_@var{name}}. The parameter(s) may be omitted
358a3dbc 3008entirely, in which case no interrupt vector table entry is provided.
08b03910
JB
3009
3010Note, on Epiphany targets, interrupts are enabled inside the function
3011unless the @code{disinterrupt} attribute is also specified.
3012
3013On Epiphany targets, you can also use the following attribute to
3014modify the behavior of an interrupt handler:
3015@table @code
3016@item forwarder_section
3017@cindex @code{forwarder_section} attribute
3018The interrupt handler may be in external memory which cannot be
3019reached by a branch instruction, so generate a local memory trampoline
3020to transfer control. The single parameter identifies the section where
358a3dbc 3021the trampoline is placed.
08b03910
JB
3022@end table
3023
3024The following examples are all valid uses of these attributes on
3025Epiphany targets:
3026@smallexample
3027void __attribute__ ((interrupt)) universal_handler ();
3028void __attribute__ ((interrupt ("dma1"))) dma1_handler ();
3029void __attribute__ ((interrupt ("dma0, dma1"))) universal_dma_handler ();
3030void __attribute__ ((interrupt ("timer0"), disinterrupt))
3031 fast_timer_handler ();
3032void __attribute__ ((interrupt ("dma0, dma1"), forwarder_section ("tramp")))
3033 external_dma_handler ();
3034@end smallexample
3035
e19da24c
CF
3036On MIPS targets, you can use the following attributes to modify the behavior
3037of an interrupt handler:
3038@table @code
3039@item use_shadow_register_set
3040@cindex @code{use_shadow_register_set} attribute
3041Assume that the handler uses a shadow register set, instead of
3042the main general-purpose registers.
3043
3044@item keep_interrupts_masked
3045@cindex @code{keep_interrupts_masked} attribute
3046Keep interrupts masked for the whole function. Without this attribute,
3047GCC tries to reenable interrupts for as much of the function as it can.
3048
3049@item use_debug_exception_return
3050@cindex @code{use_debug_exception_return} attribute
3051Return using the @code{deret} instruction. Interrupt handlers that don't
3052have this attribute return using @code{eret} instead.
3053@end table
3054
3055You can use any combination of these attributes, as shown below:
3056@smallexample
3057void __attribute__ ((interrupt)) v0 ();
3058void __attribute__ ((interrupt, use_shadow_register_set)) v1 ();
3059void __attribute__ ((interrupt, keep_interrupts_masked)) v2 ();
3060void __attribute__ ((interrupt, use_debug_exception_return)) v3 ();
3061void __attribute__ ((interrupt, use_shadow_register_set,
73b8bfe1 3062 keep_interrupts_masked)) v4 ();
e19da24c 3063void __attribute__ ((interrupt, use_shadow_register_set,
73b8bfe1 3064 use_debug_exception_return)) v5 ();
e19da24c 3065void __attribute__ ((interrupt, keep_interrupts_masked,
73b8bfe1 3066 use_debug_exception_return)) v6 ();
e19da24c 3067void __attribute__ ((interrupt, use_shadow_register_set,
73b8bfe1
RW
3068 keep_interrupts_masked,
3069 use_debug_exception_return)) v7 ();
e19da24c
CF
3070@end smallexample
3071
9304f876
CJW
3072On NDS32 target, this attribute is to indicate that the specified function
3073is an interrupt handler. The compiler will generate corresponding sections
3074for use in an interrupt handler. You can use the following attributes
3075to modify the behavior:
3076@table @code
3077@item nested
3078@cindex @code{nested} attribute
3079This interrupt service routine is interruptible.
3080@item not_nested
3081@cindex @code{not_nested} attribute
3082This interrupt service routine is not interruptible.
3083@item nested_ready
3084@cindex @code{nested_ready} attribute
3085This interrupt service routine is interruptible after @code{PSW.GIE}
3086(global interrupt enable) is set. This allows interrupt service routine to
3087finish some short critical code before enabling interrupts.
3088@item save_all
3089@cindex @code{save_all} attribute
3090The system will help save all registers into stack before entering
3091interrupt handler.
3092@item partial_save
3093@cindex @code{partial_save} attribute
3094The system will help save caller registers into stack before entering
3095interrupt handler.
3096@end table
3097
85b8555e 3098On RL78, use @code{brk_interrupt} instead of @code{interrupt} for
566fb011 3099handlers intended to be used with the @code{BRK} opcode (i.e.@: those
85b8555e
DD
3100that must end with @code{RETB} instead of @code{RETI}).
3101
69c7a374
DD
3102On RX targets, you may specify one or more vector numbers as arguments
3103to the attribute, as well as naming an alternate table name.
3104Parameters are handled sequentially, so one handler can be assigned to
3105multiple entries in multiple tables. One may also pass the magic
3106string @code{"$default"} which causes the function to be used for any
3107unfilled slots in the current table.
3108
3109This example shows a simple assignment of a function to one vector in
3110the default table (note that preprocessor macros may be used for
3111chip-specific symbolic vector names):
3112@smallexample
3113void __attribute__ ((interrupt (5))) txd1_handler ();
3114@end smallexample
3115
3116This example assigns a function to two slots in the default table
3117(using preprocessor macros defined elsewhere) and makes it the default
3118for the @code{dct} table:
3119@smallexample
3120void __attribute__ ((interrupt (RXD1_VECT,RXD2_VECT,"dct","$default")))
3121 txd1_handler ();
3122@end smallexample
3123
c8619b90 3124@item interrupt_handler
0d4a78eb
BS
3125@cindex interrupt handler functions on the Blackfin, m68k, H8/300 and SH processors
3126Use this attribute on the Blackfin, m68k, H8/300, H8/300H, H8S, and SH to
3127indicate that the specified function is an interrupt handler. The compiler
358a3dbc 3128generates function entry and exit sequences suitable for use in an
0d4a78eb
BS
3129interrupt handler when this attribute is present.
3130
a4242737
KH
3131@item interrupt_thread
3132@cindex interrupt thread functions on fido
3133Use this attribute on fido, a subarchitecture of the m68k, to indicate
3134that the specified function is an interrupt handler that is designed
3135to run as a thread. The compiler omits generate prologue/epilogue
3136sequences and replaces the return instruction with a @code{sleep}
3137instruction. This attribute is available only on fido.
3138
d8f8ca80
RR
3139@item isr
3140@cindex interrupt service routines on ARM
3141Use this attribute on ARM to write Interrupt Service Routines. This is an
3142alias to the @code{interrupt} attribute above.
3143
0d4a78eb
BS
3144@item kspisusp
3145@cindex User stack pointer in interrupts on the Blackfin
3146When used together with @code{interrupt_handler}, @code{exception_handler}
358a3dbc 3147or @code{nmi_handler}, code is generated to load the stack pointer
0d4a78eb 3148from the USP register in the function prologue.
72954a4f 3149
4af797b5
JZ
3150@item l1_text
3151@cindex @code{l1_text} function attribute
3152This attribute specifies a function to be placed into L1 Instruction
358a3dbc 3153SRAM@. The function is put into a specific section named @code{.l1.text}.
4af797b5 3154With @option{-mfdpic}, function calls with a such function as the callee
358a3dbc 3155or caller uses inlined PLT.
4af797b5 3156
603bb63e
BS
3157@item l2
3158@cindex @code{l2} function attribute
3159On the Blackfin, this attribute specifies a function to be placed into L2
358a3dbc
SL
3160SRAM. The function is put into a specific section named
3161@code{.l1.text}. With @option{-mfdpic}, callers of such functions use
603bb63e
BS
3162an inlined PLT.
3163
46a4da10
JH
3164@item leaf
3165@cindex @code{leaf} function attribute
3166Calls to external functions with this attribute must return to the current
2b0d3573
RW
3167compilation unit only by return or by exception handling. In particular, leaf
3168functions are not allowed to call callback function passed to it from the current
46a4da10 3169compilation unit or directly call functions exported by the unit or longjmp
2b0d3573
RW
3170into the unit. Leaf function might still call functions from other compilation
3171units and thus they are not necessarily leaf in the sense that they contain no
46a4da10
JH
3172function calls at all.
3173
3174The attribute is intended for library functions to improve dataflow analysis.
2b0d3573
RW
3175The compiler takes the hint that any data not escaping the current compilation unit can
3176not be used or modified by the leaf function. For example, the @code{sin} function
3177is a leaf function, but @code{qsort} is not.
46a4da10 3178
2b0d3573
RW
3179Note that leaf functions might invoke signals and signal handlers might be
3180defined in the current compilation unit and use static variables. The only
46a4da10
JH
3181compliant way to write such a signal handler is to declare such variables
3182@code{volatile}.
3183
2b0d3573 3184The attribute has no effect on functions defined within the current compilation
46a4da10 3185unit. This is to allow easy merging of multiple compilation units into one,
566fb011 3186for example, by using the link-time optimization. For this reason the
46a4da10
JH
3187attribute is not allowed on types to annotate indirect calls.
3188
5d5f6720
JR
3189@item long_call/medium_call/short_call
3190@cindex indirect calls on ARC
c8619b90 3191@cindex indirect calls on ARM
5d5f6720 3192@cindex indirect calls on Epiphany
5c0b3021 3193These attributes specify how a particular function is called on
5d5f6720
JR
3194ARC, ARM and Epiphany - with @code{medium_call} being specific to ARC.
3195These attributes override the
3196@option{-mlong-calls} (@pxref{ARM Options} and @ref{ARC Options})
3197and @option{-mmedium-calls} (@pxref{ARC Options})
3198command-line switches and @code{#pragma long_calls} settings. For ARM, the
87c365a4
NS
3199@code{long_call} attribute indicates that the function might be far
3200away from the call site and require a different (more expensive)
3201calling sequence. The @code{short_call} attribute always places
c8619b90
NS
3202the offset to the function from the call site into the @samp{BL}
3203instruction directly.
72954a4f 3204
5d5f6720
JR
3205For ARC, a function marked with the @code{long_call} attribute is
3206always called using register-indirect jump-and-link instructions,
3207thereby enabling the called function to be placed anywhere within the
320832-bit address space. A function marked with the @code{medium_call}
3209attribute will always be close enough to be called with an unconditional
3210branch-and-link instruction, which has a 25-bit offset from
3211the call site. A function marked with the @code{short_call}
3212attribute will always be close enough to be called with a conditional
3213branch-and-link instruction, which has a 21-bit offset from
3214the call site.
3215
c8619b90
NS
3216@item longcall/shortcall
3217@cindex functions called via pointer on the RS/6000 and PowerPC
87c365a4
NS
3218On the Blackfin, RS/6000 and PowerPC, the @code{longcall} attribute
3219indicates that the function might be far away from the call site and
3220require a different (more expensive) calling sequence. The
3221@code{shortcall} attribute indicates that the function is always close
3222enough for the shorter calling sequence to be used. These attributes
3223override both the @option{-mlongcall} switch and, on the RS/6000 and
3224PowerPC, the @code{#pragma longcall} setting.
72954a4f 3225
c8619b90
NS
3226@xref{RS/6000 and PowerPC Options}, for more information on whether long
3227calls are necessary.
c1f7febf 3228
cd3a59b3 3229@item long_call/near/far
4dbdb061 3230@cindex indirect calls on MIPS
cd3a59b3
SL
3231These attributes specify how a particular function is called on MIPS@.
3232The attributes override the @option{-mlong-calls} (@pxref{MIPS Options})
3233command-line switch. The @code{long_call} and @code{far} attributes are
3234synonyms, and cause the compiler to always call
4dbdb061 3235the function by first loading its address into a register, and then using
cd3a59b3 3236the contents of that register. The @code{near} attribute has the opposite
ff2ce160 3237effect; it specifies that non-PIC calls should be made using the more
cd3a59b3 3238efficient @code{jal} instruction.
4dbdb061 3239
140592a0
AG
3240@item malloc
3241@cindex @code{malloc} attribute
ee526ea7
PE
3242This tells the compiler that a function is @code{malloc}-like, i.e.,
3243that the pointer @var{P} returned by the function cannot alias any
3244other pointer valid when the function returns, and moreover no
3245pointers to valid objects occur in any storage addressed by @var{P}.
3246
3247Using this attribute can improve optimization. Functions like
3248@code{malloc} and @code{calloc} have this property because they return
3249a pointer to uninitialized or zeroed-out storage. However, functions
3250like @code{realloc} do not have this property, as they can return a
3251pointer to storage containing pointers.
140592a0 3252
f9e4a411
SL
3253@item mips16/nomips16
3254@cindex @code{mips16} attribute
3255@cindex @code{nomips16} attribute
3256
3257On MIPS targets, you can use the @code{mips16} and @code{nomips16}
3258function attributes to locally select or turn off MIPS16 code generation.
ff2ce160
MS
3259A function with the @code{mips16} attribute is emitted as MIPS16 code,
3260while MIPS16 code generation is disabled for functions with the
3261@code{nomips16} attribute. These attributes override the
f9e4a411 3262@option{-mips16} and @option{-mno-mips16} options on the command line
ff2ce160 3263(@pxref{MIPS Options}).
f9e4a411
SL
3264
3265When compiling files containing mixed MIPS16 and non-MIPS16 code, the
3266preprocessor symbol @code{__mips16} reflects the setting on the command line,
3267not that within individual functions. Mixed MIPS16 and non-MIPS16 code
3268may interact badly with some GCC extensions such as @code{__builtin_apply}
3269(@pxref{Constructing Calls}).
3270
22c4c869
CM
3271@item micromips/nomicromips
3272@cindex @code{micromips} attribute
3273@cindex @code{nomicromips} attribute
3274
3275On MIPS targets, you can use the @code{micromips} and @code{nomicromips}
3276function attributes to locally select or turn off microMIPS code generation.
3277A function with the @code{micromips} attribute is emitted as microMIPS code,
3278while microMIPS code generation is disabled for functions with the
3279@code{nomicromips} attribute. These attributes override the
3280@option{-mmicromips} and @option{-mno-micromips} options on the command line
3281(@pxref{MIPS Options}).
3282
3283When compiling files containing mixed microMIPS and non-microMIPS code, the
3284preprocessor symbol @code{__mips_micromips} reflects the setting on the
3285command line,
3286not that within individual functions. Mixed microMIPS and non-microMIPS code
3287may interact badly with some GCC extensions such as @code{__builtin_apply}
3288(@pxref{Constructing Calls}).
3289
c8619b90
NS
3290@item model (@var{model-name})
3291@cindex function addressability on the M32R/D
3292@cindex variable addressability on the IA-64
3293
3294On the M32R/D, use this attribute to set the addressability of an
3295object, and of the code generated for a function. The identifier
3296@var{model-name} is one of @code{small}, @code{medium}, or
3297@code{large}, representing each of the code models.
3298
3299Small model objects live in the lower 16MB of memory (so that their
3300addresses can be loaded with the @code{ld24} instruction), and are
3301callable with the @code{bl} instruction.
3302
3303Medium model objects may live anywhere in the 32-bit address space (the
358a3dbc 3304compiler generates @code{seth/add3} instructions to load their addresses),
c8619b90
NS
3305and are callable with the @code{bl} instruction.
3306
3307Large model objects may live anywhere in the 32-bit address space (the
358a3dbc
SL
3308compiler generates @code{seth/add3} instructions to load their addresses),
3309and may not be reachable with the @code{bl} instruction (the compiler
3310generates the much slower @code{seth/add3/jl} instruction sequence).
c8619b90
NS
3311
3312On IA-64, use this attribute to set the addressability of an object.
3313At present, the only supported identifier for @var{model-name} is
3314@code{small}, indicating addressability via ``small'' (22-bit)
3315addresses (so that their addresses can be loaded with the @code{addl}
3316instruction). Caveat: such addressing is by definition not position
3317independent and hence this attribute must not be used for objects
3318defined by shared libraries.
3319
7c800926 3320@item ms_abi/sysv_abi
f9ac6b1e 3321@cindex @code{ms_abi} attribute
7c800926
KT
3322@cindex @code{sysv_abi} attribute
3323
2fe83a0c
KT
3324On 32-bit and 64-bit (i?86|x86_64)-*-* targets, you can use an ABI attribute
3325to indicate which calling convention should be used for a function. The
3326@code{ms_abi} attribute tells the compiler to use the Microsoft ABI,
3327while the @code{sysv_abi} attribute tells the compiler to use the ABI
3328used on GNU/Linux and other systems. The default is to use the Microsoft ABI
3329when targeting Windows. On all other systems, the default is the x86/AMD ABI.
7c800926 3330
566fb011 3331Note, the @code{ms_abi} attribute for Microsoft Windows 64-bit targets currently
2fe83a0c 3332requires the @option{-maccumulate-outgoing-args} option.
7c800926 3333
628c4eee
KT
3334@item callee_pop_aggregate_return (@var{number})
3335@cindex @code{callee_pop_aggregate_return} attribute
3336
bafa88c2
SL
3337On 32-bit i?86-*-* targets, you can use this attribute to control how
3338aggregates are returned in memory. If the caller is responsible for
3339popping the hidden pointer together with the rest of the arguments, specify
3340@var{number} equal to zero. If callee is responsible for popping the
3341hidden pointer, specify @var{number} equal to one.
628c4eee 3342
bafa88c2
SL
3343The default i386 ABI assumes that the callee pops the
3344stack for hidden pointer. However, on 32-bit i386 Microsoft Windows targets,
566fb011 3345the compiler assumes that the
2fe83a0c
KT
3346caller pops the stack for hidden pointer.
3347
afd2c302
SD
3348@item ms_hook_prologue
3349@cindex @code{ms_hook_prologue} attribute
3350
6f46cb63 3351On 32-bit i[34567]86-*-* targets and 64-bit x86_64-*-* targets, you can use
566fb011 3352this function attribute to make GCC generate the ``hot-patching'' function
135a687e
KT
3353prologue used in Win32 API functions in Microsoft Windows XP Service Pack 2
3354and newer.
afd2c302 3355
d0de9e13
DV
3356@item hotpatch [(@var{prologue-halfwords})]
3357@cindex @code{hotpatch} attribute
3358
3359On S/390 System z targets, you can use this function attribute to
3360make GCC generate a ``hot-patching'' function prologue. The
3361@code{hotpatch} has no effect on funtions that are explicitly
3362inline. If the @option{-mhotpatch} or @option{-mno-hotpatch}
3363command-line option is used at the same time, the @code{hotpatch}
3364attribute takes precedence. If an argument is given, the maximum
3365allowed value is 1000000.
3366
c8619b90
NS
3367@item naked
3368@cindex function without a prologue/epilogue code
3a96c7cc
DW
3369This attribute is available on the ARM, AVR, MCORE, MSP430, NDS32,
3370RL78, RX and SPU ports. It allows the compiler to construct the
3371requisite function declaration, while allowing the body of the
3372function to be assembly code. The specified function will not have
3373prologue/epilogue sequences generated by the compiler. Only Basic
3374@code{asm} statements can safely be included in naked functions
3375(@pxref{Basic Asm}). While using Extended @code{asm} or a mixture of
3376Basic @code{asm} and ``C'' code may appear to work, they cannot be
3377depended upon to work reliably and are not supported.
c8619b90
NS
3378
3379@item near
c417597c 3380@cindex functions that do not handle memory bank switching on 68HC11/68HC12
c8619b90
NS
3381On 68HC11 and 68HC12 the @code{near} attribute causes the compiler to
3382use the normal calling convention based on @code{jsr} and @code{rts}.
3383This attribute can be used to cancel the effect of the @option{-mlong-calls}
3384option.
3385
e2491744
DD
3386On MeP targets this attribute causes the compiler to assume the called
3387function is close enough to use the normal calling convention,
bafa88c2 3388overriding the @option{-mtf} command-line option.
e2491744 3389
0d4a78eb
BS
3390@item nesting
3391@cindex Allow nesting in an interrupt handler on the Blackfin processor.
3392Use this attribute together with @code{interrupt_handler},
3393@code{exception_handler} or @code{nmi_handler} to indicate that the function
3394entry code should enable nested interrupts or exceptions.
3395
3396@item nmi_handler
3397@cindex NMI handler functions on the Blackfin processor
3398Use this attribute on the Blackfin to indicate that the specified function
358a3dbc 3399is an NMI handler. The compiler generates function entry and
0d4a78eb
BS
3400exit sequences suitable for use in an NMI handler when this
3401attribute is present.
3402
22c4c869
CM
3403@item nocompression
3404@cindex @code{nocompression} attribute
3405On MIPS targets, you can use the @code{nocompression} function attribute
3406to locally turn off MIPS16 and microMIPS code generation. This attribute
3407overrides the @option{-mips16} and @option{-mmicromips} options on the
3408command line (@pxref{MIPS Options}).
3409
c8619b90
NS
3410@item no_instrument_function
3411@cindex @code{no_instrument_function} function attribute
3412@opindex finstrument-functions
358a3dbc
SL
3413If @option{-finstrument-functions} is given, profiling function calls are
3414generated at entry and exit of most user-compiled functions.
3415Functions with this attribute are not so instrumented.
c8619b90 3416
7458026b
ILT
3417@item no_split_stack
3418@cindex @code{no_split_stack} function attribute
3419@opindex fsplit-stack
358a3dbc 3420If @option{-fsplit-stack} is given, functions have a small
7458026b 3421prologue which decides whether to split the stack. Functions with the
358a3dbc 3422@code{no_split_stack} attribute do not have that prologue, and thus
7458026b
ILT
3423may run with only a small amount of stack space available.
3424
c8619b90
NS
3425@item noinline
3426@cindex @code{noinline} function attribute
3427This function attribute prevents a function from being considered for
3428inlining.
ccd2a21e
HPN
3429@c Don't enumerate the optimizations by name here; we try to be
3430@c future-compatible with this mechanism.
3431If the function does not have side-effects, there are optimizations
c417597c 3432other than inlining that cause function calls to be optimized away,
ccd2a21e
HPN
3433although the function call is live. To keep such calls from being
3434optimized away, put
3435@smallexample
3436asm ("");
3437@end smallexample
c513ecbf
SL
3438
3439@noindent
ccd2a21e
HPN
3440(@pxref{Extended Asm}) in the called function, to serve as a special
3441side-effect.
c8619b90 3442
86631ea3
MJ
3443@item noclone
3444@cindex @code{noclone} function attribute
3445This function attribute prevents a function from being considered for
c417597c 3446cloning---a mechanism that produces specialized copies of functions
86631ea3
MJ
3447and which is (currently) performed by interprocedural constant
3448propagation.
3449
c8619b90
NS
3450@item nonnull (@var{arg-index}, @dots{})
3451@cindex @code{nonnull} function attribute
3452The @code{nonnull} attribute specifies that some function parameters should
3453be non-null pointers. For instance, the declaration:
c1f7febf
RK
3454
3455@smallexample
c8619b90
NS
3456extern void *
3457my_memcpy (void *dest, const void *src, size_t len)
6ccde948 3458 __attribute__((nonnull (1, 2)));
c1f7febf
RK
3459@end smallexample
3460
c8619b90
NS
3461@noindent
3462causes the compiler to check that, in calls to @code{my_memcpy},
3463arguments @var{dest} and @var{src} are non-null. If the compiler
3464determines that a null pointer is passed in an argument slot marked
3465as non-null, and the @option{-Wnonnull} option is enabled, a warning
3466is issued. The compiler may also choose to make optimizations based
358a3dbc 3467on the knowledge that certain function arguments will never be null.
af3e86c2 3468
c8619b90
NS
3469If no argument index list is given to the @code{nonnull} attribute,
3470all pointer arguments are marked as non-null. To illustrate, the
3471following declaration is equivalent to the previous example:
47bd70b5
JJ
3472
3473@smallexample
c8619b90
NS
3474extern void *
3475my_memcpy (void *dest, const void *src, size_t len)
6ccde948 3476 __attribute__((nonnull));
47bd70b5
JJ
3477@end smallexample
3478
7861b648
AK
3479@item no_reorder
3480@cindex @code{no_reorder} function or variable attribute
3481Do not reorder functions or variables marked @code{no_reorder}
3482against each other or top level assembler statements the executable.
3483The actual order in the program will depend on the linker command
3484line. Static variables marked like this are also not removed.
3485This has a similar effect
3486as the @option{-fno-toplevel-reorder} option, but only applies to the
3487marked symbols.
3488
8d28e3fc 3489@item returns_nonnull
826cacfe
MG
3490@cindex @code{returns_nonnull} function attribute
3491The @code{returns_nonnull} attribute specifies that the function
3492return value should be a non-null pointer. For instance, the declaration:
3493
3494@smallexample
3495extern void *
3496mymalloc (size_t len) __attribute__((returns_nonnull));
3497@end smallexample
3498
3499@noindent
3500lets the compiler optimize callers based on the knowledge
3501that the return value will never be null.
3502
c8619b90
NS
3503@item noreturn
3504@cindex @code{noreturn} function attribute
3505A few standard library functions, such as @code{abort} and @code{exit},
3506cannot return. GCC knows this automatically. Some programs define
3507their own functions that never return. You can declare them
3508@code{noreturn} to tell the compiler this fact. For example,
9e8aab55 3509
c8619b90
NS
3510@smallexample
3511@group
3512void fatal () __attribute__ ((noreturn));
d5c4db17 3513
c8619b90
NS
3514void
3515fatal (/* @r{@dots{}} */)
3516@{
3517 /* @r{@dots{}} */ /* @r{Print error message.} */ /* @r{@dots{}} */
3518 exit (1);
3519@}
3520@end group
3521@end smallexample
9e8aab55 3522
c8619b90
NS
3523The @code{noreturn} keyword tells the compiler to assume that
3524@code{fatal} cannot return. It can then optimize without regard to what
3525would happen if @code{fatal} ever did return. This makes slightly
3526better code. More importantly, it helps avoid spurious warnings of
3527uninitialized variables.
9e8aab55 3528
c8619b90
NS
3529The @code{noreturn} keyword does not affect the exceptional path when that
3530applies: a @code{noreturn}-marked function may still return to the caller
2e9522f4 3531by throwing an exception or calling @code{longjmp}.
9e8aab55 3532
c8619b90
NS
3533Do not assume that registers saved by the calling function are
3534restored before calling the @code{noreturn} function.
47bd70b5 3535
c8619b90
NS
3536It does not make sense for a @code{noreturn} function to have a return
3537type other than @code{void}.
c1f7febf 3538
c8619b90
NS
3539The attribute @code{noreturn} is not implemented in GCC versions
3540earlier than 2.5. An alternative way to declare that a function does
3541not return, which works in the current version and in some older
3542versions, is as follows:
5d34c8e9 3543
c8619b90
NS
3544@smallexample
3545typedef void voidfn ();
c1f7febf 3546
c8619b90
NS
3547volatile voidfn fatal;
3548@end smallexample
e91f04de 3549
c513ecbf 3550@noindent
a1e73046
PC
3551This approach does not work in GNU C++.
3552
c8619b90
NS
3553@item nothrow
3554@cindex @code{nothrow} function attribute
3555The @code{nothrow} attribute is used to inform the compiler that a
3556function cannot throw an exception. For example, most functions in
3557the standard C library can be guaranteed not to throw an exception
3558with the notable exceptions of @code{qsort} and @code{bsearch} that
3559take function pointer arguments. The @code{nothrow} attribute is not
3f3174b6 3560implemented in GCC versions earlier than 3.3.
c1f7febf 3561
845f4111
OE
3562@item nosave_low_regs
3563@cindex @code{nosave_low_regs} attribute
3564Use this attribute on SH targets to indicate that an @code{interrupt_handler}
3565function should not save and restore registers R0..R7. This can be used on SH3*
c417597c 3566and SH4* targets that have a second R0..R7 register bank for non-reentrant
845f4111
OE
3567interrupt handlers.
3568
ab442df7
MM
3569@item optimize
3570@cindex @code{optimize} function attribute
3571The @code{optimize} attribute is used to specify that a function is to
3572be compiled with different optimization options than specified on the
3573command line. Arguments can either be numbers or strings. Numbers
3574are assumed to be an optimization level. Strings that begin with
3575@code{O} are assumed to be an optimization option, while other options
3576are assumed to be used with a @code{-f} prefix. You can also use the
3577@samp{#pragma GCC optimize} pragma to set the optimization options
3578that affect more than one function.
3579@xref{Function Specific Option Pragmas}, for details about the
e3606f3b 3580@samp{#pragma GCC optimize} pragma.
ab442df7 3581
bafa88c2 3582This can be used for instance to have frequently-executed functions
ab442df7 3583compiled with more aggressive optimization options that produce faster
bafa88c2 3584and larger code, while other functions can be compiled with less
5779e713 3585aggressive options.
ab442df7 3586
3d33d151
AS
3587@item OS_main/OS_task
3588@cindex @code{OS_main} AVR function attribute
3589@cindex @code{OS_task} AVR function attribute
3590On AVR, functions with the @code{OS_main} or @code{OS_task} attribute
3591do not save/restore any call-saved register in their prologue/epilogue.
3592
3593The @code{OS_main} attribute can be used when there @emph{is
3594guarantee} that interrupts are disabled at the time when the function
358a3dbc 3595is entered. This saves resources when the stack pointer has to be
3d33d151
AS
3596changed to set up a frame for local variables.
3597
3598The @code{OS_task} attribute can be used when there is @emph{no
3599guarantee} that interrupts are disabled at that time when the function
3600is entered like for, e@.g@. task functions in a multi-threading operating
358a3dbc 3601system. In that case, changing the stack pointer register is
3d33d151
AS
3602guarded by save/clear/restore of the global interrupt enable flag.
3603
aa9ec4db 3604The differences to the @code{naked} function attribute are:
3d33d151
AS
3605@itemize @bullet
3606@item @code{naked} functions do not have a return instruction whereas
358a3dbc 3607@code{OS_main} and @code{OS_task} functions have a @code{RET} or
3d33d151
AS
3608@code{RETI} return instruction.
3609@item @code{naked} functions do not set up a frame for local variables
3610or a frame pointer whereas @code{OS_main} and @code{OS_task} do this
3611as needed.
3612@end itemize
3613
14a782c8
RE
3614@item pcs
3615@cindex @code{pcs} function attribute
3616
3617The @code{pcs} attribute can be used to control the calling convention
3618used for a function on ARM. The attribute takes an argument that specifies
3619the calling convention to use.
3620
c417597c 3621When compiling using the AAPCS ABI (or a variant of it) then valid
14a782c8
RE
3622values for the argument are @code{"aapcs"} and @code{"aapcs-vfp"}. In
3623order to use a variant other than @code{"aapcs"} then the compiler must
3624be permitted to use the appropriate co-processor registers (i.e., the
3625VFP registers must be available in order to use @code{"aapcs-vfp"}).
3626For example,
3627
3628@smallexample
3629/* Argument passed in r0, and result returned in r0+r1. */
3630double f2d (float) __attribute__((pcs("aapcs")));
3631@end smallexample
3632
3633Variadic functions always use the @code{"aapcs"} calling convention and
358a3dbc 3634the compiler rejects attempts to specify an alternative.
14a782c8 3635
c8619b90
NS
3636@item pure
3637@cindex @code{pure} function attribute
3638Many functions have no effects except the return value and their
3639return value depends only on the parameters and/or global variables.
3640Such a function can be subject
3641to common subexpression elimination and loop optimization just as an
3642arithmetic operator would be. These functions should be declared
3643with the attribute @code{pure}. For example,
a5c76ee6 3644
c8619b90
NS
3645@smallexample
3646int square (int) __attribute__ ((pure));
3647@end smallexample
c1f7febf 3648
c8619b90
NS
3649@noindent
3650says that the hypothetical function @code{square} is safe to call
3651fewer times than the program says.
c27ba912 3652
c8619b90
NS
3653Some of common examples of pure functions are @code{strlen} or @code{memcmp}.
3654Interesting non-pure functions are functions with infinite loops or those
3655depending on volatile memory or other system resource, that may change between
3656two consecutive calls (such as @code{feof} in a multithreading environment).
c1f7febf 3657
c8619b90
NS
3658The attribute @code{pure} is not implemented in GCC versions earlier
3659than 2.96.
c1f7febf 3660
52bf96d2
JH
3661@item hot
3662@cindex @code{hot} function attribute
e45abe1f
RH
3663The @code{hot} attribute on a function is used to inform the compiler that
3664the function is a hot spot of the compiled program. The function is
883755a1
DW
3665optimized more aggressively and on many targets it is placed into a special
3666subsection of the text section so all hot functions appear close together,
e45abe1f 3667improving locality.
52bf96d2
JH
3668
3669When profile feedback is available, via @option{-fprofile-use}, hot functions
3670are automatically detected and this attribute is ignored.
3671
e45abe1f
RH
3672The @code{hot} attribute on functions is not implemented in GCC versions
3673earlier than 4.3.
3674
52bf96d2
JH
3675@item cold
3676@cindex @code{cold} function attribute
e45abe1f
RH
3677The @code{cold} attribute on functions is used to inform the compiler that
3678the function is unlikely to be executed. The function is optimized for
883755a1
DW
3679size rather than speed and on many targets it is placed into a special
3680subsection of the text section so all cold functions appear close together,
e45abe1f 3681improving code locality of non-cold parts of program. The paths leading
883755a1 3682to calls of cold functions within code are marked as unlikely by the branch
e45abe1f
RH
3683prediction mechanism. It is thus useful to mark functions used to handle
3684unlikely conditions, such as @code{perror}, as cold to improve optimization
3685of hot functions that do call marked functions in rare occasions.
3686
3687When profile feedback is available, via @option{-fprofile-use}, cold functions
52bf96d2
JH
3688are automatically detected and this attribute is ignored.
3689
e45abe1f
RH
3690The @code{cold} attribute on functions is not implemented in GCC versions
3691earlier than 4.3.
3692
e664c61c
KS
3693@item no_sanitize_address
3694@itemx no_address_safety_analysis
3695@cindex @code{no_sanitize_address} function attribute
3696The @code{no_sanitize_address} attribute on functions is used
77bc5132
JJ
3697to inform the compiler that it should not instrument memory accesses
3698in the function when compiling with the @option{-fsanitize=address} option.
e664c61c
KS
3699The @code{no_address_safety_analysis} is a deprecated alias of the
3700@code{no_sanitize_address} attribute, new code should use
3701@code{no_sanitize_address}.
77bc5132 3702
ce6923c5
MP
3703@item no_sanitize_undefined
3704@cindex @code{no_sanitize_undefined} function attribute
3705The @code{no_sanitize_undefined} attribute on functions is used
3706to inform the compiler that it should not check for undefined behavior
3707in the function when compiling with the @option{-fsanitize=undefined} option.
3708
d5e254e1
IE
3709@item bnd_legacy
3710@cindex @code{bnd_legacy} function attribute
3711The @code{bnd_legacy} attribute on functions is used to inform
3712compiler that function should not be instrumented when compiled
3713with @option{-fcheck-pointer-bounds} option.
3714
3715@item bnd_instrument
3716@cindex @code{bnd_instrument} function attribute
3717The @code{bnd_instrument} attribute on functions is used to inform
3718compiler that function should be instrumented when compiled
3719with @option{-fchkp-instrument-marked-only} option.
3720
c8619b90
NS
3721@item regparm (@var{number})
3722@cindex @code{regparm} attribute
3723@cindex functions that are passed arguments in registers on the 386
3724On the Intel 386, the @code{regparm} attribute causes the compiler to
2f84b963
RG
3725pass arguments number one to @var{number} if they are of integral type
3726in registers EAX, EDX, and ECX instead of on the stack. Functions that
358a3dbc 3727take a variable number of arguments continue to be passed all of their
c8619b90 3728arguments on the stack.
6d3d9133 3729
c8619b90
NS
3730Beware that on some ELF systems this attribute is unsuitable for
3731global functions in shared libraries with lazy binding (which is the
358a3dbc 3732default). Lazy binding sends the first call via resolving code in
c8619b90
NS
3733the loader, which might assume EAX, EDX and ECX can be clobbered, as
3734per the standard calling conventions. Solaris 8 is affected by this.
bafa88c2
SL
3735Systems with the GNU C Library version 2.1 or higher
3736and FreeBSD are believed to be
21440b2d 3737safe since the loaders there save EAX, EDX and ECX. (Lazy binding can be
c8619b90
NS
3738disabled with the linker or the loader if desired, to avoid the
3739problem.)
6d3d9133 3740
9304f876
CJW
3741@item reset
3742@cindex reset handler functions
3743Use this attribute on the NDS32 target to indicate that the specified function
3744is a reset handler. The compiler will generate corresponding sections
3745for use in a reset handler. You can use the following attributes
3746to provide extra exception handling:
3747@table @code
3748@item nmi
3749@cindex @code{nmi} attribute
3750Provide a user-defined function to handle NMI exception.
3751@item warm
3752@cindex @code{warm} attribute
3753Provide a user-defined function to handle warm reset exception.
3754@end table
3755
2f84b963
RG
3756@item sseregparm
3757@cindex @code{sseregparm} attribute
3758On the Intel 386 with SSE support, the @code{sseregparm} attribute
6f46cb63 3759causes the compiler to pass up to 3 floating-point arguments in
2f84b963 3760SSE registers instead of on the stack. Functions that take a
358a3dbc 3761variable number of arguments continue to pass all of their
6f46cb63 3762floating-point arguments on the stack.
2f84b963 3763
33932946
SH
3764@item force_align_arg_pointer
3765@cindex @code{force_align_arg_pointer} attribute
3766On the Intel x86, the @code{force_align_arg_pointer} attribute may be
3767applied to individual function definitions, generating an alternate
566fb011 3768prologue and epilogue that realigns the run-time stack if necessary.
2e3f842f
L
3769This supports mixing legacy codes that run with a 4-byte aligned stack
3770with modern codes that keep a 16-byte stack for SSE compatibility.
33932946 3771
845f4111
OE
3772@item renesas
3773@cindex @code{renesas} attribute
3774On SH targets this attribute specifies that the function or struct follows the
3775Renesas ABI.
3776
561642fa
AP
3777@item resbank
3778@cindex @code{resbank} attribute
3779On the SH2A target, this attribute enables the high-speed register
3780saving and restoration using a register bank for @code{interrupt_handler}
a640c13b 3781routines. Saving to the bank is performed automatically after the CPU
561642fa
AP
3782accepts an interrupt that uses a register bank.
3783
3784The nineteen 32-bit registers comprising general register R0 to R14,
3785control register GBR, and system registers MACH, MACL, and PR and the
3786vector table address offset are saved into a register bank. Register
3787banks are stacked in first-in last-out (FILO) sequence. Restoration
3788from the bank is executed by issuing a RESBANK instruction.
3789
6e9a3221
AN
3790@item returns_twice
3791@cindex @code{returns_twice} attribute
3792The @code{returns_twice} attribute tells the compiler that a function may
358a3dbc
SL
3793return more than one time. The compiler ensures that all registers
3794are dead before calling such a function and emits a warning about
6e9a3221
AN
3795the variables that may be clobbered after the second return from the
3796function. Examples of such functions are @code{setjmp} and @code{vfork}.
3797The @code{longjmp}-like counterpart of such function, if any, might need
3798to be marked with the @code{noreturn} attribute.
3799
c8619b90 3800@item saveall
0d4a78eb
BS
3801@cindex save all registers on the Blackfin, H8/300, H8/300H, and H8S
3802Use this attribute on the Blackfin, H8/300, H8/300H, and H8S to indicate that
c8619b90
NS
3803all registers except the stack pointer should be saved in the prologue
3804regardless of whether they are used or not.
6d3d9133 3805
80920132
ME
3806@item save_volatiles
3807@cindex save volatile registers on the MicroBlaze
3808Use this attribute on the MicroBlaze to indicate that the function is
ff2ce160 3809an interrupt handler. All volatile registers (in addition to non-volatile
358a3dbc 3810registers) are saved in the function prologue. If the function is a leaf
ff2ce160
MS
3811function, only volatiles used by the function are saved. A normal function
3812return is generated instead of a return from interrupt.
80920132 3813
86498dba
AA
3814@item break_handler
3815@cindex break handler functions
3816Use this attribute on the MicroBlaze ports to indicate that
3817the specified function is an break handler. The compiler generates function
3818entry and exit sequences suitable for use in an break handler when this
3819attribute is present. The return from @code{break_handler} is done through
3820the @code{rtbd} instead of @code{rtsd}.
3821
3822@smallexample
3823void f () __attribute__ ((break_handler));
3824@end smallexample
3825
c8619b90
NS
3826@item section ("@var{section-name}")
3827@cindex @code{section} function attribute
3828Normally, the compiler places the code it generates in the @code{text} section.
3829Sometimes, however, you need additional sections, or you need certain
3830particular functions to appear in special sections. The @code{section}
3831attribute specifies that a function lives in a particular section.
3832For example, the declaration:
6d3d9133
NC
3833
3834@smallexample
c8619b90 3835extern void foobar (void) __attribute__ ((section ("bar")));
6d3d9133
NC
3836@end smallexample
3837
c8619b90
NS
3838@noindent
3839puts the function @code{foobar} in the @code{bar} section.
6d3d9133 3840
c8619b90
NS
3841Some file formats do not support arbitrary sections so the @code{section}
3842attribute is not available on all platforms.
3843If you need to map the entire contents of a module to a particular
3844section, consider using the facilities of the linker instead.
3845
3d091dac
KG
3846@item sentinel
3847@cindex @code{sentinel} function attribute
254986c7
KG
3848This function attribute ensures that a parameter in a function call is
3849an explicit @code{NULL}. The attribute is only valid on variadic
3850functions. By default, the sentinel is located at position zero, the
3851last parameter of the function call. If an optional integer position
3852argument P is supplied to the attribute, the sentinel must be located at
3853position P counting backwards from the end of the argument list.
3854
3855@smallexample
3856__attribute__ ((sentinel))
3857is equivalent to
3858__attribute__ ((sentinel(0)))
3859@end smallexample
3860
3861The attribute is automatically set with a position of 0 for the built-in
3862functions @code{execl} and @code{execlp}. The built-in function
254ea84c 3863@code{execle} has the attribute set with a position of 1.
254986c7
KG
3864
3865A valid @code{NULL} in this context is defined as zero with any pointer
3866type. If your system defines the @code{NULL} macro with an integer type
3867then you need to add an explicit cast. GCC replaces @code{stddef.h}
3868with a copy that redefines NULL appropriately.
3869
3870The warnings for missing or incorrect sentinels are enabled with
3871@option{-Wformat}.
3d091dac 3872
c8619b90 3873@item short_call
bafa88c2 3874See @code{long_call/short_call}.
c8619b90
NS
3875
3876@item shortcall
bafa88c2 3877See @code{longcall/shortcall}.
c8619b90
NS
3878
3879@item signal
eac188c5 3880@cindex interrupt handler functions on the AVR processors
c8619b90 3881Use this attribute on the AVR to indicate that the specified
358a3dbc 3882function is an interrupt handler. The compiler generates function
eac188c5
GJL
3883entry and exit sequences suitable for use in an interrupt handler when this
3884attribute is present.
3885
3886See also the @code{interrupt} function attribute.
3887
3888The AVR hardware globally disables interrupts when an interrupt is executed.
3889Interrupt handler functions defined with the @code{signal} attribute
3890do not re-enable interrupts. It is save to enable interrupts in a
3891@code{signal} handler. This ``save'' only applies to the code
bafa88c2 3892generated by the compiler and not to the IRQ layout of the
eac188c5
GJL
3893application which is responsibility of the application.
3894
3895If both @code{signal} and @code{interrupt} are specified for the same
358a3dbc 3896function, @code{signal} is silently ignored.
b93e3893
AO
3897
3898@item sp_switch
845f4111 3899@cindex @code{sp_switch} attribute
88ab0d1c 3900Use this attribute on the SH to indicate an @code{interrupt_handler}
b93e3893
AO
3901function should switch to an alternate stack. It expects a string
3902argument that names a global variable holding the address of the
3903alternate stack.
3904
3905@smallexample
3906void *alt_stack;
aee96fe9
JM
3907void f () __attribute__ ((interrupt_handler,
3908 sp_switch ("alt_stack")));
b93e3893
AO
3909@end smallexample
3910
c8619b90
NS
3911@item stdcall
3912@cindex functions that pop the argument stack on the 386
3913On the Intel 386, the @code{stdcall} attribute causes the compiler to
358a3dbc 3914assume that the called function pops off the stack space used to
c8619b90 3915pass arguments, unless it takes a variable number of arguments.
c1f7febf 3916
4b84f3de
SE
3917@item syscall_linkage
3918@cindex @code{syscall_linkage} attribute
bafa88c2 3919This attribute is used to modify the IA-64 calling convention by marking
4b84f3de
SE
3920all input registers as live at all function exits. This makes it possible
3921to restart a system call after an interrupt without having to save/restore
3922the input registers. This also prevents kernel data from leaking into
3923application code.
3924
1df48f5c
JW
3925@item target
3926@cindex @code{target} function attribute
3927The @code{target} attribute is used to specify that a function is to
3928be compiled with different target options than specified on the
3929command line. This can be used for instance to have functions
3930compiled with a different ISA (instruction set architecture) than the
3931default. You can also use the @samp{#pragma GCC target} pragma to set
3932more than one function to be compiled with specific target options.
3933@xref{Function Specific Option Pragmas}, for details about the
3934@samp{#pragma GCC target} pragma.
3935
3936For instance on a 386, you could compile one function with
3937@code{target("sse4.1,arch=core2")} and another with
c417597c 3938@code{target("sse4a,arch=amdfam10")}. This is equivalent to
1df48f5c
JW
3939compiling the first function with @option{-msse4.1} and
3940@option{-march=core2} options, and the second function with
3941@option{-msse4a} and @option{-march=amdfam10} options. It is up to the
3942user to make sure that a function is only invoked on a machine that
358a3dbc 3943supports the particular ISA it is compiled for (for example by using
1df48f5c
JW
3944@code{cpuid} on 386 to determine what feature bits and architecture
3945family are used).
3946
3947@smallexample
3948int core2_func (void) __attribute__ ((__target__ ("arch=core2")));
3949int sse3_func (void) __attribute__ ((__target__ ("sse3")));
3950@end smallexample
3951
e430824f
CLT
3952You can either use multiple
3953strings to specify multiple options, or separate the options
3954with a comma (@samp{,}).
3955
3956The @code{target} attribute is presently implemented for
3957i386/x86_64, PowerPC, and Nios II targets only.
3958The options supported are specific to each target.
3959
1df48f5c
JW
3960On the 386, the following options are allowed:
3961
3962@table @samp
3963@item abm
3964@itemx no-abm
3965@cindex @code{target("abm")} attribute
3966Enable/disable the generation of the advanced bit instructions.
3967
3968@item aes
3969@itemx no-aes
3970@cindex @code{target("aes")} attribute
3971Enable/disable the generation of the AES instructions.
3972
f80e0faf
ST
3973@item default
3974@cindex @code{target("default")} attribute
3975@xref{Function Multiversioning}, where it is used to specify the
3976default function version.
3977
1df48f5c
JW
3978@item mmx
3979@itemx no-mmx
3980@cindex @code{target("mmx")} attribute
3981Enable/disable the generation of the MMX instructions.
3982
3983@item pclmul
3984@itemx no-pclmul
3985@cindex @code{target("pclmul")} attribute
3986Enable/disable the generation of the PCLMUL instructions.
3987
3988@item popcnt
3989@itemx no-popcnt
3990@cindex @code{target("popcnt")} attribute
3991Enable/disable the generation of the POPCNT instruction.
3992
3993@item sse
3994@itemx no-sse
3995@cindex @code{target("sse")} attribute
3996Enable/disable the generation of the SSE instructions.
3997
3998@item sse2
3999@itemx no-sse2
4000@cindex @code{target("sse2")} attribute
4001Enable/disable the generation of the SSE2 instructions.
4002
4003@item sse3
4004@itemx no-sse3
4005@cindex @code{target("sse3")} attribute
4006Enable/disable the generation of the SSE3 instructions.
4007
4008@item sse4
4009@itemx no-sse4
4010@cindex @code{target("sse4")} attribute
4011Enable/disable the generation of the SSE4 instructions (both SSE4.1
4012and SSE4.2).
4013
4014@item sse4.1
4015@itemx no-sse4.1
4016@cindex @code{target("sse4.1")} attribute
4017Enable/disable the generation of the sse4.1 instructions.
4018
4019@item sse4.2
4020@itemx no-sse4.2
4021@cindex @code{target("sse4.2")} attribute
4022Enable/disable the generation of the sse4.2 instructions.
4023
4024@item sse4a
4025@itemx no-sse4a
4026@cindex @code{target("sse4a")} attribute
4027Enable/disable the generation of the SSE4A instructions.
4028
cbf2e4d4
HJ
4029@item fma4
4030@itemx no-fma4
4031@cindex @code{target("fma4")} attribute
4032Enable/disable the generation of the FMA4 instructions.
4033
43a8b705
HJ
4034@item xop
4035@itemx no-xop
4036@cindex @code{target("xop")} attribute
4037Enable/disable the generation of the XOP instructions.
4038
3e901069
HJ
4039@item lwp
4040@itemx no-lwp
4041@cindex @code{target("lwp")} attribute
4042Enable/disable the generation of the LWP instructions.
4043
1df48f5c
JW
4044@item ssse3
4045@itemx no-ssse3
4046@cindex @code{target("ssse3")} attribute
4047Enable/disable the generation of the SSSE3 instructions.
4048
4049@item cld
4050@itemx no-cld
4051@cindex @code{target("cld")} attribute
4052Enable/disable the generation of the CLD before string moves.
4053
4054@item fancy-math-387
4055@itemx no-fancy-math-387
4056@cindex @code{target("fancy-math-387")} attribute
4057Enable/disable the generation of the @code{sin}, @code{cos}, and
6f46cb63 4058@code{sqrt} instructions on the 387 floating-point unit.
1df48f5c
JW
4059
4060@item fused-madd
4061@itemx no-fused-madd
4062@cindex @code{target("fused-madd")} attribute
4063Enable/disable the generation of the fused multiply/add instructions.
4064
4065@item ieee-fp
4066@itemx no-ieee-fp
4067@cindex @code{target("ieee-fp")} attribute
4068Enable/disable the generation of floating point that depends on IEEE arithmetic.
4069
4070@item inline-all-stringops
4071@itemx no-inline-all-stringops
4072@cindex @code{target("inline-all-stringops")} attribute
4073Enable/disable inlining of string operations.
4074
4075@item inline-stringops-dynamically
4076@itemx no-inline-stringops-dynamically
4077@cindex @code{target("inline-stringops-dynamically")} attribute
4078Enable/disable the generation of the inline code to do small string
4079operations and calling the library routines for large operations.
4080
4081@item align-stringops
4082@itemx no-align-stringops
4083@cindex @code{target("align-stringops")} attribute
4084Do/do not align destination of inlined string operations.
4085
4086@item recip
4087@itemx no-recip
4088@cindex @code{target("recip")} attribute
4089Enable/disable the generation of RCPSS, RCPPS, RSQRTSS and RSQRTPS
048fd785 4090instructions followed an additional Newton-Raphson step instead of
6f46cb63 4091doing a floating-point division.
1df48f5c
JW
4092
4093@item arch=@var{ARCH}
4094@cindex @code{target("arch=@var{ARCH}")} attribute
4095Specify the architecture to generate code for in compiling the function.
4096
4097@item tune=@var{TUNE}
4098@cindex @code{target("tune=@var{TUNE}")} attribute
4099Specify the architecture to tune for in compiling the function.
4100
4101@item fpmath=@var{FPMATH}
4102@cindex @code{target("fpmath=@var{FPMATH}")} attribute
6f46cb63 4103Specify which floating-point unit to use. The
1df48f5c
JW
4104@code{target("fpmath=sse,387")} option must be specified as
4105@code{target("fpmath=sse+387")} because the comma would separate
4106different options.
15bf6f3a 4107@end table
fd438373 4108
fd438373
MM
4109On the PowerPC, the following options are allowed:
4110
4111@table @samp
4112@item altivec
4113@itemx no-altivec
4114@cindex @code{target("altivec")} attribute
4115Generate code that uses (does not use) AltiVec instructions. In
566fb011 411632-bit code, you cannot enable AltiVec instructions unless
358a3dbc 4117@option{-mabi=altivec} is used on the command line.
fd438373
MM
4118
4119@item cmpb
4120@itemx no-cmpb
4121@cindex @code{target("cmpb")} attribute
4122Generate code that uses (does not use) the compare bytes instruction
4123implemented on the POWER6 processor and other processors that support
4124the PowerPC V2.05 architecture.
4125
4126@item dlmzb
4127@itemx no-dlmzb
4128@cindex @code{target("dlmzb")} attribute
4129Generate code that uses (does not use) the string-search @samp{dlmzb}
4130instruction on the IBM 405, 440, 464 and 476 processors. This instruction is
073a8998 4131generated by default when targeting those processors.
fd438373
MM
4132
4133@item fprnd
4134@itemx no-fprnd
4135@cindex @code{target("fprnd")} attribute
4136Generate code that uses (does not use) the FP round to integer
4137instructions implemented on the POWER5+ processor and other processors
4138that support the PowerPC V2.03 architecture.
4139
4140@item hard-dfp
4141@itemx no-hard-dfp
4142@cindex @code{target("hard-dfp")} attribute
6f46cb63 4143Generate code that uses (does not use) the decimal floating-point
fd438373
MM
4144instructions implemented on some POWER processors.
4145
4146@item isel
4147@itemx no-isel
4148@cindex @code{target("isel")} attribute
4149Generate code that uses (does not use) ISEL instruction.
4150
4151@item mfcrf
4152@itemx no-mfcrf
4153@cindex @code{target("mfcrf")} attribute
4154Generate code that uses (does not use) the move from condition
4155register field instruction implemented on the POWER4 processor and
4156other processors that support the PowerPC V2.01 architecture.
4157
4158@item mfpgpr
4159@itemx no-mfpgpr
4160@cindex @code{target("mfpgpr")} attribute
4161Generate code that uses (does not use) the FP move to/from general
4162purpose register instructions implemented on the POWER6X processor and
4163other processors that support the extended PowerPC V2.05 architecture.
4164
4165@item mulhw
4166@itemx no-mulhw
4167@cindex @code{target("mulhw")} attribute
4168Generate code that uses (does not use) the half-word multiply and
4169multiply-accumulate instructions on the IBM 405, 440, 464 and 476 processors.
073a8998 4170These instructions are generated by default when targeting those
fd438373
MM
4171processors.
4172
4173@item multiple
4174@itemx no-multiple
4175@cindex @code{target("multiple")} attribute
4176Generate code that uses (does not use) the load multiple word
4177instructions and the store multiple word instructions.
4178
4179@item update
4180@itemx no-update
4181@cindex @code{target("update")} attribute
4182Generate code that uses (does not use) the load or store instructions
4183that update the base register to the address of the calculated memory
4184location.
4185
4186@item popcntb
4187@itemx no-popcntb
4188@cindex @code{target("popcntb")} attribute
6f46cb63
SL
4189Generate code that uses (does not use) the popcount and double-precision
4190FP reciprocal estimate instruction implemented on the POWER5
fd438373
MM
4191processor and other processors that support the PowerPC V2.02
4192architecture.
4193
4194@item popcntd
4195@itemx no-popcntd
4196@cindex @code{target("popcntd")} attribute
4197Generate code that uses (does not use) the popcount instruction
4198implemented on the POWER7 processor and other processors that support
4199the PowerPC V2.06 architecture.
4200
4201@item powerpc-gfxopt
4202@itemx no-powerpc-gfxopt
4203@cindex @code{target("powerpc-gfxopt")} attribute
4204Generate code that uses (does not use) the optional PowerPC
4205architecture instructions in the Graphics group, including
4206floating-point select.
4207
4208@item powerpc-gpopt
4209@itemx no-powerpc-gpopt
4210@cindex @code{target("powerpc-gpopt")} attribute
4211Generate code that uses (does not use) the optional PowerPC
4212architecture instructions in the General Purpose group, including
4213floating-point square root.
4214
4215@item recip-precision
4216@itemx no-recip-precision
4217@cindex @code{target("recip-precision")} attribute
4218Assume (do not assume) that the reciprocal estimate instructions
6f46cb63 4219provide higher-precision estimates than is mandated by the powerpc
fd438373
MM
4220ABI.
4221
4222@item string
4223@itemx no-string
4224@cindex @code{target("string")} attribute
4225Generate code that uses (does not use) the load string instructions
4226and the store string word instructions to save multiple registers and
4227do small block moves.
4228
4229@item vsx
4230@itemx no-vsx
4231@cindex @code{target("vsx")} attribute
4232Generate code that uses (does not use) vector/scalar (VSX)
4233instructions, and also enable the use of built-in functions that allow
4234more direct access to the VSX instruction set. In 32-bit code, you
566fb011 4235cannot enable VSX or AltiVec instructions unless
358a3dbc 4236@option{-mabi=altivec} is used on the command line.
fd438373
MM
4237
4238@item friz
4239@itemx no-friz
4240@cindex @code{target("friz")} attribute
4241Generate (do not generate) the @code{friz} instruction when the
4242@option{-funsafe-math-optimizations} option is used to optimize
6f46cb63 4243rounding a floating-point value to 64-bit integer and back to floating
fd438373 4244point. The @code{friz} instruction does not return the same value if
6f46cb63 4245the floating-point number is too large to fit in an integer.
fd438373
MM
4246
4247@item avoid-indexed-addresses
4248@itemx no-avoid-indexed-addresses
4249@cindex @code{target("avoid-indexed-addresses")} attribute
4250Generate code that tries to avoid (not avoid) the use of indexed load
4251or store instructions.
4252
4253@item paired
4254@itemx no-paired
4255@cindex @code{target("paired")} attribute
4256Generate code that uses (does not use) the generation of PAIRED simd
4257instructions.
4258
4259@item longcall
4260@itemx no-longcall
4261@cindex @code{target("longcall")} attribute
4262Generate code that assumes (does not assume) that all calls are far
4263away so that a longer more expensive calling sequence is required.
4264
4265@item cpu=@var{CPU}
4266@cindex @code{target("cpu=@var{CPU}")} attribute
2b0d3573 4267Specify the architecture to generate code for when compiling the
76f59013 4268function. If you select the @code{target("cpu=power7")} attribute when
566fb011 4269generating 32-bit code, VSX and AltiVec instructions are not generated
fd438373
MM
4270unless you use the @option{-mabi=altivec} option on the command line.
4271
4272@item tune=@var{TUNE}
4273@cindex @code{target("tune=@var{TUNE}")} attribute
2b0d3573 4274Specify the architecture to tune for when compiling the function. If
fd438373 4275you do not specify the @code{target("tune=@var{TUNE}")} attribute and
2b0d3573 4276you do specify the @code{target("cpu=@var{CPU}")} attribute,
358a3dbc 4277compilation tunes for the @var{CPU} architecture, and not the
fd438373
MM
4278default tuning specified on the command line.
4279@end table
1df48f5c 4280
e430824f
CLT
4281When compiling for Nios II, the following options are allowed:
4282
4283@table @samp
4284@item custom-@var{insn}=@var{N}
4285@itemx no-custom-@var{insn}
4286@cindex @code{target("custom-@var{insn}=@var{N}")} attribute
4287@cindex @code{target("no-custom-@var{insn}")} attribute
4288Each @samp{custom-@var{insn}=@var{N}} attribute locally enables use of a
4289custom instruction with encoding @var{N} when generating code that uses
4290@var{insn}. Similarly, @samp{no-custom-@var{insn}} locally inhibits use of
4291the custom instruction @var{insn}.
4292These target attributes correspond to the
4293@option{-mcustom-@var{insn}=@var{N}} and @option{-mno-custom-@var{insn}}
4294command-line options, and support the same set of @var{insn} keywords.
4295@xref{Nios II Options}, for more information.
4296
4297@item custom-fpu-cfg=@var{name}
4298@cindex @code{target("custom-fpu-cfg=@var{name}")} attribute
4299This attribute corresponds to the @option{-mcustom-fpu-cfg=@var{name}}
4300command-line option, to select a predefined set of custom instructions
4301named @var{name}.
4302@xref{Nios II Options}, for more information.
4303@end table
1df48f5c 4304
566fb011 4305On the 386/x86_64 and PowerPC back ends, the inliner does not inline a
fd438373
MM
4306function that has different target options than the caller, unless the
4307callee has a subset of the target options of the caller. For example
4308a function declared with @code{target("sse3")} can inline a function
4309with @code{target("sse2")}, since @code{-msse3} implies @code{-msse2}.
1df48f5c 4310
c1f7febf 4311@item tiny_data
dbacaa98
KH
4312@cindex tiny data section on the H8/300H and H8S
4313Use this attribute on the H8/300H and H8S to indicate that the specified
c1f7febf 4314variable should be placed into the tiny data section.
358a3dbc 4315The compiler generates more efficient code for loads and stores
c1f7febf 4316on data in the tiny data section. Note the tiny data area is limited to
6f46cb63 4317slightly under 32KB of data.
845da534 4318
c8619b90 4319@item trap_exit
845f4111 4320@cindex @code{trap_exit} attribute
c8619b90
NS
4321Use this attribute on the SH for an @code{interrupt_handler} to return using
4322@code{trapa} instead of @code{rte}. This attribute expects an integer
4323argument specifying the trap number to be used.
845da534 4324
845f4111
OE
4325@item trapa_handler
4326@cindex @code{trapa_handler} attribute
4327On SH targets this function attribute is similar to @code{interrupt_handler}
4328but it does not save and restore all registers.
4329
c8619b90
NS
4330@item unused
4331@cindex @code{unused} attribute.
4332This attribute, attached to a function, means that the function is meant
358a3dbc 4333to be possibly unused. GCC does not produce a warning for this
c8619b90 4334function.
a32767e4 4335
c8619b90
NS
4336@item used
4337@cindex @code{used} attribute.
4338This attribute, attached to a function, means that code must be emitted
4339for the function even if it appears that the function is not referenced.
4340This is useful, for example, when the function is referenced only in
4341inline assembly.
5936c7e7 4342
4951efb6 4343When applied to a member function of a C++ class template, the
358a3dbc 4344attribute also means that the function is instantiated if the
4951efb6
JM
4345class itself is instantiated.
4346
69c7a374 4347@item vector
5ed8a176
NC
4348@cindex @code{vector} attribute
4349This RX attribute is similar to the @code{interrupt} attribute, including its
69c7a374
DD
4350parameters, but does not make the function an interrupt-handler type
4351function (i.e. it retains the normal C function calling ABI). See the
4352@code{interrupt} attribute for a description of its arguments.
4353
812b587e 4354@item version_id
4b84f3de 4355@cindex @code{version_id} attribute
bafa88c2 4356This IA-64 HP-UX attribute, attached to a global variable or function, renames a
812b587e 4357symbol to contain a version string, thus allowing for function level
6d10a203 4358versioning. HP-UX system header files may use function level versioning
812b587e
SE
4359for some system calls.
4360
4361@smallexample
4362extern int foo () __attribute__((version_id ("20040821")));
4363@end smallexample
4364
c513ecbf 4365@noindent
358a3dbc 4366Calls to @var{foo} are mapped to calls to @var{foo@{20040821@}}.
812b587e 4367
c8619b90
NS
4368@item visibility ("@var{visibility_type}")
4369@cindex @code{visibility} attribute
46bdbc00
GK
4370This attribute affects the linkage of the declaration to which it is attached.
4371There are four supported @var{visibility_type} values: default,
4372hidden, protected or internal visibility.
5936c7e7 4373
c8619b90
NS
4374@smallexample
4375void __attribute__ ((visibility ("protected")))
4376f () @{ /* @r{Do something.} */; @}
4377int i __attribute__ ((visibility ("hidden")));
4378@end smallexample
5936c7e7 4379
46bdbc00
GK
4380The possible values of @var{visibility_type} correspond to the
4381visibility settings in the ELF gABI.
5936c7e7 4382
c8619b90 4383@table @dfn
63c5b495 4384@c keep this list of visibilities in alphabetical order.
6b6cb52e 4385
c8619b90 4386@item default
46bdbc00
GK
4387Default visibility is the normal case for the object file format.
4388This value is available for the visibility attribute to override other
4389options that may change the assumed visibility of entities.
4390
4391On ELF, default visibility means that the declaration is visible to other
4392modules and, in shared libraries, means that the declared entity may be
4393overridden.
4394
4395On Darwin, default visibility means that the declaration is visible to
4396other modules.
4397
4398Default visibility corresponds to ``external linkage'' in the language.
6b6cb52e 4399
c8619b90 4400@item hidden
358a3dbc
SL
4401Hidden visibility indicates that the entity declared has a new
4402form of linkage, which we call ``hidden linkage''. Two
46bdbc00
GK
4403declarations of an object with hidden linkage refer to the same object
4404if they are in the same shared object.
6b6cb52e 4405
c8619b90
NS
4406@item internal
4407Internal visibility is like hidden visibility, but with additional
46bdbc00
GK
4408processor specific semantics. Unless otherwise specified by the
4409psABI, GCC defines internal visibility to mean that a function is
4410@emph{never} called from another module. Compare this with hidden
4411functions which, while they cannot be referenced directly by other
4412modules, can be referenced indirectly via function pointers. By
4413indicating that a function cannot be called from outside the module,
4414GCC may for instance omit the load of a PIC register since it is known
4415that the calling function loaded the correct value.
6b6cb52e 4416
c8619b90 4417@item protected
46bdbc00 4418Protected visibility is like default visibility except that it
358a3dbc 4419indicates that references within the defining module bind to the
46bdbc00
GK
4420definition in that module. That is, the declared entity cannot be
4421overridden by another module.
6b6cb52e 4422
c8619b90 4423@end table
6b6cb52e 4424
46bdbc00
GK
4425All visibilities are supported on many, but not all, ELF targets
4426(supported when the assembler supports the @samp{.visibility}
4427pseudo-op). Default visibility is supported everywhere. Hidden
4428visibility is supported on Darwin targets.
4429
c417597c 4430The visibility attribute should be applied only to declarations that
46bdbc00
GK
4431would otherwise have external linkage. The attribute should be applied
4432consistently, so that the same entity should not be declared with
4433different settings of the attribute.
4434
4435In C++, the visibility attribute applies to types as well as functions
b9e75696
JM
4436and objects, because in C++ types have linkage. A class must not have
4437greater visibility than its non-static data member types and bases,
4438and class members default to the visibility of their class. Also, a
b70f0f48
JM
4439declaration without explicit visibility is limited to the visibility
4440of its type.
46bdbc00
GK
4441
4442In C++, you can mark member functions and static member variables of a
d1facce0 4443class with the visibility attribute. This is useful if you know a
46bdbc00
GK
4444particular method or static member variable should only be used from
4445one shared object; then you can mark it hidden while the rest of the
4446class has default visibility. Care must be taken to avoid breaking
b70f0f48
JM
4447the One Definition Rule; for example, it is usually not useful to mark
4448an inline method as hidden without marking the whole class as hidden.
6b6cb52e 4449
b9e75696 4450A C++ namespace declaration can also have the visibility attribute.
33b5d6da
PC
4451
4452@smallexample
4453namespace nspace1 __attribute__ ((visibility ("protected")))
4454@{ /* @r{Do something.} */; @}
4455@end smallexample
4456
b9e75696
JM
4457This attribute applies only to the particular namespace body, not to
4458other definitions of the same namespace; it is equivalent to using
4459@samp{#pragma GCC visibility} before and after the namespace
4460definition (@pxref{Visibility Pragmas}).
4461
4462In C++, if a template argument has limited visibility, this
4463restriction is implicitly propagated to the template instantiation.
4464Otherwise, template instantiations and specializations default to the
4465visibility of their template.
4466
b70f0f48
JM
4467If both the template and enclosing class have explicit visibility, the
4468visibility from the template is used.
4469
e2491744
DD
4470@item vliw
4471@cindex @code{vliw} attribute
4472On MeP, the @code{vliw} attribute tells the compiler to emit
4473instructions in VLIW mode instead of core mode. Note that this
4474attribute is not allowed unless a VLIW coprocessor has been configured
566fb011 4475and enabled through command-line options.
e2491744 4476
c8619b90
NS
4477@item warn_unused_result
4478@cindex @code{warn_unused_result} attribute
4479The @code{warn_unused_result} attribute causes a warning to be emitted
4480if a caller of the function with this attribute does not use its
4481return value. This is useful for functions where not checking
4482the result is either a security problem or always a bug, such as
4483@code{realloc}.
6b6cb52e 4484
c8619b90
NS
4485@smallexample
4486int fn () __attribute__ ((warn_unused_result));
4487int foo ()
4488@{
4489 if (fn () < 0) return -1;
4490 fn ();
4491 return 0;
4492@}
4493@end smallexample
6b6cb52e 4494
c513ecbf 4495@noindent
c8619b90 4496results in warning on line 5.
6b6cb52e 4497
c8619b90
NS
4498@item weak
4499@cindex @code{weak} attribute
4500The @code{weak} attribute causes the declaration to be emitted as a weak
4501symbol rather than a global. This is primarily useful in defining
c417597c 4502library functions that can be overridden in user code, though it can
c8619b90
NS
4503also be used with non-function declarations. Weak symbols are supported
4504for ELF targets, and also for a.out targets when using the GNU assembler
4505and linker.
6b6cb52e 4506
a0203ca7
AO
4507@item weakref
4508@itemx weakref ("@var{target}")
4509@cindex @code{weakref} attribute
4510The @code{weakref} attribute marks a declaration as a weak reference.
4511Without arguments, it should be accompanied by an @code{alias} attribute
4512naming the target symbol. Optionally, the @var{target} may be given as
4513an argument to @code{weakref} itself. In either case, @code{weakref}
4514implicitly marks the declaration as @code{weak}. Without a
4515@var{target}, given as an argument to @code{weakref} or to @code{alias},
4516@code{weakref} is equivalent to @code{weak}.
4517
4518@smallexample
a9b0b825 4519static int x() __attribute__ ((weakref ("y")));
a0203ca7 4520/* is equivalent to... */
a9b0b825 4521static int x() __attribute__ ((weak, weakref, alias ("y")));
a0203ca7 4522/* and to... */
a9b0b825
GK
4523static int x() __attribute__ ((weakref));
4524static int x() __attribute__ ((alias ("y")));
a0203ca7
AO
4525@end smallexample
4526
4527A weak reference is an alias that does not by itself require a
4528definition to be given for the target symbol. If the target symbol is
4896c7b8 4529only referenced through weak references, then it becomes a @code{weak}
a0203ca7 4530undefined symbol. If it is directly referenced, however, then such
358a3dbc 4531strong references prevail, and a definition is required for the
a0203ca7
AO
4532symbol, not necessarily in the same translation unit.
4533
4534The effect is equivalent to moving all references to the alias to a
4535separate translation unit, renaming the alias to the aliased symbol,
4536declaring it as weak, compiling the two separate translation units and
4537performing a reloadable link on them.
4538
a9b0b825
GK
4539At present, a declaration to which @code{weakref} is attached can
4540only be @code{static}.
4541
c1f7febf
RK
4542@end table
4543
4544You can specify multiple attributes in a declaration by separating them
4545by commas within the double parentheses or by immediately following an
4546attribute declaration with another attribute declaration.
4547
4548@cindex @code{#pragma}, reason for not using
4549@cindex pragma, reason for not using
9f1bbeaa
JM
4550Some people object to the @code{__attribute__} feature, suggesting that
4551ISO C's @code{#pragma} should be used instead. At the time
4552@code{__attribute__} was designed, there were two reasons for not doing
4553this.
c1f7febf
RK
4554
4555@enumerate
4556@item
4557It is impossible to generate @code{#pragma} commands from a macro.
4558
4559@item
4560There is no telling what the same @code{#pragma} might mean in another
4561compiler.
4562@end enumerate
4563
9f1bbeaa
JM
4564These two reasons applied to almost any application that might have been
4565proposed for @code{#pragma}. It was basically a mistake to use
4566@code{#pragma} for @emph{anything}.
4567
4568The ISO C99 standard includes @code{_Pragma}, which now allows pragmas
4569to be generated from macros. In addition, a @code{#pragma GCC}
4570namespace is now in use for GCC-specific pragmas. However, it has been
4571found convenient to use @code{__attribute__} to achieve a natural
4572attachment of attributes to their corresponding declarations, whereas
4573@code{#pragma GCC} is of use for constructs that do not naturally form
c54e7136 4574part of the grammar. @xref{Pragmas,,Pragmas Accepted by GCC}.
c1f7febf 4575
883755a1
DW
4576@node Label Attributes
4577@section Label Attributes
4578@cindex Label Attributes
4579
4580GCC allows attributes to be set on C labels. @xref{Attribute Syntax}, for
4581details of the exact syntax for using attributes. Other attributes are
4582available for functions (@pxref{Function Attributes}), variables
4583(@pxref{Variable Attributes}) and for types (@pxref{Type Attributes}).
4584
4585This example uses the @code{cold} label attribute to indicate the
4586@code{ErrorHandling} branch is unlikely to be taken and that the
4587@code{ErrorHandling} label is unused:
4588
4589@smallexample
4590
4591 asm goto ("some asm" : : : : NoError);
4592
4593/* This branch (the fallthru from the asm) is less commonly used */
4594ErrorHandling:
4595 __attribute__((cold, unused)); /* Semi-colon is required here */
4596 printf("error\n");
4597 return 0;
4598
4599NoError:
4600 printf("no error\n");
4601 return 1;
4602@end smallexample
4603
4604@table @code
4605@item unused
4606@cindex @code{unused} label attribute
4607This feature is intended for program-generated code that may contain
4608unused labels, but which is compiled with @option{-Wall}. It is
4609not normally appropriate to use in it human-written code, though it
4610could be useful in cases where the code that jumps to the label is
4611contained within an @code{#ifdef} conditional.
4612
4613@item hot
4614@cindex @code{hot} label attribute
4615The @code{hot} attribute on a label is used to inform the compiler that
4616the path following the label is more likely than paths that are not so
4617annotated. This attribute is used in cases where @code{__builtin_expect}
4618cannot be used, for instance with computed goto or @code{asm goto}.
4619
4620The @code{hot} attribute on labels is not implemented in GCC versions
4621earlier than 4.8.
4622
4623@item cold
4624@cindex @code{cold} label attribute
4625The @code{cold} attribute on labels is used to inform the compiler that
4626the path following the label is unlikely to be executed. This attribute
4627is used in cases where @code{__builtin_expect} cannot be used, for instance
4628with computed goto or @code{asm goto}.
4629
4630The @code{cold} attribute on labels is not implemented in GCC versions
4631earlier than 4.8.
4632
4633@end table
4634
2c5e91d2
JM
4635@node Attribute Syntax
4636@section Attribute Syntax
4637@cindex attribute syntax
4638
4639This section describes the syntax with which @code{__attribute__} may be
4640used, and the constructs to which attribute specifiers bind, for the C
161d7b59 4641language. Some details may vary for C++ and Objective-C@. Because of
2c5e91d2
JM
4642infelicities in the grammar for attributes, some forms described here
4643may not be successfully parsed in all cases.
4644
91d231cb
JM
4645There are some problems with the semantics of attributes in C++. For
4646example, there are no manglings for attributes, although they may affect
4647code generation, so problems may arise when attributed types are used in
4648conjunction with templates or overloading. Similarly, @code{typeid}
4649does not distinguish between types with different attributes. Support
4650for attributes in C++ may be restricted in future to attributes on
4651declarations only, but not on nested declarators.
4652
2c5e91d2
JM
4653@xref{Function Attributes}, for details of the semantics of attributes
4654applying to functions. @xref{Variable Attributes}, for details of the
4655semantics of attributes applying to variables. @xref{Type Attributes},
4656for details of the semantics of attributes applying to structure, union
4657and enumerated types.
883755a1
DW
4658@xref{Label Attributes}, for details of the semantics of attributes
4659applying to labels.
2c5e91d2
JM
4660
4661An @dfn{attribute specifier} is of the form
4662@code{__attribute__ ((@var{attribute-list}))}. An @dfn{attribute list}
4663is a possibly empty comma-separated sequence of @dfn{attributes}, where
4664each attribute is one of the following:
4665
4666@itemize @bullet
4667@item
4668Empty. Empty attributes are ignored.
4669
4670@item
4671A word (which may be an identifier such as @code{unused}, or a reserved
4672word such as @code{const}).
4673
4674@item
4675A word, followed by, in parentheses, parameters for the attribute.
4676These parameters take one of the following forms:
4677
4678@itemize @bullet
4679@item
4680An identifier. For example, @code{mode} attributes use this form.
4681
4682@item
4683An identifier followed by a comma and a non-empty comma-separated list
4684of expressions. For example, @code{format} attributes use this form.
4685
4686@item
4687A possibly empty comma-separated list of expressions. For example,
4688@code{format_arg} attributes use this form with the list being a single
4689integer constant expression, and @code{alias} attributes use this form
4690with the list being a single string constant.
4691@end itemize
4692@end itemize
4693
4694An @dfn{attribute specifier list} is a sequence of one or more attribute
4695specifiers, not separated by any other tokens.
4696
883755a1
DW
4697@subsubheading Label Attributes
4698
50fc59e7 4699In GNU C, an attribute specifier list may appear after the colon following a
883755a1 4700label, other than a @code{case} or @code{default} label. GNU C++ only permits
5bca4e80
ILT
4701attributes on labels if the attribute specifier is immediately
4702followed by a semicolon (i.e., the label applies to an empty
4703statement). If the semicolon is missing, C++ label attributes are
4704ambiguous, as it is permissible for a declaration, which could begin
4705with an attribute list, to be labelled in C++. Declarations cannot be
4706labelled in C90 or C99, so the ambiguity does not arise there.
2c5e91d2 4707
883755a1
DW
4708@subsubheading Type Attributes
4709
2c5e91d2
JM
4710An attribute specifier list may appear as part of a @code{struct},
4711@code{union} or @code{enum} specifier. It may go either immediately
4712after the @code{struct}, @code{union} or @code{enum} keyword, or after
b9e75696 4713the closing brace. The former syntax is preferred.
2c5e91d2
JM
4714Where attribute specifiers follow the closing brace, they are considered
4715to relate to the structure, union or enumerated type defined, not to any
4716enclosing declaration the type specifier appears in, and the type
4717defined is not complete until after the attribute specifiers.
4718@c Otherwise, there would be the following problems: a shift/reduce
4fe9b91c 4719@c conflict between attributes binding the struct/union/enum and
2c5e91d2
JM
4720@c binding to the list of specifiers/qualifiers; and "aligned"
4721@c attributes could use sizeof for the structure, but the size could be
4722@c changed later by "packed" attributes.
4723
883755a1
DW
4724
4725@subsubheading All other attributes
4726
2c5e91d2
JM
4727Otherwise, an attribute specifier appears as part of a declaration,
4728counting declarations of unnamed parameters and type names, and relates
4729to that declaration (which may be nested in another declaration, for
91d231cb
JM
4730example in the case of a parameter declaration), or to a particular declarator
4731within a declaration. Where an
ff867905
JM
4732attribute specifier is applied to a parameter declared as a function or
4733an array, it should apply to the function or array rather than the
4734pointer to which the parameter is implicitly converted, but this is not
4735yet correctly implemented.
2c5e91d2
JM
4736
4737Any list of specifiers and qualifiers at the start of a declaration may
4738contain attribute specifiers, whether or not such a list may in that
4739context contain storage class specifiers. (Some attributes, however,
4740are essentially in the nature of storage class specifiers, and only make
4741sense where storage class specifiers may be used; for example,
4742@code{section}.) There is one necessary limitation to this syntax: the
4743first old-style parameter declaration in a function definition cannot
4744begin with an attribute specifier, because such an attribute applies to
4745the function instead by syntax described below (which, however, is not
4746yet implemented in this case). In some other cases, attribute
4747specifiers are permitted by this grammar but not yet supported by the
4748compiler. All attribute specifiers in this place relate to the
c771326b 4749declaration as a whole. In the obsolescent usage where a type of
2c5e91d2
JM
4750@code{int} is implied by the absence of type specifiers, such a list of
4751specifiers and qualifiers may be an attribute specifier list with no
4752other specifiers or qualifiers.
4753
7dcb0442 4754At present, the first parameter in a function prototype must have some
c417597c 4755type specifier that is not an attribute specifier; this resolves an
7dcb0442
JM
4756ambiguity in the interpretation of @code{void f(int
4757(__attribute__((foo)) x))}, but is subject to change. At present, if
4758the parentheses of a function declarator contain only attributes then
4759those attributes are ignored, rather than yielding an error or warning
4760or implying a single parameter of type int, but this is subject to
4761change.
4762
2c5e91d2
JM
4763An attribute specifier list may appear immediately before a declarator
4764(other than the first) in a comma-separated list of declarators in a
4765declaration of more than one identifier using a single list of
4b01f8d8 4766specifiers and qualifiers. Such attribute specifiers apply
9c34dbbf
ZW
4767only to the identifier before whose declarator they appear. For
4768example, in
4769
4770@smallexample
4771__attribute__((noreturn)) void d0 (void),
4772 __attribute__((format(printf, 1, 2))) d1 (const char *, ...),
4773 d2 (void)
4774@end smallexample
4775
4776@noindent
4777the @code{noreturn} attribute applies to all the functions
4b01f8d8 4778declared; the @code{format} attribute only applies to @code{d1}.
2c5e91d2
JM
4779
4780An attribute specifier list may appear immediately before the comma,
4781@code{=} or semicolon terminating the declaration of an identifier other
770a9950
JM
4782than a function definition. Such attribute specifiers apply
4783to the declared object or function. Where an
9c34dbbf 4784assembler name for an object or function is specified (@pxref{Asm
770a9950
JM
4785Labels}), the attribute must follow the @code{asm}
4786specification.
2c5e91d2
JM
4787
4788An attribute specifier list may, in future, be permitted to appear after
4789the declarator in a function definition (before any old-style parameter
4790declarations or the function body).
4791
0e03329a
JM
4792Attribute specifiers may be mixed with type qualifiers appearing inside
4793the @code{[]} of a parameter array declarator, in the C99 construct by
4794which such qualifiers are applied to the pointer to which the array is
4795implicitly converted. Such attribute specifiers apply to the pointer,
4796not to the array, but at present this is not implemented and they are
4797ignored.
4798
2c5e91d2
JM
4799An attribute specifier list may appear at the start of a nested
4800declarator. At present, there are some limitations in this usage: the
91d231cb
JM
4801attributes correctly apply to the declarator, but for most individual
4802attributes the semantics this implies are not implemented.
4803When attribute specifiers follow the @code{*} of a pointer
4b01f8d8 4804declarator, they may be mixed with any type qualifiers present.
358a3dbc 4805The following describes the formal semantics of this syntax. It makes the
2c5e91d2
JM
4806most sense if you are familiar with the formal specification of
4807declarators in the ISO C standard.
4808
4809Consider (as in C99 subclause 6.7.5 paragraph 4) a declaration @code{T
4810D1}, where @code{T} contains declaration specifiers that specify a type
4811@var{Type} (such as @code{int}) and @code{D1} is a declarator that
4812contains an identifier @var{ident}. The type specified for @var{ident}
4813for derived declarators whose type does not include an attribute
4814specifier is as in the ISO C standard.
4815
4816If @code{D1} has the form @code{( @var{attribute-specifier-list} D )},
4817and the declaration @code{T D} specifies the type
4818``@var{derived-declarator-type-list} @var{Type}'' for @var{ident}, then
4819@code{T D1} specifies the type ``@var{derived-declarator-type-list}
4820@var{attribute-specifier-list} @var{Type}'' for @var{ident}.
4821
4822If @code{D1} has the form @code{*
4823@var{type-qualifier-and-attribute-specifier-list} D}, and the
4824declaration @code{T D} specifies the type
4825``@var{derived-declarator-type-list} @var{Type}'' for @var{ident}, then
4826@code{T D1} specifies the type ``@var{derived-declarator-type-list}
197ef306 4827@var{type-qualifier-and-attribute-specifier-list} pointer to @var{Type}'' for
2c5e91d2
JM
4828@var{ident}.
4829
f282ffb3 4830For example,
9c34dbbf
ZW
4831
4832@smallexample
4833void (__attribute__((noreturn)) ****f) (void);
4834@end smallexample
4835
4836@noindent
4837specifies the type ``pointer to pointer to pointer to pointer to
4838non-returning function returning @code{void}''. As another example,
4839
4840@smallexample
4841char *__attribute__((aligned(8))) *f;
4842@end smallexample
4843
4844@noindent
4845specifies the type ``pointer to 8-byte-aligned pointer to @code{char}''.
91d231cb
JM
4846Note again that this does not work with most attributes; for example,
4847the usage of @samp{aligned} and @samp{noreturn} attributes given above
4848is not yet supported.
4849
4850For compatibility with existing code written for compiler versions that
4851did not implement attributes on nested declarators, some laxity is
4852allowed in the placing of attributes. If an attribute that only applies
358a3dbc 4853to types is applied to a declaration, it is treated as applying to
91d231cb 4854the type of that declaration. If an attribute that only applies to
358a3dbc 4855declarations is applied to the type of a declaration, it is treated
91d231cb
JM
4856as applying to that declaration; and, for compatibility with code
4857placing the attributes immediately before the identifier declared, such
358a3dbc 4858an attribute applied to a function return type is treated as
91d231cb 4859applying to the function type, and such an attribute applied to an array
358a3dbc 4860element type is treated as applying to the array type. If an
91d231cb 4861attribute that only applies to function types is applied to a
358a3dbc 4862pointer-to-function type, it is treated as applying to the pointer
91d231cb 4863target type; if such an attribute is applied to a function return type
358a3dbc 4864that is not a pointer-to-function type, it is treated as applying
91d231cb 4865to the function type.
2c5e91d2 4866
c1f7febf
RK
4867@node Function Prototypes
4868@section Prototypes and Old-Style Function Definitions
4869@cindex function prototype declarations
4870@cindex old-style function definitions
4871@cindex promotion of formal parameters
4872
5490d604 4873GNU C extends ISO C to allow a function prototype to override a later
c1f7febf
RK
4874old-style non-prototype definition. Consider the following example:
4875
3ab51846 4876@smallexample
c1f7febf 4877/* @r{Use prototypes unless the compiler is old-fashioned.} */
d863830b 4878#ifdef __STDC__
c1f7febf
RK
4879#define P(x) x
4880#else
4881#define P(x) ()
4882#endif
4883
4884/* @r{Prototype function declaration.} */
4885int isroot P((uid_t));
4886
4887/* @r{Old-style function definition.} */
4888int
12bcfaa1 4889isroot (x) /* @r{??? lossage here ???} */
c1f7febf
RK
4890 uid_t x;
4891@{
4892 return x == 0;
4893@}
3ab51846 4894@end smallexample
c1f7febf 4895
5490d604 4896Suppose the type @code{uid_t} happens to be @code{short}. ISO C does
c1f7febf
RK
4897not allow this example, because subword arguments in old-style
4898non-prototype definitions are promoted. Therefore in this example the
4899function definition's argument is really an @code{int}, which does not
4900match the prototype argument type of @code{short}.
4901
5490d604 4902This restriction of ISO C makes it hard to write code that is portable
c1f7febf
RK
4903to traditional C compilers, because the programmer does not know
4904whether the @code{uid_t} type is @code{short}, @code{int}, or
4905@code{long}. Therefore, in cases like these GNU C allows a prototype
4906to override a later old-style definition. More precisely, in GNU C, a
4907function prototype argument type overrides the argument type specified
4908by a later old-style definition if the former type is the same as the
4909latter type before promotion. Thus in GNU C the above example is
4910equivalent to the following:
4911
3ab51846 4912@smallexample
c1f7febf
RK
4913int isroot (uid_t);
4914
4915int
4916isroot (uid_t x)
4917@{
4918 return x == 0;
4919@}
3ab51846 4920@end smallexample
c1f7febf 4921
9c34dbbf 4922@noindent
c1f7febf
RK
4923GNU C++ does not support old-style function definitions, so this
4924extension is irrelevant.
4925
4926@node C++ Comments
4927@section C++ Style Comments
ab940b73 4928@cindex @code{//}
c1f7febf
RK
4929@cindex C++ comments
4930@cindex comments, C++ style
4931
4932In GNU C, you may use C++ style comments, which start with @samp{//} and
4933continue until the end of the line. Many other C implementations allow
f458d1d5
ZW
4934such comments, and they are included in the 1999 C standard. However,
4935C++ style comments are not recognized if you specify an @option{-std}
4936option specifying a version of ISO C before C99, or @option{-ansi}
7e1542b9 4937(equivalent to @option{-std=c90}).
c1f7febf
RK
4938
4939@node Dollar Signs
4940@section Dollar Signs in Identifier Names
4941@cindex $
4942@cindex dollar signs in identifier names
4943@cindex identifier names, dollar signs in
4944
79188db9
RK
4945In GNU C, you may normally use dollar signs in identifier names.
4946This is because many traditional C implementations allow such identifiers.
4947However, dollar signs in identifiers are not supported on a few target
4948machines, typically because the target assembler does not allow them.
c1f7febf
RK
4949
4950@node Character Escapes
4951@section The Character @key{ESC} in Constants
4952
4953You can use the sequence @samp{\e} in a string or character constant to
4954stand for the ASCII character @key{ESC}.
4955
c1f7febf
RK
4956@node Variable Attributes
4957@section Specifying Attributes of Variables
4958@cindex attribute of variables
4959@cindex variable attributes
4960
4961The keyword @code{__attribute__} allows you to specify special
4962attributes of variables or structure fields. This keyword is followed
905e8651
RH
4963by an attribute specification inside double parentheses. Some
4964attributes are currently defined generically for variables.
4965Other attributes are defined for variables on particular target
4966systems. Other attributes are available for functions
883755a1
DW
4967(@pxref{Function Attributes}), labels (@pxref{Label Attributes}) and for
4968types (@pxref{Type Attributes}).
905e8651
RH
4969Other front ends might define more attributes
4970(@pxref{C++ Extensions,,Extensions to the C++ Language}).
c1f7febf
RK
4971
4972You may also specify attributes with @samp{__} preceding and following
4973each keyword. This allows you to use them in header files without
4974being concerned about a possible macro of the same name. For example,
4975you may use @code{__aligned__} instead of @code{aligned}.
4976
2c5e91d2
JM
4977@xref{Attribute Syntax}, for details of the exact syntax for using
4978attributes.
4979
c1f7febf
RK
4980@table @code
4981@cindex @code{aligned} attribute
4982@item aligned (@var{alignment})
4983This attribute specifies a minimum alignment for the variable or
4984structure field, measured in bytes. For example, the declaration:
4985
4986@smallexample
4987int x __attribute__ ((aligned (16))) = 0;
4988@end smallexample
4989
4990@noindent
4991causes the compiler to allocate the global variable @code{x} on a
499216-byte boundary. On a 68040, this could be used in conjunction with
4993an @code{asm} expression to access the @code{move16} instruction which
4994requires 16-byte aligned operands.
4995
4996You can also specify the alignment of structure fields. For example, to
4997create a double-word aligned @code{int} pair, you could write:
4998
4999@smallexample
5000struct foo @{ int x[2] __attribute__ ((aligned (8))); @};
5001@end smallexample
5002
5003@noindent
c417597c
SL
5004This is an alternative to creating a union with a @code{double} member,
5005which forces the union to be double-word aligned.
c1f7febf 5006
c1f7febf
RK
5007As in the preceding examples, you can explicitly specify the alignment
5008(in bytes) that you wish the compiler to use for a given variable or
5009structure field. Alternatively, you can leave out the alignment factor
6e4f1168
L
5010and just ask the compiler to align a variable or field to the
5011default alignment for the target architecture you are compiling for.
5012The default alignment is sufficient for all scalar types, but may not be
c417597c 5013enough for all vector types on a target that supports vector operations.
6e4f1168
L
5014The default alignment is fixed for a particular target ABI.
5015
566fb011 5016GCC also provides a target specific macro @code{__BIGGEST_ALIGNMENT__},
6e4f1168
L
5017which is the largest alignment ever used for any data type on the
5018target machine you are compiling for. For example, you could write:
c1f7febf
RK
5019
5020@smallexample
6e4f1168 5021short array[3] __attribute__ ((aligned (__BIGGEST_ALIGNMENT__)));
c1f7febf
RK
5022@end smallexample
5023
6e4f1168
L
5024The compiler automatically sets the alignment for the declared
5025variable or field to @code{__BIGGEST_ALIGNMENT__}. Doing this can
5026often make copy operations more efficient, because the compiler can
5027use whatever instructions copy the biggest chunks of memory when
5028performing copies to or from the variables or fields that you have
5029aligned this way. Note that the value of @code{__BIGGEST_ALIGNMENT__}
566fb011 5030may change depending on command-line options.
c1f7febf 5031
e9f9692b
MW
5032When used on a struct, or struct member, the @code{aligned} attribute can
5033only increase the alignment; in order to decrease it, the @code{packed}
5034attribute must be specified as well. When used as part of a typedef, the
5035@code{aligned} attribute can both increase and decrease alignment, and
358a3dbc 5036specifying the @code{packed} attribute generates a warning.
c1f7febf
RK
5037
5038Note that the effectiveness of @code{aligned} attributes may be limited
5039by inherent limitations in your linker. On many systems, the linker is
5040only able to arrange for variables to be aligned up to a certain maximum
5041alignment. (For some linkers, the maximum supported alignment may
5042be very very small.) If your linker is only able to align variables
6f46cb63
SL
5043up to a maximum of 8-byte alignment, then specifying @code{aligned(16)}
5044in an @code{__attribute__} still only provides you with 8-byte
c1f7febf
RK
5045alignment. See your linker documentation for further information.
5046
ff2ce160 5047The @code{aligned} attribute can also be used for functions
837edd5f
GK
5048(@pxref{Function Attributes}.)
5049
0bfa5f65
RH
5050@item cleanup (@var{cleanup_function})
5051@cindex @code{cleanup} attribute
5052The @code{cleanup} attribute runs a function when the variable goes
5053out of scope. This attribute can only be applied to auto function
5054scope variables; it may not be applied to parameters or variables
5055with static storage duration. The function must take one parameter,
5056a pointer to a type compatible with the variable. The return value
5057of the function (if any) is ignored.
5058
5059If @option{-fexceptions} is enabled, then @var{cleanup_function}
358a3dbc 5060is run during the stack unwinding that happens during the
0bfa5f65
RH
5061processing of the exception. Note that the @code{cleanup} attribute
5062does not allow the exception to be caught, only to perform an action.
5063It is undefined what happens if @var{cleanup_function} does not
5064return normally.
5065
905e8651
RH
5066@item common
5067@itemx nocommon
5068@cindex @code{common} attribute
5069@cindex @code{nocommon} attribute
5070@opindex fcommon
5071@opindex fno-common
5072The @code{common} attribute requests GCC to place a variable in
5073``common'' storage. The @code{nocommon} attribute requests the
78466c0e 5074opposite---to allocate space for it directly.
905e8651 5075
daf2f129 5076These attributes override the default chosen by the
905e8651
RH
5077@option{-fno-common} and @option{-fcommon} flags respectively.
5078
5079@item deprecated
9b86d6bb 5080@itemx deprecated (@var{msg})
905e8651
RH
5081@cindex @code{deprecated} attribute
5082The @code{deprecated} attribute results in a warning if the variable
5083is used anywhere in the source file. This is useful when identifying
5084variables that are expected to be removed in a future version of a
5085program. The warning also includes the location of the declaration
5086of the deprecated variable, to enable users to easily find further
5087information about why the variable is deprecated, or what they should
64c18e57 5088do instead. Note that the warning only occurs for uses:
905e8651
RH
5089
5090@smallexample
5091extern int old_var __attribute__ ((deprecated));
5092extern int old_var;
5093int new_fn () @{ return old_var; @}
5094@end smallexample
5095
358a3dbc
SL
5096@noindent
5097results in a warning on line 3 but not line 2. The optional @var{msg}
5098argument, which must be a string, is printed in the warning if
9b86d6bb 5099present.
905e8651
RH
5100
5101The @code{deprecated} attribute can also be used for functions and
5102types (@pxref{Function Attributes}, @pxref{Type Attributes}.)
5103
c1f7febf
RK
5104@item mode (@var{mode})
5105@cindex @code{mode} attribute
5106This attribute specifies the data type for the declaration---whichever
5107type corresponds to the mode @var{mode}. This in effect lets you
6f46cb63 5108request an integer or floating-point type according to its width.
c1f7febf 5109
bafa88c2
SL
5110You may also specify a mode of @code{byte} or @code{__byte__} to
5111indicate the mode corresponding to a one-byte integer, @code{word} or
5112@code{__word__} for the mode of a one-word integer, and @code{pointer}
5113or @code{__pointer__} for the mode used to represent pointers.
c1f7febf 5114
c1f7febf
RK
5115@item packed
5116@cindex @code{packed} attribute
5117The @code{packed} attribute specifies that a variable or structure field
5118should have the smallest possible alignment---one byte for a variable,
5119and one bit for a field, unless you specify a larger value with the
5120@code{aligned} attribute.
5121
5122Here is a structure in which the field @code{x} is packed, so that it
5123immediately follows @code{a}:
5124
3ab51846 5125@smallexample
c1f7febf
RK
5126struct foo
5127@{
5128 char a;
5129 int x[2] __attribute__ ((packed));
5130@};
3ab51846 5131@end smallexample
c1f7febf 5132
2cd36c22
AN
5133@emph{Note:} The 4.1, 4.2 and 4.3 series of GCC ignore the
5134@code{packed} attribute on bit-fields of type @code{char}. This has
5135been fixed in GCC 4.4 but the change can lead to differences in the
048fd785 5136structure layout. See the documentation of
2cd36c22
AN
5137@option{-Wpacked-bitfield-compat} for more information.
5138
84330467 5139@item section ("@var{section-name}")
c1f7febf
RK
5140@cindex @code{section} variable attribute
5141Normally, the compiler places the objects it generates in sections like
5142@code{data} and @code{bss}. Sometimes, however, you need additional sections,
5143or you need certain particular variables to appear in special sections,
5144for example to map to special hardware. The @code{section}
5145attribute specifies that a variable (or function) lives in a particular
5146section. For example, this small program uses several specific section names:
5147
5148@smallexample
5149struct duart a __attribute__ ((section ("DUART_A"))) = @{ 0 @};
5150struct duart b __attribute__ ((section ("DUART_B"))) = @{ 0 @};
5151char stack[10000] __attribute__ ((section ("STACK"))) = @{ 0 @};
8b9d598f 5152int init_data __attribute__ ((section ("INITDATA")));
c1f7febf
RK
5153
5154main()
5155@{
12bcfaa1 5156 /* @r{Initialize stack pointer} */
c1f7febf
RK
5157 init_sp (stack + sizeof (stack));
5158
12bcfaa1 5159 /* @r{Initialize initialized data} */
c1f7febf
RK
5160 memcpy (&init_data, &data, &edata - &data);
5161
12bcfaa1 5162 /* @r{Turn on the serial ports} */
c1f7febf
RK
5163 init_duart (&a);
5164 init_duart (&b);
5165@}
5166@end smallexample
5167
5168@noindent
8b9d598f
SE
5169Use the @code{section} attribute with
5170@emph{global} variables and not @emph{local} variables,
5171as shown in the example.
c1f7febf 5172
8b9d598f
SE
5173You may use the @code{section} attribute with initialized or
5174uninitialized global variables but the linker requires
c1f7febf
RK
5175each object be defined once, with the exception that uninitialized
5176variables tentatively go in the @code{common} (or @code{bss}) section
8b9d598f 5177and can be multiply ``defined''. Using the @code{section} attribute
358a3dbc 5178changes what section the variable goes into and may cause the
8b9d598f
SE
5179linker to issue an error if an uninitialized variable has multiple
5180definitions. You can force a variable to be initialized with the
5181@option{-fno-common} flag or the @code{nocommon} attribute.
c1f7febf
RK
5182
5183Some file formats do not support arbitrary sections so the @code{section}
5184attribute is not available on all platforms.
5185If you need to map the entire contents of a module to a particular
5186section, consider using the facilities of the linker instead.
5187
593d3a34
MK
5188@item shared
5189@cindex @code{shared} variable attribute
95fef11f 5190On Microsoft Windows, in addition to putting variable definitions in a named
02f52e19 5191section, the section can also be shared among all running copies of an
161d7b59 5192executable or DLL@. For example, this small program defines shared data
84330467 5193by putting it in a named section @code{shared} and marking the section
593d3a34
MK
5194shareable:
5195
5196@smallexample
5197int foo __attribute__((section ("shared"), shared)) = 0;
5198
5199int
5200main()
5201@{
12bcfaa1
JM
5202 /* @r{Read and write foo. All running
5203 copies see the same value.} */
593d3a34
MK
5204 return 0;
5205@}
5206@end smallexample
5207
5208@noindent
5209You may only use the @code{shared} attribute along with @code{section}
bafa88c2 5210attribute with a fully-initialized global definition because of the way
593d3a34
MK
5211linkers work. See @code{section} attribute for more information.
5212
95fef11f 5213The @code{shared} attribute is only available on Microsoft Windows@.
593d3a34 5214
905e8651
RH
5215@item tls_model ("@var{tls_model}")
5216@cindex @code{tls_model} attribute
5217The @code{tls_model} attribute sets thread-local storage model
5218(@pxref{Thread-Local}) of a particular @code{__thread} variable,
bcbc9564 5219overriding @option{-ftls-model=} command-line switch on a per-variable
905e8651
RH
5220basis.
5221The @var{tls_model} argument should be one of @code{global-dynamic},
5222@code{local-dynamic}, @code{initial-exec} or @code{local-exec}.
5223
5224Not all targets support this attribute.
5225
c1f7febf
RK
5226@item unused
5227This attribute, attached to a variable, means that the variable is meant
358a3dbc 5228to be possibly unused. GCC does not produce a warning for this
c1f7febf
RK
5229variable.
5230
5f79d643 5231@item used
87fccdbb
MP
5232This attribute, attached to a variable with the static storage, means that
5233the variable must be emitted even if it appears that the variable is not
5234referenced.
5f79d643 5235
4951efb6 5236When applied to a static data member of a C++ class template, the
358a3dbc 5237attribute also means that the member is instantiated if the
4951efb6
JM
5238class itself is instantiated.
5239
1b9191d2
AH
5240@item vector_size (@var{bytes})
5241This attribute specifies the vector size for the variable, measured in
5242bytes. For example, the declaration:
5243
5244@smallexample
5245int foo __attribute__ ((vector_size (16)));
5246@end smallexample
5247
5248@noindent
5249causes the compiler to set the mode for @code{foo}, to be 16 bytes,
5250divided into @code{int} sized units. Assuming a 32-bit int (a vector of
358a3dbc 52514 units of 4 bytes), the corresponding mode of @code{foo} is V4SI@.
1b9191d2
AH
5252
5253This attribute is only applicable to integral and float scalars,
5254although arrays, pointers, and function return values are allowed in
5255conjunction with this construct.
5256
5257Aggregates with this attribute are invalid, even if they are of the same
5258size as a corresponding scalar. For example, the declaration:
5259
5260@smallexample
ad706f54 5261struct S @{ int a; @};
1b9191d2
AH
5262struct S __attribute__ ((vector_size (16))) foo;
5263@end smallexample
5264
5265@noindent
5266is invalid even if the size of the structure is the same as the size of
5267the @code{int}.
5268
a20f6f00
DS
5269@item selectany
5270The @code{selectany} attribute causes an initialized global variable to
5271have link-once semantics. When multiple definitions of the variable are
5272encountered by the linker, the first is selected and the remainder are
5273discarded. Following usage by the Microsoft compiler, the linker is told
5274@emph{not} to warn about size or content differences of the multiple
5275definitions.
5276
5277Although the primary usage of this attribute is for POD types, the
5278attribute can also be applied to global C++ objects that are initialized
5279by a constructor. In this case, the static initialization and destruction
5280code for the object is emitted in each translation defining the object,
5281but the calls to the constructor and destructor are protected by a
0ac11108 5282link-once guard variable.
a20f6f00
DS
5283
5284The @code{selectany} attribute is only available on Microsoft Windows
5285targets. You can use @code{__declspec (selectany)} as a synonym for
5286@code{__attribute__ ((selectany))} for compatibility with other
5287compilers.
5288
c1f7febf 5289@item weak
38bb2b65 5290The @code{weak} attribute is described in @ref{Function Attributes}.
6b6cb52e
DS
5291
5292@item dllimport
38bb2b65 5293The @code{dllimport} attribute is described in @ref{Function Attributes}.
6b6cb52e 5294
9baf8aea 5295@item dllexport
38bb2b65 5296The @code{dllexport} attribute is described in @ref{Function Attributes}.
6b6cb52e 5297
905e8651
RH
5298@end table
5299
542bf446 5300@anchor{AVR Variable Attributes}
3d33d151
AS
5301@subsection AVR Variable Attributes
5302
5303@table @code
5304@item progmem
5305@cindex @code{progmem} AVR variable attribute
542bf446
GJL
5306The @code{progmem} attribute is used on the AVR to place read-only
5307data in the non-volatile program memory (flash). The @code{progmem}
5308attribute accomplishes this by putting respective variables into a
5309section whose name starts with @code{.progmem}.
5310
aa9ec4db 5311This attribute works similar to the @code{section} attribute
542bf446
GJL
5312but adds additional checking. Notice that just like the
5313@code{section} attribute, @code{progmem} affects the location
5314of the data but not how this data is accessed.
5315
aa9ec4db
GJL
5316In order to read data located with the @code{progmem} attribute
5317(inline) assembler must be used.
c513ecbf 5318@smallexample
53cb97f9 5319/* Use custom macros from @w{@uref{http://nongnu.org/avr-libc/user-manual/,AVR-LibC}} */
aa9ec4db
GJL
5320#include <avr/pgmspace.h>
5321
5322/* Locate var in flash memory */
5323const int var[2] PROGMEM = @{ 1, 2 @};
5324
5325int read_var (int i)
5326@{
5327 /* Access var[] by accessor macro from avr/pgmspace.h */
5328 return (int) pgm_read_word (& var[i]);
5329@}
c513ecbf 5330@end smallexample
aa9ec4db 5331
542bf446
GJL
5332AVR is a Harvard architecture processor and data and read-only data
5333normally resides in the data memory (RAM).
aa9ec4db
GJL
5334
5335See also the @ref{AVR Named Address Spaces} section for
5336an alternate way to locate and access data in flash memory.
f9d29866
JR
5337
5338@item io
5339@itemx io (@var{addr})
5340Variables with the @code{io} attribute are used to address
5341memory-mapped peripherals in the io address range.
5342If an address is specified, the variable
5343is assigned that address, and the value is interpreted as an
5344address in the data address space.
5345Example:
5346
5347@smallexample
5348volatile int porta __attribute__((io (0x22)));
5349@end smallexample
5350
5351The address specified in the address in the data address range.
5352
5353Otherwise, the variable it is not assigned an address, but the
5354compiler will still use in/out instructions where applicable,
5355assuming some other module assigns an address in the io address range.
5356Example:
5357
5358@smallexample
5359extern volatile int porta __attribute__((io));
5360@end smallexample
5361
5362@item io_low
5363@itemx io_low (@var{addr})
5364This is like the @code{io} attribute, but additionally it informs the
5365compiler that the object lies in the lower half of the I/O area,
5366allowing the use of @code{cbi}, @code{sbi}, @code{sbic} and @code{sbis}
5367instructions.
5368
5369@item address
5370@itemx address (@var{addr})
5371Variables with the @code{address} attribute are used to address
5372memory-mapped peripherals that may lie outside the io address range.
5373
5374@smallexample
5375volatile int porta __attribute__((address (0x600)));
5376@end smallexample
5377
3d33d151
AS
5378@end table
5379
4af797b5
JZ
5380@subsection Blackfin Variable Attributes
5381
5382Three attributes are currently defined for the Blackfin.
5383
5384@table @code
5385@item l1_data
1588fb31
RW
5386@itemx l1_data_A
5387@itemx l1_data_B
4af797b5
JZ
5388@cindex @code{l1_data} variable attribute
5389@cindex @code{l1_data_A} variable attribute
5390@cindex @code{l1_data_B} variable attribute
5391Use these attributes on the Blackfin to place the variable into L1 Data SRAM.
358a3dbc
SL
5392Variables with @code{l1_data} attribute are put into the specific section
5393named @code{.l1.data}. Those with @code{l1_data_A} attribute are put into
4af797b5 5394the specific section named @code{.l1.data.A}. Those with @code{l1_data_B}
358a3dbc 5395attribute are put into the specific section named @code{.l1.data.B}.
603bb63e
BS
5396
5397@item l2
5398@cindex @code{l2} variable attribute
5399Use this attribute on the Blackfin to place the variable into L2 SRAM.
358a3dbc 5400Variables with @code{l2} attribute are put into the specific section
603bb63e 5401named @code{.l2.data}.
4af797b5
JZ
5402@end table
5403
905e8651 5404@subsection M32R/D Variable Attributes
845da534 5405
8a36672b 5406One attribute is currently defined for the M32R/D@.
905e8651
RH
5407
5408@table @code
845da534
DE
5409@item model (@var{model-name})
5410@cindex variable addressability on the M32R/D
5411Use this attribute on the M32R/D to set the addressability of an object.
5412The identifier @var{model-name} is one of @code{small}, @code{medium},
5413or @code{large}, representing each of the code models.
5414
5415Small model objects live in the lower 16MB of memory (so that their
5416addresses can be loaded with the @code{ld24} instruction).
5417
02f52e19 5418Medium and large model objects may live anywhere in the 32-bit address space
358a3dbc 5419(the compiler generates @code{seth/add3} instructions to load their
845da534 5420addresses).
905e8651 5421@end table
845da534 5422
e2491744
DD
5423@anchor{MeP Variable Attributes}
5424@subsection MeP Variable Attributes
5425
5426The MeP target has a number of addressing modes and busses. The
5427@code{near} space spans the standard memory space's first 16 megabytes
5428(24 bits). The @code{far} space spans the entire 32-bit memory space.
6f46cb63 5429The @code{based} space is a 128-byte region in the memory space that
e2491744 5430is addressed relative to the @code{$tp} register. The @code{tiny}
6f46cb63 5431space is a 65536-byte region relative to the @code{$gp} register. In
e2491744
DD
5432addition to these memory regions, the MeP target has a separate 16-bit
5433control bus which is specified with @code{cb} attributes.
5434
5435@table @code
5436
5437@item based
358a3dbc
SL
5438Any variable with the @code{based} attribute is assigned to the
5439@code{.based} section, and is accessed with relative to the
e2491744
DD
5440@code{$tp} register.
5441
5442@item tiny
5443Likewise, the @code{tiny} attribute assigned variables to the
5444@code{.tiny} section, relative to the @code{$gp} register.
5445
5446@item near
5447Variables with the @code{near} attribute are assumed to have addresses
5448that fit in a 24-bit addressing mode. This is the default for large
5449variables (@code{-mtiny=4} is the default) but this attribute can
5450override @code{-mtiny=} for small variables, or override @code{-ml}.
5451
5452@item far
5453Variables with the @code{far} attribute are addressed using a full
545432-bit address. Since this covers the entire memory space, this
5455allows modules to make no assumptions about where variables might be
5456stored.
5457
5458@item io
1588fb31 5459@itemx io (@var{addr})
e2491744
DD
5460Variables with the @code{io} attribute are used to address
5461memory-mapped peripherals. If an address is specified, the variable
5462is assigned that address, else it is not assigned an address (it is
358a3dbc 5463assumed some other module assigns an address). Example:
e2491744 5464
c513ecbf 5465@smallexample
e2491744 5466int timer_count __attribute__((io(0x123)));
c513ecbf 5467@end smallexample
e2491744
DD
5468
5469@item cb
1588fb31 5470@itemx cb (@var{addr})
e2491744
DD
5471Variables with the @code{cb} attribute are used to access the control
5472bus, using special instructions. @code{addr} indicates the control bus
5473address. Example:
5474
c513ecbf 5475@smallexample
e2491744 5476int cpu_clock __attribute__((cb(0x123)));
c513ecbf 5477@end smallexample
e2491744
DD
5478
5479@end table
5480
1ccbef77 5481@anchor{i386 Variable Attributes}
fe77449a
DR
5482@subsection i386 Variable Attributes
5483
5484Two attributes are currently defined for i386 configurations:
5485@code{ms_struct} and @code{gcc_struct}
5486
905e8651 5487@table @code
fe77449a
DR
5488@item ms_struct
5489@itemx gcc_struct
905e8651
RH
5490@cindex @code{ms_struct} attribute
5491@cindex @code{gcc_struct} attribute
fe77449a 5492
bafa88c2
SL
5493If @code{packed} is used on a structure, or if bit-fields are used,
5494it may be that the Microsoft ABI lays out the structure differently
5495than the way GCC normally does. Particularly when moving packed
fe77449a
DR
5496data between functions compiled with GCC and the native Microsoft compiler
5497(either via function call or as data in a file), it may be necessary to access
5498either format.
5499
95fef11f 5500Currently @option{-m[no-]ms-bitfields} is provided for the Microsoft Windows X86
fe77449a 5501compilers to match the native Microsoft compiler.
0ac11108
EC
5502
5503The Microsoft structure layout algorithm is fairly simple with the exception
bafa88c2
SL
5504of the bit-field packing.
5505The padding and alignment of members of structures and whether a bit-field
5506can straddle a storage-unit boundary are determine by these rules:
0ac11108
EC
5507
5508@enumerate
5509@item Structure members are stored sequentially in the order in which they are
5510declared: the first member has the lowest memory address and the last member
5511the highest.
5512
bafa88c2 5513@item Every data object has an alignment requirement. The alignment requirement
0ac11108 5514for all data except structures, unions, and arrays is either the size of the
bafa88c2
SL
5515object or the current packing size (specified with either the
5516@code{aligned} attribute or the @code{pack} pragma),
5517whichever is less. For structures, unions, and arrays,
5518the alignment requirement is the largest alignment requirement of its members.
0ac11108
EC
5519Every object is allocated an offset so that:
5520
bafa88c2
SL
5521@smallexample
5522offset % alignment_requirement == 0
5523@end smallexample
0ac11108 5524
40cbe8d2
SL
5525@item Adjacent bit-fields are packed into the same 1-, 2-, or 4-byte allocation
5526unit if the integral types are the same size and if the next bit-field fits
0ac11108 5527into the current allocation unit without crossing the boundary imposed by the
40cbe8d2 5528common alignment requirements of the bit-fields.
0ac11108
EC
5529@end enumerate
5530
40cbe8d2 5531MSVC interprets zero-length bit-fields in the following ways:
0ac11108
EC
5532
5533@enumerate
40cbe8d2
SL
5534@item If a zero-length bit-field is inserted between two bit-fields that
5535are normally coalesced, the bit-fields are not coalesced.
0ac11108
EC
5536
5537For example:
5538
5539@smallexample
5540struct
5541 @{
5542 unsigned long bf_1 : 12;
5543 unsigned long : 0;
5544 unsigned long bf_2 : 12;
5545 @} t1;
5546@end smallexample
5547
c513ecbf 5548@noindent
40cbe8d2
SL
5549The size of @code{t1} is 8 bytes with the zero-length bit-field. If the
5550zero-length bit-field were removed, @code{t1}'s size would be 4 bytes.
0ac11108 5551
40cbe8d2
SL
5552@item If a zero-length bit-field is inserted after a bit-field, @code{foo}, and the
5553alignment of the zero-length bit-field is greater than the member that follows it,
5554@code{bar}, @code{bar} is aligned as the type of the zero-length bit-field.
0ac11108
EC
5555
5556For example:
5557
5558@smallexample
5559struct
5560 @{
5561 char foo : 4;
5562 short : 0;
5563 char bar;
5564 @} t2;
5565
5566struct
5567 @{
5568 char foo : 4;
5569 short : 0;
5570 double bar;
5571 @} t3;
5572@end smallexample
5573
c513ecbf 5574@noindent
358a3dbc
SL
5575For @code{t2}, @code{bar} is placed at offset 2, rather than offset 1.
5576Accordingly, the size of @code{t2} is 4. For @code{t3}, the zero-length
40cbe8d2 5577bit-field does not affect the alignment of @code{bar} or, as a result, the size
0ac11108
EC
5578of the structure.
5579
5580Taking this into account, it is important to note the following:
5581
5582@enumerate
40cbe8d2
SL
5583@item If a zero-length bit-field follows a normal bit-field, the type of the
5584zero-length bit-field may affect the alignment of the structure as whole. For
5585example, @code{t2} has a size of 4 bytes, since the zero-length bit-field follows a
5586normal bit-field, and is of type short.
0ac11108 5587
40cbe8d2 5588@item Even if a zero-length bit-field is not followed by a normal bit-field, it may
0ac11108
EC
5589still affect the alignment of the structure:
5590
5591@smallexample
5592struct
5593 @{
5594 char foo : 6;
5595 long : 0;
5596 @} t4;
5597@end smallexample
5598
c513ecbf 5599@noindent
358a3dbc 5600Here, @code{t4} takes up 4 bytes.
0ac11108
EC
5601@end enumerate
5602
40cbe8d2 5603@item Zero-length bit-fields following non-bit-field members are ignored:
0ac11108
EC
5604
5605@smallexample
5606struct
5607 @{
5608 char foo;
5609 long : 0;
5610 char bar;
5611 @} t5;
5612@end smallexample
5613
c513ecbf 5614@noindent
358a3dbc 5615Here, @code{t5} takes up 2 bytes.
0ac11108 5616@end enumerate
c1f7febf
RK
5617@end table
5618
1ccbef77
EC
5619@subsection PowerPC Variable Attributes
5620
63d0dca4
DE
5621Three attributes currently are defined for PowerPC configurations:
5622@code{altivec}, @code{ms_struct} and @code{gcc_struct}.
1ccbef77 5623
63d0dca4 5624For full documentation of the struct attributes please see the
38bb2b65 5625documentation in @ref{i386 Variable Attributes}.
63d0dca4
DE
5626
5627For documentation of @code{altivec} attribute please see the
38bb2b65 5628documentation in @ref{PowerPC Type Attributes}.
1ccbef77 5629
85d9c13c
TS
5630@subsection SPU Variable Attributes
5631
5632The SPU supports the @code{spu_vector} attribute for variables. For
38bb2b65
SL
5633documentation of this attribute please see the documentation in
5634@ref{SPU Type Attributes}.
85d9c13c 5635
54e9a19d
DD
5636@subsection Xstormy16 Variable Attributes
5637
5638One attribute is currently defined for xstormy16 configurations:
38bb2b65 5639@code{below100}.
54e9a19d
DD
5640
5641@table @code
5642@item below100
5643@cindex @code{below100} attribute
5644
5645If a variable has the @code{below100} attribute (@code{BELOW100} is
358a3dbc
SL
5646allowed also), GCC places the variable in the first 0x100 bytes of
5647memory and use special opcodes to access it. Such variables are
54e9a19d
DD
5648placed in either the @code{.bss_below100} section or the
5649@code{.data_below100} section.
5650
5651@end table
5652
c1f7febf
RK
5653@node Type Attributes
5654@section Specifying Attributes of Types
5655@cindex attribute of types
5656@cindex type attributes
5657
5658The keyword @code{__attribute__} allows you to specify special
b9e75696
JM
5659attributes of @code{struct} and @code{union} types when you define
5660such types. This keyword is followed by an attribute specification
d5e254e1 5661inside double parentheses. Eight attributes are currently defined for
b9e75696 5662types: @code{aligned}, @code{packed}, @code{transparent_union},
d5e254e1
IE
5663@code{unused}, @code{deprecated}, @code{visibility}, @code{may_alias}
5664and @code{bnd_variable_size}. Other attributes are defined for
5665functions (@pxref{Function Attributes}), labels (@pxref{Label
883755a1 5666Attributes}) and for variables (@pxref{Variable Attributes}).
c1f7febf
RK
5667
5668You may also specify any one of these attributes with @samp{__}
5669preceding and following its keyword. This allows you to use these
5670attributes in header files without being concerned about a possible
5671macro of the same name. For example, you may use @code{__aligned__}
5672instead of @code{aligned}.
5673
4009f2e7
JM
5674You may specify type attributes in an enum, struct or union type
5675declaration or definition, or for other types in a @code{typedef}
5676declaration.
c1f7febf 5677
b9e75696
JM
5678For an enum, struct or union type, you may specify attributes either
5679between the enum, struct or union tag and the name of the type, or
5680just past the closing curly brace of the @emph{definition}. The
5681former syntax is preferred.
4051959b 5682
2c5e91d2
JM
5683@xref{Attribute Syntax}, for details of the exact syntax for using
5684attributes.
5685
c1f7febf
RK
5686@table @code
5687@cindex @code{aligned} attribute
5688@item aligned (@var{alignment})
5689This attribute specifies a minimum alignment (in bytes) for variables
5690of the specified type. For example, the declarations:
5691
5692@smallexample
f69eecfb
JL
5693struct S @{ short f[3]; @} __attribute__ ((aligned (8)));
5694typedef int more_aligned_int __attribute__ ((aligned (8)));
c1f7febf
RK
5695@end smallexample
5696
5697@noindent
bafa88c2 5698force the compiler to ensure (as far as it can) that each variable whose
358a3dbc 5699type is @code{struct S} or @code{more_aligned_int} is allocated and
981f6289 5700aligned @emph{at least} on a 8-byte boundary. On a SPARC, having all
c1f7febf
RK
5701variables of type @code{struct S} aligned to 8-byte boundaries allows
5702the compiler to use the @code{ldd} and @code{std} (doubleword load and
5703store) instructions when copying one variable of type @code{struct S} to
5704another, thus improving run-time efficiency.
5705
5706Note that the alignment of any given @code{struct} or @code{union} type
5490d604 5707is required by the ISO C standard to be at least a perfect multiple of
c1f7febf
RK
5708the lowest common multiple of the alignments of all of the members of
5709the @code{struct} or @code{union} in question. This means that you @emph{can}
5710effectively adjust the alignment of a @code{struct} or @code{union}
5711type by attaching an @code{aligned} attribute to any one of the members
5712of such a type, but the notation illustrated in the example above is a
5713more obvious, intuitive, and readable way to request the compiler to
5714adjust the alignment of an entire @code{struct} or @code{union} type.
5715
5716As in the preceding example, you can explicitly specify the alignment
5717(in bytes) that you wish the compiler to use for a given @code{struct}
5718or @code{union} type. Alternatively, you can leave out the alignment factor
5719and just ask the compiler to align a type to the maximum
5720useful alignment for the target machine you are compiling for. For
5721example, you could write:
5722
5723@smallexample
5724struct S @{ short f[3]; @} __attribute__ ((aligned));
5725@end smallexample
5726
5727Whenever you leave out the alignment factor in an @code{aligned}
5728attribute specification, the compiler automatically sets the alignment
c417597c 5729for the type to the largest alignment that is ever used for any data
c1f7febf
RK
5730type on the target machine you are compiling for. Doing this can often
5731make copy operations more efficient, because the compiler can use
5732whatever instructions copy the biggest chunks of memory when performing
c417597c 5733copies to or from the variables that have types that you have aligned
c1f7febf
RK
5734this way.
5735
5736In the example above, if the size of each @code{short} is 2 bytes, then
5737the size of the entire @code{struct S} type is 6 bytes. The smallest
c417597c 5738power of two that is greater than or equal to that is 8, so the
c1f7febf
RK
5739compiler sets the alignment for the entire @code{struct S} type to 8
5740bytes.
5741
5742Note that although you can ask the compiler to select a time-efficient
5743alignment for a given type and then declare only individual stand-alone
5744objects of that type, the compiler's ability to select a time-efficient
5745alignment is primarily useful only when you plan to create arrays of
5746variables having the relevant (efficiently aligned) type. If you
5747declare or use arrays of variables of an efficiently-aligned type, then
358a3dbc 5748it is likely that your program also does pointer arithmetic (or
c1f7febf
RK
5749subscripting, which amounts to the same thing) on pointers to the
5750relevant type, and the code that the compiler generates for these
358a3dbc 5751pointer arithmetic operations is often more efficient for
c1f7febf
RK
5752efficiently-aligned types than for other types.
5753
5754The @code{aligned} attribute can only increase the alignment; but you
5755can decrease it by specifying @code{packed} as well. See below.
5756
5757Note that the effectiveness of @code{aligned} attributes may be limited
5758by inherent limitations in your linker. On many systems, the linker is
5759only able to arrange for variables to be aligned up to a certain maximum
5760alignment. (For some linkers, the maximum supported alignment may
5761be very very small.) If your linker is only able to align variables
6f46cb63
SL
5762up to a maximum of 8-byte alignment, then specifying @code{aligned(16)}
5763in an @code{__attribute__} still only provides you with 8-byte
c1f7febf
RK
5764alignment. See your linker documentation for further information.
5765
5766@item packed
a5bcc582 5767This attribute, attached to @code{struct} or @code{union} type
40cbe8d2 5768definition, specifies that each member (other than zero-width bit-fields)
d1a701eb
MM
5769of the structure or union is placed to minimize the memory required. When
5770attached to an @code{enum} definition, it indicates that the smallest
5771integral type should be used.
c1f7febf 5772
84330467 5773@opindex fshort-enums
c1f7febf
RK
5774Specifying this attribute for @code{struct} and @code{union} types is
5775equivalent to specifying the @code{packed} attribute on each of the
84330467 5776structure or union members. Specifying the @option{-fshort-enums}
c1f7febf
RK
5777flag on the line is equivalent to specifying the @code{packed}
5778attribute on all @code{enum} definitions.
5779
a5bcc582
NS
5780In the following example @code{struct my_packed_struct}'s members are
5781packed closely together, but the internal layout of its @code{s} member
358a3dbc 5782is not packed---to do that, @code{struct my_unpacked_struct} needs to
a5bcc582
NS
5783be packed too.
5784
5785@smallexample
5786struct my_unpacked_struct
5787 @{
5788 char c;
5789 int i;
5790 @};
5791
75b66a16 5792struct __attribute__ ((__packed__)) my_packed_struct
a5bcc582
NS
5793 @{
5794 char c;
5795 int i;
5796 struct my_unpacked_struct s;
5797 @};
5798@end smallexample
5799
e4ae5e77 5800You may only specify this attribute on the definition of an @code{enum},
c417597c 5801@code{struct} or @code{union}, not on a @code{typedef} that does not
a5bcc582 5802also define the enumerated type, structure or union.
c1f7febf
RK
5803
5804@item transparent_union
c9f2b7e9
MP
5805@cindex @code{transparent_union} attribute
5806
c1f7febf
RK
5807This attribute, attached to a @code{union} type definition, indicates
5808that any function parameter having that union type causes calls to that
5809function to be treated in a special way.
5810
5811First, the argument corresponding to a transparent union type can be of
5812any type in the union; no cast is required. Also, if the union contains
5813a pointer type, the corresponding argument can be a null pointer
5814constant or a void pointer expression; and if the union contains a void
5815pointer type, the corresponding argument can be any pointer expression.
5816If the union member type is a pointer, qualifiers like @code{const} on
5817the referenced type must be respected, just as with normal pointer
5818conversions.
5819
5820Second, the argument is passed to the function using the calling
64c18e57 5821conventions of the first member of the transparent union, not the calling
c1f7febf
RK
5822conventions of the union itself. All members of the union must have the
5823same machine representation; this is necessary for this argument passing
5824to work properly.
5825
5826Transparent unions are designed for library functions that have multiple
5827interfaces for compatibility reasons. For example, suppose the
5828@code{wait} function must accept either a value of type @code{int *} to
bafa88c2 5829comply with POSIX, or a value of type @code{union wait *} to comply with
c1f7febf
RK
5830the 4.1BSD interface. If @code{wait}'s parameter were @code{void *},
5831@code{wait} would accept both kinds of arguments, but it would also
5832accept any other pointer type and this would make argument type checking
5833less useful. Instead, @code{<sys/wait.h>} might define the interface
5834as follows:
5835
5836@smallexample
4009f2e7 5837typedef union __attribute__ ((__transparent_union__))
c1f7febf
RK
5838 @{
5839 int *__ip;
5840 union wait *__up;
4009f2e7 5841 @} wait_status_ptr_t;
c1f7febf
RK
5842
5843pid_t wait (wait_status_ptr_t);
5844@end smallexample
5845
c513ecbf 5846@noindent
c1f7febf
RK
5847This interface allows either @code{int *} or @code{union wait *}
5848arguments to be passed, using the @code{int *} calling convention.
5849The program can call @code{wait} with arguments of either type:
5850
3ab51846 5851@smallexample
c1f7febf
RK
5852int w1 () @{ int w; return wait (&w); @}
5853int w2 () @{ union wait w; return wait (&w); @}
3ab51846 5854@end smallexample
c1f7febf 5855
c513ecbf 5856@noindent
c1f7febf
RK
5857With this interface, @code{wait}'s implementation might look like this:
5858
3ab51846 5859@smallexample
c1f7febf
RK
5860pid_t wait (wait_status_ptr_t p)
5861@{
5862 return waitpid (-1, p.__ip, 0);
5863@}
3ab51846 5864@end smallexample
d863830b
JL
5865
5866@item unused
5867When attached to a type (including a @code{union} or a @code{struct}),
5868this attribute means that variables of that type are meant to appear
358a3dbc 5869possibly unused. GCC does not produce a warning for any variables of
d863830b
JL
5870that type, even if the variable appears to do nothing. This is often
5871the case with lock or thread classes, which are usually defined and then
5872not referenced, but contain constructors and destructors that have
956d6950 5873nontrivial bookkeeping functions.
d863830b 5874
e23bd218 5875@item deprecated
9b86d6bb 5876@itemx deprecated (@var{msg})
e23bd218
IR
5877The @code{deprecated} attribute results in a warning if the type
5878is used anywhere in the source file. This is useful when identifying
5879types that are expected to be removed in a future version of a program.
5880If possible, the warning also includes the location of the declaration
5881of the deprecated type, to enable users to easily find further
5882information about why the type is deprecated, or what they should do
5883instead. Note that the warnings only occur for uses and then only
adc9fe67 5884if the type is being applied to an identifier that itself is not being
e23bd218
IR
5885declared as deprecated.
5886
5887@smallexample
5888typedef int T1 __attribute__ ((deprecated));
5889T1 x;
5890typedef T1 T2;
5891T2 y;
5892typedef T1 T3 __attribute__ ((deprecated));
5893T3 z __attribute__ ((deprecated));
5894@end smallexample
5895
358a3dbc 5896@noindent
e23bd218
IR
5897results in a warning on line 2 and 3 but not lines 4, 5, or 6. No
5898warning is issued for line 4 because T2 is not explicitly
5899deprecated. Line 5 has no warning because T3 is explicitly
358a3dbc
SL
5900deprecated. Similarly for line 6. The optional @var{msg}
5901argument, which must be a string, is printed in the warning if
9b86d6bb 5902present.
e23bd218
IR
5903
5904The @code{deprecated} attribute can also be used for functions and
5905variables (@pxref{Function Attributes}, @pxref{Variable Attributes}.)
5906
d18b1ed8 5907@item may_alias
ac7ee6ad
RG
5908Accesses through pointers to types with this attribute are not subject
5909to type-based alias analysis, but are instead assumed to be able to alias
bafa88c2
SL
5910any other type of objects.
5911In the context of section 6.5 paragraph 7 of the C99 standard,
5912an lvalue expression
ac7ee6ad
RG
5913dereferencing such a pointer is treated like having a character type.
5914See @option{-fstrict-aliasing} for more information on aliasing issues.
5915This extension exists to support some vector APIs, in which pointers to
5916one vector type are permitted to alias pointers to a different vector type.
5917
5918Note that an object of a type with this attribute does not have any
5919special semantics.
d18b1ed8
OS
5920
5921Example of use:
5922
478c9e72 5923@smallexample
d18b1ed8
OS
5924typedef short __attribute__((__may_alias__)) short_a;
5925
5926int
5927main (void)
5928@{
5929 int a = 0x12345678;
5930 short_a *b = (short_a *) &a;
5931
5932 b[1] = 0;
5933
5934 if (a == 0x12345678)
5935 abort();
5936
5937 exit(0);
5938@}
478c9e72 5939@end smallexample
d18b1ed8 5940
c513ecbf 5941@noindent
d18b1ed8
OS
5942If you replaced @code{short_a} with @code{short} in the variable
5943declaration, the above program would abort when compiled with
5944@option{-fstrict-aliasing}, which is on by default at @option{-O2} or
5945above in recent GCC versions.
fe77449a 5946
b9e75696 5947@item visibility
b9e75696
JM
5948In C++, attribute visibility (@pxref{Function Attributes}) can also be
5949applied to class, struct, union and enum types. Unlike other type
5950attributes, the attribute must appear between the initial keyword and
5951the name of the type; it cannot appear after the body of the type.
5952
b70f0f48
JM
5953Note that the type visibility is applied to vague linkage entities
5954associated with the class (vtable, typeinfo node, etc.). In
5955particular, if a class is thrown as an exception in one shared object
5956and caught in another, the class must have default visibility.
358a3dbc 5957Otherwise the two shared objects are unable to use the same
b70f0f48
JM
5958typeinfo node and exception handling will break.
5959
976d5a22
TT
5960@item designated_init
5961This attribute may only be applied to structure types. It indicates
5962that any initialization of an object of this type must use designated
5963initializers rather than positional initializers. The intent of this
5964attribute is to allow the programmer to indicate that a structure's
5965layout may change, and that therefore relying on positional
5966initialization will result in future breakage.
5967
5968GCC emits warnings based on this attribute by default; use
5969@option{-Wno-designated-init} to suppress them.
5970
d5e254e1
IE
5971@item bnd_variable_size
5972When applied to a structure field, this attribute tells Pointer
5973Bounds Checker that the size of this field should not be computed
5974using static type information. It may be used to mark variable
5975sized static array fields placed at the end of a structure.
5976
5977@smallexample
5978struct S
5979@{
5980 int size;
5981 char data[1];
5982@}
5983S *p = (S *)malloc (sizeof(S) + 100);
5984p->data[10] = 0; //Bounds violation
5985@end smallexample
5986
5987By using an attribute for a field we may avoid bound violation
5988we most probably do not want to see:
5989
5990@smallexample
5991struct S
5992@{
5993 int size;
5994 char data[1] __attribute__((bnd_variable_size));
5995@}
5996S *p = (S *)malloc (sizeof(S) + 100);
5997p->data[10] = 0; //OK
5998@end smallexample
5999
38bb2b65
SL
6000@end table
6001
ada37101
TG
6002To specify multiple attributes, separate them by commas within the
6003double parentheses: for example, @samp{__attribute__ ((aligned (16),
6004packed))}.
6005
04fb56d5
MM
6006@subsection ARM Type Attributes
6007
6008On those ARM targets that support @code{dllimport} (such as Symbian
f0eb93a8 6009OS), you can use the @code{notshared} attribute to indicate that the
04fb56d5 6010virtual table and other similar data for a class should not be
8a36672b 6011exported from a DLL@. For example:
04fb56d5
MM
6012
6013@smallexample
6014class __declspec(notshared) C @{
6015public:
f0eb93a8 6016 __declspec(dllimport) C();
04fb56d5
MM
6017 virtual void f();
6018@}
6019
6020__declspec(dllexport)
6021C::C() @{@}
6022@end smallexample
6023
c513ecbf 6024@noindent
04fb56d5
MM
6025In this code, @code{C::C} is exported from the current DLL, but the
6026virtual table for @code{C} is not exported. (You can use
6027@code{__attribute__} instead of @code{__declspec} if you prefer, but
6028most Symbian OS code uses @code{__declspec}.)
6029
e2491744
DD
6030@anchor{MeP Type Attributes}
6031@subsection MeP Type Attributes
6032
6033Many of the MeP variable attributes may be applied to types as well.
6034Specifically, the @code{based}, @code{tiny}, @code{near}, and
6035@code{far} attributes may be applied to either. The @code{io} and
6036@code{cb} attributes may not be applied to types.
6037
63d0dca4 6038@anchor{i386 Type Attributes}
fe77449a
DR
6039@subsection i386 Type Attributes
6040
6041Two attributes are currently defined for i386 configurations:
38bb2b65
SL
6042@code{ms_struct} and @code{gcc_struct}.
6043
6044@table @code
fe77449a
DR
6045
6046@item ms_struct
6047@itemx gcc_struct
6048@cindex @code{ms_struct}
6049@cindex @code{gcc_struct}
6050
6051If @code{packed} is used on a structure, or if bit-fields are used
6052it may be that the Microsoft ABI packs them differently
358a3dbc 6053than GCC normally packs them. Particularly when moving packed
fe77449a
DR
6054data between functions compiled with GCC and the native Microsoft compiler
6055(either via function call or as data in a file), it may be necessary to access
6056either format.
6057
95fef11f 6058Currently @option{-m[no-]ms-bitfields} is provided for the Microsoft Windows X86
fe77449a 6059compilers to match the native Microsoft compiler.
c1f7febf
RK
6060@end table
6061
63d0dca4
DE
6062@anchor{PowerPC Type Attributes}
6063@subsection PowerPC Type Attributes
6064
6065Three attributes currently are defined for PowerPC configurations:
6066@code{altivec}, @code{ms_struct} and @code{gcc_struct}.
6067
ff2ce160 6068For full documentation of the @code{ms_struct} and @code{gcc_struct}
38bb2b65 6069attributes please see the documentation in @ref{i386 Type Attributes}.
63d0dca4
DE
6070
6071The @code{altivec} attribute allows one to declare AltiVec vector data
6072types supported by the AltiVec Programming Interface Manual. The
6073attribute requires an argument to specify one of three vector types:
6074@code{vector__}, @code{pixel__} (always followed by unsigned short),
6075and @code{bool__} (always followed by unsigned).
6076
6077@smallexample
6078__attribute__((altivec(vector__)))
6079__attribute__((altivec(pixel__))) unsigned short
6080__attribute__((altivec(bool__))) unsigned
6081@end smallexample
6082
6083These attributes mainly are intended to support the @code{__vector},
6084@code{__pixel}, and @code{__bool} AltiVec keywords.
6085
85d9c13c
TS
6086@anchor{SPU Type Attributes}
6087@subsection SPU Type Attributes
6088
6089The SPU supports the @code{spu_vector} attribute for types. This attribute
6090allows one to declare vector data types supported by the Sony/Toshiba/IBM SPU
6091Language Extensions Specification. It is intended to support the
6092@code{__vector} keyword.
6093
2be478a2
JW
6094@node Alignment
6095@section Inquiring on Alignment of Types or Variables
6096@cindex alignment
6097@cindex type alignment
6098@cindex variable alignment
6099
6100The keyword @code{__alignof__} allows you to inquire about how an object
6101is aligned, or the minimum alignment usually required by a type. Its
6102syntax is just like @code{sizeof}.
6103
6104For example, if the target machine requires a @code{double} value to be
6105aligned on an 8-byte boundary, then @code{__alignof__ (double)} is 8.
6106This is true on many RISC machines. On more traditional machine
6107designs, @code{__alignof__ (double)} is 4 or even 2.
6108
6109Some machines never actually require alignment; they allow reference to any
6110data type even at an odd address. For these machines, @code{__alignof__}
358a3dbc 6111reports the smallest alignment that GCC gives the data type, usually as
2be478a2
JW
6112mandated by the target ABI.
6113
6114If the operand of @code{__alignof__} is an lvalue rather than a type,
6115its value is the required alignment for its type, taking into account
6116any minimum alignment specified with GCC's @code{__attribute__}
6117extension (@pxref{Variable Attributes}). For example, after this
6118declaration:
6119
6120@smallexample
6121struct foo @{ int x; char y; @} foo1;
6122@end smallexample
6123
6124@noindent
6125the value of @code{__alignof__ (foo1.y)} is 1, even though its actual
6126alignment is probably 2 or 4, the same as @code{__alignof__ (int)}.
6127
6128It is an error to ask for the alignment of an incomplete type.
6129
85d9c13c 6130
c1f7febf
RK
6131@node Inline
6132@section An Inline Function is As Fast As a Macro
6133@cindex inline functions
6134@cindex integrating function code
6135@cindex open coding
6136@cindex macros, inline alternative
6137
0a052b16
GK
6138By declaring a function inline, you can direct GCC to make
6139calls to that function faster. One way GCC can achieve this is to
c1f7febf
RK
6140integrate that function's code into the code for its callers. This
6141makes execution faster by eliminating the function-call overhead; in
0a052b16
GK
6142addition, if any of the actual argument values are constant, their
6143known values may permit simplifications at compile time so that not
6144all of the inline function's code needs to be included. The effect on
6145code size is less predictable; object code may be larger or smaller
6146with function inlining, depending on the particular case. You can
6147also direct GCC to try to integrate all ``simple enough'' functions
6148into their callers with the option @option{-finline-functions}.
6149
6150GCC implements three different semantics of declaring a function
da1c7394
ILT
6151inline. One is available with @option{-std=gnu89} or
6152@option{-fgnu89-inline} or when @code{gnu_inline} attribute is present
2778d766 6153on all inline declarations, another when
48b0b196
JM
6154@option{-std=c99}, @option{-std=c11},
6155@option{-std=gnu99} or @option{-std=gnu11}
2778d766 6156(without @option{-fgnu89-inline}), and the third
da1c7394 6157is used when compiling C++.
4b404517 6158
c1f7febf
RK
6159To declare a function inline, use the @code{inline} keyword in its
6160declaration, like this:
6161
3ab51846 6162@smallexample
0a052b16 6163static inline int
c1f7febf
RK
6164inc (int *a)
6165@{
bcbc9564 6166 return (*a)++;
c1f7febf 6167@}
3ab51846 6168@end smallexample
c1f7febf 6169
7e1542b9 6170If you are writing a header file to be included in ISO C90 programs, write
0a052b16 6171@code{__inline__} instead of @code{inline}. @xref{Alternate Keywords}.
247b14bd 6172
0a052b16
GK
6173The three types of inlining behave similarly in two important cases:
6174when the @code{inline} keyword is used on a @code{static} function,
6175like the example above, and when a function is first declared without
6176using the @code{inline} keyword and then is defined with
6177@code{inline}, like this:
c1f7febf 6178
0a052b16
GK
6179@smallexample
6180extern int inc (int *a);
6181inline int
6182inc (int *a)
6183@{
bcbc9564 6184 return (*a)++;
0a052b16
GK
6185@}
6186@end smallexample
c1f7febf 6187
0a052b16
GK
6188In both of these common cases, the program behaves the same as if you
6189had not used the @code{inline} keyword, except for its speed.
c1f7febf
RK
6190
6191@cindex inline functions, omission of
84330467 6192@opindex fkeep-inline-functions
c1f7febf
RK
6193When a function is both inline and @code{static}, if all calls to the
6194function are integrated into the caller, and the function's address is
6195never used, then the function's own assembler code is never referenced.
f0523f02 6196In this case, GCC does not actually output assembler code for the
84330467 6197function, unless you specify the option @option{-fkeep-inline-functions}.
c1f7febf
RK
6198Some calls cannot be integrated for various reasons (in particular,
6199calls that precede the function's definition cannot be integrated, and
6200neither can recursive calls within the definition). If there is a
6201nonintegrated call, then the function is compiled to assembler code as
6202usual. The function must also be compiled as usual if the program
6203refers to its address, because that can't be inlined.
6204
0a052b16
GK
6205@opindex Winline
6206Note that certain usages in a function definition can make it unsuitable
bafa88c2
SL
6207for inline substitution. Among these usages are: variadic functions, use of
6208@code{alloca}, use of variable-length data types (@pxref{Variable Length}),
0a052b16
GK
6209use of computed goto (@pxref{Labels as Values}), use of nonlocal goto,
6210and nested functions (@pxref{Nested Functions}). Using @option{-Winline}
358a3dbc
SL
6211warns when a function marked @code{inline} could not be substituted,
6212and gives the reason for the failure.
0a052b16
GK
6213
6214@cindex automatic @code{inline} for C++ member fns
6215@cindex @code{inline} automatic for C++ member fns
6216@cindex member fns, automatically @code{inline}
6217@cindex C++ member fns, automatically @code{inline}
6218@opindex fno-default-inline
6219As required by ISO C++, GCC considers member functions defined within
6220the body of a class to be marked inline even if they are
6221not explicitly declared with the @code{inline} keyword. You can
6222override this with @option{-fno-default-inline}; @pxref{C++ Dialect
6223Options,,Options Controlling C++ Dialect}.
6224
6225GCC does not inline any functions when not optimizing unless you specify
6226the @samp{always_inline} attribute for the function, like this:
6227
6228@smallexample
6229/* @r{Prototype.} */
6230inline void foo (const char) __attribute__((always_inline));
6231@end smallexample
6232
7e1542b9 6233The remainder of this section is specific to GNU C90 inlining.
0a052b16 6234
c1f7febf
RK
6235@cindex non-static inline function
6236When an inline function is not @code{static}, then the compiler must assume
6237that there may be calls from other source files; since a global symbol can
6238be defined only once in any program, the function must not be defined in
6239the other source files, so the calls therein cannot be integrated.
6240Therefore, a non-@code{static} inline function is always compiled on its
6241own in the usual fashion.
6242
6243If you specify both @code{inline} and @code{extern} in the function
6244definition, then the definition is used only for inlining. In no case
6245is the function compiled on its own, not even if you refer to its
6246address explicitly. Such an address becomes an external reference, as
6247if you had only declared the function, and had not defined it.
6248
6249This combination of @code{inline} and @code{extern} has almost the
6250effect of a macro. The way to use it is to put a function definition in
6251a header file with these keywords, and put another copy of the
6252definition (lacking @code{inline} and @code{extern}) in a library file.
358a3dbc
SL
6253The definition in the header file causes most calls to the function
6254to be inlined. If any uses of the function remain, they refer to
c1f7febf
RK
6255the single copy in the library.
6256
8f0fe813
NS
6257@node Volatiles
6258@section When is a Volatile Object Accessed?
6259@cindex accessing volatiles
6260@cindex volatile read
6261@cindex volatile write
6262@cindex volatile access
6263
6264C has the concept of volatile objects. These are normally accessed by
6265pointers and used for accessing hardware or inter-thread
2b0d3573 6266communication. The standard encourages compilers to refrain from
8f0fe813
NS
6267optimizations concerning accesses to volatile objects, but leaves it
6268implementation defined as to what constitutes a volatile access. The
6269minimum requirement is that at a sequence point all previous accesses
6270to volatile objects have stabilized and no subsequent accesses have
6271occurred. Thus an implementation is free to reorder and combine
c417597c 6272volatile accesses that occur between sequence points, but cannot do
2b0d3573 6273so for accesses across a sequence point. The use of volatile does
8f0fe813
NS
6274not allow you to violate the restriction on updating objects multiple
6275times between two sequence points.
6276
6277Accesses to non-volatile objects are not ordered with respect to
6278volatile accesses. You cannot use a volatile object as a memory
6279barrier to order a sequence of writes to non-volatile memory. For
6280instance:
6281
6282@smallexample
6283int *ptr = @var{something};
6284volatile int vobj;
6285*ptr = @var{something};
6286vobj = 1;
6287@end smallexample
6288
c513ecbf 6289@noindent
8f0fe813 6290Unless @var{*ptr} and @var{vobj} can be aliased, it is not guaranteed
358a3dbc
SL
6291that the write to @var{*ptr} occurs by the time the update
6292of @var{vobj} happens. If you need this guarantee, you must use
8f0fe813
NS
6293a stronger memory barrier such as:
6294
6295@smallexample
6296int *ptr = @var{something};
6297volatile int vobj;
6298*ptr = @var{something};
6299asm volatile ("" : : : "memory");
6300vobj = 1;
6301@end smallexample
6302
2b0d3573 6303A scalar volatile object is read when it is accessed in a void context:
8f0fe813
NS
6304
6305@smallexample
6306volatile int *src = @var{somevalue};
6307*src;
6308@end smallexample
6309
6310Such expressions are rvalues, and GCC implements this as a
6311read of the volatile object being pointed to.
6312
6313Assignments are also expressions and have an rvalue. However when
6314assigning to a scalar volatile, the volatile object is not reread,
6315regardless of whether the assignment expression's rvalue is used or
6316not. If the assignment's rvalue is used, the value is that assigned
6317to the volatile object. For instance, there is no read of @var{vobj}
6318in all the following cases:
6319
6320@smallexample
6321int obj;
6322volatile int vobj;
6323vobj = @var{something};
6324obj = vobj = @var{something};
6325obj ? vobj = @var{onething} : vobj = @var{anotherthing};
6326obj = (@var{something}, vobj = @var{anotherthing});
6327@end smallexample
6328
6329If you need to read the volatile object after an assignment has
6330occurred, you must use a separate expression with an intervening
6331sequence point.
6332
40cbe8d2
SL
6333As bit-fields are not individually addressable, volatile bit-fields may
6334be implicitly read when written to, or when adjacent bit-fields are
6335accessed. Bit-field operations may be optimized such that adjacent
6336bit-fields are only partially accessed, if they straddle a storage unit
6337boundary. For these reasons it is unwise to use volatile bit-fields to
8f0fe813
NS
6338access hardware.
6339
04e137a1
DW
6340@node Using Assembly Language with C
6341@section How to Use Inline Assembly Language in C Code
c1f7febf 6342
04e137a1
DW
6343GCC provides various extensions that allow you to embed assembler within
6344C code.
805c33df 6345
04e137a1
DW
6346@menu
6347* Basic Asm:: Inline assembler with no operands.
6348* Extended Asm:: Inline assembler with operands.
6349* Constraints:: Constraints for @code{asm} operands
6350* Asm Labels:: Specifying the assembler name to use for a C symbol.
6351* Explicit Reg Vars:: Defining variables residing in specified registers.
6352* Size of an asm:: How GCC calculates the size of an @code{asm} block.
6353@end menu
c1f7febf 6354
04e137a1
DW
6355@node Basic Asm
6356@subsection Basic Asm --- Assembler Instructions with No Operands
6357@cindex basic @code{asm}
6358
6359The @code{asm} keyword allows you to embed assembler instructions within
6360C code.
6361
6362@example
6363asm [ volatile ] ( AssemblerInstructions )
6364@end example
6365
6366To create headers compatible with ISO C, write @code{__asm__} instead of
6367@code{asm} (@pxref{Alternate Keywords}).
6368
6369By definition, a Basic @code{asm} statement is one with no operands.
6370@code{asm} statements that contain one or more colons (used to delineate
6371operands) are considered to be Extended (for example, @code{asm("int $3")}
6372is Basic, and @code{asm("int $3" : )} is Extended). @xref{Extended Asm}.
6373
6374@subsubheading Qualifiers
6375@emph{volatile}
6376@*
6377This optional qualifier has no effect. All Basic @code{asm} blocks are
6378implicitly volatile.
6379
6380@subsubheading Parameters
6381@emph{AssemblerInstructions}
6382@*
6383This is a literal string that specifies the assembler code. The string can
6384contain any instructions recognized by the assembler, including directives.
6385GCC does not parse the assembler instructions themselves and
6386does not know what they mean or even whether they are valid assembler input.
6387The compiler copies it verbatim to the assembly language output file, without
6388processing dialects or any of the "%" operators that are available with
6389Extended @code{asm}. This results in minor differences between Basic
6390@code{asm} strings and Extended @code{asm} templates. For example, to refer to
6391registers you might use %%eax in Extended @code{asm} and %eax in Basic
6392@code{asm}.
6393
6394You may place multiple assembler instructions together in a single @code{asm}
6395string, separated by the characters normally used in assembly code for the
6396system. A combination that works in most places is a newline to break the
6397line, plus a tab character (written as "\n\t").
6398Some assemblers allow semicolons as a line separator. However,
6399note that some assembler dialects use semicolons to start a comment.
6400
6401Do not expect a sequence of @code{asm} statements to remain perfectly
6402consecutive after compilation. If certain instructions need to remain
6403consecutive in the output, put them in a single multi-instruction asm
6404statement. Note that GCC's optimizers can move @code{asm} statements
6405relative to other code, including across jumps.
6406
6407@code{asm} statements may not perform jumps into other @code{asm} statements.
6408GCC does not know about these jumps, and therefore cannot take
6409account of them when deciding how to optimize. Jumps from @code{asm} to C
6410labels are only supported in Extended @code{asm}.
6411
6412@subsubheading Remarks
6413Using Extended @code{asm} will typically produce smaller, safer, and more
6414efficient code, and in most cases it is a better solution. When writing
6415inline assembly language outside of C functions, however, you must use Basic
6416@code{asm}. Extended @code{asm} statements have to be inside a C function.
3a96c7cc
DW
6417Functions declared with the @code{naked} attribute also require Basic
6418@code{asm} (@pxref{Function Attributes}).
04e137a1
DW
6419
6420Under certain circumstances, GCC may duplicate (or remove duplicates of) your
6421assembly code when optimizing. This can lead to unexpected duplicate
6422symbol errors during compilation if your assembly code defines symbols or
6423labels.
6424
6425Safely accessing C data and calling functions from Basic @code{asm} is more
6426complex than it may appear. To access C data, it is better to use Extended
6427@code{asm}.
6428
6429Since GCC does not parse the AssemblerInstructions, it has no
6430visibility of any symbols it references. This may result in GCC discarding
6431those symbols as unreferenced.
6432
6433Unlike Extended @code{asm}, all Basic @code{asm} blocks are implicitly
6434volatile. @xref{Volatile}. Similarly, Basic @code{asm} blocks are not treated
6435as though they used a "memory" clobber (@pxref{Clobbers}).
6436
6437All Basic @code{asm} blocks use the assembler dialect specified by the
6438@option{-masm} command-line option. Basic @code{asm} provides no
6439mechanism to provide different assembler strings for different dialects.
6440
6441Here is an example of Basic @code{asm} for i386:
6442
6443@example
6444/* Note that this code will not compile with -masm=intel */
6445#define DebugBreak() asm("int $3")
6446@end example
c1f7febf 6447
04e137a1
DW
6448@node Extended Asm
6449@subsection Extended Asm - Assembler Instructions with C Expression Operands
6450@cindex @code{asm} keyword
6451@cindex extended @code{asm}
6452@cindex assembler instructions
8fe1938e 6453
04e137a1
DW
6454The @code{asm} keyword allows you to embed assembler instructions within C
6455code. With Extended @code{asm} you can read and write C variables from
6456assembler and perform jumps from assembler code to C labels.
6457
6458@example
6459@ifhtml
6460asm [volatile] ( AssemblerTemplate : [OutputOperands] [ : [InputOperands] [ : [Clobbers] ] ] )
6461
6462asm [volatile] goto ( AssemblerTemplate : : [InputOperands] : [Clobbers] : GotoLabels )
6463@end ifhtml
6464@ifnothtml
6465asm [volatile] ( AssemblerTemplate
6466 : [OutputOperands]
6467 [ : [InputOperands]
6468 [ : [Clobbers] ] ])
6469
6470asm [volatile] goto ( AssemblerTemplate
6471 :
6472 : [InputOperands]
6473 : [Clobbers]
6474 : GotoLabels)
6475@end ifnothtml
6476@end example
6477
6478To create headers compatible with ISO C, write @code{__asm__} instead of
6479@code{asm} and @code{__volatile__} instead of @code{volatile}
6480(@pxref{Alternate Keywords}). There is no alternate for @code{goto}.
6481
6482By definition, Extended @code{asm} is an @code{asm} statement that contains
6483operands. To separate the classes of operands, you use colons. Basic
6484@code{asm} statements contain no colons. (So, for example,
6485@code{asm("int $3")} is Basic @code{asm}, and @code{asm("int $3" : )} is
6486Extended @code{asm}. @pxref{Basic Asm}.)
6487
6488@subsubheading Qualifiers
6489@emph{volatile}
6490@*
6491The typical use of Extended @code{asm} statements is to manipulate input
6492values to produce output values. However, your @code{asm} statements may
6493also produce side effects. If so, you may need to use the @code{volatile}
6494qualifier to disable certain optimizations. @xref{Volatile}.
6495
6496@emph{goto}
6497@*
6498This qualifier informs the compiler that the @code{asm} statement may
6499perform a jump to one of the labels listed in the GotoLabels section.
6500@xref{GotoLabels}.
6501
6502@subsubheading Parameters
6503@emph{AssemblerTemplate}
6504@*
6505This is a literal string that contains the assembler code. It is a
6506combination of fixed text and tokens that refer to the input, output,
6507and goto parameters. @xref{AssemblerTemplate}.
6508
6509@emph{OutputOperands}
6510@*
6511A comma-separated list of the C variables modified by the instructions in the
6512AssemblerTemplate. @xref{OutputOperands}.
6513
6514@emph{InputOperands}
6515@*
6516A comma-separated list of C expressions read by the instructions in the
6517AssemblerTemplate. @xref{InputOperands}.
6518
6519@emph{Clobbers}
6520@*
6521A comma-separated list of registers or other values changed by the
6522AssemblerTemplate, beyond those listed as outputs. @xref{Clobbers}.
6523
6524@emph{GotoLabels}
6525@*
6526When you are using the @code{goto} form of @code{asm}, this section contains
6527the list of all C labels to which the AssemblerTemplate may jump.
6528@xref{GotoLabels}.
6529
6530@subsubheading Remarks
6531The @code{asm} statement allows you to include assembly instructions directly
6532within C code. This may help you to maximize performance in time-sensitive
6533code or to access assembly instructions that are not readily available to C
6534programs.
6535
6536Note that Extended @code{asm} statements must be inside a function. Only
6537Basic @code{asm} may be outside functions (@pxref{Basic Asm}).
3a96c7cc
DW
6538Functions declared with the @code{naked} attribute also require Basic
6539@code{asm} (@pxref{Function Attributes}).
04e137a1
DW
6540
6541While the uses of @code{asm} are many and varied, it may help to think of an
6542@code{asm} statement as a series of low-level instructions that convert input
6543parameters to output parameters. So a simple (if not particularly useful)
6544example for i386 using @code{asm} might look like this:
6545
6546@example
6547int src = 1;
6548int dst;
6549
6550asm ("mov %1, %0\n\t"
6551 "add $1, %0"
6552 : "=r" (dst)
6553 : "r" (src));
6554
6555printf("%d\n", dst);
6556@end example
6557
6558This code will copy @var{src} to @var{dst} and add 1 to @var{dst}.
6559
6560@anchor{Volatile}
6561@subsubsection Volatile
6562@cindex volatile @code{asm}
6563@cindex @code{asm} volatile
6564
6565GCC's optimizers sometimes discard @code{asm} statements if they determine
6566there is no need for the output variables. Also, the optimizers may move
6567code out of loops if they believe that the code will always return the same
6568result (i.e. none of its input values change between calls). Using the
6569@code{volatile} qualifier disables these optimizations. @code{asm} statements
6570that have no output operands are implicitly volatile.
6571
6572Examples:
6573
6574This i386 code demonstrates a case that does not use (or require) the
6575@code{volatile} qualifier. If it is performing assertion checking, this code
6576uses @code{asm} to perform the validation. Otherwise, @var{dwRes} is
6577unreferenced by any code. As a result, the optimizers can discard the
6578@code{asm} statement, which in turn removes the need for the entire
6579@code{DoCheck} routine. By omitting the @code{volatile} qualifier when it
6580isn't needed you allow the optimizers to produce the most efficient code
6581possible.
6582
6583@example
6584void DoCheck(uint32_t dwSomeValue)
6585@{
6586 uint32_t dwRes;
c85f7c16 6587
04e137a1
DW
6588 // Assumes dwSomeValue is not zero.
6589 asm ("bsfl %1,%0"
6590 : "=r" (dwRes)
6591 : "r" (dwSomeValue)
6592 : "cc");
c1f7febf 6593
04e137a1
DW
6594 assert(dwRes > 3);
6595@}
6596@end example
bbf5a54d 6597
04e137a1
DW
6598The next example shows a case where the optimizers can recognize that the input
6599(@var{dwSomeValue}) never changes during the execution of the function and can
6600therefore move the @code{asm} outside the loop to produce more efficient code.
6601Again, using @code{volatile} disables this type of optimization.
bbf5a54d 6602
04e137a1
DW
6603@example
6604void do_print(uint32_t dwSomeValue)
bbf5a54d 6605@{
04e137a1
DW
6606 uint32_t dwRes;
6607
6608 for (uint32_t x=0; x < 5; x++)
6609 @{
6610 // Assumes dwSomeValue is not zero.
6611 asm ("bsfl %1,%0"
6612 : "=r" (dwRes)
6613 : "r" (dwSomeValue)
6614 : "cc");
6615
6616 printf("%u: %u %u\n", x, dwSomeValue, dwRes);
6617 @}
bbf5a54d 6618@}
04e137a1
DW
6619@end example
6620
6621The following example demonstrates a case where you need to use the
6622@code{volatile} qualifier. It uses the i386 RDTSC instruction, which reads
6623the computer's time-stamp counter. Without the @code{volatile} qualifier,
6624the optimizers might assume that the @code{asm} block will always return the
6625same value and therefore optimize away the second call.
6626
6627@example
6628uint64_t msr;
6629
6630asm volatile ( "rdtsc\n\t" // Returns the time in EDX:EAX.
6631 "shl $32, %%rdx\n\t" // Shift the upper bits left.
6632 "or %%rdx, %0" // 'Or' in the lower bits.
6633 : "=a" (msr)
6634 :
6635 : "rdx");
6636
6637printf("msr: %llx\n", msr);
6638
6639// Do other work...
6640
6641// Reprint the timestamp
6642asm volatile ( "rdtsc\n\t" // Returns the time in EDX:EAX.
6643 "shl $32, %%rdx\n\t" // Shift the upper bits left.
6644 "or %%rdx, %0" // 'Or' in the lower bits.
6645 : "=a" (msr)
6646 :
6647 : "rdx");
6648
6649printf("msr: %llx\n", msr);
6650@end example
6651
6652GCC's optimizers will not treat this code like the non-volatile code in the
6653earlier examples. They do not move it out of loops or omit it on the
6654assumption that the result from a previous call is still valid.
6655
6656Note that the compiler can move even volatile @code{asm} instructions relative
6657to other code, including across jump instructions. For example, on many
6658targets there is a system register that controls the rounding mode of
6659floating-point operations. Setting it with a volatile @code{asm}, as in the
6660following PowerPC example, will not work reliably.
6661
6662@example
6663asm volatile("mtfsf 255, %0" : : "f" (fpenv));
6664sum = x + y;
6665@end example
6666
6667The compiler may move the addition back before the volatile @code{asm}. To
6668make it work as expected, add an artificial dependency to the @code{asm} by
6669referencing a variable in the subsequent code, for example:
6670
6671@example
6672asm volatile ("mtfsf 255,%1" : "=X" (sum) : "f" (fpenv));
6673sum = x + y;
6674@end example
6675
6676Under certain circumstances, GCC may duplicate (or remove duplicates of) your
6677assembly code when optimizing. This can lead to unexpected duplicate symbol
6678errors during compilation if your asm code defines symbols or labels. Using %=
6679(@pxref{AssemblerTemplate}) may help resolve this problem.
6680
6681@anchor{AssemblerTemplate}
6682@subsubsection Assembler Template
6683@cindex @code{asm} assembler template
6684
6685An assembler template is a literal string containing assembler instructions.
6686The compiler will replace any references to inputs, outputs, and goto labels
6687in the template, and then output the resulting string to the assembler. The
6688string can contain any instructions recognized by the assembler, including
6689directives. GCC does not parse the assembler instructions
6690themselves and does not know what they mean or even whether they are valid
6691assembler input. However, it does count the statements
6692(@pxref{Size of an asm}).
6693
6694You may place multiple assembler instructions together in a single @code{asm}
6695string, separated by the characters normally used in assembly code for the
6696system. A combination that works in most places is a newline to break the
6697line, plus a tab character to move to the instruction field (written as
6698"\n\t"). Some assemblers allow semicolons as a line separator. However, note
6699that some assembler dialects use semicolons to start a comment.
6700
6701Do not expect a sequence of @code{asm} statements to remain perfectly
6702consecutive after compilation, even when you are using the @code{volatile}
6703qualifier. If certain instructions need to remain consecutive in the output,
6704put them in a single multi-instruction asm statement.
6705
6706Accessing data from C programs without using input/output operands (such as
6707by using global symbols directly from the assembler template) may not work as
6708expected. Similarly, calling functions directly from an assembler template
6709requires a detailed understanding of the target assembler and ABI.
6710
6711Since GCC does not parse the AssemblerTemplate, it has no visibility of any
6712symbols it references. This may result in GCC discarding those symbols as
6713unreferenced unless they are also listed as input, output, or goto operands.
6714
6715GCC can support multiple assembler dialects (for example, GCC for i386
6716supports "att" and "intel" dialects) for inline assembler. In builds that
6717support this capability, the @option{-masm} option controls which dialect
6718GCC uses as its default. The hardware-specific documentation for the
6719@option{-masm} option contains the list of supported dialects, as well as the
6720default dialect if the option is not specified. This information may be
6721important to understand, since assembler code that works correctly when
6722compiled using one dialect will likely fail if compiled using another.
6723
6724@subsubheading Using braces in @code{asm} templates
6725
6726If your code needs to support multiple assembler dialects (for example, if
6727you are writing public headers that need to support a variety of compilation
6728options), use constructs of this form:
6729
6730@example
6731@{ dialect0 | dialect1 | dialect2... @}
6732@end example
6733
6734This construct outputs 'dialect0' when using dialect #0 to compile the code,
6735'dialect1' for dialect #1, etc. If there are fewer alternatives within the
6736braces than the number of dialects the compiler supports, the construct
6737outputs nothing.
6738
6739For example, if an i386 compiler supports two dialects (att, intel), an
6740assembler template such as this:
6741
6742@example
6743"bt@{l %[Offset],%[Base] | %[Base],%[Offset]@}; jc %l2"
6744@end example
6745
6746would produce the output:
6747
6748@example
6749For att: "btl %[Offset],%[Base] ; jc %l2"
6750For intel: "bt %[Base],%[Offset]; jc %l2"
6751@end example
6752
6753Using that same compiler, this code:
6754
6755@example
6756"xchg@{l@}\t@{%%@}ebx, %1"
6757@end example
6758
6759would produce
6760
6761@example
6762For att: "xchgl\t%%ebx, %1"
6763For intel: "xchg\tebx, %1"
6764@end example
6765
6766There is no support for nesting dialect alternatives. Also, there is no
6767``escape'' for an open brace (@{), so do not use open braces in an Extended
6768@code{asm} template other than as a dialect indicator.
6769
6770@subsubheading Other format strings
6771
6772In addition to the tokens described by the input, output, and goto operands,
6773there are a few special cases:
c1f7febf 6774
04e137a1
DW
6775@itemize
6776@item
6777"%%" outputs a single "%" into the assembler code.
2f59e40e 6778
04e137a1
DW
6779@item
6780"%=" outputs a number that is unique to each instance of the @code{asm}
6781statement in the entire compilation. This option is useful when creating local
6782labels and referring to them multiple times in a single template that
6783generates multiple assembler instructions.
2f59e40e 6784
04e137a1 6785@end itemize
2f59e40e 6786
04e137a1
DW
6787@anchor{OutputOperands}
6788@subsubsection Output Operands
6789@cindex @code{asm} output operands
6790
6791An @code{asm} statement has zero or more output operands indicating the names
6792of C variables modified by the assembler code.
6793
6794In this i386 example, @var{old} (referred to in the template string as
6795@code{%0}) and @var{*Base} (as @code{%1}) are outputs and @var{Offset}
6796(@code{%2}) is an input:
6797
6798@example
6799bool old;
6800
6801__asm__ ("btsl %2,%1\n\t" // Turn on zero-based bit #Offset in Base.
6802 "sbb %0,%0" // Use the CF to calculate old.
6803 : "=r" (old), "+rm" (*Base)
6804 : "Ir" (Offset)
6805 : "cc");
6806
6807return old;
6808@end example
6809
6810Operands use this format:
6811
6812@example
6813[ [asmSymbolicName] ] "constraint" (cvariablename)
6814@end example
6815
6816@emph{asmSymbolicName}
6817@*
6818
6819When not using asmSymbolicNames, use the (zero-based) position of the operand
6820in the list of operands in the assembler template. For example if there are
6821three output operands, use @code{%0} in the template to refer to the first,
6822@code{%1} for the second, and @code{%2} for the third. When using an
6823asmSymbolicName, reference it by enclosing the name in square brackets
6824(i.e. @code{%[Value]}). The scope of the name is the @code{asm} statement
6825that contains the definition. Any valid C variable name is acceptable,
6826including names already defined in the surrounding code. No two operands
6827within the same @code{asm} statement can use the same symbolic name.
6828
6829@emph{constraint}
6830@*
6831Output constraints must begin with either @code{"="} (a variable overwriting an
6832existing value) or @code{"+"} (when reading and writing). When using
6833@code{"="}, do not assume the location will contain the existing value (except
6834when tying the variable to an input; @pxref{InputOperands,,Input Operands}).
6835
6836After the prefix, there must be one or more additional constraints
6837(@pxref{Constraints}) that describe where the value resides. Common
6838constraints include @code{"r"} for register and @code{"m"} for memory.
6839When you list more than one possible location (for example @code{"=rm"}), the
6840compiler chooses the most efficient one based on the current context. If you
6841list as many alternates as the @code{asm} statement allows, you will permit
6842the optimizers to produce the best possible code. If you must use a specific
6843register, but your Machine Constraints do not provide sufficient
6844control to select the specific register you want, Local Reg Vars may provide
6845a solution (@pxref{Local Reg Vars}).
6846
6847@emph{cvariablename}
6848@*
6849Specifies the C variable name of the output (enclosed by parentheses). Accepts
6850any (non-constant) variable within scope.
6851
6852Remarks:
6853
6854The total number of input + output + goto operands has a limit of 30. Commas
6855separate the operands. When the compiler selects the registers to use to
6856represent the output operands, it will not use any of the clobbered registers
6857(@pxref{Clobbers}).
6858
6859Output operand expressions must be lvalues. The compiler cannot check whether
6860the operands have data types that are reasonable for the instruction being
6861executed. For output expressions that are not directly addressable (for
6862example a bit-field), the constraint must allow a register. In that case, GCC
6863uses the register as the output of the @code{asm}, and then stores that
6864register into the output.
6865
6866Unless an output operand has the '@code{&}' constraint modifier
6867(@pxref{Modifiers}), GCC may allocate it in the same register as an unrelated
6868input operand, on the assumption that the assembler code will consume its
6869inputs before producing outputs. This assumption may be false if the assembler
6870code actually consists of more than one instruction. In this case, use
6871'@code{&}' on each output operand that must not overlap an input.
6872
6873The same problem can occur if one output parameter (@var{a}) allows a register
6874constraint and another output parameter (@var{b}) allows a memory constraint.
6875The code generated by GCC to access the memory address in @var{b} can contain
6876registers which @emph{might} be shared by @var{a}, and GCC considers those
6877registers to be inputs to the asm. As above, GCC assumes that such input
6878registers are consumed before any outputs are written. This assumption may
6879result in incorrect behavior if the asm writes to @var{a} before using
6880@var{b}. Combining the `@code{&}' constraint with the register constraint
6881ensures that modifying @var{a} will not affect what address is referenced by
6882@var{b}. Omitting the `@code{&}' constraint means that the location of @var{b}
6883will be undefined if @var{a} is modified before using @var{b}.
6884
6885@code{asm} supports operand modifiers on operands (for example @code{%k2}
6886instead of simply @code{%2}). Typically these qualifiers are hardware
6887dependent. The list of supported modifiers for i386 is found at
6888@ref{i386Operandmodifiers,i386 Operand modifiers}.
6889
6890If the C code that follows the @code{asm} makes no use of any of the output
6891operands, use @code{volatile} for the @code{asm} statement to prevent the
6892optimizers from discarding the @code{asm} statement as unneeded
6893(see @ref{Volatile}).
6894
6895Examples:
6896
6897This code makes no use of the optional asmSymbolicName. Therefore it
6898references the first output operand as @code{%0} (were there a second, it
6899would be @code{%1}, etc). The number of the first input operand is one greater
6900than that of the last output operand. In this i386 example, that makes
6901@var{Mask} @code{%1}:
6902
6903@example
6904uint32_t Mask = 1234;
6905uint32_t Index;
6906
6907 asm ("bsfl %1, %0"
6908 : "=r" (Index)
6909 : "r" (Mask)
6910 : "cc");
6911@end example
6912
6913That code overwrites the variable Index ("="), placing the value in a register
6914("r"). The generic "r" constraint instead of a constraint for a specific
6915register allows the compiler to pick the register to use, which can result
6916in more efficient code. This may not be possible if an assembler instruction
6917requires a specific register.
6918
6919The following i386 example uses the asmSymbolicName operand. It produces the
6920same result as the code above, but some may consider it more readable or more
6921maintainable since reordering index numbers is not necessary when adding or
6922removing operands. The names aIndex and aMask are only used to emphasize which
6923names get used where. It is acceptable to reuse the names Index and Mask.
6924
6925@example
6926uint32_t Mask = 1234;
6927uint32_t Index;
6928
6929 asm ("bsfl %[aMask], %[aIndex]"
6930 : [aIndex] "=r" (Index)
6931 : [aMask] "r" (Mask)
6932 : "cc");
6933@end example
6934
6935Here are some more examples of output operands.
6936
6937@example
6938uint32_t c = 1;
6939uint32_t d;
6940uint32_t *e = &c;
6941
6942asm ("mov %[e], %[d]"
6943 : [d] "=rm" (d)
6944 : [e] "rm" (*e));
6945@end example
6946
6947Here, @var{d} may either be in a register or in memory. Since the compiler
6948might already have the current value of the uint32_t pointed to by @var{e}
6949in a register, you can enable it to choose the best location
6950for @var{d} by specifying both constraints.
6951
6952@anchor{InputOperands}
6953@subsubsection Input Operands
6954@cindex @code{asm} input operands
6955@cindex @code{asm} expressions
c1f7febf 6956
04e137a1
DW
6957Input operands make inputs from C variables and expressions available to the
6958assembly code.
6959
6960Specify input operands by using the format:
6961
6962@example
6963[ [asmSymbolicName] ] "constraint" (cexpression)
6964@end example
6965
6966@emph{asmSymbolicName}
6967@*
6968When not using asmSymbolicNames, use the (zero-based) position of the operand
6969in the list of operands, including outputs, in the assembler template. For
6970example, if there are two output parameters and three inputs, @code{%2} refers
6971to the first input, @code{%3} to the second, and @code{%4} to the third.
6972When using an asmSymbolicName, reference it by enclosing the name in square
6973brackets (e.g. @code{%[Value]}). The scope of the name is the @code{asm}
6974statement that contains the definition. Any valid C variable name is
6975acceptable, including names already defined in the surrounding code. No two
6976operands within the same @code{asm} statement can use the same symbolic name.
6977
6978@emph{constraint}
6979@*
6980Input constraints must be a string containing one or more constraints
6981(@pxref{Constraints}). When you give more than one possible constraint
6982(for example, @code{"irm"}), the compiler will choose the most efficient
6983method based on the current context. Input constraints may not begin with
6984either "=" or "+". If you must use a specific register, but your Machine
6985Constraints do not provide sufficient control to select the specific
6986register you want, Local Reg Vars may provide a solution
6987(@pxref{Local Reg Vars}).
6988
6989Input constraints can also be digits (for example, @code{"0"}). This indicates
6990that the specified input will be in the same place as the output constraint
6991at the (zero-based) index in the output constraint list. When using
6992asmSymbolicNames for the output operands, you may use these names (enclosed
6993in brackets []) instead of digits.
6994
6995@emph{cexpression}
6996@*
6997This is the C variable or expression being passed to the @code{asm} statement
6998as input.
6999
7000When the compiler selects the registers to use to represent the input
7001operands, it will not use any of the clobbered registers (@pxref{Clobbers}).
7002
7003If there are no output operands but there are input operands, place two
7004consecutive colons where the output operands would go:
7005
7006@example
7007__asm__ ("some instructions"
7008 : /* No outputs. */
7009 : "r" (Offset / 8);
7010@end example
7011
7012@strong{Warning:} Do @emph{not} modify the contents of input-only operands
7013(except for inputs tied to outputs). The compiler assumes that on exit from
7014the @code{asm} statement these operands will contain the same values as they
7015had before executing the assembler. It is @emph{not} possible to use Clobbers
7016to inform the compiler that the values in these inputs are changing. One
7017common work-around is to tie the changing input variable to an output variable
7018that never gets used. Note, however, that if the code that follows the
7019@code{asm} statement makes no use of any of the output operands, the GCC
7020optimizers may discard the @code{asm} statement as unneeded
7021(see @ref{Volatile}).
7022
7023Remarks:
7024
7025The total number of input + output + goto operands has a limit of 30.
7026
7027@code{asm} supports operand modifiers on operands (for example @code{%k2}
7028instead of simply @code{%2}). Typically these qualifiers are hardware
7029dependent. The list of supported modifiers for i386 is found at
7030@ref{i386Operandmodifiers,i386 Operand modifiers}.
7031
7032Examples:
7033
7034In this example using the fictitious @code{combine} instruction, the
7035constraint @code{"0"} for input operand 1 says that it must occupy the same
7036location as output operand 0. Only input operands may use numbers in
7037constraints, and they must each refer to an output operand. Only a number (or
7038the symbolic assembler name) in the constraint can guarantee that one operand
7039is in the same place as another. The mere fact that @var{foo} is the value of
7040both operands is not enough to guarantee that they are in the same place in
7041the generated assembler code.
7042
7043@example
7044asm ("combine %2, %0"
7045 : "=r" (foo)
7046 : "0" (foo), "g" (bar));
7047@end example
7048
7049Here is an example using symbolic names.
7050
7051@example
7052asm ("cmoveq %1, %2, %[result]"
7053 : [result] "=r"(result)
7054 : "r" (test), "r" (new), "[result]" (old));
7055@end example
7056
7057@anchor{Clobbers}
7058@subsubsection Clobbers
7059@cindex @code{asm} clobbers
7060
7061While the compiler is aware of changes to entries listed in the output
7062operands, the assembler code may modify more than just the outputs. For
7063example, calculations may require additional registers, or the processor may
7064overwrite a register as a side effect of a particular assembler instruction.
7065In order to inform the compiler of these changes, list them in the clobber
7066list. Clobber list items are either register names or the special clobbers
7067(listed below). Each clobber list item is enclosed in double quotes and
7068separated by commas.
7069
7070Clobber descriptions may not in any way overlap with an input or output
7071operand. For example, you may not have an operand describing a register class
7072with one member when listing that register in the clobber list. Variables
7073declared to live in specific registers (@pxref{Explicit Reg Vars}), and used
7074as @code{asm} input or output operands, must have no part mentioned in the
7075clobber description. In particular, there is no way to specify that input
7076operands get modified without also specifying them as output operands.
7077
7078When the compiler selects which registers to use to represent input and output
7079operands, it will not use any of the clobbered registers. As a result,
7080clobbered registers are available for any use in the assembler code.
7081
7082Here is a realistic example for the VAX showing the use of clobbered
7083registers:
7084
7085@example
7086asm volatile ("movc3 %0, %1, %2"
7087 : /* No outputs. */
7088 : "g" (from), "g" (to), "g" (count)
7089 : "r0", "r1", "r2", "r3", "r4", "r5");
7090@end example
7091
7092Also, there are two special clobber arguments:
c1f7febf 7093
04e137a1
DW
7094@enumerate
7095@item
7096The @code{"cc"} clobber indicates that the assembler code modifies the flags
7097register. On some machines, GCC represents the condition codes as a specific
7098hardware register; "cc" serves to name this register. On other machines,
7099condition code handling is different, and specifying "cc" has no effect. But
7100it is valid no matter what the machine.
eda3fbbe 7101
04e137a1
DW
7102@item
7103The "memory" clobber tells the compiler that the assembly code performs memory
7104reads or writes to items other than those listed in the input and output
7105operands (for example accessing the memory pointed to by one of the input
7106parameters). To ensure memory contains correct values, GCC may need to flush
7107specific register values to memory before executing the @code{asm}. Further,
7108the compiler will not assume that any values read from memory before an
7109@code{asm} will remain unchanged after that @code{asm}; it will reload them as
7110needed. This effectively forms a read/write memory barrier for the compiler.
7111
7112Note that this clobber does not prevent the @emph{processor} from doing
7113speculative reads past the @code{asm} statement. To prevent that, you need
7114processor-specific fence instructions.
7115
7116Flushing registers to memory has performance implications and may be an issue
7117for time-sensitive code. One trick to avoid this is available if the size of
7118the memory being accessed is known at compile time. For example, if accessing
7119ten bytes of a string, use a memory input like:
7120
7121@code{@{"m"( (@{ struct @{ char x[10]; @} *p = (void *)ptr ; *p; @}) )@}}.
1c384bf1 7122
04e137a1 7123@end enumerate
1c384bf1 7124
04e137a1
DW
7125@anchor{GotoLabels}
7126@subsubsection Goto Labels
7127@cindex @code{asm} goto labels
7128
7129@code{asm goto} allows assembly code to jump to one or more C labels. The
7130GotoLabels section in an @code{asm goto} statement contains a comma-separated
7131list of all C labels to which the assembler code may jump. GCC assumes that
7132@code{asm} execution falls through to the next statement (if this is not the
7133case, consider using the @code{__builtin_unreachable} intrinsic after the
883755a1
DW
7134@code{asm} statement). Optimization of @code{asm goto} may be improved by
7135using the @code{hot} and @code{cold} label attributes (@pxref{Label
7136Attributes}). The total number of input + output + goto operands has
04e137a1
DW
7137a limit of 30.
7138
7139An @code{asm goto} statement can not have outputs (which means that the
7140statement is implicitly volatile). This is due to an internal restriction of
7141the compiler: control transfer instructions cannot have outputs. If the
7142assembler code does modify anything, use the "memory" clobber to force the
7143optimizers to flush all register values to memory, and reload them if
7144necessary, after the @code{asm} statement.
7145
7146To reference a label, prefix it with @code{%l} (that's a lowercase L) followed
7147by its (zero-based) position in GotoLabels plus the number of input
7148arguments. For example, if the @code{asm} has three inputs and references two
7149labels, refer to the first label as @code{%l3} and the second as @code{%l4}).
7150
7151@code{asm} statements may not perform jumps into other @code{asm} statements.
7152GCC's optimizers do not know about these jumps; therefore they cannot take
7153account of them when deciding how to optimize.
7154
7155Example code for i386 might look like:
7156
7157@example
7158asm goto (
7159 "btl %1, %0\n\t"
7160 "jc %l2"
7161 : /* No outputs. */
7162 : "r" (p1), "r" (p2)
7163 : "cc"
7164 : carry);
7165
7166return 0;
7167
7168carry:
7169return 1;
7170@end example
7171
7172The following example shows an @code{asm goto} that uses the memory clobber.
7173
7174@example
1c384bf1
RH
7175int frob(int x)
7176@{
7177 int y;
7178 asm goto ("frob %%r5, %1; jc %l[error]; mov (%2), %%r5"
04e137a1
DW
7179 : /* No outputs. */
7180 : "r"(x), "r"(&y)
7181 : "r5", "memory"
7182 : error);
1c384bf1 7183 return y;
04e137a1 7184error:
1c384bf1
RH
7185 return -1;
7186@}
04e137a1 7187@end example
1c384bf1 7188
04e137a1
DW
7189@anchor{i386Operandmodifiers}
7190@subsubsection i386 Operand modifiers
1c384bf1 7191
04e137a1
DW
7192Input, output, and goto operands for extended @code{asm} statements can use
7193modifiers to affect the code output to the assembler. For example, the
7194following code uses the "h" and "b" modifiers for i386:
1c384bf1 7195
04e137a1
DW
7196@example
7197uint16_t num;
7198asm volatile ("xchg %h0, %b0" : "+a" (num) );
7199@end example
1c384bf1 7200
04e137a1 7201These modifiers generate this assembler code:
c1f7febf 7202
04e137a1
DW
7203@example
7204xchg %ah, %al
7205@end example
ece7fc1c 7206
04e137a1 7207The rest of this discussion uses the following code for illustrative purposes.
ece7fc1c 7208
04e137a1
DW
7209@example
7210int main()
7211@{
7212 int iInt = 1;
7213
7214top:
7215
7216 asm volatile goto ("some assembler instructions here"
7217 : /* No outputs. */
7218 : "q" (iInt), "X" (sizeof(unsigned char) + 1)
7219 : /* No clobbers. */
7220 : top);
7221@}
7222@end example
7223
7224With no modifiers, this is what the output from the operands would be for the
7225att and intel dialects of assembler:
7226
7227@multitable {Operand} {masm=att} {OFFSET FLAT:.L2}
7228@headitem Operand @tab masm=att @tab masm=intel
7229@item @code{%0}
7230@tab @code{%eax}
7231@tab @code{eax}
7232@item @code{%1}
7233@tab @code{$2}
7234@tab @code{2}
7235@item @code{%2}
7236@tab @code{$.L2}
7237@tab @code{OFFSET FLAT:.L2}
7238@end multitable
7239
7240The table below shows the list of supported modifiers and their effects.
7241
7242@multitable {Modifier} {Print the opcode suffix for the size of th} {Operand} {masm=att} {masm=intel}
7243@headitem Modifier @tab Description @tab Operand @tab @option{masm=att} @tab @option{masm=intel}
7244@item @code{z}
7245@tab Print the opcode suffix for the size of the current integer operand (one of @code{b}/@code{w}/@code{l}/@code{q}).
7246@tab @code{%z0}
7247@tab @code{l}
7248@tab
7249@item @code{b}
7250@tab Print the QImode name of the register.
7251@tab @code{%b0}
7252@tab @code{%al}
7253@tab @code{al}
7254@item @code{h}
7255@tab Print the QImode name for a ``high'' register.
7256@tab @code{%h0}
7257@tab @code{%ah}
7258@tab @code{ah}
7259@item @code{w}
7260@tab Print the HImode name of the register.
7261@tab @code{%w0}
7262@tab @code{%ax}
7263@tab @code{ax}
7264@item @code{k}
7265@tab Print the SImode name of the register.
7266@tab @code{%k0}
7267@tab @code{%eax}
7268@tab @code{eax}
7269@item @code{q}
7270@tab Print the DImode name of the register.
7271@tab @code{%q0}
7272@tab @code{%rax}
7273@tab @code{rax}
7274@item @code{l}
7275@tab Print the label name with no punctuation.
7276@tab @code{%l2}
7277@tab @code{.L2}
7278@tab @code{.L2}
7279@item @code{c}
7280@tab Require a constant operand and print the constant expression with no punctuation.
7281@tab @code{%c1}
7282@tab @code{2}
7283@tab @code{2}
7284@end multitable
7285
7286@anchor{i386floatingpointasmoperands}
7287@subsubsection i386 floating-point asm operands
fe0ce426 7288
bafa88c2
SL
7289On i386 targets, there are several rules on the usage of stack-like registers
7290in the operands of an @code{asm}. These rules apply only to the operands
7291that are stack-like registers:
fe0ce426
JH
7292
7293@enumerate
7294@item
bafa88c2
SL
7295Given a set of input registers that die in an @code{asm}, it is
7296necessary to know which are implicitly popped by the @code{asm}, and
566fb011 7297which must be explicitly popped by GCC@.
fe0ce426 7298
bafa88c2 7299An input register that is implicitly popped by the @code{asm} must be
fe0ce426
JH
7300explicitly clobbered, unless it is constrained to match an
7301output operand.
7302
7303@item
bafa88c2 7304For any input register that is implicitly popped by an @code{asm}, it is
fe0ce426
JH
7305necessary to know how to adjust the stack to compensate for the pop.
7306If any non-popped input is closer to the top of the reg-stack than
bafa88c2 7307the implicitly popped register, it would not be possible to know what the
84330467 7308stack looked like---it's not clear how the rest of the stack ``slides
fe0ce426
JH
7309up''.
7310
bafa88c2 7311All implicitly popped input registers must be closer to the top of
fe0ce426
JH
7312the reg-stack than any input that is not implicitly popped.
7313
bafa88c2
SL
7314It is possible that if an input dies in an @code{asm}, the compiler might
7315use the input register for an output reload. Consider this example:
fe0ce426 7316
3ab51846 7317@smallexample
fe0ce426 7318asm ("foo" : "=t" (a) : "f" (b));
3ab51846 7319@end smallexample
fe0ce426 7320
c513ecbf 7321@noindent
bafa88c2
SL
7322This code says that input @code{b} is not popped by the @code{asm}, and that
7323the @code{asm} pushes a result onto the reg-stack, i.e., the stack is one
7324deeper after the @code{asm} than it was before. But, it is possible that
7325reload may think that it can use the same register for both the input and
7326the output.
fe0ce426 7327
bafa88c2
SL
7328To prevent this from happening,
7329if any input operand uses the @code{f} constraint, all output register
7330constraints must use the @code{&} early-clobber modifier.
fe0ce426 7331
bafa88c2 7332The example above would be correctly written as:
fe0ce426 7333
3ab51846 7334@smallexample
fe0ce426 7335asm ("foo" : "=&t" (a) : "f" (b));
3ab51846 7336@end smallexample
fe0ce426
JH
7337
7338@item
7339Some operands need to be in particular places on the stack. All
bafa88c2
SL
7340output operands fall in this category---GCC has no other way to
7341know which registers the outputs appear in unless you indicate
fe0ce426
JH
7342this in the constraints.
7343
bafa88c2
SL
7344Output operands must specifically indicate which register an output
7345appears in after an @code{asm}. @code{=f} is not allowed: the operand
7346constraints must select a class with a single register.
fe0ce426
JH
7347
7348@item
bafa88c2 7349Output operands may not be ``inserted'' between existing stack registers.
fe0ce426 7350Since no 387 opcode uses a read/write operand, all output operands
bafa88c2 7351are dead before the @code{asm}, and are pushed by the @code{asm}.
fe0ce426
JH
7352It makes no sense to push anywhere but the top of the reg-stack.
7353
7354Output operands must start at the top of the reg-stack: output
bafa88c2 7355operands may not ``skip'' a register.
fe0ce426
JH
7356
7357@item
bafa88c2 7358Some @code{asm} statements may need extra stack space for internal
fe0ce426
JH
7359calculations. This can be guaranteed by clobbering stack registers
7360unrelated to the inputs and outputs.
7361
7362@end enumerate
7363
bafa88c2
SL
7364Here are a couple of reasonable @code{asm}s to want to write. This
7365@code{asm}
fe0ce426
JH
7366takes one input, which is internally popped, and produces two outputs.
7367
3ab51846 7368@smallexample
fe0ce426 7369asm ("fsincos" : "=t" (cos), "=u" (sin) : "0" (inp));
3ab51846 7370@end smallexample
fe0ce426 7371
c513ecbf 7372@noindent
bafa88c2
SL
7373This @code{asm} takes two inputs, which are popped by the @code{fyl2xp1} opcode,
7374and replaces them with one output. The @code{st(1)} clobber is necessary
7375for the compiler to know that @code{fyl2xp1} pops both inputs.
fe0ce426 7376
3ab51846 7377@smallexample
fe0ce426 7378asm ("fyl2xp1" : "=t" (result) : "0" (x), "u" (y) : "st(1)");
3ab51846 7379@end smallexample
fe0ce426 7380
04e137a1 7381@lowersections
c1f7febf 7382@include md.texi
04e137a1
DW
7383@raisesections
7384
c1f7febf 7385@node Asm Labels
04e137a1 7386@subsection Controlling Names Used in Assembler Code
c1f7febf
RK
7387@cindex assembler names for identifiers
7388@cindex names used in assembler code
7389@cindex identifiers, names in assembler code
7390
7391You can specify the name to be used in the assembler code for a C
7392function or variable by writing the @code{asm} (or @code{__asm__})
7393keyword after the declarator as follows:
7394
3ab51846 7395@smallexample
c1f7febf 7396int foo asm ("myfoo") = 2;
3ab51846 7397@end smallexample
c1f7febf
RK
7398
7399@noindent
7400This specifies that the name to be used for the variable @code{foo} in
7401the assembler code should be @samp{myfoo} rather than the usual
7402@samp{_foo}.
7403
7404On systems where an underscore is normally prepended to the name of a C
7405function or variable, this feature allows you to define names for the
7406linker that do not start with an underscore.
7407
0adc3c19
MM
7408It does not make sense to use this feature with a non-static local
7409variable since such variables do not have assembler names. If you are
7410trying to put the variable in a particular register, see @ref{Explicit
7411Reg Vars}. GCC presently accepts such code with a warning, but will
7412probably be changed to issue an error, rather than a warning, in the
7413future.
7414
c1f7febf
RK
7415You cannot use @code{asm} in this way in a function @emph{definition}; but
7416you can get the same effect by writing a declaration for the function
7417before its definition and putting @code{asm} there, like this:
7418
3ab51846 7419@smallexample
c1f7febf
RK
7420extern func () asm ("FUNC");
7421
7422func (x, y)
7423 int x, y;
0d893a63 7424/* @r{@dots{}} */
3ab51846 7425@end smallexample
c1f7febf
RK
7426
7427It is up to you to make sure that the assembler names you choose do not
7428conflict with any other assembler symbols. Also, you must not use a
f0523f02
JM
7429register name; that would produce completely invalid assembler code. GCC
7430does not as yet have the ability to store static variables in registers.
c1f7febf
RK
7431Perhaps that will be added.
7432
7433@node Explicit Reg Vars
04e137a1 7434@subsection Variables in Specified Registers
c1f7febf
RK
7435@cindex explicit register variables
7436@cindex variables in specified registers
7437@cindex specified registers
7438@cindex registers, global allocation
7439
7440GNU C allows you to put a few global variables into specified hardware
7441registers. You can also specify the register in which an ordinary
7442register variable should be allocated.
7443
7444@itemize @bullet
7445@item
7446Global register variables reserve registers throughout the program.
7447This may be useful in programs such as programming language
c417597c 7448interpreters that have a couple of global variables that are accessed
c1f7febf
RK
7449very often.
7450
7451@item
7452Local register variables in specific registers do not reserve the
805c33df
HPN
7453registers, except at the point where they are used as input or output
7454operands in an @code{asm} statement and the @code{asm} statement itself is
7455not deleted. The compiler's data flow analysis is capable of determining
c1f7febf 7456where the specified registers contain live values, and where they are
8d344fbc 7457available for other uses. Stores into local register variables may be deleted
0deaf590
JL
7458when they appear to be dead according to dataflow analysis. References
7459to local register variables may be deleted or moved or simplified.
c1f7febf
RK
7460
7461These local variables are sometimes convenient for use with the extended
7462@code{asm} feature (@pxref{Extended Asm}), if you want to write one
7463output of the assembler instruction directly into a particular register.
358a3dbc 7464(This works provided the register you specify fits the constraints
c1f7febf
RK
7465specified for that operand in the @code{asm}.)
7466@end itemize
7467
7468@menu
7469* Global Reg Vars::
7470* Local Reg Vars::
7471@end menu
7472
7473@node Global Reg Vars
04e137a1 7474@subsubsection Defining Global Register Variables
c1f7febf
RK
7475@cindex global register variables
7476@cindex registers, global variables in
7477
7478You can define a global register variable in GNU C like this:
7479
3ab51846 7480@smallexample
c1f7febf 7481register int *foo asm ("a5");
3ab51846 7482@end smallexample
c1f7febf
RK
7483
7484@noindent
c417597c
SL
7485Here @code{a5} is the name of the register that should be used. Choose a
7486register that is normally saved and restored by function calls on your
c1f7febf
RK
7487machine, so that library routines will not clobber it.
7488
358a3dbc 7489Naturally the register name is cpu-dependent, so you need to
c1f7febf 7490conditionalize your program according to cpu type. The register
358a3dbc 7491@code{a5} is a good choice on a 68000 for a variable of pointer
c1f7febf
RK
7492type. On machines with register windows, be sure to choose a ``global''
7493register that is not affected magically by the function call mechanism.
7494
bafa88c2 7495In addition, different operating systems on the same CPU may differ in how they
358a3dbc 7496name the registers; then you need additional conditionals. For
c1f7febf
RK
7497example, some 68000 operating systems call this register @code{%a5}.
7498
7499Eventually there may be a way of asking the compiler to choose a register
7500automatically, but first we need to figure out how it should choose and
7501how to enable you to guide the choice. No solution is evident.
7502
7503Defining a global register variable in a certain register reserves that
7504register entirely for this use, at least within the current compilation.
358a3dbc
SL
7505The register is not allocated for any other purpose in the functions
7506in the current compilation, and is not saved and restored by
c1f7febf 7507these functions. Stores into this register are never deleted even if they
358a3dbc 7508appear to be dead, but references may be deleted or moved or
c1f7febf
RK
7509simplified.
7510
7511It is not safe to access the global register variables from signal
7512handlers, or from more than one thread of control, because the system
7513library routines may temporarily use the register for other things (unless
7514you recompile them specially for the task at hand).
7515
7516@cindex @code{qsort}, and global register variables
7517It is not safe for one function that uses a global register variable to
7518call another such function @code{foo} by way of a third function
358a3dbc
SL
7519@code{lose} that is compiled without knowledge of this variable (i.e.@: in a
7520different source file in which the variable isn't declared). This is
c1f7febf
RK
7521because @code{lose} might save the register and put some other value there.
7522For example, you can't expect a global register variable to be available in
7523the comparison-function that you pass to @code{qsort}, since @code{qsort}
7524might have put something else in that register. (If you are prepared to
7525recompile @code{qsort} with the same global register variable, you can
7526solve this problem.)
7527
c417597c 7528If you want to recompile @code{qsort} or other source files that do not
358a3dbc 7529actually use your global register variable, so that they do not use that
c1f7febf 7530register for any other purpose, then it suffices to specify the compiler
84330467 7531option @option{-ffixed-@var{reg}}. You need not actually add a global
c1f7febf
RK
7532register declaration to their source code.
7533
c417597c 7534A function that can alter the value of a global register variable cannot
c1f7febf
RK
7535safely be called from a function compiled without this variable, because it
7536could clobber the value the caller expects to find there on return.
c417597c 7537Therefore, the function that is the entry point into the part of the
c1f7febf 7538program that uses the global register variable must explicitly save and
c417597c 7539restore the value that belongs to its caller.
c1f7febf
RK
7540
7541@cindex register variable after @code{longjmp}
7542@cindex global register after @code{longjmp}
7543@cindex value after @code{longjmp}
7544@findex longjmp
7545@findex setjmp
358a3dbc 7546On most machines, @code{longjmp} restores to each global register
c1f7febf 7547variable the value it had at the time of the @code{setjmp}. On some
358a3dbc 7548machines, however, @code{longjmp} does not change the value of global
c1f7febf
RK
7549register variables. To be portable, the function that called @code{setjmp}
7550should make other arrangements to save the values of the global register
7551variables, and to restore them in a @code{longjmp}. This way, the same
358a3dbc 7552thing happens regardless of what @code{longjmp} does.
c1f7febf
RK
7553
7554All global register variable declarations must precede all function
7555definitions. If such a declaration could appear after function
7556definitions, the declaration would be too late to prevent the register from
7557being used for other purposes in the preceding functions.
7558
7559Global register variables may not have initial values, because an
7560executable file has no means to supply initial contents for a register.
7561
981f6289 7562On the SPARC, there are reports that g3 @dots{} g7 are suitable
c1f7febf
RK
7563registers, but certain library functions, such as @code{getwd}, as well
7564as the subroutines for division and remainder, modify g3 and g4. g1 and
7565g2 are local temporaries.
7566
7567On the 68000, a2 @dots{} a5 should be suitable, as should d2 @dots{} d7.
358a3dbc 7568Of course, it does not do to use more than a few of those.
c1f7febf
RK
7569
7570@node Local Reg Vars
04e137a1 7571@subsubsection Specifying Registers for Local Variables
c1f7febf
RK
7572@cindex local variables, specifying registers
7573@cindex specifying registers for local variables
7574@cindex registers for local variables
7575
7576You can define a local register variable with a specified register
7577like this:
7578
3ab51846 7579@smallexample
c1f7febf 7580register int *foo asm ("a5");
3ab51846 7581@end smallexample
c1f7febf
RK
7582
7583@noindent
c417597c 7584Here @code{a5} is the name of the register that should be used. Note
c1f7febf 7585that this is the same syntax used for defining global register
358a3dbc 7586variables, but for a local variable it appears within a function.
c1f7febf
RK
7587
7588Naturally the register name is cpu-dependent, but this is not a
7589problem, since specific registers are most often useful with explicit
7590assembler instructions (@pxref{Extended Asm}). Both of these things
7591generally require that you conditionalize your program according to
7592cpu type.
7593
7594In addition, operating systems on one type of cpu may differ in how they
358a3dbc 7595name the registers; then you need additional conditionals. For
c1f7febf
RK
7596example, some 68000 operating systems call this register @code{%a5}.
7597
c1f7febf
RK
7598Defining such a register variable does not reserve the register; it
7599remains available for other uses in places where flow control determines
d754127f 7600the variable's value is not live.
e5e809f4 7601
358a3dbc 7602This option does not guarantee that GCC generates code that has
e5e809f4 7603this variable in the register you specify at all times. You may not
805c33df 7604code an explicit reference to this register in the @emph{assembler
358a3dbc
SL
7605instruction template} part of an @code{asm} statement and assume it
7606always refers to this variable. However, using the variable as an
805c33df
HPN
7607@code{asm} @emph{operand} guarantees that the specified register is used
7608for the operand.
c1f7febf 7609
8d344fbc 7610Stores into local register variables may be deleted when they appear to be dead
0deaf590
JL
7611according to dataflow analysis. References to local register variables may
7612be deleted or moved or simplified.
7613
04e137a1 7614As with global register variables, it is recommended that you choose a
c417597c 7615register that is normally saved and restored by function calls on
04e137a1
DW
7616your machine, so that library routines will not clobber it.
7617
7618Sometimes when writing inline @code{asm} code, you need to make an operand be a
7619specific register, but there's no matching constraint letter for that
7620register. To force the operand into that register, create a local variable
7621and specify the register in the variable's declaration. Then use the local
7622variable for the asm operand and specify any constraint letter that matches
7623the register:
7624
b55d5746
HPN
7625@smallexample
7626register int *p1 asm ("r0") = @dots{};
7627register int *p2 asm ("r1") = @dots{};
04e137a1
DW
7628register int *result asm ("r0");
7629asm ("sysint" : "=r" (result) : "0" (p1), "r" (p2));
b55d5746 7630@end smallexample
c513ecbf 7631
04e137a1
DW
7632@emph{Warning:} In the above example, be aware that a register (for example r0) can be
7633call-clobbered by subsequent code, including function calls and library calls
7634for arithmetic operators on other variables (for example the initialization
7635of p2). In this case, use temporary variables for expressions between the
7636register assignments:
7637
7638@smallexample
7639int t1 = @dots{};
7640register int *p1 asm ("r0") = @dots{};
7641register int *p2 asm ("r1") = t1;
7642register int *result asm ("r0");
7643asm ("sysint" : "=r" (result) : "0" (p1), "r" (p2));
7644@end smallexample
b55d5746 7645
db2687a0
UB
7646@node Size of an asm
7647@subsection Size of an @code{asm}
7648
7649Some targets require that GCC track the size of each instruction used
7650in order to generate correct code. Because the final length of the
7651code produced by an @code{asm} statement is only known by the
7652assembler, GCC must make an estimate as to how big it will be. It
7653does this by counting the number of instructions in the pattern of the
7654@code{asm} and multiplying that by the length of the longest
7655instruction supported by that processor. (When working out the number
7656of instructions, it assumes that any occurrence of a newline or of
7657whatever statement separator character is supported by the assembler --
7658typically @samp{;} --- indicates the end of an instruction.)
7659
7660Normally, GCC's estimate is adequate to ensure that correct
7661code is generated, but it is possible to confuse the compiler if you use
7662pseudo instructions or assembler macros that expand into multiple real
7663instructions, or if you use assembler directives that expand to more
7664space in the object file than is needed for a single instruction.
7665If this happens then the assembler may produce a diagnostic saying that
7666a label is unreachable.
7667
c1f7febf
RK
7668@node Alternate Keywords
7669@section Alternate Keywords
7670@cindex alternate keywords
7671@cindex keywords, alternate
7672
5490d604 7673@option{-ansi} and the various @option{-std} options disable certain
f458d1d5
ZW
7674keywords. This causes trouble when you want to use GNU C extensions, or
7675a general-purpose header file that should be usable by all programs,
7676including ISO C programs. The keywords @code{asm}, @code{typeof} and
7677@code{inline} are not available in programs compiled with
7678@option{-ansi} or @option{-std} (although @code{inline} can be used in a
48b0b196 7679program compiled with @option{-std=c99} or @option{-std=c11}). The
2778d766 7680ISO C99 keyword
5490d604
JM
7681@code{restrict} is only available when @option{-std=gnu99} (which will
7682eventually be the default) or @option{-std=c99} (or the equivalent
2778d766
JM
7683@option{-std=iso9899:1999}), or an option for a later standard
7684version, is used.
c1f7febf
RK
7685
7686The way to solve these problems is to put @samp{__} at the beginning and
7687end of each problematical keyword. For example, use @code{__asm__}
f458d1d5 7688instead of @code{asm}, and @code{__inline__} instead of @code{inline}.
c1f7febf
RK
7689
7690Other C compilers won't accept these alternative keywords; if you want to
7691compile with another compiler, you can define the alternate keywords as
7692macros to replace them with the customary keywords. It looks like this:
7693
3ab51846 7694@smallexample
c1f7febf
RK
7695#ifndef __GNUC__
7696#define __asm__ asm
7697#endif
3ab51846 7698@end smallexample
c1f7febf 7699
6e6b0525 7700@findex __extension__
84330467
JM
7701@opindex pedantic
7702@option{-pedantic} and other options cause warnings for many GNU C extensions.
dbe519e0 7703You can
c1f7febf
RK
7704prevent such warnings within one expression by writing
7705@code{__extension__} before the expression. @code{__extension__} has no
7706effect aside from this.
7707
7708@node Incomplete Enums
7709@section Incomplete @code{enum} Types
7710
7711You can define an @code{enum} tag without specifying its possible values.
7712This results in an incomplete type, much like what you get if you write
7713@code{struct foo} without describing the elements. A later declaration
c417597c 7714that does specify the possible values completes the type.
c1f7febf
RK
7715
7716You can't allocate variables or storage using the type while it is
7717incomplete. However, you can work with pointers to that type.
7718
7719This extension may not be very useful, but it makes the handling of
7720@code{enum} more consistent with the way @code{struct} and @code{union}
7721are handled.
7722
7723This extension is not supported by GNU C++.
7724
7725@node Function Names
7726@section Function Names as Strings
e6cc3a24 7727@cindex @code{__func__} identifier
4b404517
JM
7728@cindex @code{__FUNCTION__} identifier
7729@cindex @code{__PRETTY_FUNCTION__} identifier
c1f7febf 7730
c417597c 7731GCC provides three magic variables that hold the name of the current
e6cc3a24
ZW
7732function, as a string. The first of these is @code{__func__}, which
7733is part of the C99 standard:
7734
e6cc3a24
ZW
7735The identifier @code{__func__} is implicitly declared by the translator
7736as if, immediately following the opening brace of each function
7737definition, the declaration
7738
7739@smallexample
7740static const char __func__[] = "function-name";
7741@end smallexample
c1f7febf 7742
38bb2b65 7743@noindent
e6cc3a24
ZW
7744appeared, where function-name is the name of the lexically-enclosing
7745function. This name is the unadorned name of the function.
e6cc3a24
ZW
7746
7747@code{__FUNCTION__} is another name for @code{__func__}. Older
7748versions of GCC recognize only this name. However, it is not
7749standardized. For maximum portability, we recommend you use
7750@code{__func__}, but provide a fallback definition with the
7751preprocessor:
7752
7753@smallexample
7754#if __STDC_VERSION__ < 199901L
7755# if __GNUC__ >= 2
7756# define __func__ __FUNCTION__
7757# else
7758# define __func__ "<unknown>"
7759# endif
7760#endif
7761@end smallexample
7762
7763In C, @code{__PRETTY_FUNCTION__} is yet another name for
7764@code{__func__}. However, in C++, @code{__PRETTY_FUNCTION__} contains
7765the type signature of the function as well as its bare name. For
7766example, this program:
c1f7febf
RK
7767
7768@smallexample
7769extern "C" @{
7770extern int printf (char *, ...);
7771@}
7772
7773class a @{
7774 public:
a721a601 7775 void sub (int i)
c1f7febf
RK
7776 @{
7777 printf ("__FUNCTION__ = %s\n", __FUNCTION__);
7778 printf ("__PRETTY_FUNCTION__ = %s\n", __PRETTY_FUNCTION__);
7779 @}
7780@};
7781
7782int
7783main (void)
7784@{
7785 a ax;
7786 ax.sub (0);
7787 return 0;
7788@}
7789@end smallexample
7790
7791@noindent
7792gives this output:
7793
7794@smallexample
7795__FUNCTION__ = sub
e6cc3a24 7796__PRETTY_FUNCTION__ = void a::sub(int)
22acfb79
NM
7797@end smallexample
7798
e6cc3a24
ZW
7799These identifiers are not preprocessor macros. In GCC 3.3 and
7800earlier, in C only, @code{__FUNCTION__} and @code{__PRETTY_FUNCTION__}
7801were treated as string literals; they could be used to initialize
7802@code{char} arrays, and they could be concatenated with other string
7803literals. GCC 3.4 and later treat them as variables, like
7804@code{__func__}. In C++, @code{__FUNCTION__} and
7805@code{__PRETTY_FUNCTION__} have always been variables.
22acfb79 7806
c1f7febf
RK
7807@node Return Address
7808@section Getting the Return or Frame Address of a Function
7809
7810These functions may be used to get information about the callers of a
7811function.
7812
84330467 7813@deftypefn {Built-in Function} {void *} __builtin_return_address (unsigned int @var{level})
c1f7febf
RK
7814This function returns the return address of the current function, or of
7815one of its callers. The @var{level} argument is number of frames to
7816scan up the call stack. A value of @code{0} yields the return address
7817of the current function, a value of @code{1} yields the return address
8a36672b 7818of the caller of the current function, and so forth. When inlining
358a3dbc
SL
7819the expected behavior is that the function returns the address of
7820the function that is returned to. To work around this behavior use
95b1627e 7821the @code{noinline} function attribute.
c1f7febf
RK
7822
7823The @var{level} argument must be a constant integer.
7824
7825On some machines it may be impossible to determine the return address of
7826any function other than the current one; in such cases, or when the top
358a3dbc 7827of the stack has been reached, this function returns @code{0} or a
8a36672b 7828random value. In addition, @code{__builtin_frame_address} may be used
dd96fbc5 7829to determine if the top of the stack has been reached.
c1f7febf 7830
48c4de16 7831Additional post-processing of the returned value may be needed, see
d564b816 7832@code{__builtin_extract_return_addr}.
48c4de16 7833
df2a54e9 7834This function should only be used with a nonzero argument for debugging
c1f7febf 7835purposes.
84330467 7836@end deftypefn
c1f7febf 7837
d564b816 7838@deftypefn {Built-in Function} {void *} __builtin_extract_return_addr (void *@var{addr})
48c4de16
TS
7839The address as returned by @code{__builtin_return_address} may have to be fed
7840through this function to get the actual encoded address. For example, on the
784131-bit S/390 platform the highest bit has to be masked out, or on SPARC
7842platforms an offset has to be added for the true next instruction to be
7843executed.
7844
7845If no fixup is needed, this function simply passes through @var{addr}.
7846@end deftypefn
7847
7848@deftypefn {Built-in Function} {void *} __builtin_frob_return_address (void *@var{addr})
d564b816 7849This function does the reverse of @code{__builtin_extract_return_addr}.
48c4de16
TS
7850@end deftypefn
7851
84330467 7852@deftypefn {Built-in Function} {void *} __builtin_frame_address (unsigned int @var{level})
c1f7febf
RK
7853This function is similar to @code{__builtin_return_address}, but it
7854returns the address of the function frame rather than the return address
7855of the function. Calling @code{__builtin_frame_address} with a value of
7856@code{0} yields the frame address of the current function, a value of
7857@code{1} yields the frame address of the caller of the current function,
7858and so forth.
7859
c417597c 7860The frame is the area on the stack that holds local variables and saved
c1f7febf
RK
7861registers. The frame address is normally the address of the first word
7862pushed on to the stack by the function. However, the exact definition
7863depends upon the processor and the calling convention. If the processor
7864has a dedicated frame pointer register, and the function has a frame,
358a3dbc 7865then @code{__builtin_frame_address} returns the value of the frame
c1f7febf
RK
7866pointer register.
7867
dd96fbc5
L
7868On some machines it may be impossible to determine the frame address of
7869any function other than the current one; in such cases, or when the top
358a3dbc 7870of the stack has been reached, this function returns @code{0} if
dd96fbc5
L
7871the first frame pointer is properly initialized by the startup code.
7872
df2a54e9 7873This function should only be used with a nonzero argument for debugging
dd96fbc5 7874purposes.
84330467 7875@end deftypefn
c1f7febf 7876
1255c85c 7877@node Vector Extensions
18abab9f 7878@section Using Vector Instructions through Built-in Functions
1255c85c 7879
c417597c 7880On some targets, the instruction set contains SIMD vector instructions which
1255c85c 7881operate on multiple values contained in one large register at the same time.
f8723eb6 7882For example, on the i386 the MMX, 3DNow!@: and SSE extensions can be used
1255c85c
BS
7883this way.
7884
7885The first step in using these extensions is to provide the necessary data
7886types. This should be done using an appropriate @code{typedef}:
7887
3ab51846 7888@smallexample
4a5eab38 7889typedef int v4si __attribute__ ((vector_size (16)));
3ab51846 7890@end smallexample
1255c85c 7891
c513ecbf 7892@noindent
4a5eab38
PB
7893The @code{int} type specifies the base type, while the attribute specifies
7894the vector size for the variable, measured in bytes. For example, the
7895declaration above causes the compiler to set the mode for the @code{v4si}
7896type to be 16 bytes wide and divided into @code{int} sized units. For
7897a 32-bit @code{int} this means a vector of 4 units of 4 bytes, and the
358a3dbc 7898corresponding mode of @code{foo} is @acronym{V4SI}.
1255c85c 7899
4a5eab38
PB
7900The @code{vector_size} attribute is only applicable to integral and
7901float scalars, although arrays, pointers, and function return values
bafa88c2
SL
7902are allowed in conjunction with this construct. Only sizes that are
7903a power of two are currently allowed.
4a5eab38
PB
7904
7905All the basic integer types can be used as base types, both as signed
7906and as unsigned: @code{char}, @code{short}, @code{int}, @code{long},
7907@code{long long}. In addition, @code{float} and @code{double} can be
7908used to build floating-point vector types.
1255c85c 7909
cb2a532e 7910Specifying a combination that is not valid for the current architecture
358a3dbc 7911causes GCC to synthesize the instructions using a narrower mode.
cb2a532e 7912For example, if you specify a variable of type @code{V4SI} and your
358a3dbc
SL
7913architecture does not allow for this specific SIMD type, GCC
7914produces code that uses 4 @code{SIs}.
cb2a532e
AH
7915
7916The types defined in this manner can be used with a subset of normal C
358a3dbc 7917operations. Currently, GCC allows using the following operators
5cfd5d9b 7918on these types: @code{+, -, *, /, unary minus, ^, |, &, ~, %}@.
cb2a532e
AH
7919
7920The operations behave like C++ @code{valarrays}. Addition is defined as
7921the addition of the corresponding elements of the operands. For
358a3dbc 7922example, in the code below, each of the 4 elements in @var{a} is
cb2a532e 7923added to the corresponding 4 elements in @var{b} and the resulting
358a3dbc 7924vector is stored in @var{c}.
cb2a532e 7925
3ab51846 7926@smallexample
4a5eab38 7927typedef int v4si __attribute__ ((vector_size (16)));
cb2a532e
AH
7928
7929v4si a, b, c;
7930
7931c = a + b;
3ab51846 7932@end smallexample
cb2a532e 7933
3a3e1600
GK
7934Subtraction, multiplication, division, and the logical operations
7935operate in a similar manner. Likewise, the result of using the unary
7936minus or complement operators on a vector type is a vector whose
7937elements are the negative or complemented values of the corresponding
cb2a532e
AH
7938elements in the operand.
7939
e481cda6 7940It is possible to use shifting operators @code{<<}, @code{>>} on
f87bd04b
AS
7941integer-type vectors. The operation is defined as following: @code{@{a0,
7942a1, @dots{}, an@} >> @{b0, b1, @dots{}, bn@} == @{a0 >> b0, a1 >> b1,
7943@dots{}, an >> bn@}}@. Vector operands must have the same number of
0e3a99ae
AS
7944elements.
7945
0fdce875 7946For convenience, it is allowed to use a binary vector operation
358a3dbc 7947where one operand is a scalar. In that case the compiler transforms
0e3a99ae 7948the scalar operand into a vector where each element is the scalar from
358a3dbc 7949the operation. The transformation happens only if the scalar could be
0e3a99ae 7950safely converted to the vector-element type.
f87bd04b
AS
7951Consider the following code.
7952
7953@smallexample
7954typedef int v4si __attribute__ ((vector_size (16)));
7955
0e3a99ae
AS
7956v4si a, b, c;
7957long l;
7958
7959a = b + 1; /* a = b + @{1,1,1,1@}; */
7960a = 2 * b; /* a = @{2,2,2,2@} * b; */
f87bd04b 7961
0e3a99ae 7962a = l + a; /* Error, cannot convert long to int. */
f87bd04b
AS
7963@end smallexample
7964
7edaa4d2 7965Vectors can be subscripted as if the vector were an array with
30cd1c5d 7966the same number of elements and base type. Out of bound accesses
566fb011 7967invoke undefined behavior at run time. Warnings for out of bound
30cd1c5d
AS
7968accesses for vector subscription can be enabled with
7969@option{-Warray-bounds}.
7970
e481cda6 7971Vector comparison is supported with standard comparison
d246ab4f
AS
7972operators: @code{==, !=, <, <=, >, >=}. Comparison operands can be
7973vector expressions of integer-type or real-type. Comparison between
7974integer-type vectors and real-type vectors are not supported. The
7975result of the comparison is a vector of the same width and number of
7976elements as the comparison operands with a signed integral element
7977type.
7978
7979Vectors are compared element-wise producing 0 when comparison is false
7980and -1 (constant of the appropriate type where all bits are set)
7981otherwise. Consider the following example.
7982
7983@smallexample
7984typedef int v4si __attribute__ ((vector_size (16)));
7985
7986v4si a = @{1,2,3,4@};
7987v4si b = @{3,2,1,4@};
7988v4si c;
7989
7990c = a > b; /* The result would be @{0, 0,-1, 0@} */
7991c = a == b; /* The result would be @{0,-1, 0,-1@} */
7992@end smallexample
7993
0878d68a
MG
7994In C++, the ternary operator @code{?:} is available. @code{a?b:c}, where
7995@code{b} and @code{c} are vectors of the same type and @code{a} is an
7996integer vector with the same number of elements of the same size as @code{b}
7997and @code{c}, computes all three arguments and creates a vector
7998@code{@{a[0]?b[0]:c[0], a[1]?b[1]:c[1], @dots{}@}}. Note that unlike in
7999OpenCL, @code{a} is thus interpreted as @code{a != 0} and not @code{a < 0}.
8000As in the case of binary operations, this syntax is also accepted when
8001one of @code{b} or @code{c} is a scalar that is then transformed into a
8002vector. If both @code{b} and @code{c} are scalars and the type of
8003@code{true?b:c} has the same size as the element type of @code{a}, then
8004@code{b} and @code{c} are converted to a vector type whose elements have
8005this type and with the same number of elements as @code{a}.
8006
3c9aabbd
MG
8007In C++, the logic operators @code{!, &&, ||} are available for vectors.
8008@code{!v} is equivalent to @code{v == 0}, @code{a && b} is equivalent to
8009@code{a!=0 & b!=0} and @code{a || b} is equivalent to @code{a!=0 | b!=0}.
8010For mixed operations between a scalar @code{s} and a vector @code{v},
8011@code{s && v} is equivalent to @code{s?v!=0:0} (the evaluation is
8012short-circuit) and @code{v && s} is equivalent to @code{v!=0 & (s?-1:0)}.
8013
f90e8e2e
AS
8014Vector shuffling is available using functions
8015@code{__builtin_shuffle (vec, mask)} and
2205ed25
RH
8016@code{__builtin_shuffle (vec0, vec1, mask)}.
8017Both functions construct a permutation of elements from one or two
8018vectors and return a vector of the same type as the input vector(s).
8019The @var{mask} is an integral vector with the same width (@var{W})
8020and element count (@var{N}) as the output vector.
f90e8e2e 8021
2205ed25
RH
8022The elements of the input vectors are numbered in memory ordering of
8023@var{vec0} beginning at 0 and @var{vec1} beginning at @var{N}. The
8024elements of @var{mask} are considered modulo @var{N} in the single-operand
8025case and modulo @math{2*@var{N}} in the two-operand case.
8026
8027Consider the following example,
f90e8e2e
AS
8028
8029@smallexample
8030typedef int v4si __attribute__ ((vector_size (16)));
8031
8032v4si a = @{1,2,3,4@};
8033v4si b = @{5,6,7,8@};
8034v4si mask1 = @{0,1,1,3@};
8035v4si mask2 = @{0,4,2,5@};
8036v4si res;
8037
8038res = __builtin_shuffle (a, mask1); /* res is @{1,2,2,4@} */
8039res = __builtin_shuffle (a, b, mask2); /* res is @{1,5,3,6@} */
8040@end smallexample
8041
2205ed25
RH
8042Note that @code{__builtin_shuffle} is intentionally semantically
8043compatible with the OpenCL @code{shuffle} and @code{shuffle2} functions.
8044
cb2a532e
AH
8045You can declare variables and use them in function calls and returns, as
8046well as in assignments and some casts. You can specify a vector type as
8047a return type for a function. Vector types can also be used as function
8048arguments. It is possible to cast from one vector type to another,
8049provided they are of the same size (in fact, you can also cast vectors
8050to and from other datatypes of the same size).
8051
8052You cannot operate between vectors of different lengths or different
90a21764 8053signedness without a cast.
cb2a532e 8054
7a3ea201
RH
8055@node Offsetof
8056@section Offsetof
8057@findex __builtin_offsetof
8058
8059GCC implements for both C and C++ a syntactic extension to implement
8060the @code{offsetof} macro.
8061
8062@smallexample
8063primary:
6ccde948 8064 "__builtin_offsetof" "(" @code{typename} "," offsetof_member_designator ")"
7a3ea201
RH
8065
8066offsetof_member_designator:
6ccde948
RW
8067 @code{identifier}
8068 | offsetof_member_designator "." @code{identifier}
8069 | offsetof_member_designator "[" @code{expr} "]"
7a3ea201
RH
8070@end smallexample
8071
8072This extension is sufficient such that
8073
8074@smallexample
8075#define offsetof(@var{type}, @var{member}) __builtin_offsetof (@var{type}, @var{member})
8076@end smallexample
8077
c513ecbf 8078@noindent
7a3ea201
RH
8079is a suitable definition of the @code{offsetof} macro. In C++, @var{type}
8080may be dependent. In either case, @var{member} may consist of a single
8081identifier, or a sequence of member accesses and array references.
8082
86951993 8083@node __sync Builtins
18abab9f 8084@section Legacy __sync Built-in Functions for Atomic Memory Access
48ae6c13 8085
18abab9f
SL
8086The following built-in functions
8087are intended to be compatible with those described
48ae6c13
RH
8088in the @cite{Intel Itanium Processor-specific Application Binary Interface},
8089section 7.4. As such, they depart from the normal GCC practice of using
566fb011 8090the @samp{__builtin_} prefix, and further that they are overloaded such that
48ae6c13
RH
8091they work on multiple types.
8092
8093The definition given in the Intel documentation allows only for the use of
8094the types @code{int}, @code{long}, @code{long long} as well as their unsigned
358a3dbc 8095counterparts. GCC allows any integral scalar or pointer type that is
48ae6c13
RH
80961, 2, 4 or 8 bytes in length.
8097
8098Not all operations are supported by all target processors. If a particular
358a3dbc
SL
8099operation cannot be implemented on the target processor, a warning is
8100generated and a call an external function is generated. The external
18abab9f
SL
8101function carries the same name as the built-in version,
8102with an additional suffix
48ae6c13
RH
8103@samp{_@var{n}} where @var{n} is the size of the data type.
8104
8105@c ??? Should we have a mechanism to suppress this warning? This is almost
8106@c useful for implementing the operation under the control of an external
8107@c mutex.
8108
18abab9f
SL
8109In most cases, these built-in functions are considered a @dfn{full barrier}.
8110That is,
358a3dbc
SL
8111no memory operand is moved across the operation, either forward or
8112backward. Further, instructions are issued as necessary to prevent the
48ae6c13
RH
8113processor from speculating loads across the operation and from queuing stores
8114after the operation.
8115
d1facce0 8116All of the routines are described in the Intel documentation to take
48ae6c13
RH
8117``an optional list of variables protected by the memory barrier''. It's
8118not clear what is meant by that; it could mean that @emph{only} the
8119following variables are protected, or it could mean that these variables
8120should in addition be protected. At present GCC ignores this list and
c417597c 8121protects all variables that are globally accessible. If in the future
48ae6c13
RH
8122we make some use of this list, an empty list will continue to mean all
8123globally accessible variables.
8124
8125@table @code
8126@item @var{type} __sync_fetch_and_add (@var{type} *ptr, @var{type} value, ...)
8127@itemx @var{type} __sync_fetch_and_sub (@var{type} *ptr, @var{type} value, ...)
8128@itemx @var{type} __sync_fetch_and_or (@var{type} *ptr, @var{type} value, ...)
8129@itemx @var{type} __sync_fetch_and_and (@var{type} *ptr, @var{type} value, ...)
8130@itemx @var{type} __sync_fetch_and_xor (@var{type} *ptr, @var{type} value, ...)
8131@itemx @var{type} __sync_fetch_and_nand (@var{type} *ptr, @var{type} value, ...)
8132@findex __sync_fetch_and_add
8133@findex __sync_fetch_and_sub
8134@findex __sync_fetch_and_or
8135@findex __sync_fetch_and_and
8136@findex __sync_fetch_and_xor
8137@findex __sync_fetch_and_nand
18abab9f 8138These built-in functions perform the operation suggested by the name, and
48ae6c13
RH
8139returns the value that had previously been in memory. That is,
8140
8141@smallexample
8142@{ tmp = *ptr; *ptr @var{op}= value; return tmp; @}
23462d4d 8143@{ tmp = *ptr; *ptr = ~(tmp & value); return tmp; @} // nand
48ae6c13
RH
8144@end smallexample
8145
23462d4d 8146@emph{Note:} GCC 4.4 and later implement @code{__sync_fetch_and_nand}
18abab9f 8147as @code{*ptr = ~(tmp & value)} instead of @code{*ptr = ~tmp & value}.
23462d4d 8148
48ae6c13
RH
8149@item @var{type} __sync_add_and_fetch (@var{type} *ptr, @var{type} value, ...)
8150@itemx @var{type} __sync_sub_and_fetch (@var{type} *ptr, @var{type} value, ...)
8151@itemx @var{type} __sync_or_and_fetch (@var{type} *ptr, @var{type} value, ...)
8152@itemx @var{type} __sync_and_and_fetch (@var{type} *ptr, @var{type} value, ...)
8153@itemx @var{type} __sync_xor_and_fetch (@var{type} *ptr, @var{type} value, ...)
8154@itemx @var{type} __sync_nand_and_fetch (@var{type} *ptr, @var{type} value, ...)
8155@findex __sync_add_and_fetch
8156@findex __sync_sub_and_fetch
8157@findex __sync_or_and_fetch
8158@findex __sync_and_and_fetch
8159@findex __sync_xor_and_fetch
8160@findex __sync_nand_and_fetch
18abab9f 8161These built-in functions perform the operation suggested by the name, and
48ae6c13
RH
8162return the new value. That is,
8163
8164@smallexample
8165@{ *ptr @var{op}= value; return *ptr; @}
23462d4d 8166@{ *ptr = ~(*ptr & value); return *ptr; @} // nand
48ae6c13
RH
8167@end smallexample
8168
23462d4d 8169@emph{Note:} GCC 4.4 and later implement @code{__sync_nand_and_fetch}
18abab9f 8170as @code{*ptr = ~(*ptr & value)} instead of
23462d4d
UB
8171@code{*ptr = ~*ptr & value}.
8172
06ef8c2e
L
8173@item bool __sync_bool_compare_and_swap (@var{type} *ptr, @var{type} oldval, @var{type} newval, ...)
8174@itemx @var{type} __sync_val_compare_and_swap (@var{type} *ptr, @var{type} oldval, @var{type} newval, ...)
48ae6c13
RH
8175@findex __sync_bool_compare_and_swap
8176@findex __sync_val_compare_and_swap
18abab9f
SL
8177These built-in functions perform an atomic compare and swap.
8178That is, if the current
48ae6c13
RH
8179value of @code{*@var{ptr}} is @var{oldval}, then write @var{newval} into
8180@code{*@var{ptr}}.
8181
0ac11108 8182The ``bool'' version returns true if the comparison is successful and
358a3dbc 8183@var{newval} is written. The ``val'' version returns the contents
f12b785d 8184of @code{*@var{ptr}} before the operation.
48ae6c13
RH
8185
8186@item __sync_synchronize (...)
8187@findex __sync_synchronize
18abab9f 8188This built-in function issues a full memory barrier.
48ae6c13
RH
8189
8190@item @var{type} __sync_lock_test_and_set (@var{type} *ptr, @var{type} value, ...)
8191@findex __sync_lock_test_and_set
18abab9f 8192This built-in function, as described by Intel, is not a traditional test-and-set
48ae6c13
RH
8193operation, but rather an atomic exchange operation. It writes @var{value}
8194into @code{*@var{ptr}}, and returns the previous contents of
8195@code{*@var{ptr}}.
8196
8197Many targets have only minimal support for such locks, and do not support
8198a full exchange operation. In this case, a target may support reduced
8199functionality here by which the @emph{only} valid value to store is the
8200immediate constant 1. The exact value actually stored in @code{*@var{ptr}}
8201is implementation defined.
8202
18abab9f
SL
8203This built-in function is not a full barrier,
8204but rather an @dfn{acquire barrier}.
8205This means that references after the operation cannot move to (or be
8206speculated to) before the operation, but previous memory stores may not
0ac11108 8207be globally visible yet, and previous memory loads may not yet be
48ae6c13
RH
8208satisfied.
8209
8210@item void __sync_lock_release (@var{type} *ptr, ...)
8211@findex __sync_lock_release
18abab9f
SL
8212This built-in function releases the lock acquired by
8213@code{__sync_lock_test_and_set}.
48ae6c13
RH
8214Normally this means writing the constant 0 to @code{*@var{ptr}}.
8215
18abab9f
SL
8216This built-in function is not a full barrier,
8217but rather a @dfn{release barrier}.
48ae6c13
RH
8218This means that all previous memory stores are globally visible, and all
8219previous memory loads have been satisfied, but following memory reads
8220are not prevented from being speculated to before the barrier.
8221@end table
8222
86951993
AM
8223@node __atomic Builtins
8224@section Built-in functions for memory model aware atomic operations
8225
8226The following built-in functions approximately match the requirements for
8227C++11 memory model. Many are similar to the @samp{__sync} prefixed built-in
8228functions, but all also have a memory model parameter. These are all
8229identified by being prefixed with @samp{__atomic}, and most are overloaded
8230such that they work with multiple types.
8231
358a3dbc 8232GCC allows any integral scalar or pointer type that is 1, 2, 4, or 8
86951993
AM
8233bytes in length. 16-byte integral types are also allowed if
8234@samp{__int128} (@pxref{__int128}) is supported by the architecture.
8235
8236Target architectures are encouraged to provide their own patterns for
8237each of these built-in functions. If no target is provided, the original
358a3dbc 8238non-memory model set of @samp{__sync} atomic built-in functions are
86951993 8239utilized, along with any required synchronization fences surrounding it in
566fb011 8240order to achieve the proper behavior. Execution in this case is subject
86951993
AM
8241to the same restrictions as those built-in functions.
8242
8243If there is no pattern or mechanism to provide a lock free instruction
8244sequence, a call is made to an external routine with the same parameters
566fb011 8245to be resolved at run time.
86951993
AM
8246
8247The four non-arithmetic functions (load, store, exchange, and
8248compare_exchange) all have a generic version as well. This generic
358a3dbc 8249version works on any data type. If the data type size maps to one
c417597c 8250of the integral sizes that may have lock free support, the generic
358a3dbc 8251version utilizes the lock free built-in function. Otherwise an
566fb011 8252external call is left to be resolved at run time. This external call is
358a3dbc 8253the same format with the addition of a @samp{size_t} parameter inserted
86951993
AM
8254as the first parameter indicating the size of the object being pointed to.
8255All objects must be the same size.
8256
c417597c 8257There are 6 different memory models that can be specified. These map
86951993
AM
8258to the same names in the C++11 standard. Refer there or to the
8259@uref{http://gcc.gnu.org/wiki/Atomic/GCCMM/AtomicSync,GCC wiki on
8260atomic synchronization} for more detailed definitions. These memory
8261models integrate both barriers to code motion as well as synchronization
8262requirements with other threads. These are listed in approximately
5dcfdccd
KY
8263ascending order of strength. It is also possible to use target specific
8264flags for memory model flags, like Hardware Lock Elision.
86951993
AM
8265
8266@table @code
8267@item __ATOMIC_RELAXED
8268No barriers or synchronization.
8269@item __ATOMIC_CONSUME
8270Data dependency only for both barrier and synchronization with another
8271thread.
8272@item __ATOMIC_ACQUIRE
8273Barrier to hoisting of code and synchronizes with release (or stronger)
8274semantic stores from another thread.
8275@item __ATOMIC_RELEASE
8276Barrier to sinking of code and synchronizes with acquire (or stronger)
8277semantic loads from another thread.
8278@item __ATOMIC_ACQ_REL
8279Full barrier in both directions and synchronizes with acquire loads and
8280release stores in another thread.
8281@item __ATOMIC_SEQ_CST
8282Full barrier in both directions and synchronizes with acquire loads and
8283release stores in all threads.
8284@end table
8285
81ea3024 8286When implementing patterns for these built-in functions, the memory model
86951993
AM
8287parameter can be ignored as long as the pattern implements the most
8288restrictive @code{__ATOMIC_SEQ_CST} model. Any of the other memory models
358a3dbc 8289execute correctly with this memory model but they may not execute as
bafa88c2 8290efficiently as they could with a more appropriate implementation of the
86951993
AM
8291relaxed requirements.
8292
8293Note that the C++11 standard allows for the memory model parameter to be
566fb011
SL
8294determined at run time rather than at compile time. These built-in
8295functions map any run-time value to @code{__ATOMIC_SEQ_CST} rather
86951993
AM
8296than invoke a runtime library call or inline a switch statement. This is
8297standard compliant, safe, and the simplest approach for now.
8298
b1cef2a5
AM
8299The memory model parameter is a signed int, but only the lower 8 bits are
8300reserved for the memory model. The remainder of the signed int is reserved
358a3dbc
SL
8301for future use and should be 0. Use of the predefined atomic values
8302ensures proper usage.
b1cef2a5 8303
86951993
AM
8304@deftypefn {Built-in Function} @var{type} __atomic_load_n (@var{type} *ptr, int memmodel)
8305This built-in function implements an atomic load operation. It returns the
8306contents of @code{*@var{ptr}}.
8307
8308The valid memory model variants are
8309@code{__ATOMIC_RELAXED}, @code{__ATOMIC_SEQ_CST}, @code{__ATOMIC_ACQUIRE},
8310and @code{__ATOMIC_CONSUME}.
8311
8312@end deftypefn
8313
8314@deftypefn {Built-in Function} void __atomic_load (@var{type} *ptr, @var{type} *ret, int memmodel)
358a3dbc 8315This is the generic version of an atomic load. It returns the
86951993
AM
8316contents of @code{*@var{ptr}} in @code{*@var{ret}}.
8317
8318@end deftypefn
8319
8320@deftypefn {Built-in Function} void __atomic_store_n (@var{type} *ptr, @var{type} val, int memmodel)
8321This built-in function implements an atomic store operation. It writes
0669295b 8322@code{@var{val}} into @code{*@var{ptr}}.
86951993
AM
8323
8324The valid memory model variants are
8325@code{__ATOMIC_RELAXED}, @code{__ATOMIC_SEQ_CST}, and @code{__ATOMIC_RELEASE}.
8326
8327@end deftypefn
8328
8329@deftypefn {Built-in Function} void __atomic_store (@var{type} *ptr, @var{type} *val, int memmodel)
358a3dbc 8330This is the generic version of an atomic store. It stores the value
86951993
AM
8331of @code{*@var{val}} into @code{*@var{ptr}}.
8332
8333@end deftypefn
8334
8335@deftypefn {Built-in Function} @var{type} __atomic_exchange_n (@var{type} *ptr, @var{type} val, int memmodel)
8336This built-in function implements an atomic exchange operation. It writes
8337@var{val} into @code{*@var{ptr}}, and returns the previous contents of
8338@code{*@var{ptr}}.
8339
86951993
AM
8340The valid memory model variants are
8341@code{__ATOMIC_RELAXED}, @code{__ATOMIC_SEQ_CST}, @code{__ATOMIC_ACQUIRE},
8342@code{__ATOMIC_RELEASE}, and @code{__ATOMIC_ACQ_REL}.
8343
8344@end deftypefn
8345
8346@deftypefn {Built-in Function} void __atomic_exchange (@var{type} *ptr, @var{type} *val, @var{type} *ret, int memmodel)
358a3dbc 8347This is the generic version of an atomic exchange. It stores the
86951993 8348contents of @code{*@var{val}} into @code{*@var{ptr}}. The original value
358a3dbc 8349of @code{*@var{ptr}} is copied into @code{*@var{ret}}.
86951993
AM
8350
8351@end deftypefn
8352
8353@deftypefn {Built-in Function} bool __atomic_compare_exchange_n (@var{type} *ptr, @var{type} *expected, @var{type} desired, bool weak, int success_memmodel, int failure_memmodel)
8354This built-in function implements an atomic compare and exchange operation.
8355This compares the contents of @code{*@var{ptr}} with the contents of
8356@code{*@var{expected}} and if equal, writes @var{desired} into
8357@code{*@var{ptr}}. If they are not equal, the current contents of
9ac1504b
AM
8358@code{*@var{ptr}} is written into @code{*@var{expected}}. @var{weak} is true
8359for weak compare_exchange, and false for the strong variation. Many targets
8360only offer the strong variation and ignore the parameter. When in doubt, use
8361the strong variation.
86951993 8362
8ca1b342 8363True is returned if @var{desired} is written into
86951993
AM
8364@code{*@var{ptr}} and the execution is considered to conform to the
8365memory model specified by @var{success_memmodel}. There are no
8366restrictions on what memory model can be used here.
8367
8368False is returned otherwise, and the execution is considered to conform
8369to @var{failure_memmodel}. This memory model cannot be
8370@code{__ATOMIC_RELEASE} nor @code{__ATOMIC_ACQ_REL}. It also cannot be a
8371stronger model than that specified by @var{success_memmodel}.
8372
8373@end deftypefn
8374
8375@deftypefn {Built-in Function} bool __atomic_compare_exchange (@var{type} *ptr, @var{type} *expected, @var{type} *desired, bool weak, int success_memmodel, int failure_memmodel)
8376This built-in function implements the generic version of
8377@code{__atomic_compare_exchange}. The function is virtually identical to
8378@code{__atomic_compare_exchange_n}, except the desired value is also a
8379pointer.
8380
8381@end deftypefn
8382
8383@deftypefn {Built-in Function} @var{type} __atomic_add_fetch (@var{type} *ptr, @var{type} val, int memmodel)
8384@deftypefnx {Built-in Function} @var{type} __atomic_sub_fetch (@var{type} *ptr, @var{type} val, int memmodel)
8385@deftypefnx {Built-in Function} @var{type} __atomic_and_fetch (@var{type} *ptr, @var{type} val, int memmodel)
8386@deftypefnx {Built-in Function} @var{type} __atomic_xor_fetch (@var{type} *ptr, @var{type} val, int memmodel)
8387@deftypefnx {Built-in Function} @var{type} __atomic_or_fetch (@var{type} *ptr, @var{type} val, int memmodel)
8388@deftypefnx {Built-in Function} @var{type} __atomic_nand_fetch (@var{type} *ptr, @var{type} val, int memmodel)
8389These built-in functions perform the operation suggested by the name, and
8390return the result of the operation. That is,
8391
8392@smallexample
8393@{ *ptr @var{op}= val; return *ptr; @}
8394@end smallexample
8395
8396All memory models are valid.
8397
8398@end deftypefn
8399
8400@deftypefn {Built-in Function} @var{type} __atomic_fetch_add (@var{type} *ptr, @var{type} val, int memmodel)
8401@deftypefnx {Built-in Function} @var{type} __atomic_fetch_sub (@var{type} *ptr, @var{type} val, int memmodel)
8402@deftypefnx {Built-in Function} @var{type} __atomic_fetch_and (@var{type} *ptr, @var{type} val, int memmodel)
8403@deftypefnx {Built-in Function} @var{type} __atomic_fetch_xor (@var{type} *ptr, @var{type} val, int memmodel)
8404@deftypefnx {Built-in Function} @var{type} __atomic_fetch_or (@var{type} *ptr, @var{type} val, int memmodel)
8405@deftypefnx {Built-in Function} @var{type} __atomic_fetch_nand (@var{type} *ptr, @var{type} val, int memmodel)
8406These built-in functions perform the operation suggested by the name, and
8407return the value that had previously been in @code{*@var{ptr}}. That is,
8408
8409@smallexample
8410@{ tmp = *ptr; *ptr @var{op}= val; return tmp; @}
8411@end smallexample
8412
8413All memory models are valid.
8414
8415@end deftypefn
8416
f8a27aa6 8417@deftypefn {Built-in Function} bool __atomic_test_and_set (void *ptr, int memmodel)
1aabd05e
AM
8418
8419This built-in function performs an atomic test-and-set operation on
f8a27aa6 8420the byte at @code{*@var{ptr}}. The byte is set to some implementation
566fb011
SL
8421defined nonzero ``set'' value and the return value is @code{true} if and only
8422if the previous contents were ``set''.
cca410b6
AK
8423It should be only used for operands of type @code{bool} or @code{char}. For
8424other types only part of the value may be set.
1aabd05e
AM
8425
8426All memory models are valid.
8427
8428@end deftypefn
8429
8430@deftypefn {Built-in Function} void __atomic_clear (bool *ptr, int memmodel)
8431
8432This built-in function performs an atomic clear operation on
358a3dbc 8433@code{*@var{ptr}}. After the operation, @code{*@var{ptr}} contains 0.
cca410b6
AK
8434It should be only used for operands of type @code{bool} or @code{char} and
8435in conjunction with @code{__atomic_test_and_set}.
8436For other types it may only clear partially. If the type is not @code{bool}
8437prefer using @code{__atomic_store}.
1aabd05e
AM
8438
8439The valid memory model variants are
8440@code{__ATOMIC_RELAXED}, @code{__ATOMIC_SEQ_CST}, and
8441@code{__ATOMIC_RELEASE}.
8442
8443@end deftypefn
8444
86951993
AM
8445@deftypefn {Built-in Function} void __atomic_thread_fence (int memmodel)
8446
8447This built-in function acts as a synchronization fence between threads
8448based on the specified memory model.
8449
8450All memory orders are valid.
8451
8452@end deftypefn
8453
8454@deftypefn {Built-in Function} void __atomic_signal_fence (int memmodel)
8455
8456This built-in function acts as a synchronization fence between a thread
8457and signal handlers based in the same thread.
8458
8459All memory orders are valid.
8460
8461@end deftypefn
8462
9ac1504b 8463@deftypefn {Built-in Function} bool __atomic_always_lock_free (size_t size, void *ptr)
86951993 8464
358a3dbc 8465This built-in function returns true if objects of @var{size} bytes always
9ac1504b 8466generate lock free atomic instructions for the target architecture.
566fb011
SL
8467@var{size} must resolve to a compile-time constant and the result also
8468resolves to a compile-time constant.
86951993 8469
c417597c 8470@var{ptr} is an optional pointer to the object that may be used to determine
9ac1504b
AM
8471alignment. A value of 0 indicates typical alignment should be used. The
8472compiler may also ignore this parameter.
86951993
AM
8473
8474@smallexample
9ac1504b 8475if (_atomic_always_lock_free (sizeof (long long), 0))
86951993
AM
8476@end smallexample
8477
8478@end deftypefn
8479
9ac1504b 8480@deftypefn {Built-in Function} bool __atomic_is_lock_free (size_t size, void *ptr)
86951993 8481
358a3dbc 8482This built-in function returns true if objects of @var{size} bytes always
86951993
AM
8483generate lock free atomic instructions for the target architecture. If
8484it is not known to be lock free a call is made to a runtime routine named
8485@code{__atomic_is_lock_free}.
8486
c417597c 8487@var{ptr} is an optional pointer to the object that may be used to determine
9ac1504b
AM
8488alignment. A value of 0 indicates typical alignment should be used. The
8489compiler may also ignore this parameter.
86951993
AM
8490@end deftypefn
8491
1304953e
JJ
8492@node Integer Overflow Builtins
8493@section Built-in functions to perform arithmetics and arithmetic overflow checking.
8494
8495The following built-in functions allow performing simple arithmetic operations
8496together with checking whether the operations overflowed.
8497
8498@deftypefn {Built-in Function} bool __builtin_add_overflow (@var{type1} a, @var{type2} b, @var{type3} *res)
8499@deftypefnx {Built-in Function} bool __builtin_sadd_overflow (int a, int b, int *res)
8500@deftypefnx {Built-in Function} bool __builtin_saddl_overflow (long int a, long int b, long int *res)
8501@deftypefnx {Built-in Function} bool __builtin_saddll_overflow (long long int a, long long int b, long int *res)
8502@deftypefnx {Built-in Function} bool __builtin_uadd_overflow (unsigned int a, unsigned int b, unsigned int *res)
8503@deftypefnx {Built-in Function} bool __builtin_uaddl_overflow (unsigned long int a, unsigned long int b, unsigned long int *res)
8504@deftypefnx {Built-in Function} bool __builtin_uaddll_overflow (unsigned long long int a, unsigned long long int b, unsigned long int *res)
8505
8506These built-in functions promote the first two operands into infinite precision signed
8507type and perform addition on those promoted operands. The result is then
8508cast to the type the third pointer argument points to and stored there.
8509If the stored result is equal to the infinite precision result, the built-in
8510functions return false, otherwise they return true. As the addition is
8511performed in infinite signed precision, these built-in functions have fully defined
8512behavior for all argument values.
8513
8514The first built-in function allows arbitrary integral types for operands and
8515the result type must be pointer to some integer type, the rest of the built-in
8516functions have explicit integer types.
8517
8518The compiler will attempt to use hardware instructions to implement
8519these built-in functions where possible, like conditional jump on overflow
8520after addition, conditional jump on carry etc.
8521
8522@end deftypefn
8523
8524@deftypefn {Built-in Function} bool __builtin_sub_overflow (@var{type1} a, @var{type2} b, @var{type3} *res)
8525@deftypefnx {Built-in Function} bool __builtin_ssub_overflow (int a, int b, int *res)
8526@deftypefnx {Built-in Function} bool __builtin_ssubl_overflow (long int a, long int b, long int *res)
8527@deftypefnx {Built-in Function} bool __builtin_ssubll_overflow (long long int a, long long int b, long int *res)
8528@deftypefnx {Built-in Function} bool __builtin_usub_overflow (unsigned int a, unsigned int b, unsigned int *res)
8529@deftypefnx {Built-in Function} bool __builtin_usubl_overflow (unsigned long int a, unsigned long int b, unsigned long int *res)
8530@deftypefnx {Built-in Function} bool __builtin_usubll_overflow (unsigned long long int a, unsigned long long int b, unsigned long int *res)
8531
8532These built-in functions are similar to the add overflow checking built-in
8533functions above, except they perform subtraction, subtract the second argument
8534from the first one, instead of addition.
8535
8536@end deftypefn
8537
8538@deftypefn {Built-in Function} bool __builtin_mul_overflow (@var{type1} a, @var{type2} b, @var{type3} *res)
8539@deftypefnx {Built-in Function} bool __builtin_smul_overflow (int a, int b, int *res)
8540@deftypefnx {Built-in Function} bool __builtin_smull_overflow (long int a, long int b, long int *res)
8541@deftypefnx {Built-in Function} bool __builtin_smulll_overflow (long long int a, long long int b, long int *res)
8542@deftypefnx {Built-in Function} bool __builtin_umul_overflow (unsigned int a, unsigned int b, unsigned int *res)
8543@deftypefnx {Built-in Function} bool __builtin_umull_overflow (unsigned long int a, unsigned long int b, unsigned long int *res)
8544@deftypefnx {Built-in Function} bool __builtin_umulll_overflow (unsigned long long int a, unsigned long long int b, unsigned long int *res)
8545
8546These built-in functions are similar to the add overflow checking built-in
8547functions above, except they perform multiplication, instead of addition.
8548
8549@end deftypefn
8550
4323afa0
AK
8551@node x86 specific memory model extensions for transactional memory
8552@section x86 specific memory model extensions for transactional memory
8553
8554The i386 architecture supports additional memory ordering flags
8555to mark lock critical sections for hardware lock elision.
8556These must be specified in addition to an existing memory model to
8557atomic intrinsics.
8558
8559@table @code
8560@item __ATOMIC_HLE_ACQUIRE
8561Start lock elision on a lock variable.
8562Memory model must be @code{__ATOMIC_ACQUIRE} or stronger.
8563@item __ATOMIC_HLE_RELEASE
8564End lock elision on a lock variable.
8565Memory model must be @code{__ATOMIC_RELEASE} or stronger.
8566@end table
8567
927f908b 8568When a lock acquire fails it is required for good performance to abort
4323afa0
AK
8569the transaction quickly. This can be done with a @code{_mm_pause}
8570
8571@smallexample
8572#include <immintrin.h> // For _mm_pause
8573
927f908b
AK
8574int lockvar;
8575
4323afa0
AK
8576/* Acquire lock with lock elision */
8577while (__atomic_exchange_n(&lockvar, 1, __ATOMIC_ACQUIRE|__ATOMIC_HLE_ACQUIRE))
8578 _mm_pause(); /* Abort failed transaction */
8579...
8580/* Free lock with lock elision */
11e8f687 8581__atomic_store_n(&lockvar, 0, __ATOMIC_RELEASE|__ATOMIC_HLE_RELEASE);
4323afa0
AK
8582@end smallexample
8583
10a0d495 8584@node Object Size Checking
18abab9f 8585@section Object Size Checking Built-in Functions
10a0d495
JJ
8586@findex __builtin_object_size
8587@findex __builtin___memcpy_chk
8588@findex __builtin___mempcpy_chk
8589@findex __builtin___memmove_chk
8590@findex __builtin___memset_chk
8591@findex __builtin___strcpy_chk
8592@findex __builtin___stpcpy_chk
8593@findex __builtin___strncpy_chk
8594@findex __builtin___strcat_chk
8595@findex __builtin___strncat_chk
8596@findex __builtin___sprintf_chk
8597@findex __builtin___snprintf_chk
8598@findex __builtin___vsprintf_chk
8599@findex __builtin___vsnprintf_chk
8600@findex __builtin___printf_chk
8601@findex __builtin___vprintf_chk
8602@findex __builtin___fprintf_chk
8603@findex __builtin___vfprintf_chk
8604
8605GCC implements a limited buffer overflow protection mechanism
8606that can prevent some buffer overflow attacks.
8607
8608@deftypefn {Built-in Function} {size_t} __builtin_object_size (void * @var{ptr}, int @var{type})
8609is a built-in construct that returns a constant number of bytes from
8610@var{ptr} to the end of the object @var{ptr} pointer points to
8611(if known at compile time). @code{__builtin_object_size} never evaluates
8612its arguments for side-effects. If there are any side-effects in them, it
8613returns @code{(size_t) -1} for @var{type} 0 or 1 and @code{(size_t) 0}
8614for @var{type} 2 or 3. If there are multiple objects @var{ptr} can
8615point to and all of them are known at compile time, the returned number
8616is the maximum of remaining byte counts in those objects if @var{type} & 2 is
a4d05547 86170 and minimum if nonzero. If it is not possible to determine which objects
10a0d495
JJ
8618@var{ptr} points to at compile time, @code{__builtin_object_size} should
8619return @code{(size_t) -1} for @var{type} 0 or 1 and @code{(size_t) 0}
8620for @var{type} 2 or 3.
8621
8622@var{type} is an integer constant from 0 to 3. If the least significant
8623bit is clear, objects are whole variables, if it is set, a closest
8624surrounding subobject is considered the object a pointer points to.
8625The second bit determines if maximum or minimum of remaining bytes
8626is computed.
8627
8628@smallexample
8629struct V @{ char buf1[10]; int b; char buf2[10]; @} var;
8630char *p = &var.buf1[1], *q = &var.b;
8631
8632/* Here the object p points to is var. */
8633assert (__builtin_object_size (p, 0) == sizeof (var) - 1);
8634/* The subobject p points to is var.buf1. */
8635assert (__builtin_object_size (p, 1) == sizeof (var.buf1) - 1);
8636/* The object q points to is var. */
8637assert (__builtin_object_size (q, 0)
6ccde948 8638 == (char *) (&var + 1) - (char *) &var.b);
10a0d495
JJ
8639/* The subobject q points to is var.b. */
8640assert (__builtin_object_size (q, 1) == sizeof (var.b));
8641@end smallexample
8642@end deftypefn
8643
8644There are built-in functions added for many common string operation
021efafc 8645functions, e.g., for @code{memcpy} @code{__builtin___memcpy_chk}
10a0d495
JJ
8646built-in is provided. This built-in has an additional last argument,
8647which is the number of bytes remaining in object the @var{dest}
8648argument points to or @code{(size_t) -1} if the size is not known.
8649
8650The built-in functions are optimized into the normal string functions
8651like @code{memcpy} if the last argument is @code{(size_t) -1} or if
8652it is known at compile time that the destination object will not
8653be overflown. If the compiler can determine at compile time the
8654object will be always overflown, it issues a warning.
8655
566fb011 8656The intended use can be e.g.@:
10a0d495
JJ
8657
8658@smallexample
8659#undef memcpy
8660#define bos0(dest) __builtin_object_size (dest, 0)
8661#define memcpy(dest, src, n) \
8662 __builtin___memcpy_chk (dest, src, n, bos0 (dest))
8663
8664char *volatile p;
8665char buf[10];
8666/* It is unknown what object p points to, so this is optimized
8667 into plain memcpy - no checking is possible. */
8668memcpy (p, "abcde", n);
8669/* Destination is known and length too. It is known at compile
8670 time there will be no overflow. */
8671memcpy (&buf[5], "abcde", 5);
8672/* Destination is known, but the length is not known at compile time.
8673 This will result in __memcpy_chk call that can check for overflow
566fb011 8674 at run time. */
10a0d495
JJ
8675memcpy (&buf[5], "abcde", n);
8676/* Destination is known and it is known at compile time there will
8677 be overflow. There will be a warning and __memcpy_chk call that
566fb011 8678 will abort the program at run time. */
10a0d495
JJ
8679memcpy (&buf[6], "abcde", 5);
8680@end smallexample
8681
8682Such built-in functions are provided for @code{memcpy}, @code{mempcpy},
8683@code{memmove}, @code{memset}, @code{strcpy}, @code{stpcpy}, @code{strncpy},
8684@code{strcat} and @code{strncat}.
8685
8686There are also checking built-in functions for formatted output functions.
8687@smallexample
8688int __builtin___sprintf_chk (char *s, int flag, size_t os, const char *fmt, ...);
8689int __builtin___snprintf_chk (char *s, size_t maxlen, int flag, size_t os,
6ccde948 8690 const char *fmt, ...);
10a0d495 8691int __builtin___vsprintf_chk (char *s, int flag, size_t os, const char *fmt,
6ccde948 8692 va_list ap);
10a0d495 8693int __builtin___vsnprintf_chk (char *s, size_t maxlen, int flag, size_t os,
6ccde948 8694 const char *fmt, va_list ap);
10a0d495
JJ
8695@end smallexample
8696
8697The added @var{flag} argument is passed unchanged to @code{__sprintf_chk}
021efafc 8698etc.@: functions and can contain implementation specific flags on what
10a0d495
JJ
8699additional security measures the checking function might take, such as
8700handling @code{%n} differently.
8701
8702The @var{os} argument is the object size @var{s} points to, like in the
a4d05547 8703other built-in functions. There is a small difference in the behavior
10a0d495
JJ
8704though, if @var{os} is @code{(size_t) -1}, the built-in functions are
8705optimized into the non-checking functions only if @var{flag} is 0, otherwise
8706the checking function is called with @var{os} argument set to
8707@code{(size_t) -1}.
8708
8709In addition to this, there are checking built-in functions
8710@code{__builtin___printf_chk}, @code{__builtin___vprintf_chk},
8711@code{__builtin___fprintf_chk} and @code{__builtin___vfprintf_chk}.
8712These have just one additional argument, @var{flag}, right before
8713format string @var{fmt}. If the compiler is able to optimize them to
358a3dbc
SL
8714@code{fputc} etc.@: functions, it does, otherwise the checking function
8715is called and the @var{flag} argument passed to it.
10a0d495 8716
d5e254e1
IE
8717@node Pointer Bounds Checker builtins
8718@section Pointer Bounds Checker Built-in Functions
8719@findex __builtin___bnd_set_ptr_bounds
8720@findex __builtin___bnd_narrow_ptr_bounds
8721@findex __builtin___bnd_copy_ptr_bounds
8722@findex __builtin___bnd_init_ptr_bounds
8723@findex __builtin___bnd_null_ptr_bounds
8724@findex __builtin___bnd_store_ptr_bounds
8725@findex __builtin___bnd_chk_ptr_lbounds
8726@findex __builtin___bnd_chk_ptr_ubounds
8727@findex __builtin___bnd_chk_ptr_bounds
8728@findex __builtin___bnd_get_ptr_lbound
8729@findex __builtin___bnd_get_ptr_ubound
8730
8731GCC provides a set of built-in functions to control Pointer Bounds Checker
8732instrumentation. Note that all Pointer Bounds Checker builtins are allowed
8733to use even if you compile with Pointer Bounds Checker off. The builtins
8734behavior may differ in such case as documented below.
8735
8736@deftypefn {Built-in Function} void * __builtin___bnd_set_ptr_bounds (const void * @var{q}, size_t @var{size})
8737
8738This built-in function returns a new pointer with the value of @var{q}, and
8739associate it with the bounds [@var{q}, @var{q}+@var{size}-1]. With Pointer
8740Bounds Checker off built-in function just returns the first argument.
8741
8742@smallexample
8743extern void *__wrap_malloc (size_t n)
8744@{
8745 void *p = (void *)__real_malloc (n);
8746 if (!p) return __builtin___bnd_null_ptr_bounds (p);
8747 return __builtin___bnd_set_ptr_bounds (p, n);
8748@}
8749@end smallexample
8750
8751@end deftypefn
8752
8753@deftypefn {Built-in Function} void * __builtin___bnd_narrow_ptr_bounds (const void * @var{p}, const void * @var{q}, size_t @var{size})
8754
8755This built-in function returns a new pointer with the value of @var{p}
8756and associate it with the narrowed bounds formed by the intersection
8757of bounds associated with @var{q} and the [@var{p}, @var{p} + @var{size} - 1].
8758With Pointer Bounds Checker off built-in function just returns the first
8759argument.
8760
8761@smallexample
8762void init_objects (object *objs, size_t size)
8763@{
8764 size_t i;
8765 /* Initialize objects one-by-one passing pointers with bounds of an object,
8766 not the full array of objects. */
8767 for (i = 0; i < size; i++)
8768 init_object (__builtin___bnd_narrow_ptr_bounds (objs + i, objs, sizeof(object)));
8769@}
8770@end smallexample
8771
8772@end deftypefn
8773
8774@deftypefn {Built-in Function} void * __builtin___bnd_copy_ptr_bounds (const void * @var{q}, const void * @var{r})
8775
8776This built-in function returns a new pointer with the value of @var{q},
8777and associate it with the bounds already associated with pointer @var{r}.
8778With Pointer Bounds Checker off built-in function just returns the first
8779argument.
8780
8781@smallexample
8782/* Here is a way to get pointer to object's field but
8783 still with the full object's bounds. */
8784int *field_ptr = __builtin___bnd_copy_ptr_bounds (&objptr->int_filed, objptr);
8785@end smallexample
8786
8787@end deftypefn
8788
8789@deftypefn {Built-in Function} void * __builtin___bnd_init_ptr_bounds (const void * @var{q})
8790
8791This built-in function returns a new pointer with the value of @var{q}, and
8792associate it with INIT (allowing full memory access) bounds. With Pointer
8793Bounds Checker off built-in function just returns the first argument.
8794
8795@end deftypefn
8796
8797@deftypefn {Built-in Function} void * __builtin___bnd_null_ptr_bounds (const void * @var{q})
8798
8799This built-in function returns a new pointer with the value of @var{q}, and
8800associate it with NULL (allowing no memory access) bounds. With Pointer
8801Bounds Checker off built-in function just returns the first argument.
8802
8803@end deftypefn
8804
8805@deftypefn {Built-in Function} void __builtin___bnd_store_ptr_bounds (const void ** @var{ptr_addr}, const void * @var{ptr_val})
8806
8807This built-in function stores the bounds associated with pointer @var{ptr_val}
8808and location @var{ptr_addr} into Bounds Table. This can be useful to propagate
8809bounds from legacy code without touching the associated pointer's memory when
8810pointers were copied as integers. With Pointer Bounds Checker off built-in
8811function call is ignored.
8812
8813@end deftypefn
8814
8815@deftypefn {Built-in Function} void __builtin___bnd_chk_ptr_lbounds (const void * @var{q})
8816
8817This built-in function checks if the pointer @var{q} is within the lower
8818bound of its associated bounds. With Pointer Bounds Checker off built-in
8819function call is ignored.
8820
8821@smallexample
8822extern void *__wrap_memset (void *dst, int c, size_t len)
8823@{
8824 if (len > 0)
8825 @{
8826 __builtin___bnd_chk_ptr_lbounds (dst);
8827 __builtin___bnd_chk_ptr_ubounds ((char *)dst + len - 1);
8828 __real_memset (dst, c, len);
8829 @}
8830 return dst;
8831@}
8832@end smallexample
8833
8834@end deftypefn
8835
8836@deftypefn {Built-in Function} void __builtin___bnd_chk_ptr_ubounds (const void * @var{q})
8837
8838This built-in function checks if the pointer @var{q} is within the upper
8839bound of its associated bounds. With Pointer Bounds Checker off built-in
8840function call is ignored.
8841
8842@end deftypefn
8843
8844@deftypefn {Built-in Function} void __builtin___bnd_chk_ptr_bounds (const void * @var{q}, size_t @var{size})
8845
8846This built-in function checks if [@var{q}, @var{q} + @var{size} - 1] is within
8847the lower and upper bounds associated with @var{q}. With Pointer Bounds Checker
8848off built-in function call is ignored.
8849
8850@smallexample
8851extern void *__wrap_memcpy (void *dst, const void *src, size_t n)
8852@{
8853 if (n > 0)
8854 @{
8855 __bnd_chk_ptr_bounds (dst, n);
8856 __bnd_chk_ptr_bounds (src, n);
8857 __real_memcpy (dst, src, n);
8858 @}
8859 return dst;
8860@}
8861@end smallexample
8862
8863@end deftypefn
8864
8865@deftypefn {Built-in Function} const void * __builtin___bnd_get_ptr_lbound (const void * @var{q})
8866
8867This built-in function returns the lower bound (which is a pointer) associated
8868with the pointer @var{q}. This is at least useful for debugging using printf.
8869With Pointer Bounds Checker off built-in function returns 0.
8870
8871@smallexample
8872void *lb = __builtin___bnd_get_ptr_lbound (q);
8873void *ub = __builtin___bnd_get_ptr_ubound (q);
8874printf ("q = %p lb(q) = %p ub(q) = %p", q, lb, ub);
8875@end smallexample
8876
8877@end deftypefn
8878
8879@deftypefn {Built-in Function} const void * __builtin___bnd_get_ptr_ubound (const void * @var{q})
8880
8881This built-in function returns the upper bound (which is a pointer) associated
8882with the pointer @var{q}. With Pointer Bounds Checker off built-in function
8883returns -1.
8884
8885@end deftypefn
8886
f0e56cd6
L
8887@node Cilk Plus Builtins
8888@section Cilk Plus C/C++ language extension Built-in Functions.
8889
8890GCC provides support for the following built-in reduction funtions if Cilk Plus
8891is enabled. Cilk Plus can be enabled using the @option{-fcilkplus} flag.
8892
8893@itemize @bullet
8894@item __sec_implicit_index
8895@item __sec_reduce
8896@item __sec_reduce_add
8897@item __sec_reduce_all_nonzero
8898@item __sec_reduce_all_zero
8899@item __sec_reduce_any_nonzero
8900@item __sec_reduce_any_zero
8901@item __sec_reduce_max
8902@item __sec_reduce_min
8903@item __sec_reduce_max_ind
8904@item __sec_reduce_min_ind
8905@item __sec_reduce_mul
8906@item __sec_reduce_mutating
8907@end itemize
8908
8909Further details and examples about these built-in functions are described
8910in the Cilk Plus language manual which can be found at
8911@uref{http://www.cilkplus.org}.
8912
185ebd6c 8913@node Other Builtins
18abab9f 8914@section Other Built-in Functions Provided by GCC
c771326b 8915@cindex built-in functions
3bf5906b 8916@findex __builtin_fpclassify
0c8d3c2b 8917@findex __builtin_isfinite
8a91c45b 8918@findex __builtin_isnormal
01702459
JM
8919@findex __builtin_isgreater
8920@findex __builtin_isgreaterequal
05f41289 8921@findex __builtin_isinf_sign
01702459
JM
8922@findex __builtin_isless
8923@findex __builtin_islessequal
8924@findex __builtin_islessgreater
8925@findex __builtin_isunordered
17684d46
RG
8926@findex __builtin_powi
8927@findex __builtin_powif
8928@findex __builtin_powil
98ff7c4d
KG
8929@findex _Exit
8930@findex _exit
01702459
JM
8931@findex abort
8932@findex abs
98ff7c4d
KG
8933@findex acos
8934@findex acosf
8935@findex acosh
8936@findex acoshf
8937@findex acoshl
8938@findex acosl
01702459 8939@findex alloca
98ff7c4d
KG
8940@findex asin
8941@findex asinf
8942@findex asinh
8943@findex asinhf
8944@findex asinhl
8945@findex asinl
29f523be 8946@findex atan
46847aa6
RS
8947@findex atan2
8948@findex atan2f
8949@findex atan2l
29f523be 8950@findex atanf
98ff7c4d
KG
8951@findex atanh
8952@findex atanhf
8953@findex atanhl
29f523be 8954@findex atanl
01702459
JM
8955@findex bcmp
8956@findex bzero
075ec276
RS
8957@findex cabs
8958@findex cabsf
8959@findex cabsl
11bf0eb0
KG
8960@findex cacos
8961@findex cacosf
8962@findex cacosh
8963@findex cacoshf
8964@findex cacoshl
8965@findex cacosl
1331d16f 8966@findex calloc
11bf0eb0
KG
8967@findex carg
8968@findex cargf
8969@findex cargl
8970@findex casin
8971@findex casinf
8972@findex casinh
8973@findex casinhf
8974@findex casinhl
8975@findex casinl
8976@findex catan
8977@findex catanf
8978@findex catanh
8979@findex catanhf
8980@findex catanhl
8981@findex catanl
98ff7c4d
KG
8982@findex cbrt
8983@findex cbrtf
8984@findex cbrtl
11bf0eb0
KG
8985@findex ccos
8986@findex ccosf
8987@findex ccosh
8988@findex ccoshf
8989@findex ccoshl
8990@findex ccosl
b052d8ee
RS
8991@findex ceil
8992@findex ceilf
8993@findex ceill
11bf0eb0
KG
8994@findex cexp
8995@findex cexpf
8996@findex cexpl
341e3d11
JM
8997@findex cimag
8998@findex cimagf
8999@findex cimagl
c3887ef2
PC
9000@findex clog
9001@findex clogf
9002@findex clogl
341e3d11
JM
9003@findex conj
9004@findex conjf
9005@findex conjl
98ff7c4d
KG
9006@findex copysign
9007@findex copysignf
9008@findex copysignl
01702459
JM
9009@findex cos
9010@findex cosf
98ff7c4d
KG
9011@findex cosh
9012@findex coshf
9013@findex coshl
01702459 9014@findex cosl
11bf0eb0
KG
9015@findex cpow
9016@findex cpowf
9017@findex cpowl
9018@findex cproj
9019@findex cprojf
9020@findex cprojl
341e3d11
JM
9021@findex creal
9022@findex crealf
9023@findex creall
11bf0eb0
KG
9024@findex csin
9025@findex csinf
9026@findex csinh
9027@findex csinhf
9028@findex csinhl
9029@findex csinl
9030@findex csqrt
9031@findex csqrtf
9032@findex csqrtl
9033@findex ctan
9034@findex ctanf
9035@findex ctanh
9036@findex ctanhf
9037@findex ctanhl
9038@findex ctanl
178b2b9f
RS
9039@findex dcgettext
9040@findex dgettext
98ff7c4d
KG
9041@findex drem
9042@findex dremf
9043@findex dreml
488f17e1
KG
9044@findex erf
9045@findex erfc
9046@findex erfcf
9047@findex erfcl
9048@findex erff
9049@findex erfl
01702459 9050@findex exit
e7b489c8 9051@findex exp
98ff7c4d
KG
9052@findex exp10
9053@findex exp10f
9054@findex exp10l
9055@findex exp2
9056@findex exp2f
9057@findex exp2l
e7b489c8
RS
9058@findex expf
9059@findex expl
98ff7c4d
KG
9060@findex expm1
9061@findex expm1f
9062@findex expm1l
01702459
JM
9063@findex fabs
9064@findex fabsf
9065@findex fabsl
98ff7c4d
KG
9066@findex fdim
9067@findex fdimf
9068@findex fdiml
01702459 9069@findex ffs
b052d8ee
RS
9070@findex floor
9071@findex floorf
9072@findex floorl
98ff7c4d
KG
9073@findex fma
9074@findex fmaf
9075@findex fmal
9076@findex fmax
9077@findex fmaxf
9078@findex fmaxl
9079@findex fmin
9080@findex fminf
9081@findex fminl
b052d8ee
RS
9082@findex fmod
9083@findex fmodf
9084@findex fmodl
18f988a0 9085@findex fprintf
b4c984fb 9086@findex fprintf_unlocked
01702459 9087@findex fputs
b4c984fb 9088@findex fputs_unlocked
a2a919aa
KG
9089@findex frexp
9090@findex frexpf
9091@findex frexpl
178b2b9f 9092@findex fscanf
488f17e1
KG
9093@findex gamma
9094@findex gammaf
9095@findex gammal
bf460eec
KG
9096@findex gamma_r
9097@findex gammaf_r
9098@findex gammal_r
178b2b9f 9099@findex gettext
98ff7c4d
KG
9100@findex hypot
9101@findex hypotf
9102@findex hypotl
9103@findex ilogb
9104@findex ilogbf
9105@findex ilogbl
e78f4a97 9106@findex imaxabs
c7b6c6cd 9107@findex index
740e5b6f
KG
9108@findex isalnum
9109@findex isalpha
9110@findex isascii
9111@findex isblank
9112@findex iscntrl
9113@findex isdigit
9114@findex isgraph
9115@findex islower
9116@findex isprint
9117@findex ispunct
9118@findex isspace
9119@findex isupper
ca4944e1
KG
9120@findex iswalnum
9121@findex iswalpha
9122@findex iswblank
9123@findex iswcntrl
9124@findex iswdigit
9125@findex iswgraph
9126@findex iswlower
9127@findex iswprint
9128@findex iswpunct
9129@findex iswspace
9130@findex iswupper
9131@findex iswxdigit
740e5b6f 9132@findex isxdigit
488f17e1
KG
9133@findex j0
9134@findex j0f
9135@findex j0l
9136@findex j1
9137@findex j1f
9138@findex j1l
9139@findex jn
9140@findex jnf
9141@findex jnl
01702459 9142@findex labs
98ff7c4d
KG
9143@findex ldexp
9144@findex ldexpf
9145@findex ldexpl
488f17e1
KG
9146@findex lgamma
9147@findex lgammaf
9148@findex lgammal
bf460eec
KG
9149@findex lgamma_r
9150@findex lgammaf_r
9151@findex lgammal_r
01702459 9152@findex llabs
98ff7c4d
KG
9153@findex llrint
9154@findex llrintf
9155@findex llrintl
9156@findex llround
9157@findex llroundf
9158@findex llroundl
e7b489c8 9159@findex log
98ff7c4d
KG
9160@findex log10
9161@findex log10f
9162@findex log10l
9163@findex log1p
9164@findex log1pf
9165@findex log1pl
9166@findex log2
9167@findex log2f
9168@findex log2l
9169@findex logb
9170@findex logbf
9171@findex logbl
e7b489c8
RS
9172@findex logf
9173@findex logl
98ff7c4d
KG
9174@findex lrint
9175@findex lrintf
9176@findex lrintl
9177@findex lround
9178@findex lroundf
9179@findex lroundl
1331d16f 9180@findex malloc
2a5fce6d 9181@findex memchr
01702459
JM
9182@findex memcmp
9183@findex memcpy
9cb65f92 9184@findex mempcpy
01702459 9185@findex memset
a2a919aa
KG
9186@findex modf
9187@findex modff
9188@findex modfl
b052d8ee
RS
9189@findex nearbyint
9190@findex nearbyintf
9191@findex nearbyintl
98ff7c4d
KG
9192@findex nextafter
9193@findex nextafterf
9194@findex nextafterl
9195@findex nexttoward
9196@findex nexttowardf
9197@findex nexttowardl
46847aa6 9198@findex pow
98ff7c4d
KG
9199@findex pow10
9200@findex pow10f
9201@findex pow10l
46847aa6
RS
9202@findex powf
9203@findex powl
01702459 9204@findex printf
b4c984fb 9205@findex printf_unlocked
08291658
RS
9206@findex putchar
9207@findex puts
98ff7c4d
KG
9208@findex remainder
9209@findex remainderf
9210@findex remainderl
a2a919aa
KG
9211@findex remquo
9212@findex remquof
9213@findex remquol
c7b6c6cd 9214@findex rindex
98ff7c4d
KG
9215@findex rint
9216@findex rintf
9217@findex rintl
b052d8ee
RS
9218@findex round
9219@findex roundf
9220@findex roundl
98ff7c4d
KG
9221@findex scalb
9222@findex scalbf
9223@findex scalbl
9224@findex scalbln
9225@findex scalblnf
9226@findex scalblnf
9227@findex scalbn
9228@findex scalbnf
9229@findex scanfnl
ef79730c
RS
9230@findex signbit
9231@findex signbitf
9232@findex signbitl
44aea9ac
JJ
9233@findex signbitd32
9234@findex signbitd64
9235@findex signbitd128
488f17e1
KG
9236@findex significand
9237@findex significandf
9238@findex significandl
01702459 9239@findex sin
a2a919aa
KG
9240@findex sincos
9241@findex sincosf
9242@findex sincosl
01702459 9243@findex sinf
98ff7c4d
KG
9244@findex sinh
9245@findex sinhf
9246@findex sinhl
01702459 9247@findex sinl
08291658
RS
9248@findex snprintf
9249@findex sprintf
01702459
JM
9250@findex sqrt
9251@findex sqrtf
9252@findex sqrtl
08291658 9253@findex sscanf
9cb65f92 9254@findex stpcpy
e905ac64
KG
9255@findex stpncpy
9256@findex strcasecmp
d118937d 9257@findex strcat
01702459
JM
9258@findex strchr
9259@findex strcmp
9260@findex strcpy
d118937d 9261@findex strcspn
1331d16f 9262@findex strdup
178b2b9f
RS
9263@findex strfmon
9264@findex strftime
01702459 9265@findex strlen
e905ac64 9266@findex strncasecmp
d118937d 9267@findex strncat
da9e9f08
KG
9268@findex strncmp
9269@findex strncpy
e905ac64 9270@findex strndup
01702459
JM
9271@findex strpbrk
9272@findex strrchr
d118937d 9273@findex strspn
01702459 9274@findex strstr
29f523be
RS
9275@findex tan
9276@findex tanf
98ff7c4d
KG
9277@findex tanh
9278@findex tanhf
9279@findex tanhl
29f523be 9280@findex tanl
488f17e1
KG
9281@findex tgamma
9282@findex tgammaf
9283@findex tgammal
740e5b6f
KG
9284@findex toascii
9285@findex tolower
9286@findex toupper
ca4944e1
KG
9287@findex towlower
9288@findex towupper
4977bab6
ZW
9289@findex trunc
9290@findex truncf
9291@findex truncl
178b2b9f
RS
9292@findex vfprintf
9293@findex vfscanf
08291658
RS
9294@findex vprintf
9295@findex vscanf
9296@findex vsnprintf
9297@findex vsprintf
9298@findex vsscanf
488f17e1
KG
9299@findex y0
9300@findex y0f
9301@findex y0l
9302@findex y1
9303@findex y1f
9304@findex y1l
9305@findex yn
9306@findex ynf
9307@findex ynl
185ebd6c 9308
f0523f02 9309GCC provides a large number of built-in functions other than the ones
185ebd6c 9310mentioned above. Some of these are for internal use in the processing
358a3dbc 9311of exceptions or variable-length argument lists and are not
185ebd6c
RH
9312documented here because they may change from time to time; we do not
9313recommend general use of these functions.
9314
9315The remaining functions are provided for optimization purposes.
9316
84330467 9317@opindex fno-builtin
9c34dbbf 9318GCC includes built-in versions of many of the functions in the standard
358a3dbc 9319C library. The versions prefixed with @code{__builtin_} are always
9c34dbbf 9320treated as having the same meaning as the C library function even if you
8a36672b 9321specify the @option{-fno-builtin} option. (@pxref{C Dialect Options})
9c34dbbf 9322Many of these functions are only optimized in certain cases; if they are
358a3dbc
SL
9323not optimized in a particular case, a call to the library function is
9324emitted.
01702459 9325
84330467
JM
9326@opindex ansi
9327@opindex std
2778d766 9328Outside strict ISO C mode (@option{-ansi}, @option{-std=c90},
48b0b196 9329@option{-std=c99} or @option{-std=c11}), the functions
98ff7c4d
KG
9330@code{_exit}, @code{alloca}, @code{bcmp}, @code{bzero},
9331@code{dcgettext}, @code{dgettext}, @code{dremf}, @code{dreml},
9332@code{drem}, @code{exp10f}, @code{exp10l}, @code{exp10}, @code{ffsll},
bf460eec
KG
9333@code{ffsl}, @code{ffs}, @code{fprintf_unlocked},
9334@code{fputs_unlocked}, @code{gammaf}, @code{gammal}, @code{gamma},
9335@code{gammaf_r}, @code{gammal_r}, @code{gamma_r}, @code{gettext},
740e5b6f
KG
9336@code{index}, @code{isascii}, @code{j0f}, @code{j0l}, @code{j0},
9337@code{j1f}, @code{j1l}, @code{j1}, @code{jnf}, @code{jnl}, @code{jn},
bf460eec
KG
9338@code{lgammaf_r}, @code{lgammal_r}, @code{lgamma_r}, @code{mempcpy},
9339@code{pow10f}, @code{pow10l}, @code{pow10}, @code{printf_unlocked},
9340@code{rindex}, @code{scalbf}, @code{scalbl}, @code{scalb},
9341@code{signbit}, @code{signbitf}, @code{signbitl}, @code{signbitd32},
9342@code{signbitd64}, @code{signbitd128}, @code{significandf},
9343@code{significandl}, @code{significand}, @code{sincosf},
9344@code{sincosl}, @code{sincos}, @code{stpcpy}, @code{stpncpy},
9345@code{strcasecmp}, @code{strdup}, @code{strfmon}, @code{strncasecmp},
9346@code{strndup}, @code{toascii}, @code{y0f}, @code{y0l}, @code{y0},
9347@code{y1f}, @code{y1l}, @code{y1}, @code{ynf}, @code{ynl} and
9348@code{yn}
1331d16f 9349may be handled as built-in functions.
b052d8ee 9350All these functions have corresponding versions
7e1542b9 9351prefixed with @code{__builtin_}, which may be used even in strict C90
9c34dbbf 9352mode.
01702459 9353
075ec276 9354The ISO C99 functions
98ff7c4d
KG
9355@code{_Exit}, @code{acoshf}, @code{acoshl}, @code{acosh}, @code{asinhf},
9356@code{asinhl}, @code{asinh}, @code{atanhf}, @code{atanhl}, @code{atanh},
11bf0eb0
KG
9357@code{cabsf}, @code{cabsl}, @code{cabs}, @code{cacosf}, @code{cacoshf},
9358@code{cacoshl}, @code{cacosh}, @code{cacosl}, @code{cacos},
9359@code{cargf}, @code{cargl}, @code{carg}, @code{casinf}, @code{casinhf},
9360@code{casinhl}, @code{casinh}, @code{casinl}, @code{casin},
9361@code{catanf}, @code{catanhf}, @code{catanhl}, @code{catanh},
9362@code{catanl}, @code{catan}, @code{cbrtf}, @code{cbrtl}, @code{cbrt},
9363@code{ccosf}, @code{ccoshf}, @code{ccoshl}, @code{ccosh}, @code{ccosl},
9364@code{ccos}, @code{cexpf}, @code{cexpl}, @code{cexp}, @code{cimagf},
c3887ef2
PC
9365@code{cimagl}, @code{cimag}, @code{clogf}, @code{clogl}, @code{clog},
9366@code{conjf}, @code{conjl}, @code{conj}, @code{copysignf}, @code{copysignl},
9367@code{copysign}, @code{cpowf}, @code{cpowl}, @code{cpow}, @code{cprojf},
9368@code{cprojl}, @code{cproj}, @code{crealf}, @code{creall}, @code{creal},
9369@code{csinf}, @code{csinhf}, @code{csinhl}, @code{csinh}, @code{csinl},
9370@code{csin}, @code{csqrtf}, @code{csqrtl}, @code{csqrt}, @code{ctanf},
9371@code{ctanhf}, @code{ctanhl}, @code{ctanh}, @code{ctanl}, @code{ctan},
9372@code{erfcf}, @code{erfcl}, @code{erfc}, @code{erff}, @code{erfl},
9373@code{erf}, @code{exp2f}, @code{exp2l}, @code{exp2}, @code{expm1f},
9374@code{expm1l}, @code{expm1}, @code{fdimf}, @code{fdiml}, @code{fdim},
9375@code{fmaf}, @code{fmal}, @code{fmaxf}, @code{fmaxl}, @code{fmax},
9376@code{fma}, @code{fminf}, @code{fminl}, @code{fmin}, @code{hypotf},
9377@code{hypotl}, @code{hypot}, @code{ilogbf}, @code{ilogbl}, @code{ilogb},
9378@code{imaxabs}, @code{isblank}, @code{iswblank}, @code{lgammaf},
9379@code{lgammal}, @code{lgamma}, @code{llabs}, @code{llrintf}, @code{llrintl},
ca4944e1
KG
9380@code{llrint}, @code{llroundf}, @code{llroundl}, @code{llround},
9381@code{log1pf}, @code{log1pl}, @code{log1p}, @code{log2f}, @code{log2l},
9382@code{log2}, @code{logbf}, @code{logbl}, @code{logb}, @code{lrintf},
9383@code{lrintl}, @code{lrint}, @code{lroundf}, @code{lroundl},
9384@code{lround}, @code{nearbyintf}, @code{nearbyintl}, @code{nearbyint},
740e5b6f
KG
9385@code{nextafterf}, @code{nextafterl}, @code{nextafter},
9386@code{nexttowardf}, @code{nexttowardl}, @code{nexttoward},
9387@code{remainderf}, @code{remainderl}, @code{remainder}, @code{remquof},
9388@code{remquol}, @code{remquo}, @code{rintf}, @code{rintl}, @code{rint},
9389@code{roundf}, @code{roundl}, @code{round}, @code{scalblnf},
9390@code{scalblnl}, @code{scalbln}, @code{scalbnf}, @code{scalbnl},
9391@code{scalbn}, @code{snprintf}, @code{tgammaf}, @code{tgammal},
9392@code{tgamma}, @code{truncf}, @code{truncl}, @code{trunc},
9393@code{vfscanf}, @code{vscanf}, @code{vsnprintf} and @code{vsscanf}
08291658 9394are handled as built-in functions
7e1542b9 9395except in strict ISO C90 mode (@option{-ansi} or @option{-std=c90}).
46847aa6 9396
98ff7c4d
KG
9397There are also built-in versions of the ISO C99 functions
9398@code{acosf}, @code{acosl}, @code{asinf}, @code{asinl}, @code{atan2f},
29f523be 9399@code{atan2l}, @code{atanf}, @code{atanl}, @code{ceilf}, @code{ceill},
98ff7c4d
KG
9400@code{cosf}, @code{coshf}, @code{coshl}, @code{cosl}, @code{expf},
9401@code{expl}, @code{fabsf}, @code{fabsl}, @code{floorf}, @code{floorl},
a2a919aa
KG
9402@code{fmodf}, @code{fmodl}, @code{frexpf}, @code{frexpl}, @code{ldexpf},
9403@code{ldexpl}, @code{log10f}, @code{log10l}, @code{logf}, @code{logl},
9404@code{modfl}, @code{modf}, @code{powf}, @code{powl}, @code{sinf},
9405@code{sinhf}, @code{sinhl}, @code{sinl}, @code{sqrtf}, @code{sqrtl},
9406@code{tanf}, @code{tanhf}, @code{tanhl} and @code{tanl}
46847aa6
RS
9407that are recognized in any mode since ISO C90 reserves these names for
9408the purpose to which ISO C99 puts them. All these functions have
9409corresponding versions prefixed with @code{__builtin_}.
9410
ca4944e1
KG
9411The ISO C94 functions
9412@code{iswalnum}, @code{iswalpha}, @code{iswcntrl}, @code{iswdigit},
9413@code{iswgraph}, @code{iswlower}, @code{iswprint}, @code{iswpunct},
9414@code{iswspace}, @code{iswupper}, @code{iswxdigit}, @code{towlower} and
9415@code{towupper}
9416are handled as built-in functions
7e1542b9 9417except in strict ISO C90 mode (@option{-ansi} or @option{-std=c90}).
ca4944e1 9418
98ff7c4d
KG
9419The ISO C90 functions
9420@code{abort}, @code{abs}, @code{acos}, @code{asin}, @code{atan2},
9421@code{atan}, @code{calloc}, @code{ceil}, @code{cosh}, @code{cos},
9422@code{exit}, @code{exp}, @code{fabs}, @code{floor}, @code{fmod},
740e5b6f
KG
9423@code{fprintf}, @code{fputs}, @code{frexp}, @code{fscanf},
9424@code{isalnum}, @code{isalpha}, @code{iscntrl}, @code{isdigit},
9425@code{isgraph}, @code{islower}, @code{isprint}, @code{ispunct},
9426@code{isspace}, @code{isupper}, @code{isxdigit}, @code{tolower},
9427@code{toupper}, @code{labs}, @code{ldexp}, @code{log10}, @code{log},
2a5fce6d
PC
9428@code{malloc}, @code{memchr}, @code{memcmp}, @code{memcpy},
9429@code{memset}, @code{modf}, @code{pow}, @code{printf}, @code{putchar},
9430@code{puts}, @code{scanf}, @code{sinh}, @code{sin}, @code{snprintf},
9431@code{sprintf}, @code{sqrt}, @code{sscanf}, @code{strcat},
9432@code{strchr}, @code{strcmp}, @code{strcpy}, @code{strcspn},
9433@code{strlen}, @code{strncat}, @code{strncmp}, @code{strncpy},
9434@code{strpbrk}, @code{strrchr}, @code{strspn}, @code{strstr},
9435@code{tanh}, @code{tan}, @code{vfprintf}, @code{vprintf} and @code{vsprintf}
08291658 9436are all recognized as built-in functions unless
46847aa6
RS
9437@option{-fno-builtin} is specified (or @option{-fno-builtin-@var{function}}
9438is specified for an individual function). All of these functions have
4977bab6 9439corresponding versions prefixed with @code{__builtin_}.
9c34dbbf 9440
6f46cb63 9441GCC provides built-in versions of the ISO C99 floating-point comparison
9c34dbbf
ZW
9442macros that avoid raising exceptions for unordered operands. They have
9443the same names as the standard macros ( @code{isgreater},
9444@code{isgreaterequal}, @code{isless}, @code{islessequal},
9445@code{islessgreater}, and @code{isunordered}) , with @code{__builtin_}
9446prefixed. We intend for a library implementor to be able to simply
9447@code{#define} each standard macro to its built-in equivalent.
3bf5906b
KG
9448In the same fashion, GCC provides @code{fpclassify}, @code{isfinite},
9449@code{isinf_sign} and @code{isnormal} built-ins used with
9450@code{__builtin_} prefixed. The @code{isinf} and @code{isnan}
18abab9f 9451built-in functions appear both with and without the @code{__builtin_} prefix.
185ebd6c 9452
ecbcf7b3
AH
9453@deftypefn {Built-in Function} int __builtin_types_compatible_p (@var{type1}, @var{type2})
9454
9455You can use the built-in function @code{__builtin_types_compatible_p} to
9456determine whether two types are the same.
9457
9458This built-in function returns 1 if the unqualified versions of the
9459types @var{type1} and @var{type2} (which are types, not expressions) are
9460compatible, 0 otherwise. The result of this built-in function can be
9461used in integer constant expressions.
9462
9463This built-in function ignores top level qualifiers (e.g., @code{const},
9464@code{volatile}). For example, @code{int} is equivalent to @code{const
9465int}.
9466
9467The type @code{int[]} and @code{int[5]} are compatible. On the other
9468hand, @code{int} and @code{char *} are not compatible, even if the size
9469of their types, on the particular architecture are the same. Also, the
9470amount of pointer indirection is taken into account when determining
9471similarity. Consequently, @code{short *} is not similar to
9472@code{short **}. Furthermore, two types that are typedefed are
9473considered compatible if their underlying types are compatible.
9474
bca63328
JM
9475An @code{enum} type is not considered to be compatible with another
9476@code{enum} type even if both are compatible with the same integer
9477type; this is what the C standard specifies.
9478For example, @code{enum @{foo, bar@}} is not similar to
ecbcf7b3
AH
9479@code{enum @{hot, dog@}}.
9480
358a3dbc 9481You typically use this function in code whose execution varies
ecbcf7b3
AH
9482depending on the arguments' types. For example:
9483
9484@smallexample
6e5bb5ad
JM
9485#define foo(x) \
9486 (@{ \
b7886f14 9487 typeof (x) tmp = (x); \
6e5bb5ad
JM
9488 if (__builtin_types_compatible_p (typeof (x), long double)) \
9489 tmp = foo_long_double (tmp); \
9490 else if (__builtin_types_compatible_p (typeof (x), double)) \
9491 tmp = foo_double (tmp); \
9492 else if (__builtin_types_compatible_p (typeof (x), float)) \
9493 tmp = foo_float (tmp); \
9494 else \
9495 abort (); \
9496 tmp; \
ecbcf7b3
AH
9497 @})
9498@end smallexample
9499
8a36672b 9500@emph{Note:} This construct is only available for C@.
ecbcf7b3
AH
9501
9502@end deftypefn
9503
9504@deftypefn {Built-in Function} @var{type} __builtin_choose_expr (@var{const_exp}, @var{exp1}, @var{exp2})
9505
9506You can use the built-in function @code{__builtin_choose_expr} to
9507evaluate code depending on the value of a constant expression. This
928c19bb 9508built-in function returns @var{exp1} if @var{const_exp}, which is an
6cea734d 9509integer constant expression, is nonzero. Otherwise it returns @var{exp2}.
ecbcf7b3
AH
9510
9511This built-in function is analogous to the @samp{? :} operator in C,
9512except that the expression returned has its type unaltered by promotion
9513rules. Also, the built-in function does not evaluate the expression
358a3dbc 9514that is not chosen. For example, if @var{const_exp} evaluates to true,
ecbcf7b3
AH
9515@var{exp2} is not evaluated even if it has side-effects.
9516
9517This built-in function can return an lvalue if the chosen argument is an
9518lvalue.
9519
9520If @var{exp1} is returned, the return type is the same as @var{exp1}'s
9521type. Similarly, if @var{exp2} is returned, its return type is the same
9522as @var{exp2}.
9523
9524Example:
9525
9526@smallexample
478c9e72
JJ
9527#define foo(x) \
9528 __builtin_choose_expr ( \
9529 __builtin_types_compatible_p (typeof (x), double), \
9530 foo_double (x), \
9531 __builtin_choose_expr ( \
9532 __builtin_types_compatible_p (typeof (x), float), \
9533 foo_float (x), \
9534 /* @r{The void expression results in a compile-time error} \
9535 @r{when assigning the result to something.} */ \
ecbcf7b3
AH
9536 (void)0))
9537@end smallexample
9538
8a36672b 9539@emph{Note:} This construct is only available for C@. Furthermore, the
ecbcf7b3
AH
9540unused expression (@var{exp1} or @var{exp2} depending on the value of
9541@var{const_exp}) may still generate syntax errors. This may change in
9542future revisions.
9543
9544@end deftypefn
9545
d4a83c10
JM
9546@deftypefn {Built-in Function} @var{type} __builtin_complex (@var{real}, @var{imag})
9547
9548The built-in function @code{__builtin_complex} is provided for use in
48b0b196 9549implementing the ISO C11 macros @code{CMPLXF}, @code{CMPLX} and
d4a83c10
JM
9550@code{CMPLXL}. @var{real} and @var{imag} must have the same type, a
9551real binary floating-point type, and the result has the corresponding
9552complex type with real and imaginary parts @var{real} and @var{imag}.
9553Unlike @samp{@var{real} + I * @var{imag}}, this works even when
9554infinities, NaNs and negative zeros are involved.
9555
9556@end deftypefn
9557
84330467
JM
9558@deftypefn {Built-in Function} int __builtin_constant_p (@var{exp})
9559You can use the built-in function @code{__builtin_constant_p} to
566fb011 9560determine if a value is known to be constant at compile time and hence
f0523f02 9561that GCC can perform constant-folding on expressions involving that
185ebd6c
RH
9562value. The argument of the function is the value to test. The function
9563returns the integer 1 if the argument is known to be a compile-time
9564constant and 0 if it is not known to be a compile-time constant. A
9565return of 0 does not indicate that the value is @emph{not} a constant,
f0523f02 9566but merely that GCC cannot prove it is a constant with the specified
84330467 9567value of the @option{-O} option.
185ebd6c 9568
358a3dbc
SL
9569You typically use this function in an embedded application where
9570memory is a critical resource. If you have some complex calculation,
185ebd6c
RH
9571you may want it to be folded if it involves constants, but need to call
9572a function if it does not. For example:
9573
4d390518 9574@smallexample
310668e8
JM
9575#define Scale_Value(X) \
9576 (__builtin_constant_p (X) \
9577 ? ((X) * SCALE + OFFSET) : Scale (X))
185ebd6c
RH
9578@end smallexample
9579
84330467 9580You may use this built-in function in either a macro or an inline
185ebd6c 9581function. However, if you use it in an inlined function and pass an
358a3dbc
SL
9582argument of the function as the argument to the built-in, GCC
9583never returns 1 when you call the inline function with a string constant
9584or compound literal (@pxref{Compound Literals}) and does not return 1
185ebd6c 9585when you pass a constant numeric value to the inline function unless you
84330467 9586specify the @option{-O} option.
13104975
ZW
9587
9588You may also use @code{__builtin_constant_p} in initializers for static
9589data. For instance, you can write
9590
9591@smallexample
79323c50 9592static const int table[] = @{
13104975 9593 __builtin_constant_p (EXPRESSION) ? (EXPRESSION) : -1,
0d893a63 9594 /* @r{@dots{}} */
79323c50 9595@};
13104975
ZW
9596@end smallexample
9597
9598@noindent
9599This is an acceptable initializer even if @var{EXPRESSION} is not a
928c19bb
JM
9600constant expression, including the case where
9601@code{__builtin_constant_p} returns 1 because @var{EXPRESSION} can be
358a3dbc
SL
9602folded to a constant but @var{EXPRESSION} contains operands that are
9603not otherwise permitted in a static initializer (for example,
928c19bb 9604@code{0 && foo ()}). GCC must be more conservative about evaluating the
13104975
ZW
9605built-in in this case, because it has no opportunity to perform
9606optimization.
9607
9608Previous versions of GCC did not accept this built-in in data
9609initializers. The earliest version where it is completely safe is
96103.0.1.
84330467 9611@end deftypefn
185ebd6c 9612
84330467
JM
9613@deftypefn {Built-in Function} long __builtin_expect (long @var{exp}, long @var{c})
9614@opindex fprofile-arcs
02f52e19 9615You may use @code{__builtin_expect} to provide the compiler with
994a57cd 9616branch prediction information. In general, you should prefer to
84330467 9617use actual profile feedback for this (@option{-fprofile-arcs}), as
994a57cd 9618programmers are notoriously bad at predicting how their programs
60b6e1f5 9619actually perform. However, there are applications in which this
994a57cd
RH
9620data is hard to collect.
9621
ef950eba
JH
9622The return value is the value of @var{exp}, which should be an integral
9623expression. The semantics of the built-in are that it is expected that
9624@var{exp} == @var{c}. For example:
994a57cd
RH
9625
9626@smallexample
9627if (__builtin_expect (x, 0))
9628 foo ();
9629@end smallexample
9630
9631@noindent
358a3dbc 9632indicates that we do not expect to call @code{foo}, since
994a57cd
RH
9633we expect @code{x} to be zero. Since you are limited to integral
9634expressions for @var{exp}, you should use constructions such as
9635
9636@smallexample
9637if (__builtin_expect (ptr != NULL, 1))
e2724fd2 9638 foo (*ptr);
994a57cd
RH
9639@end smallexample
9640
9641@noindent
9642when testing pointer or floating-point values.
84330467 9643@end deftypefn
994a57cd 9644
a18c20ec
AP
9645@deftypefn {Built-in Function} void __builtin_trap (void)
9646This function causes the program to exit abnormally. GCC implements
9647this function by using a target-dependent mechanism (such as
9648intentionally executing an illegal instruction) or by calling
9649@code{abort}. The mechanism used may vary from release to release so
9650you should not rely on any particular implementation.
9651@end deftypefn
9652
468059bc
DD
9653@deftypefn {Built-in Function} void __builtin_unreachable (void)
9654If control flow reaches the point of the @code{__builtin_unreachable},
9655the program is undefined. It is useful in situations where the
9656compiler cannot deduce the unreachability of the code.
9657
9658One such case is immediately following an @code{asm} statement that
358a3dbc 9659either never terminates, or one that transfers control elsewhere
468059bc 9660and never returns. In this example, without the
358a3dbc
SL
9661@code{__builtin_unreachable}, GCC issues a warning that control
9662reaches the end of a non-void function. It also generates code
468059bc
DD
9663to return after the @code{asm}.
9664
9665@smallexample
9666int f (int c, int v)
9667@{
9668 if (c)
9669 @{
9670 return v;
9671 @}
9672 else
9673 @{
9674 asm("jmp error_handler");
9675 __builtin_unreachable ();
9676 @}
9677@}
9678@end smallexample
9679
c513ecbf 9680@noindent
468059bc 9681Because the @code{asm} statement unconditionally transfers control out
358a3dbc 9682of the function, control never reaches the end of the function
468059bc
DD
9683body. The @code{__builtin_unreachable} is in fact unreachable and
9684communicates this fact to the compiler.
9685
9686Another use for @code{__builtin_unreachable} is following a call a
9687function that never returns but that is not declared
9688@code{__attribute__((noreturn))}, as in this example:
9689
9690@smallexample
9691void function_that_never_returns (void);
9692
9693int g (int c)
9694@{
9695 if (c)
9696 @{
9697 return 1;
9698 @}
9699 else
9700 @{
9701 function_that_never_returns ();
9702 __builtin_unreachable ();
9703 @}
9704@}
9705@end smallexample
9706
9707@end deftypefn
9708
45d439ac
JJ
9709@deftypefn {Built-in Function} void *__builtin_assume_aligned (const void *@var{exp}, size_t @var{align}, ...)
9710This function returns its first argument, and allows the compiler
9711to assume that the returned pointer is at least @var{align} bytes
9712aligned. This built-in can have either two or three arguments,
9713if it has three, the third argument should have integer type, and
566fb011 9714if it is nonzero means misalignment offset. For example:
45d439ac
JJ
9715
9716@smallexample
9717void *x = __builtin_assume_aligned (arg, 16);
9718@end smallexample
9719
c513ecbf 9720@noindent
6f46cb63
SL
9721means that the compiler can assume @code{x}, set to @code{arg}, is at least
972216-byte aligned, while:
45d439ac
JJ
9723
9724@smallexample
9725void *x = __builtin_assume_aligned (arg, 32, 8);
9726@end smallexample
9727
c513ecbf 9728@noindent
6f46cb63
SL
9729means that the compiler can assume for @code{x}, set to @code{arg}, that
9730@code{(char *) x - 8} is 32-byte aligned.
45d439ac
JJ
9731@end deftypefn
9732
3537a0cd
RG
9733@deftypefn {Built-in Function} int __builtin_LINE ()
9734This function is the equivalent to the preprocessor @code{__LINE__}
9735macro and returns the line number of the invocation of the built-in.
cfb1582c
JM
9736In a C++ default argument for a function @var{F}, it gets the line number of
9737the call to @var{F}.
3537a0cd
RG
9738@end deftypefn
9739
56a34230 9740@deftypefn {Built-in Function} {const char *} __builtin_FUNCTION ()
3537a0cd
RG
9741This function is the equivalent to the preprocessor @code{__FUNCTION__}
9742macro and returns the function name the invocation of the built-in is in.
9743@end deftypefn
9744
56a34230 9745@deftypefn {Built-in Function} {const char *} __builtin_FILE ()
3537a0cd
RG
9746This function is the equivalent to the preprocessor @code{__FILE__}
9747macro and returns the file name the invocation of the built-in is in.
cfb1582c
JM
9748In a C++ default argument for a function @var{F}, it gets the file name of
9749the call to @var{F}.
3537a0cd
RG
9750@end deftypefn
9751
677feb77
DD
9752@deftypefn {Built-in Function} void __builtin___clear_cache (char *@var{begin}, char *@var{end})
9753This function is used to flush the processor's instruction cache for
9754the region of memory between @var{begin} inclusive and @var{end}
9755exclusive. Some targets require that the instruction cache be
9756flushed, after modifying memory containing code, in order to obtain
9757deterministic behavior.
9758
9759If the target does not require instruction cache flushes,
9760@code{__builtin___clear_cache} has no effect. Otherwise either
9761instructions are emitted in-line to clear the instruction cache or a
9762call to the @code{__clear_cache} function in libgcc is made.
9763@end deftypefn
9764
3bca17dd 9765@deftypefn {Built-in Function} void __builtin_prefetch (const void *@var{addr}, ...)
a9ccbb60
JJ
9766This function is used to minimize cache-miss latency by moving data into
9767a cache before it is accessed.
9768You can insert calls to @code{__builtin_prefetch} into code for which
9769you know addresses of data in memory that is likely to be accessed soon.
358a3dbc 9770If the target supports them, data prefetch instructions are generated.
a9ccbb60
JJ
9771If the prefetch is done early enough before the access then the data will
9772be in the cache by the time it is accessed.
9773
9774The value of @var{addr} is the address of the memory to prefetch.
e83d297b 9775There are two optional arguments, @var{rw} and @var{locality}.
a9ccbb60 9776The value of @var{rw} is a compile-time constant one or zero; one
e83d297b
JJ
9777means that the prefetch is preparing for a write to the memory address
9778and zero, the default, means that the prefetch is preparing for a read.
a9ccbb60
JJ
9779The value @var{locality} must be a compile-time constant integer between
9780zero and three. A value of zero means that the data has no temporal
9781locality, so it need not be left in the cache after the access. A value
9782of three means that the data has a high degree of temporal locality and
9783should be left in all levels of cache possible. Values of one and two
e83d297b
JJ
9784mean, respectively, a low or moderate degree of temporal locality. The
9785default is three.
a9ccbb60
JJ
9786
9787@smallexample
9788for (i = 0; i < n; i++)
9789 @{
9790 a[i] = a[i] + b[i];
9791 __builtin_prefetch (&a[i+j], 1, 1);
9792 __builtin_prefetch (&b[i+j], 0, 1);
0d893a63 9793 /* @r{@dots{}} */
a9ccbb60
JJ
9794 @}
9795@end smallexample
9796
f282ffb3 9797Data prefetch does not generate faults if @var{addr} is invalid, but
a9ccbb60 9798the address expression itself must be valid. For example, a prefetch
358a3dbc
SL
9799of @code{p->next} does not fault if @code{p->next} is not a valid
9800address, but evaluation faults if @code{p} is not a valid address.
a9ccbb60
JJ
9801
9802If the target does not support data prefetch, the address expression
9803is evaluated if it includes side effects but no other code is generated
9804and GCC does not issue a warning.
9805@end deftypefn
9806
ab5e2615
RH
9807@deftypefn {Built-in Function} double __builtin_huge_val (void)
9808Returns a positive infinity, if supported by the floating-point format,
9809else @code{DBL_MAX}. This function is suitable for implementing the
9810ISO C macro @code{HUGE_VAL}.
9811@end deftypefn
9812
9813@deftypefn {Built-in Function} float __builtin_huge_valf (void)
9814Similar to @code{__builtin_huge_val}, except the return type is @code{float}.
9815@end deftypefn
9816
dad78426 9817@deftypefn {Built-in Function} {long double} __builtin_huge_vall (void)
ab5e2615
RH
9818Similar to @code{__builtin_huge_val}, except the return
9819type is @code{long double}.
9820@end deftypefn
9821
3bf5906b
KG
9822@deftypefn {Built-in Function} int __builtin_fpclassify (int, int, int, int, int, ...)
9823This built-in implements the C99 fpclassify functionality. The first
9824five int arguments should be the target library's notion of the
9825possible FP classes and are used for return values. They must be
9826constant values and they must appear in this order: @code{FP_NAN},
32101f99 9827@code{FP_INFINITE}, @code{FP_NORMAL}, @code{FP_SUBNORMAL} and
6f46cb63 9828@code{FP_ZERO}. The ellipsis is for exactly one floating-point value
3bf5906b
KG
9829to classify. GCC treats the last argument as type-generic, which
9830means it does not do default promotion from float to double.
9831@end deftypefn
9832
ab5e2615
RH
9833@deftypefn {Built-in Function} double __builtin_inf (void)
9834Similar to @code{__builtin_huge_val}, except a warning is generated
9835if the target floating-point format does not support infinities.
ab5e2615
RH
9836@end deftypefn
9837
9a8ce21f
JG
9838@deftypefn {Built-in Function} _Decimal32 __builtin_infd32 (void)
9839Similar to @code{__builtin_inf}, except the return type is @code{_Decimal32}.
9840@end deftypefn
9841
9842@deftypefn {Built-in Function} _Decimal64 __builtin_infd64 (void)
9843Similar to @code{__builtin_inf}, except the return type is @code{_Decimal64}.
9844@end deftypefn
9845
9846@deftypefn {Built-in Function} _Decimal128 __builtin_infd128 (void)
9847Similar to @code{__builtin_inf}, except the return type is @code{_Decimal128}.
9848@end deftypefn
9849
ab5e2615
RH
9850@deftypefn {Built-in Function} float __builtin_inff (void)
9851Similar to @code{__builtin_inf}, except the return type is @code{float}.
9c86fc0b 9852This function is suitable for implementing the ISO C99 macro @code{INFINITY}.
ab5e2615
RH
9853@end deftypefn
9854
dad78426 9855@deftypefn {Built-in Function} {long double} __builtin_infl (void)
ab5e2615
RH
9856Similar to @code{__builtin_inf}, except the return
9857type is @code{long double}.
9858@end deftypefn
9859
05f41289 9860@deftypefn {Built-in Function} int __builtin_isinf_sign (...)
1c5abb53
MG
9861Similar to @code{isinf}, except the return value is -1 for
9862an argument of @code{-Inf} and 1 for an argument of @code{+Inf}.
9863Note while the parameter list is an
6f46cb63 9864ellipsis, this function only accepts exactly one floating-point
05f41289
KG
9865argument. GCC treats this parameter as type-generic, which means it
9866does not do default promotion from float to double.
9867@end deftypefn
9868
1472e41c
RH
9869@deftypefn {Built-in Function} double __builtin_nan (const char *str)
9870This is an implementation of the ISO C99 function @code{nan}.
9871
9872Since ISO C99 defines this function in terms of @code{strtod}, which we
c0478a66 9873do not implement, a description of the parsing is in order. The string
1472e41c
RH
9874is parsed as by @code{strtol}; that is, the base is recognized by
9875leading @samp{0} or @samp{0x} prefixes. The number parsed is placed
9876in the significand such that the least significant bit of the number
daf2f129 9877is at the least significant bit of the significand. The number is
1472e41c 9878truncated to fit the significand field provided. The significand is
8a36672b 9879forced to be a quiet NaN@.
1472e41c 9880
a7d37464 9881This function, if given a string literal all of which would have been
bafa88c2 9882consumed by @code{strtol}, is evaluated early enough that it is considered a
a7d37464 9883compile-time constant.
1472e41c
RH
9884@end deftypefn
9885
9a8ce21f
JG
9886@deftypefn {Built-in Function} _Decimal32 __builtin_nand32 (const char *str)
9887Similar to @code{__builtin_nan}, except the return type is @code{_Decimal32}.
9888@end deftypefn
9889
9890@deftypefn {Built-in Function} _Decimal64 __builtin_nand64 (const char *str)
9891Similar to @code{__builtin_nan}, except the return type is @code{_Decimal64}.
9892@end deftypefn
9893
9894@deftypefn {Built-in Function} _Decimal128 __builtin_nand128 (const char *str)
9895Similar to @code{__builtin_nan}, except the return type is @code{_Decimal128}.
9896@end deftypefn
9897
1472e41c
RH
9898@deftypefn {Built-in Function} float __builtin_nanf (const char *str)
9899Similar to @code{__builtin_nan}, except the return type is @code{float}.
9900@end deftypefn
9901
dad78426 9902@deftypefn {Built-in Function} {long double} __builtin_nanl (const char *str)
1472e41c
RH
9903Similar to @code{__builtin_nan}, except the return type is @code{long double}.
9904@end deftypefn
9905
9906@deftypefn {Built-in Function} double __builtin_nans (const char *str)
daf2f129 9907Similar to @code{__builtin_nan}, except the significand is forced
8a36672b 9908to be a signaling NaN@. The @code{nans} function is proposed by
aaa67502 9909@uref{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n965.htm,,WG14 N965}.
1472e41c
RH
9910@end deftypefn
9911
9912@deftypefn {Built-in Function} float __builtin_nansf (const char *str)
9913Similar to @code{__builtin_nans}, except the return type is @code{float}.
9914@end deftypefn
9915
dad78426 9916@deftypefn {Built-in Function} {long double} __builtin_nansl (const char *str)
1472e41c
RH
9917Similar to @code{__builtin_nans}, except the return type is @code{long double}.
9918@end deftypefn
9919
324dc401 9920@deftypefn {Built-in Function} int __builtin_ffs (int x)
2928cd7a
RH
9921Returns one plus the index of the least significant 1-bit of @var{x}, or
9922if @var{x} is zero, returns zero.
9923@end deftypefn
9924
9925@deftypefn {Built-in Function} int __builtin_clz (unsigned int x)
9926Returns the number of leading 0-bits in @var{x}, starting at the most
9927significant bit position. If @var{x} is 0, the result is undefined.
9928@end deftypefn
9929
9930@deftypefn {Built-in Function} int __builtin_ctz (unsigned int x)
9931Returns the number of trailing 0-bits in @var{x}, starting at the least
9932significant bit position. If @var{x} is 0, the result is undefined.
9933@end deftypefn
9934
3801c801 9935@deftypefn {Built-in Function} int __builtin_clrsb (int x)
566fb011 9936Returns the number of leading redundant sign bits in @var{x}, i.e.@: the
c417597c 9937number of bits following the most significant bit that are identical
3801c801
BS
9938to it. There are no special cases for 0 or other values.
9939@end deftypefn
9940
2928cd7a
RH
9941@deftypefn {Built-in Function} int __builtin_popcount (unsigned int x)
9942Returns the number of 1-bits in @var{x}.
9943@end deftypefn
9944
9945@deftypefn {Built-in Function} int __builtin_parity (unsigned int x)
8a36672b 9946Returns the parity of @var{x}, i.e.@: the number of 1-bits in @var{x}
2928cd7a
RH
9947modulo 2.
9948@end deftypefn
9949
324dc401 9950@deftypefn {Built-in Function} int __builtin_ffsl (long)
2928cd7a 9951Similar to @code{__builtin_ffs}, except the argument type is
324dc401 9952@code{long}.
2928cd7a
RH
9953@end deftypefn
9954
9955@deftypefn {Built-in Function} int __builtin_clzl (unsigned long)
9956Similar to @code{__builtin_clz}, except the argument type is
9957@code{unsigned long}.
9958@end deftypefn
9959
9960@deftypefn {Built-in Function} int __builtin_ctzl (unsigned long)
9961Similar to @code{__builtin_ctz}, except the argument type is
9962@code{unsigned long}.
9963@end deftypefn
9964
3801c801
BS
9965@deftypefn {Built-in Function} int __builtin_clrsbl (long)
9966Similar to @code{__builtin_clrsb}, except the argument type is
9967@code{long}.
9968@end deftypefn
9969
2928cd7a
RH
9970@deftypefn {Built-in Function} int __builtin_popcountl (unsigned long)
9971Similar to @code{__builtin_popcount}, except the argument type is
9972@code{unsigned long}.
9973@end deftypefn
9974
9975@deftypefn {Built-in Function} int __builtin_parityl (unsigned long)
9976Similar to @code{__builtin_parity}, except the argument type is
9977@code{unsigned long}.
9978@end deftypefn
9979
324dc401 9980@deftypefn {Built-in Function} int __builtin_ffsll (long long)
2928cd7a 9981Similar to @code{__builtin_ffs}, except the argument type is
324dc401 9982@code{long long}.
2928cd7a
RH
9983@end deftypefn
9984
9985@deftypefn {Built-in Function} int __builtin_clzll (unsigned long long)
9986Similar to @code{__builtin_clz}, except the argument type is
9987@code{unsigned long long}.
9988@end deftypefn
9989
9990@deftypefn {Built-in Function} int __builtin_ctzll (unsigned long long)
9991Similar to @code{__builtin_ctz}, except the argument type is
9992@code{unsigned long long}.
9993@end deftypefn
9994
3801c801
BS
9995@deftypefn {Built-in Function} int __builtin_clrsbll (long long)
9996Similar to @code{__builtin_clrsb}, except the argument type is
9997@code{long long}.
9998@end deftypefn
9999
2928cd7a
RH
10000@deftypefn {Built-in Function} int __builtin_popcountll (unsigned long long)
10001Similar to @code{__builtin_popcount}, except the argument type is
10002@code{unsigned long long}.
10003@end deftypefn
10004
10005@deftypefn {Built-in Function} int __builtin_parityll (unsigned long long)
10006Similar to @code{__builtin_parity}, except the argument type is
10007@code{unsigned long long}.
10008@end deftypefn
10009
17684d46
RG
10010@deftypefn {Built-in Function} double __builtin_powi (double, int)
10011Returns the first argument raised to the power of the second. Unlike the
10012@code{pow} function no guarantees about precision and rounding are made.
10013@end deftypefn
10014
10015@deftypefn {Built-in Function} float __builtin_powif (float, int)
10016Similar to @code{__builtin_powi}, except the argument and return types
10017are @code{float}.
10018@end deftypefn
10019
10020@deftypefn {Built-in Function} {long double} __builtin_powil (long double, int)
10021Similar to @code{__builtin_powi}, except the argument and return types
10022are @code{long double}.
10023@end deftypefn
10024
a104e60b 10025@deftypefn {Built-in Function} uint16_t __builtin_bswap16 (uint16_t x)
167fa32c 10026Returns @var{x} with the order of the bytes reversed; for example,
ac868f29 10027@code{0xaabb} becomes @code{0xbbaa}. Byte here always means
167fa32c
EC
10028exactly 8 bits.
10029@end deftypefn
10030
a104e60b 10031@deftypefn {Built-in Function} uint32_t __builtin_bswap32 (uint32_t x)
ac868f29 10032Similar to @code{__builtin_bswap16}, except the argument and return types
6f46cb63 10033are 32 bit.
ac868f29
EB
10034@end deftypefn
10035
a104e60b 10036@deftypefn {Built-in Function} uint64_t __builtin_bswap64 (uint64_t x)
167fa32c 10037Similar to @code{__builtin_bswap32}, except the argument and return types
6f46cb63 10038are 64 bit.
167fa32c 10039@end deftypefn
2928cd7a 10040
0975678f
JM
10041@node Target Builtins
10042@section Built-in Functions Specific to Particular Target Machines
10043
10044On some target machines, GCC supports many built-in functions specific
10045to those machines. Generally these generate calls to specific machine
10046instructions, but allow the compiler to schedule those calls.
10047
10048@menu
aa87aced 10049* AArch64 Built-in Functions::
6d8fd7bb 10050* Alpha Built-in Functions::
e430824f 10051* Altera Nios II Built-in Functions::
5d5f6720
JR
10052* ARC Built-in Functions::
10053* ARC SIMD Built-in Functions::
88f77cba 10054* ARM iWMMXt Built-in Functions::
3f155273 10055* ARM C Language Extensions (ACLE)::
f10743d3 10056* ARM Floating Point Status and Control Intrinsics::
43ea6502 10057* AVR Built-in Functions::
161c21b6 10058* Blackfin Built-in Functions::
c3ee0579 10059* FR-V Built-in Functions::
0975678f 10060* X86 Built-in Functions::
4323afa0 10061* X86 transactional memory intrinsics::
118ea793 10062* MIPS DSP Built-in Functions::
d840bfd3 10063* MIPS Paired-Single Support::
93581857 10064* MIPS Loongson Built-in Functions::
4d210b07 10065* Other MIPS Built-in Functions::
cad055a4 10066* MSP430 Built-in Functions::
9304f876 10067* NDS32 Built-in Functions::
358da97e 10068* picoChip Built-in Functions::
0efbf084 10069* PowerPC Built-in Functions::
29e6733c 10070* PowerPC AltiVec/VSX Built-in Functions::
af7d1b7d 10071* PowerPC Hardware Transactional Memory Built-in Functions::
65a324b4 10072* RX Built-in Functions::
5a3fe9b6 10073* S/390 System z Built-in Functions::
be06a8b0 10074* SH Built-in Functions::
c5145ceb 10075* SPARC VIS Built-in Functions::
85d9c13c 10076* SPU Built-in Functions::
bcead286 10077* TI C6X Built-in Functions::
dd552284
WL
10078* TILE-Gx Built-in Functions::
10079* TILEPro Built-in Functions::
0975678f
JM
10080@end menu
10081
aa87aced
KV
10082@node AArch64 Built-in Functions
10083@subsection AArch64 Built-in Functions
10084
10085These built-in functions are available for the AArch64 family of
10086processors.
10087@smallexample
10088unsigned int __builtin_aarch64_get_fpcr ()
10089void __builtin_aarch64_set_fpcr (unsigned int)
10090unsigned int __builtin_aarch64_get_fpsr ()
10091void __builtin_aarch64_set_fpsr (unsigned int)
10092@end smallexample
10093
6d8fd7bb
RH
10094@node Alpha Built-in Functions
10095@subsection Alpha Built-in Functions
10096
10097These built-in functions are available for the Alpha family of
10098processors, depending on the command-line switches used.
10099
95b1627e 10100The following built-in functions are always available. They
6d8fd7bb
RH
10101all generate the machine instruction that is part of the name.
10102
3ab51846 10103@smallexample
6d8fd7bb
RH
10104long __builtin_alpha_implver (void)
10105long __builtin_alpha_rpcc (void)
10106long __builtin_alpha_amask (long)
10107long __builtin_alpha_cmpbge (long, long)
c4b50f1a
RH
10108long __builtin_alpha_extbl (long, long)
10109long __builtin_alpha_extwl (long, long)
10110long __builtin_alpha_extll (long, long)
6d8fd7bb 10111long __builtin_alpha_extql (long, long)
c4b50f1a
RH
10112long __builtin_alpha_extwh (long, long)
10113long __builtin_alpha_extlh (long, long)
6d8fd7bb 10114long __builtin_alpha_extqh (long, long)
c4b50f1a
RH
10115long __builtin_alpha_insbl (long, long)
10116long __builtin_alpha_inswl (long, long)
10117long __builtin_alpha_insll (long, long)
10118long __builtin_alpha_insql (long, long)
10119long __builtin_alpha_inswh (long, long)
10120long __builtin_alpha_inslh (long, long)
10121long __builtin_alpha_insqh (long, long)
10122long __builtin_alpha_mskbl (long, long)
10123long __builtin_alpha_mskwl (long, long)
10124long __builtin_alpha_mskll (long, long)
10125long __builtin_alpha_mskql (long, long)
10126long __builtin_alpha_mskwh (long, long)
10127long __builtin_alpha_msklh (long, long)
10128long __builtin_alpha_mskqh (long, long)
10129long __builtin_alpha_umulh (long, long)
6d8fd7bb
RH
10130long __builtin_alpha_zap (long, long)
10131long __builtin_alpha_zapnot (long, long)
3ab51846 10132@end smallexample
6d8fd7bb
RH
10133
10134The following built-in functions are always with @option{-mmax}
10135or @option{-mcpu=@var{cpu}} where @var{cpu} is @code{pca56} or
10136later. They all generate the machine instruction that is part
10137of the name.
10138
3ab51846 10139@smallexample
6d8fd7bb
RH
10140long __builtin_alpha_pklb (long)
10141long __builtin_alpha_pkwb (long)
10142long __builtin_alpha_unpkbl (long)
10143long __builtin_alpha_unpkbw (long)
10144long __builtin_alpha_minub8 (long, long)
10145long __builtin_alpha_minsb8 (long, long)
10146long __builtin_alpha_minuw4 (long, long)
10147long __builtin_alpha_minsw4 (long, long)
10148long __builtin_alpha_maxub8 (long, long)
10149long __builtin_alpha_maxsb8 (long, long)
10150long __builtin_alpha_maxuw4 (long, long)
10151long __builtin_alpha_maxsw4 (long, long)
10152long __builtin_alpha_perr (long, long)
3ab51846 10153@end smallexample
6d8fd7bb 10154
c4b50f1a
RH
10155The following built-in functions are always with @option{-mcix}
10156or @option{-mcpu=@var{cpu}} where @var{cpu} is @code{ev67} or
10157later. They all generate the machine instruction that is part
10158of the name.
10159
3ab51846 10160@smallexample
c4b50f1a
RH
10161long __builtin_alpha_cttz (long)
10162long __builtin_alpha_ctlz (long)
10163long __builtin_alpha_ctpop (long)
3ab51846 10164@end smallexample
c4b50f1a 10165
18abab9f 10166The following built-in functions are available on systems that use the OSF/1
116b7a5e
RH
10167PALcode. Normally they invoke the @code{rduniq} and @code{wruniq}
10168PAL calls, but when invoked with @option{-mtls-kernel}, they invoke
10169@code{rdval} and @code{wrval}.
10170
3ab51846 10171@smallexample
116b7a5e
RH
10172void *__builtin_thread_pointer (void)
10173void __builtin_set_thread_pointer (void *)
3ab51846 10174@end smallexample
116b7a5e 10175
e430824f
CLT
10176@node Altera Nios II Built-in Functions
10177@subsection Altera Nios II Built-in Functions
10178
10179These built-in functions are available for the Altera Nios II
10180family of processors.
10181
10182The following built-in functions are always available. They
10183all generate the machine instruction that is part of the name.
10184
10185@example
10186int __builtin_ldbio (volatile const void *)
10187int __builtin_ldbuio (volatile const void *)
10188int __builtin_ldhio (volatile const void *)
10189int __builtin_ldhuio (volatile const void *)
10190int __builtin_ldwio (volatile const void *)
10191void __builtin_stbio (volatile void *, int)
10192void __builtin_sthio (volatile void *, int)
10193void __builtin_stwio (volatile void *, int)
10194void __builtin_sync (void)
10195int __builtin_rdctl (int)
10196void __builtin_wrctl (int, int)
10197@end example
10198
10199The following built-in functions are always available. They
10200all generate a Nios II Custom Instruction. The name of the
10201function represents the types that the function takes and
10202returns. The letter before the @code{n} is the return type
10203or void if absent. The @code{n} represents the first parameter
10204to all the custom instructions, the custom instruction number.
10205The two letters after the @code{n} represent the up to two
10206parameters to the function.
10207
10208The letters represent the following data types:
10209@table @code
10210@item <no letter>
10211@code{void} for return type and no parameter for parameter types.
10212
10213@item i
10214@code{int} for return type and parameter type
10215
10216@item f
10217@code{float} for return type and parameter type
10218
10219@item p
10220@code{void *} for return type and parameter type
10221
10222@end table
10223
10224And the function names are:
10225@example
10226void __builtin_custom_n (void)
10227void __builtin_custom_ni (int)
10228void __builtin_custom_nf (float)
10229void __builtin_custom_np (void *)
10230void __builtin_custom_nii (int, int)
10231void __builtin_custom_nif (int, float)
10232void __builtin_custom_nip (int, void *)
10233void __builtin_custom_nfi (float, int)
10234void __builtin_custom_nff (float, float)
10235void __builtin_custom_nfp (float, void *)
10236void __builtin_custom_npi (void *, int)
10237void __builtin_custom_npf (void *, float)
10238void __builtin_custom_npp (void *, void *)
10239int __builtin_custom_in (void)
10240int __builtin_custom_ini (int)
10241int __builtin_custom_inf (float)
10242int __builtin_custom_inp (void *)
10243int __builtin_custom_inii (int, int)
10244int __builtin_custom_inif (int, float)
10245int __builtin_custom_inip (int, void *)
10246int __builtin_custom_infi (float, int)
10247int __builtin_custom_inff (float, float)
10248int __builtin_custom_infp (float, void *)
10249int __builtin_custom_inpi (void *, int)
10250int __builtin_custom_inpf (void *, float)
10251int __builtin_custom_inpp (void *, void *)
10252float __builtin_custom_fn (void)
10253float __builtin_custom_fni (int)
10254float __builtin_custom_fnf (float)
10255float __builtin_custom_fnp (void *)
10256float __builtin_custom_fnii (int, int)
10257float __builtin_custom_fnif (int, float)
10258float __builtin_custom_fnip (int, void *)
10259float __builtin_custom_fnfi (float, int)
10260float __builtin_custom_fnff (float, float)
10261float __builtin_custom_fnfp (float, void *)
10262float __builtin_custom_fnpi (void *, int)
10263float __builtin_custom_fnpf (void *, float)
10264float __builtin_custom_fnpp (void *, void *)
10265void * __builtin_custom_pn (void)
10266void * __builtin_custom_pni (int)
10267void * __builtin_custom_pnf (float)
10268void * __builtin_custom_pnp (void *)
10269void * __builtin_custom_pnii (int, int)
10270void * __builtin_custom_pnif (int, float)
10271void * __builtin_custom_pnip (int, void *)
10272void * __builtin_custom_pnfi (float, int)
10273void * __builtin_custom_pnff (float, float)
10274void * __builtin_custom_pnfp (float, void *)
10275void * __builtin_custom_pnpi (void *, int)
10276void * __builtin_custom_pnpf (void *, float)
10277void * __builtin_custom_pnpp (void *, void *)
10278@end example
10279
5d5f6720
JR
10280@node ARC Built-in Functions
10281@subsection ARC Built-in Functions
10282
10283The following built-in functions are provided for ARC targets. The
10284built-ins generate the corresponding assembly instructions. In the
10285examples given below, the generated code often requires an operand or
10286result to be in a register. Where necessary further code will be
10287generated to ensure this is true, but for brevity this is not
10288described in each case.
10289
10290@emph{Note:} Using a built-in to generate an instruction not supported
10291by a target may cause problems. At present the compiler is not
10292guaranteed to detect such misuse, and as a result an internal compiler
10293error may be generated.
10294
10295@deftypefn {Built-in Function} int __builtin_arc_aligned (void *@var{val}, int @var{alignval})
10296Return 1 if @var{val} is known to have the byte alignment given
10297by @var{alignval}, otherwise return 0.
10298Note that this is different from
10299@smallexample
10300__alignof__(*(char *)@var{val}) >= alignval
10301@end smallexample
0ccbc132 10302because __alignof__ sees only the type of the dereference, whereas
5d5f6720
JR
10303__builtin_arc_align uses alignment information from the pointer
10304as well as from the pointed-to type.
10305The information available will depend on optimization level.
10306@end deftypefn
10307
10308@deftypefn {Built-in Function} void __builtin_arc_brk (void)
10309Generates
10310@example
10311brk
10312@end example
10313@end deftypefn
10314
10315@deftypefn {Built-in Function} {unsigned int} __builtin_arc_core_read (unsigned int @var{regno})
10316The operand is the number of a register to be read. Generates:
10317@example
10318mov @var{dest}, r@var{regno}
10319@end example
10320where the value in @var{dest} will be the result returned from the
10321built-in.
10322@end deftypefn
10323
10324@deftypefn {Built-in Function} void __builtin_arc_core_write (unsigned int @var{regno}, unsigned int @var{val})
10325The first operand is the number of a register to be written, the
10326second operand is a compile time constant to write into that
10327register. Generates:
10328@example
10329mov r@var{regno}, @var{val}
10330@end example
10331@end deftypefn
10332
10333@deftypefn {Built-in Function} int __builtin_arc_divaw (int @var{a}, int @var{b})
10334Only available if either @option{-mcpu=ARC700} or @option{-meA} is set.
10335Generates:
10336@example
10337divaw @var{dest}, @var{a}, @var{b}
10338@end example
10339where the value in @var{dest} will be the result returned from the
10340built-in.
10341@end deftypefn
10342
10343@deftypefn {Built-in Function} void __builtin_arc_flag (unsigned int @var{a})
10344Generates
10345@example
10346flag @var{a}
10347@end example
10348@end deftypefn
10349
10350@deftypefn {Built-in Function} {unsigned int} __builtin_arc_lr (unsigned int @var{auxr})
10351The operand, @var{auxv}, is the address of an auxiliary register and
10352must be a compile time constant. Generates:
10353@example
10354lr @var{dest}, [@var{auxr}]
10355@end example
10356Where the value in @var{dest} will be the result returned from the
10357built-in.
10358@end deftypefn
10359
10360@deftypefn {Built-in Function} void __builtin_arc_mul64 (int @var{a}, int @var{b})
10361Only available with @option{-mmul64}. Generates:
10362@example
10363mul64 @var{a}, @var{b}
10364@end example
10365@end deftypefn
10366
10367@deftypefn {Built-in Function} void __builtin_arc_mulu64 (unsigned int @var{a}, unsigned int @var{b})
10368Only available with @option{-mmul64}. Generates:
10369@example
10370mulu64 @var{a}, @var{b}
10371@end example
10372@end deftypefn
10373
10374@deftypefn {Built-in Function} void __builtin_arc_nop (void)
10375Generates:
10376@example
10377nop
10378@end example
10379@end deftypefn
10380
10381@deftypefn {Built-in Function} int __builtin_arc_norm (int @var{src})
10382Only valid if the @samp{norm} instruction is available through the
10383@option{-mnorm} option or by default with @option{-mcpu=ARC700}.
10384Generates:
10385@example
10386norm @var{dest}, @var{src}
10387@end example
10388Where the value in @var{dest} will be the result returned from the
10389built-in.
10390@end deftypefn
10391
10392@deftypefn {Built-in Function} {short int} __builtin_arc_normw (short int @var{src})
10393Only valid if the @samp{normw} instruction is available through the
10394@option{-mnorm} option or by default with @option{-mcpu=ARC700}.
10395Generates:
10396@example
10397normw @var{dest}, @var{src}
10398@end example
10399Where the value in @var{dest} will be the result returned from the
10400built-in.
10401@end deftypefn
10402
10403@deftypefn {Built-in Function} void __builtin_arc_rtie (void)
10404Generates:
10405@example
10406rtie
10407@end example
10408@end deftypefn
10409
10410@deftypefn {Built-in Function} void __builtin_arc_sleep (int @var{a}
10411Generates:
10412@example
10413sleep @var{a}
10414@end example
10415@end deftypefn
10416
10417@deftypefn {Built-in Function} void __builtin_arc_sr (unsigned int @var{auxr}, unsigned int @var{val})
10418The first argument, @var{auxv}, is the address of an auxiliary
10419register, the second argument, @var{val}, is a compile time constant
10420to be written to the register. Generates:
10421@example
10422sr @var{auxr}, [@var{val}]
10423@end example
10424@end deftypefn
10425
10426@deftypefn {Built-in Function} int __builtin_arc_swap (int @var{src})
10427Only valid with @option{-mswap}. Generates:
10428@example
10429swap @var{dest}, @var{src}
10430@end example
10431Where the value in @var{dest} will be the result returned from the
10432built-in.
10433@end deftypefn
10434
10435@deftypefn {Built-in Function} void __builtin_arc_swi (void)
10436Generates:
10437@example
10438swi
10439@end example
10440@end deftypefn
10441
10442@deftypefn {Built-in Function} void __builtin_arc_sync (void)
10443Only available with @option{-mcpu=ARC700}. Generates:
10444@example
10445sync
10446@end example
10447@end deftypefn
10448
10449@deftypefn {Built-in Function} void __builtin_arc_trap_s (unsigned int @var{c})
10450Only available with @option{-mcpu=ARC700}. Generates:
10451@example
10452trap_s @var{c}
10453@end example
10454@end deftypefn
10455
10456@deftypefn {Built-in Function} void __builtin_arc_unimp_s (void)
10457Only available with @option{-mcpu=ARC700}. Generates:
10458@example
10459unimp_s
10460@end example
10461@end deftypefn
10462
10463The instructions generated by the following builtins are not
10464considered as candidates for scheduling. They are not moved around by
10465the compiler during scheduling, and thus can be expected to appear
10466where they are put in the C code:
10467@example
10468__builtin_arc_brk()
10469__builtin_arc_core_read()
10470__builtin_arc_core_write()
10471__builtin_arc_flag()
10472__builtin_arc_lr()
10473__builtin_arc_sleep()
10474__builtin_arc_sr()
10475__builtin_arc_swi()
10476@end example
10477
10478@node ARC SIMD Built-in Functions
10479@subsection ARC SIMD Built-in Functions
10480
10481SIMD builtins provided by the compiler can be used to generate the
10482vector instructions. This section describes the available builtins
10483and their usage in programs. With the @option{-msimd} option, the
10484compiler provides 128-bit vector types, which can be specified using
10485the @code{vector_size} attribute. The header file @file{arc-simd.h}
10486can be included to use the following predefined types:
10487@example
10488typedef int __v4si __attribute__((vector_size(16)));
10489typedef short __v8hi __attribute__((vector_size(16)));
10490@end example
10491
10492These types can be used to define 128-bit variables. The built-in
10493functions listed in the following section can be used on these
10494variables to generate the vector operations.
10495
10496For all builtins, @code{__builtin_arc_@var{someinsn}}, the header file
10497@file{arc-simd.h} also provides equivalent macros called
10498@code{_@var{someinsn}} that can be used for programming ease and
10499improved readability. The following macros for DMA control are also
10500provided:
10501@example
10502#define _setup_dma_in_channel_reg _vdiwr
10503#define _setup_dma_out_channel_reg _vdowr
10504@end example
10505
10506The following is a complete list of all the SIMD built-ins provided
10507for ARC, grouped by calling signature.
10508
10509The following take two @code{__v8hi} arguments and return a
10510@code{__v8hi} result:
10511@example
10512__v8hi __builtin_arc_vaddaw (__v8hi, __v8hi)
10513__v8hi __builtin_arc_vaddw (__v8hi, __v8hi)
10514__v8hi __builtin_arc_vand (__v8hi, __v8hi)
10515__v8hi __builtin_arc_vandaw (__v8hi, __v8hi)
10516__v8hi __builtin_arc_vavb (__v8hi, __v8hi)
10517__v8hi __builtin_arc_vavrb (__v8hi, __v8hi)
10518__v8hi __builtin_arc_vbic (__v8hi, __v8hi)
10519__v8hi __builtin_arc_vbicaw (__v8hi, __v8hi)
10520__v8hi __builtin_arc_vdifaw (__v8hi, __v8hi)
10521__v8hi __builtin_arc_vdifw (__v8hi, __v8hi)
10522__v8hi __builtin_arc_veqw (__v8hi, __v8hi)
10523__v8hi __builtin_arc_vh264f (__v8hi, __v8hi)
10524__v8hi __builtin_arc_vh264ft (__v8hi, __v8hi)
10525__v8hi __builtin_arc_vh264fw (__v8hi, __v8hi)
10526__v8hi __builtin_arc_vlew (__v8hi, __v8hi)
10527__v8hi __builtin_arc_vltw (__v8hi, __v8hi)
10528__v8hi __builtin_arc_vmaxaw (__v8hi, __v8hi)
10529__v8hi __builtin_arc_vmaxw (__v8hi, __v8hi)
10530__v8hi __builtin_arc_vminaw (__v8hi, __v8hi)
10531__v8hi __builtin_arc_vminw (__v8hi, __v8hi)
10532__v8hi __builtin_arc_vmr1aw (__v8hi, __v8hi)
10533__v8hi __builtin_arc_vmr1w (__v8hi, __v8hi)
10534__v8hi __builtin_arc_vmr2aw (__v8hi, __v8hi)
10535__v8hi __builtin_arc_vmr2w (__v8hi, __v8hi)
10536__v8hi __builtin_arc_vmr3aw (__v8hi, __v8hi)
10537__v8hi __builtin_arc_vmr3w (__v8hi, __v8hi)
10538__v8hi __builtin_arc_vmr4aw (__v8hi, __v8hi)
10539__v8hi __builtin_arc_vmr4w (__v8hi, __v8hi)
10540__v8hi __builtin_arc_vmr5aw (__v8hi, __v8hi)
10541__v8hi __builtin_arc_vmr5w (__v8hi, __v8hi)
10542__v8hi __builtin_arc_vmr6aw (__v8hi, __v8hi)
10543__v8hi __builtin_arc_vmr6w (__v8hi, __v8hi)
10544__v8hi __builtin_arc_vmr7aw (__v8hi, __v8hi)
10545__v8hi __builtin_arc_vmr7w (__v8hi, __v8hi)
10546__v8hi __builtin_arc_vmrb (__v8hi, __v8hi)
10547__v8hi __builtin_arc_vmulaw (__v8hi, __v8hi)
10548__v8hi __builtin_arc_vmulfaw (__v8hi, __v8hi)
10549__v8hi __builtin_arc_vmulfw (__v8hi, __v8hi)
10550__v8hi __builtin_arc_vmulw (__v8hi, __v8hi)
10551__v8hi __builtin_arc_vnew (__v8hi, __v8hi)
10552__v8hi __builtin_arc_vor (__v8hi, __v8hi)
10553__v8hi __builtin_arc_vsubaw (__v8hi, __v8hi)
10554__v8hi __builtin_arc_vsubw (__v8hi, __v8hi)
10555__v8hi __builtin_arc_vsummw (__v8hi, __v8hi)
10556__v8hi __builtin_arc_vvc1f (__v8hi, __v8hi)
10557__v8hi __builtin_arc_vvc1ft (__v8hi, __v8hi)
10558__v8hi __builtin_arc_vxor (__v8hi, __v8hi)
10559__v8hi __builtin_arc_vxoraw (__v8hi, __v8hi)
10560@end example
10561
10562The following take one @code{__v8hi} and one @code{int} argument and return a
10563@code{__v8hi} result:
10564
10565@example
10566__v8hi __builtin_arc_vbaddw (__v8hi, int)
10567__v8hi __builtin_arc_vbmaxw (__v8hi, int)
10568__v8hi __builtin_arc_vbminw (__v8hi, int)
10569__v8hi __builtin_arc_vbmulaw (__v8hi, int)
10570__v8hi __builtin_arc_vbmulfw (__v8hi, int)
10571__v8hi __builtin_arc_vbmulw (__v8hi, int)
10572__v8hi __builtin_arc_vbrsubw (__v8hi, int)
10573__v8hi __builtin_arc_vbsubw (__v8hi, int)
10574@end example
10575
10576The following take one @code{__v8hi} argument and one @code{int} argument which
10577must be a 3-bit compile time constant indicating a register number
10578I0-I7. They return a @code{__v8hi} result.
10579@example
10580__v8hi __builtin_arc_vasrw (__v8hi, const int)
10581__v8hi __builtin_arc_vsr8 (__v8hi, const int)
10582__v8hi __builtin_arc_vsr8aw (__v8hi, const int)
10583@end example
10584
10585The following take one @code{__v8hi} argument and one @code{int}
10586argument which must be a 6-bit compile time constant. They return a
10587@code{__v8hi} result.
10588@example
10589__v8hi __builtin_arc_vasrpwbi (__v8hi, const int)
10590__v8hi __builtin_arc_vasrrpwbi (__v8hi, const int)
10591__v8hi __builtin_arc_vasrrwi (__v8hi, const int)
10592__v8hi __builtin_arc_vasrsrwi (__v8hi, const int)
10593__v8hi __builtin_arc_vasrwi (__v8hi, const int)
10594__v8hi __builtin_arc_vsr8awi (__v8hi, const int)
10595__v8hi __builtin_arc_vsr8i (__v8hi, const int)
10596@end example
10597
10598The following take one @code{__v8hi} argument and one @code{int} argument which
10599must be a 8-bit compile time constant. They return a @code{__v8hi}
10600result.
10601@example
10602__v8hi __builtin_arc_vd6tapf (__v8hi, const int)
10603__v8hi __builtin_arc_vmvaw (__v8hi, const int)
10604__v8hi __builtin_arc_vmvw (__v8hi, const int)
10605__v8hi __builtin_arc_vmvzw (__v8hi, const int)
10606@end example
10607
10608The following take two @code{int} arguments, the second of which which
10609must be a 8-bit compile time constant. They return a @code{__v8hi}
10610result:
10611@example
10612__v8hi __builtin_arc_vmovaw (int, const int)
10613__v8hi __builtin_arc_vmovw (int, const int)
10614__v8hi __builtin_arc_vmovzw (int, const int)
10615@end example
10616
10617The following take a single @code{__v8hi} argument and return a
10618@code{__v8hi} result:
10619@example
10620__v8hi __builtin_arc_vabsaw (__v8hi)
10621__v8hi __builtin_arc_vabsw (__v8hi)
10622__v8hi __builtin_arc_vaddsuw (__v8hi)
10623__v8hi __builtin_arc_vexch1 (__v8hi)
10624__v8hi __builtin_arc_vexch2 (__v8hi)
10625__v8hi __builtin_arc_vexch4 (__v8hi)
10626__v8hi __builtin_arc_vsignw (__v8hi)
10627__v8hi __builtin_arc_vupbaw (__v8hi)
10628__v8hi __builtin_arc_vupbw (__v8hi)
10629__v8hi __builtin_arc_vupsbaw (__v8hi)
10630__v8hi __builtin_arc_vupsbw (__v8hi)
10631@end example
10632
10633The followign take two @code{int} arguments and return no result:
10634@example
10635void __builtin_arc_vdirun (int, int)
10636void __builtin_arc_vdorun (int, int)
10637@end example
10638
10639The following take two @code{int} arguments and return no result. The
10640first argument must a 3-bit compile time constant indicating one of
10641the DR0-DR7 DMA setup channels:
10642@example
10643void __builtin_arc_vdiwr (const int, int)
10644void __builtin_arc_vdowr (const int, int)
10645@end example
10646
10647The following take an @code{int} argument and return no result:
10648@example
10649void __builtin_arc_vendrec (int)
10650void __builtin_arc_vrec (int)
10651void __builtin_arc_vrecrun (int)
10652void __builtin_arc_vrun (int)
10653@end example
10654
10655The following take a @code{__v8hi} argument and two @code{int}
10656arguments and return a @code{__v8hi} result. The second argument must
10657be a 3-bit compile time constants, indicating one the registers I0-I7,
10658and the third argument must be an 8-bit compile time constant.
10659
10660@emph{Note:} Although the equivalent hardware instructions do not take
10661an SIMD register as an operand, these builtins overwrite the relevant
10662bits of the @code{__v8hi} register provided as the first argument with
10663the value loaded from the @code{[Ib, u8]} location in the SDM.
10664
10665@example
10666__v8hi __builtin_arc_vld32 (__v8hi, const int, const int)
10667__v8hi __builtin_arc_vld32wh (__v8hi, const int, const int)
10668__v8hi __builtin_arc_vld32wl (__v8hi, const int, const int)
10669__v8hi __builtin_arc_vld64 (__v8hi, const int, const int)
10670@end example
10671
10672The following take two @code{int} arguments and return a @code{__v8hi}
10673result. The first argument must be a 3-bit compile time constants,
10674indicating one the registers I0-I7, and the second argument must be an
106758-bit compile time constant.
10676
10677@example
10678__v8hi __builtin_arc_vld128 (const int, const int)
10679__v8hi __builtin_arc_vld64w (const int, const int)
10680@end example
10681
10682The following take a @code{__v8hi} argument and two @code{int}
10683arguments and return no result. The second argument must be a 3-bit
10684compile time constants, indicating one the registers I0-I7, and the
10685third argument must be an 8-bit compile time constant.
10686
10687@example
10688void __builtin_arc_vst128 (__v8hi, const int, const int)
10689void __builtin_arc_vst64 (__v8hi, const int, const int)
10690@end example
10691
10692The following take a @code{__v8hi} argument and three @code{int}
10693arguments and return no result. The second argument must be a 3-bit
10694compile-time constant, identifying the 16-bit sub-register to be
10695stored, the third argument must be a 3-bit compile time constants,
10696indicating one the registers I0-I7, and the fourth argument must be an
106978-bit compile time constant.
10698
10699@example
10700void __builtin_arc_vst16_n (__v8hi, const int, const int, const int)
10701void __builtin_arc_vst32_n (__v8hi, const int, const int, const int)
10702@end example
10703
88f77cba
JB
10704@node ARM iWMMXt Built-in Functions
10705@subsection ARM iWMMXt Built-in Functions
4bc73018
NC
10706
10707These built-in functions are available for the ARM family of
88f77cba 10708processors when the @option{-mcpu=iwmmxt} switch is used:
4bc73018 10709
3ab51846 10710@smallexample
d63851eb
ILT
10711typedef int v2si __attribute__ ((vector_size (8)));
10712typedef short v4hi __attribute__ ((vector_size (8)));
10713typedef char v8qi __attribute__ ((vector_size (8)));
10714
703ae70c
MT
10715int __builtin_arm_getwcgr0 (void)
10716void __builtin_arm_setwcgr0 (int)
10717int __builtin_arm_getwcgr1 (void)
10718void __builtin_arm_setwcgr1 (int)
10719int __builtin_arm_getwcgr2 (void)
10720void __builtin_arm_setwcgr2 (int)
10721int __builtin_arm_getwcgr3 (void)
10722void __builtin_arm_setwcgr3 (int)
d63851eb
ILT
10723int __builtin_arm_textrmsb (v8qi, int)
10724int __builtin_arm_textrmsh (v4hi, int)
10725int __builtin_arm_textrmsw (v2si, int)
10726int __builtin_arm_textrmub (v8qi, int)
10727int __builtin_arm_textrmuh (v4hi, int)
10728int __builtin_arm_textrmuw (v2si, int)
703ae70c
MT
10729v8qi __builtin_arm_tinsrb (v8qi, int, int)
10730v4hi __builtin_arm_tinsrh (v4hi, int, int)
10731v2si __builtin_arm_tinsrw (v2si, int, int)
d63851eb
ILT
10732long long __builtin_arm_tmia (long long, int, int)
10733long long __builtin_arm_tmiabb (long long, int, int)
10734long long __builtin_arm_tmiabt (long long, int, int)
10735long long __builtin_arm_tmiaph (long long, int, int)
10736long long __builtin_arm_tmiatb (long long, int, int)
10737long long __builtin_arm_tmiatt (long long, int, int)
10738int __builtin_arm_tmovmskb (v8qi)
10739int __builtin_arm_tmovmskh (v4hi)
10740int __builtin_arm_tmovmskw (v2si)
10741long long __builtin_arm_waccb (v8qi)
10742long long __builtin_arm_wacch (v4hi)
10743long long __builtin_arm_waccw (v2si)
10744v8qi __builtin_arm_waddb (v8qi, v8qi)
10745v8qi __builtin_arm_waddbss (v8qi, v8qi)
10746v8qi __builtin_arm_waddbus (v8qi, v8qi)
10747v4hi __builtin_arm_waddh (v4hi, v4hi)
10748v4hi __builtin_arm_waddhss (v4hi, v4hi)
10749v4hi __builtin_arm_waddhus (v4hi, v4hi)
4bc73018 10750v2si __builtin_arm_waddw (v2si, v2si)
4bc73018 10751v2si __builtin_arm_waddwss (v2si, v2si)
4bc73018 10752v2si __builtin_arm_waddwus (v2si, v2si)
d63851eb
ILT
10753v8qi __builtin_arm_walign (v8qi, v8qi, int)
10754long long __builtin_arm_wand(long long, long long)
10755long long __builtin_arm_wandn (long long, long long)
10756v8qi __builtin_arm_wavg2b (v8qi, v8qi)
10757v8qi __builtin_arm_wavg2br (v8qi, v8qi)
10758v4hi __builtin_arm_wavg2h (v4hi, v4hi)
10759v4hi __builtin_arm_wavg2hr (v4hi, v4hi)
10760v8qi __builtin_arm_wcmpeqb (v8qi, v8qi)
10761v4hi __builtin_arm_wcmpeqh (v4hi, v4hi)
4bc73018 10762v2si __builtin_arm_wcmpeqw (v2si, v2si)
d63851eb
ILT
10763v8qi __builtin_arm_wcmpgtsb (v8qi, v8qi)
10764v4hi __builtin_arm_wcmpgtsh (v4hi, v4hi)
4bc73018 10765v2si __builtin_arm_wcmpgtsw (v2si, v2si)
d63851eb
ILT
10766v8qi __builtin_arm_wcmpgtub (v8qi, v8qi)
10767v4hi __builtin_arm_wcmpgtuh (v4hi, v4hi)
10768v2si __builtin_arm_wcmpgtuw (v2si, v2si)
10769long long __builtin_arm_wmacs (long long, v4hi, v4hi)
10770long long __builtin_arm_wmacsz (v4hi, v4hi)
10771long long __builtin_arm_wmacu (long long, v4hi, v4hi)
10772long long __builtin_arm_wmacuz (v4hi, v4hi)
10773v4hi __builtin_arm_wmadds (v4hi, v4hi)
10774v4hi __builtin_arm_wmaddu (v4hi, v4hi)
10775v8qi __builtin_arm_wmaxsb (v8qi, v8qi)
10776v4hi __builtin_arm_wmaxsh (v4hi, v4hi)
4bc73018 10777v2si __builtin_arm_wmaxsw (v2si, v2si)
d63851eb
ILT
10778v8qi __builtin_arm_wmaxub (v8qi, v8qi)
10779v4hi __builtin_arm_wmaxuh (v4hi, v4hi)
4bc73018 10780v2si __builtin_arm_wmaxuw (v2si, v2si)
d63851eb
ILT
10781v8qi __builtin_arm_wminsb (v8qi, v8qi)
10782v4hi __builtin_arm_wminsh (v4hi, v4hi)
4bc73018 10783v2si __builtin_arm_wminsw (v2si, v2si)
d63851eb
ILT
10784v8qi __builtin_arm_wminub (v8qi, v8qi)
10785v4hi __builtin_arm_wminuh (v4hi, v4hi)
4bc73018 10786v2si __builtin_arm_wminuw (v2si, v2si)
d63851eb
ILT
10787v4hi __builtin_arm_wmulsm (v4hi, v4hi)
10788v4hi __builtin_arm_wmulul (v4hi, v4hi)
10789v4hi __builtin_arm_wmulum (v4hi, v4hi)
10790long long __builtin_arm_wor (long long, long long)
10791v2si __builtin_arm_wpackdss (long long, long long)
10792v2si __builtin_arm_wpackdus (long long, long long)
10793v8qi __builtin_arm_wpackhss (v4hi, v4hi)
10794v8qi __builtin_arm_wpackhus (v4hi, v4hi)
10795v4hi __builtin_arm_wpackwss (v2si, v2si)
10796v4hi __builtin_arm_wpackwus (v2si, v2si)
10797long long __builtin_arm_wrord (long long, long long)
10798long long __builtin_arm_wrordi (long long, int)
10799v4hi __builtin_arm_wrorh (v4hi, long long)
10800v4hi __builtin_arm_wrorhi (v4hi, int)
10801v2si __builtin_arm_wrorw (v2si, long long)
10802v2si __builtin_arm_wrorwi (v2si, int)
703ae70c 10803v2si __builtin_arm_wsadb (v2si, v8qi, v8qi)
d63851eb 10804v2si __builtin_arm_wsadbz (v8qi, v8qi)
703ae70c 10805v2si __builtin_arm_wsadh (v2si, v4hi, v4hi)
d63851eb
ILT
10806v2si __builtin_arm_wsadhz (v4hi, v4hi)
10807v4hi __builtin_arm_wshufh (v4hi, int)
10808long long __builtin_arm_wslld (long long, long long)
10809long long __builtin_arm_wslldi (long long, int)
10810v4hi __builtin_arm_wsllh (v4hi, long long)
10811v4hi __builtin_arm_wsllhi (v4hi, int)
10812v2si __builtin_arm_wsllw (v2si, long long)
4bc73018 10813v2si __builtin_arm_wsllwi (v2si, int)
d63851eb
ILT
10814long long __builtin_arm_wsrad (long long, long long)
10815long long __builtin_arm_wsradi (long long, int)
10816v4hi __builtin_arm_wsrah (v4hi, long long)
10817v4hi __builtin_arm_wsrahi (v4hi, int)
10818v2si __builtin_arm_wsraw (v2si, long long)
4bc73018 10819v2si __builtin_arm_wsrawi (v2si, int)
d63851eb
ILT
10820long long __builtin_arm_wsrld (long long, long long)
10821long long __builtin_arm_wsrldi (long long, int)
10822v4hi __builtin_arm_wsrlh (v4hi, long long)
10823v4hi __builtin_arm_wsrlhi (v4hi, int)
10824v2si __builtin_arm_wsrlw (v2si, long long)
4bc73018 10825v2si __builtin_arm_wsrlwi (v2si, int)
d63851eb
ILT
10826v8qi __builtin_arm_wsubb (v8qi, v8qi)
10827v8qi __builtin_arm_wsubbss (v8qi, v8qi)
10828v8qi __builtin_arm_wsubbus (v8qi, v8qi)
10829v4hi __builtin_arm_wsubh (v4hi, v4hi)
10830v4hi __builtin_arm_wsubhss (v4hi, v4hi)
10831v4hi __builtin_arm_wsubhus (v4hi, v4hi)
10832v2si __builtin_arm_wsubw (v2si, v2si)
10833v2si __builtin_arm_wsubwss (v2si, v2si)
10834v2si __builtin_arm_wsubwus (v2si, v2si)
10835v4hi __builtin_arm_wunpckehsb (v8qi)
10836v2si __builtin_arm_wunpckehsh (v4hi)
10837long long __builtin_arm_wunpckehsw (v2si)
10838v4hi __builtin_arm_wunpckehub (v8qi)
10839v2si __builtin_arm_wunpckehuh (v4hi)
10840long long __builtin_arm_wunpckehuw (v2si)
10841v4hi __builtin_arm_wunpckelsb (v8qi)
10842v2si __builtin_arm_wunpckelsh (v4hi)
10843long long __builtin_arm_wunpckelsw (v2si)
10844v4hi __builtin_arm_wunpckelub (v8qi)
10845v2si __builtin_arm_wunpckeluh (v4hi)
10846long long __builtin_arm_wunpckeluw (v2si)
10847v8qi __builtin_arm_wunpckihb (v8qi, v8qi)
10848v4hi __builtin_arm_wunpckihh (v4hi, v4hi)
4bc73018 10849v2si __builtin_arm_wunpckihw (v2si, v2si)
d63851eb
ILT
10850v8qi __builtin_arm_wunpckilb (v8qi, v8qi)
10851v4hi __builtin_arm_wunpckilh (v4hi, v4hi)
4bc73018 10852v2si __builtin_arm_wunpckilw (v2si, v2si)
d63851eb
ILT
10853long long __builtin_arm_wxor (long long, long long)
10854long long __builtin_arm_wzero ()
3ab51846 10855@end smallexample
4bc73018 10856
88f77cba 10857
3f155273
TB
10858@node ARM C Language Extensions (ACLE)
10859@subsection ARM C Language Extensions (ACLE)
10860
10861GCC implements extensions for C as described in the ARM C Language
10862Extensions (ACLE) specification, which can be found at
10863@uref{http://infocenter.arm.com/help/topic/com.arm.doc.ihi0053c/IHI0053C_acle_2_0.pdf}.
88f77cba 10864
3f155273
TB
10865As a part of ACLE, GCC implements extensions for Advanced SIMD as described in
10866the ARM C Language Extensions Specification. The complete list of Advanced SIMD
10867intrinsics can be found at
10868@uref{http://infocenter.arm.com/help/topic/com.arm.doc.ihi0073a/IHI0073A_arm_neon_intrinsics_ref.pdf}.
10869The built-in intrinsics for the Advanced SIMD extension are available when
10870NEON is enabled.
88f77cba 10871
3f155273
TB
10872Currently, ARM and AArch64 back-ends do not support ACLE 2.0 fully. Both
10873back-ends support CRC32 intrinsics from @file{arm_acle.h}. The ARM backend's
1087416-bit floating-point Advanded SIMD Intrinsics currently comply to ACLE v1.1.
10875AArch64's backend does not have support for 16-bit floating point Advanced SIMD
10876Intrinsics yet.
582e2e43 10877
3f155273
TB
10878See @ref{ARM Options} and @ref{AArch64 Options} for more information on the
10879availability of extensions.
582e2e43 10880
f10743d3
KV
10881@node ARM Floating Point Status and Control Intrinsics
10882@subsection ARM Floating Point Status and Control Intrinsics
10883
10884These built-in functions are available for the ARM family of
10885processors with floating-point unit.
10886
10887@smallexample
10888unsigned int __builtin_arm_get_fpscr ()
10889void __builtin_arm_set_fpscr (unsigned int)
10890@end smallexample
10891
43ea6502
AS
10892@node AVR Built-in Functions
10893@subsection AVR Built-in Functions
10894
10895For each built-in function for AVR, there is an equally named,
10896uppercase built-in macro defined. That way users can easily query if
10897or if not a specific built-in is implemented or not. For example, if
10898@code{__builtin_avr_nop} is available the macro
10899@code{__BUILTIN_AVR_NOP} is defined to @code{1} and undefined otherwise.
10900
10901The following built-in functions map to the respective machine
566fb011 10902instruction, i.e.@: @code{nop}, @code{sei}, @code{cli}, @code{sleep},
43ea6502 10903@code{wdr}, @code{swap}, @code{fmul}, @code{fmuls}
f451d14d
GJL
10904resp. @code{fmulsu}. The three @code{fmul*} built-ins are implemented
10905as library call if no hardware multiplier is available.
43ea6502
AS
10906
10907@smallexample
10908void __builtin_avr_nop (void)
10909void __builtin_avr_sei (void)
10910void __builtin_avr_cli (void)
10911void __builtin_avr_sleep (void)
10912void __builtin_avr_wdr (void)
10913unsigned char __builtin_avr_swap (unsigned char)
10914unsigned int __builtin_avr_fmul (unsigned char, unsigned char)
10915int __builtin_avr_fmuls (char, char)
10916int __builtin_avr_fmulsu (char, unsigned char)
10917@end smallexample
10918
10919In order to delay execution for a specific number of cycles, GCC
10920implements
10921@smallexample
10922void __builtin_avr_delay_cycles (unsigned long ticks)
10923@end smallexample
10924
49b2772e 10925@noindent
43ea6502 10926@code{ticks} is the number of ticks to delay execution. Note that this
c417597c 10927built-in does not take into account the effect of interrupts that
566fb011 10928might increase delay time. @code{ticks} must be a compile-time
43ea6502
AS
10929integer constant; delays with a variable number of cycles are not supported.
10930
49b2772e 10931@smallexample
1619fcfc
GJL
10932char __builtin_avr_flash_segment (const __memx void*)
10933@end smallexample
10934
10935@noindent
10936This built-in takes a byte address to the 24-bit
10937@ref{AVR Named Address Spaces,address space} @code{__memx} and returns
10938the number of the flash segment (the 64 KiB chunk) where the address
10939points to. Counting starts at @code{0}.
10940If the address does not point to flash memory, return @code{-1}.
10941
10942@smallexample
10943unsigned char __builtin_avr_insert_bits (unsigned long map, unsigned char bits, unsigned char val)
49b2772e
GJL
10944@end smallexample
10945
10946@noindent
0c578db6
GJL
10947Insert bits from @var{bits} into @var{val} and return the resulting
10948value. The nibbles of @var{map} determine how the insertion is
10949performed: Let @var{X} be the @var{n}-th nibble of @var{map}
10950@enumerate
10951@item If @var{X} is @code{0xf},
10952then the @var{n}-th bit of @var{val} is returned unaltered.
10953
10954@item If X is in the range 0@dots{}7,
10955then the @var{n}-th result bit is set to the @var{X}-th bit of @var{bits}
10956
10957@item If X is in the range 8@dots{}@code{0xe},
10958then the @var{n}-th result bit is undefined.
10959@end enumerate
49b2772e
GJL
10960
10961@noindent
0c578db6
GJL
10962One typical use case for this built-in is adjusting input and
10963output values to non-contiguous port layouts. Some examples:
49b2772e
GJL
10964
10965@smallexample
0c578db6
GJL
10966// same as val, bits is unused
10967__builtin_avr_insert_bits (0xffffffff, bits, val)
49b2772e
GJL
10968@end smallexample
10969
0c578db6
GJL
10970@smallexample
10971// same as bits, val is unused
10972__builtin_avr_insert_bits (0x76543210, bits, val)
10973@end smallexample
10974
10975@smallexample
10976// same as rotating bits by 4
10977__builtin_avr_insert_bits (0x32107654, bits, 0)
10978@end smallexample
10979
10980@smallexample
6f46cb63
SL
10981// high nibble of result is the high nibble of val
10982// low nibble of result is the low nibble of bits
0c578db6
GJL
10983__builtin_avr_insert_bits (0xffff3210, bits, val)
10984@end smallexample
10985
10986@smallexample
10987// reverse the bit order of bits
10988__builtin_avr_insert_bits (0x01234567, bits, 0)
10989@end smallexample
49b2772e 10990
161c21b6
BS
10991@node Blackfin Built-in Functions
10992@subsection Blackfin Built-in Functions
10993
10994Currently, there are two Blackfin-specific built-in functions. These are
10995used for generating @code{CSYNC} and @code{SSYNC} machine insns without
10996using inline assembly; by using these built-in functions the compiler can
10997automatically add workarounds for hardware errata involving these
10998instructions. These functions are named as follows:
10999
11000@smallexample
11001void __builtin_bfin_csync (void)
11002void __builtin_bfin_ssync (void)
11003@end smallexample
11004
c3ee0579
RS
11005@node FR-V Built-in Functions
11006@subsection FR-V Built-in Functions
11007
11008GCC provides many FR-V-specific built-in functions. In general,
11009these functions are intended to be compatible with those described
11010by @cite{FR-V Family, Softune C/C++ Compiler Manual (V6), Fujitsu
11011Semiconductor}. The two exceptions are @code{__MDUNPACKH} and
566fb011 11012@code{__MBTOHE}, the GCC forms of which pass 128-bit values by
c3ee0579
RS
11013pointer rather than by value.
11014
11015Most of the functions are named after specific FR-V instructions.
27ef2cdd 11016Such functions are said to be ``directly mapped'' and are summarized
c3ee0579
RS
11017here in tabular form.
11018
11019@menu
11020* Argument Types::
11021* Directly-mapped Integer Functions::
11022* Directly-mapped Media Functions::
c14ff86e 11023* Raw read/write Functions::
c3ee0579
RS
11024* Other Built-in Functions::
11025@end menu
11026
11027@node Argument Types
11028@subsubsection Argument Types
11029
11030The arguments to the built-in functions can be divided into three groups:
11031register numbers, compile-time constants and run-time values. In order
11032to make this classification clear at a glance, the arguments and return
11033values are given the following pseudo types:
11034
11035@multitable @columnfractions .20 .30 .15 .35
11036@item Pseudo type @tab Real C type @tab Constant? @tab Description
11037@item @code{uh} @tab @code{unsigned short} @tab No @tab an unsigned halfword
11038@item @code{uw1} @tab @code{unsigned int} @tab No @tab an unsigned word
11039@item @code{sw1} @tab @code{int} @tab No @tab a signed word
11040@item @code{uw2} @tab @code{unsigned long long} @tab No
11041@tab an unsigned doubleword
11042@item @code{sw2} @tab @code{long long} @tab No @tab a signed doubleword
11043@item @code{const} @tab @code{int} @tab Yes @tab an integer constant
11044@item @code{acc} @tab @code{int} @tab Yes @tab an ACC register number
11045@item @code{iacc} @tab @code{int} @tab Yes @tab an IACC register number
11046@end multitable
11047
11048These pseudo types are not defined by GCC, they are simply a notational
11049convenience used in this manual.
11050
11051Arguments of type @code{uh}, @code{uw1}, @code{sw1}, @code{uw2}
11052and @code{sw2} are evaluated at run time. They correspond to
11053register operands in the underlying FR-V instructions.
11054
11055@code{const} arguments represent immediate operands in the underlying
11056FR-V instructions. They must be compile-time constants.
11057
11058@code{acc} arguments are evaluated at compile time and specify the number
11059of an accumulator register. For example, an @code{acc} argument of 2
358a3dbc 11060selects the ACC2 register.
c3ee0579
RS
11061
11062@code{iacc} arguments are similar to @code{acc} arguments but specify the
11063number of an IACC register. See @pxref{Other Built-in Functions}
11064for more details.
11065
11066@node Directly-mapped Integer Functions
11067@subsubsection Directly-mapped Integer Functions
11068
11069The functions listed below map directly to FR-V I-type instructions.
11070
11071@multitable @columnfractions .45 .32 .23
11072@item Function prototype @tab Example usage @tab Assembly output
11073@item @code{sw1 __ADDSS (sw1, sw1)}
11074@tab @code{@var{c} = __ADDSS (@var{a}, @var{b})}
11075@tab @code{ADDSS @var{a},@var{b},@var{c}}
11076@item @code{sw1 __SCAN (sw1, sw1)}
11077@tab @code{@var{c} = __SCAN (@var{a}, @var{b})}
11078@tab @code{SCAN @var{a},@var{b},@var{c}}
11079@item @code{sw1 __SCUTSS (sw1)}
11080@tab @code{@var{b} = __SCUTSS (@var{a})}
11081@tab @code{SCUTSS @var{a},@var{b}}
11082@item @code{sw1 __SLASS (sw1, sw1)}
11083@tab @code{@var{c} = __SLASS (@var{a}, @var{b})}
11084@tab @code{SLASS @var{a},@var{b},@var{c}}
11085@item @code{void __SMASS (sw1, sw1)}
11086@tab @code{__SMASS (@var{a}, @var{b})}
11087@tab @code{SMASS @var{a},@var{b}}
11088@item @code{void __SMSSS (sw1, sw1)}
11089@tab @code{__SMSSS (@var{a}, @var{b})}
11090@tab @code{SMSSS @var{a},@var{b}}
11091@item @code{void __SMU (sw1, sw1)}
11092@tab @code{__SMU (@var{a}, @var{b})}
11093@tab @code{SMU @var{a},@var{b}}
11094@item @code{sw2 __SMUL (sw1, sw1)}
11095@tab @code{@var{c} = __SMUL (@var{a}, @var{b})}
11096@tab @code{SMUL @var{a},@var{b},@var{c}}
11097@item @code{sw1 __SUBSS (sw1, sw1)}
11098@tab @code{@var{c} = __SUBSS (@var{a}, @var{b})}
11099@tab @code{SUBSS @var{a},@var{b},@var{c}}
11100@item @code{uw2 __UMUL (uw1, uw1)}
11101@tab @code{@var{c} = __UMUL (@var{a}, @var{b})}
11102@tab @code{UMUL @var{a},@var{b},@var{c}}
11103@end multitable
11104
11105@node Directly-mapped Media Functions
11106@subsubsection Directly-mapped Media Functions
11107
11108The functions listed below map directly to FR-V M-type instructions.
11109
11110@multitable @columnfractions .45 .32 .23
11111@item Function prototype @tab Example usage @tab Assembly output
11112@item @code{uw1 __MABSHS (sw1)}
11113@tab @code{@var{b} = __MABSHS (@var{a})}
11114@tab @code{MABSHS @var{a},@var{b}}
11115@item @code{void __MADDACCS (acc, acc)}
11116@tab @code{__MADDACCS (@var{b}, @var{a})}
11117@tab @code{MADDACCS @var{a},@var{b}}
11118@item @code{sw1 __MADDHSS (sw1, sw1)}
11119@tab @code{@var{c} = __MADDHSS (@var{a}, @var{b})}
11120@tab @code{MADDHSS @var{a},@var{b},@var{c}}
11121@item @code{uw1 __MADDHUS (uw1, uw1)}
11122@tab @code{@var{c} = __MADDHUS (@var{a}, @var{b})}
11123@tab @code{MADDHUS @var{a},@var{b},@var{c}}
11124@item @code{uw1 __MAND (uw1, uw1)}
11125@tab @code{@var{c} = __MAND (@var{a}, @var{b})}
11126@tab @code{MAND @var{a},@var{b},@var{c}}
11127@item @code{void __MASACCS (acc, acc)}
11128@tab @code{__MASACCS (@var{b}, @var{a})}
11129@tab @code{MASACCS @var{a},@var{b}}
11130@item @code{uw1 __MAVEH (uw1, uw1)}
11131@tab @code{@var{c} = __MAVEH (@var{a}, @var{b})}
11132@tab @code{MAVEH @var{a},@var{b},@var{c}}
11133@item @code{uw2 __MBTOH (uw1)}
11134@tab @code{@var{b} = __MBTOH (@var{a})}
11135@tab @code{MBTOH @var{a},@var{b}}
11136@item @code{void __MBTOHE (uw1 *, uw1)}
11137@tab @code{__MBTOHE (&@var{b}, @var{a})}
11138@tab @code{MBTOHE @var{a},@var{b}}
11139@item @code{void __MCLRACC (acc)}
11140@tab @code{__MCLRACC (@var{a})}
11141@tab @code{MCLRACC @var{a}}
11142@item @code{void __MCLRACCA (void)}
11143@tab @code{__MCLRACCA ()}
11144@tab @code{MCLRACCA}
11145@item @code{uw1 __Mcop1 (uw1, uw1)}
11146@tab @code{@var{c} = __Mcop1 (@var{a}, @var{b})}
11147@tab @code{Mcop1 @var{a},@var{b},@var{c}}
11148@item @code{uw1 __Mcop2 (uw1, uw1)}
11149@tab @code{@var{c} = __Mcop2 (@var{a}, @var{b})}
11150@tab @code{Mcop2 @var{a},@var{b},@var{c}}
11151@item @code{uw1 __MCPLHI (uw2, const)}
11152@tab @code{@var{c} = __MCPLHI (@var{a}, @var{b})}
11153@tab @code{MCPLHI @var{a},#@var{b},@var{c}}
11154@item @code{uw1 __MCPLI (uw2, const)}
11155@tab @code{@var{c} = __MCPLI (@var{a}, @var{b})}
11156@tab @code{MCPLI @var{a},#@var{b},@var{c}}
11157@item @code{void __MCPXIS (acc, sw1, sw1)}
11158@tab @code{__MCPXIS (@var{c}, @var{a}, @var{b})}
11159@tab @code{MCPXIS @var{a},@var{b},@var{c}}
11160@item @code{void __MCPXIU (acc, uw1, uw1)}
11161@tab @code{__MCPXIU (@var{c}, @var{a}, @var{b})}
11162@tab @code{MCPXIU @var{a},@var{b},@var{c}}
11163@item @code{void __MCPXRS (acc, sw1, sw1)}
11164@tab @code{__MCPXRS (@var{c}, @var{a}, @var{b})}
11165@tab @code{MCPXRS @var{a},@var{b},@var{c}}
11166@item @code{void __MCPXRU (acc, uw1, uw1)}
11167@tab @code{__MCPXRU (@var{c}, @var{a}, @var{b})}
11168@tab @code{MCPXRU @var{a},@var{b},@var{c}}
11169@item @code{uw1 __MCUT (acc, uw1)}
11170@tab @code{@var{c} = __MCUT (@var{a}, @var{b})}
11171@tab @code{MCUT @var{a},@var{b},@var{c}}
11172@item @code{uw1 __MCUTSS (acc, sw1)}
11173@tab @code{@var{c} = __MCUTSS (@var{a}, @var{b})}
11174@tab @code{MCUTSS @var{a},@var{b},@var{c}}
11175@item @code{void __MDADDACCS (acc, acc)}
11176@tab @code{__MDADDACCS (@var{b}, @var{a})}
11177@tab @code{MDADDACCS @var{a},@var{b}}
11178@item @code{void __MDASACCS (acc, acc)}
11179@tab @code{__MDASACCS (@var{b}, @var{a})}
11180@tab @code{MDASACCS @var{a},@var{b}}
11181@item @code{uw2 __MDCUTSSI (acc, const)}
11182@tab @code{@var{c} = __MDCUTSSI (@var{a}, @var{b})}
11183@tab @code{MDCUTSSI @var{a},#@var{b},@var{c}}
11184@item @code{uw2 __MDPACKH (uw2, uw2)}
11185@tab @code{@var{c} = __MDPACKH (@var{a}, @var{b})}
11186@tab @code{MDPACKH @var{a},@var{b},@var{c}}
11187@item @code{uw2 __MDROTLI (uw2, const)}
11188@tab @code{@var{c} = __MDROTLI (@var{a}, @var{b})}
11189@tab @code{MDROTLI @var{a},#@var{b},@var{c}}
11190@item @code{void __MDSUBACCS (acc, acc)}
11191@tab @code{__MDSUBACCS (@var{b}, @var{a})}
11192@tab @code{MDSUBACCS @var{a},@var{b}}
11193@item @code{void __MDUNPACKH (uw1 *, uw2)}
11194@tab @code{__MDUNPACKH (&@var{b}, @var{a})}
11195@tab @code{MDUNPACKH @var{a},@var{b}}
11196@item @code{uw2 __MEXPDHD (uw1, const)}
11197@tab @code{@var{c} = __MEXPDHD (@var{a}, @var{b})}
11198@tab @code{MEXPDHD @var{a},#@var{b},@var{c}}
11199@item @code{uw1 __MEXPDHW (uw1, const)}
11200@tab @code{@var{c} = __MEXPDHW (@var{a}, @var{b})}
11201@tab @code{MEXPDHW @var{a},#@var{b},@var{c}}
11202@item @code{uw1 __MHDSETH (uw1, const)}
11203@tab @code{@var{c} = __MHDSETH (@var{a}, @var{b})}
11204@tab @code{MHDSETH @var{a},#@var{b},@var{c}}
11205@item @code{sw1 __MHDSETS (const)}
11206@tab @code{@var{b} = __MHDSETS (@var{a})}
11207@tab @code{MHDSETS #@var{a},@var{b}}
11208@item @code{uw1 __MHSETHIH (uw1, const)}
11209@tab @code{@var{b} = __MHSETHIH (@var{b}, @var{a})}
11210@tab @code{MHSETHIH #@var{a},@var{b}}
11211@item @code{sw1 __MHSETHIS (sw1, const)}
11212@tab @code{@var{b} = __MHSETHIS (@var{b}, @var{a})}
11213@tab @code{MHSETHIS #@var{a},@var{b}}
11214@item @code{uw1 __MHSETLOH (uw1, const)}
11215@tab @code{@var{b} = __MHSETLOH (@var{b}, @var{a})}
11216@tab @code{MHSETLOH #@var{a},@var{b}}
11217@item @code{sw1 __MHSETLOS (sw1, const)}
11218@tab @code{@var{b} = __MHSETLOS (@var{b}, @var{a})}
11219@tab @code{MHSETLOS #@var{a},@var{b}}
11220@item @code{uw1 __MHTOB (uw2)}
11221@tab @code{@var{b} = __MHTOB (@var{a})}
11222@tab @code{MHTOB @var{a},@var{b}}
11223@item @code{void __MMACHS (acc, sw1, sw1)}
11224@tab @code{__MMACHS (@var{c}, @var{a}, @var{b})}
11225@tab @code{MMACHS @var{a},@var{b},@var{c}}
11226@item @code{void __MMACHU (acc, uw1, uw1)}
11227@tab @code{__MMACHU (@var{c}, @var{a}, @var{b})}
11228@tab @code{MMACHU @var{a},@var{b},@var{c}}
11229@item @code{void __MMRDHS (acc, sw1, sw1)}
11230@tab @code{__MMRDHS (@var{c}, @var{a}, @var{b})}
11231@tab @code{MMRDHS @var{a},@var{b},@var{c}}
11232@item @code{void __MMRDHU (acc, uw1, uw1)}
11233@tab @code{__MMRDHU (@var{c}, @var{a}, @var{b})}
11234@tab @code{MMRDHU @var{a},@var{b},@var{c}}
11235@item @code{void __MMULHS (acc, sw1, sw1)}
11236@tab @code{__MMULHS (@var{c}, @var{a}, @var{b})}
11237@tab @code{MMULHS @var{a},@var{b},@var{c}}
11238@item @code{void __MMULHU (acc, uw1, uw1)}
11239@tab @code{__MMULHU (@var{c}, @var{a}, @var{b})}
11240@tab @code{MMULHU @var{a},@var{b},@var{c}}
11241@item @code{void __MMULXHS (acc, sw1, sw1)}
11242@tab @code{__MMULXHS (@var{c}, @var{a}, @var{b})}
11243@tab @code{MMULXHS @var{a},@var{b},@var{c}}
11244@item @code{void __MMULXHU (acc, uw1, uw1)}
11245@tab @code{__MMULXHU (@var{c}, @var{a}, @var{b})}
11246@tab @code{MMULXHU @var{a},@var{b},@var{c}}
11247@item @code{uw1 __MNOT (uw1)}
11248@tab @code{@var{b} = __MNOT (@var{a})}
11249@tab @code{MNOT @var{a},@var{b}}
11250@item @code{uw1 __MOR (uw1, uw1)}
11251@tab @code{@var{c} = __MOR (@var{a}, @var{b})}
11252@tab @code{MOR @var{a},@var{b},@var{c}}
11253@item @code{uw1 __MPACKH (uh, uh)}
11254@tab @code{@var{c} = __MPACKH (@var{a}, @var{b})}
11255@tab @code{MPACKH @var{a},@var{b},@var{c}}
11256@item @code{sw2 __MQADDHSS (sw2, sw2)}
11257@tab @code{@var{c} = __MQADDHSS (@var{a}, @var{b})}
11258@tab @code{MQADDHSS @var{a},@var{b},@var{c}}
11259@item @code{uw2 __MQADDHUS (uw2, uw2)}
11260@tab @code{@var{c} = __MQADDHUS (@var{a}, @var{b})}
11261@tab @code{MQADDHUS @var{a},@var{b},@var{c}}
11262@item @code{void __MQCPXIS (acc, sw2, sw2)}
11263@tab @code{__MQCPXIS (@var{c}, @var{a}, @var{b})}
11264@tab @code{MQCPXIS @var{a},@var{b},@var{c}}
11265@item @code{void __MQCPXIU (acc, uw2, uw2)}
11266@tab @code{__MQCPXIU (@var{c}, @var{a}, @var{b})}
11267@tab @code{MQCPXIU @var{a},@var{b},@var{c}}
11268@item @code{void __MQCPXRS (acc, sw2, sw2)}
11269@tab @code{__MQCPXRS (@var{c}, @var{a}, @var{b})}
11270@tab @code{MQCPXRS @var{a},@var{b},@var{c}}
11271@item @code{void __MQCPXRU (acc, uw2, uw2)}
11272@tab @code{__MQCPXRU (@var{c}, @var{a}, @var{b})}
11273@tab @code{MQCPXRU @var{a},@var{b},@var{c}}
11274@item @code{sw2 __MQLCLRHS (sw2, sw2)}
11275@tab @code{@var{c} = __MQLCLRHS (@var{a}, @var{b})}
11276@tab @code{MQLCLRHS @var{a},@var{b},@var{c}}
11277@item @code{sw2 __MQLMTHS (sw2, sw2)}
11278@tab @code{@var{c} = __MQLMTHS (@var{a}, @var{b})}
11279@tab @code{MQLMTHS @var{a},@var{b},@var{c}}
11280@item @code{void __MQMACHS (acc, sw2, sw2)}
11281@tab @code{__MQMACHS (@var{c}, @var{a}, @var{b})}
11282@tab @code{MQMACHS @var{a},@var{b},@var{c}}
11283@item @code{void __MQMACHU (acc, uw2, uw2)}
11284@tab @code{__MQMACHU (@var{c}, @var{a}, @var{b})}
11285@tab @code{MQMACHU @var{a},@var{b},@var{c}}
11286@item @code{void __MQMACXHS (acc, sw2, sw2)}
11287@tab @code{__MQMACXHS (@var{c}, @var{a}, @var{b})}
11288@tab @code{MQMACXHS @var{a},@var{b},@var{c}}
11289@item @code{void __MQMULHS (acc, sw2, sw2)}
11290@tab @code{__MQMULHS (@var{c}, @var{a}, @var{b})}
11291@tab @code{MQMULHS @var{a},@var{b},@var{c}}
11292@item @code{void __MQMULHU (acc, uw2, uw2)}
11293@tab @code{__MQMULHU (@var{c}, @var{a}, @var{b})}
11294@tab @code{MQMULHU @var{a},@var{b},@var{c}}
11295@item @code{void __MQMULXHS (acc, sw2, sw2)}
11296@tab @code{__MQMULXHS (@var{c}, @var{a}, @var{b})}
11297@tab @code{MQMULXHS @var{a},@var{b},@var{c}}
11298@item @code{void __MQMULXHU (acc, uw2, uw2)}
11299@tab @code{__MQMULXHU (@var{c}, @var{a}, @var{b})}
11300@tab @code{MQMULXHU @var{a},@var{b},@var{c}}
11301@item @code{sw2 __MQSATHS (sw2, sw2)}
11302@tab @code{@var{c} = __MQSATHS (@var{a}, @var{b})}
11303@tab @code{MQSATHS @var{a},@var{b},@var{c}}
11304@item @code{uw2 __MQSLLHI (uw2, int)}
11305@tab @code{@var{c} = __MQSLLHI (@var{a}, @var{b})}
11306@tab @code{MQSLLHI @var{a},@var{b},@var{c}}
11307@item @code{sw2 __MQSRAHI (sw2, int)}
11308@tab @code{@var{c} = __MQSRAHI (@var{a}, @var{b})}
11309@tab @code{MQSRAHI @var{a},@var{b},@var{c}}
11310@item @code{sw2 __MQSUBHSS (sw2, sw2)}
11311@tab @code{@var{c} = __MQSUBHSS (@var{a}, @var{b})}
11312@tab @code{MQSUBHSS @var{a},@var{b},@var{c}}
11313@item @code{uw2 __MQSUBHUS (uw2, uw2)}
11314@tab @code{@var{c} = __MQSUBHUS (@var{a}, @var{b})}
11315@tab @code{MQSUBHUS @var{a},@var{b},@var{c}}
11316@item @code{void __MQXMACHS (acc, sw2, sw2)}
11317@tab @code{__MQXMACHS (@var{c}, @var{a}, @var{b})}
11318@tab @code{MQXMACHS @var{a},@var{b},@var{c}}
11319@item @code{void __MQXMACXHS (acc, sw2, sw2)}
11320@tab @code{__MQXMACXHS (@var{c}, @var{a}, @var{b})}
11321@tab @code{MQXMACXHS @var{a},@var{b},@var{c}}
11322@item @code{uw1 __MRDACC (acc)}
11323@tab @code{@var{b} = __MRDACC (@var{a})}
11324@tab @code{MRDACC @var{a},@var{b}}
11325@item @code{uw1 __MRDACCG (acc)}
11326@tab @code{@var{b} = __MRDACCG (@var{a})}
11327@tab @code{MRDACCG @var{a},@var{b}}
11328@item @code{uw1 __MROTLI (uw1, const)}
11329@tab @code{@var{c} = __MROTLI (@var{a}, @var{b})}
11330@tab @code{MROTLI @var{a},#@var{b},@var{c}}
11331@item @code{uw1 __MROTRI (uw1, const)}
11332@tab @code{@var{c} = __MROTRI (@var{a}, @var{b})}
11333@tab @code{MROTRI @var{a},#@var{b},@var{c}}
11334@item @code{sw1 __MSATHS (sw1, sw1)}
11335@tab @code{@var{c} = __MSATHS (@var{a}, @var{b})}
11336@tab @code{MSATHS @var{a},@var{b},@var{c}}
11337@item @code{uw1 __MSATHU (uw1, uw1)}
11338@tab @code{@var{c} = __MSATHU (@var{a}, @var{b})}
11339@tab @code{MSATHU @var{a},@var{b},@var{c}}
11340@item @code{uw1 __MSLLHI (uw1, const)}
11341@tab @code{@var{c} = __MSLLHI (@var{a}, @var{b})}
11342@tab @code{MSLLHI @var{a},#@var{b},@var{c}}
11343@item @code{sw1 __MSRAHI (sw1, const)}
11344@tab @code{@var{c} = __MSRAHI (@var{a}, @var{b})}
11345@tab @code{MSRAHI @var{a},#@var{b},@var{c}}
11346@item @code{uw1 __MSRLHI (uw1, const)}
11347@tab @code{@var{c} = __MSRLHI (@var{a}, @var{b})}
11348@tab @code{MSRLHI @var{a},#@var{b},@var{c}}
11349@item @code{void __MSUBACCS (acc, acc)}
11350@tab @code{__MSUBACCS (@var{b}, @var{a})}
11351@tab @code{MSUBACCS @var{a},@var{b}}
11352@item @code{sw1 __MSUBHSS (sw1, sw1)}
11353@tab @code{@var{c} = __MSUBHSS (@var{a}, @var{b})}
11354@tab @code{MSUBHSS @var{a},@var{b},@var{c}}
11355@item @code{uw1 __MSUBHUS (uw1, uw1)}
11356@tab @code{@var{c} = __MSUBHUS (@var{a}, @var{b})}
11357@tab @code{MSUBHUS @var{a},@var{b},@var{c}}
11358@item @code{void __MTRAP (void)}
11359@tab @code{__MTRAP ()}
11360@tab @code{MTRAP}
11361@item @code{uw2 __MUNPACKH (uw1)}
11362@tab @code{@var{b} = __MUNPACKH (@var{a})}
11363@tab @code{MUNPACKH @var{a},@var{b}}
11364@item @code{uw1 __MWCUT (uw2, uw1)}
11365@tab @code{@var{c} = __MWCUT (@var{a}, @var{b})}
11366@tab @code{MWCUT @var{a},@var{b},@var{c}}
11367@item @code{void __MWTACC (acc, uw1)}
11368@tab @code{__MWTACC (@var{b}, @var{a})}
11369@tab @code{MWTACC @var{a},@var{b}}
11370@item @code{void __MWTACCG (acc, uw1)}
11371@tab @code{__MWTACCG (@var{b}, @var{a})}
11372@tab @code{MWTACCG @var{a},@var{b}}
11373@item @code{uw1 __MXOR (uw1, uw1)}
11374@tab @code{@var{c} = __MXOR (@var{a}, @var{b})}
11375@tab @code{MXOR @var{a},@var{b},@var{c}}
11376@end multitable
11377
c14ff86e
AH
11378@node Raw read/write Functions
11379@subsubsection Raw read/write Functions
11380
11381This sections describes built-in functions related to read and write
11382instructions to access memory. These functions generate
11383@code{membar} instructions to flush the I/O load and stores where
11384appropriate, as described in Fujitsu's manual described above.
11385
11386@table @code
11387
11388@item unsigned char __builtin_read8 (void *@var{data})
11389@item unsigned short __builtin_read16 (void *@var{data})
11390@item unsigned long __builtin_read32 (void *@var{data})
11391@item unsigned long long __builtin_read64 (void *@var{data})
11392
11393@item void __builtin_write8 (void *@var{data}, unsigned char @var{datum})
11394@item void __builtin_write16 (void *@var{data}, unsigned short @var{datum})
11395@item void __builtin_write32 (void *@var{data}, unsigned long @var{datum})
11396@item void __builtin_write64 (void *@var{data}, unsigned long long @var{datum})
11397@end table
11398
c3ee0579
RS
11399@node Other Built-in Functions
11400@subsubsection Other Built-in Functions
11401
11402This section describes built-in functions that are not named after
11403a specific FR-V instruction.
11404
11405@table @code
11406@item sw2 __IACCreadll (iacc @var{reg})
11407Return the full 64-bit value of IACC0@. The @var{reg} argument is reserved
11408for future expansion and must be 0.
11409
11410@item sw1 __IACCreadl (iacc @var{reg})
11411Return the value of IACC0H if @var{reg} is 0 and IACC0L if @var{reg} is 1.
11412Other values of @var{reg} are rejected as invalid.
11413
11414@item void __IACCsetll (iacc @var{reg}, sw2 @var{x})
11415Set the full 64-bit value of IACC0 to @var{x}. The @var{reg} argument
11416is reserved for future expansion and must be 0.
11417
11418@item void __IACCsetl (iacc @var{reg}, sw1 @var{x})
11419Set IACC0H to @var{x} if @var{reg} is 0 and IACC0L to @var{x} if @var{reg}
11420is 1. Other values of @var{reg} are rejected as invalid.
11421
11422@item void __data_prefetch0 (const void *@var{x})
11423Use the @code{dcpl} instruction to load the contents of address @var{x}
11424into the data cache.
11425
11426@item void __data_prefetch (const void *@var{x})
11427Use the @code{nldub} instruction to load the contents of address @var{x}
358a3dbc 11428into the data cache. The instruction is issued in slot I1@.
c3ee0579
RS
11429@end table
11430
0975678f
JM
11431@node X86 Built-in Functions
11432@subsection X86 Built-in Functions
11433
11434These built-in functions are available for the i386 and x86-64 family
11435of computers, depending on the command-line switches used.
11436
c417597c 11437If you specify command-line switches such as @option{-msse},
75576871
BB
11438the compiler could use the extended instruction sets even if the built-ins
11439are not used explicitly in the program. For this reason, applications
566fb011 11440that perform run-time CPU detection must compile separate files for each
75576871
BB
11441supported architecture, using the appropriate flags. In particular,
11442the file containing the CPU detection code should be compiled without
11443these options.
11444
0975678f 11445The following machine modes are available for use with MMX built-in functions
333c8841
AH
11446(@pxref{Vector Extensions}): @code{V2SI} for a vector of two 32-bit integers,
11447@code{V4HI} for a vector of four 16-bit integers, and @code{V8QI} for a
11448vector of eight 8-bit integers. Some of the built-in functions operate on
75d8b30e 11449MMX registers as a whole 64-bit entity, these use @code{V1DI} as their mode.
0975678f 11450
f8723eb6 11451If 3DNow!@: extensions are enabled, @code{V2SF} is used as a mode for a vector
6f46cb63 11452of two 32-bit floating-point values.
0975678f 11453
333c8841 11454If SSE extensions are enabled, @code{V4SF} is used for a vector of four 32-bit
6f46cb63 11455floating-point values. Some instructions use a vector of four 32-bit
0975678f 11456integers, these use @code{V4SI}. Finally, some instructions operate on an
333c8841 11457entire vector register, interpreting it as a 128-bit integer, these use mode
0975678f
JM
11458@code{TI}.
11459
27f56cb1 11460In 64-bit mode, the x86-64 family of processors uses additional built-in
5513e239 11461functions for efficient use of @code{TF} (@code{__float128}) 128-bit
6f46cb63 11462floating point and @code{TC} 128-bit complex floating-point values.
5513e239 11463
6f46cb63 11464The following floating-point built-in functions are available in 64-bit
27f56cb1 11465mode. All of them implement the function that is part of the name.
5513e239
UB
11466
11467@smallexample
11468__float128 __builtin_fabsq (__float128)
11469__float128 __builtin_copysignq (__float128, __float128)
11470@end smallexample
11471
74838de3
L
11472The following built-in function is always available.
11473
11474@table @code
11475@item void __builtin_ia32_pause (void)
6c81b2bc
L
11476Generates the @code{pause} machine instruction with a compiler memory
11477barrier.
74838de3
L
11478@end table
11479
6f46cb63 11480The following floating-point built-in functions are made available in the
5513e239
UB
1148164-bit mode.
11482
11483@table @code
11484@item __float128 __builtin_infq (void)
11485Similar to @code{__builtin_inf}, except the return type is @code{__float128}.
593812b6
BE
11486@findex __builtin_infq
11487
11488@item __float128 __builtin_huge_valq (void)
11489Similar to @code{__builtin_huge_val}, except the return type is @code{__float128}.
11490@findex __builtin_huge_valq
5513e239
UB
11491@end table
11492
792317cc
ST
11493The following built-in functions are always available and can be used to
11494check the target platform type.
11495
11496@deftypefn {Built-in Function} void __builtin_cpu_init (void)
11497This function runs the CPU detection code to check the type of CPU and the
18abab9f 11498features supported. This built-in function needs to be invoked along with the built-in functions
792317cc 11499to check CPU type and features, @code{__builtin_cpu_is} and
358a3dbc 11500@code{__builtin_cpu_supports}, only when used in a function that is
792317cc
ST
11501executed before any constructors are called. The CPU detection code is
11502automatically executed in a very high priority constructor.
11503
c417597c 11504For example, this function has to be used in @code{ifunc} resolvers that
18abab9f 11505check for CPU type using the built-in functions @code{__builtin_cpu_is}
c417597c 11506and @code{__builtin_cpu_supports}, or in constructors on targets that
aca06c90 11507don't support constructor priority.
792317cc
ST
11508@smallexample
11509
11510static void (*resolve_memcpy (void)) (void)
11511@{
11512 // ifunc resolvers fire before constructors, explicitly call the init
11513 // function.
11514 __builtin_cpu_init ();
11515 if (__builtin_cpu_supports ("ssse3"))
11516 return ssse3_memcpy; // super fast memcpy with ssse3 instructions.
11517 else
11518 return default_memcpy;
11519@}
11520
11521void *memcpy (void *, const void *, size_t)
11522 __attribute__ ((ifunc ("resolve_memcpy")));
11523@end smallexample
11524
11525@end deftypefn
11526
11527@deftypefn {Built-in Function} int __builtin_cpu_is (const char *@var{cpuname})
566fb011
SL
11528This function returns a positive integer if the run-time CPU
11529is of type @var{cpuname}
11530and returns @code{0} otherwise. The following CPU names can be detected:
792317cc
ST
11531
11532@table @samp
11533@item intel
11534Intel CPU.
11535
11536@item atom
bafa88c2 11537Intel Atom CPU.
792317cc
ST
11538
11539@item core2
bafa88c2 11540Intel Core 2 CPU.
792317cc
ST
11541
11542@item corei7
bafa88c2 11543Intel Core i7 CPU.
792317cc
ST
11544
11545@item nehalem
bafa88c2 11546Intel Core i7 Nehalem CPU.
792317cc
ST
11547
11548@item westmere
bafa88c2 11549Intel Core i7 Westmere CPU.
792317cc
ST
11550
11551@item sandybridge
bafa88c2 11552Intel Core i7 Sandy Bridge CPU.
792317cc
ST
11553
11554@item amd
11555AMD CPU.
11556
11557@item amdfam10h
bafa88c2 11558AMD Family 10h CPU.
792317cc
ST
11559
11560@item barcelona
bafa88c2 11561AMD Family 10h Barcelona CPU.
792317cc
ST
11562
11563@item shanghai
bafa88c2 11564AMD Family 10h Shanghai CPU.
792317cc
ST
11565
11566@item istanbul
bafa88c2 11567AMD Family 10h Istanbul CPU.
792317cc 11568
d5b02d90 11569@item btver1
bafa88c2 11570AMD Family 14h CPU.
d5b02d90 11571
792317cc 11572@item amdfam15h
bafa88c2 11573AMD Family 15h CPU.
792317cc
ST
11574
11575@item bdver1
bafa88c2 11576AMD Family 15h Bulldozer version 1.
792317cc
ST
11577
11578@item bdver2
bafa88c2 11579AMD Family 15h Bulldozer version 2.
d5b02d90 11580
eb2f2b44 11581@item bdver3
bafa88c2 11582AMD Family 15h Bulldozer version 3.
eb2f2b44 11583
ed97ad47
GG
11584@item bdver4
11585AMD Family 15h Bulldozer version 4.
11586
d5b02d90 11587@item btver2
bafa88c2 11588AMD Family 16h CPU.
792317cc
ST
11589@end table
11590
11591Here is an example:
11592@smallexample
11593if (__builtin_cpu_is ("corei7"))
11594 @{
bafa88c2 11595 do_corei7 (); // Core i7 specific implementation.
792317cc
ST
11596 @}
11597else
11598 @{
bafa88c2 11599 do_generic (); // Generic implementation.
792317cc
ST
11600 @}
11601@end smallexample
11602@end deftypefn
11603
11604@deftypefn {Built-in Function} int __builtin_cpu_supports (const char *@var{feature})
566fb011
SL
11605This function returns a positive integer if the run-time CPU
11606supports @var{feature}
11607and returns @code{0} otherwise. The following features can be detected:
792317cc
ST
11608
11609@table @samp
11610@item cmov
11611CMOV instruction.
11612@item mmx
11613MMX instructions.
11614@item popcnt
11615POPCNT instruction.
11616@item sse
11617SSE instructions.
11618@item sse2
11619SSE2 instructions.
11620@item sse3
11621SSE3 instructions.
11622@item ssse3
11623SSSE3 instructions.
11624@item sse4.1
11625SSE4.1 instructions.
11626@item sse4.2
11627SSE4.2 instructions.
11628@item avx
11629AVX instructions.
5ddecff9
ST
11630@item avx2
11631AVX2 instructions.
792317cc
ST
11632@end table
11633
11634Here is an example:
11635@smallexample
11636if (__builtin_cpu_supports ("popcnt"))
11637 @{
11638 asm("popcnt %1,%0" : "=r"(count) : "rm"(n) : "cc");
11639 @}
11640else
11641 @{
11642 count = generic_countbits (n); //generic implementation.
11643 @}
11644@end smallexample
11645@end deftypefn
11646
11647
0975678f
JM
11648The following built-in functions are made available by @option{-mmmx}.
11649All of them generate the machine instruction that is part of the name.
11650
3ab51846 11651@smallexample
0975678f
JM
11652v8qi __builtin_ia32_paddb (v8qi, v8qi)
11653v4hi __builtin_ia32_paddw (v4hi, v4hi)
11654v2si __builtin_ia32_paddd (v2si, v2si)
11655v8qi __builtin_ia32_psubb (v8qi, v8qi)
11656v4hi __builtin_ia32_psubw (v4hi, v4hi)
11657v2si __builtin_ia32_psubd (v2si, v2si)
11658v8qi __builtin_ia32_paddsb (v8qi, v8qi)
11659v4hi __builtin_ia32_paddsw (v4hi, v4hi)
11660v8qi __builtin_ia32_psubsb (v8qi, v8qi)
11661v4hi __builtin_ia32_psubsw (v4hi, v4hi)
11662v8qi __builtin_ia32_paddusb (v8qi, v8qi)
11663v4hi __builtin_ia32_paddusw (v4hi, v4hi)
11664v8qi __builtin_ia32_psubusb (v8qi, v8qi)
11665v4hi __builtin_ia32_psubusw (v4hi, v4hi)
11666v4hi __builtin_ia32_pmullw (v4hi, v4hi)
11667v4hi __builtin_ia32_pmulhw (v4hi, v4hi)
11668di __builtin_ia32_pand (di, di)
11669di __builtin_ia32_pandn (di,di)
11670di __builtin_ia32_por (di, di)
11671di __builtin_ia32_pxor (di, di)
11672v8qi __builtin_ia32_pcmpeqb (v8qi, v8qi)
11673v4hi __builtin_ia32_pcmpeqw (v4hi, v4hi)
11674v2si __builtin_ia32_pcmpeqd (v2si, v2si)
11675v8qi __builtin_ia32_pcmpgtb (v8qi, v8qi)
11676v4hi __builtin_ia32_pcmpgtw (v4hi, v4hi)
11677v2si __builtin_ia32_pcmpgtd (v2si, v2si)
11678v8qi __builtin_ia32_punpckhbw (v8qi, v8qi)
11679v4hi __builtin_ia32_punpckhwd (v4hi, v4hi)
11680v2si __builtin_ia32_punpckhdq (v2si, v2si)
11681v8qi __builtin_ia32_punpcklbw (v8qi, v8qi)
11682v4hi __builtin_ia32_punpcklwd (v4hi, v4hi)
11683v2si __builtin_ia32_punpckldq (v2si, v2si)
11684v8qi __builtin_ia32_packsswb (v4hi, v4hi)
11685v4hi __builtin_ia32_packssdw (v2si, v2si)
11686v8qi __builtin_ia32_packuswb (v4hi, v4hi)
10a97ae6 11687
52eaae97
UB
11688v4hi __builtin_ia32_psllw (v4hi, v4hi)
11689v2si __builtin_ia32_pslld (v2si, v2si)
11690v1di __builtin_ia32_psllq (v1di, v1di)
11691v4hi __builtin_ia32_psrlw (v4hi, v4hi)
11692v2si __builtin_ia32_psrld (v2si, v2si)
11693v1di __builtin_ia32_psrlq (v1di, v1di)
11694v4hi __builtin_ia32_psraw (v4hi, v4hi)
11695v2si __builtin_ia32_psrad (v2si, v2si)
11696v4hi __builtin_ia32_psllwi (v4hi, int)
11697v2si __builtin_ia32_pslldi (v2si, int)
11698v1di __builtin_ia32_psllqi (v1di, int)
11699v4hi __builtin_ia32_psrlwi (v4hi, int)
11700v2si __builtin_ia32_psrldi (v2si, int)
11701v1di __builtin_ia32_psrlqi (v1di, int)
11702v4hi __builtin_ia32_psrawi (v4hi, int)
11703v2si __builtin_ia32_psradi (v2si, int)
10a97ae6 11704
3ab51846 11705@end smallexample
0975678f
JM
11706
11707The following built-in functions are made available either with
11708@option{-msse}, or with a combination of @option{-m3dnow} and
11709@option{-march=athlon}. All of them generate the machine
11710instruction that is part of the name.
11711
3ab51846 11712@smallexample
0975678f
JM
11713v4hi __builtin_ia32_pmulhuw (v4hi, v4hi)
11714v8qi __builtin_ia32_pavgb (v8qi, v8qi)
11715v4hi __builtin_ia32_pavgw (v4hi, v4hi)
ab555a5b 11716v1di __builtin_ia32_psadbw (v8qi, v8qi)
0975678f
JM
11717v8qi __builtin_ia32_pmaxub (v8qi, v8qi)
11718v4hi __builtin_ia32_pmaxsw (v4hi, v4hi)
11719v8qi __builtin_ia32_pminub (v8qi, v8qi)
11720v4hi __builtin_ia32_pminsw (v4hi, v4hi)
0975678f
JM
11721int __builtin_ia32_pmovmskb (v8qi)
11722void __builtin_ia32_maskmovq (v8qi, v8qi, char *)
11723void __builtin_ia32_movntq (di *, di)
11724void __builtin_ia32_sfence (void)
3ab51846 11725@end smallexample
0975678f
JM
11726
11727The following built-in functions are available when @option{-msse} is used.
11728All of them generate the machine instruction that is part of the name.
11729
3ab51846 11730@smallexample
0975678f
JM
11731int __builtin_ia32_comieq (v4sf, v4sf)
11732int __builtin_ia32_comineq (v4sf, v4sf)
11733int __builtin_ia32_comilt (v4sf, v4sf)
11734int __builtin_ia32_comile (v4sf, v4sf)
11735int __builtin_ia32_comigt (v4sf, v4sf)
11736int __builtin_ia32_comige (v4sf, v4sf)
11737int __builtin_ia32_ucomieq (v4sf, v4sf)
11738int __builtin_ia32_ucomineq (v4sf, v4sf)
11739int __builtin_ia32_ucomilt (v4sf, v4sf)
11740int __builtin_ia32_ucomile (v4sf, v4sf)
11741int __builtin_ia32_ucomigt (v4sf, v4sf)
11742int __builtin_ia32_ucomige (v4sf, v4sf)
11743v4sf __builtin_ia32_addps (v4sf, v4sf)
11744v4sf __builtin_ia32_subps (v4sf, v4sf)
11745v4sf __builtin_ia32_mulps (v4sf, v4sf)
11746v4sf __builtin_ia32_divps (v4sf, v4sf)
11747v4sf __builtin_ia32_addss (v4sf, v4sf)
11748v4sf __builtin_ia32_subss (v4sf, v4sf)
11749v4sf __builtin_ia32_mulss (v4sf, v4sf)
11750v4sf __builtin_ia32_divss (v4sf, v4sf)
41a7c215
CM
11751v4sf __builtin_ia32_cmpeqps (v4sf, v4sf)
11752v4sf __builtin_ia32_cmpltps (v4sf, v4sf)
11753v4sf __builtin_ia32_cmpleps (v4sf, v4sf)
11754v4sf __builtin_ia32_cmpgtps (v4sf, v4sf)
11755v4sf __builtin_ia32_cmpgeps (v4sf, v4sf)
11756v4sf __builtin_ia32_cmpunordps (v4sf, v4sf)
11757v4sf __builtin_ia32_cmpneqps (v4sf, v4sf)
11758v4sf __builtin_ia32_cmpnltps (v4sf, v4sf)
11759v4sf __builtin_ia32_cmpnleps (v4sf, v4sf)
11760v4sf __builtin_ia32_cmpngtps (v4sf, v4sf)
11761v4sf __builtin_ia32_cmpngeps (v4sf, v4sf)
11762v4sf __builtin_ia32_cmpordps (v4sf, v4sf)
11763v4sf __builtin_ia32_cmpeqss (v4sf, v4sf)
11764v4sf __builtin_ia32_cmpltss (v4sf, v4sf)
11765v4sf __builtin_ia32_cmpless (v4sf, v4sf)
11766v4sf __builtin_ia32_cmpunordss (v4sf, v4sf)
11767v4sf __builtin_ia32_cmpneqss (v4sf, v4sf)
11768v4sf __builtin_ia32_cmpnltss (v4sf, v4sf)
11769v4sf __builtin_ia32_cmpnless (v4sf, v4sf)
11770v4sf __builtin_ia32_cmpordss (v4sf, v4sf)
0975678f
JM
11771v4sf __builtin_ia32_maxps (v4sf, v4sf)
11772v4sf __builtin_ia32_maxss (v4sf, v4sf)
11773v4sf __builtin_ia32_minps (v4sf, v4sf)
11774v4sf __builtin_ia32_minss (v4sf, v4sf)
11775v4sf __builtin_ia32_andps (v4sf, v4sf)
11776v4sf __builtin_ia32_andnps (v4sf, v4sf)
11777v4sf __builtin_ia32_orps (v4sf, v4sf)
11778v4sf __builtin_ia32_xorps (v4sf, v4sf)
11779v4sf __builtin_ia32_movss (v4sf, v4sf)
11780v4sf __builtin_ia32_movhlps (v4sf, v4sf)
11781v4sf __builtin_ia32_movlhps (v4sf, v4sf)
11782v4sf __builtin_ia32_unpckhps (v4sf, v4sf)
11783v4sf __builtin_ia32_unpcklps (v4sf, v4sf)
11784v4sf __builtin_ia32_cvtpi2ps (v4sf, v2si)
11785v4sf __builtin_ia32_cvtsi2ss (v4sf, int)
11786v2si __builtin_ia32_cvtps2pi (v4sf)
11787int __builtin_ia32_cvtss2si (v4sf)
11788v2si __builtin_ia32_cvttps2pi (v4sf)
11789int __builtin_ia32_cvttss2si (v4sf)
11790v4sf __builtin_ia32_rcpps (v4sf)
11791v4sf __builtin_ia32_rsqrtps (v4sf)
11792v4sf __builtin_ia32_sqrtps (v4sf)
11793v4sf __builtin_ia32_rcpss (v4sf)
11794v4sf __builtin_ia32_rsqrtss (v4sf)
11795v4sf __builtin_ia32_sqrtss (v4sf)
11796v4sf __builtin_ia32_shufps (v4sf, v4sf, int)
11797void __builtin_ia32_movntps (float *, v4sf)
11798int __builtin_ia32_movmskps (v4sf)
3ab51846 11799@end smallexample
0975678f
JM
11800
11801The following built-in functions are available when @option{-msse} is used.
11802
11803@table @code
0975678f
JM
11804@item v4sf __builtin_ia32_loadups (float *)
11805Generates the @code{movups} machine instruction as a load from memory.
11806@item void __builtin_ia32_storeups (float *, v4sf)
11807Generates the @code{movups} machine instruction as a store to memory.
41a7c215 11808@item v4sf __builtin_ia32_loadss (float *)
0975678f 11809Generates the @code{movss} machine instruction as a load from memory.
bb1418c1 11810@item v4sf __builtin_ia32_loadhps (v4sf, const v2sf *)
0975678f 11811Generates the @code{movhps} machine instruction as a load from memory.
bb1418c1 11812@item v4sf __builtin_ia32_loadlps (v4sf, const v2sf *)
0975678f 11813Generates the @code{movlps} machine instruction as a load from memory
bb1418c1 11814@item void __builtin_ia32_storehps (v2sf *, v4sf)
0975678f 11815Generates the @code{movhps} machine instruction as a store to memory.
bb1418c1 11816@item void __builtin_ia32_storelps (v2sf *, v4sf)
0975678f
JM
11817Generates the @code{movlps} machine instruction as a store to memory.
11818@end table
11819
d7aa4788
RG
11820The following built-in functions are available when @option{-msse2} is used.
11821All of them generate the machine instruction that is part of the name.
11822
11823@smallexample
11824int __builtin_ia32_comisdeq (v2df, v2df)
11825int __builtin_ia32_comisdlt (v2df, v2df)
11826int __builtin_ia32_comisdle (v2df, v2df)
11827int __builtin_ia32_comisdgt (v2df, v2df)
11828int __builtin_ia32_comisdge (v2df, v2df)
11829int __builtin_ia32_comisdneq (v2df, v2df)
11830int __builtin_ia32_ucomisdeq (v2df, v2df)
11831int __builtin_ia32_ucomisdlt (v2df, v2df)
11832int __builtin_ia32_ucomisdle (v2df, v2df)
11833int __builtin_ia32_ucomisdgt (v2df, v2df)
11834int __builtin_ia32_ucomisdge (v2df, v2df)
11835int __builtin_ia32_ucomisdneq (v2df, v2df)
11836v2df __builtin_ia32_cmpeqpd (v2df, v2df)
11837v2df __builtin_ia32_cmpltpd (v2df, v2df)
11838v2df __builtin_ia32_cmplepd (v2df, v2df)
11839v2df __builtin_ia32_cmpgtpd (v2df, v2df)
11840v2df __builtin_ia32_cmpgepd (v2df, v2df)
11841v2df __builtin_ia32_cmpunordpd (v2df, v2df)
11842v2df __builtin_ia32_cmpneqpd (v2df, v2df)
11843v2df __builtin_ia32_cmpnltpd (v2df, v2df)
11844v2df __builtin_ia32_cmpnlepd (v2df, v2df)
11845v2df __builtin_ia32_cmpngtpd (v2df, v2df)
11846v2df __builtin_ia32_cmpngepd (v2df, v2df)
11847v2df __builtin_ia32_cmpordpd (v2df, v2df)
11848v2df __builtin_ia32_cmpeqsd (v2df, v2df)
11849v2df __builtin_ia32_cmpltsd (v2df, v2df)
11850v2df __builtin_ia32_cmplesd (v2df, v2df)
11851v2df __builtin_ia32_cmpunordsd (v2df, v2df)
11852v2df __builtin_ia32_cmpneqsd (v2df, v2df)
11853v2df __builtin_ia32_cmpnltsd (v2df, v2df)
11854v2df __builtin_ia32_cmpnlesd (v2df, v2df)
11855v2df __builtin_ia32_cmpordsd (v2df, v2df)
11856v2di __builtin_ia32_paddq (v2di, v2di)
11857v2di __builtin_ia32_psubq (v2di, v2di)
11858v2df __builtin_ia32_addpd (v2df, v2df)
11859v2df __builtin_ia32_subpd (v2df, v2df)
11860v2df __builtin_ia32_mulpd (v2df, v2df)
11861v2df __builtin_ia32_divpd (v2df, v2df)
11862v2df __builtin_ia32_addsd (v2df, v2df)
11863v2df __builtin_ia32_subsd (v2df, v2df)
11864v2df __builtin_ia32_mulsd (v2df, v2df)
11865v2df __builtin_ia32_divsd (v2df, v2df)
11866v2df __builtin_ia32_minpd (v2df, v2df)
11867v2df __builtin_ia32_maxpd (v2df, v2df)
11868v2df __builtin_ia32_minsd (v2df, v2df)
11869v2df __builtin_ia32_maxsd (v2df, v2df)
11870v2df __builtin_ia32_andpd (v2df, v2df)
11871v2df __builtin_ia32_andnpd (v2df, v2df)
11872v2df __builtin_ia32_orpd (v2df, v2df)
11873v2df __builtin_ia32_xorpd (v2df, v2df)
11874v2df __builtin_ia32_movsd (v2df, v2df)
11875v2df __builtin_ia32_unpckhpd (v2df, v2df)
11876v2df __builtin_ia32_unpcklpd (v2df, v2df)
11877v16qi __builtin_ia32_paddb128 (v16qi, v16qi)
11878v8hi __builtin_ia32_paddw128 (v8hi, v8hi)
11879v4si __builtin_ia32_paddd128 (v4si, v4si)
11880v2di __builtin_ia32_paddq128 (v2di, v2di)
11881v16qi __builtin_ia32_psubb128 (v16qi, v16qi)
11882v8hi __builtin_ia32_psubw128 (v8hi, v8hi)
11883v4si __builtin_ia32_psubd128 (v4si, v4si)
11884v2di __builtin_ia32_psubq128 (v2di, v2di)
11885v8hi __builtin_ia32_pmullw128 (v8hi, v8hi)
11886v8hi __builtin_ia32_pmulhw128 (v8hi, v8hi)
11887v2di __builtin_ia32_pand128 (v2di, v2di)
11888v2di __builtin_ia32_pandn128 (v2di, v2di)
11889v2di __builtin_ia32_por128 (v2di, v2di)
11890v2di __builtin_ia32_pxor128 (v2di, v2di)
11891v16qi __builtin_ia32_pavgb128 (v16qi, v16qi)
11892v8hi __builtin_ia32_pavgw128 (v8hi, v8hi)
11893v16qi __builtin_ia32_pcmpeqb128 (v16qi, v16qi)
11894v8hi __builtin_ia32_pcmpeqw128 (v8hi, v8hi)
11895v4si __builtin_ia32_pcmpeqd128 (v4si, v4si)
11896v16qi __builtin_ia32_pcmpgtb128 (v16qi, v16qi)
11897v8hi __builtin_ia32_pcmpgtw128 (v8hi, v8hi)
11898v4si __builtin_ia32_pcmpgtd128 (v4si, v4si)
11899v16qi __builtin_ia32_pmaxub128 (v16qi, v16qi)
11900v8hi __builtin_ia32_pmaxsw128 (v8hi, v8hi)
11901v16qi __builtin_ia32_pminub128 (v16qi, v16qi)
11902v8hi __builtin_ia32_pminsw128 (v8hi, v8hi)
11903v16qi __builtin_ia32_punpckhbw128 (v16qi, v16qi)
11904v8hi __builtin_ia32_punpckhwd128 (v8hi, v8hi)
11905v4si __builtin_ia32_punpckhdq128 (v4si, v4si)
11906v2di __builtin_ia32_punpckhqdq128 (v2di, v2di)
11907v16qi __builtin_ia32_punpcklbw128 (v16qi, v16qi)
11908v8hi __builtin_ia32_punpcklwd128 (v8hi, v8hi)
11909v4si __builtin_ia32_punpckldq128 (v4si, v4si)
11910v2di __builtin_ia32_punpcklqdq128 (v2di, v2di)
1b667c82
L
11911v16qi __builtin_ia32_packsswb128 (v8hi, v8hi)
11912v8hi __builtin_ia32_packssdw128 (v4si, v4si)
11913v16qi __builtin_ia32_packuswb128 (v8hi, v8hi)
d7aa4788
RG
11914v8hi __builtin_ia32_pmulhuw128 (v8hi, v8hi)
11915void __builtin_ia32_maskmovdqu (v16qi, v16qi)
11916v2df __builtin_ia32_loadupd (double *)
11917void __builtin_ia32_storeupd (double *, v2df)
bb1418c1
L
11918v2df __builtin_ia32_loadhpd (v2df, double const *)
11919v2df __builtin_ia32_loadlpd (v2df, double const *)
d7aa4788
RG
11920int __builtin_ia32_movmskpd (v2df)
11921int __builtin_ia32_pmovmskb128 (v16qi)
11922void __builtin_ia32_movnti (int *, int)
f32c951e 11923void __builtin_ia32_movnti64 (long long int *, long long int)
d7aa4788
RG
11924void __builtin_ia32_movntpd (double *, v2df)
11925void __builtin_ia32_movntdq (v2df *, v2df)
11926v4si __builtin_ia32_pshufd (v4si, int)
11927v8hi __builtin_ia32_pshuflw (v8hi, int)
11928v8hi __builtin_ia32_pshufhw (v8hi, int)
11929v2di __builtin_ia32_psadbw128 (v16qi, v16qi)
11930v2df __builtin_ia32_sqrtpd (v2df)
11931v2df __builtin_ia32_sqrtsd (v2df)
11932v2df __builtin_ia32_shufpd (v2df, v2df, int)
11933v2df __builtin_ia32_cvtdq2pd (v4si)
11934v4sf __builtin_ia32_cvtdq2ps (v4si)
11935v4si __builtin_ia32_cvtpd2dq (v2df)
11936v2si __builtin_ia32_cvtpd2pi (v2df)
11937v4sf __builtin_ia32_cvtpd2ps (v2df)
11938v4si __builtin_ia32_cvttpd2dq (v2df)
11939v2si __builtin_ia32_cvttpd2pi (v2df)
11940v2df __builtin_ia32_cvtpi2pd (v2si)
11941int __builtin_ia32_cvtsd2si (v2df)
11942int __builtin_ia32_cvttsd2si (v2df)
11943long long __builtin_ia32_cvtsd2si64 (v2df)
11944long long __builtin_ia32_cvttsd2si64 (v2df)
11945v4si __builtin_ia32_cvtps2dq (v4sf)
11946v2df __builtin_ia32_cvtps2pd (v4sf)
11947v4si __builtin_ia32_cvttps2dq (v4sf)
11948v2df __builtin_ia32_cvtsi2sd (v2df, int)
11949v2df __builtin_ia32_cvtsi642sd (v2df, long long)
11950v4sf __builtin_ia32_cvtsd2ss (v4sf, v2df)
11951v2df __builtin_ia32_cvtss2sd (v2df, v4sf)
11952void __builtin_ia32_clflush (const void *)
11953void __builtin_ia32_lfence (void)
11954void __builtin_ia32_mfence (void)
11955v16qi __builtin_ia32_loaddqu (const char *)
11956void __builtin_ia32_storedqu (char *, v16qi)
ab555a5b 11957v1di __builtin_ia32_pmuludq (v2si, v2si)
d7aa4788 11958v2di __builtin_ia32_pmuludq128 (v4si, v4si)
52eaae97
UB
11959v8hi __builtin_ia32_psllw128 (v8hi, v8hi)
11960v4si __builtin_ia32_pslld128 (v4si, v4si)
11961v2di __builtin_ia32_psllq128 (v2di, v2di)
11962v8hi __builtin_ia32_psrlw128 (v8hi, v8hi)
11963v4si __builtin_ia32_psrld128 (v4si, v4si)
d7aa4788 11964v2di __builtin_ia32_psrlq128 (v2di, v2di)
52eaae97
UB
11965v8hi __builtin_ia32_psraw128 (v8hi, v8hi)
11966v4si __builtin_ia32_psrad128 (v4si, v4si)
d7aa4788
RG
11967v2di __builtin_ia32_pslldqi128 (v2di, int)
11968v8hi __builtin_ia32_psllwi128 (v8hi, int)
11969v4si __builtin_ia32_pslldi128 (v4si, int)
11970v2di __builtin_ia32_psllqi128 (v2di, int)
11971v2di __builtin_ia32_psrldqi128 (v2di, int)
11972v8hi __builtin_ia32_psrlwi128 (v8hi, int)
11973v4si __builtin_ia32_psrldi128 (v4si, int)
11974v2di __builtin_ia32_psrlqi128 (v2di, int)
11975v8hi __builtin_ia32_psrawi128 (v8hi, int)
11976v4si __builtin_ia32_psradi128 (v4si, int)
11977v4si __builtin_ia32_pmaddwd128 (v8hi, v8hi)
b53b23dc 11978v2di __builtin_ia32_movq128 (v2di)
d7aa4788
RG
11979@end smallexample
11980
9e200aaf 11981The following built-in functions are available when @option{-msse3} is used.
22c7c85e
L
11982All of them generate the machine instruction that is part of the name.
11983
3ab51846 11984@smallexample
22c7c85e 11985v2df __builtin_ia32_addsubpd (v2df, v2df)
d7aa4788 11986v4sf __builtin_ia32_addsubps (v4sf, v4sf)
22c7c85e 11987v2df __builtin_ia32_haddpd (v2df, v2df)
d7aa4788 11988v4sf __builtin_ia32_haddps (v4sf, v4sf)
22c7c85e 11989v2df __builtin_ia32_hsubpd (v2df, v2df)
d7aa4788 11990v4sf __builtin_ia32_hsubps (v4sf, v4sf)
22c7c85e
L
11991v16qi __builtin_ia32_lddqu (char const *)
11992void __builtin_ia32_monitor (void *, unsigned int, unsigned int)
22c7c85e
L
11993v4sf __builtin_ia32_movshdup (v4sf)
11994v4sf __builtin_ia32_movsldup (v4sf)
11995void __builtin_ia32_mwait (unsigned int, unsigned int)
3ab51846 11996@end smallexample
22c7c85e 11997
b1875f52 11998The following built-in functions are available when @option{-mssse3} is used.
893e85fa 11999All of them generate the machine instruction that is part of the name.
b1875f52
L
12000
12001@smallexample
12002v2si __builtin_ia32_phaddd (v2si, v2si)
12003v4hi __builtin_ia32_phaddw (v4hi, v4hi)
12004v4hi __builtin_ia32_phaddsw (v4hi, v4hi)
12005v2si __builtin_ia32_phsubd (v2si, v2si)
12006v4hi __builtin_ia32_phsubw (v4hi, v4hi)
12007v4hi __builtin_ia32_phsubsw (v4hi, v4hi)
1b667c82 12008v4hi __builtin_ia32_pmaddubsw (v8qi, v8qi)
b1875f52
L
12009v4hi __builtin_ia32_pmulhrsw (v4hi, v4hi)
12010v8qi __builtin_ia32_pshufb (v8qi, v8qi)
12011v8qi __builtin_ia32_psignb (v8qi, v8qi)
12012v2si __builtin_ia32_psignd (v2si, v2si)
12013v4hi __builtin_ia32_psignw (v4hi, v4hi)
99c25ac1 12014v1di __builtin_ia32_palignr (v1di, v1di, int)
b1875f52
L
12015v8qi __builtin_ia32_pabsb (v8qi)
12016v2si __builtin_ia32_pabsd (v2si)
12017v4hi __builtin_ia32_pabsw (v4hi)
12018@end smallexample
12019
12020The following built-in functions are available when @option{-mssse3} is used.
893e85fa 12021All of them generate the machine instruction that is part of the name.
b1875f52
L
12022
12023@smallexample
12024v4si __builtin_ia32_phaddd128 (v4si, v4si)
12025v8hi __builtin_ia32_phaddw128 (v8hi, v8hi)
12026v8hi __builtin_ia32_phaddsw128 (v8hi, v8hi)
12027v4si __builtin_ia32_phsubd128 (v4si, v4si)
12028v8hi __builtin_ia32_phsubw128 (v8hi, v8hi)
12029v8hi __builtin_ia32_phsubsw128 (v8hi, v8hi)
1b667c82 12030v8hi __builtin_ia32_pmaddubsw128 (v16qi, v16qi)
b1875f52
L
12031v8hi __builtin_ia32_pmulhrsw128 (v8hi, v8hi)
12032v16qi __builtin_ia32_pshufb128 (v16qi, v16qi)
12033v16qi __builtin_ia32_psignb128 (v16qi, v16qi)
12034v4si __builtin_ia32_psignd128 (v4si, v4si)
12035v8hi __builtin_ia32_psignw128 (v8hi, v8hi)
858e5e79 12036v2di __builtin_ia32_palignr128 (v2di, v2di, int)
b1875f52
L
12037v16qi __builtin_ia32_pabsb128 (v16qi)
12038v4si __builtin_ia32_pabsd128 (v4si)
12039v8hi __builtin_ia32_pabsw128 (v8hi)
12040@end smallexample
12041
9a5cee02
L
12042The following built-in functions are available when @option{-msse4.1} is
12043used. All of them generate the machine instruction that is part of the
12044name.
12045
12046@smallexample
12047v2df __builtin_ia32_blendpd (v2df, v2df, const int)
12048v4sf __builtin_ia32_blendps (v4sf, v4sf, const int)
12049v2df __builtin_ia32_blendvpd (v2df, v2df, v2df)
12050v4sf __builtin_ia32_blendvps (v4sf, v4sf, v4sf)
291d9a2d 12051v2df __builtin_ia32_dppd (v2df, v2df, const int)
9a5cee02
L
12052v4sf __builtin_ia32_dpps (v4sf, v4sf, const int)
12053v4sf __builtin_ia32_insertps128 (v4sf, v4sf, const int)
12054v2di __builtin_ia32_movntdqa (v2di *);
12055v16qi __builtin_ia32_mpsadbw128 (v16qi, v16qi, const int)
12056v8hi __builtin_ia32_packusdw128 (v4si, v4si)
12057v16qi __builtin_ia32_pblendvb128 (v16qi, v16qi, v16qi)
12058v8hi __builtin_ia32_pblendw128 (v8hi, v8hi, const int)
12059v2di __builtin_ia32_pcmpeqq (v2di, v2di)
12060v8hi __builtin_ia32_phminposuw128 (v8hi)
12061v16qi __builtin_ia32_pmaxsb128 (v16qi, v16qi)
12062v4si __builtin_ia32_pmaxsd128 (v4si, v4si)
12063v4si __builtin_ia32_pmaxud128 (v4si, v4si)
12064v8hi __builtin_ia32_pmaxuw128 (v8hi, v8hi)
12065v16qi __builtin_ia32_pminsb128 (v16qi, v16qi)
12066v4si __builtin_ia32_pminsd128 (v4si, v4si)
12067v4si __builtin_ia32_pminud128 (v4si, v4si)
12068v8hi __builtin_ia32_pminuw128 (v8hi, v8hi)
12069v4si __builtin_ia32_pmovsxbd128 (v16qi)
12070v2di __builtin_ia32_pmovsxbq128 (v16qi)
12071v8hi __builtin_ia32_pmovsxbw128 (v16qi)
12072v2di __builtin_ia32_pmovsxdq128 (v4si)
12073v4si __builtin_ia32_pmovsxwd128 (v8hi)
12074v2di __builtin_ia32_pmovsxwq128 (v8hi)
12075v4si __builtin_ia32_pmovzxbd128 (v16qi)
12076v2di __builtin_ia32_pmovzxbq128 (v16qi)
12077v8hi __builtin_ia32_pmovzxbw128 (v16qi)
12078v2di __builtin_ia32_pmovzxdq128 (v4si)
12079v4si __builtin_ia32_pmovzxwd128 (v8hi)
12080v2di __builtin_ia32_pmovzxwq128 (v8hi)
12081v2di __builtin_ia32_pmuldq128 (v4si, v4si)
12082v4si __builtin_ia32_pmulld128 (v4si, v4si)
12083int __builtin_ia32_ptestc128 (v2di, v2di)
12084int __builtin_ia32_ptestnzc128 (v2di, v2di)
12085int __builtin_ia32_ptestz128 (v2di, v2di)
12086v2df __builtin_ia32_roundpd (v2df, const int)
12087v4sf __builtin_ia32_roundps (v4sf, const int)
12088v2df __builtin_ia32_roundsd (v2df, v2df, const int)
12089v4sf __builtin_ia32_roundss (v4sf, v4sf, const int)
12090@end smallexample
12091
12092The following built-in functions are available when @option{-msse4.1} is
12093used.
12094
12095@table @code
12096@item v4sf __builtin_ia32_vec_set_v4sf (v4sf, float, const int)
12097Generates the @code{insertps} machine instruction.
12098@item int __builtin_ia32_vec_ext_v16qi (v16qi, const int)
12099Generates the @code{pextrb} machine instruction.
12100@item v16qi __builtin_ia32_vec_set_v16qi (v16qi, int, const int)
12101Generates the @code{pinsrb} machine instruction.
12102@item v4si __builtin_ia32_vec_set_v4si (v4si, int, const int)
12103Generates the @code{pinsrd} machine instruction.
12104@item v2di __builtin_ia32_vec_set_v2di (v2di, long long, const int)
12105Generates the @code{pinsrq} machine instruction in 64bit mode.
12106@end table
12107
12108The following built-in functions are changed to generate new SSE4.1
12109instructions when @option{-msse4.1} is used.
12110
12111@table @code
12112@item float __builtin_ia32_vec_ext_v4sf (v4sf, const int)
12113Generates the @code{extractps} machine instruction.
12114@item int __builtin_ia32_vec_ext_v4si (v4si, const int)
12115Generates the @code{pextrd} machine instruction.
12116@item long long __builtin_ia32_vec_ext_v2di (v2di, const int)
12117Generates the @code{pextrq} machine instruction in 64bit mode.
12118@end table
12119
3b8dd071
L
12120The following built-in functions are available when @option{-msse4.2} is
12121used. All of them generate the machine instruction that is part of the
12122name.
12123
12124@smallexample
12125v16qi __builtin_ia32_pcmpestrm128 (v16qi, int, v16qi, int, const int)
12126int __builtin_ia32_pcmpestri128 (v16qi, int, v16qi, int, const int)
12127int __builtin_ia32_pcmpestria128 (v16qi, int, v16qi, int, const int)
12128int __builtin_ia32_pcmpestric128 (v16qi, int, v16qi, int, const int)
12129int __builtin_ia32_pcmpestrio128 (v16qi, int, v16qi, int, const int)
12130int __builtin_ia32_pcmpestris128 (v16qi, int, v16qi, int, const int)
12131int __builtin_ia32_pcmpestriz128 (v16qi, int, v16qi, int, const int)
12132v16qi __builtin_ia32_pcmpistrm128 (v16qi, v16qi, const int)
12133int __builtin_ia32_pcmpistri128 (v16qi, v16qi, const int)
12134int __builtin_ia32_pcmpistria128 (v16qi, v16qi, const int)
12135int __builtin_ia32_pcmpistric128 (v16qi, v16qi, const int)
12136int __builtin_ia32_pcmpistrio128 (v16qi, v16qi, const int)
12137int __builtin_ia32_pcmpistris128 (v16qi, v16qi, const int)
12138int __builtin_ia32_pcmpistriz128 (v16qi, v16qi, const int)
291d9a2d 12139v2di __builtin_ia32_pcmpgtq (v2di, v2di)
3b8dd071
L
12140@end smallexample
12141
12142The following built-in functions are available when @option{-msse4.2} is
12143used.
12144
12145@table @code
291d9a2d 12146@item unsigned int __builtin_ia32_crc32qi (unsigned int, unsigned char)
3b8dd071 12147Generates the @code{crc32b} machine instruction.
291d9a2d 12148@item unsigned int __builtin_ia32_crc32hi (unsigned int, unsigned short)
3b8dd071 12149Generates the @code{crc32w} machine instruction.
291d9a2d 12150@item unsigned int __builtin_ia32_crc32si (unsigned int, unsigned int)
3b8dd071 12151Generates the @code{crc32l} machine instruction.
a44acfb9 12152@item unsigned long long __builtin_ia32_crc32di (unsigned long long, unsigned long long)
412ac8d5 12153Generates the @code{crc32q} machine instruction.
3b8dd071
L
12154@end table
12155
12156The following built-in functions are changed to generate new SSE4.2
12157instructions when @option{-msse4.2} is used.
12158
12159@table @code
291d9a2d 12160@item int __builtin_popcount (unsigned int)
3b8dd071 12161Generates the @code{popcntl} machine instruction.
291d9a2d 12162@item int __builtin_popcountl (unsigned long)
3b8dd071
L
12163Generates the @code{popcntl} or @code{popcntq} machine instruction,
12164depending on the size of @code{unsigned long}.
291d9a2d 12165@item int __builtin_popcountll (unsigned long long)
3b8dd071
L
12166Generates the @code{popcntq} machine instruction.
12167@end table
12168
31cb596a
JY
12169The following built-in functions are available when @option{-mavx} is
12170used. All of them generate the machine instruction that is part of the
12171name.
12172
12173@smallexample
12174v4df __builtin_ia32_addpd256 (v4df,v4df)
12175v8sf __builtin_ia32_addps256 (v8sf,v8sf)
12176v4df __builtin_ia32_addsubpd256 (v4df,v4df)
12177v8sf __builtin_ia32_addsubps256 (v8sf,v8sf)
12178v4df __builtin_ia32_andnpd256 (v4df,v4df)
12179v8sf __builtin_ia32_andnps256 (v8sf,v8sf)
12180v4df __builtin_ia32_andpd256 (v4df,v4df)
12181v8sf __builtin_ia32_andps256 (v8sf,v8sf)
12182v4df __builtin_ia32_blendpd256 (v4df,v4df,int)
12183v8sf __builtin_ia32_blendps256 (v8sf,v8sf,int)
12184v4df __builtin_ia32_blendvpd256 (v4df,v4df,v4df)
12185v8sf __builtin_ia32_blendvps256 (v8sf,v8sf,v8sf)
12186v2df __builtin_ia32_cmppd (v2df,v2df,int)
12187v4df __builtin_ia32_cmppd256 (v4df,v4df,int)
12188v4sf __builtin_ia32_cmpps (v4sf,v4sf,int)
12189v8sf __builtin_ia32_cmpps256 (v8sf,v8sf,int)
12190v2df __builtin_ia32_cmpsd (v2df,v2df,int)
12191v4sf __builtin_ia32_cmpss (v4sf,v4sf,int)
12192v4df __builtin_ia32_cvtdq2pd256 (v4si)
12193v8sf __builtin_ia32_cvtdq2ps256 (v8si)
12194v4si __builtin_ia32_cvtpd2dq256 (v4df)
12195v4sf __builtin_ia32_cvtpd2ps256 (v4df)
12196v8si __builtin_ia32_cvtps2dq256 (v8sf)
12197v4df __builtin_ia32_cvtps2pd256 (v4sf)
12198v4si __builtin_ia32_cvttpd2dq256 (v4df)
12199v8si __builtin_ia32_cvttps2dq256 (v8sf)
12200v4df __builtin_ia32_divpd256 (v4df,v4df)
12201v8sf __builtin_ia32_divps256 (v8sf,v8sf)
12202v8sf __builtin_ia32_dpps256 (v8sf,v8sf,int)
12203v4df __builtin_ia32_haddpd256 (v4df,v4df)
12204v8sf __builtin_ia32_haddps256 (v8sf,v8sf)
12205v4df __builtin_ia32_hsubpd256 (v4df,v4df)
12206v8sf __builtin_ia32_hsubps256 (v8sf,v8sf)
12207v32qi __builtin_ia32_lddqu256 (pcchar)
12208v32qi __builtin_ia32_loaddqu256 (pcchar)
12209v4df __builtin_ia32_loadupd256 (pcdouble)
12210v8sf __builtin_ia32_loadups256 (pcfloat)
12211v2df __builtin_ia32_maskloadpd (pcv2df,v2df)
12212v4df __builtin_ia32_maskloadpd256 (pcv4df,v4df)
12213v4sf __builtin_ia32_maskloadps (pcv4sf,v4sf)
12214v8sf __builtin_ia32_maskloadps256 (pcv8sf,v8sf)
12215void __builtin_ia32_maskstorepd (pv2df,v2df,v2df)
12216void __builtin_ia32_maskstorepd256 (pv4df,v4df,v4df)
12217void __builtin_ia32_maskstoreps (pv4sf,v4sf,v4sf)
12218void __builtin_ia32_maskstoreps256 (pv8sf,v8sf,v8sf)
12219v4df __builtin_ia32_maxpd256 (v4df,v4df)
12220v8sf __builtin_ia32_maxps256 (v8sf,v8sf)
12221v4df __builtin_ia32_minpd256 (v4df,v4df)
12222v8sf __builtin_ia32_minps256 (v8sf,v8sf)
12223v4df __builtin_ia32_movddup256 (v4df)
12224int __builtin_ia32_movmskpd256 (v4df)
12225int __builtin_ia32_movmskps256 (v8sf)
12226v8sf __builtin_ia32_movshdup256 (v8sf)
12227v8sf __builtin_ia32_movsldup256 (v8sf)
12228v4df __builtin_ia32_mulpd256 (v4df,v4df)
12229v8sf __builtin_ia32_mulps256 (v8sf,v8sf)
12230v4df __builtin_ia32_orpd256 (v4df,v4df)
12231v8sf __builtin_ia32_orps256 (v8sf,v8sf)
12232v2df __builtin_ia32_pd_pd256 (v4df)
12233v4df __builtin_ia32_pd256_pd (v2df)
12234v4sf __builtin_ia32_ps_ps256 (v8sf)
12235v8sf __builtin_ia32_ps256_ps (v4sf)
12236int __builtin_ia32_ptestc256 (v4di,v4di,ptest)
12237int __builtin_ia32_ptestnzc256 (v4di,v4di,ptest)
12238int __builtin_ia32_ptestz256 (v4di,v4di,ptest)
12239v8sf __builtin_ia32_rcpps256 (v8sf)
12240v4df __builtin_ia32_roundpd256 (v4df,int)
12241v8sf __builtin_ia32_roundps256 (v8sf,int)
12242v8sf __builtin_ia32_rsqrtps_nr256 (v8sf)
12243v8sf __builtin_ia32_rsqrtps256 (v8sf)
12244v4df __builtin_ia32_shufpd256 (v4df,v4df,int)
12245v8sf __builtin_ia32_shufps256 (v8sf,v8sf,int)
12246v4si __builtin_ia32_si_si256 (v8si)
12247v8si __builtin_ia32_si256_si (v4si)
12248v4df __builtin_ia32_sqrtpd256 (v4df)
12249v8sf __builtin_ia32_sqrtps_nr256 (v8sf)
12250v8sf __builtin_ia32_sqrtps256 (v8sf)
12251void __builtin_ia32_storedqu256 (pchar,v32qi)
12252void __builtin_ia32_storeupd256 (pdouble,v4df)
12253void __builtin_ia32_storeups256 (pfloat,v8sf)
12254v4df __builtin_ia32_subpd256 (v4df,v4df)
12255v8sf __builtin_ia32_subps256 (v8sf,v8sf)
12256v4df __builtin_ia32_unpckhpd256 (v4df,v4df)
12257v8sf __builtin_ia32_unpckhps256 (v8sf,v8sf)
12258v4df __builtin_ia32_unpcklpd256 (v4df,v4df)
12259v8sf __builtin_ia32_unpcklps256 (v8sf,v8sf)
12260v4df __builtin_ia32_vbroadcastf128_pd256 (pcv2df)
12261v8sf __builtin_ia32_vbroadcastf128_ps256 (pcv4sf)
12262v4df __builtin_ia32_vbroadcastsd256 (pcdouble)
12263v4sf __builtin_ia32_vbroadcastss (pcfloat)
12264v8sf __builtin_ia32_vbroadcastss256 (pcfloat)
12265v2df __builtin_ia32_vextractf128_pd256 (v4df,int)
12266v4sf __builtin_ia32_vextractf128_ps256 (v8sf,int)
12267v4si __builtin_ia32_vextractf128_si256 (v8si,int)
12268v4df __builtin_ia32_vinsertf128_pd256 (v4df,v2df,int)
12269v8sf __builtin_ia32_vinsertf128_ps256 (v8sf,v4sf,int)
12270v8si __builtin_ia32_vinsertf128_si256 (v8si,v4si,int)
12271v4df __builtin_ia32_vperm2f128_pd256 (v4df,v4df,int)
12272v8sf __builtin_ia32_vperm2f128_ps256 (v8sf,v8sf,int)
12273v8si __builtin_ia32_vperm2f128_si256 (v8si,v8si,int)
12274v2df __builtin_ia32_vpermil2pd (v2df,v2df,v2di,int)
12275v4df __builtin_ia32_vpermil2pd256 (v4df,v4df,v4di,int)
12276v4sf __builtin_ia32_vpermil2ps (v4sf,v4sf,v4si,int)
12277v8sf __builtin_ia32_vpermil2ps256 (v8sf,v8sf,v8si,int)
12278v2df __builtin_ia32_vpermilpd (v2df,int)
12279v4df __builtin_ia32_vpermilpd256 (v4df,int)
12280v4sf __builtin_ia32_vpermilps (v4sf,int)
12281v8sf __builtin_ia32_vpermilps256 (v8sf,int)
12282v2df __builtin_ia32_vpermilvarpd (v2df,v2di)
12283v4df __builtin_ia32_vpermilvarpd256 (v4df,v4di)
12284v4sf __builtin_ia32_vpermilvarps (v4sf,v4si)
12285v8sf __builtin_ia32_vpermilvarps256 (v8sf,v8si)
12286int __builtin_ia32_vtestcpd (v2df,v2df,ptest)
12287int __builtin_ia32_vtestcpd256 (v4df,v4df,ptest)
12288int __builtin_ia32_vtestcps (v4sf,v4sf,ptest)
12289int __builtin_ia32_vtestcps256 (v8sf,v8sf,ptest)
12290int __builtin_ia32_vtestnzcpd (v2df,v2df,ptest)
12291int __builtin_ia32_vtestnzcpd256 (v4df,v4df,ptest)
12292int __builtin_ia32_vtestnzcps (v4sf,v4sf,ptest)
12293int __builtin_ia32_vtestnzcps256 (v8sf,v8sf,ptest)
12294int __builtin_ia32_vtestzpd (v2df,v2df,ptest)
12295int __builtin_ia32_vtestzpd256 (v4df,v4df,ptest)
12296int __builtin_ia32_vtestzps (v4sf,v4sf,ptest)
12297int __builtin_ia32_vtestzps256 (v8sf,v8sf,ptest)
12298void __builtin_ia32_vzeroall (void)
12299void __builtin_ia32_vzeroupper (void)
12300v4df __builtin_ia32_xorpd256 (v4df,v4df)
12301v8sf __builtin_ia32_xorps256 (v8sf,v8sf)
12302@end smallexample
12303
977e83a3
KY
12304The following built-in functions are available when @option{-mavx2} is
12305used. All of them generate the machine instruction that is part of the
12306name.
12307
12308@smallexample
d4082970 12309v32qi __builtin_ia32_mpsadbw256 (v32qi,v32qi,int)
977e83a3
KY
12310v32qi __builtin_ia32_pabsb256 (v32qi)
12311v16hi __builtin_ia32_pabsw256 (v16hi)
12312v8si __builtin_ia32_pabsd256 (v8si)
5bc35113 12313v16hi __builtin_ia32_packssdw256 (v8si,v8si)
977e83a3
KY
12314v32qi __builtin_ia32_packsswb256 (v16hi,v16hi)
12315v16hi __builtin_ia32_packusdw256 (v8si,v8si)
12316v32qi __builtin_ia32_packuswb256 (v16hi,v16hi)
3f287e4b 12317v32qi __builtin_ia32_paddb256 (v32qi,v32qi)
977e83a3
KY
12318v16hi __builtin_ia32_paddw256 (v16hi,v16hi)
12319v8si __builtin_ia32_paddd256 (v8si,v8si)
12320v4di __builtin_ia32_paddq256 (v4di,v4di)
12321v32qi __builtin_ia32_paddsb256 (v32qi,v32qi)
12322v16hi __builtin_ia32_paddsw256 (v16hi,v16hi)
12323v32qi __builtin_ia32_paddusb256 (v32qi,v32qi)
12324v16hi __builtin_ia32_paddusw256 (v16hi,v16hi)
12325v4di __builtin_ia32_palignr256 (v4di,v4di,int)
12326v4di __builtin_ia32_andsi256 (v4di,v4di)
12327v4di __builtin_ia32_andnotsi256 (v4di,v4di)
3f287e4b 12328v32qi __builtin_ia32_pavgb256 (v32qi,v32qi)
977e83a3
KY
12329v16hi __builtin_ia32_pavgw256 (v16hi,v16hi)
12330v32qi __builtin_ia32_pblendvb256 (v32qi,v32qi,v32qi)
12331v16hi __builtin_ia32_pblendw256 (v16hi,v16hi,int)
12332v32qi __builtin_ia32_pcmpeqb256 (v32qi,v32qi)
12333v16hi __builtin_ia32_pcmpeqw256 (v16hi,v16hi)
12334v8si __builtin_ia32_pcmpeqd256 (c8si,v8si)
12335v4di __builtin_ia32_pcmpeqq256 (v4di,v4di)
12336v32qi __builtin_ia32_pcmpgtb256 (v32qi,v32qi)
12337v16hi __builtin_ia32_pcmpgtw256 (16hi,v16hi)
12338v8si __builtin_ia32_pcmpgtd256 (v8si,v8si)
12339v4di __builtin_ia32_pcmpgtq256 (v4di,v4di)
12340v16hi __builtin_ia32_phaddw256 (v16hi,v16hi)
12341v8si __builtin_ia32_phaddd256 (v8si,v8si)
12342v16hi __builtin_ia32_phaddsw256 (v16hi,v16hi)
12343v16hi __builtin_ia32_phsubw256 (v16hi,v16hi)
12344v8si __builtin_ia32_phsubd256 (v8si,v8si)
12345v16hi __builtin_ia32_phsubsw256 (v16hi,v16hi)
12346v32qi __builtin_ia32_pmaddubsw256 (v32qi,v32qi)
12347v16hi __builtin_ia32_pmaddwd256 (v16hi,v16hi)
12348v32qi __builtin_ia32_pmaxsb256 (v32qi,v32qi)
12349v16hi __builtin_ia32_pmaxsw256 (v16hi,v16hi)
12350v8si __builtin_ia32_pmaxsd256 (v8si,v8si)
12351v32qi __builtin_ia32_pmaxub256 (v32qi,v32qi)
12352v16hi __builtin_ia32_pmaxuw256 (v16hi,v16hi)
12353v8si __builtin_ia32_pmaxud256 (v8si,v8si)
12354v32qi __builtin_ia32_pminsb256 (v32qi,v32qi)
12355v16hi __builtin_ia32_pminsw256 (v16hi,v16hi)
12356v8si __builtin_ia32_pminsd256 (v8si,v8si)
12357v32qi __builtin_ia32_pminub256 (v32qi,v32qi)
12358v16hi __builtin_ia32_pminuw256 (v16hi,v16hi)
12359v8si __builtin_ia32_pminud256 (v8si,v8si)
12360int __builtin_ia32_pmovmskb256 (v32qi)
12361v16hi __builtin_ia32_pmovsxbw256 (v16qi)
12362v8si __builtin_ia32_pmovsxbd256 (v16qi)
12363v4di __builtin_ia32_pmovsxbq256 (v16qi)
12364v8si __builtin_ia32_pmovsxwd256 (v8hi)
12365v4di __builtin_ia32_pmovsxwq256 (v8hi)
12366v4di __builtin_ia32_pmovsxdq256 (v4si)
12367v16hi __builtin_ia32_pmovzxbw256 (v16qi)
12368v8si __builtin_ia32_pmovzxbd256 (v16qi)
12369v4di __builtin_ia32_pmovzxbq256 (v16qi)
12370v8si __builtin_ia32_pmovzxwd256 (v8hi)
12371v4di __builtin_ia32_pmovzxwq256 (v8hi)
12372v4di __builtin_ia32_pmovzxdq256 (v4si)
12373v4di __builtin_ia32_pmuldq256 (v8si,v8si)
12374v16hi __builtin_ia32_pmulhrsw256 (v16hi, v16hi)
12375v16hi __builtin_ia32_pmulhuw256 (v16hi,v16hi)
12376v16hi __builtin_ia32_pmulhw256 (v16hi,v16hi)
12377v16hi __builtin_ia32_pmullw256 (v16hi,v16hi)
12378v8si __builtin_ia32_pmulld256 (v8si,v8si)
12379v4di __builtin_ia32_pmuludq256 (v8si,v8si)
12380v4di __builtin_ia32_por256 (v4di,v4di)
12381v16hi __builtin_ia32_psadbw256 (v32qi,v32qi)
12382v32qi __builtin_ia32_pshufb256 (v32qi,v32qi)
12383v8si __builtin_ia32_pshufd256 (v8si,int)
12384v16hi __builtin_ia32_pshufhw256 (v16hi,int)
12385v16hi __builtin_ia32_pshuflw256 (v16hi,int)
12386v32qi __builtin_ia32_psignb256 (v32qi,v32qi)
12387v16hi __builtin_ia32_psignw256 (v16hi,v16hi)
12388v8si __builtin_ia32_psignd256 (v8si,v8si)
12389v4di __builtin_ia32_pslldqi256 (v4di,int)
12390v16hi __builtin_ia32_psllwi256 (16hi,int)
12391v16hi __builtin_ia32_psllw256(v16hi,v8hi)
12392v8si __builtin_ia32_pslldi256 (v8si,int)
12393v8si __builtin_ia32_pslld256(v8si,v4si)
12394v4di __builtin_ia32_psllqi256 (v4di,int)
12395v4di __builtin_ia32_psllq256(v4di,v2di)
12396v16hi __builtin_ia32_psrawi256 (v16hi,int)
12397v16hi __builtin_ia32_psraw256 (v16hi,v8hi)
12398v8si __builtin_ia32_psradi256 (v8si,int)
12399v8si __builtin_ia32_psrad256 (v8si,v4si)
12400v4di __builtin_ia32_psrldqi256 (v4di, int)
12401v16hi __builtin_ia32_psrlwi256 (v16hi,int)
12402v16hi __builtin_ia32_psrlw256 (v16hi,v8hi)
12403v8si __builtin_ia32_psrldi256 (v8si,int)
12404v8si __builtin_ia32_psrld256 (v8si,v4si)
12405v4di __builtin_ia32_psrlqi256 (v4di,int)
12406v4di __builtin_ia32_psrlq256(v4di,v2di)
12407v32qi __builtin_ia32_psubb256 (v32qi,v32qi)
12408v32hi __builtin_ia32_psubw256 (v16hi,v16hi)
12409v8si __builtin_ia32_psubd256 (v8si,v8si)
12410v4di __builtin_ia32_psubq256 (v4di,v4di)
12411v32qi __builtin_ia32_psubsb256 (v32qi,v32qi)
12412v16hi __builtin_ia32_psubsw256 (v16hi,v16hi)
12413v32qi __builtin_ia32_psubusb256 (v32qi,v32qi)
12414v16hi __builtin_ia32_psubusw256 (v16hi,v16hi)
12415v32qi __builtin_ia32_punpckhbw256 (v32qi,v32qi)
12416v16hi __builtin_ia32_punpckhwd256 (v16hi,v16hi)
12417v8si __builtin_ia32_punpckhdq256 (v8si,v8si)
12418v4di __builtin_ia32_punpckhqdq256 (v4di,v4di)
12419v32qi __builtin_ia32_punpcklbw256 (v32qi,v32qi)
12420v16hi __builtin_ia32_punpcklwd256 (v16hi,v16hi)
12421v8si __builtin_ia32_punpckldq256 (v8si,v8si)
12422v4di __builtin_ia32_punpcklqdq256 (v4di,v4di)
12423v4di __builtin_ia32_pxor256 (v4di,v4di)
12424v4di __builtin_ia32_movntdqa256 (pv4di)
12425v4sf __builtin_ia32_vbroadcastss_ps (v4sf)
12426v8sf __builtin_ia32_vbroadcastss_ps256 (v4sf)
12427v4df __builtin_ia32_vbroadcastsd_pd256 (v2df)
12428v4di __builtin_ia32_vbroadcastsi256 (v2di)
12429v4si __builtin_ia32_pblendd128 (v4si,v4si)
12430v8si __builtin_ia32_pblendd256 (v8si,v8si)
12431v32qi __builtin_ia32_pbroadcastb256 (v16qi)
12432v16hi __builtin_ia32_pbroadcastw256 (v8hi)
12433v8si __builtin_ia32_pbroadcastd256 (v4si)
12434v4di __builtin_ia32_pbroadcastq256 (v2di)
12435v16qi __builtin_ia32_pbroadcastb128 (v16qi)
12436v8hi __builtin_ia32_pbroadcastw128 (v8hi)
12437v4si __builtin_ia32_pbroadcastd128 (v4si)
12438v2di __builtin_ia32_pbroadcastq128 (v2di)
12439v8si __builtin_ia32_permvarsi256 (v8si,v8si)
12440v4df __builtin_ia32_permdf256 (v4df,int)
12441v8sf __builtin_ia32_permvarsf256 (v8sf,v8sf)
12442v4di __builtin_ia32_permdi256 (v4di,int)
12443v4di __builtin_ia32_permti256 (v4di,v4di,int)
12444v4di __builtin_ia32_extract128i256 (v4di,int)
12445v4di __builtin_ia32_insert128i256 (v4di,v2di,int)
12446v8si __builtin_ia32_maskloadd256 (pcv8si,v8si)
12447v4di __builtin_ia32_maskloadq256 (pcv4di,v4di)
12448v4si __builtin_ia32_maskloadd (pcv4si,v4si)
12449v2di __builtin_ia32_maskloadq (pcv2di,v2di)
12450void __builtin_ia32_maskstored256 (pv8si,v8si,v8si)
12451void __builtin_ia32_maskstoreq256 (pv4di,v4di,v4di)
12452void __builtin_ia32_maskstored (pv4si,v4si,v4si)
12453void __builtin_ia32_maskstoreq (pv2di,v2di,v2di)
12454v8si __builtin_ia32_psllv8si (v8si,v8si)
12455v4si __builtin_ia32_psllv4si (v4si,v4si)
12456v4di __builtin_ia32_psllv4di (v4di,v4di)
12457v2di __builtin_ia32_psllv2di (v2di,v2di)
12458v8si __builtin_ia32_psrav8si (v8si,v8si)
12459v4si __builtin_ia32_psrav4si (v4si,v4si)
12460v8si __builtin_ia32_psrlv8si (v8si,v8si)
12461v4si __builtin_ia32_psrlv4si (v4si,v4si)
12462v4di __builtin_ia32_psrlv4di (v4di,v4di)
12463v2di __builtin_ia32_psrlv2di (v2di,v2di)
12464v2df __builtin_ia32_gathersiv2df (v2df, pcdouble,v4si,v2df,int)
12465v4df __builtin_ia32_gathersiv4df (v4df, pcdouble,v4si,v4df,int)
12466v2df __builtin_ia32_gatherdiv2df (v2df, pcdouble,v2di,v2df,int)
12467v4df __builtin_ia32_gatherdiv4df (v4df, pcdouble,v4di,v4df,int)
12468v4sf __builtin_ia32_gathersiv4sf (v4sf, pcfloat,v4si,v4sf,int)
12469v8sf __builtin_ia32_gathersiv8sf (v8sf, pcfloat,v8si,v8sf,int)
12470v4sf __builtin_ia32_gatherdiv4sf (v4sf, pcfloat,v2di,v4sf,int)
12471v4sf __builtin_ia32_gatherdiv4sf256 (v4sf, pcfloat,v4di,v4sf,int)
12472v2di __builtin_ia32_gathersiv2di (v2di, pcint64,v4si,v2di,int)
12473v4di __builtin_ia32_gathersiv4di (v4di, pcint64,v4si,v4di,int)
12474v2di __builtin_ia32_gatherdiv2di (v2di, pcint64,v2di,v2di,int)
12475v4di __builtin_ia32_gatherdiv4di (v4di, pcint64,v4di,v4di,int)
12476v4si __builtin_ia32_gathersiv4si (v4si, pcint,v4si,v4si,int)
12477v8si __builtin_ia32_gathersiv8si (v8si, pcint,v8si,v8si,int)
12478v4si __builtin_ia32_gatherdiv4si (v4si, pcint,v2di,v4si,int)
12479v4si __builtin_ia32_gatherdiv4si256 (v4si, pcint,v4di,v4si,int)
12480@end smallexample
12481
8b96a312
L
12482The following built-in functions are available when @option{-maes} is
12483used. All of them generate the machine instruction that is part of the
12484name.
12485
12486@smallexample
12487v2di __builtin_ia32_aesenc128 (v2di, v2di)
12488v2di __builtin_ia32_aesenclast128 (v2di, v2di)
12489v2di __builtin_ia32_aesdec128 (v2di, v2di)
12490v2di __builtin_ia32_aesdeclast128 (v2di, v2di)
12491v2di __builtin_ia32_aeskeygenassist128 (v2di, const int)
12492v2di __builtin_ia32_aesimc128 (v2di)
12493@end smallexample
12494
12495The following built-in function is available when @option{-mpclmul} is
12496used.
12497
12498@table @code
12499@item v2di __builtin_ia32_pclmulqdq128 (v2di, v2di, const int)
12500Generates the @code{pclmulqdq} machine instruction.
12501@end table
12502
4ee89d5f
L
12503The following built-in function is available when @option{-mfsgsbase} is
12504used. All of them generate the machine instruction that is part of the
12505name.
12506
12507@smallexample
12508unsigned int __builtin_ia32_rdfsbase32 (void)
12509unsigned long long __builtin_ia32_rdfsbase64 (void)
12510unsigned int __builtin_ia32_rdgsbase32 (void)
12511unsigned long long __builtin_ia32_rdgsbase64 (void)
12512void _writefsbase_u32 (unsigned int)
12513void _writefsbase_u64 (unsigned long long)
12514void _writegsbase_u32 (unsigned int)
12515void _writegsbase_u64 (unsigned long long)
12516@end smallexample
12517
12518The following built-in function is available when @option{-mrdrnd} is
12519used. All of them generate the machine instruction that is part of the
12520name.
12521
12522@smallexample
11c4a1c0
L
12523unsigned int __builtin_ia32_rdrand16_step (unsigned short *)
12524unsigned int __builtin_ia32_rdrand32_step (unsigned int *)
12525unsigned int __builtin_ia32_rdrand64_step (unsigned long long *)
4ee89d5f
L
12526@end smallexample
12527
21efb4d4 12528The following built-in functions are available when @option{-msse4a} is used.
291d9a2d 12529All of them generate the machine instruction that is part of the name.
21efb4d4
HJ
12530
12531@smallexample
291d9a2d
UB
12532void __builtin_ia32_movntsd (double *, v2df)
12533void __builtin_ia32_movntss (float *, v4sf)
12534v2di __builtin_ia32_extrq (v2di, v16qi)
12535v2di __builtin_ia32_extrqi (v2di, const unsigned int, const unsigned int)
12536v2di __builtin_ia32_insertq (v2di, v2di)
12537v2di __builtin_ia32_insertqi (v2di, v2di, const unsigned int, const unsigned int)
21efb4d4
HJ
12538@end smallexample
12539
43a8b705
HJ
12540The following built-in functions are available when @option{-mxop} is used.
12541@smallexample
12542v2df __builtin_ia32_vfrczpd (v2df)
12543v4sf __builtin_ia32_vfrczps (v4sf)
d4082970
MT
12544v2df __builtin_ia32_vfrczsd (v2df)
12545v4sf __builtin_ia32_vfrczss (v4sf)
43a8b705
HJ
12546v4df __builtin_ia32_vfrczpd256 (v4df)
12547v8sf __builtin_ia32_vfrczps256 (v8sf)
12548v2di __builtin_ia32_vpcmov (v2di, v2di, v2di)
12549v2di __builtin_ia32_vpcmov_v2di (v2di, v2di, v2di)
12550v4si __builtin_ia32_vpcmov_v4si (v4si, v4si, v4si)
12551v8hi __builtin_ia32_vpcmov_v8hi (v8hi, v8hi, v8hi)
12552v16qi __builtin_ia32_vpcmov_v16qi (v16qi, v16qi, v16qi)
12553v2df __builtin_ia32_vpcmov_v2df (v2df, v2df, v2df)
12554v4sf __builtin_ia32_vpcmov_v4sf (v4sf, v4sf, v4sf)
12555v4di __builtin_ia32_vpcmov_v4di256 (v4di, v4di, v4di)
12556v8si __builtin_ia32_vpcmov_v8si256 (v8si, v8si, v8si)
12557v16hi __builtin_ia32_vpcmov_v16hi256 (v16hi, v16hi, v16hi)
12558v32qi __builtin_ia32_vpcmov_v32qi256 (v32qi, v32qi, v32qi)
12559v4df __builtin_ia32_vpcmov_v4df256 (v4df, v4df, v4df)
12560v8sf __builtin_ia32_vpcmov_v8sf256 (v8sf, v8sf, v8sf)
12561v16qi __builtin_ia32_vpcomeqb (v16qi, v16qi)
12562v8hi __builtin_ia32_vpcomeqw (v8hi, v8hi)
12563v4si __builtin_ia32_vpcomeqd (v4si, v4si)
12564v2di __builtin_ia32_vpcomeqq (v2di, v2di)
12565v16qi __builtin_ia32_vpcomequb (v16qi, v16qi)
12566v4si __builtin_ia32_vpcomequd (v4si, v4si)
12567v2di __builtin_ia32_vpcomequq (v2di, v2di)
12568v8hi __builtin_ia32_vpcomequw (v8hi, v8hi)
12569v8hi __builtin_ia32_vpcomeqw (v8hi, v8hi)
12570v16qi __builtin_ia32_vpcomfalseb (v16qi, v16qi)
12571v4si __builtin_ia32_vpcomfalsed (v4si, v4si)
12572v2di __builtin_ia32_vpcomfalseq (v2di, v2di)
12573v16qi __builtin_ia32_vpcomfalseub (v16qi, v16qi)
12574v4si __builtin_ia32_vpcomfalseud (v4si, v4si)
12575v2di __builtin_ia32_vpcomfalseuq (v2di, v2di)
12576v8hi __builtin_ia32_vpcomfalseuw (v8hi, v8hi)
12577v8hi __builtin_ia32_vpcomfalsew (v8hi, v8hi)
12578v16qi __builtin_ia32_vpcomgeb (v16qi, v16qi)
12579v4si __builtin_ia32_vpcomged (v4si, v4si)
12580v2di __builtin_ia32_vpcomgeq (v2di, v2di)
12581v16qi __builtin_ia32_vpcomgeub (v16qi, v16qi)
12582v4si __builtin_ia32_vpcomgeud (v4si, v4si)
12583v2di __builtin_ia32_vpcomgeuq (v2di, v2di)
12584v8hi __builtin_ia32_vpcomgeuw (v8hi, v8hi)
12585v8hi __builtin_ia32_vpcomgew (v8hi, v8hi)
12586v16qi __builtin_ia32_vpcomgtb (v16qi, v16qi)
12587v4si __builtin_ia32_vpcomgtd (v4si, v4si)
12588v2di __builtin_ia32_vpcomgtq (v2di, v2di)
12589v16qi __builtin_ia32_vpcomgtub (v16qi, v16qi)
12590v4si __builtin_ia32_vpcomgtud (v4si, v4si)
12591v2di __builtin_ia32_vpcomgtuq (v2di, v2di)
12592v8hi __builtin_ia32_vpcomgtuw (v8hi, v8hi)
12593v8hi __builtin_ia32_vpcomgtw (v8hi, v8hi)
12594v16qi __builtin_ia32_vpcomleb (v16qi, v16qi)
12595v4si __builtin_ia32_vpcomled (v4si, v4si)
12596v2di __builtin_ia32_vpcomleq (v2di, v2di)
12597v16qi __builtin_ia32_vpcomleub (v16qi, v16qi)
12598v4si __builtin_ia32_vpcomleud (v4si, v4si)
12599v2di __builtin_ia32_vpcomleuq (v2di, v2di)
12600v8hi __builtin_ia32_vpcomleuw (v8hi, v8hi)
12601v8hi __builtin_ia32_vpcomlew (v8hi, v8hi)
12602v16qi __builtin_ia32_vpcomltb (v16qi, v16qi)
12603v4si __builtin_ia32_vpcomltd (v4si, v4si)
12604v2di __builtin_ia32_vpcomltq (v2di, v2di)
12605v16qi __builtin_ia32_vpcomltub (v16qi, v16qi)
12606v4si __builtin_ia32_vpcomltud (v4si, v4si)
12607v2di __builtin_ia32_vpcomltuq (v2di, v2di)
12608v8hi __builtin_ia32_vpcomltuw (v8hi, v8hi)
12609v8hi __builtin_ia32_vpcomltw (v8hi, v8hi)
12610v16qi __builtin_ia32_vpcomneb (v16qi, v16qi)
12611v4si __builtin_ia32_vpcomned (v4si, v4si)
12612v2di __builtin_ia32_vpcomneq (v2di, v2di)
12613v16qi __builtin_ia32_vpcomneub (v16qi, v16qi)
12614v4si __builtin_ia32_vpcomneud (v4si, v4si)
12615v2di __builtin_ia32_vpcomneuq (v2di, v2di)
12616v8hi __builtin_ia32_vpcomneuw (v8hi, v8hi)
12617v8hi __builtin_ia32_vpcomnew (v8hi, v8hi)
12618v16qi __builtin_ia32_vpcomtrueb (v16qi, v16qi)
12619v4si __builtin_ia32_vpcomtrued (v4si, v4si)
12620v2di __builtin_ia32_vpcomtrueq (v2di, v2di)
12621v16qi __builtin_ia32_vpcomtrueub (v16qi, v16qi)
12622v4si __builtin_ia32_vpcomtrueud (v4si, v4si)
12623v2di __builtin_ia32_vpcomtrueuq (v2di, v2di)
12624v8hi __builtin_ia32_vpcomtrueuw (v8hi, v8hi)
12625v8hi __builtin_ia32_vpcomtruew (v8hi, v8hi)
12626v4si __builtin_ia32_vphaddbd (v16qi)
12627v2di __builtin_ia32_vphaddbq (v16qi)
12628v8hi __builtin_ia32_vphaddbw (v16qi)
12629v2di __builtin_ia32_vphadddq (v4si)
12630v4si __builtin_ia32_vphaddubd (v16qi)
12631v2di __builtin_ia32_vphaddubq (v16qi)
12632v8hi __builtin_ia32_vphaddubw (v16qi)
12633v2di __builtin_ia32_vphaddudq (v4si)
12634v4si __builtin_ia32_vphadduwd (v8hi)
12635v2di __builtin_ia32_vphadduwq (v8hi)
12636v4si __builtin_ia32_vphaddwd (v8hi)
12637v2di __builtin_ia32_vphaddwq (v8hi)
12638v8hi __builtin_ia32_vphsubbw (v16qi)
12639v2di __builtin_ia32_vphsubdq (v4si)
12640v4si __builtin_ia32_vphsubwd (v8hi)
12641v4si __builtin_ia32_vpmacsdd (v4si, v4si, v4si)
12642v2di __builtin_ia32_vpmacsdqh (v4si, v4si, v2di)
12643v2di __builtin_ia32_vpmacsdql (v4si, v4si, v2di)
12644v4si __builtin_ia32_vpmacssdd (v4si, v4si, v4si)
12645v2di __builtin_ia32_vpmacssdqh (v4si, v4si, v2di)
12646v2di __builtin_ia32_vpmacssdql (v4si, v4si, v2di)
12647v4si __builtin_ia32_vpmacsswd (v8hi, v8hi, v4si)
12648v8hi __builtin_ia32_vpmacssww (v8hi, v8hi, v8hi)
12649v4si __builtin_ia32_vpmacswd (v8hi, v8hi, v4si)
12650v8hi __builtin_ia32_vpmacsww (v8hi, v8hi, v8hi)
12651v4si __builtin_ia32_vpmadcsswd (v8hi, v8hi, v4si)
12652v4si __builtin_ia32_vpmadcswd (v8hi, v8hi, v4si)
12653v16qi __builtin_ia32_vpperm (v16qi, v16qi, v16qi)
12654v16qi __builtin_ia32_vprotb (v16qi, v16qi)
12655v4si __builtin_ia32_vprotd (v4si, v4si)
12656v2di __builtin_ia32_vprotq (v2di, v2di)
12657v8hi __builtin_ia32_vprotw (v8hi, v8hi)
12658v16qi __builtin_ia32_vpshab (v16qi, v16qi)
12659v4si __builtin_ia32_vpshad (v4si, v4si)
12660v2di __builtin_ia32_vpshaq (v2di, v2di)
12661v8hi __builtin_ia32_vpshaw (v8hi, v8hi)
12662v16qi __builtin_ia32_vpshlb (v16qi, v16qi)
12663v4si __builtin_ia32_vpshld (v4si, v4si)
12664v2di __builtin_ia32_vpshlq (v2di, v2di)
12665v8hi __builtin_ia32_vpshlw (v8hi, v8hi)
12666@end smallexample
12667
cbf2e4d4 12668The following built-in functions are available when @option{-mfma4} is used.
893e85fa
CM
12669All of them generate the machine instruction that is part of the name.
12670
12671@smallexample
12672v2df __builtin_ia32_vfmaddpd (v2df, v2df, v2df)
12673v4sf __builtin_ia32_vfmaddps (v4sf, v4sf, v4sf)
12674v2df __builtin_ia32_vfmaddsd (v2df, v2df, v2df)
12675v4sf __builtin_ia32_vfmaddss (v4sf, v4sf, v4sf)
12676v2df __builtin_ia32_vfmsubpd (v2df, v2df, v2df)
12677v4sf __builtin_ia32_vfmsubps (v4sf, v4sf, v4sf)
12678v2df __builtin_ia32_vfmsubsd (v2df, v2df, v2df)
12679v4sf __builtin_ia32_vfmsubss (v4sf, v4sf, v4sf)
12680v2df __builtin_ia32_vfnmaddpd (v2df, v2df, v2df)
12681v4sf __builtin_ia32_vfnmaddps (v4sf, v4sf, v4sf)
12682v2df __builtin_ia32_vfnmaddsd (v2df, v2df, v2df)
12683v4sf __builtin_ia32_vfnmaddss (v4sf, v4sf, v4sf)
12684v2df __builtin_ia32_vfnmsubpd (v2df, v2df, v2df)
12685v4sf __builtin_ia32_vfnmsubps (v4sf, v4sf, v4sf)
12686v2df __builtin_ia32_vfnmsubsd (v2df, v2df, v2df)
12687v4sf __builtin_ia32_vfnmsubss (v4sf, v4sf, v4sf)
12688v2df __builtin_ia32_vfmaddsubpd (v2df, v2df, v2df)
12689v4sf __builtin_ia32_vfmaddsubps (v4sf, v4sf, v4sf)
12690v2df __builtin_ia32_vfmsubaddpd (v2df, v2df, v2df)
12691v4sf __builtin_ia32_vfmsubaddps (v4sf, v4sf, v4sf)
12692v4df __builtin_ia32_vfmaddpd256 (v4df, v4df, v4df)
12693v8sf __builtin_ia32_vfmaddps256 (v8sf, v8sf, v8sf)
12694v4df __builtin_ia32_vfmsubpd256 (v4df, v4df, v4df)
12695v8sf __builtin_ia32_vfmsubps256 (v8sf, v8sf, v8sf)
12696v4df __builtin_ia32_vfnmaddpd256 (v4df, v4df, v4df)
12697v8sf __builtin_ia32_vfnmaddps256 (v8sf, v8sf, v8sf)
12698v4df __builtin_ia32_vfnmsubpd256 (v4df, v4df, v4df)
12699v8sf __builtin_ia32_vfnmsubps256 (v8sf, v8sf, v8sf)
12700v4df __builtin_ia32_vfmaddsubpd256 (v4df, v4df, v4df)
12701v8sf __builtin_ia32_vfmaddsubps256 (v8sf, v8sf, v8sf)
12702v4df __builtin_ia32_vfmsubaddpd256 (v4df, v4df, v4df)
12703v8sf __builtin_ia32_vfmsubaddps256 (v8sf, v8sf, v8sf)
cbf2e4d4
HJ
12704
12705@end smallexample
3e901069
HJ
12706
12707The following built-in functions are available when @option{-mlwp} is used.
12708
12709@smallexample
12710void __builtin_ia32_llwpcb16 (void *);
12711void __builtin_ia32_llwpcb32 (void *);
12712void __builtin_ia32_llwpcb64 (void *);
12713void * __builtin_ia32_llwpcb16 (void);
12714void * __builtin_ia32_llwpcb32 (void);
12715void * __builtin_ia32_llwpcb64 (void);
12716void __builtin_ia32_lwpval16 (unsigned short, unsigned int, unsigned short)
12717void __builtin_ia32_lwpval32 (unsigned int, unsigned int, unsigned int)
12718void __builtin_ia32_lwpval64 (unsigned __int64, unsigned int, unsigned int)
12719unsigned char __builtin_ia32_lwpins16 (unsigned short, unsigned int, unsigned short)
12720unsigned char __builtin_ia32_lwpins32 (unsigned int, unsigned int, unsigned int)
12721unsigned char __builtin_ia32_lwpins64 (unsigned __int64, unsigned int, unsigned int)
12722@end smallexample
cbf2e4d4 12723
91afcfa3
QN
12724The following built-in functions are available when @option{-mbmi} is used.
12725All of them generate the machine instruction that is part of the name.
12726@smallexample
12727unsigned int __builtin_ia32_bextr_u32(unsigned int, unsigned int);
12728unsigned long long __builtin_ia32_bextr_u64 (unsigned long long, unsigned long long);
5fcafa60
KY
12729@end smallexample
12730
82feeb8d
L
12731The following built-in functions are available when @option{-mbmi2} is used.
12732All of them generate the machine instruction that is part of the name.
12733@smallexample
12734unsigned int _bzhi_u32 (unsigned int, unsigned int)
12735unsigned int _pdep_u32 (unsigned int, unsigned int)
12736unsigned int _pext_u32 (unsigned int, unsigned int)
12737unsigned long long _bzhi_u64 (unsigned long long, unsigned long long)
12738unsigned long long _pdep_u64 (unsigned long long, unsigned long long)
12739unsigned long long _pext_u64 (unsigned long long, unsigned long long)
12740@end smallexample
12741
5fcafa60
KY
12742The following built-in functions are available when @option{-mlzcnt} is used.
12743All of them generate the machine instruction that is part of the name.
12744@smallexample
91afcfa3
QN
12745unsigned short __builtin_ia32_lzcnt_16(unsigned short);
12746unsigned int __builtin_ia32_lzcnt_u32(unsigned int);
12747unsigned long long __builtin_ia32_lzcnt_u64 (unsigned long long);
12748@end smallexample
7e570821
AI
12749
12750The following built-in functions are available when @option{-mfxsr} is used.
12751All of them generate the machine instruction that is part of the name.
12752@smallexample
12753void __builtin_ia32_fxsave (void *)
12754void __builtin_ia32_fxrstor (void *)
12755void __builtin_ia32_fxsave64 (void *)
12756void __builtin_ia32_fxrstor64 (void *)
12757@end smallexample
12758
12759The following built-in functions are available when @option{-mxsave} is used.
12760All of them generate the machine instruction that is part of the name.
12761@smallexample
12762void __builtin_ia32_xsave (void *, long long)
12763void __builtin_ia32_xrstor (void *, long long)
12764void __builtin_ia32_xsave64 (void *, long long)
12765void __builtin_ia32_xrstor64 (void *, long long)
12766@end smallexample
12767
12768The following built-in functions are available when @option{-mxsaveopt} is used.
12769All of them generate the machine instruction that is part of the name.
12770@smallexample
12771void __builtin_ia32_xsaveopt (void *, long long)
12772void __builtin_ia32_xsaveopt64 (void *, long long)
12773@end smallexample
91afcfa3 12774
94d13ad1
QN
12775The following built-in functions are available when @option{-mtbm} is used.
12776Both of them generate the immediate form of the bextr machine instruction.
12777@smallexample
12778unsigned int __builtin_ia32_bextri_u32 (unsigned int, const unsigned int);
12779unsigned long long __builtin_ia32_bextri_u64 (unsigned long long, const unsigned long long);
12780@end smallexample
12781
12782
0975678f
JM
12783The following built-in functions are available when @option{-m3dnow} is used.
12784All of them generate the machine instruction that is part of the name.
12785
3ab51846 12786@smallexample
0975678f
JM
12787void __builtin_ia32_femms (void)
12788v8qi __builtin_ia32_pavgusb (v8qi, v8qi)
12789v2si __builtin_ia32_pf2id (v2sf)
12790v2sf __builtin_ia32_pfacc (v2sf, v2sf)
12791v2sf __builtin_ia32_pfadd (v2sf, v2sf)
12792v2si __builtin_ia32_pfcmpeq (v2sf, v2sf)
12793v2si __builtin_ia32_pfcmpge (v2sf, v2sf)
12794v2si __builtin_ia32_pfcmpgt (v2sf, v2sf)
12795v2sf __builtin_ia32_pfmax (v2sf, v2sf)
12796v2sf __builtin_ia32_pfmin (v2sf, v2sf)
12797v2sf __builtin_ia32_pfmul (v2sf, v2sf)
12798v2sf __builtin_ia32_pfrcp (v2sf)
12799v2sf __builtin_ia32_pfrcpit1 (v2sf, v2sf)
12800v2sf __builtin_ia32_pfrcpit2 (v2sf, v2sf)
12801v2sf __builtin_ia32_pfrsqrt (v2sf)
0975678f
JM
12802v2sf __builtin_ia32_pfsub (v2sf, v2sf)
12803v2sf __builtin_ia32_pfsubr (v2sf, v2sf)
12804v2sf __builtin_ia32_pi2fd (v2si)
12805v4hi __builtin_ia32_pmulhrw (v4hi, v4hi)
3ab51846 12806@end smallexample
0975678f
JM
12807
12808The following built-in functions are available when both @option{-m3dnow}
12809and @option{-march=athlon} are used. All of them generate the machine
12810instruction that is part of the name.
12811
3ab51846 12812@smallexample
0975678f
JM
12813v2si __builtin_ia32_pf2iw (v2sf)
12814v2sf __builtin_ia32_pfnacc (v2sf, v2sf)
12815v2sf __builtin_ia32_pfpnacc (v2sf, v2sf)
12816v2sf __builtin_ia32_pi2fw (v2si)
12817v2sf __builtin_ia32_pswapdsf (v2sf)
12818v2si __builtin_ia32_pswapdsi (v2si)
3ab51846 12819@end smallexample
0975678f 12820
4323afa0
AK
12821The following built-in functions are available when @option{-mrtm} is used
12822They are used for restricted transactional memory. These are the internal
12823low level functions. Normally the functions in
12824@ref{X86 transactional memory intrinsics} should be used instead.
12825
12826@smallexample
12827int __builtin_ia32_xbegin ()
12828void __builtin_ia32_xend ()
12829void __builtin_ia32_xabort (status)
12830int __builtin_ia32_xtest ()
12831@end smallexample
12832
12833@node X86 transactional memory intrinsics
12834@subsection X86 transaction memory intrinsics
12835
12836Hardware transactional memory intrinsics for i386. These allow to use
12837memory transactions with RTM (Restricted Transactional Memory).
12838For using HLE (Hardware Lock Elision) see @ref{x86 specific memory model extensions for transactional memory} instead.
12839This support is enabled with the @option{-mrtm} option.
12840
12841A memory transaction commits all changes to memory in an atomic way,
12842as visible to other threads. If the transaction fails it is rolled back
12843and all side effects discarded.
12844
54a41d1b 12845Generally there is no guarantee that a memory transaction ever succeeds
4323afa0
AK
12846and suitable fallback code always needs to be supplied.
12847
12848@deftypefn {RTM Function} {unsigned} _xbegin ()
12849Start a RTM (Restricted Transactional Memory) transaction.
12850Returns _XBEGIN_STARTED when the transaction
12851started successfully (note this is not 0, so the constant has to be
12852explicitely tested). When the transaction aborts all side effects
12853are undone and an abort code is returned. There is no guarantee
12854any transaction ever succeeds, so there always needs to be a valid
12855tested fallback path.
12856@end deftypefn
12857
12858@smallexample
12859#include <immintrin.h>
12860
12861if ((status = _xbegin ()) == _XBEGIN_STARTED) @{
12862 ... transaction code...
12863 _xend ();
12864@} else @{
12865 ... non transactional fallback path...
12866@}
12867@end smallexample
12868
12869Valid abort status bits (when the value is not @code{_XBEGIN_STARTED}) are:
12870
12871@table @code
12872@item _XABORT_EXPLICIT
12873Transaction explicitely aborted with @code{_xabort}. The parameter passed
12874to @code{_xabort} is available with @code{_XABORT_CODE(status)}
12875@item _XABORT_RETRY
12876Transaction retry is possible.
12877@item _XABORT_CONFLICT
12878Transaction abort due to a memory conflict with another thread
12879@item _XABORT_CAPACITY
12880Transaction abort due to the transaction using too much memory
12881@item _XABORT_DEBUG
12882Transaction abort due to a debug trap
12883@item _XABORT_NESTED
12884Transaction abort in a inner nested transaction
12885@end table
12886
12887@deftypefn {RTM Function} {void} _xend ()
12888Commit the current transaction. When no transaction is active this will
12889fault. All memory side effects of the transactions will become visible
12890to other threads in an atomic matter.
12891@end deftypefn
12892
12893@deftypefn {RTM Function} {int} _xtest ()
12894Return a value not zero when a transaction is currently active, otherwise 0.
12895@end deftypefn
12896
12897@deftypefn {RTM Function} {void} _xabort (status)
12898Abort the current transaction. When no transaction is active this is a no-op.
12899status must be a 8bit constant, that is included in the status code returned
12900by @code{_xbegin}
12901@end deftypefn
12902
118ea793
CF
12903@node MIPS DSP Built-in Functions
12904@subsection MIPS DSP Built-in Functions
12905
12906The MIPS DSP Application-Specific Extension (ASE) includes new
12907instructions that are designed to improve the performance of DSP and
12908media applications. It provides instructions that operate on packed
32041385 129098-bit/16-bit integer data, Q7, Q15 and Q31 fractional data.
118ea793
CF
12910
12911GCC supports MIPS DSP operations using both the generic
12912vector extensions (@pxref{Vector Extensions}) and a collection of
12913MIPS-specific built-in functions. Both kinds of support are
12914enabled by the @option{-mdsp} command-line option.
12915
32041385
CF
12916Revision 2 of the ASE was introduced in the second half of 2006.
12917This revision adds extra instructions to the original ASE, but is
12918otherwise backwards-compatible with it. You can select revision 2
12919using the command-line option @option{-mdspr2}; this option implies
12920@option{-mdsp}.
12921
1e27273f
CM
12922The SCOUNT and POS bits of the DSP control register are global. The
12923WRDSP, EXTPDP, EXTPDPV and MTHLIP instructions modify the SCOUNT and
358a3dbc
SL
12924POS bits. During optimization, the compiler does not delete these
12925instructions and it does not delete calls to functions containing
1e27273f
CM
12926these instructions.
12927
118ea793
CF
12928At present, GCC only provides support for operations on 32-bit
12929vectors. The vector type associated with 8-bit integer data is
32041385
CF
12930usually called @code{v4i8}, the vector type associated with Q7
12931is usually called @code{v4q7}, the vector type associated with 16-bit
12932integer data is usually called @code{v2i16}, and the vector type
12933associated with Q15 is usually called @code{v2q15}. They can be
12934defined in C as follows:
118ea793
CF
12935
12936@smallexample
32041385
CF
12937typedef signed char v4i8 __attribute__ ((vector_size(4)));
12938typedef signed char v4q7 __attribute__ ((vector_size(4)));
12939typedef short v2i16 __attribute__ ((vector_size(4)));
118ea793
CF
12940typedef short v2q15 __attribute__ ((vector_size(4)));
12941@end smallexample
12942
32041385
CF
12943@code{v4i8}, @code{v4q7}, @code{v2i16} and @code{v2q15} values are
12944initialized in the same way as aggregates. For example:
118ea793
CF
12945
12946@smallexample
12947v4i8 a = @{1, 2, 3, 4@};
12948v4i8 b;
12949b = (v4i8) @{5, 6, 7, 8@};
12950
12951v2q15 c = @{0x0fcb, 0x3a75@};
12952v2q15 d;
12953d = (v2q15) @{0.1234 * 0x1.0p15, 0.4567 * 0x1.0p15@};
12954@end smallexample
12955
12956@emph{Note:} The CPU's endianness determines the order in which values
12957are packed. On little-endian targets, the first value is the least
12958significant and the last value is the most significant. The opposite
358a3dbc
SL
12959order applies to big-endian targets. For example, the code above
12960sets the lowest byte of @code{a} to @code{1} on little-endian targets
118ea793
CF
12961and @code{4} on big-endian targets.
12962
32041385 12963@emph{Note:} Q7, Q15 and Q31 values must be initialized with their integer
118ea793 12964representation. As shown in this example, the integer representation
32041385
CF
12965of a Q7 value can be obtained by multiplying the fractional value by
12966@code{0x1.0p7}. The equivalent for Q15 values is to multiply by
118ea793
CF
12967@code{0x1.0p15}. The equivalent for Q31 values is to multiply by
12968@code{0x1.0p31}.
12969
12970The table below lists the @code{v4i8} and @code{v2q15} operations for which
12971hardware support exists. @code{a} and @code{b} are @code{v4i8} values,
12972and @code{c} and @code{d} are @code{v2q15} values.
12973
12974@multitable @columnfractions .50 .50
12975@item C code @tab MIPS instruction
12976@item @code{a + b} @tab @code{addu.qb}
12977@item @code{c + d} @tab @code{addq.ph}
12978@item @code{a - b} @tab @code{subu.qb}
12979@item @code{c - d} @tab @code{subq.ph}
12980@end multitable
12981
32041385
CF
12982The table below lists the @code{v2i16} operation for which
12983hardware support exists for the DSP ASE REV 2. @code{e} and @code{f} are
12984@code{v2i16} values.
12985
12986@multitable @columnfractions .50 .50
12987@item C code @tab MIPS instruction
12988@item @code{e * f} @tab @code{mul.ph}
12989@end multitable
12990
118ea793
CF
12991It is easier to describe the DSP built-in functions if we first define
12992the following types:
12993
12994@smallexample
12995typedef int q31;
12996typedef int i32;
32041385 12997typedef unsigned int ui32;
118ea793
CF
12998typedef long long a64;
12999@end smallexample
13000
13001@code{q31} and @code{i32} are actually the same as @code{int}, but we
13002use @code{q31} to indicate a Q31 fractional value and @code{i32} to
13003indicate a 32-bit integer value. Similarly, @code{a64} is the same as
358a3dbc
SL
13004@code{long long}, but we use @code{a64} to indicate values that are
13005placed in one of the four DSP accumulators (@code{$ac0},
118ea793
CF
13006@code{$ac1}, @code{$ac2} or @code{$ac3}).
13007
13008Also, some built-in functions prefer or require immediate numbers as
13009parameters, because the corresponding DSP instructions accept both immediate
13010numbers and register operands, or accept immediate numbers only. The
13011immediate parameters are listed as follows.
13012
13013@smallexample
32041385 13014imm0_3: 0 to 3.
118ea793
CF
13015imm0_7: 0 to 7.
13016imm0_15: 0 to 15.
13017imm0_31: 0 to 31.
13018imm0_63: 0 to 63.
13019imm0_255: 0 to 255.
13020imm_n32_31: -32 to 31.
13021imm_n512_511: -512 to 511.
13022@end smallexample
13023
13024The following built-in functions map directly to a particular MIPS DSP
13025instruction. Please refer to the architecture specification
13026for details on what each instruction does.
13027
13028@smallexample
13029v2q15 __builtin_mips_addq_ph (v2q15, v2q15)
13030v2q15 __builtin_mips_addq_s_ph (v2q15, v2q15)
13031q31 __builtin_mips_addq_s_w (q31, q31)
13032v4i8 __builtin_mips_addu_qb (v4i8, v4i8)
13033v4i8 __builtin_mips_addu_s_qb (v4i8, v4i8)
13034v2q15 __builtin_mips_subq_ph (v2q15, v2q15)
13035v2q15 __builtin_mips_subq_s_ph (v2q15, v2q15)
13036q31 __builtin_mips_subq_s_w (q31, q31)
13037v4i8 __builtin_mips_subu_qb (v4i8, v4i8)
13038v4i8 __builtin_mips_subu_s_qb (v4i8, v4i8)
13039i32 __builtin_mips_addsc (i32, i32)
13040i32 __builtin_mips_addwc (i32, i32)
13041i32 __builtin_mips_modsub (i32, i32)
13042i32 __builtin_mips_raddu_w_qb (v4i8)
13043v2q15 __builtin_mips_absq_s_ph (v2q15)
13044q31 __builtin_mips_absq_s_w (q31)
13045v4i8 __builtin_mips_precrq_qb_ph (v2q15, v2q15)
13046v2q15 __builtin_mips_precrq_ph_w (q31, q31)
13047v2q15 __builtin_mips_precrq_rs_ph_w (q31, q31)
13048v4i8 __builtin_mips_precrqu_s_qb_ph (v2q15, v2q15)
13049q31 __builtin_mips_preceq_w_phl (v2q15)
13050q31 __builtin_mips_preceq_w_phr (v2q15)
13051v2q15 __builtin_mips_precequ_ph_qbl (v4i8)
13052v2q15 __builtin_mips_precequ_ph_qbr (v4i8)
13053v2q15 __builtin_mips_precequ_ph_qbla (v4i8)
13054v2q15 __builtin_mips_precequ_ph_qbra (v4i8)
13055v2q15 __builtin_mips_preceu_ph_qbl (v4i8)
13056v2q15 __builtin_mips_preceu_ph_qbr (v4i8)
13057v2q15 __builtin_mips_preceu_ph_qbla (v4i8)
13058v2q15 __builtin_mips_preceu_ph_qbra (v4i8)
13059v4i8 __builtin_mips_shll_qb (v4i8, imm0_7)
13060v4i8 __builtin_mips_shll_qb (v4i8, i32)
13061v2q15 __builtin_mips_shll_ph (v2q15, imm0_15)
13062v2q15 __builtin_mips_shll_ph (v2q15, i32)
13063v2q15 __builtin_mips_shll_s_ph (v2q15, imm0_15)
13064v2q15 __builtin_mips_shll_s_ph (v2q15, i32)
13065q31 __builtin_mips_shll_s_w (q31, imm0_31)
13066q31 __builtin_mips_shll_s_w (q31, i32)
13067v4i8 __builtin_mips_shrl_qb (v4i8, imm0_7)
13068v4i8 __builtin_mips_shrl_qb (v4i8, i32)
13069v2q15 __builtin_mips_shra_ph (v2q15, imm0_15)
13070v2q15 __builtin_mips_shra_ph (v2q15, i32)
13071v2q15 __builtin_mips_shra_r_ph (v2q15, imm0_15)
13072v2q15 __builtin_mips_shra_r_ph (v2q15, i32)
13073q31 __builtin_mips_shra_r_w (q31, imm0_31)
13074q31 __builtin_mips_shra_r_w (q31, i32)
13075v2q15 __builtin_mips_muleu_s_ph_qbl (v4i8, v2q15)
13076v2q15 __builtin_mips_muleu_s_ph_qbr (v4i8, v2q15)
13077v2q15 __builtin_mips_mulq_rs_ph (v2q15, v2q15)
13078q31 __builtin_mips_muleq_s_w_phl (v2q15, v2q15)
13079q31 __builtin_mips_muleq_s_w_phr (v2q15, v2q15)
13080a64 __builtin_mips_dpau_h_qbl (a64, v4i8, v4i8)
13081a64 __builtin_mips_dpau_h_qbr (a64, v4i8, v4i8)
13082a64 __builtin_mips_dpsu_h_qbl (a64, v4i8, v4i8)
13083a64 __builtin_mips_dpsu_h_qbr (a64, v4i8, v4i8)
13084a64 __builtin_mips_dpaq_s_w_ph (a64, v2q15, v2q15)
13085a64 __builtin_mips_dpaq_sa_l_w (a64, q31, q31)
13086a64 __builtin_mips_dpsq_s_w_ph (a64, v2q15, v2q15)
13087a64 __builtin_mips_dpsq_sa_l_w (a64, q31, q31)
13088a64 __builtin_mips_mulsaq_s_w_ph (a64, v2q15, v2q15)
13089a64 __builtin_mips_maq_s_w_phl (a64, v2q15, v2q15)
13090a64 __builtin_mips_maq_s_w_phr (a64, v2q15, v2q15)
13091a64 __builtin_mips_maq_sa_w_phl (a64, v2q15, v2q15)
13092a64 __builtin_mips_maq_sa_w_phr (a64, v2q15, v2q15)
13093i32 __builtin_mips_bitrev (i32)
13094i32 __builtin_mips_insv (i32, i32)
13095v4i8 __builtin_mips_repl_qb (imm0_255)
13096v4i8 __builtin_mips_repl_qb (i32)
13097v2q15 __builtin_mips_repl_ph (imm_n512_511)
13098v2q15 __builtin_mips_repl_ph (i32)
13099void __builtin_mips_cmpu_eq_qb (v4i8, v4i8)
13100void __builtin_mips_cmpu_lt_qb (v4i8, v4i8)
13101void __builtin_mips_cmpu_le_qb (v4i8, v4i8)
13102i32 __builtin_mips_cmpgu_eq_qb (v4i8, v4i8)
13103i32 __builtin_mips_cmpgu_lt_qb (v4i8, v4i8)
13104i32 __builtin_mips_cmpgu_le_qb (v4i8, v4i8)
13105void __builtin_mips_cmp_eq_ph (v2q15, v2q15)
13106void __builtin_mips_cmp_lt_ph (v2q15, v2q15)
13107void __builtin_mips_cmp_le_ph (v2q15, v2q15)
13108v4i8 __builtin_mips_pick_qb (v4i8, v4i8)
13109v2q15 __builtin_mips_pick_ph (v2q15, v2q15)
13110v2q15 __builtin_mips_packrl_ph (v2q15, v2q15)
13111i32 __builtin_mips_extr_w (a64, imm0_31)
13112i32 __builtin_mips_extr_w (a64, i32)
13113i32 __builtin_mips_extr_r_w (a64, imm0_31)
13114i32 __builtin_mips_extr_s_h (a64, i32)
13115i32 __builtin_mips_extr_rs_w (a64, imm0_31)
13116i32 __builtin_mips_extr_rs_w (a64, i32)
13117i32 __builtin_mips_extr_s_h (a64, imm0_31)
13118i32 __builtin_mips_extr_r_w (a64, i32)
13119i32 __builtin_mips_extp (a64, imm0_31)
13120i32 __builtin_mips_extp (a64, i32)
13121i32 __builtin_mips_extpdp (a64, imm0_31)
13122i32 __builtin_mips_extpdp (a64, i32)
13123a64 __builtin_mips_shilo (a64, imm_n32_31)
13124a64 __builtin_mips_shilo (a64, i32)
13125a64 __builtin_mips_mthlip (a64, i32)
13126void __builtin_mips_wrdsp (i32, imm0_63)
13127i32 __builtin_mips_rddsp (imm0_63)
13128i32 __builtin_mips_lbux (void *, i32)
13129i32 __builtin_mips_lhx (void *, i32)
13130i32 __builtin_mips_lwx (void *, i32)
770da00a 13131a64 __builtin_mips_ldx (void *, i32) [MIPS64 only]
118ea793 13132i32 __builtin_mips_bposge32 (void)
293b77b0
CF
13133a64 __builtin_mips_madd (a64, i32, i32);
13134a64 __builtin_mips_maddu (a64, ui32, ui32);
13135a64 __builtin_mips_msub (a64, i32, i32);
13136a64 __builtin_mips_msubu (a64, ui32, ui32);
13137a64 __builtin_mips_mult (i32, i32);
13138a64 __builtin_mips_multu (ui32, ui32);
118ea793
CF
13139@end smallexample
13140
32041385
CF
13141The following built-in functions map directly to a particular MIPS DSP REV 2
13142instruction. Please refer to the architecture specification
13143for details on what each instruction does.
13144
13145@smallexample
13146v4q7 __builtin_mips_absq_s_qb (v4q7);
13147v2i16 __builtin_mips_addu_ph (v2i16, v2i16);
13148v2i16 __builtin_mips_addu_s_ph (v2i16, v2i16);
13149v4i8 __builtin_mips_adduh_qb (v4i8, v4i8);
13150v4i8 __builtin_mips_adduh_r_qb (v4i8, v4i8);
13151i32 __builtin_mips_append (i32, i32, imm0_31);
13152i32 __builtin_mips_balign (i32, i32, imm0_3);
13153i32 __builtin_mips_cmpgdu_eq_qb (v4i8, v4i8);
13154i32 __builtin_mips_cmpgdu_lt_qb (v4i8, v4i8);
13155i32 __builtin_mips_cmpgdu_le_qb (v4i8, v4i8);
13156a64 __builtin_mips_dpa_w_ph (a64, v2i16, v2i16);
13157a64 __builtin_mips_dps_w_ph (a64, v2i16, v2i16);
32041385
CF
13158v2i16 __builtin_mips_mul_ph (v2i16, v2i16);
13159v2i16 __builtin_mips_mul_s_ph (v2i16, v2i16);
13160q31 __builtin_mips_mulq_rs_w (q31, q31);
13161v2q15 __builtin_mips_mulq_s_ph (v2q15, v2q15);
13162q31 __builtin_mips_mulq_s_w (q31, q31);
13163a64 __builtin_mips_mulsa_w_ph (a64, v2i16, v2i16);
32041385
CF
13164v4i8 __builtin_mips_precr_qb_ph (v2i16, v2i16);
13165v2i16 __builtin_mips_precr_sra_ph_w (i32, i32, imm0_31);
13166v2i16 __builtin_mips_precr_sra_r_ph_w (i32, i32, imm0_31);
13167i32 __builtin_mips_prepend (i32, i32, imm0_31);
13168v4i8 __builtin_mips_shra_qb (v4i8, imm0_7);
13169v4i8 __builtin_mips_shra_r_qb (v4i8, imm0_7);
13170v4i8 __builtin_mips_shra_qb (v4i8, i32);
13171v4i8 __builtin_mips_shra_r_qb (v4i8, i32);
13172v2i16 __builtin_mips_shrl_ph (v2i16, imm0_15);
13173v2i16 __builtin_mips_shrl_ph (v2i16, i32);
13174v2i16 __builtin_mips_subu_ph (v2i16, v2i16);
13175v2i16 __builtin_mips_subu_s_ph (v2i16, v2i16);
13176v4i8 __builtin_mips_subuh_qb (v4i8, v4i8);
13177v4i8 __builtin_mips_subuh_r_qb (v4i8, v4i8);
13178v2q15 __builtin_mips_addqh_ph (v2q15, v2q15);
13179v2q15 __builtin_mips_addqh_r_ph (v2q15, v2q15);
13180q31 __builtin_mips_addqh_w (q31, q31);
13181q31 __builtin_mips_addqh_r_w (q31, q31);
13182v2q15 __builtin_mips_subqh_ph (v2q15, v2q15);
13183v2q15 __builtin_mips_subqh_r_ph (v2q15, v2q15);
13184q31 __builtin_mips_subqh_w (q31, q31);
13185q31 __builtin_mips_subqh_r_w (q31, q31);
13186a64 __builtin_mips_dpax_w_ph (a64, v2i16, v2i16);
13187a64 __builtin_mips_dpsx_w_ph (a64, v2i16, v2i16);
13188a64 __builtin_mips_dpaqx_s_w_ph (a64, v2q15, v2q15);
13189a64 __builtin_mips_dpaqx_sa_w_ph (a64, v2q15, v2q15);
13190a64 __builtin_mips_dpsqx_s_w_ph (a64, v2q15, v2q15);
13191a64 __builtin_mips_dpsqx_sa_w_ph (a64, v2q15, v2q15);
13192@end smallexample
13193
13194
d840bfd3
CF
13195@node MIPS Paired-Single Support
13196@subsection MIPS Paired-Single Support
13197
13198The MIPS64 architecture includes a number of instructions that
13199operate on pairs of single-precision floating-point values.
13200Each pair is packed into a 64-bit floating-point register,
13201with one element being designated the ``upper half'' and
13202the other being designated the ``lower half''.
13203
13204GCC supports paired-single operations using both the generic
13205vector extensions (@pxref{Vector Extensions}) and a collection of
13206MIPS-specific built-in functions. Both kinds of support are
13207enabled by the @option{-mpaired-single} command-line option.
13208
13209The vector type associated with paired-single values is usually
13210called @code{v2sf}. It can be defined in C as follows:
13211
13212@smallexample
13213typedef float v2sf __attribute__ ((vector_size (8)));
13214@end smallexample
13215
13216@code{v2sf} values are initialized in the same way as aggregates.
13217For example:
13218
13219@smallexample
13220v2sf a = @{1.5, 9.1@};
13221v2sf b;
13222float e, f;
13223b = (v2sf) @{e, f@};
13224@end smallexample
13225
13226@emph{Note:} The CPU's endianness determines which value is stored in
13227the upper half of a register and which value is stored in the lower half.
13228On little-endian targets, the first value is the lower one and the second
13229value is the upper one. The opposite order applies to big-endian targets.
358a3dbc 13230For example, the code above sets the lower half of @code{a} to
d840bfd3
CF
13231@code{1.5} on little-endian targets and @code{9.1} on big-endian targets.
13232
93581857
MS
13233@node MIPS Loongson Built-in Functions
13234@subsection MIPS Loongson Built-in Functions
13235
13236GCC provides intrinsics to access the SIMD instructions provided by the
13237ST Microelectronics Loongson-2E and -2F processors. These intrinsics,
13238available after inclusion of the @code{loongson.h} header file,
13239operate on the following 64-bit vector types:
13240
13241@itemize
13242@item @code{uint8x8_t}, a vector of eight unsigned 8-bit integers;
13243@item @code{uint16x4_t}, a vector of four unsigned 16-bit integers;
13244@item @code{uint32x2_t}, a vector of two unsigned 32-bit integers;
13245@item @code{int8x8_t}, a vector of eight signed 8-bit integers;
13246@item @code{int16x4_t}, a vector of four signed 16-bit integers;
13247@item @code{int32x2_t}, a vector of two signed 32-bit integers.
13248@end itemize
13249
13250The intrinsics provided are listed below; each is named after the
13251machine instruction to which it corresponds, with suffixes added as
13252appropriate to distinguish intrinsics that expand to the same machine
13253instruction yet have different argument types. Refer to the architecture
13254documentation for a description of the functionality of each
13255instruction.
13256
13257@smallexample
13258int16x4_t packsswh (int32x2_t s, int32x2_t t);
13259int8x8_t packsshb (int16x4_t s, int16x4_t t);
13260uint8x8_t packushb (uint16x4_t s, uint16x4_t t);
13261uint32x2_t paddw_u (uint32x2_t s, uint32x2_t t);
13262uint16x4_t paddh_u (uint16x4_t s, uint16x4_t t);
13263uint8x8_t paddb_u (uint8x8_t s, uint8x8_t t);
13264int32x2_t paddw_s (int32x2_t s, int32x2_t t);
13265int16x4_t paddh_s (int16x4_t s, int16x4_t t);
13266int8x8_t paddb_s (int8x8_t s, int8x8_t t);
13267uint64_t paddd_u (uint64_t s, uint64_t t);
13268int64_t paddd_s (int64_t s, int64_t t);
13269int16x4_t paddsh (int16x4_t s, int16x4_t t);
13270int8x8_t paddsb (int8x8_t s, int8x8_t t);
13271uint16x4_t paddush (uint16x4_t s, uint16x4_t t);
13272uint8x8_t paddusb (uint8x8_t s, uint8x8_t t);
13273uint64_t pandn_ud (uint64_t s, uint64_t t);
13274uint32x2_t pandn_uw (uint32x2_t s, uint32x2_t t);
13275uint16x4_t pandn_uh (uint16x4_t s, uint16x4_t t);
13276uint8x8_t pandn_ub (uint8x8_t s, uint8x8_t t);
13277int64_t pandn_sd (int64_t s, int64_t t);
13278int32x2_t pandn_sw (int32x2_t s, int32x2_t t);
13279int16x4_t pandn_sh (int16x4_t s, int16x4_t t);
13280int8x8_t pandn_sb (int8x8_t s, int8x8_t t);
13281uint16x4_t pavgh (uint16x4_t s, uint16x4_t t);
13282uint8x8_t pavgb (uint8x8_t s, uint8x8_t t);
13283uint32x2_t pcmpeqw_u (uint32x2_t s, uint32x2_t t);
13284uint16x4_t pcmpeqh_u (uint16x4_t s, uint16x4_t t);
13285uint8x8_t pcmpeqb_u (uint8x8_t s, uint8x8_t t);
13286int32x2_t pcmpeqw_s (int32x2_t s, int32x2_t t);
13287int16x4_t pcmpeqh_s (int16x4_t s, int16x4_t t);
13288int8x8_t pcmpeqb_s (int8x8_t s, int8x8_t t);
13289uint32x2_t pcmpgtw_u (uint32x2_t s, uint32x2_t t);
13290uint16x4_t pcmpgth_u (uint16x4_t s, uint16x4_t t);
13291uint8x8_t pcmpgtb_u (uint8x8_t s, uint8x8_t t);
13292int32x2_t pcmpgtw_s (int32x2_t s, int32x2_t t);
13293int16x4_t pcmpgth_s (int16x4_t s, int16x4_t t);
13294int8x8_t pcmpgtb_s (int8x8_t s, int8x8_t t);
13295uint16x4_t pextrh_u (uint16x4_t s, int field);
13296int16x4_t pextrh_s (int16x4_t s, int field);
13297uint16x4_t pinsrh_0_u (uint16x4_t s, uint16x4_t t);
13298uint16x4_t pinsrh_1_u (uint16x4_t s, uint16x4_t t);
13299uint16x4_t pinsrh_2_u (uint16x4_t s, uint16x4_t t);
13300uint16x4_t pinsrh_3_u (uint16x4_t s, uint16x4_t t);
13301int16x4_t pinsrh_0_s (int16x4_t s, int16x4_t t);
13302int16x4_t pinsrh_1_s (int16x4_t s, int16x4_t t);
13303int16x4_t pinsrh_2_s (int16x4_t s, int16x4_t t);
13304int16x4_t pinsrh_3_s (int16x4_t s, int16x4_t t);
13305int32x2_t pmaddhw (int16x4_t s, int16x4_t t);
13306int16x4_t pmaxsh (int16x4_t s, int16x4_t t);
13307uint8x8_t pmaxub (uint8x8_t s, uint8x8_t t);
13308int16x4_t pminsh (int16x4_t s, int16x4_t t);
13309uint8x8_t pminub (uint8x8_t s, uint8x8_t t);
13310uint8x8_t pmovmskb_u (uint8x8_t s);
13311int8x8_t pmovmskb_s (int8x8_t s);
13312uint16x4_t pmulhuh (uint16x4_t s, uint16x4_t t);
13313int16x4_t pmulhh (int16x4_t s, int16x4_t t);
13314int16x4_t pmullh (int16x4_t s, int16x4_t t);
13315int64_t pmuluw (uint32x2_t s, uint32x2_t t);
13316uint8x8_t pasubub (uint8x8_t s, uint8x8_t t);
13317uint16x4_t biadd (uint8x8_t s);
13318uint16x4_t psadbh (uint8x8_t s, uint8x8_t t);
13319uint16x4_t pshufh_u (uint16x4_t dest, uint16x4_t s, uint8_t order);
13320int16x4_t pshufh_s (int16x4_t dest, int16x4_t s, uint8_t order);
13321uint16x4_t psllh_u (uint16x4_t s, uint8_t amount);
13322int16x4_t psllh_s (int16x4_t s, uint8_t amount);
13323uint32x2_t psllw_u (uint32x2_t s, uint8_t amount);
13324int32x2_t psllw_s (int32x2_t s, uint8_t amount);
13325uint16x4_t psrlh_u (uint16x4_t s, uint8_t amount);
13326int16x4_t psrlh_s (int16x4_t s, uint8_t amount);
13327uint32x2_t psrlw_u (uint32x2_t s, uint8_t amount);
13328int32x2_t psrlw_s (int32x2_t s, uint8_t amount);
13329uint16x4_t psrah_u (uint16x4_t s, uint8_t amount);
13330int16x4_t psrah_s (int16x4_t s, uint8_t amount);
13331uint32x2_t psraw_u (uint32x2_t s, uint8_t amount);
13332int32x2_t psraw_s (int32x2_t s, uint8_t amount);
13333uint32x2_t psubw_u (uint32x2_t s, uint32x2_t t);
13334uint16x4_t psubh_u (uint16x4_t s, uint16x4_t t);
13335uint8x8_t psubb_u (uint8x8_t s, uint8x8_t t);
13336int32x2_t psubw_s (int32x2_t s, int32x2_t t);
13337int16x4_t psubh_s (int16x4_t s, int16x4_t t);
13338int8x8_t psubb_s (int8x8_t s, int8x8_t t);
13339uint64_t psubd_u (uint64_t s, uint64_t t);
13340int64_t psubd_s (int64_t s, int64_t t);
13341int16x4_t psubsh (int16x4_t s, int16x4_t t);
13342int8x8_t psubsb (int8x8_t s, int8x8_t t);
13343uint16x4_t psubush (uint16x4_t s, uint16x4_t t);
13344uint8x8_t psubusb (uint8x8_t s, uint8x8_t t);
13345uint32x2_t punpckhwd_u (uint32x2_t s, uint32x2_t t);
13346uint16x4_t punpckhhw_u (uint16x4_t s, uint16x4_t t);
13347uint8x8_t punpckhbh_u (uint8x8_t s, uint8x8_t t);
13348int32x2_t punpckhwd_s (int32x2_t s, int32x2_t t);
13349int16x4_t punpckhhw_s (int16x4_t s, int16x4_t t);
13350int8x8_t punpckhbh_s (int8x8_t s, int8x8_t t);
13351uint32x2_t punpcklwd_u (uint32x2_t s, uint32x2_t t);
13352uint16x4_t punpcklhw_u (uint16x4_t s, uint16x4_t t);
13353uint8x8_t punpcklbh_u (uint8x8_t s, uint8x8_t t);
13354int32x2_t punpcklwd_s (int32x2_t s, int32x2_t t);
13355int16x4_t punpcklhw_s (int16x4_t s, int16x4_t t);
13356int8x8_t punpcklbh_s (int8x8_t s, int8x8_t t);
13357@end smallexample
13358
d840bfd3
CF
13359@menu
13360* Paired-Single Arithmetic::
13361* Paired-Single Built-in Functions::
13362* MIPS-3D Built-in Functions::
13363@end menu
13364
13365@node Paired-Single Arithmetic
13366@subsubsection Paired-Single Arithmetic
13367
13368The table below lists the @code{v2sf} operations for which hardware
13369support exists. @code{a}, @code{b} and @code{c} are @code{v2sf}
13370values and @code{x} is an integral value.
13371
13372@multitable @columnfractions .50 .50
13373@item C code @tab MIPS instruction
13374@item @code{a + b} @tab @code{add.ps}
13375@item @code{a - b} @tab @code{sub.ps}
13376@item @code{-a} @tab @code{neg.ps}
13377@item @code{a * b} @tab @code{mul.ps}
13378@item @code{a * b + c} @tab @code{madd.ps}
13379@item @code{a * b - c} @tab @code{msub.ps}
13380@item @code{-(a * b + c)} @tab @code{nmadd.ps}
13381@item @code{-(a * b - c)} @tab @code{nmsub.ps}
13382@item @code{x ? a : b} @tab @code{movn.ps}/@code{movz.ps}
13383@end multitable
13384
13385Note that the multiply-accumulate instructions can be disabled
13386using the command-line option @code{-mno-fused-madd}.
13387
13388@node Paired-Single Built-in Functions
13389@subsubsection Paired-Single Built-in Functions
13390
13391The following paired-single functions map directly to a particular
13392MIPS instruction. Please refer to the architecture specification
13393for details on what each instruction does.
13394
13395@table @code
13396@item v2sf __builtin_mips_pll_ps (v2sf, v2sf)
13397Pair lower lower (@code{pll.ps}).
13398
13399@item v2sf __builtin_mips_pul_ps (v2sf, v2sf)
13400Pair upper lower (@code{pul.ps}).
13401
13402@item v2sf __builtin_mips_plu_ps (v2sf, v2sf)
13403Pair lower upper (@code{plu.ps}).
13404
13405@item v2sf __builtin_mips_puu_ps (v2sf, v2sf)
13406Pair upper upper (@code{puu.ps}).
13407
13408@item v2sf __builtin_mips_cvt_ps_s (float, float)
13409Convert pair to paired single (@code{cvt.ps.s}).
13410
13411@item float __builtin_mips_cvt_s_pl (v2sf)
13412Convert pair lower to single (@code{cvt.s.pl}).
13413
13414@item float __builtin_mips_cvt_s_pu (v2sf)
13415Convert pair upper to single (@code{cvt.s.pu}).
13416
13417@item v2sf __builtin_mips_abs_ps (v2sf)
13418Absolute value (@code{abs.ps}).
13419
13420@item v2sf __builtin_mips_alnv_ps (v2sf, v2sf, int)
13421Align variable (@code{alnv.ps}).
13422
13423@emph{Note:} The value of the third parameter must be 0 or 4
358a3dbc 13424modulo 8, otherwise the result is unpredictable. Please read the
d840bfd3
CF
13425instruction description for details.
13426@end table
13427
13428The following multi-instruction functions are also available.
13429In each case, @var{cond} can be any of the 16 floating-point conditions:
13430@code{f}, @code{un}, @code{eq}, @code{ueq}, @code{olt}, @code{ult},
13431@code{ole}, @code{ule}, @code{sf}, @code{ngle}, @code{seq}, @code{ngl},
13432@code{lt}, @code{nge}, @code{le} or @code{ngt}.
13433
13434@table @code
13435@item v2sf __builtin_mips_movt_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
13436@itemx v2sf __builtin_mips_movf_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
6f46cb63 13437Conditional move based on floating-point comparison (@code{c.@var{cond}.ps},
d840bfd3
CF
13438@code{movt.ps}/@code{movf.ps}).
13439
13440The @code{movt} functions return the value @var{x} computed by:
13441
13442@smallexample
13443c.@var{cond}.ps @var{cc},@var{a},@var{b}
13444mov.ps @var{x},@var{c}
13445movt.ps @var{x},@var{d},@var{cc}
13446@end smallexample
13447
13448The @code{movf} functions are similar but use @code{movf.ps} instead
13449of @code{movt.ps}.
13450
13451@item int __builtin_mips_upper_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
13452@itemx int __builtin_mips_lower_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
13453Comparison of two paired-single values (@code{c.@var{cond}.ps},
13454@code{bc1t}/@code{bc1f}).
13455
13456These functions compare @var{a} and @var{b} using @code{c.@var{cond}.ps}
13457and return either the upper or lower half of the result. For example:
13458
13459@smallexample
13460v2sf a, b;
13461if (__builtin_mips_upper_c_eq_ps (a, b))
13462 upper_halves_are_equal ();
13463else
13464 upper_halves_are_unequal ();
13465
13466if (__builtin_mips_lower_c_eq_ps (a, b))
13467 lower_halves_are_equal ();
13468else
13469 lower_halves_are_unequal ();
13470@end smallexample
13471@end table
13472
13473@node MIPS-3D Built-in Functions
13474@subsubsection MIPS-3D Built-in Functions
13475
13476The MIPS-3D Application-Specific Extension (ASE) includes additional
13477paired-single instructions that are designed to improve the performance
13478of 3D graphics operations. Support for these instructions is controlled
13479by the @option{-mips3d} command-line option.
13480
13481The functions listed below map directly to a particular MIPS-3D
13482instruction. Please refer to the architecture specification for
13483more details on what each instruction does.
13484
13485@table @code
13486@item v2sf __builtin_mips_addr_ps (v2sf, v2sf)
13487Reduction add (@code{addr.ps}).
13488
13489@item v2sf __builtin_mips_mulr_ps (v2sf, v2sf)
13490Reduction multiply (@code{mulr.ps}).
13491
13492@item v2sf __builtin_mips_cvt_pw_ps (v2sf)
13493Convert paired single to paired word (@code{cvt.pw.ps}).
13494
13495@item v2sf __builtin_mips_cvt_ps_pw (v2sf)
13496Convert paired word to paired single (@code{cvt.ps.pw}).
13497
13498@item float __builtin_mips_recip1_s (float)
13499@itemx double __builtin_mips_recip1_d (double)
13500@itemx v2sf __builtin_mips_recip1_ps (v2sf)
6f46cb63 13501Reduced-precision reciprocal (sequence step 1) (@code{recip1.@var{fmt}}).
d840bfd3
CF
13502
13503@item float __builtin_mips_recip2_s (float, float)
13504@itemx double __builtin_mips_recip2_d (double, double)
13505@itemx v2sf __builtin_mips_recip2_ps (v2sf, v2sf)
6f46cb63 13506Reduced-precision reciprocal (sequence step 2) (@code{recip2.@var{fmt}}).
d840bfd3
CF
13507
13508@item float __builtin_mips_rsqrt1_s (float)
13509@itemx double __builtin_mips_rsqrt1_d (double)
13510@itemx v2sf __builtin_mips_rsqrt1_ps (v2sf)
6f46cb63 13511Reduced-precision reciprocal square root (sequence step 1)
d840bfd3
CF
13512(@code{rsqrt1.@var{fmt}}).
13513
13514@item float __builtin_mips_rsqrt2_s (float, float)
13515@itemx double __builtin_mips_rsqrt2_d (double, double)
13516@itemx v2sf __builtin_mips_rsqrt2_ps (v2sf, v2sf)
6f46cb63 13517Reduced-precision reciprocal square root (sequence step 2)
d840bfd3
CF
13518(@code{rsqrt2.@var{fmt}}).
13519@end table
13520
13521The following multi-instruction functions are also available.
13522In each case, @var{cond} can be any of the 16 floating-point conditions:
13523@code{f}, @code{un}, @code{eq}, @code{ueq}, @code{olt}, @code{ult},
13524@code{ole}, @code{ule}, @code{sf}, @code{ngle}, @code{seq},
13525@code{ngl}, @code{lt}, @code{nge}, @code{le} or @code{ngt}.
13526
13527@table @code
13528@item int __builtin_mips_cabs_@var{cond}_s (float @var{a}, float @var{b})
13529@itemx int __builtin_mips_cabs_@var{cond}_d (double @var{a}, double @var{b})
13530Absolute comparison of two scalar values (@code{cabs.@var{cond}.@var{fmt}},
13531@code{bc1t}/@code{bc1f}).
13532
13533These functions compare @var{a} and @var{b} using @code{cabs.@var{cond}.s}
13534or @code{cabs.@var{cond}.d} and return the result as a boolean value.
13535For example:
13536
13537@smallexample
13538float a, b;
13539if (__builtin_mips_cabs_eq_s (a, b))
13540 true ();
13541else
13542 false ();
13543@end smallexample
13544
13545@item int __builtin_mips_upper_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
13546@itemx int __builtin_mips_lower_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
13547Absolute comparison of two paired-single values (@code{cabs.@var{cond}.ps},
13548@code{bc1t}/@code{bc1f}).
13549
13550These functions compare @var{a} and @var{b} using @code{cabs.@var{cond}.ps}
13551and return either the upper or lower half of the result. For example:
13552
13553@smallexample
13554v2sf a, b;
13555if (__builtin_mips_upper_cabs_eq_ps (a, b))
13556 upper_halves_are_equal ();
13557else
13558 upper_halves_are_unequal ();
13559
13560if (__builtin_mips_lower_cabs_eq_ps (a, b))
13561 lower_halves_are_equal ();
13562else
13563 lower_halves_are_unequal ();
13564@end smallexample
13565
13566@item v2sf __builtin_mips_movt_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
13567@itemx v2sf __builtin_mips_movf_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
13568Conditional move based on absolute comparison (@code{cabs.@var{cond}.ps},
13569@code{movt.ps}/@code{movf.ps}).
13570
13571The @code{movt} functions return the value @var{x} computed by:
13572
13573@smallexample
13574cabs.@var{cond}.ps @var{cc},@var{a},@var{b}
13575mov.ps @var{x},@var{c}
13576movt.ps @var{x},@var{d},@var{cc}
13577@end smallexample
13578
13579The @code{movf} functions are similar but use @code{movf.ps} instead
13580of @code{movt.ps}.
13581
13582@item int __builtin_mips_any_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
13583@itemx int __builtin_mips_all_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
13584@itemx int __builtin_mips_any_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
13585@itemx int __builtin_mips_all_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
13586Comparison of two paired-single values
13587(@code{c.@var{cond}.ps}/@code{cabs.@var{cond}.ps},
13588@code{bc1any2t}/@code{bc1any2f}).
13589
13590These functions compare @var{a} and @var{b} using @code{c.@var{cond}.ps}
13591or @code{cabs.@var{cond}.ps}. The @code{any} forms return true if either
13592result is true and the @code{all} forms return true if both results are true.
13593For example:
13594
13595@smallexample
13596v2sf a, b;
13597if (__builtin_mips_any_c_eq_ps (a, b))
13598 one_is_true ();
13599else
13600 both_are_false ();
13601
13602if (__builtin_mips_all_c_eq_ps (a, b))
13603 both_are_true ();
13604else
13605 one_is_false ();
13606@end smallexample
13607
13608@item int __builtin_mips_any_c_@var{cond}_4s (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
13609@itemx int __builtin_mips_all_c_@var{cond}_4s (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
13610@itemx int __builtin_mips_any_cabs_@var{cond}_4s (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
13611@itemx int __builtin_mips_all_cabs_@var{cond}_4s (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
13612Comparison of four paired-single values
13613(@code{c.@var{cond}.ps}/@code{cabs.@var{cond}.ps},
13614@code{bc1any4t}/@code{bc1any4f}).
13615
13616These functions use @code{c.@var{cond}.ps} or @code{cabs.@var{cond}.ps}
13617to compare @var{a} with @var{b} and to compare @var{c} with @var{d}.
13618The @code{any} forms return true if any of the four results are true
13619and the @code{all} forms return true if all four results are true.
13620For example:
13621
13622@smallexample
13623v2sf a, b, c, d;
13624if (__builtin_mips_any_c_eq_4s (a, b, c, d))
13625 some_are_true ();
13626else
13627 all_are_false ();
13628
13629if (__builtin_mips_all_c_eq_4s (a, b, c, d))
13630 all_are_true ();
13631else
13632 some_are_false ();
13633@end smallexample
13634@end table
13635
40bf31ed
TB
13636@node Other MIPS Built-in Functions
13637@subsection Other MIPS Built-in Functions
13638
13639GCC provides other MIPS-specific built-in functions:
13640
13641@table @code
13642@item void __builtin_mips_cache (int @var{op}, const volatile void *@var{addr})
13643Insert a @samp{cache} instruction with operands @var{op} and @var{addr}.
13644GCC defines the preprocessor macro @code{___GCC_HAVE_BUILTIN_MIPS_CACHE}
13645when this function is available.
a90c0245
RS
13646
13647@item unsigned int __builtin_mips_get_fcsr (void)
13648@itemx void __builtin_mips_set_fcsr (unsigned int @var{value})
13649Get and set the contents of the floating-point control and status register
13650(FPU control register 31). These functions are only available in hard-float
13651code but can be called in both MIPS16 and non-MIPS16 contexts.
13652
13653@code{__builtin_mips_set_fcsr} can be used to change any bit of the
13654register except the condition codes, which GCC assumes are preserved.
40bf31ed
TB
13655@end table
13656
cad055a4
NC
13657@node MSP430 Built-in Functions
13658@subsection MSP430 Built-in Functions
13659
13660GCC provides a couple of special builtin functions to aid in the
13661writing of interrupt handlers in C.
13662
13663@table @code
13664@item __bic_SR_register_on_exit (int @var{mask})
13665This clears the indicated bits in the saved copy of the status register
13666currently residing on the stack. This only works inside interrupt
13667handlers and the changes to the status register will only take affect
13668once the handler returns.
13669
13670@item __bis_SR_register_on_exit (int @var{mask})
13671This sets the indicated bits in the saved copy of the status register
13672currently residing on the stack. This only works inside interrupt
13673handlers and the changes to the status register will only take affect
13674once the handler returns.
5f35dde5
DD
13675
13676@item __delay_cycles (long long @var{cycles})
13677This inserts an instruction sequence that takes exactly @var{cycles}
13678cycles (between 0 and about 17E9) to complete. The inserted sequence
13679may use jumps, loops, or no-ops, and does not interfere with any other
13680instructions. Note that @var{cycles} must be a compile-time constant
13681integer - that is, you must pass a number, not a variable that may be
13682optimized to a constant later. The number of cycles delayed by this
13683builtin is exact.
cad055a4
NC
13684@end table
13685
9304f876
CJW
13686@node NDS32 Built-in Functions
13687@subsection NDS32 Built-in Functions
13688
13689These built-in functions are available for the NDS32 target:
13690
13691@deftypefn {Built-in Function} void __builtin_nds32_isync (int *@var{addr})
13692Insert an ISYNC instruction into the instruction stream where
13693@var{addr} is an instruction address for serialization.
13694@end deftypefn
13695
13696@deftypefn {Built-in Function} void __builtin_nds32_isb (void)
13697Insert an ISB instruction into the instruction stream.
13698@end deftypefn
13699
13700@deftypefn {Built-in Function} int __builtin_nds32_mfsr (int @var{sr})
13701Return the content of a system register which is mapped by @var{sr}.
13702@end deftypefn
13703
13704@deftypefn {Built-in Function} int __builtin_nds32_mfusr (int @var{usr})
13705Return the content of a user space register which is mapped by @var{usr}.
13706@end deftypefn
13707
13708@deftypefn {Built-in Function} void __builtin_nds32_mtsr (int @var{value}, int @var{sr})
13709Move the @var{value} to a system register which is mapped by @var{sr}.
13710@end deftypefn
13711
13712@deftypefn {Built-in Function} void __builtin_nds32_mtusr (int @var{value}, int @var{usr})
13713Move the @var{value} to a user space register which is mapped by @var{usr}.
13714@end deftypefn
13715
13716@deftypefn {Built-in Function} void __builtin_nds32_setgie_en (void)
13717Enable global interrupt.
13718@end deftypefn
13719
13720@deftypefn {Built-in Function} void __builtin_nds32_setgie_dis (void)
13721Disable global interrupt.
13722@end deftypefn
13723
358da97e
HS
13724@node picoChip Built-in Functions
13725@subsection picoChip Built-in Functions
13726
13727GCC provides an interface to selected machine instructions from the
13728picoChip instruction set.
13729
13730@table @code
13731@item int __builtin_sbc (int @var{value})
13732Sign bit count. Return the number of consecutive bits in @var{value}
6f46cb63 13733that have the same value as the sign bit. The result is the number of
358da97e
HS
13734leading sign bits minus one, giving the number of redundant sign bits in
13735@var{value}.
13736
13737@item int __builtin_byteswap (int @var{value})
13738Byte swap. Return the result of swapping the upper and lower bytes of
13739@var{value}.
13740
13741@item int __builtin_brev (int @var{value})
13742Bit reversal. Return the result of reversing the bits in
13743@var{value}. Bit 15 is swapped with bit 0, bit 14 is swapped with bit 1,
13744and so on.
13745
13746@item int __builtin_adds (int @var{x}, int @var{y})
13747Saturating addition. Return the result of adding @var{x} and @var{y},
13748storing the value 32767 if the result overflows.
13749
13750@item int __builtin_subs (int @var{x}, int @var{y})
13751Saturating subtraction. Return the result of subtracting @var{y} from
8ad1dde7 13752@var{x}, storing the value @minus{}32768 if the result overflows.
358da97e
HS
13753
13754@item void __builtin_halt (void)
358a3dbc 13755Halt. The processor stops execution. This built-in is useful for
358da97e
HS
13756implementing assertions.
13757
13758@end table
13759
0efbf084
DE
13760@node PowerPC Built-in Functions
13761@subsection PowerPC Built-in Functions
13762
13763These built-in functions are available for the PowerPC family of
13764processors:
13765@smallexample
13766float __builtin_recipdivf (float, float);
13767float __builtin_rsqrtf (float);
13768double __builtin_recipdiv (double, double);
13769double __builtin_rsqrt (double);
0efbf084
DE
13770uint64_t __builtin_ppc_get_timebase ();
13771unsigned long __builtin_ppc_mftb ();
06b39289 13772double __builtin_unpack_longdouble (long double, int);
06b39289 13773long double __builtin_pack_longdouble (double, double);
0efbf084
DE
13774@end smallexample
13775
13776The @code{vec_rsqrt}, @code{__builtin_rsqrt}, and
13777@code{__builtin_rsqrtf} functions generate multiple instructions to
13778implement the reciprocal sqrt functionality using reciprocal sqrt
13779estimate instructions.
13780
13781The @code{__builtin_recipdiv}, and @code{__builtin_recipdivf}
13782functions generate multiple instructions to implement division using
13783the reciprocal estimate instructions.
13784
13785The @code{__builtin_ppc_get_timebase} and @code{__builtin_ppc_mftb}
13786functions generate instructions to read the Time Base Register. The
13787@code{__builtin_ppc_get_timebase} function may generate multiple
13788instructions and always returns the 64 bits of the Time Base Register.
13789The @code{__builtin_ppc_mftb} function always generates one instruction and
13790returns the Time Base Register value as an unsigned long, throwing away
13791the most significant word on 32-bit environments.
13792
06b39289
MM
13793The following built-in functions are available for the PowerPC family
13794of processors, starting with ISA 2.06 or later (@option{-mcpu=power7}
13795or @option{-mpopcntd}):
13796@smallexample
13797long __builtin_bpermd (long, long);
13798int __builtin_divwe (int, int);
13799int __builtin_divweo (int, int);
13800unsigned int __builtin_divweu (unsigned int, unsigned int);
13801unsigned int __builtin_divweuo (unsigned int, unsigned int);
13802long __builtin_divde (long, long);
13803long __builtin_divdeo (long, long);
13804unsigned long __builtin_divdeu (unsigned long, unsigned long);
13805unsigned long __builtin_divdeuo (unsigned long, unsigned long);
13806unsigned int cdtbcd (unsigned int);
13807unsigned int cbcdtd (unsigned int);
13808unsigned int addg6s (unsigned int, unsigned int);
13809@end smallexample
13810
13811The @code{__builtin_divde}, @code{__builtin_divdeo},
13812@code{__builitin_divdeu}, @code{__builtin_divdeou} functions require a
1381364-bit environment support ISA 2.06 or later.
13814
13815The following built-in functions are available for the PowerPC family
13816of processors when hardware decimal floating point
13817(@option{-mhard-dfp}) is available:
13818@smallexample
13819_Decimal64 __builtin_dxex (_Decimal64);
13820_Decimal128 __builtin_dxexq (_Decimal128);
13821_Decimal64 __builtin_ddedpd (int, _Decimal64);
13822_Decimal128 __builtin_ddedpdq (int, _Decimal128);
13823_Decimal64 __builtin_denbcd (int, _Decimal64);
13824_Decimal128 __builtin_denbcdq (int, _Decimal128);
13825_Decimal64 __builtin_diex (_Decimal64, _Decimal64);
13826_Decimal128 _builtin_diexq (_Decimal128, _Decimal128);
13827_Decimal64 __builtin_dscli (_Decimal64, int);
13828_Decimal128 __builitn_dscliq (_Decimal128, int);
13829_Decimal64 __builtin_dscri (_Decimal64, int);
13830_Decimal128 __builitn_dscriq (_Decimal128, int);
13831unsigned long long __builtin_unpack_dec128 (_Decimal128, int);
13832_Decimal128 __builtin_pack_dec128 (unsigned long long, unsigned long long);
13833@end smallexample
13834
13835The following built-in functions are available for the PowerPC family
13836of processors when the Vector Scalar (vsx) instruction set is
13837available:
13838@smallexample
13839unsigned long long __builtin_unpack_vector_int128 (vector __int128_t, int);
13840vector __int128_t __builtin_pack_vector_int128 (unsigned long long,
13841 unsigned long long);
13842@end smallexample
13843
29e6733c 13844@node PowerPC AltiVec/VSX Built-in Functions
333c8841
AH
13845@subsection PowerPC AltiVec Built-in Functions
13846
b0b343db
JJ
13847GCC provides an interface for the PowerPC family of processors to access
13848the AltiVec operations described in Motorola's AltiVec Programming
13849Interface Manual. The interface is made available by including
13850@code{<altivec.h>} and using @option{-maltivec} and
13851@option{-mabi=altivec}. The interface supports the following vector
13852types.
333c8841 13853
b0b343db
JJ
13854@smallexample
13855vector unsigned char
13856vector signed char
13857vector bool char
333c8841 13858
b0b343db
JJ
13859vector unsigned short
13860vector signed short
13861vector bool short
13862vector pixel
13863
13864vector unsigned int
13865vector signed int
13866vector bool int
13867vector float
13868@end smallexample
13869
29e6733c
MM
13870If @option{-mvsx} is used the following additional vector types are
13871implemented.
13872
13873@smallexample
13874vector unsigned long
13875vector signed long
13876vector double
13877@end smallexample
13878
13879The long types are only implemented for 64-bit code generation, and
13880the long type is only used in the floating point/integer conversion
13881instructions.
13882
b0b343db
JJ
13883GCC's implementation of the high-level language interface available from
13884C and C++ code differs from Motorola's documentation in several ways.
13885
13886@itemize @bullet
13887
13888@item
13889A vector constant is a list of constant expressions within curly braces.
13890
13891@item
13892A vector initializer requires no cast if the vector constant is of the
13893same type as the variable it is initializing.
333c8841 13894
b0b343db 13895@item
5edea4c6
JJ
13896If @code{signed} or @code{unsigned} is omitted, the signedness of the
13897vector type is the default signedness of the base type. The default
13898varies depending on the operating system, so a portable program should
13899always specify the signedness.
4e6e4e4c
JJ
13900
13901@item
13902Compiling with @option{-maltivec} adds keywords @code{__vector},
5950c3c9
BE
13903@code{vector}, @code{__pixel}, @code{pixel}, @code{__bool} and
13904@code{bool}. When compiling ISO C, the context-sensitive substitution
13905of the keywords @code{vector}, @code{pixel} and @code{bool} is
13906disabled. To use them, you must include @code{<altivec.h>} instead.
4e6e4e4c
JJ
13907
13908@item
13909GCC allows using a @code{typedef} name as the type specifier for a
13910vector type.
b0b343db
JJ
13911
13912@item
13913For C, overloaded functions are implemented with macros so the following
13914does not work:
90989b26
AH
13915
13916@smallexample
8254cb45 13917 vec_add ((vector signed int)@{1, 2, 3, 4@}, foo);
90989b26
AH
13918@end smallexample
13919
c513ecbf 13920@noindent
b0b343db
JJ
13921Since @code{vec_add} is a macro, the vector constant in the example
13922is treated as four separate arguments. Wrap the entire argument in
13923parentheses for this to work.
13924@end itemize
90989b26 13925
ae4b4a02
AH
13926@emph{Note:} Only the @code{<altivec.h>} interface is supported.
13927Internally, GCC uses built-in functions to achieve the functionality in
13928the aforementioned header file, but they are not supported and are
13929subject to change without notice.
13930
b0b343db
JJ
13931The following interfaces are supported for the generic and specific
13932AltiVec operations and the AltiVec predicates. In cases where there
13933is a direct mapping between generic and specific operations, only the
13934generic names are shown here, although the specific operations can also
13935be used.
333c8841 13936
b0b343db
JJ
13937Arguments that are documented as @code{const int} require literal
13938integral values within the range required for that operation.
333c8841 13939
b0b343db
JJ
13940@smallexample
13941vector signed char vec_abs (vector signed char);
13942vector signed short vec_abs (vector signed short);
13943vector signed int vec_abs (vector signed int);
13944vector float vec_abs (vector float);
333c8841 13945
b0b343db
JJ
13946vector signed char vec_abss (vector signed char);
13947vector signed short vec_abss (vector signed short);
13948vector signed int vec_abss (vector signed int);
333c8841 13949
b0b343db
JJ
13950vector signed char vec_add (vector bool char, vector signed char);
13951vector signed char vec_add (vector signed char, vector bool char);
13952vector signed char vec_add (vector signed char, vector signed char);
13953vector unsigned char vec_add (vector bool char, vector unsigned char);
13954vector unsigned char vec_add (vector unsigned char, vector bool char);
924fcc4e
JM
13955vector unsigned char vec_add (vector unsigned char,
13956 vector unsigned char);
b0b343db
JJ
13957vector signed short vec_add (vector bool short, vector signed short);
13958vector signed short vec_add (vector signed short, vector bool short);
333c8841 13959vector signed short vec_add (vector signed short, vector signed short);
b0b343db 13960vector unsigned short vec_add (vector bool short,
924fcc4e
JM
13961 vector unsigned short);
13962vector unsigned short vec_add (vector unsigned short,
b0b343db 13963 vector bool short);
6e5bb5ad
JM
13964vector unsigned short vec_add (vector unsigned short,
13965 vector unsigned short);
b0b343db
JJ
13966vector signed int vec_add (vector bool int, vector signed int);
13967vector signed int vec_add (vector signed int, vector bool int);
333c8841 13968vector signed int vec_add (vector signed int, vector signed int);
b0b343db
JJ
13969vector unsigned int vec_add (vector bool int, vector unsigned int);
13970vector unsigned int vec_add (vector unsigned int, vector bool int);
333c8841
AH
13971vector unsigned int vec_add (vector unsigned int, vector unsigned int);
13972vector float vec_add (vector float, vector float);
13973
b0b343db
JJ
13974vector float vec_vaddfp (vector float, vector float);
13975
13976vector signed int vec_vadduwm (vector bool int, vector signed int);
13977vector signed int vec_vadduwm (vector signed int, vector bool int);
13978vector signed int vec_vadduwm (vector signed int, vector signed int);
13979vector unsigned int vec_vadduwm (vector bool int, vector unsigned int);
13980vector unsigned int vec_vadduwm (vector unsigned int, vector bool int);
13981vector unsigned int vec_vadduwm (vector unsigned int,
13982 vector unsigned int);
13983
13984vector signed short vec_vadduhm (vector bool short,
13985 vector signed short);
13986vector signed short vec_vadduhm (vector signed short,
13987 vector bool short);
13988vector signed short vec_vadduhm (vector signed short,
13989 vector signed short);
13990vector unsigned short vec_vadduhm (vector bool short,
13991 vector unsigned short);
13992vector unsigned short vec_vadduhm (vector unsigned short,
13993 vector bool short);
13994vector unsigned short vec_vadduhm (vector unsigned short,
13995 vector unsigned short);
13996
13997vector signed char vec_vaddubm (vector bool char, vector signed char);
13998vector signed char vec_vaddubm (vector signed char, vector bool char);
13999vector signed char vec_vaddubm (vector signed char, vector signed char);
14000vector unsigned char vec_vaddubm (vector bool char,
14001 vector unsigned char);
14002vector unsigned char vec_vaddubm (vector unsigned char,
14003 vector bool char);
14004vector unsigned char vec_vaddubm (vector unsigned char,
14005 vector unsigned char);
14006
333c8841
AH
14007vector unsigned int vec_addc (vector unsigned int, vector unsigned int);
14008
b0b343db
JJ
14009vector unsigned char vec_adds (vector bool char, vector unsigned char);
14010vector unsigned char vec_adds (vector unsigned char, vector bool char);
924fcc4e
JM
14011vector unsigned char vec_adds (vector unsigned char,
14012 vector unsigned char);
b0b343db
JJ
14013vector signed char vec_adds (vector bool char, vector signed char);
14014vector signed char vec_adds (vector signed char, vector bool char);
333c8841 14015vector signed char vec_adds (vector signed char, vector signed char);
b0b343db 14016vector unsigned short vec_adds (vector bool short,
924fcc4e
JM
14017 vector unsigned short);
14018vector unsigned short vec_adds (vector unsigned short,
b0b343db 14019 vector bool short);
6e5bb5ad
JM
14020vector unsigned short vec_adds (vector unsigned short,
14021 vector unsigned short);
b0b343db
JJ
14022vector signed short vec_adds (vector bool short, vector signed short);
14023vector signed short vec_adds (vector signed short, vector bool short);
333c8841 14024vector signed short vec_adds (vector signed short, vector signed short);
b0b343db
JJ
14025vector unsigned int vec_adds (vector bool int, vector unsigned int);
14026vector unsigned int vec_adds (vector unsigned int, vector bool int);
333c8841 14027vector unsigned int vec_adds (vector unsigned int, vector unsigned int);
b0b343db
JJ
14028vector signed int vec_adds (vector bool int, vector signed int);
14029vector signed int vec_adds (vector signed int, vector bool int);
333c8841
AH
14030vector signed int vec_adds (vector signed int, vector signed int);
14031
b0b343db
JJ
14032vector signed int vec_vaddsws (vector bool int, vector signed int);
14033vector signed int vec_vaddsws (vector signed int, vector bool int);
14034vector signed int vec_vaddsws (vector signed int, vector signed int);
14035
14036vector unsigned int vec_vadduws (vector bool int, vector unsigned int);
14037vector unsigned int vec_vadduws (vector unsigned int, vector bool int);
14038vector unsigned int vec_vadduws (vector unsigned int,
14039 vector unsigned int);
14040
14041vector signed short vec_vaddshs (vector bool short,
14042 vector signed short);
14043vector signed short vec_vaddshs (vector signed short,
14044 vector bool short);
14045vector signed short vec_vaddshs (vector signed short,
14046 vector signed short);
14047
14048vector unsigned short vec_vadduhs (vector bool short,
14049 vector unsigned short);
14050vector unsigned short vec_vadduhs (vector unsigned short,
14051 vector bool short);
14052vector unsigned short vec_vadduhs (vector unsigned short,
14053 vector unsigned short);
14054
14055vector signed char vec_vaddsbs (vector bool char, vector signed char);
14056vector signed char vec_vaddsbs (vector signed char, vector bool char);
14057vector signed char vec_vaddsbs (vector signed char, vector signed char);
14058
14059vector unsigned char vec_vaddubs (vector bool char,
14060 vector unsigned char);
14061vector unsigned char vec_vaddubs (vector unsigned char,
14062 vector bool char);
14063vector unsigned char vec_vaddubs (vector unsigned char,
14064 vector unsigned char);
14065
333c8841 14066vector float vec_and (vector float, vector float);
b0b343db
JJ
14067vector float vec_and (vector float, vector bool int);
14068vector float vec_and (vector bool int, vector float);
14069vector bool int vec_and (vector bool int, vector bool int);
14070vector signed int vec_and (vector bool int, vector signed int);
14071vector signed int vec_and (vector signed int, vector bool int);
333c8841 14072vector signed int vec_and (vector signed int, vector signed int);
b0b343db
JJ
14073vector unsigned int vec_and (vector bool int, vector unsigned int);
14074vector unsigned int vec_and (vector unsigned int, vector bool int);
333c8841 14075vector unsigned int vec_and (vector unsigned int, vector unsigned int);
b0b343db
JJ
14076vector bool short vec_and (vector bool short, vector bool short);
14077vector signed short vec_and (vector bool short, vector signed short);
14078vector signed short vec_and (vector signed short, vector bool short);
333c8841 14079vector signed short vec_and (vector signed short, vector signed short);
b0b343db 14080vector unsigned short vec_and (vector bool short,
924fcc4e
JM
14081 vector unsigned short);
14082vector unsigned short vec_and (vector unsigned short,
b0b343db 14083 vector bool short);
6e5bb5ad
JM
14084vector unsigned short vec_and (vector unsigned short,
14085 vector unsigned short);
b0b343db
JJ
14086vector signed char vec_and (vector bool char, vector signed char);
14087vector bool char vec_and (vector bool char, vector bool char);
14088vector signed char vec_and (vector signed char, vector bool char);
333c8841 14089vector signed char vec_and (vector signed char, vector signed char);
b0b343db
JJ
14090vector unsigned char vec_and (vector bool char, vector unsigned char);
14091vector unsigned char vec_and (vector unsigned char, vector bool char);
924fcc4e
JM
14092vector unsigned char vec_and (vector unsigned char,
14093 vector unsigned char);
333c8841
AH
14094
14095vector float vec_andc (vector float, vector float);
b0b343db
JJ
14096vector float vec_andc (vector float, vector bool int);
14097vector float vec_andc (vector bool int, vector float);
14098vector bool int vec_andc (vector bool int, vector bool int);
14099vector signed int vec_andc (vector bool int, vector signed int);
14100vector signed int vec_andc (vector signed int, vector bool int);
333c8841 14101vector signed int vec_andc (vector signed int, vector signed int);
b0b343db
JJ
14102vector unsigned int vec_andc (vector bool int, vector unsigned int);
14103vector unsigned int vec_andc (vector unsigned int, vector bool int);
333c8841 14104vector unsigned int vec_andc (vector unsigned int, vector unsigned int);
b0b343db
JJ
14105vector bool short vec_andc (vector bool short, vector bool short);
14106vector signed short vec_andc (vector bool short, vector signed short);
14107vector signed short vec_andc (vector signed short, vector bool short);
333c8841 14108vector signed short vec_andc (vector signed short, vector signed short);
b0b343db 14109vector unsigned short vec_andc (vector bool short,
924fcc4e
JM
14110 vector unsigned short);
14111vector unsigned short vec_andc (vector unsigned short,
b0b343db 14112 vector bool short);
6e5bb5ad
JM
14113vector unsigned short vec_andc (vector unsigned short,
14114 vector unsigned short);
b0b343db
JJ
14115vector signed char vec_andc (vector bool char, vector signed char);
14116vector bool char vec_andc (vector bool char, vector bool char);
14117vector signed char vec_andc (vector signed char, vector bool char);
333c8841 14118vector signed char vec_andc (vector signed char, vector signed char);
b0b343db
JJ
14119vector unsigned char vec_andc (vector bool char, vector unsigned char);
14120vector unsigned char vec_andc (vector unsigned char, vector bool char);
924fcc4e
JM
14121vector unsigned char vec_andc (vector unsigned char,
14122 vector unsigned char);
333c8841 14123
924fcc4e
JM
14124vector unsigned char vec_avg (vector unsigned char,
14125 vector unsigned char);
333c8841 14126vector signed char vec_avg (vector signed char, vector signed char);
6e5bb5ad
JM
14127vector unsigned short vec_avg (vector unsigned short,
14128 vector unsigned short);
333c8841
AH
14129vector signed short vec_avg (vector signed short, vector signed short);
14130vector unsigned int vec_avg (vector unsigned int, vector unsigned int);
14131vector signed int vec_avg (vector signed int, vector signed int);
14132
b0b343db
JJ
14133vector signed int vec_vavgsw (vector signed int, vector signed int);
14134
14135vector unsigned int vec_vavguw (vector unsigned int,
14136 vector unsigned int);
14137
14138vector signed short vec_vavgsh (vector signed short,
14139 vector signed short);
14140
14141vector unsigned short vec_vavguh (vector unsigned short,
14142 vector unsigned short);
14143
14144vector signed char vec_vavgsb (vector signed char, vector signed char);
14145
14146vector unsigned char vec_vavgub (vector unsigned char,
14147 vector unsigned char);
14148
29e6733c
MM
14149vector float vec_copysign (vector float);
14150
333c8841
AH
14151vector float vec_ceil (vector float);
14152
14153vector signed int vec_cmpb (vector float, vector float);
14154
b0b343db
JJ
14155vector bool char vec_cmpeq (vector signed char, vector signed char);
14156vector bool char vec_cmpeq (vector unsigned char, vector unsigned char);
14157vector bool short vec_cmpeq (vector signed short, vector signed short);
14158vector bool short vec_cmpeq (vector unsigned short,
14159 vector unsigned short);
14160vector bool int vec_cmpeq (vector signed int, vector signed int);
14161vector bool int vec_cmpeq (vector unsigned int, vector unsigned int);
14162vector bool int vec_cmpeq (vector float, vector float);
333c8841 14163
b0b343db 14164vector bool int vec_vcmpeqfp (vector float, vector float);
333c8841 14165
b0b343db
JJ
14166vector bool int vec_vcmpequw (vector signed int, vector signed int);
14167vector bool int vec_vcmpequw (vector unsigned int, vector unsigned int);
14168
14169vector bool short vec_vcmpequh (vector signed short,
14170 vector signed short);
14171vector bool short vec_vcmpequh (vector unsigned short,
14172 vector unsigned short);
333c8841 14173
b0b343db
JJ
14174vector bool char vec_vcmpequb (vector signed char, vector signed char);
14175vector bool char vec_vcmpequb (vector unsigned char,
14176 vector unsigned char);
333c8841 14177
b0b343db 14178vector bool int vec_cmpge (vector float, vector float);
333c8841 14179
b0b343db
JJ
14180vector bool char vec_cmpgt (vector unsigned char, vector unsigned char);
14181vector bool char vec_cmpgt (vector signed char, vector signed char);
14182vector bool short vec_cmpgt (vector unsigned short,
14183 vector unsigned short);
14184vector bool short vec_cmpgt (vector signed short, vector signed short);
14185vector bool int vec_cmpgt (vector unsigned int, vector unsigned int);
14186vector bool int vec_cmpgt (vector signed int, vector signed int);
14187vector bool int vec_cmpgt (vector float, vector float);
14188
14189vector bool int vec_vcmpgtfp (vector float, vector float);
14190
14191vector bool int vec_vcmpgtsw (vector signed int, vector signed int);
14192
14193vector bool int vec_vcmpgtuw (vector unsigned int, vector unsigned int);
333c8841 14194
b0b343db
JJ
14195vector bool short vec_vcmpgtsh (vector signed short,
14196 vector signed short);
14197
14198vector bool short vec_vcmpgtuh (vector unsigned short,
14199 vector unsigned short);
14200
14201vector bool char vec_vcmpgtsb (vector signed char, vector signed char);
14202
14203vector bool char vec_vcmpgtub (vector unsigned char,
14204 vector unsigned char);
14205
14206vector bool int vec_cmple (vector float, vector float);
14207
14208vector bool char vec_cmplt (vector unsigned char, vector unsigned char);
14209vector bool char vec_cmplt (vector signed char, vector signed char);
14210vector bool short vec_cmplt (vector unsigned short,
14211 vector unsigned short);
14212vector bool short vec_cmplt (vector signed short, vector signed short);
14213vector bool int vec_cmplt (vector unsigned int, vector unsigned int);
14214vector bool int vec_cmplt (vector signed int, vector signed int);
14215vector bool int vec_cmplt (vector float, vector float);
333c8841 14216
65fa79c3
BS
14217vector float vec_cpsgn (vector float, vector float);
14218
b0b343db
JJ
14219vector float vec_ctf (vector unsigned int, const int);
14220vector float vec_ctf (vector signed int, const int);
70f0f8b2
BS
14221vector double vec_ctf (vector unsigned long, const int);
14222vector double vec_ctf (vector signed long, const int);
333c8841 14223
b0b343db
JJ
14224vector float vec_vcfsx (vector signed int, const int);
14225
14226vector float vec_vcfux (vector unsigned int, const int);
14227
14228vector signed int vec_cts (vector float, const int);
70f0f8b2 14229vector signed long vec_cts (vector double, const int);
b0b343db
JJ
14230
14231vector unsigned int vec_ctu (vector float, const int);
70f0f8b2 14232vector unsigned long vec_ctu (vector double, const int);
b0b343db
JJ
14233
14234void vec_dss (const int);
333c8841
AH
14235
14236void vec_dssall (void);
14237
b0b343db
JJ
14238void vec_dst (const vector unsigned char *, int, const int);
14239void vec_dst (const vector signed char *, int, const int);
14240void vec_dst (const vector bool char *, int, const int);
14241void vec_dst (const vector unsigned short *, int, const int);
14242void vec_dst (const vector signed short *, int, const int);
14243void vec_dst (const vector bool short *, int, const int);
14244void vec_dst (const vector pixel *, int, const int);
14245void vec_dst (const vector unsigned int *, int, const int);
14246void vec_dst (const vector signed int *, int, const int);
14247void vec_dst (const vector bool int *, int, const int);
14248void vec_dst (const vector float *, int, const int);
14249void vec_dst (const unsigned char *, int, const int);
14250void vec_dst (const signed char *, int, const int);
14251void vec_dst (const unsigned short *, int, const int);
14252void vec_dst (const short *, int, const int);
14253void vec_dst (const unsigned int *, int, const int);
14254void vec_dst (const int *, int, const int);
14255void vec_dst (const unsigned long *, int, const int);
14256void vec_dst (const long *, int, const int);
14257void vec_dst (const float *, int, const int);
14258
14259void vec_dstst (const vector unsigned char *, int, const int);
14260void vec_dstst (const vector signed char *, int, const int);
14261void vec_dstst (const vector bool char *, int, const int);
14262void vec_dstst (const vector unsigned short *, int, const int);
14263void vec_dstst (const vector signed short *, int, const int);
14264void vec_dstst (const vector bool short *, int, const int);
14265void vec_dstst (const vector pixel *, int, const int);
14266void vec_dstst (const vector unsigned int *, int, const int);
14267void vec_dstst (const vector signed int *, int, const int);
14268void vec_dstst (const vector bool int *, int, const int);
14269void vec_dstst (const vector float *, int, const int);
14270void vec_dstst (const unsigned char *, int, const int);
14271void vec_dstst (const signed char *, int, const int);
14272void vec_dstst (const unsigned short *, int, const int);
14273void vec_dstst (const short *, int, const int);
14274void vec_dstst (const unsigned int *, int, const int);
14275void vec_dstst (const int *, int, const int);
14276void vec_dstst (const unsigned long *, int, const int);
14277void vec_dstst (const long *, int, const int);
14278void vec_dstst (const float *, int, const int);
14279
14280void vec_dststt (const vector unsigned char *, int, const int);
14281void vec_dststt (const vector signed char *, int, const int);
14282void vec_dststt (const vector bool char *, int, const int);
14283void vec_dststt (const vector unsigned short *, int, const int);
14284void vec_dststt (const vector signed short *, int, const int);
14285void vec_dststt (const vector bool short *, int, const int);
14286void vec_dststt (const vector pixel *, int, const int);
14287void vec_dststt (const vector unsigned int *, int, const int);
14288void vec_dststt (const vector signed int *, int, const int);
14289void vec_dststt (const vector bool int *, int, const int);
14290void vec_dststt (const vector float *, int, const int);
14291void vec_dststt (const unsigned char *, int, const int);
14292void vec_dststt (const signed char *, int, const int);
14293void vec_dststt (const unsigned short *, int, const int);
14294void vec_dststt (const short *, int, const int);
14295void vec_dststt (const unsigned int *, int, const int);
14296void vec_dststt (const int *, int, const int);
14297void vec_dststt (const unsigned long *, int, const int);
14298void vec_dststt (const long *, int, const int);
14299void vec_dststt (const float *, int, const int);
14300
14301void vec_dstt (const vector unsigned char *, int, const int);
14302void vec_dstt (const vector signed char *, int, const int);
14303void vec_dstt (const vector bool char *, int, const int);
14304void vec_dstt (const vector unsigned short *, int, const int);
14305void vec_dstt (const vector signed short *, int, const int);
14306void vec_dstt (const vector bool short *, int, const int);
14307void vec_dstt (const vector pixel *, int, const int);
14308void vec_dstt (const vector unsigned int *, int, const int);
14309void vec_dstt (const vector signed int *, int, const int);
14310void vec_dstt (const vector bool int *, int, const int);
14311void vec_dstt (const vector float *, int, const int);
14312void vec_dstt (const unsigned char *, int, const int);
14313void vec_dstt (const signed char *, int, const int);
14314void vec_dstt (const unsigned short *, int, const int);
14315void vec_dstt (const short *, int, const int);
14316void vec_dstt (const unsigned int *, int, const int);
14317void vec_dstt (const int *, int, const int);
14318void vec_dstt (const unsigned long *, int, const int);
14319void vec_dstt (const long *, int, const int);
14320void vec_dstt (const float *, int, const int);
14321
14322vector float vec_expte (vector float);
14323
14324vector float vec_floor (vector float);
14325
14326vector float vec_ld (int, const vector float *);
14327vector float vec_ld (int, const float *);
14328vector bool int vec_ld (int, const vector bool int *);
14329vector signed int vec_ld (int, const vector signed int *);
14330vector signed int vec_ld (int, const int *);
14331vector signed int vec_ld (int, const long *);
14332vector unsigned int vec_ld (int, const vector unsigned int *);
14333vector unsigned int vec_ld (int, const unsigned int *);
14334vector unsigned int vec_ld (int, const unsigned long *);
14335vector bool short vec_ld (int, const vector bool short *);
14336vector pixel vec_ld (int, const vector pixel *);
14337vector signed short vec_ld (int, const vector signed short *);
14338vector signed short vec_ld (int, const short *);
14339vector unsigned short vec_ld (int, const vector unsigned short *);
14340vector unsigned short vec_ld (int, const unsigned short *);
14341vector bool char vec_ld (int, const vector bool char *);
14342vector signed char vec_ld (int, const vector signed char *);
14343vector signed char vec_ld (int, const signed char *);
14344vector unsigned char vec_ld (int, const vector unsigned char *);
14345vector unsigned char vec_ld (int, const unsigned char *);
14346
14347vector signed char vec_lde (int, const signed char *);
14348vector unsigned char vec_lde (int, const unsigned char *);
14349vector signed short vec_lde (int, const short *);
14350vector unsigned short vec_lde (int, const unsigned short *);
14351vector float vec_lde (int, const float *);
14352vector signed int vec_lde (int, const int *);
14353vector unsigned int vec_lde (int, const unsigned int *);
14354vector signed int vec_lde (int, const long *);
14355vector unsigned int vec_lde (int, const unsigned long *);
14356
14357vector float vec_lvewx (int, float *);
14358vector signed int vec_lvewx (int, int *);
14359vector unsigned int vec_lvewx (int, unsigned int *);
14360vector signed int vec_lvewx (int, long *);
14361vector unsigned int vec_lvewx (int, unsigned long *);
14362
14363vector signed short vec_lvehx (int, short *);
14364vector unsigned short vec_lvehx (int, unsigned short *);
14365
14366vector signed char vec_lvebx (int, char *);
14367vector unsigned char vec_lvebx (int, unsigned char *);
14368
14369vector float vec_ldl (int, const vector float *);
14370vector float vec_ldl (int, const float *);
14371vector bool int vec_ldl (int, const vector bool int *);
14372vector signed int vec_ldl (int, const vector signed int *);
14373vector signed int vec_ldl (int, const int *);
14374vector signed int vec_ldl (int, const long *);
14375vector unsigned int vec_ldl (int, const vector unsigned int *);
14376vector unsigned int vec_ldl (int, const unsigned int *);
14377vector unsigned int vec_ldl (int, const unsigned long *);
14378vector bool short vec_ldl (int, const vector bool short *);
14379vector pixel vec_ldl (int, const vector pixel *);
14380vector signed short vec_ldl (int, const vector signed short *);
14381vector signed short vec_ldl (int, const short *);
14382vector unsigned short vec_ldl (int, const vector unsigned short *);
14383vector unsigned short vec_ldl (int, const unsigned short *);
14384vector bool char vec_ldl (int, const vector bool char *);
14385vector signed char vec_ldl (int, const vector signed char *);
14386vector signed char vec_ldl (int, const signed char *);
14387vector unsigned char vec_ldl (int, const vector unsigned char *);
14388vector unsigned char vec_ldl (int, const unsigned char *);
333c8841
AH
14389
14390vector float vec_loge (vector float);
14391
b0b343db
JJ
14392vector unsigned char vec_lvsl (int, const volatile unsigned char *);
14393vector unsigned char vec_lvsl (int, const volatile signed char *);
14394vector unsigned char vec_lvsl (int, const volatile unsigned short *);
14395vector unsigned char vec_lvsl (int, const volatile short *);
14396vector unsigned char vec_lvsl (int, const volatile unsigned int *);
14397vector unsigned char vec_lvsl (int, const volatile int *);
14398vector unsigned char vec_lvsl (int, const volatile unsigned long *);
14399vector unsigned char vec_lvsl (int, const volatile long *);
14400vector unsigned char vec_lvsl (int, const volatile float *);
14401
14402vector unsigned char vec_lvsr (int, const volatile unsigned char *);
14403vector unsigned char vec_lvsr (int, const volatile signed char *);
14404vector unsigned char vec_lvsr (int, const volatile unsigned short *);
14405vector unsigned char vec_lvsr (int, const volatile short *);
14406vector unsigned char vec_lvsr (int, const volatile unsigned int *);
14407vector unsigned char vec_lvsr (int, const volatile int *);
14408vector unsigned char vec_lvsr (int, const volatile unsigned long *);
14409vector unsigned char vec_lvsr (int, const volatile long *);
14410vector unsigned char vec_lvsr (int, const volatile float *);
333c8841
AH
14411
14412vector float vec_madd (vector float, vector float, vector float);
14413
b0b343db
JJ
14414vector signed short vec_madds (vector signed short,
14415 vector signed short,
6e5bb5ad 14416 vector signed short);
333c8841 14417
b0b343db
JJ
14418vector unsigned char vec_max (vector bool char, vector unsigned char);
14419vector unsigned char vec_max (vector unsigned char, vector bool char);
924fcc4e
JM
14420vector unsigned char vec_max (vector unsigned char,
14421 vector unsigned char);
b0b343db
JJ
14422vector signed char vec_max (vector bool char, vector signed char);
14423vector signed char vec_max (vector signed char, vector bool char);
333c8841 14424vector signed char vec_max (vector signed char, vector signed char);
b0b343db 14425vector unsigned short vec_max (vector bool short,
924fcc4e
JM
14426 vector unsigned short);
14427vector unsigned short vec_max (vector unsigned short,
b0b343db 14428 vector bool short);
6e5bb5ad
JM
14429vector unsigned short vec_max (vector unsigned short,
14430 vector unsigned short);
b0b343db
JJ
14431vector signed short vec_max (vector bool short, vector signed short);
14432vector signed short vec_max (vector signed short, vector bool short);
333c8841 14433vector signed short vec_max (vector signed short, vector signed short);
b0b343db
JJ
14434vector unsigned int vec_max (vector bool int, vector unsigned int);
14435vector unsigned int vec_max (vector unsigned int, vector bool int);
333c8841 14436vector unsigned int vec_max (vector unsigned int, vector unsigned int);
b0b343db
JJ
14437vector signed int vec_max (vector bool int, vector signed int);
14438vector signed int vec_max (vector signed int, vector bool int);
333c8841
AH
14439vector signed int vec_max (vector signed int, vector signed int);
14440vector float vec_max (vector float, vector float);
14441
b0b343db
JJ
14442vector float vec_vmaxfp (vector float, vector float);
14443
14444vector signed int vec_vmaxsw (vector bool int, vector signed int);
14445vector signed int vec_vmaxsw (vector signed int, vector bool int);
14446vector signed int vec_vmaxsw (vector signed int, vector signed int);
14447
14448vector unsigned int vec_vmaxuw (vector bool int, vector unsigned int);
14449vector unsigned int vec_vmaxuw (vector unsigned int, vector bool int);
14450vector unsigned int vec_vmaxuw (vector unsigned int,
14451 vector unsigned int);
14452
14453vector signed short vec_vmaxsh (vector bool short, vector signed short);
14454vector signed short vec_vmaxsh (vector signed short, vector bool short);
14455vector signed short vec_vmaxsh (vector signed short,
14456 vector signed short);
14457
14458vector unsigned short vec_vmaxuh (vector bool short,
14459 vector unsigned short);
14460vector unsigned short vec_vmaxuh (vector unsigned short,
14461 vector bool short);
14462vector unsigned short vec_vmaxuh (vector unsigned short,
14463 vector unsigned short);
14464
14465vector signed char vec_vmaxsb (vector bool char, vector signed char);
14466vector signed char vec_vmaxsb (vector signed char, vector bool char);
14467vector signed char vec_vmaxsb (vector signed char, vector signed char);
14468
14469vector unsigned char vec_vmaxub (vector bool char,
14470 vector unsigned char);
14471vector unsigned char vec_vmaxub (vector unsigned char,
14472 vector bool char);
14473vector unsigned char vec_vmaxub (vector unsigned char,
14474 vector unsigned char);
14475
14476vector bool char vec_mergeh (vector bool char, vector bool char);
333c8841 14477vector signed char vec_mergeh (vector signed char, vector signed char);
6e5bb5ad
JM
14478vector unsigned char vec_mergeh (vector unsigned char,
14479 vector unsigned char);
b0b343db
JJ
14480vector bool short vec_mergeh (vector bool short, vector bool short);
14481vector pixel vec_mergeh (vector pixel, vector pixel);
924fcc4e
JM
14482vector signed short vec_mergeh (vector signed short,
14483 vector signed short);
6e5bb5ad
JM
14484vector unsigned short vec_mergeh (vector unsigned short,
14485 vector unsigned short);
333c8841 14486vector float vec_mergeh (vector float, vector float);
b0b343db 14487vector bool int vec_mergeh (vector bool int, vector bool int);
333c8841 14488vector signed int vec_mergeh (vector signed int, vector signed int);
924fcc4e
JM
14489vector unsigned int vec_mergeh (vector unsigned int,
14490 vector unsigned int);
333c8841 14491
b0b343db
JJ
14492vector float vec_vmrghw (vector float, vector float);
14493vector bool int vec_vmrghw (vector bool int, vector bool int);
14494vector signed int vec_vmrghw (vector signed int, vector signed int);
14495vector unsigned int vec_vmrghw (vector unsigned int,
14496 vector unsigned int);
14497
14498vector bool short vec_vmrghh (vector bool short, vector bool short);
14499vector signed short vec_vmrghh (vector signed short,
14500 vector signed short);
14501vector unsigned short vec_vmrghh (vector unsigned short,
14502 vector unsigned short);
14503vector pixel vec_vmrghh (vector pixel, vector pixel);
14504
14505vector bool char vec_vmrghb (vector bool char, vector bool char);
14506vector signed char vec_vmrghb (vector signed char, vector signed char);
14507vector unsigned char vec_vmrghb (vector unsigned char,
14508 vector unsigned char);
14509
14510vector bool char vec_mergel (vector bool char, vector bool char);
333c8841 14511vector signed char vec_mergel (vector signed char, vector signed char);
6e5bb5ad
JM
14512vector unsigned char vec_mergel (vector unsigned char,
14513 vector unsigned char);
b0b343db
JJ
14514vector bool short vec_mergel (vector bool short, vector bool short);
14515vector pixel vec_mergel (vector pixel, vector pixel);
924fcc4e
JM
14516vector signed short vec_mergel (vector signed short,
14517 vector signed short);
6e5bb5ad
JM
14518vector unsigned short vec_mergel (vector unsigned short,
14519 vector unsigned short);
333c8841 14520vector float vec_mergel (vector float, vector float);
b0b343db 14521vector bool int vec_mergel (vector bool int, vector bool int);
333c8841 14522vector signed int vec_mergel (vector signed int, vector signed int);
924fcc4e
JM
14523vector unsigned int vec_mergel (vector unsigned int,
14524 vector unsigned int);
333c8841 14525
b0b343db
JJ
14526vector float vec_vmrglw (vector float, vector float);
14527vector signed int vec_vmrglw (vector signed int, vector signed int);
14528vector unsigned int vec_vmrglw (vector unsigned int,
14529 vector unsigned int);
14530vector bool int vec_vmrglw (vector bool int, vector bool int);
333c8841 14531
b0b343db
JJ
14532vector bool short vec_vmrglh (vector bool short, vector bool short);
14533vector signed short vec_vmrglh (vector signed short,
14534 vector signed short);
14535vector unsigned short vec_vmrglh (vector unsigned short,
14536 vector unsigned short);
14537vector pixel vec_vmrglh (vector pixel, vector pixel);
14538
14539vector bool char vec_vmrglb (vector bool char, vector bool char);
14540vector signed char vec_vmrglb (vector signed char, vector signed char);
14541vector unsigned char vec_vmrglb (vector unsigned char,
14542 vector unsigned char);
333c8841 14543
b0b343db 14544vector unsigned short vec_mfvscr (void);
333c8841 14545
b0b343db
JJ
14546vector unsigned char vec_min (vector bool char, vector unsigned char);
14547vector unsigned char vec_min (vector unsigned char, vector bool char);
924fcc4e
JM
14548vector unsigned char vec_min (vector unsigned char,
14549 vector unsigned char);
b0b343db
JJ
14550vector signed char vec_min (vector bool char, vector signed char);
14551vector signed char vec_min (vector signed char, vector bool char);
333c8841 14552vector signed char vec_min (vector signed char, vector signed char);
b0b343db 14553vector unsigned short vec_min (vector bool short,
924fcc4e
JM
14554 vector unsigned short);
14555vector unsigned short vec_min (vector unsigned short,
b0b343db 14556 vector bool short);
6e5bb5ad
JM
14557vector unsigned short vec_min (vector unsigned short,
14558 vector unsigned short);
b0b343db
JJ
14559vector signed short vec_min (vector bool short, vector signed short);
14560vector signed short vec_min (vector signed short, vector bool short);
333c8841 14561vector signed short vec_min (vector signed short, vector signed short);
b0b343db
JJ
14562vector unsigned int vec_min (vector bool int, vector unsigned int);
14563vector unsigned int vec_min (vector unsigned int, vector bool int);
333c8841 14564vector unsigned int vec_min (vector unsigned int, vector unsigned int);
b0b343db
JJ
14565vector signed int vec_min (vector bool int, vector signed int);
14566vector signed int vec_min (vector signed int, vector bool int);
333c8841
AH
14567vector signed int vec_min (vector signed int, vector signed int);
14568vector float vec_min (vector float, vector float);
14569
b0b343db
JJ
14570vector float vec_vminfp (vector float, vector float);
14571
14572vector signed int vec_vminsw (vector bool int, vector signed int);
14573vector signed int vec_vminsw (vector signed int, vector bool int);
14574vector signed int vec_vminsw (vector signed int, vector signed int);
14575
14576vector unsigned int vec_vminuw (vector bool int, vector unsigned int);
14577vector unsigned int vec_vminuw (vector unsigned int, vector bool int);
14578vector unsigned int vec_vminuw (vector unsigned int,
14579 vector unsigned int);
14580
14581vector signed short vec_vminsh (vector bool short, vector signed short);
14582vector signed short vec_vminsh (vector signed short, vector bool short);
14583vector signed short vec_vminsh (vector signed short,
14584 vector signed short);
14585
14586vector unsigned short vec_vminuh (vector bool short,
14587 vector unsigned short);
14588vector unsigned short vec_vminuh (vector unsigned short,
14589 vector bool short);
14590vector unsigned short vec_vminuh (vector unsigned short,
14591 vector unsigned short);
14592
14593vector signed char vec_vminsb (vector bool char, vector signed char);
14594vector signed char vec_vminsb (vector signed char, vector bool char);
14595vector signed char vec_vminsb (vector signed char, vector signed char);
14596
14597vector unsigned char vec_vminub (vector bool char,
14598 vector unsigned char);
14599vector unsigned char vec_vminub (vector unsigned char,
14600 vector bool char);
14601vector unsigned char vec_vminub (vector unsigned char,
14602 vector unsigned char);
14603
14604vector signed short vec_mladd (vector signed short,
14605 vector signed short,
6e5bb5ad 14606 vector signed short);
924fcc4e
JM
14607vector signed short vec_mladd (vector signed short,
14608 vector unsigned short,
6e5bb5ad 14609 vector unsigned short);
924fcc4e
JM
14610vector signed short vec_mladd (vector unsigned short,
14611 vector signed short,
6e5bb5ad
JM
14612 vector signed short);
14613vector unsigned short vec_mladd (vector unsigned short,
14614 vector unsigned short,
14615 vector unsigned short);
14616
924fcc4e
JM
14617vector signed short vec_mradds (vector signed short,
14618 vector signed short,
6e5bb5ad
JM
14619 vector signed short);
14620
924fcc4e
JM
14621vector unsigned int vec_msum (vector unsigned char,
14622 vector unsigned char,
6e5bb5ad 14623 vector unsigned int);
b0b343db
JJ
14624vector signed int vec_msum (vector signed char,
14625 vector unsigned char,
6e5bb5ad 14626 vector signed int);
924fcc4e
JM
14627vector unsigned int vec_msum (vector unsigned short,
14628 vector unsigned short,
6e5bb5ad 14629 vector unsigned int);
b0b343db
JJ
14630vector signed int vec_msum (vector signed short,
14631 vector signed short,
6e5bb5ad
JM
14632 vector signed int);
14633
b0b343db
JJ
14634vector signed int vec_vmsumshm (vector signed short,
14635 vector signed short,
14636 vector signed int);
14637
14638vector unsigned int vec_vmsumuhm (vector unsigned short,
14639 vector unsigned short,
14640 vector unsigned int);
14641
14642vector signed int vec_vmsummbm (vector signed char,
14643 vector unsigned char,
14644 vector signed int);
14645
14646vector unsigned int vec_vmsumubm (vector unsigned char,
14647 vector unsigned char,
14648 vector unsigned int);
14649
6e5bb5ad 14650vector unsigned int vec_msums (vector unsigned short,
924fcc4e
JM
14651 vector unsigned short,
14652 vector unsigned int);
b0b343db
JJ
14653vector signed int vec_msums (vector signed short,
14654 vector signed short,
6e5bb5ad 14655 vector signed int);
333c8841 14656
b0b343db
JJ
14657vector signed int vec_vmsumshs (vector signed short,
14658 vector signed short,
14659 vector signed int);
14660
14661vector unsigned int vec_vmsumuhs (vector unsigned short,
14662 vector unsigned short,
14663 vector unsigned int);
14664
333c8841
AH
14665void vec_mtvscr (vector signed int);
14666void vec_mtvscr (vector unsigned int);
b0b343db 14667void vec_mtvscr (vector bool int);
333c8841
AH
14668void vec_mtvscr (vector signed short);
14669void vec_mtvscr (vector unsigned short);
b0b343db
JJ
14670void vec_mtvscr (vector bool short);
14671void vec_mtvscr (vector pixel);
333c8841
AH
14672void vec_mtvscr (vector signed char);
14673void vec_mtvscr (vector unsigned char);
b0b343db 14674void vec_mtvscr (vector bool char);
333c8841 14675
924fcc4e
JM
14676vector unsigned short vec_mule (vector unsigned char,
14677 vector unsigned char);
b0b343db
JJ
14678vector signed short vec_mule (vector signed char,
14679 vector signed char);
924fcc4e
JM
14680vector unsigned int vec_mule (vector unsigned short,
14681 vector unsigned short);
333c8841
AH
14682vector signed int vec_mule (vector signed short, vector signed short);
14683
b0b343db
JJ
14684vector signed int vec_vmulesh (vector signed short,
14685 vector signed short);
14686
14687vector unsigned int vec_vmuleuh (vector unsigned short,
14688 vector unsigned short);
14689
14690vector signed short vec_vmulesb (vector signed char,
14691 vector signed char);
14692
14693vector unsigned short vec_vmuleub (vector unsigned char,
14694 vector unsigned char);
14695
924fcc4e
JM
14696vector unsigned short vec_mulo (vector unsigned char,
14697 vector unsigned char);
333c8841 14698vector signed short vec_mulo (vector signed char, vector signed char);
924fcc4e
JM
14699vector unsigned int vec_mulo (vector unsigned short,
14700 vector unsigned short);
333c8841
AH
14701vector signed int vec_mulo (vector signed short, vector signed short);
14702
b0b343db
JJ
14703vector signed int vec_vmulosh (vector signed short,
14704 vector signed short);
14705
14706vector unsigned int vec_vmulouh (vector unsigned short,
14707 vector unsigned short);
14708
14709vector signed short vec_vmulosb (vector signed char,
14710 vector signed char);
14711
14712vector unsigned short vec_vmuloub (vector unsigned char,
14713 vector unsigned char);
14714
333c8841
AH
14715vector float vec_nmsub (vector float, vector float, vector float);
14716
14717vector float vec_nor (vector float, vector float);
14718vector signed int vec_nor (vector signed int, vector signed int);
14719vector unsigned int vec_nor (vector unsigned int, vector unsigned int);
b0b343db 14720vector bool int vec_nor (vector bool int, vector bool int);
333c8841 14721vector signed short vec_nor (vector signed short, vector signed short);
6e5bb5ad
JM
14722vector unsigned short vec_nor (vector unsigned short,
14723 vector unsigned short);
b0b343db 14724vector bool short vec_nor (vector bool short, vector bool short);
333c8841 14725vector signed char vec_nor (vector signed char, vector signed char);
924fcc4e
JM
14726vector unsigned char vec_nor (vector unsigned char,
14727 vector unsigned char);
b0b343db 14728vector bool char vec_nor (vector bool char, vector bool char);
333c8841
AH
14729
14730vector float vec_or (vector float, vector float);
b0b343db
JJ
14731vector float vec_or (vector float, vector bool int);
14732vector float vec_or (vector bool int, vector float);
14733vector bool int vec_or (vector bool int, vector bool int);
14734vector signed int vec_or (vector bool int, vector signed int);
14735vector signed int vec_or (vector signed int, vector bool int);
333c8841 14736vector signed int vec_or (vector signed int, vector signed int);
b0b343db
JJ
14737vector unsigned int vec_or (vector bool int, vector unsigned int);
14738vector unsigned int vec_or (vector unsigned int, vector bool int);
333c8841 14739vector unsigned int vec_or (vector unsigned int, vector unsigned int);
b0b343db
JJ
14740vector bool short vec_or (vector bool short, vector bool short);
14741vector signed short vec_or (vector bool short, vector signed short);
14742vector signed short vec_or (vector signed short, vector bool short);
333c8841 14743vector signed short vec_or (vector signed short, vector signed short);
b0b343db
JJ
14744vector unsigned short vec_or (vector bool short, vector unsigned short);
14745vector unsigned short vec_or (vector unsigned short, vector bool short);
924fcc4e
JM
14746vector unsigned short vec_or (vector unsigned short,
14747 vector unsigned short);
b0b343db
JJ
14748vector signed char vec_or (vector bool char, vector signed char);
14749vector bool char vec_or (vector bool char, vector bool char);
14750vector signed char vec_or (vector signed char, vector bool char);
333c8841 14751vector signed char vec_or (vector signed char, vector signed char);
b0b343db
JJ
14752vector unsigned char vec_or (vector bool char, vector unsigned char);
14753vector unsigned char vec_or (vector unsigned char, vector bool char);
924fcc4e
JM
14754vector unsigned char vec_or (vector unsigned char,
14755 vector unsigned char);
333c8841
AH
14756
14757vector signed char vec_pack (vector signed short, vector signed short);
6e5bb5ad
JM
14758vector unsigned char vec_pack (vector unsigned short,
14759 vector unsigned short);
b0b343db 14760vector bool char vec_pack (vector bool short, vector bool short);
333c8841 14761vector signed short vec_pack (vector signed int, vector signed int);
924fcc4e
JM
14762vector unsigned short vec_pack (vector unsigned int,
14763 vector unsigned int);
b0b343db 14764vector bool short vec_pack (vector bool int, vector bool int);
333c8841 14765
b0b343db
JJ
14766vector bool short vec_vpkuwum (vector bool int, vector bool int);
14767vector signed short vec_vpkuwum (vector signed int, vector signed int);
14768vector unsigned short vec_vpkuwum (vector unsigned int,
14769 vector unsigned int);
14770
14771vector bool char vec_vpkuhum (vector bool short, vector bool short);
14772vector signed char vec_vpkuhum (vector signed short,
14773 vector signed short);
14774vector unsigned char vec_vpkuhum (vector unsigned short,
14775 vector unsigned short);
14776
14777vector pixel vec_packpx (vector unsigned int, vector unsigned int);
333c8841 14778
6e5bb5ad
JM
14779vector unsigned char vec_packs (vector unsigned short,
14780 vector unsigned short);
333c8841 14781vector signed char vec_packs (vector signed short, vector signed short);
924fcc4e
JM
14782vector unsigned short vec_packs (vector unsigned int,
14783 vector unsigned int);
333c8841
AH
14784vector signed short vec_packs (vector signed int, vector signed int);
14785
b0b343db
JJ
14786vector signed short vec_vpkswss (vector signed int, vector signed int);
14787
14788vector unsigned short vec_vpkuwus (vector unsigned int,
14789 vector unsigned int);
14790
14791vector signed char vec_vpkshss (vector signed short,
14792 vector signed short);
14793
14794vector unsigned char vec_vpkuhus (vector unsigned short,
14795 vector unsigned short);
14796
6e5bb5ad
JM
14797vector unsigned char vec_packsu (vector unsigned short,
14798 vector unsigned short);
924fcc4e
JM
14799vector unsigned char vec_packsu (vector signed short,
14800 vector signed short);
14801vector unsigned short vec_packsu (vector unsigned int,
14802 vector unsigned int);
333c8841
AH
14803vector unsigned short vec_packsu (vector signed int, vector signed int);
14804
b0b343db
JJ
14805vector unsigned short vec_vpkswus (vector signed int,
14806 vector signed int);
14807
14808vector unsigned char vec_vpkshus (vector signed short,
14809 vector signed short);
14810
14811vector float vec_perm (vector float,
14812 vector float,
924fcc4e 14813 vector unsigned char);
b0b343db
JJ
14814vector signed int vec_perm (vector signed int,
14815 vector signed int,
6e5bb5ad 14816 vector unsigned char);
b0b343db
JJ
14817vector unsigned int vec_perm (vector unsigned int,
14818 vector unsigned int,
6e5bb5ad 14819 vector unsigned char);
b0b343db
JJ
14820vector bool int vec_perm (vector bool int,
14821 vector bool int,
14822 vector unsigned char);
14823vector signed short vec_perm (vector signed short,
14824 vector signed short,
6e5bb5ad
JM
14825 vector unsigned char);
14826vector unsigned short vec_perm (vector unsigned short,
14827 vector unsigned short,
14828 vector unsigned char);
b0b343db
JJ
14829vector bool short vec_perm (vector bool short,
14830 vector bool short,
14831 vector unsigned char);
14832vector pixel vec_perm (vector pixel,
14833 vector pixel,
14834 vector unsigned char);
14835vector signed char vec_perm (vector signed char,
14836 vector signed char,
6e5bb5ad 14837 vector unsigned char);
924fcc4e
JM
14838vector unsigned char vec_perm (vector unsigned char,
14839 vector unsigned char,
6e5bb5ad 14840 vector unsigned char);
b0b343db
JJ
14841vector bool char vec_perm (vector bool char,
14842 vector bool char,
14843 vector unsigned char);
333c8841
AH
14844
14845vector float vec_re (vector float);
14846
b0b343db
JJ
14847vector signed char vec_rl (vector signed char,
14848 vector unsigned char);
924fcc4e
JM
14849vector unsigned char vec_rl (vector unsigned char,
14850 vector unsigned char);
333c8841 14851vector signed short vec_rl (vector signed short, vector unsigned short);
924fcc4e
JM
14852vector unsigned short vec_rl (vector unsigned short,
14853 vector unsigned short);
333c8841
AH
14854vector signed int vec_rl (vector signed int, vector unsigned int);
14855vector unsigned int vec_rl (vector unsigned int, vector unsigned int);
14856
b0b343db
JJ
14857vector signed int vec_vrlw (vector signed int, vector unsigned int);
14858vector unsigned int vec_vrlw (vector unsigned int, vector unsigned int);
14859
14860vector signed short vec_vrlh (vector signed short,
14861 vector unsigned short);
14862vector unsigned short vec_vrlh (vector unsigned short,
14863 vector unsigned short);
14864
14865vector signed char vec_vrlb (vector signed char, vector unsigned char);
14866vector unsigned char vec_vrlb (vector unsigned char,
14867 vector unsigned char);
14868
333c8841
AH
14869vector float vec_round (vector float);
14870
92902797
MM
14871vector float vec_recip (vector float, vector float);
14872
14873vector float vec_rsqrt (vector float);
14874
333c8841
AH
14875vector float vec_rsqrte (vector float);
14876
b0b343db 14877vector float vec_sel (vector float, vector float, vector bool int);
333c8841 14878vector float vec_sel (vector float, vector float, vector unsigned int);
b0b343db
JJ
14879vector signed int vec_sel (vector signed int,
14880 vector signed int,
14881 vector bool int);
14882vector signed int vec_sel (vector signed int,
14883 vector signed int,
6e5bb5ad 14884 vector unsigned int);
b0b343db
JJ
14885vector unsigned int vec_sel (vector unsigned int,
14886 vector unsigned int,
14887 vector bool int);
14888vector unsigned int vec_sel (vector unsigned int,
14889 vector unsigned int,
6e5bb5ad 14890 vector unsigned int);
b0b343db
JJ
14891vector bool int vec_sel (vector bool int,
14892 vector bool int,
14893 vector bool int);
14894vector bool int vec_sel (vector bool int,
14895 vector bool int,
14896 vector unsigned int);
14897vector signed short vec_sel (vector signed short,
14898 vector signed short,
14899 vector bool short);
14900vector signed short vec_sel (vector signed short,
14901 vector signed short,
6e5bb5ad
JM
14902 vector unsigned short);
14903vector unsigned short vec_sel (vector unsigned short,
924fcc4e 14904 vector unsigned short,
b0b343db 14905 vector bool short);
6e5bb5ad
JM
14906vector unsigned short vec_sel (vector unsigned short,
14907 vector unsigned short,
14908 vector unsigned short);
b0b343db
JJ
14909vector bool short vec_sel (vector bool short,
14910 vector bool short,
14911 vector bool short);
14912vector bool short vec_sel (vector bool short,
14913 vector bool short,
14914 vector unsigned short);
14915vector signed char vec_sel (vector signed char,
14916 vector signed char,
14917 vector bool char);
14918vector signed char vec_sel (vector signed char,
14919 vector signed char,
6e5bb5ad 14920 vector unsigned char);
924fcc4e
JM
14921vector unsigned char vec_sel (vector unsigned char,
14922 vector unsigned char,
b0b343db 14923 vector bool char);
924fcc4e
JM
14924vector unsigned char vec_sel (vector unsigned char,
14925 vector unsigned char,
6e5bb5ad 14926 vector unsigned char);
b0b343db
JJ
14927vector bool char vec_sel (vector bool char,
14928 vector bool char,
14929 vector bool char);
14930vector bool char vec_sel (vector bool char,
14931 vector bool char,
14932 vector unsigned char);
14933
14934vector signed char vec_sl (vector signed char,
14935 vector unsigned char);
924fcc4e
JM
14936vector unsigned char vec_sl (vector unsigned char,
14937 vector unsigned char);
333c8841 14938vector signed short vec_sl (vector signed short, vector unsigned short);
924fcc4e
JM
14939vector unsigned short vec_sl (vector unsigned short,
14940 vector unsigned short);
333c8841
AH
14941vector signed int vec_sl (vector signed int, vector unsigned int);
14942vector unsigned int vec_sl (vector unsigned int, vector unsigned int);
14943
b0b343db
JJ
14944vector signed int vec_vslw (vector signed int, vector unsigned int);
14945vector unsigned int vec_vslw (vector unsigned int, vector unsigned int);
14946
14947vector signed short vec_vslh (vector signed short,
14948 vector unsigned short);
14949vector unsigned short vec_vslh (vector unsigned short,
14950 vector unsigned short);
14951
14952vector signed char vec_vslb (vector signed char, vector unsigned char);
14953vector unsigned char vec_vslb (vector unsigned char,
14954 vector unsigned char);
14955
14956vector float vec_sld (vector float, vector float, const int);
14957vector signed int vec_sld (vector signed int,
14958 vector signed int,
14959 const int);
14960vector unsigned int vec_sld (vector unsigned int,
14961 vector unsigned int,
14962 const int);
14963vector bool int vec_sld (vector bool int,
14964 vector bool int,
14965 const int);
14966vector signed short vec_sld (vector signed short,
14967 vector signed short,
14968 const int);
6e5bb5ad 14969vector unsigned short vec_sld (vector unsigned short,
b0b343db
JJ
14970 vector unsigned short,
14971 const int);
14972vector bool short vec_sld (vector bool short,
14973 vector bool short,
14974 const int);
14975vector pixel vec_sld (vector pixel,
14976 vector pixel,
14977 const int);
14978vector signed char vec_sld (vector signed char,
14979 vector signed char,
14980 const int);
924fcc4e
JM
14981vector unsigned char vec_sld (vector unsigned char,
14982 vector unsigned char,
b0b343db
JJ
14983 const int);
14984vector bool char vec_sld (vector bool char,
14985 vector bool char,
14986 const int);
333c8841 14987
b0b343db
JJ
14988vector signed int vec_sll (vector signed int,
14989 vector unsigned int);
14990vector signed int vec_sll (vector signed int,
14991 vector unsigned short);
14992vector signed int vec_sll (vector signed int,
14993 vector unsigned char);
14994vector unsigned int vec_sll (vector unsigned int,
14995 vector unsigned int);
924fcc4e
JM
14996vector unsigned int vec_sll (vector unsigned int,
14997 vector unsigned short);
b0b343db
JJ
14998vector unsigned int vec_sll (vector unsigned int,
14999 vector unsigned char);
15000vector bool int vec_sll (vector bool int,
15001 vector unsigned int);
15002vector bool int vec_sll (vector bool int,
15003 vector unsigned short);
15004vector bool int vec_sll (vector bool int,
15005 vector unsigned char);
15006vector signed short vec_sll (vector signed short,
15007 vector unsigned int);
924fcc4e
JM
15008vector signed short vec_sll (vector signed short,
15009 vector unsigned short);
b0b343db
JJ
15010vector signed short vec_sll (vector signed short,
15011 vector unsigned char);
924fcc4e
JM
15012vector unsigned short vec_sll (vector unsigned short,
15013 vector unsigned int);
6e5bb5ad
JM
15014vector unsigned short vec_sll (vector unsigned short,
15015 vector unsigned short);
924fcc4e
JM
15016vector unsigned short vec_sll (vector unsigned short,
15017 vector unsigned char);
b0b343db
JJ
15018vector bool short vec_sll (vector bool short, vector unsigned int);
15019vector bool short vec_sll (vector bool short, vector unsigned short);
15020vector bool short vec_sll (vector bool short, vector unsigned char);
15021vector pixel vec_sll (vector pixel, vector unsigned int);
15022vector pixel vec_sll (vector pixel, vector unsigned short);
15023vector pixel vec_sll (vector pixel, vector unsigned char);
333c8841
AH
15024vector signed char vec_sll (vector signed char, vector unsigned int);
15025vector signed char vec_sll (vector signed char, vector unsigned short);
15026vector signed char vec_sll (vector signed char, vector unsigned char);
924fcc4e
JM
15027vector unsigned char vec_sll (vector unsigned char,
15028 vector unsigned int);
15029vector unsigned char vec_sll (vector unsigned char,
15030 vector unsigned short);
15031vector unsigned char vec_sll (vector unsigned char,
15032 vector unsigned char);
b0b343db
JJ
15033vector bool char vec_sll (vector bool char, vector unsigned int);
15034vector bool char vec_sll (vector bool char, vector unsigned short);
15035vector bool char vec_sll (vector bool char, vector unsigned char);
333c8841
AH
15036
15037vector float vec_slo (vector float, vector signed char);
15038vector float vec_slo (vector float, vector unsigned char);
15039vector signed int vec_slo (vector signed int, vector signed char);
15040vector signed int vec_slo (vector signed int, vector unsigned char);
15041vector unsigned int vec_slo (vector unsigned int, vector signed char);
15042vector unsigned int vec_slo (vector unsigned int, vector unsigned char);
333c8841
AH
15043vector signed short vec_slo (vector signed short, vector signed char);
15044vector signed short vec_slo (vector signed short, vector unsigned char);
924fcc4e
JM
15045vector unsigned short vec_slo (vector unsigned short,
15046 vector signed char);
15047vector unsigned short vec_slo (vector unsigned short,
15048 vector unsigned char);
b0b343db
JJ
15049vector pixel vec_slo (vector pixel, vector signed char);
15050vector pixel vec_slo (vector pixel, vector unsigned char);
333c8841
AH
15051vector signed char vec_slo (vector signed char, vector signed char);
15052vector signed char vec_slo (vector signed char, vector unsigned char);
15053vector unsigned char vec_slo (vector unsigned char, vector signed char);
924fcc4e
JM
15054vector unsigned char vec_slo (vector unsigned char,
15055 vector unsigned char);
333c8841 15056
b0b343db
JJ
15057vector signed char vec_splat (vector signed char, const int);
15058vector unsigned char vec_splat (vector unsigned char, const int);
15059vector bool char vec_splat (vector bool char, const int);
15060vector signed short vec_splat (vector signed short, const int);
15061vector unsigned short vec_splat (vector unsigned short, const int);
15062vector bool short vec_splat (vector bool short, const int);
15063vector pixel vec_splat (vector pixel, const int);
15064vector float vec_splat (vector float, const int);
15065vector signed int vec_splat (vector signed int, const int);
15066vector unsigned int vec_splat (vector unsigned int, const int);
15067vector bool int vec_splat (vector bool int, const int);
70f0f8b2
BS
15068vector signed long vec_splat (vector signed long, const int);
15069vector unsigned long vec_splat (vector unsigned long, const int);
b0b343db 15070
65fa79c3
BS
15071vector signed char vec_splats (signed char);
15072vector unsigned char vec_splats (unsigned char);
15073vector signed short vec_splats (signed short);
15074vector unsigned short vec_splats (unsigned short);
15075vector signed int vec_splats (signed int);
15076vector unsigned int vec_splats (unsigned int);
15077vector float vec_splats (float);
15078
b0b343db
JJ
15079vector float vec_vspltw (vector float, const int);
15080vector signed int vec_vspltw (vector signed int, const int);
15081vector unsigned int vec_vspltw (vector unsigned int, const int);
15082vector bool int vec_vspltw (vector bool int, const int);
15083
15084vector bool short vec_vsplth (vector bool short, const int);
15085vector signed short vec_vsplth (vector signed short, const int);
15086vector unsigned short vec_vsplth (vector unsigned short, const int);
15087vector pixel vec_vsplth (vector pixel, const int);
15088
15089vector signed char vec_vspltb (vector signed char, const int);
15090vector unsigned char vec_vspltb (vector unsigned char, const int);
15091vector bool char vec_vspltb (vector bool char, const int);
333c8841 15092
b0b343db 15093vector signed char vec_splat_s8 (const int);
333c8841 15094
b0b343db 15095vector signed short vec_splat_s16 (const int);
333c8841 15096
b0b343db 15097vector signed int vec_splat_s32 (const int);
333c8841 15098
b0b343db 15099vector unsigned char vec_splat_u8 (const int);
333c8841 15100
b0b343db 15101vector unsigned short vec_splat_u16 (const int);
333c8841 15102
b0b343db 15103vector unsigned int vec_splat_u32 (const int);
333c8841
AH
15104
15105vector signed char vec_sr (vector signed char, vector unsigned char);
924fcc4e
JM
15106vector unsigned char vec_sr (vector unsigned char,
15107 vector unsigned char);
b0b343db
JJ
15108vector signed short vec_sr (vector signed short,
15109 vector unsigned short);
924fcc4e
JM
15110vector unsigned short vec_sr (vector unsigned short,
15111 vector unsigned short);
333c8841
AH
15112vector signed int vec_sr (vector signed int, vector unsigned int);
15113vector unsigned int vec_sr (vector unsigned int, vector unsigned int);
15114
b0b343db
JJ
15115vector signed int vec_vsrw (vector signed int, vector unsigned int);
15116vector unsigned int vec_vsrw (vector unsigned int, vector unsigned int);
15117
15118vector signed short vec_vsrh (vector signed short,
15119 vector unsigned short);
15120vector unsigned short vec_vsrh (vector unsigned short,
15121 vector unsigned short);
15122
15123vector signed char vec_vsrb (vector signed char, vector unsigned char);
15124vector unsigned char vec_vsrb (vector unsigned char,
15125 vector unsigned char);
15126
333c8841 15127vector signed char vec_sra (vector signed char, vector unsigned char);
924fcc4e
JM
15128vector unsigned char vec_sra (vector unsigned char,
15129 vector unsigned char);
15130vector signed short vec_sra (vector signed short,
15131 vector unsigned short);
6e5bb5ad
JM
15132vector unsigned short vec_sra (vector unsigned short,
15133 vector unsigned short);
333c8841
AH
15134vector signed int vec_sra (vector signed int, vector unsigned int);
15135vector unsigned int vec_sra (vector unsigned int, vector unsigned int);
15136
b0b343db
JJ
15137vector signed int vec_vsraw (vector signed int, vector unsigned int);
15138vector unsigned int vec_vsraw (vector unsigned int,
15139 vector unsigned int);
15140
15141vector signed short vec_vsrah (vector signed short,
15142 vector unsigned short);
15143vector unsigned short vec_vsrah (vector unsigned short,
15144 vector unsigned short);
15145
15146vector signed char vec_vsrab (vector signed char, vector unsigned char);
15147vector unsigned char vec_vsrab (vector unsigned char,
15148 vector unsigned char);
15149
333c8841
AH
15150vector signed int vec_srl (vector signed int, vector unsigned int);
15151vector signed int vec_srl (vector signed int, vector unsigned short);
15152vector signed int vec_srl (vector signed int, vector unsigned char);
15153vector unsigned int vec_srl (vector unsigned int, vector unsigned int);
924fcc4e
JM
15154vector unsigned int vec_srl (vector unsigned int,
15155 vector unsigned short);
333c8841 15156vector unsigned int vec_srl (vector unsigned int, vector unsigned char);
b0b343db
JJ
15157vector bool int vec_srl (vector bool int, vector unsigned int);
15158vector bool int vec_srl (vector bool int, vector unsigned short);
15159vector bool int vec_srl (vector bool int, vector unsigned char);
333c8841 15160vector signed short vec_srl (vector signed short, vector unsigned int);
924fcc4e
JM
15161vector signed short vec_srl (vector signed short,
15162 vector unsigned short);
333c8841 15163vector signed short vec_srl (vector signed short, vector unsigned char);
924fcc4e
JM
15164vector unsigned short vec_srl (vector unsigned short,
15165 vector unsigned int);
6e5bb5ad
JM
15166vector unsigned short vec_srl (vector unsigned short,
15167 vector unsigned short);
924fcc4e
JM
15168vector unsigned short vec_srl (vector unsigned short,
15169 vector unsigned char);
b0b343db
JJ
15170vector bool short vec_srl (vector bool short, vector unsigned int);
15171vector bool short vec_srl (vector bool short, vector unsigned short);
15172vector bool short vec_srl (vector bool short, vector unsigned char);
15173vector pixel vec_srl (vector pixel, vector unsigned int);
15174vector pixel vec_srl (vector pixel, vector unsigned short);
15175vector pixel vec_srl (vector pixel, vector unsigned char);
333c8841
AH
15176vector signed char vec_srl (vector signed char, vector unsigned int);
15177vector signed char vec_srl (vector signed char, vector unsigned short);
15178vector signed char vec_srl (vector signed char, vector unsigned char);
924fcc4e
JM
15179vector unsigned char vec_srl (vector unsigned char,
15180 vector unsigned int);
15181vector unsigned char vec_srl (vector unsigned char,
15182 vector unsigned short);
15183vector unsigned char vec_srl (vector unsigned char,
15184 vector unsigned char);
b0b343db
JJ
15185vector bool char vec_srl (vector bool char, vector unsigned int);
15186vector bool char vec_srl (vector bool char, vector unsigned short);
15187vector bool char vec_srl (vector bool char, vector unsigned char);
333c8841
AH
15188
15189vector float vec_sro (vector float, vector signed char);
15190vector float vec_sro (vector float, vector unsigned char);
15191vector signed int vec_sro (vector signed int, vector signed char);
15192vector signed int vec_sro (vector signed int, vector unsigned char);
15193vector unsigned int vec_sro (vector unsigned int, vector signed char);
15194vector unsigned int vec_sro (vector unsigned int, vector unsigned char);
333c8841
AH
15195vector signed short vec_sro (vector signed short, vector signed char);
15196vector signed short vec_sro (vector signed short, vector unsigned char);
924fcc4e
JM
15197vector unsigned short vec_sro (vector unsigned short,
15198 vector signed char);
15199vector unsigned short vec_sro (vector unsigned short,
15200 vector unsigned char);
b0b343db
JJ
15201vector pixel vec_sro (vector pixel, vector signed char);
15202vector pixel vec_sro (vector pixel, vector unsigned char);
333c8841
AH
15203vector signed char vec_sro (vector signed char, vector signed char);
15204vector signed char vec_sro (vector signed char, vector unsigned char);
15205vector unsigned char vec_sro (vector unsigned char, vector signed char);
924fcc4e
JM
15206vector unsigned char vec_sro (vector unsigned char,
15207 vector unsigned char);
333c8841 15208
333c8841 15209void vec_st (vector float, int, vector float *);
b0b343db
JJ
15210void vec_st (vector float, int, float *);
15211void vec_st (vector signed int, int, vector signed int *);
333c8841 15212void vec_st (vector signed int, int, int *);
333c8841 15213void vec_st (vector unsigned int, int, vector unsigned int *);
b0b343db
JJ
15214void vec_st (vector unsigned int, int, unsigned int *);
15215void vec_st (vector bool int, int, vector bool int *);
15216void vec_st (vector bool int, int, unsigned int *);
15217void vec_st (vector bool int, int, int *);
333c8841 15218void vec_st (vector signed short, int, vector signed short *);
b0b343db 15219void vec_st (vector signed short, int, short *);
333c8841 15220void vec_st (vector unsigned short, int, vector unsigned short *);
b0b343db
JJ
15221void vec_st (vector unsigned short, int, unsigned short *);
15222void vec_st (vector bool short, int, vector bool short *);
15223void vec_st (vector bool short, int, unsigned short *);
15224void vec_st (vector pixel, int, vector pixel *);
15225void vec_st (vector pixel, int, unsigned short *);
15226void vec_st (vector pixel, int, short *);
15227void vec_st (vector bool short, int, short *);
333c8841 15228void vec_st (vector signed char, int, vector signed char *);
b0b343db 15229void vec_st (vector signed char, int, signed char *);
333c8841 15230void vec_st (vector unsigned char, int, vector unsigned char *);
b0b343db
JJ
15231void vec_st (vector unsigned char, int, unsigned char *);
15232void vec_st (vector bool char, int, vector bool char *);
15233void vec_st (vector bool char, int, unsigned char *);
15234void vec_st (vector bool char, int, signed char *);
333c8841 15235
333c8841
AH
15236void vec_ste (vector signed char, int, signed char *);
15237void vec_ste (vector unsigned char, int, unsigned char *);
b0b343db
JJ
15238void vec_ste (vector bool char, int, signed char *);
15239void vec_ste (vector bool char, int, unsigned char *);
333c8841 15240void vec_ste (vector signed short, int, short *);
b0b343db
JJ
15241void vec_ste (vector unsigned short, int, unsigned short *);
15242void vec_ste (vector bool short, int, short *);
15243void vec_ste (vector bool short, int, unsigned short *);
15244void vec_ste (vector pixel, int, short *);
15245void vec_ste (vector pixel, int, unsigned short *);
15246void vec_ste (vector float, int, float *);
333c8841
AH
15247void vec_ste (vector signed int, int, int *);
15248void vec_ste (vector unsigned int, int, unsigned int *);
b0b343db
JJ
15249void vec_ste (vector bool int, int, int *);
15250void vec_ste (vector bool int, int, unsigned int *);
15251
15252void vec_stvewx (vector float, int, float *);
15253void vec_stvewx (vector signed int, int, int *);
15254void vec_stvewx (vector unsigned int, int, unsigned int *);
15255void vec_stvewx (vector bool int, int, int *);
15256void vec_stvewx (vector bool int, int, unsigned int *);
15257
15258void vec_stvehx (vector signed short, int, short *);
15259void vec_stvehx (vector unsigned short, int, unsigned short *);
15260void vec_stvehx (vector bool short, int, short *);
15261void vec_stvehx (vector bool short, int, unsigned short *);
15262void vec_stvehx (vector pixel, int, short *);
15263void vec_stvehx (vector pixel, int, unsigned short *);
15264
15265void vec_stvebx (vector signed char, int, signed char *);
15266void vec_stvebx (vector unsigned char, int, unsigned char *);
15267void vec_stvebx (vector bool char, int, signed char *);
15268void vec_stvebx (vector bool char, int, unsigned char *);
333c8841
AH
15269
15270void vec_stl (vector float, int, vector float *);
15271void vec_stl (vector float, int, float *);
15272void vec_stl (vector signed int, int, vector signed int *);
15273void vec_stl (vector signed int, int, int *);
333c8841
AH
15274void vec_stl (vector unsigned int, int, vector unsigned int *);
15275void vec_stl (vector unsigned int, int, unsigned int *);
b0b343db
JJ
15276void vec_stl (vector bool int, int, vector bool int *);
15277void vec_stl (vector bool int, int, unsigned int *);
15278void vec_stl (vector bool int, int, int *);
333c8841 15279void vec_stl (vector signed short, int, vector signed short *);
b0b343db
JJ
15280void vec_stl (vector signed short, int, short *);
15281void vec_stl (vector unsigned short, int, vector unsigned short *);
333c8841 15282void vec_stl (vector unsigned short, int, unsigned short *);
b0b343db
JJ
15283void vec_stl (vector bool short, int, vector bool short *);
15284void vec_stl (vector bool short, int, unsigned short *);
15285void vec_stl (vector bool short, int, short *);
15286void vec_stl (vector pixel, int, vector pixel *);
15287void vec_stl (vector pixel, int, unsigned short *);
15288void vec_stl (vector pixel, int, short *);
333c8841 15289void vec_stl (vector signed char, int, vector signed char *);
b0b343db 15290void vec_stl (vector signed char, int, signed char *);
333c8841 15291void vec_stl (vector unsigned char, int, vector unsigned char *);
b0b343db
JJ
15292void vec_stl (vector unsigned char, int, unsigned char *);
15293void vec_stl (vector bool char, int, vector bool char *);
15294void vec_stl (vector bool char, int, unsigned char *);
15295void vec_stl (vector bool char, int, signed char *);
333c8841 15296
b0b343db
JJ
15297vector signed char vec_sub (vector bool char, vector signed char);
15298vector signed char vec_sub (vector signed char, vector bool char);
333c8841 15299vector signed char vec_sub (vector signed char, vector signed char);
b0b343db
JJ
15300vector unsigned char vec_sub (vector bool char, vector unsigned char);
15301vector unsigned char vec_sub (vector unsigned char, vector bool char);
924fcc4e
JM
15302vector unsigned char vec_sub (vector unsigned char,
15303 vector unsigned char);
b0b343db
JJ
15304vector signed short vec_sub (vector bool short, vector signed short);
15305vector signed short vec_sub (vector signed short, vector bool short);
333c8841 15306vector signed short vec_sub (vector signed short, vector signed short);
b0b343db 15307vector unsigned short vec_sub (vector bool short,
924fcc4e
JM
15308 vector unsigned short);
15309vector unsigned short vec_sub (vector unsigned short,
b0b343db 15310 vector bool short);
6e5bb5ad
JM
15311vector unsigned short vec_sub (vector unsigned short,
15312 vector unsigned short);
b0b343db
JJ
15313vector signed int vec_sub (vector bool int, vector signed int);
15314vector signed int vec_sub (vector signed int, vector bool int);
333c8841 15315vector signed int vec_sub (vector signed int, vector signed int);
b0b343db
JJ
15316vector unsigned int vec_sub (vector bool int, vector unsigned int);
15317vector unsigned int vec_sub (vector unsigned int, vector bool int);
333c8841
AH
15318vector unsigned int vec_sub (vector unsigned int, vector unsigned int);
15319vector float vec_sub (vector float, vector float);
15320
b0b343db
JJ
15321vector float vec_vsubfp (vector float, vector float);
15322
15323vector signed int vec_vsubuwm (vector bool int, vector signed int);
15324vector signed int vec_vsubuwm (vector signed int, vector bool int);
15325vector signed int vec_vsubuwm (vector signed int, vector signed int);
15326vector unsigned int vec_vsubuwm (vector bool int, vector unsigned int);
15327vector unsigned int vec_vsubuwm (vector unsigned int, vector bool int);
15328vector unsigned int vec_vsubuwm (vector unsigned int,
15329 vector unsigned int);
15330
15331vector signed short vec_vsubuhm (vector bool short,
15332 vector signed short);
15333vector signed short vec_vsubuhm (vector signed short,
15334 vector bool short);
15335vector signed short vec_vsubuhm (vector signed short,
15336 vector signed short);
15337vector unsigned short vec_vsubuhm (vector bool short,
15338 vector unsigned short);
15339vector unsigned short vec_vsubuhm (vector unsigned short,
15340 vector bool short);
15341vector unsigned short vec_vsubuhm (vector unsigned short,
15342 vector unsigned short);
15343
15344vector signed char vec_vsububm (vector bool char, vector signed char);
15345vector signed char vec_vsububm (vector signed char, vector bool char);
15346vector signed char vec_vsububm (vector signed char, vector signed char);
15347vector unsigned char vec_vsububm (vector bool char,
15348 vector unsigned char);
15349vector unsigned char vec_vsububm (vector unsigned char,
15350 vector bool char);
15351vector unsigned char vec_vsububm (vector unsigned char,
15352 vector unsigned char);
15353
333c8841
AH
15354vector unsigned int vec_subc (vector unsigned int, vector unsigned int);
15355
b0b343db
JJ
15356vector unsigned char vec_subs (vector bool char, vector unsigned char);
15357vector unsigned char vec_subs (vector unsigned char, vector bool char);
924fcc4e
JM
15358vector unsigned char vec_subs (vector unsigned char,
15359 vector unsigned char);
b0b343db
JJ
15360vector signed char vec_subs (vector bool char, vector signed char);
15361vector signed char vec_subs (vector signed char, vector bool char);
333c8841 15362vector signed char vec_subs (vector signed char, vector signed char);
b0b343db 15363vector unsigned short vec_subs (vector bool short,
924fcc4e
JM
15364 vector unsigned short);
15365vector unsigned short vec_subs (vector unsigned short,
b0b343db 15366 vector bool short);
6e5bb5ad
JM
15367vector unsigned short vec_subs (vector unsigned short,
15368 vector unsigned short);
b0b343db
JJ
15369vector signed short vec_subs (vector bool short, vector signed short);
15370vector signed short vec_subs (vector signed short, vector bool short);
333c8841 15371vector signed short vec_subs (vector signed short, vector signed short);
b0b343db
JJ
15372vector unsigned int vec_subs (vector bool int, vector unsigned int);
15373vector unsigned int vec_subs (vector unsigned int, vector bool int);
333c8841 15374vector unsigned int vec_subs (vector unsigned int, vector unsigned int);
b0b343db
JJ
15375vector signed int vec_subs (vector bool int, vector signed int);
15376vector signed int vec_subs (vector signed int, vector bool int);
333c8841
AH
15377vector signed int vec_subs (vector signed int, vector signed int);
15378
b0b343db
JJ
15379vector signed int vec_vsubsws (vector bool int, vector signed int);
15380vector signed int vec_vsubsws (vector signed int, vector bool int);
15381vector signed int vec_vsubsws (vector signed int, vector signed int);
15382
15383vector unsigned int vec_vsubuws (vector bool int, vector unsigned int);
15384vector unsigned int vec_vsubuws (vector unsigned int, vector bool int);
15385vector unsigned int vec_vsubuws (vector unsigned int,
15386 vector unsigned int);
15387
15388vector signed short vec_vsubshs (vector bool short,
15389 vector signed short);
15390vector signed short vec_vsubshs (vector signed short,
15391 vector bool short);
15392vector signed short vec_vsubshs (vector signed short,
15393 vector signed short);
15394
15395vector unsigned short vec_vsubuhs (vector bool short,
15396 vector unsigned short);
15397vector unsigned short vec_vsubuhs (vector unsigned short,
15398 vector bool short);
15399vector unsigned short vec_vsubuhs (vector unsigned short,
15400 vector unsigned short);
15401
15402vector signed char vec_vsubsbs (vector bool char, vector signed char);
15403vector signed char vec_vsubsbs (vector signed char, vector bool char);
15404vector signed char vec_vsubsbs (vector signed char, vector signed char);
15405
15406vector unsigned char vec_vsububs (vector bool char,
15407 vector unsigned char);
15408vector unsigned char vec_vsububs (vector unsigned char,
15409 vector bool char);
15410vector unsigned char vec_vsububs (vector unsigned char,
15411 vector unsigned char);
15412
924fcc4e
JM
15413vector unsigned int vec_sum4s (vector unsigned char,
15414 vector unsigned int);
333c8841
AH
15415vector signed int vec_sum4s (vector signed char, vector signed int);
15416vector signed int vec_sum4s (vector signed short, vector signed int);
15417
b0b343db
JJ
15418vector signed int vec_vsum4shs (vector signed short, vector signed int);
15419
15420vector signed int vec_vsum4sbs (vector signed char, vector signed int);
15421
15422vector unsigned int vec_vsum4ubs (vector unsigned char,
15423 vector unsigned int);
15424
333c8841
AH
15425vector signed int vec_sum2s (vector signed int, vector signed int);
15426
15427vector signed int vec_sums (vector signed int, vector signed int);
15428
15429vector float vec_trunc (vector float);
15430
15431vector signed short vec_unpackh (vector signed char);
b0b343db 15432vector bool short vec_unpackh (vector bool char);
333c8841 15433vector signed int vec_unpackh (vector signed short);
b0b343db
JJ
15434vector bool int vec_unpackh (vector bool short);
15435vector unsigned int vec_unpackh (vector pixel);
15436
15437vector bool int vec_vupkhsh (vector bool short);
15438vector signed int vec_vupkhsh (vector signed short);
15439
15440vector unsigned int vec_vupkhpx (vector pixel);
15441
15442vector bool short vec_vupkhsb (vector bool char);
15443vector signed short vec_vupkhsb (vector signed char);
333c8841
AH
15444
15445vector signed short vec_unpackl (vector signed char);
b0b343db
JJ
15446vector bool short vec_unpackl (vector bool char);
15447vector unsigned int vec_unpackl (vector pixel);
333c8841 15448vector signed int vec_unpackl (vector signed short);
b0b343db
JJ
15449vector bool int vec_unpackl (vector bool short);
15450
15451vector unsigned int vec_vupklpx (vector pixel);
15452
15453vector bool int vec_vupklsh (vector bool short);
15454vector signed int vec_vupklsh (vector signed short);
15455
15456vector bool short vec_vupklsb (vector bool char);
15457vector signed short vec_vupklsb (vector signed char);
333c8841
AH
15458
15459vector float vec_xor (vector float, vector float);
b0b343db
JJ
15460vector float vec_xor (vector float, vector bool int);
15461vector float vec_xor (vector bool int, vector float);
15462vector bool int vec_xor (vector bool int, vector bool int);
15463vector signed int vec_xor (vector bool int, vector signed int);
15464vector signed int vec_xor (vector signed int, vector bool int);
333c8841 15465vector signed int vec_xor (vector signed int, vector signed int);
b0b343db
JJ
15466vector unsigned int vec_xor (vector bool int, vector unsigned int);
15467vector unsigned int vec_xor (vector unsigned int, vector bool int);
333c8841 15468vector unsigned int vec_xor (vector unsigned int, vector unsigned int);
b0b343db
JJ
15469vector bool short vec_xor (vector bool short, vector bool short);
15470vector signed short vec_xor (vector bool short, vector signed short);
15471vector signed short vec_xor (vector signed short, vector bool short);
333c8841 15472vector signed short vec_xor (vector signed short, vector signed short);
b0b343db 15473vector unsigned short vec_xor (vector bool short,
924fcc4e
JM
15474 vector unsigned short);
15475vector unsigned short vec_xor (vector unsigned short,
b0b343db 15476 vector bool short);
6e5bb5ad
JM
15477vector unsigned short vec_xor (vector unsigned short,
15478 vector unsigned short);
b0b343db
JJ
15479vector signed char vec_xor (vector bool char, vector signed char);
15480vector bool char vec_xor (vector bool char, vector bool char);
15481vector signed char vec_xor (vector signed char, vector bool char);
333c8841 15482vector signed char vec_xor (vector signed char, vector signed char);
b0b343db
JJ
15483vector unsigned char vec_xor (vector bool char, vector unsigned char);
15484vector unsigned char vec_xor (vector unsigned char, vector bool char);
924fcc4e
JM
15485vector unsigned char vec_xor (vector unsigned char,
15486 vector unsigned char);
333c8841 15487
b0b343db
JJ
15488int vec_all_eq (vector signed char, vector bool char);
15489int vec_all_eq (vector signed char, vector signed char);
15490int vec_all_eq (vector unsigned char, vector bool char);
15491int vec_all_eq (vector unsigned char, vector unsigned char);
15492int vec_all_eq (vector bool char, vector bool char);
15493int vec_all_eq (vector bool char, vector unsigned char);
15494int vec_all_eq (vector bool char, vector signed char);
15495int vec_all_eq (vector signed short, vector bool short);
15496int vec_all_eq (vector signed short, vector signed short);
15497int vec_all_eq (vector unsigned short, vector bool short);
15498int vec_all_eq (vector unsigned short, vector unsigned short);
15499int vec_all_eq (vector bool short, vector bool short);
15500int vec_all_eq (vector bool short, vector unsigned short);
15501int vec_all_eq (vector bool short, vector signed short);
15502int vec_all_eq (vector pixel, vector pixel);
15503int vec_all_eq (vector signed int, vector bool int);
15504int vec_all_eq (vector signed int, vector signed int);
15505int vec_all_eq (vector unsigned int, vector bool int);
15506int vec_all_eq (vector unsigned int, vector unsigned int);
15507int vec_all_eq (vector bool int, vector bool int);
15508int vec_all_eq (vector bool int, vector unsigned int);
15509int vec_all_eq (vector bool int, vector signed int);
15510int vec_all_eq (vector float, vector float);
15511
15512int vec_all_ge (vector bool char, vector unsigned char);
15513int vec_all_ge (vector unsigned char, vector bool char);
15514int vec_all_ge (vector unsigned char, vector unsigned char);
15515int vec_all_ge (vector bool char, vector signed char);
15516int vec_all_ge (vector signed char, vector bool char);
15517int vec_all_ge (vector signed char, vector signed char);
15518int vec_all_ge (vector bool short, vector unsigned short);
15519int vec_all_ge (vector unsigned short, vector bool short);
15520int vec_all_ge (vector unsigned short, vector unsigned short);
15521int vec_all_ge (vector signed short, vector signed short);
15522int vec_all_ge (vector bool short, vector signed short);
15523int vec_all_ge (vector signed short, vector bool short);
15524int vec_all_ge (vector bool int, vector unsigned int);
15525int vec_all_ge (vector unsigned int, vector bool int);
15526int vec_all_ge (vector unsigned int, vector unsigned int);
15527int vec_all_ge (vector bool int, vector signed int);
15528int vec_all_ge (vector signed int, vector bool int);
15529int vec_all_ge (vector signed int, vector signed int);
15530int vec_all_ge (vector float, vector float);
15531
15532int vec_all_gt (vector bool char, vector unsigned char);
15533int vec_all_gt (vector unsigned char, vector bool char);
15534int vec_all_gt (vector unsigned char, vector unsigned char);
15535int vec_all_gt (vector bool char, vector signed char);
15536int vec_all_gt (vector signed char, vector bool char);
15537int vec_all_gt (vector signed char, vector signed char);
15538int vec_all_gt (vector bool short, vector unsigned short);
15539int vec_all_gt (vector unsigned short, vector bool short);
15540int vec_all_gt (vector unsigned short, vector unsigned short);
15541int vec_all_gt (vector bool short, vector signed short);
15542int vec_all_gt (vector signed short, vector bool short);
15543int vec_all_gt (vector signed short, vector signed short);
15544int vec_all_gt (vector bool int, vector unsigned int);
15545int vec_all_gt (vector unsigned int, vector bool int);
15546int vec_all_gt (vector unsigned int, vector unsigned int);
15547int vec_all_gt (vector bool int, vector signed int);
15548int vec_all_gt (vector signed int, vector bool int);
15549int vec_all_gt (vector signed int, vector signed int);
15550int vec_all_gt (vector float, vector float);
15551
15552int vec_all_in (vector float, vector float);
15553
15554int vec_all_le (vector bool char, vector unsigned char);
15555int vec_all_le (vector unsigned char, vector bool char);
15556int vec_all_le (vector unsigned char, vector unsigned char);
15557int vec_all_le (vector bool char, vector signed char);
15558int vec_all_le (vector signed char, vector bool char);
15559int vec_all_le (vector signed char, vector signed char);
15560int vec_all_le (vector bool short, vector unsigned short);
15561int vec_all_le (vector unsigned short, vector bool short);
15562int vec_all_le (vector unsigned short, vector unsigned short);
15563int vec_all_le (vector bool short, vector signed short);
15564int vec_all_le (vector signed short, vector bool short);
15565int vec_all_le (vector signed short, vector signed short);
15566int vec_all_le (vector bool int, vector unsigned int);
15567int vec_all_le (vector unsigned int, vector bool int);
15568int vec_all_le (vector unsigned int, vector unsigned int);
15569int vec_all_le (vector bool int, vector signed int);
15570int vec_all_le (vector signed int, vector bool int);
15571int vec_all_le (vector signed int, vector signed int);
15572int vec_all_le (vector float, vector float);
15573
15574int vec_all_lt (vector bool char, vector unsigned char);
15575int vec_all_lt (vector unsigned char, vector bool char);
15576int vec_all_lt (vector unsigned char, vector unsigned char);
15577int vec_all_lt (vector bool char, vector signed char);
15578int vec_all_lt (vector signed char, vector bool char);
15579int vec_all_lt (vector signed char, vector signed char);
15580int vec_all_lt (vector bool short, vector unsigned short);
15581int vec_all_lt (vector unsigned short, vector bool short);
15582int vec_all_lt (vector unsigned short, vector unsigned short);
15583int vec_all_lt (vector bool short, vector signed short);
15584int vec_all_lt (vector signed short, vector bool short);
15585int vec_all_lt (vector signed short, vector signed short);
15586int vec_all_lt (vector bool int, vector unsigned int);
15587int vec_all_lt (vector unsigned int, vector bool int);
15588int vec_all_lt (vector unsigned int, vector unsigned int);
15589int vec_all_lt (vector bool int, vector signed int);
15590int vec_all_lt (vector signed int, vector bool int);
15591int vec_all_lt (vector signed int, vector signed int);
15592int vec_all_lt (vector float, vector float);
15593
15594int vec_all_nan (vector float);
15595
15596int vec_all_ne (vector signed char, vector bool char);
15597int vec_all_ne (vector signed char, vector signed char);
15598int vec_all_ne (vector unsigned char, vector bool char);
15599int vec_all_ne (vector unsigned char, vector unsigned char);
15600int vec_all_ne (vector bool char, vector bool char);
15601int vec_all_ne (vector bool char, vector unsigned char);
15602int vec_all_ne (vector bool char, vector signed char);
15603int vec_all_ne (vector signed short, vector bool short);
15604int vec_all_ne (vector signed short, vector signed short);
15605int vec_all_ne (vector unsigned short, vector bool short);
15606int vec_all_ne (vector unsigned short, vector unsigned short);
15607int vec_all_ne (vector bool short, vector bool short);
15608int vec_all_ne (vector bool short, vector unsigned short);
15609int vec_all_ne (vector bool short, vector signed short);
15610int vec_all_ne (vector pixel, vector pixel);
15611int vec_all_ne (vector signed int, vector bool int);
15612int vec_all_ne (vector signed int, vector signed int);
15613int vec_all_ne (vector unsigned int, vector bool int);
15614int vec_all_ne (vector unsigned int, vector unsigned int);
15615int vec_all_ne (vector bool int, vector bool int);
15616int vec_all_ne (vector bool int, vector unsigned int);
15617int vec_all_ne (vector bool int, vector signed int);
15618int vec_all_ne (vector float, vector float);
15619
15620int vec_all_nge (vector float, vector float);
15621
15622int vec_all_ngt (vector float, vector float);
15623
15624int vec_all_nle (vector float, vector float);
15625
15626int vec_all_nlt (vector float, vector float);
15627
15628int vec_all_numeric (vector float);
15629
15630int vec_any_eq (vector signed char, vector bool char);
15631int vec_any_eq (vector signed char, vector signed char);
15632int vec_any_eq (vector unsigned char, vector bool char);
15633int vec_any_eq (vector unsigned char, vector unsigned char);
15634int vec_any_eq (vector bool char, vector bool char);
15635int vec_any_eq (vector bool char, vector unsigned char);
15636int vec_any_eq (vector bool char, vector signed char);
15637int vec_any_eq (vector signed short, vector bool short);
15638int vec_any_eq (vector signed short, vector signed short);
15639int vec_any_eq (vector unsigned short, vector bool short);
15640int vec_any_eq (vector unsigned short, vector unsigned short);
15641int vec_any_eq (vector bool short, vector bool short);
15642int vec_any_eq (vector bool short, vector unsigned short);
15643int vec_any_eq (vector bool short, vector signed short);
15644int vec_any_eq (vector pixel, vector pixel);
15645int vec_any_eq (vector signed int, vector bool int);
15646int vec_any_eq (vector signed int, vector signed int);
15647int vec_any_eq (vector unsigned int, vector bool int);
15648int vec_any_eq (vector unsigned int, vector unsigned int);
15649int vec_any_eq (vector bool int, vector bool int);
15650int vec_any_eq (vector bool int, vector unsigned int);
15651int vec_any_eq (vector bool int, vector signed int);
15652int vec_any_eq (vector float, vector float);
15653
15654int vec_any_ge (vector signed char, vector bool char);
15655int vec_any_ge (vector unsigned char, vector bool char);
15656int vec_any_ge (vector unsigned char, vector unsigned char);
15657int vec_any_ge (vector signed char, vector signed char);
15658int vec_any_ge (vector bool char, vector unsigned char);
15659int vec_any_ge (vector bool char, vector signed char);
15660int vec_any_ge (vector unsigned short, vector bool short);
15661int vec_any_ge (vector unsigned short, vector unsigned short);
15662int vec_any_ge (vector signed short, vector signed short);
15663int vec_any_ge (vector signed short, vector bool short);
15664int vec_any_ge (vector bool short, vector unsigned short);
15665int vec_any_ge (vector bool short, vector signed short);
15666int vec_any_ge (vector signed int, vector bool int);
15667int vec_any_ge (vector unsigned int, vector bool int);
15668int vec_any_ge (vector unsigned int, vector unsigned int);
15669int vec_any_ge (vector signed int, vector signed int);
15670int vec_any_ge (vector bool int, vector unsigned int);
15671int vec_any_ge (vector bool int, vector signed int);
15672int vec_any_ge (vector float, vector float);
15673
15674int vec_any_gt (vector bool char, vector unsigned char);
15675int vec_any_gt (vector unsigned char, vector bool char);
15676int vec_any_gt (vector unsigned char, vector unsigned char);
15677int vec_any_gt (vector bool char, vector signed char);
15678int vec_any_gt (vector signed char, vector bool char);
15679int vec_any_gt (vector signed char, vector signed char);
15680int vec_any_gt (vector bool short, vector unsigned short);
15681int vec_any_gt (vector unsigned short, vector bool short);
15682int vec_any_gt (vector unsigned short, vector unsigned short);
15683int vec_any_gt (vector bool short, vector signed short);
15684int vec_any_gt (vector signed short, vector bool short);
15685int vec_any_gt (vector signed short, vector signed short);
15686int vec_any_gt (vector bool int, vector unsigned int);
15687int vec_any_gt (vector unsigned int, vector bool int);
15688int vec_any_gt (vector unsigned int, vector unsigned int);
15689int vec_any_gt (vector bool int, vector signed int);
15690int vec_any_gt (vector signed int, vector bool int);
15691int vec_any_gt (vector signed int, vector signed int);
15692int vec_any_gt (vector float, vector float);
15693
15694int vec_any_le (vector bool char, vector unsigned char);
15695int vec_any_le (vector unsigned char, vector bool char);
15696int vec_any_le (vector unsigned char, vector unsigned char);
15697int vec_any_le (vector bool char, vector signed char);
15698int vec_any_le (vector signed char, vector bool char);
15699int vec_any_le (vector signed char, vector signed char);
15700int vec_any_le (vector bool short, vector unsigned short);
15701int vec_any_le (vector unsigned short, vector bool short);
15702int vec_any_le (vector unsigned short, vector unsigned short);
15703int vec_any_le (vector bool short, vector signed short);
15704int vec_any_le (vector signed short, vector bool short);
15705int vec_any_le (vector signed short, vector signed short);
15706int vec_any_le (vector bool int, vector unsigned int);
15707int vec_any_le (vector unsigned int, vector bool int);
15708int vec_any_le (vector unsigned int, vector unsigned int);
15709int vec_any_le (vector bool int, vector signed int);
15710int vec_any_le (vector signed int, vector bool int);
15711int vec_any_le (vector signed int, vector signed int);
15712int vec_any_le (vector float, vector float);
15713
15714int vec_any_lt (vector bool char, vector unsigned char);
15715int vec_any_lt (vector unsigned char, vector bool char);
15716int vec_any_lt (vector unsigned char, vector unsigned char);
15717int vec_any_lt (vector bool char, vector signed char);
15718int vec_any_lt (vector signed char, vector bool char);
15719int vec_any_lt (vector signed char, vector signed char);
15720int vec_any_lt (vector bool short, vector unsigned short);
15721int vec_any_lt (vector unsigned short, vector bool short);
15722int vec_any_lt (vector unsigned short, vector unsigned short);
15723int vec_any_lt (vector bool short, vector signed short);
15724int vec_any_lt (vector signed short, vector bool short);
15725int vec_any_lt (vector signed short, vector signed short);
15726int vec_any_lt (vector bool int, vector unsigned int);
15727int vec_any_lt (vector unsigned int, vector bool int);
15728int vec_any_lt (vector unsigned int, vector unsigned int);
15729int vec_any_lt (vector bool int, vector signed int);
15730int vec_any_lt (vector signed int, vector bool int);
15731int vec_any_lt (vector signed int, vector signed int);
15732int vec_any_lt (vector float, vector float);
15733
15734int vec_any_nan (vector float);
15735
15736int vec_any_ne (vector signed char, vector bool char);
15737int vec_any_ne (vector signed char, vector signed char);
15738int vec_any_ne (vector unsigned char, vector bool char);
15739int vec_any_ne (vector unsigned char, vector unsigned char);
15740int vec_any_ne (vector bool char, vector bool char);
15741int vec_any_ne (vector bool char, vector unsigned char);
15742int vec_any_ne (vector bool char, vector signed char);
15743int vec_any_ne (vector signed short, vector bool short);
15744int vec_any_ne (vector signed short, vector signed short);
15745int vec_any_ne (vector unsigned short, vector bool short);
15746int vec_any_ne (vector unsigned short, vector unsigned short);
15747int vec_any_ne (vector bool short, vector bool short);
15748int vec_any_ne (vector bool short, vector unsigned short);
15749int vec_any_ne (vector bool short, vector signed short);
15750int vec_any_ne (vector pixel, vector pixel);
15751int vec_any_ne (vector signed int, vector bool int);
15752int vec_any_ne (vector signed int, vector signed int);
15753int vec_any_ne (vector unsigned int, vector bool int);
15754int vec_any_ne (vector unsigned int, vector unsigned int);
15755int vec_any_ne (vector bool int, vector bool int);
15756int vec_any_ne (vector bool int, vector unsigned int);
15757int vec_any_ne (vector bool int, vector signed int);
15758int vec_any_ne (vector float, vector float);
15759
15760int vec_any_nge (vector float, vector float);
15761
15762int vec_any_ngt (vector float, vector float);
15763
15764int vec_any_nle (vector float, vector float);
15765
15766int vec_any_nlt (vector float, vector float);
15767
15768int vec_any_numeric (vector float);
15769
15770int vec_any_out (vector float, vector float);
333c8841
AH
15771@end smallexample
15772
29e6733c
MM
15773If the vector/scalar (VSX) instruction set is available, the following
15774additional functions are available:
15775
15776@smallexample
15777vector double vec_abs (vector double);
15778vector double vec_add (vector double, vector double);
15779vector double vec_and (vector double, vector double);
15780vector double vec_and (vector double, vector bool long);
15781vector double vec_and (vector bool long, vector double);
65fa79c3
BS
15782vector long vec_and (vector long, vector long);
15783vector long vec_and (vector long, vector bool long);
15784vector long vec_and (vector bool long, vector long);
15785vector unsigned long vec_and (vector unsigned long, vector unsigned long);
15786vector unsigned long vec_and (vector unsigned long, vector bool long);
15787vector unsigned long vec_and (vector bool long, vector unsigned long);
29e6733c
MM
15788vector double vec_andc (vector double, vector double);
15789vector double vec_andc (vector double, vector bool long);
15790vector double vec_andc (vector bool long, vector double);
65fa79c3
BS
15791vector long vec_andc (vector long, vector long);
15792vector long vec_andc (vector long, vector bool long);
15793vector long vec_andc (vector bool long, vector long);
15794vector unsigned long vec_andc (vector unsigned long, vector unsigned long);
15795vector unsigned long vec_andc (vector unsigned long, vector bool long);
15796vector unsigned long vec_andc (vector bool long, vector unsigned long);
29e6733c
MM
15797vector double vec_ceil (vector double);
15798vector bool long vec_cmpeq (vector double, vector double);
15799vector bool long vec_cmpge (vector double, vector double);
15800vector bool long vec_cmpgt (vector double, vector double);
15801vector bool long vec_cmple (vector double, vector double);
15802vector bool long vec_cmplt (vector double, vector double);
65fa79c3 15803vector double vec_cpsgn (vector double, vector double);
29e6733c
MM
15804vector float vec_div (vector float, vector float);
15805vector double vec_div (vector double, vector double);
70f0f8b2
BS
15806vector long vec_div (vector long, vector long);
15807vector unsigned long vec_div (vector unsigned long, vector unsigned long);
29e6733c 15808vector double vec_floor (vector double);
c9485473
MM
15809vector double vec_ld (int, const vector double *);
15810vector double vec_ld (int, const double *);
15811vector double vec_ldl (int, const vector double *);
15812vector double vec_ldl (int, const double *);
15813vector unsigned char vec_lvsl (int, const volatile double *);
15814vector unsigned char vec_lvsr (int, const volatile double *);
29e6733c
MM
15815vector double vec_madd (vector double, vector double, vector double);
15816vector double vec_max (vector double, vector double);
65fa79c3
BS
15817vector signed long vec_mergeh (vector signed long, vector signed long);
15818vector signed long vec_mergeh (vector signed long, vector bool long);
15819vector signed long vec_mergeh (vector bool long, vector signed long);
15820vector unsigned long vec_mergeh (vector unsigned long, vector unsigned long);
15821vector unsigned long vec_mergeh (vector unsigned long, vector bool long);
15822vector unsigned long vec_mergeh (vector bool long, vector unsigned long);
15823vector signed long vec_mergel (vector signed long, vector signed long);
15824vector signed long vec_mergel (vector signed long, vector bool long);
15825vector signed long vec_mergel (vector bool long, vector signed long);
15826vector unsigned long vec_mergel (vector unsigned long, vector unsigned long);
15827vector unsigned long vec_mergel (vector unsigned long, vector bool long);
15828vector unsigned long vec_mergel (vector bool long, vector unsigned long);
29e6733c
MM
15829vector double vec_min (vector double, vector double);
15830vector float vec_msub (vector float, vector float, vector float);
15831vector double vec_msub (vector double, vector double, vector double);
15832vector float vec_mul (vector float, vector float);
15833vector double vec_mul (vector double, vector double);
70f0f8b2
BS
15834vector long vec_mul (vector long, vector long);
15835vector unsigned long vec_mul (vector unsigned long, vector unsigned long);
29e6733c
MM
15836vector float vec_nearbyint (vector float);
15837vector double vec_nearbyint (vector double);
15838vector float vec_nmadd (vector float, vector float, vector float);
15839vector double vec_nmadd (vector double, vector double, vector double);
15840vector double vec_nmsub (vector double, vector double, vector double);
15841vector double vec_nor (vector double, vector double);
65fa79c3
BS
15842vector long vec_nor (vector long, vector long);
15843vector long vec_nor (vector long, vector bool long);
15844vector long vec_nor (vector bool long, vector long);
15845vector unsigned long vec_nor (vector unsigned long, vector unsigned long);
15846vector unsigned long vec_nor (vector unsigned long, vector bool long);
15847vector unsigned long vec_nor (vector bool long, vector unsigned long);
29e6733c
MM
15848vector double vec_or (vector double, vector double);
15849vector double vec_or (vector double, vector bool long);
15850vector double vec_or (vector bool long, vector double);
65fa79c3
BS
15851vector long vec_or (vector long, vector long);
15852vector long vec_or (vector long, vector bool long);
15853vector long vec_or (vector bool long, vector long);
15854vector unsigned long vec_or (vector unsigned long, vector unsigned long);
15855vector unsigned long vec_or (vector unsigned long, vector bool long);
15856vector unsigned long vec_or (vector bool long, vector unsigned long);
15857vector double vec_perm (vector double, vector double, vector unsigned char);
15858vector long vec_perm (vector long, vector long, vector unsigned char);
15859vector unsigned long vec_perm (vector unsigned long, vector unsigned long,
15860 vector unsigned char);
29e6733c 15861vector double vec_rint (vector double);
92902797
MM
15862vector double vec_recip (vector double, vector double);
15863vector double vec_rsqrt (vector double);
15864vector double vec_rsqrte (vector double);
29e6733c
MM
15865vector double vec_sel (vector double, vector double, vector bool long);
15866vector double vec_sel (vector double, vector double, vector unsigned long);
65fa79c3
BS
15867vector long vec_sel (vector long, vector long, vector long);
15868vector long vec_sel (vector long, vector long, vector unsigned long);
15869vector long vec_sel (vector long, vector long, vector bool long);
15870vector unsigned long vec_sel (vector unsigned long, vector unsigned long,
15871 vector long);
15872vector unsigned long vec_sel (vector unsigned long, vector unsigned long,
15873 vector unsigned long);
15874vector unsigned long vec_sel (vector unsigned long, vector unsigned long,
15875 vector bool long);
15876vector double vec_splats (double);
15877vector signed long vec_splats (signed long);
15878vector unsigned long vec_splats (unsigned long);
29e6733c
MM
15879vector float vec_sqrt (vector float);
15880vector double vec_sqrt (vector double);
c9485473
MM
15881void vec_st (vector double, int, vector double *);
15882void vec_st (vector double, int, double *);
65fa79c3 15883vector double vec_sub (vector double, vector double);
29e6733c
MM
15884vector double vec_trunc (vector double);
15885vector double vec_xor (vector double, vector double);
15886vector double vec_xor (vector double, vector bool long);
15887vector double vec_xor (vector bool long, vector double);
65fa79c3
BS
15888vector long vec_xor (vector long, vector long);
15889vector long vec_xor (vector long, vector bool long);
15890vector long vec_xor (vector bool long, vector long);
15891vector unsigned long vec_xor (vector unsigned long, vector unsigned long);
15892vector unsigned long vec_xor (vector unsigned long, vector bool long);
15893vector unsigned long vec_xor (vector bool long, vector unsigned long);
29e6733c
MM
15894int vec_all_eq (vector double, vector double);
15895int vec_all_ge (vector double, vector double);
15896int vec_all_gt (vector double, vector double);
15897int vec_all_le (vector double, vector double);
15898int vec_all_lt (vector double, vector double);
15899int vec_all_nan (vector double);
15900int vec_all_ne (vector double, vector double);
15901int vec_all_nge (vector double, vector double);
15902int vec_all_ngt (vector double, vector double);
15903int vec_all_nle (vector double, vector double);
15904int vec_all_nlt (vector double, vector double);
15905int vec_all_numeric (vector double);
15906int vec_any_eq (vector double, vector double);
15907int vec_any_ge (vector double, vector double);
15908int vec_any_gt (vector double, vector double);
15909int vec_any_le (vector double, vector double);
15910int vec_any_lt (vector double, vector double);
15911int vec_any_nan (vector double);
15912int vec_any_ne (vector double, vector double);
15913int vec_any_nge (vector double, vector double);
15914int vec_any_ngt (vector double, vector double);
15915int vec_any_nle (vector double, vector double);
15916int vec_any_nlt (vector double, vector double);
15917int vec_any_numeric (vector double);
c9485473
MM
15918
15919vector double vec_vsx_ld (int, const vector double *);
15920vector double vec_vsx_ld (int, const double *);
15921vector float vec_vsx_ld (int, const vector float *);
15922vector float vec_vsx_ld (int, const float *);
15923vector bool int vec_vsx_ld (int, const vector bool int *);
15924vector signed int vec_vsx_ld (int, const vector signed int *);
15925vector signed int vec_vsx_ld (int, const int *);
15926vector signed int vec_vsx_ld (int, const long *);
15927vector unsigned int vec_vsx_ld (int, const vector unsigned int *);
15928vector unsigned int vec_vsx_ld (int, const unsigned int *);
15929vector unsigned int vec_vsx_ld (int, const unsigned long *);
15930vector bool short vec_vsx_ld (int, const vector bool short *);
15931vector pixel vec_vsx_ld (int, const vector pixel *);
15932vector signed short vec_vsx_ld (int, const vector signed short *);
15933vector signed short vec_vsx_ld (int, const short *);
15934vector unsigned short vec_vsx_ld (int, const vector unsigned short *);
15935vector unsigned short vec_vsx_ld (int, const unsigned short *);
15936vector bool char vec_vsx_ld (int, const vector bool char *);
15937vector signed char vec_vsx_ld (int, const vector signed char *);
15938vector signed char vec_vsx_ld (int, const signed char *);
15939vector unsigned char vec_vsx_ld (int, const vector unsigned char *);
15940vector unsigned char vec_vsx_ld (int, const unsigned char *);
15941
15942void vec_vsx_st (vector double, int, vector double *);
15943void vec_vsx_st (vector double, int, double *);
15944void vec_vsx_st (vector float, int, vector float *);
15945void vec_vsx_st (vector float, int, float *);
15946void vec_vsx_st (vector signed int, int, vector signed int *);
15947void vec_vsx_st (vector signed int, int, int *);
15948void vec_vsx_st (vector unsigned int, int, vector unsigned int *);
15949void vec_vsx_st (vector unsigned int, int, unsigned int *);
15950void vec_vsx_st (vector bool int, int, vector bool int *);
15951void vec_vsx_st (vector bool int, int, unsigned int *);
15952void vec_vsx_st (vector bool int, int, int *);
15953void vec_vsx_st (vector signed short, int, vector signed short *);
15954void vec_vsx_st (vector signed short, int, short *);
15955void vec_vsx_st (vector unsigned short, int, vector unsigned short *);
15956void vec_vsx_st (vector unsigned short, int, unsigned short *);
15957void vec_vsx_st (vector bool short, int, vector bool short *);
15958void vec_vsx_st (vector bool short, int, unsigned short *);
15959void vec_vsx_st (vector pixel, int, vector pixel *);
15960void vec_vsx_st (vector pixel, int, unsigned short *);
15961void vec_vsx_st (vector pixel, int, short *);
15962void vec_vsx_st (vector bool short, int, short *);
15963void vec_vsx_st (vector signed char, int, vector signed char *);
15964void vec_vsx_st (vector signed char, int, signed char *);
15965void vec_vsx_st (vector unsigned char, int, vector unsigned char *);
15966void vec_vsx_st (vector unsigned char, int, unsigned char *);
15967void vec_vsx_st (vector bool char, int, vector bool char *);
15968void vec_vsx_st (vector bool char, int, unsigned char *);
15969void vec_vsx_st (vector bool char, int, signed char *);
117f16fb
MM
15970
15971vector double vec_xxpermdi (vector double, vector double, int);
15972vector float vec_xxpermdi (vector float, vector float, int);
15973vector long long vec_xxpermdi (vector long long, vector long long, int);
15974vector unsigned long long vec_xxpermdi (vector unsigned long long,
15975 vector unsigned long long, int);
15976vector int vec_xxpermdi (vector int, vector int, int);
15977vector unsigned int vec_xxpermdi (vector unsigned int,
15978 vector unsigned int, int);
15979vector short vec_xxpermdi (vector short, vector short, int);
15980vector unsigned short vec_xxpermdi (vector unsigned short,
15981 vector unsigned short, int);
15982vector signed char vec_xxpermdi (vector signed char, vector signed char, int);
15983vector unsigned char vec_xxpermdi (vector unsigned char,
15984 vector unsigned char, int);
15985
15986vector double vec_xxsldi (vector double, vector double, int);
15987vector float vec_xxsldi (vector float, vector float, int);
15988vector long long vec_xxsldi (vector long long, vector long long, int);
15989vector unsigned long long vec_xxsldi (vector unsigned long long,
15990 vector unsigned long long, int);
15991vector int vec_xxsldi (vector int, vector int, int);
15992vector unsigned int vec_xxsldi (vector unsigned int, vector unsigned int, int);
15993vector short vec_xxsldi (vector short, vector short, int);
15994vector unsigned short vec_xxsldi (vector unsigned short,
15995 vector unsigned short, int);
15996vector signed char vec_xxsldi (vector signed char, vector signed char, int);
15997vector unsigned char vec_xxsldi (vector unsigned char,
15998 vector unsigned char, int);
c9485473
MM
15999@end smallexample
16000
18abab9f 16001Note that the @samp{vec_ld} and @samp{vec_st} built-in functions always
566fb011 16002generate the AltiVec @samp{LVX} and @samp{STVX} instructions even
c9485473 16003if the VSX instruction set is available. The @samp{vec_vsx_ld} and
18abab9f 16004@samp{vec_vsx_st} built-in functions always generate the VSX @samp{LXVD2X},
c9485473 16005@samp{LXVW4X}, @samp{STXVD2X}, and @samp{STXVW4X} instructions.
29e6733c 16006
a5965b52
MM
16007If the ISA 2.07 additions to the vector/scalar (power8-vector)
16008instruction set is available, the following additional functions are
16009available for both 32-bit and 64-bit targets. For 64-bit targets, you
16010can use @var{vector long} instead of @var{vector long long},
16011@var{vector bool long} instead of @var{vector bool long long}, and
16012@var{vector unsigned long} instead of @var{vector unsigned long long}.
16013
16014@smallexample
16015vector long long vec_abs (vector long long);
16016
16017vector long long vec_add (vector long long, vector long long);
16018vector unsigned long long vec_add (vector unsigned long long,
16019 vector unsigned long long);
16020
16021int vec_all_eq (vector long long, vector long long);
65fa79c3 16022int vec_all_eq (vector unsigned long long, vector unsigned long long);
a5965b52 16023int vec_all_ge (vector long long, vector long long);
65fa79c3 16024int vec_all_ge (vector unsigned long long, vector unsigned long long);
a5965b52 16025int vec_all_gt (vector long long, vector long long);
65fa79c3 16026int vec_all_gt (vector unsigned long long, vector unsigned long long);
a5965b52 16027int vec_all_le (vector long long, vector long long);
65fa79c3 16028int vec_all_le (vector unsigned long long, vector unsigned long long);
a5965b52 16029int vec_all_lt (vector long long, vector long long);
65fa79c3 16030int vec_all_lt (vector unsigned long long, vector unsigned long long);
a5965b52 16031int vec_all_ne (vector long long, vector long long);
65fa79c3
BS
16032int vec_all_ne (vector unsigned long long, vector unsigned long long);
16033
a5965b52 16034int vec_any_eq (vector long long, vector long long);
65fa79c3 16035int vec_any_eq (vector unsigned long long, vector unsigned long long);
a5965b52 16036int vec_any_ge (vector long long, vector long long);
65fa79c3 16037int vec_any_ge (vector unsigned long long, vector unsigned long long);
a5965b52 16038int vec_any_gt (vector long long, vector long long);
65fa79c3 16039int vec_any_gt (vector unsigned long long, vector unsigned long long);
a5965b52 16040int vec_any_le (vector long long, vector long long);
65fa79c3 16041int vec_any_le (vector unsigned long long, vector unsigned long long);
a5965b52 16042int vec_any_lt (vector long long, vector long long);
65fa79c3 16043int vec_any_lt (vector unsigned long long, vector unsigned long long);
a5965b52 16044int vec_any_ne (vector long long, vector long long);
65fa79c3 16045int vec_any_ne (vector unsigned long long, vector unsigned long long);
a5965b52 16046
0bd62dca
MM
16047vector long long vec_eqv (vector long long, vector long long);
16048vector long long vec_eqv (vector bool long long, vector long long);
16049vector long long vec_eqv (vector long long, vector bool long long);
16050vector unsigned long long vec_eqv (vector unsigned long long,
16051 vector unsigned long long);
16052vector unsigned long long vec_eqv (vector bool long long,
16053 vector unsigned long long);
16054vector unsigned long long vec_eqv (vector unsigned long long,
16055 vector bool long long);
16056vector int vec_eqv (vector int, vector int);
16057vector int vec_eqv (vector bool int, vector int);
16058vector int vec_eqv (vector int, vector bool int);
16059vector unsigned int vec_eqv (vector unsigned int, vector unsigned int);
16060vector unsigned int vec_eqv (vector bool unsigned int,
16061 vector unsigned int);
16062vector unsigned int vec_eqv (vector unsigned int,
16063 vector bool unsigned int);
16064vector short vec_eqv (vector short, vector short);
16065vector short vec_eqv (vector bool short, vector short);
16066vector short vec_eqv (vector short, vector bool short);
16067vector unsigned short vec_eqv (vector unsigned short, vector unsigned short);
16068vector unsigned short vec_eqv (vector bool unsigned short,
16069 vector unsigned short);
16070vector unsigned short vec_eqv (vector unsigned short,
16071 vector bool unsigned short);
16072vector signed char vec_eqv (vector signed char, vector signed char);
16073vector signed char vec_eqv (vector bool signed char, vector signed char);
16074vector signed char vec_eqv (vector signed char, vector bool signed char);
16075vector unsigned char vec_eqv (vector unsigned char, vector unsigned char);
16076vector unsigned char vec_eqv (vector bool unsigned char, vector unsigned char);
16077vector unsigned char vec_eqv (vector unsigned char, vector bool unsigned char);
16078
a5965b52
MM
16079vector long long vec_max (vector long long, vector long long);
16080vector unsigned long long vec_max (vector unsigned long long,
16081 vector unsigned long long);
16082
65fa79c3
BS
16083vector signed int vec_mergee (vector signed int, vector signed int);
16084vector unsigned int vec_mergee (vector unsigned int, vector unsigned int);
16085vector bool int vec_mergee (vector bool int, vector bool int);
16086
16087vector signed int vec_mergeo (vector signed int, vector signed int);
16088vector unsigned int vec_mergeo (vector unsigned int, vector unsigned int);
16089vector bool int vec_mergeo (vector bool int, vector bool int);
16090
a5965b52
MM
16091vector long long vec_min (vector long long, vector long long);
16092vector unsigned long long vec_min (vector unsigned long long,
16093 vector unsigned long long);
16094
0bd62dca
MM
16095vector long long vec_nand (vector long long, vector long long);
16096vector long long vec_nand (vector bool long long, vector long long);
16097vector long long vec_nand (vector long long, vector bool long long);
16098vector unsigned long long vec_nand (vector unsigned long long,
16099 vector unsigned long long);
16100vector unsigned long long vec_nand (vector bool long long,
16101 vector unsigned long long);
16102vector unsigned long long vec_nand (vector unsigned long long,
16103 vector bool long long);
16104vector int vec_nand (vector int, vector int);
16105vector int vec_nand (vector bool int, vector int);
16106vector int vec_nand (vector int, vector bool int);
16107vector unsigned int vec_nand (vector unsigned int, vector unsigned int);
16108vector unsigned int vec_nand (vector bool unsigned int,
16109 vector unsigned int);
16110vector unsigned int vec_nand (vector unsigned int,
16111 vector bool unsigned int);
16112vector short vec_nand (vector short, vector short);
16113vector short vec_nand (vector bool short, vector short);
16114vector short vec_nand (vector short, vector bool short);
16115vector unsigned short vec_nand (vector unsigned short, vector unsigned short);
16116vector unsigned short vec_nand (vector bool unsigned short,
16117 vector unsigned short);
16118vector unsigned short vec_nand (vector unsigned short,
16119 vector bool unsigned short);
16120vector signed char vec_nand (vector signed char, vector signed char);
16121vector signed char vec_nand (vector bool signed char, vector signed char);
16122vector signed char vec_nand (vector signed char, vector bool signed char);
16123vector unsigned char vec_nand (vector unsigned char, vector unsigned char);
16124vector unsigned char vec_nand (vector bool unsigned char, vector unsigned char);
16125vector unsigned char vec_nand (vector unsigned char, vector bool unsigned char);
16126
16127vector long long vec_orc (vector long long, vector long long);
16128vector long long vec_orc (vector bool long long, vector long long);
16129vector long long vec_orc (vector long long, vector bool long long);
16130vector unsigned long long vec_orc (vector unsigned long long,
16131 vector unsigned long long);
16132vector unsigned long long vec_orc (vector bool long long,
16133 vector unsigned long long);
16134vector unsigned long long vec_orc (vector unsigned long long,
16135 vector bool long long);
16136vector int vec_orc (vector int, vector int);
16137vector int vec_orc (vector bool int, vector int);
16138vector int vec_orc (vector int, vector bool int);
16139vector unsigned int vec_orc (vector unsigned int, vector unsigned int);
16140vector unsigned int vec_orc (vector bool unsigned int,
16141 vector unsigned int);
16142vector unsigned int vec_orc (vector unsigned int,
16143 vector bool unsigned int);
16144vector short vec_orc (vector short, vector short);
16145vector short vec_orc (vector bool short, vector short);
16146vector short vec_orc (vector short, vector bool short);
16147vector unsigned short vec_orc (vector unsigned short, vector unsigned short);
16148vector unsigned short vec_orc (vector bool unsigned short,
16149 vector unsigned short);
16150vector unsigned short vec_orc (vector unsigned short,
16151 vector bool unsigned short);
16152vector signed char vec_orc (vector signed char, vector signed char);
16153vector signed char vec_orc (vector bool signed char, vector signed char);
16154vector signed char vec_orc (vector signed char, vector bool signed char);
16155vector unsigned char vec_orc (vector unsigned char, vector unsigned char);
16156vector unsigned char vec_orc (vector bool unsigned char, vector unsigned char);
16157vector unsigned char vec_orc (vector unsigned char, vector bool unsigned char);
16158
a5965b52
MM
16159vector int vec_pack (vector long long, vector long long);
16160vector unsigned int vec_pack (vector unsigned long long,
16161 vector unsigned long long);
16162vector bool int vec_pack (vector bool long long, vector bool long long);
16163
16164vector int vec_packs (vector long long, vector long long);
16165vector unsigned int vec_packs (vector unsigned long long,
16166 vector unsigned long long);
16167
16168vector unsigned int vec_packsu (vector long long, vector long long);
65fa79c3
BS
16169vector unsigned int vec_packsu (vector unsigned long long,
16170 vector unsigned long long);
a5965b52
MM
16171
16172vector long long vec_rl (vector long long,
16173 vector unsigned long long);
16174vector long long vec_rl (vector unsigned long long,
16175 vector unsigned long long);
16176
16177vector long long vec_sl (vector long long, vector unsigned long long);
16178vector long long vec_sl (vector unsigned long long,
16179 vector unsigned long long);
16180
16181vector long long vec_sr (vector long long, vector unsigned long long);
16182vector unsigned long long char vec_sr (vector unsigned long long,
16183 vector unsigned long long);
16184
16185vector long long vec_sra (vector long long, vector unsigned long long);
16186vector unsigned long long vec_sra (vector unsigned long long,
16187 vector unsigned long long);
16188
16189vector long long vec_sub (vector long long, vector long long);
16190vector unsigned long long vec_sub (vector unsigned long long,
16191 vector unsigned long long);
16192
16193vector long long vec_unpackh (vector int);
16194vector unsigned long long vec_unpackh (vector unsigned int);
16195
16196vector long long vec_unpackl (vector int);
16197vector unsigned long long vec_unpackl (vector unsigned int);
16198
16199vector long long vec_vaddudm (vector long long, vector long long);
16200vector long long vec_vaddudm (vector bool long long, vector long long);
16201vector long long vec_vaddudm (vector long long, vector bool long long);
16202vector unsigned long long vec_vaddudm (vector unsigned long long,
16203 vector unsigned long long);
16204vector unsigned long long vec_vaddudm (vector bool unsigned long long,
16205 vector unsigned long long);
16206vector unsigned long long vec_vaddudm (vector unsigned long long,
16207 vector bool unsigned long long);
16208
6788164b
MM
16209vector long long vec_vbpermq (vector signed char, vector signed char);
16210vector long long vec_vbpermq (vector unsigned char, vector unsigned char);
16211
65fa79c3
BS
16212vector long long vec_cntlz (vector long long);
16213vector unsigned long long vec_cntlz (vector unsigned long long);
16214vector int vec_cntlz (vector int);
16215vector unsigned int vec_cntlz (vector int);
16216vector short vec_cntlz (vector short);
16217vector unsigned short vec_cntlz (vector unsigned short);
16218vector signed char vec_cntlz (vector signed char);
16219vector unsigned char vec_cntlz (vector unsigned char);
16220
0bd62dca
MM
16221vector long long vec_vclz (vector long long);
16222vector unsigned long long vec_vclz (vector unsigned long long);
16223vector int vec_vclz (vector int);
16224vector unsigned int vec_vclz (vector int);
16225vector short vec_vclz (vector short);
16226vector unsigned short vec_vclz (vector unsigned short);
16227vector signed char vec_vclz (vector signed char);
16228vector unsigned char vec_vclz (vector unsigned char);
16229
16230vector signed char vec_vclzb (vector signed char);
16231vector unsigned char vec_vclzb (vector unsigned char);
16232
16233vector long long vec_vclzd (vector long long);
16234vector unsigned long long vec_vclzd (vector unsigned long long);
16235
16236vector short vec_vclzh (vector short);
16237vector unsigned short vec_vclzh (vector unsigned short);
16238
16239vector int vec_vclzw (vector int);
16240vector unsigned int vec_vclzw (vector int);
16241
6fb619e4
MM
16242vector signed char vec_vgbbd (vector signed char);
16243vector unsigned char vec_vgbbd (vector unsigned char);
16244
a5965b52
MM
16245vector long long vec_vmaxsd (vector long long, vector long long);
16246
16247vector unsigned long long vec_vmaxud (vector unsigned long long,
16248 unsigned vector long long);
16249
16250vector long long vec_vminsd (vector long long, vector long long);
16251
16252vector unsigned long long vec_vminud (vector long long,
16253 vector long long);
16254
16255vector int vec_vpksdss (vector long long, vector long long);
16256vector unsigned int vec_vpksdss (vector long long, vector long long);
16257
16258vector unsigned int vec_vpkudus (vector unsigned long long,
16259 vector unsigned long long);
16260
16261vector int vec_vpkudum (vector long long, vector long long);
16262vector unsigned int vec_vpkudum (vector unsigned long long,
16263 vector unsigned long long);
16264vector bool int vec_vpkudum (vector bool long long, vector bool long long);
16265
0bd62dca
MM
16266vector long long vec_vpopcnt (vector long long);
16267vector unsigned long long vec_vpopcnt (vector unsigned long long);
16268vector int vec_vpopcnt (vector int);
16269vector unsigned int vec_vpopcnt (vector int);
16270vector short vec_vpopcnt (vector short);
16271vector unsigned short vec_vpopcnt (vector unsigned short);
16272vector signed char vec_vpopcnt (vector signed char);
16273vector unsigned char vec_vpopcnt (vector unsigned char);
16274
16275vector signed char vec_vpopcntb (vector signed char);
16276vector unsigned char vec_vpopcntb (vector unsigned char);
16277
16278vector long long vec_vpopcntd (vector long long);
16279vector unsigned long long vec_vpopcntd (vector unsigned long long);
16280
16281vector short vec_vpopcnth (vector short);
16282vector unsigned short vec_vpopcnth (vector unsigned short);
16283
16284vector int vec_vpopcntw (vector int);
16285vector unsigned int vec_vpopcntw (vector int);
16286
a5965b52
MM
16287vector long long vec_vrld (vector long long, vector unsigned long long);
16288vector unsigned long long vec_vrld (vector unsigned long long,
16289 vector unsigned long long);
16290
16291vector long long vec_vsld (vector long long, vector unsigned long long);
16292vector long long vec_vsld (vector unsigned long long,
16293 vector unsigned long long);
16294
16295vector long long vec_vsrad (vector long long, vector unsigned long long);
16296vector unsigned long long vec_vsrad (vector unsigned long long,
16297 vector unsigned long long);
16298
16299vector long long vec_vsrd (vector long long, vector unsigned long long);
16300vector unsigned long long char vec_vsrd (vector unsigned long long,
16301 vector unsigned long long);
16302
16303vector long long vec_vsubudm (vector long long, vector long long);
16304vector long long vec_vsubudm (vector bool long long, vector long long);
16305vector long long vec_vsubudm (vector long long, vector bool long long);
16306vector unsigned long long vec_vsubudm (vector unsigned long long,
16307 vector unsigned long long);
16308vector unsigned long long vec_vsubudm (vector bool long long,
16309 vector unsigned long long);
16310vector unsigned long long vec_vsubudm (vector unsigned long long,
16311 vector bool long long);
16312
16313vector long long vec_vupkhsw (vector int);
16314vector unsigned long long vec_vupkhsw (vector unsigned int);
16315
16316vector long long vec_vupklsw (vector int);
16317vector unsigned long long vec_vupklsw (vector int);
16318@end smallexample
16319
a16a872d
MM
16320If the ISA 2.07 additions to the vector/scalar (power8-vector)
16321instruction set is available, the following additional functions are
16322available for 64-bit targets. New vector types
16323(@var{vector __int128_t} and @var{vector __uint128_t}) are available
16324to hold the @var{__int128_t} and @var{__uint128_t} types to use these
16325builtins.
16326
16327The normal vector extract, and set operations work on
16328@var{vector __int128_t} and @var{vector __uint128_t} types,
16329but the index value must be 0.
16330
16331@smallexample
16332vector __int128_t vec_vaddcuq (vector __int128_t, vector __int128_t);
16333vector __uint128_t vec_vaddcuq (vector __uint128_t, vector __uint128_t);
16334
16335vector __int128_t vec_vadduqm (vector __int128_t, vector __int128_t);
16336vector __uint128_t vec_vadduqm (vector __uint128_t, vector __uint128_t);
16337
16338vector __int128_t vec_vaddecuq (vector __int128_t, vector __int128_t,
16339 vector __int128_t);
16340vector __uint128_t vec_vaddecuq (vector __uint128_t, vector __uint128_t,
16341 vector __uint128_t);
16342
16343vector __int128_t vec_vaddeuqm (vector __int128_t, vector __int128_t,
16344 vector __int128_t);
16345vector __uint128_t vec_vaddeuqm (vector __uint128_t, vector __uint128_t,
16346 vector __uint128_t);
16347
16348vector __int128_t vec_vsubecuq (vector __int128_t, vector __int128_t,
16349 vector __int128_t);
16350vector __uint128_t vec_vsubecuq (vector __uint128_t, vector __uint128_t,
16351 vector __uint128_t);
16352
16353vector __int128_t vec_vsubeuqm (vector __int128_t, vector __int128_t,
16354 vector __int128_t);
16355vector __uint128_t vec_vsubeuqm (vector __uint128_t, vector __uint128_t,
16356 vector __uint128_t);
16357
16358vector __int128_t vec_vsubcuq (vector __int128_t, vector __int128_t);
16359vector __uint128_t vec_vsubcuq (vector __uint128_t, vector __uint128_t);
16360
16361__int128_t vec_vsubuqm (__int128_t, __int128_t);
16362__uint128_t vec_vsubuqm (__uint128_t, __uint128_t);
06b39289
MM
16363
16364vector __int128_t __builtin_bcdadd (vector __int128_t, vector__int128_t);
16365int __builtin_bcdadd_lt (vector __int128_t, vector__int128_t);
16366int __builtin_bcdadd_eq (vector __int128_t, vector__int128_t);
16367int __builtin_bcdadd_gt (vector __int128_t, vector__int128_t);
16368int __builtin_bcdadd_ov (vector __int128_t, vector__int128_t);
16369vector __int128_t bcdsub (vector __int128_t, vector__int128_t);
16370int __builtin_bcdsub_lt (vector __int128_t, vector__int128_t);
16371int __builtin_bcdsub_eq (vector __int128_t, vector__int128_t);
16372int __builtin_bcdsub_gt (vector __int128_t, vector__int128_t);
16373int __builtin_bcdsub_ov (vector __int128_t, vector__int128_t);
a16a872d
MM
16374@end smallexample
16375
f62511da
MM
16376If the cryptographic instructions are enabled (@option{-mcrypto} or
16377@option{-mcpu=power8}), the following builtins are enabled.
16378
16379@smallexample
16380vector unsigned long long __builtin_crypto_vsbox (vector unsigned long long);
16381
16382vector unsigned long long __builtin_crypto_vcipher (vector unsigned long long,
16383 vector unsigned long long);
16384
16385vector unsigned long long __builtin_crypto_vcipherlast
16386 (vector unsigned long long,
16387 vector unsigned long long);
16388
16389vector unsigned long long __builtin_crypto_vncipher (vector unsigned long long,
16390 vector unsigned long long);
16391
16392vector unsigned long long __builtin_crypto_vncipherlast
16393 (vector unsigned long long,
16394 vector unsigned long long);
16395
16396vector unsigned char __builtin_crypto_vpermxor (vector unsigned char,
16397 vector unsigned char,
16398 vector unsigned char);
16399
16400vector unsigned short __builtin_crypto_vpermxor (vector unsigned short,
16401 vector unsigned short,
16402 vector unsigned short);
16403
16404vector unsigned int __builtin_crypto_vpermxor (vector unsigned int,
16405 vector unsigned int,
16406 vector unsigned int);
16407
16408vector unsigned long long __builtin_crypto_vpermxor (vector unsigned long long,
16409 vector unsigned long long,
16410 vector unsigned long long);
16411
16412vector unsigned char __builtin_crypto_vpmsumb (vector unsigned char,
16413 vector unsigned char);
16414
16415vector unsigned short __builtin_crypto_vpmsumb (vector unsigned short,
16416 vector unsigned short);
16417
16418vector unsigned int __builtin_crypto_vpmsumb (vector unsigned int,
16419 vector unsigned int);
16420
16421vector unsigned long long __builtin_crypto_vpmsumb (vector unsigned long long,
16422 vector unsigned long long);
16423
16424vector unsigned long long __builtin_crypto_vshasigmad
16425 (vector unsigned long long, int, int);
16426
16427vector unsigned int __builtin_crypto_vshasigmaw (vector unsigned int,
16428 int, int);
16429@end smallexample
16430
16431The second argument to the @var{__builtin_crypto_vshasigmad} and
16432@var{__builtin_crypto_vshasigmaw} builtin functions must be a constant
16433integer that is 0 or 1. The third argument to these builtin functions
16434must be a constant integer in the range of 0 to 15.
af7d1b7d
PB
16435
16436@node PowerPC Hardware Transactional Memory Built-in Functions
16437@subsection PowerPC Hardware Transactional Memory Built-in Functions
16438GCC provides two interfaces for accessing the Hardware Transactional
16439Memory (HTM) instructions available on some of the PowerPC family
16440of prcoessors (eg, POWER8). The two interfaces come in a low level
16441interface, consisting of built-in functions specific to PowerPC and a
16442higher level interface consisting of inline functions that are common
16443between PowerPC and S/390.
16444
16445@subsubsection PowerPC HTM Low Level Built-in Functions
16446
16447The following low level built-in functions are available with
16448@option{-mhtm} or @option{-mcpu=CPU} where CPU is `power8' or later.
16449They all generate the machine instruction that is part of the name.
16450
16451The HTM built-ins return true or false depending on their success and
16452their arguments match exactly the type and order of the associated
16453hardware instruction's operands. Refer to the ISA manual for a
16454description of each instruction's operands.
16455
16456@smallexample
16457unsigned int __builtin_tbegin (unsigned int)
16458unsigned int __builtin_tend (unsigned int)
16459
16460unsigned int __builtin_tabort (unsigned int)
16461unsigned int __builtin_tabortdc (unsigned int, unsigned int, unsigned int)
16462unsigned int __builtin_tabortdci (unsigned int, unsigned int, int)
16463unsigned int __builtin_tabortwc (unsigned int, unsigned int, unsigned int)
16464unsigned int __builtin_tabortwci (unsigned int, unsigned int, int)
16465
16466unsigned int __builtin_tcheck (unsigned int)
16467unsigned int __builtin_treclaim (unsigned int)
16468unsigned int __builtin_trechkpt (void)
16469unsigned int __builtin_tsr (unsigned int)
16470@end smallexample
16471
16472In addition to the above HTM built-ins, we have added built-ins for
16473some common extended mnemonics of the HTM instructions:
16474
16475@smallexample
16476unsigned int __builtin_tendall (void)
16477unsigned int __builtin_tresume (void)
16478unsigned int __builtin_tsuspend (void)
16479@end smallexample
16480
16481The following set of built-in functions are available to gain access
16482to the HTM specific special purpose registers.
16483
16484@smallexample
16485unsigned long __builtin_get_texasr (void)
16486unsigned long __builtin_get_texasru (void)
16487unsigned long __builtin_get_tfhar (void)
16488unsigned long __builtin_get_tfiar (void)
16489
16490void __builtin_set_texasr (unsigned long);
16491void __builtin_set_texasru (unsigned long);
16492void __builtin_set_tfhar (unsigned long);
16493void __builtin_set_tfiar (unsigned long);
16494@end smallexample
16495
16496Example usage of these low level built-in functions may look like:
16497
16498@smallexample
16499#include <htmintrin.h>
16500
16501int num_retries = 10;
16502
16503while (1)
16504 @{
16505 if (__builtin_tbegin (0))
16506 @{
16507 /* Transaction State Initiated. */
16508 if (is_locked (lock))
16509 __builtin_tabort (0);
16510 ... transaction code...
16511 __builtin_tend (0);
16512 break;
16513 @}
16514 else
16515 @{
16516 /* Transaction State Failed. Use locks if the transaction
16517 failure is "persistent" or we've tried too many times. */
16518 if (num_retries-- <= 0
16519 || _TEXASRU_FAILURE_PERSISTENT (__builtin_get_texasru ()))
16520 @{
16521 acquire_lock (lock);
16522 ... non transactional fallback path...
16523 release_lock (lock);
16524 break;
16525 @}
16526 @}
16527 @}
16528@end smallexample
16529
16530One final built-in function has been added that returns the value of
16531the 2-bit Transaction State field of the Machine Status Register (MSR)
16532as stored in @code{CR0}.
16533
16534@smallexample
16535unsigned long __builtin_ttest (void)
16536@end smallexample
16537
16538This built-in can be used to determine the current transaction state
16539using the following code example:
16540
16541@smallexample
16542#include <htmintrin.h>
16543
16544unsigned char tx_state = _HTM_STATE (__builtin_ttest ());
16545
16546if (tx_state == _HTM_TRANSACTIONAL)
16547 @{
16548 /* Code to use in transactional state. */
16549 @}
16550else if (tx_state == _HTM_NONTRANSACTIONAL)
16551 @{
16552 /* Code to use in non-transactional state. */
16553 @}
16554else if (tx_state == _HTM_SUSPENDED)
16555 @{
16556 /* Code to use in transaction suspended state. */
16557 @}
16558@end smallexample
16559
16560@subsubsection PowerPC HTM High Level Inline Functions
16561
16562The following high level HTM interface is made available by including
16563@code{<htmxlintrin.h>} and using @option{-mhtm} or @option{-mcpu=CPU}
16564where CPU is `power8' or later. This interface is common between PowerPC
16565and S/390, allowing users to write one HTM source implementation that
16566can be compiled and executed on either system.
16567
16568@smallexample
16569long __TM_simple_begin (void)
16570long __TM_begin (void* const TM_buff)
16571long __TM_end (void)
16572void __TM_abort (void)
16573void __TM_named_abort (unsigned char const code)
16574void __TM_resume (void)
16575void __TM_suspend (void)
16576
16577long __TM_is_user_abort (void* const TM_buff)
16578long __TM_is_named_user_abort (void* const TM_buff, unsigned char *code)
16579long __TM_is_illegal (void* const TM_buff)
16580long __TM_is_footprint_exceeded (void* const TM_buff)
16581long __TM_nesting_depth (void* const TM_buff)
16582long __TM_is_nested_too_deep(void* const TM_buff)
16583long __TM_is_conflict(void* const TM_buff)
16584long __TM_is_failure_persistent(void* const TM_buff)
16585long __TM_failure_address(void* const TM_buff)
16586long long __TM_failure_code(void* const TM_buff)
16587@end smallexample
16588
16589Using these common set of HTM inline functions, we can create
16590a more portable version of the HTM example in the previous
16591section that will work on either PowerPC or S/390:
16592
16593@smallexample
16594#include <htmxlintrin.h>
16595
16596int num_retries = 10;
16597TM_buff_type TM_buff;
16598
16599while (1)
16600 @{
16601 if (__TM_begin (TM_buff))
16602 @{
16603 /* Transaction State Initiated. */
16604 if (is_locked (lock))
16605 __TM_abort ();
16606 ... transaction code...
16607 __TM_end ();
16608 break;
16609 @}
16610 else
16611 @{
16612 /* Transaction State Failed. Use locks if the transaction
16613 failure is "persistent" or we've tried too many times. */
16614 if (num_retries-- <= 0
16615 || __TM_is_failure_persistent (TM_buff))
16616 @{
16617 acquire_lock (lock);
16618 ... non transactional fallback path...
16619 release_lock (lock);
16620 break;
16621 @}
16622 @}
16623 @}
16624@end smallexample
f62511da 16625
65a324b4
NC
16626@node RX Built-in Functions
16627@subsection RX Built-in Functions
16628GCC supports some of the RX instructions which cannot be expressed in
16629the C programming language via the use of built-in functions. The
16630following functions are supported:
16631
16632@deftypefn {Built-in Function} void __builtin_rx_brk (void)
16633Generates the @code{brk} machine instruction.
16634@end deftypefn
16635
16636@deftypefn {Built-in Function} void __builtin_rx_clrpsw (int)
16637Generates the @code{clrpsw} machine instruction to clear the specified
16638bit in the processor status word.
16639@end deftypefn
16640
16641@deftypefn {Built-in Function} void __builtin_rx_int (int)
16642Generates the @code{int} machine instruction to generate an interrupt
16643with the specified value.
16644@end deftypefn
16645
16646@deftypefn {Built-in Function} void __builtin_rx_machi (int, int)
16647Generates the @code{machi} machine instruction to add the result of
6f46cb63 16648multiplying the top 16 bits of the two arguments into the
65a324b4
NC
16649accumulator.
16650@end deftypefn
16651
16652@deftypefn {Built-in Function} void __builtin_rx_maclo (int, int)
16653Generates the @code{maclo} machine instruction to add the result of
6f46cb63 16654multiplying the bottom 16 bits of the two arguments into the
65a324b4
NC
16655accumulator.
16656@end deftypefn
16657
16658@deftypefn {Built-in Function} void __builtin_rx_mulhi (int, int)
16659Generates the @code{mulhi} machine instruction to place the result of
6f46cb63 16660multiplying the top 16 bits of the two arguments into the
65a324b4
NC
16661accumulator.
16662@end deftypefn
16663
16664@deftypefn {Built-in Function} void __builtin_rx_mullo (int, int)
16665Generates the @code{mullo} machine instruction to place the result of
6f46cb63 16666multiplying the bottom 16 bits of the two arguments into the
65a324b4
NC
16667accumulator.
16668@end deftypefn
16669
16670@deftypefn {Built-in Function} int __builtin_rx_mvfachi (void)
16671Generates the @code{mvfachi} machine instruction to read the top
6f46cb63 1667232 bits of the accumulator.
65a324b4
NC
16673@end deftypefn
16674
16675@deftypefn {Built-in Function} int __builtin_rx_mvfacmi (void)
16676Generates the @code{mvfacmi} machine instruction to read the middle
6f46cb63 1667732 bits of the accumulator.
65a324b4
NC
16678@end deftypefn
16679
16680@deftypefn {Built-in Function} int __builtin_rx_mvfc (int)
16681Generates the @code{mvfc} machine instruction which reads the control
16682register specified in its argument and returns its value.
16683@end deftypefn
16684
16685@deftypefn {Built-in Function} void __builtin_rx_mvtachi (int)
16686Generates the @code{mvtachi} machine instruction to set the top
6f46cb63 1668732 bits of the accumulator.
65a324b4
NC
16688@end deftypefn
16689
16690@deftypefn {Built-in Function} void __builtin_rx_mvtaclo (int)
16691Generates the @code{mvtaclo} machine instruction to set the bottom
6f46cb63 1669232 bits of the accumulator.
65a324b4
NC
16693@end deftypefn
16694
16695@deftypefn {Built-in Function} void __builtin_rx_mvtc (int reg, int val)
16696Generates the @code{mvtc} machine instruction which sets control
16697register number @code{reg} to @code{val}.
16698@end deftypefn
16699
16700@deftypefn {Built-in Function} void __builtin_rx_mvtipl (int)
16701Generates the @code{mvtipl} machine instruction set the interrupt
16702priority level.
16703@end deftypefn
16704
16705@deftypefn {Built-in Function} void __builtin_rx_racw (int)
16706Generates the @code{racw} machine instruction to round the accumulator
16707according to the specified mode.
16708@end deftypefn
16709
16710@deftypefn {Built-in Function} int __builtin_rx_revw (int)
16711Generates the @code{revw} machine instruction which swaps the bytes in
16712the argument so that bits 0--7 now occupy bits 8--15 and vice versa,
16713and also bits 16--23 occupy bits 24--31 and vice versa.
16714@end deftypefn
16715
16716@deftypefn {Built-in Function} void __builtin_rx_rmpa (void)
16717Generates the @code{rmpa} machine instruction which initiates a
16718repeated multiply and accumulate sequence.
16719@end deftypefn
16720
16721@deftypefn {Built-in Function} void __builtin_rx_round (float)
16722Generates the @code{round} machine instruction which returns the
6f46cb63
SL
16723floating-point argument rounded according to the current rounding mode
16724set in the floating-point status word register.
65a324b4
NC
16725@end deftypefn
16726
16727@deftypefn {Built-in Function} int __builtin_rx_sat (int)
16728Generates the @code{sat} machine instruction which returns the
16729saturated value of the argument.
16730@end deftypefn
16731
16732@deftypefn {Built-in Function} void __builtin_rx_setpsw (int)
16733Generates the @code{setpsw} machine instruction to set the specified
16734bit in the processor status word.
16735@end deftypefn
16736
16737@deftypefn {Built-in Function} void __builtin_rx_wait (void)
16738Generates the @code{wait} machine instruction.
16739@end deftypefn
16740
5a3fe9b6
AK
16741@node S/390 System z Built-in Functions
16742@subsection S/390 System z Built-in Functions
16743@deftypefn {Built-in Function} int __builtin_tbegin (void*)
16744Generates the @code{tbegin} machine instruction starting a
16745non-constraint hardware transaction. If the parameter is non-NULL the
16746memory area is used to store the transaction diagnostic buffer and
16747will be passed as first operand to @code{tbegin}. This buffer can be
16748defined using the @code{struct __htm_tdb} C struct defined in
16749@code{htmintrin.h} and must reside on a double-word boundary. The
16750second tbegin operand is set to @code{0xff0c}. This enables
16751save/restore of all GPRs and disables aborts for FPR and AR
16752manipulations inside the transaction body. The condition code set by
16753the tbegin instruction is returned as integer value. The tbegin
16754instruction by definition overwrites the content of all FPRs. The
16755compiler will generate code which saves and restores the FPRs. For
16756soft-float code it is recommended to used the @code{*_nofloat}
16757variant. In order to prevent a TDB from being written it is required
16758to pass an constant zero value as parameter. Passing the zero value
16759through a variable is not sufficient. Although modifications of
16760access registers inside the transaction will not trigger an
16761transaction abort it is not supported to actually modify them. Access
16762registers do not get saved when entering a transaction. They will have
16763undefined state when reaching the abort code.
16764@end deftypefn
16765
16766Macros for the possible return codes of tbegin are defined in the
16767@code{htmintrin.h} header file:
16768
16769@table @code
16770@item _HTM_TBEGIN_STARTED
16771@code{tbegin} has been executed as part of normal processing. The
16772transaction body is supposed to be executed.
16773@item _HTM_TBEGIN_INDETERMINATE
16774The transaction was aborted due to an indeterminate condition which
16775might be persistent.
16776@item _HTM_TBEGIN_TRANSIENT
16777The transaction aborted due to a transient failure. The transaction
16778should be re-executed in that case.
16779@item _HTM_TBEGIN_PERSISTENT
16780The transaction aborted due to a persistent failure. Re-execution
16781under same circumstances will not be productive.
16782@end table
16783
16784@defmac _HTM_FIRST_USER_ABORT_CODE
16785The @code{_HTM_FIRST_USER_ABORT_CODE} defined in @code{htmintrin.h}
16786specifies the first abort code which can be used for
16787@code{__builtin_tabort}. Values below this threshold are reserved for
16788machine use.
16789@end defmac
16790
16791@deftp {Data type} {struct __htm_tdb}
16792The @code{struct __htm_tdb} defined in @code{htmintrin.h} describes
16793the structure of the transaction diagnostic block as specified in the
16794Principles of Operation manual chapter 5-91.
16795@end deftp
16796
16797@deftypefn {Built-in Function} int __builtin_tbegin_nofloat (void*)
16798Same as @code{__builtin_tbegin} but without FPR saves and restores.
16799Using this variant in code making use of FPRs will leave the FPRs in
16800undefined state when entering the transaction abort handler code.
16801@end deftypefn
16802
16803@deftypefn {Built-in Function} int __builtin_tbegin_retry (void*, int)
16804In addition to @code{__builtin_tbegin} a loop for transient failures
16805is generated. If tbegin returns a condition code of 2 the transaction
16806will be retried as often as specified in the second argument. The
16807perform processor assist instruction is used to tell the CPU about the
16808number of fails so far.
16809@end deftypefn
16810
16811@deftypefn {Built-in Function} int __builtin_tbegin_retry_nofloat (void*, int)
16812Same as @code{__builtin_tbegin_retry} but without FPR saves and
16813restores. Using this variant in code making use of FPRs will leave
16814the FPRs in undefined state when entering the transaction abort
16815handler code.
16816@end deftypefn
16817
16818@deftypefn {Built-in Function} void __builtin_tbeginc (void)
16819Generates the @code{tbeginc} machine instruction starting a constraint
16820hardware transaction. The second operand is set to @code{0xff08}.
16821@end deftypefn
16822
16823@deftypefn {Built-in Function} int __builtin_tend (void)
16824Generates the @code{tend} machine instruction finishing a transaction
16825and making the changes visible to other threads. The condition code
16826generated by tend is returned as integer value.
16827@end deftypefn
16828
16829@deftypefn {Built-in Function} void __builtin_tabort (int)
16830Generates the @code{tabort} machine instruction with the specified
16831abort code. Abort codes from 0 through 255 are reserved and will
16832result in an error message.
16833@end deftypefn
16834
16835@deftypefn {Built-in Function} void __builtin_tx_assist (int)
16836Generates the @code{ppa rX,rY,1} machine instruction. Where the
16837integer parameter is loaded into rX and a value of zero is loaded into
16838rY. The integer parameter specifies the number of times the
16839transaction repeatedly aborted.
16840@end deftypefn
16841
16842@deftypefn {Built-in Function} int __builtin_tx_nesting_depth (void)
16843Generates the @code{etnd} machine instruction. The current nesting
16844depth is returned as integer value. For a nesting depth of 0 the code
16845is not executed as part of an transaction.
16846@end deftypefn
16847
ee163e72 16848@deftypefn {Built-in Function} void __builtin_non_tx_store (uint64_t *, uint64_t)
5a3fe9b6
AK
16849
16850Generates the @code{ntstg} machine instruction. The second argument
16851is written to the first arguments location. The store operation will
16852not be rolled-back in case of an transaction abort.
16853@end deftypefn
16854
40bf31ed
TB
16855@node SH Built-in Functions
16856@subsection SH Built-in Functions
16857The following built-in functions are supported on the SH1, SH2, SH3 and SH4
16858families of processors:
16859
16860@deftypefn {Built-in Function} {void} __builtin_set_thread_pointer (void *@var{ptr})
16861Sets the @samp{GBR} register to the specified value @var{ptr}. This is usually
16862used by system code that manages threads and execution contexts. The compiler
16863normally does not generate code that modifies the contents of @samp{GBR} and
16864thus the value is preserved across function calls. Changing the @samp{GBR}
16865value in user code must be done with caution, since the compiler might use
16866@samp{GBR} in order to access thread local variables.
16867
16868@end deftypefn
16869
16870@deftypefn {Built-in Function} {void *} __builtin_thread_pointer (void)
16871Returns the value that is currently set in the @samp{GBR} register.
16872Memory loads and stores that use the thread pointer as a base address are
16873turned into @samp{GBR} based displacement loads and stores, if possible.
16874For example:
16875@smallexample
16876struct my_tcb
16877@{
16878 int a, b, c, d, e;
16879@};
16880
16881int get_tcb_value (void)
16882@{
16883 // Generate @samp{mov.l @@(8,gbr),r0} instruction
16884 return ((my_tcb*)__builtin_thread_pointer ())->c;
16885@}
16886
16887@end smallexample
16888@end deftypefn
16889
c5145ceb
JM
16890@node SPARC VIS Built-in Functions
16891@subsection SPARC VIS Built-in Functions
16892
16893GCC supports SIMD operations on the SPARC using both the generic vector
2fd13506 16894extensions (@pxref{Vector Extensions}) as well as built-in functions for
c5145ceb
JM
16895the SPARC Visual Instruction Set (VIS). When you use the @option{-mvis}
16896switch, the VIS extension is exposed as the following built-in functions:
16897
16898@smallexample
f14e0262 16899typedef int v1si __attribute__ ((vector_size (4)));
c5145ceb
JM
16900typedef int v2si __attribute__ ((vector_size (8)));
16901typedef short v4hi __attribute__ ((vector_size (8)));
16902typedef short v2hi __attribute__ ((vector_size (4)));
47640f40
DM
16903typedef unsigned char v8qi __attribute__ ((vector_size (8)));
16904typedef unsigned char v4qi __attribute__ ((vector_size (4)));
c5145ceb 16905
10b859c0
DM
16906void __builtin_vis_write_gsr (int64_t);
16907int64_t __builtin_vis_read_gsr (void);
16908
c5145ceb 16909void * __builtin_vis_alignaddr (void *, long);
47640f40 16910void * __builtin_vis_alignaddrl (void *, long);
c5145ceb
JM
16911int64_t __builtin_vis_faligndatadi (int64_t, int64_t);
16912v2si __builtin_vis_faligndatav2si (v2si, v2si);
16913v4hi __builtin_vis_faligndatav4hi (v4si, v4si);
16914v8qi __builtin_vis_faligndatav8qi (v8qi, v8qi);
16915
16916v4hi __builtin_vis_fexpand (v4qi);
16917
16918v4hi __builtin_vis_fmul8x16 (v4qi, v4hi);
47640f40
DM
16919v4hi __builtin_vis_fmul8x16au (v4qi, v2hi);
16920v4hi __builtin_vis_fmul8x16al (v4qi, v2hi);
c5145ceb
JM
16921v4hi __builtin_vis_fmul8sux16 (v8qi, v4hi);
16922v4hi __builtin_vis_fmul8ulx16 (v8qi, v4hi);
16923v2si __builtin_vis_fmuld8sux16 (v4qi, v2hi);
16924v2si __builtin_vis_fmuld8ulx16 (v4qi, v2hi);
16925
16926v4qi __builtin_vis_fpack16 (v4hi);
47640f40 16927v8qi __builtin_vis_fpack32 (v2si, v8qi);
c5145ceb
JM
16928v2hi __builtin_vis_fpackfix (v2si);
16929v8qi __builtin_vis_fpmerge (v4qi, v4qi);
16930
16931int64_t __builtin_vis_pdist (v8qi, v8qi, int64_t);
b1e4f4dd 16932
cb8bbba8
DM
16933long __builtin_vis_edge8 (void *, void *);
16934long __builtin_vis_edge8l (void *, void *);
16935long __builtin_vis_edge16 (void *, void *);
16936long __builtin_vis_edge16l (void *, void *);
16937long __builtin_vis_edge32 (void *, void *);
16938long __builtin_vis_edge32l (void *, void *);
16939
16940long __builtin_vis_fcmple16 (v4hi, v4hi);
16941long __builtin_vis_fcmple32 (v2si, v2si);
16942long __builtin_vis_fcmpne16 (v4hi, v4hi);
16943long __builtin_vis_fcmpne32 (v2si, v2si);
16944long __builtin_vis_fcmpgt16 (v4hi, v4hi);
16945long __builtin_vis_fcmpgt32 (v2si, v2si);
16946long __builtin_vis_fcmpeq16 (v4hi, v4hi);
16947long __builtin_vis_fcmpeq32 (v2si, v2si);
f14e0262
DM
16948
16949v4hi __builtin_vis_fpadd16 (v4hi, v4hi);
16950v2hi __builtin_vis_fpadd16s (v2hi, v2hi);
16951v2si __builtin_vis_fpadd32 (v2si, v2si);
16952v1si __builtin_vis_fpadd32s (v1si, v1si);
16953v4hi __builtin_vis_fpsub16 (v4hi, v4hi);
16954v2hi __builtin_vis_fpsub16s (v2hi, v2hi);
16955v2si __builtin_vis_fpsub32 (v2si, v2si);
16956v1si __builtin_vis_fpsub32s (v1si, v1si);
1ec01ab2
DM
16957
16958long __builtin_vis_array8 (long, long);
16959long __builtin_vis_array16 (long, long);
16960long __builtin_vis_array32 (long, long);
c5145ceb
JM
16961@end smallexample
16962
96d7b15f
DM
16963When you use the @option{-mvis2} switch, the VIS version 2.0 built-in
16964functions also become available:
c4728c6b
DM
16965
16966@smallexample
16967long __builtin_vis_bmask (long, long);
16968int64_t __builtin_vis_bshuffledi (int64_t, int64_t);
16969v2si __builtin_vis_bshufflev2si (v2si, v2si);
16970v4hi __builtin_vis_bshufflev2si (v4hi, v4hi);
16971v8qi __builtin_vis_bshufflev2si (v8qi, v8qi);
16972
16973long __builtin_vis_edge8n (void *, void *);
16974long __builtin_vis_edge8ln (void *, void *);
16975long __builtin_vis_edge16n (void *, void *);
16976long __builtin_vis_edge16ln (void *, void *);
16977long __builtin_vis_edge32n (void *, void *);
16978long __builtin_vis_edge32ln (void *, void *);
16979@end smallexample
16980
96d7b15f
DM
16981When you use the @option{-mvis3} switch, the VIS version 3.0 built-in
16982functions also become available:
16983
16984@smallexample
16985void __builtin_vis_cmask8 (long);
16986void __builtin_vis_cmask16 (long);
16987void __builtin_vis_cmask32 (long);
16988
16989v4hi __builtin_vis_fchksm16 (v4hi, v4hi);
16990
16991v4hi __builtin_vis_fsll16 (v4hi, v4hi);
16992v4hi __builtin_vis_fslas16 (v4hi, v4hi);
16993v4hi __builtin_vis_fsrl16 (v4hi, v4hi);
16994v4hi __builtin_vis_fsra16 (v4hi, v4hi);
16995v2si __builtin_vis_fsll16 (v2si, v2si);
16996v2si __builtin_vis_fslas16 (v2si, v2si);
16997v2si __builtin_vis_fsrl16 (v2si, v2si);
16998v2si __builtin_vis_fsra16 (v2si, v2si);
16999
17000long __builtin_vis_pdistn (v8qi, v8qi);
17001
17002v4hi __builtin_vis_fmean16 (v4hi, v4hi);
17003
17004int64_t __builtin_vis_fpadd64 (int64_t, int64_t);
17005int64_t __builtin_vis_fpsub64 (int64_t, int64_t);
17006
17007v4hi __builtin_vis_fpadds16 (v4hi, v4hi);
17008v2hi __builtin_vis_fpadds16s (v2hi, v2hi);
17009v4hi __builtin_vis_fpsubs16 (v4hi, v4hi);
17010v2hi __builtin_vis_fpsubs16s (v2hi, v2hi);
17011v2si __builtin_vis_fpadds32 (v2si, v2si);
17012v1si __builtin_vis_fpadds32s (v1si, v1si);
17013v2si __builtin_vis_fpsubs32 (v2si, v2si);
17014v1si __builtin_vis_fpsubs32s (v1si, v1si);
17015
17016long __builtin_vis_fucmple8 (v8qi, v8qi);
17017long __builtin_vis_fucmpne8 (v8qi, v8qi);
17018long __builtin_vis_fucmpgt8 (v8qi, v8qi);
17019long __builtin_vis_fucmpeq8 (v8qi, v8qi);
facb3fd7
DM
17020
17021float __builtin_vis_fhadds (float, float);
17022double __builtin_vis_fhaddd (double, double);
17023float __builtin_vis_fhsubs (float, float);
17024double __builtin_vis_fhsubd (double, double);
17025float __builtin_vis_fnhadds (float, float);
17026double __builtin_vis_fnhaddd (double, double);
17027
17028int64_t __builtin_vis_umulxhi (int64_t, int64_t);
17029int64_t __builtin_vis_xmulx (int64_t, int64_t);
17030int64_t __builtin_vis_xmulxhi (int64_t, int64_t);
96d7b15f
DM
17031@end smallexample
17032
85d9c13c
TS
17033@node SPU Built-in Functions
17034@subsection SPU Built-in Functions
17035
17036GCC provides extensions for the SPU processor as described in the
17037Sony/Toshiba/IBM SPU Language Extensions Specification, which can be
17038found at @uref{http://cell.scei.co.jp/} or
17039@uref{http://www.ibm.com/developerworks/power/cell/}. GCC's
17040implementation differs in several ways.
17041
17042@itemize @bullet
17043
17044@item
17045The optional extension of specifying vector constants in parentheses is
17046not supported.
17047
17048@item
17049A vector initializer requires no cast if the vector constant is of the
17050same type as the variable it is initializing.
17051
17052@item
17053If @code{signed} or @code{unsigned} is omitted, the signedness of the
17054vector type is the default signedness of the base type. The default
17055varies depending on the operating system, so a portable program should
17056always specify the signedness.
17057
17058@item
17059By default, the keyword @code{__vector} is added. The macro
17060@code{vector} is defined in @code{<spu_intrinsics.h>} and can be
17061undefined.
17062
17063@item
17064GCC allows using a @code{typedef} name as the type specifier for a
17065vector type.
17066
17067@item
17068For C, overloaded functions are implemented with macros so the following
17069does not work:
17070
17071@smallexample
17072 spu_add ((vector signed int)@{1, 2, 3, 4@}, foo);
17073@end smallexample
17074
c513ecbf 17075@noindent
85d9c13c
TS
17076Since @code{spu_add} is a macro, the vector constant in the example
17077is treated as four separate arguments. Wrap the entire argument in
17078parentheses for this to work.
17079
17080@item
17081The extended version of @code{__builtin_expect} is not supported.
17082
17083@end itemize
17084
5681c208 17085@emph{Note:} Only the interface described in the aforementioned
85d9c13c
TS
17086specification is supported. Internally, GCC uses built-in functions to
17087implement the required functionality, but these are not supported and
17088are subject to change without notice.
17089
bcead286
BS
17090@node TI C6X Built-in Functions
17091@subsection TI C6X Built-in Functions
17092
17093GCC provides intrinsics to access certain instructions of the TI C6X
17094processors. These intrinsics, listed below, are available after
17095inclusion of the @code{c6x_intrinsics.h} header file. They map directly
17096to C6X instructions.
17097
17098@smallexample
17099
17100int _sadd (int, int)
17101int _ssub (int, int)
17102int _sadd2 (int, int)
17103int _ssub2 (int, int)
17104long long _mpy2 (int, int)
17105long long _smpy2 (int, int)
17106int _add4 (int, int)
17107int _sub4 (int, int)
17108int _saddu4 (int, int)
17109
17110int _smpy (int, int)
17111int _smpyh (int, int)
17112int _smpyhl (int, int)
17113int _smpylh (int, int)
17114
17115int _sshl (int, int)
17116int _subc (int, int)
17117
17118int _avg2 (int, int)
17119int _avgu4 (int, int)
17120
17121int _clrr (int, int)
17122int _extr (int, int)
17123int _extru (int, int)
17124int _abs (int)
17125int _abs2 (int)
17126
17127@end smallexample
17128
dd552284
WL
17129@node TILE-Gx Built-in Functions
17130@subsection TILE-Gx Built-in Functions
17131
17132GCC provides intrinsics to access every instruction of the TILE-Gx
17133processor. The intrinsics are of the form:
17134
17135@smallexample
17136
17137unsigned long long __insn_@var{op} (...)
17138
17139@end smallexample
17140
17141Where @var{op} is the name of the instruction. Refer to the ISA manual
17142for the complete list of instructions.
17143
17144GCC also provides intrinsics to directly access the network registers.
17145The intrinsics are:
17146
17147@smallexample
17148
17149unsigned long long __tile_idn0_receive (void)
17150unsigned long long __tile_idn1_receive (void)
17151unsigned long long __tile_udn0_receive (void)
17152unsigned long long __tile_udn1_receive (void)
17153unsigned long long __tile_udn2_receive (void)
17154unsigned long long __tile_udn3_receive (void)
17155void __tile_idn_send (unsigned long long)
17156void __tile_udn_send (unsigned long long)
17157
17158@end smallexample
17159
17160The intrinsic @code{void __tile_network_barrier (void)} is used to
358a3dbc 17161guarantee that no network operations before it are reordered with
dd552284
WL
17162those after it.
17163
17164@node TILEPro Built-in Functions
17165@subsection TILEPro Built-in Functions
17166
17167GCC provides intrinsics to access every instruction of the TILEPro
17168processor. The intrinsics are of the form:
17169
17170@smallexample
17171
17172unsigned __insn_@var{op} (...)
17173
17174@end smallexample
17175
c513ecbf
SL
17176@noindent
17177where @var{op} is the name of the instruction. Refer to the ISA manual
dd552284
WL
17178for the complete list of instructions.
17179
17180GCC also provides intrinsics to directly access the network registers.
17181The intrinsics are:
17182
17183@smallexample
17184
17185unsigned __tile_idn0_receive (void)
17186unsigned __tile_idn1_receive (void)
17187unsigned __tile_sn_receive (void)
17188unsigned __tile_udn0_receive (void)
17189unsigned __tile_udn1_receive (void)
17190unsigned __tile_udn2_receive (void)
17191unsigned __tile_udn3_receive (void)
17192void __tile_idn_send (unsigned)
17193void __tile_sn_send (unsigned)
17194void __tile_udn_send (unsigned)
17195
17196@end smallexample
17197
17198The intrinsic @code{void __tile_network_barrier (void)} is used to
358a3dbc 17199guarantee that no network operations before it are reordered with
dd552284
WL
17200those after it.
17201
a2bec818
DJ
17202@node Target Format Checks
17203@section Format Checks Specific to Particular Target Machines
17204
17205For some target machines, GCC supports additional options to the
17206format attribute
17207(@pxref{Function Attributes,,Declaring Attributes of Functions}).
17208
17209@menu
17210* Solaris Format Checks::
91ebb981 17211* Darwin Format Checks::
a2bec818
DJ
17212@end menu
17213
17214@node Solaris Format Checks
17215@subsection Solaris Format Checks
17216
17217Solaris targets support the @code{cmn_err} (or @code{__cmn_err__}) format
17218check. @code{cmn_err} accepts a subset of the standard @code{printf}
17219conversions, and the two-argument @code{%b} conversion for displaying
17220bit-fields. See the Solaris man page for @code{cmn_err} for more information.
17221
91ebb981
IS
17222@node Darwin Format Checks
17223@subsection Darwin Format Checks
17224
ff2ce160 17225Darwin targets support the @code{CFString} (or @code{__CFString__}) in the format
358a3dbc 17226attribute context. Declarations made with such attribution are parsed for correct syntax
91ebb981 17227and format argument types. However, parsing of the format string itself is currently undefined
358a3dbc 17228and is not carried out by this version of the compiler.
91ebb981
IS
17229
17230Additionally, @code{CFStringRefs} (defined by the @code{CoreFoundation} headers) may
17231also be used as format arguments. Note that the relevant headers are only likely to be
17232available on Darwin (OSX) installations. On such installations, the XCode and system
17233documentation provide descriptions of @code{CFString}, @code{CFStringRefs} and
17234associated functions.
17235
0168a849
SS
17236@node Pragmas
17237@section Pragmas Accepted by GCC
17238@cindex pragmas
ab940b73 17239@cindex @code{#pragma}
0168a849
SS
17240
17241GCC supports several types of pragmas, primarily in order to compile
17242code originally written for other compilers. Note that in general
17243we do not recommend the use of pragmas; @xref{Function Attributes},
17244for further explanation.
17245
17246@menu
17247* ARM Pragmas::
38b2d076 17248* M32C Pragmas::
e2491744 17249* MeP Pragmas::
a5c76ee6 17250* RS/6000 and PowerPC Pragmas::
0168a849 17251* Darwin Pragmas::
07a43492 17252* Solaris Pragmas::
84b8b0e0 17253* Symbol-Renaming Pragmas::
467cecf3 17254* Structure-Packing Pragmas::
52eb57df 17255* Weak Pragmas::
79cf5994 17256* Diagnostic Pragmas::
b9e75696 17257* Visibility Pragmas::
20cef83a 17258* Push/Pop Macro Pragmas::
ab442df7 17259* Function Specific Option Pragmas::
8170608b 17260* Loop-Specific Pragmas::
0168a849
SS
17261@end menu
17262
17263@node ARM Pragmas
17264@subsection ARM Pragmas
17265
17266The ARM target defines pragmas for controlling the default addition of
17267@code{long_call} and @code{short_call} attributes to functions.
17268@xref{Function Attributes}, for information about the effects of these
17269attributes.
17270
17271@table @code
17272@item long_calls
17273@cindex pragma, long_calls
17274Set all subsequent functions to have the @code{long_call} attribute.
17275
17276@item no_long_calls
17277@cindex pragma, no_long_calls
17278Set all subsequent functions to have the @code{short_call} attribute.
17279
17280@item long_calls_off
17281@cindex pragma, long_calls_off
17282Do not affect the @code{long_call} or @code{short_call} attributes of
17283subsequent functions.
17284@end table
17285
38b2d076
DD
17286@node M32C Pragmas
17287@subsection M32C Pragmas
17288
17289@table @code
f6052f86 17290@item GCC memregs @var{number}
38b2d076 17291@cindex pragma, memregs
bcbc9564 17292Overrides the command-line option @code{-memregs=} for the current
38b2d076
DD
17293file. Use with care! This pragma must be before any function in the
17294file, and mixing different memregs values in different objects may
17295make them incompatible. This pragma is useful when a
17296performance-critical function uses a memreg for temporary values,
17297as it may allow you to reduce the number of memregs used.
17298
f6052f86
DD
17299@item ADDRESS @var{name} @var{address}
17300@cindex pragma, address
17301For any declared symbols matching @var{name}, this does three things
17302to that symbol: it forces the symbol to be located at the given
17303address (a number), it forces the symbol to be volatile, and it
17304changes the symbol's scope to be static. This pragma exists for
17305compatibility with other compilers, but note that the common
17306@code{1234H} numeric syntax is not supported (use @code{0x1234}
17307instead). Example:
17308
c513ecbf 17309@smallexample
f6052f86
DD
17310#pragma ADDRESS port3 0x103
17311char port3;
c513ecbf 17312@end smallexample
f6052f86 17313
38b2d076
DD
17314@end table
17315
e2491744
DD
17316@node MeP Pragmas
17317@subsection MeP Pragmas
17318
17319@table @code
17320
17321@item custom io_volatile (on|off)
17322@cindex pragma, custom io_volatile
566fb011 17323Overrides the command-line option @code{-mio-volatile} for the current
e2491744
DD
17324file. Note that for compatibility with future GCC releases, this
17325option should only be used once before any @code{io} variables in each
17326file.
17327
17328@item GCC coprocessor available @var{registers}
17329@cindex pragma, coprocessor available
17330Specifies which coprocessor registers are available to the register
17331allocator. @var{registers} may be a single register, register range
17332separated by ellipses, or comma-separated list of those. Example:
17333
c513ecbf 17334@smallexample
e2491744 17335#pragma GCC coprocessor available $c0...$c10, $c28
c513ecbf 17336@end smallexample
e2491744
DD
17337
17338@item GCC coprocessor call_saved @var{registers}
17339@cindex pragma, coprocessor call_saved
17340Specifies which coprocessor registers are to be saved and restored by
17341any function using them. @var{registers} may be a single register,
17342register range separated by ellipses, or comma-separated list of
17343those. Example:
17344
c513ecbf 17345@smallexample
e2491744 17346#pragma GCC coprocessor call_saved $c4...$c6, $c31
c513ecbf 17347@end smallexample
e2491744
DD
17348
17349@item GCC coprocessor subclass '(A|B|C|D)' = @var{registers}
17350@cindex pragma, coprocessor subclass
17351Creates and defines a register class. These register classes can be
17352used by inline @code{asm} constructs. @var{registers} may be a single
17353register, register range separated by ellipses, or comma-separated
17354list of those. Example:
17355
c513ecbf 17356@smallexample
e2491744
DD
17357#pragma GCC coprocessor subclass 'B' = $c2, $c4, $c6
17358
17359asm ("cpfoo %0" : "=B" (x));
c513ecbf 17360@end smallexample
e2491744
DD
17361
17362@item GCC disinterrupt @var{name} , @var{name} @dots{}
17363@cindex pragma, disinterrupt
17364For the named functions, the compiler adds code to disable interrupts
c417597c
SL
17365for the duration of those functions. If any functions so named
17366are not encountered in the source, a warning is emitted that the pragma is
e2491744
DD
17367not used. Examples:
17368
c513ecbf 17369@smallexample
e2491744
DD
17370#pragma disinterrupt foo
17371#pragma disinterrupt bar, grill
ddaa3488 17372int foo () @{ @dots{} @}
c513ecbf 17373@end smallexample
e2491744
DD
17374
17375@item GCC call @var{name} , @var{name} @dots{}
17376@cindex pragma, call
17377For the named functions, the compiler always uses a register-indirect
17378call model when calling the named functions. Examples:
17379
c513ecbf 17380@smallexample
e2491744
DD
17381extern int foo ();
17382#pragma call foo
c513ecbf 17383@end smallexample
e2491744
DD
17384
17385@end table
17386
a5c76ee6
ZW
17387@node RS/6000 and PowerPC Pragmas
17388@subsection RS/6000 and PowerPC Pragmas
17389
17390The RS/6000 and PowerPC targets define one pragma for controlling
17391whether or not the @code{longcall} attribute is added to function
17392declarations by default. This pragma overrides the @option{-mlongcall}
95b1627e 17393option, but not the @code{longcall} and @code{shortcall} attributes.
a5c76ee6
ZW
17394@xref{RS/6000 and PowerPC Options}, for more information about when long
17395calls are and are not necessary.
17396
17397@table @code
17398@item longcall (1)
17399@cindex pragma, longcall
17400Apply the @code{longcall} attribute to all subsequent function
17401declarations.
17402
17403@item longcall (0)
17404Do not apply the @code{longcall} attribute to subsequent function
17405declarations.
17406@end table
17407
0168a849 17408@c Describe h8300 pragmas here.
0168a849
SS
17409@c Describe sh pragmas here.
17410@c Describe v850 pragmas here.
17411
17412@node Darwin Pragmas
17413@subsection Darwin Pragmas
17414
17415The following pragmas are available for all architectures running the
17416Darwin operating system. These are useful for compatibility with other
85ebf0c6 17417Mac OS compilers.
0168a849
SS
17418
17419@table @code
17420@item mark @var{tokens}@dots{}
17421@cindex pragma, mark
17422This pragma is accepted, but has no effect.
17423
17424@item options align=@var{alignment}
17425@cindex pragma, options align
17426This pragma sets the alignment of fields in structures. The values of
17427@var{alignment} may be @code{mac68k}, to emulate m68k alignment, or
17428@code{power}, to emulate PowerPC alignment. Uses of this pragma nest
17429properly; to restore the previous setting, use @code{reset} for the
17430@var{alignment}.
17431
17432@item segment @var{tokens}@dots{}
17433@cindex pragma, segment
17434This pragma is accepted, but has no effect.
17435
17436@item unused (@var{var} [, @var{var}]@dots{})
17437@cindex pragma, unused
358a3dbc 17438This pragma declares variables to be possibly unused. GCC does not
0168a849
SS
17439produce warnings for the listed variables. The effect is similar to
17440that of the @code{unused} attribute, except that this pragma may appear
17441anywhere within the variables' scopes.
17442@end table
17443
07a43492
DJ
17444@node Solaris Pragmas
17445@subsection Solaris Pragmas
17446
17447The Solaris target supports @code{#pragma redefine_extname}
17448(@pxref{Symbol-Renaming Pragmas}). It also supports additional
17449@code{#pragma} directives for compatibility with the system compiler.
17450
17451@table @code
17452@item align @var{alignment} (@var{variable} [, @var{variable}]...)
17453@cindex pragma, align
17454
17455Increase the minimum alignment of each @var{variable} to @var{alignment}.
17456This is the same as GCC's @code{aligned} attribute @pxref{Variable
b5b3e36a 17457Attributes}). Macro expansion occurs on the arguments to this pragma
0ee2ea09 17458when compiling C and Objective-C@. It does not currently occur when
b5b3e36a
DJ
17459compiling C++, but this is a bug which may be fixed in a future
17460release.
07a43492
DJ
17461
17462@item fini (@var{function} [, @var{function}]...)
17463@cindex pragma, fini
17464
17465This pragma causes each listed @var{function} to be called after
17466main, or during shared module unloading, by adding a call to the
17467@code{.fini} section.
17468
17469@item init (@var{function} [, @var{function}]...)
17470@cindex pragma, init
17471
17472This pragma causes each listed @var{function} to be called during
17473initialization (before @code{main}) or during shared module loading, by
17474adding a call to the @code{.init} section.
17475
17476@end table
17477
84b8b0e0
ZW
17478@node Symbol-Renaming Pragmas
17479@subsection Symbol-Renaming Pragmas
41c64394 17480
f95c6a78
DW
17481GCC supports a @code{#pragma} directive that changes the name used in
17482assembly for a given declaration. This effect can also be achieved
17483using the asm labels extension (@pxref{Asm Labels}).
41c64394
RH
17484
17485@table @code
17486@item redefine_extname @var{oldname} @var{newname}
17487@cindex pragma, redefine_extname
17488
84b8b0e0
ZW
17489This pragma gives the C function @var{oldname} the assembly symbol
17490@var{newname}. The preprocessor macro @code{__PRAGMA_REDEFINE_EXTNAME}
358a3dbc 17491is defined if this pragma is available (currently on all platforms).
41c64394
RH
17492@end table
17493
5c30094f 17494This pragma and the asm labels extension interact in a complicated
f95c6a78 17495manner. Here are some corner cases you may want to be aware of:
84b8b0e0
ZW
17496
17497@enumerate
f95c6a78 17498@item This pragma silently applies only to declarations with external
84b8b0e0
ZW
17499linkage. Asm labels do not have this restriction.
17500
f95c6a78 17501@item In C++, this pragma silently applies only to declarations with
84b8b0e0
ZW
17502``C'' linkage. Again, asm labels do not have this restriction.
17503
f95c6a78
DW
17504@item If either of the ways of changing the assembly name of a
17505declaration are applied to a declaration whose assembly name has
84b8b0e0
ZW
17506already been determined (either by a previous use of one of these
17507features, or because the compiler needed the assembly name in order to
17508generate code), and the new name is different, a warning issues and
17509the name does not change.
17510
17511@item The @var{oldname} used by @code{#pragma redefine_extname} is
17512always the C-language name.
84b8b0e0
ZW
17513@end enumerate
17514
467cecf3
JB
17515@node Structure-Packing Pragmas
17516@subsection Structure-Packing Pragmas
17517
20cef83a 17518For compatibility with Microsoft Windows compilers, GCC supports a
c417597c 17519set of @code{#pragma} directives that change the maximum alignment of
40cbe8d2 17520members of structures (other than zero-width bit-fields), unions, and
20cef83a
DS
17521classes subsequently defined. The @var{n} value below always is required
17522to be a small power of two and specifies the new alignment in bytes.
467cecf3
JB
17523
17524@enumerate
17525@item @code{#pragma pack(@var{n})} simply sets the new alignment.
17526@item @code{#pragma pack()} sets the alignment to the one that was in
bcbc9564 17527effect when compilation started (see also command-line option
917e11d7 17528@option{-fpack-struct[=@var{n}]} @pxref{Code Gen Options}).
467cecf3
JB
17529@item @code{#pragma pack(push[,@var{n}])} pushes the current alignment
17530setting on an internal stack and then optionally sets the new alignment.
17531@item @code{#pragma pack(pop)} restores the alignment setting to the one
17532saved at the top of the internal stack (and removes that stack entry).
17533Note that @code{#pragma pack([@var{n}])} does not influence this internal
17534stack; thus it is possible to have @code{#pragma pack(push)} followed by
17535multiple @code{#pragma pack(@var{n})} instances and finalized by a single
17536@code{#pragma pack(pop)}.
17537@end enumerate
17538
566fb011 17539Some targets, e.g.@: i386 and PowerPC, support the @code{ms_struct}
6bb7beac
EC
17540@code{#pragma} which lays out a structure as the documented
17541@code{__attribute__ ((ms_struct))}.
17542@enumerate
17543@item @code{#pragma ms_struct on} turns on the layout for structures
17544declared.
17545@item @code{#pragma ms_struct off} turns off the layout for structures
17546declared.
17547@item @code{#pragma ms_struct reset} goes back to the default layout.
17548@end enumerate
17549
52eb57df
RH
17550@node Weak Pragmas
17551@subsection Weak Pragmas
17552
17553For compatibility with SVR4, GCC supports a set of @code{#pragma}
17554directives for declaring symbols to be weak, and defining weak
17555aliases.
17556
17557@table @code
17558@item #pragma weak @var{symbol}
17559@cindex pragma, weak
17560This pragma declares @var{symbol} to be weak, as if the declaration
17561had the attribute of the same name. The pragma may appear before
e8ba94fc 17562or after the declaration of @var{symbol}. It is not an error for
52eb57df
RH
17563@var{symbol} to never be defined at all.
17564
17565@item #pragma weak @var{symbol1} = @var{symbol2}
17566This pragma declares @var{symbol1} to be a weak alias of @var{symbol2}.
17567It is an error if @var{symbol2} is not defined in the current
17568translation unit.
17569@end table
17570
79cf5994
DD
17571@node Diagnostic Pragmas
17572@subsection Diagnostic Pragmas
17573
17574GCC allows the user to selectively enable or disable certain types of
17575diagnostics, and change the kind of the diagnostic. For example, a
17576project's policy might require that all sources compile with
17577@option{-Werror} but certain files might have exceptions allowing
17578specific types of warnings. Or, a project might selectively enable
17579diagnostics and treat them as errors depending on which preprocessor
17580macros are defined.
17581
17582@table @code
17583@item #pragma GCC diagnostic @var{kind} @var{option}
17584@cindex pragma, diagnostic
17585
17586Modifies the disposition of a diagnostic. Note that not all
1eaf20ec 17587diagnostics are modifiable; at the moment only warnings (normally
923158be 17588controlled by @samp{-W@dots{}}) can be controlled, and not all of them.
79cf5994
DD
17589Use @option{-fdiagnostics-show-option} to determine which diagnostics
17590are controllable and which option controls them.
17591
17592@var{kind} is @samp{error} to treat this diagnostic as an error,
17593@samp{warning} to treat it like a warning (even if @option{-Werror} is
17594in effect), or @samp{ignored} if the diagnostic is to be ignored.
c417597c 17595@var{option} is a double quoted string that matches the command-line
79cf5994
DD
17596option.
17597
c513ecbf 17598@smallexample
79cf5994 17599#pragma GCC diagnostic warning "-Wformat"
c116cd05
MLI
17600#pragma GCC diagnostic error "-Wformat"
17601#pragma GCC diagnostic ignored "-Wformat"
c513ecbf 17602@end smallexample
79cf5994 17603
cd7fe53b
DD
17604Note that these pragmas override any command-line options. GCC keeps
17605track of the location of each pragma, and issues diagnostics according
17606to the state as of that point in the source file. Thus, pragmas occurring
17607after a line do not affect diagnostics caused by that line.
17608
17609@item #pragma GCC diagnostic push
17610@itemx #pragma GCC diagnostic pop
17611
17612Causes GCC to remember the state of the diagnostics as of each
17613@code{push}, and restore to that point at each @code{pop}. If a
566fb011 17614@code{pop} has no matching @code{push}, the command-line options are
cd7fe53b
DD
17615restored.
17616
c513ecbf 17617@smallexample
cd7fe53b 17618#pragma GCC diagnostic error "-Wuninitialized"
c513ecbf 17619 foo(a); /* error is given for this one */
cd7fe53b
DD
17620#pragma GCC diagnostic push
17621#pragma GCC diagnostic ignored "-Wuninitialized"
c513ecbf 17622 foo(b); /* no diagnostic for this one */
cd7fe53b 17623#pragma GCC diagnostic pop
c513ecbf 17624 foo(c); /* error is given for this one */
cd7fe53b 17625#pragma GCC diagnostic pop
c513ecbf
SL
17626 foo(d); /* depends on command-line options */
17627@end smallexample
79cf5994
DD
17628
17629@end table
17630
0d48657d
SB
17631GCC also offers a simple mechanism for printing messages during
17632compilation.
17633
17634@table @code
17635@item #pragma message @var{string}
17636@cindex pragma, diagnostic
17637
17638Prints @var{string} as a compiler message on compilation. The message
17639is informational only, and is neither a compilation warning nor an error.
17640
17641@smallexample
17642#pragma message "Compiling " __FILE__ "..."
17643@end smallexample
17644
17645@var{string} may be parenthesized, and is printed with location
17646information. For example,
17647
17648@smallexample
17649#define DO_PRAGMA(x) _Pragma (#x)
17650#define TODO(x) DO_PRAGMA(message ("TODO - " #x))
17651
17652TODO(Remember to fix this)
17653@end smallexample
17654
c513ecbf 17655@noindent
0d48657d
SB
17656prints @samp{/tmp/file.c:4: note: #pragma message:
17657TODO - Remember to fix this}.
17658
17659@end table
17660
b9e75696
JM
17661@node Visibility Pragmas
17662@subsection Visibility Pragmas
17663
17664@table @code
17665@item #pragma GCC visibility push(@var{visibility})
17666@itemx #pragma GCC visibility pop
17667@cindex pragma, visibility
17668
17669This pragma allows the user to set the visibility for multiple
17670declarations without having to give each a visibility attribute
8e90f610 17671(@pxref{Function Attributes}).
b9e75696
JM
17672
17673In C++, @samp{#pragma GCC visibility} affects only namespace-scope
17674declarations. Class members and template specializations are not
17675affected; if you want to override the visibility for a particular
17676member or instantiation, you must use an attribute.
17677
17678@end table
17679
20cef83a
DS
17680
17681@node Push/Pop Macro Pragmas
17682@subsection Push/Pop Macro Pragmas
17683
17684For compatibility with Microsoft Windows compilers, GCC supports
17685@samp{#pragma push_macro(@var{"macro_name"})}
17686and @samp{#pragma pop_macro(@var{"macro_name"})}.
17687
17688@table @code
17689@item #pragma push_macro(@var{"macro_name"})
17690@cindex pragma, push_macro
17691This pragma saves the value of the macro named as @var{macro_name} to
17692the top of the stack for this macro.
17693
17694@item #pragma pop_macro(@var{"macro_name"})
17695@cindex pragma, pop_macro
17696This pragma sets the value of the macro named as @var{macro_name} to
17697the value on top of the stack for this macro. If the stack for
17698@var{macro_name} is empty, the value of the macro remains unchanged.
17699@end table
17700
17701For example:
17702
17703@smallexample
17704#define X 1
17705#pragma push_macro("X")
17706#undef X
17707#define X -1
17708#pragma pop_macro("X")
ff2ce160 17709int x [X];
20cef83a
DS
17710@end smallexample
17711
c513ecbf 17712@noindent
20cef83a
DS
17713In this example, the definition of X as 1 is saved by @code{#pragma
17714push_macro} and restored by @code{#pragma pop_macro}.
17715
ab442df7
MM
17716@node Function Specific Option Pragmas
17717@subsection Function Specific Option Pragmas
17718
17719@table @code
5779e713
MM
17720@item #pragma GCC target (@var{"string"}...)
17721@cindex pragma GCC target
ab442df7
MM
17722
17723This pragma allows you to set target specific options for functions
17724defined later in the source file. One or more strings can be
358a3dbc 17725specified. Each function that is defined after this point is as
5779e713 17726if @code{attribute((target("STRING")))} was specified for that
ab442df7
MM
17727function. The parenthesis around the options is optional.
17728@xref{Function Attributes}, for more information about the
5779e713 17729@code{target} attribute and the attribute syntax.
ab442df7 17730
e430824f
CLT
17731The @code{#pragma GCC target} pragma is presently implemented for
17732i386/x86_64, PowerPC, and Nios II targets only.
ab442df7
MM
17733@end table
17734
ab442df7
MM
17735@table @code
17736@item #pragma GCC optimize (@var{"string"}...)
17737@cindex pragma GCC optimize
17738
17739This pragma allows you to set global optimization options for functions
17740defined later in the source file. One or more strings can be
358a3dbc 17741specified. Each function that is defined after this point is as
ab442df7
MM
17742if @code{attribute((optimize("STRING")))} was specified for that
17743function. The parenthesis around the options is optional.
17744@xref{Function Attributes}, for more information about the
17745@code{optimize} attribute and the attribute syntax.
17746
17747The @samp{#pragma GCC optimize} pragma is not implemented in GCC
17748versions earlier than 4.4.
17749@end table
17750
17751@table @code
5779e713
MM
17752@item #pragma GCC push_options
17753@itemx #pragma GCC pop_options
17754@cindex pragma GCC push_options
17755@cindex pragma GCC pop_options
17756
17757These pragmas maintain a stack of the current target and optimization
17758options. It is intended for include files where you temporarily want
17759to switch to using a different @samp{#pragma GCC target} or
17760@samp{#pragma GCC optimize} and then to pop back to the previous
17761options.
17762
17763The @samp{#pragma GCC push_options} and @samp{#pragma GCC pop_options}
17764pragmas are not implemented in GCC versions earlier than 4.4.
ab442df7
MM
17765@end table
17766
17767@table @code
5779e713
MM
17768@item #pragma GCC reset_options
17769@cindex pragma GCC reset_options
ab442df7 17770
5779e713
MM
17771This pragma clears the current @code{#pragma GCC target} and
17772@code{#pragma GCC optimize} to use the default switches as specified
17773on the command line.
17774
17775The @samp{#pragma GCC reset_options} pragma is not implemented in GCC
17776versions earlier than 4.4.
ab442df7
MM
17777@end table
17778
8170608b
TB
17779@node Loop-Specific Pragmas
17780@subsection Loop-Specific Pragmas
17781
17782@table @code
17783@item #pragma GCC ivdep
17784@cindex pragma GCC ivdep
17785@end table
17786
17787With this pragma, the programmer asserts that there are no loop-carried
17788dependencies which would prevent that consecutive iterations of
17789the following loop can be executed concurrently with SIMD
17790(single instruction multiple data) instructions.
17791
17792For example, the compiler can only unconditionally vectorize the following
17793loop with the pragma:
17794
17795@smallexample
17796void foo (int n, int *a, int *b, int *c)
17797@{
17798 int i, j;
17799#pragma GCC ivdep
17800 for (i = 0; i < n; ++i)
17801 a[i] = b[i] + c[i];
17802@}
17803@end smallexample
17804
17805@noindent
17806In this example, using the @code{restrict} qualifier had the same
17807effect. In the following example, that would not be possible. Assume
17808@math{k < -m} or @math{k >= m}. Only with the pragma, the compiler knows
17809that it can unconditionally vectorize the following loop:
17810
17811@smallexample
17812void ignore_vec_dep (int *a, int k, int c, int m)
17813@{
17814#pragma GCC ivdep
17815 for (int i = 0; i < m; i++)
17816 a[i] = a[i + k] * c;
17817@}
17818@end smallexample
17819
17820
3e96a2fd 17821@node Unnamed Fields
2fbebc71 17822@section Unnamed struct/union fields within structs/unions
ab940b73
RW
17823@cindex @code{struct}
17824@cindex @code{union}
3e96a2fd 17825
48b0b196 17826As permitted by ISO C11 and for compatibility with other compilers,
4bdd0a60 17827GCC allows you to define
3e96a2fd
DD
17828a structure or union that contains, as fields, structures and unions
17829without names. For example:
17830
3ab51846 17831@smallexample
3e96a2fd
DD
17832struct @{
17833 int a;
17834 union @{
17835 int b;
17836 float c;
17837 @};
17838 int d;
17839@} foo;
3ab51846 17840@end smallexample
3e96a2fd 17841
c513ecbf 17842@noindent
358a3dbc 17843In this example, you are able to access members of the unnamed
3e96a2fd
DD
17844union with code like @samp{foo.b}. Note that only unnamed structs and
17845unions are allowed, you may not have, for example, an unnamed
17846@code{int}.
17847
17848You must never create such structures that cause ambiguous field definitions.
c513ecbf 17849For example, in this structure:
3e96a2fd 17850
3ab51846 17851@smallexample
3e96a2fd
DD
17852struct @{
17853 int a;
17854 struct @{
17855 int a;
17856 @};
17857@} foo;
3ab51846 17858@end smallexample
3e96a2fd 17859
c513ecbf
SL
17860@noindent
17861it is ambiguous which @code{a} is being referred to with @samp{foo.a}.
492fc0ee 17862The compiler gives errors for such constructs.
3e96a2fd 17863
2fbebc71
JM
17864@opindex fms-extensions
17865Unless @option{-fms-extensions} is used, the unnamed field must be a
17866structure or union definition without a tag (for example, @samp{struct
ff8e2159 17867@{ int a; @};}). If @option{-fms-extensions} is used, the field may
2fbebc71
JM
17868also be a definition with a tag such as @samp{struct foo @{ int a;
17869@};}, a reference to a previously defined structure or union such as
17870@samp{struct foo;}, or a reference to a @code{typedef} name for a
ff8e2159 17871previously defined structure or union type.
2fbebc71 17872
478a1c5b
ILT
17873@opindex fplan9-extensions
17874The option @option{-fplan9-extensions} enables
17875@option{-fms-extensions} as well as two other extensions. First, a
17876pointer to a structure is automatically converted to a pointer to an
17877anonymous field for assignments and function calls. For example:
17878
17879@smallexample
17880struct s1 @{ int a; @};
17881struct s2 @{ struct s1; @};
17882extern void f1 (struct s1 *);
17883void f2 (struct s2 *p) @{ f1 (p); @}
17884@end smallexample
17885
c513ecbf 17886@noindent
478a1c5b
ILT
17887In the call to @code{f1} inside @code{f2}, the pointer @code{p} is
17888converted into a pointer to the anonymous field.
17889
17890Second, when the type of an anonymous field is a @code{typedef} for a
17891@code{struct} or @code{union}, code may refer to the field using the
17892name of the @code{typedef}.
17893
17894@smallexample
17895typedef struct @{ int a; @} s1;
17896struct s2 @{ s1; @};
17897s1 f1 (struct s2 *p) @{ return p->s1; @}
17898@end smallexample
17899
17900These usages are only permitted when they are not ambiguous.
17901
3d78f2e9
RH
17902@node Thread-Local
17903@section Thread-Local Storage
17904@cindex Thread-Local Storage
9217ef40 17905@cindex @acronym{TLS}
ab940b73 17906@cindex @code{__thread}
3d78f2e9 17907
9217ef40
RH
17908Thread-local storage (@acronym{TLS}) is a mechanism by which variables
17909are allocated such that there is one instance of the variable per extant
566fb011 17910thread. The runtime model GCC uses to implement this originates
3d78f2e9
RH
17911in the IA-64 processor-specific ABI, but has since been migrated
17912to other processors as well. It requires significant support from
17913the linker (@command{ld}), dynamic linker (@command{ld.so}), and
17914system libraries (@file{libc.so} and @file{libpthread.so}), so it
9217ef40 17915is not available everywhere.
3d78f2e9
RH
17916
17917At the user level, the extension is visible with a new storage
17918class keyword: @code{__thread}. For example:
17919
3ab51846 17920@smallexample
3d78f2e9
RH
17921__thread int i;
17922extern __thread struct state s;
17923static __thread char *p;
3ab51846 17924@end smallexample
3d78f2e9
RH
17925
17926The @code{__thread} specifier may be used alone, with the @code{extern}
17927or @code{static} specifiers, but with no other storage class specifier.
17928When used with @code{extern} or @code{static}, @code{__thread} must appear
17929immediately after the other storage class specifier.
17930
17931The @code{__thread} specifier may be applied to any global, file-scoped
244c2241
RH
17932static, function-scoped static, or static data member of a class. It may
17933not be applied to block-scoped automatic or non-static data member.
3d78f2e9
RH
17934
17935When the address-of operator is applied to a thread-local variable, it is
566fb011 17936evaluated at run time and returns the address of the current thread's
3d78f2e9
RH
17937instance of that variable. An address so obtained may be used by any
17938thread. When a thread terminates, any pointers to thread-local variables
17939in that thread become invalid.
17940
17941No static initialization may refer to the address of a thread-local variable.
17942
244c2241
RH
17943In C++, if an initializer is present for a thread-local variable, it must
17944be a @var{constant-expression}, as defined in 5.19.2 of the ANSI/ISO C++
17945standard.
3d78f2e9 17946
419d1d37 17947See @uref{http://www.akkadia.org/drepper/tls.pdf,
3d78f2e9 17948ELF Handling For Thread-Local Storage} for a detailed explanation of
566fb011 17949the four thread-local storage addressing models, and how the runtime
3d78f2e9
RH
17950is expected to function.
17951
9217ef40
RH
17952@menu
17953* C99 Thread-Local Edits::
17954* C++98 Thread-Local Edits::
17955@end menu
17956
17957@node C99 Thread-Local Edits
17958@subsection ISO/IEC 9899:1999 Edits for Thread-Local Storage
17959
17960The following are a set of changes to ISO/IEC 9899:1999 (aka C99)
17961that document the exact semantics of the language extension.
17962
17963@itemize @bullet
17964@item
17965@cite{5.1.2 Execution environments}
17966
17967Add new text after paragraph 1
17968
17969@quotation
17970Within either execution environment, a @dfn{thread} is a flow of
17971control within a program. It is implementation defined whether
17972or not there may be more than one thread associated with a program.
17973It is implementation defined how threads beyond the first are
17974created, the name and type of the function called at thread
17975startup, and how threads may be terminated. However, objects
17976with thread storage duration shall be initialized before thread
17977startup.
17978@end quotation
17979
17980@item
17981@cite{6.2.4 Storage durations of objects}
17982
17983Add new text before paragraph 3
17984
17985@quotation
17986An object whose identifier is declared with the storage-class
17987specifier @w{@code{__thread}} has @dfn{thread storage duration}.
17988Its lifetime is the entire execution of the thread, and its
17989stored value is initialized only once, prior to thread startup.
17990@end quotation
17991
17992@item
17993@cite{6.4.1 Keywords}
17994
17995Add @code{__thread}.
17996
17997@item
17998@cite{6.7.1 Storage-class specifiers}
17999
18000Add @code{__thread} to the list of storage class specifiers in
18001paragraph 1.
18002
18003Change paragraph 2 to
18004
18005@quotation
18006With the exception of @code{__thread}, at most one storage-class
18007specifier may be given [@dots{}]. The @code{__thread} specifier may
18008be used alone, or immediately following @code{extern} or
18009@code{static}.
18010@end quotation
18011
18012Add new text after paragraph 6
18013
18014@quotation
18015The declaration of an identifier for a variable that has
18016block scope that specifies @code{__thread} shall also
18017specify either @code{extern} or @code{static}.
18018
18019The @code{__thread} specifier shall be used only with
18020variables.
18021@end quotation
18022@end itemize
18023
18024@node C++98 Thread-Local Edits
18025@subsection ISO/IEC 14882:1998 Edits for Thread-Local Storage
18026
18027The following are a set of changes to ISO/IEC 14882:1998 (aka C++98)
18028that document the exact semantics of the language extension.
18029
18030@itemize @bullet
8d23a2c8 18031@item
9217ef40
RH
18032@b{[intro.execution]}
18033
18034New text after paragraph 4
18035
18036@quotation
18037A @dfn{thread} is a flow of control within the abstract machine.
18038It is implementation defined whether or not there may be more than
18039one thread.
18040@end quotation
18041
18042New text after paragraph 7
18043
18044@quotation
95b1627e 18045It is unspecified whether additional action must be taken to
9217ef40
RH
18046ensure when and whether side effects are visible to other threads.
18047@end quotation
18048
18049@item
18050@b{[lex.key]}
18051
18052Add @code{__thread}.
18053
18054@item
18055@b{[basic.start.main]}
18056
18057Add after paragraph 5
18058
18059@quotation
18060The thread that begins execution at the @code{main} function is called
95b1627e 18061the @dfn{main thread}. It is implementation defined how functions
9217ef40
RH
18062beginning threads other than the main thread are designated or typed.
18063A function so designated, as well as the @code{main} function, is called
18064a @dfn{thread startup function}. It is implementation defined what
18065happens if a thread startup function returns. It is implementation
18066defined what happens to other threads when any thread calls @code{exit}.
18067@end quotation
18068
18069@item
18070@b{[basic.start.init]}
18071
18072Add after paragraph 4
18073
18074@quotation
18075The storage for an object of thread storage duration shall be
c0478a66 18076statically initialized before the first statement of the thread startup
9217ef40
RH
18077function. An object of thread storage duration shall not require
18078dynamic initialization.
18079@end quotation
18080
18081@item
18082@b{[basic.start.term]}
18083
18084Add after paragraph 3
18085
18086@quotation
244c2241
RH
18087The type of an object with thread storage duration shall not have a
18088non-trivial destructor, nor shall it be an array type whose elements
18089(directly or indirectly) have non-trivial destructors.
9217ef40
RH
18090@end quotation
18091
18092@item
18093@b{[basic.stc]}
18094
18095Add ``thread storage duration'' to the list in paragraph 1.
18096
18097Change paragraph 2
18098
18099@quotation
18100Thread, static, and automatic storage durations are associated with
18101objects introduced by declarations [@dots{}].
18102@end quotation
18103
18104Add @code{__thread} to the list of specifiers in paragraph 3.
18105
18106@item
18107@b{[basic.stc.thread]}
18108
18109New section before @b{[basic.stc.static]}
18110
18111@quotation
63519d23 18112The keyword @code{__thread} applied to a non-local object gives the
9217ef40
RH
18113object thread storage duration.
18114
18115A local variable or class data member declared both @code{static}
18116and @code{__thread} gives the variable or member thread storage
18117duration.
18118@end quotation
18119
18120@item
18121@b{[basic.stc.static]}
18122
18123Change paragraph 1
18124
18125@quotation
c417597c 18126All objects that have neither thread storage duration, dynamic
9217ef40
RH
18127storage duration nor are local [@dots{}].
18128@end quotation
18129
18130@item
18131@b{[dcl.stc]}
18132
18133Add @code{__thread} to the list in paragraph 1.
18134
18135Change paragraph 1
18136
18137@quotation
18138With the exception of @code{__thread}, at most one
18139@var{storage-class-specifier} shall appear in a given
18140@var{decl-specifier-seq}. The @code{__thread} specifier may
18141be used alone, or immediately following the @code{extern} or
18142@code{static} specifiers. [@dots{}]
18143@end quotation
18144
18145Add after paragraph 5
18146
18147@quotation
18148The @code{__thread} specifier can be applied only to the names of objects
18149and to anonymous unions.
18150@end quotation
18151
18152@item
18153@b{[class.mem]}
18154
18155Add after paragraph 6
18156
18157@quotation
18158Non-@code{static} members shall not be @code{__thread}.
18159@end quotation
18160@end itemize
18161
f7fd775f
JW
18162@node Binary constants
18163@section Binary constants using the @samp{0b} prefix
18164@cindex Binary constants using the @samp{0b} prefix
18165
18166Integer constants can be written as binary constants, consisting of a
18167sequence of @samp{0} and @samp{1} digits, prefixed by @samp{0b} or
18168@samp{0B}. This is particularly useful in environments that operate a
6f46cb63 18169lot on the bit level (like microcontrollers).
f7fd775f
JW
18170
18171The following statements are identical:
18172
18173@smallexample
18174i = 42;
18175i = 0x2a;
18176i = 052;
18177i = 0b101010;
18178@end smallexample
18179
18180The type of these constants follows the same rules as for octal or
18181hexadecimal integer constants, so suffixes like @samp{L} or @samp{UL}
18182can be applied.
18183
c1f7febf
RK
18184@node C++ Extensions
18185@chapter Extensions to the C++ Language
18186@cindex extensions, C++ language
18187@cindex C++ language extensions
18188
18189The GNU compiler provides these extensions to the C++ language (and you
18190can also use most of the C language extensions in your C++ programs). If you
18191want to write code that checks whether these features are available, you can
18192test for the GNU compiler the same way as for C programs: check for a
18193predefined macro @code{__GNUC__}. You can also use @code{__GNUG__} to
48795525
GP
18194test specifically for GNU C++ (@pxref{Common Predefined Macros,,
18195Predefined Macros,cpp,The GNU C Preprocessor}).
c1f7febf
RK
18196
18197@menu
8f0fe813 18198* C++ Volatiles:: What constitutes an access to a volatile object.
49419c8f 18199* Restricted Pointers:: C99 restricted pointers and references.
7a81cf7f 18200* Vague Linkage:: Where G++ puts inlines, vtables and such.
c1f7febf 18201* C++ Interface:: You can use a single C++ header file for both
e6f3b89d 18202 declarations and definitions.
c1f7febf 18203* Template Instantiation:: Methods for ensuring that exactly one copy of
e6f3b89d 18204 each needed template instantiation is emitted.
0ded1f18
JM
18205* Bound member functions:: You can extract a function pointer to the
18206 method denoted by a @samp{->*} or @samp{.*} expression.
e6f3b89d 18207* C++ Attributes:: Variable, function, and type attributes for C++ only.
f80e0faf 18208* Function Multiversioning:: Declaring multiple function versions.
664a90c0 18209* Namespace Association:: Strong using-directives for namespace association.
cb68ec50 18210* Type Traits:: Compiler support for type traits
1f730ff7 18211* Java Exceptions:: Tweaking exception handling to work with Java.
566fb011 18212* Deprecated Features:: Things will disappear from G++.
e6f3b89d 18213* Backwards Compatibility:: Compatibilities with earlier definitions of C++.
c1f7febf
RK
18214@end menu
18215
8f0fe813
NS
18216@node C++ Volatiles
18217@section When is a Volatile C++ Object Accessed?
02cac427
NS
18218@cindex accessing volatiles
18219@cindex volatile read
18220@cindex volatile write
18221@cindex volatile access
18222
8f0fe813
NS
18223The C++ standard differs from the C standard in its treatment of
18224volatile objects. It fails to specify what constitutes a volatile
18225access, except to say that C++ should behave in a similar manner to C
18226with respect to volatiles, where possible. However, the different
c4c8962b 18227lvalueness of expressions between C and C++ complicate the behavior.
8f0fe813 18228G++ behaves the same as GCC for volatile access, @xref{C
c4c8962b 18229Extensions,,Volatiles}, for a description of GCC's behavior.
02cac427 18230
8f0fe813
NS
18231The C and C++ language specifications differ when an object is
18232accessed in a void context:
02cac427 18233
3ab51846 18234@smallexample
c771326b 18235volatile int *src = @var{somevalue};
02cac427 18236*src;
3ab51846 18237@end smallexample
02cac427 18238
8f0fe813
NS
18239The C++ standard specifies that such expressions do not undergo lvalue
18240to rvalue conversion, and that the type of the dereferenced object may
18241be incomplete. The C++ standard does not specify explicitly that it
c417597c 18242is lvalue to rvalue conversion that is responsible for causing an
8f0fe813
NS
18243access. There is reason to believe that it is, because otherwise
18244certain simple expressions become undefined. However, because it
18245would surprise most programmers, G++ treats dereferencing a pointer to
18246volatile object of complete type as GCC would do for an equivalent
18247type in C@. When the object has incomplete type, G++ issues a
18248warning; if you wish to force an error, you must force a conversion to
18249rvalue with, for instance, a static cast.
02cac427 18250
f0523f02 18251When using a reference to volatile, G++ does not treat equivalent
02cac427 18252expressions as accesses to volatiles, but instead issues a warning that
767094dd 18253no volatile is accessed. The rationale for this is that otherwise it
02cac427
NS
18254becomes difficult to determine where volatile access occur, and not
18255possible to ignore the return value from functions returning volatile
767094dd 18256references. Again, if you wish to force a read, cast the reference to
02cac427
NS
18257an rvalue.
18258
c4c8962b 18259G++ implements the same behavior as GCC does when assigning to a
566fb011 18260volatile object---there is no reread of the assigned-to object, the
8f0fe813 18261assigned rvalue is reused. Note that in C++ assignment expressions
358a3dbc
SL
18262are lvalues, and if used as an lvalue, the volatile object is
18263referred to. For instance, @var{vref} refers to @var{vobj}, as
8f0fe813
NS
18264expected, in the following example:
18265
18266@smallexample
18267volatile int vobj;
18268volatile int &vref = vobj = @var{something};
18269@end smallexample
18270
535233a8
NS
18271@node Restricted Pointers
18272@section Restricting Pointer Aliasing
18273@cindex restricted pointers
18274@cindex restricted references
18275@cindex restricted this pointer
18276
2dd76960 18277As with the C front end, G++ understands the C99 feature of restricted pointers,
535233a8 18278specified with the @code{__restrict__}, or @code{__restrict} type
767094dd 18279qualifier. Because you cannot compile C++ by specifying the @option{-std=c99}
535233a8
NS
18280language flag, @code{restrict} is not a keyword in C++.
18281
18282In addition to allowing restricted pointers, you can specify restricted
18283references, which indicate that the reference is not aliased in the local
18284context.
18285
3ab51846 18286@smallexample
535233a8
NS
18287void fn (int *__restrict__ rptr, int &__restrict__ rref)
18288@{
0d893a63 18289 /* @r{@dots{}} */
535233a8 18290@}
3ab51846 18291@end smallexample
535233a8
NS
18292
18293@noindent
18294In the body of @code{fn}, @var{rptr} points to an unaliased integer and
18295@var{rref} refers to a (different) unaliased integer.
18296
18297You may also specify whether a member function's @var{this} pointer is
18298unaliased by using @code{__restrict__} as a member function qualifier.
18299
3ab51846 18300@smallexample
535233a8
NS
18301void T::fn () __restrict__
18302@{
0d893a63 18303 /* @r{@dots{}} */
535233a8 18304@}
3ab51846 18305@end smallexample
535233a8
NS
18306
18307@noindent
358a3dbc 18308Within the body of @code{T::fn}, @var{this} has the effective
767094dd 18309definition @code{T *__restrict__ const this}. Notice that the
535233a8
NS
18310interpretation of a @code{__restrict__} member function qualifier is
18311different to that of @code{const} or @code{volatile} qualifier, in that it
767094dd 18312is applied to the pointer rather than the object. This is consistent with
c417597c 18313other compilers that implement restricted pointers.
535233a8
NS
18314
18315As with all outermost parameter qualifiers, @code{__restrict__} is
767094dd 18316ignored in function definition matching. This means you only need to
535233a8
NS
18317specify @code{__restrict__} in a function definition, rather than
18318in a function prototype as well.
18319
7a81cf7f
JM
18320@node Vague Linkage
18321@section Vague Linkage
18322@cindex vague linkage
18323
c417597c 18324There are several constructs in C++ that require space in the object
7a81cf7f
JM
18325file but are not clearly tied to a single translation unit. We say that
18326these constructs have ``vague linkage''. Typically such constructs are
18327emitted wherever they are needed, though sometimes we can be more
18328clever.
18329
18330@table @asis
18331@item Inline Functions
18332Inline functions are typically defined in a header file which can be
18333included in many different compilations. Hopefully they can usually be
18334inlined, but sometimes an out-of-line copy is necessary, if the address
18335of the function is taken or if inlining fails. In general, we emit an
18336out-of-line copy in all translation units where one is needed. As an
18337exception, we only emit inline virtual functions with the vtable, since
358a3dbc 18338it always requires a copy.
7a81cf7f
JM
18339
18340Local static variables and string constants used in an inline function
18341are also considered to have vague linkage, since they must be shared
18342between all inlined and out-of-line instances of the function.
18343
18344@item VTables
18345@cindex vtable
18346C++ virtual functions are implemented in most compilers using a lookup
18347table, known as a vtable. The vtable contains pointers to the virtual
18348functions provided by a class, and each object of the class contains a
18349pointer to its vtable (or vtables, in some multiple-inheritance
18350situations). If the class declares any non-inline, non-pure virtual
18351functions, the first one is chosen as the ``key method'' for the class,
18352and the vtable is only emitted in the translation unit where the key
18353method is defined.
18354
18355@emph{Note:} If the chosen key method is later defined as inline, the
c417597c 18356vtable is still emitted in every translation unit that defines it.
7a81cf7f
JM
18357Make sure that any inline virtuals are declared inline in the class
18358body, even if they are not defined there.
18359
ab940b73
RW
18360@item @code{type_info} objects
18361@cindex @code{type_info}
7a81cf7f
JM
18362@cindex RTTI
18363C++ requires information about types to be written out in order to
18364implement @samp{dynamic_cast}, @samp{typeid} and exception handling.
ab940b73 18365For polymorphic classes (classes with virtual functions), the @samp{type_info}
7a81cf7f 18366object is written out along with the vtable so that @samp{dynamic_cast}
566fb011 18367can determine the dynamic type of a class object at run time. For all
ab940b73 18368other types, we write out the @samp{type_info} object when it is used: when
7a81cf7f
JM
18369applying @samp{typeid} to an expression, throwing an object, or
18370referring to a type in a catch clause or exception specification.
18371
18372@item Template Instantiations
18373Most everything in this section also applies to template instantiations,
18374but there are other options as well.
18375@xref{Template Instantiation,,Where's the Template?}.
18376
18377@end table
18378
18379When used with GNU ld version 2.8 or later on an ELF system such as
95fef11f 18380GNU/Linux or Solaris 2, or on Microsoft Windows, duplicate copies of
7a81cf7f
JM
18381these constructs will be discarded at link time. This is known as
18382COMDAT support.
18383
18384On targets that don't support COMDAT, but do support weak symbols, GCC
358a3dbc
SL
18385uses them. This way one copy overrides all the others, but
18386the unused copies still take up space in the executable.
7a81cf7f 18387
c417597c 18388For targets that do not support either COMDAT or weak symbols,
358a3dbc
SL
18389most entities with vague linkage are emitted as local symbols to
18390avoid duplicate definition errors from the linker. This does not happen
18391for local statics in inlines, however, as having multiple copies
18392almost certainly breaks things.
7a81cf7f
JM
18393
18394@xref{C++ Interface,,Declarations and Definitions in One Header}, for
18395another way to control placement of these constructs.
18396
c1f7febf 18397@node C++ Interface
fc72b380 18398@section #pragma interface and implementation
c1f7febf
RK
18399
18400@cindex interface and implementation headers, C++
18401@cindex C++ interface and implementation headers
c1f7febf 18402@cindex pragmas, interface and implementation
c1f7febf 18403
fc72b380
JM
18404@code{#pragma interface} and @code{#pragma implementation} provide the
18405user with a way of explicitly directing the compiler to emit entities
18406with vague linkage (and debugging information) in a particular
18407translation unit.
c1f7febf 18408
fc72b380
JM
18409@emph{Note:} As of GCC 2.7.2, these @code{#pragma}s are not useful in
18410most cases, because of COMDAT support and the ``key method'' heuristic
18411mentioned in @ref{Vague Linkage}. Using them can actually cause your
27ef2cdd 18412program to grow due to unnecessary out-of-line copies of inline
fc72b380
JM
18413functions. Currently (3.4) the only benefit of these
18414@code{#pragma}s is reduced duplication of debugging information, and
18415that should be addressed soon on DWARF 2 targets with the use of
18416COMDAT groups.
c1f7febf
RK
18417
18418@table @code
18419@item #pragma interface
18420@itemx #pragma interface "@var{subdir}/@var{objects}.h"
18421@kindex #pragma interface
18422Use this directive in @emph{header files} that define object classes, to save
18423space in most of the object files that use those classes. Normally,
18424local copies of certain information (backup copies of inline member
18425functions, debugging information, and the internal tables that implement
18426virtual functions) must be kept in each object file that includes class
18427definitions. You can use this pragma to avoid such duplication. When a
18428header file containing @samp{#pragma interface} is included in a
358a3dbc 18429compilation, this auxiliary information is not generated (unless
c1f7febf 18430the main input source file itself uses @samp{#pragma implementation}).
358a3dbc 18431Instead, the object files contain references to be resolved at link
c1f7febf
RK
18432time.
18433
18434The second form of this directive is useful for the case where you have
18435multiple headers with the same name in different directories. If you
18436use this form, you must specify the same string to @samp{#pragma
18437implementation}.
18438
18439@item #pragma implementation
18440@itemx #pragma implementation "@var{objects}.h"
18441@kindex #pragma implementation
18442Use this pragma in a @emph{main input file}, when you want full output from
18443included header files to be generated (and made globally visible). The
18444included header file, in turn, should use @samp{#pragma interface}.
18445Backup copies of inline member functions, debugging information, and the
18446internal tables used to implement virtual functions are all generated in
18447implementation files.
18448
18449@cindex implied @code{#pragma implementation}
18450@cindex @code{#pragma implementation}, implied
18451@cindex naming convention, implementation headers
18452If you use @samp{#pragma implementation} with no argument, it applies to
18453an include file with the same basename@footnote{A file's @dfn{basename}
358a3dbc 18454is the name stripped of all leading path information and of trailing
c1f7febf
RK
18455suffixes, such as @samp{.h} or @samp{.C} or @samp{.cc}.} as your source
18456file. For example, in @file{allclass.cc}, giving just
18457@samp{#pragma implementation}
18458by itself is equivalent to @samp{#pragma implementation "allclass.h"}.
18459
18460In versions of GNU C++ prior to 2.6.0 @file{allclass.h} was treated as
18461an implementation file whenever you would include it from
18462@file{allclass.cc} even if you never specified @samp{#pragma
18463implementation}. This was deemed to be more trouble than it was worth,
18464however, and disabled.
18465
c1f7febf
RK
18466Use the string argument if you want a single implementation file to
18467include code from multiple header files. (You must also use
18468@samp{#include} to include the header file; @samp{#pragma
18469implementation} only specifies how to use the file---it doesn't actually
18470include it.)
18471
18472There is no way to split up the contents of a single header file into
18473multiple implementation files.
18474@end table
18475
18476@cindex inlining and C++ pragmas
18477@cindex C++ pragmas, effect on inlining
18478@cindex pragmas in C++, effect on inlining
18479@samp{#pragma implementation} and @samp{#pragma interface} also have an
18480effect on function inlining.
18481
18482If you define a class in a header file marked with @samp{#pragma
fc72b380
JM
18483interface}, the effect on an inline function defined in that class is
18484similar to an explicit @code{extern} declaration---the compiler emits
18485no code at all to define an independent version of the function. Its
18486definition is used only for inlining with its callers.
c1f7febf 18487
84330467 18488@opindex fno-implement-inlines
c1f7febf
RK
18489Conversely, when you include the same header file in a main source file
18490that declares it as @samp{#pragma implementation}, the compiler emits
18491code for the function itself; this defines a version of the function
18492that can be found via pointers (or by callers compiled without
18493inlining). If all calls to the function can be inlined, you can avoid
84330467 18494emitting the function by compiling with @option{-fno-implement-inlines}.
358a3dbc 18495If any calls are not inlined, you will get linker errors.
c1f7febf
RK
18496
18497@node Template Instantiation
18498@section Where's the Template?
c1f7febf
RK
18499@cindex template instantiation
18500
18501C++ templates are the first language feature to require more
18502intelligence from the environment than one usually finds on a UNIX
18503system. Somehow the compiler and linker have to make sure that each
18504template instance occurs exactly once in the executable if it is needed,
18505and not at all otherwise. There are two basic approaches to this
962e6e00 18506problem, which are referred to as the Borland model and the Cfront model.
c1f7febf
RK
18507
18508@table @asis
18509@item Borland model
18510Borland C++ solved the template instantiation problem by adding the code
469b759e
JM
18511equivalent of common blocks to their linker; the compiler emits template
18512instances in each translation unit that uses them, and the linker
18513collapses them together. The advantage of this model is that the linker
18514only has to consider the object files themselves; there is no external
18515complexity to worry about. This disadvantage is that compilation time
18516is increased because the template code is being compiled repeatedly.
18517Code written for this model tends to include definitions of all
18518templates in the header file, since they must be seen to be
18519instantiated.
c1f7febf
RK
18520
18521@item Cfront model
18522The AT&T C++ translator, Cfront, solved the template instantiation
18523problem by creating the notion of a template repository, an
469b759e
JM
18524automatically maintained place where template instances are stored. A
18525more modern version of the repository works as follows: As individual
18526object files are built, the compiler places any template definitions and
18527instantiations encountered in the repository. At link time, the link
18528wrapper adds in the objects in the repository and compiles any needed
18529instances that were not previously emitted. The advantages of this
18530model are more optimal compilation speed and the ability to use the
18531system linker; to implement the Borland model a compiler vendor also
c1f7febf 18532needs to replace the linker. The disadvantages are vastly increased
469b759e
JM
18533complexity, and thus potential for error; for some code this can be
18534just as transparent, but in practice it can been very difficult to build
c1f7febf 18535multiple programs in one directory and one program in multiple
469b759e
JM
18536directories. Code written for this model tends to separate definitions
18537of non-inline member templates into a separate file, which should be
18538compiled separately.
c1f7febf
RK
18539@end table
18540
469b759e 18541When used with GNU ld version 2.8 or later on an ELF system such as
2dd76960
JM
18542GNU/Linux or Solaris 2, or on Microsoft Windows, G++ supports the
18543Borland model. On other systems, G++ implements neither automatic
a4b3b54a 18544model.
469b759e 18545
513d0519 18546You have the following options for dealing with template instantiations:
c1f7febf
RK
18547
18548@enumerate
d863830b 18549@item
84330467 18550@opindex frepo
358a3dbc
SL
18551Compile your template-using code with @option{-frepo}. The compiler
18552generates files with the extension @samp{.rpo} listing all of the
c417597c 18553template instantiations used in the corresponding object files that
358a3dbc
SL
18554could be instantiated there; the link wrapper, @samp{collect2},
18555then updates the @samp{.rpo} files to tell the compiler where to place
d863830b
JL
18556those instantiations and rebuild any affected object files. The
18557link-time overhead is negligible after the first pass, as the compiler
358a3dbc 18558continues to place the instantiations in the same files.
d863830b
JL
18559
18560This is your best option for application code written for the Borland
358a3dbc
SL
18561model, as it just works. Code written for the Cfront model
18562needs to be modified so that the template definitions are available at
d863830b
JL
18563one or more points of instantiation; usually this is as simple as adding
18564@code{#include <tmethods.cc>} to the end of each template header.
18565
18566For library code, if you want the library to provide all of the template
18567instantiations it needs, just try to link all of its object files
18568together; the link will fail, but cause the instantiations to be
18569generated as a side effect. Be warned, however, that this may cause
18570conflicts if multiple libraries try to provide the same instantiations.
18571For greater control, use explicit instantiation as described in the next
18572option.
18573
c1f7febf 18574@item
84330467
JM
18575@opindex fno-implicit-templates
18576Compile your code with @option{-fno-implicit-templates} to disable the
c1f7febf
RK
18577implicit generation of template instances, and explicitly instantiate
18578all the ones you use. This approach requires more knowledge of exactly
18579which instances you need than do the others, but it's less
18580mysterious and allows greater control. You can scatter the explicit
18581instantiations throughout your program, perhaps putting them in the
18582translation units where the instances are used or the translation units
18583that define the templates themselves; you can put all of the explicit
18584instantiations you need into one big file; or you can create small files
18585like
18586
3ab51846 18587@smallexample
c1f7febf
RK
18588#include "Foo.h"
18589#include "Foo.cc"
18590
18591template class Foo<int>;
18592template ostream& operator <<
18593 (ostream&, const Foo<int>&);
3ab51846 18594@end smallexample
c1f7febf 18595
c513ecbf 18596@noindent
c1f7febf
RK
18597for each of the instances you need, and create a template instantiation
18598library from those.
18599
18600If you are using Cfront-model code, you can probably get away with not
84330467 18601using @option{-fno-implicit-templates} when compiling files that don't
c1f7febf
RK
18602@samp{#include} the member template definitions.
18603
18604If you use one big file to do the instantiations, you may want to
84330467 18605compile it without @option{-fno-implicit-templates} so you get all of the
c1f7febf
RK
18606instances required by your explicit instantiations (but not by any
18607other files) without having to specify them as well.
18608
513d0519
JW
18609The ISO C++ 2011 standard allows forward declaration of explicit
18610instantiations (with @code{extern}). G++ supports explicit instantiation
18611declarations in C++98 mode and has extended the template instantiation
18612syntax to support instantiation of the compiler support data for a
e979f9e8 18613template class (i.e.@: the vtable) without instantiating any of its
4003d7f9
JM
18614members (with @code{inline}), and instantiation of only the static data
18615members of a template class, without the support data or member
4ac2a3f0 18616functions (with @code{static}):
c1f7febf 18617
3ab51846 18618@smallexample
c1f7febf 18619extern template int max (int, int);
c1f7febf 18620inline template class Foo<int>;
4003d7f9 18621static template class Foo<int>;
3ab51846 18622@end smallexample
c1f7febf
RK
18623
18624@item
2dd76960 18625Do nothing. Pretend G++ does implement automatic instantiation
358a3dbc
SL
18626management. Code written for the Borland model works fine, but
18627each translation unit contains instances of each of the templates it
c1f7febf
RK
18628uses. In a large program, this can lead to an unacceptable amount of code
18629duplication.
c1f7febf
RK
18630@end enumerate
18631
0ded1f18
JM
18632@node Bound member functions
18633@section Extracting the function pointer from a bound pointer to member function
0ded1f18
JM
18634@cindex pmf
18635@cindex pointer to member function
18636@cindex bound pointer to member function
18637
18638In C++, pointer to member functions (PMFs) are implemented using a wide
18639pointer of sorts to handle all the possible call mechanisms; the PMF
18640needs to store information about how to adjust the @samp{this} pointer,
18641and if the function pointed to is virtual, where to find the vtable, and
18642where in the vtable to look for the member function. If you are using
18643PMFs in an inner loop, you should really reconsider that decision. If
18644that is not an option, you can extract the pointer to the function that
18645would be called for a given object/PMF pair and call it directly inside
18646the inner loop, to save a bit of time.
18647
358a3dbc 18648Note that you still pay the penalty for the call through a
0ded1f18 18649function pointer; on most modern architectures, such a call defeats the
161d7b59 18650branch prediction features of the CPU@. This is also true of normal
0ded1f18
JM
18651virtual function calls.
18652
18653The syntax for this extension is
18654
3ab51846 18655@smallexample
0ded1f18
JM
18656extern A a;
18657extern int (A::*fp)();
18658typedef int (*fptr)(A *);
18659
18660fptr p = (fptr)(a.*fp);
3ab51846 18661@end smallexample
0ded1f18 18662
e979f9e8 18663For PMF constants (i.e.@: expressions of the form @samp{&Klasse::Member}),
767094dd 18664no object is needed to obtain the address of the function. They can be
0fb6bbf5
ML
18665converted to function pointers directly:
18666
3ab51846 18667@smallexample
0fb6bbf5 18668fptr p1 = (fptr)(&A::foo);
3ab51846 18669@end smallexample
0fb6bbf5 18670
84330467
JM
18671@opindex Wno-pmf-conversions
18672You must specify @option{-Wno-pmf-conversions} to use this extension.
0ded1f18 18673
5c25e11d
PE
18674@node C++ Attributes
18675@section C++-Specific Variable, Function, and Type Attributes
18676
18677Some attributes only make sense for C++ programs.
18678
18679@table @code
7dbb85a7
JM
18680@item abi_tag ("@var{tag}", ...)
18681@cindex @code{abi_tag} attribute
18682The @code{abi_tag} attribute can be applied to a function or class
18683declaration. It modifies the mangled name of the function or class to
18684incorporate the tag name, in order to distinguish the function or
18685class from an earlier version with a different ABI; perhaps the class
18686has changed size, or the function has a different return type that is
18687not encoded in the mangled name.
18688
18689The argument can be a list of strings of arbitrary length. The
18690strings are sorted on output, so the order of the list is
18691unimportant.
18692
18693A redeclaration of a function or class must not add new ABI tags,
18694since doing so would change the mangled name.
18695
2982147e
JM
18696The ABI tags apply to a name, so all instantiations and
18697specializations of a template have the same tags. The attribute will
18698be ignored if applied to an explicit specialization or instantiation.
18699
7dbb85a7 18700The @option{-Wabi-tag} flag enables a warning about a class which does
d3061adb 18701not have all the ABI tags used by its subobjects and virtual functions; for users with code
7dbb85a7
JM
18702that needs to coexist with an earlier ABI, using this option can help
18703to find all affected types that need to be tagged.
18704
5c25e11d 18705@item init_priority (@var{priority})
ab940b73 18706@cindex @code{init_priority} attribute
5c25e11d
PE
18707
18708
18709In Standard C++, objects defined at namespace scope are guaranteed to be
18710initialized in an order in strict accordance with that of their definitions
18711@emph{in a given translation unit}. No guarantee is made for initializations
18712across translation units. However, GNU C++ allows users to control the
3844cd2e 18713order of initialization of objects defined at namespace scope with the
5c25e11d
PE
18714@code{init_priority} attribute by specifying a relative @var{priority},
18715a constant integral expression currently bounded between 101 and 65535
18716inclusive. Lower numbers indicate a higher priority.
18717
18718In the following example, @code{A} would normally be created before
358a3dbc 18719@code{B}, but the @code{init_priority} attribute reverses that order:
5c25e11d 18720
478c9e72 18721@smallexample
5c25e11d
PE
18722Some_Class A __attribute__ ((init_priority (2000)));
18723Some_Class B __attribute__ ((init_priority (543)));
478c9e72 18724@end smallexample
5c25e11d
PE
18725
18726@noindent
18727Note that the particular values of @var{priority} do not matter; only their
18728relative ordering.
18729
60c87482 18730@item java_interface
ab940b73 18731@cindex @code{java_interface} attribute
60c87482 18732
02f52e19 18733This type attribute informs C++ that the class is a Java interface. It may
60c87482 18734only be applied to classes declared within an @code{extern "Java"} block.
358a3dbc 18735Calls to methods declared in this interface are dispatched using GCJ's
02f52e19 18736interface table mechanism, instead of regular virtual table dispatch.
60c87482 18737
2a99e5e6
LL
18738@item warn_unused
18739@cindex @code{warn_unused} attribute
18740
18741For C++ types with non-trivial constructors and/or destructors it is
18742impossible for the compiler to determine whether a variable of this
18743type is truly unused if it is not referenced. This type attribute
18744informs the compiler that variables of this type should be warned
18745about if they appear to be unused, just like variables of fundamental
18746types.
18747
18748This attribute is appropriate for types which just represent a value,
18749such as @code{std::string}; it is not appropriate for types which
18750control a resource, such as @code{std::mutex}.
18751
18752This attribute is also accepted in C, but it is unnecessary because C
18753does not have constructors or destructors.
18754
5c25e11d
PE
18755@end table
18756
38bb2b65 18757See also @ref{Namespace Association}.
86098eb8 18758
f80e0faf
ST
18759@node Function Multiversioning
18760@section Function Multiversioning
18761@cindex function versions
18762
18763With the GNU C++ front end, for target i386, you may specify multiple
18764versions of a function, where each function is specialized for a
18765specific target feature. At runtime, the appropriate version of the
18766function is automatically executed depending on the characteristics of
18767the execution platform. Here is an example.
18768
18769@smallexample
18770__attribute__ ((target ("default")))
18771int foo ()
18772@{
18773 // The default version of foo.
18774 return 0;
18775@}
18776
18777__attribute__ ((target ("sse4.2")))
18778int foo ()
18779@{
18780 // foo version for SSE4.2
18781 return 1;
18782@}
18783
18784__attribute__ ((target ("arch=atom")))
18785int foo ()
18786@{
18787 // foo version for the Intel ATOM processor
18788 return 2;
18789@}
18790
18791__attribute__ ((target ("arch=amdfam10")))
18792int foo ()
18793@{
18794 // foo version for the AMD Family 0x10 processors.
18795 return 3;
18796@}
18797
18798int main ()
18799@{
18800 int (*p)() = &foo;
18801 assert ((*p) () == foo ());
18802 return 0;
18803@}
18804@end smallexample
18805
18806In the above example, four versions of function foo are created. The
18807first version of foo with the target attribute "default" is the default
18808version. This version gets executed when no other target specific
18809version qualifies for execution on a particular platform. A new version
18810of foo is created by using the same function signature but with a
18811different target string. Function foo is called or a pointer to it is
18812taken just like a regular function. GCC takes care of doing the
18813dispatching to call the right version at runtime. Refer to the
18814@uref{http://gcc.gnu.org/wiki/FunctionMultiVersioning, GCC wiki on
18815Function Multiversioning} for more details.
18816
664a90c0
JM
18817@node Namespace Association
18818@section Namespace Association
86098eb8 18819
b0af456a
JW
18820@strong{Caution:} The semantics of this extension are equivalent
18821to C++ 2011 inline namespaces. Users should use inline namespaces
18822instead as this extension will be removed in future versions of G++.
fea77ed9 18823
86098eb8
JM
18824A using-directive with @code{__attribute ((strong))} is stronger
18825than a normal using-directive in two ways:
18826
18827@itemize @bullet
18828@item
664a90c0
JM
18829Templates from the used namespace can be specialized and explicitly
18830instantiated as though they were members of the using namespace.
86098eb8
JM
18831
18832@item
18833The using namespace is considered an associated namespace of all
18834templates in the used namespace for purposes of argument-dependent
18835name lookup.
18836@end itemize
18837
664a90c0
JM
18838The used namespace must be nested within the using namespace so that
18839normal unqualified lookup works properly.
18840
86098eb8
JM
18841This is useful for composing a namespace transparently from
18842implementation namespaces. For example:
18843
18844@smallexample
18845namespace std @{
18846 namespace debug @{
18847 template <class T> struct A @{ @};
18848 @}
18849 using namespace debug __attribute ((__strong__));
5bd40ade 18850 template <> struct A<int> @{ @}; // @r{OK to specialize}
86098eb8
JM
18851
18852 template <class T> void f (A<T>);
18853@}
18854
18855int main()
18856@{
cd1a8088 18857 f (std::A<float>()); // @r{lookup finds} std::f
86098eb8
JM
18858 f (std::A<int>());
18859@}
18860@end smallexample
18861
cb68ec50
PC
18862@node Type Traits
18863@section Type Traits
18864
566fb011 18865The C++ front end implements syntactic extensions that allow
c417597c
SL
18866compile-time determination of
18867various characteristics of a type (or of a
cb68ec50
PC
18868pair of types).
18869
18870@table @code
18871@item __has_nothrow_assign (type)
b29441ec
PC
18872If @code{type} is const qualified or is a reference type then the trait is
18873false. Otherwise if @code{__has_trivial_assign (type)} is true then the trait
18874is true, else if @code{type} is a cv class or union type with copy assignment
18875operators that are known not to throw an exception then the trait is true,
ff2ce160 18876else it is false. Requires: @code{type} shall be a complete type,
5307cbaa 18877(possibly cv-qualified) @code{void}, or an array of unknown bound.
cb68ec50
PC
18878
18879@item __has_nothrow_copy (type)
18880If @code{__has_trivial_copy (type)} is true then the trait is true, else if
18881@code{type} is a cv class or union type with copy constructors that
18882are known not to throw an exception then the trait is true, else it is false.
5307cbaa
PC
18883Requires: @code{type} shall be a complete type, (possibly cv-qualified)
18884@code{void}, or an array of unknown bound.
cb68ec50
PC
18885
18886@item __has_nothrow_constructor (type)
18887If @code{__has_trivial_constructor (type)} is true then the trait is
18888true, else if @code{type} is a cv class or union type (or array
18889thereof) with a default constructor that is known not to throw an
ff2ce160
MS
18890exception then the trait is true, else it is false. Requires:
18891@code{type} shall be a complete type, (possibly cv-qualified)
5307cbaa 18892@code{void}, or an array of unknown bound.
cb68ec50
PC
18893
18894@item __has_trivial_assign (type)
18895If @code{type} is const qualified or is a reference type then the trait is
18896false. Otherwise if @code{__is_pod (type)} is true then the trait is
18897true, else if @code{type} is a cv class or union type with a trivial
18898copy assignment ([class.copy]) then the trait is true, else it is
ff2ce160 18899false. Requires: @code{type} shall be a complete type, (possibly
5307cbaa 18900cv-qualified) @code{void}, or an array of unknown bound.
cb68ec50
PC
18901
18902@item __has_trivial_copy (type)
ff2ce160 18903If @code{__is_pod (type)} is true or @code{type} is a reference type
cb68ec50
PC
18904then the trait is true, else if @code{type} is a cv class or union type
18905with a trivial copy constructor ([class.copy]) then the trait
18906is true, else it is false. Requires: @code{type} shall be a complete
5307cbaa 18907type, (possibly cv-qualified) @code{void}, or an array of unknown bound.
cb68ec50
PC
18908
18909@item __has_trivial_constructor (type)
18910If @code{__is_pod (type)} is true then the trait is true, else if
18911@code{type} is a cv class or union type (or array thereof) with a
18912trivial default constructor ([class.ctor]) then the trait is true,
5307cbaa
PC
18913else it is false. Requires: @code{type} shall be a complete
18914type, (possibly cv-qualified) @code{void}, or an array of unknown bound.
cb68ec50
PC
18915
18916@item __has_trivial_destructor (type)
18917If @code{__is_pod (type)} is true or @code{type} is a reference type then
18918the trait is true, else if @code{type} is a cv class or union type (or
18919array thereof) with a trivial destructor ([class.dtor]) then the trait
18920is true, else it is false. Requires: @code{type} shall be a complete
5307cbaa 18921type, (possibly cv-qualified) @code{void}, or an array of unknown bound.
cb68ec50
PC
18922
18923@item __has_virtual_destructor (type)
18924If @code{type} is a class type with a virtual destructor
18925([class.dtor]) then the trait is true, else it is false. Requires:
5307cbaa
PC
18926@code{type} shall be a complete type, (possibly cv-qualified)
18927@code{void}, or an array of unknown bound.
cb68ec50
PC
18928
18929@item __is_abstract (type)
18930If @code{type} is an abstract class ([class.abstract]) then the trait
18931is true, else it is false. Requires: @code{type} shall be a complete
5307cbaa 18932type, (possibly cv-qualified) @code{void}, or an array of unknown bound.
cb68ec50
PC
18933
18934@item __is_base_of (base_type, derived_type)
18935If @code{base_type} is a base class of @code{derived_type}
18936([class.derived]) then the trait is true, otherwise it is false.
18937Top-level cv qualifications of @code{base_type} and
18938@code{derived_type} are ignored. For the purposes of this trait, a
18939class type is considered is own base. Requires: if @code{__is_class
18940(base_type)} and @code{__is_class (derived_type)} are true and
18941@code{base_type} and @code{derived_type} are not the same type
18942(disregarding cv-qualifiers), @code{derived_type} shall be a complete
18943type. Diagnostic is produced if this requirement is not met.
18944
18945@item __is_class (type)
18946If @code{type} is a cv class type, and not a union type
d1facce0 18947([basic.compound]) the trait is true, else it is false.
cb68ec50
PC
18948
18949@item __is_empty (type)
18950If @code{__is_class (type)} is false then the trait is false.
18951Otherwise @code{type} is considered empty if and only if: @code{type}
18952has no non-static data members, or all non-static data members, if
d1facce0 18953any, are bit-fields of length 0, and @code{type} has no virtual
cb68ec50 18954members, and @code{type} has no virtual base classes, and @code{type}
ff2ce160 18955has no base classes @code{base_type} for which
cb68ec50 18956@code{__is_empty (base_type)} is false. Requires: @code{type} shall
5307cbaa
PC
18957be a complete type, (possibly cv-qualified) @code{void}, or an array
18958of unknown bound.
cb68ec50
PC
18959
18960@item __is_enum (type)
d1facce0 18961If @code{type} is a cv enumeration type ([basic.compound]) the trait is
cb68ec50
PC
18962true, else it is false.
18963
5307cbaa
PC
18964@item __is_literal_type (type)
18965If @code{type} is a literal type ([basic.types]) the trait is
18966true, else it is false. Requires: @code{type} shall be a complete type,
18967(possibly cv-qualified) @code{void}, or an array of unknown bound.
18968
cb68ec50
PC
18969@item __is_pod (type)
18970If @code{type} is a cv POD type ([basic.types]) then the trait is true,
5307cbaa
PC
18971else it is false. Requires: @code{type} shall be a complete type,
18972(possibly cv-qualified) @code{void}, or an array of unknown bound.
cb68ec50
PC
18973
18974@item __is_polymorphic (type)
18975If @code{type} is a polymorphic class ([class.virtual]) then the trait
18976is true, else it is false. Requires: @code{type} shall be a complete
5307cbaa
PC
18977type, (possibly cv-qualified) @code{void}, or an array of unknown bound.
18978
18979@item __is_standard_layout (type)
18980If @code{type} is a standard-layout type ([basic.types]) the trait is
18981true, else it is false. Requires: @code{type} shall be a complete
18982type, (possibly cv-qualified) @code{void}, or an array of unknown bound.
18983
18984@item __is_trivial (type)
18985If @code{type} is a trivial type ([basic.types]) the trait is
18986true, else it is false. Requires: @code{type} shall be a complete
18987type, (possibly cv-qualified) @code{void}, or an array of unknown bound.
cb68ec50
PC
18988
18989@item __is_union (type)
d1facce0 18990If @code{type} is a cv union type ([basic.compound]) the trait is
cb68ec50
PC
18991true, else it is false.
18992
74e883ce
PC
18993@item __underlying_type (type)
18994The underlying type of @code{type}. Requires: @code{type} shall be
18995an enumeration type ([dcl.enum]).
18996
cb68ec50
PC
18997@end table
18998
1f730ff7
ZW
18999@node Java Exceptions
19000@section Java Exceptions
19001
19002The Java language uses a slightly different exception handling model
358a3dbc 19003from C++. Normally, GNU C++ automatically detects when you are
1f730ff7
ZW
19004writing C++ code that uses Java exceptions, and handle them
19005appropriately. However, if C++ code only needs to execute destructors
358a3dbc 19006when Java exceptions are thrown through it, GCC guesses incorrectly.
9c34dbbf 19007Sample problematic code is:
1f730ff7 19008
478c9e72 19009@smallexample
1f730ff7 19010 struct S @{ ~S(); @};
cd1a8088 19011 extern void bar(); // @r{is written in Java, and may throw exceptions}
1f730ff7
ZW
19012 void foo()
19013 @{
19014 S s;
19015 bar();
19016 @}
478c9e72 19017@end smallexample
1f730ff7
ZW
19018
19019@noindent
19020The usual effect of an incorrect guess is a link failure, complaining of
19021a missing routine called @samp{__gxx_personality_v0}.
19022
19023You can inform the compiler that Java exceptions are to be used in a
19024translation unit, irrespective of what it might think, by writing
19025@samp{@w{#pragma GCC java_exceptions}} at the head of the file. This
19026@samp{#pragma} must appear before any functions that throw or catch
19027exceptions, or run destructors when exceptions are thrown through them.
19028
19029You cannot mix Java and C++ exceptions in the same translation unit. It
19030is believed to be safe to throw a C++ exception from one file through
9c34dbbf
ZW
19031another file compiled for the Java exception model, or vice versa, but
19032there may be bugs in this area.
1f730ff7 19033
e6f3b89d
PE
19034@node Deprecated Features
19035@section Deprecated Features
19036
19037In the past, the GNU C++ compiler was extended to experiment with new
767094dd 19038features, at a time when the C++ language was still evolving. Now that
e6f3b89d 19039the C++ standard is complete, some of those features are superseded by
767094dd
JM
19040superior alternatives. Using the old features might cause a warning in
19041some cases that the feature will be dropped in the future. In other
e6f3b89d
PE
19042cases, the feature might be gone already.
19043
19044While the list below is not exhaustive, it documents some of the options
19045that are now deprecated:
19046
19047@table @code
19048@item -fexternal-templates
19049@itemx -falt-external-templates
2dd76960 19050These are two of the many ways for G++ to implement template
767094dd 19051instantiation. @xref{Template Instantiation}. The C++ standard clearly
e6f3b89d 19052defines how template definitions have to be organized across
2dd76960 19053implementation units. G++ has an implicit instantiation mechanism that
e6f3b89d
PE
19054should work just fine for standard-conforming code.
19055
19056@item -fstrict-prototype
19057@itemx -fno-strict-prototype
19058Previously it was possible to use an empty prototype parameter list to
19059indicate an unspecified number of parameters (like C), rather than no
767094dd 19060parameters, as C++ demands. This feature has been removed, except where
38bb2b65 19061it is required for backwards compatibility. @xref{Backwards Compatibility}.
e6f3b89d
PE
19062@end table
19063
ae209f28
NS
19064G++ allows a virtual function returning @samp{void *} to be overridden
19065by one returning a different pointer type. This extension to the
19066covariant return type rules is now deprecated and will be removed from a
19067future version.
19068
8ff24a79
MM
19069The G++ minimum and maximum operators (@samp{<?} and @samp{>?}) and
19070their compound forms (@samp{<?=}) and @samp{>?=}) have been deprecated
32e26ece
GK
19071and are now removed from G++. Code using these operators should be
19072modified to use @code{std::min} and @code{std::max} instead.
8ff24a79 19073
ad1a6d45 19074The named return value extension has been deprecated, and is now
2dd76960 19075removed from G++.
e6f3b89d 19076
82c18d5c 19077The use of initializer lists with new expressions has been deprecated,
2dd76960 19078and is now removed from G++.
ad1a6d45
NS
19079
19080Floating and complex non-type template parameters have been deprecated,
2dd76960 19081and are now removed from G++.
ad1a6d45 19082
90ea7324 19083The implicit typename extension has been deprecated and is now
2dd76960 19084removed from G++.
90ea7324 19085
1eaf20ec 19086The use of default arguments in function pointers, function typedefs
90ea7324 19087and other places where they are not permitted by the standard is
2dd76960 19088deprecated and will be removed from a future version of G++.
82c18d5c 19089
6871294a 19090G++ allows floating-point literals to appear in integral constant expressions,
566fb011 19091e.g.@: @samp{ enum E @{ e = int(2.2 * 3.7) @} }
6871294a
JW
19092This extension is deprecated and will be removed from a future version.
19093
19094G++ allows static data members of const floating-point type to be declared
19095with an initializer in a class definition. The standard only allows
19096initializers for static members of const integral types and const
19097enumeration types so this extension has been deprecated and will be removed
19098from a future version.
19099
e6f3b89d
PE
19100@node Backwards Compatibility
19101@section Backwards Compatibility
19102@cindex Backwards Compatibility
19103@cindex ARM [Annotated C++ Reference Manual]
19104
aee96fe9 19105Now that there is a definitive ISO standard C++, G++ has a specification
767094dd 19106to adhere to. The C++ language evolved over time, and features that
e6f3b89d 19107used to be acceptable in previous drafts of the standard, such as the ARM
767094dd 19108[Annotated C++ Reference Manual], are no longer accepted. In order to allow
aee96fe9 19109compilation of C++ written to such drafts, G++ contains some backwards
767094dd 19110compatibilities. @emph{All such backwards compatibility features are
aee96fe9 19111liable to disappear in future versions of G++.} They should be considered
38bb2b65 19112deprecated. @xref{Deprecated Features}.
e6f3b89d
PE
19113
19114@table @code
19115@item For scope
19116If a variable is declared at for scope, it used to remain in scope until
c417597c 19117the end of the scope that contained the for statement (rather than just
aee96fe9 19118within the for scope). G++ retains this, but issues a warning, if such a
e6f3b89d
PE
19119variable is accessed outside the for scope.
19120
ad1a6d45 19121@item Implicit C language
630d3d5a 19122Old C system header files did not contain an @code{extern "C" @{@dots{}@}}
767094dd
JM
19123scope to set the language. On such systems, all header files are
19124implicitly scoped inside a C language scope. Also, an empty prototype
358a3dbc 19125@code{()} is treated as an unspecified number of arguments, rather
e6f3b89d
PE
19126than no arguments, as C++ demands.
19127@end table
5d5f6720
JR
19128
19129@c LocalWords: emph deftypefn builtin ARCv2EM SIMD builtins msimd
19130@c LocalWords: typedef v4si v8hi DMA dma vdiwr vdowr followign