re PR middle-end/65958 (-fstack-check breaks alloca on architectures using generic...
[gcc.git] / gcc / doc / extend.texi
1 @c Copyright (C) 1988-2015 Free Software Foundation, Inc.
2
3 @c This is part of the GCC manual.
4 @c For copying conditions, see the file gcc.texi.
5
6 @node C Extensions
7 @chapter Extensions to the C Language Family
8 @cindex extensions, C language
9 @cindex C language extensions
10
11 @opindex pedantic
12 GNU C provides several language features not found in ISO standard C@.
13 (The @option{-pedantic} option directs GCC to print a warning message if
14 any of these features is used.) To test for the availability of these
15 features in conditional compilation, check for a predefined macro
16 @code{__GNUC__}, which is always defined under GCC@.
17
18 These extensions are available in C and Objective-C@. Most of them are
19 also available in C++. @xref{C++ Extensions,,Extensions to the
20 C++ Language}, for extensions that apply @emph{only} to C++.
21
22 Some features that are in ISO C99 but not C90 or C++ are also, as
23 extensions, accepted by GCC in C90 mode and in C++.
24
25 @menu
26 * Statement Exprs:: Putting statements and declarations inside expressions.
27 * Local Labels:: Labels local to a block.
28 * Labels as Values:: Getting pointers to labels, and computed gotos.
29 * Nested Functions:: As in Algol and Pascal, lexical scoping of functions.
30 * Constructing Calls:: Dispatching a call to another function.
31 * Typeof:: @code{typeof}: referring to the type of an expression.
32 * Conditionals:: Omitting the middle operand of a @samp{?:} expression.
33 * __int128:: 128-bit integers---@code{__int128}.
34 * Long Long:: Double-word integers---@code{long long int}.
35 * Complex:: Data types for complex numbers.
36 * Floating Types:: Additional Floating Types.
37 * Half-Precision:: Half-Precision Floating Point.
38 * Decimal Float:: Decimal Floating Types.
39 * Hex Floats:: Hexadecimal floating-point constants.
40 * Fixed-Point:: Fixed-Point Types.
41 * Named Address Spaces::Named address spaces.
42 * Zero Length:: Zero-length arrays.
43 * Empty Structures:: Structures with no members.
44 * Variable Length:: Arrays whose length is computed at run time.
45 * Variadic Macros:: Macros with a variable number of arguments.
46 * Escaped Newlines:: Slightly looser rules for escaped newlines.
47 * Subscripting:: Any array can be subscripted, even if not an lvalue.
48 * Pointer Arith:: Arithmetic on @code{void}-pointers and function pointers.
49 * Pointers to Arrays:: Pointers to arrays with qualifiers work as expected.
50 * Initializers:: Non-constant initializers.
51 * Compound Literals:: Compound literals give structures, unions
52 or arrays as values.
53 * Designated Inits:: Labeling elements of initializers.
54 * Case Ranges:: `case 1 ... 9' and such.
55 * Cast to Union:: Casting to union type from any member of the union.
56 * Mixed Declarations:: Mixing declarations and code.
57 * Function Attributes:: Declaring that functions have no side effects,
58 or that they can never return.
59 * Variable Attributes:: Specifying attributes of variables.
60 * Type Attributes:: Specifying attributes of types.
61 * Label Attributes:: Specifying attributes on labels.
62 * Enumerator Attributes:: Specifying attributes on enumerators.
63 * Attribute Syntax:: Formal syntax for attributes.
64 * Function Prototypes:: Prototype declarations and old-style definitions.
65 * C++ Comments:: C++ comments are recognized.
66 * Dollar Signs:: Dollar sign is allowed in identifiers.
67 * Character Escapes:: @samp{\e} stands for the character @key{ESC}.
68 * Alignment:: Inquiring about the alignment of a type or variable.
69 * Inline:: Defining inline functions (as fast as macros).
70 * Volatiles:: What constitutes an access to a volatile object.
71 * Using Assembly Language with C:: Instructions and extensions for interfacing C with assembler.
72 * Alternate Keywords:: @code{__const__}, @code{__asm__}, etc., for header files.
73 * Incomplete Enums:: @code{enum foo;}, with details to follow.
74 * Function Names:: Printable strings which are the name of the current
75 function.
76 * Return Address:: Getting the return or frame address of a function.
77 * Vector Extensions:: Using vector instructions through built-in functions.
78 * Offsetof:: Special syntax for implementing @code{offsetof}.
79 * __sync Builtins:: Legacy built-in functions for atomic memory access.
80 * __atomic Builtins:: Atomic built-in functions with memory model.
81 * Integer Overflow Builtins:: Built-in functions to perform arithmetics and
82 arithmetic overflow checking.
83 * x86 specific memory model extensions for transactional memory:: x86 memory models.
84 * Object Size Checking:: Built-in functions for limited buffer overflow
85 checking.
86 * Pointer Bounds Checker builtins:: Built-in functions for Pointer Bounds Checker.
87 * Cilk Plus Builtins:: Built-in functions for the Cilk Plus language extension.
88 * Other Builtins:: Other built-in functions.
89 * Target Builtins:: Built-in functions specific to particular targets.
90 * Target Format Checks:: Format checks specific to particular targets.
91 * Pragmas:: Pragmas accepted by GCC.
92 * Unnamed Fields:: Unnamed struct/union fields within structs/unions.
93 * Thread-Local:: Per-thread variables.
94 * Binary constants:: Binary constants using the @samp{0b} prefix.
95 @end menu
96
97 @node Statement Exprs
98 @section Statements and Declarations in Expressions
99 @cindex statements inside expressions
100 @cindex declarations inside expressions
101 @cindex expressions containing statements
102 @cindex macros, statements in expressions
103
104 @c the above section title wrapped and causes an underfull hbox.. i
105 @c changed it from "within" to "in". --mew 4feb93
106 A compound statement enclosed in parentheses may appear as an expression
107 in GNU C@. This allows you to use loops, switches, and local variables
108 within an expression.
109
110 Recall that a compound statement is a sequence of statements surrounded
111 by braces; in this construct, parentheses go around the braces. For
112 example:
113
114 @smallexample
115 (@{ int y = foo (); int z;
116 if (y > 0) z = y;
117 else z = - y;
118 z; @})
119 @end smallexample
120
121 @noindent
122 is a valid (though slightly more complex than necessary) expression
123 for the absolute value of @code{foo ()}.
124
125 The last thing in the compound statement should be an expression
126 followed by a semicolon; the value of this subexpression serves as the
127 value of the entire construct. (If you use some other kind of statement
128 last within the braces, the construct has type @code{void}, and thus
129 effectively no value.)
130
131 This feature is especially useful in making macro definitions ``safe'' (so
132 that they evaluate each operand exactly once). For example, the
133 ``maximum'' function is commonly defined as a macro in standard C as
134 follows:
135
136 @smallexample
137 #define max(a,b) ((a) > (b) ? (a) : (b))
138 @end smallexample
139
140 @noindent
141 @cindex side effects, macro argument
142 But this definition computes either @var{a} or @var{b} twice, with bad
143 results if the operand has side effects. In GNU C, if you know the
144 type of the operands (here taken as @code{int}), you can define
145 the macro safely as follows:
146
147 @smallexample
148 #define maxint(a,b) \
149 (@{int _a = (a), _b = (b); _a > _b ? _a : _b; @})
150 @end smallexample
151
152 Embedded statements are not allowed in constant expressions, such as
153 the value of an enumeration constant, the width of a bit-field, or
154 the initial value of a static variable.
155
156 If you don't know the type of the operand, you can still do this, but you
157 must use @code{typeof} or @code{__auto_type} (@pxref{Typeof}).
158
159 In G++, the result value of a statement expression undergoes array and
160 function pointer decay, and is returned by value to the enclosing
161 expression. For instance, if @code{A} is a class, then
162
163 @smallexample
164 A a;
165
166 (@{a;@}).Foo ()
167 @end smallexample
168
169 @noindent
170 constructs a temporary @code{A} object to hold the result of the
171 statement expression, and that is used to invoke @code{Foo}.
172 Therefore the @code{this} pointer observed by @code{Foo} is not the
173 address of @code{a}.
174
175 In a statement expression, any temporaries created within a statement
176 are destroyed at that statement's end. This makes statement
177 expressions inside macros slightly different from function calls. In
178 the latter case temporaries introduced during argument evaluation are
179 destroyed at the end of the statement that includes the function
180 call. In the statement expression case they are destroyed during
181 the statement expression. For instance,
182
183 @smallexample
184 #define macro(a) (@{__typeof__(a) b = (a); b + 3; @})
185 template<typename T> T function(T a) @{ T b = a; return b + 3; @}
186
187 void foo ()
188 @{
189 macro (X ());
190 function (X ());
191 @}
192 @end smallexample
193
194 @noindent
195 has different places where temporaries are destroyed. For the
196 @code{macro} case, the temporary @code{X} is destroyed just after
197 the initialization of @code{b}. In the @code{function} case that
198 temporary is destroyed when the function returns.
199
200 These considerations mean that it is probably a bad idea to use
201 statement expressions of this form in header files that are designed to
202 work with C++. (Note that some versions of the GNU C Library contained
203 header files using statement expressions that lead to precisely this
204 bug.)
205
206 Jumping into a statement expression with @code{goto} or using a
207 @code{switch} statement outside the statement expression with a
208 @code{case} or @code{default} label inside the statement expression is
209 not permitted. Jumping into a statement expression with a computed
210 @code{goto} (@pxref{Labels as Values}) has undefined behavior.
211 Jumping out of a statement expression is permitted, but if the
212 statement expression is part of a larger expression then it is
213 unspecified which other subexpressions of that expression have been
214 evaluated except where the language definition requires certain
215 subexpressions to be evaluated before or after the statement
216 expression. In any case, as with a function call, the evaluation of a
217 statement expression is not interleaved with the evaluation of other
218 parts of the containing expression. For example,
219
220 @smallexample
221 foo (), ((@{ bar1 (); goto a; 0; @}) + bar2 ()), baz();
222 @end smallexample
223
224 @noindent
225 calls @code{foo} and @code{bar1} and does not call @code{baz} but
226 may or may not call @code{bar2}. If @code{bar2} is called, it is
227 called after @code{foo} and before @code{bar1}.
228
229 @node Local Labels
230 @section Locally Declared Labels
231 @cindex local labels
232 @cindex macros, local labels
233
234 GCC allows you to declare @dfn{local labels} in any nested block
235 scope. A local label is just like an ordinary label, but you can
236 only reference it (with a @code{goto} statement, or by taking its
237 address) within the block in which it is declared.
238
239 A local label declaration looks like this:
240
241 @smallexample
242 __label__ @var{label};
243 @end smallexample
244
245 @noindent
246 or
247
248 @smallexample
249 __label__ @var{label1}, @var{label2}, /* @r{@dots{}} */;
250 @end smallexample
251
252 Local label declarations must come at the beginning of the block,
253 before any ordinary declarations or statements.
254
255 The label declaration defines the label @emph{name}, but does not define
256 the label itself. You must do this in the usual way, with
257 @code{@var{label}:}, within the statements of the statement expression.
258
259 The local label feature is useful for complex macros. If a macro
260 contains nested loops, a @code{goto} can be useful for breaking out of
261 them. However, an ordinary label whose scope is the whole function
262 cannot be used: if the macro can be expanded several times in one
263 function, the label is multiply defined in that function. A
264 local label avoids this problem. For example:
265
266 @smallexample
267 #define SEARCH(value, array, target) \
268 do @{ \
269 __label__ found; \
270 typeof (target) _SEARCH_target = (target); \
271 typeof (*(array)) *_SEARCH_array = (array); \
272 int i, j; \
273 int value; \
274 for (i = 0; i < max; i++) \
275 for (j = 0; j < max; j++) \
276 if (_SEARCH_array[i][j] == _SEARCH_target) \
277 @{ (value) = i; goto found; @} \
278 (value) = -1; \
279 found:; \
280 @} while (0)
281 @end smallexample
282
283 This could also be written using a statement expression:
284
285 @smallexample
286 #define SEARCH(array, target) \
287 (@{ \
288 __label__ found; \
289 typeof (target) _SEARCH_target = (target); \
290 typeof (*(array)) *_SEARCH_array = (array); \
291 int i, j; \
292 int value; \
293 for (i = 0; i < max; i++) \
294 for (j = 0; j < max; j++) \
295 if (_SEARCH_array[i][j] == _SEARCH_target) \
296 @{ value = i; goto found; @} \
297 value = -1; \
298 found: \
299 value; \
300 @})
301 @end smallexample
302
303 Local label declarations also make the labels they declare visible to
304 nested functions, if there are any. @xref{Nested Functions}, for details.
305
306 @node Labels as Values
307 @section Labels as Values
308 @cindex labels as values
309 @cindex computed gotos
310 @cindex goto with computed label
311 @cindex address of a label
312
313 You can get the address of a label defined in the current function
314 (or a containing function) with the unary operator @samp{&&}. The
315 value has type @code{void *}. This value is a constant and can be used
316 wherever a constant of that type is valid. For example:
317
318 @smallexample
319 void *ptr;
320 /* @r{@dots{}} */
321 ptr = &&foo;
322 @end smallexample
323
324 To use these values, you need to be able to jump to one. This is done
325 with the computed goto statement@footnote{The analogous feature in
326 Fortran is called an assigned goto, but that name seems inappropriate in
327 C, where one can do more than simply store label addresses in label
328 variables.}, @code{goto *@var{exp};}. For example,
329
330 @smallexample
331 goto *ptr;
332 @end smallexample
333
334 @noindent
335 Any expression of type @code{void *} is allowed.
336
337 One way of using these constants is in initializing a static array that
338 serves as a jump table:
339
340 @smallexample
341 static void *array[] = @{ &&foo, &&bar, &&hack @};
342 @end smallexample
343
344 @noindent
345 Then you can select a label with indexing, like this:
346
347 @smallexample
348 goto *array[i];
349 @end smallexample
350
351 @noindent
352 Note that this does not check whether the subscript is in bounds---array
353 indexing in C never does that.
354
355 Such an array of label values serves a purpose much like that of the
356 @code{switch} statement. The @code{switch} statement is cleaner, so
357 use that rather than an array unless the problem does not fit a
358 @code{switch} statement very well.
359
360 Another use of label values is in an interpreter for threaded code.
361 The labels within the interpreter function can be stored in the
362 threaded code for super-fast dispatching.
363
364 You may not use this mechanism to jump to code in a different function.
365 If you do that, totally unpredictable things happen. The best way to
366 avoid this is to store the label address only in automatic variables and
367 never pass it as an argument.
368
369 An alternate way to write the above example is
370
371 @smallexample
372 static const int array[] = @{ &&foo - &&foo, &&bar - &&foo,
373 &&hack - &&foo @};
374 goto *(&&foo + array[i]);
375 @end smallexample
376
377 @noindent
378 This is more friendly to code living in shared libraries, as it reduces
379 the number of dynamic relocations that are needed, and by consequence,
380 allows the data to be read-only.
381 This alternative with label differences is not supported for the AVR target,
382 please use the first approach for AVR programs.
383
384 The @code{&&foo} expressions for the same label might have different
385 values if the containing function is inlined or cloned. If a program
386 relies on them being always the same,
387 @code{__attribute__((__noinline__,__noclone__))} should be used to
388 prevent inlining and cloning. If @code{&&foo} is used in a static
389 variable initializer, inlining and cloning is forbidden.
390
391 @node Nested Functions
392 @section Nested Functions
393 @cindex nested functions
394 @cindex downward funargs
395 @cindex thunks
396
397 A @dfn{nested function} is a function defined inside another function.
398 Nested functions are supported as an extension in GNU C, but are not
399 supported by GNU C++.
400
401 The nested function's name is local to the block where it is defined.
402 For example, here we define a nested function named @code{square}, and
403 call it twice:
404
405 @smallexample
406 @group
407 foo (double a, double b)
408 @{
409 double square (double z) @{ return z * z; @}
410
411 return square (a) + square (b);
412 @}
413 @end group
414 @end smallexample
415
416 The nested function can access all the variables of the containing
417 function that are visible at the point of its definition. This is
418 called @dfn{lexical scoping}. For example, here we show a nested
419 function which uses an inherited variable named @code{offset}:
420
421 @smallexample
422 @group
423 bar (int *array, int offset, int size)
424 @{
425 int access (int *array, int index)
426 @{ return array[index + offset]; @}
427 int i;
428 /* @r{@dots{}} */
429 for (i = 0; i < size; i++)
430 /* @r{@dots{}} */ access (array, i) /* @r{@dots{}} */
431 @}
432 @end group
433 @end smallexample
434
435 Nested function definitions are permitted within functions in the places
436 where variable definitions are allowed; that is, in any block, mixed
437 with the other declarations and statements in the block.
438
439 It is possible to call the nested function from outside the scope of its
440 name by storing its address or passing the address to another function:
441
442 @smallexample
443 hack (int *array, int size)
444 @{
445 void store (int index, int value)
446 @{ array[index] = value; @}
447
448 intermediate (store, size);
449 @}
450 @end smallexample
451
452 Here, the function @code{intermediate} receives the address of
453 @code{store} as an argument. If @code{intermediate} calls @code{store},
454 the arguments given to @code{store} are used to store into @code{array}.
455 But this technique works only so long as the containing function
456 (@code{hack}, in this example) does not exit.
457
458 If you try to call the nested function through its address after the
459 containing function exits, all hell breaks loose. If you try
460 to call it after a containing scope level exits, and if it refers
461 to some of the variables that are no longer in scope, you may be lucky,
462 but it's not wise to take the risk. If, however, the nested function
463 does not refer to anything that has gone out of scope, you should be
464 safe.
465
466 GCC implements taking the address of a nested function using a technique
467 called @dfn{trampolines}. This technique was described in
468 @cite{Lexical Closures for C++} (Thomas M. Breuel, USENIX
469 C++ Conference Proceedings, October 17-21, 1988).
470
471 A nested function can jump to a label inherited from a containing
472 function, provided the label is explicitly declared in the containing
473 function (@pxref{Local Labels}). Such a jump returns instantly to the
474 containing function, exiting the nested function that did the
475 @code{goto} and any intermediate functions as well. Here is an example:
476
477 @smallexample
478 @group
479 bar (int *array, int offset, int size)
480 @{
481 __label__ failure;
482 int access (int *array, int index)
483 @{
484 if (index > size)
485 goto failure;
486 return array[index + offset];
487 @}
488 int i;
489 /* @r{@dots{}} */
490 for (i = 0; i < size; i++)
491 /* @r{@dots{}} */ access (array, i) /* @r{@dots{}} */
492 /* @r{@dots{}} */
493 return 0;
494
495 /* @r{Control comes here from @code{access}
496 if it detects an error.} */
497 failure:
498 return -1;
499 @}
500 @end group
501 @end smallexample
502
503 A nested function always has no linkage. Declaring one with
504 @code{extern} or @code{static} is erroneous. If you need to declare the nested function
505 before its definition, use @code{auto} (which is otherwise meaningless
506 for function declarations).
507
508 @smallexample
509 bar (int *array, int offset, int size)
510 @{
511 __label__ failure;
512 auto int access (int *, int);
513 /* @r{@dots{}} */
514 int access (int *array, int index)
515 @{
516 if (index > size)
517 goto failure;
518 return array[index + offset];
519 @}
520 /* @r{@dots{}} */
521 @}
522 @end smallexample
523
524 @node Constructing Calls
525 @section Constructing Function Calls
526 @cindex constructing calls
527 @cindex forwarding calls
528
529 Using the built-in functions described below, you can record
530 the arguments a function received, and call another function
531 with the same arguments, without knowing the number or types
532 of the arguments.
533
534 You can also record the return value of that function call,
535 and later return that value, without knowing what data type
536 the function tried to return (as long as your caller expects
537 that data type).
538
539 However, these built-in functions may interact badly with some
540 sophisticated features or other extensions of the language. It
541 is, therefore, not recommended to use them outside very simple
542 functions acting as mere forwarders for their arguments.
543
544 @deftypefn {Built-in Function} {void *} __builtin_apply_args ()
545 This built-in function returns a pointer to data
546 describing how to perform a call with the same arguments as are passed
547 to the current function.
548
549 The function saves the arg pointer register, structure value address,
550 and all registers that might be used to pass arguments to a function
551 into a block of memory allocated on the stack. Then it returns the
552 address of that block.
553 @end deftypefn
554
555 @deftypefn {Built-in Function} {void *} __builtin_apply (void (*@var{function})(), void *@var{arguments}, size_t @var{size})
556 This built-in function invokes @var{function}
557 with a copy of the parameters described by @var{arguments}
558 and @var{size}.
559
560 The value of @var{arguments} should be the value returned by
561 @code{__builtin_apply_args}. The argument @var{size} specifies the size
562 of the stack argument data, in bytes.
563
564 This function returns a pointer to data describing
565 how to return whatever value is returned by @var{function}. The data
566 is saved in a block of memory allocated on the stack.
567
568 It is not always simple to compute the proper value for @var{size}. The
569 value is used by @code{__builtin_apply} to compute the amount of data
570 that should be pushed on the stack and copied from the incoming argument
571 area.
572 @end deftypefn
573
574 @deftypefn {Built-in Function} {void} __builtin_return (void *@var{result})
575 This built-in function returns the value described by @var{result} from
576 the containing function. You should specify, for @var{result}, a value
577 returned by @code{__builtin_apply}.
578 @end deftypefn
579
580 @deftypefn {Built-in Function} {} __builtin_va_arg_pack ()
581 This built-in function represents all anonymous arguments of an inline
582 function. It can be used only in inline functions that are always
583 inlined, never compiled as a separate function, such as those using
584 @code{__attribute__ ((__always_inline__))} or
585 @code{__attribute__ ((__gnu_inline__))} extern inline functions.
586 It must be only passed as last argument to some other function
587 with variable arguments. This is useful for writing small wrapper
588 inlines for variable argument functions, when using preprocessor
589 macros is undesirable. For example:
590 @smallexample
591 extern int myprintf (FILE *f, const char *format, ...);
592 extern inline __attribute__ ((__gnu_inline__)) int
593 myprintf (FILE *f, const char *format, ...)
594 @{
595 int r = fprintf (f, "myprintf: ");
596 if (r < 0)
597 return r;
598 int s = fprintf (f, format, __builtin_va_arg_pack ());
599 if (s < 0)
600 return s;
601 return r + s;
602 @}
603 @end smallexample
604 @end deftypefn
605
606 @deftypefn {Built-in Function} {size_t} __builtin_va_arg_pack_len ()
607 This built-in function returns the number of anonymous arguments of
608 an inline function. It can be used only in inline functions that
609 are always inlined, never compiled as a separate function, such
610 as those using @code{__attribute__ ((__always_inline__))} or
611 @code{__attribute__ ((__gnu_inline__))} extern inline functions.
612 For example following does link- or run-time checking of open
613 arguments for optimized code:
614 @smallexample
615 #ifdef __OPTIMIZE__
616 extern inline __attribute__((__gnu_inline__)) int
617 myopen (const char *path, int oflag, ...)
618 @{
619 if (__builtin_va_arg_pack_len () > 1)
620 warn_open_too_many_arguments ();
621
622 if (__builtin_constant_p (oflag))
623 @{
624 if ((oflag & O_CREAT) != 0 && __builtin_va_arg_pack_len () < 1)
625 @{
626 warn_open_missing_mode ();
627 return __open_2 (path, oflag);
628 @}
629 return open (path, oflag, __builtin_va_arg_pack ());
630 @}
631
632 if (__builtin_va_arg_pack_len () < 1)
633 return __open_2 (path, oflag);
634
635 return open (path, oflag, __builtin_va_arg_pack ());
636 @}
637 #endif
638 @end smallexample
639 @end deftypefn
640
641 @node Typeof
642 @section Referring to a Type with @code{typeof}
643 @findex typeof
644 @findex sizeof
645 @cindex macros, types of arguments
646
647 Another way to refer to the type of an expression is with @code{typeof}.
648 The syntax of using of this keyword looks like @code{sizeof}, but the
649 construct acts semantically like a type name defined with @code{typedef}.
650
651 There are two ways of writing the argument to @code{typeof}: with an
652 expression or with a type. Here is an example with an expression:
653
654 @smallexample
655 typeof (x[0](1))
656 @end smallexample
657
658 @noindent
659 This assumes that @code{x} is an array of pointers to functions;
660 the type described is that of the values of the functions.
661
662 Here is an example with a typename as the argument:
663
664 @smallexample
665 typeof (int *)
666 @end smallexample
667
668 @noindent
669 Here the type described is that of pointers to @code{int}.
670
671 If you are writing a header file that must work when included in ISO C
672 programs, write @code{__typeof__} instead of @code{typeof}.
673 @xref{Alternate Keywords}.
674
675 A @code{typeof} construct can be used anywhere a typedef name can be
676 used. For example, you can use it in a declaration, in a cast, or inside
677 of @code{sizeof} or @code{typeof}.
678
679 The operand of @code{typeof} is evaluated for its side effects if and
680 only if it is an expression of variably modified type or the name of
681 such a type.
682
683 @code{typeof} is often useful in conjunction with
684 statement expressions (@pxref{Statement Exprs}).
685 Here is how the two together can
686 be used to define a safe ``maximum'' macro which operates on any
687 arithmetic type and evaluates each of its arguments exactly once:
688
689 @smallexample
690 #define max(a,b) \
691 (@{ typeof (a) _a = (a); \
692 typeof (b) _b = (b); \
693 _a > _b ? _a : _b; @})
694 @end smallexample
695
696 @cindex underscores in variables in macros
697 @cindex @samp{_} in variables in macros
698 @cindex local variables in macros
699 @cindex variables, local, in macros
700 @cindex macros, local variables in
701
702 The reason for using names that start with underscores for the local
703 variables is to avoid conflicts with variable names that occur within the
704 expressions that are substituted for @code{a} and @code{b}. Eventually we
705 hope to design a new form of declaration syntax that allows you to declare
706 variables whose scopes start only after their initializers; this will be a
707 more reliable way to prevent such conflicts.
708
709 @noindent
710 Some more examples of the use of @code{typeof}:
711
712 @itemize @bullet
713 @item
714 This declares @code{y} with the type of what @code{x} points to.
715
716 @smallexample
717 typeof (*x) y;
718 @end smallexample
719
720 @item
721 This declares @code{y} as an array of such values.
722
723 @smallexample
724 typeof (*x) y[4];
725 @end smallexample
726
727 @item
728 This declares @code{y} as an array of pointers to characters:
729
730 @smallexample
731 typeof (typeof (char *)[4]) y;
732 @end smallexample
733
734 @noindent
735 It is equivalent to the following traditional C declaration:
736
737 @smallexample
738 char *y[4];
739 @end smallexample
740
741 To see the meaning of the declaration using @code{typeof}, and why it
742 might be a useful way to write, rewrite it with these macros:
743
744 @smallexample
745 #define pointer(T) typeof(T *)
746 #define array(T, N) typeof(T [N])
747 @end smallexample
748
749 @noindent
750 Now the declaration can be rewritten this way:
751
752 @smallexample
753 array (pointer (char), 4) y;
754 @end smallexample
755
756 @noindent
757 Thus, @code{array (pointer (char), 4)} is the type of arrays of 4
758 pointers to @code{char}.
759 @end itemize
760
761 In GNU C, but not GNU C++, you may also declare the type of a variable
762 as @code{__auto_type}. In that case, the declaration must declare
763 only one variable, whose declarator must just be an identifier, the
764 declaration must be initialized, and the type of the variable is
765 determined by the initializer; the name of the variable is not in
766 scope until after the initializer. (In C++, you should use C++11
767 @code{auto} for this purpose.) Using @code{__auto_type}, the
768 ``maximum'' macro above could be written as:
769
770 @smallexample
771 #define max(a,b) \
772 (@{ __auto_type _a = (a); \
773 __auto_type _b = (b); \
774 _a > _b ? _a : _b; @})
775 @end smallexample
776
777 Using @code{__auto_type} instead of @code{typeof} has two advantages:
778
779 @itemize @bullet
780 @item Each argument to the macro appears only once in the expansion of
781 the macro. This prevents the size of the macro expansion growing
782 exponentially when calls to such macros are nested inside arguments of
783 such macros.
784
785 @item If the argument to the macro has variably modified type, it is
786 evaluated only once when using @code{__auto_type}, but twice if
787 @code{typeof} is used.
788 @end itemize
789
790 @node Conditionals
791 @section Conditionals with Omitted Operands
792 @cindex conditional expressions, extensions
793 @cindex omitted middle-operands
794 @cindex middle-operands, omitted
795 @cindex extensions, @code{?:}
796 @cindex @code{?:} extensions
797
798 The middle operand in a conditional expression may be omitted. Then
799 if the first operand is nonzero, its value is the value of the conditional
800 expression.
801
802 Therefore, the expression
803
804 @smallexample
805 x ? : y
806 @end smallexample
807
808 @noindent
809 has the value of @code{x} if that is nonzero; otherwise, the value of
810 @code{y}.
811
812 This example is perfectly equivalent to
813
814 @smallexample
815 x ? x : y
816 @end smallexample
817
818 @cindex side effect in @code{?:}
819 @cindex @code{?:} side effect
820 @noindent
821 In this simple case, the ability to omit the middle operand is not
822 especially useful. When it becomes useful is when the first operand does,
823 or may (if it is a macro argument), contain a side effect. Then repeating
824 the operand in the middle would perform the side effect twice. Omitting
825 the middle operand uses the value already computed without the undesirable
826 effects of recomputing it.
827
828 @node __int128
829 @section 128-bit Integers
830 @cindex @code{__int128} data types
831
832 As an extension the integer scalar type @code{__int128} is supported for
833 targets which have an integer mode wide enough to hold 128 bits.
834 Simply write @code{__int128} for a signed 128-bit integer, or
835 @code{unsigned __int128} for an unsigned 128-bit integer. There is no
836 support in GCC for expressing an integer constant of type @code{__int128}
837 for targets with @code{long long} integer less than 128 bits wide.
838
839 @node Long Long
840 @section Double-Word Integers
841 @cindex @code{long long} data types
842 @cindex double-word arithmetic
843 @cindex multiprecision arithmetic
844 @cindex @code{LL} integer suffix
845 @cindex @code{ULL} integer suffix
846
847 ISO C99 supports data types for integers that are at least 64 bits wide,
848 and as an extension GCC supports them in C90 mode and in C++.
849 Simply write @code{long long int} for a signed integer, or
850 @code{unsigned long long int} for an unsigned integer. To make an
851 integer constant of type @code{long long int}, add the suffix @samp{LL}
852 to the integer. To make an integer constant of type @code{unsigned long
853 long int}, add the suffix @samp{ULL} to the integer.
854
855 You can use these types in arithmetic like any other integer types.
856 Addition, subtraction, and bitwise boolean operations on these types
857 are open-coded on all types of machines. Multiplication is open-coded
858 if the machine supports a fullword-to-doubleword widening multiply
859 instruction. Division and shifts are open-coded only on machines that
860 provide special support. The operations that are not open-coded use
861 special library routines that come with GCC@.
862
863 There may be pitfalls when you use @code{long long} types for function
864 arguments without function prototypes. If a function
865 expects type @code{int} for its argument, and you pass a value of type
866 @code{long long int}, confusion results because the caller and the
867 subroutine disagree about the number of bytes for the argument.
868 Likewise, if the function expects @code{long long int} and you pass
869 @code{int}. The best way to avoid such problems is to use prototypes.
870
871 @node Complex
872 @section Complex Numbers
873 @cindex complex numbers
874 @cindex @code{_Complex} keyword
875 @cindex @code{__complex__} keyword
876
877 ISO C99 supports complex floating data types, and as an extension GCC
878 supports them in C90 mode and in C++. GCC also supports complex integer data
879 types which are not part of ISO C99. You can declare complex types
880 using the keyword @code{_Complex}. As an extension, the older GNU
881 keyword @code{__complex__} is also supported.
882
883 For example, @samp{_Complex double x;} declares @code{x} as a
884 variable whose real part and imaginary part are both of type
885 @code{double}. @samp{_Complex short int y;} declares @code{y} to
886 have real and imaginary parts of type @code{short int}; this is not
887 likely to be useful, but it shows that the set of complex types is
888 complete.
889
890 To write a constant with a complex data type, use the suffix @samp{i} or
891 @samp{j} (either one; they are equivalent). For example, @code{2.5fi}
892 has type @code{_Complex float} and @code{3i} has type
893 @code{_Complex int}. Such a constant always has a pure imaginary
894 value, but you can form any complex value you like by adding one to a
895 real constant. This is a GNU extension; if you have an ISO C99
896 conforming C library (such as the GNU C Library), and want to construct complex
897 constants of floating type, you should include @code{<complex.h>} and
898 use the macros @code{I} or @code{_Complex_I} instead.
899
900 @cindex @code{__real__} keyword
901 @cindex @code{__imag__} keyword
902 To extract the real part of a complex-valued expression @var{exp}, write
903 @code{__real__ @var{exp}}. Likewise, use @code{__imag__} to
904 extract the imaginary part. This is a GNU extension; for values of
905 floating type, you should use the ISO C99 functions @code{crealf},
906 @code{creal}, @code{creall}, @code{cimagf}, @code{cimag} and
907 @code{cimagl}, declared in @code{<complex.h>} and also provided as
908 built-in functions by GCC@.
909
910 @cindex complex conjugation
911 The operator @samp{~} performs complex conjugation when used on a value
912 with a complex type. This is a GNU extension; for values of
913 floating type, you should use the ISO C99 functions @code{conjf},
914 @code{conj} and @code{conjl}, declared in @code{<complex.h>} and also
915 provided as built-in functions by GCC@.
916
917 GCC can allocate complex automatic variables in a noncontiguous
918 fashion; it's even possible for the real part to be in a register while
919 the imaginary part is on the stack (or vice versa). Only the DWARF 2
920 debug info format can represent this, so use of DWARF 2 is recommended.
921 If you are using the stabs debug info format, GCC describes a noncontiguous
922 complex variable as if it were two separate variables of noncomplex type.
923 If the variable's actual name is @code{foo}, the two fictitious
924 variables are named @code{foo$real} and @code{foo$imag}. You can
925 examine and set these two fictitious variables with your debugger.
926
927 @node Floating Types
928 @section Additional Floating Types
929 @cindex additional floating types
930 @cindex @code{__float80} data type
931 @cindex @code{__float128} data type
932 @cindex @code{__ibm128} data type
933 @cindex @code{w} floating point suffix
934 @cindex @code{q} floating point suffix
935 @cindex @code{W} floating point suffix
936 @cindex @code{Q} floating point suffix
937
938 As an extension, GNU C supports additional floating
939 types, @code{__float80} and @code{__float128} to support 80-bit
940 (@code{XFmode}) and 128-bit (@code{TFmode}) floating types.
941 Support for additional types includes the arithmetic operators:
942 add, subtract, multiply, divide; unary arithmetic operators;
943 relational operators; equality operators; and conversions to and from
944 integer and other floating types. Use a suffix @samp{w} or @samp{W}
945 in a literal constant of type @code{__float80} or type
946 @code{__ibm128}. Use a suffix @samp{q} or @samp{Q} for @code{_float128}.
947
948 On the i386, x86_64, IA-64, and HP-UX targets, you can declare complex
949 types using the corresponding internal complex type, @code{XCmode} for
950 @code{__float80} type and @code{TCmode} for @code{__float128} type:
951
952 @smallexample
953 typedef _Complex float __attribute__((mode(TC))) _Complex128;
954 typedef _Complex float __attribute__((mode(XC))) _Complex80;
955 @end smallexample
956
957 On PowerPC Linux, Freebsd and Darwin systems, the default for
958 @code{long double} is to use the IBM extended floating point format
959 that uses a pair of @code{double} values to extend the precision.
960 This means that the mode @code{TCmode} was already used by the
961 traditional IBM long double format, and you would need to use the mode
962 @code{KCmode}:
963
964 @smallexample
965 typedef _Complex float __attribute__((mode(KC))) _Complex128;
966 @end smallexample
967
968 Not all targets support additional floating-point types. @code{__float80}
969 and @code{__float128} types are supported on x86 and IA-64 targets.
970 The @code{__float128} type is supported on hppa HP-UX.
971 The @code{__float128} type is supported on PowerPC systems by default
972 if the vector scalar instruction set (VSX) is enabled.
973
974 On the PowerPC, @code{__ibm128} provides access to the IBM extended
975 double format, and it is intended to be used by the library functions
976 that handle conversions if/when long double is changed to be IEEE
977 128-bit floating point.
978
979 @node Half-Precision
980 @section Half-Precision Floating Point
981 @cindex half-precision floating point
982 @cindex @code{__fp16} data type
983
984 On ARM targets, GCC supports half-precision (16-bit) floating point via
985 the @code{__fp16} type. You must enable this type explicitly
986 with the @option{-mfp16-format} command-line option in order to use it.
987
988 ARM supports two incompatible representations for half-precision
989 floating-point values. You must choose one of the representations and
990 use it consistently in your program.
991
992 Specifying @option{-mfp16-format=ieee} selects the IEEE 754-2008 format.
993 This format can represent normalized values in the range of @math{2^{-14}} to 65504.
994 There are 11 bits of significand precision, approximately 3
995 decimal digits.
996
997 Specifying @option{-mfp16-format=alternative} selects the ARM
998 alternative format. This representation is similar to the IEEE
999 format, but does not support infinities or NaNs. Instead, the range
1000 of exponents is extended, so that this format can represent normalized
1001 values in the range of @math{2^{-14}} to 131008.
1002
1003 The @code{__fp16} type is a storage format only. For purposes
1004 of arithmetic and other operations, @code{__fp16} values in C or C++
1005 expressions are automatically promoted to @code{float}. In addition,
1006 you cannot declare a function with a return value or parameters
1007 of type @code{__fp16}.
1008
1009 Note that conversions from @code{double} to @code{__fp16}
1010 involve an intermediate conversion to @code{float}. Because
1011 of rounding, this can sometimes produce a different result than a
1012 direct conversion.
1013
1014 ARM provides hardware support for conversions between
1015 @code{__fp16} and @code{float} values
1016 as an extension to VFP and NEON (Advanced SIMD). GCC generates
1017 code using these hardware instructions if you compile with
1018 options to select an FPU that provides them;
1019 for example, @option{-mfpu=neon-fp16 -mfloat-abi=softfp},
1020 in addition to the @option{-mfp16-format} option to select
1021 a half-precision format.
1022
1023 Language-level support for the @code{__fp16} data type is
1024 independent of whether GCC generates code using hardware floating-point
1025 instructions. In cases where hardware support is not specified, GCC
1026 implements conversions between @code{__fp16} and @code{float} values
1027 as library calls.
1028
1029 @node Decimal Float
1030 @section Decimal Floating Types
1031 @cindex decimal floating types
1032 @cindex @code{_Decimal32} data type
1033 @cindex @code{_Decimal64} data type
1034 @cindex @code{_Decimal128} data type
1035 @cindex @code{df} integer suffix
1036 @cindex @code{dd} integer suffix
1037 @cindex @code{dl} integer suffix
1038 @cindex @code{DF} integer suffix
1039 @cindex @code{DD} integer suffix
1040 @cindex @code{DL} integer suffix
1041
1042 As an extension, GNU C supports decimal floating types as
1043 defined in the N1312 draft of ISO/IEC WDTR24732. Support for decimal
1044 floating types in GCC will evolve as the draft technical report changes.
1045 Calling conventions for any target might also change. Not all targets
1046 support decimal floating types.
1047
1048 The decimal floating types are @code{_Decimal32}, @code{_Decimal64}, and
1049 @code{_Decimal128}. They use a radix of ten, unlike the floating types
1050 @code{float}, @code{double}, and @code{long double} whose radix is not
1051 specified by the C standard but is usually two.
1052
1053 Support for decimal floating types includes the arithmetic operators
1054 add, subtract, multiply, divide; unary arithmetic operators;
1055 relational operators; equality operators; and conversions to and from
1056 integer and other floating types. Use a suffix @samp{df} or
1057 @samp{DF} in a literal constant of type @code{_Decimal32}, @samp{dd}
1058 or @samp{DD} for @code{_Decimal64}, and @samp{dl} or @samp{DL} for
1059 @code{_Decimal128}.
1060
1061 GCC support of decimal float as specified by the draft technical report
1062 is incomplete:
1063
1064 @itemize @bullet
1065 @item
1066 When the value of a decimal floating type cannot be represented in the
1067 integer type to which it is being converted, the result is undefined
1068 rather than the result value specified by the draft technical report.
1069
1070 @item
1071 GCC does not provide the C library functionality associated with
1072 @file{math.h}, @file{fenv.h}, @file{stdio.h}, @file{stdlib.h}, and
1073 @file{wchar.h}, which must come from a separate C library implementation.
1074 Because of this the GNU C compiler does not define macro
1075 @code{__STDC_DEC_FP__} to indicate that the implementation conforms to
1076 the technical report.
1077 @end itemize
1078
1079 Types @code{_Decimal32}, @code{_Decimal64}, and @code{_Decimal128}
1080 are supported by the DWARF 2 debug information format.
1081
1082 @node Hex Floats
1083 @section Hex Floats
1084 @cindex hex floats
1085
1086 ISO C99 supports floating-point numbers written not only in the usual
1087 decimal notation, such as @code{1.55e1}, but also numbers such as
1088 @code{0x1.fp3} written in hexadecimal format. As a GNU extension, GCC
1089 supports this in C90 mode (except in some cases when strictly
1090 conforming) and in C++. In that format the
1091 @samp{0x} hex introducer and the @samp{p} or @samp{P} exponent field are
1092 mandatory. The exponent is a decimal number that indicates the power of
1093 2 by which the significant part is multiplied. Thus @samp{0x1.f} is
1094 @tex
1095 $1 {15\over16}$,
1096 @end tex
1097 @ifnottex
1098 1 15/16,
1099 @end ifnottex
1100 @samp{p3} multiplies it by 8, and the value of @code{0x1.fp3}
1101 is the same as @code{1.55e1}.
1102
1103 Unlike for floating-point numbers in the decimal notation the exponent
1104 is always required in the hexadecimal notation. Otherwise the compiler
1105 would not be able to resolve the ambiguity of, e.g., @code{0x1.f}. This
1106 could mean @code{1.0f} or @code{1.9375} since @samp{f} is also the
1107 extension for floating-point constants of type @code{float}.
1108
1109 @node Fixed-Point
1110 @section Fixed-Point Types
1111 @cindex fixed-point types
1112 @cindex @code{_Fract} data type
1113 @cindex @code{_Accum} data type
1114 @cindex @code{_Sat} data type
1115 @cindex @code{hr} fixed-suffix
1116 @cindex @code{r} fixed-suffix
1117 @cindex @code{lr} fixed-suffix
1118 @cindex @code{llr} fixed-suffix
1119 @cindex @code{uhr} fixed-suffix
1120 @cindex @code{ur} fixed-suffix
1121 @cindex @code{ulr} fixed-suffix
1122 @cindex @code{ullr} fixed-suffix
1123 @cindex @code{hk} fixed-suffix
1124 @cindex @code{k} fixed-suffix
1125 @cindex @code{lk} fixed-suffix
1126 @cindex @code{llk} fixed-suffix
1127 @cindex @code{uhk} fixed-suffix
1128 @cindex @code{uk} fixed-suffix
1129 @cindex @code{ulk} fixed-suffix
1130 @cindex @code{ullk} fixed-suffix
1131 @cindex @code{HR} fixed-suffix
1132 @cindex @code{R} fixed-suffix
1133 @cindex @code{LR} fixed-suffix
1134 @cindex @code{LLR} fixed-suffix
1135 @cindex @code{UHR} fixed-suffix
1136 @cindex @code{UR} fixed-suffix
1137 @cindex @code{ULR} fixed-suffix
1138 @cindex @code{ULLR} fixed-suffix
1139 @cindex @code{HK} fixed-suffix
1140 @cindex @code{K} fixed-suffix
1141 @cindex @code{LK} fixed-suffix
1142 @cindex @code{LLK} fixed-suffix
1143 @cindex @code{UHK} fixed-suffix
1144 @cindex @code{UK} fixed-suffix
1145 @cindex @code{ULK} fixed-suffix
1146 @cindex @code{ULLK} fixed-suffix
1147
1148 As an extension, GNU C supports fixed-point types as
1149 defined in the N1169 draft of ISO/IEC DTR 18037. Support for fixed-point
1150 types in GCC will evolve as the draft technical report changes.
1151 Calling conventions for any target might also change. Not all targets
1152 support fixed-point types.
1153
1154 The fixed-point types are
1155 @code{short _Fract},
1156 @code{_Fract},
1157 @code{long _Fract},
1158 @code{long long _Fract},
1159 @code{unsigned short _Fract},
1160 @code{unsigned _Fract},
1161 @code{unsigned long _Fract},
1162 @code{unsigned long long _Fract},
1163 @code{_Sat short _Fract},
1164 @code{_Sat _Fract},
1165 @code{_Sat long _Fract},
1166 @code{_Sat long long _Fract},
1167 @code{_Sat unsigned short _Fract},
1168 @code{_Sat unsigned _Fract},
1169 @code{_Sat unsigned long _Fract},
1170 @code{_Sat unsigned long long _Fract},
1171 @code{short _Accum},
1172 @code{_Accum},
1173 @code{long _Accum},
1174 @code{long long _Accum},
1175 @code{unsigned short _Accum},
1176 @code{unsigned _Accum},
1177 @code{unsigned long _Accum},
1178 @code{unsigned long long _Accum},
1179 @code{_Sat short _Accum},
1180 @code{_Sat _Accum},
1181 @code{_Sat long _Accum},
1182 @code{_Sat long long _Accum},
1183 @code{_Sat unsigned short _Accum},
1184 @code{_Sat unsigned _Accum},
1185 @code{_Sat unsigned long _Accum},
1186 @code{_Sat unsigned long long _Accum}.
1187
1188 Fixed-point data values contain fractional and optional integral parts.
1189 The format of fixed-point data varies and depends on the target machine.
1190
1191 Support for fixed-point types includes:
1192 @itemize @bullet
1193 @item
1194 prefix and postfix increment and decrement operators (@code{++}, @code{--})
1195 @item
1196 unary arithmetic operators (@code{+}, @code{-}, @code{!})
1197 @item
1198 binary arithmetic operators (@code{+}, @code{-}, @code{*}, @code{/})
1199 @item
1200 binary shift operators (@code{<<}, @code{>>})
1201 @item
1202 relational operators (@code{<}, @code{<=}, @code{>=}, @code{>})
1203 @item
1204 equality operators (@code{==}, @code{!=})
1205 @item
1206 assignment operators (@code{+=}, @code{-=}, @code{*=}, @code{/=},
1207 @code{<<=}, @code{>>=})
1208 @item
1209 conversions to and from integer, floating-point, or fixed-point types
1210 @end itemize
1211
1212 Use a suffix in a fixed-point literal constant:
1213 @itemize
1214 @item @samp{hr} or @samp{HR} for @code{short _Fract} and
1215 @code{_Sat short _Fract}
1216 @item @samp{r} or @samp{R} for @code{_Fract} and @code{_Sat _Fract}
1217 @item @samp{lr} or @samp{LR} for @code{long _Fract} and
1218 @code{_Sat long _Fract}
1219 @item @samp{llr} or @samp{LLR} for @code{long long _Fract} and
1220 @code{_Sat long long _Fract}
1221 @item @samp{uhr} or @samp{UHR} for @code{unsigned short _Fract} and
1222 @code{_Sat unsigned short _Fract}
1223 @item @samp{ur} or @samp{UR} for @code{unsigned _Fract} and
1224 @code{_Sat unsigned _Fract}
1225 @item @samp{ulr} or @samp{ULR} for @code{unsigned long _Fract} and
1226 @code{_Sat unsigned long _Fract}
1227 @item @samp{ullr} or @samp{ULLR} for @code{unsigned long long _Fract}
1228 and @code{_Sat unsigned long long _Fract}
1229 @item @samp{hk} or @samp{HK} for @code{short _Accum} and
1230 @code{_Sat short _Accum}
1231 @item @samp{k} or @samp{K} for @code{_Accum} and @code{_Sat _Accum}
1232 @item @samp{lk} or @samp{LK} for @code{long _Accum} and
1233 @code{_Sat long _Accum}
1234 @item @samp{llk} or @samp{LLK} for @code{long long _Accum} and
1235 @code{_Sat long long _Accum}
1236 @item @samp{uhk} or @samp{UHK} for @code{unsigned short _Accum} and
1237 @code{_Sat unsigned short _Accum}
1238 @item @samp{uk} or @samp{UK} for @code{unsigned _Accum} and
1239 @code{_Sat unsigned _Accum}
1240 @item @samp{ulk} or @samp{ULK} for @code{unsigned long _Accum} and
1241 @code{_Sat unsigned long _Accum}
1242 @item @samp{ullk} or @samp{ULLK} for @code{unsigned long long _Accum}
1243 and @code{_Sat unsigned long long _Accum}
1244 @end itemize
1245
1246 GCC support of fixed-point types as specified by the draft technical report
1247 is incomplete:
1248
1249 @itemize @bullet
1250 @item
1251 Pragmas to control overflow and rounding behaviors are not implemented.
1252 @end itemize
1253
1254 Fixed-point types are supported by the DWARF 2 debug information format.
1255
1256 @node Named Address Spaces
1257 @section Named Address Spaces
1258 @cindex Named Address Spaces
1259
1260 As an extension, GNU C supports named address spaces as
1261 defined in the N1275 draft of ISO/IEC DTR 18037. Support for named
1262 address spaces in GCC will evolve as the draft technical report
1263 changes. Calling conventions for any target might also change. At
1264 present, only the AVR, SPU, M32C, RL78, and x86 targets support
1265 address spaces other than the generic address space.
1266
1267 Address space identifiers may be used exactly like any other C type
1268 qualifier (e.g., @code{const} or @code{volatile}). See the N1275
1269 document for more details.
1270
1271 @anchor{AVR Named Address Spaces}
1272 @subsection AVR Named Address Spaces
1273
1274 On the AVR target, there are several address spaces that can be used
1275 in order to put read-only data into the flash memory and access that
1276 data by means of the special instructions @code{LPM} or @code{ELPM}
1277 needed to read from flash.
1278
1279 Per default, any data including read-only data is located in RAM
1280 (the generic address space) so that non-generic address spaces are
1281 needed to locate read-only data in flash memory
1282 @emph{and} to generate the right instructions to access this data
1283 without using (inline) assembler code.
1284
1285 @table @code
1286 @item __flash
1287 @cindex @code{__flash} AVR Named Address Spaces
1288 The @code{__flash} qualifier locates data in the
1289 @code{.progmem.data} section. Data is read using the @code{LPM}
1290 instruction. Pointers to this address space are 16 bits wide.
1291
1292 @item __flash1
1293 @itemx __flash2
1294 @itemx __flash3
1295 @itemx __flash4
1296 @itemx __flash5
1297 @cindex @code{__flash1} AVR Named Address Spaces
1298 @cindex @code{__flash2} AVR Named Address Spaces
1299 @cindex @code{__flash3} AVR Named Address Spaces
1300 @cindex @code{__flash4} AVR Named Address Spaces
1301 @cindex @code{__flash5} AVR Named Address Spaces
1302 These are 16-bit address spaces locating data in section
1303 @code{.progmem@var{N}.data} where @var{N} refers to
1304 address space @code{__flash@var{N}}.
1305 The compiler sets the @code{RAMPZ} segment register appropriately
1306 before reading data by means of the @code{ELPM} instruction.
1307
1308 @item __memx
1309 @cindex @code{__memx} AVR Named Address Spaces
1310 This is a 24-bit address space that linearizes flash and RAM:
1311 If the high bit of the address is set, data is read from
1312 RAM using the lower two bytes as RAM address.
1313 If the high bit of the address is clear, data is read from flash
1314 with @code{RAMPZ} set according to the high byte of the address.
1315 @xref{AVR Built-in Functions,,@code{__builtin_avr_flash_segment}}.
1316
1317 Objects in this address space are located in @code{.progmemx.data}.
1318 @end table
1319
1320 @b{Example}
1321
1322 @smallexample
1323 char my_read (const __flash char ** p)
1324 @{
1325 /* p is a pointer to RAM that points to a pointer to flash.
1326 The first indirection of p reads that flash pointer
1327 from RAM and the second indirection reads a char from this
1328 flash address. */
1329
1330 return **p;
1331 @}
1332
1333 /* Locate array[] in flash memory */
1334 const __flash int array[] = @{ 3, 5, 7, 11, 13, 17, 19 @};
1335
1336 int i = 1;
1337
1338 int main (void)
1339 @{
1340 /* Return 17 by reading from flash memory */
1341 return array[array[i]];
1342 @}
1343 @end smallexample
1344
1345 @noindent
1346 For each named address space supported by avr-gcc there is an equally
1347 named but uppercase built-in macro defined.
1348 The purpose is to facilitate testing if respective address space
1349 support is available or not:
1350
1351 @smallexample
1352 #ifdef __FLASH
1353 const __flash int var = 1;
1354
1355 int read_var (void)
1356 @{
1357 return var;
1358 @}
1359 #else
1360 #include <avr/pgmspace.h> /* From AVR-LibC */
1361
1362 const int var PROGMEM = 1;
1363
1364 int read_var (void)
1365 @{
1366 return (int) pgm_read_word (&var);
1367 @}
1368 #endif /* __FLASH */
1369 @end smallexample
1370
1371 @noindent
1372 Notice that attribute @ref{AVR Variable Attributes,,@code{progmem}}
1373 locates data in flash but
1374 accesses to these data read from generic address space, i.e.@:
1375 from RAM,
1376 so that you need special accessors like @code{pgm_read_byte}
1377 from @w{@uref{http://nongnu.org/avr-libc/user-manual/,AVR-LibC}}
1378 together with attribute @code{progmem}.
1379
1380 @noindent
1381 @b{Limitations and caveats}
1382
1383 @itemize
1384 @item
1385 Reading across the 64@tie{}KiB section boundary of
1386 the @code{__flash} or @code{__flash@var{N}} address spaces
1387 shows undefined behavior. The only address space that
1388 supports reading across the 64@tie{}KiB flash segment boundaries is
1389 @code{__memx}.
1390
1391 @item
1392 If you use one of the @code{__flash@var{N}} address spaces
1393 you must arrange your linker script to locate the
1394 @code{.progmem@var{N}.data} sections according to your needs.
1395
1396 @item
1397 Any data or pointers to the non-generic address spaces must
1398 be qualified as @code{const}, i.e.@: as read-only data.
1399 This still applies if the data in one of these address
1400 spaces like software version number or calibration lookup table are intended to
1401 be changed after load time by, say, a boot loader. In this case
1402 the right qualification is @code{const} @code{volatile} so that the compiler
1403 must not optimize away known values or insert them
1404 as immediates into operands of instructions.
1405
1406 @item
1407 The following code initializes a variable @code{pfoo}
1408 located in static storage with a 24-bit address:
1409 @smallexample
1410 extern const __memx char foo;
1411 const __memx void *pfoo = &foo;
1412 @end smallexample
1413
1414 @noindent
1415 Such code requires at least binutils 2.23, see
1416 @w{@uref{http://sourceware.org/PR13503,PR13503}}.
1417
1418 @end itemize
1419
1420 @subsection M32C Named Address Spaces
1421 @cindex @code{__far} M32C Named Address Spaces
1422
1423 On the M32C target, with the R8C and M16C CPU variants, variables
1424 qualified with @code{__far} are accessed using 32-bit addresses in
1425 order to access memory beyond the first 64@tie{}Ki bytes. If
1426 @code{__far} is used with the M32CM or M32C CPU variants, it has no
1427 effect.
1428
1429 @subsection RL78 Named Address Spaces
1430 @cindex @code{__far} RL78 Named Address Spaces
1431
1432 On the RL78 target, variables qualified with @code{__far} are accessed
1433 with 32-bit pointers (20-bit addresses) rather than the default 16-bit
1434 addresses. Non-far variables are assumed to appear in the topmost
1435 64@tie{}KiB of the address space.
1436
1437 @subsection SPU Named Address Spaces
1438 @cindex @code{__ea} SPU Named Address Spaces
1439
1440 On the SPU target variables may be declared as
1441 belonging to another address space by qualifying the type with the
1442 @code{__ea} address space identifier:
1443
1444 @smallexample
1445 extern int __ea i;
1446 @end smallexample
1447
1448 @noindent
1449 The compiler generates special code to access the variable @code{i}.
1450 It may use runtime library
1451 support, or generate special machine instructions to access that address
1452 space.
1453
1454 @subsection x86 Named Address Spaces
1455 @cindex x86 named address spaces
1456
1457 On the x86 target, variables may be declared as being relative
1458 to the @code{%fs} or @code{%gs} segments.
1459
1460 @table @code
1461 @item __seg_fs
1462 @itemx __seg_gs
1463 @cindex @code{__seg_fs} x86 named address space
1464 @cindex @code{__seg_gs} x86 named address space
1465 The object is accessed with the respective segment override prefix.
1466
1467 The respective segment base must be set via some method specific to
1468 the operating system. Rather than require an expensive system call
1469 to retrieve the segment base, these address spaces are not considered
1470 to be subspaces of the generic (flat) address space. This means that
1471 explicit casts are required to convert pointers between these address
1472 spaces and the generic address space. In practice the application
1473 should cast to @code{uintptr_t} and apply the segment base offset
1474 that it installed previously.
1475
1476 The preprocessor symbols @code{__SEG_FS} and @code{__SEG_GS} are
1477 defined when these address spaces are supported.
1478
1479 @item __seg_tls
1480 @cindex @code{__seg_tls} x86 named address space
1481 Some operating systems define either the @code{%fs} or @code{%gs}
1482 segment as the thread-local storage base for each thread. Objects
1483 within this address space are accessed with the appropriate
1484 segment override prefix.
1485
1486 The pointer located at address 0 within the segment contains the
1487 offset of the segment within the generic address space. Thus this
1488 address space is considered a subspace of the generic address space,
1489 and the known segment offset is applied when converting addresses
1490 to and from the generic address space.
1491
1492 The preprocessor symbol @code{__SEG_TLS} is defined when this
1493 address space is supported.
1494
1495 @end table
1496
1497 @node Zero Length
1498 @section Arrays of Length Zero
1499 @cindex arrays of length zero
1500 @cindex zero-length arrays
1501 @cindex length-zero arrays
1502 @cindex flexible array members
1503
1504 Zero-length arrays are allowed in GNU C@. They are very useful as the
1505 last element of a structure that is really a header for a variable-length
1506 object:
1507
1508 @smallexample
1509 struct line @{
1510 int length;
1511 char contents[0];
1512 @};
1513
1514 struct line *thisline = (struct line *)
1515 malloc (sizeof (struct line) + this_length);
1516 thisline->length = this_length;
1517 @end smallexample
1518
1519 In ISO C90, you would have to give @code{contents} a length of 1, which
1520 means either you waste space or complicate the argument to @code{malloc}.
1521
1522 In ISO C99, you would use a @dfn{flexible array member}, which is
1523 slightly different in syntax and semantics:
1524
1525 @itemize @bullet
1526 @item
1527 Flexible array members are written as @code{contents[]} without
1528 the @code{0}.
1529
1530 @item
1531 Flexible array members have incomplete type, and so the @code{sizeof}
1532 operator may not be applied. As a quirk of the original implementation
1533 of zero-length arrays, @code{sizeof} evaluates to zero.
1534
1535 @item
1536 Flexible array members may only appear as the last member of a
1537 @code{struct} that is otherwise non-empty.
1538
1539 @item
1540 A structure containing a flexible array member, or a union containing
1541 such a structure (possibly recursively), may not be a member of a
1542 structure or an element of an array. (However, these uses are
1543 permitted by GCC as extensions.)
1544 @end itemize
1545
1546 Non-empty initialization of zero-length
1547 arrays is treated like any case where there are more initializer
1548 elements than the array holds, in that a suitable warning about ``excess
1549 elements in array'' is given, and the excess elements (all of them, in
1550 this case) are ignored.
1551
1552 GCC allows static initialization of flexible array members.
1553 This is equivalent to defining a new structure containing the original
1554 structure followed by an array of sufficient size to contain the data.
1555 E.g.@: in the following, @code{f1} is constructed as if it were declared
1556 like @code{f2}.
1557
1558 @smallexample
1559 struct f1 @{
1560 int x; int y[];
1561 @} f1 = @{ 1, @{ 2, 3, 4 @} @};
1562
1563 struct f2 @{
1564 struct f1 f1; int data[3];
1565 @} f2 = @{ @{ 1 @}, @{ 2, 3, 4 @} @};
1566 @end smallexample
1567
1568 @noindent
1569 The convenience of this extension is that @code{f1} has the desired
1570 type, eliminating the need to consistently refer to @code{f2.f1}.
1571
1572 This has symmetry with normal static arrays, in that an array of
1573 unknown size is also written with @code{[]}.
1574
1575 Of course, this extension only makes sense if the extra data comes at
1576 the end of a top-level object, as otherwise we would be overwriting
1577 data at subsequent offsets. To avoid undue complication and confusion
1578 with initialization of deeply nested arrays, we simply disallow any
1579 non-empty initialization except when the structure is the top-level
1580 object. For example:
1581
1582 @smallexample
1583 struct foo @{ int x; int y[]; @};
1584 struct bar @{ struct foo z; @};
1585
1586 struct foo a = @{ 1, @{ 2, 3, 4 @} @}; // @r{Valid.}
1587 struct bar b = @{ @{ 1, @{ 2, 3, 4 @} @} @}; // @r{Invalid.}
1588 struct bar c = @{ @{ 1, @{ @} @} @}; // @r{Valid.}
1589 struct foo d[1] = @{ @{ 1, @{ 2, 3, 4 @} @} @}; // @r{Invalid.}
1590 @end smallexample
1591
1592 @node Empty Structures
1593 @section Structures with No Members
1594 @cindex empty structures
1595 @cindex zero-size structures
1596
1597 GCC permits a C structure to have no members:
1598
1599 @smallexample
1600 struct empty @{
1601 @};
1602 @end smallexample
1603
1604 The structure has size zero. In C++, empty structures are part
1605 of the language. G++ treats empty structures as if they had a single
1606 member of type @code{char}.
1607
1608 @node Variable Length
1609 @section Arrays of Variable Length
1610 @cindex variable-length arrays
1611 @cindex arrays of variable length
1612 @cindex VLAs
1613
1614 Variable-length automatic arrays are allowed in ISO C99, and as an
1615 extension GCC accepts them in C90 mode and in C++. These arrays are
1616 declared like any other automatic arrays, but with a length that is not
1617 a constant expression. The storage is allocated at the point of
1618 declaration and deallocated when the block scope containing the declaration
1619 exits. For
1620 example:
1621
1622 @smallexample
1623 FILE *
1624 concat_fopen (char *s1, char *s2, char *mode)
1625 @{
1626 char str[strlen (s1) + strlen (s2) + 1];
1627 strcpy (str, s1);
1628 strcat (str, s2);
1629 return fopen (str, mode);
1630 @}
1631 @end smallexample
1632
1633 @cindex scope of a variable length array
1634 @cindex variable-length array scope
1635 @cindex deallocating variable length arrays
1636 Jumping or breaking out of the scope of the array name deallocates the
1637 storage. Jumping into the scope is not allowed; you get an error
1638 message for it.
1639
1640 @cindex variable-length array in a structure
1641 As an extension, GCC accepts variable-length arrays as a member of
1642 a structure or a union. For example:
1643
1644 @smallexample
1645 void
1646 foo (int n)
1647 @{
1648 struct S @{ int x[n]; @};
1649 @}
1650 @end smallexample
1651
1652 @cindex @code{alloca} vs variable-length arrays
1653 You can use the function @code{alloca} to get an effect much like
1654 variable-length arrays. The function @code{alloca} is available in
1655 many other C implementations (but not in all). On the other hand,
1656 variable-length arrays are more elegant.
1657
1658 There are other differences between these two methods. Space allocated
1659 with @code{alloca} exists until the containing @emph{function} returns.
1660 The space for a variable-length array is deallocated as soon as the array
1661 name's scope ends, unless you also use @code{alloca} in this scope.
1662
1663 You can also use variable-length arrays as arguments to functions:
1664
1665 @smallexample
1666 struct entry
1667 tester (int len, char data[len][len])
1668 @{
1669 /* @r{@dots{}} */
1670 @}
1671 @end smallexample
1672
1673 The length of an array is computed once when the storage is allocated
1674 and is remembered for the scope of the array in case you access it with
1675 @code{sizeof}.
1676
1677 If you want to pass the array first and the length afterward, you can
1678 use a forward declaration in the parameter list---another GNU extension.
1679
1680 @smallexample
1681 struct entry
1682 tester (int len; char data[len][len], int len)
1683 @{
1684 /* @r{@dots{}} */
1685 @}
1686 @end smallexample
1687
1688 @cindex parameter forward declaration
1689 The @samp{int len} before the semicolon is a @dfn{parameter forward
1690 declaration}, and it serves the purpose of making the name @code{len}
1691 known when the declaration of @code{data} is parsed.
1692
1693 You can write any number of such parameter forward declarations in the
1694 parameter list. They can be separated by commas or semicolons, but the
1695 last one must end with a semicolon, which is followed by the ``real''
1696 parameter declarations. Each forward declaration must match a ``real''
1697 declaration in parameter name and data type. ISO C99 does not support
1698 parameter forward declarations.
1699
1700 @node Variadic Macros
1701 @section Macros with a Variable Number of Arguments.
1702 @cindex variable number of arguments
1703 @cindex macro with variable arguments
1704 @cindex rest argument (in macro)
1705 @cindex variadic macros
1706
1707 In the ISO C standard of 1999, a macro can be declared to accept a
1708 variable number of arguments much as a function can. The syntax for
1709 defining the macro is similar to that of a function. Here is an
1710 example:
1711
1712 @smallexample
1713 #define debug(format, ...) fprintf (stderr, format, __VA_ARGS__)
1714 @end smallexample
1715
1716 @noindent
1717 Here @samp{@dots{}} is a @dfn{variable argument}. In the invocation of
1718 such a macro, it represents the zero or more tokens until the closing
1719 parenthesis that ends the invocation, including any commas. This set of
1720 tokens replaces the identifier @code{__VA_ARGS__} in the macro body
1721 wherever it appears. See the CPP manual for more information.
1722
1723 GCC has long supported variadic macros, and used a different syntax that
1724 allowed you to give a name to the variable arguments just like any other
1725 argument. Here is an example:
1726
1727 @smallexample
1728 #define debug(format, args...) fprintf (stderr, format, args)
1729 @end smallexample
1730
1731 @noindent
1732 This is in all ways equivalent to the ISO C example above, but arguably
1733 more readable and descriptive.
1734
1735 GNU CPP has two further variadic macro extensions, and permits them to
1736 be used with either of the above forms of macro definition.
1737
1738 In standard C, you are not allowed to leave the variable argument out
1739 entirely; but you are allowed to pass an empty argument. For example,
1740 this invocation is invalid in ISO C, because there is no comma after
1741 the string:
1742
1743 @smallexample
1744 debug ("A message")
1745 @end smallexample
1746
1747 GNU CPP permits you to completely omit the variable arguments in this
1748 way. In the above examples, the compiler would complain, though since
1749 the expansion of the macro still has the extra comma after the format
1750 string.
1751
1752 To help solve this problem, CPP behaves specially for variable arguments
1753 used with the token paste operator, @samp{##}. If instead you write
1754
1755 @smallexample
1756 #define debug(format, ...) fprintf (stderr, format, ## __VA_ARGS__)
1757 @end smallexample
1758
1759 @noindent
1760 and if the variable arguments are omitted or empty, the @samp{##}
1761 operator causes the preprocessor to remove the comma before it. If you
1762 do provide some variable arguments in your macro invocation, GNU CPP
1763 does not complain about the paste operation and instead places the
1764 variable arguments after the comma. Just like any other pasted macro
1765 argument, these arguments are not macro expanded.
1766
1767 @node Escaped Newlines
1768 @section Slightly Looser Rules for Escaped Newlines
1769 @cindex escaped newlines
1770 @cindex newlines (escaped)
1771
1772 The preprocessor treatment of escaped newlines is more relaxed
1773 than that specified by the C90 standard, which requires the newline
1774 to immediately follow a backslash.
1775 GCC's implementation allows whitespace in the form
1776 of spaces, horizontal and vertical tabs, and form feeds between the
1777 backslash and the subsequent newline. The preprocessor issues a
1778 warning, but treats it as a valid escaped newline and combines the two
1779 lines to form a single logical line. This works within comments and
1780 tokens, as well as between tokens. Comments are @emph{not} treated as
1781 whitespace for the purposes of this relaxation, since they have not
1782 yet been replaced with spaces.
1783
1784 @node Subscripting
1785 @section Non-Lvalue Arrays May Have Subscripts
1786 @cindex subscripting
1787 @cindex arrays, non-lvalue
1788
1789 @cindex subscripting and function values
1790 In ISO C99, arrays that are not lvalues still decay to pointers, and
1791 may be subscripted, although they may not be modified or used after
1792 the next sequence point and the unary @samp{&} operator may not be
1793 applied to them. As an extension, GNU C allows such arrays to be
1794 subscripted in C90 mode, though otherwise they do not decay to
1795 pointers outside C99 mode. For example,
1796 this is valid in GNU C though not valid in C90:
1797
1798 @smallexample
1799 @group
1800 struct foo @{int a[4];@};
1801
1802 struct foo f();
1803
1804 bar (int index)
1805 @{
1806 return f().a[index];
1807 @}
1808 @end group
1809 @end smallexample
1810
1811 @node Pointer Arith
1812 @section Arithmetic on @code{void}- and Function-Pointers
1813 @cindex void pointers, arithmetic
1814 @cindex void, size of pointer to
1815 @cindex function pointers, arithmetic
1816 @cindex function, size of pointer to
1817
1818 In GNU C, addition and subtraction operations are supported on pointers to
1819 @code{void} and on pointers to functions. This is done by treating the
1820 size of a @code{void} or of a function as 1.
1821
1822 A consequence of this is that @code{sizeof} is also allowed on @code{void}
1823 and on function types, and returns 1.
1824
1825 @opindex Wpointer-arith
1826 The option @option{-Wpointer-arith} requests a warning if these extensions
1827 are used.
1828
1829 @node Pointers to Arrays
1830 @section Pointers to Arrays with Qualifiers Work as Expected
1831 @cindex pointers to arrays
1832 @cindex const qualifier
1833
1834 In GNU C, pointers to arrays with qualifiers work similar to pointers
1835 to other qualified types. For example, a value of type @code{int (*)[5]}
1836 can be used to initialize a variable of type @code{const int (*)[5]}.
1837 These types are incompatible in ISO C because the @code{const} qualifier
1838 is formally attached to the element type of the array and not the
1839 array itself.
1840
1841 @smallexample
1842 extern void
1843 transpose (int N, int M, double out[M][N], const double in[N][M]);
1844 double x[3][2];
1845 double y[2][3];
1846 @r{@dots{}}
1847 transpose(3, 2, y, x);
1848 @end smallexample
1849
1850 @node Initializers
1851 @section Non-Constant Initializers
1852 @cindex initializers, non-constant
1853 @cindex non-constant initializers
1854
1855 As in standard C++ and ISO C99, the elements of an aggregate initializer for an
1856 automatic variable are not required to be constant expressions in GNU C@.
1857 Here is an example of an initializer with run-time varying elements:
1858
1859 @smallexample
1860 foo (float f, float g)
1861 @{
1862 float beat_freqs[2] = @{ f-g, f+g @};
1863 /* @r{@dots{}} */
1864 @}
1865 @end smallexample
1866
1867 @node Compound Literals
1868 @section Compound Literals
1869 @cindex constructor expressions
1870 @cindex initializations in expressions
1871 @cindex structures, constructor expression
1872 @cindex expressions, constructor
1873 @cindex compound literals
1874 @c The GNU C name for what C99 calls compound literals was "constructor expressions".
1875
1876 ISO C99 supports compound literals. A compound literal looks like
1877 a cast containing an initializer. Its value is an object of the
1878 type specified in the cast, containing the elements specified in
1879 the initializer; it is an lvalue. As an extension, GCC supports
1880 compound literals in C90 mode and in C++, though the semantics are
1881 somewhat different in C++.
1882
1883 Usually, the specified type is a structure. Assume that
1884 @code{struct foo} and @code{structure} are declared as shown:
1885
1886 @smallexample
1887 struct foo @{int a; char b[2];@} structure;
1888 @end smallexample
1889
1890 @noindent
1891 Here is an example of constructing a @code{struct foo} with a compound literal:
1892
1893 @smallexample
1894 structure = ((struct foo) @{x + y, 'a', 0@});
1895 @end smallexample
1896
1897 @noindent
1898 This is equivalent to writing the following:
1899
1900 @smallexample
1901 @{
1902 struct foo temp = @{x + y, 'a', 0@};
1903 structure = temp;
1904 @}
1905 @end smallexample
1906
1907 You can also construct an array, though this is dangerous in C++, as
1908 explained below. If all the elements of the compound literal are
1909 (made up of) simple constant expressions, suitable for use in
1910 initializers of objects of static storage duration, then the compound
1911 literal can be coerced to a pointer to its first element and used in
1912 such an initializer, as shown here:
1913
1914 @smallexample
1915 char **foo = (char *[]) @{ "x", "y", "z" @};
1916 @end smallexample
1917
1918 Compound literals for scalar types and union types are
1919 also allowed, but then the compound literal is equivalent
1920 to a cast.
1921
1922 As a GNU extension, GCC allows initialization of objects with static storage
1923 duration by compound literals (which is not possible in ISO C99, because
1924 the initializer is not a constant).
1925 It is handled as if the object is initialized only with the bracket
1926 enclosed list if the types of the compound literal and the object match.
1927 The initializer list of the compound literal must be constant.
1928 If the object being initialized has array type of unknown size, the size is
1929 determined by compound literal size.
1930
1931 @smallexample
1932 static struct foo x = (struct foo) @{1, 'a', 'b'@};
1933 static int y[] = (int []) @{1, 2, 3@};
1934 static int z[] = (int [3]) @{1@};
1935 @end smallexample
1936
1937 @noindent
1938 The above lines are equivalent to the following:
1939 @smallexample
1940 static struct foo x = @{1, 'a', 'b'@};
1941 static int y[] = @{1, 2, 3@};
1942 static int z[] = @{1, 0, 0@};
1943 @end smallexample
1944
1945 In C, a compound literal designates an unnamed object with static or
1946 automatic storage duration. In C++, a compound literal designates a
1947 temporary object, which only lives until the end of its
1948 full-expression. As a result, well-defined C code that takes the
1949 address of a subobject of a compound literal can be undefined in C++,
1950 so the C++ compiler rejects the conversion of a temporary array to a pointer.
1951 For instance, if the array compound literal example above appeared
1952 inside a function, any subsequent use of @samp{foo} in C++ has
1953 undefined behavior because the lifetime of the array ends after the
1954 declaration of @samp{foo}.
1955
1956 As an optimization, the C++ compiler sometimes gives array compound
1957 literals longer lifetimes: when the array either appears outside a
1958 function or has const-qualified type. If @samp{foo} and its
1959 initializer had elements of @samp{char *const} type rather than
1960 @samp{char *}, or if @samp{foo} were a global variable, the array
1961 would have static storage duration. But it is probably safest just to
1962 avoid the use of array compound literals in code compiled as C++.
1963
1964 @node Designated Inits
1965 @section Designated Initializers
1966 @cindex initializers with labeled elements
1967 @cindex labeled elements in initializers
1968 @cindex case labels in initializers
1969 @cindex designated initializers
1970
1971 Standard C90 requires the elements of an initializer to appear in a fixed
1972 order, the same as the order of the elements in the array or structure
1973 being initialized.
1974
1975 In ISO C99 you can give the elements in any order, specifying the array
1976 indices or structure field names they apply to, and GNU C allows this as
1977 an extension in C90 mode as well. This extension is not
1978 implemented in GNU C++.
1979
1980 To specify an array index, write
1981 @samp{[@var{index}] =} before the element value. For example,
1982
1983 @smallexample
1984 int a[6] = @{ [4] = 29, [2] = 15 @};
1985 @end smallexample
1986
1987 @noindent
1988 is equivalent to
1989
1990 @smallexample
1991 int a[6] = @{ 0, 0, 15, 0, 29, 0 @};
1992 @end smallexample
1993
1994 @noindent
1995 The index values must be constant expressions, even if the array being
1996 initialized is automatic.
1997
1998 An alternative syntax for this that has been obsolete since GCC 2.5 but
1999 GCC still accepts is to write @samp{[@var{index}]} before the element
2000 value, with no @samp{=}.
2001
2002 To initialize a range of elements to the same value, write
2003 @samp{[@var{first} ... @var{last}] = @var{value}}. This is a GNU
2004 extension. For example,
2005
2006 @smallexample
2007 int widths[] = @{ [0 ... 9] = 1, [10 ... 99] = 2, [100] = 3 @};
2008 @end smallexample
2009
2010 @noindent
2011 If the value in it has side-effects, the side-effects happen only once,
2012 not for each initialized field by the range initializer.
2013
2014 @noindent
2015 Note that the length of the array is the highest value specified
2016 plus one.
2017
2018 In a structure initializer, specify the name of a field to initialize
2019 with @samp{.@var{fieldname} =} before the element value. For example,
2020 given the following structure,
2021
2022 @smallexample
2023 struct point @{ int x, y; @};
2024 @end smallexample
2025
2026 @noindent
2027 the following initialization
2028
2029 @smallexample
2030 struct point p = @{ .y = yvalue, .x = xvalue @};
2031 @end smallexample
2032
2033 @noindent
2034 is equivalent to
2035
2036 @smallexample
2037 struct point p = @{ xvalue, yvalue @};
2038 @end smallexample
2039
2040 Another syntax that has the same meaning, obsolete since GCC 2.5, is
2041 @samp{@var{fieldname}:}, as shown here:
2042
2043 @smallexample
2044 struct point p = @{ y: yvalue, x: xvalue @};
2045 @end smallexample
2046
2047 Omitted field members are implicitly initialized the same as objects
2048 that have static storage duration.
2049
2050 @cindex designators
2051 The @samp{[@var{index}]} or @samp{.@var{fieldname}} is known as a
2052 @dfn{designator}. You can also use a designator (or the obsolete colon
2053 syntax) when initializing a union, to specify which element of the union
2054 should be used. For example,
2055
2056 @smallexample
2057 union foo @{ int i; double d; @};
2058
2059 union foo f = @{ .d = 4 @};
2060 @end smallexample
2061
2062 @noindent
2063 converts 4 to a @code{double} to store it in the union using
2064 the second element. By contrast, casting 4 to type @code{union foo}
2065 stores it into the union as the integer @code{i}, since it is
2066 an integer. (@xref{Cast to Union}.)
2067
2068 You can combine this technique of naming elements with ordinary C
2069 initialization of successive elements. Each initializer element that
2070 does not have a designator applies to the next consecutive element of the
2071 array or structure. For example,
2072
2073 @smallexample
2074 int a[6] = @{ [1] = v1, v2, [4] = v4 @};
2075 @end smallexample
2076
2077 @noindent
2078 is equivalent to
2079
2080 @smallexample
2081 int a[6] = @{ 0, v1, v2, 0, v4, 0 @};
2082 @end smallexample
2083
2084 Labeling the elements of an array initializer is especially useful
2085 when the indices are characters or belong to an @code{enum} type.
2086 For example:
2087
2088 @smallexample
2089 int whitespace[256]
2090 = @{ [' '] = 1, ['\t'] = 1, ['\h'] = 1,
2091 ['\f'] = 1, ['\n'] = 1, ['\r'] = 1 @};
2092 @end smallexample
2093
2094 @cindex designator lists
2095 You can also write a series of @samp{.@var{fieldname}} and
2096 @samp{[@var{index}]} designators before an @samp{=} to specify a
2097 nested subobject to initialize; the list is taken relative to the
2098 subobject corresponding to the closest surrounding brace pair. For
2099 example, with the @samp{struct point} declaration above:
2100
2101 @smallexample
2102 struct point ptarray[10] = @{ [2].y = yv2, [2].x = xv2, [0].x = xv0 @};
2103 @end smallexample
2104
2105 @noindent
2106 If the same field is initialized multiple times, it has the value from
2107 the last initialization. If any such overridden initialization has
2108 side-effect, it is unspecified whether the side-effect happens or not.
2109 Currently, GCC discards them and issues a warning.
2110
2111 @node Case Ranges
2112 @section Case Ranges
2113 @cindex case ranges
2114 @cindex ranges in case statements
2115
2116 You can specify a range of consecutive values in a single @code{case} label,
2117 like this:
2118
2119 @smallexample
2120 case @var{low} ... @var{high}:
2121 @end smallexample
2122
2123 @noindent
2124 This has the same effect as the proper number of individual @code{case}
2125 labels, one for each integer value from @var{low} to @var{high}, inclusive.
2126
2127 This feature is especially useful for ranges of ASCII character codes:
2128
2129 @smallexample
2130 case 'A' ... 'Z':
2131 @end smallexample
2132
2133 @strong{Be careful:} Write spaces around the @code{...}, for otherwise
2134 it may be parsed wrong when you use it with integer values. For example,
2135 write this:
2136
2137 @smallexample
2138 case 1 ... 5:
2139 @end smallexample
2140
2141 @noindent
2142 rather than this:
2143
2144 @smallexample
2145 case 1...5:
2146 @end smallexample
2147
2148 @node Cast to Union
2149 @section Cast to a Union Type
2150 @cindex cast to a union
2151 @cindex union, casting to a
2152
2153 A cast to union type is similar to other casts, except that the type
2154 specified is a union type. You can specify the type either with
2155 @code{union @var{tag}} or with a typedef name. A cast to union is actually
2156 a constructor, not a cast, and hence does not yield an lvalue like
2157 normal casts. (@xref{Compound Literals}.)
2158
2159 The types that may be cast to the union type are those of the members
2160 of the union. Thus, given the following union and variables:
2161
2162 @smallexample
2163 union foo @{ int i; double d; @};
2164 int x;
2165 double y;
2166 @end smallexample
2167
2168 @noindent
2169 both @code{x} and @code{y} can be cast to type @code{union foo}.
2170
2171 Using the cast as the right-hand side of an assignment to a variable of
2172 union type is equivalent to storing in a member of the union:
2173
2174 @smallexample
2175 union foo u;
2176 /* @r{@dots{}} */
2177 u = (union foo) x @equiv{} u.i = x
2178 u = (union foo) y @equiv{} u.d = y
2179 @end smallexample
2180
2181 You can also use the union cast as a function argument:
2182
2183 @smallexample
2184 void hack (union foo);
2185 /* @r{@dots{}} */
2186 hack ((union foo) x);
2187 @end smallexample
2188
2189 @node Mixed Declarations
2190 @section Mixed Declarations and Code
2191 @cindex mixed declarations and code
2192 @cindex declarations, mixed with code
2193 @cindex code, mixed with declarations
2194
2195 ISO C99 and ISO C++ allow declarations and code to be freely mixed
2196 within compound statements. As an extension, GNU C also allows this in
2197 C90 mode. For example, you could do:
2198
2199 @smallexample
2200 int i;
2201 /* @r{@dots{}} */
2202 i++;
2203 int j = i + 2;
2204 @end smallexample
2205
2206 Each identifier is visible from where it is declared until the end of
2207 the enclosing block.
2208
2209 @node Function Attributes
2210 @section Declaring Attributes of Functions
2211 @cindex function attributes
2212 @cindex declaring attributes of functions
2213 @cindex @code{volatile} applied to function
2214 @cindex @code{const} applied to function
2215
2216 In GNU C, you can use function attributes to declare certain things
2217 about functions called in your program which help the compiler
2218 optimize calls and check your code more carefully. For example, you
2219 can use attributes to declare that a function never returns
2220 (@code{noreturn}), returns a value depending only on its arguments
2221 (@code{pure}), or has @code{printf}-style arguments (@code{format}).
2222
2223 You can also use attributes to control memory placement, code
2224 generation options or call/return conventions within the function
2225 being annotated. Many of these attributes are target-specific. For
2226 example, many targets support attributes for defining interrupt
2227 handler functions, which typically must follow special register usage
2228 and return conventions.
2229
2230 Function attributes are introduced by the @code{__attribute__} keyword
2231 on a declaration, followed by an attribute specification inside double
2232 parentheses. You can specify multiple attributes in a declaration by
2233 separating them by commas within the double parentheses or by
2234 immediately following an attribute declaration with another attribute
2235 declaration. @xref{Attribute Syntax}, for the exact rules on
2236 attribute syntax and placement.
2237
2238 GCC also supports attributes on
2239 variable declarations (@pxref{Variable Attributes}),
2240 labels (@pxref{Label Attributes}),
2241 enumerators (@pxref{Enumerator Attributes}),
2242 and types (@pxref{Type Attributes}).
2243
2244 There is some overlap between the purposes of attributes and pragmas
2245 (@pxref{Pragmas,,Pragmas Accepted by GCC}). It has been
2246 found convenient to use @code{__attribute__} to achieve a natural
2247 attachment of attributes to their corresponding declarations, whereas
2248 @code{#pragma} is of use for compatibility with other compilers
2249 or constructs that do not naturally form part of the grammar.
2250
2251 In addition to the attributes documented here,
2252 GCC plugins may provide their own attributes.
2253
2254 @menu
2255 * Common Function Attributes::
2256 * AArch64 Function Attributes::
2257 * ARC Function Attributes::
2258 * ARM Function Attributes::
2259 * AVR Function Attributes::
2260 * Blackfin Function Attributes::
2261 * CR16 Function Attributes::
2262 * Epiphany Function Attributes::
2263 * H8/300 Function Attributes::
2264 * IA-64 Function Attributes::
2265 * M32C Function Attributes::
2266 * M32R/D Function Attributes::
2267 * m68k Function Attributes::
2268 * MCORE Function Attributes::
2269 * MeP Function Attributes::
2270 * MicroBlaze Function Attributes::
2271 * Microsoft Windows Function Attributes::
2272 * MIPS Function Attributes::
2273 * MSP430 Function Attributes::
2274 * NDS32 Function Attributes::
2275 * Nios II Function Attributes::
2276 * PowerPC Function Attributes::
2277 * RL78 Function Attributes::
2278 * RX Function Attributes::
2279 * S/390 Function Attributes::
2280 * SH Function Attributes::
2281 * SPU Function Attributes::
2282 * Symbian OS Function Attributes::
2283 * Visium Function Attributes::
2284 * x86 Function Attributes::
2285 * Xstormy16 Function Attributes::
2286 @end menu
2287
2288 @node Common Function Attributes
2289 @subsection Common Function Attributes
2290
2291 The following attributes are supported on most targets.
2292
2293 @table @code
2294 @c Keep this table alphabetized by attribute name. Treat _ as space.
2295
2296 @item alias ("@var{target}")
2297 @cindex @code{alias} function attribute
2298 The @code{alias} attribute causes the declaration to be emitted as an
2299 alias for another symbol, which must be specified. For instance,
2300
2301 @smallexample
2302 void __f () @{ /* @r{Do something.} */; @}
2303 void f () __attribute__ ((weak, alias ("__f")));
2304 @end smallexample
2305
2306 @noindent
2307 defines @samp{f} to be a weak alias for @samp{__f}. In C++, the
2308 mangled name for the target must be used. It is an error if @samp{__f}
2309 is not defined in the same translation unit.
2310
2311 This attribute requires assembler and object file support,
2312 and may not be available on all targets.
2313
2314 @item aligned (@var{alignment})
2315 @cindex @code{aligned} function attribute
2316 This attribute specifies a minimum alignment for the function,
2317 measured in bytes.
2318
2319 You cannot use this attribute to decrease the alignment of a function,
2320 only to increase it. However, when you explicitly specify a function
2321 alignment this overrides the effect of the
2322 @option{-falign-functions} (@pxref{Optimize Options}) option for this
2323 function.
2324
2325 Note that the effectiveness of @code{aligned} attributes may be
2326 limited by inherent limitations in your linker. On many systems, the
2327 linker is only able to arrange for functions to be aligned up to a
2328 certain maximum alignment. (For some linkers, the maximum supported
2329 alignment may be very very small.) See your linker documentation for
2330 further information.
2331
2332 The @code{aligned} attribute can also be used for variables and fields
2333 (@pxref{Variable Attributes}.)
2334
2335 @item alloc_align
2336 @cindex @code{alloc_align} function attribute
2337 The @code{alloc_align} attribute is used to tell the compiler that the
2338 function return value points to memory, where the returned pointer minimum
2339 alignment is given by one of the functions parameters. GCC uses this
2340 information to improve pointer alignment analysis.
2341
2342 The function parameter denoting the allocated alignment is specified by
2343 one integer argument, whose number is the argument of the attribute.
2344 Argument numbering starts at one.
2345
2346 For instance,
2347
2348 @smallexample
2349 void* my_memalign(size_t, size_t) __attribute__((alloc_align(1)))
2350 @end smallexample
2351
2352 @noindent
2353 declares that @code{my_memalign} returns memory with minimum alignment
2354 given by parameter 1.
2355
2356 @item alloc_size
2357 @cindex @code{alloc_size} function attribute
2358 The @code{alloc_size} attribute is used to tell the compiler that the
2359 function return value points to memory, where the size is given by
2360 one or two of the functions parameters. GCC uses this
2361 information to improve the correctness of @code{__builtin_object_size}.
2362
2363 The function parameter(s) denoting the allocated size are specified by
2364 one or two integer arguments supplied to the attribute. The allocated size
2365 is either the value of the single function argument specified or the product
2366 of the two function arguments specified. Argument numbering starts at
2367 one.
2368
2369 For instance,
2370
2371 @smallexample
2372 void* my_calloc(size_t, size_t) __attribute__((alloc_size(1,2)))
2373 void* my_realloc(void*, size_t) __attribute__((alloc_size(2)))
2374 @end smallexample
2375
2376 @noindent
2377 declares that @code{my_calloc} returns memory of the size given by
2378 the product of parameter 1 and 2 and that @code{my_realloc} returns memory
2379 of the size given by parameter 2.
2380
2381 @item always_inline
2382 @cindex @code{always_inline} function attribute
2383 Generally, functions are not inlined unless optimization is specified.
2384 For functions declared inline, this attribute inlines the function
2385 independent of any restrictions that otherwise apply to inlining.
2386 Failure to inline such a function is diagnosed as an error.
2387 Note that if such a function is called indirectly the compiler may
2388 or may not inline it depending on optimization level and a failure
2389 to inline an indirect call may or may not be diagnosed.
2390
2391 @item artificial
2392 @cindex @code{artificial} function attribute
2393 This attribute is useful for small inline wrappers that if possible
2394 should appear during debugging as a unit. Depending on the debug
2395 info format it either means marking the function as artificial
2396 or using the caller location for all instructions within the inlined
2397 body.
2398
2399 @item assume_aligned
2400 @cindex @code{assume_aligned} function attribute
2401 The @code{assume_aligned} attribute is used to tell the compiler that the
2402 function return value points to memory, where the returned pointer minimum
2403 alignment is given by the first argument.
2404 If the attribute has two arguments, the second argument is misalignment offset.
2405
2406 For instance
2407
2408 @smallexample
2409 void* my_alloc1(size_t) __attribute__((assume_aligned(16)))
2410 void* my_alloc2(size_t) __attribute__((assume_aligned(32, 8)))
2411 @end smallexample
2412
2413 @noindent
2414 declares that @code{my_alloc1} returns 16-byte aligned pointer and
2415 that @code{my_alloc2} returns a pointer whose value modulo 32 is equal
2416 to 8.
2417
2418 @item bnd_instrument
2419 @cindex @code{bnd_instrument} function attribute
2420 The @code{bnd_instrument} attribute on functions is used to inform the
2421 compiler that the function should be instrumented when compiled
2422 with the @option{-fchkp-instrument-marked-only} option.
2423
2424 @item bnd_legacy
2425 @cindex @code{bnd_legacy} function attribute
2426 @cindex Pointer Bounds Checker attributes
2427 The @code{bnd_legacy} attribute on functions is used to inform the
2428 compiler that the function should not be instrumented when compiled
2429 with the @option{-fcheck-pointer-bounds} option.
2430
2431 @item cold
2432 @cindex @code{cold} function attribute
2433 The @code{cold} attribute on functions is used to inform the compiler that
2434 the function is unlikely to be executed. The function is optimized for
2435 size rather than speed and on many targets it is placed into a special
2436 subsection of the text section so all cold functions appear close together,
2437 improving code locality of non-cold parts of program. The paths leading
2438 to calls of cold functions within code are marked as unlikely by the branch
2439 prediction mechanism. It is thus useful to mark functions used to handle
2440 unlikely conditions, such as @code{perror}, as cold to improve optimization
2441 of hot functions that do call marked functions in rare occasions.
2442
2443 When profile feedback is available, via @option{-fprofile-use}, cold functions
2444 are automatically detected and this attribute is ignored.
2445
2446 @item const
2447 @cindex @code{const} function attribute
2448 @cindex functions that have no side effects
2449 Many functions do not examine any values except their arguments, and
2450 have no effects except the return value. Basically this is just slightly
2451 more strict class than the @code{pure} attribute below, since function is not
2452 allowed to read global memory.
2453
2454 @cindex pointer arguments
2455 Note that a function that has pointer arguments and examines the data
2456 pointed to must @emph{not} be declared @code{const}. Likewise, a
2457 function that calls a non-@code{const} function usually must not be
2458 @code{const}. It does not make sense for a @code{const} function to
2459 return @code{void}.
2460
2461 @item constructor
2462 @itemx destructor
2463 @itemx constructor (@var{priority})
2464 @itemx destructor (@var{priority})
2465 @cindex @code{constructor} function attribute
2466 @cindex @code{destructor} function attribute
2467 The @code{constructor} attribute causes the function to be called
2468 automatically before execution enters @code{main ()}. Similarly, the
2469 @code{destructor} attribute causes the function to be called
2470 automatically after @code{main ()} completes or @code{exit ()} is
2471 called. Functions with these attributes are useful for
2472 initializing data that is used implicitly during the execution of
2473 the program.
2474
2475 You may provide an optional integer priority to control the order in
2476 which constructor and destructor functions are run. A constructor
2477 with a smaller priority number runs before a constructor with a larger
2478 priority number; the opposite relationship holds for destructors. So,
2479 if you have a constructor that allocates a resource and a destructor
2480 that deallocates the same resource, both functions typically have the
2481 same priority. The priorities for constructor and destructor
2482 functions are the same as those specified for namespace-scope C++
2483 objects (@pxref{C++ Attributes}).
2484
2485 These attributes are not currently implemented for Objective-C@.
2486
2487 @item deprecated
2488 @itemx deprecated (@var{msg})
2489 @cindex @code{deprecated} function attribute
2490 The @code{deprecated} attribute results in a warning if the function
2491 is used anywhere in the source file. This is useful when identifying
2492 functions that are expected to be removed in a future version of a
2493 program. The warning also includes the location of the declaration
2494 of the deprecated function, to enable users to easily find further
2495 information about why the function is deprecated, or what they should
2496 do instead. Note that the warnings only occurs for uses:
2497
2498 @smallexample
2499 int old_fn () __attribute__ ((deprecated));
2500 int old_fn ();
2501 int (*fn_ptr)() = old_fn;
2502 @end smallexample
2503
2504 @noindent
2505 results in a warning on line 3 but not line 2. The optional @var{msg}
2506 argument, which must be a string, is printed in the warning if
2507 present.
2508
2509 The @code{deprecated} attribute can also be used for variables and
2510 types (@pxref{Variable Attributes}, @pxref{Type Attributes}.)
2511
2512 @item error ("@var{message}")
2513 @itemx warning ("@var{message}")
2514 @cindex @code{error} function attribute
2515 @cindex @code{warning} function attribute
2516 If the @code{error} or @code{warning} attribute
2517 is used on a function declaration and a call to such a function
2518 is not eliminated through dead code elimination or other optimizations,
2519 an error or warning (respectively) that includes @var{message} is diagnosed.
2520 This is useful
2521 for compile-time checking, especially together with @code{__builtin_constant_p}
2522 and inline functions where checking the inline function arguments is not
2523 possible through @code{extern char [(condition) ? 1 : -1];} tricks.
2524
2525 While it is possible to leave the function undefined and thus invoke
2526 a link failure (to define the function with
2527 a message in @code{.gnu.warning*} section),
2528 when using these attributes the problem is diagnosed
2529 earlier and with exact location of the call even in presence of inline
2530 functions or when not emitting debugging information.
2531
2532 @item externally_visible
2533 @cindex @code{externally_visible} function attribute
2534 This attribute, attached to a global variable or function, nullifies
2535 the effect of the @option{-fwhole-program} command-line option, so the
2536 object remains visible outside the current compilation unit.
2537
2538 If @option{-fwhole-program} is used together with @option{-flto} and
2539 @command{gold} is used as the linker plugin,
2540 @code{externally_visible} attributes are automatically added to functions
2541 (not variable yet due to a current @command{gold} issue)
2542 that are accessed outside of LTO objects according to resolution file
2543 produced by @command{gold}.
2544 For other linkers that cannot generate resolution file,
2545 explicit @code{externally_visible} attributes are still necessary.
2546
2547 @item flatten
2548 @cindex @code{flatten} function attribute
2549 Generally, inlining into a function is limited. For a function marked with
2550 this attribute, every call inside this function is inlined, if possible.
2551 Whether the function itself is considered for inlining depends on its size and
2552 the current inlining parameters.
2553
2554 @item format (@var{archetype}, @var{string-index}, @var{first-to-check})
2555 @cindex @code{format} function attribute
2556 @cindex functions with @code{printf}, @code{scanf}, @code{strftime} or @code{strfmon} style arguments
2557 @opindex Wformat
2558 The @code{format} attribute specifies that a function takes @code{printf},
2559 @code{scanf}, @code{strftime} or @code{strfmon} style arguments that
2560 should be type-checked against a format string. For example, the
2561 declaration:
2562
2563 @smallexample
2564 extern int
2565 my_printf (void *my_object, const char *my_format, ...)
2566 __attribute__ ((format (printf, 2, 3)));
2567 @end smallexample
2568
2569 @noindent
2570 causes the compiler to check the arguments in calls to @code{my_printf}
2571 for consistency with the @code{printf} style format string argument
2572 @code{my_format}.
2573
2574 The parameter @var{archetype} determines how the format string is
2575 interpreted, and should be @code{printf}, @code{scanf}, @code{strftime},
2576 @code{gnu_printf}, @code{gnu_scanf}, @code{gnu_strftime} or
2577 @code{strfmon}. (You can also use @code{__printf__},
2578 @code{__scanf__}, @code{__strftime__} or @code{__strfmon__}.) On
2579 MinGW targets, @code{ms_printf}, @code{ms_scanf}, and
2580 @code{ms_strftime} are also present.
2581 @var{archetype} values such as @code{printf} refer to the formats accepted
2582 by the system's C runtime library,
2583 while values prefixed with @samp{gnu_} always refer
2584 to the formats accepted by the GNU C Library. On Microsoft Windows
2585 targets, values prefixed with @samp{ms_} refer to the formats accepted by the
2586 @file{msvcrt.dll} library.
2587 The parameter @var{string-index}
2588 specifies which argument is the format string argument (starting
2589 from 1), while @var{first-to-check} is the number of the first
2590 argument to check against the format string. For functions
2591 where the arguments are not available to be checked (such as
2592 @code{vprintf}), specify the third parameter as zero. In this case the
2593 compiler only checks the format string for consistency. For
2594 @code{strftime} formats, the third parameter is required to be zero.
2595 Since non-static C++ methods have an implicit @code{this} argument, the
2596 arguments of such methods should be counted from two, not one, when
2597 giving values for @var{string-index} and @var{first-to-check}.
2598
2599 In the example above, the format string (@code{my_format}) is the second
2600 argument of the function @code{my_print}, and the arguments to check
2601 start with the third argument, so the correct parameters for the format
2602 attribute are 2 and 3.
2603
2604 @opindex ffreestanding
2605 @opindex fno-builtin
2606 The @code{format} attribute allows you to identify your own functions
2607 that take format strings as arguments, so that GCC can check the
2608 calls to these functions for errors. The compiler always (unless
2609 @option{-ffreestanding} or @option{-fno-builtin} is used) checks formats
2610 for the standard library functions @code{printf}, @code{fprintf},
2611 @code{sprintf}, @code{scanf}, @code{fscanf}, @code{sscanf}, @code{strftime},
2612 @code{vprintf}, @code{vfprintf} and @code{vsprintf} whenever such
2613 warnings are requested (using @option{-Wformat}), so there is no need to
2614 modify the header file @file{stdio.h}. In C99 mode, the functions
2615 @code{snprintf}, @code{vsnprintf}, @code{vscanf}, @code{vfscanf} and
2616 @code{vsscanf} are also checked. Except in strictly conforming C
2617 standard modes, the X/Open function @code{strfmon} is also checked as
2618 are @code{printf_unlocked} and @code{fprintf_unlocked}.
2619 @xref{C Dialect Options,,Options Controlling C Dialect}.
2620
2621 For Objective-C dialects, @code{NSString} (or @code{__NSString__}) is
2622 recognized in the same context. Declarations including these format attributes
2623 are parsed for correct syntax, however the result of checking of such format
2624 strings is not yet defined, and is not carried out by this version of the
2625 compiler.
2626
2627 The target may also provide additional types of format checks.
2628 @xref{Target Format Checks,,Format Checks Specific to Particular
2629 Target Machines}.
2630
2631 @item format_arg (@var{string-index})
2632 @cindex @code{format_arg} function attribute
2633 @opindex Wformat-nonliteral
2634 The @code{format_arg} attribute specifies that a function takes a format
2635 string for a @code{printf}, @code{scanf}, @code{strftime} or
2636 @code{strfmon} style function and modifies it (for example, to translate
2637 it into another language), so the result can be passed to a
2638 @code{printf}, @code{scanf}, @code{strftime} or @code{strfmon} style
2639 function (with the remaining arguments to the format function the same
2640 as they would have been for the unmodified string). For example, the
2641 declaration:
2642
2643 @smallexample
2644 extern char *
2645 my_dgettext (char *my_domain, const char *my_format)
2646 __attribute__ ((format_arg (2)));
2647 @end smallexample
2648
2649 @noindent
2650 causes the compiler to check the arguments in calls to a @code{printf},
2651 @code{scanf}, @code{strftime} or @code{strfmon} type function, whose
2652 format string argument is a call to the @code{my_dgettext} function, for
2653 consistency with the format string argument @code{my_format}. If the
2654 @code{format_arg} attribute had not been specified, all the compiler
2655 could tell in such calls to format functions would be that the format
2656 string argument is not constant; this would generate a warning when
2657 @option{-Wformat-nonliteral} is used, but the calls could not be checked
2658 without the attribute.
2659
2660 The parameter @var{string-index} specifies which argument is the format
2661 string argument (starting from one). Since non-static C++ methods have
2662 an implicit @code{this} argument, the arguments of such methods should
2663 be counted from two.
2664
2665 The @code{format_arg} attribute allows you to identify your own
2666 functions that modify format strings, so that GCC can check the
2667 calls to @code{printf}, @code{scanf}, @code{strftime} or @code{strfmon}
2668 type function whose operands are a call to one of your own function.
2669 The compiler always treats @code{gettext}, @code{dgettext}, and
2670 @code{dcgettext} in this manner except when strict ISO C support is
2671 requested by @option{-ansi} or an appropriate @option{-std} option, or
2672 @option{-ffreestanding} or @option{-fno-builtin}
2673 is used. @xref{C Dialect Options,,Options
2674 Controlling C Dialect}.
2675
2676 For Objective-C dialects, the @code{format-arg} attribute may refer to an
2677 @code{NSString} reference for compatibility with the @code{format} attribute
2678 above.
2679
2680 The target may also allow additional types in @code{format-arg} attributes.
2681 @xref{Target Format Checks,,Format Checks Specific to Particular
2682 Target Machines}.
2683
2684 @item gnu_inline
2685 @cindex @code{gnu_inline} function attribute
2686 This attribute should be used with a function that is also declared
2687 with the @code{inline} keyword. It directs GCC to treat the function
2688 as if it were defined in gnu90 mode even when compiling in C99 or
2689 gnu99 mode.
2690
2691 If the function is declared @code{extern}, then this definition of the
2692 function is used only for inlining. In no case is the function
2693 compiled as a standalone function, not even if you take its address
2694 explicitly. Such an address becomes an external reference, as if you
2695 had only declared the function, and had not defined it. This has
2696 almost the effect of a macro. The way to use this is to put a
2697 function definition in a header file with this attribute, and put
2698 another copy of the function, without @code{extern}, in a library
2699 file. The definition in the header file causes most calls to the
2700 function to be inlined. If any uses of the function remain, they
2701 refer to the single copy in the library. Note that the two
2702 definitions of the functions need not be precisely the same, although
2703 if they do not have the same effect your program may behave oddly.
2704
2705 In C, if the function is neither @code{extern} nor @code{static}, then
2706 the function is compiled as a standalone function, as well as being
2707 inlined where possible.
2708
2709 This is how GCC traditionally handled functions declared
2710 @code{inline}. Since ISO C99 specifies a different semantics for
2711 @code{inline}, this function attribute is provided as a transition
2712 measure and as a useful feature in its own right. This attribute is
2713 available in GCC 4.1.3 and later. It is available if either of the
2714 preprocessor macros @code{__GNUC_GNU_INLINE__} or
2715 @code{__GNUC_STDC_INLINE__} are defined. @xref{Inline,,An Inline
2716 Function is As Fast As a Macro}.
2717
2718 In C++, this attribute does not depend on @code{extern} in any way,
2719 but it still requires the @code{inline} keyword to enable its special
2720 behavior.
2721
2722 @item hot
2723 @cindex @code{hot} function attribute
2724 The @code{hot} attribute on a function is used to inform the compiler that
2725 the function is a hot spot of the compiled program. The function is
2726 optimized more aggressively and on many targets it is placed into a special
2727 subsection of the text section so all hot functions appear close together,
2728 improving locality.
2729
2730 When profile feedback is available, via @option{-fprofile-use}, hot functions
2731 are automatically detected and this attribute is ignored.
2732
2733 @item ifunc ("@var{resolver}")
2734 @cindex @code{ifunc} function attribute
2735 @cindex indirect functions
2736 @cindex functions that are dynamically resolved
2737 The @code{ifunc} attribute is used to mark a function as an indirect
2738 function using the STT_GNU_IFUNC symbol type extension to the ELF
2739 standard. This allows the resolution of the symbol value to be
2740 determined dynamically at load time, and an optimized version of the
2741 routine can be selected for the particular processor or other system
2742 characteristics determined then. To use this attribute, first define
2743 the implementation functions available, and a resolver function that
2744 returns a pointer to the selected implementation function. The
2745 implementation functions' declarations must match the API of the
2746 function being implemented, the resolver's declaration is be a
2747 function returning pointer to void function returning void:
2748
2749 @smallexample
2750 void *my_memcpy (void *dst, const void *src, size_t len)
2751 @{
2752 @dots{}
2753 @}
2754
2755 static void (*resolve_memcpy (void)) (void)
2756 @{
2757 return my_memcpy; // we'll just always select this routine
2758 @}
2759 @end smallexample
2760
2761 @noindent
2762 The exported header file declaring the function the user calls would
2763 contain:
2764
2765 @smallexample
2766 extern void *memcpy (void *, const void *, size_t);
2767 @end smallexample
2768
2769 @noindent
2770 allowing the user to call this as a regular function, unaware of the
2771 implementation. Finally, the indirect function needs to be defined in
2772 the same translation unit as the resolver function:
2773
2774 @smallexample
2775 void *memcpy (void *, const void *, size_t)
2776 __attribute__ ((ifunc ("resolve_memcpy")));
2777 @end smallexample
2778
2779 Indirect functions cannot be weak. Binutils version 2.20.1 or higher
2780 and GNU C Library version 2.11.1 are required to use this feature.
2781
2782 @item interrupt
2783 @itemx interrupt_handler
2784 Many GCC back ends support attributes to indicate that a function is
2785 an interrupt handler, which tells the compiler to generate function
2786 entry and exit sequences that differ from those from regular
2787 functions. The exact syntax and behavior are target-specific;
2788 refer to the following subsections for details.
2789
2790 @item leaf
2791 @cindex @code{leaf} function attribute
2792 Calls to external functions with this attribute must return to the current
2793 compilation unit only by return or by exception handling. In particular, leaf
2794 functions are not allowed to call callback function passed to it from the current
2795 compilation unit or directly call functions exported by the unit or longjmp
2796 into the unit. Leaf function might still call functions from other compilation
2797 units and thus they are not necessarily leaf in the sense that they contain no
2798 function calls at all.
2799
2800 The attribute is intended for library functions to improve dataflow analysis.
2801 The compiler takes the hint that any data not escaping the current compilation unit can
2802 not be used or modified by the leaf function. For example, the @code{sin} function
2803 is a leaf function, but @code{qsort} is not.
2804
2805 Note that leaf functions might invoke signals and signal handlers might be
2806 defined in the current compilation unit and use static variables. The only
2807 compliant way to write such a signal handler is to declare such variables
2808 @code{volatile}.
2809
2810 The attribute has no effect on functions defined within the current compilation
2811 unit. This is to allow easy merging of multiple compilation units into one,
2812 for example, by using the link-time optimization. For this reason the
2813 attribute is not allowed on types to annotate indirect calls.
2814
2815
2816 @item malloc
2817 @cindex @code{malloc} function attribute
2818 @cindex functions that behave like malloc
2819 This tells the compiler that a function is @code{malloc}-like, i.e.,
2820 that the pointer @var{P} returned by the function cannot alias any
2821 other pointer valid when the function returns, and moreover no
2822 pointers to valid objects occur in any storage addressed by @var{P}.
2823
2824 Using this attribute can improve optimization. Functions like
2825 @code{malloc} and @code{calloc} have this property because they return
2826 a pointer to uninitialized or zeroed-out storage. However, functions
2827 like @code{realloc} do not have this property, as they can return a
2828 pointer to storage containing pointers.
2829
2830 @item no_icf
2831 @cindex @code{no_icf} function attribute
2832 This function attribute prevents a functions from being merged with another
2833 semantically equivalent function.
2834
2835 @item no_instrument_function
2836 @cindex @code{no_instrument_function} function attribute
2837 @opindex finstrument-functions
2838 If @option{-finstrument-functions} is given, profiling function calls are
2839 generated at entry and exit of most user-compiled functions.
2840 Functions with this attribute are not so instrumented.
2841
2842 @item no_reorder
2843 @cindex @code{no_reorder} function attribute
2844 Do not reorder functions or variables marked @code{no_reorder}
2845 against each other or top level assembler statements the executable.
2846 The actual order in the program will depend on the linker command
2847 line. Static variables marked like this are also not removed.
2848 This has a similar effect
2849 as the @option{-fno-toplevel-reorder} option, but only applies to the
2850 marked symbols.
2851
2852 @item no_sanitize_address
2853 @itemx no_address_safety_analysis
2854 @cindex @code{no_sanitize_address} function attribute
2855 The @code{no_sanitize_address} attribute on functions is used
2856 to inform the compiler that it should not instrument memory accesses
2857 in the function when compiling with the @option{-fsanitize=address} option.
2858 The @code{no_address_safety_analysis} is a deprecated alias of the
2859 @code{no_sanitize_address} attribute, new code should use
2860 @code{no_sanitize_address}.
2861
2862 @item no_sanitize_thread
2863 @cindex @code{no_sanitize_thread} function attribute
2864 The @code{no_sanitize_thread} attribute on functions is used
2865 to inform the compiler that it should not instrument memory accesses
2866 in the function when compiling with the @option{-fsanitize=thread} option.
2867
2868 @item no_sanitize_undefined
2869 @cindex @code{no_sanitize_undefined} function attribute
2870 The @code{no_sanitize_undefined} attribute on functions is used
2871 to inform the compiler that it should not check for undefined behavior
2872 in the function when compiling with the @option{-fsanitize=undefined} option.
2873
2874 @item no_split_stack
2875 @cindex @code{no_split_stack} function attribute
2876 @opindex fsplit-stack
2877 If @option{-fsplit-stack} is given, functions have a small
2878 prologue which decides whether to split the stack. Functions with the
2879 @code{no_split_stack} attribute do not have that prologue, and thus
2880 may run with only a small amount of stack space available.
2881
2882 @item noclone
2883 @cindex @code{noclone} function attribute
2884 This function attribute prevents a function from being considered for
2885 cloning---a mechanism that produces specialized copies of functions
2886 and which is (currently) performed by interprocedural constant
2887 propagation.
2888
2889 @item noinline
2890 @cindex @code{noinline} function attribute
2891 This function attribute prevents a function from being considered for
2892 inlining.
2893 @c Don't enumerate the optimizations by name here; we try to be
2894 @c future-compatible with this mechanism.
2895 If the function does not have side-effects, there are optimizations
2896 other than inlining that cause function calls to be optimized away,
2897 although the function call is live. To keep such calls from being
2898 optimized away, put
2899 @smallexample
2900 asm ("");
2901 @end smallexample
2902
2903 @noindent
2904 (@pxref{Extended Asm}) in the called function, to serve as a special
2905 side-effect.
2906
2907 @item nonnull (@var{arg-index}, @dots{})
2908 @cindex @code{nonnull} function attribute
2909 @cindex functions with non-null pointer arguments
2910 The @code{nonnull} attribute specifies that some function parameters should
2911 be non-null pointers. For instance, the declaration:
2912
2913 @smallexample
2914 extern void *
2915 my_memcpy (void *dest, const void *src, size_t len)
2916 __attribute__((nonnull (1, 2)));
2917 @end smallexample
2918
2919 @noindent
2920 causes the compiler to check that, in calls to @code{my_memcpy},
2921 arguments @var{dest} and @var{src} are non-null. If the compiler
2922 determines that a null pointer is passed in an argument slot marked
2923 as non-null, and the @option{-Wnonnull} option is enabled, a warning
2924 is issued. The compiler may also choose to make optimizations based
2925 on the knowledge that certain function arguments will never be null.
2926
2927 If no argument index list is given to the @code{nonnull} attribute,
2928 all pointer arguments are marked as non-null. To illustrate, the
2929 following declaration is equivalent to the previous example:
2930
2931 @smallexample
2932 extern void *
2933 my_memcpy (void *dest, const void *src, size_t len)
2934 __attribute__((nonnull));
2935 @end smallexample
2936
2937 @item noreturn
2938 @cindex @code{noreturn} function attribute
2939 @cindex functions that never return
2940 A few standard library functions, such as @code{abort} and @code{exit},
2941 cannot return. GCC knows this automatically. Some programs define
2942 their own functions that never return. You can declare them
2943 @code{noreturn} to tell the compiler this fact. For example,
2944
2945 @smallexample
2946 @group
2947 void fatal () __attribute__ ((noreturn));
2948
2949 void
2950 fatal (/* @r{@dots{}} */)
2951 @{
2952 /* @r{@dots{}} */ /* @r{Print error message.} */ /* @r{@dots{}} */
2953 exit (1);
2954 @}
2955 @end group
2956 @end smallexample
2957
2958 The @code{noreturn} keyword tells the compiler to assume that
2959 @code{fatal} cannot return. It can then optimize without regard to what
2960 would happen if @code{fatal} ever did return. This makes slightly
2961 better code. More importantly, it helps avoid spurious warnings of
2962 uninitialized variables.
2963
2964 The @code{noreturn} keyword does not affect the exceptional path when that
2965 applies: a @code{noreturn}-marked function may still return to the caller
2966 by throwing an exception or calling @code{longjmp}.
2967
2968 Do not assume that registers saved by the calling function are
2969 restored before calling the @code{noreturn} function.
2970
2971 It does not make sense for a @code{noreturn} function to have a return
2972 type other than @code{void}.
2973
2974 @item nothrow
2975 @cindex @code{nothrow} function attribute
2976 The @code{nothrow} attribute is used to inform the compiler that a
2977 function cannot throw an exception. For example, most functions in
2978 the standard C library can be guaranteed not to throw an exception
2979 with the notable exceptions of @code{qsort} and @code{bsearch} that
2980 take function pointer arguments.
2981
2982 @item noplt
2983 @cindex @code{noplt} function attribute
2984 The @code{noplt} attribute is the counterpart to option @option{-fno-plt} and
2985 does not use PLT for calls to functions marked with this attribute in position
2986 independent code.
2987
2988 @smallexample
2989 @group
2990 /* Externally defined function foo. */
2991 int foo () __attribute__ ((noplt));
2992
2993 int
2994 main (/* @r{@dots{}} */)
2995 @{
2996 /* @r{@dots{}} */
2997 foo ();
2998 /* @r{@dots{}} */
2999 @}
3000 @end group
3001 @end smallexample
3002
3003 The @code{noplt} attribute on function foo tells the compiler to assume that
3004 the function foo is externally defined and the call to foo must avoid the PLT
3005 in position independent code.
3006
3007 Additionally, a few targets also convert calls to those functions that are
3008 marked to not use the PLT to use the GOT instead for non-position independent
3009 code.
3010
3011 @item optimize
3012 @cindex @code{optimize} function attribute
3013 The @code{optimize} attribute is used to specify that a function is to
3014 be compiled with different optimization options than specified on the
3015 command line. Arguments can either be numbers or strings. Numbers
3016 are assumed to be an optimization level. Strings that begin with
3017 @code{O} are assumed to be an optimization option, while other options
3018 are assumed to be used with a @code{-f} prefix. You can also use the
3019 @samp{#pragma GCC optimize} pragma to set the optimization options
3020 that affect more than one function.
3021 @xref{Function Specific Option Pragmas}, for details about the
3022 @samp{#pragma GCC optimize} pragma.
3023
3024 This can be used for instance to have frequently-executed functions
3025 compiled with more aggressive optimization options that produce faster
3026 and larger code, while other functions can be compiled with less
3027 aggressive options.
3028
3029 @item pure
3030 @cindex @code{pure} function attribute
3031 @cindex functions that have no side effects
3032 Many functions have no effects except the return value and their
3033 return value depends only on the parameters and/or global variables.
3034 Such a function can be subject
3035 to common subexpression elimination and loop optimization just as an
3036 arithmetic operator would be. These functions should be declared
3037 with the attribute @code{pure}. For example,
3038
3039 @smallexample
3040 int square (int) __attribute__ ((pure));
3041 @end smallexample
3042
3043 @noindent
3044 says that the hypothetical function @code{square} is safe to call
3045 fewer times than the program says.
3046
3047 Some of common examples of pure functions are @code{strlen} or @code{memcmp}.
3048 Interesting non-pure functions are functions with infinite loops or those
3049 depending on volatile memory or other system resource, that may change between
3050 two consecutive calls (such as @code{feof} in a multithreading environment).
3051
3052 @item returns_nonnull
3053 @cindex @code{returns_nonnull} function attribute
3054 The @code{returns_nonnull} attribute specifies that the function
3055 return value should be a non-null pointer. For instance, the declaration:
3056
3057 @smallexample
3058 extern void *
3059 mymalloc (size_t len) __attribute__((returns_nonnull));
3060 @end smallexample
3061
3062 @noindent
3063 lets the compiler optimize callers based on the knowledge
3064 that the return value will never be null.
3065
3066 @item returns_twice
3067 @cindex @code{returns_twice} function attribute
3068 @cindex functions that return more than once
3069 The @code{returns_twice} attribute tells the compiler that a function may
3070 return more than one time. The compiler ensures that all registers
3071 are dead before calling such a function and emits a warning about
3072 the variables that may be clobbered after the second return from the
3073 function. Examples of such functions are @code{setjmp} and @code{vfork}.
3074 The @code{longjmp}-like counterpart of such function, if any, might need
3075 to be marked with the @code{noreturn} attribute.
3076
3077 @item section ("@var{section-name}")
3078 @cindex @code{section} function attribute
3079 @cindex functions in arbitrary sections
3080 Normally, the compiler places the code it generates in the @code{text} section.
3081 Sometimes, however, you need additional sections, or you need certain
3082 particular functions to appear in special sections. The @code{section}
3083 attribute specifies that a function lives in a particular section.
3084 For example, the declaration:
3085
3086 @smallexample
3087 extern void foobar (void) __attribute__ ((section ("bar")));
3088 @end smallexample
3089
3090 @noindent
3091 puts the function @code{foobar} in the @code{bar} section.
3092
3093 Some file formats do not support arbitrary sections so the @code{section}
3094 attribute is not available on all platforms.
3095 If you need to map the entire contents of a module to a particular
3096 section, consider using the facilities of the linker instead.
3097
3098 @item sentinel
3099 @cindex @code{sentinel} function attribute
3100 This function attribute ensures that a parameter in a function call is
3101 an explicit @code{NULL}. The attribute is only valid on variadic
3102 functions. By default, the sentinel is located at position zero, the
3103 last parameter of the function call. If an optional integer position
3104 argument P is supplied to the attribute, the sentinel must be located at
3105 position P counting backwards from the end of the argument list.
3106
3107 @smallexample
3108 __attribute__ ((sentinel))
3109 is equivalent to
3110 __attribute__ ((sentinel(0)))
3111 @end smallexample
3112
3113 The attribute is automatically set with a position of 0 for the built-in
3114 functions @code{execl} and @code{execlp}. The built-in function
3115 @code{execle} has the attribute set with a position of 1.
3116
3117 A valid @code{NULL} in this context is defined as zero with any pointer
3118 type. If your system defines the @code{NULL} macro with an integer type
3119 then you need to add an explicit cast. GCC replaces @code{stddef.h}
3120 with a copy that redefines NULL appropriately.
3121
3122 The warnings for missing or incorrect sentinels are enabled with
3123 @option{-Wformat}.
3124
3125 @item stack_protect
3126 @cindex @code{stack_protect} function attribute
3127 This function attribute make a stack protection of the function if
3128 flags @option{fstack-protector} or @option{fstack-protector-strong}
3129 or @option{fstack-protector-explicit} are set.
3130
3131 @item target_clones (@var{options})
3132 @cindex @code{target_clones} function attribute
3133 The @code{target_clones} attribute is used to specify that a function is to
3134 be cloned into multiple versions compiled with different target options
3135 than specified on the command line. The supported options and restrictions
3136 are the same as for @code{target} attribute.
3137
3138 For instance on an x86, you could compile a function with
3139 @code{target_clones("sse4.1,avx")}. It will create 2 function clones,
3140 one compiled with @option{-msse4.1} and another with @option{-mavx}.
3141 At the function call it will create resolver @code{ifunc}, that will
3142 dynamically call a clone suitable for current architecture.
3143
3144 @item simd
3145 @cindex @code{simd} function attribute.
3146 This attribute enables creation of one or more function versions that
3147 can process multiple arguments using SIMD instructions from a
3148 single invocation. Specifying this attribute allows compiler to
3149 assume that such versions are available at link time (provided
3150 in the same or another translation unit). Generated versions are
3151 target dependent and described in corresponding Vector ABI document. For
3152 x86_64 target this document can be found
3153 @w{@uref{https://sourceware.org/glibc/wiki/libmvec?action=AttachFile&do=view&target=VectorABI.txt,here}}.
3154 The attribute should not be used together with Cilk Plus @code{vector}
3155 attribute on the same function.
3156 If the attribute is specified and @code{#pragma omp declare simd}
3157 present on a declaration and @code{-fopenmp} or @code{-fopenmp-simd}
3158 switch is specified, then the attribute is ignored.
3159
3160 @item target (@var{options})
3161 @cindex @code{target} function attribute
3162 Multiple target back ends implement the @code{target} attribute
3163 to specify that a function is to
3164 be compiled with different target options than specified on the
3165 command line. This can be used for instance to have functions
3166 compiled with a different ISA (instruction set architecture) than the
3167 default. You can also use the @samp{#pragma GCC target} pragma to set
3168 more than one function to be compiled with specific target options.
3169 @xref{Function Specific Option Pragmas}, for details about the
3170 @samp{#pragma GCC target} pragma.
3171
3172 For instance, on an x86, you could declare one function with the
3173 @code{target("sse4.1,arch=core2")} attribute and another with
3174 @code{target("sse4a,arch=amdfam10")}. This is equivalent to
3175 compiling the first function with @option{-msse4.1} and
3176 @option{-march=core2} options, and the second function with
3177 @option{-msse4a} and @option{-march=amdfam10} options. It is up to you
3178 to make sure that a function is only invoked on a machine that
3179 supports the particular ISA it is compiled for (for example by using
3180 @code{cpuid} on x86 to determine what feature bits and architecture
3181 family are used).
3182
3183 @smallexample
3184 int core2_func (void) __attribute__ ((__target__ ("arch=core2")));
3185 int sse3_func (void) __attribute__ ((__target__ ("sse3")));
3186 @end smallexample
3187
3188 You can either use multiple
3189 strings separated by commas to specify multiple options,
3190 or separate the options with a comma (@samp{,}) within a single string.
3191
3192 The options supported are specific to each target; refer to @ref{x86
3193 Function Attributes}, @ref{PowerPC Function Attributes},
3194 @ref{ARM Function Attributes},and @ref{Nios II Function Attributes},
3195 for details.
3196
3197 @item unused
3198 @cindex @code{unused} function attribute
3199 This attribute, attached to a function, means that the function is meant
3200 to be possibly unused. GCC does not produce a warning for this
3201 function.
3202
3203 @item used
3204 @cindex @code{used} function attribute
3205 This attribute, attached to a function, means that code must be emitted
3206 for the function even if it appears that the function is not referenced.
3207 This is useful, for example, when the function is referenced only in
3208 inline assembly.
3209
3210 When applied to a member function of a C++ class template, the
3211 attribute also means that the function is instantiated if the
3212 class itself is instantiated.
3213
3214 @item visibility ("@var{visibility_type}")
3215 @cindex @code{visibility} function attribute
3216 This attribute affects the linkage of the declaration to which it is attached.
3217 It can be applied to variables (@pxref{Common Variable Attributes}) and types
3218 (@pxref{Common Type Attributes}) as well as functions.
3219
3220 There are four supported @var{visibility_type} values: default,
3221 hidden, protected or internal visibility.
3222
3223 @smallexample
3224 void __attribute__ ((visibility ("protected")))
3225 f () @{ /* @r{Do something.} */; @}
3226 int i __attribute__ ((visibility ("hidden")));
3227 @end smallexample
3228
3229 The possible values of @var{visibility_type} correspond to the
3230 visibility settings in the ELF gABI.
3231
3232 @table @code
3233 @c keep this list of visibilities in alphabetical order.
3234
3235 @item default
3236 Default visibility is the normal case for the object file format.
3237 This value is available for the visibility attribute to override other
3238 options that may change the assumed visibility of entities.
3239
3240 On ELF, default visibility means that the declaration is visible to other
3241 modules and, in shared libraries, means that the declared entity may be
3242 overridden.
3243
3244 On Darwin, default visibility means that the declaration is visible to
3245 other modules.
3246
3247 Default visibility corresponds to ``external linkage'' in the language.
3248
3249 @item hidden
3250 Hidden visibility indicates that the entity declared has a new
3251 form of linkage, which we call ``hidden linkage''. Two
3252 declarations of an object with hidden linkage refer to the same object
3253 if they are in the same shared object.
3254
3255 @item internal
3256 Internal visibility is like hidden visibility, but with additional
3257 processor specific semantics. Unless otherwise specified by the
3258 psABI, GCC defines internal visibility to mean that a function is
3259 @emph{never} called from another module. Compare this with hidden
3260 functions which, while they cannot be referenced directly by other
3261 modules, can be referenced indirectly via function pointers. By
3262 indicating that a function cannot be called from outside the module,
3263 GCC may for instance omit the load of a PIC register since it is known
3264 that the calling function loaded the correct value.
3265
3266 @item protected
3267 Protected visibility is like default visibility except that it
3268 indicates that references within the defining module bind to the
3269 definition in that module. That is, the declared entity cannot be
3270 overridden by another module.
3271
3272 @end table
3273
3274 All visibilities are supported on many, but not all, ELF targets
3275 (supported when the assembler supports the @samp{.visibility}
3276 pseudo-op). Default visibility is supported everywhere. Hidden
3277 visibility is supported on Darwin targets.
3278
3279 The visibility attribute should be applied only to declarations that
3280 would otherwise have external linkage. The attribute should be applied
3281 consistently, so that the same entity should not be declared with
3282 different settings of the attribute.
3283
3284 In C++, the visibility attribute applies to types as well as functions
3285 and objects, because in C++ types have linkage. A class must not have
3286 greater visibility than its non-static data member types and bases,
3287 and class members default to the visibility of their class. Also, a
3288 declaration without explicit visibility is limited to the visibility
3289 of its type.
3290
3291 In C++, you can mark member functions and static member variables of a
3292 class with the visibility attribute. This is useful if you know a
3293 particular method or static member variable should only be used from
3294 one shared object; then you can mark it hidden while the rest of the
3295 class has default visibility. Care must be taken to avoid breaking
3296 the One Definition Rule; for example, it is usually not useful to mark
3297 an inline method as hidden without marking the whole class as hidden.
3298
3299 A C++ namespace declaration can also have the visibility attribute.
3300
3301 @smallexample
3302 namespace nspace1 __attribute__ ((visibility ("protected")))
3303 @{ /* @r{Do something.} */; @}
3304 @end smallexample
3305
3306 This attribute applies only to the particular namespace body, not to
3307 other definitions of the same namespace; it is equivalent to using
3308 @samp{#pragma GCC visibility} before and after the namespace
3309 definition (@pxref{Visibility Pragmas}).
3310
3311 In C++, if a template argument has limited visibility, this
3312 restriction is implicitly propagated to the template instantiation.
3313 Otherwise, template instantiations and specializations default to the
3314 visibility of their template.
3315
3316 If both the template and enclosing class have explicit visibility, the
3317 visibility from the template is used.
3318
3319 @item warn_unused_result
3320 @cindex @code{warn_unused_result} function attribute
3321 The @code{warn_unused_result} attribute causes a warning to be emitted
3322 if a caller of the function with this attribute does not use its
3323 return value. This is useful for functions where not checking
3324 the result is either a security problem or always a bug, such as
3325 @code{realloc}.
3326
3327 @smallexample
3328 int fn () __attribute__ ((warn_unused_result));
3329 int foo ()
3330 @{
3331 if (fn () < 0) return -1;
3332 fn ();
3333 return 0;
3334 @}
3335 @end smallexample
3336
3337 @noindent
3338 results in warning on line 5.
3339
3340 @item weak
3341 @cindex @code{weak} function attribute
3342 The @code{weak} attribute causes the declaration to be emitted as a weak
3343 symbol rather than a global. This is primarily useful in defining
3344 library functions that can be overridden in user code, though it can
3345 also be used with non-function declarations. Weak symbols are supported
3346 for ELF targets, and also for a.out targets when using the GNU assembler
3347 and linker.
3348
3349 @item weakref
3350 @itemx weakref ("@var{target}")
3351 @cindex @code{weakref} function attribute
3352 The @code{weakref} attribute marks a declaration as a weak reference.
3353 Without arguments, it should be accompanied by an @code{alias} attribute
3354 naming the target symbol. Optionally, the @var{target} may be given as
3355 an argument to @code{weakref} itself. In either case, @code{weakref}
3356 implicitly marks the declaration as @code{weak}. Without a
3357 @var{target}, given as an argument to @code{weakref} or to @code{alias},
3358 @code{weakref} is equivalent to @code{weak}.
3359
3360 @smallexample
3361 static int x() __attribute__ ((weakref ("y")));
3362 /* is equivalent to... */
3363 static int x() __attribute__ ((weak, weakref, alias ("y")));
3364 /* and to... */
3365 static int x() __attribute__ ((weakref));
3366 static int x() __attribute__ ((alias ("y")));
3367 @end smallexample
3368
3369 A weak reference is an alias that does not by itself require a
3370 definition to be given for the target symbol. If the target symbol is
3371 only referenced through weak references, then it becomes a @code{weak}
3372 undefined symbol. If it is directly referenced, however, then such
3373 strong references prevail, and a definition is required for the
3374 symbol, not necessarily in the same translation unit.
3375
3376 The effect is equivalent to moving all references to the alias to a
3377 separate translation unit, renaming the alias to the aliased symbol,
3378 declaring it as weak, compiling the two separate translation units and
3379 performing a reloadable link on them.
3380
3381 At present, a declaration to which @code{weakref} is attached can
3382 only be @code{static}.
3383
3384 @item lower
3385 @itemx upper
3386 @itemx either
3387 @cindex lower memory region on the MSP430
3388 @cindex upper memory region on the MSP430
3389 @cindex either memory region on the MSP430
3390 On the MSP430 target these attributes can be used to specify whether
3391 the function or variable should be placed into low memory, high
3392 memory, or the placement should be left to the linker to decide. The
3393 attributes are only significant if compiling for the MSP430X
3394 architecture.
3395
3396 The attributes work in conjunction with a linker script that has been
3397 augmented to specify where to place sections with a @code{.lower} and
3398 a @code{.upper} prefix. So for example as well as placing the
3399 @code{.data} section the script would also specify the placement of a
3400 @code{.lower.data} and a @code{.upper.data} section. The intention
3401 being that @code{lower} sections are placed into a small but easier to
3402 access memory region and the upper sections are placed into a larger, but
3403 slower to access region.
3404
3405 The @code{either} attribute is special. It tells the linker to place
3406 the object into the corresponding @code{lower} section if there is
3407 room for it. If there is insufficient room then the object is placed
3408 into the corresponding @code{upper} section instead. Note - the
3409 placement algorithm is not very sophisticated. It will not attempt to
3410 find an optimal packing of the @code{lower} sections. It just makes
3411 one pass over the objects and does the best that it can. Using the
3412 @option{-ffunction-sections} and @option{-fdata-sections} command line
3413 options can help the packing however, since they produce smaller,
3414 easier to pack regions.
3415
3416 @item reentrant
3417 On the MSP430 a function can be given the @code{reentant} attribute.
3418 This makes the function disable interrupts upon entry and enable
3419 interrupts upon exit. Reentrant functions cannot be @code{naked}.
3420
3421 @item critical
3422 On the MSP430 a function can be given the @code{critical} attribute.
3423 This makes the function disable interrupts upon entry and restore the
3424 previous interrupt enabled/disabled state upon exit. A function
3425 cannot have both the @code{reentrant} and @code{critical} attributes.
3426 Critical functions cannot be @code{naked}.
3427
3428 @item wakeup
3429 On the MSP430 a function can be given the @code{wakeup} attribute.
3430 Such a function must also have the @code{interrupt} attribute. When a
3431 function with the @code{wakeup} attribute exists the processor will be
3432 woken up from any low-power state in which it may be residing.
3433
3434 @end table
3435
3436 @c This is the end of the target-independent attribute table
3437
3438 @node AArch64 Function Attributes
3439 @subsection AArch64 Function Attributes
3440
3441 The following target-specific function attributes are available for the
3442 AArch64 target. For the most part, these options mirror the behavior of
3443 similar command-line options (@pxref{AArch64 Options}), but on a
3444 per-function basis.
3445
3446 @table @code
3447 @item general-regs-only
3448 @cindex @code{general-regs-only} function attribute, AArch64
3449 Indicates that no floating-point or Advanced SIMD registers should be
3450 used when generating code for this function. If the function explicitly
3451 uses floating-point code, then the compiler gives an error. This is
3452 the same behavior as that of the command-line option
3453 @option{-mgeneral-regs-only}.
3454
3455 @item fix-cortex-a53-835769
3456 @cindex @code{fix-cortex-a53-835769} function attribute, AArch64
3457 Indicates that the workaround for the Cortex-A53 erratum 835769 should be
3458 applied to this function. To explicitly disable the workaround for this
3459 function specify the negated form: @code{no-fix-cortex-a53-835769}.
3460 This corresponds to the behavior of the command line options
3461 @option{-mfix-cortex-a53-835769} and @option{-mno-fix-cortex-a53-835769}.
3462
3463 @item cmodel=
3464 @cindex @code{cmodel=} function attribute, AArch64
3465 Indicates that code should be generated for a particular code model for
3466 this function. The behavior and permissible arguments are the same as
3467 for the command line option @option{-mcmodel=}.
3468
3469 @item strict-align
3470 @cindex @code{strict-align} function attribute, AArch64
3471 Indicates that the compiler should not assume that unaligned memory references
3472 are handled by the system. The behavior is the same as for the command-line
3473 option @option{-mstrict-align}.
3474
3475 @item omit-leaf-frame-pointer
3476 @cindex @code{omit-leaf-frame-pointer} function attribute, AArch64
3477 Indicates that the frame pointer should be omitted for a leaf function call.
3478 To keep the frame pointer, the inverse attribute
3479 @code{no-omit-leaf-frame-pointer} can be specified. These attributes have
3480 the same behavior as the command-line options @option{-momit-leaf-frame-pointer}
3481 and @option{-mno-omit-leaf-frame-pointer}.
3482
3483 @item tls-dialect=
3484 @cindex @code{tls-dialect=} function attribute, AArch64
3485 Specifies the TLS dialect to use for this function. The behavior and
3486 permissible arguments are the same as for the command-line option
3487 @option{-mtls-dialect=}.
3488
3489 @item arch=
3490 @cindex @code{arch=} function attribute, AArch64
3491 Specifies the architecture version and architectural extensions to use
3492 for this function. The behavior and permissible arguments are the same as
3493 for the @option{-march=} command-line option.
3494
3495 @item tune=
3496 @cindex @code{tune=} function attribute, AArch64
3497 Specifies the core for which to tune the performance of this function.
3498 The behavior and permissible arguments are the same as for the @option{-mtune=}
3499 command-line option.
3500
3501 @item cpu=
3502 @cindex @code{cpu=} function attribute, AArch64
3503 Specifies the core for which to tune the performance of this function and also
3504 whose architectural features to use. The behavior and valid arguments are the
3505 same as for the @option{-mcpu=} command-line option.
3506
3507 @end table
3508
3509 The above target attributes can be specified as follows:
3510
3511 @smallexample
3512 __attribute__((target("@var{attr-string}")))
3513 int
3514 f (int a)
3515 @{
3516 return a + 5;
3517 @}
3518 @end smallexample
3519
3520 where @code{@var{attr-string}} is one of the attribute strings specified above.
3521
3522 Additionally, the architectural extension string may be specified on its
3523 own. This can be used to turn on and off particular architectural extensions
3524 without having to specify a particular architecture version or core. Example:
3525
3526 @smallexample
3527 __attribute__((target("+crc+nocrypto")))
3528 int
3529 foo (int a)
3530 @{
3531 return a + 5;
3532 @}
3533 @end smallexample
3534
3535 In this example @code{target("+crc+nocrypto")} enables the @code{crc}
3536 extension and disables the @code{crypto} extension for the function @code{foo}
3537 without modifying an existing @option{-march=} or @option{-mcpu} option.
3538
3539 Multiple target function attributes can be specified by separating them with
3540 a comma. For example:
3541 @smallexample
3542 __attribute__((target("arch=armv8-a+crc+crypto,tune=cortex-a53")))
3543 int
3544 foo (int a)
3545 @{
3546 return a + 5;
3547 @}
3548 @end smallexample
3549
3550 is valid and compiles function @code{foo} for ARMv8-A with @code{crc}
3551 and @code{crypto} extensions and tunes it for @code{cortex-a53}.
3552
3553 @subsubsection Inlining rules
3554 Specifying target attributes on individual functions or performing link-time
3555 optimization across translation units compiled with different target options
3556 can affect function inlining rules:
3557
3558 In particular, a caller function can inline a callee function only if the
3559 architectural features available to the callee are a subset of the features
3560 available to the caller.
3561 For example: A function @code{foo} compiled with @option{-march=armv8-a+crc},
3562 or tagged with the equivalent @code{arch=armv8-a+crc} attribute,
3563 can inline a function @code{bar} compiled with @option{-march=armv8-a+nocrc}
3564 because the all the architectural features that function @code{bar} requires
3565 are available to function @code{foo}. Conversely, function @code{bar} cannot
3566 inline function @code{foo}.
3567
3568 Additionally inlining a function compiled with @option{-mstrict-align} into a
3569 function compiled without @code{-mstrict-align} is not allowed.
3570 However, inlining a function compiled without @option{-mstrict-align} into a
3571 function compiled with @option{-mstrict-align} is allowed.
3572
3573 Note that CPU tuning options and attributes such as the @option{-mcpu=},
3574 @option{-mtune=} do not inhibit inlining unless the CPU specified by the
3575 @option{-mcpu=} option or the @code{cpu=} attribute conflicts with the
3576 architectural feature rules specified above.
3577
3578 @node ARC Function Attributes
3579 @subsection ARC Function Attributes
3580
3581 These function attributes are supported by the ARC back end:
3582
3583 @table @code
3584 @item interrupt
3585 @cindex @code{interrupt} function attribute, ARC
3586 Use this attribute to indicate
3587 that the specified function is an interrupt handler. The compiler generates
3588 function entry and exit sequences suitable for use in an interrupt handler
3589 when this attribute is present.
3590
3591 On the ARC, you must specify the kind of interrupt to be handled
3592 in a parameter to the interrupt attribute like this:
3593
3594 @smallexample
3595 void f () __attribute__ ((interrupt ("ilink1")));
3596 @end smallexample
3597
3598 Permissible values for this parameter are: @w{@code{ilink1}} and
3599 @w{@code{ilink2}}.
3600
3601 @item long_call
3602 @itemx medium_call
3603 @itemx short_call
3604 @cindex @code{long_call} function attribute, ARC
3605 @cindex @code{medium_call} function attribute, ARC
3606 @cindex @code{short_call} function attribute, ARC
3607 @cindex indirect calls, ARC
3608 These attributes specify how a particular function is called.
3609 These attributes override the
3610 @option{-mlong-calls} and @option{-mmedium-calls} (@pxref{ARC Options})
3611 command-line switches and @code{#pragma long_calls} settings.
3612
3613 For ARC, a function marked with the @code{long_call} attribute is
3614 always called using register-indirect jump-and-link instructions,
3615 thereby enabling the called function to be placed anywhere within the
3616 32-bit address space. A function marked with the @code{medium_call}
3617 attribute will always be close enough to be called with an unconditional
3618 branch-and-link instruction, which has a 25-bit offset from
3619 the call site. A function marked with the @code{short_call}
3620 attribute will always be close enough to be called with a conditional
3621 branch-and-link instruction, which has a 21-bit offset from
3622 the call site.
3623 @end table
3624
3625 @node ARM Function Attributes
3626 @subsection ARM Function Attributes
3627
3628 These function attributes are supported for ARM targets:
3629
3630 @table @code
3631 @item interrupt
3632 @cindex @code{interrupt} function attribute, ARM
3633 Use this attribute to indicate
3634 that the specified function is an interrupt handler. The compiler generates
3635 function entry and exit sequences suitable for use in an interrupt handler
3636 when this attribute is present.
3637
3638 You can specify the kind of interrupt to be handled by
3639 adding an optional parameter to the interrupt attribute like this:
3640
3641 @smallexample
3642 void f () __attribute__ ((interrupt ("IRQ")));
3643 @end smallexample
3644
3645 @noindent
3646 Permissible values for this parameter are: @code{IRQ}, @code{FIQ},
3647 @code{SWI}, @code{ABORT} and @code{UNDEF}.
3648
3649 On ARMv7-M the interrupt type is ignored, and the attribute means the function
3650 may be called with a word-aligned stack pointer.
3651
3652 @item isr
3653 @cindex @code{isr} function attribute, ARM
3654 Use this attribute on ARM to write Interrupt Service Routines. This is an
3655 alias to the @code{interrupt} attribute above.
3656
3657 @item long_call
3658 @itemx short_call
3659 @cindex @code{long_call} function attribute, ARM
3660 @cindex @code{short_call} function attribute, ARM
3661 @cindex indirect calls, ARM
3662 These attributes specify how a particular function is called.
3663 These attributes override the
3664 @option{-mlong-calls} (@pxref{ARM Options})
3665 command-line switch and @code{#pragma long_calls} settings. For ARM, the
3666 @code{long_call} attribute indicates that the function might be far
3667 away from the call site and require a different (more expensive)
3668 calling sequence. The @code{short_call} attribute always places
3669 the offset to the function from the call site into the @samp{BL}
3670 instruction directly.
3671
3672 @item naked
3673 @cindex @code{naked} function attribute, ARM
3674 This attribute allows the compiler to construct the
3675 requisite function declaration, while allowing the body of the
3676 function to be assembly code. The specified function will not have
3677 prologue/epilogue sequences generated by the compiler. Only basic
3678 @code{asm} statements can safely be included in naked functions
3679 (@pxref{Basic Asm}). While using extended @code{asm} or a mixture of
3680 basic @code{asm} and C code may appear to work, they cannot be
3681 depended upon to work reliably and are not supported.
3682
3683 @item pcs
3684 @cindex @code{pcs} function attribute, ARM
3685
3686 The @code{pcs} attribute can be used to control the calling convention
3687 used for a function on ARM. The attribute takes an argument that specifies
3688 the calling convention to use.
3689
3690 When compiling using the AAPCS ABI (or a variant of it) then valid
3691 values for the argument are @code{"aapcs"} and @code{"aapcs-vfp"}. In
3692 order to use a variant other than @code{"aapcs"} then the compiler must
3693 be permitted to use the appropriate co-processor registers (i.e., the
3694 VFP registers must be available in order to use @code{"aapcs-vfp"}).
3695 For example,
3696
3697 @smallexample
3698 /* Argument passed in r0, and result returned in r0+r1. */
3699 double f2d (float) __attribute__((pcs("aapcs")));
3700 @end smallexample
3701
3702 Variadic functions always use the @code{"aapcs"} calling convention and
3703 the compiler rejects attempts to specify an alternative.
3704
3705 @item target (@var{options})
3706 @cindex @code{target} function attribute
3707 As discussed in @ref{Common Function Attributes}, this attribute
3708 allows specification of target-specific compilation options.
3709
3710 On ARM, the following options are allowed:
3711
3712 @table @samp
3713 @item thumb
3714 @cindex @code{target("thumb")} function attribute, ARM
3715 Force code generation in the Thumb (T16/T32) ISA, depending on the
3716 architecture level.
3717
3718 @item arm
3719 @cindex @code{target("arm")} function attribute, ARM
3720 Force code generation in the ARM (A32) ISA.
3721
3722 Functions from different modes can be inlined in the caller's mode.
3723
3724 @item fpu=
3725 @cindex @code{target("fpu=")} function attribute, ARM
3726 Specifies the fpu for which to tune the performance of this function.
3727 The behavior and permissible arguments are the same as for the @option{-mfpu=}
3728 command-line option.
3729
3730 @end table
3731
3732 @end table
3733
3734 @node AVR Function Attributes
3735 @subsection AVR Function Attributes
3736
3737 These function attributes are supported by the AVR back end:
3738
3739 @table @code
3740 @item interrupt
3741 @cindex @code{interrupt} function attribute, AVR
3742 Use this attribute to indicate
3743 that the specified function is an interrupt handler. The compiler generates
3744 function entry and exit sequences suitable for use in an interrupt handler
3745 when this attribute is present.
3746
3747 On the AVR, the hardware globally disables interrupts when an
3748 interrupt is executed. The first instruction of an interrupt handler
3749 declared with this attribute is a @code{SEI} instruction to
3750 re-enable interrupts. See also the @code{signal} function attribute
3751 that does not insert a @code{SEI} instruction. If both @code{signal} and
3752 @code{interrupt} are specified for the same function, @code{signal}
3753 is silently ignored.
3754
3755 @item naked
3756 @cindex @code{naked} function attribute, AVR
3757 This attribute allows the compiler to construct the
3758 requisite function declaration, while allowing the body of the
3759 function to be assembly code. The specified function will not have
3760 prologue/epilogue sequences generated by the compiler. Only basic
3761 @code{asm} statements can safely be included in naked functions
3762 (@pxref{Basic Asm}). While using extended @code{asm} or a mixture of
3763 basic @code{asm} and C code may appear to work, they cannot be
3764 depended upon to work reliably and are not supported.
3765
3766 @item OS_main
3767 @itemx OS_task
3768 @cindex @code{OS_main} function attribute, AVR
3769 @cindex @code{OS_task} function attribute, AVR
3770 On AVR, functions with the @code{OS_main} or @code{OS_task} attribute
3771 do not save/restore any call-saved register in their prologue/epilogue.
3772
3773 The @code{OS_main} attribute can be used when there @emph{is
3774 guarantee} that interrupts are disabled at the time when the function
3775 is entered. This saves resources when the stack pointer has to be
3776 changed to set up a frame for local variables.
3777
3778 The @code{OS_task} attribute can be used when there is @emph{no
3779 guarantee} that interrupts are disabled at that time when the function
3780 is entered like for, e@.g@. task functions in a multi-threading operating
3781 system. In that case, changing the stack pointer register is
3782 guarded by save/clear/restore of the global interrupt enable flag.
3783
3784 The differences to the @code{naked} function attribute are:
3785 @itemize @bullet
3786 @item @code{naked} functions do not have a return instruction whereas
3787 @code{OS_main} and @code{OS_task} functions have a @code{RET} or
3788 @code{RETI} return instruction.
3789 @item @code{naked} functions do not set up a frame for local variables
3790 or a frame pointer whereas @code{OS_main} and @code{OS_task} do this
3791 as needed.
3792 @end itemize
3793
3794 @item signal
3795 @cindex @code{signal} function attribute, AVR
3796 Use this attribute on the AVR to indicate that the specified
3797 function is an interrupt handler. The compiler generates function
3798 entry and exit sequences suitable for use in an interrupt handler when this
3799 attribute is present.
3800
3801 See also the @code{interrupt} function attribute.
3802
3803 The AVR hardware globally disables interrupts when an interrupt is executed.
3804 Interrupt handler functions defined with the @code{signal} attribute
3805 do not re-enable interrupts. It is save to enable interrupts in a
3806 @code{signal} handler. This ``save'' only applies to the code
3807 generated by the compiler and not to the IRQ layout of the
3808 application which is responsibility of the application.
3809
3810 If both @code{signal} and @code{interrupt} are specified for the same
3811 function, @code{signal} is silently ignored.
3812 @end table
3813
3814 @node Blackfin Function Attributes
3815 @subsection Blackfin Function Attributes
3816
3817 These function attributes are supported by the Blackfin back end:
3818
3819 @table @code
3820
3821 @item exception_handler
3822 @cindex @code{exception_handler} function attribute
3823 @cindex exception handler functions, Blackfin
3824 Use this attribute on the Blackfin to indicate that the specified function
3825 is an exception handler. The compiler generates function entry and
3826 exit sequences suitable for use in an exception handler when this
3827 attribute is present.
3828
3829 @item interrupt_handler
3830 @cindex @code{interrupt_handler} function attribute, Blackfin
3831 Use this attribute to
3832 indicate that the specified function is an interrupt handler. The compiler
3833 generates function entry and exit sequences suitable for use in an
3834 interrupt handler when this attribute is present.
3835
3836 @item kspisusp
3837 @cindex @code{kspisusp} function attribute, Blackfin
3838 @cindex User stack pointer in interrupts on the Blackfin
3839 When used together with @code{interrupt_handler}, @code{exception_handler}
3840 or @code{nmi_handler}, code is generated to load the stack pointer
3841 from the USP register in the function prologue.
3842
3843 @item l1_text
3844 @cindex @code{l1_text} function attribute, Blackfin
3845 This attribute specifies a function to be placed into L1 Instruction
3846 SRAM@. The function is put into a specific section named @code{.l1.text}.
3847 With @option{-mfdpic}, function calls with a such function as the callee
3848 or caller uses inlined PLT.
3849
3850 @item l2
3851 @cindex @code{l2} function attribute, Blackfin
3852 This attribute specifies a function to be placed into L2
3853 SRAM. The function is put into a specific section named
3854 @code{.l2.text}. With @option{-mfdpic}, callers of such functions use
3855 an inlined PLT.
3856
3857 @item longcall
3858 @itemx shortcall
3859 @cindex indirect calls, Blackfin
3860 @cindex @code{longcall} function attribute, Blackfin
3861 @cindex @code{shortcall} function attribute, Blackfin
3862 The @code{longcall} attribute
3863 indicates that the function might be far away from the call site and
3864 require a different (more expensive) calling sequence. The
3865 @code{shortcall} attribute indicates that the function is always close
3866 enough for the shorter calling sequence to be used. These attributes
3867 override the @option{-mlongcall} switch.
3868
3869 @item nesting
3870 @cindex @code{nesting} function attribute, Blackfin
3871 @cindex Allow nesting in an interrupt handler on the Blackfin processor
3872 Use this attribute together with @code{interrupt_handler},
3873 @code{exception_handler} or @code{nmi_handler} to indicate that the function
3874 entry code should enable nested interrupts or exceptions.
3875
3876 @item nmi_handler
3877 @cindex @code{nmi_handler} function attribute, Blackfin
3878 @cindex NMI handler functions on the Blackfin processor
3879 Use this attribute on the Blackfin to indicate that the specified function
3880 is an NMI handler. The compiler generates function entry and
3881 exit sequences suitable for use in an NMI handler when this
3882 attribute is present.
3883
3884 @item saveall
3885 @cindex @code{saveall} function attribute, Blackfin
3886 @cindex save all registers on the Blackfin
3887 Use this attribute to indicate that
3888 all registers except the stack pointer should be saved in the prologue
3889 regardless of whether they are used or not.
3890 @end table
3891
3892 @node CR16 Function Attributes
3893 @subsection CR16 Function Attributes
3894
3895 These function attributes are supported by the CR16 back end:
3896
3897 @table @code
3898 @item interrupt
3899 @cindex @code{interrupt} function attribute, CR16
3900 Use this attribute to indicate
3901 that the specified function is an interrupt handler. The compiler generates
3902 function entry and exit sequences suitable for use in an interrupt handler
3903 when this attribute is present.
3904 @end table
3905
3906 @node Epiphany Function Attributes
3907 @subsection Epiphany Function Attributes
3908
3909 These function attributes are supported by the Epiphany back end:
3910
3911 @table @code
3912 @item disinterrupt
3913 @cindex @code{disinterrupt} function attribute, Epiphany
3914 This attribute causes the compiler to emit
3915 instructions to disable interrupts for the duration of the given
3916 function.
3917
3918 @item forwarder_section
3919 @cindex @code{forwarder_section} function attribute, Epiphany
3920 This attribute modifies the behavior of an interrupt handler.
3921 The interrupt handler may be in external memory which cannot be
3922 reached by a branch instruction, so generate a local memory trampoline
3923 to transfer control. The single parameter identifies the section where
3924 the trampoline is placed.
3925
3926 @item interrupt
3927 @cindex @code{interrupt} function attribute, Epiphany
3928 Use this attribute to indicate
3929 that the specified function is an interrupt handler. The compiler generates
3930 function entry and exit sequences suitable for use in an interrupt handler
3931 when this attribute is present. It may also generate
3932 a special section with code to initialize the interrupt vector table.
3933
3934 On Epiphany targets one or more optional parameters can be added like this:
3935
3936 @smallexample
3937 void __attribute__ ((interrupt ("dma0, dma1"))) universal_dma_handler ();
3938 @end smallexample
3939
3940 Permissible values for these parameters are: @w{@code{reset}},
3941 @w{@code{software_exception}}, @w{@code{page_miss}},
3942 @w{@code{timer0}}, @w{@code{timer1}}, @w{@code{message}},
3943 @w{@code{dma0}}, @w{@code{dma1}}, @w{@code{wand}} and @w{@code{swi}}.
3944 Multiple parameters indicate that multiple entries in the interrupt
3945 vector table should be initialized for this function, i.e.@: for each
3946 parameter @w{@var{name}}, a jump to the function is emitted in
3947 the section @w{ivt_entry_@var{name}}. The parameter(s) may be omitted
3948 entirely, in which case no interrupt vector table entry is provided.
3949
3950 Note that interrupts are enabled inside the function
3951 unless the @code{disinterrupt} attribute is also specified.
3952
3953 The following examples are all valid uses of these attributes on
3954 Epiphany targets:
3955 @smallexample
3956 void __attribute__ ((interrupt)) universal_handler ();
3957 void __attribute__ ((interrupt ("dma1"))) dma1_handler ();
3958 void __attribute__ ((interrupt ("dma0, dma1")))
3959 universal_dma_handler ();
3960 void __attribute__ ((interrupt ("timer0"), disinterrupt))
3961 fast_timer_handler ();
3962 void __attribute__ ((interrupt ("dma0, dma1"),
3963 forwarder_section ("tramp")))
3964 external_dma_handler ();
3965 @end smallexample
3966
3967 @item long_call
3968 @itemx short_call
3969 @cindex @code{long_call} function attribute, Epiphany
3970 @cindex @code{short_call} function attribute, Epiphany
3971 @cindex indirect calls, Epiphany
3972 These attributes specify how a particular function is called.
3973 These attributes override the
3974 @option{-mlong-calls} (@pxref{Adapteva Epiphany Options})
3975 command-line switch and @code{#pragma long_calls} settings.
3976 @end table
3977
3978
3979 @node H8/300 Function Attributes
3980 @subsection H8/300 Function Attributes
3981
3982 These function attributes are available for H8/300 targets:
3983
3984 @table @code
3985 @item function_vector
3986 @cindex @code{function_vector} function attribute, H8/300
3987 Use this attribute on the H8/300, H8/300H, and H8S to indicate
3988 that the specified function should be called through the function vector.
3989 Calling a function through the function vector reduces code size; however,
3990 the function vector has a limited size (maximum 128 entries on the H8/300
3991 and 64 entries on the H8/300H and H8S)
3992 and shares space with the interrupt vector.
3993
3994 @item interrupt_handler
3995 @cindex @code{interrupt_handler} function attribute, H8/300
3996 Use this attribute on the H8/300, H8/300H, and H8S to
3997 indicate that the specified function is an interrupt handler. The compiler
3998 generates function entry and exit sequences suitable for use in an
3999 interrupt handler when this attribute is present.
4000
4001 @item saveall
4002 @cindex @code{saveall} function attribute, H8/300
4003 @cindex save all registers on the H8/300, H8/300H, and H8S
4004 Use this attribute on the H8/300, H8/300H, and H8S to indicate that
4005 all registers except the stack pointer should be saved in the prologue
4006 regardless of whether they are used or not.
4007 @end table
4008
4009 @node IA-64 Function Attributes
4010 @subsection IA-64 Function Attributes
4011
4012 These function attributes are supported on IA-64 targets:
4013
4014 @table @code
4015 @item syscall_linkage
4016 @cindex @code{syscall_linkage} function attribute, IA-64
4017 This attribute is used to modify the IA-64 calling convention by marking
4018 all input registers as live at all function exits. This makes it possible
4019 to restart a system call after an interrupt without having to save/restore
4020 the input registers. This also prevents kernel data from leaking into
4021 application code.
4022
4023 @item version_id
4024 @cindex @code{version_id} function attribute, IA-64
4025 This IA-64 HP-UX attribute, attached to a global variable or function, renames a
4026 symbol to contain a version string, thus allowing for function level
4027 versioning. HP-UX system header files may use function level versioning
4028 for some system calls.
4029
4030 @smallexample
4031 extern int foo () __attribute__((version_id ("20040821")));
4032 @end smallexample
4033
4034 @noindent
4035 Calls to @code{foo} are mapped to calls to @code{foo@{20040821@}}.
4036 @end table
4037
4038 @node M32C Function Attributes
4039 @subsection M32C Function Attributes
4040
4041 These function attributes are supported by the M32C back end:
4042
4043 @table @code
4044 @item bank_switch
4045 @cindex @code{bank_switch} function attribute, M32C
4046 When added to an interrupt handler with the M32C port, causes the
4047 prologue and epilogue to use bank switching to preserve the registers
4048 rather than saving them on the stack.
4049
4050 @item fast_interrupt
4051 @cindex @code{fast_interrupt} function attribute, M32C
4052 Use this attribute on the M32C port to indicate that the specified
4053 function is a fast interrupt handler. This is just like the
4054 @code{interrupt} attribute, except that @code{freit} is used to return
4055 instead of @code{reit}.
4056
4057 @item function_vector
4058 @cindex @code{function_vector} function attribute, M16C/M32C
4059 On M16C/M32C targets, the @code{function_vector} attribute declares a
4060 special page subroutine call function. Use of this attribute reduces
4061 the code size by 2 bytes for each call generated to the
4062 subroutine. The argument to the attribute is the vector number entry
4063 from the special page vector table which contains the 16 low-order
4064 bits of the subroutine's entry address. Each vector table has special
4065 page number (18 to 255) that is used in @code{jsrs} instructions.
4066 Jump addresses of the routines are generated by adding 0x0F0000 (in
4067 case of M16C targets) or 0xFF0000 (in case of M32C targets), to the
4068 2-byte addresses set in the vector table. Therefore you need to ensure
4069 that all the special page vector routines should get mapped within the
4070 address range 0x0F0000 to 0x0FFFFF (for M16C) and 0xFF0000 to 0xFFFFFF
4071 (for M32C).
4072
4073 In the following example 2 bytes are saved for each call to
4074 function @code{foo}.
4075
4076 @smallexample
4077 void foo (void) __attribute__((function_vector(0x18)));
4078 void foo (void)
4079 @{
4080 @}
4081
4082 void bar (void)
4083 @{
4084 foo();
4085 @}
4086 @end smallexample
4087
4088 If functions are defined in one file and are called in another file,
4089 then be sure to write this declaration in both files.
4090
4091 This attribute is ignored for R8C target.
4092
4093 @item interrupt
4094 @cindex @code{interrupt} function attribute, M32C
4095 Use this attribute to indicate
4096 that the specified function is an interrupt handler. The compiler generates
4097 function entry and exit sequences suitable for use in an interrupt handler
4098 when this attribute is present.
4099 @end table
4100
4101 @node M32R/D Function Attributes
4102 @subsection M32R/D Function Attributes
4103
4104 These function attributes are supported by the M32R/D back end:
4105
4106 @table @code
4107 @item interrupt
4108 @cindex @code{interrupt} function attribute, M32R/D
4109 Use this attribute to indicate
4110 that the specified function is an interrupt handler. The compiler generates
4111 function entry and exit sequences suitable for use in an interrupt handler
4112 when this attribute is present.
4113
4114 @item model (@var{model-name})
4115 @cindex @code{model} function attribute, M32R/D
4116 @cindex function addressability on the M32R/D
4117
4118 On the M32R/D, use this attribute to set the addressability of an
4119 object, and of the code generated for a function. The identifier
4120 @var{model-name} is one of @code{small}, @code{medium}, or
4121 @code{large}, representing each of the code models.
4122
4123 Small model objects live in the lower 16MB of memory (so that their
4124 addresses can be loaded with the @code{ld24} instruction), and are
4125 callable with the @code{bl} instruction.
4126
4127 Medium model objects may live anywhere in the 32-bit address space (the
4128 compiler generates @code{seth/add3} instructions to load their addresses),
4129 and are callable with the @code{bl} instruction.
4130
4131 Large model objects may live anywhere in the 32-bit address space (the
4132 compiler generates @code{seth/add3} instructions to load their addresses),
4133 and may not be reachable with the @code{bl} instruction (the compiler
4134 generates the much slower @code{seth/add3/jl} instruction sequence).
4135 @end table
4136
4137 @node m68k Function Attributes
4138 @subsection m68k Function Attributes
4139
4140 These function attributes are supported by the m68k back end:
4141
4142 @table @code
4143 @item interrupt
4144 @itemx interrupt_handler
4145 @cindex @code{interrupt} function attribute, m68k
4146 @cindex @code{interrupt_handler} function attribute, m68k
4147 Use this attribute to
4148 indicate that the specified function is an interrupt handler. The compiler
4149 generates function entry and exit sequences suitable for use in an
4150 interrupt handler when this attribute is present. Either name may be used.
4151
4152 @item interrupt_thread
4153 @cindex @code{interrupt_thread} function attribute, fido
4154 Use this attribute on fido, a subarchitecture of the m68k, to indicate
4155 that the specified function is an interrupt handler that is designed
4156 to run as a thread. The compiler omits generate prologue/epilogue
4157 sequences and replaces the return instruction with a @code{sleep}
4158 instruction. This attribute is available only on fido.
4159 @end table
4160
4161 @node MCORE Function Attributes
4162 @subsection MCORE Function Attributes
4163
4164 These function attributes are supported by the MCORE back end:
4165
4166 @table @code
4167 @item naked
4168 @cindex @code{naked} function attribute, MCORE
4169 This attribute allows the compiler to construct the
4170 requisite function declaration, while allowing the body of the
4171 function to be assembly code. The specified function will not have
4172 prologue/epilogue sequences generated by the compiler. Only basic
4173 @code{asm} statements can safely be included in naked functions
4174 (@pxref{Basic Asm}). While using extended @code{asm} or a mixture of
4175 basic @code{asm} and C code may appear to work, they cannot be
4176 depended upon to work reliably and are not supported.
4177 @end table
4178
4179 @node MeP Function Attributes
4180 @subsection MeP Function Attributes
4181
4182 These function attributes are supported by the MeP back end:
4183
4184 @table @code
4185 @item disinterrupt
4186 @cindex @code{disinterrupt} function attribute, MeP
4187 On MeP targets, this attribute causes the compiler to emit
4188 instructions to disable interrupts for the duration of the given
4189 function.
4190
4191 @item interrupt
4192 @cindex @code{interrupt} function attribute, MeP
4193 Use this attribute to indicate
4194 that the specified function is an interrupt handler. The compiler generates
4195 function entry and exit sequences suitable for use in an interrupt handler
4196 when this attribute is present.
4197
4198 @item near
4199 @cindex @code{near} function attribute, MeP
4200 This attribute causes the compiler to assume the called
4201 function is close enough to use the normal calling convention,
4202 overriding the @option{-mtf} command-line option.
4203
4204 @item far
4205 @cindex @code{far} function attribute, MeP
4206 On MeP targets this causes the compiler to use a calling convention
4207 that assumes the called function is too far away for the built-in
4208 addressing modes.
4209
4210 @item vliw
4211 @cindex @code{vliw} function attribute, MeP
4212 The @code{vliw} attribute tells the compiler to emit
4213 instructions in VLIW mode instead of core mode. Note that this
4214 attribute is not allowed unless a VLIW coprocessor has been configured
4215 and enabled through command-line options.
4216 @end table
4217
4218 @node MicroBlaze Function Attributes
4219 @subsection MicroBlaze Function Attributes
4220
4221 These function attributes are supported on MicroBlaze targets:
4222
4223 @table @code
4224 @item save_volatiles
4225 @cindex @code{save_volatiles} function attribute, MicroBlaze
4226 Use this attribute to indicate that the function is
4227 an interrupt handler. All volatile registers (in addition to non-volatile
4228 registers) are saved in the function prologue. If the function is a leaf
4229 function, only volatiles used by the function are saved. A normal function
4230 return is generated instead of a return from interrupt.
4231
4232 @item break_handler
4233 @cindex @code{break_handler} function attribute, MicroBlaze
4234 @cindex break handler functions
4235 Use this attribute to indicate that
4236 the specified function is a break handler. The compiler generates function
4237 entry and exit sequences suitable for use in an break handler when this
4238 attribute is present. The return from @code{break_handler} is done through
4239 the @code{rtbd} instead of @code{rtsd}.
4240
4241 @smallexample
4242 void f () __attribute__ ((break_handler));
4243 @end smallexample
4244 @end table
4245
4246 @node Microsoft Windows Function Attributes
4247 @subsection Microsoft Windows Function Attributes
4248
4249 The following attributes are available on Microsoft Windows and Symbian OS
4250 targets.
4251
4252 @table @code
4253 @item dllexport
4254 @cindex @code{dllexport} function attribute
4255 @cindex @code{__declspec(dllexport)}
4256 On Microsoft Windows targets and Symbian OS targets the
4257 @code{dllexport} attribute causes the compiler to provide a global
4258 pointer to a pointer in a DLL, so that it can be referenced with the
4259 @code{dllimport} attribute. On Microsoft Windows targets, the pointer
4260 name is formed by combining @code{_imp__} and the function or variable
4261 name.
4262
4263 You can use @code{__declspec(dllexport)} as a synonym for
4264 @code{__attribute__ ((dllexport))} for compatibility with other
4265 compilers.
4266
4267 On systems that support the @code{visibility} attribute, this
4268 attribute also implies ``default'' visibility. It is an error to
4269 explicitly specify any other visibility.
4270
4271 GCC's default behavior is to emit all inline functions with the
4272 @code{dllexport} attribute. Since this can cause object file-size bloat,
4273 you can use @option{-fno-keep-inline-dllexport}, which tells GCC to
4274 ignore the attribute for inlined functions unless the
4275 @option{-fkeep-inline-functions} flag is used instead.
4276
4277 The attribute is ignored for undefined symbols.
4278
4279 When applied to C++ classes, the attribute marks defined non-inlined
4280 member functions and static data members as exports. Static consts
4281 initialized in-class are not marked unless they are also defined
4282 out-of-class.
4283
4284 For Microsoft Windows targets there are alternative methods for
4285 including the symbol in the DLL's export table such as using a
4286 @file{.def} file with an @code{EXPORTS} section or, with GNU ld, using
4287 the @option{--export-all} linker flag.
4288
4289 @item dllimport
4290 @cindex @code{dllimport} function attribute
4291 @cindex @code{__declspec(dllimport)}
4292 On Microsoft Windows and Symbian OS targets, the @code{dllimport}
4293 attribute causes the compiler to reference a function or variable via
4294 a global pointer to a pointer that is set up by the DLL exporting the
4295 symbol. The attribute implies @code{extern}. On Microsoft Windows
4296 targets, the pointer name is formed by combining @code{_imp__} and the
4297 function or variable name.
4298
4299 You can use @code{__declspec(dllimport)} as a synonym for
4300 @code{__attribute__ ((dllimport))} for compatibility with other
4301 compilers.
4302
4303 On systems that support the @code{visibility} attribute, this
4304 attribute also implies ``default'' visibility. It is an error to
4305 explicitly specify any other visibility.
4306
4307 Currently, the attribute is ignored for inlined functions. If the
4308 attribute is applied to a symbol @emph{definition}, an error is reported.
4309 If a symbol previously declared @code{dllimport} is later defined, the
4310 attribute is ignored in subsequent references, and a warning is emitted.
4311 The attribute is also overridden by a subsequent declaration as
4312 @code{dllexport}.
4313
4314 When applied to C++ classes, the attribute marks non-inlined
4315 member functions and static data members as imports. However, the
4316 attribute is ignored for virtual methods to allow creation of vtables
4317 using thunks.
4318
4319 On the SH Symbian OS target the @code{dllimport} attribute also has
4320 another affect---it can cause the vtable and run-time type information
4321 for a class to be exported. This happens when the class has a
4322 dllimported constructor or a non-inline, non-pure virtual function
4323 and, for either of those two conditions, the class also has an inline
4324 constructor or destructor and has a key function that is defined in
4325 the current translation unit.
4326
4327 For Microsoft Windows targets the use of the @code{dllimport}
4328 attribute on functions is not necessary, but provides a small
4329 performance benefit by eliminating a thunk in the DLL@. The use of the
4330 @code{dllimport} attribute on imported variables can be avoided by passing the
4331 @option{--enable-auto-import} switch to the GNU linker. As with
4332 functions, using the attribute for a variable eliminates a thunk in
4333 the DLL@.
4334
4335 One drawback to using this attribute is that a pointer to a
4336 @emph{variable} marked as @code{dllimport} cannot be used as a constant
4337 address. However, a pointer to a @emph{function} with the
4338 @code{dllimport} attribute can be used as a constant initializer; in
4339 this case, the address of a stub function in the import lib is
4340 referenced. On Microsoft Windows targets, the attribute can be disabled
4341 for functions by setting the @option{-mnop-fun-dllimport} flag.
4342 @end table
4343
4344 @node MIPS Function Attributes
4345 @subsection MIPS Function Attributes
4346
4347 These function attributes are supported by the MIPS back end:
4348
4349 @table @code
4350 @item interrupt
4351 @cindex @code{interrupt} function attribute, MIPS
4352 Use this attribute to indicate that the specified function is an interrupt
4353 handler. The compiler generates function entry and exit sequences suitable
4354 for use in an interrupt handler when this attribute is present.
4355 An optional argument is supported for the interrupt attribute which allows
4356 the interrupt mode to be described. By default GCC assumes the external
4357 interrupt controller (EIC) mode is in use, this can be explicitly set using
4358 @code{eic}. When interrupts are non-masked then the requested Interrupt
4359 Priority Level (IPL) is copied to the current IPL which has the effect of only
4360 enabling higher priority interrupts. To use vectored interrupt mode use
4361 the argument @code{vector=[sw0|sw1|hw0|hw1|hw2|hw3|hw4|hw5]}, this will change
4362 the behaviour of the non-masked interrupt support and GCC will arrange to mask
4363 all interrupts from sw0 up to and including the specified interrupt vector.
4364
4365 You can use the following attributes to modify the behavior
4366 of an interrupt handler:
4367 @table @code
4368 @item use_shadow_register_set
4369 @cindex @code{use_shadow_register_set} function attribute, MIPS
4370 Assume that the handler uses a shadow register set, instead of
4371 the main general-purpose registers. An optional argument @code{intstack} is
4372 supported to indicate that the shadow register set contains a valid stack
4373 pointer.
4374
4375 @item keep_interrupts_masked
4376 @cindex @code{keep_interrupts_masked} function attribute, MIPS
4377 Keep interrupts masked for the whole function. Without this attribute,
4378 GCC tries to reenable interrupts for as much of the function as it can.
4379
4380 @item use_debug_exception_return
4381 @cindex @code{use_debug_exception_return} function attribute, MIPS
4382 Return using the @code{deret} instruction. Interrupt handlers that don't
4383 have this attribute return using @code{eret} instead.
4384 @end table
4385
4386 You can use any combination of these attributes, as shown below:
4387 @smallexample
4388 void __attribute__ ((interrupt)) v0 ();
4389 void __attribute__ ((interrupt, use_shadow_register_set)) v1 ();
4390 void __attribute__ ((interrupt, keep_interrupts_masked)) v2 ();
4391 void __attribute__ ((interrupt, use_debug_exception_return)) v3 ();
4392 void __attribute__ ((interrupt, use_shadow_register_set,
4393 keep_interrupts_masked)) v4 ();
4394 void __attribute__ ((interrupt, use_shadow_register_set,
4395 use_debug_exception_return)) v5 ();
4396 void __attribute__ ((interrupt, keep_interrupts_masked,
4397 use_debug_exception_return)) v6 ();
4398 void __attribute__ ((interrupt, use_shadow_register_set,
4399 keep_interrupts_masked,
4400 use_debug_exception_return)) v7 ();
4401 void __attribute__ ((interrupt("eic"))) v8 ();
4402 void __attribute__ ((interrupt("vector=hw3"))) v9 ();
4403 @end smallexample
4404
4405 @item long_call
4406 @itemx near
4407 @itemx far
4408 @cindex indirect calls, MIPS
4409 @cindex @code{long_call} function attribute, MIPS
4410 @cindex @code{near} function attribute, MIPS
4411 @cindex @code{far} function attribute, MIPS
4412 These attributes specify how a particular function is called on MIPS@.
4413 The attributes override the @option{-mlong-calls} (@pxref{MIPS Options})
4414 command-line switch. The @code{long_call} and @code{far} attributes are
4415 synonyms, and cause the compiler to always call
4416 the function by first loading its address into a register, and then using
4417 the contents of that register. The @code{near} attribute has the opposite
4418 effect; it specifies that non-PIC calls should be made using the more
4419 efficient @code{jal} instruction.
4420
4421 @item mips16
4422 @itemx nomips16
4423 @cindex @code{mips16} function attribute, MIPS
4424 @cindex @code{nomips16} function attribute, MIPS
4425
4426 On MIPS targets, you can use the @code{mips16} and @code{nomips16}
4427 function attributes to locally select or turn off MIPS16 code generation.
4428 A function with the @code{mips16} attribute is emitted as MIPS16 code,
4429 while MIPS16 code generation is disabled for functions with the
4430 @code{nomips16} attribute. These attributes override the
4431 @option{-mips16} and @option{-mno-mips16} options on the command line
4432 (@pxref{MIPS Options}).
4433
4434 When compiling files containing mixed MIPS16 and non-MIPS16 code, the
4435 preprocessor symbol @code{__mips16} reflects the setting on the command line,
4436 not that within individual functions. Mixed MIPS16 and non-MIPS16 code
4437 may interact badly with some GCC extensions such as @code{__builtin_apply}
4438 (@pxref{Constructing Calls}).
4439
4440 @item micromips, MIPS
4441 @itemx nomicromips, MIPS
4442 @cindex @code{micromips} function attribute
4443 @cindex @code{nomicromips} function attribute
4444
4445 On MIPS targets, you can use the @code{micromips} and @code{nomicromips}
4446 function attributes to locally select or turn off microMIPS code generation.
4447 A function with the @code{micromips} attribute is emitted as microMIPS code,
4448 while microMIPS code generation is disabled for functions with the
4449 @code{nomicromips} attribute. These attributes override the
4450 @option{-mmicromips} and @option{-mno-micromips} options on the command line
4451 (@pxref{MIPS Options}).
4452
4453 When compiling files containing mixed microMIPS and non-microMIPS code, the
4454 preprocessor symbol @code{__mips_micromips} reflects the setting on the
4455 command line,
4456 not that within individual functions. Mixed microMIPS and non-microMIPS code
4457 may interact badly with some GCC extensions such as @code{__builtin_apply}
4458 (@pxref{Constructing Calls}).
4459
4460 @item nocompression
4461 @cindex @code{nocompression} function attribute, MIPS
4462 On MIPS targets, you can use the @code{nocompression} function attribute
4463 to locally turn off MIPS16 and microMIPS code generation. This attribute
4464 overrides the @option{-mips16} and @option{-mmicromips} options on the
4465 command line (@pxref{MIPS Options}).
4466 @end table
4467
4468 @node MSP430 Function Attributes
4469 @subsection MSP430 Function Attributes
4470
4471 These function attributes are supported by the MSP430 back end:
4472
4473 @table @code
4474 @item critical
4475 @cindex @code{critical} function attribute, MSP430
4476 Critical functions disable interrupts upon entry and restore the
4477 previous interrupt state upon exit. Critical functions cannot also
4478 have the @code{naked} or @code{reentrant} attributes. They can have
4479 the @code{interrupt} attribute.
4480
4481 @item interrupt
4482 @cindex @code{interrupt} function attribute, MSP430
4483 Use this attribute to indicate
4484 that the specified function is an interrupt handler. The compiler generates
4485 function entry and exit sequences suitable for use in an interrupt handler
4486 when this attribute is present.
4487
4488 You can provide an argument to the interrupt
4489 attribute which specifies a name or number. If the argument is a
4490 number it indicates the slot in the interrupt vector table (0 - 31) to
4491 which this handler should be assigned. If the argument is a name it
4492 is treated as a symbolic name for the vector slot. These names should
4493 match up with appropriate entries in the linker script. By default
4494 the names @code{watchdog} for vector 26, @code{nmi} for vector 30 and
4495 @code{reset} for vector 31 are recognized.
4496
4497 @item naked
4498 @cindex @code{naked} function attribute, MSP430
4499 This attribute allows the compiler to construct the
4500 requisite function declaration, while allowing the body of the
4501 function to be assembly code. The specified function will not have
4502 prologue/epilogue sequences generated by the compiler. Only basic
4503 @code{asm} statements can safely be included in naked functions
4504 (@pxref{Basic Asm}). While using extended @code{asm} or a mixture of
4505 basic @code{asm} and C code may appear to work, they cannot be
4506 depended upon to work reliably and are not supported.
4507
4508 @item reentrant
4509 @cindex @code{reentrant} function attribute, MSP430
4510 Reentrant functions disable interrupts upon entry and enable them
4511 upon exit. Reentrant functions cannot also have the @code{naked}
4512 or @code{critical} attributes. They can have the @code{interrupt}
4513 attribute.
4514
4515 @item wakeup
4516 @cindex @code{wakeup} function attribute, MSP430
4517 This attribute only applies to interrupt functions. It is silently
4518 ignored if applied to a non-interrupt function. A wakeup interrupt
4519 function will rouse the processor from any low-power state that it
4520 might be in when the function exits.
4521 @end table
4522
4523 @node NDS32 Function Attributes
4524 @subsection NDS32 Function Attributes
4525
4526 These function attributes are supported by the NDS32 back end:
4527
4528 @table @code
4529 @item exception
4530 @cindex @code{exception} function attribute
4531 @cindex exception handler functions, NDS32
4532 Use this attribute on the NDS32 target to indicate that the specified function
4533 is an exception handler. The compiler will generate corresponding sections
4534 for use in an exception handler.
4535
4536 @item interrupt
4537 @cindex @code{interrupt} function attribute, NDS32
4538 On NDS32 target, this attribute indicates that the specified function
4539 is an interrupt handler. The compiler generates corresponding sections
4540 for use in an interrupt handler. You can use the following attributes
4541 to modify the behavior:
4542 @table @code
4543 @item nested
4544 @cindex @code{nested} function attribute, NDS32
4545 This interrupt service routine is interruptible.
4546 @item not_nested
4547 @cindex @code{not_nested} function attribute, NDS32
4548 This interrupt service routine is not interruptible.
4549 @item nested_ready
4550 @cindex @code{nested_ready} function attribute, NDS32
4551 This interrupt service routine is interruptible after @code{PSW.GIE}
4552 (global interrupt enable) is set. This allows interrupt service routine to
4553 finish some short critical code before enabling interrupts.
4554 @item save_all
4555 @cindex @code{save_all} function attribute, NDS32
4556 The system will help save all registers into stack before entering
4557 interrupt handler.
4558 @item partial_save
4559 @cindex @code{partial_save} function attribute, NDS32
4560 The system will help save caller registers into stack before entering
4561 interrupt handler.
4562 @end table
4563
4564 @item naked
4565 @cindex @code{naked} function attribute, NDS32
4566 This attribute allows the compiler to construct the
4567 requisite function declaration, while allowing the body of the
4568 function to be assembly code. The specified function will not have
4569 prologue/epilogue sequences generated by the compiler. Only basic
4570 @code{asm} statements can safely be included in naked functions
4571 (@pxref{Basic Asm}). While using extended @code{asm} or a mixture of
4572 basic @code{asm} and C code may appear to work, they cannot be
4573 depended upon to work reliably and are not supported.
4574
4575 @item reset
4576 @cindex @code{reset} function attribute, NDS32
4577 @cindex reset handler functions
4578 Use this attribute on the NDS32 target to indicate that the specified function
4579 is a reset handler. The compiler will generate corresponding sections
4580 for use in a reset handler. You can use the following attributes
4581 to provide extra exception handling:
4582 @table @code
4583 @item nmi
4584 @cindex @code{nmi} function attribute, NDS32
4585 Provide a user-defined function to handle NMI exception.
4586 @item warm
4587 @cindex @code{warm} function attribute, NDS32
4588 Provide a user-defined function to handle warm reset exception.
4589 @end table
4590 @end table
4591
4592 @node Nios II Function Attributes
4593 @subsection Nios II Function Attributes
4594
4595 These function attributes are supported by the Nios II back end:
4596
4597 @table @code
4598 @item target (@var{options})
4599 @cindex @code{target} function attribute
4600 As discussed in @ref{Common Function Attributes}, this attribute
4601 allows specification of target-specific compilation options.
4602
4603 When compiling for Nios II, the following options are allowed:
4604
4605 @table @samp
4606 @item custom-@var{insn}=@var{N}
4607 @itemx no-custom-@var{insn}
4608 @cindex @code{target("custom-@var{insn}=@var{N}")} function attribute, Nios II
4609 @cindex @code{target("no-custom-@var{insn}")} function attribute, Nios II
4610 Each @samp{custom-@var{insn}=@var{N}} attribute locally enables use of a
4611 custom instruction with encoding @var{N} when generating code that uses
4612 @var{insn}. Similarly, @samp{no-custom-@var{insn}} locally inhibits use of
4613 the custom instruction @var{insn}.
4614 These target attributes correspond to the
4615 @option{-mcustom-@var{insn}=@var{N}} and @option{-mno-custom-@var{insn}}
4616 command-line options, and support the same set of @var{insn} keywords.
4617 @xref{Nios II Options}, for more information.
4618
4619 @item custom-fpu-cfg=@var{name}
4620 @cindex @code{target("custom-fpu-cfg=@var{name}")} function attribute, Nios II
4621 This attribute corresponds to the @option{-mcustom-fpu-cfg=@var{name}}
4622 command-line option, to select a predefined set of custom instructions
4623 named @var{name}.
4624 @xref{Nios II Options}, for more information.
4625 @end table
4626 @end table
4627
4628 @node PowerPC Function Attributes
4629 @subsection PowerPC Function Attributes
4630
4631 These function attributes are supported by the PowerPC back end:
4632
4633 @table @code
4634 @item longcall
4635 @itemx shortcall
4636 @cindex indirect calls, PowerPC
4637 @cindex @code{longcall} function attribute, PowerPC
4638 @cindex @code{shortcall} function attribute, PowerPC
4639 The @code{longcall} attribute
4640 indicates that the function might be far away from the call site and
4641 require a different (more expensive) calling sequence. The
4642 @code{shortcall} attribute indicates that the function is always close
4643 enough for the shorter calling sequence to be used. These attributes
4644 override both the @option{-mlongcall} switch and
4645 the @code{#pragma longcall} setting.
4646
4647 @xref{RS/6000 and PowerPC Options}, for more information on whether long
4648 calls are necessary.
4649
4650 @item target (@var{options})
4651 @cindex @code{target} function attribute
4652 As discussed in @ref{Common Function Attributes}, this attribute
4653 allows specification of target-specific compilation options.
4654
4655 On the PowerPC, the following options are allowed:
4656
4657 @table @samp
4658 @item altivec
4659 @itemx no-altivec
4660 @cindex @code{target("altivec")} function attribute, PowerPC
4661 Generate code that uses (does not use) AltiVec instructions. In
4662 32-bit code, you cannot enable AltiVec instructions unless
4663 @option{-mabi=altivec} is used on the command line.
4664
4665 @item cmpb
4666 @itemx no-cmpb
4667 @cindex @code{target("cmpb")} function attribute, PowerPC
4668 Generate code that uses (does not use) the compare bytes instruction
4669 implemented on the POWER6 processor and other processors that support
4670 the PowerPC V2.05 architecture.
4671
4672 @item dlmzb
4673 @itemx no-dlmzb
4674 @cindex @code{target("dlmzb")} function attribute, PowerPC
4675 Generate code that uses (does not use) the string-search @samp{dlmzb}
4676 instruction on the IBM 405, 440, 464 and 476 processors. This instruction is
4677 generated by default when targeting those processors.
4678
4679 @item fprnd
4680 @itemx no-fprnd
4681 @cindex @code{target("fprnd")} function attribute, PowerPC
4682 Generate code that uses (does not use) the FP round to integer
4683 instructions implemented on the POWER5+ processor and other processors
4684 that support the PowerPC V2.03 architecture.
4685
4686 @item hard-dfp
4687 @itemx no-hard-dfp
4688 @cindex @code{target("hard-dfp")} function attribute, PowerPC
4689 Generate code that uses (does not use) the decimal floating-point
4690 instructions implemented on some POWER processors.
4691
4692 @item isel
4693 @itemx no-isel
4694 @cindex @code{target("isel")} function attribute, PowerPC
4695 Generate code that uses (does not use) ISEL instruction.
4696
4697 @item mfcrf
4698 @itemx no-mfcrf
4699 @cindex @code{target("mfcrf")} function attribute, PowerPC
4700 Generate code that uses (does not use) the move from condition
4701 register field instruction implemented on the POWER4 processor and
4702 other processors that support the PowerPC V2.01 architecture.
4703
4704 @item mfpgpr
4705 @itemx no-mfpgpr
4706 @cindex @code{target("mfpgpr")} function attribute, PowerPC
4707 Generate code that uses (does not use) the FP move to/from general
4708 purpose register instructions implemented on the POWER6X processor and
4709 other processors that support the extended PowerPC V2.05 architecture.
4710
4711 @item mulhw
4712 @itemx no-mulhw
4713 @cindex @code{target("mulhw")} function attribute, PowerPC
4714 Generate code that uses (does not use) the half-word multiply and
4715 multiply-accumulate instructions on the IBM 405, 440, 464 and 476 processors.
4716 These instructions are generated by default when targeting those
4717 processors.
4718
4719 @item multiple
4720 @itemx no-multiple
4721 @cindex @code{target("multiple")} function attribute, PowerPC
4722 Generate code that uses (does not use) the load multiple word
4723 instructions and the store multiple word instructions.
4724
4725 @item update
4726 @itemx no-update
4727 @cindex @code{target("update")} function attribute, PowerPC
4728 Generate code that uses (does not use) the load or store instructions
4729 that update the base register to the address of the calculated memory
4730 location.
4731
4732 @item popcntb
4733 @itemx no-popcntb
4734 @cindex @code{target("popcntb")} function attribute, PowerPC
4735 Generate code that uses (does not use) the popcount and double-precision
4736 FP reciprocal estimate instruction implemented on the POWER5
4737 processor and other processors that support the PowerPC V2.02
4738 architecture.
4739
4740 @item popcntd
4741 @itemx no-popcntd
4742 @cindex @code{target("popcntd")} function attribute, PowerPC
4743 Generate code that uses (does not use) the popcount instruction
4744 implemented on the POWER7 processor and other processors that support
4745 the PowerPC V2.06 architecture.
4746
4747 @item powerpc-gfxopt
4748 @itemx no-powerpc-gfxopt
4749 @cindex @code{target("powerpc-gfxopt")} function attribute, PowerPC
4750 Generate code that uses (does not use) the optional PowerPC
4751 architecture instructions in the Graphics group, including
4752 floating-point select.
4753
4754 @item powerpc-gpopt
4755 @itemx no-powerpc-gpopt
4756 @cindex @code{target("powerpc-gpopt")} function attribute, PowerPC
4757 Generate code that uses (does not use) the optional PowerPC
4758 architecture instructions in the General Purpose group, including
4759 floating-point square root.
4760
4761 @item recip-precision
4762 @itemx no-recip-precision
4763 @cindex @code{target("recip-precision")} function attribute, PowerPC
4764 Assume (do not assume) that the reciprocal estimate instructions
4765 provide higher-precision estimates than is mandated by the PowerPC
4766 ABI.
4767
4768 @item string
4769 @itemx no-string
4770 @cindex @code{target("string")} function attribute, PowerPC
4771 Generate code that uses (does not use) the load string instructions
4772 and the store string word instructions to save multiple registers and
4773 do small block moves.
4774
4775 @item vsx
4776 @itemx no-vsx
4777 @cindex @code{target("vsx")} function attribute, PowerPC
4778 Generate code that uses (does not use) vector/scalar (VSX)
4779 instructions, and also enable the use of built-in functions that allow
4780 more direct access to the VSX instruction set. In 32-bit code, you
4781 cannot enable VSX or AltiVec instructions unless
4782 @option{-mabi=altivec} is used on the command line.
4783
4784 @item friz
4785 @itemx no-friz
4786 @cindex @code{target("friz")} function attribute, PowerPC
4787 Generate (do not generate) the @code{friz} instruction when the
4788 @option{-funsafe-math-optimizations} option is used to optimize
4789 rounding a floating-point value to 64-bit integer and back to floating
4790 point. The @code{friz} instruction does not return the same value if
4791 the floating-point number is too large to fit in an integer.
4792
4793 @item avoid-indexed-addresses
4794 @itemx no-avoid-indexed-addresses
4795 @cindex @code{target("avoid-indexed-addresses")} function attribute, PowerPC
4796 Generate code that tries to avoid (not avoid) the use of indexed load
4797 or store instructions.
4798
4799 @item paired
4800 @itemx no-paired
4801 @cindex @code{target("paired")} function attribute, PowerPC
4802 Generate code that uses (does not use) the generation of PAIRED simd
4803 instructions.
4804
4805 @item longcall
4806 @itemx no-longcall
4807 @cindex @code{target("longcall")} function attribute, PowerPC
4808 Generate code that assumes (does not assume) that all calls are far
4809 away so that a longer more expensive calling sequence is required.
4810
4811 @item cpu=@var{CPU}
4812 @cindex @code{target("cpu=@var{CPU}")} function attribute, PowerPC
4813 Specify the architecture to generate code for when compiling the
4814 function. If you select the @code{target("cpu=power7")} attribute when
4815 generating 32-bit code, VSX and AltiVec instructions are not generated
4816 unless you use the @option{-mabi=altivec} option on the command line.
4817
4818 @item tune=@var{TUNE}
4819 @cindex @code{target("tune=@var{TUNE}")} function attribute, PowerPC
4820 Specify the architecture to tune for when compiling the function. If
4821 you do not specify the @code{target("tune=@var{TUNE}")} attribute and
4822 you do specify the @code{target("cpu=@var{CPU}")} attribute,
4823 compilation tunes for the @var{CPU} architecture, and not the
4824 default tuning specified on the command line.
4825 @end table
4826
4827 On the PowerPC, the inliner does not inline a
4828 function that has different target options than the caller, unless the
4829 callee has a subset of the target options of the caller.
4830 @end table
4831
4832 @node RL78 Function Attributes
4833 @subsection RL78 Function Attributes
4834
4835 These function attributes are supported by the RL78 back end:
4836
4837 @table @code
4838 @item interrupt
4839 @itemx brk_interrupt
4840 @cindex @code{interrupt} function attribute, RL78
4841 @cindex @code{brk_interrupt} function attribute, RL78
4842 These attributes indicate
4843 that the specified function is an interrupt handler. The compiler generates
4844 function entry and exit sequences suitable for use in an interrupt handler
4845 when this attribute is present.
4846
4847 Use @code{brk_interrupt} instead of @code{interrupt} for
4848 handlers intended to be used with the @code{BRK} opcode (i.e.@: those
4849 that must end with @code{RETB} instead of @code{RETI}).
4850
4851 @item naked
4852 @cindex @code{naked} function attribute, RL78
4853 This attribute allows the compiler to construct the
4854 requisite function declaration, while allowing the body of the
4855 function to be assembly code. The specified function will not have
4856 prologue/epilogue sequences generated by the compiler. Only basic
4857 @code{asm} statements can safely be included in naked functions
4858 (@pxref{Basic Asm}). While using extended @code{asm} or a mixture of
4859 basic @code{asm} and C code may appear to work, they cannot be
4860 depended upon to work reliably and are not supported.
4861 @end table
4862
4863 @node RX Function Attributes
4864 @subsection RX Function Attributes
4865
4866 These function attributes are supported by the RX back end:
4867
4868 @table @code
4869 @item fast_interrupt
4870 @cindex @code{fast_interrupt} function attribute, RX
4871 Use this attribute on the RX port to indicate that the specified
4872 function is a fast interrupt handler. This is just like the
4873 @code{interrupt} attribute, except that @code{freit} is used to return
4874 instead of @code{reit}.
4875
4876 @item interrupt
4877 @cindex @code{interrupt} function attribute, RX
4878 Use this attribute to indicate
4879 that the specified function is an interrupt handler. The compiler generates
4880 function entry and exit sequences suitable for use in an interrupt handler
4881 when this attribute is present.
4882
4883 On RX targets, you may specify one or more vector numbers as arguments
4884 to the attribute, as well as naming an alternate table name.
4885 Parameters are handled sequentially, so one handler can be assigned to
4886 multiple entries in multiple tables. One may also pass the magic
4887 string @code{"$default"} which causes the function to be used for any
4888 unfilled slots in the current table.
4889
4890 This example shows a simple assignment of a function to one vector in
4891 the default table (note that preprocessor macros may be used for
4892 chip-specific symbolic vector names):
4893 @smallexample
4894 void __attribute__ ((interrupt (5))) txd1_handler ();
4895 @end smallexample
4896
4897 This example assigns a function to two slots in the default table
4898 (using preprocessor macros defined elsewhere) and makes it the default
4899 for the @code{dct} table:
4900 @smallexample
4901 void __attribute__ ((interrupt (RXD1_VECT,RXD2_VECT,"dct","$default")))
4902 txd1_handler ();
4903 @end smallexample
4904
4905 @item naked
4906 @cindex @code{naked} function attribute, RX
4907 This attribute allows the compiler to construct the
4908 requisite function declaration, while allowing the body of the
4909 function to be assembly code. The specified function will not have
4910 prologue/epilogue sequences generated by the compiler. Only basic
4911 @code{asm} statements can safely be included in naked functions
4912 (@pxref{Basic Asm}). While using extended @code{asm} or a mixture of
4913 basic @code{asm} and C code may appear to work, they cannot be
4914 depended upon to work reliably and are not supported.
4915
4916 @item vector
4917 @cindex @code{vector} function attribute, RX
4918 This RX attribute is similar to the @code{interrupt} attribute, including its
4919 parameters, but does not make the function an interrupt-handler type
4920 function (i.e. it retains the normal C function calling ABI). See the
4921 @code{interrupt} attribute for a description of its arguments.
4922 @end table
4923
4924 @node S/390 Function Attributes
4925 @subsection S/390 Function Attributes
4926
4927 These function attributes are supported on the S/390:
4928
4929 @table @code
4930 @item hotpatch (@var{halfwords-before-function-label},@var{halfwords-after-function-label})
4931 @cindex @code{hotpatch} function attribute, S/390
4932
4933 On S/390 System z targets, you can use this function attribute to
4934 make GCC generate a ``hot-patching'' function prologue. If the
4935 @option{-mhotpatch=} command-line option is used at the same time,
4936 the @code{hotpatch} attribute takes precedence. The first of the
4937 two arguments specifies the number of halfwords to be added before
4938 the function label. A second argument can be used to specify the
4939 number of halfwords to be added after the function label. For
4940 both arguments the maximum allowed value is 1000000.
4941
4942 If both arguments are zero, hotpatching is disabled.
4943 @end table
4944
4945 @node SH Function Attributes
4946 @subsection SH Function Attributes
4947
4948 These function attributes are supported on the SH family of processors:
4949
4950 @table @code
4951 @item function_vector
4952 @cindex @code{function_vector} function attribute, SH
4953 @cindex calling functions through the function vector on SH2A
4954 On SH2A targets, this attribute declares a function to be called using the
4955 TBR relative addressing mode. The argument to this attribute is the entry
4956 number of the same function in a vector table containing all the TBR
4957 relative addressable functions. For correct operation the TBR must be setup
4958 accordingly to point to the start of the vector table before any functions with
4959 this attribute are invoked. Usually a good place to do the initialization is
4960 the startup routine. The TBR relative vector table can have at max 256 function
4961 entries. The jumps to these functions are generated using a SH2A specific,
4962 non delayed branch instruction JSR/N @@(disp8,TBR). You must use GAS and GLD
4963 from GNU binutils version 2.7 or later for this attribute to work correctly.
4964
4965 In an application, for a function being called once, this attribute
4966 saves at least 8 bytes of code; and if other successive calls are being
4967 made to the same function, it saves 2 bytes of code per each of these
4968 calls.
4969
4970 @item interrupt_handler
4971 @cindex @code{interrupt_handler} function attribute, SH
4972 Use this attribute to
4973 indicate that the specified function is an interrupt handler. The compiler
4974 generates function entry and exit sequences suitable for use in an
4975 interrupt handler when this attribute is present.
4976
4977 @item nosave_low_regs
4978 @cindex @code{nosave_low_regs} function attribute, SH
4979 Use this attribute on SH targets to indicate that an @code{interrupt_handler}
4980 function should not save and restore registers R0..R7. This can be used on SH3*
4981 and SH4* targets that have a second R0..R7 register bank for non-reentrant
4982 interrupt handlers.
4983
4984 @item renesas
4985 @cindex @code{renesas} function attribute, SH
4986 On SH targets this attribute specifies that the function or struct follows the
4987 Renesas ABI.
4988
4989 @item resbank
4990 @cindex @code{resbank} function attribute, SH
4991 On the SH2A target, this attribute enables the high-speed register
4992 saving and restoration using a register bank for @code{interrupt_handler}
4993 routines. Saving to the bank is performed automatically after the CPU
4994 accepts an interrupt that uses a register bank.
4995
4996 The nineteen 32-bit registers comprising general register R0 to R14,
4997 control register GBR, and system registers MACH, MACL, and PR and the
4998 vector table address offset are saved into a register bank. Register
4999 banks are stacked in first-in last-out (FILO) sequence. Restoration
5000 from the bank is executed by issuing a RESBANK instruction.
5001
5002 @item sp_switch
5003 @cindex @code{sp_switch} function attribute, SH
5004 Use this attribute on the SH to indicate an @code{interrupt_handler}
5005 function should switch to an alternate stack. It expects a string
5006 argument that names a global variable holding the address of the
5007 alternate stack.
5008
5009 @smallexample
5010 void *alt_stack;
5011 void f () __attribute__ ((interrupt_handler,
5012 sp_switch ("alt_stack")));
5013 @end smallexample
5014
5015 @item trap_exit
5016 @cindex @code{trap_exit} function attribute, SH
5017 Use this attribute on the SH for an @code{interrupt_handler} to return using
5018 @code{trapa} instead of @code{rte}. This attribute expects an integer
5019 argument specifying the trap number to be used.
5020
5021 @item trapa_handler
5022 @cindex @code{trapa_handler} function attribute, SH
5023 On SH targets this function attribute is similar to @code{interrupt_handler}
5024 but it does not save and restore all registers.
5025 @end table
5026
5027 @node SPU Function Attributes
5028 @subsection SPU Function Attributes
5029
5030 These function attributes are supported by the SPU back end:
5031
5032 @table @code
5033 @item naked
5034 @cindex @code{naked} function attribute, SPU
5035 This attribute allows the compiler to construct the
5036 requisite function declaration, while allowing the body of the
5037 function to be assembly code. The specified function will not have
5038 prologue/epilogue sequences generated by the compiler. Only basic
5039 @code{asm} statements can safely be included in naked functions
5040 (@pxref{Basic Asm}). While using extended @code{asm} or a mixture of
5041 basic @code{asm} and C code may appear to work, they cannot be
5042 depended upon to work reliably and are not supported.
5043 @end table
5044
5045 @node Symbian OS Function Attributes
5046 @subsection Symbian OS Function Attributes
5047
5048 @xref{Microsoft Windows Function Attributes}, for discussion of the
5049 @code{dllexport} and @code{dllimport} attributes.
5050
5051 @node Visium Function Attributes
5052 @subsection Visium Function Attributes
5053
5054 These function attributes are supported by the Visium back end:
5055
5056 @table @code
5057 @item interrupt
5058 @cindex @code{interrupt} function attribute, Visium
5059 Use this attribute to indicate
5060 that the specified function is an interrupt handler. The compiler generates
5061 function entry and exit sequences suitable for use in an interrupt handler
5062 when this attribute is present.
5063 @end table
5064
5065 @node x86 Function Attributes
5066 @subsection x86 Function Attributes
5067
5068 These function attributes are supported by the x86 back end:
5069
5070 @table @code
5071 @item cdecl
5072 @cindex @code{cdecl} function attribute, x86-32
5073 @cindex functions that pop the argument stack on x86-32
5074 @opindex mrtd
5075 On the x86-32 targets, the @code{cdecl} attribute causes the compiler to
5076 assume that the calling function pops off the stack space used to
5077 pass arguments. This is
5078 useful to override the effects of the @option{-mrtd} switch.
5079
5080 @item fastcall
5081 @cindex @code{fastcall} function attribute, x86-32
5082 @cindex functions that pop the argument stack on x86-32
5083 On x86-32 targets, the @code{fastcall} attribute causes the compiler to
5084 pass the first argument (if of integral type) in the register ECX and
5085 the second argument (if of integral type) in the register EDX@. Subsequent
5086 and other typed arguments are passed on the stack. The called function
5087 pops the arguments off the stack. If the number of arguments is variable all
5088 arguments are pushed on the stack.
5089
5090 @item thiscall
5091 @cindex @code{thiscall} function attribute, x86-32
5092 @cindex functions that pop the argument stack on x86-32
5093 On x86-32 targets, the @code{thiscall} attribute causes the compiler to
5094 pass the first argument (if of integral type) in the register ECX.
5095 Subsequent and other typed arguments are passed on the stack. The called
5096 function pops the arguments off the stack.
5097 If the number of arguments is variable all arguments are pushed on the
5098 stack.
5099 The @code{thiscall} attribute is intended for C++ non-static member functions.
5100 As a GCC extension, this calling convention can be used for C functions
5101 and for static member methods.
5102
5103 @item ms_abi
5104 @itemx sysv_abi
5105 @cindex @code{ms_abi} function attribute, x86
5106 @cindex @code{sysv_abi} function attribute, x86
5107
5108 On 32-bit and 64-bit x86 targets, you can use an ABI attribute
5109 to indicate which calling convention should be used for a function. The
5110 @code{ms_abi} attribute tells the compiler to use the Microsoft ABI,
5111 while the @code{sysv_abi} attribute tells the compiler to use the ABI
5112 used on GNU/Linux and other systems. The default is to use the Microsoft ABI
5113 when targeting Windows. On all other systems, the default is the x86/AMD ABI.
5114
5115 Note, the @code{ms_abi} attribute for Microsoft Windows 64-bit targets currently
5116 requires the @option{-maccumulate-outgoing-args} option.
5117
5118 @item callee_pop_aggregate_return (@var{number})
5119 @cindex @code{callee_pop_aggregate_return} function attribute, x86
5120
5121 On x86-32 targets, you can use this attribute to control how
5122 aggregates are returned in memory. If the caller is responsible for
5123 popping the hidden pointer together with the rest of the arguments, specify
5124 @var{number} equal to zero. If callee is responsible for popping the
5125 hidden pointer, specify @var{number} equal to one.
5126
5127 The default x86-32 ABI assumes that the callee pops the
5128 stack for hidden pointer. However, on x86-32 Microsoft Windows targets,
5129 the compiler assumes that the
5130 caller pops the stack for hidden pointer.
5131
5132 @item ms_hook_prologue
5133 @cindex @code{ms_hook_prologue} function attribute, x86
5134
5135 On 32-bit and 64-bit x86 targets, you can use
5136 this function attribute to make GCC generate the ``hot-patching'' function
5137 prologue used in Win32 API functions in Microsoft Windows XP Service Pack 2
5138 and newer.
5139
5140 @item regparm (@var{number})
5141 @cindex @code{regparm} function attribute, x86
5142 @cindex functions that are passed arguments in registers on x86-32
5143 On x86-32 targets, the @code{regparm} attribute causes the compiler to
5144 pass arguments number one to @var{number} if they are of integral type
5145 in registers EAX, EDX, and ECX instead of on the stack. Functions that
5146 take a variable number of arguments continue to be passed all of their
5147 arguments on the stack.
5148
5149 Beware that on some ELF systems this attribute is unsuitable for
5150 global functions in shared libraries with lazy binding (which is the
5151 default). Lazy binding sends the first call via resolving code in
5152 the loader, which might assume EAX, EDX and ECX can be clobbered, as
5153 per the standard calling conventions. Solaris 8 is affected by this.
5154 Systems with the GNU C Library version 2.1 or higher
5155 and FreeBSD are believed to be
5156 safe since the loaders there save EAX, EDX and ECX. (Lazy binding can be
5157 disabled with the linker or the loader if desired, to avoid the
5158 problem.)
5159
5160 @item sseregparm
5161 @cindex @code{sseregparm} function attribute, x86
5162 On x86-32 targets with SSE support, the @code{sseregparm} attribute
5163 causes the compiler to pass up to 3 floating-point arguments in
5164 SSE registers instead of on the stack. Functions that take a
5165 variable number of arguments continue to pass all of their
5166 floating-point arguments on the stack.
5167
5168 @item force_align_arg_pointer
5169 @cindex @code{force_align_arg_pointer} function attribute, x86
5170 On x86 targets, the @code{force_align_arg_pointer} attribute may be
5171 applied to individual function definitions, generating an alternate
5172 prologue and epilogue that realigns the run-time stack if necessary.
5173 This supports mixing legacy codes that run with a 4-byte aligned stack
5174 with modern codes that keep a 16-byte stack for SSE compatibility.
5175
5176 @item stdcall
5177 @cindex @code{stdcall} function attribute, x86-32
5178 @cindex functions that pop the argument stack on x86-32
5179 On x86-32 targets, the @code{stdcall} attribute causes the compiler to
5180 assume that the called function pops off the stack space used to
5181 pass arguments, unless it takes a variable number of arguments.
5182
5183 @item target (@var{options})
5184 @cindex @code{target} function attribute
5185 As discussed in @ref{Common Function Attributes}, this attribute
5186 allows specification of target-specific compilation options.
5187
5188 On the x86, the following options are allowed:
5189 @table @samp
5190 @item abm
5191 @itemx no-abm
5192 @cindex @code{target("abm")} function attribute, x86
5193 Enable/disable the generation of the advanced bit instructions.
5194
5195 @item aes
5196 @itemx no-aes
5197 @cindex @code{target("aes")} function attribute, x86
5198 Enable/disable the generation of the AES instructions.
5199
5200 @item default
5201 @cindex @code{target("default")} function attribute, x86
5202 @xref{Function Multiversioning}, where it is used to specify the
5203 default function version.
5204
5205 @item mmx
5206 @itemx no-mmx
5207 @cindex @code{target("mmx")} function attribute, x86
5208 Enable/disable the generation of the MMX instructions.
5209
5210 @item pclmul
5211 @itemx no-pclmul
5212 @cindex @code{target("pclmul")} function attribute, x86
5213 Enable/disable the generation of the PCLMUL instructions.
5214
5215 @item popcnt
5216 @itemx no-popcnt
5217 @cindex @code{target("popcnt")} function attribute, x86
5218 Enable/disable the generation of the POPCNT instruction.
5219
5220 @item sse
5221 @itemx no-sse
5222 @cindex @code{target("sse")} function attribute, x86
5223 Enable/disable the generation of the SSE instructions.
5224
5225 @item sse2
5226 @itemx no-sse2
5227 @cindex @code{target("sse2")} function attribute, x86
5228 Enable/disable the generation of the SSE2 instructions.
5229
5230 @item sse3
5231 @itemx no-sse3
5232 @cindex @code{target("sse3")} function attribute, x86
5233 Enable/disable the generation of the SSE3 instructions.
5234
5235 @item sse4
5236 @itemx no-sse4
5237 @cindex @code{target("sse4")} function attribute, x86
5238 Enable/disable the generation of the SSE4 instructions (both SSE4.1
5239 and SSE4.2).
5240
5241 @item sse4.1
5242 @itemx no-sse4.1
5243 @cindex @code{target("sse4.1")} function attribute, x86
5244 Enable/disable the generation of the sse4.1 instructions.
5245
5246 @item sse4.2
5247 @itemx no-sse4.2
5248 @cindex @code{target("sse4.2")} function attribute, x86
5249 Enable/disable the generation of the sse4.2 instructions.
5250
5251 @item sse4a
5252 @itemx no-sse4a
5253 @cindex @code{target("sse4a")} function attribute, x86
5254 Enable/disable the generation of the SSE4A instructions.
5255
5256 @item fma4
5257 @itemx no-fma4
5258 @cindex @code{target("fma4")} function attribute, x86
5259 Enable/disable the generation of the FMA4 instructions.
5260
5261 @item xop
5262 @itemx no-xop
5263 @cindex @code{target("xop")} function attribute, x86
5264 Enable/disable the generation of the XOP instructions.
5265
5266 @item lwp
5267 @itemx no-lwp
5268 @cindex @code{target("lwp")} function attribute, x86
5269 Enable/disable the generation of the LWP instructions.
5270
5271 @item ssse3
5272 @itemx no-ssse3
5273 @cindex @code{target("ssse3")} function attribute, x86
5274 Enable/disable the generation of the SSSE3 instructions.
5275
5276 @item cld
5277 @itemx no-cld
5278 @cindex @code{target("cld")} function attribute, x86
5279 Enable/disable the generation of the CLD before string moves.
5280
5281 @item fancy-math-387
5282 @itemx no-fancy-math-387
5283 @cindex @code{target("fancy-math-387")} function attribute, x86
5284 Enable/disable the generation of the @code{sin}, @code{cos}, and
5285 @code{sqrt} instructions on the 387 floating-point unit.
5286
5287 @item fused-madd
5288 @itemx no-fused-madd
5289 @cindex @code{target("fused-madd")} function attribute, x86
5290 Enable/disable the generation of the fused multiply/add instructions.
5291
5292 @item ieee-fp
5293 @itemx no-ieee-fp
5294 @cindex @code{target("ieee-fp")} function attribute, x86
5295 Enable/disable the generation of floating point that depends on IEEE arithmetic.
5296
5297 @item inline-all-stringops
5298 @itemx no-inline-all-stringops
5299 @cindex @code{target("inline-all-stringops")} function attribute, x86
5300 Enable/disable inlining of string operations.
5301
5302 @item inline-stringops-dynamically
5303 @itemx no-inline-stringops-dynamically
5304 @cindex @code{target("inline-stringops-dynamically")} function attribute, x86
5305 Enable/disable the generation of the inline code to do small string
5306 operations and calling the library routines for large operations.
5307
5308 @item align-stringops
5309 @itemx no-align-stringops
5310 @cindex @code{target("align-stringops")} function attribute, x86
5311 Do/do not align destination of inlined string operations.
5312
5313 @item recip
5314 @itemx no-recip
5315 @cindex @code{target("recip")} function attribute, x86
5316 Enable/disable the generation of RCPSS, RCPPS, RSQRTSS and RSQRTPS
5317 instructions followed an additional Newton-Raphson step instead of
5318 doing a floating-point division.
5319
5320 @item arch=@var{ARCH}
5321 @cindex @code{target("arch=@var{ARCH}")} function attribute, x86
5322 Specify the architecture to generate code for in compiling the function.
5323
5324 @item tune=@var{TUNE}
5325 @cindex @code{target("tune=@var{TUNE}")} function attribute, x86
5326 Specify the architecture to tune for in compiling the function.
5327
5328 @item fpmath=@var{FPMATH}
5329 @cindex @code{target("fpmath=@var{FPMATH}")} function attribute, x86
5330 Specify which floating-point unit to use. You must specify the
5331 @code{target("fpmath=sse,387")} option as
5332 @code{target("fpmath=sse+387")} because the comma would separate
5333 different options.
5334 @end table
5335
5336 On the x86, the inliner does not inline a
5337 function that has different target options than the caller, unless the
5338 callee has a subset of the target options of the caller. For example
5339 a function declared with @code{target("sse3")} can inline a function
5340 with @code{target("sse2")}, since @code{-msse3} implies @code{-msse2}.
5341 @end table
5342
5343 @node Xstormy16 Function Attributes
5344 @subsection Xstormy16 Function Attributes
5345
5346 These function attributes are supported by the Xstormy16 back end:
5347
5348 @table @code
5349 @item interrupt
5350 @cindex @code{interrupt} function attribute, Xstormy16
5351 Use this attribute to indicate
5352 that the specified function is an interrupt handler. The compiler generates
5353 function entry and exit sequences suitable for use in an interrupt handler
5354 when this attribute is present.
5355 @end table
5356
5357 @node Variable Attributes
5358 @section Specifying Attributes of Variables
5359 @cindex attribute of variables
5360 @cindex variable attributes
5361
5362 The keyword @code{__attribute__} allows you to specify special
5363 attributes of variables or structure fields. This keyword is followed
5364 by an attribute specification inside double parentheses. Some
5365 attributes are currently defined generically for variables.
5366 Other attributes are defined for variables on particular target
5367 systems. Other attributes are available for functions
5368 (@pxref{Function Attributes}), labels (@pxref{Label Attributes}),
5369 enumerators (@pxref{Enumerator Attributes}), and for types
5370 (@pxref{Type Attributes}).
5371 Other front ends might define more attributes
5372 (@pxref{C++ Extensions,,Extensions to the C++ Language}).
5373
5374 @xref{Attribute Syntax}, for details of the exact syntax for using
5375 attributes.
5376
5377 @menu
5378 * Common Variable Attributes::
5379 * AVR Variable Attributes::
5380 * Blackfin Variable Attributes::
5381 * H8/300 Variable Attributes::
5382 * IA-64 Variable Attributes::
5383 * M32R/D Variable Attributes::
5384 * MeP Variable Attributes::
5385 * Microsoft Windows Variable Attributes::
5386 * MSP430 Variable Attributes::
5387 * PowerPC Variable Attributes::
5388 * SPU Variable Attributes::
5389 * x86 Variable Attributes::
5390 * Xstormy16 Variable Attributes::
5391 @end menu
5392
5393 @node Common Variable Attributes
5394 @subsection Common Variable Attributes
5395
5396 The following attributes are supported on most targets.
5397
5398 @table @code
5399 @cindex @code{aligned} variable attribute
5400 @item aligned (@var{alignment})
5401 This attribute specifies a minimum alignment for the variable or
5402 structure field, measured in bytes. For example, the declaration:
5403
5404 @smallexample
5405 int x __attribute__ ((aligned (16))) = 0;
5406 @end smallexample
5407
5408 @noindent
5409 causes the compiler to allocate the global variable @code{x} on a
5410 16-byte boundary. On a 68040, this could be used in conjunction with
5411 an @code{asm} expression to access the @code{move16} instruction which
5412 requires 16-byte aligned operands.
5413
5414 You can also specify the alignment of structure fields. For example, to
5415 create a double-word aligned @code{int} pair, you could write:
5416
5417 @smallexample
5418 struct foo @{ int x[2] __attribute__ ((aligned (8))); @};
5419 @end smallexample
5420
5421 @noindent
5422 This is an alternative to creating a union with a @code{double} member,
5423 which forces the union to be double-word aligned.
5424
5425 As in the preceding examples, you can explicitly specify the alignment
5426 (in bytes) that you wish the compiler to use for a given variable or
5427 structure field. Alternatively, you can leave out the alignment factor
5428 and just ask the compiler to align a variable or field to the
5429 default alignment for the target architecture you are compiling for.
5430 The default alignment is sufficient for all scalar types, but may not be
5431 enough for all vector types on a target that supports vector operations.
5432 The default alignment is fixed for a particular target ABI.
5433
5434 GCC also provides a target specific macro @code{__BIGGEST_ALIGNMENT__},
5435 which is the largest alignment ever used for any data type on the
5436 target machine you are compiling for. For example, you could write:
5437
5438 @smallexample
5439 short array[3] __attribute__ ((aligned (__BIGGEST_ALIGNMENT__)));
5440 @end smallexample
5441
5442 The compiler automatically sets the alignment for the declared
5443 variable or field to @code{__BIGGEST_ALIGNMENT__}. Doing this can
5444 often make copy operations more efficient, because the compiler can
5445 use whatever instructions copy the biggest chunks of memory when
5446 performing copies to or from the variables or fields that you have
5447 aligned this way. Note that the value of @code{__BIGGEST_ALIGNMENT__}
5448 may change depending on command-line options.
5449
5450 When used on a struct, or struct member, the @code{aligned} attribute can
5451 only increase the alignment; in order to decrease it, the @code{packed}
5452 attribute must be specified as well. When used as part of a typedef, the
5453 @code{aligned} attribute can both increase and decrease alignment, and
5454 specifying the @code{packed} attribute generates a warning.
5455
5456 Note that the effectiveness of @code{aligned} attributes may be limited
5457 by inherent limitations in your linker. On many systems, the linker is
5458 only able to arrange for variables to be aligned up to a certain maximum
5459 alignment. (For some linkers, the maximum supported alignment may
5460 be very very small.) If your linker is only able to align variables
5461 up to a maximum of 8-byte alignment, then specifying @code{aligned(16)}
5462 in an @code{__attribute__} still only provides you with 8-byte
5463 alignment. See your linker documentation for further information.
5464
5465 The @code{aligned} attribute can also be used for functions
5466 (@pxref{Common Function Attributes}.)
5467
5468 @item cleanup (@var{cleanup_function})
5469 @cindex @code{cleanup} variable attribute
5470 The @code{cleanup} attribute runs a function when the variable goes
5471 out of scope. This attribute can only be applied to auto function
5472 scope variables; it may not be applied to parameters or variables
5473 with static storage duration. The function must take one parameter,
5474 a pointer to a type compatible with the variable. The return value
5475 of the function (if any) is ignored.
5476
5477 If @option{-fexceptions} is enabled, then @var{cleanup_function}
5478 is run during the stack unwinding that happens during the
5479 processing of the exception. Note that the @code{cleanup} attribute
5480 does not allow the exception to be caught, only to perform an action.
5481 It is undefined what happens if @var{cleanup_function} does not
5482 return normally.
5483
5484 @item common
5485 @itemx nocommon
5486 @cindex @code{common} variable attribute
5487 @cindex @code{nocommon} variable attribute
5488 @opindex fcommon
5489 @opindex fno-common
5490 The @code{common} attribute requests GCC to place a variable in
5491 ``common'' storage. The @code{nocommon} attribute requests the
5492 opposite---to allocate space for it directly.
5493
5494 These attributes override the default chosen by the
5495 @option{-fno-common} and @option{-fcommon} flags respectively.
5496
5497 @item deprecated
5498 @itemx deprecated (@var{msg})
5499 @cindex @code{deprecated} variable attribute
5500 The @code{deprecated} attribute results in a warning if the variable
5501 is used anywhere in the source file. This is useful when identifying
5502 variables that are expected to be removed in a future version of a
5503 program. The warning also includes the location of the declaration
5504 of the deprecated variable, to enable users to easily find further
5505 information about why the variable is deprecated, or what they should
5506 do instead. Note that the warning only occurs for uses:
5507
5508 @smallexample
5509 extern int old_var __attribute__ ((deprecated));
5510 extern int old_var;
5511 int new_fn () @{ return old_var; @}
5512 @end smallexample
5513
5514 @noindent
5515 results in a warning on line 3 but not line 2. The optional @var{msg}
5516 argument, which must be a string, is printed in the warning if
5517 present.
5518
5519 The @code{deprecated} attribute can also be used for functions and
5520 types (@pxref{Common Function Attributes},
5521 @pxref{Common Type Attributes}).
5522
5523 @item mode (@var{mode})
5524 @cindex @code{mode} variable attribute
5525 This attribute specifies the data type for the declaration---whichever
5526 type corresponds to the mode @var{mode}. This in effect lets you
5527 request an integer or floating-point type according to its width.
5528
5529 You may also specify a mode of @code{byte} or @code{__byte__} to
5530 indicate the mode corresponding to a one-byte integer, @code{word} or
5531 @code{__word__} for the mode of a one-word integer, and @code{pointer}
5532 or @code{__pointer__} for the mode used to represent pointers.
5533
5534 @item packed
5535 @cindex @code{packed} variable attribute
5536 The @code{packed} attribute specifies that a variable or structure field
5537 should have the smallest possible alignment---one byte for a variable,
5538 and one bit for a field, unless you specify a larger value with the
5539 @code{aligned} attribute.
5540
5541 Here is a structure in which the field @code{x} is packed, so that it
5542 immediately follows @code{a}:
5543
5544 @smallexample
5545 struct foo
5546 @{
5547 char a;
5548 int x[2] __attribute__ ((packed));
5549 @};
5550 @end smallexample
5551
5552 @emph{Note:} The 4.1, 4.2 and 4.3 series of GCC ignore the
5553 @code{packed} attribute on bit-fields of type @code{char}. This has
5554 been fixed in GCC 4.4 but the change can lead to differences in the
5555 structure layout. See the documentation of
5556 @option{-Wpacked-bitfield-compat} for more information.
5557
5558 @item section ("@var{section-name}")
5559 @cindex @code{section} variable attribute
5560 Normally, the compiler places the objects it generates in sections like
5561 @code{data} and @code{bss}. Sometimes, however, you need additional sections,
5562 or you need certain particular variables to appear in special sections,
5563 for example to map to special hardware. The @code{section}
5564 attribute specifies that a variable (or function) lives in a particular
5565 section. For example, this small program uses several specific section names:
5566
5567 @smallexample
5568 struct duart a __attribute__ ((section ("DUART_A"))) = @{ 0 @};
5569 struct duart b __attribute__ ((section ("DUART_B"))) = @{ 0 @};
5570 char stack[10000] __attribute__ ((section ("STACK"))) = @{ 0 @};
5571 int init_data __attribute__ ((section ("INITDATA")));
5572
5573 main()
5574 @{
5575 /* @r{Initialize stack pointer} */
5576 init_sp (stack + sizeof (stack));
5577
5578 /* @r{Initialize initialized data} */
5579 memcpy (&init_data, &data, &edata - &data);
5580
5581 /* @r{Turn on the serial ports} */
5582 init_duart (&a);
5583 init_duart (&b);
5584 @}
5585 @end smallexample
5586
5587 @noindent
5588 Use the @code{section} attribute with
5589 @emph{global} variables and not @emph{local} variables,
5590 as shown in the example.
5591
5592 You may use the @code{section} attribute with initialized or
5593 uninitialized global variables but the linker requires
5594 each object be defined once, with the exception that uninitialized
5595 variables tentatively go in the @code{common} (or @code{bss}) section
5596 and can be multiply ``defined''. Using the @code{section} attribute
5597 changes what section the variable goes into and may cause the
5598 linker to issue an error if an uninitialized variable has multiple
5599 definitions. You can force a variable to be initialized with the
5600 @option{-fno-common} flag or the @code{nocommon} attribute.
5601
5602 Some file formats do not support arbitrary sections so the @code{section}
5603 attribute is not available on all platforms.
5604 If you need to map the entire contents of a module to a particular
5605 section, consider using the facilities of the linker instead.
5606
5607 @item tls_model ("@var{tls_model}")
5608 @cindex @code{tls_model} variable attribute
5609 The @code{tls_model} attribute sets thread-local storage model
5610 (@pxref{Thread-Local}) of a particular @code{__thread} variable,
5611 overriding @option{-ftls-model=} command-line switch on a per-variable
5612 basis.
5613 The @var{tls_model} argument should be one of @code{global-dynamic},
5614 @code{local-dynamic}, @code{initial-exec} or @code{local-exec}.
5615
5616 Not all targets support this attribute.
5617
5618 @item unused
5619 @cindex @code{unused} variable attribute
5620 This attribute, attached to a variable, means that the variable is meant
5621 to be possibly unused. GCC does not produce a warning for this
5622 variable.
5623
5624 @item used
5625 @cindex @code{used} variable attribute
5626 This attribute, attached to a variable with static storage, means that
5627 the variable must be emitted even if it appears that the variable is not
5628 referenced.
5629
5630 When applied to a static data member of a C++ class template, the
5631 attribute also means that the member is instantiated if the
5632 class itself is instantiated.
5633
5634 @item vector_size (@var{bytes})
5635 @cindex @code{vector_size} variable attribute
5636 This attribute specifies the vector size for the variable, measured in
5637 bytes. For example, the declaration:
5638
5639 @smallexample
5640 int foo __attribute__ ((vector_size (16)));
5641 @end smallexample
5642
5643 @noindent
5644 causes the compiler to set the mode for @code{foo}, to be 16 bytes,
5645 divided into @code{int} sized units. Assuming a 32-bit int (a vector of
5646 4 units of 4 bytes), the corresponding mode of @code{foo} is V4SI@.
5647
5648 This attribute is only applicable to integral and float scalars,
5649 although arrays, pointers, and function return values are allowed in
5650 conjunction with this construct.
5651
5652 Aggregates with this attribute are invalid, even if they are of the same
5653 size as a corresponding scalar. For example, the declaration:
5654
5655 @smallexample
5656 struct S @{ int a; @};
5657 struct S __attribute__ ((vector_size (16))) foo;
5658 @end smallexample
5659
5660 @noindent
5661 is invalid even if the size of the structure is the same as the size of
5662 the @code{int}.
5663
5664 @item visibility ("@var{visibility_type}")
5665 @cindex @code{visibility} variable attribute
5666 This attribute affects the linkage of the declaration to which it is attached.
5667 The @code{visibility} attribute is described in
5668 @ref{Common Function Attributes}.
5669
5670 @item weak
5671 @cindex @code{weak} variable attribute
5672 The @code{weak} attribute is described in
5673 @ref{Common Function Attributes}.
5674
5675 @end table
5676
5677 @node AVR Variable Attributes
5678 @subsection AVR Variable Attributes
5679
5680 @table @code
5681 @item progmem
5682 @cindex @code{progmem} variable attribute, AVR
5683 The @code{progmem} attribute is used on the AVR to place read-only
5684 data in the non-volatile program memory (flash). The @code{progmem}
5685 attribute accomplishes this by putting respective variables into a
5686 section whose name starts with @code{.progmem}.
5687
5688 This attribute works similar to the @code{section} attribute
5689 but adds additional checking. Notice that just like the
5690 @code{section} attribute, @code{progmem} affects the location
5691 of the data but not how this data is accessed.
5692
5693 In order to read data located with the @code{progmem} attribute
5694 (inline) assembler must be used.
5695 @smallexample
5696 /* Use custom macros from @w{@uref{http://nongnu.org/avr-libc/user-manual/,AVR-LibC}} */
5697 #include <avr/pgmspace.h>
5698
5699 /* Locate var in flash memory */
5700 const int var[2] PROGMEM = @{ 1, 2 @};
5701
5702 int read_var (int i)
5703 @{
5704 /* Access var[] by accessor macro from avr/pgmspace.h */
5705 return (int) pgm_read_word (& var[i]);
5706 @}
5707 @end smallexample
5708
5709 AVR is a Harvard architecture processor and data and read-only data
5710 normally resides in the data memory (RAM).
5711
5712 See also the @ref{AVR Named Address Spaces} section for
5713 an alternate way to locate and access data in flash memory.
5714
5715 @item io
5716 @itemx io (@var{addr})
5717 @cindex @code{io} variable attribute, AVR
5718 Variables with the @code{io} attribute are used to address
5719 memory-mapped peripherals in the io address range.
5720 If an address is specified, the variable
5721 is assigned that address, and the value is interpreted as an
5722 address in the data address space.
5723 Example:
5724
5725 @smallexample
5726 volatile int porta __attribute__((io (0x22)));
5727 @end smallexample
5728
5729 The address specified in the address in the data address range.
5730
5731 Otherwise, the variable it is not assigned an address, but the
5732 compiler will still use in/out instructions where applicable,
5733 assuming some other module assigns an address in the io address range.
5734 Example:
5735
5736 @smallexample
5737 extern volatile int porta __attribute__((io));
5738 @end smallexample
5739
5740 @item io_low
5741 @itemx io_low (@var{addr})
5742 @cindex @code{io_low} variable attribute, AVR
5743 This is like the @code{io} attribute, but additionally it informs the
5744 compiler that the object lies in the lower half of the I/O area,
5745 allowing the use of @code{cbi}, @code{sbi}, @code{sbic} and @code{sbis}
5746 instructions.
5747
5748 @item address
5749 @itemx address (@var{addr})
5750 @cindex @code{address} variable attribute, AVR
5751 Variables with the @code{address} attribute are used to address
5752 memory-mapped peripherals that may lie outside the io address range.
5753
5754 @smallexample
5755 volatile int porta __attribute__((address (0x600)));
5756 @end smallexample
5757
5758 @end table
5759
5760 @node Blackfin Variable Attributes
5761 @subsection Blackfin Variable Attributes
5762
5763 Three attributes are currently defined for the Blackfin.
5764
5765 @table @code
5766 @item l1_data
5767 @itemx l1_data_A
5768 @itemx l1_data_B
5769 @cindex @code{l1_data} variable attribute, Blackfin
5770 @cindex @code{l1_data_A} variable attribute, Blackfin
5771 @cindex @code{l1_data_B} variable attribute, Blackfin
5772 Use these attributes on the Blackfin to place the variable into L1 Data SRAM.
5773 Variables with @code{l1_data} attribute are put into the specific section
5774 named @code{.l1.data}. Those with @code{l1_data_A} attribute are put into
5775 the specific section named @code{.l1.data.A}. Those with @code{l1_data_B}
5776 attribute are put into the specific section named @code{.l1.data.B}.
5777
5778 @item l2
5779 @cindex @code{l2} variable attribute, Blackfin
5780 Use this attribute on the Blackfin to place the variable into L2 SRAM.
5781 Variables with @code{l2} attribute are put into the specific section
5782 named @code{.l2.data}.
5783 @end table
5784
5785 @node H8/300 Variable Attributes
5786 @subsection H8/300 Variable Attributes
5787
5788 These variable attributes are available for H8/300 targets:
5789
5790 @table @code
5791 @item eightbit_data
5792 @cindex @code{eightbit_data} variable attribute, H8/300
5793 @cindex eight-bit data on the H8/300, H8/300H, and H8S
5794 Use this attribute on the H8/300, H8/300H, and H8S to indicate that the specified
5795 variable should be placed into the eight-bit data section.
5796 The compiler generates more efficient code for certain operations
5797 on data in the eight-bit data area. Note the eight-bit data area is limited to
5798 256 bytes of data.
5799
5800 You must use GAS and GLD from GNU binutils version 2.7 or later for
5801 this attribute to work correctly.
5802
5803 @item tiny_data
5804 @cindex @code{tiny_data} variable attribute, H8/300
5805 @cindex tiny data section on the H8/300H and H8S
5806 Use this attribute on the H8/300H and H8S to indicate that the specified
5807 variable should be placed into the tiny data section.
5808 The compiler generates more efficient code for loads and stores
5809 on data in the tiny data section. Note the tiny data area is limited to
5810 slightly under 32KB of data.
5811
5812 @end table
5813
5814 @node IA-64 Variable Attributes
5815 @subsection IA-64 Variable Attributes
5816
5817 The IA-64 back end supports the following variable attribute:
5818
5819 @table @code
5820 @item model (@var{model-name})
5821 @cindex @code{model} variable attribute, IA-64
5822
5823 On IA-64, use this attribute to set the addressability of an object.
5824 At present, the only supported identifier for @var{model-name} is
5825 @code{small}, indicating addressability via ``small'' (22-bit)
5826 addresses (so that their addresses can be loaded with the @code{addl}
5827 instruction). Caveat: such addressing is by definition not position
5828 independent and hence this attribute must not be used for objects
5829 defined by shared libraries.
5830
5831 @end table
5832
5833 @node M32R/D Variable Attributes
5834 @subsection M32R/D Variable Attributes
5835
5836 One attribute is currently defined for the M32R/D@.
5837
5838 @table @code
5839 @item model (@var{model-name})
5840 @cindex @code{model-name} variable attribute, M32R/D
5841 @cindex variable addressability on the M32R/D
5842 Use this attribute on the M32R/D to set the addressability of an object.
5843 The identifier @var{model-name} is one of @code{small}, @code{medium},
5844 or @code{large}, representing each of the code models.
5845
5846 Small model objects live in the lower 16MB of memory (so that their
5847 addresses can be loaded with the @code{ld24} instruction).
5848
5849 Medium and large model objects may live anywhere in the 32-bit address space
5850 (the compiler generates @code{seth/add3} instructions to load their
5851 addresses).
5852 @end table
5853
5854 @node MeP Variable Attributes
5855 @subsection MeP Variable Attributes
5856
5857 The MeP target has a number of addressing modes and busses. The
5858 @code{near} space spans the standard memory space's first 16 megabytes
5859 (24 bits). The @code{far} space spans the entire 32-bit memory space.
5860 The @code{based} space is a 128-byte region in the memory space that
5861 is addressed relative to the @code{$tp} register. The @code{tiny}
5862 space is a 65536-byte region relative to the @code{$gp} register. In
5863 addition to these memory regions, the MeP target has a separate 16-bit
5864 control bus which is specified with @code{cb} attributes.
5865
5866 @table @code
5867
5868 @item based
5869 @cindex @code{based} variable attribute, MeP
5870 Any variable with the @code{based} attribute is assigned to the
5871 @code{.based} section, and is accessed with relative to the
5872 @code{$tp} register.
5873
5874 @item tiny
5875 @cindex @code{tiny} variable attribute, MeP
5876 Likewise, the @code{tiny} attribute assigned variables to the
5877 @code{.tiny} section, relative to the @code{$gp} register.
5878
5879 @item near
5880 @cindex @code{near} variable attribute, MeP
5881 Variables with the @code{near} attribute are assumed to have addresses
5882 that fit in a 24-bit addressing mode. This is the default for large
5883 variables (@code{-mtiny=4} is the default) but this attribute can
5884 override @code{-mtiny=} for small variables, or override @code{-ml}.
5885
5886 @item far
5887 @cindex @code{far} variable attribute, MeP
5888 Variables with the @code{far} attribute are addressed using a full
5889 32-bit address. Since this covers the entire memory space, this
5890 allows modules to make no assumptions about where variables might be
5891 stored.
5892
5893 @item io
5894 @cindex @code{io} variable attribute, MeP
5895 @itemx io (@var{addr})
5896 Variables with the @code{io} attribute are used to address
5897 memory-mapped peripherals. If an address is specified, the variable
5898 is assigned that address, else it is not assigned an address (it is
5899 assumed some other module assigns an address). Example:
5900
5901 @smallexample
5902 int timer_count __attribute__((io(0x123)));
5903 @end smallexample
5904
5905 @item cb
5906 @itemx cb (@var{addr})
5907 @cindex @code{cb} variable attribute, MeP
5908 Variables with the @code{cb} attribute are used to access the control
5909 bus, using special instructions. @code{addr} indicates the control bus
5910 address. Example:
5911
5912 @smallexample
5913 int cpu_clock __attribute__((cb(0x123)));
5914 @end smallexample
5915
5916 @end table
5917
5918 @node Microsoft Windows Variable Attributes
5919 @subsection Microsoft Windows Variable Attributes
5920
5921 You can use these attributes on Microsoft Windows targets.
5922 @ref{x86 Variable Attributes} for additional Windows compatibility
5923 attributes available on all x86 targets.
5924
5925 @table @code
5926 @item dllimport
5927 @itemx dllexport
5928 @cindex @code{dllimport} variable attribute
5929 @cindex @code{dllexport} variable attribute
5930 The @code{dllimport} and @code{dllexport} attributes are described in
5931 @ref{Microsoft Windows Function Attributes}.
5932
5933 @item selectany
5934 @cindex @code{selectany} variable attribute
5935 The @code{selectany} attribute causes an initialized global variable to
5936 have link-once semantics. When multiple definitions of the variable are
5937 encountered by the linker, the first is selected and the remainder are
5938 discarded. Following usage by the Microsoft compiler, the linker is told
5939 @emph{not} to warn about size or content differences of the multiple
5940 definitions.
5941
5942 Although the primary usage of this attribute is for POD types, the
5943 attribute can also be applied to global C++ objects that are initialized
5944 by a constructor. In this case, the static initialization and destruction
5945 code for the object is emitted in each translation defining the object,
5946 but the calls to the constructor and destructor are protected by a
5947 link-once guard variable.
5948
5949 The @code{selectany} attribute is only available on Microsoft Windows
5950 targets. You can use @code{__declspec (selectany)} as a synonym for
5951 @code{__attribute__ ((selectany))} for compatibility with other
5952 compilers.
5953
5954 @item shared
5955 @cindex @code{shared} variable attribute
5956 On Microsoft Windows, in addition to putting variable definitions in a named
5957 section, the section can also be shared among all running copies of an
5958 executable or DLL@. For example, this small program defines shared data
5959 by putting it in a named section @code{shared} and marking the section
5960 shareable:
5961
5962 @smallexample
5963 int foo __attribute__((section ("shared"), shared)) = 0;
5964
5965 int
5966 main()
5967 @{
5968 /* @r{Read and write foo. All running
5969 copies see the same value.} */
5970 return 0;
5971 @}
5972 @end smallexample
5973
5974 @noindent
5975 You may only use the @code{shared} attribute along with @code{section}
5976 attribute with a fully-initialized global definition because of the way
5977 linkers work. See @code{section} attribute for more information.
5978
5979 The @code{shared} attribute is only available on Microsoft Windows@.
5980
5981 @end table
5982
5983 @node MSP430 Variable Attributes
5984 @subsection MSP430 Variable Attributes
5985
5986 @table @code
5987 @item noinit
5988 @cindex @code{noinit} MSP430 variable attribute
5989 Any data with the @code{noinit} attribute will not be initialised by
5990 the C runtime startup code, or the program loader. Not initialising
5991 data in this way can reduce program startup times.
5992
5993 @item persistent
5994 @cindex @code{persistent} MSP430 variable attribute
5995 Any variable with the @code{persistent} attribute will not be
5996 initialised by the C runtime startup code. Instead its value will be
5997 set once, when the application is loaded, and then never initialised
5998 again, even if the processor is reset or the program restarts.
5999 Persistent data is intended to be placed into FLASH RAM, where its
6000 value will be retained across resets. The linker script being used to
6001 create the application should ensure that persistent data is correctly
6002 placed.
6003
6004 @item lower
6005 @itemx upper
6006 @itemx either
6007 @cindex @code{lower} memory region on the MSP430
6008 @cindex @code{upper} memory region on the MSP430
6009 @cindex @code{either} memory region on the MSP430
6010 These attributes are the same as the MSP430 function attributes of the
6011 same name. These attributes can be applied to both functions and
6012 variables.
6013 @end table
6014
6015 @node PowerPC Variable Attributes
6016 @subsection PowerPC Variable Attributes
6017
6018 Three attributes currently are defined for PowerPC configurations:
6019 @code{altivec}, @code{ms_struct} and @code{gcc_struct}.
6020
6021 @cindex @code{ms_struct} variable attribute, PowerPC
6022 @cindex @code{gcc_struct} variable attribute, PowerPC
6023 For full documentation of the struct attributes please see the
6024 documentation in @ref{x86 Variable Attributes}.
6025
6026 @cindex @code{altivec} variable attribute, PowerPC
6027 For documentation of @code{altivec} attribute please see the
6028 documentation in @ref{PowerPC Type Attributes}.
6029
6030 @node SPU Variable Attributes
6031 @subsection SPU Variable Attributes
6032
6033 @cindex @code{spu_vector} variable attribute, SPU
6034 The SPU supports the @code{spu_vector} attribute for variables. For
6035 documentation of this attribute please see the documentation in
6036 @ref{SPU Type Attributes}.
6037
6038 @node x86 Variable Attributes
6039 @subsection x86 Variable Attributes
6040
6041 Two attributes are currently defined for x86 configurations:
6042 @code{ms_struct} and @code{gcc_struct}.
6043
6044 @table @code
6045 @item ms_struct
6046 @itemx gcc_struct
6047 @cindex @code{ms_struct} variable attribute, x86
6048 @cindex @code{gcc_struct} variable attribute, x86
6049
6050 If @code{packed} is used on a structure, or if bit-fields are used,
6051 it may be that the Microsoft ABI lays out the structure differently
6052 than the way GCC normally does. Particularly when moving packed
6053 data between functions compiled with GCC and the native Microsoft compiler
6054 (either via function call or as data in a file), it may be necessary to access
6055 either format.
6056
6057 The @code{ms_struct} and @code{gcc_struct} attributes correspond
6058 to the @option{-mms-bitfields} and @option{-mno-ms-bitfields}
6059 command-line options, respectively;
6060 see @ref{x86 Options}, for details of how structure layout is affected.
6061 @xref{x86 Type Attributes}, for information about the corresponding
6062 attributes on types.
6063
6064 @end table
6065
6066 @node Xstormy16 Variable Attributes
6067 @subsection Xstormy16 Variable Attributes
6068
6069 One attribute is currently defined for xstormy16 configurations:
6070 @code{below100}.
6071
6072 @table @code
6073 @item below100
6074 @cindex @code{below100} variable attribute, Xstormy16
6075
6076 If a variable has the @code{below100} attribute (@code{BELOW100} is
6077 allowed also), GCC places the variable in the first 0x100 bytes of
6078 memory and use special opcodes to access it. Such variables are
6079 placed in either the @code{.bss_below100} section or the
6080 @code{.data_below100} section.
6081
6082 @end table
6083
6084 @node Type Attributes
6085 @section Specifying Attributes of Types
6086 @cindex attribute of types
6087 @cindex type attributes
6088
6089 The keyword @code{__attribute__} allows you to specify special
6090 attributes of types. Some type attributes apply only to @code{struct}
6091 and @code{union} types, while others can apply to any type defined
6092 via a @code{typedef} declaration. Other attributes are defined for
6093 functions (@pxref{Function Attributes}), labels (@pxref{Label
6094 Attributes}), enumerators (@pxref{Enumerator Attributes}), and for
6095 variables (@pxref{Variable Attributes}).
6096
6097 The @code{__attribute__} keyword is followed by an attribute specification
6098 inside double parentheses.
6099
6100 You may specify type attributes in an enum, struct or union type
6101 declaration or definition by placing them immediately after the
6102 @code{struct}, @code{union} or @code{enum} keyword. A less preferred
6103 syntax is to place them just past the closing curly brace of the
6104 definition.
6105
6106 You can also include type attributes in a @code{typedef} declaration.
6107 @xref{Attribute Syntax}, for details of the exact syntax for using
6108 attributes.
6109
6110 @menu
6111 * Common Type Attributes::
6112 * ARM Type Attributes::
6113 * MeP Type Attributes::
6114 * PowerPC Type Attributes::
6115 * SPU Type Attributes::
6116 * x86 Type Attributes::
6117 @end menu
6118
6119 @node Common Type Attributes
6120 @subsection Common Type Attributes
6121
6122 The following type attributes are supported on most targets.
6123
6124 @table @code
6125 @cindex @code{aligned} type attribute
6126 @item aligned (@var{alignment})
6127 This attribute specifies a minimum alignment (in bytes) for variables
6128 of the specified type. For example, the declarations:
6129
6130 @smallexample
6131 struct S @{ short f[3]; @} __attribute__ ((aligned (8)));
6132 typedef int more_aligned_int __attribute__ ((aligned (8)));
6133 @end smallexample
6134
6135 @noindent
6136 force the compiler to ensure (as far as it can) that each variable whose
6137 type is @code{struct S} or @code{more_aligned_int} is allocated and
6138 aligned @emph{at least} on a 8-byte boundary. On a SPARC, having all
6139 variables of type @code{struct S} aligned to 8-byte boundaries allows
6140 the compiler to use the @code{ldd} and @code{std} (doubleword load and
6141 store) instructions when copying one variable of type @code{struct S} to
6142 another, thus improving run-time efficiency.
6143
6144 Note that the alignment of any given @code{struct} or @code{union} type
6145 is required by the ISO C standard to be at least a perfect multiple of
6146 the lowest common multiple of the alignments of all of the members of
6147 the @code{struct} or @code{union} in question. This means that you @emph{can}
6148 effectively adjust the alignment of a @code{struct} or @code{union}
6149 type by attaching an @code{aligned} attribute to any one of the members
6150 of such a type, but the notation illustrated in the example above is a
6151 more obvious, intuitive, and readable way to request the compiler to
6152 adjust the alignment of an entire @code{struct} or @code{union} type.
6153
6154 As in the preceding example, you can explicitly specify the alignment
6155 (in bytes) that you wish the compiler to use for a given @code{struct}
6156 or @code{union} type. Alternatively, you can leave out the alignment factor
6157 and just ask the compiler to align a type to the maximum
6158 useful alignment for the target machine you are compiling for. For
6159 example, you could write:
6160
6161 @smallexample
6162 struct S @{ short f[3]; @} __attribute__ ((aligned));
6163 @end smallexample
6164
6165 Whenever you leave out the alignment factor in an @code{aligned}
6166 attribute specification, the compiler automatically sets the alignment
6167 for the type to the largest alignment that is ever used for any data
6168 type on the target machine you are compiling for. Doing this can often
6169 make copy operations more efficient, because the compiler can use
6170 whatever instructions copy the biggest chunks of memory when performing
6171 copies to or from the variables that have types that you have aligned
6172 this way.
6173
6174 In the example above, if the size of each @code{short} is 2 bytes, then
6175 the size of the entire @code{struct S} type is 6 bytes. The smallest
6176 power of two that is greater than or equal to that is 8, so the
6177 compiler sets the alignment for the entire @code{struct S} type to 8
6178 bytes.
6179
6180 Note that although you can ask the compiler to select a time-efficient
6181 alignment for a given type and then declare only individual stand-alone
6182 objects of that type, the compiler's ability to select a time-efficient
6183 alignment is primarily useful only when you plan to create arrays of
6184 variables having the relevant (efficiently aligned) type. If you
6185 declare or use arrays of variables of an efficiently-aligned type, then
6186 it is likely that your program also does pointer arithmetic (or
6187 subscripting, which amounts to the same thing) on pointers to the
6188 relevant type, and the code that the compiler generates for these
6189 pointer arithmetic operations is often more efficient for
6190 efficiently-aligned types than for other types.
6191
6192 The @code{aligned} attribute can only increase the alignment; but you
6193 can decrease it by specifying @code{packed} as well. See below.
6194
6195 Note that the effectiveness of @code{aligned} attributes may be limited
6196 by inherent limitations in your linker. On many systems, the linker is
6197 only able to arrange for variables to be aligned up to a certain maximum
6198 alignment. (For some linkers, the maximum supported alignment may
6199 be very very small.) If your linker is only able to align variables
6200 up to a maximum of 8-byte alignment, then specifying @code{aligned(16)}
6201 in an @code{__attribute__} still only provides you with 8-byte
6202 alignment. See your linker documentation for further information.
6203
6204 @opindex fshort-enums
6205 Specifying this attribute for @code{struct} and @code{union} types is
6206 equivalent to specifying the @code{packed} attribute on each of the
6207 structure or union members. Specifying the @option{-fshort-enums}
6208 flag on the line is equivalent to specifying the @code{packed}
6209 attribute on all @code{enum} definitions.
6210
6211 In the following example @code{struct my_packed_struct}'s members are
6212 packed closely together, but the internal layout of its @code{s} member
6213 is not packed---to do that, @code{struct my_unpacked_struct} needs to
6214 be packed too.
6215
6216 @smallexample
6217 struct my_unpacked_struct
6218 @{
6219 char c;
6220 int i;
6221 @};
6222
6223 struct __attribute__ ((__packed__)) my_packed_struct
6224 @{
6225 char c;
6226 int i;
6227 struct my_unpacked_struct s;
6228 @};
6229 @end smallexample
6230
6231 You may only specify this attribute on the definition of an @code{enum},
6232 @code{struct} or @code{union}, not on a @code{typedef} that does not
6233 also define the enumerated type, structure or union.
6234
6235 @item bnd_variable_size
6236 @cindex @code{bnd_variable_size} type attribute
6237 @cindex Pointer Bounds Checker attributes
6238 When applied to a structure field, this attribute tells Pointer
6239 Bounds Checker that the size of this field should not be computed
6240 using static type information. It may be used to mark variably-sized
6241 static array fields placed at the end of a structure.
6242
6243 @smallexample
6244 struct S
6245 @{
6246 int size;
6247 char data[1];
6248 @}
6249 S *p = (S *)malloc (sizeof(S) + 100);
6250 p->data[10] = 0; //Bounds violation
6251 @end smallexample
6252
6253 @noindent
6254 By using an attribute for the field we may avoid unwanted bound
6255 violation checks:
6256
6257 @smallexample
6258 struct S
6259 @{
6260 int size;
6261 char data[1] __attribute__((bnd_variable_size));
6262 @}
6263 S *p = (S *)malloc (sizeof(S) + 100);
6264 p->data[10] = 0; //OK
6265 @end smallexample
6266
6267 @item deprecated
6268 @itemx deprecated (@var{msg})
6269 @cindex @code{deprecated} type attribute
6270 The @code{deprecated} attribute results in a warning if the type
6271 is used anywhere in the source file. This is useful when identifying
6272 types that are expected to be removed in a future version of a program.
6273 If possible, the warning also includes the location of the declaration
6274 of the deprecated type, to enable users to easily find further
6275 information about why the type is deprecated, or what they should do
6276 instead. Note that the warnings only occur for uses and then only
6277 if the type is being applied to an identifier that itself is not being
6278 declared as deprecated.
6279
6280 @smallexample
6281 typedef int T1 __attribute__ ((deprecated));
6282 T1 x;
6283 typedef T1 T2;
6284 T2 y;
6285 typedef T1 T3 __attribute__ ((deprecated));
6286 T3 z __attribute__ ((deprecated));
6287 @end smallexample
6288
6289 @noindent
6290 results in a warning on line 2 and 3 but not lines 4, 5, or 6. No
6291 warning is issued for line 4 because T2 is not explicitly
6292 deprecated. Line 5 has no warning because T3 is explicitly
6293 deprecated. Similarly for line 6. The optional @var{msg}
6294 argument, which must be a string, is printed in the warning if
6295 present.
6296
6297 The @code{deprecated} attribute can also be used for functions and
6298 variables (@pxref{Function Attributes}, @pxref{Variable Attributes}.)
6299
6300 @item designated_init
6301 @cindex @code{designated_init} type attribute
6302 This attribute may only be applied to structure types. It indicates
6303 that any initialization of an object of this type must use designated
6304 initializers rather than positional initializers. The intent of this
6305 attribute is to allow the programmer to indicate that a structure's
6306 layout may change, and that therefore relying on positional
6307 initialization will result in future breakage.
6308
6309 GCC emits warnings based on this attribute by default; use
6310 @option{-Wno-designated-init} to suppress them.
6311
6312 @item may_alias
6313 @cindex @code{may_alias} type attribute
6314 Accesses through pointers to types with this attribute are not subject
6315 to type-based alias analysis, but are instead assumed to be able to alias
6316 any other type of objects.
6317 In the context of section 6.5 paragraph 7 of the C99 standard,
6318 an lvalue expression
6319 dereferencing such a pointer is treated like having a character type.
6320 See @option{-fstrict-aliasing} for more information on aliasing issues.
6321 This extension exists to support some vector APIs, in which pointers to
6322 one vector type are permitted to alias pointers to a different vector type.
6323
6324 Note that an object of a type with this attribute does not have any
6325 special semantics.
6326
6327 Example of use:
6328
6329 @smallexample
6330 typedef short __attribute__((__may_alias__)) short_a;
6331
6332 int
6333 main (void)
6334 @{
6335 int a = 0x12345678;
6336 short_a *b = (short_a *) &a;
6337
6338 b[1] = 0;
6339
6340 if (a == 0x12345678)
6341 abort();
6342
6343 exit(0);
6344 @}
6345 @end smallexample
6346
6347 @noindent
6348 If you replaced @code{short_a} with @code{short} in the variable
6349 declaration, the above program would abort when compiled with
6350 @option{-fstrict-aliasing}, which is on by default at @option{-O2} or
6351 above.
6352
6353 @item packed
6354 @cindex @code{packed} type attribute
6355 This attribute, attached to @code{struct} or @code{union} type
6356 definition, specifies that each member (other than zero-width bit-fields)
6357 of the structure or union is placed to minimize the memory required. When
6358 attached to an @code{enum} definition, it indicates that the smallest
6359 integral type should be used.
6360
6361 @item scalar_storage_order ("@var{endianness}")
6362 @cindex @code{scalar_storage_order} type attribute
6363 When attached to a @code{union} or a @code{struct}, this attribute sets
6364 the storage order, aka endianness, of the scalar fields of the type, as
6365 well as the array fields whose component is scalar. The supported
6366 endianness are @code{big-endian} and @code{little-endian}. The attribute
6367 has no effects on fields which are themselves a @code{union}, a @code{struct}
6368 or an array whose component is a @code{union} or a @code{struct}, and it is
6369 possible to have fields with a different scalar storage order than the
6370 enclosing type.
6371
6372 This attribute is supported only for targets that use a uniform default
6373 scalar storage order (fortunately, most of them), i.e. targets that store
6374 the scalars either all in big-endian or all in little-endian.
6375
6376 Additional restrictions are enforced for types with the reverse scalar
6377 storage order with regard to the scalar storage order of the target:
6378
6379 @itemize
6380 @item Taking the address of a scalar field of a @code{union} or a
6381 @code{struct} with reverse scalar storage order is not permitted and will
6382 yield an error.
6383 @item Taking the address of an array field, whose component is scalar, of
6384 a @code{union} or a @code{struct} with reverse scalar storage order is
6385 permitted but will yield a warning, unless @option{-Wno-scalar-storage-order}
6386 is specified.
6387 @item Taking the address of a @code{union} or a @code{struct} with reverse
6388 scalar storage order is permitted.
6389 @end itemize
6390
6391 These restrictions exist because the storage order attribute is lost when
6392 the address of a scalar or the address of an array with scalar component
6393 is taken, so storing indirectly through this address will generally not work.
6394 The second case is nevertheless allowed to be able to perform a block copy
6395 from or to the array.
6396
6397 @item transparent_union
6398 @cindex @code{transparent_union} type attribute
6399
6400 This attribute, attached to a @code{union} type definition, indicates
6401 that any function parameter having that union type causes calls to that
6402 function to be treated in a special way.
6403
6404 First, the argument corresponding to a transparent union type can be of
6405 any type in the union; no cast is required. Also, if the union contains
6406 a pointer type, the corresponding argument can be a null pointer
6407 constant or a void pointer expression; and if the union contains a void
6408 pointer type, the corresponding argument can be any pointer expression.
6409 If the union member type is a pointer, qualifiers like @code{const} on
6410 the referenced type must be respected, just as with normal pointer
6411 conversions.
6412
6413 Second, the argument is passed to the function using the calling
6414 conventions of the first member of the transparent union, not the calling
6415 conventions of the union itself. All members of the union must have the
6416 same machine representation; this is necessary for this argument passing
6417 to work properly.
6418
6419 Transparent unions are designed for library functions that have multiple
6420 interfaces for compatibility reasons. For example, suppose the
6421 @code{wait} function must accept either a value of type @code{int *} to
6422 comply with POSIX, or a value of type @code{union wait *} to comply with
6423 the 4.1BSD interface. If @code{wait}'s parameter were @code{void *},
6424 @code{wait} would accept both kinds of arguments, but it would also
6425 accept any other pointer type and this would make argument type checking
6426 less useful. Instead, @code{<sys/wait.h>} might define the interface
6427 as follows:
6428
6429 @smallexample
6430 typedef union __attribute__ ((__transparent_union__))
6431 @{
6432 int *__ip;
6433 union wait *__up;
6434 @} wait_status_ptr_t;
6435
6436 pid_t wait (wait_status_ptr_t);
6437 @end smallexample
6438
6439 @noindent
6440 This interface allows either @code{int *} or @code{union wait *}
6441 arguments to be passed, using the @code{int *} calling convention.
6442 The program can call @code{wait} with arguments of either type:
6443
6444 @smallexample
6445 int w1 () @{ int w; return wait (&w); @}
6446 int w2 () @{ union wait w; return wait (&w); @}
6447 @end smallexample
6448
6449 @noindent
6450 With this interface, @code{wait}'s implementation might look like this:
6451
6452 @smallexample
6453 pid_t wait (wait_status_ptr_t p)
6454 @{
6455 return waitpid (-1, p.__ip, 0);
6456 @}
6457 @end smallexample
6458
6459 @item unused
6460 @cindex @code{unused} type attribute
6461 When attached to a type (including a @code{union} or a @code{struct}),
6462 this attribute means that variables of that type are meant to appear
6463 possibly unused. GCC does not produce a warning for any variables of
6464 that type, even if the variable appears to do nothing. This is often
6465 the case with lock or thread classes, which are usually defined and then
6466 not referenced, but contain constructors and destructors that have
6467 nontrivial bookkeeping functions.
6468
6469 @item visibility
6470 @cindex @code{visibility} type attribute
6471 In C++, attribute visibility (@pxref{Function Attributes}) can also be
6472 applied to class, struct, union and enum types. Unlike other type
6473 attributes, the attribute must appear between the initial keyword and
6474 the name of the type; it cannot appear after the body of the type.
6475
6476 Note that the type visibility is applied to vague linkage entities
6477 associated with the class (vtable, typeinfo node, etc.). In
6478 particular, if a class is thrown as an exception in one shared object
6479 and caught in another, the class must have default visibility.
6480 Otherwise the two shared objects are unable to use the same
6481 typeinfo node and exception handling will break.
6482
6483 @end table
6484
6485 To specify multiple attributes, separate them by commas within the
6486 double parentheses: for example, @samp{__attribute__ ((aligned (16),
6487 packed))}.
6488
6489 @node ARM Type Attributes
6490 @subsection ARM Type Attributes
6491
6492 @cindex @code{notshared} type attribute, ARM
6493 On those ARM targets that support @code{dllimport} (such as Symbian
6494 OS), you can use the @code{notshared} attribute to indicate that the
6495 virtual table and other similar data for a class should not be
6496 exported from a DLL@. For example:
6497
6498 @smallexample
6499 class __declspec(notshared) C @{
6500 public:
6501 __declspec(dllimport) C();
6502 virtual void f();
6503 @}
6504
6505 __declspec(dllexport)
6506 C::C() @{@}
6507 @end smallexample
6508
6509 @noindent
6510 In this code, @code{C::C} is exported from the current DLL, but the
6511 virtual table for @code{C} is not exported. (You can use
6512 @code{__attribute__} instead of @code{__declspec} if you prefer, but
6513 most Symbian OS code uses @code{__declspec}.)
6514
6515 @node MeP Type Attributes
6516 @subsection MeP Type Attributes
6517
6518 @cindex @code{based} type attribute, MeP
6519 @cindex @code{tiny} type attribute, MeP
6520 @cindex @code{near} type attribute, MeP
6521 @cindex @code{far} type attribute, MeP
6522 Many of the MeP variable attributes may be applied to types as well.
6523 Specifically, the @code{based}, @code{tiny}, @code{near}, and
6524 @code{far} attributes may be applied to either. The @code{io} and
6525 @code{cb} attributes may not be applied to types.
6526
6527 @node PowerPC Type Attributes
6528 @subsection PowerPC Type Attributes
6529
6530 Three attributes currently are defined for PowerPC configurations:
6531 @code{altivec}, @code{ms_struct} and @code{gcc_struct}.
6532
6533 @cindex @code{ms_struct} type attribute, PowerPC
6534 @cindex @code{gcc_struct} type attribute, PowerPC
6535 For full documentation of the @code{ms_struct} and @code{gcc_struct}
6536 attributes please see the documentation in @ref{x86 Type Attributes}.
6537
6538 @cindex @code{altivec} type attribute, PowerPC
6539 The @code{altivec} attribute allows one to declare AltiVec vector data
6540 types supported by the AltiVec Programming Interface Manual. The
6541 attribute requires an argument to specify one of three vector types:
6542 @code{vector__}, @code{pixel__} (always followed by unsigned short),
6543 and @code{bool__} (always followed by unsigned).
6544
6545 @smallexample
6546 __attribute__((altivec(vector__)))
6547 __attribute__((altivec(pixel__))) unsigned short
6548 __attribute__((altivec(bool__))) unsigned
6549 @end smallexample
6550
6551 These attributes mainly are intended to support the @code{__vector},
6552 @code{__pixel}, and @code{__bool} AltiVec keywords.
6553
6554 @node SPU Type Attributes
6555 @subsection SPU Type Attributes
6556
6557 @cindex @code{spu_vector} type attribute, SPU
6558 The SPU supports the @code{spu_vector} attribute for types. This attribute
6559 allows one to declare vector data types supported by the Sony/Toshiba/IBM SPU
6560 Language Extensions Specification. It is intended to support the
6561 @code{__vector} keyword.
6562
6563 @node x86 Type Attributes
6564 @subsection x86 Type Attributes
6565
6566 Two attributes are currently defined for x86 configurations:
6567 @code{ms_struct} and @code{gcc_struct}.
6568
6569 @table @code
6570
6571 @item ms_struct
6572 @itemx gcc_struct
6573 @cindex @code{ms_struct} type attribute, x86
6574 @cindex @code{gcc_struct} type attribute, x86
6575
6576 If @code{packed} is used on a structure, or if bit-fields are used
6577 it may be that the Microsoft ABI packs them differently
6578 than GCC normally packs them. Particularly when moving packed
6579 data between functions compiled with GCC and the native Microsoft compiler
6580 (either via function call or as data in a file), it may be necessary to access
6581 either format.
6582
6583 The @code{ms_struct} and @code{gcc_struct} attributes correspond
6584 to the @option{-mms-bitfields} and @option{-mno-ms-bitfields}
6585 command-line options, respectively;
6586 see @ref{x86 Options}, for details of how structure layout is affected.
6587 @xref{x86 Variable Attributes}, for information about the corresponding
6588 attributes on variables.
6589
6590 @end table
6591
6592 @node Label Attributes
6593 @section Label Attributes
6594 @cindex Label Attributes
6595
6596 GCC allows attributes to be set on C labels. @xref{Attribute Syntax}, for
6597 details of the exact syntax for using attributes. Other attributes are
6598 available for functions (@pxref{Function Attributes}), variables
6599 (@pxref{Variable Attributes}), enumerators (@pxref{Enumerator Attributes}),
6600 and for types (@pxref{Type Attributes}).
6601
6602 This example uses the @code{cold} label attribute to indicate the
6603 @code{ErrorHandling} branch is unlikely to be taken and that the
6604 @code{ErrorHandling} label is unused:
6605
6606 @smallexample
6607
6608 asm goto ("some asm" : : : : NoError);
6609
6610 /* This branch (the fall-through from the asm) is less commonly used */
6611 ErrorHandling:
6612 __attribute__((cold, unused)); /* Semi-colon is required here */
6613 printf("error\n");
6614 return 0;
6615
6616 NoError:
6617 printf("no error\n");
6618 return 1;
6619 @end smallexample
6620
6621 @table @code
6622 @item unused
6623 @cindex @code{unused} label attribute
6624 This feature is intended for program-generated code that may contain
6625 unused labels, but which is compiled with @option{-Wall}. It is
6626 not normally appropriate to use in it human-written code, though it
6627 could be useful in cases where the code that jumps to the label is
6628 contained within an @code{#ifdef} conditional.
6629
6630 @item hot
6631 @cindex @code{hot} label attribute
6632 The @code{hot} attribute on a label is used to inform the compiler that
6633 the path following the label is more likely than paths that are not so
6634 annotated. This attribute is used in cases where @code{__builtin_expect}
6635 cannot be used, for instance with computed goto or @code{asm goto}.
6636
6637 @item cold
6638 @cindex @code{cold} label attribute
6639 The @code{cold} attribute on labels is used to inform the compiler that
6640 the path following the label is unlikely to be executed. This attribute
6641 is used in cases where @code{__builtin_expect} cannot be used, for instance
6642 with computed goto or @code{asm goto}.
6643
6644 @end table
6645
6646 @node Enumerator Attributes
6647 @section Enumerator Attributes
6648 @cindex Enumerator Attributes
6649
6650 GCC allows attributes to be set on enumerators. @xref{Attribute Syntax}, for
6651 details of the exact syntax for using attributes. Other attributes are
6652 available for functions (@pxref{Function Attributes}), variables
6653 (@pxref{Variable Attributes}), labels (@pxref{Label Attributes}),
6654 and for types (@pxref{Type Attributes}).
6655
6656 This example uses the @code{deprecated} enumerator attribute to indicate the
6657 @code{oldval} enumerator is deprecated:
6658
6659 @smallexample
6660 enum E @{
6661 oldval __attribute__((deprecated)),
6662 newval
6663 @};
6664
6665 int
6666 fn (void)
6667 @{
6668 return oldval;
6669 @}
6670 @end smallexample
6671
6672 @table @code
6673 @item deprecated
6674 @cindex @code{deprecated} enumerator attribute
6675 The @code{deprecated} attribute results in a warning if the enumerator
6676 is used anywhere in the source file. This is useful when identifying
6677 enumerators that are expected to be removed in a future version of a
6678 program. The warning also includes the location of the declaration
6679 of the deprecated enumerator, to enable users to easily find further
6680 information about why the enumerator is deprecated, or what they should
6681 do instead. Note that the warnings only occurs for uses.
6682
6683 @end table
6684
6685 @node Attribute Syntax
6686 @section Attribute Syntax
6687 @cindex attribute syntax
6688
6689 This section describes the syntax with which @code{__attribute__} may be
6690 used, and the constructs to which attribute specifiers bind, for the C
6691 language. Some details may vary for C++ and Objective-C@. Because of
6692 infelicities in the grammar for attributes, some forms described here
6693 may not be successfully parsed in all cases.
6694
6695 There are some problems with the semantics of attributes in C++. For
6696 example, there are no manglings for attributes, although they may affect
6697 code generation, so problems may arise when attributed types are used in
6698 conjunction with templates or overloading. Similarly, @code{typeid}
6699 does not distinguish between types with different attributes. Support
6700 for attributes in C++ may be restricted in future to attributes on
6701 declarations only, but not on nested declarators.
6702
6703 @xref{Function Attributes}, for details of the semantics of attributes
6704 applying to functions. @xref{Variable Attributes}, for details of the
6705 semantics of attributes applying to variables. @xref{Type Attributes},
6706 for details of the semantics of attributes applying to structure, union
6707 and enumerated types.
6708 @xref{Label Attributes}, for details of the semantics of attributes
6709 applying to labels.
6710 @xref{Enumerator Attributes}, for details of the semantics of attributes
6711 applying to enumerators.
6712
6713 An @dfn{attribute specifier} is of the form
6714 @code{__attribute__ ((@var{attribute-list}))}. An @dfn{attribute list}
6715 is a possibly empty comma-separated sequence of @dfn{attributes}, where
6716 each attribute is one of the following:
6717
6718 @itemize @bullet
6719 @item
6720 Empty. Empty attributes are ignored.
6721
6722 @item
6723 An attribute name
6724 (which may be an identifier such as @code{unused}, or a reserved
6725 word such as @code{const}).
6726
6727 @item
6728 An attribute name followed by a parenthesized list of
6729 parameters for the attribute.
6730 These parameters take one of the following forms:
6731
6732 @itemize @bullet
6733 @item
6734 An identifier. For example, @code{mode} attributes use this form.
6735
6736 @item
6737 An identifier followed by a comma and a non-empty comma-separated list
6738 of expressions. For example, @code{format} attributes use this form.
6739
6740 @item
6741 A possibly empty comma-separated list of expressions. For example,
6742 @code{format_arg} attributes use this form with the list being a single
6743 integer constant expression, and @code{alias} attributes use this form
6744 with the list being a single string constant.
6745 @end itemize
6746 @end itemize
6747
6748 An @dfn{attribute specifier list} is a sequence of one or more attribute
6749 specifiers, not separated by any other tokens.
6750
6751 You may optionally specify attribute names with @samp{__}
6752 preceding and following the name.
6753 This allows you to use them in header files without
6754 being concerned about a possible macro of the same name. For example,
6755 you may use the attribute name @code{__noreturn__} instead of @code{noreturn}.
6756
6757
6758 @subsubheading Label Attributes
6759
6760 In GNU C, an attribute specifier list may appear after the colon following a
6761 label, other than a @code{case} or @code{default} label. GNU C++ only permits
6762 attributes on labels if the attribute specifier is immediately
6763 followed by a semicolon (i.e., the label applies to an empty
6764 statement). If the semicolon is missing, C++ label attributes are
6765 ambiguous, as it is permissible for a declaration, which could begin
6766 with an attribute list, to be labelled in C++. Declarations cannot be
6767 labelled in C90 or C99, so the ambiguity does not arise there.
6768
6769 @subsubheading Enumerator Attributes
6770
6771 In GNU C, an attribute specifier list may appear as part of an enumerator.
6772 The attribute goes after the enumeration constant, before @code{=}, if
6773 present. The optional attribute in the enumerator appertains to the
6774 enumeration constant. It is not possible to place the attribute after
6775 the constant expression, if present.
6776
6777 @subsubheading Type Attributes
6778
6779 An attribute specifier list may appear as part of a @code{struct},
6780 @code{union} or @code{enum} specifier. It may go either immediately
6781 after the @code{struct}, @code{union} or @code{enum} keyword, or after
6782 the closing brace. The former syntax is preferred.
6783 Where attribute specifiers follow the closing brace, they are considered
6784 to relate to the structure, union or enumerated type defined, not to any
6785 enclosing declaration the type specifier appears in, and the type
6786 defined is not complete until after the attribute specifiers.
6787 @c Otherwise, there would be the following problems: a shift/reduce
6788 @c conflict between attributes binding the struct/union/enum and
6789 @c binding to the list of specifiers/qualifiers; and "aligned"
6790 @c attributes could use sizeof for the structure, but the size could be
6791 @c changed later by "packed" attributes.
6792
6793
6794 @subsubheading All other attributes
6795
6796 Otherwise, an attribute specifier appears as part of a declaration,
6797 counting declarations of unnamed parameters and type names, and relates
6798 to that declaration (which may be nested in another declaration, for
6799 example in the case of a parameter declaration), or to a particular declarator
6800 within a declaration. Where an
6801 attribute specifier is applied to a parameter declared as a function or
6802 an array, it should apply to the function or array rather than the
6803 pointer to which the parameter is implicitly converted, but this is not
6804 yet correctly implemented.
6805
6806 Any list of specifiers and qualifiers at the start of a declaration may
6807 contain attribute specifiers, whether or not such a list may in that
6808 context contain storage class specifiers. (Some attributes, however,
6809 are essentially in the nature of storage class specifiers, and only make
6810 sense where storage class specifiers may be used; for example,
6811 @code{section}.) There is one necessary limitation to this syntax: the
6812 first old-style parameter declaration in a function definition cannot
6813 begin with an attribute specifier, because such an attribute applies to
6814 the function instead by syntax described below (which, however, is not
6815 yet implemented in this case). In some other cases, attribute
6816 specifiers are permitted by this grammar but not yet supported by the
6817 compiler. All attribute specifiers in this place relate to the
6818 declaration as a whole. In the obsolescent usage where a type of
6819 @code{int} is implied by the absence of type specifiers, such a list of
6820 specifiers and qualifiers may be an attribute specifier list with no
6821 other specifiers or qualifiers.
6822
6823 At present, the first parameter in a function prototype must have some
6824 type specifier that is not an attribute specifier; this resolves an
6825 ambiguity in the interpretation of @code{void f(int
6826 (__attribute__((foo)) x))}, but is subject to change. At present, if
6827 the parentheses of a function declarator contain only attributes then
6828 those attributes are ignored, rather than yielding an error or warning
6829 or implying a single parameter of type int, but this is subject to
6830 change.
6831
6832 An attribute specifier list may appear immediately before a declarator
6833 (other than the first) in a comma-separated list of declarators in a
6834 declaration of more than one identifier using a single list of
6835 specifiers and qualifiers. Such attribute specifiers apply
6836 only to the identifier before whose declarator they appear. For
6837 example, in
6838
6839 @smallexample
6840 __attribute__((noreturn)) void d0 (void),
6841 __attribute__((format(printf, 1, 2))) d1 (const char *, ...),
6842 d2 (void);
6843 @end smallexample
6844
6845 @noindent
6846 the @code{noreturn} attribute applies to all the functions
6847 declared; the @code{format} attribute only applies to @code{d1}.
6848
6849 An attribute specifier list may appear immediately before the comma,
6850 @code{=} or semicolon terminating the declaration of an identifier other
6851 than a function definition. Such attribute specifiers apply
6852 to the declared object or function. Where an
6853 assembler name for an object or function is specified (@pxref{Asm
6854 Labels}), the attribute must follow the @code{asm}
6855 specification.
6856
6857 An attribute specifier list may, in future, be permitted to appear after
6858 the declarator in a function definition (before any old-style parameter
6859 declarations or the function body).
6860
6861 Attribute specifiers may be mixed with type qualifiers appearing inside
6862 the @code{[]} of a parameter array declarator, in the C99 construct by
6863 which such qualifiers are applied to the pointer to which the array is
6864 implicitly converted. Such attribute specifiers apply to the pointer,
6865 not to the array, but at present this is not implemented and they are
6866 ignored.
6867
6868 An attribute specifier list may appear at the start of a nested
6869 declarator. At present, there are some limitations in this usage: the
6870 attributes correctly apply to the declarator, but for most individual
6871 attributes the semantics this implies are not implemented.
6872 When attribute specifiers follow the @code{*} of a pointer
6873 declarator, they may be mixed with any type qualifiers present.
6874 The following describes the formal semantics of this syntax. It makes the
6875 most sense if you are familiar with the formal specification of
6876 declarators in the ISO C standard.
6877
6878 Consider (as in C99 subclause 6.7.5 paragraph 4) a declaration @code{T
6879 D1}, where @code{T} contains declaration specifiers that specify a type
6880 @var{Type} (such as @code{int}) and @code{D1} is a declarator that
6881 contains an identifier @var{ident}. The type specified for @var{ident}
6882 for derived declarators whose type does not include an attribute
6883 specifier is as in the ISO C standard.
6884
6885 If @code{D1} has the form @code{( @var{attribute-specifier-list} D )},
6886 and the declaration @code{T D} specifies the type
6887 ``@var{derived-declarator-type-list} @var{Type}'' for @var{ident}, then
6888 @code{T D1} specifies the type ``@var{derived-declarator-type-list}
6889 @var{attribute-specifier-list} @var{Type}'' for @var{ident}.
6890
6891 If @code{D1} has the form @code{*
6892 @var{type-qualifier-and-attribute-specifier-list} D}, and the
6893 declaration @code{T D} specifies the type
6894 ``@var{derived-declarator-type-list} @var{Type}'' for @var{ident}, then
6895 @code{T D1} specifies the type ``@var{derived-declarator-type-list}
6896 @var{type-qualifier-and-attribute-specifier-list} pointer to @var{Type}'' for
6897 @var{ident}.
6898
6899 For example,
6900
6901 @smallexample
6902 void (__attribute__((noreturn)) ****f) (void);
6903 @end smallexample
6904
6905 @noindent
6906 specifies the type ``pointer to pointer to pointer to pointer to
6907 non-returning function returning @code{void}''. As another example,
6908
6909 @smallexample
6910 char *__attribute__((aligned(8))) *f;
6911 @end smallexample
6912
6913 @noindent
6914 specifies the type ``pointer to 8-byte-aligned pointer to @code{char}''.
6915 Note again that this does not work with most attributes; for example,
6916 the usage of @samp{aligned} and @samp{noreturn} attributes given above
6917 is not yet supported.
6918
6919 For compatibility with existing code written for compiler versions that
6920 did not implement attributes on nested declarators, some laxity is
6921 allowed in the placing of attributes. If an attribute that only applies
6922 to types is applied to a declaration, it is treated as applying to
6923 the type of that declaration. If an attribute that only applies to
6924 declarations is applied to the type of a declaration, it is treated
6925 as applying to that declaration; and, for compatibility with code
6926 placing the attributes immediately before the identifier declared, such
6927 an attribute applied to a function return type is treated as
6928 applying to the function type, and such an attribute applied to an array
6929 element type is treated as applying to the array type. If an
6930 attribute that only applies to function types is applied to a
6931 pointer-to-function type, it is treated as applying to the pointer
6932 target type; if such an attribute is applied to a function return type
6933 that is not a pointer-to-function type, it is treated as applying
6934 to the function type.
6935
6936 @node Function Prototypes
6937 @section Prototypes and Old-Style Function Definitions
6938 @cindex function prototype declarations
6939 @cindex old-style function definitions
6940 @cindex promotion of formal parameters
6941
6942 GNU C extends ISO C to allow a function prototype to override a later
6943 old-style non-prototype definition. Consider the following example:
6944
6945 @smallexample
6946 /* @r{Use prototypes unless the compiler is old-fashioned.} */
6947 #ifdef __STDC__
6948 #define P(x) x
6949 #else
6950 #define P(x) ()
6951 #endif
6952
6953 /* @r{Prototype function declaration.} */
6954 int isroot P((uid_t));
6955
6956 /* @r{Old-style function definition.} */
6957 int
6958 isroot (x) /* @r{??? lossage here ???} */
6959 uid_t x;
6960 @{
6961 return x == 0;
6962 @}
6963 @end smallexample
6964
6965 Suppose the type @code{uid_t} happens to be @code{short}. ISO C does
6966 not allow this example, because subword arguments in old-style
6967 non-prototype definitions are promoted. Therefore in this example the
6968 function definition's argument is really an @code{int}, which does not
6969 match the prototype argument type of @code{short}.
6970
6971 This restriction of ISO C makes it hard to write code that is portable
6972 to traditional C compilers, because the programmer does not know
6973 whether the @code{uid_t} type is @code{short}, @code{int}, or
6974 @code{long}. Therefore, in cases like these GNU C allows a prototype
6975 to override a later old-style definition. More precisely, in GNU C, a
6976 function prototype argument type overrides the argument type specified
6977 by a later old-style definition if the former type is the same as the
6978 latter type before promotion. Thus in GNU C the above example is
6979 equivalent to the following:
6980
6981 @smallexample
6982 int isroot (uid_t);
6983
6984 int
6985 isroot (uid_t x)
6986 @{
6987 return x == 0;
6988 @}
6989 @end smallexample
6990
6991 @noindent
6992 GNU C++ does not support old-style function definitions, so this
6993 extension is irrelevant.
6994
6995 @node C++ Comments
6996 @section C++ Style Comments
6997 @cindex @code{//}
6998 @cindex C++ comments
6999 @cindex comments, C++ style
7000
7001 In GNU C, you may use C++ style comments, which start with @samp{//} and
7002 continue until the end of the line. Many other C implementations allow
7003 such comments, and they are included in the 1999 C standard. However,
7004 C++ style comments are not recognized if you specify an @option{-std}
7005 option specifying a version of ISO C before C99, or @option{-ansi}
7006 (equivalent to @option{-std=c90}).
7007
7008 @node Dollar Signs
7009 @section Dollar Signs in Identifier Names
7010 @cindex $
7011 @cindex dollar signs in identifier names
7012 @cindex identifier names, dollar signs in
7013
7014 In GNU C, you may normally use dollar signs in identifier names.
7015 This is because many traditional C implementations allow such identifiers.
7016 However, dollar signs in identifiers are not supported on a few target
7017 machines, typically because the target assembler does not allow them.
7018
7019 @node Character Escapes
7020 @section The Character @key{ESC} in Constants
7021
7022 You can use the sequence @samp{\e} in a string or character constant to
7023 stand for the ASCII character @key{ESC}.
7024
7025 @node Alignment
7026 @section Inquiring on Alignment of Types or Variables
7027 @cindex alignment
7028 @cindex type alignment
7029 @cindex variable alignment
7030
7031 The keyword @code{__alignof__} allows you to inquire about how an object
7032 is aligned, or the minimum alignment usually required by a type. Its
7033 syntax is just like @code{sizeof}.
7034
7035 For example, if the target machine requires a @code{double} value to be
7036 aligned on an 8-byte boundary, then @code{__alignof__ (double)} is 8.
7037 This is true on many RISC machines. On more traditional machine
7038 designs, @code{__alignof__ (double)} is 4 or even 2.
7039
7040 Some machines never actually require alignment; they allow reference to any
7041 data type even at an odd address. For these machines, @code{__alignof__}
7042 reports the smallest alignment that GCC gives the data type, usually as
7043 mandated by the target ABI.
7044
7045 If the operand of @code{__alignof__} is an lvalue rather than a type,
7046 its value is the required alignment for its type, taking into account
7047 any minimum alignment specified with GCC's @code{__attribute__}
7048 extension (@pxref{Variable Attributes}). For example, after this
7049 declaration:
7050
7051 @smallexample
7052 struct foo @{ int x; char y; @} foo1;
7053 @end smallexample
7054
7055 @noindent
7056 the value of @code{__alignof__ (foo1.y)} is 1, even though its actual
7057 alignment is probably 2 or 4, the same as @code{__alignof__ (int)}.
7058
7059 It is an error to ask for the alignment of an incomplete type.
7060
7061
7062 @node Inline
7063 @section An Inline Function is As Fast As a Macro
7064 @cindex inline functions
7065 @cindex integrating function code
7066 @cindex open coding
7067 @cindex macros, inline alternative
7068
7069 By declaring a function inline, you can direct GCC to make
7070 calls to that function faster. One way GCC can achieve this is to
7071 integrate that function's code into the code for its callers. This
7072 makes execution faster by eliminating the function-call overhead; in
7073 addition, if any of the actual argument values are constant, their
7074 known values may permit simplifications at compile time so that not
7075 all of the inline function's code needs to be included. The effect on
7076 code size is less predictable; object code may be larger or smaller
7077 with function inlining, depending on the particular case. You can
7078 also direct GCC to try to integrate all ``simple enough'' functions
7079 into their callers with the option @option{-finline-functions}.
7080
7081 GCC implements three different semantics of declaring a function
7082 inline. One is available with @option{-std=gnu89} or
7083 @option{-fgnu89-inline} or when @code{gnu_inline} attribute is present
7084 on all inline declarations, another when
7085 @option{-std=c99}, @option{-std=c11},
7086 @option{-std=gnu99} or @option{-std=gnu11}
7087 (without @option{-fgnu89-inline}), and the third
7088 is used when compiling C++.
7089
7090 To declare a function inline, use the @code{inline} keyword in its
7091 declaration, like this:
7092
7093 @smallexample
7094 static inline int
7095 inc (int *a)
7096 @{
7097 return (*a)++;
7098 @}
7099 @end smallexample
7100
7101 If you are writing a header file to be included in ISO C90 programs, write
7102 @code{__inline__} instead of @code{inline}. @xref{Alternate Keywords}.
7103
7104 The three types of inlining behave similarly in two important cases:
7105 when the @code{inline} keyword is used on a @code{static} function,
7106 like the example above, and when a function is first declared without
7107 using the @code{inline} keyword and then is defined with
7108 @code{inline}, like this:
7109
7110 @smallexample
7111 extern int inc (int *a);
7112 inline int
7113 inc (int *a)
7114 @{
7115 return (*a)++;
7116 @}
7117 @end smallexample
7118
7119 In both of these common cases, the program behaves the same as if you
7120 had not used the @code{inline} keyword, except for its speed.
7121
7122 @cindex inline functions, omission of
7123 @opindex fkeep-inline-functions
7124 When a function is both inline and @code{static}, if all calls to the
7125 function are integrated into the caller, and the function's address is
7126 never used, then the function's own assembler code is never referenced.
7127 In this case, GCC does not actually output assembler code for the
7128 function, unless you specify the option @option{-fkeep-inline-functions}.
7129 If there is a nonintegrated call, then the function is compiled to
7130 assembler code as usual. The function must also be compiled as usual if
7131 the program refers to its address, because that can't be inlined.
7132
7133 @opindex Winline
7134 Note that certain usages in a function definition can make it unsuitable
7135 for inline substitution. Among these usages are: variadic functions,
7136 use of @code{alloca}, use of computed goto (@pxref{Labels as Values}),
7137 use of nonlocal goto, use of nested functions, use of @code{setjmp}, use
7138 of @code{__builtin_longjmp} and use of @code{__builtin_return} or
7139 @code{__builtin_apply_args}. Using @option{-Winline} warns when a
7140 function marked @code{inline} could not be substituted, and gives the
7141 reason for the failure.
7142
7143 @cindex automatic @code{inline} for C++ member fns
7144 @cindex @code{inline} automatic for C++ member fns
7145 @cindex member fns, automatically @code{inline}
7146 @cindex C++ member fns, automatically @code{inline}
7147 @opindex fno-default-inline
7148 As required by ISO C++, GCC considers member functions defined within
7149 the body of a class to be marked inline even if they are
7150 not explicitly declared with the @code{inline} keyword. You can
7151 override this with @option{-fno-default-inline}; @pxref{C++ Dialect
7152 Options,,Options Controlling C++ Dialect}.
7153
7154 GCC does not inline any functions when not optimizing unless you specify
7155 the @samp{always_inline} attribute for the function, like this:
7156
7157 @smallexample
7158 /* @r{Prototype.} */
7159 inline void foo (const char) __attribute__((always_inline));
7160 @end smallexample
7161
7162 The remainder of this section is specific to GNU C90 inlining.
7163
7164 @cindex non-static inline function
7165 When an inline function is not @code{static}, then the compiler must assume
7166 that there may be calls from other source files; since a global symbol can
7167 be defined only once in any program, the function must not be defined in
7168 the other source files, so the calls therein cannot be integrated.
7169 Therefore, a non-@code{static} inline function is always compiled on its
7170 own in the usual fashion.
7171
7172 If you specify both @code{inline} and @code{extern} in the function
7173 definition, then the definition is used only for inlining. In no case
7174 is the function compiled on its own, not even if you refer to its
7175 address explicitly. Such an address becomes an external reference, as
7176 if you had only declared the function, and had not defined it.
7177
7178 This combination of @code{inline} and @code{extern} has almost the
7179 effect of a macro. The way to use it is to put a function definition in
7180 a header file with these keywords, and put another copy of the
7181 definition (lacking @code{inline} and @code{extern}) in a library file.
7182 The definition in the header file causes most calls to the function
7183 to be inlined. If any uses of the function remain, they refer to
7184 the single copy in the library.
7185
7186 @node Volatiles
7187 @section When is a Volatile Object Accessed?
7188 @cindex accessing volatiles
7189 @cindex volatile read
7190 @cindex volatile write
7191 @cindex volatile access
7192
7193 C has the concept of volatile objects. These are normally accessed by
7194 pointers and used for accessing hardware or inter-thread
7195 communication. The standard encourages compilers to refrain from
7196 optimizations concerning accesses to volatile objects, but leaves it
7197 implementation defined as to what constitutes a volatile access. The
7198 minimum requirement is that at a sequence point all previous accesses
7199 to volatile objects have stabilized and no subsequent accesses have
7200 occurred. Thus an implementation is free to reorder and combine
7201 volatile accesses that occur between sequence points, but cannot do
7202 so for accesses across a sequence point. The use of volatile does
7203 not allow you to violate the restriction on updating objects multiple
7204 times between two sequence points.
7205
7206 Accesses to non-volatile objects are not ordered with respect to
7207 volatile accesses. You cannot use a volatile object as a memory
7208 barrier to order a sequence of writes to non-volatile memory. For
7209 instance:
7210
7211 @smallexample
7212 int *ptr = @var{something};
7213 volatile int vobj;
7214 *ptr = @var{something};
7215 vobj = 1;
7216 @end smallexample
7217
7218 @noindent
7219 Unless @var{*ptr} and @var{vobj} can be aliased, it is not guaranteed
7220 that the write to @var{*ptr} occurs by the time the update
7221 of @var{vobj} happens. If you need this guarantee, you must use
7222 a stronger memory barrier such as:
7223
7224 @smallexample
7225 int *ptr = @var{something};
7226 volatile int vobj;
7227 *ptr = @var{something};
7228 asm volatile ("" : : : "memory");
7229 vobj = 1;
7230 @end smallexample
7231
7232 A scalar volatile object is read when it is accessed in a void context:
7233
7234 @smallexample
7235 volatile int *src = @var{somevalue};
7236 *src;
7237 @end smallexample
7238
7239 Such expressions are rvalues, and GCC implements this as a
7240 read of the volatile object being pointed to.
7241
7242 Assignments are also expressions and have an rvalue. However when
7243 assigning to a scalar volatile, the volatile object is not reread,
7244 regardless of whether the assignment expression's rvalue is used or
7245 not. If the assignment's rvalue is used, the value is that assigned
7246 to the volatile object. For instance, there is no read of @var{vobj}
7247 in all the following cases:
7248
7249 @smallexample
7250 int obj;
7251 volatile int vobj;
7252 vobj = @var{something};
7253 obj = vobj = @var{something};
7254 obj ? vobj = @var{onething} : vobj = @var{anotherthing};
7255 obj = (@var{something}, vobj = @var{anotherthing});
7256 @end smallexample
7257
7258 If you need to read the volatile object after an assignment has
7259 occurred, you must use a separate expression with an intervening
7260 sequence point.
7261
7262 As bit-fields are not individually addressable, volatile bit-fields may
7263 be implicitly read when written to, or when adjacent bit-fields are
7264 accessed. Bit-field operations may be optimized such that adjacent
7265 bit-fields are only partially accessed, if they straddle a storage unit
7266 boundary. For these reasons it is unwise to use volatile bit-fields to
7267 access hardware.
7268
7269 @node Using Assembly Language with C
7270 @section How to Use Inline Assembly Language in C Code
7271 @cindex @code{asm} keyword
7272 @cindex assembly language in C
7273 @cindex inline assembly language
7274 @cindex mixing assembly language and C
7275
7276 The @code{asm} keyword allows you to embed assembler instructions
7277 within C code. GCC provides two forms of inline @code{asm}
7278 statements. A @dfn{basic @code{asm}} statement is one with no
7279 operands (@pxref{Basic Asm}), while an @dfn{extended @code{asm}}
7280 statement (@pxref{Extended Asm}) includes one or more operands.
7281 The extended form is preferred for mixing C and assembly language
7282 within a function, but to include assembly language at
7283 top level you must use basic @code{asm}.
7284
7285 You can also use the @code{asm} keyword to override the assembler name
7286 for a C symbol, or to place a C variable in a specific register.
7287
7288 @menu
7289 * Basic Asm:: Inline assembler without operands.
7290 * Extended Asm:: Inline assembler with operands.
7291 * Constraints:: Constraints for @code{asm} operands
7292 * Asm Labels:: Specifying the assembler name to use for a C symbol.
7293 * Explicit Register Variables:: Defining variables residing in specified
7294 registers.
7295 * Size of an asm:: How GCC calculates the size of an @code{asm} block.
7296 @end menu
7297
7298 @node Basic Asm
7299 @subsection Basic Asm --- Assembler Instructions Without Operands
7300 @cindex basic @code{asm}
7301 @cindex assembly language in C, basic
7302
7303 A basic @code{asm} statement has the following syntax:
7304
7305 @example
7306 asm @r{[} volatile @r{]} ( @var{AssemblerInstructions} )
7307 @end example
7308
7309 The @code{asm} keyword is a GNU extension.
7310 When writing code that can be compiled with @option{-ansi} and the
7311 various @option{-std} options, use @code{__asm__} instead of
7312 @code{asm} (@pxref{Alternate Keywords}).
7313
7314 @subsubheading Qualifiers
7315 @table @code
7316 @item volatile
7317 The optional @code{volatile} qualifier has no effect.
7318 All basic @code{asm} blocks are implicitly volatile.
7319 @end table
7320
7321 @subsubheading Parameters
7322 @table @var
7323
7324 @item AssemblerInstructions
7325 This is a literal string that specifies the assembler code. The string can
7326 contain any instructions recognized by the assembler, including directives.
7327 GCC does not parse the assembler instructions themselves and
7328 does not know what they mean or even whether they are valid assembler input.
7329
7330 You may place multiple assembler instructions together in a single @code{asm}
7331 string, separated by the characters normally used in assembly code for the
7332 system. A combination that works in most places is a newline to break the
7333 line, plus a tab character (written as @samp{\n\t}).
7334 Some assemblers allow semicolons as a line separator. However,
7335 note that some assembler dialects use semicolons to start a comment.
7336 @end table
7337
7338 @subsubheading Remarks
7339 Using extended @code{asm} typically produces smaller, safer, and more
7340 efficient code, and in most cases it is a better solution than basic
7341 @code{asm}. However, there are two situations where only basic @code{asm}
7342 can be used:
7343
7344 @itemize @bullet
7345 @item
7346 Extended @code{asm} statements have to be inside a C
7347 function, so to write inline assembly language at file scope (``top-level''),
7348 outside of C functions, you must use basic @code{asm}.
7349 You can use this technique to emit assembler directives,
7350 define assembly language macros that can be invoked elsewhere in the file,
7351 or write entire functions in assembly language.
7352
7353 @item
7354 Functions declared
7355 with the @code{naked} attribute also require basic @code{asm}
7356 (@pxref{Function Attributes}).
7357 @end itemize
7358
7359 Safely accessing C data and calling functions from basic @code{asm} is more
7360 complex than it may appear. To access C data, it is better to use extended
7361 @code{asm}.
7362
7363 Do not expect a sequence of @code{asm} statements to remain perfectly
7364 consecutive after compilation. If certain instructions need to remain
7365 consecutive in the output, put them in a single multi-instruction @code{asm}
7366 statement. Note that GCC's optimizers can move @code{asm} statements
7367 relative to other code, including across jumps.
7368
7369 @code{asm} statements may not perform jumps into other @code{asm} statements.
7370 GCC does not know about these jumps, and therefore cannot take
7371 account of them when deciding how to optimize. Jumps from @code{asm} to C
7372 labels are only supported in extended @code{asm}.
7373
7374 Under certain circumstances, GCC may duplicate (or remove duplicates of) your
7375 assembly code when optimizing. This can lead to unexpected duplicate
7376 symbol errors during compilation if your assembly code defines symbols or
7377 labels.
7378
7379 Since GCC does not parse the @var{AssemblerInstructions}, it has no
7380 visibility of any symbols it references. This may result in GCC discarding
7381 those symbols as unreferenced.
7382
7383 The compiler copies the assembler instructions in a basic @code{asm}
7384 verbatim to the assembly language output file, without
7385 processing dialects or any of the @samp{%} operators that are available with
7386 extended @code{asm}. This results in minor differences between basic
7387 @code{asm} strings and extended @code{asm} templates. For example, to refer to
7388 registers you might use @samp{%eax} in basic @code{asm} and
7389 @samp{%%eax} in extended @code{asm}.
7390
7391 On targets such as x86 that support multiple assembler dialects,
7392 all basic @code{asm} blocks use the assembler dialect specified by the
7393 @option{-masm} command-line option (@pxref{x86 Options}).
7394 Basic @code{asm} provides no
7395 mechanism to provide different assembler strings for different dialects.
7396
7397 Here is an example of basic @code{asm} for i386:
7398
7399 @example
7400 /* Note that this code will not compile with -masm=intel */
7401 #define DebugBreak() asm("int $3")
7402 @end example
7403
7404 @node Extended Asm
7405 @subsection Extended Asm - Assembler Instructions with C Expression Operands
7406 @cindex extended @code{asm}
7407 @cindex assembly language in C, extended
7408
7409 With extended @code{asm} you can read and write C variables from
7410 assembler and perform jumps from assembler code to C labels.
7411 Extended @code{asm} syntax uses colons (@samp{:}) to delimit
7412 the operand parameters after the assembler template:
7413
7414 @example
7415 asm @r{[}volatile@r{]} ( @var{AssemblerTemplate}
7416 : @var{OutputOperands}
7417 @r{[} : @var{InputOperands}
7418 @r{[} : @var{Clobbers} @r{]} @r{]})
7419
7420 asm @r{[}volatile@r{]} goto ( @var{AssemblerTemplate}
7421 :
7422 : @var{InputOperands}
7423 : @var{Clobbers}
7424 : @var{GotoLabels})
7425 @end example
7426
7427 The @code{asm} keyword is a GNU extension.
7428 When writing code that can be compiled with @option{-ansi} and the
7429 various @option{-std} options, use @code{__asm__} instead of
7430 @code{asm} (@pxref{Alternate Keywords}).
7431
7432 @subsubheading Qualifiers
7433 @table @code
7434
7435 @item volatile
7436 The typical use of extended @code{asm} statements is to manipulate input
7437 values to produce output values. However, your @code{asm} statements may
7438 also produce side effects. If so, you may need to use the @code{volatile}
7439 qualifier to disable certain optimizations. @xref{Volatile}.
7440
7441 @item goto
7442 This qualifier informs the compiler that the @code{asm} statement may
7443 perform a jump to one of the labels listed in the @var{GotoLabels}.
7444 @xref{GotoLabels}.
7445 @end table
7446
7447 @subsubheading Parameters
7448 @table @var
7449 @item AssemblerTemplate
7450 This is a literal string that is the template for the assembler code. It is a
7451 combination of fixed text and tokens that refer to the input, output,
7452 and goto parameters. @xref{AssemblerTemplate}.
7453
7454 @item OutputOperands
7455 A comma-separated list of the C variables modified by the instructions in the
7456 @var{AssemblerTemplate}. An empty list is permitted. @xref{OutputOperands}.
7457
7458 @item InputOperands
7459 A comma-separated list of C expressions read by the instructions in the
7460 @var{AssemblerTemplate}. An empty list is permitted. @xref{InputOperands}.
7461
7462 @item Clobbers
7463 A comma-separated list of registers or other values changed by the
7464 @var{AssemblerTemplate}, beyond those listed as outputs.
7465 An empty list is permitted. @xref{Clobbers}.
7466
7467 @item GotoLabels
7468 When you are using the @code{goto} form of @code{asm}, this section contains
7469 the list of all C labels to which the code in the
7470 @var{AssemblerTemplate} may jump.
7471 @xref{GotoLabels}.
7472
7473 @code{asm} statements may not perform jumps into other @code{asm} statements,
7474 only to the listed @var{GotoLabels}.
7475 GCC's optimizers do not know about other jumps; therefore they cannot take
7476 account of them when deciding how to optimize.
7477 @end table
7478
7479 The total number of input + output + goto operands is limited to 30.
7480
7481 @subsubheading Remarks
7482 The @code{asm} statement allows you to include assembly instructions directly
7483 within C code. This may help you to maximize performance in time-sensitive
7484 code or to access assembly instructions that are not readily available to C
7485 programs.
7486
7487 Note that extended @code{asm} statements must be inside a function. Only
7488 basic @code{asm} may be outside functions (@pxref{Basic Asm}).
7489 Functions declared with the @code{naked} attribute also require basic
7490 @code{asm} (@pxref{Function Attributes}).
7491
7492 While the uses of @code{asm} are many and varied, it may help to think of an
7493 @code{asm} statement as a series of low-level instructions that convert input
7494 parameters to output parameters. So a simple (if not particularly useful)
7495 example for i386 using @code{asm} might look like this:
7496
7497 @example
7498 int src = 1;
7499 int dst;
7500
7501 asm ("mov %1, %0\n\t"
7502 "add $1, %0"
7503 : "=r" (dst)
7504 : "r" (src));
7505
7506 printf("%d\n", dst);
7507 @end example
7508
7509 This code copies @code{src} to @code{dst} and add 1 to @code{dst}.
7510
7511 @anchor{Volatile}
7512 @subsubsection Volatile
7513 @cindex volatile @code{asm}
7514 @cindex @code{asm} volatile
7515
7516 GCC's optimizers sometimes discard @code{asm} statements if they determine
7517 there is no need for the output variables. Also, the optimizers may move
7518 code out of loops if they believe that the code will always return the same
7519 result (i.e. none of its input values change between calls). Using the
7520 @code{volatile} qualifier disables these optimizations. @code{asm} statements
7521 that have no output operands, including @code{asm goto} statements,
7522 are implicitly volatile.
7523
7524 This i386 code demonstrates a case that does not use (or require) the
7525 @code{volatile} qualifier. If it is performing assertion checking, this code
7526 uses @code{asm} to perform the validation. Otherwise, @code{dwRes} is
7527 unreferenced by any code. As a result, the optimizers can discard the
7528 @code{asm} statement, which in turn removes the need for the entire
7529 @code{DoCheck} routine. By omitting the @code{volatile} qualifier when it
7530 isn't needed you allow the optimizers to produce the most efficient code
7531 possible.
7532
7533 @example
7534 void DoCheck(uint32_t dwSomeValue)
7535 @{
7536 uint32_t dwRes;
7537
7538 // Assumes dwSomeValue is not zero.
7539 asm ("bsfl %1,%0"
7540 : "=r" (dwRes)
7541 : "r" (dwSomeValue)
7542 : "cc");
7543
7544 assert(dwRes > 3);
7545 @}
7546 @end example
7547
7548 The next example shows a case where the optimizers can recognize that the input
7549 (@code{dwSomeValue}) never changes during the execution of the function and can
7550 therefore move the @code{asm} outside the loop to produce more efficient code.
7551 Again, using @code{volatile} disables this type of optimization.
7552
7553 @example
7554 void do_print(uint32_t dwSomeValue)
7555 @{
7556 uint32_t dwRes;
7557
7558 for (uint32_t x=0; x < 5; x++)
7559 @{
7560 // Assumes dwSomeValue is not zero.
7561 asm ("bsfl %1,%0"
7562 : "=r" (dwRes)
7563 : "r" (dwSomeValue)
7564 : "cc");
7565
7566 printf("%u: %u %u\n", x, dwSomeValue, dwRes);
7567 @}
7568 @}
7569 @end example
7570
7571 The following example demonstrates a case where you need to use the
7572 @code{volatile} qualifier.
7573 It uses the x86 @code{rdtsc} instruction, which reads
7574 the computer's time-stamp counter. Without the @code{volatile} qualifier,
7575 the optimizers might assume that the @code{asm} block will always return the
7576 same value and therefore optimize away the second call.
7577
7578 @example
7579 uint64_t msr;
7580
7581 asm volatile ( "rdtsc\n\t" // Returns the time in EDX:EAX.
7582 "shl $32, %%rdx\n\t" // Shift the upper bits left.
7583 "or %%rdx, %0" // 'Or' in the lower bits.
7584 : "=a" (msr)
7585 :
7586 : "rdx");
7587
7588 printf("msr: %llx\n", msr);
7589
7590 // Do other work...
7591
7592 // Reprint the timestamp
7593 asm volatile ( "rdtsc\n\t" // Returns the time in EDX:EAX.
7594 "shl $32, %%rdx\n\t" // Shift the upper bits left.
7595 "or %%rdx, %0" // 'Or' in the lower bits.
7596 : "=a" (msr)
7597 :
7598 : "rdx");
7599
7600 printf("msr: %llx\n", msr);
7601 @end example
7602
7603 GCC's optimizers do not treat this code like the non-volatile code in the
7604 earlier examples. They do not move it out of loops or omit it on the
7605 assumption that the result from a previous call is still valid.
7606
7607 Note that the compiler can move even volatile @code{asm} instructions relative
7608 to other code, including across jump instructions. For example, on many
7609 targets there is a system register that controls the rounding mode of
7610 floating-point operations. Setting it with a volatile @code{asm}, as in the
7611 following PowerPC example, does not work reliably.
7612
7613 @example
7614 asm volatile("mtfsf 255, %0" : : "f" (fpenv));
7615 sum = x + y;
7616 @end example
7617
7618 The compiler may move the addition back before the volatile @code{asm}. To
7619 make it work as expected, add an artificial dependency to the @code{asm} by
7620 referencing a variable in the subsequent code, for example:
7621
7622 @example
7623 asm volatile ("mtfsf 255,%1" : "=X" (sum) : "f" (fpenv));
7624 sum = x + y;
7625 @end example
7626
7627 Under certain circumstances, GCC may duplicate (or remove duplicates of) your
7628 assembly code when optimizing. This can lead to unexpected duplicate symbol
7629 errors during compilation if your asm code defines symbols or labels.
7630 Using @samp{%=}
7631 (@pxref{AssemblerTemplate}) may help resolve this problem.
7632
7633 @anchor{AssemblerTemplate}
7634 @subsubsection Assembler Template
7635 @cindex @code{asm} assembler template
7636
7637 An assembler template is a literal string containing assembler instructions.
7638 The compiler replaces tokens in the template that refer
7639 to inputs, outputs, and goto labels,
7640 and then outputs the resulting string to the assembler. The
7641 string can contain any instructions recognized by the assembler, including
7642 directives. GCC does not parse the assembler instructions
7643 themselves and does not know what they mean or even whether they are valid
7644 assembler input. However, it does count the statements
7645 (@pxref{Size of an asm}).
7646
7647 You may place multiple assembler instructions together in a single @code{asm}
7648 string, separated by the characters normally used in assembly code for the
7649 system. A combination that works in most places is a newline to break the
7650 line, plus a tab character to move to the instruction field (written as
7651 @samp{\n\t}).
7652 Some assemblers allow semicolons as a line separator. However, note
7653 that some assembler dialects use semicolons to start a comment.
7654
7655 Do not expect a sequence of @code{asm} statements to remain perfectly
7656 consecutive after compilation, even when you are using the @code{volatile}
7657 qualifier. If certain instructions need to remain consecutive in the output,
7658 put them in a single multi-instruction asm statement.
7659
7660 Accessing data from C programs without using input/output operands (such as
7661 by using global symbols directly from the assembler template) may not work as
7662 expected. Similarly, calling functions directly from an assembler template
7663 requires a detailed understanding of the target assembler and ABI.
7664
7665 Since GCC does not parse the assembler template,
7666 it has no visibility of any
7667 symbols it references. This may result in GCC discarding those symbols as
7668 unreferenced unless they are also listed as input, output, or goto operands.
7669
7670 @subsubheading Special format strings
7671
7672 In addition to the tokens described by the input, output, and goto operands,
7673 these tokens have special meanings in the assembler template:
7674
7675 @table @samp
7676 @item %%
7677 Outputs a single @samp{%} into the assembler code.
7678
7679 @item %=
7680 Outputs a number that is unique to each instance of the @code{asm}
7681 statement in the entire compilation. This option is useful when creating local
7682 labels and referring to them multiple times in a single template that
7683 generates multiple assembler instructions.
7684
7685 @item %@{
7686 @itemx %|
7687 @itemx %@}
7688 Outputs @samp{@{}, @samp{|}, and @samp{@}} characters (respectively)
7689 into the assembler code. When unescaped, these characters have special
7690 meaning to indicate multiple assembler dialects, as described below.
7691 @end table
7692
7693 @subsubheading Multiple assembler dialects in @code{asm} templates
7694
7695 On targets such as x86, GCC supports multiple assembler dialects.
7696 The @option{-masm} option controls which dialect GCC uses as its
7697 default for inline assembler. The target-specific documentation for the
7698 @option{-masm} option contains the list of supported dialects, as well as the
7699 default dialect if the option is not specified. This information may be
7700 important to understand, since assembler code that works correctly when
7701 compiled using one dialect will likely fail if compiled using another.
7702 @xref{x86 Options}.
7703
7704 If your code needs to support multiple assembler dialects (for example, if
7705 you are writing public headers that need to support a variety of compilation
7706 options), use constructs of this form:
7707
7708 @example
7709 @{ dialect0 | dialect1 | dialect2... @}
7710 @end example
7711
7712 This construct outputs @code{dialect0}
7713 when using dialect #0 to compile the code,
7714 @code{dialect1} for dialect #1, etc. If there are fewer alternatives within the
7715 braces than the number of dialects the compiler supports, the construct
7716 outputs nothing.
7717
7718 For example, if an x86 compiler supports two dialects
7719 (@samp{att}, @samp{intel}), an
7720 assembler template such as this:
7721
7722 @example
7723 "bt@{l %[Offset],%[Base] | %[Base],%[Offset]@}; jc %l2"
7724 @end example
7725
7726 @noindent
7727 is equivalent to one of
7728
7729 @example
7730 "btl %[Offset],%[Base] ; jc %l2" @r{/* att dialect */}
7731 "bt %[Base],%[Offset]; jc %l2" @r{/* intel dialect */}
7732 @end example
7733
7734 Using that same compiler, this code:
7735
7736 @example
7737 "xchg@{l@}\t@{%%@}ebx, %1"
7738 @end example
7739
7740 @noindent
7741 corresponds to either
7742
7743 @example
7744 "xchgl\t%%ebx, %1" @r{/* att dialect */}
7745 "xchg\tebx, %1" @r{/* intel dialect */}
7746 @end example
7747
7748 There is no support for nesting dialect alternatives.
7749
7750 @anchor{OutputOperands}
7751 @subsubsection Output Operands
7752 @cindex @code{asm} output operands
7753
7754 An @code{asm} statement has zero or more output operands indicating the names
7755 of C variables modified by the assembler code.
7756
7757 In this i386 example, @code{old} (referred to in the template string as
7758 @code{%0}) and @code{*Base} (as @code{%1}) are outputs and @code{Offset}
7759 (@code{%2}) is an input:
7760
7761 @example
7762 bool old;
7763
7764 __asm__ ("btsl %2,%1\n\t" // Turn on zero-based bit #Offset in Base.
7765 "sbb %0,%0" // Use the CF to calculate old.
7766 : "=r" (old), "+rm" (*Base)
7767 : "Ir" (Offset)
7768 : "cc");
7769
7770 return old;
7771 @end example
7772
7773 Operands are separated by commas. Each operand has this format:
7774
7775 @example
7776 @r{[} [@var{asmSymbolicName}] @r{]} @var{constraint} (@var{cvariablename})
7777 @end example
7778
7779 @table @var
7780 @item asmSymbolicName
7781 Specifies a symbolic name for the operand.
7782 Reference the name in the assembler template
7783 by enclosing it in square brackets
7784 (i.e. @samp{%[Value]}). The scope of the name is the @code{asm} statement
7785 that contains the definition. Any valid C variable name is acceptable,
7786 including names already defined in the surrounding code. No two operands
7787 within the same @code{asm} statement can use the same symbolic name.
7788
7789 When not using an @var{asmSymbolicName}, use the (zero-based) position
7790 of the operand
7791 in the list of operands in the assembler template. For example if there are
7792 three output operands, use @samp{%0} in the template to refer to the first,
7793 @samp{%1} for the second, and @samp{%2} for the third.
7794
7795 @item constraint
7796 A string constant specifying constraints on the placement of the operand;
7797 @xref{Constraints}, for details.
7798
7799 Output constraints must begin with either @samp{=} (a variable overwriting an
7800 existing value) or @samp{+} (when reading and writing). When using
7801 @samp{=}, do not assume the location contains the existing value
7802 on entry to the @code{asm}, except
7803 when the operand is tied to an input; @pxref{InputOperands,,Input Operands}.
7804
7805 After the prefix, there must be one or more additional constraints
7806 (@pxref{Constraints}) that describe where the value resides. Common
7807 constraints include @samp{r} for register and @samp{m} for memory.
7808 When you list more than one possible location (for example, @code{"=rm"}),
7809 the compiler chooses the most efficient one based on the current context.
7810 If you list as many alternates as the @code{asm} statement allows, you permit
7811 the optimizers to produce the best possible code.
7812 If you must use a specific register, but your Machine Constraints do not
7813 provide sufficient control to select the specific register you want,
7814 local register variables may provide a solution (@pxref{Local Register
7815 Variables}).
7816
7817 @item cvariablename
7818 Specifies a C lvalue expression to hold the output, typically a variable name.
7819 The enclosing parentheses are a required part of the syntax.
7820
7821 @end table
7822
7823 When the compiler selects the registers to use to
7824 represent the output operands, it does not use any of the clobbered registers
7825 (@pxref{Clobbers}).
7826
7827 Output operand expressions must be lvalues. The compiler cannot check whether
7828 the operands have data types that are reasonable for the instruction being
7829 executed. For output expressions that are not directly addressable (for
7830 example a bit-field), the constraint must allow a register. In that case, GCC
7831 uses the register as the output of the @code{asm}, and then stores that
7832 register into the output.
7833
7834 Operands using the @samp{+} constraint modifier count as two operands
7835 (that is, both as input and output) towards the total maximum of 30 operands
7836 per @code{asm} statement.
7837
7838 Use the @samp{&} constraint modifier (@pxref{Modifiers}) on all output
7839 operands that must not overlap an input. Otherwise,
7840 GCC may allocate the output operand in the same register as an unrelated
7841 input operand, on the assumption that the assembler code consumes its
7842 inputs before producing outputs. This assumption may be false if the assembler
7843 code actually consists of more than one instruction.
7844
7845 The same problem can occur if one output parameter (@var{a}) allows a register
7846 constraint and another output parameter (@var{b}) allows a memory constraint.
7847 The code generated by GCC to access the memory address in @var{b} can contain
7848 registers which @emph{might} be shared by @var{a}, and GCC considers those
7849 registers to be inputs to the asm. As above, GCC assumes that such input
7850 registers are consumed before any outputs are written. This assumption may
7851 result in incorrect behavior if the asm writes to @var{a} before using
7852 @var{b}. Combining the @samp{&} modifier with the register constraint on @var{a}
7853 ensures that modifying @var{a} does not affect the address referenced by
7854 @var{b}. Otherwise, the location of @var{b}
7855 is undefined if @var{a} is modified before using @var{b}.
7856
7857 @code{asm} supports operand modifiers on operands (for example @samp{%k2}
7858 instead of simply @samp{%2}). Typically these qualifiers are hardware
7859 dependent. The list of supported modifiers for x86 is found at
7860 @ref{x86Operandmodifiers,x86 Operand modifiers}.
7861
7862 If the C code that follows the @code{asm} makes no use of any of the output
7863 operands, use @code{volatile} for the @code{asm} statement to prevent the
7864 optimizers from discarding the @code{asm} statement as unneeded
7865 (see @ref{Volatile}).
7866
7867 This code makes no use of the optional @var{asmSymbolicName}. Therefore it
7868 references the first output operand as @code{%0} (were there a second, it
7869 would be @code{%1}, etc). The number of the first input operand is one greater
7870 than that of the last output operand. In this i386 example, that makes
7871 @code{Mask} referenced as @code{%1}:
7872
7873 @example
7874 uint32_t Mask = 1234;
7875 uint32_t Index;
7876
7877 asm ("bsfl %1, %0"
7878 : "=r" (Index)
7879 : "r" (Mask)
7880 : "cc");
7881 @end example
7882
7883 That code overwrites the variable @code{Index} (@samp{=}),
7884 placing the value in a register (@samp{r}).
7885 Using the generic @samp{r} constraint instead of a constraint for a specific
7886 register allows the compiler to pick the register to use, which can result
7887 in more efficient code. This may not be possible if an assembler instruction
7888 requires a specific register.
7889
7890 The following i386 example uses the @var{asmSymbolicName} syntax.
7891 It produces the
7892 same result as the code above, but some may consider it more readable or more
7893 maintainable since reordering index numbers is not necessary when adding or
7894 removing operands. The names @code{aIndex} and @code{aMask}
7895 are only used in this example to emphasize which
7896 names get used where.
7897 It is acceptable to reuse the names @code{Index} and @code{Mask}.
7898
7899 @example
7900 uint32_t Mask = 1234;
7901 uint32_t Index;
7902
7903 asm ("bsfl %[aMask], %[aIndex]"
7904 : [aIndex] "=r" (Index)
7905 : [aMask] "r" (Mask)
7906 : "cc");
7907 @end example
7908
7909 Here are some more examples of output operands.
7910
7911 @example
7912 uint32_t c = 1;
7913 uint32_t d;
7914 uint32_t *e = &c;
7915
7916 asm ("mov %[e], %[d]"
7917 : [d] "=rm" (d)
7918 : [e] "rm" (*e));
7919 @end example
7920
7921 Here, @code{d} may either be in a register or in memory. Since the compiler
7922 might already have the current value of the @code{uint32_t} location
7923 pointed to by @code{e}
7924 in a register, you can enable it to choose the best location
7925 for @code{d} by specifying both constraints.
7926
7927 @anchor{FlagOutputOperands}
7928 @subsection Flag Output Operands
7929 @cindex @code{asm} flag output operands
7930
7931 Some targets have a special register that holds the ``flags'' for the
7932 result of an operation or comparison. Normally, the contents of that
7933 register are either unmodifed by the asm, or the asm is considered to
7934 clobber the contents.
7935
7936 On some targets, a special form of output operand exists by which
7937 conditions in the flags register may be outputs of the asm. The set of
7938 conditions supported are target specific, but the general rule is that
7939 the output variable must be a scalar integer, and the value will be boolean.
7940 When supported, the target will define the preprocessor symbol
7941 @code{__GCC_ASM_FLAG_OUTPUTS__}.
7942
7943 Because of the special nature of the flag output operands, the constraint
7944 may not include alternatives.
7945
7946 Most often, the target has only one flags register, and thus is an implied
7947 operand of many instructions. In this case, the operand should not be
7948 referenced within the assembler template via @code{%0} etc, as there's
7949 no corresponding text in the assembly language.
7950
7951 @table @asis
7952 @item x86 family
7953 The flag output constraints for the x86 family are of the form
7954 @samp{=@@cc@var{cond}} where @var{cond} is one of the standard
7955 conditions defined in the ISA manual for @code{j@var{cc}} or
7956 @code{set@var{cc}}.
7957
7958 @table @code
7959 @item a
7960 ``above'' or unsigned greater than
7961 @item ae
7962 ``above or equal'' or unsigned greater than or equal
7963 @item b
7964 ``below'' or unsigned less than
7965 @item be
7966 ``below or equal'' or unsigned less than or equal
7967 @item c
7968 carry flag set
7969 @item e
7970 @itemx z
7971 ``equal'' or zero flag set
7972 @item g
7973 signed greater than
7974 @item ge
7975 signed greater than or equal
7976 @item l
7977 signed less than
7978 @item le
7979 signed less than or equal
7980 @item o
7981 overflow flag set
7982 @item p
7983 parity flag set
7984 @item s
7985 sign flag set
7986 @item na
7987 @itemx nae
7988 @itemx nb
7989 @itemx nbe
7990 @itemx nc
7991 @itemx ne
7992 @itemx ng
7993 @itemx nge
7994 @itemx nl
7995 @itemx nle
7996 @itemx no
7997 @itemx np
7998 @itemx ns
7999 @itemx nz
8000 ``not'' @var{flag}, or inverted versions of those above
8001 @end table
8002
8003 @end table
8004
8005 @anchor{InputOperands}
8006 @subsubsection Input Operands
8007 @cindex @code{asm} input operands
8008 @cindex @code{asm} expressions
8009
8010 Input operands make values from C variables and expressions available to the
8011 assembly code.
8012
8013 Operands are separated by commas. Each operand has this format:
8014
8015 @example
8016 @r{[} [@var{asmSymbolicName}] @r{]} @var{constraint} (@var{cexpression})
8017 @end example
8018
8019 @table @var
8020 @item asmSymbolicName
8021 Specifies a symbolic name for the operand.
8022 Reference the name in the assembler template
8023 by enclosing it in square brackets
8024 (i.e. @samp{%[Value]}). The scope of the name is the @code{asm} statement
8025 that contains the definition. Any valid C variable name is acceptable,
8026 including names already defined in the surrounding code. No two operands
8027 within the same @code{asm} statement can use the same symbolic name.
8028
8029 When not using an @var{asmSymbolicName}, use the (zero-based) position
8030 of the operand
8031 in the list of operands in the assembler template. For example if there are
8032 two output operands and three inputs,
8033 use @samp{%2} in the template to refer to the first input operand,
8034 @samp{%3} for the second, and @samp{%4} for the third.
8035
8036 @item constraint
8037 A string constant specifying constraints on the placement of the operand;
8038 @xref{Constraints}, for details.
8039
8040 Input constraint strings may not begin with either @samp{=} or @samp{+}.
8041 When you list more than one possible location (for example, @samp{"irm"}),
8042 the compiler chooses the most efficient one based on the current context.
8043 If you must use a specific register, but your Machine Constraints do not
8044 provide sufficient control to select the specific register you want,
8045 local register variables may provide a solution (@pxref{Local Register
8046 Variables}).
8047
8048 Input constraints can also be digits (for example, @code{"0"}). This indicates
8049 that the specified input must be in the same place as the output constraint
8050 at the (zero-based) index in the output constraint list.
8051 When using @var{asmSymbolicName} syntax for the output operands,
8052 you may use these names (enclosed in brackets @samp{[]}) instead of digits.
8053
8054 @item cexpression
8055 This is the C variable or expression being passed to the @code{asm} statement
8056 as input. The enclosing parentheses are a required part of the syntax.
8057
8058 @end table
8059
8060 When the compiler selects the registers to use to represent the input
8061 operands, it does not use any of the clobbered registers (@pxref{Clobbers}).
8062
8063 If there are no output operands but there are input operands, place two
8064 consecutive colons where the output operands would go:
8065
8066 @example
8067 __asm__ ("some instructions"
8068 : /* No outputs. */
8069 : "r" (Offset / 8));
8070 @end example
8071
8072 @strong{Warning:} Do @emph{not} modify the contents of input-only operands
8073 (except for inputs tied to outputs). The compiler assumes that on exit from
8074 the @code{asm} statement these operands contain the same values as they
8075 had before executing the statement.
8076 It is @emph{not} possible to use clobbers
8077 to inform the compiler that the values in these inputs are changing. One
8078 common work-around is to tie the changing input variable to an output variable
8079 that never gets used. Note, however, that if the code that follows the
8080 @code{asm} statement makes no use of any of the output operands, the GCC
8081 optimizers may discard the @code{asm} statement as unneeded
8082 (see @ref{Volatile}).
8083
8084 @code{asm} supports operand modifiers on operands (for example @samp{%k2}
8085 instead of simply @samp{%2}). Typically these qualifiers are hardware
8086 dependent. The list of supported modifiers for x86 is found at
8087 @ref{x86Operandmodifiers,x86 Operand modifiers}.
8088
8089 In this example using the fictitious @code{combine} instruction, the
8090 constraint @code{"0"} for input operand 1 says that it must occupy the same
8091 location as output operand 0. Only input operands may use numbers in
8092 constraints, and they must each refer to an output operand. Only a number (or
8093 the symbolic assembler name) in the constraint can guarantee that one operand
8094 is in the same place as another. The mere fact that @code{foo} is the value of
8095 both operands is not enough to guarantee that they are in the same place in
8096 the generated assembler code.
8097
8098 @example
8099 asm ("combine %2, %0"
8100 : "=r" (foo)
8101 : "0" (foo), "g" (bar));
8102 @end example
8103
8104 Here is an example using symbolic names.
8105
8106 @example
8107 asm ("cmoveq %1, %2, %[result]"
8108 : [result] "=r"(result)
8109 : "r" (test), "r" (new), "[result]" (old));
8110 @end example
8111
8112 @anchor{Clobbers}
8113 @subsubsection Clobbers
8114 @cindex @code{asm} clobbers
8115
8116 While the compiler is aware of changes to entries listed in the output
8117 operands, the inline @code{asm} code may modify more than just the outputs. For
8118 example, calculations may require additional registers, or the processor may
8119 overwrite a register as a side effect of a particular assembler instruction.
8120 In order to inform the compiler of these changes, list them in the clobber
8121 list. Clobber list items are either register names or the special clobbers
8122 (listed below). Each clobber list item is a string constant
8123 enclosed in double quotes and separated by commas.
8124
8125 Clobber descriptions may not in any way overlap with an input or output
8126 operand. For example, you may not have an operand describing a register class
8127 with one member when listing that register in the clobber list. Variables
8128 declared to live in specific registers (@pxref{Explicit Register
8129 Variables}) and used
8130 as @code{asm} input or output operands must have no part mentioned in the
8131 clobber description. In particular, there is no way to specify that input
8132 operands get modified without also specifying them as output operands.
8133
8134 When the compiler selects which registers to use to represent input and output
8135 operands, it does not use any of the clobbered registers. As a result,
8136 clobbered registers are available for any use in the assembler code.
8137
8138 Here is a realistic example for the VAX showing the use of clobbered
8139 registers:
8140
8141 @example
8142 asm volatile ("movc3 %0, %1, %2"
8143 : /* No outputs. */
8144 : "g" (from), "g" (to), "g" (count)
8145 : "r0", "r1", "r2", "r3", "r4", "r5");
8146 @end example
8147
8148 Also, there are two special clobber arguments:
8149
8150 @table @code
8151 @item "cc"
8152 The @code{"cc"} clobber indicates that the assembler code modifies the flags
8153 register. On some machines, GCC represents the condition codes as a specific
8154 hardware register; @code{"cc"} serves to name this register.
8155 On other machines, condition code handling is different,
8156 and specifying @code{"cc"} has no effect. But
8157 it is valid no matter what the target.
8158
8159 @item "memory"
8160 The @code{"memory"} clobber tells the compiler that the assembly code
8161 performs memory
8162 reads or writes to items other than those listed in the input and output
8163 operands (for example, accessing the memory pointed to by one of the input
8164 parameters). To ensure memory contains correct values, GCC may need to flush
8165 specific register values to memory before executing the @code{asm}. Further,
8166 the compiler does not assume that any values read from memory before an
8167 @code{asm} remain unchanged after that @code{asm}; it reloads them as
8168 needed.
8169 Using the @code{"memory"} clobber effectively forms a read/write
8170 memory barrier for the compiler.
8171
8172 Note that this clobber does not prevent the @emph{processor} from doing
8173 speculative reads past the @code{asm} statement. To prevent that, you need
8174 processor-specific fence instructions.
8175
8176 Flushing registers to memory has performance implications and may be an issue
8177 for time-sensitive code. You can use a trick to avoid this if the size of
8178 the memory being accessed is known at compile time. For example, if accessing
8179 ten bytes of a string, use a memory input like:
8180
8181 @code{@{"m"( (@{ struct @{ char x[10]; @} *p = (void *)ptr ; *p; @}) )@}}.
8182
8183 @end table
8184
8185 @anchor{GotoLabels}
8186 @subsubsection Goto Labels
8187 @cindex @code{asm} goto labels
8188
8189 @code{asm goto} allows assembly code to jump to one or more C labels. The
8190 @var{GotoLabels} section in an @code{asm goto} statement contains
8191 a comma-separated
8192 list of all C labels to which the assembler code may jump. GCC assumes that
8193 @code{asm} execution falls through to the next statement (if this is not the
8194 case, consider using the @code{__builtin_unreachable} intrinsic after the
8195 @code{asm} statement). Optimization of @code{asm goto} may be improved by
8196 using the @code{hot} and @code{cold} label attributes (@pxref{Label
8197 Attributes}).
8198
8199 An @code{asm goto} statement cannot have outputs.
8200 This is due to an internal restriction of
8201 the compiler: control transfer instructions cannot have outputs.
8202 If the assembler code does modify anything, use the @code{"memory"} clobber
8203 to force the
8204 optimizers to flush all register values to memory and reload them if
8205 necessary after the @code{asm} statement.
8206
8207 Also note that an @code{asm goto} statement is always implicitly
8208 considered volatile.
8209
8210 To reference a label in the assembler template,
8211 prefix it with @samp{%l} (lowercase @samp{L}) followed
8212 by its (zero-based) position in @var{GotoLabels} plus the number of input
8213 operands. For example, if the @code{asm} has three inputs and references two
8214 labels, refer to the first label as @samp{%l3} and the second as @samp{%l4}).
8215
8216 Alternately, you can reference labels using the actual C label name enclosed
8217 in brackets. For example, to reference a label named @code{carry}, you can
8218 use @samp{%l[carry]}. The label must still be listed in the @var{GotoLabels}
8219 section when using this approach.
8220
8221 Here is an example of @code{asm goto} for i386:
8222
8223 @example
8224 asm goto (
8225 "btl %1, %0\n\t"
8226 "jc %l2"
8227 : /* No outputs. */
8228 : "r" (p1), "r" (p2)
8229 : "cc"
8230 : carry);
8231
8232 return 0;
8233
8234 carry:
8235 return 1;
8236 @end example
8237
8238 The following example shows an @code{asm goto} that uses a memory clobber.
8239
8240 @example
8241 int frob(int x)
8242 @{
8243 int y;
8244 asm goto ("frob %%r5, %1; jc %l[error]; mov (%2), %%r5"
8245 : /* No outputs. */
8246 : "r"(x), "r"(&y)
8247 : "r5", "memory"
8248 : error);
8249 return y;
8250 error:
8251 return -1;
8252 @}
8253 @end example
8254
8255 @anchor{x86Operandmodifiers}
8256 @subsubsection x86 Operand Modifiers
8257
8258 References to input, output, and goto operands in the assembler template
8259 of extended @code{asm} statements can use
8260 modifiers to affect the way the operands are formatted in
8261 the code output to the assembler. For example, the
8262 following code uses the @samp{h} and @samp{b} modifiers for x86:
8263
8264 @example
8265 uint16_t num;
8266 asm volatile ("xchg %h0, %b0" : "+a" (num) );
8267 @end example
8268
8269 @noindent
8270 These modifiers generate this assembler code:
8271
8272 @example
8273 xchg %ah, %al
8274 @end example
8275
8276 The rest of this discussion uses the following code for illustrative purposes.
8277
8278 @example
8279 int main()
8280 @{
8281 int iInt = 1;
8282
8283 top:
8284
8285 asm volatile goto ("some assembler instructions here"
8286 : /* No outputs. */
8287 : "q" (iInt), "X" (sizeof(unsigned char) + 1)
8288 : /* No clobbers. */
8289 : top);
8290 @}
8291 @end example
8292
8293 With no modifiers, this is what the output from the operands would be for the
8294 @samp{att} and @samp{intel} dialects of assembler:
8295
8296 @multitable {Operand} {masm=att} {OFFSET FLAT:.L2}
8297 @headitem Operand @tab masm=att @tab masm=intel
8298 @item @code{%0}
8299 @tab @code{%eax}
8300 @tab @code{eax}
8301 @item @code{%1}
8302 @tab @code{$2}
8303 @tab @code{2}
8304 @item @code{%2}
8305 @tab @code{$.L2}
8306 @tab @code{OFFSET FLAT:.L2}
8307 @end multitable
8308
8309 The table below shows the list of supported modifiers and their effects.
8310
8311 @multitable {Modifier} {Print the opcode suffix for the size of th} {Operand} {masm=att} {masm=intel}
8312 @headitem Modifier @tab Description @tab Operand @tab @option{masm=att} @tab @option{masm=intel}
8313 @item @code{z}
8314 @tab Print the opcode suffix for the size of the current integer operand (one of @code{b}/@code{w}/@code{l}/@code{q}).
8315 @tab @code{%z0}
8316 @tab @code{l}
8317 @tab
8318 @item @code{b}
8319 @tab Print the QImode name of the register.
8320 @tab @code{%b0}
8321 @tab @code{%al}
8322 @tab @code{al}
8323 @item @code{h}
8324 @tab Print the QImode name for a ``high'' register.
8325 @tab @code{%h0}
8326 @tab @code{%ah}
8327 @tab @code{ah}
8328 @item @code{w}
8329 @tab Print the HImode name of the register.
8330 @tab @code{%w0}
8331 @tab @code{%ax}
8332 @tab @code{ax}
8333 @item @code{k}
8334 @tab Print the SImode name of the register.
8335 @tab @code{%k0}
8336 @tab @code{%eax}
8337 @tab @code{eax}
8338 @item @code{q}
8339 @tab Print the DImode name of the register.
8340 @tab @code{%q0}
8341 @tab @code{%rax}
8342 @tab @code{rax}
8343 @item @code{l}
8344 @tab Print the label name with no punctuation.
8345 @tab @code{%l2}
8346 @tab @code{.L2}
8347 @tab @code{.L2}
8348 @item @code{c}
8349 @tab Require a constant operand and print the constant expression with no punctuation.
8350 @tab @code{%c1}
8351 @tab @code{2}
8352 @tab @code{2}
8353 @end multitable
8354
8355 @anchor{x86floatingpointasmoperands}
8356 @subsubsection x86 Floating-Point @code{asm} Operands
8357
8358 On x86 targets, there are several rules on the usage of stack-like registers
8359 in the operands of an @code{asm}. These rules apply only to the operands
8360 that are stack-like registers:
8361
8362 @enumerate
8363 @item
8364 Given a set of input registers that die in an @code{asm}, it is
8365 necessary to know which are implicitly popped by the @code{asm}, and
8366 which must be explicitly popped by GCC@.
8367
8368 An input register that is implicitly popped by the @code{asm} must be
8369 explicitly clobbered, unless it is constrained to match an
8370 output operand.
8371
8372 @item
8373 For any input register that is implicitly popped by an @code{asm}, it is
8374 necessary to know how to adjust the stack to compensate for the pop.
8375 If any non-popped input is closer to the top of the reg-stack than
8376 the implicitly popped register, it would not be possible to know what the
8377 stack looked like---it's not clear how the rest of the stack ``slides
8378 up''.
8379
8380 All implicitly popped input registers must be closer to the top of
8381 the reg-stack than any input that is not implicitly popped.
8382
8383 It is possible that if an input dies in an @code{asm}, the compiler might
8384 use the input register for an output reload. Consider this example:
8385
8386 @smallexample
8387 asm ("foo" : "=t" (a) : "f" (b));
8388 @end smallexample
8389
8390 @noindent
8391 This code says that input @code{b} is not popped by the @code{asm}, and that
8392 the @code{asm} pushes a result onto the reg-stack, i.e., the stack is one
8393 deeper after the @code{asm} than it was before. But, it is possible that
8394 reload may think that it can use the same register for both the input and
8395 the output.
8396
8397 To prevent this from happening,
8398 if any input operand uses the @samp{f} constraint, all output register
8399 constraints must use the @samp{&} early-clobber modifier.
8400
8401 The example above is correctly written as:
8402
8403 @smallexample
8404 asm ("foo" : "=&t" (a) : "f" (b));
8405 @end smallexample
8406
8407 @item
8408 Some operands need to be in particular places on the stack. All
8409 output operands fall in this category---GCC has no other way to
8410 know which registers the outputs appear in unless you indicate
8411 this in the constraints.
8412
8413 Output operands must specifically indicate which register an output
8414 appears in after an @code{asm}. @samp{=f} is not allowed: the operand
8415 constraints must select a class with a single register.
8416
8417 @item
8418 Output operands may not be ``inserted'' between existing stack registers.
8419 Since no 387 opcode uses a read/write operand, all output operands
8420 are dead before the @code{asm}, and are pushed by the @code{asm}.
8421 It makes no sense to push anywhere but the top of the reg-stack.
8422
8423 Output operands must start at the top of the reg-stack: output
8424 operands may not ``skip'' a register.
8425
8426 @item
8427 Some @code{asm} statements may need extra stack space for internal
8428 calculations. This can be guaranteed by clobbering stack registers
8429 unrelated to the inputs and outputs.
8430
8431 @end enumerate
8432
8433 This @code{asm}
8434 takes one input, which is internally popped, and produces two outputs.
8435
8436 @smallexample
8437 asm ("fsincos" : "=t" (cos), "=u" (sin) : "0" (inp));
8438 @end smallexample
8439
8440 @noindent
8441 This @code{asm} takes two inputs, which are popped by the @code{fyl2xp1} opcode,
8442 and replaces them with one output. The @code{st(1)} clobber is necessary
8443 for the compiler to know that @code{fyl2xp1} pops both inputs.
8444
8445 @smallexample
8446 asm ("fyl2xp1" : "=t" (result) : "0" (x), "u" (y) : "st(1)");
8447 @end smallexample
8448
8449 @lowersections
8450 @include md.texi
8451 @raisesections
8452
8453 @node Asm Labels
8454 @subsection Controlling Names Used in Assembler Code
8455 @cindex assembler names for identifiers
8456 @cindex names used in assembler code
8457 @cindex identifiers, names in assembler code
8458
8459 You can specify the name to be used in the assembler code for a C
8460 function or variable by writing the @code{asm} (or @code{__asm__})
8461 keyword after the declarator.
8462 It is up to you to make sure that the assembler names you choose do not
8463 conflict with any other assembler symbols, or reference registers.
8464
8465 @subsubheading Assembler names for data:
8466
8467 This sample shows how to specify the assembler name for data:
8468
8469 @smallexample
8470 int foo asm ("myfoo") = 2;
8471 @end smallexample
8472
8473 @noindent
8474 This specifies that the name to be used for the variable @code{foo} in
8475 the assembler code should be @samp{myfoo} rather than the usual
8476 @samp{_foo}.
8477
8478 On systems where an underscore is normally prepended to the name of a C
8479 variable, this feature allows you to define names for the
8480 linker that do not start with an underscore.
8481
8482 GCC does not support using this feature with a non-static local variable
8483 since such variables do not have assembler names. If you are
8484 trying to put the variable in a particular register, see
8485 @ref{Explicit Register Variables}.
8486
8487 @subsubheading Assembler names for functions:
8488
8489 To specify the assembler name for functions, write a declaration for the
8490 function before its definition and put @code{asm} there, like this:
8491
8492 @smallexample
8493 int func (int x, int y) asm ("MYFUNC");
8494
8495 int func (int x, int y)
8496 @{
8497 /* @r{@dots{}} */
8498 @end smallexample
8499
8500 @noindent
8501 This specifies that the name to be used for the function @code{func} in
8502 the assembler code should be @code{MYFUNC}.
8503
8504 @node Explicit Register Variables
8505 @subsection Variables in Specified Registers
8506 @anchor{Explicit Reg Vars}
8507 @cindex explicit register variables
8508 @cindex variables in specified registers
8509 @cindex specified registers
8510
8511 GNU C allows you to associate specific hardware registers with C
8512 variables. In almost all cases, allowing the compiler to assign
8513 registers produces the best code. However under certain unusual
8514 circumstances, more precise control over the variable storage is
8515 required.
8516
8517 Both global and local variables can be associated with a register. The
8518 consequences of performing this association are very different between
8519 the two, as explained in the sections below.
8520
8521 @menu
8522 * Global Register Variables:: Variables declared at global scope.
8523 * Local Register Variables:: Variables declared within a function.
8524 @end menu
8525
8526 @node Global Register Variables
8527 @subsubsection Defining Global Register Variables
8528 @anchor{Global Reg Vars}
8529 @cindex global register variables
8530 @cindex registers, global variables in
8531 @cindex registers, global allocation
8532
8533 You can define a global register variable and associate it with a specified
8534 register like this:
8535
8536 @smallexample
8537 register int *foo asm ("r12");
8538 @end smallexample
8539
8540 @noindent
8541 Here @code{r12} is the name of the register that should be used. Note that
8542 this is the same syntax used for defining local register variables, but for
8543 a global variable the declaration appears outside a function. The
8544 @code{register} keyword is required, and cannot be combined with
8545 @code{static}. The register name must be a valid register name for the
8546 target platform.
8547
8548 Registers are a scarce resource on most systems and allowing the
8549 compiler to manage their usage usually results in the best code. However,
8550 under special circumstances it can make sense to reserve some globally.
8551 For example this may be useful in programs such as programming language
8552 interpreters that have a couple of global variables that are accessed
8553 very often.
8554
8555 After defining a global register variable, for the current compilation
8556 unit:
8557
8558 @itemize @bullet
8559 @item The register is reserved entirely for this use, and will not be
8560 allocated for any other purpose.
8561 @item The register is not saved and restored by any functions.
8562 @item Stores into this register are never deleted even if they appear to be
8563 dead, but references may be deleted, moved or simplified.
8564 @end itemize
8565
8566 Note that these points @emph{only} apply to code that is compiled with the
8567 definition. The behavior of code that is merely linked in (for example
8568 code from libraries) is not affected.
8569
8570 If you want to recompile source files that do not actually use your global
8571 register variable so they do not use the specified register for any other
8572 purpose, you need not actually add the global register declaration to
8573 their source code. It suffices to specify the compiler option
8574 @option{-ffixed-@var{reg}} (@pxref{Code Gen Options}) to reserve the
8575 register.
8576
8577 @subsubheading Declaring the variable
8578
8579 Global register variables can not have initial values, because an
8580 executable file has no means to supply initial contents for a register.
8581
8582 When selecting a register, choose one that is normally saved and
8583 restored by function calls on your machine. This ensures that code
8584 which is unaware of this reservation (such as library routines) will
8585 restore it before returning.
8586
8587 On machines with register windows, be sure to choose a global
8588 register that is not affected magically by the function call mechanism.
8589
8590 @subsubheading Using the variable
8591
8592 @cindex @code{qsort}, and global register variables
8593 When calling routines that are not aware of the reservation, be
8594 cautious if those routines call back into code which uses them. As an
8595 example, if you call the system library version of @code{qsort}, it may
8596 clobber your registers during execution, but (if you have selected
8597 appropriate registers) it will restore them before returning. However
8598 it will @emph{not} restore them before calling @code{qsort}'s comparison
8599 function. As a result, global values will not reliably be available to
8600 the comparison function unless the @code{qsort} function itself is rebuilt.
8601
8602 Similarly, it is not safe to access the global register variables from signal
8603 handlers or from more than one thread of control. Unless you recompile
8604 them specially for the task at hand, the system library routines may
8605 temporarily use the register for other things.
8606
8607 @cindex register variable after @code{longjmp}
8608 @cindex global register after @code{longjmp}
8609 @cindex value after @code{longjmp}
8610 @findex longjmp
8611 @findex setjmp
8612 On most machines, @code{longjmp} restores to each global register
8613 variable the value it had at the time of the @code{setjmp}. On some
8614 machines, however, @code{longjmp} does not change the value of global
8615 register variables. To be portable, the function that called @code{setjmp}
8616 should make other arrangements to save the values of the global register
8617 variables, and to restore them in a @code{longjmp}. This way, the same
8618 thing happens regardless of what @code{longjmp} does.
8619
8620 Eventually there may be a way of asking the compiler to choose a register
8621 automatically, but first we need to figure out how it should choose and
8622 how to enable you to guide the choice. No solution is evident.
8623
8624 @node Local Register Variables
8625 @subsubsection Specifying Registers for Local Variables
8626 @anchor{Local Reg Vars}
8627 @cindex local variables, specifying registers
8628 @cindex specifying registers for local variables
8629 @cindex registers for local variables
8630
8631 You can define a local register variable and associate it with a specified
8632 register like this:
8633
8634 @smallexample
8635 register int *foo asm ("r12");
8636 @end smallexample
8637
8638 @noindent
8639 Here @code{r12} is the name of the register that should be used. Note
8640 that this is the same syntax used for defining global register variables,
8641 but for a local variable the declaration appears within a function. The
8642 @code{register} keyword is required, and cannot be combined with
8643 @code{static}. The register name must be a valid register name for the
8644 target platform.
8645
8646 As with global register variables, it is recommended that you choose
8647 a register that is normally saved and restored by function calls on your
8648 machine, so that calls to library routines will not clobber it.
8649
8650 The only supported use for this feature is to specify registers
8651 for input and output operands when calling Extended @code{asm}
8652 (@pxref{Extended Asm}). This may be necessary if the constraints for a
8653 particular machine don't provide sufficient control to select the desired
8654 register. To force an operand into a register, create a local variable
8655 and specify the register name after the variable's declaration. Then use
8656 the local variable for the @code{asm} operand and specify any constraint
8657 letter that matches the register:
8658
8659 @smallexample
8660 register int *p1 asm ("r0") = @dots{};
8661 register int *p2 asm ("r1") = @dots{};
8662 register int *result asm ("r0");
8663 asm ("sysint" : "=r" (result) : "0" (p1), "r" (p2));
8664 @end smallexample
8665
8666 @emph{Warning:} In the above example, be aware that a register (for example
8667 @code{r0}) can be call-clobbered by subsequent code, including function
8668 calls and library calls for arithmetic operators on other variables (for
8669 example the initialization of @code{p2}). In this case, use temporary
8670 variables for expressions between the register assignments:
8671
8672 @smallexample
8673 int t1 = @dots{};
8674 register int *p1 asm ("r0") = @dots{};
8675 register int *p2 asm ("r1") = t1;
8676 register int *result asm ("r0");
8677 asm ("sysint" : "=r" (result) : "0" (p1), "r" (p2));
8678 @end smallexample
8679
8680 Defining a register variable does not reserve the register. Other than
8681 when invoking the Extended @code{asm}, the contents of the specified
8682 register are not guaranteed. For this reason, the following uses
8683 are explicitly @emph{not} supported. If they appear to work, it is only
8684 happenstance, and may stop working as intended due to (seemingly)
8685 unrelated changes in surrounding code, or even minor changes in the
8686 optimization of a future version of gcc:
8687
8688 @itemize @bullet
8689 @item Passing parameters to or from Basic @code{asm}
8690 @item Passing parameters to or from Extended @code{asm} without using input
8691 or output operands.
8692 @item Passing parameters to or from routines written in assembler (or
8693 other languages) using non-standard calling conventions.
8694 @end itemize
8695
8696 Some developers use Local Register Variables in an attempt to improve
8697 gcc's allocation of registers, especially in large functions. In this
8698 case the register name is essentially a hint to the register allocator.
8699 While in some instances this can generate better code, improvements are
8700 subject to the whims of the allocator/optimizers. Since there are no
8701 guarantees that your improvements won't be lost, this usage of Local
8702 Register Variables is discouraged.
8703
8704 On the MIPS platform, there is related use for local register variables
8705 with slightly different characteristics (@pxref{MIPS Coprocessors,,
8706 Defining coprocessor specifics for MIPS targets, gccint,
8707 GNU Compiler Collection (GCC) Internals}).
8708
8709 @node Size of an asm
8710 @subsection Size of an @code{asm}
8711
8712 Some targets require that GCC track the size of each instruction used
8713 in order to generate correct code. Because the final length of the
8714 code produced by an @code{asm} statement is only known by the
8715 assembler, GCC must make an estimate as to how big it will be. It
8716 does this by counting the number of instructions in the pattern of the
8717 @code{asm} and multiplying that by the length of the longest
8718 instruction supported by that processor. (When working out the number
8719 of instructions, it assumes that any occurrence of a newline or of
8720 whatever statement separator character is supported by the assembler --
8721 typically @samp{;} --- indicates the end of an instruction.)
8722
8723 Normally, GCC's estimate is adequate to ensure that correct
8724 code is generated, but it is possible to confuse the compiler if you use
8725 pseudo instructions or assembler macros that expand into multiple real
8726 instructions, or if you use assembler directives that expand to more
8727 space in the object file than is needed for a single instruction.
8728 If this happens then the assembler may produce a diagnostic saying that
8729 a label is unreachable.
8730
8731 @node Alternate Keywords
8732 @section Alternate Keywords
8733 @cindex alternate keywords
8734 @cindex keywords, alternate
8735
8736 @option{-ansi} and the various @option{-std} options disable certain
8737 keywords. This causes trouble when you want to use GNU C extensions, or
8738 a general-purpose header file that should be usable by all programs,
8739 including ISO C programs. The keywords @code{asm}, @code{typeof} and
8740 @code{inline} are not available in programs compiled with
8741 @option{-ansi} or @option{-std} (although @code{inline} can be used in a
8742 program compiled with @option{-std=c99} or @option{-std=c11}). The
8743 ISO C99 keyword
8744 @code{restrict} is only available when @option{-std=gnu99} (which will
8745 eventually be the default) or @option{-std=c99} (or the equivalent
8746 @option{-std=iso9899:1999}), or an option for a later standard
8747 version, is used.
8748
8749 The way to solve these problems is to put @samp{__} at the beginning and
8750 end of each problematical keyword. For example, use @code{__asm__}
8751 instead of @code{asm}, and @code{__inline__} instead of @code{inline}.
8752
8753 Other C compilers won't accept these alternative keywords; if you want to
8754 compile with another compiler, you can define the alternate keywords as
8755 macros to replace them with the customary keywords. It looks like this:
8756
8757 @smallexample
8758 #ifndef __GNUC__
8759 #define __asm__ asm
8760 #endif
8761 @end smallexample
8762
8763 @findex __extension__
8764 @opindex pedantic
8765 @option{-pedantic} and other options cause warnings for many GNU C extensions.
8766 You can
8767 prevent such warnings within one expression by writing
8768 @code{__extension__} before the expression. @code{__extension__} has no
8769 effect aside from this.
8770
8771 @node Incomplete Enums
8772 @section Incomplete @code{enum} Types
8773
8774 You can define an @code{enum} tag without specifying its possible values.
8775 This results in an incomplete type, much like what you get if you write
8776 @code{struct foo} without describing the elements. A later declaration
8777 that does specify the possible values completes the type.
8778
8779 You can't allocate variables or storage using the type while it is
8780 incomplete. However, you can work with pointers to that type.
8781
8782 This extension may not be very useful, but it makes the handling of
8783 @code{enum} more consistent with the way @code{struct} and @code{union}
8784 are handled.
8785
8786 This extension is not supported by GNU C++.
8787
8788 @node Function Names
8789 @section Function Names as Strings
8790 @cindex @code{__func__} identifier
8791 @cindex @code{__FUNCTION__} identifier
8792 @cindex @code{__PRETTY_FUNCTION__} identifier
8793
8794 GCC provides three magic variables that hold the name of the current
8795 function, as a string. The first of these is @code{__func__}, which
8796 is part of the C99 standard:
8797
8798 The identifier @code{__func__} is implicitly declared by the translator
8799 as if, immediately following the opening brace of each function
8800 definition, the declaration
8801
8802 @smallexample
8803 static const char __func__[] = "function-name";
8804 @end smallexample
8805
8806 @noindent
8807 appeared, where function-name is the name of the lexically-enclosing
8808 function. This name is the unadorned name of the function.
8809
8810 @code{__FUNCTION__} is another name for @code{__func__}, provided for
8811 backward compatibility with old versions of GCC.
8812
8813 In C, @code{__PRETTY_FUNCTION__} is yet another name for
8814 @code{__func__}. However, in C++, @code{__PRETTY_FUNCTION__} contains
8815 the type signature of the function as well as its bare name. For
8816 example, this program:
8817
8818 @smallexample
8819 extern "C" @{
8820 extern int printf (char *, ...);
8821 @}
8822
8823 class a @{
8824 public:
8825 void sub (int i)
8826 @{
8827 printf ("__FUNCTION__ = %s\n", __FUNCTION__);
8828 printf ("__PRETTY_FUNCTION__ = %s\n", __PRETTY_FUNCTION__);
8829 @}
8830 @};
8831
8832 int
8833 main (void)
8834 @{
8835 a ax;
8836 ax.sub (0);
8837 return 0;
8838 @}
8839 @end smallexample
8840
8841 @noindent
8842 gives this output:
8843
8844 @smallexample
8845 __FUNCTION__ = sub
8846 __PRETTY_FUNCTION__ = void a::sub(int)
8847 @end smallexample
8848
8849 These identifiers are variables, not preprocessor macros, and may not
8850 be used to initialize @code{char} arrays or be concatenated with other string
8851 literals.
8852
8853 @node Return Address
8854 @section Getting the Return or Frame Address of a Function
8855
8856 These functions may be used to get information about the callers of a
8857 function.
8858
8859 @deftypefn {Built-in Function} {void *} __builtin_return_address (unsigned int @var{level})
8860 This function returns the return address of the current function, or of
8861 one of its callers. The @var{level} argument is number of frames to
8862 scan up the call stack. A value of @code{0} yields the return address
8863 of the current function, a value of @code{1} yields the return address
8864 of the caller of the current function, and so forth. When inlining
8865 the expected behavior is that the function returns the address of
8866 the function that is returned to. To work around this behavior use
8867 the @code{noinline} function attribute.
8868
8869 The @var{level} argument must be a constant integer.
8870
8871 On some machines it may be impossible to determine the return address of
8872 any function other than the current one; in such cases, or when the top
8873 of the stack has been reached, this function returns @code{0} or a
8874 random value. In addition, @code{__builtin_frame_address} may be used
8875 to determine if the top of the stack has been reached.
8876
8877 Additional post-processing of the returned value may be needed, see
8878 @code{__builtin_extract_return_addr}.
8879
8880 Calling this function with a nonzero argument can have unpredictable
8881 effects, including crashing the calling program. As a result, calls
8882 that are considered unsafe are diagnosed when the @option{-Wframe-address}
8883 option is in effect. Such calls should only be made in debugging
8884 situations.
8885 @end deftypefn
8886
8887 @deftypefn {Built-in Function} {void *} __builtin_extract_return_addr (void *@var{addr})
8888 The address as returned by @code{__builtin_return_address} may have to be fed
8889 through this function to get the actual encoded address. For example, on the
8890 31-bit S/390 platform the highest bit has to be masked out, or on SPARC
8891 platforms an offset has to be added for the true next instruction to be
8892 executed.
8893
8894 If no fixup is needed, this function simply passes through @var{addr}.
8895 @end deftypefn
8896
8897 @deftypefn {Built-in Function} {void *} __builtin_frob_return_address (void *@var{addr})
8898 This function does the reverse of @code{__builtin_extract_return_addr}.
8899 @end deftypefn
8900
8901 @deftypefn {Built-in Function} {void *} __builtin_frame_address (unsigned int @var{level})
8902 This function is similar to @code{__builtin_return_address}, but it
8903 returns the address of the function frame rather than the return address
8904 of the function. Calling @code{__builtin_frame_address} with a value of
8905 @code{0} yields the frame address of the current function, a value of
8906 @code{1} yields the frame address of the caller of the current function,
8907 and so forth.
8908
8909 The frame is the area on the stack that holds local variables and saved
8910 registers. The frame address is normally the address of the first word
8911 pushed on to the stack by the function. However, the exact definition
8912 depends upon the processor and the calling convention. If the processor
8913 has a dedicated frame pointer register, and the function has a frame,
8914 then @code{__builtin_frame_address} returns the value of the frame
8915 pointer register.
8916
8917 On some machines it may be impossible to determine the frame address of
8918 any function other than the current one; in such cases, or when the top
8919 of the stack has been reached, this function returns @code{0} if
8920 the first frame pointer is properly initialized by the startup code.
8921
8922 Calling this function with a nonzero argument can have unpredictable
8923 effects, including crashing the calling program. As a result, calls
8924 that are considered unsafe are diagnosed when the @option{-Wframe-address}
8925 option is in effect. Such calls should only be made in debugging
8926 situations.
8927 @end deftypefn
8928
8929 @node Vector Extensions
8930 @section Using Vector Instructions through Built-in Functions
8931
8932 On some targets, the instruction set contains SIMD vector instructions which
8933 operate on multiple values contained in one large register at the same time.
8934 For example, on the x86 the MMX, 3DNow!@: and SSE extensions can be used
8935 this way.
8936
8937 The first step in using these extensions is to provide the necessary data
8938 types. This should be done using an appropriate @code{typedef}:
8939
8940 @smallexample
8941 typedef int v4si __attribute__ ((vector_size (16)));
8942 @end smallexample
8943
8944 @noindent
8945 The @code{int} type specifies the base type, while the attribute specifies
8946 the vector size for the variable, measured in bytes. For example, the
8947 declaration above causes the compiler to set the mode for the @code{v4si}
8948 type to be 16 bytes wide and divided into @code{int} sized units. For
8949 a 32-bit @code{int} this means a vector of 4 units of 4 bytes, and the
8950 corresponding mode of @code{foo} is @acronym{V4SI}.
8951
8952 The @code{vector_size} attribute is only applicable to integral and
8953 float scalars, although arrays, pointers, and function return values
8954 are allowed in conjunction with this construct. Only sizes that are
8955 a power of two are currently allowed.
8956
8957 All the basic integer types can be used as base types, both as signed
8958 and as unsigned: @code{char}, @code{short}, @code{int}, @code{long},
8959 @code{long long}. In addition, @code{float} and @code{double} can be
8960 used to build floating-point vector types.
8961
8962 Specifying a combination that is not valid for the current architecture
8963 causes GCC to synthesize the instructions using a narrower mode.
8964 For example, if you specify a variable of type @code{V4SI} and your
8965 architecture does not allow for this specific SIMD type, GCC
8966 produces code that uses 4 @code{SIs}.
8967
8968 The types defined in this manner can be used with a subset of normal C
8969 operations. Currently, GCC allows using the following operators
8970 on these types: @code{+, -, *, /, unary minus, ^, |, &, ~, %}@.
8971
8972 The operations behave like C++ @code{valarrays}. Addition is defined as
8973 the addition of the corresponding elements of the operands. For
8974 example, in the code below, each of the 4 elements in @var{a} is
8975 added to the corresponding 4 elements in @var{b} and the resulting
8976 vector is stored in @var{c}.
8977
8978 @smallexample
8979 typedef int v4si __attribute__ ((vector_size (16)));
8980
8981 v4si a, b, c;
8982
8983 c = a + b;
8984 @end smallexample
8985
8986 Subtraction, multiplication, division, and the logical operations
8987 operate in a similar manner. Likewise, the result of using the unary
8988 minus or complement operators on a vector type is a vector whose
8989 elements are the negative or complemented values of the corresponding
8990 elements in the operand.
8991
8992 It is possible to use shifting operators @code{<<}, @code{>>} on
8993 integer-type vectors. The operation is defined as following: @code{@{a0,
8994 a1, @dots{}, an@} >> @{b0, b1, @dots{}, bn@} == @{a0 >> b0, a1 >> b1,
8995 @dots{}, an >> bn@}}@. Vector operands must have the same number of
8996 elements.
8997
8998 For convenience, it is allowed to use a binary vector operation
8999 where one operand is a scalar. In that case the compiler transforms
9000 the scalar operand into a vector where each element is the scalar from
9001 the operation. The transformation happens only if the scalar could be
9002 safely converted to the vector-element type.
9003 Consider the following code.
9004
9005 @smallexample
9006 typedef int v4si __attribute__ ((vector_size (16)));
9007
9008 v4si a, b, c;
9009 long l;
9010
9011 a = b + 1; /* a = b + @{1,1,1,1@}; */
9012 a = 2 * b; /* a = @{2,2,2,2@} * b; */
9013
9014 a = l + a; /* Error, cannot convert long to int. */
9015 @end smallexample
9016
9017 Vectors can be subscripted as if the vector were an array with
9018 the same number of elements and base type. Out of bound accesses
9019 invoke undefined behavior at run time. Warnings for out of bound
9020 accesses for vector subscription can be enabled with
9021 @option{-Warray-bounds}.
9022
9023 Vector comparison is supported with standard comparison
9024 operators: @code{==, !=, <, <=, >, >=}. Comparison operands can be
9025 vector expressions of integer-type or real-type. Comparison between
9026 integer-type vectors and real-type vectors are not supported. The
9027 result of the comparison is a vector of the same width and number of
9028 elements as the comparison operands with a signed integral element
9029 type.
9030
9031 Vectors are compared element-wise producing 0 when comparison is false
9032 and -1 (constant of the appropriate type where all bits are set)
9033 otherwise. Consider the following example.
9034
9035 @smallexample
9036 typedef int v4si __attribute__ ((vector_size (16)));
9037
9038 v4si a = @{1,2,3,4@};
9039 v4si b = @{3,2,1,4@};
9040 v4si c;
9041
9042 c = a > b; /* The result would be @{0, 0,-1, 0@} */
9043 c = a == b; /* The result would be @{0,-1, 0,-1@} */
9044 @end smallexample
9045
9046 In C++, the ternary operator @code{?:} is available. @code{a?b:c}, where
9047 @code{b} and @code{c} are vectors of the same type and @code{a} is an
9048 integer vector with the same number of elements of the same size as @code{b}
9049 and @code{c}, computes all three arguments and creates a vector
9050 @code{@{a[0]?b[0]:c[0], a[1]?b[1]:c[1], @dots{}@}}. Note that unlike in
9051 OpenCL, @code{a} is thus interpreted as @code{a != 0} and not @code{a < 0}.
9052 As in the case of binary operations, this syntax is also accepted when
9053 one of @code{b} or @code{c} is a scalar that is then transformed into a
9054 vector. If both @code{b} and @code{c} are scalars and the type of
9055 @code{true?b:c} has the same size as the element type of @code{a}, then
9056 @code{b} and @code{c} are converted to a vector type whose elements have
9057 this type and with the same number of elements as @code{a}.
9058
9059 In C++, the logic operators @code{!, &&, ||} are available for vectors.
9060 @code{!v} is equivalent to @code{v == 0}, @code{a && b} is equivalent to
9061 @code{a!=0 & b!=0} and @code{a || b} is equivalent to @code{a!=0 | b!=0}.
9062 For mixed operations between a scalar @code{s} and a vector @code{v},
9063 @code{s && v} is equivalent to @code{s?v!=0:0} (the evaluation is
9064 short-circuit) and @code{v && s} is equivalent to @code{v!=0 & (s?-1:0)}.
9065
9066 Vector shuffling is available using functions
9067 @code{__builtin_shuffle (vec, mask)} and
9068 @code{__builtin_shuffle (vec0, vec1, mask)}.
9069 Both functions construct a permutation of elements from one or two
9070 vectors and return a vector of the same type as the input vector(s).
9071 The @var{mask} is an integral vector with the same width (@var{W})
9072 and element count (@var{N}) as the output vector.
9073
9074 The elements of the input vectors are numbered in memory ordering of
9075 @var{vec0} beginning at 0 and @var{vec1} beginning at @var{N}. The
9076 elements of @var{mask} are considered modulo @var{N} in the single-operand
9077 case and modulo @math{2*@var{N}} in the two-operand case.
9078
9079 Consider the following example,
9080
9081 @smallexample
9082 typedef int v4si __attribute__ ((vector_size (16)));
9083
9084 v4si a = @{1,2,3,4@};
9085 v4si b = @{5,6,7,8@};
9086 v4si mask1 = @{0,1,1,3@};
9087 v4si mask2 = @{0,4,2,5@};
9088 v4si res;
9089
9090 res = __builtin_shuffle (a, mask1); /* res is @{1,2,2,4@} */
9091 res = __builtin_shuffle (a, b, mask2); /* res is @{1,5,3,6@} */
9092 @end smallexample
9093
9094 Note that @code{__builtin_shuffle} is intentionally semantically
9095 compatible with the OpenCL @code{shuffle} and @code{shuffle2} functions.
9096
9097 You can declare variables and use them in function calls and returns, as
9098 well as in assignments and some casts. You can specify a vector type as
9099 a return type for a function. Vector types can also be used as function
9100 arguments. It is possible to cast from one vector type to another,
9101 provided they are of the same size (in fact, you can also cast vectors
9102 to and from other datatypes of the same size).
9103
9104 You cannot operate between vectors of different lengths or different
9105 signedness without a cast.
9106
9107 @node Offsetof
9108 @section Support for @code{offsetof}
9109 @findex __builtin_offsetof
9110
9111 GCC implements for both C and C++ a syntactic extension to implement
9112 the @code{offsetof} macro.
9113
9114 @smallexample
9115 primary:
9116 "__builtin_offsetof" "(" @code{typename} "," offsetof_member_designator ")"
9117
9118 offsetof_member_designator:
9119 @code{identifier}
9120 | offsetof_member_designator "." @code{identifier}
9121 | offsetof_member_designator "[" @code{expr} "]"
9122 @end smallexample
9123
9124 This extension is sufficient such that
9125
9126 @smallexample
9127 #define offsetof(@var{type}, @var{member}) __builtin_offsetof (@var{type}, @var{member})
9128 @end smallexample
9129
9130 @noindent
9131 is a suitable definition of the @code{offsetof} macro. In C++, @var{type}
9132 may be dependent. In either case, @var{member} may consist of a single
9133 identifier, or a sequence of member accesses and array references.
9134
9135 @node __sync Builtins
9136 @section Legacy @code{__sync} Built-in Functions for Atomic Memory Access
9137
9138 The following built-in functions
9139 are intended to be compatible with those described
9140 in the @cite{Intel Itanium Processor-specific Application Binary Interface},
9141 section 7.4. As such, they depart from normal GCC practice by not using
9142 the @samp{__builtin_} prefix and also by being overloaded so that they
9143 work on multiple types.
9144
9145 The definition given in the Intel documentation allows only for the use of
9146 the types @code{int}, @code{long}, @code{long long} or their unsigned
9147 counterparts. GCC allows any integral scalar or pointer type that is
9148 1, 2, 4 or 8 bytes in length.
9149
9150 These functions are implemented in terms of the @samp{__atomic}
9151 builtins (@pxref{__atomic Builtins}). They should not be used for new
9152 code which should use the @samp{__atomic} builtins instead.
9153
9154 Not all operations are supported by all target processors. If a particular
9155 operation cannot be implemented on the target processor, a warning is
9156 generated and a call to an external function is generated. The external
9157 function carries the same name as the built-in version,
9158 with an additional suffix
9159 @samp{_@var{n}} where @var{n} is the size of the data type.
9160
9161 @c ??? Should we have a mechanism to suppress this warning? This is almost
9162 @c useful for implementing the operation under the control of an external
9163 @c mutex.
9164
9165 In most cases, these built-in functions are considered a @dfn{full barrier}.
9166 That is,
9167 no memory operand is moved across the operation, either forward or
9168 backward. Further, instructions are issued as necessary to prevent the
9169 processor from speculating loads across the operation and from queuing stores
9170 after the operation.
9171
9172 All of the routines are described in the Intel documentation to take
9173 ``an optional list of variables protected by the memory barrier''. It's
9174 not clear what is meant by that; it could mean that @emph{only} the
9175 listed variables are protected, or it could mean a list of additional
9176 variables to be protected. The list is ignored by GCC which treats it as
9177 empty. GCC interprets an empty list as meaning that all globally
9178 accessible variables should be protected.
9179
9180 @table @code
9181 @item @var{type} __sync_fetch_and_add (@var{type} *ptr, @var{type} value, ...)
9182 @itemx @var{type} __sync_fetch_and_sub (@var{type} *ptr, @var{type} value, ...)
9183 @itemx @var{type} __sync_fetch_and_or (@var{type} *ptr, @var{type} value, ...)
9184 @itemx @var{type} __sync_fetch_and_and (@var{type} *ptr, @var{type} value, ...)
9185 @itemx @var{type} __sync_fetch_and_xor (@var{type} *ptr, @var{type} value, ...)
9186 @itemx @var{type} __sync_fetch_and_nand (@var{type} *ptr, @var{type} value, ...)
9187 @findex __sync_fetch_and_add
9188 @findex __sync_fetch_and_sub
9189 @findex __sync_fetch_and_or
9190 @findex __sync_fetch_and_and
9191 @findex __sync_fetch_and_xor
9192 @findex __sync_fetch_and_nand
9193 These built-in functions perform the operation suggested by the name, and
9194 returns the value that had previously been in memory. That is,
9195
9196 @smallexample
9197 @{ tmp = *ptr; *ptr @var{op}= value; return tmp; @}
9198 @{ tmp = *ptr; *ptr = ~(tmp & value); return tmp; @} // nand
9199 @end smallexample
9200
9201 @emph{Note:} GCC 4.4 and later implement @code{__sync_fetch_and_nand}
9202 as @code{*ptr = ~(tmp & value)} instead of @code{*ptr = ~tmp & value}.
9203
9204 @item @var{type} __sync_add_and_fetch (@var{type} *ptr, @var{type} value, ...)
9205 @itemx @var{type} __sync_sub_and_fetch (@var{type} *ptr, @var{type} value, ...)
9206 @itemx @var{type} __sync_or_and_fetch (@var{type} *ptr, @var{type} value, ...)
9207 @itemx @var{type} __sync_and_and_fetch (@var{type} *ptr, @var{type} value, ...)
9208 @itemx @var{type} __sync_xor_and_fetch (@var{type} *ptr, @var{type} value, ...)
9209 @itemx @var{type} __sync_nand_and_fetch (@var{type} *ptr, @var{type} value, ...)
9210 @findex __sync_add_and_fetch
9211 @findex __sync_sub_and_fetch
9212 @findex __sync_or_and_fetch
9213 @findex __sync_and_and_fetch
9214 @findex __sync_xor_and_fetch
9215 @findex __sync_nand_and_fetch
9216 These built-in functions perform the operation suggested by the name, and
9217 return the new value. That is,
9218
9219 @smallexample
9220 @{ *ptr @var{op}= value; return *ptr; @}
9221 @{ *ptr = ~(*ptr & value); return *ptr; @} // nand
9222 @end smallexample
9223
9224 @emph{Note:} GCC 4.4 and later implement @code{__sync_nand_and_fetch}
9225 as @code{*ptr = ~(*ptr & value)} instead of
9226 @code{*ptr = ~*ptr & value}.
9227
9228 @item bool __sync_bool_compare_and_swap (@var{type} *ptr, @var{type} oldval, @var{type} newval, ...)
9229 @itemx @var{type} __sync_val_compare_and_swap (@var{type} *ptr, @var{type} oldval, @var{type} newval, ...)
9230 @findex __sync_bool_compare_and_swap
9231 @findex __sync_val_compare_and_swap
9232 These built-in functions perform an atomic compare and swap.
9233 That is, if the current
9234 value of @code{*@var{ptr}} is @var{oldval}, then write @var{newval} into
9235 @code{*@var{ptr}}.
9236
9237 The ``bool'' version returns true if the comparison is successful and
9238 @var{newval} is written. The ``val'' version returns the contents
9239 of @code{*@var{ptr}} before the operation.
9240
9241 @item __sync_synchronize (...)
9242 @findex __sync_synchronize
9243 This built-in function issues a full memory barrier.
9244
9245 @item @var{type} __sync_lock_test_and_set (@var{type} *ptr, @var{type} value, ...)
9246 @findex __sync_lock_test_and_set
9247 This built-in function, as described by Intel, is not a traditional test-and-set
9248 operation, but rather an atomic exchange operation. It writes @var{value}
9249 into @code{*@var{ptr}}, and returns the previous contents of
9250 @code{*@var{ptr}}.
9251
9252 Many targets have only minimal support for such locks, and do not support
9253 a full exchange operation. In this case, a target may support reduced
9254 functionality here by which the @emph{only} valid value to store is the
9255 immediate constant 1. The exact value actually stored in @code{*@var{ptr}}
9256 is implementation defined.
9257
9258 This built-in function is not a full barrier,
9259 but rather an @dfn{acquire barrier}.
9260 This means that references after the operation cannot move to (or be
9261 speculated to) before the operation, but previous memory stores may not
9262 be globally visible yet, and previous memory loads may not yet be
9263 satisfied.
9264
9265 @item void __sync_lock_release (@var{type} *ptr, ...)
9266 @findex __sync_lock_release
9267 This built-in function releases the lock acquired by
9268 @code{__sync_lock_test_and_set}.
9269 Normally this means writing the constant 0 to @code{*@var{ptr}}.
9270
9271 This built-in function is not a full barrier,
9272 but rather a @dfn{release barrier}.
9273 This means that all previous memory stores are globally visible, and all
9274 previous memory loads have been satisfied, but following memory reads
9275 are not prevented from being speculated to before the barrier.
9276 @end table
9277
9278 @node __atomic Builtins
9279 @section Built-in Functions for Memory Model Aware Atomic Operations
9280
9281 The following built-in functions approximately match the requirements
9282 for the C++11 memory model. They are all
9283 identified by being prefixed with @samp{__atomic} and most are
9284 overloaded so that they work with multiple types.
9285
9286 These functions are intended to replace the legacy @samp{__sync}
9287 builtins. The main difference is that the memory order that is requested
9288 is a parameter to the functions. New code should always use the
9289 @samp{__atomic} builtins rather than the @samp{__sync} builtins.
9290
9291 Note that the @samp{__atomic} builtins assume that programs will
9292 conform to the C++11 memory model. In particular, they assume
9293 that programs are free of data races. See the C++11 standard for
9294 detailed requirements.
9295
9296 The @samp{__atomic} builtins can be used with any integral scalar or
9297 pointer type that is 1, 2, 4, or 8 bytes in length. 16-byte integral
9298 types are also allowed if @samp{__int128} (@pxref{__int128}) is
9299 supported by the architecture.
9300
9301 The four non-arithmetic functions (load, store, exchange, and
9302 compare_exchange) all have a generic version as well. This generic
9303 version works on any data type. It uses the lock-free built-in function
9304 if the specific data type size makes that possible; otherwise, an
9305 external call is left to be resolved at run time. This external call is
9306 the same format with the addition of a @samp{size_t} parameter inserted
9307 as the first parameter indicating the size of the object being pointed to.
9308 All objects must be the same size.
9309
9310 There are 6 different memory orders that can be specified. These map
9311 to the C++11 memory orders with the same names, see the C++11 standard
9312 or the @uref{http://gcc.gnu.org/wiki/Atomic/GCCMM/AtomicSync,GCC wiki
9313 on atomic synchronization} for detailed definitions. Individual
9314 targets may also support additional memory orders for use on specific
9315 architectures. Refer to the target documentation for details of
9316 these.
9317
9318 An atomic operation can both constrain code motion and
9319 be mapped to hardware instructions for synchronization between threads
9320 (e.g., a fence). To which extent this happens is controlled by the
9321 memory orders, which are listed here in approximately ascending order of
9322 strength. The description of each memory order is only meant to roughly
9323 illustrate the effects and is not a specification; see the C++11
9324 memory model for precise semantics.
9325
9326 @table @code
9327 @item __ATOMIC_RELAXED
9328 Implies no inter-thread ordering constraints.
9329 @item __ATOMIC_CONSUME
9330 This is currently implemented using the stronger @code{__ATOMIC_ACQUIRE}
9331 memory order because of a deficiency in C++11's semantics for
9332 @code{memory_order_consume}.
9333 @item __ATOMIC_ACQUIRE
9334 Creates an inter-thread happens-before constraint from the release (or
9335 stronger) semantic store to this acquire load. Can prevent hoisting
9336 of code to before the operation.
9337 @item __ATOMIC_RELEASE
9338 Creates an inter-thread happens-before constraint to acquire (or stronger)
9339 semantic loads that read from this release store. Can prevent sinking
9340 of code to after the operation.
9341 @item __ATOMIC_ACQ_REL
9342 Combines the effects of both @code{__ATOMIC_ACQUIRE} and
9343 @code{__ATOMIC_RELEASE}.
9344 @item __ATOMIC_SEQ_CST
9345 Enforces total ordering with all other @code{__ATOMIC_SEQ_CST} operations.
9346 @end table
9347
9348 Note that in the C++11 memory model, @emph{fences} (e.g.,
9349 @samp{__atomic_thread_fence}) take effect in combination with other
9350 atomic operations on specific memory locations (e.g., atomic loads);
9351 operations on specific memory locations do not necessarily affect other
9352 operations in the same way.
9353
9354 Target architectures are encouraged to provide their own patterns for
9355 each of the atomic built-in functions. If no target is provided, the original
9356 non-memory model set of @samp{__sync} atomic built-in functions are
9357 used, along with any required synchronization fences surrounding it in
9358 order to achieve the proper behavior. Execution in this case is subject
9359 to the same restrictions as those built-in functions.
9360
9361 If there is no pattern or mechanism to provide a lock-free instruction
9362 sequence, a call is made to an external routine with the same parameters
9363 to be resolved at run time.
9364
9365 When implementing patterns for these built-in functions, the memory order
9366 parameter can be ignored as long as the pattern implements the most
9367 restrictive @code{__ATOMIC_SEQ_CST} memory order. Any of the other memory
9368 orders execute correctly with this memory order but they may not execute as
9369 efficiently as they could with a more appropriate implementation of the
9370 relaxed requirements.
9371
9372 Note that the C++11 standard allows for the memory order parameter to be
9373 determined at run time rather than at compile time. These built-in
9374 functions map any run-time value to @code{__ATOMIC_SEQ_CST} rather
9375 than invoke a runtime library call or inline a switch statement. This is
9376 standard compliant, safe, and the simplest approach for now.
9377
9378 The memory order parameter is a signed int, but only the lower 16 bits are
9379 reserved for the memory order. The remainder of the signed int is reserved
9380 for target use and should be 0. Use of the predefined atomic values
9381 ensures proper usage.
9382
9383 @deftypefn {Built-in Function} @var{type} __atomic_load_n (@var{type} *ptr, int memorder)
9384 This built-in function implements an atomic load operation. It returns the
9385 contents of @code{*@var{ptr}}.
9386
9387 The valid memory order variants are
9388 @code{__ATOMIC_RELAXED}, @code{__ATOMIC_SEQ_CST}, @code{__ATOMIC_ACQUIRE},
9389 and @code{__ATOMIC_CONSUME}.
9390
9391 @end deftypefn
9392
9393 @deftypefn {Built-in Function} void __atomic_load (@var{type} *ptr, @var{type} *ret, int memorder)
9394 This is the generic version of an atomic load. It returns the
9395 contents of @code{*@var{ptr}} in @code{*@var{ret}}.
9396
9397 @end deftypefn
9398
9399 @deftypefn {Built-in Function} void __atomic_store_n (@var{type} *ptr, @var{type} val, int memorder)
9400 This built-in function implements an atomic store operation. It writes
9401 @code{@var{val}} into @code{*@var{ptr}}.
9402
9403 The valid memory order variants are
9404 @code{__ATOMIC_RELAXED}, @code{__ATOMIC_SEQ_CST}, and @code{__ATOMIC_RELEASE}.
9405
9406 @end deftypefn
9407
9408 @deftypefn {Built-in Function} void __atomic_store (@var{type} *ptr, @var{type} *val, int memorder)
9409 This is the generic version of an atomic store. It stores the value
9410 of @code{*@var{val}} into @code{*@var{ptr}}.
9411
9412 @end deftypefn
9413
9414 @deftypefn {Built-in Function} @var{type} __atomic_exchange_n (@var{type} *ptr, @var{type} val, int memorder)
9415 This built-in function implements an atomic exchange operation. It writes
9416 @var{val} into @code{*@var{ptr}}, and returns the previous contents of
9417 @code{*@var{ptr}}.
9418
9419 The valid memory order variants are
9420 @code{__ATOMIC_RELAXED}, @code{__ATOMIC_SEQ_CST}, @code{__ATOMIC_ACQUIRE},
9421 @code{__ATOMIC_RELEASE}, and @code{__ATOMIC_ACQ_REL}.
9422
9423 @end deftypefn
9424
9425 @deftypefn {Built-in Function} void __atomic_exchange (@var{type} *ptr, @var{type} *val, @var{type} *ret, int memorder)
9426 This is the generic version of an atomic exchange. It stores the
9427 contents of @code{*@var{val}} into @code{*@var{ptr}}. The original value
9428 of @code{*@var{ptr}} is copied into @code{*@var{ret}}.
9429
9430 @end deftypefn
9431
9432 @deftypefn {Built-in Function} bool __atomic_compare_exchange_n (@var{type} *ptr, @var{type} *expected, @var{type} desired, bool weak, int success_memorder, int failure_memorder)
9433 This built-in function implements an atomic compare and exchange operation.
9434 This compares the contents of @code{*@var{ptr}} with the contents of
9435 @code{*@var{expected}}. If equal, the operation is a @emph{read-modify-write}
9436 operation that writes @var{desired} into @code{*@var{ptr}}. If they are not
9437 equal, the operation is a @emph{read} and the current contents of
9438 @code{*@var{ptr}} is written into @code{*@var{expected}}. @var{weak} is true
9439 for weak compare_exchange, and false for the strong variation. Many targets
9440 only offer the strong variation and ignore the parameter. When in doubt, use
9441 the strong variation.
9442
9443 True is returned if @var{desired} is written into
9444 @code{*@var{ptr}} and the operation is considered to conform to the
9445 memory order specified by @var{success_memorder}. There are no
9446 restrictions on what memory order can be used here.
9447
9448 False is returned otherwise, and the operation is considered to conform
9449 to @var{failure_memorder}. This memory order cannot be
9450 @code{__ATOMIC_RELEASE} nor @code{__ATOMIC_ACQ_REL}. It also cannot be a
9451 stronger order than that specified by @var{success_memorder}.
9452
9453 @end deftypefn
9454
9455 @deftypefn {Built-in Function} bool __atomic_compare_exchange (@var{type} *ptr, @var{type} *expected, @var{type} *desired, bool weak, int success_memorder, int failure_memorder)
9456 This built-in function implements the generic version of
9457 @code{__atomic_compare_exchange}. The function is virtually identical to
9458 @code{__atomic_compare_exchange_n}, except the desired value is also a
9459 pointer.
9460
9461 @end deftypefn
9462
9463 @deftypefn {Built-in Function} @var{type} __atomic_add_fetch (@var{type} *ptr, @var{type} val, int memorder)
9464 @deftypefnx {Built-in Function} @var{type} __atomic_sub_fetch (@var{type} *ptr, @var{type} val, int memorder)
9465 @deftypefnx {Built-in Function} @var{type} __atomic_and_fetch (@var{type} *ptr, @var{type} val, int memorder)
9466 @deftypefnx {Built-in Function} @var{type} __atomic_xor_fetch (@var{type} *ptr, @var{type} val, int memorder)
9467 @deftypefnx {Built-in Function} @var{type} __atomic_or_fetch (@var{type} *ptr, @var{type} val, int memorder)
9468 @deftypefnx {Built-in Function} @var{type} __atomic_nand_fetch (@var{type} *ptr, @var{type} val, int memorder)
9469 These built-in functions perform the operation suggested by the name, and
9470 return the result of the operation. That is,
9471
9472 @smallexample
9473 @{ *ptr @var{op}= val; return *ptr; @}
9474 @end smallexample
9475
9476 All memory orders are valid.
9477
9478 @end deftypefn
9479
9480 @deftypefn {Built-in Function} @var{type} __atomic_fetch_add (@var{type} *ptr, @var{type} val, int memorder)
9481 @deftypefnx {Built-in Function} @var{type} __atomic_fetch_sub (@var{type} *ptr, @var{type} val, int memorder)
9482 @deftypefnx {Built-in Function} @var{type} __atomic_fetch_and (@var{type} *ptr, @var{type} val, int memorder)
9483 @deftypefnx {Built-in Function} @var{type} __atomic_fetch_xor (@var{type} *ptr, @var{type} val, int memorder)
9484 @deftypefnx {Built-in Function} @var{type} __atomic_fetch_or (@var{type} *ptr, @var{type} val, int memorder)
9485 @deftypefnx {Built-in Function} @var{type} __atomic_fetch_nand (@var{type} *ptr, @var{type} val, int memorder)
9486 These built-in functions perform the operation suggested by the name, and
9487 return the value that had previously been in @code{*@var{ptr}}. That is,
9488
9489 @smallexample
9490 @{ tmp = *ptr; *ptr @var{op}= val; return tmp; @}
9491 @end smallexample
9492
9493 All memory orders are valid.
9494
9495 @end deftypefn
9496
9497 @deftypefn {Built-in Function} bool __atomic_test_and_set (void *ptr, int memorder)
9498
9499 This built-in function performs an atomic test-and-set operation on
9500 the byte at @code{*@var{ptr}}. The byte is set to some implementation
9501 defined nonzero ``set'' value and the return value is @code{true} if and only
9502 if the previous contents were ``set''.
9503 It should be only used for operands of type @code{bool} or @code{char}. For
9504 other types only part of the value may be set.
9505
9506 All memory orders are valid.
9507
9508 @end deftypefn
9509
9510 @deftypefn {Built-in Function} void __atomic_clear (bool *ptr, int memorder)
9511
9512 This built-in function performs an atomic clear operation on
9513 @code{*@var{ptr}}. After the operation, @code{*@var{ptr}} contains 0.
9514 It should be only used for operands of type @code{bool} or @code{char} and
9515 in conjunction with @code{__atomic_test_and_set}.
9516 For other types it may only clear partially. If the type is not @code{bool}
9517 prefer using @code{__atomic_store}.
9518
9519 The valid memory order variants are
9520 @code{__ATOMIC_RELAXED}, @code{__ATOMIC_SEQ_CST}, and
9521 @code{__ATOMIC_RELEASE}.
9522
9523 @end deftypefn
9524
9525 @deftypefn {Built-in Function} void __atomic_thread_fence (int memorder)
9526
9527 This built-in function acts as a synchronization fence between threads
9528 based on the specified memory order.
9529
9530 All memory orders are valid.
9531
9532 @end deftypefn
9533
9534 @deftypefn {Built-in Function} void __atomic_signal_fence (int memorder)
9535
9536 This built-in function acts as a synchronization fence between a thread
9537 and signal handlers based in the same thread.
9538
9539 All memory orders are valid.
9540
9541 @end deftypefn
9542
9543 @deftypefn {Built-in Function} bool __atomic_always_lock_free (size_t size, void *ptr)
9544
9545 This built-in function returns true if objects of @var{size} bytes always
9546 generate lock-free atomic instructions for the target architecture.
9547 @var{size} must resolve to a compile-time constant and the result also
9548 resolves to a compile-time constant.
9549
9550 @var{ptr} is an optional pointer to the object that may be used to determine
9551 alignment. A value of 0 indicates typical alignment should be used. The
9552 compiler may also ignore this parameter.
9553
9554 @smallexample
9555 if (_atomic_always_lock_free (sizeof (long long), 0))
9556 @end smallexample
9557
9558 @end deftypefn
9559
9560 @deftypefn {Built-in Function} bool __atomic_is_lock_free (size_t size, void *ptr)
9561
9562 This built-in function returns true if objects of @var{size} bytes always
9563 generate lock-free atomic instructions for the target architecture. If
9564 the built-in function is not known to be lock-free, a call is made to a
9565 runtime routine named @code{__atomic_is_lock_free}.
9566
9567 @var{ptr} is an optional pointer to the object that may be used to determine
9568 alignment. A value of 0 indicates typical alignment should be used. The
9569 compiler may also ignore this parameter.
9570 @end deftypefn
9571
9572 @node Integer Overflow Builtins
9573 @section Built-in Functions to Perform Arithmetic with Overflow Checking
9574
9575 The following built-in functions allow performing simple arithmetic operations
9576 together with checking whether the operations overflowed.
9577
9578 @deftypefn {Built-in Function} bool __builtin_add_overflow (@var{type1} a, @var{type2} b, @var{type3} *res)
9579 @deftypefnx {Built-in Function} bool __builtin_sadd_overflow (int a, int b, int *res)
9580 @deftypefnx {Built-in Function} bool __builtin_saddl_overflow (long int a, long int b, long int *res)
9581 @deftypefnx {Built-in Function} bool __builtin_saddll_overflow (long long int a, long long int b, long int *res)
9582 @deftypefnx {Built-in Function} bool __builtin_uadd_overflow (unsigned int a, unsigned int b, unsigned int *res)
9583 @deftypefnx {Built-in Function} bool __builtin_uaddl_overflow (unsigned long int a, unsigned long int b, unsigned long int *res)
9584 @deftypefnx {Built-in Function} bool __builtin_uaddll_overflow (unsigned long long int a, unsigned long long int b, unsigned long int *res)
9585
9586 These built-in functions promote the first two operands into infinite precision signed
9587 type and perform addition on those promoted operands. The result is then
9588 cast to the type the third pointer argument points to and stored there.
9589 If the stored result is equal to the infinite precision result, the built-in
9590 functions return false, otherwise they return true. As the addition is
9591 performed in infinite signed precision, these built-in functions have fully defined
9592 behavior for all argument values.
9593
9594 The first built-in function allows arbitrary integral types for operands and
9595 the result type must be pointer to some integer type, the rest of the built-in
9596 functions have explicit integer types.
9597
9598 The compiler will attempt to use hardware instructions to implement
9599 these built-in functions where possible, like conditional jump on overflow
9600 after addition, conditional jump on carry etc.
9601
9602 @end deftypefn
9603
9604 @deftypefn {Built-in Function} bool __builtin_sub_overflow (@var{type1} a, @var{type2} b, @var{type3} *res)
9605 @deftypefnx {Built-in Function} bool __builtin_ssub_overflow (int a, int b, int *res)
9606 @deftypefnx {Built-in Function} bool __builtin_ssubl_overflow (long int a, long int b, long int *res)
9607 @deftypefnx {Built-in Function} bool __builtin_ssubll_overflow (long long int a, long long int b, long int *res)
9608 @deftypefnx {Built-in Function} bool __builtin_usub_overflow (unsigned int a, unsigned int b, unsigned int *res)
9609 @deftypefnx {Built-in Function} bool __builtin_usubl_overflow (unsigned long int a, unsigned long int b, unsigned long int *res)
9610 @deftypefnx {Built-in Function} bool __builtin_usubll_overflow (unsigned long long int a, unsigned long long int b, unsigned long int *res)
9611
9612 These built-in functions are similar to the add overflow checking built-in
9613 functions above, except they perform subtraction, subtract the second argument
9614 from the first one, instead of addition.
9615
9616 @end deftypefn
9617
9618 @deftypefn {Built-in Function} bool __builtin_mul_overflow (@var{type1} a, @var{type2} b, @var{type3} *res)
9619 @deftypefnx {Built-in Function} bool __builtin_smul_overflow (int a, int b, int *res)
9620 @deftypefnx {Built-in Function} bool __builtin_smull_overflow (long int a, long int b, long int *res)
9621 @deftypefnx {Built-in Function} bool __builtin_smulll_overflow (long long int a, long long int b, long int *res)
9622 @deftypefnx {Built-in Function} bool __builtin_umul_overflow (unsigned int a, unsigned int b, unsigned int *res)
9623 @deftypefnx {Built-in Function} bool __builtin_umull_overflow (unsigned long int a, unsigned long int b, unsigned long int *res)
9624 @deftypefnx {Built-in Function} bool __builtin_umulll_overflow (unsigned long long int a, unsigned long long int b, unsigned long int *res)
9625
9626 These built-in functions are similar to the add overflow checking built-in
9627 functions above, except they perform multiplication, instead of addition.
9628
9629 @end deftypefn
9630
9631 @node x86 specific memory model extensions for transactional memory
9632 @section x86-Specific Memory Model Extensions for Transactional Memory
9633
9634 The x86 architecture supports additional memory ordering flags
9635 to mark lock critical sections for hardware lock elision.
9636 These must be specified in addition to an existing memory order to
9637 atomic intrinsics.
9638
9639 @table @code
9640 @item __ATOMIC_HLE_ACQUIRE
9641 Start lock elision on a lock variable.
9642 Memory order must be @code{__ATOMIC_ACQUIRE} or stronger.
9643 @item __ATOMIC_HLE_RELEASE
9644 End lock elision on a lock variable.
9645 Memory order must be @code{__ATOMIC_RELEASE} or stronger.
9646 @end table
9647
9648 When a lock acquire fails, it is required for good performance to abort
9649 the transaction quickly. This can be done with a @code{_mm_pause}.
9650
9651 @smallexample
9652 #include <immintrin.h> // For _mm_pause
9653
9654 int lockvar;
9655
9656 /* Acquire lock with lock elision */
9657 while (__atomic_exchange_n(&lockvar, 1, __ATOMIC_ACQUIRE|__ATOMIC_HLE_ACQUIRE))
9658 _mm_pause(); /* Abort failed transaction */
9659 ...
9660 /* Free lock with lock elision */
9661 __atomic_store_n(&lockvar, 0, __ATOMIC_RELEASE|__ATOMIC_HLE_RELEASE);
9662 @end smallexample
9663
9664 @node Object Size Checking
9665 @section Object Size Checking Built-in Functions
9666 @findex __builtin_object_size
9667 @findex __builtin___memcpy_chk
9668 @findex __builtin___mempcpy_chk
9669 @findex __builtin___memmove_chk
9670 @findex __builtin___memset_chk
9671 @findex __builtin___strcpy_chk
9672 @findex __builtin___stpcpy_chk
9673 @findex __builtin___strncpy_chk
9674 @findex __builtin___strcat_chk
9675 @findex __builtin___strncat_chk
9676 @findex __builtin___sprintf_chk
9677 @findex __builtin___snprintf_chk
9678 @findex __builtin___vsprintf_chk
9679 @findex __builtin___vsnprintf_chk
9680 @findex __builtin___printf_chk
9681 @findex __builtin___vprintf_chk
9682 @findex __builtin___fprintf_chk
9683 @findex __builtin___vfprintf_chk
9684
9685 GCC implements a limited buffer overflow protection mechanism
9686 that can prevent some buffer overflow attacks.
9687
9688 @deftypefn {Built-in Function} {size_t} __builtin_object_size (void * @var{ptr}, int @var{type})
9689 is a built-in construct that returns a constant number of bytes from
9690 @var{ptr} to the end of the object @var{ptr} pointer points to
9691 (if known at compile time). @code{__builtin_object_size} never evaluates
9692 its arguments for side-effects. If there are any side-effects in them, it
9693 returns @code{(size_t) -1} for @var{type} 0 or 1 and @code{(size_t) 0}
9694 for @var{type} 2 or 3. If there are multiple objects @var{ptr} can
9695 point to and all of them are known at compile time, the returned number
9696 is the maximum of remaining byte counts in those objects if @var{type} & 2 is
9697 0 and minimum if nonzero. If it is not possible to determine which objects
9698 @var{ptr} points to at compile time, @code{__builtin_object_size} should
9699 return @code{(size_t) -1} for @var{type} 0 or 1 and @code{(size_t) 0}
9700 for @var{type} 2 or 3.
9701
9702 @var{type} is an integer constant from 0 to 3. If the least significant
9703 bit is clear, objects are whole variables, if it is set, a closest
9704 surrounding subobject is considered the object a pointer points to.
9705 The second bit determines if maximum or minimum of remaining bytes
9706 is computed.
9707
9708 @smallexample
9709 struct V @{ char buf1[10]; int b; char buf2[10]; @} var;
9710 char *p = &var.buf1[1], *q = &var.b;
9711
9712 /* Here the object p points to is var. */
9713 assert (__builtin_object_size (p, 0) == sizeof (var) - 1);
9714 /* The subobject p points to is var.buf1. */
9715 assert (__builtin_object_size (p, 1) == sizeof (var.buf1) - 1);
9716 /* The object q points to is var. */
9717 assert (__builtin_object_size (q, 0)
9718 == (char *) (&var + 1) - (char *) &var.b);
9719 /* The subobject q points to is var.b. */
9720 assert (__builtin_object_size (q, 1) == sizeof (var.b));
9721 @end smallexample
9722 @end deftypefn
9723
9724 There are built-in functions added for many common string operation
9725 functions, e.g., for @code{memcpy} @code{__builtin___memcpy_chk}
9726 built-in is provided. This built-in has an additional last argument,
9727 which is the number of bytes remaining in object the @var{dest}
9728 argument points to or @code{(size_t) -1} if the size is not known.
9729
9730 The built-in functions are optimized into the normal string functions
9731 like @code{memcpy} if the last argument is @code{(size_t) -1} or if
9732 it is known at compile time that the destination object will not
9733 be overflown. If the compiler can determine at compile time the
9734 object will be always overflown, it issues a warning.
9735
9736 The intended use can be e.g.@:
9737
9738 @smallexample
9739 #undef memcpy
9740 #define bos0(dest) __builtin_object_size (dest, 0)
9741 #define memcpy(dest, src, n) \
9742 __builtin___memcpy_chk (dest, src, n, bos0 (dest))
9743
9744 char *volatile p;
9745 char buf[10];
9746 /* It is unknown what object p points to, so this is optimized
9747 into plain memcpy - no checking is possible. */
9748 memcpy (p, "abcde", n);
9749 /* Destination is known and length too. It is known at compile
9750 time there will be no overflow. */
9751 memcpy (&buf[5], "abcde", 5);
9752 /* Destination is known, but the length is not known at compile time.
9753 This will result in __memcpy_chk call that can check for overflow
9754 at run time. */
9755 memcpy (&buf[5], "abcde", n);
9756 /* Destination is known and it is known at compile time there will
9757 be overflow. There will be a warning and __memcpy_chk call that
9758 will abort the program at run time. */
9759 memcpy (&buf[6], "abcde", 5);
9760 @end smallexample
9761
9762 Such built-in functions are provided for @code{memcpy}, @code{mempcpy},
9763 @code{memmove}, @code{memset}, @code{strcpy}, @code{stpcpy}, @code{strncpy},
9764 @code{strcat} and @code{strncat}.
9765
9766 There are also checking built-in functions for formatted output functions.
9767 @smallexample
9768 int __builtin___sprintf_chk (char *s, int flag, size_t os, const char *fmt, ...);
9769 int __builtin___snprintf_chk (char *s, size_t maxlen, int flag, size_t os,
9770 const char *fmt, ...);
9771 int __builtin___vsprintf_chk (char *s, int flag, size_t os, const char *fmt,
9772 va_list ap);
9773 int __builtin___vsnprintf_chk (char *s, size_t maxlen, int flag, size_t os,
9774 const char *fmt, va_list ap);
9775 @end smallexample
9776
9777 The added @var{flag} argument is passed unchanged to @code{__sprintf_chk}
9778 etc.@: functions and can contain implementation specific flags on what
9779 additional security measures the checking function might take, such as
9780 handling @code{%n} differently.
9781
9782 The @var{os} argument is the object size @var{s} points to, like in the
9783 other built-in functions. There is a small difference in the behavior
9784 though, if @var{os} is @code{(size_t) -1}, the built-in functions are
9785 optimized into the non-checking functions only if @var{flag} is 0, otherwise
9786 the checking function is called with @var{os} argument set to
9787 @code{(size_t) -1}.
9788
9789 In addition to this, there are checking built-in functions
9790 @code{__builtin___printf_chk}, @code{__builtin___vprintf_chk},
9791 @code{__builtin___fprintf_chk} and @code{__builtin___vfprintf_chk}.
9792 These have just one additional argument, @var{flag}, right before
9793 format string @var{fmt}. If the compiler is able to optimize them to
9794 @code{fputc} etc.@: functions, it does, otherwise the checking function
9795 is called and the @var{flag} argument passed to it.
9796
9797 @node Pointer Bounds Checker builtins
9798 @section Pointer Bounds Checker Built-in Functions
9799 @cindex Pointer Bounds Checker builtins
9800 @findex __builtin___bnd_set_ptr_bounds
9801 @findex __builtin___bnd_narrow_ptr_bounds
9802 @findex __builtin___bnd_copy_ptr_bounds
9803 @findex __builtin___bnd_init_ptr_bounds
9804 @findex __builtin___bnd_null_ptr_bounds
9805 @findex __builtin___bnd_store_ptr_bounds
9806 @findex __builtin___bnd_chk_ptr_lbounds
9807 @findex __builtin___bnd_chk_ptr_ubounds
9808 @findex __builtin___bnd_chk_ptr_bounds
9809 @findex __builtin___bnd_get_ptr_lbound
9810 @findex __builtin___bnd_get_ptr_ubound
9811
9812 GCC provides a set of built-in functions to control Pointer Bounds Checker
9813 instrumentation. Note that all Pointer Bounds Checker builtins can be used
9814 even if you compile with Pointer Bounds Checker off
9815 (@option{-fno-check-pointer-bounds}).
9816 The behavior may differ in such case as documented below.
9817
9818 @deftypefn {Built-in Function} {void *} __builtin___bnd_set_ptr_bounds (const void *@var{q}, size_t @var{size})
9819
9820 This built-in function returns a new pointer with the value of @var{q}, and
9821 associate it with the bounds [@var{q}, @var{q}+@var{size}-1]. With Pointer
9822 Bounds Checker off, the built-in function just returns the first argument.
9823
9824 @smallexample
9825 extern void *__wrap_malloc (size_t n)
9826 @{
9827 void *p = (void *)__real_malloc (n);
9828 if (!p) return __builtin___bnd_null_ptr_bounds (p);
9829 return __builtin___bnd_set_ptr_bounds (p, n);
9830 @}
9831 @end smallexample
9832
9833 @end deftypefn
9834
9835 @deftypefn {Built-in Function} {void *} __builtin___bnd_narrow_ptr_bounds (const void *@var{p}, const void *@var{q}, size_t @var{size})
9836
9837 This built-in function returns a new pointer with the value of @var{p}
9838 and associates it with the narrowed bounds formed by the intersection
9839 of bounds associated with @var{q} and the bounds
9840 [@var{p}, @var{p} + @var{size} - 1].
9841 With Pointer Bounds Checker off, the built-in function just returns the first
9842 argument.
9843
9844 @smallexample
9845 void init_objects (object *objs, size_t size)
9846 @{
9847 size_t i;
9848 /* Initialize objects one-by-one passing pointers with bounds of
9849 an object, not the full array of objects. */
9850 for (i = 0; i < size; i++)
9851 init_object (__builtin___bnd_narrow_ptr_bounds (objs + i, objs,
9852 sizeof(object)));
9853 @}
9854 @end smallexample
9855
9856 @end deftypefn
9857
9858 @deftypefn {Built-in Function} {void *} __builtin___bnd_copy_ptr_bounds (const void *@var{q}, const void *@var{r})
9859
9860 This built-in function returns a new pointer with the value of @var{q},
9861 and associates it with the bounds already associated with pointer @var{r}.
9862 With Pointer Bounds Checker off, the built-in function just returns the first
9863 argument.
9864
9865 @smallexample
9866 /* Here is a way to get pointer to object's field but
9867 still with the full object's bounds. */
9868 int *field_ptr = __builtin___bnd_copy_ptr_bounds (&objptr->int_field,
9869 objptr);
9870 @end smallexample
9871
9872 @end deftypefn
9873
9874 @deftypefn {Built-in Function} {void *} __builtin___bnd_init_ptr_bounds (const void *@var{q})
9875
9876 This built-in function returns a new pointer with the value of @var{q}, and
9877 associates it with INIT (allowing full memory access) bounds. With Pointer
9878 Bounds Checker off, the built-in function just returns the first argument.
9879
9880 @end deftypefn
9881
9882 @deftypefn {Built-in Function} {void *} __builtin___bnd_null_ptr_bounds (const void *@var{q})
9883
9884 This built-in function returns a new pointer with the value of @var{q}, and
9885 associates it with NULL (allowing no memory access) bounds. With Pointer
9886 Bounds Checker off, the built-in function just returns the first argument.
9887
9888 @end deftypefn
9889
9890 @deftypefn {Built-in Function} void __builtin___bnd_store_ptr_bounds (const void **@var{ptr_addr}, const void *@var{ptr_val})
9891
9892 This built-in function stores the bounds associated with pointer @var{ptr_val}
9893 and location @var{ptr_addr} into Bounds Table. This can be useful to propagate
9894 bounds from legacy code without touching the associated pointer's memory when
9895 pointers are copied as integers. With Pointer Bounds Checker off, the built-in
9896 function call is ignored.
9897
9898 @end deftypefn
9899
9900 @deftypefn {Built-in Function} void __builtin___bnd_chk_ptr_lbounds (const void *@var{q})
9901
9902 This built-in function checks if the pointer @var{q} is within the lower
9903 bound of its associated bounds. With Pointer Bounds Checker off, the built-in
9904 function call is ignored.
9905
9906 @smallexample
9907 extern void *__wrap_memset (void *dst, int c, size_t len)
9908 @{
9909 if (len > 0)
9910 @{
9911 __builtin___bnd_chk_ptr_lbounds (dst);
9912 __builtin___bnd_chk_ptr_ubounds ((char *)dst + len - 1);
9913 __real_memset (dst, c, len);
9914 @}
9915 return dst;
9916 @}
9917 @end smallexample
9918
9919 @end deftypefn
9920
9921 @deftypefn {Built-in Function} void __builtin___bnd_chk_ptr_ubounds (const void *@var{q})
9922
9923 This built-in function checks if the pointer @var{q} is within the upper
9924 bound of its associated bounds. With Pointer Bounds Checker off, the built-in
9925 function call is ignored.
9926
9927 @end deftypefn
9928
9929 @deftypefn {Built-in Function} void __builtin___bnd_chk_ptr_bounds (const void *@var{q}, size_t @var{size})
9930
9931 This built-in function checks if [@var{q}, @var{q} + @var{size} - 1] is within
9932 the lower and upper bounds associated with @var{q}. With Pointer Bounds Checker
9933 off, the built-in function call is ignored.
9934
9935 @smallexample
9936 extern void *__wrap_memcpy (void *dst, const void *src, size_t n)
9937 @{
9938 if (n > 0)
9939 @{
9940 __bnd_chk_ptr_bounds (dst, n);
9941 __bnd_chk_ptr_bounds (src, n);
9942 __real_memcpy (dst, src, n);
9943 @}
9944 return dst;
9945 @}
9946 @end smallexample
9947
9948 @end deftypefn
9949
9950 @deftypefn {Built-in Function} {const void *} __builtin___bnd_get_ptr_lbound (const void *@var{q})
9951
9952 This built-in function returns the lower bound associated
9953 with the pointer @var{q}, as a pointer value.
9954 This is useful for debugging using @code{printf}.
9955 With Pointer Bounds Checker off, the built-in function returns 0.
9956
9957 @smallexample
9958 void *lb = __builtin___bnd_get_ptr_lbound (q);
9959 void *ub = __builtin___bnd_get_ptr_ubound (q);
9960 printf ("q = %p lb(q) = %p ub(q) = %p", q, lb, ub);
9961 @end smallexample
9962
9963 @end deftypefn
9964
9965 @deftypefn {Built-in Function} {const void *} __builtin___bnd_get_ptr_ubound (const void *@var{q})
9966
9967 This built-in function returns the upper bound (which is a pointer) associated
9968 with the pointer @var{q}. With Pointer Bounds Checker off,
9969 the built-in function returns -1.
9970
9971 @end deftypefn
9972
9973 @node Cilk Plus Builtins
9974 @section Cilk Plus C/C++ Language Extension Built-in Functions
9975
9976 GCC provides support for the following built-in reduction functions if Cilk Plus
9977 is enabled. Cilk Plus can be enabled using the @option{-fcilkplus} flag.
9978
9979 @itemize @bullet
9980 @item @code{__sec_implicit_index}
9981 @item @code{__sec_reduce}
9982 @item @code{__sec_reduce_add}
9983 @item @code{__sec_reduce_all_nonzero}
9984 @item @code{__sec_reduce_all_zero}
9985 @item @code{__sec_reduce_any_nonzero}
9986 @item @code{__sec_reduce_any_zero}
9987 @item @code{__sec_reduce_max}
9988 @item @code{__sec_reduce_min}
9989 @item @code{__sec_reduce_max_ind}
9990 @item @code{__sec_reduce_min_ind}
9991 @item @code{__sec_reduce_mul}
9992 @item @code{__sec_reduce_mutating}
9993 @end itemize
9994
9995 Further details and examples about these built-in functions are described
9996 in the Cilk Plus language manual which can be found at
9997 @uref{http://www.cilkplus.org}.
9998
9999 @node Other Builtins
10000 @section Other Built-in Functions Provided by GCC
10001 @cindex built-in functions
10002 @findex __builtin_call_with_static_chain
10003 @findex __builtin_fpclassify
10004 @findex __builtin_isfinite
10005 @findex __builtin_isnormal
10006 @findex __builtin_isgreater
10007 @findex __builtin_isgreaterequal
10008 @findex __builtin_isinf_sign
10009 @findex __builtin_isless
10010 @findex __builtin_islessequal
10011 @findex __builtin_islessgreater
10012 @findex __builtin_isunordered
10013 @findex __builtin_powi
10014 @findex __builtin_powif
10015 @findex __builtin_powil
10016 @findex _Exit
10017 @findex _exit
10018 @findex abort
10019 @findex abs
10020 @findex acos
10021 @findex acosf
10022 @findex acosh
10023 @findex acoshf
10024 @findex acoshl
10025 @findex acosl
10026 @findex alloca
10027 @findex asin
10028 @findex asinf
10029 @findex asinh
10030 @findex asinhf
10031 @findex asinhl
10032 @findex asinl
10033 @findex atan
10034 @findex atan2
10035 @findex atan2f
10036 @findex atan2l
10037 @findex atanf
10038 @findex atanh
10039 @findex atanhf
10040 @findex atanhl
10041 @findex atanl
10042 @findex bcmp
10043 @findex bzero
10044 @findex cabs
10045 @findex cabsf
10046 @findex cabsl
10047 @findex cacos
10048 @findex cacosf
10049 @findex cacosh
10050 @findex cacoshf
10051 @findex cacoshl
10052 @findex cacosl
10053 @findex calloc
10054 @findex carg
10055 @findex cargf
10056 @findex cargl
10057 @findex casin
10058 @findex casinf
10059 @findex casinh
10060 @findex casinhf
10061 @findex casinhl
10062 @findex casinl
10063 @findex catan
10064 @findex catanf
10065 @findex catanh
10066 @findex catanhf
10067 @findex catanhl
10068 @findex catanl
10069 @findex cbrt
10070 @findex cbrtf
10071 @findex cbrtl
10072 @findex ccos
10073 @findex ccosf
10074 @findex ccosh
10075 @findex ccoshf
10076 @findex ccoshl
10077 @findex ccosl
10078 @findex ceil
10079 @findex ceilf
10080 @findex ceill
10081 @findex cexp
10082 @findex cexpf
10083 @findex cexpl
10084 @findex cimag
10085 @findex cimagf
10086 @findex cimagl
10087 @findex clog
10088 @findex clogf
10089 @findex clogl
10090 @findex conj
10091 @findex conjf
10092 @findex conjl
10093 @findex copysign
10094 @findex copysignf
10095 @findex copysignl
10096 @findex cos
10097 @findex cosf
10098 @findex cosh
10099 @findex coshf
10100 @findex coshl
10101 @findex cosl
10102 @findex cpow
10103 @findex cpowf
10104 @findex cpowl
10105 @findex cproj
10106 @findex cprojf
10107 @findex cprojl
10108 @findex creal
10109 @findex crealf
10110 @findex creall
10111 @findex csin
10112 @findex csinf
10113 @findex csinh
10114 @findex csinhf
10115 @findex csinhl
10116 @findex csinl
10117 @findex csqrt
10118 @findex csqrtf
10119 @findex csqrtl
10120 @findex ctan
10121 @findex ctanf
10122 @findex ctanh
10123 @findex ctanhf
10124 @findex ctanhl
10125 @findex ctanl
10126 @findex dcgettext
10127 @findex dgettext
10128 @findex drem
10129 @findex dremf
10130 @findex dreml
10131 @findex erf
10132 @findex erfc
10133 @findex erfcf
10134 @findex erfcl
10135 @findex erff
10136 @findex erfl
10137 @findex exit
10138 @findex exp
10139 @findex exp10
10140 @findex exp10f
10141 @findex exp10l
10142 @findex exp2
10143 @findex exp2f
10144 @findex exp2l
10145 @findex expf
10146 @findex expl
10147 @findex expm1
10148 @findex expm1f
10149 @findex expm1l
10150 @findex fabs
10151 @findex fabsf
10152 @findex fabsl
10153 @findex fdim
10154 @findex fdimf
10155 @findex fdiml
10156 @findex ffs
10157 @findex floor
10158 @findex floorf
10159 @findex floorl
10160 @findex fma
10161 @findex fmaf
10162 @findex fmal
10163 @findex fmax
10164 @findex fmaxf
10165 @findex fmaxl
10166 @findex fmin
10167 @findex fminf
10168 @findex fminl
10169 @findex fmod
10170 @findex fmodf
10171 @findex fmodl
10172 @findex fprintf
10173 @findex fprintf_unlocked
10174 @findex fputs
10175 @findex fputs_unlocked
10176 @findex frexp
10177 @findex frexpf
10178 @findex frexpl
10179 @findex fscanf
10180 @findex gamma
10181 @findex gammaf
10182 @findex gammal
10183 @findex gamma_r
10184 @findex gammaf_r
10185 @findex gammal_r
10186 @findex gettext
10187 @findex hypot
10188 @findex hypotf
10189 @findex hypotl
10190 @findex ilogb
10191 @findex ilogbf
10192 @findex ilogbl
10193 @findex imaxabs
10194 @findex index
10195 @findex isalnum
10196 @findex isalpha
10197 @findex isascii
10198 @findex isblank
10199 @findex iscntrl
10200 @findex isdigit
10201 @findex isgraph
10202 @findex islower
10203 @findex isprint
10204 @findex ispunct
10205 @findex isspace
10206 @findex isupper
10207 @findex iswalnum
10208 @findex iswalpha
10209 @findex iswblank
10210 @findex iswcntrl
10211 @findex iswdigit
10212 @findex iswgraph
10213 @findex iswlower
10214 @findex iswprint
10215 @findex iswpunct
10216 @findex iswspace
10217 @findex iswupper
10218 @findex iswxdigit
10219 @findex isxdigit
10220 @findex j0
10221 @findex j0f
10222 @findex j0l
10223 @findex j1
10224 @findex j1f
10225 @findex j1l
10226 @findex jn
10227 @findex jnf
10228 @findex jnl
10229 @findex labs
10230 @findex ldexp
10231 @findex ldexpf
10232 @findex ldexpl
10233 @findex lgamma
10234 @findex lgammaf
10235 @findex lgammal
10236 @findex lgamma_r
10237 @findex lgammaf_r
10238 @findex lgammal_r
10239 @findex llabs
10240 @findex llrint
10241 @findex llrintf
10242 @findex llrintl
10243 @findex llround
10244 @findex llroundf
10245 @findex llroundl
10246 @findex log
10247 @findex log10
10248 @findex log10f
10249 @findex log10l
10250 @findex log1p
10251 @findex log1pf
10252 @findex log1pl
10253 @findex log2
10254 @findex log2f
10255 @findex log2l
10256 @findex logb
10257 @findex logbf
10258 @findex logbl
10259 @findex logf
10260 @findex logl
10261 @findex lrint
10262 @findex lrintf
10263 @findex lrintl
10264 @findex lround
10265 @findex lroundf
10266 @findex lroundl
10267 @findex malloc
10268 @findex memchr
10269 @findex memcmp
10270 @findex memcpy
10271 @findex mempcpy
10272 @findex memset
10273 @findex modf
10274 @findex modff
10275 @findex modfl
10276 @findex nearbyint
10277 @findex nearbyintf
10278 @findex nearbyintl
10279 @findex nextafter
10280 @findex nextafterf
10281 @findex nextafterl
10282 @findex nexttoward
10283 @findex nexttowardf
10284 @findex nexttowardl
10285 @findex pow
10286 @findex pow10
10287 @findex pow10f
10288 @findex pow10l
10289 @findex powf
10290 @findex powl
10291 @findex printf
10292 @findex printf_unlocked
10293 @findex putchar
10294 @findex puts
10295 @findex remainder
10296 @findex remainderf
10297 @findex remainderl
10298 @findex remquo
10299 @findex remquof
10300 @findex remquol
10301 @findex rindex
10302 @findex rint
10303 @findex rintf
10304 @findex rintl
10305 @findex round
10306 @findex roundf
10307 @findex roundl
10308 @findex scalb
10309 @findex scalbf
10310 @findex scalbl
10311 @findex scalbln
10312 @findex scalblnf
10313 @findex scalblnf
10314 @findex scalbn
10315 @findex scalbnf
10316 @findex scanfnl
10317 @findex signbit
10318 @findex signbitf
10319 @findex signbitl
10320 @findex signbitd32
10321 @findex signbitd64
10322 @findex signbitd128
10323 @findex significand
10324 @findex significandf
10325 @findex significandl
10326 @findex sin
10327 @findex sincos
10328 @findex sincosf
10329 @findex sincosl
10330 @findex sinf
10331 @findex sinh
10332 @findex sinhf
10333 @findex sinhl
10334 @findex sinl
10335 @findex snprintf
10336 @findex sprintf
10337 @findex sqrt
10338 @findex sqrtf
10339 @findex sqrtl
10340 @findex sscanf
10341 @findex stpcpy
10342 @findex stpncpy
10343 @findex strcasecmp
10344 @findex strcat
10345 @findex strchr
10346 @findex strcmp
10347 @findex strcpy
10348 @findex strcspn
10349 @findex strdup
10350 @findex strfmon
10351 @findex strftime
10352 @findex strlen
10353 @findex strncasecmp
10354 @findex strncat
10355 @findex strncmp
10356 @findex strncpy
10357 @findex strndup
10358 @findex strpbrk
10359 @findex strrchr
10360 @findex strspn
10361 @findex strstr
10362 @findex tan
10363 @findex tanf
10364 @findex tanh
10365 @findex tanhf
10366 @findex tanhl
10367 @findex tanl
10368 @findex tgamma
10369 @findex tgammaf
10370 @findex tgammal
10371 @findex toascii
10372 @findex tolower
10373 @findex toupper
10374 @findex towlower
10375 @findex towupper
10376 @findex trunc
10377 @findex truncf
10378 @findex truncl
10379 @findex vfprintf
10380 @findex vfscanf
10381 @findex vprintf
10382 @findex vscanf
10383 @findex vsnprintf
10384 @findex vsprintf
10385 @findex vsscanf
10386 @findex y0
10387 @findex y0f
10388 @findex y0l
10389 @findex y1
10390 @findex y1f
10391 @findex y1l
10392 @findex yn
10393 @findex ynf
10394 @findex ynl
10395
10396 GCC provides a large number of built-in functions other than the ones
10397 mentioned above. Some of these are for internal use in the processing
10398 of exceptions or variable-length argument lists and are not
10399 documented here because they may change from time to time; we do not
10400 recommend general use of these functions.
10401
10402 The remaining functions are provided for optimization purposes.
10403
10404 With the exception of built-ins that have library equivalents such as
10405 the standard C library functions discussed below, or that expand to
10406 library calls, GCC built-in functions are always expanded inline and
10407 thus do not have corresponding entry points and their address cannot
10408 be obtained. Attempting to use them in an expression other than
10409 a function call results in a compile-time error.
10410
10411 @opindex fno-builtin
10412 GCC includes built-in versions of many of the functions in the standard
10413 C library. These functions come in two forms: one whose names start with
10414 the @code{__builtin_} prefix, and the other without. Both forms have the
10415 same type (including prototype), the same address (when their address is
10416 taken), and the same meaning as the C library functions even if you specify
10417 the @option{-fno-builtin} option @pxref{C Dialect Options}). Many of these
10418 functions are only optimized in certain cases; if they are not optimized in
10419 a particular case, a call to the library function is emitted.
10420
10421 @opindex ansi
10422 @opindex std
10423 Outside strict ISO C mode (@option{-ansi}, @option{-std=c90},
10424 @option{-std=c99} or @option{-std=c11}), the functions
10425 @code{_exit}, @code{alloca}, @code{bcmp}, @code{bzero},
10426 @code{dcgettext}, @code{dgettext}, @code{dremf}, @code{dreml},
10427 @code{drem}, @code{exp10f}, @code{exp10l}, @code{exp10}, @code{ffsll},
10428 @code{ffsl}, @code{ffs}, @code{fprintf_unlocked},
10429 @code{fputs_unlocked}, @code{gammaf}, @code{gammal}, @code{gamma},
10430 @code{gammaf_r}, @code{gammal_r}, @code{gamma_r}, @code{gettext},
10431 @code{index}, @code{isascii}, @code{j0f}, @code{j0l}, @code{j0},
10432 @code{j1f}, @code{j1l}, @code{j1}, @code{jnf}, @code{jnl}, @code{jn},
10433 @code{lgammaf_r}, @code{lgammal_r}, @code{lgamma_r}, @code{mempcpy},
10434 @code{pow10f}, @code{pow10l}, @code{pow10}, @code{printf_unlocked},
10435 @code{rindex}, @code{scalbf}, @code{scalbl}, @code{scalb},
10436 @code{signbit}, @code{signbitf}, @code{signbitl}, @code{signbitd32},
10437 @code{signbitd64}, @code{signbitd128}, @code{significandf},
10438 @code{significandl}, @code{significand}, @code{sincosf},
10439 @code{sincosl}, @code{sincos}, @code{stpcpy}, @code{stpncpy},
10440 @code{strcasecmp}, @code{strdup}, @code{strfmon}, @code{strncasecmp},
10441 @code{strndup}, @code{toascii}, @code{y0f}, @code{y0l}, @code{y0},
10442 @code{y1f}, @code{y1l}, @code{y1}, @code{ynf}, @code{ynl} and
10443 @code{yn}
10444 may be handled as built-in functions.
10445 All these functions have corresponding versions
10446 prefixed with @code{__builtin_}, which may be used even in strict C90
10447 mode.
10448
10449 The ISO C99 functions
10450 @code{_Exit}, @code{acoshf}, @code{acoshl}, @code{acosh}, @code{asinhf},
10451 @code{asinhl}, @code{asinh}, @code{atanhf}, @code{atanhl}, @code{atanh},
10452 @code{cabsf}, @code{cabsl}, @code{cabs}, @code{cacosf}, @code{cacoshf},
10453 @code{cacoshl}, @code{cacosh}, @code{cacosl}, @code{cacos},
10454 @code{cargf}, @code{cargl}, @code{carg}, @code{casinf}, @code{casinhf},
10455 @code{casinhl}, @code{casinh}, @code{casinl}, @code{casin},
10456 @code{catanf}, @code{catanhf}, @code{catanhl}, @code{catanh},
10457 @code{catanl}, @code{catan}, @code{cbrtf}, @code{cbrtl}, @code{cbrt},
10458 @code{ccosf}, @code{ccoshf}, @code{ccoshl}, @code{ccosh}, @code{ccosl},
10459 @code{ccos}, @code{cexpf}, @code{cexpl}, @code{cexp}, @code{cimagf},
10460 @code{cimagl}, @code{cimag}, @code{clogf}, @code{clogl}, @code{clog},
10461 @code{conjf}, @code{conjl}, @code{conj}, @code{copysignf}, @code{copysignl},
10462 @code{copysign}, @code{cpowf}, @code{cpowl}, @code{cpow}, @code{cprojf},
10463 @code{cprojl}, @code{cproj}, @code{crealf}, @code{creall}, @code{creal},
10464 @code{csinf}, @code{csinhf}, @code{csinhl}, @code{csinh}, @code{csinl},
10465 @code{csin}, @code{csqrtf}, @code{csqrtl}, @code{csqrt}, @code{ctanf},
10466 @code{ctanhf}, @code{ctanhl}, @code{ctanh}, @code{ctanl}, @code{ctan},
10467 @code{erfcf}, @code{erfcl}, @code{erfc}, @code{erff}, @code{erfl},
10468 @code{erf}, @code{exp2f}, @code{exp2l}, @code{exp2}, @code{expm1f},
10469 @code{expm1l}, @code{expm1}, @code{fdimf}, @code{fdiml}, @code{fdim},
10470 @code{fmaf}, @code{fmal}, @code{fmaxf}, @code{fmaxl}, @code{fmax},
10471 @code{fma}, @code{fminf}, @code{fminl}, @code{fmin}, @code{hypotf},
10472 @code{hypotl}, @code{hypot}, @code{ilogbf}, @code{ilogbl}, @code{ilogb},
10473 @code{imaxabs}, @code{isblank}, @code{iswblank}, @code{lgammaf},
10474 @code{lgammal}, @code{lgamma}, @code{llabs}, @code{llrintf}, @code{llrintl},
10475 @code{llrint}, @code{llroundf}, @code{llroundl}, @code{llround},
10476 @code{log1pf}, @code{log1pl}, @code{log1p}, @code{log2f}, @code{log2l},
10477 @code{log2}, @code{logbf}, @code{logbl}, @code{logb}, @code{lrintf},
10478 @code{lrintl}, @code{lrint}, @code{lroundf}, @code{lroundl},
10479 @code{lround}, @code{nearbyintf}, @code{nearbyintl}, @code{nearbyint},
10480 @code{nextafterf}, @code{nextafterl}, @code{nextafter},
10481 @code{nexttowardf}, @code{nexttowardl}, @code{nexttoward},
10482 @code{remainderf}, @code{remainderl}, @code{remainder}, @code{remquof},
10483 @code{remquol}, @code{remquo}, @code{rintf}, @code{rintl}, @code{rint},
10484 @code{roundf}, @code{roundl}, @code{round}, @code{scalblnf},
10485 @code{scalblnl}, @code{scalbln}, @code{scalbnf}, @code{scalbnl},
10486 @code{scalbn}, @code{snprintf}, @code{tgammaf}, @code{tgammal},
10487 @code{tgamma}, @code{truncf}, @code{truncl}, @code{trunc},
10488 @code{vfscanf}, @code{vscanf}, @code{vsnprintf} and @code{vsscanf}
10489 are handled as built-in functions
10490 except in strict ISO C90 mode (@option{-ansi} or @option{-std=c90}).
10491
10492 There are also built-in versions of the ISO C99 functions
10493 @code{acosf}, @code{acosl}, @code{asinf}, @code{asinl}, @code{atan2f},
10494 @code{atan2l}, @code{atanf}, @code{atanl}, @code{ceilf}, @code{ceill},
10495 @code{cosf}, @code{coshf}, @code{coshl}, @code{cosl}, @code{expf},
10496 @code{expl}, @code{fabsf}, @code{fabsl}, @code{floorf}, @code{floorl},
10497 @code{fmodf}, @code{fmodl}, @code{frexpf}, @code{frexpl}, @code{ldexpf},
10498 @code{ldexpl}, @code{log10f}, @code{log10l}, @code{logf}, @code{logl},
10499 @code{modfl}, @code{modf}, @code{powf}, @code{powl}, @code{sinf},
10500 @code{sinhf}, @code{sinhl}, @code{sinl}, @code{sqrtf}, @code{sqrtl},
10501 @code{tanf}, @code{tanhf}, @code{tanhl} and @code{tanl}
10502 that are recognized in any mode since ISO C90 reserves these names for
10503 the purpose to which ISO C99 puts them. All these functions have
10504 corresponding versions prefixed with @code{__builtin_}.
10505
10506 The ISO C94 functions
10507 @code{iswalnum}, @code{iswalpha}, @code{iswcntrl}, @code{iswdigit},
10508 @code{iswgraph}, @code{iswlower}, @code{iswprint}, @code{iswpunct},
10509 @code{iswspace}, @code{iswupper}, @code{iswxdigit}, @code{towlower} and
10510 @code{towupper}
10511 are handled as built-in functions
10512 except in strict ISO C90 mode (@option{-ansi} or @option{-std=c90}).
10513
10514 The ISO C90 functions
10515 @code{abort}, @code{abs}, @code{acos}, @code{asin}, @code{atan2},
10516 @code{atan}, @code{calloc}, @code{ceil}, @code{cosh}, @code{cos},
10517 @code{exit}, @code{exp}, @code{fabs}, @code{floor}, @code{fmod},
10518 @code{fprintf}, @code{fputs}, @code{frexp}, @code{fscanf},
10519 @code{isalnum}, @code{isalpha}, @code{iscntrl}, @code{isdigit},
10520 @code{isgraph}, @code{islower}, @code{isprint}, @code{ispunct},
10521 @code{isspace}, @code{isupper}, @code{isxdigit}, @code{tolower},
10522 @code{toupper}, @code{labs}, @code{ldexp}, @code{log10}, @code{log},
10523 @code{malloc}, @code{memchr}, @code{memcmp}, @code{memcpy},
10524 @code{memset}, @code{modf}, @code{pow}, @code{printf}, @code{putchar},
10525 @code{puts}, @code{scanf}, @code{sinh}, @code{sin}, @code{snprintf},
10526 @code{sprintf}, @code{sqrt}, @code{sscanf}, @code{strcat},
10527 @code{strchr}, @code{strcmp}, @code{strcpy}, @code{strcspn},
10528 @code{strlen}, @code{strncat}, @code{strncmp}, @code{strncpy},
10529 @code{strpbrk}, @code{strrchr}, @code{strspn}, @code{strstr},
10530 @code{tanh}, @code{tan}, @code{vfprintf}, @code{vprintf} and @code{vsprintf}
10531 are all recognized as built-in functions unless
10532 @option{-fno-builtin} is specified (or @option{-fno-builtin-@var{function}}
10533 is specified for an individual function). All of these functions have
10534 corresponding versions prefixed with @code{__builtin_}.
10535
10536 GCC provides built-in versions of the ISO C99 floating-point comparison
10537 macros that avoid raising exceptions for unordered operands. They have
10538 the same names as the standard macros ( @code{isgreater},
10539 @code{isgreaterequal}, @code{isless}, @code{islessequal},
10540 @code{islessgreater}, and @code{isunordered}) , with @code{__builtin_}
10541 prefixed. We intend for a library implementor to be able to simply
10542 @code{#define} each standard macro to its built-in equivalent.
10543 In the same fashion, GCC provides @code{fpclassify}, @code{isfinite},
10544 @code{isinf_sign}, @code{isnormal} and @code{signbit} built-ins used with
10545 @code{__builtin_} prefixed. The @code{isinf} and @code{isnan}
10546 built-in functions appear both with and without the @code{__builtin_} prefix.
10547
10548 @deftypefn {Built-in Function} int __builtin_types_compatible_p (@var{type1}, @var{type2})
10549
10550 You can use the built-in function @code{__builtin_types_compatible_p} to
10551 determine whether two types are the same.
10552
10553 This built-in function returns 1 if the unqualified versions of the
10554 types @var{type1} and @var{type2} (which are types, not expressions) are
10555 compatible, 0 otherwise. The result of this built-in function can be
10556 used in integer constant expressions.
10557
10558 This built-in function ignores top level qualifiers (e.g., @code{const},
10559 @code{volatile}). For example, @code{int} is equivalent to @code{const
10560 int}.
10561
10562 The type @code{int[]} and @code{int[5]} are compatible. On the other
10563 hand, @code{int} and @code{char *} are not compatible, even if the size
10564 of their types, on the particular architecture are the same. Also, the
10565 amount of pointer indirection is taken into account when determining
10566 similarity. Consequently, @code{short *} is not similar to
10567 @code{short **}. Furthermore, two types that are typedefed are
10568 considered compatible if their underlying types are compatible.
10569
10570 An @code{enum} type is not considered to be compatible with another
10571 @code{enum} type even if both are compatible with the same integer
10572 type; this is what the C standard specifies.
10573 For example, @code{enum @{foo, bar@}} is not similar to
10574 @code{enum @{hot, dog@}}.
10575
10576 You typically use this function in code whose execution varies
10577 depending on the arguments' types. For example:
10578
10579 @smallexample
10580 #define foo(x) \
10581 (@{ \
10582 typeof (x) tmp = (x); \
10583 if (__builtin_types_compatible_p (typeof (x), long double)) \
10584 tmp = foo_long_double (tmp); \
10585 else if (__builtin_types_compatible_p (typeof (x), double)) \
10586 tmp = foo_double (tmp); \
10587 else if (__builtin_types_compatible_p (typeof (x), float)) \
10588 tmp = foo_float (tmp); \
10589 else \
10590 abort (); \
10591 tmp; \
10592 @})
10593 @end smallexample
10594
10595 @emph{Note:} This construct is only available for C@.
10596
10597 @end deftypefn
10598
10599 @deftypefn {Built-in Function} @var{type} __builtin_call_with_static_chain (@var{call_exp}, @var{pointer_exp})
10600
10601 The @var{call_exp} expression must be a function call, and the
10602 @var{pointer_exp} expression must be a pointer. The @var{pointer_exp}
10603 is passed to the function call in the target's static chain location.
10604 The result of builtin is the result of the function call.
10605
10606 @emph{Note:} This builtin is only available for C@.
10607 This builtin can be used to call Go closures from C.
10608
10609 @end deftypefn
10610
10611 @deftypefn {Built-in Function} @var{type} __builtin_choose_expr (@var{const_exp}, @var{exp1}, @var{exp2})
10612
10613 You can use the built-in function @code{__builtin_choose_expr} to
10614 evaluate code depending on the value of a constant expression. This
10615 built-in function returns @var{exp1} if @var{const_exp}, which is an
10616 integer constant expression, is nonzero. Otherwise it returns @var{exp2}.
10617
10618 This built-in function is analogous to the @samp{? :} operator in C,
10619 except that the expression returned has its type unaltered by promotion
10620 rules. Also, the built-in function does not evaluate the expression
10621 that is not chosen. For example, if @var{const_exp} evaluates to true,
10622 @var{exp2} is not evaluated even if it has side-effects.
10623
10624 This built-in function can return an lvalue if the chosen argument is an
10625 lvalue.
10626
10627 If @var{exp1} is returned, the return type is the same as @var{exp1}'s
10628 type. Similarly, if @var{exp2} is returned, its return type is the same
10629 as @var{exp2}.
10630
10631 Example:
10632
10633 @smallexample
10634 #define foo(x) \
10635 __builtin_choose_expr ( \
10636 __builtin_types_compatible_p (typeof (x), double), \
10637 foo_double (x), \
10638 __builtin_choose_expr ( \
10639 __builtin_types_compatible_p (typeof (x), float), \
10640 foo_float (x), \
10641 /* @r{The void expression results in a compile-time error} \
10642 @r{when assigning the result to something.} */ \
10643 (void)0))
10644 @end smallexample
10645
10646 @emph{Note:} This construct is only available for C@. Furthermore, the
10647 unused expression (@var{exp1} or @var{exp2} depending on the value of
10648 @var{const_exp}) may still generate syntax errors. This may change in
10649 future revisions.
10650
10651 @end deftypefn
10652
10653 @deftypefn {Built-in Function} @var{type} __builtin_complex (@var{real}, @var{imag})
10654
10655 The built-in function @code{__builtin_complex} is provided for use in
10656 implementing the ISO C11 macros @code{CMPLXF}, @code{CMPLX} and
10657 @code{CMPLXL}. @var{real} and @var{imag} must have the same type, a
10658 real binary floating-point type, and the result has the corresponding
10659 complex type with real and imaginary parts @var{real} and @var{imag}.
10660 Unlike @samp{@var{real} + I * @var{imag}}, this works even when
10661 infinities, NaNs and negative zeros are involved.
10662
10663 @end deftypefn
10664
10665 @deftypefn {Built-in Function} int __builtin_constant_p (@var{exp})
10666 You can use the built-in function @code{__builtin_constant_p} to
10667 determine if a value is known to be constant at compile time and hence
10668 that GCC can perform constant-folding on expressions involving that
10669 value. The argument of the function is the value to test. The function
10670 returns the integer 1 if the argument is known to be a compile-time
10671 constant and 0 if it is not known to be a compile-time constant. A
10672 return of 0 does not indicate that the value is @emph{not} a constant,
10673 but merely that GCC cannot prove it is a constant with the specified
10674 value of the @option{-O} option.
10675
10676 You typically use this function in an embedded application where
10677 memory is a critical resource. If you have some complex calculation,
10678 you may want it to be folded if it involves constants, but need to call
10679 a function if it does not. For example:
10680
10681 @smallexample
10682 #define Scale_Value(X) \
10683 (__builtin_constant_p (X) \
10684 ? ((X) * SCALE + OFFSET) : Scale (X))
10685 @end smallexample
10686
10687 You may use this built-in function in either a macro or an inline
10688 function. However, if you use it in an inlined function and pass an
10689 argument of the function as the argument to the built-in, GCC
10690 never returns 1 when you call the inline function with a string constant
10691 or compound literal (@pxref{Compound Literals}) and does not return 1
10692 when you pass a constant numeric value to the inline function unless you
10693 specify the @option{-O} option.
10694
10695 You may also use @code{__builtin_constant_p} in initializers for static
10696 data. For instance, you can write
10697
10698 @smallexample
10699 static const int table[] = @{
10700 __builtin_constant_p (EXPRESSION) ? (EXPRESSION) : -1,
10701 /* @r{@dots{}} */
10702 @};
10703 @end smallexample
10704
10705 @noindent
10706 This is an acceptable initializer even if @var{EXPRESSION} is not a
10707 constant expression, including the case where
10708 @code{__builtin_constant_p} returns 1 because @var{EXPRESSION} can be
10709 folded to a constant but @var{EXPRESSION} contains operands that are
10710 not otherwise permitted in a static initializer (for example,
10711 @code{0 && foo ()}). GCC must be more conservative about evaluating the
10712 built-in in this case, because it has no opportunity to perform
10713 optimization.
10714 @end deftypefn
10715
10716 @deftypefn {Built-in Function} long __builtin_expect (long @var{exp}, long @var{c})
10717 @opindex fprofile-arcs
10718 You may use @code{__builtin_expect} to provide the compiler with
10719 branch prediction information. In general, you should prefer to
10720 use actual profile feedback for this (@option{-fprofile-arcs}), as
10721 programmers are notoriously bad at predicting how their programs
10722 actually perform. However, there are applications in which this
10723 data is hard to collect.
10724
10725 The return value is the value of @var{exp}, which should be an integral
10726 expression. The semantics of the built-in are that it is expected that
10727 @var{exp} == @var{c}. For example:
10728
10729 @smallexample
10730 if (__builtin_expect (x, 0))
10731 foo ();
10732 @end smallexample
10733
10734 @noindent
10735 indicates that we do not expect to call @code{foo}, since
10736 we expect @code{x} to be zero. Since you are limited to integral
10737 expressions for @var{exp}, you should use constructions such as
10738
10739 @smallexample
10740 if (__builtin_expect (ptr != NULL, 1))
10741 foo (*ptr);
10742 @end smallexample
10743
10744 @noindent
10745 when testing pointer or floating-point values.
10746 @end deftypefn
10747
10748 @deftypefn {Built-in Function} void __builtin_trap (void)
10749 This function causes the program to exit abnormally. GCC implements
10750 this function by using a target-dependent mechanism (such as
10751 intentionally executing an illegal instruction) or by calling
10752 @code{abort}. The mechanism used may vary from release to release so
10753 you should not rely on any particular implementation.
10754 @end deftypefn
10755
10756 @deftypefn {Built-in Function} void __builtin_unreachable (void)
10757 If control flow reaches the point of the @code{__builtin_unreachable},
10758 the program is undefined. It is useful in situations where the
10759 compiler cannot deduce the unreachability of the code.
10760
10761 One such case is immediately following an @code{asm} statement that
10762 either never terminates, or one that transfers control elsewhere
10763 and never returns. In this example, without the
10764 @code{__builtin_unreachable}, GCC issues a warning that control
10765 reaches the end of a non-void function. It also generates code
10766 to return after the @code{asm}.
10767
10768 @smallexample
10769 int f (int c, int v)
10770 @{
10771 if (c)
10772 @{
10773 return v;
10774 @}
10775 else
10776 @{
10777 asm("jmp error_handler");
10778 __builtin_unreachable ();
10779 @}
10780 @}
10781 @end smallexample
10782
10783 @noindent
10784 Because the @code{asm} statement unconditionally transfers control out
10785 of the function, control never reaches the end of the function
10786 body. The @code{__builtin_unreachable} is in fact unreachable and
10787 communicates this fact to the compiler.
10788
10789 Another use for @code{__builtin_unreachable} is following a call a
10790 function that never returns but that is not declared
10791 @code{__attribute__((noreturn))}, as in this example:
10792
10793 @smallexample
10794 void function_that_never_returns (void);
10795
10796 int g (int c)
10797 @{
10798 if (c)
10799 @{
10800 return 1;
10801 @}
10802 else
10803 @{
10804 function_that_never_returns ();
10805 __builtin_unreachable ();
10806 @}
10807 @}
10808 @end smallexample
10809
10810 @end deftypefn
10811
10812 @deftypefn {Built-in Function} {void *} __builtin_assume_aligned (const void *@var{exp}, size_t @var{align}, ...)
10813 This function returns its first argument, and allows the compiler
10814 to assume that the returned pointer is at least @var{align} bytes
10815 aligned. This built-in can have either two or three arguments,
10816 if it has three, the third argument should have integer type, and
10817 if it is nonzero means misalignment offset. For example:
10818
10819 @smallexample
10820 void *x = __builtin_assume_aligned (arg, 16);
10821 @end smallexample
10822
10823 @noindent
10824 means that the compiler can assume @code{x}, set to @code{arg}, is at least
10825 16-byte aligned, while:
10826
10827 @smallexample
10828 void *x = __builtin_assume_aligned (arg, 32, 8);
10829 @end smallexample
10830
10831 @noindent
10832 means that the compiler can assume for @code{x}, set to @code{arg}, that
10833 @code{(char *) x - 8} is 32-byte aligned.
10834 @end deftypefn
10835
10836 @deftypefn {Built-in Function} int __builtin_LINE ()
10837 This function is the equivalent to the preprocessor @code{__LINE__}
10838 macro and returns the line number of the invocation of the built-in.
10839 In a C++ default argument for a function @var{F}, it gets the line number of
10840 the call to @var{F}.
10841 @end deftypefn
10842
10843 @deftypefn {Built-in Function} {const char *} __builtin_FUNCTION ()
10844 This function is the equivalent to the preprocessor @code{__FUNCTION__}
10845 macro and returns the function name the invocation of the built-in is in.
10846 @end deftypefn
10847
10848 @deftypefn {Built-in Function} {const char *} __builtin_FILE ()
10849 This function is the equivalent to the preprocessor @code{__FILE__}
10850 macro and returns the file name the invocation of the built-in is in.
10851 In a C++ default argument for a function @var{F}, it gets the file name of
10852 the call to @var{F}.
10853 @end deftypefn
10854
10855 @deftypefn {Built-in Function} void __builtin___clear_cache (char *@var{begin}, char *@var{end})
10856 This function is used to flush the processor's instruction cache for
10857 the region of memory between @var{begin} inclusive and @var{end}
10858 exclusive. Some targets require that the instruction cache be
10859 flushed, after modifying memory containing code, in order to obtain
10860 deterministic behavior.
10861
10862 If the target does not require instruction cache flushes,
10863 @code{__builtin___clear_cache} has no effect. Otherwise either
10864 instructions are emitted in-line to clear the instruction cache or a
10865 call to the @code{__clear_cache} function in libgcc is made.
10866 @end deftypefn
10867
10868 @deftypefn {Built-in Function} void __builtin_prefetch (const void *@var{addr}, ...)
10869 This function is used to minimize cache-miss latency by moving data into
10870 a cache before it is accessed.
10871 You can insert calls to @code{__builtin_prefetch} into code for which
10872 you know addresses of data in memory that is likely to be accessed soon.
10873 If the target supports them, data prefetch instructions are generated.
10874 If the prefetch is done early enough before the access then the data will
10875 be in the cache by the time it is accessed.
10876
10877 The value of @var{addr} is the address of the memory to prefetch.
10878 There are two optional arguments, @var{rw} and @var{locality}.
10879 The value of @var{rw} is a compile-time constant one or zero; one
10880 means that the prefetch is preparing for a write to the memory address
10881 and zero, the default, means that the prefetch is preparing for a read.
10882 The value @var{locality} must be a compile-time constant integer between
10883 zero and three. A value of zero means that the data has no temporal
10884 locality, so it need not be left in the cache after the access. A value
10885 of three means that the data has a high degree of temporal locality and
10886 should be left in all levels of cache possible. Values of one and two
10887 mean, respectively, a low or moderate degree of temporal locality. The
10888 default is three.
10889
10890 @smallexample
10891 for (i = 0; i < n; i++)
10892 @{
10893 a[i] = a[i] + b[i];
10894 __builtin_prefetch (&a[i+j], 1, 1);
10895 __builtin_prefetch (&b[i+j], 0, 1);
10896 /* @r{@dots{}} */
10897 @}
10898 @end smallexample
10899
10900 Data prefetch does not generate faults if @var{addr} is invalid, but
10901 the address expression itself must be valid. For example, a prefetch
10902 of @code{p->next} does not fault if @code{p->next} is not a valid
10903 address, but evaluation faults if @code{p} is not a valid address.
10904
10905 If the target does not support data prefetch, the address expression
10906 is evaluated if it includes side effects but no other code is generated
10907 and GCC does not issue a warning.
10908 @end deftypefn
10909
10910 @deftypefn {Built-in Function} double __builtin_huge_val (void)
10911 Returns a positive infinity, if supported by the floating-point format,
10912 else @code{DBL_MAX}. This function is suitable for implementing the
10913 ISO C macro @code{HUGE_VAL}.
10914 @end deftypefn
10915
10916 @deftypefn {Built-in Function} float __builtin_huge_valf (void)
10917 Similar to @code{__builtin_huge_val}, except the return type is @code{float}.
10918 @end deftypefn
10919
10920 @deftypefn {Built-in Function} {long double} __builtin_huge_vall (void)
10921 Similar to @code{__builtin_huge_val}, except the return
10922 type is @code{long double}.
10923 @end deftypefn
10924
10925 @deftypefn {Built-in Function} int __builtin_fpclassify (int, int, int, int, int, ...)
10926 This built-in implements the C99 fpclassify functionality. The first
10927 five int arguments should be the target library's notion of the
10928 possible FP classes and are used for return values. They must be
10929 constant values and they must appear in this order: @code{FP_NAN},
10930 @code{FP_INFINITE}, @code{FP_NORMAL}, @code{FP_SUBNORMAL} and
10931 @code{FP_ZERO}. The ellipsis is for exactly one floating-point value
10932 to classify. GCC treats the last argument as type-generic, which
10933 means it does not do default promotion from float to double.
10934 @end deftypefn
10935
10936 @deftypefn {Built-in Function} double __builtin_inf (void)
10937 Similar to @code{__builtin_huge_val}, except a warning is generated
10938 if the target floating-point format does not support infinities.
10939 @end deftypefn
10940
10941 @deftypefn {Built-in Function} _Decimal32 __builtin_infd32 (void)
10942 Similar to @code{__builtin_inf}, except the return type is @code{_Decimal32}.
10943 @end deftypefn
10944
10945 @deftypefn {Built-in Function} _Decimal64 __builtin_infd64 (void)
10946 Similar to @code{__builtin_inf}, except the return type is @code{_Decimal64}.
10947 @end deftypefn
10948
10949 @deftypefn {Built-in Function} _Decimal128 __builtin_infd128 (void)
10950 Similar to @code{__builtin_inf}, except the return type is @code{_Decimal128}.
10951 @end deftypefn
10952
10953 @deftypefn {Built-in Function} float __builtin_inff (void)
10954 Similar to @code{__builtin_inf}, except the return type is @code{float}.
10955 This function is suitable for implementing the ISO C99 macro @code{INFINITY}.
10956 @end deftypefn
10957
10958 @deftypefn {Built-in Function} {long double} __builtin_infl (void)
10959 Similar to @code{__builtin_inf}, except the return
10960 type is @code{long double}.
10961 @end deftypefn
10962
10963 @deftypefn {Built-in Function} int __builtin_isinf_sign (...)
10964 Similar to @code{isinf}, except the return value is -1 for
10965 an argument of @code{-Inf} and 1 for an argument of @code{+Inf}.
10966 Note while the parameter list is an
10967 ellipsis, this function only accepts exactly one floating-point
10968 argument. GCC treats this parameter as type-generic, which means it
10969 does not do default promotion from float to double.
10970 @end deftypefn
10971
10972 @deftypefn {Built-in Function} double __builtin_nan (const char *str)
10973 This is an implementation of the ISO C99 function @code{nan}.
10974
10975 Since ISO C99 defines this function in terms of @code{strtod}, which we
10976 do not implement, a description of the parsing is in order. The string
10977 is parsed as by @code{strtol}; that is, the base is recognized by
10978 leading @samp{0} or @samp{0x} prefixes. The number parsed is placed
10979 in the significand such that the least significant bit of the number
10980 is at the least significant bit of the significand. The number is
10981 truncated to fit the significand field provided. The significand is
10982 forced to be a quiet NaN@.
10983
10984 This function, if given a string literal all of which would have been
10985 consumed by @code{strtol}, is evaluated early enough that it is considered a
10986 compile-time constant.
10987 @end deftypefn
10988
10989 @deftypefn {Built-in Function} _Decimal32 __builtin_nand32 (const char *str)
10990 Similar to @code{__builtin_nan}, except the return type is @code{_Decimal32}.
10991 @end deftypefn
10992
10993 @deftypefn {Built-in Function} _Decimal64 __builtin_nand64 (const char *str)
10994 Similar to @code{__builtin_nan}, except the return type is @code{_Decimal64}.
10995 @end deftypefn
10996
10997 @deftypefn {Built-in Function} _Decimal128 __builtin_nand128 (const char *str)
10998 Similar to @code{__builtin_nan}, except the return type is @code{_Decimal128}.
10999 @end deftypefn
11000
11001 @deftypefn {Built-in Function} float __builtin_nanf (const char *str)
11002 Similar to @code{__builtin_nan}, except the return type is @code{float}.
11003 @end deftypefn
11004
11005 @deftypefn {Built-in Function} {long double} __builtin_nanl (const char *str)
11006 Similar to @code{__builtin_nan}, except the return type is @code{long double}.
11007 @end deftypefn
11008
11009 @deftypefn {Built-in Function} double __builtin_nans (const char *str)
11010 Similar to @code{__builtin_nan}, except the significand is forced
11011 to be a signaling NaN@. The @code{nans} function is proposed by
11012 @uref{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n965.htm,,WG14 N965}.
11013 @end deftypefn
11014
11015 @deftypefn {Built-in Function} float __builtin_nansf (const char *str)
11016 Similar to @code{__builtin_nans}, except the return type is @code{float}.
11017 @end deftypefn
11018
11019 @deftypefn {Built-in Function} {long double} __builtin_nansl (const char *str)
11020 Similar to @code{__builtin_nans}, except the return type is @code{long double}.
11021 @end deftypefn
11022
11023 @deftypefn {Built-in Function} int __builtin_ffs (int x)
11024 Returns one plus the index of the least significant 1-bit of @var{x}, or
11025 if @var{x} is zero, returns zero.
11026 @end deftypefn
11027
11028 @deftypefn {Built-in Function} int __builtin_clz (unsigned int x)
11029 Returns the number of leading 0-bits in @var{x}, starting at the most
11030 significant bit position. If @var{x} is 0, the result is undefined.
11031 @end deftypefn
11032
11033 @deftypefn {Built-in Function} int __builtin_ctz (unsigned int x)
11034 Returns the number of trailing 0-bits in @var{x}, starting at the least
11035 significant bit position. If @var{x} is 0, the result is undefined.
11036 @end deftypefn
11037
11038 @deftypefn {Built-in Function} int __builtin_clrsb (int x)
11039 Returns the number of leading redundant sign bits in @var{x}, i.e.@: the
11040 number of bits following the most significant bit that are identical
11041 to it. There are no special cases for 0 or other values.
11042 @end deftypefn
11043
11044 @deftypefn {Built-in Function} int __builtin_popcount (unsigned int x)
11045 Returns the number of 1-bits in @var{x}.
11046 @end deftypefn
11047
11048 @deftypefn {Built-in Function} int __builtin_parity (unsigned int x)
11049 Returns the parity of @var{x}, i.e.@: the number of 1-bits in @var{x}
11050 modulo 2.
11051 @end deftypefn
11052
11053 @deftypefn {Built-in Function} int __builtin_ffsl (long)
11054 Similar to @code{__builtin_ffs}, except the argument type is
11055 @code{long}.
11056 @end deftypefn
11057
11058 @deftypefn {Built-in Function} int __builtin_clzl (unsigned long)
11059 Similar to @code{__builtin_clz}, except the argument type is
11060 @code{unsigned long}.
11061 @end deftypefn
11062
11063 @deftypefn {Built-in Function} int __builtin_ctzl (unsigned long)
11064 Similar to @code{__builtin_ctz}, except the argument type is
11065 @code{unsigned long}.
11066 @end deftypefn
11067
11068 @deftypefn {Built-in Function} int __builtin_clrsbl (long)
11069 Similar to @code{__builtin_clrsb}, except the argument type is
11070 @code{long}.
11071 @end deftypefn
11072
11073 @deftypefn {Built-in Function} int __builtin_popcountl (unsigned long)
11074 Similar to @code{__builtin_popcount}, except the argument type is
11075 @code{unsigned long}.
11076 @end deftypefn
11077
11078 @deftypefn {Built-in Function} int __builtin_parityl (unsigned long)
11079 Similar to @code{__builtin_parity}, except the argument type is
11080 @code{unsigned long}.
11081 @end deftypefn
11082
11083 @deftypefn {Built-in Function} int __builtin_ffsll (long long)
11084 Similar to @code{__builtin_ffs}, except the argument type is
11085 @code{long long}.
11086 @end deftypefn
11087
11088 @deftypefn {Built-in Function} int __builtin_clzll (unsigned long long)
11089 Similar to @code{__builtin_clz}, except the argument type is
11090 @code{unsigned long long}.
11091 @end deftypefn
11092
11093 @deftypefn {Built-in Function} int __builtin_ctzll (unsigned long long)
11094 Similar to @code{__builtin_ctz}, except the argument type is
11095 @code{unsigned long long}.
11096 @end deftypefn
11097
11098 @deftypefn {Built-in Function} int __builtin_clrsbll (long long)
11099 Similar to @code{__builtin_clrsb}, except the argument type is
11100 @code{long long}.
11101 @end deftypefn
11102
11103 @deftypefn {Built-in Function} int __builtin_popcountll (unsigned long long)
11104 Similar to @code{__builtin_popcount}, except the argument type is
11105 @code{unsigned long long}.
11106 @end deftypefn
11107
11108 @deftypefn {Built-in Function} int __builtin_parityll (unsigned long long)
11109 Similar to @code{__builtin_parity}, except the argument type is
11110 @code{unsigned long long}.
11111 @end deftypefn
11112
11113 @deftypefn {Built-in Function} double __builtin_powi (double, int)
11114 Returns the first argument raised to the power of the second. Unlike the
11115 @code{pow} function no guarantees about precision and rounding are made.
11116 @end deftypefn
11117
11118 @deftypefn {Built-in Function} float __builtin_powif (float, int)
11119 Similar to @code{__builtin_powi}, except the argument and return types
11120 are @code{float}.
11121 @end deftypefn
11122
11123 @deftypefn {Built-in Function} {long double} __builtin_powil (long double, int)
11124 Similar to @code{__builtin_powi}, except the argument and return types
11125 are @code{long double}.
11126 @end deftypefn
11127
11128 @deftypefn {Built-in Function} uint16_t __builtin_bswap16 (uint16_t x)
11129 Returns @var{x} with the order of the bytes reversed; for example,
11130 @code{0xaabb} becomes @code{0xbbaa}. Byte here always means
11131 exactly 8 bits.
11132 @end deftypefn
11133
11134 @deftypefn {Built-in Function} uint32_t __builtin_bswap32 (uint32_t x)
11135 Similar to @code{__builtin_bswap16}, except the argument and return types
11136 are 32 bit.
11137 @end deftypefn
11138
11139 @deftypefn {Built-in Function} uint64_t __builtin_bswap64 (uint64_t x)
11140 Similar to @code{__builtin_bswap32}, except the argument and return types
11141 are 64 bit.
11142 @end deftypefn
11143
11144 @node Target Builtins
11145 @section Built-in Functions Specific to Particular Target Machines
11146
11147 On some target machines, GCC supports many built-in functions specific
11148 to those machines. Generally these generate calls to specific machine
11149 instructions, but allow the compiler to schedule those calls.
11150
11151 @menu
11152 * AArch64 Built-in Functions::
11153 * Alpha Built-in Functions::
11154 * Altera Nios II Built-in Functions::
11155 * ARC Built-in Functions::
11156 * ARC SIMD Built-in Functions::
11157 * ARM iWMMXt Built-in Functions::
11158 * ARM C Language Extensions (ACLE)::
11159 * ARM Floating Point Status and Control Intrinsics::
11160 * AVR Built-in Functions::
11161 * Blackfin Built-in Functions::
11162 * FR-V Built-in Functions::
11163 * MIPS DSP Built-in Functions::
11164 * MIPS Paired-Single Support::
11165 * MIPS Loongson Built-in Functions::
11166 * Other MIPS Built-in Functions::
11167 * MSP430 Built-in Functions::
11168 * NDS32 Built-in Functions::
11169 * picoChip Built-in Functions::
11170 * PowerPC Built-in Functions::
11171 * PowerPC AltiVec/VSX Built-in Functions::
11172 * PowerPC Hardware Transactional Memory Built-in Functions::
11173 * RX Built-in Functions::
11174 * S/390 System z Built-in Functions::
11175 * SH Built-in Functions::
11176 * SPARC VIS Built-in Functions::
11177 * SPU Built-in Functions::
11178 * TI C6X Built-in Functions::
11179 * TILE-Gx Built-in Functions::
11180 * TILEPro Built-in Functions::
11181 * x86 Built-in Functions::
11182 * x86 transactional memory intrinsics::
11183 @end menu
11184
11185 @node AArch64 Built-in Functions
11186 @subsection AArch64 Built-in Functions
11187
11188 These built-in functions are available for the AArch64 family of
11189 processors.
11190 @smallexample
11191 unsigned int __builtin_aarch64_get_fpcr ()
11192 void __builtin_aarch64_set_fpcr (unsigned int)
11193 unsigned int __builtin_aarch64_get_fpsr ()
11194 void __builtin_aarch64_set_fpsr (unsigned int)
11195 @end smallexample
11196
11197 @node Alpha Built-in Functions
11198 @subsection Alpha Built-in Functions
11199
11200 These built-in functions are available for the Alpha family of
11201 processors, depending on the command-line switches used.
11202
11203 The following built-in functions are always available. They
11204 all generate the machine instruction that is part of the name.
11205
11206 @smallexample
11207 long __builtin_alpha_implver (void)
11208 long __builtin_alpha_rpcc (void)
11209 long __builtin_alpha_amask (long)
11210 long __builtin_alpha_cmpbge (long, long)
11211 long __builtin_alpha_extbl (long, long)
11212 long __builtin_alpha_extwl (long, long)
11213 long __builtin_alpha_extll (long, long)
11214 long __builtin_alpha_extql (long, long)
11215 long __builtin_alpha_extwh (long, long)
11216 long __builtin_alpha_extlh (long, long)
11217 long __builtin_alpha_extqh (long, long)
11218 long __builtin_alpha_insbl (long, long)
11219 long __builtin_alpha_inswl (long, long)
11220 long __builtin_alpha_insll (long, long)
11221 long __builtin_alpha_insql (long, long)
11222 long __builtin_alpha_inswh (long, long)
11223 long __builtin_alpha_inslh (long, long)
11224 long __builtin_alpha_insqh (long, long)
11225 long __builtin_alpha_mskbl (long, long)
11226 long __builtin_alpha_mskwl (long, long)
11227 long __builtin_alpha_mskll (long, long)
11228 long __builtin_alpha_mskql (long, long)
11229 long __builtin_alpha_mskwh (long, long)
11230 long __builtin_alpha_msklh (long, long)
11231 long __builtin_alpha_mskqh (long, long)
11232 long __builtin_alpha_umulh (long, long)
11233 long __builtin_alpha_zap (long, long)
11234 long __builtin_alpha_zapnot (long, long)
11235 @end smallexample
11236
11237 The following built-in functions are always with @option{-mmax}
11238 or @option{-mcpu=@var{cpu}} where @var{cpu} is @code{pca56} or
11239 later. They all generate the machine instruction that is part
11240 of the name.
11241
11242 @smallexample
11243 long __builtin_alpha_pklb (long)
11244 long __builtin_alpha_pkwb (long)
11245 long __builtin_alpha_unpkbl (long)
11246 long __builtin_alpha_unpkbw (long)
11247 long __builtin_alpha_minub8 (long, long)
11248 long __builtin_alpha_minsb8 (long, long)
11249 long __builtin_alpha_minuw4 (long, long)
11250 long __builtin_alpha_minsw4 (long, long)
11251 long __builtin_alpha_maxub8 (long, long)
11252 long __builtin_alpha_maxsb8 (long, long)
11253 long __builtin_alpha_maxuw4 (long, long)
11254 long __builtin_alpha_maxsw4 (long, long)
11255 long __builtin_alpha_perr (long, long)
11256 @end smallexample
11257
11258 The following built-in functions are always with @option{-mcix}
11259 or @option{-mcpu=@var{cpu}} where @var{cpu} is @code{ev67} or
11260 later. They all generate the machine instruction that is part
11261 of the name.
11262
11263 @smallexample
11264 long __builtin_alpha_cttz (long)
11265 long __builtin_alpha_ctlz (long)
11266 long __builtin_alpha_ctpop (long)
11267 @end smallexample
11268
11269 The following built-in functions are available on systems that use the OSF/1
11270 PALcode. Normally they invoke the @code{rduniq} and @code{wruniq}
11271 PAL calls, but when invoked with @option{-mtls-kernel}, they invoke
11272 @code{rdval} and @code{wrval}.
11273
11274 @smallexample
11275 void *__builtin_thread_pointer (void)
11276 void __builtin_set_thread_pointer (void *)
11277 @end smallexample
11278
11279 @node Altera Nios II Built-in Functions
11280 @subsection Altera Nios II Built-in Functions
11281
11282 These built-in functions are available for the Altera Nios II
11283 family of processors.
11284
11285 The following built-in functions are always available. They
11286 all generate the machine instruction that is part of the name.
11287
11288 @example
11289 int __builtin_ldbio (volatile const void *)
11290 int __builtin_ldbuio (volatile const void *)
11291 int __builtin_ldhio (volatile const void *)
11292 int __builtin_ldhuio (volatile const void *)
11293 int __builtin_ldwio (volatile const void *)
11294 void __builtin_stbio (volatile void *, int)
11295 void __builtin_sthio (volatile void *, int)
11296 void __builtin_stwio (volatile void *, int)
11297 void __builtin_sync (void)
11298 int __builtin_rdctl (int)
11299 int __builtin_rdprs (int, int)
11300 void __builtin_wrctl (int, int)
11301 void __builtin_flushd (volatile void *)
11302 void __builtin_flushda (volatile void *)
11303 int __builtin_wrpie (int);
11304 void __builtin_eni (int);
11305 int __builtin_ldex (volatile const void *)
11306 int __builtin_stex (volatile void *, int)
11307 int __builtin_ldsex (volatile const void *)
11308 int __builtin_stsex (volatile void *, int)
11309 @end example
11310
11311 The following built-in functions are always available. They
11312 all generate a Nios II Custom Instruction. The name of the
11313 function represents the types that the function takes and
11314 returns. The letter before the @code{n} is the return type
11315 or void if absent. The @code{n} represents the first parameter
11316 to all the custom instructions, the custom instruction number.
11317 The two letters after the @code{n} represent the up to two
11318 parameters to the function.
11319
11320 The letters represent the following data types:
11321 @table @code
11322 @item <no letter>
11323 @code{void} for return type and no parameter for parameter types.
11324
11325 @item i
11326 @code{int} for return type and parameter type
11327
11328 @item f
11329 @code{float} for return type and parameter type
11330
11331 @item p
11332 @code{void *} for return type and parameter type
11333
11334 @end table
11335
11336 And the function names are:
11337 @example
11338 void __builtin_custom_n (void)
11339 void __builtin_custom_ni (int)
11340 void __builtin_custom_nf (float)
11341 void __builtin_custom_np (void *)
11342 void __builtin_custom_nii (int, int)
11343 void __builtin_custom_nif (int, float)
11344 void __builtin_custom_nip (int, void *)
11345 void __builtin_custom_nfi (float, int)
11346 void __builtin_custom_nff (float, float)
11347 void __builtin_custom_nfp (float, void *)
11348 void __builtin_custom_npi (void *, int)
11349 void __builtin_custom_npf (void *, float)
11350 void __builtin_custom_npp (void *, void *)
11351 int __builtin_custom_in (void)
11352 int __builtin_custom_ini (int)
11353 int __builtin_custom_inf (float)
11354 int __builtin_custom_inp (void *)
11355 int __builtin_custom_inii (int, int)
11356 int __builtin_custom_inif (int, float)
11357 int __builtin_custom_inip (int, void *)
11358 int __builtin_custom_infi (float, int)
11359 int __builtin_custom_inff (float, float)
11360 int __builtin_custom_infp (float, void *)
11361 int __builtin_custom_inpi (void *, int)
11362 int __builtin_custom_inpf (void *, float)
11363 int __builtin_custom_inpp (void *, void *)
11364 float __builtin_custom_fn (void)
11365 float __builtin_custom_fni (int)
11366 float __builtin_custom_fnf (float)
11367 float __builtin_custom_fnp (void *)
11368 float __builtin_custom_fnii (int, int)
11369 float __builtin_custom_fnif (int, float)
11370 float __builtin_custom_fnip (int, void *)
11371 float __builtin_custom_fnfi (float, int)
11372 float __builtin_custom_fnff (float, float)
11373 float __builtin_custom_fnfp (float, void *)
11374 float __builtin_custom_fnpi (void *, int)
11375 float __builtin_custom_fnpf (void *, float)
11376 float __builtin_custom_fnpp (void *, void *)
11377 void * __builtin_custom_pn (void)
11378 void * __builtin_custom_pni (int)
11379 void * __builtin_custom_pnf (float)
11380 void * __builtin_custom_pnp (void *)
11381 void * __builtin_custom_pnii (int, int)
11382 void * __builtin_custom_pnif (int, float)
11383 void * __builtin_custom_pnip (int, void *)
11384 void * __builtin_custom_pnfi (float, int)
11385 void * __builtin_custom_pnff (float, float)
11386 void * __builtin_custom_pnfp (float, void *)
11387 void * __builtin_custom_pnpi (void *, int)
11388 void * __builtin_custom_pnpf (void *, float)
11389 void * __builtin_custom_pnpp (void *, void *)
11390 @end example
11391
11392 @node ARC Built-in Functions
11393 @subsection ARC Built-in Functions
11394
11395 The following built-in functions are provided for ARC targets. The
11396 built-ins generate the corresponding assembly instructions. In the
11397 examples given below, the generated code often requires an operand or
11398 result to be in a register. Where necessary further code will be
11399 generated to ensure this is true, but for brevity this is not
11400 described in each case.
11401
11402 @emph{Note:} Using a built-in to generate an instruction not supported
11403 by a target may cause problems. At present the compiler is not
11404 guaranteed to detect such misuse, and as a result an internal compiler
11405 error may be generated.
11406
11407 @deftypefn {Built-in Function} int __builtin_arc_aligned (void *@var{val}, int @var{alignval})
11408 Return 1 if @var{val} is known to have the byte alignment given
11409 by @var{alignval}, otherwise return 0.
11410 Note that this is different from
11411 @smallexample
11412 __alignof__(*(char *)@var{val}) >= alignval
11413 @end smallexample
11414 because __alignof__ sees only the type of the dereference, whereas
11415 __builtin_arc_align uses alignment information from the pointer
11416 as well as from the pointed-to type.
11417 The information available will depend on optimization level.
11418 @end deftypefn
11419
11420 @deftypefn {Built-in Function} void __builtin_arc_brk (void)
11421 Generates
11422 @example
11423 brk
11424 @end example
11425 @end deftypefn
11426
11427 @deftypefn {Built-in Function} {unsigned int} __builtin_arc_core_read (unsigned int @var{regno})
11428 The operand is the number of a register to be read. Generates:
11429 @example
11430 mov @var{dest}, r@var{regno}
11431 @end example
11432 where the value in @var{dest} will be the result returned from the
11433 built-in.
11434 @end deftypefn
11435
11436 @deftypefn {Built-in Function} void __builtin_arc_core_write (unsigned int @var{regno}, unsigned int @var{val})
11437 The first operand is the number of a register to be written, the
11438 second operand is a compile time constant to write into that
11439 register. Generates:
11440 @example
11441 mov r@var{regno}, @var{val}
11442 @end example
11443 @end deftypefn
11444
11445 @deftypefn {Built-in Function} int __builtin_arc_divaw (int @var{a}, int @var{b})
11446 Only available if either @option{-mcpu=ARC700} or @option{-meA} is set.
11447 Generates:
11448 @example
11449 divaw @var{dest}, @var{a}, @var{b}
11450 @end example
11451 where the value in @var{dest} will be the result returned from the
11452 built-in.
11453 @end deftypefn
11454
11455 @deftypefn {Built-in Function} void __builtin_arc_flag (unsigned int @var{a})
11456 Generates
11457 @example
11458 flag @var{a}
11459 @end example
11460 @end deftypefn
11461
11462 @deftypefn {Built-in Function} {unsigned int} __builtin_arc_lr (unsigned int @var{auxr})
11463 The operand, @var{auxv}, is the address of an auxiliary register and
11464 must be a compile time constant. Generates:
11465 @example
11466 lr @var{dest}, [@var{auxr}]
11467 @end example
11468 Where the value in @var{dest} will be the result returned from the
11469 built-in.
11470 @end deftypefn
11471
11472 @deftypefn {Built-in Function} void __builtin_arc_mul64 (int @var{a}, int @var{b})
11473 Only available with @option{-mmul64}. Generates:
11474 @example
11475 mul64 @var{a}, @var{b}
11476 @end example
11477 @end deftypefn
11478
11479 @deftypefn {Built-in Function} void __builtin_arc_mulu64 (unsigned int @var{a}, unsigned int @var{b})
11480 Only available with @option{-mmul64}. Generates:
11481 @example
11482 mulu64 @var{a}, @var{b}
11483 @end example
11484 @end deftypefn
11485
11486 @deftypefn {Built-in Function} void __builtin_arc_nop (void)
11487 Generates:
11488 @example
11489 nop
11490 @end example
11491 @end deftypefn
11492
11493 @deftypefn {Built-in Function} int __builtin_arc_norm (int @var{src})
11494 Only valid if the @samp{norm} instruction is available through the
11495 @option{-mnorm} option or by default with @option{-mcpu=ARC700}.
11496 Generates:
11497 @example
11498 norm @var{dest}, @var{src}
11499 @end example
11500 Where the value in @var{dest} will be the result returned from the
11501 built-in.
11502 @end deftypefn
11503
11504 @deftypefn {Built-in Function} {short int} __builtin_arc_normw (short int @var{src})
11505 Only valid if the @samp{normw} instruction is available through the
11506 @option{-mnorm} option or by default with @option{-mcpu=ARC700}.
11507 Generates:
11508 @example
11509 normw @var{dest}, @var{src}
11510 @end example
11511 Where the value in @var{dest} will be the result returned from the
11512 built-in.
11513 @end deftypefn
11514
11515 @deftypefn {Built-in Function} void __builtin_arc_rtie (void)
11516 Generates:
11517 @example
11518 rtie
11519 @end example
11520 @end deftypefn
11521
11522 @deftypefn {Built-in Function} void __builtin_arc_sleep (int @var{a}
11523 Generates:
11524 @example
11525 sleep @var{a}
11526 @end example
11527 @end deftypefn
11528
11529 @deftypefn {Built-in Function} void __builtin_arc_sr (unsigned int @var{auxr}, unsigned int @var{val})
11530 The first argument, @var{auxv}, is the address of an auxiliary
11531 register, the second argument, @var{val}, is a compile time constant
11532 to be written to the register. Generates:
11533 @example
11534 sr @var{auxr}, [@var{val}]
11535 @end example
11536 @end deftypefn
11537
11538 @deftypefn {Built-in Function} int __builtin_arc_swap (int @var{src})
11539 Only valid with @option{-mswap}. Generates:
11540 @example
11541 swap @var{dest}, @var{src}
11542 @end example
11543 Where the value in @var{dest} will be the result returned from the
11544 built-in.
11545 @end deftypefn
11546
11547 @deftypefn {Built-in Function} void __builtin_arc_swi (void)
11548 Generates:
11549 @example
11550 swi
11551 @end example
11552 @end deftypefn
11553
11554 @deftypefn {Built-in Function} void __builtin_arc_sync (void)
11555 Only available with @option{-mcpu=ARC700}. Generates:
11556 @example
11557 sync
11558 @end example
11559 @end deftypefn
11560
11561 @deftypefn {Built-in Function} void __builtin_arc_trap_s (unsigned int @var{c})
11562 Only available with @option{-mcpu=ARC700}. Generates:
11563 @example
11564 trap_s @var{c}
11565 @end example
11566 @end deftypefn
11567
11568 @deftypefn {Built-in Function} void __builtin_arc_unimp_s (void)
11569 Only available with @option{-mcpu=ARC700}. Generates:
11570 @example
11571 unimp_s
11572 @end example
11573 @end deftypefn
11574
11575 The instructions generated by the following builtins are not
11576 considered as candidates for scheduling. They are not moved around by
11577 the compiler during scheduling, and thus can be expected to appear
11578 where they are put in the C code:
11579 @example
11580 __builtin_arc_brk()
11581 __builtin_arc_core_read()
11582 __builtin_arc_core_write()
11583 __builtin_arc_flag()
11584 __builtin_arc_lr()
11585 __builtin_arc_sleep()
11586 __builtin_arc_sr()
11587 __builtin_arc_swi()
11588 @end example
11589
11590 @node ARC SIMD Built-in Functions
11591 @subsection ARC SIMD Built-in Functions
11592
11593 SIMD builtins provided by the compiler can be used to generate the
11594 vector instructions. This section describes the available builtins
11595 and their usage in programs. With the @option{-msimd} option, the
11596 compiler provides 128-bit vector types, which can be specified using
11597 the @code{vector_size} attribute. The header file @file{arc-simd.h}
11598 can be included to use the following predefined types:
11599 @example
11600 typedef int __v4si __attribute__((vector_size(16)));
11601 typedef short __v8hi __attribute__((vector_size(16)));
11602 @end example
11603
11604 These types can be used to define 128-bit variables. The built-in
11605 functions listed in the following section can be used on these
11606 variables to generate the vector operations.
11607
11608 For all builtins, @code{__builtin_arc_@var{someinsn}}, the header file
11609 @file{arc-simd.h} also provides equivalent macros called
11610 @code{_@var{someinsn}} that can be used for programming ease and
11611 improved readability. The following macros for DMA control are also
11612 provided:
11613 @example
11614 #define _setup_dma_in_channel_reg _vdiwr
11615 #define _setup_dma_out_channel_reg _vdowr
11616 @end example
11617
11618 The following is a complete list of all the SIMD built-ins provided
11619 for ARC, grouped by calling signature.
11620
11621 The following take two @code{__v8hi} arguments and return a
11622 @code{__v8hi} result:
11623 @example
11624 __v8hi __builtin_arc_vaddaw (__v8hi, __v8hi)
11625 __v8hi __builtin_arc_vaddw (__v8hi, __v8hi)
11626 __v8hi __builtin_arc_vand (__v8hi, __v8hi)
11627 __v8hi __builtin_arc_vandaw (__v8hi, __v8hi)
11628 __v8hi __builtin_arc_vavb (__v8hi, __v8hi)
11629 __v8hi __builtin_arc_vavrb (__v8hi, __v8hi)
11630 __v8hi __builtin_arc_vbic (__v8hi, __v8hi)
11631 __v8hi __builtin_arc_vbicaw (__v8hi, __v8hi)
11632 __v8hi __builtin_arc_vdifaw (__v8hi, __v8hi)
11633 __v8hi __builtin_arc_vdifw (__v8hi, __v8hi)
11634 __v8hi __builtin_arc_veqw (__v8hi, __v8hi)
11635 __v8hi __builtin_arc_vh264f (__v8hi, __v8hi)
11636 __v8hi __builtin_arc_vh264ft (__v8hi, __v8hi)
11637 __v8hi __builtin_arc_vh264fw (__v8hi, __v8hi)
11638 __v8hi __builtin_arc_vlew (__v8hi, __v8hi)
11639 __v8hi __builtin_arc_vltw (__v8hi, __v8hi)
11640 __v8hi __builtin_arc_vmaxaw (__v8hi, __v8hi)
11641 __v8hi __builtin_arc_vmaxw (__v8hi, __v8hi)
11642 __v8hi __builtin_arc_vminaw (__v8hi, __v8hi)
11643 __v8hi __builtin_arc_vminw (__v8hi, __v8hi)
11644 __v8hi __builtin_arc_vmr1aw (__v8hi, __v8hi)
11645 __v8hi __builtin_arc_vmr1w (__v8hi, __v8hi)
11646 __v8hi __builtin_arc_vmr2aw (__v8hi, __v8hi)
11647 __v8hi __builtin_arc_vmr2w (__v8hi, __v8hi)
11648 __v8hi __builtin_arc_vmr3aw (__v8hi, __v8hi)
11649 __v8hi __builtin_arc_vmr3w (__v8hi, __v8hi)
11650 __v8hi __builtin_arc_vmr4aw (__v8hi, __v8hi)
11651 __v8hi __builtin_arc_vmr4w (__v8hi, __v8hi)
11652 __v8hi __builtin_arc_vmr5aw (__v8hi, __v8hi)
11653 __v8hi __builtin_arc_vmr5w (__v8hi, __v8hi)
11654 __v8hi __builtin_arc_vmr6aw (__v8hi, __v8hi)
11655 __v8hi __builtin_arc_vmr6w (__v8hi, __v8hi)
11656 __v8hi __builtin_arc_vmr7aw (__v8hi, __v8hi)
11657 __v8hi __builtin_arc_vmr7w (__v8hi, __v8hi)
11658 __v8hi __builtin_arc_vmrb (__v8hi, __v8hi)
11659 __v8hi __builtin_arc_vmulaw (__v8hi, __v8hi)
11660 __v8hi __builtin_arc_vmulfaw (__v8hi, __v8hi)
11661 __v8hi __builtin_arc_vmulfw (__v8hi, __v8hi)
11662 __v8hi __builtin_arc_vmulw (__v8hi, __v8hi)
11663 __v8hi __builtin_arc_vnew (__v8hi, __v8hi)
11664 __v8hi __builtin_arc_vor (__v8hi, __v8hi)
11665 __v8hi __builtin_arc_vsubaw (__v8hi, __v8hi)
11666 __v8hi __builtin_arc_vsubw (__v8hi, __v8hi)
11667 __v8hi __builtin_arc_vsummw (__v8hi, __v8hi)
11668 __v8hi __builtin_arc_vvc1f (__v8hi, __v8hi)
11669 __v8hi __builtin_arc_vvc1ft (__v8hi, __v8hi)
11670 __v8hi __builtin_arc_vxor (__v8hi, __v8hi)
11671 __v8hi __builtin_arc_vxoraw (__v8hi, __v8hi)
11672 @end example
11673
11674 The following take one @code{__v8hi} and one @code{int} argument and return a
11675 @code{__v8hi} result:
11676
11677 @example
11678 __v8hi __builtin_arc_vbaddw (__v8hi, int)
11679 __v8hi __builtin_arc_vbmaxw (__v8hi, int)
11680 __v8hi __builtin_arc_vbminw (__v8hi, int)
11681 __v8hi __builtin_arc_vbmulaw (__v8hi, int)
11682 __v8hi __builtin_arc_vbmulfw (__v8hi, int)
11683 __v8hi __builtin_arc_vbmulw (__v8hi, int)
11684 __v8hi __builtin_arc_vbrsubw (__v8hi, int)
11685 __v8hi __builtin_arc_vbsubw (__v8hi, int)
11686 @end example
11687
11688 The following take one @code{__v8hi} argument and one @code{int} argument which
11689 must be a 3-bit compile time constant indicating a register number
11690 I0-I7. They return a @code{__v8hi} result.
11691 @example
11692 __v8hi __builtin_arc_vasrw (__v8hi, const int)
11693 __v8hi __builtin_arc_vsr8 (__v8hi, const int)
11694 __v8hi __builtin_arc_vsr8aw (__v8hi, const int)
11695 @end example
11696
11697 The following take one @code{__v8hi} argument and one @code{int}
11698 argument which must be a 6-bit compile time constant. They return a
11699 @code{__v8hi} result.
11700 @example
11701 __v8hi __builtin_arc_vasrpwbi (__v8hi, const int)
11702 __v8hi __builtin_arc_vasrrpwbi (__v8hi, const int)
11703 __v8hi __builtin_arc_vasrrwi (__v8hi, const int)
11704 __v8hi __builtin_arc_vasrsrwi (__v8hi, const int)
11705 __v8hi __builtin_arc_vasrwi (__v8hi, const int)
11706 __v8hi __builtin_arc_vsr8awi (__v8hi, const int)
11707 __v8hi __builtin_arc_vsr8i (__v8hi, const int)
11708 @end example
11709
11710 The following take one @code{__v8hi} argument and one @code{int} argument which
11711 must be a 8-bit compile time constant. They return a @code{__v8hi}
11712 result.
11713 @example
11714 __v8hi __builtin_arc_vd6tapf (__v8hi, const int)
11715 __v8hi __builtin_arc_vmvaw (__v8hi, const int)
11716 __v8hi __builtin_arc_vmvw (__v8hi, const int)
11717 __v8hi __builtin_arc_vmvzw (__v8hi, const int)
11718 @end example
11719
11720 The following take two @code{int} arguments, the second of which which
11721 must be a 8-bit compile time constant. They return a @code{__v8hi}
11722 result:
11723 @example
11724 __v8hi __builtin_arc_vmovaw (int, const int)
11725 __v8hi __builtin_arc_vmovw (int, const int)
11726 __v8hi __builtin_arc_vmovzw (int, const int)
11727 @end example
11728
11729 The following take a single @code{__v8hi} argument and return a
11730 @code{__v8hi} result:
11731 @example
11732 __v8hi __builtin_arc_vabsaw (__v8hi)
11733 __v8hi __builtin_arc_vabsw (__v8hi)
11734 __v8hi __builtin_arc_vaddsuw (__v8hi)
11735 __v8hi __builtin_arc_vexch1 (__v8hi)
11736 __v8hi __builtin_arc_vexch2 (__v8hi)
11737 __v8hi __builtin_arc_vexch4 (__v8hi)
11738 __v8hi __builtin_arc_vsignw (__v8hi)
11739 __v8hi __builtin_arc_vupbaw (__v8hi)
11740 __v8hi __builtin_arc_vupbw (__v8hi)
11741 __v8hi __builtin_arc_vupsbaw (__v8hi)
11742 __v8hi __builtin_arc_vupsbw (__v8hi)
11743 @end example
11744
11745 The following take two @code{int} arguments and return no result:
11746 @example
11747 void __builtin_arc_vdirun (int, int)
11748 void __builtin_arc_vdorun (int, int)
11749 @end example
11750
11751 The following take two @code{int} arguments and return no result. The
11752 first argument must a 3-bit compile time constant indicating one of
11753 the DR0-DR7 DMA setup channels:
11754 @example
11755 void __builtin_arc_vdiwr (const int, int)
11756 void __builtin_arc_vdowr (const int, int)
11757 @end example
11758
11759 The following take an @code{int} argument and return no result:
11760 @example
11761 void __builtin_arc_vendrec (int)
11762 void __builtin_arc_vrec (int)
11763 void __builtin_arc_vrecrun (int)
11764 void __builtin_arc_vrun (int)
11765 @end example
11766
11767 The following take a @code{__v8hi} argument and two @code{int}
11768 arguments and return a @code{__v8hi} result. The second argument must
11769 be a 3-bit compile time constants, indicating one the registers I0-I7,
11770 and the third argument must be an 8-bit compile time constant.
11771
11772 @emph{Note:} Although the equivalent hardware instructions do not take
11773 an SIMD register as an operand, these builtins overwrite the relevant
11774 bits of the @code{__v8hi} register provided as the first argument with
11775 the value loaded from the @code{[Ib, u8]} location in the SDM.
11776
11777 @example
11778 __v8hi __builtin_arc_vld32 (__v8hi, const int, const int)
11779 __v8hi __builtin_arc_vld32wh (__v8hi, const int, const int)
11780 __v8hi __builtin_arc_vld32wl (__v8hi, const int, const int)
11781 __v8hi __builtin_arc_vld64 (__v8hi, const int, const int)
11782 @end example
11783
11784 The following take two @code{int} arguments and return a @code{__v8hi}
11785 result. The first argument must be a 3-bit compile time constants,
11786 indicating one the registers I0-I7, and the second argument must be an
11787 8-bit compile time constant.
11788
11789 @example
11790 __v8hi __builtin_arc_vld128 (const int, const int)
11791 __v8hi __builtin_arc_vld64w (const int, const int)
11792 @end example
11793
11794 The following take a @code{__v8hi} argument and two @code{int}
11795 arguments and return no result. The second argument must be a 3-bit
11796 compile time constants, indicating one the registers I0-I7, and the
11797 third argument must be an 8-bit compile time constant.
11798
11799 @example
11800 void __builtin_arc_vst128 (__v8hi, const int, const int)
11801 void __builtin_arc_vst64 (__v8hi, const int, const int)
11802 @end example
11803
11804 The following take a @code{__v8hi} argument and three @code{int}
11805 arguments and return no result. The second argument must be a 3-bit
11806 compile-time constant, identifying the 16-bit sub-register to be
11807 stored, the third argument must be a 3-bit compile time constants,
11808 indicating one the registers I0-I7, and the fourth argument must be an
11809 8-bit compile time constant.
11810
11811 @example
11812 void __builtin_arc_vst16_n (__v8hi, const int, const int, const int)
11813 void __builtin_arc_vst32_n (__v8hi, const int, const int, const int)
11814 @end example
11815
11816 @node ARM iWMMXt Built-in Functions
11817 @subsection ARM iWMMXt Built-in Functions
11818
11819 These built-in functions are available for the ARM family of
11820 processors when the @option{-mcpu=iwmmxt} switch is used:
11821
11822 @smallexample
11823 typedef int v2si __attribute__ ((vector_size (8)));
11824 typedef short v4hi __attribute__ ((vector_size (8)));
11825 typedef char v8qi __attribute__ ((vector_size (8)));
11826
11827 int __builtin_arm_getwcgr0 (void)
11828 void __builtin_arm_setwcgr0 (int)
11829 int __builtin_arm_getwcgr1 (void)
11830 void __builtin_arm_setwcgr1 (int)
11831 int __builtin_arm_getwcgr2 (void)
11832 void __builtin_arm_setwcgr2 (int)
11833 int __builtin_arm_getwcgr3 (void)
11834 void __builtin_arm_setwcgr3 (int)
11835 int __builtin_arm_textrmsb (v8qi, int)
11836 int __builtin_arm_textrmsh (v4hi, int)
11837 int __builtin_arm_textrmsw (v2si, int)
11838 int __builtin_arm_textrmub (v8qi, int)
11839 int __builtin_arm_textrmuh (v4hi, int)
11840 int __builtin_arm_textrmuw (v2si, int)
11841 v8qi __builtin_arm_tinsrb (v8qi, int, int)
11842 v4hi __builtin_arm_tinsrh (v4hi, int, int)
11843 v2si __builtin_arm_tinsrw (v2si, int, int)
11844 long long __builtin_arm_tmia (long long, int, int)
11845 long long __builtin_arm_tmiabb (long long, int, int)
11846 long long __builtin_arm_tmiabt (long long, int, int)
11847 long long __builtin_arm_tmiaph (long long, int, int)
11848 long long __builtin_arm_tmiatb (long long, int, int)
11849 long long __builtin_arm_tmiatt (long long, int, int)
11850 int __builtin_arm_tmovmskb (v8qi)
11851 int __builtin_arm_tmovmskh (v4hi)
11852 int __builtin_arm_tmovmskw (v2si)
11853 long long __builtin_arm_waccb (v8qi)
11854 long long __builtin_arm_wacch (v4hi)
11855 long long __builtin_arm_waccw (v2si)
11856 v8qi __builtin_arm_waddb (v8qi, v8qi)
11857 v8qi __builtin_arm_waddbss (v8qi, v8qi)
11858 v8qi __builtin_arm_waddbus (v8qi, v8qi)
11859 v4hi __builtin_arm_waddh (v4hi, v4hi)
11860 v4hi __builtin_arm_waddhss (v4hi, v4hi)
11861 v4hi __builtin_arm_waddhus (v4hi, v4hi)
11862 v2si __builtin_arm_waddw (v2si, v2si)
11863 v2si __builtin_arm_waddwss (v2si, v2si)
11864 v2si __builtin_arm_waddwus (v2si, v2si)
11865 v8qi __builtin_arm_walign (v8qi, v8qi, int)
11866 long long __builtin_arm_wand(long long, long long)
11867 long long __builtin_arm_wandn (long long, long long)
11868 v8qi __builtin_arm_wavg2b (v8qi, v8qi)
11869 v8qi __builtin_arm_wavg2br (v8qi, v8qi)
11870 v4hi __builtin_arm_wavg2h (v4hi, v4hi)
11871 v4hi __builtin_arm_wavg2hr (v4hi, v4hi)
11872 v8qi __builtin_arm_wcmpeqb (v8qi, v8qi)
11873 v4hi __builtin_arm_wcmpeqh (v4hi, v4hi)
11874 v2si __builtin_arm_wcmpeqw (v2si, v2si)
11875 v8qi __builtin_arm_wcmpgtsb (v8qi, v8qi)
11876 v4hi __builtin_arm_wcmpgtsh (v4hi, v4hi)
11877 v2si __builtin_arm_wcmpgtsw (v2si, v2si)
11878 v8qi __builtin_arm_wcmpgtub (v8qi, v8qi)
11879 v4hi __builtin_arm_wcmpgtuh (v4hi, v4hi)
11880 v2si __builtin_arm_wcmpgtuw (v2si, v2si)
11881 long long __builtin_arm_wmacs (long long, v4hi, v4hi)
11882 long long __builtin_arm_wmacsz (v4hi, v4hi)
11883 long long __builtin_arm_wmacu (long long, v4hi, v4hi)
11884 long long __builtin_arm_wmacuz (v4hi, v4hi)
11885 v4hi __builtin_arm_wmadds (v4hi, v4hi)
11886 v4hi __builtin_arm_wmaddu (v4hi, v4hi)
11887 v8qi __builtin_arm_wmaxsb (v8qi, v8qi)
11888 v4hi __builtin_arm_wmaxsh (v4hi, v4hi)
11889 v2si __builtin_arm_wmaxsw (v2si, v2si)
11890 v8qi __builtin_arm_wmaxub (v8qi, v8qi)
11891 v4hi __builtin_arm_wmaxuh (v4hi, v4hi)
11892 v2si __builtin_arm_wmaxuw (v2si, v2si)
11893 v8qi __builtin_arm_wminsb (v8qi, v8qi)
11894 v4hi __builtin_arm_wminsh (v4hi, v4hi)
11895 v2si __builtin_arm_wminsw (v2si, v2si)
11896 v8qi __builtin_arm_wminub (v8qi, v8qi)
11897 v4hi __builtin_arm_wminuh (v4hi, v4hi)
11898 v2si __builtin_arm_wminuw (v2si, v2si)
11899 v4hi __builtin_arm_wmulsm (v4hi, v4hi)
11900 v4hi __builtin_arm_wmulul (v4hi, v4hi)
11901 v4hi __builtin_arm_wmulum (v4hi, v4hi)
11902 long long __builtin_arm_wor (long long, long long)
11903 v2si __builtin_arm_wpackdss (long long, long long)
11904 v2si __builtin_arm_wpackdus (long long, long long)
11905 v8qi __builtin_arm_wpackhss (v4hi, v4hi)
11906 v8qi __builtin_arm_wpackhus (v4hi, v4hi)
11907 v4hi __builtin_arm_wpackwss (v2si, v2si)
11908 v4hi __builtin_arm_wpackwus (v2si, v2si)
11909 long long __builtin_arm_wrord (long long, long long)
11910 long long __builtin_arm_wrordi (long long, int)
11911 v4hi __builtin_arm_wrorh (v4hi, long long)
11912 v4hi __builtin_arm_wrorhi (v4hi, int)
11913 v2si __builtin_arm_wrorw (v2si, long long)
11914 v2si __builtin_arm_wrorwi (v2si, int)
11915 v2si __builtin_arm_wsadb (v2si, v8qi, v8qi)
11916 v2si __builtin_arm_wsadbz (v8qi, v8qi)
11917 v2si __builtin_arm_wsadh (v2si, v4hi, v4hi)
11918 v2si __builtin_arm_wsadhz (v4hi, v4hi)
11919 v4hi __builtin_arm_wshufh (v4hi, int)
11920 long long __builtin_arm_wslld (long long, long long)
11921 long long __builtin_arm_wslldi (long long, int)
11922 v4hi __builtin_arm_wsllh (v4hi, long long)
11923 v4hi __builtin_arm_wsllhi (v4hi, int)
11924 v2si __builtin_arm_wsllw (v2si, long long)
11925 v2si __builtin_arm_wsllwi (v2si, int)
11926 long long __builtin_arm_wsrad (long long, long long)
11927 long long __builtin_arm_wsradi (long long, int)
11928 v4hi __builtin_arm_wsrah (v4hi, long long)
11929 v4hi __builtin_arm_wsrahi (v4hi, int)
11930 v2si __builtin_arm_wsraw (v2si, long long)
11931 v2si __builtin_arm_wsrawi (v2si, int)
11932 long long __builtin_arm_wsrld (long long, long long)
11933 long long __builtin_arm_wsrldi (long long, int)
11934 v4hi __builtin_arm_wsrlh (v4hi, long long)
11935 v4hi __builtin_arm_wsrlhi (v4hi, int)
11936 v2si __builtin_arm_wsrlw (v2si, long long)
11937 v2si __builtin_arm_wsrlwi (v2si, int)
11938 v8qi __builtin_arm_wsubb (v8qi, v8qi)
11939 v8qi __builtin_arm_wsubbss (v8qi, v8qi)
11940 v8qi __builtin_arm_wsubbus (v8qi, v8qi)
11941 v4hi __builtin_arm_wsubh (v4hi, v4hi)
11942 v4hi __builtin_arm_wsubhss (v4hi, v4hi)
11943 v4hi __builtin_arm_wsubhus (v4hi, v4hi)
11944 v2si __builtin_arm_wsubw (v2si, v2si)
11945 v2si __builtin_arm_wsubwss (v2si, v2si)
11946 v2si __builtin_arm_wsubwus (v2si, v2si)
11947 v4hi __builtin_arm_wunpckehsb (v8qi)
11948 v2si __builtin_arm_wunpckehsh (v4hi)
11949 long long __builtin_arm_wunpckehsw (v2si)
11950 v4hi __builtin_arm_wunpckehub (v8qi)
11951 v2si __builtin_arm_wunpckehuh (v4hi)
11952 long long __builtin_arm_wunpckehuw (v2si)
11953 v4hi __builtin_arm_wunpckelsb (v8qi)
11954 v2si __builtin_arm_wunpckelsh (v4hi)
11955 long long __builtin_arm_wunpckelsw (v2si)
11956 v4hi __builtin_arm_wunpckelub (v8qi)
11957 v2si __builtin_arm_wunpckeluh (v4hi)
11958 long long __builtin_arm_wunpckeluw (v2si)
11959 v8qi __builtin_arm_wunpckihb (v8qi, v8qi)
11960 v4hi __builtin_arm_wunpckihh (v4hi, v4hi)
11961 v2si __builtin_arm_wunpckihw (v2si, v2si)
11962 v8qi __builtin_arm_wunpckilb (v8qi, v8qi)
11963 v4hi __builtin_arm_wunpckilh (v4hi, v4hi)
11964 v2si __builtin_arm_wunpckilw (v2si, v2si)
11965 long long __builtin_arm_wxor (long long, long long)
11966 long long __builtin_arm_wzero ()
11967 @end smallexample
11968
11969
11970 @node ARM C Language Extensions (ACLE)
11971 @subsection ARM C Language Extensions (ACLE)
11972
11973 GCC implements extensions for C as described in the ARM C Language
11974 Extensions (ACLE) specification, which can be found at
11975 @uref{http://infocenter.arm.com/help/topic/com.arm.doc.ihi0053c/IHI0053C_acle_2_0.pdf}.
11976
11977 As a part of ACLE, GCC implements extensions for Advanced SIMD as described in
11978 the ARM C Language Extensions Specification. The complete list of Advanced SIMD
11979 intrinsics can be found at
11980 @uref{http://infocenter.arm.com/help/topic/com.arm.doc.ihi0073a/IHI0073A_arm_neon_intrinsics_ref.pdf}.
11981 The built-in intrinsics for the Advanced SIMD extension are available when
11982 NEON is enabled.
11983
11984 Currently, ARM and AArch64 back ends do not support ACLE 2.0 fully. Both
11985 back ends support CRC32 intrinsics from @file{arm_acle.h}. The ARM back end's
11986 16-bit floating-point Advanced SIMD intrinsics currently comply to ACLE v1.1.
11987 AArch64's back end does not have support for 16-bit floating point Advanced SIMD
11988 intrinsics yet.
11989
11990 See @ref{ARM Options} and @ref{AArch64 Options} for more information on the
11991 availability of extensions.
11992
11993 @node ARM Floating Point Status and Control Intrinsics
11994 @subsection ARM Floating Point Status and Control Intrinsics
11995
11996 These built-in functions are available for the ARM family of
11997 processors with floating-point unit.
11998
11999 @smallexample
12000 unsigned int __builtin_arm_get_fpscr ()
12001 void __builtin_arm_set_fpscr (unsigned int)
12002 @end smallexample
12003
12004 @node AVR Built-in Functions
12005 @subsection AVR Built-in Functions
12006
12007 For each built-in function for AVR, there is an equally named,
12008 uppercase built-in macro defined. That way users can easily query if
12009 or if not a specific built-in is implemented or not. For example, if
12010 @code{__builtin_avr_nop} is available the macro
12011 @code{__BUILTIN_AVR_NOP} is defined to @code{1} and undefined otherwise.
12012
12013 The following built-in functions map to the respective machine
12014 instruction, i.e.@: @code{nop}, @code{sei}, @code{cli}, @code{sleep},
12015 @code{wdr}, @code{swap}, @code{fmul}, @code{fmuls}
12016 resp. @code{fmulsu}. The three @code{fmul*} built-ins are implemented
12017 as library call if no hardware multiplier is available.
12018
12019 @smallexample
12020 void __builtin_avr_nop (void)
12021 void __builtin_avr_sei (void)
12022 void __builtin_avr_cli (void)
12023 void __builtin_avr_sleep (void)
12024 void __builtin_avr_wdr (void)
12025 unsigned char __builtin_avr_swap (unsigned char)
12026 unsigned int __builtin_avr_fmul (unsigned char, unsigned char)
12027 int __builtin_avr_fmuls (char, char)
12028 int __builtin_avr_fmulsu (char, unsigned char)
12029 @end smallexample
12030
12031 In order to delay execution for a specific number of cycles, GCC
12032 implements
12033 @smallexample
12034 void __builtin_avr_delay_cycles (unsigned long ticks)
12035 @end smallexample
12036
12037 @noindent
12038 @code{ticks} is the number of ticks to delay execution. Note that this
12039 built-in does not take into account the effect of interrupts that
12040 might increase delay time. @code{ticks} must be a compile-time
12041 integer constant; delays with a variable number of cycles are not supported.
12042
12043 @smallexample
12044 char __builtin_avr_flash_segment (const __memx void*)
12045 @end smallexample
12046
12047 @noindent
12048 This built-in takes a byte address to the 24-bit
12049 @ref{AVR Named Address Spaces,address space} @code{__memx} and returns
12050 the number of the flash segment (the 64 KiB chunk) where the address
12051 points to. Counting starts at @code{0}.
12052 If the address does not point to flash memory, return @code{-1}.
12053
12054 @smallexample
12055 unsigned char __builtin_avr_insert_bits (unsigned long map, unsigned char bits, unsigned char val)
12056 @end smallexample
12057
12058 @noindent
12059 Insert bits from @var{bits} into @var{val} and return the resulting
12060 value. The nibbles of @var{map} determine how the insertion is
12061 performed: Let @var{X} be the @var{n}-th nibble of @var{map}
12062 @enumerate
12063 @item If @var{X} is @code{0xf},
12064 then the @var{n}-th bit of @var{val} is returned unaltered.
12065
12066 @item If X is in the range 0@dots{}7,
12067 then the @var{n}-th result bit is set to the @var{X}-th bit of @var{bits}
12068
12069 @item If X is in the range 8@dots{}@code{0xe},
12070 then the @var{n}-th result bit is undefined.
12071 @end enumerate
12072
12073 @noindent
12074 One typical use case for this built-in is adjusting input and
12075 output values to non-contiguous port layouts. Some examples:
12076
12077 @smallexample
12078 // same as val, bits is unused
12079 __builtin_avr_insert_bits (0xffffffff, bits, val)
12080 @end smallexample
12081
12082 @smallexample
12083 // same as bits, val is unused
12084 __builtin_avr_insert_bits (0x76543210, bits, val)
12085 @end smallexample
12086
12087 @smallexample
12088 // same as rotating bits by 4
12089 __builtin_avr_insert_bits (0x32107654, bits, 0)
12090 @end smallexample
12091
12092 @smallexample
12093 // high nibble of result is the high nibble of val
12094 // low nibble of result is the low nibble of bits
12095 __builtin_avr_insert_bits (0xffff3210, bits, val)
12096 @end smallexample
12097
12098 @smallexample
12099 // reverse the bit order of bits
12100 __builtin_avr_insert_bits (0x01234567, bits, 0)
12101 @end smallexample
12102
12103 @node Blackfin Built-in Functions
12104 @subsection Blackfin Built-in Functions
12105
12106 Currently, there are two Blackfin-specific built-in functions. These are
12107 used for generating @code{CSYNC} and @code{SSYNC} machine insns without
12108 using inline assembly; by using these built-in functions the compiler can
12109 automatically add workarounds for hardware errata involving these
12110 instructions. These functions are named as follows:
12111
12112 @smallexample
12113 void __builtin_bfin_csync (void)
12114 void __builtin_bfin_ssync (void)
12115 @end smallexample
12116
12117 @node FR-V Built-in Functions
12118 @subsection FR-V Built-in Functions
12119
12120 GCC provides many FR-V-specific built-in functions. In general,
12121 these functions are intended to be compatible with those described
12122 by @cite{FR-V Family, Softune C/C++ Compiler Manual (V6), Fujitsu
12123 Semiconductor}. The two exceptions are @code{__MDUNPACKH} and
12124 @code{__MBTOHE}, the GCC forms of which pass 128-bit values by
12125 pointer rather than by value.
12126
12127 Most of the functions are named after specific FR-V instructions.
12128 Such functions are said to be ``directly mapped'' and are summarized
12129 here in tabular form.
12130
12131 @menu
12132 * Argument Types::
12133 * Directly-mapped Integer Functions::
12134 * Directly-mapped Media Functions::
12135 * Raw read/write Functions::
12136 * Other Built-in Functions::
12137 @end menu
12138
12139 @node Argument Types
12140 @subsubsection Argument Types
12141
12142 The arguments to the built-in functions can be divided into three groups:
12143 register numbers, compile-time constants and run-time values. In order
12144 to make this classification clear at a glance, the arguments and return
12145 values are given the following pseudo types:
12146
12147 @multitable @columnfractions .20 .30 .15 .35
12148 @item Pseudo type @tab Real C type @tab Constant? @tab Description
12149 @item @code{uh} @tab @code{unsigned short} @tab No @tab an unsigned halfword
12150 @item @code{uw1} @tab @code{unsigned int} @tab No @tab an unsigned word
12151 @item @code{sw1} @tab @code{int} @tab No @tab a signed word
12152 @item @code{uw2} @tab @code{unsigned long long} @tab No
12153 @tab an unsigned doubleword
12154 @item @code{sw2} @tab @code{long long} @tab No @tab a signed doubleword
12155 @item @code{const} @tab @code{int} @tab Yes @tab an integer constant
12156 @item @code{acc} @tab @code{int} @tab Yes @tab an ACC register number
12157 @item @code{iacc} @tab @code{int} @tab Yes @tab an IACC register number
12158 @end multitable
12159
12160 These pseudo types are not defined by GCC, they are simply a notational
12161 convenience used in this manual.
12162
12163 Arguments of type @code{uh}, @code{uw1}, @code{sw1}, @code{uw2}
12164 and @code{sw2} are evaluated at run time. They correspond to
12165 register operands in the underlying FR-V instructions.
12166
12167 @code{const} arguments represent immediate operands in the underlying
12168 FR-V instructions. They must be compile-time constants.
12169
12170 @code{acc} arguments are evaluated at compile time and specify the number
12171 of an accumulator register. For example, an @code{acc} argument of 2
12172 selects the ACC2 register.
12173
12174 @code{iacc} arguments are similar to @code{acc} arguments but specify the
12175 number of an IACC register. See @pxref{Other Built-in Functions}
12176 for more details.
12177
12178 @node Directly-mapped Integer Functions
12179 @subsubsection Directly-Mapped Integer Functions
12180
12181 The functions listed below map directly to FR-V I-type instructions.
12182
12183 @multitable @columnfractions .45 .32 .23
12184 @item Function prototype @tab Example usage @tab Assembly output
12185 @item @code{sw1 __ADDSS (sw1, sw1)}
12186 @tab @code{@var{c} = __ADDSS (@var{a}, @var{b})}
12187 @tab @code{ADDSS @var{a},@var{b},@var{c}}
12188 @item @code{sw1 __SCAN (sw1, sw1)}
12189 @tab @code{@var{c} = __SCAN (@var{a}, @var{b})}
12190 @tab @code{SCAN @var{a},@var{b},@var{c}}
12191 @item @code{sw1 __SCUTSS (sw1)}
12192 @tab @code{@var{b} = __SCUTSS (@var{a})}
12193 @tab @code{SCUTSS @var{a},@var{b}}
12194 @item @code{sw1 __SLASS (sw1, sw1)}
12195 @tab @code{@var{c} = __SLASS (@var{a}, @var{b})}
12196 @tab @code{SLASS @var{a},@var{b},@var{c}}
12197 @item @code{void __SMASS (sw1, sw1)}
12198 @tab @code{__SMASS (@var{a}, @var{b})}
12199 @tab @code{SMASS @var{a},@var{b}}
12200 @item @code{void __SMSSS (sw1, sw1)}
12201 @tab @code{__SMSSS (@var{a}, @var{b})}
12202 @tab @code{SMSSS @var{a},@var{b}}
12203 @item @code{void __SMU (sw1, sw1)}
12204 @tab @code{__SMU (@var{a}, @var{b})}
12205 @tab @code{SMU @var{a},@var{b}}
12206 @item @code{sw2 __SMUL (sw1, sw1)}
12207 @tab @code{@var{c} = __SMUL (@var{a}, @var{b})}
12208 @tab @code{SMUL @var{a},@var{b},@var{c}}
12209 @item @code{sw1 __SUBSS (sw1, sw1)}
12210 @tab @code{@var{c} = __SUBSS (@var{a}, @var{b})}
12211 @tab @code{SUBSS @var{a},@var{b},@var{c}}
12212 @item @code{uw2 __UMUL (uw1, uw1)}
12213 @tab @code{@var{c} = __UMUL (@var{a}, @var{b})}
12214 @tab @code{UMUL @var{a},@var{b},@var{c}}
12215 @end multitable
12216
12217 @node Directly-mapped Media Functions
12218 @subsubsection Directly-Mapped Media Functions
12219
12220 The functions listed below map directly to FR-V M-type instructions.
12221
12222 @multitable @columnfractions .45 .32 .23
12223 @item Function prototype @tab Example usage @tab Assembly output
12224 @item @code{uw1 __MABSHS (sw1)}
12225 @tab @code{@var{b} = __MABSHS (@var{a})}
12226 @tab @code{MABSHS @var{a},@var{b}}
12227 @item @code{void __MADDACCS (acc, acc)}
12228 @tab @code{__MADDACCS (@var{b}, @var{a})}
12229 @tab @code{MADDACCS @var{a},@var{b}}
12230 @item @code{sw1 __MADDHSS (sw1, sw1)}
12231 @tab @code{@var{c} = __MADDHSS (@var{a}, @var{b})}
12232 @tab @code{MADDHSS @var{a},@var{b},@var{c}}
12233 @item @code{uw1 __MADDHUS (uw1, uw1)}
12234 @tab @code{@var{c} = __MADDHUS (@var{a}, @var{b})}
12235 @tab @code{MADDHUS @var{a},@var{b},@var{c}}
12236 @item @code{uw1 __MAND (uw1, uw1)}
12237 @tab @code{@var{c} = __MAND (@var{a}, @var{b})}
12238 @tab @code{MAND @var{a},@var{b},@var{c}}
12239 @item @code{void __MASACCS (acc, acc)}
12240 @tab @code{__MASACCS (@var{b}, @var{a})}
12241 @tab @code{MASACCS @var{a},@var{b}}
12242 @item @code{uw1 __MAVEH (uw1, uw1)}
12243 @tab @code{@var{c} = __MAVEH (@var{a}, @var{b})}
12244 @tab @code{MAVEH @var{a},@var{b},@var{c}}
12245 @item @code{uw2 __MBTOH (uw1)}
12246 @tab @code{@var{b} = __MBTOH (@var{a})}
12247 @tab @code{MBTOH @var{a},@var{b}}
12248 @item @code{void __MBTOHE (uw1 *, uw1)}
12249 @tab @code{__MBTOHE (&@var{b}, @var{a})}
12250 @tab @code{MBTOHE @var{a},@var{b}}
12251 @item @code{void __MCLRACC (acc)}
12252 @tab @code{__MCLRACC (@var{a})}
12253 @tab @code{MCLRACC @var{a}}
12254 @item @code{void __MCLRACCA (void)}
12255 @tab @code{__MCLRACCA ()}
12256 @tab @code{MCLRACCA}
12257 @item @code{uw1 __Mcop1 (uw1, uw1)}
12258 @tab @code{@var{c} = __Mcop1 (@var{a}, @var{b})}
12259 @tab @code{Mcop1 @var{a},@var{b},@var{c}}
12260 @item @code{uw1 __Mcop2 (uw1, uw1)}
12261 @tab @code{@var{c} = __Mcop2 (@var{a}, @var{b})}
12262 @tab @code{Mcop2 @var{a},@var{b},@var{c}}
12263 @item @code{uw1 __MCPLHI (uw2, const)}
12264 @tab @code{@var{c} = __MCPLHI (@var{a}, @var{b})}
12265 @tab @code{MCPLHI @var{a},#@var{b},@var{c}}
12266 @item @code{uw1 __MCPLI (uw2, const)}
12267 @tab @code{@var{c} = __MCPLI (@var{a}, @var{b})}
12268 @tab @code{MCPLI @var{a},#@var{b},@var{c}}
12269 @item @code{void __MCPXIS (acc, sw1, sw1)}
12270 @tab @code{__MCPXIS (@var{c}, @var{a}, @var{b})}
12271 @tab @code{MCPXIS @var{a},@var{b},@var{c}}
12272 @item @code{void __MCPXIU (acc, uw1, uw1)}
12273 @tab @code{__MCPXIU (@var{c}, @var{a}, @var{b})}
12274 @tab @code{MCPXIU @var{a},@var{b},@var{c}}
12275 @item @code{void __MCPXRS (acc, sw1, sw1)}
12276 @tab @code{__MCPXRS (@var{c}, @var{a}, @var{b})}
12277 @tab @code{MCPXRS @var{a},@var{b},@var{c}}
12278 @item @code{void __MCPXRU (acc, uw1, uw1)}
12279 @tab @code{__MCPXRU (@var{c}, @var{a}, @var{b})}
12280 @tab @code{MCPXRU @var{a},@var{b},@var{c}}
12281 @item @code{uw1 __MCUT (acc, uw1)}
12282 @tab @code{@var{c} = __MCUT (@var{a}, @var{b})}
12283 @tab @code{MCUT @var{a},@var{b},@var{c}}
12284 @item @code{uw1 __MCUTSS (acc, sw1)}
12285 @tab @code{@var{c} = __MCUTSS (@var{a}, @var{b})}
12286 @tab @code{MCUTSS @var{a},@var{b},@var{c}}
12287 @item @code{void __MDADDACCS (acc, acc)}
12288 @tab @code{__MDADDACCS (@var{b}, @var{a})}
12289 @tab @code{MDADDACCS @var{a},@var{b}}
12290 @item @code{void __MDASACCS (acc, acc)}
12291 @tab @code{__MDASACCS (@var{b}, @var{a})}
12292 @tab @code{MDASACCS @var{a},@var{b}}
12293 @item @code{uw2 __MDCUTSSI (acc, const)}
12294 @tab @code{@var{c} = __MDCUTSSI (@var{a}, @var{b})}
12295 @tab @code{MDCUTSSI @var{a},#@var{b},@var{c}}
12296 @item @code{uw2 __MDPACKH (uw2, uw2)}
12297 @tab @code{@var{c} = __MDPACKH (@var{a}, @var{b})}
12298 @tab @code{MDPACKH @var{a},@var{b},@var{c}}
12299 @item @code{uw2 __MDROTLI (uw2, const)}
12300 @tab @code{@var{c} = __MDROTLI (@var{a}, @var{b})}
12301 @tab @code{MDROTLI @var{a},#@var{b},@var{c}}
12302 @item @code{void __MDSUBACCS (acc, acc)}
12303 @tab @code{__MDSUBACCS (@var{b}, @var{a})}
12304 @tab @code{MDSUBACCS @var{a},@var{b}}
12305 @item @code{void __MDUNPACKH (uw1 *, uw2)}
12306 @tab @code{__MDUNPACKH (&@var{b}, @var{a})}
12307 @tab @code{MDUNPACKH @var{a},@var{b}}
12308 @item @code{uw2 __MEXPDHD (uw1, const)}
12309 @tab @code{@var{c} = __MEXPDHD (@var{a}, @var{b})}
12310 @tab @code{MEXPDHD @var{a},#@var{b},@var{c}}
12311 @item @code{uw1 __MEXPDHW (uw1, const)}
12312 @tab @code{@var{c} = __MEXPDHW (@var{a}, @var{b})}
12313 @tab @code{MEXPDHW @var{a},#@var{b},@var{c}}
12314 @item @code{uw1 __MHDSETH (uw1, const)}
12315 @tab @code{@var{c} = __MHDSETH (@var{a}, @var{b})}
12316 @tab @code{MHDSETH @var{a},#@var{b},@var{c}}
12317 @item @code{sw1 __MHDSETS (const)}
12318 @tab @code{@var{b} = __MHDSETS (@var{a})}
12319 @tab @code{MHDSETS #@var{a},@var{b}}
12320 @item @code{uw1 __MHSETHIH (uw1, const)}
12321 @tab @code{@var{b} = __MHSETHIH (@var{b}, @var{a})}
12322 @tab @code{MHSETHIH #@var{a},@var{b}}
12323 @item @code{sw1 __MHSETHIS (sw1, const)}
12324 @tab @code{@var{b} = __MHSETHIS (@var{b}, @var{a})}
12325 @tab @code{MHSETHIS #@var{a},@var{b}}
12326 @item @code{uw1 __MHSETLOH (uw1, const)}
12327 @tab @code{@var{b} = __MHSETLOH (@var{b}, @var{a})}
12328 @tab @code{MHSETLOH #@var{a},@var{b}}
12329 @item @code{sw1 __MHSETLOS (sw1, const)}
12330 @tab @code{@var{b} = __MHSETLOS (@var{b}, @var{a})}
12331 @tab @code{MHSETLOS #@var{a},@var{b}}
12332 @item @code{uw1 __MHTOB (uw2)}
12333 @tab @code{@var{b} = __MHTOB (@var{a})}
12334 @tab @code{MHTOB @var{a},@var{b}}
12335 @item @code{void __MMACHS (acc, sw1, sw1)}
12336 @tab @code{__MMACHS (@var{c}, @var{a}, @var{b})}
12337 @tab @code{MMACHS @var{a},@var{b},@var{c}}
12338 @item @code{void __MMACHU (acc, uw1, uw1)}
12339 @tab @code{__MMACHU (@var{c}, @var{a}, @var{b})}
12340 @tab @code{MMACHU @var{a},@var{b},@var{c}}
12341 @item @code{void __MMRDHS (acc, sw1, sw1)}
12342 @tab @code{__MMRDHS (@var{c}, @var{a}, @var{b})}
12343 @tab @code{MMRDHS @var{a},@var{b},@var{c}}
12344 @item @code{void __MMRDHU (acc, uw1, uw1)}
12345 @tab @code{__MMRDHU (@var{c}, @var{a}, @var{b})}
12346 @tab @code{MMRDHU @var{a},@var{b},@var{c}}
12347 @item @code{void __MMULHS (acc, sw1, sw1)}
12348 @tab @code{__MMULHS (@var{c}, @var{a}, @var{b})}
12349 @tab @code{MMULHS @var{a},@var{b},@var{c}}
12350 @item @code{void __MMULHU (acc, uw1, uw1)}
12351 @tab @code{__MMULHU (@var{c}, @var{a}, @var{b})}
12352 @tab @code{MMULHU @var{a},@var{b},@var{c}}
12353 @item @code{void __MMULXHS (acc, sw1, sw1)}
12354 @tab @code{__MMULXHS (@var{c}, @var{a}, @var{b})}
12355 @tab @code{MMULXHS @var{a},@var{b},@var{c}}
12356 @item @code{void __MMULXHU (acc, uw1, uw1)}
12357 @tab @code{__MMULXHU (@var{c}, @var{a}, @var{b})}
12358 @tab @code{MMULXHU @var{a},@var{b},@var{c}}
12359 @item @code{uw1 __MNOT (uw1)}
12360 @tab @code{@var{b} = __MNOT (@var{a})}
12361 @tab @code{MNOT @var{a},@var{b}}
12362 @item @code{uw1 __MOR (uw1, uw1)}
12363 @tab @code{@var{c} = __MOR (@var{a}, @var{b})}
12364 @tab @code{MOR @var{a},@var{b},@var{c}}
12365 @item @code{uw1 __MPACKH (uh, uh)}
12366 @tab @code{@var{c} = __MPACKH (@var{a}, @var{b})}
12367 @tab @code{MPACKH @var{a},@var{b},@var{c}}
12368 @item @code{sw2 __MQADDHSS (sw2, sw2)}
12369 @tab @code{@var{c} = __MQADDHSS (@var{a}, @var{b})}
12370 @tab @code{MQADDHSS @var{a},@var{b},@var{c}}
12371 @item @code{uw2 __MQADDHUS (uw2, uw2)}
12372 @tab @code{@var{c} = __MQADDHUS (@var{a}, @var{b})}
12373 @tab @code{MQADDHUS @var{a},@var{b},@var{c}}
12374 @item @code{void __MQCPXIS (acc, sw2, sw2)}
12375 @tab @code{__MQCPXIS (@var{c}, @var{a}, @var{b})}
12376 @tab @code{MQCPXIS @var{a},@var{b},@var{c}}
12377 @item @code{void __MQCPXIU (acc, uw2, uw2)}
12378 @tab @code{__MQCPXIU (@var{c}, @var{a}, @var{b})}
12379 @tab @code{MQCPXIU @var{a},@var{b},@var{c}}
12380 @item @code{void __MQCPXRS (acc, sw2, sw2)}
12381 @tab @code{__MQCPXRS (@var{c}, @var{a}, @var{b})}
12382 @tab @code{MQCPXRS @var{a},@var{b},@var{c}}
12383 @item @code{void __MQCPXRU (acc, uw2, uw2)}
12384 @tab @code{__MQCPXRU (@var{c}, @var{a}, @var{b})}
12385 @tab @code{MQCPXRU @var{a},@var{b},@var{c}}
12386 @item @code{sw2 __MQLCLRHS (sw2, sw2)}
12387 @tab @code{@var{c} = __MQLCLRHS (@var{a}, @var{b})}
12388 @tab @code{MQLCLRHS @var{a},@var{b},@var{c}}
12389 @item @code{sw2 __MQLMTHS (sw2, sw2)}
12390 @tab @code{@var{c} = __MQLMTHS (@var{a}, @var{b})}
12391 @tab @code{MQLMTHS @var{a},@var{b},@var{c}}
12392 @item @code{void __MQMACHS (acc, sw2, sw2)}
12393 @tab @code{__MQMACHS (@var{c}, @var{a}, @var{b})}
12394 @tab @code{MQMACHS @var{a},@var{b},@var{c}}
12395 @item @code{void __MQMACHU (acc, uw2, uw2)}
12396 @tab @code{__MQMACHU (@var{c}, @var{a}, @var{b})}
12397 @tab @code{MQMACHU @var{a},@var{b},@var{c}}
12398 @item @code{void __MQMACXHS (acc, sw2, sw2)}
12399 @tab @code{__MQMACXHS (@var{c}, @var{a}, @var{b})}
12400 @tab @code{MQMACXHS @var{a},@var{b},@var{c}}
12401 @item @code{void __MQMULHS (acc, sw2, sw2)}
12402 @tab @code{__MQMULHS (@var{c}, @var{a}, @var{b})}
12403 @tab @code{MQMULHS @var{a},@var{b},@var{c}}
12404 @item @code{void __MQMULHU (acc, uw2, uw2)}
12405 @tab @code{__MQMULHU (@var{c}, @var{a}, @var{b})}
12406 @tab @code{MQMULHU @var{a},@var{b},@var{c}}
12407 @item @code{void __MQMULXHS (acc, sw2, sw2)}
12408 @tab @code{__MQMULXHS (@var{c}, @var{a}, @var{b})}
12409 @tab @code{MQMULXHS @var{a},@var{b},@var{c}}
12410 @item @code{void __MQMULXHU (acc, uw2, uw2)}
12411 @tab @code{__MQMULXHU (@var{c}, @var{a}, @var{b})}
12412 @tab @code{MQMULXHU @var{a},@var{b},@var{c}}
12413 @item @code{sw2 __MQSATHS (sw2, sw2)}
12414 @tab @code{@var{c} = __MQSATHS (@var{a}, @var{b})}
12415 @tab @code{MQSATHS @var{a},@var{b},@var{c}}
12416 @item @code{uw2 __MQSLLHI (uw2, int)}
12417 @tab @code{@var{c} = __MQSLLHI (@var{a}, @var{b})}
12418 @tab @code{MQSLLHI @var{a},@var{b},@var{c}}
12419 @item @code{sw2 __MQSRAHI (sw2, int)}
12420 @tab @code{@var{c} = __MQSRAHI (@var{a}, @var{b})}
12421 @tab @code{MQSRAHI @var{a},@var{b},@var{c}}
12422 @item @code{sw2 __MQSUBHSS (sw2, sw2)}
12423 @tab @code{@var{c} = __MQSUBHSS (@var{a}, @var{b})}
12424 @tab @code{MQSUBHSS @var{a},@var{b},@var{c}}
12425 @item @code{uw2 __MQSUBHUS (uw2, uw2)}
12426 @tab @code{@var{c} = __MQSUBHUS (@var{a}, @var{b})}
12427 @tab @code{MQSUBHUS @var{a},@var{b},@var{c}}
12428 @item @code{void __MQXMACHS (acc, sw2, sw2)}
12429 @tab @code{__MQXMACHS (@var{c}, @var{a}, @var{b})}
12430 @tab @code{MQXMACHS @var{a},@var{b},@var{c}}
12431 @item @code{void __MQXMACXHS (acc, sw2, sw2)}
12432 @tab @code{__MQXMACXHS (@var{c}, @var{a}, @var{b})}
12433 @tab @code{MQXMACXHS @var{a},@var{b},@var{c}}
12434 @item @code{uw1 __MRDACC (acc)}
12435 @tab @code{@var{b} = __MRDACC (@var{a})}
12436 @tab @code{MRDACC @var{a},@var{b}}
12437 @item @code{uw1 __MRDACCG (acc)}
12438 @tab @code{@var{b} = __MRDACCG (@var{a})}
12439 @tab @code{MRDACCG @var{a},@var{b}}
12440 @item @code{uw1 __MROTLI (uw1, const)}
12441 @tab @code{@var{c} = __MROTLI (@var{a}, @var{b})}
12442 @tab @code{MROTLI @var{a},#@var{b},@var{c}}
12443 @item @code{uw1 __MROTRI (uw1, const)}
12444 @tab @code{@var{c} = __MROTRI (@var{a}, @var{b})}
12445 @tab @code{MROTRI @var{a},#@var{b},@var{c}}
12446 @item @code{sw1 __MSATHS (sw1, sw1)}
12447 @tab @code{@var{c} = __MSATHS (@var{a}, @var{b})}
12448 @tab @code{MSATHS @var{a},@var{b},@var{c}}
12449 @item @code{uw1 __MSATHU (uw1, uw1)}
12450 @tab @code{@var{c} = __MSATHU (@var{a}, @var{b})}
12451 @tab @code{MSATHU @var{a},@var{b},@var{c}}
12452 @item @code{uw1 __MSLLHI (uw1, const)}
12453 @tab @code{@var{c} = __MSLLHI (@var{a}, @var{b})}
12454 @tab @code{MSLLHI @var{a},#@var{b},@var{c}}
12455 @item @code{sw1 __MSRAHI (sw1, const)}
12456 @tab @code{@var{c} = __MSRAHI (@var{a}, @var{b})}
12457 @tab @code{MSRAHI @var{a},#@var{b},@var{c}}
12458 @item @code{uw1 __MSRLHI (uw1, const)}
12459 @tab @code{@var{c} = __MSRLHI (@var{a}, @var{b})}
12460 @tab @code{MSRLHI @var{a},#@var{b},@var{c}}
12461 @item @code{void __MSUBACCS (acc, acc)}
12462 @tab @code{__MSUBACCS (@var{b}, @var{a})}
12463 @tab @code{MSUBACCS @var{a},@var{b}}
12464 @item @code{sw1 __MSUBHSS (sw1, sw1)}
12465 @tab @code{@var{c} = __MSUBHSS (@var{a}, @var{b})}
12466 @tab @code{MSUBHSS @var{a},@var{b},@var{c}}
12467 @item @code{uw1 __MSUBHUS (uw1, uw1)}
12468 @tab @code{@var{c} = __MSUBHUS (@var{a}, @var{b})}
12469 @tab @code{MSUBHUS @var{a},@var{b},@var{c}}
12470 @item @code{void __MTRAP (void)}
12471 @tab @code{__MTRAP ()}
12472 @tab @code{MTRAP}
12473 @item @code{uw2 __MUNPACKH (uw1)}
12474 @tab @code{@var{b} = __MUNPACKH (@var{a})}
12475 @tab @code{MUNPACKH @var{a},@var{b}}
12476 @item @code{uw1 __MWCUT (uw2, uw1)}
12477 @tab @code{@var{c} = __MWCUT (@var{a}, @var{b})}
12478 @tab @code{MWCUT @var{a},@var{b},@var{c}}
12479 @item @code{void __MWTACC (acc, uw1)}
12480 @tab @code{__MWTACC (@var{b}, @var{a})}
12481 @tab @code{MWTACC @var{a},@var{b}}
12482 @item @code{void __MWTACCG (acc, uw1)}
12483 @tab @code{__MWTACCG (@var{b}, @var{a})}
12484 @tab @code{MWTACCG @var{a},@var{b}}
12485 @item @code{uw1 __MXOR (uw1, uw1)}
12486 @tab @code{@var{c} = __MXOR (@var{a}, @var{b})}
12487 @tab @code{MXOR @var{a},@var{b},@var{c}}
12488 @end multitable
12489
12490 @node Raw read/write Functions
12491 @subsubsection Raw Read/Write Functions
12492
12493 This sections describes built-in functions related to read and write
12494 instructions to access memory. These functions generate
12495 @code{membar} instructions to flush the I/O load and stores where
12496 appropriate, as described in Fujitsu's manual described above.
12497
12498 @table @code
12499
12500 @item unsigned char __builtin_read8 (void *@var{data})
12501 @item unsigned short __builtin_read16 (void *@var{data})
12502 @item unsigned long __builtin_read32 (void *@var{data})
12503 @item unsigned long long __builtin_read64 (void *@var{data})
12504
12505 @item void __builtin_write8 (void *@var{data}, unsigned char @var{datum})
12506 @item void __builtin_write16 (void *@var{data}, unsigned short @var{datum})
12507 @item void __builtin_write32 (void *@var{data}, unsigned long @var{datum})
12508 @item void __builtin_write64 (void *@var{data}, unsigned long long @var{datum})
12509 @end table
12510
12511 @node Other Built-in Functions
12512 @subsubsection Other Built-in Functions
12513
12514 This section describes built-in functions that are not named after
12515 a specific FR-V instruction.
12516
12517 @table @code
12518 @item sw2 __IACCreadll (iacc @var{reg})
12519 Return the full 64-bit value of IACC0@. The @var{reg} argument is reserved
12520 for future expansion and must be 0.
12521
12522 @item sw1 __IACCreadl (iacc @var{reg})
12523 Return the value of IACC0H if @var{reg} is 0 and IACC0L if @var{reg} is 1.
12524 Other values of @var{reg} are rejected as invalid.
12525
12526 @item void __IACCsetll (iacc @var{reg}, sw2 @var{x})
12527 Set the full 64-bit value of IACC0 to @var{x}. The @var{reg} argument
12528 is reserved for future expansion and must be 0.
12529
12530 @item void __IACCsetl (iacc @var{reg}, sw1 @var{x})
12531 Set IACC0H to @var{x} if @var{reg} is 0 and IACC0L to @var{x} if @var{reg}
12532 is 1. Other values of @var{reg} are rejected as invalid.
12533
12534 @item void __data_prefetch0 (const void *@var{x})
12535 Use the @code{dcpl} instruction to load the contents of address @var{x}
12536 into the data cache.
12537
12538 @item void __data_prefetch (const void *@var{x})
12539 Use the @code{nldub} instruction to load the contents of address @var{x}
12540 into the data cache. The instruction is issued in slot I1@.
12541 @end table
12542
12543 @node MIPS DSP Built-in Functions
12544 @subsection MIPS DSP Built-in Functions
12545
12546 The MIPS DSP Application-Specific Extension (ASE) includes new
12547 instructions that are designed to improve the performance of DSP and
12548 media applications. It provides instructions that operate on packed
12549 8-bit/16-bit integer data, Q7, Q15 and Q31 fractional data.
12550
12551 GCC supports MIPS DSP operations using both the generic
12552 vector extensions (@pxref{Vector Extensions}) and a collection of
12553 MIPS-specific built-in functions. Both kinds of support are
12554 enabled by the @option{-mdsp} command-line option.
12555
12556 Revision 2 of the ASE was introduced in the second half of 2006.
12557 This revision adds extra instructions to the original ASE, but is
12558 otherwise backwards-compatible with it. You can select revision 2
12559 using the command-line option @option{-mdspr2}; this option implies
12560 @option{-mdsp}.
12561
12562 The SCOUNT and POS bits of the DSP control register are global. The
12563 WRDSP, EXTPDP, EXTPDPV and MTHLIP instructions modify the SCOUNT and
12564 POS bits. During optimization, the compiler does not delete these
12565 instructions and it does not delete calls to functions containing
12566 these instructions.
12567
12568 At present, GCC only provides support for operations on 32-bit
12569 vectors. The vector type associated with 8-bit integer data is
12570 usually called @code{v4i8}, the vector type associated with Q7
12571 is usually called @code{v4q7}, the vector type associated with 16-bit
12572 integer data is usually called @code{v2i16}, and the vector type
12573 associated with Q15 is usually called @code{v2q15}. They can be
12574 defined in C as follows:
12575
12576 @smallexample
12577 typedef signed char v4i8 __attribute__ ((vector_size(4)));
12578 typedef signed char v4q7 __attribute__ ((vector_size(4)));
12579 typedef short v2i16 __attribute__ ((vector_size(4)));
12580 typedef short v2q15 __attribute__ ((vector_size(4)));
12581 @end smallexample
12582
12583 @code{v4i8}, @code{v4q7}, @code{v2i16} and @code{v2q15} values are
12584 initialized in the same way as aggregates. For example:
12585
12586 @smallexample
12587 v4i8 a = @{1, 2, 3, 4@};
12588 v4i8 b;
12589 b = (v4i8) @{5, 6, 7, 8@};
12590
12591 v2q15 c = @{0x0fcb, 0x3a75@};
12592 v2q15 d;
12593 d = (v2q15) @{0.1234 * 0x1.0p15, 0.4567 * 0x1.0p15@};
12594 @end smallexample
12595
12596 @emph{Note:} The CPU's endianness determines the order in which values
12597 are packed. On little-endian targets, the first value is the least
12598 significant and the last value is the most significant. The opposite
12599 order applies to big-endian targets. For example, the code above
12600 sets the lowest byte of @code{a} to @code{1} on little-endian targets
12601 and @code{4} on big-endian targets.
12602
12603 @emph{Note:} Q7, Q15 and Q31 values must be initialized with their integer
12604 representation. As shown in this example, the integer representation
12605 of a Q7 value can be obtained by multiplying the fractional value by
12606 @code{0x1.0p7}. The equivalent for Q15 values is to multiply by
12607 @code{0x1.0p15}. The equivalent for Q31 values is to multiply by
12608 @code{0x1.0p31}.
12609
12610 The table below lists the @code{v4i8} and @code{v2q15} operations for which
12611 hardware support exists. @code{a} and @code{b} are @code{v4i8} values,
12612 and @code{c} and @code{d} are @code{v2q15} values.
12613
12614 @multitable @columnfractions .50 .50
12615 @item C code @tab MIPS instruction
12616 @item @code{a + b} @tab @code{addu.qb}
12617 @item @code{c + d} @tab @code{addq.ph}
12618 @item @code{a - b} @tab @code{subu.qb}
12619 @item @code{c - d} @tab @code{subq.ph}
12620 @end multitable
12621
12622 The table below lists the @code{v2i16} operation for which
12623 hardware support exists for the DSP ASE REV 2. @code{e} and @code{f} are
12624 @code{v2i16} values.
12625
12626 @multitable @columnfractions .50 .50
12627 @item C code @tab MIPS instruction
12628 @item @code{e * f} @tab @code{mul.ph}
12629 @end multitable
12630
12631 It is easier to describe the DSP built-in functions if we first define
12632 the following types:
12633
12634 @smallexample
12635 typedef int q31;
12636 typedef int i32;
12637 typedef unsigned int ui32;
12638 typedef long long a64;
12639 @end smallexample
12640
12641 @code{q31} and @code{i32} are actually the same as @code{int}, but we
12642 use @code{q31} to indicate a Q31 fractional value and @code{i32} to
12643 indicate a 32-bit integer value. Similarly, @code{a64} is the same as
12644 @code{long long}, but we use @code{a64} to indicate values that are
12645 placed in one of the four DSP accumulators (@code{$ac0},
12646 @code{$ac1}, @code{$ac2} or @code{$ac3}).
12647
12648 Also, some built-in functions prefer or require immediate numbers as
12649 parameters, because the corresponding DSP instructions accept both immediate
12650 numbers and register operands, or accept immediate numbers only. The
12651 immediate parameters are listed as follows.
12652
12653 @smallexample
12654 imm0_3: 0 to 3.
12655 imm0_7: 0 to 7.
12656 imm0_15: 0 to 15.
12657 imm0_31: 0 to 31.
12658 imm0_63: 0 to 63.
12659 imm0_255: 0 to 255.
12660 imm_n32_31: -32 to 31.
12661 imm_n512_511: -512 to 511.
12662 @end smallexample
12663
12664 The following built-in functions map directly to a particular MIPS DSP
12665 instruction. Please refer to the architecture specification
12666 for details on what each instruction does.
12667
12668 @smallexample
12669 v2q15 __builtin_mips_addq_ph (v2q15, v2q15)
12670 v2q15 __builtin_mips_addq_s_ph (v2q15, v2q15)
12671 q31 __builtin_mips_addq_s_w (q31, q31)
12672 v4i8 __builtin_mips_addu_qb (v4i8, v4i8)
12673 v4i8 __builtin_mips_addu_s_qb (v4i8, v4i8)
12674 v2q15 __builtin_mips_subq_ph (v2q15, v2q15)
12675 v2q15 __builtin_mips_subq_s_ph (v2q15, v2q15)
12676 q31 __builtin_mips_subq_s_w (q31, q31)
12677 v4i8 __builtin_mips_subu_qb (v4i8, v4i8)
12678 v4i8 __builtin_mips_subu_s_qb (v4i8, v4i8)
12679 i32 __builtin_mips_addsc (i32, i32)
12680 i32 __builtin_mips_addwc (i32, i32)
12681 i32 __builtin_mips_modsub (i32, i32)
12682 i32 __builtin_mips_raddu_w_qb (v4i8)
12683 v2q15 __builtin_mips_absq_s_ph (v2q15)
12684 q31 __builtin_mips_absq_s_w (q31)
12685 v4i8 __builtin_mips_precrq_qb_ph (v2q15, v2q15)
12686 v2q15 __builtin_mips_precrq_ph_w (q31, q31)
12687 v2q15 __builtin_mips_precrq_rs_ph_w (q31, q31)
12688 v4i8 __builtin_mips_precrqu_s_qb_ph (v2q15, v2q15)
12689 q31 __builtin_mips_preceq_w_phl (v2q15)
12690 q31 __builtin_mips_preceq_w_phr (v2q15)
12691 v2q15 __builtin_mips_precequ_ph_qbl (v4i8)
12692 v2q15 __builtin_mips_precequ_ph_qbr (v4i8)
12693 v2q15 __builtin_mips_precequ_ph_qbla (v4i8)
12694 v2q15 __builtin_mips_precequ_ph_qbra (v4i8)
12695 v2q15 __builtin_mips_preceu_ph_qbl (v4i8)
12696 v2q15 __builtin_mips_preceu_ph_qbr (v4i8)
12697 v2q15 __builtin_mips_preceu_ph_qbla (v4i8)
12698 v2q15 __builtin_mips_preceu_ph_qbra (v4i8)
12699 v4i8 __builtin_mips_shll_qb (v4i8, imm0_7)
12700 v4i8 __builtin_mips_shll_qb (v4i8, i32)
12701 v2q15 __builtin_mips_shll_ph (v2q15, imm0_15)
12702 v2q15 __builtin_mips_shll_ph (v2q15, i32)
12703 v2q15 __builtin_mips_shll_s_ph (v2q15, imm0_15)
12704 v2q15 __builtin_mips_shll_s_ph (v2q15, i32)
12705 q31 __builtin_mips_shll_s_w (q31, imm0_31)
12706 q31 __builtin_mips_shll_s_w (q31, i32)
12707 v4i8 __builtin_mips_shrl_qb (v4i8, imm0_7)
12708 v4i8 __builtin_mips_shrl_qb (v4i8, i32)
12709 v2q15 __builtin_mips_shra_ph (v2q15, imm0_15)
12710 v2q15 __builtin_mips_shra_ph (v2q15, i32)
12711 v2q15 __builtin_mips_shra_r_ph (v2q15, imm0_15)
12712 v2q15 __builtin_mips_shra_r_ph (v2q15, i32)
12713 q31 __builtin_mips_shra_r_w (q31, imm0_31)
12714 q31 __builtin_mips_shra_r_w (q31, i32)
12715 v2q15 __builtin_mips_muleu_s_ph_qbl (v4i8, v2q15)
12716 v2q15 __builtin_mips_muleu_s_ph_qbr (v4i8, v2q15)
12717 v2q15 __builtin_mips_mulq_rs_ph (v2q15, v2q15)
12718 q31 __builtin_mips_muleq_s_w_phl (v2q15, v2q15)
12719 q31 __builtin_mips_muleq_s_w_phr (v2q15, v2q15)
12720 a64 __builtin_mips_dpau_h_qbl (a64, v4i8, v4i8)
12721 a64 __builtin_mips_dpau_h_qbr (a64, v4i8, v4i8)
12722 a64 __builtin_mips_dpsu_h_qbl (a64, v4i8, v4i8)
12723 a64 __builtin_mips_dpsu_h_qbr (a64, v4i8, v4i8)
12724 a64 __builtin_mips_dpaq_s_w_ph (a64, v2q15, v2q15)
12725 a64 __builtin_mips_dpaq_sa_l_w (a64, q31, q31)
12726 a64 __builtin_mips_dpsq_s_w_ph (a64, v2q15, v2q15)
12727 a64 __builtin_mips_dpsq_sa_l_w (a64, q31, q31)
12728 a64 __builtin_mips_mulsaq_s_w_ph (a64, v2q15, v2q15)
12729 a64 __builtin_mips_maq_s_w_phl (a64, v2q15, v2q15)
12730 a64 __builtin_mips_maq_s_w_phr (a64, v2q15, v2q15)
12731 a64 __builtin_mips_maq_sa_w_phl (a64, v2q15, v2q15)
12732 a64 __builtin_mips_maq_sa_w_phr (a64, v2q15, v2q15)
12733 i32 __builtin_mips_bitrev (i32)
12734 i32 __builtin_mips_insv (i32, i32)
12735 v4i8 __builtin_mips_repl_qb (imm0_255)
12736 v4i8 __builtin_mips_repl_qb (i32)
12737 v2q15 __builtin_mips_repl_ph (imm_n512_511)
12738 v2q15 __builtin_mips_repl_ph (i32)
12739 void __builtin_mips_cmpu_eq_qb (v4i8, v4i8)
12740 void __builtin_mips_cmpu_lt_qb (v4i8, v4i8)
12741 void __builtin_mips_cmpu_le_qb (v4i8, v4i8)
12742 i32 __builtin_mips_cmpgu_eq_qb (v4i8, v4i8)
12743 i32 __builtin_mips_cmpgu_lt_qb (v4i8, v4i8)
12744 i32 __builtin_mips_cmpgu_le_qb (v4i8, v4i8)
12745 void __builtin_mips_cmp_eq_ph (v2q15, v2q15)
12746 void __builtin_mips_cmp_lt_ph (v2q15, v2q15)
12747 void __builtin_mips_cmp_le_ph (v2q15, v2q15)
12748 v4i8 __builtin_mips_pick_qb (v4i8, v4i8)
12749 v2q15 __builtin_mips_pick_ph (v2q15, v2q15)
12750 v2q15 __builtin_mips_packrl_ph (v2q15, v2q15)
12751 i32 __builtin_mips_extr_w (a64, imm0_31)
12752 i32 __builtin_mips_extr_w (a64, i32)
12753 i32 __builtin_mips_extr_r_w (a64, imm0_31)
12754 i32 __builtin_mips_extr_s_h (a64, i32)
12755 i32 __builtin_mips_extr_rs_w (a64, imm0_31)
12756 i32 __builtin_mips_extr_rs_w (a64, i32)
12757 i32 __builtin_mips_extr_s_h (a64, imm0_31)
12758 i32 __builtin_mips_extr_r_w (a64, i32)
12759 i32 __builtin_mips_extp (a64, imm0_31)
12760 i32 __builtin_mips_extp (a64, i32)
12761 i32 __builtin_mips_extpdp (a64, imm0_31)
12762 i32 __builtin_mips_extpdp (a64, i32)
12763 a64 __builtin_mips_shilo (a64, imm_n32_31)
12764 a64 __builtin_mips_shilo (a64, i32)
12765 a64 __builtin_mips_mthlip (a64, i32)
12766 void __builtin_mips_wrdsp (i32, imm0_63)
12767 i32 __builtin_mips_rddsp (imm0_63)
12768 i32 __builtin_mips_lbux (void *, i32)
12769 i32 __builtin_mips_lhx (void *, i32)
12770 i32 __builtin_mips_lwx (void *, i32)
12771 a64 __builtin_mips_ldx (void *, i32) [MIPS64 only]
12772 i32 __builtin_mips_bposge32 (void)
12773 a64 __builtin_mips_madd (a64, i32, i32);
12774 a64 __builtin_mips_maddu (a64, ui32, ui32);
12775 a64 __builtin_mips_msub (a64, i32, i32);
12776 a64 __builtin_mips_msubu (a64, ui32, ui32);
12777 a64 __builtin_mips_mult (i32, i32);
12778 a64 __builtin_mips_multu (ui32, ui32);
12779 @end smallexample
12780
12781 The following built-in functions map directly to a particular MIPS DSP REV 2
12782 instruction. Please refer to the architecture specification
12783 for details on what each instruction does.
12784
12785 @smallexample
12786 v4q7 __builtin_mips_absq_s_qb (v4q7);
12787 v2i16 __builtin_mips_addu_ph (v2i16, v2i16);
12788 v2i16 __builtin_mips_addu_s_ph (v2i16, v2i16);
12789 v4i8 __builtin_mips_adduh_qb (v4i8, v4i8);
12790 v4i8 __builtin_mips_adduh_r_qb (v4i8, v4i8);
12791 i32 __builtin_mips_append (i32, i32, imm0_31);
12792 i32 __builtin_mips_balign (i32, i32, imm0_3);
12793 i32 __builtin_mips_cmpgdu_eq_qb (v4i8, v4i8);
12794 i32 __builtin_mips_cmpgdu_lt_qb (v4i8, v4i8);
12795 i32 __builtin_mips_cmpgdu_le_qb (v4i8, v4i8);
12796 a64 __builtin_mips_dpa_w_ph (a64, v2i16, v2i16);
12797 a64 __builtin_mips_dps_w_ph (a64, v2i16, v2i16);
12798 v2i16 __builtin_mips_mul_ph (v2i16, v2i16);
12799 v2i16 __builtin_mips_mul_s_ph (v2i16, v2i16);
12800 q31 __builtin_mips_mulq_rs_w (q31, q31);
12801 v2q15 __builtin_mips_mulq_s_ph (v2q15, v2q15);
12802 q31 __builtin_mips_mulq_s_w (q31, q31);
12803 a64 __builtin_mips_mulsa_w_ph (a64, v2i16, v2i16);
12804 v4i8 __builtin_mips_precr_qb_ph (v2i16, v2i16);
12805 v2i16 __builtin_mips_precr_sra_ph_w (i32, i32, imm0_31);
12806 v2i16 __builtin_mips_precr_sra_r_ph_w (i32, i32, imm0_31);
12807 i32 __builtin_mips_prepend (i32, i32, imm0_31);
12808 v4i8 __builtin_mips_shra_qb (v4i8, imm0_7);
12809 v4i8 __builtin_mips_shra_r_qb (v4i8, imm0_7);
12810 v4i8 __builtin_mips_shra_qb (v4i8, i32);
12811 v4i8 __builtin_mips_shra_r_qb (v4i8, i32);
12812 v2i16 __builtin_mips_shrl_ph (v2i16, imm0_15);
12813 v2i16 __builtin_mips_shrl_ph (v2i16, i32);
12814 v2i16 __builtin_mips_subu_ph (v2i16, v2i16);
12815 v2i16 __builtin_mips_subu_s_ph (v2i16, v2i16);
12816 v4i8 __builtin_mips_subuh_qb (v4i8, v4i8);
12817 v4i8 __builtin_mips_subuh_r_qb (v4i8, v4i8);
12818 v2q15 __builtin_mips_addqh_ph (v2q15, v2q15);
12819 v2q15 __builtin_mips_addqh_r_ph (v2q15, v2q15);
12820 q31 __builtin_mips_addqh_w (q31, q31);
12821 q31 __builtin_mips_addqh_r_w (q31, q31);
12822 v2q15 __builtin_mips_subqh_ph (v2q15, v2q15);
12823 v2q15 __builtin_mips_subqh_r_ph (v2q15, v2q15);
12824 q31 __builtin_mips_subqh_w (q31, q31);
12825 q31 __builtin_mips_subqh_r_w (q31, q31);
12826 a64 __builtin_mips_dpax_w_ph (a64, v2i16, v2i16);
12827 a64 __builtin_mips_dpsx_w_ph (a64, v2i16, v2i16);
12828 a64 __builtin_mips_dpaqx_s_w_ph (a64, v2q15, v2q15);
12829 a64 __builtin_mips_dpaqx_sa_w_ph (a64, v2q15, v2q15);
12830 a64 __builtin_mips_dpsqx_s_w_ph (a64, v2q15, v2q15);
12831 a64 __builtin_mips_dpsqx_sa_w_ph (a64, v2q15, v2q15);
12832 @end smallexample
12833
12834
12835 @node MIPS Paired-Single Support
12836 @subsection MIPS Paired-Single Support
12837
12838 The MIPS64 architecture includes a number of instructions that
12839 operate on pairs of single-precision floating-point values.
12840 Each pair is packed into a 64-bit floating-point register,
12841 with one element being designated the ``upper half'' and
12842 the other being designated the ``lower half''.
12843
12844 GCC supports paired-single operations using both the generic
12845 vector extensions (@pxref{Vector Extensions}) and a collection of
12846 MIPS-specific built-in functions. Both kinds of support are
12847 enabled by the @option{-mpaired-single} command-line option.
12848
12849 The vector type associated with paired-single values is usually
12850 called @code{v2sf}. It can be defined in C as follows:
12851
12852 @smallexample
12853 typedef float v2sf __attribute__ ((vector_size (8)));
12854 @end smallexample
12855
12856 @code{v2sf} values are initialized in the same way as aggregates.
12857 For example:
12858
12859 @smallexample
12860 v2sf a = @{1.5, 9.1@};
12861 v2sf b;
12862 float e, f;
12863 b = (v2sf) @{e, f@};
12864 @end smallexample
12865
12866 @emph{Note:} The CPU's endianness determines which value is stored in
12867 the upper half of a register and which value is stored in the lower half.
12868 On little-endian targets, the first value is the lower one and the second
12869 value is the upper one. The opposite order applies to big-endian targets.
12870 For example, the code above sets the lower half of @code{a} to
12871 @code{1.5} on little-endian targets and @code{9.1} on big-endian targets.
12872
12873 @node MIPS Loongson Built-in Functions
12874 @subsection MIPS Loongson Built-in Functions
12875
12876 GCC provides intrinsics to access the SIMD instructions provided by the
12877 ST Microelectronics Loongson-2E and -2F processors. These intrinsics,
12878 available after inclusion of the @code{loongson.h} header file,
12879 operate on the following 64-bit vector types:
12880
12881 @itemize
12882 @item @code{uint8x8_t}, a vector of eight unsigned 8-bit integers;
12883 @item @code{uint16x4_t}, a vector of four unsigned 16-bit integers;
12884 @item @code{uint32x2_t}, a vector of two unsigned 32-bit integers;
12885 @item @code{int8x8_t}, a vector of eight signed 8-bit integers;
12886 @item @code{int16x4_t}, a vector of four signed 16-bit integers;
12887 @item @code{int32x2_t}, a vector of two signed 32-bit integers.
12888 @end itemize
12889
12890 The intrinsics provided are listed below; each is named after the
12891 machine instruction to which it corresponds, with suffixes added as
12892 appropriate to distinguish intrinsics that expand to the same machine
12893 instruction yet have different argument types. Refer to the architecture
12894 documentation for a description of the functionality of each
12895 instruction.
12896
12897 @smallexample
12898 int16x4_t packsswh (int32x2_t s, int32x2_t t);
12899 int8x8_t packsshb (int16x4_t s, int16x4_t t);
12900 uint8x8_t packushb (uint16x4_t s, uint16x4_t t);
12901 uint32x2_t paddw_u (uint32x2_t s, uint32x2_t t);
12902 uint16x4_t paddh_u (uint16x4_t s, uint16x4_t t);
12903 uint8x8_t paddb_u (uint8x8_t s, uint8x8_t t);
12904 int32x2_t paddw_s (int32x2_t s, int32x2_t t);
12905 int16x4_t paddh_s (int16x4_t s, int16x4_t t);
12906 int8x8_t paddb_s (int8x8_t s, int8x8_t t);
12907 uint64_t paddd_u (uint64_t s, uint64_t t);
12908 int64_t paddd_s (int64_t s, int64_t t);
12909 int16x4_t paddsh (int16x4_t s, int16x4_t t);
12910 int8x8_t paddsb (int8x8_t s, int8x8_t t);
12911 uint16x4_t paddush (uint16x4_t s, uint16x4_t t);
12912 uint8x8_t paddusb (uint8x8_t s, uint8x8_t t);
12913 uint64_t pandn_ud (uint64_t s, uint64_t t);
12914 uint32x2_t pandn_uw (uint32x2_t s, uint32x2_t t);
12915 uint16x4_t pandn_uh (uint16x4_t s, uint16x4_t t);
12916 uint8x8_t pandn_ub (uint8x8_t s, uint8x8_t t);
12917 int64_t pandn_sd (int64_t s, int64_t t);
12918 int32x2_t pandn_sw (int32x2_t s, int32x2_t t);
12919 int16x4_t pandn_sh (int16x4_t s, int16x4_t t);
12920 int8x8_t pandn_sb (int8x8_t s, int8x8_t t);
12921 uint16x4_t pavgh (uint16x4_t s, uint16x4_t t);
12922 uint8x8_t pavgb (uint8x8_t s, uint8x8_t t);
12923 uint32x2_t pcmpeqw_u (uint32x2_t s, uint32x2_t t);
12924 uint16x4_t pcmpeqh_u (uint16x4_t s, uint16x4_t t);
12925 uint8x8_t pcmpeqb_u (uint8x8_t s, uint8x8_t t);
12926 int32x2_t pcmpeqw_s (int32x2_t s, int32x2_t t);
12927 int16x4_t pcmpeqh_s (int16x4_t s, int16x4_t t);
12928 int8x8_t pcmpeqb_s (int8x8_t s, int8x8_t t);
12929 uint32x2_t pcmpgtw_u (uint32x2_t s, uint32x2_t t);
12930 uint16x4_t pcmpgth_u (uint16x4_t s, uint16x4_t t);
12931 uint8x8_t pcmpgtb_u (uint8x8_t s, uint8x8_t t);
12932 int32x2_t pcmpgtw_s (int32x2_t s, int32x2_t t);
12933 int16x4_t pcmpgth_s (int16x4_t s, int16x4_t t);
12934 int8x8_t pcmpgtb_s (int8x8_t s, int8x8_t t);
12935 uint16x4_t pextrh_u (uint16x4_t s, int field);
12936 int16x4_t pextrh_s (int16x4_t s, int field);
12937 uint16x4_t pinsrh_0_u (uint16x4_t s, uint16x4_t t);
12938 uint16x4_t pinsrh_1_u (uint16x4_t s, uint16x4_t t);
12939 uint16x4_t pinsrh_2_u (uint16x4_t s, uint16x4_t t);
12940 uint16x4_t pinsrh_3_u (uint16x4_t s, uint16x4_t t);
12941 int16x4_t pinsrh_0_s (int16x4_t s, int16x4_t t);
12942 int16x4_t pinsrh_1_s (int16x4_t s, int16x4_t t);
12943 int16x4_t pinsrh_2_s (int16x4_t s, int16x4_t t);
12944 int16x4_t pinsrh_3_s (int16x4_t s, int16x4_t t);
12945 int32x2_t pmaddhw (int16x4_t s, int16x4_t t);
12946 int16x4_t pmaxsh (int16x4_t s, int16x4_t t);
12947 uint8x8_t pmaxub (uint8x8_t s, uint8x8_t t);
12948 int16x4_t pminsh (int16x4_t s, int16x4_t t);
12949 uint8x8_t pminub (uint8x8_t s, uint8x8_t t);
12950 uint8x8_t pmovmskb_u (uint8x8_t s);
12951 int8x8_t pmovmskb_s (int8x8_t s);
12952 uint16x4_t pmulhuh (uint16x4_t s, uint16x4_t t);
12953 int16x4_t pmulhh (int16x4_t s, int16x4_t t);
12954 int16x4_t pmullh (int16x4_t s, int16x4_t t);
12955 int64_t pmuluw (uint32x2_t s, uint32x2_t t);
12956 uint8x8_t pasubub (uint8x8_t s, uint8x8_t t);
12957 uint16x4_t biadd (uint8x8_t s);
12958 uint16x4_t psadbh (uint8x8_t s, uint8x8_t t);
12959 uint16x4_t pshufh_u (uint16x4_t dest, uint16x4_t s, uint8_t order);
12960 int16x4_t pshufh_s (int16x4_t dest, int16x4_t s, uint8_t order);
12961 uint16x4_t psllh_u (uint16x4_t s, uint8_t amount);
12962 int16x4_t psllh_s (int16x4_t s, uint8_t amount);
12963 uint32x2_t psllw_u (uint32x2_t s, uint8_t amount);
12964 int32x2_t psllw_s (int32x2_t s, uint8_t amount);
12965 uint16x4_t psrlh_u (uint16x4_t s, uint8_t amount);
12966 int16x4_t psrlh_s (int16x4_t s, uint8_t amount);
12967 uint32x2_t psrlw_u (uint32x2_t s, uint8_t amount);
12968 int32x2_t psrlw_s (int32x2_t s, uint8_t amount);
12969 uint16x4_t psrah_u (uint16x4_t s, uint8_t amount);
12970 int16x4_t psrah_s (int16x4_t s, uint8_t amount);
12971 uint32x2_t psraw_u (uint32x2_t s, uint8_t amount);
12972 int32x2_t psraw_s (int32x2_t s, uint8_t amount);
12973 uint32x2_t psubw_u (uint32x2_t s, uint32x2_t t);
12974 uint16x4_t psubh_u (uint16x4_t s, uint16x4_t t);
12975 uint8x8_t psubb_u (uint8x8_t s, uint8x8_t t);
12976 int32x2_t psubw_s (int32x2_t s, int32x2_t t);
12977 int16x4_t psubh_s (int16x4_t s, int16x4_t t);
12978 int8x8_t psubb_s (int8x8_t s, int8x8_t t);
12979 uint64_t psubd_u (uint64_t s, uint64_t t);
12980 int64_t psubd_s (int64_t s, int64_t t);
12981 int16x4_t psubsh (int16x4_t s, int16x4_t t);
12982 int8x8_t psubsb (int8x8_t s, int8x8_t t);
12983 uint16x4_t psubush (uint16x4_t s, uint16x4_t t);
12984 uint8x8_t psubusb (uint8x8_t s, uint8x8_t t);
12985 uint32x2_t punpckhwd_u (uint32x2_t s, uint32x2_t t);
12986 uint16x4_t punpckhhw_u (uint16x4_t s, uint16x4_t t);
12987 uint8x8_t punpckhbh_u (uint8x8_t s, uint8x8_t t);
12988 int32x2_t punpckhwd_s (int32x2_t s, int32x2_t t);
12989 int16x4_t punpckhhw_s (int16x4_t s, int16x4_t t);
12990 int8x8_t punpckhbh_s (int8x8_t s, int8x8_t t);
12991 uint32x2_t punpcklwd_u (uint32x2_t s, uint32x2_t t);
12992 uint16x4_t punpcklhw_u (uint16x4_t s, uint16x4_t t);
12993 uint8x8_t punpcklbh_u (uint8x8_t s, uint8x8_t t);
12994 int32x2_t punpcklwd_s (int32x2_t s, int32x2_t t);
12995 int16x4_t punpcklhw_s (int16x4_t s, int16x4_t t);
12996 int8x8_t punpcklbh_s (int8x8_t s, int8x8_t t);
12997 @end smallexample
12998
12999 @menu
13000 * Paired-Single Arithmetic::
13001 * Paired-Single Built-in Functions::
13002 * MIPS-3D Built-in Functions::
13003 @end menu
13004
13005 @node Paired-Single Arithmetic
13006 @subsubsection Paired-Single Arithmetic
13007
13008 The table below lists the @code{v2sf} operations for which hardware
13009 support exists. @code{a}, @code{b} and @code{c} are @code{v2sf}
13010 values and @code{x} is an integral value.
13011
13012 @multitable @columnfractions .50 .50
13013 @item C code @tab MIPS instruction
13014 @item @code{a + b} @tab @code{add.ps}
13015 @item @code{a - b} @tab @code{sub.ps}
13016 @item @code{-a} @tab @code{neg.ps}
13017 @item @code{a * b} @tab @code{mul.ps}
13018 @item @code{a * b + c} @tab @code{madd.ps}
13019 @item @code{a * b - c} @tab @code{msub.ps}
13020 @item @code{-(a * b + c)} @tab @code{nmadd.ps}
13021 @item @code{-(a * b - c)} @tab @code{nmsub.ps}
13022 @item @code{x ? a : b} @tab @code{movn.ps}/@code{movz.ps}
13023 @end multitable
13024
13025 Note that the multiply-accumulate instructions can be disabled
13026 using the command-line option @code{-mno-fused-madd}.
13027
13028 @node Paired-Single Built-in Functions
13029 @subsubsection Paired-Single Built-in Functions
13030
13031 The following paired-single functions map directly to a particular
13032 MIPS instruction. Please refer to the architecture specification
13033 for details on what each instruction does.
13034
13035 @table @code
13036 @item v2sf __builtin_mips_pll_ps (v2sf, v2sf)
13037 Pair lower lower (@code{pll.ps}).
13038
13039 @item v2sf __builtin_mips_pul_ps (v2sf, v2sf)
13040 Pair upper lower (@code{pul.ps}).
13041
13042 @item v2sf __builtin_mips_plu_ps (v2sf, v2sf)
13043 Pair lower upper (@code{plu.ps}).
13044
13045 @item v2sf __builtin_mips_puu_ps (v2sf, v2sf)
13046 Pair upper upper (@code{puu.ps}).
13047
13048 @item v2sf __builtin_mips_cvt_ps_s (float, float)
13049 Convert pair to paired single (@code{cvt.ps.s}).
13050
13051 @item float __builtin_mips_cvt_s_pl (v2sf)
13052 Convert pair lower to single (@code{cvt.s.pl}).
13053
13054 @item float __builtin_mips_cvt_s_pu (v2sf)
13055 Convert pair upper to single (@code{cvt.s.pu}).
13056
13057 @item v2sf __builtin_mips_abs_ps (v2sf)
13058 Absolute value (@code{abs.ps}).
13059
13060 @item v2sf __builtin_mips_alnv_ps (v2sf, v2sf, int)
13061 Align variable (@code{alnv.ps}).
13062
13063 @emph{Note:} The value of the third parameter must be 0 or 4
13064 modulo 8, otherwise the result is unpredictable. Please read the
13065 instruction description for details.
13066 @end table
13067
13068 The following multi-instruction functions are also available.
13069 In each case, @var{cond} can be any of the 16 floating-point conditions:
13070 @code{f}, @code{un}, @code{eq}, @code{ueq}, @code{olt}, @code{ult},
13071 @code{ole}, @code{ule}, @code{sf}, @code{ngle}, @code{seq}, @code{ngl},
13072 @code{lt}, @code{nge}, @code{le} or @code{ngt}.
13073
13074 @table @code
13075 @item v2sf __builtin_mips_movt_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
13076 @itemx v2sf __builtin_mips_movf_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
13077 Conditional move based on floating-point comparison (@code{c.@var{cond}.ps},
13078 @code{movt.ps}/@code{movf.ps}).
13079
13080 The @code{movt} functions return the value @var{x} computed by:
13081
13082 @smallexample
13083 c.@var{cond}.ps @var{cc},@var{a},@var{b}
13084 mov.ps @var{x},@var{c}
13085 movt.ps @var{x},@var{d},@var{cc}
13086 @end smallexample
13087
13088 The @code{movf} functions are similar but use @code{movf.ps} instead
13089 of @code{movt.ps}.
13090
13091 @item int __builtin_mips_upper_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
13092 @itemx int __builtin_mips_lower_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
13093 Comparison of two paired-single values (@code{c.@var{cond}.ps},
13094 @code{bc1t}/@code{bc1f}).
13095
13096 These functions compare @var{a} and @var{b} using @code{c.@var{cond}.ps}
13097 and return either the upper or lower half of the result. For example:
13098
13099 @smallexample
13100 v2sf a, b;
13101 if (__builtin_mips_upper_c_eq_ps (a, b))
13102 upper_halves_are_equal ();
13103 else
13104 upper_halves_are_unequal ();
13105
13106 if (__builtin_mips_lower_c_eq_ps (a, b))
13107 lower_halves_are_equal ();
13108 else
13109 lower_halves_are_unequal ();
13110 @end smallexample
13111 @end table
13112
13113 @node MIPS-3D Built-in Functions
13114 @subsubsection MIPS-3D Built-in Functions
13115
13116 The MIPS-3D Application-Specific Extension (ASE) includes additional
13117 paired-single instructions that are designed to improve the performance
13118 of 3D graphics operations. Support for these instructions is controlled
13119 by the @option{-mips3d} command-line option.
13120
13121 The functions listed below map directly to a particular MIPS-3D
13122 instruction. Please refer to the architecture specification for
13123 more details on what each instruction does.
13124
13125 @table @code
13126 @item v2sf __builtin_mips_addr_ps (v2sf, v2sf)
13127 Reduction add (@code{addr.ps}).
13128
13129 @item v2sf __builtin_mips_mulr_ps (v2sf, v2sf)
13130 Reduction multiply (@code{mulr.ps}).
13131
13132 @item v2sf __builtin_mips_cvt_pw_ps (v2sf)
13133 Convert paired single to paired word (@code{cvt.pw.ps}).
13134
13135 @item v2sf __builtin_mips_cvt_ps_pw (v2sf)
13136 Convert paired word to paired single (@code{cvt.ps.pw}).
13137
13138 @item float __builtin_mips_recip1_s (float)
13139 @itemx double __builtin_mips_recip1_d (double)
13140 @itemx v2sf __builtin_mips_recip1_ps (v2sf)
13141 Reduced-precision reciprocal (sequence step 1) (@code{recip1.@var{fmt}}).
13142
13143 @item float __builtin_mips_recip2_s (float, float)
13144 @itemx double __builtin_mips_recip2_d (double, double)
13145 @itemx v2sf __builtin_mips_recip2_ps (v2sf, v2sf)
13146 Reduced-precision reciprocal (sequence step 2) (@code{recip2.@var{fmt}}).
13147
13148 @item float __builtin_mips_rsqrt1_s (float)
13149 @itemx double __builtin_mips_rsqrt1_d (double)
13150 @itemx v2sf __builtin_mips_rsqrt1_ps (v2sf)
13151 Reduced-precision reciprocal square root (sequence step 1)
13152 (@code{rsqrt1.@var{fmt}}).
13153
13154 @item float __builtin_mips_rsqrt2_s (float, float)
13155 @itemx double __builtin_mips_rsqrt2_d (double, double)
13156 @itemx v2sf __builtin_mips_rsqrt2_ps (v2sf, v2sf)
13157 Reduced-precision reciprocal square root (sequence step 2)
13158 (@code{rsqrt2.@var{fmt}}).
13159 @end table
13160
13161 The following multi-instruction functions are also available.
13162 In each case, @var{cond} can be any of the 16 floating-point conditions:
13163 @code{f}, @code{un}, @code{eq}, @code{ueq}, @code{olt}, @code{ult},
13164 @code{ole}, @code{ule}, @code{sf}, @code{ngle}, @code{seq},
13165 @code{ngl}, @code{lt}, @code{nge}, @code{le} or @code{ngt}.
13166
13167 @table @code
13168 @item int __builtin_mips_cabs_@var{cond}_s (float @var{a}, float @var{b})
13169 @itemx int __builtin_mips_cabs_@var{cond}_d (double @var{a}, double @var{b})
13170 Absolute comparison of two scalar values (@code{cabs.@var{cond}.@var{fmt}},
13171 @code{bc1t}/@code{bc1f}).
13172
13173 These functions compare @var{a} and @var{b} using @code{cabs.@var{cond}.s}
13174 or @code{cabs.@var{cond}.d} and return the result as a boolean value.
13175 For example:
13176
13177 @smallexample
13178 float a, b;
13179 if (__builtin_mips_cabs_eq_s (a, b))
13180 true ();
13181 else
13182 false ();
13183 @end smallexample
13184
13185 @item int __builtin_mips_upper_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
13186 @itemx int __builtin_mips_lower_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
13187 Absolute comparison of two paired-single values (@code{cabs.@var{cond}.ps},
13188 @code{bc1t}/@code{bc1f}).
13189
13190 These functions compare @var{a} and @var{b} using @code{cabs.@var{cond}.ps}
13191 and return either the upper or lower half of the result. For example:
13192
13193 @smallexample
13194 v2sf a, b;
13195 if (__builtin_mips_upper_cabs_eq_ps (a, b))
13196 upper_halves_are_equal ();
13197 else
13198 upper_halves_are_unequal ();
13199
13200 if (__builtin_mips_lower_cabs_eq_ps (a, b))
13201 lower_halves_are_equal ();
13202 else
13203 lower_halves_are_unequal ();
13204 @end smallexample
13205
13206 @item v2sf __builtin_mips_movt_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
13207 @itemx v2sf __builtin_mips_movf_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
13208 Conditional move based on absolute comparison (@code{cabs.@var{cond}.ps},
13209 @code{movt.ps}/@code{movf.ps}).
13210
13211 The @code{movt} functions return the value @var{x} computed by:
13212
13213 @smallexample
13214 cabs.@var{cond}.ps @var{cc},@var{a},@var{b}
13215 mov.ps @var{x},@var{c}
13216 movt.ps @var{x},@var{d},@var{cc}
13217 @end smallexample
13218
13219 The @code{movf} functions are similar but use @code{movf.ps} instead
13220 of @code{movt.ps}.
13221
13222 @item int __builtin_mips_any_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
13223 @itemx int __builtin_mips_all_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
13224 @itemx int __builtin_mips_any_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
13225 @itemx int __builtin_mips_all_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b})
13226 Comparison of two paired-single values
13227 (@code{c.@var{cond}.ps}/@code{cabs.@var{cond}.ps},
13228 @code{bc1any2t}/@code{bc1any2f}).
13229
13230 These functions compare @var{a} and @var{b} using @code{c.@var{cond}.ps}
13231 or @code{cabs.@var{cond}.ps}. The @code{any} forms return true if either
13232 result is true and the @code{all} forms return true if both results are true.
13233 For example:
13234
13235 @smallexample
13236 v2sf a, b;
13237 if (__builtin_mips_any_c_eq_ps (a, b))
13238 one_is_true ();
13239 else
13240 both_are_false ();
13241
13242 if (__builtin_mips_all_c_eq_ps (a, b))
13243 both_are_true ();
13244 else
13245 one_is_false ();
13246 @end smallexample
13247
13248 @item int __builtin_mips_any_c_@var{cond}_4s (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
13249 @itemx int __builtin_mips_all_c_@var{cond}_4s (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
13250 @itemx int __builtin_mips_any_cabs_@var{cond}_4s (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
13251 @itemx int __builtin_mips_all_cabs_@var{cond}_4s (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d})
13252 Comparison of four paired-single values
13253 (@code{c.@var{cond}.ps}/@code{cabs.@var{cond}.ps},
13254 @code{bc1any4t}/@code{bc1any4f}).
13255
13256 These functions use @code{c.@var{cond}.ps} or @code{cabs.@var{cond}.ps}
13257 to compare @var{a} with @var{b} and to compare @var{c} with @var{d}.
13258 The @code{any} forms return true if any of the four results are true
13259 and the @code{all} forms return true if all four results are true.
13260 For example:
13261
13262 @smallexample
13263 v2sf a, b, c, d;
13264 if (__builtin_mips_any_c_eq_4s (a, b, c, d))
13265 some_are_true ();
13266 else
13267 all_are_false ();
13268
13269 if (__builtin_mips_all_c_eq_4s (a, b, c, d))
13270 all_are_true ();
13271 else
13272 some_are_false ();
13273 @end smallexample
13274 @end table
13275
13276 @node Other MIPS Built-in Functions
13277 @subsection Other MIPS Built-in Functions
13278
13279 GCC provides other MIPS-specific built-in functions:
13280
13281 @table @code
13282 @item void __builtin_mips_cache (int @var{op}, const volatile void *@var{addr})
13283 Insert a @samp{cache} instruction with operands @var{op} and @var{addr}.
13284 GCC defines the preprocessor macro @code{___GCC_HAVE_BUILTIN_MIPS_CACHE}
13285 when this function is available.
13286
13287 @item unsigned int __builtin_mips_get_fcsr (void)
13288 @itemx void __builtin_mips_set_fcsr (unsigned int @var{value})
13289 Get and set the contents of the floating-point control and status register
13290 (FPU control register 31). These functions are only available in hard-float
13291 code but can be called in both MIPS16 and non-MIPS16 contexts.
13292
13293 @code{__builtin_mips_set_fcsr} can be used to change any bit of the
13294 register except the condition codes, which GCC assumes are preserved.
13295 @end table
13296
13297 @node MSP430 Built-in Functions
13298 @subsection MSP430 Built-in Functions
13299
13300 GCC provides a couple of special builtin functions to aid in the
13301 writing of interrupt handlers in C.
13302
13303 @table @code
13304 @item __bic_SR_register_on_exit (int @var{mask})
13305 This clears the indicated bits in the saved copy of the status register
13306 currently residing on the stack. This only works inside interrupt
13307 handlers and the changes to the status register will only take affect
13308 once the handler returns.
13309
13310 @item __bis_SR_register_on_exit (int @var{mask})
13311 This sets the indicated bits in the saved copy of the status register
13312 currently residing on the stack. This only works inside interrupt
13313 handlers and the changes to the status register will only take affect
13314 once the handler returns.
13315
13316 @item __delay_cycles (long long @var{cycles})
13317 This inserts an instruction sequence that takes exactly @var{cycles}
13318 cycles (between 0 and about 17E9) to complete. The inserted sequence
13319 may use jumps, loops, or no-ops, and does not interfere with any other
13320 instructions. Note that @var{cycles} must be a compile-time constant
13321 integer - that is, you must pass a number, not a variable that may be
13322 optimized to a constant later. The number of cycles delayed by this
13323 builtin is exact.
13324 @end table
13325
13326 @node NDS32 Built-in Functions
13327 @subsection NDS32 Built-in Functions
13328
13329 These built-in functions are available for the NDS32 target:
13330
13331 @deftypefn {Built-in Function} void __builtin_nds32_isync (int *@var{addr})
13332 Insert an ISYNC instruction into the instruction stream where
13333 @var{addr} is an instruction address for serialization.
13334 @end deftypefn
13335
13336 @deftypefn {Built-in Function} void __builtin_nds32_isb (void)
13337 Insert an ISB instruction into the instruction stream.
13338 @end deftypefn
13339
13340 @deftypefn {Built-in Function} int __builtin_nds32_mfsr (int @var{sr})
13341 Return the content of a system register which is mapped by @var{sr}.
13342 @end deftypefn
13343
13344 @deftypefn {Built-in Function} int __builtin_nds32_mfusr (int @var{usr})
13345 Return the content of a user space register which is mapped by @var{usr}.
13346 @end deftypefn
13347
13348 @deftypefn {Built-in Function} void __builtin_nds32_mtsr (int @var{value}, int @var{sr})
13349 Move the @var{value} to a system register which is mapped by @var{sr}.
13350 @end deftypefn
13351
13352 @deftypefn {Built-in Function} void __builtin_nds32_mtusr (int @var{value}, int @var{usr})
13353 Move the @var{value} to a user space register which is mapped by @var{usr}.
13354 @end deftypefn
13355
13356 @deftypefn {Built-in Function} void __builtin_nds32_setgie_en (void)
13357 Enable global interrupt.
13358 @end deftypefn
13359
13360 @deftypefn {Built-in Function} void __builtin_nds32_setgie_dis (void)
13361 Disable global interrupt.
13362 @end deftypefn
13363
13364 @node picoChip Built-in Functions
13365 @subsection picoChip Built-in Functions
13366
13367 GCC provides an interface to selected machine instructions from the
13368 picoChip instruction set.
13369
13370 @table @code
13371 @item int __builtin_sbc (int @var{value})
13372 Sign bit count. Return the number of consecutive bits in @var{value}
13373 that have the same value as the sign bit. The result is the number of
13374 leading sign bits minus one, giving the number of redundant sign bits in
13375 @var{value}.
13376
13377 @item int __builtin_byteswap (int @var{value})
13378 Byte swap. Return the result of swapping the upper and lower bytes of
13379 @var{value}.
13380
13381 @item int __builtin_brev (int @var{value})
13382 Bit reversal. Return the result of reversing the bits in
13383 @var{value}. Bit 15 is swapped with bit 0, bit 14 is swapped with bit 1,
13384 and so on.
13385
13386 @item int __builtin_adds (int @var{x}, int @var{y})
13387 Saturating addition. Return the result of adding @var{x} and @var{y},
13388 storing the value 32767 if the result overflows.
13389
13390 @item int __builtin_subs (int @var{x}, int @var{y})
13391 Saturating subtraction. Return the result of subtracting @var{y} from
13392 @var{x}, storing the value @minus{}32768 if the result overflows.
13393
13394 @item void __builtin_halt (void)
13395 Halt. The processor stops execution. This built-in is useful for
13396 implementing assertions.
13397
13398 @end table
13399
13400 @node PowerPC Built-in Functions
13401 @subsection PowerPC Built-in Functions
13402
13403 These built-in functions are available for the PowerPC family of
13404 processors:
13405 @smallexample
13406 float __builtin_recipdivf (float, float);
13407 float __builtin_rsqrtf (float);
13408 double __builtin_recipdiv (double, double);
13409 double __builtin_rsqrt (double);
13410 uint64_t __builtin_ppc_get_timebase ();
13411 unsigned long __builtin_ppc_mftb ();
13412 double __builtin_unpack_longdouble (long double, int);
13413 long double __builtin_pack_longdouble (double, double);
13414 @end smallexample
13415
13416 The @code{vec_rsqrt}, @code{__builtin_rsqrt}, and
13417 @code{__builtin_rsqrtf} functions generate multiple instructions to
13418 implement the reciprocal sqrt functionality using reciprocal sqrt
13419 estimate instructions.
13420
13421 The @code{__builtin_recipdiv}, and @code{__builtin_recipdivf}
13422 functions generate multiple instructions to implement division using
13423 the reciprocal estimate instructions.
13424
13425 The @code{__builtin_ppc_get_timebase} and @code{__builtin_ppc_mftb}
13426 functions generate instructions to read the Time Base Register. The
13427 @code{__builtin_ppc_get_timebase} function may generate multiple
13428 instructions and always returns the 64 bits of the Time Base Register.
13429 The @code{__builtin_ppc_mftb} function always generates one instruction and
13430 returns the Time Base Register value as an unsigned long, throwing away
13431 the most significant word on 32-bit environments.
13432
13433 The following built-in functions are available for the PowerPC family
13434 of processors, starting with ISA 2.06 or later (@option{-mcpu=power7}
13435 or @option{-mpopcntd}):
13436 @smallexample
13437 long __builtin_bpermd (long, long);
13438 int __builtin_divwe (int, int);
13439 int __builtin_divweo (int, int);
13440 unsigned int __builtin_divweu (unsigned int, unsigned int);
13441 unsigned int __builtin_divweuo (unsigned int, unsigned int);
13442 long __builtin_divde (long, long);
13443 long __builtin_divdeo (long, long);
13444 unsigned long __builtin_divdeu (unsigned long, unsigned long);
13445 unsigned long __builtin_divdeuo (unsigned long, unsigned long);
13446 unsigned int cdtbcd (unsigned int);
13447 unsigned int cbcdtd (unsigned int);
13448 unsigned int addg6s (unsigned int, unsigned int);
13449 @end smallexample
13450
13451 The @code{__builtin_divde}, @code{__builtin_divdeo},
13452 @code{__builtin_divdeu}, @code{__builtin_divdeou} functions require a
13453 64-bit environment support ISA 2.06 or later.
13454
13455 The following built-in functions are available for the PowerPC family
13456 of processors when hardware decimal floating point
13457 (@option{-mhard-dfp}) is available:
13458 @smallexample
13459 _Decimal64 __builtin_dxex (_Decimal64);
13460 _Decimal128 __builtin_dxexq (_Decimal128);
13461 _Decimal64 __builtin_ddedpd (int, _Decimal64);
13462 _Decimal128 __builtin_ddedpdq (int, _Decimal128);
13463 _Decimal64 __builtin_denbcd (int, _Decimal64);
13464 _Decimal128 __builtin_denbcdq (int, _Decimal128);
13465 _Decimal64 __builtin_diex (_Decimal64, _Decimal64);
13466 _Decimal128 _builtin_diexq (_Decimal128, _Decimal128);
13467 _Decimal64 __builtin_dscli (_Decimal64, int);
13468 _Decimal128 __builtin_dscliq (_Decimal128, int);
13469 _Decimal64 __builtin_dscri (_Decimal64, int);
13470 _Decimal128 __builtin_dscriq (_Decimal128, int);
13471 unsigned long long __builtin_unpack_dec128 (_Decimal128, int);
13472 _Decimal128 __builtin_pack_dec128 (unsigned long long, unsigned long long);
13473 @end smallexample
13474
13475 The following built-in functions are available for the PowerPC family
13476 of processors when the Vector Scalar (vsx) instruction set is
13477 available:
13478 @smallexample
13479 unsigned long long __builtin_unpack_vector_int128 (vector __int128_t, int);
13480 vector __int128_t __builtin_pack_vector_int128 (unsigned long long,
13481 unsigned long long);
13482 @end smallexample
13483
13484 @node PowerPC AltiVec/VSX Built-in Functions
13485 @subsection PowerPC AltiVec Built-in Functions
13486
13487 GCC provides an interface for the PowerPC family of processors to access
13488 the AltiVec operations described in Motorola's AltiVec Programming
13489 Interface Manual. The interface is made available by including
13490 @code{<altivec.h>} and using @option{-maltivec} and
13491 @option{-mabi=altivec}. The interface supports the following vector
13492 types.
13493
13494 @smallexample
13495 vector unsigned char
13496 vector signed char
13497 vector bool char
13498
13499 vector unsigned short
13500 vector signed short
13501 vector bool short
13502 vector pixel
13503
13504 vector unsigned int
13505 vector signed int
13506 vector bool int
13507 vector float
13508 @end smallexample
13509
13510 If @option{-mvsx} is used the following additional vector types are
13511 implemented.
13512
13513 @smallexample
13514 vector unsigned long
13515 vector signed long
13516 vector double
13517 @end smallexample
13518
13519 The long types are only implemented for 64-bit code generation, and
13520 the long type is only used in the floating point/integer conversion
13521 instructions.
13522
13523 GCC's implementation of the high-level language interface available from
13524 C and C++ code differs from Motorola's documentation in several ways.
13525
13526 @itemize @bullet
13527
13528 @item
13529 A vector constant is a list of constant expressions within curly braces.
13530
13531 @item
13532 A vector initializer requires no cast if the vector constant is of the
13533 same type as the variable it is initializing.
13534
13535 @item
13536 If @code{signed} or @code{unsigned} is omitted, the signedness of the
13537 vector type is the default signedness of the base type. The default
13538 varies depending on the operating system, so a portable program should
13539 always specify the signedness.
13540
13541 @item
13542 Compiling with @option{-maltivec} adds keywords @code{__vector},
13543 @code{vector}, @code{__pixel}, @code{pixel}, @code{__bool} and
13544 @code{bool}. When compiling ISO C, the context-sensitive substitution
13545 of the keywords @code{vector}, @code{pixel} and @code{bool} is
13546 disabled. To use them, you must include @code{<altivec.h>} instead.
13547
13548 @item
13549 GCC allows using a @code{typedef} name as the type specifier for a
13550 vector type.
13551
13552 @item
13553 For C, overloaded functions are implemented with macros so the following
13554 does not work:
13555
13556 @smallexample
13557 vec_add ((vector signed int)@{1, 2, 3, 4@}, foo);
13558 @end smallexample
13559
13560 @noindent
13561 Since @code{vec_add} is a macro, the vector constant in the example
13562 is treated as four separate arguments. Wrap the entire argument in
13563 parentheses for this to work.
13564 @end itemize
13565
13566 @emph{Note:} Only the @code{<altivec.h>} interface is supported.
13567 Internally, GCC uses built-in functions to achieve the functionality in
13568 the aforementioned header file, but they are not supported and are
13569 subject to change without notice.
13570
13571 The following interfaces are supported for the generic and specific
13572 AltiVec operations and the AltiVec predicates. In cases where there
13573 is a direct mapping between generic and specific operations, only the
13574 generic names are shown here, although the specific operations can also
13575 be used.
13576
13577 Arguments that are documented as @code{const int} require literal
13578 integral values within the range required for that operation.
13579
13580 @smallexample
13581 vector signed char vec_abs (vector signed char);
13582 vector signed short vec_abs (vector signed short);
13583 vector signed int vec_abs (vector signed int);
13584 vector float vec_abs (vector float);
13585
13586 vector signed char vec_abss (vector signed char);
13587 vector signed short vec_abss (vector signed short);
13588 vector signed int vec_abss (vector signed int);
13589
13590 vector signed char vec_add (vector bool char, vector signed char);
13591 vector signed char vec_add (vector signed char, vector bool char);
13592 vector signed char vec_add (vector signed char, vector signed char);
13593 vector unsigned char vec_add (vector bool char, vector unsigned char);
13594 vector unsigned char vec_add (vector unsigned char, vector bool char);
13595 vector unsigned char vec_add (vector unsigned char,
13596 vector unsigned char);
13597 vector signed short vec_add (vector bool short, vector signed short);
13598 vector signed short vec_add (vector signed short, vector bool short);
13599 vector signed short vec_add (vector signed short, vector signed short);
13600 vector unsigned short vec_add (vector bool short,
13601 vector unsigned short);
13602 vector unsigned short vec_add (vector unsigned short,
13603 vector bool short);
13604 vector unsigned short vec_add (vector unsigned short,
13605 vector unsigned short);
13606 vector signed int vec_add (vector bool int, vector signed int);
13607 vector signed int vec_add (vector signed int, vector bool int);
13608 vector signed int vec_add (vector signed int, vector signed int);
13609 vector unsigned int vec_add (vector bool int, vector unsigned int);
13610 vector unsigned int vec_add (vector unsigned int, vector bool int);
13611 vector unsigned int vec_add (vector unsigned int, vector unsigned int);
13612 vector float vec_add (vector float, vector float);
13613
13614 vector float vec_vaddfp (vector float, vector float);
13615
13616 vector signed int vec_vadduwm (vector bool int, vector signed int);
13617 vector signed int vec_vadduwm (vector signed int, vector bool int);
13618 vector signed int vec_vadduwm (vector signed int, vector signed int);
13619 vector unsigned int vec_vadduwm (vector bool int, vector unsigned int);
13620 vector unsigned int vec_vadduwm (vector unsigned int, vector bool int);
13621 vector unsigned int vec_vadduwm (vector unsigned int,
13622 vector unsigned int);
13623
13624 vector signed short vec_vadduhm (vector bool short,
13625 vector signed short);
13626 vector signed short vec_vadduhm (vector signed short,
13627 vector bool short);
13628 vector signed short vec_vadduhm (vector signed short,
13629 vector signed short);
13630 vector unsigned short vec_vadduhm (vector bool short,
13631 vector unsigned short);
13632 vector unsigned short vec_vadduhm (vector unsigned short,
13633 vector bool short);
13634 vector unsigned short vec_vadduhm (vector unsigned short,
13635 vector unsigned short);
13636
13637 vector signed char vec_vaddubm (vector bool char, vector signed char);
13638 vector signed char vec_vaddubm (vector signed char, vector bool char);
13639 vector signed char vec_vaddubm (vector signed char, vector signed char);
13640 vector unsigned char vec_vaddubm (vector bool char,
13641 vector unsigned char);
13642 vector unsigned char vec_vaddubm (vector unsigned char,
13643 vector bool char);
13644 vector unsigned char vec_vaddubm (vector unsigned char,
13645 vector unsigned char);
13646
13647 vector unsigned int vec_addc (vector unsigned int, vector unsigned int);
13648
13649 vector unsigned char vec_adds (vector bool char, vector unsigned char);
13650 vector unsigned char vec_adds (vector unsigned char, vector bool char);
13651 vector unsigned char vec_adds (vector unsigned char,
13652 vector unsigned char);
13653 vector signed char vec_adds (vector bool char, vector signed char);
13654 vector signed char vec_adds (vector signed char, vector bool char);
13655 vector signed char vec_adds (vector signed char, vector signed char);
13656 vector unsigned short vec_adds (vector bool short,
13657 vector unsigned short);
13658 vector unsigned short vec_adds (vector unsigned short,
13659 vector bool short);
13660 vector unsigned short vec_adds (vector unsigned short,
13661 vector unsigned short);
13662 vector signed short vec_adds (vector bool short, vector signed short);
13663 vector signed short vec_adds (vector signed short, vector bool short);
13664 vector signed short vec_adds (vector signed short, vector signed short);
13665 vector unsigned int vec_adds (vector bool int, vector unsigned int);
13666 vector unsigned int vec_adds (vector unsigned int, vector bool int);
13667 vector unsigned int vec_adds (vector unsigned int, vector unsigned int);
13668 vector signed int vec_adds (vector bool int, vector signed int);
13669 vector signed int vec_adds (vector signed int, vector bool int);
13670 vector signed int vec_adds (vector signed int, vector signed int);
13671
13672 vector signed int vec_vaddsws (vector bool int, vector signed int);
13673 vector signed int vec_vaddsws (vector signed int, vector bool int);
13674 vector signed int vec_vaddsws (vector signed int, vector signed int);
13675
13676 vector unsigned int vec_vadduws (vector bool int, vector unsigned int);
13677 vector unsigned int vec_vadduws (vector unsigned int, vector bool int);
13678 vector unsigned int vec_vadduws (vector unsigned int,
13679 vector unsigned int);
13680
13681 vector signed short vec_vaddshs (vector bool short,
13682 vector signed short);
13683 vector signed short vec_vaddshs (vector signed short,
13684 vector bool short);
13685 vector signed short vec_vaddshs (vector signed short,
13686 vector signed short);
13687
13688 vector unsigned short vec_vadduhs (vector bool short,
13689 vector unsigned short);
13690 vector unsigned short vec_vadduhs (vector unsigned short,
13691 vector bool short);
13692 vector unsigned short vec_vadduhs (vector unsigned short,
13693 vector unsigned short);
13694
13695 vector signed char vec_vaddsbs (vector bool char, vector signed char);
13696 vector signed char vec_vaddsbs (vector signed char, vector bool char);
13697 vector signed char vec_vaddsbs (vector signed char, vector signed char);
13698
13699 vector unsigned char vec_vaddubs (vector bool char,
13700 vector unsigned char);
13701 vector unsigned char vec_vaddubs (vector unsigned char,
13702 vector bool char);
13703 vector unsigned char vec_vaddubs (vector unsigned char,
13704 vector unsigned char);
13705
13706 vector float vec_and (vector float, vector float);
13707 vector float vec_and (vector float, vector bool int);
13708 vector float vec_and (vector bool int, vector float);
13709 vector bool int vec_and (vector bool int, vector bool int);
13710 vector signed int vec_and (vector bool int, vector signed int);
13711 vector signed int vec_and (vector signed int, vector bool int);
13712 vector signed int vec_and (vector signed int, vector signed int);
13713 vector unsigned int vec_and (vector bool int, vector unsigned int);
13714 vector unsigned int vec_and (vector unsigned int, vector bool int);
13715 vector unsigned int vec_and (vector unsigned int, vector unsigned int);
13716 vector bool short vec_and (vector bool short, vector bool short);
13717 vector signed short vec_and (vector bool short, vector signed short);
13718 vector signed short vec_and (vector signed short, vector bool short);
13719 vector signed short vec_and (vector signed short, vector signed short);
13720 vector unsigned short vec_and (vector bool short,
13721 vector unsigned short);
13722 vector unsigned short vec_and (vector unsigned short,
13723 vector bool short);
13724 vector unsigned short vec_and (vector unsigned short,
13725 vector unsigned short);
13726 vector signed char vec_and (vector bool char, vector signed char);
13727 vector bool char vec_and (vector bool char, vector bool char);
13728 vector signed char vec_and (vector signed char, vector bool char);
13729 vector signed char vec_and (vector signed char, vector signed char);
13730 vector unsigned char vec_and (vector bool char, vector unsigned char);
13731 vector unsigned char vec_and (vector unsigned char, vector bool char);
13732 vector unsigned char vec_and (vector unsigned char,
13733 vector unsigned char);
13734
13735 vector float vec_andc (vector float, vector float);
13736 vector float vec_andc (vector float, vector bool int);
13737 vector float vec_andc (vector bool int, vector float);
13738 vector bool int vec_andc (vector bool int, vector bool int);
13739 vector signed int vec_andc (vector bool int, vector signed int);
13740 vector signed int vec_andc (vector signed int, vector bool int);
13741 vector signed int vec_andc (vector signed int, vector signed int);
13742 vector unsigned int vec_andc (vector bool int, vector unsigned int);
13743 vector unsigned int vec_andc (vector unsigned int, vector bool int);
13744 vector unsigned int vec_andc (vector unsigned int, vector unsigned int);
13745 vector bool short vec_andc (vector bool short, vector bool short);
13746 vector signed short vec_andc (vector bool short, vector signed short);
13747 vector signed short vec_andc (vector signed short, vector bool short);
13748 vector signed short vec_andc (vector signed short, vector signed short);
13749 vector unsigned short vec_andc (vector bool short,
13750 vector unsigned short);
13751 vector unsigned short vec_andc (vector unsigned short,
13752 vector bool short);
13753 vector unsigned short vec_andc (vector unsigned short,
13754 vector unsigned short);
13755 vector signed char vec_andc (vector bool char, vector signed char);
13756 vector bool char vec_andc (vector bool char, vector bool char);
13757 vector signed char vec_andc (vector signed char, vector bool char);
13758 vector signed char vec_andc (vector signed char, vector signed char);
13759 vector unsigned char vec_andc (vector bool char, vector unsigned char);
13760 vector unsigned char vec_andc (vector unsigned char, vector bool char);
13761 vector unsigned char vec_andc (vector unsigned char,
13762 vector unsigned char);
13763
13764 vector unsigned char vec_avg (vector unsigned char,
13765 vector unsigned char);
13766 vector signed char vec_avg (vector signed char, vector signed char);
13767 vector unsigned short vec_avg (vector unsigned short,
13768 vector unsigned short);
13769 vector signed short vec_avg (vector signed short, vector signed short);
13770 vector unsigned int vec_avg (vector unsigned int, vector unsigned int);
13771 vector signed int vec_avg (vector signed int, vector signed int);
13772
13773 vector signed int vec_vavgsw (vector signed int, vector signed int);
13774
13775 vector unsigned int vec_vavguw (vector unsigned int,
13776 vector unsigned int);
13777
13778 vector signed short vec_vavgsh (vector signed short,
13779 vector signed short);
13780
13781 vector unsigned short vec_vavguh (vector unsigned short,
13782 vector unsigned short);
13783
13784 vector signed char vec_vavgsb (vector signed char, vector signed char);
13785
13786 vector unsigned char vec_vavgub (vector unsigned char,
13787 vector unsigned char);
13788
13789 vector float vec_copysign (vector float);
13790
13791 vector float vec_ceil (vector float);
13792
13793 vector signed int vec_cmpb (vector float, vector float);
13794
13795 vector bool char vec_cmpeq (vector signed char, vector signed char);
13796 vector bool char vec_cmpeq (vector unsigned char, vector unsigned char);
13797 vector bool short vec_cmpeq (vector signed short, vector signed short);
13798 vector bool short vec_cmpeq (vector unsigned short,
13799 vector unsigned short);
13800 vector bool int vec_cmpeq (vector signed int, vector signed int);
13801 vector bool int vec_cmpeq (vector unsigned int, vector unsigned int);
13802 vector bool int vec_cmpeq (vector float, vector float);
13803
13804 vector bool int vec_vcmpeqfp (vector float, vector float);
13805
13806 vector bool int vec_vcmpequw (vector signed int, vector signed int);
13807 vector bool int vec_vcmpequw (vector unsigned int, vector unsigned int);
13808
13809 vector bool short vec_vcmpequh (vector signed short,
13810 vector signed short);
13811 vector bool short vec_vcmpequh (vector unsigned short,
13812 vector unsigned short);
13813
13814 vector bool char vec_vcmpequb (vector signed char, vector signed char);
13815 vector bool char vec_vcmpequb (vector unsigned char,
13816 vector unsigned char);
13817
13818 vector bool int vec_cmpge (vector float, vector float);
13819
13820 vector bool char vec_cmpgt (vector unsigned char, vector unsigned char);
13821 vector bool char vec_cmpgt (vector signed char, vector signed char);
13822 vector bool short vec_cmpgt (vector unsigned short,
13823 vector unsigned short);
13824 vector bool short vec_cmpgt (vector signed short, vector signed short);
13825 vector bool int vec_cmpgt (vector unsigned int, vector unsigned int);
13826 vector bool int vec_cmpgt (vector signed int, vector signed int);
13827 vector bool int vec_cmpgt (vector float, vector float);
13828
13829 vector bool int vec_vcmpgtfp (vector float, vector float);
13830
13831 vector bool int vec_vcmpgtsw (vector signed int, vector signed int);
13832
13833 vector bool int vec_vcmpgtuw (vector unsigned int, vector unsigned int);
13834
13835 vector bool short vec_vcmpgtsh (vector signed short,
13836 vector signed short);
13837
13838 vector bool short vec_vcmpgtuh (vector unsigned short,
13839 vector unsigned short);
13840
13841 vector bool char vec_vcmpgtsb (vector signed char, vector signed char);
13842
13843 vector bool char vec_vcmpgtub (vector unsigned char,
13844 vector unsigned char);
13845
13846 vector bool int vec_cmple (vector float, vector float);
13847
13848 vector bool char vec_cmplt (vector unsigned char, vector unsigned char);
13849 vector bool char vec_cmplt (vector signed char, vector signed char);
13850 vector bool short vec_cmplt (vector unsigned short,
13851 vector unsigned short);
13852 vector bool short vec_cmplt (vector signed short, vector signed short);
13853 vector bool int vec_cmplt (vector unsigned int, vector unsigned int);
13854 vector bool int vec_cmplt (vector signed int, vector signed int);
13855 vector bool int vec_cmplt (vector float, vector float);
13856
13857 vector float vec_cpsgn (vector float, vector float);
13858
13859 vector float vec_ctf (vector unsigned int, const int);
13860 vector float vec_ctf (vector signed int, const int);
13861 vector double vec_ctf (vector unsigned long, const int);
13862 vector double vec_ctf (vector signed long, const int);
13863
13864 vector float vec_vcfsx (vector signed int, const int);
13865
13866 vector float vec_vcfux (vector unsigned int, const int);
13867
13868 vector signed int vec_cts (vector float, const int);
13869 vector signed long vec_cts (vector double, const int);
13870
13871 vector unsigned int vec_ctu (vector float, const int);
13872 vector unsigned long vec_ctu (vector double, const int);
13873
13874 void vec_dss (const int);
13875
13876 void vec_dssall (void);
13877
13878 void vec_dst (const vector unsigned char *, int, const int);
13879 void vec_dst (const vector signed char *, int, const int);
13880 void vec_dst (const vector bool char *, int, const int);
13881 void vec_dst (const vector unsigned short *, int, const int);
13882 void vec_dst (const vector signed short *, int, const int);
13883 void vec_dst (const vector bool short *, int, const int);
13884 void vec_dst (const vector pixel *, int, const int);
13885 void vec_dst (const vector unsigned int *, int, const int);
13886 void vec_dst (const vector signed int *, int, const int);
13887 void vec_dst (const vector bool int *, int, const int);
13888 void vec_dst (const vector float *, int, const int);
13889 void vec_dst (const unsigned char *, int, const int);
13890 void vec_dst (const signed char *, int, const int);
13891 void vec_dst (const unsigned short *, int, const int);
13892 void vec_dst (const short *, int, const int);
13893 void vec_dst (const unsigned int *, int, const int);
13894 void vec_dst (const int *, int, const int);
13895 void vec_dst (const unsigned long *, int, const int);
13896 void vec_dst (const long *, int, const int);
13897 void vec_dst (const float *, int, const int);
13898
13899 void vec_dstst (const vector unsigned char *, int, const int);
13900 void vec_dstst (const vector signed char *, int, const int);
13901 void vec_dstst (const vector bool char *, int, const int);
13902 void vec_dstst (const vector unsigned short *, int, const int);
13903 void vec_dstst (const vector signed short *, int, const int);
13904 void vec_dstst (const vector bool short *, int, const int);
13905 void vec_dstst (const vector pixel *, int, const int);
13906 void vec_dstst (const vector unsigned int *, int, const int);
13907 void vec_dstst (const vector signed int *, int, const int);
13908 void vec_dstst (const vector bool int *, int, const int);
13909 void vec_dstst (const vector float *, int, const int);
13910 void vec_dstst (const unsigned char *, int, const int);
13911 void vec_dstst (const signed char *, int, const int);
13912 void vec_dstst (const unsigned short *, int, const int);
13913 void vec_dstst (const short *, int, const int);
13914 void vec_dstst (const unsigned int *, int, const int);
13915 void vec_dstst (const int *, int, const int);
13916 void vec_dstst (const unsigned long *, int, const int);
13917 void vec_dstst (const long *, int, const int);
13918 void vec_dstst (const float *, int, const int);
13919
13920 void vec_dststt (const vector unsigned char *, int, const int);
13921 void vec_dststt (const vector signed char *, int, const int);
13922 void vec_dststt (const vector bool char *, int, const int);
13923 void vec_dststt (const vector unsigned short *, int, const int);
13924 void vec_dststt (const vector signed short *, int, const int);
13925 void vec_dststt (const vector bool short *, int, const int);
13926 void vec_dststt (const vector pixel *, int, const int);
13927 void vec_dststt (const vector unsigned int *, int, const int);
13928 void vec_dststt (const vector signed int *, int, const int);
13929 void vec_dststt (const vector bool int *, int, const int);
13930 void vec_dststt (const vector float *, int, const int);
13931 void vec_dststt (const unsigned char *, int, const int);
13932 void vec_dststt (const signed char *, int, const int);
13933 void vec_dststt (const unsigned short *, int, const int);
13934 void vec_dststt (const short *, int, const int);
13935 void vec_dststt (const unsigned int *, int, const int);
13936 void vec_dststt (const int *, int, const int);
13937 void vec_dststt (const unsigned long *, int, const int);
13938 void vec_dststt (const long *, int, const int);
13939 void vec_dststt (const float *, int, const int);
13940
13941 void vec_dstt (const vector unsigned char *, int, const int);
13942 void vec_dstt (const vector signed char *, int, const int);
13943 void vec_dstt (const vector bool char *, int, const int);
13944 void vec_dstt (const vector unsigned short *, int, const int);
13945 void vec_dstt (const vector signed short *, int, const int);
13946 void vec_dstt (const vector bool short *, int, const int);
13947 void vec_dstt (const vector pixel *, int, const int);
13948 void vec_dstt (const vector unsigned int *, int, const int);
13949 void vec_dstt (const vector signed int *, int, const int);
13950 void vec_dstt (const vector bool int *, int, const int);
13951 void vec_dstt (const vector float *, int, const int);
13952 void vec_dstt (const unsigned char *, int, const int);
13953 void vec_dstt (const signed char *, int, const int);
13954 void vec_dstt (const unsigned short *, int, const int);
13955 void vec_dstt (const short *, int, const int);
13956 void vec_dstt (const unsigned int *, int, const int);
13957 void vec_dstt (const int *, int, const int);
13958 void vec_dstt (const unsigned long *, int, const int);
13959 void vec_dstt (const long *, int, const int);
13960 void vec_dstt (const float *, int, const int);
13961
13962 vector float vec_expte (vector float);
13963
13964 vector float vec_floor (vector float);
13965
13966 vector float vec_ld (int, const vector float *);
13967 vector float vec_ld (int, const float *);
13968 vector bool int vec_ld (int, const vector bool int *);
13969 vector signed int vec_ld (int, const vector signed int *);
13970 vector signed int vec_ld (int, const int *);
13971 vector signed int vec_ld (int, const long *);
13972 vector unsigned int vec_ld (int, const vector unsigned int *);
13973 vector unsigned int vec_ld (int, const unsigned int *);
13974 vector unsigned int vec_ld (int, const unsigned long *);
13975 vector bool short vec_ld (int, const vector bool short *);
13976 vector pixel vec_ld (int, const vector pixel *);
13977 vector signed short vec_ld (int, const vector signed short *);
13978 vector signed short vec_ld (int, const short *);
13979 vector unsigned short vec_ld (int, const vector unsigned short *);
13980 vector unsigned short vec_ld (int, const unsigned short *);
13981 vector bool char vec_ld (int, const vector bool char *);
13982 vector signed char vec_ld (int, const vector signed char *);
13983 vector signed char vec_ld (int, const signed char *);
13984 vector unsigned char vec_ld (int, const vector unsigned char *);
13985 vector unsigned char vec_ld (int, const unsigned char *);
13986
13987 vector signed char vec_lde (int, const signed char *);
13988 vector unsigned char vec_lde (int, const unsigned char *);
13989 vector signed short vec_lde (int, const short *);
13990 vector unsigned short vec_lde (int, const unsigned short *);
13991 vector float vec_lde (int, const float *);
13992 vector signed int vec_lde (int, const int *);
13993 vector unsigned int vec_lde (int, const unsigned int *);
13994 vector signed int vec_lde (int, const long *);
13995 vector unsigned int vec_lde (int, const unsigned long *);
13996
13997 vector float vec_lvewx (int, float *);
13998 vector signed int vec_lvewx (int, int *);
13999 vector unsigned int vec_lvewx (int, unsigned int *);
14000 vector signed int vec_lvewx (int, long *);
14001 vector unsigned int vec_lvewx (int, unsigned long *);
14002
14003 vector signed short vec_lvehx (int, short *);
14004 vector unsigned short vec_lvehx (int, unsigned short *);
14005
14006 vector signed char vec_lvebx (int, char *);
14007 vector unsigned char vec_lvebx (int, unsigned char *);
14008
14009 vector float vec_ldl (int, const vector float *);
14010 vector float vec_ldl (int, const float *);
14011 vector bool int vec_ldl (int, const vector bool int *);
14012 vector signed int vec_ldl (int, const vector signed int *);
14013 vector signed int vec_ldl (int, const int *);
14014 vector signed int vec_ldl (int, const long *);
14015 vector unsigned int vec_ldl (int, const vector unsigned int *);
14016 vector unsigned int vec_ldl (int, const unsigned int *);
14017 vector unsigned int vec_ldl (int, const unsigned long *);
14018 vector bool short vec_ldl (int, const vector bool short *);
14019 vector pixel vec_ldl (int, const vector pixel *);
14020 vector signed short vec_ldl (int, const vector signed short *);
14021 vector signed short vec_ldl (int, const short *);
14022 vector unsigned short vec_ldl (int, const vector unsigned short *);
14023 vector unsigned short vec_ldl (int, const unsigned short *);
14024 vector bool char vec_ldl (int, const vector bool char *);
14025 vector signed char vec_ldl (int, const vector signed char *);
14026 vector signed char vec_ldl (int, const signed char *);
14027 vector unsigned char vec_ldl (int, const vector unsigned char *);
14028 vector unsigned char vec_ldl (int, const unsigned char *);
14029
14030 vector float vec_loge (vector float);
14031
14032 vector unsigned char vec_lvsl (int, const volatile unsigned char *);
14033 vector unsigned char vec_lvsl (int, const volatile signed char *);
14034 vector unsigned char vec_lvsl (int, const volatile unsigned short *);
14035 vector unsigned char vec_lvsl (int, const volatile short *);
14036 vector unsigned char vec_lvsl (int, const volatile unsigned int *);
14037 vector unsigned char vec_lvsl (int, const volatile int *);
14038 vector unsigned char vec_lvsl (int, const volatile unsigned long *);
14039 vector unsigned char vec_lvsl (int, const volatile long *);
14040 vector unsigned char vec_lvsl (int, const volatile float *);
14041
14042 vector unsigned char vec_lvsr (int, const volatile unsigned char *);
14043 vector unsigned char vec_lvsr (int, const volatile signed char *);
14044 vector unsigned char vec_lvsr (int, const volatile unsigned short *);
14045 vector unsigned char vec_lvsr (int, const volatile short *);
14046 vector unsigned char vec_lvsr (int, const volatile unsigned int *);
14047 vector unsigned char vec_lvsr (int, const volatile int *);
14048 vector unsigned char vec_lvsr (int, const volatile unsigned long *);
14049 vector unsigned char vec_lvsr (int, const volatile long *);
14050 vector unsigned char vec_lvsr (int, const volatile float *);
14051
14052 vector float vec_madd (vector float, vector float, vector float);
14053
14054 vector signed short vec_madds (vector signed short,
14055 vector signed short,
14056 vector signed short);
14057
14058 vector unsigned char vec_max (vector bool char, vector unsigned char);
14059 vector unsigned char vec_max (vector unsigned char, vector bool char);
14060 vector unsigned char vec_max (vector unsigned char,
14061 vector unsigned char);
14062 vector signed char vec_max (vector bool char, vector signed char);
14063 vector signed char vec_max (vector signed char, vector bool char);
14064 vector signed char vec_max (vector signed char, vector signed char);
14065 vector unsigned short vec_max (vector bool short,
14066 vector unsigned short);
14067 vector unsigned short vec_max (vector unsigned short,
14068 vector bool short);
14069 vector unsigned short vec_max (vector unsigned short,
14070 vector unsigned short);
14071 vector signed short vec_max (vector bool short, vector signed short);
14072 vector signed short vec_max (vector signed short, vector bool short);
14073 vector signed short vec_max (vector signed short, vector signed short);
14074 vector unsigned int vec_max (vector bool int, vector unsigned int);
14075 vector unsigned int vec_max (vector unsigned int, vector bool int);
14076 vector unsigned int vec_max (vector unsigned int, vector unsigned int);
14077 vector signed int vec_max (vector bool int, vector signed int);
14078 vector signed int vec_max (vector signed int, vector bool int);
14079 vector signed int vec_max (vector signed int, vector signed int);
14080 vector float vec_max (vector float, vector float);
14081
14082 vector float vec_vmaxfp (vector float, vector float);
14083
14084 vector signed int vec_vmaxsw (vector bool int, vector signed int);
14085 vector signed int vec_vmaxsw (vector signed int, vector bool int);
14086 vector signed int vec_vmaxsw (vector signed int, vector signed int);
14087
14088 vector unsigned int vec_vmaxuw (vector bool int, vector unsigned int);
14089 vector unsigned int vec_vmaxuw (vector unsigned int, vector bool int);
14090 vector unsigned int vec_vmaxuw (vector unsigned int,
14091 vector unsigned int);
14092
14093 vector signed short vec_vmaxsh (vector bool short, vector signed short);
14094 vector signed short vec_vmaxsh (vector signed short, vector bool short);
14095 vector signed short vec_vmaxsh (vector signed short,
14096 vector signed short);
14097
14098 vector unsigned short vec_vmaxuh (vector bool short,
14099 vector unsigned short);
14100 vector unsigned short vec_vmaxuh (vector unsigned short,
14101 vector bool short);
14102 vector unsigned short vec_vmaxuh (vector unsigned short,
14103 vector unsigned short);
14104
14105 vector signed char vec_vmaxsb (vector bool char, vector signed char);
14106 vector signed char vec_vmaxsb (vector signed char, vector bool char);
14107 vector signed char vec_vmaxsb (vector signed char, vector signed char);
14108
14109 vector unsigned char vec_vmaxub (vector bool char,
14110 vector unsigned char);
14111 vector unsigned char vec_vmaxub (vector unsigned char,
14112 vector bool char);
14113 vector unsigned char vec_vmaxub (vector unsigned char,
14114 vector unsigned char);
14115
14116 vector bool char vec_mergeh (vector bool char, vector bool char);
14117 vector signed char vec_mergeh (vector signed char, vector signed char);
14118 vector unsigned char vec_mergeh (vector unsigned char,
14119 vector unsigned char);
14120 vector bool short vec_mergeh (vector bool short, vector bool short);
14121 vector pixel vec_mergeh (vector pixel, vector pixel);
14122 vector signed short vec_mergeh (vector signed short,
14123 vector signed short);
14124 vector unsigned short vec_mergeh (vector unsigned short,
14125 vector unsigned short);
14126 vector float vec_mergeh (vector float, vector float);
14127 vector bool int vec_mergeh (vector bool int, vector bool int);
14128 vector signed int vec_mergeh (vector signed int, vector signed int);
14129 vector unsigned int vec_mergeh (vector unsigned int,
14130 vector unsigned int);
14131
14132 vector float vec_vmrghw (vector float, vector float);
14133 vector bool int vec_vmrghw (vector bool int, vector bool int);
14134 vector signed int vec_vmrghw (vector signed int, vector signed int);
14135 vector unsigned int vec_vmrghw (vector unsigned int,
14136 vector unsigned int);
14137
14138 vector bool short vec_vmrghh (vector bool short, vector bool short);
14139 vector signed short vec_vmrghh (vector signed short,
14140 vector signed short);
14141 vector unsigned short vec_vmrghh (vector unsigned short,
14142 vector unsigned short);
14143 vector pixel vec_vmrghh (vector pixel, vector pixel);
14144
14145 vector bool char vec_vmrghb (vector bool char, vector bool char);
14146 vector signed char vec_vmrghb (vector signed char, vector signed char);
14147 vector unsigned char vec_vmrghb (vector unsigned char,
14148 vector unsigned char);
14149
14150 vector bool char vec_mergel (vector bool char, vector bool char);
14151 vector signed char vec_mergel (vector signed char, vector signed char);
14152 vector unsigned char vec_mergel (vector unsigned char,
14153 vector unsigned char);
14154 vector bool short vec_mergel (vector bool short, vector bool short);
14155 vector pixel vec_mergel (vector pixel, vector pixel);
14156 vector signed short vec_mergel (vector signed short,
14157 vector signed short);
14158 vector unsigned short vec_mergel (vector unsigned short,
14159 vector unsigned short);
14160 vector float vec_mergel (vector float, vector float);
14161 vector bool int vec_mergel (vector bool int, vector bool int);
14162 vector signed int vec_mergel (vector signed int, vector signed int);
14163 vector unsigned int vec_mergel (vector unsigned int,
14164 vector unsigned int);
14165
14166 vector float vec_vmrglw (vector float, vector float);
14167 vector signed int vec_vmrglw (vector signed int, vector signed int);
14168 vector unsigned int vec_vmrglw (vector unsigned int,
14169 vector unsigned int);
14170 vector bool int vec_vmrglw (vector bool int, vector bool int);
14171
14172 vector bool short vec_vmrglh (vector bool short, vector bool short);
14173 vector signed short vec_vmrglh (vector signed short,
14174 vector signed short);
14175 vector unsigned short vec_vmrglh (vector unsigned short,
14176 vector unsigned short);
14177 vector pixel vec_vmrglh (vector pixel, vector pixel);
14178
14179 vector bool char vec_vmrglb (vector bool char, vector bool char);
14180 vector signed char vec_vmrglb (vector signed char, vector signed char);
14181 vector unsigned char vec_vmrglb (vector unsigned char,
14182 vector unsigned char);
14183
14184 vector unsigned short vec_mfvscr (void);
14185
14186 vector unsigned char vec_min (vector bool char, vector unsigned char);
14187 vector unsigned char vec_min (vector unsigned char, vector bool char);
14188 vector unsigned char vec_min (vector unsigned char,
14189 vector unsigned char);
14190 vector signed char vec_min (vector bool char, vector signed char);
14191 vector signed char vec_min (vector signed char, vector bool char);
14192 vector signed char vec_min (vector signed char, vector signed char);
14193 vector unsigned short vec_min (vector bool short,
14194 vector unsigned short);
14195 vector unsigned short vec_min (vector unsigned short,
14196 vector bool short);
14197 vector unsigned short vec_min (vector unsigned short,
14198 vector unsigned short);
14199 vector signed short vec_min (vector bool short, vector signed short);
14200 vector signed short vec_min (vector signed short, vector bool short);
14201 vector signed short vec_min (vector signed short, vector signed short);
14202 vector unsigned int vec_min (vector bool int, vector unsigned int);
14203 vector unsigned int vec_min (vector unsigned int, vector bool int);
14204 vector unsigned int vec_min (vector unsigned int, vector unsigned int);
14205 vector signed int vec_min (vector bool int, vector signed int);
14206 vector signed int vec_min (vector signed int, vector bool int);
14207 vector signed int vec_min (vector signed int, vector signed int);
14208 vector float vec_min (vector float, vector float);
14209
14210 vector float vec_vminfp (vector float, vector float);
14211
14212 vector signed int vec_vminsw (vector bool int, vector signed int);
14213 vector signed int vec_vminsw (vector signed int, vector bool int);
14214 vector signed int vec_vminsw (vector signed int, vector signed int);
14215
14216 vector unsigned int vec_vminuw (vector bool int, vector unsigned int);
14217 vector unsigned int vec_vminuw (vector unsigned int, vector bool int);
14218 vector unsigned int vec_vminuw (vector unsigned int,
14219 vector unsigned int);
14220
14221 vector signed short vec_vminsh (vector bool short, vector signed short);
14222 vector signed short vec_vminsh (vector signed short, vector bool short);
14223 vector signed short vec_vminsh (vector signed short,
14224 vector signed short);
14225
14226 vector unsigned short vec_vminuh (vector bool short,
14227 vector unsigned short);
14228 vector unsigned short vec_vminuh (vector unsigned short,
14229 vector bool short);
14230 vector unsigned short vec_vminuh (vector unsigned short,
14231 vector unsigned short);
14232
14233 vector signed char vec_vminsb (vector bool char, vector signed char);
14234 vector signed char vec_vminsb (vector signed char, vector bool char);
14235 vector signed char vec_vminsb (vector signed char, vector signed char);
14236
14237 vector unsigned char vec_vminub (vector bool char,
14238 vector unsigned char);
14239 vector unsigned char vec_vminub (vector unsigned char,
14240 vector bool char);
14241 vector unsigned char vec_vminub (vector unsigned char,
14242 vector unsigned char);
14243
14244 vector signed short vec_mladd (vector signed short,
14245 vector signed short,
14246 vector signed short);
14247 vector signed short vec_mladd (vector signed short,
14248 vector unsigned short,
14249 vector unsigned short);
14250 vector signed short vec_mladd (vector unsigned short,
14251 vector signed short,
14252 vector signed short);
14253 vector unsigned short vec_mladd (vector unsigned short,
14254 vector unsigned short,
14255 vector unsigned short);
14256
14257 vector signed short vec_mradds (vector signed short,
14258 vector signed short,
14259 vector signed short);
14260
14261 vector unsigned int vec_msum (vector unsigned char,
14262 vector unsigned char,
14263 vector unsigned int);
14264 vector signed int vec_msum (vector signed char,
14265 vector unsigned char,
14266 vector signed int);
14267 vector unsigned int vec_msum (vector unsigned short,
14268 vector unsigned short,
14269 vector unsigned int);
14270 vector signed int vec_msum (vector signed short,
14271 vector signed short,
14272 vector signed int);
14273
14274 vector signed int vec_vmsumshm (vector signed short,
14275 vector signed short,
14276 vector signed int);
14277
14278 vector unsigned int vec_vmsumuhm (vector unsigned short,
14279 vector unsigned short,
14280 vector unsigned int);
14281
14282 vector signed int vec_vmsummbm (vector signed char,
14283 vector unsigned char,
14284 vector signed int);
14285
14286 vector unsigned int vec_vmsumubm (vector unsigned char,
14287 vector unsigned char,
14288 vector unsigned int);
14289
14290 vector unsigned int vec_msums (vector unsigned short,
14291 vector unsigned short,
14292 vector unsigned int);
14293 vector signed int vec_msums (vector signed short,
14294 vector signed short,
14295 vector signed int);
14296
14297 vector signed int vec_vmsumshs (vector signed short,
14298 vector signed short,
14299 vector signed int);
14300
14301 vector unsigned int vec_vmsumuhs (vector unsigned short,
14302 vector unsigned short,
14303 vector unsigned int);
14304
14305 void vec_mtvscr (vector signed int);
14306 void vec_mtvscr (vector unsigned int);
14307 void vec_mtvscr (vector bool int);
14308 void vec_mtvscr (vector signed short);
14309 void vec_mtvscr (vector unsigned short);
14310 void vec_mtvscr (vector bool short);
14311 void vec_mtvscr (vector pixel);
14312 void vec_mtvscr (vector signed char);
14313 void vec_mtvscr (vector unsigned char);
14314 void vec_mtvscr (vector bool char);
14315
14316 vector unsigned short vec_mule (vector unsigned char,
14317 vector unsigned char);
14318 vector signed short vec_mule (vector signed char,
14319 vector signed char);
14320 vector unsigned int vec_mule (vector unsigned short,
14321 vector unsigned short);
14322 vector signed int vec_mule (vector signed short, vector signed short);
14323
14324 vector signed int vec_vmulesh (vector signed short,
14325 vector signed short);
14326
14327 vector unsigned int vec_vmuleuh (vector unsigned short,
14328 vector unsigned short);
14329
14330 vector signed short vec_vmulesb (vector signed char,
14331 vector signed char);
14332
14333 vector unsigned short vec_vmuleub (vector unsigned char,
14334 vector unsigned char);
14335
14336 vector unsigned short vec_mulo (vector unsigned char,
14337 vector unsigned char);
14338 vector signed short vec_mulo (vector signed char, vector signed char);
14339 vector unsigned int vec_mulo (vector unsigned short,
14340 vector unsigned short);
14341 vector signed int vec_mulo (vector signed short, vector signed short);
14342
14343 vector signed int vec_vmulosh (vector signed short,
14344 vector signed short);
14345
14346 vector unsigned int vec_vmulouh (vector unsigned short,
14347 vector unsigned short);
14348
14349 vector signed short vec_vmulosb (vector signed char,
14350 vector signed char);
14351
14352 vector unsigned short vec_vmuloub (vector unsigned char,
14353 vector unsigned char);
14354
14355 vector float vec_nmsub (vector float, vector float, vector float);
14356
14357 vector float vec_nor (vector float, vector float);
14358 vector signed int vec_nor (vector signed int, vector signed int);
14359 vector unsigned int vec_nor (vector unsigned int, vector unsigned int);
14360 vector bool int vec_nor (vector bool int, vector bool int);
14361 vector signed short vec_nor (vector signed short, vector signed short);
14362 vector unsigned short vec_nor (vector unsigned short,
14363 vector unsigned short);
14364 vector bool short vec_nor (vector bool short, vector bool short);
14365 vector signed char vec_nor (vector signed char, vector signed char);
14366 vector unsigned char vec_nor (vector unsigned char,
14367 vector unsigned char);
14368 vector bool char vec_nor (vector bool char, vector bool char);
14369
14370 vector float vec_or (vector float, vector float);
14371 vector float vec_or (vector float, vector bool int);
14372 vector float vec_or (vector bool int, vector float);
14373 vector bool int vec_or (vector bool int, vector bool int);
14374 vector signed int vec_or (vector bool int, vector signed int);
14375 vector signed int vec_or (vector signed int, vector bool int);
14376 vector signed int vec_or (vector signed int, vector signed int);
14377 vector unsigned int vec_or (vector bool int, vector unsigned int);
14378 vector unsigned int vec_or (vector unsigned int, vector bool int);
14379 vector unsigned int vec_or (vector unsigned int, vector unsigned int);
14380 vector bool short vec_or (vector bool short, vector bool short);
14381 vector signed short vec_or (vector bool short, vector signed short);
14382 vector signed short vec_or (vector signed short, vector bool short);
14383 vector signed short vec_or (vector signed short, vector signed short);
14384 vector unsigned short vec_or (vector bool short, vector unsigned short);
14385 vector unsigned short vec_or (vector unsigned short, vector bool short);
14386 vector unsigned short vec_or (vector unsigned short,
14387 vector unsigned short);
14388 vector signed char vec_or (vector bool char, vector signed char);
14389 vector bool char vec_or (vector bool char, vector bool char);
14390 vector signed char vec_or (vector signed char, vector bool char);
14391 vector signed char vec_or (vector signed char, vector signed char);
14392 vector unsigned char vec_or (vector bool char, vector unsigned char);
14393 vector unsigned char vec_or (vector unsigned char, vector bool char);
14394 vector unsigned char vec_or (vector unsigned char,
14395 vector unsigned char);
14396
14397 vector signed char vec_pack (vector signed short, vector signed short);
14398 vector unsigned char vec_pack (vector unsigned short,
14399 vector unsigned short);
14400 vector bool char vec_pack (vector bool short, vector bool short);
14401 vector signed short vec_pack (vector signed int, vector signed int);
14402 vector unsigned short vec_pack (vector unsigned int,
14403 vector unsigned int);
14404 vector bool short vec_pack (vector bool int, vector bool int);
14405
14406 vector bool short vec_vpkuwum (vector bool int, vector bool int);
14407 vector signed short vec_vpkuwum (vector signed int, vector signed int);
14408 vector unsigned short vec_vpkuwum (vector unsigned int,
14409 vector unsigned int);
14410
14411 vector bool char vec_vpkuhum (vector bool short, vector bool short);
14412 vector signed char vec_vpkuhum (vector signed short,
14413 vector signed short);
14414 vector unsigned char vec_vpkuhum (vector unsigned short,
14415 vector unsigned short);
14416
14417 vector pixel vec_packpx (vector unsigned int, vector unsigned int);
14418
14419 vector unsigned char vec_packs (vector unsigned short,
14420 vector unsigned short);
14421 vector signed char vec_packs (vector signed short, vector signed short);
14422 vector unsigned short vec_packs (vector unsigned int,
14423 vector unsigned int);
14424 vector signed short vec_packs (vector signed int, vector signed int);
14425
14426 vector signed short vec_vpkswss (vector signed int, vector signed int);
14427
14428 vector unsigned short vec_vpkuwus (vector unsigned int,
14429 vector unsigned int);
14430
14431 vector signed char vec_vpkshss (vector signed short,
14432 vector signed short);
14433
14434 vector unsigned char vec_vpkuhus (vector unsigned short,
14435 vector unsigned short);
14436
14437 vector unsigned char vec_packsu (vector unsigned short,
14438 vector unsigned short);
14439 vector unsigned char vec_packsu (vector signed short,
14440 vector signed short);
14441 vector unsigned short vec_packsu (vector unsigned int,
14442 vector unsigned int);
14443 vector unsigned short vec_packsu (vector signed int, vector signed int);
14444
14445 vector unsigned short vec_vpkswus (vector signed int,
14446 vector signed int);
14447
14448 vector unsigned char vec_vpkshus (vector signed short,
14449 vector signed short);
14450
14451 vector float vec_perm (vector float,
14452 vector float,
14453 vector unsigned char);
14454 vector signed int vec_perm (vector signed int,
14455 vector signed int,
14456 vector unsigned char);
14457 vector unsigned int vec_perm (vector unsigned int,
14458 vector unsigned int,
14459 vector unsigned char);
14460 vector bool int vec_perm (vector bool int,
14461 vector bool int,
14462 vector unsigned char);
14463 vector signed short vec_perm (vector signed short,
14464 vector signed short,
14465 vector unsigned char);
14466 vector unsigned short vec_perm (vector unsigned short,
14467 vector unsigned short,
14468 vector unsigned char);
14469 vector bool short vec_perm (vector bool short,
14470 vector bool short,
14471 vector unsigned char);
14472 vector pixel vec_perm (vector pixel,
14473 vector pixel,
14474 vector unsigned char);
14475 vector signed char vec_perm (vector signed char,
14476 vector signed char,
14477 vector unsigned char);
14478 vector unsigned char vec_perm (vector unsigned char,
14479 vector unsigned char,
14480 vector unsigned char);
14481 vector bool char vec_perm (vector bool char,
14482 vector bool char,
14483 vector unsigned char);
14484
14485 vector float vec_re (vector float);
14486
14487 vector signed char vec_rl (vector signed char,
14488 vector unsigned char);
14489 vector unsigned char vec_rl (vector unsigned char,
14490 vector unsigned char);
14491 vector signed short vec_rl (vector signed short, vector unsigned short);
14492 vector unsigned short vec_rl (vector unsigned short,
14493 vector unsigned short);
14494 vector signed int vec_rl (vector signed int, vector unsigned int);
14495 vector unsigned int vec_rl (vector unsigned int, vector unsigned int);
14496
14497 vector signed int vec_vrlw (vector signed int, vector unsigned int);
14498 vector unsigned int vec_vrlw (vector unsigned int, vector unsigned int);
14499
14500 vector signed short vec_vrlh (vector signed short,
14501 vector unsigned short);
14502 vector unsigned short vec_vrlh (vector unsigned short,
14503 vector unsigned short);
14504
14505 vector signed char vec_vrlb (vector signed char, vector unsigned char);
14506 vector unsigned char vec_vrlb (vector unsigned char,
14507 vector unsigned char);
14508
14509 vector float vec_round (vector float);
14510
14511 vector float vec_recip (vector float, vector float);
14512
14513 vector float vec_rsqrt (vector float);
14514
14515 vector float vec_rsqrte (vector float);
14516
14517 vector float vec_sel (vector float, vector float, vector bool int);
14518 vector float vec_sel (vector float, vector float, vector unsigned int);
14519 vector signed int vec_sel (vector signed int,
14520 vector signed int,
14521 vector bool int);
14522 vector signed int vec_sel (vector signed int,
14523 vector signed int,
14524 vector unsigned int);
14525 vector unsigned int vec_sel (vector unsigned int,
14526 vector unsigned int,
14527 vector bool int);
14528 vector unsigned int vec_sel (vector unsigned int,
14529 vector unsigned int,
14530 vector unsigned int);
14531 vector bool int vec_sel (vector bool int,
14532 vector bool int,
14533 vector bool int);
14534 vector bool int vec_sel (vector bool int,
14535 vector bool int,
14536 vector unsigned int);
14537 vector signed short vec_sel (vector signed short,
14538 vector signed short,
14539 vector bool short);
14540 vector signed short vec_sel (vector signed short,
14541 vector signed short,
14542 vector unsigned short);
14543 vector unsigned short vec_sel (vector unsigned short,
14544 vector unsigned short,
14545 vector bool short);
14546 vector unsigned short vec_sel (vector unsigned short,
14547 vector unsigned short,
14548 vector unsigned short);
14549 vector bool short vec_sel (vector bool short,
14550 vector bool short,
14551 vector bool short);
14552 vector bool short vec_sel (vector bool short,
14553 vector bool short,
14554 vector unsigned short);
14555 vector signed char vec_sel (vector signed char,
14556 vector signed char,
14557 vector bool char);
14558 vector signed char vec_sel (vector signed char,
14559 vector signed char,
14560 vector unsigned char);
14561 vector unsigned char vec_sel (vector unsigned char,
14562 vector unsigned char,
14563 vector bool char);
14564 vector unsigned char vec_sel (vector unsigned char,
14565 vector unsigned char,
14566 vector unsigned char);
14567 vector bool char vec_sel (vector bool char,
14568 vector bool char,
14569 vector bool char);
14570 vector bool char vec_sel (vector bool char,
14571 vector bool char,
14572 vector unsigned char);
14573
14574 vector signed char vec_sl (vector signed char,
14575 vector unsigned char);
14576 vector unsigned char vec_sl (vector unsigned char,
14577 vector unsigned char);
14578 vector signed short vec_sl (vector signed short, vector unsigned short);
14579 vector unsigned short vec_sl (vector unsigned short,
14580 vector unsigned short);
14581 vector signed int vec_sl (vector signed int, vector unsigned int);
14582 vector unsigned int vec_sl (vector unsigned int, vector unsigned int);
14583
14584 vector signed int vec_vslw (vector signed int, vector unsigned int);
14585 vector unsigned int vec_vslw (vector unsigned int, vector unsigned int);
14586
14587 vector signed short vec_vslh (vector signed short,
14588 vector unsigned short);
14589 vector unsigned short vec_vslh (vector unsigned short,
14590 vector unsigned short);
14591
14592 vector signed char vec_vslb (vector signed char, vector unsigned char);
14593 vector unsigned char vec_vslb (vector unsigned char,
14594 vector unsigned char);
14595
14596 vector float vec_sld (vector float, vector float, const int);
14597 vector signed int vec_sld (vector signed int,
14598 vector signed int,
14599 const int);
14600 vector unsigned int vec_sld (vector unsigned int,
14601 vector unsigned int,
14602 const int);
14603 vector bool int vec_sld (vector bool int,
14604 vector bool int,
14605 const int);
14606 vector signed short vec_sld (vector signed short,
14607 vector signed short,
14608 const int);
14609 vector unsigned short vec_sld (vector unsigned short,
14610 vector unsigned short,
14611 const int);
14612 vector bool short vec_sld (vector bool short,
14613 vector bool short,
14614 const int);
14615 vector pixel vec_sld (vector pixel,
14616 vector pixel,
14617 const int);
14618 vector signed char vec_sld (vector signed char,
14619 vector signed char,
14620 const int);
14621 vector unsigned char vec_sld (vector unsigned char,
14622 vector unsigned char,
14623 const int);
14624 vector bool char vec_sld (vector bool char,
14625 vector bool char,
14626 const int);
14627
14628 vector signed int vec_sll (vector signed int,
14629 vector unsigned int);
14630 vector signed int vec_sll (vector signed int,
14631 vector unsigned short);
14632 vector signed int vec_sll (vector signed int,
14633 vector unsigned char);
14634 vector unsigned int vec_sll (vector unsigned int,
14635 vector unsigned int);
14636 vector unsigned int vec_sll (vector unsigned int,
14637 vector unsigned short);
14638 vector unsigned int vec_sll (vector unsigned int,
14639 vector unsigned char);
14640 vector bool int vec_sll (vector bool int,
14641 vector unsigned int);
14642 vector bool int vec_sll (vector bool int,
14643 vector unsigned short);
14644 vector bool int vec_sll (vector bool int,
14645 vector unsigned char);
14646 vector signed short vec_sll (vector signed short,
14647 vector unsigned int);
14648 vector signed short vec_sll (vector signed short,
14649 vector unsigned short);
14650 vector signed short vec_sll (vector signed short,
14651 vector unsigned char);
14652 vector unsigned short vec_sll (vector unsigned short,
14653 vector unsigned int);
14654 vector unsigned short vec_sll (vector unsigned short,
14655 vector unsigned short);
14656 vector unsigned short vec_sll (vector unsigned short,
14657 vector unsigned char);
14658 vector bool short vec_sll (vector bool short, vector unsigned int);
14659 vector bool short vec_sll (vector bool short, vector unsigned short);
14660 vector bool short vec_sll (vector bool short, vector unsigned char);
14661 vector pixel vec_sll (vector pixel, vector unsigned int);
14662 vector pixel vec_sll (vector pixel, vector unsigned short);
14663 vector pixel vec_sll (vector pixel, vector unsigned char);
14664 vector signed char vec_sll (vector signed char, vector unsigned int);
14665 vector signed char vec_sll (vector signed char, vector unsigned short);
14666 vector signed char vec_sll (vector signed char, vector unsigned char);
14667 vector unsigned char vec_sll (vector unsigned char,
14668 vector unsigned int);
14669 vector unsigned char vec_sll (vector unsigned char,
14670 vector unsigned short);
14671 vector unsigned char vec_sll (vector unsigned char,
14672 vector unsigned char);
14673 vector bool char vec_sll (vector bool char, vector unsigned int);
14674 vector bool char vec_sll (vector bool char, vector unsigned short);
14675 vector bool char vec_sll (vector bool char, vector unsigned char);
14676
14677 vector float vec_slo (vector float, vector signed char);
14678 vector float vec_slo (vector float, vector unsigned char);
14679 vector signed int vec_slo (vector signed int, vector signed char);
14680 vector signed int vec_slo (vector signed int, vector unsigned char);
14681 vector unsigned int vec_slo (vector unsigned int, vector signed char);
14682 vector unsigned int vec_slo (vector unsigned int, vector unsigned char);
14683 vector signed short vec_slo (vector signed short, vector signed char);
14684 vector signed short vec_slo (vector signed short, vector unsigned char);
14685 vector unsigned short vec_slo (vector unsigned short,
14686 vector signed char);
14687 vector unsigned short vec_slo (vector unsigned short,
14688 vector unsigned char);
14689 vector pixel vec_slo (vector pixel, vector signed char);
14690 vector pixel vec_slo (vector pixel, vector unsigned char);
14691 vector signed char vec_slo (vector signed char, vector signed char);
14692 vector signed char vec_slo (vector signed char, vector unsigned char);
14693 vector unsigned char vec_slo (vector unsigned char, vector signed char);
14694 vector unsigned char vec_slo (vector unsigned char,
14695 vector unsigned char);
14696
14697 vector signed char vec_splat (vector signed char, const int);
14698 vector unsigned char vec_splat (vector unsigned char, const int);
14699 vector bool char vec_splat (vector bool char, const int);
14700 vector signed short vec_splat (vector signed short, const int);
14701 vector unsigned short vec_splat (vector unsigned short, const int);
14702 vector bool short vec_splat (vector bool short, const int);
14703 vector pixel vec_splat (vector pixel, const int);
14704 vector float vec_splat (vector float, const int);
14705 vector signed int vec_splat (vector signed int, const int);
14706 vector unsigned int vec_splat (vector unsigned int, const int);
14707 vector bool int vec_splat (vector bool int, const int);
14708 vector signed long vec_splat (vector signed long, const int);
14709 vector unsigned long vec_splat (vector unsigned long, const int);
14710
14711 vector signed char vec_splats (signed char);
14712 vector unsigned char vec_splats (unsigned char);
14713 vector signed short vec_splats (signed short);
14714 vector unsigned short vec_splats (unsigned short);
14715 vector signed int vec_splats (signed int);
14716 vector unsigned int vec_splats (unsigned int);
14717 vector float vec_splats (float);
14718
14719 vector float vec_vspltw (vector float, const int);
14720 vector signed int vec_vspltw (vector signed int, const int);
14721 vector unsigned int vec_vspltw (vector unsigned int, const int);
14722 vector bool int vec_vspltw (vector bool int, const int);
14723
14724 vector bool short vec_vsplth (vector bool short, const int);
14725 vector signed short vec_vsplth (vector signed short, const int);
14726 vector unsigned short vec_vsplth (vector unsigned short, const int);
14727 vector pixel vec_vsplth (vector pixel, const int);
14728
14729 vector signed char vec_vspltb (vector signed char, const int);
14730 vector unsigned char vec_vspltb (vector unsigned char, const int);
14731 vector bool char vec_vspltb (vector bool char, const int);
14732
14733 vector signed char vec_splat_s8 (const int);
14734
14735 vector signed short vec_splat_s16 (const int);
14736
14737 vector signed int vec_splat_s32 (const int);
14738
14739 vector unsigned char vec_splat_u8 (const int);
14740
14741 vector unsigned short vec_splat_u16 (const int);
14742
14743 vector unsigned int vec_splat_u32 (const int);
14744
14745 vector signed char vec_sr (vector signed char, vector unsigned char);
14746 vector unsigned char vec_sr (vector unsigned char,
14747 vector unsigned char);
14748 vector signed short vec_sr (vector signed short,
14749 vector unsigned short);
14750 vector unsigned short vec_sr (vector unsigned short,
14751 vector unsigned short);
14752 vector signed int vec_sr (vector signed int, vector unsigned int);
14753 vector unsigned int vec_sr (vector unsigned int, vector unsigned int);
14754
14755 vector signed int vec_vsrw (vector signed int, vector unsigned int);
14756 vector unsigned int vec_vsrw (vector unsigned int, vector unsigned int);
14757
14758 vector signed short vec_vsrh (vector signed short,
14759 vector unsigned short);
14760 vector unsigned short vec_vsrh (vector unsigned short,
14761 vector unsigned short);
14762
14763 vector signed char vec_vsrb (vector signed char, vector unsigned char);
14764 vector unsigned char vec_vsrb (vector unsigned char,
14765 vector unsigned char);
14766
14767 vector signed char vec_sra (vector signed char, vector unsigned char);
14768 vector unsigned char vec_sra (vector unsigned char,
14769 vector unsigned char);
14770 vector signed short vec_sra (vector signed short,
14771 vector unsigned short);
14772 vector unsigned short vec_sra (vector unsigned short,
14773 vector unsigned short);
14774 vector signed int vec_sra (vector signed int, vector unsigned int);
14775 vector unsigned int vec_sra (vector unsigned int, vector unsigned int);
14776
14777 vector signed int vec_vsraw (vector signed int, vector unsigned int);
14778 vector unsigned int vec_vsraw (vector unsigned int,
14779 vector unsigned int);
14780
14781 vector signed short vec_vsrah (vector signed short,
14782 vector unsigned short);
14783 vector unsigned short vec_vsrah (vector unsigned short,
14784 vector unsigned short);
14785
14786 vector signed char vec_vsrab (vector signed char, vector unsigned char);
14787 vector unsigned char vec_vsrab (vector unsigned char,
14788 vector unsigned char);
14789
14790 vector signed int vec_srl (vector signed int, vector unsigned int);
14791 vector signed int vec_srl (vector signed int, vector unsigned short);
14792 vector signed int vec_srl (vector signed int, vector unsigned char);
14793 vector unsigned int vec_srl (vector unsigned int, vector unsigned int);
14794 vector unsigned int vec_srl (vector unsigned int,
14795 vector unsigned short);
14796 vector unsigned int vec_srl (vector unsigned int, vector unsigned char);
14797 vector bool int vec_srl (vector bool int, vector unsigned int);
14798 vector bool int vec_srl (vector bool int, vector unsigned short);
14799 vector bool int vec_srl (vector bool int, vector unsigned char);
14800 vector signed short vec_srl (vector signed short, vector unsigned int);
14801 vector signed short vec_srl (vector signed short,
14802 vector unsigned short);
14803 vector signed short vec_srl (vector signed short, vector unsigned char);
14804 vector unsigned short vec_srl (vector unsigned short,
14805 vector unsigned int);
14806 vector unsigned short vec_srl (vector unsigned short,
14807 vector unsigned short);
14808 vector unsigned short vec_srl (vector unsigned short,
14809 vector unsigned char);
14810 vector bool short vec_srl (vector bool short, vector unsigned int);
14811 vector bool short vec_srl (vector bool short, vector unsigned short);
14812 vector bool short vec_srl (vector bool short, vector unsigned char);
14813 vector pixel vec_srl (vector pixel, vector unsigned int);
14814 vector pixel vec_srl (vector pixel, vector unsigned short);
14815 vector pixel vec_srl (vector pixel, vector unsigned char);
14816 vector signed char vec_srl (vector signed char, vector unsigned int);
14817 vector signed char vec_srl (vector signed char, vector unsigned short);
14818 vector signed char vec_srl (vector signed char, vector unsigned char);
14819 vector unsigned char vec_srl (vector unsigned char,
14820 vector unsigned int);
14821 vector unsigned char vec_srl (vector unsigned char,
14822 vector unsigned short);
14823 vector unsigned char vec_srl (vector unsigned char,
14824 vector unsigned char);
14825 vector bool char vec_srl (vector bool char, vector unsigned int);
14826 vector bool char vec_srl (vector bool char, vector unsigned short);
14827 vector bool char vec_srl (vector bool char, vector unsigned char);
14828
14829 vector float vec_sro (vector float, vector signed char);
14830 vector float vec_sro (vector float, vector unsigned char);
14831 vector signed int vec_sro (vector signed int, vector signed char);
14832 vector signed int vec_sro (vector signed int, vector unsigned char);
14833 vector unsigned int vec_sro (vector unsigned int, vector signed char);
14834 vector unsigned int vec_sro (vector unsigned int, vector unsigned char);
14835 vector signed short vec_sro (vector signed short, vector signed char);
14836 vector signed short vec_sro (vector signed short, vector unsigned char);
14837 vector unsigned short vec_sro (vector unsigned short,
14838 vector signed char);
14839 vector unsigned short vec_sro (vector unsigned short,
14840 vector unsigned char);
14841 vector pixel vec_sro (vector pixel, vector signed char);
14842 vector pixel vec_sro (vector pixel, vector unsigned char);
14843 vector signed char vec_sro (vector signed char, vector signed char);
14844 vector signed char vec_sro (vector signed char, vector unsigned char);
14845 vector unsigned char vec_sro (vector unsigned char, vector signed char);
14846 vector unsigned char vec_sro (vector unsigned char,
14847 vector unsigned char);
14848
14849 void vec_st (vector float, int, vector float *);
14850 void vec_st (vector float, int, float *);
14851 void vec_st (vector signed int, int, vector signed int *);
14852 void vec_st (vector signed int, int, int *);
14853 void vec_st (vector unsigned int, int, vector unsigned int *);
14854 void vec_st (vector unsigned int, int, unsigned int *);
14855 void vec_st (vector bool int, int, vector bool int *);
14856 void vec_st (vector bool int, int, unsigned int *);
14857 void vec_st (vector bool int, int, int *);
14858 void vec_st (vector signed short, int, vector signed short *);
14859 void vec_st (vector signed short, int, short *);
14860 void vec_st (vector unsigned short, int, vector unsigned short *);
14861 void vec_st (vector unsigned short, int, unsigned short *);
14862 void vec_st (vector bool short, int, vector bool short *);
14863 void vec_st (vector bool short, int, unsigned short *);
14864 void vec_st (vector pixel, int, vector pixel *);
14865 void vec_st (vector pixel, int, unsigned short *);
14866 void vec_st (vector pixel, int, short *);
14867 void vec_st (vector bool short, int, short *);
14868 void vec_st (vector signed char, int, vector signed char *);
14869 void vec_st (vector signed char, int, signed char *);
14870 void vec_st (vector unsigned char, int, vector unsigned char *);
14871 void vec_st (vector unsigned char, int, unsigned char *);
14872 void vec_st (vector bool char, int, vector bool char *);
14873 void vec_st (vector bool char, int, unsigned char *);
14874 void vec_st (vector bool char, int, signed char *);
14875
14876 void vec_ste (vector signed char, int, signed char *);
14877 void vec_ste (vector unsigned char, int, unsigned char *);
14878 void vec_ste (vector bool char, int, signed char *);
14879 void vec_ste (vector bool char, int, unsigned char *);
14880 void vec_ste (vector signed short, int, short *);
14881 void vec_ste (vector unsigned short, int, unsigned short *);
14882 void vec_ste (vector bool short, int, short *);
14883 void vec_ste (vector bool short, int, unsigned short *);
14884 void vec_ste (vector pixel, int, short *);
14885 void vec_ste (vector pixel, int, unsigned short *);
14886 void vec_ste (vector float, int, float *);
14887 void vec_ste (vector signed int, int, int *);
14888 void vec_ste (vector unsigned int, int, unsigned int *);
14889 void vec_ste (vector bool int, int, int *);
14890 void vec_ste (vector bool int, int, unsigned int *);
14891
14892 void vec_stvewx (vector float, int, float *);
14893 void vec_stvewx (vector signed int, int, int *);
14894 void vec_stvewx (vector unsigned int, int, unsigned int *);
14895 void vec_stvewx (vector bool int, int, int *);
14896 void vec_stvewx (vector bool int, int, unsigned int *);
14897
14898 void vec_stvehx (vector signed short, int, short *);
14899 void vec_stvehx (vector unsigned short, int, unsigned short *);
14900 void vec_stvehx (vector bool short, int, short *);
14901 void vec_stvehx (vector bool short, int, unsigned short *);
14902 void vec_stvehx (vector pixel, int, short *);
14903 void vec_stvehx (vector pixel, int, unsigned short *);
14904
14905 void vec_stvebx (vector signed char, int, signed char *);
14906 void vec_stvebx (vector unsigned char, int, unsigned char *);
14907 void vec_stvebx (vector bool char, int, signed char *);
14908 void vec_stvebx (vector bool char, int, unsigned char *);
14909
14910 void vec_stl (vector float, int, vector float *);
14911 void vec_stl (vector float, int, float *);
14912 void vec_stl (vector signed int, int, vector signed int *);
14913 void vec_stl (vector signed int, int, int *);
14914 void vec_stl (vector unsigned int, int, vector unsigned int *);
14915 void vec_stl (vector unsigned int, int, unsigned int *);
14916 void vec_stl (vector bool int, int, vector bool int *);
14917 void vec_stl (vector bool int, int, unsigned int *);
14918 void vec_stl (vector bool int, int, int *);
14919 void vec_stl (vector signed short, int, vector signed short *);
14920 void vec_stl (vector signed short, int, short *);
14921 void vec_stl (vector unsigned short, int, vector unsigned short *);
14922 void vec_stl (vector unsigned short, int, unsigned short *);
14923 void vec_stl (vector bool short, int, vector bool short *);
14924 void vec_stl (vector bool short, int, unsigned short *);
14925 void vec_stl (vector bool short, int, short *);
14926 void vec_stl (vector pixel, int, vector pixel *);
14927 void vec_stl (vector pixel, int, unsigned short *);
14928 void vec_stl (vector pixel, int, short *);
14929 void vec_stl (vector signed char, int, vector signed char *);
14930 void vec_stl (vector signed char, int, signed char *);
14931 void vec_stl (vector unsigned char, int, vector unsigned char *);
14932 void vec_stl (vector unsigned char, int, unsigned char *);
14933 void vec_stl (vector bool char, int, vector bool char *);
14934 void vec_stl (vector bool char, int, unsigned char *);
14935 void vec_stl (vector bool char, int, signed char *);
14936
14937 vector signed char vec_sub (vector bool char, vector signed char);
14938 vector signed char vec_sub (vector signed char, vector bool char);
14939 vector signed char vec_sub (vector signed char, vector signed char);
14940 vector unsigned char vec_sub (vector bool char, vector unsigned char);
14941 vector unsigned char vec_sub (vector unsigned char, vector bool char);
14942 vector unsigned char vec_sub (vector unsigned char,
14943 vector unsigned char);
14944 vector signed short vec_sub (vector bool short, vector signed short);
14945 vector signed short vec_sub (vector signed short, vector bool short);
14946 vector signed short vec_sub (vector signed short, vector signed short);
14947 vector unsigned short vec_sub (vector bool short,
14948 vector unsigned short);
14949 vector unsigned short vec_sub (vector unsigned short,
14950 vector bool short);
14951 vector unsigned short vec_sub (vector unsigned short,
14952 vector unsigned short);
14953 vector signed int vec_sub (vector bool int, vector signed int);
14954 vector signed int vec_sub (vector signed int, vector bool int);
14955 vector signed int vec_sub (vector signed int, vector signed int);
14956 vector unsigned int vec_sub (vector bool int, vector unsigned int);
14957 vector unsigned int vec_sub (vector unsigned int, vector bool int);
14958 vector unsigned int vec_sub (vector unsigned int, vector unsigned int);
14959 vector float vec_sub (vector float, vector float);
14960
14961 vector float vec_vsubfp (vector float, vector float);
14962
14963 vector signed int vec_vsubuwm (vector bool int, vector signed int);
14964 vector signed int vec_vsubuwm (vector signed int, vector bool int);
14965 vector signed int vec_vsubuwm (vector signed int, vector signed int);
14966 vector unsigned int vec_vsubuwm (vector bool int, vector unsigned int);
14967 vector unsigned int vec_vsubuwm (vector unsigned int, vector bool int);
14968 vector unsigned int vec_vsubuwm (vector unsigned int,
14969 vector unsigned int);
14970
14971 vector signed short vec_vsubuhm (vector bool short,
14972 vector signed short);
14973 vector signed short vec_vsubuhm (vector signed short,
14974 vector bool short);
14975 vector signed short vec_vsubuhm (vector signed short,
14976 vector signed short);
14977 vector unsigned short vec_vsubuhm (vector bool short,
14978 vector unsigned short);
14979 vector unsigned short vec_vsubuhm (vector unsigned short,
14980 vector bool short);
14981 vector unsigned short vec_vsubuhm (vector unsigned short,
14982 vector unsigned short);
14983
14984 vector signed char vec_vsububm (vector bool char, vector signed char);
14985 vector signed char vec_vsububm (vector signed char, vector bool char);
14986 vector signed char vec_vsububm (vector signed char, vector signed char);
14987 vector unsigned char vec_vsububm (vector bool char,
14988 vector unsigned char);
14989 vector unsigned char vec_vsububm (vector unsigned char,
14990 vector bool char);
14991 vector unsigned char vec_vsububm (vector unsigned char,
14992 vector unsigned char);
14993
14994 vector unsigned int vec_subc (vector unsigned int, vector unsigned int);
14995
14996 vector unsigned char vec_subs (vector bool char, vector unsigned char);
14997 vector unsigned char vec_subs (vector unsigned char, vector bool char);
14998 vector unsigned char vec_subs (vector unsigned char,
14999 vector unsigned char);
15000 vector signed char vec_subs (vector bool char, vector signed char);
15001 vector signed char vec_subs (vector signed char, vector bool char);
15002 vector signed char vec_subs (vector signed char, vector signed char);
15003 vector unsigned short vec_subs (vector bool short,
15004 vector unsigned short);
15005 vector unsigned short vec_subs (vector unsigned short,
15006 vector bool short);
15007 vector unsigned short vec_subs (vector unsigned short,
15008 vector unsigned short);
15009 vector signed short vec_subs (vector bool short, vector signed short);
15010 vector signed short vec_subs (vector signed short, vector bool short);
15011 vector signed short vec_subs (vector signed short, vector signed short);
15012 vector unsigned int vec_subs (vector bool int, vector unsigned int);
15013 vector unsigned int vec_subs (vector unsigned int, vector bool int);
15014 vector unsigned int vec_subs (vector unsigned int, vector unsigned int);
15015 vector signed int vec_subs (vector bool int, vector signed int);
15016 vector signed int vec_subs (vector signed int, vector bool int);
15017 vector signed int vec_subs (vector signed int, vector signed int);
15018
15019 vector signed int vec_vsubsws (vector bool int, vector signed int);
15020 vector signed int vec_vsubsws (vector signed int, vector bool int);
15021 vector signed int vec_vsubsws (vector signed int, vector signed int);
15022
15023 vector unsigned int vec_vsubuws (vector bool int, vector unsigned int);
15024 vector unsigned int vec_vsubuws (vector unsigned int, vector bool int);
15025 vector unsigned int vec_vsubuws (vector unsigned int,
15026 vector unsigned int);
15027
15028 vector signed short vec_vsubshs (vector bool short,
15029 vector signed short);
15030 vector signed short vec_vsubshs (vector signed short,
15031 vector bool short);
15032 vector signed short vec_vsubshs (vector signed short,
15033 vector signed short);
15034
15035 vector unsigned short vec_vsubuhs (vector bool short,
15036 vector unsigned short);
15037 vector unsigned short vec_vsubuhs (vector unsigned short,
15038 vector bool short);
15039 vector unsigned short vec_vsubuhs (vector unsigned short,
15040 vector unsigned short);
15041
15042 vector signed char vec_vsubsbs (vector bool char, vector signed char);
15043 vector signed char vec_vsubsbs (vector signed char, vector bool char);
15044 vector signed char vec_vsubsbs (vector signed char, vector signed char);
15045
15046 vector unsigned char vec_vsububs (vector bool char,
15047 vector unsigned char);
15048 vector unsigned char vec_vsububs (vector unsigned char,
15049 vector bool char);
15050 vector unsigned char vec_vsububs (vector unsigned char,
15051 vector unsigned char);
15052
15053 vector unsigned int vec_sum4s (vector unsigned char,
15054 vector unsigned int);
15055 vector signed int vec_sum4s (vector signed char, vector signed int);
15056 vector signed int vec_sum4s (vector signed short, vector signed int);
15057
15058 vector signed int vec_vsum4shs (vector signed short, vector signed int);
15059
15060 vector signed int vec_vsum4sbs (vector signed char, vector signed int);
15061
15062 vector unsigned int vec_vsum4ubs (vector unsigned char,
15063 vector unsigned int);
15064
15065 vector signed int vec_sum2s (vector signed int, vector signed int);
15066
15067 vector signed int vec_sums (vector signed int, vector signed int);
15068
15069 vector float vec_trunc (vector float);
15070
15071 vector signed short vec_unpackh (vector signed char);
15072 vector bool short vec_unpackh (vector bool char);
15073 vector signed int vec_unpackh (vector signed short);
15074 vector bool int vec_unpackh (vector bool short);
15075 vector unsigned int vec_unpackh (vector pixel);
15076
15077 vector bool int vec_vupkhsh (vector bool short);
15078 vector signed int vec_vupkhsh (vector signed short);
15079
15080 vector unsigned int vec_vupkhpx (vector pixel);
15081
15082 vector bool short vec_vupkhsb (vector bool char);
15083 vector signed short vec_vupkhsb (vector signed char);
15084
15085 vector signed short vec_unpackl (vector signed char);
15086 vector bool short vec_unpackl (vector bool char);
15087 vector unsigned int vec_unpackl (vector pixel);
15088 vector signed int vec_unpackl (vector signed short);
15089 vector bool int vec_unpackl (vector bool short);
15090
15091 vector unsigned int vec_vupklpx (vector pixel);
15092
15093 vector bool int vec_vupklsh (vector bool short);
15094 vector signed int vec_vupklsh (vector signed short);
15095
15096 vector bool short vec_vupklsb (vector bool char);
15097 vector signed short vec_vupklsb (vector signed char);
15098
15099 vector float vec_xor (vector float, vector float);
15100 vector float vec_xor (vector float, vector bool int);
15101 vector float vec_xor (vector bool int, vector float);
15102 vector bool int vec_xor (vector bool int, vector bool int);
15103 vector signed int vec_xor (vector bool int, vector signed int);
15104 vector signed int vec_xor (vector signed int, vector bool int);
15105 vector signed int vec_xor (vector signed int, vector signed int);
15106 vector unsigned int vec_xor (vector bool int, vector unsigned int);
15107 vector unsigned int vec_xor (vector unsigned int, vector bool int);
15108 vector unsigned int vec_xor (vector unsigned int, vector unsigned int);
15109 vector bool short vec_xor (vector bool short, vector bool short);
15110 vector signed short vec_xor (vector bool short, vector signed short);
15111 vector signed short vec_xor (vector signed short, vector bool short);
15112 vector signed short vec_xor (vector signed short, vector signed short);
15113 vector unsigned short vec_xor (vector bool short,
15114 vector unsigned short);
15115 vector unsigned short vec_xor (vector unsigned short,
15116 vector bool short);
15117 vector unsigned short vec_xor (vector unsigned short,
15118 vector unsigned short);
15119 vector signed char vec_xor (vector bool char, vector signed char);
15120 vector bool char vec_xor (vector bool char, vector bool char);
15121 vector signed char vec_xor (vector signed char, vector bool char);
15122 vector signed char vec_xor (vector signed char, vector signed char);
15123 vector unsigned char vec_xor (vector bool char, vector unsigned char);
15124 vector unsigned char vec_xor (vector unsigned char, vector bool char);
15125 vector unsigned char vec_xor (vector unsigned char,
15126 vector unsigned char);
15127
15128 int vec_all_eq (vector signed char, vector bool char);
15129 int vec_all_eq (vector signed char, vector signed char);
15130 int vec_all_eq (vector unsigned char, vector bool char);
15131 int vec_all_eq (vector unsigned char, vector unsigned char);
15132 int vec_all_eq (vector bool char, vector bool char);
15133 int vec_all_eq (vector bool char, vector unsigned char);
15134 int vec_all_eq (vector bool char, vector signed char);
15135 int vec_all_eq (vector signed short, vector bool short);
15136 int vec_all_eq (vector signed short, vector signed short);
15137 int vec_all_eq (vector unsigned short, vector bool short);
15138 int vec_all_eq (vector unsigned short, vector unsigned short);
15139 int vec_all_eq (vector bool short, vector bool short);
15140 int vec_all_eq (vector bool short, vector unsigned short);
15141 int vec_all_eq (vector bool short, vector signed short);
15142 int vec_all_eq (vector pixel, vector pixel);
15143 int vec_all_eq (vector signed int, vector bool int);
15144 int vec_all_eq (vector signed int, vector signed int);
15145 int vec_all_eq (vector unsigned int, vector bool int);
15146 int vec_all_eq (vector unsigned int, vector unsigned int);
15147 int vec_all_eq (vector bool int, vector bool int);
15148 int vec_all_eq (vector bool int, vector unsigned int);
15149 int vec_all_eq (vector bool int, vector signed int);
15150 int vec_all_eq (vector float, vector float);
15151
15152 int vec_all_ge (vector bool char, vector unsigned char);
15153 int vec_all_ge (vector unsigned char, vector bool char);
15154 int vec_all_ge (vector unsigned char, vector unsigned char);
15155 int vec_all_ge (vector bool char, vector signed char);
15156 int vec_all_ge (vector signed char, vector bool char);
15157 int vec_all_ge (vector signed char, vector signed char);
15158 int vec_all_ge (vector bool short, vector unsigned short);
15159 int vec_all_ge (vector unsigned short, vector bool short);
15160 int vec_all_ge (vector unsigned short, vector unsigned short);
15161 int vec_all_ge (vector signed short, vector signed short);
15162 int vec_all_ge (vector bool short, vector signed short);
15163 int vec_all_ge (vector signed short, vector bool short);
15164 int vec_all_ge (vector bool int, vector unsigned int);
15165 int vec_all_ge (vector unsigned int, vector bool int);
15166 int vec_all_ge (vector unsigned int, vector unsigned int);
15167 int vec_all_ge (vector bool int, vector signed int);
15168 int vec_all_ge (vector signed int, vector bool int);
15169 int vec_all_ge (vector signed int, vector signed int);
15170 int vec_all_ge (vector float, vector float);
15171
15172 int vec_all_gt (vector bool char, vector unsigned char);
15173 int vec_all_gt (vector unsigned char, vector bool char);
15174 int vec_all_gt (vector unsigned char, vector unsigned char);
15175 int vec_all_gt (vector bool char, vector signed char);
15176 int vec_all_gt (vector signed char, vector bool char);
15177 int vec_all_gt (vector signed char, vector signed char);
15178 int vec_all_gt (vector bool short, vector unsigned short);
15179 int vec_all_gt (vector unsigned short, vector bool short);
15180 int vec_all_gt (vector unsigned short, vector unsigned short);
15181 int vec_all_gt (vector bool short, vector signed short);
15182 int vec_all_gt (vector signed short, vector bool short);
15183 int vec_all_gt (vector signed short, vector signed short);
15184 int vec_all_gt (vector bool int, vector unsigned int);
15185 int vec_all_gt (vector unsigned int, vector bool int);
15186 int vec_all_gt (vector unsigned int, vector unsigned int);
15187 int vec_all_gt (vector bool int, vector signed int);
15188 int vec_all_gt (vector signed int, vector bool int);
15189 int vec_all_gt (vector signed int, vector signed int);
15190 int vec_all_gt (vector float, vector float);
15191
15192 int vec_all_in (vector float, vector float);
15193
15194 int vec_all_le (vector bool char, vector unsigned char);
15195 int vec_all_le (vector unsigned char, vector bool char);
15196 int vec_all_le (vector unsigned char, vector unsigned char);
15197 int vec_all_le (vector bool char, vector signed char);
15198 int vec_all_le (vector signed char, vector bool char);
15199 int vec_all_le (vector signed char, vector signed char);
15200 int vec_all_le (vector bool short, vector unsigned short);
15201 int vec_all_le (vector unsigned short, vector bool short);
15202 int vec_all_le (vector unsigned short, vector unsigned short);
15203 int vec_all_le (vector bool short, vector signed short);
15204 int vec_all_le (vector signed short, vector bool short);
15205 int vec_all_le (vector signed short, vector signed short);
15206 int vec_all_le (vector bool int, vector unsigned int);
15207 int vec_all_le (vector unsigned int, vector bool int);
15208 int vec_all_le (vector unsigned int, vector unsigned int);
15209 int vec_all_le (vector bool int, vector signed int);
15210 int vec_all_le (vector signed int, vector bool int);
15211 int vec_all_le (vector signed int, vector signed int);
15212 int vec_all_le (vector float, vector float);
15213
15214 int vec_all_lt (vector bool char, vector unsigned char);
15215 int vec_all_lt (vector unsigned char, vector bool char);
15216 int vec_all_lt (vector unsigned char, vector unsigned char);
15217 int vec_all_lt (vector bool char, vector signed char);
15218 int vec_all_lt (vector signed char, vector bool char);
15219 int vec_all_lt (vector signed char, vector signed char);
15220 int vec_all_lt (vector bool short, vector unsigned short);
15221 int vec_all_lt (vector unsigned short, vector bool short);
15222 int vec_all_lt (vector unsigned short, vector unsigned short);
15223 int vec_all_lt (vector bool short, vector signed short);
15224 int vec_all_lt (vector signed short, vector bool short);
15225 int vec_all_lt (vector signed short, vector signed short);
15226 int vec_all_lt (vector bool int, vector unsigned int);
15227 int vec_all_lt (vector unsigned int, vector bool int);
15228 int vec_all_lt (vector unsigned int, vector unsigned int);
15229 int vec_all_lt (vector bool int, vector signed int);
15230 int vec_all_lt (vector signed int, vector bool int);
15231 int vec_all_lt (vector signed int, vector signed int);
15232 int vec_all_lt (vector float, vector float);
15233
15234 int vec_all_nan (vector float);
15235
15236 int vec_all_ne (vector signed char, vector bool char);
15237 int vec_all_ne (vector signed char, vector signed char);
15238 int vec_all_ne (vector unsigned char, vector bool char);
15239 int vec_all_ne (vector unsigned char, vector unsigned char);
15240 int vec_all_ne (vector bool char, vector bool char);
15241 int vec_all_ne (vector bool char, vector unsigned char);
15242 int vec_all_ne (vector bool char, vector signed char);
15243 int vec_all_ne (vector signed short, vector bool short);
15244 int vec_all_ne (vector signed short, vector signed short);
15245 int vec_all_ne (vector unsigned short, vector bool short);
15246 int vec_all_ne (vector unsigned short, vector unsigned short);
15247 int vec_all_ne (vector bool short, vector bool short);
15248 int vec_all_ne (vector bool short, vector unsigned short);
15249 int vec_all_ne (vector bool short, vector signed short);
15250 int vec_all_ne (vector pixel, vector pixel);
15251 int vec_all_ne (vector signed int, vector bool int);
15252 int vec_all_ne (vector signed int, vector signed int);
15253 int vec_all_ne (vector unsigned int, vector bool int);
15254 int vec_all_ne (vector unsigned int, vector unsigned int);
15255 int vec_all_ne (vector bool int, vector bool int);
15256 int vec_all_ne (vector bool int, vector unsigned int);
15257 int vec_all_ne (vector bool int, vector signed int);
15258 int vec_all_ne (vector float, vector float);
15259
15260 int vec_all_nge (vector float, vector float);
15261
15262 int vec_all_ngt (vector float, vector float);
15263
15264 int vec_all_nle (vector float, vector float);
15265
15266 int vec_all_nlt (vector float, vector float);
15267
15268 int vec_all_numeric (vector float);
15269
15270 int vec_any_eq (vector signed char, vector bool char);
15271 int vec_any_eq (vector signed char, vector signed char);
15272 int vec_any_eq (vector unsigned char, vector bool char);
15273 int vec_any_eq (vector unsigned char, vector unsigned char);
15274 int vec_any_eq (vector bool char, vector bool char);
15275 int vec_any_eq (vector bool char, vector unsigned char);
15276 int vec_any_eq (vector bool char, vector signed char);
15277 int vec_any_eq (vector signed short, vector bool short);
15278 int vec_any_eq (vector signed short, vector signed short);
15279 int vec_any_eq (vector unsigned short, vector bool short);
15280 int vec_any_eq (vector unsigned short, vector unsigned short);
15281 int vec_any_eq (vector bool short, vector bool short);
15282 int vec_any_eq (vector bool short, vector unsigned short);
15283 int vec_any_eq (vector bool short, vector signed short);
15284 int vec_any_eq (vector pixel, vector pixel);
15285 int vec_any_eq (vector signed int, vector bool int);
15286 int vec_any_eq (vector signed int, vector signed int);
15287 int vec_any_eq (vector unsigned int, vector bool int);
15288 int vec_any_eq (vector unsigned int, vector unsigned int);
15289 int vec_any_eq (vector bool int, vector bool int);
15290 int vec_any_eq (vector bool int, vector unsigned int);
15291 int vec_any_eq (vector bool int, vector signed int);
15292 int vec_any_eq (vector float, vector float);
15293
15294 int vec_any_ge (vector signed char, vector bool char);
15295 int vec_any_ge (vector unsigned char, vector bool char);
15296 int vec_any_ge (vector unsigned char, vector unsigned char);
15297 int vec_any_ge (vector signed char, vector signed char);
15298 int vec_any_ge (vector bool char, vector unsigned char);
15299 int vec_any_ge (vector bool char, vector signed char);
15300 int vec_any_ge (vector unsigned short, vector bool short);
15301 int vec_any_ge (vector unsigned short, vector unsigned short);
15302 int vec_any_ge (vector signed short, vector signed short);
15303 int vec_any_ge (vector signed short, vector bool short);
15304 int vec_any_ge (vector bool short, vector unsigned short);
15305 int vec_any_ge (vector bool short, vector signed short);
15306 int vec_any_ge (vector signed int, vector bool int);
15307 int vec_any_ge (vector unsigned int, vector bool int);
15308 int vec_any_ge (vector unsigned int, vector unsigned int);
15309 int vec_any_ge (vector signed int, vector signed int);
15310 int vec_any_ge (vector bool int, vector unsigned int);
15311 int vec_any_ge (vector bool int, vector signed int);
15312 int vec_any_ge (vector float, vector float);
15313
15314 int vec_any_gt (vector bool char, vector unsigned char);
15315 int vec_any_gt (vector unsigned char, vector bool char);
15316 int vec_any_gt (vector unsigned char, vector unsigned char);
15317 int vec_any_gt (vector bool char, vector signed char);
15318 int vec_any_gt (vector signed char, vector bool char);
15319 int vec_any_gt (vector signed char, vector signed char);
15320 int vec_any_gt (vector bool short, vector unsigned short);
15321 int vec_any_gt (vector unsigned short, vector bool short);
15322 int vec_any_gt (vector unsigned short, vector unsigned short);
15323 int vec_any_gt (vector bool short, vector signed short);
15324 int vec_any_gt (vector signed short, vector bool short);
15325 int vec_any_gt (vector signed short, vector signed short);
15326 int vec_any_gt (vector bool int, vector unsigned int);
15327 int vec_any_gt (vector unsigned int, vector bool int);
15328 int vec_any_gt (vector unsigned int, vector unsigned int);
15329 int vec_any_gt (vector bool int, vector signed int);
15330 int vec_any_gt (vector signed int, vector bool int);
15331 int vec_any_gt (vector signed int, vector signed int);
15332 int vec_any_gt (vector float, vector float);
15333
15334 int vec_any_le (vector bool char, vector unsigned char);
15335 int vec_any_le (vector unsigned char, vector bool char);
15336 int vec_any_le (vector unsigned char, vector unsigned char);
15337 int vec_any_le (vector bool char, vector signed char);
15338 int vec_any_le (vector signed char, vector bool char);
15339 int vec_any_le (vector signed char, vector signed char);
15340 int vec_any_le (vector bool short, vector unsigned short);
15341 int vec_any_le (vector unsigned short, vector bool short);
15342 int vec_any_le (vector unsigned short, vector unsigned short);
15343 int vec_any_le (vector bool short, vector signed short);
15344 int vec_any_le (vector signed short, vector bool short);
15345 int vec_any_le (vector signed short, vector signed short);
15346 int vec_any_le (vector bool int, vector unsigned int);
15347 int vec_any_le (vector unsigned int, vector bool int);
15348 int vec_any_le (vector unsigned int, vector unsigned int);
15349 int vec_any_le (vector bool int, vector signed int);
15350 int vec_any_le (vector signed int, vector bool int);
15351 int vec_any_le (vector signed int, vector signed int);
15352 int vec_any_le (vector float, vector float);
15353
15354 int vec_any_lt (vector bool char, vector unsigned char);
15355 int vec_any_lt (vector unsigned char, vector bool char);
15356 int vec_any_lt (vector unsigned char, vector unsigned char);
15357 int vec_any_lt (vector bool char, vector signed char);
15358 int vec_any_lt (vector signed char, vector bool char);
15359 int vec_any_lt (vector signed char, vector signed char);
15360 int vec_any_lt (vector bool short, vector unsigned short);
15361 int vec_any_lt (vector unsigned short, vector bool short);
15362 int vec_any_lt (vector unsigned short, vector unsigned short);
15363 int vec_any_lt (vector bool short, vector signed short);
15364 int vec_any_lt (vector signed short, vector bool short);
15365 int vec_any_lt (vector signed short, vector signed short);
15366 int vec_any_lt (vector bool int, vector unsigned int);
15367 int vec_any_lt (vector unsigned int, vector bool int);
15368 int vec_any_lt (vector unsigned int, vector unsigned int);
15369 int vec_any_lt (vector bool int, vector signed int);
15370 int vec_any_lt (vector signed int, vector bool int);
15371 int vec_any_lt (vector signed int, vector signed int);
15372 int vec_any_lt (vector float, vector float);
15373
15374 int vec_any_nan (vector float);
15375
15376 int vec_any_ne (vector signed char, vector bool char);
15377 int vec_any_ne (vector signed char, vector signed char);
15378 int vec_any_ne (vector unsigned char, vector bool char);
15379 int vec_any_ne (vector unsigned char, vector unsigned char);
15380 int vec_any_ne (vector bool char, vector bool char);
15381 int vec_any_ne (vector bool char, vector unsigned char);
15382 int vec_any_ne (vector bool char, vector signed char);
15383 int vec_any_ne (vector signed short, vector bool short);
15384 int vec_any_ne (vector signed short, vector signed short);
15385 int vec_any_ne (vector unsigned short, vector bool short);
15386 int vec_any_ne (vector unsigned short, vector unsigned short);
15387 int vec_any_ne (vector bool short, vector bool short);
15388 int vec_any_ne (vector bool short, vector unsigned short);
15389 int vec_any_ne (vector bool short, vector signed short);
15390 int vec_any_ne (vector pixel, vector pixel);
15391 int vec_any_ne (vector signed int, vector bool int);
15392 int vec_any_ne (vector signed int, vector signed int);
15393 int vec_any_ne (vector unsigned int, vector bool int);
15394 int vec_any_ne (vector unsigned int, vector unsigned int);
15395 int vec_any_ne (vector bool int, vector bool int);
15396 int vec_any_ne (vector bool int, vector unsigned int);
15397 int vec_any_ne (vector bool int, vector signed int);
15398 int vec_any_ne (vector float, vector float);
15399
15400 int vec_any_nge (vector float, vector float);
15401
15402 int vec_any_ngt (vector float, vector float);
15403
15404 int vec_any_nle (vector float, vector float);
15405
15406 int vec_any_nlt (vector float, vector float);
15407
15408 int vec_any_numeric (vector float);
15409
15410 int vec_any_out (vector float, vector float);
15411 @end smallexample
15412
15413 If the vector/scalar (VSX) instruction set is available, the following
15414 additional functions are available:
15415
15416 @smallexample
15417 vector double vec_abs (vector double);
15418 vector double vec_add (vector double, vector double);
15419 vector double vec_and (vector double, vector double);
15420 vector double vec_and (vector double, vector bool long);
15421 vector double vec_and (vector bool long, vector double);
15422 vector long vec_and (vector long, vector long);
15423 vector long vec_and (vector long, vector bool long);
15424 vector long vec_and (vector bool long, vector long);
15425 vector unsigned long vec_and (vector unsigned long, vector unsigned long);
15426 vector unsigned long vec_and (vector unsigned long, vector bool long);
15427 vector unsigned long vec_and (vector bool long, vector unsigned long);
15428 vector double vec_andc (vector double, vector double);
15429 vector double vec_andc (vector double, vector bool long);
15430 vector double vec_andc (vector bool long, vector double);
15431 vector long vec_andc (vector long, vector long);
15432 vector long vec_andc (vector long, vector bool long);
15433 vector long vec_andc (vector bool long, vector long);
15434 vector unsigned long vec_andc (vector unsigned long, vector unsigned long);
15435 vector unsigned long vec_andc (vector unsigned long, vector bool long);
15436 vector unsigned long vec_andc (vector bool long, vector unsigned long);
15437 vector double vec_ceil (vector double);
15438 vector bool long vec_cmpeq (vector double, vector double);
15439 vector bool long vec_cmpge (vector double, vector double);
15440 vector bool long vec_cmpgt (vector double, vector double);
15441 vector bool long vec_cmple (vector double, vector double);
15442 vector bool long vec_cmplt (vector double, vector double);
15443 vector double vec_cpsgn (vector double, vector double);
15444 vector float vec_div (vector float, vector float);
15445 vector double vec_div (vector double, vector double);
15446 vector long vec_div (vector long, vector long);
15447 vector unsigned long vec_div (vector unsigned long, vector unsigned long);
15448 vector double vec_floor (vector double);
15449 vector double vec_ld (int, const vector double *);
15450 vector double vec_ld (int, const double *);
15451 vector double vec_ldl (int, const vector double *);
15452 vector double vec_ldl (int, const double *);
15453 vector unsigned char vec_lvsl (int, const volatile double *);
15454 vector unsigned char vec_lvsr (int, const volatile double *);
15455 vector double vec_madd (vector double, vector double, vector double);
15456 vector double vec_max (vector double, vector double);
15457 vector signed long vec_mergeh (vector signed long, vector signed long);
15458 vector signed long vec_mergeh (vector signed long, vector bool long);
15459 vector signed long vec_mergeh (vector bool long, vector signed long);
15460 vector unsigned long vec_mergeh (vector unsigned long, vector unsigned long);
15461 vector unsigned long vec_mergeh (vector unsigned long, vector bool long);
15462 vector unsigned long vec_mergeh (vector bool long, vector unsigned long);
15463 vector signed long vec_mergel (vector signed long, vector signed long);
15464 vector signed long vec_mergel (vector signed long, vector bool long);
15465 vector signed long vec_mergel (vector bool long, vector signed long);
15466 vector unsigned long vec_mergel (vector unsigned long, vector unsigned long);
15467 vector unsigned long vec_mergel (vector unsigned long, vector bool long);
15468 vector unsigned long vec_mergel (vector bool long, vector unsigned long);
15469 vector double vec_min (vector double, vector double);
15470 vector float vec_msub (vector float, vector float, vector float);
15471 vector double vec_msub (vector double, vector double, vector double);
15472 vector float vec_mul (vector float, vector float);
15473 vector double vec_mul (vector double, vector double);
15474 vector long vec_mul (vector long, vector long);
15475 vector unsigned long vec_mul (vector unsigned long, vector unsigned long);
15476 vector float vec_nearbyint (vector float);
15477 vector double vec_nearbyint (vector double);
15478 vector float vec_nmadd (vector float, vector float, vector float);
15479 vector double vec_nmadd (vector double, vector double, vector double);
15480 vector double vec_nmsub (vector double, vector double, vector double);
15481 vector double vec_nor (vector double, vector double);
15482 vector long vec_nor (vector long, vector long);
15483 vector long vec_nor (vector long, vector bool long);
15484 vector long vec_nor (vector bool long, vector long);
15485 vector unsigned long vec_nor (vector unsigned long, vector unsigned long);
15486 vector unsigned long vec_nor (vector unsigned long, vector bool long);
15487 vector unsigned long vec_nor (vector bool long, vector unsigned long);
15488 vector double vec_or (vector double, vector double);
15489 vector double vec_or (vector double, vector bool long);
15490 vector double vec_or (vector bool long, vector double);
15491 vector long vec_or (vector long, vector long);
15492 vector long vec_or (vector long, vector bool long);
15493 vector long vec_or (vector bool long, vector long);
15494 vector unsigned long vec_or (vector unsigned long, vector unsigned long);
15495 vector unsigned long vec_or (vector unsigned long, vector bool long);
15496 vector unsigned long vec_or (vector bool long, vector unsigned long);
15497 vector double vec_perm (vector double, vector double, vector unsigned char);
15498 vector long vec_perm (vector long, vector long, vector unsigned char);
15499 vector unsigned long vec_perm (vector unsigned long, vector unsigned long,
15500 vector unsigned char);
15501 vector double vec_rint (vector double);
15502 vector double vec_recip (vector double, vector double);
15503 vector double vec_rsqrt (vector double);
15504 vector double vec_rsqrte (vector double);
15505 vector double vec_sel (vector double, vector double, vector bool long);
15506 vector double vec_sel (vector double, vector double, vector unsigned long);
15507 vector long vec_sel (vector long, vector long, vector long);
15508 vector long vec_sel (vector long, vector long, vector unsigned long);
15509 vector long vec_sel (vector long, vector long, vector bool long);
15510 vector unsigned long vec_sel (vector unsigned long, vector unsigned long,
15511 vector long);
15512 vector unsigned long vec_sel (vector unsigned long, vector unsigned long,
15513 vector unsigned long);
15514 vector unsigned long vec_sel (vector unsigned long, vector unsigned long,
15515 vector bool long);
15516 vector double vec_splats (double);
15517 vector signed long vec_splats (signed long);
15518 vector unsigned long vec_splats (unsigned long);
15519 vector float vec_sqrt (vector float);
15520 vector double vec_sqrt (vector double);
15521 void vec_st (vector double, int, vector double *);
15522 void vec_st (vector double, int, double *);
15523 vector double vec_sub (vector double, vector double);
15524 vector double vec_trunc (vector double);
15525 vector double vec_xor (vector double, vector double);
15526 vector double vec_xor (vector double, vector bool long);
15527 vector double vec_xor (vector bool long, vector double);
15528 vector long vec_xor (vector long, vector long);
15529 vector long vec_xor (vector long, vector bool long);
15530 vector long vec_xor (vector bool long, vector long);
15531 vector unsigned long vec_xor (vector unsigned long, vector unsigned long);
15532 vector unsigned long vec_xor (vector unsigned long, vector bool long);
15533 vector unsigned long vec_xor (vector bool long, vector unsigned long);
15534 int vec_all_eq (vector double, vector double);
15535 int vec_all_ge (vector double, vector double);
15536 int vec_all_gt (vector double, vector double);
15537 int vec_all_le (vector double, vector double);
15538 int vec_all_lt (vector double, vector double);
15539 int vec_all_nan (vector double);
15540 int vec_all_ne (vector double, vector double);
15541 int vec_all_nge (vector double, vector double);
15542 int vec_all_ngt (vector double, vector double);
15543 int vec_all_nle (vector double, vector double);
15544 int vec_all_nlt (vector double, vector double);
15545 int vec_all_numeric (vector double);
15546 int vec_any_eq (vector double, vector double);
15547 int vec_any_ge (vector double, vector double);
15548 int vec_any_gt (vector double, vector double);
15549 int vec_any_le (vector double, vector double);
15550 int vec_any_lt (vector double, vector double);
15551 int vec_any_nan (vector double);
15552 int vec_any_ne (vector double, vector double);
15553 int vec_any_nge (vector double, vector double);
15554 int vec_any_ngt (vector double, vector double);
15555 int vec_any_nle (vector double, vector double);
15556 int vec_any_nlt (vector double, vector double);
15557 int vec_any_numeric (vector double);
15558
15559 vector double vec_vsx_ld (int, const vector double *);
15560 vector double vec_vsx_ld (int, const double *);
15561 vector float vec_vsx_ld (int, const vector float *);
15562 vector float vec_vsx_ld (int, const float *);
15563 vector bool int vec_vsx_ld (int, const vector bool int *);
15564 vector signed int vec_vsx_ld (int, const vector signed int *);
15565 vector signed int vec_vsx_ld (int, const int *);
15566 vector signed int vec_vsx_ld (int, const long *);
15567 vector unsigned int vec_vsx_ld (int, const vector unsigned int *);
15568 vector unsigned int vec_vsx_ld (int, const unsigned int *);
15569 vector unsigned int vec_vsx_ld (int, const unsigned long *);
15570 vector bool short vec_vsx_ld (int, const vector bool short *);
15571 vector pixel vec_vsx_ld (int, const vector pixel *);
15572 vector signed short vec_vsx_ld (int, const vector signed short *);
15573 vector signed short vec_vsx_ld (int, const short *);
15574 vector unsigned short vec_vsx_ld (int, const vector unsigned short *);
15575 vector unsigned short vec_vsx_ld (int, const unsigned short *);
15576 vector bool char vec_vsx_ld (int, const vector bool char *);
15577 vector signed char vec_vsx_ld (int, const vector signed char *);
15578 vector signed char vec_vsx_ld (int, const signed char *);
15579 vector unsigned char vec_vsx_ld (int, const vector unsigned char *);
15580 vector unsigned char vec_vsx_ld (int, const unsigned char *);
15581
15582 void vec_vsx_st (vector double, int, vector double *);
15583 void vec_vsx_st (vector double, int, double *);
15584 void vec_vsx_st (vector float, int, vector float *);
15585 void vec_vsx_st (vector float, int, float *);
15586 void vec_vsx_st (vector signed int, int, vector signed int *);
15587 void vec_vsx_st (vector signed int, int, int *);
15588 void vec_vsx_st (vector unsigned int, int, vector unsigned int *);
15589 void vec_vsx_st (vector unsigned int, int, unsigned int *);
15590 void vec_vsx_st (vector bool int, int, vector bool int *);
15591 void vec_vsx_st (vector bool int, int, unsigned int *);
15592 void vec_vsx_st (vector bool int, int, int *);
15593 void vec_vsx_st (vector signed short, int, vector signed short *);
15594 void vec_vsx_st (vector signed short, int, short *);
15595 void vec_vsx_st (vector unsigned short, int, vector unsigned short *);
15596 void vec_vsx_st (vector unsigned short, int, unsigned short *);
15597 void vec_vsx_st (vector bool short, int, vector bool short *);
15598 void vec_vsx_st (vector bool short, int, unsigned short *);
15599 void vec_vsx_st (vector pixel, int, vector pixel *);
15600 void vec_vsx_st (vector pixel, int, unsigned short *);
15601 void vec_vsx_st (vector pixel, int, short *);
15602 void vec_vsx_st (vector bool short, int, short *);
15603 void vec_vsx_st (vector signed char, int, vector signed char *);
15604 void vec_vsx_st (vector signed char, int, signed char *);
15605 void vec_vsx_st (vector unsigned char, int, vector unsigned char *);
15606 void vec_vsx_st (vector unsigned char, int, unsigned char *);
15607 void vec_vsx_st (vector bool char, int, vector bool char *);
15608 void vec_vsx_st (vector bool char, int, unsigned char *);
15609 void vec_vsx_st (vector bool char, int, signed char *);
15610
15611 vector double vec_xxpermdi (vector double, vector double, int);
15612 vector float vec_xxpermdi (vector float, vector float, int);
15613 vector long long vec_xxpermdi (vector long long, vector long long, int);
15614 vector unsigned long long vec_xxpermdi (vector unsigned long long,
15615 vector unsigned long long, int);
15616 vector int vec_xxpermdi (vector int, vector int, int);
15617 vector unsigned int vec_xxpermdi (vector unsigned int,
15618 vector unsigned int, int);
15619 vector short vec_xxpermdi (vector short, vector short, int);
15620 vector unsigned short vec_xxpermdi (vector unsigned short,
15621 vector unsigned short, int);
15622 vector signed char vec_xxpermdi (vector signed char, vector signed char, int);
15623 vector unsigned char vec_xxpermdi (vector unsigned char,
15624 vector unsigned char, int);
15625
15626 vector double vec_xxsldi (vector double, vector double, int);
15627 vector float vec_xxsldi (vector float, vector float, int);
15628 vector long long vec_xxsldi (vector long long, vector long long, int);
15629 vector unsigned long long vec_xxsldi (vector unsigned long long,
15630 vector unsigned long long, int);
15631 vector int vec_xxsldi (vector int, vector int, int);
15632 vector unsigned int vec_xxsldi (vector unsigned int, vector unsigned int, int);
15633 vector short vec_xxsldi (vector short, vector short, int);
15634 vector unsigned short vec_xxsldi (vector unsigned short,
15635 vector unsigned short, int);
15636 vector signed char vec_xxsldi (vector signed char, vector signed char, int);
15637 vector unsigned char vec_xxsldi (vector unsigned char,
15638 vector unsigned char, int);
15639 @end smallexample
15640
15641 Note that the @samp{vec_ld} and @samp{vec_st} built-in functions always
15642 generate the AltiVec @samp{LVX} and @samp{STVX} instructions even
15643 if the VSX instruction set is available. The @samp{vec_vsx_ld} and
15644 @samp{vec_vsx_st} built-in functions always generate the VSX @samp{LXVD2X},
15645 @samp{LXVW4X}, @samp{STXVD2X}, and @samp{STXVW4X} instructions.
15646
15647 If the ISA 2.07 additions to the vector/scalar (power8-vector)
15648 instruction set is available, the following additional functions are
15649 available for both 32-bit and 64-bit targets. For 64-bit targets, you
15650 can use @var{vector long} instead of @var{vector long long},
15651 @var{vector bool long} instead of @var{vector bool long long}, and
15652 @var{vector unsigned long} instead of @var{vector unsigned long long}.
15653
15654 @smallexample
15655 vector long long vec_abs (vector long long);
15656
15657 vector long long vec_add (vector long long, vector long long);
15658 vector unsigned long long vec_add (vector unsigned long long,
15659 vector unsigned long long);
15660
15661 int vec_all_eq (vector long long, vector long long);
15662 int vec_all_eq (vector unsigned long long, vector unsigned long long);
15663 int vec_all_ge (vector long long, vector long long);
15664 int vec_all_ge (vector unsigned long long, vector unsigned long long);
15665 int vec_all_gt (vector long long, vector long long);
15666 int vec_all_gt (vector unsigned long long, vector unsigned long long);
15667 int vec_all_le (vector long long, vector long long);
15668 int vec_all_le (vector unsigned long long, vector unsigned long long);
15669 int vec_all_lt (vector long long, vector long long);
15670 int vec_all_lt (vector unsigned long long, vector unsigned long long);
15671 int vec_all_ne (vector long long, vector long long);
15672 int vec_all_ne (vector unsigned long long, vector unsigned long long);
15673
15674 int vec_any_eq (vector long long, vector long long);
15675 int vec_any_eq (vector unsigned long long, vector unsigned long long);
15676 int vec_any_ge (vector long long, vector long long);
15677 int vec_any_ge (vector unsigned long long, vector unsigned long long);
15678 int vec_any_gt (vector long long, vector long long);
15679 int vec_any_gt (vector unsigned long long, vector unsigned long long);
15680 int vec_any_le (vector long long, vector long long);
15681 int vec_any_le (vector unsigned long long, vector unsigned long long);
15682 int vec_any_lt (vector long long, vector long long);
15683 int vec_any_lt (vector unsigned long long, vector unsigned long long);
15684 int vec_any_ne (vector long long, vector long long);
15685 int vec_any_ne (vector unsigned long long, vector unsigned long long);
15686
15687 vector long long vec_eqv (vector long long, vector long long);
15688 vector long long vec_eqv (vector bool long long, vector long long);
15689 vector long long vec_eqv (vector long long, vector bool long long);
15690 vector unsigned long long vec_eqv (vector unsigned long long,
15691 vector unsigned long long);
15692 vector unsigned long long vec_eqv (vector bool long long,
15693 vector unsigned long long);
15694 vector unsigned long long vec_eqv (vector unsigned long long,
15695 vector bool long long);
15696 vector int vec_eqv (vector int, vector int);
15697 vector int vec_eqv (vector bool int, vector int);
15698 vector int vec_eqv (vector int, vector bool int);
15699 vector unsigned int vec_eqv (vector unsigned int, vector unsigned int);
15700 vector unsigned int vec_eqv (vector bool unsigned int,
15701 vector unsigned int);
15702 vector unsigned int vec_eqv (vector unsigned int,
15703 vector bool unsigned int);
15704 vector short vec_eqv (vector short, vector short);
15705 vector short vec_eqv (vector bool short, vector short);
15706 vector short vec_eqv (vector short, vector bool short);
15707 vector unsigned short vec_eqv (vector unsigned short, vector unsigned short);
15708 vector unsigned short vec_eqv (vector bool unsigned short,
15709 vector unsigned short);
15710 vector unsigned short vec_eqv (vector unsigned short,
15711 vector bool unsigned short);
15712 vector signed char vec_eqv (vector signed char, vector signed char);
15713 vector signed char vec_eqv (vector bool signed char, vector signed char);
15714 vector signed char vec_eqv (vector signed char, vector bool signed char);
15715 vector unsigned char vec_eqv (vector unsigned char, vector unsigned char);
15716 vector unsigned char vec_eqv (vector bool unsigned char, vector unsigned char);
15717 vector unsigned char vec_eqv (vector unsigned char, vector bool unsigned char);
15718
15719 vector long long vec_max (vector long long, vector long long);
15720 vector unsigned long long vec_max (vector unsigned long long,
15721 vector unsigned long long);
15722
15723 vector signed int vec_mergee (vector signed int, vector signed int);
15724 vector unsigned int vec_mergee (vector unsigned int, vector unsigned int);
15725 vector bool int vec_mergee (vector bool int, vector bool int);
15726
15727 vector signed int vec_mergeo (vector signed int, vector signed int);
15728 vector unsigned int vec_mergeo (vector unsigned int, vector unsigned int);
15729 vector bool int vec_mergeo (vector bool int, vector bool int);
15730
15731 vector long long vec_min (vector long long, vector long long);
15732 vector unsigned long long vec_min (vector unsigned long long,
15733 vector unsigned long long);
15734
15735 vector long long vec_nand (vector long long, vector long long);
15736 vector long long vec_nand (vector bool long long, vector long long);
15737 vector long long vec_nand (vector long long, vector bool long long);
15738 vector unsigned long long vec_nand (vector unsigned long long,
15739 vector unsigned long long);
15740 vector unsigned long long vec_nand (vector bool long long,
15741 vector unsigned long long);
15742 vector unsigned long long vec_nand (vector unsigned long long,
15743 vector bool long long);
15744 vector int vec_nand (vector int, vector int);
15745 vector int vec_nand (vector bool int, vector int);
15746 vector int vec_nand (vector int, vector bool int);
15747 vector unsigned int vec_nand (vector unsigned int, vector unsigned int);
15748 vector unsigned int vec_nand (vector bool unsigned int,
15749 vector unsigned int);
15750 vector unsigned int vec_nand (vector unsigned int,
15751 vector bool unsigned int);
15752 vector short vec_nand (vector short, vector short);
15753 vector short vec_nand (vector bool short, vector short);
15754 vector short vec_nand (vector short, vector bool short);
15755 vector unsigned short vec_nand (vector unsigned short, vector unsigned short);
15756 vector unsigned short vec_nand (vector bool unsigned short,
15757 vector unsigned short);
15758 vector unsigned short vec_nand (vector unsigned short,
15759 vector bool unsigned short);
15760 vector signed char vec_nand (vector signed char, vector signed char);
15761 vector signed char vec_nand (vector bool signed char, vector signed char);
15762 vector signed char vec_nand (vector signed char, vector bool signed char);
15763 vector unsigned char vec_nand (vector unsigned char, vector unsigned char);
15764 vector unsigned char vec_nand (vector bool unsigned char, vector unsigned char);
15765 vector unsigned char vec_nand (vector unsigned char, vector bool unsigned char);
15766
15767 vector long long vec_orc (vector long long, vector long long);
15768 vector long long vec_orc (vector bool long long, vector long long);
15769 vector long long vec_orc (vector long long, vector bool long long);
15770 vector unsigned long long vec_orc (vector unsigned long long,
15771 vector unsigned long long);
15772 vector unsigned long long vec_orc (vector bool long long,
15773 vector unsigned long long);
15774 vector unsigned long long vec_orc (vector unsigned long long,
15775 vector bool long long);
15776 vector int vec_orc (vector int, vector int);
15777 vector int vec_orc (vector bool int, vector int);
15778 vector int vec_orc (vector int, vector bool int);
15779 vector unsigned int vec_orc (vector unsigned int, vector unsigned int);
15780 vector unsigned int vec_orc (vector bool unsigned int,
15781 vector unsigned int);
15782 vector unsigned int vec_orc (vector unsigned int,
15783 vector bool unsigned int);
15784 vector short vec_orc (vector short, vector short);
15785 vector short vec_orc (vector bool short, vector short);
15786 vector short vec_orc (vector short, vector bool short);
15787 vector unsigned short vec_orc (vector unsigned short, vector unsigned short);
15788 vector unsigned short vec_orc (vector bool unsigned short,
15789 vector unsigned short);
15790 vector unsigned short vec_orc (vector unsigned short,
15791 vector bool unsigned short);
15792 vector signed char vec_orc (vector signed char, vector signed char);
15793 vector signed char vec_orc (vector bool signed char, vector signed char);
15794 vector signed char vec_orc (vector signed char, vector bool signed char);
15795 vector unsigned char vec_orc (vector unsigned char, vector unsigned char);
15796 vector unsigned char vec_orc (vector bool unsigned char, vector unsigned char);
15797 vector unsigned char vec_orc (vector unsigned char, vector bool unsigned char);
15798
15799 vector int vec_pack (vector long long, vector long long);
15800 vector unsigned int vec_pack (vector unsigned long long,
15801 vector unsigned long long);
15802 vector bool int vec_pack (vector bool long long, vector bool long long);
15803
15804 vector int vec_packs (vector long long, vector long long);
15805 vector unsigned int vec_packs (vector unsigned long long,
15806 vector unsigned long long);
15807
15808 vector unsigned int vec_packsu (vector long long, vector long long);
15809 vector unsigned int vec_packsu (vector unsigned long long,
15810 vector unsigned long long);
15811
15812 vector long long vec_rl (vector long long,
15813 vector unsigned long long);
15814 vector long long vec_rl (vector unsigned long long,
15815 vector unsigned long long);
15816
15817 vector long long vec_sl (vector long long, vector unsigned long long);
15818 vector long long vec_sl (vector unsigned long long,
15819 vector unsigned long long);
15820
15821 vector long long vec_sr (vector long long, vector unsigned long long);
15822 vector unsigned long long char vec_sr (vector unsigned long long,
15823 vector unsigned long long);
15824
15825 vector long long vec_sra (vector long long, vector unsigned long long);
15826 vector unsigned long long vec_sra (vector unsigned long long,
15827 vector unsigned long long);
15828
15829 vector long long vec_sub (vector long long, vector long long);
15830 vector unsigned long long vec_sub (vector unsigned long long,
15831 vector unsigned long long);
15832
15833 vector long long vec_unpackh (vector int);
15834 vector unsigned long long vec_unpackh (vector unsigned int);
15835
15836 vector long long vec_unpackl (vector int);
15837 vector unsigned long long vec_unpackl (vector unsigned int);
15838
15839 vector long long vec_vaddudm (vector long long, vector long long);
15840 vector long long vec_vaddudm (vector bool long long, vector long long);
15841 vector long long vec_vaddudm (vector long long, vector bool long long);
15842 vector unsigned long long vec_vaddudm (vector unsigned long long,
15843 vector unsigned long long);
15844 vector unsigned long long vec_vaddudm (vector bool unsigned long long,
15845 vector unsigned long long);
15846 vector unsigned long long vec_vaddudm (vector unsigned long long,
15847 vector bool unsigned long long);
15848
15849 vector long long vec_vbpermq (vector signed char, vector signed char);
15850 vector long long vec_vbpermq (vector unsigned char, vector unsigned char);
15851
15852 vector long long vec_cntlz (vector long long);
15853 vector unsigned long long vec_cntlz (vector unsigned long long);
15854 vector int vec_cntlz (vector int);
15855 vector unsigned int vec_cntlz (vector int);
15856 vector short vec_cntlz (vector short);
15857 vector unsigned short vec_cntlz (vector unsigned short);
15858 vector signed char vec_cntlz (vector signed char);
15859 vector unsigned char vec_cntlz (vector unsigned char);
15860
15861 vector long long vec_vclz (vector long long);
15862 vector unsigned long long vec_vclz (vector unsigned long long);
15863 vector int vec_vclz (vector int);
15864 vector unsigned int vec_vclz (vector int);
15865 vector short vec_vclz (vector short);
15866 vector unsigned short vec_vclz (vector unsigned short);
15867 vector signed char vec_vclz (vector signed char);
15868 vector unsigned char vec_vclz (vector unsigned char);
15869
15870 vector signed char vec_vclzb (vector signed char);
15871 vector unsigned char vec_vclzb (vector unsigned char);
15872
15873 vector long long vec_vclzd (vector long long);
15874 vector unsigned long long vec_vclzd (vector unsigned long long);
15875
15876 vector short vec_vclzh (vector short);
15877 vector unsigned short vec_vclzh (vector unsigned short);
15878
15879 vector int vec_vclzw (vector int);
15880 vector unsigned int vec_vclzw (vector int);
15881
15882 vector signed char vec_vgbbd (vector signed char);
15883 vector unsigned char vec_vgbbd (vector unsigned char);
15884
15885 vector long long vec_vmaxsd (vector long long, vector long long);
15886
15887 vector unsigned long long vec_vmaxud (vector unsigned long long,
15888 unsigned vector long long);
15889
15890 vector long long vec_vminsd (vector long long, vector long long);
15891
15892 vector unsigned long long vec_vminud (vector long long,
15893 vector long long);
15894
15895 vector int vec_vpksdss (vector long long, vector long long);
15896 vector unsigned int vec_vpksdss (vector long long, vector long long);
15897
15898 vector unsigned int vec_vpkudus (vector unsigned long long,
15899 vector unsigned long long);
15900
15901 vector int vec_vpkudum (vector long long, vector long long);
15902 vector unsigned int vec_vpkudum (vector unsigned long long,
15903 vector unsigned long long);
15904 vector bool int vec_vpkudum (vector bool long long, vector bool long long);
15905
15906 vector long long vec_vpopcnt (vector long long);
15907 vector unsigned long long vec_vpopcnt (vector unsigned long long);
15908 vector int vec_vpopcnt (vector int);
15909 vector unsigned int vec_vpopcnt (vector int);
15910 vector short vec_vpopcnt (vector short);
15911 vector unsigned short vec_vpopcnt (vector unsigned short);
15912 vector signed char vec_vpopcnt (vector signed char);
15913 vector unsigned char vec_vpopcnt (vector unsigned char);
15914
15915 vector signed char vec_vpopcntb (vector signed char);
15916 vector unsigned char vec_vpopcntb (vector unsigned char);
15917
15918 vector long long vec_vpopcntd (vector long long);
15919 vector unsigned long long vec_vpopcntd (vector unsigned long long);
15920
15921 vector short vec_vpopcnth (vector short);
15922 vector unsigned short vec_vpopcnth (vector unsigned short);
15923
15924 vector int vec_vpopcntw (vector int);
15925 vector unsigned int vec_vpopcntw (vector int);
15926
15927 vector long long vec_vrld (vector long long, vector unsigned long long);
15928 vector unsigned long long vec_vrld (vector unsigned long long,
15929 vector unsigned long long);
15930
15931 vector long long vec_vsld (vector long long, vector unsigned long long);
15932 vector long long vec_vsld (vector unsigned long long,
15933 vector unsigned long long);
15934
15935 vector long long vec_vsrad (vector long long, vector unsigned long long);
15936 vector unsigned long long vec_vsrad (vector unsigned long long,
15937 vector unsigned long long);
15938
15939 vector long long vec_vsrd (vector long long, vector unsigned long long);
15940 vector unsigned long long char vec_vsrd (vector unsigned long long,
15941 vector unsigned long long);
15942
15943 vector long long vec_vsubudm (vector long long, vector long long);
15944 vector long long vec_vsubudm (vector bool long long, vector long long);
15945 vector long long vec_vsubudm (vector long long, vector bool long long);
15946 vector unsigned long long vec_vsubudm (vector unsigned long long,
15947 vector unsigned long long);
15948 vector unsigned long long vec_vsubudm (vector bool long long,
15949 vector unsigned long long);
15950 vector unsigned long long vec_vsubudm (vector unsigned long long,
15951 vector bool long long);
15952
15953 vector long long vec_vupkhsw (vector int);
15954 vector unsigned long long vec_vupkhsw (vector unsigned int);
15955
15956 vector long long vec_vupklsw (vector int);
15957 vector unsigned long long vec_vupklsw (vector int);
15958 @end smallexample
15959
15960 If the ISA 2.07 additions to the vector/scalar (power8-vector)
15961 instruction set is available, the following additional functions are
15962 available for 64-bit targets. New vector types
15963 (@var{vector __int128_t} and @var{vector __uint128_t}) are available
15964 to hold the @var{__int128_t} and @var{__uint128_t} types to use these
15965 builtins.
15966
15967 The normal vector extract, and set operations work on
15968 @var{vector __int128_t} and @var{vector __uint128_t} types,
15969 but the index value must be 0.
15970
15971 @smallexample
15972 vector __int128_t vec_vaddcuq (vector __int128_t, vector __int128_t);
15973 vector __uint128_t vec_vaddcuq (vector __uint128_t, vector __uint128_t);
15974
15975 vector __int128_t vec_vadduqm (vector __int128_t, vector __int128_t);
15976 vector __uint128_t vec_vadduqm (vector __uint128_t, vector __uint128_t);
15977
15978 vector __int128_t vec_vaddecuq (vector __int128_t, vector __int128_t,
15979 vector __int128_t);
15980 vector __uint128_t vec_vaddecuq (vector __uint128_t, vector __uint128_t,
15981 vector __uint128_t);
15982
15983 vector __int128_t vec_vaddeuqm (vector __int128_t, vector __int128_t,
15984 vector __int128_t);
15985 vector __uint128_t vec_vaddeuqm (vector __uint128_t, vector __uint128_t,
15986 vector __uint128_t);
15987
15988 vector __int128_t vec_vsubecuq (vector __int128_t, vector __int128_t,
15989 vector __int128_t);
15990 vector __uint128_t vec_vsubecuq (vector __uint128_t, vector __uint128_t,
15991 vector __uint128_t);
15992
15993 vector __int128_t vec_vsubeuqm (vector __int128_t, vector __int128_t,
15994 vector __int128_t);
15995 vector __uint128_t vec_vsubeuqm (vector __uint128_t, vector __uint128_t,
15996 vector __uint128_t);
15997
15998 vector __int128_t vec_vsubcuq (vector __int128_t, vector __int128_t);
15999 vector __uint128_t vec_vsubcuq (vector __uint128_t, vector __uint128_t);
16000
16001 __int128_t vec_vsubuqm (__int128_t, __int128_t);
16002 __uint128_t vec_vsubuqm (__uint128_t, __uint128_t);
16003
16004 vector __int128_t __builtin_bcdadd (vector __int128_t, vector__int128_t);
16005 int __builtin_bcdadd_lt (vector __int128_t, vector__int128_t);
16006 int __builtin_bcdadd_eq (vector __int128_t, vector__int128_t);
16007 int __builtin_bcdadd_gt (vector __int128_t, vector__int128_t);
16008 int __builtin_bcdadd_ov (vector __int128_t, vector__int128_t);
16009 vector __int128_t bcdsub (vector __int128_t, vector__int128_t);
16010 int __builtin_bcdsub_lt (vector __int128_t, vector__int128_t);
16011 int __builtin_bcdsub_eq (vector __int128_t, vector__int128_t);
16012 int __builtin_bcdsub_gt (vector __int128_t, vector__int128_t);
16013 int __builtin_bcdsub_ov (vector __int128_t, vector__int128_t);
16014 @end smallexample
16015
16016 If the cryptographic instructions are enabled (@option{-mcrypto} or
16017 @option{-mcpu=power8}), the following builtins are enabled.
16018
16019 @smallexample
16020 vector unsigned long long __builtin_crypto_vsbox (vector unsigned long long);
16021
16022 vector unsigned long long __builtin_crypto_vcipher (vector unsigned long long,
16023 vector unsigned long long);
16024
16025 vector unsigned long long __builtin_crypto_vcipherlast
16026 (vector unsigned long long,
16027 vector unsigned long long);
16028
16029 vector unsigned long long __builtin_crypto_vncipher (vector unsigned long long,
16030 vector unsigned long long);
16031
16032 vector unsigned long long __builtin_crypto_vncipherlast
16033 (vector unsigned long long,
16034 vector unsigned long long);
16035
16036 vector unsigned char __builtin_crypto_vpermxor (vector unsigned char,
16037 vector unsigned char,
16038 vector unsigned char);
16039
16040 vector unsigned short __builtin_crypto_vpermxor (vector unsigned short,
16041 vector unsigned short,
16042 vector unsigned short);
16043
16044 vector unsigned int __builtin_crypto_vpermxor (vector unsigned int,
16045 vector unsigned int,
16046 vector unsigned int);
16047
16048 vector unsigned long long __builtin_crypto_vpermxor (vector unsigned long long,
16049 vector unsigned long long,
16050 vector unsigned long long);
16051
16052 vector unsigned char __builtin_crypto_vpmsumb (vector unsigned char,
16053 vector unsigned char);
16054
16055 vector unsigned short __builtin_crypto_vpmsumb (vector unsigned short,
16056 vector unsigned short);
16057
16058 vector unsigned int __builtin_crypto_vpmsumb (vector unsigned int,
16059 vector unsigned int);
16060
16061 vector unsigned long long __builtin_crypto_vpmsumb (vector unsigned long long,
16062 vector unsigned long long);
16063
16064 vector unsigned long long __builtin_crypto_vshasigmad
16065 (vector unsigned long long, int, int);
16066
16067 vector unsigned int __builtin_crypto_vshasigmaw (vector unsigned int,
16068 int, int);
16069 @end smallexample
16070
16071 The second argument to the @var{__builtin_crypto_vshasigmad} and
16072 @var{__builtin_crypto_vshasigmaw} builtin functions must be a constant
16073 integer that is 0 or 1. The third argument to these builtin functions
16074 must be a constant integer in the range of 0 to 15.
16075
16076 @node PowerPC Hardware Transactional Memory Built-in Functions
16077 @subsection PowerPC Hardware Transactional Memory Built-in Functions
16078 GCC provides two interfaces for accessing the Hardware Transactional
16079 Memory (HTM) instructions available on some of the PowerPC family
16080 of processors (eg, POWER8). The two interfaces come in a low level
16081 interface, consisting of built-in functions specific to PowerPC and a
16082 higher level interface consisting of inline functions that are common
16083 between PowerPC and S/390.
16084
16085 @subsubsection PowerPC HTM Low Level Built-in Functions
16086
16087 The following low level built-in functions are available with
16088 @option{-mhtm} or @option{-mcpu=CPU} where CPU is `power8' or later.
16089 They all generate the machine instruction that is part of the name.
16090
16091 The HTM builtins (with the exception of @code{__builtin_tbegin}) return
16092 the full 4-bit condition register value set by their associated hardware
16093 instruction. The header file @code{htmintrin.h} defines some macros that can
16094 be used to decipher the return value. The @code{__builtin_tbegin} builtin
16095 returns a simple true or false value depending on whether a transaction was
16096 successfully started or not. The arguments of the builtins match exactly the
16097 type and order of the associated hardware instruction's operands, except for
16098 the @code{__builtin_tcheck} builtin, which does not take any input arguments.
16099 Refer to the ISA manual for a description of each instruction's operands.
16100
16101 @smallexample
16102 unsigned int __builtin_tbegin (unsigned int)
16103 unsigned int __builtin_tend (unsigned int)
16104
16105 unsigned int __builtin_tabort (unsigned int)
16106 unsigned int __builtin_tabortdc (unsigned int, unsigned int, unsigned int)
16107 unsigned int __builtin_tabortdci (unsigned int, unsigned int, int)
16108 unsigned int __builtin_tabortwc (unsigned int, unsigned int, unsigned int)
16109 unsigned int __builtin_tabortwci (unsigned int, unsigned int, int)
16110
16111 unsigned int __builtin_tcheck (void)
16112 unsigned int __builtin_treclaim (unsigned int)
16113 unsigned int __builtin_trechkpt (void)
16114 unsigned int __builtin_tsr (unsigned int)
16115 @end smallexample
16116
16117 In addition to the above HTM built-ins, we have added built-ins for
16118 some common extended mnemonics of the HTM instructions:
16119
16120 @smallexample
16121 unsigned int __builtin_tendall (void)
16122 unsigned int __builtin_tresume (void)
16123 unsigned int __builtin_tsuspend (void)
16124 @end smallexample
16125
16126 Note that the semantics of the above HTM builtins are required to mimic
16127 the locking semantics used for critical sections. Builtins that are used
16128 to create a new transaction or restart a suspended transaction must have
16129 lock acquisition like semantics while those builtins that end or suspend a
16130 transaction must have lock release like semantics. Specifically, this must
16131 mimic lock semantics as specified by C++11, for example: Lock acquisition is
16132 as-if an execution of __atomic_exchange_n(&globallock,1,__ATOMIC_ACQUIRE)
16133 that returns 0, and lock release is as-if an execution of
16134 __atomic_store(&globallock,0,__ATOMIC_RELEASE), with globallock being an
16135 implicit implementation-defined lock used for all transactions. The HTM
16136 instructions associated with with the builtins inherently provide the
16137 correct acquisition and release hardware barriers required. However,
16138 the compiler must also be prohibited from moving loads and stores across
16139 the builtins in a way that would violate their semantics. This has been
16140 accomplished by adding memory barriers to the associated HTM instructions
16141 (which is a conservative approach to provide acquire and release semantics).
16142 Earlier versions of the compiler did not treat the HTM instructions as
16143 memory barriers. A @code{__TM_FENCE__} macro has been added, which can
16144 be used to determine whether the current compiler treats HTM instructions
16145 as memory barriers or not. This allows the user to explicitly add memory
16146 barriers to their code when using an older version of the compiler.
16147
16148 The following set of built-in functions are available to gain access
16149 to the HTM specific special purpose registers.
16150
16151 @smallexample
16152 unsigned long __builtin_get_texasr (void)
16153 unsigned long __builtin_get_texasru (void)
16154 unsigned long __builtin_get_tfhar (void)
16155 unsigned long __builtin_get_tfiar (void)
16156
16157 void __builtin_set_texasr (unsigned long);
16158 void __builtin_set_texasru (unsigned long);
16159 void __builtin_set_tfhar (unsigned long);
16160 void __builtin_set_tfiar (unsigned long);
16161 @end smallexample
16162
16163 Example usage of these low level built-in functions may look like:
16164
16165 @smallexample
16166 #include <htmintrin.h>
16167
16168 int num_retries = 10;
16169
16170 while (1)
16171 @{
16172 if (__builtin_tbegin (0))
16173 @{
16174 /* Transaction State Initiated. */
16175 if (is_locked (lock))
16176 __builtin_tabort (0);
16177 ... transaction code...
16178 __builtin_tend (0);
16179 break;
16180 @}
16181 else
16182 @{
16183 /* Transaction State Failed. Use locks if the transaction
16184 failure is "persistent" or we've tried too many times. */
16185 if (num_retries-- <= 0
16186 || _TEXASRU_FAILURE_PERSISTENT (__builtin_get_texasru ()))
16187 @{
16188 acquire_lock (lock);
16189 ... non transactional fallback path...
16190 release_lock (lock);
16191 break;
16192 @}
16193 @}
16194 @}
16195 @end smallexample
16196
16197 One final built-in function has been added that returns the value of
16198 the 2-bit Transaction State field of the Machine Status Register (MSR)
16199 as stored in @code{CR0}.
16200
16201 @smallexample
16202 unsigned long __builtin_ttest (void)
16203 @end smallexample
16204
16205 This built-in can be used to determine the current transaction state
16206 using the following code example:
16207
16208 @smallexample
16209 #include <htmintrin.h>
16210
16211 unsigned char tx_state = _HTM_STATE (__builtin_ttest ());
16212
16213 if (tx_state == _HTM_TRANSACTIONAL)
16214 @{
16215 /* Code to use in transactional state. */
16216 @}
16217 else if (tx_state == _HTM_NONTRANSACTIONAL)
16218 @{
16219 /* Code to use in non-transactional state. */
16220 @}
16221 else if (tx_state == _HTM_SUSPENDED)
16222 @{
16223 /* Code to use in transaction suspended state. */
16224 @}
16225 @end smallexample
16226
16227 @subsubsection PowerPC HTM High Level Inline Functions
16228
16229 The following high level HTM interface is made available by including
16230 @code{<htmxlintrin.h>} and using @option{-mhtm} or @option{-mcpu=CPU}
16231 where CPU is `power8' or later. This interface is common between PowerPC
16232 and S/390, allowing users to write one HTM source implementation that
16233 can be compiled and executed on either system.
16234
16235 @smallexample
16236 long __TM_simple_begin (void)
16237 long __TM_begin (void* const TM_buff)
16238 long __TM_end (void)
16239 void __TM_abort (void)
16240 void __TM_named_abort (unsigned char const code)
16241 void __TM_resume (void)
16242 void __TM_suspend (void)
16243
16244 long __TM_is_user_abort (void* const TM_buff)
16245 long __TM_is_named_user_abort (void* const TM_buff, unsigned char *code)
16246 long __TM_is_illegal (void* const TM_buff)
16247 long __TM_is_footprint_exceeded (void* const TM_buff)
16248 long __TM_nesting_depth (void* const TM_buff)
16249 long __TM_is_nested_too_deep(void* const TM_buff)
16250 long __TM_is_conflict(void* const TM_buff)
16251 long __TM_is_failure_persistent(void* const TM_buff)
16252 long __TM_failure_address(void* const TM_buff)
16253 long long __TM_failure_code(void* const TM_buff)
16254 @end smallexample
16255
16256 Using these common set of HTM inline functions, we can create
16257 a more portable version of the HTM example in the previous
16258 section that will work on either PowerPC or S/390:
16259
16260 @smallexample
16261 #include <htmxlintrin.h>
16262
16263 int num_retries = 10;
16264 TM_buff_type TM_buff;
16265
16266 while (1)
16267 @{
16268 if (__TM_begin (TM_buff) == _HTM_TBEGIN_STARTED)
16269 @{
16270 /* Transaction State Initiated. */
16271 if (is_locked (lock))
16272 __TM_abort ();
16273 ... transaction code...
16274 __TM_end ();
16275 break;
16276 @}
16277 else
16278 @{
16279 /* Transaction State Failed. Use locks if the transaction
16280 failure is "persistent" or we've tried too many times. */
16281 if (num_retries-- <= 0
16282 || __TM_is_failure_persistent (TM_buff))
16283 @{
16284 acquire_lock (lock);
16285 ... non transactional fallback path...
16286 release_lock (lock);
16287 break;
16288 @}
16289 @}
16290 @}
16291 @end smallexample
16292
16293 @node RX Built-in Functions
16294 @subsection RX Built-in Functions
16295 GCC supports some of the RX instructions which cannot be expressed in
16296 the C programming language via the use of built-in functions. The
16297 following functions are supported:
16298
16299 @deftypefn {Built-in Function} void __builtin_rx_brk (void)
16300 Generates the @code{brk} machine instruction.
16301 @end deftypefn
16302
16303 @deftypefn {Built-in Function} void __builtin_rx_clrpsw (int)
16304 Generates the @code{clrpsw} machine instruction to clear the specified
16305 bit in the processor status word.
16306 @end deftypefn
16307
16308 @deftypefn {Built-in Function} void __builtin_rx_int (int)
16309 Generates the @code{int} machine instruction to generate an interrupt
16310 with the specified value.
16311 @end deftypefn
16312
16313 @deftypefn {Built-in Function} void __builtin_rx_machi (int, int)
16314 Generates the @code{machi} machine instruction to add the result of
16315 multiplying the top 16 bits of the two arguments into the
16316 accumulator.
16317 @end deftypefn
16318
16319 @deftypefn {Built-in Function} void __builtin_rx_maclo (int, int)
16320 Generates the @code{maclo} machine instruction to add the result of
16321 multiplying the bottom 16 bits of the two arguments into the
16322 accumulator.
16323 @end deftypefn
16324
16325 @deftypefn {Built-in Function} void __builtin_rx_mulhi (int, int)
16326 Generates the @code{mulhi} machine instruction to place the result of
16327 multiplying the top 16 bits of the two arguments into the
16328 accumulator.
16329 @end deftypefn
16330
16331 @deftypefn {Built-in Function} void __builtin_rx_mullo (int, int)
16332 Generates the @code{mullo} machine instruction to place the result of
16333 multiplying the bottom 16 bits of the two arguments into the
16334 accumulator.
16335 @end deftypefn
16336
16337 @deftypefn {Built-in Function} int __builtin_rx_mvfachi (void)
16338 Generates the @code{mvfachi} machine instruction to read the top
16339 32 bits of the accumulator.
16340 @end deftypefn
16341
16342 @deftypefn {Built-in Function} int __builtin_rx_mvfacmi (void)
16343 Generates the @code{mvfacmi} machine instruction to read the middle
16344 32 bits of the accumulator.
16345 @end deftypefn
16346
16347 @deftypefn {Built-in Function} int __builtin_rx_mvfc (int)
16348 Generates the @code{mvfc} machine instruction which reads the control
16349 register specified in its argument and returns its value.
16350 @end deftypefn
16351
16352 @deftypefn {Built-in Function} void __builtin_rx_mvtachi (int)
16353 Generates the @code{mvtachi} machine instruction to set the top
16354 32 bits of the accumulator.
16355 @end deftypefn
16356
16357 @deftypefn {Built-in Function} void __builtin_rx_mvtaclo (int)
16358 Generates the @code{mvtaclo} machine instruction to set the bottom
16359 32 bits of the accumulator.
16360 @end deftypefn
16361
16362 @deftypefn {Built-in Function} void __builtin_rx_mvtc (int reg, int val)
16363 Generates the @code{mvtc} machine instruction which sets control
16364 register number @code{reg} to @code{val}.
16365 @end deftypefn
16366
16367 @deftypefn {Built-in Function} void __builtin_rx_mvtipl (int)
16368 Generates the @code{mvtipl} machine instruction set the interrupt
16369 priority level.
16370 @end deftypefn
16371
16372 @deftypefn {Built-in Function} void __builtin_rx_racw (int)
16373 Generates the @code{racw} machine instruction to round the accumulator
16374 according to the specified mode.
16375 @end deftypefn
16376
16377 @deftypefn {Built-in Function} int __builtin_rx_revw (int)
16378 Generates the @code{revw} machine instruction which swaps the bytes in
16379 the argument so that bits 0--7 now occupy bits 8--15 and vice versa,
16380 and also bits 16--23 occupy bits 24--31 and vice versa.
16381 @end deftypefn
16382
16383 @deftypefn {Built-in Function} void __builtin_rx_rmpa (void)
16384 Generates the @code{rmpa} machine instruction which initiates a
16385 repeated multiply and accumulate sequence.
16386 @end deftypefn
16387
16388 @deftypefn {Built-in Function} void __builtin_rx_round (float)
16389 Generates the @code{round} machine instruction which returns the
16390 floating-point argument rounded according to the current rounding mode
16391 set in the floating-point status word register.
16392 @end deftypefn
16393
16394 @deftypefn {Built-in Function} int __builtin_rx_sat (int)
16395 Generates the @code{sat} machine instruction which returns the
16396 saturated value of the argument.
16397 @end deftypefn
16398
16399 @deftypefn {Built-in Function} void __builtin_rx_setpsw (int)
16400 Generates the @code{setpsw} machine instruction to set the specified
16401 bit in the processor status word.
16402 @end deftypefn
16403
16404 @deftypefn {Built-in Function} void __builtin_rx_wait (void)
16405 Generates the @code{wait} machine instruction.
16406 @end deftypefn
16407
16408 @node S/390 System z Built-in Functions
16409 @subsection S/390 System z Built-in Functions
16410 @deftypefn {Built-in Function} int __builtin_tbegin (void*)
16411 Generates the @code{tbegin} machine instruction starting a
16412 non-constraint hardware transaction. If the parameter is non-NULL the
16413 memory area is used to store the transaction diagnostic buffer and
16414 will be passed as first operand to @code{tbegin}. This buffer can be
16415 defined using the @code{struct __htm_tdb} C struct defined in
16416 @code{htmintrin.h} and must reside on a double-word boundary. The
16417 second tbegin operand is set to @code{0xff0c}. This enables
16418 save/restore of all GPRs and disables aborts for FPR and AR
16419 manipulations inside the transaction body. The condition code set by
16420 the tbegin instruction is returned as integer value. The tbegin
16421 instruction by definition overwrites the content of all FPRs. The
16422 compiler will generate code which saves and restores the FPRs. For
16423 soft-float code it is recommended to used the @code{*_nofloat}
16424 variant. In order to prevent a TDB from being written it is required
16425 to pass an constant zero value as parameter. Passing the zero value
16426 through a variable is not sufficient. Although modifications of
16427 access registers inside the transaction will not trigger an
16428 transaction abort it is not supported to actually modify them. Access
16429 registers do not get saved when entering a transaction. They will have
16430 undefined state when reaching the abort code.
16431 @end deftypefn
16432
16433 Macros for the possible return codes of tbegin are defined in the
16434 @code{htmintrin.h} header file:
16435
16436 @table @code
16437 @item _HTM_TBEGIN_STARTED
16438 @code{tbegin} has been executed as part of normal processing. The
16439 transaction body is supposed to be executed.
16440 @item _HTM_TBEGIN_INDETERMINATE
16441 The transaction was aborted due to an indeterminate condition which
16442 might be persistent.
16443 @item _HTM_TBEGIN_TRANSIENT
16444 The transaction aborted due to a transient failure. The transaction
16445 should be re-executed in that case.
16446 @item _HTM_TBEGIN_PERSISTENT
16447 The transaction aborted due to a persistent failure. Re-execution
16448 under same circumstances will not be productive.
16449 @end table
16450
16451 @defmac _HTM_FIRST_USER_ABORT_CODE
16452 The @code{_HTM_FIRST_USER_ABORT_CODE} defined in @code{htmintrin.h}
16453 specifies the first abort code which can be used for
16454 @code{__builtin_tabort}. Values below this threshold are reserved for
16455 machine use.
16456 @end defmac
16457
16458 @deftp {Data type} {struct __htm_tdb}
16459 The @code{struct __htm_tdb} defined in @code{htmintrin.h} describes
16460 the structure of the transaction diagnostic block as specified in the
16461 Principles of Operation manual chapter 5-91.
16462 @end deftp
16463
16464 @deftypefn {Built-in Function} int __builtin_tbegin_nofloat (void*)
16465 Same as @code{__builtin_tbegin} but without FPR saves and restores.
16466 Using this variant in code making use of FPRs will leave the FPRs in
16467 undefined state when entering the transaction abort handler code.
16468 @end deftypefn
16469
16470 @deftypefn {Built-in Function} int __builtin_tbegin_retry (void*, int)
16471 In addition to @code{__builtin_tbegin} a loop for transient failures
16472 is generated. If tbegin returns a condition code of 2 the transaction
16473 will be retried as often as specified in the second argument. The
16474 perform processor assist instruction is used to tell the CPU about the
16475 number of fails so far.
16476 @end deftypefn
16477
16478 @deftypefn {Built-in Function} int __builtin_tbegin_retry_nofloat (void*, int)
16479 Same as @code{__builtin_tbegin_retry} but without FPR saves and
16480 restores. Using this variant in code making use of FPRs will leave
16481 the FPRs in undefined state when entering the transaction abort
16482 handler code.
16483 @end deftypefn
16484
16485 @deftypefn {Built-in Function} void __builtin_tbeginc (void)
16486 Generates the @code{tbeginc} machine instruction starting a constraint
16487 hardware transaction. The second operand is set to @code{0xff08}.
16488 @end deftypefn
16489
16490 @deftypefn {Built-in Function} int __builtin_tend (void)
16491 Generates the @code{tend} machine instruction finishing a transaction
16492 and making the changes visible to other threads. The condition code
16493 generated by tend is returned as integer value.
16494 @end deftypefn
16495
16496 @deftypefn {Built-in Function} void __builtin_tabort (int)
16497 Generates the @code{tabort} machine instruction with the specified
16498 abort code. Abort codes from 0 through 255 are reserved and will
16499 result in an error message.
16500 @end deftypefn
16501
16502 @deftypefn {Built-in Function} void __builtin_tx_assist (int)
16503 Generates the @code{ppa rX,rY,1} machine instruction. Where the
16504 integer parameter is loaded into rX and a value of zero is loaded into
16505 rY. The integer parameter specifies the number of times the
16506 transaction repeatedly aborted.
16507 @end deftypefn
16508
16509 @deftypefn {Built-in Function} int __builtin_tx_nesting_depth (void)
16510 Generates the @code{etnd} machine instruction. The current nesting
16511 depth is returned as integer value. For a nesting depth of 0 the code
16512 is not executed as part of an transaction.
16513 @end deftypefn
16514
16515 @deftypefn {Built-in Function} void __builtin_non_tx_store (uint64_t *, uint64_t)
16516
16517 Generates the @code{ntstg} machine instruction. The second argument
16518 is written to the first arguments location. The store operation will
16519 not be rolled-back in case of an transaction abort.
16520 @end deftypefn
16521
16522 @node SH Built-in Functions
16523 @subsection SH Built-in Functions
16524 The following built-in functions are supported on the SH1, SH2, SH3 and SH4
16525 families of processors:
16526
16527 @deftypefn {Built-in Function} {void} __builtin_set_thread_pointer (void *@var{ptr})
16528 Sets the @samp{GBR} register to the specified value @var{ptr}. This is usually
16529 used by system code that manages threads and execution contexts. The compiler
16530 normally does not generate code that modifies the contents of @samp{GBR} and
16531 thus the value is preserved across function calls. Changing the @samp{GBR}
16532 value in user code must be done with caution, since the compiler might use
16533 @samp{GBR} in order to access thread local variables.
16534
16535 @end deftypefn
16536
16537 @deftypefn {Built-in Function} {void *} __builtin_thread_pointer (void)
16538 Returns the value that is currently set in the @samp{GBR} register.
16539 Memory loads and stores that use the thread pointer as a base address are
16540 turned into @samp{GBR} based displacement loads and stores, if possible.
16541 For example:
16542 @smallexample
16543 struct my_tcb
16544 @{
16545 int a, b, c, d, e;
16546 @};
16547
16548 int get_tcb_value (void)
16549 @{
16550 // Generate @samp{mov.l @@(8,gbr),r0} instruction
16551 return ((my_tcb*)__builtin_thread_pointer ())->c;
16552 @}
16553
16554 @end smallexample
16555 @end deftypefn
16556
16557 @deftypefn {Built-in Function} {unsigned int} __builtin_sh_get_fpscr (void)
16558 Returns the value that is currently set in the @samp{FPSCR} register.
16559 @end deftypefn
16560
16561 @deftypefn {Built-in Function} {void} __builtin_sh_set_fpscr (unsigned int @var{val})
16562 Sets the @samp{FPSCR} register to the specified value @var{val}, while
16563 preserving the current values of the FR, SZ and PR bits.
16564 @end deftypefn
16565
16566 @node SPARC VIS Built-in Functions
16567 @subsection SPARC VIS Built-in Functions
16568
16569 GCC supports SIMD operations on the SPARC using both the generic vector
16570 extensions (@pxref{Vector Extensions}) as well as built-in functions for
16571 the SPARC Visual Instruction Set (VIS). When you use the @option{-mvis}
16572 switch, the VIS extension is exposed as the following built-in functions:
16573
16574 @smallexample
16575 typedef int v1si __attribute__ ((vector_size (4)));
16576 typedef int v2si __attribute__ ((vector_size (8)));
16577 typedef short v4hi __attribute__ ((vector_size (8)));
16578 typedef short v2hi __attribute__ ((vector_size (4)));
16579 typedef unsigned char v8qi __attribute__ ((vector_size (8)));
16580 typedef unsigned char v4qi __attribute__ ((vector_size (4)));
16581
16582 void __builtin_vis_write_gsr (int64_t);
16583 int64_t __builtin_vis_read_gsr (void);
16584
16585 void * __builtin_vis_alignaddr (void *, long);
16586 void * __builtin_vis_alignaddrl (void *, long);
16587 int64_t __builtin_vis_faligndatadi (int64_t, int64_t);
16588 v2si __builtin_vis_faligndatav2si (v2si, v2si);
16589 v4hi __builtin_vis_faligndatav4hi (v4si, v4si);
16590 v8qi __builtin_vis_faligndatav8qi (v8qi, v8qi);
16591
16592 v4hi __builtin_vis_fexpand (v4qi);
16593
16594 v4hi __builtin_vis_fmul8x16 (v4qi, v4hi);
16595 v4hi __builtin_vis_fmul8x16au (v4qi, v2hi);
16596 v4hi __builtin_vis_fmul8x16al (v4qi, v2hi);
16597 v4hi __builtin_vis_fmul8sux16 (v8qi, v4hi);
16598 v4hi __builtin_vis_fmul8ulx16 (v8qi, v4hi);
16599 v2si __builtin_vis_fmuld8sux16 (v4qi, v2hi);
16600 v2si __builtin_vis_fmuld8ulx16 (v4qi, v2hi);
16601
16602 v4qi __builtin_vis_fpack16 (v4hi);
16603 v8qi __builtin_vis_fpack32 (v2si, v8qi);
16604 v2hi __builtin_vis_fpackfix (v2si);
16605 v8qi __builtin_vis_fpmerge (v4qi, v4qi);
16606
16607 int64_t __builtin_vis_pdist (v8qi, v8qi, int64_t);
16608
16609 long __builtin_vis_edge8 (void *, void *);
16610 long __builtin_vis_edge8l (void *, void *);
16611 long __builtin_vis_edge16 (void *, void *);
16612 long __builtin_vis_edge16l (void *, void *);
16613 long __builtin_vis_edge32 (void *, void *);
16614 long __builtin_vis_edge32l (void *, void *);
16615
16616 long __builtin_vis_fcmple16 (v4hi, v4hi);
16617 long __builtin_vis_fcmple32 (v2si, v2si);
16618 long __builtin_vis_fcmpne16 (v4hi, v4hi);
16619 long __builtin_vis_fcmpne32 (v2si, v2si);
16620 long __builtin_vis_fcmpgt16 (v4hi, v4hi);
16621 long __builtin_vis_fcmpgt32 (v2si, v2si);
16622 long __builtin_vis_fcmpeq16 (v4hi, v4hi);
16623 long __builtin_vis_fcmpeq32 (v2si, v2si);
16624
16625 v4hi __builtin_vis_fpadd16 (v4hi, v4hi);
16626 v2hi __builtin_vis_fpadd16s (v2hi, v2hi);
16627 v2si __builtin_vis_fpadd32 (v2si, v2si);
16628 v1si __builtin_vis_fpadd32s (v1si, v1si);
16629 v4hi __builtin_vis_fpsub16 (v4hi, v4hi);
16630 v2hi __builtin_vis_fpsub16s (v2hi, v2hi);
16631 v2si __builtin_vis_fpsub32 (v2si, v2si);
16632 v1si __builtin_vis_fpsub32s (v1si, v1si);
16633
16634 long __builtin_vis_array8 (long, long);
16635 long __builtin_vis_array16 (long, long);
16636 long __builtin_vis_array32 (long, long);
16637 @end smallexample
16638
16639 When you use the @option{-mvis2} switch, the VIS version 2.0 built-in
16640 functions also become available:
16641
16642 @smallexample
16643 long __builtin_vis_bmask (long, long);
16644 int64_t __builtin_vis_bshuffledi (int64_t, int64_t);
16645 v2si __builtin_vis_bshufflev2si (v2si, v2si);
16646 v4hi __builtin_vis_bshufflev2si (v4hi, v4hi);
16647 v8qi __builtin_vis_bshufflev2si (v8qi, v8qi);
16648
16649 long __builtin_vis_edge8n (void *, void *);
16650 long __builtin_vis_edge8ln (void *, void *);
16651 long __builtin_vis_edge16n (void *, void *);
16652 long __builtin_vis_edge16ln (void *, void *);
16653 long __builtin_vis_edge32n (void *, void *);
16654 long __builtin_vis_edge32ln (void *, void *);
16655 @end smallexample
16656
16657 When you use the @option{-mvis3} switch, the VIS version 3.0 built-in
16658 functions also become available:
16659
16660 @smallexample
16661 void __builtin_vis_cmask8 (long);
16662 void __builtin_vis_cmask16 (long);
16663 void __builtin_vis_cmask32 (long);
16664
16665 v4hi __builtin_vis_fchksm16 (v4hi, v4hi);
16666
16667 v4hi __builtin_vis_fsll16 (v4hi, v4hi);
16668 v4hi __builtin_vis_fslas16 (v4hi, v4hi);
16669 v4hi __builtin_vis_fsrl16 (v4hi, v4hi);
16670 v4hi __builtin_vis_fsra16 (v4hi, v4hi);
16671 v2si __builtin_vis_fsll16 (v2si, v2si);
16672 v2si __builtin_vis_fslas16 (v2si, v2si);
16673 v2si __builtin_vis_fsrl16 (v2si, v2si);
16674 v2si __builtin_vis_fsra16 (v2si, v2si);
16675
16676 long __builtin_vis_pdistn (v8qi, v8qi);
16677
16678 v4hi __builtin_vis_fmean16 (v4hi, v4hi);
16679
16680 int64_t __builtin_vis_fpadd64 (int64_t, int64_t);
16681 int64_t __builtin_vis_fpsub64 (int64_t, int64_t);
16682
16683 v4hi __builtin_vis_fpadds16 (v4hi, v4hi);
16684 v2hi __builtin_vis_fpadds16s (v2hi, v2hi);
16685 v4hi __builtin_vis_fpsubs16 (v4hi, v4hi);
16686 v2hi __builtin_vis_fpsubs16s (v2hi, v2hi);
16687 v2si __builtin_vis_fpadds32 (v2si, v2si);
16688 v1si __builtin_vis_fpadds32s (v1si, v1si);
16689 v2si __builtin_vis_fpsubs32 (v2si, v2si);
16690 v1si __builtin_vis_fpsubs32s (v1si, v1si);
16691
16692 long __builtin_vis_fucmple8 (v8qi, v8qi);
16693 long __builtin_vis_fucmpne8 (v8qi, v8qi);
16694 long __builtin_vis_fucmpgt8 (v8qi, v8qi);
16695 long __builtin_vis_fucmpeq8 (v8qi, v8qi);
16696
16697 float __builtin_vis_fhadds (float, float);
16698 double __builtin_vis_fhaddd (double, double);
16699 float __builtin_vis_fhsubs (float, float);
16700 double __builtin_vis_fhsubd (double, double);
16701 float __builtin_vis_fnhadds (float, float);
16702 double __builtin_vis_fnhaddd (double, double);
16703
16704 int64_t __builtin_vis_umulxhi (int64_t, int64_t);
16705 int64_t __builtin_vis_xmulx (int64_t, int64_t);
16706 int64_t __builtin_vis_xmulxhi (int64_t, int64_t);
16707 @end smallexample
16708
16709 @node SPU Built-in Functions
16710 @subsection SPU Built-in Functions
16711
16712 GCC provides extensions for the SPU processor as described in the
16713 Sony/Toshiba/IBM SPU Language Extensions Specification, which can be
16714 found at @uref{http://cell.scei.co.jp/} or
16715 @uref{http://www.ibm.com/developerworks/power/cell/}. GCC's
16716 implementation differs in several ways.
16717
16718 @itemize @bullet
16719
16720 @item
16721 The optional extension of specifying vector constants in parentheses is
16722 not supported.
16723
16724 @item
16725 A vector initializer requires no cast if the vector constant is of the
16726 same type as the variable it is initializing.
16727
16728 @item
16729 If @code{signed} or @code{unsigned} is omitted, the signedness of the
16730 vector type is the default signedness of the base type. The default
16731 varies depending on the operating system, so a portable program should
16732 always specify the signedness.
16733
16734 @item
16735 By default, the keyword @code{__vector} is added. The macro
16736 @code{vector} is defined in @code{<spu_intrinsics.h>} and can be
16737 undefined.
16738
16739 @item
16740 GCC allows using a @code{typedef} name as the type specifier for a
16741 vector type.
16742
16743 @item
16744 For C, overloaded functions are implemented with macros so the following
16745 does not work:
16746
16747 @smallexample
16748 spu_add ((vector signed int)@{1, 2, 3, 4@}, foo);
16749 @end smallexample
16750
16751 @noindent
16752 Since @code{spu_add} is a macro, the vector constant in the example
16753 is treated as four separate arguments. Wrap the entire argument in
16754 parentheses for this to work.
16755
16756 @item
16757 The extended version of @code{__builtin_expect} is not supported.
16758
16759 @end itemize
16760
16761 @emph{Note:} Only the interface described in the aforementioned
16762 specification is supported. Internally, GCC uses built-in functions to
16763 implement the required functionality, but these are not supported and
16764 are subject to change without notice.
16765
16766 @node TI C6X Built-in Functions
16767 @subsection TI C6X Built-in Functions
16768
16769 GCC provides intrinsics to access certain instructions of the TI C6X
16770 processors. These intrinsics, listed below, are available after
16771 inclusion of the @code{c6x_intrinsics.h} header file. They map directly
16772 to C6X instructions.
16773
16774 @smallexample
16775
16776 int _sadd (int, int)
16777 int _ssub (int, int)
16778 int _sadd2 (int, int)
16779 int _ssub2 (int, int)
16780 long long _mpy2 (int, int)
16781 long long _smpy2 (int, int)
16782 int _add4 (int, int)
16783 int _sub4 (int, int)
16784 int _saddu4 (int, int)
16785
16786 int _smpy (int, int)
16787 int _smpyh (int, int)
16788 int _smpyhl (int, int)
16789 int _smpylh (int, int)
16790
16791 int _sshl (int, int)
16792 int _subc (int, int)
16793
16794 int _avg2 (int, int)
16795 int _avgu4 (int, int)
16796
16797 int _clrr (int, int)
16798 int _extr (int, int)
16799 int _extru (int, int)
16800 int _abs (int)
16801 int _abs2 (int)
16802
16803 @end smallexample
16804
16805 @node TILE-Gx Built-in Functions
16806 @subsection TILE-Gx Built-in Functions
16807
16808 GCC provides intrinsics to access every instruction of the TILE-Gx
16809 processor. The intrinsics are of the form:
16810
16811 @smallexample
16812
16813 unsigned long long __insn_@var{op} (...)
16814
16815 @end smallexample
16816
16817 Where @var{op} is the name of the instruction. Refer to the ISA manual
16818 for the complete list of instructions.
16819
16820 GCC also provides intrinsics to directly access the network registers.
16821 The intrinsics are:
16822
16823 @smallexample
16824
16825 unsigned long long __tile_idn0_receive (void)
16826 unsigned long long __tile_idn1_receive (void)
16827 unsigned long long __tile_udn0_receive (void)
16828 unsigned long long __tile_udn1_receive (void)
16829 unsigned long long __tile_udn2_receive (void)
16830 unsigned long long __tile_udn3_receive (void)
16831 void __tile_idn_send (unsigned long long)
16832 void __tile_udn_send (unsigned long long)
16833
16834 @end smallexample
16835
16836 The intrinsic @code{void __tile_network_barrier (void)} is used to
16837 guarantee that no network operations before it are reordered with
16838 those after it.
16839
16840 @node TILEPro Built-in Functions
16841 @subsection TILEPro Built-in Functions
16842
16843 GCC provides intrinsics to access every instruction of the TILEPro
16844 processor. The intrinsics are of the form:
16845
16846 @smallexample
16847
16848 unsigned __insn_@var{op} (...)
16849
16850 @end smallexample
16851
16852 @noindent
16853 where @var{op} is the name of the instruction. Refer to the ISA manual
16854 for the complete list of instructions.
16855
16856 GCC also provides intrinsics to directly access the network registers.
16857 The intrinsics are:
16858
16859 @smallexample
16860
16861 unsigned __tile_idn0_receive (void)
16862 unsigned __tile_idn1_receive (void)
16863 unsigned __tile_sn_receive (void)
16864 unsigned __tile_udn0_receive (void)
16865 unsigned __tile_udn1_receive (void)
16866 unsigned __tile_udn2_receive (void)
16867 unsigned __tile_udn3_receive (void)
16868 void __tile_idn_send (unsigned)
16869 void __tile_sn_send (unsigned)
16870 void __tile_udn_send (unsigned)
16871
16872 @end smallexample
16873
16874 The intrinsic @code{void __tile_network_barrier (void)} is used to
16875 guarantee that no network operations before it are reordered with
16876 those after it.
16877
16878 @node x86 Built-in Functions
16879 @subsection x86 Built-in Functions
16880
16881 These built-in functions are available for the x86-32 and x86-64 family
16882 of computers, depending on the command-line switches used.
16883
16884 If you specify command-line switches such as @option{-msse},
16885 the compiler could use the extended instruction sets even if the built-ins
16886 are not used explicitly in the program. For this reason, applications
16887 that perform run-time CPU detection must compile separate files for each
16888 supported architecture, using the appropriate flags. In particular,
16889 the file containing the CPU detection code should be compiled without
16890 these options.
16891
16892 The following machine modes are available for use with MMX built-in functions
16893 (@pxref{Vector Extensions}): @code{V2SI} for a vector of two 32-bit integers,
16894 @code{V4HI} for a vector of four 16-bit integers, and @code{V8QI} for a
16895 vector of eight 8-bit integers. Some of the built-in functions operate on
16896 MMX registers as a whole 64-bit entity, these use @code{V1DI} as their mode.
16897
16898 If 3DNow!@: extensions are enabled, @code{V2SF} is used as a mode for a vector
16899 of two 32-bit floating-point values.
16900
16901 If SSE extensions are enabled, @code{V4SF} is used for a vector of four 32-bit
16902 floating-point values. Some instructions use a vector of four 32-bit
16903 integers, these use @code{V4SI}. Finally, some instructions operate on an
16904 entire vector register, interpreting it as a 128-bit integer, these use mode
16905 @code{TI}.
16906
16907 In 64-bit mode, the x86-64 family of processors uses additional built-in
16908 functions for efficient use of @code{TF} (@code{__float128}) 128-bit
16909 floating point and @code{TC} 128-bit complex floating-point values.
16910
16911 The following floating-point built-in functions are available in 64-bit
16912 mode. All of them implement the function that is part of the name.
16913
16914 @smallexample
16915 __float128 __builtin_fabsq (__float128)
16916 __float128 __builtin_copysignq (__float128, __float128)
16917 @end smallexample
16918
16919 The following built-in function is always available.
16920
16921 @table @code
16922 @item void __builtin_ia32_pause (void)
16923 Generates the @code{pause} machine instruction with a compiler memory
16924 barrier.
16925 @end table
16926
16927 The following floating-point built-in functions are made available in the
16928 64-bit mode.
16929
16930 @table @code
16931 @item __float128 __builtin_infq (void)
16932 Similar to @code{__builtin_inf}, except the return type is @code{__float128}.
16933 @findex __builtin_infq
16934
16935 @item __float128 __builtin_huge_valq (void)
16936 Similar to @code{__builtin_huge_val}, except the return type is @code{__float128}.
16937 @findex __builtin_huge_valq
16938 @end table
16939
16940 The following built-in functions are always available and can be used to
16941 check the target platform type.
16942
16943 @deftypefn {Built-in Function} void __builtin_cpu_init (void)
16944 This function runs the CPU detection code to check the type of CPU and the
16945 features supported. This built-in function needs to be invoked along with the built-in functions
16946 to check CPU type and features, @code{__builtin_cpu_is} and
16947 @code{__builtin_cpu_supports}, only when used in a function that is
16948 executed before any constructors are called. The CPU detection code is
16949 automatically executed in a very high priority constructor.
16950
16951 For example, this function has to be used in @code{ifunc} resolvers that
16952 check for CPU type using the built-in functions @code{__builtin_cpu_is}
16953 and @code{__builtin_cpu_supports}, or in constructors on targets that
16954 don't support constructor priority.
16955 @smallexample
16956
16957 static void (*resolve_memcpy (void)) (void)
16958 @{
16959 // ifunc resolvers fire before constructors, explicitly call the init
16960 // function.
16961 __builtin_cpu_init ();
16962 if (__builtin_cpu_supports ("ssse3"))
16963 return ssse3_memcpy; // super fast memcpy with ssse3 instructions.
16964 else
16965 return default_memcpy;
16966 @}
16967
16968 void *memcpy (void *, const void *, size_t)
16969 __attribute__ ((ifunc ("resolve_memcpy")));
16970 @end smallexample
16971
16972 @end deftypefn
16973
16974 @deftypefn {Built-in Function} int __builtin_cpu_is (const char *@var{cpuname})
16975 This function returns a positive integer if the run-time CPU
16976 is of type @var{cpuname}
16977 and returns @code{0} otherwise. The following CPU names can be detected:
16978
16979 @table @samp
16980 @item intel
16981 Intel CPU.
16982
16983 @item atom
16984 Intel Atom CPU.
16985
16986 @item core2
16987 Intel Core 2 CPU.
16988
16989 @item corei7
16990 Intel Core i7 CPU.
16991
16992 @item nehalem
16993 Intel Core i7 Nehalem CPU.
16994
16995 @item westmere
16996 Intel Core i7 Westmere CPU.
16997
16998 @item sandybridge
16999 Intel Core i7 Sandy Bridge CPU.
17000
17001 @item amd
17002 AMD CPU.
17003
17004 @item amdfam10h
17005 AMD Family 10h CPU.
17006
17007 @item barcelona
17008 AMD Family 10h Barcelona CPU.
17009
17010 @item shanghai
17011 AMD Family 10h Shanghai CPU.
17012
17013 @item istanbul
17014 AMD Family 10h Istanbul CPU.
17015
17016 @item btver1
17017 AMD Family 14h CPU.
17018
17019 @item amdfam15h
17020 AMD Family 15h CPU.
17021
17022 @item bdver1
17023 AMD Family 15h Bulldozer version 1.
17024
17025 @item bdver2
17026 AMD Family 15h Bulldozer version 2.
17027
17028 @item bdver3
17029 AMD Family 15h Bulldozer version 3.
17030
17031 @item bdver4
17032 AMD Family 15h Bulldozer version 4.
17033
17034 @item btver2
17035 AMD Family 16h CPU.
17036
17037 @item znver1
17038 AMD Family 17h CPU.
17039 @end table
17040
17041 Here is an example:
17042 @smallexample
17043 if (__builtin_cpu_is ("corei7"))
17044 @{
17045 do_corei7 (); // Core i7 specific implementation.
17046 @}
17047 else
17048 @{
17049 do_generic (); // Generic implementation.
17050 @}
17051 @end smallexample
17052 @end deftypefn
17053
17054 @deftypefn {Built-in Function} int __builtin_cpu_supports (const char *@var{feature})
17055 This function returns a positive integer if the run-time CPU
17056 supports @var{feature}
17057 and returns @code{0} otherwise. The following features can be detected:
17058
17059 @table @samp
17060 @item cmov
17061 CMOV instruction.
17062 @item mmx
17063 MMX instructions.
17064 @item popcnt
17065 POPCNT instruction.
17066 @item sse
17067 SSE instructions.
17068 @item sse2
17069 SSE2 instructions.
17070 @item sse3
17071 SSE3 instructions.
17072 @item ssse3
17073 SSSE3 instructions.
17074 @item sse4.1
17075 SSE4.1 instructions.
17076 @item sse4.2
17077 SSE4.2 instructions.
17078 @item avx
17079 AVX instructions.
17080 @item avx2
17081 AVX2 instructions.
17082 @item avx512f
17083 AVX512F instructions.
17084 @end table
17085
17086 Here is an example:
17087 @smallexample
17088 if (__builtin_cpu_supports ("popcnt"))
17089 @{
17090 asm("popcnt %1,%0" : "=r"(count) : "rm"(n) : "cc");
17091 @}
17092 else
17093 @{
17094 count = generic_countbits (n); //generic implementation.
17095 @}
17096 @end smallexample
17097 @end deftypefn
17098
17099
17100 The following built-in functions are made available by @option{-mmmx}.
17101 All of them generate the machine instruction that is part of the name.
17102
17103 @smallexample
17104 v8qi __builtin_ia32_paddb (v8qi, v8qi)
17105 v4hi __builtin_ia32_paddw (v4hi, v4hi)
17106 v2si __builtin_ia32_paddd (v2si, v2si)
17107 v8qi __builtin_ia32_psubb (v8qi, v8qi)
17108 v4hi __builtin_ia32_psubw (v4hi, v4hi)
17109 v2si __builtin_ia32_psubd (v2si, v2si)
17110 v8qi __builtin_ia32_paddsb (v8qi, v8qi)
17111 v4hi __builtin_ia32_paddsw (v4hi, v4hi)
17112 v8qi __builtin_ia32_psubsb (v8qi, v8qi)
17113 v4hi __builtin_ia32_psubsw (v4hi, v4hi)
17114 v8qi __builtin_ia32_paddusb (v8qi, v8qi)
17115 v4hi __builtin_ia32_paddusw (v4hi, v4hi)
17116 v8qi __builtin_ia32_psubusb (v8qi, v8qi)
17117 v4hi __builtin_ia32_psubusw (v4hi, v4hi)
17118 v4hi __builtin_ia32_pmullw (v4hi, v4hi)
17119 v4hi __builtin_ia32_pmulhw (v4hi, v4hi)
17120 di __builtin_ia32_pand (di, di)
17121 di __builtin_ia32_pandn (di,di)
17122 di __builtin_ia32_por (di, di)
17123 di __builtin_ia32_pxor (di, di)
17124 v8qi __builtin_ia32_pcmpeqb (v8qi, v8qi)
17125 v4hi __builtin_ia32_pcmpeqw (v4hi, v4hi)
17126 v2si __builtin_ia32_pcmpeqd (v2si, v2si)
17127 v8qi __builtin_ia32_pcmpgtb (v8qi, v8qi)
17128 v4hi __builtin_ia32_pcmpgtw (v4hi, v4hi)
17129 v2si __builtin_ia32_pcmpgtd (v2si, v2si)
17130 v8qi __builtin_ia32_punpckhbw (v8qi, v8qi)
17131 v4hi __builtin_ia32_punpckhwd (v4hi, v4hi)
17132 v2si __builtin_ia32_punpckhdq (v2si, v2si)
17133 v8qi __builtin_ia32_punpcklbw (v8qi, v8qi)
17134 v4hi __builtin_ia32_punpcklwd (v4hi, v4hi)
17135 v2si __builtin_ia32_punpckldq (v2si, v2si)
17136 v8qi __builtin_ia32_packsswb (v4hi, v4hi)
17137 v4hi __builtin_ia32_packssdw (v2si, v2si)
17138 v8qi __builtin_ia32_packuswb (v4hi, v4hi)
17139
17140 v4hi __builtin_ia32_psllw (v4hi, v4hi)
17141 v2si __builtin_ia32_pslld (v2si, v2si)
17142 v1di __builtin_ia32_psllq (v1di, v1di)
17143 v4hi __builtin_ia32_psrlw (v4hi, v4hi)
17144 v2si __builtin_ia32_psrld (v2si, v2si)
17145 v1di __builtin_ia32_psrlq (v1di, v1di)
17146 v4hi __builtin_ia32_psraw (v4hi, v4hi)
17147 v2si __builtin_ia32_psrad (v2si, v2si)
17148 v4hi __builtin_ia32_psllwi (v4hi, int)
17149 v2si __builtin_ia32_pslldi (v2si, int)
17150 v1di __builtin_ia32_psllqi (v1di, int)
17151 v4hi __builtin_ia32_psrlwi (v4hi, int)
17152 v2si __builtin_ia32_psrldi (v2si, int)
17153 v1di __builtin_ia32_psrlqi (v1di, int)
17154 v4hi __builtin_ia32_psrawi (v4hi, int)
17155 v2si __builtin_ia32_psradi (v2si, int)
17156
17157 @end smallexample
17158
17159 The following built-in functions are made available either with
17160 @option{-msse}, or with a combination of @option{-m3dnow} and
17161 @option{-march=athlon}. All of them generate the machine
17162 instruction that is part of the name.
17163
17164 @smallexample
17165 v4hi __builtin_ia32_pmulhuw (v4hi, v4hi)
17166 v8qi __builtin_ia32_pavgb (v8qi, v8qi)
17167 v4hi __builtin_ia32_pavgw (v4hi, v4hi)
17168 v1di __builtin_ia32_psadbw (v8qi, v8qi)
17169 v8qi __builtin_ia32_pmaxub (v8qi, v8qi)
17170 v4hi __builtin_ia32_pmaxsw (v4hi, v4hi)
17171 v8qi __builtin_ia32_pminub (v8qi, v8qi)
17172 v4hi __builtin_ia32_pminsw (v4hi, v4hi)
17173 int __builtin_ia32_pmovmskb (v8qi)
17174 void __builtin_ia32_maskmovq (v8qi, v8qi, char *)
17175 void __builtin_ia32_movntq (di *, di)
17176 void __builtin_ia32_sfence (void)
17177 @end smallexample
17178
17179 The following built-in functions are available when @option{-msse} is used.
17180 All of them generate the machine instruction that is part of the name.
17181
17182 @smallexample
17183 int __builtin_ia32_comieq (v4sf, v4sf)
17184 int __builtin_ia32_comineq (v4sf, v4sf)
17185 int __builtin_ia32_comilt (v4sf, v4sf)
17186 int __builtin_ia32_comile (v4sf, v4sf)
17187 int __builtin_ia32_comigt (v4sf, v4sf)
17188 int __builtin_ia32_comige (v4sf, v4sf)
17189 int __builtin_ia32_ucomieq (v4sf, v4sf)
17190 int __builtin_ia32_ucomineq (v4sf, v4sf)
17191 int __builtin_ia32_ucomilt (v4sf, v4sf)
17192 int __builtin_ia32_ucomile (v4sf, v4sf)
17193 int __builtin_ia32_ucomigt (v4sf, v4sf)
17194 int __builtin_ia32_ucomige (v4sf, v4sf)
17195 v4sf __builtin_ia32_addps (v4sf, v4sf)
17196 v4sf __builtin_ia32_subps (v4sf, v4sf)
17197 v4sf __builtin_ia32_mulps (v4sf, v4sf)
17198 v4sf __builtin_ia32_divps (v4sf, v4sf)
17199 v4sf __builtin_ia32_addss (v4sf, v4sf)
17200 v4sf __builtin_ia32_subss (v4sf, v4sf)
17201 v4sf __builtin_ia32_mulss (v4sf, v4sf)
17202 v4sf __builtin_ia32_divss (v4sf, v4sf)
17203 v4sf __builtin_ia32_cmpeqps (v4sf, v4sf)
17204 v4sf __builtin_ia32_cmpltps (v4sf, v4sf)
17205 v4sf __builtin_ia32_cmpleps (v4sf, v4sf)
17206 v4sf __builtin_ia32_cmpgtps (v4sf, v4sf)
17207 v4sf __builtin_ia32_cmpgeps (v4sf, v4sf)
17208 v4sf __builtin_ia32_cmpunordps (v4sf, v4sf)
17209 v4sf __builtin_ia32_cmpneqps (v4sf, v4sf)
17210 v4sf __builtin_ia32_cmpnltps (v4sf, v4sf)
17211 v4sf __builtin_ia32_cmpnleps (v4sf, v4sf)
17212 v4sf __builtin_ia32_cmpngtps (v4sf, v4sf)
17213 v4sf __builtin_ia32_cmpngeps (v4sf, v4sf)
17214 v4sf __builtin_ia32_cmpordps (v4sf, v4sf)
17215 v4sf __builtin_ia32_cmpeqss (v4sf, v4sf)
17216 v4sf __builtin_ia32_cmpltss (v4sf, v4sf)
17217 v4sf __builtin_ia32_cmpless (v4sf, v4sf)
17218 v4sf __builtin_ia32_cmpunordss (v4sf, v4sf)
17219 v4sf __builtin_ia32_cmpneqss (v4sf, v4sf)
17220 v4sf __builtin_ia32_cmpnltss (v4sf, v4sf)
17221 v4sf __builtin_ia32_cmpnless (v4sf, v4sf)
17222 v4sf __builtin_ia32_cmpordss (v4sf, v4sf)
17223 v4sf __builtin_ia32_maxps (v4sf, v4sf)
17224 v4sf __builtin_ia32_maxss (v4sf, v4sf)
17225 v4sf __builtin_ia32_minps (v4sf, v4sf)
17226 v4sf __builtin_ia32_minss (v4sf, v4sf)
17227 v4sf __builtin_ia32_andps (v4sf, v4sf)
17228 v4sf __builtin_ia32_andnps (v4sf, v4sf)
17229 v4sf __builtin_ia32_orps (v4sf, v4sf)
17230 v4sf __builtin_ia32_xorps (v4sf, v4sf)
17231 v4sf __builtin_ia32_movss (v4sf, v4sf)
17232 v4sf __builtin_ia32_movhlps (v4sf, v4sf)
17233 v4sf __builtin_ia32_movlhps (v4sf, v4sf)
17234 v4sf __builtin_ia32_unpckhps (v4sf, v4sf)
17235 v4sf __builtin_ia32_unpcklps (v4sf, v4sf)
17236 v4sf __builtin_ia32_cvtpi2ps (v4sf, v2si)
17237 v4sf __builtin_ia32_cvtsi2ss (v4sf, int)
17238 v2si __builtin_ia32_cvtps2pi (v4sf)
17239 int __builtin_ia32_cvtss2si (v4sf)
17240 v2si __builtin_ia32_cvttps2pi (v4sf)
17241 int __builtin_ia32_cvttss2si (v4sf)
17242 v4sf __builtin_ia32_rcpps (v4sf)
17243 v4sf __builtin_ia32_rsqrtps (v4sf)
17244 v4sf __builtin_ia32_sqrtps (v4sf)
17245 v4sf __builtin_ia32_rcpss (v4sf)
17246 v4sf __builtin_ia32_rsqrtss (v4sf)
17247 v4sf __builtin_ia32_sqrtss (v4sf)
17248 v4sf __builtin_ia32_shufps (v4sf, v4sf, int)
17249 void __builtin_ia32_movntps (float *, v4sf)
17250 int __builtin_ia32_movmskps (v4sf)
17251 @end smallexample
17252
17253 The following built-in functions are available when @option{-msse} is used.
17254
17255 @table @code
17256 @item v4sf __builtin_ia32_loadups (float *)
17257 Generates the @code{movups} machine instruction as a load from memory.
17258 @item void __builtin_ia32_storeups (float *, v4sf)
17259 Generates the @code{movups} machine instruction as a store to memory.
17260 @item v4sf __builtin_ia32_loadss (float *)
17261 Generates the @code{movss} machine instruction as a load from memory.
17262 @item v4sf __builtin_ia32_loadhps (v4sf, const v2sf *)
17263 Generates the @code{movhps} machine instruction as a load from memory.
17264 @item v4sf __builtin_ia32_loadlps (v4sf, const v2sf *)
17265 Generates the @code{movlps} machine instruction as a load from memory
17266 @item void __builtin_ia32_storehps (v2sf *, v4sf)
17267 Generates the @code{movhps} machine instruction as a store to memory.
17268 @item void __builtin_ia32_storelps (v2sf *, v4sf)
17269 Generates the @code{movlps} machine instruction as a store to memory.
17270 @end table
17271
17272 The following built-in functions are available when @option{-msse2} is used.
17273 All of them generate the machine instruction that is part of the name.
17274
17275 @smallexample
17276 int __builtin_ia32_comisdeq (v2df, v2df)
17277 int __builtin_ia32_comisdlt (v2df, v2df)
17278 int __builtin_ia32_comisdle (v2df, v2df)
17279 int __builtin_ia32_comisdgt (v2df, v2df)
17280 int __builtin_ia32_comisdge (v2df, v2df)
17281 int __builtin_ia32_comisdneq (v2df, v2df)
17282 int __builtin_ia32_ucomisdeq (v2df, v2df)
17283 int __builtin_ia32_ucomisdlt (v2df, v2df)
17284 int __builtin_ia32_ucomisdle (v2df, v2df)
17285 int __builtin_ia32_ucomisdgt (v2df, v2df)
17286 int __builtin_ia32_ucomisdge (v2df, v2df)
17287 int __builtin_ia32_ucomisdneq (v2df, v2df)
17288 v2df __builtin_ia32_cmpeqpd (v2df, v2df)
17289 v2df __builtin_ia32_cmpltpd (v2df, v2df)
17290 v2df __builtin_ia32_cmplepd (v2df, v2df)
17291 v2df __builtin_ia32_cmpgtpd (v2df, v2df)
17292 v2df __builtin_ia32_cmpgepd (v2df, v2df)
17293 v2df __builtin_ia32_cmpunordpd (v2df, v2df)
17294 v2df __builtin_ia32_cmpneqpd (v2df, v2df)
17295 v2df __builtin_ia32_cmpnltpd (v2df, v2df)
17296 v2df __builtin_ia32_cmpnlepd (v2df, v2df)
17297 v2df __builtin_ia32_cmpngtpd (v2df, v2df)
17298 v2df __builtin_ia32_cmpngepd (v2df, v2df)
17299 v2df __builtin_ia32_cmpordpd (v2df, v2df)
17300 v2df __builtin_ia32_cmpeqsd (v2df, v2df)
17301 v2df __builtin_ia32_cmpltsd (v2df, v2df)
17302 v2df __builtin_ia32_cmplesd (v2df, v2df)
17303 v2df __builtin_ia32_cmpunordsd (v2df, v2df)
17304 v2df __builtin_ia32_cmpneqsd (v2df, v2df)
17305 v2df __builtin_ia32_cmpnltsd (v2df, v2df)
17306 v2df __builtin_ia32_cmpnlesd (v2df, v2df)
17307 v2df __builtin_ia32_cmpordsd (v2df, v2df)
17308 v2di __builtin_ia32_paddq (v2di, v2di)
17309 v2di __builtin_ia32_psubq (v2di, v2di)
17310 v2df __builtin_ia32_addpd (v2df, v2df)
17311 v2df __builtin_ia32_subpd (v2df, v2df)
17312 v2df __builtin_ia32_mulpd (v2df, v2df)
17313 v2df __builtin_ia32_divpd (v2df, v2df)
17314 v2df __builtin_ia32_addsd (v2df, v2df)
17315 v2df __builtin_ia32_subsd (v2df, v2df)
17316 v2df __builtin_ia32_mulsd (v2df, v2df)
17317 v2df __builtin_ia32_divsd (v2df, v2df)
17318 v2df __builtin_ia32_minpd (v2df, v2df)
17319 v2df __builtin_ia32_maxpd (v2df, v2df)
17320 v2df __builtin_ia32_minsd (v2df, v2df)
17321 v2df __builtin_ia32_maxsd (v2df, v2df)
17322 v2df __builtin_ia32_andpd (v2df, v2df)
17323 v2df __builtin_ia32_andnpd (v2df, v2df)
17324 v2df __builtin_ia32_orpd (v2df, v2df)
17325 v2df __builtin_ia32_xorpd (v2df, v2df)
17326 v2df __builtin_ia32_movsd (v2df, v2df)
17327 v2df __builtin_ia32_unpckhpd (v2df, v2df)
17328 v2df __builtin_ia32_unpcklpd (v2df, v2df)
17329 v16qi __builtin_ia32_paddb128 (v16qi, v16qi)
17330 v8hi __builtin_ia32_paddw128 (v8hi, v8hi)
17331 v4si __builtin_ia32_paddd128 (v4si, v4si)
17332 v2di __builtin_ia32_paddq128 (v2di, v2di)
17333 v16qi __builtin_ia32_psubb128 (v16qi, v16qi)
17334 v8hi __builtin_ia32_psubw128 (v8hi, v8hi)
17335 v4si __builtin_ia32_psubd128 (v4si, v4si)
17336 v2di __builtin_ia32_psubq128 (v2di, v2di)
17337 v8hi __builtin_ia32_pmullw128 (v8hi, v8hi)
17338 v8hi __builtin_ia32_pmulhw128 (v8hi, v8hi)
17339 v2di __builtin_ia32_pand128 (v2di, v2di)
17340 v2di __builtin_ia32_pandn128 (v2di, v2di)
17341 v2di __builtin_ia32_por128 (v2di, v2di)
17342 v2di __builtin_ia32_pxor128 (v2di, v2di)
17343 v16qi __builtin_ia32_pavgb128 (v16qi, v16qi)
17344 v8hi __builtin_ia32_pavgw128 (v8hi, v8hi)
17345 v16qi __builtin_ia32_pcmpeqb128 (v16qi, v16qi)
17346 v8hi __builtin_ia32_pcmpeqw128 (v8hi, v8hi)
17347 v4si __builtin_ia32_pcmpeqd128 (v4si, v4si)
17348 v16qi __builtin_ia32_pcmpgtb128 (v16qi, v16qi)
17349 v8hi __builtin_ia32_pcmpgtw128 (v8hi, v8hi)
17350 v4si __builtin_ia32_pcmpgtd128 (v4si, v4si)
17351 v16qi __builtin_ia32_pmaxub128 (v16qi, v16qi)
17352 v8hi __builtin_ia32_pmaxsw128 (v8hi, v8hi)
17353 v16qi __builtin_ia32_pminub128 (v16qi, v16qi)
17354 v8hi __builtin_ia32_pminsw128 (v8hi, v8hi)
17355 v16qi __builtin_ia32_punpckhbw128 (v16qi, v16qi)
17356 v8hi __builtin_ia32_punpckhwd128 (v8hi, v8hi)
17357 v4si __builtin_ia32_punpckhdq128 (v4si, v4si)
17358 v2di __builtin_ia32_punpckhqdq128 (v2di, v2di)
17359 v16qi __builtin_ia32_punpcklbw128 (v16qi, v16qi)
17360 v8hi __builtin_ia32_punpcklwd128 (v8hi, v8hi)
17361 v4si __builtin_ia32_punpckldq128 (v4si, v4si)
17362 v2di __builtin_ia32_punpcklqdq128 (v2di, v2di)
17363 v16qi __builtin_ia32_packsswb128 (v8hi, v8hi)
17364 v8hi __builtin_ia32_packssdw128 (v4si, v4si)
17365 v16qi __builtin_ia32_packuswb128 (v8hi, v8hi)
17366 v8hi __builtin_ia32_pmulhuw128 (v8hi, v8hi)
17367 void __builtin_ia32_maskmovdqu (v16qi, v16qi)
17368 v2df __builtin_ia32_loadupd (double *)
17369 void __builtin_ia32_storeupd (double *, v2df)
17370 v2df __builtin_ia32_loadhpd (v2df, double const *)
17371 v2df __builtin_ia32_loadlpd (v2df, double const *)
17372 int __builtin_ia32_movmskpd (v2df)
17373 int __builtin_ia32_pmovmskb128 (v16qi)
17374 void __builtin_ia32_movnti (int *, int)
17375 void __builtin_ia32_movnti64 (long long int *, long long int)
17376 void __builtin_ia32_movntpd (double *, v2df)
17377 void __builtin_ia32_movntdq (v2df *, v2df)
17378 v4si __builtin_ia32_pshufd (v4si, int)
17379 v8hi __builtin_ia32_pshuflw (v8hi, int)
17380 v8hi __builtin_ia32_pshufhw (v8hi, int)
17381 v2di __builtin_ia32_psadbw128 (v16qi, v16qi)
17382 v2df __builtin_ia32_sqrtpd (v2df)
17383 v2df __builtin_ia32_sqrtsd (v2df)
17384 v2df __builtin_ia32_shufpd (v2df, v2df, int)
17385 v2df __builtin_ia32_cvtdq2pd (v4si)
17386 v4sf __builtin_ia32_cvtdq2ps (v4si)
17387 v4si __builtin_ia32_cvtpd2dq (v2df)
17388 v2si __builtin_ia32_cvtpd2pi (v2df)
17389 v4sf __builtin_ia32_cvtpd2ps (v2df)
17390 v4si __builtin_ia32_cvttpd2dq (v2df)
17391 v2si __builtin_ia32_cvttpd2pi (v2df)
17392 v2df __builtin_ia32_cvtpi2pd (v2si)
17393 int __builtin_ia32_cvtsd2si (v2df)
17394 int __builtin_ia32_cvttsd2si (v2df)
17395 long long __builtin_ia32_cvtsd2si64 (v2df)
17396 long long __builtin_ia32_cvttsd2si64 (v2df)
17397 v4si __builtin_ia32_cvtps2dq (v4sf)
17398 v2df __builtin_ia32_cvtps2pd (v4sf)
17399 v4si __builtin_ia32_cvttps2dq (v4sf)
17400 v2df __builtin_ia32_cvtsi2sd (v2df, int)
17401 v2df __builtin_ia32_cvtsi642sd (v2df, long long)
17402 v4sf __builtin_ia32_cvtsd2ss (v4sf, v2df)
17403 v2df __builtin_ia32_cvtss2sd (v2df, v4sf)
17404 void __builtin_ia32_clflush (const void *)
17405 void __builtin_ia32_lfence (void)
17406 void __builtin_ia32_mfence (void)
17407 v16qi __builtin_ia32_loaddqu (const char *)
17408 void __builtin_ia32_storedqu (char *, v16qi)
17409 v1di __builtin_ia32_pmuludq (v2si, v2si)
17410 v2di __builtin_ia32_pmuludq128 (v4si, v4si)
17411 v8hi __builtin_ia32_psllw128 (v8hi, v8hi)
17412 v4si __builtin_ia32_pslld128 (v4si, v4si)
17413 v2di __builtin_ia32_psllq128 (v2di, v2di)
17414 v8hi __builtin_ia32_psrlw128 (v8hi, v8hi)
17415 v4si __builtin_ia32_psrld128 (v4si, v4si)
17416 v2di __builtin_ia32_psrlq128 (v2di, v2di)
17417 v8hi __builtin_ia32_psraw128 (v8hi, v8hi)
17418 v4si __builtin_ia32_psrad128 (v4si, v4si)
17419 v2di __builtin_ia32_pslldqi128 (v2di, int)
17420 v8hi __builtin_ia32_psllwi128 (v8hi, int)
17421 v4si __builtin_ia32_pslldi128 (v4si, int)
17422 v2di __builtin_ia32_psllqi128 (v2di, int)
17423 v2di __builtin_ia32_psrldqi128 (v2di, int)
17424 v8hi __builtin_ia32_psrlwi128 (v8hi, int)
17425 v4si __builtin_ia32_psrldi128 (v4si, int)
17426 v2di __builtin_ia32_psrlqi128 (v2di, int)
17427 v8hi __builtin_ia32_psrawi128 (v8hi, int)
17428 v4si __builtin_ia32_psradi128 (v4si, int)
17429 v4si __builtin_ia32_pmaddwd128 (v8hi, v8hi)
17430 v2di __builtin_ia32_movq128 (v2di)
17431 @end smallexample
17432
17433 The following built-in functions are available when @option{-msse3} is used.
17434 All of them generate the machine instruction that is part of the name.
17435
17436 @smallexample
17437 v2df __builtin_ia32_addsubpd (v2df, v2df)
17438 v4sf __builtin_ia32_addsubps (v4sf, v4sf)
17439 v2df __builtin_ia32_haddpd (v2df, v2df)
17440 v4sf __builtin_ia32_haddps (v4sf, v4sf)
17441 v2df __builtin_ia32_hsubpd (v2df, v2df)
17442 v4sf __builtin_ia32_hsubps (v4sf, v4sf)
17443 v16qi __builtin_ia32_lddqu (char const *)
17444 void __builtin_ia32_monitor (void *, unsigned int, unsigned int)
17445 v4sf __builtin_ia32_movshdup (v4sf)
17446 v4sf __builtin_ia32_movsldup (v4sf)
17447 void __builtin_ia32_mwait (unsigned int, unsigned int)
17448 @end smallexample
17449
17450 The following built-in functions are available when @option{-mssse3} is used.
17451 All of them generate the machine instruction that is part of the name.
17452
17453 @smallexample
17454 v2si __builtin_ia32_phaddd (v2si, v2si)
17455 v4hi __builtin_ia32_phaddw (v4hi, v4hi)
17456 v4hi __builtin_ia32_phaddsw (v4hi, v4hi)
17457 v2si __builtin_ia32_phsubd (v2si, v2si)
17458 v4hi __builtin_ia32_phsubw (v4hi, v4hi)
17459 v4hi __builtin_ia32_phsubsw (v4hi, v4hi)
17460 v4hi __builtin_ia32_pmaddubsw (v8qi, v8qi)
17461 v4hi __builtin_ia32_pmulhrsw (v4hi, v4hi)
17462 v8qi __builtin_ia32_pshufb (v8qi, v8qi)
17463 v8qi __builtin_ia32_psignb (v8qi, v8qi)
17464 v2si __builtin_ia32_psignd (v2si, v2si)
17465 v4hi __builtin_ia32_psignw (v4hi, v4hi)
17466 v1di __builtin_ia32_palignr (v1di, v1di, int)
17467 v8qi __builtin_ia32_pabsb (v8qi)
17468 v2si __builtin_ia32_pabsd (v2si)
17469 v4hi __builtin_ia32_pabsw (v4hi)
17470 @end smallexample
17471
17472 The following built-in functions are available when @option{-mssse3} is used.
17473 All of them generate the machine instruction that is part of the name.
17474
17475 @smallexample
17476 v4si __builtin_ia32_phaddd128 (v4si, v4si)
17477 v8hi __builtin_ia32_phaddw128 (v8hi, v8hi)
17478 v8hi __builtin_ia32_phaddsw128 (v8hi, v8hi)
17479 v4si __builtin_ia32_phsubd128 (v4si, v4si)
17480 v8hi __builtin_ia32_phsubw128 (v8hi, v8hi)
17481 v8hi __builtin_ia32_phsubsw128 (v8hi, v8hi)
17482 v8hi __builtin_ia32_pmaddubsw128 (v16qi, v16qi)
17483 v8hi __builtin_ia32_pmulhrsw128 (v8hi, v8hi)
17484 v16qi __builtin_ia32_pshufb128 (v16qi, v16qi)
17485 v16qi __builtin_ia32_psignb128 (v16qi, v16qi)
17486 v4si __builtin_ia32_psignd128 (v4si, v4si)
17487 v8hi __builtin_ia32_psignw128 (v8hi, v8hi)
17488 v2di __builtin_ia32_palignr128 (v2di, v2di, int)
17489 v16qi __builtin_ia32_pabsb128 (v16qi)
17490 v4si __builtin_ia32_pabsd128 (v4si)
17491 v8hi __builtin_ia32_pabsw128 (v8hi)
17492 @end smallexample
17493
17494 The following built-in functions are available when @option{-msse4.1} is
17495 used. All of them generate the machine instruction that is part of the
17496 name.
17497
17498 @smallexample
17499 v2df __builtin_ia32_blendpd (v2df, v2df, const int)
17500 v4sf __builtin_ia32_blendps (v4sf, v4sf, const int)
17501 v2df __builtin_ia32_blendvpd (v2df, v2df, v2df)
17502 v4sf __builtin_ia32_blendvps (v4sf, v4sf, v4sf)
17503 v2df __builtin_ia32_dppd (v2df, v2df, const int)
17504 v4sf __builtin_ia32_dpps (v4sf, v4sf, const int)
17505 v4sf __builtin_ia32_insertps128 (v4sf, v4sf, const int)
17506 v2di __builtin_ia32_movntdqa (v2di *);
17507 v16qi __builtin_ia32_mpsadbw128 (v16qi, v16qi, const int)
17508 v8hi __builtin_ia32_packusdw128 (v4si, v4si)
17509 v16qi __builtin_ia32_pblendvb128 (v16qi, v16qi, v16qi)
17510 v8hi __builtin_ia32_pblendw128 (v8hi, v8hi, const int)
17511 v2di __builtin_ia32_pcmpeqq (v2di, v2di)
17512 v8hi __builtin_ia32_phminposuw128 (v8hi)
17513 v16qi __builtin_ia32_pmaxsb128 (v16qi, v16qi)
17514 v4si __builtin_ia32_pmaxsd128 (v4si, v4si)
17515 v4si __builtin_ia32_pmaxud128 (v4si, v4si)
17516 v8hi __builtin_ia32_pmaxuw128 (v8hi, v8hi)
17517 v16qi __builtin_ia32_pminsb128 (v16qi, v16qi)
17518 v4si __builtin_ia32_pminsd128 (v4si, v4si)
17519 v4si __builtin_ia32_pminud128 (v4si, v4si)
17520 v8hi __builtin_ia32_pminuw128 (v8hi, v8hi)
17521 v4si __builtin_ia32_pmovsxbd128 (v16qi)
17522 v2di __builtin_ia32_pmovsxbq128 (v16qi)
17523 v8hi __builtin_ia32_pmovsxbw128 (v16qi)
17524 v2di __builtin_ia32_pmovsxdq128 (v4si)
17525 v4si __builtin_ia32_pmovsxwd128 (v8hi)
17526 v2di __builtin_ia32_pmovsxwq128 (v8hi)
17527 v4si __builtin_ia32_pmovzxbd128 (v16qi)
17528 v2di __builtin_ia32_pmovzxbq128 (v16qi)
17529 v8hi __builtin_ia32_pmovzxbw128 (v16qi)
17530 v2di __builtin_ia32_pmovzxdq128 (v4si)
17531 v4si __builtin_ia32_pmovzxwd128 (v8hi)
17532 v2di __builtin_ia32_pmovzxwq128 (v8hi)
17533 v2di __builtin_ia32_pmuldq128 (v4si, v4si)
17534 v4si __builtin_ia32_pmulld128 (v4si, v4si)
17535 int __builtin_ia32_ptestc128 (v2di, v2di)
17536 int __builtin_ia32_ptestnzc128 (v2di, v2di)
17537 int __builtin_ia32_ptestz128 (v2di, v2di)
17538 v2df __builtin_ia32_roundpd (v2df, const int)
17539 v4sf __builtin_ia32_roundps (v4sf, const int)
17540 v2df __builtin_ia32_roundsd (v2df, v2df, const int)
17541 v4sf __builtin_ia32_roundss (v4sf, v4sf, const int)
17542 @end smallexample
17543
17544 The following built-in functions are available when @option{-msse4.1} is
17545 used.
17546
17547 @table @code
17548 @item v4sf __builtin_ia32_vec_set_v4sf (v4sf, float, const int)
17549 Generates the @code{insertps} machine instruction.
17550 @item int __builtin_ia32_vec_ext_v16qi (v16qi, const int)
17551 Generates the @code{pextrb} machine instruction.
17552 @item v16qi __builtin_ia32_vec_set_v16qi (v16qi, int, const int)
17553 Generates the @code{pinsrb} machine instruction.
17554 @item v4si __builtin_ia32_vec_set_v4si (v4si, int, const int)
17555 Generates the @code{pinsrd} machine instruction.
17556 @item v2di __builtin_ia32_vec_set_v2di (v2di, long long, const int)
17557 Generates the @code{pinsrq} machine instruction in 64bit mode.
17558 @end table
17559
17560 The following built-in functions are changed to generate new SSE4.1
17561 instructions when @option{-msse4.1} is used.
17562
17563 @table @code
17564 @item float __builtin_ia32_vec_ext_v4sf (v4sf, const int)
17565 Generates the @code{extractps} machine instruction.
17566 @item int __builtin_ia32_vec_ext_v4si (v4si, const int)
17567 Generates the @code{pextrd} machine instruction.
17568 @item long long __builtin_ia32_vec_ext_v2di (v2di, const int)
17569 Generates the @code{pextrq} machine instruction in 64bit mode.
17570 @end table
17571
17572 The following built-in functions are available when @option{-msse4.2} is
17573 used. All of them generate the machine instruction that is part of the
17574 name.
17575
17576 @smallexample
17577 v16qi __builtin_ia32_pcmpestrm128 (v16qi, int, v16qi, int, const int)
17578 int __builtin_ia32_pcmpestri128 (v16qi, int, v16qi, int, const int)
17579 int __builtin_ia32_pcmpestria128 (v16qi, int, v16qi, int, const int)
17580 int __builtin_ia32_pcmpestric128 (v16qi, int, v16qi, int, const int)
17581 int __builtin_ia32_pcmpestrio128 (v16qi, int, v16qi, int, const int)
17582 int __builtin_ia32_pcmpestris128 (v16qi, int, v16qi, int, const int)
17583 int __builtin_ia32_pcmpestriz128 (v16qi, int, v16qi, int, const int)
17584 v16qi __builtin_ia32_pcmpistrm128 (v16qi, v16qi, const int)
17585 int __builtin_ia32_pcmpistri128 (v16qi, v16qi, const int)
17586 int __builtin_ia32_pcmpistria128 (v16qi, v16qi, const int)
17587 int __builtin_ia32_pcmpistric128 (v16qi, v16qi, const int)
17588 int __builtin_ia32_pcmpistrio128 (v16qi, v16qi, const int)
17589 int __builtin_ia32_pcmpistris128 (v16qi, v16qi, const int)
17590 int __builtin_ia32_pcmpistriz128 (v16qi, v16qi, const int)
17591 v2di __builtin_ia32_pcmpgtq (v2di, v2di)
17592 @end smallexample
17593
17594 The following built-in functions are available when @option{-msse4.2} is
17595 used.
17596
17597 @table @code
17598 @item unsigned int __builtin_ia32_crc32qi (unsigned int, unsigned char)
17599 Generates the @code{crc32b} machine instruction.
17600 @item unsigned int __builtin_ia32_crc32hi (unsigned int, unsigned short)
17601 Generates the @code{crc32w} machine instruction.
17602 @item unsigned int __builtin_ia32_crc32si (unsigned int, unsigned int)
17603 Generates the @code{crc32l} machine instruction.
17604 @item unsigned long long __builtin_ia32_crc32di (unsigned long long, unsigned long long)
17605 Generates the @code{crc32q} machine instruction.
17606 @end table
17607
17608 The following built-in functions are changed to generate new SSE4.2
17609 instructions when @option{-msse4.2} is used.
17610
17611 @table @code
17612 @item int __builtin_popcount (unsigned int)
17613 Generates the @code{popcntl} machine instruction.
17614 @item int __builtin_popcountl (unsigned long)
17615 Generates the @code{popcntl} or @code{popcntq} machine instruction,
17616 depending on the size of @code{unsigned long}.
17617 @item int __builtin_popcountll (unsigned long long)
17618 Generates the @code{popcntq} machine instruction.
17619 @end table
17620
17621 The following built-in functions are available when @option{-mavx} is
17622 used. All of them generate the machine instruction that is part of the
17623 name.
17624
17625 @smallexample
17626 v4df __builtin_ia32_addpd256 (v4df,v4df)
17627 v8sf __builtin_ia32_addps256 (v8sf,v8sf)
17628 v4df __builtin_ia32_addsubpd256 (v4df,v4df)
17629 v8sf __builtin_ia32_addsubps256 (v8sf,v8sf)
17630 v4df __builtin_ia32_andnpd256 (v4df,v4df)
17631 v8sf __builtin_ia32_andnps256 (v8sf,v8sf)
17632 v4df __builtin_ia32_andpd256 (v4df,v4df)
17633 v8sf __builtin_ia32_andps256 (v8sf,v8sf)
17634 v4df __builtin_ia32_blendpd256 (v4df,v4df,int)
17635 v8sf __builtin_ia32_blendps256 (v8sf,v8sf,int)
17636 v4df __builtin_ia32_blendvpd256 (v4df,v4df,v4df)
17637 v8sf __builtin_ia32_blendvps256 (v8sf,v8sf,v8sf)
17638 v2df __builtin_ia32_cmppd (v2df,v2df,int)
17639 v4df __builtin_ia32_cmppd256 (v4df,v4df,int)
17640 v4sf __builtin_ia32_cmpps (v4sf,v4sf,int)
17641 v8sf __builtin_ia32_cmpps256 (v8sf,v8sf,int)
17642 v2df __builtin_ia32_cmpsd (v2df,v2df,int)
17643 v4sf __builtin_ia32_cmpss (v4sf,v4sf,int)
17644 v4df __builtin_ia32_cvtdq2pd256 (v4si)
17645 v8sf __builtin_ia32_cvtdq2ps256 (v8si)
17646 v4si __builtin_ia32_cvtpd2dq256 (v4df)
17647 v4sf __builtin_ia32_cvtpd2ps256 (v4df)
17648 v8si __builtin_ia32_cvtps2dq256 (v8sf)
17649 v4df __builtin_ia32_cvtps2pd256 (v4sf)
17650 v4si __builtin_ia32_cvttpd2dq256 (v4df)
17651 v8si __builtin_ia32_cvttps2dq256 (v8sf)
17652 v4df __builtin_ia32_divpd256 (v4df,v4df)
17653 v8sf __builtin_ia32_divps256 (v8sf,v8sf)
17654 v8sf __builtin_ia32_dpps256 (v8sf,v8sf,int)
17655 v4df __builtin_ia32_haddpd256 (v4df,v4df)
17656 v8sf __builtin_ia32_haddps256 (v8sf,v8sf)
17657 v4df __builtin_ia32_hsubpd256 (v4df,v4df)
17658 v8sf __builtin_ia32_hsubps256 (v8sf,v8sf)
17659 v32qi __builtin_ia32_lddqu256 (pcchar)
17660 v32qi __builtin_ia32_loaddqu256 (pcchar)
17661 v4df __builtin_ia32_loadupd256 (pcdouble)
17662 v8sf __builtin_ia32_loadups256 (pcfloat)
17663 v2df __builtin_ia32_maskloadpd (pcv2df,v2df)
17664 v4df __builtin_ia32_maskloadpd256 (pcv4df,v4df)
17665 v4sf __builtin_ia32_maskloadps (pcv4sf,v4sf)
17666 v8sf __builtin_ia32_maskloadps256 (pcv8sf,v8sf)
17667 void __builtin_ia32_maskstorepd (pv2df,v2df,v2df)
17668 void __builtin_ia32_maskstorepd256 (pv4df,v4df,v4df)
17669 void __builtin_ia32_maskstoreps (pv4sf,v4sf,v4sf)
17670 void __builtin_ia32_maskstoreps256 (pv8sf,v8sf,v8sf)
17671 v4df __builtin_ia32_maxpd256 (v4df,v4df)
17672 v8sf __builtin_ia32_maxps256 (v8sf,v8sf)
17673 v4df __builtin_ia32_minpd256 (v4df,v4df)
17674 v8sf __builtin_ia32_minps256 (v8sf,v8sf)
17675 v4df __builtin_ia32_movddup256 (v4df)
17676 int __builtin_ia32_movmskpd256 (v4df)
17677 int __builtin_ia32_movmskps256 (v8sf)
17678 v8sf __builtin_ia32_movshdup256 (v8sf)
17679 v8sf __builtin_ia32_movsldup256 (v8sf)
17680 v4df __builtin_ia32_mulpd256 (v4df,v4df)
17681 v8sf __builtin_ia32_mulps256 (v8sf,v8sf)
17682 v4df __builtin_ia32_orpd256 (v4df,v4df)
17683 v8sf __builtin_ia32_orps256 (v8sf,v8sf)
17684 v2df __builtin_ia32_pd_pd256 (v4df)
17685 v4df __builtin_ia32_pd256_pd (v2df)
17686 v4sf __builtin_ia32_ps_ps256 (v8sf)
17687 v8sf __builtin_ia32_ps256_ps (v4sf)
17688 int __builtin_ia32_ptestc256 (v4di,v4di,ptest)
17689 int __builtin_ia32_ptestnzc256 (v4di,v4di,ptest)
17690 int __builtin_ia32_ptestz256 (v4di,v4di,ptest)
17691 v8sf __builtin_ia32_rcpps256 (v8sf)
17692 v4df __builtin_ia32_roundpd256 (v4df,int)
17693 v8sf __builtin_ia32_roundps256 (v8sf,int)
17694 v8sf __builtin_ia32_rsqrtps_nr256 (v8sf)
17695 v8sf __builtin_ia32_rsqrtps256 (v8sf)
17696 v4df __builtin_ia32_shufpd256 (v4df,v4df,int)
17697 v8sf __builtin_ia32_shufps256 (v8sf,v8sf,int)
17698 v4si __builtin_ia32_si_si256 (v8si)
17699 v8si __builtin_ia32_si256_si (v4si)
17700 v4df __builtin_ia32_sqrtpd256 (v4df)
17701 v8sf __builtin_ia32_sqrtps_nr256 (v8sf)
17702 v8sf __builtin_ia32_sqrtps256 (v8sf)
17703 void __builtin_ia32_storedqu256 (pchar,v32qi)
17704 void __builtin_ia32_storeupd256 (pdouble,v4df)
17705 void __builtin_ia32_storeups256 (pfloat,v8sf)
17706 v4df __builtin_ia32_subpd256 (v4df,v4df)
17707 v8sf __builtin_ia32_subps256 (v8sf,v8sf)
17708 v4df __builtin_ia32_unpckhpd256 (v4df,v4df)
17709 v8sf __builtin_ia32_unpckhps256 (v8sf,v8sf)
17710 v4df __builtin_ia32_unpcklpd256 (v4df,v4df)
17711 v8sf __builtin_ia32_unpcklps256 (v8sf,v8sf)
17712 v4df __builtin_ia32_vbroadcastf128_pd256 (pcv2df)
17713 v8sf __builtin_ia32_vbroadcastf128_ps256 (pcv4sf)
17714 v4df __builtin_ia32_vbroadcastsd256 (pcdouble)
17715 v4sf __builtin_ia32_vbroadcastss (pcfloat)
17716 v8sf __builtin_ia32_vbroadcastss256 (pcfloat)
17717 v2df __builtin_ia32_vextractf128_pd256 (v4df,int)
17718 v4sf __builtin_ia32_vextractf128_ps256 (v8sf,int)
17719 v4si __builtin_ia32_vextractf128_si256 (v8si,int)
17720 v4df __builtin_ia32_vinsertf128_pd256 (v4df,v2df,int)
17721 v8sf __builtin_ia32_vinsertf128_ps256 (v8sf,v4sf,int)
17722 v8si __builtin_ia32_vinsertf128_si256 (v8si,v4si,int)
17723 v4df __builtin_ia32_vperm2f128_pd256 (v4df,v4df,int)
17724 v8sf __builtin_ia32_vperm2f128_ps256 (v8sf,v8sf,int)
17725 v8si __builtin_ia32_vperm2f128_si256 (v8si,v8si,int)
17726 v2df __builtin_ia32_vpermil2pd (v2df,v2df,v2di,int)
17727 v4df __builtin_ia32_vpermil2pd256 (v4df,v4df,v4di,int)
17728 v4sf __builtin_ia32_vpermil2ps (v4sf,v4sf,v4si,int)
17729 v8sf __builtin_ia32_vpermil2ps256 (v8sf,v8sf,v8si,int)
17730 v2df __builtin_ia32_vpermilpd (v2df,int)
17731 v4df __builtin_ia32_vpermilpd256 (v4df,int)
17732 v4sf __builtin_ia32_vpermilps (v4sf,int)
17733 v8sf __builtin_ia32_vpermilps256 (v8sf,int)
17734 v2df __builtin_ia32_vpermilvarpd (v2df,v2di)
17735 v4df __builtin_ia32_vpermilvarpd256 (v4df,v4di)
17736 v4sf __builtin_ia32_vpermilvarps (v4sf,v4si)
17737 v8sf __builtin_ia32_vpermilvarps256 (v8sf,v8si)
17738 int __builtin_ia32_vtestcpd (v2df,v2df,ptest)
17739 int __builtin_ia32_vtestcpd256 (v4df,v4df,ptest)
17740 int __builtin_ia32_vtestcps (v4sf,v4sf,ptest)
17741 int __builtin_ia32_vtestcps256 (v8sf,v8sf,ptest)
17742 int __builtin_ia32_vtestnzcpd (v2df,v2df,ptest)
17743 int __builtin_ia32_vtestnzcpd256 (v4df,v4df,ptest)
17744 int __builtin_ia32_vtestnzcps (v4sf,v4sf,ptest)
17745 int __builtin_ia32_vtestnzcps256 (v8sf,v8sf,ptest)
17746 int __builtin_ia32_vtestzpd (v2df,v2df,ptest)
17747 int __builtin_ia32_vtestzpd256 (v4df,v4df,ptest)
17748 int __builtin_ia32_vtestzps (v4sf,v4sf,ptest)
17749 int __builtin_ia32_vtestzps256 (v8sf,v8sf,ptest)
17750 void __builtin_ia32_vzeroall (void)
17751 void __builtin_ia32_vzeroupper (void)
17752 v4df __builtin_ia32_xorpd256 (v4df,v4df)
17753 v8sf __builtin_ia32_xorps256 (v8sf,v8sf)
17754 @end smallexample
17755
17756 The following built-in functions are available when @option{-mavx2} is
17757 used. All of them generate the machine instruction that is part of the
17758 name.
17759
17760 @smallexample
17761 v32qi __builtin_ia32_mpsadbw256 (v32qi,v32qi,int)
17762 v32qi __builtin_ia32_pabsb256 (v32qi)
17763 v16hi __builtin_ia32_pabsw256 (v16hi)
17764 v8si __builtin_ia32_pabsd256 (v8si)
17765 v16hi __builtin_ia32_packssdw256 (v8si,v8si)
17766 v32qi __builtin_ia32_packsswb256 (v16hi,v16hi)
17767 v16hi __builtin_ia32_packusdw256 (v8si,v8si)
17768 v32qi __builtin_ia32_packuswb256 (v16hi,v16hi)
17769 v32qi __builtin_ia32_paddb256 (v32qi,v32qi)
17770 v16hi __builtin_ia32_paddw256 (v16hi,v16hi)
17771 v8si __builtin_ia32_paddd256 (v8si,v8si)
17772 v4di __builtin_ia32_paddq256 (v4di,v4di)
17773 v32qi __builtin_ia32_paddsb256 (v32qi,v32qi)
17774 v16hi __builtin_ia32_paddsw256 (v16hi,v16hi)
17775 v32qi __builtin_ia32_paddusb256 (v32qi,v32qi)
17776 v16hi __builtin_ia32_paddusw256 (v16hi,v16hi)
17777 v4di __builtin_ia32_palignr256 (v4di,v4di,int)
17778 v4di __builtin_ia32_andsi256 (v4di,v4di)
17779 v4di __builtin_ia32_andnotsi256 (v4di,v4di)
17780 v32qi __builtin_ia32_pavgb256 (v32qi,v32qi)
17781 v16hi __builtin_ia32_pavgw256 (v16hi,v16hi)
17782 v32qi __builtin_ia32_pblendvb256 (v32qi,v32qi,v32qi)
17783 v16hi __builtin_ia32_pblendw256 (v16hi,v16hi,int)
17784 v32qi __builtin_ia32_pcmpeqb256 (v32qi,v32qi)
17785 v16hi __builtin_ia32_pcmpeqw256 (v16hi,v16hi)
17786 v8si __builtin_ia32_pcmpeqd256 (c8si,v8si)
17787 v4di __builtin_ia32_pcmpeqq256 (v4di,v4di)
17788 v32qi __builtin_ia32_pcmpgtb256 (v32qi,v32qi)
17789 v16hi __builtin_ia32_pcmpgtw256 (16hi,v16hi)
17790 v8si __builtin_ia32_pcmpgtd256 (v8si,v8si)
17791 v4di __builtin_ia32_pcmpgtq256 (v4di,v4di)
17792 v16hi __builtin_ia32_phaddw256 (v16hi,v16hi)
17793 v8si __builtin_ia32_phaddd256 (v8si,v8si)
17794 v16hi __builtin_ia32_phaddsw256 (v16hi,v16hi)
17795 v16hi __builtin_ia32_phsubw256 (v16hi,v16hi)
17796 v8si __builtin_ia32_phsubd256 (v8si,v8si)
17797 v16hi __builtin_ia32_phsubsw256 (v16hi,v16hi)
17798 v32qi __builtin_ia32_pmaddubsw256 (v32qi,v32qi)
17799 v16hi __builtin_ia32_pmaddwd256 (v16hi,v16hi)
17800 v32qi __builtin_ia32_pmaxsb256 (v32qi,v32qi)
17801 v16hi __builtin_ia32_pmaxsw256 (v16hi,v16hi)
17802 v8si __builtin_ia32_pmaxsd256 (v8si,v8si)
17803 v32qi __builtin_ia32_pmaxub256 (v32qi,v32qi)
17804 v16hi __builtin_ia32_pmaxuw256 (v16hi,v16hi)
17805 v8si __builtin_ia32_pmaxud256 (v8si,v8si)
17806 v32qi __builtin_ia32_pminsb256 (v32qi,v32qi)
17807 v16hi __builtin_ia32_pminsw256 (v16hi,v16hi)
17808 v8si __builtin_ia32_pminsd256 (v8si,v8si)
17809 v32qi __builtin_ia32_pminub256 (v32qi,v32qi)
17810 v16hi __builtin_ia32_pminuw256 (v16hi,v16hi)
17811 v8si __builtin_ia32_pminud256 (v8si,v8si)
17812 int __builtin_ia32_pmovmskb256 (v32qi)
17813 v16hi __builtin_ia32_pmovsxbw256 (v16qi)
17814 v8si __builtin_ia32_pmovsxbd256 (v16qi)
17815 v4di __builtin_ia32_pmovsxbq256 (v16qi)
17816 v8si __builtin_ia32_pmovsxwd256 (v8hi)
17817 v4di __builtin_ia32_pmovsxwq256 (v8hi)
17818 v4di __builtin_ia32_pmovsxdq256 (v4si)
17819 v16hi __builtin_ia32_pmovzxbw256 (v16qi)
17820 v8si __builtin_ia32_pmovzxbd256 (v16qi)
17821 v4di __builtin_ia32_pmovzxbq256 (v16qi)
17822 v8si __builtin_ia32_pmovzxwd256 (v8hi)
17823 v4di __builtin_ia32_pmovzxwq256 (v8hi)
17824 v4di __builtin_ia32_pmovzxdq256 (v4si)
17825 v4di __builtin_ia32_pmuldq256 (v8si,v8si)
17826 v16hi __builtin_ia32_pmulhrsw256 (v16hi, v16hi)
17827 v16hi __builtin_ia32_pmulhuw256 (v16hi,v16hi)
17828 v16hi __builtin_ia32_pmulhw256 (v16hi,v16hi)
17829 v16hi __builtin_ia32_pmullw256 (v16hi,v16hi)
17830 v8si __builtin_ia32_pmulld256 (v8si,v8si)
17831 v4di __builtin_ia32_pmuludq256 (v8si,v8si)
17832 v4di __builtin_ia32_por256 (v4di,v4di)
17833 v16hi __builtin_ia32_psadbw256 (v32qi,v32qi)
17834 v32qi __builtin_ia32_pshufb256 (v32qi,v32qi)
17835 v8si __builtin_ia32_pshufd256 (v8si,int)
17836 v16hi __builtin_ia32_pshufhw256 (v16hi,int)
17837 v16hi __builtin_ia32_pshuflw256 (v16hi,int)
17838 v32qi __builtin_ia32_psignb256 (v32qi,v32qi)
17839 v16hi __builtin_ia32_psignw256 (v16hi,v16hi)
17840 v8si __builtin_ia32_psignd256 (v8si,v8si)
17841 v4di __builtin_ia32_pslldqi256 (v4di,int)
17842 v16hi __builtin_ia32_psllwi256 (16hi,int)
17843 v16hi __builtin_ia32_psllw256(v16hi,v8hi)
17844 v8si __builtin_ia32_pslldi256 (v8si,int)
17845 v8si __builtin_ia32_pslld256(v8si,v4si)
17846 v4di __builtin_ia32_psllqi256 (v4di,int)
17847 v4di __builtin_ia32_psllq256(v4di,v2di)
17848 v16hi __builtin_ia32_psrawi256 (v16hi,int)
17849 v16hi __builtin_ia32_psraw256 (v16hi,v8hi)
17850 v8si __builtin_ia32_psradi256 (v8si,int)
17851 v8si __builtin_ia32_psrad256 (v8si,v4si)
17852 v4di __builtin_ia32_psrldqi256 (v4di, int)
17853 v16hi __builtin_ia32_psrlwi256 (v16hi,int)
17854 v16hi __builtin_ia32_psrlw256 (v16hi,v8hi)
17855 v8si __builtin_ia32_psrldi256 (v8si,int)
17856 v8si __builtin_ia32_psrld256 (v8si,v4si)
17857 v4di __builtin_ia32_psrlqi256 (v4di,int)
17858 v4di __builtin_ia32_psrlq256(v4di,v2di)
17859 v32qi __builtin_ia32_psubb256 (v32qi,v32qi)
17860 v32hi __builtin_ia32_psubw256 (v16hi,v16hi)
17861 v8si __builtin_ia32_psubd256 (v8si,v8si)
17862 v4di __builtin_ia32_psubq256 (v4di,v4di)
17863 v32qi __builtin_ia32_psubsb256 (v32qi,v32qi)
17864 v16hi __builtin_ia32_psubsw256 (v16hi,v16hi)
17865 v32qi __builtin_ia32_psubusb256 (v32qi,v32qi)
17866 v16hi __builtin_ia32_psubusw256 (v16hi,v16hi)
17867 v32qi __builtin_ia32_punpckhbw256 (v32qi,v32qi)
17868 v16hi __builtin_ia32_punpckhwd256 (v16hi,v16hi)
17869 v8si __builtin_ia32_punpckhdq256 (v8si,v8si)
17870 v4di __builtin_ia32_punpckhqdq256 (v4di,v4di)
17871 v32qi __builtin_ia32_punpcklbw256 (v32qi,v32qi)
17872 v16hi __builtin_ia32_punpcklwd256 (v16hi,v16hi)
17873 v8si __builtin_ia32_punpckldq256 (v8si,v8si)
17874 v4di __builtin_ia32_punpcklqdq256 (v4di,v4di)
17875 v4di __builtin_ia32_pxor256 (v4di,v4di)
17876 v4di __builtin_ia32_movntdqa256 (pv4di)
17877 v4sf __builtin_ia32_vbroadcastss_ps (v4sf)
17878 v8sf __builtin_ia32_vbroadcastss_ps256 (v4sf)
17879 v4df __builtin_ia32_vbroadcastsd_pd256 (v2df)
17880 v4di __builtin_ia32_vbroadcastsi256 (v2di)
17881 v4si __builtin_ia32_pblendd128 (v4si,v4si)
17882 v8si __builtin_ia32_pblendd256 (v8si,v8si)
17883 v32qi __builtin_ia32_pbroadcastb256 (v16qi)
17884 v16hi __builtin_ia32_pbroadcastw256 (v8hi)
17885 v8si __builtin_ia32_pbroadcastd256 (v4si)
17886 v4di __builtin_ia32_pbroadcastq256 (v2di)
17887 v16qi __builtin_ia32_pbroadcastb128 (v16qi)
17888 v8hi __builtin_ia32_pbroadcastw128 (v8hi)
17889 v4si __builtin_ia32_pbroadcastd128 (v4si)
17890 v2di __builtin_ia32_pbroadcastq128 (v2di)
17891 v8si __builtin_ia32_permvarsi256 (v8si,v8si)
17892 v4df __builtin_ia32_permdf256 (v4df,int)
17893 v8sf __builtin_ia32_permvarsf256 (v8sf,v8sf)
17894 v4di __builtin_ia32_permdi256 (v4di,int)
17895 v4di __builtin_ia32_permti256 (v4di,v4di,int)
17896 v4di __builtin_ia32_extract128i256 (v4di,int)
17897 v4di __builtin_ia32_insert128i256 (v4di,v2di,int)
17898 v8si __builtin_ia32_maskloadd256 (pcv8si,v8si)
17899 v4di __builtin_ia32_maskloadq256 (pcv4di,v4di)
17900 v4si __builtin_ia32_maskloadd (pcv4si,v4si)
17901 v2di __builtin_ia32_maskloadq (pcv2di,v2di)
17902 void __builtin_ia32_maskstored256 (pv8si,v8si,v8si)
17903 void __builtin_ia32_maskstoreq256 (pv4di,v4di,v4di)
17904 void __builtin_ia32_maskstored (pv4si,v4si,v4si)
17905 void __builtin_ia32_maskstoreq (pv2di,v2di,v2di)
17906 v8si __builtin_ia32_psllv8si (v8si,v8si)
17907 v4si __builtin_ia32_psllv4si (v4si,v4si)
17908 v4di __builtin_ia32_psllv4di (v4di,v4di)
17909 v2di __builtin_ia32_psllv2di (v2di,v2di)
17910 v8si __builtin_ia32_psrav8si (v8si,v8si)
17911 v4si __builtin_ia32_psrav4si (v4si,v4si)
17912 v8si __builtin_ia32_psrlv8si (v8si,v8si)
17913 v4si __builtin_ia32_psrlv4si (v4si,v4si)
17914 v4di __builtin_ia32_psrlv4di (v4di,v4di)
17915 v2di __builtin_ia32_psrlv2di (v2di,v2di)
17916 v2df __builtin_ia32_gathersiv2df (v2df, pcdouble,v4si,v2df,int)
17917 v4df __builtin_ia32_gathersiv4df (v4df, pcdouble,v4si,v4df,int)
17918 v2df __builtin_ia32_gatherdiv2df (v2df, pcdouble,v2di,v2df,int)
17919 v4df __builtin_ia32_gatherdiv4df (v4df, pcdouble,v4di,v4df,int)
17920 v4sf __builtin_ia32_gathersiv4sf (v4sf, pcfloat,v4si,v4sf,int)
17921 v8sf __builtin_ia32_gathersiv8sf (v8sf, pcfloat,v8si,v8sf,int)
17922 v4sf __builtin_ia32_gatherdiv4sf (v4sf, pcfloat,v2di,v4sf,int)
17923 v4sf __builtin_ia32_gatherdiv4sf256 (v4sf, pcfloat,v4di,v4sf,int)
17924 v2di __builtin_ia32_gathersiv2di (v2di, pcint64,v4si,v2di,int)
17925 v4di __builtin_ia32_gathersiv4di (v4di, pcint64,v4si,v4di,int)
17926 v2di __builtin_ia32_gatherdiv2di (v2di, pcint64,v2di,v2di,int)
17927 v4di __builtin_ia32_gatherdiv4di (v4di, pcint64,v4di,v4di,int)
17928 v4si __builtin_ia32_gathersiv4si (v4si, pcint,v4si,v4si,int)
17929 v8si __builtin_ia32_gathersiv8si (v8si, pcint,v8si,v8si,int)
17930 v4si __builtin_ia32_gatherdiv4si (v4si, pcint,v2di,v4si,int)
17931 v4si __builtin_ia32_gatherdiv4si256 (v4si, pcint,v4di,v4si,int)
17932 @end smallexample
17933
17934 The following built-in functions are available when @option{-maes} is
17935 used. All of them generate the machine instruction that is part of the
17936 name.
17937
17938 @smallexample
17939 v2di __builtin_ia32_aesenc128 (v2di, v2di)
17940 v2di __builtin_ia32_aesenclast128 (v2di, v2di)
17941 v2di __builtin_ia32_aesdec128 (v2di, v2di)
17942 v2di __builtin_ia32_aesdeclast128 (v2di, v2di)
17943 v2di __builtin_ia32_aeskeygenassist128 (v2di, const int)
17944 v2di __builtin_ia32_aesimc128 (v2di)
17945 @end smallexample
17946
17947 The following built-in function is available when @option{-mpclmul} is
17948 used.
17949
17950 @table @code
17951 @item v2di __builtin_ia32_pclmulqdq128 (v2di, v2di, const int)
17952 Generates the @code{pclmulqdq} machine instruction.
17953 @end table
17954
17955 The following built-in function is available when @option{-mfsgsbase} is
17956 used. All of them generate the machine instruction that is part of the
17957 name.
17958
17959 @smallexample
17960 unsigned int __builtin_ia32_rdfsbase32 (void)
17961 unsigned long long __builtin_ia32_rdfsbase64 (void)
17962 unsigned int __builtin_ia32_rdgsbase32 (void)
17963 unsigned long long __builtin_ia32_rdgsbase64 (void)
17964 void _writefsbase_u32 (unsigned int)
17965 void _writefsbase_u64 (unsigned long long)
17966 void _writegsbase_u32 (unsigned int)
17967 void _writegsbase_u64 (unsigned long long)
17968 @end smallexample
17969
17970 The following built-in function is available when @option{-mrdrnd} is
17971 used. All of them generate the machine instruction that is part of the
17972 name.
17973
17974 @smallexample
17975 unsigned int __builtin_ia32_rdrand16_step (unsigned short *)
17976 unsigned int __builtin_ia32_rdrand32_step (unsigned int *)
17977 unsigned int __builtin_ia32_rdrand64_step (unsigned long long *)
17978 @end smallexample
17979
17980 The following built-in functions are available when @option{-msse4a} is used.
17981 All of them generate the machine instruction that is part of the name.
17982
17983 @smallexample
17984 void __builtin_ia32_movntsd (double *, v2df)
17985 void __builtin_ia32_movntss (float *, v4sf)
17986 v2di __builtin_ia32_extrq (v2di, v16qi)
17987 v2di __builtin_ia32_extrqi (v2di, const unsigned int, const unsigned int)
17988 v2di __builtin_ia32_insertq (v2di, v2di)
17989 v2di __builtin_ia32_insertqi (v2di, v2di, const unsigned int, const unsigned int)
17990 @end smallexample
17991
17992 The following built-in functions are available when @option{-mxop} is used.
17993 @smallexample
17994 v2df __builtin_ia32_vfrczpd (v2df)
17995 v4sf __builtin_ia32_vfrczps (v4sf)
17996 v2df __builtin_ia32_vfrczsd (v2df)
17997 v4sf __builtin_ia32_vfrczss (v4sf)
17998 v4df __builtin_ia32_vfrczpd256 (v4df)
17999 v8sf __builtin_ia32_vfrczps256 (v8sf)
18000 v2di __builtin_ia32_vpcmov (v2di, v2di, v2di)
18001 v2di __builtin_ia32_vpcmov_v2di (v2di, v2di, v2di)
18002 v4si __builtin_ia32_vpcmov_v4si (v4si, v4si, v4si)
18003 v8hi __builtin_ia32_vpcmov_v8hi (v8hi, v8hi, v8hi)
18004 v16qi __builtin_ia32_vpcmov_v16qi (v16qi, v16qi, v16qi)
18005 v2df __builtin_ia32_vpcmov_v2df (v2df, v2df, v2df)
18006 v4sf __builtin_ia32_vpcmov_v4sf (v4sf, v4sf, v4sf)
18007 v4di __builtin_ia32_vpcmov_v4di256 (v4di, v4di, v4di)
18008 v8si __builtin_ia32_vpcmov_v8si256 (v8si, v8si, v8si)
18009 v16hi __builtin_ia32_vpcmov_v16hi256 (v16hi, v16hi, v16hi)
18010 v32qi __builtin_ia32_vpcmov_v32qi256 (v32qi, v32qi, v32qi)
18011 v4df __builtin_ia32_vpcmov_v4df256 (v4df, v4df, v4df)
18012 v8sf __builtin_ia32_vpcmov_v8sf256 (v8sf, v8sf, v8sf)
18013 v16qi __builtin_ia32_vpcomeqb (v16qi, v16qi)
18014 v8hi __builtin_ia32_vpcomeqw (v8hi, v8hi)
18015 v4si __builtin_ia32_vpcomeqd (v4si, v4si)
18016 v2di __builtin_ia32_vpcomeqq (v2di, v2di)
18017 v16qi __builtin_ia32_vpcomequb (v16qi, v16qi)
18018 v4si __builtin_ia32_vpcomequd (v4si, v4si)
18019 v2di __builtin_ia32_vpcomequq (v2di, v2di)
18020 v8hi __builtin_ia32_vpcomequw (v8hi, v8hi)
18021 v8hi __builtin_ia32_vpcomeqw (v8hi, v8hi)
18022 v16qi __builtin_ia32_vpcomfalseb (v16qi, v16qi)
18023 v4si __builtin_ia32_vpcomfalsed (v4si, v4si)
18024 v2di __builtin_ia32_vpcomfalseq (v2di, v2di)
18025 v16qi __builtin_ia32_vpcomfalseub (v16qi, v16qi)
18026 v4si __builtin_ia32_vpcomfalseud (v4si, v4si)
18027 v2di __builtin_ia32_vpcomfalseuq (v2di, v2di)
18028 v8hi __builtin_ia32_vpcomfalseuw (v8hi, v8hi)
18029 v8hi __builtin_ia32_vpcomfalsew (v8hi, v8hi)
18030 v16qi __builtin_ia32_vpcomgeb (v16qi, v16qi)
18031 v4si __builtin_ia32_vpcomged (v4si, v4si)
18032 v2di __builtin_ia32_vpcomgeq (v2di, v2di)
18033 v16qi __builtin_ia32_vpcomgeub (v16qi, v16qi)
18034 v4si __builtin_ia32_vpcomgeud (v4si, v4si)
18035 v2di __builtin_ia32_vpcomgeuq (v2di, v2di)
18036 v8hi __builtin_ia32_vpcomgeuw (v8hi, v8hi)
18037 v8hi __builtin_ia32_vpcomgew (v8hi, v8hi)
18038 v16qi __builtin_ia32_vpcomgtb (v16qi, v16qi)
18039 v4si __builtin_ia32_vpcomgtd (v4si, v4si)
18040 v2di __builtin_ia32_vpcomgtq (v2di, v2di)
18041 v16qi __builtin_ia32_vpcomgtub (v16qi, v16qi)
18042 v4si __builtin_ia32_vpcomgtud (v4si, v4si)
18043 v2di __builtin_ia32_vpcomgtuq (v2di, v2di)
18044 v8hi __builtin_ia32_vpcomgtuw (v8hi, v8hi)
18045 v8hi __builtin_ia32_vpcomgtw (v8hi, v8hi)
18046 v16qi __builtin_ia32_vpcomleb (v16qi, v16qi)
18047 v4si __builtin_ia32_vpcomled (v4si, v4si)
18048 v2di __builtin_ia32_vpcomleq (v2di, v2di)
18049 v16qi __builtin_ia32_vpcomleub (v16qi, v16qi)
18050 v4si __builtin_ia32_vpcomleud (v4si, v4si)
18051 v2di __builtin_ia32_vpcomleuq (v2di, v2di)
18052 v8hi __builtin_ia32_vpcomleuw (v8hi, v8hi)
18053 v8hi __builtin_ia32_vpcomlew (v8hi, v8hi)
18054 v16qi __builtin_ia32_vpcomltb (v16qi, v16qi)
18055 v4si __builtin_ia32_vpcomltd (v4si, v4si)
18056 v2di __builtin_ia32_vpcomltq (v2di, v2di)
18057 v16qi __builtin_ia32_vpcomltub (v16qi, v16qi)
18058 v4si __builtin_ia32_vpcomltud (v4si, v4si)
18059 v2di __builtin_ia32_vpcomltuq (v2di, v2di)
18060 v8hi __builtin_ia32_vpcomltuw (v8hi, v8hi)
18061 v8hi __builtin_ia32_vpcomltw (v8hi, v8hi)
18062 v16qi __builtin_ia32_vpcomneb (v16qi, v16qi)
18063 v4si __builtin_ia32_vpcomned (v4si, v4si)
18064 v2di __builtin_ia32_vpcomneq (v2di, v2di)
18065 v16qi __builtin_ia32_vpcomneub (v16qi, v16qi)
18066 v4si __builtin_ia32_vpcomneud (v4si, v4si)
18067 v2di __builtin_ia32_vpcomneuq (v2di, v2di)
18068 v8hi __builtin_ia32_vpcomneuw (v8hi, v8hi)
18069 v8hi __builtin_ia32_vpcomnew (v8hi, v8hi)
18070 v16qi __builtin_ia32_vpcomtrueb (v16qi, v16qi)
18071 v4si __builtin_ia32_vpcomtrued (v4si, v4si)
18072 v2di __builtin_ia32_vpcomtrueq (v2di, v2di)
18073 v16qi __builtin_ia32_vpcomtrueub (v16qi, v16qi)
18074 v4si __builtin_ia32_vpcomtrueud (v4si, v4si)
18075 v2di __builtin_ia32_vpcomtrueuq (v2di, v2di)
18076 v8hi __builtin_ia32_vpcomtrueuw (v8hi, v8hi)
18077 v8hi __builtin_ia32_vpcomtruew (v8hi, v8hi)
18078 v4si __builtin_ia32_vphaddbd (v16qi)
18079 v2di __builtin_ia32_vphaddbq (v16qi)
18080 v8hi __builtin_ia32_vphaddbw (v16qi)
18081 v2di __builtin_ia32_vphadddq (v4si)
18082 v4si __builtin_ia32_vphaddubd (v16qi)
18083 v2di __builtin_ia32_vphaddubq (v16qi)
18084 v8hi __builtin_ia32_vphaddubw (v16qi)
18085 v2di __builtin_ia32_vphaddudq (v4si)
18086 v4si __builtin_ia32_vphadduwd (v8hi)
18087 v2di __builtin_ia32_vphadduwq (v8hi)
18088 v4si __builtin_ia32_vphaddwd (v8hi)
18089 v2di __builtin_ia32_vphaddwq (v8hi)
18090 v8hi __builtin_ia32_vphsubbw (v16qi)
18091 v2di __builtin_ia32_vphsubdq (v4si)
18092 v4si __builtin_ia32_vphsubwd (v8hi)
18093 v4si __builtin_ia32_vpmacsdd (v4si, v4si, v4si)
18094 v2di __builtin_ia32_vpmacsdqh (v4si, v4si, v2di)
18095 v2di __builtin_ia32_vpmacsdql (v4si, v4si, v2di)
18096 v4si __builtin_ia32_vpmacssdd (v4si, v4si, v4si)
18097 v2di __builtin_ia32_vpmacssdqh (v4si, v4si, v2di)
18098 v2di __builtin_ia32_vpmacssdql (v4si, v4si, v2di)
18099 v4si __builtin_ia32_vpmacsswd (v8hi, v8hi, v4si)
18100 v8hi __builtin_ia32_vpmacssww (v8hi, v8hi, v8hi)
18101 v4si __builtin_ia32_vpmacswd (v8hi, v8hi, v4si)
18102 v8hi __builtin_ia32_vpmacsww (v8hi, v8hi, v8hi)
18103 v4si __builtin_ia32_vpmadcsswd (v8hi, v8hi, v4si)
18104 v4si __builtin_ia32_vpmadcswd (v8hi, v8hi, v4si)
18105 v16qi __builtin_ia32_vpperm (v16qi, v16qi, v16qi)
18106 v16qi __builtin_ia32_vprotb (v16qi, v16qi)
18107 v4si __builtin_ia32_vprotd (v4si, v4si)
18108 v2di __builtin_ia32_vprotq (v2di, v2di)
18109 v8hi __builtin_ia32_vprotw (v8hi, v8hi)
18110 v16qi __builtin_ia32_vpshab (v16qi, v16qi)
18111 v4si __builtin_ia32_vpshad (v4si, v4si)
18112 v2di __builtin_ia32_vpshaq (v2di, v2di)
18113 v8hi __builtin_ia32_vpshaw (v8hi, v8hi)
18114 v16qi __builtin_ia32_vpshlb (v16qi, v16qi)
18115 v4si __builtin_ia32_vpshld (v4si, v4si)
18116 v2di __builtin_ia32_vpshlq (v2di, v2di)
18117 v8hi __builtin_ia32_vpshlw (v8hi, v8hi)
18118 @end smallexample
18119
18120 The following built-in functions are available when @option{-mfma4} is used.
18121 All of them generate the machine instruction that is part of the name.
18122
18123 @smallexample
18124 v2df __builtin_ia32_vfmaddpd (v2df, v2df, v2df)
18125 v4sf __builtin_ia32_vfmaddps (v4sf, v4sf, v4sf)
18126 v2df __builtin_ia32_vfmaddsd (v2df, v2df, v2df)
18127 v4sf __builtin_ia32_vfmaddss (v4sf, v4sf, v4sf)
18128 v2df __builtin_ia32_vfmsubpd (v2df, v2df, v2df)
18129 v4sf __builtin_ia32_vfmsubps (v4sf, v4sf, v4sf)
18130 v2df __builtin_ia32_vfmsubsd (v2df, v2df, v2df)
18131 v4sf __builtin_ia32_vfmsubss (v4sf, v4sf, v4sf)
18132 v2df __builtin_ia32_vfnmaddpd (v2df, v2df, v2df)
18133 v4sf __builtin_ia32_vfnmaddps (v4sf, v4sf, v4sf)
18134 v2df __builtin_ia32_vfnmaddsd (v2df, v2df, v2df)
18135 v4sf __builtin_ia32_vfnmaddss (v4sf, v4sf, v4sf)
18136 v2df __builtin_ia32_vfnmsubpd (v2df, v2df, v2df)
18137 v4sf __builtin_ia32_vfnmsubps (v4sf, v4sf, v4sf)
18138 v2df __builtin_ia32_vfnmsubsd (v2df, v2df, v2df)
18139 v4sf __builtin_ia32_vfnmsubss (v4sf, v4sf, v4sf)
18140 v2df __builtin_ia32_vfmaddsubpd (v2df, v2df, v2df)
18141 v4sf __builtin_ia32_vfmaddsubps (v4sf, v4sf, v4sf)
18142 v2df __builtin_ia32_vfmsubaddpd (v2df, v2df, v2df)
18143 v4sf __builtin_ia32_vfmsubaddps (v4sf, v4sf, v4sf)
18144 v4df __builtin_ia32_vfmaddpd256 (v4df, v4df, v4df)
18145 v8sf __builtin_ia32_vfmaddps256 (v8sf, v8sf, v8sf)
18146 v4df __builtin_ia32_vfmsubpd256 (v4df, v4df, v4df)
18147 v8sf __builtin_ia32_vfmsubps256 (v8sf, v8sf, v8sf)
18148 v4df __builtin_ia32_vfnmaddpd256 (v4df, v4df, v4df)
18149 v8sf __builtin_ia32_vfnmaddps256 (v8sf, v8sf, v8sf)
18150 v4df __builtin_ia32_vfnmsubpd256 (v4df, v4df, v4df)
18151 v8sf __builtin_ia32_vfnmsubps256 (v8sf, v8sf, v8sf)
18152 v4df __builtin_ia32_vfmaddsubpd256 (v4df, v4df, v4df)
18153 v8sf __builtin_ia32_vfmaddsubps256 (v8sf, v8sf, v8sf)
18154 v4df __builtin_ia32_vfmsubaddpd256 (v4df, v4df, v4df)
18155 v8sf __builtin_ia32_vfmsubaddps256 (v8sf, v8sf, v8sf)
18156
18157 @end smallexample
18158
18159 The following built-in functions are available when @option{-mlwp} is used.
18160
18161 @smallexample
18162 void __builtin_ia32_llwpcb16 (void *);
18163 void __builtin_ia32_llwpcb32 (void *);
18164 void __builtin_ia32_llwpcb64 (void *);
18165 void * __builtin_ia32_llwpcb16 (void);
18166 void * __builtin_ia32_llwpcb32 (void);
18167 void * __builtin_ia32_llwpcb64 (void);
18168 void __builtin_ia32_lwpval16 (unsigned short, unsigned int, unsigned short)
18169 void __builtin_ia32_lwpval32 (unsigned int, unsigned int, unsigned int)
18170 void __builtin_ia32_lwpval64 (unsigned __int64, unsigned int, unsigned int)
18171 unsigned char __builtin_ia32_lwpins16 (unsigned short, unsigned int, unsigned short)
18172 unsigned char __builtin_ia32_lwpins32 (unsigned int, unsigned int, unsigned int)
18173 unsigned char __builtin_ia32_lwpins64 (unsigned __int64, unsigned int, unsigned int)
18174 @end smallexample
18175
18176 The following built-in functions are available when @option{-mbmi} is used.
18177 All of them generate the machine instruction that is part of the name.
18178 @smallexample
18179 unsigned int __builtin_ia32_bextr_u32(unsigned int, unsigned int);
18180 unsigned long long __builtin_ia32_bextr_u64 (unsigned long long, unsigned long long);
18181 @end smallexample
18182
18183 The following built-in functions are available when @option{-mbmi2} is used.
18184 All of them generate the machine instruction that is part of the name.
18185 @smallexample
18186 unsigned int _bzhi_u32 (unsigned int, unsigned int)
18187 unsigned int _pdep_u32 (unsigned int, unsigned int)
18188 unsigned int _pext_u32 (unsigned int, unsigned int)
18189 unsigned long long _bzhi_u64 (unsigned long long, unsigned long long)
18190 unsigned long long _pdep_u64 (unsigned long long, unsigned long long)
18191 unsigned long long _pext_u64 (unsigned long long, unsigned long long)
18192 @end smallexample
18193
18194 The following built-in functions are available when @option{-mlzcnt} is used.
18195 All of them generate the machine instruction that is part of the name.
18196 @smallexample
18197 unsigned short __builtin_ia32_lzcnt_16(unsigned short);
18198 unsigned int __builtin_ia32_lzcnt_u32(unsigned int);
18199 unsigned long long __builtin_ia32_lzcnt_u64 (unsigned long long);
18200 @end smallexample
18201
18202 The following built-in functions are available when @option{-mfxsr} is used.
18203 All of them generate the machine instruction that is part of the name.
18204 @smallexample
18205 void __builtin_ia32_fxsave (void *)
18206 void __builtin_ia32_fxrstor (void *)
18207 void __builtin_ia32_fxsave64 (void *)
18208 void __builtin_ia32_fxrstor64 (void *)
18209 @end smallexample
18210
18211 The following built-in functions are available when @option{-mxsave} is used.
18212 All of them generate the machine instruction that is part of the name.
18213 @smallexample
18214 void __builtin_ia32_xsave (void *, long long)
18215 void __builtin_ia32_xrstor (void *, long long)
18216 void __builtin_ia32_xsave64 (void *, long long)
18217 void __builtin_ia32_xrstor64 (void *, long long)
18218 @end smallexample
18219
18220 The following built-in functions are available when @option{-mxsaveopt} is used.
18221 All of them generate the machine instruction that is part of the name.
18222 @smallexample
18223 void __builtin_ia32_xsaveopt (void *, long long)
18224 void __builtin_ia32_xsaveopt64 (void *, long long)
18225 @end smallexample
18226
18227 The following built-in functions are available when @option{-mtbm} is used.
18228 Both of them generate the immediate form of the bextr machine instruction.
18229 @smallexample
18230 unsigned int __builtin_ia32_bextri_u32 (unsigned int, const unsigned int);
18231 unsigned long long __builtin_ia32_bextri_u64 (unsigned long long, const unsigned long long);
18232 @end smallexample
18233
18234
18235 The following built-in functions are available when @option{-m3dnow} is used.
18236 All of them generate the machine instruction that is part of the name.
18237
18238 @smallexample
18239 void __builtin_ia32_femms (void)
18240 v8qi __builtin_ia32_pavgusb (v8qi, v8qi)
18241 v2si __builtin_ia32_pf2id (v2sf)
18242 v2sf __builtin_ia32_pfacc (v2sf, v2sf)
18243 v2sf __builtin_ia32_pfadd (v2sf, v2sf)
18244 v2si __builtin_ia32_pfcmpeq (v2sf, v2sf)
18245 v2si __builtin_ia32_pfcmpge (v2sf, v2sf)
18246 v2si __builtin_ia32_pfcmpgt (v2sf, v2sf)
18247 v2sf __builtin_ia32_pfmax (v2sf, v2sf)
18248 v2sf __builtin_ia32_pfmin (v2sf, v2sf)
18249 v2sf __builtin_ia32_pfmul (v2sf, v2sf)
18250 v2sf __builtin_ia32_pfrcp (v2sf)
18251 v2sf __builtin_ia32_pfrcpit1 (v2sf, v2sf)
18252 v2sf __builtin_ia32_pfrcpit2 (v2sf, v2sf)
18253 v2sf __builtin_ia32_pfrsqrt (v2sf)
18254 v2sf __builtin_ia32_pfsub (v2sf, v2sf)
18255 v2sf __builtin_ia32_pfsubr (v2sf, v2sf)
18256 v2sf __builtin_ia32_pi2fd (v2si)
18257 v4hi __builtin_ia32_pmulhrw (v4hi, v4hi)
18258 @end smallexample
18259
18260 The following built-in functions are available when both @option{-m3dnow}
18261 and @option{-march=athlon} are used. All of them generate the machine
18262 instruction that is part of the name.
18263
18264 @smallexample
18265 v2si __builtin_ia32_pf2iw (v2sf)
18266 v2sf __builtin_ia32_pfnacc (v2sf, v2sf)
18267 v2sf __builtin_ia32_pfpnacc (v2sf, v2sf)
18268 v2sf __builtin_ia32_pi2fw (v2si)
18269 v2sf __builtin_ia32_pswapdsf (v2sf)
18270 v2si __builtin_ia32_pswapdsi (v2si)
18271 @end smallexample
18272
18273 The following built-in functions are available when @option{-mrtm} is used
18274 They are used for restricted transactional memory. These are the internal
18275 low level functions. Normally the functions in
18276 @ref{x86 transactional memory intrinsics} should be used instead.
18277
18278 @smallexample
18279 int __builtin_ia32_xbegin ()
18280 void __builtin_ia32_xend ()
18281 void __builtin_ia32_xabort (status)
18282 int __builtin_ia32_xtest ()
18283 @end smallexample
18284
18285 The following built-in functions are available when @option{-mmwaitx} is used.
18286 All of them generate the machine instruction that is part of the name.
18287 @smallexample
18288 void __builtin_ia32_monitorx (void *, unsigned int, unsigned int)
18289 void __builtin_ia32_mwaitx (unsigned int, unsigned int, unsigned int)
18290 @end smallexample
18291
18292 @node x86 transactional memory intrinsics
18293 @subsection x86 Transactional Memory Intrinsics
18294
18295 These hardware transactional memory intrinsics for x86 allow you to use
18296 memory transactions with RTM (Restricted Transactional Memory).
18297 This support is enabled with the @option{-mrtm} option.
18298 For using HLE (Hardware Lock Elision) see
18299 @ref{x86 specific memory model extensions for transactional memory} instead.
18300
18301 A memory transaction commits all changes to memory in an atomic way,
18302 as visible to other threads. If the transaction fails it is rolled back
18303 and all side effects discarded.
18304
18305 Generally there is no guarantee that a memory transaction ever succeeds
18306 and suitable fallback code always needs to be supplied.
18307
18308 @deftypefn {RTM Function} {unsigned} _xbegin ()
18309 Start a RTM (Restricted Transactional Memory) transaction.
18310 Returns @code{_XBEGIN_STARTED} when the transaction
18311 started successfully (note this is not 0, so the constant has to be
18312 explicitly tested).
18313
18314 If the transaction aborts, all side-effects
18315 are undone and an abort code encoded as a bit mask is returned.
18316 The following macros are defined:
18317
18318 @table @code
18319 @item _XABORT_EXPLICIT
18320 Transaction was explicitly aborted with @code{_xabort}. The parameter passed
18321 to @code{_xabort} is available with @code{_XABORT_CODE(status)}.
18322 @item _XABORT_RETRY
18323 Transaction retry is possible.
18324 @item _XABORT_CONFLICT
18325 Transaction abort due to a memory conflict with another thread.
18326 @item _XABORT_CAPACITY
18327 Transaction abort due to the transaction using too much memory.
18328 @item _XABORT_DEBUG
18329 Transaction abort due to a debug trap.
18330 @item _XABORT_NESTED
18331 Transaction abort in an inner nested transaction.
18332 @end table
18333
18334 There is no guarantee
18335 any transaction ever succeeds, so there always needs to be a valid
18336 fallback path.
18337 @end deftypefn
18338
18339 @deftypefn {RTM Function} {void} _xend ()
18340 Commit the current transaction. When no transaction is active this faults.
18341 All memory side-effects of the transaction become visible
18342 to other threads in an atomic manner.
18343 @end deftypefn
18344
18345 @deftypefn {RTM Function} {int} _xtest ()
18346 Return a nonzero value if a transaction is currently active, otherwise 0.
18347 @end deftypefn
18348
18349 @deftypefn {RTM Function} {void} _xabort (status)
18350 Abort the current transaction. When no transaction is active this is a no-op.
18351 The @var{status} is an 8-bit constant; its value is encoded in the return
18352 value from @code{_xbegin}.
18353 @end deftypefn
18354
18355 Here is an example showing handling for @code{_XABORT_RETRY}
18356 and a fallback path for other failures:
18357
18358 @smallexample
18359 #include <immintrin.h>
18360
18361 int n_tries, max_tries;
18362 unsigned status = _XABORT_EXPLICIT;
18363 ...
18364
18365 for (n_tries = 0; n_tries < max_tries; n_tries++)
18366 @{
18367 status = _xbegin ();
18368 if (status == _XBEGIN_STARTED || !(status & _XABORT_RETRY))
18369 break;
18370 @}
18371 if (status == _XBEGIN_STARTED)
18372 @{
18373 ... transaction code...
18374 _xend ();
18375 @}
18376 else
18377 @{
18378 ... non-transactional fallback path...
18379 @}
18380 @end smallexample
18381
18382 @noindent
18383 Note that, in most cases, the transactional and non-transactional code
18384 must synchronize together to ensure consistency.
18385
18386 @node Target Format Checks
18387 @section Format Checks Specific to Particular Target Machines
18388
18389 For some target machines, GCC supports additional options to the
18390 format attribute
18391 (@pxref{Function Attributes,,Declaring Attributes of Functions}).
18392
18393 @menu
18394 * Solaris Format Checks::
18395 * Darwin Format Checks::
18396 @end menu
18397
18398 @node Solaris Format Checks
18399 @subsection Solaris Format Checks
18400
18401 Solaris targets support the @code{cmn_err} (or @code{__cmn_err__}) format
18402 check. @code{cmn_err} accepts a subset of the standard @code{printf}
18403 conversions, and the two-argument @code{%b} conversion for displaying
18404 bit-fields. See the Solaris man page for @code{cmn_err} for more information.
18405
18406 @node Darwin Format Checks
18407 @subsection Darwin Format Checks
18408
18409 Darwin targets support the @code{CFString} (or @code{__CFString__}) in the format
18410 attribute context. Declarations made with such attribution are parsed for correct syntax
18411 and format argument types. However, parsing of the format string itself is currently undefined
18412 and is not carried out by this version of the compiler.
18413
18414 Additionally, @code{CFStringRefs} (defined by the @code{CoreFoundation} headers) may
18415 also be used as format arguments. Note that the relevant headers are only likely to be
18416 available on Darwin (OSX) installations. On such installations, the XCode and system
18417 documentation provide descriptions of @code{CFString}, @code{CFStringRefs} and
18418 associated functions.
18419
18420 @node Pragmas
18421 @section Pragmas Accepted by GCC
18422 @cindex pragmas
18423 @cindex @code{#pragma}
18424
18425 GCC supports several types of pragmas, primarily in order to compile
18426 code originally written for other compilers. Note that in general
18427 we do not recommend the use of pragmas; @xref{Function Attributes},
18428 for further explanation.
18429
18430 @menu
18431 * AArch64 Pragmas::
18432 * ARM Pragmas::
18433 * M32C Pragmas::
18434 * MeP Pragmas::
18435 * RS/6000 and PowerPC Pragmas::
18436 * Darwin Pragmas::
18437 * Solaris Pragmas::
18438 * Symbol-Renaming Pragmas::
18439 * Structure-Layout Pragmas::
18440 * Weak Pragmas::
18441 * Diagnostic Pragmas::
18442 * Visibility Pragmas::
18443 * Push/Pop Macro Pragmas::
18444 * Function Specific Option Pragmas::
18445 * Loop-Specific Pragmas::
18446 @end menu
18447
18448 @node AArch64 Pragmas
18449 @subsection AArch64 Pragmas
18450
18451 The pragmas defined by the AArch64 target correspond to the AArch64
18452 target function attributes. They can be specified as below:
18453 @smallexample
18454 #pragma GCC target("string")
18455 @end smallexample
18456
18457 where @code{@var{string}} can be any string accepted as an AArch64 target
18458 attribute. @xref{AArch64 Function Attributes}, for more details
18459 on the permissible values of @code{string}.
18460
18461 @node ARM Pragmas
18462 @subsection ARM Pragmas
18463
18464 The ARM target defines pragmas for controlling the default addition of
18465 @code{long_call} and @code{short_call} attributes to functions.
18466 @xref{Function Attributes}, for information about the effects of these
18467 attributes.
18468
18469 @table @code
18470 @item long_calls
18471 @cindex pragma, long_calls
18472 Set all subsequent functions to have the @code{long_call} attribute.
18473
18474 @item no_long_calls
18475 @cindex pragma, no_long_calls
18476 Set all subsequent functions to have the @code{short_call} attribute.
18477
18478 @item long_calls_off
18479 @cindex pragma, long_calls_off
18480 Do not affect the @code{long_call} or @code{short_call} attributes of
18481 subsequent functions.
18482 @end table
18483
18484 @node M32C Pragmas
18485 @subsection M32C Pragmas
18486
18487 @table @code
18488 @item GCC memregs @var{number}
18489 @cindex pragma, memregs
18490 Overrides the command-line option @code{-memregs=} for the current
18491 file. Use with care! This pragma must be before any function in the
18492 file, and mixing different memregs values in different objects may
18493 make them incompatible. This pragma is useful when a
18494 performance-critical function uses a memreg for temporary values,
18495 as it may allow you to reduce the number of memregs used.
18496
18497 @item ADDRESS @var{name} @var{address}
18498 @cindex pragma, address
18499 For any declared symbols matching @var{name}, this does three things
18500 to that symbol: it forces the symbol to be located at the given
18501 address (a number), it forces the symbol to be volatile, and it
18502 changes the symbol's scope to be static. This pragma exists for
18503 compatibility with other compilers, but note that the common
18504 @code{1234H} numeric syntax is not supported (use @code{0x1234}
18505 instead). Example:
18506
18507 @smallexample
18508 #pragma ADDRESS port3 0x103
18509 char port3;
18510 @end smallexample
18511
18512 @end table
18513
18514 @node MeP Pragmas
18515 @subsection MeP Pragmas
18516
18517 @table @code
18518
18519 @item custom io_volatile (on|off)
18520 @cindex pragma, custom io_volatile
18521 Overrides the command-line option @code{-mio-volatile} for the current
18522 file. Note that for compatibility with future GCC releases, this
18523 option should only be used once before any @code{io} variables in each
18524 file.
18525
18526 @item GCC coprocessor available @var{registers}
18527 @cindex pragma, coprocessor available
18528 Specifies which coprocessor registers are available to the register
18529 allocator. @var{registers} may be a single register, register range
18530 separated by ellipses, or comma-separated list of those. Example:
18531
18532 @smallexample
18533 #pragma GCC coprocessor available $c0...$c10, $c28
18534 @end smallexample
18535
18536 @item GCC coprocessor call_saved @var{registers}
18537 @cindex pragma, coprocessor call_saved
18538 Specifies which coprocessor registers are to be saved and restored by
18539 any function using them. @var{registers} may be a single register,
18540 register range separated by ellipses, or comma-separated list of
18541 those. Example:
18542
18543 @smallexample
18544 #pragma GCC coprocessor call_saved $c4...$c6, $c31
18545 @end smallexample
18546
18547 @item GCC coprocessor subclass '(A|B|C|D)' = @var{registers}
18548 @cindex pragma, coprocessor subclass
18549 Creates and defines a register class. These register classes can be
18550 used by inline @code{asm} constructs. @var{registers} may be a single
18551 register, register range separated by ellipses, or comma-separated
18552 list of those. Example:
18553
18554 @smallexample
18555 #pragma GCC coprocessor subclass 'B' = $c2, $c4, $c6
18556
18557 asm ("cpfoo %0" : "=B" (x));
18558 @end smallexample
18559
18560 @item GCC disinterrupt @var{name} , @var{name} @dots{}
18561 @cindex pragma, disinterrupt
18562 For the named functions, the compiler adds code to disable interrupts
18563 for the duration of those functions. If any functions so named
18564 are not encountered in the source, a warning is emitted that the pragma is
18565 not used. Examples:
18566
18567 @smallexample
18568 #pragma disinterrupt foo
18569 #pragma disinterrupt bar, grill
18570 int foo () @{ @dots{} @}
18571 @end smallexample
18572
18573 @item GCC call @var{name} , @var{name} @dots{}
18574 @cindex pragma, call
18575 For the named functions, the compiler always uses a register-indirect
18576 call model when calling the named functions. Examples:
18577
18578 @smallexample
18579 extern int foo ();
18580 #pragma call foo
18581 @end smallexample
18582
18583 @end table
18584
18585 @node RS/6000 and PowerPC Pragmas
18586 @subsection RS/6000 and PowerPC Pragmas
18587
18588 The RS/6000 and PowerPC targets define one pragma for controlling
18589 whether or not the @code{longcall} attribute is added to function
18590 declarations by default. This pragma overrides the @option{-mlongcall}
18591 option, but not the @code{longcall} and @code{shortcall} attributes.
18592 @xref{RS/6000 and PowerPC Options}, for more information about when long
18593 calls are and are not necessary.
18594
18595 @table @code
18596 @item longcall (1)
18597 @cindex pragma, longcall
18598 Apply the @code{longcall} attribute to all subsequent function
18599 declarations.
18600
18601 @item longcall (0)
18602 Do not apply the @code{longcall} attribute to subsequent function
18603 declarations.
18604 @end table
18605
18606 @c Describe h8300 pragmas here.
18607 @c Describe sh pragmas here.
18608 @c Describe v850 pragmas here.
18609
18610 @node Darwin Pragmas
18611 @subsection Darwin Pragmas
18612
18613 The following pragmas are available for all architectures running the
18614 Darwin operating system. These are useful for compatibility with other
18615 Mac OS compilers.
18616
18617 @table @code
18618 @item mark @var{tokens}@dots{}
18619 @cindex pragma, mark
18620 This pragma is accepted, but has no effect.
18621
18622 @item options align=@var{alignment}
18623 @cindex pragma, options align
18624 This pragma sets the alignment of fields in structures. The values of
18625 @var{alignment} may be @code{mac68k}, to emulate m68k alignment, or
18626 @code{power}, to emulate PowerPC alignment. Uses of this pragma nest
18627 properly; to restore the previous setting, use @code{reset} for the
18628 @var{alignment}.
18629
18630 @item segment @var{tokens}@dots{}
18631 @cindex pragma, segment
18632 This pragma is accepted, but has no effect.
18633
18634 @item unused (@var{var} [, @var{var}]@dots{})
18635 @cindex pragma, unused
18636 This pragma declares variables to be possibly unused. GCC does not
18637 produce warnings for the listed variables. The effect is similar to
18638 that of the @code{unused} attribute, except that this pragma may appear
18639 anywhere within the variables' scopes.
18640 @end table
18641
18642 @node Solaris Pragmas
18643 @subsection Solaris Pragmas
18644
18645 The Solaris target supports @code{#pragma redefine_extname}
18646 (@pxref{Symbol-Renaming Pragmas}). It also supports additional
18647 @code{#pragma} directives for compatibility with the system compiler.
18648
18649 @table @code
18650 @item align @var{alignment} (@var{variable} [, @var{variable}]...)
18651 @cindex pragma, align
18652
18653 Increase the minimum alignment of each @var{variable} to @var{alignment}.
18654 This is the same as GCC's @code{aligned} attribute @pxref{Variable
18655 Attributes}). Macro expansion occurs on the arguments to this pragma
18656 when compiling C and Objective-C@. It does not currently occur when
18657 compiling C++, but this is a bug which may be fixed in a future
18658 release.
18659
18660 @item fini (@var{function} [, @var{function}]...)
18661 @cindex pragma, fini
18662
18663 This pragma causes each listed @var{function} to be called after
18664 main, or during shared module unloading, by adding a call to the
18665 @code{.fini} section.
18666
18667 @item init (@var{function} [, @var{function}]...)
18668 @cindex pragma, init
18669
18670 This pragma causes each listed @var{function} to be called during
18671 initialization (before @code{main}) or during shared module loading, by
18672 adding a call to the @code{.init} section.
18673
18674 @end table
18675
18676 @node Symbol-Renaming Pragmas
18677 @subsection Symbol-Renaming Pragmas
18678
18679 GCC supports a @code{#pragma} directive that changes the name used in
18680 assembly for a given declaration. While this pragma is supported on all
18681 platforms, it is intended primarily to provide compatibility with the
18682 Solaris system headers. This effect can also be achieved using the asm
18683 labels extension (@pxref{Asm Labels}).
18684
18685 @table @code
18686 @item redefine_extname @var{oldname} @var{newname}
18687 @cindex pragma, redefine_extname
18688
18689 This pragma gives the C function @var{oldname} the assembly symbol
18690 @var{newname}. The preprocessor macro @code{__PRAGMA_REDEFINE_EXTNAME}
18691 is defined if this pragma is available (currently on all platforms).
18692 @end table
18693
18694 This pragma and the asm labels extension interact in a complicated
18695 manner. Here are some corner cases you may want to be aware of:
18696
18697 @enumerate
18698 @item This pragma silently applies only to declarations with external
18699 linkage. Asm labels do not have this restriction.
18700
18701 @item In C++, this pragma silently applies only to declarations with
18702 ``C'' linkage. Again, asm labels do not have this restriction.
18703
18704 @item If either of the ways of changing the assembly name of a
18705 declaration are applied to a declaration whose assembly name has
18706 already been determined (either by a previous use of one of these
18707 features, or because the compiler needed the assembly name in order to
18708 generate code), and the new name is different, a warning issues and
18709 the name does not change.
18710
18711 @item The @var{oldname} used by @code{#pragma redefine_extname} is
18712 always the C-language name.
18713 @end enumerate
18714
18715 @node Structure-Layout Pragmas
18716 @subsection Structure-Layout Pragmas
18717
18718 For compatibility with Microsoft Windows compilers, GCC supports a
18719 set of @code{#pragma} directives that change the maximum alignment of
18720 members of structures (other than zero-width bit-fields), unions, and
18721 classes subsequently defined. The @var{n} value below always is required
18722 to be a small power of two and specifies the new alignment in bytes.
18723
18724 @enumerate
18725 @item @code{#pragma pack(@var{n})} simply sets the new alignment.
18726 @item @code{#pragma pack()} sets the alignment to the one that was in
18727 effect when compilation started (see also command-line option
18728 @option{-fpack-struct[=@var{n}]} @pxref{Code Gen Options}).
18729 @item @code{#pragma pack(push[,@var{n}])} pushes the current alignment
18730 setting on an internal stack and then optionally sets the new alignment.
18731 @item @code{#pragma pack(pop)} restores the alignment setting to the one
18732 saved at the top of the internal stack (and removes that stack entry).
18733 Note that @code{#pragma pack([@var{n}])} does not influence this internal
18734 stack; thus it is possible to have @code{#pragma pack(push)} followed by
18735 multiple @code{#pragma pack(@var{n})} instances and finalized by a single
18736 @code{#pragma pack(pop)}.
18737 @end enumerate
18738
18739 Some targets, e.g.@: x86 and PowerPC, support the @code{#pragma ms_struct}
18740 directive which lays out structures and unions subsequently defined as the
18741 documented @code{__attribute__ ((ms_struct))}.
18742
18743 @enumerate
18744 @item @code{#pragma ms_struct on} turns on the Microsoft layout.
18745 @item @code{#pragma ms_struct off} turns off the Microsoft layout.
18746 @item @code{#pragma ms_struct reset} goes back to the default layout.
18747 @end enumerate
18748
18749 Most targets also support the @code{#pragma scalar_storage_order} directive
18750 which lays out structures and unions subsequently defined as the documented
18751 @code{__attribute__ ((scalar_storage_order))}.
18752
18753 @enumerate
18754 @item @code{#pragma scalar_storage_order big-endian} sets the storage order
18755 of the scalar fields to big-endian.
18756 @item @code{#pragma scalar_storage_order little-endian} sets the storage order
18757 of the scalar fields to little-endian.
18758 @item @code{#pragma scalar_storage_order default} goes back to the endianness
18759 that was in effect when compilation started (see also command-line option
18760 @option{-fsso-struct=@var{endianness}} @pxref{C Dialect Options}).
18761 @end enumerate
18762
18763 @node Weak Pragmas
18764 @subsection Weak Pragmas
18765
18766 For compatibility with SVR4, GCC supports a set of @code{#pragma}
18767 directives for declaring symbols to be weak, and defining weak
18768 aliases.
18769
18770 @table @code
18771 @item #pragma weak @var{symbol}
18772 @cindex pragma, weak
18773 This pragma declares @var{symbol} to be weak, as if the declaration
18774 had the attribute of the same name. The pragma may appear before
18775 or after the declaration of @var{symbol}. It is not an error for
18776 @var{symbol} to never be defined at all.
18777
18778 @item #pragma weak @var{symbol1} = @var{symbol2}
18779 This pragma declares @var{symbol1} to be a weak alias of @var{symbol2}.
18780 It is an error if @var{symbol2} is not defined in the current
18781 translation unit.
18782 @end table
18783
18784 @node Diagnostic Pragmas
18785 @subsection Diagnostic Pragmas
18786
18787 GCC allows the user to selectively enable or disable certain types of
18788 diagnostics, and change the kind of the diagnostic. For example, a
18789 project's policy might require that all sources compile with
18790 @option{-Werror} but certain files might have exceptions allowing
18791 specific types of warnings. Or, a project might selectively enable
18792 diagnostics and treat them as errors depending on which preprocessor
18793 macros are defined.
18794
18795 @table @code
18796 @item #pragma GCC diagnostic @var{kind} @var{option}
18797 @cindex pragma, diagnostic
18798
18799 Modifies the disposition of a diagnostic. Note that not all
18800 diagnostics are modifiable; at the moment only warnings (normally
18801 controlled by @samp{-W@dots{}}) can be controlled, and not all of them.
18802 Use @option{-fdiagnostics-show-option} to determine which diagnostics
18803 are controllable and which option controls them.
18804
18805 @var{kind} is @samp{error} to treat this diagnostic as an error,
18806 @samp{warning} to treat it like a warning (even if @option{-Werror} is
18807 in effect), or @samp{ignored} if the diagnostic is to be ignored.
18808 @var{option} is a double quoted string that matches the command-line
18809 option.
18810
18811 @smallexample
18812 #pragma GCC diagnostic warning "-Wformat"
18813 #pragma GCC diagnostic error "-Wformat"
18814 #pragma GCC diagnostic ignored "-Wformat"
18815 @end smallexample
18816
18817 Note that these pragmas override any command-line options. GCC keeps
18818 track of the location of each pragma, and issues diagnostics according
18819 to the state as of that point in the source file. Thus, pragmas occurring
18820 after a line do not affect diagnostics caused by that line.
18821
18822 @item #pragma GCC diagnostic push
18823 @itemx #pragma GCC diagnostic pop
18824
18825 Causes GCC to remember the state of the diagnostics as of each
18826 @code{push}, and restore to that point at each @code{pop}. If a
18827 @code{pop} has no matching @code{push}, the command-line options are
18828 restored.
18829
18830 @smallexample
18831 #pragma GCC diagnostic error "-Wuninitialized"
18832 foo(a); /* error is given for this one */
18833 #pragma GCC diagnostic push
18834 #pragma GCC diagnostic ignored "-Wuninitialized"
18835 foo(b); /* no diagnostic for this one */
18836 #pragma GCC diagnostic pop
18837 foo(c); /* error is given for this one */
18838 #pragma GCC diagnostic pop
18839 foo(d); /* depends on command-line options */
18840 @end smallexample
18841
18842 @end table
18843
18844 GCC also offers a simple mechanism for printing messages during
18845 compilation.
18846
18847 @table @code
18848 @item #pragma message @var{string}
18849 @cindex pragma, diagnostic
18850
18851 Prints @var{string} as a compiler message on compilation. The message
18852 is informational only, and is neither a compilation warning nor an error.
18853
18854 @smallexample
18855 #pragma message "Compiling " __FILE__ "..."
18856 @end smallexample
18857
18858 @var{string} may be parenthesized, and is printed with location
18859 information. For example,
18860
18861 @smallexample
18862 #define DO_PRAGMA(x) _Pragma (#x)
18863 #define TODO(x) DO_PRAGMA(message ("TODO - " #x))
18864
18865 TODO(Remember to fix this)
18866 @end smallexample
18867
18868 @noindent
18869 prints @samp{/tmp/file.c:4: note: #pragma message:
18870 TODO - Remember to fix this}.
18871
18872 @end table
18873
18874 @node Visibility Pragmas
18875 @subsection Visibility Pragmas
18876
18877 @table @code
18878 @item #pragma GCC visibility push(@var{visibility})
18879 @itemx #pragma GCC visibility pop
18880 @cindex pragma, visibility
18881
18882 This pragma allows the user to set the visibility for multiple
18883 declarations without having to give each a visibility attribute
18884 (@pxref{Function Attributes}).
18885
18886 In C++, @samp{#pragma GCC visibility} affects only namespace-scope
18887 declarations. Class members and template specializations are not
18888 affected; if you want to override the visibility for a particular
18889 member or instantiation, you must use an attribute.
18890
18891 @end table
18892
18893
18894 @node Push/Pop Macro Pragmas
18895 @subsection Push/Pop Macro Pragmas
18896
18897 For compatibility with Microsoft Windows compilers, GCC supports
18898 @samp{#pragma push_macro(@var{"macro_name"})}
18899 and @samp{#pragma pop_macro(@var{"macro_name"})}.
18900
18901 @table @code
18902 @item #pragma push_macro(@var{"macro_name"})
18903 @cindex pragma, push_macro
18904 This pragma saves the value of the macro named as @var{macro_name} to
18905 the top of the stack for this macro.
18906
18907 @item #pragma pop_macro(@var{"macro_name"})
18908 @cindex pragma, pop_macro
18909 This pragma sets the value of the macro named as @var{macro_name} to
18910 the value on top of the stack for this macro. If the stack for
18911 @var{macro_name} is empty, the value of the macro remains unchanged.
18912 @end table
18913
18914 For example:
18915
18916 @smallexample
18917 #define X 1
18918 #pragma push_macro("X")
18919 #undef X
18920 #define X -1
18921 #pragma pop_macro("X")
18922 int x [X];
18923 @end smallexample
18924
18925 @noindent
18926 In this example, the definition of X as 1 is saved by @code{#pragma
18927 push_macro} and restored by @code{#pragma pop_macro}.
18928
18929 @node Function Specific Option Pragmas
18930 @subsection Function Specific Option Pragmas
18931
18932 @table @code
18933 @item #pragma GCC target (@var{"string"}...)
18934 @cindex pragma GCC target
18935
18936 This pragma allows you to set target specific options for functions
18937 defined later in the source file. One or more strings can be
18938 specified. Each function that is defined after this point is as
18939 if @code{attribute((target("STRING")))} was specified for that
18940 function. The parenthesis around the options is optional.
18941 @xref{Function Attributes}, for more information about the
18942 @code{target} attribute and the attribute syntax.
18943
18944 The @code{#pragma GCC target} pragma is presently implemented for
18945 x86, PowerPC, and Nios II targets only.
18946 @end table
18947
18948 @table @code
18949 @item #pragma GCC optimize (@var{"string"}...)
18950 @cindex pragma GCC optimize
18951
18952 This pragma allows you to set global optimization options for functions
18953 defined later in the source file. One or more strings can be
18954 specified. Each function that is defined after this point is as
18955 if @code{attribute((optimize("STRING")))} was specified for that
18956 function. The parenthesis around the options is optional.
18957 @xref{Function Attributes}, for more information about the
18958 @code{optimize} attribute and the attribute syntax.
18959 @end table
18960
18961 @table @code
18962 @item #pragma GCC push_options
18963 @itemx #pragma GCC pop_options
18964 @cindex pragma GCC push_options
18965 @cindex pragma GCC pop_options
18966
18967 These pragmas maintain a stack of the current target and optimization
18968 options. It is intended for include files where you temporarily want
18969 to switch to using a different @samp{#pragma GCC target} or
18970 @samp{#pragma GCC optimize} and then to pop back to the previous
18971 options.
18972 @end table
18973
18974 @table @code
18975 @item #pragma GCC reset_options
18976 @cindex pragma GCC reset_options
18977
18978 This pragma clears the current @code{#pragma GCC target} and
18979 @code{#pragma GCC optimize} to use the default switches as specified
18980 on the command line.
18981 @end table
18982
18983 @node Loop-Specific Pragmas
18984 @subsection Loop-Specific Pragmas
18985
18986 @table @code
18987 @item #pragma GCC ivdep
18988 @cindex pragma GCC ivdep
18989 @end table
18990
18991 With this pragma, the programmer asserts that there are no loop-carried
18992 dependencies which would prevent consecutive iterations of
18993 the following loop from executing concurrently with SIMD
18994 (single instruction multiple data) instructions.
18995
18996 For example, the compiler can only unconditionally vectorize the following
18997 loop with the pragma:
18998
18999 @smallexample
19000 void foo (int n, int *a, int *b, int *c)
19001 @{
19002 int i, j;
19003 #pragma GCC ivdep
19004 for (i = 0; i < n; ++i)
19005 a[i] = b[i] + c[i];
19006 @}
19007 @end smallexample
19008
19009 @noindent
19010 In this example, using the @code{restrict} qualifier had the same
19011 effect. In the following example, that would not be possible. Assume
19012 @math{k < -m} or @math{k >= m}. Only with the pragma, the compiler knows
19013 that it can unconditionally vectorize the following loop:
19014
19015 @smallexample
19016 void ignore_vec_dep (int *a, int k, int c, int m)
19017 @{
19018 #pragma GCC ivdep
19019 for (int i = 0; i < m; i++)
19020 a[i] = a[i + k] * c;
19021 @}
19022 @end smallexample
19023
19024
19025 @node Unnamed Fields
19026 @section Unnamed Structure and Union Fields
19027 @cindex @code{struct}
19028 @cindex @code{union}
19029
19030 As permitted by ISO C11 and for compatibility with other compilers,
19031 GCC allows you to define
19032 a structure or union that contains, as fields, structures and unions
19033 without names. For example:
19034
19035 @smallexample
19036 struct @{
19037 int a;
19038 union @{
19039 int b;
19040 float c;
19041 @};
19042 int d;
19043 @} foo;
19044 @end smallexample
19045
19046 @noindent
19047 In this example, you are able to access members of the unnamed
19048 union with code like @samp{foo.b}. Note that only unnamed structs and
19049 unions are allowed, you may not have, for example, an unnamed
19050 @code{int}.
19051
19052 You must never create such structures that cause ambiguous field definitions.
19053 For example, in this structure:
19054
19055 @smallexample
19056 struct @{
19057 int a;
19058 struct @{
19059 int a;
19060 @};
19061 @} foo;
19062 @end smallexample
19063
19064 @noindent
19065 it is ambiguous which @code{a} is being referred to with @samp{foo.a}.
19066 The compiler gives errors for such constructs.
19067
19068 @opindex fms-extensions
19069 Unless @option{-fms-extensions} is used, the unnamed field must be a
19070 structure or union definition without a tag (for example, @samp{struct
19071 @{ int a; @};}). If @option{-fms-extensions} is used, the field may
19072 also be a definition with a tag such as @samp{struct foo @{ int a;
19073 @};}, a reference to a previously defined structure or union such as
19074 @samp{struct foo;}, or a reference to a @code{typedef} name for a
19075 previously defined structure or union type.
19076
19077 @opindex fplan9-extensions
19078 The option @option{-fplan9-extensions} enables
19079 @option{-fms-extensions} as well as two other extensions. First, a
19080 pointer to a structure is automatically converted to a pointer to an
19081 anonymous field for assignments and function calls. For example:
19082
19083 @smallexample
19084 struct s1 @{ int a; @};
19085 struct s2 @{ struct s1; @};
19086 extern void f1 (struct s1 *);
19087 void f2 (struct s2 *p) @{ f1 (p); @}
19088 @end smallexample
19089
19090 @noindent
19091 In the call to @code{f1} inside @code{f2}, the pointer @code{p} is
19092 converted into a pointer to the anonymous field.
19093
19094 Second, when the type of an anonymous field is a @code{typedef} for a
19095 @code{struct} or @code{union}, code may refer to the field using the
19096 name of the @code{typedef}.
19097
19098 @smallexample
19099 typedef struct @{ int a; @} s1;
19100 struct s2 @{ s1; @};
19101 s1 f1 (struct s2 *p) @{ return p->s1; @}
19102 @end smallexample
19103
19104 These usages are only permitted when they are not ambiguous.
19105
19106 @node Thread-Local
19107 @section Thread-Local Storage
19108 @cindex Thread-Local Storage
19109 @cindex @acronym{TLS}
19110 @cindex @code{__thread}
19111
19112 Thread-local storage (@acronym{TLS}) is a mechanism by which variables
19113 are allocated such that there is one instance of the variable per extant
19114 thread. The runtime model GCC uses to implement this originates
19115 in the IA-64 processor-specific ABI, but has since been migrated
19116 to other processors as well. It requires significant support from
19117 the linker (@command{ld}), dynamic linker (@command{ld.so}), and
19118 system libraries (@file{libc.so} and @file{libpthread.so}), so it
19119 is not available everywhere.
19120
19121 At the user level, the extension is visible with a new storage
19122 class keyword: @code{__thread}. For example:
19123
19124 @smallexample
19125 __thread int i;
19126 extern __thread struct state s;
19127 static __thread char *p;
19128 @end smallexample
19129
19130 The @code{__thread} specifier may be used alone, with the @code{extern}
19131 or @code{static} specifiers, but with no other storage class specifier.
19132 When used with @code{extern} or @code{static}, @code{__thread} must appear
19133 immediately after the other storage class specifier.
19134
19135 The @code{__thread} specifier may be applied to any global, file-scoped
19136 static, function-scoped static, or static data member of a class. It may
19137 not be applied to block-scoped automatic or non-static data member.
19138
19139 When the address-of operator is applied to a thread-local variable, it is
19140 evaluated at run time and returns the address of the current thread's
19141 instance of that variable. An address so obtained may be used by any
19142 thread. When a thread terminates, any pointers to thread-local variables
19143 in that thread become invalid.
19144
19145 No static initialization may refer to the address of a thread-local variable.
19146
19147 In C++, if an initializer is present for a thread-local variable, it must
19148 be a @var{constant-expression}, as defined in 5.19.2 of the ANSI/ISO C++
19149 standard.
19150
19151 See @uref{http://www.akkadia.org/drepper/tls.pdf,
19152 ELF Handling For Thread-Local Storage} for a detailed explanation of
19153 the four thread-local storage addressing models, and how the runtime
19154 is expected to function.
19155
19156 @menu
19157 * C99 Thread-Local Edits::
19158 * C++98 Thread-Local Edits::
19159 @end menu
19160
19161 @node C99 Thread-Local Edits
19162 @subsection ISO/IEC 9899:1999 Edits for Thread-Local Storage
19163
19164 The following are a set of changes to ISO/IEC 9899:1999 (aka C99)
19165 that document the exact semantics of the language extension.
19166
19167 @itemize @bullet
19168 @item
19169 @cite{5.1.2 Execution environments}
19170
19171 Add new text after paragraph 1
19172
19173 @quotation
19174 Within either execution environment, a @dfn{thread} is a flow of
19175 control within a program. It is implementation defined whether
19176 or not there may be more than one thread associated with a program.
19177 It is implementation defined how threads beyond the first are
19178 created, the name and type of the function called at thread
19179 startup, and how threads may be terminated. However, objects
19180 with thread storage duration shall be initialized before thread
19181 startup.
19182 @end quotation
19183
19184 @item
19185 @cite{6.2.4 Storage durations of objects}
19186
19187 Add new text before paragraph 3
19188
19189 @quotation
19190 An object whose identifier is declared with the storage-class
19191 specifier @w{@code{__thread}} has @dfn{thread storage duration}.
19192 Its lifetime is the entire execution of the thread, and its
19193 stored value is initialized only once, prior to thread startup.
19194 @end quotation
19195
19196 @item
19197 @cite{6.4.1 Keywords}
19198
19199 Add @code{__thread}.
19200
19201 @item
19202 @cite{6.7.1 Storage-class specifiers}
19203
19204 Add @code{__thread} to the list of storage class specifiers in
19205 paragraph 1.
19206
19207 Change paragraph 2 to
19208
19209 @quotation
19210 With the exception of @code{__thread}, at most one storage-class
19211 specifier may be given [@dots{}]. The @code{__thread} specifier may
19212 be used alone, or immediately following @code{extern} or
19213 @code{static}.
19214 @end quotation
19215
19216 Add new text after paragraph 6
19217
19218 @quotation
19219 The declaration of an identifier for a variable that has
19220 block scope that specifies @code{__thread} shall also
19221 specify either @code{extern} or @code{static}.
19222
19223 The @code{__thread} specifier shall be used only with
19224 variables.
19225 @end quotation
19226 @end itemize
19227
19228 @node C++98 Thread-Local Edits
19229 @subsection ISO/IEC 14882:1998 Edits for Thread-Local Storage
19230
19231 The following are a set of changes to ISO/IEC 14882:1998 (aka C++98)
19232 that document the exact semantics of the language extension.
19233
19234 @itemize @bullet
19235 @item
19236 @b{[intro.execution]}
19237
19238 New text after paragraph 4
19239
19240 @quotation
19241 A @dfn{thread} is a flow of control within the abstract machine.
19242 It is implementation defined whether or not there may be more than
19243 one thread.
19244 @end quotation
19245
19246 New text after paragraph 7
19247
19248 @quotation
19249 It is unspecified whether additional action must be taken to
19250 ensure when and whether side effects are visible to other threads.
19251 @end quotation
19252
19253 @item
19254 @b{[lex.key]}
19255
19256 Add @code{__thread}.
19257
19258 @item
19259 @b{[basic.start.main]}
19260
19261 Add after paragraph 5
19262
19263 @quotation
19264 The thread that begins execution at the @code{main} function is called
19265 the @dfn{main thread}. It is implementation defined how functions
19266 beginning threads other than the main thread are designated or typed.
19267 A function so designated, as well as the @code{main} function, is called
19268 a @dfn{thread startup function}. It is implementation defined what
19269 happens if a thread startup function returns. It is implementation
19270 defined what happens to other threads when any thread calls @code{exit}.
19271 @end quotation
19272
19273 @item
19274 @b{[basic.start.init]}
19275
19276 Add after paragraph 4
19277
19278 @quotation
19279 The storage for an object of thread storage duration shall be
19280 statically initialized before the first statement of the thread startup
19281 function. An object of thread storage duration shall not require
19282 dynamic initialization.
19283 @end quotation
19284
19285 @item
19286 @b{[basic.start.term]}
19287
19288 Add after paragraph 3
19289
19290 @quotation
19291 The type of an object with thread storage duration shall not have a
19292 non-trivial destructor, nor shall it be an array type whose elements
19293 (directly or indirectly) have non-trivial destructors.
19294 @end quotation
19295
19296 @item
19297 @b{[basic.stc]}
19298
19299 Add ``thread storage duration'' to the list in paragraph 1.
19300
19301 Change paragraph 2
19302
19303 @quotation
19304 Thread, static, and automatic storage durations are associated with
19305 objects introduced by declarations [@dots{}].
19306 @end quotation
19307
19308 Add @code{__thread} to the list of specifiers in paragraph 3.
19309
19310 @item
19311 @b{[basic.stc.thread]}
19312
19313 New section before @b{[basic.stc.static]}
19314
19315 @quotation
19316 The keyword @code{__thread} applied to a non-local object gives the
19317 object thread storage duration.
19318
19319 A local variable or class data member declared both @code{static}
19320 and @code{__thread} gives the variable or member thread storage
19321 duration.
19322 @end quotation
19323
19324 @item
19325 @b{[basic.stc.static]}
19326
19327 Change paragraph 1
19328
19329 @quotation
19330 All objects that have neither thread storage duration, dynamic
19331 storage duration nor are local [@dots{}].
19332 @end quotation
19333
19334 @item
19335 @b{[dcl.stc]}
19336
19337 Add @code{__thread} to the list in paragraph 1.
19338
19339 Change paragraph 1
19340
19341 @quotation
19342 With the exception of @code{__thread}, at most one
19343 @var{storage-class-specifier} shall appear in a given
19344 @var{decl-specifier-seq}. The @code{__thread} specifier may
19345 be used alone, or immediately following the @code{extern} or
19346 @code{static} specifiers. [@dots{}]
19347 @end quotation
19348
19349 Add after paragraph 5
19350
19351 @quotation
19352 The @code{__thread} specifier can be applied only to the names of objects
19353 and to anonymous unions.
19354 @end quotation
19355
19356 @item
19357 @b{[class.mem]}
19358
19359 Add after paragraph 6
19360
19361 @quotation
19362 Non-@code{static} members shall not be @code{__thread}.
19363 @end quotation
19364 @end itemize
19365
19366 @node Binary constants
19367 @section Binary Constants using the @samp{0b} Prefix
19368 @cindex Binary constants using the @samp{0b} prefix
19369
19370 Integer constants can be written as binary constants, consisting of a
19371 sequence of @samp{0} and @samp{1} digits, prefixed by @samp{0b} or
19372 @samp{0B}. This is particularly useful in environments that operate a
19373 lot on the bit level (like microcontrollers).
19374
19375 The following statements are identical:
19376
19377 @smallexample
19378 i = 42;
19379 i = 0x2a;
19380 i = 052;
19381 i = 0b101010;
19382 @end smallexample
19383
19384 The type of these constants follows the same rules as for octal or
19385 hexadecimal integer constants, so suffixes like @samp{L} or @samp{UL}
19386 can be applied.
19387
19388 @node C++ Extensions
19389 @chapter Extensions to the C++ Language
19390 @cindex extensions, C++ language
19391 @cindex C++ language extensions
19392
19393 The GNU compiler provides these extensions to the C++ language (and you
19394 can also use most of the C language extensions in your C++ programs). If you
19395 want to write code that checks whether these features are available, you can
19396 test for the GNU compiler the same way as for C programs: check for a
19397 predefined macro @code{__GNUC__}. You can also use @code{__GNUG__} to
19398 test specifically for GNU C++ (@pxref{Common Predefined Macros,,
19399 Predefined Macros,cpp,The GNU C Preprocessor}).
19400
19401 @menu
19402 * C++ Volatiles:: What constitutes an access to a volatile object.
19403 * Restricted Pointers:: C99 restricted pointers and references.
19404 * Vague Linkage:: Where G++ puts inlines, vtables and such.
19405 * C++ Interface:: You can use a single C++ header file for both
19406 declarations and definitions.
19407 * Template Instantiation:: Methods for ensuring that exactly one copy of
19408 each needed template instantiation is emitted.
19409 * Bound member functions:: You can extract a function pointer to the
19410 method denoted by a @samp{->*} or @samp{.*} expression.
19411 * C++ Attributes:: Variable, function, and type attributes for C++ only.
19412 * Function Multiversioning:: Declaring multiple function versions.
19413 * Namespace Association:: Strong using-directives for namespace association.
19414 * Type Traits:: Compiler support for type traits.
19415 * C++ Concepts:: Improved support for generic programming.
19416 * Java Exceptions:: Tweaking exception handling to work with Java.
19417 * Deprecated Features:: Things will disappear from G++.
19418 * Backwards Compatibility:: Compatibilities with earlier definitions of C++.
19419 @end menu
19420
19421 @node C++ Volatiles
19422 @section When is a Volatile C++ Object Accessed?
19423 @cindex accessing volatiles
19424 @cindex volatile read
19425 @cindex volatile write
19426 @cindex volatile access
19427
19428 The C++ standard differs from the C standard in its treatment of
19429 volatile objects. It fails to specify what constitutes a volatile
19430 access, except to say that C++ should behave in a similar manner to C
19431 with respect to volatiles, where possible. However, the different
19432 lvalueness of expressions between C and C++ complicate the behavior.
19433 G++ behaves the same as GCC for volatile access, @xref{C
19434 Extensions,,Volatiles}, for a description of GCC's behavior.
19435
19436 The C and C++ language specifications differ when an object is
19437 accessed in a void context:
19438
19439 @smallexample
19440 volatile int *src = @var{somevalue};
19441 *src;
19442 @end smallexample
19443
19444 The C++ standard specifies that such expressions do not undergo lvalue
19445 to rvalue conversion, and that the type of the dereferenced object may
19446 be incomplete. The C++ standard does not specify explicitly that it
19447 is lvalue to rvalue conversion that is responsible for causing an
19448 access. There is reason to believe that it is, because otherwise
19449 certain simple expressions become undefined. However, because it
19450 would surprise most programmers, G++ treats dereferencing a pointer to
19451 volatile object of complete type as GCC would do for an equivalent
19452 type in C@. When the object has incomplete type, G++ issues a
19453 warning; if you wish to force an error, you must force a conversion to
19454 rvalue with, for instance, a static cast.
19455
19456 When using a reference to volatile, G++ does not treat equivalent
19457 expressions as accesses to volatiles, but instead issues a warning that
19458 no volatile is accessed. The rationale for this is that otherwise it
19459 becomes difficult to determine where volatile access occur, and not
19460 possible to ignore the return value from functions returning volatile
19461 references. Again, if you wish to force a read, cast the reference to
19462 an rvalue.
19463
19464 G++ implements the same behavior as GCC does when assigning to a
19465 volatile object---there is no reread of the assigned-to object, the
19466 assigned rvalue is reused. Note that in C++ assignment expressions
19467 are lvalues, and if used as an lvalue, the volatile object is
19468 referred to. For instance, @var{vref} refers to @var{vobj}, as
19469 expected, in the following example:
19470
19471 @smallexample
19472 volatile int vobj;
19473 volatile int &vref = vobj = @var{something};
19474 @end smallexample
19475
19476 @node Restricted Pointers
19477 @section Restricting Pointer Aliasing
19478 @cindex restricted pointers
19479 @cindex restricted references
19480 @cindex restricted this pointer
19481
19482 As with the C front end, G++ understands the C99 feature of restricted pointers,
19483 specified with the @code{__restrict__}, or @code{__restrict} type
19484 qualifier. Because you cannot compile C++ by specifying the @option{-std=c99}
19485 language flag, @code{restrict} is not a keyword in C++.
19486
19487 In addition to allowing restricted pointers, you can specify restricted
19488 references, which indicate that the reference is not aliased in the local
19489 context.
19490
19491 @smallexample
19492 void fn (int *__restrict__ rptr, int &__restrict__ rref)
19493 @{
19494 /* @r{@dots{}} */
19495 @}
19496 @end smallexample
19497
19498 @noindent
19499 In the body of @code{fn}, @var{rptr} points to an unaliased integer and
19500 @var{rref} refers to a (different) unaliased integer.
19501
19502 You may also specify whether a member function's @var{this} pointer is
19503 unaliased by using @code{__restrict__} as a member function qualifier.
19504
19505 @smallexample
19506 void T::fn () __restrict__
19507 @{
19508 /* @r{@dots{}} */
19509 @}
19510 @end smallexample
19511
19512 @noindent
19513 Within the body of @code{T::fn}, @var{this} has the effective
19514 definition @code{T *__restrict__ const this}. Notice that the
19515 interpretation of a @code{__restrict__} member function qualifier is
19516 different to that of @code{const} or @code{volatile} qualifier, in that it
19517 is applied to the pointer rather than the object. This is consistent with
19518 other compilers that implement restricted pointers.
19519
19520 As with all outermost parameter qualifiers, @code{__restrict__} is
19521 ignored in function definition matching. This means you only need to
19522 specify @code{__restrict__} in a function definition, rather than
19523 in a function prototype as well.
19524
19525 @node Vague Linkage
19526 @section Vague Linkage
19527 @cindex vague linkage
19528
19529 There are several constructs in C++ that require space in the object
19530 file but are not clearly tied to a single translation unit. We say that
19531 these constructs have ``vague linkage''. Typically such constructs are
19532 emitted wherever they are needed, though sometimes we can be more
19533 clever.
19534
19535 @table @asis
19536 @item Inline Functions
19537 Inline functions are typically defined in a header file which can be
19538 included in many different compilations. Hopefully they can usually be
19539 inlined, but sometimes an out-of-line copy is necessary, if the address
19540 of the function is taken or if inlining fails. In general, we emit an
19541 out-of-line copy in all translation units where one is needed. As an
19542 exception, we only emit inline virtual functions with the vtable, since
19543 it always requires a copy.
19544
19545 Local static variables and string constants used in an inline function
19546 are also considered to have vague linkage, since they must be shared
19547 between all inlined and out-of-line instances of the function.
19548
19549 @item VTables
19550 @cindex vtable
19551 C++ virtual functions are implemented in most compilers using a lookup
19552 table, known as a vtable. The vtable contains pointers to the virtual
19553 functions provided by a class, and each object of the class contains a
19554 pointer to its vtable (or vtables, in some multiple-inheritance
19555 situations). If the class declares any non-inline, non-pure virtual
19556 functions, the first one is chosen as the ``key method'' for the class,
19557 and the vtable is only emitted in the translation unit where the key
19558 method is defined.
19559
19560 @emph{Note:} If the chosen key method is later defined as inline, the
19561 vtable is still emitted in every translation unit that defines it.
19562 Make sure that any inline virtuals are declared inline in the class
19563 body, even if they are not defined there.
19564
19565 @item @code{type_info} objects
19566 @cindex @code{type_info}
19567 @cindex RTTI
19568 C++ requires information about types to be written out in order to
19569 implement @samp{dynamic_cast}, @samp{typeid} and exception handling.
19570 For polymorphic classes (classes with virtual functions), the @samp{type_info}
19571 object is written out along with the vtable so that @samp{dynamic_cast}
19572 can determine the dynamic type of a class object at run time. For all
19573 other types, we write out the @samp{type_info} object when it is used: when
19574 applying @samp{typeid} to an expression, throwing an object, or
19575 referring to a type in a catch clause or exception specification.
19576
19577 @item Template Instantiations
19578 Most everything in this section also applies to template instantiations,
19579 but there are other options as well.
19580 @xref{Template Instantiation,,Where's the Template?}.
19581
19582 @end table
19583
19584 When used with GNU ld version 2.8 or later on an ELF system such as
19585 GNU/Linux or Solaris 2, or on Microsoft Windows, duplicate copies of
19586 these constructs will be discarded at link time. This is known as
19587 COMDAT support.
19588
19589 On targets that don't support COMDAT, but do support weak symbols, GCC
19590 uses them. This way one copy overrides all the others, but
19591 the unused copies still take up space in the executable.
19592
19593 For targets that do not support either COMDAT or weak symbols,
19594 most entities with vague linkage are emitted as local symbols to
19595 avoid duplicate definition errors from the linker. This does not happen
19596 for local statics in inlines, however, as having multiple copies
19597 almost certainly breaks things.
19598
19599 @xref{C++ Interface,,Declarations and Definitions in One Header}, for
19600 another way to control placement of these constructs.
19601
19602 @node C++ Interface
19603 @section C++ Interface and Implementation Pragmas
19604
19605 @cindex interface and implementation headers, C++
19606 @cindex C++ interface and implementation headers
19607 @cindex pragmas, interface and implementation
19608
19609 @code{#pragma interface} and @code{#pragma implementation} provide the
19610 user with a way of explicitly directing the compiler to emit entities
19611 with vague linkage (and debugging information) in a particular
19612 translation unit.
19613
19614 @emph{Note:} These @code{#pragma}s have been superceded as of GCC 2.7.2
19615 by COMDAT support and the ``key method'' heuristic
19616 mentioned in @ref{Vague Linkage}. Using them can actually cause your
19617 program to grow due to unnecessary out-of-line copies of inline
19618 functions.
19619
19620 @table @code
19621 @item #pragma interface
19622 @itemx #pragma interface "@var{subdir}/@var{objects}.h"
19623 @kindex #pragma interface
19624 Use this directive in @emph{header files} that define object classes, to save
19625 space in most of the object files that use those classes. Normally,
19626 local copies of certain information (backup copies of inline member
19627 functions, debugging information, and the internal tables that implement
19628 virtual functions) must be kept in each object file that includes class
19629 definitions. You can use this pragma to avoid such duplication. When a
19630 header file containing @samp{#pragma interface} is included in a
19631 compilation, this auxiliary information is not generated (unless
19632 the main input source file itself uses @samp{#pragma implementation}).
19633 Instead, the object files contain references to be resolved at link
19634 time.
19635
19636 The second form of this directive is useful for the case where you have
19637 multiple headers with the same name in different directories. If you
19638 use this form, you must specify the same string to @samp{#pragma
19639 implementation}.
19640
19641 @item #pragma implementation
19642 @itemx #pragma implementation "@var{objects}.h"
19643 @kindex #pragma implementation
19644 Use this pragma in a @emph{main input file}, when you want full output from
19645 included header files to be generated (and made globally visible). The
19646 included header file, in turn, should use @samp{#pragma interface}.
19647 Backup copies of inline member functions, debugging information, and the
19648 internal tables used to implement virtual functions are all generated in
19649 implementation files.
19650
19651 @cindex implied @code{#pragma implementation}
19652 @cindex @code{#pragma implementation}, implied
19653 @cindex naming convention, implementation headers
19654 If you use @samp{#pragma implementation} with no argument, it applies to
19655 an include file with the same basename@footnote{A file's @dfn{basename}
19656 is the name stripped of all leading path information and of trailing
19657 suffixes, such as @samp{.h} or @samp{.C} or @samp{.cc}.} as your source
19658 file. For example, in @file{allclass.cc}, giving just
19659 @samp{#pragma implementation}
19660 by itself is equivalent to @samp{#pragma implementation "allclass.h"}.
19661
19662 Use the string argument if you want a single implementation file to
19663 include code from multiple header files. (You must also use
19664 @samp{#include} to include the header file; @samp{#pragma
19665 implementation} only specifies how to use the file---it doesn't actually
19666 include it.)
19667
19668 There is no way to split up the contents of a single header file into
19669 multiple implementation files.
19670 @end table
19671
19672 @cindex inlining and C++ pragmas
19673 @cindex C++ pragmas, effect on inlining
19674 @cindex pragmas in C++, effect on inlining
19675 @samp{#pragma implementation} and @samp{#pragma interface} also have an
19676 effect on function inlining.
19677
19678 If you define a class in a header file marked with @samp{#pragma
19679 interface}, the effect on an inline function defined in that class is
19680 similar to an explicit @code{extern} declaration---the compiler emits
19681 no code at all to define an independent version of the function. Its
19682 definition is used only for inlining with its callers.
19683
19684 @opindex fno-implement-inlines
19685 Conversely, when you include the same header file in a main source file
19686 that declares it as @samp{#pragma implementation}, the compiler emits
19687 code for the function itself; this defines a version of the function
19688 that can be found via pointers (or by callers compiled without
19689 inlining). If all calls to the function can be inlined, you can avoid
19690 emitting the function by compiling with @option{-fno-implement-inlines}.
19691 If any calls are not inlined, you will get linker errors.
19692
19693 @node Template Instantiation
19694 @section Where's the Template?
19695 @cindex template instantiation
19696
19697 C++ templates were the first language feature to require more
19698 intelligence from the environment than was traditionally found on a UNIX
19699 system. Somehow the compiler and linker have to make sure that each
19700 template instance occurs exactly once in the executable if it is needed,
19701 and not at all otherwise. There are two basic approaches to this
19702 problem, which are referred to as the Borland model and the Cfront model.
19703
19704 @table @asis
19705 @item Borland model
19706 Borland C++ solved the template instantiation problem by adding the code
19707 equivalent of common blocks to their linker; the compiler emits template
19708 instances in each translation unit that uses them, and the linker
19709 collapses them together. The advantage of this model is that the linker
19710 only has to consider the object files themselves; there is no external
19711 complexity to worry about. The disadvantage is that compilation time
19712 is increased because the template code is being compiled repeatedly.
19713 Code written for this model tends to include definitions of all
19714 templates in the header file, since they must be seen to be
19715 instantiated.
19716
19717 @item Cfront model
19718 The AT&T C++ translator, Cfront, solved the template instantiation
19719 problem by creating the notion of a template repository, an
19720 automatically maintained place where template instances are stored. A
19721 more modern version of the repository works as follows: As individual
19722 object files are built, the compiler places any template definitions and
19723 instantiations encountered in the repository. At link time, the link
19724 wrapper adds in the objects in the repository and compiles any needed
19725 instances that were not previously emitted. The advantages of this
19726 model are more optimal compilation speed and the ability to use the
19727 system linker; to implement the Borland model a compiler vendor also
19728 needs to replace the linker. The disadvantages are vastly increased
19729 complexity, and thus potential for error; for some code this can be
19730 just as transparent, but in practice it can been very difficult to build
19731 multiple programs in one directory and one program in multiple
19732 directories. Code written for this model tends to separate definitions
19733 of non-inline member templates into a separate file, which should be
19734 compiled separately.
19735 @end table
19736
19737 G++ implements the Borland model on targets where the linker supports it,
19738 including ELF targets (such as GNU/Linux), Mac OS X and Microsoft Windows.
19739 Otherwise G++ implements neither automatic model.
19740
19741 You have the following options for dealing with template instantiations:
19742
19743 @enumerate
19744 @item
19745 Do nothing. Code written for the Borland model works fine, but
19746 each translation unit contains instances of each of the templates it
19747 uses. The duplicate instances will be discarded by the linker, but in
19748 a large program, this can lead to an unacceptable amount of code
19749 duplication in object files or shared libraries.
19750
19751 Duplicate instances of a template can be avoided by defining an explicit
19752 instantiation in one object file, and preventing the compiler from doing
19753 implicit instantiations in any other object files by using an explicit
19754 instantiation declaration, using the @code{extern template} syntax:
19755
19756 @smallexample
19757 extern template int max (int, int);
19758 @end smallexample
19759
19760 This syntax is defined in the C++ 2011 standard, but has been supported by
19761 G++ and other compilers since well before 2011.
19762
19763 Explicit instantiations can be used for the largest or most frequently
19764 duplicated instances, without having to know exactly which other instances
19765 are used in the rest of the program. You can scatter the explicit
19766 instantiations throughout your program, perhaps putting them in the
19767 translation units where the instances are used or the translation units
19768 that define the templates themselves; you can put all of the explicit
19769 instantiations you need into one big file; or you can create small files
19770 like
19771
19772 @smallexample
19773 #include "Foo.h"
19774 #include "Foo.cc"
19775
19776 template class Foo<int>;
19777 template ostream& operator <<
19778 (ostream&, const Foo<int>&);
19779 @end smallexample
19780
19781 @noindent
19782 for each of the instances you need, and create a template instantiation
19783 library from those.
19784
19785 This is the simplest option, but also offers flexibility and
19786 fine-grained control when necessary. It is also the most portable
19787 alternative and programs using this approach will work with most modern
19788 compilers.
19789
19790 @item
19791 @opindex frepo
19792 Compile your template-using code with @option{-frepo}. The compiler
19793 generates files with the extension @samp{.rpo} listing all of the
19794 template instantiations used in the corresponding object files that
19795 could be instantiated there; the link wrapper, @samp{collect2},
19796 then updates the @samp{.rpo} files to tell the compiler where to place
19797 those instantiations and rebuild any affected object files. The
19798 link-time overhead is negligible after the first pass, as the compiler
19799 continues to place the instantiations in the same files.
19800
19801 This can be a suitable option for application code written for the Borland
19802 model, as it usually just works. Code written for the Cfront model
19803 needs to be modified so that the template definitions are available at
19804 one or more points of instantiation; usually this is as simple as adding
19805 @code{#include <tmethods.cc>} to the end of each template header.
19806
19807 For library code, if you want the library to provide all of the template
19808 instantiations it needs, just try to link all of its object files
19809 together; the link will fail, but cause the instantiations to be
19810 generated as a side effect. Be warned, however, that this may cause
19811 conflicts if multiple libraries try to provide the same instantiations.
19812 For greater control, use explicit instantiation as described in the next
19813 option.
19814
19815 @item
19816 @opindex fno-implicit-templates
19817 Compile your code with @option{-fno-implicit-templates} to disable the
19818 implicit generation of template instances, and explicitly instantiate
19819 all the ones you use. This approach requires more knowledge of exactly
19820 which instances you need than do the others, but it's less
19821 mysterious and allows greater control if you want to ensure that only
19822 the intended instances are used.
19823
19824 If you are using Cfront-model code, you can probably get away with not
19825 using @option{-fno-implicit-templates} when compiling files that don't
19826 @samp{#include} the member template definitions.
19827
19828 If you use one big file to do the instantiations, you may want to
19829 compile it without @option{-fno-implicit-templates} so you get all of the
19830 instances required by your explicit instantiations (but not by any
19831 other files) without having to specify them as well.
19832
19833 In addition to forward declaration of explicit instantiations
19834 (with @code{extern}), G++ has extended the template instantiation
19835 syntax to support instantiation of the compiler support data for a
19836 template class (i.e.@: the vtable) without instantiating any of its
19837 members (with @code{inline}), and instantiation of only the static data
19838 members of a template class, without the support data or member
19839 functions (with @code{static}):
19840
19841 @smallexample
19842 inline template class Foo<int>;
19843 static template class Foo<int>;
19844 @end smallexample
19845 @end enumerate
19846
19847 @node Bound member functions
19848 @section Extracting the Function Pointer from a Bound Pointer to Member Function
19849 @cindex pmf
19850 @cindex pointer to member function
19851 @cindex bound pointer to member function
19852
19853 In C++, pointer to member functions (PMFs) are implemented using a wide
19854 pointer of sorts to handle all the possible call mechanisms; the PMF
19855 needs to store information about how to adjust the @samp{this} pointer,
19856 and if the function pointed to is virtual, where to find the vtable, and
19857 where in the vtable to look for the member function. If you are using
19858 PMFs in an inner loop, you should really reconsider that decision. If
19859 that is not an option, you can extract the pointer to the function that
19860 would be called for a given object/PMF pair and call it directly inside
19861 the inner loop, to save a bit of time.
19862
19863 Note that you still pay the penalty for the call through a
19864 function pointer; on most modern architectures, such a call defeats the
19865 branch prediction features of the CPU@. This is also true of normal
19866 virtual function calls.
19867
19868 The syntax for this extension is
19869
19870 @smallexample
19871 extern A a;
19872 extern int (A::*fp)();
19873 typedef int (*fptr)(A *);
19874
19875 fptr p = (fptr)(a.*fp);
19876 @end smallexample
19877
19878 For PMF constants (i.e.@: expressions of the form @samp{&Klasse::Member}),
19879 no object is needed to obtain the address of the function. They can be
19880 converted to function pointers directly:
19881
19882 @smallexample
19883 fptr p1 = (fptr)(&A::foo);
19884 @end smallexample
19885
19886 @opindex Wno-pmf-conversions
19887 You must specify @option{-Wno-pmf-conversions} to use this extension.
19888
19889 @node C++ Attributes
19890 @section C++-Specific Variable, Function, and Type Attributes
19891
19892 Some attributes only make sense for C++ programs.
19893
19894 @table @code
19895 @item abi_tag ("@var{tag}", ...)
19896 @cindex @code{abi_tag} function attribute
19897 @cindex @code{abi_tag} variable attribute
19898 @cindex @code{abi_tag} type attribute
19899 The @code{abi_tag} attribute can be applied to a function, variable, or class
19900 declaration. It modifies the mangled name of the entity to
19901 incorporate the tag name, in order to distinguish the function or
19902 class from an earlier version with a different ABI; perhaps the class
19903 has changed size, or the function has a different return type that is
19904 not encoded in the mangled name.
19905
19906 The attribute can also be applied to an inline namespace, but does not
19907 affect the mangled name of the namespace; in this case it is only used
19908 for @option{-Wabi-tag} warnings and automatic tagging of functions and
19909 variables. Tagging inline namespaces is generally preferable to
19910 tagging individual declarations, but the latter is sometimes
19911 necessary, such as when only certain members of a class need to be
19912 tagged.
19913
19914 The argument can be a list of strings of arbitrary length. The
19915 strings are sorted on output, so the order of the list is
19916 unimportant.
19917
19918 A redeclaration of an entity must not add new ABI tags,
19919 since doing so would change the mangled name.
19920
19921 The ABI tags apply to a name, so all instantiations and
19922 specializations of a template have the same tags. The attribute will
19923 be ignored if applied to an explicit specialization or instantiation.
19924
19925 The @option{-Wabi-tag} flag enables a warning about a class which does
19926 not have all the ABI tags used by its subobjects and virtual functions; for users with code
19927 that needs to coexist with an earlier ABI, using this option can help
19928 to find all affected types that need to be tagged.
19929
19930 When a type involving an ABI tag is used as the type of a variable or
19931 return type of a function where that tag is not already present in the
19932 signature of the function, the tag is automatically applied to the
19933 variable or function. @option{-Wabi-tag} also warns about this
19934 situation; this warning can be avoided by explicitly tagging the
19935 variable or function or moving it into a tagged inline namespace.
19936
19937 @item init_priority (@var{priority})
19938 @cindex @code{init_priority} variable attribute
19939
19940 In Standard C++, objects defined at namespace scope are guaranteed to be
19941 initialized in an order in strict accordance with that of their definitions
19942 @emph{in a given translation unit}. No guarantee is made for initializations
19943 across translation units. However, GNU C++ allows users to control the
19944 order of initialization of objects defined at namespace scope with the
19945 @code{init_priority} attribute by specifying a relative @var{priority},
19946 a constant integral expression currently bounded between 101 and 65535
19947 inclusive. Lower numbers indicate a higher priority.
19948
19949 In the following example, @code{A} would normally be created before
19950 @code{B}, but the @code{init_priority} attribute reverses that order:
19951
19952 @smallexample
19953 Some_Class A __attribute__ ((init_priority (2000)));
19954 Some_Class B __attribute__ ((init_priority (543)));
19955 @end smallexample
19956
19957 @noindent
19958 Note that the particular values of @var{priority} do not matter; only their
19959 relative ordering.
19960
19961 @item java_interface
19962 @cindex @code{java_interface} type attribute
19963
19964 This type attribute informs C++ that the class is a Java interface. It may
19965 only be applied to classes declared within an @code{extern "Java"} block.
19966 Calls to methods declared in this interface are dispatched using GCJ's
19967 interface table mechanism, instead of regular virtual table dispatch.
19968
19969 @item warn_unused
19970 @cindex @code{warn_unused} type attribute
19971
19972 For C++ types with non-trivial constructors and/or destructors it is
19973 impossible for the compiler to determine whether a variable of this
19974 type is truly unused if it is not referenced. This type attribute
19975 informs the compiler that variables of this type should be warned
19976 about if they appear to be unused, just like variables of fundamental
19977 types.
19978
19979 This attribute is appropriate for types which just represent a value,
19980 such as @code{std::string}; it is not appropriate for types which
19981 control a resource, such as @code{std::mutex}.
19982
19983 This attribute is also accepted in C, but it is unnecessary because C
19984 does not have constructors or destructors.
19985
19986 @end table
19987
19988 See also @ref{Namespace Association}.
19989
19990 @node Function Multiversioning
19991 @section Function Multiversioning
19992 @cindex function versions
19993
19994 With the GNU C++ front end, for x86 targets, you may specify multiple
19995 versions of a function, where each function is specialized for a
19996 specific target feature. At runtime, the appropriate version of the
19997 function is automatically executed depending on the characteristics of
19998 the execution platform. Here is an example.
19999
20000 @smallexample
20001 __attribute__ ((target ("default")))
20002 int foo ()
20003 @{
20004 // The default version of foo.
20005 return 0;
20006 @}
20007
20008 __attribute__ ((target ("sse4.2")))
20009 int foo ()
20010 @{
20011 // foo version for SSE4.2
20012 return 1;
20013 @}
20014
20015 __attribute__ ((target ("arch=atom")))
20016 int foo ()
20017 @{
20018 // foo version for the Intel ATOM processor
20019 return 2;
20020 @}
20021
20022 __attribute__ ((target ("arch=amdfam10")))
20023 int foo ()
20024 @{
20025 // foo version for the AMD Family 0x10 processors.
20026 return 3;
20027 @}
20028
20029 int main ()
20030 @{
20031 int (*p)() = &foo;
20032 assert ((*p) () == foo ());
20033 return 0;
20034 @}
20035 @end smallexample
20036
20037 In the above example, four versions of function foo are created. The
20038 first version of foo with the target attribute "default" is the default
20039 version. This version gets executed when no other target specific
20040 version qualifies for execution on a particular platform. A new version
20041 of foo is created by using the same function signature but with a
20042 different target string. Function foo is called or a pointer to it is
20043 taken just like a regular function. GCC takes care of doing the
20044 dispatching to call the right version at runtime. Refer to the
20045 @uref{http://gcc.gnu.org/wiki/FunctionMultiVersioning, GCC wiki on
20046 Function Multiversioning} for more details.
20047
20048 @node Namespace Association
20049 @section Namespace Association
20050
20051 @strong{Caution:} The semantics of this extension are equivalent
20052 to C++ 2011 inline namespaces. Users should use inline namespaces
20053 instead as this extension will be removed in future versions of G++.
20054
20055 A using-directive with @code{__attribute ((strong))} is stronger
20056 than a normal using-directive in two ways:
20057
20058 @itemize @bullet
20059 @item
20060 Templates from the used namespace can be specialized and explicitly
20061 instantiated as though they were members of the using namespace.
20062
20063 @item
20064 The using namespace is considered an associated namespace of all
20065 templates in the used namespace for purposes of argument-dependent
20066 name lookup.
20067 @end itemize
20068
20069 The used namespace must be nested within the using namespace so that
20070 normal unqualified lookup works properly.
20071
20072 This is useful for composing a namespace transparently from
20073 implementation namespaces. For example:
20074
20075 @smallexample
20076 namespace std @{
20077 namespace debug @{
20078 template <class T> struct A @{ @};
20079 @}
20080 using namespace debug __attribute ((__strong__));
20081 template <> struct A<int> @{ @}; // @r{OK to specialize}
20082
20083 template <class T> void f (A<T>);
20084 @}
20085
20086 int main()
20087 @{
20088 f (std::A<float>()); // @r{lookup finds} std::f
20089 f (std::A<int>());
20090 @}
20091 @end smallexample
20092
20093 @node Type Traits
20094 @section Type Traits
20095
20096 The C++ front end implements syntactic extensions that allow
20097 compile-time determination of
20098 various characteristics of a type (or of a
20099 pair of types).
20100
20101 @table @code
20102 @item __has_nothrow_assign (type)
20103 If @code{type} is const qualified or is a reference type then the trait is
20104 false. Otherwise if @code{__has_trivial_assign (type)} is true then the trait
20105 is true, else if @code{type} is a cv class or union type with copy assignment
20106 operators that are known not to throw an exception then the trait is true,
20107 else it is false. Requires: @code{type} shall be a complete type,
20108 (possibly cv-qualified) @code{void}, or an array of unknown bound.
20109
20110 @item __has_nothrow_copy (type)
20111 If @code{__has_trivial_copy (type)} is true then the trait is true, else if
20112 @code{type} is a cv class or union type with copy constructors that
20113 are known not to throw an exception then the trait is true, else it is false.
20114 Requires: @code{type} shall be a complete type, (possibly cv-qualified)
20115 @code{void}, or an array of unknown bound.
20116
20117 @item __has_nothrow_constructor (type)
20118 If @code{__has_trivial_constructor (type)} is true then the trait is
20119 true, else if @code{type} is a cv class or union type (or array
20120 thereof) with a default constructor that is known not to throw an
20121 exception then the trait is true, else it is false. Requires:
20122 @code{type} shall be a complete type, (possibly cv-qualified)
20123 @code{void}, or an array of unknown bound.
20124
20125 @item __has_trivial_assign (type)
20126 If @code{type} is const qualified or is a reference type then the trait is
20127 false. Otherwise if @code{__is_pod (type)} is true then the trait is
20128 true, else if @code{type} is a cv class or union type with a trivial
20129 copy assignment ([class.copy]) then the trait is true, else it is
20130 false. Requires: @code{type} shall be a complete type, (possibly
20131 cv-qualified) @code{void}, or an array of unknown bound.
20132
20133 @item __has_trivial_copy (type)
20134 If @code{__is_pod (type)} is true or @code{type} is a reference type
20135 then the trait is true, else if @code{type} is a cv class or union type
20136 with a trivial copy constructor ([class.copy]) then the trait
20137 is true, else it is false. Requires: @code{type} shall be a complete
20138 type, (possibly cv-qualified) @code{void}, or an array of unknown bound.
20139
20140 @item __has_trivial_constructor (type)
20141 If @code{__is_pod (type)} is true then the trait is true, else if
20142 @code{type} is a cv class or union type (or array thereof) with a
20143 trivial default constructor ([class.ctor]) then the trait is true,
20144 else it is false. Requires: @code{type} shall be a complete
20145 type, (possibly cv-qualified) @code{void}, or an array of unknown bound.
20146
20147 @item __has_trivial_destructor (type)
20148 If @code{__is_pod (type)} is true or @code{type} is a reference type then
20149 the trait is true, else if @code{type} is a cv class or union type (or
20150 array thereof) with a trivial destructor ([class.dtor]) then the trait
20151 is true, else it is false. Requires: @code{type} shall be a complete
20152 type, (possibly cv-qualified) @code{void}, or an array of unknown bound.
20153
20154 @item __has_virtual_destructor (type)
20155 If @code{type} is a class type with a virtual destructor
20156 ([class.dtor]) then the trait is true, else it is false. Requires:
20157 @code{type} shall be a complete type, (possibly cv-qualified)
20158 @code{void}, or an array of unknown bound.
20159
20160 @item __is_abstract (type)
20161 If @code{type} is an abstract class ([class.abstract]) then the trait
20162 is true, else it is false. Requires: @code{type} shall be a complete
20163 type, (possibly cv-qualified) @code{void}, or an array of unknown bound.
20164
20165 @item __is_base_of (base_type, derived_type)
20166 If @code{base_type} is a base class of @code{derived_type}
20167 ([class.derived]) then the trait is true, otherwise it is false.
20168 Top-level cv qualifications of @code{base_type} and
20169 @code{derived_type} are ignored. For the purposes of this trait, a
20170 class type is considered is own base. Requires: if @code{__is_class
20171 (base_type)} and @code{__is_class (derived_type)} are true and
20172 @code{base_type} and @code{derived_type} are not the same type
20173 (disregarding cv-qualifiers), @code{derived_type} shall be a complete
20174 type. Diagnostic is produced if this requirement is not met.
20175
20176 @item __is_class (type)
20177 If @code{type} is a cv class type, and not a union type
20178 ([basic.compound]) the trait is true, else it is false.
20179
20180 @item __is_empty (type)
20181 If @code{__is_class (type)} is false then the trait is false.
20182 Otherwise @code{type} is considered empty if and only if: @code{type}
20183 has no non-static data members, or all non-static data members, if
20184 any, are bit-fields of length 0, and @code{type} has no virtual
20185 members, and @code{type} has no virtual base classes, and @code{type}
20186 has no base classes @code{base_type} for which
20187 @code{__is_empty (base_type)} is false. Requires: @code{type} shall
20188 be a complete type, (possibly cv-qualified) @code{void}, or an array
20189 of unknown bound.
20190
20191 @item __is_enum (type)
20192 If @code{type} is a cv enumeration type ([basic.compound]) the trait is
20193 true, else it is false.
20194
20195 @item __is_literal_type (type)
20196 If @code{type} is a literal type ([basic.types]) the trait is
20197 true, else it is false. Requires: @code{type} shall be a complete type,
20198 (possibly cv-qualified) @code{void}, or an array of unknown bound.
20199
20200 @item __is_pod (type)
20201 If @code{type} is a cv POD type ([basic.types]) then the trait is true,
20202 else it is false. Requires: @code{type} shall be a complete type,
20203 (possibly cv-qualified) @code{void}, or an array of unknown bound.
20204
20205 @item __is_polymorphic (type)
20206 If @code{type} is a polymorphic class ([class.virtual]) then the trait
20207 is true, else it is false. Requires: @code{type} shall be a complete
20208 type, (possibly cv-qualified) @code{void}, or an array of unknown bound.
20209
20210 @item __is_standard_layout (type)
20211 If @code{type} is a standard-layout type ([basic.types]) the trait is
20212 true, else it is false. Requires: @code{type} shall be a complete
20213 type, (possibly cv-qualified) @code{void}, or an array of unknown bound.
20214
20215 @item __is_trivial (type)
20216 If @code{type} is a trivial type ([basic.types]) the trait is
20217 true, else it is false. Requires: @code{type} shall be a complete
20218 type, (possibly cv-qualified) @code{void}, or an array of unknown bound.
20219
20220 @item __is_union (type)
20221 If @code{type} is a cv union type ([basic.compound]) the trait is
20222 true, else it is false.
20223
20224 @item __underlying_type (type)
20225 The underlying type of @code{type}. Requires: @code{type} shall be
20226 an enumeration type ([dcl.enum]).
20227
20228 @end table
20229
20230
20231 @node C++ Concepts
20232 @section C++ Concepts
20233
20234 C++ concepts provide much-improved support for generic programming. In
20235 particular, they allow the specification of constraints on template arguments.
20236 The constraints are used to extend the usual overloading and partial
20237 specialization capabilities of the language, allowing generic data structures
20238 and algorithms to be ``refined'' based on their properties rather than their
20239 type names.
20240
20241 The following keywords are reserved for concepts.
20242
20243 @table @code
20244 @item assumes
20245 States an expression as an assumption, and if possible, verifies that the
20246 assumption is valid. For example, @code{assume(n > 0)}.
20247
20248 @item axiom
20249 Introduces an axiom definition. Axioms introduce requirements on values.
20250
20251 @item forall
20252 Introduces a universally quantified object in an axiom. For example,
20253 @code{forall (int n) n + 0 == n}).
20254
20255 @item concept
20256 Introduces a concept definition. Concepts are sets of syntactic and semantic
20257 requirements on types and their values.
20258
20259 @item requires
20260 Introduces constraints on template arguments or requirements for a member
20261 function of a class template.
20262
20263 @end table
20264
20265 The front end also exposes a number of internal mechanism that can be used
20266 to simplify the writing of type traits. Note that some of these traits are
20267 likely to be removed in the future.
20268
20269 @table @code
20270 @item __is_same (type1, type2)
20271 A binary type trait: true whenever the type arguments are the same.
20272
20273 @end table
20274
20275
20276 @node Java Exceptions
20277 @section Java Exceptions
20278
20279 The Java language uses a slightly different exception handling model
20280 from C++. Normally, GNU C++ automatically detects when you are
20281 writing C++ code that uses Java exceptions, and handle them
20282 appropriately. However, if C++ code only needs to execute destructors
20283 when Java exceptions are thrown through it, GCC guesses incorrectly.
20284 Sample problematic code is:
20285
20286 @smallexample
20287 struct S @{ ~S(); @};
20288 extern void bar(); // @r{is written in Java, and may throw exceptions}
20289 void foo()
20290 @{
20291 S s;
20292 bar();
20293 @}
20294 @end smallexample
20295
20296 @noindent
20297 The usual effect of an incorrect guess is a link failure, complaining of
20298 a missing routine called @samp{__gxx_personality_v0}.
20299
20300 You can inform the compiler that Java exceptions are to be used in a
20301 translation unit, irrespective of what it might think, by writing
20302 @samp{@w{#pragma GCC java_exceptions}} at the head of the file. This
20303 @samp{#pragma} must appear before any functions that throw or catch
20304 exceptions, or run destructors when exceptions are thrown through them.
20305
20306 You cannot mix Java and C++ exceptions in the same translation unit. It
20307 is believed to be safe to throw a C++ exception from one file through
20308 another file compiled for the Java exception model, or vice versa, but
20309 there may be bugs in this area.
20310
20311 @node Deprecated Features
20312 @section Deprecated Features
20313
20314 In the past, the GNU C++ compiler was extended to experiment with new
20315 features, at a time when the C++ language was still evolving. Now that
20316 the C++ standard is complete, some of those features are superseded by
20317 superior alternatives. Using the old features might cause a warning in
20318 some cases that the feature will be dropped in the future. In other
20319 cases, the feature might be gone already.
20320
20321 While the list below is not exhaustive, it documents some of the options
20322 that are now deprecated:
20323
20324 @table @code
20325 @item -fexternal-templates
20326 @itemx -falt-external-templates
20327 These are two of the many ways for G++ to implement template
20328 instantiation. @xref{Template Instantiation}. The C++ standard clearly
20329 defines how template definitions have to be organized across
20330 implementation units. G++ has an implicit instantiation mechanism that
20331 should work just fine for standard-conforming code.
20332
20333 @item -fstrict-prototype
20334 @itemx -fno-strict-prototype
20335 Previously it was possible to use an empty prototype parameter list to
20336 indicate an unspecified number of parameters (like C), rather than no
20337 parameters, as C++ demands. This feature has been removed, except where
20338 it is required for backwards compatibility. @xref{Backwards Compatibility}.
20339 @end table
20340
20341 G++ allows a virtual function returning @samp{void *} to be overridden
20342 by one returning a different pointer type. This extension to the
20343 covariant return type rules is now deprecated and will be removed from a
20344 future version.
20345
20346 The G++ minimum and maximum operators (@samp{<?} and @samp{>?}) and
20347 their compound forms (@samp{<?=}) and @samp{>?=}) have been deprecated
20348 and are now removed from G++. Code using these operators should be
20349 modified to use @code{std::min} and @code{std::max} instead.
20350
20351 The named return value extension has been deprecated, and is now
20352 removed from G++.
20353
20354 The use of initializer lists with new expressions has been deprecated,
20355 and is now removed from G++.
20356
20357 Floating and complex non-type template parameters have been deprecated,
20358 and are now removed from G++.
20359
20360 The implicit typename extension has been deprecated and is now
20361 removed from G++.
20362
20363 The use of default arguments in function pointers, function typedefs
20364 and other places where they are not permitted by the standard is
20365 deprecated and will be removed from a future version of G++.
20366
20367 G++ allows floating-point literals to appear in integral constant expressions,
20368 e.g.@: @samp{ enum E @{ e = int(2.2 * 3.7) @} }
20369 This extension is deprecated and will be removed from a future version.
20370
20371 G++ allows static data members of const floating-point type to be declared
20372 with an initializer in a class definition. The standard only allows
20373 initializers for static members of const integral types and const
20374 enumeration types so this extension has been deprecated and will be removed
20375 from a future version.
20376
20377 @node Backwards Compatibility
20378 @section Backwards Compatibility
20379 @cindex Backwards Compatibility
20380 @cindex ARM [Annotated C++ Reference Manual]
20381
20382 Now that there is a definitive ISO standard C++, G++ has a specification
20383 to adhere to. The C++ language evolved over time, and features that
20384 used to be acceptable in previous drafts of the standard, such as the ARM
20385 [Annotated C++ Reference Manual], are no longer accepted. In order to allow
20386 compilation of C++ written to such drafts, G++ contains some backwards
20387 compatibilities. @emph{All such backwards compatibility features are
20388 liable to disappear in future versions of G++.} They should be considered
20389 deprecated. @xref{Deprecated Features}.
20390
20391 @table @code
20392 @item For scope
20393 If a variable is declared at for scope, it used to remain in scope until
20394 the end of the scope that contained the for statement (rather than just
20395 within the for scope). G++ retains this, but issues a warning, if such a
20396 variable is accessed outside the for scope.
20397
20398 @item Implicit C language
20399 Old C system header files did not contain an @code{extern "C" @{@dots{}@}}
20400 scope to set the language. On such systems, all header files are
20401 implicitly scoped inside a C language scope. Also, an empty prototype
20402 @code{()} is treated as an unspecified number of arguments, rather
20403 than no arguments, as C++ demands.
20404 @end table
20405
20406 @c LocalWords: emph deftypefn builtin ARCv2EM SIMD builtins msimd
20407 @c LocalWords: typedef v4si v8hi DMA dma vdiwr vdowr