]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/doc/extend.texi
2012-09-14 Richard Guenther <rguenther@suse.de>
[thirdparty/gcc.git] / gcc / doc / extend.texi
CommitLineData
99c77e32 1@c Copyright (C) 1988, 1989, 1992, 1993, 1994, 1996, 1998, 1999, 2000, 2001,
b7508909 2@c 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
cfaf579d 3@c Free Software Foundation, Inc.
c4503c0a 4
146ef39f 5@c This is part of the GCC manual.
6@c For copying conditions, see the file gcc.texi.
7
8@node C Extensions
9@chapter Extensions to the C Language Family
10@cindex extensions, C language
11@cindex C language extensions
12
67791935 13@opindex pedantic
0858e3a2 14GNU C provides several language features not found in ISO standard C@.
37744367 15(The @option{-pedantic} option directs GCC to print a warning message if
146ef39f 16any of these features is used.) To test for the availability of these
17features in conditional compilation, check for a predefined macro
0858e3a2 18@code{__GNUC__}, which is always defined under GCC@.
146ef39f 19
0858e3a2 20These extensions are available in C and Objective-C@. Most of them are
146ef39f 21also available in C++. @xref{C++ Extensions,,Extensions to the
22C++ Language}, for extensions that apply @emph{only} to C++.
23
32f1f35b 24Some features that are in ISO C99 but not C90 or C++ are also, as
25extensions, accepted by GCC in C90 mode and in C++.
78b1f616 26
146ef39f 27@menu
28* Statement Exprs:: Putting statements and declarations inside expressions.
bdc33d98 29* Local Labels:: Labels local to a block.
146ef39f 30* Labels as Values:: Getting pointers to labels, and computed gotos.
31* Nested Functions:: As in Algol and Pascal, lexical scoping of functions.
c24c5fac 32* Constructing Calls:: Dispatching a call to another function.
146ef39f 33* Typeof:: @code{typeof}: referring to the type of an expression.
146ef39f 34* Conditionals:: Omitting the middle operand of a @samp{?:} expression.
c24c5fac 35* Long Long:: Double-word integers---@code{long long int}.
6388cfe2 36* __int128:: 128-bit integers---@code{__int128}.
146ef39f 37* Complex:: Data types for complex numbers.
430be8e2 38* Floating Types:: Additional Floating Types.
9b8516be 39* Half-Precision:: Half-Precision Floating Point.
15b474a2 40* Decimal Float:: Decimal Floating Types.
75bd5ada 41* Hex Floats:: Hexadecimal floating-point constants.
68a556d6 42* Fixed-Point:: Fixed-Point Types.
bd1a81f7 43* Named Address Spaces::Named address spaces.
146ef39f 44* Zero Length:: Zero-length arrays.
45* Variable Length:: Arrays whose length is computed at run time.
710d60ed 46* Empty Structures:: Structures with no members.
c24c5fac 47* Variadic Macros:: Macros with a variable number of arguments.
da825954 48* Escaped Newlines:: Slightly looser rules for escaped newlines.
146ef39f 49* Subscripting:: Any array can be subscripted, even if not an lvalue.
50* Pointer Arith:: Arithmetic on @code{void}-pointers and function pointers.
51* Initializers:: Non-constant initializers.
3cfa0cc4 52* Compound Literals:: Compound literals give structures, unions
c24c5fac 53 or arrays as values.
54* Designated Inits:: Labeling elements of initializers.
146ef39f 55* Cast to Union:: Casting to union type from any member of the union.
c24c5fac 56* Case Ranges:: `case 1 ... 9' and such.
57* Mixed Declarations:: Mixing declarations and code.
146ef39f 58* Function Attributes:: Declaring that functions have no side effects,
c24c5fac 59 or that they can never return.
b31bfb3f 60* Attribute Syntax:: Formal syntax for attributes.
146ef39f 61* Function Prototypes:: Prototype declarations and old-style definitions.
62* C++ Comments:: C++ comments are recognized.
63* Dollar Signs:: Dollar sign is allowed in identifiers.
64* Character Escapes:: @samp{\e} stands for the character @key{ESC}.
c24c5fac 65* Variable Attributes:: Specifying attributes of variables.
66* Type Attributes:: Specifying attributes of types.
146ef39f 67* Alignment:: Inquiring about the alignment of a type or variable.
68* Inline:: Defining inline functions (as fast as macros).
e83c4d0f 69* Volatiles:: What constitutes an access to a volatile object.
146ef39f 70* Extended Asm:: Assembler instructions with C expressions as operands.
c24c5fac 71 (With them you can define ``built-in'' functions.)
146ef39f 72* Constraints:: Constraints for asm operands
73* Asm Labels:: Specifying the assembler name to use for a C symbol.
74* Explicit Reg Vars:: Defining variables residing in specified registers.
75* Alternate Keywords:: @code{__const__}, @code{__asm__}, etc., for header files.
76* Incomplete Enums:: @code{enum foo;}, with details to follow.
c24c5fac 77* Function Names:: Printable strings which are the name of the current
78 function.
146ef39f 79* Return Address:: Getting the return or frame address of a function.
ee5925ea 80* Vector Extensions:: Using vector instructions through built-in functions.
43bf5d72 81* Offsetof:: Special syntax for implementing @code{offsetof}.
1cd6e20d 82* __sync Builtins:: Legacy built-in functions for atomic memory access.
83* __atomic Builtins:: Atomic built-in functions with memory model.
0a39fd54 84* Object Size Checking:: Built-in functions for limited buffer overflow
85 checking.
7014838c 86* Other Builtins:: Other built-in functions.
ca5827cf 87* Target Builtins:: Built-in functions specific to particular targets.
1e9af880 88* Target Format Checks:: Format checks specific to particular targets.
49f45d83 89* Pragmas:: Pragmas accepted by GCC.
f5b36051 90* Unnamed Fields:: Unnamed struct/union fields within structs/unions.
2a6f0f81 91* Thread-Local:: Per-thread variables.
d7282a2b 92* Binary constants:: Binary constants using the @samp{0b} prefix.
146ef39f 93@end menu
146ef39f 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
146ef39f 104A compound statement enclosed in parentheses may appear as an expression
0858e3a2 105in GNU C@. This allows you to use loops, switches, and local variables
146ef39f 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
a0ecd6b1 112@smallexample
146ef39f 113(@{ int y = foo (); int z;
114 if (y > 0) z = y;
115 else z = - y;
116 z; @})
a0ecd6b1 117@end smallexample
146ef39f 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
a0ecd6b1 134@smallexample
146ef39f 135#define max(a,b) ((a) > (b) ? (a) : (b))
a0ecd6b1 136@end smallexample
146ef39f 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
153e79bc 142type of the operands (here taken as @code{int}), you can define
146ef39f 143the macro safely as follows:
144
a0ecd6b1 145@smallexample
146ef39f 146#define maxint(a,b) \
147 (@{int _a = (a), _b = (b); _a > _b ? _a : _b; @})
a0ecd6b1 148@end smallexample
146ef39f 149
150Embedded statements are not allowed in constant expressions, such as
8e5fcce7 151the value of an enumeration constant, the width of a bit-field, or
146ef39f 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
f6f89f14 155must use @code{typeof} (@pxref{Typeof}).
146ef39f 156
942ab15b 157In G++, the result value of a statement expression undergoes array and
158function pointer decay, and is returned by value to the enclosing
b3d47662 159expression. For instance, if @code{A} is a class, then
6a50ae27 160
942ab15b 161@smallexample
162 A a;
6a50ae27 163
942ab15b 164 (@{a;@}).Foo ()
165@end smallexample
6a50ae27 166
167@noindent
942ab15b 168will construct a temporary @code{A} object to hold the result of the
169statement expression, and that will be used to invoke @code{Foo}.
170Therefore the @code{this} pointer observed by @code{Foo} will not be the
171address of @code{a}.
172
173Any temporaries created within a statement within a statement expression
174will be destroyed at the statement's end. This makes statement
175expressions inside macros slightly different from function calls. In
176the latter case temporaries introduced during argument evaluation will
177be destroyed at the end of the statement that includes the function
178call. In the statement expression case they will be destroyed during
179the statement expression. For instance,
6a50ae27 180
942ab15b 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
6a50ae27 191
192@noindent
942ab15b 193will have different places where temporaries are destroyed. For the
194@code{macro} case, the temporary @code{X} will be destroyed just after
195the initialization of @code{b}. In the @code{function} case that
196temporary will be destroyed when the function returns.
6a50ae27 197
198These considerations mean that it is probably a bad idea to use
199statement-expressions of this form in header files that are designed to
f12bbcea 200work with C++. (Note that some versions of the GNU C Library contained
201header files using statement-expression that lead to precisely this
202bug.)
6a50ae27 203
f08c7a57 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
208@code{goto} (@pxref{Labels as Values}) yields undefined behavior.
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
214expression. In any case, as with a function call the evaluation of a
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
223will call @code{foo} and @code{bar1} and will not call @code{baz} but
224may or may not call @code{bar2}. If @code{bar2} is called, it will be
225called after @code{foo} and before @code{bar1}
226
146ef39f 227@node Local Labels
228@section Locally Declared Labels
229@cindex local labels
230@cindex macros, local labels
231
bdc33d98 232GCC allows you to declare @dfn{local labels} in any nested block
b3d47662 233scope. A local label is just like an ordinary label, but you can
bdc33d98 234only reference it (with a @code{goto} statement, or by taking its
7a0ad664 235address) within the block in which it was declared.
146ef39f 236
237A local label declaration looks like this:
238
a0ecd6b1 239@smallexample
146ef39f 240__label__ @var{label};
a0ecd6b1 241@end smallexample
146ef39f 242
243@noindent
244or
245
a0ecd6b1 246@smallexample
4ae74ddd 247__label__ @var{label1}, @var{label2}, /* @r{@dots{}} */;
a0ecd6b1 248@end smallexample
146ef39f 249
bdc33d98 250Local label declarations must come at the beginning of the block,
251before any ordinary declarations or statements.
146ef39f 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
bdc33d98 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
261function, the label will be multiply defined in that function. A
262local label avoids this problem. For example:
263
a0ecd6b1 264@smallexample
bdc33d98 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)
a0ecd6b1 279@end smallexample
bdc33d98 280
281This could also be written using a statement-expression:
146ef39f 282
a0ecd6b1 283@smallexample
146ef39f 284#define SEARCH(array, target) \
d90db7dc 285(@{ \
146ef39f 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) \
d90db7dc 294 @{ value = i; goto found; @} \
146ef39f 295 value = -1; \
296 found: \
297 value; \
298@})
a0ecd6b1 299@end smallexample
146ef39f 300
bdc33d98 301Local label declarations also make the labels they declare visible to
302nested functions, if there are any. @xref{Nested Functions}, for details.
303
146ef39f 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
a0ecd6b1 316@smallexample
146ef39f 317void *ptr;
4ae74ddd 318/* @r{@dots{}} */
146ef39f 319ptr = &&foo;
a0ecd6b1 320@end smallexample
146ef39f 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
a0ecd6b1 328@smallexample
146ef39f 329goto *ptr;
a0ecd6b1 330@end smallexample
146ef39f 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
336will serve as a jump table:
337
a0ecd6b1 338@smallexample
146ef39f 339static void *array[] = @{ &&foo, &&bar, &&hack @};
a0ecd6b1 340@end smallexample
146ef39f 341
342Then you can select a label with indexing, like this:
343
a0ecd6b1 344@smallexample
146ef39f 345goto *array[i];
a0ecd6b1 346@end smallexample
146ef39f 347
348@noindent
349Note that this does not check whether the subscript is in bounds---array
350indexing in C never does that.
351
352Such an array of label values serves a purpose much like that of the
353@code{switch} statement. The @code{switch} statement is cleaner, so
354use that rather than an array unless the problem does not fit a
355@code{switch} statement very well.
356
357Another use of label values is in an interpreter for threaded code.
358The labels within the interpreter function can be stored in the
359threaded code for super-fast dispatching.
360
3b0848a2 361You may not use this mechanism to jump to code in a different function.
56d9dfd0 362If you do that, totally unpredictable things will happen. The best way to
146ef39f 363avoid this is to store the label address only in automatic variables and
364never pass it as an argument.
365
56d9dfd0 366An alternate way to write the above example is
367
a0ecd6b1 368@smallexample
d90db7dc 369static const int array[] = @{ &&foo - &&foo, &&bar - &&foo,
370 &&hack - &&foo @};
56d9dfd0 371goto *(&&foo + array[i]);
a0ecd6b1 372@end smallexample
56d9dfd0 373
374@noindent
375This is more friendly to code living in shared libraries, as it reduces
376the number of dynamic relocations that are needed, and by consequence,
377allows the data to be read-only.
378
bdb1f0d1 379The @code{&&foo} expressions for the same label might have different
380values if the containing function is inlined or cloned. If a program
381relies on them being always the same,
382@code{__attribute__((__noinline__,__noclone__))} should be used to
383prevent inlining and cloning. If @code{&&foo} is used in a static
384variable initializer, inlining and cloning is forbidden.
361c9aad 385
146ef39f 386@node Nested Functions
387@section Nested Functions
388@cindex nested functions
389@cindex downward funargs
390@cindex thunks
391
392A @dfn{nested function} is a function defined inside another function.
393(Nested functions are not supported for GNU C++.) The nested function's
394name is local to the block where it is defined. For example, here we
395define a nested function named @code{square}, and call it twice:
396
a0ecd6b1 397@smallexample
146ef39f 398@group
399foo (double a, double b)
400@{
401 double square (double z) @{ return z * z; @}
402
403 return square (a) + square (b);
404@}
405@end group
a0ecd6b1 406@end smallexample
146ef39f 407
408The nested function can access all the variables of the containing
409function that are visible at the point of its definition. This is
410called @dfn{lexical scoping}. For example, here we show a nested
411function which uses an inherited variable named @code{offset}:
412
a0ecd6b1 413@smallexample
70c2c81c 414@group
146ef39f 415bar (int *array, int offset, int size)
416@{
417 int access (int *array, int index)
418 @{ return array[index + offset]; @}
419 int i;
4ae74ddd 420 /* @r{@dots{}} */
146ef39f 421 for (i = 0; i < size; i++)
4ae74ddd 422 /* @r{@dots{}} */ access (array, i) /* @r{@dots{}} */
146ef39f 423@}
70c2c81c 424@end group
a0ecd6b1 425@end smallexample
146ef39f 426
427Nested function definitions are permitted within functions in the places
dbb77364 428where variable definitions are allowed; that is, in any block, mixed
429with the other declarations and statements in the block.
146ef39f 430
431It is possible to call the nested function from outside the scope of its
432name by storing its address or passing the address to another function:
433
a0ecd6b1 434@smallexample
146ef39f 435hack (int *array, int size)
436@{
437 void store (int index, int value)
438 @{ array[index] = value; @}
439
440 intermediate (store, size);
441@}
a0ecd6b1 442@end smallexample
146ef39f 443
444Here, the function @code{intermediate} receives the address of
445@code{store} as an argument. If @code{intermediate} calls @code{store},
446the arguments given to @code{store} are used to store into @code{array}.
447But this technique works only so long as the containing function
448(@code{hack}, in this example) does not exit.
449
450If you try to call the nested function through its address after the
451containing function has exited, all hell will break loose. If you try
452to call it after a containing scope level has exited, and if it refers
453to some of the variables that are no longer in scope, you may be lucky,
454but it's not wise to take the risk. If, however, the nested function
455does not refer to anything that has gone out of scope, you should be
456safe.
457
0fff59be 458GCC implements taking the address of a nested function using a technique
15b474a2 459called @dfn{trampolines}. This technique was described in
3e8e7577 460@cite{Lexical Closures for C++} (Thomas M. Breuel, USENIX
461C++ Conference Proceedings, October 17-21, 1988).
146ef39f 462
463A nested function can jump to a label inherited from a containing
464function, provided the label was explicitly declared in the containing
465function (@pxref{Local Labels}). Such a jump returns instantly to the
466containing function, exiting the nested function which did the
467@code{goto} and any intermediate functions as well. Here is an example:
468
a0ecd6b1 469@smallexample
146ef39f 470@group
471bar (int *array, int offset, int size)
472@{
473 __label__ failure;
474 int access (int *array, int index)
475 @{
476 if (index > size)
477 goto failure;
478 return array[index + offset];
479 @}
480 int i;
4ae74ddd 481 /* @r{@dots{}} */
146ef39f 482 for (i = 0; i < size; i++)
4ae74ddd 483 /* @r{@dots{}} */ access (array, i) /* @r{@dots{}} */
484 /* @r{@dots{}} */
146ef39f 485 return 0;
486
487 /* @r{Control comes here from @code{access}
488 if it detects an error.} */
489 failure:
490 return -1;
491@}
492@end group
a0ecd6b1 493@end smallexample
146ef39f 494
557522b9 495A nested function always has no linkage. Declaring one with
496@code{extern} or @code{static} is erroneous. If you need to declare the nested function
146ef39f 497before its definition, use @code{auto} (which is otherwise meaningless
498for function declarations).
499
a0ecd6b1 500@smallexample
146ef39f 501bar (int *array, int offset, int size)
502@{
503 __label__ failure;
504 auto int access (int *, int);
4ae74ddd 505 /* @r{@dots{}} */
146ef39f 506 int access (int *array, int index)
507 @{
508 if (index > size)
509 goto failure;
510 return array[index + offset];
511 @}
4ae74ddd 512 /* @r{@dots{}} */
146ef39f 513@}
a0ecd6b1 514@end smallexample
146ef39f 515
516@node Constructing Calls
517@section Constructing Function Calls
518@cindex constructing calls
519@cindex forwarding calls
520
521Using the built-in functions described below, you can record
522the arguments a function received, and call another function
523with the same arguments, without knowing the number or types
524of the arguments.
525
526You can also record the return value of that function call,
527and later return that value, without knowing what data type
528the function tried to return (as long as your caller expects
529that data type).
530
57fbc47a 531However, these built-in functions may interact badly with some
532sophisticated features or other extensions of the language. It
533is, therefore, not recommended to use them outside very simple
534functions acting as mere forwarders for their arguments.
535
67791935 536@deftypefn {Built-in Function} {void *} __builtin_apply_args ()
537This built-in function returns a pointer to data
146ef39f 538describing how to perform a call with the same arguments as were passed
539to the current function.
540
541The function saves the arg pointer register, structure value address,
542and all registers that might be used to pass arguments to a function
543into a block of memory allocated on the stack. Then it returns the
544address of that block.
67791935 545@end deftypefn
146ef39f 546
67791935 547@deftypefn {Built-in Function} {void *} __builtin_apply (void (*@var{function})(), void *@var{arguments}, size_t @var{size})
548This built-in function invokes @var{function}
549with a copy of the parameters described by @var{arguments}
550and @var{size}.
146ef39f 551
552The value of @var{arguments} should be the value returned by
553@code{__builtin_apply_args}. The argument @var{size} specifies the size
554of the stack argument data, in bytes.
555
67791935 556This function returns a pointer to data describing
146ef39f 557how to return whatever value was returned by @var{function}. The data
558is saved in a block of memory allocated on the stack.
559
560It is not always simple to compute the proper value for @var{size}. The
561value is used by @code{__builtin_apply} to compute the amount of data
562that should be pushed on the stack and copied from the incoming argument
563area.
67791935 564@end deftypefn
146ef39f 565
67791935 566@deftypefn {Built-in Function} {void} __builtin_return (void *@var{result})
146ef39f 567This built-in function returns the value described by @var{result} from
568the containing function. You should specify, for @var{result}, a value
569returned by @code{__builtin_apply}.
67791935 570@end deftypefn
146ef39f 571
12786727 572@deftypefn {Built-in Function} {} __builtin_va_arg_pack ()
48dc2227 573This built-in function represents all anonymous arguments of an inline
574function. It can be used only in inline functions which will be always
575inlined, never compiled as a separate function, such as those using
576@code{__attribute__ ((__always_inline__))} or
577@code{__attribute__ ((__gnu_inline__))} extern inline functions.
578It must be only passed as last argument to some other function
579with variable arguments. This is useful for writing small wrapper
580inlines for variable argument functions, when using preprocessor
581macros is undesirable. For example:
582@smallexample
583extern int myprintf (FILE *f, const char *format, ...);
584extern inline __attribute__ ((__gnu_inline__)) int
585myprintf (FILE *f, const char *format, ...)
586@{
587 int r = fprintf (f, "myprintf: ");
588 if (r < 0)
589 return r;
590 int s = fprintf (f, format, __builtin_va_arg_pack ());
591 if (s < 0)
592 return s;
593 return r + s;
594@}
595@end smallexample
596@end deftypefn
597
12786727 598@deftypefn {Built-in Function} {size_t} __builtin_va_arg_pack_len ()
4e1d7ea4 599This built-in function returns the number of anonymous arguments of
600an inline function. It can be used only in inline functions which
601will be always inlined, never compiled as a separate function, such
602as those using @code{__attribute__ ((__always_inline__))} or
603@code{__attribute__ ((__gnu_inline__))} extern inline functions.
604For example following will do link or runtime checking of open
605arguments for optimized code:
606@smallexample
607#ifdef __OPTIMIZE__
608extern inline __attribute__((__gnu_inline__)) int
609myopen (const char *path, int oflag, ...)
610@{
611 if (__builtin_va_arg_pack_len () > 1)
612 warn_open_too_many_arguments ();
613
614 if (__builtin_constant_p (oflag))
615 @{
616 if ((oflag & O_CREAT) != 0 && __builtin_va_arg_pack_len () < 1)
617 @{
618 warn_open_missing_mode ();
619 return __open_2 (path, oflag);
620 @}
621 return open (path, oflag, __builtin_va_arg_pack ());
622 @}
15b474a2 623
4e1d7ea4 624 if (__builtin_va_arg_pack_len () < 1)
625 return __open_2 (path, oflag);
626
627 return open (path, oflag, __builtin_va_arg_pack ());
628@}
629#endif
630@end smallexample
631@end deftypefn
632
146ef39f 633@node Typeof
634@section Referring to a Type with @code{typeof}
635@findex typeof
636@findex sizeof
637@cindex macros, types of arguments
638
639Another way to refer to the type of an expression is with @code{typeof}.
640The syntax of using of this keyword looks like @code{sizeof}, but the
641construct acts semantically like a type name defined with @code{typedef}.
642
643There are two ways of writing the argument to @code{typeof}: with an
644expression or with a type. Here is an example with an expression:
645
a0ecd6b1 646@smallexample
146ef39f 647typeof (x[0](1))
a0ecd6b1 648@end smallexample
146ef39f 649
650@noindent
f934d81d 651This assumes that @code{x} is an array of pointers to functions;
652the type described is that of the values of the functions.
146ef39f 653
654Here is an example with a typename as the argument:
655
a0ecd6b1 656@smallexample
146ef39f 657typeof (int *)
a0ecd6b1 658@end smallexample
146ef39f 659
660@noindent
661Here the type described is that of pointers to @code{int}.
662
78b1f616 663If you are writing a header file that must work when included in ISO C
146ef39f 664programs, write @code{__typeof__} instead of @code{typeof}.
665@xref{Alternate Keywords}.
666
667A @code{typeof}-construct can be used anywhere a typedef name could be
668used. For example, you can use it in a declaration, in a cast, or inside
669of @code{sizeof} or @code{typeof}.
670
a75b1c71 671The operand of @code{typeof} is evaluated for its side effects if and
672only if it is an expression of variably modified type or the name of
673such a type.
674
f6f89f14 675@code{typeof} is often useful in conjunction with the
676statements-within-expressions feature. Here is how the two together can
677be used to define a safe ``maximum'' macro that operates on any
678arithmetic type and evaluates each of its arguments exactly once:
679
a0ecd6b1 680@smallexample
f6f89f14 681#define max(a,b) \
682 (@{ typeof (a) _a = (a); \
683 typeof (b) _b = (b); \
684 _a > _b ? _a : _b; @})
a0ecd6b1 685@end smallexample
f6f89f14 686
2e411f1f 687@cindex underscores in variables in macros
688@cindex @samp{_} in variables in macros
689@cindex local variables in macros
690@cindex variables, local, in macros
691@cindex macros, local variables in
692
693The reason for using names that start with underscores for the local
694variables is to avoid conflicts with variable names that occur within the
695expressions that are substituted for @code{a} and @code{b}. Eventually we
696hope to design a new form of declaration syntax that allows you to declare
697variables whose scopes start only after their initializers; this will be a
698more reliable way to prevent such conflicts.
699
f6f89f14 700@noindent
701Some more examples of the use of @code{typeof}:
702
146ef39f 703@itemize @bullet
704@item
705This declares @code{y} with the type of what @code{x} points to.
706
a0ecd6b1 707@smallexample
146ef39f 708typeof (*x) y;
a0ecd6b1 709@end smallexample
146ef39f 710
711@item
712This declares @code{y} as an array of such values.
713
a0ecd6b1 714@smallexample
146ef39f 715typeof (*x) y[4];
a0ecd6b1 716@end smallexample
146ef39f 717
718@item
719This declares @code{y} as an array of pointers to characters:
720
a0ecd6b1 721@smallexample
146ef39f 722typeof (typeof (char *)[4]) y;
a0ecd6b1 723@end smallexample
146ef39f 724
725@noindent
726It is equivalent to the following traditional C declaration:
727
a0ecd6b1 728@smallexample
146ef39f 729char *y[4];
a0ecd6b1 730@end smallexample
146ef39f 731
732To see the meaning of the declaration using @code{typeof}, and why it
153e79bc 733might be a useful way to write, rewrite it with these macros:
146ef39f 734
a0ecd6b1 735@smallexample
146ef39f 736#define pointer(T) typeof(T *)
737#define array(T, N) typeof(T [N])
a0ecd6b1 738@end smallexample
146ef39f 739
740@noindent
741Now the declaration can be rewritten this way:
742
a0ecd6b1 743@smallexample
146ef39f 744array (pointer (char), 4) y;
a0ecd6b1 745@end smallexample
146ef39f 746
747@noindent
748Thus, @code{array (pointer (char), 4)} is the type of arrays of 4
749pointers to @code{char}.
750@end itemize
751
f6f89f14 752@emph{Compatibility Note:} In addition to @code{typeof}, GCC 2 supported
753a more limited extension which permitted one to write
754
a0ecd6b1 755@smallexample
f6f89f14 756typedef @var{T} = @var{expr};
a0ecd6b1 757@end smallexample
f6f89f14 758
759@noindent
760with the effect of declaring @var{T} to have the type of the expression
761@var{expr}. This extension does not work with GCC 3 (versions between
7623.0 and 3.2 will crash; 3.2.1 and later give an error). Code which
763relies on it should be rewritten to use @code{typeof}:
764
a0ecd6b1 765@smallexample
f6f89f14 766typedef typeof(@var{expr}) @var{T};
a0ecd6b1 767@end smallexample
f6f89f14 768
769@noindent
770This will work with all versions of GCC@.
771
146ef39f 772@node Conditionals
773@section Conditionals with Omitted Operands
774@cindex conditional expressions, extensions
775@cindex omitted middle-operands
776@cindex middle-operands, omitted
777@cindex extensions, @code{?:}
778@cindex @code{?:} extensions
779
780The middle operand in a conditional expression may be omitted. Then
781if the first operand is nonzero, its value is the value of the conditional
782expression.
783
784Therefore, the expression
785
a0ecd6b1 786@smallexample
146ef39f 787x ? : y
a0ecd6b1 788@end smallexample
146ef39f 789
790@noindent
791has the value of @code{x} if that is nonzero; otherwise, the value of
792@code{y}.
793
794This example is perfectly equivalent to
795
a0ecd6b1 796@smallexample
146ef39f 797x ? x : y
a0ecd6b1 798@end smallexample
146ef39f 799
12786727 800@cindex side effect in @code{?:}
801@cindex @code{?:} side effect
146ef39f 802@noindent
803In this simple case, the ability to omit the middle operand is not
804especially useful. When it becomes useful is when the first operand does,
805or may (if it is a macro argument), contain a side effect. Then repeating
806the operand in the middle would perform the side effect twice. Omitting
807the middle operand uses the value already computed without the undesirable
808effects of recomputing it.
809
6388cfe2 810@node __int128
811@section 128-bits integers
812@cindex @code{__int128} data types
813
814As an extension the integer scalar type @code{__int128} is supported for
815targets having an integer mode wide enough to hold 128-bit.
816Simply write @code{__int128} for a signed 128-bit integer, or
817@code{unsigned __int128} for an unsigned 128-bit integer. There is no
818support in GCC to express an integer constant of type @code{__int128}
819for targets having @code{long long} integer with less then 128 bit width.
820
146ef39f 821@node Long Long
822@section Double-Word Integers
823@cindex @code{long long} data types
824@cindex double-word arithmetic
825@cindex multiprecision arithmetic
3cfa0cc4 826@cindex @code{LL} integer suffix
827@cindex @code{ULL} integer suffix
146ef39f 828
3cfa0cc4 829ISO C99 supports data types for integers that are at least 64 bits wide,
32f1f35b 830and as an extension GCC supports them in C90 mode and in C++.
3cfa0cc4 831Simply write @code{long long int} for a signed integer, or
146ef39f 832@code{unsigned long long int} for an unsigned integer. To make an
67791935 833integer constant of type @code{long long int}, add the suffix @samp{LL}
146ef39f 834to the integer. To make an integer constant of type @code{unsigned long
67791935 835long int}, add the suffix @samp{ULL} to the integer.
146ef39f 836
837You can use these types in arithmetic like any other integer types.
838Addition, subtraction, and bitwise boolean operations on these types
839are open-coded on all types of machines. Multiplication is open-coded
840if the machine supports fullword-to-doubleword a widening multiply
841instruction. Division and shifts are open-coded only on machines that
842provide special support. The operations that are not open-coded use
0858e3a2 843special library routines that come with GCC@.
146ef39f 844
845There may be pitfalls when you use @code{long long} types for function
846arguments, unless you declare function prototypes. If a function
847expects type @code{int} for its argument, and you pass a value of type
848@code{long long int}, confusion will result because the caller and the
849subroutine will disagree about the number of bytes for the argument.
850Likewise, if the function expects @code{long long int} and you pass
851@code{int}. The best way to avoid such problems is to use prototypes.
852
853@node Complex
854@section Complex Numbers
855@cindex complex numbers
3cfa0cc4 856@cindex @code{_Complex} keyword
857@cindex @code{__complex__} keyword
146ef39f 858
3cfa0cc4 859ISO C99 supports complex floating data types, and as an extension GCC
32f1f35b 860supports them in C90 mode and in C++, and supports complex integer data
3cfa0cc4 861types which are not part of ISO C99. You can declare complex types
862using the keyword @code{_Complex}. As an extension, the older GNU
863keyword @code{__complex__} is also supported.
146ef39f 864
3cfa0cc4 865For example, @samp{_Complex double x;} declares @code{x} as a
146ef39f 866variable whose real part and imaginary part are both of type
3cfa0cc4 867@code{double}. @samp{_Complex short int y;} declares @code{y} to
146ef39f 868have real and imaginary parts of type @code{short int}; this is not
869likely to be useful, but it shows that the set of complex types is
870complete.
871
872To write a constant with a complex data type, use the suffix @samp{i} or
873@samp{j} (either one; they are equivalent). For example, @code{2.5fi}
3cfa0cc4 874has type @code{_Complex float} and @code{3i} has type
875@code{_Complex int}. Such a constant always has a pure imaginary
146ef39f 876value, but you can form any complex value you like by adding one to a
3cfa0cc4 877real constant. This is a GNU extension; if you have an ISO C99
878conforming C library (such as GNU libc), and want to construct complex
879constants of floating type, you should include @code{<complex.h>} and
880use the macros @code{I} or @code{_Complex_I} instead.
146ef39f 881
3cfa0cc4 882@cindex @code{__real__} keyword
883@cindex @code{__imag__} keyword
146ef39f 884To extract the real part of a complex-valued expression @var{exp}, write
885@code{__real__ @var{exp}}. Likewise, use @code{__imag__} to
3cfa0cc4 886extract the imaginary part. This is a GNU extension; for values of
887floating type, you should use the ISO C99 functions @code{crealf},
888@code{creal}, @code{creall}, @code{cimagf}, @code{cimag} and
889@code{cimagl}, declared in @code{<complex.h>} and also provided as
0858e3a2 890built-in functions by GCC@.
146ef39f 891
3cfa0cc4 892@cindex complex conjugation
146ef39f 893The operator @samp{~} performs complex conjugation when used on a value
3cfa0cc4 894with a complex type. This is a GNU extension; for values of
895floating type, you should use the ISO C99 functions @code{conjf},
896@code{conj} and @code{conjl}, declared in @code{<complex.h>} and also
0858e3a2 897provided as built-in functions by GCC@.
146ef39f 898
37744367 899GCC can allocate complex automatic variables in a noncontiguous
146ef39f 900fashion; it's even possible for the real part to be in a register while
1a050f4e 901the imaginary part is on the stack (or vice-versa). Only the DWARF2
902debug info format can represent this, so use of DWARF2 is recommended.
903If you are using the stabs debug info format, GCC describes a noncontiguous
904complex variable as if it were two separate variables of noncomplex type.
146ef39f 905If the variable's actual name is @code{foo}, the two fictitious
906variables are named @code{foo$real} and @code{foo$imag}. You can
907examine and set these two fictitious variables with your debugger.
908
430be8e2 909@node Floating Types
910@section Additional Floating Types
911@cindex additional floating types
912@cindex @code{__float80} data type
913@cindex @code{__float128} data type
914@cindex @code{w} floating point suffix
915@cindex @code{q} floating point suffix
916@cindex @code{W} floating point suffix
917@cindex @code{Q} floating point suffix
918
919As an extension, the GNU C compiler supports additional floating
920types, @code{__float80} and @code{__float128} to support 80bit
921(@code{XFmode}) and 128 bit (@code{TFmode}) floating types.
922Support for additional types includes the arithmetic operators:
923add, subtract, multiply, divide; unary arithmetic operators;
924relational operators; equality operators; and conversions to and from
925integer and other floating types. Use a suffix @samp{w} or @samp{W}
926in a literal constant of type @code{__float80} and @samp{q} or @samp{Q}
927for @code{_float128}. You can declare complex types using the
928corresponding internal complex type, @code{XCmode} for @code{__float80}
929type and @code{TCmode} for @code{__float128} type:
930
931@smallexample
932typedef _Complex float __attribute__((mode(TC))) _Complex128;
933typedef _Complex float __attribute__((mode(XC))) _Complex80;
934@end smallexample
935
936Not all targets support additional floating point types. @code{__float80}
70a23968 937and @code{__float128} types are supported on i386, x86_64 and ia64 targets.
0f9c87cc 938The @code{__float128} type is supported on hppa HP-UX targets.
430be8e2 939
9b8516be 940@node Half-Precision
941@section Half-Precision Floating Point
942@cindex half-precision floating point
943@cindex @code{__fp16} data type
944
945On ARM targets, GCC supports half-precision (16-bit) floating point via
15b474a2 946the @code{__fp16} type. You must enable this type explicitly
9b8516be 947with the @option{-mfp16-format} command-line option in order to use it.
948
949ARM supports two incompatible representations for half-precision
950floating-point values. You must choose one of the representations and
951use it consistently in your program.
952
953Specifying @option{-mfp16-format=ieee} selects the IEEE 754-2008 format.
954This format can represent normalized values in the range of @math{2^{-14}} to 65504.
955There are 11 bits of significand precision, approximately 3
956decimal digits.
957
958Specifying @option{-mfp16-format=alternative} selects the ARM
959alternative format. This representation is similar to the IEEE
960format, but does not support infinities or NaNs. Instead, the range
961of exponents is extended, so that this format can represent normalized
962values in the range of @math{2^{-14}} to 131008.
963
964The @code{__fp16} type is a storage format only. For purposes
965of arithmetic and other operations, @code{__fp16} values in C or C++
966expressions are automatically promoted to @code{float}. In addition,
15b474a2 967you cannot declare a function with a return value or parameters
9b8516be 968of type @code{__fp16}.
969
970Note that conversions from @code{double} to @code{__fp16}
971involve an intermediate conversion to @code{float}. Because
972of rounding, this can sometimes produce a different result than a
973direct conversion.
974
15b474a2 975ARM provides hardware support for conversions between
9b8516be 976@code{__fp16} and @code{float} values
977as an extension to VFP and NEON (Advanced SIMD). GCC generates
a50d7267 978code using these hardware instructions if you compile with
15b474a2 979options to select an FPU that provides them;
a50d7267 980for example, @option{-mfpu=neon-fp16 -mfloat-abi=softfp},
9b8516be 981in addition to the @option{-mfp16-format} option to select
15b474a2 982a half-precision format.
9b8516be 983
984Language-level support for the @code{__fp16} data type is
985independent of whether GCC generates code using hardware floating-point
986instructions. In cases where hardware support is not specified, GCC
987implements conversions between @code{__fp16} and @code{float} values
988as library calls.
989
c4503c0a 990@node Decimal Float
cded8ad2 991@section Decimal Floating Types
992@cindex decimal floating types
c4503c0a 993@cindex @code{_Decimal32} data type
994@cindex @code{_Decimal64} data type
995@cindex @code{_Decimal128} data type
996@cindex @code{df} integer suffix
997@cindex @code{dd} integer suffix
998@cindex @code{dl} integer suffix
999@cindex @code{DF} integer suffix
1000@cindex @code{DD} integer suffix
1001@cindex @code{DL} integer suffix
1002
cded8ad2 1003As an extension, the GNU C compiler supports decimal floating types as
0e86dff0 1004defined in the N1312 draft of ISO/IEC WDTR24732. Support for decimal
cded8ad2 1005floating types in GCC will evolve as the draft technical report changes.
1006Calling conventions for any target might also change. Not all targets
1007support decimal floating types.
c4503c0a 1008
cded8ad2 1009The decimal floating types are @code{_Decimal32}, @code{_Decimal64}, and
1010@code{_Decimal128}. They use a radix of ten, unlike the floating types
1011@code{float}, @code{double}, and @code{long double} whose radix is not
1012specified by the C standard but is usually two.
1013
1014Support for decimal floating types includes the arithmetic operators
c4503c0a 1015add, subtract, multiply, divide; unary arithmetic operators;
1016relational operators; equality operators; and conversions to and from
cded8ad2 1017integer and other floating types. Use a suffix @samp{df} or
c4503c0a 1018@samp{DF} in a literal constant of type @code{_Decimal32}, @samp{dd}
1019or @samp{DD} for @code{_Decimal64}, and @samp{dl} or @samp{DL} for
1020@code{_Decimal128}.
1021
cded8ad2 1022GCC support of decimal float as specified by the draft technical report
1023is incomplete:
1024
1025@itemize @bullet
cded8ad2 1026@item
1027When the value of a decimal floating type cannot be represented in the
1028integer type to which it is being converted, the result is undefined
1029rather than the result value specified by the draft technical report.
0e86dff0 1030
1031@item
1032GCC does not provide the C library functionality associated with
1033@file{math.h}, @file{fenv.h}, @file{stdio.h}, @file{stdlib.h}, and
1034@file{wchar.h}, which must come from a separate C library implementation.
1035Because of this the GNU C compiler does not define macro
1036@code{__STDC_DEC_FP__} to indicate that the implementation conforms to
1037the technical report.
cded8ad2 1038@end itemize
c4503c0a 1039
1040Types @code{_Decimal32}, @code{_Decimal64}, and @code{_Decimal128}
1041are supported by the DWARF2 debug information format.
1042
75bd5ada 1043@node Hex Floats
caee732e 1044@section Hex Floats
1045@cindex hex floats
7014838c 1046
3cfa0cc4 1047ISO C99 supports floating-point numbers written not only in the usual
75bd5ada 1048decimal notation, such as @code{1.55e1}, but also numbers such as
3cfa0cc4 1049@code{0x1.fp3} written in hexadecimal format. As a GNU extension, GCC
32f1f35b 1050supports this in C90 mode (except in some cases when strictly
3cfa0cc4 1051conforming) and in C++. In that format the
67791935 1052@samp{0x} hex introducer and the @samp{p} or @samp{P} exponent field are
75bd5ada 1053mandatory. The exponent is a decimal number that indicates the power of
67791935 10542 by which the significant part will be multiplied. Thus @samp{0x1.f} is
70c2c81c 1055@tex
1056$1 {15\over16}$,
1057@end tex
1058@ifnottex
10591 15/16,
1060@end ifnottex
1061@samp{p3} multiplies it by 8, and the value of @code{0x1.fp3}
75bd5ada 1062is the same as @code{1.55e1}.
1063
1064Unlike for floating-point numbers in the decimal notation the exponent
1065is always required in the hexadecimal notation. Otherwise the compiler
1066would not be able to resolve the ambiguity of, e.g., @code{0x1.f}. This
67791935 1067could mean @code{1.0f} or @code{1.9375} since @samp{f} is also the
75bd5ada 1068extension for floating-point constants of type @code{float}.
1069
68a556d6 1070@node Fixed-Point
1071@section Fixed-Point Types
1072@cindex fixed-point types
1073@cindex @code{_Fract} data type
1074@cindex @code{_Accum} data type
1075@cindex @code{_Sat} data type
1076@cindex @code{hr} fixed-suffix
1077@cindex @code{r} fixed-suffix
1078@cindex @code{lr} fixed-suffix
1079@cindex @code{llr} fixed-suffix
1080@cindex @code{uhr} fixed-suffix
1081@cindex @code{ur} fixed-suffix
1082@cindex @code{ulr} fixed-suffix
1083@cindex @code{ullr} fixed-suffix
1084@cindex @code{hk} fixed-suffix
1085@cindex @code{k} fixed-suffix
1086@cindex @code{lk} fixed-suffix
1087@cindex @code{llk} fixed-suffix
1088@cindex @code{uhk} fixed-suffix
1089@cindex @code{uk} fixed-suffix
1090@cindex @code{ulk} fixed-suffix
1091@cindex @code{ullk} fixed-suffix
1092@cindex @code{HR} fixed-suffix
1093@cindex @code{R} fixed-suffix
1094@cindex @code{LR} fixed-suffix
1095@cindex @code{LLR} fixed-suffix
1096@cindex @code{UHR} fixed-suffix
1097@cindex @code{UR} fixed-suffix
1098@cindex @code{ULR} fixed-suffix
1099@cindex @code{ULLR} fixed-suffix
1100@cindex @code{HK} fixed-suffix
1101@cindex @code{K} fixed-suffix
1102@cindex @code{LK} fixed-suffix
1103@cindex @code{LLK} fixed-suffix
1104@cindex @code{UHK} fixed-suffix
1105@cindex @code{UK} fixed-suffix
1106@cindex @code{ULK} fixed-suffix
1107@cindex @code{ULLK} fixed-suffix
1108
1109As an extension, the GNU C compiler supports fixed-point types as
1110defined in the N1169 draft of ISO/IEC DTR 18037. Support for fixed-point
1111types in GCC will evolve as the draft technical report changes.
1112Calling conventions for any target might also change. Not all targets
1113support fixed-point types.
1114
1115The fixed-point types are
1116@code{short _Fract},
1117@code{_Fract},
1118@code{long _Fract},
1119@code{long long _Fract},
1120@code{unsigned short _Fract},
1121@code{unsigned _Fract},
1122@code{unsigned long _Fract},
1123@code{unsigned long long _Fract},
1124@code{_Sat short _Fract},
1125@code{_Sat _Fract},
1126@code{_Sat long _Fract},
1127@code{_Sat long long _Fract},
1128@code{_Sat unsigned short _Fract},
1129@code{_Sat unsigned _Fract},
1130@code{_Sat unsigned long _Fract},
1131@code{_Sat unsigned long long _Fract},
1132@code{short _Accum},
1133@code{_Accum},
1134@code{long _Accum},
1135@code{long long _Accum},
1136@code{unsigned short _Accum},
1137@code{unsigned _Accum},
1138@code{unsigned long _Accum},
1139@code{unsigned long long _Accum},
1140@code{_Sat short _Accum},
1141@code{_Sat _Accum},
1142@code{_Sat long _Accum},
1143@code{_Sat long long _Accum},
1144@code{_Sat unsigned short _Accum},
1145@code{_Sat unsigned _Accum},
1146@code{_Sat unsigned long _Accum},
1147@code{_Sat unsigned long long _Accum}.
560db68e 1148
68a556d6 1149Fixed-point data values contain fractional and optional integral parts.
1150The format of fixed-point data varies and depends on the target machine.
1151
560db68e 1152Support for fixed-point types includes:
1153@itemize @bullet
1154@item
1155prefix and postfix increment and decrement operators (@code{++}, @code{--})
1156@item
1157unary arithmetic operators (@code{+}, @code{-}, @code{!})
1158@item
1159binary arithmetic operators (@code{+}, @code{-}, @code{*}, @code{/})
1160@item
1161binary shift operators (@code{<<}, @code{>>})
1162@item
1163relational operators (@code{<}, @code{<=}, @code{>=}, @code{>})
1164@item
1165equality operators (@code{==}, @code{!=})
1166@item
1167assignment operators (@code{+=}, @code{-=}, @code{*=}, @code{/=},
1168@code{<<=}, @code{>>=})
1169@item
1170conversions to and from integer, floating-point, or fixed-point types
1171@end itemize
1172
1173Use a suffix in a fixed-point literal constant:
1174@itemize
1175@item @samp{hr} or @samp{HR} for @code{short _Fract} and
1176@code{_Sat short _Fract}
1177@item @samp{r} or @samp{R} for @code{_Fract} and @code{_Sat _Fract}
1178@item @samp{lr} or @samp{LR} for @code{long _Fract} and
1179@code{_Sat long _Fract}
1180@item @samp{llr} or @samp{LLR} for @code{long long _Fract} and
1181@code{_Sat long long _Fract}
1182@item @samp{uhr} or @samp{UHR} for @code{unsigned short _Fract} and
1183@code{_Sat unsigned short _Fract}
1184@item @samp{ur} or @samp{UR} for @code{unsigned _Fract} and
1185@code{_Sat unsigned _Fract}
1186@item @samp{ulr} or @samp{ULR} for @code{unsigned long _Fract} and
1187@code{_Sat unsigned long _Fract}
1188@item @samp{ullr} or @samp{ULLR} for @code{unsigned long long _Fract}
1189and @code{_Sat unsigned long long _Fract}
1190@item @samp{hk} or @samp{HK} for @code{short _Accum} and
1191@code{_Sat short _Accum}
1192@item @samp{k} or @samp{K} for @code{_Accum} and @code{_Sat _Accum}
1193@item @samp{lk} or @samp{LK} for @code{long _Accum} and
1194@code{_Sat long _Accum}
1195@item @samp{llk} or @samp{LLK} for @code{long long _Accum} and
1196@code{_Sat long long _Accum}
1197@item @samp{uhk} or @samp{UHK} for @code{unsigned short _Accum} and
1198@code{_Sat unsigned short _Accum}
1199@item @samp{uk} or @samp{UK} for @code{unsigned _Accum} and
1200@code{_Sat unsigned _Accum}
1201@item @samp{ulk} or @samp{ULK} for @code{unsigned long _Accum} and
1202@code{_Sat unsigned long _Accum}
1203@item @samp{ullk} or @samp{ULLK} for @code{unsigned long long _Accum}
1204and @code{_Sat unsigned long long _Accum}
1205@end itemize
68a556d6 1206
1207GCC support of fixed-point types as specified by the draft technical report
1208is incomplete:
1209
1210@itemize @bullet
1211@item
1212Pragmas to control overflow and rounding behaviors are not implemented.
1213@end itemize
1214
1215Fixed-point types are supported by the DWARF2 debug information format.
1216
bd1a81f7 1217@node Named Address Spaces
8516b1c4 1218@section Named Address Spaces
1219@cindex Named Address Spaces
bd1a81f7 1220
1221As an extension, the GNU C compiler supports named address spaces as
1222defined in the N1275 draft of ISO/IEC DTR 18037. Support for named
78e515f7 1223address spaces in GCC will evolve as the draft technical report
1224changes. Calling conventions for any target might also change. At
8516b1c4 1225present, only the AVR, SPU, M32C, and RL78 targets support address
1226spaces other than the generic address space.
1227
1228Address space identifiers may be used exactly like any other C type
1229qualifier (e.g., @code{const} or @code{volatile}). See the N1275
1230document for more details.
1231
1232@anchor{AVR Named Address Spaces}
1233@subsection AVR Named Address Spaces
1234
1235On the AVR target, there are several address spaces that can be used
1236in order to put read-only data into the flash memory and access that
1237data by means of the special instructions @code{LPM} or @code{ELPM}
1238needed to read from flash.
1239
6ee532ba 1240Per default, any data including read-only data is located in RAM
1241(the generic address space) so that non-generic address spaces are
1242needed to locate read-only data in flash memory
1243@emph{and} to generate the right instructions to access this data
8516b1c4 1244without using (inline) assembler code.
1245
1246@table @code
590da9f2 1247@item __flash
1248@cindex @code{__flash} AVR Named Address Spaces
1249The @code{__flash} qualifier will locate data in the
8516b1c4 1250@code{.progmem.data} section. Data will be read using the @code{LPM}
1251instruction. Pointers to this address space are 16 bits wide.
1252
590da9f2 1253@item __flash1
1254@item __flash2
1255@item __flash3
1256@item __flash4
1257@item __flash5
1258@cindex @code{__flash1} AVR Named Address Spaces
1259@cindex @code{__flash2} AVR Named Address Spaces
1260@cindex @code{__flash3} AVR Named Address Spaces
1261@cindex @code{__flash4} AVR Named Address Spaces
1262@cindex @code{__flash5} AVR Named Address Spaces
8516b1c4 1263These are 16-bit address spaces locating data in section
1264@code{.progmem@var{N}.data} where @var{N} refers to
590da9f2 1265address space @code{__flash@var{N}}.
8516b1c4 1266The compiler will set the @code{RAMPZ} segment register approptiately
1267before reading data by means of the @code{ELPM} instruction.
1268
590da9f2 1269@item __memx
1270@cindex @code{__memx} AVR Named Address Spaces
8516b1c4 1271This is a 24-bit address space that linearizes flash and RAM:
1272If the high bit of the address is set, data is read from
1273RAM using the lower two bytes as RAM address.
1274If the high bit of the address is clear, data is read from flash
1275with @code{RAMPZ} set according to the high byte of the address.
5a9cc803 1276@xref{AVR Built-in Functions,,@code{__builtin_avr_flash_segment}}.
8516b1c4 1277
1278Objects in this address space will be located in @code{.progmem.data}.
1279@end table
1280
6ee532ba 1281@b{Example}
1282
1283@example
590da9f2 1284char my_read (const __flash char ** p)
6ee532ba 1285@{
1286 /* p is a pointer to RAM that points to a pointer to flash.
1287 The first indirection of p will read that flash pointer
1288 from RAM and the second indirection reads a char from this
1289 flash address. */
1290
1291 return **p;
1292@}
1293
1294/* Locate array[] in flash memory */
590da9f2 1295const __flash int array[] = @{ 3, 5, 7, 11, 13, 17, 19 @};
6ee532ba 1296
1297int i = 1;
1298
1299int main (void)
1300@{
1301 /* Return 17 by reading from flash memory */
1302 return array[array[i]];
1303@}
1304@end example
1305
5a9cc803 1306@noindent
8516b1c4 1307For each named address space supported by avr-gcc there is an equally
1308named but uppercase built-in macro defined.
1309The purpose is to facilitate testing if respective address space
1310support is available or not:
1311
1312@example
590da9f2 1313#ifdef __FLASH
1314const __flash int var = 1;
8516b1c4 1315
6222cbcc 1316int read_var (void)
8516b1c4 1317@{
6222cbcc 1318 return var;
8516b1c4 1319@}
1320#else
6222cbcc 1321#include <avr/pgmspace.h> /* From AVR-LibC */
8516b1c4 1322
1323const int var PROGMEM = 1;
1324
6222cbcc 1325int read_var (void)
8516b1c4 1326@{
6222cbcc 1327 return (int) pgm_read_word (&var);
8516b1c4 1328@}
590da9f2 1329#endif /* __FLASH */
8516b1c4 1330@end example
1331
5a9cc803 1332@noindent
1333Notice that attribute @ref{AVR Variable Attributes,,@code{progmem}}
8516b1c4 1334locates data in flash but
6ee532ba 1335accesses to these data will read from generic address space, i.e.@:
1336from RAM,
1337so that you need special accessors like @code{pgm_read_byte}
6222cbcc 1338from @w{@uref{http://nongnu.org/avr-libc/user-manual,AVR-LibC}}
1339together with attribute @code{progmem}.
8516b1c4 1340
5a9cc803 1341@noindent
8516b1c4 1342@b{Limitations and caveats}
1343
1344@itemize
1345@item
1346Reading across the 64@tie{}KiB section boundary of
590da9f2 1347the @code{__flash} or @code{__flash@var{N}} address spaces
8516b1c4 1348will show undefined behaviour. The only address space that
1349supports reading across the 64@tie{}KiB flash segment boundaries is
590da9f2 1350@code{__memx}.
8516b1c4 1351
1352@item
6222cbcc 1353If you use one of the @code{__flash@var{N}} address spaces
8516b1c4 1354you will have to arrange your linker skript to locate the
1355@code{.progmem@var{N}.data} sections according to your needs.
1356
1357@item
6ee532ba 1358Any data or pointers to the non-generic address spaces must
1359be qualified as @code{const}, i.e.@: as read-only data.
8516b1c4 1360This still applies if the data in one of these address
6ee532ba 1361spaces like software version number or calibration lookup table are intended to
8516b1c4 1362be changed after load time by, say, a boot loader. In this case
1363the right qualification is @code{const} @code{volatile} so that the compiler
1364must not optimize away known values or insert them
1365as immediates into operands of instructions.
1366
1367@item
5a9cc803 1368The following code initializes a variable @code{pfoo}
1369located in static storage with a 24-bit address:
8516b1c4 1370@example
590da9f2 1371extern const __memx char foo;
1372const __memx void *pfoo = &foo;
8516b1c4 1373@end example
5a9cc803 1374Such code requires at least binutils 2.23, see
1375@w{@uref{http://sourceware.org/PR13503,PR13503}}.
8516b1c4 1376
8516b1c4 1377@end itemize
1378
8516b1c4 1379@subsection M32C Named Address Spaces
1380@cindex @code{__far} M32C Named Address Spaces
1381
1382On the M32C target, with the R8C and M16C cpu variants, variables
1383qualified with @code{__far} are accessed using 32-bit addresses in
1384order to access memory beyond the first 64@tie{}Ki bytes. If
1385@code{__far} is used with the M32CM or M32C cpu variants, it has no
1386effect.
1387
1388@subsection RL78 Named Address Spaces
1389@cindex @code{__far} RL78 Named Address Spaces
1390
1391On the RL78 target, variables qualified with @code{__far} are accessed
1392with 32-bit pointers (20-bit addresses) rather than the default 16-bit
1393addresses. Non-far variables are assumed to appear in the topmost
139464@tie{}KiB of the address space.
1395
1396@subsection SPU Named Address Spaces
1397@cindex @code{__ea} SPU Named Address Spaces
1398
1399On the SPU target variables may be declared as
78e515f7 1400belonging to another address space by qualifying the type with the
1401@code{__ea} address space identifier:
bd1a81f7 1402
1403@smallexample
1404extern int __ea i;
1405@end smallexample
1406
1407When the variable @code{i} is accessed, the compiler will generate
1408special code to access this variable. It may use runtime library
1409support, or generate special machine instructions to access that address
1410space.
1411
146ef39f 1412@node Zero Length
1413@section Arrays of Length Zero
1414@cindex arrays of length zero
1415@cindex zero-length arrays
1416@cindex length-zero arrays
21c8999d 1417@cindex flexible array members
146ef39f 1418
0858e3a2 1419Zero-length arrays are allowed in GNU C@. They are very useful as the
15119d83 1420last element of a structure which is really a header for a variable-length
146ef39f 1421object:
1422
a0ecd6b1 1423@smallexample
146ef39f 1424struct line @{
1425 int length;
1426 char contents[0];
1427@};
1428
15119d83 1429struct line *thisline = (struct line *)
1430 malloc (sizeof (struct line) + this_length);
1431thisline->length = this_length;
a0ecd6b1 1432@end smallexample
146ef39f 1433
7fb9818b 1434In ISO C90, you would have to give @code{contents} a length of 1, which
146ef39f 1435means either you waste space or complicate the argument to @code{malloc}.
1436
3b0848a2 1437In ISO C99, you would use a @dfn{flexible array member}, which is
15119d83 1438slightly different in syntax and semantics:
1439
1440@itemize @bullet
1441@item
1442Flexible array members are written as @code{contents[]} without
1443the @code{0}.
1444
1445@item
1446Flexible array members have incomplete type, and so the @code{sizeof}
1447operator may not be applied. As a quirk of the original implementation
1448of zero-length arrays, @code{sizeof} evaluates to zero.
1449
1450@item
1451Flexible array members may only appear as the last member of a
26877a3f 1452@code{struct} that is otherwise non-empty.
ce09bc13 1453
1454@item
1455A structure containing a flexible array member, or a union containing
1456such a structure (possibly recursively), may not be a member of a
1457structure or an element of an array. (However, these uses are
1458permitted by GCC as extensions.)
21c8999d 1459@end itemize
1b82e858 1460
21c8999d 1461GCC versions before 3.0 allowed zero-length arrays to be statically
26877a3f 1462initialized, as if they were flexible arrays. In addition to those
1463cases that were useful, it also allowed initializations in situations
1464that would corrupt later data. Non-empty initialization of zero-length
1465arrays is now treated like any case where there are more initializer
1466elements than the array holds, in that a suitable warning about "excess
1467elements in array" is given, and the excess elements (all of them, in
1468this case) are ignored.
21c8999d 1469
1470Instead GCC allows static initialization of flexible array members.
1471This is equivalent to defining a new structure containing the original
1472structure followed by an array of sufficient size to contain the data.
0858f8a2 1473I.e.@: in the following, @code{f1} is constructed as if it were declared
21c8999d 1474like @code{f2}.
1b82e858 1475
a0ecd6b1 1476@smallexample
21c8999d 1477struct f1 @{
1478 int x; int y[];
1479@} f1 = @{ 1, @{ 2, 3, 4 @} @};
1480
1481struct f2 @{
1482 struct f1 f1; int data[3];
1483@} f2 = @{ @{ 1 @}, @{ 2, 3, 4 @} @};
a0ecd6b1 1484@end smallexample
15119d83 1485
21c8999d 1486@noindent
1487The convenience of this extension is that @code{f1} has the desired
1488type, eliminating the need to consistently refer to @code{f2.f1}.
1489
1490This has symmetry with normal static arrays, in that an array of
1491unknown size is also written with @code{[]}.
1b82e858 1492
21c8999d 1493Of course, this extension only makes sense if the extra data comes at
1494the end of a top-level object, as otherwise we would be overwriting
1495data at subsequent offsets. To avoid undue complication and confusion
1496with initialization of deeply nested arrays, we simply disallow any
1497non-empty initialization except when the structure is the top-level
1498object. For example:
15119d83 1499
a0ecd6b1 1500@smallexample
21c8999d 1501struct foo @{ int x; int y[]; @};
1502struct bar @{ struct foo z; @};
1503
afb00aa2 1504struct foo a = @{ 1, @{ 2, 3, 4 @} @}; // @r{Valid.}
1505struct bar b = @{ @{ 1, @{ 2, 3, 4 @} @} @}; // @r{Invalid.}
1506struct bar c = @{ @{ 1, @{ @} @} @}; // @r{Valid.}
1507struct foo d[1] = @{ @{ 1 @{ 2, 3, 4 @} @} @}; // @r{Invalid.}
a0ecd6b1 1508@end smallexample
eae914e2 1509
710d60ed 1510@node Empty Structures
1511@section Structures With No Members
1512@cindex empty structures
1513@cindex zero-size structures
1514
1515GCC permits a C structure to have no members:
1516
a0ecd6b1 1517@smallexample
710d60ed 1518struct empty @{
1519@};
a0ecd6b1 1520@end smallexample
710d60ed 1521
1522The structure will have size zero. In C++, empty structures are part
907e3369 1523of the language. G++ treats empty structures as if they had a single
1524member of type @code{char}.
710d60ed 1525
146ef39f 1526@node Variable Length
1527@section Arrays of Variable Length
1528@cindex variable-length arrays
1529@cindex arrays of variable length
3cfa0cc4 1530@cindex VLAs
146ef39f 1531
3cfa0cc4 1532Variable-length automatic arrays are allowed in ISO C99, and as an
15334b7a 1533extension GCC accepts them in C90 mode and in C++. These arrays are
146ef39f 1534declared like any other automatic arrays, but with a length that is not
1535a constant expression. The storage is allocated at the point of
1536declaration and deallocated when the brace-level is exited. For
1537example:
1538
a0ecd6b1 1539@smallexample
146ef39f 1540FILE *
1541concat_fopen (char *s1, char *s2, char *mode)
1542@{
1543 char str[strlen (s1) + strlen (s2) + 1];
1544 strcpy (str, s1);
1545 strcat (str, s2);
1546 return fopen (str, mode);
1547@}
a0ecd6b1 1548@end smallexample
146ef39f 1549
1550@cindex scope of a variable length array
1551@cindex variable-length array scope
1552@cindex deallocating variable length arrays
1553Jumping or breaking out of the scope of the array name deallocates the
1554storage. Jumping into the scope is not allowed; you get an error
1555message for it.
1556
1557@cindex @code{alloca} vs variable-length arrays
1558You can use the function @code{alloca} to get an effect much like
1559variable-length arrays. The function @code{alloca} is available in
1560many other C implementations (but not in all). On the other hand,
1561variable-length arrays are more elegant.
1562
1563There are other differences between these two methods. Space allocated
1564with @code{alloca} exists until the containing @emph{function} returns.
1565The space for a variable-length array is deallocated as soon as the array
1566name's scope ends. (If you use both variable-length arrays and
1567@code{alloca} in the same function, deallocation of a variable-length array
1568will also deallocate anything more recently allocated with @code{alloca}.)
1569
1570You can also use variable-length arrays as arguments to functions:
1571
a0ecd6b1 1572@smallexample
146ef39f 1573struct entry
1574tester (int len, char data[len][len])
1575@{
4ae74ddd 1576 /* @r{@dots{}} */
146ef39f 1577@}
a0ecd6b1 1578@end smallexample
146ef39f 1579
1580The length of an array is computed once when the storage is allocated
1581and is remembered for the scope of the array in case you access it with
1582@code{sizeof}.
1583
1584If you want to pass the array first and the length afterward, you can
1585use a forward declaration in the parameter list---another GNU extension.
1586
a0ecd6b1 1587@smallexample
146ef39f 1588struct entry
1589tester (int len; char data[len][len], int len)
1590@{
4ae74ddd 1591 /* @r{@dots{}} */
146ef39f 1592@}
a0ecd6b1 1593@end smallexample
146ef39f 1594
1595@cindex parameter forward declaration
1596The @samp{int len} before the semicolon is a @dfn{parameter forward
1597declaration}, and it serves the purpose of making the name @code{len}
1598known when the declaration of @code{data} is parsed.
1599
1600You can write any number of such parameter forward declarations in the
1601parameter list. They can be separated by commas or semicolons, but the
1602last one must end with a semicolon, which is followed by the ``real''
1603parameter declarations. Each forward declaration must match a ``real''
3cfa0cc4 1604declaration in parameter name and data type. ISO C99 does not support
1605parameter forward declarations.
146ef39f 1606
da825954 1607@node Variadic Macros
1608@section Macros with a Variable Number of Arguments.
146ef39f 1609@cindex variable number of arguments
1610@cindex macro with variable arguments
1611@cindex rest argument (in macro)
da825954 1612@cindex variadic macros
146ef39f 1613
da825954 1614In the ISO C standard of 1999, a macro can be declared to accept a
1615variable number of arguments much as a function can. The syntax for
1616defining the macro is similar to that of a function. Here is an
1617example:
146ef39f 1618
b724fad7 1619@smallexample
da825954 1620#define debug(format, ...) fprintf (stderr, format, __VA_ARGS__)
b724fad7 1621@end smallexample
146ef39f 1622
da825954 1623Here @samp{@dots{}} is a @dfn{variable argument}. In the invocation of
1624such a macro, it represents the zero or more tokens until the closing
1625parenthesis that ends the invocation, including any commas. This set of
1626tokens replaces the identifier @code{__VA_ARGS__} in the macro body
1627wherever it appears. See the CPP manual for more information.
1628
1629GCC has long supported variadic macros, and used a different syntax that
1630allowed you to give a name to the variable arguments just like any other
1631argument. Here is an example:
146ef39f 1632
a0ecd6b1 1633@smallexample
da825954 1634#define debug(format, args...) fprintf (stderr, format, args)
a0ecd6b1 1635@end smallexample
146ef39f 1636
da825954 1637This is in all ways equivalent to the ISO C example above, but arguably
1638more readable and descriptive.
146ef39f 1639
da825954 1640GNU CPP has two further variadic macro extensions, and permits them to
1641be used with either of the above forms of macro definition.
1642
1643In standard C, you are not allowed to leave the variable argument out
1644entirely; but you are allowed to pass an empty argument. For example,
1645this invocation is invalid in ISO C, because there is no comma after
1646the string:
146ef39f 1647
a0ecd6b1 1648@smallexample
da825954 1649debug ("A message")
a0ecd6b1 1650@end smallexample
146ef39f 1651
da825954 1652GNU CPP permits you to completely omit the variable arguments in this
1653way. In the above examples, the compiler would complain, though since
1654the expansion of the macro still has the extra comma after the format
1655string.
1656
1657To help solve this problem, CPP behaves specially for variable arguments
1658used with the token paste operator, @samp{##}. If instead you write
146ef39f 1659
b724fad7 1660@smallexample
da825954 1661#define debug(format, ...) fprintf (stderr, format, ## __VA_ARGS__)
b724fad7 1662@end smallexample
146ef39f 1663
da825954 1664and if the variable arguments are omitted or empty, the @samp{##}
1665operator causes the preprocessor to remove the comma before it. If you
1666do provide some variable arguments in your macro invocation, GNU CPP
1667does not complain about the paste operation and instead places the
1668variable arguments after the comma. Just like any other pasted macro
1669argument, these arguments are not macro expanded.
1670
1671@node Escaped Newlines
1672@section Slightly Looser Rules for Escaped Newlines
1673@cindex escaped newlines
1674@cindex newlines (escaped)
1675
455730ef 1676Recently, the preprocessor has relaxed its treatment of escaped
1677newlines. Previously, the newline had to immediately follow a
ebc03810 1678backslash. The current implementation allows whitespace in the form
1679of spaces, horizontal and vertical tabs, and form feeds between the
da825954 1680backslash and the subsequent newline. The preprocessor issues a
1681warning, but treats it as a valid escaped newline and combines the two
1682lines to form a single logical line. This works within comments and
ebc03810 1683tokens, as well as between tokens. Comments are @emph{not} treated as
1684whitespace for the purposes of this relaxation, since they have not
1685yet been replaced with spaces.
146ef39f 1686
1687@node Subscripting
1688@section Non-Lvalue Arrays May Have Subscripts
1689@cindex subscripting
1690@cindex arrays, non-lvalue
1691
1692@cindex subscripting and function values
62827f44 1693In ISO C99, arrays that are not lvalues still decay to pointers, and
1694may be subscripted, although they may not be modified or used after
1695the next sequence point and the unary @samp{&} operator may not be
1696applied to them. As an extension, GCC allows such arrays to be
32f1f35b 1697subscripted in C90 mode, though otherwise they do not decay to
62827f44 1698pointers outside C99 mode. For example,
32f1f35b 1699this is valid in GNU C though not valid in C90:
146ef39f 1700
a0ecd6b1 1701@smallexample
146ef39f 1702@group
1703struct foo @{int a[4];@};
1704
1705struct foo f();
1706
1707bar (int index)
1708@{
1709 return f().a[index];
1710@}
1711@end group
a0ecd6b1 1712@end smallexample
146ef39f 1713
1714@node Pointer Arith
1715@section Arithmetic on @code{void}- and Function-Pointers
1716@cindex void pointers, arithmetic
1717@cindex void, size of pointer to
1718@cindex function pointers, arithmetic
1719@cindex function, size of pointer to
1720
1721In GNU C, addition and subtraction operations are supported on pointers to
1722@code{void} and on pointers to functions. This is done by treating the
1723size of a @code{void} or of a function as 1.
1724
1725A consequence of this is that @code{sizeof} is also allowed on @code{void}
1726and on function types, and returns 1.
1727
67791935 1728@opindex Wpointer-arith
1729The option @option{-Wpointer-arith} requests a warning if these extensions
146ef39f 1730are used.
1731
1732@node Initializers
1733@section Non-Constant Initializers
1734@cindex initializers, non-constant
1735@cindex non-constant initializers
1736
3cfa0cc4 1737As in standard C++ and ISO C99, the elements of an aggregate initializer for an
0858e3a2 1738automatic variable are not required to be constant expressions in GNU C@.
146ef39f 1739Here is an example of an initializer with run-time varying elements:
1740
a0ecd6b1 1741@smallexample
146ef39f 1742foo (float f, float g)
1743@{
1744 float beat_freqs[2] = @{ f-g, f+g @};
4ae74ddd 1745 /* @r{@dots{}} */
146ef39f 1746@}
a0ecd6b1 1747@end smallexample
146ef39f 1748
3cfa0cc4 1749@node Compound Literals
1750@section Compound Literals
146ef39f 1751@cindex constructor expressions
1752@cindex initializations in expressions
1753@cindex structures, constructor expression
1754@cindex expressions, constructor
3cfa0cc4 1755@cindex compound literals
1756@c The GNU C name for what C99 calls compound literals was "constructor expressions".
146ef39f 1757
3cfa0cc4 1758ISO C99 supports compound literals. A compound literal looks like
146ef39f 1759a cast containing an initializer. Its value is an object of the
1760type specified in the cast, containing the elements specified in
ec11e38e 1761the initializer; it is an lvalue. As an extension, GCC supports
eb5d9b7b 1762compound literals in C90 mode and in C++, though the semantics are
1763somewhat different in C++.
146ef39f 1764
1765Usually, the specified type is a structure. Assume that
1766@code{struct foo} and @code{structure} are declared as shown:
1767
a0ecd6b1 1768@smallexample
146ef39f 1769struct foo @{int a; char b[2];@} structure;
a0ecd6b1 1770@end smallexample
146ef39f 1771
1772@noindent
3cfa0cc4 1773Here is an example of constructing a @code{struct foo} with a compound literal:
146ef39f 1774
a0ecd6b1 1775@smallexample
146ef39f 1776structure = ((struct foo) @{x + y, 'a', 0@});
a0ecd6b1 1777@end smallexample
146ef39f 1778
1779@noindent
1780This is equivalent to writing the following:
1781
a0ecd6b1 1782@smallexample
146ef39f 1783@{
1784 struct foo temp = @{x + y, 'a', 0@};
1785 structure = temp;
1786@}
a0ecd6b1 1787@end smallexample
146ef39f 1788
eb5d9b7b 1789You can also construct an array, though this is dangerous in C++, as
1790explained below. If all the elements of the compound literal are
1791(made up of) simple constant expressions, suitable for use in
ec11e38e 1792initializers of objects of static storage duration, then the compound
1793literal can be coerced to a pointer to its first element and used in
1794such an initializer, as shown here:
146ef39f 1795
a0ecd6b1 1796@smallexample
146ef39f 1797char **foo = (char *[]) @{ "x", "y", "z" @};
a0ecd6b1 1798@end smallexample
146ef39f 1799
f3b11bf1 1800Compound literals for scalar types and union types are
3cfa0cc4 1801also allowed, but then the compound literal is equivalent
146ef39f 1802to a cast.
1803
4619fc15 1804As a GNU extension, GCC allows initialization of objects with static storage
1805duration by compound literals (which is not possible in ISO C99, because
1806the initializer is not a constant).
1807It is handled as if the object was initialized only with the bracket
d1c59264 1808enclosed list if the types of the compound literal and the object match.
4619fc15 1809The initializer list of the compound literal must be constant.
1810If the object being initialized has array type of unknown size, the size is
02643ebc 1811determined by compound literal size.
4619fc15 1812
a0ecd6b1 1813@smallexample
4619fc15 1814static struct foo x = (struct foo) @{1, 'a', 'b'@};
1815static int y[] = (int []) @{1, 2, 3@};
1816static int z[] = (int [3]) @{1@};
a0ecd6b1 1817@end smallexample
4619fc15 1818
1819@noindent
1820The above lines are equivalent to the following:
a0ecd6b1 1821@smallexample
4619fc15 1822static struct foo x = @{1, 'a', 'b'@};
1823static int y[] = @{1, 2, 3@};
02643ebc 1824static int z[] = @{1, 0, 0@};
a0ecd6b1 1825@end smallexample
4619fc15 1826
eb5d9b7b 1827In C, a compound literal designates an unnamed object with static or
1828automatic storage duration. In C++, a compound literal designates a
1829temporary object, which only lives until the end of its
1830full-expression. As a result, well-defined C code that takes the
1831address of a subobject of a compound literal can be undefined in C++.
1832For instance, if the array compound literal example above appeared
1833inside a function, any subsequent use of @samp{foo} in C++ has
1834undefined behavior because the lifetime of the array ends after the
1835declaration of @samp{foo}. As a result, the C++ compiler now rejects
1836the conversion of a temporary array to a pointer.
1837
1838As an optimization, the C++ compiler sometimes gives array compound
1839literals longer lifetimes: when the array either appears outside a
1840function or has const-qualified type. If @samp{foo} and its
1841initializer had elements of @samp{char *const} type rather than
1842@samp{char *}, or if @samp{foo} were a global variable, the array
1843would have static storage duration. But it is probably safest just to
1844avoid the use of array compound literals in code compiled as C++.
1845
3cfa0cc4 1846@node Designated Inits
1847@section Designated Initializers
146ef39f 1848@cindex initializers with labeled elements
1849@cindex labeled elements in initializers
1850@cindex case labels in initializers
3cfa0cc4 1851@cindex designated initializers
146ef39f 1852
32f1f35b 1853Standard C90 requires the elements of an initializer to appear in a fixed
146ef39f 1854order, the same as the order of the elements in the array or structure
1855being initialized.
1856
31bd149b 1857In ISO C99 you can give the elements in any order, specifying the array
1858indices or structure field names they apply to, and GNU C allows this as
32f1f35b 1859an extension in C90 mode as well. This extension is not
146ef39f 1860implemented in GNU C++.
1861
31bd149b 1862To specify an array index, write
146ef39f 1863@samp{[@var{index}] =} before the element value. For example,
1864
a0ecd6b1 1865@smallexample
31bd149b 1866int a[6] = @{ [4] = 29, [2] = 15 @};
a0ecd6b1 1867@end smallexample
146ef39f 1868
1869@noindent
1870is equivalent to
1871
a0ecd6b1 1872@smallexample
146ef39f 1873int a[6] = @{ 0, 0, 15, 0, 29, 0 @};
a0ecd6b1 1874@end smallexample
146ef39f 1875
1876@noindent
1877The index values must be constant expressions, even if the array being
1878initialized is automatic.
1879
31bd149b 1880An alternative syntax for this which has been obsolete since GCC 2.5 but
1881GCC still accepts is to write @samp{[@var{index}]} before the element
1882value, with no @samp{=}.
1883
146ef39f 1884To initialize a range of elements to the same value, write
31bd149b 1885@samp{[@var{first} ... @var{last}] = @var{value}}. This is a GNU
1886extension. For example,
146ef39f 1887
a0ecd6b1 1888@smallexample
146ef39f 1889int widths[] = @{ [0 ... 9] = 1, [10 ... 99] = 2, [100] = 3 @};
a0ecd6b1 1890@end smallexample
146ef39f 1891
989bbcfc 1892@noindent
1893If the value in it has side-effects, the side-effects will happen only once,
1894not for each initialized field by the range initializer.
1895
146ef39f 1896@noindent
1897Note that the length of the array is the highest value specified
1898plus one.
1899
1900In a structure initializer, specify the name of a field to initialize
31bd149b 1901with @samp{.@var{fieldname} =} before the element value. For example,
146ef39f 1902given the following structure,
1903
a0ecd6b1 1904@smallexample
146ef39f 1905struct point @{ int x, y; @};
a0ecd6b1 1906@end smallexample
146ef39f 1907
1908@noindent
1909the following initialization
1910
a0ecd6b1 1911@smallexample
31bd149b 1912struct point p = @{ .y = yvalue, .x = xvalue @};
a0ecd6b1 1913@end smallexample
146ef39f 1914
1915@noindent
1916is equivalent to
1917
a0ecd6b1 1918@smallexample
146ef39f 1919struct point p = @{ xvalue, yvalue @};
a0ecd6b1 1920@end smallexample
146ef39f 1921
31bd149b 1922Another syntax which has the same meaning, obsolete since GCC 2.5, is
1923@samp{@var{fieldname}:}, as shown here:
146ef39f 1924
a0ecd6b1 1925@smallexample
31bd149b 1926struct point p = @{ y: yvalue, x: xvalue @};
a0ecd6b1 1927@end smallexample
146ef39f 1928
3cfa0cc4 1929@cindex designators
1930The @samp{[@var{index}]} or @samp{.@var{fieldname}} is known as a
1931@dfn{designator}. You can also use a designator (or the obsolete colon
1932syntax) when initializing a union, to specify which element of the union
1933should be used. For example,
146ef39f 1934
a0ecd6b1 1935@smallexample
146ef39f 1936union foo @{ int i; double d; @};
1937
31bd149b 1938union foo f = @{ .d = 4 @};
a0ecd6b1 1939@end smallexample
146ef39f 1940
1941@noindent
1942will convert 4 to a @code{double} to store it in the union using
1943the second element. By contrast, casting 4 to type @code{union foo}
1944would store it into the union as the integer @code{i}, since it is
1945an integer. (@xref{Cast to Union}.)
1946
1947You can combine this technique of naming elements with ordinary C
1948initialization of successive elements. Each initializer element that
3cfa0cc4 1949does not have a designator applies to the next consecutive element of the
146ef39f 1950array or structure. For example,
1951
a0ecd6b1 1952@smallexample
146ef39f 1953int a[6] = @{ [1] = v1, v2, [4] = v4 @};
a0ecd6b1 1954@end smallexample
146ef39f 1955
1956@noindent
1957is equivalent to
1958
a0ecd6b1 1959@smallexample
146ef39f 1960int a[6] = @{ 0, v1, v2, 0, v4, 0 @};
a0ecd6b1 1961@end smallexample
146ef39f 1962
1963Labeling the elements of an array initializer is especially useful
1964when the indices are characters or belong to an @code{enum} type.
1965For example:
1966
a0ecd6b1 1967@smallexample
146ef39f 1968int whitespace[256]
1969 = @{ [' '] = 1, ['\t'] = 1, ['\h'] = 1,
1970 ['\f'] = 1, ['\n'] = 1, ['\r'] = 1 @};
a0ecd6b1 1971@end smallexample
146ef39f 1972
3cfa0cc4 1973@cindex designator lists
31bd149b 1974You can also write a series of @samp{.@var{fieldname}} and
3cfa0cc4 1975@samp{[@var{index}]} designators before an @samp{=} to specify a
31bd149b 1976nested subobject to initialize; the list is taken relative to the
1977subobject corresponding to the closest surrounding brace pair. For
1978example, with the @samp{struct point} declaration above:
1979
b724fad7 1980@smallexample
31bd149b 1981struct point ptarray[10] = @{ [2].y = yv2, [2].x = xv2, [0].x = xv0 @};
b724fad7 1982@end smallexample
31bd149b 1983
989bbcfc 1984@noindent
1985If the same field is initialized multiple times, it will have value from
1986the last initialization. If any such overridden initialization has
1987side-effect, it is unspecified whether the side-effect happens or not.
ef8d967c 1988Currently, GCC will discard them and issue a warning.
989bbcfc 1989
146ef39f 1990@node Case Ranges
1991@section Case Ranges
1992@cindex case ranges
1993@cindex ranges in case statements
1994
1995You can specify a range of consecutive values in a single @code{case} label,
1996like this:
1997
a0ecd6b1 1998@smallexample
146ef39f 1999case @var{low} ... @var{high}:
a0ecd6b1 2000@end smallexample
146ef39f 2001
2002@noindent
2003This has the same effect as the proper number of individual @code{case}
2004labels, one for each integer value from @var{low} to @var{high}, inclusive.
2005
2006This feature is especially useful for ranges of ASCII character codes:
2007
a0ecd6b1 2008@smallexample
146ef39f 2009case 'A' ... 'Z':
a0ecd6b1 2010@end smallexample
146ef39f 2011
2012@strong{Be careful:} Write spaces around the @code{...}, for otherwise
2013it may be parsed wrong when you use it with integer values. For example,
2014write this:
2015
a0ecd6b1 2016@smallexample
146ef39f 2017case 1 ... 5:
a0ecd6b1 2018@end smallexample
146ef39f 2019
2020@noindent
2021rather than this:
2022
a0ecd6b1 2023@smallexample
146ef39f 2024case 1...5:
a0ecd6b1 2025@end smallexample
146ef39f 2026
2027@node Cast to Union
2028@section Cast to a Union Type
2029@cindex cast to a union
2030@cindex union, casting to a
2031
2032A cast to union type is similar to other casts, except that the type
2033specified is a union type. You can specify the type either with
2034@code{union @var{tag}} or with a typedef name. A cast to union is actually
2035a constructor though, not a cast, and hence does not yield an lvalue like
3cfa0cc4 2036normal casts. (@xref{Compound Literals}.)
146ef39f 2037
2038The types that may be cast to the union type are those of the members
2039of the union. Thus, given the following union and variables:
2040
a0ecd6b1 2041@smallexample
146ef39f 2042union foo @{ int i; double d; @};
2043int x;
2044double y;
a0ecd6b1 2045@end smallexample
146ef39f 2046
2047@noindent
70c2c81c 2048both @code{x} and @code{y} can be cast to type @code{union foo}.
146ef39f 2049
2050Using the cast as the right-hand side of an assignment to a variable of
2051union type is equivalent to storing in a member of the union:
2052
a0ecd6b1 2053@smallexample
146ef39f 2054union foo u;
4ae74ddd 2055/* @r{@dots{}} */
146ef39f 2056u = (union foo) x @equiv{} u.i = x
2057u = (union foo) y @equiv{} u.d = y
a0ecd6b1 2058@end smallexample
146ef39f 2059
2060You can also use the union cast as a function argument:
2061
a0ecd6b1 2062@smallexample
146ef39f 2063void hack (union foo);
4ae74ddd 2064/* @r{@dots{}} */
146ef39f 2065hack ((union foo) x);
a0ecd6b1 2066@end smallexample
146ef39f 2067
3cfa0cc4 2068@node Mixed Declarations
2069@section Mixed Declarations and Code
2070@cindex mixed declarations and code
2071@cindex declarations, mixed with code
2072@cindex code, mixed with declarations
2073
2074ISO C99 and ISO C++ allow declarations and code to be freely mixed
2075within compound statements. As an extension, GCC also allows this in
32f1f35b 2076C90 mode. For example, you could do:
3cfa0cc4 2077
a0ecd6b1 2078@smallexample
3cfa0cc4 2079int i;
4ae74ddd 2080/* @r{@dots{}} */
3cfa0cc4 2081i++;
2082int j = i + 2;
a0ecd6b1 2083@end smallexample
3cfa0cc4 2084
2085Each identifier is visible from where it is declared until the end of
2086the enclosing block.
2087
146ef39f 2088@node Function Attributes
2089@section Declaring Attributes of Functions
2090@cindex function attributes
2091@cindex declaring attributes of functions
2092@cindex functions that never return
26d1c5ff 2093@cindex functions that return more than once
146ef39f 2094@cindex functions that have no side effects
2095@cindex functions in arbitrary sections
1caefcbd 2096@cindex functions that behave like malloc
146ef39f 2097@cindex @code{volatile} applied to function
2098@cindex @code{const} applied to function
6a87209c 2099@cindex functions with @code{printf}, @code{scanf}, @code{strftime} or @code{strfmon} style arguments
dbf6c367 2100@cindex functions with non-null pointer arguments
146ef39f 2101@cindex functions that are passed arguments in registers on the 386
2102@cindex functions that pop the argument stack on the 386
2103@cindex functions that do not pop the argument stack on the 386
46f8e3b0 2104@cindex functions that have different compilation options on the 386
2105@cindex functions that have different optimization options
85c0a25c 2106@cindex functions that are dynamically resolved
146ef39f 2107
2108In GNU C, you declare certain things about functions called in your program
2109which help the compiler optimize function calls and check your code more
2110carefully.
2111
2112The keyword @code{__attribute__} allows you to specify special
2113attributes when making a declaration. This keyword is followed by an
93f10b04 2114attribute specification inside double parentheses. The following
b28b3cd2 2115attributes are currently defined for functions on all targets:
097b5c8b 2116@code{aligned}, @code{alloc_size}, @code{noreturn},
bdb1f0d1 2117@code{returns_twice}, @code{noinline}, @code{noclone},
2118@code{always_inline}, @code{flatten}, @code{pure}, @code{const},
2119@code{nothrow}, @code{sentinel}, @code{format}, @code{format_arg},
48b14f50 2120@code{no_instrument_function}, @code{no_split_stack},
2121@code{section}, @code{constructor},
4a29c97c 2122@code{destructor}, @code{used}, @code{unused}, @code{deprecated},
85c0a25c 2123@code{weak}, @code{malloc}, @code{alias}, @code{ifunc},
2124@code{warn_unused_result}, @code{nonnull}, @code{gnu_inline},
2125@code{externally_visible}, @code{hot}, @code{cold}, @code{artificial},
2126@code{error} and @code{warning}. Several other attributes are defined
2127for functions on particular target systems. Other attributes,
2128including @code{section} are supported for variables declarations
2129(@pxref{Variable Attributes}) and for types (@pxref{Type Attributes}).
146ef39f 2130
2dc819f3 2131GCC plugins may provide their own attributes.
2132
146ef39f 2133You may also specify attributes with @samp{__} preceding and following
2134each keyword. This allows you to use them in header files without
2135being concerned about a possible macro of the same name. For example,
2136you may use @code{__noreturn__} instead of @code{noreturn}.
2137
b31bfb3f 2138@xref{Attribute Syntax}, for details of the exact syntax for using
2139attributes.
2140
146ef39f 2141@table @code
b3d47662 2142@c Keep this table alphabetized by attribute name. Treat _ as space.
146ef39f 2143
7c85682d 2144@item alias ("@var{target}")
2145@cindex @code{alias} attribute
2146The @code{alias} attribute causes the declaration to be emitted as an
2147alias for another symbol, which must be specified. For instance,
146ef39f 2148
2149@smallexample
7c85682d 2150void __f () @{ /* @r{Do something.} */; @}
2151void f () __attribute__ ((weak, alias ("__f")));
146ef39f 2152@end smallexample
2153
0a3ecdc1 2154defines @samp{f} to be a weak alias for @samp{__f}. In C++, the
b60f73dc 2155mangled name for the target must be used. It is an error if @samp{__f}
2156is not defined in the same translation unit.
7c85682d 2157
2158Not all target machines support this attribute.
93f10b04 2159
097b5c8b 2160@item aligned (@var{alignment})
2161@cindex @code{aligned} attribute
2162This attribute specifies a minimum alignment for the function,
2163measured in bytes.
2164
2165You cannot use this attribute to decrease the alignment of a function,
2166only to increase it. However, when you explicitly specify a function
2167alignment this will override the effect of the
2168@option{-falign-functions} (@pxref{Optimize Options}) option for this
2169function.
2170
2171Note that the effectiveness of @code{aligned} attributes may be
2172limited by inherent limitations in your linker. On many systems, the
2173linker is only able to arrange for functions to be aligned up to a
2174certain maximum alignment. (For some linkers, the maximum supported
2175alignment may be very very small.) See your linker documentation for
2176further information.
2177
2178The @code{aligned} attribute can also be used for variables and fields
2179(@pxref{Variable Attributes}.)
2180
4a29c97c 2181@item alloc_size
2182@cindex @code{alloc_size} attribute
2183The @code{alloc_size} attribute is used to tell the compiler that the
2184function return value points to memory, where the size is given by
15b474a2 2185one or two of the functions parameters. GCC uses this
4a29c97c 2186information to improve the correctness of @code{__builtin_object_size}.
2187
2188The function parameter(s) denoting the allocated size are specified by
2189one or two integer arguments supplied to the attribute. The allocated size
2190is either the value of the single function argument specified or the product
2191of the two function arguments specified. Argument numbering starts at
2192one.
2193
15b474a2 2194For instance,
4a29c97c 2195
2196@smallexample
2197void* my_calloc(size_t, size_t) __attribute__((alloc_size(1,2)))
9d5b78d0 2198void my_realloc(void*, size_t) __attribute__((alloc_size(2)))
4a29c97c 2199@end smallexample
2200
2201declares that my_calloc will return memory of the size given by
2202the product of parameter 1 and 2 and that my_realloc will return memory
2203of the size given by parameter 2.
2204
af87ad83 2205@item always_inline
7c85682d 2206@cindex @code{always_inline} function attribute
af87ad83 2207Generally, functions are not inlined unless optimization is specified.
2208For functions declared inline, this attribute inlines the function even
2209if no optimization level was specified.
2210
541e4101 2211@item gnu_inline
2212@cindex @code{gnu_inline} function attribute
11950bdd 2213This attribute should be used with a function which is also declared
2214with the @code{inline} keyword. It directs GCC to treat the function
32f1f35b 2215as if it were defined in gnu90 mode even when compiling in C99 or
11950bdd 2216gnu99 mode.
2217
2218If the function is declared @code{extern}, then this definition of the
2219function is used only for inlining. In no case is the function
2220compiled as a standalone function, not even if you take its address
2221explicitly. Such an address becomes an external reference, as if you
2222had only declared the function, and had not defined it. This has
2223almost the effect of a macro. The way to use this is to put a
2224function definition in a header file with this attribute, and put
2225another copy of the function, without @code{extern}, in a library
2226file. The definition in the header file will cause most calls to the
2227function to be inlined. If any uses of the function remain, they will
2228refer to the single copy in the library. Note that the two
2229definitions of the functions need not be precisely the same, although
2230if they do not have the same effect your program may behave oddly.
2231
db577900 2232In C, if the function is neither @code{extern} nor @code{static}, then
2233the function is compiled as a standalone function, as well as being
11950bdd 2234inlined where possible.
2235
2236This is how GCC traditionally handled functions declared
2237@code{inline}. Since ISO C99 specifies a different semantics for
2238@code{inline}, this function attribute is provided as a transition
2239measure and as a useful feature in its own right. This attribute is
2240available in GCC 4.1.3 and later. It is available if either of the
2241preprocessor macros @code{__GNUC_GNU_INLINE__} or
2242@code{__GNUC_STDC_INLINE__} are defined. @xref{Inline,,An Inline
2243Function is As Fast As a Macro}.
541e4101 2244
db577900 2245In C++, this attribute does not depend on @code{extern} in any way,
2246but it still requires the @code{inline} keyword to enable its special
2247behavior.
2248
1b16fc45 2249@item artificial
c17add59 2250@cindex @code{artificial} function attribute
1b16fc45 2251This attribute is useful for small inline wrappers which if possible
2252should appear during debugging as a unit, depending on the debug
2253info format it will either mean marking the function as artificial
2254or using the caller location for all instructions within the inlined
2255body.
2256
cc24427c 2257@item bank_switch
2258@cindex interrupt handler functions
2259When added to an interrupt handler with the M32C port, causes the
2260prologue and epilogue to use bank switching to preserve the registers
2261rather than saving them on the stack.
2262
0cdd9887 2263@item flatten
c17add59 2264@cindex @code{flatten} function attribute
0cdd9887 2265Generally, inlining into a function is limited. For a function marked with
2266this attribute, every call inside this function will be inlined, if possible.
2267Whether the function itself is considered for inlining depends on its size and
8188ae06 2268the current inlining parameters.
0cdd9887 2269
10fc867f 2270@item error ("@var{message}")
2271@cindex @code{error} function attribute
2272If this attribute is used on a function declaration and a call to such a function
2273is not eliminated through dead code elimination or other optimizations, an error
2274which will include @var{message} will be diagnosed. This is useful
2275for compile time checking, especially together with @code{__builtin_constant_p}
2276and inline functions where checking the inline function arguments is not
2277possible through @code{extern char [(condition) ? 1 : -1];} tricks.
2278While it is possible to leave the function undefined and thus invoke
2279a link failure, when using this attribute the problem will be diagnosed
2280earlier and with exact location of the call even in presence of inline
2281functions or when not emitting debugging information.
2282
2283@item warning ("@var{message}")
2284@cindex @code{warning} function attribute
2285If this attribute is used on a function declaration and a call to such a function
2286is not eliminated through dead code elimination or other optimizations, a warning
2287which will include @var{message} will be diagnosed. This is useful
2288for compile time checking, especially together with @code{__builtin_constant_p}
2289and inline functions. While it is possible to define the function with
2290a message in @code{.gnu.warning*} section, when using this attribute the problem
2291will be diagnosed earlier and with exact location of the call even in presence
2292of inline functions or when not emitting debugging information.
2293
7c85682d 2294@item cdecl
2295@cindex functions that do pop the argument stack on the 386
2296@opindex mrtd
2297On the Intel 386, the @code{cdecl} attribute causes the compiler to
2298assume that the calling function will pop off the stack space used to
2299pass arguments. This is
2300useful to override the effects of the @option{-mrtd} switch.
26dfc457 2301
26dfc457 2302@item const
7c85682d 2303@cindex @code{const} function attribute
26dfc457 2304Many functions do not examine any values except their arguments, and
2305have no effects except the return value. Basically this is just slightly
2abf0218 2306more strict class than the @code{pure} attribute below, since function is not
1caefcbd 2307allowed to read global memory.
26dfc457 2308
2309@cindex pointer arguments
2310Note that a function that has pointer arguments and examines the data
2311pointed to must @emph{not} be declared @code{const}. Likewise, a
2312function that calls a non-@code{const} function usually must not be
2313@code{const}. It does not make sense for a @code{const} function to
2314return @code{void}.
2315
37744367 2316The attribute @code{const} is not implemented in GCC versions earlier
146ef39f 2317than 2.5. An alternative way to declare that a function has no side
2318effects, which works in the current version and in some older versions,
2319is as follows:
2320
2321@smallexample
2322typedef int intfn ();
2323
2324extern const intfn square;
2325@end smallexample
2326
2327This approach does not work in GNU C++ from 2.6.0 on, since the language
2328specifies that the @samp{const} must be attached to the return value.
2329
7c85682d 2330@item constructor
2331@itemx destructor
9af7fd5b 2332@itemx constructor (@var{priority})
2333@itemx destructor (@var{priority})
7c85682d 2334@cindex @code{constructor} function attribute
2335@cindex @code{destructor} function attribute
2336The @code{constructor} attribute causes the function to be called
2337automatically before execution enters @code{main ()}. Similarly, the
2338@code{destructor} attribute causes the function to be called
2339automatically after @code{main ()} has completed or @code{exit ()} has
2340been called. Functions with these attributes are useful for
2341initializing data that will be used implicitly during the execution of
2342the program.
2343
9af7fd5b 2344You may provide an optional integer priority to control the order in
2345which constructor and destructor functions are run. A constructor
2346with a smaller priority number runs before a constructor with a larger
2347priority number; the opposite relationship holds for destructors. So,
2348if you have a constructor that allocates a resource and a destructor
2349that deallocates the same resource, both functions typically have the
2350same priority. The priorities for constructor and destructor
2351functions are the same as those specified for namespace-scope C++
2352objects (@pxref{C++ Attributes}).
2353
7c85682d 2354These attributes are not currently implemented for Objective-C@.
2355
2356@item deprecated
45c4e798 2357@itemx deprecated (@var{msg})
7c85682d 2358@cindex @code{deprecated} attribute.
2359The @code{deprecated} attribute results in a warning if the function
2360is used anywhere in the source file. This is useful when identifying
2361functions that are expected to be removed in a future version of a
2362program. The warning also includes the location of the declaration
2363of the deprecated function, to enable users to easily find further
2364information about why the function is deprecated, or what they should
2365do instead. Note that the warnings only occurs for uses:
2366
2367@smallexample
2368int old_fn () __attribute__ ((deprecated));
2369int old_fn ();
2370int (*fn_ptr)() = old_fn;
2371@end smallexample
2372
45c4e798 2373results in a warning on line 3 but not line 2. The optional msg
2374argument, which must be a string, will be printed in the warning if
2375present.
7c85682d 2376
2377The @code{deprecated} attribute can also be used for variables and
2378types (@pxref{Variable Attributes}, @pxref{Type Attributes}.)
2379
7c3116fb 2380@item disinterrupt
2381@cindex @code{disinterrupt} attribute
d19f5793 2382On Epiphany and MeP targets, this attribute causes the compiler to emit
7c3116fb 2383instructions to disable interrupts for the duration of the given
2384function.
2385
7c85682d 2386@item dllexport
2387@cindex @code{__declspec(dllexport)}
3aa0c315 2388On Microsoft Windows targets and Symbian OS targets the
2389@code{dllexport} attribute causes the compiler to provide a global
2390pointer to a pointer in a DLL, so that it can be referenced with the
2391@code{dllimport} attribute. On Microsoft Windows targets, the pointer
2392name is formed by combining @code{_imp__} and the function or variable
2393name.
2394
2395You can use @code{__declspec(dllexport)} as a synonym for
2396@code{__attribute__ ((dllexport))} for compatibility with other
2397compilers.
2398
2399On systems that support the @code{visibility} attribute, this
098a01e7 2400attribute also implies ``default'' visibility. It is an error to
2401explicitly specify any other visibility.
7c85682d 2402
15b474a2 2403In previous versions of GCC, the @code{dllexport} attribute was ignored
0675168d 2404for inlined functions, unless the @option{-fkeep-inline-functions} flag
2405had been used. The default behaviour now is to emit all dllexported
2406inline functions; however, this can cause object file-size bloat, in
2407which case the old behaviour can be restored by using
2408@option{-fno-keep-inline-dllexport}.
2409
2410The attribute is also ignored for undefined symbols.
7c85682d 2411
b3d47662 2412When applied to C++ classes, the attribute marks defined non-inlined
2413member functions and static data members as exports. Static consts
7c85682d 2414initialized in-class are not marked unless they are also defined
2415out-of-class.
2416
db281f5a 2417For Microsoft Windows targets there are alternative methods for
3aa0c315 2418including the symbol in the DLL's export table such as using a
db281f5a 2419@file{.def} file with an @code{EXPORTS} section or, with GNU ld, using
2420the @option{--export-all} linker flag.
7c85682d 2421
2422@item dllimport
2423@cindex @code{__declspec(dllimport)}
3aa0c315 2424On Microsoft Windows and Symbian OS targets, the @code{dllimport}
db281f5a 2425attribute causes the compiler to reference a function or variable via
3aa0c315 2426a global pointer to a pointer that is set up by the DLL exporting the
098a01e7 2427symbol. The attribute implies @code{extern}. On Microsoft Windows
2428targets, the pointer name is formed by combining @code{_imp__} and the
2429function or variable name.
3aa0c315 2430
2431You can use @code{__declspec(dllimport)} as a synonym for
2432@code{__attribute__ ((dllimport))} for compatibility with other
2433compilers.
7c85682d 2434
098a01e7 2435On systems that support the @code{visibility} attribute, this
2436attribute also implies ``default'' visibility. It is an error to
2437explicitly specify any other visibility.
2438
b3d47662 2439Currently, the attribute is ignored for inlined functions. If the
7c85682d 2440attribute is applied to a symbol @emph{definition}, an error is reported.
2441If a symbol previously declared @code{dllimport} is later defined, the
2442attribute is ignored in subsequent references, and a warning is emitted.
2443The attribute is also overridden by a subsequent declaration as
2444@code{dllexport}.
2445
2446When applied to C++ classes, the attribute marks non-inlined
2447member functions and static data members as imports. However, the
2448attribute is ignored for virtual methods to allow creation of vtables
2449using thunks.
2450
3aa0c315 2451On the SH Symbian OS target the @code{dllimport} attribute also has
01e3cadf 2452another affect---it can cause the vtable and run-time type information
3aa0c315 2453for a class to be exported. This happens when the class has a
2454dllimport'ed constructor or a non-inline, non-pure virtual function
68576faf 2455and, for either of those two conditions, the class also has an inline
3aa0c315 2456constructor or destructor and has a key function that is defined in
2457the current translation unit.
db281f5a 2458
2459For Microsoft Windows based targets the use of the @code{dllimport}
2460attribute on functions is not necessary, but provides a small
b3d47662 2461performance benefit by eliminating a thunk in the DLL@. The use of the
db281f5a 2462@code{dllimport} attribute on imported variables was required on older
3aa0c315 2463versions of the GNU linker, but can now be avoided by passing the
b3d47662 2464@option{--enable-auto-import} switch to the GNU linker. As with
3aa0c315 2465functions, using the attribute for a variable eliminates a thunk in
b3d47662 2466the DLL@.
3aa0c315 2467
7e6a4e8b 2468One drawback to using this attribute is that a pointer to a
2469@emph{variable} marked as @code{dllimport} cannot be used as a constant
2470address. However, a pointer to a @emph{function} with the
2471@code{dllimport} attribute can be used as a constant initializer; in
2472this case, the address of a stub function in the import lib is
2473referenced. On Microsoft Windows targets, the attribute can be disabled
3aa0c315 2474for functions by setting the @option{-mnop-fun-dllimport} flag.
7c85682d 2475
2476@item eightbit_data
2477@cindex eight bit data on the H8/300, H8/300H, and H8S
2478Use this attribute on the H8/300, H8/300H, and H8S to indicate that the specified
2479variable should be placed into the eight bit data section.
2480The compiler will generate more efficient code for certain operations
2481on data in the eight bit data area. Note the eight bit data area is limited to
2482256 bytes of data.
2483
2484You must use GAS and GLD from GNU binutils version 2.7 or later for
2485this attribute to work correctly.
2486
9e6a0967 2487@item exception_handler
2488@cindex exception handler functions on the Blackfin processor
2489Use this attribute on the Blackfin to indicate that the specified function
2490is an exception handler. The compiler will generate function entry and
2491exit sequences suitable for use in an exception handler when this
2492attribute is present.
2493
c17add59 2494@item externally_visible
2495@cindex @code{externally_visible} attribute.
2496This attribute, attached to a global variable or function, nullifies
2497the effect of the @option{-fwhole-program} command-line option, so the
61a3c321 2498object remains visible outside the current compilation unit. If @option{-fwhole-program} is used together with @option{-flto} and @command{gold} is used as the linker plugin, @code{externally_visible} attributes are automatically added to functions (not variable yet due to a current @command{gold} issue) that are accessed outside of LTO objects according to resolution file produced by @command{gold}. For other linkers that cannot generate resolution file, explicit @code{externally_visible} attributes are still necessary.
c17add59 2499
7c85682d 2500@item far
2501@cindex functions which handle memory bank switching
2502On 68HC11 and 68HC12 the @code{far} attribute causes the compiler to
2503use a calling convention that takes care of switching memory banks when
2504entering and leaving a function. This calling convention is also the
2505default when using the @option{-mlong-calls} option.
2506
2507On 68HC12 the compiler will use the @code{call} and @code{rtc} instructions
2508to call and return from a function.
2509
2510On 68HC11 the compiler will generate a sequence of instructions
2511to invoke a board-specific routine to switch the memory bank and call the
b3d47662 2512real function. The board-specific routine simulates a @code{call}.
7c85682d 2513At the end of a function, it will jump to a board-specific routine
b3d47662 2514instead of using @code{rts}. The board-specific return routine simulates
7c85682d 2515the @code{rtc}.
2516
7c3116fb 2517On MeP targets this causes the compiler to use a calling convention
2518which assumes the called function is too far away for the built-in
2519addressing modes.
2520
cc24427c 2521@item fast_interrupt
2522@cindex interrupt handler functions
24833e1a 2523Use this attribute on the M32C and RX ports to indicate that the specified
cc24427c 2524function is a fast interrupt handler. This is just like the
2525@code{interrupt} attribute, except that @code{freit} is used to return
2526instead of @code{reit}.
2527
7c85682d 2528@item fastcall
2529@cindex functions that pop the argument stack on the 386
2530On the Intel 386, the @code{fastcall} attribute causes the compiler to
3524624e 2531pass the first argument (if of integral type) in the register ECX and
2532the second argument (if of integral type) in the register EDX@. Subsequent
2533and other typed arguments are passed on the stack. The called function will
2534pop the arguments off the stack. If the number of arguments is variable all
7c85682d 2535arguments are pushed on the stack.
146ef39f 2536
538adab1 2537@item thiscall
2538@cindex functions that pop the argument stack on the 386
2539On the Intel 386, the @code{thiscall} attribute causes the compiler to
2540pass the first argument (if of integral type) in the register ECX.
2541Subsequent and other typed arguments are passed on the stack. The called
2542function will pop the arguments off the stack.
2543If the number of arguments is variable all arguments are pushed on the
2544stack.
2545The @code{thiscall} attribute is intended for C++ non-static member functions.
2546As gcc extension this calling convention can be used for C-functions
2547and for static member methods.
2548
146ef39f 2549@item format (@var{archetype}, @var{string-index}, @var{first-to-check})
2550@cindex @code{format} function attribute
67791935 2551@opindex Wformat
d1f11193 2552The @code{format} attribute specifies that a function takes @code{printf},
6a87209c 2553@code{scanf}, @code{strftime} or @code{strfmon} style arguments which
2554should be type-checked against a format string. For example, the
2555declaration:
146ef39f 2556
2557@smallexample
2558extern int
2559my_printf (void *my_object, const char *my_format, ...)
2560 __attribute__ ((format (printf, 2, 3)));
2561@end smallexample
2562
2563@noindent
2564causes the compiler to check the arguments in calls to @code{my_printf}
2565for consistency with the @code{printf} style format string argument
2566@code{my_format}.
2567
2568The parameter @var{archetype} determines how the format string is
635c5a98 2569interpreted, and should be @code{printf}, @code{scanf}, @code{strftime},
2570@code{gnu_printf}, @code{gnu_scanf}, @code{gnu_strftime} or
2571@code{strfmon}. (You can also use @code{__printf__},
2572@code{__scanf__}, @code{__strftime__} or @code{__strfmon__}.) On
2573MinGW targets, @code{ms_printf}, @code{ms_scanf}, and
2574@code{ms_strftime} are also present.
2575@var{archtype} values such as @code{printf} refer to the formats accepted
2576by the system's C run-time library, while @code{gnu_} values always refer
2577to the formats accepted by the GNU C Library. On Microsoft Windows
2578targets, @code{ms_} values refer to the formats accepted by the
2579@file{msvcrt.dll} library.
2580The parameter @var{string-index}
2581specifies which argument is the format string argument (starting
2582from 1), while @var{first-to-check} is the number of the first
2583argument to check against the format string. For functions
2584where the arguments are not available to be checked (such as
146ef39f 2585@code{vprintf}), specify the third parameter as zero. In this case the
0f502901 2586compiler only checks the format string for consistency. For
2587@code{strftime} formats, the third parameter is required to be zero.
6b4b1c7b 2588Since non-static C++ methods have an implicit @code{this} argument, the
2589arguments of such methods should be counted from two, not one, when
2590giving values for @var{string-index} and @var{first-to-check}.
146ef39f 2591
2592In the example above, the format string (@code{my_format}) is the second
2593argument of the function @code{my_print}, and the arguments to check
2594start with the third argument, so the correct parameters for the format
2595attribute are 2 and 3.
2596
67791935 2597@opindex ffreestanding
67933247 2598@opindex fno-builtin
146ef39f 2599The @code{format} attribute allows you to identify your own functions
37744367 2600which take format strings as arguments, so that GCC can check the
0f502901 2601calls to these functions for errors. The compiler always (unless
67933247 2602@option{-ffreestanding} or @option{-fno-builtin} is used) checks formats
0f502901 2603for the standard library functions @code{printf}, @code{fprintf},
d1f11193 2604@code{sprintf}, @code{scanf}, @code{fscanf}, @code{sscanf}, @code{strftime},
146ef39f 2605@code{vprintf}, @code{vfprintf} and @code{vsprintf} whenever such
67791935 2606warnings are requested (using @option{-Wformat}), so there is no need to
0f502901 2607modify the header file @file{stdio.h}. In C99 mode, the functions
2608@code{snprintf}, @code{vsnprintf}, @code{vscanf}, @code{vfscanf} and
6a87209c 2609@code{vsscanf} are also checked. Except in strictly conforming C
c013a46e 2610standard modes, the X/Open function @code{strfmon} is also checked as
2611are @code{printf_unlocked} and @code{fprintf_unlocked}.
0f502901 2612@xref{C Dialect Options,,Options Controlling C Dialect}.
146ef39f 2613
15b474a2 2614For Objective-C dialects, @code{NSString} (or @code{__NSString__}) is
1f6616ee 2615recognized in the same context. Declarations including these format attributes
2616will be parsed for correct syntax, however the result of checking of such format
15b474a2 2617strings is not yet defined, and will not be carried out by this version of the
1f6616ee 2618compiler.
2619
2620The target may also provide additional types of format checks.
1e9af880 2621@xref{Target Format Checks,,Format Checks Specific to Particular
2622Target Machines}.
2623
146ef39f 2624@item format_arg (@var{string-index})
2625@cindex @code{format_arg} function attribute
67791935 2626@opindex Wformat-nonliteral
6a87209c 2627The @code{format_arg} attribute specifies that a function takes a format
2628string for a @code{printf}, @code{scanf}, @code{strftime} or
2629@code{strfmon} style function and modifies it (for example, to translate
2630it into another language), so the result can be passed to a
2631@code{printf}, @code{scanf}, @code{strftime} or @code{strfmon} style
2632function (with the remaining arguments to the format function the same
2633as they would have been for the unmodified string). For example, the
2634declaration:
146ef39f 2635
2636@smallexample
2637extern char *
2638my_dgettext (char *my_domain, const char *my_format)
2639 __attribute__ ((format_arg (2)));
2640@end smallexample
2641
2642@noindent
6a87209c 2643causes the compiler to check the arguments in calls to a @code{printf},
2644@code{scanf}, @code{strftime} or @code{strfmon} type function, whose
2645format string argument is a call to the @code{my_dgettext} function, for
2646consistency with the format string argument @code{my_format}. If the
2647@code{format_arg} attribute had not been specified, all the compiler
2648could tell in such calls to format functions would be that the format
2649string argument is not constant; this would generate a warning when
67791935 2650@option{-Wformat-nonliteral} is used, but the calls could not be checked
6a87209c 2651without the attribute.
146ef39f 2652
2653The parameter @var{string-index} specifies which argument is the format
6b4b1c7b 2654string argument (starting from one). Since non-static C++ methods have
2655an implicit @code{this} argument, the arguments of such methods should
2656be counted from two.
146ef39f 2657
2658The @code{format-arg} attribute allows you to identify your own
37744367 2659functions which modify format strings, so that GCC can check the
6a87209c 2660calls to @code{printf}, @code{scanf}, @code{strftime} or @code{strfmon}
2661type function whose operands are a call to one of your own function.
2662The compiler always treats @code{gettext}, @code{dgettext}, and
2663@code{dcgettext} in this manner except when strict ISO C support is
67791935 2664requested by @option{-ansi} or an appropriate @option{-std} option, or
67933247 2665@option{-ffreestanding} or @option{-fno-builtin}
2666is used. @xref{C Dialect Options,,Options
6a87209c 2667Controlling C Dialect}.
146ef39f 2668
1f6616ee 2669For Objective-C dialects, the @code{format-arg} attribute may refer to an
2670@code{NSString} reference for compatibility with the @code{format} attribute
2671above.
2672
2673The target may also allow additional types in @code{format-arg} attributes.
2674@xref{Target Format Checks,,Format Checks Specific to Particular
2675Target Machines}.
2676
7c85682d 2677@item function_vector
5241f4ad 2678@cindex calling functions through the function vector on H8/300, M16C, M32C and SH2A processors
7c85682d 2679Use this attribute on the H8/300, H8/300H, and H8S to indicate that the specified
2680function should be called through the function vector. Calling a
2681function through the function vector will reduce code size, however;
2682the function vector has a limited size (maximum 128 entries on the H8/300
2683and 64 entries on the H8/300H and H8S) and shares space with the interrupt vector.
dbf6c367 2684
5241f4ad 2685In SH2A target, this attribute declares a function to be called using the
2686TBR relative addressing mode. The argument to this attribute is the entry
2687number of the same function in a vector table containing all the TBR
2688relative addressable functions. For the successful jump, register TBR
2689should contain the start address of this TBR relative vector table.
2690In the startup routine of the user application, user needs to care of this
2691TBR register initialization. The TBR relative vector table can have at
2692max 256 function entries. The jumps to these functions will be generated
2693using a SH2A specific, non delayed branch instruction JSR/N @@(disp8,TBR).
7c85682d 2694You must use GAS and GLD from GNU binutils version 2.7 or later for
2695this attribute to work correctly.
dbf6c367 2696
5241f4ad 2697Please refer the example of M16C target, to see the use of this
2698attribute while declaring a function,
2699
2700In an application, for a function being called once, this attribute will
2701save at least 8 bytes of code; and if other successive calls are being
2702made to the same function, it will save 2 bytes of code per each of these
2703calls.
2704
2efce110 2705On M16C/M32C targets, the @code{function_vector} attribute declares a
2706special page subroutine call function. Use of this attribute reduces
2707the code size by 2 bytes for each call generated to the
2708subroutine. The argument to the attribute is the vector number entry
2709from the special page vector table which contains the 16 low-order
2710bits of the subroutine's entry address. Each vector table has special
2711page number (18 to 255) which are used in @code{jsrs} instruction.
2712Jump addresses of the routines are generated by adding 0x0F0000 (in
2713case of M16C targets) or 0xFF0000 (in case of M32C targets), to the 2
2714byte addresses set in the vector table. Therefore you need to ensure
2715that all the special page vector routines should get mapped within the
2716address range 0x0F0000 to 0x0FFFFF (for M16C) and 0xFF0000 to 0xFFFFFF
2717(for M32C).
2718
2719In the following example 2 bytes will be saved for each call to
2720function @code{foo}.
2721
2722@smallexample
2723void foo (void) __attribute__((function_vector(0x18)));
2724void foo (void)
2725@{
2726@}
2727
2728void bar (void)
2729@{
2730 foo();
2731@}
2732@end smallexample
2733
2734If functions are defined in one file and are called in another file,
2735then be sure to write this declaration in both files.
2736
2737This attribute is ignored for R8C target.
2738
ea679361 2739@item ifunc ("@var{resolver}")
2740@cindex @code{ifunc} attribute
2741The @code{ifunc} attribute is used to mark a function as an indirect
2742function using the STT_GNU_IFUNC symbol type extension to the ELF
2743standard. This allows the resolution of the symbol value to be
2744determined dynamically at load time, and an optimized version of the
2745routine can be selected for the particular processor or other system
2746characteristics determined then. To use this attribute, first define
2747the implementation functions available, and a resolver function that
2748returns a pointer to the selected implementation function. The
2749implementation functions' declarations must match the API of the
2750function being implemented, the resolver's declaration is be a
2751function returning pointer to void function returning void:
2752
2753@smallexample
2754void *my_memcpy (void *dst, const void *src, size_t len)
2755@{
2756 @dots{}
2757@}
2758
2759static void (*resolve_memcpy (void)) (void)
2760@{
2761 return my_memcpy; // we'll just always select this routine
2762@}
2763@end smallexample
2764
2765The exported header file declaring the function the user calls would
2766contain:
2767
2768@smallexample
2769extern void *memcpy (void *, const void *, size_t);
2770@end smallexample
2771
2772allowing the user to call this as a regular function, unaware of the
2773implementation. Finally, the indirect function needs to be defined in
2774the same translation unit as the resolver function:
2775
2776@smallexample
2777void *memcpy (void *, const void *, size_t)
2778 __attribute__ ((ifunc ("resolve_memcpy")));
2779@end smallexample
2780
2781Indirect functions cannot be weak, and require a recent binutils (at
2782least version 2.20.1), and GNU C library (at least version 2.11.1).
2783
7c85682d 2784@item interrupt
2785@cindex interrupt handler functions
b9fdd12b 2786Use this attribute on the ARM, AVR, CR16, Epiphany, M32C, M32R/D, m68k, MeP, MIPS,
78e515f7 2787RL78, RX and Xstormy16 ports to indicate that the specified function is an
29968436 2788interrupt handler. The compiler will generate function entry and exit
2789sequences suitable for use in an interrupt handler when this attribute
43770c4d 2790is present. With Epiphany targets it may also generate a special section with
2791code to initialize the interrupt vector table.
dbf6c367 2792
d34b0d1e 2793Note, interrupt handlers for the Blackfin, H8/300, H8/300H, H8S, MicroBlaze,
2794and SH processors can be specified via the @code{interrupt_handler} attribute.
dbf6c367 2795
ea679361 2796Note, on the AVR, the hardware globally disables interrupts when an
2797interrupt is executed. The first instruction of an interrupt handler
2798declared with this attribute will be a @code{SEI} instruction to
2799re-enable interrupts. See also the @code{signal} function attribute
2800that does not insert a @code{SEI} instuction. If both @code{signal} and
2801@code{interrupt} are specified for the same function, @code{signal}
2802will be silently ignored.
93f10b04 2803
7c85682d 2804Note, for the ARM, you can specify the kind of interrupt to be handled by
2805adding an optional parameter to the interrupt attribute like this:
88da234d 2806
2807@smallexample
7c85682d 2808void f () __attribute__ ((interrupt ("IRQ")));
88da234d 2809@end smallexample
2810
7c85682d 2811Permissible values for this parameter are: IRQ, FIQ, SWI, ABORT and UNDEF@.
88da234d 2812
542d5028 2813On ARMv7-M the interrupt type is ignored, and the attribute means the function
25f905c2 2814may be called with a word aligned stack pointer.
2815
43770c4d 2816On Epiphany targets one or more optional parameters can be added like this:
2817
2818@smallexample
2819void __attribute__ ((interrupt ("dma0, dma1"))) universal_dma_handler ();
2820@end smallexample
2821
2822Permissible values for these parameters are: @w{@code{reset}},
2823@w{@code{software_exception}}, @w{@code{page_miss}},
2824@w{@code{timer0}}, @w{@code{timer1}}, @w{@code{message}},
2825@w{@code{dma0}}, @w{@code{dma1}}, @w{@code{wand}} and @w{@code{swi}}.
2826Multiple parameters indicate that multiple entries in the interrupt
2827vector table should be initialized for this function, i.e. for each
2828parameter @w{@var{name}}, a jump to the function will be emitted in
2829the section @w{ivt_entry_@var{name}}. The parameter(s) may be omitted
2830entirely, in which case no interrupt vector table entry will be provided.
2831
2832Note, on Epiphany targets, interrupts are enabled inside the function
2833unless the @code{disinterrupt} attribute is also specified.
2834
2835On Epiphany targets, you can also use the following attribute to
2836modify the behavior of an interrupt handler:
2837@table @code
2838@item forwarder_section
2839@cindex @code{forwarder_section} attribute
2840The interrupt handler may be in external memory which cannot be
2841reached by a branch instruction, so generate a local memory trampoline
2842to transfer control. The single parameter identifies the section where
2843the trampoline will be placed.
2844@end table
2845
2846The following examples are all valid uses of these attributes on
2847Epiphany targets:
2848@smallexample
2849void __attribute__ ((interrupt)) universal_handler ();
2850void __attribute__ ((interrupt ("dma1"))) dma1_handler ();
2851void __attribute__ ((interrupt ("dma0, dma1"))) universal_dma_handler ();
2852void __attribute__ ((interrupt ("timer0"), disinterrupt))
2853 fast_timer_handler ();
2854void __attribute__ ((interrupt ("dma0, dma1"), forwarder_section ("tramp")))
2855 external_dma_handler ();
2856@end smallexample
2857
0bfaf4c4 2858On MIPS targets, you can use the following attributes to modify the behavior
2859of an interrupt handler:
2860@table @code
2861@item use_shadow_register_set
2862@cindex @code{use_shadow_register_set} attribute
2863Assume that the handler uses a shadow register set, instead of
2864the main general-purpose registers.
2865
2866@item keep_interrupts_masked
2867@cindex @code{keep_interrupts_masked} attribute
2868Keep interrupts masked for the whole function. Without this attribute,
2869GCC tries to reenable interrupts for as much of the function as it can.
2870
2871@item use_debug_exception_return
2872@cindex @code{use_debug_exception_return} attribute
2873Return using the @code{deret} instruction. Interrupt handlers that don't
2874have this attribute return using @code{eret} instead.
2875@end table
2876
2877You can use any combination of these attributes, as shown below:
2878@smallexample
2879void __attribute__ ((interrupt)) v0 ();
2880void __attribute__ ((interrupt, use_shadow_register_set)) v1 ();
2881void __attribute__ ((interrupt, keep_interrupts_masked)) v2 ();
2882void __attribute__ ((interrupt, use_debug_exception_return)) v3 ();
2883void __attribute__ ((interrupt, use_shadow_register_set,
910faa40 2884 keep_interrupts_masked)) v4 ();
0bfaf4c4 2885void __attribute__ ((interrupt, use_shadow_register_set,
910faa40 2886 use_debug_exception_return)) v5 ();
0bfaf4c4 2887void __attribute__ ((interrupt, keep_interrupts_masked,
910faa40 2888 use_debug_exception_return)) v6 ();
0bfaf4c4 2889void __attribute__ ((interrupt, use_shadow_register_set,
910faa40 2890 keep_interrupts_masked,
2891 use_debug_exception_return)) v7 ();
0bfaf4c4 2892@end smallexample
2893
78e515f7 2894On RL78, use @code{brk_interrupt} instead of @code{interrupt} for
2895handlers intended to be used with the @code{BRK} opcode (i.e. those
2896that must end with @code{RETB} instead of @code{RETI}).
2897
7c85682d 2898@item interrupt_handler
9e6a0967 2899@cindex interrupt handler functions on the Blackfin, m68k, H8/300 and SH processors
2900Use this attribute on the Blackfin, m68k, H8/300, H8/300H, H8S, and SH to
2901indicate that the specified function is an interrupt handler. The compiler
2902will generate function entry and exit sequences suitable for use in an
2903interrupt handler when this attribute is present.
2904
f9a44575 2905@item interrupt_thread
2906@cindex interrupt thread functions on fido
2907Use this attribute on fido, a subarchitecture of the m68k, to indicate
2908that the specified function is an interrupt handler that is designed
2909to run as a thread. The compiler omits generate prologue/epilogue
2910sequences and replaces the return instruction with a @code{sleep}
2911instruction. This attribute is available only on fido.
2912
1fe1c6f5 2913@item isr
2914@cindex interrupt service routines on ARM
2915Use this attribute on ARM to write Interrupt Service Routines. This is an
2916alias to the @code{interrupt} attribute above.
2917
9e6a0967 2918@item kspisusp
2919@cindex User stack pointer in interrupts on the Blackfin
2920When used together with @code{interrupt_handler}, @code{exception_handler}
2921or @code{nmi_handler}, code will be generated to load the stack pointer
2922from the USP register in the function prologue.
8a8cdb8d 2923
fc8aef7f 2924@item l1_text
2925@cindex @code{l1_text} function attribute
2926This attribute specifies a function to be placed into L1 Instruction
a81d4cba 2927SRAM@. The function will be put into a specific section named @code{.l1.text}.
fc8aef7f 2928With @option{-mfdpic}, function calls with a such function as the callee
2929or caller will use inlined PLT.
2930
59fbccf3 2931@item l2
2932@cindex @code{l2} function attribute
2933On the Blackfin, this attribute specifies a function to be placed into L2
2934SRAM. The function will be put into a specific section named
2935@code{.l1.text}. With @option{-mfdpic}, callers of such functions will use
2936an inlined PLT.
2937
7bd95dfd 2938@item leaf
2939@cindex @code{leaf} function attribute
2940Calls to external functions with this attribute must return to the current
b59688ee 2941compilation unit only by return or by exception handling. In particular, leaf
2942functions are not allowed to call callback function passed to it from the current
7bd95dfd 2943compilation unit or directly call functions exported by the unit or longjmp
b59688ee 2944into the unit. Leaf function might still call functions from other compilation
2945units and thus they are not necessarily leaf in the sense that they contain no
7bd95dfd 2946function calls at all.
2947
2948The attribute is intended for library functions to improve dataflow analysis.
b59688ee 2949The compiler takes the hint that any data not escaping the current compilation unit can
2950not be used or modified by the leaf function. For example, the @code{sin} function
2951is a leaf function, but @code{qsort} is not.
7bd95dfd 2952
b59688ee 2953Note that leaf functions might invoke signals and signal handlers might be
2954defined in the current compilation unit and use static variables. The only
7bd95dfd 2955compliant way to write such a signal handler is to declare such variables
2956@code{volatile}.
2957
b59688ee 2958The attribute has no effect on functions defined within the current compilation
7bd95dfd 2959unit. This is to allow easy merging of multiple compilation units into one,
2960for example, by using the link time optimization. For this reason the
2961attribute is not allowed on types to annotate indirect calls.
2962
7c85682d 2963@item long_call/short_call
2964@cindex indirect calls on ARM
2965This attribute specifies how a particular function is called on
d19f5793 2966ARM and Epiphany. Both attributes override the
2967@option{-mlong-calls} (@pxref{ARM Options})
bfe513a4 2968command-line switch and @code{#pragma long_calls} settings. The
e3eb8567 2969@code{long_call} attribute indicates that the function might be far
2970away from the call site and require a different (more expensive)
2971calling sequence. The @code{short_call} attribute always places
7c85682d 2972the offset to the function from the call site into the @samp{BL}
2973instruction directly.
8a8cdb8d 2974
7c85682d 2975@item longcall/shortcall
2976@cindex functions called via pointer on the RS/6000 and PowerPC
e3eb8567 2977On the Blackfin, RS/6000 and PowerPC, the @code{longcall} attribute
2978indicates that the function might be far away from the call site and
2979require a different (more expensive) calling sequence. The
2980@code{shortcall} attribute indicates that the function is always close
2981enough for the shorter calling sequence to be used. These attributes
2982override both the @option{-mlongcall} switch and, on the RS/6000 and
2983PowerPC, the @code{#pragma longcall} setting.
8a8cdb8d 2984
7c85682d 2985@xref{RS/6000 and PowerPC Options}, for more information on whether long
2986calls are necessary.
146ef39f 2987
7808555b 2988@item long_call/near/far
3d375286 2989@cindex indirect calls on MIPS
7808555b 2990These attributes specify how a particular function is called on MIPS@.
2991The attributes override the @option{-mlong-calls} (@pxref{MIPS Options})
2992command-line switch. The @code{long_call} and @code{far} attributes are
2993synonyms, and cause the compiler to always call
3d375286 2994the function by first loading its address into a register, and then using
7808555b 2995the contents of that register. The @code{near} attribute has the opposite
15b474a2 2996effect; it specifies that non-PIC calls should be made using the more
7808555b 2997efficient @code{jal} instruction.
3d375286 2998
7259f3f8 2999@item malloc
3000@cindex @code{malloc} attribute
3001The @code{malloc} attribute is used to tell the compiler that a function
648147e8 3002may be treated as if any non-@code{NULL} pointer it returns cannot
35cbef6c 3003alias any other pointer valid when the function returns and that the memory
3004has undefined content.
7259f3f8 3005This will often improve optimization.
648147e8 3006Standard functions with this property include @code{malloc} and
35cbef6c 3007@code{calloc}. @code{realloc}-like functions do not have this
3008property as the memory pointed to does not have undefined content.
7259f3f8 3009
bd4d19da 3010@item mips16/nomips16
3011@cindex @code{mips16} attribute
3012@cindex @code{nomips16} attribute
3013
3014On MIPS targets, you can use the @code{mips16} and @code{nomips16}
3015function attributes to locally select or turn off MIPS16 code generation.
15b474a2 3016A function with the @code{mips16} attribute is emitted as MIPS16 code,
3017while MIPS16 code generation is disabled for functions with the
3018@code{nomips16} attribute. These attributes override the
bd4d19da 3019@option{-mips16} and @option{-mno-mips16} options on the command line
15b474a2 3020(@pxref{MIPS Options}).
bd4d19da 3021
3022When compiling files containing mixed MIPS16 and non-MIPS16 code, the
3023preprocessor symbol @code{__mips16} reflects the setting on the command line,
3024not that within individual functions. Mixed MIPS16 and non-MIPS16 code
3025may interact badly with some GCC extensions such as @code{__builtin_apply}
3026(@pxref{Constructing Calls}).
3027
7c85682d 3028@item model (@var{model-name})
3029@cindex function addressability on the M32R/D
3030@cindex variable addressability on the IA-64
3031
3032On the M32R/D, use this attribute to set the addressability of an
3033object, and of the code generated for a function. The identifier
3034@var{model-name} is one of @code{small}, @code{medium}, or
3035@code{large}, representing each of the code models.
3036
3037Small model objects live in the lower 16MB of memory (so that their
3038addresses can be loaded with the @code{ld24} instruction), and are
3039callable with the @code{bl} instruction.
3040
3041Medium model objects may live anywhere in the 32-bit address space (the
3042compiler will generate @code{seth/add3} instructions to load their addresses),
3043and are callable with the @code{bl} instruction.
3044
3045Large model objects may live anywhere in the 32-bit address space (the
3046compiler will generate @code{seth/add3} instructions to load their addresses),
3047and may not be reachable with the @code{bl} instruction (the compiler will
3048generate the much slower @code{seth/add3/jl} instruction sequence).
3049
3050On IA-64, use this attribute to set the addressability of an object.
3051At present, the only supported identifier for @var{model-name} is
3052@code{small}, indicating addressability via ``small'' (22-bit)
3053addresses (so that their addresses can be loaded with the @code{addl}
3054instruction). Caveat: such addressing is by definition not position
3055independent and hence this attribute must not be used for objects
3056defined by shared libraries.
3057
d3feb168 3058@item ms_abi/sysv_abi
9440ae7b 3059@cindex @code{ms_abi} attribute
d3feb168 3060@cindex @code{sysv_abi} attribute
3061
05b56dfa 3062On 32-bit and 64-bit (i?86|x86_64)-*-* targets, you can use an ABI attribute
3063to indicate which calling convention should be used for a function. The
3064@code{ms_abi} attribute tells the compiler to use the Microsoft ABI,
3065while the @code{sysv_abi} attribute tells the compiler to use the ABI
3066used on GNU/Linux and other systems. The default is to use the Microsoft ABI
3067when targeting Windows. On all other systems, the default is the x86/AMD ABI.
d3feb168 3068
05b56dfa 3069Note, the @code{ms_abi} attribute for Windows 64-bit targets currently
3070requires the @option{-maccumulate-outgoing-args} option.
d3feb168 3071
c1817294 3072@item callee_pop_aggregate_return (@var{number})
3073@cindex @code{callee_pop_aggregate_return} attribute
3074
3075On 32-bit i?86-*-* targets, you can control by those attribute for
3076aggregate return in memory, if the caller is responsible to pop the hidden
3077pointer together with the rest of the arguments - @var{number} equal to
3078zero -, or if the callee is responsible to pop hidden pointer - @var{number}
4d72c922 3079equal to one. The default i386 ABI assumes that the callee pops the
3080stack for hidden pointer.
c1817294 3081
05b56dfa 3082Note, that on 32-bit i386 Windows targets the compiler assumes that the
3083caller pops the stack for hidden pointer.
3084
5a5324bc 3085@item ms_hook_prologue
3086@cindex @code{ms_hook_prologue} attribute
3087
2761b7cb 3088On 32 bit i[34567]86-*-* targets and 64 bit x86_64-*-* targets, you can use
3089this function attribute to make gcc generate the "hot-patching" function
3090prologue used in Win32 API functions in Microsoft Windows XP Service Pack 2
3091and newer.
5a5324bc 3092
7c85682d 3093@item naked
3094@cindex function without a prologue/epilogue code
69f483eb 3095Use this attribute on the ARM, AVR, MCORE, RX and SPU ports to indicate that
644459d0 3096the specified function does not need prologue/epilogue sequences generated by
15b474a2 3097the compiler. It is up to the programmer to provide these sequences. The
3098only statements that can be safely included in naked functions are
658e203c 3099@code{asm} statements that do not have operands. All other statements,
15b474a2 3100including declarations of local variables, @code{if} statements, and so
3101forth, should be avoided. Naked functions should be used to implement the
658e203c 3102body of an assembly function, while allowing the compiler to construct
3103the requisite function declaration for the assembler.
7c85682d 3104
3105@item near
3106@cindex functions which do not handle memory bank switching on 68HC11/68HC12
3107On 68HC11 and 68HC12 the @code{near} attribute causes the compiler to
3108use the normal calling convention based on @code{jsr} and @code{rts}.
3109This attribute can be used to cancel the effect of the @option{-mlong-calls}
3110option.
3111
7c3116fb 3112On MeP targets this attribute causes the compiler to assume the called
3113function is close enough to use the normal calling convention,
3114overriding the @code{-mtf} command line option.
3115
9e6a0967 3116@item nesting
3117@cindex Allow nesting in an interrupt handler on the Blackfin processor.
3118Use this attribute together with @code{interrupt_handler},
3119@code{exception_handler} or @code{nmi_handler} to indicate that the function
3120entry code should enable nested interrupts or exceptions.
3121
3122@item nmi_handler
3123@cindex NMI handler functions on the Blackfin processor
3124Use this attribute on the Blackfin to indicate that the specified function
3125is an NMI handler. The compiler will generate function entry and
3126exit sequences suitable for use in an NMI handler when this
3127attribute is present.
3128
7c85682d 3129@item no_instrument_function
3130@cindex @code{no_instrument_function} function attribute
3131@opindex finstrument-functions
3132If @option{-finstrument-functions} is given, profiling function calls will
3133be generated at entry and exit of most user-compiled functions.
3134Functions with this attribute will not be so instrumented.
3135
48b14f50 3136@item no_split_stack
3137@cindex @code{no_split_stack} function attribute
3138@opindex fsplit-stack
3139If @option{-fsplit-stack} is given, functions will have a small
3140prologue which decides whether to split the stack. Functions with the
3141@code{no_split_stack} attribute will not have that prologue, and thus
3142may run with only a small amount of stack space available.
3143
7c85682d 3144@item noinline
3145@cindex @code{noinline} function attribute
3146This function attribute prevents a function from being considered for
3147inlining.
9bc2537d 3148@c Don't enumerate the optimizations by name here; we try to be
3149@c future-compatible with this mechanism.
3150If the function does not have side-effects, there are optimizations
3151other than inlining that causes function calls to be optimized away,
3152although the function call is live. To keep such calls from being
3153optimized away, put
3154@smallexample
3155asm ("");
3156@end smallexample
3157(@pxref{Extended Asm}) in the called function, to serve as a special
3158side-effect.
7c85682d 3159
bdb1f0d1 3160@item noclone
3161@cindex @code{noclone} function attribute
3162This function attribute prevents a function from being considered for
3163cloning - a mechanism which produces specialized copies of functions
3164and which is (currently) performed by interprocedural constant
3165propagation.
3166
7c85682d 3167@item nonnull (@var{arg-index}, @dots{})
3168@cindex @code{nonnull} function attribute
3169The @code{nonnull} attribute specifies that some function parameters should
3170be non-null pointers. For instance, the declaration:
146ef39f 3171
3172@smallexample
7c85682d 3173extern void *
3174my_memcpy (void *dest, const void *src, size_t len)
c24c5fac 3175 __attribute__((nonnull (1, 2)));
146ef39f 3176@end smallexample
3177
7c85682d 3178@noindent
3179causes the compiler to check that, in calls to @code{my_memcpy},
3180arguments @var{dest} and @var{src} are non-null. If the compiler
3181determines that a null pointer is passed in an argument slot marked
3182as non-null, and the @option{-Wnonnull} option is enabled, a warning
3183is issued. The compiler may also choose to make optimizations based
3184on the knowledge that certain function arguments will not be null.
35073234 3185
7c85682d 3186If no argument index list is given to the @code{nonnull} attribute,
3187all pointer arguments are marked as non-null. To illustrate, the
3188following declaration is equivalent to the previous example:
b4cf9ec1 3189
3190@smallexample
7c85682d 3191extern void *
3192my_memcpy (void *dest, const void *src, size_t len)
c24c5fac 3193 __attribute__((nonnull));
b4cf9ec1 3194@end smallexample
3195
7c85682d 3196@item noreturn
3197@cindex @code{noreturn} function attribute
3198A few standard library functions, such as @code{abort} and @code{exit},
3199cannot return. GCC knows this automatically. Some programs define
3200their own functions that never return. You can declare them
3201@code{noreturn} to tell the compiler this fact. For example,
21a24508 3202
7c85682d 3203@smallexample
3204@group
3205void fatal () __attribute__ ((noreturn));
2d0ba106 3206
7c85682d 3207void
3208fatal (/* @r{@dots{}} */)
3209@{
3210 /* @r{@dots{}} */ /* @r{Print error message.} */ /* @r{@dots{}} */
3211 exit (1);
3212@}
3213@end group
3214@end smallexample
21a24508 3215
7c85682d 3216The @code{noreturn} keyword tells the compiler to assume that
3217@code{fatal} cannot return. It can then optimize without regard to what
3218would happen if @code{fatal} ever did return. This makes slightly
3219better code. More importantly, it helps avoid spurious warnings of
3220uninitialized variables.
21a24508 3221
7c85682d 3222The @code{noreturn} keyword does not affect the exceptional path when that
3223applies: a @code{noreturn}-marked function may still return to the caller
14bca5d1 3224by throwing an exception or calling @code{longjmp}.
21a24508 3225
7c85682d 3226Do not assume that registers saved by the calling function are
3227restored before calling the @code{noreturn} function.
b4cf9ec1 3228
7c85682d 3229It does not make sense for a @code{noreturn} function to have a return
3230type other than @code{void}.
146ef39f 3231
7c85682d 3232The attribute @code{noreturn} is not implemented in GCC versions
3233earlier than 2.5. An alternative way to declare that a function does
3234not return, which works in the current version and in some older
3235versions, is as follows:
3deb1c7e 3236
7c85682d 3237@smallexample
3238typedef void voidfn ();
146ef39f 3239
7c85682d 3240volatile voidfn fatal;
3241@end smallexample
54f917d1 3242
fc08fc16 3243This approach does not work in GNU C++.
3244
7c85682d 3245@item nothrow
3246@cindex @code{nothrow} function attribute
3247The @code{nothrow} attribute is used to inform the compiler that a
3248function cannot throw an exception. For example, most functions in
3249the standard C library can be guaranteed not to throw an exception
3250with the notable exceptions of @code{qsort} and @code{bsearch} that
3251take function pointer arguments. The @code{nothrow} attribute is not
6a40c9c1 3252implemented in GCC versions earlier than 3.3.
146ef39f 3253
46f8e3b0 3254@item optimize
3255@cindex @code{optimize} function attribute
3256The @code{optimize} attribute is used to specify that a function is to
3257be compiled with different optimization options than specified on the
3258command line. Arguments can either be numbers or strings. Numbers
3259are assumed to be an optimization level. Strings that begin with
3260@code{O} are assumed to be an optimization option, while other options
3261are assumed to be used with a @code{-f} prefix. You can also use the
3262@samp{#pragma GCC optimize} pragma to set the optimization options
3263that affect more than one function.
3264@xref{Function Specific Option Pragmas}, for details about the
db8edef0 3265@samp{#pragma GCC optimize} pragma.
46f8e3b0 3266
3267This can be used for instance to have frequently executed functions
3268compiled with more aggressive optimization options that produce faster
3269and larger code, while other functions can be called with less
24470055 3270aggressive options.
46f8e3b0 3271
91f3009d 3272@item OS_main/OS_task
3273@cindex @code{OS_main} AVR function attribute
3274@cindex @code{OS_task} AVR function attribute
3275On AVR, functions with the @code{OS_main} or @code{OS_task} attribute
3276do not save/restore any call-saved register in their prologue/epilogue.
3277
3278The @code{OS_main} attribute can be used when there @emph{is
3279guarantee} that interrupts are disabled at the time when the function
3280is entered. This will save resources when the stack pointer has to be
3281changed to set up a frame for local variables.
3282
3283The @code{OS_task} attribute can be used when there is @emph{no
3284guarantee} that interrupts are disabled at that time when the function
3285is entered like for, e@.g@. task functions in a multi-threading operating
3286system. In that case, changing the stack pointer register will be
3287guarded by save/clear/restore of the global interrupt enable flag.
3288
6ee532ba 3289The differences to the @code{naked} function attribute are:
91f3009d 3290@itemize @bullet
3291@item @code{naked} functions do not have a return instruction whereas
3292@code{OS_main} and @code{OS_task} functions will have a @code{RET} or
3293@code{RETI} return instruction.
3294@item @code{naked} functions do not set up a frame for local variables
3295or a frame pointer whereas @code{OS_main} and @code{OS_task} do this
3296as needed.
3297@end itemize
3298
3eec35ec 3299@item pcs
3300@cindex @code{pcs} function attribute
3301
3302The @code{pcs} attribute can be used to control the calling convention
3303used for a function on ARM. The attribute takes an argument that specifies
3304the calling convention to use.
3305
3306When compiling using the AAPCS ABI (or a variant of that) then valid
3307values for the argument are @code{"aapcs"} and @code{"aapcs-vfp"}. In
3308order to use a variant other than @code{"aapcs"} then the compiler must
3309be permitted to use the appropriate co-processor registers (i.e., the
3310VFP registers must be available in order to use @code{"aapcs-vfp"}).
3311For example,
3312
3313@smallexample
3314/* Argument passed in r0, and result returned in r0+r1. */
3315double f2d (float) __attribute__((pcs("aapcs")));
3316@end smallexample
3317
3318Variadic functions always use the @code{"aapcs"} calling convention and
3319the compiler will reject attempts to specify an alternative.
3320
7c85682d 3321@item pure
3322@cindex @code{pure} function attribute
3323Many functions have no effects except the return value and their
3324return value depends only on the parameters and/or global variables.
3325Such a function can be subject
3326to common subexpression elimination and loop optimization just as an
3327arithmetic operator would be. These functions should be declared
3328with the attribute @code{pure}. For example,
edd2f2ae 3329
7c85682d 3330@smallexample
3331int square (int) __attribute__ ((pure));
3332@end smallexample
146ef39f 3333
7c85682d 3334@noindent
3335says that the hypothetical function @code{square} is safe to call
3336fewer times than the program says.
78fe751b 3337
7c85682d 3338Some of common examples of pure functions are @code{strlen} or @code{memcmp}.
3339Interesting non-pure functions are functions with infinite loops or those
3340depending on volatile memory or other system resource, that may change between
3341two consecutive calls (such as @code{feof} in a multithreading environment).
146ef39f 3342
7c85682d 3343The attribute @code{pure} is not implemented in GCC versions earlier
3344than 2.96.
146ef39f 3345
5de92639 3346@item hot
3347@cindex @code{hot} function attribute
758a38ab 3348The @code{hot} attribute on a function is used to inform the compiler that
3349the function is a hot spot of the compiled program. The function is
3350optimized more aggressively and on many target it is placed into special
3351subsection of the text section so all hot functions appears close together
3352improving locality.
5de92639 3353
3354When profile feedback is available, via @option{-fprofile-use}, hot functions
3355are automatically detected and this attribute is ignored.
3356
758a38ab 3357The @code{hot} attribute on functions is not implemented in GCC versions
3358earlier than 4.3.
3359
3360@cindex @code{hot} label attribute
3361The @code{hot} attribute on a label is used to inform the compiler that
3362path following the label are more likely than paths that are not so
3363annotated. This attribute is used in cases where @code{__builtin_expect}
3364cannot be used, for instance with computed goto or @code{asm goto}.
3365
3366The @code{hot} attribute on labels is not implemented in GCC versions
3367earlier than 4.8.
46f8e3b0 3368
5de92639 3369@item cold
3370@cindex @code{cold} function attribute
758a38ab 3371The @code{cold} attribute on functions is used to inform the compiler that
3372the function is unlikely to be executed. The function is optimized for
3373size rather than speed and on many targets it is placed into special
3374subsection of the text section so all cold functions appears close together
3375improving code locality of non-cold parts of program. The paths leading
3376to call of cold functions within code are marked as unlikely by the branch
3377prediction mechanism. It is thus useful to mark functions used to handle
3378unlikely conditions, such as @code{perror}, as cold to improve optimization
3379of hot functions that do call marked functions in rare occasions.
3380
3381When profile feedback is available, via @option{-fprofile-use}, cold functions
5de92639 3382are automatically detected and this attribute is ignored.
3383
758a38ab 3384The @code{cold} attribute on functions is not implemented in GCC versions
3385earlier than 4.3.
3386
3387@cindex @code{cold} label attribute
3388The @code{cold} attribute on labels is used to inform the compiler that
3389the path following the label is unlikely to be executed. This attribute
3390is used in cases where @code{__builtin_expect} cannot be used, for instance
3391with computed goto or @code{asm goto}.
3392
3393The @code{cold} attribute on labels is not implemented in GCC versions
3394earlier than 4.8.
46f8e3b0 3395
7c85682d 3396@item regparm (@var{number})
3397@cindex @code{regparm} attribute
3398@cindex functions that are passed arguments in registers on the 386
3399On the Intel 386, the @code{regparm} attribute causes the compiler to
3524624e 3400pass arguments number one to @var{number} if they are of integral type
3401in registers EAX, EDX, and ECX instead of on the stack. Functions that
3402take a variable number of arguments will continue to be passed all of their
7c85682d 3403arguments on the stack.
e27ad2d5 3404
7c85682d 3405Beware that on some ELF systems this attribute is unsuitable for
3406global functions in shared libraries with lazy binding (which is the
3407default). Lazy binding will send the first call via resolving code in
3408the loader, which might assume EAX, EDX and ECX can be clobbered, as
3409per the standard calling conventions. Solaris 8 is affected by this.
3410GNU systems with GLIBC 2.1 or higher, and FreeBSD, are believed to be
dc8c96bb 3411safe since the loaders there save EAX, EDX and ECX. (Lazy binding can be
7c85682d 3412disabled with the linker or the loader if desired, to avoid the
3413problem.)
e27ad2d5 3414
3524624e 3415@item sseregparm
3416@cindex @code{sseregparm} attribute
3417On the Intel 386 with SSE support, the @code{sseregparm} attribute
56a575a5 3418causes the compiler to pass up to 3 floating point arguments in
3524624e 3419SSE registers instead of on the stack. Functions that take a
3420variable number of arguments will continue to pass all of their
3421floating point arguments on the stack.
3422
124c0201 3423@item force_align_arg_pointer
3424@cindex @code{force_align_arg_pointer} attribute
3425On the Intel x86, the @code{force_align_arg_pointer} attribute may be
3426applied to individual function definitions, generating an alternate
27a7a23a 3427prologue and epilogue that realigns the runtime stack if necessary.
3428This supports mixing legacy codes that run with a 4-byte aligned stack
3429with modern codes that keep a 16-byte stack for SSE compatibility.
124c0201 3430
5241f4ad 3431@item resbank
3432@cindex @code{resbank} attribute
3433On the SH2A target, this attribute enables the high-speed register
3434saving and restoration using a register bank for @code{interrupt_handler}
91f54ca3 3435routines. Saving to the bank is performed automatically after the CPU
5241f4ad 3436accepts an interrupt that uses a register bank.
3437
3438The nineteen 32-bit registers comprising general register R0 to R14,
3439control register GBR, and system registers MACH, MACL, and PR and the
3440vector table address offset are saved into a register bank. Register
3441banks are stacked in first-in last-out (FILO) sequence. Restoration
3442from the bank is executed by issuing a RESBANK instruction.
3443
26d1c5ff 3444@item returns_twice
3445@cindex @code{returns_twice} attribute
3446The @code{returns_twice} attribute tells the compiler that a function may
3447return more than one time. The compiler will ensure that all registers
3448are dead before calling such a function and will emit a warning about
3449the variables that may be clobbered after the second return from the
3450function. Examples of such functions are @code{setjmp} and @code{vfork}.
3451The @code{longjmp}-like counterpart of such function, if any, might need
3452to be marked with the @code{noreturn} attribute.
3453
7c85682d 3454@item saveall
9e6a0967 3455@cindex save all registers on the Blackfin, H8/300, H8/300H, and H8S
3456Use this attribute on the Blackfin, H8/300, H8/300H, and H8S to indicate that
7c85682d 3457all registers except the stack pointer should be saved in the prologue
3458regardless of whether they are used or not.
e27ad2d5 3459
d34b0d1e 3460@item save_volatiles
3461@cindex save volatile registers on the MicroBlaze
3462Use this attribute on the MicroBlaze to indicate that the function is
15b474a2 3463an interrupt handler. All volatile registers (in addition to non-volatile
3464registers) will be saved in the function prologue. If the function is a leaf
3465function, only volatiles used by the function are saved. A normal function
3466return is generated instead of a return from interrupt.
d34b0d1e 3467
7c85682d 3468@item section ("@var{section-name}")
3469@cindex @code{section} function attribute
3470Normally, the compiler places the code it generates in the @code{text} section.
3471Sometimes, however, you need additional sections, or you need certain
3472particular functions to appear in special sections. The @code{section}
3473attribute specifies that a function lives in a particular section.
3474For example, the declaration:
e27ad2d5 3475
3476@smallexample
7c85682d 3477extern void foobar (void) __attribute__ ((section ("bar")));
e27ad2d5 3478@end smallexample
3479
7c85682d 3480@noindent
3481puts the function @code{foobar} in the @code{bar} section.
e27ad2d5 3482
7c85682d 3483Some file formats do not support arbitrary sections so the @code{section}
3484attribute is not available on all platforms.
3485If you need to map the entire contents of a module to a particular
3486section, consider using the facilities of the linker instead.
3487
bf6c8de0 3488@item sentinel
3489@cindex @code{sentinel} function attribute
50ca527f 3490This function attribute ensures that a parameter in a function call is
3491an explicit @code{NULL}. The attribute is only valid on variadic
3492functions. By default, the sentinel is located at position zero, the
3493last parameter of the function call. If an optional integer position
3494argument P is supplied to the attribute, the sentinel must be located at
3495position P counting backwards from the end of the argument list.
3496
3497@smallexample
3498__attribute__ ((sentinel))
3499is equivalent to
3500__attribute__ ((sentinel(0)))
3501@end smallexample
3502
3503The attribute is automatically set with a position of 0 for the built-in
3504functions @code{execl} and @code{execlp}. The built-in function
515c3cb4 3505@code{execle} has the attribute set with a position of 1.
50ca527f 3506
3507A valid @code{NULL} in this context is defined as zero with any pointer
3508type. If your system defines the @code{NULL} macro with an integer type
3509then you need to add an explicit cast. GCC replaces @code{stddef.h}
3510with a copy that redefines NULL appropriately.
3511
3512The warnings for missing or incorrect sentinels are enabled with
3513@option{-Wformat}.
bf6c8de0 3514
7c85682d 3515@item short_call
3516See long_call/short_call.
3517
3518@item shortcall
3519See longcall/shortcall.
3520
3521@item signal
ea679361 3522@cindex interrupt handler functions on the AVR processors
7c85682d 3523Use this attribute on the AVR to indicate that the specified
ea679361 3524function is an interrupt handler. The compiler will generate function
3525entry and exit sequences suitable for use in an interrupt handler when this
3526attribute is present.
3527
3528See also the @code{interrupt} function attribute.
3529
3530The AVR hardware globally disables interrupts when an interrupt is executed.
3531Interrupt handler functions defined with the @code{signal} attribute
3532do not re-enable interrupts. It is save to enable interrupts in a
3533@code{signal} handler. This ``save'' only applies to the code
3534generated by the compiler and not to the IRQ-layout of the
3535application which is responsibility of the application.
3536
3537If both @code{signal} and @code{interrupt} are specified for the same
3538function, @code{signal} will be silently ignored.
9763338f 3539
3540@item sp_switch
eafbc061 3541Use this attribute on the SH to indicate an @code{interrupt_handler}
9763338f 3542function should switch to an alternate stack. It expects a string
3543argument that names a global variable holding the address of the
3544alternate stack.
3545
3546@smallexample
3547void *alt_stack;
70c2c81c 3548void f () __attribute__ ((interrupt_handler,
3549 sp_switch ("alt_stack")));
9763338f 3550@end smallexample
3551
7c85682d 3552@item stdcall
3553@cindex functions that pop the argument stack on the 386
3554On the Intel 386, the @code{stdcall} attribute causes the compiler to
3555assume that the called function will pop off the stack space used to
3556pass arguments, unless it takes a variable number of arguments.
146ef39f 3557
b84fdfe2 3558@item syscall_linkage
3559@cindex @code{syscall_linkage} attribute
3560This attribute is used to modify the IA64 calling convention by marking
3561all input registers as live at all function exits. This makes it possible
3562to restart a system call after an interrupt without having to save/restore
3563the input registers. This also prevents kernel data from leaking into
3564application code.
3565
c17add59 3566@item target
3567@cindex @code{target} function attribute
3568The @code{target} attribute is used to specify that a function is to
3569be compiled with different target options than specified on the
3570command line. This can be used for instance to have functions
3571compiled with a different ISA (instruction set architecture) than the
3572default. You can also use the @samp{#pragma GCC target} pragma to set
3573more than one function to be compiled with specific target options.
3574@xref{Function Specific Option Pragmas}, for details about the
3575@samp{#pragma GCC target} pragma.
3576
3577For instance on a 386, you could compile one function with
3578@code{target("sse4.1,arch=core2")} and another with
3579@code{target("sse4a,arch=amdfam10")} that would be equivalent to
3580compiling the first function with @option{-msse4.1} and
3581@option{-march=core2} options, and the second function with
3582@option{-msse4a} and @option{-march=amdfam10} options. It is up to the
3583user to make sure that a function is only invoked on a machine that
3584supports the particular ISA it was compiled for (for example by using
3585@code{cpuid} on 386 to determine what feature bits and architecture
3586family are used).
3587
3588@smallexample
3589int core2_func (void) __attribute__ ((__target__ ("arch=core2")));
3590int sse3_func (void) __attribute__ ((__target__ ("sse3")));
3591@end smallexample
3592
3593On the 386, the following options are allowed:
3594
3595@table @samp
3596@item abm
3597@itemx no-abm
3598@cindex @code{target("abm")} attribute
3599Enable/disable the generation of the advanced bit instructions.
3600
3601@item aes
3602@itemx no-aes
3603@cindex @code{target("aes")} attribute
3604Enable/disable the generation of the AES instructions.
3605
3606@item mmx
3607@itemx no-mmx
3608@cindex @code{target("mmx")} attribute
3609Enable/disable the generation of the MMX instructions.
3610
3611@item pclmul
3612@itemx no-pclmul
3613@cindex @code{target("pclmul")} attribute
3614Enable/disable the generation of the PCLMUL instructions.
3615
3616@item popcnt
3617@itemx no-popcnt
3618@cindex @code{target("popcnt")} attribute
3619Enable/disable the generation of the POPCNT instruction.
3620
3621@item sse
3622@itemx no-sse
3623@cindex @code{target("sse")} attribute
3624Enable/disable the generation of the SSE instructions.
3625
3626@item sse2
3627@itemx no-sse2
3628@cindex @code{target("sse2")} attribute
3629Enable/disable the generation of the SSE2 instructions.
3630
3631@item sse3
3632@itemx no-sse3
3633@cindex @code{target("sse3")} attribute
3634Enable/disable the generation of the SSE3 instructions.
3635
3636@item sse4
3637@itemx no-sse4
3638@cindex @code{target("sse4")} attribute
3639Enable/disable the generation of the SSE4 instructions (both SSE4.1
3640and SSE4.2).
3641
3642@item sse4.1
3643@itemx no-sse4.1
3644@cindex @code{target("sse4.1")} attribute
3645Enable/disable the generation of the sse4.1 instructions.
3646
3647@item sse4.2
3648@itemx no-sse4.2
3649@cindex @code{target("sse4.2")} attribute
3650Enable/disable the generation of the sse4.2 instructions.
3651
3652@item sse4a
3653@itemx no-sse4a
3654@cindex @code{target("sse4a")} attribute
3655Enable/disable the generation of the SSE4A instructions.
3656
2f212aae 3657@item fma4
3658@itemx no-fma4
3659@cindex @code{target("fma4")} attribute
3660Enable/disable the generation of the FMA4 instructions.
3661
18525343 3662@item xop
3663@itemx no-xop
3664@cindex @code{target("xop")} attribute
3665Enable/disable the generation of the XOP instructions.
3666
048fbb59 3667@item lwp
3668@itemx no-lwp
3669@cindex @code{target("lwp")} attribute
3670Enable/disable the generation of the LWP instructions.
3671
c17add59 3672@item ssse3
3673@itemx no-ssse3
3674@cindex @code{target("ssse3")} attribute
3675Enable/disable the generation of the SSSE3 instructions.
3676
3677@item cld
3678@itemx no-cld
3679@cindex @code{target("cld")} attribute
3680Enable/disable the generation of the CLD before string moves.
3681
3682@item fancy-math-387
3683@itemx no-fancy-math-387
3684@cindex @code{target("fancy-math-387")} attribute
3685Enable/disable the generation of the @code{sin}, @code{cos}, and
3686@code{sqrt} instructions on the 387 floating point unit.
3687
3688@item fused-madd
3689@itemx no-fused-madd
3690@cindex @code{target("fused-madd")} attribute
3691Enable/disable the generation of the fused multiply/add instructions.
3692
3693@item ieee-fp
3694@itemx no-ieee-fp
3695@cindex @code{target("ieee-fp")} attribute
3696Enable/disable the generation of floating point that depends on IEEE arithmetic.
3697
3698@item inline-all-stringops
3699@itemx no-inline-all-stringops
3700@cindex @code{target("inline-all-stringops")} attribute
3701Enable/disable inlining of string operations.
3702
3703@item inline-stringops-dynamically
3704@itemx no-inline-stringops-dynamically
3705@cindex @code{target("inline-stringops-dynamically")} attribute
3706Enable/disable the generation of the inline code to do small string
3707operations and calling the library routines for large operations.
3708
3709@item align-stringops
3710@itemx no-align-stringops
3711@cindex @code{target("align-stringops")} attribute
3712Do/do not align destination of inlined string operations.
3713
3714@item recip
3715@itemx no-recip
3716@cindex @code{target("recip")} attribute
3717Enable/disable the generation of RCPSS, RCPPS, RSQRTSS and RSQRTPS
8898b2ef 3718instructions followed an additional Newton-Raphson step instead of
c17add59 3719doing a floating point division.
3720
3721@item arch=@var{ARCH}
3722@cindex @code{target("arch=@var{ARCH}")} attribute
3723Specify the architecture to generate code for in compiling the function.
3724
3725@item tune=@var{TUNE}
3726@cindex @code{target("tune=@var{TUNE}")} attribute
3727Specify the architecture to tune for in compiling the function.
3728
3729@item fpmath=@var{FPMATH}
3730@cindex @code{target("fpmath=@var{FPMATH}")} attribute
3731Specify which floating point unit to use. The
3732@code{target("fpmath=sse,387")} option must be specified as
3733@code{target("fpmath=sse+387")} because the comma would separate
3734different options.
0695a9f1 3735@end table
755fa783 3736
755fa783 3737On the PowerPC, the following options are allowed:
3738
3739@table @samp
3740@item altivec
3741@itemx no-altivec
3742@cindex @code{target("altivec")} attribute
3743Generate code that uses (does not use) AltiVec instructions. In
374432-bit code, you cannot enable Altivec instructions unless
3745@option{-mabi=altivec} was used on the command line.
3746
3747@item cmpb
3748@itemx no-cmpb
3749@cindex @code{target("cmpb")} attribute
3750Generate code that uses (does not use) the compare bytes instruction
3751implemented on the POWER6 processor and other processors that support
3752the PowerPC V2.05 architecture.
3753
3754@item dlmzb
3755@itemx no-dlmzb
3756@cindex @code{target("dlmzb")} attribute
3757Generate code that uses (does not use) the string-search @samp{dlmzb}
3758instruction on the IBM 405, 440, 464 and 476 processors. This instruction is
9d75589a 3759generated by default when targeting those processors.
755fa783 3760
3761@item fprnd
3762@itemx no-fprnd
3763@cindex @code{target("fprnd")} attribute
3764Generate code that uses (does not use) the FP round to integer
3765instructions implemented on the POWER5+ processor and other processors
3766that support the PowerPC V2.03 architecture.
3767
3768@item hard-dfp
3769@itemx no-hard-dfp
3770@cindex @code{target("hard-dfp")} attribute
3771Generate code that uses (does not use) the decimal floating point
3772instructions implemented on some POWER processors.
3773
3774@item isel
3775@itemx no-isel
3776@cindex @code{target("isel")} attribute
3777Generate code that uses (does not use) ISEL instruction.
3778
3779@item mfcrf
3780@itemx no-mfcrf
3781@cindex @code{target("mfcrf")} attribute
3782Generate code that uses (does not use) the move from condition
3783register field instruction implemented on the POWER4 processor and
3784other processors that support the PowerPC V2.01 architecture.
3785
3786@item mfpgpr
3787@itemx no-mfpgpr
3788@cindex @code{target("mfpgpr")} attribute
3789Generate code that uses (does not use) the FP move to/from general
3790purpose register instructions implemented on the POWER6X processor and
3791other processors that support the extended PowerPC V2.05 architecture.
3792
3793@item mulhw
3794@itemx no-mulhw
3795@cindex @code{target("mulhw")} attribute
3796Generate code that uses (does not use) the half-word multiply and
3797multiply-accumulate instructions on the IBM 405, 440, 464 and 476 processors.
9d75589a 3798These instructions are generated by default when targeting those
755fa783 3799processors.
3800
3801@item multiple
3802@itemx no-multiple
3803@cindex @code{target("multiple")} attribute
3804Generate code that uses (does not use) the load multiple word
3805instructions and the store multiple word instructions.
3806
3807@item update
3808@itemx no-update
3809@cindex @code{target("update")} attribute
3810Generate code that uses (does not use) the load or store instructions
3811that update the base register to the address of the calculated memory
3812location.
3813
3814@item popcntb
3815@itemx no-popcntb
3816@cindex @code{target("popcntb")} attribute
3817Generate code that uses (does not use) the popcount and double
3818precision FP reciprocal estimate instruction implemented on the POWER5
3819processor and other processors that support the PowerPC V2.02
3820architecture.
3821
3822@item popcntd
3823@itemx no-popcntd
3824@cindex @code{target("popcntd")} attribute
3825Generate code that uses (does not use) the popcount instruction
3826implemented on the POWER7 processor and other processors that support
3827the PowerPC V2.06 architecture.
3828
3829@item powerpc-gfxopt
3830@itemx no-powerpc-gfxopt
3831@cindex @code{target("powerpc-gfxopt")} attribute
3832Generate code that uses (does not use) the optional PowerPC
3833architecture instructions in the Graphics group, including
3834floating-point select.
3835
3836@item powerpc-gpopt
3837@itemx no-powerpc-gpopt
3838@cindex @code{target("powerpc-gpopt")} attribute
3839Generate code that uses (does not use) the optional PowerPC
3840architecture instructions in the General Purpose group, including
3841floating-point square root.
3842
3843@item recip-precision
3844@itemx no-recip-precision
3845@cindex @code{target("recip-precision")} attribute
3846Assume (do not assume) that the reciprocal estimate instructions
3847provide higher precision estimates than is mandated by the powerpc
3848ABI.
3849
3850@item string
3851@itemx no-string
3852@cindex @code{target("string")} attribute
3853Generate code that uses (does not use) the load string instructions
3854and the store string word instructions to save multiple registers and
3855do small block moves.
3856
3857@item vsx
3858@itemx no-vsx
3859@cindex @code{target("vsx")} attribute
3860Generate code that uses (does not use) vector/scalar (VSX)
3861instructions, and also enable the use of built-in functions that allow
3862more direct access to the VSX instruction set. In 32-bit code, you
3863cannot enable VSX or Altivec instructions unless
3864@option{-mabi=altivec} was used on the command line.
3865
3866@item friz
3867@itemx no-friz
3868@cindex @code{target("friz")} attribute
3869Generate (do not generate) the @code{friz} instruction when the
3870@option{-funsafe-math-optimizations} option is used to optimize
3871rounding a floating point value to 64-bit integer and back to floating
3872point. The @code{friz} instruction does not return the same value if
3873the floating point number is too large to fit in an integer.
3874
3875@item avoid-indexed-addresses
3876@itemx no-avoid-indexed-addresses
3877@cindex @code{target("avoid-indexed-addresses")} attribute
3878Generate code that tries to avoid (not avoid) the use of indexed load
3879or store instructions.
3880
3881@item paired
3882@itemx no-paired
3883@cindex @code{target("paired")} attribute
3884Generate code that uses (does not use) the generation of PAIRED simd
3885instructions.
3886
3887@item longcall
3888@itemx no-longcall
3889@cindex @code{target("longcall")} attribute
3890Generate code that assumes (does not assume) that all calls are far
3891away so that a longer more expensive calling sequence is required.
3892
3893@item cpu=@var{CPU}
3894@cindex @code{target("cpu=@var{CPU}")} attribute
b59688ee 3895Specify the architecture to generate code for when compiling the
79b69060 3896function. If you select the @code{target("cpu=power7")} attribute when
755fa783 3897generating 32-bit code, VSX and Altivec instructions are not generated
3898unless you use the @option{-mabi=altivec} option on the command line.
3899
3900@item tune=@var{TUNE}
3901@cindex @code{target("tune=@var{TUNE}")} attribute
b59688ee 3902Specify the architecture to tune for when compiling the function. If
755fa783 3903you do not specify the @code{target("tune=@var{TUNE}")} attribute and
b59688ee 3904you do specify the @code{target("cpu=@var{CPU}")} attribute,
755fa783 3905compilation will tune for the @var{CPU} architecture, and not the
3906default tuning specified on the command line.
3907@end table
c17add59 3908
755fa783 3909On the 386/x86_64 and PowerPC backends, you can use either multiple
3910strings to specify multiple options, or you can separate the option
3911with a comma (@code{,}).
c17add59 3912
755fa783 3913On the 386/x86_64 and PowerPC backends, the inliner will not inline a
3914function that has different target options than the caller, unless the
3915callee has a subset of the target options of the caller. For example
3916a function declared with @code{target("sse3")} can inline a function
3917with @code{target("sse2")}, since @code{-msse3} implies @code{-msse2}.
c17add59 3918
3919The @code{target} attribute is not implemented in GCC versions earlier
755fa783 3920than 4.4 for the i386/x86_64 and 4.6 for the PowerPC backends. It is
3921not currently implemented for other backends.
c17add59 3922
146ef39f 3923@item tiny_data
11a83f51 3924@cindex tiny data section on the H8/300H and H8S
3925Use this attribute on the H8/300H and H8S to indicate that the specified
146ef39f 3926variable should be placed into the tiny data section.
3927The compiler will generate more efficient code for loads and stores
3928on data in the tiny data section. Note the tiny data area is limited to
3929slightly under 32kbytes of data.
097cea9f 3930
7c85682d 3931@item trap_exit
3932Use this attribute on the SH for an @code{interrupt_handler} to return using
3933@code{trapa} instead of @code{rte}. This attribute expects an integer
3934argument specifying the trap number to be used.
097cea9f 3935
7c85682d 3936@item unused
3937@cindex @code{unused} attribute.
3938This attribute, attached to a function, means that the function is meant
3939to be possibly unused. GCC will not produce a warning for this
3940function.
b8629bcb 3941
7c85682d 3942@item used
3943@cindex @code{used} attribute.
3944This attribute, attached to a function, means that code must be emitted
3945for the function even if it appears that the function is not referenced.
3946This is useful, for example, when the function is referenced only in
3947inline assembly.
76b9b5f9 3948
c86f0926 3949When applied to a member function of a C++ class template, the
3950attribute also means that the function will be instantiated if the
3951class itself is instantiated.
3952
9afff52d 3953@item version_id
b84fdfe2 3954@cindex @code{version_id} attribute
3955This IA64 HP-UX attribute, attached to a global variable or function, renames a
9afff52d 3956symbol to contain a version string, thus allowing for function level
3957versioning. HP-UX system header files may use version level functioning
3958for some system calls.
3959
3960@smallexample
3961extern int foo () __attribute__((version_id ("20040821")));
3962@end smallexample
3963
3964Calls to @var{foo} will be mapped to calls to @var{foo@{20040821@}}.
3965
7c85682d 3966@item visibility ("@var{visibility_type}")
3967@cindex @code{visibility} attribute
8ab158f9 3968This attribute affects the linkage of the declaration to which it is attached.
3969There are four supported @var{visibility_type} values: default,
3970hidden, protected or internal visibility.
76b9b5f9 3971
7c85682d 3972@smallexample
3973void __attribute__ ((visibility ("protected")))
3974f () @{ /* @r{Do something.} */; @}
3975int i __attribute__ ((visibility ("hidden")));
3976@end smallexample
76b9b5f9 3977
8ab158f9 3978The possible values of @var{visibility_type} correspond to the
3979visibility settings in the ELF gABI.
76b9b5f9 3980
7c85682d 3981@table @dfn
3c5c992f 3982@c keep this list of visibilities in alphabetical order.
195d932a 3983
7c85682d 3984@item default
8ab158f9 3985Default visibility is the normal case for the object file format.
3986This value is available for the visibility attribute to override other
3987options that may change the assumed visibility of entities.
3988
3989On ELF, default visibility means that the declaration is visible to other
3990modules and, in shared libraries, means that the declared entity may be
3991overridden.
3992
3993On Darwin, default visibility means that the declaration is visible to
3994other modules.
3995
3996Default visibility corresponds to ``external linkage'' in the language.
195d932a 3997
7c85682d 3998@item hidden
8ab158f9 3999Hidden visibility indicates that the entity declared will have a new
4000form of linkage, which we'll call ``hidden linkage''. Two
4001declarations of an object with hidden linkage refer to the same object
4002if they are in the same shared object.
195d932a 4003
7c85682d 4004@item internal
4005Internal visibility is like hidden visibility, but with additional
8ab158f9 4006processor specific semantics. Unless otherwise specified by the
4007psABI, GCC defines internal visibility to mean that a function is
4008@emph{never} called from another module. Compare this with hidden
4009functions which, while they cannot be referenced directly by other
4010modules, can be referenced indirectly via function pointers. By
4011indicating that a function cannot be called from outside the module,
4012GCC may for instance omit the load of a PIC register since it is known
4013that the calling function loaded the correct value.
195d932a 4014
7c85682d 4015@item protected
8ab158f9 4016Protected visibility is like default visibility except that it
4017indicates that references within the defining module will bind to the
4018definition in that module. That is, the declared entity cannot be
4019overridden by another module.
195d932a 4020
7c85682d 4021@end table
195d932a 4022
8ab158f9 4023All visibilities are supported on many, but not all, ELF targets
4024(supported when the assembler supports the @samp{.visibility}
4025pseudo-op). Default visibility is supported everywhere. Hidden
4026visibility is supported on Darwin targets.
4027
4028The visibility attribute should be applied only to declarations which
4029would otherwise have external linkage. The attribute should be applied
4030consistently, so that the same entity should not be declared with
4031different settings of the attribute.
4032
4033In C++, the visibility attribute applies to types as well as functions
4a2849cb 4034and objects, because in C++ types have linkage. A class must not have
4035greater visibility than its non-static data member types and bases,
4036and class members default to the visibility of their class. Also, a
6a47600c 4037declaration without explicit visibility is limited to the visibility
4038of its type.
8ab158f9 4039
4040In C++, you can mark member functions and static member variables of a
d2258b2f 4041class with the visibility attribute. This is useful if you know a
8ab158f9 4042particular method or static member variable should only be used from
4043one shared object; then you can mark it hidden while the rest of the
4044class has default visibility. Care must be taken to avoid breaking
6a47600c 4045the One Definition Rule; for example, it is usually not useful to mark
4046an inline method as hidden without marking the whole class as hidden.
195d932a 4047
4a2849cb 4048A C++ namespace declaration can also have the visibility attribute.
4049This attribute applies only to the particular namespace body, not to
4050other definitions of the same namespace; it is equivalent to using
4051@samp{#pragma GCC visibility} before and after the namespace
4052definition (@pxref{Visibility Pragmas}).
4053
4054In C++, if a template argument has limited visibility, this
4055restriction is implicitly propagated to the template instantiation.
4056Otherwise, template instantiations and specializations default to the
4057visibility of their template.
4058
6a47600c 4059If both the template and enclosing class have explicit visibility, the
4060visibility from the template is used.
4061
7c3116fb 4062@item vliw
4063@cindex @code{vliw} attribute
4064On MeP, the @code{vliw} attribute tells the compiler to emit
4065instructions in VLIW mode instead of core mode. Note that this
4066attribute is not allowed unless a VLIW coprocessor has been configured
4067and enabled through command line options.
4068
7c85682d 4069@item warn_unused_result
4070@cindex @code{warn_unused_result} attribute
4071The @code{warn_unused_result} attribute causes a warning to be emitted
4072if a caller of the function with this attribute does not use its
4073return value. This is useful for functions where not checking
4074the result is either a security problem or always a bug, such as
4075@code{realloc}.
195d932a 4076
7c85682d 4077@smallexample
4078int fn () __attribute__ ((warn_unused_result));
4079int foo ()
4080@{
4081 if (fn () < 0) return -1;
4082 fn ();
4083 return 0;
4084@}
4085@end smallexample
195d932a 4086
7c85682d 4087results in warning on line 5.
195d932a 4088
7c85682d 4089@item weak
4090@cindex @code{weak} attribute
4091The @code{weak} attribute causes the declaration to be emitted as a weak
4092symbol rather than a global. This is primarily useful in defining
4093library functions which can be overridden in user code, though it can
4094also be used with non-function declarations. Weak symbols are supported
4095for ELF targets, and also for a.out targets when using the GNU assembler
4096and linker.
195d932a 4097
f4a30bd7 4098@item weakref
4099@itemx weakref ("@var{target}")
4100@cindex @code{weakref} attribute
4101The @code{weakref} attribute marks a declaration as a weak reference.
4102Without arguments, it should be accompanied by an @code{alias} attribute
4103naming the target symbol. Optionally, the @var{target} may be given as
4104an argument to @code{weakref} itself. In either case, @code{weakref}
4105implicitly marks the declaration as @code{weak}. Without a
4106@var{target}, given as an argument to @code{weakref} or to @code{alias},
4107@code{weakref} is equivalent to @code{weak}.
4108
4109@smallexample
0a3ecdc1 4110static int x() __attribute__ ((weakref ("y")));
f4a30bd7 4111/* is equivalent to... */
0a3ecdc1 4112static int x() __attribute__ ((weak, weakref, alias ("y")));
f4a30bd7 4113/* and to... */
0a3ecdc1 4114static int x() __attribute__ ((weakref));
4115static int x() __attribute__ ((alias ("y")));
f4a30bd7 4116@end smallexample
4117
4118A weak reference is an alias that does not by itself require a
4119definition to be given for the target symbol. If the target symbol is
bc2e3b16 4120only referenced through weak references, then it becomes a @code{weak}
f4a30bd7 4121undefined symbol. If it is directly referenced, however, then such
4122strong references prevail, and a definition will be required for the
4123symbol, not necessarily in the same translation unit.
4124
4125The effect is equivalent to moving all references to the alias to a
4126separate translation unit, renaming the alias to the aliased symbol,
4127declaring it as weak, compiling the two separate translation units and
4128performing a reloadable link on them.
4129
0a3ecdc1 4130At present, a declaration to which @code{weakref} is attached can
4131only be @code{static}.
4132
146ef39f 4133@end table
4134
4135You can specify multiple attributes in a declaration by separating them
4136by commas within the double parentheses or by immediately following an
4137attribute declaration with another attribute declaration.
4138
4139@cindex @code{#pragma}, reason for not using
4140@cindex pragma, reason for not using
4449f3e0 4141Some people object to the @code{__attribute__} feature, suggesting that
4142ISO C's @code{#pragma} should be used instead. At the time
4143@code{__attribute__} was designed, there were two reasons for not doing
4144this.
146ef39f 4145
4146@enumerate
4147@item
4148It is impossible to generate @code{#pragma} commands from a macro.
4149
4150@item
4151There is no telling what the same @code{#pragma} might mean in another
4152compiler.
4153@end enumerate
4154
4449f3e0 4155These two reasons applied to almost any application that might have been
4156proposed for @code{#pragma}. It was basically a mistake to use
4157@code{#pragma} for @emph{anything}.
4158
4159The ISO C99 standard includes @code{_Pragma}, which now allows pragmas
4160to be generated from macros. In addition, a @code{#pragma GCC}
4161namespace is now in use for GCC-specific pragmas. However, it has been
4162found convenient to use @code{__attribute__} to achieve a natural
4163attachment of attributes to their corresponding declarations, whereas
4164@code{#pragma GCC} is of use for constructs that do not naturally form
fd0ccb39 4165part of the grammar. @xref{Pragmas,,Pragmas Accepted by GCC}.
146ef39f 4166
b31bfb3f 4167@node Attribute Syntax
4168@section Attribute Syntax
4169@cindex attribute syntax
4170
4171This section describes the syntax with which @code{__attribute__} may be
4172used, and the constructs to which attribute specifiers bind, for the C
0858e3a2 4173language. Some details may vary for C++ and Objective-C@. Because of
b31bfb3f 4174infelicities in the grammar for attributes, some forms described here
4175may not be successfully parsed in all cases.
4176
e3c541f0 4177There are some problems with the semantics of attributes in C++. For
4178example, there are no manglings for attributes, although they may affect
4179code generation, so problems may arise when attributed types are used in
4180conjunction with templates or overloading. Similarly, @code{typeid}
4181does not distinguish between types with different attributes. Support
4182for attributes in C++ may be restricted in future to attributes on
4183declarations only, but not on nested declarators.
4184
b31bfb3f 4185@xref{Function Attributes}, for details of the semantics of attributes
4186applying to functions. @xref{Variable Attributes}, for details of the
4187semantics of attributes applying to variables. @xref{Type Attributes},
4188for details of the semantics of attributes applying to structure, union
4189and enumerated types.
4190
4191An @dfn{attribute specifier} is of the form
4192@code{__attribute__ ((@var{attribute-list}))}. An @dfn{attribute list}
4193is a possibly empty comma-separated sequence of @dfn{attributes}, where
4194each attribute is one of the following:
4195
4196@itemize @bullet
4197@item
4198Empty. Empty attributes are ignored.
4199
4200@item
4201A word (which may be an identifier such as @code{unused}, or a reserved
4202word such as @code{const}).
4203
4204@item
4205A word, followed by, in parentheses, parameters for the attribute.
4206These parameters take one of the following forms:
4207
4208@itemize @bullet
4209@item
4210An identifier. For example, @code{mode} attributes use this form.
4211
4212@item
4213An identifier followed by a comma and a non-empty comma-separated list
4214of expressions. For example, @code{format} attributes use this form.
4215
4216@item
4217A possibly empty comma-separated list of expressions. For example,
4218@code{format_arg} attributes use this form with the list being a single
4219integer constant expression, and @code{alias} attributes use this form
4220with the list being a single string constant.
4221@end itemize
4222@end itemize
4223
4224An @dfn{attribute specifier list} is a sequence of one or more attribute
4225specifiers, not separated by any other tokens.
4226
2f215800 4227In GNU C, an attribute specifier list may appear after the colon following a
b31bfb3f 4228label, other than a @code{case} or @code{default} label. The only
4229attribute it makes sense to use after a label is @code{unused}. This
4230feature is intended for code generated by programs which contains labels
4231that may be unused but which is compiled with @option{-Wall}. It would
4232not normally be appropriate to use in it human-written code, though it
4233could be useful in cases where the code that jumps to the label is
e1c8f1c5 4234contained within an @code{#ifdef} conditional. GNU C++ only permits
4235attributes on labels if the attribute specifier is immediately
4236followed by a semicolon (i.e., the label applies to an empty
4237statement). If the semicolon is missing, C++ label attributes are
4238ambiguous, as it is permissible for a declaration, which could begin
4239with an attribute list, to be labelled in C++. Declarations cannot be
4240labelled in C90 or C99, so the ambiguity does not arise there.
b31bfb3f 4241
4242An attribute specifier list may appear as part of a @code{struct},
4243@code{union} or @code{enum} specifier. It may go either immediately
4244after the @code{struct}, @code{union} or @code{enum} keyword, or after
4a2849cb 4245the closing brace. The former syntax is preferred.
b31bfb3f 4246Where attribute specifiers follow the closing brace, they are considered
4247to relate to the structure, union or enumerated type defined, not to any
4248enclosing declaration the type specifier appears in, and the type
4249defined is not complete until after the attribute specifiers.
4250@c Otherwise, there would be the following problems: a shift/reduce
20dd417a 4251@c conflict between attributes binding the struct/union/enum and
b31bfb3f 4252@c binding to the list of specifiers/qualifiers; and "aligned"
4253@c attributes could use sizeof for the structure, but the size could be
4254@c changed later by "packed" attributes.
4255
4256Otherwise, an attribute specifier appears as part of a declaration,
4257counting declarations of unnamed parameters and type names, and relates
4258to that declaration (which may be nested in another declaration, for
e3c541f0 4259example in the case of a parameter declaration), or to a particular declarator
4260within a declaration. Where an
d193f25f 4261attribute specifier is applied to a parameter declared as a function or
4262an array, it should apply to the function or array rather than the
4263pointer to which the parameter is implicitly converted, but this is not
4264yet correctly implemented.
b31bfb3f 4265
4266Any list of specifiers and qualifiers at the start of a declaration may
4267contain attribute specifiers, whether or not such a list may in that
4268context contain storage class specifiers. (Some attributes, however,
4269are essentially in the nature of storage class specifiers, and only make
4270sense where storage class specifiers may be used; for example,
4271@code{section}.) There is one necessary limitation to this syntax: the
4272first old-style parameter declaration in a function definition cannot
4273begin with an attribute specifier, because such an attribute applies to
4274the function instead by syntax described below (which, however, is not
4275yet implemented in this case). In some other cases, attribute
4276specifiers are permitted by this grammar but not yet supported by the
4277compiler. All attribute specifiers in this place relate to the
8e5fcce7 4278declaration as a whole. In the obsolescent usage where a type of
b31bfb3f 4279@code{int} is implied by the absence of type specifiers, such a list of
4280specifiers and qualifiers may be an attribute specifier list with no
4281other specifiers or qualifiers.
4282
b19fb627 4283At present, the first parameter in a function prototype must have some
4284type specifier which is not an attribute specifier; this resolves an
4285ambiguity in the interpretation of @code{void f(int
4286(__attribute__((foo)) x))}, but is subject to change. At present, if
4287the parentheses of a function declarator contain only attributes then
4288those attributes are ignored, rather than yielding an error or warning
4289or implying a single parameter of type int, but this is subject to
4290change.
4291
b31bfb3f 4292An attribute specifier list may appear immediately before a declarator
4293(other than the first) in a comma-separated list of declarators in a
4294declaration of more than one identifier using a single list of
ecb4f65e 4295specifiers and qualifiers. Such attribute specifiers apply
0fff59be 4296only to the identifier before whose declarator they appear. For
4297example, in
4298
4299@smallexample
4300__attribute__((noreturn)) void d0 (void),
4301 __attribute__((format(printf, 1, 2))) d1 (const char *, ...),
4302 d2 (void)
4303@end smallexample
4304
4305@noindent
4306the @code{noreturn} attribute applies to all the functions
ecb4f65e 4307declared; the @code{format} attribute only applies to @code{d1}.
b31bfb3f 4308
4309An attribute specifier list may appear immediately before the comma,
4310@code{=} or semicolon terminating the declaration of an identifier other
3961e70d 4311than a function definition. Such attribute specifiers apply
4312to the declared object or function. Where an
0fff59be 4313assembler name for an object or function is specified (@pxref{Asm
3961e70d 4314Labels}), the attribute must follow the @code{asm}
4315specification.
b31bfb3f 4316
4317An attribute specifier list may, in future, be permitted to appear after
4318the declarator in a function definition (before any old-style parameter
4319declarations or the function body).
4320
1fd94215 4321Attribute specifiers may be mixed with type qualifiers appearing inside
4322the @code{[]} of a parameter array declarator, in the C99 construct by
4323which such qualifiers are applied to the pointer to which the array is
4324implicitly converted. Such attribute specifiers apply to the pointer,
4325not to the array, but at present this is not implemented and they are
4326ignored.
4327
b31bfb3f 4328An attribute specifier list may appear at the start of a nested
4329declarator. At present, there are some limitations in this usage: the
e3c541f0 4330attributes correctly apply to the declarator, but for most individual
4331attributes the semantics this implies are not implemented.
4332When attribute specifiers follow the @code{*} of a pointer
ecb4f65e 4333declarator, they may be mixed with any type qualifiers present.
e3c541f0 4334The following describes the formal semantics of this syntax. It will make the
b31bfb3f 4335most sense if you are familiar with the formal specification of
4336declarators in the ISO C standard.
4337
4338Consider (as in C99 subclause 6.7.5 paragraph 4) a declaration @code{T
4339D1}, where @code{T} contains declaration specifiers that specify a type
4340@var{Type} (such as @code{int}) and @code{D1} is a declarator that
4341contains an identifier @var{ident}. The type specified for @var{ident}
4342for derived declarators whose type does not include an attribute
4343specifier is as in the ISO C standard.
4344
4345If @code{D1} has the form @code{( @var{attribute-specifier-list} D )},
4346and the declaration @code{T D} specifies the type
4347``@var{derived-declarator-type-list} @var{Type}'' for @var{ident}, then
4348@code{T D1} specifies the type ``@var{derived-declarator-type-list}
4349@var{attribute-specifier-list} @var{Type}'' for @var{ident}.
4350
4351If @code{D1} has the form @code{*
4352@var{type-qualifier-and-attribute-specifier-list} D}, and the
4353declaration @code{T D} specifies the type
4354``@var{derived-declarator-type-list} @var{Type}'' for @var{ident}, then
4355@code{T D1} specifies the type ``@var{derived-declarator-type-list}
5e96ea45 4356@var{type-qualifier-and-attribute-specifier-list} pointer to @var{Type}'' for
b31bfb3f 4357@var{ident}.
4358
228c5b30 4359For example,
0fff59be 4360
4361@smallexample
4362void (__attribute__((noreturn)) ****f) (void);
4363@end smallexample
4364
4365@noindent
4366specifies the type ``pointer to pointer to pointer to pointer to
4367non-returning function returning @code{void}''. As another example,
4368
4369@smallexample
4370char *__attribute__((aligned(8))) *f;
4371@end smallexample
4372
4373@noindent
4374specifies the type ``pointer to 8-byte-aligned pointer to @code{char}''.
e3c541f0 4375Note again that this does not work with most attributes; for example,
4376the usage of @samp{aligned} and @samp{noreturn} attributes given above
4377is not yet supported.
4378
4379For compatibility with existing code written for compiler versions that
4380did not implement attributes on nested declarators, some laxity is
4381allowed in the placing of attributes. If an attribute that only applies
4382to types is applied to a declaration, it will be treated as applying to
4383the type of that declaration. If an attribute that only applies to
4384declarations is applied to the type of a declaration, it will be treated
4385as applying to that declaration; and, for compatibility with code
4386placing the attributes immediately before the identifier declared, such
4387an attribute applied to a function return type will be treated as
4388applying to the function type, and such an attribute applied to an array
4389element type will be treated as applying to the array type. If an
4390attribute that only applies to function types is applied to a
4391pointer-to-function type, it will be treated as applying to the pointer
4392target type; if such an attribute is applied to a function return type
4393that is not a pointer-to-function type, it will be treated as applying
4394to the function type.
b31bfb3f 4395
146ef39f 4396@node Function Prototypes
4397@section Prototypes and Old-Style Function Definitions
4398@cindex function prototype declarations
4399@cindex old-style function definitions
4400@cindex promotion of formal parameters
4401
78b1f616 4402GNU C extends ISO C to allow a function prototype to override a later
146ef39f 4403old-style non-prototype definition. Consider the following example:
4404
a0ecd6b1 4405@smallexample
146ef39f 4406/* @r{Use prototypes unless the compiler is old-fashioned.} */
7223a120 4407#ifdef __STDC__
146ef39f 4408#define P(x) x
4409#else
4410#define P(x) ()
4411#endif
4412
4413/* @r{Prototype function declaration.} */
4414int isroot P((uid_t));
4415
4416/* @r{Old-style function definition.} */
4417int
12e2a142 4418isroot (x) /* @r{??? lossage here ???} */
146ef39f 4419 uid_t x;
4420@{
4421 return x == 0;
4422@}
a0ecd6b1 4423@end smallexample
146ef39f 4424
78b1f616 4425Suppose the type @code{uid_t} happens to be @code{short}. ISO C does
146ef39f 4426not allow this example, because subword arguments in old-style
4427non-prototype definitions are promoted. Therefore in this example the
4428function definition's argument is really an @code{int}, which does not
4429match the prototype argument type of @code{short}.
4430
78b1f616 4431This restriction of ISO C makes it hard to write code that is portable
146ef39f 4432to traditional C compilers, because the programmer does not know
4433whether the @code{uid_t} type is @code{short}, @code{int}, or
4434@code{long}. Therefore, in cases like these GNU C allows a prototype
4435to override a later old-style definition. More precisely, in GNU C, a
4436function prototype argument type overrides the argument type specified
4437by a later old-style definition if the former type is the same as the
4438latter type before promotion. Thus in GNU C the above example is
4439equivalent to the following:
4440
a0ecd6b1 4441@smallexample
146ef39f 4442int isroot (uid_t);
4443
4444int
4445isroot (uid_t x)
4446@{
4447 return x == 0;
4448@}
a0ecd6b1 4449@end smallexample
146ef39f 4450
0fff59be 4451@noindent
146ef39f 4452GNU C++ does not support old-style function definitions, so this
4453extension is irrelevant.
4454
4455@node C++ Comments
4456@section C++ Style Comments
12786727 4457@cindex @code{//}
146ef39f 4458@cindex C++ comments
4459@cindex comments, C++ style
4460
4461In GNU C, you may use C++ style comments, which start with @samp{//} and
4462continue until the end of the line. Many other C implementations allow
455730ef 4463such comments, and they are included in the 1999 C standard. However,
4464C++ style comments are not recognized if you specify an @option{-std}
4465option specifying a version of ISO C before C99, or @option{-ansi}
32f1f35b 4466(equivalent to @option{-std=c90}).
146ef39f 4467
4468@node Dollar Signs
4469@section Dollar Signs in Identifier Names
4470@cindex $
4471@cindex dollar signs in identifier names
4472@cindex identifier names, dollar signs in
4473
fae2383c 4474In GNU C, you may normally use dollar signs in identifier names.
4475This is because many traditional C implementations allow such identifiers.
4476However, dollar signs in identifiers are not supported on a few target
4477machines, typically because the target assembler does not allow them.
146ef39f 4478
4479@node Character Escapes
4480@section The Character @key{ESC} in Constants
4481
4482You can use the sequence @samp{\e} in a string or character constant to
4483stand for the ASCII character @key{ESC}.
4484
146ef39f 4485@node Variable Attributes
4486@section Specifying Attributes of Variables
4487@cindex attribute of variables
4488@cindex variable attributes
4489
4490The keyword @code{__attribute__} allows you to specify special
4491attributes of variables or structure fields. This keyword is followed
e7d1f980 4492by an attribute specification inside double parentheses. Some
4493attributes are currently defined generically for variables.
4494Other attributes are defined for variables on particular target
4495systems. Other attributes are available for functions
4496(@pxref{Function Attributes}) and for types (@pxref{Type Attributes}).
4497Other front ends might define more attributes
4498(@pxref{C++ Extensions,,Extensions to the C++ Language}).
146ef39f 4499
4500You may also specify attributes with @samp{__} preceding and following
4501each keyword. This allows you to use them in header files without
4502being concerned about a possible macro of the same name. For example,
4503you may use @code{__aligned__} instead of @code{aligned}.
4504
b31bfb3f 4505@xref{Attribute Syntax}, for details of the exact syntax for using
4506attributes.
4507
146ef39f 4508@table @code
4509@cindex @code{aligned} attribute
4510@item aligned (@var{alignment})
4511This attribute specifies a minimum alignment for the variable or
4512structure field, measured in bytes. For example, the declaration:
4513
4514@smallexample
4515int x __attribute__ ((aligned (16))) = 0;
4516@end smallexample
4517
4518@noindent
4519causes the compiler to allocate the global variable @code{x} on a
452016-byte boundary. On a 68040, this could be used in conjunction with
4521an @code{asm} expression to access the @code{move16} instruction which
4522requires 16-byte aligned operands.
4523
4524You can also specify the alignment of structure fields. For example, to
4525create a double-word aligned @code{int} pair, you could write:
4526
4527@smallexample
4528struct foo @{ int x[2] __attribute__ ((aligned (8))); @};
4529@end smallexample
4530
4531@noindent
4532This is an alternative to creating a union with a @code{double} member
4533that forces the union to be double-word aligned.
4534
146ef39f 4535As in the preceding examples, you can explicitly specify the alignment
4536(in bytes) that you wish the compiler to use for a given variable or
4537structure field. Alternatively, you can leave out the alignment factor
02421213 4538and just ask the compiler to align a variable or field to the
4539default alignment for the target architecture you are compiling for.
4540The default alignment is sufficient for all scalar types, but may not be
4541enough for all vector types on a target which supports vector operations.
4542The default alignment is fixed for a particular target ABI.
4543
4544Gcc also provides a target specific macro @code{__BIGGEST_ALIGNMENT__},
4545which is the largest alignment ever used for any data type on the
4546target machine you are compiling for. For example, you could write:
146ef39f 4547
4548@smallexample
02421213 4549short array[3] __attribute__ ((aligned (__BIGGEST_ALIGNMENT__)));
146ef39f 4550@end smallexample
4551
02421213 4552The compiler automatically sets the alignment for the declared
4553variable or field to @code{__BIGGEST_ALIGNMENT__}. Doing this can
4554often make copy operations more efficient, because the compiler can
4555use whatever instructions copy the biggest chunks of memory when
4556performing copies to or from the variables or fields that you have
4557aligned this way. Note that the value of @code{__BIGGEST_ALIGNMENT__}
4558may change depending on command line options.
146ef39f 4559
2d3e8e7b 4560When used on a struct, or struct member, the @code{aligned} attribute can
4561only increase the alignment; in order to decrease it, the @code{packed}
4562attribute must be specified as well. When used as part of a typedef, the
4563@code{aligned} attribute can both increase and decrease alignment, and
4564specifying the @code{packed} attribute will generate a warning.
146ef39f 4565
4566Note that the effectiveness of @code{aligned} attributes may be limited
4567by inherent limitations in your linker. On many systems, the linker is
4568only able to arrange for variables to be aligned up to a certain maximum
4569alignment. (For some linkers, the maximum supported alignment may
4570be very very small.) If your linker is only able to align variables
4571up to a maximum of 8 byte alignment, then specifying @code{aligned(16)}
4572in an @code{__attribute__} will still only provide you with 8 byte
4573alignment. See your linker documentation for further information.
4574
15b474a2 4575The @code{aligned} attribute can also be used for functions
097b5c8b 4576(@pxref{Function Attributes}.)
4577
7acb29a3 4578@item cleanup (@var{cleanup_function})
4579@cindex @code{cleanup} attribute
4580The @code{cleanup} attribute runs a function when the variable goes
4581out of scope. This attribute can only be applied to auto function
4582scope variables; it may not be applied to parameters or variables
4583with static storage duration. The function must take one parameter,
4584a pointer to a type compatible with the variable. The return value
4585of the function (if any) is ignored.
4586
4587If @option{-fexceptions} is enabled, then @var{cleanup_function}
4588will be run during the stack unwinding that happens during the
4589processing of the exception. Note that the @code{cleanup} attribute
4590does not allow the exception to be caught, only to perform an action.
4591It is undefined what happens if @var{cleanup_function} does not
4592return normally.
4593
e7d1f980 4594@item common
4595@itemx nocommon
4596@cindex @code{common} attribute
4597@cindex @code{nocommon} attribute
4598@opindex fcommon
4599@opindex fno-common
4600The @code{common} attribute requests GCC to place a variable in
4601``common'' storage. The @code{nocommon} attribute requests the
01e3cadf 4602opposite---to allocate space for it directly.
e7d1f980 4603
7a0ad664 4604These attributes override the default chosen by the
e7d1f980 4605@option{-fno-common} and @option{-fcommon} flags respectively.
4606
4607@item deprecated
45c4e798 4608@itemx deprecated (@var{msg})
e7d1f980 4609@cindex @code{deprecated} attribute
4610The @code{deprecated} attribute results in a warning if the variable
4611is used anywhere in the source file. This is useful when identifying
4612variables that are expected to be removed in a future version of a
4613program. The warning also includes the location of the declaration
4614of the deprecated variable, to enable users to easily find further
4615information about why the variable is deprecated, or what they should
ea1c20d0 4616do instead. Note that the warning only occurs for uses:
e7d1f980 4617
4618@smallexample
4619extern int old_var __attribute__ ((deprecated));
4620extern int old_var;
4621int new_fn () @{ return old_var; @}
4622@end smallexample
4623
45c4e798 4624results in a warning on line 3 but not line 2. The optional msg
4625argument, which must be a string, will be printed in the warning if
4626present.
e7d1f980 4627
4628The @code{deprecated} attribute can also be used for functions and
4629types (@pxref{Function Attributes}, @pxref{Type Attributes}.)
4630
146ef39f 4631@item mode (@var{mode})
4632@cindex @code{mode} attribute
4633This attribute specifies the data type for the declaration---whichever
4634type corresponds to the mode @var{mode}. This in effect lets you
4635request an integer or floating point type according to its width.
4636
4637You may also specify a mode of @samp{byte} or @samp{__byte__} to
4638indicate the mode corresponding to a one-byte integer, @samp{word} or
4639@samp{__word__} for the mode of a one-word integer, and @samp{pointer}
4640or @samp{__pointer__} for the mode used to represent pointers.
4641
146ef39f 4642@item packed
4643@cindex @code{packed} attribute
4644The @code{packed} attribute specifies that a variable or structure field
4645should have the smallest possible alignment---one byte for a variable,
4646and one bit for a field, unless you specify a larger value with the
4647@code{aligned} attribute.
4648
4649Here is a structure in which the field @code{x} is packed, so that it
4650immediately follows @code{a}:
4651
a0ecd6b1 4652@smallexample
146ef39f 4653struct foo
4654@{
4655 char a;
4656 int x[2] __attribute__ ((packed));
4657@};
a0ecd6b1 4658@end smallexample
146ef39f 4659
9fd767c5 4660@emph{Note:} The 4.1, 4.2 and 4.3 series of GCC ignore the
4661@code{packed} attribute on bit-fields of type @code{char}. This has
4662been fixed in GCC 4.4 but the change can lead to differences in the
8898b2ef 4663structure layout. See the documentation of
9fd767c5 4664@option{-Wpacked-bitfield-compat} for more information.
4665
67791935 4666@item section ("@var{section-name}")
146ef39f 4667@cindex @code{section} variable attribute
4668Normally, the compiler places the objects it generates in sections like
4669@code{data} and @code{bss}. Sometimes, however, you need additional sections,
4670or you need certain particular variables to appear in special sections,
4671for example to map to special hardware. The @code{section}
4672attribute specifies that a variable (or function) lives in a particular
4673section. For example, this small program uses several specific section names:
4674
4675@smallexample
4676struct duart a __attribute__ ((section ("DUART_A"))) = @{ 0 @};
4677struct duart b __attribute__ ((section ("DUART_B"))) = @{ 0 @};
4678char stack[10000] __attribute__ ((section ("STACK"))) = @{ 0 @};
e5e13288 4679int init_data __attribute__ ((section ("INITDATA")));
146ef39f 4680
4681main()
4682@{
12e2a142 4683 /* @r{Initialize stack pointer} */
146ef39f 4684 init_sp (stack + sizeof (stack));
4685
12e2a142 4686 /* @r{Initialize initialized data} */
146ef39f 4687 memcpy (&init_data, &data, &edata - &data);
4688
12e2a142 4689 /* @r{Turn on the serial ports} */
146ef39f 4690 init_duart (&a);
4691 init_duart (&b);
4692@}
4693@end smallexample
4694
4695@noindent
e5e13288 4696Use the @code{section} attribute with
4697@emph{global} variables and not @emph{local} variables,
4698as shown in the example.
146ef39f 4699
e5e13288 4700You may use the @code{section} attribute with initialized or
4701uninitialized global variables but the linker requires
146ef39f 4702each object be defined once, with the exception that uninitialized
4703variables tentatively go in the @code{common} (or @code{bss}) section
e5e13288 4704and can be multiply ``defined''. Using the @code{section} attribute
4705will change what section the variable goes into and may cause the
4706linker to issue an error if an uninitialized variable has multiple
4707definitions. You can force a variable to be initialized with the
4708@option{-fno-common} flag or the @code{nocommon} attribute.
146ef39f 4709
4710Some file formats do not support arbitrary sections so the @code{section}
4711attribute is not available on all platforms.
4712If you need to map the entire contents of a module to a particular
4713section, consider using the facilities of the linker instead.
4714
87135be0 4715@item shared
4716@cindex @code{shared} variable attribute
c20b542c 4717On Microsoft Windows, in addition to putting variable definitions in a named
3b0848a2 4718section, the section can also be shared among all running copies of an
0858e3a2 4719executable or DLL@. For example, this small program defines shared data
67791935 4720by putting it in a named section @code{shared} and marking the section
87135be0 4721shareable:
4722
4723@smallexample
4724int foo __attribute__((section ("shared"), shared)) = 0;
4725
4726int
4727main()
4728@{
12e2a142 4729 /* @r{Read and write foo. All running
4730 copies see the same value.} */
87135be0 4731 return 0;
4732@}
4733@end smallexample
4734
4735@noindent
4736You may only use the @code{shared} attribute along with @code{section}
3b0848a2 4737attribute with a fully initialized global definition because of the way
87135be0 4738linkers work. See @code{section} attribute for more information.
4739
c20b542c 4740The @code{shared} attribute is only available on Microsoft Windows@.
87135be0 4741
e7d1f980 4742@item tls_model ("@var{tls_model}")
4743@cindex @code{tls_model} attribute
4744The @code{tls_model} attribute sets thread-local storage model
4745(@pxref{Thread-Local}) of a particular @code{__thread} variable,
bfe513a4 4746overriding @option{-ftls-model=} command-line switch on a per-variable
e7d1f980 4747basis.
4748The @var{tls_model} argument should be one of @code{global-dynamic},
4749@code{local-dynamic}, @code{initial-exec} or @code{local-exec}.
4750
4751Not all targets support this attribute.
4752
146ef39f 4753@item unused
4754This attribute, attached to a variable, means that the variable is meant
37744367 4755to be possibly unused. GCC will not produce a warning for this
146ef39f 4756variable.
4757
b7aa2b22 4758@item used
4759This attribute, attached to a variable, means that the variable must be
4760emitted even if it appears that the variable is not referenced.
4761
c86f0926 4762When applied to a static data member of a C++ class template, the
4763attribute also means that the member will be instantiated if the
4764class itself is instantiated.
4765
ae4718db 4766@item vector_size (@var{bytes})
4767This attribute specifies the vector size for the variable, measured in
4768bytes. For example, the declaration:
4769
4770@smallexample
4771int foo __attribute__ ((vector_size (16)));
4772@end smallexample
4773
4774@noindent
4775causes the compiler to set the mode for @code{foo}, to be 16 bytes,
4776divided into @code{int} sized units. Assuming a 32-bit int (a vector of
47774 units of 4 bytes), the corresponding mode of @code{foo} will be V4SI@.
4778
4779This attribute is only applicable to integral and float scalars,
4780although arrays, pointers, and function return values are allowed in
4781conjunction with this construct.
4782
4783Aggregates with this attribute are invalid, even if they are of the same
4784size as a corresponding scalar. For example, the declaration:
4785
4786@smallexample
6bdacb9b 4787struct S @{ int a; @};
ae4718db 4788struct S __attribute__ ((vector_size (16))) foo;
4789@end smallexample
4790
4791@noindent
4792is invalid even if the size of the structure is the same as the size of
4793the @code{int}.
4794
04868974 4795@item selectany
4796The @code{selectany} attribute causes an initialized global variable to
4797have link-once semantics. When multiple definitions of the variable are
4798encountered by the linker, the first is selected and the remainder are
4799discarded. Following usage by the Microsoft compiler, the linker is told
4800@emph{not} to warn about size or content differences of the multiple
4801definitions.
4802
4803Although the primary usage of this attribute is for POD types, the
4804attribute can also be applied to global C++ objects that are initialized
4805by a constructor. In this case, the static initialization and destruction
4806code for the object is emitted in each translation defining the object,
4807but the calls to the constructor and destructor are protected by a
7bd4091f 4808link-once guard variable.
04868974 4809
4810The @code{selectany} attribute is only available on Microsoft Windows
4811targets. You can use @code{__declspec (selectany)} as a synonym for
4812@code{__attribute__ ((selectany))} for compatibility with other
4813compilers.
4814
146ef39f 4815@item weak
e66bbea3 4816The @code{weak} attribute is described in @ref{Function Attributes}.
195d932a 4817
4818@item dllimport
e66bbea3 4819The @code{dllimport} attribute is described in @ref{Function Attributes}.
195d932a 4820
b44d6960 4821@item dllexport
e66bbea3 4822The @code{dllexport} attribute is described in @ref{Function Attributes}.
195d932a 4823
e7d1f980 4824@end table
4825
8516b1c4 4826@anchor{AVR Variable Attributes}
91f3009d 4827@subsection AVR Variable Attributes
4828
4829@table @code
4830@item progmem
4831@cindex @code{progmem} AVR variable attribute
8516b1c4 4832The @code{progmem} attribute is used on the AVR to place read-only
4833data in the non-volatile program memory (flash). The @code{progmem}
4834attribute accomplishes this by putting respective variables into a
4835section whose name starts with @code{.progmem}.
4836
6ee532ba 4837This attribute works similar to the @code{section} attribute
8516b1c4 4838but adds additional checking. Notice that just like the
4839@code{section} attribute, @code{progmem} affects the location
4840of the data but not how this data is accessed.
4841
6ee532ba 4842In order to read data located with the @code{progmem} attribute
4843(inline) assembler must be used.
4844@example
6222cbcc 4845/* Use custom macros from @w{@uref{http://nongnu.org/avr-libc/user-manual,AVR-LibC}} */
6ee532ba 4846#include <avr/pgmspace.h>
4847
4848/* Locate var in flash memory */
4849const int var[2] PROGMEM = @{ 1, 2 @};
4850
4851int read_var (int i)
4852@{
4853 /* Access var[] by accessor macro from avr/pgmspace.h */
4854 return (int) pgm_read_word (& var[i]);
4855@}
4856@end example
4857
8516b1c4 4858AVR is a Harvard architecture processor and data and read-only data
4859normally resides in the data memory (RAM).
6ee532ba 4860
4861See also the @ref{AVR Named Address Spaces} section for
4862an alternate way to locate and access data in flash memory.
91f3009d 4863@end table
4864
fc8aef7f 4865@subsection Blackfin Variable Attributes
4866
4867Three attributes are currently defined for the Blackfin.
4868
4869@table @code
4870@item l1_data
171b9b78 4871@itemx l1_data_A
4872@itemx l1_data_B
fc8aef7f 4873@cindex @code{l1_data} variable attribute
4874@cindex @code{l1_data_A} variable attribute
4875@cindex @code{l1_data_B} variable attribute
4876Use these attributes on the Blackfin to place the variable into L1 Data SRAM.
4877Variables with @code{l1_data} attribute will be put into the specific section
4878named @code{.l1.data}. Those with @code{l1_data_A} attribute will be put into
4879the specific section named @code{.l1.data.A}. Those with @code{l1_data_B}
4880attribute will be put into the specific section named @code{.l1.data.B}.
59fbccf3 4881
4882@item l2
4883@cindex @code{l2} variable attribute
4884Use this attribute on the Blackfin to place the variable into L2 SRAM.
4885Variables with @code{l2} attribute will be put into the specific section
4886named @code{.l2.data}.
fc8aef7f 4887@end table
4888
e7d1f980 4889@subsection M32R/D Variable Attributes
097cea9f 4890
b3d47662 4891One attribute is currently defined for the M32R/D@.
e7d1f980 4892
4893@table @code
097cea9f 4894@item model (@var{model-name})
4895@cindex variable addressability on the M32R/D
4896Use this attribute on the M32R/D to set the addressability of an object.
4897The identifier @var{model-name} is one of @code{small}, @code{medium},
4898or @code{large}, representing each of the code models.
4899
4900Small model objects live in the lower 16MB of memory (so that their
4901addresses can be loaded with the @code{ld24} instruction).
4902
3b0848a2 4903Medium and large model objects may live anywhere in the 32-bit address space
097cea9f 4904(the compiler will generate @code{seth/add3} instructions to load their
4905addresses).
e7d1f980 4906@end table
097cea9f 4907
7c3116fb 4908@anchor{MeP Variable Attributes}
4909@subsection MeP Variable Attributes
4910
4911The MeP target has a number of addressing modes and busses. The
4912@code{near} space spans the standard memory space's first 16 megabytes
4913(24 bits). The @code{far} space spans the entire 32-bit memory space.
4914The @code{based} space is a 128 byte region in the memory space which
4915is addressed relative to the @code{$tp} register. The @code{tiny}
4916space is a 65536 byte region relative to the @code{$gp} register. In
4917addition to these memory regions, the MeP target has a separate 16-bit
4918control bus which is specified with @code{cb} attributes.
4919
4920@table @code
4921
4922@item based
4923Any variable with the @code{based} attribute will be assigned to the
4924@code{.based} section, and will be accessed with relative to the
4925@code{$tp} register.
4926
4927@item tiny
4928Likewise, the @code{tiny} attribute assigned variables to the
4929@code{.tiny} section, relative to the @code{$gp} register.
4930
4931@item near
4932Variables with the @code{near} attribute are assumed to have addresses
4933that fit in a 24-bit addressing mode. This is the default for large
4934variables (@code{-mtiny=4} is the default) but this attribute can
4935override @code{-mtiny=} for small variables, or override @code{-ml}.
4936
4937@item far
4938Variables with the @code{far} attribute are addressed using a full
493932-bit address. Since this covers the entire memory space, this
4940allows modules to make no assumptions about where variables might be
4941stored.
4942
4943@item io
171b9b78 4944@itemx io (@var{addr})
7c3116fb 4945Variables with the @code{io} attribute are used to address
4946memory-mapped peripherals. If an address is specified, the variable
4947is assigned that address, else it is not assigned an address (it is
4948assumed some other module will assign an address). Example:
4949
4950@example
4951int timer_count __attribute__((io(0x123)));
4952@end example
4953
4954@item cb
171b9b78 4955@itemx cb (@var{addr})
7c3116fb 4956Variables with the @code{cb} attribute are used to access the control
4957bus, using special instructions. @code{addr} indicates the control bus
4958address. Example:
4959
4960@example
4961int cpu_clock __attribute__((cb(0x123)));
4962@end example
4963
4964@end table
4965
c4e8a4d4 4966@anchor{i386 Variable Attributes}
b09c5db2 4967@subsection i386 Variable Attributes
4968
4969Two attributes are currently defined for i386 configurations:
4970@code{ms_struct} and @code{gcc_struct}
4971
e7d1f980 4972@table @code
b09c5db2 4973@item ms_struct
4974@itemx gcc_struct
e7d1f980 4975@cindex @code{ms_struct} attribute
4976@cindex @code{gcc_struct} attribute
b09c5db2 4977
4978If @code{packed} is used on a structure, or if bit-fields are used
4979it may be that the Microsoft ABI packs them differently
4980than GCC would normally pack them. Particularly when moving packed
4981data between functions compiled with GCC and the native Microsoft compiler
4982(either via function call or as data in a file), it may be necessary to access
4983either format.
4984
c20b542c 4985Currently @option{-m[no-]ms-bitfields} is provided for the Microsoft Windows X86
b09c5db2 4986compilers to match the native Microsoft compiler.
7bd4091f 4987
4988The Microsoft structure layout algorithm is fairly simple with the exception
4989of the bitfield packing:
4990
4991The padding and alignment of members of structures and whether a bit field
4992can straddle a storage-unit boundary
4993
4994@enumerate
4995@item Structure members are stored sequentially in the order in which they are
4996declared: the first member has the lowest memory address and the last member
4997the highest.
4998
4999@item Every data object has an alignment-requirement. The alignment-requirement
5000for all data except structures, unions, and arrays is either the size of the
5001object or the current packing size (specified with either the aligned attribute
5002or the pack pragma), whichever is less. For structures, unions, and arrays,
5003the alignment-requirement is the largest alignment-requirement of its members.
5004Every object is allocated an offset so that:
5005
5006offset % alignment-requirement == 0
5007
5008@item Adjacent bit fields are packed into the same 1-, 2-, or 4-byte allocation
5009unit if the integral types are the same size and if the next bit field fits
5010into the current allocation unit without crossing the boundary imposed by the
5011common alignment requirements of the bit fields.
5012@end enumerate
5013
5014Handling of zero-length bitfields:
5015
5016MSVC interprets zero-length bitfields in the following ways:
5017
5018@enumerate
5019@item If a zero-length bitfield is inserted between two bitfields that would
5020normally be coalesced, the bitfields will not be coalesced.
5021
5022For example:
5023
5024@smallexample
5025struct
5026 @{
5027 unsigned long bf_1 : 12;
5028 unsigned long : 0;
5029 unsigned long bf_2 : 12;
5030 @} t1;
5031@end smallexample
5032
5033The size of @code{t1} would be 8 bytes with the zero-length bitfield. If the
5034zero-length bitfield were removed, @code{t1}'s size would be 4 bytes.
5035
5036@item If a zero-length bitfield is inserted after a bitfield, @code{foo}, and the
5037alignment of the zero-length bitfield is greater than the member that follows it,
5038@code{bar}, @code{bar} will be aligned as the type of the zero-length bitfield.
5039
5040For example:
5041
5042@smallexample
5043struct
5044 @{
5045 char foo : 4;
5046 short : 0;
5047 char bar;
5048 @} t2;
5049
5050struct
5051 @{
5052 char foo : 4;
5053 short : 0;
5054 double bar;
5055 @} t3;
5056@end smallexample
5057
5058For @code{t2}, @code{bar} will be placed at offset 2, rather than offset 1.
5059Accordingly, the size of @code{t2} will be 4. For @code{t3}, the zero-length
5060bitfield will not affect the alignment of @code{bar} or, as a result, the size
5061of the structure.
5062
5063Taking this into account, it is important to note the following:
5064
5065@enumerate
5066@item If a zero-length bitfield follows a normal bitfield, the type of the
5067zero-length bitfield may affect the alignment of the structure as whole. For
5068example, @code{t2} has a size of 4 bytes, since the zero-length bitfield follows a
5069normal bitfield, and is of type short.
5070
5071@item Even if a zero-length bitfield is not followed by a normal bitfield, it may
5072still affect the alignment of the structure:
5073
5074@smallexample
5075struct
5076 @{
5077 char foo : 6;
5078 long : 0;
5079 @} t4;
5080@end smallexample
5081
5082Here, @code{t4} will take up 4 bytes.
5083@end enumerate
5084
5085@item Zero-length bitfields following non-bitfield members are ignored:
5086
5087@smallexample
5088struct
5089 @{
5090 char foo;
5091 long : 0;
5092 char bar;
5093 @} t5;
5094@end smallexample
5095
5096Here, @code{t5} will take up 2 bytes.
5097@end enumerate
146ef39f 5098@end table
5099
c4e8a4d4 5100@subsection PowerPC Variable Attributes
5101
268b2718 5102Three attributes currently are defined for PowerPC configurations:
5103@code{altivec}, @code{ms_struct} and @code{gcc_struct}.
c4e8a4d4 5104
268b2718 5105For full documentation of the struct attributes please see the
e66bbea3 5106documentation in @ref{i386 Variable Attributes}.
268b2718 5107
5108For documentation of @code{altivec} attribute please see the
e66bbea3 5109documentation in @ref{PowerPC Type Attributes}.
c4e8a4d4 5110
644459d0 5111@subsection SPU Variable Attributes
5112
5113The SPU supports the @code{spu_vector} attribute for variables. For
e66bbea3 5114documentation of this attribute please see the documentation in
5115@ref{SPU Type Attributes}.
644459d0 5116
3c1df5aa 5117@subsection Xstormy16 Variable Attributes
5118
5119One attribute is currently defined for xstormy16 configurations:
e66bbea3 5120@code{below100}.
3c1df5aa 5121
5122@table @code
5123@item below100
5124@cindex @code{below100} attribute
5125
5126If a variable has the @code{below100} attribute (@code{BELOW100} is
5127allowed also), GCC will place the variable in the first 0x100 bytes of
5128memory and use special opcodes to access it. Such variables will be
5129placed in either the @code{.bss_below100} section or the
5130@code{.data_below100} section.
5131
5132@end table
5133
146ef39f 5134@node Type Attributes
5135@section Specifying Attributes of Types
5136@cindex attribute of types
5137@cindex type attributes
5138
5139The keyword @code{__attribute__} allows you to specify special
4a2849cb 5140attributes of @code{struct} and @code{union} types when you define
5141such types. This keyword is followed by an attribute specification
5142inside double parentheses. Seven attributes are currently defined for
5143types: @code{aligned}, @code{packed}, @code{transparent_union},
5144@code{unused}, @code{deprecated}, @code{visibility}, and
5145@code{may_alias}. Other attributes are defined for functions
5146(@pxref{Function Attributes}) and for variables (@pxref{Variable
5147Attributes}).
146ef39f 5148
5149You may also specify any one of these attributes with @samp{__}
5150preceding and following its keyword. This allows you to use these
5151attributes in header files without being concerned about a possible
5152macro of the same name. For example, you may use @code{__aligned__}
5153instead of @code{aligned}.
5154
881eb642 5155You may specify type attributes in an enum, struct or union type
5156declaration or definition, or for other types in a @code{typedef}
5157declaration.
146ef39f 5158
4a2849cb 5159For an enum, struct or union type, you may specify attributes either
5160between the enum, struct or union tag and the name of the type, or
5161just past the closing curly brace of the @emph{definition}. The
5162former syntax is preferred.
257b057a 5163
b31bfb3f 5164@xref{Attribute Syntax}, for details of the exact syntax for using
5165attributes.
5166
146ef39f 5167@table @code
5168@cindex @code{aligned} attribute
5169@item aligned (@var{alignment})
5170This attribute specifies a minimum alignment (in bytes) for variables
5171of the specified type. For example, the declarations:
5172
5173@smallexample
c8b8ebd3 5174struct S @{ short f[3]; @} __attribute__ ((aligned (8)));
5175typedef int more_aligned_int __attribute__ ((aligned (8)));
146ef39f 5176@end smallexample
5177
5178@noindent
7223a120 5179force the compiler to insure (as far as it can) that each variable whose
146ef39f 5180type is @code{struct S} or @code{more_aligned_int} will be allocated and
7800959d 5181aligned @emph{at least} on a 8-byte boundary. On a SPARC, having all
146ef39f 5182variables of type @code{struct S} aligned to 8-byte boundaries allows
5183the compiler to use the @code{ldd} and @code{std} (doubleword load and
5184store) instructions when copying one variable of type @code{struct S} to
5185another, thus improving run-time efficiency.
5186
5187Note that the alignment of any given @code{struct} or @code{union} type
78b1f616 5188is required by the ISO C standard to be at least a perfect multiple of
146ef39f 5189the lowest common multiple of the alignments of all of the members of
5190the @code{struct} or @code{union} in question. This means that you @emph{can}
5191effectively adjust the alignment of a @code{struct} or @code{union}
5192type by attaching an @code{aligned} attribute to any one of the members
5193of such a type, but the notation illustrated in the example above is a
5194more obvious, intuitive, and readable way to request the compiler to
5195adjust the alignment of an entire @code{struct} or @code{union} type.
5196
5197As in the preceding example, you can explicitly specify the alignment
5198(in bytes) that you wish the compiler to use for a given @code{struct}
5199or @code{union} type. Alternatively, you can leave out the alignment factor
5200and just ask the compiler to align a type to the maximum
5201useful alignment for the target machine you are compiling for. For
5202example, you could write:
5203
5204@smallexample
5205struct S @{ short f[3]; @} __attribute__ ((aligned));
5206@end smallexample
5207
5208Whenever you leave out the alignment factor in an @code{aligned}
5209attribute specification, the compiler automatically sets the alignment
5210for the type to the largest alignment which is ever used for any data
5211type on the target machine you are compiling for. Doing this can often
5212make copy operations more efficient, because the compiler can use
5213whatever instructions copy the biggest chunks of memory when performing
5214copies to or from the variables which have types that you have aligned
5215this way.
5216
5217In the example above, if the size of each @code{short} is 2 bytes, then
5218the size of the entire @code{struct S} type is 6 bytes. The smallest
5219power of two which is greater than or equal to that is 8, so the
5220compiler sets the alignment for the entire @code{struct S} type to 8
5221bytes.
5222
5223Note that although you can ask the compiler to select a time-efficient
5224alignment for a given type and then declare only individual stand-alone
5225objects of that type, the compiler's ability to select a time-efficient
5226alignment is primarily useful only when you plan to create arrays of
5227variables having the relevant (efficiently aligned) type. If you
5228declare or use arrays of variables of an efficiently-aligned type, then
5229it is likely that your program will also be doing pointer arithmetic (or
5230subscripting, which amounts to the same thing) on pointers to the
5231relevant type, and the code that the compiler generates for these
5232pointer arithmetic operations will often be more efficient for
5233efficiently-aligned types than for other types.
5234
5235The @code{aligned} attribute can only increase the alignment; but you
5236can decrease it by specifying @code{packed} as well. See below.
5237
5238Note that the effectiveness of @code{aligned} attributes may be limited
5239by inherent limitations in your linker. On many systems, the linker is
5240only able to arrange for variables to be aligned up to a certain maximum
5241alignment. (For some linkers, the maximum supported alignment may
5242be very very small.) If your linker is only able to align variables
5243up to a maximum of 8 byte alignment, then specifying @code{aligned(16)}
5244in an @code{__attribute__} will still only provide you with 8 byte
5245alignment. See your linker documentation for further information.
5246
5247@item packed
942ab15b 5248This attribute, attached to @code{struct} or @code{union} type
7c68c953 5249definition, specifies that each member (other than zero-width bitfields)
5250of the structure or union is placed to minimize the memory required. When
5251attached to an @code{enum} definition, it indicates that the smallest
5252integral type should be used.
146ef39f 5253
67791935 5254@opindex fshort-enums
146ef39f 5255Specifying this attribute for @code{struct} and @code{union} types is
5256equivalent to specifying the @code{packed} attribute on each of the
67791935 5257structure or union members. Specifying the @option{-fshort-enums}
146ef39f 5258flag on the line is equivalent to specifying the @code{packed}
5259attribute on all @code{enum} definitions.
5260
942ab15b 5261In the following example @code{struct my_packed_struct}'s members are
5262packed closely together, but the internal layout of its @code{s} member
01e3cadf 5263is not packed---to do that, @code{struct my_unpacked_struct} would need to
942ab15b 5264be packed too.
5265
5266@smallexample
5267struct my_unpacked_struct
5268 @{
5269 char c;
5270 int i;
5271 @};
5272
c3c702dd 5273struct __attribute__ ((__packed__)) my_packed_struct
942ab15b 5274 @{
5275 char c;
5276 int i;
5277 struct my_unpacked_struct s;
5278 @};
5279@end smallexample
5280
68576faf 5281You may only specify this attribute on the definition of an @code{enum},
942ab15b 5282@code{struct} or @code{union}, not on a @code{typedef} which does not
5283also define the enumerated type, structure or union.
146ef39f 5284
5285@item transparent_union
5286This attribute, attached to a @code{union} type definition, indicates
5287that any function parameter having that union type causes calls to that
5288function to be treated in a special way.
5289
5290First, the argument corresponding to a transparent union type can be of
5291any type in the union; no cast is required. Also, if the union contains
5292a pointer type, the corresponding argument can be a null pointer
5293constant or a void pointer expression; and if the union contains a void
5294pointer type, the corresponding argument can be any pointer expression.
5295If the union member type is a pointer, qualifiers like @code{const} on
5296the referenced type must be respected, just as with normal pointer
5297conversions.
5298
5299Second, the argument is passed to the function using the calling
ea1c20d0 5300conventions of the first member of the transparent union, not the calling
146ef39f 5301conventions of the union itself. All members of the union must have the
5302same machine representation; this is necessary for this argument passing
5303to work properly.
5304
5305Transparent unions are designed for library functions that have multiple
5306interfaces for compatibility reasons. For example, suppose the
5307@code{wait} function must accept either a value of type @code{int *} to
5308comply with Posix, or a value of type @code{union wait *} to comply with
5309the 4.1BSD interface. If @code{wait}'s parameter were @code{void *},
5310@code{wait} would accept both kinds of arguments, but it would also
5311accept any other pointer type and this would make argument type checking
5312less useful. Instead, @code{<sys/wait.h>} might define the interface
5313as follows:
5314
5315@smallexample
881eb642 5316typedef union __attribute__ ((__transparent_union__))
146ef39f 5317 @{
5318 int *__ip;
5319 union wait *__up;
881eb642 5320 @} wait_status_ptr_t;
146ef39f 5321
5322pid_t wait (wait_status_ptr_t);
5323@end smallexample
5324
5325This interface allows either @code{int *} or @code{union wait *}
5326arguments to be passed, using the @code{int *} calling convention.
5327The program can call @code{wait} with arguments of either type:
5328
a0ecd6b1 5329@smallexample
146ef39f 5330int w1 () @{ int w; return wait (&w); @}
5331int w2 () @{ union wait w; return wait (&w); @}
a0ecd6b1 5332@end smallexample
146ef39f 5333
5334With this interface, @code{wait}'s implementation might look like this:
5335
a0ecd6b1 5336@smallexample
146ef39f 5337pid_t wait (wait_status_ptr_t p)
5338@{
5339 return waitpid (-1, p.__ip, 0);
5340@}
a0ecd6b1 5341@end smallexample
7223a120 5342
5343@item unused
5344When attached to a type (including a @code{union} or a @code{struct}),
5345this attribute means that variables of that type are meant to appear
37744367 5346possibly unused. GCC will not produce a warning for any variables of
7223a120 5347that type, even if the variable appears to do nothing. This is often
5348the case with lock or thread classes, which are usually defined and then
5349not referenced, but contain constructors and destructors that have
ad87de1e 5350nontrivial bookkeeping functions.
7223a120 5351
88da234d 5352@item deprecated
45c4e798 5353@itemx deprecated (@var{msg})
88da234d 5354The @code{deprecated} attribute results in a warning if the type
5355is used anywhere in the source file. This is useful when identifying
5356types that are expected to be removed in a future version of a program.
5357If possible, the warning also includes the location of the declaration
5358of the deprecated type, to enable users to easily find further
5359information about why the type is deprecated, or what they should do
5360instead. Note that the warnings only occur for uses and then only
6831447b 5361if the type is being applied to an identifier that itself is not being
88da234d 5362declared as deprecated.
5363
5364@smallexample
5365typedef int T1 __attribute__ ((deprecated));
5366T1 x;
5367typedef T1 T2;
5368T2 y;
5369typedef T1 T3 __attribute__ ((deprecated));
5370T3 z __attribute__ ((deprecated));
5371@end smallexample
5372
5373results in a warning on line 2 and 3 but not lines 4, 5, or 6. No
5374warning is issued for line 4 because T2 is not explicitly
5375deprecated. Line 5 has no warning because T3 is explicitly
45c4e798 5376deprecated. Similarly for line 6. The optional msg
5377argument, which must be a string, will be printed in the warning if
5378present.
88da234d 5379
5380The @code{deprecated} attribute can also be used for functions and
5381variables (@pxref{Function Attributes}, @pxref{Variable Attributes}.)
5382
cb59f969 5383@item may_alias
f06537f2 5384Accesses through pointers to types with this attribute are not subject
5385to type-based alias analysis, but are instead assumed to be able to alias
5386any other type of objects. In the context of 6.5/7 an lvalue expression
5387dereferencing such a pointer is treated like having a character type.
5388See @option{-fstrict-aliasing} for more information on aliasing issues.
5389This extension exists to support some vector APIs, in which pointers to
5390one vector type are permitted to alias pointers to a different vector type.
5391
5392Note that an object of a type with this attribute does not have any
5393special semantics.
cb59f969 5394
5395Example of use:
5396
b724fad7 5397@smallexample
cb59f969 5398typedef short __attribute__((__may_alias__)) short_a;
5399
5400int
5401main (void)
5402@{
5403 int a = 0x12345678;
5404 short_a *b = (short_a *) &a;
5405
5406 b[1] = 0;
5407
5408 if (a == 0x12345678)
5409 abort();
5410
5411 exit(0);
5412@}
b724fad7 5413@end smallexample
cb59f969 5414
5415If you replaced @code{short_a} with @code{short} in the variable
5416declaration, the above program would abort when compiled with
5417@option{-fstrict-aliasing}, which is on by default at @option{-O2} or
5418above in recent GCC versions.
b09c5db2 5419
4a2849cb 5420@item visibility
4a2849cb 5421In C++, attribute visibility (@pxref{Function Attributes}) can also be
5422applied to class, struct, union and enum types. Unlike other type
5423attributes, the attribute must appear between the initial keyword and
5424the name of the type; it cannot appear after the body of the type.
5425
6a47600c 5426Note that the type visibility is applied to vague linkage entities
5427associated with the class (vtable, typeinfo node, etc.). In
5428particular, if a class is thrown as an exception in one shared object
5429and caught in another, the class must have default visibility.
5430Otherwise the two shared objects will be unable to use the same
5431typeinfo node and exception handling will break.
5432
e66bbea3 5433@end table
5434
669b0b52 5435To specify multiple attributes, separate them by commas within the
5436double parentheses: for example, @samp{__attribute__ ((aligned (16),
5437packed))}.
5438
a79b1d93 5439@subsection ARM Type Attributes
5440
5441On those ARM targets that support @code{dllimport} (such as Symbian
09c8496f 5442OS), you can use the @code{notshared} attribute to indicate that the
a79b1d93 5443virtual table and other similar data for a class should not be
b3d47662 5444exported from a DLL@. For example:
a79b1d93 5445
5446@smallexample
5447class __declspec(notshared) C @{
5448public:
09c8496f 5449 __declspec(dllimport) C();
a79b1d93 5450 virtual void f();
5451@}
5452
5453__declspec(dllexport)
5454C::C() @{@}
5455@end smallexample
5456
5457In this code, @code{C::C} is exported from the current DLL, but the
5458virtual table for @code{C} is not exported. (You can use
5459@code{__attribute__} instead of @code{__declspec} if you prefer, but
5460most Symbian OS code uses @code{__declspec}.)
5461
7c3116fb 5462@anchor{MeP Type Attributes}
5463@subsection MeP Type Attributes
5464
5465Many of the MeP variable attributes may be applied to types as well.
5466Specifically, the @code{based}, @code{tiny}, @code{near}, and
5467@code{far} attributes may be applied to either. The @code{io} and
5468@code{cb} attributes may not be applied to types.
5469
268b2718 5470@anchor{i386 Type Attributes}
b09c5db2 5471@subsection i386 Type Attributes
5472
5473Two attributes are currently defined for i386 configurations:
e66bbea3 5474@code{ms_struct} and @code{gcc_struct}.
5475
5476@table @code
b09c5db2 5477
5478@item ms_struct
5479@itemx gcc_struct
5480@cindex @code{ms_struct}
5481@cindex @code{gcc_struct}
5482
5483If @code{packed} is used on a structure, or if bit-fields are used
5484it may be that the Microsoft ABI packs them differently
5485than GCC would normally pack them. Particularly when moving packed
5486data between functions compiled with GCC and the native Microsoft compiler
5487(either via function call or as data in a file), it may be necessary to access
5488either format.
5489
c20b542c 5490Currently @option{-m[no-]ms-bitfields} is provided for the Microsoft Windows X86
b09c5db2 5491compilers to match the native Microsoft compiler.
146ef39f 5492@end table
5493
268b2718 5494@anchor{PowerPC Type Attributes}
5495@subsection PowerPC Type Attributes
5496
5497Three attributes currently are defined for PowerPC configurations:
5498@code{altivec}, @code{ms_struct} and @code{gcc_struct}.
5499
15b474a2 5500For full documentation of the @code{ms_struct} and @code{gcc_struct}
e66bbea3 5501attributes please see the documentation in @ref{i386 Type Attributes}.
268b2718 5502
5503The @code{altivec} attribute allows one to declare AltiVec vector data
5504types supported by the AltiVec Programming Interface Manual. The
5505attribute requires an argument to specify one of three vector types:
5506@code{vector__}, @code{pixel__} (always followed by unsigned short),
5507and @code{bool__} (always followed by unsigned).
5508
5509@smallexample
5510__attribute__((altivec(vector__)))
5511__attribute__((altivec(pixel__))) unsigned short
5512__attribute__((altivec(bool__))) unsigned
5513@end smallexample
5514
5515These attributes mainly are intended to support the @code{__vector},
5516@code{__pixel}, and @code{__bool} AltiVec keywords.
5517
644459d0 5518@anchor{SPU Type Attributes}
5519@subsection SPU Type Attributes
5520
5521The SPU supports the @code{spu_vector} attribute for types. This attribute
5522allows one to declare vector data types supported by the Sony/Toshiba/IBM SPU
5523Language Extensions Specification. It is intended to support the
5524@code{__vector} keyword.
5525
145f7c33 5526@node Alignment
5527@section Inquiring on Alignment of Types or Variables
5528@cindex alignment
5529@cindex type alignment
5530@cindex variable alignment
5531
5532The keyword @code{__alignof__} allows you to inquire about how an object
5533is aligned, or the minimum alignment usually required by a type. Its
5534syntax is just like @code{sizeof}.
5535
5536For example, if the target machine requires a @code{double} value to be
5537aligned on an 8-byte boundary, then @code{__alignof__ (double)} is 8.
5538This is true on many RISC machines. On more traditional machine
5539designs, @code{__alignof__ (double)} is 4 or even 2.
5540
5541Some machines never actually require alignment; they allow reference to any
5542data type even at an odd address. For these machines, @code{__alignof__}
5543reports the smallest alignment that GCC will give the data type, usually as
5544mandated by the target ABI.
5545
5546If the operand of @code{__alignof__} is an lvalue rather than a type,
5547its value is the required alignment for its type, taking into account
5548any minimum alignment specified with GCC's @code{__attribute__}
5549extension (@pxref{Variable Attributes}). For example, after this
5550declaration:
5551
5552@smallexample
5553struct foo @{ int x; char y; @} foo1;
5554@end smallexample
5555
5556@noindent
5557the value of @code{__alignof__ (foo1.y)} is 1, even though its actual
5558alignment is probably 2 or 4, the same as @code{__alignof__ (int)}.
5559
5560It is an error to ask for the alignment of an incomplete type.
5561
644459d0 5562
146ef39f 5563@node Inline
5564@section An Inline Function is As Fast As a Macro
5565@cindex inline functions
5566@cindex integrating function code
5567@cindex open coding
5568@cindex macros, inline alternative
5569
f9a907b0 5570By declaring a function inline, you can direct GCC to make
5571calls to that function faster. One way GCC can achieve this is to
146ef39f 5572integrate that function's code into the code for its callers. This
5573makes execution faster by eliminating the function-call overhead; in
f9a907b0 5574addition, if any of the actual argument values are constant, their
5575known values may permit simplifications at compile time so that not
5576all of the inline function's code needs to be included. The effect on
5577code size is less predictable; object code may be larger or smaller
5578with function inlining, depending on the particular case. You can
5579also direct GCC to try to integrate all ``simple enough'' functions
5580into their callers with the option @option{-finline-functions}.
5581
5582GCC implements three different semantics of declaring a function
11950bdd 5583inline. One is available with @option{-std=gnu89} or
5584@option{-fgnu89-inline} or when @code{gnu_inline} attribute is present
39012afb 5585on all inline declarations, another when
32074525 5586@option{-std=c99}, @option{-std=c11},
5587@option{-std=gnu99} or @option{-std=gnu11}
39012afb 5588(without @option{-fgnu89-inline}), and the third
11950bdd 5589is used when compiling C++.
3cfa0cc4 5590
146ef39f 5591To declare a function inline, use the @code{inline} keyword in its
5592declaration, like this:
5593
a0ecd6b1 5594@smallexample
f9a907b0 5595static inline int
146ef39f 5596inc (int *a)
5597@{
bfe513a4 5598 return (*a)++;
146ef39f 5599@}
a0ecd6b1 5600@end smallexample
146ef39f 5601
32f1f35b 5602If you are writing a header file to be included in ISO C90 programs, write
f9a907b0 5603@code{__inline__} instead of @code{inline}. @xref{Alternate Keywords}.
5a967f61 5604
f9a907b0 5605The three types of inlining behave similarly in two important cases:
5606when the @code{inline} keyword is used on a @code{static} function,
5607like the example above, and when a function is first declared without
5608using the @code{inline} keyword and then is defined with
5609@code{inline}, like this:
146ef39f 5610
f9a907b0 5611@smallexample
5612extern int inc (int *a);
5613inline int
5614inc (int *a)
5615@{
bfe513a4 5616 return (*a)++;
f9a907b0 5617@}
5618@end smallexample
146ef39f 5619
f9a907b0 5620In both of these common cases, the program behaves the same as if you
5621had not used the @code{inline} keyword, except for its speed.
146ef39f 5622
5623@cindex inline functions, omission of
67791935 5624@opindex fkeep-inline-functions
146ef39f 5625When a function is both inline and @code{static}, if all calls to the
5626function are integrated into the caller, and the function's address is
5627never used, then the function's own assembler code is never referenced.
37744367 5628In this case, GCC does not actually output assembler code for the
67791935 5629function, unless you specify the option @option{-fkeep-inline-functions}.
146ef39f 5630Some calls cannot be integrated for various reasons (in particular,
5631calls that precede the function's definition cannot be integrated, and
5632neither can recursive calls within the definition). If there is a
5633nonintegrated call, then the function is compiled to assembler code as
5634usual. The function must also be compiled as usual if the program
5635refers to its address, because that can't be inlined.
5636
f9a907b0 5637@opindex Winline
5638Note that certain usages in a function definition can make it unsuitable
5639for inline substitution. Among these usages are: use of varargs, use of
5640alloca, use of variable sized data types (@pxref{Variable Length}),
5641use of computed goto (@pxref{Labels as Values}), use of nonlocal goto,
5642and nested functions (@pxref{Nested Functions}). Using @option{-Winline}
5643will warn when a function marked @code{inline} could not be substituted,
5644and will give the reason for the failure.
5645
5646@cindex automatic @code{inline} for C++ member fns
5647@cindex @code{inline} automatic for C++ member fns
5648@cindex member fns, automatically @code{inline}
5649@cindex C++ member fns, automatically @code{inline}
5650@opindex fno-default-inline
5651As required by ISO C++, GCC considers member functions defined within
5652the body of a class to be marked inline even if they are
5653not explicitly declared with the @code{inline} keyword. You can
5654override this with @option{-fno-default-inline}; @pxref{C++ Dialect
5655Options,,Options Controlling C++ Dialect}.
5656
5657GCC does not inline any functions when not optimizing unless you specify
5658the @samp{always_inline} attribute for the function, like this:
5659
5660@smallexample
5661/* @r{Prototype.} */
5662inline void foo (const char) __attribute__((always_inline));
5663@end smallexample
5664
32f1f35b 5665The remainder of this section is specific to GNU C90 inlining.
f9a907b0 5666
146ef39f 5667@cindex non-static inline function
5668When an inline function is not @code{static}, then the compiler must assume
5669that there may be calls from other source files; since a global symbol can
5670be defined only once in any program, the function must not be defined in
5671the other source files, so the calls therein cannot be integrated.
5672Therefore, a non-@code{static} inline function is always compiled on its
5673own in the usual fashion.
5674
5675If you specify both @code{inline} and @code{extern} in the function
5676definition, then the definition is used only for inlining. In no case
5677is the function compiled on its own, not even if you refer to its
5678address explicitly. Such an address becomes an external reference, as
5679if you had only declared the function, and had not defined it.
5680
5681This combination of @code{inline} and @code{extern} has almost the
5682effect of a macro. The way to use it is to put a function definition in
5683a header file with these keywords, and put another copy of the
5684definition (lacking @code{inline} and @code{extern}) in a library file.
5685The definition in the header file will cause most calls to the function
5686to be inlined. If any uses of the function remain, they will refer to
5687the single copy in the library.
5688
e83c4d0f 5689@node Volatiles
5690@section When is a Volatile Object Accessed?
5691@cindex accessing volatiles
5692@cindex volatile read
5693@cindex volatile write
5694@cindex volatile access
5695
5696C has the concept of volatile objects. These are normally accessed by
5697pointers and used for accessing hardware or inter-thread
b59688ee 5698communication. The standard encourages compilers to refrain from
e83c4d0f 5699optimizations concerning accesses to volatile objects, but leaves it
5700implementation defined as to what constitutes a volatile access. The
5701minimum requirement is that at a sequence point all previous accesses
5702to volatile objects have stabilized and no subsequent accesses have
5703occurred. Thus an implementation is free to reorder and combine
5704volatile accesses which occur between sequence points, but cannot do
b59688ee 5705so for accesses across a sequence point. The use of volatile does
e83c4d0f 5706not allow you to violate the restriction on updating objects multiple
5707times between two sequence points.
5708
5709Accesses to non-volatile objects are not ordered with respect to
5710volatile accesses. You cannot use a volatile object as a memory
5711barrier to order a sequence of writes to non-volatile memory. For
5712instance:
5713
5714@smallexample
5715int *ptr = @var{something};
5716volatile int vobj;
5717*ptr = @var{something};
5718vobj = 1;
5719@end smallexample
5720
5721Unless @var{*ptr} and @var{vobj} can be aliased, it is not guaranteed
5722that the write to @var{*ptr} will have occurred by the time the update
5723of @var{vobj} has happened. If you need this guarantee, you must use
5724a stronger memory barrier such as:
5725
5726@smallexample
5727int *ptr = @var{something};
5728volatile int vobj;
5729*ptr = @var{something};
5730asm volatile ("" : : : "memory");
5731vobj = 1;
5732@end smallexample
5733
b59688ee 5734A scalar volatile object is read when it is accessed in a void context:
e83c4d0f 5735
5736@smallexample
5737volatile int *src = @var{somevalue};
5738*src;
5739@end smallexample
5740
5741Such expressions are rvalues, and GCC implements this as a
5742read of the volatile object being pointed to.
5743
5744Assignments are also expressions and have an rvalue. However when
5745assigning to a scalar volatile, the volatile object is not reread,
5746regardless of whether the assignment expression's rvalue is used or
5747not. If the assignment's rvalue is used, the value is that assigned
5748to the volatile object. For instance, there is no read of @var{vobj}
5749in all the following cases:
5750
5751@smallexample
5752int obj;
5753volatile int vobj;
5754vobj = @var{something};
5755obj = vobj = @var{something};
5756obj ? vobj = @var{onething} : vobj = @var{anotherthing};
5757obj = (@var{something}, vobj = @var{anotherthing});
5758@end smallexample
5759
5760If you need to read the volatile object after an assignment has
5761occurred, you must use a separate expression with an intervening
5762sequence point.
5763
5764As bitfields are not individually addressable, volatile bitfields may
5765be implicitly read when written to, or when adjacent bitfields are
5766accessed. Bitfield operations may be optimized such that adjacent
5767bitfields are only partially accessed, if they straddle a storage unit
5768boundary. For these reasons it is unwise to use volatile bitfields to
5769access hardware.
5770
146ef39f 5771@node Extended Asm
5772@section Assembler Instructions with C Expression Operands
5773@cindex extended @code{asm}
5774@cindex @code{asm} expressions
5775@cindex assembler instructions
5776@cindex registers
5777
220345e0 5778In an assembler instruction using @code{asm}, you can specify the
5779operands of the instruction using C expressions. This means you need not
5780guess which registers or memory locations will contain the data you want
146ef39f 5781to use.
5782
220345e0 5783You must specify an assembler instruction template much like what
5784appears in a machine description, plus an operand constraint string for
5785each operand.
146ef39f 5786
5787For example, here is how to use the 68881's @code{fsinx} instruction:
5788
a0ecd6b1 5789@smallexample
146ef39f 5790asm ("fsinx %1,%0" : "=f" (result) : "f" (angle));
a0ecd6b1 5791@end smallexample
146ef39f 5792
5793@noindent
5794Here @code{angle} is the C expression for the input operand while
5795@code{result} is that of the output operand. Each has @samp{"f"} as its
220345e0 5796operand constraint, saying that a floating point register is required.
5797The @samp{=} in @samp{=f} indicates that the operand is an output; all
5798output operands' constraints must use @samp{=}. The constraints use the
5799same language used in the machine description (@pxref{Constraints}).
5800
5801Each operand is described by an operand-constraint string followed by
5802the C expression in parentheses. A colon separates the assembler
5803template from the first output operand and another separates the last
5804output operand from the first input, if any. Commas separate the
2c7f203c 5805operands within each group. The total number of operands is currently
5806limited to 30; this limitation may be lifted in some future version of
b3d47662 5807GCC@.
220345e0 5808
5809If there are no output operands but there are input operands, you must
5810place two consecutive colons surrounding the place where the output
146ef39f 5811operands would go.
5812
2c7f203c 5813As of GCC version 3.1, it is also possible to specify input and output
5814operands using symbolic names which can be referenced within the
5815assembler code. These names are specified inside square brackets
5816preceding the constraint string, and can be referenced inside the
5817assembler code using @code{%[@var{name}]} instead of a percentage sign
5818followed by the operand number. Using named operands the above example
5819could look like:
5820
a0ecd6b1 5821@smallexample
2c7f203c 5822asm ("fsinx %[angle],%[output]"
5823 : [output] "=f" (result)
5824 : [angle] "f" (angle));
a0ecd6b1 5825@end smallexample
2c7f203c 5826
5827@noindent
5828Note that the symbolic operand names have no relation whatsoever to
5829other C identifiers. You may use any name you like, even those of
ea1c20d0 5830existing C symbols, but you must ensure that no two operands within the same
2c7f203c 5831assembler construct use the same symbolic name.
5832
146ef39f 5833Output operand expressions must be lvalues; the compiler can check this.
220345e0 5834The input operands need not be lvalues. The compiler cannot check
5835whether the operands have data types that are reasonable for the
5836instruction being executed. It does not parse the assembler instruction
5837template and does not know what it means or even whether it is valid
5838assembler input. The extended @code{asm} feature is most often used for
5839machine instructions the compiler itself does not know exist. If
5840the output expression cannot be directly addressed (for example, it is a
37744367 5841bit-field), your constraint must allow a register. In that case, GCC
220345e0 5842will use the register as the output of the @code{asm}, and then store
5843that register into the output.
5844
37744367 5845The ordinary output operands must be write-only; GCC will assume that
220345e0 5846the values in these operands before the instruction are dead and need
5847not be generated. Extended asm supports input-output or read-write
5848operands. Use the constraint character @samp{+} to indicate such an
7cb2ace4 5849operand and list it with the output operands. You should only use
5850read-write operands when the constraints for the operand (or the
5851operand in which only some of the bits are to be changed) allow a
5852register.
5853
5854You may, as an alternative, logically split its function into two
5855separate operands, one input operand and one write-only output
5856operand. The connection between them is expressed by constraints
5857which say they need to be in the same location when the instruction
5858executes. You can use the same C expression for both operands, or
5859different expressions. For example, here we write the (fictitious)
5860@samp{combine} instruction with @code{bar} as its read-only source
5861operand and @code{foo} as its read-write destination:
146ef39f 5862
a0ecd6b1 5863@smallexample
146ef39f 5864asm ("combine %2,%0" : "=r" (foo) : "0" (foo), "g" (bar));
a0ecd6b1 5865@end smallexample
146ef39f 5866
5867@noindent
220345e0 5868The constraint @samp{"0"} for operand 1 says that it must occupy the
2c7f203c 5869same location as operand 0. A number in constraint is allowed only in
5870an input operand and it must refer to an output operand.
146ef39f 5871
2c7f203c 5872Only a number in the constraint can guarantee that one operand will be in
220345e0 5873the same place as another. The mere fact that @code{foo} is the value
5874of both operands is not enough to guarantee that they will be in the
5875same place in the generated assembler code. The following would not
5876work reliably:
146ef39f 5877
a0ecd6b1 5878@smallexample
146ef39f 5879asm ("combine %2,%0" : "=r" (foo) : "r" (foo), "g" (bar));
a0ecd6b1 5880@end smallexample
146ef39f 5881
5882Various optimizations or reloading could cause operands 0 and 1 to be in
37744367 5883different registers; GCC knows no reason not to do so. For example, the
146ef39f 5884compiler might find a copy of the value of @code{foo} in one register and
5885use it for operand 1, but generate the output operand 0 in a different
5886register (copying it afterward to @code{foo}'s own address). Of course,
5887since the register for operand 1 is not even mentioned in the assembler
37744367 5888code, the result will not work, but GCC can't tell that.
146ef39f 5889
2c7f203c 5890As of GCC version 3.1, one may write @code{[@var{name}]} instead of
5891the operand number for a matching constraint. For example:
5892
a0ecd6b1 5893@smallexample
2c7f203c 5894asm ("cmoveq %1,%2,%[result]"
5895 : [result] "=r"(result)
5896 : "r" (test), "r"(new), "[result]"(old));
a0ecd6b1 5897@end smallexample
2c7f203c 5898
1358f000 5899Sometimes you need to make an @code{asm} operand be a specific register,
5900but there's no matching constraint letter for that register @emph{by
5901itself}. To force the operand into that register, use a local variable
5902for the operand and specify the register in the variable declaration.
5903@xref{Explicit Reg Vars}. Then for the @code{asm} operand, use any
5904register constraint letter that matches the register:
5905
5906@smallexample
5907register int *p1 asm ("r0") = @dots{};
5908register int *p2 asm ("r1") = @dots{};
5909register int *result asm ("r0");
5910asm ("sysint" : "=r" (result) : "0" (p1), "r" (p2));
5911@end smallexample
5912
2de78c9f 5913@anchor{Example of asm with clobbered asm reg}
5914In the above example, beware that a register that is call-clobbered by
5915the target ABI will be overwritten by any function call in the
5916assignment, including library calls for arithmetic operators.
2687629f 5917Also a register may be clobbered when generating some operations,
5918like variable shift, memory copy or memory move on x86.
2de78c9f 5919Assuming it is a call-clobbered register, this may happen to @code{r0}
5920above by the assignment to @code{p2}. If you have to use such a
5921register, use temporary variables for expressions between the register
5922assignment and use:
5923
5924@smallexample
5925int t1 = @dots{};
5926register int *p1 asm ("r0") = @dots{};
5927register int *p2 asm ("r1") = t1;
5928register int *result asm ("r0");
5929asm ("sysint" : "=r" (result) : "0" (p1), "r" (p2));
5930@end smallexample
5931
220345e0 5932Some instructions clobber specific hard registers. To describe this,
5933write a third colon after the input operands, followed by the names of
5934the clobbered hard registers (given as strings). Here is a realistic
5935example for the VAX:
146ef39f 5936
a0ecd6b1 5937@smallexample
146ef39f 5938asm volatile ("movc3 %0,%1,%2"
12e2a142 5939 : /* @r{no outputs} */
146ef39f 5940 : "g" (from), "g" (to), "g" (count)
5941 : "r0", "r1", "r2", "r3", "r4", "r5");
a0ecd6b1 5942@end smallexample
146ef39f 5943
7014838c 5944You may not write a clobber description in a way that overlaps with an
5945input or output operand. For example, you may not have an operand
5946describing a register class with one member if you mention that register
3d52d305 5947in the clobber list. Variables declared to live in specific registers
5948(@pxref{Explicit Reg Vars}), and used as asm input or output operands must
5949have no part mentioned in the clobber description.
5950There is no way for you to specify that an input
7014838c 5951operand is modified without also specifying it as an output
5952operand. Note that if all the output operands you specify are for this
5953purpose (and hence unused), you will then also need to specify
5954@code{volatile} for the @code{asm} construct, as described below, to
37744367 5955prevent GCC from deleting the @code{asm} statement as unused.
abd6a9dd 5956
146ef39f 5957If you refer to a particular hardware register from the assembler code,
220345e0 5958you will probably have to list the register after the third colon to
5959tell the compiler the register's value is modified. In some assemblers,
5960the register names begin with @samp{%}; to produce one @samp{%} in the
5961assembler code, you must write @samp{%%} in the input.
5962
5963If your assembler instruction can alter the condition code register, add
37744367 5964@samp{cc} to the list of clobbered registers. GCC on some machines
220345e0 5965represents the condition codes as a specific hardware register;
5966@samp{cc} serves to name this register. On other machines, the
5967condition code is handled differently, and specifying @samp{cc} has no
5968effect. But it is valid no matter what the machine.
146ef39f 5969
f899e75e 5970If your assembler instructions access memory in an unpredictable
220345e0 5971fashion, add @samp{memory} to the list of clobbered registers. This
f899e75e 5972will cause GCC to not keep memory values cached in registers across the
5973assembler instruction and not optimize stores or loads to that memory.
5974You will also want to add the @code{volatile} keyword if the memory
5975affected is not listed in the inputs or outputs of the @code{asm}, as
5976the @samp{memory} clobber does not count as a side-effect of the
5977@code{asm}. If you know how large the accessed memory is, you can add
5978it as input or output but if this is not known, you should add
5979@samp{memory}. As an example, if you access ten bytes of a string, you
5980can use a memory input like:
5981
91acd86c 5982@smallexample
f899e75e 5983@{"m"( (@{ struct @{ char x[10]; @} *p = (void *)ptr ; *p; @}) )@}.
91acd86c 5984@end smallexample
f899e75e 5985
5986Note that in the following example the memory input is necessary,
5987otherwise GCC might optimize the store to @code{x} away:
91acd86c 5988@smallexample
f899e75e 5989int foo ()
5990@{
5991 int x = 42;
5992 int *y = &x;
5993 int result;
5994 asm ("magic stuff accessing an 'int' pointed to by '%1'"
5995 "=&d" (r) : "a" (y), "m" (*y));
09c8496f 5996 return result;
f899e75e 5997@}
91acd86c 5998@end smallexample
146ef39f 5999
220345e0 6000You can put multiple assembler instructions together in a single
4cd470f2 6001@code{asm} template, separated by the characters normally used in assembly
6002code for the system. A combination that works in most places is a newline
6003to break the line, plus a tab character to move to the instruction field
6004(written as @samp{\n\t}). Sometimes semicolons can be used, if the
6005assembler allows semicolons as a line-breaking character. Note that some
6006assembler dialects use semicolons to start a comment.
6007The input operands are guaranteed not to use any of the clobbered
220345e0 6008registers, and neither will the output operands' addresses, so you can
6009read and write the clobbered registers as many times as you like. Here
6010is an example of multiple instructions in a template; it assumes the
6011subroutine @code{_foo} accepts arguments in registers 9 and 10:
146ef39f 6012
a0ecd6b1 6013@smallexample
4cd470f2 6014asm ("movl %0,r9\n\tmovl %1,r10\n\tcall _foo"
146ef39f 6015 : /* no outputs */
6016 : "g" (from), "g" (to)
6017 : "r9", "r10");
a0ecd6b1 6018@end smallexample
146ef39f 6019
37744367 6020Unless an output operand has the @samp{&} constraint modifier, GCC
220345e0 6021may allocate it in the same register as an unrelated input operand, on
6022the assumption the inputs are consumed before the outputs are produced.
146ef39f 6023This assumption may be false if the assembler code actually consists of
6024more than one instruction. In such a case, use @samp{&} for each output
220345e0 6025operand that may not overlap an input. @xref{Modifiers}.
146ef39f 6026
220345e0 6027If you want to test the condition code produced by an assembler
6028instruction, you must include a branch and a label in the @code{asm}
6029construct, as follows:
146ef39f 6030
a0ecd6b1 6031@smallexample
4cd470f2 6032asm ("clr %0\n\tfrob %1\n\tbeq 0f\n\tmov #1,%0\n0:"
146ef39f 6033 : "g" (result)
6034 : "g" (input));
a0ecd6b1 6035@end smallexample
146ef39f 6036
6037@noindent
6038This assumes your assembler supports local labels, as the GNU assembler
6039and most Unix assemblers do.
6040
6041Speaking of labels, jumps from one @code{asm} to another are not
220345e0 6042supported. The compiler's optimizers do not know about these jumps, and
6043therefore they cannot take account of them when deciding how to
78f55ca8 6044optimize. @xref{Extended asm with goto}.
146ef39f 6045
6046@cindex macros containing @code{asm}
6047Usually the most convenient way to use these @code{asm} instructions is to
6048encapsulate them in macros that look like functions. For example,
6049
a0ecd6b1 6050@smallexample
146ef39f 6051#define sin(x) \
6052(@{ double __value, __arg = (x); \
6053 asm ("fsinx %1,%0": "=f" (__value): "f" (__arg)); \
6054 __value; @})
a0ecd6b1 6055@end smallexample
146ef39f 6056
6057@noindent
6058Here the variable @code{__arg} is used to make sure that the instruction
6059operates on a proper @code{double} value, and to accept only those
6060arguments @code{x} which can convert automatically to a @code{double}.
6061
220345e0 6062Another way to make sure the instruction operates on the correct data
6063type is to use a cast in the @code{asm}. This is different from using a
146ef39f 6064variable @code{__arg} in that it converts more different types. For
6065example, if the desired type were @code{int}, casting the argument to
6066@code{int} would accept a pointer with no complaint, while assigning the
6067argument to an @code{int} variable named @code{__arg} would warn about
6068using a pointer unless the caller explicitly casts it.
6069
37744367 6070If an @code{asm} has output operands, GCC assumes for optimization
220345e0 6071purposes the instruction has no side effects except to change the output
6072operands. This does not mean instructions with a side effect cannot be
6073used, but you must be careful, because the compiler may eliminate them
6074if the output operands aren't used, or move them out of loops, or
6075replace two with one if they constitute a common subexpression. Also,
6076if your instruction does have a side effect on a variable that otherwise
6077appears not to change, the old value of the variable may be reused later
6078if it happens to be found in a register.
146ef39f 6079
3eb4e85f 6080You can prevent an @code{asm} instruction from being deleted
6081by writing the keyword @code{volatile} after
146ef39f 6082the @code{asm}. For example:
6083
a0ecd6b1 6084@smallexample
d90db7dc 6085#define get_and_set_priority(new) \
6086(@{ int __old; \
6087 asm volatile ("get_and_set_priority %0, %1" \
6088 : "=g" (__old) : "g" (new)); \
220345e0 6089 __old; @})
a0ecd6b1 6090@end smallexample
146ef39f 6091
6092@noindent
90f960d5 6093The @code{volatile} keyword indicates that the instruction has
6094important side-effects. GCC will not delete a volatile @code{asm} if
6095it is reachable. (The instruction can still be deleted if GCC can
6096prove that control-flow will never reach the location of the
09c8496f 6097instruction.) Note that even a volatile @code{asm} instruction
3eb4e85f 6098can be moved relative to other code, including across jump
09c8496f 6099instructions. For example, on many targets there is a system
6100register which can be set to control the rounding mode of
3eb4e85f 6101floating point operations. You might try
6102setting it with a volatile @code{asm}, like this PowerPC example:
90f960d5 6103
a0ecd6b1 6104@smallexample
3eb4e85f 6105 asm volatile("mtfsf 255,%0" : : "f" (fpenv));
6106 sum = x + y;
a0ecd6b1 6107@end smallexample
90f960d5 6108
77f71523 6109@noindent
3eb4e85f 6110This will not work reliably, as the compiler may move the addition back
6111before the volatile @code{asm}. To make it work you need to add an
6112artificial dependency to the @code{asm} referencing a variable in the code
6113you don't want moved, for example:
6114
6115@smallexample
6116 asm volatile ("mtfsf 255,%1" : "=X"(sum): "f"(fpenv));
6117 sum = x + y;
6118@end smallexample
6119
6120Similarly, you can't expect a
6121sequence of volatile @code{asm} instructions to remain perfectly
6122consecutive. If you want consecutive output, use a single @code{asm}.
6123Also, GCC will perform some optimizations across a volatile @code{asm}
6124instruction; GCC does not ``forget everything'' when it encounters
6125a volatile @code{asm} instruction the way some other compilers do.
6126
6127An @code{asm} instruction without any output operands will be treated
6128identically to a volatile @code{asm} instruction.
146ef39f 6129
6130It is a natural idea to look for a way to give access to the condition
6131code left by the assembler instruction. However, when we attempted to
6132implement this, we found no way to make it work reliably. The problem
6133is that output operands might need reloading, which would result in
6134additional following ``store'' instructions. On most machines, these
6135instructions would alter the condition code before there was time to
6136test it. This problem doesn't arise for ordinary ``test'' and
6137``compare'' instructions because they don't have any output operands.
6138
356ed71f 6139For reasons similar to those described above, it is not possible to give
6140an assembler instruction access to the condition code left by previous
6141instructions.
6142
78f55ca8 6143@anchor{Extended asm with goto}
6144As of GCC version 4.5, @code{asm goto} may be used to have the assembly
6145jump to one or more C labels. In this form, a fifth section after the
6146clobber list contains a list of all C labels to which the assembly may jump.
6147Each label operand is implicitly self-named. The @code{asm} is also assumed
6148to fall through to the next statement.
6149
6150This form of @code{asm} is restricted to not have outputs. This is due
6151to a internal restriction in the compiler that control transfer instructions
6152cannot have outputs. This restriction on @code{asm goto} may be lifted
6153in some future version of the compiler. In the mean time, @code{asm goto}
6154may include a memory clobber, and so leave outputs in memory.
6155
6156@smallexample
6157int frob(int x)
6158@{
6159 int y;
6160 asm goto ("frob %%r5, %1; jc %l[error]; mov (%2), %%r5"
6161 : : "r"(x), "r"(&y) : "r5", "memory" : error);
6162 return y;
6163 error:
6164 return -1;
6165@}
6166@end smallexample
6167
6168In this (inefficient) example, the @code{frob} instruction sets the
6169carry bit to indicate an error. The @code{jc} instruction detects
15b474a2 6170this and branches to the @code{error} label. Finally, the output
78f55ca8 6171of the @code{frob} instruction (@code{%r5}) is stored into the memory
6172for variable @code{y}, which is later read by the @code{return} statement.
6173
6174@smallexample
6175void doit(void)
6176@{
6177 int i = 0;
6178 asm goto ("mfsr %%r1, 123; jmp %%r1;"
6179 ".pushsection doit_table;"
910faa40 6180 ".long %l0, %l1, %l2, %l3;"
6181 ".popsection"
6182 : : : "r1" : label1, label2, label3, label4);
78f55ca8 6183 __builtin_unreachable ();
6184
6185 label1:
6186 f1();
6187 return;
6188 label2:
6189 f2();
6190 return;
6191 label3:
6192 i = 1;
6193 label4:
6194 f3(i);
6195@}
6196@end smallexample
6197
6198In this (also inefficient) example, the @code{mfsr} instruction reads
6199an address from some out-of-band machine register, and the following
6200@code{jmp} instruction branches to that address. The address read by
6201the @code{mfsr} instruction is assumed to have been previously set via
6202some application-specific mechanism to be one of the four values stored
6203in the @code{doit_table} section. Finally, the @code{asm} is followed
6204by a call to @code{__builtin_unreachable} to indicate that the @code{asm}
6205does not in fact fall through.
6206
6207@smallexample
6208#define TRACE1(NUM) \
6209 do @{ \
6210 asm goto ("0: nop;" \
6211 ".pushsection trace_table;" \
6212 ".long 0b, %l0;" \
6213 ".popsection" \
6214 : : : : trace#NUM); \
6215 if (0) @{ trace#NUM: trace(); @} \
6216 @} while (0)
6217#define TRACE TRACE1(__COUNTER__)
6218@end smallexample
6219
6220In this example (which in fact inspired the @code{asm goto} feature)
6221we want on rare occasions to call the @code{trace} function; on other
6222occasions we'd like to keep the overhead to the absolute minimum.
6223The normal code path consists of a single @code{nop} instruction.
6224However, we record the address of this @code{nop} together with the
6225address of a label that calls the @code{trace} function. This allows
15b474a2 6226the @code{nop} instruction to be patched at runtime to be an
78f55ca8 6227unconditional branch to the stored label. It is assumed that an
6228optimizing compiler will move the labeled block out of line, to
6229optimize the fall through path from the @code{asm}.
6230
78b1f616 6231If you are writing a header file that should be includable in ISO C
146ef39f 6232programs, write @code{__asm__} instead of @code{asm}. @xref{Alternate
6233Keywords}.
6234
9214c2cb 6235@subsection Size of an @code{asm}
6236
6237Some targets require that GCC track the size of each instruction used in
6238order to generate correct code. Because the final length of an
6239@code{asm} is only known by the assembler, GCC must make an estimate as
6240to how big it will be. The estimate is formed by counting the number of
6241statements in the pattern of the @code{asm} and multiplying that by the
6242length of the longest instruction on that processor. Statements in the
6243@code{asm} are identified by newline characters and whatever statement
6244separator characters are supported by the assembler; on most processors
6245this is the `@code{;}' character.
6246
6247Normally, GCC's estimate is perfectly adequate to ensure that correct
6248code is generated, but it is possible to confuse the compiler if you use
6249pseudo instructions or assembler macros that expand into multiple real
6250instructions or if you use assembler directives that expand to more
6251space in the object file than would be needed for a single instruction.
6252If this happens then the assembler will produce a diagnostic saying that
6253a label is unreachable.
6254
53ae8f59 6255@subsection i386 floating point asm operands
6256
6257There are several rules on the usage of stack-like regs in
6258asm_operands insns. These rules apply only to the operands that are
6259stack-like regs:
6260
6261@enumerate
6262@item
6263Given a set of input regs that die in an asm_operands, it is
6264necessary to know which are implicitly popped by the asm, and
6265which must be explicitly popped by gcc.
6266
6267An input reg that is implicitly popped by the asm must be
6268explicitly clobbered, unless it is constrained to match an
6269output operand.
6270
6271@item
6272For any input reg that is implicitly popped by an asm, it is
6273necessary to know how to adjust the stack to compensate for the pop.
6274If any non-popped input is closer to the top of the reg-stack than
6275the implicitly popped reg, it would not be possible to know what the
67791935 6276stack looked like---it's not clear how the rest of the stack ``slides
53ae8f59 6277up''.
6278
6279All implicitly popped input regs must be closer to the top of
6280the reg-stack than any input that is not implicitly popped.
6281
6282It is possible that if an input dies in an insn, reload might
6283use the input reg for an output reload. Consider this example:
6284
a0ecd6b1 6285@smallexample
53ae8f59 6286asm ("foo" : "=t" (a) : "f" (b));
a0ecd6b1 6287@end smallexample
53ae8f59 6288
6289This asm says that input B is not popped by the asm, and that
8e5fcce7 6290the asm pushes a result onto the reg-stack, i.e., the stack is one
53ae8f59 6291deeper after the asm than it was before. But, it is possible that
6292reload will think that it can use the same reg for both the input and
6293the output, if input B dies in this insn.
6294
6295If any input operand uses the @code{f} constraint, all output reg
6296constraints must use the @code{&} earlyclobber.
6297
6298The asm above would be written as
6299
a0ecd6b1 6300@smallexample
53ae8f59 6301asm ("foo" : "=&t" (a) : "f" (b));
a0ecd6b1 6302@end smallexample
53ae8f59 6303
6304@item
6305Some operands need to be in particular places on the stack. All
67791935 6306output operands fall in this category---there is no other way to
53ae8f59 6307know which regs the outputs appear in unless the user indicates
6308this in the constraints.
6309
6310Output operands must specifically indicate which reg an output
6311appears in after an asm. @code{=f} is not allowed: the operand
6312constraints must select a class with a single reg.
6313
6314@item
6315Output operands may not be ``inserted'' between existing stack regs.
6316Since no 387 opcode uses a read/write operand, all output operands
6317are dead before the asm_operands, and are pushed by the asm_operands.
6318It makes no sense to push anywhere but the top of the reg-stack.
6319
6320Output operands must start at the top of the reg-stack: output
6321operands may not ``skip'' a reg.
6322
6323@item
6324Some asm statements may need extra stack space for internal
6325calculations. This can be guaranteed by clobbering stack registers
6326unrelated to the inputs and outputs.
6327
6328@end enumerate
6329
6330Here are a couple of reasonable asms to want to write. This asm
6331takes one input, which is internally popped, and produces two outputs.
6332
a0ecd6b1 6333@smallexample
53ae8f59 6334asm ("fsincos" : "=t" (cos), "=u" (sin) : "0" (inp));
a0ecd6b1 6335@end smallexample
53ae8f59 6336
6337This asm takes two inputs, which are popped by the @code{fyl2xp1} opcode,
6338and replaces them with one output. The user must code the @code{st(1)}
6339clobber for reg-stack.c to know that @code{fyl2xp1} pops both inputs.
6340
a0ecd6b1 6341@smallexample
53ae8f59 6342asm ("fyl2xp1" : "=t" (result) : "0" (x), "u" (y) : "st(1)");
a0ecd6b1 6343@end smallexample
53ae8f59 6344
146ef39f 6345@include md.texi
146ef39f 6346
6347@node Asm Labels
6348@section Controlling Names Used in Assembler Code
6349@cindex assembler names for identifiers
6350@cindex names used in assembler code
6351@cindex identifiers, names in assembler code
6352
6353You can specify the name to be used in the assembler code for a C
6354function or variable by writing the @code{asm} (or @code{__asm__})
6355keyword after the declarator as follows:
6356
a0ecd6b1 6357@smallexample
146ef39f 6358int foo asm ("myfoo") = 2;
a0ecd6b1 6359@end smallexample
146ef39f 6360
6361@noindent
6362This specifies that the name to be used for the variable @code{foo} in
6363the assembler code should be @samp{myfoo} rather than the usual
6364@samp{_foo}.
6365
6366On systems where an underscore is normally prepended to the name of a C
6367function or variable, this feature allows you to define names for the
6368linker that do not start with an underscore.
6369
cd5abf58 6370It does not make sense to use this feature with a non-static local
6371variable since such variables do not have assembler names. If you are
6372trying to put the variable in a particular register, see @ref{Explicit
6373Reg Vars}. GCC presently accepts such code with a warning, but will
6374probably be changed to issue an error, rather than a warning, in the
6375future.
6376
146ef39f 6377You cannot use @code{asm} in this way in a function @emph{definition}; but
6378you can get the same effect by writing a declaration for the function
6379before its definition and putting @code{asm} there, like this:
6380
a0ecd6b1 6381@smallexample
146ef39f 6382extern func () asm ("FUNC");
6383
6384func (x, y)
6385 int x, y;
4ae74ddd 6386/* @r{@dots{}} */
a0ecd6b1 6387@end smallexample
146ef39f 6388
6389It is up to you to make sure that the assembler names you choose do not
6390conflict with any other assembler symbols. Also, you must not use a
37744367 6391register name; that would produce completely invalid assembler code. GCC
6392does not as yet have the ability to store static variables in registers.
146ef39f 6393Perhaps that will be added.
6394
6395@node Explicit Reg Vars
6396@section Variables in Specified Registers
6397@cindex explicit register variables
6398@cindex variables in specified registers
6399@cindex specified registers
6400@cindex registers, global allocation
6401
6402GNU C allows you to put a few global variables into specified hardware
6403registers. You can also specify the register in which an ordinary
6404register variable should be allocated.
6405
6406@itemize @bullet
6407@item
6408Global register variables reserve registers throughout the program.
6409This may be useful in programs such as programming language
6410interpreters which have a couple of global variables that are accessed
6411very often.
6412
6413@item
6414Local register variables in specific registers do not reserve the
1358f000 6415registers, except at the point where they are used as input or output
6416operands in an @code{asm} statement and the @code{asm} statement itself is
6417not deleted. The compiler's data flow analysis is capable of determining
146ef39f 6418where the specified registers contain live values, and where they are
dcb61f7f 6419available for other uses. Stores into local register variables may be deleted
d2763590 6420when they appear to be dead according to dataflow analysis. References
6421to local register variables may be deleted or moved or simplified.
146ef39f 6422
6423These local variables are sometimes convenient for use with the extended
6424@code{asm} feature (@pxref{Extended Asm}), if you want to write one
6425output of the assembler instruction directly into a particular register.
6426(This will work provided the register you specify fits the constraints
6427specified for that operand in the @code{asm}.)
6428@end itemize
6429
6430@menu
6431* Global Reg Vars::
6432* Local Reg Vars::
6433@end menu
6434
6435@node Global Reg Vars
6436@subsection Defining Global Register Variables
6437@cindex global register variables
6438@cindex registers, global variables in
6439
6440You can define a global register variable in GNU C like this:
6441
a0ecd6b1 6442@smallexample
146ef39f 6443register int *foo asm ("a5");
a0ecd6b1 6444@end smallexample
146ef39f 6445
6446@noindent
6447Here @code{a5} is the name of the register which should be used. Choose a
6448register which is normally saved and restored by function calls on your
6449machine, so that library routines will not clobber it.
6450
6451Naturally the register name is cpu-dependent, so you would need to
6452conditionalize your program according to cpu type. The register
6453@code{a5} would be a good choice on a 68000 for a variable of pointer
6454type. On machines with register windows, be sure to choose a ``global''
6455register that is not affected magically by the function call mechanism.
6456
6457In addition, operating systems on one type of cpu may differ in how they
6458name the registers; then you would need additional conditionals. For
6459example, some 68000 operating systems call this register @code{%a5}.
6460
6461Eventually there may be a way of asking the compiler to choose a register
6462automatically, but first we need to figure out how it should choose and
6463how to enable you to guide the choice. No solution is evident.
6464
6465Defining a global register variable in a certain register reserves that
6466register entirely for this use, at least within the current compilation.
6467The register will not be allocated for any other purpose in the functions
6468in the current compilation. The register will not be saved and restored by
6469these functions. Stores into this register are never deleted even if they
6470would appear to be dead, but references may be deleted or moved or
6471simplified.
6472
6473It is not safe to access the global register variables from signal
6474handlers, or from more than one thread of control, because the system
6475library routines may temporarily use the register for other things (unless
6476you recompile them specially for the task at hand).
6477
6478@cindex @code{qsort}, and global register variables
6479It is not safe for one function that uses a global register variable to
6480call another such function @code{foo} by way of a third function
0858f8a2 6481@code{lose} that was compiled without knowledge of this variable (i.e.@: in a
146ef39f 6482different source file in which the variable wasn't declared). This is
6483because @code{lose} might save the register and put some other value there.
6484For example, you can't expect a global register variable to be available in
6485the comparison-function that you pass to @code{qsort}, since @code{qsort}
6486might have put something else in that register. (If you are prepared to
6487recompile @code{qsort} with the same global register variable, you can
6488solve this problem.)
6489
6490If you want to recompile @code{qsort} or other source files which do not
6491actually use your global register variable, so that they will not use that
6492register for any other purpose, then it suffices to specify the compiler
67791935 6493option @option{-ffixed-@var{reg}}. You need not actually add a global
146ef39f 6494register declaration to their source code.
6495
6496A function which can alter the value of a global register variable cannot
6497safely be called from a function compiled without this variable, because it
6498could clobber the value the caller expects to find there on return.
6499Therefore, the function which is the entry point into the part of the
6500program that uses the global register variable must explicitly save and
6501restore the value which belongs to its caller.
6502
6503@cindex register variable after @code{longjmp}
6504@cindex global register after @code{longjmp}
6505@cindex value after @code{longjmp}
6506@findex longjmp
6507@findex setjmp
6508On most machines, @code{longjmp} will restore to each global register
6509variable the value it had at the time of the @code{setjmp}. On some
6510machines, however, @code{longjmp} will not change the value of global
6511register variables. To be portable, the function that called @code{setjmp}
6512should make other arrangements to save the values of the global register
6513variables, and to restore them in a @code{longjmp}. This way, the same
6514thing will happen regardless of what @code{longjmp} does.
6515
6516All global register variable declarations must precede all function
6517definitions. If such a declaration could appear after function
6518definitions, the declaration would be too late to prevent the register from
6519being used for other purposes in the preceding functions.
6520
6521Global register variables may not have initial values, because an
6522executable file has no means to supply initial contents for a register.
6523
7800959d 6524On the SPARC, there are reports that g3 @dots{} g7 are suitable
146ef39f 6525registers, but certain library functions, such as @code{getwd}, as well
6526as the subroutines for division and remainder, modify g3 and g4. g1 and
6527g2 are local temporaries.
6528
6529On the 68000, a2 @dots{} a5 should be suitable, as should d2 @dots{} d7.
6530Of course, it will not do to use more than a few of those.
6531
6532@node Local Reg Vars
6533@subsection Specifying Registers for Local Variables
6534@cindex local variables, specifying registers
6535@cindex specifying registers for local variables
6536@cindex registers for local variables
6537
6538You can define a local register variable with a specified register
6539like this:
6540
a0ecd6b1 6541@smallexample
146ef39f 6542register int *foo asm ("a5");
a0ecd6b1 6543@end smallexample
146ef39f 6544
6545@noindent
6546Here @code{a5} is the name of the register which should be used. Note
6547that this is the same syntax used for defining global register
6548variables, but for a local variable it would appear within a function.
6549
6550Naturally the register name is cpu-dependent, but this is not a
6551problem, since specific registers are most often useful with explicit
6552assembler instructions (@pxref{Extended Asm}). Both of these things
6553generally require that you conditionalize your program according to
6554cpu type.
6555
6556In addition, operating systems on one type of cpu may differ in how they
6557name the registers; then you would need additional conditionals. For
6558example, some 68000 operating systems call this register @code{%a5}.
6559
146ef39f 6560Defining such a register variable does not reserve the register; it
6561remains available for other uses in places where flow control determines
d40bf399 6562the variable's value is not live.
997d68fe 6563
37744367 6564This option does not guarantee that GCC will generate code that has
997d68fe 6565this variable in the register you specify at all times. You may not
1358f000 6566code an explicit reference to this register in the @emph{assembler
6567instruction template} part of an @code{asm} statement and assume it will
6568always refer to this variable. However, using the variable as an
6569@code{asm} @emph{operand} guarantees that the specified register is used
6570for the operand.
146ef39f 6571
dcb61f7f 6572Stores into local register variables may be deleted when they appear to be dead
d2763590 6573according to dataflow analysis. References to local register variables may
6574be deleted or moved or simplified.
6575
2de78c9f 6576As for global register variables, it's recommended that you choose a
6577register which is normally saved and restored by function calls on
6578your machine, so that library routines will not clobber it. A common
6579pitfall is to initialize multiple call-clobbered registers with
6580arbitrary expressions, where a function call or library call for an
6581arithmetic operator will overwrite a register value from a previous
6582assignment, for example @code{r0} below:
6583@smallexample
6584register int *p1 asm ("r0") = @dots{};
6585register int *p2 asm ("r1") = @dots{};
6586@end smallexample
6587In those cases, a solution is to use a temporary variable for
6588each arbitrary expression. @xref{Example of asm with clobbered asm reg}.
6589
146ef39f 6590@node Alternate Keywords
6591@section Alternate Keywords
6592@cindex alternate keywords
6593@cindex keywords, alternate
6594
78b1f616 6595@option{-ansi} and the various @option{-std} options disable certain
455730ef 6596keywords. This causes trouble when you want to use GNU C extensions, or
6597a general-purpose header file that should be usable by all programs,
6598including ISO C programs. The keywords @code{asm}, @code{typeof} and
6599@code{inline} are not available in programs compiled with
6600@option{-ansi} or @option{-std} (although @code{inline} can be used in a
32074525 6601program compiled with @option{-std=c99} or @option{-std=c11}). The
39012afb 6602ISO C99 keyword
78b1f616 6603@code{restrict} is only available when @option{-std=gnu99} (which will
6604eventually be the default) or @option{-std=c99} (or the equivalent
39012afb 6605@option{-std=iso9899:1999}), or an option for a later standard
6606version, is used.
146ef39f 6607
6608The way to solve these problems is to put @samp{__} at the beginning and
6609end of each problematical keyword. For example, use @code{__asm__}
455730ef 6610instead of @code{asm}, and @code{__inline__} instead of @code{inline}.
146ef39f 6611
6612Other C compilers won't accept these alternative keywords; if you want to
6613compile with another compiler, you can define the alternate keywords as
6614macros to replace them with the customary keywords. It looks like this:
6615
a0ecd6b1 6616@smallexample
146ef39f 6617#ifndef __GNUC__
6618#define __asm__ asm
6619#endif
a0ecd6b1 6620@end smallexample
146ef39f 6621
d4303d2a 6622@findex __extension__
67791935 6623@opindex pedantic
6624@option{-pedantic} and other options cause warnings for many GNU C extensions.
6b88ddb7 6625You can
146ef39f 6626prevent such warnings within one expression by writing
6627@code{__extension__} before the expression. @code{__extension__} has no
6628effect aside from this.
6629
6630@node Incomplete Enums
6631@section Incomplete @code{enum} Types
6632
6633You can define an @code{enum} tag without specifying its possible values.
6634This results in an incomplete type, much like what you get if you write
6635@code{struct foo} without describing the elements. A later declaration
6636which does specify the possible values completes the type.
6637
6638You can't allocate variables or storage using the type while it is
6639incomplete. However, you can work with pointers to that type.
6640
6641This extension may not be very useful, but it makes the handling of
6642@code{enum} more consistent with the way @code{struct} and @code{union}
6643are handled.
6644
6645This extension is not supported by GNU C++.
6646
6647@node Function Names
6648@section Function Names as Strings
ebc03810 6649@cindex @code{__func__} identifier
3cfa0cc4 6650@cindex @code{__FUNCTION__} identifier
6651@cindex @code{__PRETTY_FUNCTION__} identifier
146ef39f 6652
ebc03810 6653GCC provides three magic variables which hold the name of the current
6654function, as a string. The first of these is @code{__func__}, which
6655is part of the C99 standard:
6656
ebc03810 6657The identifier @code{__func__} is implicitly declared by the translator
6658as if, immediately following the opening brace of each function
6659definition, the declaration
6660
6661@smallexample
6662static const char __func__[] = "function-name";
6663@end smallexample
146ef39f 6664
e66bbea3 6665@noindent
ebc03810 6666appeared, where function-name is the name of the lexically-enclosing
6667function. This name is the unadorned name of the function.
ebc03810 6668
6669@code{__FUNCTION__} is another name for @code{__func__}. Older
6670versions of GCC recognize only this name. However, it is not
6671standardized. For maximum portability, we recommend you use
6672@code{__func__}, but provide a fallback definition with the
6673preprocessor:
6674
6675@smallexample
6676#if __STDC_VERSION__ < 199901L
6677# if __GNUC__ >= 2
6678# define __func__ __FUNCTION__
6679# else
6680# define __func__ "<unknown>"
6681# endif
6682#endif
6683@end smallexample
6684
6685In C, @code{__PRETTY_FUNCTION__} is yet another name for
6686@code{__func__}. However, in C++, @code{__PRETTY_FUNCTION__} contains
6687the type signature of the function as well as its bare name. For
6688example, this program:
146ef39f 6689
6690@smallexample
6691extern "C" @{
6692extern int printf (char *, ...);
6693@}
6694
6695class a @{
6696 public:
20a69fd5 6697 void sub (int i)
146ef39f 6698 @{
6699 printf ("__FUNCTION__ = %s\n", __FUNCTION__);
6700 printf ("__PRETTY_FUNCTION__ = %s\n", __PRETTY_FUNCTION__);
6701 @}
6702@};
6703
6704int
6705main (void)
6706@{
6707 a ax;
6708 ax.sub (0);
6709 return 0;
6710@}
6711@end smallexample
6712
6713@noindent
6714gives this output:
6715
6716@smallexample
6717__FUNCTION__ = sub
ebc03810 6718__PRETTY_FUNCTION__ = void a::sub(int)
b082e8af 6719@end smallexample
6720
ebc03810 6721These identifiers are not preprocessor macros. In GCC 3.3 and
6722earlier, in C only, @code{__FUNCTION__} and @code{__PRETTY_FUNCTION__}
6723were treated as string literals; they could be used to initialize
6724@code{char} arrays, and they could be concatenated with other string
6725literals. GCC 3.4 and later treat them as variables, like
6726@code{__func__}. In C++, @code{__FUNCTION__} and
6727@code{__PRETTY_FUNCTION__} have always been variables.
b082e8af 6728
146ef39f 6729@node Return Address
6730@section Getting the Return or Frame Address of a Function
6731
6732These functions may be used to get information about the callers of a
6733function.
6734
67791935 6735@deftypefn {Built-in Function} {void *} __builtin_return_address (unsigned int @var{level})
146ef39f 6736This function returns the return address of the current function, or of
6737one of its callers. The @var{level} argument is number of frames to
6738scan up the call stack. A value of @code{0} yields the return address
6739of the current function, a value of @code{1} yields the return address
b3d47662 6740of the caller of the current function, and so forth. When inlining
85456819 6741the expected behavior is that the function will return the address of
6742the function that will be returned to. To work around this behavior use
6743the @code{noinline} function attribute.
146ef39f 6744
6745The @var{level} argument must be a constant integer.
6746
6747On some machines it may be impossible to determine the return address of
6748any function other than the current one; in such cases, or when the top
1288313e 6749of the stack has been reached, this function will return @code{0} or a
b3d47662 6750random value. In addition, @code{__builtin_frame_address} may be used
1288313e 6751to determine if the top of the stack has been reached.
146ef39f 6752
23807f43 6753Additional post-processing of the returned value may be needed, see
6754@code{__builtin_extract_return_address}.
6755
f45856ef 6756This function should only be used with a nonzero argument for debugging
146ef39f 6757purposes.
67791935 6758@end deftypefn
146ef39f 6759
23807f43 6760@deftypefn {Built-in Function} {void *} __builtin_extract_return_address (void *@var{addr})
6761The address as returned by @code{__builtin_return_address} may have to be fed
6762through this function to get the actual encoded address. For example, on the
676331-bit S/390 platform the highest bit has to be masked out, or on SPARC
6764platforms an offset has to be added for the true next instruction to be
6765executed.
6766
6767If no fixup is needed, this function simply passes through @var{addr}.
6768@end deftypefn
6769
6770@deftypefn {Built-in Function} {void *} __builtin_frob_return_address (void *@var{addr})
6771This function does the reverse of @code{__builtin_extract_return_address}.
6772@end deftypefn
6773
67791935 6774@deftypefn {Built-in Function} {void *} __builtin_frame_address (unsigned int @var{level})
146ef39f 6775This function is similar to @code{__builtin_return_address}, but it
6776returns the address of the function frame rather than the return address
6777of the function. Calling @code{__builtin_frame_address} with a value of
6778@code{0} yields the frame address of the current function, a value of
6779@code{1} yields the frame address of the caller of the current function,
6780and so forth.
6781
6782The frame is the area on the stack which holds local variables and saved
6783registers. The frame address is normally the address of the first word
6784pushed on to the stack by the function. However, the exact definition
6785depends upon the processor and the calling convention. If the processor
6786has a dedicated frame pointer register, and the function has a frame,
6787then @code{__builtin_frame_address} will return the value of the frame
6788pointer register.
6789
1288313e 6790On some machines it may be impossible to determine the frame address of
6791any function other than the current one; in such cases, or when the top
6792of the stack has been reached, this function will return @code{0} if
6793the first frame pointer is properly initialized by the startup code.
6794
f45856ef 6795This function should only be used with a nonzero argument for debugging
1288313e 6796purposes.
67791935 6797@end deftypefn
146ef39f 6798
ee5925ea 6799@node Vector Extensions
6800@section Using vector instructions through built-in functions
6801
6802On some targets, the instruction set contains SIMD vector instructions that
6803operate on multiple values contained in one large register at the same time.
4f0fcaad 6804For example, on the i386 the MMX, 3DNow!@: and SSE extensions can be used
ee5925ea 6805this way.
6806
6807The first step in using these extensions is to provide the necessary data
6808types. This should be done using an appropriate @code{typedef}:
6809
a0ecd6b1 6810@smallexample
4917c376 6811typedef int v4si __attribute__ ((vector_size (16)));
a0ecd6b1 6812@end smallexample
ee5925ea 6813
4917c376 6814The @code{int} type specifies the base type, while the attribute specifies
6815the vector size for the variable, measured in bytes. For example, the
6816declaration above causes the compiler to set the mode for the @code{v4si}
6817type to be 16 bytes wide and divided into @code{int} sized units. For
6818a 32-bit @code{int} this means a vector of 4 units of 4 bytes, and the
6819corresponding mode of @code{foo} will be @acronym{V4SI}.
ee5925ea 6820
4917c376 6821The @code{vector_size} attribute is only applicable to integral and
6822float scalars, although arrays, pointers, and function return values
6823are allowed in conjunction with this construct.
6824
6825All the basic integer types can be used as base types, both as signed
6826and as unsigned: @code{char}, @code{short}, @code{int}, @code{long},
6827@code{long long}. In addition, @code{float} and @code{double} can be
6828used to build floating-point vector types.
ee5925ea 6829
ead34f59 6830Specifying a combination that is not valid for the current architecture
ef8d967c 6831will cause GCC to synthesize the instructions using a narrower mode.
ead34f59 6832For example, if you specify a variable of type @code{V4SI} and your
ef8d967c 6833architecture does not allow for this specific SIMD type, GCC will
ead34f59 6834produce code that uses 4 @code{SIs}.
6835
6836The types defined in this manner can be used with a subset of normal C
ef8d967c 6837operations. Currently, GCC will allow using the following operators
b6d7101e 6838on these types: @code{+, -, *, /, unary minus, ^, |, &, ~, %}@.
ead34f59 6839
6840The operations behave like C++ @code{valarrays}. Addition is defined as
6841the addition of the corresponding elements of the operands. For
6842example, in the code below, each of the 4 elements in @var{a} will be
6843added to the corresponding 4 elements in @var{b} and the resulting
6844vector will be stored in @var{c}.
6845
a0ecd6b1 6846@smallexample
4917c376 6847typedef int v4si __attribute__ ((vector_size (16)));
ead34f59 6848
6849v4si a, b, c;
6850
6851c = a + b;
a0ecd6b1 6852@end smallexample
ead34f59 6853
b51e481d 6854Subtraction, multiplication, division, and the logical operations
6855operate in a similar manner. Likewise, the result of using the unary
6856minus or complement operators on a vector type is a vector whose
6857elements are the negative or complemented values of the corresponding
ead34f59 6858elements in the operand.
6859
191b2c61 6860In C it is possible to use shifting operators @code{<<}, @code{>>} on
6861integer-type vectors. The operation is defined as following: @code{@{a0,
6862a1, @dots{}, an@} >> @{b0, b1, @dots{}, bn@} == @{a0 >> b0, a1 >> b1,
6863@dots{}, an >> bn@}}@. Vector operands must have the same number of
7dfa155b 6864elements.
6865
6866For the convenience in C it is allowed to use a binary vector operation
6867where one operand is a scalar. In that case the compiler will transform
6868the scalar operand into a vector where each element is the scalar from
6869the operation. The transformation will happen only if the scalar could be
6870safely converted to the vector-element type.
191b2c61 6871Consider the following code.
6872
6873@smallexample
6874typedef int v4si __attribute__ ((vector_size (16)));
6875
7dfa155b 6876v4si a, b, c;
6877long l;
6878
6879a = b + 1; /* a = b + @{1,1,1,1@}; */
6880a = 2 * b; /* a = @{2,2,2,2@} * b; */
191b2c61 6881
7dfa155b 6882a = l + a; /* Error, cannot convert long to int. */
191b2c61 6883@end smallexample
6884
7059d45d 6885Vectors can be subscripted as if the vector were an array with
93426222 6886the same number of elements and base type. Out of bound accesses
6887invoke undefined behavior at runtime. Warnings for out of bound
6888accesses for vector subscription can be enabled with
6889@option{-Warray-bounds}.
6890
d7ad16c2 6891In GNU C vector comparison is supported within standard comparison
6892operators: @code{==, !=, <, <=, >, >=}. Comparison operands can be
6893vector expressions of integer-type or real-type. Comparison between
6894integer-type vectors and real-type vectors are not supported. The
6895result of the comparison is a vector of the same width and number of
6896elements as the comparison operands with a signed integral element
6897type.
6898
6899Vectors are compared element-wise producing 0 when comparison is false
6900and -1 (constant of the appropriate type where all bits are set)
6901otherwise. Consider the following example.
6902
6903@smallexample
6904typedef int v4si __attribute__ ((vector_size (16)));
6905
6906v4si a = @{1,2,3,4@};
6907v4si b = @{3,2,1,4@};
6908v4si c;
6909
6910c = a > b; /* The result would be @{0, 0,-1, 0@} */
6911c = a == b; /* The result would be @{0,-1, 0,-1@} */
6912@end smallexample
6913
6cf89e04 6914Vector shuffling is available using functions
6915@code{__builtin_shuffle (vec, mask)} and
f4803722 6916@code{__builtin_shuffle (vec0, vec1, mask)}.
6917Both functions construct a permutation of elements from one or two
6918vectors and return a vector of the same type as the input vector(s).
6919The @var{mask} is an integral vector with the same width (@var{W})
6920and element count (@var{N}) as the output vector.
6cf89e04 6921
f4803722 6922The elements of the input vectors are numbered in memory ordering of
6923@var{vec0} beginning at 0 and @var{vec1} beginning at @var{N}. The
6924elements of @var{mask} are considered modulo @var{N} in the single-operand
6925case and modulo @math{2*@var{N}} in the two-operand case.
6926
6927Consider the following example,
6cf89e04 6928
6929@smallexample
6930typedef int v4si __attribute__ ((vector_size (16)));
6931
6932v4si a = @{1,2,3,4@};
6933v4si b = @{5,6,7,8@};
6934v4si mask1 = @{0,1,1,3@};
6935v4si mask2 = @{0,4,2,5@};
6936v4si res;
6937
6938res = __builtin_shuffle (a, mask1); /* res is @{1,2,2,4@} */
6939res = __builtin_shuffle (a, b, mask2); /* res is @{1,5,3,6@} */
6940@end smallexample
6941
f4803722 6942Note that @code{__builtin_shuffle} is intentionally semantically
6943compatible with the OpenCL @code{shuffle} and @code{shuffle2} functions.
6944
ead34f59 6945You can declare variables and use them in function calls and returns, as
6946well as in assignments and some casts. You can specify a vector type as
6947a return type for a function. Vector types can also be used as function
6948arguments. It is possible to cast from one vector type to another,
6949provided they are of the same size (in fact, you can also cast vectors
6950to and from other datatypes of the same size).
6951
6952You cannot operate between vectors of different lengths or different
d835d5ce 6953signedness without a cast.
ead34f59 6954
43bf5d72 6955@node Offsetof
6956@section Offsetof
6957@findex __builtin_offsetof
6958
6959GCC implements for both C and C++ a syntactic extension to implement
6960the @code{offsetof} macro.
6961
6962@smallexample
6963primary:
c24c5fac 6964 "__builtin_offsetof" "(" @code{typename} "," offsetof_member_designator ")"
43bf5d72 6965
6966offsetof_member_designator:
c24c5fac 6967 @code{identifier}
6968 | offsetof_member_designator "." @code{identifier}
6969 | offsetof_member_designator "[" @code{expr} "]"
43bf5d72 6970@end smallexample
6971
6972This extension is sufficient such that
6973
6974@smallexample
6975#define offsetof(@var{type}, @var{member}) __builtin_offsetof (@var{type}, @var{member})
6976@end smallexample
6977
6978is a suitable definition of the @code{offsetof} macro. In C++, @var{type}
6979may be dependent. In either case, @var{member} may consist of a single
6980identifier, or a sequence of member accesses and array references.
6981
1cd6e20d 6982@node __sync Builtins
6983@section Legacy __sync built-in functions for atomic memory access
b6a5fc45 6984
6985The following builtins are intended to be compatible with those described
6986in the @cite{Intel Itanium Processor-specific Application Binary Interface},
6987section 7.4. As such, they depart from the normal GCC practice of using
6988the ``__builtin_'' prefix, and further that they are overloaded such that
6989they work on multiple types.
6990
6991The definition given in the Intel documentation allows only for the use of
6992the types @code{int}, @code{long}, @code{long long} as well as their unsigned
6993counterparts. GCC will allow any integral scalar or pointer type that is
69941, 2, 4 or 8 bytes in length.
6995
6996Not all operations are supported by all target processors. If a particular
6997operation cannot be implemented on the target processor, a warning will be
6998generated and a call an external function will be generated. The external
6999function will carry the same name as the builtin, with an additional suffix
7000@samp{_@var{n}} where @var{n} is the size of the data type.
7001
7002@c ??? Should we have a mechanism to suppress this warning? This is almost
7003@c useful for implementing the operation under the control of an external
7004@c mutex.
7005
7006In most cases, these builtins are considered a @dfn{full barrier}. That is,
7007no memory operand will be moved across the operation, either forward or
7008backward. Further, instructions will be issued as necessary to prevent the
7009processor from speculating loads across the operation and from queuing stores
7010after the operation.
7011
d2258b2f 7012All of the routines are described in the Intel documentation to take
b6a5fc45 7013``an optional list of variables protected by the memory barrier''. It's
7014not clear what is meant by that; it could mean that @emph{only} the
7015following variables are protected, or it could mean that these variables
7016should in addition be protected. At present GCC ignores this list and
7017protects all variables which are globally accessible. If in the future
7018we make some use of this list, an empty list will continue to mean all
7019globally accessible variables.
7020
7021@table @code
7022@item @var{type} __sync_fetch_and_add (@var{type} *ptr, @var{type} value, ...)
7023@itemx @var{type} __sync_fetch_and_sub (@var{type} *ptr, @var{type} value, ...)
7024@itemx @var{type} __sync_fetch_and_or (@var{type} *ptr, @var{type} value, ...)
7025@itemx @var{type} __sync_fetch_and_and (@var{type} *ptr, @var{type} value, ...)
7026@itemx @var{type} __sync_fetch_and_xor (@var{type} *ptr, @var{type} value, ...)
7027@itemx @var{type} __sync_fetch_and_nand (@var{type} *ptr, @var{type} value, ...)
7028@findex __sync_fetch_and_add
7029@findex __sync_fetch_and_sub
7030@findex __sync_fetch_and_or
7031@findex __sync_fetch_and_and
7032@findex __sync_fetch_and_xor
7033@findex __sync_fetch_and_nand
7034These builtins perform the operation suggested by the name, and
7035returns the value that had previously been in memory. That is,
7036
7037@smallexample
7038@{ tmp = *ptr; *ptr @var{op}= value; return tmp; @}
cf73e559 7039@{ tmp = *ptr; *ptr = ~(tmp & value); return tmp; @} // nand
b6a5fc45 7040@end smallexample
7041
cf73e559 7042@emph{Note:} GCC 4.4 and later implement @code{__sync_fetch_and_nand}
7043builtin as @code{*ptr = ~(tmp & value)} instead of @code{*ptr = ~tmp & value}.
7044
b6a5fc45 7045@item @var{type} __sync_add_and_fetch (@var{type} *ptr, @var{type} value, ...)
7046@itemx @var{type} __sync_sub_and_fetch (@var{type} *ptr, @var{type} value, ...)
7047@itemx @var{type} __sync_or_and_fetch (@var{type} *ptr, @var{type} value, ...)
7048@itemx @var{type} __sync_and_and_fetch (@var{type} *ptr, @var{type} value, ...)
7049@itemx @var{type} __sync_xor_and_fetch (@var{type} *ptr, @var{type} value, ...)
7050@itemx @var{type} __sync_nand_and_fetch (@var{type} *ptr, @var{type} value, ...)
7051@findex __sync_add_and_fetch
7052@findex __sync_sub_and_fetch
7053@findex __sync_or_and_fetch
7054@findex __sync_and_and_fetch
7055@findex __sync_xor_and_fetch
7056@findex __sync_nand_and_fetch
7057These builtins perform the operation suggested by the name, and
7058return the new value. That is,
7059
7060@smallexample
7061@{ *ptr @var{op}= value; return *ptr; @}
cf73e559 7062@{ *ptr = ~(*ptr & value); return *ptr; @} // nand
b6a5fc45 7063@end smallexample
7064
cf73e559 7065@emph{Note:} GCC 4.4 and later implement @code{__sync_nand_and_fetch}
7066builtin as @code{*ptr = ~(*ptr & value)} instead of
7067@code{*ptr = ~*ptr & value}.
7068
142d1be6 7069@item bool __sync_bool_compare_and_swap (@var{type} *ptr, @var{type} oldval, @var{type} newval, ...)
7070@itemx @var{type} __sync_val_compare_and_swap (@var{type} *ptr, @var{type} oldval, @var{type} newval, ...)
b6a5fc45 7071@findex __sync_bool_compare_and_swap
7072@findex __sync_val_compare_and_swap
7073These builtins perform an atomic compare and swap. That is, if the current
7074value of @code{*@var{ptr}} is @var{oldval}, then write @var{newval} into
7075@code{*@var{ptr}}.
7076
7bd4091f 7077The ``bool'' version returns true if the comparison is successful and
b6a5fc45 7078@var{newval} was written. The ``val'' version returns the contents
87121034 7079of @code{*@var{ptr}} before the operation.
b6a5fc45 7080
7081@item __sync_synchronize (...)
7082@findex __sync_synchronize
7083This builtin issues a full memory barrier.
7084
7085@item @var{type} __sync_lock_test_and_set (@var{type} *ptr, @var{type} value, ...)
7086@findex __sync_lock_test_and_set
7087This builtin, as described by Intel, is not a traditional test-and-set
7088operation, but rather an atomic exchange operation. It writes @var{value}
7089into @code{*@var{ptr}}, and returns the previous contents of
7090@code{*@var{ptr}}.
7091
7092Many targets have only minimal support for such locks, and do not support
7093a full exchange operation. In this case, a target may support reduced
7094functionality here by which the @emph{only} valid value to store is the
7095immediate constant 1. The exact value actually stored in @code{*@var{ptr}}
7096is implementation defined.
7097
7098This builtin is not a full barrier, but rather an @dfn{acquire barrier}.
7099This means that references after the builtin cannot move to (or be
7100speculated to) before the builtin, but previous memory stores may not
7bd4091f 7101be globally visible yet, and previous memory loads may not yet be
b6a5fc45 7102satisfied.
7103
7104@item void __sync_lock_release (@var{type} *ptr, ...)
7105@findex __sync_lock_release
7106This builtin releases the lock acquired by @code{__sync_lock_test_and_set}.
7107Normally this means writing the constant 0 to @code{*@var{ptr}}.
7108
7109This builtin is not a full barrier, but rather a @dfn{release barrier}.
7110This means that all previous memory stores are globally visible, and all
7111previous memory loads have been satisfied, but following memory reads
7112are not prevented from being speculated to before the barrier.
7113@end table
7114
1cd6e20d 7115@node __atomic Builtins
7116@section Built-in functions for memory model aware atomic operations
7117
7118The following built-in functions approximately match the requirements for
7119C++11 memory model. Many are similar to the @samp{__sync} prefixed built-in
7120functions, but all also have a memory model parameter. These are all
7121identified by being prefixed with @samp{__atomic}, and most are overloaded
7122such that they work with multiple types.
7123
7124GCC will allow any integral scalar or pointer type that is 1, 2, 4, or 8
7125bytes in length. 16-byte integral types are also allowed if
7126@samp{__int128} (@pxref{__int128}) is supported by the architecture.
7127
7128Target architectures are encouraged to provide their own patterns for
7129each of these built-in functions. If no target is provided, the original
7130non-memory model set of @samp{__sync} atomic built-in functions will be
7131utilized, along with any required synchronization fences surrounding it in
7132order to achieve the proper behaviour. Execution in this case is subject
7133to the same restrictions as those built-in functions.
7134
7135If there is no pattern or mechanism to provide a lock free instruction
7136sequence, a call is made to an external routine with the same parameters
7137to be resolved at runtime.
7138
7139The four non-arithmetic functions (load, store, exchange, and
7140compare_exchange) all have a generic version as well. This generic
7141version will work on any data type. If the data type size maps to one
7142of the integral sizes which may have lock free support, the generic
7143version will utilize the lock free built-in function. Otherwise an
7144external call is left to be resolved at runtime. This external call will
7145be the same format with the addition of a @samp{size_t} parameter inserted
7146as the first parameter indicating the size of the object being pointed to.
7147All objects must be the same size.
7148
7149There are 6 different memory models which can be specified. These map
7150to the same names in the C++11 standard. Refer there or to the
7151@uref{http://gcc.gnu.org/wiki/Atomic/GCCMM/AtomicSync,GCC wiki on
7152atomic synchronization} for more detailed definitions. These memory
7153models integrate both barriers to code motion as well as synchronization
7154requirements with other threads. These are listed in approximately
7f738025 7155ascending order of strength. It is also possible to use target specific
7156flags for memory model flags, like Hardware Lock Elision.
1cd6e20d 7157
7158@table @code
7159@item __ATOMIC_RELAXED
7160No barriers or synchronization.
7161@item __ATOMIC_CONSUME
7162Data dependency only for both barrier and synchronization with another
7163thread.
7164@item __ATOMIC_ACQUIRE
7165Barrier to hoisting of code and synchronizes with release (or stronger)
7166semantic stores from another thread.
7167@item __ATOMIC_RELEASE
7168Barrier to sinking of code and synchronizes with acquire (or stronger)
7169semantic loads from another thread.
7170@item __ATOMIC_ACQ_REL
7171Full barrier in both directions and synchronizes with acquire loads and
7172release stores in another thread.
7173@item __ATOMIC_SEQ_CST
7174Full barrier in both directions and synchronizes with acquire loads and
7175release stores in all threads.
7176@end table
7177
23b5e150 7178When implementing patterns for these built-in functions, the memory model
1cd6e20d 7179parameter can be ignored as long as the pattern implements the most
7180restrictive @code{__ATOMIC_SEQ_CST} model. Any of the other memory models
7181will execute correctly with this memory model but they may not execute as
7182efficiently as they could with a more appropriate implemention of the
7183relaxed requirements.
7184
7185Note that the C++11 standard allows for the memory model parameter to be
7186determined at runtime rather than at compile time. These built-in
7187functions will map any runtime value to @code{__ATOMIC_SEQ_CST} rather
7188than invoke a runtime library call or inline a switch statement. This is
7189standard compliant, safe, and the simplest approach for now.
7190
fd46ba2e 7191The memory model parameter is a signed int, but only the lower 8 bits are
7192reserved for the memory model. The remainder of the signed int is reserved
7193for future use and should be 0. Use of the predefined atomic values will
7194ensure proper usage.
7195
1cd6e20d 7196@deftypefn {Built-in Function} @var{type} __atomic_load_n (@var{type} *ptr, int memmodel)
7197This built-in function implements an atomic load operation. It returns the
7198contents of @code{*@var{ptr}}.
7199
7200The valid memory model variants are
7201@code{__ATOMIC_RELAXED}, @code{__ATOMIC_SEQ_CST}, @code{__ATOMIC_ACQUIRE},
7202and @code{__ATOMIC_CONSUME}.
7203
7204@end deftypefn
7205
7206@deftypefn {Built-in Function} void __atomic_load (@var{type} *ptr, @var{type} *ret, int memmodel)
7207This is the generic version of an atomic load. It will return the
7208contents of @code{*@var{ptr}} in @code{*@var{ret}}.
7209
7210@end deftypefn
7211
7212@deftypefn {Built-in Function} void __atomic_store_n (@var{type} *ptr, @var{type} val, int memmodel)
7213This built-in function implements an atomic store operation. It writes
8808bf16 7214@code{@var{val}} into @code{*@var{ptr}}.
1cd6e20d 7215
7216The valid memory model variants are
7217@code{__ATOMIC_RELAXED}, @code{__ATOMIC_SEQ_CST}, and @code{__ATOMIC_RELEASE}.
7218
7219@end deftypefn
7220
7221@deftypefn {Built-in Function} void __atomic_store (@var{type} *ptr, @var{type} *val, int memmodel)
7222This is the generic version of an atomic store. It will store the value
7223of @code{*@var{val}} into @code{*@var{ptr}}.
7224
7225@end deftypefn
7226
7227@deftypefn {Built-in Function} @var{type} __atomic_exchange_n (@var{type} *ptr, @var{type} val, int memmodel)
7228This built-in function implements an atomic exchange operation. It writes
7229@var{val} into @code{*@var{ptr}}, and returns the previous contents of
7230@code{*@var{ptr}}.
7231
1cd6e20d 7232The valid memory model variants are
7233@code{__ATOMIC_RELAXED}, @code{__ATOMIC_SEQ_CST}, @code{__ATOMIC_ACQUIRE},
7234@code{__ATOMIC_RELEASE}, and @code{__ATOMIC_ACQ_REL}.
7235
7236@end deftypefn
7237
7238@deftypefn {Built-in Function} void __atomic_exchange (@var{type} *ptr, @var{type} *val, @var{type} *ret, int memmodel)
7239This is the generic version of an atomic exchange. It will store the
7240contents of @code{*@var{val}} into @code{*@var{ptr}}. The original value
7241of @code{*@var{ptr}} will be copied into @code{*@var{ret}}.
7242
7243@end deftypefn
7244
7245@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)
7246This built-in function implements an atomic compare and exchange operation.
7247This compares the contents of @code{*@var{ptr}} with the contents of
7248@code{*@var{expected}} and if equal, writes @var{desired} into
7249@code{*@var{ptr}}. If they are not equal, the current contents of
c311fe7e 7250@code{*@var{ptr}} is written into @code{*@var{expected}}. @var{weak} is true
7251for weak compare_exchange, and false for the strong variation. Many targets
7252only offer the strong variation and ignore the parameter. When in doubt, use
7253the strong variation.
1cd6e20d 7254
c5519669 7255True is returned if @var{desired} is written into
1cd6e20d 7256@code{*@var{ptr}} and the execution is considered to conform to the
7257memory model specified by @var{success_memmodel}. There are no
7258restrictions on what memory model can be used here.
7259
7260False is returned otherwise, and the execution is considered to conform
7261to @var{failure_memmodel}. This memory model cannot be
7262@code{__ATOMIC_RELEASE} nor @code{__ATOMIC_ACQ_REL}. It also cannot be a
7263stronger model than that specified by @var{success_memmodel}.
7264
7265@end deftypefn
7266
7267@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)
7268This built-in function implements the generic version of
7269@code{__atomic_compare_exchange}. The function is virtually identical to
7270@code{__atomic_compare_exchange_n}, except the desired value is also a
7271pointer.
7272
7273@end deftypefn
7274
7275@deftypefn {Built-in Function} @var{type} __atomic_add_fetch (@var{type} *ptr, @var{type} val, int memmodel)
7276@deftypefnx {Built-in Function} @var{type} __atomic_sub_fetch (@var{type} *ptr, @var{type} val, int memmodel)
7277@deftypefnx {Built-in Function} @var{type} __atomic_and_fetch (@var{type} *ptr, @var{type} val, int memmodel)
7278@deftypefnx {Built-in Function} @var{type} __atomic_xor_fetch (@var{type} *ptr, @var{type} val, int memmodel)
7279@deftypefnx {Built-in Function} @var{type} __atomic_or_fetch (@var{type} *ptr, @var{type} val, int memmodel)
7280@deftypefnx {Built-in Function} @var{type} __atomic_nand_fetch (@var{type} *ptr, @var{type} val, int memmodel)
7281These built-in functions perform the operation suggested by the name, and
7282return the result of the operation. That is,
7283
7284@smallexample
7285@{ *ptr @var{op}= val; return *ptr; @}
7286@end smallexample
7287
7288All memory models are valid.
7289
7290@end deftypefn
7291
7292@deftypefn {Built-in Function} @var{type} __atomic_fetch_add (@var{type} *ptr, @var{type} val, int memmodel)
7293@deftypefnx {Built-in Function} @var{type} __atomic_fetch_sub (@var{type} *ptr, @var{type} val, int memmodel)
7294@deftypefnx {Built-in Function} @var{type} __atomic_fetch_and (@var{type} *ptr, @var{type} val, int memmodel)
7295@deftypefnx {Built-in Function} @var{type} __atomic_fetch_xor (@var{type} *ptr, @var{type} val, int memmodel)
7296@deftypefnx {Built-in Function} @var{type} __atomic_fetch_or (@var{type} *ptr, @var{type} val, int memmodel)
7297@deftypefnx {Built-in Function} @var{type} __atomic_fetch_nand (@var{type} *ptr, @var{type} val, int memmodel)
7298These built-in functions perform the operation suggested by the name, and
7299return the value that had previously been in @code{*@var{ptr}}. That is,
7300
7301@smallexample
7302@{ tmp = *ptr; *ptr @var{op}= val; return tmp; @}
7303@end smallexample
7304
7305All memory models are valid.
7306
7307@end deftypefn
7308
39ca90d5 7309@deftypefn {Built-in Function} bool __atomic_test_and_set (void *ptr, int memmodel)
faefd2ad 7310
7311This built-in function performs an atomic test-and-set operation on
39ca90d5 7312the byte at @code{*@var{ptr}}. The byte is set to some implementation
7313defined non-zero "set" value and the return value is @code{true} if and only
7314if the previous contents were "set".
faefd2ad 7315
7316All memory models are valid.
7317
7318@end deftypefn
7319
7320@deftypefn {Built-in Function} void __atomic_clear (bool *ptr, int memmodel)
7321
7322This built-in function performs an atomic clear operation on
7323@code{*@var{ptr}}. After the operation, @code{*@var{ptr}} will contain 0.
7324
7325The valid memory model variants are
7326@code{__ATOMIC_RELAXED}, @code{__ATOMIC_SEQ_CST}, and
7327@code{__ATOMIC_RELEASE}.
7328
7329@end deftypefn
7330
1cd6e20d 7331@deftypefn {Built-in Function} void __atomic_thread_fence (int memmodel)
7332
7333This built-in function acts as a synchronization fence between threads
7334based on the specified memory model.
7335
7336All memory orders are valid.
7337
7338@end deftypefn
7339
7340@deftypefn {Built-in Function} void __atomic_signal_fence (int memmodel)
7341
7342This built-in function acts as a synchronization fence between a thread
7343and signal handlers based in the same thread.
7344
7345All memory orders are valid.
7346
7347@end deftypefn
7348
c311fe7e 7349@deftypefn {Built-in Function} bool __atomic_always_lock_free (size_t size, void *ptr)
1cd6e20d 7350
c311fe7e 7351This built-in function returns true if objects of @var{size} bytes will always
7352generate lock free atomic instructions for the target architecture.
7353@var{size} must resolve to a compile time constant and the result also resolves to compile time constant.
1cd6e20d 7354
c311fe7e 7355@var{ptr} is an optional pointer to the object which may be used to determine
7356alignment. A value of 0 indicates typical alignment should be used. The
7357compiler may also ignore this parameter.
1cd6e20d 7358
7359@smallexample
c311fe7e 7360if (_atomic_always_lock_free (sizeof (long long), 0))
1cd6e20d 7361@end smallexample
7362
7363@end deftypefn
7364
c311fe7e 7365@deftypefn {Built-in Function} bool __atomic_is_lock_free (size_t size, void *ptr)
1cd6e20d 7366
c311fe7e 7367This built-in function returns true if objects of @var{size} bytes will always
1cd6e20d 7368generate lock free atomic instructions for the target architecture. If
7369it is not known to be lock free a call is made to a runtime routine named
7370@code{__atomic_is_lock_free}.
7371
c311fe7e 7372@var{ptr} is an optional pointer to the object which may be used to determine
7373alignment. A value of 0 indicates typical alignment should be used. The
7374compiler may also ignore this parameter.
1cd6e20d 7375@end deftypefn
7376
0a39fd54 7377@node Object Size Checking
7378@section Object Size Checking Builtins
7379@findex __builtin_object_size
7380@findex __builtin___memcpy_chk
7381@findex __builtin___mempcpy_chk
7382@findex __builtin___memmove_chk
7383@findex __builtin___memset_chk
7384@findex __builtin___strcpy_chk
7385@findex __builtin___stpcpy_chk
7386@findex __builtin___strncpy_chk
7387@findex __builtin___strcat_chk
7388@findex __builtin___strncat_chk
7389@findex __builtin___sprintf_chk
7390@findex __builtin___snprintf_chk
7391@findex __builtin___vsprintf_chk
7392@findex __builtin___vsnprintf_chk
7393@findex __builtin___printf_chk
7394@findex __builtin___vprintf_chk
7395@findex __builtin___fprintf_chk
7396@findex __builtin___vfprintf_chk
7397
7398GCC implements a limited buffer overflow protection mechanism
7399that can prevent some buffer overflow attacks.
7400
7401@deftypefn {Built-in Function} {size_t} __builtin_object_size (void * @var{ptr}, int @var{type})
7402is a built-in construct that returns a constant number of bytes from
7403@var{ptr} to the end of the object @var{ptr} pointer points to
7404(if known at compile time). @code{__builtin_object_size} never evaluates
7405its arguments for side-effects. If there are any side-effects in them, it
7406returns @code{(size_t) -1} for @var{type} 0 or 1 and @code{(size_t) 0}
7407for @var{type} 2 or 3. If there are multiple objects @var{ptr} can
7408point to and all of them are known at compile time, the returned number
7409is the maximum of remaining byte counts in those objects if @var{type} & 2 is
3ce7ff97 74100 and minimum if nonzero. If it is not possible to determine which objects
0a39fd54 7411@var{ptr} points to at compile time, @code{__builtin_object_size} should
7412return @code{(size_t) -1} for @var{type} 0 or 1 and @code{(size_t) 0}
7413for @var{type} 2 or 3.
7414
7415@var{type} is an integer constant from 0 to 3. If the least significant
7416bit is clear, objects are whole variables, if it is set, a closest
7417surrounding subobject is considered the object a pointer points to.
7418The second bit determines if maximum or minimum of remaining bytes
7419is computed.
7420
7421@smallexample
7422struct V @{ char buf1[10]; int b; char buf2[10]; @} var;
7423char *p = &var.buf1[1], *q = &var.b;
7424
7425/* Here the object p points to is var. */
7426assert (__builtin_object_size (p, 0) == sizeof (var) - 1);
7427/* The subobject p points to is var.buf1. */
7428assert (__builtin_object_size (p, 1) == sizeof (var.buf1) - 1);
7429/* The object q points to is var. */
7430assert (__builtin_object_size (q, 0)
c24c5fac 7431 == (char *) (&var + 1) - (char *) &var.b);
0a39fd54 7432/* The subobject q points to is var.b. */
7433assert (__builtin_object_size (q, 1) == sizeof (var.b));
7434@end smallexample
7435@end deftypefn
7436
7437There are built-in functions added for many common string operation
83d10720 7438functions, e.g., for @code{memcpy} @code{__builtin___memcpy_chk}
0a39fd54 7439built-in is provided. This built-in has an additional last argument,
7440which is the number of bytes remaining in object the @var{dest}
7441argument points to or @code{(size_t) -1} if the size is not known.
7442
7443The built-in functions are optimized into the normal string functions
7444like @code{memcpy} if the last argument is @code{(size_t) -1} or if
7445it is known at compile time that the destination object will not
7446be overflown. If the compiler can determine at compile time the
7447object will be always overflown, it issues a warning.
7448
7449The intended use can be e.g.
7450
7451@smallexample
7452#undef memcpy
7453#define bos0(dest) __builtin_object_size (dest, 0)
7454#define memcpy(dest, src, n) \
7455 __builtin___memcpy_chk (dest, src, n, bos0 (dest))
7456
7457char *volatile p;
7458char buf[10];
7459/* It is unknown what object p points to, so this is optimized
7460 into plain memcpy - no checking is possible. */
7461memcpy (p, "abcde", n);
7462/* Destination is known and length too. It is known at compile
7463 time there will be no overflow. */
7464memcpy (&buf[5], "abcde", 5);
7465/* Destination is known, but the length is not known at compile time.
7466 This will result in __memcpy_chk call that can check for overflow
7467 at runtime. */
7468memcpy (&buf[5], "abcde", n);
7469/* Destination is known and it is known at compile time there will
7470 be overflow. There will be a warning and __memcpy_chk call that
7471 will abort the program at runtime. */
7472memcpy (&buf[6], "abcde", 5);
7473@end smallexample
7474
7475Such built-in functions are provided for @code{memcpy}, @code{mempcpy},
7476@code{memmove}, @code{memset}, @code{strcpy}, @code{stpcpy}, @code{strncpy},
7477@code{strcat} and @code{strncat}.
7478
7479There are also checking built-in functions for formatted output functions.
7480@smallexample
7481int __builtin___sprintf_chk (char *s, int flag, size_t os, const char *fmt, ...);
7482int __builtin___snprintf_chk (char *s, size_t maxlen, int flag, size_t os,
c24c5fac 7483 const char *fmt, ...);
0a39fd54 7484int __builtin___vsprintf_chk (char *s, int flag, size_t os, const char *fmt,
c24c5fac 7485 va_list ap);
0a39fd54 7486int __builtin___vsnprintf_chk (char *s, size_t maxlen, int flag, size_t os,
c24c5fac 7487 const char *fmt, va_list ap);
0a39fd54 7488@end smallexample
7489
7490The added @var{flag} argument is passed unchanged to @code{__sprintf_chk}
83d10720 7491etc.@: functions and can contain implementation specific flags on what
0a39fd54 7492additional security measures the checking function might take, such as
7493handling @code{%n} differently.
7494
7495The @var{os} argument is the object size @var{s} points to, like in the
3ce7ff97 7496other built-in functions. There is a small difference in the behavior
0a39fd54 7497though, if @var{os} is @code{(size_t) -1}, the built-in functions are
7498optimized into the non-checking functions only if @var{flag} is 0, otherwise
7499the checking function is called with @var{os} argument set to
7500@code{(size_t) -1}.
7501
7502In addition to this, there are checking built-in functions
7503@code{__builtin___printf_chk}, @code{__builtin___vprintf_chk},
7504@code{__builtin___fprintf_chk} and @code{__builtin___vfprintf_chk}.
7505These have just one additional argument, @var{flag}, right before
7506format string @var{fmt}. If the compiler is able to optimize them to
83d10720 7507@code{fputc} etc.@: functions, it will, otherwise the checking function
0a39fd54 7508should be called and the @var{flag} argument passed to it.
7509
2c776a54 7510@node Other Builtins
37744367 7511@section Other built-in functions provided by GCC
8e5fcce7 7512@cindex built-in functions
19fbe3a4 7513@findex __builtin_fpclassify
cde061c1 7514@findex __builtin_isfinite
8a1a9cb7 7515@findex __builtin_isnormal
1f4e0dac 7516@findex __builtin_isgreater
7517@findex __builtin_isgreaterequal
c319d56a 7518@findex __builtin_isinf_sign
1f4e0dac 7519@findex __builtin_isless
7520@findex __builtin_islessequal
7521@findex __builtin_islessgreater
7522@findex __builtin_isunordered
757c219d 7523@findex __builtin_powi
7524@findex __builtin_powif
7525@findex __builtin_powil
e88e2794 7526@findex _Exit
7527@findex _exit
1f4e0dac 7528@findex abort
7529@findex abs
e88e2794 7530@findex acos
7531@findex acosf
7532@findex acosh
7533@findex acoshf
7534@findex acoshl
7535@findex acosl
1f4e0dac 7536@findex alloca
e88e2794 7537@findex asin
7538@findex asinf
7539@findex asinh
7540@findex asinhf
7541@findex asinhl
7542@findex asinl
a2246f84 7543@findex atan
fa426235 7544@findex atan2
7545@findex atan2f
7546@findex atan2l
a2246f84 7547@findex atanf
e88e2794 7548@findex atanh
7549@findex atanhf
7550@findex atanhl
a2246f84 7551@findex atanl
1f4e0dac 7552@findex bcmp
7553@findex bzero
78a74442 7554@findex cabs
7555@findex cabsf
7556@findex cabsl
61b922e7 7557@findex cacos
7558@findex cacosf
7559@findex cacosh
7560@findex cacoshf
7561@findex cacoshl
7562@findex cacosl
32ef1cd2 7563@findex calloc
61b922e7 7564@findex carg
7565@findex cargf
7566@findex cargl
7567@findex casin
7568@findex casinf
7569@findex casinh
7570@findex casinhf
7571@findex casinhl
7572@findex casinl
7573@findex catan
7574@findex catanf
7575@findex catanh
7576@findex catanhf
7577@findex catanhl
7578@findex catanl
e88e2794 7579@findex cbrt
7580@findex cbrtf
7581@findex cbrtl
61b922e7 7582@findex ccos
7583@findex ccosf
7584@findex ccosh
7585@findex ccoshf
7586@findex ccoshl
7587@findex ccosl
982c684c 7588@findex ceil
7589@findex ceilf
7590@findex ceill
61b922e7 7591@findex cexp
7592@findex cexpf
7593@findex cexpl
d30e4d04 7594@findex cimag
7595@findex cimagf
7596@findex cimagl
18c2e7b1 7597@findex clog
7598@findex clogf
7599@findex clogl
d30e4d04 7600@findex conj
7601@findex conjf
7602@findex conjl
e88e2794 7603@findex copysign
7604@findex copysignf
7605@findex copysignl
1f4e0dac 7606@findex cos
7607@findex cosf
e88e2794 7608@findex cosh
7609@findex coshf
7610@findex coshl
1f4e0dac 7611@findex cosl
61b922e7 7612@findex cpow
7613@findex cpowf
7614@findex cpowl
7615@findex cproj
7616@findex cprojf
7617@findex cprojl
d30e4d04 7618@findex creal
7619@findex crealf
7620@findex creall
61b922e7 7621@findex csin
7622@findex csinf
7623@findex csinh
7624@findex csinhf
7625@findex csinhl
7626@findex csinl
7627@findex csqrt
7628@findex csqrtf
7629@findex csqrtl
7630@findex ctan
7631@findex ctanf
7632@findex ctanh
7633@findex ctanhf
7634@findex ctanhl
7635@findex ctanl
b9b15671 7636@findex dcgettext
7637@findex dgettext
e88e2794 7638@findex drem
7639@findex dremf
7640@findex dreml
847749e5 7641@findex erf
7642@findex erfc
7643@findex erfcf
7644@findex erfcl
7645@findex erff
7646@findex erfl
1f4e0dac 7647@findex exit
42721db0 7648@findex exp
e88e2794 7649@findex exp10
7650@findex exp10f
7651@findex exp10l
7652@findex exp2
7653@findex exp2f
7654@findex exp2l
42721db0 7655@findex expf
7656@findex expl
e88e2794 7657@findex expm1
7658@findex expm1f
7659@findex expm1l
1f4e0dac 7660@findex fabs
7661@findex fabsf
7662@findex fabsl
e88e2794 7663@findex fdim
7664@findex fdimf
7665@findex fdiml
1f4e0dac 7666@findex ffs
982c684c 7667@findex floor
7668@findex floorf
7669@findex floorl
e88e2794 7670@findex fma
7671@findex fmaf
7672@findex fmal
7673@findex fmax
7674@findex fmaxf
7675@findex fmaxl
7676@findex fmin
7677@findex fminf
7678@findex fminl
982c684c 7679@findex fmod
7680@findex fmodf
7681@findex fmodl
96df8b77 7682@findex fprintf
c013a46e 7683@findex fprintf_unlocked
1f4e0dac 7684@findex fputs
c013a46e 7685@findex fputs_unlocked
4070bd43 7686@findex frexp
7687@findex frexpf
7688@findex frexpl
b9b15671 7689@findex fscanf
847749e5 7690@findex gamma
7691@findex gammaf
7692@findex gammal
cd2656b0 7693@findex gamma_r
7694@findex gammaf_r
7695@findex gammal_r
b9b15671 7696@findex gettext
e88e2794 7697@findex hypot
7698@findex hypotf
7699@findex hypotl
7700@findex ilogb
7701@findex ilogbf
7702@findex ilogbl
1dfa965e 7703@findex imaxabs
398aae36 7704@findex index
054f84e6 7705@findex isalnum
7706@findex isalpha
7707@findex isascii
7708@findex isblank
7709@findex iscntrl
7710@findex isdigit
7711@findex isgraph
7712@findex islower
7713@findex isprint
7714@findex ispunct
7715@findex isspace
7716@findex isupper
4617d9b5 7717@findex iswalnum
7718@findex iswalpha
7719@findex iswblank
7720@findex iswcntrl
7721@findex iswdigit
7722@findex iswgraph
7723@findex iswlower
7724@findex iswprint
7725@findex iswpunct
7726@findex iswspace
7727@findex iswupper
7728@findex iswxdigit
054f84e6 7729@findex isxdigit
847749e5 7730@findex j0
7731@findex j0f
7732@findex j0l
7733@findex j1
7734@findex j1f
7735@findex j1l
7736@findex jn
7737@findex jnf
7738@findex jnl
1f4e0dac 7739@findex labs
e88e2794 7740@findex ldexp
7741@findex ldexpf
7742@findex ldexpl
847749e5 7743@findex lgamma
7744@findex lgammaf
7745@findex lgammal
cd2656b0 7746@findex lgamma_r
7747@findex lgammaf_r
7748@findex lgammal_r
1f4e0dac 7749@findex llabs
e88e2794 7750@findex llrint
7751@findex llrintf
7752@findex llrintl
7753@findex llround
7754@findex llroundf
7755@findex llroundl
42721db0 7756@findex log
e88e2794 7757@findex log10
7758@findex log10f
7759@findex log10l
7760@findex log1p
7761@findex log1pf
7762@findex log1pl
7763@findex log2
7764@findex log2f
7765@findex log2l
7766@findex logb
7767@findex logbf
7768@findex logbl
42721db0 7769@findex logf
7770@findex logl
e88e2794 7771@findex lrint
7772@findex lrintf
7773@findex lrintl
7774@findex lround
7775@findex lroundf
7776@findex lroundl
32ef1cd2 7777@findex malloc
7959b13b 7778@findex memchr
1f4e0dac 7779@findex memcmp
7780@findex memcpy
3b824fa6 7781@findex mempcpy
1f4e0dac 7782@findex memset
4070bd43 7783@findex modf
7784@findex modff
7785@findex modfl
982c684c 7786@findex nearbyint
7787@findex nearbyintf
7788@findex nearbyintl
e88e2794 7789@findex nextafter
7790@findex nextafterf
7791@findex nextafterl
7792@findex nexttoward
7793@findex nexttowardf
7794@findex nexttowardl
fa426235 7795@findex pow
e88e2794 7796@findex pow10
7797@findex pow10f
7798@findex pow10l
fa426235 7799@findex powf
7800@findex powl
1f4e0dac 7801@findex printf
c013a46e 7802@findex printf_unlocked
03901330 7803@findex putchar
7804@findex puts
e88e2794 7805@findex remainder
7806@findex remainderf
7807@findex remainderl
4070bd43 7808@findex remquo
7809@findex remquof
7810@findex remquol
398aae36 7811@findex rindex
e88e2794 7812@findex rint
7813@findex rintf
7814@findex rintl
982c684c 7815@findex round
7816@findex roundf
7817@findex roundl
e88e2794 7818@findex scalb
7819@findex scalbf
7820@findex scalbl
7821@findex scalbln
7822@findex scalblnf
7823@findex scalblnf
7824@findex scalbn
7825@findex scalbnf
7826@findex scanfnl
27f261ef 7827@findex signbit
7828@findex signbitf
7829@findex signbitl
004e23c4 7830@findex signbitd32
7831@findex signbitd64
7832@findex signbitd128
847749e5 7833@findex significand
7834@findex significandf
7835@findex significandl
1f4e0dac 7836@findex sin
4070bd43 7837@findex sincos
7838@findex sincosf
7839@findex sincosl
1f4e0dac 7840@findex sinf
e88e2794 7841@findex sinh
7842@findex sinhf
7843@findex sinhl
1f4e0dac 7844@findex sinl
03901330 7845@findex snprintf
7846@findex sprintf
1f4e0dac 7847@findex sqrt
7848@findex sqrtf
7849@findex sqrtl
03901330 7850@findex sscanf
3b824fa6 7851@findex stpcpy
989d048f 7852@findex stpncpy
7853@findex strcasecmp
49f0327b 7854@findex strcat
1f4e0dac 7855@findex strchr
7856@findex strcmp
7857@findex strcpy
49f0327b 7858@findex strcspn
32ef1cd2 7859@findex strdup
b9b15671 7860@findex strfmon
7861@findex strftime
1f4e0dac 7862@findex strlen
989d048f 7863@findex strncasecmp
49f0327b 7864@findex strncat
ed09096d 7865@findex strncmp
7866@findex strncpy
989d048f 7867@findex strndup
1f4e0dac 7868@findex strpbrk
7869@findex strrchr
49f0327b 7870@findex strspn
1f4e0dac 7871@findex strstr
a2246f84 7872@findex tan
7873@findex tanf
e88e2794 7874@findex tanh
7875@findex tanhf
7876@findex tanhl
a2246f84 7877@findex tanl
847749e5 7878@findex tgamma
7879@findex tgammaf
7880@findex tgammal
054f84e6 7881@findex toascii
7882@findex tolower
7883@findex toupper
4617d9b5 7884@findex towlower
7885@findex towupper
805e22b2 7886@findex trunc
7887@findex truncf
7888@findex truncl
b9b15671 7889@findex vfprintf
7890@findex vfscanf
03901330 7891@findex vprintf
7892@findex vscanf
7893@findex vsnprintf
7894@findex vsprintf
7895@findex vsscanf
847749e5 7896@findex y0
7897@findex y0f
7898@findex y0l
7899@findex y1
7900@findex y1f
7901@findex y1l
7902@findex yn
7903@findex ynf
7904@findex ynl
2c776a54 7905
37744367 7906GCC provides a large number of built-in functions other than the ones
2c776a54 7907mentioned above. Some of these are for internal use in the processing
7908of exceptions or variable-length argument lists and will not be
7909documented here because they may change from time to time; we do not
7910recommend general use of these functions.
7911
7912The remaining functions are provided for optimization purposes.
7913
67791935 7914@opindex fno-builtin
0fff59be 7915GCC includes built-in versions of many of the functions in the standard
7916C library. The versions prefixed with @code{__builtin_} will always be
7917treated as having the same meaning as the C library function even if you
b3d47662 7918specify the @option{-fno-builtin} option. (@pxref{C Dialect Options})
0fff59be 7919Many of these functions are only optimized in certain cases; if they are
1f4e0dac 7920not optimized in a particular case, a call to the library function will
7921be emitted.
7922
67791935 7923@opindex ansi
7924@opindex std
39012afb 7925Outside strict ISO C mode (@option{-ansi}, @option{-std=c90},
32074525 7926@option{-std=c99} or @option{-std=c11}), the functions
e88e2794 7927@code{_exit}, @code{alloca}, @code{bcmp}, @code{bzero},
7928@code{dcgettext}, @code{dgettext}, @code{dremf}, @code{dreml},
7929@code{drem}, @code{exp10f}, @code{exp10l}, @code{exp10}, @code{ffsll},
cd2656b0 7930@code{ffsl}, @code{ffs}, @code{fprintf_unlocked},
7931@code{fputs_unlocked}, @code{gammaf}, @code{gammal}, @code{gamma},
7932@code{gammaf_r}, @code{gammal_r}, @code{gamma_r}, @code{gettext},
054f84e6 7933@code{index}, @code{isascii}, @code{j0f}, @code{j0l}, @code{j0},
7934@code{j1f}, @code{j1l}, @code{j1}, @code{jnf}, @code{jnl}, @code{jn},
cd2656b0 7935@code{lgammaf_r}, @code{lgammal_r}, @code{lgamma_r}, @code{mempcpy},
7936@code{pow10f}, @code{pow10l}, @code{pow10}, @code{printf_unlocked},
7937@code{rindex}, @code{scalbf}, @code{scalbl}, @code{scalb},
7938@code{signbit}, @code{signbitf}, @code{signbitl}, @code{signbitd32},
7939@code{signbitd64}, @code{signbitd128}, @code{significandf},
7940@code{significandl}, @code{significand}, @code{sincosf},
7941@code{sincosl}, @code{sincos}, @code{stpcpy}, @code{stpncpy},
7942@code{strcasecmp}, @code{strdup}, @code{strfmon}, @code{strncasecmp},
7943@code{strndup}, @code{toascii}, @code{y0f}, @code{y0l}, @code{y0},
7944@code{y1f}, @code{y1l}, @code{y1}, @code{ynf}, @code{ynl} and
7945@code{yn}
32ef1cd2 7946may be handled as built-in functions.
982c684c 7947All these functions have corresponding versions
32f1f35b 7948prefixed with @code{__builtin_}, which may be used even in strict C90
0fff59be 7949mode.
1f4e0dac 7950
78a74442 7951The ISO C99 functions
e88e2794 7952@code{_Exit}, @code{acoshf}, @code{acoshl}, @code{acosh}, @code{asinhf},
7953@code{asinhl}, @code{asinh}, @code{atanhf}, @code{atanhl}, @code{atanh},
61b922e7 7954@code{cabsf}, @code{cabsl}, @code{cabs}, @code{cacosf}, @code{cacoshf},
7955@code{cacoshl}, @code{cacosh}, @code{cacosl}, @code{cacos},
7956@code{cargf}, @code{cargl}, @code{carg}, @code{casinf}, @code{casinhf},
7957@code{casinhl}, @code{casinh}, @code{casinl}, @code{casin},
7958@code{catanf}, @code{catanhf}, @code{catanhl}, @code{catanh},
7959@code{catanl}, @code{catan}, @code{cbrtf}, @code{cbrtl}, @code{cbrt},
7960@code{ccosf}, @code{ccoshf}, @code{ccoshl}, @code{ccosh}, @code{ccosl},
7961@code{ccos}, @code{cexpf}, @code{cexpl}, @code{cexp}, @code{cimagf},
18c2e7b1 7962@code{cimagl}, @code{cimag}, @code{clogf}, @code{clogl}, @code{clog},
7963@code{conjf}, @code{conjl}, @code{conj}, @code{copysignf}, @code{copysignl},
7964@code{copysign}, @code{cpowf}, @code{cpowl}, @code{cpow}, @code{cprojf},
7965@code{cprojl}, @code{cproj}, @code{crealf}, @code{creall}, @code{creal},
7966@code{csinf}, @code{csinhf}, @code{csinhl}, @code{csinh}, @code{csinl},
7967@code{csin}, @code{csqrtf}, @code{csqrtl}, @code{csqrt}, @code{ctanf},
7968@code{ctanhf}, @code{ctanhl}, @code{ctanh}, @code{ctanl}, @code{ctan},
7969@code{erfcf}, @code{erfcl}, @code{erfc}, @code{erff}, @code{erfl},
7970@code{erf}, @code{exp2f}, @code{exp2l}, @code{exp2}, @code{expm1f},
7971@code{expm1l}, @code{expm1}, @code{fdimf}, @code{fdiml}, @code{fdim},
7972@code{fmaf}, @code{fmal}, @code{fmaxf}, @code{fmaxl}, @code{fmax},
7973@code{fma}, @code{fminf}, @code{fminl}, @code{fmin}, @code{hypotf},
7974@code{hypotl}, @code{hypot}, @code{ilogbf}, @code{ilogbl}, @code{ilogb},
7975@code{imaxabs}, @code{isblank}, @code{iswblank}, @code{lgammaf},
7976@code{lgammal}, @code{lgamma}, @code{llabs}, @code{llrintf}, @code{llrintl},
4617d9b5 7977@code{llrint}, @code{llroundf}, @code{llroundl}, @code{llround},
7978@code{log1pf}, @code{log1pl}, @code{log1p}, @code{log2f}, @code{log2l},
7979@code{log2}, @code{logbf}, @code{logbl}, @code{logb}, @code{lrintf},
7980@code{lrintl}, @code{lrint}, @code{lroundf}, @code{lroundl},
7981@code{lround}, @code{nearbyintf}, @code{nearbyintl}, @code{nearbyint},
054f84e6 7982@code{nextafterf}, @code{nextafterl}, @code{nextafter},
7983@code{nexttowardf}, @code{nexttowardl}, @code{nexttoward},
7984@code{remainderf}, @code{remainderl}, @code{remainder}, @code{remquof},
7985@code{remquol}, @code{remquo}, @code{rintf}, @code{rintl}, @code{rint},
7986@code{roundf}, @code{roundl}, @code{round}, @code{scalblnf},
7987@code{scalblnl}, @code{scalbln}, @code{scalbnf}, @code{scalbnl},
7988@code{scalbn}, @code{snprintf}, @code{tgammaf}, @code{tgammal},
7989@code{tgamma}, @code{truncf}, @code{truncl}, @code{trunc},
7990@code{vfscanf}, @code{vscanf}, @code{vsnprintf} and @code{vsscanf}
03901330 7991are handled as built-in functions
32f1f35b 7992except in strict ISO C90 mode (@option{-ansi} or @option{-std=c90}).
fa426235 7993
e88e2794 7994There are also built-in versions of the ISO C99 functions
7995@code{acosf}, @code{acosl}, @code{asinf}, @code{asinl}, @code{atan2f},
a2246f84 7996@code{atan2l}, @code{atanf}, @code{atanl}, @code{ceilf}, @code{ceill},
e88e2794 7997@code{cosf}, @code{coshf}, @code{coshl}, @code{cosl}, @code{expf},
7998@code{expl}, @code{fabsf}, @code{fabsl}, @code{floorf}, @code{floorl},
4070bd43 7999@code{fmodf}, @code{fmodl}, @code{frexpf}, @code{frexpl}, @code{ldexpf},
8000@code{ldexpl}, @code{log10f}, @code{log10l}, @code{logf}, @code{logl},
8001@code{modfl}, @code{modf}, @code{powf}, @code{powl}, @code{sinf},
8002@code{sinhf}, @code{sinhl}, @code{sinl}, @code{sqrtf}, @code{sqrtl},
8003@code{tanf}, @code{tanhf}, @code{tanhl} and @code{tanl}
fa426235 8004that are recognized in any mode since ISO C90 reserves these names for
8005the purpose to which ISO C99 puts them. All these functions have
8006corresponding versions prefixed with @code{__builtin_}.
8007
4617d9b5 8008The ISO C94 functions
8009@code{iswalnum}, @code{iswalpha}, @code{iswcntrl}, @code{iswdigit},
8010@code{iswgraph}, @code{iswlower}, @code{iswprint}, @code{iswpunct},
8011@code{iswspace}, @code{iswupper}, @code{iswxdigit}, @code{towlower} and
8012@code{towupper}
8013are handled as built-in functions
32f1f35b 8014except in strict ISO C90 mode (@option{-ansi} or @option{-std=c90}).
4617d9b5 8015
e88e2794 8016The ISO C90 functions
8017@code{abort}, @code{abs}, @code{acos}, @code{asin}, @code{atan2},
8018@code{atan}, @code{calloc}, @code{ceil}, @code{cosh}, @code{cos},
8019@code{exit}, @code{exp}, @code{fabs}, @code{floor}, @code{fmod},
054f84e6 8020@code{fprintf}, @code{fputs}, @code{frexp}, @code{fscanf},
8021@code{isalnum}, @code{isalpha}, @code{iscntrl}, @code{isdigit},
8022@code{isgraph}, @code{islower}, @code{isprint}, @code{ispunct},
8023@code{isspace}, @code{isupper}, @code{isxdigit}, @code{tolower},
8024@code{toupper}, @code{labs}, @code{ldexp}, @code{log10}, @code{log},
7959b13b 8025@code{malloc}, @code{memchr}, @code{memcmp}, @code{memcpy},
8026@code{memset}, @code{modf}, @code{pow}, @code{printf}, @code{putchar},
8027@code{puts}, @code{scanf}, @code{sinh}, @code{sin}, @code{snprintf},
8028@code{sprintf}, @code{sqrt}, @code{sscanf}, @code{strcat},
8029@code{strchr}, @code{strcmp}, @code{strcpy}, @code{strcspn},
8030@code{strlen}, @code{strncat}, @code{strncmp}, @code{strncpy},
8031@code{strpbrk}, @code{strrchr}, @code{strspn}, @code{strstr},
8032@code{tanh}, @code{tan}, @code{vfprintf}, @code{vprintf} and @code{vsprintf}
03901330 8033are all recognized as built-in functions unless
fa426235 8034@option{-fno-builtin} is specified (or @option{-fno-builtin-@var{function}}
8035is specified for an individual function). All of these functions have
805e22b2 8036corresponding versions prefixed with @code{__builtin_}.
0fff59be 8037
8038GCC provides built-in versions of the ISO C99 floating point comparison
8039macros that avoid raising exceptions for unordered operands. They have
8040the same names as the standard macros ( @code{isgreater},
8041@code{isgreaterequal}, @code{isless}, @code{islessequal},
8042@code{islessgreater}, and @code{isunordered}) , with @code{__builtin_}
8043prefixed. We intend for a library implementor to be able to simply
8044@code{#define} each standard macro to its built-in equivalent.
19fbe3a4 8045In the same fashion, GCC provides @code{fpclassify}, @code{isfinite},
8046@code{isinf_sign} and @code{isnormal} built-ins used with
8047@code{__builtin_} prefixed. The @code{isinf} and @code{isnan}
8048builtins appear both with and without the @code{__builtin_} prefix.
2c776a54 8049
acb6974b 8050@deftypefn {Built-in Function} int __builtin_types_compatible_p (@var{type1}, @var{type2})
8051
8052You can use the built-in function @code{__builtin_types_compatible_p} to
8053determine whether two types are the same.
8054
8055This built-in function returns 1 if the unqualified versions of the
8056types @var{type1} and @var{type2} (which are types, not expressions) are
8057compatible, 0 otherwise. The result of this built-in function can be
8058used in integer constant expressions.
8059
8060This built-in function ignores top level qualifiers (e.g., @code{const},
8061@code{volatile}). For example, @code{int} is equivalent to @code{const
8062int}.
8063
8064The type @code{int[]} and @code{int[5]} are compatible. On the other
8065hand, @code{int} and @code{char *} are not compatible, even if the size
8066of their types, on the particular architecture are the same. Also, the
8067amount of pointer indirection is taken into account when determining
8068similarity. Consequently, @code{short *} is not similar to
8069@code{short **}. Furthermore, two types that are typedefed are
8070considered compatible if their underlying types are compatible.
8071
09e0a2a1 8072An @code{enum} type is not considered to be compatible with another
8073@code{enum} type even if both are compatible with the same integer
8074type; this is what the C standard specifies.
8075For example, @code{enum @{foo, bar@}} is not similar to
acb6974b 8076@code{enum @{hot, dog@}}.
8077
8078You would typically use this function in code whose execution varies
8079depending on the arguments' types. For example:
8080
8081@smallexample
8e1103d3 8082#define foo(x) \
8083 (@{ \
57bcf24d 8084 typeof (x) tmp = (x); \
8e1103d3 8085 if (__builtin_types_compatible_p (typeof (x), long double)) \
8086 tmp = foo_long_double (tmp); \
8087 else if (__builtin_types_compatible_p (typeof (x), double)) \
8088 tmp = foo_double (tmp); \
8089 else if (__builtin_types_compatible_p (typeof (x), float)) \
8090 tmp = foo_float (tmp); \
8091 else \
8092 abort (); \
8093 tmp; \
acb6974b 8094 @})
8095@end smallexample
8096
b3d47662 8097@emph{Note:} This construct is only available for C@.
acb6974b 8098
8099@end deftypefn
8100
8101@deftypefn {Built-in Function} @var{type} __builtin_choose_expr (@var{const_exp}, @var{exp1}, @var{exp2})
8102
8103You can use the built-in function @code{__builtin_choose_expr} to
8104evaluate code depending on the value of a constant expression. This
a75b1c71 8105built-in function returns @var{exp1} if @var{const_exp}, which is an
bcd71332 8106integer constant expression, is nonzero. Otherwise it returns @var{exp2}.
acb6974b 8107
8108This built-in function is analogous to the @samp{? :} operator in C,
8109except that the expression returned has its type unaltered by promotion
8110rules. Also, the built-in function does not evaluate the expression
8111that was not chosen. For example, if @var{const_exp} evaluates to true,
8112@var{exp2} is not evaluated even if it has side-effects.
8113
8114This built-in function can return an lvalue if the chosen argument is an
8115lvalue.
8116
8117If @var{exp1} is returned, the return type is the same as @var{exp1}'s
8118type. Similarly, if @var{exp2} is returned, its return type is the same
8119as @var{exp2}.
8120
8121Example:
8122
8123@smallexample
b724fad7 8124#define foo(x) \
8125 __builtin_choose_expr ( \
8126 __builtin_types_compatible_p (typeof (x), double), \
8127 foo_double (x), \
8128 __builtin_choose_expr ( \
8129 __builtin_types_compatible_p (typeof (x), float), \
8130 foo_float (x), \
8131 /* @r{The void expression results in a compile-time error} \
8132 @r{when assigning the result to something.} */ \
acb6974b 8133 (void)0))
8134@end smallexample
8135
b3d47662 8136@emph{Note:} This construct is only available for C@. Furthermore, the
acb6974b 8137unused expression (@var{exp1} or @var{exp2} depending on the value of
8138@var{const_exp}) may still generate syntax errors. This may change in
8139future revisions.
8140
8141@end deftypefn
8142
bff4ad11 8143@deftypefn {Built-in Function} @var{type} __builtin_complex (@var{real}, @var{imag})
8144
8145The built-in function @code{__builtin_complex} is provided for use in
32074525 8146implementing the ISO C11 macros @code{CMPLXF}, @code{CMPLX} and
bff4ad11 8147@code{CMPLXL}. @var{real} and @var{imag} must have the same type, a
8148real binary floating-point type, and the result has the corresponding
8149complex type with real and imaginary parts @var{real} and @var{imag}.
8150Unlike @samp{@var{real} + I * @var{imag}}, this works even when
8151infinities, NaNs and negative zeros are involved.
8152
8153@end deftypefn
8154
67791935 8155@deftypefn {Built-in Function} int __builtin_constant_p (@var{exp})
8156You can use the built-in function @code{__builtin_constant_p} to
2c776a54 8157determine if a value is known to be constant at compile-time and hence
37744367 8158that GCC can perform constant-folding on expressions involving that
2c776a54 8159value. The argument of the function is the value to test. The function
8160returns the integer 1 if the argument is known to be a compile-time
8161constant and 0 if it is not known to be a compile-time constant. A
8162return of 0 does not indicate that the value is @emph{not} a constant,
37744367 8163but merely that GCC cannot prove it is a constant with the specified
67791935 8164value of the @option{-O} option.
2c776a54 8165
8166You would typically use this function in an embedded application where
8167memory was a critical resource. If you have some complex calculation,
8168you may want it to be folded if it involves constants, but need to call
8169a function if it does not. For example:
8170
6e894357 8171@smallexample
d90db7dc 8172#define Scale_Value(X) \
8173 (__builtin_constant_p (X) \
8174 ? ((X) * SCALE + OFFSET) : Scale (X))
2c776a54 8175@end smallexample
8176
67791935 8177You may use this built-in function in either a macro or an inline
2c776a54 8178function. However, if you use it in an inlined function and pass an
37744367 8179argument of the function as the argument to the built-in, GCC will
2c776a54 8180never return 1 when you call the inline function with a string constant
3cfa0cc4 8181or compound literal (@pxref{Compound Literals}) and will not return 1
2c776a54 8182when you pass a constant numeric value to the inline function unless you
67791935 8183specify the @option{-O} option.
f97c71a1 8184
8185You may also use @code{__builtin_constant_p} in initializers for static
8186data. For instance, you can write
8187
8188@smallexample
c371393a 8189static const int table[] = @{
f97c71a1 8190 __builtin_constant_p (EXPRESSION) ? (EXPRESSION) : -1,
4ae74ddd 8191 /* @r{@dots{}} */
c371393a 8192@};
f97c71a1 8193@end smallexample
8194
8195@noindent
8196This is an acceptable initializer even if @var{EXPRESSION} is not a
a75b1c71 8197constant expression, including the case where
8198@code{__builtin_constant_p} returns 1 because @var{EXPRESSION} can be
8199folded to a constant but @var{EXPRESSION} contains operands that would
d270ac20 8200not otherwise be permitted in a static initializer (for example,
a75b1c71 8201@code{0 && foo ()}). GCC must be more conservative about evaluating the
f97c71a1 8202built-in in this case, because it has no opportunity to perform
8203optimization.
8204
8205Previous versions of GCC did not accept this built-in in data
8206initializers. The earliest version where it is completely safe is
82073.0.1.
67791935 8208@end deftypefn
2c776a54 8209
67791935 8210@deftypefn {Built-in Function} long __builtin_expect (long @var{exp}, long @var{c})
8211@opindex fprofile-arcs
3b0848a2 8212You may use @code{__builtin_expect} to provide the compiler with
89cfe6e5 8213branch prediction information. In general, you should prefer to
67791935 8214use actual profile feedback for this (@option{-fprofile-arcs}), as
89cfe6e5 8215programmers are notoriously bad at predicting how their programs
def8652b 8216actually perform. However, there are applications in which this
89cfe6e5 8217data is hard to collect.
8218
5a74f77e 8219The return value is the value of @var{exp}, which should be an integral
8220expression. The semantics of the built-in are that it is expected that
8221@var{exp} == @var{c}. For example:
89cfe6e5 8222
8223@smallexample
8224if (__builtin_expect (x, 0))
8225 foo ();
8226@end smallexample
8227
8228@noindent
8229would indicate that we do not expect to call @code{foo}, since
8230we expect @code{x} to be zero. Since you are limited to integral
8231expressions for @var{exp}, you should use constructions such as
8232
8233@smallexample
8234if (__builtin_expect (ptr != NULL, 1))
64382d5f 8235 foo (*ptr);
89cfe6e5 8236@end smallexample
8237
8238@noindent
8239when testing pointer or floating-point values.
67791935 8240@end deftypefn
89cfe6e5 8241
2f5beddc 8242@deftypefn {Built-in Function} void __builtin_trap (void)
8243This function causes the program to exit abnormally. GCC implements
8244this function by using a target-dependent mechanism (such as
8245intentionally executing an illegal instruction) or by calling
8246@code{abort}. The mechanism used may vary from release to release so
8247you should not rely on any particular implementation.
8248@end deftypefn
8249
d2b48f0c 8250@deftypefn {Built-in Function} void __builtin_unreachable (void)
8251If control flow reaches the point of the @code{__builtin_unreachable},
8252the program is undefined. It is useful in situations where the
8253compiler cannot deduce the unreachability of the code.
8254
8255One such case is immediately following an @code{asm} statement that
8256will either never terminate, or one that transfers control elsewhere
8257and never returns. In this example, without the
8258@code{__builtin_unreachable}, GCC would issue a warning that control
8259reaches the end of a non-void function. It would also generate code
8260to return after the @code{asm}.
8261
8262@smallexample
8263int f (int c, int v)
8264@{
8265 if (c)
8266 @{
8267 return v;
8268 @}
8269 else
8270 @{
8271 asm("jmp error_handler");
8272 __builtin_unreachable ();
8273 @}
8274@}
8275@end smallexample
8276
8277Because the @code{asm} statement unconditionally transfers control out
8278of the function, control will never reach the end of the function
8279body. The @code{__builtin_unreachable} is in fact unreachable and
8280communicates this fact to the compiler.
8281
8282Another use for @code{__builtin_unreachable} is following a call a
8283function that never returns but that is not declared
8284@code{__attribute__((noreturn))}, as in this example:
8285
8286@smallexample
8287void function_that_never_returns (void);
8288
8289int g (int c)
8290@{
8291 if (c)
8292 @{
8293 return 1;
8294 @}
8295 else
8296 @{
8297 function_that_never_returns ();
8298 __builtin_unreachable ();
8299 @}
8300@}
8301@end smallexample
8302
8303@end deftypefn
8304
fca0886c 8305@deftypefn {Built-in Function} void *__builtin_assume_aligned (const void *@var{exp}, size_t @var{align}, ...)
8306This function returns its first argument, and allows the compiler
8307to assume that the returned pointer is at least @var{align} bytes
8308aligned. This built-in can have either two or three arguments,
8309if it has three, the third argument should have integer type, and
8310if it is non-zero means misalignment offset. For example:
8311
8312@smallexample
8313void *x = __builtin_assume_aligned (arg, 16);
8314@end smallexample
8315
8316means that the compiler can assume x, set to arg, is at least
831716 byte aligned, while:
8318
8319@smallexample
8320void *x = __builtin_assume_aligned (arg, 32, 8);
8321@end smallexample
8322
8323means that the compiler can assume for x, set to arg, that
8324(char *) x - 8 is 32 byte aligned.
8325@end deftypefn
8326
8b76fbe9 8327@deftypefn {Built-in Function} int __builtin_LINE ()
8328This function is the equivalent to the preprocessor @code{__LINE__}
8329macro and returns the line number of the invocation of the built-in.
8330@end deftypefn
8331
8332@deftypefn {Built-in Function} int __builtin_FUNCTION ()
8333This function is the equivalent to the preprocessor @code{__FUNCTION__}
8334macro and returns the function name the invocation of the built-in is in.
8335@end deftypefn
8336
8337@deftypefn {Built-in Function} int __builtin_FILE ()
8338This function is the equivalent to the preprocessor @code{__FILE__}
8339macro and returns the file name the invocation of the built-in is in.
8340@end deftypefn
8341
ac8fb6db 8342@deftypefn {Built-in Function} void __builtin___clear_cache (char *@var{begin}, char *@var{end})
8343This function is used to flush the processor's instruction cache for
8344the region of memory between @var{begin} inclusive and @var{end}
8345exclusive. Some targets require that the instruction cache be
8346flushed, after modifying memory containing code, in order to obtain
8347deterministic behavior.
8348
8349If the target does not require instruction cache flushes,
8350@code{__builtin___clear_cache} has no effect. Otherwise either
8351instructions are emitted in-line to clear the instruction cache or a
8352call to the @code{__clear_cache} function in libgcc is made.
8353@end deftypefn
8354
82086392 8355@deftypefn {Built-in Function} void __builtin_prefetch (const void *@var{addr}, ...)
5e3608d8 8356This function is used to minimize cache-miss latency by moving data into
8357a cache before it is accessed.
8358You can insert calls to @code{__builtin_prefetch} into code for which
8359you know addresses of data in memory that is likely to be accessed soon.
8360If the target supports them, data prefetch instructions will be generated.
8361If the prefetch is done early enough before the access then the data will
8362be in the cache by the time it is accessed.
8363
8364The value of @var{addr} is the address of the memory to prefetch.
26a5cadb 8365There are two optional arguments, @var{rw} and @var{locality}.
5e3608d8 8366The value of @var{rw} is a compile-time constant one or zero; one
26a5cadb 8367means that the prefetch is preparing for a write to the memory address
8368and zero, the default, means that the prefetch is preparing for a read.
5e3608d8 8369The value @var{locality} must be a compile-time constant integer between
8370zero and three. A value of zero means that the data has no temporal
8371locality, so it need not be left in the cache after the access. A value
8372of three means that the data has a high degree of temporal locality and
8373should be left in all levels of cache possible. Values of one and two
26a5cadb 8374mean, respectively, a low or moderate degree of temporal locality. The
8375default is three.
5e3608d8 8376
8377@smallexample
8378for (i = 0; i < n; i++)
8379 @{
8380 a[i] = a[i] + b[i];
8381 __builtin_prefetch (&a[i+j], 1, 1);
8382 __builtin_prefetch (&b[i+j], 0, 1);
4ae74ddd 8383 /* @r{@dots{}} */
5e3608d8 8384 @}
8385@end smallexample
8386
228c5b30 8387Data prefetch does not generate faults if @var{addr} is invalid, but
5e3608d8 8388the address expression itself must be valid. For example, a prefetch
8389of @code{p->next} will not fault if @code{p->next} is not a valid
8390address, but evaluation will fault if @code{p} is not a valid address.
8391
8392If the target does not support data prefetch, the address expression
8393is evaluated if it includes side effects but no other code is generated
8394and GCC does not issue a warning.
8395@end deftypefn
8396
92c43e3c 8397@deftypefn {Built-in Function} double __builtin_huge_val (void)
8398Returns a positive infinity, if supported by the floating-point format,
8399else @code{DBL_MAX}. This function is suitable for implementing the
8400ISO C macro @code{HUGE_VAL}.
8401@end deftypefn
8402
8403@deftypefn {Built-in Function} float __builtin_huge_valf (void)
8404Similar to @code{__builtin_huge_val}, except the return type is @code{float}.
8405@end deftypefn
8406
a5285cd3 8407@deftypefn {Built-in Function} {long double} __builtin_huge_vall (void)
92c43e3c 8408Similar to @code{__builtin_huge_val}, except the return
8409type is @code{long double}.
8410@end deftypefn
8411
19fbe3a4 8412@deftypefn {Built-in Function} int __builtin_fpclassify (int, int, int, int, int, ...)
8413This built-in implements the C99 fpclassify functionality. The first
8414five int arguments should be the target library's notion of the
8415possible FP classes and are used for return values. They must be
8416constant values and they must appear in this order: @code{FP_NAN},
921b27c0 8417@code{FP_INFINITE}, @code{FP_NORMAL}, @code{FP_SUBNORMAL} and
19fbe3a4 8418@code{FP_ZERO}. The ellipsis is for exactly one floating point value
8419to classify. GCC treats the last argument as type-generic, which
8420means it does not do default promotion from float to double.
8421@end deftypefn
8422
92c43e3c 8423@deftypefn {Built-in Function} double __builtin_inf (void)
8424Similar to @code{__builtin_huge_val}, except a warning is generated
8425if the target floating-point format does not support infinities.
92c43e3c 8426@end deftypefn
8427
c4503c0a 8428@deftypefn {Built-in Function} _Decimal32 __builtin_infd32 (void)
8429Similar to @code{__builtin_inf}, except the return type is @code{_Decimal32}.
8430@end deftypefn
8431
8432@deftypefn {Built-in Function} _Decimal64 __builtin_infd64 (void)
8433Similar to @code{__builtin_inf}, except the return type is @code{_Decimal64}.
8434@end deftypefn
8435
8436@deftypefn {Built-in Function} _Decimal128 __builtin_infd128 (void)
8437Similar to @code{__builtin_inf}, except the return type is @code{_Decimal128}.
8438@end deftypefn
8439
92c43e3c 8440@deftypefn {Built-in Function} float __builtin_inff (void)
8441Similar to @code{__builtin_inf}, except the return type is @code{float}.
5cbfa3ba 8442This function is suitable for implementing the ISO C99 macro @code{INFINITY}.
92c43e3c 8443@end deftypefn
8444
a5285cd3 8445@deftypefn {Built-in Function} {long double} __builtin_infl (void)
92c43e3c 8446Similar to @code{__builtin_inf}, except the return
8447type is @code{long double}.
8448@end deftypefn
8449
c319d56a 8450@deftypefn {Built-in Function} int __builtin_isinf_sign (...)
8451Similar to @code{isinf}, except the return value will be negative for
8452an argument of @code{-Inf}. Note while the parameter list is an
8453ellipsis, this function only accepts exactly one floating point
8454argument. GCC treats this parameter as type-generic, which means it
8455does not do default promotion from float to double.
8456@end deftypefn
8457
b0db7939 8458@deftypefn {Built-in Function} double __builtin_nan (const char *str)
8459This is an implementation of the ISO C99 function @code{nan}.
8460
8461Since ISO C99 defines this function in terms of @code{strtod}, which we
a99e98db 8462do not implement, a description of the parsing is in order. The string
b0db7939 8463is parsed as by @code{strtol}; that is, the base is recognized by
8464leading @samp{0} or @samp{0x} prefixes. The number parsed is placed
8465in the significand such that the least significant bit of the number
7a0ad664 8466is at the least significant bit of the significand. The number is
b0db7939 8467truncated to fit the significand field provided. The significand is
b3d47662 8468forced to be a quiet NaN@.
b0db7939 8469
87ea783a 8470This function, if given a string literal all of which would have been
8471consumed by strtol, is evaluated early enough that it is considered a
8472compile-time constant.
b0db7939 8473@end deftypefn
8474
c4503c0a 8475@deftypefn {Built-in Function} _Decimal32 __builtin_nand32 (const char *str)
8476Similar to @code{__builtin_nan}, except the return type is @code{_Decimal32}.
8477@end deftypefn
8478
8479@deftypefn {Built-in Function} _Decimal64 __builtin_nand64 (const char *str)
8480Similar to @code{__builtin_nan}, except the return type is @code{_Decimal64}.
8481@end deftypefn
8482
8483@deftypefn {Built-in Function} _Decimal128 __builtin_nand128 (const char *str)
8484Similar to @code{__builtin_nan}, except the return type is @code{_Decimal128}.
8485@end deftypefn
8486
b0db7939 8487@deftypefn {Built-in Function} float __builtin_nanf (const char *str)
8488Similar to @code{__builtin_nan}, except the return type is @code{float}.
8489@end deftypefn
8490
a5285cd3 8491@deftypefn {Built-in Function} {long double} __builtin_nanl (const char *str)
b0db7939 8492Similar to @code{__builtin_nan}, except the return type is @code{long double}.
8493@end deftypefn
8494
8495@deftypefn {Built-in Function} double __builtin_nans (const char *str)
7a0ad664 8496Similar to @code{__builtin_nan}, except the significand is forced
b3d47662 8497to be a signaling NaN@. The @code{nans} function is proposed by
97ef626f 8498@uref{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n965.htm,,WG14 N965}.
b0db7939 8499@end deftypefn
8500
8501@deftypefn {Built-in Function} float __builtin_nansf (const char *str)
8502Similar to @code{__builtin_nans}, except the return type is @code{float}.
8503@end deftypefn
8504
a5285cd3 8505@deftypefn {Built-in Function} {long double} __builtin_nansl (const char *str)
b0db7939 8506Similar to @code{__builtin_nans}, except the return type is @code{long double}.
8507@end deftypefn
8508
6a08d0ab 8509@deftypefn {Built-in Function} int __builtin_ffs (unsigned int x)
8510Returns one plus the index of the least significant 1-bit of @var{x}, or
8511if @var{x} is zero, returns zero.
8512@end deftypefn
8513
8514@deftypefn {Built-in Function} int __builtin_clz (unsigned int x)
8515Returns the number of leading 0-bits in @var{x}, starting at the most
8516significant bit position. If @var{x} is 0, the result is undefined.
8517@end deftypefn
8518
8519@deftypefn {Built-in Function} int __builtin_ctz (unsigned int x)
8520Returns the number of trailing 0-bits in @var{x}, starting at the least
8521significant bit position. If @var{x} is 0, the result is undefined.
8522@end deftypefn
8523
d8492bd3 8524@deftypefn {Built-in Function} int __builtin_clrsb (int x)
8525Returns the number of leading redundant sign bits in @var{x}, i.e. the
8526number of bits following the most significant bit which are identical
8527to it. There are no special cases for 0 or other values.
8528@end deftypefn
8529
6a08d0ab 8530@deftypefn {Built-in Function} int __builtin_popcount (unsigned int x)
8531Returns the number of 1-bits in @var{x}.
8532@end deftypefn
8533
8534@deftypefn {Built-in Function} int __builtin_parity (unsigned int x)
b3d47662 8535Returns the parity of @var{x}, i.e.@: the number of 1-bits in @var{x}
6a08d0ab 8536modulo 2.
8537@end deftypefn
8538
8539@deftypefn {Built-in Function} int __builtin_ffsl (unsigned long)
8540Similar to @code{__builtin_ffs}, except the argument type is
8541@code{unsigned long}.
8542@end deftypefn
8543
8544@deftypefn {Built-in Function} int __builtin_clzl (unsigned long)
8545Similar to @code{__builtin_clz}, except the argument type is
8546@code{unsigned long}.
8547@end deftypefn
8548
8549@deftypefn {Built-in Function} int __builtin_ctzl (unsigned long)
8550Similar to @code{__builtin_ctz}, except the argument type is
8551@code{unsigned long}.
8552@end deftypefn
8553
d8492bd3 8554@deftypefn {Built-in Function} int __builtin_clrsbl (long)
8555Similar to @code{__builtin_clrsb}, except the argument type is
8556@code{long}.
8557@end deftypefn
8558
6a08d0ab 8559@deftypefn {Built-in Function} int __builtin_popcountl (unsigned long)
8560Similar to @code{__builtin_popcount}, except the argument type is
8561@code{unsigned long}.
8562@end deftypefn
8563
8564@deftypefn {Built-in Function} int __builtin_parityl (unsigned long)
8565Similar to @code{__builtin_parity}, except the argument type is
8566@code{unsigned long}.
8567@end deftypefn
8568
8569@deftypefn {Built-in Function} int __builtin_ffsll (unsigned long long)
8570Similar to @code{__builtin_ffs}, except the argument type is
8571@code{unsigned long long}.
8572@end deftypefn
8573
8574@deftypefn {Built-in Function} int __builtin_clzll (unsigned long long)
8575Similar to @code{__builtin_clz}, except the argument type is
8576@code{unsigned long long}.
8577@end deftypefn
8578
8579@deftypefn {Built-in Function} int __builtin_ctzll (unsigned long long)
8580Similar to @code{__builtin_ctz}, except the argument type is
8581@code{unsigned long long}.
8582@end deftypefn
8583
d8492bd3 8584@deftypefn {Built-in Function} int __builtin_clrsbll (long long)
8585Similar to @code{__builtin_clrsb}, except the argument type is
8586@code{long long}.
8587@end deftypefn
8588
6a08d0ab 8589@deftypefn {Built-in Function} int __builtin_popcountll (unsigned long long)
8590Similar to @code{__builtin_popcount}, except the argument type is
8591@code{unsigned long long}.
8592@end deftypefn
8593
8594@deftypefn {Built-in Function} int __builtin_parityll (unsigned long long)
8595Similar to @code{__builtin_parity}, except the argument type is
8596@code{unsigned long long}.
8597@end deftypefn
8598
757c219d 8599@deftypefn {Built-in Function} double __builtin_powi (double, int)
8600Returns the first argument raised to the power of the second. Unlike the
8601@code{pow} function no guarantees about precision and rounding are made.
8602@end deftypefn
8603
8604@deftypefn {Built-in Function} float __builtin_powif (float, int)
8605Similar to @code{__builtin_powi}, except the argument and return types
8606are @code{float}.
8607@end deftypefn
8608
8609@deftypefn {Built-in Function} {long double} __builtin_powil (long double, int)
8610Similar to @code{__builtin_powi}, except the argument and return types
8611are @code{long double}.
8612@end deftypefn
8613
74bdbe96 8614@deftypefn {Built-in Function} int16_t __builtin_bswap16 (int16_t x)
42791117 8615Returns @var{x} with the order of the bytes reversed; for example,
74bdbe96 8616@code{0xaabb} becomes @code{0xbbaa}. Byte here always means
42791117 8617exactly 8 bits.
8618@end deftypefn
8619
74bdbe96 8620@deftypefn {Built-in Function} int32_t __builtin_bswap32 (int32_t x)
8621Similar to @code{__builtin_bswap16}, except the argument and return types
8622are 32-bit.
8623@end deftypefn
8624
42791117 8625@deftypefn {Built-in Function} int64_t __builtin_bswap64 (int64_t x)
8626Similar to @code{__builtin_bswap32}, except the argument and return types
8627are 64-bit.
8628@end deftypefn
6a08d0ab 8629
ca5827cf 8630@node Target Builtins
8631@section Built-in Functions Specific to Particular Target Machines
8632
8633On some target machines, GCC supports many built-in functions specific
8634to those machines. Generally these generate calls to specific machine
8635instructions, but allow the compiler to schedule those calls.
8636
8637@menu
f2cc13dc 8638* Alpha Built-in Functions::
d98a3884 8639* ARM iWMMXt Built-in Functions::
8640* ARM NEON Intrinsics::
c5be380e 8641* AVR Built-in Functions::
88a26425 8642* Blackfin Built-in Functions::
8001abc8 8643* FR-V Built-in Functions::
ca5827cf 8644* X86 Built-in Functions::
b7efe757 8645* MIPS DSP Built-in Functions::
dd2a386a 8646* MIPS Paired-Single Support::
9636921b 8647* MIPS Loongson Built-in Functions::
f5ec18cc 8648* Other MIPS Built-in Functions::
8372e9ea 8649* picoChip Built-in Functions::
32374e3c 8650* PowerPC AltiVec/VSX Built-in Functions::
24833e1a 8651* RX Built-in Functions::
88fb6217 8652* SPARC VIS Built-in Functions::
644459d0 8653* SPU Built-in Functions::
5aa04b01 8654* TI C6X Built-in Functions::
7ce78e23 8655* TILE-Gx Built-in Functions::
8656* TILEPro Built-in Functions::
ca5827cf 8657@end menu
8658
f2cc13dc 8659@node Alpha Built-in Functions
8660@subsection Alpha Built-in Functions
8661
8662These built-in functions are available for the Alpha family of
8663processors, depending on the command-line switches used.
8664
85456819 8665The following built-in functions are always available. They
f2cc13dc 8666all generate the machine instruction that is part of the name.
8667
a0ecd6b1 8668@smallexample
f2cc13dc 8669long __builtin_alpha_implver (void)
8670long __builtin_alpha_rpcc (void)
8671long __builtin_alpha_amask (long)
8672long __builtin_alpha_cmpbge (long, long)
ae4cd3a5 8673long __builtin_alpha_extbl (long, long)
8674long __builtin_alpha_extwl (long, long)
8675long __builtin_alpha_extll (long, long)
f2cc13dc 8676long __builtin_alpha_extql (long, long)
ae4cd3a5 8677long __builtin_alpha_extwh (long, long)
8678long __builtin_alpha_extlh (long, long)
f2cc13dc 8679long __builtin_alpha_extqh (long, long)
ae4cd3a5 8680long __builtin_alpha_insbl (long, long)
8681long __builtin_alpha_inswl (long, long)
8682long __builtin_alpha_insll (long, long)
8683long __builtin_alpha_insql (long, long)
8684long __builtin_alpha_inswh (long, long)
8685long __builtin_alpha_inslh (long, long)
8686long __builtin_alpha_insqh (long, long)
8687long __builtin_alpha_mskbl (long, long)
8688long __builtin_alpha_mskwl (long, long)
8689long __builtin_alpha_mskll (long, long)
8690long __builtin_alpha_mskql (long, long)
8691long __builtin_alpha_mskwh (long, long)
8692long __builtin_alpha_msklh (long, long)
8693long __builtin_alpha_mskqh (long, long)
8694long __builtin_alpha_umulh (long, long)
f2cc13dc 8695long __builtin_alpha_zap (long, long)
8696long __builtin_alpha_zapnot (long, long)
a0ecd6b1 8697@end smallexample
f2cc13dc 8698
8699The following built-in functions are always with @option{-mmax}
8700or @option{-mcpu=@var{cpu}} where @var{cpu} is @code{pca56} or
8701later. They all generate the machine instruction that is part
8702of the name.
8703
a0ecd6b1 8704@smallexample
f2cc13dc 8705long __builtin_alpha_pklb (long)
8706long __builtin_alpha_pkwb (long)
8707long __builtin_alpha_unpkbl (long)
8708long __builtin_alpha_unpkbw (long)
8709long __builtin_alpha_minub8 (long, long)
8710long __builtin_alpha_minsb8 (long, long)
8711long __builtin_alpha_minuw4 (long, long)
8712long __builtin_alpha_minsw4 (long, long)
8713long __builtin_alpha_maxub8 (long, long)
8714long __builtin_alpha_maxsb8 (long, long)
8715long __builtin_alpha_maxuw4 (long, long)
8716long __builtin_alpha_maxsw4 (long, long)
8717long __builtin_alpha_perr (long, long)
a0ecd6b1 8718@end smallexample
f2cc13dc 8719
ae4cd3a5 8720The following built-in functions are always with @option{-mcix}
8721or @option{-mcpu=@var{cpu}} where @var{cpu} is @code{ev67} or
8722later. They all generate the machine instruction that is part
8723of the name.
8724
a0ecd6b1 8725@smallexample
ae4cd3a5 8726long __builtin_alpha_cttz (long)
8727long __builtin_alpha_ctlz (long)
8728long __builtin_alpha_ctpop (long)
a0ecd6b1 8729@end smallexample
ae4cd3a5 8730
938e069b 8731The following builtins are available on systems that use the OSF/1
8732PALcode. Normally they invoke the @code{rduniq} and @code{wruniq}
8733PAL calls, but when invoked with @option{-mtls-kernel}, they invoke
8734@code{rdval} and @code{wrval}.
8735
a0ecd6b1 8736@smallexample
938e069b 8737void *__builtin_thread_pointer (void)
8738void __builtin_set_thread_pointer (void *)
a0ecd6b1 8739@end smallexample
938e069b 8740
d98a3884 8741@node ARM iWMMXt Built-in Functions
8742@subsection ARM iWMMXt Built-in Functions
af72d7d6 8743
8744These built-in functions are available for the ARM family of
d98a3884 8745processors when the @option{-mcpu=iwmmxt} switch is used:
af72d7d6 8746
a0ecd6b1 8747@smallexample
c1f4dba6 8748typedef int v2si __attribute__ ((vector_size (8)));
8749typedef short v4hi __attribute__ ((vector_size (8)));
8750typedef char v8qi __attribute__ ((vector_size (8)));
8751
b780dd27 8752int __builtin_arm_getwcgr0 (void)
8753void __builtin_arm_setwcgr0 (int)
8754int __builtin_arm_getwcgr1 (void)
8755void __builtin_arm_setwcgr1 (int)
8756int __builtin_arm_getwcgr2 (void)
8757void __builtin_arm_setwcgr2 (int)
8758int __builtin_arm_getwcgr3 (void)
8759void __builtin_arm_setwcgr3 (int)
c1f4dba6 8760int __builtin_arm_textrmsb (v8qi, int)
8761int __builtin_arm_textrmsh (v4hi, int)
8762int __builtin_arm_textrmsw (v2si, int)
8763int __builtin_arm_textrmub (v8qi, int)
8764int __builtin_arm_textrmuh (v4hi, int)
8765int __builtin_arm_textrmuw (v2si, int)
b780dd27 8766v8qi __builtin_arm_tinsrb (v8qi, int, int)
8767v4hi __builtin_arm_tinsrh (v4hi, int, int)
8768v2si __builtin_arm_tinsrw (v2si, int, int)
c1f4dba6 8769long long __builtin_arm_tmia (long long, int, int)
8770long long __builtin_arm_tmiabb (long long, int, int)
8771long long __builtin_arm_tmiabt (long long, int, int)
8772long long __builtin_arm_tmiaph (long long, int, int)
8773long long __builtin_arm_tmiatb (long long, int, int)
8774long long __builtin_arm_tmiatt (long long, int, int)
8775int __builtin_arm_tmovmskb (v8qi)
8776int __builtin_arm_tmovmskh (v4hi)
8777int __builtin_arm_tmovmskw (v2si)
8778long long __builtin_arm_waccb (v8qi)
8779long long __builtin_arm_wacch (v4hi)
8780long long __builtin_arm_waccw (v2si)
8781v8qi __builtin_arm_waddb (v8qi, v8qi)
8782v8qi __builtin_arm_waddbss (v8qi, v8qi)
8783v8qi __builtin_arm_waddbus (v8qi, v8qi)
8784v4hi __builtin_arm_waddh (v4hi, v4hi)
8785v4hi __builtin_arm_waddhss (v4hi, v4hi)
8786v4hi __builtin_arm_waddhus (v4hi, v4hi)
af72d7d6 8787v2si __builtin_arm_waddw (v2si, v2si)
af72d7d6 8788v2si __builtin_arm_waddwss (v2si, v2si)
af72d7d6 8789v2si __builtin_arm_waddwus (v2si, v2si)
c1f4dba6 8790v8qi __builtin_arm_walign (v8qi, v8qi, int)
8791long long __builtin_arm_wand(long long, long long)
8792long long __builtin_arm_wandn (long long, long long)
8793v8qi __builtin_arm_wavg2b (v8qi, v8qi)
8794v8qi __builtin_arm_wavg2br (v8qi, v8qi)
8795v4hi __builtin_arm_wavg2h (v4hi, v4hi)
8796v4hi __builtin_arm_wavg2hr (v4hi, v4hi)
8797v8qi __builtin_arm_wcmpeqb (v8qi, v8qi)
8798v4hi __builtin_arm_wcmpeqh (v4hi, v4hi)
af72d7d6 8799v2si __builtin_arm_wcmpeqw (v2si, v2si)
c1f4dba6 8800v8qi __builtin_arm_wcmpgtsb (v8qi, v8qi)
8801v4hi __builtin_arm_wcmpgtsh (v4hi, v4hi)
af72d7d6 8802v2si __builtin_arm_wcmpgtsw (v2si, v2si)
c1f4dba6 8803v8qi __builtin_arm_wcmpgtub (v8qi, v8qi)
8804v4hi __builtin_arm_wcmpgtuh (v4hi, v4hi)
8805v2si __builtin_arm_wcmpgtuw (v2si, v2si)
8806long long __builtin_arm_wmacs (long long, v4hi, v4hi)
8807long long __builtin_arm_wmacsz (v4hi, v4hi)
8808long long __builtin_arm_wmacu (long long, v4hi, v4hi)
8809long long __builtin_arm_wmacuz (v4hi, v4hi)
8810v4hi __builtin_arm_wmadds (v4hi, v4hi)
8811v4hi __builtin_arm_wmaddu (v4hi, v4hi)
8812v8qi __builtin_arm_wmaxsb (v8qi, v8qi)
8813v4hi __builtin_arm_wmaxsh (v4hi, v4hi)
af72d7d6 8814v2si __builtin_arm_wmaxsw (v2si, v2si)
c1f4dba6 8815v8qi __builtin_arm_wmaxub (v8qi, v8qi)
8816v4hi __builtin_arm_wmaxuh (v4hi, v4hi)
af72d7d6 8817v2si __builtin_arm_wmaxuw (v2si, v2si)
c1f4dba6 8818v8qi __builtin_arm_wminsb (v8qi, v8qi)
8819v4hi __builtin_arm_wminsh (v4hi, v4hi)
af72d7d6 8820v2si __builtin_arm_wminsw (v2si, v2si)
c1f4dba6 8821v8qi __builtin_arm_wminub (v8qi, v8qi)
8822v4hi __builtin_arm_wminuh (v4hi, v4hi)
af72d7d6 8823v2si __builtin_arm_wminuw (v2si, v2si)
c1f4dba6 8824v4hi __builtin_arm_wmulsm (v4hi, v4hi)
8825v4hi __builtin_arm_wmulul (v4hi, v4hi)
8826v4hi __builtin_arm_wmulum (v4hi, v4hi)
8827long long __builtin_arm_wor (long long, long long)
8828v2si __builtin_arm_wpackdss (long long, long long)
8829v2si __builtin_arm_wpackdus (long long, long long)
8830v8qi __builtin_arm_wpackhss (v4hi, v4hi)
8831v8qi __builtin_arm_wpackhus (v4hi, v4hi)
8832v4hi __builtin_arm_wpackwss (v2si, v2si)
8833v4hi __builtin_arm_wpackwus (v2si, v2si)
8834long long __builtin_arm_wrord (long long, long long)
8835long long __builtin_arm_wrordi (long long, int)
8836v4hi __builtin_arm_wrorh (v4hi, long long)
8837v4hi __builtin_arm_wrorhi (v4hi, int)
8838v2si __builtin_arm_wrorw (v2si, long long)
8839v2si __builtin_arm_wrorwi (v2si, int)
b780dd27 8840v2si __builtin_arm_wsadb (v2si, v8qi, v8qi)
c1f4dba6 8841v2si __builtin_arm_wsadbz (v8qi, v8qi)
b780dd27 8842v2si __builtin_arm_wsadh (v2si, v4hi, v4hi)
c1f4dba6 8843v2si __builtin_arm_wsadhz (v4hi, v4hi)
8844v4hi __builtin_arm_wshufh (v4hi, int)
8845long long __builtin_arm_wslld (long long, long long)
8846long long __builtin_arm_wslldi (long long, int)
8847v4hi __builtin_arm_wsllh (v4hi, long long)
8848v4hi __builtin_arm_wsllhi (v4hi, int)
8849v2si __builtin_arm_wsllw (v2si, long long)
af72d7d6 8850v2si __builtin_arm_wsllwi (v2si, int)
c1f4dba6 8851long long __builtin_arm_wsrad (long long, long long)
8852long long __builtin_arm_wsradi (long long, int)
8853v4hi __builtin_arm_wsrah (v4hi, long long)
8854v4hi __builtin_arm_wsrahi (v4hi, int)
8855v2si __builtin_arm_wsraw (v2si, long long)
af72d7d6 8856v2si __builtin_arm_wsrawi (v2si, int)
c1f4dba6 8857long long __builtin_arm_wsrld (long long, long long)
8858long long __builtin_arm_wsrldi (long long, int)
8859v4hi __builtin_arm_wsrlh (v4hi, long long)
8860v4hi __builtin_arm_wsrlhi (v4hi, int)
8861v2si __builtin_arm_wsrlw (v2si, long long)
af72d7d6 8862v2si __builtin_arm_wsrlwi (v2si, int)
c1f4dba6 8863v8qi __builtin_arm_wsubb (v8qi, v8qi)
8864v8qi __builtin_arm_wsubbss (v8qi, v8qi)
8865v8qi __builtin_arm_wsubbus (v8qi, v8qi)
8866v4hi __builtin_arm_wsubh (v4hi, v4hi)
8867v4hi __builtin_arm_wsubhss (v4hi, v4hi)
8868v4hi __builtin_arm_wsubhus (v4hi, v4hi)
8869v2si __builtin_arm_wsubw (v2si, v2si)
8870v2si __builtin_arm_wsubwss (v2si, v2si)
8871v2si __builtin_arm_wsubwus (v2si, v2si)
8872v4hi __builtin_arm_wunpckehsb (v8qi)
8873v2si __builtin_arm_wunpckehsh (v4hi)
8874long long __builtin_arm_wunpckehsw (v2si)
8875v4hi __builtin_arm_wunpckehub (v8qi)
8876v2si __builtin_arm_wunpckehuh (v4hi)
8877long long __builtin_arm_wunpckehuw (v2si)
8878v4hi __builtin_arm_wunpckelsb (v8qi)
8879v2si __builtin_arm_wunpckelsh (v4hi)
8880long long __builtin_arm_wunpckelsw (v2si)
8881v4hi __builtin_arm_wunpckelub (v8qi)
8882v2si __builtin_arm_wunpckeluh (v4hi)
8883long long __builtin_arm_wunpckeluw (v2si)
8884v8qi __builtin_arm_wunpckihb (v8qi, v8qi)
8885v4hi __builtin_arm_wunpckihh (v4hi, v4hi)
af72d7d6 8886v2si __builtin_arm_wunpckihw (v2si, v2si)
c1f4dba6 8887v8qi __builtin_arm_wunpckilb (v8qi, v8qi)
8888v4hi __builtin_arm_wunpckilh (v4hi, v4hi)
af72d7d6 8889v2si __builtin_arm_wunpckilw (v2si, v2si)
c1f4dba6 8890long long __builtin_arm_wxor (long long, long long)
8891long long __builtin_arm_wzero ()
a0ecd6b1 8892@end smallexample
af72d7d6 8893
d98a3884 8894@node ARM NEON Intrinsics
8895@subsection ARM NEON Intrinsics
8896
8897These built-in intrinsics for the ARM Advanced SIMD extension are available
8898when the @option{-mfpu=neon} switch is used:
8899
8900@include arm-neon-intrinsics.texi
8901
c5be380e 8902@node AVR Built-in Functions
8903@subsection AVR Built-in Functions
8904
8905For each built-in function for AVR, there is an equally named,
8906uppercase built-in macro defined. That way users can easily query if
8907or if not a specific built-in is implemented or not. For example, if
8908@code{__builtin_avr_nop} is available the macro
8909@code{__BUILTIN_AVR_NOP} is defined to @code{1} and undefined otherwise.
8910
8911The following built-in functions map to the respective machine
8912instruction, i.e. @code{nop}, @code{sei}, @code{cli}, @code{sleep},
8913@code{wdr}, @code{swap}, @code{fmul}, @code{fmuls}
12596ea7 8914resp. @code{fmulsu}. The three @code{fmul*} built-ins are implemented
8915as library call if no hardware multiplier is available.
c5be380e 8916
8917@smallexample
8918void __builtin_avr_nop (void)
8919void __builtin_avr_sei (void)
8920void __builtin_avr_cli (void)
8921void __builtin_avr_sleep (void)
8922void __builtin_avr_wdr (void)
8923unsigned char __builtin_avr_swap (unsigned char)
8924unsigned int __builtin_avr_fmul (unsigned char, unsigned char)
8925int __builtin_avr_fmuls (char, char)
8926int __builtin_avr_fmulsu (char, unsigned char)
8927@end smallexample
8928
8929In order to delay execution for a specific number of cycles, GCC
8930implements
8931@smallexample
8932void __builtin_avr_delay_cycles (unsigned long ticks)
8933@end smallexample
8934
384f6361 8935@noindent
c5be380e 8936@code{ticks} is the number of ticks to delay execution. Note that this
8937built-in does not take into account the effect of interrupts which
8938might increase delay time. @code{ticks} must be a compile time
8939integer constant; delays with a variable number of cycles are not supported.
8940
384f6361 8941@smallexample
12ffadfa 8942char __builtin_avr_flash_segment (const __memx void*)
8943@end smallexample
8944
8945@noindent
8946This built-in takes a byte address to the 24-bit
8947@ref{AVR Named Address Spaces,address space} @code{__memx} and returns
8948the number of the flash segment (the 64 KiB chunk) where the address
8949points to. Counting starts at @code{0}.
8950If the address does not point to flash memory, return @code{-1}.
8951
8952@smallexample
8953unsigned char __builtin_avr_insert_bits (unsigned long map, unsigned char bits, unsigned char val)
384f6361 8954@end smallexample
8955
8956@noindent
15b84087 8957Insert bits from @var{bits} into @var{val} and return the resulting
8958value. The nibbles of @var{map} determine how the insertion is
8959performed: Let @var{X} be the @var{n}-th nibble of @var{map}
8960@enumerate
8961@item If @var{X} is @code{0xf},
8962then the @var{n}-th bit of @var{val} is returned unaltered.
8963
8964@item If X is in the range 0@dots{}7,
8965then the @var{n}-th result bit is set to the @var{X}-th bit of @var{bits}
8966
8967@item If X is in the range 8@dots{}@code{0xe},
8968then the @var{n}-th result bit is undefined.
8969@end enumerate
384f6361 8970
8971@noindent
15b84087 8972One typical use case for this built-in is adjusting input and
8973output values to non-contiguous port layouts. Some examples:
384f6361 8974
8975@smallexample
15b84087 8976// same as val, bits is unused
8977__builtin_avr_insert_bits (0xffffffff, bits, val)
384f6361 8978@end smallexample
8979
15b84087 8980@smallexample
8981// same as bits, val is unused
8982__builtin_avr_insert_bits (0x76543210, bits, val)
8983@end smallexample
8984
8985@smallexample
8986// same as rotating bits by 4
8987__builtin_avr_insert_bits (0x32107654, bits, 0)
8988@end smallexample
8989
8990@smallexample
8991// high-nibble of result is the high-nibble of val
8992// low-nibble of result is the low-nibble of bits
8993__builtin_avr_insert_bits (0xffff3210, bits, val)
8994@end smallexample
8995
8996@smallexample
8997// reverse the bit order of bits
8998__builtin_avr_insert_bits (0x01234567, bits, 0)
8999@end smallexample
384f6361 9000
88a26425 9001@node Blackfin Built-in Functions
9002@subsection Blackfin Built-in Functions
9003
9004Currently, there are two Blackfin-specific built-in functions. These are
9005used for generating @code{CSYNC} and @code{SSYNC} machine insns without
9006using inline assembly; by using these built-in functions the compiler can
9007automatically add workarounds for hardware errata involving these
9008instructions. These functions are named as follows:
9009
9010@smallexample
9011void __builtin_bfin_csync (void)
9012void __builtin_bfin_ssync (void)
9013@end smallexample
9014
8001abc8 9015@node FR-V Built-in Functions
9016@subsection FR-V Built-in Functions
9017
9018GCC provides many FR-V-specific built-in functions. In general,
9019these functions are intended to be compatible with those described
9020by @cite{FR-V Family, Softune C/C++ Compiler Manual (V6), Fujitsu
9021Semiconductor}. The two exceptions are @code{__MDUNPACKH} and
9022@code{__MBTOHE}, the gcc forms of which pass 128-bit values by
9023pointer rather than by value.
9024
9025Most of the functions are named after specific FR-V instructions.
fcc3191b 9026Such functions are said to be ``directly mapped'' and are summarized
8001abc8 9027here in tabular form.
9028
9029@menu
9030* Argument Types::
9031* Directly-mapped Integer Functions::
9032* Directly-mapped Media Functions::
9f3b67fe 9033* Raw read/write Functions::
8001abc8 9034* Other Built-in Functions::
9035@end menu
9036
9037@node Argument Types
9038@subsubsection Argument Types
9039
9040The arguments to the built-in functions can be divided into three groups:
9041register numbers, compile-time constants and run-time values. In order
9042to make this classification clear at a glance, the arguments and return
9043values are given the following pseudo types:
9044
9045@multitable @columnfractions .20 .30 .15 .35
9046@item Pseudo type @tab Real C type @tab Constant? @tab Description
9047@item @code{uh} @tab @code{unsigned short} @tab No @tab an unsigned halfword
9048@item @code{uw1} @tab @code{unsigned int} @tab No @tab an unsigned word
9049@item @code{sw1} @tab @code{int} @tab No @tab a signed word
9050@item @code{uw2} @tab @code{unsigned long long} @tab No
9051@tab an unsigned doubleword
9052@item @code{sw2} @tab @code{long long} @tab No @tab a signed doubleword
9053@item @code{const} @tab @code{int} @tab Yes @tab an integer constant
9054@item @code{acc} @tab @code{int} @tab Yes @tab an ACC register number
9055@item @code{iacc} @tab @code{int} @tab Yes @tab an IACC register number
9056@end multitable
9057
9058These pseudo types are not defined by GCC, they are simply a notational
9059convenience used in this manual.
9060
9061Arguments of type @code{uh}, @code{uw1}, @code{sw1}, @code{uw2}
9062and @code{sw2} are evaluated at run time. They correspond to
9063register operands in the underlying FR-V instructions.
9064
9065@code{const} arguments represent immediate operands in the underlying
9066FR-V instructions. They must be compile-time constants.
9067
9068@code{acc} arguments are evaluated at compile time and specify the number
9069of an accumulator register. For example, an @code{acc} argument of 2
9070will select the ACC2 register.
9071
9072@code{iacc} arguments are similar to @code{acc} arguments but specify the
9073number of an IACC register. See @pxref{Other Built-in Functions}
9074for more details.
9075
9076@node Directly-mapped Integer Functions
9077@subsubsection Directly-mapped Integer Functions
9078
9079The functions listed below map directly to FR-V I-type instructions.
9080
9081@multitable @columnfractions .45 .32 .23
9082@item Function prototype @tab Example usage @tab Assembly output
9083@item @code{sw1 __ADDSS (sw1, sw1)}
9084@tab @code{@var{c} = __ADDSS (@var{a}, @var{b})}
9085@tab @code{ADDSS @var{a},@var{b},@var{c}}
9086@item @code{sw1 __SCAN (sw1, sw1)}
9087@tab @code{@var{c} = __SCAN (@var{a}, @var{b})}
9088@tab @code{SCAN @var{a},@var{b},@var{c}}
9089@item @code{sw1 __SCUTSS (sw1)}
9090@tab @code{@var{b} = __SCUTSS (@var{a})}
9091@tab @code{SCUTSS @var{a},@var{b}}
9092@item @code{sw1 __SLASS (sw1, sw1)}
9093@tab @code{@var{c} = __SLASS (@var{a}, @var{b})}
9094@tab @code{SLASS @var{a},@var{b},@var{c}}
9095@item @code{void __SMASS (sw1, sw1)}
9096@tab @code{__SMASS (@var{a}, @var{b})}
9097@tab @code{SMASS @var{a},@var{b}}
9098@item @code{void __SMSSS (sw1, sw1)}
9099@tab @code{__SMSSS (@var{a}, @var{b})}
9100@tab @code{SMSSS @var{a},@var{b}}
9101@item @code{void __SMU (sw1, sw1)}
9102@tab @code{__SMU (@var{a}, @var{b})}
9103@tab @code{SMU @var{a},@var{b}}
9104@item @code{sw2 __SMUL (sw1, sw1)}
9105@tab @code{@var{c} = __SMUL (@var{a}, @var{b})}
9106@tab @code{SMUL @var{a},@var{b},@var{c}}
9107@item @code{sw1 __SUBSS (sw1, sw1)}
9108@tab @code{@var{c} = __SUBSS (@var{a}, @var{b})}
9109@tab @code{SUBSS @var{a},@var{b},@var{c}}
9110@item @code{uw2 __UMUL (uw1, uw1)}
9111@tab @code{@var{c} = __UMUL (@var{a}, @var{b})}
9112@tab @code{UMUL @var{a},@var{b},@var{c}}
9113@end multitable
9114
9115@node Directly-mapped Media Functions
9116@subsubsection Directly-mapped Media Functions
9117
9118The functions listed below map directly to FR-V M-type instructions.
9119
9120@multitable @columnfractions .45 .32 .23
9121@item Function prototype @tab Example usage @tab Assembly output
9122@item @code{uw1 __MABSHS (sw1)}
9123@tab @code{@var{b} = __MABSHS (@var{a})}
9124@tab @code{MABSHS @var{a},@var{b}}
9125@item @code{void __MADDACCS (acc, acc)}
9126@tab @code{__MADDACCS (@var{b}, @var{a})}
9127@tab @code{MADDACCS @var{a},@var{b}}
9128@item @code{sw1 __MADDHSS (sw1, sw1)}
9129@tab @code{@var{c} = __MADDHSS (@var{a}, @var{b})}
9130@tab @code{MADDHSS @var{a},@var{b},@var{c}}
9131@item @code{uw1 __MADDHUS (uw1, uw1)}
9132@tab @code{@var{c} = __MADDHUS (@var{a}, @var{b})}
9133@tab @code{MADDHUS @var{a},@var{b},@var{c}}
9134@item @code{uw1 __MAND (uw1, uw1)}
9135@tab @code{@var{c} = __MAND (@var{a}, @var{b})}
9136@tab @code{MAND @var{a},@var{b},@var{c}}
9137@item @code{void __MASACCS (acc, acc)}
9138@tab @code{__MASACCS (@var{b}, @var{a})}
9139@tab @code{MASACCS @var{a},@var{b}}
9140@item @code{uw1 __MAVEH (uw1, uw1)}
9141@tab @code{@var{c} = __MAVEH (@var{a}, @var{b})}
9142@tab @code{MAVEH @var{a},@var{b},@var{c}}
9143@item @code{uw2 __MBTOH (uw1)}
9144@tab @code{@var{b} = __MBTOH (@var{a})}
9145@tab @code{MBTOH @var{a},@var{b}}
9146@item @code{void __MBTOHE (uw1 *, uw1)}
9147@tab @code{__MBTOHE (&@var{b}, @var{a})}
9148@tab @code{MBTOHE @var{a},@var{b}}
9149@item @code{void __MCLRACC (acc)}
9150@tab @code{__MCLRACC (@var{a})}
9151@tab @code{MCLRACC @var{a}}
9152@item @code{void __MCLRACCA (void)}
9153@tab @code{__MCLRACCA ()}
9154@tab @code{MCLRACCA}
9155@item @code{uw1 __Mcop1 (uw1, uw1)}
9156@tab @code{@var{c} = __Mcop1 (@var{a}, @var{b})}
9157@tab @code{Mcop1 @var{a},@var{b},@var{c}}
9158@item @code{uw1 __Mcop2 (uw1, uw1)}
9159@tab @code{@var{c} = __Mcop2 (@var{a}, @var{b})}
9160@tab @code{Mcop2 @var{a},@var{b},@var{c}}
9161@item @code{uw1 __MCPLHI (uw2, const)}
9162@tab @code{@var{c} = __MCPLHI (@var{a}, @var{b})}
9163@tab @code{MCPLHI @var{a},#@var{b},@var{c}}
9164@item @code{uw1 __MCPLI (uw2, const)}
9165@tab @code{@var{c} = __MCPLI (@var{a}, @var{b})}
9166@tab @code{MCPLI @var{a},#@var{b},@var{c}}
9167@item @code{void __MCPXIS (acc, sw1, sw1)}
9168@tab @code{__MCPXIS (@var{c}, @var{a}, @var{b})}
9169@tab @code{MCPXIS @var{a},@var{b},@var{c}}
9170@item @code{void __MCPXIU (acc, uw1, uw1)}
9171@tab @code{__MCPXIU (@var{c}, @var{a}, @var{b})}
9172@tab @code{MCPXIU @var{a},@var{b},@var{c}}
9173@item @code{void __MCPXRS (acc, sw1, sw1)}
9174@tab @code{__MCPXRS (@var{c}, @var{a}, @var{b})}
9175@tab @code{MCPXRS @var{a},@var{b},@var{c}}
9176@item @code{void __MCPXRU (acc, uw1, uw1)}
9177@tab @code{__MCPXRU (@var{c}, @var{a}, @var{b})}
9178@tab @code{MCPXRU @var{a},@var{b},@var{c}}
9179@item @code{uw1 __MCUT (acc, uw1)}
9180@tab @code{@var{c} = __MCUT (@var{a}, @var{b})}
9181@tab @code{MCUT @var{a},@var{b},@var{c}}
9182@item @code{uw1 __MCUTSS (acc, sw1)}
9183@tab @code{@var{c} = __MCUTSS (@var{a}, @var{b})}
9184@tab @code{MCUTSS @var{a},@var{b},@var{c}}
9185@item @code{void __MDADDACCS (acc, acc)}
9186@tab @code{__MDADDACCS (@var{b}, @var{a})}
9187@tab @code{MDADDACCS @var{a},@var{b}}
9188@item @code{void __MDASACCS (acc, acc)}
9189@tab @code{__MDASACCS (@var{b}, @var{a})}
9190@tab @code{MDASACCS @var{a},@var{b}}
9191@item @code{uw2 __MDCUTSSI (acc, const)}
9192@tab @code{@var{c} = __MDCUTSSI (@var{a}, @var{b})}
9193@tab @code{MDCUTSSI @var{a},#@var{b},@var{c}}
9194@item @code{uw2 __MDPACKH (uw2, uw2)}
9195@tab @code{@var{c} = __MDPACKH (@var{a}, @var{b})}
9196@tab @code{MDPACKH @var{a},@var{b},@var{c}}
9197@item @code{uw2 __MDROTLI (uw2, const)}
9198@tab @code{@var{c} = __MDROTLI (@var{a}, @var{b})}
9199@tab @code{MDROTLI @var{a},#@var{b},@var{c}}
9200@item @code{void __MDSUBACCS (acc, acc)}
9201@tab @code{__MDSUBACCS (@var{b}, @var{a})}
9202@tab @code{MDSUBACCS @var{a},@var{b}}
9203@item @code{void __MDUNPACKH (uw1 *, uw2)}
9204@tab @code{__MDUNPACKH (&@var{b}, @var{a})}
9205@tab @code{MDUNPACKH @var{a},@var{b}}
9206@item @code{uw2 __MEXPDHD (uw1, const)}
9207@tab @code{@var{c} = __MEXPDHD (@var{a}, @var{b})}
9208@tab @code{MEXPDHD @var{a},#@var{b},@var{c}}
9209@item @code{uw1 __MEXPDHW (uw1, const)}
9210@tab @code{@var{c} = __MEXPDHW (@var{a}, @var{b})}
9211@tab @code{MEXPDHW @var{a},#@var{b},@var{c}}
9212@item @code{uw1 __MHDSETH (uw1, const)}
9213@tab @code{@var{c} = __MHDSETH (@var{a}, @var{b})}
9214@tab @code{MHDSETH @var{a},#@var{b},@var{c}}
9215@item @code{sw1 __MHDSETS (const)}
9216@tab @code{@var{b} = __MHDSETS (@var{a})}
9217@tab @code{MHDSETS #@var{a},@var{b}}
9218@item @code{uw1 __MHSETHIH (uw1, const)}
9219@tab @code{@var{b} = __MHSETHIH (@var{b}, @var{a})}
9220@tab @code{MHSETHIH #@var{a},@var{b}}
9221@item @code{sw1 __MHSETHIS (sw1, const)}
9222@tab @code{@var{b} = __MHSETHIS (@var{b}, @var{a})}
9223@tab @code{MHSETHIS #@var{a},@var{b}}
9224@item @code{uw1 __MHSETLOH (uw1, const)}
9225@tab @code{@var{b} = __MHSETLOH (@var{b}, @var{a})}
9226@tab @code{MHSETLOH #@var{a},@var{b}}
9227@item @code{sw1 __MHSETLOS (sw1, const)}
9228@tab @code{@var{b} = __MHSETLOS (@var{b}, @var{a})}
9229@tab @code{MHSETLOS #@var{a},@var{b}}
9230@item @code{uw1 __MHTOB (uw2)}
9231@tab @code{@var{b} = __MHTOB (@var{a})}
9232@tab @code{MHTOB @var{a},@var{b}}
9233@item @code{void __MMACHS (acc, sw1, sw1)}
9234@tab @code{__MMACHS (@var{c}, @var{a}, @var{b})}
9235@tab @code{MMACHS @var{a},@var{b},@var{c}}
9236@item @code{void __MMACHU (acc, uw1, uw1)}
9237@tab @code{__MMACHU (@var{c}, @var{a}, @var{b})}
9238@tab @code{MMACHU @var{a},@var{b},@var{c}}
9239@item @code{void __MMRDHS (acc, sw1, sw1)}
9240@tab @code{__MMRDHS (@var{c}, @var{a}, @var{b})}
9241@tab @code{MMRDHS @var{a},@var{b},@var{c}}
9242@item @code{void __MMRDHU (acc, uw1, uw1)}
9243@tab @code{__MMRDHU (@var{c}, @var{a}, @var{b})}
9244@tab @code{MMRDHU @var{a},@var{b},@var{c}}
9245@item @code{void __MMULHS (acc, sw1, sw1)}
9246@tab @code{__MMULHS (@var{c}, @var{a}, @var{b})}
9247@tab @code{MMULHS @var{a},@var{b},@var{c}}
9248@item @code{void __MMULHU (acc, uw1, uw1)}
9249@tab @code{__MMULHU (@var{c}, @var{a}, @var{b})}
9250@tab @code{MMULHU @var{a},@var{b},@var{c}}
9251@item @code{void __MMULXHS (acc, sw1, sw1)}
9252@tab @code{__MMULXHS (@var{c}, @var{a}, @var{b})}
9253@tab @code{MMULXHS @var{a},@var{b},@var{c}}
9254@item @code{void __MMULXHU (acc, uw1, uw1)}
9255@tab @code{__MMULXHU (@var{c}, @var{a}, @var{b})}
9256@tab @code{MMULXHU @var{a},@var{b},@var{c}}
9257@item @code{uw1 __MNOT (uw1)}
9258@tab @code{@var{b} = __MNOT (@var{a})}
9259@tab @code{MNOT @var{a},@var{b}}
9260@item @code{uw1 __MOR (uw1, uw1)}
9261@tab @code{@var{c} = __MOR (@var{a}, @var{b})}
9262@tab @code{MOR @var{a},@var{b},@var{c}}
9263@item @code{uw1 __MPACKH (uh, uh)}
9264@tab @code{@var{c} = __MPACKH (@var{a}, @var{b})}
9265@tab @code{MPACKH @var{a},@var{b},@var{c}}
9266@item @code{sw2 __MQADDHSS (sw2, sw2)}
9267@tab @code{@var{c} = __MQADDHSS (@var{a}, @var{b})}
9268@tab @code{MQADDHSS @var{a},@var{b},@var{c}}
9269@item @code{uw2 __MQADDHUS (uw2, uw2)}
9270@tab @code{@var{c} = __MQADDHUS (@var{a}, @var{b})}
9271@tab @code{MQADDHUS @var{a},@var{b},@var{c}}
9272@item @code{void __MQCPXIS (acc, sw2, sw2)}
9273@tab @code{__MQCPXIS (@var{c}, @var{a}, @var{b})}
9274@tab @code{MQCPXIS @var{a},@var{b},@var{c}}
9275@item @code{void __MQCPXIU (acc, uw2, uw2)}
9276@tab @code{__MQCPXIU (@var{c}, @var{a}, @var{b})}
9277@tab @code{MQCPXIU @var{a},@var{b},@var{c}}
9278@item @code{void __MQCPXRS (acc, sw2, sw2)}
9279@tab @code{__MQCPXRS (@var{c}, @var{a}, @var{b})}
9280@tab @code{MQCPXRS @var{a},@var{b},@var{c}}
9281@item @code{void __MQCPXRU (acc, uw2, uw2)}
9282@tab @code{__MQCPXRU (@var{c}, @var{a}, @var{b})}
9283@tab @code{MQCPXRU @var{a},@var{b},@var{c}}
9284@item @code{sw2 __MQLCLRHS (sw2, sw2)}
9285@tab @code{@var{c} = __MQLCLRHS (@var{a}, @var{b})}
9286@tab @code{MQLCLRHS @var{a},@var{b},@var{c}}
9287@item @code{sw2 __MQLMTHS (sw2, sw2)}
9288@tab @code{@var{c} = __MQLMTHS (@var{a}, @var{b})}
9289@tab @code{MQLMTHS @var{a},@var{b},@var{c}}
9290@item @code{void __MQMACHS (acc, sw2, sw2)}
9291@tab @code{__MQMACHS (@var{c}, @var{a}, @var{b})}
9292@tab @code{MQMACHS @var{a},@var{b},@var{c}}
9293@item @code{void __MQMACHU (acc, uw2, uw2)}
9294@tab @code{__MQMACHU (@var{c}, @var{a}, @var{b})}
9295@tab @code{MQMACHU @var{a},@var{b},@var{c}}
9296@item @code{void __MQMACXHS (acc, sw2, sw2)}
9297@tab @code{__MQMACXHS (@var{c}, @var{a}, @var{b})}
9298@tab @code{MQMACXHS @var{a},@var{b},@var{c}}
9299@item @code{void __MQMULHS (acc, sw2, sw2)}
9300@tab @code{__MQMULHS (@var{c}, @var{a}, @var{b})}
9301@tab @code{MQMULHS @var{a},@var{b},@var{c}}
9302@item @code{void __MQMULHU (acc, uw2, uw2)}
9303@tab @code{__MQMULHU (@var{c}, @var{a}, @var{b})}
9304@tab @code{MQMULHU @var{a},@var{b},@var{c}}
9305@item @code{void __MQMULXHS (acc, sw2, sw2)}
9306@tab @code{__MQMULXHS (@var{c}, @var{a}, @var{b})}
9307@tab @code{MQMULXHS @var{a},@var{b},@var{c}}
9308@item @code{void __MQMULXHU (acc, uw2, uw2)}
9309@tab @code{__MQMULXHU (@var{c}, @var{a}, @var{b})}
9310@tab @code{MQMULXHU @var{a},@var{b},@var{c}}
9311@item @code{sw2 __MQSATHS (sw2, sw2)}
9312@tab @code{@var{c} = __MQSATHS (@var{a}, @var{b})}
9313@tab @code{MQSATHS @var{a},@var{b},@var{c}}
9314@item @code{uw2 __MQSLLHI (uw2, int)}
9315@tab @code{@var{c} = __MQSLLHI (@var{a}, @var{b})}
9316@tab @code{MQSLLHI @var{a},@var{b},@var{c}}
9317@item @code{sw2 __MQSRAHI (sw2, int)}
9318@tab @code{@var{c} = __MQSRAHI (@var{a}, @var{b})}
9319@tab @code{MQSRAHI @var{a},@var{b},@var{c}}
9320@item @code{sw2 __MQSUBHSS (sw2, sw2)}
9321@tab @code{@var{c} = __MQSUBHSS (@var{a}, @var{b})}
9322@tab @code{MQSUBHSS @var{a},@var{b},@var{c}}
9323@item @code{uw2 __MQSUBHUS (uw2, uw2)}
9324@tab @code{@var{c} = __MQSUBHUS (@var{a}, @var{b})}
9325@tab @code{MQSUBHUS @var{a},@var{b},@var{c}}
9326@item @code{void __MQXMACHS (acc, sw2, sw2)}
9327@tab @code{__MQXMACHS (@var{c}, @var{a}, @var{b})}
9328@tab @code{MQXMACHS @var{a},@var{b},@var{c}}
9329@item @code{void __MQXMACXHS (acc, sw2, sw2)}
9330@tab @code{__MQXMACXHS (@var{c}, @var{a}, @var{b})}
9331@tab @code{MQXMACXHS @var{a},@var{b},@var{c}}
9332@item @code{uw1 __MRDACC (acc)}
9333@tab @code{@var{b} = __MRDACC (@var{a})}
9334@tab @code{MRDACC @var{a},@var{b}}
9335@item @code{uw1 __MRDACCG (acc)}
9336@tab @code{@var{b} = __MRDACCG (@var{a})}
9337@tab @code{MRDACCG @var{a},@var{b}}
9338@item @code{uw1 __MROTLI (uw1, const)}
9339@tab @code{@var{c} = __MROTLI (@var{a}, @var{b})}
9340@tab @code{MROTLI @var{a},#@var{b},@var{c}}
9341@item @code{uw1 __MROTRI (uw1, const)}
9342@tab @code{@var{c} = __MROTRI (@var{a}, @var{b})}
9343@tab @code{MROTRI @var{a},#@var{b},@var{c}}
9344@item @code{sw1 __MSATHS (sw1, sw1)}
9345@tab @code{@var{c} = __MSATHS (@var{a}, @var{b})}
9346@tab @code{MSATHS @var{a},@var{b},@var{c}}
9347@item @code{uw1 __MSATHU (uw1, uw1)}
9348@tab @code{@var{c} = __MSATHU (@var{a}, @var{b})}
9349@tab @code{MSATHU @var{a},@var{b},@var{c}}
9350@item @code{uw1 __MSLLHI (uw1, const)}
9351@tab @code{@var{c} = __MSLLHI (@var{a}, @var{b})}
9352@tab @code{MSLLHI @var{a},#@var{b},@var{c}}
9353@item @code{sw1 __MSRAHI (sw1, const)}
9354@tab @code{@var{c} = __MSRAHI (@var{a}, @var{b})}
9355@tab @code{MSRAHI @var{a},#@var{b},@var{c}}
9356@item @code{uw1 __MSRLHI (uw1, const)}
9357@tab @code{@var{c} = __MSRLHI (@var{a}, @var{b})}
9358@tab @code{MSRLHI @var{a},#@var{b},@var{c}}
9359@item @code{void __MSUBACCS (acc, acc)}
9360@tab @code{__MSUBACCS (@var{b}, @var{a})}
9361@tab @code{MSUBACCS @var{a},@var{b}}
9362@item @code{sw1 __MSUBHSS (sw1, sw1)}
9363@tab @code{@var{c} = __MSUBHSS (@var{a}, @var{b})}
9364@tab @code{MSUBHSS @var{a},@var{b},@var{c}}
9365@item @code{uw1 __MSUBHUS (uw1, uw1)}
9366@tab @code{@var{c} = __MSUBHUS (@var{a}, @var{b})}
9367@tab @code{MSUBHUS @var{a},@var{b},@var{c}}
9368@item @code{void __MTRAP (void)}
9369@tab @code{__MTRAP ()}
9370@tab @code{MTRAP}
9371@item @code{uw2 __MUNPACKH (uw1)}
9372@tab @code{@var{b} = __MUNPACKH (@var{a})}
9373@tab @code{MUNPACKH @var{a},@var{b}}
9374@item @code{uw1 __MWCUT (uw2, uw1)}
9375@tab @code{@var{c} = __MWCUT (@var{a}, @var{b})}
9376@tab @code{MWCUT @var{a},@var{b},@var{c}}
9377@item @code{void __MWTACC (acc, uw1)}
9378@tab @code{__MWTACC (@var{b}, @var{a})}
9379@tab @code{MWTACC @var{a},@var{b}}
9380@item @code{void __MWTACCG (acc, uw1)}
9381@tab @code{__MWTACCG (@var{b}, @var{a})}
9382@tab @code{MWTACCG @var{a},@var{b}}
9383@item @code{uw1 __MXOR (uw1, uw1)}
9384@tab @code{@var{c} = __MXOR (@var{a}, @var{b})}
9385@tab @code{MXOR @var{a},@var{b},@var{c}}
9386@end multitable
9387
9f3b67fe 9388@node Raw read/write Functions
9389@subsubsection Raw read/write Functions
9390
9391This sections describes built-in functions related to read and write
9392instructions to access memory. These functions generate
9393@code{membar} instructions to flush the I/O load and stores where
9394appropriate, as described in Fujitsu's manual described above.
9395
9396@table @code
9397
9398@item unsigned char __builtin_read8 (void *@var{data})
9399@item unsigned short __builtin_read16 (void *@var{data})
9400@item unsigned long __builtin_read32 (void *@var{data})
9401@item unsigned long long __builtin_read64 (void *@var{data})
9402
9403@item void __builtin_write8 (void *@var{data}, unsigned char @var{datum})
9404@item void __builtin_write16 (void *@var{data}, unsigned short @var{datum})
9405@item void __builtin_write32 (void *@var{data}, unsigned long @var{datum})
9406@item void __builtin_write64 (void *@var{data}, unsigned long long @var{datum})
9407@end table
9408
8001abc8 9409@node Other Built-in Functions
9410@subsubsection Other Built-in Functions
9411
9412This section describes built-in functions that are not named after
9413a specific FR-V instruction.
9414
9415@table @code
9416@item sw2 __IACCreadll (iacc @var{reg})
9417Return the full 64-bit value of IACC0@. The @var{reg} argument is reserved
9418for future expansion and must be 0.
9419
9420@item sw1 __IACCreadl (iacc @var{reg})
9421Return the value of IACC0H if @var{reg} is 0 and IACC0L if @var{reg} is 1.
9422Other values of @var{reg} are rejected as invalid.
9423
9424@item void __IACCsetll (iacc @var{reg}, sw2 @var{x})
9425Set the full 64-bit value of IACC0 to @var{x}. The @var{reg} argument
9426is reserved for future expansion and must be 0.
9427
9428@item void __IACCsetl (iacc @var{reg}, sw1 @var{x})
9429Set IACC0H to @var{x} if @var{reg} is 0 and IACC0L to @var{x} if @var{reg}
9430is 1. Other values of @var{reg} are rejected as invalid.
9431
9432@item void __data_prefetch0 (const void *@var{x})
9433Use the @code{dcpl} instruction to load the contents of address @var{x}
9434into the data cache.
9435
9436@item void __data_prefetch (const void *@var{x})
9437Use the @code{nldub} instruction to load the contents of address @var{x}
9438into the data cache. The instruction will be issued in slot I1@.
9439@end table
9440
ca5827cf 9441@node X86 Built-in Functions
9442@subsection X86 Built-in Functions
9443
9444These built-in functions are available for the i386 and x86-64 family
9445of computers, depending on the command-line switches used.
9446
0e6c8ad0 9447Note that, if you specify command-line switches such as @option{-msse},
9448the compiler could use the extended instruction sets even if the built-ins
9449are not used explicitly in the program. For this reason, applications
9450which perform runtime CPU detection must compile separate files for each
9451supported architecture, using the appropriate flags. In particular,
9452the file containing the CPU detection code should be compiled without
9453these options.
9454
ca5827cf 9455The following machine modes are available for use with MMX built-in functions
0ae4308e 9456(@pxref{Vector Extensions}): @code{V2SI} for a vector of two 32-bit integers,
9457@code{V4HI} for a vector of four 16-bit integers, and @code{V8QI} for a
9458vector of eight 8-bit integers. Some of the built-in functions operate on
5b2ddfe1 9459MMX registers as a whole 64-bit entity, these use @code{V1DI} as their mode.
ca5827cf 9460
4f0fcaad 9461If 3DNow!@: extensions are enabled, @code{V2SF} is used as a mode for a vector
0ae4308e 9462of two 32-bit floating point values.
ca5827cf 9463
0ae4308e 9464If SSE extensions are enabled, @code{V4SF} is used for a vector of four 32-bit
9465floating point values. Some instructions use a vector of four 32-bit
ca5827cf 9466integers, these use @code{V4SI}. Finally, some instructions operate on an
0ae4308e 9467entire vector register, interpreting it as a 128-bit integer, these use mode
ca5827cf 9468@code{TI}.
9469
957fb083 9470In 64-bit mode, the x86-64 family of processors uses additional built-in
c902c5c2 9471functions for efficient use of @code{TF} (@code{__float128}) 128-bit
9472floating point and @code{TC} 128-bit complex floating point values.
9473
957fb083 9474The following floating point built-in functions are available in 64-bit
9475mode. All of them implement the function that is part of the name.
c902c5c2 9476
9477@smallexample
9478__float128 __builtin_fabsq (__float128)
9479__float128 __builtin_copysignq (__float128, __float128)
9480@end smallexample
9481
1c0d1529 9482The following built-in function is always available.
9483
9484@table @code
9485@item void __builtin_ia32_pause (void)
4d7a5fd9 9486Generates the @code{pause} machine instruction with a compiler memory
9487barrier.
1c0d1529 9488@end table
9489
c902c5c2 9490The following floating point built-in functions are made available in the
949164-bit mode.
9492
9493@table @code
9494@item __float128 __builtin_infq (void)
9495Similar to @code{__builtin_inf}, except the return type is @code{__float128}.
29c63a97 9496@findex __builtin_infq
9497
9498@item __float128 __builtin_huge_valq (void)
9499Similar to @code{__builtin_huge_val}, except the return type is @code{__float128}.
9500@findex __builtin_huge_valq
c902c5c2 9501@end table
9502
f0fd108f 9503The following built-in functions are always available and can be used to
9504check the target platform type.
9505
9506@deftypefn {Built-in Function} void __builtin_cpu_init (void)
9507This function runs the CPU detection code to check the type of CPU and the
9508features supported. This builtin needs to be invoked along with the builtins
9509to check CPU type and features, @code{__builtin_cpu_is} and
9510@code{__builtin_cpu_supports}, only when used in a function that will be
9511executed before any constructors are called. The CPU detection code is
9512automatically executed in a very high priority constructor.
9513
9514For example, this function has to be used in @code{ifunc} resolvers which
98c9b52b 9515check for CPU type using the builtins @code{__builtin_cpu_is}
9516and @code{__builtin_cpu_supports}, or in constructors on targets which
9517don't support constructor priority.
f0fd108f 9518@smallexample
9519
9520static void (*resolve_memcpy (void)) (void)
9521@{
9522 // ifunc resolvers fire before constructors, explicitly call the init
9523 // function.
9524 __builtin_cpu_init ();
9525 if (__builtin_cpu_supports ("ssse3"))
9526 return ssse3_memcpy; // super fast memcpy with ssse3 instructions.
9527 else
9528 return default_memcpy;
9529@}
9530
9531void *memcpy (void *, const void *, size_t)
9532 __attribute__ ((ifunc ("resolve_memcpy")));
9533@end smallexample
9534
9535@end deftypefn
9536
9537@deftypefn {Built-in Function} int __builtin_cpu_is (const char *@var{cpuname})
9538This function returns a positive integer if the runtime cpu is of type @var{cpuname}
9539 and returns @code{0} otherwise. The following cpu names can be detected:
9540
9541@table @samp
9542@item intel
9543Intel CPU.
9544
9545@item atom
9546Intel ATOM CPU.
9547
9548@item core2
9549Intel Core2 CPU.
9550
9551@item corei7
9552Intel Corei7 CPU.
9553
9554@item nehalem
9555Intel Corei7 Nehalem CPU.
9556
9557@item westmere
9558Intel Corei7 Westmere CPU.
9559
9560@item sandybridge
9561Intel Corei7 Sandybridge CPU.
9562
9563@item amd
9564AMD CPU.
9565
9566@item amdfam10h
9567AMD family 10h CPU.
9568
9569@item barcelona
9570AMD family 10h Barcelona CPU.
9571
9572@item shanghai
9573AMD family 10h Shanghai CPU.
9574
9575@item istanbul
9576AMD family 10h Istanbul CPU.
9577
6ef15b76 9578@item btver1
9579AMD family 14h CPU.
9580
f0fd108f 9581@item amdfam15h
9582AMD family 15h CPU.
9583
9584@item bdver1
9585AMD family 15h Bulldozer version 1.
9586
9587@item bdver2
9588AMD family 15h Bulldozer version 2.
6ef15b76 9589
9590@item btver2
9591AMD family 16h CPU.
f0fd108f 9592@end table
9593
9594Here is an example:
9595@smallexample
9596if (__builtin_cpu_is ("corei7"))
9597 @{
9598 do_corei7 (); //Corei7 specific implementation.
9599 @}
9600else
9601 @{
9602 do_generic (); //Generic implementation.
9603 @}
9604@end smallexample
9605@end deftypefn
9606
9607@deftypefn {Built-in Function} int __builtin_cpu_supports (const char *@var{feature})
9d75589a 9608This function returns a positive integer if the runtime cpu supports @var{feature}
f0fd108f 9609 and returns @code{0} otherwise. The following features can be detected:
9610
9611@table @samp
9612@item cmov
9613CMOV instruction.
9614@item mmx
9615MMX instructions.
9616@item popcnt
9617POPCNT instruction.
9618@item sse
9619SSE instructions.
9620@item sse2
9621SSE2 instructions.
9622@item sse3
9623SSE3 instructions.
9624@item ssse3
9625SSSE3 instructions.
9626@item sse4.1
9627SSE4.1 instructions.
9628@item sse4.2
9629SSE4.2 instructions.
9630@item avx
9631AVX instructions.
d79cfc15 9632@item avx2
9633AVX2 instructions.
f0fd108f 9634@end table
9635
9636Here is an example:
9637@smallexample
9638if (__builtin_cpu_supports ("popcnt"))
9639 @{
9640 asm("popcnt %1,%0" : "=r"(count) : "rm"(n) : "cc");
9641 @}
9642else
9643 @{
9644 count = generic_countbits (n); //generic implementation.
9645 @}
9646@end smallexample
9647@end deftypefn
9648
9649
ca5827cf 9650The following built-in functions are made available by @option{-mmmx}.
9651All of them generate the machine instruction that is part of the name.
9652
a0ecd6b1 9653@smallexample
ca5827cf 9654v8qi __builtin_ia32_paddb (v8qi, v8qi)
9655v4hi __builtin_ia32_paddw (v4hi, v4hi)
9656v2si __builtin_ia32_paddd (v2si, v2si)
9657v8qi __builtin_ia32_psubb (v8qi, v8qi)
9658v4hi __builtin_ia32_psubw (v4hi, v4hi)
9659v2si __builtin_ia32_psubd (v2si, v2si)
9660v8qi __builtin_ia32_paddsb (v8qi, v8qi)
9661v4hi __builtin_ia32_paddsw (v4hi, v4hi)
9662v8qi __builtin_ia32_psubsb (v8qi, v8qi)
9663v4hi __builtin_ia32_psubsw (v4hi, v4hi)
9664v8qi __builtin_ia32_paddusb (v8qi, v8qi)
9665v4hi __builtin_ia32_paddusw (v4hi, v4hi)
9666v8qi __builtin_ia32_psubusb (v8qi, v8qi)
9667v4hi __builtin_ia32_psubusw (v4hi, v4hi)
9668v4hi __builtin_ia32_pmullw (v4hi, v4hi)
9669v4hi __builtin_ia32_pmulhw (v4hi, v4hi)
9670di __builtin_ia32_pand (di, di)
9671di __builtin_ia32_pandn (di,di)
9672di __builtin_ia32_por (di, di)
9673di __builtin_ia32_pxor (di, di)
9674v8qi __builtin_ia32_pcmpeqb (v8qi, v8qi)
9675v4hi __builtin_ia32_pcmpeqw (v4hi, v4hi)
9676v2si __builtin_ia32_pcmpeqd (v2si, v2si)
9677v8qi __builtin_ia32_pcmpgtb (v8qi, v8qi)
9678v4hi __builtin_ia32_pcmpgtw (v4hi, v4hi)
9679v2si __builtin_ia32_pcmpgtd (v2si, v2si)
9680v8qi __builtin_ia32_punpckhbw (v8qi, v8qi)
9681v4hi __builtin_ia32_punpckhwd (v4hi, v4hi)
9682v2si __builtin_ia32_punpckhdq (v2si, v2si)
9683v8qi __builtin_ia32_punpcklbw (v8qi, v8qi)
9684v4hi __builtin_ia32_punpcklwd (v4hi, v4hi)
9685v2si __builtin_ia32_punpckldq (v2si, v2si)
9686v8qi __builtin_ia32_packsswb (v4hi, v4hi)
9687v4hi __builtin_ia32_packssdw (v2si, v2si)
9688v8qi __builtin_ia32_packuswb (v4hi, v4hi)
7916ca8a 9689
c9f96750 9690v4hi __builtin_ia32_psllw (v4hi, v4hi)
9691v2si __builtin_ia32_pslld (v2si, v2si)
9692v1di __builtin_ia32_psllq (v1di, v1di)
9693v4hi __builtin_ia32_psrlw (v4hi, v4hi)
9694v2si __builtin_ia32_psrld (v2si, v2si)
9695v1di __builtin_ia32_psrlq (v1di, v1di)
9696v4hi __builtin_ia32_psraw (v4hi, v4hi)
9697v2si __builtin_ia32_psrad (v2si, v2si)
9698v4hi __builtin_ia32_psllwi (v4hi, int)
9699v2si __builtin_ia32_pslldi (v2si, int)
9700v1di __builtin_ia32_psllqi (v1di, int)
9701v4hi __builtin_ia32_psrlwi (v4hi, int)
9702v2si __builtin_ia32_psrldi (v2si, int)
9703v1di __builtin_ia32_psrlqi (v1di, int)
9704v4hi __builtin_ia32_psrawi (v4hi, int)
9705v2si __builtin_ia32_psradi (v2si, int)
7916ca8a 9706
a0ecd6b1 9707@end smallexample
ca5827cf 9708
9709The following built-in functions are made available either with
9710@option{-msse}, or with a combination of @option{-m3dnow} and
9711@option{-march=athlon}. All of them generate the machine
9712instruction that is part of the name.
9713
a0ecd6b1 9714@smallexample
ca5827cf 9715v4hi __builtin_ia32_pmulhuw (v4hi, v4hi)
9716v8qi __builtin_ia32_pavgb (v8qi, v8qi)
9717v4hi __builtin_ia32_pavgw (v4hi, v4hi)
28a2ab9f 9718v1di __builtin_ia32_psadbw (v8qi, v8qi)
ca5827cf 9719v8qi __builtin_ia32_pmaxub (v8qi, v8qi)
9720v4hi __builtin_ia32_pmaxsw (v4hi, v4hi)
9721v8qi __builtin_ia32_pminub (v8qi, v8qi)
9722v4hi __builtin_ia32_pminsw (v4hi, v4hi)
9723int __builtin_ia32_pextrw (v4hi, int)
9724v4hi __builtin_ia32_pinsrw (v4hi, int, int)
9725int __builtin_ia32_pmovmskb (v8qi)
9726void __builtin_ia32_maskmovq (v8qi, v8qi, char *)
9727void __builtin_ia32_movntq (di *, di)
9728void __builtin_ia32_sfence (void)
a0ecd6b1 9729@end smallexample
ca5827cf 9730
9731The following built-in functions are available when @option{-msse} is used.
9732All of them generate the machine instruction that is part of the name.
9733
a0ecd6b1 9734@smallexample
ca5827cf 9735int __builtin_ia32_comieq (v4sf, v4sf)
9736int __builtin_ia32_comineq (v4sf, v4sf)
9737int __builtin_ia32_comilt (v4sf, v4sf)
9738int __builtin_ia32_comile (v4sf, v4sf)
9739int __builtin_ia32_comigt (v4sf, v4sf)
9740int __builtin_ia32_comige (v4sf, v4sf)
9741int __builtin_ia32_ucomieq (v4sf, v4sf)
9742int __builtin_ia32_ucomineq (v4sf, v4sf)
9743int __builtin_ia32_ucomilt (v4sf, v4sf)
9744int __builtin_ia32_ucomile (v4sf, v4sf)
9745int __builtin_ia32_ucomigt (v4sf, v4sf)
9746int __builtin_ia32_ucomige (v4sf, v4sf)
9747v4sf __builtin_ia32_addps (v4sf, v4sf)
9748v4sf __builtin_ia32_subps (v4sf, v4sf)
9749v4sf __builtin_ia32_mulps (v4sf, v4sf)
9750v4sf __builtin_ia32_divps (v4sf, v4sf)
9751v4sf __builtin_ia32_addss (v4sf, v4sf)
9752v4sf __builtin_ia32_subss (v4sf, v4sf)
9753v4sf __builtin_ia32_mulss (v4sf, v4sf)
9754v4sf __builtin_ia32_divss (v4sf, v4sf)
9755v4si __builtin_ia32_cmpeqps (v4sf, v4sf)
9756v4si __builtin_ia32_cmpltps (v4sf, v4sf)
9757v4si __builtin_ia32_cmpleps (v4sf, v4sf)
9758v4si __builtin_ia32_cmpgtps (v4sf, v4sf)
9759v4si __builtin_ia32_cmpgeps (v4sf, v4sf)
9760v4si __builtin_ia32_cmpunordps (v4sf, v4sf)
9761v4si __builtin_ia32_cmpneqps (v4sf, v4sf)
9762v4si __builtin_ia32_cmpnltps (v4sf, v4sf)
9763v4si __builtin_ia32_cmpnleps (v4sf, v4sf)
9764v4si __builtin_ia32_cmpngtps (v4sf, v4sf)
9765v4si __builtin_ia32_cmpngeps (v4sf, v4sf)
9766v4si __builtin_ia32_cmpordps (v4sf, v4sf)
9767v4si __builtin_ia32_cmpeqss (v4sf, v4sf)
9768v4si __builtin_ia32_cmpltss (v4sf, v4sf)
9769v4si __builtin_ia32_cmpless (v4sf, v4sf)
ca5827cf 9770v4si __builtin_ia32_cmpunordss (v4sf, v4sf)
9771v4si __builtin_ia32_cmpneqss (v4sf, v4sf)
9772v4si __builtin_ia32_cmpnlts (v4sf, v4sf)
9773v4si __builtin_ia32_cmpnless (v4sf, v4sf)
ca5827cf 9774v4si __builtin_ia32_cmpordss (v4sf, v4sf)
9775v4sf __builtin_ia32_maxps (v4sf, v4sf)
9776v4sf __builtin_ia32_maxss (v4sf, v4sf)
9777v4sf __builtin_ia32_minps (v4sf, v4sf)
9778v4sf __builtin_ia32_minss (v4sf, v4sf)
9779v4sf __builtin_ia32_andps (v4sf, v4sf)
9780v4sf __builtin_ia32_andnps (v4sf, v4sf)
9781v4sf __builtin_ia32_orps (v4sf, v4sf)
9782v4sf __builtin_ia32_xorps (v4sf, v4sf)
9783v4sf __builtin_ia32_movss (v4sf, v4sf)
9784v4sf __builtin_ia32_movhlps (v4sf, v4sf)
9785v4sf __builtin_ia32_movlhps (v4sf, v4sf)
9786v4sf __builtin_ia32_unpckhps (v4sf, v4sf)
9787v4sf __builtin_ia32_unpcklps (v4sf, v4sf)
9788v4sf __builtin_ia32_cvtpi2ps (v4sf, v2si)
9789v4sf __builtin_ia32_cvtsi2ss (v4sf, int)
9790v2si __builtin_ia32_cvtps2pi (v4sf)
9791int __builtin_ia32_cvtss2si (v4sf)
9792v2si __builtin_ia32_cvttps2pi (v4sf)
9793int __builtin_ia32_cvttss2si (v4sf)
9794v4sf __builtin_ia32_rcpps (v4sf)
9795v4sf __builtin_ia32_rsqrtps (v4sf)
9796v4sf __builtin_ia32_sqrtps (v4sf)
9797v4sf __builtin_ia32_rcpss (v4sf)
9798v4sf __builtin_ia32_rsqrtss (v4sf)
9799v4sf __builtin_ia32_sqrtss (v4sf)
9800v4sf __builtin_ia32_shufps (v4sf, v4sf, int)
9801void __builtin_ia32_movntps (float *, v4sf)
9802int __builtin_ia32_movmskps (v4sf)
a0ecd6b1 9803@end smallexample
ca5827cf 9804
9805The following built-in functions are available when @option{-msse} is used.
9806
9807@table @code
9808@item v4sf __builtin_ia32_loadaps (float *)
9809Generates the @code{movaps} machine instruction as a load from memory.
9810@item void __builtin_ia32_storeaps (float *, v4sf)
9811Generates the @code{movaps} machine instruction as a store to memory.
9812@item v4sf __builtin_ia32_loadups (float *)
9813Generates the @code{movups} machine instruction as a load from memory.
9814@item void __builtin_ia32_storeups (float *, v4sf)
9815Generates the @code{movups} machine instruction as a store to memory.
9816@item v4sf __builtin_ia32_loadsss (float *)
9817Generates the @code{movss} machine instruction as a load from memory.
9818@item void __builtin_ia32_storess (float *, v4sf)
9819Generates the @code{movss} machine instruction as a store to memory.
875a66b2 9820@item v4sf __builtin_ia32_loadhps (v4sf, const v2sf *)
ca5827cf 9821Generates the @code{movhps} machine instruction as a load from memory.
875a66b2 9822@item v4sf __builtin_ia32_loadlps (v4sf, const v2sf *)
ca5827cf 9823Generates the @code{movlps} machine instruction as a load from memory
875a66b2 9824@item void __builtin_ia32_storehps (v2sf *, v4sf)
ca5827cf 9825Generates the @code{movhps} machine instruction as a store to memory.
875a66b2 9826@item void __builtin_ia32_storelps (v2sf *, v4sf)
ca5827cf 9827Generates the @code{movlps} machine instruction as a store to memory.
9828@end table
9829
e2d5ef68 9830The following built-in functions are available when @option{-msse2} is used.
9831All of them generate the machine instruction that is part of the name.
9832
9833@smallexample
9834int __builtin_ia32_comisdeq (v2df, v2df)
9835int __builtin_ia32_comisdlt (v2df, v2df)
9836int __builtin_ia32_comisdle (v2df, v2df)
9837int __builtin_ia32_comisdgt (v2df, v2df)
9838int __builtin_ia32_comisdge (v2df, v2df)
9839int __builtin_ia32_comisdneq (v2df, v2df)
9840int __builtin_ia32_ucomisdeq (v2df, v2df)
9841int __builtin_ia32_ucomisdlt (v2df, v2df)
9842int __builtin_ia32_ucomisdle (v2df, v2df)
9843int __builtin_ia32_ucomisdgt (v2df, v2df)
9844int __builtin_ia32_ucomisdge (v2df, v2df)
9845int __builtin_ia32_ucomisdneq (v2df, v2df)
9846v2df __builtin_ia32_cmpeqpd (v2df, v2df)
9847v2df __builtin_ia32_cmpltpd (v2df, v2df)
9848v2df __builtin_ia32_cmplepd (v2df, v2df)
9849v2df __builtin_ia32_cmpgtpd (v2df, v2df)
9850v2df __builtin_ia32_cmpgepd (v2df, v2df)
9851v2df __builtin_ia32_cmpunordpd (v2df, v2df)
9852v2df __builtin_ia32_cmpneqpd (v2df, v2df)
9853v2df __builtin_ia32_cmpnltpd (v2df, v2df)
9854v2df __builtin_ia32_cmpnlepd (v2df, v2df)
9855v2df __builtin_ia32_cmpngtpd (v2df, v2df)
9856v2df __builtin_ia32_cmpngepd (v2df, v2df)
9857v2df __builtin_ia32_cmpordpd (v2df, v2df)
9858v2df __builtin_ia32_cmpeqsd (v2df, v2df)
9859v2df __builtin_ia32_cmpltsd (v2df, v2df)
9860v2df __builtin_ia32_cmplesd (v2df, v2df)
9861v2df __builtin_ia32_cmpunordsd (v2df, v2df)
9862v2df __builtin_ia32_cmpneqsd (v2df, v2df)
9863v2df __builtin_ia32_cmpnltsd (v2df, v2df)
9864v2df __builtin_ia32_cmpnlesd (v2df, v2df)
9865v2df __builtin_ia32_cmpordsd (v2df, v2df)
9866v2di __builtin_ia32_paddq (v2di, v2di)
9867v2di __builtin_ia32_psubq (v2di, v2di)
9868v2df __builtin_ia32_addpd (v2df, v2df)
9869v2df __builtin_ia32_subpd (v2df, v2df)
9870v2df __builtin_ia32_mulpd (v2df, v2df)
9871v2df __builtin_ia32_divpd (v2df, v2df)
9872v2df __builtin_ia32_addsd (v2df, v2df)
9873v2df __builtin_ia32_subsd (v2df, v2df)
9874v2df __builtin_ia32_mulsd (v2df, v2df)
9875v2df __builtin_ia32_divsd (v2df, v2df)
9876v2df __builtin_ia32_minpd (v2df, v2df)
9877v2df __builtin_ia32_maxpd (v2df, v2df)
9878v2df __builtin_ia32_minsd (v2df, v2df)
9879v2df __builtin_ia32_maxsd (v2df, v2df)
9880v2df __builtin_ia32_andpd (v2df, v2df)
9881v2df __builtin_ia32_andnpd (v2df, v2df)
9882v2df __builtin_ia32_orpd (v2df, v2df)
9883v2df __builtin_ia32_xorpd (v2df, v2df)
9884v2df __builtin_ia32_movsd (v2df, v2df)
9885v2df __builtin_ia32_unpckhpd (v2df, v2df)
9886v2df __builtin_ia32_unpcklpd (v2df, v2df)
9887v16qi __builtin_ia32_paddb128 (v16qi, v16qi)
9888v8hi __builtin_ia32_paddw128 (v8hi, v8hi)
9889v4si __builtin_ia32_paddd128 (v4si, v4si)
9890v2di __builtin_ia32_paddq128 (v2di, v2di)
9891v16qi __builtin_ia32_psubb128 (v16qi, v16qi)
9892v8hi __builtin_ia32_psubw128 (v8hi, v8hi)
9893v4si __builtin_ia32_psubd128 (v4si, v4si)
9894v2di __builtin_ia32_psubq128 (v2di, v2di)
9895v8hi __builtin_ia32_pmullw128 (v8hi, v8hi)
9896v8hi __builtin_ia32_pmulhw128 (v8hi, v8hi)
9897v2di __builtin_ia32_pand128 (v2di, v2di)
9898v2di __builtin_ia32_pandn128 (v2di, v2di)
9899v2di __builtin_ia32_por128 (v2di, v2di)
9900v2di __builtin_ia32_pxor128 (v2di, v2di)
9901v16qi __builtin_ia32_pavgb128 (v16qi, v16qi)
9902v8hi __builtin_ia32_pavgw128 (v8hi, v8hi)
9903v16qi __builtin_ia32_pcmpeqb128 (v16qi, v16qi)
9904v8hi __builtin_ia32_pcmpeqw128 (v8hi, v8hi)
9905v4si __builtin_ia32_pcmpeqd128 (v4si, v4si)
9906v16qi __builtin_ia32_pcmpgtb128 (v16qi, v16qi)
9907v8hi __builtin_ia32_pcmpgtw128 (v8hi, v8hi)
9908v4si __builtin_ia32_pcmpgtd128 (v4si, v4si)
9909v16qi __builtin_ia32_pmaxub128 (v16qi, v16qi)
9910v8hi __builtin_ia32_pmaxsw128 (v8hi, v8hi)
9911v16qi __builtin_ia32_pminub128 (v16qi, v16qi)
9912v8hi __builtin_ia32_pminsw128 (v8hi, v8hi)
9913v16qi __builtin_ia32_punpckhbw128 (v16qi, v16qi)
9914v8hi __builtin_ia32_punpckhwd128 (v8hi, v8hi)
9915v4si __builtin_ia32_punpckhdq128 (v4si, v4si)
9916v2di __builtin_ia32_punpckhqdq128 (v2di, v2di)
9917v16qi __builtin_ia32_punpcklbw128 (v16qi, v16qi)
9918v8hi __builtin_ia32_punpcklwd128 (v8hi, v8hi)
9919v4si __builtin_ia32_punpckldq128 (v4si, v4si)
9920v2di __builtin_ia32_punpcklqdq128 (v2di, v2di)
6f50184d 9921v16qi __builtin_ia32_packsswb128 (v8hi, v8hi)
9922v8hi __builtin_ia32_packssdw128 (v4si, v4si)
9923v16qi __builtin_ia32_packuswb128 (v8hi, v8hi)
e2d5ef68 9924v8hi __builtin_ia32_pmulhuw128 (v8hi, v8hi)
9925void __builtin_ia32_maskmovdqu (v16qi, v16qi)
9926v2df __builtin_ia32_loadupd (double *)
9927void __builtin_ia32_storeupd (double *, v2df)
875a66b2 9928v2df __builtin_ia32_loadhpd (v2df, double const *)
9929v2df __builtin_ia32_loadlpd (v2df, double const *)
e2d5ef68 9930int __builtin_ia32_movmskpd (v2df)
9931int __builtin_ia32_pmovmskb128 (v16qi)
9932void __builtin_ia32_movnti (int *, int)
821b85a2 9933void __builtin_ia32_movnti64 (long long int *, long long int)
e2d5ef68 9934void __builtin_ia32_movntpd (double *, v2df)
9935void __builtin_ia32_movntdq (v2df *, v2df)
9936v4si __builtin_ia32_pshufd (v4si, int)
9937v8hi __builtin_ia32_pshuflw (v8hi, int)
9938v8hi __builtin_ia32_pshufhw (v8hi, int)
9939v2di __builtin_ia32_psadbw128 (v16qi, v16qi)
9940v2df __builtin_ia32_sqrtpd (v2df)
9941v2df __builtin_ia32_sqrtsd (v2df)
9942v2df __builtin_ia32_shufpd (v2df, v2df, int)
9943v2df __builtin_ia32_cvtdq2pd (v4si)
9944v4sf __builtin_ia32_cvtdq2ps (v4si)
9945v4si __builtin_ia32_cvtpd2dq (v2df)
9946v2si __builtin_ia32_cvtpd2pi (v2df)
9947v4sf __builtin_ia32_cvtpd2ps (v2df)
9948v4si __builtin_ia32_cvttpd2dq (v2df)
9949v2si __builtin_ia32_cvttpd2pi (v2df)
9950v2df __builtin_ia32_cvtpi2pd (v2si)
9951int __builtin_ia32_cvtsd2si (v2df)
9952int __builtin_ia32_cvttsd2si (v2df)
9953long long __builtin_ia32_cvtsd2si64 (v2df)
9954long long __builtin_ia32_cvttsd2si64 (v2df)
9955v4si __builtin_ia32_cvtps2dq (v4sf)
9956v2df __builtin_ia32_cvtps2pd (v4sf)
9957v4si __builtin_ia32_cvttps2dq (v4sf)
9958v2df __builtin_ia32_cvtsi2sd (v2df, int)
9959v2df __builtin_ia32_cvtsi642sd (v2df, long long)
9960v4sf __builtin_ia32_cvtsd2ss (v4sf, v2df)
9961v2df __builtin_ia32_cvtss2sd (v2df, v4sf)
9962void __builtin_ia32_clflush (const void *)
9963void __builtin_ia32_lfence (void)
9964void __builtin_ia32_mfence (void)
9965v16qi __builtin_ia32_loaddqu (const char *)
9966void __builtin_ia32_storedqu (char *, v16qi)
28a2ab9f 9967v1di __builtin_ia32_pmuludq (v2si, v2si)
e2d5ef68 9968v2di __builtin_ia32_pmuludq128 (v4si, v4si)
c9f96750 9969v8hi __builtin_ia32_psllw128 (v8hi, v8hi)
9970v4si __builtin_ia32_pslld128 (v4si, v4si)
9971v2di __builtin_ia32_psllq128 (v2di, v2di)
9972v8hi __builtin_ia32_psrlw128 (v8hi, v8hi)
9973v4si __builtin_ia32_psrld128 (v4si, v4si)
e2d5ef68 9974v2di __builtin_ia32_psrlq128 (v2di, v2di)
c9f96750 9975v8hi __builtin_ia32_psraw128 (v8hi, v8hi)
9976v4si __builtin_ia32_psrad128 (v4si, v4si)
e2d5ef68 9977v2di __builtin_ia32_pslldqi128 (v2di, int)
9978v8hi __builtin_ia32_psllwi128 (v8hi, int)
9979v4si __builtin_ia32_pslldi128 (v4si, int)
9980v2di __builtin_ia32_psllqi128 (v2di, int)
9981v2di __builtin_ia32_psrldqi128 (v2di, int)
9982v8hi __builtin_ia32_psrlwi128 (v8hi, int)
9983v4si __builtin_ia32_psrldi128 (v4si, int)
9984v2di __builtin_ia32_psrlqi128 (v2di, int)
9985v8hi __builtin_ia32_psrawi128 (v8hi, int)
9986v4si __builtin_ia32_psradi128 (v4si, int)
9987v4si __builtin_ia32_pmaddwd128 (v8hi, v8hi)
c578ed7f 9988v2di __builtin_ia32_movq128 (v2di)
e2d5ef68 9989@end smallexample
9990
4aafbf22 9991The following built-in functions are available when @option{-msse3} is used.
754c06ac 9992All of them generate the machine instruction that is part of the name.
9993
a0ecd6b1 9994@smallexample
754c06ac 9995v2df __builtin_ia32_addsubpd (v2df, v2df)
e2d5ef68 9996v4sf __builtin_ia32_addsubps (v4sf, v4sf)
754c06ac 9997v2df __builtin_ia32_haddpd (v2df, v2df)
e2d5ef68 9998v4sf __builtin_ia32_haddps (v4sf, v4sf)
754c06ac 9999v2df __builtin_ia32_hsubpd (v2df, v2df)
e2d5ef68 10000v4sf __builtin_ia32_hsubps (v4sf, v4sf)
754c06ac 10001v16qi __builtin_ia32_lddqu (char const *)
10002void __builtin_ia32_monitor (void *, unsigned int, unsigned int)
10003v2df __builtin_ia32_movddup (v2df)
10004v4sf __builtin_ia32_movshdup (v4sf)
10005v4sf __builtin_ia32_movsldup (v4sf)
10006void __builtin_ia32_mwait (unsigned int, unsigned int)
a0ecd6b1 10007@end smallexample
754c06ac 10008
4aafbf22 10009The following built-in functions are available when @option{-msse3} is used.
754c06ac 10010
10011@table @code
10012@item v2df __builtin_ia32_loadddup (double const *)
10013Generates the @code{movddup} machine instruction as a load from memory.
10014@end table
10015
2b4894c5 10016The following built-in functions are available when @option{-mssse3} is used.
10017All of them generate the machine instruction that is part of the name
10018with MMX registers.
10019
10020@smallexample
10021v2si __builtin_ia32_phaddd (v2si, v2si)
10022v4hi __builtin_ia32_phaddw (v4hi, v4hi)
10023v4hi __builtin_ia32_phaddsw (v4hi, v4hi)
10024v2si __builtin_ia32_phsubd (v2si, v2si)
10025v4hi __builtin_ia32_phsubw (v4hi, v4hi)
10026v4hi __builtin_ia32_phsubsw (v4hi, v4hi)
6f50184d 10027v4hi __builtin_ia32_pmaddubsw (v8qi, v8qi)
2b4894c5 10028v4hi __builtin_ia32_pmulhrsw (v4hi, v4hi)
10029v8qi __builtin_ia32_pshufb (v8qi, v8qi)
10030v8qi __builtin_ia32_psignb (v8qi, v8qi)
10031v2si __builtin_ia32_psignd (v2si, v2si)
10032v4hi __builtin_ia32_psignw (v4hi, v4hi)
49698f18 10033v1di __builtin_ia32_palignr (v1di, v1di, int)
2b4894c5 10034v8qi __builtin_ia32_pabsb (v8qi)
10035v2si __builtin_ia32_pabsd (v2si)
10036v4hi __builtin_ia32_pabsw (v4hi)
10037@end smallexample
10038
10039The following built-in functions are available when @option{-mssse3} is used.
10040All of them generate the machine instruction that is part of the name
10041with SSE registers.
10042
10043@smallexample
10044v4si __builtin_ia32_phaddd128 (v4si, v4si)
10045v8hi __builtin_ia32_phaddw128 (v8hi, v8hi)
10046v8hi __builtin_ia32_phaddsw128 (v8hi, v8hi)
10047v4si __builtin_ia32_phsubd128 (v4si, v4si)
10048v8hi __builtin_ia32_phsubw128 (v8hi, v8hi)
10049v8hi __builtin_ia32_phsubsw128 (v8hi, v8hi)
6f50184d 10050v8hi __builtin_ia32_pmaddubsw128 (v16qi, v16qi)
2b4894c5 10051v8hi __builtin_ia32_pmulhrsw128 (v8hi, v8hi)
10052v16qi __builtin_ia32_pshufb128 (v16qi, v16qi)
10053v16qi __builtin_ia32_psignb128 (v16qi, v16qi)
10054v4si __builtin_ia32_psignd128 (v4si, v4si)
10055v8hi __builtin_ia32_psignw128 (v8hi, v8hi)
30063220 10056v2di __builtin_ia32_palignr128 (v2di, v2di, int)
2b4894c5 10057v16qi __builtin_ia32_pabsb128 (v16qi)
10058v4si __builtin_ia32_pabsd128 (v4si)
10059v8hi __builtin_ia32_pabsw128 (v8hi)
10060@end smallexample
10061
2d771892 10062The following built-in functions are available when @option{-msse4.1} is
10063used. All of them generate the machine instruction that is part of the
10064name.
10065
10066@smallexample
10067v2df __builtin_ia32_blendpd (v2df, v2df, const int)
10068v4sf __builtin_ia32_blendps (v4sf, v4sf, const int)
10069v2df __builtin_ia32_blendvpd (v2df, v2df, v2df)
10070v4sf __builtin_ia32_blendvps (v4sf, v4sf, v4sf)
e6fc1977 10071v2df __builtin_ia32_dppd (v2df, v2df, const int)
2d771892 10072v4sf __builtin_ia32_dpps (v4sf, v4sf, const int)
10073v4sf __builtin_ia32_insertps128 (v4sf, v4sf, const int)
10074v2di __builtin_ia32_movntdqa (v2di *);
10075v16qi __builtin_ia32_mpsadbw128 (v16qi, v16qi, const int)
10076v8hi __builtin_ia32_packusdw128 (v4si, v4si)
10077v16qi __builtin_ia32_pblendvb128 (v16qi, v16qi, v16qi)
10078v8hi __builtin_ia32_pblendw128 (v8hi, v8hi, const int)
10079v2di __builtin_ia32_pcmpeqq (v2di, v2di)
10080v8hi __builtin_ia32_phminposuw128 (v8hi)
10081v16qi __builtin_ia32_pmaxsb128 (v16qi, v16qi)
10082v4si __builtin_ia32_pmaxsd128 (v4si, v4si)
10083v4si __builtin_ia32_pmaxud128 (v4si, v4si)
10084v8hi __builtin_ia32_pmaxuw128 (v8hi, v8hi)
10085v16qi __builtin_ia32_pminsb128 (v16qi, v16qi)
10086v4si __builtin_ia32_pminsd128 (v4si, v4si)
10087v4si __builtin_ia32_pminud128 (v4si, v4si)
10088v8hi __builtin_ia32_pminuw128 (v8hi, v8hi)
10089v4si __builtin_ia32_pmovsxbd128 (v16qi)
10090v2di __builtin_ia32_pmovsxbq128 (v16qi)
10091v8hi __builtin_ia32_pmovsxbw128 (v16qi)
10092v2di __builtin_ia32_pmovsxdq128 (v4si)
10093v4si __builtin_ia32_pmovsxwd128 (v8hi)
10094v2di __builtin_ia32_pmovsxwq128 (v8hi)
10095v4si __builtin_ia32_pmovzxbd128 (v16qi)
10096v2di __builtin_ia32_pmovzxbq128 (v16qi)
10097v8hi __builtin_ia32_pmovzxbw128 (v16qi)
10098v2di __builtin_ia32_pmovzxdq128 (v4si)
10099v4si __builtin_ia32_pmovzxwd128 (v8hi)
10100v2di __builtin_ia32_pmovzxwq128 (v8hi)
10101v2di __builtin_ia32_pmuldq128 (v4si, v4si)
10102v4si __builtin_ia32_pmulld128 (v4si, v4si)
10103int __builtin_ia32_ptestc128 (v2di, v2di)
10104int __builtin_ia32_ptestnzc128 (v2di, v2di)
10105int __builtin_ia32_ptestz128 (v2di, v2di)
10106v2df __builtin_ia32_roundpd (v2df, const int)
10107v4sf __builtin_ia32_roundps (v4sf, const int)
10108v2df __builtin_ia32_roundsd (v2df, v2df, const int)
10109v4sf __builtin_ia32_roundss (v4sf, v4sf, const int)
10110@end smallexample
10111
10112The following built-in functions are available when @option{-msse4.1} is
10113used.
10114
10115@table @code
10116@item v4sf __builtin_ia32_vec_set_v4sf (v4sf, float, const int)
10117Generates the @code{insertps} machine instruction.
10118@item int __builtin_ia32_vec_ext_v16qi (v16qi, const int)
10119Generates the @code{pextrb} machine instruction.
10120@item v16qi __builtin_ia32_vec_set_v16qi (v16qi, int, const int)
10121Generates the @code{pinsrb} machine instruction.
10122@item v4si __builtin_ia32_vec_set_v4si (v4si, int, const int)
10123Generates the @code{pinsrd} machine instruction.
10124@item v2di __builtin_ia32_vec_set_v2di (v2di, long long, const int)
10125Generates the @code{pinsrq} machine instruction in 64bit mode.
10126@end table
10127
10128The following built-in functions are changed to generate new SSE4.1
10129instructions when @option{-msse4.1} is used.
10130
10131@table @code
10132@item float __builtin_ia32_vec_ext_v4sf (v4sf, const int)
10133Generates the @code{extractps} machine instruction.
10134@item int __builtin_ia32_vec_ext_v4si (v4si, const int)
10135Generates the @code{pextrd} machine instruction.
10136@item long long __builtin_ia32_vec_ext_v2di (v2di, const int)
10137Generates the @code{pextrq} machine instruction in 64bit mode.
10138@end table
10139
f25d51c3 10140The following built-in functions are available when @option{-msse4.2} is
10141used. All of them generate the machine instruction that is part of the
10142name.
10143
10144@smallexample
10145v16qi __builtin_ia32_pcmpestrm128 (v16qi, int, v16qi, int, const int)
10146int __builtin_ia32_pcmpestri128 (v16qi, int, v16qi, int, const int)
10147int __builtin_ia32_pcmpestria128 (v16qi, int, v16qi, int, const int)
10148int __builtin_ia32_pcmpestric128 (v16qi, int, v16qi, int, const int)
10149int __builtin_ia32_pcmpestrio128 (v16qi, int, v16qi, int, const int)
10150int __builtin_ia32_pcmpestris128 (v16qi, int, v16qi, int, const int)
10151int __builtin_ia32_pcmpestriz128 (v16qi, int, v16qi, int, const int)
10152v16qi __builtin_ia32_pcmpistrm128 (v16qi, v16qi, const int)
10153int __builtin_ia32_pcmpistri128 (v16qi, v16qi, const int)
10154int __builtin_ia32_pcmpistria128 (v16qi, v16qi, const int)
10155int __builtin_ia32_pcmpistric128 (v16qi, v16qi, const int)
10156int __builtin_ia32_pcmpistrio128 (v16qi, v16qi, const int)
10157int __builtin_ia32_pcmpistris128 (v16qi, v16qi, const int)
10158int __builtin_ia32_pcmpistriz128 (v16qi, v16qi, const int)
e6fc1977 10159v2di __builtin_ia32_pcmpgtq (v2di, v2di)
f25d51c3 10160@end smallexample
10161
10162The following built-in functions are available when @option{-msse4.2} is
10163used.
10164
10165@table @code
e6fc1977 10166@item unsigned int __builtin_ia32_crc32qi (unsigned int, unsigned char)
f25d51c3 10167Generates the @code{crc32b} machine instruction.
e6fc1977 10168@item unsigned int __builtin_ia32_crc32hi (unsigned int, unsigned short)
f25d51c3 10169Generates the @code{crc32w} machine instruction.
e6fc1977 10170@item unsigned int __builtin_ia32_crc32si (unsigned int, unsigned int)
f25d51c3 10171Generates the @code{crc32l} machine instruction.
2424d00f 10172@item unsigned long long __builtin_ia32_crc32di (unsigned long long, unsigned long long)
9e26132e 10173Generates the @code{crc32q} machine instruction.
f25d51c3 10174@end table
10175
10176The following built-in functions are changed to generate new SSE4.2
10177instructions when @option{-msse4.2} is used.
10178
10179@table @code
e6fc1977 10180@item int __builtin_popcount (unsigned int)
f25d51c3 10181Generates the @code{popcntl} machine instruction.
e6fc1977 10182@item int __builtin_popcountl (unsigned long)
f25d51c3 10183Generates the @code{popcntl} or @code{popcntq} machine instruction,
10184depending on the size of @code{unsigned long}.
e6fc1977 10185@item int __builtin_popcountll (unsigned long long)
f25d51c3 10186Generates the @code{popcntq} machine instruction.
10187@end table
10188
f6c7e4af 10189The following built-in functions are available when @option{-mavx} is
10190used. All of them generate the machine instruction that is part of the
10191name.
10192
10193@smallexample
10194v4df __builtin_ia32_addpd256 (v4df,v4df)
10195v8sf __builtin_ia32_addps256 (v8sf,v8sf)
10196v4df __builtin_ia32_addsubpd256 (v4df,v4df)
10197v8sf __builtin_ia32_addsubps256 (v8sf,v8sf)
10198v4df __builtin_ia32_andnpd256 (v4df,v4df)
10199v8sf __builtin_ia32_andnps256 (v8sf,v8sf)
10200v4df __builtin_ia32_andpd256 (v4df,v4df)
10201v8sf __builtin_ia32_andps256 (v8sf,v8sf)
10202v4df __builtin_ia32_blendpd256 (v4df,v4df,int)
10203v8sf __builtin_ia32_blendps256 (v8sf,v8sf,int)
10204v4df __builtin_ia32_blendvpd256 (v4df,v4df,v4df)
10205v8sf __builtin_ia32_blendvps256 (v8sf,v8sf,v8sf)
10206v2df __builtin_ia32_cmppd (v2df,v2df,int)
10207v4df __builtin_ia32_cmppd256 (v4df,v4df,int)
10208v4sf __builtin_ia32_cmpps (v4sf,v4sf,int)
10209v8sf __builtin_ia32_cmpps256 (v8sf,v8sf,int)
10210v2df __builtin_ia32_cmpsd (v2df,v2df,int)
10211v4sf __builtin_ia32_cmpss (v4sf,v4sf,int)
10212v4df __builtin_ia32_cvtdq2pd256 (v4si)
10213v8sf __builtin_ia32_cvtdq2ps256 (v8si)
10214v4si __builtin_ia32_cvtpd2dq256 (v4df)
10215v4sf __builtin_ia32_cvtpd2ps256 (v4df)
10216v8si __builtin_ia32_cvtps2dq256 (v8sf)
10217v4df __builtin_ia32_cvtps2pd256 (v4sf)
10218v4si __builtin_ia32_cvttpd2dq256 (v4df)
10219v8si __builtin_ia32_cvttps2dq256 (v8sf)
10220v4df __builtin_ia32_divpd256 (v4df,v4df)
10221v8sf __builtin_ia32_divps256 (v8sf,v8sf)
10222v8sf __builtin_ia32_dpps256 (v8sf,v8sf,int)
10223v4df __builtin_ia32_haddpd256 (v4df,v4df)
10224v8sf __builtin_ia32_haddps256 (v8sf,v8sf)
10225v4df __builtin_ia32_hsubpd256 (v4df,v4df)
10226v8sf __builtin_ia32_hsubps256 (v8sf,v8sf)
10227v32qi __builtin_ia32_lddqu256 (pcchar)
10228v32qi __builtin_ia32_loaddqu256 (pcchar)
10229v4df __builtin_ia32_loadupd256 (pcdouble)
10230v8sf __builtin_ia32_loadups256 (pcfloat)
10231v2df __builtin_ia32_maskloadpd (pcv2df,v2df)
10232v4df __builtin_ia32_maskloadpd256 (pcv4df,v4df)
10233v4sf __builtin_ia32_maskloadps (pcv4sf,v4sf)
10234v8sf __builtin_ia32_maskloadps256 (pcv8sf,v8sf)
10235void __builtin_ia32_maskstorepd (pv2df,v2df,v2df)
10236void __builtin_ia32_maskstorepd256 (pv4df,v4df,v4df)
10237void __builtin_ia32_maskstoreps (pv4sf,v4sf,v4sf)
10238void __builtin_ia32_maskstoreps256 (pv8sf,v8sf,v8sf)
10239v4df __builtin_ia32_maxpd256 (v4df,v4df)
10240v8sf __builtin_ia32_maxps256 (v8sf,v8sf)
10241v4df __builtin_ia32_minpd256 (v4df,v4df)
10242v8sf __builtin_ia32_minps256 (v8sf,v8sf)
10243v4df __builtin_ia32_movddup256 (v4df)
10244int __builtin_ia32_movmskpd256 (v4df)
10245int __builtin_ia32_movmskps256 (v8sf)
10246v8sf __builtin_ia32_movshdup256 (v8sf)
10247v8sf __builtin_ia32_movsldup256 (v8sf)
10248v4df __builtin_ia32_mulpd256 (v4df,v4df)
10249v8sf __builtin_ia32_mulps256 (v8sf,v8sf)
10250v4df __builtin_ia32_orpd256 (v4df,v4df)
10251v8sf __builtin_ia32_orps256 (v8sf,v8sf)
10252v2df __builtin_ia32_pd_pd256 (v4df)
10253v4df __builtin_ia32_pd256_pd (v2df)
10254v4sf __builtin_ia32_ps_ps256 (v8sf)
10255v8sf __builtin_ia32_ps256_ps (v4sf)
10256int __builtin_ia32_ptestc256 (v4di,v4di,ptest)
10257int __builtin_ia32_ptestnzc256 (v4di,v4di,ptest)
10258int __builtin_ia32_ptestz256 (v4di,v4di,ptest)
10259v8sf __builtin_ia32_rcpps256 (v8sf)
10260v4df __builtin_ia32_roundpd256 (v4df,int)
10261v8sf __builtin_ia32_roundps256 (v8sf,int)
10262v8sf __builtin_ia32_rsqrtps_nr256 (v8sf)
10263v8sf __builtin_ia32_rsqrtps256 (v8sf)
10264v4df __builtin_ia32_shufpd256 (v4df,v4df,int)
10265v8sf __builtin_ia32_shufps256 (v8sf,v8sf,int)
10266v4si __builtin_ia32_si_si256 (v8si)
10267v8si __builtin_ia32_si256_si (v4si)
10268v4df __builtin_ia32_sqrtpd256 (v4df)
10269v8sf __builtin_ia32_sqrtps_nr256 (v8sf)
10270v8sf __builtin_ia32_sqrtps256 (v8sf)
10271void __builtin_ia32_storedqu256 (pchar,v32qi)
10272void __builtin_ia32_storeupd256 (pdouble,v4df)
10273void __builtin_ia32_storeups256 (pfloat,v8sf)
10274v4df __builtin_ia32_subpd256 (v4df,v4df)
10275v8sf __builtin_ia32_subps256 (v8sf,v8sf)
10276v4df __builtin_ia32_unpckhpd256 (v4df,v4df)
10277v8sf __builtin_ia32_unpckhps256 (v8sf,v8sf)
10278v4df __builtin_ia32_unpcklpd256 (v4df,v4df)
10279v8sf __builtin_ia32_unpcklps256 (v8sf,v8sf)
10280v4df __builtin_ia32_vbroadcastf128_pd256 (pcv2df)
10281v8sf __builtin_ia32_vbroadcastf128_ps256 (pcv4sf)
10282v4df __builtin_ia32_vbroadcastsd256 (pcdouble)
10283v4sf __builtin_ia32_vbroadcastss (pcfloat)
10284v8sf __builtin_ia32_vbroadcastss256 (pcfloat)
10285v2df __builtin_ia32_vextractf128_pd256 (v4df,int)
10286v4sf __builtin_ia32_vextractf128_ps256 (v8sf,int)
10287v4si __builtin_ia32_vextractf128_si256 (v8si,int)
10288v4df __builtin_ia32_vinsertf128_pd256 (v4df,v2df,int)
10289v8sf __builtin_ia32_vinsertf128_ps256 (v8sf,v4sf,int)
10290v8si __builtin_ia32_vinsertf128_si256 (v8si,v4si,int)
10291v4df __builtin_ia32_vperm2f128_pd256 (v4df,v4df,int)
10292v8sf __builtin_ia32_vperm2f128_ps256 (v8sf,v8sf,int)
10293v8si __builtin_ia32_vperm2f128_si256 (v8si,v8si,int)
10294v2df __builtin_ia32_vpermil2pd (v2df,v2df,v2di,int)
10295v4df __builtin_ia32_vpermil2pd256 (v4df,v4df,v4di,int)
10296v4sf __builtin_ia32_vpermil2ps (v4sf,v4sf,v4si,int)
10297v8sf __builtin_ia32_vpermil2ps256 (v8sf,v8sf,v8si,int)
10298v2df __builtin_ia32_vpermilpd (v2df,int)
10299v4df __builtin_ia32_vpermilpd256 (v4df,int)
10300v4sf __builtin_ia32_vpermilps (v4sf,int)
10301v8sf __builtin_ia32_vpermilps256 (v8sf,int)
10302v2df __builtin_ia32_vpermilvarpd (v2df,v2di)
10303v4df __builtin_ia32_vpermilvarpd256 (v4df,v4di)
10304v4sf __builtin_ia32_vpermilvarps (v4sf,v4si)
10305v8sf __builtin_ia32_vpermilvarps256 (v8sf,v8si)
10306int __builtin_ia32_vtestcpd (v2df,v2df,ptest)
10307int __builtin_ia32_vtestcpd256 (v4df,v4df,ptest)
10308int __builtin_ia32_vtestcps (v4sf,v4sf,ptest)
10309int __builtin_ia32_vtestcps256 (v8sf,v8sf,ptest)
10310int __builtin_ia32_vtestnzcpd (v2df,v2df,ptest)
10311int __builtin_ia32_vtestnzcpd256 (v4df,v4df,ptest)
10312int __builtin_ia32_vtestnzcps (v4sf,v4sf,ptest)
10313int __builtin_ia32_vtestnzcps256 (v8sf,v8sf,ptest)
10314int __builtin_ia32_vtestzpd (v2df,v2df,ptest)
10315int __builtin_ia32_vtestzpd256 (v4df,v4df,ptest)
10316int __builtin_ia32_vtestzps (v4sf,v4sf,ptest)
10317int __builtin_ia32_vtestzps256 (v8sf,v8sf,ptest)
10318void __builtin_ia32_vzeroall (void)
10319void __builtin_ia32_vzeroupper (void)
10320v4df __builtin_ia32_xorpd256 (v4df,v4df)
10321v8sf __builtin_ia32_xorps256 (v8sf,v8sf)
10322@end smallexample
10323
5deb404d 10324The following built-in functions are available when @option{-mavx2} is
10325used. All of them generate the machine instruction that is part of the
10326name.
10327
10328@smallexample
10329v32qi __builtin_ia32_mpsadbw256 (v32qi,v32qi,v32qi,int)
10330v32qi __builtin_ia32_pabsb256 (v32qi)
10331v16hi __builtin_ia32_pabsw256 (v16hi)
10332v8si __builtin_ia32_pabsd256 (v8si)
10333v16hi builtin_ia32_packssdw256 (v8si,v8si)
10334v32qi __builtin_ia32_packsswb256 (v16hi,v16hi)
10335v16hi __builtin_ia32_packusdw256 (v8si,v8si)
10336v32qi __builtin_ia32_packuswb256 (v16hi,v16hi)
10337v32qi__builtin_ia32_paddb256 (v32qi,v32qi)
10338v16hi __builtin_ia32_paddw256 (v16hi,v16hi)
10339v8si __builtin_ia32_paddd256 (v8si,v8si)
10340v4di __builtin_ia32_paddq256 (v4di,v4di)
10341v32qi __builtin_ia32_paddsb256 (v32qi,v32qi)
10342v16hi __builtin_ia32_paddsw256 (v16hi,v16hi)
10343v32qi __builtin_ia32_paddusb256 (v32qi,v32qi)
10344v16hi __builtin_ia32_paddusw256 (v16hi,v16hi)
10345v4di __builtin_ia32_palignr256 (v4di,v4di,int)
10346v4di __builtin_ia32_andsi256 (v4di,v4di)
10347v4di __builtin_ia32_andnotsi256 (v4di,v4di)
10348v32qi__builtin_ia32_pavgb256 (v32qi,v32qi)
10349v16hi __builtin_ia32_pavgw256 (v16hi,v16hi)
10350v32qi __builtin_ia32_pblendvb256 (v32qi,v32qi,v32qi)
10351v16hi __builtin_ia32_pblendw256 (v16hi,v16hi,int)
10352v32qi __builtin_ia32_pcmpeqb256 (v32qi,v32qi)
10353v16hi __builtin_ia32_pcmpeqw256 (v16hi,v16hi)
10354v8si __builtin_ia32_pcmpeqd256 (c8si,v8si)
10355v4di __builtin_ia32_pcmpeqq256 (v4di,v4di)
10356v32qi __builtin_ia32_pcmpgtb256 (v32qi,v32qi)
10357v16hi __builtin_ia32_pcmpgtw256 (16hi,v16hi)
10358v8si __builtin_ia32_pcmpgtd256 (v8si,v8si)
10359v4di __builtin_ia32_pcmpgtq256 (v4di,v4di)
10360v16hi __builtin_ia32_phaddw256 (v16hi,v16hi)
10361v8si __builtin_ia32_phaddd256 (v8si,v8si)
10362v16hi __builtin_ia32_phaddsw256 (v16hi,v16hi)
10363v16hi __builtin_ia32_phsubw256 (v16hi,v16hi)
10364v8si __builtin_ia32_phsubd256 (v8si,v8si)
10365v16hi __builtin_ia32_phsubsw256 (v16hi,v16hi)
10366v32qi __builtin_ia32_pmaddubsw256 (v32qi,v32qi)
10367v16hi __builtin_ia32_pmaddwd256 (v16hi,v16hi)
10368v32qi __builtin_ia32_pmaxsb256 (v32qi,v32qi)
10369v16hi __builtin_ia32_pmaxsw256 (v16hi,v16hi)
10370v8si __builtin_ia32_pmaxsd256 (v8si,v8si)
10371v32qi __builtin_ia32_pmaxub256 (v32qi,v32qi)
10372v16hi __builtin_ia32_pmaxuw256 (v16hi,v16hi)
10373v8si __builtin_ia32_pmaxud256 (v8si,v8si)
10374v32qi __builtin_ia32_pminsb256 (v32qi,v32qi)
10375v16hi __builtin_ia32_pminsw256 (v16hi,v16hi)
10376v8si __builtin_ia32_pminsd256 (v8si,v8si)
10377v32qi __builtin_ia32_pminub256 (v32qi,v32qi)
10378v16hi __builtin_ia32_pminuw256 (v16hi,v16hi)
10379v8si __builtin_ia32_pminud256 (v8si,v8si)
10380int __builtin_ia32_pmovmskb256 (v32qi)
10381v16hi __builtin_ia32_pmovsxbw256 (v16qi)
10382v8si __builtin_ia32_pmovsxbd256 (v16qi)
10383v4di __builtin_ia32_pmovsxbq256 (v16qi)
10384v8si __builtin_ia32_pmovsxwd256 (v8hi)
10385v4di __builtin_ia32_pmovsxwq256 (v8hi)
10386v4di __builtin_ia32_pmovsxdq256 (v4si)
10387v16hi __builtin_ia32_pmovzxbw256 (v16qi)
10388v8si __builtin_ia32_pmovzxbd256 (v16qi)
10389v4di __builtin_ia32_pmovzxbq256 (v16qi)
10390v8si __builtin_ia32_pmovzxwd256 (v8hi)
10391v4di __builtin_ia32_pmovzxwq256 (v8hi)
10392v4di __builtin_ia32_pmovzxdq256 (v4si)
10393v4di __builtin_ia32_pmuldq256 (v8si,v8si)
10394v16hi __builtin_ia32_pmulhrsw256 (v16hi, v16hi)
10395v16hi __builtin_ia32_pmulhuw256 (v16hi,v16hi)
10396v16hi __builtin_ia32_pmulhw256 (v16hi,v16hi)
10397v16hi __builtin_ia32_pmullw256 (v16hi,v16hi)
10398v8si __builtin_ia32_pmulld256 (v8si,v8si)
10399v4di __builtin_ia32_pmuludq256 (v8si,v8si)
10400v4di __builtin_ia32_por256 (v4di,v4di)
10401v16hi __builtin_ia32_psadbw256 (v32qi,v32qi)
10402v32qi __builtin_ia32_pshufb256 (v32qi,v32qi)
10403v8si __builtin_ia32_pshufd256 (v8si,int)
10404v16hi __builtin_ia32_pshufhw256 (v16hi,int)
10405v16hi __builtin_ia32_pshuflw256 (v16hi,int)
10406v32qi __builtin_ia32_psignb256 (v32qi,v32qi)
10407v16hi __builtin_ia32_psignw256 (v16hi,v16hi)
10408v8si __builtin_ia32_psignd256 (v8si,v8si)
10409v4di __builtin_ia32_pslldqi256 (v4di,int)
10410v16hi __builtin_ia32_psllwi256 (16hi,int)
10411v16hi __builtin_ia32_psllw256(v16hi,v8hi)
10412v8si __builtin_ia32_pslldi256 (v8si,int)
10413v8si __builtin_ia32_pslld256(v8si,v4si)
10414v4di __builtin_ia32_psllqi256 (v4di,int)
10415v4di __builtin_ia32_psllq256(v4di,v2di)
10416v16hi __builtin_ia32_psrawi256 (v16hi,int)
10417v16hi __builtin_ia32_psraw256 (v16hi,v8hi)
10418v8si __builtin_ia32_psradi256 (v8si,int)
10419v8si __builtin_ia32_psrad256 (v8si,v4si)
10420v4di __builtin_ia32_psrldqi256 (v4di, int)
10421v16hi __builtin_ia32_psrlwi256 (v16hi,int)
10422v16hi __builtin_ia32_psrlw256 (v16hi,v8hi)
10423v8si __builtin_ia32_psrldi256 (v8si,int)
10424v8si __builtin_ia32_psrld256 (v8si,v4si)
10425v4di __builtin_ia32_psrlqi256 (v4di,int)
10426v4di __builtin_ia32_psrlq256(v4di,v2di)
10427v32qi __builtin_ia32_psubb256 (v32qi,v32qi)
10428v32hi __builtin_ia32_psubw256 (v16hi,v16hi)
10429v8si __builtin_ia32_psubd256 (v8si,v8si)
10430v4di __builtin_ia32_psubq256 (v4di,v4di)
10431v32qi __builtin_ia32_psubsb256 (v32qi,v32qi)
10432v16hi __builtin_ia32_psubsw256 (v16hi,v16hi)
10433v32qi __builtin_ia32_psubusb256 (v32qi,v32qi)
10434v16hi __builtin_ia32_psubusw256 (v16hi,v16hi)
10435v32qi __builtin_ia32_punpckhbw256 (v32qi,v32qi)
10436v16hi __builtin_ia32_punpckhwd256 (v16hi,v16hi)
10437v8si __builtin_ia32_punpckhdq256 (v8si,v8si)
10438v4di __builtin_ia32_punpckhqdq256 (v4di,v4di)
10439v32qi __builtin_ia32_punpcklbw256 (v32qi,v32qi)
10440v16hi __builtin_ia32_punpcklwd256 (v16hi,v16hi)
10441v8si __builtin_ia32_punpckldq256 (v8si,v8si)
10442v4di __builtin_ia32_punpcklqdq256 (v4di,v4di)
10443v4di __builtin_ia32_pxor256 (v4di,v4di)
10444v4di __builtin_ia32_movntdqa256 (pv4di)
10445v4sf __builtin_ia32_vbroadcastss_ps (v4sf)
10446v8sf __builtin_ia32_vbroadcastss_ps256 (v4sf)
10447v4df __builtin_ia32_vbroadcastsd_pd256 (v2df)
10448v4di __builtin_ia32_vbroadcastsi256 (v2di)
10449v4si __builtin_ia32_pblendd128 (v4si,v4si)
10450v8si __builtin_ia32_pblendd256 (v8si,v8si)
10451v32qi __builtin_ia32_pbroadcastb256 (v16qi)
10452v16hi __builtin_ia32_pbroadcastw256 (v8hi)
10453v8si __builtin_ia32_pbroadcastd256 (v4si)
10454v4di __builtin_ia32_pbroadcastq256 (v2di)
10455v16qi __builtin_ia32_pbroadcastb128 (v16qi)
10456v8hi __builtin_ia32_pbroadcastw128 (v8hi)
10457v4si __builtin_ia32_pbroadcastd128 (v4si)
10458v2di __builtin_ia32_pbroadcastq128 (v2di)
10459v8si __builtin_ia32_permvarsi256 (v8si,v8si)
10460v4df __builtin_ia32_permdf256 (v4df,int)
10461v8sf __builtin_ia32_permvarsf256 (v8sf,v8sf)
10462v4di __builtin_ia32_permdi256 (v4di,int)
10463v4di __builtin_ia32_permti256 (v4di,v4di,int)
10464v4di __builtin_ia32_extract128i256 (v4di,int)
10465v4di __builtin_ia32_insert128i256 (v4di,v2di,int)
10466v8si __builtin_ia32_maskloadd256 (pcv8si,v8si)
10467v4di __builtin_ia32_maskloadq256 (pcv4di,v4di)
10468v4si __builtin_ia32_maskloadd (pcv4si,v4si)
10469v2di __builtin_ia32_maskloadq (pcv2di,v2di)
10470void __builtin_ia32_maskstored256 (pv8si,v8si,v8si)
10471void __builtin_ia32_maskstoreq256 (pv4di,v4di,v4di)
10472void __builtin_ia32_maskstored (pv4si,v4si,v4si)
10473void __builtin_ia32_maskstoreq (pv2di,v2di,v2di)
10474v8si __builtin_ia32_psllv8si (v8si,v8si)
10475v4si __builtin_ia32_psllv4si (v4si,v4si)
10476v4di __builtin_ia32_psllv4di (v4di,v4di)
10477v2di __builtin_ia32_psllv2di (v2di,v2di)
10478v8si __builtin_ia32_psrav8si (v8si,v8si)
10479v4si __builtin_ia32_psrav4si (v4si,v4si)
10480v8si __builtin_ia32_psrlv8si (v8si,v8si)
10481v4si __builtin_ia32_psrlv4si (v4si,v4si)
10482v4di __builtin_ia32_psrlv4di (v4di,v4di)
10483v2di __builtin_ia32_psrlv2di (v2di,v2di)
10484v2df __builtin_ia32_gathersiv2df (v2df, pcdouble,v4si,v2df,int)
10485v4df __builtin_ia32_gathersiv4df (v4df, pcdouble,v4si,v4df,int)
10486v2df __builtin_ia32_gatherdiv2df (v2df, pcdouble,v2di,v2df,int)
10487v4df __builtin_ia32_gatherdiv4df (v4df, pcdouble,v4di,v4df,int)
10488v4sf __builtin_ia32_gathersiv4sf (v4sf, pcfloat,v4si,v4sf,int)
10489v8sf __builtin_ia32_gathersiv8sf (v8sf, pcfloat,v8si,v8sf,int)
10490v4sf __builtin_ia32_gatherdiv4sf (v4sf, pcfloat,v2di,v4sf,int)
10491v4sf __builtin_ia32_gatherdiv4sf256 (v4sf, pcfloat,v4di,v4sf,int)
10492v2di __builtin_ia32_gathersiv2di (v2di, pcint64,v4si,v2di,int)
10493v4di __builtin_ia32_gathersiv4di (v4di, pcint64,v4si,v4di,int)
10494v2di __builtin_ia32_gatherdiv2di (v2di, pcint64,v2di,v2di,int)
10495v4di __builtin_ia32_gatherdiv4di (v4di, pcint64,v4di,v4di,int)
10496v4si __builtin_ia32_gathersiv4si (v4si, pcint,v4si,v4si,int)
10497v8si __builtin_ia32_gathersiv8si (v8si, pcint,v8si,v8si,int)
10498v4si __builtin_ia32_gatherdiv4si (v4si, pcint,v2di,v4si,int)
10499v4si __builtin_ia32_gatherdiv4si256 (v4si, pcint,v4di,v4si,int)
10500@end smallexample
10501
1d9ef704 10502The following built-in functions are available when @option{-maes} is
10503used. All of them generate the machine instruction that is part of the
10504name.
10505
10506@smallexample
10507v2di __builtin_ia32_aesenc128 (v2di, v2di)
10508v2di __builtin_ia32_aesenclast128 (v2di, v2di)
10509v2di __builtin_ia32_aesdec128 (v2di, v2di)
10510v2di __builtin_ia32_aesdeclast128 (v2di, v2di)
10511v2di __builtin_ia32_aeskeygenassist128 (v2di, const int)
10512v2di __builtin_ia32_aesimc128 (v2di)
10513@end smallexample
10514
10515The following built-in function is available when @option{-mpclmul} is
10516used.
10517
10518@table @code
10519@item v2di __builtin_ia32_pclmulqdq128 (v2di, v2di, const int)
10520Generates the @code{pclmulqdq} machine instruction.
10521@end table
10522
ec113e67 10523The following built-in function is available when @option{-mfsgsbase} is
10524used. All of them generate the machine instruction that is part of the
10525name.
10526
10527@smallexample
10528unsigned int __builtin_ia32_rdfsbase32 (void)
10529unsigned long long __builtin_ia32_rdfsbase64 (void)
10530unsigned int __builtin_ia32_rdgsbase32 (void)
10531unsigned long long __builtin_ia32_rdgsbase64 (void)
10532void _writefsbase_u32 (unsigned int)
10533void _writefsbase_u64 (unsigned long long)
10534void _writegsbase_u32 (unsigned int)
10535void _writegsbase_u64 (unsigned long long)
10536@end smallexample
10537
10538The following built-in function is available when @option{-mrdrnd} is
10539used. All of them generate the machine instruction that is part of the
10540name.
10541
10542@smallexample
2d1e402c 10543unsigned int __builtin_ia32_rdrand16_step (unsigned short *)
10544unsigned int __builtin_ia32_rdrand32_step (unsigned int *)
10545unsigned int __builtin_ia32_rdrand64_step (unsigned long long *)
ec113e67 10546@end smallexample
10547
3d775f8e 10548The following built-in functions are available when @option{-msse4a} is used.
e6fc1977 10549All of them generate the machine instruction that is part of the name.
3d775f8e 10550
10551@smallexample
e6fc1977 10552void __builtin_ia32_movntsd (double *, v2df)
10553void __builtin_ia32_movntss (float *, v4sf)
10554v2di __builtin_ia32_extrq (v2di, v16qi)
10555v2di __builtin_ia32_extrqi (v2di, const unsigned int, const unsigned int)
10556v2di __builtin_ia32_insertq (v2di, v2di)
10557v2di __builtin_ia32_insertqi (v2di, v2di, const unsigned int, const unsigned int)
3d775f8e 10558@end smallexample
10559
18525343 10560The following built-in functions are available when @option{-mxop} is used.
10561@smallexample
10562v2df __builtin_ia32_vfrczpd (v2df)
10563v4sf __builtin_ia32_vfrczps (v4sf)
10564v2df __builtin_ia32_vfrczsd (v2df, v2df)
10565v4sf __builtin_ia32_vfrczss (v4sf, v4sf)
10566v4df __builtin_ia32_vfrczpd256 (v4df)
10567v8sf __builtin_ia32_vfrczps256 (v8sf)
10568v2di __builtin_ia32_vpcmov (v2di, v2di, v2di)
10569v2di __builtin_ia32_vpcmov_v2di (v2di, v2di, v2di)
10570v4si __builtin_ia32_vpcmov_v4si (v4si, v4si, v4si)
10571v8hi __builtin_ia32_vpcmov_v8hi (v8hi, v8hi, v8hi)
10572v16qi __builtin_ia32_vpcmov_v16qi (v16qi, v16qi, v16qi)
10573v2df __builtin_ia32_vpcmov_v2df (v2df, v2df, v2df)
10574v4sf __builtin_ia32_vpcmov_v4sf (v4sf, v4sf, v4sf)
10575v4di __builtin_ia32_vpcmov_v4di256 (v4di, v4di, v4di)
10576v8si __builtin_ia32_vpcmov_v8si256 (v8si, v8si, v8si)
10577v16hi __builtin_ia32_vpcmov_v16hi256 (v16hi, v16hi, v16hi)
10578v32qi __builtin_ia32_vpcmov_v32qi256 (v32qi, v32qi, v32qi)
10579v4df __builtin_ia32_vpcmov_v4df256 (v4df, v4df, v4df)
10580v8sf __builtin_ia32_vpcmov_v8sf256 (v8sf, v8sf, v8sf)
10581v16qi __builtin_ia32_vpcomeqb (v16qi, v16qi)
10582v8hi __builtin_ia32_vpcomeqw (v8hi, v8hi)
10583v4si __builtin_ia32_vpcomeqd (v4si, v4si)
10584v2di __builtin_ia32_vpcomeqq (v2di, v2di)
10585v16qi __builtin_ia32_vpcomequb (v16qi, v16qi)
10586v4si __builtin_ia32_vpcomequd (v4si, v4si)
10587v2di __builtin_ia32_vpcomequq (v2di, v2di)
10588v8hi __builtin_ia32_vpcomequw (v8hi, v8hi)
10589v8hi __builtin_ia32_vpcomeqw (v8hi, v8hi)
10590v16qi __builtin_ia32_vpcomfalseb (v16qi, v16qi)
10591v4si __builtin_ia32_vpcomfalsed (v4si, v4si)
10592v2di __builtin_ia32_vpcomfalseq (v2di, v2di)
10593v16qi __builtin_ia32_vpcomfalseub (v16qi, v16qi)
10594v4si __builtin_ia32_vpcomfalseud (v4si, v4si)
10595v2di __builtin_ia32_vpcomfalseuq (v2di, v2di)
10596v8hi __builtin_ia32_vpcomfalseuw (v8hi, v8hi)
10597v8hi __builtin_ia32_vpcomfalsew (v8hi, v8hi)
10598v16qi __builtin_ia32_vpcomgeb (v16qi, v16qi)
10599v4si __builtin_ia32_vpcomged (v4si, v4si)
10600v2di __builtin_ia32_vpcomgeq (v2di, v2di)
10601v16qi __builtin_ia32_vpcomgeub (v16qi, v16qi)
10602v4si __builtin_ia32_vpcomgeud (v4si, v4si)
10603v2di __builtin_ia32_vpcomgeuq (v2di, v2di)
10604v8hi __builtin_ia32_vpcomgeuw (v8hi, v8hi)
10605v8hi __builtin_ia32_vpcomgew (v8hi, v8hi)
10606v16qi __builtin_ia32_vpcomgtb (v16qi, v16qi)
10607v4si __builtin_ia32_vpcomgtd (v4si, v4si)
10608v2di __builtin_ia32_vpcomgtq (v2di, v2di)
10609v16qi __builtin_ia32_vpcomgtub (v16qi, v16qi)
10610v4si __builtin_ia32_vpcomgtud (v4si, v4si)
10611v2di __builtin_ia32_vpcomgtuq (v2di, v2di)
10612v8hi __builtin_ia32_vpcomgtuw (v8hi, v8hi)
10613v8hi __builtin_ia32_vpcomgtw (v8hi, v8hi)
10614v16qi __builtin_ia32_vpcomleb (v16qi, v16qi)
10615v4si __builtin_ia32_vpcomled (v4si, v4si)
10616v2di __builtin_ia32_vpcomleq (v2di, v2di)
10617v16qi __builtin_ia32_vpcomleub (v16qi, v16qi)
10618v4si __builtin_ia32_vpcomleud (v4si, v4si)
10619v2di __builtin_ia32_vpcomleuq (v2di, v2di)
10620v8hi __builtin_ia32_vpcomleuw (v8hi, v8hi)
10621v8hi __builtin_ia32_vpcomlew (v8hi, v8hi)
10622v16qi __builtin_ia32_vpcomltb (v16qi, v16qi)
10623v4si __builtin_ia32_vpcomltd (v4si, v4si)
10624v2di __builtin_ia32_vpcomltq (v2di, v2di)
10625v16qi __builtin_ia32_vpcomltub (v16qi, v16qi)
10626v4si __builtin_ia32_vpcomltud (v4si, v4si)
10627v2di __builtin_ia32_vpcomltuq (v2di, v2di)
10628v8hi __builtin_ia32_vpcomltuw (v8hi, v8hi)
10629v8hi __builtin_ia32_vpcomltw (v8hi, v8hi)
10630v16qi __builtin_ia32_vpcomneb (v16qi, v16qi)
10631v4si __builtin_ia32_vpcomned (v4si, v4si)
10632v2di __builtin_ia32_vpcomneq (v2di, v2di)
10633v16qi __builtin_ia32_vpcomneub (v16qi, v16qi)
10634v4si __builtin_ia32_vpcomneud (v4si, v4si)
10635v2di __builtin_ia32_vpcomneuq (v2di, v2di)
10636v8hi __builtin_ia32_vpcomneuw (v8hi, v8hi)
10637v8hi __builtin_ia32_vpcomnew (v8hi, v8hi)
10638v16qi __builtin_ia32_vpcomtrueb (v16qi, v16qi)
10639v4si __builtin_ia32_vpcomtrued (v4si, v4si)
10640v2di __builtin_ia32_vpcomtrueq (v2di, v2di)
10641v16qi __builtin_ia32_vpcomtrueub (v16qi, v16qi)
10642v4si __builtin_ia32_vpcomtrueud (v4si, v4si)
10643v2di __builtin_ia32_vpcomtrueuq (v2di, v2di)
10644v8hi __builtin_ia32_vpcomtrueuw (v8hi, v8hi)
10645v8hi __builtin_ia32_vpcomtruew (v8hi, v8hi)
10646v4si __builtin_ia32_vphaddbd (v16qi)
10647v2di __builtin_ia32_vphaddbq (v16qi)
10648v8hi __builtin_ia32_vphaddbw (v16qi)
10649v2di __builtin_ia32_vphadddq (v4si)
10650v4si __builtin_ia32_vphaddubd (v16qi)
10651v2di __builtin_ia32_vphaddubq (v16qi)
10652v8hi __builtin_ia32_vphaddubw (v16qi)
10653v2di __builtin_ia32_vphaddudq (v4si)
10654v4si __builtin_ia32_vphadduwd (v8hi)
10655v2di __builtin_ia32_vphadduwq (v8hi)
10656v4si __builtin_ia32_vphaddwd (v8hi)
10657v2di __builtin_ia32_vphaddwq (v8hi)
10658v8hi __builtin_ia32_vphsubbw (v16qi)
10659v2di __builtin_ia32_vphsubdq (v4si)
10660v4si __builtin_ia32_vphsubwd (v8hi)
10661v4si __builtin_ia32_vpmacsdd (v4si, v4si, v4si)
10662v2di __builtin_ia32_vpmacsdqh (v4si, v4si, v2di)
10663v2di __builtin_ia32_vpmacsdql (v4si, v4si, v2di)
10664v4si __builtin_ia32_vpmacssdd (v4si, v4si, v4si)
10665v2di __builtin_ia32_vpmacssdqh (v4si, v4si, v2di)
10666v2di __builtin_ia32_vpmacssdql (v4si, v4si, v2di)
10667v4si __builtin_ia32_vpmacsswd (v8hi, v8hi, v4si)
10668v8hi __builtin_ia32_vpmacssww (v8hi, v8hi, v8hi)
10669v4si __builtin_ia32_vpmacswd (v8hi, v8hi, v4si)
10670v8hi __builtin_ia32_vpmacsww (v8hi, v8hi, v8hi)
10671v4si __builtin_ia32_vpmadcsswd (v8hi, v8hi, v4si)
10672v4si __builtin_ia32_vpmadcswd (v8hi, v8hi, v4si)
10673v16qi __builtin_ia32_vpperm (v16qi, v16qi, v16qi)
10674v16qi __builtin_ia32_vprotb (v16qi, v16qi)
10675v4si __builtin_ia32_vprotd (v4si, v4si)
10676v2di __builtin_ia32_vprotq (v2di, v2di)
10677v8hi __builtin_ia32_vprotw (v8hi, v8hi)
10678v16qi __builtin_ia32_vpshab (v16qi, v16qi)
10679v4si __builtin_ia32_vpshad (v4si, v4si)
10680v2di __builtin_ia32_vpshaq (v2di, v2di)
10681v8hi __builtin_ia32_vpshaw (v8hi, v8hi)
10682v16qi __builtin_ia32_vpshlb (v16qi, v16qi)
10683v4si __builtin_ia32_vpshld (v4si, v4si)
10684v2di __builtin_ia32_vpshlq (v2di, v2di)
10685v8hi __builtin_ia32_vpshlw (v8hi, v8hi)
10686@end smallexample
10687
2f212aae 10688The following built-in functions are available when @option{-mfma4} is used.
10689All of them generate the machine instruction that is part of the name
10690with MMX registers.
10691
10692@smallexample
10693v2df __builtin_ia32_fmaddpd (v2df, v2df, v2df)
10694v4sf __builtin_ia32_fmaddps (v4sf, v4sf, v4sf)
10695v2df __builtin_ia32_fmaddsd (v2df, v2df, v2df)
10696v4sf __builtin_ia32_fmaddss (v4sf, v4sf, v4sf)
10697v2df __builtin_ia32_fmsubpd (v2df, v2df, v2df)
10698v4sf __builtin_ia32_fmsubps (v4sf, v4sf, v4sf)
10699v2df __builtin_ia32_fmsubsd (v2df, v2df, v2df)
10700v4sf __builtin_ia32_fmsubss (v4sf, v4sf, v4sf)
10701v2df __builtin_ia32_fnmaddpd (v2df, v2df, v2df)
10702v4sf __builtin_ia32_fnmaddps (v4sf, v4sf, v4sf)
10703v2df __builtin_ia32_fnmaddsd (v2df, v2df, v2df)
10704v4sf __builtin_ia32_fnmaddss (v4sf, v4sf, v4sf)
10705v2df __builtin_ia32_fnmsubpd (v2df, v2df, v2df)
10706v4sf __builtin_ia32_fnmsubps (v4sf, v4sf, v4sf)
10707v2df __builtin_ia32_fnmsubsd (v2df, v2df, v2df)
10708v4sf __builtin_ia32_fnmsubss (v4sf, v4sf, v4sf)
10709v2df __builtin_ia32_fmaddsubpd (v2df, v2df, v2df)
10710v4sf __builtin_ia32_fmaddsubps (v4sf, v4sf, v4sf)
10711v2df __builtin_ia32_fmsubaddpd (v2df, v2df, v2df)
10712v4sf __builtin_ia32_fmsubaddps (v4sf, v4sf, v4sf)
10713v4df __builtin_ia32_fmaddpd256 (v4df, v4df, v4df)
10714v8sf __builtin_ia32_fmaddps256 (v8sf, v8sf, v8sf)
10715v4df __builtin_ia32_fmsubpd256 (v4df, v4df, v4df)
10716v8sf __builtin_ia32_fmsubps256 (v8sf, v8sf, v8sf)
10717v4df __builtin_ia32_fnmaddpd256 (v4df, v4df, v4df)
10718v8sf __builtin_ia32_fnmaddps256 (v8sf, v8sf, v8sf)
10719v4df __builtin_ia32_fnmsubpd256 (v4df, v4df, v4df)
10720v8sf __builtin_ia32_fnmsubps256 (v8sf, v8sf, v8sf)
10721v4df __builtin_ia32_fmaddsubpd256 (v4df, v4df, v4df)
10722v8sf __builtin_ia32_fmaddsubps256 (v8sf, v8sf, v8sf)
10723v4df __builtin_ia32_fmsubaddpd256 (v4df, v4df, v4df)
10724v8sf __builtin_ia32_fmsubaddps256 (v8sf, v8sf, v8sf)
10725
10726@end smallexample
048fbb59 10727
10728The following built-in functions are available when @option{-mlwp} is used.
10729
10730@smallexample
10731void __builtin_ia32_llwpcb16 (void *);
10732void __builtin_ia32_llwpcb32 (void *);
10733void __builtin_ia32_llwpcb64 (void *);
10734void * __builtin_ia32_llwpcb16 (void);
10735void * __builtin_ia32_llwpcb32 (void);
10736void * __builtin_ia32_llwpcb64 (void);
10737void __builtin_ia32_lwpval16 (unsigned short, unsigned int, unsigned short)
10738void __builtin_ia32_lwpval32 (unsigned int, unsigned int, unsigned int)
10739void __builtin_ia32_lwpval64 (unsigned __int64, unsigned int, unsigned int)
10740unsigned char __builtin_ia32_lwpins16 (unsigned short, unsigned int, unsigned short)
10741unsigned char __builtin_ia32_lwpins32 (unsigned int, unsigned int, unsigned int)
10742unsigned char __builtin_ia32_lwpins64 (unsigned __int64, unsigned int, unsigned int)
10743@end smallexample
2f212aae 10744
02024195 10745The following built-in functions are available when @option{-mbmi} is used.
10746All of them generate the machine instruction that is part of the name.
10747@smallexample
10748unsigned int __builtin_ia32_bextr_u32(unsigned int, unsigned int);
10749unsigned long long __builtin_ia32_bextr_u64 (unsigned long long, unsigned long long);
a3398ee6 10750@end smallexample
10751
2339767f 10752The following built-in functions are available when @option{-mbmi2} is used.
10753All of them generate the machine instruction that is part of the name.
10754@smallexample
10755unsigned int _bzhi_u32 (unsigned int, unsigned int)
10756unsigned int _pdep_u32 (unsigned int, unsigned int)
10757unsigned int _pext_u32 (unsigned int, unsigned int)
10758unsigned long long _bzhi_u64 (unsigned long long, unsigned long long)
10759unsigned long long _pdep_u64 (unsigned long long, unsigned long long)
10760unsigned long long _pext_u64 (unsigned long long, unsigned long long)
10761@end smallexample
10762
a3398ee6 10763The following built-in functions are available when @option{-mlzcnt} is used.
10764All of them generate the machine instruction that is part of the name.
10765@smallexample
02024195 10766unsigned short __builtin_ia32_lzcnt_16(unsigned short);
10767unsigned int __builtin_ia32_lzcnt_u32(unsigned int);
10768unsigned long long __builtin_ia32_lzcnt_u64 (unsigned long long);
10769@end smallexample
10770
2c1d4003 10771The following built-in functions are available when @option{-mtbm} is used.
10772Both of them generate the immediate form of the bextr machine instruction.
10773@smallexample
10774unsigned int __builtin_ia32_bextri_u32 (unsigned int, const unsigned int);
10775unsigned long long __builtin_ia32_bextri_u64 (unsigned long long, const unsigned long long);
10776@end smallexample
10777
10778
ca5827cf 10779The following built-in functions are available when @option{-m3dnow} is used.
10780All of them generate the machine instruction that is part of the name.
10781
a0ecd6b1 10782@smallexample
ca5827cf 10783void __builtin_ia32_femms (void)
10784v8qi __builtin_ia32_pavgusb (v8qi, v8qi)
10785v2si __builtin_ia32_pf2id (v2sf)
10786v2sf __builtin_ia32_pfacc (v2sf, v2sf)
10787v2sf __builtin_ia32_pfadd (v2sf, v2sf)
10788v2si __builtin_ia32_pfcmpeq (v2sf, v2sf)
10789v2si __builtin_ia32_pfcmpge (v2sf, v2sf)
10790v2si __builtin_ia32_pfcmpgt (v2sf, v2sf)
10791v2sf __builtin_ia32_pfmax (v2sf, v2sf)
10792v2sf __builtin_ia32_pfmin (v2sf, v2sf)
10793v2sf __builtin_ia32_pfmul (v2sf, v2sf)
10794v2sf __builtin_ia32_pfrcp (v2sf)
10795v2sf __builtin_ia32_pfrcpit1 (v2sf, v2sf)
10796v2sf __builtin_ia32_pfrcpit2 (v2sf, v2sf)
10797v2sf __builtin_ia32_pfrsqrt (v2sf)
10798v2sf __builtin_ia32_pfrsqrtit1 (v2sf, v2sf)
10799v2sf __builtin_ia32_pfsub (v2sf, v2sf)
10800v2sf __builtin_ia32_pfsubr (v2sf, v2sf)
10801v2sf __builtin_ia32_pi2fd (v2si)
10802v4hi __builtin_ia32_pmulhrw (v4hi, v4hi)
a0ecd6b1 10803@end smallexample
ca5827cf 10804
10805The following built-in functions are available when both @option{-m3dnow}
10806and @option{-march=athlon} are used. All of them generate the machine
10807instruction that is part of the name.
10808
a0ecd6b1 10809@smallexample
ca5827cf 10810v2si __builtin_ia32_pf2iw (v2sf)
10811v2sf __builtin_ia32_pfnacc (v2sf, v2sf)
10812v2sf __builtin_ia32_pfpnacc (v2sf, v2sf)
10813v2sf __builtin_ia32_pi2fw (v2si)
10814v2sf __builtin_ia32_pswapdsf (v2sf)
10815v2si __builtin_ia32_pswapdsi (v2si)
a0ecd6b1 10816@end smallexample
ca5827cf 10817
b7efe757 10818@node MIPS DSP Built-in Functions
10819@subsection MIPS DSP Built-in Functions
10820
10821The MIPS DSP Application-Specific Extension (ASE) includes new
10822instructions that are designed to improve the performance of DSP and
10823media applications. It provides instructions that operate on packed
c1901bc7 108248-bit/16-bit integer data, Q7, Q15 and Q31 fractional data.
b7efe757 10825
10826GCC supports MIPS DSP operations using both the generic
10827vector extensions (@pxref{Vector Extensions}) and a collection of
10828MIPS-specific built-in functions. Both kinds of support are
10829enabled by the @option{-mdsp} command-line option.
10830
c1901bc7 10831Revision 2 of the ASE was introduced in the second half of 2006.
10832This revision adds extra instructions to the original ASE, but is
10833otherwise backwards-compatible with it. You can select revision 2
10834using the command-line option @option{-mdspr2}; this option implies
10835@option{-mdsp}.
10836
d036db4d 10837The SCOUNT and POS bits of the DSP control register are global. The
10838WRDSP, EXTPDP, EXTPDPV and MTHLIP instructions modify the SCOUNT and
10839POS bits. During optimization, the compiler will not delete these
10840instructions and it will not delete calls to functions containing
10841these instructions.
10842
b7efe757 10843At present, GCC only provides support for operations on 32-bit
10844vectors. The vector type associated with 8-bit integer data is
c1901bc7 10845usually called @code{v4i8}, the vector type associated with Q7
10846is usually called @code{v4q7}, the vector type associated with 16-bit
10847integer data is usually called @code{v2i16}, and the vector type
10848associated with Q15 is usually called @code{v2q15}. They can be
10849defined in C as follows:
b7efe757 10850
10851@smallexample
c1901bc7 10852typedef signed char v4i8 __attribute__ ((vector_size(4)));
10853typedef signed char v4q7 __attribute__ ((vector_size(4)));
10854typedef short v2i16 __attribute__ ((vector_size(4)));
b7efe757 10855typedef short v2q15 __attribute__ ((vector_size(4)));
10856@end smallexample
10857
c1901bc7 10858@code{v4i8}, @code{v4q7}, @code{v2i16} and @code{v2q15} values are
10859initialized in the same way as aggregates. For example:
b7efe757 10860
10861@smallexample
10862v4i8 a = @{1, 2, 3, 4@};
10863v4i8 b;
10864b = (v4i8) @{5, 6, 7, 8@};
10865
10866v2q15 c = @{0x0fcb, 0x3a75@};
10867v2q15 d;
10868d = (v2q15) @{0.1234 * 0x1.0p15, 0.4567 * 0x1.0p15@};
10869@end smallexample
10870
10871@emph{Note:} The CPU's endianness determines the order in which values
10872are packed. On little-endian targets, the first value is the least
10873significant and the last value is the most significant. The opposite
10874order applies to big-endian targets. For example, the code above will
10875set the lowest byte of @code{a} to @code{1} on little-endian targets
10876and @code{4} on big-endian targets.
10877
c1901bc7 10878@emph{Note:} Q7, Q15 and Q31 values must be initialized with their integer
b7efe757 10879representation. As shown in this example, the integer representation
c1901bc7 10880of a Q7 value can be obtained by multiplying the fractional value by
10881@code{0x1.0p7}. The equivalent for Q15 values is to multiply by
b7efe757 10882@code{0x1.0p15}. The equivalent for Q31 values is to multiply by
10883@code{0x1.0p31}.
10884
10885The table below lists the @code{v4i8} and @code{v2q15} operations for which
10886hardware support exists. @code{a} and @code{b} are @code{v4i8} values,
10887and @code{c} and @code{d} are @code{v2q15} values.
10888
10889@multitable @columnfractions .50 .50
10890@item C code @tab MIPS instruction
10891@item @code{a + b} @tab @code{addu.qb}
10892@item @code{c + d} @tab @code{addq.ph}
10893@item @code{a - b} @tab @code{subu.qb}
10894@item @code{c - d} @tab @code{subq.ph}
10895@end multitable
10896
c1901bc7 10897The table below lists the @code{v2i16} operation for which
10898hardware support exists for the DSP ASE REV 2. @code{e} and @code{f} are
10899@code{v2i16} values.
10900
10901@multitable @columnfractions .50 .50
10902@item C code @tab MIPS instruction
10903@item @code{e * f} @tab @code{mul.ph}
10904@end multitable
10905
b7efe757 10906It is easier to describe the DSP built-in functions if we first define
10907the following types:
10908
10909@smallexample
10910typedef int q31;
10911typedef int i32;
c1901bc7 10912typedef unsigned int ui32;
b7efe757 10913typedef long long a64;
10914@end smallexample
10915
10916@code{q31} and @code{i32} are actually the same as @code{int}, but we
10917use @code{q31} to indicate a Q31 fractional value and @code{i32} to
10918indicate a 32-bit integer value. Similarly, @code{a64} is the same as
10919@code{long long}, but we use @code{a64} to indicate values that will
10920be placed in one of the four DSP accumulators (@code{$ac0},
10921@code{$ac1}, @code{$ac2} or @code{$ac3}).
10922
10923Also, some built-in functions prefer or require immediate numbers as
10924parameters, because the corresponding DSP instructions accept both immediate
10925numbers and register operands, or accept immediate numbers only. The
10926immediate parameters are listed as follows.
10927
10928@smallexample
c1901bc7 10929imm0_3: 0 to 3.
b7efe757 10930imm0_7: 0 to 7.
10931imm0_15: 0 to 15.
10932imm0_31: 0 to 31.
10933imm0_63: 0 to 63.
10934imm0_255: 0 to 255.
10935imm_n32_31: -32 to 31.
10936imm_n512_511: -512 to 511.
10937@end smallexample
10938
10939The following built-in functions map directly to a particular MIPS DSP
10940instruction. Please refer to the architecture specification
10941for details on what each instruction does.
10942
10943@smallexample
10944v2q15 __builtin_mips_addq_ph (v2q15, v2q15)
10945v2q15 __builtin_mips_addq_s_ph (v2q15, v2q15)
10946q31 __builtin_mips_addq_s_w (q31, q31)
10947v4i8 __builtin_mips_addu_qb (v4i8, v4i8)
10948v4i8 __builtin_mips_addu_s_qb (v4i8, v4i8)
10949v2q15 __builtin_mips_subq_ph (v2q15, v2q15)
10950v2q15 __builtin_mips_subq_s_ph (v2q15, v2q15)
10951q31 __builtin_mips_subq_s_w (q31, q31)
10952v4i8 __builtin_mips_subu_qb (v4i8, v4i8)
10953v4i8 __builtin_mips_subu_s_qb (v4i8, v4i8)
10954i32 __builtin_mips_addsc (i32, i32)
10955i32 __builtin_mips_addwc (i32, i32)
10956i32 __builtin_mips_modsub (i32, i32)
10957i32 __builtin_mips_raddu_w_qb (v4i8)
10958v2q15 __builtin_mips_absq_s_ph (v2q15)
10959q31 __builtin_mips_absq_s_w (q31)
10960v4i8 __builtin_mips_precrq_qb_ph (v2q15, v2q15)
10961v2q15 __builtin_mips_precrq_ph_w (q31, q31)
10962v2q15 __builtin_mips_precrq_rs_ph_w (q31, q31)
10963v4i8 __builtin_mips_precrqu_s_qb_ph (v2q15, v2q15)
10964q31 __builtin_mips_preceq_w_phl (v2q15)
10965q31 __builtin_mips_preceq_w_phr (v2q15)
10966v2q15 __builtin_mips_precequ_ph_qbl (v4i8)
10967v2q15 __builtin_mips_precequ_ph_qbr (v4i8)
10968v2q15 __builtin_mips_precequ_ph_qbla (v4i8)
10969v2q15 __builtin_mips_precequ_ph_qbra (v4i8)
10970v2q15 __builtin_mips_preceu_ph_qbl (v4i8)
10971v2q15 __builtin_mips_preceu_ph_qbr (v4i8)
10972v2q15 __builtin_mips_preceu_ph_qbla (v4i8)
10973v2q15 __builtin_mips_preceu_ph_qbra (v4i8)
10974v4i8 __builtin_mips_shll_qb (v4i8, imm0_7)
10975v4i8 __builtin_mips_shll_qb (v4i8, i32)
10976v2q15 __builtin_mips_shll_ph (v2q15, imm0_15)
10977v2q15 __builtin_mips_shll_ph (v2q15, i32)
10978v2q15 __builtin_mips_shll_s_ph (v2q15, imm0_15)
10979v2q15 __builtin_mips_shll_s_ph (v2q15, i32)
10980q31 __builtin_mips_shll_s_w (q31, imm0_31)
10981q31 __builtin_mips_shll_s_w (q31, i32)
10982v4i8 __builtin_mips_shrl_qb (v4i8, imm0_7)
10983v4i8 __builtin_mips_shrl_qb (v4i8, i32)
10984v2q15 __builtin_mips_shra_ph (v2q15, imm0_15)
10985v2q15 __builtin_mips_shra_ph (v2q15, i32)
10986v2q15 __builtin_mips_shra_r_ph (v2q15, imm0_15)
10987v2q15 __builtin_mips_shra_r_ph (v2q15, i32)
10988q31 __builtin_mips_shra_r_w (q31, imm0_31)
10989q31 __builtin_mips_shra_r_w (q31, i32)
10990v2q15 __builtin_mips_muleu_s_ph_qbl (v4i8, v2q15)
10991v2q15 __builtin_mips_muleu_s_ph_qbr (v4i8, v2q15)
10992v2q15 __builtin_mips_mulq_rs_ph (v2q15, v2q15)
10993q31 __builtin_mips_muleq_s_w_phl (v2q15, v2q15)
10994q31 __builtin_mips_muleq_s_w_phr (v2q15, v2q15)
10995a64 __builtin_mips_dpau_h_qbl (a64, v4i8, v4i8)
10996a64 __builtin_mips_dpau_h_qbr (a64, v4i8, v4i8)
10997a64 __builtin_mips_dpsu_h_qbl (a64, v4i8, v4i8)
10998a64 __builtin_mips_dpsu_h_qbr (a64, v4i8, v4i8)
10999a64 __builtin_mips_dpaq_s_w_ph (a64, v2q15, v2q15)
11000a64 __builtin_mips_dpaq_sa_l_w (a64, q31, q31)
11001a64 __builtin_mips_dpsq_s_w_ph (a64, v2q15, v2q15)
11002a64 __builtin_mips_dpsq_sa_l_w (a64, q31, q31)
11003a64 __builtin_mips_mulsaq_s_w_ph (a64, v2q15, v2q15)
11004a64 __builtin_mips_maq_s_w_phl (a64, v2q15, v2q15)
11005a64 __builtin_mips_maq_s_w_phr (a64, v2q15, v2q15)
11006a64 __builtin_mips_maq_sa_w_phl (a64, v2q15, v2q15)
11007a64 __builtin_mips_maq_sa_w_phr (a64, v2q15, v2q15)
11008i32 __builtin_mips_bitrev (i32)
11009i32 __builtin_mips_insv (i32, i32)
11010v4i8 __builtin_mips_repl_qb (imm0_255)
11011v4i8 __builtin_mips_repl_qb (i32)
11012v2q15 __builtin_mips_repl_ph (imm_n512_511)
11013v2q15 __builtin_mips_repl_ph (i32)
11014void __builtin_mips_cmpu_eq_qb (v4i8, v4i8)
11015void __builtin_mips_cmpu_lt_qb (v4i8, v4i8)
11016void __builtin_mips_cmpu_le_qb (v4i8, v4i8)
11017i32 __builtin_mips_cmpgu_eq_qb (v4i8, v4i8)
11018i32 __builtin_mips_cmpgu_lt_qb (v4i8, v4i8)
11019i32 __builtin_mips_cmpgu_le_qb (v4i8, v4i8)
11020void __builtin_mips_cmp_eq_ph (v2q15, v2q15)
11021void __builtin_mips_cmp_lt_ph (v2q15, v2q15)
11022void __builtin_mips_cmp_le_ph (v2q15, v2q15)
11023v4i8 __builtin_mips_pick_qb (v4i8, v4i8)
11024v2q15 __builtin_mips_pick_ph (v2q15, v2q15)
11025v2q15 __builtin_mips_packrl_ph (v2q15, v2q15)
11026i32 __builtin_mips_extr_w (a64, imm0_31)
11027i32 __builtin_mips_extr_w (a64, i32)
11028i32 __builtin_mips_extr_r_w (a64, imm0_31)
11029i32 __builtin_mips_extr_s_h (a64, i32)
11030i32 __builtin_mips_extr_rs_w (a64, imm0_31)
11031i32 __builtin_mips_extr_rs_w (a64, i32)
11032i32 __builtin_mips_extr_s_h (a64, imm0_31)
11033i32 __builtin_mips_extr_r_w (a64, i32)
11034i32 __builtin_mips_extp (a64, imm0_31)
11035i32 __builtin_mips_extp (a64, i32)
11036i32 __builtin_mips_extpdp (a64, imm0_31)
11037i32 __builtin_mips_extpdp (a64, i32)
11038a64 __builtin_mips_shilo (a64, imm_n32_31)
11039a64 __builtin_mips_shilo (a64, i32)
11040a64 __builtin_mips_mthlip (a64, i32)
11041void __builtin_mips_wrdsp (i32, imm0_63)
11042i32 __builtin_mips_rddsp (imm0_63)
11043i32 __builtin_mips_lbux (void *, i32)
11044i32 __builtin_mips_lhx (void *, i32)
11045i32 __builtin_mips_lwx (void *, i32)
b7508909 11046a64 __builtin_mips_ldx (void *, i32) [MIPS64 only]
b7efe757 11047i32 __builtin_mips_bposge32 (void)
3e60fdb7 11048a64 __builtin_mips_madd (a64, i32, i32);
11049a64 __builtin_mips_maddu (a64, ui32, ui32);
11050a64 __builtin_mips_msub (a64, i32, i32);
11051a64 __builtin_mips_msubu (a64, ui32, ui32);
11052a64 __builtin_mips_mult (i32, i32);
11053a64 __builtin_mips_multu (ui32, ui32);
b7efe757 11054@end smallexample
11055
c1901bc7 11056The following built-in functions map directly to a particular MIPS DSP REV 2
11057instruction. Please refer to the architecture specification
11058for details on what each instruction does.
11059
11060@smallexample
11061v4q7 __builtin_mips_absq_s_qb (v4q7);
11062v2i16 __builtin_mips_addu_ph (v2i16, v2i16);
11063v2i16 __builtin_mips_addu_s_ph (v2i16, v2i16);
11064v4i8 __builtin_mips_adduh_qb (v4i8, v4i8);
11065v4i8 __builtin_mips_adduh_r_qb (v4i8, v4i8);
11066i32 __builtin_mips_append (i32, i32, imm0_31);
11067i32 __builtin_mips_balign (i32, i32, imm0_3);
11068i32 __builtin_mips_cmpgdu_eq_qb (v4i8, v4i8);
11069i32 __builtin_mips_cmpgdu_lt_qb (v4i8, v4i8);
11070i32 __builtin_mips_cmpgdu_le_qb (v4i8, v4i8);
11071a64 __builtin_mips_dpa_w_ph (a64, v2i16, v2i16);
11072a64 __builtin_mips_dps_w_ph (a64, v2i16, v2i16);
c1901bc7 11073v2i16 __builtin_mips_mul_ph (v2i16, v2i16);
11074v2i16 __builtin_mips_mul_s_ph (v2i16, v2i16);
11075q31 __builtin_mips_mulq_rs_w (q31, q31);
11076v2q15 __builtin_mips_mulq_s_ph (v2q15, v2q15);
11077q31 __builtin_mips_mulq_s_w (q31, q31);
11078a64 __builtin_mips_mulsa_w_ph (a64, v2i16, v2i16);
c1901bc7 11079v4i8 __builtin_mips_precr_qb_ph (v2i16, v2i16);
11080v2i16 __builtin_mips_precr_sra_ph_w (i32, i32, imm0_31);
11081v2i16 __builtin_mips_precr_sra_r_ph_w (i32, i32, imm0_31);
11082i32 __builtin_mips_prepend (i32, i32, imm0_31);
11083v4i8 __builtin_mips_shra_qb (v4i8, imm0_7);
11084v4i8 __builtin_mips_shra_r_qb (v4i8, imm0_7);
11085v4i8 __builtin_mips_shra_qb (v4i8, i32);
11086v4i8 __builtin_mips_shra_r_qb (v4i8, i32);
11087v2i16 __builtin_mips_shrl_ph (v2i16, imm0_15);
11088v2i16 __builtin_mips_shrl_ph (v2i16, i32);
11089v2i16 __builtin_mips_subu_ph (v2i16, v2i16);
11090v2i16 __builtin_mips_subu_s_ph (v2i16, v2i16);
11091v4i8 __builtin_mips_subuh_qb (v4i8, v4i8);
11092v4i8 __builtin_mips_subuh_r_qb (v4i8, v4i8);
11093v2q15 __builtin_mips_addqh_ph (v2q15, v2q15);
11094v2q15 __builtin_mips_addqh_r_ph (v2q15, v2q15);
11095q31 __builtin_mips_addqh_w (q31, q31);
11096q31 __builtin_mips_addqh_r_w (q31, q31);
11097v2q15 __builtin_mips_subqh_ph (v2q15, v2q15);
11098v2q15 __builtin_mips_subqh_r_ph (v2q15, v2q15);
11099q31 __builtin_mips_subqh_w (q31, q31);
11100q31 __builtin_mips_subqh_r_w (q31, q31);
11101a64 __builtin_mips_dpax_w_ph (a64, v2i16, v2i16);
11102a64 __builtin_mips_dpsx_w_ph (a64, v2i16, v2i16);
11103a64 __builtin_mips_dpaqx_s_w_ph (a64, v2q15, v2q15);
11104a64 __builtin_mips_dpaqx_sa_w_ph (a64, v2q15, v2q15);
11105a64 __builtin_mips_dpsqx_s_w_ph (a64, v2q15, v2q15);
11106a64 __builtin_mips_dpsqx_sa_w_ph (a64, v2q15, v2q15);
11107@end smallexample
11108
11109
dd2a386a 11110@node MIPS Paired-Single Support
11111@subsection MIPS Paired-Single Support
11112
11113The MIPS64 architecture includes a number of instructions that
11114operate on pairs of single-precision floating-point values.
11115Each pair is packed into a 64-bit floating-point register,
11116with one element being designated the ``upper half'' and
11117the other being designated the ``lower half''.
11118
11119GCC supports paired-single operations using both the generic
11120vector extensions (@pxref{Vector Extensions}) and a collection of
11121MIPS-specific built-in functions. Both kinds of support are
11122enabled by the @option{-mpaired-single} command-line option.
11123
11124The vector type associated with paired-single values is usually
11125called @code{v2sf}. It can be defined in C as follows:
11126
11127@smallexample
11128typedef float v2sf __attribute__ ((vector_size (8)));
11129@end smallexample
11130
11131@code{v2sf} values are initialized in the same way as aggregates.
11132For example:
11133
11134@smallexample
11135v2sf a = @{1.5, 9.1@};
11136v2sf b;
11137float e, f;
11138b = (v2sf) @{e, f@};
11139@end smallexample
11140
11141@emph{Note:} The CPU's endianness determines which value is stored in
11142the upper half of a register and which value is stored in the lower half.
11143On little-endian targets, the first value is the lower one and the second
11144value is the upper one. The opposite order applies to big-endian targets.
11145For example, the code above will set the lower half of @code{a} to
11146@code{1.5} on little-endian targets and @code{9.1} on big-endian targets.
11147
9636921b 11148@node MIPS Loongson Built-in Functions
11149@subsection MIPS Loongson Built-in Functions
11150
11151GCC provides intrinsics to access the SIMD instructions provided by the
11152ST Microelectronics Loongson-2E and -2F processors. These intrinsics,
11153available after inclusion of the @code{loongson.h} header file,
11154operate on the following 64-bit vector types:
11155
11156@itemize
11157@item @code{uint8x8_t}, a vector of eight unsigned 8-bit integers;
11158@item @code{uint16x4_t}, a vector of four unsigned 16-bit integers;
11159@item @code{uint32x2_t}, a vector of two unsigned 32-bit integers;
11160@item @code{int8x8_t}, a vector of eight signed 8-bit integers;
11161@item @code{int16x4_t}, a vector of four signed 16-bit integers;
11162@item @code{int32x2_t}, a vector of two signed 32-bit integers.
11163@end itemize
11164
11165The intrinsics provided are listed below; each is named after the
11166machine instruction to which it corresponds, with suffixes added as
11167appropriate to distinguish intrinsics that expand to the same machine
11168instruction yet have different argument types. Refer to the architecture
11169documentation for a description of the functionality of each
11170instruction.
11171
11172@smallexample
11173int16x4_t packsswh (int32x2_t s, int32x2_t t);
11174int8x8_t packsshb (int16x4_t s, int16x4_t t);
11175uint8x8_t packushb (uint16x4_t s, uint16x4_t t);
11176uint32x2_t paddw_u (uint32x2_t s, uint32x2_t t);
11177uint16x4_t paddh_u (uint16x4_t s, uint16x4_t t);
11178uint8x8_t paddb_u (uint8x8_t s, uint8x8_t t);
11179int32x2_t paddw_s (int32x2_t s, int32x2_t t);
11180int16x4_t paddh_s (int16x4_t s, int16x4_t t);
11181int8x8_t paddb_s (int8x8_t s, int8x8_t t);
11182uint64_t paddd_u (uint64_t s, uint64_t t);
11183int64_t paddd_s (int64_t s, int64_t t);
11184int16x4_t paddsh (int16x4_t s, int16x4_t t);
11185int8x8_t paddsb (int8x8_t s, int8x8_t t);
11186uint16x4_t paddush (uint16x4_t s, uint16x4_t t);
11187uint8x8_t paddusb (uint8x8_t s, uint8x8_t t);
11188uint64_t pandn_ud (uint64_t s, uint64_t t);
11189uint32x2_t pandn_uw (uint32x2_t s, uint32x2_t t);
11190uint16x4_t pandn_uh (uint16x4_t s, uint16x4_t t);
11191uint8x8_t pandn_ub (uint8x8_t s, uint8x8_t t);
11192int64_t pandn_sd (int64_t s, int64_t t);
11193int32x2_t pandn_sw (int32x2_t s, int32x2_t t);
11194int16x4_t pandn_sh (int16x4_t s, int16x4_t t);
11195int8x8_t pandn_sb (int8x8_t s, int8x8_t t);
11196uint16x4_t pavgh (uint16x4_t s, uint16x4_t t);
11197uint8x8_t pavgb (uint8x8_t s, uint8x8_t t);
11198uint32x2_t pcmpeqw_u (uint32x2_t s, uint32x2_t t);
11199uint16x4_t pcmpeqh_u (uint16x4_t s, uint16x4_t t);
11200uint8x8_t pcmpeqb_u (uint8x8_t s, uint8x8_t t);
11201int32x2_t pcmpeqw_s (int32x2_t s, int32x2_t t);
11202int16x4_t pcmpeqh_s (int16x4_t s, int16x4_t t);
11203int8x8_t pcmpeqb_s (int8x8_t s, int8x8_t t);
11204uint32x2_t pcmpgtw_u (uint32x2_t s, uint32x2_t t);
11205uint16x4_t pcmpgth_u (uint16x4_t s, uint16x4_t t);
11206uint8x8_t pcmpgtb_u (uint8x8_t s, uint8x8_t t);
11207int32x2_t pcmpgtw_s (int32x2_t s, int32x2_t t);
11208int16x4_t pcmpgth_s (int16x4_t s, int16x4_t t);
11209int8x8_t pcmpgtb_s (int8x8_t s, int8x8_t t);
11210uint16x4_t pextrh_u (uint16x4_t s, int field);
11211int16x4_t pextrh_s (int16x4_t s, int field);
11212uint16x4_t pinsrh_0_u (uint16x4_t s, uint16x4_t t);
11213uint16x4_t pinsrh_1_u (uint16x4_t s, uint16x4_t t);
11214uint16x4_t pinsrh_2_u (uint16x4_t s, uint16x4_t t);
11215uint16x4_t pinsrh_3_u (uint16x4_t s, uint16x4_t t);
11216int16x4_t pinsrh_0_s (int16x4_t s, int16x4_t t);
11217int16x4_t pinsrh_1_s (int16x4_t s, int16x4_t t);
11218int16x4_t pinsrh_2_s (int16x4_t s, int16x4_t t);
11219int16x4_t pinsrh_3_s (int16x4_t s, int16x4_t t);
11220int32x2_t pmaddhw (int16x4_t s, int16x4_t t);
11221int16x4_t pmaxsh (int16x4_t s, int16x4_t t);
11222uint8x8_t pmaxub (uint8x8_t s, uint8x8_t t);
11223int16x4_t pminsh (int16x4_t s, int16x4_t t);
11224uint8x8_t pminub (uint8x8_t s, uint8x8_t t);
11225uint8x8_t pmovmskb_u (uint8x8_t s);
11226int8x8_t pmovmskb_s (int8x8_t s);
11227uint16x4_t pmulhuh (uint16x4_t s, uint16x4_t t);
11228int16x4_t pmulhh (int16x4_t s, int16x4_t t);
11229int16x4_t pmullh (int16x4_t s, int16x4_t t);
11230int64_t pmuluw (uint32x2_t s, uint32x2_t t);
11231uint8x8_t pasubub (uint8x8_t s, uint8x8_t t);
11232uint16x4_t biadd (uint8x8_t s);
11233uint16x4_t psadbh (uint8x8_t s, uint8x8_t t);
11234uint16x4_t pshufh_u (uint16x4_t dest, uint16x4_t s, uint8_t order);
11235int16x4_t pshufh_s (int16x4_t dest, int16x4_t s, uint8_t order);
11236uint16x4_t psllh_u (uint16x4_t s, uint8_t amount);
11237int16x4_t psllh_s (int16x4_t s, uint8_t amount);
11238uint32x2_t psllw_u (uint32x2_t s, uint8_t amount);
11239int32x2_t psllw_s (int32x2_t s, uint8_t amount);
11240uint16x4_t psrlh_u (uint16x4_t s, uint8_t amount);
11241int16x4_t psrlh_s (int16x4_t s, uint8_t amount);
11242uint32x2_t psrlw_u (uint32x2_t s, uint8_t amount);
11243int32x2_t psrlw_s (int32x2_t s, uint8_t amount);
11244uint16x4_t psrah_u (uint16x4_t s, uint8_t amount);
11245int16x4_t psrah_s (int16x4_t s, uint8_t amount);
11246uint32x2_t psraw_u (uint32x2_t s, uint8_t amount);
11247int32x2_t psraw_s (int32x2_t s, uint8_t amount);
11248uint32x2_t psubw_u (uint32x2_t s, uint32x2_t t);
11249uint16x4_t psubh_u (uint16x4_t s, uint16x4_t t);
11250uint8x8_t psubb_u (uint8x8_t s, uint8x8_t t);
11251int32x2_t psubw_s (int32x2_t s, int32x2_t t);
11252int16x4_t psubh_s (int16x4_t s, int16x4_t t);
11253int8x8_t psubb_s (int8x8_t s, int8x8_t t);
11254uint64_t psubd_u (uint64_t s, uint64_t t);
11255int64_t psubd_s (int64_t s, int64_t t);
11256int16x4_t psubsh (int16x4_t s, int16x4_t t);
11257int8x8_t psubsb (int8x8_t s, int8x8_t t);
11258uint16x4_t psubush (uint16x4_t s, uint16x4_t t);
11259uint8x8_t psubusb (uint8x8_t s, uint8x8_t t);
11260uint32x2_t punpckhwd_u (uint32x2_t s, uint32x2_t t);
11261uint16x4_t punpckhhw_u (uint16x4_t s, uint16x4_t t);
11262uint8x8_t punpckhbh_u (uint8x8_t s, uint8x8_t t);
11263int32x2_t punpckhwd_s (int32x2_t s, int32x2_t t);
11264int16x4_t punpckhhw_s (int16x4_t s, int16x4_t t);
11265int8x8_t punpckhbh_s (int8x8_t s, int8x8_t t);
11266uint32x2_t punpcklwd_u (uint32x2_t s, uint32x2_t t);
11267uint16x4_t punpcklhw_u (uint16x4_t s, uint16x4_t t);
11268uint8x8_t punpcklbh_u (uint8x8_t s, uint8x8_t t);
11269int32x2_t punpcklwd_s (int32x2_t s, int32x2_t t);
11270int16x4_t punpcklhw_s (int16x4_t s, int16x4_t t);
11271int8x8_t punpcklbh_s (int8x8_t s, int8x8_t t);
11272@end smallexample
11273
dd2a386a 11274@menu
11275* Paired-Single Arithmetic::
11276* Paired-Single Built-in Functions::
11277* MIPS-3D Built-in Functions::
11278@end menu
11279
11280@node Paired-Single Arithmetic
11281@subsubsection Paired-Single Arithmetic
11282
11283The table below lists the @code{v2sf} operations for which hardware
11284support exists. @code{a}, @code{b} and @code{c} are @code{v2sf}
11285values and @code{x} is an integral value.
11286
11287@multitable @columnfractions .50 .50
11288@item C code @tab MIPS instruction
11289@item @code{a + b} @tab @code{add.ps}
11290@item @code{a - b} @tab @code{sub.ps}
11291@item @code{-a} @tab @code{neg.ps}
11292@item @code{a * b} @tab @code{mul.ps}
11293@item @code{a * b + c} @tab @code{madd.ps}
11294@item @code{a * b - c} @tab @code{msub.ps}
11295@item @code{-(a * b + c)} @tab @code{nmadd.ps}
11296@item @code{-(a * b - c)} @tab @code{nmsub.ps}
11297@item @code{x ? a : b} @tab @code{movn.ps}/@code{movz.ps}
11298@end multitable
11299
11300Note that the multiply-accumulate instructions can be disabled
11301using the command-line option @code{-mno-fused-madd}.
11302
11303@node Paired-Single Built-in Functions
11304@subsubsection Paired-Single Built-in Functions
11305
11306The following paired-single functions map directly to a particular
11307MIPS instruction. Please refer to the architecture specification
11308for details on what each instruction does.
11309
11310@table @code
11311@item v2sf __builtin_mips_pll_ps (v2sf, v2sf)
11312Pair lower lower (@code{pll.ps}).
11313
11314@item v2sf __builtin_mips_pul_ps (v2sf, v2sf)
11315Pair upper lower (@code{pul.ps}).
11316
11317@item v2sf __builtin_mips_plu_ps (v2sf, v2sf)
11318Pair lower upper (@code{plu.ps}).
11319
11320@item v2sf __builtin_mips_puu_ps (v2sf, v2sf)
11321Pair upper upper (@code{puu.ps}).
11322
11323@item v2sf __builtin_mips_cvt_ps_s (float, float)
11324Convert pair to paired single (@code{cvt.ps.s}).
11325
11326@item float __builtin_mips_cvt_s_pl (v2sf)
11327Convert pair lower to single (@code{cvt.s.pl}).
11328
11329@item float __builtin_mips_cvt_s_pu (v2sf)
11330Convert pair upper to single (@code{cvt.s.pu}).
11331
11332@item v2sf __builtin_mips_abs_ps (v2sf)
11333Absolute value (@code{abs.ps}).
11334
11335@item v2sf __builtin_mips_alnv_ps (v2sf, v2sf, int)
11336Align variable (@code{alnv.ps}).
11337
11338@emph{Note:} The value of the third parameter must be 0 or 4
11339modulo 8, otherwise the result will be unpredictable. Please read the
11340instruction description for details.
11341@end table
11342
11343The following multi-instruction functions are also available.
11344In each case, @var{cond} can be any of the 16 floating-point conditions:
11345@code{f}, @code{un}, @code{eq}, @code{ueq}, @code{olt}, @code{ult},
11346@code{ole}, @code{ule}, @code{sf}, @code{ngle}, @code{seq}, @code{ngl},
11347@code{lt}, @code{nge}, @code{le} or @code{ngt}.
11348
11349@table @code
11350@item v2sf __builtin_mips_movt_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
11351@itemx v2sf __builtin_mips_movf_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
11352Conditional move based on floating point comparison (@code{c.@var{cond}.ps},
11353@code{movt.ps}/@code{movf.ps}).
11354
11355The @code{movt} functions return the value @var{x} computed by:
11356
11357@smallexample
11358c.@var{cond}.ps @var{cc},@var{a},@var{b}
11359mov.ps @var{x},@var{c}
11360movt.ps @var{x},@var{d},@var{cc}
11361@end smallexample
11362
11363The @code{movf} functions are similar but use @code{movf.ps} instead
11364of @code{movt.ps}.
11365
11366@item int __builtin_mips_upper_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
11367@itemx int __builtin_mips_lower_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
11368Comparison of two paired-single values (@code{c.@var{cond}.ps},
11369@code{bc1t}/@code{bc1f}).
11370
11371These functions compare @var{a} and @var{b} using @code{c.@var{cond}.ps}
11372and return either the upper or lower half of the result. For example:
11373
11374@smallexample
11375v2sf a, b;
11376if (__builtin_mips_upper_c_eq_ps (a, b))
11377 upper_halves_are_equal ();
11378else
11379 upper_halves_are_unequal ();
11380
11381if (__builtin_mips_lower_c_eq_ps (a, b))
11382 lower_halves_are_equal ();
11383else
11384 lower_halves_are_unequal ();
11385@end smallexample
11386@end table
11387
11388@node MIPS-3D Built-in Functions
11389@subsubsection MIPS-3D Built-in Functions
11390
11391The MIPS-3D Application-Specific Extension (ASE) includes additional
11392paired-single instructions that are designed to improve the performance
11393of 3D graphics operations. Support for these instructions is controlled
11394by the @option{-mips3d} command-line option.
11395
11396The functions listed below map directly to a particular MIPS-3D
11397instruction. Please refer to the architecture specification for
11398more details on what each instruction does.
11399
11400@table @code
11401@item v2sf __builtin_mips_addr_ps (v2sf, v2sf)
11402Reduction add (@code{addr.ps}).
11403
11404@item v2sf __builtin_mips_mulr_ps (v2sf, v2sf)
11405Reduction multiply (@code{mulr.ps}).
11406
11407@item v2sf __builtin_mips_cvt_pw_ps (v2sf)
11408Convert paired single to paired word (@code{cvt.pw.ps}).
11409
11410@item v2sf __builtin_mips_cvt_ps_pw (v2sf)
11411Convert paired word to paired single (@code{cvt.ps.pw}).
11412
11413@item float __builtin_mips_recip1_s (float)
11414@itemx double __builtin_mips_recip1_d (double)
11415@itemx v2sf __builtin_mips_recip1_ps (v2sf)
11416Reduced precision reciprocal (sequence step 1) (@code{recip1.@var{fmt}}).
11417
11418@item float __builtin_mips_recip2_s (float, float)
11419@itemx double __builtin_mips_recip2_d (double, double)
11420@itemx v2sf __builtin_mips_recip2_ps (v2sf, v2sf)
11421Reduced precision reciprocal (sequence step 2) (@code{recip2.@var{fmt}}).
11422
11423@item float __builtin_mips_rsqrt1_s (float)
11424@itemx double __builtin_mips_rsqrt1_d (double)
11425@itemx v2sf __builtin_mips_rsqrt1_ps (v2sf)
11426Reduced precision reciprocal square root (sequence step 1)
11427(@code{rsqrt1.@var{fmt}}).
11428
11429@item float __builtin_mips_rsqrt2_s (float, float)
11430@itemx double __builtin_mips_rsqrt2_d (double, double)
11431@itemx v2sf __builtin_mips_rsqrt2_ps (v2sf, v2sf)
11432Reduced precision reciprocal square root (sequence step 2)
11433(@code{rsqrt2.@var{fmt}}).
11434@end table
11435
11436The following multi-instruction functions are also available.
11437In each case, @var{cond} can be any of the 16 floating-point conditions:
11438@code{f}, @code{un}, @code{eq}, @code{ueq}, @code{olt}, @code{ult},
11439@code{ole}, @code{ule}, @code{sf}, @code{ngle}, @code{seq},
11440@code{ngl}, @code{lt}, @code{nge}, @code{le} or @code{ngt}.
11441
11442@table @code
11443@item int __builtin_mips_cabs_@var{cond}_s (float @var{a}, float @var{b})
11444@itemx int __builtin_mips_cabs_@var{cond}_d (double @var{a}, double @var{b})
11445Absolute comparison of two scalar values (@code{cabs.@var{cond}.@var{fmt}},
11446@code{bc1t}/@code{bc1f}).
11447
11448These functions compare @var{a} and @var{b} using @code{cabs.@var{cond}.s}
11449or @code{cabs.@var{cond}.d} and return the result as a boolean value.
11450For example:
11451
11452@smallexample
11453float a, b;
11454if (__builtin_mips_cabs_eq_s (a, b))
11455 true ();
11456else
11457 false ();
11458@end smallexample
11459
11460@item int __builtin_mips_upper_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
11461@itemx int __builtin_mips_lower_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
11462Absolute comparison of two paired-single values (@code{cabs.@var{cond}.ps},
11463@code{bc1t}/@code{bc1f}).
11464
11465These functions compare @var{a} and @var{b} using @code{cabs.@var{cond}.ps}
11466and return either the upper or lower half of the result. For example:
11467
11468@smallexample
11469v2sf a, b;
11470if (__builtin_mips_upper_cabs_eq_ps (a, b))
11471 upper_halves_are_equal ();
11472else
11473 upper_halves_are_unequal ();
11474
11475if (__builtin_mips_lower_cabs_eq_ps (a, b))
11476 lower_halves_are_equal ();
11477else
11478 lower_halves_are_unequal ();
11479@end smallexample
11480
11481@item v2sf __builtin_mips_movt_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
11482@itemx v2sf __builtin_mips_movf_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
11483Conditional move based on absolute comparison (@code{cabs.@var{cond}.ps},
11484@code{movt.ps}/@code{movf.ps}).
11485
11486The @code{movt} functions return the value @var{x} computed by:
11487
11488@smallexample
11489cabs.@var{cond}.ps @var{cc},@var{a},@var{b}
11490mov.ps @var{x},@var{c}
11491movt.ps @var{x},@var{d},@var{cc}
11492@end smallexample
11493
11494The @code{movf} functions are similar but use @code{movf.ps} instead
11495of @code{movt.ps}.
11496
11497@item int __builtin_mips_any_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
11498@itemx int __builtin_mips_all_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
11499@itemx int __builtin_mips_any_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
11500@itemx int __builtin_mips_all_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
11501Comparison of two paired-single values
11502(@code{c.@var{cond}.ps}/@code{cabs.@var{cond}.ps},
11503@code{bc1any2t}/@code{bc1any2f}).
11504
11505These functions compare @var{a} and @var{b} using @code{c.@var{cond}.ps}
11506or @code{cabs.@var{cond}.ps}. The @code{any} forms return true if either
11507result is true and the @code{all} forms return true if both results are true.
11508For example:
11509
11510@smallexample
11511v2sf a, b;
11512if (__builtin_mips_any_c_eq_ps (a, b))
11513 one_is_true ();
11514else
11515 both_are_false ();
11516
11517if (__builtin_mips_all_c_eq_ps (a, b))
11518 both_are_true ();
11519else
11520 one_is_false ();
11521@end smallexample
11522
11523@item int __builtin_mips_any_c_@var{cond}_4s (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
11524@itemx int __builtin_mips_all_c_@var{cond}_4s (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
11525@itemx int __builtin_mips_any_cabs_@var{cond}_4s (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
11526@itemx int __builtin_mips_all_cabs_@var{cond}_4s (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
11527Comparison of four paired-single values
11528(@code{c.@var{cond}.ps}/@code{cabs.@var{cond}.ps},
11529@code{bc1any4t}/@code{bc1any4f}).
11530
11531These functions use @code{c.@var{cond}.ps} or @code{cabs.@var{cond}.ps}
11532to compare @var{a} with @var{b} and to compare @var{c} with @var{d}.
11533The @code{any} forms return true if any of the four results are true
11534and the @code{all} forms return true if all four results are true.
11535For example:
11536
11537@smallexample
11538v2sf a, b, c, d;
11539if (__builtin_mips_any_c_eq_4s (a, b, c, d))
11540 some_are_true ();
11541else
11542 all_are_false ();
11543
11544if (__builtin_mips_all_c_eq_4s (a, b, c, d))
11545 all_are_true ();
11546else
11547 some_are_false ();
11548@end smallexample
11549@end table
11550
8372e9ea 11551@node picoChip Built-in Functions
11552@subsection picoChip Built-in Functions
11553
11554GCC provides an interface to selected machine instructions from the
11555picoChip instruction set.
11556
11557@table @code
11558@item int __builtin_sbc (int @var{value})
11559Sign bit count. Return the number of consecutive bits in @var{value}
11560which have the same value as the sign-bit. The result is the number of
11561leading sign bits minus one, giving the number of redundant sign bits in
11562@var{value}.
11563
11564@item int __builtin_byteswap (int @var{value})
11565Byte swap. Return the result of swapping the upper and lower bytes of
11566@var{value}.
11567
11568@item int __builtin_brev (int @var{value})
11569Bit reversal. Return the result of reversing the bits in
11570@var{value}. Bit 15 is swapped with bit 0, bit 14 is swapped with bit 1,
11571and so on.
11572
11573@item int __builtin_adds (int @var{x}, int @var{y})
11574Saturating addition. Return the result of adding @var{x} and @var{y},
11575storing the value 32767 if the result overflows.
11576
11577@item int __builtin_subs (int @var{x}, int @var{y})
11578Saturating subtraction. Return the result of subtracting @var{y} from
1cbc9316 11579@var{x}, storing the value @minus{}32768 if the result overflows.
8372e9ea 11580
11581@item void __builtin_halt (void)
11582Halt. The processor will stop execution. This built-in is useful for
11583implementing assertions.
11584
11585@end table
11586
f5ec18cc 11587@node Other MIPS Built-in Functions
11588@subsection Other MIPS Built-in Functions
11589
11590GCC provides other MIPS-specific built-in functions:
11591
11592@table @code
11593@item void __builtin_mips_cache (int @var{op}, const volatile void *@var{addr})
11594Insert a @samp{cache} instruction with operands @var{op} and @var{addr}.
11595GCC defines the preprocessor macro @code{___GCC_HAVE_BUILTIN_MIPS_CACHE}
11596when this function is available.
11597@end table
11598
32374e3c 11599@node PowerPC AltiVec/VSX Built-in Functions
0ae4308e 11600@subsection PowerPC AltiVec Built-in Functions
11601
2b9c51df 11602GCC provides an interface for the PowerPC family of processors to access
11603the AltiVec operations described in Motorola's AltiVec Programming
11604Interface Manual. The interface is made available by including
11605@code{<altivec.h>} and using @option{-maltivec} and
11606@option{-mabi=altivec}. The interface supports the following vector
11607types.
0ae4308e 11608
2b9c51df 11609@smallexample
11610vector unsigned char
11611vector signed char
11612vector bool char
0ae4308e 11613
2b9c51df 11614vector unsigned short
11615vector signed short
11616vector bool short
11617vector pixel
11618
11619vector unsigned int
11620vector signed int
11621vector bool int
11622vector float
11623@end smallexample
11624
32374e3c 11625If @option{-mvsx} is used the following additional vector types are
11626implemented.
11627
11628@smallexample
11629vector unsigned long
11630vector signed long
11631vector double
11632@end smallexample
11633
11634The long types are only implemented for 64-bit code generation, and
11635the long type is only used in the floating point/integer conversion
11636instructions.
11637
2b9c51df 11638GCC's implementation of the high-level language interface available from
11639C and C++ code differs from Motorola's documentation in several ways.
11640
11641@itemize @bullet
11642
11643@item
11644A vector constant is a list of constant expressions within curly braces.
11645
11646@item
11647A vector initializer requires no cast if the vector constant is of the
11648same type as the variable it is initializing.
0ae4308e 11649
2b9c51df 11650@item
7731e499 11651If @code{signed} or @code{unsigned} is omitted, the signedness of the
11652vector type is the default signedness of the base type. The default
11653varies depending on the operating system, so a portable program should
11654always specify the signedness.
f67199e1 11655
11656@item
11657Compiling with @option{-maltivec} adds keywords @code{__vector},
89768577 11658@code{vector}, @code{__pixel}, @code{pixel}, @code{__bool} and
11659@code{bool}. When compiling ISO C, the context-sensitive substitution
11660of the keywords @code{vector}, @code{pixel} and @code{bool} is
11661disabled. To use them, you must include @code{<altivec.h>} instead.
f67199e1 11662
11663@item
11664GCC allows using a @code{typedef} name as the type specifier for a
11665vector type.
2b9c51df 11666
11667@item
11668For C, overloaded functions are implemented with macros so the following
11669does not work:
af08769f 11670
11671@smallexample
17e01dc5 11672 vec_add ((vector signed int)@{1, 2, 3, 4@}, foo);
af08769f 11673@end smallexample
11674
2b9c51df 11675Since @code{vec_add} is a macro, the vector constant in the example
11676is treated as four separate arguments. Wrap the entire argument in
11677parentheses for this to work.
11678@end itemize
af08769f 11679
15e5a1c8 11680@emph{Note:} Only the @code{<altivec.h>} interface is supported.
11681Internally, GCC uses built-in functions to achieve the functionality in
11682the aforementioned header file, but they are not supported and are
11683subject to change without notice.
11684
2b9c51df 11685The following interfaces are supported for the generic and specific
11686AltiVec operations and the AltiVec predicates. In cases where there
11687is a direct mapping between generic and specific operations, only the
11688generic names are shown here, although the specific operations can also
11689be used.
0ae4308e 11690
2b9c51df 11691Arguments that are documented as @code{const int} require literal
11692integral values within the range required for that operation.
0ae4308e 11693
2b9c51df 11694@smallexample
11695vector signed char vec_abs (vector signed char);
11696vector signed short vec_abs (vector signed short);
11697vector signed int vec_abs (vector signed int);
11698vector float vec_abs (vector float);
0ae4308e 11699
2b9c51df 11700vector signed char vec_abss (vector signed char);
11701vector signed short vec_abss (vector signed short);
11702vector signed int vec_abss (vector signed int);
0ae4308e 11703
2b9c51df 11704vector signed char vec_add (vector bool char, vector signed char);
11705vector signed char vec_add (vector signed char, vector bool char);
11706vector signed char vec_add (vector signed char, vector signed char);
11707vector unsigned char vec_add (vector bool char, vector unsigned char);
11708vector unsigned char vec_add (vector unsigned char, vector bool char);
8bdbaccf 11709vector unsigned char vec_add (vector unsigned char,
11710 vector unsigned char);
2b9c51df 11711vector signed short vec_add (vector bool short, vector signed short);
11712vector signed short vec_add (vector signed short, vector bool short);
0ae4308e 11713vector signed short vec_add (vector signed short, vector signed short);
2b9c51df 11714vector unsigned short vec_add (vector bool short,
8bdbaccf 11715 vector unsigned short);
11716vector unsigned short vec_add (vector unsigned short,
2b9c51df 11717 vector bool short);
8e1103d3 11718vector unsigned short vec_add (vector unsigned short,
11719 vector unsigned short);
2b9c51df 11720vector signed int vec_add (vector bool int, vector signed int);
11721vector signed int vec_add (vector signed int, vector bool int);
0ae4308e 11722vector signed int vec_add (vector signed int, vector signed int);
2b9c51df 11723vector unsigned int vec_add (vector bool int, vector unsigned int);
11724vector unsigned int vec_add (vector unsigned int, vector bool int);
0ae4308e 11725vector unsigned int vec_add (vector unsigned int, vector unsigned int);
11726vector float vec_add (vector float, vector float);
11727
2b9c51df 11728vector float vec_vaddfp (vector float, vector float);
11729
11730vector signed int vec_vadduwm (vector bool int, vector signed int);
11731vector signed int vec_vadduwm (vector signed int, vector bool int);
11732vector signed int vec_vadduwm (vector signed int, vector signed int);
11733vector unsigned int vec_vadduwm (vector bool int, vector unsigned int);
11734vector unsigned int vec_vadduwm (vector unsigned int, vector bool int);
11735vector unsigned int vec_vadduwm (vector unsigned int,
11736 vector unsigned int);
11737
11738vector signed short vec_vadduhm (vector bool short,
11739 vector signed short);
11740vector signed short vec_vadduhm (vector signed short,
11741 vector bool short);
11742vector signed short vec_vadduhm (vector signed short,
11743 vector signed short);
11744vector unsigned short vec_vadduhm (vector bool short,
11745 vector unsigned short);
11746vector unsigned short vec_vadduhm (vector unsigned short,
11747 vector bool short);
11748vector unsigned short vec_vadduhm (vector unsigned short,
11749 vector unsigned short);
11750
11751vector signed char vec_vaddubm (vector bool char, vector signed char);
11752vector signed char vec_vaddubm (vector signed char, vector bool char);
11753vector signed char vec_vaddubm (vector signed char, vector signed char);
11754vector unsigned char vec_vaddubm (vector bool char,
11755 vector unsigned char);
11756vector unsigned char vec_vaddubm (vector unsigned char,
11757 vector bool char);
11758vector unsigned char vec_vaddubm (vector unsigned char,
11759 vector unsigned char);
11760
0ae4308e 11761vector unsigned int vec_addc (vector unsigned int, vector unsigned int);
11762
2b9c51df 11763vector unsigned char vec_adds (vector bool char, vector unsigned char);
11764vector unsigned char vec_adds (vector unsigned char, vector bool char);
8bdbaccf 11765vector unsigned char vec_adds (vector unsigned char,
11766 vector unsigned char);
2b9c51df 11767vector signed char vec_adds (vector bool char, vector signed char);
11768vector signed char vec_adds (vector signed char, vector bool char);
0ae4308e 11769vector signed char vec_adds (vector signed char, vector signed char);
2b9c51df 11770vector unsigned short vec_adds (vector bool short,
8bdbaccf 11771 vector unsigned short);
11772vector unsigned short vec_adds (vector unsigned short,
2b9c51df 11773 vector bool short);
8e1103d3 11774vector unsigned short vec_adds (vector unsigned short,
11775 vector unsigned short);
2b9c51df 11776vector signed short vec_adds (vector bool short, vector signed short);
11777vector signed short vec_adds (vector signed short, vector bool short);
0ae4308e 11778vector signed short vec_adds (vector signed short, vector signed short);
2b9c51df 11779vector unsigned int vec_adds (vector bool int, vector unsigned int);
11780vector unsigned int vec_adds (vector unsigned int, vector bool int);
0ae4308e 11781vector unsigned int vec_adds (vector unsigned int, vector unsigned int);
2b9c51df 11782vector signed int vec_adds (vector bool int, vector signed int);
11783vector signed int vec_adds (vector signed int, vector bool int);
0ae4308e 11784vector signed int vec_adds (vector signed int, vector signed int);
11785
2b9c51df 11786vector signed int vec_vaddsws (vector bool int, vector signed int);
11787vector signed int vec_vaddsws (vector signed int, vector bool int);
11788vector signed int vec_vaddsws (vector signed int, vector signed int);
11789
11790vector unsigned int vec_vadduws (vector bool int, vector unsigned int);
11791vector unsigned int vec_vadduws (vector unsigned int, vector bool int);
11792vector unsigned int vec_vadduws (vector unsigned int,
11793 vector unsigned int);
11794
11795vector signed short vec_vaddshs (vector bool short,
11796 vector signed short);
11797vector signed short vec_vaddshs (vector signed short,
11798 vector bool short);
11799vector signed short vec_vaddshs (vector signed short,
11800 vector signed short);
11801
11802vector unsigned short vec_vadduhs (vector bool short,
11803 vector unsigned short);
11804vector unsigned short vec_vadduhs (vector unsigned short,
11805 vector bool short);
11806vector unsigned short vec_vadduhs (vector unsigned short,
11807 vector unsigned short);
11808
11809vector signed char vec_vaddsbs (vector bool char, vector signed char);
11810vector signed char vec_vaddsbs (vector signed char, vector bool char);
11811vector signed char vec_vaddsbs (vector signed char, vector signed char);
11812
11813vector unsigned char vec_vaddubs (vector bool char,
11814 vector unsigned char);
11815vector unsigned char vec_vaddubs (vector unsigned char,
11816 vector bool char);
11817vector unsigned char vec_vaddubs (vector unsigned char,
11818 vector unsigned char);
11819
0ae4308e 11820vector float vec_and (vector float, vector float);
2b9c51df 11821vector float vec_and (vector float, vector bool int);
11822vector float vec_and (vector bool int, vector float);
11823vector bool int vec_and (vector bool int, vector bool int);
11824vector signed int vec_and (vector bool int, vector signed int);
11825vector signed int vec_and (vector signed int, vector bool int);
0ae4308e 11826vector signed int vec_and (vector signed int, vector signed int);
2b9c51df 11827vector unsigned int vec_and (vector bool int, vector unsigned int);
11828vector unsigned int vec_and (vector unsigned int, vector bool int);
0ae4308e 11829vector unsigned int vec_and (vector unsigned int, vector unsigned int);
2b9c51df 11830vector bool short vec_and (vector bool short, vector bool short);
11831vector signed short vec_and (vector bool short, vector signed short);
11832vector signed short vec_and (vector signed short, vector bool short);
0ae4308e 11833vector signed short vec_and (vector signed short, vector signed short);
2b9c51df 11834vector unsigned short vec_and (vector bool short,
8bdbaccf 11835 vector unsigned short);
11836vector unsigned short vec_and (vector unsigned short,
2b9c51df 11837 vector bool short);
8e1103d3 11838vector unsigned short vec_and (vector unsigned short,
11839 vector unsigned short);
2b9c51df 11840vector signed char vec_and (vector bool char, vector signed char);
11841vector bool char vec_and (vector bool char, vector bool char);
11842vector signed char vec_and (vector signed char, vector bool char);
0ae4308e 11843vector signed char vec_and (vector signed char, vector signed char);
2b9c51df 11844vector unsigned char vec_and (vector bool char, vector unsigned char);
11845vector unsigned char vec_and (vector unsigned char, vector bool char);
8bdbaccf 11846vector unsigned char vec_and (vector unsigned char,
11847 vector unsigned char);
0ae4308e 11848
11849vector float vec_andc (vector float, vector float);
2b9c51df 11850vector float vec_andc (vector float, vector bool int);
11851vector float vec_andc (vector bool int, vector float);
11852vector bool int vec_andc (vector bool int, vector bool int);
11853vector signed int vec_andc (vector bool int, vector signed int);
11854vector signed int vec_andc (vector signed int, vector bool int);
0ae4308e 11855vector signed int vec_andc (vector signed int, vector signed int);
2b9c51df 11856vector unsigned int vec_andc (vector bool int, vector unsigned int);
11857vector unsigned int vec_andc (vector unsigned int, vector bool int);
0ae4308e 11858vector unsigned int vec_andc (vector unsigned int, vector unsigned int);
2b9c51df 11859vector bool short vec_andc (vector bool short, vector bool short);
11860vector signed short vec_andc (vector bool short, vector signed short);
11861vector signed short vec_andc (vector signed short, vector bool short);
0ae4308e 11862vector signed short vec_andc (vector signed short, vector signed short);
2b9c51df 11863vector unsigned short vec_andc (vector bool short,
8bdbaccf 11864 vector unsigned short);
11865vector unsigned short vec_andc (vector unsigned short,
2b9c51df 11866 vector bool short);
8e1103d3 11867vector unsigned short vec_andc (vector unsigned short,
11868 vector unsigned short);
2b9c51df 11869vector signed char vec_andc (vector bool char, vector signed char);
11870vector bool char vec_andc (vector bool char, vector bool char);
11871vector signed char vec_andc (vector signed char, vector bool char);
0ae4308e 11872vector signed char vec_andc (vector signed char, vector signed char);
2b9c51df 11873vector unsigned char vec_andc (vector bool char, vector unsigned char);
11874vector unsigned char vec_andc (vector unsigned char, vector bool char);
8bdbaccf 11875vector unsigned char vec_andc (vector unsigned char,
11876 vector unsigned char);
0ae4308e 11877
8bdbaccf 11878vector unsigned char vec_avg (vector unsigned char,
11879 vector unsigned char);
0ae4308e 11880vector signed char vec_avg (vector signed char, vector signed char);
8e1103d3 11881vector unsigned short vec_avg (vector unsigned short,
11882 vector unsigned short);
0ae4308e 11883vector signed short vec_avg (vector signed short, vector signed short);
11884vector unsigned int vec_avg (vector unsigned int, vector unsigned int);
11885vector signed int vec_avg (vector signed int, vector signed int);
11886
2b9c51df 11887vector signed int vec_vavgsw (vector signed int, vector signed int);
11888
11889vector unsigned int vec_vavguw (vector unsigned int,
11890 vector unsigned int);
11891
11892vector signed short vec_vavgsh (vector signed short,
11893 vector signed short);
11894
11895vector unsigned short vec_vavguh (vector unsigned short,
11896 vector unsigned short);
11897
11898vector signed char vec_vavgsb (vector signed char, vector signed char);
11899
11900vector unsigned char vec_vavgub (vector unsigned char,
11901 vector unsigned char);
11902
32374e3c 11903vector float vec_copysign (vector float);
11904
0ae4308e 11905vector float vec_ceil (vector float);
11906
11907vector signed int vec_cmpb (vector float, vector float);
11908
2b9c51df 11909vector bool char vec_cmpeq (vector signed char, vector signed char);
11910vector bool char vec_cmpeq (vector unsigned char, vector unsigned char);
11911vector bool short vec_cmpeq (vector signed short, vector signed short);
11912vector bool short vec_cmpeq (vector unsigned short,
11913 vector unsigned short);
11914vector bool int vec_cmpeq (vector signed int, vector signed int);
11915vector bool int vec_cmpeq (vector unsigned int, vector unsigned int);
11916vector bool int vec_cmpeq (vector float, vector float);
0ae4308e 11917
2b9c51df 11918vector bool int vec_vcmpeqfp (vector float, vector float);
0ae4308e 11919
2b9c51df 11920vector bool int vec_vcmpequw (vector signed int, vector signed int);
11921vector bool int vec_vcmpequw (vector unsigned int, vector unsigned int);
11922
11923vector bool short vec_vcmpequh (vector signed short,
11924 vector signed short);
11925vector bool short vec_vcmpequh (vector unsigned short,
11926 vector unsigned short);
0ae4308e 11927
2b9c51df 11928vector bool char vec_vcmpequb (vector signed char, vector signed char);
11929vector bool char vec_vcmpequb (vector unsigned char,
11930 vector unsigned char);
0ae4308e 11931
2b9c51df 11932vector bool int vec_cmpge (vector float, vector float);
0ae4308e 11933
2b9c51df 11934vector bool char vec_cmpgt (vector unsigned char, vector unsigned char);
11935vector bool char vec_cmpgt (vector signed char, vector signed char);
11936vector bool short vec_cmpgt (vector unsigned short,
11937 vector unsigned short);
11938vector bool short vec_cmpgt (vector signed short, vector signed short);
11939vector bool int vec_cmpgt (vector unsigned int, vector unsigned int);
11940vector bool int vec_cmpgt (vector signed int, vector signed int);
11941vector bool int vec_cmpgt (vector float, vector float);
11942
11943vector bool int vec_vcmpgtfp (vector float, vector float);
11944
11945vector bool int vec_vcmpgtsw (vector signed int, vector signed int);
11946
11947vector bool int vec_vcmpgtuw (vector unsigned int, vector unsigned int);
0ae4308e 11948
2b9c51df 11949vector bool short vec_vcmpgtsh (vector signed short,
11950 vector signed short);
11951
11952vector bool short vec_vcmpgtuh (vector unsigned short,
11953 vector unsigned short);
11954
11955vector bool char vec_vcmpgtsb (vector signed char, vector signed char);
11956
11957vector bool char vec_vcmpgtub (vector unsigned char,
11958 vector unsigned char);
11959
11960vector bool int vec_cmple (vector float, vector float);
11961
11962vector bool char vec_cmplt (vector unsigned char, vector unsigned char);
11963vector bool char vec_cmplt (vector signed char, vector signed char);
11964vector bool short vec_cmplt (vector unsigned short,
11965 vector unsigned short);
11966vector bool short vec_cmplt (vector signed short, vector signed short);
11967vector bool int vec_cmplt (vector unsigned int, vector unsigned int);
11968vector bool int vec_cmplt (vector signed int, vector signed int);
11969vector bool int vec_cmplt (vector float, vector float);
0ae4308e 11970
2b9c51df 11971vector float vec_ctf (vector unsigned int, const int);
11972vector float vec_ctf (vector signed int, const int);
0ae4308e 11973
2b9c51df 11974vector float vec_vcfsx (vector signed int, const int);
11975
11976vector float vec_vcfux (vector unsigned int, const int);
11977
11978vector signed int vec_cts (vector float, const int);
11979
11980vector unsigned int vec_ctu (vector float, const int);
11981
11982void vec_dss (const int);
0ae4308e 11983
11984void vec_dssall (void);
11985
2b9c51df 11986void vec_dst (const vector unsigned char *, int, const int);
11987void vec_dst (const vector signed char *, int, const int);
11988void vec_dst (const vector bool char *, int, const int);
11989void vec_dst (const vector unsigned short *, int, const int);
11990void vec_dst (const vector signed short *, int, const int);
11991void vec_dst (const vector bool short *, int, const int);
11992void vec_dst (const vector pixel *, int, const int);
11993void vec_dst (const vector unsigned int *, int, const int);
11994void vec_dst (const vector signed int *, int, const int);
11995void vec_dst (const vector bool int *, int, const int);
11996void vec_dst (const vector float *, int, const int);
11997void vec_dst (const unsigned char *, int, const int);
11998void vec_dst (const signed char *, int, const int);
11999void vec_dst (const unsigned short *, int, const int);
12000void vec_dst (const short *, int, const int);
12001void vec_dst (const unsigned int *, int, const int);
12002void vec_dst (const int *, int, const int);
12003void vec_dst (const unsigned long *, int, const int);
12004void vec_dst (const long *, int, const int);
12005void vec_dst (const float *, int, const int);
12006
12007void vec_dstst (const vector unsigned char *, int, const int);
12008void vec_dstst (const vector signed char *, int, const int);
12009void vec_dstst (const vector bool char *, int, const int);
12010void vec_dstst (const vector unsigned short *, int, const int);
12011void vec_dstst (const vector signed short *, int, const int);
12012void vec_dstst (const vector bool short *, int, const int);
12013void vec_dstst (const vector pixel *, int, const int);
12014void vec_dstst (const vector unsigned int *, int, const int);
12015void vec_dstst (const vector signed int *, int, const int);
12016void vec_dstst (const vector bool int *, int, const int);
12017void vec_dstst (const vector float *, int, const int);
12018void vec_dstst (const unsigned char *, int, const int);
12019void vec_dstst (const signed char *, int, const int);
12020void vec_dstst (const unsigned short *, int, const int);
12021void vec_dstst (const short *, int, const int);
12022void vec_dstst (const unsigned int *, int, const int);
12023void vec_dstst (const int *, int, const int);
12024void vec_dstst (const unsigned long *, int, const int);
12025void vec_dstst (const long *, int, const int);
12026void vec_dstst (const float *, int, const int);
12027
12028void vec_dststt (const vector unsigned char *, int, const int);
12029void vec_dststt (const vector signed char *, int, const int);
12030void vec_dststt (const vector bool char *, int, const int);
12031void vec_dststt (const vector unsigned short *, int, const int);
12032void vec_dststt (const vector signed short *, int, const int);
12033void vec_dststt (const vector bool short *, int, const int);
12034void vec_dststt (const vector pixel *, int, const int);
12035void vec_dststt (const vector unsigned int *, int, const int);
12036void vec_dststt (const vector signed int *, int, const int);
12037void vec_dststt (const vector bool int *, int, const int);
12038void vec_dststt (const vector float *, int, const int);
12039void vec_dststt (const unsigned char *, int, const int);
12040void vec_dststt (const signed char *, int, const int);
12041void vec_dststt (const unsigned short *, int, const int);
12042void vec_dststt (const short *, int, const int);
12043void vec_dststt (const unsigned int *, int, const int);
12044void vec_dststt (const int *, int, const int);
12045void vec_dststt (const unsigned long *, int, const int);
12046void vec_dststt (const long *, int, const int);
12047void vec_dststt (const float *, int, const int);
12048
12049void vec_dstt (const vector unsigned char *, int, const int);
12050void vec_dstt (const vector signed char *, int, const int);
12051void vec_dstt (const vector bool char *, int, const int);
12052void vec_dstt (const vector unsigned short *, int, const int);
12053void vec_dstt (const vector signed short *, int, const int);
12054void vec_dstt (const vector bool short *, int, const int);
12055void vec_dstt (const vector pixel *, int, const int);
12056void vec_dstt (const vector unsigned int *, int, const int);
12057void vec_dstt (const vector signed int *, int, const int);
12058void vec_dstt (const vector bool int *, int, const int);
12059void vec_dstt (const vector float *, int, const int);
12060void vec_dstt (const unsigned char *, int, const int);
12061void vec_dstt (const signed char *, int, const int);
12062void vec_dstt (const unsigned short *, int, const int);
12063void vec_dstt (const short *, int, const int);
12064void vec_dstt (const unsigned int *, int, const int);
12065void vec_dstt (const int *, int, const int);
12066void vec_dstt (const unsigned long *, int, const int);
12067void vec_dstt (const long *, int, const int);
12068void vec_dstt (const float *, int, const int);
12069
12070vector float vec_expte (vector float);
12071
12072vector float vec_floor (vector float);
12073
12074vector float vec_ld (int, const vector float *);
12075vector float vec_ld (int, const float *);
12076vector bool int vec_ld (int, const vector bool int *);
12077vector signed int vec_ld (int, const vector signed int *);
12078vector signed int vec_ld (int, const int *);
12079vector signed int vec_ld (int, const long *);
12080vector unsigned int vec_ld (int, const vector unsigned int *);
12081vector unsigned int vec_ld (int, const unsigned int *);
12082vector unsigned int vec_ld (int, const unsigned long *);
12083vector bool short vec_ld (int, const vector bool short *);
12084vector pixel vec_ld (int, const vector pixel *);
12085vector signed short vec_ld (int, const vector signed short *);
12086vector signed short vec_ld (int, const short *);
12087vector unsigned short vec_ld (int, const vector unsigned short *);
12088vector unsigned short vec_ld (int, const unsigned short *);
12089vector bool char vec_ld (int, const vector bool char *);
12090vector signed char vec_ld (int, const vector signed char *);
12091vector signed char vec_ld (int, const signed char *);
12092vector unsigned char vec_ld (int, const vector unsigned char *);
12093vector unsigned char vec_ld (int, const unsigned char *);
12094
12095vector signed char vec_lde (int, const signed char *);
12096vector unsigned char vec_lde (int, const unsigned char *);
12097vector signed short vec_lde (int, const short *);
12098vector unsigned short vec_lde (int, const unsigned short *);
12099vector float vec_lde (int, const float *);
12100vector signed int vec_lde (int, const int *);
12101vector unsigned int vec_lde (int, const unsigned int *);
12102vector signed int vec_lde (int, const long *);
12103vector unsigned int vec_lde (int, const unsigned long *);
12104
12105vector float vec_lvewx (int, float *);
12106vector signed int vec_lvewx (int, int *);
12107vector unsigned int vec_lvewx (int, unsigned int *);
12108vector signed int vec_lvewx (int, long *);
12109vector unsigned int vec_lvewx (int, unsigned long *);
12110
12111vector signed short vec_lvehx (int, short *);
12112vector unsigned short vec_lvehx (int, unsigned short *);
12113
12114vector signed char vec_lvebx (int, char *);
12115vector unsigned char vec_lvebx (int, unsigned char *);
12116
12117vector float vec_ldl (int, const vector float *);
12118vector float vec_ldl (int, const float *);
12119vector bool int vec_ldl (int, const vector bool int *);
12120vector signed int vec_ldl (int, const vector signed int *);
12121vector signed int vec_ldl (int, const int *);
12122vector signed int vec_ldl (int, const long *);
12123vector unsigned int vec_ldl (int, const vector unsigned int *);
12124vector unsigned int vec_ldl (int, const unsigned int *);
12125vector unsigned int vec_ldl (int, const unsigned long *);
12126vector bool short vec_ldl (int, const vector bool short *);
12127vector pixel vec_ldl (int, const vector pixel *);
12128vector signed short vec_ldl (int, const vector signed short *);
12129vector signed short vec_ldl (int, const short *);
12130vector unsigned short vec_ldl (int, const vector unsigned short *);
12131vector unsigned short vec_ldl (int, const unsigned short *);
12132vector bool char vec_ldl (int, const vector bool char *);
12133vector signed char vec_ldl (int, const vector signed char *);
12134vector signed char vec_ldl (int, const signed char *);
12135vector unsigned char vec_ldl (int, const vector unsigned char *);
12136vector unsigned char vec_ldl (int, const unsigned char *);
0ae4308e 12137
12138vector float vec_loge (vector float);
12139
2b9c51df 12140vector unsigned char vec_lvsl (int, const volatile unsigned char *);
12141vector unsigned char vec_lvsl (int, const volatile signed char *);
12142vector unsigned char vec_lvsl (int, const volatile unsigned short *);
12143vector unsigned char vec_lvsl (int, const volatile short *);
12144vector unsigned char vec_lvsl (int, const volatile unsigned int *);
12145vector unsigned char vec_lvsl (int, const volatile int *);
12146vector unsigned char vec_lvsl (int, const volatile unsigned long *);
12147vector unsigned char vec_lvsl (int, const volatile long *);
12148vector unsigned char vec_lvsl (int, const volatile float *);
12149
12150vector unsigned char vec_lvsr (int, const volatile unsigned char *);
12151vector unsigned char vec_lvsr (int, const volatile signed char *);
12152vector unsigned char vec_lvsr (int, const volatile unsigned short *);
12153vector unsigned char vec_lvsr (int, const volatile short *);
12154vector unsigned char vec_lvsr (int, const volatile unsigned int *);
12155vector unsigned char vec_lvsr (int, const volatile int *);
12156vector unsigned char vec_lvsr (int, const volatile unsigned long *);
12157vector unsigned char vec_lvsr (int, const volatile long *);
12158vector unsigned char vec_lvsr (int, const volatile float *);
0ae4308e 12159
12160vector float vec_madd (vector float, vector float, vector float);
12161
2b9c51df 12162vector signed short vec_madds (vector signed short,
12163 vector signed short,
8e1103d3 12164 vector signed short);
0ae4308e 12165
2b9c51df 12166vector unsigned char vec_max (vector bool char, vector unsigned char);
12167vector unsigned char vec_max (vector unsigned char, vector bool char);
8bdbaccf 12168vector unsigned char vec_max (vector unsigned char,
12169 vector unsigned char);
2b9c51df 12170vector signed char vec_max (vector bool char, vector signed char);
12171vector signed char vec_max (vector signed char, vector bool char);
0ae4308e 12172vector signed char vec_max (vector signed char, vector signed char);
2b9c51df 12173vector unsigned short vec_max (vector bool short,
8bdbaccf 12174 vector unsigned short);
12175vector unsigned short vec_max (vector unsigned short,
2b9c51df 12176 vector bool short);
8e1103d3 12177vector unsigned short vec_max (vector unsigned short,
12178 vector unsigned short);
2b9c51df 12179vector signed short vec_max (vector bool short, vector signed short);
12180vector signed short vec_max (vector signed short, vector bool short);
0ae4308e 12181vector signed short vec_max (vector signed short, vector signed short);
2b9c51df 12182vector unsigned int vec_max (vector bool int, vector unsigned int);
12183vector unsigned int vec_max (vector unsigned int, vector bool int);
0ae4308e 12184vector unsigned int vec_max (vector unsigned int, vector unsigned int);
2b9c51df 12185vector signed int vec_max (vector bool int, vector signed int);
12186vector signed int vec_max (vector signed int, vector bool int);
0ae4308e 12187vector signed int vec_max (vector signed int, vector signed int);
12188vector float vec_max (vector float, vector float);
12189
2b9c51df 12190vector float vec_vmaxfp (vector float, vector float);
12191
12192vector signed int vec_vmaxsw (vector bool int, vector signed int);
12193vector signed int vec_vmaxsw (vector signed int, vector bool int);
12194vector signed int vec_vmaxsw (vector signed int, vector signed int);
12195
12196vector unsigned int vec_vmaxuw (vector bool int, vector unsigned int);
12197vector unsigned int vec_vmaxuw (vector unsigned int, vector bool int);
12198vector unsigned int vec_vmaxuw (vector unsigned int,
12199 vector unsigned int);
12200
12201vector signed short vec_vmaxsh (vector bool short, vector signed short);
12202vector signed short vec_vmaxsh (vector signed short, vector bool short);
12203vector signed short vec_vmaxsh (vector signed short,
12204 vector signed short);
12205
12206vector unsigned short vec_vmaxuh (vector bool short,
12207 vector unsigned short);
12208vector unsigned short vec_vmaxuh (vector unsigned short,
12209 vector bool short);
12210vector unsigned short vec_vmaxuh (vector unsigned short,
12211 vector unsigned short);
12212
12213vector signed char vec_vmaxsb (vector bool char, vector signed char);
12214vector signed char vec_vmaxsb (vector signed char, vector bool char);
12215vector signed char vec_vmaxsb (vector signed char, vector signed char);
12216
12217vector unsigned char vec_vmaxub (vector bool char,
12218 vector unsigned char);
12219vector unsigned char vec_vmaxub (vector unsigned char,
12220 vector bool char);
12221vector unsigned char vec_vmaxub (vector unsigned char,
12222 vector unsigned char);
12223
12224vector bool char vec_mergeh (vector bool char, vector bool char);
0ae4308e 12225vector signed char vec_mergeh (vector signed char, vector signed char);
8e1103d3 12226vector unsigned char vec_mergeh (vector unsigned char,
12227 vector unsigned char);
2b9c51df 12228vector bool short vec_mergeh (vector bool short, vector bool short);
12229vector pixel vec_mergeh (vector pixel, vector pixel);
8bdbaccf 12230vector signed short vec_mergeh (vector signed short,
12231 vector signed short);
8e1103d3 12232vector unsigned short vec_mergeh (vector unsigned short,
12233 vector unsigned short);
0ae4308e 12234vector float vec_mergeh (vector float, vector float);
2b9c51df 12235vector bool int vec_mergeh (vector bool int, vector bool int);
0ae4308e 12236vector signed int vec_mergeh (vector signed int, vector signed int);
8bdbaccf 12237vector unsigned int vec_mergeh (vector unsigned int,
12238 vector unsigned int);
0ae4308e 12239
2b9c51df 12240vector float vec_vmrghw (vector float, vector float);
12241vector bool int vec_vmrghw (vector bool int, vector bool int);
12242vector signed int vec_vmrghw (vector signed int, vector signed int);
12243vector unsigned int vec_vmrghw (vector unsigned int,
12244 vector unsigned int);
12245
12246vector bool short vec_vmrghh (vector bool short, vector bool short);
12247vector signed short vec_vmrghh (vector signed short,
12248 vector signed short);
12249vector unsigned short vec_vmrghh (vector unsigned short,
12250 vector unsigned short);
12251vector pixel vec_vmrghh (vector pixel, vector pixel);
12252
12253vector bool char vec_vmrghb (vector bool char, vector bool char);
12254vector signed char vec_vmrghb (vector signed char, vector signed char);
12255vector unsigned char vec_vmrghb (vector unsigned char,
12256 vector unsigned char);
12257
12258vector bool char vec_mergel (vector bool char, vector bool char);
0ae4308e 12259vector signed char vec_mergel (vector signed char, vector signed char);
8e1103d3 12260vector unsigned char vec_mergel (vector unsigned char,
12261 vector unsigned char);
2b9c51df 12262vector bool short vec_mergel (vector bool short, vector bool short);
12263vector pixel vec_mergel (vector pixel, vector pixel);
8bdbaccf 12264vector signed short vec_mergel (vector signed short,
12265 vector signed short);
8e1103d3 12266vector unsigned short vec_mergel (vector unsigned short,
12267 vector unsigned short);
0ae4308e 12268vector float vec_mergel (vector float, vector float);
2b9c51df 12269vector bool int vec_mergel (vector bool int, vector bool int);
0ae4308e 12270vector signed int vec_mergel (vector signed int, vector signed int);
8bdbaccf 12271vector unsigned int vec_mergel (vector unsigned int,
12272 vector unsigned int);
0ae4308e 12273
2b9c51df 12274vector float vec_vmrglw (vector float, vector float);
12275vector signed int vec_vmrglw (vector signed int, vector signed int);
12276vector unsigned int vec_vmrglw (vector unsigned int,
12277 vector unsigned int);
12278vector bool int vec_vmrglw (vector bool int, vector bool int);
0ae4308e 12279
2b9c51df 12280vector bool short vec_vmrglh (vector bool short, vector bool short);
12281vector signed short vec_vmrglh (vector signed short,
12282 vector signed short);
12283vector unsigned short vec_vmrglh (vector unsigned short,
12284 vector unsigned short);
12285vector pixel vec_vmrglh (vector pixel, vector pixel);
12286
12287vector bool char vec_vmrglb (vector bool char, vector bool char);
12288vector signed char vec_vmrglb (vector signed char, vector signed char);
12289vector unsigned char vec_vmrglb (vector unsigned char,
12290 vector unsigned char);
0ae4308e 12291
2b9c51df 12292vector unsigned short vec_mfvscr (void);
0ae4308e 12293
2b9c51df 12294vector unsigned char vec_min (vector bool char, vector unsigned char);
12295vector unsigned char vec_min (vector unsigned char, vector bool char);
8bdbaccf 12296vector unsigned char vec_min (vector unsigned char,
12297 vector unsigned char);
2b9c51df 12298vector signed char vec_min (vector bool char, vector signed char);
12299vector signed char vec_min (vector signed char, vector bool char);
0ae4308e 12300vector signed char vec_min (vector signed char, vector signed char);
2b9c51df 12301vector unsigned short vec_min (vector bool short,
8bdbaccf 12302 vector unsigned short);
12303vector unsigned short vec_min (vector unsigned short,
2b9c51df 12304 vector bool short);
8e1103d3 12305vector unsigned short vec_min (vector unsigned short,
12306 vector unsigned short);
2b9c51df 12307vector signed short vec_min (vector bool short, vector signed short);
12308vector signed short vec_min (vector signed short, vector bool short);
0ae4308e 12309vector signed short vec_min (vector signed short, vector signed short);
2b9c51df 12310vector unsigned int vec_min (vector bool int, vector unsigned int);
12311vector unsigned int vec_min (vector unsigned int, vector bool int);
0ae4308e 12312vector unsigned int vec_min (vector unsigned int, vector unsigned int);
2b9c51df 12313vector signed int vec_min (vector bool int, vector signed int);
12314vector signed int vec_min (vector signed int, vector bool int);
0ae4308e 12315vector signed int vec_min (vector signed int, vector signed int);
12316vector float vec_min (vector float, vector float);
12317
2b9c51df 12318vector float vec_vminfp (vector float, vector float);
12319
12320vector signed int vec_vminsw (vector bool int, vector signed int);
12321vector signed int vec_vminsw (vector signed int, vector bool int);
12322vector signed int vec_vminsw (vector signed int, vector signed int);
12323
12324vector unsigned int vec_vminuw (vector bool int, vector unsigned int);
12325vector unsigned int vec_vminuw (vector unsigned int, vector bool int);
12326vector unsigned int vec_vminuw (vector unsigned int,
12327 vector unsigned int);
12328
12329vector signed short vec_vminsh (vector bool short, vector signed short);
12330vector signed short vec_vminsh (vector signed short, vector bool short);
12331vector signed short vec_vminsh (vector signed short,
12332 vector signed short);
12333
12334vector unsigned short vec_vminuh (vector bool short,
12335 vector unsigned short);
12336vector unsigned short vec_vminuh (vector unsigned short,
12337 vector bool short);
12338vector unsigned short vec_vminuh (vector unsigned short,
12339 vector unsigned short);
12340
12341vector signed char vec_vminsb (vector bool char, vector signed char);
12342vector signed char vec_vminsb (vector signed char, vector bool char);
12343vector signed char vec_vminsb (vector signed char, vector signed char);
12344
12345vector unsigned char vec_vminub (vector bool char,
12346 vector unsigned char);
12347vector unsigned char vec_vminub (vector unsigned char,
12348 vector bool char);
12349vector unsigned char vec_vminub (vector unsigned char,
12350 vector unsigned char);
12351
12352vector signed short vec_mladd (vector signed short,
12353 vector signed short,
8e1103d3 12354 vector signed short);
8bdbaccf 12355vector signed short vec_mladd (vector signed short,
12356 vector unsigned short,
8e1103d3 12357 vector unsigned short);
8bdbaccf 12358vector signed short vec_mladd (vector unsigned short,
12359 vector signed short,
8e1103d3 12360 vector signed short);
12361vector unsigned short vec_mladd (vector unsigned short,
12362 vector unsigned short,
12363 vector unsigned short);
12364
8bdbaccf 12365vector signed short vec_mradds (vector signed short,
12366 vector signed short,
8e1103d3 12367 vector signed short);
12368
8bdbaccf 12369vector unsigned int vec_msum (vector unsigned char,
12370 vector unsigned char,
8e1103d3 12371 vector unsigned int);
2b9c51df 12372vector signed int vec_msum (vector signed char,
12373 vector unsigned char,
8e1103d3 12374 vector signed int);
8bdbaccf 12375vector unsigned int vec_msum (vector unsigned short,
12376 vector unsigned short,
8e1103d3 12377 vector unsigned int);
2b9c51df 12378vector signed int vec_msum (vector signed short,
12379 vector signed short,
8e1103d3 12380 vector signed int);
12381
2b9c51df 12382vector signed int vec_vmsumshm (vector signed short,
12383 vector signed short,
12384 vector signed int);
12385
12386vector unsigned int vec_vmsumuhm (vector unsigned short,
12387 vector unsigned short,
12388 vector unsigned int);
12389
12390vector signed int vec_vmsummbm (vector signed char,
12391 vector unsigned char,
12392 vector signed int);
12393
12394vector unsigned int vec_vmsumubm (vector unsigned char,
12395 vector unsigned char,
12396 vector unsigned int);
12397
8e1103d3 12398vector unsigned int vec_msums (vector unsigned short,
8bdbaccf 12399 vector unsigned short,
12400 vector unsigned int);
2b9c51df 12401vector signed int vec_msums (vector signed short,
12402 vector signed short,
8e1103d3 12403 vector signed int);
0ae4308e 12404
2b9c51df 12405vector signed int vec_vmsumshs (vector signed short,
12406 vector signed short,
12407 vector signed int);
12408
12409vector unsigned int vec_vmsumuhs (vector unsigned short,
12410 vector unsigned short,
12411 vector unsigned int);
12412
0ae4308e 12413void vec_mtvscr (vector signed int);
12414void vec_mtvscr (vector unsigned int);
2b9c51df 12415void vec_mtvscr (vector bool int);
0ae4308e 12416void vec_mtvscr (vector signed short);
12417void vec_mtvscr (vector unsigned short);
2b9c51df 12418void vec_mtvscr (vector bool short);
12419void vec_mtvscr (vector pixel);
0ae4308e 12420void vec_mtvscr (vector signed char);
12421void vec_mtvscr (vector unsigned char);
2b9c51df 12422void vec_mtvscr (vector bool char);
0ae4308e 12423
8bdbaccf 12424vector unsigned short vec_mule (vector unsigned char,
12425 vector unsigned char);
2b9c51df 12426vector signed short vec_mule (vector signed char,
12427 vector signed char);
8bdbaccf 12428vector unsigned int vec_mule (vector unsigned short,
12429 vector unsigned short);
0ae4308e 12430vector signed int vec_mule (vector signed short, vector signed short);
12431
2b9c51df 12432vector signed int vec_vmulesh (vector signed short,
12433 vector signed short);
12434
12435vector unsigned int vec_vmuleuh (vector unsigned short,
12436 vector unsigned short);
12437
12438vector signed short vec_vmulesb (vector signed char,
12439 vector signed char);
12440
12441vector unsigned short vec_vmuleub (vector unsigned char,
12442 vector unsigned char);
12443
8bdbaccf 12444vector unsigned short vec_mulo (vector unsigned char,
12445 vector unsigned char);
0ae4308e 12446vector signed short vec_mulo (vector signed char, vector signed char);
8bdbaccf 12447vector unsigned int vec_mulo (vector unsigned short,
12448 vector unsigned short);
0ae4308e 12449vector signed int vec_mulo (vector signed short, vector signed short);
12450
2b9c51df 12451vector signed int vec_vmulosh (vector signed short,
12452 vector signed short);
12453
12454vector unsigned int vec_vmulouh (vector unsigned short,
12455 vector unsigned short);
12456
12457vector signed short vec_vmulosb (vector signed char,
12458 vector signed char);
12459
12460vector unsigned short vec_vmuloub (vector unsigned char,
12461 vector unsigned char);
12462
0ae4308e 12463vector float vec_nmsub (vector float, vector float, vector float);
12464
12465vector float vec_nor (vector float, vector float);
12466vector signed int vec_nor (vector signed int, vector signed int);
12467vector unsigned int vec_nor (vector unsigned int, vector unsigned int);
2b9c51df 12468vector bool int vec_nor (vector bool int, vector bool int);
0ae4308e 12469vector signed short vec_nor (vector signed short, vector signed short);
8e1103d3 12470vector unsigned short vec_nor (vector unsigned short,
12471 vector unsigned short);
2b9c51df 12472vector bool short vec_nor (vector bool short, vector bool short);
0ae4308e 12473vector signed char vec_nor (vector signed char, vector signed char);
8bdbaccf 12474vector unsigned char vec_nor (vector unsigned char,
12475 vector unsigned char);
2b9c51df 12476vector bool char vec_nor (vector bool char, vector bool char);
0ae4308e 12477
12478vector float vec_or (vector float, vector float);
2b9c51df 12479vector float vec_or (vector float, vector bool int);
12480vector float vec_or (vector bool int, vector float);
12481vector bool int vec_or (vector bool int, vector bool int);
12482vector signed int vec_or (vector bool int, vector signed int);
12483vector signed int vec_or (vector signed int, vector bool int);
0ae4308e 12484vector signed int vec_or (vector signed int, vector signed int);
2b9c51df 12485vector unsigned int vec_or (vector bool int, vector unsigned int);
12486vector unsigned int vec_or (vector unsigned int, vector bool int);
0ae4308e 12487vector unsigned int vec_or (vector unsigned int, vector unsigned int);
2b9c51df 12488vector bool short vec_or (vector bool short, vector bool short);
12489vector signed short vec_or (vector bool short, vector signed short);
12490vector signed short vec_or (vector signed short, vector bool short);
0ae4308e 12491vector signed short vec_or (vector signed short, vector signed short);
2b9c51df 12492vector unsigned short vec_or (vector bool short, vector unsigned short);
12493vector unsigned short vec_or (vector unsigned short, vector bool short);
8bdbaccf 12494vector unsigned short vec_or (vector unsigned short,
12495 vector unsigned short);
2b9c51df 12496vector signed char vec_or (vector bool char, vector signed char);
12497vector bool char vec_or (vector bool char, vector bool char);
12498vector signed char vec_or (vector signed char, vector bool char);
0ae4308e 12499vector signed char vec_or (vector signed char, vector signed char);
2b9c51df 12500vector unsigned char vec_or (vector bool char, vector unsigned char);
12501vector unsigned char vec_or (vector unsigned char, vector bool char);
8bdbaccf 12502vector unsigned char vec_or (vector unsigned char,
12503 vector unsigned char);
0ae4308e 12504
12505vector signed char vec_pack (vector signed short, vector signed short);
8e1103d3 12506vector unsigned char vec_pack (vector unsigned short,
12507 vector unsigned short);
2b9c51df 12508vector bool char vec_pack (vector bool short, vector bool short);
0ae4308e 12509vector signed short vec_pack (vector signed int, vector signed int);
8bdbaccf 12510vector unsigned short vec_pack (vector unsigned int,
12511 vector unsigned int);
2b9c51df 12512vector bool short vec_pack (vector bool int, vector bool int);
0ae4308e 12513
2b9c51df 12514vector bool short vec_vpkuwum (vector bool int, vector bool int);
12515vector signed short vec_vpkuwum (vector signed int, vector signed int);
12516vector unsigned short vec_vpkuwum (vector unsigned int,
12517 vector unsigned int);
12518
12519vector bool char vec_vpkuhum (vector bool short, vector bool short);
12520vector signed char vec_vpkuhum (vector signed short,
12521 vector signed short);
12522vector unsigned char vec_vpkuhum (vector unsigned short,
12523 vector unsigned short);
12524
12525vector pixel vec_packpx (vector unsigned int, vector unsigned int);
0ae4308e 12526
8e1103d3 12527vector unsigned char vec_packs (vector unsigned short,
12528 vector unsigned short);
0ae4308e 12529vector signed char vec_packs (vector signed short, vector signed short);
8bdbaccf 12530vector unsigned short vec_packs (vector unsigned int,
12531 vector unsigned int);
0ae4308e 12532vector signed short vec_packs (vector signed int, vector signed int);
12533
2b9c51df 12534vector signed short vec_vpkswss (vector signed int, vector signed int);
12535
12536vector unsigned short vec_vpkuwus (vector unsigned int,
12537 vector unsigned int);
12538
12539vector signed char vec_vpkshss (vector signed short,
12540 vector signed short);
12541
12542vector unsigned char vec_vpkuhus (vector unsigned short,
12543 vector unsigned short);
12544
8e1103d3 12545vector unsigned char vec_packsu (vector unsigned short,
12546 vector unsigned short);
8bdbaccf 12547vector unsigned char vec_packsu (vector signed short,
12548 vector signed short);
12549vector unsigned short vec_packsu (vector unsigned int,
12550 vector unsigned int);
0ae4308e 12551vector unsigned short vec_packsu (vector signed int, vector signed int);
12552
2b9c51df 12553vector unsigned short vec_vpkswus (vector signed int,
12554 vector signed int);
12555
12556vector unsigned char vec_vpkshus (vector signed short,
12557 vector signed short);
12558
12559vector float vec_perm (vector float,
12560 vector float,
8bdbaccf 12561 vector unsigned char);
2b9c51df 12562vector signed int vec_perm (vector signed int,
12563 vector signed int,
8e1103d3 12564 vector unsigned char);
2b9c51df 12565vector unsigned int vec_perm (vector unsigned int,
12566 vector unsigned int,
8e1103d3 12567 vector unsigned char);
2b9c51df 12568vector bool int vec_perm (vector bool int,
12569 vector bool int,
12570 vector unsigned char);
12571vector signed short vec_perm (vector signed short,
12572 vector signed short,
8e1103d3 12573 vector unsigned char);
12574vector unsigned short vec_perm (vector unsigned short,
12575 vector unsigned short,
12576 vector unsigned char);
2b9c51df 12577vector bool short vec_perm (vector bool short,
12578 vector bool short,
12579 vector unsigned char);
12580vector pixel vec_perm (vector pixel,
12581 vector pixel,
12582 vector unsigned char);
12583vector signed char vec_perm (vector signed char,
12584 vector signed char,
8e1103d3 12585 vector unsigned char);
8bdbaccf 12586vector unsigned char vec_perm (vector unsigned char,
12587 vector unsigned char,
8e1103d3 12588 vector unsigned char);
2b9c51df 12589vector bool char vec_perm (vector bool char,
12590 vector bool char,
12591 vector unsigned char);
0ae4308e 12592
12593vector float vec_re (vector float);
12594
2b9c51df 12595vector signed char vec_rl (vector signed char,
12596 vector unsigned char);
8bdbaccf 12597vector unsigned char vec_rl (vector unsigned char,
12598 vector unsigned char);
0ae4308e 12599vector signed short vec_rl (vector signed short, vector unsigned short);
8bdbaccf 12600vector unsigned short vec_rl (vector unsigned short,
12601 vector unsigned short);
0ae4308e 12602vector signed int vec_rl (vector signed int, vector unsigned int);
12603vector unsigned int vec_rl (vector unsigned int, vector unsigned int);
12604
2b9c51df 12605vector signed int vec_vrlw (vector signed int, vector unsigned int);
12606vector unsigned int vec_vrlw (vector unsigned int, vector unsigned int);
12607
12608vector signed short vec_vrlh (vector signed short,
12609 vector unsigned short);
12610vector unsigned short vec_vrlh (vector unsigned short,
12611 vector unsigned short);
12612
12613vector signed char vec_vrlb (vector signed char, vector unsigned char);
12614vector unsigned char vec_vrlb (vector unsigned char,
12615 vector unsigned char);
12616
0ae4308e 12617vector float vec_round (vector float);
12618
0eac26de 12619vector float vec_recip (vector float, vector float);
12620
12621vector float vec_rsqrt (vector float);
12622
0ae4308e 12623vector float vec_rsqrte (vector float);
12624
2b9c51df 12625vector float vec_sel (vector float, vector float, vector bool int);
0ae4308e 12626vector float vec_sel (vector float, vector float, vector unsigned int);
2b9c51df 12627vector signed int vec_sel (vector signed int,
12628 vector signed int,
12629 vector bool int);
12630vector signed int vec_sel (vector signed int,
12631 vector signed int,
8e1103d3 12632 vector unsigned int);
2b9c51df 12633vector unsigned int vec_sel (vector unsigned int,
12634 vector unsigned int,
12635 vector bool int);
12636vector unsigned int vec_sel (vector unsigned int,
12637 vector unsigned int,
8e1103d3 12638 vector unsigned int);
2b9c51df 12639vector bool int vec_sel (vector bool int,
12640 vector bool int,
12641 vector bool int);
12642vector bool int vec_sel (vector bool int,
12643 vector bool int,
12644 vector unsigned int);
12645vector signed short vec_sel (vector signed short,
12646 vector signed short,
12647 vector bool short);
12648vector signed short vec_sel (vector signed short,
12649 vector signed short,
8e1103d3 12650 vector unsigned short);
12651vector unsigned short vec_sel (vector unsigned short,
8bdbaccf 12652 vector unsigned short,
2b9c51df 12653 vector bool short);
8e1103d3 12654vector unsigned short vec_sel (vector unsigned short,
12655 vector unsigned short,
12656 vector unsigned short);
2b9c51df 12657vector bool short vec_sel (vector bool short,
12658 vector bool short,
12659 vector bool short);
12660vector bool short vec_sel (vector bool short,
12661 vector bool short,
12662 vector unsigned short);
12663vector signed char vec_sel (vector signed char,
12664 vector signed char,
12665 vector bool char);
12666vector signed char vec_sel (vector signed char,
12667 vector signed char,
8e1103d3 12668 vector unsigned char);
8bdbaccf 12669vector unsigned char vec_sel (vector unsigned char,
12670 vector unsigned char,
2b9c51df 12671 vector bool char);
8bdbaccf 12672vector unsigned char vec_sel (vector unsigned char,
12673 vector unsigned char,
8e1103d3 12674 vector unsigned char);
2b9c51df 12675vector bool char vec_sel (vector bool char,
12676 vector bool char,
12677 vector bool char);
12678vector bool char vec_sel (vector bool char,
12679 vector bool char,
12680 vector unsigned char);
12681
12682vector signed char vec_sl (vector signed char,
12683 vector unsigned char);
8bdbaccf 12684vector unsigned char vec_sl (vector unsigned char,
12685 vector unsigned char);
0ae4308e 12686vector signed short vec_sl (vector signed short, vector unsigned short);
8bdbaccf 12687vector unsigned short vec_sl (vector unsigned short,
12688 vector unsigned short);
0ae4308e 12689vector signed int vec_sl (vector signed int, vector unsigned int);
12690vector unsigned int vec_sl (vector unsigned int, vector unsigned int);
12691
2b9c51df 12692vector signed int vec_vslw (vector signed int, vector unsigned int);
12693vector unsigned int vec_vslw (vector unsigned int, vector unsigned int);
12694
12695vector signed short vec_vslh (vector signed short,
12696 vector unsigned short);
12697vector unsigned short vec_vslh (vector unsigned short,
12698 vector unsigned short);
12699
12700vector signed char vec_vslb (vector signed char, vector unsigned char);
12701vector unsigned char vec_vslb (vector unsigned char,
12702 vector unsigned char);
12703
12704vector float vec_sld (vector float, vector float, const int);
12705vector signed int vec_sld (vector signed int,
12706 vector signed int,
12707 const int);
12708vector unsigned int vec_sld (vector unsigned int,
12709 vector unsigned int,
12710 const int);
12711vector bool int vec_sld (vector bool int,
12712 vector bool int,
12713 const int);
12714vector signed short vec_sld (vector signed short,
12715 vector signed short,
12716 const int);
8e1103d3 12717vector unsigned short vec_sld (vector unsigned short,
2b9c51df 12718 vector unsigned short,
12719 const int);
12720vector bool short vec_sld (vector bool short,
12721 vector bool short,
12722 const int);
12723vector pixel vec_sld (vector pixel,
12724 vector pixel,
12725 const int);
12726vector signed char vec_sld (vector signed char,
12727 vector signed char,
12728 const int);
8bdbaccf 12729vector unsigned char vec_sld (vector unsigned char,
12730 vector unsigned char,
2b9c51df 12731 const int);
12732vector bool char vec_sld (vector bool char,
12733 vector bool char,
12734 const int);
0ae4308e 12735
2b9c51df 12736vector signed int vec_sll (vector signed int,
12737 vector unsigned int);
12738vector signed int vec_sll (vector signed int,
12739 vector unsigned short);
12740vector signed int vec_sll (vector signed int,
12741 vector unsigned char);
12742vector unsigned int vec_sll (vector unsigned int,
12743 vector unsigned int);
8bdbaccf 12744vector unsigned int vec_sll (vector unsigned int,
12745 vector unsigned short);
2b9c51df 12746vector unsigned int vec_sll (vector unsigned int,
12747 vector unsigned char);
12748vector bool int vec_sll (vector bool int,
12749 vector unsigned int);
12750vector bool int vec_sll (vector bool int,
12751 vector unsigned short);
12752vector bool int vec_sll (vector bool int,
12753 vector unsigned char);
12754vector signed short vec_sll (vector signed short,
12755 vector unsigned int);
8bdbaccf 12756vector signed short vec_sll (vector signed short,
12757 vector unsigned short);
2b9c51df 12758vector signed short vec_sll (vector signed short,
12759 vector unsigned char);
8bdbaccf 12760vector unsigned short vec_sll (vector unsigned short,
12761 vector unsigned int);
8e1103d3 12762vector unsigned short vec_sll (vector unsigned short,
12763 vector unsigned short);
8bdbaccf 12764vector unsigned short vec_sll (vector unsigned short,
12765 vector unsigned char);
2b9c51df 12766vector bool short vec_sll (vector bool short, vector unsigned int);
12767vector bool short vec_sll (vector bool short, vector unsigned short);
12768vector bool short vec_sll (vector bool short, vector unsigned char);
12769vector pixel vec_sll (vector pixel, vector unsigned int);
12770vector pixel vec_sll (vector pixel, vector unsigned short);
12771vector pixel vec_sll (vector pixel, vector unsigned char);
0ae4308e 12772vector signed char vec_sll (vector signed char, vector unsigned int);
12773vector signed char vec_sll (vector signed char, vector unsigned short);
12774vector signed char vec_sll (vector signed char, vector unsigned char);
8bdbaccf 12775vector unsigned char vec_sll (vector unsigned char,
12776 vector unsigned int);
12777vector unsigned char vec_sll (vector unsigned char,
12778 vector unsigned short);
12779vector unsigned char vec_sll (vector unsigned char,
12780 vector unsigned char);
2b9c51df 12781vector bool char vec_sll (vector bool char, vector unsigned int);
12782vector bool char vec_sll (vector bool char, vector unsigned short);
12783vector bool char vec_sll (vector bool char, vector unsigned char);
0ae4308e 12784
12785vector float vec_slo (vector float, vector signed char);
12786vector float vec_slo (vector float, vector unsigned char);
12787vector signed int vec_slo (vector signed int, vector signed char);
12788vector signed int vec_slo (vector signed int, vector unsigned char);
12789vector unsigned int vec_slo (vector unsigned int, vector signed char);
12790vector unsigned int vec_slo (vector unsigned int, vector unsigned char);
0ae4308e 12791vector signed short vec_slo (vector signed short, vector signed char);
12792vector signed short vec_slo (vector signed short, vector unsigned char);
8bdbaccf 12793vector unsigned short vec_slo (vector unsigned short,
12794 vector signed char);
12795vector unsigned short vec_slo (vector unsigned short,
12796 vector unsigned char);
2b9c51df 12797vector pixel vec_slo (vector pixel, vector signed char);
12798vector pixel vec_slo (vector pixel, vector unsigned char);
0ae4308e 12799vector signed char vec_slo (vector signed char, vector signed char);
12800vector signed char vec_slo (vector signed char, vector unsigned char);
12801vector unsigned char vec_slo (vector unsigned char, vector signed char);
8bdbaccf 12802vector unsigned char vec_slo (vector unsigned char,
12803 vector unsigned char);
0ae4308e 12804
2b9c51df 12805vector signed char vec_splat (vector signed char, const int);
12806vector unsigned char vec_splat (vector unsigned char, const int);
12807vector bool char vec_splat (vector bool char, const int);
12808vector signed short vec_splat (vector signed short, const int);
12809vector unsigned short vec_splat (vector unsigned short, const int);
12810vector bool short vec_splat (vector bool short, const int);
12811vector pixel vec_splat (vector pixel, const int);
12812vector float vec_splat (vector float, const int);
12813vector signed int vec_splat (vector signed int, const int);
12814vector unsigned int vec_splat (vector unsigned int, const int);
12815vector bool int vec_splat (vector bool int, const int);
12816
12817vector float vec_vspltw (vector float, const int);
12818vector signed int vec_vspltw (vector signed int, const int);
12819vector unsigned int vec_vspltw (vector unsigned int, const int);
12820vector bool int vec_vspltw (vector bool int, const int);
12821
12822vector bool short vec_vsplth (vector bool short, const int);
12823vector signed short vec_vsplth (vector signed short, const int);
12824vector unsigned short vec_vsplth (vector unsigned short, const int);
12825vector pixel vec_vsplth (vector pixel, const int);
12826
12827vector signed char vec_vspltb (vector signed char, const int);
12828vector unsigned char vec_vspltb (vector unsigned char, const int);
12829vector bool char vec_vspltb (vector bool char, const int);
0ae4308e 12830
2b9c51df 12831vector signed char vec_splat_s8 (const int);
0ae4308e 12832
2b9c51df 12833vector signed short vec_splat_s16 (const int);
0ae4308e 12834
2b9c51df 12835vector signed int vec_splat_s32 (const int);
0ae4308e 12836
2b9c51df 12837vector unsigned char vec_splat_u8 (const int);
0ae4308e 12838
2b9c51df 12839vector unsigned short vec_splat_u16 (const int);
0ae4308e 12840
2b9c51df 12841vector unsigned int vec_splat_u32 (const int);
0ae4308e 12842
12843vector signed char vec_sr (vector signed char, vector unsigned char);
8bdbaccf 12844vector unsigned char vec_sr (vector unsigned char,
12845 vector unsigned char);
2b9c51df 12846vector signed short vec_sr (vector signed short,
12847 vector unsigned short);
8bdbaccf 12848vector unsigned short vec_sr (vector unsigned short,
12849 vector unsigned short);
0ae4308e 12850vector signed int vec_sr (vector signed int, vector unsigned int);
12851vector unsigned int vec_sr (vector unsigned int, vector unsigned int);
12852
2b9c51df 12853vector signed int vec_vsrw (vector signed int, vector unsigned int);
12854vector unsigned int vec_vsrw (vector unsigned int, vector unsigned int);
12855
12856vector signed short vec_vsrh (vector signed short,
12857 vector unsigned short);
12858vector unsigned short vec_vsrh (vector unsigned short,
12859 vector unsigned short);
12860
12861vector signed char vec_vsrb (vector signed char, vector unsigned char);
12862vector unsigned char vec_vsrb (vector unsigned char,
12863 vector unsigned char);
12864
0ae4308e 12865vector signed char vec_sra (vector signed char, vector unsigned char);
8bdbaccf 12866vector unsigned char vec_sra (vector unsigned char,
12867 vector unsigned char);
12868vector signed short vec_sra (vector signed short,
12869 vector unsigned short);
8e1103d3 12870vector unsigned short vec_sra (vector unsigned short,
12871 vector unsigned short);
0ae4308e 12872vector signed int vec_sra (vector signed int, vector unsigned int);
12873vector unsigned int vec_sra (vector unsigned int, vector unsigned int);
12874
2b9c51df 12875vector signed int vec_vsraw (vector signed int, vector unsigned int);
12876vector unsigned int vec_vsraw (vector unsigned int,
12877 vector unsigned int);
12878
12879vector signed short vec_vsrah (vector signed short,
12880 vector unsigned short);
12881vector unsigned short vec_vsrah (vector unsigned short,
12882 vector unsigned short);
12883
12884vector signed char vec_vsrab (vector signed char, vector unsigned char);
12885vector unsigned char vec_vsrab (vector unsigned char,
12886 vector unsigned char);
12887
0ae4308e 12888vector signed int vec_srl (vector signed int, vector unsigned int);
12889vector signed int vec_srl (vector signed int, vector unsigned short);
12890vector signed int vec_srl (vector signed int, vector unsigned char);
12891vector unsigned int vec_srl (vector unsigned int, vector unsigned int);
8bdbaccf 12892vector unsigned int vec_srl (vector unsigned int,
12893 vector unsigned short);
0ae4308e 12894vector unsigned int vec_srl (vector unsigned int, vector unsigned char);
2b9c51df 12895vector bool int vec_srl (vector bool int, vector unsigned int);
12896vector bool int vec_srl (vector bool int, vector unsigned short);
12897vector bool int vec_srl (vector bool int, vector unsigned char);
0ae4308e 12898vector signed short vec_srl (vector signed short, vector unsigned int);
8bdbaccf 12899vector signed short vec_srl (vector signed short,
12900 vector unsigned short);
0ae4308e 12901vector signed short vec_srl (vector signed short, vector unsigned char);
8bdbaccf 12902vector unsigned short vec_srl (vector unsigned short,
12903 vector unsigned int);
8e1103d3 12904vector unsigned short vec_srl (vector unsigned short,
12905 vector unsigned short);
8bdbaccf 12906vector unsigned short vec_srl (vector unsigned short,
12907 vector unsigned char);
2b9c51df 12908vector bool short vec_srl (vector bool short, vector unsigned int);
12909vector bool short vec_srl (vector bool short, vector unsigned short);
12910vector bool short vec_srl (vector bool short, vector unsigned char);
12911vector pixel vec_srl (vector pixel, vector unsigned int);
12912vector pixel vec_srl (vector pixel, vector unsigned short);
12913vector pixel vec_srl (vector pixel, vector unsigned char);
0ae4308e 12914vector signed char vec_srl (vector signed char, vector unsigned int);
12915vector signed char vec_srl (vector signed char, vector unsigned short);
12916vector signed char vec_srl (vector signed char, vector unsigned char);
8bdbaccf 12917vector unsigned char vec_srl (vector unsigned char,
12918 vector unsigned int);
12919vector unsigned char vec_srl (vector unsigned char,
12920 vector unsigned short);
12921vector unsigned char vec_srl (vector unsigned char,
12922 vector unsigned char);
2b9c51df 12923vector bool char vec_srl (vector bool char, vector unsigned int);
12924vector bool char vec_srl (vector bool char, vector unsigned short);
12925vector bool char vec_srl (vector bool char, vector unsigned char);
0ae4308e 12926
12927vector float vec_sro (vector float, vector signed char);
12928vector float vec_sro (vector float, vector unsigned char);
12929vector signed int vec_sro (vector signed int, vector signed char);
12930vector signed int vec_sro (vector signed int, vector unsigned char);
12931vector unsigned int vec_sro (vector unsigned int, vector signed char);
12932vector unsigned int vec_sro (vector unsigned int, vector unsigned char);
0ae4308e 12933vector signed short vec_sro (vector signed short, vector signed char);
12934vector signed short vec_sro (vector signed short, vector unsigned char);
8bdbaccf 12935vector unsigned short vec_sro (vector unsigned short,
12936 vector signed char);
12937vector unsigned short vec_sro (vector unsigned short,
12938 vector unsigned char);
2b9c51df 12939vector pixel vec_sro (vector pixel, vector signed char);
12940vector pixel vec_sro (vector pixel, vector unsigned char);
0ae4308e 12941vector signed char vec_sro (vector signed char, vector signed char);
12942vector signed char vec_sro (vector signed char, vector unsigned char);
12943vector unsigned char vec_sro (vector unsigned char, vector signed char);
8bdbaccf 12944vector unsigned char vec_sro (vector unsigned char,
12945 vector unsigned char);
0ae4308e 12946
0ae4308e 12947void vec_st (vector float, int, vector float *);
2b9c51df 12948void vec_st (vector float, int, float *);
12949void vec_st (vector signed int, int, vector signed int *);
0ae4308e 12950void vec_st (vector signed int, int, int *);
0ae4308e 12951void vec_st (vector unsigned int, int, vector unsigned int *);
2b9c51df 12952void vec_st (vector unsigned int, int, unsigned int *);
12953void vec_st (vector bool int, int, vector bool int *);
12954void vec_st (vector bool int, int, unsigned int *);
12955void vec_st (vector bool int, int, int *);
0ae4308e 12956void vec_st (vector signed short, int, vector signed short *);
2b9c51df 12957void vec_st (vector signed short, int, short *);
0ae4308e 12958void vec_st (vector unsigned short, int, vector unsigned short *);
2b9c51df 12959void vec_st (vector unsigned short, int, unsigned short *);
12960void vec_st (vector bool short, int, vector bool short *);
12961void vec_st (vector bool short, int, unsigned short *);
12962void vec_st (vector pixel, int, vector pixel *);
12963void vec_st (vector pixel, int, unsigned short *);
12964void vec_st (vector pixel, int, short *);
12965void vec_st (vector bool short, int, short *);
0ae4308e 12966void vec_st (vector signed char, int, vector signed char *);
2b9c51df 12967void vec_st (vector signed char, int, signed char *);
0ae4308e 12968void vec_st (vector unsigned char, int, vector unsigned char *);
2b9c51df 12969void vec_st (vector unsigned char, int, unsigned char *);
12970void vec_st (vector bool char, int, vector bool char *);
12971void vec_st (vector bool char, int, unsigned char *);
12972void vec_st (vector bool char, int, signed char *);
0ae4308e 12973
0ae4308e 12974void vec_ste (vector signed char, int, signed char *);
12975void vec_ste (vector unsigned char, int, unsigned char *);
2b9c51df 12976void vec_ste (vector bool char, int, signed char *);
12977void vec_ste (vector bool char, int, unsigned char *);
0ae4308e 12978void vec_ste (vector signed short, int, short *);
2b9c51df 12979void vec_ste (vector unsigned short, int, unsigned short *);
12980void vec_ste (vector bool short, int, short *);
12981void vec_ste (vector bool short, int, unsigned short *);
12982void vec_ste (vector pixel, int, short *);
12983void vec_ste (vector pixel, int, unsigned short *);
12984void vec_ste (vector float, int, float *);
0ae4308e 12985void vec_ste (vector signed int, int, int *);
12986void vec_ste (vector unsigned int, int, unsigned int *);
2b9c51df 12987void vec_ste (vector bool int, int, int *);
12988void vec_ste (vector bool int, int, unsigned int *);
12989
12990void vec_stvewx (vector float, int, float *);
12991void vec_stvewx (vector signed int, int, int *);
12992void vec_stvewx (vector unsigned int, int, unsigned int *);
12993void vec_stvewx (vector bool int, int, int *);
12994void vec_stvewx (vector bool int, int, unsigned int *);
12995
12996void vec_stvehx (vector signed short, int, short *);
12997void vec_stvehx (vector unsigned short, int, unsigned short *);
12998void vec_stvehx (vector bool short, int, short *);
12999void vec_stvehx (vector bool short, int, unsigned short *);
13000void vec_stvehx (vector pixel, int, short *);
13001void vec_stvehx (vector pixel, int, unsigned short *);
13002
13003void vec_stvebx (vector signed char, int, signed char *);
13004void vec_stvebx (vector unsigned char, int, unsigned char *);
13005void vec_stvebx (vector bool char, int, signed char *);
13006void vec_stvebx (vector bool char, int, unsigned char *);
0ae4308e 13007
13008void vec_stl (vector float, int, vector float *);
13009void vec_stl (vector float, int, float *);
13010void vec_stl (vector signed int, int, vector signed int *);
13011void vec_stl (vector signed int, int, int *);
0ae4308e 13012void vec_stl (vector unsigned int, int, vector unsigned int *);
13013void vec_stl (vector unsigned int, int, unsigned int *);
2b9c51df 13014void vec_stl (vector bool int, int, vector bool int *);
13015void vec_stl (vector bool int, int, unsigned int *);
13016void vec_stl (vector bool int, int, int *);
0ae4308e 13017void vec_stl (vector signed short, int, vector signed short *);
2b9c51df 13018void vec_stl (vector signed short, int, short *);
13019void vec_stl (vector unsigned short, int, vector unsigned short *);
0ae4308e 13020void vec_stl (vector unsigned short, int, unsigned short *);
2b9c51df 13021void vec_stl (vector bool short, int, vector bool short *);
13022void vec_stl (vector bool short, int, unsigned short *);
13023void vec_stl (vector bool short, int, short *);
13024void vec_stl (vector pixel, int, vector pixel *);
13025void vec_stl (vector pixel, int, unsigned short *);
13026void vec_stl (vector pixel, int, short *);
0ae4308e 13027void vec_stl (vector signed char, int, vector signed char *);
2b9c51df 13028void vec_stl (vector signed char, int, signed char *);
0ae4308e 13029void vec_stl (vector unsigned char, int, vector unsigned char *);
2b9c51df 13030void vec_stl (vector unsigned char, int, unsigned char *);
13031void vec_stl (vector bool char, int, vector bool char *);
13032void vec_stl (vector bool char, int, unsigned char *);
13033void vec_stl (vector bool char, int, signed char *);
0ae4308e 13034
2b9c51df 13035vector signed char vec_sub (vector bool char, vector signed char);
13036vector signed char vec_sub (vector signed char, vector bool char);
0ae4308e 13037vector signed char vec_sub (vector signed char, vector signed char);
2b9c51df 13038vector unsigned char vec_sub (vector bool char, vector unsigned char);
13039vector unsigned char vec_sub (vector unsigned char, vector bool char);
8bdbaccf 13040vector unsigned char vec_sub (vector unsigned char,
13041 vector unsigned char);
2b9c51df 13042vector signed short vec_sub (vector bool short, vector signed short);
13043vector signed short vec_sub (vector signed short, vector bool short);
0ae4308e 13044vector signed short vec_sub (vector signed short, vector signed short);
2b9c51df 13045vector unsigned short vec_sub (vector bool short,
8bdbaccf 13046 vector unsigned short);
13047vector unsigned short vec_sub (vector unsigned short,
2b9c51df 13048 vector bool short);
8e1103d3 13049vector unsigned short vec_sub (vector unsigned short,
13050 vector unsigned short);
2b9c51df 13051vector signed int vec_sub (vector bool int, vector signed int);
13052vector signed int vec_sub (vector signed int, vector bool int);
0ae4308e 13053vector signed int vec_sub (vector signed int, vector signed int);
2b9c51df 13054vector unsigned int vec_sub (vector bool int, vector unsigned int);
13055vector unsigned int vec_sub (vector unsigned int, vector bool int);
0ae4308e 13056vector unsigned int vec_sub (vector unsigned int, vector unsigned int);
13057vector float vec_sub (vector float, vector float);
13058
2b9c51df 13059vector float vec_vsubfp (vector float, vector float);
13060
13061vector signed int vec_vsubuwm (vector bool int, vector signed int);
13062vector signed int vec_vsubuwm (vector signed int, vector bool int);
13063vector signed int vec_vsubuwm (vector signed int, vector signed int);
13064vector unsigned int vec_vsubuwm (vector bool int, vector unsigned int);
13065vector unsigned int vec_vsubuwm (vector unsigned int, vector bool int);
13066vector unsigned int vec_vsubuwm (vector unsigned int,
13067 vector unsigned int);
13068
13069vector signed short vec_vsubuhm (vector bool short,
13070 vector signed short);
13071vector signed short vec_vsubuhm (vector signed short,
13072 vector bool short);
13073vector signed short vec_vsubuhm (vector signed short,
13074 vector signed short);
13075vector unsigned short vec_vsubuhm (vector bool short,
13076 vector unsigned short);
13077vector unsigned short vec_vsubuhm (vector unsigned short,
13078 vector bool short);
13079vector unsigned short vec_vsubuhm (vector unsigned short,
13080 vector unsigned short);
13081
13082vector signed char vec_vsububm (vector bool char, vector signed char);
13083vector signed char vec_vsububm (vector signed char, vector bool char);
13084vector signed char vec_vsububm (vector signed char, vector signed char);
13085vector unsigned char vec_vsububm (vector bool char,
13086 vector unsigned char);
13087vector unsigned char vec_vsububm (vector unsigned char,
13088 vector bool char);
13089vector unsigned char vec_vsububm (vector unsigned char,
13090 vector unsigned char);
13091
0ae4308e 13092vector unsigned int vec_subc (vector unsigned int, vector unsigned int);
13093
2b9c51df 13094vector unsigned char vec_subs (vector bool char, vector unsigned char);
13095vector unsigned char vec_subs (vector unsigned char, vector bool char);
8bdbaccf 13096vector unsigned char vec_subs (vector unsigned char,
13097 vector unsigned char);
2b9c51df 13098vector signed char vec_subs (vector bool char, vector signed char);
13099vector signed char vec_subs (vector signed char, vector bool char);
0ae4308e 13100vector signed char vec_subs (vector signed char, vector signed char);
2b9c51df 13101vector unsigned short vec_subs (vector bool short,
8bdbaccf 13102 vector unsigned short);
13103vector unsigned short vec_subs (vector unsigned short,
2b9c51df 13104 vector bool short);
8e1103d3 13105vector unsigned short vec_subs (vector unsigned short,
13106 vector unsigned short);
2b9c51df 13107vector signed short vec_subs (vector bool short, vector signed short);
13108vector signed short vec_subs (vector signed short, vector bool short);
0ae4308e 13109vector signed short vec_subs (vector signed short, vector signed short);
2b9c51df 13110vector unsigned int vec_subs (vector bool int, vector unsigned int);
13111vector unsigned int vec_subs (vector unsigned int, vector bool int);
0ae4308e 13112vector unsigned int vec_subs (vector unsigned int, vector unsigned int);
2b9c51df 13113vector signed int vec_subs (vector bool int, vector signed int);
13114vector signed int vec_subs (vector signed int, vector bool int);
0ae4308e 13115vector signed int vec_subs (vector signed int, vector signed int);
13116
2b9c51df 13117vector signed int vec_vsubsws (vector bool int, vector signed int);
13118vector signed int vec_vsubsws (vector signed int, vector bool int);
13119vector signed int vec_vsubsws (vector signed int, vector signed int);
13120
13121vector unsigned int vec_vsubuws (vector bool int, vector unsigned int);
13122vector unsigned int vec_vsubuws (vector unsigned int, vector bool int);
13123vector unsigned int vec_vsubuws (vector unsigned int,
13124 vector unsigned int);
13125
13126vector signed short vec_vsubshs (vector bool short,
13127 vector signed short);
13128vector signed short vec_vsubshs (vector signed short,
13129 vector bool short);
13130vector signed short vec_vsubshs (vector signed short,
13131 vector signed short);
13132
13133vector unsigned short vec_vsubuhs (vector bool short,
13134 vector unsigned short);
13135vector unsigned short vec_vsubuhs (vector unsigned short,
13136 vector bool short);
13137vector unsigned short vec_vsubuhs (vector unsigned short,
13138 vector unsigned short);
13139
13140vector signed char vec_vsubsbs (vector bool char, vector signed char);
13141vector signed char vec_vsubsbs (vector signed char, vector bool char);
13142vector signed char vec_vsubsbs (vector signed char, vector signed char);
13143
13144vector unsigned char vec_vsububs (vector bool char,
13145 vector unsigned char);
13146vector unsigned char vec_vsububs (vector unsigned char,
13147 vector bool char);
13148vector unsigned char vec_vsububs (vector unsigned char,
13149 vector unsigned char);
13150
8bdbaccf 13151vector unsigned int vec_sum4s (vector unsigned char,
13152 vector unsigned int);
0ae4308e 13153vector signed int vec_sum4s (vector signed char, vector signed int);
13154vector signed int vec_sum4s (vector signed short, vector signed int);
13155
2b9c51df 13156vector signed int vec_vsum4shs (vector signed short, vector signed int);
13157
13158vector signed int vec_vsum4sbs (vector signed char, vector signed int);
13159
13160vector unsigned int vec_vsum4ubs (vector unsigned char,
13161 vector unsigned int);
13162
0ae4308e 13163vector signed int vec_sum2s (vector signed int, vector signed int);
13164
13165vector signed int vec_sums (vector signed int, vector signed int);
13166
13167vector float vec_trunc (vector float);
13168
13169vector signed short vec_unpackh (vector signed char);
2b9c51df 13170vector bool short vec_unpackh (vector bool char);
0ae4308e 13171vector signed int vec_unpackh (vector signed short);
2b9c51df 13172vector bool int vec_unpackh (vector bool short);
13173vector unsigned int vec_unpackh (vector pixel);
13174
13175vector bool int vec_vupkhsh (vector bool short);
13176vector signed int vec_vupkhsh (vector signed short);
13177
13178vector unsigned int vec_vupkhpx (vector pixel);
13179
13180vector bool short vec_vupkhsb (vector bool char);
13181vector signed short vec_vupkhsb (vector signed char);
0ae4308e 13182
13183vector signed short vec_unpackl (vector signed char);
2b9c51df 13184vector bool short vec_unpackl (vector bool char);
13185vector unsigned int vec_unpackl (vector pixel);
0ae4308e 13186vector signed int vec_unpackl (vector signed short);
2b9c51df 13187vector bool int vec_unpackl (vector bool short);
13188
13189vector unsigned int vec_vupklpx (vector pixel);
13190
13191vector bool int vec_vupklsh (vector bool short);
13192vector signed int vec_vupklsh (vector signed short);
13193
13194vector bool short vec_vupklsb (vector bool char);
13195vector signed short vec_vupklsb (vector signed char);
0ae4308e 13196
13197vector float vec_xor (vector float, vector float);
2b9c51df 13198vector float vec_xor (vector float, vector bool int);
13199vector float vec_xor (vector bool int, vector float);
13200vector bool int vec_xor (vector bool int, vector bool int);
13201vector signed int vec_xor (vector bool int, vector signed int);
13202vector signed int vec_xor (vector signed int, vector bool int);
0ae4308e 13203vector signed int vec_xor (vector signed int, vector signed int);
2b9c51df 13204vector unsigned int vec_xor (vector bool int, vector unsigned int);
13205vector unsigned int vec_xor (vector unsigned int, vector bool int);
0ae4308e 13206vector unsigned int vec_xor (vector unsigned int, vector unsigned int);
2b9c51df 13207vector bool short vec_xor (vector bool short, vector bool short);
13208vector signed short vec_xor (vector bool short, vector signed short);
13209vector signed short vec_xor (vector signed short, vector bool short);
0ae4308e 13210vector signed short vec_xor (vector signed short, vector signed short);
2b9c51df 13211vector unsigned short vec_xor (vector bool short,
8bdbaccf 13212 vector unsigned short);
13213vector unsigned short vec_xor (vector unsigned short,
2b9c51df 13214 vector bool short);
8e1103d3 13215vector unsigned short vec_xor (vector unsigned short,
13216 vector unsigned short);
2b9c51df 13217vector signed char vec_xor (vector bool char, vector signed char);
13218vector bool char vec_xor (vector bool char, vector bool char);
13219vector signed char vec_xor (vector signed char, vector bool char);
0ae4308e 13220vector signed char vec_xor (vector signed char, vector signed char);
2b9c51df 13221vector unsigned char vec_xor (vector bool char, vector unsigned char);
13222vector unsigned char vec_xor (vector unsigned char, vector bool char);
8bdbaccf 13223vector unsigned char vec_xor (vector unsigned char,
13224 vector unsigned char);
0ae4308e 13225
2b9c51df 13226int vec_all_eq (vector signed char, vector bool char);
13227int vec_all_eq (vector signed char, vector signed char);
13228int vec_all_eq (vector unsigned char, vector bool char);
13229int vec_all_eq (vector unsigned char, vector unsigned char);
13230int vec_all_eq (vector bool char, vector bool char);
13231int vec_all_eq (vector bool char, vector unsigned char);
13232int vec_all_eq (vector bool char, vector signed char);
13233int vec_all_eq (vector signed short, vector bool short);
13234int vec_all_eq (vector signed short, vector signed short);
13235int vec_all_eq (vector unsigned short, vector bool short);
13236int vec_all_eq (vector unsigned short, vector unsigned short);
13237int vec_all_eq (vector bool short, vector bool short);
13238int vec_all_eq (vector bool short, vector unsigned short);
13239int vec_all_eq (vector bool short, vector signed short);
13240int vec_all_eq (vector pixel, vector pixel);
13241int vec_all_eq (vector signed int, vector bool int);
13242int vec_all_eq (vector signed int, vector signed int);
13243int vec_all_eq (vector unsigned int, vector bool int);
13244int vec_all_eq (vector unsigned int, vector unsigned int);
13245int vec_all_eq (vector bool int, vector bool int);
13246int vec_all_eq (vector bool int, vector unsigned int);
13247int vec_all_eq (vector bool int, vector signed int);
13248int vec_all_eq (vector float, vector float);
13249
13250int vec_all_ge (vector bool char, vector unsigned char);
13251int vec_all_ge (vector unsigned char, vector bool char);
13252int vec_all_ge (vector unsigned char, vector unsigned char);
13253int vec_all_ge (vector bool char, vector signed char);
13254int vec_all_ge (vector signed char, vector bool char);
13255int vec_all_ge (vector signed char, vector signed char);
13256int vec_all_ge (vector bool short, vector unsigned short);
13257int vec_all_ge (vector unsigned short, vector bool short);
13258int vec_all_ge (vector unsigned short, vector unsigned short);
13259int vec_all_ge (vector signed short, vector signed short);
13260int vec_all_ge (vector bool short, vector signed short);
13261int vec_all_ge (vector signed short, vector bool short);
13262int vec_all_ge (vector bool int, vector unsigned int);
13263int vec_all_ge (vector unsigned int, vector bool int);
13264int vec_all_ge (vector unsigned int, vector unsigned int);
13265int vec_all_ge (vector bool int, vector signed int);
13266int vec_all_ge (vector signed int, vector bool int);
13267int vec_all_ge (vector signed int, vector signed int);
13268int vec_all_ge (vector float, vector float);
13269
13270int vec_all_gt (vector bool char, vector unsigned char);
13271int vec_all_gt (vector unsigned char, vector bool char);
13272int vec_all_gt (vector unsigned char, vector unsigned char);
13273int vec_all_gt (vector bool char, vector signed char);
13274int vec_all_gt (vector signed char, vector bool char);
13275int vec_all_gt (vector signed char, vector signed char);
13276int vec_all_gt (vector bool short, vector unsigned short);
13277int vec_all_gt (vector unsigned short, vector bool short);
13278int vec_all_gt (vector unsigned short, vector unsigned short);
13279int vec_all_gt (vector bool short, vector signed short);
13280int vec_all_gt (vector signed short, vector bool short);
13281int vec_all_gt (vector signed short, vector signed short);
13282int vec_all_gt (vector bool int, vector unsigned int);
13283int vec_all_gt (vector unsigned int, vector bool int);
13284int vec_all_gt (vector unsigned int, vector unsigned int);
13285int vec_all_gt (vector bool int, vector signed int);
13286int vec_all_gt (vector signed int, vector bool int);
13287int vec_all_gt (vector signed int, vector signed int);
13288int vec_all_gt (vector float, vector float);
13289
13290int vec_all_in (vector float, vector float);
13291
13292int vec_all_le (vector bool char, vector unsigned char);
13293int vec_all_le (vector unsigned char, vector bool char);
13294int vec_all_le (vector unsigned char, vector unsigned char);
13295int vec_all_le (vector bool char, vector signed char);
13296int vec_all_le (vector signed char, vector bool char);
13297int vec_all_le (vector signed char, vector signed char);
13298int vec_all_le (vector bool short, vector unsigned short);
13299int vec_all_le (vector unsigned short, vector bool short);
13300int vec_all_le (vector unsigned short, vector unsigned short);
13301int vec_all_le (vector bool short, vector signed short);
13302int vec_all_le (vector signed short, vector bool short);
13303int vec_all_le (vector signed short, vector signed short);
13304int vec_all_le (vector bool int, vector unsigned int);
13305int vec_all_le (vector unsigned int, vector bool int);
13306int vec_all_le (vector unsigned int, vector unsigned int);
13307int vec_all_le (vector bool int, vector signed int);
13308int vec_all_le (vector signed int, vector bool int);
13309int vec_all_le (vector signed int, vector signed int);
13310int vec_all_le (vector float, vector float);
13311
13312int vec_all_lt (vector bool char, vector unsigned char);
13313int vec_all_lt (vector unsigned char, vector bool char);
13314int vec_all_lt (vector unsigned char, vector unsigned char);
13315int vec_all_lt (vector bool char, vector signed char);
13316int vec_all_lt (vector signed char, vector bool char);
13317int vec_all_lt (vector signed char, vector signed char);
13318int vec_all_lt (vector bool short, vector unsigned short);
13319int vec_all_lt (vector unsigned short, vector bool short);
13320int vec_all_lt (vector unsigned short, vector unsigned short);
13321int vec_all_lt (vector bool short, vector signed short);
13322int vec_all_lt (vector signed short, vector bool short);
13323int vec_all_lt (vector signed short, vector signed short);
13324int vec_all_lt (vector bool int, vector unsigned int);
13325int vec_all_lt (vector unsigned int, vector bool int);
13326int vec_all_lt (vector unsigned int, vector unsigned int);
13327int vec_all_lt (vector bool int, vector signed int);
13328int vec_all_lt (vector signed int, vector bool int);
13329int vec_all_lt (vector signed int, vector signed int);
13330int vec_all_lt (vector float, vector float);
13331
13332int vec_all_nan (vector float);
13333
13334int vec_all_ne (vector signed char, vector bool char);
13335int vec_all_ne (vector signed char, vector signed char);
13336int vec_all_ne (vector unsigned char, vector bool char);
13337int vec_all_ne (vector unsigned char, vector unsigned char);
13338int vec_all_ne (vector bool char, vector bool char);
13339int vec_all_ne (vector bool char, vector unsigned char);
13340int vec_all_ne (vector bool char, vector signed char);
13341int vec_all_ne (vector signed short, vector bool short);
13342int vec_all_ne (vector signed short, vector signed short);
13343int vec_all_ne (vector unsigned short, vector bool short);
13344int vec_all_ne (vector unsigned short, vector unsigned short);
13345int vec_all_ne (vector bool short, vector bool short);
13346int vec_all_ne (vector bool short, vector unsigned short);
13347int vec_all_ne (vector bool short, vector signed short);
13348int vec_all_ne (vector pixel, vector pixel);
13349int vec_all_ne (vector signed int, vector bool int);
13350int vec_all_ne (vector signed int, vector signed int);
13351int vec_all_ne (vector unsigned int, vector bool int);
13352int vec_all_ne (vector unsigned int, vector unsigned int);
13353int vec_all_ne (vector bool int, vector bool int);
13354int vec_all_ne (vector bool int, vector unsigned int);
13355int vec_all_ne (vector bool int, vector signed int);
13356int vec_all_ne (vector float, vector float);
13357
13358int vec_all_nge (vector float, vector float);
13359
13360int vec_all_ngt (vector float, vector float);
13361
13362int vec_all_nle (vector float, vector float);
13363
13364int vec_all_nlt (vector float, vector float);
13365
13366int vec_all_numeric (vector float);
13367
13368int vec_any_eq (vector signed char, vector bool char);
13369int vec_any_eq (vector signed char, vector signed char);
13370int vec_any_eq (vector unsigned char, vector bool char);
13371int vec_any_eq (vector unsigned char, vector unsigned char);
13372int vec_any_eq (vector bool char, vector bool char);
13373int vec_any_eq (vector bool char, vector unsigned char);
13374int vec_any_eq (vector bool char, vector signed char);
13375int vec_any_eq (vector signed short, vector bool short);
13376int vec_any_eq (vector signed short, vector signed short);
13377int vec_any_eq (vector unsigned short, vector bool short);
13378int vec_any_eq (vector unsigned short, vector unsigned short);
13379int vec_any_eq (vector bool short, vector bool short);
13380int vec_any_eq (vector bool short, vector unsigned short);
13381int vec_any_eq (vector bool short, vector signed short);
13382int vec_any_eq (vector pixel, vector pixel);
13383int vec_any_eq (vector signed int, vector bool int);
13384int vec_any_eq (vector signed int, vector signed int);
13385int vec_any_eq (vector unsigned int, vector bool int);
13386int vec_any_eq (vector unsigned int, vector unsigned int);
13387int vec_any_eq (vector bool int, vector bool int);
13388int vec_any_eq (vector bool int, vector unsigned int);
13389int vec_any_eq (vector bool int, vector signed int);
13390int vec_any_eq (vector float, vector float);
13391
13392int vec_any_ge (vector signed char, vector bool char);
13393int vec_any_ge (vector unsigned char, vector bool char);
13394int vec_any_ge (vector unsigned char, vector unsigned char);
13395int vec_any_ge (vector signed char, vector signed char);
13396int vec_any_ge (vector bool char, vector unsigned char);
13397int vec_any_ge (vector bool char, vector signed char);
13398int vec_any_ge (vector unsigned short, vector bool short);
13399int vec_any_ge (vector unsigned short, vector unsigned short);
13400int vec_any_ge (vector signed short, vector signed short);
13401int vec_any_ge (vector signed short, vector bool short);
13402int vec_any_ge (vector bool short, vector unsigned short);
13403int vec_any_ge (vector bool short, vector signed short);
13404int vec_any_ge (vector signed int, vector bool int);
13405int vec_any_ge (vector unsigned int, vector bool int);
13406int vec_any_ge (vector unsigned int, vector unsigned int);
13407int vec_any_ge (vector signed int, vector signed int);
13408int vec_any_ge (vector bool int, vector unsigned int);
13409int vec_any_ge (vector bool int, vector signed int);
13410int vec_any_ge (vector float, vector float);
13411
13412int vec_any_gt (vector bool char, vector unsigned char);
13413int vec_any_gt (vector unsigned char, vector bool char);
13414int vec_any_gt (vector unsigned char, vector unsigned char);
13415int vec_any_gt (vector bool char, vector signed char);
13416int vec_any_gt (vector signed char, vector bool char);
13417int vec_any_gt (vector signed char, vector signed char);
13418int vec_any_gt (vector bool short, vector unsigned short);
13419int vec_any_gt (vector unsigned short, vector bool short);
13420int vec_any_gt (vector unsigned short, vector unsigned short);
13421int vec_any_gt (vector bool short, vector signed short);
13422int vec_any_gt (vector signed short, vector bool short);
13423int vec_any_gt (vector signed short, vector signed short);
13424int vec_any_gt (vector bool int, vector unsigned int);
13425int vec_any_gt (vector unsigned int, vector bool int);
13426int vec_any_gt (vector unsigned int, vector unsigned int);
13427int vec_any_gt (vector bool int, vector signed int);
13428int vec_any_gt (vector signed int, vector bool int);
13429int vec_any_gt (vector signed int, vector signed int);
13430int vec_any_gt (vector float, vector float);
13431
13432int vec_any_le (vector bool char, vector unsigned char);
13433int vec_any_le (vector unsigned char, vector bool char);
13434int vec_any_le (vector unsigned char, vector unsigned char);
13435int vec_any_le (vector bool char, vector signed char);
13436int vec_any_le (vector signed char, vector bool char);
13437int vec_any_le (vector signed char, vector signed char);
13438int vec_any_le (vector bool short, vector unsigned short);
13439int vec_any_le (vector unsigned short, vector bool short);
13440int vec_any_le (vector unsigned short, vector unsigned short);
13441int vec_any_le (vector bool short, vector signed short);
13442int vec_any_le (vector signed short, vector bool short);
13443int vec_any_le (vector signed short, vector signed short);
13444int vec_any_le (vector bool int, vector unsigned int);
13445int vec_any_le (vector unsigned int, vector bool int);
13446int vec_any_le (vector unsigned int, vector unsigned int);
13447int vec_any_le (vector bool int, vector signed int);
13448int vec_any_le (vector signed int, vector bool int);
13449int vec_any_le (vector signed int, vector signed int);
13450int vec_any_le (vector float, vector float);
13451
13452int vec_any_lt (vector bool char, vector unsigned char);
13453int vec_any_lt (vector unsigned char, vector bool char);
13454int vec_any_lt (vector unsigned char, vector unsigned char);
13455int vec_any_lt (vector bool char, vector signed char);
13456int vec_any_lt (vector signed char, vector bool char);
13457int vec_any_lt (vector signed char, vector signed char);
13458int vec_any_lt (vector bool short, vector unsigned short);
13459int vec_any_lt (vector unsigned short, vector bool short);
13460int vec_any_lt (vector unsigned short, vector unsigned short);
13461int vec_any_lt (vector bool short, vector signed short);
13462int vec_any_lt (vector signed short, vector bool short);
13463int vec_any_lt (vector signed short, vector signed short);
13464int vec_any_lt (vector bool int, vector unsigned int);
13465int vec_any_lt (vector unsigned int, vector bool int);
13466int vec_any_lt (vector unsigned int, vector unsigned int);
13467int vec_any_lt (vector bool int, vector signed int);
13468int vec_any_lt (vector signed int, vector bool int);
13469int vec_any_lt (vector signed int, vector signed int);
13470int vec_any_lt (vector float, vector float);
13471
13472int vec_any_nan (vector float);
13473
13474int vec_any_ne (vector signed char, vector bool char);
13475int vec_any_ne (vector signed char, vector signed char);
13476int vec_any_ne (vector unsigned char, vector bool char);
13477int vec_any_ne (vector unsigned char, vector unsigned char);
13478int vec_any_ne (vector bool char, vector bool char);
13479int vec_any_ne (vector bool char, vector unsigned char);
13480int vec_any_ne (vector bool char, vector signed char);
13481int vec_any_ne (vector signed short, vector bool short);
13482int vec_any_ne (vector signed short, vector signed short);
13483int vec_any_ne (vector unsigned short, vector bool short);
13484int vec_any_ne (vector unsigned short, vector unsigned short);
13485int vec_any_ne (vector bool short, vector bool short);
13486int vec_any_ne (vector bool short, vector unsigned short);
13487int vec_any_ne (vector bool short, vector signed short);
13488int vec_any_ne (vector pixel, vector pixel);
13489int vec_any_ne (vector signed int, vector bool int);
13490int vec_any_ne (vector signed int, vector signed int);
13491int vec_any_ne (vector unsigned int, vector bool int);
13492int vec_any_ne (vector unsigned int, vector unsigned int);
13493int vec_any_ne (vector bool int, vector bool int);
13494int vec_any_ne (vector bool int, vector unsigned int);
13495int vec_any_ne (vector bool int, vector signed int);
13496int vec_any_ne (vector float, vector float);
13497
13498int vec_any_nge (vector float, vector float);
13499
13500int vec_any_ngt (vector float, vector float);
13501
13502int vec_any_nle (vector float, vector float);
13503
13504int vec_any_nlt (vector float, vector float);
13505
13506int vec_any_numeric (vector float);
13507
13508int vec_any_out (vector float, vector float);
0ae4308e 13509@end smallexample
13510
32374e3c 13511If the vector/scalar (VSX) instruction set is available, the following
13512additional functions are available:
13513
13514@smallexample
13515vector double vec_abs (vector double);
13516vector double vec_add (vector double, vector double);
13517vector double vec_and (vector double, vector double);
13518vector double vec_and (vector double, vector bool long);
13519vector double vec_and (vector bool long, vector double);
13520vector double vec_andc (vector double, vector double);
13521vector double vec_andc (vector double, vector bool long);
13522vector double vec_andc (vector bool long, vector double);
13523vector double vec_ceil (vector double);
13524vector bool long vec_cmpeq (vector double, vector double);
13525vector bool long vec_cmpge (vector double, vector double);
13526vector bool long vec_cmpgt (vector double, vector double);
13527vector bool long vec_cmple (vector double, vector double);
13528vector bool long vec_cmplt (vector double, vector double);
13529vector float vec_div (vector float, vector float);
13530vector double vec_div (vector double, vector double);
13531vector double vec_floor (vector double);
a501acda 13532vector double vec_ld (int, const vector double *);
13533vector double vec_ld (int, const double *);
13534vector double vec_ldl (int, const vector double *);
13535vector double vec_ldl (int, const double *);
13536vector unsigned char vec_lvsl (int, const volatile double *);
13537vector unsigned char vec_lvsr (int, const volatile double *);
32374e3c 13538vector double vec_madd (vector double, vector double, vector double);
13539vector double vec_max (vector double, vector double);
13540vector double vec_min (vector double, vector double);
13541vector float vec_msub (vector float, vector float, vector float);
13542vector double vec_msub (vector double, vector double, vector double);
13543vector float vec_mul (vector float, vector float);
13544vector double vec_mul (vector double, vector double);
13545vector float vec_nearbyint (vector float);
13546vector double vec_nearbyint (vector double);
13547vector float vec_nmadd (vector float, vector float, vector float);
13548vector double vec_nmadd (vector double, vector double, vector double);
13549vector double vec_nmsub (vector double, vector double, vector double);
13550vector double vec_nor (vector double, vector double);
13551vector double vec_or (vector double, vector double);
13552vector double vec_or (vector double, vector bool long);
13553vector double vec_or (vector bool long, vector double);
13554vector double vec_perm (vector double,
13555 vector double,
13556 vector unsigned char);
32374e3c 13557vector double vec_rint (vector double);
0eac26de 13558vector double vec_recip (vector double, vector double);
13559vector double vec_rsqrt (vector double);
13560vector double vec_rsqrte (vector double);
32374e3c 13561vector double vec_sel (vector double, vector double, vector bool long);
13562vector double vec_sel (vector double, vector double, vector unsigned long);
13563vector double vec_sub (vector double, vector double);
13564vector float vec_sqrt (vector float);
13565vector double vec_sqrt (vector double);
a501acda 13566void vec_st (vector double, int, vector double *);
13567void vec_st (vector double, int, double *);
32374e3c 13568vector double vec_trunc (vector double);
13569vector double vec_xor (vector double, vector double);
13570vector double vec_xor (vector double, vector bool long);
13571vector double vec_xor (vector bool long, vector double);
13572int vec_all_eq (vector double, vector double);
13573int vec_all_ge (vector double, vector double);
13574int vec_all_gt (vector double, vector double);
13575int vec_all_le (vector double, vector double);
13576int vec_all_lt (vector double, vector double);
13577int vec_all_nan (vector double);
13578int vec_all_ne (vector double, vector double);
13579int vec_all_nge (vector double, vector double);
13580int vec_all_ngt (vector double, vector double);
13581int vec_all_nle (vector double, vector double);
13582int vec_all_nlt (vector double, vector double);
13583int vec_all_numeric (vector double);
13584int vec_any_eq (vector double, vector double);
13585int vec_any_ge (vector double, vector double);
13586int vec_any_gt (vector double, vector double);
13587int vec_any_le (vector double, vector double);
13588int vec_any_lt (vector double, vector double);
13589int vec_any_nan (vector double);
13590int vec_any_ne (vector double, vector double);
13591int vec_any_nge (vector double, vector double);
13592int vec_any_ngt (vector double, vector double);
13593int vec_any_nle (vector double, vector double);
13594int vec_any_nlt (vector double, vector double);
13595int vec_any_numeric (vector double);
a501acda 13596
13597vector double vec_vsx_ld (int, const vector double *);
13598vector double vec_vsx_ld (int, const double *);
13599vector float vec_vsx_ld (int, const vector float *);
13600vector float vec_vsx_ld (int, const float *);
13601vector bool int vec_vsx_ld (int, const vector bool int *);
13602vector signed int vec_vsx_ld (int, const vector signed int *);
13603vector signed int vec_vsx_ld (int, const int *);
13604vector signed int vec_vsx_ld (int, const long *);
13605vector unsigned int vec_vsx_ld (int, const vector unsigned int *);
13606vector unsigned int vec_vsx_ld (int, const unsigned int *);
13607vector unsigned int vec_vsx_ld (int, const unsigned long *);
13608vector bool short vec_vsx_ld (int, const vector bool short *);
13609vector pixel vec_vsx_ld (int, const vector pixel *);
13610vector signed short vec_vsx_ld (int, const vector signed short *);
13611vector signed short vec_vsx_ld (int, const short *);
13612vector unsigned short vec_vsx_ld (int, const vector unsigned short *);
13613vector unsigned short vec_vsx_ld (int, const unsigned short *);
13614vector bool char vec_vsx_ld (int, const vector bool char *);
13615vector signed char vec_vsx_ld (int, const vector signed char *);
13616vector signed char vec_vsx_ld (int, const signed char *);
13617vector unsigned char vec_vsx_ld (int, const vector unsigned char *);
13618vector unsigned char vec_vsx_ld (int, const unsigned char *);
13619
13620void vec_vsx_st (vector double, int, vector double *);
13621void vec_vsx_st (vector double, int, double *);
13622void vec_vsx_st (vector float, int, vector float *);
13623void vec_vsx_st (vector float, int, float *);
13624void vec_vsx_st (vector signed int, int, vector signed int *);
13625void vec_vsx_st (vector signed int, int, int *);
13626void vec_vsx_st (vector unsigned int, int, vector unsigned int *);
13627void vec_vsx_st (vector unsigned int, int, unsigned int *);
13628void vec_vsx_st (vector bool int, int, vector bool int *);
13629void vec_vsx_st (vector bool int, int, unsigned int *);
13630void vec_vsx_st (vector bool int, int, int *);
13631void vec_vsx_st (vector signed short, int, vector signed short *);
13632void vec_vsx_st (vector signed short, int, short *);
13633void vec_vsx_st (vector unsigned short, int, vector unsigned short *);
13634void vec_vsx_st (vector unsigned short, int, unsigned short *);
13635void vec_vsx_st (vector bool short, int, vector bool short *);
13636void vec_vsx_st (vector bool short, int, unsigned short *);
13637void vec_vsx_st (vector pixel, int, vector pixel *);
13638void vec_vsx_st (vector pixel, int, unsigned short *);
13639void vec_vsx_st (vector pixel, int, short *);
13640void vec_vsx_st (vector bool short, int, short *);
13641void vec_vsx_st (vector signed char, int, vector signed char *);
13642void vec_vsx_st (vector signed char, int, signed char *);
13643void vec_vsx_st (vector unsigned char, int, vector unsigned char *);
13644void vec_vsx_st (vector unsigned char, int, unsigned char *);
13645void vec_vsx_st (vector bool char, int, vector bool char *);
13646void vec_vsx_st (vector bool char, int, unsigned char *);
13647void vec_vsx_st (vector bool char, int, signed char *);
13648@end smallexample
13649
13650Note that the @samp{vec_ld} and @samp{vec_st} builtins will always
13651generate the Altivec @samp{LVX} and @samp{STVX} instructions even
13652if the VSX instruction set is available. The @samp{vec_vsx_ld} and
13653@samp{vec_vsx_st} builtins will always generate the VSX @samp{LXVD2X},
13654@samp{LXVW4X}, @samp{STXVD2X}, and @samp{STXVW4X} instructions.
32374e3c 13655
13656GCC provides a few other builtins on Powerpc to access certain instructions:
13657@smallexample
13658float __builtin_recipdivf (float, float);
13659float __builtin_rsqrtf (float);
13660double __builtin_recipdiv (double, double);
0eac26de 13661double __builtin_rsqrt (double);
32374e3c 13662long __builtin_bpermd (long, long);
32374e3c 13663@end smallexample
13664
0eac26de 13665The @code{vec_rsqrt}, @code{__builtin_rsqrt}, and
13666@code{__builtin_rsqrtf} functions generate multiple instructions to
13667implement the reciprocal sqrt functionality using reciprocal sqrt
13668estimate instructions.
13669
13670The @code{__builtin_recipdiv}, and @code{__builtin_recipdivf}
13671functions generate multiple instructions to implement division using
13672the reciprocal estimate instructions.
13673
24833e1a 13674@node RX Built-in Functions
13675@subsection RX Built-in Functions
13676GCC supports some of the RX instructions which cannot be expressed in
13677the C programming language via the use of built-in functions. The
13678following functions are supported:
13679
13680@deftypefn {Built-in Function} void __builtin_rx_brk (void)
13681Generates the @code{brk} machine instruction.
13682@end deftypefn
13683
13684@deftypefn {Built-in Function} void __builtin_rx_clrpsw (int)
13685Generates the @code{clrpsw} machine instruction to clear the specified
13686bit in the processor status word.
13687@end deftypefn
13688
13689@deftypefn {Built-in Function} void __builtin_rx_int (int)
13690Generates the @code{int} machine instruction to generate an interrupt
13691with the specified value.
13692@end deftypefn
13693
13694@deftypefn {Built-in Function} void __builtin_rx_machi (int, int)
13695Generates the @code{machi} machine instruction to add the result of
13696multiplying the top 16-bits of the two arguments into the
13697accumulator.
13698@end deftypefn
13699
13700@deftypefn {Built-in Function} void __builtin_rx_maclo (int, int)
13701Generates the @code{maclo} machine instruction to add the result of
13702multiplying the bottom 16-bits of the two arguments into the
13703accumulator.
13704@end deftypefn
13705
13706@deftypefn {Built-in Function} void __builtin_rx_mulhi (int, int)
13707Generates the @code{mulhi} machine instruction to place the result of
13708multiplying the top 16-bits of the two arguments into the
13709accumulator.
13710@end deftypefn
13711
13712@deftypefn {Built-in Function} void __builtin_rx_mullo (int, int)
13713Generates the @code{mullo} machine instruction to place the result of
13714multiplying the bottom 16-bits of the two arguments into the
13715accumulator.
13716@end deftypefn
13717
13718@deftypefn {Built-in Function} int __builtin_rx_mvfachi (void)
13719Generates the @code{mvfachi} machine instruction to read the top
1372032-bits of the accumulator.
13721@end deftypefn
13722
13723@deftypefn {Built-in Function} int __builtin_rx_mvfacmi (void)
13724Generates the @code{mvfacmi} machine instruction to read the middle
1372532-bits of the accumulator.
13726@end deftypefn
13727
13728@deftypefn {Built-in Function} int __builtin_rx_mvfc (int)
13729Generates the @code{mvfc} machine instruction which reads the control
13730register specified in its argument and returns its value.
13731@end deftypefn
13732
13733@deftypefn {Built-in Function} void __builtin_rx_mvtachi (int)
13734Generates the @code{mvtachi} machine instruction to set the top
1373532-bits of the accumulator.
13736@end deftypefn
13737
13738@deftypefn {Built-in Function} void __builtin_rx_mvtaclo (int)
13739Generates the @code{mvtaclo} machine instruction to set the bottom
1374032-bits of the accumulator.
13741@end deftypefn
13742
13743@deftypefn {Built-in Function} void __builtin_rx_mvtc (int reg, int val)
13744Generates the @code{mvtc} machine instruction which sets control
13745register number @code{reg} to @code{val}.
13746@end deftypefn
13747
13748@deftypefn {Built-in Function} void __builtin_rx_mvtipl (int)
13749Generates the @code{mvtipl} machine instruction set the interrupt
13750priority level.
13751@end deftypefn
13752
13753@deftypefn {Built-in Function} void __builtin_rx_racw (int)
13754Generates the @code{racw} machine instruction to round the accumulator
13755according to the specified mode.
13756@end deftypefn
13757
13758@deftypefn {Built-in Function} int __builtin_rx_revw (int)
13759Generates the @code{revw} machine instruction which swaps the bytes in
13760the argument so that bits 0--7 now occupy bits 8--15 and vice versa,
13761and also bits 16--23 occupy bits 24--31 and vice versa.
13762@end deftypefn
13763
13764@deftypefn {Built-in Function} void __builtin_rx_rmpa (void)
13765Generates the @code{rmpa} machine instruction which initiates a
13766repeated multiply and accumulate sequence.
13767@end deftypefn
13768
13769@deftypefn {Built-in Function} void __builtin_rx_round (float)
13770Generates the @code{round} machine instruction which returns the
13771floating point argument rounded according to the current rounding mode
13772set in the floating point status word register.
13773@end deftypefn
13774
13775@deftypefn {Built-in Function} int __builtin_rx_sat (int)
13776Generates the @code{sat} machine instruction which returns the
13777saturated value of the argument.
13778@end deftypefn
13779
13780@deftypefn {Built-in Function} void __builtin_rx_setpsw (int)
13781Generates the @code{setpsw} machine instruction to set the specified
13782bit in the processor status word.
13783@end deftypefn
13784
13785@deftypefn {Built-in Function} void __builtin_rx_wait (void)
13786Generates the @code{wait} machine instruction.
13787@end deftypefn
13788
88fb6217 13789@node SPARC VIS Built-in Functions
13790@subsection SPARC VIS Built-in Functions
13791
13792GCC supports SIMD operations on the SPARC using both the generic vector
1b5d7d3d 13793extensions (@pxref{Vector Extensions}) as well as built-in functions for
88fb6217 13794the SPARC Visual Instruction Set (VIS). When you use the @option{-mvis}
13795switch, the VIS extension is exposed as the following built-in functions:
13796
13797@smallexample
e39e0668 13798typedef int v1si __attribute__ ((vector_size (4)));
88fb6217 13799typedef int v2si __attribute__ ((vector_size (8)));
13800typedef short v4hi __attribute__ ((vector_size (8)));
13801typedef short v2hi __attribute__ ((vector_size (4)));
4e3a6159 13802typedef unsigned char v8qi __attribute__ ((vector_size (8)));
13803typedef unsigned char v4qi __attribute__ ((vector_size (4)));
88fb6217 13804
b011bbe2 13805void __builtin_vis_write_gsr (int64_t);
13806int64_t __builtin_vis_read_gsr (void);
13807
88fb6217 13808void * __builtin_vis_alignaddr (void *, long);
4e3a6159 13809void * __builtin_vis_alignaddrl (void *, long);
88fb6217 13810int64_t __builtin_vis_faligndatadi (int64_t, int64_t);
13811v2si __builtin_vis_faligndatav2si (v2si, v2si);
13812v4hi __builtin_vis_faligndatav4hi (v4si, v4si);
13813v8qi __builtin_vis_faligndatav8qi (v8qi, v8qi);
13814
13815v4hi __builtin_vis_fexpand (v4qi);
13816
13817v4hi __builtin_vis_fmul8x16 (v4qi, v4hi);
4e3a6159 13818v4hi __builtin_vis_fmul8x16au (v4qi, v2hi);
13819v4hi __builtin_vis_fmul8x16al (v4qi, v2hi);
88fb6217 13820v4hi __builtin_vis_fmul8sux16 (v8qi, v4hi);
13821v4hi __builtin_vis_fmul8ulx16 (v8qi, v4hi);
13822v2si __builtin_vis_fmuld8sux16 (v4qi, v2hi);
13823v2si __builtin_vis_fmuld8ulx16 (v4qi, v2hi);
13824
13825v4qi __builtin_vis_fpack16 (v4hi);
4e3a6159 13826v8qi __builtin_vis_fpack32 (v2si, v8qi);
88fb6217 13827v2hi __builtin_vis_fpackfix (v2si);
13828v8qi __builtin_vis_fpmerge (v4qi, v4qi);
13829
13830int64_t __builtin_vis_pdist (v8qi, v8qi, int64_t);
010db245 13831
faa087bb 13832long __builtin_vis_edge8 (void *, void *);
13833long __builtin_vis_edge8l (void *, void *);
13834long __builtin_vis_edge16 (void *, void *);
13835long __builtin_vis_edge16l (void *, void *);
13836long __builtin_vis_edge32 (void *, void *);
13837long __builtin_vis_edge32l (void *, void *);
13838
13839long __builtin_vis_fcmple16 (v4hi, v4hi);
13840long __builtin_vis_fcmple32 (v2si, v2si);
13841long __builtin_vis_fcmpne16 (v4hi, v4hi);
13842long __builtin_vis_fcmpne32 (v2si, v2si);
13843long __builtin_vis_fcmpgt16 (v4hi, v4hi);
13844long __builtin_vis_fcmpgt32 (v2si, v2si);
13845long __builtin_vis_fcmpeq16 (v4hi, v4hi);
13846long __builtin_vis_fcmpeq32 (v2si, v2si);
e39e0668 13847
13848v4hi __builtin_vis_fpadd16 (v4hi, v4hi);
13849v2hi __builtin_vis_fpadd16s (v2hi, v2hi);
13850v2si __builtin_vis_fpadd32 (v2si, v2si);
13851v1si __builtin_vis_fpadd32s (v1si, v1si);
13852v4hi __builtin_vis_fpsub16 (v4hi, v4hi);
13853v2hi __builtin_vis_fpsub16s (v2hi, v2hi);
13854v2si __builtin_vis_fpsub32 (v2si, v2si);
13855v1si __builtin_vis_fpsub32s (v1si, v1si);
386d043d 13856
13857long __builtin_vis_array8 (long, long);
13858long __builtin_vis_array16 (long, long);
13859long __builtin_vis_array32 (long, long);
88fb6217 13860@end smallexample
13861
33e7b55c 13862When you use the @option{-mvis2} switch, the VIS version 2.0 built-in
13863functions also become available:
95c09f2c 13864
13865@smallexample
13866long __builtin_vis_bmask (long, long);
13867int64_t __builtin_vis_bshuffledi (int64_t, int64_t);
13868v2si __builtin_vis_bshufflev2si (v2si, v2si);
13869v4hi __builtin_vis_bshufflev2si (v4hi, v4hi);
13870v8qi __builtin_vis_bshufflev2si (v8qi, v8qi);
13871
13872long __builtin_vis_edge8n (void *, void *);
13873long __builtin_vis_edge8ln (void *, void *);
13874long __builtin_vis_edge16n (void *, void *);
13875long __builtin_vis_edge16ln (void *, void *);
13876long __builtin_vis_edge32n (void *, void *);
13877long __builtin_vis_edge32ln (void *, void *);
13878@end smallexample
13879
33e7b55c 13880When you use the @option{-mvis3} switch, the VIS version 3.0 built-in
13881functions also become available:
13882
13883@smallexample
13884void __builtin_vis_cmask8 (long);
13885void __builtin_vis_cmask16 (long);
13886void __builtin_vis_cmask32 (long);
13887
13888v4hi __builtin_vis_fchksm16 (v4hi, v4hi);
13889
13890v4hi __builtin_vis_fsll16 (v4hi, v4hi);
13891v4hi __builtin_vis_fslas16 (v4hi, v4hi);
13892v4hi __builtin_vis_fsrl16 (v4hi, v4hi);
13893v4hi __builtin_vis_fsra16 (v4hi, v4hi);
13894v2si __builtin_vis_fsll16 (v2si, v2si);
13895v2si __builtin_vis_fslas16 (v2si, v2si);
13896v2si __builtin_vis_fsrl16 (v2si, v2si);
13897v2si __builtin_vis_fsra16 (v2si, v2si);
13898
13899long __builtin_vis_pdistn (v8qi, v8qi);
13900
13901v4hi __builtin_vis_fmean16 (v4hi, v4hi);
13902
13903int64_t __builtin_vis_fpadd64 (int64_t, int64_t);
13904int64_t __builtin_vis_fpsub64 (int64_t, int64_t);
13905
13906v4hi __builtin_vis_fpadds16 (v4hi, v4hi);
13907v2hi __builtin_vis_fpadds16s (v2hi, v2hi);
13908v4hi __builtin_vis_fpsubs16 (v4hi, v4hi);
13909v2hi __builtin_vis_fpsubs16s (v2hi, v2hi);
13910v2si __builtin_vis_fpadds32 (v2si, v2si);
13911v1si __builtin_vis_fpadds32s (v1si, v1si);
13912v2si __builtin_vis_fpsubs32 (v2si, v2si);
13913v1si __builtin_vis_fpsubs32s (v1si, v1si);
13914
13915long __builtin_vis_fucmple8 (v8qi, v8qi);
13916long __builtin_vis_fucmpne8 (v8qi, v8qi);
13917long __builtin_vis_fucmpgt8 (v8qi, v8qi);
13918long __builtin_vis_fucmpeq8 (v8qi, v8qi);
47cc4525 13919
13920float __builtin_vis_fhadds (float, float);
13921double __builtin_vis_fhaddd (double, double);
13922float __builtin_vis_fhsubs (float, float);
13923double __builtin_vis_fhsubd (double, double);
13924float __builtin_vis_fnhadds (float, float);
13925double __builtin_vis_fnhaddd (double, double);
13926
13927int64_t __builtin_vis_umulxhi (int64_t, int64_t);
13928int64_t __builtin_vis_xmulx (int64_t, int64_t);
13929int64_t __builtin_vis_xmulxhi (int64_t, int64_t);
33e7b55c 13930@end smallexample
13931
644459d0 13932@node SPU Built-in Functions
13933@subsection SPU Built-in Functions
13934
13935GCC provides extensions for the SPU processor as described in the
13936Sony/Toshiba/IBM SPU Language Extensions Specification, which can be
13937found at @uref{http://cell.scei.co.jp/} or
13938@uref{http://www.ibm.com/developerworks/power/cell/}. GCC's
13939implementation differs in several ways.
13940
13941@itemize @bullet
13942
13943@item
13944The optional extension of specifying vector constants in parentheses is
13945not supported.
13946
13947@item
13948A vector initializer requires no cast if the vector constant is of the
13949same type as the variable it is initializing.
13950
13951@item
13952If @code{signed} or @code{unsigned} is omitted, the signedness of the
13953vector type is the default signedness of the base type. The default
13954varies depending on the operating system, so a portable program should
13955always specify the signedness.
13956
13957@item
13958By default, the keyword @code{__vector} is added. The macro
13959@code{vector} is defined in @code{<spu_intrinsics.h>} and can be
13960undefined.
13961
13962@item
13963GCC allows using a @code{typedef} name as the type specifier for a
13964vector type.
13965
13966@item
13967For C, overloaded functions are implemented with macros so the following
13968does not work:
13969
13970@smallexample
13971 spu_add ((vector signed int)@{1, 2, 3, 4@}, foo);
13972@end smallexample
13973
13974Since @code{spu_add} is a macro, the vector constant in the example
13975is treated as four separate arguments. Wrap the entire argument in
13976parentheses for this to work.
13977
13978@item
13979The extended version of @code{__builtin_expect} is not supported.
13980
13981@end itemize
13982
b5fb9cbe 13983@emph{Note:} Only the interface described in the aforementioned
644459d0 13984specification is supported. Internally, GCC uses built-in functions to
13985implement the required functionality, but these are not supported and
13986are subject to change without notice.
13987
5aa04b01 13988@node TI C6X Built-in Functions
13989@subsection TI C6X Built-in Functions
13990
13991GCC provides intrinsics to access certain instructions of the TI C6X
13992processors. These intrinsics, listed below, are available after
13993inclusion of the @code{c6x_intrinsics.h} header file. They map directly
13994to C6X instructions.
13995
13996@smallexample
13997
13998int _sadd (int, int)
13999int _ssub (int, int)
14000int _sadd2 (int, int)
14001int _ssub2 (int, int)
14002long long _mpy2 (int, int)
14003long long _smpy2 (int, int)
14004int _add4 (int, int)
14005int _sub4 (int, int)
14006int _saddu4 (int, int)
14007
14008int _smpy (int, int)
14009int _smpyh (int, int)
14010int _smpyhl (int, int)
14011int _smpylh (int, int)
14012
14013int _sshl (int, int)
14014int _subc (int, int)
14015
14016int _avg2 (int, int)
14017int _avgu4 (int, int)
14018
14019int _clrr (int, int)
14020int _extr (int, int)
14021int _extru (int, int)
14022int _abs (int)
14023int _abs2 (int)
14024
14025@end smallexample
14026
7ce78e23 14027@node TILE-Gx Built-in Functions
14028@subsection TILE-Gx Built-in Functions
14029
14030GCC provides intrinsics to access every instruction of the TILE-Gx
14031processor. The intrinsics are of the form:
14032
14033@smallexample
14034
14035unsigned long long __insn_@var{op} (...)
14036
14037@end smallexample
14038
14039Where @var{op} is the name of the instruction. Refer to the ISA manual
14040for the complete list of instructions.
14041
14042GCC also provides intrinsics to directly access the network registers.
14043The intrinsics are:
14044
14045@smallexample
14046
14047unsigned long long __tile_idn0_receive (void)
14048unsigned long long __tile_idn1_receive (void)
14049unsigned long long __tile_udn0_receive (void)
14050unsigned long long __tile_udn1_receive (void)
14051unsigned long long __tile_udn2_receive (void)
14052unsigned long long __tile_udn3_receive (void)
14053void __tile_idn_send (unsigned long long)
14054void __tile_udn_send (unsigned long long)
14055
14056@end smallexample
14057
14058The intrinsic @code{void __tile_network_barrier (void)} is used to
14059guarantee that no network operatons before it will be reordered with
14060those after it.
14061
14062@node TILEPro Built-in Functions
14063@subsection TILEPro Built-in Functions
14064
14065GCC provides intrinsics to access every instruction of the TILEPro
14066processor. The intrinsics are of the form:
14067
14068@smallexample
14069
14070unsigned __insn_@var{op} (...)
14071
14072@end smallexample
14073
14074Where @var{op} is the name of the instruction. Refer to the ISA manual
14075for the complete list of instructions.
14076
14077GCC also provides intrinsics to directly access the network registers.
14078The intrinsics are:
14079
14080@smallexample
14081
14082unsigned __tile_idn0_receive (void)
14083unsigned __tile_idn1_receive (void)
14084unsigned __tile_sn_receive (void)
14085unsigned __tile_udn0_receive (void)
14086unsigned __tile_udn1_receive (void)
14087unsigned __tile_udn2_receive (void)
14088unsigned __tile_udn3_receive (void)
14089void __tile_idn_send (unsigned)
14090void __tile_sn_send (unsigned)
14091void __tile_udn_send (unsigned)
14092
14093@end smallexample
14094
14095The intrinsic @code{void __tile_network_barrier (void)} is used to
14096guarantee that no network operatons before it will be reordered with
14097those after it.
14098
1e9af880 14099@node Target Format Checks
14100@section Format Checks Specific to Particular Target Machines
14101
14102For some target machines, GCC supports additional options to the
14103format attribute
14104(@pxref{Function Attributes,,Declaring Attributes of Functions}).
14105
14106@menu
14107* Solaris Format Checks::
1f6616ee 14108* Darwin Format Checks::
1e9af880 14109@end menu
14110
14111@node Solaris Format Checks
14112@subsection Solaris Format Checks
14113
14114Solaris targets support the @code{cmn_err} (or @code{__cmn_err__}) format
14115check. @code{cmn_err} accepts a subset of the standard @code{printf}
14116conversions, and the two-argument @code{%b} conversion for displaying
14117bit-fields. See the Solaris man page for @code{cmn_err} for more information.
14118
1f6616ee 14119@node Darwin Format Checks
14120@subsection Darwin Format Checks
14121
15b474a2 14122Darwin targets support the @code{CFString} (or @code{__CFString__}) in the format
1f6616ee 14123attribute context. Declarations made with such attribution will be parsed for correct syntax
14124and format argument types. However, parsing of the format string itself is currently undefined
15b474a2 14125and will not be carried out by this version of the compiler.
1f6616ee 14126
14127Additionally, @code{CFStringRefs} (defined by the @code{CoreFoundation} headers) may
14128also be used as format arguments. Note that the relevant headers are only likely to be
14129available on Darwin (OSX) installations. On such installations, the XCode and system
14130documentation provide descriptions of @code{CFString}, @code{CFStringRefs} and
14131associated functions.
14132
49f45d83 14133@node Pragmas
14134@section Pragmas Accepted by GCC
14135@cindex pragmas
12786727 14136@cindex @code{#pragma}
49f45d83 14137
14138GCC supports several types of pragmas, primarily in order to compile
14139code originally written for other compilers. Note that in general
14140we do not recommend the use of pragmas; @xref{Function Attributes},
14141for further explanation.
14142
14143@menu
14144* ARM Pragmas::
85c84d5c 14145* M32C Pragmas::
7c3116fb 14146* MeP Pragmas::
edd2f2ae 14147* RS/6000 and PowerPC Pragmas::
49f45d83 14148* Darwin Pragmas::
e02a1225 14149* Solaris Pragmas::
146c1b4f 14150* Symbol-Renaming Pragmas::
6b5553e5 14151* Structure-Packing Pragmas::
b60f73dc 14152* Weak Pragmas::
76f02516 14153* Diagnostic Pragmas::
4a2849cb 14154* Visibility Pragmas::
ebba2dc7 14155* Push/Pop Macro Pragmas::
46f8e3b0 14156* Function Specific Option Pragmas::
49f45d83 14157@end menu
14158
14159@node ARM Pragmas
14160@subsection ARM Pragmas
14161
14162The ARM target defines pragmas for controlling the default addition of
14163@code{long_call} and @code{short_call} attributes to functions.
14164@xref{Function Attributes}, for information about the effects of these
14165attributes.
14166
14167@table @code
14168@item long_calls
14169@cindex pragma, long_calls
14170Set all subsequent functions to have the @code{long_call} attribute.
14171
14172@item no_long_calls
14173@cindex pragma, no_long_calls
14174Set all subsequent functions to have the @code{short_call} attribute.
14175
14176@item long_calls_off
14177@cindex pragma, long_calls_off
14178Do not affect the @code{long_call} or @code{short_call} attributes of
14179subsequent functions.
14180@end table
14181
85c84d5c 14182@node M32C Pragmas
14183@subsection M32C Pragmas
14184
14185@table @code
e3d4e41e 14186@item GCC memregs @var{number}
85c84d5c 14187@cindex pragma, memregs
bfe513a4 14188Overrides the command-line option @code{-memregs=} for the current
85c84d5c 14189file. Use with care! This pragma must be before any function in the
14190file, and mixing different memregs values in different objects may
14191make them incompatible. This pragma is useful when a
14192performance-critical function uses a memreg for temporary values,
14193as it may allow you to reduce the number of memregs used.
14194
e3d4e41e 14195@item ADDRESS @var{name} @var{address}
14196@cindex pragma, address
14197For any declared symbols matching @var{name}, this does three things
14198to that symbol: it forces the symbol to be located at the given
14199address (a number), it forces the symbol to be volatile, and it
14200changes the symbol's scope to be static. This pragma exists for
14201compatibility with other compilers, but note that the common
14202@code{1234H} numeric syntax is not supported (use @code{0x1234}
14203instead). Example:
14204
14205@example
14206#pragma ADDRESS port3 0x103
14207char port3;
14208@end example
14209
85c84d5c 14210@end table
14211
7c3116fb 14212@node MeP Pragmas
14213@subsection MeP Pragmas
14214
14215@table @code
14216
14217@item custom io_volatile (on|off)
14218@cindex pragma, custom io_volatile
14219Overrides the command line option @code{-mio-volatile} for the current
14220file. Note that for compatibility with future GCC releases, this
14221option should only be used once before any @code{io} variables in each
14222file.
14223
14224@item GCC coprocessor available @var{registers}
14225@cindex pragma, coprocessor available
14226Specifies which coprocessor registers are available to the register
14227allocator. @var{registers} may be a single register, register range
14228separated by ellipses, or comma-separated list of those. Example:
14229
14230@example
14231#pragma GCC coprocessor available $c0...$c10, $c28
14232@end example
14233
14234@item GCC coprocessor call_saved @var{registers}
14235@cindex pragma, coprocessor call_saved
14236Specifies which coprocessor registers are to be saved and restored by
14237any function using them. @var{registers} may be a single register,
14238register range separated by ellipses, or comma-separated list of
14239those. Example:
14240
14241@example
14242#pragma GCC coprocessor call_saved $c4...$c6, $c31
14243@end example
14244
14245@item GCC coprocessor subclass '(A|B|C|D)' = @var{registers}
14246@cindex pragma, coprocessor subclass
14247Creates and defines a register class. These register classes can be
14248used by inline @code{asm} constructs. @var{registers} may be a single
14249register, register range separated by ellipses, or comma-separated
14250list of those. Example:
14251
14252@example
14253#pragma GCC coprocessor subclass 'B' = $c2, $c4, $c6
14254
14255asm ("cpfoo %0" : "=B" (x));
14256@end example
14257
14258@item GCC disinterrupt @var{name} , @var{name} @dots{}
14259@cindex pragma, disinterrupt
14260For the named functions, the compiler adds code to disable interrupts
14261for the duration of those functions. Any functions so named, which
14262are not encountered in the source, cause a warning that the pragma was
14263not used. Examples:
14264
14265@example
14266#pragma disinterrupt foo
14267#pragma disinterrupt bar, grill
58c0b97e 14268int foo () @{ @dots{} @}
7c3116fb 14269@end example
14270
14271@item GCC call @var{name} , @var{name} @dots{}
14272@cindex pragma, call
14273For the named functions, the compiler always uses a register-indirect
14274call model when calling the named functions. Examples:
14275
14276@example
14277extern int foo ();
14278#pragma call foo
14279@end example
14280
14281@end table
14282
edd2f2ae 14283@node RS/6000 and PowerPC Pragmas
14284@subsection RS/6000 and PowerPC Pragmas
14285
14286The RS/6000 and PowerPC targets define one pragma for controlling
14287whether or not the @code{longcall} attribute is added to function
14288declarations by default. This pragma overrides the @option{-mlongcall}
85456819 14289option, but not the @code{longcall} and @code{shortcall} attributes.
edd2f2ae 14290@xref{RS/6000 and PowerPC Options}, for more information about when long
14291calls are and are not necessary.
14292
14293@table @code
14294@item longcall (1)
14295@cindex pragma, longcall
14296Apply the @code{longcall} attribute to all subsequent function
14297declarations.
14298
14299@item longcall (0)
14300Do not apply the @code{longcall} attribute to subsequent function
14301declarations.
14302@end table
14303
49f45d83 14304@c Describe h8300 pragmas here.
49f45d83 14305@c Describe sh pragmas here.
14306@c Describe v850 pragmas here.
14307
14308@node Darwin Pragmas
14309@subsection Darwin Pragmas
14310
14311The following pragmas are available for all architectures running the
14312Darwin operating system. These are useful for compatibility with other
1c95bb8d 14313Mac OS compilers.
49f45d83 14314
14315@table @code
14316@item mark @var{tokens}@dots{}
14317@cindex pragma, mark
14318This pragma is accepted, but has no effect.
14319
14320@item options align=@var{alignment}
14321@cindex pragma, options align
14322This pragma sets the alignment of fields in structures. The values of
14323@var{alignment} may be @code{mac68k}, to emulate m68k alignment, or
14324@code{power}, to emulate PowerPC alignment. Uses of this pragma nest
14325properly; to restore the previous setting, use @code{reset} for the
14326@var{alignment}.
14327
14328@item segment @var{tokens}@dots{}
14329@cindex pragma, segment
14330This pragma is accepted, but has no effect.
14331
14332@item unused (@var{var} [, @var{var}]@dots{})
14333@cindex pragma, unused
14334This pragma declares variables to be possibly unused. GCC will not
14335produce warnings for the listed variables. The effect is similar to
14336that of the @code{unused} attribute, except that this pragma may appear
14337anywhere within the variables' scopes.
14338@end table
14339
e02a1225 14340@node Solaris Pragmas
14341@subsection Solaris Pragmas
14342
14343The Solaris target supports @code{#pragma redefine_extname}
14344(@pxref{Symbol-Renaming Pragmas}). It also supports additional
14345@code{#pragma} directives for compatibility with the system compiler.
14346
14347@table @code
14348@item align @var{alignment} (@var{variable} [, @var{variable}]...)
14349@cindex pragma, align
14350
14351Increase the minimum alignment of each @var{variable} to @var{alignment}.
14352This is the same as GCC's @code{aligned} attribute @pxref{Variable
68bf2ad9 14353Attributes}). Macro expansion occurs on the arguments to this pragma
a81d4cba 14354when compiling C and Objective-C@. It does not currently occur when
68bf2ad9 14355compiling C++, but this is a bug which may be fixed in a future
14356release.
e02a1225 14357
14358@item fini (@var{function} [, @var{function}]...)
14359@cindex pragma, fini
14360
14361This pragma causes each listed @var{function} to be called after
14362main, or during shared module unloading, by adding a call to the
14363@code{.fini} section.
14364
14365@item init (@var{function} [, @var{function}]...)
14366@cindex pragma, init
14367
14368This pragma causes each listed @var{function} to be called during
14369initialization (before @code{main}) or during shared module loading, by
14370adding a call to the @code{.init} section.
14371
14372@end table
14373
146c1b4f 14374@node Symbol-Renaming Pragmas
14375@subsection Symbol-Renaming Pragmas
ea42c4de 14376
126b6848 14377For compatibility with the Solaris system headers, GCC
146c1b4f 14378supports two @code{#pragma} directives which change the name used in
126b6848 14379assembly for a given declaration. To get this effect
7f68f564 14380on all platforms supported by GCC, use the asm labels extension (@pxref{Asm
146c1b4f 14381Labels}).
ea42c4de 14382
14383@table @code
14384@item redefine_extname @var{oldname} @var{newname}
14385@cindex pragma, redefine_extname
14386
146c1b4f 14387This pragma gives the C function @var{oldname} the assembly symbol
14388@var{newname}. The preprocessor macro @code{__PRAGMA_REDEFINE_EXTNAME}
7f68f564 14389will be defined if this pragma is available (currently on all platforms).
ea42c4de 14390@end table
14391
126b6848 14392This pragma and the asm labels extension interact in a complicated
146c1b4f 14393manner. Here are some corner cases you may want to be aware of.
14394
14395@enumerate
14396@item Both pragmas silently apply only to declarations with external
14397linkage. Asm labels do not have this restriction.
14398
14399@item In C++, both pragmas silently apply only to declarations with
14400``C'' linkage. Again, asm labels do not have this restriction.
14401
14402@item If any of the three ways of changing the assembly name of a
14403declaration is applied to a declaration whose assembly name has
14404already been determined (either by a previous use of one of these
14405features, or because the compiler needed the assembly name in order to
14406generate code), and the new name is different, a warning issues and
14407the name does not change.
14408
14409@item The @var{oldname} used by @code{#pragma redefine_extname} is
14410always the C-language name.
146c1b4f 14411@end enumerate
14412
6b5553e5 14413@node Structure-Packing Pragmas
14414@subsection Structure-Packing Pragmas
14415
ebba2dc7 14416For compatibility with Microsoft Windows compilers, GCC supports a
14417set of @code{#pragma} directives which change the maximum alignment of
14418members of structures (other than zero-width bitfields), unions, and
14419classes subsequently defined. The @var{n} value below always is required
14420to be a small power of two and specifies the new alignment in bytes.
6b5553e5 14421
14422@enumerate
14423@item @code{#pragma pack(@var{n})} simply sets the new alignment.
14424@item @code{#pragma pack()} sets the alignment to the one that was in
bfe513a4 14425effect when compilation started (see also command-line option
c23d8da9 14426@option{-fpack-struct[=@var{n}]} @pxref{Code Gen Options}).
6b5553e5 14427@item @code{#pragma pack(push[,@var{n}])} pushes the current alignment
14428setting on an internal stack and then optionally sets the new alignment.
14429@item @code{#pragma pack(pop)} restores the alignment setting to the one
14430saved at the top of the internal stack (and removes that stack entry).
14431Note that @code{#pragma pack([@var{n}])} does not influence this internal
14432stack; thus it is possible to have @code{#pragma pack(push)} followed by
14433multiple @code{#pragma pack(@var{n})} instances and finalized by a single
14434@code{#pragma pack(pop)}.
14435@end enumerate
14436
83d10720 14437Some targets, e.g.@: i386 and powerpc, support the @code{ms_struct}
114d1545 14438@code{#pragma} which lays out a structure as the documented
14439@code{__attribute__ ((ms_struct))}.
14440@enumerate
14441@item @code{#pragma ms_struct on} turns on the layout for structures
14442declared.
14443@item @code{#pragma ms_struct off} turns off the layout for structures
14444declared.
14445@item @code{#pragma ms_struct reset} goes back to the default layout.
14446@end enumerate
14447
b60f73dc 14448@node Weak Pragmas
14449@subsection Weak Pragmas
14450
14451For compatibility with SVR4, GCC supports a set of @code{#pragma}
14452directives for declaring symbols to be weak, and defining weak
14453aliases.
14454
14455@table @code
14456@item #pragma weak @var{symbol}
14457@cindex pragma, weak
14458This pragma declares @var{symbol} to be weak, as if the declaration
14459had the attribute of the same name. The pragma may appear before
fbdda6a7 14460or after the declaration of @var{symbol}. It is not an error for
b60f73dc 14461@var{symbol} to never be defined at all.
14462
14463@item #pragma weak @var{symbol1} = @var{symbol2}
14464This pragma declares @var{symbol1} to be a weak alias of @var{symbol2}.
14465It is an error if @var{symbol2} is not defined in the current
14466translation unit.
14467@end table
14468
76f02516 14469@node Diagnostic Pragmas
14470@subsection Diagnostic Pragmas
14471
14472GCC allows the user to selectively enable or disable certain types of
14473diagnostics, and change the kind of the diagnostic. For example, a
14474project's policy might require that all sources compile with
14475@option{-Werror} but certain files might have exceptions allowing
14476specific types of warnings. Or, a project might selectively enable
14477diagnostics and treat them as errors depending on which preprocessor
14478macros are defined.
14479
14480@table @code
14481@item #pragma GCC diagnostic @var{kind} @var{option}
14482@cindex pragma, diagnostic
14483
14484Modifies the disposition of a diagnostic. Note that not all
d1c59264 14485diagnostics are modifiable; at the moment only warnings (normally
7a5a9c54 14486controlled by @samp{-W@dots{}}) can be controlled, and not all of them.
76f02516 14487Use @option{-fdiagnostics-show-option} to determine which diagnostics
14488are controllable and which option controls them.
14489
14490@var{kind} is @samp{error} to treat this diagnostic as an error,
14491@samp{warning} to treat it like a warning (even if @option{-Werror} is
14492in effect), or @samp{ignored} if the diagnostic is to be ignored.
bfe513a4 14493@var{option} is a double quoted string which matches the command-line
76f02516 14494option.
14495
14496@example
14497#pragma GCC diagnostic warning "-Wformat"
ede5a481 14498#pragma GCC diagnostic error "-Wformat"
14499#pragma GCC diagnostic ignored "-Wformat"
76f02516 14500@end example
14501
0955be65 14502Note that these pragmas override any command-line options. GCC keeps
14503track of the location of each pragma, and issues diagnostics according
14504to the state as of that point in the source file. Thus, pragmas occurring
14505after a line do not affect diagnostics caused by that line.
14506
14507@item #pragma GCC diagnostic push
14508@itemx #pragma GCC diagnostic pop
14509
14510Causes GCC to remember the state of the diagnostics as of each
14511@code{push}, and restore to that point at each @code{pop}. If a
14512@code{pop} has no matching @code{push}, the command line options are
14513restored.
14514
14515@example
14516#pragma GCC diagnostic error "-Wuninitialized"
14517 foo(a); /* error is given for this one */
14518#pragma GCC diagnostic push
14519#pragma GCC diagnostic ignored "-Wuninitialized"
14520 foo(b); /* no diagnostic for this one */
14521#pragma GCC diagnostic pop
14522 foo(c); /* error is given for this one */
14523#pragma GCC diagnostic pop
14524 foo(d); /* depends on command line options */
14525@end example
76f02516 14526
14527@end table
14528
d0a9db40 14529GCC also offers a simple mechanism for printing messages during
14530compilation.
14531
14532@table @code
14533@item #pragma message @var{string}
14534@cindex pragma, diagnostic
14535
14536Prints @var{string} as a compiler message on compilation. The message
14537is informational only, and is neither a compilation warning nor an error.
14538
14539@smallexample
14540#pragma message "Compiling " __FILE__ "..."
14541@end smallexample
14542
14543@var{string} may be parenthesized, and is printed with location
14544information. For example,
14545
14546@smallexample
14547#define DO_PRAGMA(x) _Pragma (#x)
14548#define TODO(x) DO_PRAGMA(message ("TODO - " #x))
14549
14550TODO(Remember to fix this)
14551@end smallexample
14552
14553prints @samp{/tmp/file.c:4: note: #pragma message:
14554TODO - Remember to fix this}.
14555
14556@end table
14557
4a2849cb 14558@node Visibility Pragmas
14559@subsection Visibility Pragmas
14560
14561@table @code
14562@item #pragma GCC visibility push(@var{visibility})
14563@itemx #pragma GCC visibility pop
14564@cindex pragma, visibility
14565
14566This pragma allows the user to set the visibility for multiple
14567declarations without having to give each a visibility attribute
14568@xref{Function Attributes}, for more information about visibility and
14569the attribute syntax.
14570
14571In C++, @samp{#pragma GCC visibility} affects only namespace-scope
14572declarations. Class members and template specializations are not
14573affected; if you want to override the visibility for a particular
14574member or instantiation, you must use an attribute.
14575
14576@end table
14577
ebba2dc7 14578
14579@node Push/Pop Macro Pragmas
14580@subsection Push/Pop Macro Pragmas
14581
14582For compatibility with Microsoft Windows compilers, GCC supports
14583@samp{#pragma push_macro(@var{"macro_name"})}
14584and @samp{#pragma pop_macro(@var{"macro_name"})}.
14585
14586@table @code
14587@item #pragma push_macro(@var{"macro_name"})
14588@cindex pragma, push_macro
14589This pragma saves the value of the macro named as @var{macro_name} to
14590the top of the stack for this macro.
14591
14592@item #pragma pop_macro(@var{"macro_name"})
14593@cindex pragma, pop_macro
14594This pragma sets the value of the macro named as @var{macro_name} to
14595the value on top of the stack for this macro. If the stack for
14596@var{macro_name} is empty, the value of the macro remains unchanged.
14597@end table
14598
14599For example:
14600
14601@smallexample
14602#define X 1
14603#pragma push_macro("X")
14604#undef X
14605#define X -1
14606#pragma pop_macro("X")
15b474a2 14607int x [X];
ebba2dc7 14608@end smallexample
14609
14610In this example, the definition of X as 1 is saved by @code{#pragma
14611push_macro} and restored by @code{#pragma pop_macro}.
14612
46f8e3b0 14613@node Function Specific Option Pragmas
14614@subsection Function Specific Option Pragmas
14615
14616@table @code
24470055 14617@item #pragma GCC target (@var{"string"}...)
14618@cindex pragma GCC target
46f8e3b0 14619
14620This pragma allows you to set target specific options for functions
14621defined later in the source file. One or more strings can be
14622specified. Each function that is defined after this point will be as
24470055 14623if @code{attribute((target("STRING")))} was specified for that
46f8e3b0 14624function. The parenthesis around the options is optional.
14625@xref{Function Attributes}, for more information about the
24470055 14626@code{target} attribute and the attribute syntax.
46f8e3b0 14627
755fa783 14628The @code{#pragma GCC target} attribute is not implemented in GCC versions earlier
14629than 4.4 for the i386/x86_64 and 4.6 for the PowerPC backends. At
14630present, it is not implemented for other backends.
46f8e3b0 14631@end table
14632
46f8e3b0 14633@table @code
14634@item #pragma GCC optimize (@var{"string"}...)
14635@cindex pragma GCC optimize
14636
14637This pragma allows you to set global optimization options for functions
14638defined later in the source file. One or more strings can be
14639specified. Each function that is defined after this point will be as
14640if @code{attribute((optimize("STRING")))} was specified for that
14641function. The parenthesis around the options is optional.
14642@xref{Function Attributes}, for more information about the
14643@code{optimize} attribute and the attribute syntax.
14644
14645The @samp{#pragma GCC optimize} pragma is not implemented in GCC
14646versions earlier than 4.4.
14647@end table
14648
14649@table @code
24470055 14650@item #pragma GCC push_options
14651@itemx #pragma GCC pop_options
14652@cindex pragma GCC push_options
14653@cindex pragma GCC pop_options
14654
14655These pragmas maintain a stack of the current target and optimization
14656options. It is intended for include files where you temporarily want
14657to switch to using a different @samp{#pragma GCC target} or
14658@samp{#pragma GCC optimize} and then to pop back to the previous
14659options.
14660
14661The @samp{#pragma GCC push_options} and @samp{#pragma GCC pop_options}
14662pragmas are not implemented in GCC versions earlier than 4.4.
46f8e3b0 14663@end table
14664
14665@table @code
24470055 14666@item #pragma GCC reset_options
14667@cindex pragma GCC reset_options
46f8e3b0 14668
24470055 14669This pragma clears the current @code{#pragma GCC target} and
14670@code{#pragma GCC optimize} to use the default switches as specified
14671on the command line.
14672
14673The @samp{#pragma GCC reset_options} pragma is not implemented in GCC
14674versions earlier than 4.4.
46f8e3b0 14675@end table
14676
7cb6c162 14677@node Unnamed Fields
158eddcc 14678@section Unnamed struct/union fields within structs/unions
12786727 14679@cindex @code{struct}
14680@cindex @code{union}
7cb6c162 14681
32074525 14682As permitted by ISO C11 and for compatibility with other compilers,
afb3d3c4 14683GCC allows you to define
7cb6c162 14684a structure or union that contains, as fields, structures and unions
14685without names. For example:
14686
a0ecd6b1 14687@smallexample
7cb6c162 14688struct @{
14689 int a;
14690 union @{
14691 int b;
14692 float c;
14693 @};
14694 int d;
14695@} foo;
a0ecd6b1 14696@end smallexample
7cb6c162 14697
14698In this example, the user would be able to access members of the unnamed
14699union with code like @samp{foo.b}. Note that only unnamed structs and
14700unions are allowed, you may not have, for example, an unnamed
14701@code{int}.
14702
14703You must never create such structures that cause ambiguous field definitions.
14704For example, this structure:
14705
a0ecd6b1 14706@smallexample
7cb6c162 14707struct @{
14708 int a;
14709 struct @{
14710 int a;
14711 @};
14712@} foo;
a0ecd6b1 14713@end smallexample
7cb6c162 14714
14715It is ambiguous which @code{a} is being referred to with @samp{foo.a}.
8af5341f 14716The compiler gives errors for such constructs.
7cb6c162 14717
158eddcc 14718@opindex fms-extensions
14719Unless @option{-fms-extensions} is used, the unnamed field must be a
14720structure or union definition without a tag (for example, @samp{struct
9b280b35 14721@{ int a; @};}). If @option{-fms-extensions} is used, the field may
158eddcc 14722also be a definition with a tag such as @samp{struct foo @{ int a;
14723@};}, a reference to a previously defined structure or union such as
14724@samp{struct foo;}, or a reference to a @code{typedef} name for a
9b280b35 14725previously defined structure or union type.
158eddcc 14726
2fdec027 14727@opindex fplan9-extensions
14728The option @option{-fplan9-extensions} enables
14729@option{-fms-extensions} as well as two other extensions. First, a
14730pointer to a structure is automatically converted to a pointer to an
14731anonymous field for assignments and function calls. For example:
14732
14733@smallexample
14734struct s1 @{ int a; @};
14735struct s2 @{ struct s1; @};
14736extern void f1 (struct s1 *);
14737void f2 (struct s2 *p) @{ f1 (p); @}
14738@end smallexample
14739
14740In the call to @code{f1} inside @code{f2}, the pointer @code{p} is
14741converted into a pointer to the anonymous field.
14742
14743Second, when the type of an anonymous field is a @code{typedef} for a
14744@code{struct} or @code{union}, code may refer to the field using the
14745name of the @code{typedef}.
14746
14747@smallexample
14748typedef struct @{ int a; @} s1;
14749struct s2 @{ s1; @};
14750s1 f1 (struct s2 *p) @{ return p->s1; @}
14751@end smallexample
14752
14753These usages are only permitted when they are not ambiguous.
14754
2a6f0f81 14755@node Thread-Local
14756@section Thread-Local Storage
14757@cindex Thread-Local Storage
abf68e10 14758@cindex @acronym{TLS}
12786727 14759@cindex @code{__thread}
2a6f0f81 14760
abf68e10 14761Thread-local storage (@acronym{TLS}) is a mechanism by which variables
14762are allocated such that there is one instance of the variable per extant
2a6f0f81 14763thread. The run-time model GCC uses to implement this originates
14764in the IA-64 processor-specific ABI, but has since been migrated
14765to other processors as well. It requires significant support from
14766the linker (@command{ld}), dynamic linker (@command{ld.so}), and
14767system libraries (@file{libc.so} and @file{libpthread.so}), so it
abf68e10 14768is not available everywhere.
2a6f0f81 14769
14770At the user level, the extension is visible with a new storage
14771class keyword: @code{__thread}. For example:
14772
a0ecd6b1 14773@smallexample
2a6f0f81 14774__thread int i;
14775extern __thread struct state s;
14776static __thread char *p;
a0ecd6b1 14777@end smallexample
2a6f0f81 14778
14779The @code{__thread} specifier may be used alone, with the @code{extern}
14780or @code{static} specifiers, but with no other storage class specifier.
14781When used with @code{extern} or @code{static}, @code{__thread} must appear
14782immediately after the other storage class specifier.
14783
14784The @code{__thread} specifier may be applied to any global, file-scoped
4facf21c 14785static, function-scoped static, or static data member of a class. It may
14786not be applied to block-scoped automatic or non-static data member.
2a6f0f81 14787
14788When the address-of operator is applied to a thread-local variable, it is
14789evaluated at run-time and returns the address of the current thread's
14790instance of that variable. An address so obtained may be used by any
14791thread. When a thread terminates, any pointers to thread-local variables
14792in that thread become invalid.
14793
14794No static initialization may refer to the address of a thread-local variable.
14795
4facf21c 14796In C++, if an initializer is present for a thread-local variable, it must
14797be a @var{constant-expression}, as defined in 5.19.2 of the ANSI/ISO C++
14798standard.
2a6f0f81 14799
f4e302ca 14800See @uref{http://www.akkadia.org/drepper/tls.pdf,
2a6f0f81 14801ELF Handling For Thread-Local Storage} for a detailed explanation of
14802the four thread-local storage addressing models, and how the run-time
14803is expected to function.
14804
abf68e10 14805@menu
14806* C99 Thread-Local Edits::
14807* C++98 Thread-Local Edits::
14808@end menu
14809
14810@node C99 Thread-Local Edits
14811@subsection ISO/IEC 9899:1999 Edits for Thread-Local Storage
14812
14813The following are a set of changes to ISO/IEC 9899:1999 (aka C99)
14814that document the exact semantics of the language extension.
14815
14816@itemize @bullet
14817@item
14818@cite{5.1.2 Execution environments}
14819
14820Add new text after paragraph 1
14821
14822@quotation
14823Within either execution environment, a @dfn{thread} is a flow of
14824control within a program. It is implementation defined whether
14825or not there may be more than one thread associated with a program.
14826It is implementation defined how threads beyond the first are
14827created, the name and type of the function called at thread
14828startup, and how threads may be terminated. However, objects
14829with thread storage duration shall be initialized before thread
14830startup.
14831@end quotation
14832
14833@item
14834@cite{6.2.4 Storage durations of objects}
14835
14836Add new text before paragraph 3
14837
14838@quotation
14839An object whose identifier is declared with the storage-class
14840specifier @w{@code{__thread}} has @dfn{thread storage duration}.
14841Its lifetime is the entire execution of the thread, and its
14842stored value is initialized only once, prior to thread startup.
14843@end quotation
14844
14845@item
14846@cite{6.4.1 Keywords}
14847
14848Add @code{__thread}.
14849
14850@item
14851@cite{6.7.1 Storage-class specifiers}
14852
14853Add @code{__thread} to the list of storage class specifiers in
14854paragraph 1.
14855
14856Change paragraph 2 to
14857
14858@quotation
14859With the exception of @code{__thread}, at most one storage-class
14860specifier may be given [@dots{}]. The @code{__thread} specifier may
14861be used alone, or immediately following @code{extern} or
14862@code{static}.
14863@end quotation
14864
14865Add new text after paragraph 6
14866
14867@quotation
14868The declaration of an identifier for a variable that has
14869block scope that specifies @code{__thread} shall also
14870specify either @code{extern} or @code{static}.
14871
14872The @code{__thread} specifier shall be used only with
14873variables.
14874@end quotation
14875@end itemize
14876
14877@node C++98 Thread-Local Edits
14878@subsection ISO/IEC 14882:1998 Edits for Thread-Local Storage
14879
14880The following are a set of changes to ISO/IEC 14882:1998 (aka C++98)
14881that document the exact semantics of the language extension.
14882
14883@itemize @bullet
258b58a9 14884@item
abf68e10 14885@b{[intro.execution]}
14886
14887New text after paragraph 4
14888
14889@quotation
14890A @dfn{thread} is a flow of control within the abstract machine.
14891It is implementation defined whether or not there may be more than
14892one thread.
14893@end quotation
14894
14895New text after paragraph 7
14896
14897@quotation
85456819 14898It is unspecified whether additional action must be taken to
abf68e10 14899ensure when and whether side effects are visible to other threads.
14900@end quotation
14901
14902@item
14903@b{[lex.key]}
14904
14905Add @code{__thread}.
14906
14907@item
14908@b{[basic.start.main]}
14909
14910Add after paragraph 5
14911
14912@quotation
14913The thread that begins execution at the @code{main} function is called
85456819 14914the @dfn{main thread}. It is implementation defined how functions
abf68e10 14915beginning threads other than the main thread are designated or typed.
14916A function so designated, as well as the @code{main} function, is called
14917a @dfn{thread startup function}. It is implementation defined what
14918happens if a thread startup function returns. It is implementation
14919defined what happens to other threads when any thread calls @code{exit}.
14920@end quotation
14921
14922@item
14923@b{[basic.start.init]}
14924
14925Add after paragraph 4
14926
14927@quotation
14928The storage for an object of thread storage duration shall be
a99e98db 14929statically initialized before the first statement of the thread startup
abf68e10 14930function. An object of thread storage duration shall not require
14931dynamic initialization.
14932@end quotation
14933
14934@item
14935@b{[basic.start.term]}
14936
14937Add after paragraph 3
14938
14939@quotation
4facf21c 14940The type of an object with thread storage duration shall not have a
14941non-trivial destructor, nor shall it be an array type whose elements
14942(directly or indirectly) have non-trivial destructors.
abf68e10 14943@end quotation
14944
14945@item
14946@b{[basic.stc]}
14947
14948Add ``thread storage duration'' to the list in paragraph 1.
14949
14950Change paragraph 2
14951
14952@quotation
14953Thread, static, and automatic storage durations are associated with
14954objects introduced by declarations [@dots{}].
14955@end quotation
14956
14957Add @code{__thread} to the list of specifiers in paragraph 3.
14958
14959@item
14960@b{[basic.stc.thread]}
14961
14962New section before @b{[basic.stc.static]}
14963
14964@quotation
299006ee 14965The keyword @code{__thread} applied to a non-local object gives the
abf68e10 14966object thread storage duration.
14967
14968A local variable or class data member declared both @code{static}
14969and @code{__thread} gives the variable or member thread storage
14970duration.
14971@end quotation
14972
14973@item
14974@b{[basic.stc.static]}
14975
14976Change paragraph 1
14977
14978@quotation
14979All objects which have neither thread storage duration, dynamic
14980storage duration nor are local [@dots{}].
14981@end quotation
14982
14983@item
14984@b{[dcl.stc]}
14985
14986Add @code{__thread} to the list in paragraph 1.
14987
14988Change paragraph 1
14989
14990@quotation
14991With the exception of @code{__thread}, at most one
14992@var{storage-class-specifier} shall appear in a given
14993@var{decl-specifier-seq}. The @code{__thread} specifier may
14994be used alone, or immediately following the @code{extern} or
14995@code{static} specifiers. [@dots{}]
14996@end quotation
14997
14998Add after paragraph 5
14999
15000@quotation
15001The @code{__thread} specifier can be applied only to the names of objects
15002and to anonymous unions.
15003@end quotation
15004
15005@item
15006@b{[class.mem]}
15007
15008Add after paragraph 6
15009
15010@quotation
15011Non-@code{static} members shall not be @code{__thread}.
15012@end quotation
15013@end itemize
15014
d7282a2b 15015@node Binary constants
15016@section Binary constants using the @samp{0b} prefix
15017@cindex Binary constants using the @samp{0b} prefix
15018
15019Integer constants can be written as binary constants, consisting of a
15020sequence of @samp{0} and @samp{1} digits, prefixed by @samp{0b} or
15021@samp{0B}. This is particularly useful in environments that operate a
15022lot on the bit-level (like microcontrollers).
15023
15024The following statements are identical:
15025
15026@smallexample
15027i = 42;
15028i = 0x2a;
15029i = 052;
15030i = 0b101010;
15031@end smallexample
15032
15033The type of these constants follows the same rules as for octal or
15034hexadecimal integer constants, so suffixes like @samp{L} or @samp{UL}
15035can be applied.
15036
146ef39f 15037@node C++ Extensions
15038@chapter Extensions to the C++ Language
15039@cindex extensions, C++ language
15040@cindex C++ language extensions
15041
15042The GNU compiler provides these extensions to the C++ language (and you
15043can also use most of the C language extensions in your C++ programs). If you
15044want to write code that checks whether these features are available, you can
15045test for the GNU compiler the same way as for C programs: check for a
15046predefined macro @code{__GNUC__}. You can also use @code{__GNUG__} to
c47cbd00 15047test specifically for GNU C++ (@pxref{Common Predefined Macros,,
15048Predefined Macros,cpp,The GNU C Preprocessor}).
146ef39f 15049
15050@menu
e83c4d0f 15051* C++ Volatiles:: What constitutes an access to a volatile object.
dbe4c49e 15052* Restricted Pointers:: C99 restricted pointers and references.
a89b0e97 15053* Vague Linkage:: Where G++ puts inlines, vtables and such.
146ef39f 15054* C++ Interface:: You can use a single C++ header file for both
64b04d50 15055 declarations and definitions.
146ef39f 15056* Template Instantiation:: Methods for ensuring that exactly one copy of
64b04d50 15057 each needed template instantiation is emitted.
8b76b461 15058* Bound member functions:: You can extract a function pointer to the
15059 method denoted by a @samp{->*} or @samp{.*} expression.
64b04d50 15060* C++ Attributes:: Variable, function, and type attributes for C++ only.
ea4d28f3 15061* Namespace Association:: Strong using-directives for namespace association.
481451eb 15062* Type Traits:: Compiler support for type traits
6df8a9dd 15063* Java Exceptions:: Tweaking exception handling to work with Java.
a77827f5 15064* Deprecated Features:: Things will disappear from g++.
64b04d50 15065* Backwards Compatibility:: Compatibilities with earlier definitions of C++.
146ef39f 15066@end menu
15067
e83c4d0f 15068@node C++ Volatiles
15069@section When is a Volatile C++ Object Accessed?
b1a8d4ce 15070@cindex accessing volatiles
15071@cindex volatile read
15072@cindex volatile write
15073@cindex volatile access
15074
e83c4d0f 15075The C++ standard differs from the C standard in its treatment of
15076volatile objects. It fails to specify what constitutes a volatile
15077access, except to say that C++ should behave in a similar manner to C
15078with respect to volatiles, where possible. However, the different
7e44812a 15079lvalueness of expressions between C and C++ complicate the behavior.
e83c4d0f 15080G++ behaves the same as GCC for volatile access, @xref{C
7e44812a 15081Extensions,,Volatiles}, for a description of GCC's behavior.
b1a8d4ce 15082
e83c4d0f 15083The C and C++ language specifications differ when an object is
15084accessed in a void context:
b1a8d4ce 15085
a0ecd6b1 15086@smallexample
8e5fcce7 15087volatile int *src = @var{somevalue};
b1a8d4ce 15088*src;
a0ecd6b1 15089@end smallexample
b1a8d4ce 15090
e83c4d0f 15091The C++ standard specifies that such expressions do not undergo lvalue
15092to rvalue conversion, and that the type of the dereferenced object may
15093be incomplete. The C++ standard does not specify explicitly that it
15094is lvalue to rvalue conversion which is responsible for causing an
15095access. There is reason to believe that it is, because otherwise
15096certain simple expressions become undefined. However, because it
15097would surprise most programmers, G++ treats dereferencing a pointer to
15098volatile object of complete type as GCC would do for an equivalent
15099type in C@. When the object has incomplete type, G++ issues a
15100warning; if you wish to force an error, you must force a conversion to
15101rvalue with, for instance, a static cast.
b1a8d4ce 15102
37744367 15103When using a reference to volatile, G++ does not treat equivalent
b1a8d4ce 15104expressions as accesses to volatiles, but instead issues a warning that
71d6ad5e 15105no volatile is accessed. The rationale for this is that otherwise it
b1a8d4ce 15106becomes difficult to determine where volatile access occur, and not
15107possible to ignore the return value from functions returning volatile
71d6ad5e 15108references. Again, if you wish to force a read, cast the reference to
b1a8d4ce 15109an rvalue.
15110
7e44812a 15111G++ implements the same behavior as GCC does when assigning to a
e83c4d0f 15112volatile object -- there is no reread of the assigned-to object, the
15113assigned rvalue is reused. Note that in C++ assignment expressions
15114are lvalues, and if used as an lvalue, the volatile object will be
15115referred to. For instance, @var{vref} will refer to @var{vobj}, as
15116expected, in the following example:
15117
15118@smallexample
15119volatile int vobj;
15120volatile int &vref = vobj = @var{something};
15121@end smallexample
15122
6795ece9 15123@node Restricted Pointers
15124@section Restricting Pointer Aliasing
15125@cindex restricted pointers
15126@cindex restricted references
15127@cindex restricted this pointer
15128
ef8d967c 15129As with the C front end, G++ understands the C99 feature of restricted pointers,
6795ece9 15130specified with the @code{__restrict__}, or @code{__restrict} type
71d6ad5e 15131qualifier. Because you cannot compile C++ by specifying the @option{-std=c99}
6795ece9 15132language flag, @code{restrict} is not a keyword in C++.
15133
15134In addition to allowing restricted pointers, you can specify restricted
15135references, which indicate that the reference is not aliased in the local
15136context.
15137
a0ecd6b1 15138@smallexample
6795ece9 15139void fn (int *__restrict__ rptr, int &__restrict__ rref)
15140@{
4ae74ddd 15141 /* @r{@dots{}} */
6795ece9 15142@}
a0ecd6b1 15143@end smallexample
6795ece9 15144
15145@noindent
15146In the body of @code{fn}, @var{rptr} points to an unaliased integer and
15147@var{rref} refers to a (different) unaliased integer.
15148
15149You may also specify whether a member function's @var{this} pointer is
15150unaliased by using @code{__restrict__} as a member function qualifier.
15151
a0ecd6b1 15152@smallexample
6795ece9 15153void T::fn () __restrict__
15154@{
4ae74ddd 15155 /* @r{@dots{}} */
6795ece9 15156@}
a0ecd6b1 15157@end smallexample
6795ece9 15158
15159@noindent
15160Within the body of @code{T::fn}, @var{this} will have the effective
71d6ad5e 15161definition @code{T *__restrict__ const this}. Notice that the
6795ece9 15162interpretation of a @code{__restrict__} member function qualifier is
15163different to that of @code{const} or @code{volatile} qualifier, in that it
71d6ad5e 15164is applied to the pointer rather than the object. This is consistent with
6795ece9 15165other compilers which implement restricted pointers.
15166
15167As with all outermost parameter qualifiers, @code{__restrict__} is
71d6ad5e 15168ignored in function definition matching. This means you only need to
6795ece9 15169specify @code{__restrict__} in a function definition, rather than
15170in a function prototype as well.
15171
a89b0e97 15172@node Vague Linkage
15173@section Vague Linkage
15174@cindex vague linkage
15175
15176There are several constructs in C++ which require space in the object
15177file but are not clearly tied to a single translation unit. We say that
15178these constructs have ``vague linkage''. Typically such constructs are
15179emitted wherever they are needed, though sometimes we can be more
15180clever.
15181
15182@table @asis
15183@item Inline Functions
15184Inline functions are typically defined in a header file which can be
15185included in many different compilations. Hopefully they can usually be
15186inlined, but sometimes an out-of-line copy is necessary, if the address
15187of the function is taken or if inlining fails. In general, we emit an
15188out-of-line copy in all translation units where one is needed. As an
15189exception, we only emit inline virtual functions with the vtable, since
15190it will always require a copy.
15191
15192Local static variables and string constants used in an inline function
15193are also considered to have vague linkage, since they must be shared
15194between all inlined and out-of-line instances of the function.
15195
15196@item VTables
15197@cindex vtable
15198C++ virtual functions are implemented in most compilers using a lookup
15199table, known as a vtable. The vtable contains pointers to the virtual
15200functions provided by a class, and each object of the class contains a
15201pointer to its vtable (or vtables, in some multiple-inheritance
15202situations). If the class declares any non-inline, non-pure virtual
15203functions, the first one is chosen as the ``key method'' for the class,
15204and the vtable is only emitted in the translation unit where the key
15205method is defined.
15206
15207@emph{Note:} If the chosen key method is later defined as inline, the
15208vtable will still be emitted in every translation unit which defines it.
15209Make sure that any inline virtuals are declared inline in the class
15210body, even if they are not defined there.
15211
12786727 15212@item @code{type_info} objects
15213@cindex @code{type_info}
a89b0e97 15214@cindex RTTI
15215C++ requires information about types to be written out in order to
15216implement @samp{dynamic_cast}, @samp{typeid} and exception handling.
12786727 15217For polymorphic classes (classes with virtual functions), the @samp{type_info}
a89b0e97 15218object is written out along with the vtable so that @samp{dynamic_cast}
15219can determine the dynamic type of a class object at runtime. For all
12786727 15220other types, we write out the @samp{type_info} object when it is used: when
a89b0e97 15221applying @samp{typeid} to an expression, throwing an object, or
15222referring to a type in a catch clause or exception specification.
15223
15224@item Template Instantiations
15225Most everything in this section also applies to template instantiations,
15226but there are other options as well.
15227@xref{Template Instantiation,,Where's the Template?}.
15228
15229@end table
15230
15231When used with GNU ld version 2.8 or later on an ELF system such as
c20b542c 15232GNU/Linux or Solaris 2, or on Microsoft Windows, duplicate copies of
a89b0e97 15233these constructs will be discarded at link time. This is known as
15234COMDAT support.
15235
15236On targets that don't support COMDAT, but do support weak symbols, GCC
15237will use them. This way one copy will override all the others, but
15238the unused copies will still take up space in the executable.
15239
15240For targets which do not support either COMDAT or weak symbols,
15241most entities with vague linkage will be emitted as local symbols to
15242avoid duplicate definition errors from the linker. This will not happen
15243for local statics in inlines, however, as having multiple copies will
15244almost certainly break things.
15245
15246@xref{C++ Interface,,Declarations and Definitions in One Header}, for
15247another way to control placement of these constructs.
15248
146ef39f 15249@node C++ Interface
9dc0b451 15250@section #pragma interface and implementation
146ef39f 15251
15252@cindex interface and implementation headers, C++
15253@cindex C++ interface and implementation headers
146ef39f 15254@cindex pragmas, interface and implementation
146ef39f 15255
9dc0b451 15256@code{#pragma interface} and @code{#pragma implementation} provide the
15257user with a way of explicitly directing the compiler to emit entities
15258with vague linkage (and debugging information) in a particular
15259translation unit.
146ef39f 15260
9dc0b451 15261@emph{Note:} As of GCC 2.7.2, these @code{#pragma}s are not useful in
15262most cases, because of COMDAT support and the ``key method'' heuristic
15263mentioned in @ref{Vague Linkage}. Using them can actually cause your
fcc3191b 15264program to grow due to unnecessary out-of-line copies of inline
9dc0b451 15265functions. Currently (3.4) the only benefit of these
15266@code{#pragma}s is reduced duplication of debugging information, and
15267that should be addressed soon on DWARF 2 targets with the use of
15268COMDAT groups.
146ef39f 15269
15270@table @code
15271@item #pragma interface
15272@itemx #pragma interface "@var{subdir}/@var{objects}.h"
15273@kindex #pragma interface
15274Use this directive in @emph{header files} that define object classes, to save
15275space in most of the object files that use those classes. Normally,
15276local copies of certain information (backup copies of inline member
15277functions, debugging information, and the internal tables that implement
15278virtual functions) must be kept in each object file that includes class
15279definitions. You can use this pragma to avoid such duplication. When a
15280header file containing @samp{#pragma interface} is included in a
15281compilation, this auxiliary information will not be generated (unless
15282the main input source file itself uses @samp{#pragma implementation}).
15283Instead, the object files will contain references to be resolved at link
15284time.
15285
15286The second form of this directive is useful for the case where you have
15287multiple headers with the same name in different directories. If you
15288use this form, you must specify the same string to @samp{#pragma
15289implementation}.
15290
15291@item #pragma implementation
15292@itemx #pragma implementation "@var{objects}.h"
15293@kindex #pragma implementation
15294Use this pragma in a @emph{main input file}, when you want full output from
15295included header files to be generated (and made globally visible). The
15296included header file, in turn, should use @samp{#pragma interface}.
15297Backup copies of inline member functions, debugging information, and the
15298internal tables used to implement virtual functions are all generated in
15299implementation files.
15300
15301@cindex implied @code{#pragma implementation}
15302@cindex @code{#pragma implementation}, implied
15303@cindex naming convention, implementation headers
15304If you use @samp{#pragma implementation} with no argument, it applies to
15305an include file with the same basename@footnote{A file's @dfn{basename}
15306was the name stripped of all leading path information and of trailing
15307suffixes, such as @samp{.h} or @samp{.C} or @samp{.cc}.} as your source
15308file. For example, in @file{allclass.cc}, giving just
15309@samp{#pragma implementation}
15310by itself is equivalent to @samp{#pragma implementation "allclass.h"}.
15311
15312In versions of GNU C++ prior to 2.6.0 @file{allclass.h} was treated as
15313an implementation file whenever you would include it from
15314@file{allclass.cc} even if you never specified @samp{#pragma
15315implementation}. This was deemed to be more trouble than it was worth,
15316however, and disabled.
15317
146ef39f 15318Use the string argument if you want a single implementation file to
15319include code from multiple header files. (You must also use
15320@samp{#include} to include the header file; @samp{#pragma
15321implementation} only specifies how to use the file---it doesn't actually
15322include it.)
15323
15324There is no way to split up the contents of a single header file into
15325multiple implementation files.
15326@end table
15327
15328@cindex inlining and C++ pragmas
15329@cindex C++ pragmas, effect on inlining
15330@cindex pragmas in C++, effect on inlining
15331@samp{#pragma implementation} and @samp{#pragma interface} also have an
15332effect on function inlining.
15333
15334If you define a class in a header file marked with @samp{#pragma
9dc0b451 15335interface}, the effect on an inline function defined in that class is
15336similar to an explicit @code{extern} declaration---the compiler emits
15337no code at all to define an independent version of the function. Its
15338definition is used only for inlining with its callers.
146ef39f 15339
67791935 15340@opindex fno-implement-inlines
146ef39f 15341Conversely, when you include the same header file in a main source file
15342that declares it as @samp{#pragma implementation}, the compiler emits
15343code for the function itself; this defines a version of the function
15344that can be found via pointers (or by callers compiled without
15345inlining). If all calls to the function can be inlined, you can avoid
67791935 15346emitting the function by compiling with @option{-fno-implement-inlines}.
146ef39f 15347If any calls were not inlined, you will get linker errors.
15348
15349@node Template Instantiation
15350@section Where's the Template?
146ef39f 15351@cindex template instantiation
15352
15353C++ templates are the first language feature to require more
15354intelligence from the environment than one usually finds on a UNIX
15355system. Somehow the compiler and linker have to make sure that each
15356template instance occurs exactly once in the executable if it is needed,
15357and not at all otherwise. There are two basic approaches to this
153e79bc 15358problem, which are referred to as the Borland model and the Cfront model.
146ef39f 15359
15360@table @asis
15361@item Borland model
15362Borland C++ solved the template instantiation problem by adding the code
f96ff825 15363equivalent of common blocks to their linker; the compiler emits template
15364instances in each translation unit that uses them, and the linker
15365collapses them together. The advantage of this model is that the linker
15366only has to consider the object files themselves; there is no external
15367complexity to worry about. This disadvantage is that compilation time
15368is increased because the template code is being compiled repeatedly.
15369Code written for this model tends to include definitions of all
15370templates in the header file, since they must be seen to be
15371instantiated.
146ef39f 15372
15373@item Cfront model
15374The AT&T C++ translator, Cfront, solved the template instantiation
15375problem by creating the notion of a template repository, an
f96ff825 15376automatically maintained place where template instances are stored. A
15377more modern version of the repository works as follows: As individual
15378object files are built, the compiler places any template definitions and
15379instantiations encountered in the repository. At link time, the link
15380wrapper adds in the objects in the repository and compiles any needed
15381instances that were not previously emitted. The advantages of this
15382model are more optimal compilation speed and the ability to use the
15383system linker; to implement the Borland model a compiler vendor also
146ef39f 15384needs to replace the linker. The disadvantages are vastly increased
f96ff825 15385complexity, and thus potential for error; for some code this can be
15386just as transparent, but in practice it can been very difficult to build
146ef39f 15387multiple programs in one directory and one program in multiple
f96ff825 15388directories. Code written for this model tends to separate definitions
15389of non-inline member templates into a separate file, which should be
15390compiled separately.
146ef39f 15391@end table
15392
f96ff825 15393When used with GNU ld version 2.8 or later on an ELF system such as
ef8d967c 15394GNU/Linux or Solaris 2, or on Microsoft Windows, G++ supports the
15395Borland model. On other systems, G++ implements neither automatic
865ff07f 15396model.
f96ff825 15397
6ad63f69 15398You have the following options for dealing with template instantiations:
146ef39f 15399
15400@enumerate
7223a120 15401@item
67791935 15402@opindex frepo
15403Compile your template-using code with @option{-frepo}. The compiler will
7223a120 15404generate files with the extension @samp{.rpo} listing all of the
15405template instantiations used in the corresponding object files which
15406could be instantiated there; the link wrapper, @samp{collect2}, will
15407then update the @samp{.rpo} files to tell the compiler where to place
15408those instantiations and rebuild any affected object files. The
15409link-time overhead is negligible after the first pass, as the compiler
15410will continue to place the instantiations in the same files.
15411
15412This is your best option for application code written for the Borland
15413model, as it will just work. Code written for the Cfront model will
15414need to be modified so that the template definitions are available at
15415one or more points of instantiation; usually this is as simple as adding
15416@code{#include <tmethods.cc>} to the end of each template header.
15417
15418For library code, if you want the library to provide all of the template
15419instantiations it needs, just try to link all of its object files
15420together; the link will fail, but cause the instantiations to be
15421generated as a side effect. Be warned, however, that this may cause
15422conflicts if multiple libraries try to provide the same instantiations.
15423For greater control, use explicit instantiation as described in the next
15424option.
15425
146ef39f 15426@item
67791935 15427@opindex fno-implicit-templates
15428Compile your code with @option{-fno-implicit-templates} to disable the
146ef39f 15429implicit generation of template instances, and explicitly instantiate
15430all the ones you use. This approach requires more knowledge of exactly
15431which instances you need than do the others, but it's less
15432mysterious and allows greater control. You can scatter the explicit
15433instantiations throughout your program, perhaps putting them in the
15434translation units where the instances are used or the translation units
15435that define the templates themselves; you can put all of the explicit
15436instantiations you need into one big file; or you can create small files
15437like
15438
a0ecd6b1 15439@smallexample
146ef39f 15440#include "Foo.h"
15441#include "Foo.cc"
15442
15443template class Foo<int>;
15444template ostream& operator <<
15445 (ostream&, const Foo<int>&);
a0ecd6b1 15446@end smallexample
146ef39f 15447
15448for each of the instances you need, and create a template instantiation
15449library from those.
15450
15451If you are using Cfront-model code, you can probably get away with not
67791935 15452using @option{-fno-implicit-templates} when compiling files that don't
146ef39f 15453@samp{#include} the member template definitions.
15454
15455If you use one big file to do the instantiations, you may want to
67791935 15456compile it without @option{-fno-implicit-templates} so you get all of the
146ef39f 15457instances required by your explicit instantiations (but not by any
15458other files) without having to specify them as well.
15459
6ad63f69 15460The ISO C++ 2011 standard allows forward declaration of explicit
15461instantiations (with @code{extern}). G++ supports explicit instantiation
15462declarations in C++98 mode and has extended the template instantiation
15463syntax to support instantiation of the compiler support data for a
0858f8a2 15464template class (i.e.@: the vtable) without instantiating any of its
d39bcd80 15465members (with @code{inline}), and instantiation of only the static data
15466members of a template class, without the support data or member
15467functions (with (@code{static}):
146ef39f 15468
a0ecd6b1 15469@smallexample
146ef39f 15470extern template int max (int, int);
146ef39f 15471inline template class Foo<int>;
d39bcd80 15472static template class Foo<int>;
a0ecd6b1 15473@end smallexample
146ef39f 15474
15475@item
ef8d967c 15476Do nothing. Pretend G++ does implement automatic instantiation
146ef39f 15477management. Code written for the Borland model will work fine, but
15478each translation unit will contain instances of each of the templates it
15479uses. In a large program, this can lead to an unacceptable amount of code
15480duplication.
146ef39f 15481@end enumerate
15482
8b76b461 15483@node Bound member functions
15484@section Extracting the function pointer from a bound pointer to member function
8b76b461 15485@cindex pmf
15486@cindex pointer to member function
15487@cindex bound pointer to member function
15488
15489In C++, pointer to member functions (PMFs) are implemented using a wide
15490pointer of sorts to handle all the possible call mechanisms; the PMF
15491needs to store information about how to adjust the @samp{this} pointer,
15492and if the function pointed to is virtual, where to find the vtable, and
15493where in the vtable to look for the member function. If you are using
15494PMFs in an inner loop, you should really reconsider that decision. If
15495that is not an option, you can extract the pointer to the function that
15496would be called for a given object/PMF pair and call it directly inside
15497the inner loop, to save a bit of time.
15498
15499Note that you will still be paying the penalty for the call through a
15500function pointer; on most modern architectures, such a call defeats the
0858e3a2 15501branch prediction features of the CPU@. This is also true of normal
8b76b461 15502virtual function calls.
15503
15504The syntax for this extension is
15505
a0ecd6b1 15506@smallexample
8b76b461 15507extern A a;
15508extern int (A::*fp)();
15509typedef int (*fptr)(A *);
15510
15511fptr p = (fptr)(a.*fp);
a0ecd6b1 15512@end smallexample
8b76b461 15513
0858f8a2 15514For PMF constants (i.e.@: expressions of the form @samp{&Klasse::Member}),
71d6ad5e 15515no object is needed to obtain the address of the function. They can be
96149f2d 15516converted to function pointers directly:
15517
a0ecd6b1 15518@smallexample
96149f2d 15519fptr p1 = (fptr)(&A::foo);
a0ecd6b1 15520@end smallexample
96149f2d 15521
67791935 15522@opindex Wno-pmf-conversions
15523You must specify @option{-Wno-pmf-conversions} to use this extension.
8b76b461 15524
2f1d6059 15525@node C++ Attributes
15526@section C++-Specific Variable, Function, and Type Attributes
15527
15528Some attributes only make sense for C++ programs.
15529
15530@table @code
15531@item init_priority (@var{priority})
12786727 15532@cindex @code{init_priority} attribute
2f1d6059 15533
15534
15535In Standard C++, objects defined at namespace scope are guaranteed to be
15536initialized in an order in strict accordance with that of their definitions
15537@emph{in a given translation unit}. No guarantee is made for initializations
15538across translation units. However, GNU C++ allows users to control the
f7b79b48 15539order of initialization of objects defined at namespace scope with the
2f1d6059 15540@code{init_priority} attribute by specifying a relative @var{priority},
15541a constant integral expression currently bounded between 101 and 65535
15542inclusive. Lower numbers indicate a higher priority.
15543
15544In the following example, @code{A} would normally be created before
15545@code{B}, but the @code{init_priority} attribute has reversed that order:
15546
b724fad7 15547@smallexample
2f1d6059 15548Some_Class A __attribute__ ((init_priority (2000)));
15549Some_Class B __attribute__ ((init_priority (543)));
b724fad7 15550@end smallexample
2f1d6059 15551
15552@noindent
15553Note that the particular values of @var{priority} do not matter; only their
15554relative ordering.
15555
15672c96 15556@item java_interface
12786727 15557@cindex @code{java_interface} attribute
15672c96 15558
3b0848a2 15559This type attribute informs C++ that the class is a Java interface. It may
15672c96 15560only be applied to classes declared within an @code{extern "Java"} block.
3b0848a2 15561Calls to methods declared in this interface will be dispatched using GCJ's
15562interface table mechanism, instead of regular virtual table dispatch.
15672c96 15563
2f1d6059 15564@end table
15565
e66bbea3 15566See also @ref{Namespace Association}.
a5ed46c9 15567
ea4d28f3 15568@node Namespace Association
15569@section Namespace Association
a5ed46c9 15570
b1cd4fdd 15571@strong{Caution:} The semantics of this extension are equivalent
15572to C++ 2011 inline namespaces. Users should use inline namespaces
15573instead as this extension will be removed in future versions of G++.
a703c8a1 15574
a5ed46c9 15575A using-directive with @code{__attribute ((strong))} is stronger
15576than a normal using-directive in two ways:
15577
15578@itemize @bullet
15579@item
ea4d28f3 15580Templates from the used namespace can be specialized and explicitly
15581instantiated as though they were members of the using namespace.
a5ed46c9 15582
15583@item
15584The using namespace is considered an associated namespace of all
15585templates in the used namespace for purposes of argument-dependent
15586name lookup.
15587@end itemize
15588
ea4d28f3 15589The used namespace must be nested within the using namespace so that
15590normal unqualified lookup works properly.
15591
a5ed46c9 15592This is useful for composing a namespace transparently from
15593implementation namespaces. For example:
15594
15595@smallexample
15596namespace std @{
15597 namespace debug @{
15598 template <class T> struct A @{ @};
15599 @}
15600 using namespace debug __attribute ((__strong__));
91acd86c 15601 template <> struct A<int> @{ @}; // @r{ok to specialize}
a5ed46c9 15602
15603 template <class T> void f (A<T>);
15604@}
15605
15606int main()
15607@{
91acd86c 15608 f (std::A<float>()); // @r{lookup finds} std::f
a5ed46c9 15609 f (std::A<int>());
15610@}
15611@end smallexample
15612
481451eb 15613@node Type Traits
15614@section Type Traits
15615
15616The C++ front-end implements syntactic extensions that allow to
15617determine at compile time various characteristics of a type (or of a
15618pair of types).
15619
15620@table @code
15621@item __has_nothrow_assign (type)
0aa5d886 15622If @code{type} is const qualified or is a reference type then the trait is
15623false. Otherwise if @code{__has_trivial_assign (type)} is true then the trait
15624is true, else if @code{type} is a cv class or union type with copy assignment
15625operators that are known not to throw an exception then the trait is true,
15b474a2 15626else it is false. Requires: @code{type} shall be a complete type,
a799da27 15627(possibly cv-qualified) @code{void}, or an array of unknown bound.
481451eb 15628
15629@item __has_nothrow_copy (type)
15630If @code{__has_trivial_copy (type)} is true then the trait is true, else if
15631@code{type} is a cv class or union type with copy constructors that
15632are known not to throw an exception then the trait is true, else it is false.
a799da27 15633Requires: @code{type} shall be a complete type, (possibly cv-qualified)
15634@code{void}, or an array of unknown bound.
481451eb 15635
15636@item __has_nothrow_constructor (type)
15637If @code{__has_trivial_constructor (type)} is true then the trait is
15638true, else if @code{type} is a cv class or union type (or array
15639thereof) with a default constructor that is known not to throw an
15b474a2 15640exception then the trait is true, else it is false. Requires:
15641@code{type} shall be a complete type, (possibly cv-qualified)
a799da27 15642@code{void}, or an array of unknown bound.
481451eb 15643
15644@item __has_trivial_assign (type)
15645If @code{type} is const qualified or is a reference type then the trait is
15646false. Otherwise if @code{__is_pod (type)} is true then the trait is
15647true, else if @code{type} is a cv class or union type with a trivial
15648copy assignment ([class.copy]) then the trait is true, else it is
15b474a2 15649false. Requires: @code{type} shall be a complete type, (possibly
a799da27 15650cv-qualified) @code{void}, or an array of unknown bound.
481451eb 15651
15652@item __has_trivial_copy (type)
15b474a2 15653If @code{__is_pod (type)} is true or @code{type} is a reference type
481451eb 15654then the trait is true, else if @code{type} is a cv class or union type
15655with a trivial copy constructor ([class.copy]) then the trait
15656is true, else it is false. Requires: @code{type} shall be a complete
a799da27 15657type, (possibly cv-qualified) @code{void}, or an array of unknown bound.
481451eb 15658
15659@item __has_trivial_constructor (type)
15660If @code{__is_pod (type)} is true then the trait is true, else if
15661@code{type} is a cv class or union type (or array thereof) with a
15662trivial default constructor ([class.ctor]) then the trait is true,
a799da27 15663else it is false. Requires: @code{type} shall be a complete
15664type, (possibly cv-qualified) @code{void}, or an array of unknown bound.
481451eb 15665
15666@item __has_trivial_destructor (type)
15667If @code{__is_pod (type)} is true or @code{type} is a reference type then
15668the trait is true, else if @code{type} is a cv class or union type (or
15669array thereof) with a trivial destructor ([class.dtor]) then the trait
15670is true, else it is false. Requires: @code{type} shall be a complete
a799da27 15671type, (possibly cv-qualified) @code{void}, or an array of unknown bound.
481451eb 15672
15673@item __has_virtual_destructor (type)
15674If @code{type} is a class type with a virtual destructor
15675([class.dtor]) then the trait is true, else it is false. Requires:
a799da27 15676@code{type} shall be a complete type, (possibly cv-qualified)
15677@code{void}, or an array of unknown bound.
481451eb 15678
15679@item __is_abstract (type)
15680If @code{type} is an abstract class ([class.abstract]) then the trait
15681is true, else it is false. Requires: @code{type} shall be a complete
a799da27 15682type, (possibly cv-qualified) @code{void}, or an array of unknown bound.
481451eb 15683
15684@item __is_base_of (base_type, derived_type)
15685If @code{base_type} is a base class of @code{derived_type}
15686([class.derived]) then the trait is true, otherwise it is false.
15687Top-level cv qualifications of @code{base_type} and
15688@code{derived_type} are ignored. For the purposes of this trait, a
15689class type is considered is own base. Requires: if @code{__is_class
15690(base_type)} and @code{__is_class (derived_type)} are true and
15691@code{base_type} and @code{derived_type} are not the same type
15692(disregarding cv-qualifiers), @code{derived_type} shall be a complete
15693type. Diagnostic is produced if this requirement is not met.
15694
15695@item __is_class (type)
15696If @code{type} is a cv class type, and not a union type
d2258b2f 15697([basic.compound]) the trait is true, else it is false.
481451eb 15698
15699@item __is_empty (type)
15700If @code{__is_class (type)} is false then the trait is false.
15701Otherwise @code{type} is considered empty if and only if: @code{type}
15702has no non-static data members, or all non-static data members, if
d2258b2f 15703any, are bit-fields of length 0, and @code{type} has no virtual
481451eb 15704members, and @code{type} has no virtual base classes, and @code{type}
15b474a2 15705has no base classes @code{base_type} for which
481451eb 15706@code{__is_empty (base_type)} is false. Requires: @code{type} shall
a799da27 15707be a complete type, (possibly cv-qualified) @code{void}, or an array
15708of unknown bound.
481451eb 15709
15710@item __is_enum (type)
d2258b2f 15711If @code{type} is a cv enumeration type ([basic.compound]) the trait is
481451eb 15712true, else it is false.
15713
a799da27 15714@item __is_literal_type (type)
15715If @code{type} is a literal type ([basic.types]) the trait is
15716true, else it is false. Requires: @code{type} shall be a complete type,
15717(possibly cv-qualified) @code{void}, or an array of unknown bound.
15718
481451eb 15719@item __is_pod (type)
15720If @code{type} is a cv POD type ([basic.types]) then the trait is true,
a799da27 15721else it is false. Requires: @code{type} shall be a complete type,
15722(possibly cv-qualified) @code{void}, or an array of unknown bound.
481451eb 15723
15724@item __is_polymorphic (type)
15725If @code{type} is a polymorphic class ([class.virtual]) then the trait
15726is true, else it is false. Requires: @code{type} shall be a complete
a799da27 15727type, (possibly cv-qualified) @code{void}, or an array of unknown bound.
15728
15729@item __is_standard_layout (type)
15730If @code{type} is a standard-layout type ([basic.types]) the trait is
15731true, else it is false. Requires: @code{type} shall be a complete
15732type, (possibly cv-qualified) @code{void}, or an array of unknown bound.
15733
15734@item __is_trivial (type)
15735If @code{type} is a trivial type ([basic.types]) the trait is
15736true, else it is false. Requires: @code{type} shall be a complete
15737type, (possibly cv-qualified) @code{void}, or an array of unknown bound.
481451eb 15738
15739@item __is_union (type)
d2258b2f 15740If @code{type} is a cv union type ([basic.compound]) the trait is
481451eb 15741true, else it is false.
15742
e455102d 15743@item __underlying_type (type)
15744The underlying type of @code{type}. Requires: @code{type} shall be
15745an enumeration type ([dcl.enum]).
15746
481451eb 15747@end table
15748
6df8a9dd 15749@node Java Exceptions
15750@section Java Exceptions
15751
15752The Java language uses a slightly different exception handling model
15753from C++. Normally, GNU C++ will automatically detect when you are
15754writing C++ code that uses Java exceptions, and handle them
15755appropriately. However, if C++ code only needs to execute destructors
15756when Java exceptions are thrown through it, GCC will guess incorrectly.
0fff59be 15757Sample problematic code is:
6df8a9dd 15758
b724fad7 15759@smallexample
6df8a9dd 15760 struct S @{ ~S(); @};
91acd86c 15761 extern void bar(); // @r{is written in Java, and may throw exceptions}
6df8a9dd 15762 void foo()
15763 @{
15764 S s;
15765 bar();
15766 @}
b724fad7 15767@end smallexample
6df8a9dd 15768
15769@noindent
15770The usual effect of an incorrect guess is a link failure, complaining of
15771a missing routine called @samp{__gxx_personality_v0}.
15772
15773You can inform the compiler that Java exceptions are to be used in a
15774translation unit, irrespective of what it might think, by writing
15775@samp{@w{#pragma GCC java_exceptions}} at the head of the file. This
15776@samp{#pragma} must appear before any functions that throw or catch
15777exceptions, or run destructors when exceptions are thrown through them.
15778
15779You cannot mix Java and C++ exceptions in the same translation unit. It
15780is believed to be safe to throw a C++ exception from one file through
0fff59be 15781another file compiled for the Java exception model, or vice versa, but
15782there may be bugs in this area.
6df8a9dd 15783
64b04d50 15784@node Deprecated Features
15785@section Deprecated Features
15786
15787In the past, the GNU C++ compiler was extended to experiment with new
71d6ad5e 15788features, at a time when the C++ language was still evolving. Now that
64b04d50 15789the C++ standard is complete, some of those features are superseded by
71d6ad5e 15790superior alternatives. Using the old features might cause a warning in
15791some cases that the feature will be dropped in the future. In other
64b04d50 15792cases, the feature might be gone already.
15793
15794While the list below is not exhaustive, it documents some of the options
15795that are now deprecated:
15796
15797@table @code
15798@item -fexternal-templates
15799@itemx -falt-external-templates
ef8d967c 15800These are two of the many ways for G++ to implement template
71d6ad5e 15801instantiation. @xref{Template Instantiation}. The C++ standard clearly
64b04d50 15802defines how template definitions have to be organized across
ef8d967c 15803implementation units. G++ has an implicit instantiation mechanism that
64b04d50 15804should work just fine for standard-conforming code.
15805
15806@item -fstrict-prototype
15807@itemx -fno-strict-prototype
15808Previously it was possible to use an empty prototype parameter list to
15809indicate an unspecified number of parameters (like C), rather than no
71d6ad5e 15810parameters, as C++ demands. This feature has been removed, except where
e66bbea3 15811it is required for backwards compatibility. @xref{Backwards Compatibility}.
64b04d50 15812@end table
15813
ac1c4b0c 15814G++ allows a virtual function returning @samp{void *} to be overridden
15815by one returning a different pointer type. This extension to the
15816covariant return type rules is now deprecated and will be removed from a
15817future version.
15818
d50879bc 15819The G++ minimum and maximum operators (@samp{<?} and @samp{>?}) and
15820their compound forms (@samp{<?=}) and @samp{>?=}) have been deprecated
04222864 15821and are now removed from G++. Code using these operators should be
15822modified to use @code{std::min} and @code{std::max} instead.
d50879bc 15823
57a9b138 15824The named return value extension has been deprecated, and is now
ef8d967c 15825removed from G++.
64b04d50 15826
4ea8b5e2 15827The use of initializer lists with new expressions has been deprecated,
ef8d967c 15828and is now removed from G++.
57a9b138 15829
15830Floating and complex non-type template parameters have been deprecated,
ef8d967c 15831and are now removed from G++.
57a9b138 15832
a77827f5 15833The implicit typename extension has been deprecated and is now
ef8d967c 15834removed from G++.
a77827f5 15835
d1c59264 15836The use of default arguments in function pointers, function typedefs
a77827f5 15837and other places where they are not permitted by the standard is
ef8d967c 15838deprecated and will be removed from a future version of G++.
4ea8b5e2 15839
36f6aa5e 15840G++ allows floating-point literals to appear in integral constant expressions,
15841e.g. @samp{ enum E @{ e = int(2.2 * 3.7) @} }
15842This extension is deprecated and will be removed from a future version.
15843
15844G++ allows static data members of const floating-point type to be declared
15845with an initializer in a class definition. The standard only allows
15846initializers for static members of const integral types and const
15847enumeration types so this extension has been deprecated and will be removed
15848from a future version.
15849
64b04d50 15850@node Backwards Compatibility
15851@section Backwards Compatibility
15852@cindex Backwards Compatibility
15853@cindex ARM [Annotated C++ Reference Manual]
15854
70c2c81c 15855Now that there is a definitive ISO standard C++, G++ has a specification
71d6ad5e 15856to adhere to. The C++ language evolved over time, and features that
64b04d50 15857used to be acceptable in previous drafts of the standard, such as the ARM
71d6ad5e 15858[Annotated C++ Reference Manual], are no longer accepted. In order to allow
70c2c81c 15859compilation of C++ written to such drafts, G++ contains some backwards
71d6ad5e 15860compatibilities. @emph{All such backwards compatibility features are
70c2c81c 15861liable to disappear in future versions of G++.} They should be considered
e66bbea3 15862deprecated. @xref{Deprecated Features}.
64b04d50 15863
15864@table @code
15865@item For scope
15866If a variable is declared at for scope, it used to remain in scope until
15867the end of the scope which contained the for statement (rather than just
70c2c81c 15868within the for scope). G++ retains this, but issues a warning, if such a
64b04d50 15869variable is accessed outside the for scope.
15870
57a9b138 15871@item Implicit C language
8ae77b3c 15872Old C system header files did not contain an @code{extern "C" @{@dots{}@}}
71d6ad5e 15873scope to set the language. On such systems, all header files are
15874implicitly scoped inside a C language scope. Also, an empty prototype
64b04d50 15875@code{()} will be treated as an unspecified number of arguments, rather
15876than no arguments, as C++ demands.
15877@end table