]>
Commit | Line | Data |
---|---|---|
99c77e32 | 1 | @c Copyright (C) 1988, 1989, 1992, 1993, 1994, 1996, 1998, 1999, 2000, 2001, |
b7508909 | 2 | @c 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 |
cfaf579d | 3 | @c Free Software Foundation, Inc. |
c4503c0a | 4 | |
146ef39f | 5 | @c This is part of the GCC manual. |
6 | @c For copying conditions, see the file gcc.texi. | |
7 | ||
8 | @node C Extensions | |
9 | @chapter Extensions to the C Language Family | |
10 | @cindex extensions, C language | |
11 | @cindex C language extensions | |
12 | ||
67791935 | 13 | @opindex pedantic |
0858e3a2 | 14 | GNU C provides several language features not found in ISO standard C@. |
37744367 | 15 | (The @option{-pedantic} option directs GCC to print a warning message if |
146ef39f | 16 | any of these features is used.) To test for the availability of these |
17 | features in conditional compilation, check for a predefined macro | |
0858e3a2 | 18 | @code{__GNUC__}, which is always defined under GCC@. |
146ef39f | 19 | |
0858e3a2 | 20 | These extensions are available in C and Objective-C@. Most of them are |
146ef39f | 21 | also available in C++. @xref{C++ Extensions,,Extensions to the |
22 | C++ Language}, for extensions that apply @emph{only} to C++. | |
23 | ||
32f1f35b | 24 | Some features that are in ISO C99 but not C90 or C++ are also, as |
25 | extensions, accepted by GCC in C90 mode and in C++. | |
78b1f616 | 26 | |
146ef39f | 27 | @menu |
28 | * Statement Exprs:: Putting statements and declarations inside expressions. | |
bdc33d98 | 29 | * Local Labels:: Labels local to a block. |
146ef39f | 30 | * Labels as Values:: Getting pointers to labels, and computed gotos. |
31 | * Nested Functions:: As in Algol and Pascal, lexical scoping of functions. | |
c24c5fac | 32 | * Constructing Calls:: Dispatching a call to another function. |
146ef39f | 33 | * Typeof:: @code{typeof}: referring to the type of an expression. |
146ef39f | 34 | * Conditionals:: Omitting the middle operand of a @samp{?:} expression. |
c24c5fac | 35 | * Long Long:: Double-word integers---@code{long long int}. |
6388cfe2 | 36 | * __int128:: 128-bit integers---@code{__int128}. |
146ef39f | 37 | * Complex:: Data types for complex numbers. |
430be8e2 | 38 | * Floating Types:: Additional Floating Types. |
9b8516be | 39 | * Half-Precision:: Half-Precision Floating Point. |
15b474a2 | 40 | * Decimal Float:: Decimal Floating Types. |
75bd5ada | 41 | * Hex Floats:: Hexadecimal floating-point constants. |
68a556d6 | 42 | * Fixed-Point:: Fixed-Point Types. |
bd1a81f7 | 43 | * Named Address Spaces::Named address spaces. |
146ef39f | 44 | * Zero Length:: Zero-length arrays. |
45 | * Variable Length:: Arrays whose length is computed at run time. | |
710d60ed | 46 | * Empty Structures:: Structures with no members. |
c24c5fac | 47 | * Variadic Macros:: Macros with a variable number of arguments. |
da825954 | 48 | * Escaped Newlines:: Slightly looser rules for escaped newlines. |
146ef39f | 49 | * Subscripting:: Any array can be subscripted, even if not an lvalue. |
50 | * Pointer Arith:: Arithmetic on @code{void}-pointers and function pointers. | |
51 | * Initializers:: Non-constant initializers. | |
3cfa0cc4 | 52 | * Compound Literals:: Compound literals give structures, unions |
c24c5fac | 53 | or arrays as values. |
54 | * Designated Inits:: Labeling elements of initializers. | |
146ef39f | 55 | * Cast to Union:: Casting to union type from any member of the union. |
c24c5fac | 56 | * Case Ranges:: `case 1 ... 9' and such. |
57 | * Mixed Declarations:: Mixing declarations and code. | |
146ef39f | 58 | * Function Attributes:: Declaring that functions have no side effects, |
c24c5fac | 59 | or that they can never return. |
b31bfb3f | 60 | * Attribute Syntax:: Formal syntax for attributes. |
146ef39f | 61 | * Function Prototypes:: Prototype declarations and old-style definitions. |
62 | * C++ Comments:: C++ comments are recognized. | |
63 | * Dollar Signs:: Dollar sign is allowed in identifiers. | |
64 | * Character Escapes:: @samp{\e} stands for the character @key{ESC}. | |
c24c5fac | 65 | * Variable Attributes:: Specifying attributes of variables. |
66 | * Type Attributes:: Specifying attributes of types. | |
146ef39f | 67 | * Alignment:: Inquiring about the alignment of a type or variable. |
68 | * Inline:: Defining inline functions (as fast as macros). | |
e83c4d0f | 69 | * Volatiles:: What constitutes an access to a volatile object. |
146ef39f | 70 | * Extended Asm:: Assembler instructions with C expressions as operands. |
c24c5fac | 71 | (With them you can define ``built-in'' functions.) |
146ef39f | 72 | * Constraints:: Constraints for asm operands |
73 | * Asm Labels:: Specifying the assembler name to use for a C symbol. | |
74 | * Explicit Reg Vars:: Defining variables residing in specified registers. | |
75 | * Alternate Keywords:: @code{__const__}, @code{__asm__}, etc., for header files. | |
76 | * Incomplete Enums:: @code{enum foo;}, with details to follow. | |
c24c5fac | 77 | * Function Names:: Printable strings which are the name of the current |
78 | function. | |
146ef39f | 79 | * Return Address:: Getting the return or frame address of a function. |
ee5925ea | 80 | * Vector Extensions:: Using vector instructions through built-in functions. |
43bf5d72 | 81 | * Offsetof:: Special syntax for implementing @code{offsetof}. |
1cd6e20d | 82 | * __sync Builtins:: Legacy built-in functions for atomic memory access. |
83 | * __atomic Builtins:: Atomic built-in functions with memory model. | |
0a39fd54 | 84 | * Object Size Checking:: Built-in functions for limited buffer overflow |
85 | checking. | |
7014838c | 86 | * Other Builtins:: Other built-in functions. |
ca5827cf | 87 | * Target Builtins:: Built-in functions specific to particular targets. |
1e9af880 | 88 | * Target Format Checks:: Format checks specific to particular targets. |
49f45d83 | 89 | * Pragmas:: Pragmas accepted by GCC. |
f5b36051 | 90 | * Unnamed Fields:: Unnamed struct/union fields within structs/unions. |
2a6f0f81 | 91 | * Thread-Local:: Per-thread variables. |
d7282a2b | 92 | * Binary constants:: Binary constants using the @samp{0b} prefix. |
146ef39f | 93 | @end menu |
146ef39f | 94 | |
95 | @node Statement Exprs | |
96 | @section Statements and Declarations in Expressions | |
97 | @cindex statements inside expressions | |
98 | @cindex declarations inside expressions | |
99 | @cindex expressions containing statements | |
100 | @cindex macros, statements in expressions | |
101 | ||
102 | @c the above section title wrapped and causes an underfull hbox.. i | |
103 | @c changed it from "within" to "in". --mew 4feb93 | |
146ef39f | 104 | A compound statement enclosed in parentheses may appear as an expression |
0858e3a2 | 105 | in GNU C@. This allows you to use loops, switches, and local variables |
146ef39f | 106 | within an expression. |
107 | ||
108 | Recall that a compound statement is a sequence of statements surrounded | |
109 | by braces; in this construct, parentheses go around the braces. For | |
110 | example: | |
111 | ||
a0ecd6b1 | 112 | @smallexample |
146ef39f | 113 | (@{ int y = foo (); int z; |
114 | if (y > 0) z = y; | |
115 | else z = - y; | |
116 | z; @}) | |
a0ecd6b1 | 117 | @end smallexample |
146ef39f | 118 | |
119 | @noindent | |
120 | is a valid (though slightly more complex than necessary) expression | |
121 | for the absolute value of @code{foo ()}. | |
122 | ||
123 | The last thing in the compound statement should be an expression | |
124 | followed by a semicolon; the value of this subexpression serves as the | |
125 | value of the entire construct. (If you use some other kind of statement | |
126 | last within the braces, the construct has type @code{void}, and thus | |
127 | effectively no value.) | |
128 | ||
129 | This feature is especially useful in making macro definitions ``safe'' (so | |
130 | that they evaluate each operand exactly once). For example, the | |
131 | ``maximum'' function is commonly defined as a macro in standard C as | |
132 | follows: | |
133 | ||
a0ecd6b1 | 134 | @smallexample |
146ef39f | 135 | #define max(a,b) ((a) > (b) ? (a) : (b)) |
a0ecd6b1 | 136 | @end smallexample |
146ef39f | 137 | |
138 | @noindent | |
139 | @cindex side effects, macro argument | |
140 | But this definition computes either @var{a} or @var{b} twice, with bad | |
141 | results if the operand has side effects. In GNU C, if you know the | |
153e79bc | 142 | type of the operands (here taken as @code{int}), you can define |
146ef39f | 143 | the macro safely as follows: |
144 | ||
a0ecd6b1 | 145 | @smallexample |
146ef39f | 146 | #define maxint(a,b) \ |
147 | (@{int _a = (a), _b = (b); _a > _b ? _a : _b; @}) | |
a0ecd6b1 | 148 | @end smallexample |
146ef39f | 149 | |
150 | Embedded statements are not allowed in constant expressions, such as | |
8e5fcce7 | 151 | the value of an enumeration constant, the width of a bit-field, or |
146ef39f | 152 | the initial value of a static variable. |
153 | ||
154 | If you don't know the type of the operand, you can still do this, but you | |
f6f89f14 | 155 | must use @code{typeof} (@pxref{Typeof}). |
146ef39f | 156 | |
942ab15b | 157 | In G++, the result value of a statement expression undergoes array and |
158 | function pointer decay, and is returned by value to the enclosing | |
b3d47662 | 159 | expression. For instance, if @code{A} is a class, then |
6a50ae27 | 160 | |
942ab15b | 161 | @smallexample |
162 | A a; | |
6a50ae27 | 163 | |
942ab15b | 164 | (@{a;@}).Foo () |
165 | @end smallexample | |
6a50ae27 | 166 | |
167 | @noindent | |
942ab15b | 168 | will construct a temporary @code{A} object to hold the result of the |
169 | statement expression, and that will be used to invoke @code{Foo}. | |
170 | Therefore the @code{this} pointer observed by @code{Foo} will not be the | |
171 | address of @code{a}. | |
172 | ||
173 | Any temporaries created within a statement within a statement expression | |
174 | will be destroyed at the statement's end. This makes statement | |
175 | expressions inside macros slightly different from function calls. In | |
176 | the latter case temporaries introduced during argument evaluation will | |
177 | be destroyed at the end of the statement that includes the function | |
178 | call. In the statement expression case they will be destroyed during | |
179 | the statement expression. For instance, | |
6a50ae27 | 180 | |
942ab15b | 181 | @smallexample |
182 | #define macro(a) (@{__typeof__(a) b = (a); b + 3; @}) | |
183 | template<typename T> T function(T a) @{ T b = a; return b + 3; @} | |
184 | ||
185 | void foo () | |
186 | @{ | |
187 | macro (X ()); | |
188 | function (X ()); | |
189 | @} | |
190 | @end smallexample | |
6a50ae27 | 191 | |
192 | @noindent | |
942ab15b | 193 | will have different places where temporaries are destroyed. For the |
194 | @code{macro} case, the temporary @code{X} will be destroyed just after | |
195 | the initialization of @code{b}. In the @code{function} case that | |
196 | temporary will be destroyed when the function returns. | |
6a50ae27 | 197 | |
198 | These considerations mean that it is probably a bad idea to use | |
199 | statement-expressions of this form in header files that are designed to | |
f12bbcea | 200 | work with C++. (Note that some versions of the GNU C Library contained |
201 | header files using statement-expression that lead to precisely this | |
202 | bug.) | |
6a50ae27 | 203 | |
f08c7a57 | 204 | Jumping into a statement expression with @code{goto} or using a |
205 | @code{switch} statement outside the statement expression with a | |
206 | @code{case} or @code{default} label inside the statement expression is | |
207 | not permitted. Jumping into a statement expression with a computed | |
208 | @code{goto} (@pxref{Labels as Values}) yields undefined behavior. | |
209 | Jumping out of a statement expression is permitted, but if the | |
210 | statement expression is part of a larger expression then it is | |
211 | unspecified which other subexpressions of that expression have been | |
212 | evaluated except where the language definition requires certain | |
213 | subexpressions to be evaluated before or after the statement | |
214 | expression. In any case, as with a function call the evaluation of a | |
215 | statement expression is not interleaved with the evaluation of other | |
216 | parts of the containing expression. For example, | |
217 | ||
218 | @smallexample | |
219 | foo (), ((@{ bar1 (); goto a; 0; @}) + bar2 ()), baz(); | |
220 | @end smallexample | |
221 | ||
222 | @noindent | |
223 | will call @code{foo} and @code{bar1} and will not call @code{baz} but | |
224 | may or may not call @code{bar2}. If @code{bar2} is called, it will be | |
225 | called after @code{foo} and before @code{bar1} | |
226 | ||
146ef39f | 227 | @node Local Labels |
228 | @section Locally Declared Labels | |
229 | @cindex local labels | |
230 | @cindex macros, local labels | |
231 | ||
bdc33d98 | 232 | GCC allows you to declare @dfn{local labels} in any nested block |
b3d47662 | 233 | scope. A local label is just like an ordinary label, but you can |
bdc33d98 | 234 | only reference it (with a @code{goto} statement, or by taking its |
7a0ad664 | 235 | address) within the block in which it was declared. |
146ef39f | 236 | |
237 | A local label declaration looks like this: | |
238 | ||
a0ecd6b1 | 239 | @smallexample |
146ef39f | 240 | __label__ @var{label}; |
a0ecd6b1 | 241 | @end smallexample |
146ef39f | 242 | |
243 | @noindent | |
244 | or | |
245 | ||
a0ecd6b1 | 246 | @smallexample |
4ae74ddd | 247 | __label__ @var{label1}, @var{label2}, /* @r{@dots{}} */; |
a0ecd6b1 | 248 | @end smallexample |
146ef39f | 249 | |
bdc33d98 | 250 | Local label declarations must come at the beginning of the block, |
251 | before any ordinary declarations or statements. | |
146ef39f | 252 | |
253 | The label declaration defines the label @emph{name}, but does not define | |
254 | the label itself. You must do this in the usual way, with | |
255 | @code{@var{label}:}, within the statements of the statement expression. | |
256 | ||
bdc33d98 | 257 | The local label feature is useful for complex macros. If a macro |
258 | contains nested loops, a @code{goto} can be useful for breaking out of | |
259 | them. However, an ordinary label whose scope is the whole function | |
260 | cannot be used: if the macro can be expanded several times in one | |
261 | function, the label will be multiply defined in that function. A | |
262 | local label avoids this problem. For example: | |
263 | ||
a0ecd6b1 | 264 | @smallexample |
bdc33d98 | 265 | #define SEARCH(value, array, target) \ |
266 | do @{ \ | |
267 | __label__ found; \ | |
268 | typeof (target) _SEARCH_target = (target); \ | |
269 | typeof (*(array)) *_SEARCH_array = (array); \ | |
270 | int i, j; \ | |
271 | int value; \ | |
272 | for (i = 0; i < max; i++) \ | |
273 | for (j = 0; j < max; j++) \ | |
274 | if (_SEARCH_array[i][j] == _SEARCH_target) \ | |
275 | @{ (value) = i; goto found; @} \ | |
276 | (value) = -1; \ | |
277 | found:; \ | |
278 | @} while (0) | |
a0ecd6b1 | 279 | @end smallexample |
bdc33d98 | 280 | |
281 | This could also be written using a statement-expression: | |
146ef39f | 282 | |
a0ecd6b1 | 283 | @smallexample |
146ef39f | 284 | #define SEARCH(array, target) \ |
d90db7dc | 285 | (@{ \ |
146ef39f | 286 | __label__ found; \ |
287 | typeof (target) _SEARCH_target = (target); \ | |
288 | typeof (*(array)) *_SEARCH_array = (array); \ | |
289 | int i, j; \ | |
290 | int value; \ | |
291 | for (i = 0; i < max; i++) \ | |
292 | for (j = 0; j < max; j++) \ | |
293 | if (_SEARCH_array[i][j] == _SEARCH_target) \ | |
d90db7dc | 294 | @{ value = i; goto found; @} \ |
146ef39f | 295 | value = -1; \ |
296 | found: \ | |
297 | value; \ | |
298 | @}) | |
a0ecd6b1 | 299 | @end smallexample |
146ef39f | 300 | |
bdc33d98 | 301 | Local label declarations also make the labels they declare visible to |
302 | nested functions, if there are any. @xref{Nested Functions}, for details. | |
303 | ||
146ef39f | 304 | @node Labels as Values |
305 | @section Labels as Values | |
306 | @cindex labels as values | |
307 | @cindex computed gotos | |
308 | @cindex goto with computed label | |
309 | @cindex address of a label | |
310 | ||
311 | You can get the address of a label defined in the current function | |
312 | (or a containing function) with the unary operator @samp{&&}. The | |
313 | value has type @code{void *}. This value is a constant and can be used | |
314 | wherever a constant of that type is valid. For example: | |
315 | ||
a0ecd6b1 | 316 | @smallexample |
146ef39f | 317 | void *ptr; |
4ae74ddd | 318 | /* @r{@dots{}} */ |
146ef39f | 319 | ptr = &&foo; |
a0ecd6b1 | 320 | @end smallexample |
146ef39f | 321 | |
322 | To use these values, you need to be able to jump to one. This is done | |
323 | with the computed goto statement@footnote{The analogous feature in | |
324 | Fortran is called an assigned goto, but that name seems inappropriate in | |
325 | C, where one can do more than simply store label addresses in label | |
326 | variables.}, @code{goto *@var{exp};}. For example, | |
327 | ||
a0ecd6b1 | 328 | @smallexample |
146ef39f | 329 | goto *ptr; |
a0ecd6b1 | 330 | @end smallexample |
146ef39f | 331 | |
332 | @noindent | |
333 | Any expression of type @code{void *} is allowed. | |
334 | ||
335 | One way of using these constants is in initializing a static array that | |
336 | will serve as a jump table: | |
337 | ||
a0ecd6b1 | 338 | @smallexample |
146ef39f | 339 | static void *array[] = @{ &&foo, &&bar, &&hack @}; |
a0ecd6b1 | 340 | @end smallexample |
146ef39f | 341 | |
342 | Then you can select a label with indexing, like this: | |
343 | ||
a0ecd6b1 | 344 | @smallexample |
146ef39f | 345 | goto *array[i]; |
a0ecd6b1 | 346 | @end smallexample |
146ef39f | 347 | |
348 | @noindent | |
349 | Note that this does not check whether the subscript is in bounds---array | |
350 | indexing in C never does that. | |
351 | ||
352 | Such an array of label values serves a purpose much like that of the | |
353 | @code{switch} statement. The @code{switch} statement is cleaner, so | |
354 | use that rather than an array unless the problem does not fit a | |
355 | @code{switch} statement very well. | |
356 | ||
357 | Another use of label values is in an interpreter for threaded code. | |
358 | The labels within the interpreter function can be stored in the | |
359 | threaded code for super-fast dispatching. | |
360 | ||
3b0848a2 | 361 | You may not use this mechanism to jump to code in a different function. |
56d9dfd0 | 362 | If you do that, totally unpredictable things will happen. The best way to |
146ef39f | 363 | avoid this is to store the label address only in automatic variables and |
364 | never pass it as an argument. | |
365 | ||
56d9dfd0 | 366 | An alternate way to write the above example is |
367 | ||
a0ecd6b1 | 368 | @smallexample |
d90db7dc | 369 | static const int array[] = @{ &&foo - &&foo, &&bar - &&foo, |
370 | &&hack - &&foo @}; | |
56d9dfd0 | 371 | goto *(&&foo + array[i]); |
a0ecd6b1 | 372 | @end smallexample |
56d9dfd0 | 373 | |
374 | @noindent | |
375 | This is more friendly to code living in shared libraries, as it reduces | |
376 | the number of dynamic relocations that are needed, and by consequence, | |
377 | allows the data to be read-only. | |
378 | ||
bdb1f0d1 | 379 | The @code{&&foo} expressions for the same label might have different |
380 | values if the containing function is inlined or cloned. If a program | |
381 | relies on them being always the same, | |
382 | @code{__attribute__((__noinline__,__noclone__))} should be used to | |
383 | prevent inlining and cloning. If @code{&&foo} is used in a static | |
384 | variable initializer, inlining and cloning is forbidden. | |
361c9aad | 385 | |
146ef39f | 386 | @node Nested Functions |
387 | @section Nested Functions | |
388 | @cindex nested functions | |
389 | @cindex downward funargs | |
390 | @cindex thunks | |
391 | ||
392 | A @dfn{nested function} is a function defined inside another function. | |
393 | (Nested functions are not supported for GNU C++.) The nested function's | |
394 | name is local to the block where it is defined. For example, here we | |
395 | define a nested function named @code{square}, and call it twice: | |
396 | ||
a0ecd6b1 | 397 | @smallexample |
146ef39f | 398 | @group |
399 | foo (double a, double b) | |
400 | @{ | |
401 | double square (double z) @{ return z * z; @} | |
402 | ||
403 | return square (a) + square (b); | |
404 | @} | |
405 | @end group | |
a0ecd6b1 | 406 | @end smallexample |
146ef39f | 407 | |
408 | The nested function can access all the variables of the containing | |
409 | function that are visible at the point of its definition. This is | |
410 | called @dfn{lexical scoping}. For example, here we show a nested | |
411 | function which uses an inherited variable named @code{offset}: | |
412 | ||
a0ecd6b1 | 413 | @smallexample |
70c2c81c | 414 | @group |
146ef39f | 415 | bar (int *array, int offset, int size) |
416 | @{ | |
417 | int access (int *array, int index) | |
418 | @{ return array[index + offset]; @} | |
419 | int i; | |
4ae74ddd | 420 | /* @r{@dots{}} */ |
146ef39f | 421 | for (i = 0; i < size; i++) |
4ae74ddd | 422 | /* @r{@dots{}} */ access (array, i) /* @r{@dots{}} */ |
146ef39f | 423 | @} |
70c2c81c | 424 | @end group |
a0ecd6b1 | 425 | @end smallexample |
146ef39f | 426 | |
427 | Nested function definitions are permitted within functions in the places | |
dbb77364 | 428 | where variable definitions are allowed; that is, in any block, mixed |
429 | with the other declarations and statements in the block. | |
146ef39f | 430 | |
431 | It is possible to call the nested function from outside the scope of its | |
432 | name by storing its address or passing the address to another function: | |
433 | ||
a0ecd6b1 | 434 | @smallexample |
146ef39f | 435 | hack (int *array, int size) |
436 | @{ | |
437 | void store (int index, int value) | |
438 | @{ array[index] = value; @} | |
439 | ||
440 | intermediate (store, size); | |
441 | @} | |
a0ecd6b1 | 442 | @end smallexample |
146ef39f | 443 | |
444 | Here, the function @code{intermediate} receives the address of | |
445 | @code{store} as an argument. If @code{intermediate} calls @code{store}, | |
446 | the arguments given to @code{store} are used to store into @code{array}. | |
447 | But this technique works only so long as the containing function | |
448 | (@code{hack}, in this example) does not exit. | |
449 | ||
450 | If you try to call the nested function through its address after the | |
451 | containing function has exited, all hell will break loose. If you try | |
452 | to call it after a containing scope level has exited, and if it refers | |
453 | to some of the variables that are no longer in scope, you may be lucky, | |
454 | but it's not wise to take the risk. If, however, the nested function | |
455 | does not refer to anything that has gone out of scope, you should be | |
456 | safe. | |
457 | ||
0fff59be | 458 | GCC implements taking the address of a nested function using a technique |
15b474a2 | 459 | called @dfn{trampolines}. This technique was described in |
3e8e7577 | 460 | @cite{Lexical Closures for C++} (Thomas M. Breuel, USENIX |
461 | C++ Conference Proceedings, October 17-21, 1988). | |
146ef39f | 462 | |
463 | A nested function can jump to a label inherited from a containing | |
464 | function, provided the label was explicitly declared in the containing | |
465 | function (@pxref{Local Labels}). Such a jump returns instantly to the | |
466 | containing function, exiting the nested function which did the | |
467 | @code{goto} and any intermediate functions as well. Here is an example: | |
468 | ||
a0ecd6b1 | 469 | @smallexample |
146ef39f | 470 | @group |
471 | bar (int *array, int offset, int size) | |
472 | @{ | |
473 | __label__ failure; | |
474 | int access (int *array, int index) | |
475 | @{ | |
476 | if (index > size) | |
477 | goto failure; | |
478 | return array[index + offset]; | |
479 | @} | |
480 | int i; | |
4ae74ddd | 481 | /* @r{@dots{}} */ |
146ef39f | 482 | for (i = 0; i < size; i++) |
4ae74ddd | 483 | /* @r{@dots{}} */ access (array, i) /* @r{@dots{}} */ |
484 | /* @r{@dots{}} */ | |
146ef39f | 485 | return 0; |
486 | ||
487 | /* @r{Control comes here from @code{access} | |
488 | if it detects an error.} */ | |
489 | failure: | |
490 | return -1; | |
491 | @} | |
492 | @end group | |
a0ecd6b1 | 493 | @end smallexample |
146ef39f | 494 | |
557522b9 | 495 | A nested function always has no linkage. Declaring one with |
496 | @code{extern} or @code{static} is erroneous. If you need to declare the nested function | |
146ef39f | 497 | before its definition, use @code{auto} (which is otherwise meaningless |
498 | for function declarations). | |
499 | ||
a0ecd6b1 | 500 | @smallexample |
146ef39f | 501 | bar (int *array, int offset, int size) |
502 | @{ | |
503 | __label__ failure; | |
504 | auto int access (int *, int); | |
4ae74ddd | 505 | /* @r{@dots{}} */ |
146ef39f | 506 | int access (int *array, int index) |
507 | @{ | |
508 | if (index > size) | |
509 | goto failure; | |
510 | return array[index + offset]; | |
511 | @} | |
4ae74ddd | 512 | /* @r{@dots{}} */ |
146ef39f | 513 | @} |
a0ecd6b1 | 514 | @end smallexample |
146ef39f | 515 | |
516 | @node Constructing Calls | |
517 | @section Constructing Function Calls | |
518 | @cindex constructing calls | |
519 | @cindex forwarding calls | |
520 | ||
521 | Using the built-in functions described below, you can record | |
522 | the arguments a function received, and call another function | |
523 | with the same arguments, without knowing the number or types | |
524 | of the arguments. | |
525 | ||
526 | You can also record the return value of that function call, | |
527 | and later return that value, without knowing what data type | |
528 | the function tried to return (as long as your caller expects | |
529 | that data type). | |
530 | ||
57fbc47a | 531 | However, these built-in functions may interact badly with some |
532 | sophisticated features or other extensions of the language. It | |
533 | is, therefore, not recommended to use them outside very simple | |
534 | functions acting as mere forwarders for their arguments. | |
535 | ||
67791935 | 536 | @deftypefn {Built-in Function} {void *} __builtin_apply_args () |
537 | This built-in function returns a pointer to data | |
146ef39f | 538 | describing how to perform a call with the same arguments as were passed |
539 | to the current function. | |
540 | ||
541 | The function saves the arg pointer register, structure value address, | |
542 | and all registers that might be used to pass arguments to a function | |
543 | into a block of memory allocated on the stack. Then it returns the | |
544 | address of that block. | |
67791935 | 545 | @end deftypefn |
146ef39f | 546 | |
67791935 | 547 | @deftypefn {Built-in Function} {void *} __builtin_apply (void (*@var{function})(), void *@var{arguments}, size_t @var{size}) |
548 | This built-in function invokes @var{function} | |
549 | with a copy of the parameters described by @var{arguments} | |
550 | and @var{size}. | |
146ef39f | 551 | |
552 | The value of @var{arguments} should be the value returned by | |
553 | @code{__builtin_apply_args}. The argument @var{size} specifies the size | |
554 | of the stack argument data, in bytes. | |
555 | ||
67791935 | 556 | This function returns a pointer to data describing |
146ef39f | 557 | how to return whatever value was returned by @var{function}. The data |
558 | is saved in a block of memory allocated on the stack. | |
559 | ||
560 | It is not always simple to compute the proper value for @var{size}. The | |
561 | value is used by @code{__builtin_apply} to compute the amount of data | |
562 | that should be pushed on the stack and copied from the incoming argument | |
563 | area. | |
67791935 | 564 | @end deftypefn |
146ef39f | 565 | |
67791935 | 566 | @deftypefn {Built-in Function} {void} __builtin_return (void *@var{result}) |
146ef39f | 567 | This built-in function returns the value described by @var{result} from |
568 | the containing function. You should specify, for @var{result}, a value | |
569 | returned by @code{__builtin_apply}. | |
67791935 | 570 | @end deftypefn |
146ef39f | 571 | |
12786727 | 572 | @deftypefn {Built-in Function} {} __builtin_va_arg_pack () |
48dc2227 | 573 | This built-in function represents all anonymous arguments of an inline |
574 | function. It can be used only in inline functions which will be always | |
575 | inlined, never compiled as a separate function, such as those using | |
576 | @code{__attribute__ ((__always_inline__))} or | |
577 | @code{__attribute__ ((__gnu_inline__))} extern inline functions. | |
578 | It must be only passed as last argument to some other function | |
579 | with variable arguments. This is useful for writing small wrapper | |
580 | inlines for variable argument functions, when using preprocessor | |
581 | macros is undesirable. For example: | |
582 | @smallexample | |
583 | extern int myprintf (FILE *f, const char *format, ...); | |
584 | extern inline __attribute__ ((__gnu_inline__)) int | |
585 | myprintf (FILE *f, const char *format, ...) | |
586 | @{ | |
587 | int r = fprintf (f, "myprintf: "); | |
588 | if (r < 0) | |
589 | return r; | |
590 | int s = fprintf (f, format, __builtin_va_arg_pack ()); | |
591 | if (s < 0) | |
592 | return s; | |
593 | return r + s; | |
594 | @} | |
595 | @end smallexample | |
596 | @end deftypefn | |
597 | ||
12786727 | 598 | @deftypefn {Built-in Function} {size_t} __builtin_va_arg_pack_len () |
4e1d7ea4 | 599 | This built-in function returns the number of anonymous arguments of |
600 | an inline function. It can be used only in inline functions which | |
601 | will be always inlined, never compiled as a separate function, such | |
602 | as those using @code{__attribute__ ((__always_inline__))} or | |
603 | @code{__attribute__ ((__gnu_inline__))} extern inline functions. | |
604 | For example following will do link or runtime checking of open | |
605 | arguments for optimized code: | |
606 | @smallexample | |
607 | #ifdef __OPTIMIZE__ | |
608 | extern inline __attribute__((__gnu_inline__)) int | |
609 | myopen (const char *path, int oflag, ...) | |
610 | @{ | |
611 | if (__builtin_va_arg_pack_len () > 1) | |
612 | warn_open_too_many_arguments (); | |
613 | ||
614 | if (__builtin_constant_p (oflag)) | |
615 | @{ | |
616 | if ((oflag & O_CREAT) != 0 && __builtin_va_arg_pack_len () < 1) | |
617 | @{ | |
618 | warn_open_missing_mode (); | |
619 | return __open_2 (path, oflag); | |
620 | @} | |
621 | return open (path, oflag, __builtin_va_arg_pack ()); | |
622 | @} | |
15b474a2 | 623 | |
4e1d7ea4 | 624 | if (__builtin_va_arg_pack_len () < 1) |
625 | return __open_2 (path, oflag); | |
626 | ||
627 | return open (path, oflag, __builtin_va_arg_pack ()); | |
628 | @} | |
629 | #endif | |
630 | @end smallexample | |
631 | @end deftypefn | |
632 | ||
146ef39f | 633 | @node Typeof |
634 | @section Referring to a Type with @code{typeof} | |
635 | @findex typeof | |
636 | @findex sizeof | |
637 | @cindex macros, types of arguments | |
638 | ||
639 | Another way to refer to the type of an expression is with @code{typeof}. | |
640 | The syntax of using of this keyword looks like @code{sizeof}, but the | |
641 | construct acts semantically like a type name defined with @code{typedef}. | |
642 | ||
643 | There are two ways of writing the argument to @code{typeof}: with an | |
644 | expression or with a type. Here is an example with an expression: | |
645 | ||
a0ecd6b1 | 646 | @smallexample |
146ef39f | 647 | typeof (x[0](1)) |
a0ecd6b1 | 648 | @end smallexample |
146ef39f | 649 | |
650 | @noindent | |
f934d81d | 651 | This assumes that @code{x} is an array of pointers to functions; |
652 | the type described is that of the values of the functions. | |
146ef39f | 653 | |
654 | Here is an example with a typename as the argument: | |
655 | ||
a0ecd6b1 | 656 | @smallexample |
146ef39f | 657 | typeof (int *) |
a0ecd6b1 | 658 | @end smallexample |
146ef39f | 659 | |
660 | @noindent | |
661 | Here the type described is that of pointers to @code{int}. | |
662 | ||
78b1f616 | 663 | If you are writing a header file that must work when included in ISO C |
146ef39f | 664 | programs, write @code{__typeof__} instead of @code{typeof}. |
665 | @xref{Alternate Keywords}. | |
666 | ||
667 | A @code{typeof}-construct can be used anywhere a typedef name could be | |
668 | used. For example, you can use it in a declaration, in a cast, or inside | |
669 | of @code{sizeof} or @code{typeof}. | |
670 | ||
a75b1c71 | 671 | The operand of @code{typeof} is evaluated for its side effects if and |
672 | only if it is an expression of variably modified type or the name of | |
673 | such a type. | |
674 | ||
f6f89f14 | 675 | @code{typeof} is often useful in conjunction with the |
676 | statements-within-expressions feature. Here is how the two together can | |
677 | be used to define a safe ``maximum'' macro that operates on any | |
678 | arithmetic type and evaluates each of its arguments exactly once: | |
679 | ||
a0ecd6b1 | 680 | @smallexample |
f6f89f14 | 681 | #define max(a,b) \ |
682 | (@{ typeof (a) _a = (a); \ | |
683 | typeof (b) _b = (b); \ | |
684 | _a > _b ? _a : _b; @}) | |
a0ecd6b1 | 685 | @end smallexample |
f6f89f14 | 686 | |
2e411f1f | 687 | @cindex underscores in variables in macros |
688 | @cindex @samp{_} in variables in macros | |
689 | @cindex local variables in macros | |
690 | @cindex variables, local, in macros | |
691 | @cindex macros, local variables in | |
692 | ||
693 | The reason for using names that start with underscores for the local | |
694 | variables is to avoid conflicts with variable names that occur within the | |
695 | expressions that are substituted for @code{a} and @code{b}. Eventually we | |
696 | hope to design a new form of declaration syntax that allows you to declare | |
697 | variables whose scopes start only after their initializers; this will be a | |
698 | more reliable way to prevent such conflicts. | |
699 | ||
f6f89f14 | 700 | @noindent |
701 | Some more examples of the use of @code{typeof}: | |
702 | ||
146ef39f | 703 | @itemize @bullet |
704 | @item | |
705 | This declares @code{y} with the type of what @code{x} points to. | |
706 | ||
a0ecd6b1 | 707 | @smallexample |
146ef39f | 708 | typeof (*x) y; |
a0ecd6b1 | 709 | @end smallexample |
146ef39f | 710 | |
711 | @item | |
712 | This declares @code{y} as an array of such values. | |
713 | ||
a0ecd6b1 | 714 | @smallexample |
146ef39f | 715 | typeof (*x) y[4]; |
a0ecd6b1 | 716 | @end smallexample |
146ef39f | 717 | |
718 | @item | |
719 | This declares @code{y} as an array of pointers to characters: | |
720 | ||
a0ecd6b1 | 721 | @smallexample |
146ef39f | 722 | typeof (typeof (char *)[4]) y; |
a0ecd6b1 | 723 | @end smallexample |
146ef39f | 724 | |
725 | @noindent | |
726 | It is equivalent to the following traditional C declaration: | |
727 | ||
a0ecd6b1 | 728 | @smallexample |
146ef39f | 729 | char *y[4]; |
a0ecd6b1 | 730 | @end smallexample |
146ef39f | 731 | |
732 | To see the meaning of the declaration using @code{typeof}, and why it | |
153e79bc | 733 | might be a useful way to write, rewrite it with these macros: |
146ef39f | 734 | |
a0ecd6b1 | 735 | @smallexample |
146ef39f | 736 | #define pointer(T) typeof(T *) |
737 | #define array(T, N) typeof(T [N]) | |
a0ecd6b1 | 738 | @end smallexample |
146ef39f | 739 | |
740 | @noindent | |
741 | Now the declaration can be rewritten this way: | |
742 | ||
a0ecd6b1 | 743 | @smallexample |
146ef39f | 744 | array (pointer (char), 4) y; |
a0ecd6b1 | 745 | @end smallexample |
146ef39f | 746 | |
747 | @noindent | |
748 | Thus, @code{array (pointer (char), 4)} is the type of arrays of 4 | |
749 | pointers to @code{char}. | |
750 | @end itemize | |
751 | ||
f6f89f14 | 752 | @emph{Compatibility Note:} In addition to @code{typeof}, GCC 2 supported |
753 | a more limited extension which permitted one to write | |
754 | ||
a0ecd6b1 | 755 | @smallexample |
f6f89f14 | 756 | typedef @var{T} = @var{expr}; |
a0ecd6b1 | 757 | @end smallexample |
f6f89f14 | 758 | |
759 | @noindent | |
760 | with the effect of declaring @var{T} to have the type of the expression | |
761 | @var{expr}. This extension does not work with GCC 3 (versions between | |
762 | 3.0 and 3.2 will crash; 3.2.1 and later give an error). Code which | |
763 | relies on it should be rewritten to use @code{typeof}: | |
764 | ||
a0ecd6b1 | 765 | @smallexample |
f6f89f14 | 766 | typedef typeof(@var{expr}) @var{T}; |
a0ecd6b1 | 767 | @end smallexample |
f6f89f14 | 768 | |
769 | @noindent | |
770 | This will work with all versions of GCC@. | |
771 | ||
146ef39f | 772 | @node Conditionals |
773 | @section Conditionals with Omitted Operands | |
774 | @cindex conditional expressions, extensions | |
775 | @cindex omitted middle-operands | |
776 | @cindex middle-operands, omitted | |
777 | @cindex extensions, @code{?:} | |
778 | @cindex @code{?:} extensions | |
779 | ||
780 | The middle operand in a conditional expression may be omitted. Then | |
781 | if the first operand is nonzero, its value is the value of the conditional | |
782 | expression. | |
783 | ||
784 | Therefore, the expression | |
785 | ||
a0ecd6b1 | 786 | @smallexample |
146ef39f | 787 | x ? : y |
a0ecd6b1 | 788 | @end smallexample |
146ef39f | 789 | |
790 | @noindent | |
791 | has the value of @code{x} if that is nonzero; otherwise, the value of | |
792 | @code{y}. | |
793 | ||
794 | This example is perfectly equivalent to | |
795 | ||
a0ecd6b1 | 796 | @smallexample |
146ef39f | 797 | x ? x : y |
a0ecd6b1 | 798 | @end smallexample |
146ef39f | 799 | |
12786727 | 800 | @cindex side effect in @code{?:} |
801 | @cindex @code{?:} side effect | |
146ef39f | 802 | @noindent |
803 | In this simple case, the ability to omit the middle operand is not | |
804 | especially useful. When it becomes useful is when the first operand does, | |
805 | or may (if it is a macro argument), contain a side effect. Then repeating | |
806 | the operand in the middle would perform the side effect twice. Omitting | |
807 | the middle operand uses the value already computed without the undesirable | |
808 | effects of recomputing it. | |
809 | ||
6388cfe2 | 810 | @node __int128 |
811 | @section 128-bits integers | |
812 | @cindex @code{__int128} data types | |
813 | ||
814 | As an extension the integer scalar type @code{__int128} is supported for | |
815 | targets having an integer mode wide enough to hold 128-bit. | |
816 | Simply write @code{__int128} for a signed 128-bit integer, or | |
817 | @code{unsigned __int128} for an unsigned 128-bit integer. There is no | |
818 | support in GCC to express an integer constant of type @code{__int128} | |
819 | for targets having @code{long long} integer with less then 128 bit width. | |
820 | ||
146ef39f | 821 | @node Long Long |
822 | @section Double-Word Integers | |
823 | @cindex @code{long long} data types | |
824 | @cindex double-word arithmetic | |
825 | @cindex multiprecision arithmetic | |
3cfa0cc4 | 826 | @cindex @code{LL} integer suffix |
827 | @cindex @code{ULL} integer suffix | |
146ef39f | 828 | |
3cfa0cc4 | 829 | ISO C99 supports data types for integers that are at least 64 bits wide, |
32f1f35b | 830 | and as an extension GCC supports them in C90 mode and in C++. |
3cfa0cc4 | 831 | Simply write @code{long long int} for a signed integer, or |
146ef39f | 832 | @code{unsigned long long int} for an unsigned integer. To make an |
67791935 | 833 | integer constant of type @code{long long int}, add the suffix @samp{LL} |
146ef39f | 834 | to the integer. To make an integer constant of type @code{unsigned long |
67791935 | 835 | long int}, add the suffix @samp{ULL} to the integer. |
146ef39f | 836 | |
837 | You can use these types in arithmetic like any other integer types. | |
838 | Addition, subtraction, and bitwise boolean operations on these types | |
839 | are open-coded on all types of machines. Multiplication is open-coded | |
840 | if the machine supports fullword-to-doubleword a widening multiply | |
841 | instruction. Division and shifts are open-coded only on machines that | |
842 | provide special support. The operations that are not open-coded use | |
0858e3a2 | 843 | special library routines that come with GCC@. |
146ef39f | 844 | |
845 | There may be pitfalls when you use @code{long long} types for function | |
846 | arguments, unless you declare function prototypes. If a function | |
847 | expects type @code{int} for its argument, and you pass a value of type | |
848 | @code{long long int}, confusion will result because the caller and the | |
849 | subroutine will disagree about the number of bytes for the argument. | |
850 | Likewise, if the function expects @code{long long int} and you pass | |
851 | @code{int}. The best way to avoid such problems is to use prototypes. | |
852 | ||
853 | @node Complex | |
854 | @section Complex Numbers | |
855 | @cindex complex numbers | |
3cfa0cc4 | 856 | @cindex @code{_Complex} keyword |
857 | @cindex @code{__complex__} keyword | |
146ef39f | 858 | |
3cfa0cc4 | 859 | ISO C99 supports complex floating data types, and as an extension GCC |
32f1f35b | 860 | supports them in C90 mode and in C++, and supports complex integer data |
3cfa0cc4 | 861 | types which are not part of ISO C99. You can declare complex types |
862 | using the keyword @code{_Complex}. As an extension, the older GNU | |
863 | keyword @code{__complex__} is also supported. | |
146ef39f | 864 | |
3cfa0cc4 | 865 | For example, @samp{_Complex double x;} declares @code{x} as a |
146ef39f | 866 | variable whose real part and imaginary part are both of type |
3cfa0cc4 | 867 | @code{double}. @samp{_Complex short int y;} declares @code{y} to |
146ef39f | 868 | have real and imaginary parts of type @code{short int}; this is not |
869 | likely to be useful, but it shows that the set of complex types is | |
870 | complete. | |
871 | ||
872 | To write a constant with a complex data type, use the suffix @samp{i} or | |
873 | @samp{j} (either one; they are equivalent). For example, @code{2.5fi} | |
3cfa0cc4 | 874 | has type @code{_Complex float} and @code{3i} has type |
875 | @code{_Complex int}. Such a constant always has a pure imaginary | |
146ef39f | 876 | value, but you can form any complex value you like by adding one to a |
3cfa0cc4 | 877 | real constant. This is a GNU extension; if you have an ISO C99 |
878 | conforming C library (such as GNU libc), and want to construct complex | |
879 | constants of floating type, you should include @code{<complex.h>} and | |
880 | use the macros @code{I} or @code{_Complex_I} instead. | |
146ef39f | 881 | |
3cfa0cc4 | 882 | @cindex @code{__real__} keyword |
883 | @cindex @code{__imag__} keyword | |
146ef39f | 884 | To extract the real part of a complex-valued expression @var{exp}, write |
885 | @code{__real__ @var{exp}}. Likewise, use @code{__imag__} to | |
3cfa0cc4 | 886 | extract the imaginary part. This is a GNU extension; for values of |
887 | floating type, you should use the ISO C99 functions @code{crealf}, | |
888 | @code{creal}, @code{creall}, @code{cimagf}, @code{cimag} and | |
889 | @code{cimagl}, declared in @code{<complex.h>} and also provided as | |
0858e3a2 | 890 | built-in functions by GCC@. |
146ef39f | 891 | |
3cfa0cc4 | 892 | @cindex complex conjugation |
146ef39f | 893 | The operator @samp{~} performs complex conjugation when used on a value |
3cfa0cc4 | 894 | with a complex type. This is a GNU extension; for values of |
895 | floating type, you should use the ISO C99 functions @code{conjf}, | |
896 | @code{conj} and @code{conjl}, declared in @code{<complex.h>} and also | |
0858e3a2 | 897 | provided as built-in functions by GCC@. |
146ef39f | 898 | |
37744367 | 899 | GCC can allocate complex automatic variables in a noncontiguous |
146ef39f | 900 | fashion; it's even possible for the real part to be in a register while |
1a050f4e | 901 | the imaginary part is on the stack (or vice-versa). Only the DWARF2 |
902 | debug info format can represent this, so use of DWARF2 is recommended. | |
903 | If you are using the stabs debug info format, GCC describes a noncontiguous | |
904 | complex variable as if it were two separate variables of noncomplex type. | |
146ef39f | 905 | If the variable's actual name is @code{foo}, the two fictitious |
906 | variables are named @code{foo$real} and @code{foo$imag}. You can | |
907 | examine and set these two fictitious variables with your debugger. | |
908 | ||
430be8e2 | 909 | @node Floating Types |
910 | @section Additional Floating Types | |
911 | @cindex additional floating types | |
912 | @cindex @code{__float80} data type | |
913 | @cindex @code{__float128} data type | |
914 | @cindex @code{w} floating point suffix | |
915 | @cindex @code{q} floating point suffix | |
916 | @cindex @code{W} floating point suffix | |
917 | @cindex @code{Q} floating point suffix | |
918 | ||
919 | As an extension, the GNU C compiler supports additional floating | |
920 | types, @code{__float80} and @code{__float128} to support 80bit | |
921 | (@code{XFmode}) and 128 bit (@code{TFmode}) floating types. | |
922 | Support for additional types includes the arithmetic operators: | |
923 | add, subtract, multiply, divide; unary arithmetic operators; | |
924 | relational operators; equality operators; and conversions to and from | |
925 | integer and other floating types. Use a suffix @samp{w} or @samp{W} | |
926 | in a literal constant of type @code{__float80} and @samp{q} or @samp{Q} | |
927 | for @code{_float128}. You can declare complex types using the | |
928 | corresponding internal complex type, @code{XCmode} for @code{__float80} | |
929 | type and @code{TCmode} for @code{__float128} type: | |
930 | ||
931 | @smallexample | |
932 | typedef _Complex float __attribute__((mode(TC))) _Complex128; | |
933 | typedef _Complex float __attribute__((mode(XC))) _Complex80; | |
934 | @end smallexample | |
935 | ||
936 | Not all targets support additional floating point types. @code{__float80} | |
70a23968 | 937 | and @code{__float128} types are supported on i386, x86_64 and ia64 targets. |
0f9c87cc | 938 | The @code{__float128} type is supported on hppa HP-UX targets. |
430be8e2 | 939 | |
9b8516be | 940 | @node Half-Precision |
941 | @section Half-Precision Floating Point | |
942 | @cindex half-precision floating point | |
943 | @cindex @code{__fp16} data type | |
944 | ||
945 | On ARM targets, GCC supports half-precision (16-bit) floating point via | |
15b474a2 | 946 | the @code{__fp16} type. You must enable this type explicitly |
9b8516be | 947 | with the @option{-mfp16-format} command-line option in order to use it. |
948 | ||
949 | ARM supports two incompatible representations for half-precision | |
950 | floating-point values. You must choose one of the representations and | |
951 | use it consistently in your program. | |
952 | ||
953 | Specifying @option{-mfp16-format=ieee} selects the IEEE 754-2008 format. | |
954 | This format can represent normalized values in the range of @math{2^{-14}} to 65504. | |
955 | There are 11 bits of significand precision, approximately 3 | |
956 | decimal digits. | |
957 | ||
958 | Specifying @option{-mfp16-format=alternative} selects the ARM | |
959 | alternative format. This representation is similar to the IEEE | |
960 | format, but does not support infinities or NaNs. Instead, the range | |
961 | of exponents is extended, so that this format can represent normalized | |
962 | values in the range of @math{2^{-14}} to 131008. | |
963 | ||
964 | The @code{__fp16} type is a storage format only. For purposes | |
965 | of arithmetic and other operations, @code{__fp16} values in C or C++ | |
966 | expressions are automatically promoted to @code{float}. In addition, | |
15b474a2 | 967 | you cannot declare a function with a return value or parameters |
9b8516be | 968 | of type @code{__fp16}. |
969 | ||
970 | Note that conversions from @code{double} to @code{__fp16} | |
971 | involve an intermediate conversion to @code{float}. Because | |
972 | of rounding, this can sometimes produce a different result than a | |
973 | direct conversion. | |
974 | ||
15b474a2 | 975 | ARM provides hardware support for conversions between |
9b8516be | 976 | @code{__fp16} and @code{float} values |
977 | as an extension to VFP and NEON (Advanced SIMD). GCC generates | |
a50d7267 | 978 | code using these hardware instructions if you compile with |
15b474a2 | 979 | options to select an FPU that provides them; |
a50d7267 | 980 | for example, @option{-mfpu=neon-fp16 -mfloat-abi=softfp}, |
9b8516be | 981 | in addition to the @option{-mfp16-format} option to select |
15b474a2 | 982 | a half-precision format. |
9b8516be | 983 | |
984 | Language-level support for the @code{__fp16} data type is | |
985 | independent of whether GCC generates code using hardware floating-point | |
986 | instructions. In cases where hardware support is not specified, GCC | |
987 | implements conversions between @code{__fp16} and @code{float} values | |
988 | as library calls. | |
989 | ||
c4503c0a | 990 | @node Decimal Float |
cded8ad2 | 991 | @section Decimal Floating Types |
992 | @cindex decimal floating types | |
c4503c0a | 993 | @cindex @code{_Decimal32} data type |
994 | @cindex @code{_Decimal64} data type | |
995 | @cindex @code{_Decimal128} data type | |
996 | @cindex @code{df} integer suffix | |
997 | @cindex @code{dd} integer suffix | |
998 | @cindex @code{dl} integer suffix | |
999 | @cindex @code{DF} integer suffix | |
1000 | @cindex @code{DD} integer suffix | |
1001 | @cindex @code{DL} integer suffix | |
1002 | ||
cded8ad2 | 1003 | As an extension, the GNU C compiler supports decimal floating types as |
0e86dff0 | 1004 | defined in the N1312 draft of ISO/IEC WDTR24732. Support for decimal |
cded8ad2 | 1005 | floating types in GCC will evolve as the draft technical report changes. |
1006 | Calling conventions for any target might also change. Not all targets | |
1007 | support decimal floating types. | |
c4503c0a | 1008 | |
cded8ad2 | 1009 | The decimal floating types are @code{_Decimal32}, @code{_Decimal64}, and |
1010 | @code{_Decimal128}. They use a radix of ten, unlike the floating types | |
1011 | @code{float}, @code{double}, and @code{long double} whose radix is not | |
1012 | specified by the C standard but is usually two. | |
1013 | ||
1014 | Support for decimal floating types includes the arithmetic operators | |
c4503c0a | 1015 | add, subtract, multiply, divide; unary arithmetic operators; |
1016 | relational operators; equality operators; and conversions to and from | |
cded8ad2 | 1017 | integer and other floating types. Use a suffix @samp{df} or |
c4503c0a | 1018 | @samp{DF} in a literal constant of type @code{_Decimal32}, @samp{dd} |
1019 | or @samp{DD} for @code{_Decimal64}, and @samp{dl} or @samp{DL} for | |
1020 | @code{_Decimal128}. | |
1021 | ||
cded8ad2 | 1022 | GCC support of decimal float as specified by the draft technical report |
1023 | is incomplete: | |
1024 | ||
1025 | @itemize @bullet | |
cded8ad2 | 1026 | @item |
1027 | When the value of a decimal floating type cannot be represented in the | |
1028 | integer type to which it is being converted, the result is undefined | |
1029 | rather than the result value specified by the draft technical report. | |
0e86dff0 | 1030 | |
1031 | @item | |
1032 | GCC does not provide the C library functionality associated with | |
1033 | @file{math.h}, @file{fenv.h}, @file{stdio.h}, @file{stdlib.h}, and | |
1034 | @file{wchar.h}, which must come from a separate C library implementation. | |
1035 | Because of this the GNU C compiler does not define macro | |
1036 | @code{__STDC_DEC_FP__} to indicate that the implementation conforms to | |
1037 | the technical report. | |
cded8ad2 | 1038 | @end itemize |
c4503c0a | 1039 | |
1040 | Types @code{_Decimal32}, @code{_Decimal64}, and @code{_Decimal128} | |
1041 | are supported by the DWARF2 debug information format. | |
1042 | ||
75bd5ada | 1043 | @node Hex Floats |
caee732e | 1044 | @section Hex Floats |
1045 | @cindex hex floats | |
7014838c | 1046 | |
3cfa0cc4 | 1047 | ISO C99 supports floating-point numbers written not only in the usual |
75bd5ada | 1048 | decimal notation, such as @code{1.55e1}, but also numbers such as |
3cfa0cc4 | 1049 | @code{0x1.fp3} written in hexadecimal format. As a GNU extension, GCC |
32f1f35b | 1050 | supports this in C90 mode (except in some cases when strictly |
3cfa0cc4 | 1051 | conforming) and in C++. In that format the |
67791935 | 1052 | @samp{0x} hex introducer and the @samp{p} or @samp{P} exponent field are |
75bd5ada | 1053 | mandatory. The exponent is a decimal number that indicates the power of |
67791935 | 1054 | 2 by which the significant part will be multiplied. Thus @samp{0x1.f} is |
70c2c81c | 1055 | @tex |
1056 | $1 {15\over16}$, | |
1057 | @end tex | |
1058 | @ifnottex | |
1059 | 1 15/16, | |
1060 | @end ifnottex | |
1061 | @samp{p3} multiplies it by 8, and the value of @code{0x1.fp3} | |
75bd5ada | 1062 | is the same as @code{1.55e1}. |
1063 | ||
1064 | Unlike for floating-point numbers in the decimal notation the exponent | |
1065 | is always required in the hexadecimal notation. Otherwise the compiler | |
1066 | would not be able to resolve the ambiguity of, e.g., @code{0x1.f}. This | |
67791935 | 1067 | could mean @code{1.0f} or @code{1.9375} since @samp{f} is also the |
75bd5ada | 1068 | extension for floating-point constants of type @code{float}. |
1069 | ||
68a556d6 | 1070 | @node Fixed-Point |
1071 | @section Fixed-Point Types | |
1072 | @cindex fixed-point types | |
1073 | @cindex @code{_Fract} data type | |
1074 | @cindex @code{_Accum} data type | |
1075 | @cindex @code{_Sat} data type | |
1076 | @cindex @code{hr} fixed-suffix | |
1077 | @cindex @code{r} fixed-suffix | |
1078 | @cindex @code{lr} fixed-suffix | |
1079 | @cindex @code{llr} fixed-suffix | |
1080 | @cindex @code{uhr} fixed-suffix | |
1081 | @cindex @code{ur} fixed-suffix | |
1082 | @cindex @code{ulr} fixed-suffix | |
1083 | @cindex @code{ullr} fixed-suffix | |
1084 | @cindex @code{hk} fixed-suffix | |
1085 | @cindex @code{k} fixed-suffix | |
1086 | @cindex @code{lk} fixed-suffix | |
1087 | @cindex @code{llk} fixed-suffix | |
1088 | @cindex @code{uhk} fixed-suffix | |
1089 | @cindex @code{uk} fixed-suffix | |
1090 | @cindex @code{ulk} fixed-suffix | |
1091 | @cindex @code{ullk} fixed-suffix | |
1092 | @cindex @code{HR} fixed-suffix | |
1093 | @cindex @code{R} fixed-suffix | |
1094 | @cindex @code{LR} fixed-suffix | |
1095 | @cindex @code{LLR} fixed-suffix | |
1096 | @cindex @code{UHR} fixed-suffix | |
1097 | @cindex @code{UR} fixed-suffix | |
1098 | @cindex @code{ULR} fixed-suffix | |
1099 | @cindex @code{ULLR} fixed-suffix | |
1100 | @cindex @code{HK} fixed-suffix | |
1101 | @cindex @code{K} fixed-suffix | |
1102 | @cindex @code{LK} fixed-suffix | |
1103 | @cindex @code{LLK} fixed-suffix | |
1104 | @cindex @code{UHK} fixed-suffix | |
1105 | @cindex @code{UK} fixed-suffix | |
1106 | @cindex @code{ULK} fixed-suffix | |
1107 | @cindex @code{ULLK} fixed-suffix | |
1108 | ||
1109 | As an extension, the GNU C compiler supports fixed-point types as | |
1110 | defined in the N1169 draft of ISO/IEC DTR 18037. Support for fixed-point | |
1111 | types in GCC will evolve as the draft technical report changes. | |
1112 | Calling conventions for any target might also change. Not all targets | |
1113 | support fixed-point types. | |
1114 | ||
1115 | The fixed-point types are | |
1116 | @code{short _Fract}, | |
1117 | @code{_Fract}, | |
1118 | @code{long _Fract}, | |
1119 | @code{long long _Fract}, | |
1120 | @code{unsigned short _Fract}, | |
1121 | @code{unsigned _Fract}, | |
1122 | @code{unsigned long _Fract}, | |
1123 | @code{unsigned long long _Fract}, | |
1124 | @code{_Sat short _Fract}, | |
1125 | @code{_Sat _Fract}, | |
1126 | @code{_Sat long _Fract}, | |
1127 | @code{_Sat long long _Fract}, | |
1128 | @code{_Sat unsigned short _Fract}, | |
1129 | @code{_Sat unsigned _Fract}, | |
1130 | @code{_Sat unsigned long _Fract}, | |
1131 | @code{_Sat unsigned long long _Fract}, | |
1132 | @code{short _Accum}, | |
1133 | @code{_Accum}, | |
1134 | @code{long _Accum}, | |
1135 | @code{long long _Accum}, | |
1136 | @code{unsigned short _Accum}, | |
1137 | @code{unsigned _Accum}, | |
1138 | @code{unsigned long _Accum}, | |
1139 | @code{unsigned long long _Accum}, | |
1140 | @code{_Sat short _Accum}, | |
1141 | @code{_Sat _Accum}, | |
1142 | @code{_Sat long _Accum}, | |
1143 | @code{_Sat long long _Accum}, | |
1144 | @code{_Sat unsigned short _Accum}, | |
1145 | @code{_Sat unsigned _Accum}, | |
1146 | @code{_Sat unsigned long _Accum}, | |
1147 | @code{_Sat unsigned long long _Accum}. | |
560db68e | 1148 | |
68a556d6 | 1149 | Fixed-point data values contain fractional and optional integral parts. |
1150 | The format of fixed-point data varies and depends on the target machine. | |
1151 | ||
560db68e | 1152 | Support for fixed-point types includes: |
1153 | @itemize @bullet | |
1154 | @item | |
1155 | prefix and postfix increment and decrement operators (@code{++}, @code{--}) | |
1156 | @item | |
1157 | unary arithmetic operators (@code{+}, @code{-}, @code{!}) | |
1158 | @item | |
1159 | binary arithmetic operators (@code{+}, @code{-}, @code{*}, @code{/}) | |
1160 | @item | |
1161 | binary shift operators (@code{<<}, @code{>>}) | |
1162 | @item | |
1163 | relational operators (@code{<}, @code{<=}, @code{>=}, @code{>}) | |
1164 | @item | |
1165 | equality operators (@code{==}, @code{!=}) | |
1166 | @item | |
1167 | assignment operators (@code{+=}, @code{-=}, @code{*=}, @code{/=}, | |
1168 | @code{<<=}, @code{>>=}) | |
1169 | @item | |
1170 | conversions to and from integer, floating-point, or fixed-point types | |
1171 | @end itemize | |
1172 | ||
1173 | Use a suffix in a fixed-point literal constant: | |
1174 | @itemize | |
1175 | @item @samp{hr} or @samp{HR} for @code{short _Fract} and | |
1176 | @code{_Sat short _Fract} | |
1177 | @item @samp{r} or @samp{R} for @code{_Fract} and @code{_Sat _Fract} | |
1178 | @item @samp{lr} or @samp{LR} for @code{long _Fract} and | |
1179 | @code{_Sat long _Fract} | |
1180 | @item @samp{llr} or @samp{LLR} for @code{long long _Fract} and | |
1181 | @code{_Sat long long _Fract} | |
1182 | @item @samp{uhr} or @samp{UHR} for @code{unsigned short _Fract} and | |
1183 | @code{_Sat unsigned short _Fract} | |
1184 | @item @samp{ur} or @samp{UR} for @code{unsigned _Fract} and | |
1185 | @code{_Sat unsigned _Fract} | |
1186 | @item @samp{ulr} or @samp{ULR} for @code{unsigned long _Fract} and | |
1187 | @code{_Sat unsigned long _Fract} | |
1188 | @item @samp{ullr} or @samp{ULLR} for @code{unsigned long long _Fract} | |
1189 | and @code{_Sat unsigned long long _Fract} | |
1190 | @item @samp{hk} or @samp{HK} for @code{short _Accum} and | |
1191 | @code{_Sat short _Accum} | |
1192 | @item @samp{k} or @samp{K} for @code{_Accum} and @code{_Sat _Accum} | |
1193 | @item @samp{lk} or @samp{LK} for @code{long _Accum} and | |
1194 | @code{_Sat long _Accum} | |
1195 | @item @samp{llk} or @samp{LLK} for @code{long long _Accum} and | |
1196 | @code{_Sat long long _Accum} | |
1197 | @item @samp{uhk} or @samp{UHK} for @code{unsigned short _Accum} and | |
1198 | @code{_Sat unsigned short _Accum} | |
1199 | @item @samp{uk} or @samp{UK} for @code{unsigned _Accum} and | |
1200 | @code{_Sat unsigned _Accum} | |
1201 | @item @samp{ulk} or @samp{ULK} for @code{unsigned long _Accum} and | |
1202 | @code{_Sat unsigned long _Accum} | |
1203 | @item @samp{ullk} or @samp{ULLK} for @code{unsigned long long _Accum} | |
1204 | and @code{_Sat unsigned long long _Accum} | |
1205 | @end itemize | |
68a556d6 | 1206 | |
1207 | GCC support of fixed-point types as specified by the draft technical report | |
1208 | is incomplete: | |
1209 | ||
1210 | @itemize @bullet | |
1211 | @item | |
1212 | Pragmas to control overflow and rounding behaviors are not implemented. | |
1213 | @end itemize | |
1214 | ||
1215 | Fixed-point types are supported by the DWARF2 debug information format. | |
1216 | ||
bd1a81f7 | 1217 | @node Named Address Spaces |
8516b1c4 | 1218 | @section Named Address Spaces |
1219 | @cindex Named Address Spaces | |
bd1a81f7 | 1220 | |
1221 | As an extension, the GNU C compiler supports named address spaces as | |
1222 | defined in the N1275 draft of ISO/IEC DTR 18037. Support for named | |
78e515f7 | 1223 | address spaces in GCC will evolve as the draft technical report |
1224 | changes. Calling conventions for any target might also change. At | |
8516b1c4 | 1225 | present, only the AVR, SPU, M32C, and RL78 targets support address |
1226 | spaces other than the generic address space. | |
1227 | ||
1228 | Address space identifiers may be used exactly like any other C type | |
1229 | qualifier (e.g., @code{const} or @code{volatile}). See the N1275 | |
1230 | document for more details. | |
1231 | ||
1232 | @anchor{AVR Named Address Spaces} | |
1233 | @subsection AVR Named Address Spaces | |
1234 | ||
1235 | On the AVR target, there are several address spaces that can be used | |
1236 | in order to put read-only data into the flash memory and access that | |
1237 | data by means of the special instructions @code{LPM} or @code{ELPM} | |
1238 | needed to read from flash. | |
1239 | ||
6ee532ba | 1240 | Per default, any data including read-only data is located in RAM |
1241 | (the generic address space) so that non-generic address spaces are | |
1242 | needed to locate read-only data in flash memory | |
1243 | @emph{and} to generate the right instructions to access this data | |
8516b1c4 | 1244 | without using (inline) assembler code. |
1245 | ||
1246 | @table @code | |
590da9f2 | 1247 | @item __flash |
1248 | @cindex @code{__flash} AVR Named Address Spaces | |
1249 | The @code{__flash} qualifier will locate data in the | |
8516b1c4 | 1250 | @code{.progmem.data} section. Data will be read using the @code{LPM} |
1251 | instruction. Pointers to this address space are 16 bits wide. | |
1252 | ||
590da9f2 | 1253 | @item __flash1 |
1254 | @item __flash2 | |
1255 | @item __flash3 | |
1256 | @item __flash4 | |
1257 | @item __flash5 | |
1258 | @cindex @code{__flash1} AVR Named Address Spaces | |
1259 | @cindex @code{__flash2} AVR Named Address Spaces | |
1260 | @cindex @code{__flash3} AVR Named Address Spaces | |
1261 | @cindex @code{__flash4} AVR Named Address Spaces | |
1262 | @cindex @code{__flash5} AVR Named Address Spaces | |
8516b1c4 | 1263 | These are 16-bit address spaces locating data in section |
1264 | @code{.progmem@var{N}.data} where @var{N} refers to | |
590da9f2 | 1265 | address space @code{__flash@var{N}}. |
8516b1c4 | 1266 | The compiler will set the @code{RAMPZ} segment register approptiately |
1267 | before reading data by means of the @code{ELPM} instruction. | |
1268 | ||
590da9f2 | 1269 | @item __memx |
1270 | @cindex @code{__memx} AVR Named Address Spaces | |
8516b1c4 | 1271 | This is a 24-bit address space that linearizes flash and RAM: |
1272 | If the high bit of the address is set, data is read from | |
1273 | RAM using the lower two bytes as RAM address. | |
1274 | If the high bit of the address is clear, data is read from flash | |
1275 | with @code{RAMPZ} set according to the high byte of the address. | |
5a9cc803 | 1276 | @xref{AVR Built-in Functions,,@code{__builtin_avr_flash_segment}}. |
8516b1c4 | 1277 | |
1278 | Objects in this address space will be located in @code{.progmem.data}. | |
1279 | @end table | |
1280 | ||
6ee532ba | 1281 | @b{Example} |
1282 | ||
1283 | @example | |
590da9f2 | 1284 | char my_read (const __flash char ** p) |
6ee532ba | 1285 | @{ |
1286 | /* p is a pointer to RAM that points to a pointer to flash. | |
1287 | The first indirection of p will read that flash pointer | |
1288 | from RAM and the second indirection reads a char from this | |
1289 | flash address. */ | |
1290 | ||
1291 | return **p; | |
1292 | @} | |
1293 | ||
1294 | /* Locate array[] in flash memory */ | |
590da9f2 | 1295 | const __flash int array[] = @{ 3, 5, 7, 11, 13, 17, 19 @}; |
6ee532ba | 1296 | |
1297 | int i = 1; | |
1298 | ||
1299 | int main (void) | |
1300 | @{ | |
1301 | /* Return 17 by reading from flash memory */ | |
1302 | return array[array[i]]; | |
1303 | @} | |
1304 | @end example | |
1305 | ||
5a9cc803 | 1306 | @noindent |
8516b1c4 | 1307 | For each named address space supported by avr-gcc there is an equally |
1308 | named but uppercase built-in macro defined. | |
1309 | The purpose is to facilitate testing if respective address space | |
1310 | support is available or not: | |
1311 | ||
1312 | @example | |
590da9f2 | 1313 | #ifdef __FLASH |
1314 | const __flash int var = 1; | |
8516b1c4 | 1315 | |
6222cbcc | 1316 | int read_var (void) |
8516b1c4 | 1317 | @{ |
6222cbcc | 1318 | return var; |
8516b1c4 | 1319 | @} |
1320 | #else | |
6222cbcc | 1321 | #include <avr/pgmspace.h> /* From AVR-LibC */ |
8516b1c4 | 1322 | |
1323 | const int var PROGMEM = 1; | |
1324 | ||
6222cbcc | 1325 | int read_var (void) |
8516b1c4 | 1326 | @{ |
6222cbcc | 1327 | return (int) pgm_read_word (&var); |
8516b1c4 | 1328 | @} |
590da9f2 | 1329 | #endif /* __FLASH */ |
8516b1c4 | 1330 | @end example |
1331 | ||
5a9cc803 | 1332 | @noindent |
1333 | Notice that attribute @ref{AVR Variable Attributes,,@code{progmem}} | |
8516b1c4 | 1334 | locates data in flash but |
6ee532ba | 1335 | accesses to these data will read from generic address space, i.e.@: |
1336 | from RAM, | |
1337 | so that you need special accessors like @code{pgm_read_byte} | |
6222cbcc | 1338 | from @w{@uref{http://nongnu.org/avr-libc/user-manual,AVR-LibC}} |
1339 | together with attribute @code{progmem}. | |
8516b1c4 | 1340 | |
5a9cc803 | 1341 | @noindent |
8516b1c4 | 1342 | @b{Limitations and caveats} |
1343 | ||
1344 | @itemize | |
1345 | @item | |
1346 | Reading across the 64@tie{}KiB section boundary of | |
590da9f2 | 1347 | the @code{__flash} or @code{__flash@var{N}} address spaces |
8516b1c4 | 1348 | will show undefined behaviour. The only address space that |
1349 | supports reading across the 64@tie{}KiB flash segment boundaries is | |
590da9f2 | 1350 | @code{__memx}. |
8516b1c4 | 1351 | |
1352 | @item | |
6222cbcc | 1353 | If you use one of the @code{__flash@var{N}} address spaces |
8516b1c4 | 1354 | you will have to arrange your linker skript to locate the |
1355 | @code{.progmem@var{N}.data} sections according to your needs. | |
1356 | ||
1357 | @item | |
6ee532ba | 1358 | Any data or pointers to the non-generic address spaces must |
1359 | be qualified as @code{const}, i.e.@: as read-only data. | |
8516b1c4 | 1360 | This still applies if the data in one of these address |
6ee532ba | 1361 | spaces like software version number or calibration lookup table are intended to |
8516b1c4 | 1362 | be changed after load time by, say, a boot loader. In this case |
1363 | the right qualification is @code{const} @code{volatile} so that the compiler | |
1364 | must not optimize away known values or insert them | |
1365 | as immediates into operands of instructions. | |
1366 | ||
1367 | @item | |
5a9cc803 | 1368 | The following code initializes a variable @code{pfoo} |
1369 | located in static storage with a 24-bit address: | |
8516b1c4 | 1370 | @example |
590da9f2 | 1371 | extern const __memx char foo; |
1372 | const __memx void *pfoo = &foo; | |
8516b1c4 | 1373 | @end example |
5a9cc803 | 1374 | Such code requires at least binutils 2.23, see |
1375 | @w{@uref{http://sourceware.org/PR13503,PR13503}}. | |
8516b1c4 | 1376 | |
8516b1c4 | 1377 | @end itemize |
1378 | ||
8516b1c4 | 1379 | @subsection M32C Named Address Spaces |
1380 | @cindex @code{__far} M32C Named Address Spaces | |
1381 | ||
1382 | On the M32C target, with the R8C and M16C cpu variants, variables | |
1383 | qualified with @code{__far} are accessed using 32-bit addresses in | |
1384 | order to access memory beyond the first 64@tie{}Ki bytes. If | |
1385 | @code{__far} is used with the M32CM or M32C cpu variants, it has no | |
1386 | effect. | |
1387 | ||
1388 | @subsection RL78 Named Address Spaces | |
1389 | @cindex @code{__far} RL78 Named Address Spaces | |
1390 | ||
1391 | On the RL78 target, variables qualified with @code{__far} are accessed | |
1392 | with 32-bit pointers (20-bit addresses) rather than the default 16-bit | |
1393 | addresses. Non-far variables are assumed to appear in the topmost | |
1394 | 64@tie{}KiB of the address space. | |
1395 | ||
1396 | @subsection SPU Named Address Spaces | |
1397 | @cindex @code{__ea} SPU Named Address Spaces | |
1398 | ||
1399 | On the SPU target variables may be declared as | |
78e515f7 | 1400 | belonging to another address space by qualifying the type with the |
1401 | @code{__ea} address space identifier: | |
bd1a81f7 | 1402 | |
1403 | @smallexample | |
1404 | extern int __ea i; | |
1405 | @end smallexample | |
1406 | ||
1407 | When the variable @code{i} is accessed, the compiler will generate | |
1408 | special code to access this variable. It may use runtime library | |
1409 | support, or generate special machine instructions to access that address | |
1410 | space. | |
1411 | ||
146ef39f | 1412 | @node Zero Length |
1413 | @section Arrays of Length Zero | |
1414 | @cindex arrays of length zero | |
1415 | @cindex zero-length arrays | |
1416 | @cindex length-zero arrays | |
21c8999d | 1417 | @cindex flexible array members |
146ef39f | 1418 | |
0858e3a2 | 1419 | Zero-length arrays are allowed in GNU C@. They are very useful as the |
15119d83 | 1420 | last element of a structure which is really a header for a variable-length |
146ef39f | 1421 | object: |
1422 | ||
a0ecd6b1 | 1423 | @smallexample |
146ef39f | 1424 | struct line @{ |
1425 | int length; | |
1426 | char contents[0]; | |
1427 | @}; | |
1428 | ||
15119d83 | 1429 | struct line *thisline = (struct line *) |
1430 | malloc (sizeof (struct line) + this_length); | |
1431 | thisline->length = this_length; | |
a0ecd6b1 | 1432 | @end smallexample |
146ef39f | 1433 | |
7fb9818b | 1434 | In ISO C90, you would have to give @code{contents} a length of 1, which |
146ef39f | 1435 | means either you waste space or complicate the argument to @code{malloc}. |
1436 | ||
3b0848a2 | 1437 | In ISO C99, you would use a @dfn{flexible array member}, which is |
15119d83 | 1438 | slightly different in syntax and semantics: |
1439 | ||
1440 | @itemize @bullet | |
1441 | @item | |
1442 | Flexible array members are written as @code{contents[]} without | |
1443 | the @code{0}. | |
1444 | ||
1445 | @item | |
1446 | Flexible array members have incomplete type, and so the @code{sizeof} | |
1447 | operator may not be applied. As a quirk of the original implementation | |
1448 | of zero-length arrays, @code{sizeof} evaluates to zero. | |
1449 | ||
1450 | @item | |
1451 | Flexible array members may only appear as the last member of a | |
26877a3f | 1452 | @code{struct} that is otherwise non-empty. |
ce09bc13 | 1453 | |
1454 | @item | |
1455 | A structure containing a flexible array member, or a union containing | |
1456 | such a structure (possibly recursively), may not be a member of a | |
1457 | structure or an element of an array. (However, these uses are | |
1458 | permitted by GCC as extensions.) | |
21c8999d | 1459 | @end itemize |
1b82e858 | 1460 | |
21c8999d | 1461 | GCC versions before 3.0 allowed zero-length arrays to be statically |
26877a3f | 1462 | initialized, as if they were flexible arrays. In addition to those |
1463 | cases that were useful, it also allowed initializations in situations | |
1464 | that would corrupt later data. Non-empty initialization of zero-length | |
1465 | arrays is now treated like any case where there are more initializer | |
1466 | elements than the array holds, in that a suitable warning about "excess | |
1467 | elements in array" is given, and the excess elements (all of them, in | |
1468 | this case) are ignored. | |
21c8999d | 1469 | |
1470 | Instead GCC allows static initialization of flexible array members. | |
1471 | This is equivalent to defining a new structure containing the original | |
1472 | structure followed by an array of sufficient size to contain the data. | |
0858f8a2 | 1473 | I.e.@: in the following, @code{f1} is constructed as if it were declared |
21c8999d | 1474 | like @code{f2}. |
1b82e858 | 1475 | |
a0ecd6b1 | 1476 | @smallexample |
21c8999d | 1477 | struct f1 @{ |
1478 | int x; int y[]; | |
1479 | @} f1 = @{ 1, @{ 2, 3, 4 @} @}; | |
1480 | ||
1481 | struct f2 @{ | |
1482 | struct f1 f1; int data[3]; | |
1483 | @} f2 = @{ @{ 1 @}, @{ 2, 3, 4 @} @}; | |
a0ecd6b1 | 1484 | @end smallexample |
15119d83 | 1485 | |
21c8999d | 1486 | @noindent |
1487 | The convenience of this extension is that @code{f1} has the desired | |
1488 | type, eliminating the need to consistently refer to @code{f2.f1}. | |
1489 | ||
1490 | This has symmetry with normal static arrays, in that an array of | |
1491 | unknown size is also written with @code{[]}. | |
1b82e858 | 1492 | |
21c8999d | 1493 | Of course, this extension only makes sense if the extra data comes at |
1494 | the end of a top-level object, as otherwise we would be overwriting | |
1495 | data at subsequent offsets. To avoid undue complication and confusion | |
1496 | with initialization of deeply nested arrays, we simply disallow any | |
1497 | non-empty initialization except when the structure is the top-level | |
1498 | object. For example: | |
15119d83 | 1499 | |
a0ecd6b1 | 1500 | @smallexample |
21c8999d | 1501 | struct foo @{ int x; int y[]; @}; |
1502 | struct bar @{ struct foo z; @}; | |
1503 | ||
afb00aa2 | 1504 | struct foo a = @{ 1, @{ 2, 3, 4 @} @}; // @r{Valid.} |
1505 | struct bar b = @{ @{ 1, @{ 2, 3, 4 @} @} @}; // @r{Invalid.} | |
1506 | struct bar c = @{ @{ 1, @{ @} @} @}; // @r{Valid.} | |
1507 | struct foo d[1] = @{ @{ 1 @{ 2, 3, 4 @} @} @}; // @r{Invalid.} | |
a0ecd6b1 | 1508 | @end smallexample |
eae914e2 | 1509 | |
710d60ed | 1510 | @node Empty Structures |
1511 | @section Structures With No Members | |
1512 | @cindex empty structures | |
1513 | @cindex zero-size structures | |
1514 | ||
1515 | GCC permits a C structure to have no members: | |
1516 | ||
a0ecd6b1 | 1517 | @smallexample |
710d60ed | 1518 | struct empty @{ |
1519 | @}; | |
a0ecd6b1 | 1520 | @end smallexample |
710d60ed | 1521 | |
1522 | The structure will have size zero. In C++, empty structures are part | |
907e3369 | 1523 | of the language. G++ treats empty structures as if they had a single |
1524 | member of type @code{char}. | |
710d60ed | 1525 | |
146ef39f | 1526 | @node Variable Length |
1527 | @section Arrays of Variable Length | |
1528 | @cindex variable-length arrays | |
1529 | @cindex arrays of variable length | |
3cfa0cc4 | 1530 | @cindex VLAs |
146ef39f | 1531 | |
3cfa0cc4 | 1532 | Variable-length automatic arrays are allowed in ISO C99, and as an |
15334b7a | 1533 | extension GCC accepts them in C90 mode and in C++. These arrays are |
146ef39f | 1534 | declared like any other automatic arrays, but with a length that is not |
1535 | a constant expression. The storage is allocated at the point of | |
1536 | declaration and deallocated when the brace-level is exited. For | |
1537 | example: | |
1538 | ||
a0ecd6b1 | 1539 | @smallexample |
146ef39f | 1540 | FILE * |
1541 | concat_fopen (char *s1, char *s2, char *mode) | |
1542 | @{ | |
1543 | char str[strlen (s1) + strlen (s2) + 1]; | |
1544 | strcpy (str, s1); | |
1545 | strcat (str, s2); | |
1546 | return fopen (str, mode); | |
1547 | @} | |
a0ecd6b1 | 1548 | @end smallexample |
146ef39f | 1549 | |
1550 | @cindex scope of a variable length array | |
1551 | @cindex variable-length array scope | |
1552 | @cindex deallocating variable length arrays | |
1553 | Jumping or breaking out of the scope of the array name deallocates the | |
1554 | storage. Jumping into the scope is not allowed; you get an error | |
1555 | message for it. | |
1556 | ||
1557 | @cindex @code{alloca} vs variable-length arrays | |
1558 | You can use the function @code{alloca} to get an effect much like | |
1559 | variable-length arrays. The function @code{alloca} is available in | |
1560 | many other C implementations (but not in all). On the other hand, | |
1561 | variable-length arrays are more elegant. | |
1562 | ||
1563 | There are other differences between these two methods. Space allocated | |
1564 | with @code{alloca} exists until the containing @emph{function} returns. | |
1565 | The space for a variable-length array is deallocated as soon as the array | |
1566 | name's scope ends. (If you use both variable-length arrays and | |
1567 | @code{alloca} in the same function, deallocation of a variable-length array | |
1568 | will also deallocate anything more recently allocated with @code{alloca}.) | |
1569 | ||
1570 | You can also use variable-length arrays as arguments to functions: | |
1571 | ||
a0ecd6b1 | 1572 | @smallexample |
146ef39f | 1573 | struct entry |
1574 | tester (int len, char data[len][len]) | |
1575 | @{ | |
4ae74ddd | 1576 | /* @r{@dots{}} */ |
146ef39f | 1577 | @} |
a0ecd6b1 | 1578 | @end smallexample |
146ef39f | 1579 | |
1580 | The length of an array is computed once when the storage is allocated | |
1581 | and is remembered for the scope of the array in case you access it with | |
1582 | @code{sizeof}. | |
1583 | ||
1584 | If you want to pass the array first and the length afterward, you can | |
1585 | use a forward declaration in the parameter list---another GNU extension. | |
1586 | ||
a0ecd6b1 | 1587 | @smallexample |
146ef39f | 1588 | struct entry |
1589 | tester (int len; char data[len][len], int len) | |
1590 | @{ | |
4ae74ddd | 1591 | /* @r{@dots{}} */ |
146ef39f | 1592 | @} |
a0ecd6b1 | 1593 | @end smallexample |
146ef39f | 1594 | |
1595 | @cindex parameter forward declaration | |
1596 | The @samp{int len} before the semicolon is a @dfn{parameter forward | |
1597 | declaration}, and it serves the purpose of making the name @code{len} | |
1598 | known when the declaration of @code{data} is parsed. | |
1599 | ||
1600 | You can write any number of such parameter forward declarations in the | |
1601 | parameter list. They can be separated by commas or semicolons, but the | |
1602 | last one must end with a semicolon, which is followed by the ``real'' | |
1603 | parameter declarations. Each forward declaration must match a ``real'' | |
3cfa0cc4 | 1604 | declaration in parameter name and data type. ISO C99 does not support |
1605 | parameter forward declarations. | |
146ef39f | 1606 | |
da825954 | 1607 | @node Variadic Macros |
1608 | @section Macros with a Variable Number of Arguments. | |
146ef39f | 1609 | @cindex variable number of arguments |
1610 | @cindex macro with variable arguments | |
1611 | @cindex rest argument (in macro) | |
da825954 | 1612 | @cindex variadic macros |
146ef39f | 1613 | |
da825954 | 1614 | In the ISO C standard of 1999, a macro can be declared to accept a |
1615 | variable number of arguments much as a function can. The syntax for | |
1616 | defining the macro is similar to that of a function. Here is an | |
1617 | example: | |
146ef39f | 1618 | |
b724fad7 | 1619 | @smallexample |
da825954 | 1620 | #define debug(format, ...) fprintf (stderr, format, __VA_ARGS__) |
b724fad7 | 1621 | @end smallexample |
146ef39f | 1622 | |
da825954 | 1623 | Here @samp{@dots{}} is a @dfn{variable argument}. In the invocation of |
1624 | such a macro, it represents the zero or more tokens until the closing | |
1625 | parenthesis that ends the invocation, including any commas. This set of | |
1626 | tokens replaces the identifier @code{__VA_ARGS__} in the macro body | |
1627 | wherever it appears. See the CPP manual for more information. | |
1628 | ||
1629 | GCC has long supported variadic macros, and used a different syntax that | |
1630 | allowed you to give a name to the variable arguments just like any other | |
1631 | argument. Here is an example: | |
146ef39f | 1632 | |
a0ecd6b1 | 1633 | @smallexample |
da825954 | 1634 | #define debug(format, args...) fprintf (stderr, format, args) |
a0ecd6b1 | 1635 | @end smallexample |
146ef39f | 1636 | |
da825954 | 1637 | This is in all ways equivalent to the ISO C example above, but arguably |
1638 | more readable and descriptive. | |
146ef39f | 1639 | |
da825954 | 1640 | GNU CPP has two further variadic macro extensions, and permits them to |
1641 | be used with either of the above forms of macro definition. | |
1642 | ||
1643 | In standard C, you are not allowed to leave the variable argument out | |
1644 | entirely; but you are allowed to pass an empty argument. For example, | |
1645 | this invocation is invalid in ISO C, because there is no comma after | |
1646 | the string: | |
146ef39f | 1647 | |
a0ecd6b1 | 1648 | @smallexample |
da825954 | 1649 | debug ("A message") |
a0ecd6b1 | 1650 | @end smallexample |
146ef39f | 1651 | |
da825954 | 1652 | GNU CPP permits you to completely omit the variable arguments in this |
1653 | way. In the above examples, the compiler would complain, though since | |
1654 | the expansion of the macro still has the extra comma after the format | |
1655 | string. | |
1656 | ||
1657 | To help solve this problem, CPP behaves specially for variable arguments | |
1658 | used with the token paste operator, @samp{##}. If instead you write | |
146ef39f | 1659 | |
b724fad7 | 1660 | @smallexample |
da825954 | 1661 | #define debug(format, ...) fprintf (stderr, format, ## __VA_ARGS__) |
b724fad7 | 1662 | @end smallexample |
146ef39f | 1663 | |
da825954 | 1664 | and if the variable arguments are omitted or empty, the @samp{##} |
1665 | operator causes the preprocessor to remove the comma before it. If you | |
1666 | do provide some variable arguments in your macro invocation, GNU CPP | |
1667 | does not complain about the paste operation and instead places the | |
1668 | variable arguments after the comma. Just like any other pasted macro | |
1669 | argument, these arguments are not macro expanded. | |
1670 | ||
1671 | @node Escaped Newlines | |
1672 | @section Slightly Looser Rules for Escaped Newlines | |
1673 | @cindex escaped newlines | |
1674 | @cindex newlines (escaped) | |
1675 | ||
455730ef | 1676 | Recently, the preprocessor has relaxed its treatment of escaped |
1677 | newlines. Previously, the newline had to immediately follow a | |
ebc03810 | 1678 | backslash. The current implementation allows whitespace in the form |
1679 | of spaces, horizontal and vertical tabs, and form feeds between the | |
da825954 | 1680 | backslash and the subsequent newline. The preprocessor issues a |
1681 | warning, but treats it as a valid escaped newline and combines the two | |
1682 | lines to form a single logical line. This works within comments and | |
ebc03810 | 1683 | tokens, as well as between tokens. Comments are @emph{not} treated as |
1684 | whitespace for the purposes of this relaxation, since they have not | |
1685 | yet been replaced with spaces. | |
146ef39f | 1686 | |
1687 | @node Subscripting | |
1688 | @section Non-Lvalue Arrays May Have Subscripts | |
1689 | @cindex subscripting | |
1690 | @cindex arrays, non-lvalue | |
1691 | ||
1692 | @cindex subscripting and function values | |
62827f44 | 1693 | In ISO C99, arrays that are not lvalues still decay to pointers, and |
1694 | may be subscripted, although they may not be modified or used after | |
1695 | the next sequence point and the unary @samp{&} operator may not be | |
1696 | applied to them. As an extension, GCC allows such arrays to be | |
32f1f35b | 1697 | subscripted in C90 mode, though otherwise they do not decay to |
62827f44 | 1698 | pointers outside C99 mode. For example, |
32f1f35b | 1699 | this is valid in GNU C though not valid in C90: |
146ef39f | 1700 | |
a0ecd6b1 | 1701 | @smallexample |
146ef39f | 1702 | @group |
1703 | struct foo @{int a[4];@}; | |
1704 | ||
1705 | struct foo f(); | |
1706 | ||
1707 | bar (int index) | |
1708 | @{ | |
1709 | return f().a[index]; | |
1710 | @} | |
1711 | @end group | |
a0ecd6b1 | 1712 | @end smallexample |
146ef39f | 1713 | |
1714 | @node Pointer Arith | |
1715 | @section Arithmetic on @code{void}- and Function-Pointers | |
1716 | @cindex void pointers, arithmetic | |
1717 | @cindex void, size of pointer to | |
1718 | @cindex function pointers, arithmetic | |
1719 | @cindex function, size of pointer to | |
1720 | ||
1721 | In GNU C, addition and subtraction operations are supported on pointers to | |
1722 | @code{void} and on pointers to functions. This is done by treating the | |
1723 | size of a @code{void} or of a function as 1. | |
1724 | ||
1725 | A consequence of this is that @code{sizeof} is also allowed on @code{void} | |
1726 | and on function types, and returns 1. | |
1727 | ||
67791935 | 1728 | @opindex Wpointer-arith |
1729 | The option @option{-Wpointer-arith} requests a warning if these extensions | |
146ef39f | 1730 | are used. |
1731 | ||
1732 | @node Initializers | |
1733 | @section Non-Constant Initializers | |
1734 | @cindex initializers, non-constant | |
1735 | @cindex non-constant initializers | |
1736 | ||
3cfa0cc4 | 1737 | As in standard C++ and ISO C99, the elements of an aggregate initializer for an |
0858e3a2 | 1738 | automatic variable are not required to be constant expressions in GNU C@. |
146ef39f | 1739 | Here is an example of an initializer with run-time varying elements: |
1740 | ||
a0ecd6b1 | 1741 | @smallexample |
146ef39f | 1742 | foo (float f, float g) |
1743 | @{ | |
1744 | float beat_freqs[2] = @{ f-g, f+g @}; | |
4ae74ddd | 1745 | /* @r{@dots{}} */ |
146ef39f | 1746 | @} |
a0ecd6b1 | 1747 | @end smallexample |
146ef39f | 1748 | |
3cfa0cc4 | 1749 | @node Compound Literals |
1750 | @section Compound Literals | |
146ef39f | 1751 | @cindex constructor expressions |
1752 | @cindex initializations in expressions | |
1753 | @cindex structures, constructor expression | |
1754 | @cindex expressions, constructor | |
3cfa0cc4 | 1755 | @cindex compound literals |
1756 | @c The GNU C name for what C99 calls compound literals was "constructor expressions". | |
146ef39f | 1757 | |
3cfa0cc4 | 1758 | ISO C99 supports compound literals. A compound literal looks like |
146ef39f | 1759 | a cast containing an initializer. Its value is an object of the |
1760 | type specified in the cast, containing the elements specified in | |
ec11e38e | 1761 | the initializer; it is an lvalue. As an extension, GCC supports |
eb5d9b7b | 1762 | compound literals in C90 mode and in C++, though the semantics are |
1763 | somewhat different in C++. | |
146ef39f | 1764 | |
1765 | Usually, the specified type is a structure. Assume that | |
1766 | @code{struct foo} and @code{structure} are declared as shown: | |
1767 | ||
a0ecd6b1 | 1768 | @smallexample |
146ef39f | 1769 | struct foo @{int a; char b[2];@} structure; |
a0ecd6b1 | 1770 | @end smallexample |
146ef39f | 1771 | |
1772 | @noindent | |
3cfa0cc4 | 1773 | Here is an example of constructing a @code{struct foo} with a compound literal: |
146ef39f | 1774 | |
a0ecd6b1 | 1775 | @smallexample |
146ef39f | 1776 | structure = ((struct foo) @{x + y, 'a', 0@}); |
a0ecd6b1 | 1777 | @end smallexample |
146ef39f | 1778 | |
1779 | @noindent | |
1780 | This is equivalent to writing the following: | |
1781 | ||
a0ecd6b1 | 1782 | @smallexample |
146ef39f | 1783 | @{ |
1784 | struct foo temp = @{x + y, 'a', 0@}; | |
1785 | structure = temp; | |
1786 | @} | |
a0ecd6b1 | 1787 | @end smallexample |
146ef39f | 1788 | |
eb5d9b7b | 1789 | You can also construct an array, though this is dangerous in C++, as |
1790 | explained below. If all the elements of the compound literal are | |
1791 | (made up of) simple constant expressions, suitable for use in | |
ec11e38e | 1792 | initializers of objects of static storage duration, then the compound |
1793 | literal can be coerced to a pointer to its first element and used in | |
1794 | such an initializer, as shown here: | |
146ef39f | 1795 | |
a0ecd6b1 | 1796 | @smallexample |
146ef39f | 1797 | char **foo = (char *[]) @{ "x", "y", "z" @}; |
a0ecd6b1 | 1798 | @end smallexample |
146ef39f | 1799 | |
f3b11bf1 | 1800 | Compound literals for scalar types and union types are |
3cfa0cc4 | 1801 | also allowed, but then the compound literal is equivalent |
146ef39f | 1802 | to a cast. |
1803 | ||
4619fc15 | 1804 | As a GNU extension, GCC allows initialization of objects with static storage |
1805 | duration by compound literals (which is not possible in ISO C99, because | |
1806 | the initializer is not a constant). | |
1807 | It is handled as if the object was initialized only with the bracket | |
d1c59264 | 1808 | enclosed list if the types of the compound literal and the object match. |
4619fc15 | 1809 | The initializer list of the compound literal must be constant. |
1810 | If the object being initialized has array type of unknown size, the size is | |
02643ebc | 1811 | determined by compound literal size. |
4619fc15 | 1812 | |
a0ecd6b1 | 1813 | @smallexample |
4619fc15 | 1814 | static struct foo x = (struct foo) @{1, 'a', 'b'@}; |
1815 | static int y[] = (int []) @{1, 2, 3@}; | |
1816 | static int z[] = (int [3]) @{1@}; | |
a0ecd6b1 | 1817 | @end smallexample |
4619fc15 | 1818 | |
1819 | @noindent | |
1820 | The above lines are equivalent to the following: | |
a0ecd6b1 | 1821 | @smallexample |
4619fc15 | 1822 | static struct foo x = @{1, 'a', 'b'@}; |
1823 | static int y[] = @{1, 2, 3@}; | |
02643ebc | 1824 | static int z[] = @{1, 0, 0@}; |
a0ecd6b1 | 1825 | @end smallexample |
4619fc15 | 1826 | |
eb5d9b7b | 1827 | In C, a compound literal designates an unnamed object with static or |
1828 | automatic storage duration. In C++, a compound literal designates a | |
1829 | temporary object, which only lives until the end of its | |
1830 | full-expression. As a result, well-defined C code that takes the | |
1831 | address of a subobject of a compound literal can be undefined in C++. | |
1832 | For instance, if the array compound literal example above appeared | |
1833 | inside a function, any subsequent use of @samp{foo} in C++ has | |
1834 | undefined behavior because the lifetime of the array ends after the | |
1835 | declaration of @samp{foo}. As a result, the C++ compiler now rejects | |
1836 | the conversion of a temporary array to a pointer. | |
1837 | ||
1838 | As an optimization, the C++ compiler sometimes gives array compound | |
1839 | literals longer lifetimes: when the array either appears outside a | |
1840 | function or has const-qualified type. If @samp{foo} and its | |
1841 | initializer had elements of @samp{char *const} type rather than | |
1842 | @samp{char *}, or if @samp{foo} were a global variable, the array | |
1843 | would have static storage duration. But it is probably safest just to | |
1844 | avoid the use of array compound literals in code compiled as C++. | |
1845 | ||
3cfa0cc4 | 1846 | @node Designated Inits |
1847 | @section Designated Initializers | |
146ef39f | 1848 | @cindex initializers with labeled elements |
1849 | @cindex labeled elements in initializers | |
1850 | @cindex case labels in initializers | |
3cfa0cc4 | 1851 | @cindex designated initializers |
146ef39f | 1852 | |
32f1f35b | 1853 | Standard C90 requires the elements of an initializer to appear in a fixed |
146ef39f | 1854 | order, the same as the order of the elements in the array or structure |
1855 | being initialized. | |
1856 | ||
31bd149b | 1857 | In ISO C99 you can give the elements in any order, specifying the array |
1858 | indices or structure field names they apply to, and GNU C allows this as | |
32f1f35b | 1859 | an extension in C90 mode as well. This extension is not |
146ef39f | 1860 | implemented in GNU C++. |
1861 | ||
31bd149b | 1862 | To specify an array index, write |
146ef39f | 1863 | @samp{[@var{index}] =} before the element value. For example, |
1864 | ||
a0ecd6b1 | 1865 | @smallexample |
31bd149b | 1866 | int a[6] = @{ [4] = 29, [2] = 15 @}; |
a0ecd6b1 | 1867 | @end smallexample |
146ef39f | 1868 | |
1869 | @noindent | |
1870 | is equivalent to | |
1871 | ||
a0ecd6b1 | 1872 | @smallexample |
146ef39f | 1873 | int a[6] = @{ 0, 0, 15, 0, 29, 0 @}; |
a0ecd6b1 | 1874 | @end smallexample |
146ef39f | 1875 | |
1876 | @noindent | |
1877 | The index values must be constant expressions, even if the array being | |
1878 | initialized is automatic. | |
1879 | ||
31bd149b | 1880 | An alternative syntax for this which has been obsolete since GCC 2.5 but |
1881 | GCC still accepts is to write @samp{[@var{index}]} before the element | |
1882 | value, with no @samp{=}. | |
1883 | ||
146ef39f | 1884 | To initialize a range of elements to the same value, write |
31bd149b | 1885 | @samp{[@var{first} ... @var{last}] = @var{value}}. This is a GNU |
1886 | extension. For example, | |
146ef39f | 1887 | |
a0ecd6b1 | 1888 | @smallexample |
146ef39f | 1889 | int widths[] = @{ [0 ... 9] = 1, [10 ... 99] = 2, [100] = 3 @}; |
a0ecd6b1 | 1890 | @end smallexample |
146ef39f | 1891 | |
989bbcfc | 1892 | @noindent |
1893 | If the value in it has side-effects, the side-effects will happen only once, | |
1894 | not for each initialized field by the range initializer. | |
1895 | ||
146ef39f | 1896 | @noindent |
1897 | Note that the length of the array is the highest value specified | |
1898 | plus one. | |
1899 | ||
1900 | In a structure initializer, specify the name of a field to initialize | |
31bd149b | 1901 | with @samp{.@var{fieldname} =} before the element value. For example, |
146ef39f | 1902 | given the following structure, |
1903 | ||
a0ecd6b1 | 1904 | @smallexample |
146ef39f | 1905 | struct point @{ int x, y; @}; |
a0ecd6b1 | 1906 | @end smallexample |
146ef39f | 1907 | |
1908 | @noindent | |
1909 | the following initialization | |
1910 | ||
a0ecd6b1 | 1911 | @smallexample |
31bd149b | 1912 | struct point p = @{ .y = yvalue, .x = xvalue @}; |
a0ecd6b1 | 1913 | @end smallexample |
146ef39f | 1914 | |
1915 | @noindent | |
1916 | is equivalent to | |
1917 | ||
a0ecd6b1 | 1918 | @smallexample |
146ef39f | 1919 | struct point p = @{ xvalue, yvalue @}; |
a0ecd6b1 | 1920 | @end smallexample |
146ef39f | 1921 | |
31bd149b | 1922 | Another syntax which has the same meaning, obsolete since GCC 2.5, is |
1923 | @samp{@var{fieldname}:}, as shown here: | |
146ef39f | 1924 | |
a0ecd6b1 | 1925 | @smallexample |
31bd149b | 1926 | struct point p = @{ y: yvalue, x: xvalue @}; |
a0ecd6b1 | 1927 | @end smallexample |
146ef39f | 1928 | |
3cfa0cc4 | 1929 | @cindex designators |
1930 | The @samp{[@var{index}]} or @samp{.@var{fieldname}} is known as a | |
1931 | @dfn{designator}. You can also use a designator (or the obsolete colon | |
1932 | syntax) when initializing a union, to specify which element of the union | |
1933 | should be used. For example, | |
146ef39f | 1934 | |
a0ecd6b1 | 1935 | @smallexample |
146ef39f | 1936 | union foo @{ int i; double d; @}; |
1937 | ||
31bd149b | 1938 | union foo f = @{ .d = 4 @}; |
a0ecd6b1 | 1939 | @end smallexample |
146ef39f | 1940 | |
1941 | @noindent | |
1942 | will convert 4 to a @code{double} to store it in the union using | |
1943 | the second element. By contrast, casting 4 to type @code{union foo} | |
1944 | would store it into the union as the integer @code{i}, since it is | |
1945 | an integer. (@xref{Cast to Union}.) | |
1946 | ||
1947 | You can combine this technique of naming elements with ordinary C | |
1948 | initialization of successive elements. Each initializer element that | |
3cfa0cc4 | 1949 | does not have a designator applies to the next consecutive element of the |
146ef39f | 1950 | array or structure. For example, |
1951 | ||
a0ecd6b1 | 1952 | @smallexample |
146ef39f | 1953 | int a[6] = @{ [1] = v1, v2, [4] = v4 @}; |
a0ecd6b1 | 1954 | @end smallexample |
146ef39f | 1955 | |
1956 | @noindent | |
1957 | is equivalent to | |
1958 | ||
a0ecd6b1 | 1959 | @smallexample |
146ef39f | 1960 | int a[6] = @{ 0, v1, v2, 0, v4, 0 @}; |
a0ecd6b1 | 1961 | @end smallexample |
146ef39f | 1962 | |
1963 | Labeling the elements of an array initializer is especially useful | |
1964 | when the indices are characters or belong to an @code{enum} type. | |
1965 | For example: | |
1966 | ||
a0ecd6b1 | 1967 | @smallexample |
146ef39f | 1968 | int whitespace[256] |
1969 | = @{ [' '] = 1, ['\t'] = 1, ['\h'] = 1, | |
1970 | ['\f'] = 1, ['\n'] = 1, ['\r'] = 1 @}; | |
a0ecd6b1 | 1971 | @end smallexample |
146ef39f | 1972 | |
3cfa0cc4 | 1973 | @cindex designator lists |
31bd149b | 1974 | You can also write a series of @samp{.@var{fieldname}} and |
3cfa0cc4 | 1975 | @samp{[@var{index}]} designators before an @samp{=} to specify a |
31bd149b | 1976 | nested subobject to initialize; the list is taken relative to the |
1977 | subobject corresponding to the closest surrounding brace pair. For | |
1978 | example, with the @samp{struct point} declaration above: | |
1979 | ||
b724fad7 | 1980 | @smallexample |
31bd149b | 1981 | struct point ptarray[10] = @{ [2].y = yv2, [2].x = xv2, [0].x = xv0 @}; |
b724fad7 | 1982 | @end smallexample |
31bd149b | 1983 | |
989bbcfc | 1984 | @noindent |
1985 | If the same field is initialized multiple times, it will have value from | |
1986 | the last initialization. If any such overridden initialization has | |
1987 | side-effect, it is unspecified whether the side-effect happens or not. | |
ef8d967c | 1988 | Currently, GCC will discard them and issue a warning. |
989bbcfc | 1989 | |
146ef39f | 1990 | @node Case Ranges |
1991 | @section Case Ranges | |
1992 | @cindex case ranges | |
1993 | @cindex ranges in case statements | |
1994 | ||
1995 | You can specify a range of consecutive values in a single @code{case} label, | |
1996 | like this: | |
1997 | ||
a0ecd6b1 | 1998 | @smallexample |
146ef39f | 1999 | case @var{low} ... @var{high}: |
a0ecd6b1 | 2000 | @end smallexample |
146ef39f | 2001 | |
2002 | @noindent | |
2003 | This has the same effect as the proper number of individual @code{case} | |
2004 | labels, one for each integer value from @var{low} to @var{high}, inclusive. | |
2005 | ||
2006 | This feature is especially useful for ranges of ASCII character codes: | |
2007 | ||
a0ecd6b1 | 2008 | @smallexample |
146ef39f | 2009 | case 'A' ... 'Z': |
a0ecd6b1 | 2010 | @end smallexample |
146ef39f | 2011 | |
2012 | @strong{Be careful:} Write spaces around the @code{...}, for otherwise | |
2013 | it may be parsed wrong when you use it with integer values. For example, | |
2014 | write this: | |
2015 | ||
a0ecd6b1 | 2016 | @smallexample |
146ef39f | 2017 | case 1 ... 5: |
a0ecd6b1 | 2018 | @end smallexample |
146ef39f | 2019 | |
2020 | @noindent | |
2021 | rather than this: | |
2022 | ||
a0ecd6b1 | 2023 | @smallexample |
146ef39f | 2024 | case 1...5: |
a0ecd6b1 | 2025 | @end smallexample |
146ef39f | 2026 | |
2027 | @node Cast to Union | |
2028 | @section Cast to a Union Type | |
2029 | @cindex cast to a union | |
2030 | @cindex union, casting to a | |
2031 | ||
2032 | A cast to union type is similar to other casts, except that the type | |
2033 | specified is a union type. You can specify the type either with | |
2034 | @code{union @var{tag}} or with a typedef name. A cast to union is actually | |
2035 | a constructor though, not a cast, and hence does not yield an lvalue like | |
3cfa0cc4 | 2036 | normal casts. (@xref{Compound Literals}.) |
146ef39f | 2037 | |
2038 | The types that may be cast to the union type are those of the members | |
2039 | of the union. Thus, given the following union and variables: | |
2040 | ||
a0ecd6b1 | 2041 | @smallexample |
146ef39f | 2042 | union foo @{ int i; double d; @}; |
2043 | int x; | |
2044 | double y; | |
a0ecd6b1 | 2045 | @end smallexample |
146ef39f | 2046 | |
2047 | @noindent | |
70c2c81c | 2048 | both @code{x} and @code{y} can be cast to type @code{union foo}. |
146ef39f | 2049 | |
2050 | Using the cast as the right-hand side of an assignment to a variable of | |
2051 | union type is equivalent to storing in a member of the union: | |
2052 | ||
a0ecd6b1 | 2053 | @smallexample |
146ef39f | 2054 | union foo u; |
4ae74ddd | 2055 | /* @r{@dots{}} */ |
146ef39f | 2056 | u = (union foo) x @equiv{} u.i = x |
2057 | u = (union foo) y @equiv{} u.d = y | |
a0ecd6b1 | 2058 | @end smallexample |
146ef39f | 2059 | |
2060 | You can also use the union cast as a function argument: | |
2061 | ||
a0ecd6b1 | 2062 | @smallexample |
146ef39f | 2063 | void hack (union foo); |
4ae74ddd | 2064 | /* @r{@dots{}} */ |
146ef39f | 2065 | hack ((union foo) x); |
a0ecd6b1 | 2066 | @end smallexample |
146ef39f | 2067 | |
3cfa0cc4 | 2068 | @node Mixed Declarations |
2069 | @section Mixed Declarations and Code | |
2070 | @cindex mixed declarations and code | |
2071 | @cindex declarations, mixed with code | |
2072 | @cindex code, mixed with declarations | |
2073 | ||
2074 | ISO C99 and ISO C++ allow declarations and code to be freely mixed | |
2075 | within compound statements. As an extension, GCC also allows this in | |
32f1f35b | 2076 | C90 mode. For example, you could do: |
3cfa0cc4 | 2077 | |
a0ecd6b1 | 2078 | @smallexample |
3cfa0cc4 | 2079 | int i; |
4ae74ddd | 2080 | /* @r{@dots{}} */ |
3cfa0cc4 | 2081 | i++; |
2082 | int j = i + 2; | |
a0ecd6b1 | 2083 | @end smallexample |
3cfa0cc4 | 2084 | |
2085 | Each identifier is visible from where it is declared until the end of | |
2086 | the enclosing block. | |
2087 | ||
146ef39f | 2088 | @node Function Attributes |
2089 | @section Declaring Attributes of Functions | |
2090 | @cindex function attributes | |
2091 | @cindex declaring attributes of functions | |
2092 | @cindex functions that never return | |
26d1c5ff | 2093 | @cindex functions that return more than once |
146ef39f | 2094 | @cindex functions that have no side effects |
2095 | @cindex functions in arbitrary sections | |
1caefcbd | 2096 | @cindex functions that behave like malloc |
146ef39f | 2097 | @cindex @code{volatile} applied to function |
2098 | @cindex @code{const} applied to function | |
6a87209c | 2099 | @cindex functions with @code{printf}, @code{scanf}, @code{strftime} or @code{strfmon} style arguments |
dbf6c367 | 2100 | @cindex functions with non-null pointer arguments |
146ef39f | 2101 | @cindex functions that are passed arguments in registers on the 386 |
2102 | @cindex functions that pop the argument stack on the 386 | |
2103 | @cindex functions that do not pop the argument stack on the 386 | |
46f8e3b0 | 2104 | @cindex functions that have different compilation options on the 386 |
2105 | @cindex functions that have different optimization options | |
85c0a25c | 2106 | @cindex functions that are dynamically resolved |
146ef39f | 2107 | |
2108 | In GNU C, you declare certain things about functions called in your program | |
2109 | which help the compiler optimize function calls and check your code more | |
2110 | carefully. | |
2111 | ||
2112 | The keyword @code{__attribute__} allows you to specify special | |
2113 | attributes when making a declaration. This keyword is followed by an | |
93f10b04 | 2114 | attribute specification inside double parentheses. The following |
b28b3cd2 | 2115 | attributes are currently defined for functions on all targets: |
097b5c8b | 2116 | @code{aligned}, @code{alloc_size}, @code{noreturn}, |
bdb1f0d1 | 2117 | @code{returns_twice}, @code{noinline}, @code{noclone}, |
2118 | @code{always_inline}, @code{flatten}, @code{pure}, @code{const}, | |
2119 | @code{nothrow}, @code{sentinel}, @code{format}, @code{format_arg}, | |
48b14f50 | 2120 | @code{no_instrument_function}, @code{no_split_stack}, |
2121 | @code{section}, @code{constructor}, | |
4a29c97c | 2122 | @code{destructor}, @code{used}, @code{unused}, @code{deprecated}, |
85c0a25c | 2123 | @code{weak}, @code{malloc}, @code{alias}, @code{ifunc}, |
2124 | @code{warn_unused_result}, @code{nonnull}, @code{gnu_inline}, | |
2125 | @code{externally_visible}, @code{hot}, @code{cold}, @code{artificial}, | |
2126 | @code{error} and @code{warning}. Several other attributes are defined | |
2127 | for functions on particular target systems. Other attributes, | |
2128 | including @code{section} are supported for variables declarations | |
2129 | (@pxref{Variable Attributes}) and for types (@pxref{Type Attributes}). | |
146ef39f | 2130 | |
2dc819f3 | 2131 | GCC plugins may provide their own attributes. |
2132 | ||
146ef39f | 2133 | You may also specify attributes with @samp{__} preceding and following |
2134 | each keyword. This allows you to use them in header files without | |
2135 | being concerned about a possible macro of the same name. For example, | |
2136 | you may use @code{__noreturn__} instead of @code{noreturn}. | |
2137 | ||
b31bfb3f | 2138 | @xref{Attribute Syntax}, for details of the exact syntax for using |
2139 | attributes. | |
2140 | ||
146ef39f | 2141 | @table @code |
b3d47662 | 2142 | @c Keep this table alphabetized by attribute name. Treat _ as space. |
146ef39f | 2143 | |
7c85682d | 2144 | @item alias ("@var{target}") |
2145 | @cindex @code{alias} attribute | |
2146 | The @code{alias} attribute causes the declaration to be emitted as an | |
2147 | alias for another symbol, which must be specified. For instance, | |
146ef39f | 2148 | |
2149 | @smallexample | |
7c85682d | 2150 | void __f () @{ /* @r{Do something.} */; @} |
2151 | void f () __attribute__ ((weak, alias ("__f"))); | |
146ef39f | 2152 | @end smallexample |
2153 | ||
0a3ecdc1 | 2154 | defines @samp{f} to be a weak alias for @samp{__f}. In C++, the |
b60f73dc | 2155 | mangled name for the target must be used. It is an error if @samp{__f} |
2156 | is not defined in the same translation unit. | |
7c85682d | 2157 | |
2158 | Not all target machines support this attribute. | |
93f10b04 | 2159 | |
097b5c8b | 2160 | @item aligned (@var{alignment}) |
2161 | @cindex @code{aligned} attribute | |
2162 | This attribute specifies a minimum alignment for the function, | |
2163 | measured in bytes. | |
2164 | ||
2165 | You cannot use this attribute to decrease the alignment of a function, | |
2166 | only to increase it. However, when you explicitly specify a function | |
2167 | alignment this will override the effect of the | |
2168 | @option{-falign-functions} (@pxref{Optimize Options}) option for this | |
2169 | function. | |
2170 | ||
2171 | Note that the effectiveness of @code{aligned} attributes may be | |
2172 | limited by inherent limitations in your linker. On many systems, the | |
2173 | linker is only able to arrange for functions to be aligned up to a | |
2174 | certain maximum alignment. (For some linkers, the maximum supported | |
2175 | alignment may be very very small.) See your linker documentation for | |
2176 | further information. | |
2177 | ||
2178 | The @code{aligned} attribute can also be used for variables and fields | |
2179 | (@pxref{Variable Attributes}.) | |
2180 | ||
4a29c97c | 2181 | @item alloc_size |
2182 | @cindex @code{alloc_size} attribute | |
2183 | The @code{alloc_size} attribute is used to tell the compiler that the | |
2184 | function return value points to memory, where the size is given by | |
15b474a2 | 2185 | one or two of the functions parameters. GCC uses this |
4a29c97c | 2186 | information to improve the correctness of @code{__builtin_object_size}. |
2187 | ||
2188 | The function parameter(s) denoting the allocated size are specified by | |
2189 | one or two integer arguments supplied to the attribute. The allocated size | |
2190 | is either the value of the single function argument specified or the product | |
2191 | of the two function arguments specified. Argument numbering starts at | |
2192 | one. | |
2193 | ||
15b474a2 | 2194 | For instance, |
4a29c97c | 2195 | |
2196 | @smallexample | |
2197 | void* my_calloc(size_t, size_t) __attribute__((alloc_size(1,2))) | |
9d5b78d0 | 2198 | void my_realloc(void*, size_t) __attribute__((alloc_size(2))) |
4a29c97c | 2199 | @end smallexample |
2200 | ||
2201 | declares that my_calloc will return memory of the size given by | |
2202 | the product of parameter 1 and 2 and that my_realloc will return memory | |
2203 | of the size given by parameter 2. | |
2204 | ||
af87ad83 | 2205 | @item always_inline |
7c85682d | 2206 | @cindex @code{always_inline} function attribute |
af87ad83 | 2207 | Generally, functions are not inlined unless optimization is specified. |
2208 | For functions declared inline, this attribute inlines the function even | |
2209 | if no optimization level was specified. | |
2210 | ||
541e4101 | 2211 | @item gnu_inline |
2212 | @cindex @code{gnu_inline} function attribute | |
11950bdd | 2213 | This attribute should be used with a function which is also declared |
2214 | with the @code{inline} keyword. It directs GCC to treat the function | |
32f1f35b | 2215 | as if it were defined in gnu90 mode even when compiling in C99 or |
11950bdd | 2216 | gnu99 mode. |
2217 | ||
2218 | If the function is declared @code{extern}, then this definition of the | |
2219 | function is used only for inlining. In no case is the function | |
2220 | compiled as a standalone function, not even if you take its address | |
2221 | explicitly. Such an address becomes an external reference, as if you | |
2222 | had only declared the function, and had not defined it. This has | |
2223 | almost the effect of a macro. The way to use this is to put a | |
2224 | function definition in a header file with this attribute, and put | |
2225 | another copy of the function, without @code{extern}, in a library | |
2226 | file. The definition in the header file will cause most calls to the | |
2227 | function to be inlined. If any uses of the function remain, they will | |
2228 | refer to the single copy in the library. Note that the two | |
2229 | definitions of the functions need not be precisely the same, although | |
2230 | if they do not have the same effect your program may behave oddly. | |
2231 | ||
db577900 | 2232 | In C, if the function is neither @code{extern} nor @code{static}, then |
2233 | the function is compiled as a standalone function, as well as being | |
11950bdd | 2234 | inlined where possible. |
2235 | ||
2236 | This is how GCC traditionally handled functions declared | |
2237 | @code{inline}. Since ISO C99 specifies a different semantics for | |
2238 | @code{inline}, this function attribute is provided as a transition | |
2239 | measure and as a useful feature in its own right. This attribute is | |
2240 | available in GCC 4.1.3 and later. It is available if either of the | |
2241 | preprocessor macros @code{__GNUC_GNU_INLINE__} or | |
2242 | @code{__GNUC_STDC_INLINE__} are defined. @xref{Inline,,An Inline | |
2243 | Function is As Fast As a Macro}. | |
541e4101 | 2244 | |
db577900 | 2245 | In C++, this attribute does not depend on @code{extern} in any way, |
2246 | but it still requires the @code{inline} keyword to enable its special | |
2247 | behavior. | |
2248 | ||
1b16fc45 | 2249 | @item artificial |
c17add59 | 2250 | @cindex @code{artificial} function attribute |
1b16fc45 | 2251 | This attribute is useful for small inline wrappers which if possible |
2252 | should appear during debugging as a unit, depending on the debug | |
2253 | info format it will either mean marking the function as artificial | |
2254 | or using the caller location for all instructions within the inlined | |
2255 | body. | |
2256 | ||
cc24427c | 2257 | @item bank_switch |
2258 | @cindex interrupt handler functions | |
2259 | When added to an interrupt handler with the M32C port, causes the | |
2260 | prologue and epilogue to use bank switching to preserve the registers | |
2261 | rather than saving them on the stack. | |
2262 | ||
0cdd9887 | 2263 | @item flatten |
c17add59 | 2264 | @cindex @code{flatten} function attribute |
0cdd9887 | 2265 | Generally, inlining into a function is limited. For a function marked with |
2266 | this attribute, every call inside this function will be inlined, if possible. | |
2267 | Whether the function itself is considered for inlining depends on its size and | |
8188ae06 | 2268 | the current inlining parameters. |
0cdd9887 | 2269 | |
10fc867f | 2270 | @item error ("@var{message}") |
2271 | @cindex @code{error} function attribute | |
2272 | If this attribute is used on a function declaration and a call to such a function | |
2273 | is not eliminated through dead code elimination or other optimizations, an error | |
2274 | which will include @var{message} will be diagnosed. This is useful | |
2275 | for compile time checking, especially together with @code{__builtin_constant_p} | |
2276 | and inline functions where checking the inline function arguments is not | |
2277 | possible through @code{extern char [(condition) ? 1 : -1];} tricks. | |
2278 | While it is possible to leave the function undefined and thus invoke | |
2279 | a link failure, when using this attribute the problem will be diagnosed | |
2280 | earlier and with exact location of the call even in presence of inline | |
2281 | functions or when not emitting debugging information. | |
2282 | ||
2283 | @item warning ("@var{message}") | |
2284 | @cindex @code{warning} function attribute | |
2285 | If this attribute is used on a function declaration and a call to such a function | |
2286 | is not eliminated through dead code elimination or other optimizations, a warning | |
2287 | which will include @var{message} will be diagnosed. This is useful | |
2288 | for compile time checking, especially together with @code{__builtin_constant_p} | |
2289 | and inline functions. While it is possible to define the function with | |
2290 | a message in @code{.gnu.warning*} section, when using this attribute the problem | |
2291 | will be diagnosed earlier and with exact location of the call even in presence | |
2292 | of inline functions or when not emitting debugging information. | |
2293 | ||
7c85682d | 2294 | @item cdecl |
2295 | @cindex functions that do pop the argument stack on the 386 | |
2296 | @opindex mrtd | |
2297 | On the Intel 386, the @code{cdecl} attribute causes the compiler to | |
2298 | assume that the calling function will pop off the stack space used to | |
2299 | pass arguments. This is | |
2300 | useful to override the effects of the @option{-mrtd} switch. | |
26dfc457 | 2301 | |
26dfc457 | 2302 | @item const |
7c85682d | 2303 | @cindex @code{const} function attribute |
26dfc457 | 2304 | Many functions do not examine any values except their arguments, and |
2305 | have no effects except the return value. Basically this is just slightly | |
2abf0218 | 2306 | more strict class than the @code{pure} attribute below, since function is not |
1caefcbd | 2307 | allowed to read global memory. |
26dfc457 | 2308 | |
2309 | @cindex pointer arguments | |
2310 | Note that a function that has pointer arguments and examines the data | |
2311 | pointed to must @emph{not} be declared @code{const}. Likewise, a | |
2312 | function that calls a non-@code{const} function usually must not be | |
2313 | @code{const}. It does not make sense for a @code{const} function to | |
2314 | return @code{void}. | |
2315 | ||
37744367 | 2316 | The attribute @code{const} is not implemented in GCC versions earlier |
146ef39f | 2317 | than 2.5. An alternative way to declare that a function has no side |
2318 | effects, which works in the current version and in some older versions, | |
2319 | is as follows: | |
2320 | ||
2321 | @smallexample | |
2322 | typedef int intfn (); | |
2323 | ||
2324 | extern const intfn square; | |
2325 | @end smallexample | |
2326 | ||
2327 | This approach does not work in GNU C++ from 2.6.0 on, since the language | |
2328 | specifies that the @samp{const} must be attached to the return value. | |
2329 | ||
7c85682d | 2330 | @item constructor |
2331 | @itemx destructor | |
9af7fd5b | 2332 | @itemx constructor (@var{priority}) |
2333 | @itemx destructor (@var{priority}) | |
7c85682d | 2334 | @cindex @code{constructor} function attribute |
2335 | @cindex @code{destructor} function attribute | |
2336 | The @code{constructor} attribute causes the function to be called | |
2337 | automatically before execution enters @code{main ()}. Similarly, the | |
2338 | @code{destructor} attribute causes the function to be called | |
2339 | automatically after @code{main ()} has completed or @code{exit ()} has | |
2340 | been called. Functions with these attributes are useful for | |
2341 | initializing data that will be used implicitly during the execution of | |
2342 | the program. | |
2343 | ||
9af7fd5b | 2344 | You may provide an optional integer priority to control the order in |
2345 | which constructor and destructor functions are run. A constructor | |
2346 | with a smaller priority number runs before a constructor with a larger | |
2347 | priority number; the opposite relationship holds for destructors. So, | |
2348 | if you have a constructor that allocates a resource and a destructor | |
2349 | that deallocates the same resource, both functions typically have the | |
2350 | same priority. The priorities for constructor and destructor | |
2351 | functions are the same as those specified for namespace-scope C++ | |
2352 | objects (@pxref{C++ Attributes}). | |
2353 | ||
7c85682d | 2354 | These attributes are not currently implemented for Objective-C@. |
2355 | ||
2356 | @item deprecated | |
45c4e798 | 2357 | @itemx deprecated (@var{msg}) |
7c85682d | 2358 | @cindex @code{deprecated} attribute. |
2359 | The @code{deprecated} attribute results in a warning if the function | |
2360 | is used anywhere in the source file. This is useful when identifying | |
2361 | functions that are expected to be removed in a future version of a | |
2362 | program. The warning also includes the location of the declaration | |
2363 | of the deprecated function, to enable users to easily find further | |
2364 | information about why the function is deprecated, or what they should | |
2365 | do instead. Note that the warnings only occurs for uses: | |
2366 | ||
2367 | @smallexample | |
2368 | int old_fn () __attribute__ ((deprecated)); | |
2369 | int old_fn (); | |
2370 | int (*fn_ptr)() = old_fn; | |
2371 | @end smallexample | |
2372 | ||
45c4e798 | 2373 | results in a warning on line 3 but not line 2. The optional msg |
2374 | argument, which must be a string, will be printed in the warning if | |
2375 | present. | |
7c85682d | 2376 | |
2377 | The @code{deprecated} attribute can also be used for variables and | |
2378 | types (@pxref{Variable Attributes}, @pxref{Type Attributes}.) | |
2379 | ||
7c3116fb | 2380 | @item disinterrupt |
2381 | @cindex @code{disinterrupt} attribute | |
d19f5793 | 2382 | On Epiphany and MeP targets, this attribute causes the compiler to emit |
7c3116fb | 2383 | instructions to disable interrupts for the duration of the given |
2384 | function. | |
2385 | ||
7c85682d | 2386 | @item dllexport |
2387 | @cindex @code{__declspec(dllexport)} | |
3aa0c315 | 2388 | On Microsoft Windows targets and Symbian OS targets the |
2389 | @code{dllexport} attribute causes the compiler to provide a global | |
2390 | pointer to a pointer in a DLL, so that it can be referenced with the | |
2391 | @code{dllimport} attribute. On Microsoft Windows targets, the pointer | |
2392 | name is formed by combining @code{_imp__} and the function or variable | |
2393 | name. | |
2394 | ||
2395 | You can use @code{__declspec(dllexport)} as a synonym for | |
2396 | @code{__attribute__ ((dllexport))} for compatibility with other | |
2397 | compilers. | |
2398 | ||
2399 | On systems that support the @code{visibility} attribute, this | |
098a01e7 | 2400 | attribute also implies ``default'' visibility. It is an error to |
2401 | explicitly specify any other visibility. | |
7c85682d | 2402 | |
15b474a2 | 2403 | In previous versions of GCC, the @code{dllexport} attribute was ignored |
0675168d | 2404 | for inlined functions, unless the @option{-fkeep-inline-functions} flag |
2405 | had been used. The default behaviour now is to emit all dllexported | |
2406 | inline functions; however, this can cause object file-size bloat, in | |
2407 | which case the old behaviour can be restored by using | |
2408 | @option{-fno-keep-inline-dllexport}. | |
2409 | ||
2410 | The attribute is also ignored for undefined symbols. | |
7c85682d | 2411 | |
b3d47662 | 2412 | When applied to C++ classes, the attribute marks defined non-inlined |
2413 | member functions and static data members as exports. Static consts | |
7c85682d | 2414 | initialized in-class are not marked unless they are also defined |
2415 | out-of-class. | |
2416 | ||
db281f5a | 2417 | For Microsoft Windows targets there are alternative methods for |
3aa0c315 | 2418 | including the symbol in the DLL's export table such as using a |
db281f5a | 2419 | @file{.def} file with an @code{EXPORTS} section or, with GNU ld, using |
2420 | the @option{--export-all} linker flag. | |
7c85682d | 2421 | |
2422 | @item dllimport | |
2423 | @cindex @code{__declspec(dllimport)} | |
3aa0c315 | 2424 | On Microsoft Windows and Symbian OS targets, the @code{dllimport} |
db281f5a | 2425 | attribute causes the compiler to reference a function or variable via |
3aa0c315 | 2426 | a global pointer to a pointer that is set up by the DLL exporting the |
098a01e7 | 2427 | symbol. The attribute implies @code{extern}. On Microsoft Windows |
2428 | targets, the pointer name is formed by combining @code{_imp__} and the | |
2429 | function or variable name. | |
3aa0c315 | 2430 | |
2431 | You can use @code{__declspec(dllimport)} as a synonym for | |
2432 | @code{__attribute__ ((dllimport))} for compatibility with other | |
2433 | compilers. | |
7c85682d | 2434 | |
098a01e7 | 2435 | On systems that support the @code{visibility} attribute, this |
2436 | attribute also implies ``default'' visibility. It is an error to | |
2437 | explicitly specify any other visibility. | |
2438 | ||
b3d47662 | 2439 | Currently, the attribute is ignored for inlined functions. If the |
7c85682d | 2440 | attribute is applied to a symbol @emph{definition}, an error is reported. |
2441 | If a symbol previously declared @code{dllimport} is later defined, the | |
2442 | attribute is ignored in subsequent references, and a warning is emitted. | |
2443 | The attribute is also overridden by a subsequent declaration as | |
2444 | @code{dllexport}. | |
2445 | ||
2446 | When applied to C++ classes, the attribute marks non-inlined | |
2447 | member functions and static data members as imports. However, the | |
2448 | attribute is ignored for virtual methods to allow creation of vtables | |
2449 | using thunks. | |
2450 | ||
3aa0c315 | 2451 | On the SH Symbian OS target the @code{dllimport} attribute also has |
01e3cadf | 2452 | another affect---it can cause the vtable and run-time type information |
3aa0c315 | 2453 | for a class to be exported. This happens when the class has a |
2454 | dllimport'ed constructor or a non-inline, non-pure virtual function | |
68576faf | 2455 | and, for either of those two conditions, the class also has an inline |
3aa0c315 | 2456 | constructor or destructor and has a key function that is defined in |
2457 | the current translation unit. | |
db281f5a | 2458 | |
2459 | For Microsoft Windows based targets the use of the @code{dllimport} | |
2460 | attribute on functions is not necessary, but provides a small | |
b3d47662 | 2461 | performance benefit by eliminating a thunk in the DLL@. The use of the |
db281f5a | 2462 | @code{dllimport} attribute on imported variables was required on older |
3aa0c315 | 2463 | versions of the GNU linker, but can now be avoided by passing the |
b3d47662 | 2464 | @option{--enable-auto-import} switch to the GNU linker. As with |
3aa0c315 | 2465 | functions, using the attribute for a variable eliminates a thunk in |
b3d47662 | 2466 | the DLL@. |
3aa0c315 | 2467 | |
7e6a4e8b | 2468 | One drawback to using this attribute is that a pointer to a |
2469 | @emph{variable} marked as @code{dllimport} cannot be used as a constant | |
2470 | address. However, a pointer to a @emph{function} with the | |
2471 | @code{dllimport} attribute can be used as a constant initializer; in | |
2472 | this case, the address of a stub function in the import lib is | |
2473 | referenced. On Microsoft Windows targets, the attribute can be disabled | |
3aa0c315 | 2474 | for functions by setting the @option{-mnop-fun-dllimport} flag. |
7c85682d | 2475 | |
2476 | @item eightbit_data | |
2477 | @cindex eight bit data on the H8/300, H8/300H, and H8S | |
2478 | Use this attribute on the H8/300, H8/300H, and H8S to indicate that the specified | |
2479 | variable should be placed into the eight bit data section. | |
2480 | The compiler will generate more efficient code for certain operations | |
2481 | on data in the eight bit data area. Note the eight bit data area is limited to | |
2482 | 256 bytes of data. | |
2483 | ||
2484 | You must use GAS and GLD from GNU binutils version 2.7 or later for | |
2485 | this attribute to work correctly. | |
2486 | ||
9e6a0967 | 2487 | @item exception_handler |
2488 | @cindex exception handler functions on the Blackfin processor | |
2489 | Use this attribute on the Blackfin to indicate that the specified function | |
2490 | is an exception handler. The compiler will generate function entry and | |
2491 | exit sequences suitable for use in an exception handler when this | |
2492 | attribute is present. | |
2493 | ||
c17add59 | 2494 | @item externally_visible |
2495 | @cindex @code{externally_visible} attribute. | |
2496 | This attribute, attached to a global variable or function, nullifies | |
2497 | the effect of the @option{-fwhole-program} command-line option, so the | |
61a3c321 | 2498 | object remains visible outside the current compilation unit. If @option{-fwhole-program} is used together with @option{-flto} and @command{gold} is used as the linker plugin, @code{externally_visible} attributes are automatically added to functions (not variable yet due to a current @command{gold} issue) that are accessed outside of LTO objects according to resolution file produced by @command{gold}. For other linkers that cannot generate resolution file, explicit @code{externally_visible} attributes are still necessary. |
c17add59 | 2499 | |
7c85682d | 2500 | @item far |
2501 | @cindex functions which handle memory bank switching | |
2502 | On 68HC11 and 68HC12 the @code{far} attribute causes the compiler to | |
2503 | use a calling convention that takes care of switching memory banks when | |
2504 | entering and leaving a function. This calling convention is also the | |
2505 | default when using the @option{-mlong-calls} option. | |
2506 | ||
2507 | On 68HC12 the compiler will use the @code{call} and @code{rtc} instructions | |
2508 | to call and return from a function. | |
2509 | ||
2510 | On 68HC11 the compiler will generate a sequence of instructions | |
2511 | to invoke a board-specific routine to switch the memory bank and call the | |
b3d47662 | 2512 | real function. The board-specific routine simulates a @code{call}. |
7c85682d | 2513 | At the end of a function, it will jump to a board-specific routine |
b3d47662 | 2514 | instead of using @code{rts}. The board-specific return routine simulates |
7c85682d | 2515 | the @code{rtc}. |
2516 | ||
7c3116fb | 2517 | On MeP targets this causes the compiler to use a calling convention |
2518 | which assumes the called function is too far away for the built-in | |
2519 | addressing modes. | |
2520 | ||
cc24427c | 2521 | @item fast_interrupt |
2522 | @cindex interrupt handler functions | |
24833e1a | 2523 | Use this attribute on the M32C and RX ports to indicate that the specified |
cc24427c | 2524 | function is a fast interrupt handler. This is just like the |
2525 | @code{interrupt} attribute, except that @code{freit} is used to return | |
2526 | instead of @code{reit}. | |
2527 | ||
7c85682d | 2528 | @item fastcall |
2529 | @cindex functions that pop the argument stack on the 386 | |
2530 | On the Intel 386, the @code{fastcall} attribute causes the compiler to | |
3524624e | 2531 | pass the first argument (if of integral type) in the register ECX and |
2532 | the second argument (if of integral type) in the register EDX@. Subsequent | |
2533 | and other typed arguments are passed on the stack. The called function will | |
2534 | pop the arguments off the stack. If the number of arguments is variable all | |
7c85682d | 2535 | arguments are pushed on the stack. |
146ef39f | 2536 | |
538adab1 | 2537 | @item thiscall |
2538 | @cindex functions that pop the argument stack on the 386 | |
2539 | On the Intel 386, the @code{thiscall} attribute causes the compiler to | |
2540 | pass the first argument (if of integral type) in the register ECX. | |
2541 | Subsequent and other typed arguments are passed on the stack. The called | |
2542 | function will pop the arguments off the stack. | |
2543 | If the number of arguments is variable all arguments are pushed on the | |
2544 | stack. | |
2545 | The @code{thiscall} attribute is intended for C++ non-static member functions. | |
2546 | As gcc extension this calling convention can be used for C-functions | |
2547 | and for static member methods. | |
2548 | ||
146ef39f | 2549 | @item format (@var{archetype}, @var{string-index}, @var{first-to-check}) |
2550 | @cindex @code{format} function attribute | |
67791935 | 2551 | @opindex Wformat |
d1f11193 | 2552 | The @code{format} attribute specifies that a function takes @code{printf}, |
6a87209c | 2553 | @code{scanf}, @code{strftime} or @code{strfmon} style arguments which |
2554 | should be type-checked against a format string. For example, the | |
2555 | declaration: | |
146ef39f | 2556 | |
2557 | @smallexample | |
2558 | extern int | |
2559 | my_printf (void *my_object, const char *my_format, ...) | |
2560 | __attribute__ ((format (printf, 2, 3))); | |
2561 | @end smallexample | |
2562 | ||
2563 | @noindent | |
2564 | causes the compiler to check the arguments in calls to @code{my_printf} | |
2565 | for consistency with the @code{printf} style format string argument | |
2566 | @code{my_format}. | |
2567 | ||
2568 | The parameter @var{archetype} determines how the format string is | |
635c5a98 | 2569 | interpreted, and should be @code{printf}, @code{scanf}, @code{strftime}, |
2570 | @code{gnu_printf}, @code{gnu_scanf}, @code{gnu_strftime} or | |
2571 | @code{strfmon}. (You can also use @code{__printf__}, | |
2572 | @code{__scanf__}, @code{__strftime__} or @code{__strfmon__}.) On | |
2573 | MinGW targets, @code{ms_printf}, @code{ms_scanf}, and | |
2574 | @code{ms_strftime} are also present. | |
2575 | @var{archtype} values such as @code{printf} refer to the formats accepted | |
2576 | by the system's C run-time library, while @code{gnu_} values always refer | |
2577 | to the formats accepted by the GNU C Library. On Microsoft Windows | |
2578 | targets, @code{ms_} values refer to the formats accepted by the | |
2579 | @file{msvcrt.dll} library. | |
2580 | The parameter @var{string-index} | |
2581 | specifies which argument is the format string argument (starting | |
2582 | from 1), while @var{first-to-check} is the number of the first | |
2583 | argument to check against the format string. For functions | |
2584 | where the arguments are not available to be checked (such as | |
146ef39f | 2585 | @code{vprintf}), specify the third parameter as zero. In this case the |
0f502901 | 2586 | compiler only checks the format string for consistency. For |
2587 | @code{strftime} formats, the third parameter is required to be zero. | |
6b4b1c7b | 2588 | Since non-static C++ methods have an implicit @code{this} argument, the |
2589 | arguments of such methods should be counted from two, not one, when | |
2590 | giving values for @var{string-index} and @var{first-to-check}. | |
146ef39f | 2591 | |
2592 | In the example above, the format string (@code{my_format}) is the second | |
2593 | argument of the function @code{my_print}, and the arguments to check | |
2594 | start with the third argument, so the correct parameters for the format | |
2595 | attribute are 2 and 3. | |
2596 | ||
67791935 | 2597 | @opindex ffreestanding |
67933247 | 2598 | @opindex fno-builtin |
146ef39f | 2599 | The @code{format} attribute allows you to identify your own functions |
37744367 | 2600 | which take format strings as arguments, so that GCC can check the |
0f502901 | 2601 | calls to these functions for errors. The compiler always (unless |
67933247 | 2602 | @option{-ffreestanding} or @option{-fno-builtin} is used) checks formats |
0f502901 | 2603 | for the standard library functions @code{printf}, @code{fprintf}, |
d1f11193 | 2604 | @code{sprintf}, @code{scanf}, @code{fscanf}, @code{sscanf}, @code{strftime}, |
146ef39f | 2605 | @code{vprintf}, @code{vfprintf} and @code{vsprintf} whenever such |
67791935 | 2606 | warnings are requested (using @option{-Wformat}), so there is no need to |
0f502901 | 2607 | modify the header file @file{stdio.h}. In C99 mode, the functions |
2608 | @code{snprintf}, @code{vsnprintf}, @code{vscanf}, @code{vfscanf} and | |
6a87209c | 2609 | @code{vsscanf} are also checked. Except in strictly conforming C |
c013a46e | 2610 | standard modes, the X/Open function @code{strfmon} is also checked as |
2611 | are @code{printf_unlocked} and @code{fprintf_unlocked}. | |
0f502901 | 2612 | @xref{C Dialect Options,,Options Controlling C Dialect}. |
146ef39f | 2613 | |
15b474a2 | 2614 | For Objective-C dialects, @code{NSString} (or @code{__NSString__}) is |
1f6616ee | 2615 | recognized in the same context. Declarations including these format attributes |
2616 | will be parsed for correct syntax, however the result of checking of such format | |
15b474a2 | 2617 | strings is not yet defined, and will not be carried out by this version of the |
1f6616ee | 2618 | compiler. |
2619 | ||
2620 | The target may also provide additional types of format checks. | |
1e9af880 | 2621 | @xref{Target Format Checks,,Format Checks Specific to Particular |
2622 | Target Machines}. | |
2623 | ||
146ef39f | 2624 | @item format_arg (@var{string-index}) |
2625 | @cindex @code{format_arg} function attribute | |
67791935 | 2626 | @opindex Wformat-nonliteral |
6a87209c | 2627 | The @code{format_arg} attribute specifies that a function takes a format |
2628 | string for a @code{printf}, @code{scanf}, @code{strftime} or | |
2629 | @code{strfmon} style function and modifies it (for example, to translate | |
2630 | it into another language), so the result can be passed to a | |
2631 | @code{printf}, @code{scanf}, @code{strftime} or @code{strfmon} style | |
2632 | function (with the remaining arguments to the format function the same | |
2633 | as they would have been for the unmodified string). For example, the | |
2634 | declaration: | |
146ef39f | 2635 | |
2636 | @smallexample | |
2637 | extern char * | |
2638 | my_dgettext (char *my_domain, const char *my_format) | |
2639 | __attribute__ ((format_arg (2))); | |
2640 | @end smallexample | |
2641 | ||
2642 | @noindent | |
6a87209c | 2643 | causes the compiler to check the arguments in calls to a @code{printf}, |
2644 | @code{scanf}, @code{strftime} or @code{strfmon} type function, whose | |
2645 | format string argument is a call to the @code{my_dgettext} function, for | |
2646 | consistency with the format string argument @code{my_format}. If the | |
2647 | @code{format_arg} attribute had not been specified, all the compiler | |
2648 | could tell in such calls to format functions would be that the format | |
2649 | string argument is not constant; this would generate a warning when | |
67791935 | 2650 | @option{-Wformat-nonliteral} is used, but the calls could not be checked |
6a87209c | 2651 | without the attribute. |
146ef39f | 2652 | |
2653 | The parameter @var{string-index} specifies which argument is the format | |
6b4b1c7b | 2654 | string argument (starting from one). Since non-static C++ methods have |
2655 | an implicit @code{this} argument, the arguments of such methods should | |
2656 | be counted from two. | |
146ef39f | 2657 | |
2658 | The @code{format-arg} attribute allows you to identify your own | |
37744367 | 2659 | functions which modify format strings, so that GCC can check the |
6a87209c | 2660 | calls to @code{printf}, @code{scanf}, @code{strftime} or @code{strfmon} |
2661 | type function whose operands are a call to one of your own function. | |
2662 | The compiler always treats @code{gettext}, @code{dgettext}, and | |
2663 | @code{dcgettext} in this manner except when strict ISO C support is | |
67791935 | 2664 | requested by @option{-ansi} or an appropriate @option{-std} option, or |
67933247 | 2665 | @option{-ffreestanding} or @option{-fno-builtin} |
2666 | is used. @xref{C Dialect Options,,Options | |
6a87209c | 2667 | Controlling C Dialect}. |
146ef39f | 2668 | |
1f6616ee | 2669 | For Objective-C dialects, the @code{format-arg} attribute may refer to an |
2670 | @code{NSString} reference for compatibility with the @code{format} attribute | |
2671 | above. | |
2672 | ||
2673 | The target may also allow additional types in @code{format-arg} attributes. | |
2674 | @xref{Target Format Checks,,Format Checks Specific to Particular | |
2675 | Target Machines}. | |
2676 | ||
7c85682d | 2677 | @item function_vector |
5241f4ad | 2678 | @cindex calling functions through the function vector on H8/300, M16C, M32C and SH2A processors |
7c85682d | 2679 | Use this attribute on the H8/300, H8/300H, and H8S to indicate that the specified |
2680 | function should be called through the function vector. Calling a | |
2681 | function through the function vector will reduce code size, however; | |
2682 | the function vector has a limited size (maximum 128 entries on the H8/300 | |
2683 | and 64 entries on the H8/300H and H8S) and shares space with the interrupt vector. | |
dbf6c367 | 2684 | |
5241f4ad | 2685 | In SH2A target, this attribute declares a function to be called using the |
2686 | TBR relative addressing mode. The argument to this attribute is the entry | |
2687 | number of the same function in a vector table containing all the TBR | |
2688 | relative addressable functions. For the successful jump, register TBR | |
2689 | should contain the start address of this TBR relative vector table. | |
2690 | In the startup routine of the user application, user needs to care of this | |
2691 | TBR register initialization. The TBR relative vector table can have at | |
2692 | max 256 function entries. The jumps to these functions will be generated | |
2693 | using a SH2A specific, non delayed branch instruction JSR/N @@(disp8,TBR). | |
7c85682d | 2694 | You must use GAS and GLD from GNU binutils version 2.7 or later for |
2695 | this attribute to work correctly. | |
dbf6c367 | 2696 | |
5241f4ad | 2697 | Please refer the example of M16C target, to see the use of this |
2698 | attribute while declaring a function, | |
2699 | ||
2700 | In an application, for a function being called once, this attribute will | |
2701 | save at least 8 bytes of code; and if other successive calls are being | |
2702 | made to the same function, it will save 2 bytes of code per each of these | |
2703 | calls. | |
2704 | ||
2efce110 | 2705 | On M16C/M32C targets, the @code{function_vector} attribute declares a |
2706 | special page subroutine call function. Use of this attribute reduces | |
2707 | the code size by 2 bytes for each call generated to the | |
2708 | subroutine. The argument to the attribute is the vector number entry | |
2709 | from the special page vector table which contains the 16 low-order | |
2710 | bits of the subroutine's entry address. Each vector table has special | |
2711 | page number (18 to 255) which are used in @code{jsrs} instruction. | |
2712 | Jump addresses of the routines are generated by adding 0x0F0000 (in | |
2713 | case of M16C targets) or 0xFF0000 (in case of M32C targets), to the 2 | |
2714 | byte addresses set in the vector table. Therefore you need to ensure | |
2715 | that all the special page vector routines should get mapped within the | |
2716 | address range 0x0F0000 to 0x0FFFFF (for M16C) and 0xFF0000 to 0xFFFFFF | |
2717 | (for M32C). | |
2718 | ||
2719 | In the following example 2 bytes will be saved for each call to | |
2720 | function @code{foo}. | |
2721 | ||
2722 | @smallexample | |
2723 | void foo (void) __attribute__((function_vector(0x18))); | |
2724 | void foo (void) | |
2725 | @{ | |
2726 | @} | |
2727 | ||
2728 | void bar (void) | |
2729 | @{ | |
2730 | foo(); | |
2731 | @} | |
2732 | @end smallexample | |
2733 | ||
2734 | If functions are defined in one file and are called in another file, | |
2735 | then be sure to write this declaration in both files. | |
2736 | ||
2737 | This attribute is ignored for R8C target. | |
2738 | ||
ea679361 | 2739 | @item ifunc ("@var{resolver}") |
2740 | @cindex @code{ifunc} attribute | |
2741 | The @code{ifunc} attribute is used to mark a function as an indirect | |
2742 | function using the STT_GNU_IFUNC symbol type extension to the ELF | |
2743 | standard. This allows the resolution of the symbol value to be | |
2744 | determined dynamically at load time, and an optimized version of the | |
2745 | routine can be selected for the particular processor or other system | |
2746 | characteristics determined then. To use this attribute, first define | |
2747 | the implementation functions available, and a resolver function that | |
2748 | returns a pointer to the selected implementation function. The | |
2749 | implementation functions' declarations must match the API of the | |
2750 | function being implemented, the resolver's declaration is be a | |
2751 | function returning pointer to void function returning void: | |
2752 | ||
2753 | @smallexample | |
2754 | void *my_memcpy (void *dst, const void *src, size_t len) | |
2755 | @{ | |
2756 | @dots{} | |
2757 | @} | |
2758 | ||
2759 | static void (*resolve_memcpy (void)) (void) | |
2760 | @{ | |
2761 | return my_memcpy; // we'll just always select this routine | |
2762 | @} | |
2763 | @end smallexample | |
2764 | ||
2765 | The exported header file declaring the function the user calls would | |
2766 | contain: | |
2767 | ||
2768 | @smallexample | |
2769 | extern void *memcpy (void *, const void *, size_t); | |
2770 | @end smallexample | |
2771 | ||
2772 | allowing the user to call this as a regular function, unaware of the | |
2773 | implementation. Finally, the indirect function needs to be defined in | |
2774 | the same translation unit as the resolver function: | |
2775 | ||
2776 | @smallexample | |
2777 | void *memcpy (void *, const void *, size_t) | |
2778 | __attribute__ ((ifunc ("resolve_memcpy"))); | |
2779 | @end smallexample | |
2780 | ||
2781 | Indirect functions cannot be weak, and require a recent binutils (at | |
2782 | least version 2.20.1), and GNU C library (at least version 2.11.1). | |
2783 | ||
7c85682d | 2784 | @item interrupt |
2785 | @cindex interrupt handler functions | |
b9fdd12b | 2786 | Use this attribute on the ARM, AVR, CR16, Epiphany, M32C, M32R/D, m68k, MeP, MIPS, |
78e515f7 | 2787 | RL78, RX and Xstormy16 ports to indicate that the specified function is an |
29968436 | 2788 | interrupt handler. The compiler will generate function entry and exit |
2789 | sequences suitable for use in an interrupt handler when this attribute | |
43770c4d | 2790 | is present. With Epiphany targets it may also generate a special section with |
2791 | code to initialize the interrupt vector table. | |
dbf6c367 | 2792 | |
d34b0d1e | 2793 | Note, interrupt handlers for the Blackfin, H8/300, H8/300H, H8S, MicroBlaze, |
2794 | and SH processors can be specified via the @code{interrupt_handler} attribute. | |
dbf6c367 | 2795 | |
ea679361 | 2796 | Note, on the AVR, the hardware globally disables interrupts when an |
2797 | interrupt is executed. The first instruction of an interrupt handler | |
2798 | declared with this attribute will be a @code{SEI} instruction to | |
2799 | re-enable interrupts. See also the @code{signal} function attribute | |
2800 | that does not insert a @code{SEI} instuction. If both @code{signal} and | |
2801 | @code{interrupt} are specified for the same function, @code{signal} | |
2802 | will be silently ignored. | |
93f10b04 | 2803 | |
7c85682d | 2804 | Note, for the ARM, you can specify the kind of interrupt to be handled by |
2805 | adding an optional parameter to the interrupt attribute like this: | |
88da234d | 2806 | |
2807 | @smallexample | |
7c85682d | 2808 | void f () __attribute__ ((interrupt ("IRQ"))); |
88da234d | 2809 | @end smallexample |
2810 | ||
7c85682d | 2811 | Permissible values for this parameter are: IRQ, FIQ, SWI, ABORT and UNDEF@. |
88da234d | 2812 | |
542d5028 | 2813 | On ARMv7-M the interrupt type is ignored, and the attribute means the function |
25f905c2 | 2814 | may be called with a word aligned stack pointer. |
2815 | ||
43770c4d | 2816 | On Epiphany targets one or more optional parameters can be added like this: |
2817 | ||
2818 | @smallexample | |
2819 | void __attribute__ ((interrupt ("dma0, dma1"))) universal_dma_handler (); | |
2820 | @end smallexample | |
2821 | ||
2822 | Permissible values for these parameters are: @w{@code{reset}}, | |
2823 | @w{@code{software_exception}}, @w{@code{page_miss}}, | |
2824 | @w{@code{timer0}}, @w{@code{timer1}}, @w{@code{message}}, | |
2825 | @w{@code{dma0}}, @w{@code{dma1}}, @w{@code{wand}} and @w{@code{swi}}. | |
2826 | Multiple parameters indicate that multiple entries in the interrupt | |
2827 | vector table should be initialized for this function, i.e. for each | |
2828 | parameter @w{@var{name}}, a jump to the function will be emitted in | |
2829 | the section @w{ivt_entry_@var{name}}. The parameter(s) may be omitted | |
2830 | entirely, in which case no interrupt vector table entry will be provided. | |
2831 | ||
2832 | Note, on Epiphany targets, interrupts are enabled inside the function | |
2833 | unless the @code{disinterrupt} attribute is also specified. | |
2834 | ||
2835 | On Epiphany targets, you can also use the following attribute to | |
2836 | modify the behavior of an interrupt handler: | |
2837 | @table @code | |
2838 | @item forwarder_section | |
2839 | @cindex @code{forwarder_section} attribute | |
2840 | The interrupt handler may be in external memory which cannot be | |
2841 | reached by a branch instruction, so generate a local memory trampoline | |
2842 | to transfer control. The single parameter identifies the section where | |
2843 | the trampoline will be placed. | |
2844 | @end table | |
2845 | ||
2846 | The following examples are all valid uses of these attributes on | |
2847 | Epiphany targets: | |
2848 | @smallexample | |
2849 | void __attribute__ ((interrupt)) universal_handler (); | |
2850 | void __attribute__ ((interrupt ("dma1"))) dma1_handler (); | |
2851 | void __attribute__ ((interrupt ("dma0, dma1"))) universal_dma_handler (); | |
2852 | void __attribute__ ((interrupt ("timer0"), disinterrupt)) | |
2853 | fast_timer_handler (); | |
2854 | void __attribute__ ((interrupt ("dma0, dma1"), forwarder_section ("tramp"))) | |
2855 | external_dma_handler (); | |
2856 | @end smallexample | |
2857 | ||
0bfaf4c4 | 2858 | On MIPS targets, you can use the following attributes to modify the behavior |
2859 | of an interrupt handler: | |
2860 | @table @code | |
2861 | @item use_shadow_register_set | |
2862 | @cindex @code{use_shadow_register_set} attribute | |
2863 | Assume that the handler uses a shadow register set, instead of | |
2864 | the main general-purpose registers. | |
2865 | ||
2866 | @item keep_interrupts_masked | |
2867 | @cindex @code{keep_interrupts_masked} attribute | |
2868 | Keep interrupts masked for the whole function. Without this attribute, | |
2869 | GCC tries to reenable interrupts for as much of the function as it can. | |
2870 | ||
2871 | @item use_debug_exception_return | |
2872 | @cindex @code{use_debug_exception_return} attribute | |
2873 | Return using the @code{deret} instruction. Interrupt handlers that don't | |
2874 | have this attribute return using @code{eret} instead. | |
2875 | @end table | |
2876 | ||
2877 | You can use any combination of these attributes, as shown below: | |
2878 | @smallexample | |
2879 | void __attribute__ ((interrupt)) v0 (); | |
2880 | void __attribute__ ((interrupt, use_shadow_register_set)) v1 (); | |
2881 | void __attribute__ ((interrupt, keep_interrupts_masked)) v2 (); | |
2882 | void __attribute__ ((interrupt, use_debug_exception_return)) v3 (); | |
2883 | void __attribute__ ((interrupt, use_shadow_register_set, | |
910faa40 | 2884 | keep_interrupts_masked)) v4 (); |
0bfaf4c4 | 2885 | void __attribute__ ((interrupt, use_shadow_register_set, |
910faa40 | 2886 | use_debug_exception_return)) v5 (); |
0bfaf4c4 | 2887 | void __attribute__ ((interrupt, keep_interrupts_masked, |
910faa40 | 2888 | use_debug_exception_return)) v6 (); |
0bfaf4c4 | 2889 | void __attribute__ ((interrupt, use_shadow_register_set, |
910faa40 | 2890 | keep_interrupts_masked, |
2891 | use_debug_exception_return)) v7 (); | |
0bfaf4c4 | 2892 | @end smallexample |
2893 | ||
78e515f7 | 2894 | On RL78, use @code{brk_interrupt} instead of @code{interrupt} for |
2895 | handlers intended to be used with the @code{BRK} opcode (i.e. those | |
2896 | that must end with @code{RETB} instead of @code{RETI}). | |
2897 | ||
7c85682d | 2898 | @item interrupt_handler |
9e6a0967 | 2899 | @cindex interrupt handler functions on the Blackfin, m68k, H8/300 and SH processors |
2900 | Use this attribute on the Blackfin, m68k, H8/300, H8/300H, H8S, and SH to | |
2901 | indicate that the specified function is an interrupt handler. The compiler | |
2902 | will generate function entry and exit sequences suitable for use in an | |
2903 | interrupt handler when this attribute is present. | |
2904 | ||
f9a44575 | 2905 | @item interrupt_thread |
2906 | @cindex interrupt thread functions on fido | |
2907 | Use this attribute on fido, a subarchitecture of the m68k, to indicate | |
2908 | that the specified function is an interrupt handler that is designed | |
2909 | to run as a thread. The compiler omits generate prologue/epilogue | |
2910 | sequences and replaces the return instruction with a @code{sleep} | |
2911 | instruction. This attribute is available only on fido. | |
2912 | ||
1fe1c6f5 | 2913 | @item isr |
2914 | @cindex interrupt service routines on ARM | |
2915 | Use this attribute on ARM to write Interrupt Service Routines. This is an | |
2916 | alias to the @code{interrupt} attribute above. | |
2917 | ||
9e6a0967 | 2918 | @item kspisusp |
2919 | @cindex User stack pointer in interrupts on the Blackfin | |
2920 | When used together with @code{interrupt_handler}, @code{exception_handler} | |
2921 | or @code{nmi_handler}, code will be generated to load the stack pointer | |
2922 | from the USP register in the function prologue. | |
8a8cdb8d | 2923 | |
fc8aef7f | 2924 | @item l1_text |
2925 | @cindex @code{l1_text} function attribute | |
2926 | This attribute specifies a function to be placed into L1 Instruction | |
a81d4cba | 2927 | SRAM@. The function will be put into a specific section named @code{.l1.text}. |
fc8aef7f | 2928 | With @option{-mfdpic}, function calls with a such function as the callee |
2929 | or caller will use inlined PLT. | |
2930 | ||
59fbccf3 | 2931 | @item l2 |
2932 | @cindex @code{l2} function attribute | |
2933 | On the Blackfin, this attribute specifies a function to be placed into L2 | |
2934 | SRAM. The function will be put into a specific section named | |
2935 | @code{.l1.text}. With @option{-mfdpic}, callers of such functions will use | |
2936 | an inlined PLT. | |
2937 | ||
7bd95dfd | 2938 | @item leaf |
2939 | @cindex @code{leaf} function attribute | |
2940 | Calls to external functions with this attribute must return to the current | |
b59688ee | 2941 | compilation unit only by return or by exception handling. In particular, leaf |
2942 | functions are not allowed to call callback function passed to it from the current | |
7bd95dfd | 2943 | compilation unit or directly call functions exported by the unit or longjmp |
b59688ee | 2944 | into the unit. Leaf function might still call functions from other compilation |
2945 | units and thus they are not necessarily leaf in the sense that they contain no | |
7bd95dfd | 2946 | function calls at all. |
2947 | ||
2948 | The attribute is intended for library functions to improve dataflow analysis. | |
b59688ee | 2949 | The compiler takes the hint that any data not escaping the current compilation unit can |
2950 | not be used or modified by the leaf function. For example, the @code{sin} function | |
2951 | is a leaf function, but @code{qsort} is not. | |
7bd95dfd | 2952 | |
b59688ee | 2953 | Note that leaf functions might invoke signals and signal handlers might be |
2954 | defined in the current compilation unit and use static variables. The only | |
7bd95dfd | 2955 | compliant way to write such a signal handler is to declare such variables |
2956 | @code{volatile}. | |
2957 | ||
b59688ee | 2958 | The attribute has no effect on functions defined within the current compilation |
7bd95dfd | 2959 | unit. This is to allow easy merging of multiple compilation units into one, |
2960 | for example, by using the link time optimization. For this reason the | |
2961 | attribute is not allowed on types to annotate indirect calls. | |
2962 | ||
7c85682d | 2963 | @item long_call/short_call |
2964 | @cindex indirect calls on ARM | |
2965 | This attribute specifies how a particular function is called on | |
d19f5793 | 2966 | ARM and Epiphany. Both attributes override the |
2967 | @option{-mlong-calls} (@pxref{ARM Options}) | |
bfe513a4 | 2968 | command-line switch and @code{#pragma long_calls} settings. The |
e3eb8567 | 2969 | @code{long_call} attribute indicates that the function might be far |
2970 | away from the call site and require a different (more expensive) | |
2971 | calling sequence. The @code{short_call} attribute always places | |
7c85682d | 2972 | the offset to the function from the call site into the @samp{BL} |
2973 | instruction directly. | |
8a8cdb8d | 2974 | |
7c85682d | 2975 | @item longcall/shortcall |
2976 | @cindex functions called via pointer on the RS/6000 and PowerPC | |
e3eb8567 | 2977 | On the Blackfin, RS/6000 and PowerPC, the @code{longcall} attribute |
2978 | indicates that the function might be far away from the call site and | |
2979 | require a different (more expensive) calling sequence. The | |
2980 | @code{shortcall} attribute indicates that the function is always close | |
2981 | enough for the shorter calling sequence to be used. These attributes | |
2982 | override both the @option{-mlongcall} switch and, on the RS/6000 and | |
2983 | PowerPC, the @code{#pragma longcall} setting. | |
8a8cdb8d | 2984 | |
7c85682d | 2985 | @xref{RS/6000 and PowerPC Options}, for more information on whether long |
2986 | calls are necessary. | |
146ef39f | 2987 | |
7808555b | 2988 | @item long_call/near/far |
3d375286 | 2989 | @cindex indirect calls on MIPS |
7808555b | 2990 | These attributes specify how a particular function is called on MIPS@. |
2991 | The attributes override the @option{-mlong-calls} (@pxref{MIPS Options}) | |
2992 | command-line switch. The @code{long_call} and @code{far} attributes are | |
2993 | synonyms, and cause the compiler to always call | |
3d375286 | 2994 | the function by first loading its address into a register, and then using |
7808555b | 2995 | the contents of that register. The @code{near} attribute has the opposite |
15b474a2 | 2996 | effect; it specifies that non-PIC calls should be made using the more |
7808555b | 2997 | efficient @code{jal} instruction. |
3d375286 | 2998 | |
7259f3f8 | 2999 | @item malloc |
3000 | @cindex @code{malloc} attribute | |
3001 | The @code{malloc} attribute is used to tell the compiler that a function | |
648147e8 | 3002 | may be treated as if any non-@code{NULL} pointer it returns cannot |
35cbef6c | 3003 | alias any other pointer valid when the function returns and that the memory |
3004 | has undefined content. | |
7259f3f8 | 3005 | This will often improve optimization. |
648147e8 | 3006 | Standard functions with this property include @code{malloc} and |
35cbef6c | 3007 | @code{calloc}. @code{realloc}-like functions do not have this |
3008 | property as the memory pointed to does not have undefined content. | |
7259f3f8 | 3009 | |
bd4d19da | 3010 | @item mips16/nomips16 |
3011 | @cindex @code{mips16} attribute | |
3012 | @cindex @code{nomips16} attribute | |
3013 | ||
3014 | On MIPS targets, you can use the @code{mips16} and @code{nomips16} | |
3015 | function attributes to locally select or turn off MIPS16 code generation. | |
15b474a2 | 3016 | A function with the @code{mips16} attribute is emitted as MIPS16 code, |
3017 | while MIPS16 code generation is disabled for functions with the | |
3018 | @code{nomips16} attribute. These attributes override the | |
bd4d19da | 3019 | @option{-mips16} and @option{-mno-mips16} options on the command line |
15b474a2 | 3020 | (@pxref{MIPS Options}). |
bd4d19da | 3021 | |
3022 | When compiling files containing mixed MIPS16 and non-MIPS16 code, the | |
3023 | preprocessor symbol @code{__mips16} reflects the setting on the command line, | |
3024 | not that within individual functions. Mixed MIPS16 and non-MIPS16 code | |
3025 | may interact badly with some GCC extensions such as @code{__builtin_apply} | |
3026 | (@pxref{Constructing Calls}). | |
3027 | ||
7c85682d | 3028 | @item model (@var{model-name}) |
3029 | @cindex function addressability on the M32R/D | |
3030 | @cindex variable addressability on the IA-64 | |
3031 | ||
3032 | On the M32R/D, use this attribute to set the addressability of an | |
3033 | object, and of the code generated for a function. The identifier | |
3034 | @var{model-name} is one of @code{small}, @code{medium}, or | |
3035 | @code{large}, representing each of the code models. | |
3036 | ||
3037 | Small model objects live in the lower 16MB of memory (so that their | |
3038 | addresses can be loaded with the @code{ld24} instruction), and are | |
3039 | callable with the @code{bl} instruction. | |
3040 | ||
3041 | Medium model objects may live anywhere in the 32-bit address space (the | |
3042 | compiler will generate @code{seth/add3} instructions to load their addresses), | |
3043 | and are callable with the @code{bl} instruction. | |
3044 | ||
3045 | Large model objects may live anywhere in the 32-bit address space (the | |
3046 | compiler will generate @code{seth/add3} instructions to load their addresses), | |
3047 | and may not be reachable with the @code{bl} instruction (the compiler will | |
3048 | generate the much slower @code{seth/add3/jl} instruction sequence). | |
3049 | ||
3050 | On IA-64, use this attribute to set the addressability of an object. | |
3051 | At present, the only supported identifier for @var{model-name} is | |
3052 | @code{small}, indicating addressability via ``small'' (22-bit) | |
3053 | addresses (so that their addresses can be loaded with the @code{addl} | |
3054 | instruction). Caveat: such addressing is by definition not position | |
3055 | independent and hence this attribute must not be used for objects | |
3056 | defined by shared libraries. | |
3057 | ||
d3feb168 | 3058 | @item ms_abi/sysv_abi |
9440ae7b | 3059 | @cindex @code{ms_abi} attribute |
d3feb168 | 3060 | @cindex @code{sysv_abi} attribute |
3061 | ||
05b56dfa | 3062 | On 32-bit and 64-bit (i?86|x86_64)-*-* targets, you can use an ABI attribute |
3063 | to indicate which calling convention should be used for a function. The | |
3064 | @code{ms_abi} attribute tells the compiler to use the Microsoft ABI, | |
3065 | while the @code{sysv_abi} attribute tells the compiler to use the ABI | |
3066 | used on GNU/Linux and other systems. The default is to use the Microsoft ABI | |
3067 | when targeting Windows. On all other systems, the default is the x86/AMD ABI. | |
d3feb168 | 3068 | |
05b56dfa | 3069 | Note, the @code{ms_abi} attribute for Windows 64-bit targets currently |
3070 | requires the @option{-maccumulate-outgoing-args} option. | |
d3feb168 | 3071 | |
c1817294 | 3072 | @item callee_pop_aggregate_return (@var{number}) |
3073 | @cindex @code{callee_pop_aggregate_return} attribute | |
3074 | ||
3075 | On 32-bit i?86-*-* targets, you can control by those attribute for | |
3076 | aggregate return in memory, if the caller is responsible to pop the hidden | |
3077 | pointer together with the rest of the arguments - @var{number} equal to | |
3078 | zero -, or if the callee is responsible to pop hidden pointer - @var{number} | |
4d72c922 | 3079 | equal to one. The default i386 ABI assumes that the callee pops the |
3080 | stack for hidden pointer. | |
c1817294 | 3081 | |
05b56dfa | 3082 | Note, that on 32-bit i386 Windows targets the compiler assumes that the |
3083 | caller pops the stack for hidden pointer. | |
3084 | ||
5a5324bc | 3085 | @item ms_hook_prologue |
3086 | @cindex @code{ms_hook_prologue} attribute | |
3087 | ||
2761b7cb | 3088 | On 32 bit i[34567]86-*-* targets and 64 bit x86_64-*-* targets, you can use |
3089 | this function attribute to make gcc generate the "hot-patching" function | |
3090 | prologue used in Win32 API functions in Microsoft Windows XP Service Pack 2 | |
3091 | and newer. | |
5a5324bc | 3092 | |
7c85682d | 3093 | @item naked |
3094 | @cindex function without a prologue/epilogue code | |
69f483eb | 3095 | Use this attribute on the ARM, AVR, MCORE, RX and SPU ports to indicate that |
644459d0 | 3096 | the specified function does not need prologue/epilogue sequences generated by |
15b474a2 | 3097 | the compiler. It is up to the programmer to provide these sequences. The |
3098 | only statements that can be safely included in naked functions are | |
658e203c | 3099 | @code{asm} statements that do not have operands. All other statements, |
15b474a2 | 3100 | including declarations of local variables, @code{if} statements, and so |
3101 | forth, should be avoided. Naked functions should be used to implement the | |
658e203c | 3102 | body of an assembly function, while allowing the compiler to construct |
3103 | the requisite function declaration for the assembler. | |
7c85682d | 3104 | |
3105 | @item near | |
3106 | @cindex functions which do not handle memory bank switching on 68HC11/68HC12 | |
3107 | On 68HC11 and 68HC12 the @code{near} attribute causes the compiler to | |
3108 | use the normal calling convention based on @code{jsr} and @code{rts}. | |
3109 | This attribute can be used to cancel the effect of the @option{-mlong-calls} | |
3110 | option. | |
3111 | ||
7c3116fb | 3112 | On MeP targets this attribute causes the compiler to assume the called |
3113 | function is close enough to use the normal calling convention, | |
3114 | overriding the @code{-mtf} command line option. | |
3115 | ||
9e6a0967 | 3116 | @item nesting |
3117 | @cindex Allow nesting in an interrupt handler on the Blackfin processor. | |
3118 | Use this attribute together with @code{interrupt_handler}, | |
3119 | @code{exception_handler} or @code{nmi_handler} to indicate that the function | |
3120 | entry code should enable nested interrupts or exceptions. | |
3121 | ||
3122 | @item nmi_handler | |
3123 | @cindex NMI handler functions on the Blackfin processor | |
3124 | Use this attribute on the Blackfin to indicate that the specified function | |
3125 | is an NMI handler. The compiler will generate function entry and | |
3126 | exit sequences suitable for use in an NMI handler when this | |
3127 | attribute is present. | |
3128 | ||
7c85682d | 3129 | @item no_instrument_function |
3130 | @cindex @code{no_instrument_function} function attribute | |
3131 | @opindex finstrument-functions | |
3132 | If @option{-finstrument-functions} is given, profiling function calls will | |
3133 | be generated at entry and exit of most user-compiled functions. | |
3134 | Functions with this attribute will not be so instrumented. | |
3135 | ||
48b14f50 | 3136 | @item no_split_stack |
3137 | @cindex @code{no_split_stack} function attribute | |
3138 | @opindex fsplit-stack | |
3139 | If @option{-fsplit-stack} is given, functions will have a small | |
3140 | prologue which decides whether to split the stack. Functions with the | |
3141 | @code{no_split_stack} attribute will not have that prologue, and thus | |
3142 | may run with only a small amount of stack space available. | |
3143 | ||
7c85682d | 3144 | @item noinline |
3145 | @cindex @code{noinline} function attribute | |
3146 | This function attribute prevents a function from being considered for | |
3147 | inlining. | |
9bc2537d | 3148 | @c Don't enumerate the optimizations by name here; we try to be |
3149 | @c future-compatible with this mechanism. | |
3150 | If the function does not have side-effects, there are optimizations | |
3151 | other than inlining that causes function calls to be optimized away, | |
3152 | although the function call is live. To keep such calls from being | |
3153 | optimized away, put | |
3154 | @smallexample | |
3155 | asm (""); | |
3156 | @end smallexample | |
3157 | (@pxref{Extended Asm}) in the called function, to serve as a special | |
3158 | side-effect. | |
7c85682d | 3159 | |
bdb1f0d1 | 3160 | @item noclone |
3161 | @cindex @code{noclone} function attribute | |
3162 | This function attribute prevents a function from being considered for | |
3163 | cloning - a mechanism which produces specialized copies of functions | |
3164 | and which is (currently) performed by interprocedural constant | |
3165 | propagation. | |
3166 | ||
7c85682d | 3167 | @item nonnull (@var{arg-index}, @dots{}) |
3168 | @cindex @code{nonnull} function attribute | |
3169 | The @code{nonnull} attribute specifies that some function parameters should | |
3170 | be non-null pointers. For instance, the declaration: | |
146ef39f | 3171 | |
3172 | @smallexample | |
7c85682d | 3173 | extern void * |
3174 | my_memcpy (void *dest, const void *src, size_t len) | |
c24c5fac | 3175 | __attribute__((nonnull (1, 2))); |
146ef39f | 3176 | @end smallexample |
3177 | ||
7c85682d | 3178 | @noindent |
3179 | causes the compiler to check that, in calls to @code{my_memcpy}, | |
3180 | arguments @var{dest} and @var{src} are non-null. If the compiler | |
3181 | determines that a null pointer is passed in an argument slot marked | |
3182 | as non-null, and the @option{-Wnonnull} option is enabled, a warning | |
3183 | is issued. The compiler may also choose to make optimizations based | |
3184 | on the knowledge that certain function arguments will not be null. | |
35073234 | 3185 | |
7c85682d | 3186 | If no argument index list is given to the @code{nonnull} attribute, |
3187 | all pointer arguments are marked as non-null. To illustrate, the | |
3188 | following declaration is equivalent to the previous example: | |
b4cf9ec1 | 3189 | |
3190 | @smallexample | |
7c85682d | 3191 | extern void * |
3192 | my_memcpy (void *dest, const void *src, size_t len) | |
c24c5fac | 3193 | __attribute__((nonnull)); |
b4cf9ec1 | 3194 | @end smallexample |
3195 | ||
7c85682d | 3196 | @item noreturn |
3197 | @cindex @code{noreturn} function attribute | |
3198 | A few standard library functions, such as @code{abort} and @code{exit}, | |
3199 | cannot return. GCC knows this automatically. Some programs define | |
3200 | their own functions that never return. You can declare them | |
3201 | @code{noreturn} to tell the compiler this fact. For example, | |
21a24508 | 3202 | |
7c85682d | 3203 | @smallexample |
3204 | @group | |
3205 | void fatal () __attribute__ ((noreturn)); | |
2d0ba106 | 3206 | |
7c85682d | 3207 | void |
3208 | fatal (/* @r{@dots{}} */) | |
3209 | @{ | |
3210 | /* @r{@dots{}} */ /* @r{Print error message.} */ /* @r{@dots{}} */ | |
3211 | exit (1); | |
3212 | @} | |
3213 | @end group | |
3214 | @end smallexample | |
21a24508 | 3215 | |
7c85682d | 3216 | The @code{noreturn} keyword tells the compiler to assume that |
3217 | @code{fatal} cannot return. It can then optimize without regard to what | |
3218 | would happen if @code{fatal} ever did return. This makes slightly | |
3219 | better code. More importantly, it helps avoid spurious warnings of | |
3220 | uninitialized variables. | |
21a24508 | 3221 | |
7c85682d | 3222 | The @code{noreturn} keyword does not affect the exceptional path when that |
3223 | applies: a @code{noreturn}-marked function may still return to the caller | |
14bca5d1 | 3224 | by throwing an exception or calling @code{longjmp}. |
21a24508 | 3225 | |
7c85682d | 3226 | Do not assume that registers saved by the calling function are |
3227 | restored before calling the @code{noreturn} function. | |
b4cf9ec1 | 3228 | |
7c85682d | 3229 | It does not make sense for a @code{noreturn} function to have a return |
3230 | type other than @code{void}. | |
146ef39f | 3231 | |
7c85682d | 3232 | The attribute @code{noreturn} is not implemented in GCC versions |
3233 | earlier than 2.5. An alternative way to declare that a function does | |
3234 | not return, which works in the current version and in some older | |
3235 | versions, is as follows: | |
3deb1c7e | 3236 | |
7c85682d | 3237 | @smallexample |
3238 | typedef void voidfn (); | |
146ef39f | 3239 | |
7c85682d | 3240 | volatile voidfn fatal; |
3241 | @end smallexample | |
54f917d1 | 3242 | |
fc08fc16 | 3243 | This approach does not work in GNU C++. |
3244 | ||
7c85682d | 3245 | @item nothrow |
3246 | @cindex @code{nothrow} function attribute | |
3247 | The @code{nothrow} attribute is used to inform the compiler that a | |
3248 | function cannot throw an exception. For example, most functions in | |
3249 | the standard C library can be guaranteed not to throw an exception | |
3250 | with the notable exceptions of @code{qsort} and @code{bsearch} that | |
3251 | take function pointer arguments. The @code{nothrow} attribute is not | |
6a40c9c1 | 3252 | implemented in GCC versions earlier than 3.3. |
146ef39f | 3253 | |
46f8e3b0 | 3254 | @item optimize |
3255 | @cindex @code{optimize} function attribute | |
3256 | The @code{optimize} attribute is used to specify that a function is to | |
3257 | be compiled with different optimization options than specified on the | |
3258 | command line. Arguments can either be numbers or strings. Numbers | |
3259 | are assumed to be an optimization level. Strings that begin with | |
3260 | @code{O} are assumed to be an optimization option, while other options | |
3261 | are assumed to be used with a @code{-f} prefix. You can also use the | |
3262 | @samp{#pragma GCC optimize} pragma to set the optimization options | |
3263 | that affect more than one function. | |
3264 | @xref{Function Specific Option Pragmas}, for details about the | |
db8edef0 | 3265 | @samp{#pragma GCC optimize} pragma. |
46f8e3b0 | 3266 | |
3267 | This can be used for instance to have frequently executed functions | |
3268 | compiled with more aggressive optimization options that produce faster | |
3269 | and larger code, while other functions can be called with less | |
24470055 | 3270 | aggressive options. |
46f8e3b0 | 3271 | |
91f3009d | 3272 | @item OS_main/OS_task |
3273 | @cindex @code{OS_main} AVR function attribute | |
3274 | @cindex @code{OS_task} AVR function attribute | |
3275 | On AVR, functions with the @code{OS_main} or @code{OS_task} attribute | |
3276 | do not save/restore any call-saved register in their prologue/epilogue. | |
3277 | ||
3278 | The @code{OS_main} attribute can be used when there @emph{is | |
3279 | guarantee} that interrupts are disabled at the time when the function | |
3280 | is entered. This will save resources when the stack pointer has to be | |
3281 | changed to set up a frame for local variables. | |
3282 | ||
3283 | The @code{OS_task} attribute can be used when there is @emph{no | |
3284 | guarantee} that interrupts are disabled at that time when the function | |
3285 | is entered like for, e@.g@. task functions in a multi-threading operating | |
3286 | system. In that case, changing the stack pointer register will be | |
3287 | guarded by save/clear/restore of the global interrupt enable flag. | |
3288 | ||
6ee532ba | 3289 | The differences to the @code{naked} function attribute are: |
91f3009d | 3290 | @itemize @bullet |
3291 | @item @code{naked} functions do not have a return instruction whereas | |
3292 | @code{OS_main} and @code{OS_task} functions will have a @code{RET} or | |
3293 | @code{RETI} return instruction. | |
3294 | @item @code{naked} functions do not set up a frame for local variables | |
3295 | or a frame pointer whereas @code{OS_main} and @code{OS_task} do this | |
3296 | as needed. | |
3297 | @end itemize | |
3298 | ||
3eec35ec | 3299 | @item pcs |
3300 | @cindex @code{pcs} function attribute | |
3301 | ||
3302 | The @code{pcs} attribute can be used to control the calling convention | |
3303 | used for a function on ARM. The attribute takes an argument that specifies | |
3304 | the calling convention to use. | |
3305 | ||
3306 | When compiling using the AAPCS ABI (or a variant of that) then valid | |
3307 | values for the argument are @code{"aapcs"} and @code{"aapcs-vfp"}. In | |
3308 | order to use a variant other than @code{"aapcs"} then the compiler must | |
3309 | be permitted to use the appropriate co-processor registers (i.e., the | |
3310 | VFP registers must be available in order to use @code{"aapcs-vfp"}). | |
3311 | For example, | |
3312 | ||
3313 | @smallexample | |
3314 | /* Argument passed in r0, and result returned in r0+r1. */ | |
3315 | double f2d (float) __attribute__((pcs("aapcs"))); | |
3316 | @end smallexample | |
3317 | ||
3318 | Variadic functions always use the @code{"aapcs"} calling convention and | |
3319 | the compiler will reject attempts to specify an alternative. | |
3320 | ||
7c85682d | 3321 | @item pure |
3322 | @cindex @code{pure} function attribute | |
3323 | Many functions have no effects except the return value and their | |
3324 | return value depends only on the parameters and/or global variables. | |
3325 | Such a function can be subject | |
3326 | to common subexpression elimination and loop optimization just as an | |
3327 | arithmetic operator would be. These functions should be declared | |
3328 | with the attribute @code{pure}. For example, | |
edd2f2ae | 3329 | |
7c85682d | 3330 | @smallexample |
3331 | int square (int) __attribute__ ((pure)); | |
3332 | @end smallexample | |
146ef39f | 3333 | |
7c85682d | 3334 | @noindent |
3335 | says that the hypothetical function @code{square} is safe to call | |
3336 | fewer times than the program says. | |
78fe751b | 3337 | |
7c85682d | 3338 | Some of common examples of pure functions are @code{strlen} or @code{memcmp}. |
3339 | Interesting non-pure functions are functions with infinite loops or those | |
3340 | depending on volatile memory or other system resource, that may change between | |
3341 | two consecutive calls (such as @code{feof} in a multithreading environment). | |
146ef39f | 3342 | |
7c85682d | 3343 | The attribute @code{pure} is not implemented in GCC versions earlier |
3344 | than 2.96. | |
146ef39f | 3345 | |
5de92639 | 3346 | @item hot |
3347 | @cindex @code{hot} function attribute | |
758a38ab | 3348 | The @code{hot} attribute on a function is used to inform the compiler that |
3349 | the function is a hot spot of the compiled program. The function is | |
3350 | optimized more aggressively and on many target it is placed into special | |
3351 | subsection of the text section so all hot functions appears close together | |
3352 | improving locality. | |
5de92639 | 3353 | |
3354 | When profile feedback is available, via @option{-fprofile-use}, hot functions | |
3355 | are automatically detected and this attribute is ignored. | |
3356 | ||
758a38ab | 3357 | The @code{hot} attribute on functions is not implemented in GCC versions |
3358 | earlier than 4.3. | |
3359 | ||
3360 | @cindex @code{hot} label attribute | |
3361 | The @code{hot} attribute on a label is used to inform the compiler that | |
3362 | path following the label are more likely than paths that are not so | |
3363 | annotated. This attribute is used in cases where @code{__builtin_expect} | |
3364 | cannot be used, for instance with computed goto or @code{asm goto}. | |
3365 | ||
3366 | The @code{hot} attribute on labels is not implemented in GCC versions | |
3367 | earlier than 4.8. | |
46f8e3b0 | 3368 | |
5de92639 | 3369 | @item cold |
3370 | @cindex @code{cold} function attribute | |
758a38ab | 3371 | The @code{cold} attribute on functions is used to inform the compiler that |
3372 | the function is unlikely to be executed. The function is optimized for | |
3373 | size rather than speed and on many targets it is placed into special | |
3374 | subsection of the text section so all cold functions appears close together | |
3375 | improving code locality of non-cold parts of program. The paths leading | |
3376 | to call of cold functions within code are marked as unlikely by the branch | |
3377 | prediction mechanism. It is thus useful to mark functions used to handle | |
3378 | unlikely conditions, such as @code{perror}, as cold to improve optimization | |
3379 | of hot functions that do call marked functions in rare occasions. | |
3380 | ||
3381 | When profile feedback is available, via @option{-fprofile-use}, cold functions | |
5de92639 | 3382 | are automatically detected and this attribute is ignored. |
3383 | ||
758a38ab | 3384 | The @code{cold} attribute on functions is not implemented in GCC versions |
3385 | earlier than 4.3. | |
3386 | ||
3387 | @cindex @code{cold} label attribute | |
3388 | The @code{cold} attribute on labels is used to inform the compiler that | |
3389 | the path following the label is unlikely to be executed. This attribute | |
3390 | is used in cases where @code{__builtin_expect} cannot be used, for instance | |
3391 | with computed goto or @code{asm goto}. | |
3392 | ||
3393 | The @code{cold} attribute on labels is not implemented in GCC versions | |
3394 | earlier than 4.8. | |
46f8e3b0 | 3395 | |
7c85682d | 3396 | @item regparm (@var{number}) |
3397 | @cindex @code{regparm} attribute | |
3398 | @cindex functions that are passed arguments in registers on the 386 | |
3399 | On the Intel 386, the @code{regparm} attribute causes the compiler to | |
3524624e | 3400 | pass arguments number one to @var{number} if they are of integral type |
3401 | in registers EAX, EDX, and ECX instead of on the stack. Functions that | |
3402 | take a variable number of arguments will continue to be passed all of their | |
7c85682d | 3403 | arguments on the stack. |
e27ad2d5 | 3404 | |
7c85682d | 3405 | Beware that on some ELF systems this attribute is unsuitable for |
3406 | global functions in shared libraries with lazy binding (which is the | |
3407 | default). Lazy binding will send the first call via resolving code in | |
3408 | the loader, which might assume EAX, EDX and ECX can be clobbered, as | |
3409 | per the standard calling conventions. Solaris 8 is affected by this. | |
3410 | GNU systems with GLIBC 2.1 or higher, and FreeBSD, are believed to be | |
dc8c96bb | 3411 | safe since the loaders there save EAX, EDX and ECX. (Lazy binding can be |
7c85682d | 3412 | disabled with the linker or the loader if desired, to avoid the |
3413 | problem.) | |
e27ad2d5 | 3414 | |
3524624e | 3415 | @item sseregparm |
3416 | @cindex @code{sseregparm} attribute | |
3417 | On the Intel 386 with SSE support, the @code{sseregparm} attribute | |
56a575a5 | 3418 | causes the compiler to pass up to 3 floating point arguments in |
3524624e | 3419 | SSE registers instead of on the stack. Functions that take a |
3420 | variable number of arguments will continue to pass all of their | |
3421 | floating point arguments on the stack. | |
3422 | ||
124c0201 | 3423 | @item force_align_arg_pointer |
3424 | @cindex @code{force_align_arg_pointer} attribute | |
3425 | On the Intel x86, the @code{force_align_arg_pointer} attribute may be | |
3426 | applied to individual function definitions, generating an alternate | |
27a7a23a | 3427 | prologue and epilogue that realigns the runtime stack if necessary. |
3428 | This supports mixing legacy codes that run with a 4-byte aligned stack | |
3429 | with modern codes that keep a 16-byte stack for SSE compatibility. | |
124c0201 | 3430 | |
5241f4ad | 3431 | @item resbank |
3432 | @cindex @code{resbank} attribute | |
3433 | On the SH2A target, this attribute enables the high-speed register | |
3434 | saving and restoration using a register bank for @code{interrupt_handler} | |
91f54ca3 | 3435 | routines. Saving to the bank is performed automatically after the CPU |
5241f4ad | 3436 | accepts an interrupt that uses a register bank. |
3437 | ||
3438 | The nineteen 32-bit registers comprising general register R0 to R14, | |
3439 | control register GBR, and system registers MACH, MACL, and PR and the | |
3440 | vector table address offset are saved into a register bank. Register | |
3441 | banks are stacked in first-in last-out (FILO) sequence. Restoration | |
3442 | from the bank is executed by issuing a RESBANK instruction. | |
3443 | ||
26d1c5ff | 3444 | @item returns_twice |
3445 | @cindex @code{returns_twice} attribute | |
3446 | The @code{returns_twice} attribute tells the compiler that a function may | |
3447 | return more than one time. The compiler will ensure that all registers | |
3448 | are dead before calling such a function and will emit a warning about | |
3449 | the variables that may be clobbered after the second return from the | |
3450 | function. Examples of such functions are @code{setjmp} and @code{vfork}. | |
3451 | The @code{longjmp}-like counterpart of such function, if any, might need | |
3452 | to be marked with the @code{noreturn} attribute. | |
3453 | ||
7c85682d | 3454 | @item saveall |
9e6a0967 | 3455 | @cindex save all registers on the Blackfin, H8/300, H8/300H, and H8S |
3456 | Use this attribute on the Blackfin, H8/300, H8/300H, and H8S to indicate that | |
7c85682d | 3457 | all registers except the stack pointer should be saved in the prologue |
3458 | regardless of whether they are used or not. | |
e27ad2d5 | 3459 | |
d34b0d1e | 3460 | @item save_volatiles |
3461 | @cindex save volatile registers on the MicroBlaze | |
3462 | Use this attribute on the MicroBlaze to indicate that the function is | |
15b474a2 | 3463 | an interrupt handler. All volatile registers (in addition to non-volatile |
3464 | registers) will be saved in the function prologue. If the function is a leaf | |
3465 | function, only volatiles used by the function are saved. A normal function | |
3466 | return is generated instead of a return from interrupt. | |
d34b0d1e | 3467 | |
7c85682d | 3468 | @item section ("@var{section-name}") |
3469 | @cindex @code{section} function attribute | |
3470 | Normally, the compiler places the code it generates in the @code{text} section. | |
3471 | Sometimes, however, you need additional sections, or you need certain | |
3472 | particular functions to appear in special sections. The @code{section} | |
3473 | attribute specifies that a function lives in a particular section. | |
3474 | For example, the declaration: | |
e27ad2d5 | 3475 | |
3476 | @smallexample | |
7c85682d | 3477 | extern void foobar (void) __attribute__ ((section ("bar"))); |
e27ad2d5 | 3478 | @end smallexample |
3479 | ||
7c85682d | 3480 | @noindent |
3481 | puts the function @code{foobar} in the @code{bar} section. | |
e27ad2d5 | 3482 | |
7c85682d | 3483 | Some file formats do not support arbitrary sections so the @code{section} |
3484 | attribute is not available on all platforms. | |
3485 | If you need to map the entire contents of a module to a particular | |
3486 | section, consider using the facilities of the linker instead. | |
3487 | ||
bf6c8de0 | 3488 | @item sentinel |
3489 | @cindex @code{sentinel} function attribute | |
50ca527f | 3490 | This function attribute ensures that a parameter in a function call is |
3491 | an explicit @code{NULL}. The attribute is only valid on variadic | |
3492 | functions. By default, the sentinel is located at position zero, the | |
3493 | last parameter of the function call. If an optional integer position | |
3494 | argument P is supplied to the attribute, the sentinel must be located at | |
3495 | position P counting backwards from the end of the argument list. | |
3496 | ||
3497 | @smallexample | |
3498 | __attribute__ ((sentinel)) | |
3499 | is equivalent to | |
3500 | __attribute__ ((sentinel(0))) | |
3501 | @end smallexample | |
3502 | ||
3503 | The attribute is automatically set with a position of 0 for the built-in | |
3504 | functions @code{execl} and @code{execlp}. The built-in function | |
515c3cb4 | 3505 | @code{execle} has the attribute set with a position of 1. |
50ca527f | 3506 | |
3507 | A valid @code{NULL} in this context is defined as zero with any pointer | |
3508 | type. If your system defines the @code{NULL} macro with an integer type | |
3509 | then you need to add an explicit cast. GCC replaces @code{stddef.h} | |
3510 | with a copy that redefines NULL appropriately. | |
3511 | ||
3512 | The warnings for missing or incorrect sentinels are enabled with | |
3513 | @option{-Wformat}. | |
bf6c8de0 | 3514 | |
7c85682d | 3515 | @item short_call |
3516 | See long_call/short_call. | |
3517 | ||
3518 | @item shortcall | |
3519 | See longcall/shortcall. | |
3520 | ||
3521 | @item signal | |
ea679361 | 3522 | @cindex interrupt handler functions on the AVR processors |
7c85682d | 3523 | Use this attribute on the AVR to indicate that the specified |
ea679361 | 3524 | function is an interrupt handler. The compiler will generate function |
3525 | entry and exit sequences suitable for use in an interrupt handler when this | |
3526 | attribute is present. | |
3527 | ||
3528 | See also the @code{interrupt} function attribute. | |
3529 | ||
3530 | The AVR hardware globally disables interrupts when an interrupt is executed. | |
3531 | Interrupt handler functions defined with the @code{signal} attribute | |
3532 | do not re-enable interrupts. It is save to enable interrupts in a | |
3533 | @code{signal} handler. This ``save'' only applies to the code | |
3534 | generated by the compiler and not to the IRQ-layout of the | |
3535 | application which is responsibility of the application. | |
3536 | ||
3537 | If both @code{signal} and @code{interrupt} are specified for the same | |
3538 | function, @code{signal} will be silently ignored. | |
9763338f | 3539 | |
3540 | @item sp_switch | |
eafbc061 | 3541 | Use this attribute on the SH to indicate an @code{interrupt_handler} |
9763338f | 3542 | function should switch to an alternate stack. It expects a string |
3543 | argument that names a global variable holding the address of the | |
3544 | alternate stack. | |
3545 | ||
3546 | @smallexample | |
3547 | void *alt_stack; | |
70c2c81c | 3548 | void f () __attribute__ ((interrupt_handler, |
3549 | sp_switch ("alt_stack"))); | |
9763338f | 3550 | @end smallexample |
3551 | ||
7c85682d | 3552 | @item stdcall |
3553 | @cindex functions that pop the argument stack on the 386 | |
3554 | On the Intel 386, the @code{stdcall} attribute causes the compiler to | |
3555 | assume that the called function will pop off the stack space used to | |
3556 | pass arguments, unless it takes a variable number of arguments. | |
146ef39f | 3557 | |
b84fdfe2 | 3558 | @item syscall_linkage |
3559 | @cindex @code{syscall_linkage} attribute | |
3560 | This attribute is used to modify the IA64 calling convention by marking | |
3561 | all input registers as live at all function exits. This makes it possible | |
3562 | to restart a system call after an interrupt without having to save/restore | |
3563 | the input registers. This also prevents kernel data from leaking into | |
3564 | application code. | |
3565 | ||
c17add59 | 3566 | @item target |
3567 | @cindex @code{target} function attribute | |
3568 | The @code{target} attribute is used to specify that a function is to | |
3569 | be compiled with different target options than specified on the | |
3570 | command line. This can be used for instance to have functions | |
3571 | compiled with a different ISA (instruction set architecture) than the | |
3572 | default. You can also use the @samp{#pragma GCC target} pragma to set | |
3573 | more than one function to be compiled with specific target options. | |
3574 | @xref{Function Specific Option Pragmas}, for details about the | |
3575 | @samp{#pragma GCC target} pragma. | |
3576 | ||
3577 | For instance on a 386, you could compile one function with | |
3578 | @code{target("sse4.1,arch=core2")} and another with | |
3579 | @code{target("sse4a,arch=amdfam10")} that would be equivalent to | |
3580 | compiling the first function with @option{-msse4.1} and | |
3581 | @option{-march=core2} options, and the second function with | |
3582 | @option{-msse4a} and @option{-march=amdfam10} options. It is up to the | |
3583 | user to make sure that a function is only invoked on a machine that | |
3584 | supports the particular ISA it was compiled for (for example by using | |
3585 | @code{cpuid} on 386 to determine what feature bits and architecture | |
3586 | family are used). | |
3587 | ||
3588 | @smallexample | |
3589 | int core2_func (void) __attribute__ ((__target__ ("arch=core2"))); | |
3590 | int sse3_func (void) __attribute__ ((__target__ ("sse3"))); | |
3591 | @end smallexample | |
3592 | ||
3593 | On the 386, the following options are allowed: | |
3594 | ||
3595 | @table @samp | |
3596 | @item abm | |
3597 | @itemx no-abm | |
3598 | @cindex @code{target("abm")} attribute | |
3599 | Enable/disable the generation of the advanced bit instructions. | |
3600 | ||
3601 | @item aes | |
3602 | @itemx no-aes | |
3603 | @cindex @code{target("aes")} attribute | |
3604 | Enable/disable the generation of the AES instructions. | |
3605 | ||
3606 | @item mmx | |
3607 | @itemx no-mmx | |
3608 | @cindex @code{target("mmx")} attribute | |
3609 | Enable/disable the generation of the MMX instructions. | |
3610 | ||
3611 | @item pclmul | |
3612 | @itemx no-pclmul | |
3613 | @cindex @code{target("pclmul")} attribute | |
3614 | Enable/disable the generation of the PCLMUL instructions. | |
3615 | ||
3616 | @item popcnt | |
3617 | @itemx no-popcnt | |
3618 | @cindex @code{target("popcnt")} attribute | |
3619 | Enable/disable the generation of the POPCNT instruction. | |
3620 | ||
3621 | @item sse | |
3622 | @itemx no-sse | |
3623 | @cindex @code{target("sse")} attribute | |
3624 | Enable/disable the generation of the SSE instructions. | |
3625 | ||
3626 | @item sse2 | |
3627 | @itemx no-sse2 | |
3628 | @cindex @code{target("sse2")} attribute | |
3629 | Enable/disable the generation of the SSE2 instructions. | |
3630 | ||
3631 | @item sse3 | |
3632 | @itemx no-sse3 | |
3633 | @cindex @code{target("sse3")} attribute | |
3634 | Enable/disable the generation of the SSE3 instructions. | |
3635 | ||
3636 | @item sse4 | |
3637 | @itemx no-sse4 | |
3638 | @cindex @code{target("sse4")} attribute | |
3639 | Enable/disable the generation of the SSE4 instructions (both SSE4.1 | |
3640 | and SSE4.2). | |
3641 | ||
3642 | @item sse4.1 | |
3643 | @itemx no-sse4.1 | |
3644 | @cindex @code{target("sse4.1")} attribute | |
3645 | Enable/disable the generation of the sse4.1 instructions. | |
3646 | ||
3647 | @item sse4.2 | |
3648 | @itemx no-sse4.2 | |
3649 | @cindex @code{target("sse4.2")} attribute | |
3650 | Enable/disable the generation of the sse4.2 instructions. | |
3651 | ||
3652 | @item sse4a | |
3653 | @itemx no-sse4a | |
3654 | @cindex @code{target("sse4a")} attribute | |
3655 | Enable/disable the generation of the SSE4A instructions. | |
3656 | ||
2f212aae | 3657 | @item fma4 |
3658 | @itemx no-fma4 | |
3659 | @cindex @code{target("fma4")} attribute | |
3660 | Enable/disable the generation of the FMA4 instructions. | |
3661 | ||
18525343 | 3662 | @item xop |
3663 | @itemx no-xop | |
3664 | @cindex @code{target("xop")} attribute | |
3665 | Enable/disable the generation of the XOP instructions. | |
3666 | ||
048fbb59 | 3667 | @item lwp |
3668 | @itemx no-lwp | |
3669 | @cindex @code{target("lwp")} attribute | |
3670 | Enable/disable the generation of the LWP instructions. | |
3671 | ||
c17add59 | 3672 | @item ssse3 |
3673 | @itemx no-ssse3 | |
3674 | @cindex @code{target("ssse3")} attribute | |
3675 | Enable/disable the generation of the SSSE3 instructions. | |
3676 | ||
3677 | @item cld | |
3678 | @itemx no-cld | |
3679 | @cindex @code{target("cld")} attribute | |
3680 | Enable/disable the generation of the CLD before string moves. | |
3681 | ||
3682 | @item fancy-math-387 | |
3683 | @itemx no-fancy-math-387 | |
3684 | @cindex @code{target("fancy-math-387")} attribute | |
3685 | Enable/disable the generation of the @code{sin}, @code{cos}, and | |
3686 | @code{sqrt} instructions on the 387 floating point unit. | |
3687 | ||
3688 | @item fused-madd | |
3689 | @itemx no-fused-madd | |
3690 | @cindex @code{target("fused-madd")} attribute | |
3691 | Enable/disable the generation of the fused multiply/add instructions. | |
3692 | ||
3693 | @item ieee-fp | |
3694 | @itemx no-ieee-fp | |
3695 | @cindex @code{target("ieee-fp")} attribute | |
3696 | Enable/disable the generation of floating point that depends on IEEE arithmetic. | |
3697 | ||
3698 | @item inline-all-stringops | |
3699 | @itemx no-inline-all-stringops | |
3700 | @cindex @code{target("inline-all-stringops")} attribute | |
3701 | Enable/disable inlining of string operations. | |
3702 | ||
3703 | @item inline-stringops-dynamically | |
3704 | @itemx no-inline-stringops-dynamically | |
3705 | @cindex @code{target("inline-stringops-dynamically")} attribute | |
3706 | Enable/disable the generation of the inline code to do small string | |
3707 | operations and calling the library routines for large operations. | |
3708 | ||
3709 | @item align-stringops | |
3710 | @itemx no-align-stringops | |
3711 | @cindex @code{target("align-stringops")} attribute | |
3712 | Do/do not align destination of inlined string operations. | |
3713 | ||
3714 | @item recip | |
3715 | @itemx no-recip | |
3716 | @cindex @code{target("recip")} attribute | |
3717 | Enable/disable the generation of RCPSS, RCPPS, RSQRTSS and RSQRTPS | |
8898b2ef | 3718 | instructions followed an additional Newton-Raphson step instead of |
c17add59 | 3719 | doing a floating point division. |
3720 | ||
3721 | @item arch=@var{ARCH} | |
3722 | @cindex @code{target("arch=@var{ARCH}")} attribute | |
3723 | Specify the architecture to generate code for in compiling the function. | |
3724 | ||
3725 | @item tune=@var{TUNE} | |
3726 | @cindex @code{target("tune=@var{TUNE}")} attribute | |
3727 | Specify the architecture to tune for in compiling the function. | |
3728 | ||
3729 | @item fpmath=@var{FPMATH} | |
3730 | @cindex @code{target("fpmath=@var{FPMATH}")} attribute | |
3731 | Specify which floating point unit to use. The | |
3732 | @code{target("fpmath=sse,387")} option must be specified as | |
3733 | @code{target("fpmath=sse+387")} because the comma would separate | |
3734 | different options. | |
0695a9f1 | 3735 | @end table |
755fa783 | 3736 | |
755fa783 | 3737 | On the PowerPC, the following options are allowed: |
3738 | ||
3739 | @table @samp | |
3740 | @item altivec | |
3741 | @itemx no-altivec | |
3742 | @cindex @code{target("altivec")} attribute | |
3743 | Generate code that uses (does not use) AltiVec instructions. In | |
3744 | 32-bit code, you cannot enable Altivec instructions unless | |
3745 | @option{-mabi=altivec} was used on the command line. | |
3746 | ||
3747 | @item cmpb | |
3748 | @itemx no-cmpb | |
3749 | @cindex @code{target("cmpb")} attribute | |
3750 | Generate code that uses (does not use) the compare bytes instruction | |
3751 | implemented on the POWER6 processor and other processors that support | |
3752 | the PowerPC V2.05 architecture. | |
3753 | ||
3754 | @item dlmzb | |
3755 | @itemx no-dlmzb | |
3756 | @cindex @code{target("dlmzb")} attribute | |
3757 | Generate code that uses (does not use) the string-search @samp{dlmzb} | |
3758 | instruction on the IBM 405, 440, 464 and 476 processors. This instruction is | |
9d75589a | 3759 | generated by default when targeting those processors. |
755fa783 | 3760 | |
3761 | @item fprnd | |
3762 | @itemx no-fprnd | |
3763 | @cindex @code{target("fprnd")} attribute | |
3764 | Generate code that uses (does not use) the FP round to integer | |
3765 | instructions implemented on the POWER5+ processor and other processors | |
3766 | that support the PowerPC V2.03 architecture. | |
3767 | ||
3768 | @item hard-dfp | |
3769 | @itemx no-hard-dfp | |
3770 | @cindex @code{target("hard-dfp")} attribute | |
3771 | Generate code that uses (does not use) the decimal floating point | |
3772 | instructions implemented on some POWER processors. | |
3773 | ||
3774 | @item isel | |
3775 | @itemx no-isel | |
3776 | @cindex @code{target("isel")} attribute | |
3777 | Generate code that uses (does not use) ISEL instruction. | |
3778 | ||
3779 | @item mfcrf | |
3780 | @itemx no-mfcrf | |
3781 | @cindex @code{target("mfcrf")} attribute | |
3782 | Generate code that uses (does not use) the move from condition | |
3783 | register field instruction implemented on the POWER4 processor and | |
3784 | other processors that support the PowerPC V2.01 architecture. | |
3785 | ||
3786 | @item mfpgpr | |
3787 | @itemx no-mfpgpr | |
3788 | @cindex @code{target("mfpgpr")} attribute | |
3789 | Generate code that uses (does not use) the FP move to/from general | |
3790 | purpose register instructions implemented on the POWER6X processor and | |
3791 | other processors that support the extended PowerPC V2.05 architecture. | |
3792 | ||
3793 | @item mulhw | |
3794 | @itemx no-mulhw | |
3795 | @cindex @code{target("mulhw")} attribute | |
3796 | Generate code that uses (does not use) the half-word multiply and | |
3797 | multiply-accumulate instructions on the IBM 405, 440, 464 and 476 processors. | |
9d75589a | 3798 | These instructions are generated by default when targeting those |
755fa783 | 3799 | processors. |
3800 | ||
3801 | @item multiple | |
3802 | @itemx no-multiple | |
3803 | @cindex @code{target("multiple")} attribute | |
3804 | Generate code that uses (does not use) the load multiple word | |
3805 | instructions and the store multiple word instructions. | |
3806 | ||
3807 | @item update | |
3808 | @itemx no-update | |
3809 | @cindex @code{target("update")} attribute | |
3810 | Generate code that uses (does not use) the load or store instructions | |
3811 | that update the base register to the address of the calculated memory | |
3812 | location. | |
3813 | ||
3814 | @item popcntb | |
3815 | @itemx no-popcntb | |
3816 | @cindex @code{target("popcntb")} attribute | |
3817 | Generate code that uses (does not use) the popcount and double | |
3818 | precision FP reciprocal estimate instruction implemented on the POWER5 | |
3819 | processor and other processors that support the PowerPC V2.02 | |
3820 | architecture. | |
3821 | ||
3822 | @item popcntd | |
3823 | @itemx no-popcntd | |
3824 | @cindex @code{target("popcntd")} attribute | |
3825 | Generate code that uses (does not use) the popcount instruction | |
3826 | implemented on the POWER7 processor and other processors that support | |
3827 | the PowerPC V2.06 architecture. | |
3828 | ||
3829 | @item powerpc-gfxopt | |
3830 | @itemx no-powerpc-gfxopt | |
3831 | @cindex @code{target("powerpc-gfxopt")} attribute | |
3832 | Generate code that uses (does not use) the optional PowerPC | |
3833 | architecture instructions in the Graphics group, including | |
3834 | floating-point select. | |
3835 | ||
3836 | @item powerpc-gpopt | |
3837 | @itemx no-powerpc-gpopt | |
3838 | @cindex @code{target("powerpc-gpopt")} attribute | |
3839 | Generate code that uses (does not use) the optional PowerPC | |
3840 | architecture instructions in the General Purpose group, including | |
3841 | floating-point square root. | |
3842 | ||
3843 | @item recip-precision | |
3844 | @itemx no-recip-precision | |
3845 | @cindex @code{target("recip-precision")} attribute | |
3846 | Assume (do not assume) that the reciprocal estimate instructions | |
3847 | provide higher precision estimates than is mandated by the powerpc | |
3848 | ABI. | |
3849 | ||
3850 | @item string | |
3851 | @itemx no-string | |
3852 | @cindex @code{target("string")} attribute | |
3853 | Generate code that uses (does not use) the load string instructions | |
3854 | and the store string word instructions to save multiple registers and | |
3855 | do small block moves. | |
3856 | ||
3857 | @item vsx | |
3858 | @itemx no-vsx | |
3859 | @cindex @code{target("vsx")} attribute | |
3860 | Generate code that uses (does not use) vector/scalar (VSX) | |
3861 | instructions, and also enable the use of built-in functions that allow | |
3862 | more direct access to the VSX instruction set. In 32-bit code, you | |
3863 | cannot enable VSX or Altivec instructions unless | |
3864 | @option{-mabi=altivec} was used on the command line. | |
3865 | ||
3866 | @item friz | |
3867 | @itemx no-friz | |
3868 | @cindex @code{target("friz")} attribute | |
3869 | Generate (do not generate) the @code{friz} instruction when the | |
3870 | @option{-funsafe-math-optimizations} option is used to optimize | |
3871 | rounding a floating point value to 64-bit integer and back to floating | |
3872 | point. The @code{friz} instruction does not return the same value if | |
3873 | the floating point number is too large to fit in an integer. | |
3874 | ||
3875 | @item avoid-indexed-addresses | |
3876 | @itemx no-avoid-indexed-addresses | |
3877 | @cindex @code{target("avoid-indexed-addresses")} attribute | |
3878 | Generate code that tries to avoid (not avoid) the use of indexed load | |
3879 | or store instructions. | |
3880 | ||
3881 | @item paired | |
3882 | @itemx no-paired | |
3883 | @cindex @code{target("paired")} attribute | |
3884 | Generate code that uses (does not use) the generation of PAIRED simd | |
3885 | instructions. | |
3886 | ||
3887 | @item longcall | |
3888 | @itemx no-longcall | |
3889 | @cindex @code{target("longcall")} attribute | |
3890 | Generate code that assumes (does not assume) that all calls are far | |
3891 | away so that a longer more expensive calling sequence is required. | |
3892 | ||
3893 | @item cpu=@var{CPU} | |
3894 | @cindex @code{target("cpu=@var{CPU}")} attribute | |
b59688ee | 3895 | Specify the architecture to generate code for when compiling the |
79b69060 | 3896 | function. If you select the @code{target("cpu=power7")} attribute when |
755fa783 | 3897 | generating 32-bit code, VSX and Altivec instructions are not generated |
3898 | unless you use the @option{-mabi=altivec} option on the command line. | |
3899 | ||
3900 | @item tune=@var{TUNE} | |
3901 | @cindex @code{target("tune=@var{TUNE}")} attribute | |
b59688ee | 3902 | Specify the architecture to tune for when compiling the function. If |
755fa783 | 3903 | you do not specify the @code{target("tune=@var{TUNE}")} attribute and |
b59688ee | 3904 | you do specify the @code{target("cpu=@var{CPU}")} attribute, |
755fa783 | 3905 | compilation will tune for the @var{CPU} architecture, and not the |
3906 | default tuning specified on the command line. | |
3907 | @end table | |
c17add59 | 3908 | |
755fa783 | 3909 | On the 386/x86_64 and PowerPC backends, you can use either multiple |
3910 | strings to specify multiple options, or you can separate the option | |
3911 | with a comma (@code{,}). | |
c17add59 | 3912 | |
755fa783 | 3913 | On the 386/x86_64 and PowerPC backends, the inliner will not inline a |
3914 | function that has different target options than the caller, unless the | |
3915 | callee has a subset of the target options of the caller. For example | |
3916 | a function declared with @code{target("sse3")} can inline a function | |
3917 | with @code{target("sse2")}, since @code{-msse3} implies @code{-msse2}. | |
c17add59 | 3918 | |
3919 | The @code{target} attribute is not implemented in GCC versions earlier | |
755fa783 | 3920 | than 4.4 for the i386/x86_64 and 4.6 for the PowerPC backends. It is |
3921 | not currently implemented for other backends. | |
c17add59 | 3922 | |
146ef39f | 3923 | @item tiny_data |
11a83f51 | 3924 | @cindex tiny data section on the H8/300H and H8S |
3925 | Use this attribute on the H8/300H and H8S to indicate that the specified | |
146ef39f | 3926 | variable should be placed into the tiny data section. |
3927 | The compiler will generate more efficient code for loads and stores | |
3928 | on data in the tiny data section. Note the tiny data area is limited to | |
3929 | slightly under 32kbytes of data. | |
097cea9f | 3930 | |
7c85682d | 3931 | @item trap_exit |
3932 | Use this attribute on the SH for an @code{interrupt_handler} to return using | |
3933 | @code{trapa} instead of @code{rte}. This attribute expects an integer | |
3934 | argument specifying the trap number to be used. | |
097cea9f | 3935 | |
7c85682d | 3936 | @item unused |
3937 | @cindex @code{unused} attribute. | |
3938 | This attribute, attached to a function, means that the function is meant | |
3939 | to be possibly unused. GCC will not produce a warning for this | |
3940 | function. | |
b8629bcb | 3941 | |
7c85682d | 3942 | @item used |
3943 | @cindex @code{used} attribute. | |
3944 | This attribute, attached to a function, means that code must be emitted | |
3945 | for the function even if it appears that the function is not referenced. | |
3946 | This is useful, for example, when the function is referenced only in | |
3947 | inline assembly. | |
76b9b5f9 | 3948 | |
c86f0926 | 3949 | When applied to a member function of a C++ class template, the |
3950 | attribute also means that the function will be instantiated if the | |
3951 | class itself is instantiated. | |
3952 | ||
9afff52d | 3953 | @item version_id |
b84fdfe2 | 3954 | @cindex @code{version_id} attribute |
3955 | This IA64 HP-UX attribute, attached to a global variable or function, renames a | |
9afff52d | 3956 | symbol to contain a version string, thus allowing for function level |
3957 | versioning. HP-UX system header files may use version level functioning | |
3958 | for some system calls. | |
3959 | ||
3960 | @smallexample | |
3961 | extern int foo () __attribute__((version_id ("20040821"))); | |
3962 | @end smallexample | |
3963 | ||
3964 | Calls to @var{foo} will be mapped to calls to @var{foo@{20040821@}}. | |
3965 | ||
7c85682d | 3966 | @item visibility ("@var{visibility_type}") |
3967 | @cindex @code{visibility} attribute | |
8ab158f9 | 3968 | This attribute affects the linkage of the declaration to which it is attached. |
3969 | There are four supported @var{visibility_type} values: default, | |
3970 | hidden, protected or internal visibility. | |
76b9b5f9 | 3971 | |
7c85682d | 3972 | @smallexample |
3973 | void __attribute__ ((visibility ("protected"))) | |
3974 | f () @{ /* @r{Do something.} */; @} | |
3975 | int i __attribute__ ((visibility ("hidden"))); | |
3976 | @end smallexample | |
76b9b5f9 | 3977 | |
8ab158f9 | 3978 | The possible values of @var{visibility_type} correspond to the |
3979 | visibility settings in the ELF gABI. | |
76b9b5f9 | 3980 | |
7c85682d | 3981 | @table @dfn |
3c5c992f | 3982 | @c keep this list of visibilities in alphabetical order. |
195d932a | 3983 | |
7c85682d | 3984 | @item default |
8ab158f9 | 3985 | Default visibility is the normal case for the object file format. |
3986 | This value is available for the visibility attribute to override other | |
3987 | options that may change the assumed visibility of entities. | |
3988 | ||
3989 | On ELF, default visibility means that the declaration is visible to other | |
3990 | modules and, in shared libraries, means that the declared entity may be | |
3991 | overridden. | |
3992 | ||
3993 | On Darwin, default visibility means that the declaration is visible to | |
3994 | other modules. | |
3995 | ||
3996 | Default visibility corresponds to ``external linkage'' in the language. | |
195d932a | 3997 | |
7c85682d | 3998 | @item hidden |
8ab158f9 | 3999 | Hidden visibility indicates that the entity declared will have a new |
4000 | form of linkage, which we'll call ``hidden linkage''. Two | |
4001 | declarations of an object with hidden linkage refer to the same object | |
4002 | if they are in the same shared object. | |
195d932a | 4003 | |
7c85682d | 4004 | @item internal |
4005 | Internal visibility is like hidden visibility, but with additional | |
8ab158f9 | 4006 | processor specific semantics. Unless otherwise specified by the |
4007 | psABI, GCC defines internal visibility to mean that a function is | |
4008 | @emph{never} called from another module. Compare this with hidden | |
4009 | functions which, while they cannot be referenced directly by other | |
4010 | modules, can be referenced indirectly via function pointers. By | |
4011 | indicating that a function cannot be called from outside the module, | |
4012 | GCC may for instance omit the load of a PIC register since it is known | |
4013 | that the calling function loaded the correct value. | |
195d932a | 4014 | |
7c85682d | 4015 | @item protected |
8ab158f9 | 4016 | Protected visibility is like default visibility except that it |
4017 | indicates that references within the defining module will bind to the | |
4018 | definition in that module. That is, the declared entity cannot be | |
4019 | overridden by another module. | |
195d932a | 4020 | |
7c85682d | 4021 | @end table |
195d932a | 4022 | |
8ab158f9 | 4023 | All visibilities are supported on many, but not all, ELF targets |
4024 | (supported when the assembler supports the @samp{.visibility} | |
4025 | pseudo-op). Default visibility is supported everywhere. Hidden | |
4026 | visibility is supported on Darwin targets. | |
4027 | ||
4028 | The visibility attribute should be applied only to declarations which | |
4029 | would otherwise have external linkage. The attribute should be applied | |
4030 | consistently, so that the same entity should not be declared with | |
4031 | different settings of the attribute. | |
4032 | ||
4033 | In C++, the visibility attribute applies to types as well as functions | |
4a2849cb | 4034 | and objects, because in C++ types have linkage. A class must not have |
4035 | greater visibility than its non-static data member types and bases, | |
4036 | and class members default to the visibility of their class. Also, a | |
6a47600c | 4037 | declaration without explicit visibility is limited to the visibility |
4038 | of its type. | |
8ab158f9 | 4039 | |
4040 | In C++, you can mark member functions and static member variables of a | |
d2258b2f | 4041 | class with the visibility attribute. This is useful if you know a |
8ab158f9 | 4042 | particular method or static member variable should only be used from |
4043 | one shared object; then you can mark it hidden while the rest of the | |
4044 | class has default visibility. Care must be taken to avoid breaking | |
6a47600c | 4045 | the One Definition Rule; for example, it is usually not useful to mark |
4046 | an inline method as hidden without marking the whole class as hidden. | |
195d932a | 4047 | |
4a2849cb | 4048 | A C++ namespace declaration can also have the visibility attribute. |
4049 | This attribute applies only to the particular namespace body, not to | |
4050 | other definitions of the same namespace; it is equivalent to using | |
4051 | @samp{#pragma GCC visibility} before and after the namespace | |
4052 | definition (@pxref{Visibility Pragmas}). | |
4053 | ||
4054 | In C++, if a template argument has limited visibility, this | |
4055 | restriction is implicitly propagated to the template instantiation. | |
4056 | Otherwise, template instantiations and specializations default to the | |
4057 | visibility of their template. | |
4058 | ||
6a47600c | 4059 | If both the template and enclosing class have explicit visibility, the |
4060 | visibility from the template is used. | |
4061 | ||
7c3116fb | 4062 | @item vliw |
4063 | @cindex @code{vliw} attribute | |
4064 | On MeP, the @code{vliw} attribute tells the compiler to emit | |
4065 | instructions in VLIW mode instead of core mode. Note that this | |
4066 | attribute is not allowed unless a VLIW coprocessor has been configured | |
4067 | and enabled through command line options. | |
4068 | ||
7c85682d | 4069 | @item warn_unused_result |
4070 | @cindex @code{warn_unused_result} attribute | |
4071 | The @code{warn_unused_result} attribute causes a warning to be emitted | |
4072 | if a caller of the function with this attribute does not use its | |
4073 | return value. This is useful for functions where not checking | |
4074 | the result is either a security problem or always a bug, such as | |
4075 | @code{realloc}. | |
195d932a | 4076 | |
7c85682d | 4077 | @smallexample |
4078 | int fn () __attribute__ ((warn_unused_result)); | |
4079 | int foo () | |
4080 | @{ | |
4081 | if (fn () < 0) return -1; | |
4082 | fn (); | |
4083 | return 0; | |
4084 | @} | |
4085 | @end smallexample | |
195d932a | 4086 | |
7c85682d | 4087 | results in warning on line 5. |
195d932a | 4088 | |
7c85682d | 4089 | @item weak |
4090 | @cindex @code{weak} attribute | |
4091 | The @code{weak} attribute causes the declaration to be emitted as a weak | |
4092 | symbol rather than a global. This is primarily useful in defining | |
4093 | library functions which can be overridden in user code, though it can | |
4094 | also be used with non-function declarations. Weak symbols are supported | |
4095 | for ELF targets, and also for a.out targets when using the GNU assembler | |
4096 | and linker. | |
195d932a | 4097 | |
f4a30bd7 | 4098 | @item weakref |
4099 | @itemx weakref ("@var{target}") | |
4100 | @cindex @code{weakref} attribute | |
4101 | The @code{weakref} attribute marks a declaration as a weak reference. | |
4102 | Without arguments, it should be accompanied by an @code{alias} attribute | |
4103 | naming the target symbol. Optionally, the @var{target} may be given as | |
4104 | an argument to @code{weakref} itself. In either case, @code{weakref} | |
4105 | implicitly marks the declaration as @code{weak}. Without a | |
4106 | @var{target}, given as an argument to @code{weakref} or to @code{alias}, | |
4107 | @code{weakref} is equivalent to @code{weak}. | |
4108 | ||
4109 | @smallexample | |
0a3ecdc1 | 4110 | static int x() __attribute__ ((weakref ("y"))); |
f4a30bd7 | 4111 | /* is equivalent to... */ |
0a3ecdc1 | 4112 | static int x() __attribute__ ((weak, weakref, alias ("y"))); |
f4a30bd7 | 4113 | /* and to... */ |
0a3ecdc1 | 4114 | static int x() __attribute__ ((weakref)); |
4115 | static int x() __attribute__ ((alias ("y"))); | |
f4a30bd7 | 4116 | @end smallexample |
4117 | ||
4118 | A weak reference is an alias that does not by itself require a | |
4119 | definition to be given for the target symbol. If the target symbol is | |
bc2e3b16 | 4120 | only referenced through weak references, then it becomes a @code{weak} |
f4a30bd7 | 4121 | undefined symbol. If it is directly referenced, however, then such |
4122 | strong references prevail, and a definition will be required for the | |
4123 | symbol, not necessarily in the same translation unit. | |
4124 | ||
4125 | The effect is equivalent to moving all references to the alias to a | |
4126 | separate translation unit, renaming the alias to the aliased symbol, | |
4127 | declaring it as weak, compiling the two separate translation units and | |
4128 | performing a reloadable link on them. | |
4129 | ||
0a3ecdc1 | 4130 | At present, a declaration to which @code{weakref} is attached can |
4131 | only be @code{static}. | |
4132 | ||
146ef39f | 4133 | @end table |
4134 | ||
4135 | You can specify multiple attributes in a declaration by separating them | |
4136 | by commas within the double parentheses or by immediately following an | |
4137 | attribute declaration with another attribute declaration. | |
4138 | ||
4139 | @cindex @code{#pragma}, reason for not using | |
4140 | @cindex pragma, reason for not using | |
4449f3e0 | 4141 | Some people object to the @code{__attribute__} feature, suggesting that |
4142 | ISO C's @code{#pragma} should be used instead. At the time | |
4143 | @code{__attribute__} was designed, there were two reasons for not doing | |
4144 | this. | |
146ef39f | 4145 | |
4146 | @enumerate | |
4147 | @item | |
4148 | It is impossible to generate @code{#pragma} commands from a macro. | |
4149 | ||
4150 | @item | |
4151 | There is no telling what the same @code{#pragma} might mean in another | |
4152 | compiler. | |
4153 | @end enumerate | |
4154 | ||
4449f3e0 | 4155 | These two reasons applied to almost any application that might have been |
4156 | proposed for @code{#pragma}. It was basically a mistake to use | |
4157 | @code{#pragma} for @emph{anything}. | |
4158 | ||
4159 | The ISO C99 standard includes @code{_Pragma}, which now allows pragmas | |
4160 | to be generated from macros. In addition, a @code{#pragma GCC} | |
4161 | namespace is now in use for GCC-specific pragmas. However, it has been | |
4162 | found convenient to use @code{__attribute__} to achieve a natural | |
4163 | attachment of attributes to their corresponding declarations, whereas | |
4164 | @code{#pragma GCC} is of use for constructs that do not naturally form | |
fd0ccb39 | 4165 | part of the grammar. @xref{Pragmas,,Pragmas Accepted by GCC}. |
146ef39f | 4166 | |
b31bfb3f | 4167 | @node Attribute Syntax |
4168 | @section Attribute Syntax | |
4169 | @cindex attribute syntax | |
4170 | ||
4171 | This section describes the syntax with which @code{__attribute__} may be | |
4172 | used, and the constructs to which attribute specifiers bind, for the C | |
0858e3a2 | 4173 | language. Some details may vary for C++ and Objective-C@. Because of |
b31bfb3f | 4174 | infelicities in the grammar for attributes, some forms described here |
4175 | may not be successfully parsed in all cases. | |
4176 | ||
e3c541f0 | 4177 | There are some problems with the semantics of attributes in C++. For |
4178 | example, there are no manglings for attributes, although they may affect | |
4179 | code generation, so problems may arise when attributed types are used in | |
4180 | conjunction with templates or overloading. Similarly, @code{typeid} | |
4181 | does not distinguish between types with different attributes. Support | |
4182 | for attributes in C++ may be restricted in future to attributes on | |
4183 | declarations only, but not on nested declarators. | |
4184 | ||
b31bfb3f | 4185 | @xref{Function Attributes}, for details of the semantics of attributes |
4186 | applying to functions. @xref{Variable Attributes}, for details of the | |
4187 | semantics of attributes applying to variables. @xref{Type Attributes}, | |
4188 | for details of the semantics of attributes applying to structure, union | |
4189 | and enumerated types. | |
4190 | ||
4191 | An @dfn{attribute specifier} is of the form | |
4192 | @code{__attribute__ ((@var{attribute-list}))}. An @dfn{attribute list} | |
4193 | is a possibly empty comma-separated sequence of @dfn{attributes}, where | |
4194 | each attribute is one of the following: | |
4195 | ||
4196 | @itemize @bullet | |
4197 | @item | |
4198 | Empty. Empty attributes are ignored. | |
4199 | ||
4200 | @item | |
4201 | A word (which may be an identifier such as @code{unused}, or a reserved | |
4202 | word such as @code{const}). | |
4203 | ||
4204 | @item | |
4205 | A word, followed by, in parentheses, parameters for the attribute. | |
4206 | These parameters take one of the following forms: | |
4207 | ||
4208 | @itemize @bullet | |
4209 | @item | |
4210 | An identifier. For example, @code{mode} attributes use this form. | |
4211 | ||
4212 | @item | |
4213 | An identifier followed by a comma and a non-empty comma-separated list | |
4214 | of expressions. For example, @code{format} attributes use this form. | |
4215 | ||
4216 | @item | |
4217 | A possibly empty comma-separated list of expressions. For example, | |
4218 | @code{format_arg} attributes use this form with the list being a single | |
4219 | integer constant expression, and @code{alias} attributes use this form | |
4220 | with the list being a single string constant. | |
4221 | @end itemize | |
4222 | @end itemize | |
4223 | ||
4224 | An @dfn{attribute specifier list} is a sequence of one or more attribute | |
4225 | specifiers, not separated by any other tokens. | |
4226 | ||
2f215800 | 4227 | In GNU C, an attribute specifier list may appear after the colon following a |
b31bfb3f | 4228 | label, other than a @code{case} or @code{default} label. The only |
4229 | attribute it makes sense to use after a label is @code{unused}. This | |
4230 | feature is intended for code generated by programs which contains labels | |
4231 | that may be unused but which is compiled with @option{-Wall}. It would | |
4232 | not normally be appropriate to use in it human-written code, though it | |
4233 | could be useful in cases where the code that jumps to the label is | |
e1c8f1c5 | 4234 | contained within an @code{#ifdef} conditional. GNU C++ only permits |
4235 | attributes on labels if the attribute specifier is immediately | |
4236 | followed by a semicolon (i.e., the label applies to an empty | |
4237 | statement). If the semicolon is missing, C++ label attributes are | |
4238 | ambiguous, as it is permissible for a declaration, which could begin | |
4239 | with an attribute list, to be labelled in C++. Declarations cannot be | |
4240 | labelled in C90 or C99, so the ambiguity does not arise there. | |
b31bfb3f | 4241 | |
4242 | An attribute specifier list may appear as part of a @code{struct}, | |
4243 | @code{union} or @code{enum} specifier. It may go either immediately | |
4244 | after the @code{struct}, @code{union} or @code{enum} keyword, or after | |
4a2849cb | 4245 | the closing brace. The former syntax is preferred. |
b31bfb3f | 4246 | Where attribute specifiers follow the closing brace, they are considered |
4247 | to relate to the structure, union or enumerated type defined, not to any | |
4248 | enclosing declaration the type specifier appears in, and the type | |
4249 | defined is not complete until after the attribute specifiers. | |
4250 | @c Otherwise, there would be the following problems: a shift/reduce | |
20dd417a | 4251 | @c conflict between attributes binding the struct/union/enum and |
b31bfb3f | 4252 | @c binding to the list of specifiers/qualifiers; and "aligned" |
4253 | @c attributes could use sizeof for the structure, but the size could be | |
4254 | @c changed later by "packed" attributes. | |
4255 | ||
4256 | Otherwise, an attribute specifier appears as part of a declaration, | |
4257 | counting declarations of unnamed parameters and type names, and relates | |
4258 | to that declaration (which may be nested in another declaration, for | |
e3c541f0 | 4259 | example in the case of a parameter declaration), or to a particular declarator |
4260 | within a declaration. Where an | |
d193f25f | 4261 | attribute specifier is applied to a parameter declared as a function or |
4262 | an array, it should apply to the function or array rather than the | |
4263 | pointer to which the parameter is implicitly converted, but this is not | |
4264 | yet correctly implemented. | |
b31bfb3f | 4265 | |
4266 | Any list of specifiers and qualifiers at the start of a declaration may | |
4267 | contain attribute specifiers, whether or not such a list may in that | |
4268 | context contain storage class specifiers. (Some attributes, however, | |
4269 | are essentially in the nature of storage class specifiers, and only make | |
4270 | sense where storage class specifiers may be used; for example, | |
4271 | @code{section}.) There is one necessary limitation to this syntax: the | |
4272 | first old-style parameter declaration in a function definition cannot | |
4273 | begin with an attribute specifier, because such an attribute applies to | |
4274 | the function instead by syntax described below (which, however, is not | |
4275 | yet implemented in this case). In some other cases, attribute | |
4276 | specifiers are permitted by this grammar but not yet supported by the | |
4277 | compiler. All attribute specifiers in this place relate to the | |
8e5fcce7 | 4278 | declaration as a whole. In the obsolescent usage where a type of |
b31bfb3f | 4279 | @code{int} is implied by the absence of type specifiers, such a list of |
4280 | specifiers and qualifiers may be an attribute specifier list with no | |
4281 | other specifiers or qualifiers. | |
4282 | ||
b19fb627 | 4283 | At present, the first parameter in a function prototype must have some |
4284 | type specifier which is not an attribute specifier; this resolves an | |
4285 | ambiguity in the interpretation of @code{void f(int | |
4286 | (__attribute__((foo)) x))}, but is subject to change. At present, if | |
4287 | the parentheses of a function declarator contain only attributes then | |
4288 | those attributes are ignored, rather than yielding an error or warning | |
4289 | or implying a single parameter of type int, but this is subject to | |
4290 | change. | |
4291 | ||
b31bfb3f | 4292 | An attribute specifier list may appear immediately before a declarator |
4293 | (other than the first) in a comma-separated list of declarators in a | |
4294 | declaration of more than one identifier using a single list of | |
ecb4f65e | 4295 | specifiers and qualifiers. Such attribute specifiers apply |
0fff59be | 4296 | only to the identifier before whose declarator they appear. For |
4297 | example, in | |
4298 | ||
4299 | @smallexample | |
4300 | __attribute__((noreturn)) void d0 (void), | |
4301 | __attribute__((format(printf, 1, 2))) d1 (const char *, ...), | |
4302 | d2 (void) | |
4303 | @end smallexample | |
4304 | ||
4305 | @noindent | |
4306 | the @code{noreturn} attribute applies to all the functions | |
ecb4f65e | 4307 | declared; the @code{format} attribute only applies to @code{d1}. |
b31bfb3f | 4308 | |
4309 | An attribute specifier list may appear immediately before the comma, | |
4310 | @code{=} or semicolon terminating the declaration of an identifier other | |
3961e70d | 4311 | than a function definition. Such attribute specifiers apply |
4312 | to the declared object or function. Where an | |
0fff59be | 4313 | assembler name for an object or function is specified (@pxref{Asm |
3961e70d | 4314 | Labels}), the attribute must follow the @code{asm} |
4315 | specification. | |
b31bfb3f | 4316 | |
4317 | An attribute specifier list may, in future, be permitted to appear after | |
4318 | the declarator in a function definition (before any old-style parameter | |
4319 | declarations or the function body). | |
4320 | ||
1fd94215 | 4321 | Attribute specifiers may be mixed with type qualifiers appearing inside |
4322 | the @code{[]} of a parameter array declarator, in the C99 construct by | |
4323 | which such qualifiers are applied to the pointer to which the array is | |
4324 | implicitly converted. Such attribute specifiers apply to the pointer, | |
4325 | not to the array, but at present this is not implemented and they are | |
4326 | ignored. | |
4327 | ||
b31bfb3f | 4328 | An attribute specifier list may appear at the start of a nested |
4329 | declarator. At present, there are some limitations in this usage: the | |
e3c541f0 | 4330 | attributes correctly apply to the declarator, but for most individual |
4331 | attributes the semantics this implies are not implemented. | |
4332 | When attribute specifiers follow the @code{*} of a pointer | |
ecb4f65e | 4333 | declarator, they may be mixed with any type qualifiers present. |
e3c541f0 | 4334 | The following describes the formal semantics of this syntax. It will make the |
b31bfb3f | 4335 | most sense if you are familiar with the formal specification of |
4336 | declarators in the ISO C standard. | |
4337 | ||
4338 | Consider (as in C99 subclause 6.7.5 paragraph 4) a declaration @code{T | |
4339 | D1}, where @code{T} contains declaration specifiers that specify a type | |
4340 | @var{Type} (such as @code{int}) and @code{D1} is a declarator that | |
4341 | contains an identifier @var{ident}. The type specified for @var{ident} | |
4342 | for derived declarators whose type does not include an attribute | |
4343 | specifier is as in the ISO C standard. | |
4344 | ||
4345 | If @code{D1} has the form @code{( @var{attribute-specifier-list} D )}, | |
4346 | and the declaration @code{T D} specifies the type | |
4347 | ``@var{derived-declarator-type-list} @var{Type}'' for @var{ident}, then | |
4348 | @code{T D1} specifies the type ``@var{derived-declarator-type-list} | |
4349 | @var{attribute-specifier-list} @var{Type}'' for @var{ident}. | |
4350 | ||
4351 | If @code{D1} has the form @code{* | |
4352 | @var{type-qualifier-and-attribute-specifier-list} D}, and the | |
4353 | declaration @code{T D} specifies the type | |
4354 | ``@var{derived-declarator-type-list} @var{Type}'' for @var{ident}, then | |
4355 | @code{T D1} specifies the type ``@var{derived-declarator-type-list} | |
5e96ea45 | 4356 | @var{type-qualifier-and-attribute-specifier-list} pointer to @var{Type}'' for |
b31bfb3f | 4357 | @var{ident}. |
4358 | ||
228c5b30 | 4359 | For example, |
0fff59be | 4360 | |
4361 | @smallexample | |
4362 | void (__attribute__((noreturn)) ****f) (void); | |
4363 | @end smallexample | |
4364 | ||
4365 | @noindent | |
4366 | specifies the type ``pointer to pointer to pointer to pointer to | |
4367 | non-returning function returning @code{void}''. As another example, | |
4368 | ||
4369 | @smallexample | |
4370 | char *__attribute__((aligned(8))) *f; | |
4371 | @end smallexample | |
4372 | ||
4373 | @noindent | |
4374 | specifies the type ``pointer to 8-byte-aligned pointer to @code{char}''. | |
e3c541f0 | 4375 | Note again that this does not work with most attributes; for example, |
4376 | the usage of @samp{aligned} and @samp{noreturn} attributes given above | |
4377 | is not yet supported. | |
4378 | ||
4379 | For compatibility with existing code written for compiler versions that | |
4380 | did not implement attributes on nested declarators, some laxity is | |
4381 | allowed in the placing of attributes. If an attribute that only applies | |
4382 | to types is applied to a declaration, it will be treated as applying to | |
4383 | the type of that declaration. If an attribute that only applies to | |
4384 | declarations is applied to the type of a declaration, it will be treated | |
4385 | as applying to that declaration; and, for compatibility with code | |
4386 | placing the attributes immediately before the identifier declared, such | |
4387 | an attribute applied to a function return type will be treated as | |
4388 | applying to the function type, and such an attribute applied to an array | |
4389 | element type will be treated as applying to the array type. If an | |
4390 | attribute that only applies to function types is applied to a | |
4391 | pointer-to-function type, it will be treated as applying to the pointer | |
4392 | target type; if such an attribute is applied to a function return type | |
4393 | that is not a pointer-to-function type, it will be treated as applying | |
4394 | to the function type. | |
b31bfb3f | 4395 | |
146ef39f | 4396 | @node Function Prototypes |
4397 | @section Prototypes and Old-Style Function Definitions | |
4398 | @cindex function prototype declarations | |
4399 | @cindex old-style function definitions | |
4400 | @cindex promotion of formal parameters | |
4401 | ||
78b1f616 | 4402 | GNU C extends ISO C to allow a function prototype to override a later |
146ef39f | 4403 | old-style non-prototype definition. Consider the following example: |
4404 | ||
a0ecd6b1 | 4405 | @smallexample |
146ef39f | 4406 | /* @r{Use prototypes unless the compiler is old-fashioned.} */ |
7223a120 | 4407 | #ifdef __STDC__ |
146ef39f | 4408 | #define P(x) x |
4409 | #else | |
4410 | #define P(x) () | |
4411 | #endif | |
4412 | ||
4413 | /* @r{Prototype function declaration.} */ | |
4414 | int isroot P((uid_t)); | |
4415 | ||
4416 | /* @r{Old-style function definition.} */ | |
4417 | int | |
12e2a142 | 4418 | isroot (x) /* @r{??? lossage here ???} */ |
146ef39f | 4419 | uid_t x; |
4420 | @{ | |
4421 | return x == 0; | |
4422 | @} | |
a0ecd6b1 | 4423 | @end smallexample |
146ef39f | 4424 | |
78b1f616 | 4425 | Suppose the type @code{uid_t} happens to be @code{short}. ISO C does |
146ef39f | 4426 | not allow this example, because subword arguments in old-style |
4427 | non-prototype definitions are promoted. Therefore in this example the | |
4428 | function definition's argument is really an @code{int}, which does not | |
4429 | match the prototype argument type of @code{short}. | |
4430 | ||
78b1f616 | 4431 | This restriction of ISO C makes it hard to write code that is portable |
146ef39f | 4432 | to traditional C compilers, because the programmer does not know |
4433 | whether the @code{uid_t} type is @code{short}, @code{int}, or | |
4434 | @code{long}. Therefore, in cases like these GNU C allows a prototype | |
4435 | to override a later old-style definition. More precisely, in GNU C, a | |
4436 | function prototype argument type overrides the argument type specified | |
4437 | by a later old-style definition if the former type is the same as the | |
4438 | latter type before promotion. Thus in GNU C the above example is | |
4439 | equivalent to the following: | |
4440 | ||
a0ecd6b1 | 4441 | @smallexample |
146ef39f | 4442 | int isroot (uid_t); |
4443 | ||
4444 | int | |
4445 | isroot (uid_t x) | |
4446 | @{ | |
4447 | return x == 0; | |
4448 | @} | |
a0ecd6b1 | 4449 | @end smallexample |
146ef39f | 4450 | |
0fff59be | 4451 | @noindent |
146ef39f | 4452 | GNU C++ does not support old-style function definitions, so this |
4453 | extension is irrelevant. | |
4454 | ||
4455 | @node C++ Comments | |
4456 | @section C++ Style Comments | |
12786727 | 4457 | @cindex @code{//} |
146ef39f | 4458 | @cindex C++ comments |
4459 | @cindex comments, C++ style | |
4460 | ||
4461 | In GNU C, you may use C++ style comments, which start with @samp{//} and | |
4462 | continue until the end of the line. Many other C implementations allow | |
455730ef | 4463 | such comments, and they are included in the 1999 C standard. However, |
4464 | C++ style comments are not recognized if you specify an @option{-std} | |
4465 | option specifying a version of ISO C before C99, or @option{-ansi} | |
32f1f35b | 4466 | (equivalent to @option{-std=c90}). |
146ef39f | 4467 | |
4468 | @node Dollar Signs | |
4469 | @section Dollar Signs in Identifier Names | |
4470 | @cindex $ | |
4471 | @cindex dollar signs in identifier names | |
4472 | @cindex identifier names, dollar signs in | |
4473 | ||
fae2383c | 4474 | In GNU C, you may normally use dollar signs in identifier names. |
4475 | This is because many traditional C implementations allow such identifiers. | |
4476 | However, dollar signs in identifiers are not supported on a few target | |
4477 | machines, typically because the target assembler does not allow them. | |
146ef39f | 4478 | |
4479 | @node Character Escapes | |
4480 | @section The Character @key{ESC} in Constants | |
4481 | ||
4482 | You can use the sequence @samp{\e} in a string or character constant to | |
4483 | stand for the ASCII character @key{ESC}. | |
4484 | ||
146ef39f | 4485 | @node Variable Attributes |
4486 | @section Specifying Attributes of Variables | |
4487 | @cindex attribute of variables | |
4488 | @cindex variable attributes | |
4489 | ||
4490 | The keyword @code{__attribute__} allows you to specify special | |
4491 | attributes of variables or structure fields. This keyword is followed | |
e7d1f980 | 4492 | by an attribute specification inside double parentheses. Some |
4493 | attributes are currently defined generically for variables. | |
4494 | Other attributes are defined for variables on particular target | |
4495 | systems. Other attributes are available for functions | |
4496 | (@pxref{Function Attributes}) and for types (@pxref{Type Attributes}). | |
4497 | Other front ends might define more attributes | |
4498 | (@pxref{C++ Extensions,,Extensions to the C++ Language}). | |
146ef39f | 4499 | |
4500 | You may also specify attributes with @samp{__} preceding and following | |
4501 | each keyword. This allows you to use them in header files without | |
4502 | being concerned about a possible macro of the same name. For example, | |
4503 | you may use @code{__aligned__} instead of @code{aligned}. | |
4504 | ||
b31bfb3f | 4505 | @xref{Attribute Syntax}, for details of the exact syntax for using |
4506 | attributes. | |
4507 | ||
146ef39f | 4508 | @table @code |
4509 | @cindex @code{aligned} attribute | |
4510 | @item aligned (@var{alignment}) | |
4511 | This attribute specifies a minimum alignment for the variable or | |
4512 | structure field, measured in bytes. For example, the declaration: | |
4513 | ||
4514 | @smallexample | |
4515 | int x __attribute__ ((aligned (16))) = 0; | |
4516 | @end smallexample | |
4517 | ||
4518 | @noindent | |
4519 | causes the compiler to allocate the global variable @code{x} on a | |
4520 | 16-byte boundary. On a 68040, this could be used in conjunction with | |
4521 | an @code{asm} expression to access the @code{move16} instruction which | |
4522 | requires 16-byte aligned operands. | |
4523 | ||
4524 | You can also specify the alignment of structure fields. For example, to | |
4525 | create a double-word aligned @code{int} pair, you could write: | |
4526 | ||
4527 | @smallexample | |
4528 | struct foo @{ int x[2] __attribute__ ((aligned (8))); @}; | |
4529 | @end smallexample | |
4530 | ||
4531 | @noindent | |
4532 | This is an alternative to creating a union with a @code{double} member | |
4533 | that forces the union to be double-word aligned. | |
4534 | ||
146ef39f | 4535 | As in the preceding examples, you can explicitly specify the alignment |
4536 | (in bytes) that you wish the compiler to use for a given variable or | |
4537 | structure field. Alternatively, you can leave out the alignment factor | |
02421213 | 4538 | and just ask the compiler to align a variable or field to the |
4539 | default alignment for the target architecture you are compiling for. | |
4540 | The default alignment is sufficient for all scalar types, but may not be | |
4541 | enough for all vector types on a target which supports vector operations. | |
4542 | The default alignment is fixed for a particular target ABI. | |
4543 | ||
4544 | Gcc also provides a target specific macro @code{__BIGGEST_ALIGNMENT__}, | |
4545 | which is the largest alignment ever used for any data type on the | |
4546 | target machine you are compiling for. For example, you could write: | |
146ef39f | 4547 | |
4548 | @smallexample | |
02421213 | 4549 | short array[3] __attribute__ ((aligned (__BIGGEST_ALIGNMENT__))); |
146ef39f | 4550 | @end smallexample |
4551 | ||
02421213 | 4552 | The compiler automatically sets the alignment for the declared |
4553 | variable or field to @code{__BIGGEST_ALIGNMENT__}. Doing this can | |
4554 | often make copy operations more efficient, because the compiler can | |
4555 | use whatever instructions copy the biggest chunks of memory when | |
4556 | performing copies to or from the variables or fields that you have | |
4557 | aligned this way. Note that the value of @code{__BIGGEST_ALIGNMENT__} | |
4558 | may change depending on command line options. | |
146ef39f | 4559 | |
2d3e8e7b | 4560 | When used on a struct, or struct member, the @code{aligned} attribute can |
4561 | only increase the alignment; in order to decrease it, the @code{packed} | |
4562 | attribute must be specified as well. When used as part of a typedef, the | |
4563 | @code{aligned} attribute can both increase and decrease alignment, and | |
4564 | specifying the @code{packed} attribute will generate a warning. | |
146ef39f | 4565 | |
4566 | Note that the effectiveness of @code{aligned} attributes may be limited | |
4567 | by inherent limitations in your linker. On many systems, the linker is | |
4568 | only able to arrange for variables to be aligned up to a certain maximum | |
4569 | alignment. (For some linkers, the maximum supported alignment may | |
4570 | be very very small.) If your linker is only able to align variables | |
4571 | up to a maximum of 8 byte alignment, then specifying @code{aligned(16)} | |
4572 | in an @code{__attribute__} will still only provide you with 8 byte | |
4573 | alignment. See your linker documentation for further information. | |
4574 | ||
15b474a2 | 4575 | The @code{aligned} attribute can also be used for functions |
097b5c8b | 4576 | (@pxref{Function Attributes}.) |
4577 | ||
7acb29a3 | 4578 | @item cleanup (@var{cleanup_function}) |
4579 | @cindex @code{cleanup} attribute | |
4580 | The @code{cleanup} attribute runs a function when the variable goes | |
4581 | out of scope. This attribute can only be applied to auto function | |
4582 | scope variables; it may not be applied to parameters or variables | |
4583 | with static storage duration. The function must take one parameter, | |
4584 | a pointer to a type compatible with the variable. The return value | |
4585 | of the function (if any) is ignored. | |
4586 | ||
4587 | If @option{-fexceptions} is enabled, then @var{cleanup_function} | |
4588 | will be run during the stack unwinding that happens during the | |
4589 | processing of the exception. Note that the @code{cleanup} attribute | |
4590 | does not allow the exception to be caught, only to perform an action. | |
4591 | It is undefined what happens if @var{cleanup_function} does not | |
4592 | return normally. | |
4593 | ||
e7d1f980 | 4594 | @item common |
4595 | @itemx nocommon | |
4596 | @cindex @code{common} attribute | |
4597 | @cindex @code{nocommon} attribute | |
4598 | @opindex fcommon | |
4599 | @opindex fno-common | |
4600 | The @code{common} attribute requests GCC to place a variable in | |
4601 | ``common'' storage. The @code{nocommon} attribute requests the | |
01e3cadf | 4602 | opposite---to allocate space for it directly. |
e7d1f980 | 4603 | |
7a0ad664 | 4604 | These attributes override the default chosen by the |
e7d1f980 | 4605 | @option{-fno-common} and @option{-fcommon} flags respectively. |
4606 | ||
4607 | @item deprecated | |
45c4e798 | 4608 | @itemx deprecated (@var{msg}) |
e7d1f980 | 4609 | @cindex @code{deprecated} attribute |
4610 | The @code{deprecated} attribute results in a warning if the variable | |
4611 | is used anywhere in the source file. This is useful when identifying | |
4612 | variables that are expected to be removed in a future version of a | |
4613 | program. The warning also includes the location of the declaration | |
4614 | of the deprecated variable, to enable users to easily find further | |
4615 | information about why the variable is deprecated, or what they should | |
ea1c20d0 | 4616 | do instead. Note that the warning only occurs for uses: |
e7d1f980 | 4617 | |
4618 | @smallexample | |
4619 | extern int old_var __attribute__ ((deprecated)); | |
4620 | extern int old_var; | |
4621 | int new_fn () @{ return old_var; @} | |
4622 | @end smallexample | |
4623 | ||
45c4e798 | 4624 | results in a warning on line 3 but not line 2. The optional msg |
4625 | argument, which must be a string, will be printed in the warning if | |
4626 | present. | |
e7d1f980 | 4627 | |
4628 | The @code{deprecated} attribute can also be used for functions and | |
4629 | types (@pxref{Function Attributes}, @pxref{Type Attributes}.) | |
4630 | ||
146ef39f | 4631 | @item mode (@var{mode}) |
4632 | @cindex @code{mode} attribute | |
4633 | This attribute specifies the data type for the declaration---whichever | |
4634 | type corresponds to the mode @var{mode}. This in effect lets you | |
4635 | request an integer or floating point type according to its width. | |
4636 | ||
4637 | You may also specify a mode of @samp{byte} or @samp{__byte__} to | |
4638 | indicate the mode corresponding to a one-byte integer, @samp{word} or | |
4639 | @samp{__word__} for the mode of a one-word integer, and @samp{pointer} | |
4640 | or @samp{__pointer__} for the mode used to represent pointers. | |
4641 | ||
146ef39f | 4642 | @item packed |
4643 | @cindex @code{packed} attribute | |
4644 | The @code{packed} attribute specifies that a variable or structure field | |
4645 | should have the smallest possible alignment---one byte for a variable, | |
4646 | and one bit for a field, unless you specify a larger value with the | |
4647 | @code{aligned} attribute. | |
4648 | ||
4649 | Here is a structure in which the field @code{x} is packed, so that it | |
4650 | immediately follows @code{a}: | |
4651 | ||
a0ecd6b1 | 4652 | @smallexample |
146ef39f | 4653 | struct foo |
4654 | @{ | |
4655 | char a; | |
4656 | int x[2] __attribute__ ((packed)); | |
4657 | @}; | |
a0ecd6b1 | 4658 | @end smallexample |
146ef39f | 4659 | |
9fd767c5 | 4660 | @emph{Note:} The 4.1, 4.2 and 4.3 series of GCC ignore the |
4661 | @code{packed} attribute on bit-fields of type @code{char}. This has | |
4662 | been fixed in GCC 4.4 but the change can lead to differences in the | |
8898b2ef | 4663 | structure layout. See the documentation of |
9fd767c5 | 4664 | @option{-Wpacked-bitfield-compat} for more information. |
4665 | ||
67791935 | 4666 | @item section ("@var{section-name}") |
146ef39f | 4667 | @cindex @code{section} variable attribute |
4668 | Normally, the compiler places the objects it generates in sections like | |
4669 | @code{data} and @code{bss}. Sometimes, however, you need additional sections, | |
4670 | or you need certain particular variables to appear in special sections, | |
4671 | for example to map to special hardware. The @code{section} | |
4672 | attribute specifies that a variable (or function) lives in a particular | |
4673 | section. For example, this small program uses several specific section names: | |
4674 | ||
4675 | @smallexample | |
4676 | struct duart a __attribute__ ((section ("DUART_A"))) = @{ 0 @}; | |
4677 | struct duart b __attribute__ ((section ("DUART_B"))) = @{ 0 @}; | |
4678 | char stack[10000] __attribute__ ((section ("STACK"))) = @{ 0 @}; | |
e5e13288 | 4679 | int init_data __attribute__ ((section ("INITDATA"))); |
146ef39f | 4680 | |
4681 | main() | |
4682 | @{ | |
12e2a142 | 4683 | /* @r{Initialize stack pointer} */ |
146ef39f | 4684 | init_sp (stack + sizeof (stack)); |
4685 | ||
12e2a142 | 4686 | /* @r{Initialize initialized data} */ |
146ef39f | 4687 | memcpy (&init_data, &data, &edata - &data); |
4688 | ||
12e2a142 | 4689 | /* @r{Turn on the serial ports} */ |
146ef39f | 4690 | init_duart (&a); |
4691 | init_duart (&b); | |
4692 | @} | |
4693 | @end smallexample | |
4694 | ||
4695 | @noindent | |
e5e13288 | 4696 | Use the @code{section} attribute with |
4697 | @emph{global} variables and not @emph{local} variables, | |
4698 | as shown in the example. | |
146ef39f | 4699 | |
e5e13288 | 4700 | You may use the @code{section} attribute with initialized or |
4701 | uninitialized global variables but the linker requires | |
146ef39f | 4702 | each object be defined once, with the exception that uninitialized |
4703 | variables tentatively go in the @code{common} (or @code{bss}) section | |
e5e13288 | 4704 | and can be multiply ``defined''. Using the @code{section} attribute |
4705 | will change what section the variable goes into and may cause the | |
4706 | linker to issue an error if an uninitialized variable has multiple | |
4707 | definitions. You can force a variable to be initialized with the | |
4708 | @option{-fno-common} flag or the @code{nocommon} attribute. | |
146ef39f | 4709 | |
4710 | Some file formats do not support arbitrary sections so the @code{section} | |
4711 | attribute is not available on all platforms. | |
4712 | If you need to map the entire contents of a module to a particular | |
4713 | section, consider using the facilities of the linker instead. | |
4714 | ||
87135be0 | 4715 | @item shared |
4716 | @cindex @code{shared} variable attribute | |
c20b542c | 4717 | On Microsoft Windows, in addition to putting variable definitions in a named |
3b0848a2 | 4718 | section, the section can also be shared among all running copies of an |
0858e3a2 | 4719 | executable or DLL@. For example, this small program defines shared data |
67791935 | 4720 | by putting it in a named section @code{shared} and marking the section |
87135be0 | 4721 | shareable: |
4722 | ||
4723 | @smallexample | |
4724 | int foo __attribute__((section ("shared"), shared)) = 0; | |
4725 | ||
4726 | int | |
4727 | main() | |
4728 | @{ | |
12e2a142 | 4729 | /* @r{Read and write foo. All running |
4730 | copies see the same value.} */ | |
87135be0 | 4731 | return 0; |
4732 | @} | |
4733 | @end smallexample | |
4734 | ||
4735 | @noindent | |
4736 | You may only use the @code{shared} attribute along with @code{section} | |
3b0848a2 | 4737 | attribute with a fully initialized global definition because of the way |
87135be0 | 4738 | linkers work. See @code{section} attribute for more information. |
4739 | ||
c20b542c | 4740 | The @code{shared} attribute is only available on Microsoft Windows@. |
87135be0 | 4741 | |
e7d1f980 | 4742 | @item tls_model ("@var{tls_model}") |
4743 | @cindex @code{tls_model} attribute | |
4744 | The @code{tls_model} attribute sets thread-local storage model | |
4745 | (@pxref{Thread-Local}) of a particular @code{__thread} variable, | |
bfe513a4 | 4746 | overriding @option{-ftls-model=} command-line switch on a per-variable |
e7d1f980 | 4747 | basis. |
4748 | The @var{tls_model} argument should be one of @code{global-dynamic}, | |
4749 | @code{local-dynamic}, @code{initial-exec} or @code{local-exec}. | |
4750 | ||
4751 | Not all targets support this attribute. | |
4752 | ||
146ef39f | 4753 | @item unused |
4754 | This attribute, attached to a variable, means that the variable is meant | |
37744367 | 4755 | to be possibly unused. GCC will not produce a warning for this |
146ef39f | 4756 | variable. |
4757 | ||
b7aa2b22 | 4758 | @item used |
4759 | This attribute, attached to a variable, means that the variable must be | |
4760 | emitted even if it appears that the variable is not referenced. | |
4761 | ||
c86f0926 | 4762 | When applied to a static data member of a C++ class template, the |
4763 | attribute also means that the member will be instantiated if the | |
4764 | class itself is instantiated. | |
4765 | ||
ae4718db | 4766 | @item vector_size (@var{bytes}) |
4767 | This attribute specifies the vector size for the variable, measured in | |
4768 | bytes. For example, the declaration: | |
4769 | ||
4770 | @smallexample | |
4771 | int foo __attribute__ ((vector_size (16))); | |
4772 | @end smallexample | |
4773 | ||
4774 | @noindent | |
4775 | causes the compiler to set the mode for @code{foo}, to be 16 bytes, | |
4776 | divided into @code{int} sized units. Assuming a 32-bit int (a vector of | |
4777 | 4 units of 4 bytes), the corresponding mode of @code{foo} will be V4SI@. | |
4778 | ||
4779 | This attribute is only applicable to integral and float scalars, | |
4780 | although arrays, pointers, and function return values are allowed in | |
4781 | conjunction with this construct. | |
4782 | ||
4783 | Aggregates with this attribute are invalid, even if they are of the same | |
4784 | size as a corresponding scalar. For example, the declaration: | |
4785 | ||
4786 | @smallexample | |
6bdacb9b | 4787 | struct S @{ int a; @}; |
ae4718db | 4788 | struct S __attribute__ ((vector_size (16))) foo; |
4789 | @end smallexample | |
4790 | ||
4791 | @noindent | |
4792 | is invalid even if the size of the structure is the same as the size of | |
4793 | the @code{int}. | |
4794 | ||
04868974 | 4795 | @item selectany |
4796 | The @code{selectany} attribute causes an initialized global variable to | |
4797 | have link-once semantics. When multiple definitions of the variable are | |
4798 | encountered by the linker, the first is selected and the remainder are | |
4799 | discarded. Following usage by the Microsoft compiler, the linker is told | |
4800 | @emph{not} to warn about size or content differences of the multiple | |
4801 | definitions. | |
4802 | ||
4803 | Although the primary usage of this attribute is for POD types, the | |
4804 | attribute can also be applied to global C++ objects that are initialized | |
4805 | by a constructor. In this case, the static initialization and destruction | |
4806 | code for the object is emitted in each translation defining the object, | |
4807 | but the calls to the constructor and destructor are protected by a | |
7bd4091f | 4808 | link-once guard variable. |
04868974 | 4809 | |
4810 | The @code{selectany} attribute is only available on Microsoft Windows | |
4811 | targets. You can use @code{__declspec (selectany)} as a synonym for | |
4812 | @code{__attribute__ ((selectany))} for compatibility with other | |
4813 | compilers. | |
4814 | ||
146ef39f | 4815 | @item weak |
e66bbea3 | 4816 | The @code{weak} attribute is described in @ref{Function Attributes}. |
195d932a | 4817 | |
4818 | @item dllimport | |
e66bbea3 | 4819 | The @code{dllimport} attribute is described in @ref{Function Attributes}. |
195d932a | 4820 | |
b44d6960 | 4821 | @item dllexport |
e66bbea3 | 4822 | The @code{dllexport} attribute is described in @ref{Function Attributes}. |
195d932a | 4823 | |
e7d1f980 | 4824 | @end table |
4825 | ||
8516b1c4 | 4826 | @anchor{AVR Variable Attributes} |
91f3009d | 4827 | @subsection AVR Variable Attributes |
4828 | ||
4829 | @table @code | |
4830 | @item progmem | |
4831 | @cindex @code{progmem} AVR variable attribute | |
8516b1c4 | 4832 | The @code{progmem} attribute is used on the AVR to place read-only |
4833 | data in the non-volatile program memory (flash). The @code{progmem} | |
4834 | attribute accomplishes this by putting respective variables into a | |
4835 | section whose name starts with @code{.progmem}. | |
4836 | ||
6ee532ba | 4837 | This attribute works similar to the @code{section} attribute |
8516b1c4 | 4838 | but adds additional checking. Notice that just like the |
4839 | @code{section} attribute, @code{progmem} affects the location | |
4840 | of the data but not how this data is accessed. | |
4841 | ||
6ee532ba | 4842 | In order to read data located with the @code{progmem} attribute |
4843 | (inline) assembler must be used. | |
4844 | @example | |
6222cbcc | 4845 | /* Use custom macros from @w{@uref{http://nongnu.org/avr-libc/user-manual,AVR-LibC}} */ |
6ee532ba | 4846 | #include <avr/pgmspace.h> |
4847 | ||
4848 | /* Locate var in flash memory */ | |
4849 | const int var[2] PROGMEM = @{ 1, 2 @}; | |
4850 | ||
4851 | int read_var (int i) | |
4852 | @{ | |
4853 | /* Access var[] by accessor macro from avr/pgmspace.h */ | |
4854 | return (int) pgm_read_word (& var[i]); | |
4855 | @} | |
4856 | @end example | |
4857 | ||
8516b1c4 | 4858 | AVR is a Harvard architecture processor and data and read-only data |
4859 | normally resides in the data memory (RAM). | |
6ee532ba | 4860 | |
4861 | See also the @ref{AVR Named Address Spaces} section for | |
4862 | an alternate way to locate and access data in flash memory. | |
91f3009d | 4863 | @end table |
4864 | ||
fc8aef7f | 4865 | @subsection Blackfin Variable Attributes |
4866 | ||
4867 | Three attributes are currently defined for the Blackfin. | |
4868 | ||
4869 | @table @code | |
4870 | @item l1_data | |
171b9b78 | 4871 | @itemx l1_data_A |
4872 | @itemx l1_data_B | |
fc8aef7f | 4873 | @cindex @code{l1_data} variable attribute |
4874 | @cindex @code{l1_data_A} variable attribute | |
4875 | @cindex @code{l1_data_B} variable attribute | |
4876 | Use these attributes on the Blackfin to place the variable into L1 Data SRAM. | |
4877 | Variables with @code{l1_data} attribute will be put into the specific section | |
4878 | named @code{.l1.data}. Those with @code{l1_data_A} attribute will be put into | |
4879 | the specific section named @code{.l1.data.A}. Those with @code{l1_data_B} | |
4880 | attribute will be put into the specific section named @code{.l1.data.B}. | |
59fbccf3 | 4881 | |
4882 | @item l2 | |
4883 | @cindex @code{l2} variable attribute | |
4884 | Use this attribute on the Blackfin to place the variable into L2 SRAM. | |
4885 | Variables with @code{l2} attribute will be put into the specific section | |
4886 | named @code{.l2.data}. | |
fc8aef7f | 4887 | @end table |
4888 | ||
e7d1f980 | 4889 | @subsection M32R/D Variable Attributes |
097cea9f | 4890 | |
b3d47662 | 4891 | One attribute is currently defined for the M32R/D@. |
e7d1f980 | 4892 | |
4893 | @table @code | |
097cea9f | 4894 | @item model (@var{model-name}) |
4895 | @cindex variable addressability on the M32R/D | |
4896 | Use this attribute on the M32R/D to set the addressability of an object. | |
4897 | The identifier @var{model-name} is one of @code{small}, @code{medium}, | |
4898 | or @code{large}, representing each of the code models. | |
4899 | ||
4900 | Small model objects live in the lower 16MB of memory (so that their | |
4901 | addresses can be loaded with the @code{ld24} instruction). | |
4902 | ||
3b0848a2 | 4903 | Medium and large model objects may live anywhere in the 32-bit address space |
097cea9f | 4904 | (the compiler will generate @code{seth/add3} instructions to load their |
4905 | addresses). | |
e7d1f980 | 4906 | @end table |
097cea9f | 4907 | |
7c3116fb | 4908 | @anchor{MeP Variable Attributes} |
4909 | @subsection MeP Variable Attributes | |
4910 | ||
4911 | The MeP target has a number of addressing modes and busses. The | |
4912 | @code{near} space spans the standard memory space's first 16 megabytes | |
4913 | (24 bits). The @code{far} space spans the entire 32-bit memory space. | |
4914 | The @code{based} space is a 128 byte region in the memory space which | |
4915 | is addressed relative to the @code{$tp} register. The @code{tiny} | |
4916 | space is a 65536 byte region relative to the @code{$gp} register. In | |
4917 | addition to these memory regions, the MeP target has a separate 16-bit | |
4918 | control bus which is specified with @code{cb} attributes. | |
4919 | ||
4920 | @table @code | |
4921 | ||
4922 | @item based | |
4923 | Any variable with the @code{based} attribute will be assigned to the | |
4924 | @code{.based} section, and will be accessed with relative to the | |
4925 | @code{$tp} register. | |
4926 | ||
4927 | @item tiny | |
4928 | Likewise, the @code{tiny} attribute assigned variables to the | |
4929 | @code{.tiny} section, relative to the @code{$gp} register. | |
4930 | ||
4931 | @item near | |
4932 | Variables with the @code{near} attribute are assumed to have addresses | |
4933 | that fit in a 24-bit addressing mode. This is the default for large | |
4934 | variables (@code{-mtiny=4} is the default) but this attribute can | |
4935 | override @code{-mtiny=} for small variables, or override @code{-ml}. | |
4936 | ||
4937 | @item far | |
4938 | Variables with the @code{far} attribute are addressed using a full | |
4939 | 32-bit address. Since this covers the entire memory space, this | |
4940 | allows modules to make no assumptions about where variables might be | |
4941 | stored. | |
4942 | ||
4943 | @item io | |
171b9b78 | 4944 | @itemx io (@var{addr}) |
7c3116fb | 4945 | Variables with the @code{io} attribute are used to address |
4946 | memory-mapped peripherals. If an address is specified, the variable | |
4947 | is assigned that address, else it is not assigned an address (it is | |
4948 | assumed some other module will assign an address). Example: | |
4949 | ||
4950 | @example | |
4951 | int timer_count __attribute__((io(0x123))); | |
4952 | @end example | |
4953 | ||
4954 | @item cb | |
171b9b78 | 4955 | @itemx cb (@var{addr}) |
7c3116fb | 4956 | Variables with the @code{cb} attribute are used to access the control |
4957 | bus, using special instructions. @code{addr} indicates the control bus | |
4958 | address. Example: | |
4959 | ||
4960 | @example | |
4961 | int cpu_clock __attribute__((cb(0x123))); | |
4962 | @end example | |
4963 | ||
4964 | @end table | |
4965 | ||
c4e8a4d4 | 4966 | @anchor{i386 Variable Attributes} |
b09c5db2 | 4967 | @subsection i386 Variable Attributes |
4968 | ||
4969 | Two attributes are currently defined for i386 configurations: | |
4970 | @code{ms_struct} and @code{gcc_struct} | |
4971 | ||
e7d1f980 | 4972 | @table @code |
b09c5db2 | 4973 | @item ms_struct |
4974 | @itemx gcc_struct | |
e7d1f980 | 4975 | @cindex @code{ms_struct} attribute |
4976 | @cindex @code{gcc_struct} attribute | |
b09c5db2 | 4977 | |
4978 | If @code{packed} is used on a structure, or if bit-fields are used | |
4979 | it may be that the Microsoft ABI packs them differently | |
4980 | than GCC would normally pack them. Particularly when moving packed | |
4981 | data between functions compiled with GCC and the native Microsoft compiler | |
4982 | (either via function call or as data in a file), it may be necessary to access | |
4983 | either format. | |
4984 | ||
c20b542c | 4985 | Currently @option{-m[no-]ms-bitfields} is provided for the Microsoft Windows X86 |
b09c5db2 | 4986 | compilers to match the native Microsoft compiler. |
7bd4091f | 4987 | |
4988 | The Microsoft structure layout algorithm is fairly simple with the exception | |
4989 | of the bitfield packing: | |
4990 | ||
4991 | The padding and alignment of members of structures and whether a bit field | |
4992 | can straddle a storage-unit boundary | |
4993 | ||
4994 | @enumerate | |
4995 | @item Structure members are stored sequentially in the order in which they are | |
4996 | declared: the first member has the lowest memory address and the last member | |
4997 | the highest. | |
4998 | ||
4999 | @item Every data object has an alignment-requirement. The alignment-requirement | |
5000 | for all data except structures, unions, and arrays is either the size of the | |
5001 | object or the current packing size (specified with either the aligned attribute | |
5002 | or the pack pragma), whichever is less. For structures, unions, and arrays, | |
5003 | the alignment-requirement is the largest alignment-requirement of its members. | |
5004 | Every object is allocated an offset so that: | |
5005 | ||
5006 | offset % alignment-requirement == 0 | |
5007 | ||
5008 | @item Adjacent bit fields are packed into the same 1-, 2-, or 4-byte allocation | |
5009 | unit if the integral types are the same size and if the next bit field fits | |
5010 | into the current allocation unit without crossing the boundary imposed by the | |
5011 | common alignment requirements of the bit fields. | |
5012 | @end enumerate | |
5013 | ||
5014 | Handling of zero-length bitfields: | |
5015 | ||
5016 | MSVC interprets zero-length bitfields in the following ways: | |
5017 | ||
5018 | @enumerate | |
5019 | @item If a zero-length bitfield is inserted between two bitfields that would | |
5020 | normally be coalesced, the bitfields will not be coalesced. | |
5021 | ||
5022 | For example: | |
5023 | ||
5024 | @smallexample | |
5025 | struct | |
5026 | @{ | |
5027 | unsigned long bf_1 : 12; | |
5028 | unsigned long : 0; | |
5029 | unsigned long bf_2 : 12; | |
5030 | @} t1; | |
5031 | @end smallexample | |
5032 | ||
5033 | The size of @code{t1} would be 8 bytes with the zero-length bitfield. If the | |
5034 | zero-length bitfield were removed, @code{t1}'s size would be 4 bytes. | |
5035 | ||
5036 | @item If a zero-length bitfield is inserted after a bitfield, @code{foo}, and the | |
5037 | alignment of the zero-length bitfield is greater than the member that follows it, | |
5038 | @code{bar}, @code{bar} will be aligned as the type of the zero-length bitfield. | |
5039 | ||
5040 | For example: | |
5041 | ||
5042 | @smallexample | |
5043 | struct | |
5044 | @{ | |
5045 | char foo : 4; | |
5046 | short : 0; | |
5047 | char bar; | |
5048 | @} t2; | |
5049 | ||
5050 | struct | |
5051 | @{ | |
5052 | char foo : 4; | |
5053 | short : 0; | |
5054 | double bar; | |
5055 | @} t3; | |
5056 | @end smallexample | |
5057 | ||
5058 | For @code{t2}, @code{bar} will be placed at offset 2, rather than offset 1. | |
5059 | Accordingly, the size of @code{t2} will be 4. For @code{t3}, the zero-length | |
5060 | bitfield will not affect the alignment of @code{bar} or, as a result, the size | |
5061 | of the structure. | |
5062 | ||
5063 | Taking this into account, it is important to note the following: | |
5064 | ||
5065 | @enumerate | |
5066 | @item If a zero-length bitfield follows a normal bitfield, the type of the | |
5067 | zero-length bitfield may affect the alignment of the structure as whole. For | |
5068 | example, @code{t2} has a size of 4 bytes, since the zero-length bitfield follows a | |
5069 | normal bitfield, and is of type short. | |
5070 | ||
5071 | @item Even if a zero-length bitfield is not followed by a normal bitfield, it may | |
5072 | still affect the alignment of the structure: | |
5073 | ||
5074 | @smallexample | |
5075 | struct | |
5076 | @{ | |
5077 | char foo : 6; | |
5078 | long : 0; | |
5079 | @} t4; | |
5080 | @end smallexample | |
5081 | ||
5082 | Here, @code{t4} will take up 4 bytes. | |
5083 | @end enumerate | |
5084 | ||
5085 | @item Zero-length bitfields following non-bitfield members are ignored: | |
5086 | ||
5087 | @smallexample | |
5088 | struct | |
5089 | @{ | |
5090 | char foo; | |
5091 | long : 0; | |
5092 | char bar; | |
5093 | @} t5; | |
5094 | @end smallexample | |
5095 | ||
5096 | Here, @code{t5} will take up 2 bytes. | |
5097 | @end enumerate | |
146ef39f | 5098 | @end table |
5099 | ||
c4e8a4d4 | 5100 | @subsection PowerPC Variable Attributes |
5101 | ||
268b2718 | 5102 | Three attributes currently are defined for PowerPC configurations: |
5103 | @code{altivec}, @code{ms_struct} and @code{gcc_struct}. | |
c4e8a4d4 | 5104 | |
268b2718 | 5105 | For full documentation of the struct attributes please see the |
e66bbea3 | 5106 | documentation in @ref{i386 Variable Attributes}. |
268b2718 | 5107 | |
5108 | For documentation of @code{altivec} attribute please see the | |
e66bbea3 | 5109 | documentation in @ref{PowerPC Type Attributes}. |
c4e8a4d4 | 5110 | |
644459d0 | 5111 | @subsection SPU Variable Attributes |
5112 | ||
5113 | The SPU supports the @code{spu_vector} attribute for variables. For | |
e66bbea3 | 5114 | documentation of this attribute please see the documentation in |
5115 | @ref{SPU Type Attributes}. | |
644459d0 | 5116 | |
3c1df5aa | 5117 | @subsection Xstormy16 Variable Attributes |
5118 | ||
5119 | One attribute is currently defined for xstormy16 configurations: | |
e66bbea3 | 5120 | @code{below100}. |
3c1df5aa | 5121 | |
5122 | @table @code | |
5123 | @item below100 | |
5124 | @cindex @code{below100} attribute | |
5125 | ||
5126 | If a variable has the @code{below100} attribute (@code{BELOW100} is | |
5127 | allowed also), GCC will place the variable in the first 0x100 bytes of | |
5128 | memory and use special opcodes to access it. Such variables will be | |
5129 | placed in either the @code{.bss_below100} section or the | |
5130 | @code{.data_below100} section. | |
5131 | ||
5132 | @end table | |
5133 | ||
146ef39f | 5134 | @node Type Attributes |
5135 | @section Specifying Attributes of Types | |
5136 | @cindex attribute of types | |
5137 | @cindex type attributes | |
5138 | ||
5139 | The keyword @code{__attribute__} allows you to specify special | |
4a2849cb | 5140 | attributes of @code{struct} and @code{union} types when you define |
5141 | such types. This keyword is followed by an attribute specification | |
5142 | inside double parentheses. Seven attributes are currently defined for | |
5143 | types: @code{aligned}, @code{packed}, @code{transparent_union}, | |
5144 | @code{unused}, @code{deprecated}, @code{visibility}, and | |
5145 | @code{may_alias}. Other attributes are defined for functions | |
5146 | (@pxref{Function Attributes}) and for variables (@pxref{Variable | |
5147 | Attributes}). | |
146ef39f | 5148 | |
5149 | You may also specify any one of these attributes with @samp{__} | |
5150 | preceding and following its keyword. This allows you to use these | |
5151 | attributes in header files without being concerned about a possible | |
5152 | macro of the same name. For example, you may use @code{__aligned__} | |
5153 | instead of @code{aligned}. | |
5154 | ||
881eb642 | 5155 | You may specify type attributes in an enum, struct or union type |
5156 | declaration or definition, or for other types in a @code{typedef} | |
5157 | declaration. | |
146ef39f | 5158 | |
4a2849cb | 5159 | For an enum, struct or union type, you may specify attributes either |
5160 | between the enum, struct or union tag and the name of the type, or | |
5161 | just past the closing curly brace of the @emph{definition}. The | |
5162 | former syntax is preferred. | |
257b057a | 5163 | |
b31bfb3f | 5164 | @xref{Attribute Syntax}, for details of the exact syntax for using |
5165 | attributes. | |
5166 | ||
146ef39f | 5167 | @table @code |
5168 | @cindex @code{aligned} attribute | |
5169 | @item aligned (@var{alignment}) | |
5170 | This attribute specifies a minimum alignment (in bytes) for variables | |
5171 | of the specified type. For example, the declarations: | |
5172 | ||
5173 | @smallexample | |
c8b8ebd3 | 5174 | struct S @{ short f[3]; @} __attribute__ ((aligned (8))); |
5175 | typedef int more_aligned_int __attribute__ ((aligned (8))); | |
146ef39f | 5176 | @end smallexample |
5177 | ||
5178 | @noindent | |
7223a120 | 5179 | force the compiler to insure (as far as it can) that each variable whose |
146ef39f | 5180 | type is @code{struct S} or @code{more_aligned_int} will be allocated and |
7800959d | 5181 | aligned @emph{at least} on a 8-byte boundary. On a SPARC, having all |
146ef39f | 5182 | variables of type @code{struct S} aligned to 8-byte boundaries allows |
5183 | the compiler to use the @code{ldd} and @code{std} (doubleword load and | |
5184 | store) instructions when copying one variable of type @code{struct S} to | |
5185 | another, thus improving run-time efficiency. | |
5186 | ||
5187 | Note that the alignment of any given @code{struct} or @code{union} type | |
78b1f616 | 5188 | is required by the ISO C standard to be at least a perfect multiple of |
146ef39f | 5189 | the lowest common multiple of the alignments of all of the members of |
5190 | the @code{struct} or @code{union} in question. This means that you @emph{can} | |
5191 | effectively adjust the alignment of a @code{struct} or @code{union} | |
5192 | type by attaching an @code{aligned} attribute to any one of the members | |
5193 | of such a type, but the notation illustrated in the example above is a | |
5194 | more obvious, intuitive, and readable way to request the compiler to | |
5195 | adjust the alignment of an entire @code{struct} or @code{union} type. | |
5196 | ||
5197 | As in the preceding example, you can explicitly specify the alignment | |
5198 | (in bytes) that you wish the compiler to use for a given @code{struct} | |
5199 | or @code{union} type. Alternatively, you can leave out the alignment factor | |
5200 | and just ask the compiler to align a type to the maximum | |
5201 | useful alignment for the target machine you are compiling for. For | |
5202 | example, you could write: | |
5203 | ||
5204 | @smallexample | |
5205 | struct S @{ short f[3]; @} __attribute__ ((aligned)); | |
5206 | @end smallexample | |
5207 | ||
5208 | Whenever you leave out the alignment factor in an @code{aligned} | |
5209 | attribute specification, the compiler automatically sets the alignment | |
5210 | for the type to the largest alignment which is ever used for any data | |
5211 | type on the target machine you are compiling for. Doing this can often | |
5212 | make copy operations more efficient, because the compiler can use | |
5213 | whatever instructions copy the biggest chunks of memory when performing | |
5214 | copies to or from the variables which have types that you have aligned | |
5215 | this way. | |
5216 | ||
5217 | In the example above, if the size of each @code{short} is 2 bytes, then | |
5218 | the size of the entire @code{struct S} type is 6 bytes. The smallest | |
5219 | power of two which is greater than or equal to that is 8, so the | |
5220 | compiler sets the alignment for the entire @code{struct S} type to 8 | |
5221 | bytes. | |
5222 | ||
5223 | Note that although you can ask the compiler to select a time-efficient | |
5224 | alignment for a given type and then declare only individual stand-alone | |
5225 | objects of that type, the compiler's ability to select a time-efficient | |
5226 | alignment is primarily useful only when you plan to create arrays of | |
5227 | variables having the relevant (efficiently aligned) type. If you | |
5228 | declare or use arrays of variables of an efficiently-aligned type, then | |
5229 | it is likely that your program will also be doing pointer arithmetic (or | |
5230 | subscripting, which amounts to the same thing) on pointers to the | |
5231 | relevant type, and the code that the compiler generates for these | |
5232 | pointer arithmetic operations will often be more efficient for | |
5233 | efficiently-aligned types than for other types. | |
5234 | ||
5235 | The @code{aligned} attribute can only increase the alignment; but you | |
5236 | can decrease it by specifying @code{packed} as well. See below. | |
5237 | ||
5238 | Note that the effectiveness of @code{aligned} attributes may be limited | |
5239 | by inherent limitations in your linker. On many systems, the linker is | |
5240 | only able to arrange for variables to be aligned up to a certain maximum | |
5241 | alignment. (For some linkers, the maximum supported alignment may | |
5242 | be very very small.) If your linker is only able to align variables | |
5243 | up to a maximum of 8 byte alignment, then specifying @code{aligned(16)} | |
5244 | in an @code{__attribute__} will still only provide you with 8 byte | |
5245 | alignment. See your linker documentation for further information. | |
5246 | ||
5247 | @item packed | |
942ab15b | 5248 | This attribute, attached to @code{struct} or @code{union} type |
7c68c953 | 5249 | definition, specifies that each member (other than zero-width bitfields) |
5250 | of the structure or union is placed to minimize the memory required. When | |
5251 | attached to an @code{enum} definition, it indicates that the smallest | |
5252 | integral type should be used. | |
146ef39f | 5253 | |
67791935 | 5254 | @opindex fshort-enums |
146ef39f | 5255 | Specifying this attribute for @code{struct} and @code{union} types is |
5256 | equivalent to specifying the @code{packed} attribute on each of the | |
67791935 | 5257 | structure or union members. Specifying the @option{-fshort-enums} |
146ef39f | 5258 | flag on the line is equivalent to specifying the @code{packed} |
5259 | attribute on all @code{enum} definitions. | |
5260 | ||
942ab15b | 5261 | In the following example @code{struct my_packed_struct}'s members are |
5262 | packed closely together, but the internal layout of its @code{s} member | |
01e3cadf | 5263 | is not packed---to do that, @code{struct my_unpacked_struct} would need to |
942ab15b | 5264 | be packed too. |
5265 | ||
5266 | @smallexample | |
5267 | struct my_unpacked_struct | |
5268 | @{ | |
5269 | char c; | |
5270 | int i; | |
5271 | @}; | |
5272 | ||
c3c702dd | 5273 | struct __attribute__ ((__packed__)) my_packed_struct |
942ab15b | 5274 | @{ |
5275 | char c; | |
5276 | int i; | |
5277 | struct my_unpacked_struct s; | |
5278 | @}; | |
5279 | @end smallexample | |
5280 | ||
68576faf | 5281 | You may only specify this attribute on the definition of an @code{enum}, |
942ab15b | 5282 | @code{struct} or @code{union}, not on a @code{typedef} which does not |
5283 | also define the enumerated type, structure or union. | |
146ef39f | 5284 | |
5285 | @item transparent_union | |
5286 | This attribute, attached to a @code{union} type definition, indicates | |
5287 | that any function parameter having that union type causes calls to that | |
5288 | function to be treated in a special way. | |
5289 | ||
5290 | First, the argument corresponding to a transparent union type can be of | |
5291 | any type in the union; no cast is required. Also, if the union contains | |
5292 | a pointer type, the corresponding argument can be a null pointer | |
5293 | constant or a void pointer expression; and if the union contains a void | |
5294 | pointer type, the corresponding argument can be any pointer expression. | |
5295 | If the union member type is a pointer, qualifiers like @code{const} on | |
5296 | the referenced type must be respected, just as with normal pointer | |
5297 | conversions. | |
5298 | ||
5299 | Second, the argument is passed to the function using the calling | |
ea1c20d0 | 5300 | conventions of the first member of the transparent union, not the calling |
146ef39f | 5301 | conventions of the union itself. All members of the union must have the |
5302 | same machine representation; this is necessary for this argument passing | |
5303 | to work properly. | |
5304 | ||
5305 | Transparent unions are designed for library functions that have multiple | |
5306 | interfaces for compatibility reasons. For example, suppose the | |
5307 | @code{wait} function must accept either a value of type @code{int *} to | |
5308 | comply with Posix, or a value of type @code{union wait *} to comply with | |
5309 | the 4.1BSD interface. If @code{wait}'s parameter were @code{void *}, | |
5310 | @code{wait} would accept both kinds of arguments, but it would also | |
5311 | accept any other pointer type and this would make argument type checking | |
5312 | less useful. Instead, @code{<sys/wait.h>} might define the interface | |
5313 | as follows: | |
5314 | ||
5315 | @smallexample | |
881eb642 | 5316 | typedef union __attribute__ ((__transparent_union__)) |
146ef39f | 5317 | @{ |
5318 | int *__ip; | |
5319 | union wait *__up; | |
881eb642 | 5320 | @} wait_status_ptr_t; |
146ef39f | 5321 | |
5322 | pid_t wait (wait_status_ptr_t); | |
5323 | @end smallexample | |
5324 | ||
5325 | This interface allows either @code{int *} or @code{union wait *} | |
5326 | arguments to be passed, using the @code{int *} calling convention. | |
5327 | The program can call @code{wait} with arguments of either type: | |
5328 | ||
a0ecd6b1 | 5329 | @smallexample |
146ef39f | 5330 | int w1 () @{ int w; return wait (&w); @} |
5331 | int w2 () @{ union wait w; return wait (&w); @} | |
a0ecd6b1 | 5332 | @end smallexample |
146ef39f | 5333 | |
5334 | With this interface, @code{wait}'s implementation might look like this: | |
5335 | ||
a0ecd6b1 | 5336 | @smallexample |
146ef39f | 5337 | pid_t wait (wait_status_ptr_t p) |
5338 | @{ | |
5339 | return waitpid (-1, p.__ip, 0); | |
5340 | @} | |
a0ecd6b1 | 5341 | @end smallexample |
7223a120 | 5342 | |
5343 | @item unused | |
5344 | When attached to a type (including a @code{union} or a @code{struct}), | |
5345 | this attribute means that variables of that type are meant to appear | |
37744367 | 5346 | possibly unused. GCC will not produce a warning for any variables of |
7223a120 | 5347 | that type, even if the variable appears to do nothing. This is often |
5348 | the case with lock or thread classes, which are usually defined and then | |
5349 | not referenced, but contain constructors and destructors that have | |
ad87de1e | 5350 | nontrivial bookkeeping functions. |
7223a120 | 5351 | |
88da234d | 5352 | @item deprecated |
45c4e798 | 5353 | @itemx deprecated (@var{msg}) |
88da234d | 5354 | The @code{deprecated} attribute results in a warning if the type |
5355 | is used anywhere in the source file. This is useful when identifying | |
5356 | types that are expected to be removed in a future version of a program. | |
5357 | If possible, the warning also includes the location of the declaration | |
5358 | of the deprecated type, to enable users to easily find further | |
5359 | information about why the type is deprecated, or what they should do | |
5360 | instead. Note that the warnings only occur for uses and then only | |
6831447b | 5361 | if the type is being applied to an identifier that itself is not being |
88da234d | 5362 | declared as deprecated. |
5363 | ||
5364 | @smallexample | |
5365 | typedef int T1 __attribute__ ((deprecated)); | |
5366 | T1 x; | |
5367 | typedef T1 T2; | |
5368 | T2 y; | |
5369 | typedef T1 T3 __attribute__ ((deprecated)); | |
5370 | T3 z __attribute__ ((deprecated)); | |
5371 | @end smallexample | |
5372 | ||
5373 | results in a warning on line 2 and 3 but not lines 4, 5, or 6. No | |
5374 | warning is issued for line 4 because T2 is not explicitly | |
5375 | deprecated. Line 5 has no warning because T3 is explicitly | |
45c4e798 | 5376 | deprecated. Similarly for line 6. The optional msg |
5377 | argument, which must be a string, will be printed in the warning if | |
5378 | present. | |
88da234d | 5379 | |
5380 | The @code{deprecated} attribute can also be used for functions and | |
5381 | variables (@pxref{Function Attributes}, @pxref{Variable Attributes}.) | |
5382 | ||
cb59f969 | 5383 | @item may_alias |
f06537f2 | 5384 | Accesses through pointers to types with this attribute are not subject |
5385 | to type-based alias analysis, but are instead assumed to be able to alias | |
5386 | any other type of objects. In the context of 6.5/7 an lvalue expression | |
5387 | dereferencing such a pointer is treated like having a character type. | |
5388 | See @option{-fstrict-aliasing} for more information on aliasing issues. | |
5389 | This extension exists to support some vector APIs, in which pointers to | |
5390 | one vector type are permitted to alias pointers to a different vector type. | |
5391 | ||
5392 | Note that an object of a type with this attribute does not have any | |
5393 | special semantics. | |
cb59f969 | 5394 | |
5395 | Example of use: | |
5396 | ||
b724fad7 | 5397 | @smallexample |
cb59f969 | 5398 | typedef short __attribute__((__may_alias__)) short_a; |
5399 | ||
5400 | int | |
5401 | main (void) | |
5402 | @{ | |
5403 | int a = 0x12345678; | |
5404 | short_a *b = (short_a *) &a; | |
5405 | ||
5406 | b[1] = 0; | |
5407 | ||
5408 | if (a == 0x12345678) | |
5409 | abort(); | |
5410 | ||
5411 | exit(0); | |
5412 | @} | |
b724fad7 | 5413 | @end smallexample |
cb59f969 | 5414 | |
5415 | If you replaced @code{short_a} with @code{short} in the variable | |
5416 | declaration, the above program would abort when compiled with | |
5417 | @option{-fstrict-aliasing}, which is on by default at @option{-O2} or | |
5418 | above in recent GCC versions. | |
b09c5db2 | 5419 | |
4a2849cb | 5420 | @item visibility |
4a2849cb | 5421 | In C++, attribute visibility (@pxref{Function Attributes}) can also be |
5422 | applied to class, struct, union and enum types. Unlike other type | |
5423 | attributes, the attribute must appear between the initial keyword and | |
5424 | the name of the type; it cannot appear after the body of the type. | |
5425 | ||
6a47600c | 5426 | Note that the type visibility is applied to vague linkage entities |
5427 | associated with the class (vtable, typeinfo node, etc.). In | |
5428 | particular, if a class is thrown as an exception in one shared object | |
5429 | and caught in another, the class must have default visibility. | |
5430 | Otherwise the two shared objects will be unable to use the same | |
5431 | typeinfo node and exception handling will break. | |
5432 | ||
e66bbea3 | 5433 | @end table |
5434 | ||
669b0b52 | 5435 | To specify multiple attributes, separate them by commas within the |
5436 | double parentheses: for example, @samp{__attribute__ ((aligned (16), | |
5437 | packed))}. | |
5438 | ||
a79b1d93 | 5439 | @subsection ARM Type Attributes |
5440 | ||
5441 | On those ARM targets that support @code{dllimport} (such as Symbian | |
09c8496f | 5442 | OS), you can use the @code{notshared} attribute to indicate that the |
a79b1d93 | 5443 | virtual table and other similar data for a class should not be |
b3d47662 | 5444 | exported from a DLL@. For example: |
a79b1d93 | 5445 | |
5446 | @smallexample | |
5447 | class __declspec(notshared) C @{ | |
5448 | public: | |
09c8496f | 5449 | __declspec(dllimport) C(); |
a79b1d93 | 5450 | virtual void f(); |
5451 | @} | |
5452 | ||
5453 | __declspec(dllexport) | |
5454 | C::C() @{@} | |
5455 | @end smallexample | |
5456 | ||
5457 | In this code, @code{C::C} is exported from the current DLL, but the | |
5458 | virtual table for @code{C} is not exported. (You can use | |
5459 | @code{__attribute__} instead of @code{__declspec} if you prefer, but | |
5460 | most Symbian OS code uses @code{__declspec}.) | |
5461 | ||
7c3116fb | 5462 | @anchor{MeP Type Attributes} |
5463 | @subsection MeP Type Attributes | |
5464 | ||
5465 | Many of the MeP variable attributes may be applied to types as well. | |
5466 | Specifically, the @code{based}, @code{tiny}, @code{near}, and | |
5467 | @code{far} attributes may be applied to either. The @code{io} and | |
5468 | @code{cb} attributes may not be applied to types. | |
5469 | ||
268b2718 | 5470 | @anchor{i386 Type Attributes} |
b09c5db2 | 5471 | @subsection i386 Type Attributes |
5472 | ||
5473 | Two attributes are currently defined for i386 configurations: | |
e66bbea3 | 5474 | @code{ms_struct} and @code{gcc_struct}. |
5475 | ||
5476 | @table @code | |
b09c5db2 | 5477 | |
5478 | @item ms_struct | |
5479 | @itemx gcc_struct | |
5480 | @cindex @code{ms_struct} | |
5481 | @cindex @code{gcc_struct} | |
5482 | ||
5483 | If @code{packed} is used on a structure, or if bit-fields are used | |
5484 | it may be that the Microsoft ABI packs them differently | |
5485 | than GCC would normally pack them. Particularly when moving packed | |
5486 | data between functions compiled with GCC and the native Microsoft compiler | |
5487 | (either via function call or as data in a file), it may be necessary to access | |
5488 | either format. | |
5489 | ||
c20b542c | 5490 | Currently @option{-m[no-]ms-bitfields} is provided for the Microsoft Windows X86 |
b09c5db2 | 5491 | compilers to match the native Microsoft compiler. |
146ef39f | 5492 | @end table |
5493 | ||
268b2718 | 5494 | @anchor{PowerPC Type Attributes} |
5495 | @subsection PowerPC Type Attributes | |
5496 | ||
5497 | Three attributes currently are defined for PowerPC configurations: | |
5498 | @code{altivec}, @code{ms_struct} and @code{gcc_struct}. | |
5499 | ||
15b474a2 | 5500 | For full documentation of the @code{ms_struct} and @code{gcc_struct} |
e66bbea3 | 5501 | attributes please see the documentation in @ref{i386 Type Attributes}. |
268b2718 | 5502 | |
5503 | The @code{altivec} attribute allows one to declare AltiVec vector data | |
5504 | types supported by the AltiVec Programming Interface Manual. The | |
5505 | attribute requires an argument to specify one of three vector types: | |
5506 | @code{vector__}, @code{pixel__} (always followed by unsigned short), | |
5507 | and @code{bool__} (always followed by unsigned). | |
5508 | ||
5509 | @smallexample | |
5510 | __attribute__((altivec(vector__))) | |
5511 | __attribute__((altivec(pixel__))) unsigned short | |
5512 | __attribute__((altivec(bool__))) unsigned | |
5513 | @end smallexample | |
5514 | ||
5515 | These attributes mainly are intended to support the @code{__vector}, | |
5516 | @code{__pixel}, and @code{__bool} AltiVec keywords. | |
5517 | ||
644459d0 | 5518 | @anchor{SPU Type Attributes} |
5519 | @subsection SPU Type Attributes | |
5520 | ||
5521 | The SPU supports the @code{spu_vector} attribute for types. This attribute | |
5522 | allows one to declare vector data types supported by the Sony/Toshiba/IBM SPU | |
5523 | Language Extensions Specification. It is intended to support the | |
5524 | @code{__vector} keyword. | |
5525 | ||
145f7c33 | 5526 | @node Alignment |
5527 | @section Inquiring on Alignment of Types or Variables | |
5528 | @cindex alignment | |
5529 | @cindex type alignment | |
5530 | @cindex variable alignment | |
5531 | ||
5532 | The keyword @code{__alignof__} allows you to inquire about how an object | |
5533 | is aligned, or the minimum alignment usually required by a type. Its | |
5534 | syntax is just like @code{sizeof}. | |
5535 | ||
5536 | For example, if the target machine requires a @code{double} value to be | |
5537 | aligned on an 8-byte boundary, then @code{__alignof__ (double)} is 8. | |
5538 | This is true on many RISC machines. On more traditional machine | |
5539 | designs, @code{__alignof__ (double)} is 4 or even 2. | |
5540 | ||
5541 | Some machines never actually require alignment; they allow reference to any | |
5542 | data type even at an odd address. For these machines, @code{__alignof__} | |
5543 | reports the smallest alignment that GCC will give the data type, usually as | |
5544 | mandated by the target ABI. | |
5545 | ||
5546 | If the operand of @code{__alignof__} is an lvalue rather than a type, | |
5547 | its value is the required alignment for its type, taking into account | |
5548 | any minimum alignment specified with GCC's @code{__attribute__} | |
5549 | extension (@pxref{Variable Attributes}). For example, after this | |
5550 | declaration: | |
5551 | ||
5552 | @smallexample | |
5553 | struct foo @{ int x; char y; @} foo1; | |
5554 | @end smallexample | |
5555 | ||
5556 | @noindent | |
5557 | the value of @code{__alignof__ (foo1.y)} is 1, even though its actual | |
5558 | alignment is probably 2 or 4, the same as @code{__alignof__ (int)}. | |
5559 | ||
5560 | It is an error to ask for the alignment of an incomplete type. | |
5561 | ||
644459d0 | 5562 | |
146ef39f | 5563 | @node Inline |
5564 | @section An Inline Function is As Fast As a Macro | |
5565 | @cindex inline functions | |
5566 | @cindex integrating function code | |
5567 | @cindex open coding | |
5568 | @cindex macros, inline alternative | |
5569 | ||
f9a907b0 | 5570 | By declaring a function inline, you can direct GCC to make |
5571 | calls to that function faster. One way GCC can achieve this is to | |
146ef39f | 5572 | integrate that function's code into the code for its callers. This |
5573 | makes execution faster by eliminating the function-call overhead; in | |
f9a907b0 | 5574 | addition, if any of the actual argument values are constant, their |
5575 | known values may permit simplifications at compile time so that not | |
5576 | all of the inline function's code needs to be included. The effect on | |
5577 | code size is less predictable; object code may be larger or smaller | |
5578 | with function inlining, depending on the particular case. You can | |
5579 | also direct GCC to try to integrate all ``simple enough'' functions | |
5580 | into their callers with the option @option{-finline-functions}. | |
5581 | ||
5582 | GCC implements three different semantics of declaring a function | |
11950bdd | 5583 | inline. One is available with @option{-std=gnu89} or |
5584 | @option{-fgnu89-inline} or when @code{gnu_inline} attribute is present | |
39012afb | 5585 | on all inline declarations, another when |
32074525 | 5586 | @option{-std=c99}, @option{-std=c11}, |
5587 | @option{-std=gnu99} or @option{-std=gnu11} | |
39012afb | 5588 | (without @option{-fgnu89-inline}), and the third |
11950bdd | 5589 | is used when compiling C++. |
3cfa0cc4 | 5590 | |
146ef39f | 5591 | To declare a function inline, use the @code{inline} keyword in its |
5592 | declaration, like this: | |
5593 | ||
a0ecd6b1 | 5594 | @smallexample |
f9a907b0 | 5595 | static inline int |
146ef39f | 5596 | inc (int *a) |
5597 | @{ | |
bfe513a4 | 5598 | return (*a)++; |
146ef39f | 5599 | @} |
a0ecd6b1 | 5600 | @end smallexample |
146ef39f | 5601 | |
32f1f35b | 5602 | If you are writing a header file to be included in ISO C90 programs, write |
f9a907b0 | 5603 | @code{__inline__} instead of @code{inline}. @xref{Alternate Keywords}. |
5a967f61 | 5604 | |
f9a907b0 | 5605 | The three types of inlining behave similarly in two important cases: |
5606 | when the @code{inline} keyword is used on a @code{static} function, | |
5607 | like the example above, and when a function is first declared without | |
5608 | using the @code{inline} keyword and then is defined with | |
5609 | @code{inline}, like this: | |
146ef39f | 5610 | |
f9a907b0 | 5611 | @smallexample |
5612 | extern int inc (int *a); | |
5613 | inline int | |
5614 | inc (int *a) | |
5615 | @{ | |
bfe513a4 | 5616 | return (*a)++; |
f9a907b0 | 5617 | @} |
5618 | @end smallexample | |
146ef39f | 5619 | |
f9a907b0 | 5620 | In both of these common cases, the program behaves the same as if you |
5621 | had not used the @code{inline} keyword, except for its speed. | |
146ef39f | 5622 | |
5623 | @cindex inline functions, omission of | |
67791935 | 5624 | @opindex fkeep-inline-functions |
146ef39f | 5625 | When a function is both inline and @code{static}, if all calls to the |
5626 | function are integrated into the caller, and the function's address is | |
5627 | never used, then the function's own assembler code is never referenced. | |
37744367 | 5628 | In this case, GCC does not actually output assembler code for the |
67791935 | 5629 | function, unless you specify the option @option{-fkeep-inline-functions}. |
146ef39f | 5630 | Some calls cannot be integrated for various reasons (in particular, |
5631 | calls that precede the function's definition cannot be integrated, and | |
5632 | neither can recursive calls within the definition). If there is a | |
5633 | nonintegrated call, then the function is compiled to assembler code as | |
5634 | usual. The function must also be compiled as usual if the program | |
5635 | refers to its address, because that can't be inlined. | |
5636 | ||
f9a907b0 | 5637 | @opindex Winline |
5638 | Note that certain usages in a function definition can make it unsuitable | |
5639 | for inline substitution. Among these usages are: use of varargs, use of | |
5640 | alloca, use of variable sized data types (@pxref{Variable Length}), | |
5641 | use of computed goto (@pxref{Labels as Values}), use of nonlocal goto, | |
5642 | and nested functions (@pxref{Nested Functions}). Using @option{-Winline} | |
5643 | will warn when a function marked @code{inline} could not be substituted, | |
5644 | and will give the reason for the failure. | |
5645 | ||
5646 | @cindex automatic @code{inline} for C++ member fns | |
5647 | @cindex @code{inline} automatic for C++ member fns | |
5648 | @cindex member fns, automatically @code{inline} | |
5649 | @cindex C++ member fns, automatically @code{inline} | |
5650 | @opindex fno-default-inline | |
5651 | As required by ISO C++, GCC considers member functions defined within | |
5652 | the body of a class to be marked inline even if they are | |
5653 | not explicitly declared with the @code{inline} keyword. You can | |
5654 | override this with @option{-fno-default-inline}; @pxref{C++ Dialect | |
5655 | Options,,Options Controlling C++ Dialect}. | |
5656 | ||
5657 | GCC does not inline any functions when not optimizing unless you specify | |
5658 | the @samp{always_inline} attribute for the function, like this: | |
5659 | ||
5660 | @smallexample | |
5661 | /* @r{Prototype.} */ | |
5662 | inline void foo (const char) __attribute__((always_inline)); | |
5663 | @end smallexample | |
5664 | ||
32f1f35b | 5665 | The remainder of this section is specific to GNU C90 inlining. |
f9a907b0 | 5666 | |
146ef39f | 5667 | @cindex non-static inline function |
5668 | When an inline function is not @code{static}, then the compiler must assume | |
5669 | that there may be calls from other source files; since a global symbol can | |
5670 | be defined only once in any program, the function must not be defined in | |
5671 | the other source files, so the calls therein cannot be integrated. | |
5672 | Therefore, a non-@code{static} inline function is always compiled on its | |
5673 | own in the usual fashion. | |
5674 | ||
5675 | If you specify both @code{inline} and @code{extern} in the function | |
5676 | definition, then the definition is used only for inlining. In no case | |
5677 | is the function compiled on its own, not even if you refer to its | |
5678 | address explicitly. Such an address becomes an external reference, as | |
5679 | if you had only declared the function, and had not defined it. | |
5680 | ||
5681 | This combination of @code{inline} and @code{extern} has almost the | |
5682 | effect of a macro. The way to use it is to put a function definition in | |
5683 | a header file with these keywords, and put another copy of the | |
5684 | definition (lacking @code{inline} and @code{extern}) in a library file. | |
5685 | The definition in the header file will cause most calls to the function | |
5686 | to be inlined. If any uses of the function remain, they will refer to | |
5687 | the single copy in the library. | |
5688 | ||
e83c4d0f | 5689 | @node Volatiles |
5690 | @section When is a Volatile Object Accessed? | |
5691 | @cindex accessing volatiles | |
5692 | @cindex volatile read | |
5693 | @cindex volatile write | |
5694 | @cindex volatile access | |
5695 | ||
5696 | C has the concept of volatile objects. These are normally accessed by | |
5697 | pointers and used for accessing hardware or inter-thread | |
b59688ee | 5698 | communication. The standard encourages compilers to refrain from |
e83c4d0f | 5699 | optimizations concerning accesses to volatile objects, but leaves it |
5700 | implementation defined as to what constitutes a volatile access. The | |
5701 | minimum requirement is that at a sequence point all previous accesses | |
5702 | to volatile objects have stabilized and no subsequent accesses have | |
5703 | occurred. Thus an implementation is free to reorder and combine | |
5704 | volatile accesses which occur between sequence points, but cannot do | |
b59688ee | 5705 | so for accesses across a sequence point. The use of volatile does |
e83c4d0f | 5706 | not allow you to violate the restriction on updating objects multiple |
5707 | times between two sequence points. | |
5708 | ||
5709 | Accesses to non-volatile objects are not ordered with respect to | |
5710 | volatile accesses. You cannot use a volatile object as a memory | |
5711 | barrier to order a sequence of writes to non-volatile memory. For | |
5712 | instance: | |
5713 | ||
5714 | @smallexample | |
5715 | int *ptr = @var{something}; | |
5716 | volatile int vobj; | |
5717 | *ptr = @var{something}; | |
5718 | vobj = 1; | |
5719 | @end smallexample | |
5720 | ||
5721 | Unless @var{*ptr} and @var{vobj} can be aliased, it is not guaranteed | |
5722 | that the write to @var{*ptr} will have occurred by the time the update | |
5723 | of @var{vobj} has happened. If you need this guarantee, you must use | |
5724 | a stronger memory barrier such as: | |
5725 | ||
5726 | @smallexample | |
5727 | int *ptr = @var{something}; | |
5728 | volatile int vobj; | |
5729 | *ptr = @var{something}; | |
5730 | asm volatile ("" : : : "memory"); | |
5731 | vobj = 1; | |
5732 | @end smallexample | |
5733 | ||
b59688ee | 5734 | A scalar volatile object is read when it is accessed in a void context: |
e83c4d0f | 5735 | |
5736 | @smallexample | |
5737 | volatile int *src = @var{somevalue}; | |
5738 | *src; | |
5739 | @end smallexample | |
5740 | ||
5741 | Such expressions are rvalues, and GCC implements this as a | |
5742 | read of the volatile object being pointed to. | |
5743 | ||
5744 | Assignments are also expressions and have an rvalue. However when | |
5745 | assigning to a scalar volatile, the volatile object is not reread, | |
5746 | regardless of whether the assignment expression's rvalue is used or | |
5747 | not. If the assignment's rvalue is used, the value is that assigned | |
5748 | to the volatile object. For instance, there is no read of @var{vobj} | |
5749 | in all the following cases: | |
5750 | ||
5751 | @smallexample | |
5752 | int obj; | |
5753 | volatile int vobj; | |
5754 | vobj = @var{something}; | |
5755 | obj = vobj = @var{something}; | |
5756 | obj ? vobj = @var{onething} : vobj = @var{anotherthing}; | |
5757 | obj = (@var{something}, vobj = @var{anotherthing}); | |
5758 | @end smallexample | |
5759 | ||
5760 | If you need to read the volatile object after an assignment has | |
5761 | occurred, you must use a separate expression with an intervening | |
5762 | sequence point. | |
5763 | ||
5764 | As bitfields are not individually addressable, volatile bitfields may | |
5765 | be implicitly read when written to, or when adjacent bitfields are | |
5766 | accessed. Bitfield operations may be optimized such that adjacent | |
5767 | bitfields are only partially accessed, if they straddle a storage unit | |
5768 | boundary. For these reasons it is unwise to use volatile bitfields to | |
5769 | access hardware. | |
5770 | ||
146ef39f | 5771 | @node Extended Asm |
5772 | @section Assembler Instructions with C Expression Operands | |
5773 | @cindex extended @code{asm} | |
5774 | @cindex @code{asm} expressions | |
5775 | @cindex assembler instructions | |
5776 | @cindex registers | |
5777 | ||
220345e0 | 5778 | In an assembler instruction using @code{asm}, you can specify the |
5779 | operands of the instruction using C expressions. This means you need not | |
5780 | guess which registers or memory locations will contain the data you want | |
146ef39f | 5781 | to use. |
5782 | ||
220345e0 | 5783 | You must specify an assembler instruction template much like what |
5784 | appears in a machine description, plus an operand constraint string for | |
5785 | each operand. | |
146ef39f | 5786 | |
5787 | For example, here is how to use the 68881's @code{fsinx} instruction: | |
5788 | ||
a0ecd6b1 | 5789 | @smallexample |
146ef39f | 5790 | asm ("fsinx %1,%0" : "=f" (result) : "f" (angle)); |
a0ecd6b1 | 5791 | @end smallexample |
146ef39f | 5792 | |
5793 | @noindent | |
5794 | Here @code{angle} is the C expression for the input operand while | |
5795 | @code{result} is that of the output operand. Each has @samp{"f"} as its | |
220345e0 | 5796 | operand constraint, saying that a floating point register is required. |
5797 | The @samp{=} in @samp{=f} indicates that the operand is an output; all | |
5798 | output operands' constraints must use @samp{=}. The constraints use the | |
5799 | same language used in the machine description (@pxref{Constraints}). | |
5800 | ||
5801 | Each operand is described by an operand-constraint string followed by | |
5802 | the C expression in parentheses. A colon separates the assembler | |
5803 | template from the first output operand and another separates the last | |
5804 | output operand from the first input, if any. Commas separate the | |
2c7f203c | 5805 | operands within each group. The total number of operands is currently |
5806 | limited to 30; this limitation may be lifted in some future version of | |
b3d47662 | 5807 | GCC@. |
220345e0 | 5808 | |
5809 | If there are no output operands but there are input operands, you must | |
5810 | place two consecutive colons surrounding the place where the output | |
146ef39f | 5811 | operands would go. |
5812 | ||
2c7f203c | 5813 | As of GCC version 3.1, it is also possible to specify input and output |
5814 | operands using symbolic names which can be referenced within the | |
5815 | assembler code. These names are specified inside square brackets | |
5816 | preceding the constraint string, and can be referenced inside the | |
5817 | assembler code using @code{%[@var{name}]} instead of a percentage sign | |
5818 | followed by the operand number. Using named operands the above example | |
5819 | could look like: | |
5820 | ||
a0ecd6b1 | 5821 | @smallexample |
2c7f203c | 5822 | asm ("fsinx %[angle],%[output]" |
5823 | : [output] "=f" (result) | |
5824 | : [angle] "f" (angle)); | |
a0ecd6b1 | 5825 | @end smallexample |
2c7f203c | 5826 | |
5827 | @noindent | |
5828 | Note that the symbolic operand names have no relation whatsoever to | |
5829 | other C identifiers. You may use any name you like, even those of | |
ea1c20d0 | 5830 | existing C symbols, but you must ensure that no two operands within the same |
2c7f203c | 5831 | assembler construct use the same symbolic name. |
5832 | ||
146ef39f | 5833 | Output operand expressions must be lvalues; the compiler can check this. |
220345e0 | 5834 | The input operands need not be lvalues. The compiler cannot check |
5835 | whether the operands have data types that are reasonable for the | |
5836 | instruction being executed. It does not parse the assembler instruction | |
5837 | template and does not know what it means or even whether it is valid | |
5838 | assembler input. The extended @code{asm} feature is most often used for | |
5839 | machine instructions the compiler itself does not know exist. If | |
5840 | the output expression cannot be directly addressed (for example, it is a | |
37744367 | 5841 | bit-field), your constraint must allow a register. In that case, GCC |
220345e0 | 5842 | will use the register as the output of the @code{asm}, and then store |
5843 | that register into the output. | |
5844 | ||
37744367 | 5845 | The ordinary output operands must be write-only; GCC will assume that |
220345e0 | 5846 | the values in these operands before the instruction are dead and need |
5847 | not be generated. Extended asm supports input-output or read-write | |
5848 | operands. Use the constraint character @samp{+} to indicate such an | |
7cb2ace4 | 5849 | operand and list it with the output operands. You should only use |
5850 | read-write operands when the constraints for the operand (or the | |
5851 | operand in which only some of the bits are to be changed) allow a | |
5852 | register. | |
5853 | ||
5854 | You may, as an alternative, logically split its function into two | |
5855 | separate operands, one input operand and one write-only output | |
5856 | operand. The connection between them is expressed by constraints | |
5857 | which say they need to be in the same location when the instruction | |
5858 | executes. You can use the same C expression for both operands, or | |
5859 | different expressions. For example, here we write the (fictitious) | |
5860 | @samp{combine} instruction with @code{bar} as its read-only source | |
5861 | operand and @code{foo} as its read-write destination: | |
146ef39f | 5862 | |
a0ecd6b1 | 5863 | @smallexample |
146ef39f | 5864 | asm ("combine %2,%0" : "=r" (foo) : "0" (foo), "g" (bar)); |
a0ecd6b1 | 5865 | @end smallexample |
146ef39f | 5866 | |
5867 | @noindent | |
220345e0 | 5868 | The constraint @samp{"0"} for operand 1 says that it must occupy the |
2c7f203c | 5869 | same location as operand 0. A number in constraint is allowed only in |
5870 | an input operand and it must refer to an output operand. | |
146ef39f | 5871 | |
2c7f203c | 5872 | Only a number in the constraint can guarantee that one operand will be in |
220345e0 | 5873 | the same place as another. The mere fact that @code{foo} is the value |
5874 | of both operands is not enough to guarantee that they will be in the | |
5875 | same place in the generated assembler code. The following would not | |
5876 | work reliably: | |
146ef39f | 5877 | |
a0ecd6b1 | 5878 | @smallexample |
146ef39f | 5879 | asm ("combine %2,%0" : "=r" (foo) : "r" (foo), "g" (bar)); |
a0ecd6b1 | 5880 | @end smallexample |
146ef39f | 5881 | |
5882 | Various optimizations or reloading could cause operands 0 and 1 to be in | |
37744367 | 5883 | different registers; GCC knows no reason not to do so. For example, the |
146ef39f | 5884 | compiler might find a copy of the value of @code{foo} in one register and |
5885 | use it for operand 1, but generate the output operand 0 in a different | |
5886 | register (copying it afterward to @code{foo}'s own address). Of course, | |
5887 | since the register for operand 1 is not even mentioned in the assembler | |
37744367 | 5888 | code, the result will not work, but GCC can't tell that. |
146ef39f | 5889 | |
2c7f203c | 5890 | As of GCC version 3.1, one may write @code{[@var{name}]} instead of |
5891 | the operand number for a matching constraint. For example: | |
5892 | ||
a0ecd6b1 | 5893 | @smallexample |
2c7f203c | 5894 | asm ("cmoveq %1,%2,%[result]" |
5895 | : [result] "=r"(result) | |
5896 | : "r" (test), "r"(new), "[result]"(old)); | |
a0ecd6b1 | 5897 | @end smallexample |
2c7f203c | 5898 | |
1358f000 | 5899 | Sometimes you need to make an @code{asm} operand be a specific register, |
5900 | but there's no matching constraint letter for that register @emph{by | |
5901 | itself}. To force the operand into that register, use a local variable | |
5902 | for the operand and specify the register in the variable declaration. | |
5903 | @xref{Explicit Reg Vars}. Then for the @code{asm} operand, use any | |
5904 | register constraint letter that matches the register: | |
5905 | ||
5906 | @smallexample | |
5907 | register int *p1 asm ("r0") = @dots{}; | |
5908 | register int *p2 asm ("r1") = @dots{}; | |
5909 | register int *result asm ("r0"); | |
5910 | asm ("sysint" : "=r" (result) : "0" (p1), "r" (p2)); | |
5911 | @end smallexample | |
5912 | ||
2de78c9f | 5913 | @anchor{Example of asm with clobbered asm reg} |
5914 | In the above example, beware that a register that is call-clobbered by | |
5915 | the target ABI will be overwritten by any function call in the | |
5916 | assignment, including library calls for arithmetic operators. | |
2687629f | 5917 | Also a register may be clobbered when generating some operations, |
5918 | like variable shift, memory copy or memory move on x86. | |
2de78c9f | 5919 | Assuming it is a call-clobbered register, this may happen to @code{r0} |
5920 | above by the assignment to @code{p2}. If you have to use such a | |
5921 | register, use temporary variables for expressions between the register | |
5922 | assignment and use: | |
5923 | ||
5924 | @smallexample | |
5925 | int t1 = @dots{}; | |
5926 | register int *p1 asm ("r0") = @dots{}; | |
5927 | register int *p2 asm ("r1") = t1; | |
5928 | register int *result asm ("r0"); | |
5929 | asm ("sysint" : "=r" (result) : "0" (p1), "r" (p2)); | |
5930 | @end smallexample | |
5931 | ||
220345e0 | 5932 | Some instructions clobber specific hard registers. To describe this, |
5933 | write a third colon after the input operands, followed by the names of | |
5934 | the clobbered hard registers (given as strings). Here is a realistic | |
5935 | example for the VAX: | |
146ef39f | 5936 | |
a0ecd6b1 | 5937 | @smallexample |
146ef39f | 5938 | asm volatile ("movc3 %0,%1,%2" |
12e2a142 | 5939 | : /* @r{no outputs} */ |
146ef39f | 5940 | : "g" (from), "g" (to), "g" (count) |
5941 | : "r0", "r1", "r2", "r3", "r4", "r5"); | |
a0ecd6b1 | 5942 | @end smallexample |
146ef39f | 5943 | |
7014838c | 5944 | You may not write a clobber description in a way that overlaps with an |
5945 | input or output operand. For example, you may not have an operand | |
5946 | describing a register class with one member if you mention that register | |
3d52d305 | 5947 | in the clobber list. Variables declared to live in specific registers |
5948 | (@pxref{Explicit Reg Vars}), and used as asm input or output operands must | |
5949 | have no part mentioned in the clobber description. | |
5950 | There is no way for you to specify that an input | |
7014838c | 5951 | operand is modified without also specifying it as an output |
5952 | operand. Note that if all the output operands you specify are for this | |
5953 | purpose (and hence unused), you will then also need to specify | |
5954 | @code{volatile} for the @code{asm} construct, as described below, to | |
37744367 | 5955 | prevent GCC from deleting the @code{asm} statement as unused. |
abd6a9dd | 5956 | |
146ef39f | 5957 | If you refer to a particular hardware register from the assembler code, |
220345e0 | 5958 | you will probably have to list the register after the third colon to |
5959 | tell the compiler the register's value is modified. In some assemblers, | |
5960 | the register names begin with @samp{%}; to produce one @samp{%} in the | |
5961 | assembler code, you must write @samp{%%} in the input. | |
5962 | ||
5963 | If your assembler instruction can alter the condition code register, add | |
37744367 | 5964 | @samp{cc} to the list of clobbered registers. GCC on some machines |
220345e0 | 5965 | represents the condition codes as a specific hardware register; |
5966 | @samp{cc} serves to name this register. On other machines, the | |
5967 | condition code is handled differently, and specifying @samp{cc} has no | |
5968 | effect. But it is valid no matter what the machine. | |
146ef39f | 5969 | |
f899e75e | 5970 | If your assembler instructions access memory in an unpredictable |
220345e0 | 5971 | fashion, add @samp{memory} to the list of clobbered registers. This |
f899e75e | 5972 | will cause GCC to not keep memory values cached in registers across the |
5973 | assembler instruction and not optimize stores or loads to that memory. | |
5974 | You will also want to add the @code{volatile} keyword if the memory | |
5975 | affected is not listed in the inputs or outputs of the @code{asm}, as | |
5976 | the @samp{memory} clobber does not count as a side-effect of the | |
5977 | @code{asm}. If you know how large the accessed memory is, you can add | |
5978 | it as input or output but if this is not known, you should add | |
5979 | @samp{memory}. As an example, if you access ten bytes of a string, you | |
5980 | can use a memory input like: | |
5981 | ||
91acd86c | 5982 | @smallexample |
f899e75e | 5983 | @{"m"( (@{ struct @{ char x[10]; @} *p = (void *)ptr ; *p; @}) )@}. |
91acd86c | 5984 | @end smallexample |
f899e75e | 5985 | |
5986 | Note that in the following example the memory input is necessary, | |
5987 | otherwise GCC might optimize the store to @code{x} away: | |
91acd86c | 5988 | @smallexample |
f899e75e | 5989 | int foo () |
5990 | @{ | |
5991 | int x = 42; | |
5992 | int *y = &x; | |
5993 | int result; | |
5994 | asm ("magic stuff accessing an 'int' pointed to by '%1'" | |
5995 | "=&d" (r) : "a" (y), "m" (*y)); | |
09c8496f | 5996 | return result; |
f899e75e | 5997 | @} |
91acd86c | 5998 | @end smallexample |
146ef39f | 5999 | |
220345e0 | 6000 | You can put multiple assembler instructions together in a single |
4cd470f2 | 6001 | @code{asm} template, separated by the characters normally used in assembly |
6002 | code for the system. A combination that works in most places is a newline | |
6003 | to break the line, plus a tab character to move to the instruction field | |
6004 | (written as @samp{\n\t}). Sometimes semicolons can be used, if the | |
6005 | assembler allows semicolons as a line-breaking character. Note that some | |
6006 | assembler dialects use semicolons to start a comment. | |
6007 | The input operands are guaranteed not to use any of the clobbered | |
220345e0 | 6008 | registers, and neither will the output operands' addresses, so you can |
6009 | read and write the clobbered registers as many times as you like. Here | |
6010 | is an example of multiple instructions in a template; it assumes the | |
6011 | subroutine @code{_foo} accepts arguments in registers 9 and 10: | |
146ef39f | 6012 | |
a0ecd6b1 | 6013 | @smallexample |
4cd470f2 | 6014 | asm ("movl %0,r9\n\tmovl %1,r10\n\tcall _foo" |
146ef39f | 6015 | : /* no outputs */ |
6016 | : "g" (from), "g" (to) | |
6017 | : "r9", "r10"); | |
a0ecd6b1 | 6018 | @end smallexample |
146ef39f | 6019 | |
37744367 | 6020 | Unless an output operand has the @samp{&} constraint modifier, GCC |
220345e0 | 6021 | may allocate it in the same register as an unrelated input operand, on |
6022 | the assumption the inputs are consumed before the outputs are produced. | |
146ef39f | 6023 | This assumption may be false if the assembler code actually consists of |
6024 | more than one instruction. In such a case, use @samp{&} for each output | |
220345e0 | 6025 | operand that may not overlap an input. @xref{Modifiers}. |
146ef39f | 6026 | |
220345e0 | 6027 | If you want to test the condition code produced by an assembler |
6028 | instruction, you must include a branch and a label in the @code{asm} | |
6029 | construct, as follows: | |
146ef39f | 6030 | |
a0ecd6b1 | 6031 | @smallexample |
4cd470f2 | 6032 | asm ("clr %0\n\tfrob %1\n\tbeq 0f\n\tmov #1,%0\n0:" |
146ef39f | 6033 | : "g" (result) |
6034 | : "g" (input)); | |
a0ecd6b1 | 6035 | @end smallexample |
146ef39f | 6036 | |
6037 | @noindent | |
6038 | This assumes your assembler supports local labels, as the GNU assembler | |
6039 | and most Unix assemblers do. | |
6040 | ||
6041 | Speaking of labels, jumps from one @code{asm} to another are not | |
220345e0 | 6042 | supported. The compiler's optimizers do not know about these jumps, and |
6043 | therefore they cannot take account of them when deciding how to | |
78f55ca8 | 6044 | optimize. @xref{Extended asm with goto}. |
146ef39f | 6045 | |
6046 | @cindex macros containing @code{asm} | |
6047 | Usually the most convenient way to use these @code{asm} instructions is to | |
6048 | encapsulate them in macros that look like functions. For example, | |
6049 | ||
a0ecd6b1 | 6050 | @smallexample |
146ef39f | 6051 | #define sin(x) \ |
6052 | (@{ double __value, __arg = (x); \ | |
6053 | asm ("fsinx %1,%0": "=f" (__value): "f" (__arg)); \ | |
6054 | __value; @}) | |
a0ecd6b1 | 6055 | @end smallexample |
146ef39f | 6056 | |
6057 | @noindent | |
6058 | Here the variable @code{__arg} is used to make sure that the instruction | |
6059 | operates on a proper @code{double} value, and to accept only those | |
6060 | arguments @code{x} which can convert automatically to a @code{double}. | |
6061 | ||
220345e0 | 6062 | Another way to make sure the instruction operates on the correct data |
6063 | type is to use a cast in the @code{asm}. This is different from using a | |
146ef39f | 6064 | variable @code{__arg} in that it converts more different types. For |
6065 | example, if the desired type were @code{int}, casting the argument to | |
6066 | @code{int} would accept a pointer with no complaint, while assigning the | |
6067 | argument to an @code{int} variable named @code{__arg} would warn about | |
6068 | using a pointer unless the caller explicitly casts it. | |
6069 | ||
37744367 | 6070 | If an @code{asm} has output operands, GCC assumes for optimization |
220345e0 | 6071 | purposes the instruction has no side effects except to change the output |
6072 | operands. This does not mean instructions with a side effect cannot be | |
6073 | used, but you must be careful, because the compiler may eliminate them | |
6074 | if the output operands aren't used, or move them out of loops, or | |
6075 | replace two with one if they constitute a common subexpression. Also, | |
6076 | if your instruction does have a side effect on a variable that otherwise | |
6077 | appears not to change, the old value of the variable may be reused later | |
6078 | if it happens to be found in a register. | |
146ef39f | 6079 | |
3eb4e85f | 6080 | You can prevent an @code{asm} instruction from being deleted |
6081 | by writing the keyword @code{volatile} after | |
146ef39f | 6082 | the @code{asm}. For example: |
6083 | ||
a0ecd6b1 | 6084 | @smallexample |
d90db7dc | 6085 | #define get_and_set_priority(new) \ |
6086 | (@{ int __old; \ | |
6087 | asm volatile ("get_and_set_priority %0, %1" \ | |
6088 | : "=g" (__old) : "g" (new)); \ | |
220345e0 | 6089 | __old; @}) |
a0ecd6b1 | 6090 | @end smallexample |
146ef39f | 6091 | |
6092 | @noindent | |
90f960d5 | 6093 | The @code{volatile} keyword indicates that the instruction has |
6094 | important side-effects. GCC will not delete a volatile @code{asm} if | |
6095 | it is reachable. (The instruction can still be deleted if GCC can | |
6096 | prove that control-flow will never reach the location of the | |
09c8496f | 6097 | instruction.) Note that even a volatile @code{asm} instruction |
3eb4e85f | 6098 | can be moved relative to other code, including across jump |
09c8496f | 6099 | instructions. For example, on many targets there is a system |
6100 | register which can be set to control the rounding mode of | |
3eb4e85f | 6101 | floating point operations. You might try |
6102 | setting it with a volatile @code{asm}, like this PowerPC example: | |
90f960d5 | 6103 | |
a0ecd6b1 | 6104 | @smallexample |
3eb4e85f | 6105 | asm volatile("mtfsf 255,%0" : : "f" (fpenv)); |
6106 | sum = x + y; | |
a0ecd6b1 | 6107 | @end smallexample |
90f960d5 | 6108 | |
77f71523 | 6109 | @noindent |
3eb4e85f | 6110 | This will not work reliably, as the compiler may move the addition back |
6111 | before the volatile @code{asm}. To make it work you need to add an | |
6112 | artificial dependency to the @code{asm} referencing a variable in the code | |
6113 | you don't want moved, for example: | |
6114 | ||
6115 | @smallexample | |
6116 | asm volatile ("mtfsf 255,%1" : "=X"(sum): "f"(fpenv)); | |
6117 | sum = x + y; | |
6118 | @end smallexample | |
6119 | ||
6120 | Similarly, you can't expect a | |
6121 | sequence of volatile @code{asm} instructions to remain perfectly | |
6122 | consecutive. If you want consecutive output, use a single @code{asm}. | |
6123 | Also, GCC will perform some optimizations across a volatile @code{asm} | |
6124 | instruction; GCC does not ``forget everything'' when it encounters | |
6125 | a volatile @code{asm} instruction the way some other compilers do. | |
6126 | ||
6127 | An @code{asm} instruction without any output operands will be treated | |
6128 | identically to a volatile @code{asm} instruction. | |
146ef39f | 6129 | |
6130 | It is a natural idea to look for a way to give access to the condition | |
6131 | code left by the assembler instruction. However, when we attempted to | |
6132 | implement this, we found no way to make it work reliably. The problem | |
6133 | is that output operands might need reloading, which would result in | |
6134 | additional following ``store'' instructions. On most machines, these | |
6135 | instructions would alter the condition code before there was time to | |
6136 | test it. This problem doesn't arise for ordinary ``test'' and | |
6137 | ``compare'' instructions because they don't have any output operands. | |
6138 | ||
356ed71f | 6139 | For reasons similar to those described above, it is not possible to give |
6140 | an assembler instruction access to the condition code left by previous | |
6141 | instructions. | |
6142 | ||
78f55ca8 | 6143 | @anchor{Extended asm with goto} |
6144 | As of GCC version 4.5, @code{asm goto} may be used to have the assembly | |
6145 | jump to one or more C labels. In this form, a fifth section after the | |
6146 | clobber list contains a list of all C labels to which the assembly may jump. | |
6147 | Each label operand is implicitly self-named. The @code{asm} is also assumed | |
6148 | to fall through to the next statement. | |
6149 | ||
6150 | This form of @code{asm} is restricted to not have outputs. This is due | |
6151 | to a internal restriction in the compiler that control transfer instructions | |
6152 | cannot have outputs. This restriction on @code{asm goto} may be lifted | |
6153 | in some future version of the compiler. In the mean time, @code{asm goto} | |
6154 | may include a memory clobber, and so leave outputs in memory. | |
6155 | ||
6156 | @smallexample | |
6157 | int frob(int x) | |
6158 | @{ | |
6159 | int y; | |
6160 | asm goto ("frob %%r5, %1; jc %l[error]; mov (%2), %%r5" | |
6161 | : : "r"(x), "r"(&y) : "r5", "memory" : error); | |
6162 | return y; | |
6163 | error: | |
6164 | return -1; | |
6165 | @} | |
6166 | @end smallexample | |
6167 | ||
6168 | In this (inefficient) example, the @code{frob} instruction sets the | |
6169 | carry bit to indicate an error. The @code{jc} instruction detects | |
15b474a2 | 6170 | this and branches to the @code{error} label. Finally, the output |
78f55ca8 | 6171 | of the @code{frob} instruction (@code{%r5}) is stored into the memory |
6172 | for variable @code{y}, which is later read by the @code{return} statement. | |
6173 | ||
6174 | @smallexample | |
6175 | void doit(void) | |
6176 | @{ | |
6177 | int i = 0; | |
6178 | asm goto ("mfsr %%r1, 123; jmp %%r1;" | |
6179 | ".pushsection doit_table;" | |
910faa40 | 6180 | ".long %l0, %l1, %l2, %l3;" |
6181 | ".popsection" | |
6182 | : : : "r1" : label1, label2, label3, label4); | |
78f55ca8 | 6183 | __builtin_unreachable (); |
6184 | ||
6185 | label1: | |
6186 | f1(); | |
6187 | return; | |
6188 | label2: | |
6189 | f2(); | |
6190 | return; | |
6191 | label3: | |
6192 | i = 1; | |
6193 | label4: | |
6194 | f3(i); | |
6195 | @} | |
6196 | @end smallexample | |
6197 | ||
6198 | In this (also inefficient) example, the @code{mfsr} instruction reads | |
6199 | an address from some out-of-band machine register, and the following | |
6200 | @code{jmp} instruction branches to that address. The address read by | |
6201 | the @code{mfsr} instruction is assumed to have been previously set via | |
6202 | some application-specific mechanism to be one of the four values stored | |
6203 | in the @code{doit_table} section. Finally, the @code{asm} is followed | |
6204 | by a call to @code{__builtin_unreachable} to indicate that the @code{asm} | |
6205 | does not in fact fall through. | |
6206 | ||
6207 | @smallexample | |
6208 | #define TRACE1(NUM) \ | |
6209 | do @{ \ | |
6210 | asm goto ("0: nop;" \ | |
6211 | ".pushsection trace_table;" \ | |
6212 | ".long 0b, %l0;" \ | |
6213 | ".popsection" \ | |
6214 | : : : : trace#NUM); \ | |
6215 | if (0) @{ trace#NUM: trace(); @} \ | |
6216 | @} while (0) | |
6217 | #define TRACE TRACE1(__COUNTER__) | |
6218 | @end smallexample | |
6219 | ||
6220 | In this example (which in fact inspired the @code{asm goto} feature) | |
6221 | we want on rare occasions to call the @code{trace} function; on other | |
6222 | occasions we'd like to keep the overhead to the absolute minimum. | |
6223 | The normal code path consists of a single @code{nop} instruction. | |
6224 | However, we record the address of this @code{nop} together with the | |
6225 | address of a label that calls the @code{trace} function. This allows | |
15b474a2 | 6226 | the @code{nop} instruction to be patched at runtime to be an |
78f55ca8 | 6227 | unconditional branch to the stored label. It is assumed that an |
6228 | optimizing compiler will move the labeled block out of line, to | |
6229 | optimize the fall through path from the @code{asm}. | |
6230 | ||
78b1f616 | 6231 | If you are writing a header file that should be includable in ISO C |
146ef39f | 6232 | programs, write @code{__asm__} instead of @code{asm}. @xref{Alternate |
6233 | Keywords}. | |
6234 | ||
9214c2cb | 6235 | @subsection Size of an @code{asm} |
6236 | ||
6237 | Some targets require that GCC track the size of each instruction used in | |
6238 | order to generate correct code. Because the final length of an | |
6239 | @code{asm} is only known by the assembler, GCC must make an estimate as | |
6240 | to how big it will be. The estimate is formed by counting the number of | |
6241 | statements in the pattern of the @code{asm} and multiplying that by the | |
6242 | length of the longest instruction on that processor. Statements in the | |
6243 | @code{asm} are identified by newline characters and whatever statement | |
6244 | separator characters are supported by the assembler; on most processors | |
6245 | this is the `@code{;}' character. | |
6246 | ||
6247 | Normally, GCC's estimate is perfectly adequate to ensure that correct | |
6248 | code is generated, but it is possible to confuse the compiler if you use | |
6249 | pseudo instructions or assembler macros that expand into multiple real | |
6250 | instructions or if you use assembler directives that expand to more | |
6251 | space in the object file than would be needed for a single instruction. | |
6252 | If this happens then the assembler will produce a diagnostic saying that | |
6253 | a label is unreachable. | |
6254 | ||
53ae8f59 | 6255 | @subsection i386 floating point asm operands |
6256 | ||
6257 | There are several rules on the usage of stack-like regs in | |
6258 | asm_operands insns. These rules apply only to the operands that are | |
6259 | stack-like regs: | |
6260 | ||
6261 | @enumerate | |
6262 | @item | |
6263 | Given a set of input regs that die in an asm_operands, it is | |
6264 | necessary to know which are implicitly popped by the asm, and | |
6265 | which must be explicitly popped by gcc. | |
6266 | ||
6267 | An input reg that is implicitly popped by the asm must be | |
6268 | explicitly clobbered, unless it is constrained to match an | |
6269 | output operand. | |
6270 | ||
6271 | @item | |
6272 | For any input reg that is implicitly popped by an asm, it is | |
6273 | necessary to know how to adjust the stack to compensate for the pop. | |
6274 | If any non-popped input is closer to the top of the reg-stack than | |
6275 | the implicitly popped reg, it would not be possible to know what the | |
67791935 | 6276 | stack looked like---it's not clear how the rest of the stack ``slides |
53ae8f59 | 6277 | up''. |
6278 | ||
6279 | All implicitly popped input regs must be closer to the top of | |
6280 | the reg-stack than any input that is not implicitly popped. | |
6281 | ||
6282 | It is possible that if an input dies in an insn, reload might | |
6283 | use the input reg for an output reload. Consider this example: | |
6284 | ||
a0ecd6b1 | 6285 | @smallexample |
53ae8f59 | 6286 | asm ("foo" : "=t" (a) : "f" (b)); |
a0ecd6b1 | 6287 | @end smallexample |
53ae8f59 | 6288 | |
6289 | This asm says that input B is not popped by the asm, and that | |
8e5fcce7 | 6290 | the asm pushes a result onto the reg-stack, i.e., the stack is one |
53ae8f59 | 6291 | deeper after the asm than it was before. But, it is possible that |
6292 | reload will think that it can use the same reg for both the input and | |
6293 | the output, if input B dies in this insn. | |
6294 | ||
6295 | If any input operand uses the @code{f} constraint, all output reg | |
6296 | constraints must use the @code{&} earlyclobber. | |
6297 | ||
6298 | The asm above would be written as | |
6299 | ||
a0ecd6b1 | 6300 | @smallexample |
53ae8f59 | 6301 | asm ("foo" : "=&t" (a) : "f" (b)); |
a0ecd6b1 | 6302 | @end smallexample |
53ae8f59 | 6303 | |
6304 | @item | |
6305 | Some operands need to be in particular places on the stack. All | |
67791935 | 6306 | output operands fall in this category---there is no other way to |
53ae8f59 | 6307 | know which regs the outputs appear in unless the user indicates |
6308 | this in the constraints. | |
6309 | ||
6310 | Output operands must specifically indicate which reg an output | |
6311 | appears in after an asm. @code{=f} is not allowed: the operand | |
6312 | constraints must select a class with a single reg. | |
6313 | ||
6314 | @item | |
6315 | Output operands may not be ``inserted'' between existing stack regs. | |
6316 | Since no 387 opcode uses a read/write operand, all output operands | |
6317 | are dead before the asm_operands, and are pushed by the asm_operands. | |
6318 | It makes no sense to push anywhere but the top of the reg-stack. | |
6319 | ||
6320 | Output operands must start at the top of the reg-stack: output | |
6321 | operands may not ``skip'' a reg. | |
6322 | ||
6323 | @item | |
6324 | Some asm statements may need extra stack space for internal | |
6325 | calculations. This can be guaranteed by clobbering stack registers | |
6326 | unrelated to the inputs and outputs. | |
6327 | ||
6328 | @end enumerate | |
6329 | ||
6330 | Here are a couple of reasonable asms to want to write. This asm | |
6331 | takes one input, which is internally popped, and produces two outputs. | |
6332 | ||
a0ecd6b1 | 6333 | @smallexample |
53ae8f59 | 6334 | asm ("fsincos" : "=t" (cos), "=u" (sin) : "0" (inp)); |
a0ecd6b1 | 6335 | @end smallexample |
53ae8f59 | 6336 | |
6337 | This asm takes two inputs, which are popped by the @code{fyl2xp1} opcode, | |
6338 | and replaces them with one output. The user must code the @code{st(1)} | |
6339 | clobber for reg-stack.c to know that @code{fyl2xp1} pops both inputs. | |
6340 | ||
a0ecd6b1 | 6341 | @smallexample |
53ae8f59 | 6342 | asm ("fyl2xp1" : "=t" (result) : "0" (x), "u" (y) : "st(1)"); |
a0ecd6b1 | 6343 | @end smallexample |
53ae8f59 | 6344 | |
146ef39f | 6345 | @include md.texi |
146ef39f | 6346 | |
6347 | @node Asm Labels | |
6348 | @section Controlling Names Used in Assembler Code | |
6349 | @cindex assembler names for identifiers | |
6350 | @cindex names used in assembler code | |
6351 | @cindex identifiers, names in assembler code | |
6352 | ||
6353 | You can specify the name to be used in the assembler code for a C | |
6354 | function or variable by writing the @code{asm} (or @code{__asm__}) | |
6355 | keyword after the declarator as follows: | |
6356 | ||
a0ecd6b1 | 6357 | @smallexample |
146ef39f | 6358 | int foo asm ("myfoo") = 2; |
a0ecd6b1 | 6359 | @end smallexample |
146ef39f | 6360 | |
6361 | @noindent | |
6362 | This specifies that the name to be used for the variable @code{foo} in | |
6363 | the assembler code should be @samp{myfoo} rather than the usual | |
6364 | @samp{_foo}. | |
6365 | ||
6366 | On systems where an underscore is normally prepended to the name of a C | |
6367 | function or variable, this feature allows you to define names for the | |
6368 | linker that do not start with an underscore. | |
6369 | ||
cd5abf58 | 6370 | It does not make sense to use this feature with a non-static local |
6371 | variable since such variables do not have assembler names. If you are | |
6372 | trying to put the variable in a particular register, see @ref{Explicit | |
6373 | Reg Vars}. GCC presently accepts such code with a warning, but will | |
6374 | probably be changed to issue an error, rather than a warning, in the | |
6375 | future. | |
6376 | ||
146ef39f | 6377 | You cannot use @code{asm} in this way in a function @emph{definition}; but |
6378 | you can get the same effect by writing a declaration for the function | |
6379 | before its definition and putting @code{asm} there, like this: | |
6380 | ||
a0ecd6b1 | 6381 | @smallexample |
146ef39f | 6382 | extern func () asm ("FUNC"); |
6383 | ||
6384 | func (x, y) | |
6385 | int x, y; | |
4ae74ddd | 6386 | /* @r{@dots{}} */ |
a0ecd6b1 | 6387 | @end smallexample |
146ef39f | 6388 | |
6389 | It is up to you to make sure that the assembler names you choose do not | |
6390 | conflict with any other assembler symbols. Also, you must not use a | |
37744367 | 6391 | register name; that would produce completely invalid assembler code. GCC |
6392 | does not as yet have the ability to store static variables in registers. | |
146ef39f | 6393 | Perhaps that will be added. |
6394 | ||
6395 | @node Explicit Reg Vars | |
6396 | @section Variables in Specified Registers | |
6397 | @cindex explicit register variables | |
6398 | @cindex variables in specified registers | |
6399 | @cindex specified registers | |
6400 | @cindex registers, global allocation | |
6401 | ||
6402 | GNU C allows you to put a few global variables into specified hardware | |
6403 | registers. You can also specify the register in which an ordinary | |
6404 | register variable should be allocated. | |
6405 | ||
6406 | @itemize @bullet | |
6407 | @item | |
6408 | Global register variables reserve registers throughout the program. | |
6409 | This may be useful in programs such as programming language | |
6410 | interpreters which have a couple of global variables that are accessed | |
6411 | very often. | |
6412 | ||
6413 | @item | |
6414 | Local register variables in specific registers do not reserve the | |
1358f000 | 6415 | registers, except at the point where they are used as input or output |
6416 | operands in an @code{asm} statement and the @code{asm} statement itself is | |
6417 | not deleted. The compiler's data flow analysis is capable of determining | |
146ef39f | 6418 | where the specified registers contain live values, and where they are |
dcb61f7f | 6419 | available for other uses. Stores into local register variables may be deleted |
d2763590 | 6420 | when they appear to be dead according to dataflow analysis. References |
6421 | to local register variables may be deleted or moved or simplified. | |
146ef39f | 6422 | |
6423 | These local variables are sometimes convenient for use with the extended | |
6424 | @code{asm} feature (@pxref{Extended Asm}), if you want to write one | |
6425 | output of the assembler instruction directly into a particular register. | |
6426 | (This will work provided the register you specify fits the constraints | |
6427 | specified for that operand in the @code{asm}.) | |
6428 | @end itemize | |
6429 | ||
6430 | @menu | |
6431 | * Global Reg Vars:: | |
6432 | * Local Reg Vars:: | |
6433 | @end menu | |
6434 | ||
6435 | @node Global Reg Vars | |
6436 | @subsection Defining Global Register Variables | |
6437 | @cindex global register variables | |
6438 | @cindex registers, global variables in | |
6439 | ||
6440 | You can define a global register variable in GNU C like this: | |
6441 | ||
a0ecd6b1 | 6442 | @smallexample |
146ef39f | 6443 | register int *foo asm ("a5"); |
a0ecd6b1 | 6444 | @end smallexample |
146ef39f | 6445 | |
6446 | @noindent | |
6447 | Here @code{a5} is the name of the register which should be used. Choose a | |
6448 | register which is normally saved and restored by function calls on your | |
6449 | machine, so that library routines will not clobber it. | |
6450 | ||
6451 | Naturally the register name is cpu-dependent, so you would need to | |
6452 | conditionalize your program according to cpu type. The register | |
6453 | @code{a5} would be a good choice on a 68000 for a variable of pointer | |
6454 | type. On machines with register windows, be sure to choose a ``global'' | |
6455 | register that is not affected magically by the function call mechanism. | |
6456 | ||
6457 | In addition, operating systems on one type of cpu may differ in how they | |
6458 | name the registers; then you would need additional conditionals. For | |
6459 | example, some 68000 operating systems call this register @code{%a5}. | |
6460 | ||
6461 | Eventually there may be a way of asking the compiler to choose a register | |
6462 | automatically, but first we need to figure out how it should choose and | |
6463 | how to enable you to guide the choice. No solution is evident. | |
6464 | ||
6465 | Defining a global register variable in a certain register reserves that | |
6466 | register entirely for this use, at least within the current compilation. | |
6467 | The register will not be allocated for any other purpose in the functions | |
6468 | in the current compilation. The register will not be saved and restored by | |
6469 | these functions. Stores into this register are never deleted even if they | |
6470 | would appear to be dead, but references may be deleted or moved or | |
6471 | simplified. | |
6472 | ||
6473 | It is not safe to access the global register variables from signal | |
6474 | handlers, or from more than one thread of control, because the system | |
6475 | library routines may temporarily use the register for other things (unless | |
6476 | you recompile them specially for the task at hand). | |
6477 | ||
6478 | @cindex @code{qsort}, and global register variables | |
6479 | It is not safe for one function that uses a global register variable to | |
6480 | call another such function @code{foo} by way of a third function | |
0858f8a2 | 6481 | @code{lose} that was compiled without knowledge of this variable (i.e.@: in a |
146ef39f | 6482 | different source file in which the variable wasn't declared). This is |
6483 | because @code{lose} might save the register and put some other value there. | |
6484 | For example, you can't expect a global register variable to be available in | |
6485 | the comparison-function that you pass to @code{qsort}, since @code{qsort} | |
6486 | might have put something else in that register. (If you are prepared to | |
6487 | recompile @code{qsort} with the same global register variable, you can | |
6488 | solve this problem.) | |
6489 | ||
6490 | If you want to recompile @code{qsort} or other source files which do not | |
6491 | actually use your global register variable, so that they will not use that | |
6492 | register for any other purpose, then it suffices to specify the compiler | |
67791935 | 6493 | option @option{-ffixed-@var{reg}}. You need not actually add a global |
146ef39f | 6494 | register declaration to their source code. |
6495 | ||
6496 | A function which can alter the value of a global register variable cannot | |
6497 | safely be called from a function compiled without this variable, because it | |
6498 | could clobber the value the caller expects to find there on return. | |
6499 | Therefore, the function which is the entry point into the part of the | |
6500 | program that uses the global register variable must explicitly save and | |
6501 | restore the value which belongs to its caller. | |
6502 | ||
6503 | @cindex register variable after @code{longjmp} | |
6504 | @cindex global register after @code{longjmp} | |
6505 | @cindex value after @code{longjmp} | |
6506 | @findex longjmp | |
6507 | @findex setjmp | |
6508 | On most machines, @code{longjmp} will restore to each global register | |
6509 | variable the value it had at the time of the @code{setjmp}. On some | |
6510 | machines, however, @code{longjmp} will not change the value of global | |
6511 | register variables. To be portable, the function that called @code{setjmp} | |
6512 | should make other arrangements to save the values of the global register | |
6513 | variables, and to restore them in a @code{longjmp}. This way, the same | |
6514 | thing will happen regardless of what @code{longjmp} does. | |
6515 | ||
6516 | All global register variable declarations must precede all function | |
6517 | definitions. If such a declaration could appear after function | |
6518 | definitions, the declaration would be too late to prevent the register from | |
6519 | being used for other purposes in the preceding functions. | |
6520 | ||
6521 | Global register variables may not have initial values, because an | |
6522 | executable file has no means to supply initial contents for a register. | |
6523 | ||
7800959d | 6524 | On the SPARC, there are reports that g3 @dots{} g7 are suitable |
146ef39f | 6525 | registers, but certain library functions, such as @code{getwd}, as well |
6526 | as the subroutines for division and remainder, modify g3 and g4. g1 and | |
6527 | g2 are local temporaries. | |
6528 | ||
6529 | On the 68000, a2 @dots{} a5 should be suitable, as should d2 @dots{} d7. | |
6530 | Of course, it will not do to use more than a few of those. | |
6531 | ||
6532 | @node Local Reg Vars | |
6533 | @subsection Specifying Registers for Local Variables | |
6534 | @cindex local variables, specifying registers | |
6535 | @cindex specifying registers for local variables | |
6536 | @cindex registers for local variables | |
6537 | ||
6538 | You can define a local register variable with a specified register | |
6539 | like this: | |
6540 | ||
a0ecd6b1 | 6541 | @smallexample |
146ef39f | 6542 | register int *foo asm ("a5"); |
a0ecd6b1 | 6543 | @end smallexample |
146ef39f | 6544 | |
6545 | @noindent | |
6546 | Here @code{a5} is the name of the register which should be used. Note | |
6547 | that this is the same syntax used for defining global register | |
6548 | variables, but for a local variable it would appear within a function. | |
6549 | ||
6550 | Naturally the register name is cpu-dependent, but this is not a | |
6551 | problem, since specific registers are most often useful with explicit | |
6552 | assembler instructions (@pxref{Extended Asm}). Both of these things | |
6553 | generally require that you conditionalize your program according to | |
6554 | cpu type. | |
6555 | ||
6556 | In addition, operating systems on one type of cpu may differ in how they | |
6557 | name the registers; then you would need additional conditionals. For | |
6558 | example, some 68000 operating systems call this register @code{%a5}. | |
6559 | ||
146ef39f | 6560 | Defining such a register variable does not reserve the register; it |
6561 | remains available for other uses in places where flow control determines | |
d40bf399 | 6562 | the variable's value is not live. |
997d68fe | 6563 | |
37744367 | 6564 | This option does not guarantee that GCC will generate code that has |
997d68fe | 6565 | this variable in the register you specify at all times. You may not |
1358f000 | 6566 | code an explicit reference to this register in the @emph{assembler |
6567 | instruction template} part of an @code{asm} statement and assume it will | |
6568 | always refer to this variable. However, using the variable as an | |
6569 | @code{asm} @emph{operand} guarantees that the specified register is used | |
6570 | for the operand. | |
146ef39f | 6571 | |
dcb61f7f | 6572 | Stores into local register variables may be deleted when they appear to be dead |
d2763590 | 6573 | according to dataflow analysis. References to local register variables may |
6574 | be deleted or moved or simplified. | |
6575 | ||
2de78c9f | 6576 | As for global register variables, it's recommended that you choose a |
6577 | register which is normally saved and restored by function calls on | |
6578 | your machine, so that library routines will not clobber it. A common | |
6579 | pitfall is to initialize multiple call-clobbered registers with | |
6580 | arbitrary expressions, where a function call or library call for an | |
6581 | arithmetic operator will overwrite a register value from a previous | |
6582 | assignment, for example @code{r0} below: | |
6583 | @smallexample | |
6584 | register int *p1 asm ("r0") = @dots{}; | |
6585 | register int *p2 asm ("r1") = @dots{}; | |
6586 | @end smallexample | |
6587 | In those cases, a solution is to use a temporary variable for | |
6588 | each arbitrary expression. @xref{Example of asm with clobbered asm reg}. | |
6589 | ||
146ef39f | 6590 | @node Alternate Keywords |
6591 | @section Alternate Keywords | |
6592 | @cindex alternate keywords | |
6593 | @cindex keywords, alternate | |
6594 | ||
78b1f616 | 6595 | @option{-ansi} and the various @option{-std} options disable certain |
455730ef | 6596 | keywords. This causes trouble when you want to use GNU C extensions, or |
6597 | a general-purpose header file that should be usable by all programs, | |
6598 | including ISO C programs. The keywords @code{asm}, @code{typeof} and | |
6599 | @code{inline} are not available in programs compiled with | |
6600 | @option{-ansi} or @option{-std} (although @code{inline} can be used in a | |
32074525 | 6601 | program compiled with @option{-std=c99} or @option{-std=c11}). The |
39012afb | 6602 | ISO C99 keyword |
78b1f616 | 6603 | @code{restrict} is only available when @option{-std=gnu99} (which will |
6604 | eventually be the default) or @option{-std=c99} (or the equivalent | |
39012afb | 6605 | @option{-std=iso9899:1999}), or an option for a later standard |
6606 | version, is used. | |
146ef39f | 6607 | |
6608 | The way to solve these problems is to put @samp{__} at the beginning and | |
6609 | end of each problematical keyword. For example, use @code{__asm__} | |
455730ef | 6610 | instead of @code{asm}, and @code{__inline__} instead of @code{inline}. |
146ef39f | 6611 | |
6612 | Other C compilers won't accept these alternative keywords; if you want to | |
6613 | compile with another compiler, you can define the alternate keywords as | |
6614 | macros to replace them with the customary keywords. It looks like this: | |
6615 | ||
a0ecd6b1 | 6616 | @smallexample |
146ef39f | 6617 | #ifndef __GNUC__ |
6618 | #define __asm__ asm | |
6619 | #endif | |
a0ecd6b1 | 6620 | @end smallexample |
146ef39f | 6621 | |
d4303d2a | 6622 | @findex __extension__ |
67791935 | 6623 | @opindex pedantic |
6624 | @option{-pedantic} and other options cause warnings for many GNU C extensions. | |
6b88ddb7 | 6625 | You can |
146ef39f | 6626 | prevent such warnings within one expression by writing |
6627 | @code{__extension__} before the expression. @code{__extension__} has no | |
6628 | effect aside from this. | |
6629 | ||
6630 | @node Incomplete Enums | |
6631 | @section Incomplete @code{enum} Types | |
6632 | ||
6633 | You can define an @code{enum} tag without specifying its possible values. | |
6634 | This results in an incomplete type, much like what you get if you write | |
6635 | @code{struct foo} without describing the elements. A later declaration | |
6636 | which does specify the possible values completes the type. | |
6637 | ||
6638 | You can't allocate variables or storage using the type while it is | |
6639 | incomplete. However, you can work with pointers to that type. | |
6640 | ||
6641 | This extension may not be very useful, but it makes the handling of | |
6642 | @code{enum} more consistent with the way @code{struct} and @code{union} | |
6643 | are handled. | |
6644 | ||
6645 | This extension is not supported by GNU C++. | |
6646 | ||
6647 | @node Function Names | |
6648 | @section Function Names as Strings | |
ebc03810 | 6649 | @cindex @code{__func__} identifier |
3cfa0cc4 | 6650 | @cindex @code{__FUNCTION__} identifier |
6651 | @cindex @code{__PRETTY_FUNCTION__} identifier | |
146ef39f | 6652 | |
ebc03810 | 6653 | GCC provides three magic variables which hold the name of the current |
6654 | function, as a string. The first of these is @code{__func__}, which | |
6655 | is part of the C99 standard: | |
6656 | ||
ebc03810 | 6657 | The identifier @code{__func__} is implicitly declared by the translator |
6658 | as if, immediately following the opening brace of each function | |
6659 | definition, the declaration | |
6660 | ||
6661 | @smallexample | |
6662 | static const char __func__[] = "function-name"; | |
6663 | @end smallexample | |
146ef39f | 6664 | |
e66bbea3 | 6665 | @noindent |
ebc03810 | 6666 | appeared, where function-name is the name of the lexically-enclosing |
6667 | function. This name is the unadorned name of the function. | |
ebc03810 | 6668 | |
6669 | @code{__FUNCTION__} is another name for @code{__func__}. Older | |
6670 | versions of GCC recognize only this name. However, it is not | |
6671 | standardized. For maximum portability, we recommend you use | |
6672 | @code{__func__}, but provide a fallback definition with the | |
6673 | preprocessor: | |
6674 | ||
6675 | @smallexample | |
6676 | #if __STDC_VERSION__ < 199901L | |
6677 | # if __GNUC__ >= 2 | |
6678 | # define __func__ __FUNCTION__ | |
6679 | # else | |
6680 | # define __func__ "<unknown>" | |
6681 | # endif | |
6682 | #endif | |
6683 | @end smallexample | |
6684 | ||
6685 | In C, @code{__PRETTY_FUNCTION__} is yet another name for | |
6686 | @code{__func__}. However, in C++, @code{__PRETTY_FUNCTION__} contains | |
6687 | the type signature of the function as well as its bare name. For | |
6688 | example, this program: | |
146ef39f | 6689 | |
6690 | @smallexample | |
6691 | extern "C" @{ | |
6692 | extern int printf (char *, ...); | |
6693 | @} | |
6694 | ||
6695 | class a @{ | |
6696 | public: | |
20a69fd5 | 6697 | void sub (int i) |
146ef39f | 6698 | @{ |
6699 | printf ("__FUNCTION__ = %s\n", __FUNCTION__); | |
6700 | printf ("__PRETTY_FUNCTION__ = %s\n", __PRETTY_FUNCTION__); | |
6701 | @} | |
6702 | @}; | |
6703 | ||
6704 | int | |
6705 | main (void) | |
6706 | @{ | |
6707 | a ax; | |
6708 | ax.sub (0); | |
6709 | return 0; | |
6710 | @} | |
6711 | @end smallexample | |
6712 | ||
6713 | @noindent | |
6714 | gives this output: | |
6715 | ||
6716 | @smallexample | |
6717 | __FUNCTION__ = sub | |
ebc03810 | 6718 | __PRETTY_FUNCTION__ = void a::sub(int) |
b082e8af | 6719 | @end smallexample |
6720 | ||
ebc03810 | 6721 | These identifiers are not preprocessor macros. In GCC 3.3 and |
6722 | earlier, in C only, @code{__FUNCTION__} and @code{__PRETTY_FUNCTION__} | |
6723 | were treated as string literals; they could be used to initialize | |
6724 | @code{char} arrays, and they could be concatenated with other string | |
6725 | literals. GCC 3.4 and later treat them as variables, like | |
6726 | @code{__func__}. In C++, @code{__FUNCTION__} and | |
6727 | @code{__PRETTY_FUNCTION__} have always been variables. | |
b082e8af | 6728 | |
146ef39f | 6729 | @node Return Address |
6730 | @section Getting the Return or Frame Address of a Function | |
6731 | ||
6732 | These functions may be used to get information about the callers of a | |
6733 | function. | |
6734 | ||
67791935 | 6735 | @deftypefn {Built-in Function} {void *} __builtin_return_address (unsigned int @var{level}) |
146ef39f | 6736 | This function returns the return address of the current function, or of |
6737 | one of its callers. The @var{level} argument is number of frames to | |
6738 | scan up the call stack. A value of @code{0} yields the return address | |
6739 | of the current function, a value of @code{1} yields the return address | |
b3d47662 | 6740 | of the caller of the current function, and so forth. When inlining |
85456819 | 6741 | the expected behavior is that the function will return the address of |
6742 | the function that will be returned to. To work around this behavior use | |
6743 | the @code{noinline} function attribute. | |
146ef39f | 6744 | |
6745 | The @var{level} argument must be a constant integer. | |
6746 | ||
6747 | On some machines it may be impossible to determine the return address of | |
6748 | any function other than the current one; in such cases, or when the top | |
1288313e | 6749 | of the stack has been reached, this function will return @code{0} or a |
b3d47662 | 6750 | random value. In addition, @code{__builtin_frame_address} may be used |
1288313e | 6751 | to determine if the top of the stack has been reached. |
146ef39f | 6752 | |
23807f43 | 6753 | Additional post-processing of the returned value may be needed, see |
6754 | @code{__builtin_extract_return_address}. | |
6755 | ||
f45856ef | 6756 | This function should only be used with a nonzero argument for debugging |
146ef39f | 6757 | purposes. |
67791935 | 6758 | @end deftypefn |
146ef39f | 6759 | |
23807f43 | 6760 | @deftypefn {Built-in Function} {void *} __builtin_extract_return_address (void *@var{addr}) |
6761 | The address as returned by @code{__builtin_return_address} may have to be fed | |
6762 | through this function to get the actual encoded address. For example, on the | |
6763 | 31-bit S/390 platform the highest bit has to be masked out, or on SPARC | |
6764 | platforms an offset has to be added for the true next instruction to be | |
6765 | executed. | |
6766 | ||
6767 | If no fixup is needed, this function simply passes through @var{addr}. | |
6768 | @end deftypefn | |
6769 | ||
6770 | @deftypefn {Built-in Function} {void *} __builtin_frob_return_address (void *@var{addr}) | |
6771 | This function does the reverse of @code{__builtin_extract_return_address}. | |
6772 | @end deftypefn | |
6773 | ||
67791935 | 6774 | @deftypefn {Built-in Function} {void *} __builtin_frame_address (unsigned int @var{level}) |
146ef39f | 6775 | This function is similar to @code{__builtin_return_address}, but it |
6776 | returns the address of the function frame rather than the return address | |
6777 | of the function. Calling @code{__builtin_frame_address} with a value of | |
6778 | @code{0} yields the frame address of the current function, a value of | |
6779 | @code{1} yields the frame address of the caller of the current function, | |
6780 | and so forth. | |
6781 | ||
6782 | The frame is the area on the stack which holds local variables and saved | |
6783 | registers. The frame address is normally the address of the first word | |
6784 | pushed on to the stack by the function. However, the exact definition | |
6785 | depends upon the processor and the calling convention. If the processor | |
6786 | has a dedicated frame pointer register, and the function has a frame, | |
6787 | then @code{__builtin_frame_address} will return the value of the frame | |
6788 | pointer register. | |
6789 | ||
1288313e | 6790 | On some machines it may be impossible to determine the frame address of |
6791 | any function other than the current one; in such cases, or when the top | |
6792 | of the stack has been reached, this function will return @code{0} if | |
6793 | the first frame pointer is properly initialized by the startup code. | |
6794 | ||
f45856ef | 6795 | This function should only be used with a nonzero argument for debugging |
1288313e | 6796 | purposes. |
67791935 | 6797 | @end deftypefn |
146ef39f | 6798 | |
ee5925ea | 6799 | @node Vector Extensions |
6800 | @section Using vector instructions through built-in functions | |
6801 | ||
6802 | On some targets, the instruction set contains SIMD vector instructions that | |
6803 | operate on multiple values contained in one large register at the same time. | |
4f0fcaad | 6804 | For example, on the i386 the MMX, 3DNow!@: and SSE extensions can be used |
ee5925ea | 6805 | this way. |
6806 | ||
6807 | The first step in using these extensions is to provide the necessary data | |
6808 | types. This should be done using an appropriate @code{typedef}: | |
6809 | ||
a0ecd6b1 | 6810 | @smallexample |
4917c376 | 6811 | typedef int v4si __attribute__ ((vector_size (16))); |
a0ecd6b1 | 6812 | @end smallexample |
ee5925ea | 6813 | |
4917c376 | 6814 | The @code{int} type specifies the base type, while the attribute specifies |
6815 | the vector size for the variable, measured in bytes. For example, the | |
6816 | declaration above causes the compiler to set the mode for the @code{v4si} | |
6817 | type to be 16 bytes wide and divided into @code{int} sized units. For | |
6818 | a 32-bit @code{int} this means a vector of 4 units of 4 bytes, and the | |
6819 | corresponding mode of @code{foo} will be @acronym{V4SI}. | |
ee5925ea | 6820 | |
4917c376 | 6821 | The @code{vector_size} attribute is only applicable to integral and |
6822 | float scalars, although arrays, pointers, and function return values | |
6823 | are allowed in conjunction with this construct. | |
6824 | ||
6825 | All the basic integer types can be used as base types, both as signed | |
6826 | and as unsigned: @code{char}, @code{short}, @code{int}, @code{long}, | |
6827 | @code{long long}. In addition, @code{float} and @code{double} can be | |
6828 | used to build floating-point vector types. | |
ee5925ea | 6829 | |
ead34f59 | 6830 | Specifying a combination that is not valid for the current architecture |
ef8d967c | 6831 | will cause GCC to synthesize the instructions using a narrower mode. |
ead34f59 | 6832 | For example, if you specify a variable of type @code{V4SI} and your |
ef8d967c | 6833 | architecture does not allow for this specific SIMD type, GCC will |
ead34f59 | 6834 | produce code that uses 4 @code{SIs}. |
6835 | ||
6836 | The types defined in this manner can be used with a subset of normal C | |
ef8d967c | 6837 | operations. Currently, GCC will allow using the following operators |
b6d7101e | 6838 | on these types: @code{+, -, *, /, unary minus, ^, |, &, ~, %}@. |
ead34f59 | 6839 | |
6840 | The operations behave like C++ @code{valarrays}. Addition is defined as | |
6841 | the addition of the corresponding elements of the operands. For | |
6842 | example, in the code below, each of the 4 elements in @var{a} will be | |
6843 | added to the corresponding 4 elements in @var{b} and the resulting | |
6844 | vector will be stored in @var{c}. | |
6845 | ||
a0ecd6b1 | 6846 | @smallexample |
4917c376 | 6847 | typedef int v4si __attribute__ ((vector_size (16))); |
ead34f59 | 6848 | |
6849 | v4si a, b, c; | |
6850 | ||
6851 | c = a + b; | |
a0ecd6b1 | 6852 | @end smallexample |
ead34f59 | 6853 | |
b51e481d | 6854 | Subtraction, multiplication, division, and the logical operations |
6855 | operate in a similar manner. Likewise, the result of using the unary | |
6856 | minus or complement operators on a vector type is a vector whose | |
6857 | elements are the negative or complemented values of the corresponding | |
ead34f59 | 6858 | elements in the operand. |
6859 | ||
191b2c61 | 6860 | In C it is possible to use shifting operators @code{<<}, @code{>>} on |
6861 | integer-type vectors. The operation is defined as following: @code{@{a0, | |
6862 | a1, @dots{}, an@} >> @{b0, b1, @dots{}, bn@} == @{a0 >> b0, a1 >> b1, | |
6863 | @dots{}, an >> bn@}}@. Vector operands must have the same number of | |
7dfa155b | 6864 | elements. |
6865 | ||
6866 | For the convenience in C it is allowed to use a binary vector operation | |
6867 | where one operand is a scalar. In that case the compiler will transform | |
6868 | the scalar operand into a vector where each element is the scalar from | |
6869 | the operation. The transformation will happen only if the scalar could be | |
6870 | safely converted to the vector-element type. | |
191b2c61 | 6871 | Consider the following code. |
6872 | ||
6873 | @smallexample | |
6874 | typedef int v4si __attribute__ ((vector_size (16))); | |
6875 | ||
7dfa155b | 6876 | v4si a, b, c; |
6877 | long l; | |
6878 | ||
6879 | a = b + 1; /* a = b + @{1,1,1,1@}; */ | |
6880 | a = 2 * b; /* a = @{2,2,2,2@} * b; */ | |
191b2c61 | 6881 | |
7dfa155b | 6882 | a = l + a; /* Error, cannot convert long to int. */ |
191b2c61 | 6883 | @end smallexample |
6884 | ||
7059d45d | 6885 | Vectors can be subscripted as if the vector were an array with |
93426222 | 6886 | the same number of elements and base type. Out of bound accesses |
6887 | invoke undefined behavior at runtime. Warnings for out of bound | |
6888 | accesses for vector subscription can be enabled with | |
6889 | @option{-Warray-bounds}. | |
6890 | ||
d7ad16c2 | 6891 | In GNU C vector comparison is supported within standard comparison |
6892 | operators: @code{==, !=, <, <=, >, >=}. Comparison operands can be | |
6893 | vector expressions of integer-type or real-type. Comparison between | |
6894 | integer-type vectors and real-type vectors are not supported. The | |
6895 | result of the comparison is a vector of the same width and number of | |
6896 | elements as the comparison operands with a signed integral element | |
6897 | type. | |
6898 | ||
6899 | Vectors are compared element-wise producing 0 when comparison is false | |
6900 | and -1 (constant of the appropriate type where all bits are set) | |
6901 | otherwise. Consider the following example. | |
6902 | ||
6903 | @smallexample | |
6904 | typedef int v4si __attribute__ ((vector_size (16))); | |
6905 | ||
6906 | v4si a = @{1,2,3,4@}; | |
6907 | v4si b = @{3,2,1,4@}; | |
6908 | v4si c; | |
6909 | ||
6910 | c = a > b; /* The result would be @{0, 0,-1, 0@} */ | |
6911 | c = a == b; /* The result would be @{0,-1, 0,-1@} */ | |
6912 | @end smallexample | |
6913 | ||
6cf89e04 | 6914 | Vector shuffling is available using functions |
6915 | @code{__builtin_shuffle (vec, mask)} and | |
f4803722 | 6916 | @code{__builtin_shuffle (vec0, vec1, mask)}. |
6917 | Both functions construct a permutation of elements from one or two | |
6918 | vectors and return a vector of the same type as the input vector(s). | |
6919 | The @var{mask} is an integral vector with the same width (@var{W}) | |
6920 | and element count (@var{N}) as the output vector. | |
6cf89e04 | 6921 | |
f4803722 | 6922 | The elements of the input vectors are numbered in memory ordering of |
6923 | @var{vec0} beginning at 0 and @var{vec1} beginning at @var{N}. The | |
6924 | elements of @var{mask} are considered modulo @var{N} in the single-operand | |
6925 | case and modulo @math{2*@var{N}} in the two-operand case. | |
6926 | ||
6927 | Consider the following example, | |
6cf89e04 | 6928 | |
6929 | @smallexample | |
6930 | typedef int v4si __attribute__ ((vector_size (16))); | |
6931 | ||
6932 | v4si a = @{1,2,3,4@}; | |
6933 | v4si b = @{5,6,7,8@}; | |
6934 | v4si mask1 = @{0,1,1,3@}; | |
6935 | v4si mask2 = @{0,4,2,5@}; | |
6936 | v4si res; | |
6937 | ||
6938 | res = __builtin_shuffle (a, mask1); /* res is @{1,2,2,4@} */ | |
6939 | res = __builtin_shuffle (a, b, mask2); /* res is @{1,5,3,6@} */ | |
6940 | @end smallexample | |
6941 | ||
f4803722 | 6942 | Note that @code{__builtin_shuffle} is intentionally semantically |
6943 | compatible with the OpenCL @code{shuffle} and @code{shuffle2} functions. | |
6944 | ||
ead34f59 | 6945 | You can declare variables and use them in function calls and returns, as |
6946 | well as in assignments and some casts. You can specify a vector type as | |
6947 | a return type for a function. Vector types can also be used as function | |
6948 | arguments. It is possible to cast from one vector type to another, | |
6949 | provided they are of the same size (in fact, you can also cast vectors | |
6950 | to and from other datatypes of the same size). | |
6951 | ||
6952 | You cannot operate between vectors of different lengths or different | |
d835d5ce | 6953 | signedness without a cast. |
ead34f59 | 6954 | |
43bf5d72 | 6955 | @node Offsetof |
6956 | @section Offsetof | |
6957 | @findex __builtin_offsetof | |
6958 | ||
6959 | GCC implements for both C and C++ a syntactic extension to implement | |
6960 | the @code{offsetof} macro. | |
6961 | ||
6962 | @smallexample | |
6963 | primary: | |
c24c5fac | 6964 | "__builtin_offsetof" "(" @code{typename} "," offsetof_member_designator ")" |
43bf5d72 | 6965 | |
6966 | offsetof_member_designator: | |
c24c5fac | 6967 | @code{identifier} |
6968 | | offsetof_member_designator "." @code{identifier} | |
6969 | | offsetof_member_designator "[" @code{expr} "]" | |
43bf5d72 | 6970 | @end smallexample |
6971 | ||
6972 | This extension is sufficient such that | |
6973 | ||
6974 | @smallexample | |
6975 | #define offsetof(@var{type}, @var{member}) __builtin_offsetof (@var{type}, @var{member}) | |
6976 | @end smallexample | |
6977 | ||
6978 | is a suitable definition of the @code{offsetof} macro. In C++, @var{type} | |
6979 | may be dependent. In either case, @var{member} may consist of a single | |
6980 | identifier, or a sequence of member accesses and array references. | |
6981 | ||
1cd6e20d | 6982 | @node __sync Builtins |
6983 | @section Legacy __sync built-in functions for atomic memory access | |
b6a5fc45 | 6984 | |
6985 | The following builtins are intended to be compatible with those described | |
6986 | in the @cite{Intel Itanium Processor-specific Application Binary Interface}, | |
6987 | section 7.4. As such, they depart from the normal GCC practice of using | |
6988 | the ``__builtin_'' prefix, and further that they are overloaded such that | |
6989 | they work on multiple types. | |
6990 | ||
6991 | The definition given in the Intel documentation allows only for the use of | |
6992 | the types @code{int}, @code{long}, @code{long long} as well as their unsigned | |
6993 | counterparts. GCC will allow any integral scalar or pointer type that is | |
6994 | 1, 2, 4 or 8 bytes in length. | |
6995 | ||
6996 | Not all operations are supported by all target processors. If a particular | |
6997 | operation cannot be implemented on the target processor, a warning will be | |
6998 | generated and a call an external function will be generated. The external | |
6999 | function will carry the same name as the builtin, with an additional suffix | |
7000 | @samp{_@var{n}} where @var{n} is the size of the data type. | |
7001 | ||
7002 | @c ??? Should we have a mechanism to suppress this warning? This is almost | |
7003 | @c useful for implementing the operation under the control of an external | |
7004 | @c mutex. | |
7005 | ||
7006 | In most cases, these builtins are considered a @dfn{full barrier}. That is, | |
7007 | no memory operand will be moved across the operation, either forward or | |
7008 | backward. Further, instructions will be issued as necessary to prevent the | |
7009 | processor from speculating loads across the operation and from queuing stores | |
7010 | after the operation. | |
7011 | ||
d2258b2f | 7012 | All of the routines are described in the Intel documentation to take |
b6a5fc45 | 7013 | ``an optional list of variables protected by the memory barrier''. It's |
7014 | not clear what is meant by that; it could mean that @emph{only} the | |
7015 | following variables are protected, or it could mean that these variables | |
7016 | should in addition be protected. At present GCC ignores this list and | |
7017 | protects all variables which are globally accessible. If in the future | |
7018 | we make some use of this list, an empty list will continue to mean all | |
7019 | globally accessible variables. | |
7020 | ||
7021 | @table @code | |
7022 | @item @var{type} __sync_fetch_and_add (@var{type} *ptr, @var{type} value, ...) | |
7023 | @itemx @var{type} __sync_fetch_and_sub (@var{type} *ptr, @var{type} value, ...) | |
7024 | @itemx @var{type} __sync_fetch_and_or (@var{type} *ptr, @var{type} value, ...) | |
7025 | @itemx @var{type} __sync_fetch_and_and (@var{type} *ptr, @var{type} value, ...) | |
7026 | @itemx @var{type} __sync_fetch_and_xor (@var{type} *ptr, @var{type} value, ...) | |
7027 | @itemx @var{type} __sync_fetch_and_nand (@var{type} *ptr, @var{type} value, ...) | |
7028 | @findex __sync_fetch_and_add | |
7029 | @findex __sync_fetch_and_sub | |
7030 | @findex __sync_fetch_and_or | |
7031 | @findex __sync_fetch_and_and | |
7032 | @findex __sync_fetch_and_xor | |
7033 | @findex __sync_fetch_and_nand | |
7034 | These builtins perform the operation suggested by the name, and | |
7035 | returns the value that had previously been in memory. That is, | |
7036 | ||
7037 | @smallexample | |
7038 | @{ tmp = *ptr; *ptr @var{op}= value; return tmp; @} | |
cf73e559 | 7039 | @{ tmp = *ptr; *ptr = ~(tmp & value); return tmp; @} // nand |
b6a5fc45 | 7040 | @end smallexample |
7041 | ||
cf73e559 | 7042 | @emph{Note:} GCC 4.4 and later implement @code{__sync_fetch_and_nand} |
7043 | builtin as @code{*ptr = ~(tmp & value)} instead of @code{*ptr = ~tmp & value}. | |
7044 | ||
b6a5fc45 | 7045 | @item @var{type} __sync_add_and_fetch (@var{type} *ptr, @var{type} value, ...) |
7046 | @itemx @var{type} __sync_sub_and_fetch (@var{type} *ptr, @var{type} value, ...) | |
7047 | @itemx @var{type} __sync_or_and_fetch (@var{type} *ptr, @var{type} value, ...) | |
7048 | @itemx @var{type} __sync_and_and_fetch (@var{type} *ptr, @var{type} value, ...) | |
7049 | @itemx @var{type} __sync_xor_and_fetch (@var{type} *ptr, @var{type} value, ...) | |
7050 | @itemx @var{type} __sync_nand_and_fetch (@var{type} *ptr, @var{type} value, ...) | |
7051 | @findex __sync_add_and_fetch | |
7052 | @findex __sync_sub_and_fetch | |
7053 | @findex __sync_or_and_fetch | |
7054 | @findex __sync_and_and_fetch | |
7055 | @findex __sync_xor_and_fetch | |
7056 | @findex __sync_nand_and_fetch | |
7057 | These builtins perform the operation suggested by the name, and | |
7058 | return the new value. That is, | |
7059 | ||
7060 | @smallexample | |
7061 | @{ *ptr @var{op}= value; return *ptr; @} | |
cf73e559 | 7062 | @{ *ptr = ~(*ptr & value); return *ptr; @} // nand |
b6a5fc45 | 7063 | @end smallexample |
7064 | ||
cf73e559 | 7065 | @emph{Note:} GCC 4.4 and later implement @code{__sync_nand_and_fetch} |
7066 | builtin as @code{*ptr = ~(*ptr & value)} instead of | |
7067 | @code{*ptr = ~*ptr & value}. | |
7068 | ||
142d1be6 | 7069 | @item bool __sync_bool_compare_and_swap (@var{type} *ptr, @var{type} oldval, @var{type} newval, ...) |
7070 | @itemx @var{type} __sync_val_compare_and_swap (@var{type} *ptr, @var{type} oldval, @var{type} newval, ...) | |
b6a5fc45 | 7071 | @findex __sync_bool_compare_and_swap |
7072 | @findex __sync_val_compare_and_swap | |
7073 | These builtins perform an atomic compare and swap. That is, if the current | |
7074 | value of @code{*@var{ptr}} is @var{oldval}, then write @var{newval} into | |
7075 | @code{*@var{ptr}}. | |
7076 | ||
7bd4091f | 7077 | The ``bool'' version returns true if the comparison is successful and |
b6a5fc45 | 7078 | @var{newval} was written. The ``val'' version returns the contents |
87121034 | 7079 | of @code{*@var{ptr}} before the operation. |
b6a5fc45 | 7080 | |
7081 | @item __sync_synchronize (...) | |
7082 | @findex __sync_synchronize | |
7083 | This builtin issues a full memory barrier. | |
7084 | ||
7085 | @item @var{type} __sync_lock_test_and_set (@var{type} *ptr, @var{type} value, ...) | |
7086 | @findex __sync_lock_test_and_set | |
7087 | This builtin, as described by Intel, is not a traditional test-and-set | |
7088 | operation, but rather an atomic exchange operation. It writes @var{value} | |
7089 | into @code{*@var{ptr}}, and returns the previous contents of | |
7090 | @code{*@var{ptr}}. | |
7091 | ||
7092 | Many targets have only minimal support for such locks, and do not support | |
7093 | a full exchange operation. In this case, a target may support reduced | |
7094 | functionality here by which the @emph{only} valid value to store is the | |
7095 | immediate constant 1. The exact value actually stored in @code{*@var{ptr}} | |
7096 | is implementation defined. | |
7097 | ||
7098 | This builtin is not a full barrier, but rather an @dfn{acquire barrier}. | |
7099 | This means that references after the builtin cannot move to (or be | |
7100 | speculated to) before the builtin, but previous memory stores may not | |
7bd4091f | 7101 | be globally visible yet, and previous memory loads may not yet be |
b6a5fc45 | 7102 | satisfied. |
7103 | ||
7104 | @item void __sync_lock_release (@var{type} *ptr, ...) | |
7105 | @findex __sync_lock_release | |
7106 | This builtin releases the lock acquired by @code{__sync_lock_test_and_set}. | |
7107 | Normally this means writing the constant 0 to @code{*@var{ptr}}. | |
7108 | ||
7109 | This builtin is not a full barrier, but rather a @dfn{release barrier}. | |
7110 | This means that all previous memory stores are globally visible, and all | |
7111 | previous memory loads have been satisfied, but following memory reads | |
7112 | are not prevented from being speculated to before the barrier. | |
7113 | @end table | |
7114 | ||
1cd6e20d | 7115 | @node __atomic Builtins |
7116 | @section Built-in functions for memory model aware atomic operations | |
7117 | ||
7118 | The following built-in functions approximately match the requirements for | |
7119 | C++11 memory model. Many are similar to the @samp{__sync} prefixed built-in | |
7120 | functions, but all also have a memory model parameter. These are all | |
7121 | identified by being prefixed with @samp{__atomic}, and most are overloaded | |
7122 | such that they work with multiple types. | |
7123 | ||
7124 | GCC will allow any integral scalar or pointer type that is 1, 2, 4, or 8 | |
7125 | bytes in length. 16-byte integral types are also allowed if | |
7126 | @samp{__int128} (@pxref{__int128}) is supported by the architecture. | |
7127 | ||
7128 | Target architectures are encouraged to provide their own patterns for | |
7129 | each of these built-in functions. If no target is provided, the original | |
7130 | non-memory model set of @samp{__sync} atomic built-in functions will be | |
7131 | utilized, along with any required synchronization fences surrounding it in | |
7132 | order to achieve the proper behaviour. Execution in this case is subject | |
7133 | to the same restrictions as those built-in functions. | |
7134 | ||
7135 | If there is no pattern or mechanism to provide a lock free instruction | |
7136 | sequence, a call is made to an external routine with the same parameters | |
7137 | to be resolved at runtime. | |
7138 | ||
7139 | The four non-arithmetic functions (load, store, exchange, and | |
7140 | compare_exchange) all have a generic version as well. This generic | |
7141 | version will work on any data type. If the data type size maps to one | |
7142 | of the integral sizes which may have lock free support, the generic | |
7143 | version will utilize the lock free built-in function. Otherwise an | |
7144 | external call is left to be resolved at runtime. This external call will | |
7145 | be the same format with the addition of a @samp{size_t} parameter inserted | |
7146 | as the first parameter indicating the size of the object being pointed to. | |
7147 | All objects must be the same size. | |
7148 | ||
7149 | There are 6 different memory models which can be specified. These map | |
7150 | to the same names in the C++11 standard. Refer there or to the | |
7151 | @uref{http://gcc.gnu.org/wiki/Atomic/GCCMM/AtomicSync,GCC wiki on | |
7152 | atomic synchronization} for more detailed definitions. These memory | |
7153 | models integrate both barriers to code motion as well as synchronization | |
7154 | requirements with other threads. These are listed in approximately | |
7f738025 | 7155 | ascending order of strength. It is also possible to use target specific |
7156 | flags for memory model flags, like Hardware Lock Elision. | |
1cd6e20d | 7157 | |
7158 | @table @code | |
7159 | @item __ATOMIC_RELAXED | |
7160 | No barriers or synchronization. | |
7161 | @item __ATOMIC_CONSUME | |
7162 | Data dependency only for both barrier and synchronization with another | |
7163 | thread. | |
7164 | @item __ATOMIC_ACQUIRE | |
7165 | Barrier to hoisting of code and synchronizes with release (or stronger) | |
7166 | semantic stores from another thread. | |
7167 | @item __ATOMIC_RELEASE | |
7168 | Barrier to sinking of code and synchronizes with acquire (or stronger) | |
7169 | semantic loads from another thread. | |
7170 | @item __ATOMIC_ACQ_REL | |
7171 | Full barrier in both directions and synchronizes with acquire loads and | |
7172 | release stores in another thread. | |
7173 | @item __ATOMIC_SEQ_CST | |
7174 | Full barrier in both directions and synchronizes with acquire loads and | |
7175 | release stores in all threads. | |
7176 | @end table | |
7177 | ||
23b5e150 | 7178 | When implementing patterns for these built-in functions, the memory model |
1cd6e20d | 7179 | parameter can be ignored as long as the pattern implements the most |
7180 | restrictive @code{__ATOMIC_SEQ_CST} model. Any of the other memory models | |
7181 | will execute correctly with this memory model but they may not execute as | |
7182 | efficiently as they could with a more appropriate implemention of the | |
7183 | relaxed requirements. | |
7184 | ||
7185 | Note that the C++11 standard allows for the memory model parameter to be | |
7186 | determined at runtime rather than at compile time. These built-in | |
7187 | functions will map any runtime value to @code{__ATOMIC_SEQ_CST} rather | |
7188 | than invoke a runtime library call or inline a switch statement. This is | |
7189 | standard compliant, safe, and the simplest approach for now. | |
7190 | ||
fd46ba2e | 7191 | The memory model parameter is a signed int, but only the lower 8 bits are |
7192 | reserved for the memory model. The remainder of the signed int is reserved | |
7193 | for future use and should be 0. Use of the predefined atomic values will | |
7194 | ensure proper usage. | |
7195 | ||
1cd6e20d | 7196 | @deftypefn {Built-in Function} @var{type} __atomic_load_n (@var{type} *ptr, int memmodel) |
7197 | This built-in function implements an atomic load operation. It returns the | |
7198 | contents of @code{*@var{ptr}}. | |
7199 | ||
7200 | The valid memory model variants are | |
7201 | @code{__ATOMIC_RELAXED}, @code{__ATOMIC_SEQ_CST}, @code{__ATOMIC_ACQUIRE}, | |
7202 | and @code{__ATOMIC_CONSUME}. | |
7203 | ||
7204 | @end deftypefn | |
7205 | ||
7206 | @deftypefn {Built-in Function} void __atomic_load (@var{type} *ptr, @var{type} *ret, int memmodel) | |
7207 | This is the generic version of an atomic load. It will return the | |
7208 | contents of @code{*@var{ptr}} in @code{*@var{ret}}. | |
7209 | ||
7210 | @end deftypefn | |
7211 | ||
7212 | @deftypefn {Built-in Function} void __atomic_store_n (@var{type} *ptr, @var{type} val, int memmodel) | |
7213 | This built-in function implements an atomic store operation. It writes | |
8808bf16 | 7214 | @code{@var{val}} into @code{*@var{ptr}}. |
1cd6e20d | 7215 | |
7216 | The valid memory model variants are | |
7217 | @code{__ATOMIC_RELAXED}, @code{__ATOMIC_SEQ_CST}, and @code{__ATOMIC_RELEASE}. | |
7218 | ||
7219 | @end deftypefn | |
7220 | ||
7221 | @deftypefn {Built-in Function} void __atomic_store (@var{type} *ptr, @var{type} *val, int memmodel) | |
7222 | This is the generic version of an atomic store. It will store the value | |
7223 | of @code{*@var{val}} into @code{*@var{ptr}}. | |
7224 | ||
7225 | @end deftypefn | |
7226 | ||
7227 | @deftypefn {Built-in Function} @var{type} __atomic_exchange_n (@var{type} *ptr, @var{type} val, int memmodel) | |
7228 | This built-in function implements an atomic exchange operation. It writes | |
7229 | @var{val} into @code{*@var{ptr}}, and returns the previous contents of | |
7230 | @code{*@var{ptr}}. | |
7231 | ||
1cd6e20d | 7232 | The valid memory model variants are |
7233 | @code{__ATOMIC_RELAXED}, @code{__ATOMIC_SEQ_CST}, @code{__ATOMIC_ACQUIRE}, | |
7234 | @code{__ATOMIC_RELEASE}, and @code{__ATOMIC_ACQ_REL}. | |
7235 | ||
7236 | @end deftypefn | |
7237 | ||
7238 | @deftypefn {Built-in Function} void __atomic_exchange (@var{type} *ptr, @var{type} *val, @var{type} *ret, int memmodel) | |
7239 | This is the generic version of an atomic exchange. It will store the | |
7240 | contents of @code{*@var{val}} into @code{*@var{ptr}}. The original value | |
7241 | of @code{*@var{ptr}} will be copied into @code{*@var{ret}}. | |
7242 | ||
7243 | @end deftypefn | |
7244 | ||
7245 | @deftypefn {Built-in Function} bool __atomic_compare_exchange_n (@var{type} *ptr, @var{type} *expected, @var{type} desired, bool weak, int success_memmodel, int failure_memmodel) | |
7246 | This built-in function implements an atomic compare and exchange operation. | |
7247 | This compares the contents of @code{*@var{ptr}} with the contents of | |
7248 | @code{*@var{expected}} and if equal, writes @var{desired} into | |
7249 | @code{*@var{ptr}}. If they are not equal, the current contents of | |
c311fe7e | 7250 | @code{*@var{ptr}} is written into @code{*@var{expected}}. @var{weak} is true |
7251 | for weak compare_exchange, and false for the strong variation. Many targets | |
7252 | only offer the strong variation and ignore the parameter. When in doubt, use | |
7253 | the strong variation. | |
1cd6e20d | 7254 | |
c5519669 | 7255 | True is returned if @var{desired} is written into |
1cd6e20d | 7256 | @code{*@var{ptr}} and the execution is considered to conform to the |
7257 | memory model specified by @var{success_memmodel}. There are no | |
7258 | restrictions on what memory model can be used here. | |
7259 | ||
7260 | False is returned otherwise, and the execution is considered to conform | |
7261 | to @var{failure_memmodel}. This memory model cannot be | |
7262 | @code{__ATOMIC_RELEASE} nor @code{__ATOMIC_ACQ_REL}. It also cannot be a | |
7263 | stronger model than that specified by @var{success_memmodel}. | |
7264 | ||
7265 | @end deftypefn | |
7266 | ||
7267 | @deftypefn {Built-in Function} bool __atomic_compare_exchange (@var{type} *ptr, @var{type} *expected, @var{type} *desired, bool weak, int success_memmodel, int failure_memmodel) | |
7268 | This built-in function implements the generic version of | |
7269 | @code{__atomic_compare_exchange}. The function is virtually identical to | |
7270 | @code{__atomic_compare_exchange_n}, except the desired value is also a | |
7271 | pointer. | |
7272 | ||
7273 | @end deftypefn | |
7274 | ||
7275 | @deftypefn {Built-in Function} @var{type} __atomic_add_fetch (@var{type} *ptr, @var{type} val, int memmodel) | |
7276 | @deftypefnx {Built-in Function} @var{type} __atomic_sub_fetch (@var{type} *ptr, @var{type} val, int memmodel) | |
7277 | @deftypefnx {Built-in Function} @var{type} __atomic_and_fetch (@var{type} *ptr, @var{type} val, int memmodel) | |
7278 | @deftypefnx {Built-in Function} @var{type} __atomic_xor_fetch (@var{type} *ptr, @var{type} val, int memmodel) | |
7279 | @deftypefnx {Built-in Function} @var{type} __atomic_or_fetch (@var{type} *ptr, @var{type} val, int memmodel) | |
7280 | @deftypefnx {Built-in Function} @var{type} __atomic_nand_fetch (@var{type} *ptr, @var{type} val, int memmodel) | |
7281 | These built-in functions perform the operation suggested by the name, and | |
7282 | return the result of the operation. That is, | |
7283 | ||
7284 | @smallexample | |
7285 | @{ *ptr @var{op}= val; return *ptr; @} | |
7286 | @end smallexample | |
7287 | ||
7288 | All memory models are valid. | |
7289 | ||
7290 | @end deftypefn | |
7291 | ||
7292 | @deftypefn {Built-in Function} @var{type} __atomic_fetch_add (@var{type} *ptr, @var{type} val, int memmodel) | |
7293 | @deftypefnx {Built-in Function} @var{type} __atomic_fetch_sub (@var{type} *ptr, @var{type} val, int memmodel) | |
7294 | @deftypefnx {Built-in Function} @var{type} __atomic_fetch_and (@var{type} *ptr, @var{type} val, int memmodel) | |
7295 | @deftypefnx {Built-in Function} @var{type} __atomic_fetch_xor (@var{type} *ptr, @var{type} val, int memmodel) | |
7296 | @deftypefnx {Built-in Function} @var{type} __atomic_fetch_or (@var{type} *ptr, @var{type} val, int memmodel) | |
7297 | @deftypefnx {Built-in Function} @var{type} __atomic_fetch_nand (@var{type} *ptr, @var{type} val, int memmodel) | |
7298 | These built-in functions perform the operation suggested by the name, and | |
7299 | return the value that had previously been in @code{*@var{ptr}}. That is, | |
7300 | ||
7301 | @smallexample | |
7302 | @{ tmp = *ptr; *ptr @var{op}= val; return tmp; @} | |
7303 | @end smallexample | |
7304 | ||
7305 | All memory models are valid. | |
7306 | ||
7307 | @end deftypefn | |
7308 | ||
39ca90d5 | 7309 | @deftypefn {Built-in Function} bool __atomic_test_and_set (void *ptr, int memmodel) |
faefd2ad | 7310 | |
7311 | This built-in function performs an atomic test-and-set operation on | |
39ca90d5 | 7312 | the byte at @code{*@var{ptr}}. The byte is set to some implementation |
7313 | defined non-zero "set" value and the return value is @code{true} if and only | |
7314 | if the previous contents were "set". | |
faefd2ad | 7315 | |
7316 | All memory models are valid. | |
7317 | ||
7318 | @end deftypefn | |
7319 | ||
7320 | @deftypefn {Built-in Function} void __atomic_clear (bool *ptr, int memmodel) | |
7321 | ||
7322 | This built-in function performs an atomic clear operation on | |
7323 | @code{*@var{ptr}}. After the operation, @code{*@var{ptr}} will contain 0. | |
7324 | ||
7325 | The valid memory model variants are | |
7326 | @code{__ATOMIC_RELAXED}, @code{__ATOMIC_SEQ_CST}, and | |
7327 | @code{__ATOMIC_RELEASE}. | |
7328 | ||
7329 | @end deftypefn | |
7330 | ||
1cd6e20d | 7331 | @deftypefn {Built-in Function} void __atomic_thread_fence (int memmodel) |
7332 | ||
7333 | This built-in function acts as a synchronization fence between threads | |
7334 | based on the specified memory model. | |
7335 | ||
7336 | All memory orders are valid. | |
7337 | ||
7338 | @end deftypefn | |
7339 | ||
7340 | @deftypefn {Built-in Function} void __atomic_signal_fence (int memmodel) | |
7341 | ||
7342 | This built-in function acts as a synchronization fence between a thread | |
7343 | and signal handlers based in the same thread. | |
7344 | ||
7345 | All memory orders are valid. | |
7346 | ||
7347 | @end deftypefn | |
7348 | ||
c311fe7e | 7349 | @deftypefn {Built-in Function} bool __atomic_always_lock_free (size_t size, void *ptr) |
1cd6e20d | 7350 | |
c311fe7e | 7351 | This built-in function returns true if objects of @var{size} bytes will always |
7352 | generate lock free atomic instructions for the target architecture. | |
7353 | @var{size} must resolve to a compile time constant and the result also resolves to compile time constant. | |
1cd6e20d | 7354 | |
c311fe7e | 7355 | @var{ptr} is an optional pointer to the object which may be used to determine |
7356 | alignment. A value of 0 indicates typical alignment should be used. The | |
7357 | compiler may also ignore this parameter. | |
1cd6e20d | 7358 | |
7359 | @smallexample | |
c311fe7e | 7360 | if (_atomic_always_lock_free (sizeof (long long), 0)) |
1cd6e20d | 7361 | @end smallexample |
7362 | ||
7363 | @end deftypefn | |
7364 | ||
c311fe7e | 7365 | @deftypefn {Built-in Function} bool __atomic_is_lock_free (size_t size, void *ptr) |
1cd6e20d | 7366 | |
c311fe7e | 7367 | This built-in function returns true if objects of @var{size} bytes will always |
1cd6e20d | 7368 | generate lock free atomic instructions for the target architecture. If |
7369 | it is not known to be lock free a call is made to a runtime routine named | |
7370 | @code{__atomic_is_lock_free}. | |
7371 | ||
c311fe7e | 7372 | @var{ptr} is an optional pointer to the object which may be used to determine |
7373 | alignment. A value of 0 indicates typical alignment should be used. The | |
7374 | compiler may also ignore this parameter. | |
1cd6e20d | 7375 | @end deftypefn |
7376 | ||
0a39fd54 | 7377 | @node Object Size Checking |
7378 | @section Object Size Checking Builtins | |
7379 | @findex __builtin_object_size | |
7380 | @findex __builtin___memcpy_chk | |
7381 | @findex __builtin___mempcpy_chk | |
7382 | @findex __builtin___memmove_chk | |
7383 | @findex __builtin___memset_chk | |
7384 | @findex __builtin___strcpy_chk | |
7385 | @findex __builtin___stpcpy_chk | |
7386 | @findex __builtin___strncpy_chk | |
7387 | @findex __builtin___strcat_chk | |
7388 | @findex __builtin___strncat_chk | |
7389 | @findex __builtin___sprintf_chk | |
7390 | @findex __builtin___snprintf_chk | |
7391 | @findex __builtin___vsprintf_chk | |
7392 | @findex __builtin___vsnprintf_chk | |
7393 | @findex __builtin___printf_chk | |
7394 | @findex __builtin___vprintf_chk | |
7395 | @findex __builtin___fprintf_chk | |
7396 | @findex __builtin___vfprintf_chk | |
7397 | ||
7398 | GCC implements a limited buffer overflow protection mechanism | |
7399 | that can prevent some buffer overflow attacks. | |
7400 | ||
7401 | @deftypefn {Built-in Function} {size_t} __builtin_object_size (void * @var{ptr}, int @var{type}) | |
7402 | is a built-in construct that returns a constant number of bytes from | |
7403 | @var{ptr} to the end of the object @var{ptr} pointer points to | |
7404 | (if known at compile time). @code{__builtin_object_size} never evaluates | |
7405 | its arguments for side-effects. If there are any side-effects in them, it | |
7406 | returns @code{(size_t) -1} for @var{type} 0 or 1 and @code{(size_t) 0} | |
7407 | for @var{type} 2 or 3. If there are multiple objects @var{ptr} can | |
7408 | point to and all of them are known at compile time, the returned number | |
7409 | is the maximum of remaining byte counts in those objects if @var{type} & 2 is | |
3ce7ff97 | 7410 | 0 and minimum if nonzero. If it is not possible to determine which objects |
0a39fd54 | 7411 | @var{ptr} points to at compile time, @code{__builtin_object_size} should |
7412 | return @code{(size_t) -1} for @var{type} 0 or 1 and @code{(size_t) 0} | |
7413 | for @var{type} 2 or 3. | |
7414 | ||
7415 | @var{type} is an integer constant from 0 to 3. If the least significant | |
7416 | bit is clear, objects are whole variables, if it is set, a closest | |
7417 | surrounding subobject is considered the object a pointer points to. | |
7418 | The second bit determines if maximum or minimum of remaining bytes | |
7419 | is computed. | |
7420 | ||
7421 | @smallexample | |
7422 | struct V @{ char buf1[10]; int b; char buf2[10]; @} var; | |
7423 | char *p = &var.buf1[1], *q = &var.b; | |
7424 | ||
7425 | /* Here the object p points to is var. */ | |
7426 | assert (__builtin_object_size (p, 0) == sizeof (var) - 1); | |
7427 | /* The subobject p points to is var.buf1. */ | |
7428 | assert (__builtin_object_size (p, 1) == sizeof (var.buf1) - 1); | |
7429 | /* The object q points to is var. */ | |
7430 | assert (__builtin_object_size (q, 0) | |
c24c5fac | 7431 | == (char *) (&var + 1) - (char *) &var.b); |
0a39fd54 | 7432 | /* The subobject q points to is var.b. */ |
7433 | assert (__builtin_object_size (q, 1) == sizeof (var.b)); | |
7434 | @end smallexample | |
7435 | @end deftypefn | |
7436 | ||
7437 | There are built-in functions added for many common string operation | |
83d10720 | 7438 | functions, e.g., for @code{memcpy} @code{__builtin___memcpy_chk} |
0a39fd54 | 7439 | built-in is provided. This built-in has an additional last argument, |
7440 | which is the number of bytes remaining in object the @var{dest} | |
7441 | argument points to or @code{(size_t) -1} if the size is not known. | |
7442 | ||
7443 | The built-in functions are optimized into the normal string functions | |
7444 | like @code{memcpy} if the last argument is @code{(size_t) -1} or if | |
7445 | it is known at compile time that the destination object will not | |
7446 | be overflown. If the compiler can determine at compile time the | |
7447 | object will be always overflown, it issues a warning. | |
7448 | ||
7449 | The intended use can be e.g. | |
7450 | ||
7451 | @smallexample | |
7452 | #undef memcpy | |
7453 | #define bos0(dest) __builtin_object_size (dest, 0) | |
7454 | #define memcpy(dest, src, n) \ | |
7455 | __builtin___memcpy_chk (dest, src, n, bos0 (dest)) | |
7456 | ||
7457 | char *volatile p; | |
7458 | char buf[10]; | |
7459 | /* It is unknown what object p points to, so this is optimized | |
7460 | into plain memcpy - no checking is possible. */ | |
7461 | memcpy (p, "abcde", n); | |
7462 | /* Destination is known and length too. It is known at compile | |
7463 | time there will be no overflow. */ | |
7464 | memcpy (&buf[5], "abcde", 5); | |
7465 | /* Destination is known, but the length is not known at compile time. | |
7466 | This will result in __memcpy_chk call that can check for overflow | |
7467 | at runtime. */ | |
7468 | memcpy (&buf[5], "abcde", n); | |
7469 | /* Destination is known and it is known at compile time there will | |
7470 | be overflow. There will be a warning and __memcpy_chk call that | |
7471 | will abort the program at runtime. */ | |
7472 | memcpy (&buf[6], "abcde", 5); | |
7473 | @end smallexample | |
7474 | ||
7475 | Such built-in functions are provided for @code{memcpy}, @code{mempcpy}, | |
7476 | @code{memmove}, @code{memset}, @code{strcpy}, @code{stpcpy}, @code{strncpy}, | |
7477 | @code{strcat} and @code{strncat}. | |
7478 | ||
7479 | There are also checking built-in functions for formatted output functions. | |
7480 | @smallexample | |
7481 | int __builtin___sprintf_chk (char *s, int flag, size_t os, const char *fmt, ...); | |
7482 | int __builtin___snprintf_chk (char *s, size_t maxlen, int flag, size_t os, | |
c24c5fac | 7483 | const char *fmt, ...); |
0a39fd54 | 7484 | int __builtin___vsprintf_chk (char *s, int flag, size_t os, const char *fmt, |
c24c5fac | 7485 | va_list ap); |
0a39fd54 | 7486 | int __builtin___vsnprintf_chk (char *s, size_t maxlen, int flag, size_t os, |
c24c5fac | 7487 | const char *fmt, va_list ap); |
0a39fd54 | 7488 | @end smallexample |
7489 | ||
7490 | The added @var{flag} argument is passed unchanged to @code{__sprintf_chk} | |
83d10720 | 7491 | etc.@: functions and can contain implementation specific flags on what |
0a39fd54 | 7492 | additional security measures the checking function might take, such as |
7493 | handling @code{%n} differently. | |
7494 | ||
7495 | The @var{os} argument is the object size @var{s} points to, like in the | |
3ce7ff97 | 7496 | other built-in functions. There is a small difference in the behavior |
0a39fd54 | 7497 | though, if @var{os} is @code{(size_t) -1}, the built-in functions are |
7498 | optimized into the non-checking functions only if @var{flag} is 0, otherwise | |
7499 | the checking function is called with @var{os} argument set to | |
7500 | @code{(size_t) -1}. | |
7501 | ||
7502 | In addition to this, there are checking built-in functions | |
7503 | @code{__builtin___printf_chk}, @code{__builtin___vprintf_chk}, | |
7504 | @code{__builtin___fprintf_chk} and @code{__builtin___vfprintf_chk}. | |
7505 | These have just one additional argument, @var{flag}, right before | |
7506 | format string @var{fmt}. If the compiler is able to optimize them to | |
83d10720 | 7507 | @code{fputc} etc.@: functions, it will, otherwise the checking function |
0a39fd54 | 7508 | should be called and the @var{flag} argument passed to it. |
7509 | ||
2c776a54 | 7510 | @node Other Builtins |
37744367 | 7511 | @section Other built-in functions provided by GCC |
8e5fcce7 | 7512 | @cindex built-in functions |
19fbe3a4 | 7513 | @findex __builtin_fpclassify |
cde061c1 | 7514 | @findex __builtin_isfinite |
8a1a9cb7 | 7515 | @findex __builtin_isnormal |
1f4e0dac | 7516 | @findex __builtin_isgreater |
7517 | @findex __builtin_isgreaterequal | |
c319d56a | 7518 | @findex __builtin_isinf_sign |
1f4e0dac | 7519 | @findex __builtin_isless |
7520 | @findex __builtin_islessequal | |
7521 | @findex __builtin_islessgreater | |
7522 | @findex __builtin_isunordered | |
757c219d | 7523 | @findex __builtin_powi |
7524 | @findex __builtin_powif | |
7525 | @findex __builtin_powil | |
e88e2794 | 7526 | @findex _Exit |
7527 | @findex _exit | |
1f4e0dac | 7528 | @findex abort |
7529 | @findex abs | |
e88e2794 | 7530 | @findex acos |
7531 | @findex acosf | |
7532 | @findex acosh | |
7533 | @findex acoshf | |
7534 | @findex acoshl | |
7535 | @findex acosl | |
1f4e0dac | 7536 | @findex alloca |
e88e2794 | 7537 | @findex asin |
7538 | @findex asinf | |
7539 | @findex asinh | |
7540 | @findex asinhf | |
7541 | @findex asinhl | |
7542 | @findex asinl | |
a2246f84 | 7543 | @findex atan |
fa426235 | 7544 | @findex atan2 |
7545 | @findex atan2f | |
7546 | @findex atan2l | |
a2246f84 | 7547 | @findex atanf |
e88e2794 | 7548 | @findex atanh |
7549 | @findex atanhf | |
7550 | @findex atanhl | |
a2246f84 | 7551 | @findex atanl |
1f4e0dac | 7552 | @findex bcmp |
7553 | @findex bzero | |
78a74442 | 7554 | @findex cabs |
7555 | @findex cabsf | |
7556 | @findex cabsl | |
61b922e7 | 7557 | @findex cacos |
7558 | @findex cacosf | |
7559 | @findex cacosh | |
7560 | @findex cacoshf | |
7561 | @findex cacoshl | |
7562 | @findex cacosl | |
32ef1cd2 | 7563 | @findex calloc |
61b922e7 | 7564 | @findex carg |
7565 | @findex cargf | |
7566 | @findex cargl | |
7567 | @findex casin | |
7568 | @findex casinf | |
7569 | @findex casinh | |
7570 | @findex casinhf | |
7571 | @findex casinhl | |
7572 | @findex casinl | |
7573 | @findex catan | |
7574 | @findex catanf | |
7575 | @findex catanh | |
7576 | @findex catanhf | |
7577 | @findex catanhl | |
7578 | @findex catanl | |
e88e2794 | 7579 | @findex cbrt |
7580 | @findex cbrtf | |
7581 | @findex cbrtl | |
61b922e7 | 7582 | @findex ccos |
7583 | @findex ccosf | |
7584 | @findex ccosh | |
7585 | @findex ccoshf | |
7586 | @findex ccoshl | |
7587 | @findex ccosl | |
982c684c | 7588 | @findex ceil |
7589 | @findex ceilf | |
7590 | @findex ceill | |
61b922e7 | 7591 | @findex cexp |
7592 | @findex cexpf | |
7593 | @findex cexpl | |
d30e4d04 | 7594 | @findex cimag |
7595 | @findex cimagf | |
7596 | @findex cimagl | |
18c2e7b1 | 7597 | @findex clog |
7598 | @findex clogf | |
7599 | @findex clogl | |
d30e4d04 | 7600 | @findex conj |
7601 | @findex conjf | |
7602 | @findex conjl | |
e88e2794 | 7603 | @findex copysign |
7604 | @findex copysignf | |
7605 | @findex copysignl | |
1f4e0dac | 7606 | @findex cos |
7607 | @findex cosf | |
e88e2794 | 7608 | @findex cosh |
7609 | @findex coshf | |
7610 | @findex coshl | |
1f4e0dac | 7611 | @findex cosl |
61b922e7 | 7612 | @findex cpow |
7613 | @findex cpowf | |
7614 | @findex cpowl | |
7615 | @findex cproj | |
7616 | @findex cprojf | |
7617 | @findex cprojl | |
d30e4d04 | 7618 | @findex creal |
7619 | @findex crealf | |
7620 | @findex creall | |
61b922e7 | 7621 | @findex csin |
7622 | @findex csinf | |
7623 | @findex csinh | |
7624 | @findex csinhf | |
7625 | @findex csinhl | |
7626 | @findex csinl | |
7627 | @findex csqrt | |
7628 | @findex csqrtf | |
7629 | @findex csqrtl | |
7630 | @findex ctan | |
7631 | @findex ctanf | |
7632 | @findex ctanh | |
7633 | @findex ctanhf | |
7634 | @findex ctanhl | |
7635 | @findex ctanl | |
b9b15671 | 7636 | @findex dcgettext |
7637 | @findex dgettext | |
e88e2794 | 7638 | @findex drem |
7639 | @findex dremf | |
7640 | @findex dreml | |
847749e5 | 7641 | @findex erf |
7642 | @findex erfc | |
7643 | @findex erfcf | |
7644 | @findex erfcl | |
7645 | @findex erff | |
7646 | @findex erfl | |
1f4e0dac | 7647 | @findex exit |
42721db0 | 7648 | @findex exp |
e88e2794 | 7649 | @findex exp10 |
7650 | @findex exp10f | |
7651 | @findex exp10l | |
7652 | @findex exp2 | |
7653 | @findex exp2f | |
7654 | @findex exp2l | |
42721db0 | 7655 | @findex expf |
7656 | @findex expl | |
e88e2794 | 7657 | @findex expm1 |
7658 | @findex expm1f | |
7659 | @findex expm1l | |
1f4e0dac | 7660 | @findex fabs |
7661 | @findex fabsf | |
7662 | @findex fabsl | |
e88e2794 | 7663 | @findex fdim |
7664 | @findex fdimf | |
7665 | @findex fdiml | |
1f4e0dac | 7666 | @findex ffs |
982c684c | 7667 | @findex floor |
7668 | @findex floorf | |
7669 | @findex floorl | |
e88e2794 | 7670 | @findex fma |
7671 | @findex fmaf | |
7672 | @findex fmal | |
7673 | @findex fmax | |
7674 | @findex fmaxf | |
7675 | @findex fmaxl | |
7676 | @findex fmin | |
7677 | @findex fminf | |
7678 | @findex fminl | |
982c684c | 7679 | @findex fmod |
7680 | @findex fmodf | |
7681 | @findex fmodl | |
96df8b77 | 7682 | @findex fprintf |
c013a46e | 7683 | @findex fprintf_unlocked |
1f4e0dac | 7684 | @findex fputs |
c013a46e | 7685 | @findex fputs_unlocked |
4070bd43 | 7686 | @findex frexp |
7687 | @findex frexpf | |
7688 | @findex frexpl | |
b9b15671 | 7689 | @findex fscanf |
847749e5 | 7690 | @findex gamma |
7691 | @findex gammaf | |
7692 | @findex gammal | |
cd2656b0 | 7693 | @findex gamma_r |
7694 | @findex gammaf_r | |
7695 | @findex gammal_r | |
b9b15671 | 7696 | @findex gettext |
e88e2794 | 7697 | @findex hypot |
7698 | @findex hypotf | |
7699 | @findex hypotl | |
7700 | @findex ilogb | |
7701 | @findex ilogbf | |
7702 | @findex ilogbl | |
1dfa965e | 7703 | @findex imaxabs |
398aae36 | 7704 | @findex index |
054f84e6 | 7705 | @findex isalnum |
7706 | @findex isalpha | |
7707 | @findex isascii | |
7708 | @findex isblank | |
7709 | @findex iscntrl | |
7710 | @findex isdigit | |
7711 | @findex isgraph | |
7712 | @findex islower | |
7713 | @findex isprint | |
7714 | @findex ispunct | |
7715 | @findex isspace | |
7716 | @findex isupper | |
4617d9b5 | 7717 | @findex iswalnum |
7718 | @findex iswalpha | |
7719 | @findex iswblank | |
7720 | @findex iswcntrl | |
7721 | @findex iswdigit | |
7722 | @findex iswgraph | |
7723 | @findex iswlower | |
7724 | @findex iswprint | |
7725 | @findex iswpunct | |
7726 | @findex iswspace | |
7727 | @findex iswupper | |
7728 | @findex iswxdigit | |
054f84e6 | 7729 | @findex isxdigit |
847749e5 | 7730 | @findex j0 |
7731 | @findex j0f | |
7732 | @findex j0l | |
7733 | @findex j1 | |
7734 | @findex j1f | |
7735 | @findex j1l | |
7736 | @findex jn | |
7737 | @findex jnf | |
7738 | @findex jnl | |
1f4e0dac | 7739 | @findex labs |
e88e2794 | 7740 | @findex ldexp |
7741 | @findex ldexpf | |
7742 | @findex ldexpl | |
847749e5 | 7743 | @findex lgamma |
7744 | @findex lgammaf | |
7745 | @findex lgammal | |
cd2656b0 | 7746 | @findex lgamma_r |
7747 | @findex lgammaf_r | |
7748 | @findex lgammal_r | |
1f4e0dac | 7749 | @findex llabs |
e88e2794 | 7750 | @findex llrint |
7751 | @findex llrintf | |
7752 | @findex llrintl | |
7753 | @findex llround | |
7754 | @findex llroundf | |
7755 | @findex llroundl | |
42721db0 | 7756 | @findex log |
e88e2794 | 7757 | @findex log10 |
7758 | @findex log10f | |
7759 | @findex log10l | |
7760 | @findex log1p | |
7761 | @findex log1pf | |
7762 | @findex log1pl | |
7763 | @findex log2 | |
7764 | @findex log2f | |
7765 | @findex log2l | |
7766 | @findex logb | |
7767 | @findex logbf | |
7768 | @findex logbl | |
42721db0 | 7769 | @findex logf |
7770 | @findex logl | |
e88e2794 | 7771 | @findex lrint |
7772 | @findex lrintf | |
7773 | @findex lrintl | |
7774 | @findex lround | |
7775 | @findex lroundf | |
7776 | @findex lroundl | |
32ef1cd2 | 7777 | @findex malloc |
7959b13b | 7778 | @findex memchr |
1f4e0dac | 7779 | @findex memcmp |
7780 | @findex memcpy | |
3b824fa6 | 7781 | @findex mempcpy |
1f4e0dac | 7782 | @findex memset |
4070bd43 | 7783 | @findex modf |
7784 | @findex modff | |
7785 | @findex modfl | |
982c684c | 7786 | @findex nearbyint |
7787 | @findex nearbyintf | |
7788 | @findex nearbyintl | |
e88e2794 | 7789 | @findex nextafter |
7790 | @findex nextafterf | |
7791 | @findex nextafterl | |
7792 | @findex nexttoward | |
7793 | @findex nexttowardf | |
7794 | @findex nexttowardl | |
fa426235 | 7795 | @findex pow |
e88e2794 | 7796 | @findex pow10 |
7797 | @findex pow10f | |
7798 | @findex pow10l | |
fa426235 | 7799 | @findex powf |
7800 | @findex powl | |
1f4e0dac | 7801 | @findex printf |
c013a46e | 7802 | @findex printf_unlocked |
03901330 | 7803 | @findex putchar |
7804 | @findex puts | |
e88e2794 | 7805 | @findex remainder |
7806 | @findex remainderf | |
7807 | @findex remainderl | |
4070bd43 | 7808 | @findex remquo |
7809 | @findex remquof | |
7810 | @findex remquol | |
398aae36 | 7811 | @findex rindex |
e88e2794 | 7812 | @findex rint |
7813 | @findex rintf | |
7814 | @findex rintl | |
982c684c | 7815 | @findex round |
7816 | @findex roundf | |
7817 | @findex roundl | |
e88e2794 | 7818 | @findex scalb |
7819 | @findex scalbf | |
7820 | @findex scalbl | |
7821 | @findex scalbln | |
7822 | @findex scalblnf | |
7823 | @findex scalblnf | |
7824 | @findex scalbn | |
7825 | @findex scalbnf | |
7826 | @findex scanfnl | |
27f261ef | 7827 | @findex signbit |
7828 | @findex signbitf | |
7829 | @findex signbitl | |
004e23c4 | 7830 | @findex signbitd32 |
7831 | @findex signbitd64 | |
7832 | @findex signbitd128 | |
847749e5 | 7833 | @findex significand |
7834 | @findex significandf | |
7835 | @findex significandl | |
1f4e0dac | 7836 | @findex sin |
4070bd43 | 7837 | @findex sincos |
7838 | @findex sincosf | |
7839 | @findex sincosl | |
1f4e0dac | 7840 | @findex sinf |
e88e2794 | 7841 | @findex sinh |
7842 | @findex sinhf | |
7843 | @findex sinhl | |
1f4e0dac | 7844 | @findex sinl |
03901330 | 7845 | @findex snprintf |
7846 | @findex sprintf | |
1f4e0dac | 7847 | @findex sqrt |
7848 | @findex sqrtf | |
7849 | @findex sqrtl | |
03901330 | 7850 | @findex sscanf |
3b824fa6 | 7851 | @findex stpcpy |
989d048f | 7852 | @findex stpncpy |
7853 | @findex strcasecmp | |
49f0327b | 7854 | @findex strcat |
1f4e0dac | 7855 | @findex strchr |
7856 | @findex strcmp | |
7857 | @findex strcpy | |
49f0327b | 7858 | @findex strcspn |
32ef1cd2 | 7859 | @findex strdup |
b9b15671 | 7860 | @findex strfmon |
7861 | @findex strftime | |
1f4e0dac | 7862 | @findex strlen |
989d048f | 7863 | @findex strncasecmp |
49f0327b | 7864 | @findex strncat |
ed09096d | 7865 | @findex strncmp |
7866 | @findex strncpy | |
989d048f | 7867 | @findex strndup |
1f4e0dac | 7868 | @findex strpbrk |
7869 | @findex strrchr | |
49f0327b | 7870 | @findex strspn |
1f4e0dac | 7871 | @findex strstr |
a2246f84 | 7872 | @findex tan |
7873 | @findex tanf | |
e88e2794 | 7874 | @findex tanh |
7875 | @findex tanhf | |
7876 | @findex tanhl | |
a2246f84 | 7877 | @findex tanl |
847749e5 | 7878 | @findex tgamma |
7879 | @findex tgammaf | |
7880 | @findex tgammal | |
054f84e6 | 7881 | @findex toascii |
7882 | @findex tolower | |
7883 | @findex toupper | |
4617d9b5 | 7884 | @findex towlower |
7885 | @findex towupper | |
805e22b2 | 7886 | @findex trunc |
7887 | @findex truncf | |
7888 | @findex truncl | |
b9b15671 | 7889 | @findex vfprintf |
7890 | @findex vfscanf | |
03901330 | 7891 | @findex vprintf |
7892 | @findex vscanf | |
7893 | @findex vsnprintf | |
7894 | @findex vsprintf | |
7895 | @findex vsscanf | |
847749e5 | 7896 | @findex y0 |
7897 | @findex y0f | |
7898 | @findex y0l | |
7899 | @findex y1 | |
7900 | @findex y1f | |
7901 | @findex y1l | |
7902 | @findex yn | |
7903 | @findex ynf | |
7904 | @findex ynl | |
2c776a54 | 7905 | |
37744367 | 7906 | GCC provides a large number of built-in functions other than the ones |
2c776a54 | 7907 | mentioned above. Some of these are for internal use in the processing |
7908 | of exceptions or variable-length argument lists and will not be | |
7909 | documented here because they may change from time to time; we do not | |
7910 | recommend general use of these functions. | |
7911 | ||
7912 | The remaining functions are provided for optimization purposes. | |
7913 | ||
67791935 | 7914 | @opindex fno-builtin |
0fff59be | 7915 | GCC includes built-in versions of many of the functions in the standard |
7916 | C library. The versions prefixed with @code{__builtin_} will always be | |
7917 | treated as having the same meaning as the C library function even if you | |
b3d47662 | 7918 | specify the @option{-fno-builtin} option. (@pxref{C Dialect Options}) |
0fff59be | 7919 | Many of these functions are only optimized in certain cases; if they are |
1f4e0dac | 7920 | not optimized in a particular case, a call to the library function will |
7921 | be emitted. | |
7922 | ||
67791935 | 7923 | @opindex ansi |
7924 | @opindex std | |
39012afb | 7925 | Outside strict ISO C mode (@option{-ansi}, @option{-std=c90}, |
32074525 | 7926 | @option{-std=c99} or @option{-std=c11}), the functions |
e88e2794 | 7927 | @code{_exit}, @code{alloca}, @code{bcmp}, @code{bzero}, |
7928 | @code{dcgettext}, @code{dgettext}, @code{dremf}, @code{dreml}, | |
7929 | @code{drem}, @code{exp10f}, @code{exp10l}, @code{exp10}, @code{ffsll}, | |
cd2656b0 | 7930 | @code{ffsl}, @code{ffs}, @code{fprintf_unlocked}, |
7931 | @code{fputs_unlocked}, @code{gammaf}, @code{gammal}, @code{gamma}, | |
7932 | @code{gammaf_r}, @code{gammal_r}, @code{gamma_r}, @code{gettext}, | |
054f84e6 | 7933 | @code{index}, @code{isascii}, @code{j0f}, @code{j0l}, @code{j0}, |
7934 | @code{j1f}, @code{j1l}, @code{j1}, @code{jnf}, @code{jnl}, @code{jn}, | |
cd2656b0 | 7935 | @code{lgammaf_r}, @code{lgammal_r}, @code{lgamma_r}, @code{mempcpy}, |
7936 | @code{pow10f}, @code{pow10l}, @code{pow10}, @code{printf_unlocked}, | |
7937 | @code{rindex}, @code{scalbf}, @code{scalbl}, @code{scalb}, | |
7938 | @code{signbit}, @code{signbitf}, @code{signbitl}, @code{signbitd32}, | |
7939 | @code{signbitd64}, @code{signbitd128}, @code{significandf}, | |
7940 | @code{significandl}, @code{significand}, @code{sincosf}, | |
7941 | @code{sincosl}, @code{sincos}, @code{stpcpy}, @code{stpncpy}, | |
7942 | @code{strcasecmp}, @code{strdup}, @code{strfmon}, @code{strncasecmp}, | |
7943 | @code{strndup}, @code{toascii}, @code{y0f}, @code{y0l}, @code{y0}, | |
7944 | @code{y1f}, @code{y1l}, @code{y1}, @code{ynf}, @code{ynl} and | |
7945 | @code{yn} | |
32ef1cd2 | 7946 | may be handled as built-in functions. |
982c684c | 7947 | All these functions have corresponding versions |
32f1f35b | 7948 | prefixed with @code{__builtin_}, which may be used even in strict C90 |
0fff59be | 7949 | mode. |
1f4e0dac | 7950 | |
78a74442 | 7951 | The ISO C99 functions |
e88e2794 | 7952 | @code{_Exit}, @code{acoshf}, @code{acoshl}, @code{acosh}, @code{asinhf}, |
7953 | @code{asinhl}, @code{asinh}, @code{atanhf}, @code{atanhl}, @code{atanh}, | |
61b922e7 | 7954 | @code{cabsf}, @code{cabsl}, @code{cabs}, @code{cacosf}, @code{cacoshf}, |
7955 | @code{cacoshl}, @code{cacosh}, @code{cacosl}, @code{cacos}, | |
7956 | @code{cargf}, @code{cargl}, @code{carg}, @code{casinf}, @code{casinhf}, | |
7957 | @code{casinhl}, @code{casinh}, @code{casinl}, @code{casin}, | |
7958 | @code{catanf}, @code{catanhf}, @code{catanhl}, @code{catanh}, | |
7959 | @code{catanl}, @code{catan}, @code{cbrtf}, @code{cbrtl}, @code{cbrt}, | |
7960 | @code{ccosf}, @code{ccoshf}, @code{ccoshl}, @code{ccosh}, @code{ccosl}, | |
7961 | @code{ccos}, @code{cexpf}, @code{cexpl}, @code{cexp}, @code{cimagf}, | |
18c2e7b1 | 7962 | @code{cimagl}, @code{cimag}, @code{clogf}, @code{clogl}, @code{clog}, |
7963 | @code{conjf}, @code{conjl}, @code{conj}, @code{copysignf}, @code{copysignl}, | |
7964 | @code{copysign}, @code{cpowf}, @code{cpowl}, @code{cpow}, @code{cprojf}, | |
7965 | @code{cprojl}, @code{cproj}, @code{crealf}, @code{creall}, @code{creal}, | |
7966 | @code{csinf}, @code{csinhf}, @code{csinhl}, @code{csinh}, @code{csinl}, | |
7967 | @code{csin}, @code{csqrtf}, @code{csqrtl}, @code{csqrt}, @code{ctanf}, | |
7968 | @code{ctanhf}, @code{ctanhl}, @code{ctanh}, @code{ctanl}, @code{ctan}, | |
7969 | @code{erfcf}, @code{erfcl}, @code{erfc}, @code{erff}, @code{erfl}, | |
7970 | @code{erf}, @code{exp2f}, @code{exp2l}, @code{exp2}, @code{expm1f}, | |
7971 | @code{expm1l}, @code{expm1}, @code{fdimf}, @code{fdiml}, @code{fdim}, | |
7972 | @code{fmaf}, @code{fmal}, @code{fmaxf}, @code{fmaxl}, @code{fmax}, | |
7973 | @code{fma}, @code{fminf}, @code{fminl}, @code{fmin}, @code{hypotf}, | |
7974 | @code{hypotl}, @code{hypot}, @code{ilogbf}, @code{ilogbl}, @code{ilogb}, | |
7975 | @code{imaxabs}, @code{isblank}, @code{iswblank}, @code{lgammaf}, | |
7976 | @code{lgammal}, @code{lgamma}, @code{llabs}, @code{llrintf}, @code{llrintl}, | |
4617d9b5 | 7977 | @code{llrint}, @code{llroundf}, @code{llroundl}, @code{llround}, |
7978 | @code{log1pf}, @code{log1pl}, @code{log1p}, @code{log2f}, @code{log2l}, | |
7979 | @code{log2}, @code{logbf}, @code{logbl}, @code{logb}, @code{lrintf}, | |
7980 | @code{lrintl}, @code{lrint}, @code{lroundf}, @code{lroundl}, | |
7981 | @code{lround}, @code{nearbyintf}, @code{nearbyintl}, @code{nearbyint}, | |
054f84e6 | 7982 | @code{nextafterf}, @code{nextafterl}, @code{nextafter}, |
7983 | @code{nexttowardf}, @code{nexttowardl}, @code{nexttoward}, | |
7984 | @code{remainderf}, @code{remainderl}, @code{remainder}, @code{remquof}, | |
7985 | @code{remquol}, @code{remquo}, @code{rintf}, @code{rintl}, @code{rint}, | |
7986 | @code{roundf}, @code{roundl}, @code{round}, @code{scalblnf}, | |
7987 | @code{scalblnl}, @code{scalbln}, @code{scalbnf}, @code{scalbnl}, | |
7988 | @code{scalbn}, @code{snprintf}, @code{tgammaf}, @code{tgammal}, | |
7989 | @code{tgamma}, @code{truncf}, @code{truncl}, @code{trunc}, | |
7990 | @code{vfscanf}, @code{vscanf}, @code{vsnprintf} and @code{vsscanf} | |
03901330 | 7991 | are handled as built-in functions |
32f1f35b | 7992 | except in strict ISO C90 mode (@option{-ansi} or @option{-std=c90}). |
fa426235 | 7993 | |
e88e2794 | 7994 | There are also built-in versions of the ISO C99 functions |
7995 | @code{acosf}, @code{acosl}, @code{asinf}, @code{asinl}, @code{atan2f}, | |
a2246f84 | 7996 | @code{atan2l}, @code{atanf}, @code{atanl}, @code{ceilf}, @code{ceill}, |
e88e2794 | 7997 | @code{cosf}, @code{coshf}, @code{coshl}, @code{cosl}, @code{expf}, |
7998 | @code{expl}, @code{fabsf}, @code{fabsl}, @code{floorf}, @code{floorl}, | |
4070bd43 | 7999 | @code{fmodf}, @code{fmodl}, @code{frexpf}, @code{frexpl}, @code{ldexpf}, |
8000 | @code{ldexpl}, @code{log10f}, @code{log10l}, @code{logf}, @code{logl}, | |
8001 | @code{modfl}, @code{modf}, @code{powf}, @code{powl}, @code{sinf}, | |
8002 | @code{sinhf}, @code{sinhl}, @code{sinl}, @code{sqrtf}, @code{sqrtl}, | |
8003 | @code{tanf}, @code{tanhf}, @code{tanhl} and @code{tanl} | |
fa426235 | 8004 | that are recognized in any mode since ISO C90 reserves these names for |
8005 | the purpose to which ISO C99 puts them. All these functions have | |
8006 | corresponding versions prefixed with @code{__builtin_}. | |
8007 | ||
4617d9b5 | 8008 | The ISO C94 functions |
8009 | @code{iswalnum}, @code{iswalpha}, @code{iswcntrl}, @code{iswdigit}, | |
8010 | @code{iswgraph}, @code{iswlower}, @code{iswprint}, @code{iswpunct}, | |
8011 | @code{iswspace}, @code{iswupper}, @code{iswxdigit}, @code{towlower} and | |
8012 | @code{towupper} | |
8013 | are handled as built-in functions | |
32f1f35b | 8014 | except in strict ISO C90 mode (@option{-ansi} or @option{-std=c90}). |
4617d9b5 | 8015 | |
e88e2794 | 8016 | The ISO C90 functions |
8017 | @code{abort}, @code{abs}, @code{acos}, @code{asin}, @code{atan2}, | |
8018 | @code{atan}, @code{calloc}, @code{ceil}, @code{cosh}, @code{cos}, | |
8019 | @code{exit}, @code{exp}, @code{fabs}, @code{floor}, @code{fmod}, | |
054f84e6 | 8020 | @code{fprintf}, @code{fputs}, @code{frexp}, @code{fscanf}, |
8021 | @code{isalnum}, @code{isalpha}, @code{iscntrl}, @code{isdigit}, | |
8022 | @code{isgraph}, @code{islower}, @code{isprint}, @code{ispunct}, | |
8023 | @code{isspace}, @code{isupper}, @code{isxdigit}, @code{tolower}, | |
8024 | @code{toupper}, @code{labs}, @code{ldexp}, @code{log10}, @code{log}, | |
7959b13b | 8025 | @code{malloc}, @code{memchr}, @code{memcmp}, @code{memcpy}, |
8026 | @code{memset}, @code{modf}, @code{pow}, @code{printf}, @code{putchar}, | |
8027 | @code{puts}, @code{scanf}, @code{sinh}, @code{sin}, @code{snprintf}, | |
8028 | @code{sprintf}, @code{sqrt}, @code{sscanf}, @code{strcat}, | |
8029 | @code{strchr}, @code{strcmp}, @code{strcpy}, @code{strcspn}, | |
8030 | @code{strlen}, @code{strncat}, @code{strncmp}, @code{strncpy}, | |
8031 | @code{strpbrk}, @code{strrchr}, @code{strspn}, @code{strstr}, | |
8032 | @code{tanh}, @code{tan}, @code{vfprintf}, @code{vprintf} and @code{vsprintf} | |
03901330 | 8033 | are all recognized as built-in functions unless |
fa426235 | 8034 | @option{-fno-builtin} is specified (or @option{-fno-builtin-@var{function}} |
8035 | is specified for an individual function). All of these functions have | |
805e22b2 | 8036 | corresponding versions prefixed with @code{__builtin_}. |
0fff59be | 8037 | |
8038 | GCC provides built-in versions of the ISO C99 floating point comparison | |
8039 | macros that avoid raising exceptions for unordered operands. They have | |
8040 | the same names as the standard macros ( @code{isgreater}, | |
8041 | @code{isgreaterequal}, @code{isless}, @code{islessequal}, | |
8042 | @code{islessgreater}, and @code{isunordered}) , with @code{__builtin_} | |
8043 | prefixed. We intend for a library implementor to be able to simply | |
8044 | @code{#define} each standard macro to its built-in equivalent. | |
19fbe3a4 | 8045 | In the same fashion, GCC provides @code{fpclassify}, @code{isfinite}, |
8046 | @code{isinf_sign} and @code{isnormal} built-ins used with | |
8047 | @code{__builtin_} prefixed. The @code{isinf} and @code{isnan} | |
8048 | builtins appear both with and without the @code{__builtin_} prefix. | |
2c776a54 | 8049 | |
acb6974b | 8050 | @deftypefn {Built-in Function} int __builtin_types_compatible_p (@var{type1}, @var{type2}) |
8051 | ||
8052 | You can use the built-in function @code{__builtin_types_compatible_p} to | |
8053 | determine whether two types are the same. | |
8054 | ||
8055 | This built-in function returns 1 if the unqualified versions of the | |
8056 | types @var{type1} and @var{type2} (which are types, not expressions) are | |
8057 | compatible, 0 otherwise. The result of this built-in function can be | |
8058 | used in integer constant expressions. | |
8059 | ||
8060 | This built-in function ignores top level qualifiers (e.g., @code{const}, | |
8061 | @code{volatile}). For example, @code{int} is equivalent to @code{const | |
8062 | int}. | |
8063 | ||
8064 | The type @code{int[]} and @code{int[5]} are compatible. On the other | |
8065 | hand, @code{int} and @code{char *} are not compatible, even if the size | |
8066 | of their types, on the particular architecture are the same. Also, the | |
8067 | amount of pointer indirection is taken into account when determining | |
8068 | similarity. Consequently, @code{short *} is not similar to | |
8069 | @code{short **}. Furthermore, two types that are typedefed are | |
8070 | considered compatible if their underlying types are compatible. | |
8071 | ||
09e0a2a1 | 8072 | An @code{enum} type is not considered to be compatible with another |
8073 | @code{enum} type even if both are compatible with the same integer | |
8074 | type; this is what the C standard specifies. | |
8075 | For example, @code{enum @{foo, bar@}} is not similar to | |
acb6974b | 8076 | @code{enum @{hot, dog@}}. |
8077 | ||
8078 | You would typically use this function in code whose execution varies | |
8079 | depending on the arguments' types. For example: | |
8080 | ||
8081 | @smallexample | |
8e1103d3 | 8082 | #define foo(x) \ |
8083 | (@{ \ | |
57bcf24d | 8084 | typeof (x) tmp = (x); \ |
8e1103d3 | 8085 | if (__builtin_types_compatible_p (typeof (x), long double)) \ |
8086 | tmp = foo_long_double (tmp); \ | |
8087 | else if (__builtin_types_compatible_p (typeof (x), double)) \ | |
8088 | tmp = foo_double (tmp); \ | |
8089 | else if (__builtin_types_compatible_p (typeof (x), float)) \ | |
8090 | tmp = foo_float (tmp); \ | |
8091 | else \ | |
8092 | abort (); \ | |
8093 | tmp; \ | |
acb6974b | 8094 | @}) |
8095 | @end smallexample | |
8096 | ||
b3d47662 | 8097 | @emph{Note:} This construct is only available for C@. |
acb6974b | 8098 | |
8099 | @end deftypefn | |
8100 | ||
8101 | @deftypefn {Built-in Function} @var{type} __builtin_choose_expr (@var{const_exp}, @var{exp1}, @var{exp2}) | |
8102 | ||
8103 | You can use the built-in function @code{__builtin_choose_expr} to | |
8104 | evaluate code depending on the value of a constant expression. This | |
a75b1c71 | 8105 | built-in function returns @var{exp1} if @var{const_exp}, which is an |
bcd71332 | 8106 | integer constant expression, is nonzero. Otherwise it returns @var{exp2}. |
acb6974b | 8107 | |
8108 | This built-in function is analogous to the @samp{? :} operator in C, | |
8109 | except that the expression returned has its type unaltered by promotion | |
8110 | rules. Also, the built-in function does not evaluate the expression | |
8111 | that was not chosen. For example, if @var{const_exp} evaluates to true, | |
8112 | @var{exp2} is not evaluated even if it has side-effects. | |
8113 | ||
8114 | This built-in function can return an lvalue if the chosen argument is an | |
8115 | lvalue. | |
8116 | ||
8117 | If @var{exp1} is returned, the return type is the same as @var{exp1}'s | |
8118 | type. Similarly, if @var{exp2} is returned, its return type is the same | |
8119 | as @var{exp2}. | |
8120 | ||
8121 | Example: | |
8122 | ||
8123 | @smallexample | |
b724fad7 | 8124 | #define foo(x) \ |
8125 | __builtin_choose_expr ( \ | |
8126 | __builtin_types_compatible_p (typeof (x), double), \ | |
8127 | foo_double (x), \ | |
8128 | __builtin_choose_expr ( \ | |
8129 | __builtin_types_compatible_p (typeof (x), float), \ | |
8130 | foo_float (x), \ | |
8131 | /* @r{The void expression results in a compile-time error} \ | |
8132 | @r{when assigning the result to something.} */ \ | |
acb6974b | 8133 | (void)0)) |
8134 | @end smallexample | |
8135 | ||
b3d47662 | 8136 | @emph{Note:} This construct is only available for C@. Furthermore, the |
acb6974b | 8137 | unused expression (@var{exp1} or @var{exp2} depending on the value of |
8138 | @var{const_exp}) may still generate syntax errors. This may change in | |
8139 | future revisions. | |
8140 | ||
8141 | @end deftypefn | |
8142 | ||
bff4ad11 | 8143 | @deftypefn {Built-in Function} @var{type} __builtin_complex (@var{real}, @var{imag}) |
8144 | ||
8145 | The built-in function @code{__builtin_complex} is provided for use in | |
32074525 | 8146 | implementing the ISO C11 macros @code{CMPLXF}, @code{CMPLX} and |
bff4ad11 | 8147 | @code{CMPLXL}. @var{real} and @var{imag} must have the same type, a |
8148 | real binary floating-point type, and the result has the corresponding | |
8149 | complex type with real and imaginary parts @var{real} and @var{imag}. | |
8150 | Unlike @samp{@var{real} + I * @var{imag}}, this works even when | |
8151 | infinities, NaNs and negative zeros are involved. | |
8152 | ||
8153 | @end deftypefn | |
8154 | ||
67791935 | 8155 | @deftypefn {Built-in Function} int __builtin_constant_p (@var{exp}) |
8156 | You can use the built-in function @code{__builtin_constant_p} to | |
2c776a54 | 8157 | determine if a value is known to be constant at compile-time and hence |
37744367 | 8158 | that GCC can perform constant-folding on expressions involving that |
2c776a54 | 8159 | value. The argument of the function is the value to test. The function |
8160 | returns the integer 1 if the argument is known to be a compile-time | |
8161 | constant and 0 if it is not known to be a compile-time constant. A | |
8162 | return of 0 does not indicate that the value is @emph{not} a constant, | |
37744367 | 8163 | but merely that GCC cannot prove it is a constant with the specified |
67791935 | 8164 | value of the @option{-O} option. |
2c776a54 | 8165 | |
8166 | You would typically use this function in an embedded application where | |
8167 | memory was a critical resource. If you have some complex calculation, | |
8168 | you may want it to be folded if it involves constants, but need to call | |
8169 | a function if it does not. For example: | |
8170 | ||
6e894357 | 8171 | @smallexample |
d90db7dc | 8172 | #define Scale_Value(X) \ |
8173 | (__builtin_constant_p (X) \ | |
8174 | ? ((X) * SCALE + OFFSET) : Scale (X)) | |
2c776a54 | 8175 | @end smallexample |
8176 | ||
67791935 | 8177 | You may use this built-in function in either a macro or an inline |
2c776a54 | 8178 | function. However, if you use it in an inlined function and pass an |
37744367 | 8179 | argument of the function as the argument to the built-in, GCC will |
2c776a54 | 8180 | never return 1 when you call the inline function with a string constant |
3cfa0cc4 | 8181 | or compound literal (@pxref{Compound Literals}) and will not return 1 |
2c776a54 | 8182 | when you pass a constant numeric value to the inline function unless you |
67791935 | 8183 | specify the @option{-O} option. |
f97c71a1 | 8184 | |
8185 | You may also use @code{__builtin_constant_p} in initializers for static | |
8186 | data. For instance, you can write | |
8187 | ||
8188 | @smallexample | |
c371393a | 8189 | static const int table[] = @{ |
f97c71a1 | 8190 | __builtin_constant_p (EXPRESSION) ? (EXPRESSION) : -1, |
4ae74ddd | 8191 | /* @r{@dots{}} */ |
c371393a | 8192 | @}; |
f97c71a1 | 8193 | @end smallexample |
8194 | ||
8195 | @noindent | |
8196 | This is an acceptable initializer even if @var{EXPRESSION} is not a | |
a75b1c71 | 8197 | constant expression, including the case where |
8198 | @code{__builtin_constant_p} returns 1 because @var{EXPRESSION} can be | |
8199 | folded to a constant but @var{EXPRESSION} contains operands that would | |
d270ac20 | 8200 | not otherwise be permitted in a static initializer (for example, |
a75b1c71 | 8201 | @code{0 && foo ()}). GCC must be more conservative about evaluating the |
f97c71a1 | 8202 | built-in in this case, because it has no opportunity to perform |
8203 | optimization. | |
8204 | ||
8205 | Previous versions of GCC did not accept this built-in in data | |
8206 | initializers. The earliest version where it is completely safe is | |
8207 | 3.0.1. | |
67791935 | 8208 | @end deftypefn |
2c776a54 | 8209 | |
67791935 | 8210 | @deftypefn {Built-in Function} long __builtin_expect (long @var{exp}, long @var{c}) |
8211 | @opindex fprofile-arcs | |
3b0848a2 | 8212 | You may use @code{__builtin_expect} to provide the compiler with |
89cfe6e5 | 8213 | branch prediction information. In general, you should prefer to |
67791935 | 8214 | use actual profile feedback for this (@option{-fprofile-arcs}), as |
89cfe6e5 | 8215 | programmers are notoriously bad at predicting how their programs |
def8652b | 8216 | actually perform. However, there are applications in which this |
89cfe6e5 | 8217 | data is hard to collect. |
8218 | ||
5a74f77e | 8219 | The return value is the value of @var{exp}, which should be an integral |
8220 | expression. The semantics of the built-in are that it is expected that | |
8221 | @var{exp} == @var{c}. For example: | |
89cfe6e5 | 8222 | |
8223 | @smallexample | |
8224 | if (__builtin_expect (x, 0)) | |
8225 | foo (); | |
8226 | @end smallexample | |
8227 | ||
8228 | @noindent | |
8229 | would indicate that we do not expect to call @code{foo}, since | |
8230 | we expect @code{x} to be zero. Since you are limited to integral | |
8231 | expressions for @var{exp}, you should use constructions such as | |
8232 | ||
8233 | @smallexample | |
8234 | if (__builtin_expect (ptr != NULL, 1)) | |
64382d5f | 8235 | foo (*ptr); |
89cfe6e5 | 8236 | @end smallexample |
8237 | ||
8238 | @noindent | |
8239 | when testing pointer or floating-point values. | |
67791935 | 8240 | @end deftypefn |
89cfe6e5 | 8241 | |
2f5beddc | 8242 | @deftypefn {Built-in Function} void __builtin_trap (void) |
8243 | This function causes the program to exit abnormally. GCC implements | |
8244 | this function by using a target-dependent mechanism (such as | |
8245 | intentionally executing an illegal instruction) or by calling | |
8246 | @code{abort}. The mechanism used may vary from release to release so | |
8247 | you should not rely on any particular implementation. | |
8248 | @end deftypefn | |
8249 | ||
d2b48f0c | 8250 | @deftypefn {Built-in Function} void __builtin_unreachable (void) |
8251 | If control flow reaches the point of the @code{__builtin_unreachable}, | |
8252 | the program is undefined. It is useful in situations where the | |
8253 | compiler cannot deduce the unreachability of the code. | |
8254 | ||
8255 | One such case is immediately following an @code{asm} statement that | |
8256 | will either never terminate, or one that transfers control elsewhere | |
8257 | and never returns. In this example, without the | |
8258 | @code{__builtin_unreachable}, GCC would issue a warning that control | |
8259 | reaches the end of a non-void function. It would also generate code | |
8260 | to return after the @code{asm}. | |
8261 | ||
8262 | @smallexample | |
8263 | int f (int c, int v) | |
8264 | @{ | |
8265 | if (c) | |
8266 | @{ | |
8267 | return v; | |
8268 | @} | |
8269 | else | |
8270 | @{ | |
8271 | asm("jmp error_handler"); | |
8272 | __builtin_unreachable (); | |
8273 | @} | |
8274 | @} | |
8275 | @end smallexample | |
8276 | ||
8277 | Because the @code{asm} statement unconditionally transfers control out | |
8278 | of the function, control will never reach the end of the function | |
8279 | body. The @code{__builtin_unreachable} is in fact unreachable and | |
8280 | communicates this fact to the compiler. | |
8281 | ||
8282 | Another use for @code{__builtin_unreachable} is following a call a | |
8283 | function that never returns but that is not declared | |
8284 | @code{__attribute__((noreturn))}, as in this example: | |
8285 | ||
8286 | @smallexample | |
8287 | void function_that_never_returns (void); | |
8288 | ||
8289 | int g (int c) | |
8290 | @{ | |
8291 | if (c) | |
8292 | @{ | |
8293 | return 1; | |
8294 | @} | |
8295 | else | |
8296 | @{ | |
8297 | function_that_never_returns (); | |
8298 | __builtin_unreachable (); | |
8299 | @} | |
8300 | @} | |
8301 | @end smallexample | |
8302 | ||
8303 | @end deftypefn | |
8304 | ||
fca0886c | 8305 | @deftypefn {Built-in Function} void *__builtin_assume_aligned (const void *@var{exp}, size_t @var{align}, ...) |
8306 | This function returns its first argument, and allows the compiler | |
8307 | to assume that the returned pointer is at least @var{align} bytes | |
8308 | aligned. This built-in can have either two or three arguments, | |
8309 | if it has three, the third argument should have integer type, and | |
8310 | if it is non-zero means misalignment offset. For example: | |
8311 | ||
8312 | @smallexample | |
8313 | void *x = __builtin_assume_aligned (arg, 16); | |
8314 | @end smallexample | |
8315 | ||
8316 | means that the compiler can assume x, set to arg, is at least | |
8317 | 16 byte aligned, while: | |
8318 | ||
8319 | @smallexample | |
8320 | void *x = __builtin_assume_aligned (arg, 32, 8); | |
8321 | @end smallexample | |
8322 | ||
8323 | means that the compiler can assume for x, set to arg, that | |
8324 | (char *) x - 8 is 32 byte aligned. | |
8325 | @end deftypefn | |
8326 | ||
8b76fbe9 | 8327 | @deftypefn {Built-in Function} int __builtin_LINE () |
8328 | This function is the equivalent to the preprocessor @code{__LINE__} | |
8329 | macro and returns the line number of the invocation of the built-in. | |
8330 | @end deftypefn | |
8331 | ||
8332 | @deftypefn {Built-in Function} int __builtin_FUNCTION () | |
8333 | This function is the equivalent to the preprocessor @code{__FUNCTION__} | |
8334 | macro and returns the function name the invocation of the built-in is in. | |
8335 | @end deftypefn | |
8336 | ||
8337 | @deftypefn {Built-in Function} int __builtin_FILE () | |
8338 | This function is the equivalent to the preprocessor @code{__FILE__} | |
8339 | macro and returns the file name the invocation of the built-in is in. | |
8340 | @end deftypefn | |
8341 | ||
ac8fb6db | 8342 | @deftypefn {Built-in Function} void __builtin___clear_cache (char *@var{begin}, char *@var{end}) |
8343 | This function is used to flush the processor's instruction cache for | |
8344 | the region of memory between @var{begin} inclusive and @var{end} | |
8345 | exclusive. Some targets require that the instruction cache be | |
8346 | flushed, after modifying memory containing code, in order to obtain | |
8347 | deterministic behavior. | |
8348 | ||
8349 | If the target does not require instruction cache flushes, | |
8350 | @code{__builtin___clear_cache} has no effect. Otherwise either | |
8351 | instructions are emitted in-line to clear the instruction cache or a | |
8352 | call to the @code{__clear_cache} function in libgcc is made. | |
8353 | @end deftypefn | |
8354 | ||
82086392 | 8355 | @deftypefn {Built-in Function} void __builtin_prefetch (const void *@var{addr}, ...) |
5e3608d8 | 8356 | This function is used to minimize cache-miss latency by moving data into |
8357 | a cache before it is accessed. | |
8358 | You can insert calls to @code{__builtin_prefetch} into code for which | |
8359 | you know addresses of data in memory that is likely to be accessed soon. | |
8360 | If the target supports them, data prefetch instructions will be generated. | |
8361 | If the prefetch is done early enough before the access then the data will | |
8362 | be in the cache by the time it is accessed. | |
8363 | ||
8364 | The value of @var{addr} is the address of the memory to prefetch. | |
26a5cadb | 8365 | There are two optional arguments, @var{rw} and @var{locality}. |
5e3608d8 | 8366 | The value of @var{rw} is a compile-time constant one or zero; one |
26a5cadb | 8367 | means that the prefetch is preparing for a write to the memory address |
8368 | and zero, the default, means that the prefetch is preparing for a read. | |
5e3608d8 | 8369 | The value @var{locality} must be a compile-time constant integer between |
8370 | zero and three. A value of zero means that the data has no temporal | |
8371 | locality, so it need not be left in the cache after the access. A value | |
8372 | of three means that the data has a high degree of temporal locality and | |
8373 | should be left in all levels of cache possible. Values of one and two | |
26a5cadb | 8374 | mean, respectively, a low or moderate degree of temporal locality. The |
8375 | default is three. | |
5e3608d8 | 8376 | |
8377 | @smallexample | |
8378 | for (i = 0; i < n; i++) | |
8379 | @{ | |
8380 | a[i] = a[i] + b[i]; | |
8381 | __builtin_prefetch (&a[i+j], 1, 1); | |
8382 | __builtin_prefetch (&b[i+j], 0, 1); | |
4ae74ddd | 8383 | /* @r{@dots{}} */ |
5e3608d8 | 8384 | @} |
8385 | @end smallexample | |
8386 | ||
228c5b30 | 8387 | Data prefetch does not generate faults if @var{addr} is invalid, but |
5e3608d8 | 8388 | the address expression itself must be valid. For example, a prefetch |
8389 | of @code{p->next} will not fault if @code{p->next} is not a valid | |
8390 | address, but evaluation will fault if @code{p} is not a valid address. | |
8391 | ||
8392 | If the target does not support data prefetch, the address expression | |
8393 | is evaluated if it includes side effects but no other code is generated | |
8394 | and GCC does not issue a warning. | |
8395 | @end deftypefn | |
8396 | ||
92c43e3c | 8397 | @deftypefn {Built-in Function} double __builtin_huge_val (void) |
8398 | Returns a positive infinity, if supported by the floating-point format, | |
8399 | else @code{DBL_MAX}. This function is suitable for implementing the | |
8400 | ISO C macro @code{HUGE_VAL}. | |
8401 | @end deftypefn | |
8402 | ||
8403 | @deftypefn {Built-in Function} float __builtin_huge_valf (void) | |
8404 | Similar to @code{__builtin_huge_val}, except the return type is @code{float}. | |
8405 | @end deftypefn | |
8406 | ||
a5285cd3 | 8407 | @deftypefn {Built-in Function} {long double} __builtin_huge_vall (void) |
92c43e3c | 8408 | Similar to @code{__builtin_huge_val}, except the return |
8409 | type is @code{long double}. | |
8410 | @end deftypefn | |
8411 | ||
19fbe3a4 | 8412 | @deftypefn {Built-in Function} int __builtin_fpclassify (int, int, int, int, int, ...) |
8413 | This built-in implements the C99 fpclassify functionality. The first | |
8414 | five int arguments should be the target library's notion of the | |
8415 | possible FP classes and are used for return values. They must be | |
8416 | constant values and they must appear in this order: @code{FP_NAN}, | |
921b27c0 | 8417 | @code{FP_INFINITE}, @code{FP_NORMAL}, @code{FP_SUBNORMAL} and |
19fbe3a4 | 8418 | @code{FP_ZERO}. The ellipsis is for exactly one floating point value |
8419 | to classify. GCC treats the last argument as type-generic, which | |
8420 | means it does not do default promotion from float to double. | |
8421 | @end deftypefn | |
8422 | ||
92c43e3c | 8423 | @deftypefn {Built-in Function} double __builtin_inf (void) |
8424 | Similar to @code{__builtin_huge_val}, except a warning is generated | |
8425 | if the target floating-point format does not support infinities. | |
92c43e3c | 8426 | @end deftypefn |
8427 | ||
c4503c0a | 8428 | @deftypefn {Built-in Function} _Decimal32 __builtin_infd32 (void) |
8429 | Similar to @code{__builtin_inf}, except the return type is @code{_Decimal32}. | |
8430 | @end deftypefn | |
8431 | ||
8432 | @deftypefn {Built-in Function} _Decimal64 __builtin_infd64 (void) | |
8433 | Similar to @code{__builtin_inf}, except the return type is @code{_Decimal64}. | |
8434 | @end deftypefn | |
8435 | ||
8436 | @deftypefn {Built-in Function} _Decimal128 __builtin_infd128 (void) | |
8437 | Similar to @code{__builtin_inf}, except the return type is @code{_Decimal128}. | |
8438 | @end deftypefn | |
8439 | ||
92c43e3c | 8440 | @deftypefn {Built-in Function} float __builtin_inff (void) |
8441 | Similar to @code{__builtin_inf}, except the return type is @code{float}. | |
5cbfa3ba | 8442 | This function is suitable for implementing the ISO C99 macro @code{INFINITY}. |
92c43e3c | 8443 | @end deftypefn |
8444 | ||
a5285cd3 | 8445 | @deftypefn {Built-in Function} {long double} __builtin_infl (void) |
92c43e3c | 8446 | Similar to @code{__builtin_inf}, except the return |
8447 | type is @code{long double}. | |
8448 | @end deftypefn | |
8449 | ||
c319d56a | 8450 | @deftypefn {Built-in Function} int __builtin_isinf_sign (...) |
8451 | Similar to @code{isinf}, except the return value will be negative for | |
8452 | an argument of @code{-Inf}. Note while the parameter list is an | |
8453 | ellipsis, this function only accepts exactly one floating point | |
8454 | argument. GCC treats this parameter as type-generic, which means it | |
8455 | does not do default promotion from float to double. | |
8456 | @end deftypefn | |
8457 | ||
b0db7939 | 8458 | @deftypefn {Built-in Function} double __builtin_nan (const char *str) |
8459 | This is an implementation of the ISO C99 function @code{nan}. | |
8460 | ||
8461 | Since ISO C99 defines this function in terms of @code{strtod}, which we | |
a99e98db | 8462 | do not implement, a description of the parsing is in order. The string |
b0db7939 | 8463 | is parsed as by @code{strtol}; that is, the base is recognized by |
8464 | leading @samp{0} or @samp{0x} prefixes. The number parsed is placed | |
8465 | in the significand such that the least significant bit of the number | |
7a0ad664 | 8466 | is at the least significant bit of the significand. The number is |
b0db7939 | 8467 | truncated to fit the significand field provided. The significand is |
b3d47662 | 8468 | forced to be a quiet NaN@. |
b0db7939 | 8469 | |
87ea783a | 8470 | This function, if given a string literal all of which would have been |
8471 | consumed by strtol, is evaluated early enough that it is considered a | |
8472 | compile-time constant. | |
b0db7939 | 8473 | @end deftypefn |
8474 | ||
c4503c0a | 8475 | @deftypefn {Built-in Function} _Decimal32 __builtin_nand32 (const char *str) |
8476 | Similar to @code{__builtin_nan}, except the return type is @code{_Decimal32}. | |
8477 | @end deftypefn | |
8478 | ||
8479 | @deftypefn {Built-in Function} _Decimal64 __builtin_nand64 (const char *str) | |
8480 | Similar to @code{__builtin_nan}, except the return type is @code{_Decimal64}. | |
8481 | @end deftypefn | |
8482 | ||
8483 | @deftypefn {Built-in Function} _Decimal128 __builtin_nand128 (const char *str) | |
8484 | Similar to @code{__builtin_nan}, except the return type is @code{_Decimal128}. | |
8485 | @end deftypefn | |
8486 | ||
b0db7939 | 8487 | @deftypefn {Built-in Function} float __builtin_nanf (const char *str) |
8488 | Similar to @code{__builtin_nan}, except the return type is @code{float}. | |
8489 | @end deftypefn | |
8490 | ||
a5285cd3 | 8491 | @deftypefn {Built-in Function} {long double} __builtin_nanl (const char *str) |
b0db7939 | 8492 | Similar to @code{__builtin_nan}, except the return type is @code{long double}. |
8493 | @end deftypefn | |
8494 | ||
8495 | @deftypefn {Built-in Function} double __builtin_nans (const char *str) | |
7a0ad664 | 8496 | Similar to @code{__builtin_nan}, except the significand is forced |
b3d47662 | 8497 | to be a signaling NaN@. The @code{nans} function is proposed by |
97ef626f | 8498 | @uref{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n965.htm,,WG14 N965}. |
b0db7939 | 8499 | @end deftypefn |
8500 | ||
8501 | @deftypefn {Built-in Function} float __builtin_nansf (const char *str) | |
8502 | Similar to @code{__builtin_nans}, except the return type is @code{float}. | |
8503 | @end deftypefn | |
8504 | ||
a5285cd3 | 8505 | @deftypefn {Built-in Function} {long double} __builtin_nansl (const char *str) |
b0db7939 | 8506 | Similar to @code{__builtin_nans}, except the return type is @code{long double}. |
8507 | @end deftypefn | |
8508 | ||
6a08d0ab | 8509 | @deftypefn {Built-in Function} int __builtin_ffs (unsigned int x) |
8510 | Returns one plus the index of the least significant 1-bit of @var{x}, or | |
8511 | if @var{x} is zero, returns zero. | |
8512 | @end deftypefn | |
8513 | ||
8514 | @deftypefn {Built-in Function} int __builtin_clz (unsigned int x) | |
8515 | Returns the number of leading 0-bits in @var{x}, starting at the most | |
8516 | significant bit position. If @var{x} is 0, the result is undefined. | |
8517 | @end deftypefn | |
8518 | ||
8519 | @deftypefn {Built-in Function} int __builtin_ctz (unsigned int x) | |
8520 | Returns the number of trailing 0-bits in @var{x}, starting at the least | |
8521 | significant bit position. If @var{x} is 0, the result is undefined. | |
8522 | @end deftypefn | |
8523 | ||
d8492bd3 | 8524 | @deftypefn {Built-in Function} int __builtin_clrsb (int x) |
8525 | Returns the number of leading redundant sign bits in @var{x}, i.e. the | |
8526 | number of bits following the most significant bit which are identical | |
8527 | to it. There are no special cases for 0 or other values. | |
8528 | @end deftypefn | |
8529 | ||
6a08d0ab | 8530 | @deftypefn {Built-in Function} int __builtin_popcount (unsigned int x) |
8531 | Returns the number of 1-bits in @var{x}. | |
8532 | @end deftypefn | |
8533 | ||
8534 | @deftypefn {Built-in Function} int __builtin_parity (unsigned int x) | |
b3d47662 | 8535 | Returns the parity of @var{x}, i.e.@: the number of 1-bits in @var{x} |
6a08d0ab | 8536 | modulo 2. |
8537 | @end deftypefn | |
8538 | ||
8539 | @deftypefn {Built-in Function} int __builtin_ffsl (unsigned long) | |
8540 | Similar to @code{__builtin_ffs}, except the argument type is | |
8541 | @code{unsigned long}. | |
8542 | @end deftypefn | |
8543 | ||
8544 | @deftypefn {Built-in Function} int __builtin_clzl (unsigned long) | |
8545 | Similar to @code{__builtin_clz}, except the argument type is | |
8546 | @code{unsigned long}. | |
8547 | @end deftypefn | |
8548 | ||
8549 | @deftypefn {Built-in Function} int __builtin_ctzl (unsigned long) | |
8550 | Similar to @code{__builtin_ctz}, except the argument type is | |
8551 | @code{unsigned long}. | |
8552 | @end deftypefn | |
8553 | ||
d8492bd3 | 8554 | @deftypefn {Built-in Function} int __builtin_clrsbl (long) |
8555 | Similar to @code{__builtin_clrsb}, except the argument type is | |
8556 | @code{long}. | |
8557 | @end deftypefn | |
8558 | ||
6a08d0ab | 8559 | @deftypefn {Built-in Function} int __builtin_popcountl (unsigned long) |
8560 | Similar to @code{__builtin_popcount}, except the argument type is | |
8561 | @code{unsigned long}. | |
8562 | @end deftypefn | |
8563 | ||
8564 | @deftypefn {Built-in Function} int __builtin_parityl (unsigned long) | |
8565 | Similar to @code{__builtin_parity}, except the argument type is | |
8566 | @code{unsigned long}. | |
8567 | @end deftypefn | |
8568 | ||
8569 | @deftypefn {Built-in Function} int __builtin_ffsll (unsigned long long) | |
8570 | Similar to @code{__builtin_ffs}, except the argument type is | |
8571 | @code{unsigned long long}. | |
8572 | @end deftypefn | |
8573 | ||
8574 | @deftypefn {Built-in Function} int __builtin_clzll (unsigned long long) | |
8575 | Similar to @code{__builtin_clz}, except the argument type is | |
8576 | @code{unsigned long long}. | |
8577 | @end deftypefn | |
8578 | ||
8579 | @deftypefn {Built-in Function} int __builtin_ctzll (unsigned long long) | |
8580 | Similar to @code{__builtin_ctz}, except the argument type is | |
8581 | @code{unsigned long long}. | |
8582 | @end deftypefn | |
8583 | ||
d8492bd3 | 8584 | @deftypefn {Built-in Function} int __builtin_clrsbll (long long) |
8585 | Similar to @code{__builtin_clrsb}, except the argument type is | |
8586 | @code{long long}. | |
8587 | @end deftypefn | |
8588 | ||
6a08d0ab | 8589 | @deftypefn {Built-in Function} int __builtin_popcountll (unsigned long long) |
8590 | Similar to @code{__builtin_popcount}, except the argument type is | |
8591 | @code{unsigned long long}. | |
8592 | @end deftypefn | |
8593 | ||
8594 | @deftypefn {Built-in Function} int __builtin_parityll (unsigned long long) | |
8595 | Similar to @code{__builtin_parity}, except the argument type is | |
8596 | @code{unsigned long long}. | |
8597 | @end deftypefn | |
8598 | ||
757c219d | 8599 | @deftypefn {Built-in Function} double __builtin_powi (double, int) |
8600 | Returns the first argument raised to the power of the second. Unlike the | |
8601 | @code{pow} function no guarantees about precision and rounding are made. | |
8602 | @end deftypefn | |
8603 | ||
8604 | @deftypefn {Built-in Function} float __builtin_powif (float, int) | |
8605 | Similar to @code{__builtin_powi}, except the argument and return types | |
8606 | are @code{float}. | |
8607 | @end deftypefn | |
8608 | ||
8609 | @deftypefn {Built-in Function} {long double} __builtin_powil (long double, int) | |
8610 | Similar to @code{__builtin_powi}, except the argument and return types | |
8611 | are @code{long double}. | |
8612 | @end deftypefn | |
8613 | ||
74bdbe96 | 8614 | @deftypefn {Built-in Function} int16_t __builtin_bswap16 (int16_t x) |
42791117 | 8615 | Returns @var{x} with the order of the bytes reversed; for example, |
74bdbe96 | 8616 | @code{0xaabb} becomes @code{0xbbaa}. Byte here always means |
42791117 | 8617 | exactly 8 bits. |
8618 | @end deftypefn | |
8619 | ||
74bdbe96 | 8620 | @deftypefn {Built-in Function} int32_t __builtin_bswap32 (int32_t x) |
8621 | Similar to @code{__builtin_bswap16}, except the argument and return types | |
8622 | are 32-bit. | |
8623 | @end deftypefn | |
8624 | ||
42791117 | 8625 | @deftypefn {Built-in Function} int64_t __builtin_bswap64 (int64_t x) |
8626 | Similar to @code{__builtin_bswap32}, except the argument and return types | |
8627 | are 64-bit. | |
8628 | @end deftypefn | |
6a08d0ab | 8629 | |
ca5827cf | 8630 | @node Target Builtins |
8631 | @section Built-in Functions Specific to Particular Target Machines | |
8632 | ||
8633 | On some target machines, GCC supports many built-in functions specific | |
8634 | to those machines. Generally these generate calls to specific machine | |
8635 | instructions, but allow the compiler to schedule those calls. | |
8636 | ||
8637 | @menu | |
f2cc13dc | 8638 | * Alpha Built-in Functions:: |
d98a3884 | 8639 | * ARM iWMMXt Built-in Functions:: |
8640 | * ARM NEON Intrinsics:: | |
c5be380e | 8641 | * AVR Built-in Functions:: |
88a26425 | 8642 | * Blackfin Built-in Functions:: |
8001abc8 | 8643 | * FR-V Built-in Functions:: |
ca5827cf | 8644 | * X86 Built-in Functions:: |
b7efe757 | 8645 | * MIPS DSP Built-in Functions:: |
dd2a386a | 8646 | * MIPS Paired-Single Support:: |
9636921b | 8647 | * MIPS Loongson Built-in Functions:: |
f5ec18cc | 8648 | * Other MIPS Built-in Functions:: |
8372e9ea | 8649 | * picoChip Built-in Functions:: |
32374e3c | 8650 | * PowerPC AltiVec/VSX Built-in Functions:: |
24833e1a | 8651 | * RX Built-in Functions:: |
88fb6217 | 8652 | * SPARC VIS Built-in Functions:: |
644459d0 | 8653 | * SPU Built-in Functions:: |
5aa04b01 | 8654 | * TI C6X Built-in Functions:: |
7ce78e23 | 8655 | * TILE-Gx Built-in Functions:: |
8656 | * TILEPro Built-in Functions:: | |
ca5827cf | 8657 | @end menu |
8658 | ||
f2cc13dc | 8659 | @node Alpha Built-in Functions |
8660 | @subsection Alpha Built-in Functions | |
8661 | ||
8662 | These built-in functions are available for the Alpha family of | |
8663 | processors, depending on the command-line switches used. | |
8664 | ||
85456819 | 8665 | The following built-in functions are always available. They |
f2cc13dc | 8666 | all generate the machine instruction that is part of the name. |
8667 | ||
a0ecd6b1 | 8668 | @smallexample |
f2cc13dc | 8669 | long __builtin_alpha_implver (void) |
8670 | long __builtin_alpha_rpcc (void) | |
8671 | long __builtin_alpha_amask (long) | |
8672 | long __builtin_alpha_cmpbge (long, long) | |
ae4cd3a5 | 8673 | long __builtin_alpha_extbl (long, long) |
8674 | long __builtin_alpha_extwl (long, long) | |
8675 | long __builtin_alpha_extll (long, long) | |
f2cc13dc | 8676 | long __builtin_alpha_extql (long, long) |
ae4cd3a5 | 8677 | long __builtin_alpha_extwh (long, long) |
8678 | long __builtin_alpha_extlh (long, long) | |
f2cc13dc | 8679 | long __builtin_alpha_extqh (long, long) |
ae4cd3a5 | 8680 | long __builtin_alpha_insbl (long, long) |
8681 | long __builtin_alpha_inswl (long, long) | |
8682 | long __builtin_alpha_insll (long, long) | |
8683 | long __builtin_alpha_insql (long, long) | |
8684 | long __builtin_alpha_inswh (long, long) | |
8685 | long __builtin_alpha_inslh (long, long) | |
8686 | long __builtin_alpha_insqh (long, long) | |
8687 | long __builtin_alpha_mskbl (long, long) | |
8688 | long __builtin_alpha_mskwl (long, long) | |
8689 | long __builtin_alpha_mskll (long, long) | |
8690 | long __builtin_alpha_mskql (long, long) | |
8691 | long __builtin_alpha_mskwh (long, long) | |
8692 | long __builtin_alpha_msklh (long, long) | |
8693 | long __builtin_alpha_mskqh (long, long) | |
8694 | long __builtin_alpha_umulh (long, long) | |
f2cc13dc | 8695 | long __builtin_alpha_zap (long, long) |
8696 | long __builtin_alpha_zapnot (long, long) | |
a0ecd6b1 | 8697 | @end smallexample |
f2cc13dc | 8698 | |
8699 | The following built-in functions are always with @option{-mmax} | |
8700 | or @option{-mcpu=@var{cpu}} where @var{cpu} is @code{pca56} or | |
8701 | later. They all generate the machine instruction that is part | |
8702 | of the name. | |
8703 | ||
a0ecd6b1 | 8704 | @smallexample |
f2cc13dc | 8705 | long __builtin_alpha_pklb (long) |
8706 | long __builtin_alpha_pkwb (long) | |
8707 | long __builtin_alpha_unpkbl (long) | |
8708 | long __builtin_alpha_unpkbw (long) | |
8709 | long __builtin_alpha_minub8 (long, long) | |
8710 | long __builtin_alpha_minsb8 (long, long) | |
8711 | long __builtin_alpha_minuw4 (long, long) | |
8712 | long __builtin_alpha_minsw4 (long, long) | |
8713 | long __builtin_alpha_maxub8 (long, long) | |
8714 | long __builtin_alpha_maxsb8 (long, long) | |
8715 | long __builtin_alpha_maxuw4 (long, long) | |
8716 | long __builtin_alpha_maxsw4 (long, long) | |
8717 | long __builtin_alpha_perr (long, long) | |
a0ecd6b1 | 8718 | @end smallexample |
f2cc13dc | 8719 | |
ae4cd3a5 | 8720 | The following built-in functions are always with @option{-mcix} |
8721 | or @option{-mcpu=@var{cpu}} where @var{cpu} is @code{ev67} or | |
8722 | later. They all generate the machine instruction that is part | |
8723 | of the name. | |
8724 | ||
a0ecd6b1 | 8725 | @smallexample |
ae4cd3a5 | 8726 | long __builtin_alpha_cttz (long) |
8727 | long __builtin_alpha_ctlz (long) | |
8728 | long __builtin_alpha_ctpop (long) | |
a0ecd6b1 | 8729 | @end smallexample |
ae4cd3a5 | 8730 | |
938e069b | 8731 | The following builtins are available on systems that use the OSF/1 |
8732 | PALcode. Normally they invoke the @code{rduniq} and @code{wruniq} | |
8733 | PAL calls, but when invoked with @option{-mtls-kernel}, they invoke | |
8734 | @code{rdval} and @code{wrval}. | |
8735 | ||
a0ecd6b1 | 8736 | @smallexample |
938e069b | 8737 | void *__builtin_thread_pointer (void) |
8738 | void __builtin_set_thread_pointer (void *) | |
a0ecd6b1 | 8739 | @end smallexample |
938e069b | 8740 | |
d98a3884 | 8741 | @node ARM iWMMXt Built-in Functions |
8742 | @subsection ARM iWMMXt Built-in Functions | |
af72d7d6 | 8743 | |
8744 | These built-in functions are available for the ARM family of | |
d98a3884 | 8745 | processors when the @option{-mcpu=iwmmxt} switch is used: |
af72d7d6 | 8746 | |
a0ecd6b1 | 8747 | @smallexample |
c1f4dba6 | 8748 | typedef int v2si __attribute__ ((vector_size (8))); |
8749 | typedef short v4hi __attribute__ ((vector_size (8))); | |
8750 | typedef char v8qi __attribute__ ((vector_size (8))); | |
8751 | ||
b780dd27 | 8752 | int __builtin_arm_getwcgr0 (void) |
8753 | void __builtin_arm_setwcgr0 (int) | |
8754 | int __builtin_arm_getwcgr1 (void) | |
8755 | void __builtin_arm_setwcgr1 (int) | |
8756 | int __builtin_arm_getwcgr2 (void) | |
8757 | void __builtin_arm_setwcgr2 (int) | |
8758 | int __builtin_arm_getwcgr3 (void) | |
8759 | void __builtin_arm_setwcgr3 (int) | |
c1f4dba6 | 8760 | int __builtin_arm_textrmsb (v8qi, int) |
8761 | int __builtin_arm_textrmsh (v4hi, int) | |
8762 | int __builtin_arm_textrmsw (v2si, int) | |
8763 | int __builtin_arm_textrmub (v8qi, int) | |
8764 | int __builtin_arm_textrmuh (v4hi, int) | |
8765 | int __builtin_arm_textrmuw (v2si, int) | |
b780dd27 | 8766 | v8qi __builtin_arm_tinsrb (v8qi, int, int) |
8767 | v4hi __builtin_arm_tinsrh (v4hi, int, int) | |
8768 | v2si __builtin_arm_tinsrw (v2si, int, int) | |
c1f4dba6 | 8769 | long long __builtin_arm_tmia (long long, int, int) |
8770 | long long __builtin_arm_tmiabb (long long, int, int) | |
8771 | long long __builtin_arm_tmiabt (long long, int, int) | |
8772 | long long __builtin_arm_tmiaph (long long, int, int) | |
8773 | long long __builtin_arm_tmiatb (long long, int, int) | |
8774 | long long __builtin_arm_tmiatt (long long, int, int) | |
8775 | int __builtin_arm_tmovmskb (v8qi) | |
8776 | int __builtin_arm_tmovmskh (v4hi) | |
8777 | int __builtin_arm_tmovmskw (v2si) | |
8778 | long long __builtin_arm_waccb (v8qi) | |
8779 | long long __builtin_arm_wacch (v4hi) | |
8780 | long long __builtin_arm_waccw (v2si) | |
8781 | v8qi __builtin_arm_waddb (v8qi, v8qi) | |
8782 | v8qi __builtin_arm_waddbss (v8qi, v8qi) | |
8783 | v8qi __builtin_arm_waddbus (v8qi, v8qi) | |
8784 | v4hi __builtin_arm_waddh (v4hi, v4hi) | |
8785 | v4hi __builtin_arm_waddhss (v4hi, v4hi) | |
8786 | v4hi __builtin_arm_waddhus (v4hi, v4hi) | |
af72d7d6 | 8787 | v2si __builtin_arm_waddw (v2si, v2si) |
af72d7d6 | 8788 | v2si __builtin_arm_waddwss (v2si, v2si) |
af72d7d6 | 8789 | v2si __builtin_arm_waddwus (v2si, v2si) |
c1f4dba6 | 8790 | v8qi __builtin_arm_walign (v8qi, v8qi, int) |
8791 | long long __builtin_arm_wand(long long, long long) | |
8792 | long long __builtin_arm_wandn (long long, long long) | |
8793 | v8qi __builtin_arm_wavg2b (v8qi, v8qi) | |
8794 | v8qi __builtin_arm_wavg2br (v8qi, v8qi) | |
8795 | v4hi __builtin_arm_wavg2h (v4hi, v4hi) | |
8796 | v4hi __builtin_arm_wavg2hr (v4hi, v4hi) | |
8797 | v8qi __builtin_arm_wcmpeqb (v8qi, v8qi) | |
8798 | v4hi __builtin_arm_wcmpeqh (v4hi, v4hi) | |
af72d7d6 | 8799 | v2si __builtin_arm_wcmpeqw (v2si, v2si) |
c1f4dba6 | 8800 | v8qi __builtin_arm_wcmpgtsb (v8qi, v8qi) |
8801 | v4hi __builtin_arm_wcmpgtsh (v4hi, v4hi) | |
af72d7d6 | 8802 | v2si __builtin_arm_wcmpgtsw (v2si, v2si) |
c1f4dba6 | 8803 | v8qi __builtin_arm_wcmpgtub (v8qi, v8qi) |
8804 | v4hi __builtin_arm_wcmpgtuh (v4hi, v4hi) | |
8805 | v2si __builtin_arm_wcmpgtuw (v2si, v2si) | |
8806 | long long __builtin_arm_wmacs (long long, v4hi, v4hi) | |
8807 | long long __builtin_arm_wmacsz (v4hi, v4hi) | |
8808 | long long __builtin_arm_wmacu (long long, v4hi, v4hi) | |
8809 | long long __builtin_arm_wmacuz (v4hi, v4hi) | |
8810 | v4hi __builtin_arm_wmadds (v4hi, v4hi) | |
8811 | v4hi __builtin_arm_wmaddu (v4hi, v4hi) | |
8812 | v8qi __builtin_arm_wmaxsb (v8qi, v8qi) | |
8813 | v4hi __builtin_arm_wmaxsh (v4hi, v4hi) | |
af72d7d6 | 8814 | v2si __builtin_arm_wmaxsw (v2si, v2si) |
c1f4dba6 | 8815 | v8qi __builtin_arm_wmaxub (v8qi, v8qi) |
8816 | v4hi __builtin_arm_wmaxuh (v4hi, v4hi) | |
af72d7d6 | 8817 | v2si __builtin_arm_wmaxuw (v2si, v2si) |
c1f4dba6 | 8818 | v8qi __builtin_arm_wminsb (v8qi, v8qi) |
8819 | v4hi __builtin_arm_wminsh (v4hi, v4hi) | |
af72d7d6 | 8820 | v2si __builtin_arm_wminsw (v2si, v2si) |
c1f4dba6 | 8821 | v8qi __builtin_arm_wminub (v8qi, v8qi) |
8822 | v4hi __builtin_arm_wminuh (v4hi, v4hi) | |
af72d7d6 | 8823 | v2si __builtin_arm_wminuw (v2si, v2si) |
c1f4dba6 | 8824 | v4hi __builtin_arm_wmulsm (v4hi, v4hi) |
8825 | v4hi __builtin_arm_wmulul (v4hi, v4hi) | |
8826 | v4hi __builtin_arm_wmulum (v4hi, v4hi) | |
8827 | long long __builtin_arm_wor (long long, long long) | |
8828 | v2si __builtin_arm_wpackdss (long long, long long) | |
8829 | v2si __builtin_arm_wpackdus (long long, long long) | |
8830 | v8qi __builtin_arm_wpackhss (v4hi, v4hi) | |
8831 | v8qi __builtin_arm_wpackhus (v4hi, v4hi) | |
8832 | v4hi __builtin_arm_wpackwss (v2si, v2si) | |
8833 | v4hi __builtin_arm_wpackwus (v2si, v2si) | |
8834 | long long __builtin_arm_wrord (long long, long long) | |
8835 | long long __builtin_arm_wrordi (long long, int) | |
8836 | v4hi __builtin_arm_wrorh (v4hi, long long) | |
8837 | v4hi __builtin_arm_wrorhi (v4hi, int) | |
8838 | v2si __builtin_arm_wrorw (v2si, long long) | |
8839 | v2si __builtin_arm_wrorwi (v2si, int) | |
b780dd27 | 8840 | v2si __builtin_arm_wsadb (v2si, v8qi, v8qi) |
c1f4dba6 | 8841 | v2si __builtin_arm_wsadbz (v8qi, v8qi) |
b780dd27 | 8842 | v2si __builtin_arm_wsadh (v2si, v4hi, v4hi) |
c1f4dba6 | 8843 | v2si __builtin_arm_wsadhz (v4hi, v4hi) |
8844 | v4hi __builtin_arm_wshufh (v4hi, int) | |
8845 | long long __builtin_arm_wslld (long long, long long) | |
8846 | long long __builtin_arm_wslldi (long long, int) | |
8847 | v4hi __builtin_arm_wsllh (v4hi, long long) | |
8848 | v4hi __builtin_arm_wsllhi (v4hi, int) | |
8849 | v2si __builtin_arm_wsllw (v2si, long long) | |
af72d7d6 | 8850 | v2si __builtin_arm_wsllwi (v2si, int) |
c1f4dba6 | 8851 | long long __builtin_arm_wsrad (long long, long long) |
8852 | long long __builtin_arm_wsradi (long long, int) | |
8853 | v4hi __builtin_arm_wsrah (v4hi, long long) | |
8854 | v4hi __builtin_arm_wsrahi (v4hi, int) | |
8855 | v2si __builtin_arm_wsraw (v2si, long long) | |
af72d7d6 | 8856 | v2si __builtin_arm_wsrawi (v2si, int) |
c1f4dba6 | 8857 | long long __builtin_arm_wsrld (long long, long long) |
8858 | long long __builtin_arm_wsrldi (long long, int) | |
8859 | v4hi __builtin_arm_wsrlh (v4hi, long long) | |
8860 | v4hi __builtin_arm_wsrlhi (v4hi, int) | |
8861 | v2si __builtin_arm_wsrlw (v2si, long long) | |
af72d7d6 | 8862 | v2si __builtin_arm_wsrlwi (v2si, int) |
c1f4dba6 | 8863 | v8qi __builtin_arm_wsubb (v8qi, v8qi) |
8864 | v8qi __builtin_arm_wsubbss (v8qi, v8qi) | |
8865 | v8qi __builtin_arm_wsubbus (v8qi, v8qi) | |
8866 | v4hi __builtin_arm_wsubh (v4hi, v4hi) | |
8867 | v4hi __builtin_arm_wsubhss (v4hi, v4hi) | |
8868 | v4hi __builtin_arm_wsubhus (v4hi, v4hi) | |
8869 | v2si __builtin_arm_wsubw (v2si, v2si) | |
8870 | v2si __builtin_arm_wsubwss (v2si, v2si) | |
8871 | v2si __builtin_arm_wsubwus (v2si, v2si) | |
8872 | v4hi __builtin_arm_wunpckehsb (v8qi) | |
8873 | v2si __builtin_arm_wunpckehsh (v4hi) | |
8874 | long long __builtin_arm_wunpckehsw (v2si) | |
8875 | v4hi __builtin_arm_wunpckehub (v8qi) | |
8876 | v2si __builtin_arm_wunpckehuh (v4hi) | |
8877 | long long __builtin_arm_wunpckehuw (v2si) | |
8878 | v4hi __builtin_arm_wunpckelsb (v8qi) | |
8879 | v2si __builtin_arm_wunpckelsh (v4hi) | |
8880 | long long __builtin_arm_wunpckelsw (v2si) | |
8881 | v4hi __builtin_arm_wunpckelub (v8qi) | |
8882 | v2si __builtin_arm_wunpckeluh (v4hi) | |
8883 | long long __builtin_arm_wunpckeluw (v2si) | |
8884 | v8qi __builtin_arm_wunpckihb (v8qi, v8qi) | |
8885 | v4hi __builtin_arm_wunpckihh (v4hi, v4hi) | |
af72d7d6 | 8886 | v2si __builtin_arm_wunpckihw (v2si, v2si) |
c1f4dba6 | 8887 | v8qi __builtin_arm_wunpckilb (v8qi, v8qi) |
8888 | v4hi __builtin_arm_wunpckilh (v4hi, v4hi) | |
af72d7d6 | 8889 | v2si __builtin_arm_wunpckilw (v2si, v2si) |
c1f4dba6 | 8890 | long long __builtin_arm_wxor (long long, long long) |
8891 | long long __builtin_arm_wzero () | |
a0ecd6b1 | 8892 | @end smallexample |
af72d7d6 | 8893 | |
d98a3884 | 8894 | @node ARM NEON Intrinsics |
8895 | @subsection ARM NEON Intrinsics | |
8896 | ||
8897 | These built-in intrinsics for the ARM Advanced SIMD extension are available | |
8898 | when the @option{-mfpu=neon} switch is used: | |
8899 | ||
8900 | @include arm-neon-intrinsics.texi | |
8901 | ||
c5be380e | 8902 | @node AVR Built-in Functions |
8903 | @subsection AVR Built-in Functions | |
8904 | ||
8905 | For each built-in function for AVR, there is an equally named, | |
8906 | uppercase built-in macro defined. That way users can easily query if | |
8907 | or if not a specific built-in is implemented or not. For example, if | |
8908 | @code{__builtin_avr_nop} is available the macro | |
8909 | @code{__BUILTIN_AVR_NOP} is defined to @code{1} and undefined otherwise. | |
8910 | ||
8911 | The following built-in functions map to the respective machine | |
8912 | instruction, i.e. @code{nop}, @code{sei}, @code{cli}, @code{sleep}, | |
8913 | @code{wdr}, @code{swap}, @code{fmul}, @code{fmuls} | |
12596ea7 | 8914 | resp. @code{fmulsu}. The three @code{fmul*} built-ins are implemented |
8915 | as library call if no hardware multiplier is available. | |
c5be380e | 8916 | |
8917 | @smallexample | |
8918 | void __builtin_avr_nop (void) | |
8919 | void __builtin_avr_sei (void) | |
8920 | void __builtin_avr_cli (void) | |
8921 | void __builtin_avr_sleep (void) | |
8922 | void __builtin_avr_wdr (void) | |
8923 | unsigned char __builtin_avr_swap (unsigned char) | |
8924 | unsigned int __builtin_avr_fmul (unsigned char, unsigned char) | |
8925 | int __builtin_avr_fmuls (char, char) | |
8926 | int __builtin_avr_fmulsu (char, unsigned char) | |
8927 | @end smallexample | |
8928 | ||
8929 | In order to delay execution for a specific number of cycles, GCC | |
8930 | implements | |
8931 | @smallexample | |
8932 | void __builtin_avr_delay_cycles (unsigned long ticks) | |
8933 | @end smallexample | |
8934 | ||
384f6361 | 8935 | @noindent |
c5be380e | 8936 | @code{ticks} is the number of ticks to delay execution. Note that this |
8937 | built-in does not take into account the effect of interrupts which | |
8938 | might increase delay time. @code{ticks} must be a compile time | |
8939 | integer constant; delays with a variable number of cycles are not supported. | |
8940 | ||
384f6361 | 8941 | @smallexample |
12ffadfa | 8942 | char __builtin_avr_flash_segment (const __memx void*) |
8943 | @end smallexample | |
8944 | ||
8945 | @noindent | |
8946 | This built-in takes a byte address to the 24-bit | |
8947 | @ref{AVR Named Address Spaces,address space} @code{__memx} and returns | |
8948 | the number of the flash segment (the 64 KiB chunk) where the address | |
8949 | points to. Counting starts at @code{0}. | |
8950 | If the address does not point to flash memory, return @code{-1}. | |
8951 | ||
8952 | @smallexample | |
8953 | unsigned char __builtin_avr_insert_bits (unsigned long map, unsigned char bits, unsigned char val) | |
384f6361 | 8954 | @end smallexample |
8955 | ||
8956 | @noindent | |
15b84087 | 8957 | Insert bits from @var{bits} into @var{val} and return the resulting |
8958 | value. The nibbles of @var{map} determine how the insertion is | |
8959 | performed: Let @var{X} be the @var{n}-th nibble of @var{map} | |
8960 | @enumerate | |
8961 | @item If @var{X} is @code{0xf}, | |
8962 | then the @var{n}-th bit of @var{val} is returned unaltered. | |
8963 | ||
8964 | @item If X is in the range 0@dots{}7, | |
8965 | then the @var{n}-th result bit is set to the @var{X}-th bit of @var{bits} | |
8966 | ||
8967 | @item If X is in the range 8@dots{}@code{0xe}, | |
8968 | then the @var{n}-th result bit is undefined. | |
8969 | @end enumerate | |
384f6361 | 8970 | |
8971 | @noindent | |
15b84087 | 8972 | One typical use case for this built-in is adjusting input and |
8973 | output values to non-contiguous port layouts. Some examples: | |
384f6361 | 8974 | |
8975 | @smallexample | |
15b84087 | 8976 | // same as val, bits is unused |
8977 | __builtin_avr_insert_bits (0xffffffff, bits, val) | |
384f6361 | 8978 | @end smallexample |
8979 | ||
15b84087 | 8980 | @smallexample |
8981 | // same as bits, val is unused | |
8982 | __builtin_avr_insert_bits (0x76543210, bits, val) | |
8983 | @end smallexample | |
8984 | ||
8985 | @smallexample | |
8986 | // same as rotating bits by 4 | |
8987 | __builtin_avr_insert_bits (0x32107654, bits, 0) | |
8988 | @end smallexample | |
8989 | ||
8990 | @smallexample | |
8991 | // high-nibble of result is the high-nibble of val | |
8992 | // low-nibble of result is the low-nibble of bits | |
8993 | __builtin_avr_insert_bits (0xffff3210, bits, val) | |
8994 | @end smallexample | |
8995 | ||
8996 | @smallexample | |
8997 | // reverse the bit order of bits | |
8998 | __builtin_avr_insert_bits (0x01234567, bits, 0) | |
8999 | @end smallexample | |
384f6361 | 9000 | |
88a26425 | 9001 | @node Blackfin Built-in Functions |
9002 | @subsection Blackfin Built-in Functions | |
9003 | ||
9004 | Currently, there are two Blackfin-specific built-in functions. These are | |
9005 | used for generating @code{CSYNC} and @code{SSYNC} machine insns without | |
9006 | using inline assembly; by using these built-in functions the compiler can | |
9007 | automatically add workarounds for hardware errata involving these | |
9008 | instructions. These functions are named as follows: | |
9009 | ||
9010 | @smallexample | |
9011 | void __builtin_bfin_csync (void) | |
9012 | void __builtin_bfin_ssync (void) | |
9013 | @end smallexample | |
9014 | ||
8001abc8 | 9015 | @node FR-V Built-in Functions |
9016 | @subsection FR-V Built-in Functions | |
9017 | ||
9018 | GCC provides many FR-V-specific built-in functions. In general, | |
9019 | these functions are intended to be compatible with those described | |
9020 | by @cite{FR-V Family, Softune C/C++ Compiler Manual (V6), Fujitsu | |
9021 | Semiconductor}. The two exceptions are @code{__MDUNPACKH} and | |
9022 | @code{__MBTOHE}, the gcc forms of which pass 128-bit values by | |
9023 | pointer rather than by value. | |
9024 | ||
9025 | Most of the functions are named after specific FR-V instructions. | |
fcc3191b | 9026 | Such functions are said to be ``directly mapped'' and are summarized |
8001abc8 | 9027 | here in tabular form. |
9028 | ||
9029 | @menu | |
9030 | * Argument Types:: | |
9031 | * Directly-mapped Integer Functions:: | |
9032 | * Directly-mapped Media Functions:: | |
9f3b67fe | 9033 | * Raw read/write Functions:: |
8001abc8 | 9034 | * Other Built-in Functions:: |
9035 | @end menu | |
9036 | ||
9037 | @node Argument Types | |
9038 | @subsubsection Argument Types | |
9039 | ||
9040 | The arguments to the built-in functions can be divided into three groups: | |
9041 | register numbers, compile-time constants and run-time values. In order | |
9042 | to make this classification clear at a glance, the arguments and return | |
9043 | values are given the following pseudo types: | |
9044 | ||
9045 | @multitable @columnfractions .20 .30 .15 .35 | |
9046 | @item Pseudo type @tab Real C type @tab Constant? @tab Description | |
9047 | @item @code{uh} @tab @code{unsigned short} @tab No @tab an unsigned halfword | |
9048 | @item @code{uw1} @tab @code{unsigned int} @tab No @tab an unsigned word | |
9049 | @item @code{sw1} @tab @code{int} @tab No @tab a signed word | |
9050 | @item @code{uw2} @tab @code{unsigned long long} @tab No | |
9051 | @tab an unsigned doubleword | |
9052 | @item @code{sw2} @tab @code{long long} @tab No @tab a signed doubleword | |
9053 | @item @code{const} @tab @code{int} @tab Yes @tab an integer constant | |
9054 | @item @code{acc} @tab @code{int} @tab Yes @tab an ACC register number | |
9055 | @item @code{iacc} @tab @code{int} @tab Yes @tab an IACC register number | |
9056 | @end multitable | |
9057 | ||
9058 | These pseudo types are not defined by GCC, they are simply a notational | |
9059 | convenience used in this manual. | |
9060 | ||
9061 | Arguments of type @code{uh}, @code{uw1}, @code{sw1}, @code{uw2} | |
9062 | and @code{sw2} are evaluated at run time. They correspond to | |
9063 | register operands in the underlying FR-V instructions. | |
9064 | ||
9065 | @code{const} arguments represent immediate operands in the underlying | |
9066 | FR-V instructions. They must be compile-time constants. | |
9067 | ||
9068 | @code{acc} arguments are evaluated at compile time and specify the number | |
9069 | of an accumulator register. For example, an @code{acc} argument of 2 | |
9070 | will select the ACC2 register. | |
9071 | ||
9072 | @code{iacc} arguments are similar to @code{acc} arguments but specify the | |
9073 | number of an IACC register. See @pxref{Other Built-in Functions} | |
9074 | for more details. | |
9075 | ||
9076 | @node Directly-mapped Integer Functions | |
9077 | @subsubsection Directly-mapped Integer Functions | |
9078 | ||
9079 | The functions listed below map directly to FR-V I-type instructions. | |
9080 | ||
9081 | @multitable @columnfractions .45 .32 .23 | |
9082 | @item Function prototype @tab Example usage @tab Assembly output | |
9083 | @item @code{sw1 __ADDSS (sw1, sw1)} | |
9084 | @tab @code{@var{c} = __ADDSS (@var{a}, @var{b})} | |
9085 | @tab @code{ADDSS @var{a},@var{b},@var{c}} | |
9086 | @item @code{sw1 __SCAN (sw1, sw1)} | |
9087 | @tab @code{@var{c} = __SCAN (@var{a}, @var{b})} | |
9088 | @tab @code{SCAN @var{a},@var{b},@var{c}} | |
9089 | @item @code{sw1 __SCUTSS (sw1)} | |
9090 | @tab @code{@var{b} = __SCUTSS (@var{a})} | |
9091 | @tab @code{SCUTSS @var{a},@var{b}} | |
9092 | @item @code{sw1 __SLASS (sw1, sw1)} | |
9093 | @tab @code{@var{c} = __SLASS (@var{a}, @var{b})} | |
9094 | @tab @code{SLASS @var{a},@var{b},@var{c}} | |
9095 | @item @code{void __SMASS (sw1, sw1)} | |
9096 | @tab @code{__SMASS (@var{a}, @var{b})} | |
9097 | @tab @code{SMASS @var{a},@var{b}} | |
9098 | @item @code{void __SMSSS (sw1, sw1)} | |
9099 | @tab @code{__SMSSS (@var{a}, @var{b})} | |
9100 | @tab @code{SMSSS @var{a},@var{b}} | |
9101 | @item @code{void __SMU (sw1, sw1)} | |
9102 | @tab @code{__SMU (@var{a}, @var{b})} | |
9103 | @tab @code{SMU @var{a},@var{b}} | |
9104 | @item @code{sw2 __SMUL (sw1, sw1)} | |
9105 | @tab @code{@var{c} = __SMUL (@var{a}, @var{b})} | |
9106 | @tab @code{SMUL @var{a},@var{b},@var{c}} | |
9107 | @item @code{sw1 __SUBSS (sw1, sw1)} | |
9108 | @tab @code{@var{c} = __SUBSS (@var{a}, @var{b})} | |
9109 | @tab @code{SUBSS @var{a},@var{b},@var{c}} | |
9110 | @item @code{uw2 __UMUL (uw1, uw1)} | |
9111 | @tab @code{@var{c} = __UMUL (@var{a}, @var{b})} | |
9112 | @tab @code{UMUL @var{a},@var{b},@var{c}} | |
9113 | @end multitable | |
9114 | ||
9115 | @node Directly-mapped Media Functions | |
9116 | @subsubsection Directly-mapped Media Functions | |
9117 | ||
9118 | The functions listed below map directly to FR-V M-type instructions. | |
9119 | ||
9120 | @multitable @columnfractions .45 .32 .23 | |
9121 | @item Function prototype @tab Example usage @tab Assembly output | |
9122 | @item @code{uw1 __MABSHS (sw1)} | |
9123 | @tab @code{@var{b} = __MABSHS (@var{a})} | |
9124 | @tab @code{MABSHS @var{a},@var{b}} | |
9125 | @item @code{void __MADDACCS (acc, acc)} | |
9126 | @tab @code{__MADDACCS (@var{b}, @var{a})} | |
9127 | @tab @code{MADDACCS @var{a},@var{b}} | |
9128 | @item @code{sw1 __MADDHSS (sw1, sw1)} | |
9129 | @tab @code{@var{c} = __MADDHSS (@var{a}, @var{b})} | |
9130 | @tab @code{MADDHSS @var{a},@var{b},@var{c}} | |
9131 | @item @code{uw1 __MADDHUS (uw1, uw1)} | |
9132 | @tab @code{@var{c} = __MADDHUS (@var{a}, @var{b})} | |
9133 | @tab @code{MADDHUS @var{a},@var{b},@var{c}} | |
9134 | @item @code{uw1 __MAND (uw1, uw1)} | |
9135 | @tab @code{@var{c} = __MAND (@var{a}, @var{b})} | |
9136 | @tab @code{MAND @var{a},@var{b},@var{c}} | |
9137 | @item @code{void __MASACCS (acc, acc)} | |
9138 | @tab @code{__MASACCS (@var{b}, @var{a})} | |
9139 | @tab @code{MASACCS @var{a},@var{b}} | |
9140 | @item @code{uw1 __MAVEH (uw1, uw1)} | |
9141 | @tab @code{@var{c} = __MAVEH (@var{a}, @var{b})} | |
9142 | @tab @code{MAVEH @var{a},@var{b},@var{c}} | |
9143 | @item @code{uw2 __MBTOH (uw1)} | |
9144 | @tab @code{@var{b} = __MBTOH (@var{a})} | |
9145 | @tab @code{MBTOH @var{a},@var{b}} | |
9146 | @item @code{void __MBTOHE (uw1 *, uw1)} | |
9147 | @tab @code{__MBTOHE (&@var{b}, @var{a})} | |
9148 | @tab @code{MBTOHE @var{a},@var{b}} | |
9149 | @item @code{void __MCLRACC (acc)} | |
9150 | @tab @code{__MCLRACC (@var{a})} | |
9151 | @tab @code{MCLRACC @var{a}} | |
9152 | @item @code{void __MCLRACCA (void)} | |
9153 | @tab @code{__MCLRACCA ()} | |
9154 | @tab @code{MCLRACCA} | |
9155 | @item @code{uw1 __Mcop1 (uw1, uw1)} | |
9156 | @tab @code{@var{c} = __Mcop1 (@var{a}, @var{b})} | |
9157 | @tab @code{Mcop1 @var{a},@var{b},@var{c}} | |
9158 | @item @code{uw1 __Mcop2 (uw1, uw1)} | |
9159 | @tab @code{@var{c} = __Mcop2 (@var{a}, @var{b})} | |
9160 | @tab @code{Mcop2 @var{a},@var{b},@var{c}} | |
9161 | @item @code{uw1 __MCPLHI (uw2, const)} | |
9162 | @tab @code{@var{c} = __MCPLHI (@var{a}, @var{b})} | |
9163 | @tab @code{MCPLHI @var{a},#@var{b},@var{c}} | |
9164 | @item @code{uw1 __MCPLI (uw2, const)} | |
9165 | @tab @code{@var{c} = __MCPLI (@var{a}, @var{b})} | |
9166 | @tab @code{MCPLI @var{a},#@var{b},@var{c}} | |
9167 | @item @code{void __MCPXIS (acc, sw1, sw1)} | |
9168 | @tab @code{__MCPXIS (@var{c}, @var{a}, @var{b})} | |
9169 | @tab @code{MCPXIS @var{a},@var{b},@var{c}} | |
9170 | @item @code{void __MCPXIU (acc, uw1, uw1)} | |
9171 | @tab @code{__MCPXIU (@var{c}, @var{a}, @var{b})} | |
9172 | @tab @code{MCPXIU @var{a},@var{b},@var{c}} | |
9173 | @item @code{void __MCPXRS (acc, sw1, sw1)} | |
9174 | @tab @code{__MCPXRS (@var{c}, @var{a}, @var{b})} | |
9175 | @tab @code{MCPXRS @var{a},@var{b},@var{c}} | |
9176 | @item @code{void __MCPXRU (acc, uw1, uw1)} | |
9177 | @tab @code{__MCPXRU (@var{c}, @var{a}, @var{b})} | |
9178 | @tab @code{MCPXRU @var{a},@var{b},@var{c}} | |
9179 | @item @code{uw1 __MCUT (acc, uw1)} | |
9180 | @tab @code{@var{c} = __MCUT (@var{a}, @var{b})} | |
9181 | @tab @code{MCUT @var{a},@var{b},@var{c}} | |
9182 | @item @code{uw1 __MCUTSS (acc, sw1)} | |
9183 | @tab @code{@var{c} = __MCUTSS (@var{a}, @var{b})} | |
9184 | @tab @code{MCUTSS @var{a},@var{b},@var{c}} | |
9185 | @item @code{void __MDADDACCS (acc, acc)} | |
9186 | @tab @code{__MDADDACCS (@var{b}, @var{a})} | |
9187 | @tab @code{MDADDACCS @var{a},@var{b}} | |
9188 | @item @code{void __MDASACCS (acc, acc)} | |
9189 | @tab @code{__MDASACCS (@var{b}, @var{a})} | |
9190 | @tab @code{MDASACCS @var{a},@var{b}} | |
9191 | @item @code{uw2 __MDCUTSSI (acc, const)} | |
9192 | @tab @code{@var{c} = __MDCUTSSI (@var{a}, @var{b})} | |
9193 | @tab @code{MDCUTSSI @var{a},#@var{b},@var{c}} | |
9194 | @item @code{uw2 __MDPACKH (uw2, uw2)} | |
9195 | @tab @code{@var{c} = __MDPACKH (@var{a}, @var{b})} | |
9196 | @tab @code{MDPACKH @var{a},@var{b},@var{c}} | |
9197 | @item @code{uw2 __MDROTLI (uw2, const)} | |
9198 | @tab @code{@var{c} = __MDROTLI (@var{a}, @var{b})} | |
9199 | @tab @code{MDROTLI @var{a},#@var{b},@var{c}} | |
9200 | @item @code{void __MDSUBACCS (acc, acc)} | |
9201 | @tab @code{__MDSUBACCS (@var{b}, @var{a})} | |
9202 | @tab @code{MDSUBACCS @var{a},@var{b}} | |
9203 | @item @code{void __MDUNPACKH (uw1 *, uw2)} | |
9204 | @tab @code{__MDUNPACKH (&@var{b}, @var{a})} | |
9205 | @tab @code{MDUNPACKH @var{a},@var{b}} | |
9206 | @item @code{uw2 __MEXPDHD (uw1, const)} | |
9207 | @tab @code{@var{c} = __MEXPDHD (@var{a}, @var{b})} | |
9208 | @tab @code{MEXPDHD @var{a},#@var{b},@var{c}} | |
9209 | @item @code{uw1 __MEXPDHW (uw1, const)} | |
9210 | @tab @code{@var{c} = __MEXPDHW (@var{a}, @var{b})} | |
9211 | @tab @code{MEXPDHW @var{a},#@var{b},@var{c}} | |
9212 | @item @code{uw1 __MHDSETH (uw1, const)} | |
9213 | @tab @code{@var{c} = __MHDSETH (@var{a}, @var{b})} | |
9214 | @tab @code{MHDSETH @var{a},#@var{b},@var{c}} | |
9215 | @item @code{sw1 __MHDSETS (const)} | |
9216 | @tab @code{@var{b} = __MHDSETS (@var{a})} | |
9217 | @tab @code{MHDSETS #@var{a},@var{b}} | |
9218 | @item @code{uw1 __MHSETHIH (uw1, const)} | |
9219 | @tab @code{@var{b} = __MHSETHIH (@var{b}, @var{a})} | |
9220 | @tab @code{MHSETHIH #@var{a},@var{b}} | |
9221 | @item @code{sw1 __MHSETHIS (sw1, const)} | |
9222 | @tab @code{@var{b} = __MHSETHIS (@var{b}, @var{a})} | |
9223 | @tab @code{MHSETHIS #@var{a},@var{b}} | |
9224 | @item @code{uw1 __MHSETLOH (uw1, const)} | |
9225 | @tab @code{@var{b} = __MHSETLOH (@var{b}, @var{a})} | |
9226 | @tab @code{MHSETLOH #@var{a},@var{b}} | |
9227 | @item @code{sw1 __MHSETLOS (sw1, const)} | |
9228 | @tab @code{@var{b} = __MHSETLOS (@var{b}, @var{a})} | |
9229 | @tab @code{MHSETLOS #@var{a},@var{b}} | |
9230 | @item @code{uw1 __MHTOB (uw2)} | |
9231 | @tab @code{@var{b} = __MHTOB (@var{a})} | |
9232 | @tab @code{MHTOB @var{a},@var{b}} | |
9233 | @item @code{void __MMACHS (acc, sw1, sw1)} | |
9234 | @tab @code{__MMACHS (@var{c}, @var{a}, @var{b})} | |
9235 | @tab @code{MMACHS @var{a},@var{b},@var{c}} | |
9236 | @item @code{void __MMACHU (acc, uw1, uw1)} | |
9237 | @tab @code{__MMACHU (@var{c}, @var{a}, @var{b})} | |
9238 | @tab @code{MMACHU @var{a},@var{b},@var{c}} | |
9239 | @item @code{void __MMRDHS (acc, sw1, sw1)} | |
9240 | @tab @code{__MMRDHS (@var{c}, @var{a}, @var{b})} | |
9241 | @tab @code{MMRDHS @var{a},@var{b},@var{c}} | |
9242 | @item @code{void __MMRDHU (acc, uw1, uw1)} | |
9243 | @tab @code{__MMRDHU (@var{c}, @var{a}, @var{b})} | |
9244 | @tab @code{MMRDHU @var{a},@var{b},@var{c}} | |
9245 | @item @code{void __MMULHS (acc, sw1, sw1)} | |
9246 | @tab @code{__MMULHS (@var{c}, @var{a}, @var{b})} | |
9247 | @tab @code{MMULHS @var{a},@var{b},@var{c}} | |
9248 | @item @code{void __MMULHU (acc, uw1, uw1)} | |
9249 | @tab @code{__MMULHU (@var{c}, @var{a}, @var{b})} | |
9250 | @tab @code{MMULHU @var{a},@var{b},@var{c}} | |
9251 | @item @code{void __MMULXHS (acc, sw1, sw1)} | |
9252 | @tab @code{__MMULXHS (@var{c}, @var{a}, @var{b})} | |
9253 | @tab @code{MMULXHS @var{a},@var{b},@var{c}} | |
9254 | @item @code{void __MMULXHU (acc, uw1, uw1)} | |
9255 | @tab @code{__MMULXHU (@var{c}, @var{a}, @var{b})} | |
9256 | @tab @code{MMULXHU @var{a},@var{b},@var{c}} | |
9257 | @item @code{uw1 __MNOT (uw1)} | |
9258 | @tab @code{@var{b} = __MNOT (@var{a})} | |
9259 | @tab @code{MNOT @var{a},@var{b}} | |
9260 | @item @code{uw1 __MOR (uw1, uw1)} | |
9261 | @tab @code{@var{c} = __MOR (@var{a}, @var{b})} | |
9262 | @tab @code{MOR @var{a},@var{b},@var{c}} | |
9263 | @item @code{uw1 __MPACKH (uh, uh)} | |
9264 | @tab @code{@var{c} = __MPACKH (@var{a}, @var{b})} | |
9265 | @tab @code{MPACKH @var{a},@var{b},@var{c}} | |
9266 | @item @code{sw2 __MQADDHSS (sw2, sw2)} | |
9267 | @tab @code{@var{c} = __MQADDHSS (@var{a}, @var{b})} | |
9268 | @tab @code{MQADDHSS @var{a},@var{b},@var{c}} | |
9269 | @item @code{uw2 __MQADDHUS (uw2, uw2)} | |
9270 | @tab @code{@var{c} = __MQADDHUS (@var{a}, @var{b})} | |
9271 | @tab @code{MQADDHUS @var{a},@var{b},@var{c}} | |
9272 | @item @code{void __MQCPXIS (acc, sw2, sw2)} | |
9273 | @tab @code{__MQCPXIS (@var{c}, @var{a}, @var{b})} | |
9274 | @tab @code{MQCPXIS @var{a},@var{b},@var{c}} | |
9275 | @item @code{void __MQCPXIU (acc, uw2, uw2)} | |
9276 | @tab @code{__MQCPXIU (@var{c}, @var{a}, @var{b})} | |
9277 | @tab @code{MQCPXIU @var{a},@var{b},@var{c}} | |
9278 | @item @code{void __MQCPXRS (acc, sw2, sw2)} | |
9279 | @tab @code{__MQCPXRS (@var{c}, @var{a}, @var{b})} | |
9280 | @tab @code{MQCPXRS @var{a},@var{b},@var{c}} | |
9281 | @item @code{void __MQCPXRU (acc, uw2, uw2)} | |
9282 | @tab @code{__MQCPXRU (@var{c}, @var{a}, @var{b})} | |
9283 | @tab @code{MQCPXRU @var{a},@var{b},@var{c}} | |
9284 | @item @code{sw2 __MQLCLRHS (sw2, sw2)} | |
9285 | @tab @code{@var{c} = __MQLCLRHS (@var{a}, @var{b})} | |
9286 | @tab @code{MQLCLRHS @var{a},@var{b},@var{c}} | |
9287 | @item @code{sw2 __MQLMTHS (sw2, sw2)} | |
9288 | @tab @code{@var{c} = __MQLMTHS (@var{a}, @var{b})} | |
9289 | @tab @code{MQLMTHS @var{a},@var{b},@var{c}} | |
9290 | @item @code{void __MQMACHS (acc, sw2, sw2)} | |
9291 | @tab @code{__MQMACHS (@var{c}, @var{a}, @var{b})} | |
9292 | @tab @code{MQMACHS @var{a},@var{b},@var{c}} | |
9293 | @item @code{void __MQMACHU (acc, uw2, uw2)} | |
9294 | @tab @code{__MQMACHU (@var{c}, @var{a}, @var{b})} | |
9295 | @tab @code{MQMACHU @var{a},@var{b},@var{c}} | |
9296 | @item @code{void __MQMACXHS (acc, sw2, sw2)} | |
9297 | @tab @code{__MQMACXHS (@var{c}, @var{a}, @var{b})} | |
9298 | @tab @code{MQMACXHS @var{a},@var{b},@var{c}} | |
9299 | @item @code{void __MQMULHS (acc, sw2, sw2)} | |
9300 | @tab @code{__MQMULHS (@var{c}, @var{a}, @var{b})} | |
9301 | @tab @code{MQMULHS @var{a},@var{b},@var{c}} | |
9302 | @item @code{void __MQMULHU (acc, uw2, uw2)} | |
9303 | @tab @code{__MQMULHU (@var{c}, @var{a}, @var{b})} | |
9304 | @tab @code{MQMULHU @var{a},@var{b},@var{c}} | |
9305 | @item @code{void __MQMULXHS (acc, sw2, sw2)} | |
9306 | @tab @code{__MQMULXHS (@var{c}, @var{a}, @var{b})} | |
9307 | @tab @code{MQMULXHS @var{a},@var{b},@var{c}} | |
9308 | @item @code{void __MQMULXHU (acc, uw2, uw2)} | |
9309 | @tab @code{__MQMULXHU (@var{c}, @var{a}, @var{b})} | |
9310 | @tab @code{MQMULXHU @var{a},@var{b},@var{c}} | |
9311 | @item @code{sw2 __MQSATHS (sw2, sw2)} | |
9312 | @tab @code{@var{c} = __MQSATHS (@var{a}, @var{b})} | |
9313 | @tab @code{MQSATHS @var{a},@var{b},@var{c}} | |
9314 | @item @code{uw2 __MQSLLHI (uw2, int)} | |
9315 | @tab @code{@var{c} = __MQSLLHI (@var{a}, @var{b})} | |
9316 | @tab @code{MQSLLHI @var{a},@var{b},@var{c}} | |
9317 | @item @code{sw2 __MQSRAHI (sw2, int)} | |
9318 | @tab @code{@var{c} = __MQSRAHI (@var{a}, @var{b})} | |
9319 | @tab @code{MQSRAHI @var{a},@var{b},@var{c}} | |
9320 | @item @code{sw2 __MQSUBHSS (sw2, sw2)} | |
9321 | @tab @code{@var{c} = __MQSUBHSS (@var{a}, @var{b})} | |
9322 | @tab @code{MQSUBHSS @var{a},@var{b},@var{c}} | |
9323 | @item @code{uw2 __MQSUBHUS (uw2, uw2)} | |
9324 | @tab @code{@var{c} = __MQSUBHUS (@var{a}, @var{b})} | |
9325 | @tab @code{MQSUBHUS @var{a},@var{b},@var{c}} | |
9326 | @item @code{void __MQXMACHS (acc, sw2, sw2)} | |
9327 | @tab @code{__MQXMACHS (@var{c}, @var{a}, @var{b})} | |
9328 | @tab @code{MQXMACHS @var{a},@var{b},@var{c}} | |
9329 | @item @code{void __MQXMACXHS (acc, sw2, sw2)} | |
9330 | @tab @code{__MQXMACXHS (@var{c}, @var{a}, @var{b})} | |
9331 | @tab @code{MQXMACXHS @var{a},@var{b},@var{c}} | |
9332 | @item @code{uw1 __MRDACC (acc)} | |
9333 | @tab @code{@var{b} = __MRDACC (@var{a})} | |
9334 | @tab @code{MRDACC @var{a},@var{b}} | |
9335 | @item @code{uw1 __MRDACCG (acc)} | |
9336 | @tab @code{@var{b} = __MRDACCG (@var{a})} | |
9337 | @tab @code{MRDACCG @var{a},@var{b}} | |
9338 | @item @code{uw1 __MROTLI (uw1, const)} | |
9339 | @tab @code{@var{c} = __MROTLI (@var{a}, @var{b})} | |
9340 | @tab @code{MROTLI @var{a},#@var{b},@var{c}} | |
9341 | @item @code{uw1 __MROTRI (uw1, const)} | |
9342 | @tab @code{@var{c} = __MROTRI (@var{a}, @var{b})} | |
9343 | @tab @code{MROTRI @var{a},#@var{b},@var{c}} | |
9344 | @item @code{sw1 __MSATHS (sw1, sw1)} | |
9345 | @tab @code{@var{c} = __MSATHS (@var{a}, @var{b})} | |
9346 | @tab @code{MSATHS @var{a},@var{b},@var{c}} | |
9347 | @item @code{uw1 __MSATHU (uw1, uw1)} | |
9348 | @tab @code{@var{c} = __MSATHU (@var{a}, @var{b})} | |
9349 | @tab @code{MSATHU @var{a},@var{b},@var{c}} | |
9350 | @item @code{uw1 __MSLLHI (uw1, const)} | |
9351 | @tab @code{@var{c} = __MSLLHI (@var{a}, @var{b})} | |
9352 | @tab @code{MSLLHI @var{a},#@var{b},@var{c}} | |
9353 | @item @code{sw1 __MSRAHI (sw1, const)} | |
9354 | @tab @code{@var{c} = __MSRAHI (@var{a}, @var{b})} | |
9355 | @tab @code{MSRAHI @var{a},#@var{b},@var{c}} | |
9356 | @item @code{uw1 __MSRLHI (uw1, const)} | |
9357 | @tab @code{@var{c} = __MSRLHI (@var{a}, @var{b})} | |
9358 | @tab @code{MSRLHI @var{a},#@var{b},@var{c}} | |
9359 | @item @code{void __MSUBACCS (acc, acc)} | |
9360 | @tab @code{__MSUBACCS (@var{b}, @var{a})} | |
9361 | @tab @code{MSUBACCS @var{a},@var{b}} | |
9362 | @item @code{sw1 __MSUBHSS (sw1, sw1)} | |
9363 | @tab @code{@var{c} = __MSUBHSS (@var{a}, @var{b})} | |
9364 | @tab @code{MSUBHSS @var{a},@var{b},@var{c}} | |
9365 | @item @code{uw1 __MSUBHUS (uw1, uw1)} | |
9366 | @tab @code{@var{c} = __MSUBHUS (@var{a}, @var{b})} | |
9367 | @tab @code{MSUBHUS @var{a},@var{b},@var{c}} | |
9368 | @item @code{void __MTRAP (void)} | |
9369 | @tab @code{__MTRAP ()} | |
9370 | @tab @code{MTRAP} | |
9371 | @item @code{uw2 __MUNPACKH (uw1)} | |
9372 | @tab @code{@var{b} = __MUNPACKH (@var{a})} | |
9373 | @tab @code{MUNPACKH @var{a},@var{b}} | |
9374 | @item @code{uw1 __MWCUT (uw2, uw1)} | |
9375 | @tab @code{@var{c} = __MWCUT (@var{a}, @var{b})} | |
9376 | @tab @code{MWCUT @var{a},@var{b},@var{c}} | |
9377 | @item @code{void __MWTACC (acc, uw1)} | |
9378 | @tab @code{__MWTACC (@var{b}, @var{a})} | |
9379 | @tab @code{MWTACC @var{a},@var{b}} | |
9380 | @item @code{void __MWTACCG (acc, uw1)} | |
9381 | @tab @code{__MWTACCG (@var{b}, @var{a})} | |
9382 | @tab @code{MWTACCG @var{a},@var{b}} | |
9383 | @item @code{uw1 __MXOR (uw1, uw1)} | |
9384 | @tab @code{@var{c} = __MXOR (@var{a}, @var{b})} | |
9385 | @tab @code{MXOR @var{a},@var{b},@var{c}} | |
9386 | @end multitable | |
9387 | ||
9f3b67fe | 9388 | @node Raw read/write Functions |
9389 | @subsubsection Raw read/write Functions | |
9390 | ||
9391 | This sections describes built-in functions related to read and write | |
9392 | instructions to access memory. These functions generate | |
9393 | @code{membar} instructions to flush the I/O load and stores where | |
9394 | appropriate, as described in Fujitsu's manual described above. | |
9395 | ||
9396 | @table @code | |
9397 | ||
9398 | @item unsigned char __builtin_read8 (void *@var{data}) | |
9399 | @item unsigned short __builtin_read16 (void *@var{data}) | |
9400 | @item unsigned long __builtin_read32 (void *@var{data}) | |
9401 | @item unsigned long long __builtin_read64 (void *@var{data}) | |
9402 | ||
9403 | @item void __builtin_write8 (void *@var{data}, unsigned char @var{datum}) | |
9404 | @item void __builtin_write16 (void *@var{data}, unsigned short @var{datum}) | |
9405 | @item void __builtin_write32 (void *@var{data}, unsigned long @var{datum}) | |
9406 | @item void __builtin_write64 (void *@var{data}, unsigned long long @var{datum}) | |
9407 | @end table | |
9408 | ||
8001abc8 | 9409 | @node Other Built-in Functions |
9410 | @subsubsection Other Built-in Functions | |
9411 | ||
9412 | This section describes built-in functions that are not named after | |
9413 | a specific FR-V instruction. | |
9414 | ||
9415 | @table @code | |
9416 | @item sw2 __IACCreadll (iacc @var{reg}) | |
9417 | Return the full 64-bit value of IACC0@. The @var{reg} argument is reserved | |
9418 | for future expansion and must be 0. | |
9419 | ||
9420 | @item sw1 __IACCreadl (iacc @var{reg}) | |
9421 | Return the value of IACC0H if @var{reg} is 0 and IACC0L if @var{reg} is 1. | |
9422 | Other values of @var{reg} are rejected as invalid. | |
9423 | ||
9424 | @item void __IACCsetll (iacc @var{reg}, sw2 @var{x}) | |
9425 | Set the full 64-bit value of IACC0 to @var{x}. The @var{reg} argument | |
9426 | is reserved for future expansion and must be 0. | |
9427 | ||
9428 | @item void __IACCsetl (iacc @var{reg}, sw1 @var{x}) | |
9429 | Set IACC0H to @var{x} if @var{reg} is 0 and IACC0L to @var{x} if @var{reg} | |
9430 | is 1. Other values of @var{reg} are rejected as invalid. | |
9431 | ||
9432 | @item void __data_prefetch0 (const void *@var{x}) | |
9433 | Use the @code{dcpl} instruction to load the contents of address @var{x} | |
9434 | into the data cache. | |
9435 | ||
9436 | @item void __data_prefetch (const void *@var{x}) | |
9437 | Use the @code{nldub} instruction to load the contents of address @var{x} | |
9438 | into the data cache. The instruction will be issued in slot I1@. | |
9439 | @end table | |
9440 | ||
ca5827cf | 9441 | @node X86 Built-in Functions |
9442 | @subsection X86 Built-in Functions | |
9443 | ||
9444 | These built-in functions are available for the i386 and x86-64 family | |
9445 | of computers, depending on the command-line switches used. | |
9446 | ||
0e6c8ad0 | 9447 | Note that, if you specify command-line switches such as @option{-msse}, |
9448 | the compiler could use the extended instruction sets even if the built-ins | |
9449 | are not used explicitly in the program. For this reason, applications | |
9450 | which perform runtime CPU detection must compile separate files for each | |
9451 | supported architecture, using the appropriate flags. In particular, | |
9452 | the file containing the CPU detection code should be compiled without | |
9453 | these options. | |
9454 | ||
ca5827cf | 9455 | The following machine modes are available for use with MMX built-in functions |
0ae4308e | 9456 | (@pxref{Vector Extensions}): @code{V2SI} for a vector of two 32-bit integers, |
9457 | @code{V4HI} for a vector of four 16-bit integers, and @code{V8QI} for a | |
9458 | vector of eight 8-bit integers. Some of the built-in functions operate on | |
5b2ddfe1 | 9459 | MMX registers as a whole 64-bit entity, these use @code{V1DI} as their mode. |
ca5827cf | 9460 | |
4f0fcaad | 9461 | If 3DNow!@: extensions are enabled, @code{V2SF} is used as a mode for a vector |
0ae4308e | 9462 | of two 32-bit floating point values. |
ca5827cf | 9463 | |
0ae4308e | 9464 | If SSE extensions are enabled, @code{V4SF} is used for a vector of four 32-bit |
9465 | floating point values. Some instructions use a vector of four 32-bit | |
ca5827cf | 9466 | integers, these use @code{V4SI}. Finally, some instructions operate on an |
0ae4308e | 9467 | entire vector register, interpreting it as a 128-bit integer, these use mode |
ca5827cf | 9468 | @code{TI}. |
9469 | ||
957fb083 | 9470 | In 64-bit mode, the x86-64 family of processors uses additional built-in |
c902c5c2 | 9471 | functions for efficient use of @code{TF} (@code{__float128}) 128-bit |
9472 | floating point and @code{TC} 128-bit complex floating point values. | |
9473 | ||
957fb083 | 9474 | The following floating point built-in functions are available in 64-bit |
9475 | mode. All of them implement the function that is part of the name. | |
c902c5c2 | 9476 | |
9477 | @smallexample | |
9478 | __float128 __builtin_fabsq (__float128) | |
9479 | __float128 __builtin_copysignq (__float128, __float128) | |
9480 | @end smallexample | |
9481 | ||
1c0d1529 | 9482 | The following built-in function is always available. |
9483 | ||
9484 | @table @code | |
9485 | @item void __builtin_ia32_pause (void) | |
4d7a5fd9 | 9486 | Generates the @code{pause} machine instruction with a compiler memory |
9487 | barrier. | |
1c0d1529 | 9488 | @end table |
9489 | ||
c902c5c2 | 9490 | The following floating point built-in functions are made available in the |
9491 | 64-bit mode. | |
9492 | ||
9493 | @table @code | |
9494 | @item __float128 __builtin_infq (void) | |
9495 | Similar to @code{__builtin_inf}, except the return type is @code{__float128}. | |
29c63a97 | 9496 | @findex __builtin_infq |
9497 | ||
9498 | @item __float128 __builtin_huge_valq (void) | |
9499 | Similar to @code{__builtin_huge_val}, except the return type is @code{__float128}. | |
9500 | @findex __builtin_huge_valq | |
c902c5c2 | 9501 | @end table |
9502 | ||
f0fd108f | 9503 | The following built-in functions are always available and can be used to |
9504 | check the target platform type. | |
9505 | ||
9506 | @deftypefn {Built-in Function} void __builtin_cpu_init (void) | |
9507 | This function runs the CPU detection code to check the type of CPU and the | |
9508 | features supported. This builtin needs to be invoked along with the builtins | |
9509 | to check CPU type and features, @code{__builtin_cpu_is} and | |
9510 | @code{__builtin_cpu_supports}, only when used in a function that will be | |
9511 | executed before any constructors are called. The CPU detection code is | |
9512 | automatically executed in a very high priority constructor. | |
9513 | ||
9514 | For example, this function has to be used in @code{ifunc} resolvers which | |
98c9b52b | 9515 | check for CPU type using the builtins @code{__builtin_cpu_is} |
9516 | and @code{__builtin_cpu_supports}, or in constructors on targets which | |
9517 | don't support constructor priority. | |
f0fd108f | 9518 | @smallexample |
9519 | ||
9520 | static void (*resolve_memcpy (void)) (void) | |
9521 | @{ | |
9522 | // ifunc resolvers fire before constructors, explicitly call the init | |
9523 | // function. | |
9524 | __builtin_cpu_init (); | |
9525 | if (__builtin_cpu_supports ("ssse3")) | |
9526 | return ssse3_memcpy; // super fast memcpy with ssse3 instructions. | |
9527 | else | |
9528 | return default_memcpy; | |
9529 | @} | |
9530 | ||
9531 | void *memcpy (void *, const void *, size_t) | |
9532 | __attribute__ ((ifunc ("resolve_memcpy"))); | |
9533 | @end smallexample | |
9534 | ||
9535 | @end deftypefn | |
9536 | ||
9537 | @deftypefn {Built-in Function} int __builtin_cpu_is (const char *@var{cpuname}) | |
9538 | This function returns a positive integer if the runtime cpu is of type @var{cpuname} | |
9539 | and returns @code{0} otherwise. The following cpu names can be detected: | |
9540 | ||
9541 | @table @samp | |
9542 | @item intel | |
9543 | Intel CPU. | |
9544 | ||
9545 | @item atom | |
9546 | Intel ATOM CPU. | |
9547 | ||
9548 | @item core2 | |
9549 | Intel Core2 CPU. | |
9550 | ||
9551 | @item corei7 | |
9552 | Intel Corei7 CPU. | |
9553 | ||
9554 | @item nehalem | |
9555 | Intel Corei7 Nehalem CPU. | |
9556 | ||
9557 | @item westmere | |
9558 | Intel Corei7 Westmere CPU. | |
9559 | ||
9560 | @item sandybridge | |
9561 | Intel Corei7 Sandybridge CPU. | |
9562 | ||
9563 | @item amd | |
9564 | AMD CPU. | |
9565 | ||
9566 | @item amdfam10h | |
9567 | AMD family 10h CPU. | |
9568 | ||
9569 | @item barcelona | |
9570 | AMD family 10h Barcelona CPU. | |
9571 | ||
9572 | @item shanghai | |
9573 | AMD family 10h Shanghai CPU. | |
9574 | ||
9575 | @item istanbul | |
9576 | AMD family 10h Istanbul CPU. | |
9577 | ||
6ef15b76 | 9578 | @item btver1 |
9579 | AMD family 14h CPU. | |
9580 | ||
f0fd108f | 9581 | @item amdfam15h |
9582 | AMD family 15h CPU. | |
9583 | ||
9584 | @item bdver1 | |
9585 | AMD family 15h Bulldozer version 1. | |
9586 | ||
9587 | @item bdver2 | |
9588 | AMD family 15h Bulldozer version 2. | |
6ef15b76 | 9589 | |
9590 | @item btver2 | |
9591 | AMD family 16h CPU. | |
f0fd108f | 9592 | @end table |
9593 | ||
9594 | Here is an example: | |
9595 | @smallexample | |
9596 | if (__builtin_cpu_is ("corei7")) | |
9597 | @{ | |
9598 | do_corei7 (); //Corei7 specific implementation. | |
9599 | @} | |
9600 | else | |
9601 | @{ | |
9602 | do_generic (); //Generic implementation. | |
9603 | @} | |
9604 | @end smallexample | |
9605 | @end deftypefn | |
9606 | ||
9607 | @deftypefn {Built-in Function} int __builtin_cpu_supports (const char *@var{feature}) | |
9d75589a | 9608 | This function returns a positive integer if the runtime cpu supports @var{feature} |
f0fd108f | 9609 | and returns @code{0} otherwise. The following features can be detected: |
9610 | ||
9611 | @table @samp | |
9612 | @item cmov | |
9613 | CMOV instruction. | |
9614 | @item mmx | |
9615 | MMX instructions. | |
9616 | @item popcnt | |
9617 | POPCNT instruction. | |
9618 | @item sse | |
9619 | SSE instructions. | |
9620 | @item sse2 | |
9621 | SSE2 instructions. | |
9622 | @item sse3 | |
9623 | SSE3 instructions. | |
9624 | @item ssse3 | |
9625 | SSSE3 instructions. | |
9626 | @item sse4.1 | |
9627 | SSE4.1 instructions. | |
9628 | @item sse4.2 | |
9629 | SSE4.2 instructions. | |
9630 | @item avx | |
9631 | AVX instructions. | |
d79cfc15 | 9632 | @item avx2 |
9633 | AVX2 instructions. | |
f0fd108f | 9634 | @end table |
9635 | ||
9636 | Here is an example: | |
9637 | @smallexample | |
9638 | if (__builtin_cpu_supports ("popcnt")) | |
9639 | @{ | |
9640 | asm("popcnt %1,%0" : "=r"(count) : "rm"(n) : "cc"); | |
9641 | @} | |
9642 | else | |
9643 | @{ | |
9644 | count = generic_countbits (n); //generic implementation. | |
9645 | @} | |
9646 | @end smallexample | |
9647 | @end deftypefn | |
9648 | ||
9649 | ||
ca5827cf | 9650 | The following built-in functions are made available by @option{-mmmx}. |
9651 | All of them generate the machine instruction that is part of the name. | |
9652 | ||
a0ecd6b1 | 9653 | @smallexample |
ca5827cf | 9654 | v8qi __builtin_ia32_paddb (v8qi, v8qi) |
9655 | v4hi __builtin_ia32_paddw (v4hi, v4hi) | |
9656 | v2si __builtin_ia32_paddd (v2si, v2si) | |
9657 | v8qi __builtin_ia32_psubb (v8qi, v8qi) | |
9658 | v4hi __builtin_ia32_psubw (v4hi, v4hi) | |
9659 | v2si __builtin_ia32_psubd (v2si, v2si) | |
9660 | v8qi __builtin_ia32_paddsb (v8qi, v8qi) | |
9661 | v4hi __builtin_ia32_paddsw (v4hi, v4hi) | |
9662 | v8qi __builtin_ia32_psubsb (v8qi, v8qi) | |
9663 | v4hi __builtin_ia32_psubsw (v4hi, v4hi) | |
9664 | v8qi __builtin_ia32_paddusb (v8qi, v8qi) | |
9665 | v4hi __builtin_ia32_paddusw (v4hi, v4hi) | |
9666 | v8qi __builtin_ia32_psubusb (v8qi, v8qi) | |
9667 | v4hi __builtin_ia32_psubusw (v4hi, v4hi) | |
9668 | v4hi __builtin_ia32_pmullw (v4hi, v4hi) | |
9669 | v4hi __builtin_ia32_pmulhw (v4hi, v4hi) | |
9670 | di __builtin_ia32_pand (di, di) | |
9671 | di __builtin_ia32_pandn (di,di) | |
9672 | di __builtin_ia32_por (di, di) | |
9673 | di __builtin_ia32_pxor (di, di) | |
9674 | v8qi __builtin_ia32_pcmpeqb (v8qi, v8qi) | |
9675 | v4hi __builtin_ia32_pcmpeqw (v4hi, v4hi) | |
9676 | v2si __builtin_ia32_pcmpeqd (v2si, v2si) | |
9677 | v8qi __builtin_ia32_pcmpgtb (v8qi, v8qi) | |
9678 | v4hi __builtin_ia32_pcmpgtw (v4hi, v4hi) | |
9679 | v2si __builtin_ia32_pcmpgtd (v2si, v2si) | |
9680 | v8qi __builtin_ia32_punpckhbw (v8qi, v8qi) | |
9681 | v4hi __builtin_ia32_punpckhwd (v4hi, v4hi) | |
9682 | v2si __builtin_ia32_punpckhdq (v2si, v2si) | |
9683 | v8qi __builtin_ia32_punpcklbw (v8qi, v8qi) | |
9684 | v4hi __builtin_ia32_punpcklwd (v4hi, v4hi) | |
9685 | v2si __builtin_ia32_punpckldq (v2si, v2si) | |
9686 | v8qi __builtin_ia32_packsswb (v4hi, v4hi) | |
9687 | v4hi __builtin_ia32_packssdw (v2si, v2si) | |
9688 | v8qi __builtin_ia32_packuswb (v4hi, v4hi) | |
7916ca8a | 9689 | |
c9f96750 | 9690 | v4hi __builtin_ia32_psllw (v4hi, v4hi) |
9691 | v2si __builtin_ia32_pslld (v2si, v2si) | |
9692 | v1di __builtin_ia32_psllq (v1di, v1di) | |
9693 | v4hi __builtin_ia32_psrlw (v4hi, v4hi) | |
9694 | v2si __builtin_ia32_psrld (v2si, v2si) | |
9695 | v1di __builtin_ia32_psrlq (v1di, v1di) | |
9696 | v4hi __builtin_ia32_psraw (v4hi, v4hi) | |
9697 | v2si __builtin_ia32_psrad (v2si, v2si) | |
9698 | v4hi __builtin_ia32_psllwi (v4hi, int) | |
9699 | v2si __builtin_ia32_pslldi (v2si, int) | |
9700 | v1di __builtin_ia32_psllqi (v1di, int) | |
9701 | v4hi __builtin_ia32_psrlwi (v4hi, int) | |
9702 | v2si __builtin_ia32_psrldi (v2si, int) | |
9703 | v1di __builtin_ia32_psrlqi (v1di, int) | |
9704 | v4hi __builtin_ia32_psrawi (v4hi, int) | |
9705 | v2si __builtin_ia32_psradi (v2si, int) | |
7916ca8a | 9706 | |
a0ecd6b1 | 9707 | @end smallexample |
ca5827cf | 9708 | |
9709 | The following built-in functions are made available either with | |
9710 | @option{-msse}, or with a combination of @option{-m3dnow} and | |
9711 | @option{-march=athlon}. All of them generate the machine | |
9712 | instruction that is part of the name. | |
9713 | ||
a0ecd6b1 | 9714 | @smallexample |
ca5827cf | 9715 | v4hi __builtin_ia32_pmulhuw (v4hi, v4hi) |
9716 | v8qi __builtin_ia32_pavgb (v8qi, v8qi) | |
9717 | v4hi __builtin_ia32_pavgw (v4hi, v4hi) | |
28a2ab9f | 9718 | v1di __builtin_ia32_psadbw (v8qi, v8qi) |
ca5827cf | 9719 | v8qi __builtin_ia32_pmaxub (v8qi, v8qi) |
9720 | v4hi __builtin_ia32_pmaxsw (v4hi, v4hi) | |
9721 | v8qi __builtin_ia32_pminub (v8qi, v8qi) | |
9722 | v4hi __builtin_ia32_pminsw (v4hi, v4hi) | |
9723 | int __builtin_ia32_pextrw (v4hi, int) | |
9724 | v4hi __builtin_ia32_pinsrw (v4hi, int, int) | |
9725 | int __builtin_ia32_pmovmskb (v8qi) | |
9726 | void __builtin_ia32_maskmovq (v8qi, v8qi, char *) | |
9727 | void __builtin_ia32_movntq (di *, di) | |
9728 | void __builtin_ia32_sfence (void) | |
a0ecd6b1 | 9729 | @end smallexample |
ca5827cf | 9730 | |
9731 | The following built-in functions are available when @option{-msse} is used. | |
9732 | All of them generate the machine instruction that is part of the name. | |
9733 | ||
a0ecd6b1 | 9734 | @smallexample |
ca5827cf | 9735 | int __builtin_ia32_comieq (v4sf, v4sf) |
9736 | int __builtin_ia32_comineq (v4sf, v4sf) | |
9737 | int __builtin_ia32_comilt (v4sf, v4sf) | |
9738 | int __builtin_ia32_comile (v4sf, v4sf) | |
9739 | int __builtin_ia32_comigt (v4sf, v4sf) | |
9740 | int __builtin_ia32_comige (v4sf, v4sf) | |
9741 | int __builtin_ia32_ucomieq (v4sf, v4sf) | |
9742 | int __builtin_ia32_ucomineq (v4sf, v4sf) | |
9743 | int __builtin_ia32_ucomilt (v4sf, v4sf) | |
9744 | int __builtin_ia32_ucomile (v4sf, v4sf) | |
9745 | int __builtin_ia32_ucomigt (v4sf, v4sf) | |
9746 | int __builtin_ia32_ucomige (v4sf, v4sf) | |
9747 | v4sf __builtin_ia32_addps (v4sf, v4sf) | |
9748 | v4sf __builtin_ia32_subps (v4sf, v4sf) | |
9749 | v4sf __builtin_ia32_mulps (v4sf, v4sf) | |
9750 | v4sf __builtin_ia32_divps (v4sf, v4sf) | |
9751 | v4sf __builtin_ia32_addss (v4sf, v4sf) | |
9752 | v4sf __builtin_ia32_subss (v4sf, v4sf) | |
9753 | v4sf __builtin_ia32_mulss (v4sf, v4sf) | |
9754 | v4sf __builtin_ia32_divss (v4sf, v4sf) | |
9755 | v4si __builtin_ia32_cmpeqps (v4sf, v4sf) | |
9756 | v4si __builtin_ia32_cmpltps (v4sf, v4sf) | |
9757 | v4si __builtin_ia32_cmpleps (v4sf, v4sf) | |
9758 | v4si __builtin_ia32_cmpgtps (v4sf, v4sf) | |
9759 | v4si __builtin_ia32_cmpgeps (v4sf, v4sf) | |
9760 | v4si __builtin_ia32_cmpunordps (v4sf, v4sf) | |
9761 | v4si __builtin_ia32_cmpneqps (v4sf, v4sf) | |
9762 | v4si __builtin_ia32_cmpnltps (v4sf, v4sf) | |
9763 | v4si __builtin_ia32_cmpnleps (v4sf, v4sf) | |
9764 | v4si __builtin_ia32_cmpngtps (v4sf, v4sf) | |
9765 | v4si __builtin_ia32_cmpngeps (v4sf, v4sf) | |
9766 | v4si __builtin_ia32_cmpordps (v4sf, v4sf) | |
9767 | v4si __builtin_ia32_cmpeqss (v4sf, v4sf) | |
9768 | v4si __builtin_ia32_cmpltss (v4sf, v4sf) | |
9769 | v4si __builtin_ia32_cmpless (v4sf, v4sf) | |
ca5827cf | 9770 | v4si __builtin_ia32_cmpunordss (v4sf, v4sf) |
9771 | v4si __builtin_ia32_cmpneqss (v4sf, v4sf) | |
9772 | v4si __builtin_ia32_cmpnlts (v4sf, v4sf) | |
9773 | v4si __builtin_ia32_cmpnless (v4sf, v4sf) | |
ca5827cf | 9774 | v4si __builtin_ia32_cmpordss (v4sf, v4sf) |
9775 | v4sf __builtin_ia32_maxps (v4sf, v4sf) | |
9776 | v4sf __builtin_ia32_maxss (v4sf, v4sf) | |
9777 | v4sf __builtin_ia32_minps (v4sf, v4sf) | |
9778 | v4sf __builtin_ia32_minss (v4sf, v4sf) | |
9779 | v4sf __builtin_ia32_andps (v4sf, v4sf) | |
9780 | v4sf __builtin_ia32_andnps (v4sf, v4sf) | |
9781 | v4sf __builtin_ia32_orps (v4sf, v4sf) | |
9782 | v4sf __builtin_ia32_xorps (v4sf, v4sf) | |
9783 | v4sf __builtin_ia32_movss (v4sf, v4sf) | |
9784 | v4sf __builtin_ia32_movhlps (v4sf, v4sf) | |
9785 | v4sf __builtin_ia32_movlhps (v4sf, v4sf) | |
9786 | v4sf __builtin_ia32_unpckhps (v4sf, v4sf) | |
9787 | v4sf __builtin_ia32_unpcklps (v4sf, v4sf) | |
9788 | v4sf __builtin_ia32_cvtpi2ps (v4sf, v2si) | |
9789 | v4sf __builtin_ia32_cvtsi2ss (v4sf, int) | |
9790 | v2si __builtin_ia32_cvtps2pi (v4sf) | |
9791 | int __builtin_ia32_cvtss2si (v4sf) | |
9792 | v2si __builtin_ia32_cvttps2pi (v4sf) | |
9793 | int __builtin_ia32_cvttss2si (v4sf) | |
9794 | v4sf __builtin_ia32_rcpps (v4sf) | |
9795 | v4sf __builtin_ia32_rsqrtps (v4sf) | |
9796 | v4sf __builtin_ia32_sqrtps (v4sf) | |
9797 | v4sf __builtin_ia32_rcpss (v4sf) | |
9798 | v4sf __builtin_ia32_rsqrtss (v4sf) | |
9799 | v4sf __builtin_ia32_sqrtss (v4sf) | |
9800 | v4sf __builtin_ia32_shufps (v4sf, v4sf, int) | |
9801 | void __builtin_ia32_movntps (float *, v4sf) | |
9802 | int __builtin_ia32_movmskps (v4sf) | |
a0ecd6b1 | 9803 | @end smallexample |
ca5827cf | 9804 | |
9805 | The following built-in functions are available when @option{-msse} is used. | |
9806 | ||
9807 | @table @code | |
9808 | @item v4sf __builtin_ia32_loadaps (float *) | |
9809 | Generates the @code{movaps} machine instruction as a load from memory. | |
9810 | @item void __builtin_ia32_storeaps (float *, v4sf) | |
9811 | Generates the @code{movaps} machine instruction as a store to memory. | |
9812 | @item v4sf __builtin_ia32_loadups (float *) | |
9813 | Generates the @code{movups} machine instruction as a load from memory. | |
9814 | @item void __builtin_ia32_storeups (float *, v4sf) | |
9815 | Generates the @code{movups} machine instruction as a store to memory. | |
9816 | @item v4sf __builtin_ia32_loadsss (float *) | |
9817 | Generates the @code{movss} machine instruction as a load from memory. | |
9818 | @item void __builtin_ia32_storess (float *, v4sf) | |
9819 | Generates the @code{movss} machine instruction as a store to memory. | |
875a66b2 | 9820 | @item v4sf __builtin_ia32_loadhps (v4sf, const v2sf *) |
ca5827cf | 9821 | Generates the @code{movhps} machine instruction as a load from memory. |
875a66b2 | 9822 | @item v4sf __builtin_ia32_loadlps (v4sf, const v2sf *) |
ca5827cf | 9823 | Generates the @code{movlps} machine instruction as a load from memory |
875a66b2 | 9824 | @item void __builtin_ia32_storehps (v2sf *, v4sf) |
ca5827cf | 9825 | Generates the @code{movhps} machine instruction as a store to memory. |
875a66b2 | 9826 | @item void __builtin_ia32_storelps (v2sf *, v4sf) |
ca5827cf | 9827 | Generates the @code{movlps} machine instruction as a store to memory. |
9828 | @end table | |
9829 | ||
e2d5ef68 | 9830 | The following built-in functions are available when @option{-msse2} is used. |
9831 | All of them generate the machine instruction that is part of the name. | |
9832 | ||
9833 | @smallexample | |
9834 | int __builtin_ia32_comisdeq (v2df, v2df) | |
9835 | int __builtin_ia32_comisdlt (v2df, v2df) | |
9836 | int __builtin_ia32_comisdle (v2df, v2df) | |
9837 | int __builtin_ia32_comisdgt (v2df, v2df) | |
9838 | int __builtin_ia32_comisdge (v2df, v2df) | |
9839 | int __builtin_ia32_comisdneq (v2df, v2df) | |
9840 | int __builtin_ia32_ucomisdeq (v2df, v2df) | |
9841 | int __builtin_ia32_ucomisdlt (v2df, v2df) | |
9842 | int __builtin_ia32_ucomisdle (v2df, v2df) | |
9843 | int __builtin_ia32_ucomisdgt (v2df, v2df) | |
9844 | int __builtin_ia32_ucomisdge (v2df, v2df) | |
9845 | int __builtin_ia32_ucomisdneq (v2df, v2df) | |
9846 | v2df __builtin_ia32_cmpeqpd (v2df, v2df) | |
9847 | v2df __builtin_ia32_cmpltpd (v2df, v2df) | |
9848 | v2df __builtin_ia32_cmplepd (v2df, v2df) | |
9849 | v2df __builtin_ia32_cmpgtpd (v2df, v2df) | |
9850 | v2df __builtin_ia32_cmpgepd (v2df, v2df) | |
9851 | v2df __builtin_ia32_cmpunordpd (v2df, v2df) | |
9852 | v2df __builtin_ia32_cmpneqpd (v2df, v2df) | |
9853 | v2df __builtin_ia32_cmpnltpd (v2df, v2df) | |
9854 | v2df __builtin_ia32_cmpnlepd (v2df, v2df) | |
9855 | v2df __builtin_ia32_cmpngtpd (v2df, v2df) | |
9856 | v2df __builtin_ia32_cmpngepd (v2df, v2df) | |
9857 | v2df __builtin_ia32_cmpordpd (v2df, v2df) | |
9858 | v2df __builtin_ia32_cmpeqsd (v2df, v2df) | |
9859 | v2df __builtin_ia32_cmpltsd (v2df, v2df) | |
9860 | v2df __builtin_ia32_cmplesd (v2df, v2df) | |
9861 | v2df __builtin_ia32_cmpunordsd (v2df, v2df) | |
9862 | v2df __builtin_ia32_cmpneqsd (v2df, v2df) | |
9863 | v2df __builtin_ia32_cmpnltsd (v2df, v2df) | |
9864 | v2df __builtin_ia32_cmpnlesd (v2df, v2df) | |
9865 | v2df __builtin_ia32_cmpordsd (v2df, v2df) | |
9866 | v2di __builtin_ia32_paddq (v2di, v2di) | |
9867 | v2di __builtin_ia32_psubq (v2di, v2di) | |
9868 | v2df __builtin_ia32_addpd (v2df, v2df) | |
9869 | v2df __builtin_ia32_subpd (v2df, v2df) | |
9870 | v2df __builtin_ia32_mulpd (v2df, v2df) | |
9871 | v2df __builtin_ia32_divpd (v2df, v2df) | |
9872 | v2df __builtin_ia32_addsd (v2df, v2df) | |
9873 | v2df __builtin_ia32_subsd (v2df, v2df) | |
9874 | v2df __builtin_ia32_mulsd (v2df, v2df) | |
9875 | v2df __builtin_ia32_divsd (v2df, v2df) | |
9876 | v2df __builtin_ia32_minpd (v2df, v2df) | |
9877 | v2df __builtin_ia32_maxpd (v2df, v2df) | |
9878 | v2df __builtin_ia32_minsd (v2df, v2df) | |
9879 | v2df __builtin_ia32_maxsd (v2df, v2df) | |
9880 | v2df __builtin_ia32_andpd (v2df, v2df) | |
9881 | v2df __builtin_ia32_andnpd (v2df, v2df) | |
9882 | v2df __builtin_ia32_orpd (v2df, v2df) | |
9883 | v2df __builtin_ia32_xorpd (v2df, v2df) | |
9884 | v2df __builtin_ia32_movsd (v2df, v2df) | |
9885 | v2df __builtin_ia32_unpckhpd (v2df, v2df) | |
9886 | v2df __builtin_ia32_unpcklpd (v2df, v2df) | |
9887 | v16qi __builtin_ia32_paddb128 (v16qi, v16qi) | |
9888 | v8hi __builtin_ia32_paddw128 (v8hi, v8hi) | |
9889 | v4si __builtin_ia32_paddd128 (v4si, v4si) | |
9890 | v2di __builtin_ia32_paddq128 (v2di, v2di) | |
9891 | v16qi __builtin_ia32_psubb128 (v16qi, v16qi) | |
9892 | v8hi __builtin_ia32_psubw128 (v8hi, v8hi) | |
9893 | v4si __builtin_ia32_psubd128 (v4si, v4si) | |
9894 | v2di __builtin_ia32_psubq128 (v2di, v2di) | |
9895 | v8hi __builtin_ia32_pmullw128 (v8hi, v8hi) | |
9896 | v8hi __builtin_ia32_pmulhw128 (v8hi, v8hi) | |
9897 | v2di __builtin_ia32_pand128 (v2di, v2di) | |
9898 | v2di __builtin_ia32_pandn128 (v2di, v2di) | |
9899 | v2di __builtin_ia32_por128 (v2di, v2di) | |
9900 | v2di __builtin_ia32_pxor128 (v2di, v2di) | |
9901 | v16qi __builtin_ia32_pavgb128 (v16qi, v16qi) | |
9902 | v8hi __builtin_ia32_pavgw128 (v8hi, v8hi) | |
9903 | v16qi __builtin_ia32_pcmpeqb128 (v16qi, v16qi) | |
9904 | v8hi __builtin_ia32_pcmpeqw128 (v8hi, v8hi) | |
9905 | v4si __builtin_ia32_pcmpeqd128 (v4si, v4si) | |
9906 | v16qi __builtin_ia32_pcmpgtb128 (v16qi, v16qi) | |
9907 | v8hi __builtin_ia32_pcmpgtw128 (v8hi, v8hi) | |
9908 | v4si __builtin_ia32_pcmpgtd128 (v4si, v4si) | |
9909 | v16qi __builtin_ia32_pmaxub128 (v16qi, v16qi) | |
9910 | v8hi __builtin_ia32_pmaxsw128 (v8hi, v8hi) | |
9911 | v16qi __builtin_ia32_pminub128 (v16qi, v16qi) | |
9912 | v8hi __builtin_ia32_pminsw128 (v8hi, v8hi) | |
9913 | v16qi __builtin_ia32_punpckhbw128 (v16qi, v16qi) | |
9914 | v8hi __builtin_ia32_punpckhwd128 (v8hi, v8hi) | |
9915 | v4si __builtin_ia32_punpckhdq128 (v4si, v4si) | |
9916 | v2di __builtin_ia32_punpckhqdq128 (v2di, v2di) | |
9917 | v16qi __builtin_ia32_punpcklbw128 (v16qi, v16qi) | |
9918 | v8hi __builtin_ia32_punpcklwd128 (v8hi, v8hi) | |
9919 | v4si __builtin_ia32_punpckldq128 (v4si, v4si) | |
9920 | v2di __builtin_ia32_punpcklqdq128 (v2di, v2di) | |
6f50184d | 9921 | v16qi __builtin_ia32_packsswb128 (v8hi, v8hi) |
9922 | v8hi __builtin_ia32_packssdw128 (v4si, v4si) | |
9923 | v16qi __builtin_ia32_packuswb128 (v8hi, v8hi) | |
e2d5ef68 | 9924 | v8hi __builtin_ia32_pmulhuw128 (v8hi, v8hi) |
9925 | void __builtin_ia32_maskmovdqu (v16qi, v16qi) | |
9926 | v2df __builtin_ia32_loadupd (double *) | |
9927 | void __builtin_ia32_storeupd (double *, v2df) | |
875a66b2 | 9928 | v2df __builtin_ia32_loadhpd (v2df, double const *) |
9929 | v2df __builtin_ia32_loadlpd (v2df, double const *) | |
e2d5ef68 | 9930 | int __builtin_ia32_movmskpd (v2df) |
9931 | int __builtin_ia32_pmovmskb128 (v16qi) | |
9932 | void __builtin_ia32_movnti (int *, int) | |
821b85a2 | 9933 | void __builtin_ia32_movnti64 (long long int *, long long int) |
e2d5ef68 | 9934 | void __builtin_ia32_movntpd (double *, v2df) |
9935 | void __builtin_ia32_movntdq (v2df *, v2df) | |
9936 | v4si __builtin_ia32_pshufd (v4si, int) | |
9937 | v8hi __builtin_ia32_pshuflw (v8hi, int) | |
9938 | v8hi __builtin_ia32_pshufhw (v8hi, int) | |
9939 | v2di __builtin_ia32_psadbw128 (v16qi, v16qi) | |
9940 | v2df __builtin_ia32_sqrtpd (v2df) | |
9941 | v2df __builtin_ia32_sqrtsd (v2df) | |
9942 | v2df __builtin_ia32_shufpd (v2df, v2df, int) | |
9943 | v2df __builtin_ia32_cvtdq2pd (v4si) | |
9944 | v4sf __builtin_ia32_cvtdq2ps (v4si) | |
9945 | v4si __builtin_ia32_cvtpd2dq (v2df) | |
9946 | v2si __builtin_ia32_cvtpd2pi (v2df) | |
9947 | v4sf __builtin_ia32_cvtpd2ps (v2df) | |
9948 | v4si __builtin_ia32_cvttpd2dq (v2df) | |
9949 | v2si __builtin_ia32_cvttpd2pi (v2df) | |
9950 | v2df __builtin_ia32_cvtpi2pd (v2si) | |
9951 | int __builtin_ia32_cvtsd2si (v2df) | |
9952 | int __builtin_ia32_cvttsd2si (v2df) | |
9953 | long long __builtin_ia32_cvtsd2si64 (v2df) | |
9954 | long long __builtin_ia32_cvttsd2si64 (v2df) | |
9955 | v4si __builtin_ia32_cvtps2dq (v4sf) | |
9956 | v2df __builtin_ia32_cvtps2pd (v4sf) | |
9957 | v4si __builtin_ia32_cvttps2dq (v4sf) | |
9958 | v2df __builtin_ia32_cvtsi2sd (v2df, int) | |
9959 | v2df __builtin_ia32_cvtsi642sd (v2df, long long) | |
9960 | v4sf __builtin_ia32_cvtsd2ss (v4sf, v2df) | |
9961 | v2df __builtin_ia32_cvtss2sd (v2df, v4sf) | |
9962 | void __builtin_ia32_clflush (const void *) | |
9963 | void __builtin_ia32_lfence (void) | |
9964 | void __builtin_ia32_mfence (void) | |
9965 | v16qi __builtin_ia32_loaddqu (const char *) | |
9966 | void __builtin_ia32_storedqu (char *, v16qi) | |
28a2ab9f | 9967 | v1di __builtin_ia32_pmuludq (v2si, v2si) |
e2d5ef68 | 9968 | v2di __builtin_ia32_pmuludq128 (v4si, v4si) |
c9f96750 | 9969 | v8hi __builtin_ia32_psllw128 (v8hi, v8hi) |
9970 | v4si __builtin_ia32_pslld128 (v4si, v4si) | |
9971 | v2di __builtin_ia32_psllq128 (v2di, v2di) | |
9972 | v8hi __builtin_ia32_psrlw128 (v8hi, v8hi) | |
9973 | v4si __builtin_ia32_psrld128 (v4si, v4si) | |
e2d5ef68 | 9974 | v2di __builtin_ia32_psrlq128 (v2di, v2di) |
c9f96750 | 9975 | v8hi __builtin_ia32_psraw128 (v8hi, v8hi) |
9976 | v4si __builtin_ia32_psrad128 (v4si, v4si) | |
e2d5ef68 | 9977 | v2di __builtin_ia32_pslldqi128 (v2di, int) |
9978 | v8hi __builtin_ia32_psllwi128 (v8hi, int) | |
9979 | v4si __builtin_ia32_pslldi128 (v4si, int) | |
9980 | v2di __builtin_ia32_psllqi128 (v2di, int) | |
9981 | v2di __builtin_ia32_psrldqi128 (v2di, int) | |
9982 | v8hi __builtin_ia32_psrlwi128 (v8hi, int) | |
9983 | v4si __builtin_ia32_psrldi128 (v4si, int) | |
9984 | v2di __builtin_ia32_psrlqi128 (v2di, int) | |
9985 | v8hi __builtin_ia32_psrawi128 (v8hi, int) | |
9986 | v4si __builtin_ia32_psradi128 (v4si, int) | |
9987 | v4si __builtin_ia32_pmaddwd128 (v8hi, v8hi) | |
c578ed7f | 9988 | v2di __builtin_ia32_movq128 (v2di) |
e2d5ef68 | 9989 | @end smallexample |
9990 | ||
4aafbf22 | 9991 | The following built-in functions are available when @option{-msse3} is used. |
754c06ac | 9992 | All of them generate the machine instruction that is part of the name. |
9993 | ||
a0ecd6b1 | 9994 | @smallexample |
754c06ac | 9995 | v2df __builtin_ia32_addsubpd (v2df, v2df) |
e2d5ef68 | 9996 | v4sf __builtin_ia32_addsubps (v4sf, v4sf) |
754c06ac | 9997 | v2df __builtin_ia32_haddpd (v2df, v2df) |
e2d5ef68 | 9998 | v4sf __builtin_ia32_haddps (v4sf, v4sf) |
754c06ac | 9999 | v2df __builtin_ia32_hsubpd (v2df, v2df) |
e2d5ef68 | 10000 | v4sf __builtin_ia32_hsubps (v4sf, v4sf) |
754c06ac | 10001 | v16qi __builtin_ia32_lddqu (char const *) |
10002 | void __builtin_ia32_monitor (void *, unsigned int, unsigned int) | |
10003 | v2df __builtin_ia32_movddup (v2df) | |
10004 | v4sf __builtin_ia32_movshdup (v4sf) | |
10005 | v4sf __builtin_ia32_movsldup (v4sf) | |
10006 | void __builtin_ia32_mwait (unsigned int, unsigned int) | |
a0ecd6b1 | 10007 | @end smallexample |
754c06ac | 10008 | |
4aafbf22 | 10009 | The following built-in functions are available when @option{-msse3} is used. |
754c06ac | 10010 | |
10011 | @table @code | |
10012 | @item v2df __builtin_ia32_loadddup (double const *) | |
10013 | Generates the @code{movddup} machine instruction as a load from memory. | |
10014 | @end table | |
10015 | ||
2b4894c5 | 10016 | The following built-in functions are available when @option{-mssse3} is used. |
10017 | All of them generate the machine instruction that is part of the name | |
10018 | with MMX registers. | |
10019 | ||
10020 | @smallexample | |
10021 | v2si __builtin_ia32_phaddd (v2si, v2si) | |
10022 | v4hi __builtin_ia32_phaddw (v4hi, v4hi) | |
10023 | v4hi __builtin_ia32_phaddsw (v4hi, v4hi) | |
10024 | v2si __builtin_ia32_phsubd (v2si, v2si) | |
10025 | v4hi __builtin_ia32_phsubw (v4hi, v4hi) | |
10026 | v4hi __builtin_ia32_phsubsw (v4hi, v4hi) | |
6f50184d | 10027 | v4hi __builtin_ia32_pmaddubsw (v8qi, v8qi) |
2b4894c5 | 10028 | v4hi __builtin_ia32_pmulhrsw (v4hi, v4hi) |
10029 | v8qi __builtin_ia32_pshufb (v8qi, v8qi) | |
10030 | v8qi __builtin_ia32_psignb (v8qi, v8qi) | |
10031 | v2si __builtin_ia32_psignd (v2si, v2si) | |
10032 | v4hi __builtin_ia32_psignw (v4hi, v4hi) | |
49698f18 | 10033 | v1di __builtin_ia32_palignr (v1di, v1di, int) |
2b4894c5 | 10034 | v8qi __builtin_ia32_pabsb (v8qi) |
10035 | v2si __builtin_ia32_pabsd (v2si) | |
10036 | v4hi __builtin_ia32_pabsw (v4hi) | |
10037 | @end smallexample | |
10038 | ||
10039 | The following built-in functions are available when @option{-mssse3} is used. | |
10040 | All of them generate the machine instruction that is part of the name | |
10041 | with SSE registers. | |
10042 | ||
10043 | @smallexample | |
10044 | v4si __builtin_ia32_phaddd128 (v4si, v4si) | |
10045 | v8hi __builtin_ia32_phaddw128 (v8hi, v8hi) | |
10046 | v8hi __builtin_ia32_phaddsw128 (v8hi, v8hi) | |
10047 | v4si __builtin_ia32_phsubd128 (v4si, v4si) | |
10048 | v8hi __builtin_ia32_phsubw128 (v8hi, v8hi) | |
10049 | v8hi __builtin_ia32_phsubsw128 (v8hi, v8hi) | |
6f50184d | 10050 | v8hi __builtin_ia32_pmaddubsw128 (v16qi, v16qi) |
2b4894c5 | 10051 | v8hi __builtin_ia32_pmulhrsw128 (v8hi, v8hi) |
10052 | v16qi __builtin_ia32_pshufb128 (v16qi, v16qi) | |
10053 | v16qi __builtin_ia32_psignb128 (v16qi, v16qi) | |
10054 | v4si __builtin_ia32_psignd128 (v4si, v4si) | |
10055 | v8hi __builtin_ia32_psignw128 (v8hi, v8hi) | |
30063220 | 10056 | v2di __builtin_ia32_palignr128 (v2di, v2di, int) |
2b4894c5 | 10057 | v16qi __builtin_ia32_pabsb128 (v16qi) |
10058 | v4si __builtin_ia32_pabsd128 (v4si) | |
10059 | v8hi __builtin_ia32_pabsw128 (v8hi) | |
10060 | @end smallexample | |
10061 | ||
2d771892 | 10062 | The following built-in functions are available when @option{-msse4.1} is |
10063 | used. All of them generate the machine instruction that is part of the | |
10064 | name. | |
10065 | ||
10066 | @smallexample | |
10067 | v2df __builtin_ia32_blendpd (v2df, v2df, const int) | |
10068 | v4sf __builtin_ia32_blendps (v4sf, v4sf, const int) | |
10069 | v2df __builtin_ia32_blendvpd (v2df, v2df, v2df) | |
10070 | v4sf __builtin_ia32_blendvps (v4sf, v4sf, v4sf) | |
e6fc1977 | 10071 | v2df __builtin_ia32_dppd (v2df, v2df, const int) |
2d771892 | 10072 | v4sf __builtin_ia32_dpps (v4sf, v4sf, const int) |
10073 | v4sf __builtin_ia32_insertps128 (v4sf, v4sf, const int) | |
10074 | v2di __builtin_ia32_movntdqa (v2di *); | |
10075 | v16qi __builtin_ia32_mpsadbw128 (v16qi, v16qi, const int) | |
10076 | v8hi __builtin_ia32_packusdw128 (v4si, v4si) | |
10077 | v16qi __builtin_ia32_pblendvb128 (v16qi, v16qi, v16qi) | |
10078 | v8hi __builtin_ia32_pblendw128 (v8hi, v8hi, const int) | |
10079 | v2di __builtin_ia32_pcmpeqq (v2di, v2di) | |
10080 | v8hi __builtin_ia32_phminposuw128 (v8hi) | |
10081 | v16qi __builtin_ia32_pmaxsb128 (v16qi, v16qi) | |
10082 | v4si __builtin_ia32_pmaxsd128 (v4si, v4si) | |
10083 | v4si __builtin_ia32_pmaxud128 (v4si, v4si) | |
10084 | v8hi __builtin_ia32_pmaxuw128 (v8hi, v8hi) | |
10085 | v16qi __builtin_ia32_pminsb128 (v16qi, v16qi) | |
10086 | v4si __builtin_ia32_pminsd128 (v4si, v4si) | |
10087 | v4si __builtin_ia32_pminud128 (v4si, v4si) | |
10088 | v8hi __builtin_ia32_pminuw128 (v8hi, v8hi) | |
10089 | v4si __builtin_ia32_pmovsxbd128 (v16qi) | |
10090 | v2di __builtin_ia32_pmovsxbq128 (v16qi) | |
10091 | v8hi __builtin_ia32_pmovsxbw128 (v16qi) | |
10092 | v2di __builtin_ia32_pmovsxdq128 (v4si) | |
10093 | v4si __builtin_ia32_pmovsxwd128 (v8hi) | |
10094 | v2di __builtin_ia32_pmovsxwq128 (v8hi) | |
10095 | v4si __builtin_ia32_pmovzxbd128 (v16qi) | |
10096 | v2di __builtin_ia32_pmovzxbq128 (v16qi) | |
10097 | v8hi __builtin_ia32_pmovzxbw128 (v16qi) | |
10098 | v2di __builtin_ia32_pmovzxdq128 (v4si) | |
10099 | v4si __builtin_ia32_pmovzxwd128 (v8hi) | |
10100 | v2di __builtin_ia32_pmovzxwq128 (v8hi) | |
10101 | v2di __builtin_ia32_pmuldq128 (v4si, v4si) | |
10102 | v4si __builtin_ia32_pmulld128 (v4si, v4si) | |
10103 | int __builtin_ia32_ptestc128 (v2di, v2di) | |
10104 | int __builtin_ia32_ptestnzc128 (v2di, v2di) | |
10105 | int __builtin_ia32_ptestz128 (v2di, v2di) | |
10106 | v2df __builtin_ia32_roundpd (v2df, const int) | |
10107 | v4sf __builtin_ia32_roundps (v4sf, const int) | |
10108 | v2df __builtin_ia32_roundsd (v2df, v2df, const int) | |
10109 | v4sf __builtin_ia32_roundss (v4sf, v4sf, const int) | |
10110 | @end smallexample | |
10111 | ||
10112 | The following built-in functions are available when @option{-msse4.1} is | |
10113 | used. | |
10114 | ||
10115 | @table @code | |
10116 | @item v4sf __builtin_ia32_vec_set_v4sf (v4sf, float, const int) | |
10117 | Generates the @code{insertps} machine instruction. | |
10118 | @item int __builtin_ia32_vec_ext_v16qi (v16qi, const int) | |
10119 | Generates the @code{pextrb} machine instruction. | |
10120 | @item v16qi __builtin_ia32_vec_set_v16qi (v16qi, int, const int) | |
10121 | Generates the @code{pinsrb} machine instruction. | |
10122 | @item v4si __builtin_ia32_vec_set_v4si (v4si, int, const int) | |
10123 | Generates the @code{pinsrd} machine instruction. | |
10124 | @item v2di __builtin_ia32_vec_set_v2di (v2di, long long, const int) | |
10125 | Generates the @code{pinsrq} machine instruction in 64bit mode. | |
10126 | @end table | |
10127 | ||
10128 | The following built-in functions are changed to generate new SSE4.1 | |
10129 | instructions when @option{-msse4.1} is used. | |
10130 | ||
10131 | @table @code | |
10132 | @item float __builtin_ia32_vec_ext_v4sf (v4sf, const int) | |
10133 | Generates the @code{extractps} machine instruction. | |
10134 | @item int __builtin_ia32_vec_ext_v4si (v4si, const int) | |
10135 | Generates the @code{pextrd} machine instruction. | |
10136 | @item long long __builtin_ia32_vec_ext_v2di (v2di, const int) | |
10137 | Generates the @code{pextrq} machine instruction in 64bit mode. | |
10138 | @end table | |
10139 | ||
f25d51c3 | 10140 | The following built-in functions are available when @option{-msse4.2} is |
10141 | used. All of them generate the machine instruction that is part of the | |
10142 | name. | |
10143 | ||
10144 | @smallexample | |
10145 | v16qi __builtin_ia32_pcmpestrm128 (v16qi, int, v16qi, int, const int) | |
10146 | int __builtin_ia32_pcmpestri128 (v16qi, int, v16qi, int, const int) | |
10147 | int __builtin_ia32_pcmpestria128 (v16qi, int, v16qi, int, const int) | |
10148 | int __builtin_ia32_pcmpestric128 (v16qi, int, v16qi, int, const int) | |
10149 | int __builtin_ia32_pcmpestrio128 (v16qi, int, v16qi, int, const int) | |
10150 | int __builtin_ia32_pcmpestris128 (v16qi, int, v16qi, int, const int) | |
10151 | int __builtin_ia32_pcmpestriz128 (v16qi, int, v16qi, int, const int) | |
10152 | v16qi __builtin_ia32_pcmpistrm128 (v16qi, v16qi, const int) | |
10153 | int __builtin_ia32_pcmpistri128 (v16qi, v16qi, const int) | |
10154 | int __builtin_ia32_pcmpistria128 (v16qi, v16qi, const int) | |
10155 | int __builtin_ia32_pcmpistric128 (v16qi, v16qi, const int) | |
10156 | int __builtin_ia32_pcmpistrio128 (v16qi, v16qi, const int) | |
10157 | int __builtin_ia32_pcmpistris128 (v16qi, v16qi, const int) | |
10158 | int __builtin_ia32_pcmpistriz128 (v16qi, v16qi, const int) | |
e6fc1977 | 10159 | v2di __builtin_ia32_pcmpgtq (v2di, v2di) |
f25d51c3 | 10160 | @end smallexample |
10161 | ||
10162 | The following built-in functions are available when @option{-msse4.2} is | |
10163 | used. | |
10164 | ||
10165 | @table @code | |
e6fc1977 | 10166 | @item unsigned int __builtin_ia32_crc32qi (unsigned int, unsigned char) |
f25d51c3 | 10167 | Generates the @code{crc32b} machine instruction. |
e6fc1977 | 10168 | @item unsigned int __builtin_ia32_crc32hi (unsigned int, unsigned short) |
f25d51c3 | 10169 | Generates the @code{crc32w} machine instruction. |
e6fc1977 | 10170 | @item unsigned int __builtin_ia32_crc32si (unsigned int, unsigned int) |
f25d51c3 | 10171 | Generates the @code{crc32l} machine instruction. |
2424d00f | 10172 | @item unsigned long long __builtin_ia32_crc32di (unsigned long long, unsigned long long) |
9e26132e | 10173 | Generates the @code{crc32q} machine instruction. |
f25d51c3 | 10174 | @end table |
10175 | ||
10176 | The following built-in functions are changed to generate new SSE4.2 | |
10177 | instructions when @option{-msse4.2} is used. | |
10178 | ||
10179 | @table @code | |
e6fc1977 | 10180 | @item int __builtin_popcount (unsigned int) |
f25d51c3 | 10181 | Generates the @code{popcntl} machine instruction. |
e6fc1977 | 10182 | @item int __builtin_popcountl (unsigned long) |
f25d51c3 | 10183 | Generates the @code{popcntl} or @code{popcntq} machine instruction, |
10184 | depending on the size of @code{unsigned long}. | |
e6fc1977 | 10185 | @item int __builtin_popcountll (unsigned long long) |
f25d51c3 | 10186 | Generates the @code{popcntq} machine instruction. |
10187 | @end table | |
10188 | ||
f6c7e4af | 10189 | The following built-in functions are available when @option{-mavx} is |
10190 | used. All of them generate the machine instruction that is part of the | |
10191 | name. | |
10192 | ||
10193 | @smallexample | |
10194 | v4df __builtin_ia32_addpd256 (v4df,v4df) | |
10195 | v8sf __builtin_ia32_addps256 (v8sf,v8sf) | |
10196 | v4df __builtin_ia32_addsubpd256 (v4df,v4df) | |
10197 | v8sf __builtin_ia32_addsubps256 (v8sf,v8sf) | |
10198 | v4df __builtin_ia32_andnpd256 (v4df,v4df) | |
10199 | v8sf __builtin_ia32_andnps256 (v8sf,v8sf) | |
10200 | v4df __builtin_ia32_andpd256 (v4df,v4df) | |
10201 | v8sf __builtin_ia32_andps256 (v8sf,v8sf) | |
10202 | v4df __builtin_ia32_blendpd256 (v4df,v4df,int) | |
10203 | v8sf __builtin_ia32_blendps256 (v8sf,v8sf,int) | |
10204 | v4df __builtin_ia32_blendvpd256 (v4df,v4df,v4df) | |
10205 | v8sf __builtin_ia32_blendvps256 (v8sf,v8sf,v8sf) | |
10206 | v2df __builtin_ia32_cmppd (v2df,v2df,int) | |
10207 | v4df __builtin_ia32_cmppd256 (v4df,v4df,int) | |
10208 | v4sf __builtin_ia32_cmpps (v4sf,v4sf,int) | |
10209 | v8sf __builtin_ia32_cmpps256 (v8sf,v8sf,int) | |
10210 | v2df __builtin_ia32_cmpsd (v2df,v2df,int) | |
10211 | v4sf __builtin_ia32_cmpss (v4sf,v4sf,int) | |
10212 | v4df __builtin_ia32_cvtdq2pd256 (v4si) | |
10213 | v8sf __builtin_ia32_cvtdq2ps256 (v8si) | |
10214 | v4si __builtin_ia32_cvtpd2dq256 (v4df) | |
10215 | v4sf __builtin_ia32_cvtpd2ps256 (v4df) | |
10216 | v8si __builtin_ia32_cvtps2dq256 (v8sf) | |
10217 | v4df __builtin_ia32_cvtps2pd256 (v4sf) | |
10218 | v4si __builtin_ia32_cvttpd2dq256 (v4df) | |
10219 | v8si __builtin_ia32_cvttps2dq256 (v8sf) | |
10220 | v4df __builtin_ia32_divpd256 (v4df,v4df) | |
10221 | v8sf __builtin_ia32_divps256 (v8sf,v8sf) | |
10222 | v8sf __builtin_ia32_dpps256 (v8sf,v8sf,int) | |
10223 | v4df __builtin_ia32_haddpd256 (v4df,v4df) | |
10224 | v8sf __builtin_ia32_haddps256 (v8sf,v8sf) | |
10225 | v4df __builtin_ia32_hsubpd256 (v4df,v4df) | |
10226 | v8sf __builtin_ia32_hsubps256 (v8sf,v8sf) | |
10227 | v32qi __builtin_ia32_lddqu256 (pcchar) | |
10228 | v32qi __builtin_ia32_loaddqu256 (pcchar) | |
10229 | v4df __builtin_ia32_loadupd256 (pcdouble) | |
10230 | v8sf __builtin_ia32_loadups256 (pcfloat) | |
10231 | v2df __builtin_ia32_maskloadpd (pcv2df,v2df) | |
10232 | v4df __builtin_ia32_maskloadpd256 (pcv4df,v4df) | |
10233 | v4sf __builtin_ia32_maskloadps (pcv4sf,v4sf) | |
10234 | v8sf __builtin_ia32_maskloadps256 (pcv8sf,v8sf) | |
10235 | void __builtin_ia32_maskstorepd (pv2df,v2df,v2df) | |
10236 | void __builtin_ia32_maskstorepd256 (pv4df,v4df,v4df) | |
10237 | void __builtin_ia32_maskstoreps (pv4sf,v4sf,v4sf) | |
10238 | void __builtin_ia32_maskstoreps256 (pv8sf,v8sf,v8sf) | |
10239 | v4df __builtin_ia32_maxpd256 (v4df,v4df) | |
10240 | v8sf __builtin_ia32_maxps256 (v8sf,v8sf) | |
10241 | v4df __builtin_ia32_minpd256 (v4df,v4df) | |
10242 | v8sf __builtin_ia32_minps256 (v8sf,v8sf) | |
10243 | v4df __builtin_ia32_movddup256 (v4df) | |
10244 | int __builtin_ia32_movmskpd256 (v4df) | |
10245 | int __builtin_ia32_movmskps256 (v8sf) | |
10246 | v8sf __builtin_ia32_movshdup256 (v8sf) | |
10247 | v8sf __builtin_ia32_movsldup256 (v8sf) | |
10248 | v4df __builtin_ia32_mulpd256 (v4df,v4df) | |
10249 | v8sf __builtin_ia32_mulps256 (v8sf,v8sf) | |
10250 | v4df __builtin_ia32_orpd256 (v4df,v4df) | |
10251 | v8sf __builtin_ia32_orps256 (v8sf,v8sf) | |
10252 | v2df __builtin_ia32_pd_pd256 (v4df) | |
10253 | v4df __builtin_ia32_pd256_pd (v2df) | |
10254 | v4sf __builtin_ia32_ps_ps256 (v8sf) | |
10255 | v8sf __builtin_ia32_ps256_ps (v4sf) | |
10256 | int __builtin_ia32_ptestc256 (v4di,v4di,ptest) | |
10257 | int __builtin_ia32_ptestnzc256 (v4di,v4di,ptest) | |
10258 | int __builtin_ia32_ptestz256 (v4di,v4di,ptest) | |
10259 | v8sf __builtin_ia32_rcpps256 (v8sf) | |
10260 | v4df __builtin_ia32_roundpd256 (v4df,int) | |
10261 | v8sf __builtin_ia32_roundps256 (v8sf,int) | |
10262 | v8sf __builtin_ia32_rsqrtps_nr256 (v8sf) | |
10263 | v8sf __builtin_ia32_rsqrtps256 (v8sf) | |
10264 | v4df __builtin_ia32_shufpd256 (v4df,v4df,int) | |
10265 | v8sf __builtin_ia32_shufps256 (v8sf,v8sf,int) | |
10266 | v4si __builtin_ia32_si_si256 (v8si) | |
10267 | v8si __builtin_ia32_si256_si (v4si) | |
10268 | v4df __builtin_ia32_sqrtpd256 (v4df) | |
10269 | v8sf __builtin_ia32_sqrtps_nr256 (v8sf) | |
10270 | v8sf __builtin_ia32_sqrtps256 (v8sf) | |
10271 | void __builtin_ia32_storedqu256 (pchar,v32qi) | |
10272 | void __builtin_ia32_storeupd256 (pdouble,v4df) | |
10273 | void __builtin_ia32_storeups256 (pfloat,v8sf) | |
10274 | v4df __builtin_ia32_subpd256 (v4df,v4df) | |
10275 | v8sf __builtin_ia32_subps256 (v8sf,v8sf) | |
10276 | v4df __builtin_ia32_unpckhpd256 (v4df,v4df) | |
10277 | v8sf __builtin_ia32_unpckhps256 (v8sf,v8sf) | |
10278 | v4df __builtin_ia32_unpcklpd256 (v4df,v4df) | |
10279 | v8sf __builtin_ia32_unpcklps256 (v8sf,v8sf) | |
10280 | v4df __builtin_ia32_vbroadcastf128_pd256 (pcv2df) | |
10281 | v8sf __builtin_ia32_vbroadcastf128_ps256 (pcv4sf) | |
10282 | v4df __builtin_ia32_vbroadcastsd256 (pcdouble) | |
10283 | v4sf __builtin_ia32_vbroadcastss (pcfloat) | |
10284 | v8sf __builtin_ia32_vbroadcastss256 (pcfloat) | |
10285 | v2df __builtin_ia32_vextractf128_pd256 (v4df,int) | |
10286 | v4sf __builtin_ia32_vextractf128_ps256 (v8sf,int) | |
10287 | v4si __builtin_ia32_vextractf128_si256 (v8si,int) | |
10288 | v4df __builtin_ia32_vinsertf128_pd256 (v4df,v2df,int) | |
10289 | v8sf __builtin_ia32_vinsertf128_ps256 (v8sf,v4sf,int) | |
10290 | v8si __builtin_ia32_vinsertf128_si256 (v8si,v4si,int) | |
10291 | v4df __builtin_ia32_vperm2f128_pd256 (v4df,v4df,int) | |
10292 | v8sf __builtin_ia32_vperm2f128_ps256 (v8sf,v8sf,int) | |
10293 | v8si __builtin_ia32_vperm2f128_si256 (v8si,v8si,int) | |
10294 | v2df __builtin_ia32_vpermil2pd (v2df,v2df,v2di,int) | |
10295 | v4df __builtin_ia32_vpermil2pd256 (v4df,v4df,v4di,int) | |
10296 | v4sf __builtin_ia32_vpermil2ps (v4sf,v4sf,v4si,int) | |
10297 | v8sf __builtin_ia32_vpermil2ps256 (v8sf,v8sf,v8si,int) | |
10298 | v2df __builtin_ia32_vpermilpd (v2df,int) | |
10299 | v4df __builtin_ia32_vpermilpd256 (v4df,int) | |
10300 | v4sf __builtin_ia32_vpermilps (v4sf,int) | |
10301 | v8sf __builtin_ia32_vpermilps256 (v8sf,int) | |
10302 | v2df __builtin_ia32_vpermilvarpd (v2df,v2di) | |
10303 | v4df __builtin_ia32_vpermilvarpd256 (v4df,v4di) | |
10304 | v4sf __builtin_ia32_vpermilvarps (v4sf,v4si) | |
10305 | v8sf __builtin_ia32_vpermilvarps256 (v8sf,v8si) | |
10306 | int __builtin_ia32_vtestcpd (v2df,v2df,ptest) | |
10307 | int __builtin_ia32_vtestcpd256 (v4df,v4df,ptest) | |
10308 | int __builtin_ia32_vtestcps (v4sf,v4sf,ptest) | |
10309 | int __builtin_ia32_vtestcps256 (v8sf,v8sf,ptest) | |
10310 | int __builtin_ia32_vtestnzcpd (v2df,v2df,ptest) | |
10311 | int __builtin_ia32_vtestnzcpd256 (v4df,v4df,ptest) | |
10312 | int __builtin_ia32_vtestnzcps (v4sf,v4sf,ptest) | |
10313 | int __builtin_ia32_vtestnzcps256 (v8sf,v8sf,ptest) | |
10314 | int __builtin_ia32_vtestzpd (v2df,v2df,ptest) | |
10315 | int __builtin_ia32_vtestzpd256 (v4df,v4df,ptest) | |
10316 | int __builtin_ia32_vtestzps (v4sf,v4sf,ptest) | |
10317 | int __builtin_ia32_vtestzps256 (v8sf,v8sf,ptest) | |
10318 | void __builtin_ia32_vzeroall (void) | |
10319 | void __builtin_ia32_vzeroupper (void) | |
10320 | v4df __builtin_ia32_xorpd256 (v4df,v4df) | |
10321 | v8sf __builtin_ia32_xorps256 (v8sf,v8sf) | |
10322 | @end smallexample | |
10323 | ||
5deb404d | 10324 | The following built-in functions are available when @option{-mavx2} is |
10325 | used. All of them generate the machine instruction that is part of the | |
10326 | name. | |
10327 | ||
10328 | @smallexample | |
10329 | v32qi __builtin_ia32_mpsadbw256 (v32qi,v32qi,v32qi,int) | |
10330 | v32qi __builtin_ia32_pabsb256 (v32qi) | |
10331 | v16hi __builtin_ia32_pabsw256 (v16hi) | |
10332 | v8si __builtin_ia32_pabsd256 (v8si) | |
10333 | v16hi builtin_ia32_packssdw256 (v8si,v8si) | |
10334 | v32qi __builtin_ia32_packsswb256 (v16hi,v16hi) | |
10335 | v16hi __builtin_ia32_packusdw256 (v8si,v8si) | |
10336 | v32qi __builtin_ia32_packuswb256 (v16hi,v16hi) | |
10337 | v32qi__builtin_ia32_paddb256 (v32qi,v32qi) | |
10338 | v16hi __builtin_ia32_paddw256 (v16hi,v16hi) | |
10339 | v8si __builtin_ia32_paddd256 (v8si,v8si) | |
10340 | v4di __builtin_ia32_paddq256 (v4di,v4di) | |
10341 | v32qi __builtin_ia32_paddsb256 (v32qi,v32qi) | |
10342 | v16hi __builtin_ia32_paddsw256 (v16hi,v16hi) | |
10343 | v32qi __builtin_ia32_paddusb256 (v32qi,v32qi) | |
10344 | v16hi __builtin_ia32_paddusw256 (v16hi,v16hi) | |
10345 | v4di __builtin_ia32_palignr256 (v4di,v4di,int) | |
10346 | v4di __builtin_ia32_andsi256 (v4di,v4di) | |
10347 | v4di __builtin_ia32_andnotsi256 (v4di,v4di) | |
10348 | v32qi__builtin_ia32_pavgb256 (v32qi,v32qi) | |
10349 | v16hi __builtin_ia32_pavgw256 (v16hi,v16hi) | |
10350 | v32qi __builtin_ia32_pblendvb256 (v32qi,v32qi,v32qi) | |
10351 | v16hi __builtin_ia32_pblendw256 (v16hi,v16hi,int) | |
10352 | v32qi __builtin_ia32_pcmpeqb256 (v32qi,v32qi) | |
10353 | v16hi __builtin_ia32_pcmpeqw256 (v16hi,v16hi) | |
10354 | v8si __builtin_ia32_pcmpeqd256 (c8si,v8si) | |
10355 | v4di __builtin_ia32_pcmpeqq256 (v4di,v4di) | |
10356 | v32qi __builtin_ia32_pcmpgtb256 (v32qi,v32qi) | |
10357 | v16hi __builtin_ia32_pcmpgtw256 (16hi,v16hi) | |
10358 | v8si __builtin_ia32_pcmpgtd256 (v8si,v8si) | |
10359 | v4di __builtin_ia32_pcmpgtq256 (v4di,v4di) | |
10360 | v16hi __builtin_ia32_phaddw256 (v16hi,v16hi) | |
10361 | v8si __builtin_ia32_phaddd256 (v8si,v8si) | |
10362 | v16hi __builtin_ia32_phaddsw256 (v16hi,v16hi) | |
10363 | v16hi __builtin_ia32_phsubw256 (v16hi,v16hi) | |
10364 | v8si __builtin_ia32_phsubd256 (v8si,v8si) | |
10365 | v16hi __builtin_ia32_phsubsw256 (v16hi,v16hi) | |
10366 | v32qi __builtin_ia32_pmaddubsw256 (v32qi,v32qi) | |
10367 | v16hi __builtin_ia32_pmaddwd256 (v16hi,v16hi) | |
10368 | v32qi __builtin_ia32_pmaxsb256 (v32qi,v32qi) | |
10369 | v16hi __builtin_ia32_pmaxsw256 (v16hi,v16hi) | |
10370 | v8si __builtin_ia32_pmaxsd256 (v8si,v8si) | |
10371 | v32qi __builtin_ia32_pmaxub256 (v32qi,v32qi) | |
10372 | v16hi __builtin_ia32_pmaxuw256 (v16hi,v16hi) | |
10373 | v8si __builtin_ia32_pmaxud256 (v8si,v8si) | |
10374 | v32qi __builtin_ia32_pminsb256 (v32qi,v32qi) | |
10375 | v16hi __builtin_ia32_pminsw256 (v16hi,v16hi) | |
10376 | v8si __builtin_ia32_pminsd256 (v8si,v8si) | |
10377 | v32qi __builtin_ia32_pminub256 (v32qi,v32qi) | |
10378 | v16hi __builtin_ia32_pminuw256 (v16hi,v16hi) | |
10379 | v8si __builtin_ia32_pminud256 (v8si,v8si) | |
10380 | int __builtin_ia32_pmovmskb256 (v32qi) | |
10381 | v16hi __builtin_ia32_pmovsxbw256 (v16qi) | |
10382 | v8si __builtin_ia32_pmovsxbd256 (v16qi) | |
10383 | v4di __builtin_ia32_pmovsxbq256 (v16qi) | |
10384 | v8si __builtin_ia32_pmovsxwd256 (v8hi) | |
10385 | v4di __builtin_ia32_pmovsxwq256 (v8hi) | |
10386 | v4di __builtin_ia32_pmovsxdq256 (v4si) | |
10387 | v16hi __builtin_ia32_pmovzxbw256 (v16qi) | |
10388 | v8si __builtin_ia32_pmovzxbd256 (v16qi) | |
10389 | v4di __builtin_ia32_pmovzxbq256 (v16qi) | |
10390 | v8si __builtin_ia32_pmovzxwd256 (v8hi) | |
10391 | v4di __builtin_ia32_pmovzxwq256 (v8hi) | |
10392 | v4di __builtin_ia32_pmovzxdq256 (v4si) | |
10393 | v4di __builtin_ia32_pmuldq256 (v8si,v8si) | |
10394 | v16hi __builtin_ia32_pmulhrsw256 (v16hi, v16hi) | |
10395 | v16hi __builtin_ia32_pmulhuw256 (v16hi,v16hi) | |
10396 | v16hi __builtin_ia32_pmulhw256 (v16hi,v16hi) | |
10397 | v16hi __builtin_ia32_pmullw256 (v16hi,v16hi) | |
10398 | v8si __builtin_ia32_pmulld256 (v8si,v8si) | |
10399 | v4di __builtin_ia32_pmuludq256 (v8si,v8si) | |
10400 | v4di __builtin_ia32_por256 (v4di,v4di) | |
10401 | v16hi __builtin_ia32_psadbw256 (v32qi,v32qi) | |
10402 | v32qi __builtin_ia32_pshufb256 (v32qi,v32qi) | |
10403 | v8si __builtin_ia32_pshufd256 (v8si,int) | |
10404 | v16hi __builtin_ia32_pshufhw256 (v16hi,int) | |
10405 | v16hi __builtin_ia32_pshuflw256 (v16hi,int) | |
10406 | v32qi __builtin_ia32_psignb256 (v32qi,v32qi) | |
10407 | v16hi __builtin_ia32_psignw256 (v16hi,v16hi) | |
10408 | v8si __builtin_ia32_psignd256 (v8si,v8si) | |
10409 | v4di __builtin_ia32_pslldqi256 (v4di,int) | |
10410 | v16hi __builtin_ia32_psllwi256 (16hi,int) | |
10411 | v16hi __builtin_ia32_psllw256(v16hi,v8hi) | |
10412 | v8si __builtin_ia32_pslldi256 (v8si,int) | |
10413 | v8si __builtin_ia32_pslld256(v8si,v4si) | |
10414 | v4di __builtin_ia32_psllqi256 (v4di,int) | |
10415 | v4di __builtin_ia32_psllq256(v4di,v2di) | |
10416 | v16hi __builtin_ia32_psrawi256 (v16hi,int) | |
10417 | v16hi __builtin_ia32_psraw256 (v16hi,v8hi) | |
10418 | v8si __builtin_ia32_psradi256 (v8si,int) | |
10419 | v8si __builtin_ia32_psrad256 (v8si,v4si) | |
10420 | v4di __builtin_ia32_psrldqi256 (v4di, int) | |
10421 | v16hi __builtin_ia32_psrlwi256 (v16hi,int) | |
10422 | v16hi __builtin_ia32_psrlw256 (v16hi,v8hi) | |
10423 | v8si __builtin_ia32_psrldi256 (v8si,int) | |
10424 | v8si __builtin_ia32_psrld256 (v8si,v4si) | |
10425 | v4di __builtin_ia32_psrlqi256 (v4di,int) | |
10426 | v4di __builtin_ia32_psrlq256(v4di,v2di) | |
10427 | v32qi __builtin_ia32_psubb256 (v32qi,v32qi) | |
10428 | v32hi __builtin_ia32_psubw256 (v16hi,v16hi) | |
10429 | v8si __builtin_ia32_psubd256 (v8si,v8si) | |
10430 | v4di __builtin_ia32_psubq256 (v4di,v4di) | |
10431 | v32qi __builtin_ia32_psubsb256 (v32qi,v32qi) | |
10432 | v16hi __builtin_ia32_psubsw256 (v16hi,v16hi) | |
10433 | v32qi __builtin_ia32_psubusb256 (v32qi,v32qi) | |
10434 | v16hi __builtin_ia32_psubusw256 (v16hi,v16hi) | |
10435 | v32qi __builtin_ia32_punpckhbw256 (v32qi,v32qi) | |
10436 | v16hi __builtin_ia32_punpckhwd256 (v16hi,v16hi) | |
10437 | v8si __builtin_ia32_punpckhdq256 (v8si,v8si) | |
10438 | v4di __builtin_ia32_punpckhqdq256 (v4di,v4di) | |
10439 | v32qi __builtin_ia32_punpcklbw256 (v32qi,v32qi) | |
10440 | v16hi __builtin_ia32_punpcklwd256 (v16hi,v16hi) | |
10441 | v8si __builtin_ia32_punpckldq256 (v8si,v8si) | |
10442 | v4di __builtin_ia32_punpcklqdq256 (v4di,v4di) | |
10443 | v4di __builtin_ia32_pxor256 (v4di,v4di) | |
10444 | v4di __builtin_ia32_movntdqa256 (pv4di) | |
10445 | v4sf __builtin_ia32_vbroadcastss_ps (v4sf) | |
10446 | v8sf __builtin_ia32_vbroadcastss_ps256 (v4sf) | |
10447 | v4df __builtin_ia32_vbroadcastsd_pd256 (v2df) | |
10448 | v4di __builtin_ia32_vbroadcastsi256 (v2di) | |
10449 | v4si __builtin_ia32_pblendd128 (v4si,v4si) | |
10450 | v8si __builtin_ia32_pblendd256 (v8si,v8si) | |
10451 | v32qi __builtin_ia32_pbroadcastb256 (v16qi) | |
10452 | v16hi __builtin_ia32_pbroadcastw256 (v8hi) | |
10453 | v8si __builtin_ia32_pbroadcastd256 (v4si) | |
10454 | v4di __builtin_ia32_pbroadcastq256 (v2di) | |
10455 | v16qi __builtin_ia32_pbroadcastb128 (v16qi) | |
10456 | v8hi __builtin_ia32_pbroadcastw128 (v8hi) | |
10457 | v4si __builtin_ia32_pbroadcastd128 (v4si) | |
10458 | v2di __builtin_ia32_pbroadcastq128 (v2di) | |
10459 | v8si __builtin_ia32_permvarsi256 (v8si,v8si) | |
10460 | v4df __builtin_ia32_permdf256 (v4df,int) | |
10461 | v8sf __builtin_ia32_permvarsf256 (v8sf,v8sf) | |
10462 | v4di __builtin_ia32_permdi256 (v4di,int) | |
10463 | v4di __builtin_ia32_permti256 (v4di,v4di,int) | |
10464 | v4di __builtin_ia32_extract128i256 (v4di,int) | |
10465 | v4di __builtin_ia32_insert128i256 (v4di,v2di,int) | |
10466 | v8si __builtin_ia32_maskloadd256 (pcv8si,v8si) | |
10467 | v4di __builtin_ia32_maskloadq256 (pcv4di,v4di) | |
10468 | v4si __builtin_ia32_maskloadd (pcv4si,v4si) | |
10469 | v2di __builtin_ia32_maskloadq (pcv2di,v2di) | |
10470 | void __builtin_ia32_maskstored256 (pv8si,v8si,v8si) | |
10471 | void __builtin_ia32_maskstoreq256 (pv4di,v4di,v4di) | |
10472 | void __builtin_ia32_maskstored (pv4si,v4si,v4si) | |
10473 | void __builtin_ia32_maskstoreq (pv2di,v2di,v2di) | |
10474 | v8si __builtin_ia32_psllv8si (v8si,v8si) | |
10475 | v4si __builtin_ia32_psllv4si (v4si,v4si) | |
10476 | v4di __builtin_ia32_psllv4di (v4di,v4di) | |
10477 | v2di __builtin_ia32_psllv2di (v2di,v2di) | |
10478 | v8si __builtin_ia32_psrav8si (v8si,v8si) | |
10479 | v4si __builtin_ia32_psrav4si (v4si,v4si) | |
10480 | v8si __builtin_ia32_psrlv8si (v8si,v8si) | |
10481 | v4si __builtin_ia32_psrlv4si (v4si,v4si) | |
10482 | v4di __builtin_ia32_psrlv4di (v4di,v4di) | |
10483 | v2di __builtin_ia32_psrlv2di (v2di,v2di) | |
10484 | v2df __builtin_ia32_gathersiv2df (v2df, pcdouble,v4si,v2df,int) | |
10485 | v4df __builtin_ia32_gathersiv4df (v4df, pcdouble,v4si,v4df,int) | |
10486 | v2df __builtin_ia32_gatherdiv2df (v2df, pcdouble,v2di,v2df,int) | |
10487 | v4df __builtin_ia32_gatherdiv4df (v4df, pcdouble,v4di,v4df,int) | |
10488 | v4sf __builtin_ia32_gathersiv4sf (v4sf, pcfloat,v4si,v4sf,int) | |
10489 | v8sf __builtin_ia32_gathersiv8sf (v8sf, pcfloat,v8si,v8sf,int) | |
10490 | v4sf __builtin_ia32_gatherdiv4sf (v4sf, pcfloat,v2di,v4sf,int) | |
10491 | v4sf __builtin_ia32_gatherdiv4sf256 (v4sf, pcfloat,v4di,v4sf,int) | |
10492 | v2di __builtin_ia32_gathersiv2di (v2di, pcint64,v4si,v2di,int) | |
10493 | v4di __builtin_ia32_gathersiv4di (v4di, pcint64,v4si,v4di,int) | |
10494 | v2di __builtin_ia32_gatherdiv2di (v2di, pcint64,v2di,v2di,int) | |
10495 | v4di __builtin_ia32_gatherdiv4di (v4di, pcint64,v4di,v4di,int) | |
10496 | v4si __builtin_ia32_gathersiv4si (v4si, pcint,v4si,v4si,int) | |
10497 | v8si __builtin_ia32_gathersiv8si (v8si, pcint,v8si,v8si,int) | |
10498 | v4si __builtin_ia32_gatherdiv4si (v4si, pcint,v2di,v4si,int) | |
10499 | v4si __builtin_ia32_gatherdiv4si256 (v4si, pcint,v4di,v4si,int) | |
10500 | @end smallexample | |
10501 | ||
1d9ef704 | 10502 | The following built-in functions are available when @option{-maes} is |
10503 | used. All of them generate the machine instruction that is part of the | |
10504 | name. | |
10505 | ||
10506 | @smallexample | |
10507 | v2di __builtin_ia32_aesenc128 (v2di, v2di) | |
10508 | v2di __builtin_ia32_aesenclast128 (v2di, v2di) | |
10509 | v2di __builtin_ia32_aesdec128 (v2di, v2di) | |
10510 | v2di __builtin_ia32_aesdeclast128 (v2di, v2di) | |
10511 | v2di __builtin_ia32_aeskeygenassist128 (v2di, const int) | |
10512 | v2di __builtin_ia32_aesimc128 (v2di) | |
10513 | @end smallexample | |
10514 | ||
10515 | The following built-in function is available when @option{-mpclmul} is | |
10516 | used. | |
10517 | ||
10518 | @table @code | |
10519 | @item v2di __builtin_ia32_pclmulqdq128 (v2di, v2di, const int) | |
10520 | Generates the @code{pclmulqdq} machine instruction. | |
10521 | @end table | |
10522 | ||
ec113e67 | 10523 | The following built-in function is available when @option{-mfsgsbase} is |
10524 | used. All of them generate the machine instruction that is part of the | |
10525 | name. | |
10526 | ||
10527 | @smallexample | |
10528 | unsigned int __builtin_ia32_rdfsbase32 (void) | |
10529 | unsigned long long __builtin_ia32_rdfsbase64 (void) | |
10530 | unsigned int __builtin_ia32_rdgsbase32 (void) | |
10531 | unsigned long long __builtin_ia32_rdgsbase64 (void) | |
10532 | void _writefsbase_u32 (unsigned int) | |
10533 | void _writefsbase_u64 (unsigned long long) | |
10534 | void _writegsbase_u32 (unsigned int) | |
10535 | void _writegsbase_u64 (unsigned long long) | |
10536 | @end smallexample | |
10537 | ||
10538 | The following built-in function is available when @option{-mrdrnd} is | |
10539 | used. All of them generate the machine instruction that is part of the | |
10540 | name. | |
10541 | ||
10542 | @smallexample | |
2d1e402c | 10543 | unsigned int __builtin_ia32_rdrand16_step (unsigned short *) |
10544 | unsigned int __builtin_ia32_rdrand32_step (unsigned int *) | |
10545 | unsigned int __builtin_ia32_rdrand64_step (unsigned long long *) | |
ec113e67 | 10546 | @end smallexample |
10547 | ||
3d775f8e | 10548 | The following built-in functions are available when @option{-msse4a} is used. |
e6fc1977 | 10549 | All of them generate the machine instruction that is part of the name. |
3d775f8e | 10550 | |
10551 | @smallexample | |
e6fc1977 | 10552 | void __builtin_ia32_movntsd (double *, v2df) |
10553 | void __builtin_ia32_movntss (float *, v4sf) | |
10554 | v2di __builtin_ia32_extrq (v2di, v16qi) | |
10555 | v2di __builtin_ia32_extrqi (v2di, const unsigned int, const unsigned int) | |
10556 | v2di __builtin_ia32_insertq (v2di, v2di) | |
10557 | v2di __builtin_ia32_insertqi (v2di, v2di, const unsigned int, const unsigned int) | |
3d775f8e | 10558 | @end smallexample |
10559 | ||
18525343 | 10560 | The following built-in functions are available when @option{-mxop} is used. |
10561 | @smallexample | |
10562 | v2df __builtin_ia32_vfrczpd (v2df) | |
10563 | v4sf __builtin_ia32_vfrczps (v4sf) | |
10564 | v2df __builtin_ia32_vfrczsd (v2df, v2df) | |
10565 | v4sf __builtin_ia32_vfrczss (v4sf, v4sf) | |
10566 | v4df __builtin_ia32_vfrczpd256 (v4df) | |
10567 | v8sf __builtin_ia32_vfrczps256 (v8sf) | |
10568 | v2di __builtin_ia32_vpcmov (v2di, v2di, v2di) | |
10569 | v2di __builtin_ia32_vpcmov_v2di (v2di, v2di, v2di) | |
10570 | v4si __builtin_ia32_vpcmov_v4si (v4si, v4si, v4si) | |
10571 | v8hi __builtin_ia32_vpcmov_v8hi (v8hi, v8hi, v8hi) | |
10572 | v16qi __builtin_ia32_vpcmov_v16qi (v16qi, v16qi, v16qi) | |
10573 | v2df __builtin_ia32_vpcmov_v2df (v2df, v2df, v2df) | |
10574 | v4sf __builtin_ia32_vpcmov_v4sf (v4sf, v4sf, v4sf) | |
10575 | v4di __builtin_ia32_vpcmov_v4di256 (v4di, v4di, v4di) | |
10576 | v8si __builtin_ia32_vpcmov_v8si256 (v8si, v8si, v8si) | |
10577 | v16hi __builtin_ia32_vpcmov_v16hi256 (v16hi, v16hi, v16hi) | |
10578 | v32qi __builtin_ia32_vpcmov_v32qi256 (v32qi, v32qi, v32qi) | |
10579 | v4df __builtin_ia32_vpcmov_v4df256 (v4df, v4df, v4df) | |
10580 | v8sf __builtin_ia32_vpcmov_v8sf256 (v8sf, v8sf, v8sf) | |
10581 | v16qi __builtin_ia32_vpcomeqb (v16qi, v16qi) | |
10582 | v8hi __builtin_ia32_vpcomeqw (v8hi, v8hi) | |
10583 | v4si __builtin_ia32_vpcomeqd (v4si, v4si) | |
10584 | v2di __builtin_ia32_vpcomeqq (v2di, v2di) | |
10585 | v16qi __builtin_ia32_vpcomequb (v16qi, v16qi) | |
10586 | v4si __builtin_ia32_vpcomequd (v4si, v4si) | |
10587 | v2di __builtin_ia32_vpcomequq (v2di, v2di) | |
10588 | v8hi __builtin_ia32_vpcomequw (v8hi, v8hi) | |
10589 | v8hi __builtin_ia32_vpcomeqw (v8hi, v8hi) | |
10590 | v16qi __builtin_ia32_vpcomfalseb (v16qi, v16qi) | |
10591 | v4si __builtin_ia32_vpcomfalsed (v4si, v4si) | |
10592 | v2di __builtin_ia32_vpcomfalseq (v2di, v2di) | |
10593 | v16qi __builtin_ia32_vpcomfalseub (v16qi, v16qi) | |
10594 | v4si __builtin_ia32_vpcomfalseud (v4si, v4si) | |
10595 | v2di __builtin_ia32_vpcomfalseuq (v2di, v2di) | |
10596 | v8hi __builtin_ia32_vpcomfalseuw (v8hi, v8hi) | |
10597 | v8hi __builtin_ia32_vpcomfalsew (v8hi, v8hi) | |
10598 | v16qi __builtin_ia32_vpcomgeb (v16qi, v16qi) | |
10599 | v4si __builtin_ia32_vpcomged (v4si, v4si) | |
10600 | v2di __builtin_ia32_vpcomgeq (v2di, v2di) | |
10601 | v16qi __builtin_ia32_vpcomgeub (v16qi, v16qi) | |
10602 | v4si __builtin_ia32_vpcomgeud (v4si, v4si) | |
10603 | v2di __builtin_ia32_vpcomgeuq (v2di, v2di) | |
10604 | v8hi __builtin_ia32_vpcomgeuw (v8hi, v8hi) | |
10605 | v8hi __builtin_ia32_vpcomgew (v8hi, v8hi) | |
10606 | v16qi __builtin_ia32_vpcomgtb (v16qi, v16qi) | |
10607 | v4si __builtin_ia32_vpcomgtd (v4si, v4si) | |
10608 | v2di __builtin_ia32_vpcomgtq (v2di, v2di) | |
10609 | v16qi __builtin_ia32_vpcomgtub (v16qi, v16qi) | |
10610 | v4si __builtin_ia32_vpcomgtud (v4si, v4si) | |
10611 | v2di __builtin_ia32_vpcomgtuq (v2di, v2di) | |
10612 | v8hi __builtin_ia32_vpcomgtuw (v8hi, v8hi) | |
10613 | v8hi __builtin_ia32_vpcomgtw (v8hi, v8hi) | |
10614 | v16qi __builtin_ia32_vpcomleb (v16qi, v16qi) | |
10615 | v4si __builtin_ia32_vpcomled (v4si, v4si) | |
10616 | v2di __builtin_ia32_vpcomleq (v2di, v2di) | |
10617 | v16qi __builtin_ia32_vpcomleub (v16qi, v16qi) | |
10618 | v4si __builtin_ia32_vpcomleud (v4si, v4si) | |
10619 | v2di __builtin_ia32_vpcomleuq (v2di, v2di) | |
10620 | v8hi __builtin_ia32_vpcomleuw (v8hi, v8hi) | |
10621 | v8hi __builtin_ia32_vpcomlew (v8hi, v8hi) | |
10622 | v16qi __builtin_ia32_vpcomltb (v16qi, v16qi) | |
10623 | v4si __builtin_ia32_vpcomltd (v4si, v4si) | |
10624 | v2di __builtin_ia32_vpcomltq (v2di, v2di) | |
10625 | v16qi __builtin_ia32_vpcomltub (v16qi, v16qi) | |
10626 | v4si __builtin_ia32_vpcomltud (v4si, v4si) | |
10627 | v2di __builtin_ia32_vpcomltuq (v2di, v2di) | |
10628 | v8hi __builtin_ia32_vpcomltuw (v8hi, v8hi) | |
10629 | v8hi __builtin_ia32_vpcomltw (v8hi, v8hi) | |
10630 | v16qi __builtin_ia32_vpcomneb (v16qi, v16qi) | |
10631 | v4si __builtin_ia32_vpcomned (v4si, v4si) | |
10632 | v2di __builtin_ia32_vpcomneq (v2di, v2di) | |
10633 | v16qi __builtin_ia32_vpcomneub (v16qi, v16qi) | |
10634 | v4si __builtin_ia32_vpcomneud (v4si, v4si) | |
10635 | v2di __builtin_ia32_vpcomneuq (v2di, v2di) | |
10636 | v8hi __builtin_ia32_vpcomneuw (v8hi, v8hi) | |
10637 | v8hi __builtin_ia32_vpcomnew (v8hi, v8hi) | |
10638 | v16qi __builtin_ia32_vpcomtrueb (v16qi, v16qi) | |
10639 | v4si __builtin_ia32_vpcomtrued (v4si, v4si) | |
10640 | v2di __builtin_ia32_vpcomtrueq (v2di, v2di) | |
10641 | v16qi __builtin_ia32_vpcomtrueub (v16qi, v16qi) | |
10642 | v4si __builtin_ia32_vpcomtrueud (v4si, v4si) | |
10643 | v2di __builtin_ia32_vpcomtrueuq (v2di, v2di) | |
10644 | v8hi __builtin_ia32_vpcomtrueuw (v8hi, v8hi) | |
10645 | v8hi __builtin_ia32_vpcomtruew (v8hi, v8hi) | |
10646 | v4si __builtin_ia32_vphaddbd (v16qi) | |
10647 | v2di __builtin_ia32_vphaddbq (v16qi) | |
10648 | v8hi __builtin_ia32_vphaddbw (v16qi) | |
10649 | v2di __builtin_ia32_vphadddq (v4si) | |
10650 | v4si __builtin_ia32_vphaddubd (v16qi) | |
10651 | v2di __builtin_ia32_vphaddubq (v16qi) | |
10652 | v8hi __builtin_ia32_vphaddubw (v16qi) | |
10653 | v2di __builtin_ia32_vphaddudq (v4si) | |
10654 | v4si __builtin_ia32_vphadduwd (v8hi) | |
10655 | v2di __builtin_ia32_vphadduwq (v8hi) | |
10656 | v4si __builtin_ia32_vphaddwd (v8hi) | |
10657 | v2di __builtin_ia32_vphaddwq (v8hi) | |
10658 | v8hi __builtin_ia32_vphsubbw (v16qi) | |
10659 | v2di __builtin_ia32_vphsubdq (v4si) | |
10660 | v4si __builtin_ia32_vphsubwd (v8hi) | |
10661 | v4si __builtin_ia32_vpmacsdd (v4si, v4si, v4si) | |
10662 | v2di __builtin_ia32_vpmacsdqh (v4si, v4si, v2di) | |
10663 | v2di __builtin_ia32_vpmacsdql (v4si, v4si, v2di) | |
10664 | v4si __builtin_ia32_vpmacssdd (v4si, v4si, v4si) | |
10665 | v2di __builtin_ia32_vpmacssdqh (v4si, v4si, v2di) | |
10666 | v2di __builtin_ia32_vpmacssdql (v4si, v4si, v2di) | |
10667 | v4si __builtin_ia32_vpmacsswd (v8hi, v8hi, v4si) | |
10668 | v8hi __builtin_ia32_vpmacssww (v8hi, v8hi, v8hi) | |
10669 | v4si __builtin_ia32_vpmacswd (v8hi, v8hi, v4si) | |
10670 | v8hi __builtin_ia32_vpmacsww (v8hi, v8hi, v8hi) | |
10671 | v4si __builtin_ia32_vpmadcsswd (v8hi, v8hi, v4si) | |
10672 | v4si __builtin_ia32_vpmadcswd (v8hi, v8hi, v4si) | |
10673 | v16qi __builtin_ia32_vpperm (v16qi, v16qi, v16qi) | |
10674 | v16qi __builtin_ia32_vprotb (v16qi, v16qi) | |
10675 | v4si __builtin_ia32_vprotd (v4si, v4si) | |
10676 | v2di __builtin_ia32_vprotq (v2di, v2di) | |
10677 | v8hi __builtin_ia32_vprotw (v8hi, v8hi) | |
10678 | v16qi __builtin_ia32_vpshab (v16qi, v16qi) | |
10679 | v4si __builtin_ia32_vpshad (v4si, v4si) | |
10680 | v2di __builtin_ia32_vpshaq (v2di, v2di) | |
10681 | v8hi __builtin_ia32_vpshaw (v8hi, v8hi) | |
10682 | v16qi __builtin_ia32_vpshlb (v16qi, v16qi) | |
10683 | v4si __builtin_ia32_vpshld (v4si, v4si) | |
10684 | v2di __builtin_ia32_vpshlq (v2di, v2di) | |
10685 | v8hi __builtin_ia32_vpshlw (v8hi, v8hi) | |
10686 | @end smallexample | |
10687 | ||
2f212aae | 10688 | The following built-in functions are available when @option{-mfma4} is used. |
10689 | All of them generate the machine instruction that is part of the name | |
10690 | with MMX registers. | |
10691 | ||
10692 | @smallexample | |
10693 | v2df __builtin_ia32_fmaddpd (v2df, v2df, v2df) | |
10694 | v4sf __builtin_ia32_fmaddps (v4sf, v4sf, v4sf) | |
10695 | v2df __builtin_ia32_fmaddsd (v2df, v2df, v2df) | |
10696 | v4sf __builtin_ia32_fmaddss (v4sf, v4sf, v4sf) | |
10697 | v2df __builtin_ia32_fmsubpd (v2df, v2df, v2df) | |
10698 | v4sf __builtin_ia32_fmsubps (v4sf, v4sf, v4sf) | |
10699 | v2df __builtin_ia32_fmsubsd (v2df, v2df, v2df) | |
10700 | v4sf __builtin_ia32_fmsubss (v4sf, v4sf, v4sf) | |
10701 | v2df __builtin_ia32_fnmaddpd (v2df, v2df, v2df) | |
10702 | v4sf __builtin_ia32_fnmaddps (v4sf, v4sf, v4sf) | |
10703 | v2df __builtin_ia32_fnmaddsd (v2df, v2df, v2df) | |
10704 | v4sf __builtin_ia32_fnmaddss (v4sf, v4sf, v4sf) | |
10705 | v2df __builtin_ia32_fnmsubpd (v2df, v2df, v2df) | |
10706 | v4sf __builtin_ia32_fnmsubps (v4sf, v4sf, v4sf) | |
10707 | v2df __builtin_ia32_fnmsubsd (v2df, v2df, v2df) | |
10708 | v4sf __builtin_ia32_fnmsubss (v4sf, v4sf, v4sf) | |
10709 | v2df __builtin_ia32_fmaddsubpd (v2df, v2df, v2df) | |
10710 | v4sf __builtin_ia32_fmaddsubps (v4sf, v4sf, v4sf) | |
10711 | v2df __builtin_ia32_fmsubaddpd (v2df, v2df, v2df) | |
10712 | v4sf __builtin_ia32_fmsubaddps (v4sf, v4sf, v4sf) | |
10713 | v4df __builtin_ia32_fmaddpd256 (v4df, v4df, v4df) | |
10714 | v8sf __builtin_ia32_fmaddps256 (v8sf, v8sf, v8sf) | |
10715 | v4df __builtin_ia32_fmsubpd256 (v4df, v4df, v4df) | |
10716 | v8sf __builtin_ia32_fmsubps256 (v8sf, v8sf, v8sf) | |
10717 | v4df __builtin_ia32_fnmaddpd256 (v4df, v4df, v4df) | |
10718 | v8sf __builtin_ia32_fnmaddps256 (v8sf, v8sf, v8sf) | |
10719 | v4df __builtin_ia32_fnmsubpd256 (v4df, v4df, v4df) | |
10720 | v8sf __builtin_ia32_fnmsubps256 (v8sf, v8sf, v8sf) | |
10721 | v4df __builtin_ia32_fmaddsubpd256 (v4df, v4df, v4df) | |
10722 | v8sf __builtin_ia32_fmaddsubps256 (v8sf, v8sf, v8sf) | |
10723 | v4df __builtin_ia32_fmsubaddpd256 (v4df, v4df, v4df) | |
10724 | v8sf __builtin_ia32_fmsubaddps256 (v8sf, v8sf, v8sf) | |
10725 | ||
10726 | @end smallexample | |
048fbb59 | 10727 | |
10728 | The following built-in functions are available when @option{-mlwp} is used. | |
10729 | ||
10730 | @smallexample | |
10731 | void __builtin_ia32_llwpcb16 (void *); | |
10732 | void __builtin_ia32_llwpcb32 (void *); | |
10733 | void __builtin_ia32_llwpcb64 (void *); | |
10734 | void * __builtin_ia32_llwpcb16 (void); | |
10735 | void * __builtin_ia32_llwpcb32 (void); | |
10736 | void * __builtin_ia32_llwpcb64 (void); | |
10737 | void __builtin_ia32_lwpval16 (unsigned short, unsigned int, unsigned short) | |
10738 | void __builtin_ia32_lwpval32 (unsigned int, unsigned int, unsigned int) | |
10739 | void __builtin_ia32_lwpval64 (unsigned __int64, unsigned int, unsigned int) | |
10740 | unsigned char __builtin_ia32_lwpins16 (unsigned short, unsigned int, unsigned short) | |
10741 | unsigned char __builtin_ia32_lwpins32 (unsigned int, unsigned int, unsigned int) | |
10742 | unsigned char __builtin_ia32_lwpins64 (unsigned __int64, unsigned int, unsigned int) | |
10743 | @end smallexample | |
2f212aae | 10744 | |
02024195 | 10745 | The following built-in functions are available when @option{-mbmi} is used. |
10746 | All of them generate the machine instruction that is part of the name. | |
10747 | @smallexample | |
10748 | unsigned int __builtin_ia32_bextr_u32(unsigned int, unsigned int); | |
10749 | unsigned long long __builtin_ia32_bextr_u64 (unsigned long long, unsigned long long); | |
a3398ee6 | 10750 | @end smallexample |
10751 | ||
2339767f | 10752 | The following built-in functions are available when @option{-mbmi2} is used. |
10753 | All of them generate the machine instruction that is part of the name. | |
10754 | @smallexample | |
10755 | unsigned int _bzhi_u32 (unsigned int, unsigned int) | |
10756 | unsigned int _pdep_u32 (unsigned int, unsigned int) | |
10757 | unsigned int _pext_u32 (unsigned int, unsigned int) | |
10758 | unsigned long long _bzhi_u64 (unsigned long long, unsigned long long) | |
10759 | unsigned long long _pdep_u64 (unsigned long long, unsigned long long) | |
10760 | unsigned long long _pext_u64 (unsigned long long, unsigned long long) | |
10761 | @end smallexample | |
10762 | ||
a3398ee6 | 10763 | The following built-in functions are available when @option{-mlzcnt} is used. |
10764 | All of them generate the machine instruction that is part of the name. | |
10765 | @smallexample | |
02024195 | 10766 | unsigned short __builtin_ia32_lzcnt_16(unsigned short); |
10767 | unsigned int __builtin_ia32_lzcnt_u32(unsigned int); | |
10768 | unsigned long long __builtin_ia32_lzcnt_u64 (unsigned long long); | |
10769 | @end smallexample | |
10770 | ||
2c1d4003 | 10771 | The following built-in functions are available when @option{-mtbm} is used. |
10772 | Both of them generate the immediate form of the bextr machine instruction. | |
10773 | @smallexample | |
10774 | unsigned int __builtin_ia32_bextri_u32 (unsigned int, const unsigned int); | |
10775 | unsigned long long __builtin_ia32_bextri_u64 (unsigned long long, const unsigned long long); | |
10776 | @end smallexample | |
10777 | ||
10778 | ||
ca5827cf | 10779 | The following built-in functions are available when @option{-m3dnow} is used. |
10780 | All of them generate the machine instruction that is part of the name. | |
10781 | ||
a0ecd6b1 | 10782 | @smallexample |
ca5827cf | 10783 | void __builtin_ia32_femms (void) |
10784 | v8qi __builtin_ia32_pavgusb (v8qi, v8qi) | |
10785 | v2si __builtin_ia32_pf2id (v2sf) | |
10786 | v2sf __builtin_ia32_pfacc (v2sf, v2sf) | |
10787 | v2sf __builtin_ia32_pfadd (v2sf, v2sf) | |
10788 | v2si __builtin_ia32_pfcmpeq (v2sf, v2sf) | |
10789 | v2si __builtin_ia32_pfcmpge (v2sf, v2sf) | |
10790 | v2si __builtin_ia32_pfcmpgt (v2sf, v2sf) | |
10791 | v2sf __builtin_ia32_pfmax (v2sf, v2sf) | |
10792 | v2sf __builtin_ia32_pfmin (v2sf, v2sf) | |
10793 | v2sf __builtin_ia32_pfmul (v2sf, v2sf) | |
10794 | v2sf __builtin_ia32_pfrcp (v2sf) | |
10795 | v2sf __builtin_ia32_pfrcpit1 (v2sf, v2sf) | |
10796 | v2sf __builtin_ia32_pfrcpit2 (v2sf, v2sf) | |
10797 | v2sf __builtin_ia32_pfrsqrt (v2sf) | |
10798 | v2sf __builtin_ia32_pfrsqrtit1 (v2sf, v2sf) | |
10799 | v2sf __builtin_ia32_pfsub (v2sf, v2sf) | |
10800 | v2sf __builtin_ia32_pfsubr (v2sf, v2sf) | |
10801 | v2sf __builtin_ia32_pi2fd (v2si) | |
10802 | v4hi __builtin_ia32_pmulhrw (v4hi, v4hi) | |
a0ecd6b1 | 10803 | @end smallexample |
ca5827cf | 10804 | |
10805 | The following built-in functions are available when both @option{-m3dnow} | |
10806 | and @option{-march=athlon} are used. All of them generate the machine | |
10807 | instruction that is part of the name. | |
10808 | ||
a0ecd6b1 | 10809 | @smallexample |
ca5827cf | 10810 | v2si __builtin_ia32_pf2iw (v2sf) |
10811 | v2sf __builtin_ia32_pfnacc (v2sf, v2sf) | |
10812 | v2sf __builtin_ia32_pfpnacc (v2sf, v2sf) | |
10813 | v2sf __builtin_ia32_pi2fw (v2si) | |
10814 | v2sf __builtin_ia32_pswapdsf (v2sf) | |
10815 | v2si __builtin_ia32_pswapdsi (v2si) | |
a0ecd6b1 | 10816 | @end smallexample |
ca5827cf | 10817 | |
b7efe757 | 10818 | @node MIPS DSP Built-in Functions |
10819 | @subsection MIPS DSP Built-in Functions | |
10820 | ||
10821 | The MIPS DSP Application-Specific Extension (ASE) includes new | |
10822 | instructions that are designed to improve the performance of DSP and | |
10823 | media applications. It provides instructions that operate on packed | |
c1901bc7 | 10824 | 8-bit/16-bit integer data, Q7, Q15 and Q31 fractional data. |
b7efe757 | 10825 | |
10826 | GCC supports MIPS DSP operations using both the generic | |
10827 | vector extensions (@pxref{Vector Extensions}) and a collection of | |
10828 | MIPS-specific built-in functions. Both kinds of support are | |
10829 | enabled by the @option{-mdsp} command-line option. | |
10830 | ||
c1901bc7 | 10831 | Revision 2 of the ASE was introduced in the second half of 2006. |
10832 | This revision adds extra instructions to the original ASE, but is | |
10833 | otherwise backwards-compatible with it. You can select revision 2 | |
10834 | using the command-line option @option{-mdspr2}; this option implies | |
10835 | @option{-mdsp}. | |
10836 | ||
d036db4d | 10837 | The SCOUNT and POS bits of the DSP control register are global. The |
10838 | WRDSP, EXTPDP, EXTPDPV and MTHLIP instructions modify the SCOUNT and | |
10839 | POS bits. During optimization, the compiler will not delete these | |
10840 | instructions and it will not delete calls to functions containing | |
10841 | these instructions. | |
10842 | ||
b7efe757 | 10843 | At present, GCC only provides support for operations on 32-bit |
10844 | vectors. The vector type associated with 8-bit integer data is | |
c1901bc7 | 10845 | usually called @code{v4i8}, the vector type associated with Q7 |
10846 | is usually called @code{v4q7}, the vector type associated with 16-bit | |
10847 | integer data is usually called @code{v2i16}, and the vector type | |
10848 | associated with Q15 is usually called @code{v2q15}. They can be | |
10849 | defined in C as follows: | |
b7efe757 | 10850 | |
10851 | @smallexample | |
c1901bc7 | 10852 | typedef signed char v4i8 __attribute__ ((vector_size(4))); |
10853 | typedef signed char v4q7 __attribute__ ((vector_size(4))); | |
10854 | typedef short v2i16 __attribute__ ((vector_size(4))); | |
b7efe757 | 10855 | typedef short v2q15 __attribute__ ((vector_size(4))); |
10856 | @end smallexample | |
10857 | ||
c1901bc7 | 10858 | @code{v4i8}, @code{v4q7}, @code{v2i16} and @code{v2q15} values are |
10859 | initialized in the same way as aggregates. For example: | |
b7efe757 | 10860 | |
10861 | @smallexample | |
10862 | v4i8 a = @{1, 2, 3, 4@}; | |
10863 | v4i8 b; | |
10864 | b = (v4i8) @{5, 6, 7, 8@}; | |
10865 | ||
10866 | v2q15 c = @{0x0fcb, 0x3a75@}; | |
10867 | v2q15 d; | |
10868 | d = (v2q15) @{0.1234 * 0x1.0p15, 0.4567 * 0x1.0p15@}; | |
10869 | @end smallexample | |
10870 | ||
10871 | @emph{Note:} The CPU's endianness determines the order in which values | |
10872 | are packed. On little-endian targets, the first value is the least | |
10873 | significant and the last value is the most significant. The opposite | |
10874 | order applies to big-endian targets. For example, the code above will | |
10875 | set the lowest byte of @code{a} to @code{1} on little-endian targets | |
10876 | and @code{4} on big-endian targets. | |
10877 | ||
c1901bc7 | 10878 | @emph{Note:} Q7, Q15 and Q31 values must be initialized with their integer |
b7efe757 | 10879 | representation. As shown in this example, the integer representation |
c1901bc7 | 10880 | of a Q7 value can be obtained by multiplying the fractional value by |
10881 | @code{0x1.0p7}. The equivalent for Q15 values is to multiply by | |
b7efe757 | 10882 | @code{0x1.0p15}. The equivalent for Q31 values is to multiply by |
10883 | @code{0x1.0p31}. | |
10884 | ||
10885 | The table below lists the @code{v4i8} and @code{v2q15} operations for which | |
10886 | hardware support exists. @code{a} and @code{b} are @code{v4i8} values, | |
10887 | and @code{c} and @code{d} are @code{v2q15} values. | |
10888 | ||
10889 | @multitable @columnfractions .50 .50 | |
10890 | @item C code @tab MIPS instruction | |
10891 | @item @code{a + b} @tab @code{addu.qb} | |
10892 | @item @code{c + d} @tab @code{addq.ph} | |
10893 | @item @code{a - b} @tab @code{subu.qb} | |
10894 | @item @code{c - d} @tab @code{subq.ph} | |
10895 | @end multitable | |
10896 | ||
c1901bc7 | 10897 | The table below lists the @code{v2i16} operation for which |
10898 | hardware support exists for the DSP ASE REV 2. @code{e} and @code{f} are | |
10899 | @code{v2i16} values. | |
10900 | ||
10901 | @multitable @columnfractions .50 .50 | |
10902 | @item C code @tab MIPS instruction | |
10903 | @item @code{e * f} @tab @code{mul.ph} | |
10904 | @end multitable | |
10905 | ||
b7efe757 | 10906 | It is easier to describe the DSP built-in functions if we first define |
10907 | the following types: | |
10908 | ||
10909 | @smallexample | |
10910 | typedef int q31; | |
10911 | typedef int i32; | |
c1901bc7 | 10912 | typedef unsigned int ui32; |
b7efe757 | 10913 | typedef long long a64; |
10914 | @end smallexample | |
10915 | ||
10916 | @code{q31} and @code{i32} are actually the same as @code{int}, but we | |
10917 | use @code{q31} to indicate a Q31 fractional value and @code{i32} to | |
10918 | indicate a 32-bit integer value. Similarly, @code{a64} is the same as | |
10919 | @code{long long}, but we use @code{a64} to indicate values that will | |
10920 | be placed in one of the four DSP accumulators (@code{$ac0}, | |
10921 | @code{$ac1}, @code{$ac2} or @code{$ac3}). | |
10922 | ||
10923 | Also, some built-in functions prefer or require immediate numbers as | |
10924 | parameters, because the corresponding DSP instructions accept both immediate | |
10925 | numbers and register operands, or accept immediate numbers only. The | |
10926 | immediate parameters are listed as follows. | |
10927 | ||
10928 | @smallexample | |
c1901bc7 | 10929 | imm0_3: 0 to 3. |
b7efe757 | 10930 | imm0_7: 0 to 7. |
10931 | imm0_15: 0 to 15. | |
10932 | imm0_31: 0 to 31. | |
10933 | imm0_63: 0 to 63. | |
10934 | imm0_255: 0 to 255. | |
10935 | imm_n32_31: -32 to 31. | |
10936 | imm_n512_511: -512 to 511. | |
10937 | @end smallexample | |
10938 | ||
10939 | The following built-in functions map directly to a particular MIPS DSP | |
10940 | instruction. Please refer to the architecture specification | |
10941 | for details on what each instruction does. | |
10942 | ||
10943 | @smallexample | |
10944 | v2q15 __builtin_mips_addq_ph (v2q15, v2q15) | |
10945 | v2q15 __builtin_mips_addq_s_ph (v2q15, v2q15) | |
10946 | q31 __builtin_mips_addq_s_w (q31, q31) | |
10947 | v4i8 __builtin_mips_addu_qb (v4i8, v4i8) | |
10948 | v4i8 __builtin_mips_addu_s_qb (v4i8, v4i8) | |
10949 | v2q15 __builtin_mips_subq_ph (v2q15, v2q15) | |
10950 | v2q15 __builtin_mips_subq_s_ph (v2q15, v2q15) | |
10951 | q31 __builtin_mips_subq_s_w (q31, q31) | |
10952 | v4i8 __builtin_mips_subu_qb (v4i8, v4i8) | |
10953 | v4i8 __builtin_mips_subu_s_qb (v4i8, v4i8) | |
10954 | i32 __builtin_mips_addsc (i32, i32) | |
10955 | i32 __builtin_mips_addwc (i32, i32) | |
10956 | i32 __builtin_mips_modsub (i32, i32) | |
10957 | i32 __builtin_mips_raddu_w_qb (v4i8) | |
10958 | v2q15 __builtin_mips_absq_s_ph (v2q15) | |
10959 | q31 __builtin_mips_absq_s_w (q31) | |
10960 | v4i8 __builtin_mips_precrq_qb_ph (v2q15, v2q15) | |
10961 | v2q15 __builtin_mips_precrq_ph_w (q31, q31) | |
10962 | v2q15 __builtin_mips_precrq_rs_ph_w (q31, q31) | |
10963 | v4i8 __builtin_mips_precrqu_s_qb_ph (v2q15, v2q15) | |
10964 | q31 __builtin_mips_preceq_w_phl (v2q15) | |
10965 | q31 __builtin_mips_preceq_w_phr (v2q15) | |
10966 | v2q15 __builtin_mips_precequ_ph_qbl (v4i8) | |
10967 | v2q15 __builtin_mips_precequ_ph_qbr (v4i8) | |
10968 | v2q15 __builtin_mips_precequ_ph_qbla (v4i8) | |
10969 | v2q15 __builtin_mips_precequ_ph_qbra (v4i8) | |
10970 | v2q15 __builtin_mips_preceu_ph_qbl (v4i8) | |
10971 | v2q15 __builtin_mips_preceu_ph_qbr (v4i8) | |
10972 | v2q15 __builtin_mips_preceu_ph_qbla (v4i8) | |
10973 | v2q15 __builtin_mips_preceu_ph_qbra (v4i8) | |
10974 | v4i8 __builtin_mips_shll_qb (v4i8, imm0_7) | |
10975 | v4i8 __builtin_mips_shll_qb (v4i8, i32) | |
10976 | v2q15 __builtin_mips_shll_ph (v2q15, imm0_15) | |
10977 | v2q15 __builtin_mips_shll_ph (v2q15, i32) | |
10978 | v2q15 __builtin_mips_shll_s_ph (v2q15, imm0_15) | |
10979 | v2q15 __builtin_mips_shll_s_ph (v2q15, i32) | |
10980 | q31 __builtin_mips_shll_s_w (q31, imm0_31) | |
10981 | q31 __builtin_mips_shll_s_w (q31, i32) | |
10982 | v4i8 __builtin_mips_shrl_qb (v4i8, imm0_7) | |
10983 | v4i8 __builtin_mips_shrl_qb (v4i8, i32) | |
10984 | v2q15 __builtin_mips_shra_ph (v2q15, imm0_15) | |
10985 | v2q15 __builtin_mips_shra_ph (v2q15, i32) | |
10986 | v2q15 __builtin_mips_shra_r_ph (v2q15, imm0_15) | |
10987 | v2q15 __builtin_mips_shra_r_ph (v2q15, i32) | |
10988 | q31 __builtin_mips_shra_r_w (q31, imm0_31) | |
10989 | q31 __builtin_mips_shra_r_w (q31, i32) | |
10990 | v2q15 __builtin_mips_muleu_s_ph_qbl (v4i8, v2q15) | |
10991 | v2q15 __builtin_mips_muleu_s_ph_qbr (v4i8, v2q15) | |
10992 | v2q15 __builtin_mips_mulq_rs_ph (v2q15, v2q15) | |
10993 | q31 __builtin_mips_muleq_s_w_phl (v2q15, v2q15) | |
10994 | q31 __builtin_mips_muleq_s_w_phr (v2q15, v2q15) | |
10995 | a64 __builtin_mips_dpau_h_qbl (a64, v4i8, v4i8) | |
10996 | a64 __builtin_mips_dpau_h_qbr (a64, v4i8, v4i8) | |
10997 | a64 __builtin_mips_dpsu_h_qbl (a64, v4i8, v4i8) | |
10998 | a64 __builtin_mips_dpsu_h_qbr (a64, v4i8, v4i8) | |
10999 | a64 __builtin_mips_dpaq_s_w_ph (a64, v2q15, v2q15) | |
11000 | a64 __builtin_mips_dpaq_sa_l_w (a64, q31, q31) | |
11001 | a64 __builtin_mips_dpsq_s_w_ph (a64, v2q15, v2q15) | |
11002 | a64 __builtin_mips_dpsq_sa_l_w (a64, q31, q31) | |
11003 | a64 __builtin_mips_mulsaq_s_w_ph (a64, v2q15, v2q15) | |
11004 | a64 __builtin_mips_maq_s_w_phl (a64, v2q15, v2q15) | |
11005 | a64 __builtin_mips_maq_s_w_phr (a64, v2q15, v2q15) | |
11006 | a64 __builtin_mips_maq_sa_w_phl (a64, v2q15, v2q15) | |
11007 | a64 __builtin_mips_maq_sa_w_phr (a64, v2q15, v2q15) | |
11008 | i32 __builtin_mips_bitrev (i32) | |
11009 | i32 __builtin_mips_insv (i32, i32) | |
11010 | v4i8 __builtin_mips_repl_qb (imm0_255) | |
11011 | v4i8 __builtin_mips_repl_qb (i32) | |
11012 | v2q15 __builtin_mips_repl_ph (imm_n512_511) | |
11013 | v2q15 __builtin_mips_repl_ph (i32) | |
11014 | void __builtin_mips_cmpu_eq_qb (v4i8, v4i8) | |
11015 | void __builtin_mips_cmpu_lt_qb (v4i8, v4i8) | |
11016 | void __builtin_mips_cmpu_le_qb (v4i8, v4i8) | |
11017 | i32 __builtin_mips_cmpgu_eq_qb (v4i8, v4i8) | |
11018 | i32 __builtin_mips_cmpgu_lt_qb (v4i8, v4i8) | |
11019 | i32 __builtin_mips_cmpgu_le_qb (v4i8, v4i8) | |
11020 | void __builtin_mips_cmp_eq_ph (v2q15, v2q15) | |
11021 | void __builtin_mips_cmp_lt_ph (v2q15, v2q15) | |
11022 | void __builtin_mips_cmp_le_ph (v2q15, v2q15) | |
11023 | v4i8 __builtin_mips_pick_qb (v4i8, v4i8) | |
11024 | v2q15 __builtin_mips_pick_ph (v2q15, v2q15) | |
11025 | v2q15 __builtin_mips_packrl_ph (v2q15, v2q15) | |
11026 | i32 __builtin_mips_extr_w (a64, imm0_31) | |
11027 | i32 __builtin_mips_extr_w (a64, i32) | |
11028 | i32 __builtin_mips_extr_r_w (a64, imm0_31) | |
11029 | i32 __builtin_mips_extr_s_h (a64, i32) | |
11030 | i32 __builtin_mips_extr_rs_w (a64, imm0_31) | |
11031 | i32 __builtin_mips_extr_rs_w (a64, i32) | |
11032 | i32 __builtin_mips_extr_s_h (a64, imm0_31) | |
11033 | i32 __builtin_mips_extr_r_w (a64, i32) | |
11034 | i32 __builtin_mips_extp (a64, imm0_31) | |
11035 | i32 __builtin_mips_extp (a64, i32) | |
11036 | i32 __builtin_mips_extpdp (a64, imm0_31) | |
11037 | i32 __builtin_mips_extpdp (a64, i32) | |
11038 | a64 __builtin_mips_shilo (a64, imm_n32_31) | |
11039 | a64 __builtin_mips_shilo (a64, i32) | |
11040 | a64 __builtin_mips_mthlip (a64, i32) | |
11041 | void __builtin_mips_wrdsp (i32, imm0_63) | |
11042 | i32 __builtin_mips_rddsp (imm0_63) | |
11043 | i32 __builtin_mips_lbux (void *, i32) | |
11044 | i32 __builtin_mips_lhx (void *, i32) | |
11045 | i32 __builtin_mips_lwx (void *, i32) | |
b7508909 | 11046 | a64 __builtin_mips_ldx (void *, i32) [MIPS64 only] |
b7efe757 | 11047 | i32 __builtin_mips_bposge32 (void) |
3e60fdb7 | 11048 | a64 __builtin_mips_madd (a64, i32, i32); |
11049 | a64 __builtin_mips_maddu (a64, ui32, ui32); | |
11050 | a64 __builtin_mips_msub (a64, i32, i32); | |
11051 | a64 __builtin_mips_msubu (a64, ui32, ui32); | |
11052 | a64 __builtin_mips_mult (i32, i32); | |
11053 | a64 __builtin_mips_multu (ui32, ui32); | |
b7efe757 | 11054 | @end smallexample |
11055 | ||
c1901bc7 | 11056 | The following built-in functions map directly to a particular MIPS DSP REV 2 |
11057 | instruction. Please refer to the architecture specification | |
11058 | for details on what each instruction does. | |
11059 | ||
11060 | @smallexample | |
11061 | v4q7 __builtin_mips_absq_s_qb (v4q7); | |
11062 | v2i16 __builtin_mips_addu_ph (v2i16, v2i16); | |
11063 | v2i16 __builtin_mips_addu_s_ph (v2i16, v2i16); | |
11064 | v4i8 __builtin_mips_adduh_qb (v4i8, v4i8); | |
11065 | v4i8 __builtin_mips_adduh_r_qb (v4i8, v4i8); | |
11066 | i32 __builtin_mips_append (i32, i32, imm0_31); | |
11067 | i32 __builtin_mips_balign (i32, i32, imm0_3); | |
11068 | i32 __builtin_mips_cmpgdu_eq_qb (v4i8, v4i8); | |
11069 | i32 __builtin_mips_cmpgdu_lt_qb (v4i8, v4i8); | |
11070 | i32 __builtin_mips_cmpgdu_le_qb (v4i8, v4i8); | |
11071 | a64 __builtin_mips_dpa_w_ph (a64, v2i16, v2i16); | |
11072 | a64 __builtin_mips_dps_w_ph (a64, v2i16, v2i16); | |
c1901bc7 | 11073 | v2i16 __builtin_mips_mul_ph (v2i16, v2i16); |
11074 | v2i16 __builtin_mips_mul_s_ph (v2i16, v2i16); | |
11075 | q31 __builtin_mips_mulq_rs_w (q31, q31); | |
11076 | v2q15 __builtin_mips_mulq_s_ph (v2q15, v2q15); | |
11077 | q31 __builtin_mips_mulq_s_w (q31, q31); | |
11078 | a64 __builtin_mips_mulsa_w_ph (a64, v2i16, v2i16); | |
c1901bc7 | 11079 | v4i8 __builtin_mips_precr_qb_ph (v2i16, v2i16); |
11080 | v2i16 __builtin_mips_precr_sra_ph_w (i32, i32, imm0_31); | |
11081 | v2i16 __builtin_mips_precr_sra_r_ph_w (i32, i32, imm0_31); | |
11082 | i32 __builtin_mips_prepend (i32, i32, imm0_31); | |
11083 | v4i8 __builtin_mips_shra_qb (v4i8, imm0_7); | |
11084 | v4i8 __builtin_mips_shra_r_qb (v4i8, imm0_7); | |
11085 | v4i8 __builtin_mips_shra_qb (v4i8, i32); | |
11086 | v4i8 __builtin_mips_shra_r_qb (v4i8, i32); | |
11087 | v2i16 __builtin_mips_shrl_ph (v2i16, imm0_15); | |
11088 | v2i16 __builtin_mips_shrl_ph (v2i16, i32); | |
11089 | v2i16 __builtin_mips_subu_ph (v2i16, v2i16); | |
11090 | v2i16 __builtin_mips_subu_s_ph (v2i16, v2i16); | |
11091 | v4i8 __builtin_mips_subuh_qb (v4i8, v4i8); | |
11092 | v4i8 __builtin_mips_subuh_r_qb (v4i8, v4i8); | |
11093 | v2q15 __builtin_mips_addqh_ph (v2q15, v2q15); | |
11094 | v2q15 __builtin_mips_addqh_r_ph (v2q15, v2q15); | |
11095 | q31 __builtin_mips_addqh_w (q31, q31); | |
11096 | q31 __builtin_mips_addqh_r_w (q31, q31); | |
11097 | v2q15 __builtin_mips_subqh_ph (v2q15, v2q15); | |
11098 | v2q15 __builtin_mips_subqh_r_ph (v2q15, v2q15); | |
11099 | q31 __builtin_mips_subqh_w (q31, q31); | |
11100 | q31 __builtin_mips_subqh_r_w (q31, q31); | |
11101 | a64 __builtin_mips_dpax_w_ph (a64, v2i16, v2i16); | |
11102 | a64 __builtin_mips_dpsx_w_ph (a64, v2i16, v2i16); | |
11103 | a64 __builtin_mips_dpaqx_s_w_ph (a64, v2q15, v2q15); | |
11104 | a64 __builtin_mips_dpaqx_sa_w_ph (a64, v2q15, v2q15); | |
11105 | a64 __builtin_mips_dpsqx_s_w_ph (a64, v2q15, v2q15); | |
11106 | a64 __builtin_mips_dpsqx_sa_w_ph (a64, v2q15, v2q15); | |
11107 | @end smallexample | |
11108 | ||
11109 | ||
dd2a386a | 11110 | @node MIPS Paired-Single Support |
11111 | @subsection MIPS Paired-Single Support | |
11112 | ||
11113 | The MIPS64 architecture includes a number of instructions that | |
11114 | operate on pairs of single-precision floating-point values. | |
11115 | Each pair is packed into a 64-bit floating-point register, | |
11116 | with one element being designated the ``upper half'' and | |
11117 | the other being designated the ``lower half''. | |
11118 | ||
11119 | GCC supports paired-single operations using both the generic | |
11120 | vector extensions (@pxref{Vector Extensions}) and a collection of | |
11121 | MIPS-specific built-in functions. Both kinds of support are | |
11122 | enabled by the @option{-mpaired-single} command-line option. | |
11123 | ||
11124 | The vector type associated with paired-single values is usually | |
11125 | called @code{v2sf}. It can be defined in C as follows: | |
11126 | ||
11127 | @smallexample | |
11128 | typedef float v2sf __attribute__ ((vector_size (8))); | |
11129 | @end smallexample | |
11130 | ||
11131 | @code{v2sf} values are initialized in the same way as aggregates. | |
11132 | For example: | |
11133 | ||
11134 | @smallexample | |
11135 | v2sf a = @{1.5, 9.1@}; | |
11136 | v2sf b; | |
11137 | float e, f; | |
11138 | b = (v2sf) @{e, f@}; | |
11139 | @end smallexample | |
11140 | ||
11141 | @emph{Note:} The CPU's endianness determines which value is stored in | |
11142 | the upper half of a register and which value is stored in the lower half. | |
11143 | On little-endian targets, the first value is the lower one and the second | |
11144 | value is the upper one. The opposite order applies to big-endian targets. | |
11145 | For example, the code above will set the lower half of @code{a} to | |
11146 | @code{1.5} on little-endian targets and @code{9.1} on big-endian targets. | |
11147 | ||
9636921b | 11148 | @node MIPS Loongson Built-in Functions |
11149 | @subsection MIPS Loongson Built-in Functions | |
11150 | ||
11151 | GCC provides intrinsics to access the SIMD instructions provided by the | |
11152 | ST Microelectronics Loongson-2E and -2F processors. These intrinsics, | |
11153 | available after inclusion of the @code{loongson.h} header file, | |
11154 | operate on the following 64-bit vector types: | |
11155 | ||
11156 | @itemize | |
11157 | @item @code{uint8x8_t}, a vector of eight unsigned 8-bit integers; | |
11158 | @item @code{uint16x4_t}, a vector of four unsigned 16-bit integers; | |
11159 | @item @code{uint32x2_t}, a vector of two unsigned 32-bit integers; | |
11160 | @item @code{int8x8_t}, a vector of eight signed 8-bit integers; | |
11161 | @item @code{int16x4_t}, a vector of four signed 16-bit integers; | |
11162 | @item @code{int32x2_t}, a vector of two signed 32-bit integers. | |
11163 | @end itemize | |
11164 | ||
11165 | The intrinsics provided are listed below; each is named after the | |
11166 | machine instruction to which it corresponds, with suffixes added as | |
11167 | appropriate to distinguish intrinsics that expand to the same machine | |
11168 | instruction yet have different argument types. Refer to the architecture | |
11169 | documentation for a description of the functionality of each | |
11170 | instruction. | |
11171 | ||
11172 | @smallexample | |
11173 | int16x4_t packsswh (int32x2_t s, int32x2_t t); | |
11174 | int8x8_t packsshb (int16x4_t s, int16x4_t t); | |
11175 | uint8x8_t packushb (uint16x4_t s, uint16x4_t t); | |
11176 | uint32x2_t paddw_u (uint32x2_t s, uint32x2_t t); | |
11177 | uint16x4_t paddh_u (uint16x4_t s, uint16x4_t t); | |
11178 | uint8x8_t paddb_u (uint8x8_t s, uint8x8_t t); | |
11179 | int32x2_t paddw_s (int32x2_t s, int32x2_t t); | |
11180 | int16x4_t paddh_s (int16x4_t s, int16x4_t t); | |
11181 | int8x8_t paddb_s (int8x8_t s, int8x8_t t); | |
11182 | uint64_t paddd_u (uint64_t s, uint64_t t); | |
11183 | int64_t paddd_s (int64_t s, int64_t t); | |
11184 | int16x4_t paddsh (int16x4_t s, int16x4_t t); | |
11185 | int8x8_t paddsb (int8x8_t s, int8x8_t t); | |
11186 | uint16x4_t paddush (uint16x4_t s, uint16x4_t t); | |
11187 | uint8x8_t paddusb (uint8x8_t s, uint8x8_t t); | |
11188 | uint64_t pandn_ud (uint64_t s, uint64_t t); | |
11189 | uint32x2_t pandn_uw (uint32x2_t s, uint32x2_t t); | |
11190 | uint16x4_t pandn_uh (uint16x4_t s, uint16x4_t t); | |
11191 | uint8x8_t pandn_ub (uint8x8_t s, uint8x8_t t); | |
11192 | int64_t pandn_sd (int64_t s, int64_t t); | |
11193 | int32x2_t pandn_sw (int32x2_t s, int32x2_t t); | |
11194 | int16x4_t pandn_sh (int16x4_t s, int16x4_t t); | |
11195 | int8x8_t pandn_sb (int8x8_t s, int8x8_t t); | |
11196 | uint16x4_t pavgh (uint16x4_t s, uint16x4_t t); | |
11197 | uint8x8_t pavgb (uint8x8_t s, uint8x8_t t); | |
11198 | uint32x2_t pcmpeqw_u (uint32x2_t s, uint32x2_t t); | |
11199 | uint16x4_t pcmpeqh_u (uint16x4_t s, uint16x4_t t); | |
11200 | uint8x8_t pcmpeqb_u (uint8x8_t s, uint8x8_t t); | |
11201 | int32x2_t pcmpeqw_s (int32x2_t s, int32x2_t t); | |
11202 | int16x4_t pcmpeqh_s (int16x4_t s, int16x4_t t); | |
11203 | int8x8_t pcmpeqb_s (int8x8_t s, int8x8_t t); | |
11204 | uint32x2_t pcmpgtw_u (uint32x2_t s, uint32x2_t t); | |
11205 | uint16x4_t pcmpgth_u (uint16x4_t s, uint16x4_t t); | |
11206 | uint8x8_t pcmpgtb_u (uint8x8_t s, uint8x8_t t); | |
11207 | int32x2_t pcmpgtw_s (int32x2_t s, int32x2_t t); | |
11208 | int16x4_t pcmpgth_s (int16x4_t s, int16x4_t t); | |
11209 | int8x8_t pcmpgtb_s (int8x8_t s, int8x8_t t); | |
11210 | uint16x4_t pextrh_u (uint16x4_t s, int field); | |
11211 | int16x4_t pextrh_s (int16x4_t s, int field); | |
11212 | uint16x4_t pinsrh_0_u (uint16x4_t s, uint16x4_t t); | |
11213 | uint16x4_t pinsrh_1_u (uint16x4_t s, uint16x4_t t); | |
11214 | uint16x4_t pinsrh_2_u (uint16x4_t s, uint16x4_t t); | |
11215 | uint16x4_t pinsrh_3_u (uint16x4_t s, uint16x4_t t); | |
11216 | int16x4_t pinsrh_0_s (int16x4_t s, int16x4_t t); | |
11217 | int16x4_t pinsrh_1_s (int16x4_t s, int16x4_t t); | |
11218 | int16x4_t pinsrh_2_s (int16x4_t s, int16x4_t t); | |
11219 | int16x4_t pinsrh_3_s (int16x4_t s, int16x4_t t); | |
11220 | int32x2_t pmaddhw (int16x4_t s, int16x4_t t); | |
11221 | int16x4_t pmaxsh (int16x4_t s, int16x4_t t); | |
11222 | uint8x8_t pmaxub (uint8x8_t s, uint8x8_t t); | |
11223 | int16x4_t pminsh (int16x4_t s, int16x4_t t); | |
11224 | uint8x8_t pminub (uint8x8_t s, uint8x8_t t); | |
11225 | uint8x8_t pmovmskb_u (uint8x8_t s); | |
11226 | int8x8_t pmovmskb_s (int8x8_t s); | |
11227 | uint16x4_t pmulhuh (uint16x4_t s, uint16x4_t t); | |
11228 | int16x4_t pmulhh (int16x4_t s, int16x4_t t); | |
11229 | int16x4_t pmullh (int16x4_t s, int16x4_t t); | |
11230 | int64_t pmuluw (uint32x2_t s, uint32x2_t t); | |
11231 | uint8x8_t pasubub (uint8x8_t s, uint8x8_t t); | |
11232 | uint16x4_t biadd (uint8x8_t s); | |
11233 | uint16x4_t psadbh (uint8x8_t s, uint8x8_t t); | |
11234 | uint16x4_t pshufh_u (uint16x4_t dest, uint16x4_t s, uint8_t order); | |
11235 | int16x4_t pshufh_s (int16x4_t dest, int16x4_t s, uint8_t order); | |
11236 | uint16x4_t psllh_u (uint16x4_t s, uint8_t amount); | |
11237 | int16x4_t psllh_s (int16x4_t s, uint8_t amount); | |
11238 | uint32x2_t psllw_u (uint32x2_t s, uint8_t amount); | |
11239 | int32x2_t psllw_s (int32x2_t s, uint8_t amount); | |
11240 | uint16x4_t psrlh_u (uint16x4_t s, uint8_t amount); | |
11241 | int16x4_t psrlh_s (int16x4_t s, uint8_t amount); | |
11242 | uint32x2_t psrlw_u (uint32x2_t s, uint8_t amount); | |
11243 | int32x2_t psrlw_s (int32x2_t s, uint8_t amount); | |
11244 | uint16x4_t psrah_u (uint16x4_t s, uint8_t amount); | |
11245 | int16x4_t psrah_s (int16x4_t s, uint8_t amount); | |
11246 | uint32x2_t psraw_u (uint32x2_t s, uint8_t amount); | |
11247 | int32x2_t psraw_s (int32x2_t s, uint8_t amount); | |
11248 | uint32x2_t psubw_u (uint32x2_t s, uint32x2_t t); | |
11249 | uint16x4_t psubh_u (uint16x4_t s, uint16x4_t t); | |
11250 | uint8x8_t psubb_u (uint8x8_t s, uint8x8_t t); | |
11251 | int32x2_t psubw_s (int32x2_t s, int32x2_t t); | |
11252 | int16x4_t psubh_s (int16x4_t s, int16x4_t t); | |
11253 | int8x8_t psubb_s (int8x8_t s, int8x8_t t); | |
11254 | uint64_t psubd_u (uint64_t s, uint64_t t); | |
11255 | int64_t psubd_s (int64_t s, int64_t t); | |
11256 | int16x4_t psubsh (int16x4_t s, int16x4_t t); | |
11257 | int8x8_t psubsb (int8x8_t s, int8x8_t t); | |
11258 | uint16x4_t psubush (uint16x4_t s, uint16x4_t t); | |
11259 | uint8x8_t psubusb (uint8x8_t s, uint8x8_t t); | |
11260 | uint32x2_t punpckhwd_u (uint32x2_t s, uint32x2_t t); | |
11261 | uint16x4_t punpckhhw_u (uint16x4_t s, uint16x4_t t); | |
11262 | uint8x8_t punpckhbh_u (uint8x8_t s, uint8x8_t t); | |
11263 | int32x2_t punpckhwd_s (int32x2_t s, int32x2_t t); | |
11264 | int16x4_t punpckhhw_s (int16x4_t s, int16x4_t t); | |
11265 | int8x8_t punpckhbh_s (int8x8_t s, int8x8_t t); | |
11266 | uint32x2_t punpcklwd_u (uint32x2_t s, uint32x2_t t); | |
11267 | uint16x4_t punpcklhw_u (uint16x4_t s, uint16x4_t t); | |
11268 | uint8x8_t punpcklbh_u (uint8x8_t s, uint8x8_t t); | |
11269 | int32x2_t punpcklwd_s (int32x2_t s, int32x2_t t); | |
11270 | int16x4_t punpcklhw_s (int16x4_t s, int16x4_t t); | |
11271 | int8x8_t punpcklbh_s (int8x8_t s, int8x8_t t); | |
11272 | @end smallexample | |
11273 | ||
dd2a386a | 11274 | @menu |
11275 | * Paired-Single Arithmetic:: | |
11276 | * Paired-Single Built-in Functions:: | |
11277 | * MIPS-3D Built-in Functions:: | |
11278 | @end menu | |
11279 | ||
11280 | @node Paired-Single Arithmetic | |
11281 | @subsubsection Paired-Single Arithmetic | |
11282 | ||
11283 | The table below lists the @code{v2sf} operations for which hardware | |
11284 | support exists. @code{a}, @code{b} and @code{c} are @code{v2sf} | |
11285 | values and @code{x} is an integral value. | |
11286 | ||
11287 | @multitable @columnfractions .50 .50 | |
11288 | @item C code @tab MIPS instruction | |
11289 | @item @code{a + b} @tab @code{add.ps} | |
11290 | @item @code{a - b} @tab @code{sub.ps} | |
11291 | @item @code{-a} @tab @code{neg.ps} | |
11292 | @item @code{a * b} @tab @code{mul.ps} | |
11293 | @item @code{a * b + c} @tab @code{madd.ps} | |
11294 | @item @code{a * b - c} @tab @code{msub.ps} | |
11295 | @item @code{-(a * b + c)} @tab @code{nmadd.ps} | |
11296 | @item @code{-(a * b - c)} @tab @code{nmsub.ps} | |
11297 | @item @code{x ? a : b} @tab @code{movn.ps}/@code{movz.ps} | |
11298 | @end multitable | |
11299 | ||
11300 | Note that the multiply-accumulate instructions can be disabled | |
11301 | using the command-line option @code{-mno-fused-madd}. | |
11302 | ||
11303 | @node Paired-Single Built-in Functions | |
11304 | @subsubsection Paired-Single Built-in Functions | |
11305 | ||
11306 | The following paired-single functions map directly to a particular | |
11307 | MIPS instruction. Please refer to the architecture specification | |
11308 | for details on what each instruction does. | |
11309 | ||
11310 | @table @code | |
11311 | @item v2sf __builtin_mips_pll_ps (v2sf, v2sf) | |
11312 | Pair lower lower (@code{pll.ps}). | |
11313 | ||
11314 | @item v2sf __builtin_mips_pul_ps (v2sf, v2sf) | |
11315 | Pair upper lower (@code{pul.ps}). | |
11316 | ||
11317 | @item v2sf __builtin_mips_plu_ps (v2sf, v2sf) | |
11318 | Pair lower upper (@code{plu.ps}). | |
11319 | ||
11320 | @item v2sf __builtin_mips_puu_ps (v2sf, v2sf) | |
11321 | Pair upper upper (@code{puu.ps}). | |
11322 | ||
11323 | @item v2sf __builtin_mips_cvt_ps_s (float, float) | |
11324 | Convert pair to paired single (@code{cvt.ps.s}). | |
11325 | ||
11326 | @item float __builtin_mips_cvt_s_pl (v2sf) | |
11327 | Convert pair lower to single (@code{cvt.s.pl}). | |
11328 | ||
11329 | @item float __builtin_mips_cvt_s_pu (v2sf) | |
11330 | Convert pair upper to single (@code{cvt.s.pu}). | |
11331 | ||
11332 | @item v2sf __builtin_mips_abs_ps (v2sf) | |
11333 | Absolute value (@code{abs.ps}). | |
11334 | ||
11335 | @item v2sf __builtin_mips_alnv_ps (v2sf, v2sf, int) | |
11336 | Align variable (@code{alnv.ps}). | |
11337 | ||
11338 | @emph{Note:} The value of the third parameter must be 0 or 4 | |
11339 | modulo 8, otherwise the result will be unpredictable. Please read the | |
11340 | instruction description for details. | |
11341 | @end table | |
11342 | ||
11343 | The following multi-instruction functions are also available. | |
11344 | In each case, @var{cond} can be any of the 16 floating-point conditions: | |
11345 | @code{f}, @code{un}, @code{eq}, @code{ueq}, @code{olt}, @code{ult}, | |
11346 | @code{ole}, @code{ule}, @code{sf}, @code{ngle}, @code{seq}, @code{ngl}, | |
11347 | @code{lt}, @code{nge}, @code{le} or @code{ngt}. | |
11348 | ||
11349 | @table @code | |
11350 | @item v2sf __builtin_mips_movt_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d}) | |
11351 | @itemx v2sf __builtin_mips_movf_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d}) | |
11352 | Conditional move based on floating point comparison (@code{c.@var{cond}.ps}, | |
11353 | @code{movt.ps}/@code{movf.ps}). | |
11354 | ||
11355 | The @code{movt} functions return the value @var{x} computed by: | |
11356 | ||
11357 | @smallexample | |
11358 | c.@var{cond}.ps @var{cc},@var{a},@var{b} | |
11359 | mov.ps @var{x},@var{c} | |
11360 | movt.ps @var{x},@var{d},@var{cc} | |
11361 | @end smallexample | |
11362 | ||
11363 | The @code{movf} functions are similar but use @code{movf.ps} instead | |
11364 | of @code{movt.ps}. | |
11365 | ||
11366 | @item int __builtin_mips_upper_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}) | |
11367 | @itemx int __builtin_mips_lower_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}) | |
11368 | Comparison of two paired-single values (@code{c.@var{cond}.ps}, | |
11369 | @code{bc1t}/@code{bc1f}). | |
11370 | ||
11371 | These functions compare @var{a} and @var{b} using @code{c.@var{cond}.ps} | |
11372 | and return either the upper or lower half of the result. For example: | |
11373 | ||
11374 | @smallexample | |
11375 | v2sf a, b; | |
11376 | if (__builtin_mips_upper_c_eq_ps (a, b)) | |
11377 | upper_halves_are_equal (); | |
11378 | else | |
11379 | upper_halves_are_unequal (); | |
11380 | ||
11381 | if (__builtin_mips_lower_c_eq_ps (a, b)) | |
11382 | lower_halves_are_equal (); | |
11383 | else | |
11384 | lower_halves_are_unequal (); | |
11385 | @end smallexample | |
11386 | @end table | |
11387 | ||
11388 | @node MIPS-3D Built-in Functions | |
11389 | @subsubsection MIPS-3D Built-in Functions | |
11390 | ||
11391 | The MIPS-3D Application-Specific Extension (ASE) includes additional | |
11392 | paired-single instructions that are designed to improve the performance | |
11393 | of 3D graphics operations. Support for these instructions is controlled | |
11394 | by the @option{-mips3d} command-line option. | |
11395 | ||
11396 | The functions listed below map directly to a particular MIPS-3D | |
11397 | instruction. Please refer to the architecture specification for | |
11398 | more details on what each instruction does. | |
11399 | ||
11400 | @table @code | |
11401 | @item v2sf __builtin_mips_addr_ps (v2sf, v2sf) | |
11402 | Reduction add (@code{addr.ps}). | |
11403 | ||
11404 | @item v2sf __builtin_mips_mulr_ps (v2sf, v2sf) | |
11405 | Reduction multiply (@code{mulr.ps}). | |
11406 | ||
11407 | @item v2sf __builtin_mips_cvt_pw_ps (v2sf) | |
11408 | Convert paired single to paired word (@code{cvt.pw.ps}). | |
11409 | ||
11410 | @item v2sf __builtin_mips_cvt_ps_pw (v2sf) | |
11411 | Convert paired word to paired single (@code{cvt.ps.pw}). | |
11412 | ||
11413 | @item float __builtin_mips_recip1_s (float) | |
11414 | @itemx double __builtin_mips_recip1_d (double) | |
11415 | @itemx v2sf __builtin_mips_recip1_ps (v2sf) | |
11416 | Reduced precision reciprocal (sequence step 1) (@code{recip1.@var{fmt}}). | |
11417 | ||
11418 | @item float __builtin_mips_recip2_s (float, float) | |
11419 | @itemx double __builtin_mips_recip2_d (double, double) | |
11420 | @itemx v2sf __builtin_mips_recip2_ps (v2sf, v2sf) | |
11421 | Reduced precision reciprocal (sequence step 2) (@code{recip2.@var{fmt}}). | |
11422 | ||
11423 | @item float __builtin_mips_rsqrt1_s (float) | |
11424 | @itemx double __builtin_mips_rsqrt1_d (double) | |
11425 | @itemx v2sf __builtin_mips_rsqrt1_ps (v2sf) | |
11426 | Reduced precision reciprocal square root (sequence step 1) | |
11427 | (@code{rsqrt1.@var{fmt}}). | |
11428 | ||
11429 | @item float __builtin_mips_rsqrt2_s (float, float) | |
11430 | @itemx double __builtin_mips_rsqrt2_d (double, double) | |
11431 | @itemx v2sf __builtin_mips_rsqrt2_ps (v2sf, v2sf) | |
11432 | Reduced precision reciprocal square root (sequence step 2) | |
11433 | (@code{rsqrt2.@var{fmt}}). | |
11434 | @end table | |
11435 | ||
11436 | The following multi-instruction functions are also available. | |
11437 | In each case, @var{cond} can be any of the 16 floating-point conditions: | |
11438 | @code{f}, @code{un}, @code{eq}, @code{ueq}, @code{olt}, @code{ult}, | |
11439 | @code{ole}, @code{ule}, @code{sf}, @code{ngle}, @code{seq}, | |
11440 | @code{ngl}, @code{lt}, @code{nge}, @code{le} or @code{ngt}. | |
11441 | ||
11442 | @table @code | |
11443 | @item int __builtin_mips_cabs_@var{cond}_s (float @var{a}, float @var{b}) | |
11444 | @itemx int __builtin_mips_cabs_@var{cond}_d (double @var{a}, double @var{b}) | |
11445 | Absolute comparison of two scalar values (@code{cabs.@var{cond}.@var{fmt}}, | |
11446 | @code{bc1t}/@code{bc1f}). | |
11447 | ||
11448 | These functions compare @var{a} and @var{b} using @code{cabs.@var{cond}.s} | |
11449 | or @code{cabs.@var{cond}.d} and return the result as a boolean value. | |
11450 | For example: | |
11451 | ||
11452 | @smallexample | |
11453 | float a, b; | |
11454 | if (__builtin_mips_cabs_eq_s (a, b)) | |
11455 | true (); | |
11456 | else | |
11457 | false (); | |
11458 | @end smallexample | |
11459 | ||
11460 | @item int __builtin_mips_upper_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}) | |
11461 | @itemx int __builtin_mips_lower_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}) | |
11462 | Absolute comparison of two paired-single values (@code{cabs.@var{cond}.ps}, | |
11463 | @code{bc1t}/@code{bc1f}). | |
11464 | ||
11465 | These functions compare @var{a} and @var{b} using @code{cabs.@var{cond}.ps} | |
11466 | and return either the upper or lower half of the result. For example: | |
11467 | ||
11468 | @smallexample | |
11469 | v2sf a, b; | |
11470 | if (__builtin_mips_upper_cabs_eq_ps (a, b)) | |
11471 | upper_halves_are_equal (); | |
11472 | else | |
11473 | upper_halves_are_unequal (); | |
11474 | ||
11475 | if (__builtin_mips_lower_cabs_eq_ps (a, b)) | |
11476 | lower_halves_are_equal (); | |
11477 | else | |
11478 | lower_halves_are_unequal (); | |
11479 | @end smallexample | |
11480 | ||
11481 | @item v2sf __builtin_mips_movt_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d}) | |
11482 | @itemx v2sf __builtin_mips_movf_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d}) | |
11483 | Conditional move based on absolute comparison (@code{cabs.@var{cond}.ps}, | |
11484 | @code{movt.ps}/@code{movf.ps}). | |
11485 | ||
11486 | The @code{movt} functions return the value @var{x} computed by: | |
11487 | ||
11488 | @smallexample | |
11489 | cabs.@var{cond}.ps @var{cc},@var{a},@var{b} | |
11490 | mov.ps @var{x},@var{c} | |
11491 | movt.ps @var{x},@var{d},@var{cc} | |
11492 | @end smallexample | |
11493 | ||
11494 | The @code{movf} functions are similar but use @code{movf.ps} instead | |
11495 | of @code{movt.ps}. | |
11496 | ||
11497 | @item int __builtin_mips_any_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}) | |
11498 | @itemx int __builtin_mips_all_c_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}) | |
11499 | @itemx int __builtin_mips_any_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}) | |
11500 | @itemx int __builtin_mips_all_cabs_@var{cond}_ps (v2sf @var{a}, v2sf @var{b}) | |
11501 | Comparison of two paired-single values | |
11502 | (@code{c.@var{cond}.ps}/@code{cabs.@var{cond}.ps}, | |
11503 | @code{bc1any2t}/@code{bc1any2f}). | |
11504 | ||
11505 | These functions compare @var{a} and @var{b} using @code{c.@var{cond}.ps} | |
11506 | or @code{cabs.@var{cond}.ps}. The @code{any} forms return true if either | |
11507 | result is true and the @code{all} forms return true if both results are true. | |
11508 | For example: | |
11509 | ||
11510 | @smallexample | |
11511 | v2sf a, b; | |
11512 | if (__builtin_mips_any_c_eq_ps (a, b)) | |
11513 | one_is_true (); | |
11514 | else | |
11515 | both_are_false (); | |
11516 | ||
11517 | if (__builtin_mips_all_c_eq_ps (a, b)) | |
11518 | both_are_true (); | |
11519 | else | |
11520 | one_is_false (); | |
11521 | @end smallexample | |
11522 | ||
11523 | @item int __builtin_mips_any_c_@var{cond}_4s (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d}) | |
11524 | @itemx int __builtin_mips_all_c_@var{cond}_4s (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d}) | |
11525 | @itemx int __builtin_mips_any_cabs_@var{cond}_4s (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d}) | |
11526 | @itemx int __builtin_mips_all_cabs_@var{cond}_4s (v2sf @var{a}, v2sf @var{b}, v2sf @var{c}, v2sf @var{d}) | |
11527 | Comparison of four paired-single values | |
11528 | (@code{c.@var{cond}.ps}/@code{cabs.@var{cond}.ps}, | |
11529 | @code{bc1any4t}/@code{bc1any4f}). | |
11530 | ||
11531 | These functions use @code{c.@var{cond}.ps} or @code{cabs.@var{cond}.ps} | |
11532 | to compare @var{a} with @var{b} and to compare @var{c} with @var{d}. | |
11533 | The @code{any} forms return true if any of the four results are true | |
11534 | and the @code{all} forms return true if all four results are true. | |
11535 | For example: | |
11536 | ||
11537 | @smallexample | |
11538 | v2sf a, b, c, d; | |
11539 | if (__builtin_mips_any_c_eq_4s (a, b, c, d)) | |
11540 | some_are_true (); | |
11541 | else | |
11542 | all_are_false (); | |
11543 | ||
11544 | if (__builtin_mips_all_c_eq_4s (a, b, c, d)) | |
11545 | all_are_true (); | |
11546 | else | |
11547 | some_are_false (); | |
11548 | @end smallexample | |
11549 | @end table | |
11550 | ||
8372e9ea | 11551 | @node picoChip Built-in Functions |
11552 | @subsection picoChip Built-in Functions | |
11553 | ||
11554 | GCC provides an interface to selected machine instructions from the | |
11555 | picoChip instruction set. | |
11556 | ||
11557 | @table @code | |
11558 | @item int __builtin_sbc (int @var{value}) | |
11559 | Sign bit count. Return the number of consecutive bits in @var{value} | |
11560 | which have the same value as the sign-bit. The result is the number of | |
11561 | leading sign bits minus one, giving the number of redundant sign bits in | |
11562 | @var{value}. | |
11563 | ||
11564 | @item int __builtin_byteswap (int @var{value}) | |
11565 | Byte swap. Return the result of swapping the upper and lower bytes of | |
11566 | @var{value}. | |
11567 | ||
11568 | @item int __builtin_brev (int @var{value}) | |
11569 | Bit reversal. Return the result of reversing the bits in | |
11570 | @var{value}. Bit 15 is swapped with bit 0, bit 14 is swapped with bit 1, | |
11571 | and so on. | |
11572 | ||
11573 | @item int __builtin_adds (int @var{x}, int @var{y}) | |
11574 | Saturating addition. Return the result of adding @var{x} and @var{y}, | |
11575 | storing the value 32767 if the result overflows. | |
11576 | ||
11577 | @item int __builtin_subs (int @var{x}, int @var{y}) | |
11578 | Saturating subtraction. Return the result of subtracting @var{y} from | |
1cbc9316 | 11579 | @var{x}, storing the value @minus{}32768 if the result overflows. |
8372e9ea | 11580 | |
11581 | @item void __builtin_halt (void) | |
11582 | Halt. The processor will stop execution. This built-in is useful for | |
11583 | implementing assertions. | |
11584 | ||
11585 | @end table | |
11586 | ||
f5ec18cc | 11587 | @node Other MIPS Built-in Functions |
11588 | @subsection Other MIPS Built-in Functions | |
11589 | ||
11590 | GCC provides other MIPS-specific built-in functions: | |
11591 | ||
11592 | @table @code | |
11593 | @item void __builtin_mips_cache (int @var{op}, const volatile void *@var{addr}) | |
11594 | Insert a @samp{cache} instruction with operands @var{op} and @var{addr}. | |
11595 | GCC defines the preprocessor macro @code{___GCC_HAVE_BUILTIN_MIPS_CACHE} | |
11596 | when this function is available. | |
11597 | @end table | |
11598 | ||
32374e3c | 11599 | @node PowerPC AltiVec/VSX Built-in Functions |
0ae4308e | 11600 | @subsection PowerPC AltiVec Built-in Functions |
11601 | ||
2b9c51df | 11602 | GCC provides an interface for the PowerPC family of processors to access |
11603 | the AltiVec operations described in Motorola's AltiVec Programming | |
11604 | Interface Manual. The interface is made available by including | |
11605 | @code{<altivec.h>} and using @option{-maltivec} and | |
11606 | @option{-mabi=altivec}. The interface supports the following vector | |
11607 | types. | |
0ae4308e | 11608 | |
2b9c51df | 11609 | @smallexample |
11610 | vector unsigned char | |
11611 | vector signed char | |
11612 | vector bool char | |
0ae4308e | 11613 | |
2b9c51df | 11614 | vector unsigned short |
11615 | vector signed short | |
11616 | vector bool short | |
11617 | vector pixel | |
11618 | ||
11619 | vector unsigned int | |
11620 | vector signed int | |
11621 | vector bool int | |
11622 | vector float | |
11623 | @end smallexample | |
11624 | ||
32374e3c | 11625 | If @option{-mvsx} is used the following additional vector types are |
11626 | implemented. | |
11627 | ||
11628 | @smallexample | |
11629 | vector unsigned long | |
11630 | vector signed long | |
11631 | vector double | |
11632 | @end smallexample | |
11633 | ||
11634 | The long types are only implemented for 64-bit code generation, and | |
11635 | the long type is only used in the floating point/integer conversion | |
11636 | instructions. | |
11637 | ||
2b9c51df | 11638 | GCC's implementation of the high-level language interface available from |
11639 | C and C++ code differs from Motorola's documentation in several ways. | |
11640 | ||
11641 | @itemize @bullet | |
11642 | ||
11643 | @item | |
11644 | A vector constant is a list of constant expressions within curly braces. | |
11645 | ||
11646 | @item | |
11647 | A vector initializer requires no cast if the vector constant is of the | |
11648 | same type as the variable it is initializing. | |
0ae4308e | 11649 | |
2b9c51df | 11650 | @item |
7731e499 | 11651 | If @code{signed} or @code{unsigned} is omitted, the signedness of the |
11652 | vector type is the default signedness of the base type. The default | |
11653 | varies depending on the operating system, so a portable program should | |
11654 | always specify the signedness. | |
f67199e1 | 11655 | |
11656 | @item | |
11657 | Compiling with @option{-maltivec} adds keywords @code{__vector}, | |
89768577 | 11658 | @code{vector}, @code{__pixel}, @code{pixel}, @code{__bool} and |
11659 | @code{bool}. When compiling ISO C, the context-sensitive substitution | |
11660 | of the keywords @code{vector}, @code{pixel} and @code{bool} is | |
11661 | disabled. To use them, you must include @code{<altivec.h>} instead. | |
f67199e1 | 11662 | |
11663 | @item | |
11664 | GCC allows using a @code{typedef} name as the type specifier for a | |
11665 | vector type. | |
2b9c51df | 11666 | |
11667 | @item | |
11668 | For C, overloaded functions are implemented with macros so the following | |
11669 | does not work: | |
af08769f | 11670 | |
11671 | @smallexample | |
17e01dc5 | 11672 | vec_add ((vector signed int)@{1, 2, 3, 4@}, foo); |
af08769f | 11673 | @end smallexample |
11674 | ||
2b9c51df | 11675 | Since @code{vec_add} is a macro, the vector constant in the example |
11676 | is treated as four separate arguments. Wrap the entire argument in | |
11677 | parentheses for this to work. | |
11678 | @end itemize | |
af08769f | 11679 | |
15e5a1c8 | 11680 | @emph{Note:} Only the @code{<altivec.h>} interface is supported. |
11681 | Internally, GCC uses built-in functions to achieve the functionality in | |
11682 | the aforementioned header file, but they are not supported and are | |
11683 | subject to change without notice. | |
11684 | ||
2b9c51df | 11685 | The following interfaces are supported for the generic and specific |
11686 | AltiVec operations and the AltiVec predicates. In cases where there | |
11687 | is a direct mapping between generic and specific operations, only the | |
11688 | generic names are shown here, although the specific operations can also | |
11689 | be used. | |
0ae4308e | 11690 | |
2b9c51df | 11691 | Arguments that are documented as @code{const int} require literal |
11692 | integral values within the range required for that operation. | |
0ae4308e | 11693 | |
2b9c51df | 11694 | @smallexample |
11695 | vector signed char vec_abs (vector signed char); | |
11696 | vector signed short vec_abs (vector signed short); | |
11697 | vector signed int vec_abs (vector signed int); | |
11698 | vector float vec_abs (vector float); | |
0ae4308e | 11699 | |
2b9c51df | 11700 | vector signed char vec_abss (vector signed char); |
11701 | vector signed short vec_abss (vector signed short); | |
11702 | vector signed int vec_abss (vector signed int); | |
0ae4308e | 11703 | |
2b9c51df | 11704 | vector signed char vec_add (vector bool char, vector signed char); |
11705 | vector signed char vec_add (vector signed char, vector bool char); | |
11706 | vector signed char vec_add (vector signed char, vector signed char); | |
11707 | vector unsigned char vec_add (vector bool char, vector unsigned char); | |
11708 | vector unsigned char vec_add (vector unsigned char, vector bool char); | |
8bdbaccf | 11709 | vector unsigned char vec_add (vector unsigned char, |
11710 | vector unsigned char); | |
2b9c51df | 11711 | vector signed short vec_add (vector bool short, vector signed short); |
11712 | vector signed short vec_add (vector signed short, vector bool short); | |
0ae4308e | 11713 | vector signed short vec_add (vector signed short, vector signed short); |
2b9c51df | 11714 | vector unsigned short vec_add (vector bool short, |
8bdbaccf | 11715 | vector unsigned short); |
11716 | vector unsigned short vec_add (vector unsigned short, | |
2b9c51df | 11717 | vector bool short); |
8e1103d3 | 11718 | vector unsigned short vec_add (vector unsigned short, |
11719 | vector unsigned short); | |
2b9c51df | 11720 | vector signed int vec_add (vector bool int, vector signed int); |
11721 | vector signed int vec_add (vector signed int, vector bool int); | |
0ae4308e | 11722 | vector signed int vec_add (vector signed int, vector signed int); |
2b9c51df | 11723 | vector unsigned int vec_add (vector bool int, vector unsigned int); |
11724 | vector unsigned int vec_add (vector unsigned int, vector bool int); | |
0ae4308e | 11725 | vector unsigned int vec_add (vector unsigned int, vector unsigned int); |
11726 | vector float vec_add (vector float, vector float); | |
11727 | ||
2b9c51df | 11728 | vector float vec_vaddfp (vector float, vector float); |
11729 | ||
11730 | vector signed int vec_vadduwm (vector bool int, vector signed int); | |
11731 | vector signed int vec_vadduwm (vector signed int, vector bool int); | |
11732 | vector signed int vec_vadduwm (vector signed int, vector signed int); | |
11733 | vector unsigned int vec_vadduwm (vector bool int, vector unsigned int); | |
11734 | vector unsigned int vec_vadduwm (vector unsigned int, vector bool int); | |
11735 | vector unsigned int vec_vadduwm (vector unsigned int, | |
11736 | vector unsigned int); | |
11737 | ||
11738 | vector signed short vec_vadduhm (vector bool short, | |
11739 | vector signed short); | |
11740 | vector signed short vec_vadduhm (vector signed short, | |
11741 | vector bool short); | |
11742 | vector signed short vec_vadduhm (vector signed short, | |
11743 | vector signed short); | |
11744 | vector unsigned short vec_vadduhm (vector bool short, | |
11745 | vector unsigned short); | |
11746 | vector unsigned short vec_vadduhm (vector unsigned short, | |
11747 | vector bool short); | |
11748 | vector unsigned short vec_vadduhm (vector unsigned short, | |
11749 | vector unsigned short); | |
11750 | ||
11751 | vector signed char vec_vaddubm (vector bool char, vector signed char); | |
11752 | vector signed char vec_vaddubm (vector signed char, vector bool char); | |
11753 | vector signed char vec_vaddubm (vector signed char, vector signed char); | |
11754 | vector unsigned char vec_vaddubm (vector bool char, | |
11755 | vector unsigned char); | |
11756 | vector unsigned char vec_vaddubm (vector unsigned char, | |
11757 | vector bool char); | |
11758 | vector unsigned char vec_vaddubm (vector unsigned char, | |
11759 | vector unsigned char); | |
11760 | ||
0ae4308e | 11761 | vector unsigned int vec_addc (vector unsigned int, vector unsigned int); |
11762 | ||
2b9c51df | 11763 | vector unsigned char vec_adds (vector bool char, vector unsigned char); |
11764 | vector unsigned char vec_adds (vector unsigned char, vector bool char); | |
8bdbaccf | 11765 | vector unsigned char vec_adds (vector unsigned char, |
11766 | vector unsigned char); | |
2b9c51df | 11767 | vector signed char vec_adds (vector bool char, vector signed char); |
11768 | vector signed char vec_adds (vector signed char, vector bool char); | |
0ae4308e | 11769 | vector signed char vec_adds (vector signed char, vector signed char); |
2b9c51df | 11770 | vector unsigned short vec_adds (vector bool short, |
8bdbaccf | 11771 | vector unsigned short); |
11772 | vector unsigned short vec_adds (vector unsigned short, | |
2b9c51df | 11773 | vector bool short); |
8e1103d3 | 11774 | vector unsigned short vec_adds (vector unsigned short, |
11775 | vector unsigned short); | |
2b9c51df | 11776 | vector signed short vec_adds (vector bool short, vector signed short); |
11777 | vector signed short vec_adds (vector signed short, vector bool short); | |
0ae4308e | 11778 | vector signed short vec_adds (vector signed short, vector signed short); |
2b9c51df | 11779 | vector unsigned int vec_adds (vector bool int, vector unsigned int); |
11780 | vector unsigned int vec_adds (vector unsigned int, vector bool int); | |
0ae4308e | 11781 | vector unsigned int vec_adds (vector unsigned int, vector unsigned int); |
2b9c51df | 11782 | vector signed int vec_adds (vector bool int, vector signed int); |
11783 | vector signed int vec_adds (vector signed int, vector bool int); | |
0ae4308e | 11784 | vector signed int vec_adds (vector signed int, vector signed int); |
11785 | ||
2b9c51df | 11786 | vector signed int vec_vaddsws (vector bool int, vector signed int); |
11787 | vector signed int vec_vaddsws (vector signed int, vector bool int); | |
11788 | vector signed int vec_vaddsws (vector signed int, vector signed int); | |
11789 | ||
11790 | vector unsigned int vec_vadduws (vector bool int, vector unsigned int); | |
11791 | vector unsigned int vec_vadduws (vector unsigned int, vector bool int); | |
11792 | vector unsigned int vec_vadduws (vector unsigned int, | |
11793 | vector unsigned int); | |
11794 | ||
11795 | vector signed short vec_vaddshs (vector bool short, | |
11796 | vector signed short); | |
11797 | vector signed short vec_vaddshs (vector signed short, | |
11798 | vector bool short); | |
11799 | vector signed short vec_vaddshs (vector signed short, | |
11800 | vector signed short); | |
11801 | ||
11802 | vector unsigned short vec_vadduhs (vector bool short, | |
11803 | vector unsigned short); | |
11804 | vector unsigned short vec_vadduhs (vector unsigned short, | |
11805 | vector bool short); | |
11806 | vector unsigned short vec_vadduhs (vector unsigned short, | |
11807 | vector unsigned short); | |
11808 | ||
11809 | vector signed char vec_vaddsbs (vector bool char, vector signed char); | |
11810 | vector signed char vec_vaddsbs (vector signed char, vector bool char); | |
11811 | vector signed char vec_vaddsbs (vector signed char, vector signed char); | |
11812 | ||
11813 | vector unsigned char vec_vaddubs (vector bool char, | |
11814 | vector unsigned char); | |
11815 | vector unsigned char vec_vaddubs (vector unsigned char, | |
11816 | vector bool char); | |
11817 | vector unsigned char vec_vaddubs (vector unsigned char, | |
11818 | vector unsigned char); | |
11819 | ||
0ae4308e | 11820 | vector float vec_and (vector float, vector float); |
2b9c51df | 11821 | vector float vec_and (vector float, vector bool int); |
11822 | vector float vec_and (vector bool int, vector float); | |
11823 | vector bool int vec_and (vector bool int, vector bool int); | |
11824 | vector signed int vec_and (vector bool int, vector signed int); | |
11825 | vector signed int vec_and (vector signed int, vector bool int); | |
0ae4308e | 11826 | vector signed int vec_and (vector signed int, vector signed int); |
2b9c51df | 11827 | vector unsigned int vec_and (vector bool int, vector unsigned int); |
11828 | vector unsigned int vec_and (vector unsigned int, vector bool int); | |
0ae4308e | 11829 | vector unsigned int vec_and (vector unsigned int, vector unsigned int); |
2b9c51df | 11830 | vector bool short vec_and (vector bool short, vector bool short); |
11831 | vector signed short vec_and (vector bool short, vector signed short); | |
11832 | vector signed short vec_and (vector signed short, vector bool short); | |
0ae4308e | 11833 | vector signed short vec_and (vector signed short, vector signed short); |
2b9c51df | 11834 | vector unsigned short vec_and (vector bool short, |
8bdbaccf | 11835 | vector unsigned short); |
11836 | vector unsigned short vec_and (vector unsigned short, | |
2b9c51df | 11837 | vector bool short); |
8e1103d3 | 11838 | vector unsigned short vec_and (vector unsigned short, |
11839 | vector unsigned short); | |
2b9c51df | 11840 | vector signed char vec_and (vector bool char, vector signed char); |
11841 | vector bool char vec_and (vector bool char, vector bool char); | |
11842 | vector signed char vec_and (vector signed char, vector bool char); | |
0ae4308e | 11843 | vector signed char vec_and (vector signed char, vector signed char); |
2b9c51df | 11844 | vector unsigned char vec_and (vector bool char, vector unsigned char); |
11845 | vector unsigned char vec_and (vector unsigned char, vector bool char); | |
8bdbaccf | 11846 | vector unsigned char vec_and (vector unsigned char, |
11847 | vector unsigned char); | |
0ae4308e | 11848 | |
11849 | vector float vec_andc (vector float, vector float); | |
2b9c51df | 11850 | vector float vec_andc (vector float, vector bool int); |
11851 | vector float vec_andc (vector bool int, vector float); | |
11852 | vector bool int vec_andc (vector bool int, vector bool int); | |
11853 | vector signed int vec_andc (vector bool int, vector signed int); | |
11854 | vector signed int vec_andc (vector signed int, vector bool int); | |
0ae4308e | 11855 | vector signed int vec_andc (vector signed int, vector signed int); |
2b9c51df | 11856 | vector unsigned int vec_andc (vector bool int, vector unsigned int); |
11857 | vector unsigned int vec_andc (vector unsigned int, vector bool int); | |
0ae4308e | 11858 | vector unsigned int vec_andc (vector unsigned int, vector unsigned int); |
2b9c51df | 11859 | vector bool short vec_andc (vector bool short, vector bool short); |
11860 | vector signed short vec_andc (vector bool short, vector signed short); | |
11861 | vector signed short vec_andc (vector signed short, vector bool short); | |
0ae4308e | 11862 | vector signed short vec_andc (vector signed short, vector signed short); |
2b9c51df | 11863 | vector unsigned short vec_andc (vector bool short, |
8bdbaccf | 11864 | vector unsigned short); |
11865 | vector unsigned short vec_andc (vector unsigned short, | |
2b9c51df | 11866 | vector bool short); |
8e1103d3 | 11867 | vector unsigned short vec_andc (vector unsigned short, |
11868 | vector unsigned short); | |
2b9c51df | 11869 | vector signed char vec_andc (vector bool char, vector signed char); |
11870 | vector bool char vec_andc (vector bool char, vector bool char); | |
11871 | vector signed char vec_andc (vector signed char, vector bool char); | |
0ae4308e | 11872 | vector signed char vec_andc (vector signed char, vector signed char); |
2b9c51df | 11873 | vector unsigned char vec_andc (vector bool char, vector unsigned char); |
11874 | vector unsigned char vec_andc (vector unsigned char, vector bool char); | |
8bdbaccf | 11875 | vector unsigned char vec_andc (vector unsigned char, |
11876 | vector unsigned char); | |
0ae4308e | 11877 | |
8bdbaccf | 11878 | vector unsigned char vec_avg (vector unsigned char, |
11879 | vector unsigned char); | |
0ae4308e | 11880 | vector signed char vec_avg (vector signed char, vector signed char); |
8e1103d3 | 11881 | vector unsigned short vec_avg (vector unsigned short, |
11882 | vector unsigned short); | |
0ae4308e | 11883 | vector signed short vec_avg (vector signed short, vector signed short); |
11884 | vector unsigned int vec_avg (vector unsigned int, vector unsigned int); | |
11885 | vector signed int vec_avg (vector signed int, vector signed int); | |
11886 | ||
2b9c51df | 11887 | vector signed int vec_vavgsw (vector signed int, vector signed int); |
11888 | ||
11889 | vector unsigned int vec_vavguw (vector unsigned int, | |
11890 | vector unsigned int); | |
11891 | ||
11892 | vector signed short vec_vavgsh (vector signed short, | |
11893 | vector signed short); | |
11894 | ||
11895 | vector unsigned short vec_vavguh (vector unsigned short, | |
11896 | vector unsigned short); | |
11897 | ||
11898 | vector signed char vec_vavgsb (vector signed char, vector signed char); | |
11899 | ||
11900 | vector unsigned char vec_vavgub (vector unsigned char, | |
11901 | vector unsigned char); | |
11902 | ||
32374e3c | 11903 | vector float vec_copysign (vector float); |
11904 | ||
0ae4308e | 11905 | vector float vec_ceil (vector float); |
11906 | ||
11907 | vector signed int vec_cmpb (vector float, vector float); | |
11908 | ||
2b9c51df | 11909 | vector bool char vec_cmpeq (vector signed char, vector signed char); |
11910 | vector bool char vec_cmpeq (vector unsigned char, vector unsigned char); | |
11911 | vector bool short vec_cmpeq (vector signed short, vector signed short); | |
11912 | vector bool short vec_cmpeq (vector unsigned short, | |
11913 | vector unsigned short); | |
11914 | vector bool int vec_cmpeq (vector signed int, vector signed int); | |
11915 | vector bool int vec_cmpeq (vector unsigned int, vector unsigned int); | |
11916 | vector bool int vec_cmpeq (vector float, vector float); | |
0ae4308e | 11917 | |
2b9c51df | 11918 | vector bool int vec_vcmpeqfp (vector float, vector float); |
0ae4308e | 11919 | |
2b9c51df | 11920 | vector bool int vec_vcmpequw (vector signed int, vector signed int); |
11921 | vector bool int vec_vcmpequw (vector unsigned int, vector unsigned int); | |
11922 | ||
11923 | vector bool short vec_vcmpequh (vector signed short, | |
11924 | vector signed short); | |
11925 | vector bool short vec_vcmpequh (vector unsigned short, | |
11926 | vector unsigned short); | |
0ae4308e | 11927 | |
2b9c51df | 11928 | vector bool char vec_vcmpequb (vector signed char, vector signed char); |
11929 | vector bool char vec_vcmpequb (vector unsigned char, | |
11930 | vector unsigned char); | |
0ae4308e | 11931 | |
2b9c51df | 11932 | vector bool int vec_cmpge (vector float, vector float); |
0ae4308e | 11933 | |
2b9c51df | 11934 | vector bool char vec_cmpgt (vector unsigned char, vector unsigned char); |
11935 | vector bool char vec_cmpgt (vector signed char, vector signed char); | |
11936 | vector bool short vec_cmpgt (vector unsigned short, | |
11937 | vector unsigned short); | |
11938 | vector bool short vec_cmpgt (vector signed short, vector signed short); | |
11939 | vector bool int vec_cmpgt (vector unsigned int, vector unsigned int); | |
11940 | vector bool int vec_cmpgt (vector signed int, vector signed int); | |
11941 | vector bool int vec_cmpgt (vector float, vector float); | |
11942 | ||
11943 | vector bool int vec_vcmpgtfp (vector float, vector float); | |
11944 | ||
11945 | vector bool int vec_vcmpgtsw (vector signed int, vector signed int); | |
11946 | ||
11947 | vector bool int vec_vcmpgtuw (vector unsigned int, vector unsigned int); | |
0ae4308e | 11948 | |
2b9c51df | 11949 | vector bool short vec_vcmpgtsh (vector signed short, |
11950 | vector signed short); | |
11951 | ||
11952 | vector bool short vec_vcmpgtuh (vector unsigned short, | |
11953 | vector unsigned short); | |
11954 | ||
11955 | vector bool char vec_vcmpgtsb (vector signed char, vector signed char); | |
11956 | ||
11957 | vector bool char vec_vcmpgtub (vector unsigned char, | |
11958 | vector unsigned char); | |
11959 | ||
11960 | vector bool int vec_cmple (vector float, vector float); | |
11961 | ||
11962 | vector bool char vec_cmplt (vector unsigned char, vector unsigned char); | |
11963 | vector bool char vec_cmplt (vector signed char, vector signed char); | |
11964 | vector bool short vec_cmplt (vector unsigned short, | |
11965 | vector unsigned short); | |
11966 | vector bool short vec_cmplt (vector signed short, vector signed short); | |
11967 | vector bool int vec_cmplt (vector unsigned int, vector unsigned int); | |
11968 | vector bool int vec_cmplt (vector signed int, vector signed int); | |
11969 | vector bool int vec_cmplt (vector float, vector float); | |
0ae4308e | 11970 | |
2b9c51df | 11971 | vector float vec_ctf (vector unsigned int, const int); |
11972 | vector float vec_ctf (vector signed int, const int); | |
0ae4308e | 11973 | |
2b9c51df | 11974 | vector float vec_vcfsx (vector signed int, const int); |
11975 | ||
11976 | vector float vec_vcfux (vector unsigned int, const int); | |
11977 | ||
11978 | vector signed int vec_cts (vector float, const int); | |
11979 | ||
11980 | vector unsigned int vec_ctu (vector float, const int); | |
11981 | ||
11982 | void vec_dss (const int); | |
0ae4308e | 11983 | |
11984 | void vec_dssall (void); | |
11985 | ||
2b9c51df | 11986 | void vec_dst (const vector unsigned char *, int, const int); |
11987 | void vec_dst (const vector signed char *, int, const int); | |
11988 | void vec_dst (const vector bool char *, int, const int); | |
11989 | void vec_dst (const vector unsigned short *, int, const int); | |
11990 | void vec_dst (const vector signed short *, int, const int); | |
11991 | void vec_dst (const vector bool short *, int, const int); | |
11992 | void vec_dst (const vector pixel *, int, const int); | |
11993 | void vec_dst (const vector unsigned int *, int, const int); | |
11994 | void vec_dst (const vector signed int *, int, const int); | |
11995 | void vec_dst (const vector bool int *, int, const int); | |
11996 | void vec_dst (const vector float *, int, const int); | |
11997 | void vec_dst (const unsigned char *, int, const int); | |
11998 | void vec_dst (const signed char *, int, const int); | |
11999 | void vec_dst (const unsigned short *, int, const int); | |
12000 | void vec_dst (const short *, int, const int); | |
12001 | void vec_dst (const unsigned int *, int, const int); | |
12002 | void vec_dst (const int *, int, const int); | |
12003 | void vec_dst (const unsigned long *, int, const int); | |
12004 | void vec_dst (const long *, int, const int); | |
12005 | void vec_dst (const float *, int, const int); | |
12006 | ||
12007 | void vec_dstst (const vector unsigned char *, int, const int); | |
12008 | void vec_dstst (const vector signed char *, int, const int); | |
12009 | void vec_dstst (const vector bool char *, int, const int); | |
12010 | void vec_dstst (const vector unsigned short *, int, const int); | |
12011 | void vec_dstst (const vector signed short *, int, const int); | |
12012 | void vec_dstst (const vector bool short *, int, const int); | |
12013 | void vec_dstst (const vector pixel *, int, const int); | |
12014 | void vec_dstst (const vector unsigned int *, int, const int); | |
12015 | void vec_dstst (const vector signed int *, int, const int); | |
12016 | void vec_dstst (const vector bool int *, int, const int); | |
12017 | void vec_dstst (const vector float *, int, const int); | |
12018 | void vec_dstst (const unsigned char *, int, const int); | |
12019 | void vec_dstst (const signed char *, int, const int); | |
12020 | void vec_dstst (const unsigned short *, int, const int); | |
12021 | void vec_dstst (const short *, int, const int); | |
12022 | void vec_dstst (const unsigned int *, int, const int); | |
12023 | void vec_dstst (const int *, int, const int); | |
12024 | void vec_dstst (const unsigned long *, int, const int); | |
12025 | void vec_dstst (const long *, int, const int); | |
12026 | void vec_dstst (const float *, int, const int); | |
12027 | ||
12028 | void vec_dststt (const vector unsigned char *, int, const int); | |
12029 | void vec_dststt (const vector signed char *, int, const int); | |
12030 | void vec_dststt (const vector bool char *, int, const int); | |
12031 | void vec_dststt (const vector unsigned short *, int, const int); | |
12032 | void vec_dststt (const vector signed short *, int, const int); | |
12033 | void vec_dststt (const vector bool short *, int, const int); | |
12034 | void vec_dststt (const vector pixel *, int, const int); | |
12035 | void vec_dststt (const vector unsigned int *, int, const int); | |
12036 | void vec_dststt (const vector signed int *, int, const int); | |
12037 | void vec_dststt (const vector bool int *, int, const int); | |
12038 | void vec_dststt (const vector float *, int, const int); | |
12039 | void vec_dststt (const unsigned char *, int, const int); | |
12040 | void vec_dststt (const signed char *, int, const int); | |
12041 | void vec_dststt (const unsigned short *, int, const int); | |
12042 | void vec_dststt (const short *, int, const int); | |
12043 | void vec_dststt (const unsigned int *, int, const int); | |
12044 | void vec_dststt (const int *, int, const int); | |
12045 | void vec_dststt (const unsigned long *, int, const int); | |
12046 | void vec_dststt (const long *, int, const int); | |
12047 | void vec_dststt (const float *, int, const int); | |
12048 | ||
12049 | void vec_dstt (const vector unsigned char *, int, const int); | |
12050 | void vec_dstt (const vector signed char *, int, const int); | |
12051 | void vec_dstt (const vector bool char *, int, const int); | |
12052 | void vec_dstt (const vector unsigned short *, int, const int); | |
12053 | void vec_dstt (const vector signed short *, int, const int); | |
12054 | void vec_dstt (const vector bool short *, int, const int); | |
12055 | void vec_dstt (const vector pixel *, int, const int); | |
12056 | void vec_dstt (const vector unsigned int *, int, const int); | |
12057 | void vec_dstt (const vector signed int *, int, const int); | |
12058 | void vec_dstt (const vector bool int *, int, const int); | |
12059 | void vec_dstt (const vector float *, int, const int); | |
12060 | void vec_dstt (const unsigned char *, int, const int); | |
12061 | void vec_dstt (const signed char *, int, const int); | |
12062 | void vec_dstt (const unsigned short *, int, const int); | |
12063 | void vec_dstt (const short *, int, const int); | |
12064 | void vec_dstt (const unsigned int *, int, const int); | |
12065 | void vec_dstt (const int *, int, const int); | |
12066 | void vec_dstt (const unsigned long *, int, const int); | |
12067 | void vec_dstt (const long *, int, const int); | |
12068 | void vec_dstt (const float *, int, const int); | |
12069 | ||
12070 | vector float vec_expte (vector float); | |
12071 | ||
12072 | vector float vec_floor (vector float); | |
12073 | ||
12074 | vector float vec_ld (int, const vector float *); | |
12075 | vector float vec_ld (int, const float *); | |
12076 | vector bool int vec_ld (int, const vector bool int *); | |
12077 | vector signed int vec_ld (int, const vector signed int *); | |
12078 | vector signed int vec_ld (int, const int *); | |
12079 | vector signed int vec_ld (int, const long *); | |
12080 | vector unsigned int vec_ld (int, const vector unsigned int *); | |
12081 | vector unsigned int vec_ld (int, const unsigned int *); | |
12082 | vector unsigned int vec_ld (int, const unsigned long *); | |
12083 | vector bool short vec_ld (int, const vector bool short *); | |
12084 | vector pixel vec_ld (int, const vector pixel *); | |
12085 | vector signed short vec_ld (int, const vector signed short *); | |
12086 | vector signed short vec_ld (int, const short *); | |
12087 | vector unsigned short vec_ld (int, const vector unsigned short *); | |
12088 | vector unsigned short vec_ld (int, const unsigned short *); | |
12089 | vector bool char vec_ld (int, const vector bool char *); | |
12090 | vector signed char vec_ld (int, const vector signed char *); | |
12091 | vector signed char vec_ld (int, const signed char *); | |
12092 | vector unsigned char vec_ld (int, const vector unsigned char *); | |
12093 | vector unsigned char vec_ld (int, const unsigned char *); | |
12094 | ||
12095 | vector signed char vec_lde (int, const signed char *); | |
12096 | vector unsigned char vec_lde (int, const unsigned char *); | |
12097 | vector signed short vec_lde (int, const short *); | |
12098 | vector unsigned short vec_lde (int, const unsigned short *); | |
12099 | vector float vec_lde (int, const float *); | |
12100 | vector signed int vec_lde (int, const int *); | |
12101 | vector unsigned int vec_lde (int, const unsigned int *); | |
12102 | vector signed int vec_lde (int, const long *); | |
12103 | vector unsigned int vec_lde (int, const unsigned long *); | |
12104 | ||
12105 | vector float vec_lvewx (int, float *); | |
12106 | vector signed int vec_lvewx (int, int *); | |
12107 | vector unsigned int vec_lvewx (int, unsigned int *); | |
12108 | vector signed int vec_lvewx (int, long *); | |
12109 | vector unsigned int vec_lvewx (int, unsigned long *); | |
12110 | ||
12111 | vector signed short vec_lvehx (int, short *); | |
12112 | vector unsigned short vec_lvehx (int, unsigned short *); | |
12113 | ||
12114 | vector signed char vec_lvebx (int, char *); | |
12115 | vector unsigned char vec_lvebx (int, unsigned char *); | |
12116 | ||
12117 | vector float vec_ldl (int, const vector float *); | |
12118 | vector float vec_ldl (int, const float *); | |
12119 | vector bool int vec_ldl (int, const vector bool int *); | |
12120 | vector signed int vec_ldl (int, const vector signed int *); | |
12121 | vector signed int vec_ldl (int, const int *); | |
12122 | vector signed int vec_ldl (int, const long *); | |
12123 | vector unsigned int vec_ldl (int, const vector unsigned int *); | |
12124 | vector unsigned int vec_ldl (int, const unsigned int *); | |
12125 | vector unsigned int vec_ldl (int, const unsigned long *); | |
12126 | vector bool short vec_ldl (int, const vector bool short *); | |
12127 | vector pixel vec_ldl (int, const vector pixel *); | |
12128 | vector signed short vec_ldl (int, const vector signed short *); | |
12129 | vector signed short vec_ldl (int, const short *); | |
12130 | vector unsigned short vec_ldl (int, const vector unsigned short *); | |
12131 | vector unsigned short vec_ldl (int, const unsigned short *); | |
12132 | vector bool char vec_ldl (int, const vector bool char *); | |
12133 | vector signed char vec_ldl (int, const vector signed char *); | |
12134 | vector signed char vec_ldl (int, const signed char *); | |
12135 | vector unsigned char vec_ldl (int, const vector unsigned char *); | |
12136 | vector unsigned char vec_ldl (int, const unsigned char *); | |
0ae4308e | 12137 | |
12138 | vector float vec_loge (vector float); | |
12139 | ||
2b9c51df | 12140 | vector unsigned char vec_lvsl (int, const volatile unsigned char *); |
12141 | vector unsigned char vec_lvsl (int, const volatile signed char *); | |
12142 | vector unsigned char vec_lvsl (int, const volatile unsigned short *); | |
12143 | vector unsigned char vec_lvsl (int, const volatile short *); | |
12144 | vector unsigned char vec_lvsl (int, const volatile unsigned int *); | |
12145 | vector unsigned char vec_lvsl (int, const volatile int *); | |
12146 | vector unsigned char vec_lvsl (int, const volatile unsigned long *); | |
12147 | vector unsigned char vec_lvsl (int, const volatile long *); | |
12148 | vector unsigned char vec_lvsl (int, const volatile float *); | |
12149 | ||
12150 | vector unsigned char vec_lvsr (int, const volatile unsigned char *); | |
12151 | vector unsigned char vec_lvsr (int, const volatile signed char *); | |
12152 | vector unsigned char vec_lvsr (int, const volatile unsigned short *); | |
12153 | vector unsigned char vec_lvsr (int, const volatile short *); | |
12154 | vector unsigned char vec_lvsr (int, const volatile unsigned int *); | |
12155 | vector unsigned char vec_lvsr (int, const volatile int *); | |
12156 | vector unsigned char vec_lvsr (int, const volatile unsigned long *); | |
12157 | vector unsigned char vec_lvsr (int, const volatile long *); | |
12158 | vector unsigned char vec_lvsr (int, const volatile float *); | |
0ae4308e | 12159 | |
12160 | vector float vec_madd (vector float, vector float, vector float); | |
12161 | ||
2b9c51df | 12162 | vector signed short vec_madds (vector signed short, |
12163 | vector signed short, | |
8e1103d3 | 12164 | vector signed short); |
0ae4308e | 12165 | |
2b9c51df | 12166 | vector unsigned char vec_max (vector bool char, vector unsigned char); |
12167 | vector unsigned char vec_max (vector unsigned char, vector bool char); | |
8bdbaccf | 12168 | vector unsigned char vec_max (vector unsigned char, |
12169 | vector unsigned char); | |
2b9c51df | 12170 | vector signed char vec_max (vector bool char, vector signed char); |
12171 | vector signed char vec_max (vector signed char, vector bool char); | |
0ae4308e | 12172 | vector signed char vec_max (vector signed char, vector signed char); |
2b9c51df | 12173 | vector unsigned short vec_max (vector bool short, |
8bdbaccf | 12174 | vector unsigned short); |
12175 | vector unsigned short vec_max (vector unsigned short, | |
2b9c51df | 12176 | vector bool short); |
8e1103d3 | 12177 | vector unsigned short vec_max (vector unsigned short, |
12178 | vector unsigned short); | |
2b9c51df | 12179 | vector signed short vec_max (vector bool short, vector signed short); |
12180 | vector signed short vec_max (vector signed short, vector bool short); | |
0ae4308e | 12181 | vector signed short vec_max (vector signed short, vector signed short); |
2b9c51df | 12182 | vector unsigned int vec_max (vector bool int, vector unsigned int); |
12183 | vector unsigned int vec_max (vector unsigned int, vector bool int); | |
0ae4308e | 12184 | vector unsigned int vec_max (vector unsigned int, vector unsigned int); |
2b9c51df | 12185 | vector signed int vec_max (vector bool int, vector signed int); |
12186 | vector signed int vec_max (vector signed int, vector bool int); | |
0ae4308e | 12187 | vector signed int vec_max (vector signed int, vector signed int); |
12188 | vector float vec_max (vector float, vector float); | |
12189 | ||
2b9c51df | 12190 | vector float vec_vmaxfp (vector float, vector float); |
12191 | ||
12192 | vector signed int vec_vmaxsw (vector bool int, vector signed int); | |
12193 | vector signed int vec_vmaxsw (vector signed int, vector bool int); | |
12194 | vector signed int vec_vmaxsw (vector signed int, vector signed int); | |
12195 | ||
12196 | vector unsigned int vec_vmaxuw (vector bool int, vector unsigned int); | |
12197 | vector unsigned int vec_vmaxuw (vector unsigned int, vector bool int); | |
12198 | vector unsigned int vec_vmaxuw (vector unsigned int, | |
12199 | vector unsigned int); | |
12200 | ||
12201 | vector signed short vec_vmaxsh (vector bool short, vector signed short); | |
12202 | vector signed short vec_vmaxsh (vector signed short, vector bool short); | |
12203 | vector signed short vec_vmaxsh (vector signed short, | |
12204 | vector signed short); | |
12205 | ||
12206 | vector unsigned short vec_vmaxuh (vector bool short, | |
12207 | vector unsigned short); | |
12208 | vector unsigned short vec_vmaxuh (vector unsigned short, | |
12209 | vector bool short); | |
12210 | vector unsigned short vec_vmaxuh (vector unsigned short, | |
12211 | vector unsigned short); | |
12212 | ||
12213 | vector signed char vec_vmaxsb (vector bool char, vector signed char); | |
12214 | vector signed char vec_vmaxsb (vector signed char, vector bool char); | |
12215 | vector signed char vec_vmaxsb (vector signed char, vector signed char); | |
12216 | ||
12217 | vector unsigned char vec_vmaxub (vector bool char, | |
12218 | vector unsigned char); | |
12219 | vector unsigned char vec_vmaxub (vector unsigned char, | |
12220 | vector bool char); | |
12221 | vector unsigned char vec_vmaxub (vector unsigned char, | |
12222 | vector unsigned char); | |
12223 | ||
12224 | vector bool char vec_mergeh (vector bool char, vector bool char); | |
0ae4308e | 12225 | vector signed char vec_mergeh (vector signed char, vector signed char); |
8e1103d3 | 12226 | vector unsigned char vec_mergeh (vector unsigned char, |
12227 | vector unsigned char); | |
2b9c51df | 12228 | vector bool short vec_mergeh (vector bool short, vector bool short); |
12229 | vector pixel vec_mergeh (vector pixel, vector pixel); | |
8bdbaccf | 12230 | vector signed short vec_mergeh (vector signed short, |
12231 | vector signed short); | |
8e1103d3 | 12232 | vector unsigned short vec_mergeh (vector unsigned short, |
12233 | vector unsigned short); | |
0ae4308e | 12234 | vector float vec_mergeh (vector float, vector float); |
2b9c51df | 12235 | vector bool int vec_mergeh (vector bool int, vector bool int); |
0ae4308e | 12236 | vector signed int vec_mergeh (vector signed int, vector signed int); |
8bdbaccf | 12237 | vector unsigned int vec_mergeh (vector unsigned int, |
12238 | vector unsigned int); | |
0ae4308e | 12239 | |
2b9c51df | 12240 | vector float vec_vmrghw (vector float, vector float); |
12241 | vector bool int vec_vmrghw (vector bool int, vector bool int); | |
12242 | vector signed int vec_vmrghw (vector signed int, vector signed int); | |
12243 | vector unsigned int vec_vmrghw (vector unsigned int, | |
12244 | vector unsigned int); | |
12245 | ||
12246 | vector bool short vec_vmrghh (vector bool short, vector bool short); | |
12247 | vector signed short vec_vmrghh (vector signed short, | |
12248 | vector signed short); | |
12249 | vector unsigned short vec_vmrghh (vector unsigned short, | |
12250 | vector unsigned short); | |
12251 | vector pixel vec_vmrghh (vector pixel, vector pixel); | |
12252 | ||
12253 | vector bool char vec_vmrghb (vector bool char, vector bool char); | |
12254 | vector signed char vec_vmrghb (vector signed char, vector signed char); | |
12255 | vector unsigned char vec_vmrghb (vector unsigned char, | |
12256 | vector unsigned char); | |
12257 | ||
12258 | vector bool char vec_mergel (vector bool char, vector bool char); | |
0ae4308e | 12259 | vector signed char vec_mergel (vector signed char, vector signed char); |
8e1103d3 | 12260 | vector unsigned char vec_mergel (vector unsigned char, |
12261 | vector unsigned char); | |
2b9c51df | 12262 | vector bool short vec_mergel (vector bool short, vector bool short); |
12263 | vector pixel vec_mergel (vector pixel, vector pixel); | |
8bdbaccf | 12264 | vector signed short vec_mergel (vector signed short, |
12265 | vector signed short); | |
8e1103d3 | 12266 | vector unsigned short vec_mergel (vector unsigned short, |
12267 | vector unsigned short); | |
0ae4308e | 12268 | vector float vec_mergel (vector float, vector float); |
2b9c51df | 12269 | vector bool int vec_mergel (vector bool int, vector bool int); |
0ae4308e | 12270 | vector signed int vec_mergel (vector signed int, vector signed int); |
8bdbaccf | 12271 | vector unsigned int vec_mergel (vector unsigned int, |
12272 | vector unsigned int); | |
0ae4308e | 12273 | |
2b9c51df | 12274 | vector float vec_vmrglw (vector float, vector float); |
12275 | vector signed int vec_vmrglw (vector signed int, vector signed int); | |
12276 | vector unsigned int vec_vmrglw (vector unsigned int, | |
12277 | vector unsigned int); | |
12278 | vector bool int vec_vmrglw (vector bool int, vector bool int); | |
0ae4308e | 12279 | |
2b9c51df | 12280 | vector bool short vec_vmrglh (vector bool short, vector bool short); |
12281 | vector signed short vec_vmrglh (vector signed short, | |
12282 | vector signed short); | |
12283 | vector unsigned short vec_vmrglh (vector unsigned short, | |
12284 | vector unsigned short); | |
12285 | vector pixel vec_vmrglh (vector pixel, vector pixel); | |
12286 | ||
12287 | vector bool char vec_vmrglb (vector bool char, vector bool char); | |
12288 | vector signed char vec_vmrglb (vector signed char, vector signed char); | |
12289 | vector unsigned char vec_vmrglb (vector unsigned char, | |
12290 | vector unsigned char); | |
0ae4308e | 12291 | |
2b9c51df | 12292 | vector unsigned short vec_mfvscr (void); |
0ae4308e | 12293 | |
2b9c51df | 12294 | vector unsigned char vec_min (vector bool char, vector unsigned char); |
12295 | vector unsigned char vec_min (vector unsigned char, vector bool char); | |
8bdbaccf | 12296 | vector unsigned char vec_min (vector unsigned char, |
12297 | vector unsigned char); | |
2b9c51df | 12298 | vector signed char vec_min (vector bool char, vector signed char); |
12299 | vector signed char vec_min (vector signed char, vector bool char); | |
0ae4308e | 12300 | vector signed char vec_min (vector signed char, vector signed char); |
2b9c51df | 12301 | vector unsigned short vec_min (vector bool short, |
8bdbaccf | 12302 | vector unsigned short); |
12303 | vector unsigned short vec_min (vector unsigned short, | |
2b9c51df | 12304 | vector bool short); |
8e1103d3 | 12305 | vector unsigned short vec_min (vector unsigned short, |
12306 | vector unsigned short); | |
2b9c51df | 12307 | vector signed short vec_min (vector bool short, vector signed short); |
12308 | vector signed short vec_min (vector signed short, vector bool short); | |
0ae4308e | 12309 | vector signed short vec_min (vector signed short, vector signed short); |
2b9c51df | 12310 | vector unsigned int vec_min (vector bool int, vector unsigned int); |
12311 | vector unsigned int vec_min (vector unsigned int, vector bool int); | |
0ae4308e | 12312 | vector unsigned int vec_min (vector unsigned int, vector unsigned int); |
2b9c51df | 12313 | vector signed int vec_min (vector bool int, vector signed int); |
12314 | vector signed int vec_min (vector signed int, vector bool int); | |
0ae4308e | 12315 | vector signed int vec_min (vector signed int, vector signed int); |
12316 | vector float vec_min (vector float, vector float); | |
12317 | ||
2b9c51df | 12318 | vector float vec_vminfp (vector float, vector float); |
12319 | ||
12320 | vector signed int vec_vminsw (vector bool int, vector signed int); | |
12321 | vector signed int vec_vminsw (vector signed int, vector bool int); | |
12322 | vector signed int vec_vminsw (vector signed int, vector signed int); | |
12323 | ||
12324 | vector unsigned int vec_vminuw (vector bool int, vector unsigned int); | |
12325 | vector unsigned int vec_vminuw (vector unsigned int, vector bool int); | |
12326 | vector unsigned int vec_vminuw (vector unsigned int, | |
12327 | vector unsigned int); | |
12328 | ||
12329 | vector signed short vec_vminsh (vector bool short, vector signed short); | |
12330 | vector signed short vec_vminsh (vector signed short, vector bool short); | |
12331 | vector signed short vec_vminsh (vector signed short, | |
12332 | vector signed short); | |
12333 | ||
12334 | vector unsigned short vec_vminuh (vector bool short, | |
12335 | vector unsigned short); | |
12336 | vector unsigned short vec_vminuh (vector unsigned short, | |
12337 | vector bool short); | |
12338 | vector unsigned short vec_vminuh (vector unsigned short, | |
12339 | vector unsigned short); | |
12340 | ||
12341 | vector signed char vec_vminsb (vector bool char, vector signed char); | |
12342 | vector signed char vec_vminsb (vector signed char, vector bool char); | |
12343 | vector signed char vec_vminsb (vector signed char, vector signed char); | |
12344 | ||
12345 | vector unsigned char vec_vminub (vector bool char, | |
12346 | vector unsigned char); | |
12347 | vector unsigned char vec_vminub (vector unsigned char, | |
12348 | vector bool char); | |
12349 | vector unsigned char vec_vminub (vector unsigned char, | |
12350 | vector unsigned char); | |
12351 | ||
12352 | vector signed short vec_mladd (vector signed short, | |
12353 | vector signed short, | |
8e1103d3 | 12354 | vector signed short); |
8bdbaccf | 12355 | vector signed short vec_mladd (vector signed short, |
12356 | vector unsigned short, | |
8e1103d3 | 12357 | vector unsigned short); |
8bdbaccf | 12358 | vector signed short vec_mladd (vector unsigned short, |
12359 | vector signed short, | |
8e1103d3 | 12360 | vector signed short); |
12361 | vector unsigned short vec_mladd (vector unsigned short, | |
12362 | vector unsigned short, | |
12363 | vector unsigned short); | |
12364 | ||
8bdbaccf | 12365 | vector signed short vec_mradds (vector signed short, |
12366 | vector signed short, | |
8e1103d3 | 12367 | vector signed short); |
12368 | ||
8bdbaccf | 12369 | vector unsigned int vec_msum (vector unsigned char, |
12370 | vector unsigned char, | |
8e1103d3 | 12371 | vector unsigned int); |
2b9c51df | 12372 | vector signed int vec_msum (vector signed char, |
12373 | vector unsigned char, | |
8e1103d3 | 12374 | vector signed int); |
8bdbaccf | 12375 | vector unsigned int vec_msum (vector unsigned short, |
12376 | vector unsigned short, | |
8e1103d3 | 12377 | vector unsigned int); |
2b9c51df | 12378 | vector signed int vec_msum (vector signed short, |
12379 | vector signed short, | |
8e1103d3 | 12380 | vector signed int); |
12381 | ||
2b9c51df | 12382 | vector signed int vec_vmsumshm (vector signed short, |
12383 | vector signed short, | |
12384 | vector signed int); | |
12385 | ||
12386 | vector unsigned int vec_vmsumuhm (vector unsigned short, | |
12387 | vector unsigned short, | |
12388 | vector unsigned int); | |
12389 | ||
12390 | vector signed int vec_vmsummbm (vector signed char, | |
12391 | vector unsigned char, | |
12392 | vector signed int); | |
12393 | ||
12394 | vector unsigned int vec_vmsumubm (vector unsigned char, | |
12395 | vector unsigned char, | |
12396 | vector unsigned int); | |
12397 | ||
8e1103d3 | 12398 | vector unsigned int vec_msums (vector unsigned short, |
8bdbaccf | 12399 | vector unsigned short, |
12400 | vector unsigned int); | |
2b9c51df | 12401 | vector signed int vec_msums (vector signed short, |
12402 | vector signed short, | |
8e1103d3 | 12403 | vector signed int); |
0ae4308e | 12404 | |
2b9c51df | 12405 | vector signed int vec_vmsumshs (vector signed short, |
12406 | vector signed short, | |
12407 | vector signed int); | |
12408 | ||
12409 | vector unsigned int vec_vmsumuhs (vector unsigned short, | |
12410 | vector unsigned short, | |
12411 | vector unsigned int); | |
12412 | ||
0ae4308e | 12413 | void vec_mtvscr (vector signed int); |
12414 | void vec_mtvscr (vector unsigned int); | |
2b9c51df | 12415 | void vec_mtvscr (vector bool int); |
0ae4308e | 12416 | void vec_mtvscr (vector signed short); |
12417 | void vec_mtvscr (vector unsigned short); | |
2b9c51df | 12418 | void vec_mtvscr (vector bool short); |
12419 | void vec_mtvscr (vector pixel); | |
0ae4308e | 12420 | void vec_mtvscr (vector signed char); |
12421 | void vec_mtvscr (vector unsigned char); | |
2b9c51df | 12422 | void vec_mtvscr (vector bool char); |
0ae4308e | 12423 | |
8bdbaccf | 12424 | vector unsigned short vec_mule (vector unsigned char, |
12425 | vector unsigned char); | |
2b9c51df | 12426 | vector signed short vec_mule (vector signed char, |
12427 | vector signed char); | |
8bdbaccf | 12428 | vector unsigned int vec_mule (vector unsigned short, |
12429 | vector unsigned short); | |
0ae4308e | 12430 | vector signed int vec_mule (vector signed short, vector signed short); |
12431 | ||
2b9c51df | 12432 | vector signed int vec_vmulesh (vector signed short, |
12433 | vector signed short); | |
12434 | ||
12435 | vector unsigned int vec_vmuleuh (vector unsigned short, | |
12436 | vector unsigned short); | |
12437 | ||
12438 | vector signed short vec_vmulesb (vector signed char, | |
12439 | vector signed char); | |
12440 | ||
12441 | vector unsigned short vec_vmuleub (vector unsigned char, | |
12442 | vector unsigned char); | |
12443 | ||
8bdbaccf | 12444 | vector unsigned short vec_mulo (vector unsigned char, |
12445 | vector unsigned char); | |
0ae4308e | 12446 | vector signed short vec_mulo (vector signed char, vector signed char); |
8bdbaccf | 12447 | vector unsigned int vec_mulo (vector unsigned short, |
12448 | vector unsigned short); | |
0ae4308e | 12449 | vector signed int vec_mulo (vector signed short, vector signed short); |
12450 | ||
2b9c51df | 12451 | vector signed int vec_vmulosh (vector signed short, |
12452 | vector signed short); | |
12453 | ||
12454 | vector unsigned int vec_vmulouh (vector unsigned short, | |
12455 | vector unsigned short); | |
12456 | ||
12457 | vector signed short vec_vmulosb (vector signed char, | |
12458 | vector signed char); | |
12459 | ||
12460 | vector unsigned short vec_vmuloub (vector unsigned char, | |
12461 | vector unsigned char); | |
12462 | ||
0ae4308e | 12463 | vector float vec_nmsub (vector float, vector float, vector float); |
12464 | ||
12465 | vector float vec_nor (vector float, vector float); | |
12466 | vector signed int vec_nor (vector signed int, vector signed int); | |
12467 | vector unsigned int vec_nor (vector unsigned int, vector unsigned int); | |
2b9c51df | 12468 | vector bool int vec_nor (vector bool int, vector bool int); |
0ae4308e | 12469 | vector signed short vec_nor (vector signed short, vector signed short); |
8e1103d3 | 12470 | vector unsigned short vec_nor (vector unsigned short, |
12471 | vector unsigned short); | |
2b9c51df | 12472 | vector bool short vec_nor (vector bool short, vector bool short); |
0ae4308e | 12473 | vector signed char vec_nor (vector signed char, vector signed char); |
8bdbaccf | 12474 | vector unsigned char vec_nor (vector unsigned char, |
12475 | vector unsigned char); | |
2b9c51df | 12476 | vector bool char vec_nor (vector bool char, vector bool char); |
0ae4308e | 12477 | |
12478 | vector float vec_or (vector float, vector float); | |
2b9c51df | 12479 | vector float vec_or (vector float, vector bool int); |
12480 | vector float vec_or (vector bool int, vector float); | |
12481 | vector bool int vec_or (vector bool int, vector bool int); | |
12482 | vector signed int vec_or (vector bool int, vector signed int); | |
12483 | vector signed int vec_or (vector signed int, vector bool int); | |
0ae4308e | 12484 | vector signed int vec_or (vector signed int, vector signed int); |
2b9c51df | 12485 | vector unsigned int vec_or (vector bool int, vector unsigned int); |
12486 | vector unsigned int vec_or (vector unsigned int, vector bool int); | |
0ae4308e | 12487 | vector unsigned int vec_or (vector unsigned int, vector unsigned int); |
2b9c51df | 12488 | vector bool short vec_or (vector bool short, vector bool short); |
12489 | vector signed short vec_or (vector bool short, vector signed short); | |
12490 | vector signed short vec_or (vector signed short, vector bool short); | |
0ae4308e | 12491 | vector signed short vec_or (vector signed short, vector signed short); |
2b9c51df | 12492 | vector unsigned short vec_or (vector bool short, vector unsigned short); |
12493 | vector unsigned short vec_or (vector unsigned short, vector bool short); | |
8bdbaccf | 12494 | vector unsigned short vec_or (vector unsigned short, |
12495 | vector unsigned short); | |
2b9c51df | 12496 | vector signed char vec_or (vector bool char, vector signed char); |
12497 | vector bool char vec_or (vector bool char, vector bool char); | |
12498 | vector signed char vec_or (vector signed char, vector bool char); | |
0ae4308e | 12499 | vector signed char vec_or (vector signed char, vector signed char); |
2b9c51df | 12500 | vector unsigned char vec_or (vector bool char, vector unsigned char); |
12501 | vector unsigned char vec_or (vector unsigned char, vector bool char); | |
8bdbaccf | 12502 | vector unsigned char vec_or (vector unsigned char, |
12503 | vector unsigned char); | |
0ae4308e | 12504 | |
12505 | vector signed char vec_pack (vector signed short, vector signed short); | |
8e1103d3 | 12506 | vector unsigned char vec_pack (vector unsigned short, |
12507 | vector unsigned short); | |
2b9c51df | 12508 | vector bool char vec_pack (vector bool short, vector bool short); |
0ae4308e | 12509 | vector signed short vec_pack (vector signed int, vector signed int); |
8bdbaccf | 12510 | vector unsigned short vec_pack (vector unsigned int, |
12511 | vector unsigned int); | |
2b9c51df | 12512 | vector bool short vec_pack (vector bool int, vector bool int); |
0ae4308e | 12513 | |
2b9c51df | 12514 | vector bool short vec_vpkuwum (vector bool int, vector bool int); |
12515 | vector signed short vec_vpkuwum (vector signed int, vector signed int); | |
12516 | vector unsigned short vec_vpkuwum (vector unsigned int, | |
12517 | vector unsigned int); | |
12518 | ||
12519 | vector bool char vec_vpkuhum (vector bool short, vector bool short); | |
12520 | vector signed char vec_vpkuhum (vector signed short, | |
12521 | vector signed short); | |
12522 | vector unsigned char vec_vpkuhum (vector unsigned short, | |
12523 | vector unsigned short); | |
12524 | ||
12525 | vector pixel vec_packpx (vector unsigned int, vector unsigned int); | |
0ae4308e | 12526 | |
8e1103d3 | 12527 | vector unsigned char vec_packs (vector unsigned short, |
12528 | vector unsigned short); | |
0ae4308e | 12529 | vector signed char vec_packs (vector signed short, vector signed short); |
8bdbaccf | 12530 | vector unsigned short vec_packs (vector unsigned int, |
12531 | vector unsigned int); | |
0ae4308e | 12532 | vector signed short vec_packs (vector signed int, vector signed int); |
12533 | ||
2b9c51df | 12534 | vector signed short vec_vpkswss (vector signed int, vector signed int); |
12535 | ||
12536 | vector unsigned short vec_vpkuwus (vector unsigned int, | |
12537 | vector unsigned int); | |
12538 | ||
12539 | vector signed char vec_vpkshss (vector signed short, | |
12540 | vector signed short); | |
12541 | ||
12542 | vector unsigned char vec_vpkuhus (vector unsigned short, | |
12543 | vector unsigned short); | |
12544 | ||
8e1103d3 | 12545 | vector unsigned char vec_packsu (vector unsigned short, |
12546 | vector unsigned short); | |
8bdbaccf | 12547 | vector unsigned char vec_packsu (vector signed short, |
12548 | vector signed short); | |
12549 | vector unsigned short vec_packsu (vector unsigned int, | |
12550 | vector unsigned int); | |
0ae4308e | 12551 | vector unsigned short vec_packsu (vector signed int, vector signed int); |
12552 | ||
2b9c51df | 12553 | vector unsigned short vec_vpkswus (vector signed int, |
12554 | vector signed int); | |
12555 | ||
12556 | vector unsigned char vec_vpkshus (vector signed short, | |
12557 | vector signed short); | |
12558 | ||
12559 | vector float vec_perm (vector float, | |
12560 | vector float, | |
8bdbaccf | 12561 | vector unsigned char); |
2b9c51df | 12562 | vector signed int vec_perm (vector signed int, |
12563 | vector signed int, | |
8e1103d3 | 12564 | vector unsigned char); |
2b9c51df | 12565 | vector unsigned int vec_perm (vector unsigned int, |
12566 | vector unsigned int, | |
8e1103d3 | 12567 | vector unsigned char); |
2b9c51df | 12568 | vector bool int vec_perm (vector bool int, |
12569 | vector bool int, | |
12570 | vector unsigned char); | |
12571 | vector signed short vec_perm (vector signed short, | |
12572 | vector signed short, | |
8e1103d3 | 12573 | vector unsigned char); |
12574 | vector unsigned short vec_perm (vector unsigned short, | |
12575 | vector unsigned short, | |
12576 | vector unsigned char); | |
2b9c51df | 12577 | vector bool short vec_perm (vector bool short, |
12578 | vector bool short, | |
12579 | vector unsigned char); | |
12580 | vector pixel vec_perm (vector pixel, | |
12581 | vector pixel, | |
12582 | vector unsigned char); | |
12583 | vector signed char vec_perm (vector signed char, | |
12584 | vector signed char, | |
8e1103d3 | 12585 | vector unsigned char); |
8bdbaccf | 12586 | vector unsigned char vec_perm (vector unsigned char, |
12587 | vector unsigned char, | |
8e1103d3 | 12588 | vector unsigned char); |
2b9c51df | 12589 | vector bool char vec_perm (vector bool char, |
12590 | vector bool char, | |
12591 | vector unsigned char); | |
0ae4308e | 12592 | |
12593 | vector float vec_re (vector float); | |
12594 | ||
2b9c51df | 12595 | vector signed char vec_rl (vector signed char, |
12596 | vector unsigned char); | |
8bdbaccf | 12597 | vector unsigned char vec_rl (vector unsigned char, |
12598 | vector unsigned char); | |
0ae4308e | 12599 | vector signed short vec_rl (vector signed short, vector unsigned short); |
8bdbaccf | 12600 | vector unsigned short vec_rl (vector unsigned short, |
12601 | vector unsigned short); | |
0ae4308e | 12602 | vector signed int vec_rl (vector signed int, vector unsigned int); |
12603 | vector unsigned int vec_rl (vector unsigned int, vector unsigned int); | |
12604 | ||
2b9c51df | 12605 | vector signed int vec_vrlw (vector signed int, vector unsigned int); |
12606 | vector unsigned int vec_vrlw (vector unsigned int, vector unsigned int); | |
12607 | ||
12608 | vector signed short vec_vrlh (vector signed short, | |
12609 | vector unsigned short); | |
12610 | vector unsigned short vec_vrlh (vector unsigned short, | |
12611 | vector unsigned short); | |
12612 | ||
12613 | vector signed char vec_vrlb (vector signed char, vector unsigned char); | |
12614 | vector unsigned char vec_vrlb (vector unsigned char, | |
12615 | vector unsigned char); | |
12616 | ||
0ae4308e | 12617 | vector float vec_round (vector float); |
12618 | ||
0eac26de | 12619 | vector float vec_recip (vector float, vector float); |
12620 | ||
12621 | vector float vec_rsqrt (vector float); | |
12622 | ||
0ae4308e | 12623 | vector float vec_rsqrte (vector float); |
12624 | ||
2b9c51df | 12625 | vector float vec_sel (vector float, vector float, vector bool int); |
0ae4308e | 12626 | vector float vec_sel (vector float, vector float, vector unsigned int); |
2b9c51df | 12627 | vector signed int vec_sel (vector signed int, |
12628 | vector signed int, | |
12629 | vector bool int); | |
12630 | vector signed int vec_sel (vector signed int, | |
12631 | vector signed int, | |
8e1103d3 | 12632 | vector unsigned int); |
2b9c51df | 12633 | vector unsigned int vec_sel (vector unsigned int, |
12634 | vector unsigned int, | |
12635 | vector bool int); | |
12636 | vector unsigned int vec_sel (vector unsigned int, | |
12637 | vector unsigned int, | |
8e1103d3 | 12638 | vector unsigned int); |
2b9c51df | 12639 | vector bool int vec_sel (vector bool int, |
12640 | vector bool int, | |
12641 | vector bool int); | |
12642 | vector bool int vec_sel (vector bool int, | |
12643 | vector bool int, | |
12644 | vector unsigned int); | |
12645 | vector signed short vec_sel (vector signed short, | |
12646 | vector signed short, | |
12647 | vector bool short); | |
12648 | vector signed short vec_sel (vector signed short, | |
12649 | vector signed short, | |
8e1103d3 | 12650 | vector unsigned short); |
12651 | vector unsigned short vec_sel (vector unsigned short, | |
8bdbaccf | 12652 | vector unsigned short, |
2b9c51df | 12653 | vector bool short); |
8e1103d3 | 12654 | vector unsigned short vec_sel (vector unsigned short, |
12655 | vector unsigned short, | |
12656 | vector unsigned short); | |
2b9c51df | 12657 | vector bool short vec_sel (vector bool short, |
12658 | vector bool short, | |
12659 | vector bool short); | |
12660 | vector bool short vec_sel (vector bool short, | |
12661 | vector bool short, | |
12662 | vector unsigned short); | |
12663 | vector signed char vec_sel (vector signed char, | |
12664 | vector signed char, | |
12665 | vector bool char); | |
12666 | vector signed char vec_sel (vector signed char, | |
12667 | vector signed char, | |
8e1103d3 | 12668 | vector unsigned char); |
8bdbaccf | 12669 | vector unsigned char vec_sel (vector unsigned char, |
12670 | vector unsigned char, | |
2b9c51df | 12671 | vector bool char); |
8bdbaccf | 12672 | vector unsigned char vec_sel (vector unsigned char, |
12673 | vector unsigned char, | |
8e1103d3 | 12674 | vector unsigned char); |
2b9c51df | 12675 | vector bool char vec_sel (vector bool char, |
12676 | vector bool char, | |
12677 | vector bool char); | |
12678 | vector bool char vec_sel (vector bool char, | |
12679 | vector bool char, | |
12680 | vector unsigned char); | |
12681 | ||
12682 | vector signed char vec_sl (vector signed char, | |
12683 | vector unsigned char); | |
8bdbaccf | 12684 | vector unsigned char vec_sl (vector unsigned char, |
12685 | vector unsigned char); | |
0ae4308e | 12686 | vector signed short vec_sl (vector signed short, vector unsigned short); |
8bdbaccf | 12687 | vector unsigned short vec_sl (vector unsigned short, |
12688 | vector unsigned short); | |
0ae4308e | 12689 | vector signed int vec_sl (vector signed int, vector unsigned int); |
12690 | vector unsigned int vec_sl (vector unsigned int, vector unsigned int); | |
12691 | ||
2b9c51df | 12692 | vector signed int vec_vslw (vector signed int, vector unsigned int); |
12693 | vector unsigned int vec_vslw (vector unsigned int, vector unsigned int); | |
12694 | ||
12695 | vector signed short vec_vslh (vector signed short, | |
12696 | vector unsigned short); | |
12697 | vector unsigned short vec_vslh (vector unsigned short, | |
12698 | vector unsigned short); | |
12699 | ||
12700 | vector signed char vec_vslb (vector signed char, vector unsigned char); | |
12701 | vector unsigned char vec_vslb (vector unsigned char, | |
12702 | vector unsigned char); | |
12703 | ||
12704 | vector float vec_sld (vector float, vector float, const int); | |
12705 | vector signed int vec_sld (vector signed int, | |
12706 | vector signed int, | |
12707 | const int); | |
12708 | vector unsigned int vec_sld (vector unsigned int, | |
12709 | vector unsigned int, | |
12710 | const int); | |
12711 | vector bool int vec_sld (vector bool int, | |
12712 | vector bool int, | |
12713 | const int); | |
12714 | vector signed short vec_sld (vector signed short, | |
12715 | vector signed short, | |
12716 | const int); | |
8e1103d3 | 12717 | vector unsigned short vec_sld (vector unsigned short, |
2b9c51df | 12718 | vector unsigned short, |
12719 | const int); | |
12720 | vector bool short vec_sld (vector bool short, | |
12721 | vector bool short, | |
12722 | const int); | |
12723 | vector pixel vec_sld (vector pixel, | |
12724 | vector pixel, | |
12725 | const int); | |
12726 | vector signed char vec_sld (vector signed char, | |
12727 | vector signed char, | |
12728 | const int); | |
8bdbaccf | 12729 | vector unsigned char vec_sld (vector unsigned char, |
12730 | vector unsigned char, | |
2b9c51df | 12731 | const int); |
12732 | vector bool char vec_sld (vector bool char, | |
12733 | vector bool char, | |
12734 | const int); | |
0ae4308e | 12735 | |
2b9c51df | 12736 | vector signed int vec_sll (vector signed int, |
12737 | vector unsigned int); | |
12738 | vector signed int vec_sll (vector signed int, | |
12739 | vector unsigned short); | |
12740 | vector signed int vec_sll (vector signed int, | |
12741 | vector unsigned char); | |
12742 | vector unsigned int vec_sll (vector unsigned int, | |
12743 | vector unsigned int); | |
8bdbaccf | 12744 | vector unsigned int vec_sll (vector unsigned int, |
12745 | vector unsigned short); | |
2b9c51df | 12746 | vector unsigned int vec_sll (vector unsigned int, |
12747 | vector unsigned char); | |
12748 | vector bool int vec_sll (vector bool int, | |
12749 | vector unsigned int); | |
12750 | vector bool int vec_sll (vector bool int, | |
12751 | vector unsigned short); | |
12752 | vector bool int vec_sll (vector bool int, | |
12753 | vector unsigned char); | |
12754 | vector signed short vec_sll (vector signed short, | |
12755 | vector unsigned int); | |
8bdbaccf | 12756 | vector signed short vec_sll (vector signed short, |
12757 | vector unsigned short); | |
2b9c51df | 12758 | vector signed short vec_sll (vector signed short, |
12759 | vector unsigned char); | |
8bdbaccf | 12760 | vector unsigned short vec_sll (vector unsigned short, |
12761 | vector unsigned int); | |
8e1103d3 | 12762 | vector unsigned short vec_sll (vector unsigned short, |
12763 | vector unsigned short); | |
8bdbaccf | 12764 | vector unsigned short vec_sll (vector unsigned short, |
12765 | vector unsigned char); | |
2b9c51df | 12766 | vector bool short vec_sll (vector bool short, vector unsigned int); |
12767 | vector bool short vec_sll (vector bool short, vector unsigned short); | |
12768 | vector bool short vec_sll (vector bool short, vector unsigned char); | |
12769 | vector pixel vec_sll (vector pixel, vector unsigned int); | |
12770 | vector pixel vec_sll (vector pixel, vector unsigned short); | |
12771 | vector pixel vec_sll (vector pixel, vector unsigned char); | |
0ae4308e | 12772 | vector signed char vec_sll (vector signed char, vector unsigned int); |
12773 | vector signed char vec_sll (vector signed char, vector unsigned short); | |
12774 | vector signed char vec_sll (vector signed char, vector unsigned char); | |
8bdbaccf | 12775 | vector unsigned char vec_sll (vector unsigned char, |
12776 | vector unsigned int); | |
12777 | vector unsigned char vec_sll (vector unsigned char, | |
12778 | vector unsigned short); | |
12779 | vector unsigned char vec_sll (vector unsigned char, | |
12780 | vector unsigned char); | |
2b9c51df | 12781 | vector bool char vec_sll (vector bool char, vector unsigned int); |
12782 | vector bool char vec_sll (vector bool char, vector unsigned short); | |
12783 | vector bool char vec_sll (vector bool char, vector unsigned char); | |
0ae4308e | 12784 | |
12785 | vector float vec_slo (vector float, vector signed char); | |
12786 | vector float vec_slo (vector float, vector unsigned char); | |
12787 | vector signed int vec_slo (vector signed int, vector signed char); | |
12788 | vector signed int vec_slo (vector signed int, vector unsigned char); | |
12789 | vector unsigned int vec_slo (vector unsigned int, vector signed char); | |
12790 | vector unsigned int vec_slo (vector unsigned int, vector unsigned char); | |
0ae4308e | 12791 | vector signed short vec_slo (vector signed short, vector signed char); |
12792 | vector signed short vec_slo (vector signed short, vector unsigned char); | |
8bdbaccf | 12793 | vector unsigned short vec_slo (vector unsigned short, |
12794 | vector signed char); | |
12795 | vector unsigned short vec_slo (vector unsigned short, | |
12796 | vector unsigned char); | |
2b9c51df | 12797 | vector pixel vec_slo (vector pixel, vector signed char); |
12798 | vector pixel vec_slo (vector pixel, vector unsigned char); | |
0ae4308e | 12799 | vector signed char vec_slo (vector signed char, vector signed char); |
12800 | vector signed char vec_slo (vector signed char, vector unsigned char); | |
12801 | vector unsigned char vec_slo (vector unsigned char, vector signed char); | |
8bdbaccf | 12802 | vector unsigned char vec_slo (vector unsigned char, |
12803 | vector unsigned char); | |
0ae4308e | 12804 | |
2b9c51df | 12805 | vector signed char vec_splat (vector signed char, const int); |
12806 | vector unsigned char vec_splat (vector unsigned char, const int); | |
12807 | vector bool char vec_splat (vector bool char, const int); | |
12808 | vector signed short vec_splat (vector signed short, const int); | |
12809 | vector unsigned short vec_splat (vector unsigned short, const int); | |
12810 | vector bool short vec_splat (vector bool short, const int); | |
12811 | vector pixel vec_splat (vector pixel, const int); | |
12812 | vector float vec_splat (vector float, const int); | |
12813 | vector signed int vec_splat (vector signed int, const int); | |
12814 | vector unsigned int vec_splat (vector unsigned int, const int); | |
12815 | vector bool int vec_splat (vector bool int, const int); | |
12816 | ||
12817 | vector float vec_vspltw (vector float, const int); | |
12818 | vector signed int vec_vspltw (vector signed int, const int); | |
12819 | vector unsigned int vec_vspltw (vector unsigned int, const int); | |
12820 | vector bool int vec_vspltw (vector bool int, const int); | |
12821 | ||
12822 | vector bool short vec_vsplth (vector bool short, const int); | |
12823 | vector signed short vec_vsplth (vector signed short, const int); | |
12824 | vector unsigned short vec_vsplth (vector unsigned short, const int); | |
12825 | vector pixel vec_vsplth (vector pixel, const int); | |
12826 | ||
12827 | vector signed char vec_vspltb (vector signed char, const int); | |
12828 | vector unsigned char vec_vspltb (vector unsigned char, const int); | |
12829 | vector bool char vec_vspltb (vector bool char, const int); | |
0ae4308e | 12830 | |
2b9c51df | 12831 | vector signed char vec_splat_s8 (const int); |
0ae4308e | 12832 | |
2b9c51df | 12833 | vector signed short vec_splat_s16 (const int); |
0ae4308e | 12834 | |
2b9c51df | 12835 | vector signed int vec_splat_s32 (const int); |
0ae4308e | 12836 | |
2b9c51df | 12837 | vector unsigned char vec_splat_u8 (const int); |
0ae4308e | 12838 | |
2b9c51df | 12839 | vector unsigned short vec_splat_u16 (const int); |
0ae4308e | 12840 | |
2b9c51df | 12841 | vector unsigned int vec_splat_u32 (const int); |
0ae4308e | 12842 | |
12843 | vector signed char vec_sr (vector signed char, vector unsigned char); | |
8bdbaccf | 12844 | vector unsigned char vec_sr (vector unsigned char, |
12845 | vector unsigned char); | |
2b9c51df | 12846 | vector signed short vec_sr (vector signed short, |
12847 | vector unsigned short); | |
8bdbaccf | 12848 | vector unsigned short vec_sr (vector unsigned short, |
12849 | vector unsigned short); | |
0ae4308e | 12850 | vector signed int vec_sr (vector signed int, vector unsigned int); |
12851 | vector unsigned int vec_sr (vector unsigned int, vector unsigned int); | |
12852 | ||
2b9c51df | 12853 | vector signed int vec_vsrw (vector signed int, vector unsigned int); |
12854 | vector unsigned int vec_vsrw (vector unsigned int, vector unsigned int); | |
12855 | ||
12856 | vector signed short vec_vsrh (vector signed short, | |
12857 | vector unsigned short); | |
12858 | vector unsigned short vec_vsrh (vector unsigned short, | |
12859 | vector unsigned short); | |
12860 | ||
12861 | vector signed char vec_vsrb (vector signed char, vector unsigned char); | |
12862 | vector unsigned char vec_vsrb (vector unsigned char, | |
12863 | vector unsigned char); | |
12864 | ||
0ae4308e | 12865 | vector signed char vec_sra (vector signed char, vector unsigned char); |
8bdbaccf | 12866 | vector unsigned char vec_sra (vector unsigned char, |
12867 | vector unsigned char); | |
12868 | vector signed short vec_sra (vector signed short, | |
12869 | vector unsigned short); | |
8e1103d3 | 12870 | vector unsigned short vec_sra (vector unsigned short, |
12871 | vector unsigned short); | |
0ae4308e | 12872 | vector signed int vec_sra (vector signed int, vector unsigned int); |
12873 | vector unsigned int vec_sra (vector unsigned int, vector unsigned int); | |
12874 | ||
2b9c51df | 12875 | vector signed int vec_vsraw (vector signed int, vector unsigned int); |
12876 | vector unsigned int vec_vsraw (vector unsigned int, | |
12877 | vector unsigned int); | |
12878 | ||
12879 | vector signed short vec_vsrah (vector signed short, | |
12880 | vector unsigned short); | |
12881 | vector unsigned short vec_vsrah (vector unsigned short, | |
12882 | vector unsigned short); | |
12883 | ||
12884 | vector signed char vec_vsrab (vector signed char, vector unsigned char); | |
12885 | vector unsigned char vec_vsrab (vector unsigned char, | |
12886 | vector unsigned char); | |
12887 | ||
0ae4308e | 12888 | vector signed int vec_srl (vector signed int, vector unsigned int); |
12889 | vector signed int vec_srl (vector signed int, vector unsigned short); | |
12890 | vector signed int vec_srl (vector signed int, vector unsigned char); | |
12891 | vector unsigned int vec_srl (vector unsigned int, vector unsigned int); | |
8bdbaccf | 12892 | vector unsigned int vec_srl (vector unsigned int, |
12893 | vector unsigned short); | |
0ae4308e | 12894 | vector unsigned int vec_srl (vector unsigned int, vector unsigned char); |
2b9c51df | 12895 | vector bool int vec_srl (vector bool int, vector unsigned int); |
12896 | vector bool int vec_srl (vector bool int, vector unsigned short); | |
12897 | vector bool int vec_srl (vector bool int, vector unsigned char); | |
0ae4308e | 12898 | vector signed short vec_srl (vector signed short, vector unsigned int); |
8bdbaccf | 12899 | vector signed short vec_srl (vector signed short, |
12900 | vector unsigned short); | |
0ae4308e | 12901 | vector signed short vec_srl (vector signed short, vector unsigned char); |
8bdbaccf | 12902 | vector unsigned short vec_srl (vector unsigned short, |
12903 | vector unsigned int); | |
8e1103d3 | 12904 | vector unsigned short vec_srl (vector unsigned short, |
12905 | vector unsigned short); | |
8bdbaccf | 12906 | vector unsigned short vec_srl (vector unsigned short, |
12907 | vector unsigned char); | |
2b9c51df | 12908 | vector bool short vec_srl (vector bool short, vector unsigned int); |
12909 | vector bool short vec_srl (vector bool short, vector unsigned short); | |
12910 | vector bool short vec_srl (vector bool short, vector unsigned char); | |
12911 | vector pixel vec_srl (vector pixel, vector unsigned int); | |
12912 | vector pixel vec_srl (vector pixel, vector unsigned short); | |
12913 | vector pixel vec_srl (vector pixel, vector unsigned char); | |
0ae4308e | 12914 | vector signed char vec_srl (vector signed char, vector unsigned int); |
12915 | vector signed char vec_srl (vector signed char, vector unsigned short); | |
12916 | vector signed char vec_srl (vector signed char, vector unsigned char); | |
8bdbaccf | 12917 | vector unsigned char vec_srl (vector unsigned char, |
12918 | vector unsigned int); | |
12919 | vector unsigned char vec_srl (vector unsigned char, | |
12920 | vector unsigned short); | |
12921 | vector unsigned char vec_srl (vector unsigned char, | |
12922 | vector unsigned char); | |
2b9c51df | 12923 | vector bool char vec_srl (vector bool char, vector unsigned int); |
12924 | vector bool char vec_srl (vector bool char, vector unsigned short); | |
12925 | vector bool char vec_srl (vector bool char, vector unsigned char); | |
0ae4308e | 12926 | |
12927 | vector float vec_sro (vector float, vector signed char); | |
12928 | vector float vec_sro (vector float, vector unsigned char); | |
12929 | vector signed int vec_sro (vector signed int, vector signed char); | |
12930 | vector signed int vec_sro (vector signed int, vector unsigned char); | |
12931 | vector unsigned int vec_sro (vector unsigned int, vector signed char); | |
12932 | vector unsigned int vec_sro (vector unsigned int, vector unsigned char); | |
0ae4308e | 12933 | vector signed short vec_sro (vector signed short, vector signed char); |
12934 | vector signed short vec_sro (vector signed short, vector unsigned char); | |
8bdbaccf | 12935 | vector unsigned short vec_sro (vector unsigned short, |
12936 | vector signed char); | |
12937 | vector unsigned short vec_sro (vector unsigned short, | |
12938 | vector unsigned char); | |
2b9c51df | 12939 | vector pixel vec_sro (vector pixel, vector signed char); |
12940 | vector pixel vec_sro (vector pixel, vector unsigned char); | |
0ae4308e | 12941 | vector signed char vec_sro (vector signed char, vector signed char); |
12942 | vector signed char vec_sro (vector signed char, vector unsigned char); | |
12943 | vector unsigned char vec_sro (vector unsigned char, vector signed char); | |
8bdbaccf | 12944 | vector unsigned char vec_sro (vector unsigned char, |
12945 | vector unsigned char); | |
0ae4308e | 12946 | |
0ae4308e | 12947 | void vec_st (vector float, int, vector float *); |
2b9c51df | 12948 | void vec_st (vector float, int, float *); |
12949 | void vec_st (vector signed int, int, vector signed int *); | |
0ae4308e | 12950 | void vec_st (vector signed int, int, int *); |
0ae4308e | 12951 | void vec_st (vector unsigned int, int, vector unsigned int *); |
2b9c51df | 12952 | void vec_st (vector unsigned int, int, unsigned int *); |
12953 | void vec_st (vector bool int, int, vector bool int *); | |
12954 | void vec_st (vector bool int, int, unsigned int *); | |
12955 | void vec_st (vector bool int, int, int *); | |
0ae4308e | 12956 | void vec_st (vector signed short, int, vector signed short *); |
2b9c51df | 12957 | void vec_st (vector signed short, int, short *); |
0ae4308e | 12958 | void vec_st (vector unsigned short, int, vector unsigned short *); |
2b9c51df | 12959 | void vec_st (vector unsigned short, int, unsigned short *); |
12960 | void vec_st (vector bool short, int, vector bool short *); | |
12961 | void vec_st (vector bool short, int, unsigned short *); | |
12962 | void vec_st (vector pixel, int, vector pixel *); | |
12963 | void vec_st (vector pixel, int, unsigned short *); | |
12964 | void vec_st (vector pixel, int, short *); | |
12965 | void vec_st (vector bool short, int, short *); | |
0ae4308e | 12966 | void vec_st (vector signed char, int, vector signed char *); |
2b9c51df | 12967 | void vec_st (vector signed char, int, signed char *); |
0ae4308e | 12968 | void vec_st (vector unsigned char, int, vector unsigned char *); |
2b9c51df | 12969 | void vec_st (vector unsigned char, int, unsigned char *); |
12970 | void vec_st (vector bool char, int, vector bool char *); | |
12971 | void vec_st (vector bool char, int, unsigned char *); | |
12972 | void vec_st (vector bool char, int, signed char *); | |
0ae4308e | 12973 | |
0ae4308e | 12974 | void vec_ste (vector signed char, int, signed char *); |
12975 | void vec_ste (vector unsigned char, int, unsigned char *); | |
2b9c51df | 12976 | void vec_ste (vector bool char, int, signed char *); |
12977 | void vec_ste (vector bool char, int, unsigned char *); | |
0ae4308e | 12978 | void vec_ste (vector signed short, int, short *); |
2b9c51df | 12979 | void vec_ste (vector unsigned short, int, unsigned short *); |
12980 | void vec_ste (vector bool short, int, short *); | |
12981 | void vec_ste (vector bool short, int, unsigned short *); | |
12982 | void vec_ste (vector pixel, int, short *); | |
12983 | void vec_ste (vector pixel, int, unsigned short *); | |
12984 | void vec_ste (vector float, int, float *); | |
0ae4308e | 12985 | void vec_ste (vector signed int, int, int *); |
12986 | void vec_ste (vector unsigned int, int, unsigned int *); | |
2b9c51df | 12987 | void vec_ste (vector bool int, int, int *); |
12988 | void vec_ste (vector bool int, int, unsigned int *); | |
12989 | ||
12990 | void vec_stvewx (vector float, int, float *); | |
12991 | void vec_stvewx (vector signed int, int, int *); | |
12992 | void vec_stvewx (vector unsigned int, int, unsigned int *); | |
12993 | void vec_stvewx (vector bool int, int, int *); | |
12994 | void vec_stvewx (vector bool int, int, unsigned int *); | |
12995 | ||
12996 | void vec_stvehx (vector signed short, int, short *); | |
12997 | void vec_stvehx (vector unsigned short, int, unsigned short *); | |
12998 | void vec_stvehx (vector bool short, int, short *); | |
12999 | void vec_stvehx (vector bool short, int, unsigned short *); | |
13000 | void vec_stvehx (vector pixel, int, short *); | |
13001 | void vec_stvehx (vector pixel, int, unsigned short *); | |
13002 | ||
13003 | void vec_stvebx (vector signed char, int, signed char *); | |
13004 | void vec_stvebx (vector unsigned char, int, unsigned char *); | |
13005 | void vec_stvebx (vector bool char, int, signed char *); | |
13006 | void vec_stvebx (vector bool char, int, unsigned char *); | |
0ae4308e | 13007 | |
13008 | void vec_stl (vector float, int, vector float *); | |
13009 | void vec_stl (vector float, int, float *); | |
13010 | void vec_stl (vector signed int, int, vector signed int *); | |
13011 | void vec_stl (vector signed int, int, int *); | |
0ae4308e | 13012 | void vec_stl (vector unsigned int, int, vector unsigned int *); |
13013 | void vec_stl (vector unsigned int, int, unsigned int *); | |
2b9c51df | 13014 | void vec_stl (vector bool int, int, vector bool int *); |
13015 | void vec_stl (vector bool int, int, unsigned int *); | |
13016 | void vec_stl (vector bool int, int, int *); | |
0ae4308e | 13017 | void vec_stl (vector signed short, int, vector signed short *); |
2b9c51df | 13018 | void vec_stl (vector signed short, int, short *); |
13019 | void vec_stl (vector unsigned short, int, vector unsigned short *); | |
0ae4308e | 13020 | void vec_stl (vector unsigned short, int, unsigned short *); |
2b9c51df | 13021 | void vec_stl (vector bool short, int, vector bool short *); |
13022 | void vec_stl (vector bool short, int, unsigned short *); | |
13023 | void vec_stl (vector bool short, int, short *); | |
13024 | void vec_stl (vector pixel, int, vector pixel *); | |
13025 | void vec_stl (vector pixel, int, unsigned short *); | |
13026 | void vec_stl (vector pixel, int, short *); | |
0ae4308e | 13027 | void vec_stl (vector signed char, int, vector signed char *); |
2b9c51df | 13028 | void vec_stl (vector signed char, int, signed char *); |
0ae4308e | 13029 | void vec_stl (vector unsigned char, int, vector unsigned char *); |
2b9c51df | 13030 | void vec_stl (vector unsigned char, int, unsigned char *); |
13031 | void vec_stl (vector bool char, int, vector bool char *); | |
13032 | void vec_stl (vector bool char, int, unsigned char *); | |
13033 | void vec_stl (vector bool char, int, signed char *); | |
0ae4308e | 13034 | |
2b9c51df | 13035 | vector signed char vec_sub (vector bool char, vector signed char); |
13036 | vector signed char vec_sub (vector signed char, vector bool char); | |
0ae4308e | 13037 | vector signed char vec_sub (vector signed char, vector signed char); |
2b9c51df | 13038 | vector unsigned char vec_sub (vector bool char, vector unsigned char); |
13039 | vector unsigned char vec_sub (vector unsigned char, vector bool char); | |
8bdbaccf | 13040 | vector unsigned char vec_sub (vector unsigned char, |
13041 | vector unsigned char); | |
2b9c51df | 13042 | vector signed short vec_sub (vector bool short, vector signed short); |
13043 | vector signed short vec_sub (vector signed short, vector bool short); | |
0ae4308e | 13044 | vector signed short vec_sub (vector signed short, vector signed short); |
2b9c51df | 13045 | vector unsigned short vec_sub (vector bool short, |
8bdbaccf | 13046 | vector unsigned short); |
13047 | vector unsigned short vec_sub (vector unsigned short, | |
2b9c51df | 13048 | vector bool short); |
8e1103d3 | 13049 | vector unsigned short vec_sub (vector unsigned short, |
13050 | vector unsigned short); | |
2b9c51df | 13051 | vector signed int vec_sub (vector bool int, vector signed int); |
13052 | vector signed int vec_sub (vector signed int, vector bool int); | |
0ae4308e | 13053 | vector signed int vec_sub (vector signed int, vector signed int); |
2b9c51df | 13054 | vector unsigned int vec_sub (vector bool int, vector unsigned int); |
13055 | vector unsigned int vec_sub (vector unsigned int, vector bool int); | |
0ae4308e | 13056 | vector unsigned int vec_sub (vector unsigned int, vector unsigned int); |
13057 | vector float vec_sub (vector float, vector float); | |
13058 | ||
2b9c51df | 13059 | vector float vec_vsubfp (vector float, vector float); |
13060 | ||
13061 | vector signed int vec_vsubuwm (vector bool int, vector signed int); | |
13062 | vector signed int vec_vsubuwm (vector signed int, vector bool int); | |
13063 | vector signed int vec_vsubuwm (vector signed int, vector signed int); | |
13064 | vector unsigned int vec_vsubuwm (vector bool int, vector unsigned int); | |
13065 | vector unsigned int vec_vsubuwm (vector unsigned int, vector bool int); | |
13066 | vector unsigned int vec_vsubuwm (vector unsigned int, | |
13067 | vector unsigned int); | |
13068 | ||
13069 | vector signed short vec_vsubuhm (vector bool short, | |
13070 | vector signed short); | |
13071 | vector signed short vec_vsubuhm (vector signed short, | |
13072 | vector bool short); | |
13073 | vector signed short vec_vsubuhm (vector signed short, | |
13074 | vector signed short); | |
13075 | vector unsigned short vec_vsubuhm (vector bool short, | |
13076 | vector unsigned short); | |
13077 | vector unsigned short vec_vsubuhm (vector unsigned short, | |
13078 | vector bool short); | |
13079 | vector unsigned short vec_vsubuhm (vector unsigned short, | |
13080 | vector unsigned short); | |
13081 | ||
13082 | vector signed char vec_vsububm (vector bool char, vector signed char); | |
13083 | vector signed char vec_vsububm (vector signed char, vector bool char); | |
13084 | vector signed char vec_vsububm (vector signed char, vector signed char); | |
13085 | vector unsigned char vec_vsububm (vector bool char, | |
13086 | vector unsigned char); | |
13087 | vector unsigned char vec_vsububm (vector unsigned char, | |
13088 | vector bool char); | |
13089 | vector unsigned char vec_vsububm (vector unsigned char, | |
13090 | vector unsigned char); | |
13091 | ||
0ae4308e | 13092 | vector unsigned int vec_subc (vector unsigned int, vector unsigned int); |
13093 | ||
2b9c51df | 13094 | vector unsigned char vec_subs (vector bool char, vector unsigned char); |
13095 | vector unsigned char vec_subs (vector unsigned char, vector bool char); | |
8bdbaccf | 13096 | vector unsigned char vec_subs (vector unsigned char, |
13097 | vector unsigned char); | |
2b9c51df | 13098 | vector signed char vec_subs (vector bool char, vector signed char); |
13099 | vector signed char vec_subs (vector signed char, vector bool char); | |
0ae4308e | 13100 | vector signed char vec_subs (vector signed char, vector signed char); |
2b9c51df | 13101 | vector unsigned short vec_subs (vector bool short, |
8bdbaccf | 13102 | vector unsigned short); |
13103 | vector unsigned short vec_subs (vector unsigned short, | |
2b9c51df | 13104 | vector bool short); |
8e1103d3 | 13105 | vector unsigned short vec_subs (vector unsigned short, |
13106 | vector unsigned short); | |
2b9c51df | 13107 | vector signed short vec_subs (vector bool short, vector signed short); |
13108 | vector signed short vec_subs (vector signed short, vector bool short); | |
0ae4308e | 13109 | vector signed short vec_subs (vector signed short, vector signed short); |
2b9c51df | 13110 | vector unsigned int vec_subs (vector bool int, vector unsigned int); |
13111 | vector unsigned int vec_subs (vector unsigned int, vector bool int); | |
0ae4308e | 13112 | vector unsigned int vec_subs (vector unsigned int, vector unsigned int); |
2b9c51df | 13113 | vector signed int vec_subs (vector bool int, vector signed int); |
13114 | vector signed int vec_subs (vector signed int, vector bool int); | |
0ae4308e | 13115 | vector signed int vec_subs (vector signed int, vector signed int); |
13116 | ||
2b9c51df | 13117 | vector signed int vec_vsubsws (vector bool int, vector signed int); |
13118 | vector signed int vec_vsubsws (vector signed int, vector bool int); | |
13119 | vector signed int vec_vsubsws (vector signed int, vector signed int); | |
13120 | ||
13121 | vector unsigned int vec_vsubuws (vector bool int, vector unsigned int); | |
13122 | vector unsigned int vec_vsubuws (vector unsigned int, vector bool int); | |
13123 | vector unsigned int vec_vsubuws (vector unsigned int, | |
13124 | vector unsigned int); | |
13125 | ||
13126 | vector signed short vec_vsubshs (vector bool short, | |
13127 | vector signed short); | |
13128 | vector signed short vec_vsubshs (vector signed short, | |
13129 | vector bool short); | |
13130 | vector signed short vec_vsubshs (vector signed short, | |
13131 | vector signed short); | |
13132 | ||
13133 | vector unsigned short vec_vsubuhs (vector bool short, | |
13134 | vector unsigned short); | |
13135 | vector unsigned short vec_vsubuhs (vector unsigned short, | |
13136 | vector bool short); | |
13137 | vector unsigned short vec_vsubuhs (vector unsigned short, | |
13138 | vector unsigned short); | |
13139 | ||
13140 | vector signed char vec_vsubsbs (vector bool char, vector signed char); | |
13141 | vector signed char vec_vsubsbs (vector signed char, vector bool char); | |
13142 | vector signed char vec_vsubsbs (vector signed char, vector signed char); | |
13143 | ||
13144 | vector unsigned char vec_vsububs (vector bool char, | |
13145 | vector unsigned char); | |
13146 | vector unsigned char vec_vsububs (vector unsigned char, | |
13147 | vector bool char); | |
13148 | vector unsigned char vec_vsububs (vector unsigned char, | |
13149 | vector unsigned char); | |
13150 | ||
8bdbaccf | 13151 | vector unsigned int vec_sum4s (vector unsigned char, |
13152 | vector unsigned int); | |
0ae4308e | 13153 | vector signed int vec_sum4s (vector signed char, vector signed int); |
13154 | vector signed int vec_sum4s (vector signed short, vector signed int); | |
13155 | ||
2b9c51df | 13156 | vector signed int vec_vsum4shs (vector signed short, vector signed int); |
13157 | ||
13158 | vector signed int vec_vsum4sbs (vector signed char, vector signed int); | |
13159 | ||
13160 | vector unsigned int vec_vsum4ubs (vector unsigned char, | |
13161 | vector unsigned int); | |
13162 | ||
0ae4308e | 13163 | vector signed int vec_sum2s (vector signed int, vector signed int); |
13164 | ||
13165 | vector signed int vec_sums (vector signed int, vector signed int); | |
13166 | ||
13167 | vector float vec_trunc (vector float); | |
13168 | ||
13169 | vector signed short vec_unpackh (vector signed char); | |
2b9c51df | 13170 | vector bool short vec_unpackh (vector bool char); |
0ae4308e | 13171 | vector signed int vec_unpackh (vector signed short); |
2b9c51df | 13172 | vector bool int vec_unpackh (vector bool short); |
13173 | vector unsigned int vec_unpackh (vector pixel); | |
13174 | ||
13175 | vector bool int vec_vupkhsh (vector bool short); | |
13176 | vector signed int vec_vupkhsh (vector signed short); | |
13177 | ||
13178 | vector unsigned int vec_vupkhpx (vector pixel); | |
13179 | ||
13180 | vector bool short vec_vupkhsb (vector bool char); | |
13181 | vector signed short vec_vupkhsb (vector signed char); | |
0ae4308e | 13182 | |
13183 | vector signed short vec_unpackl (vector signed char); | |
2b9c51df | 13184 | vector bool short vec_unpackl (vector bool char); |
13185 | vector unsigned int vec_unpackl (vector pixel); | |
0ae4308e | 13186 | vector signed int vec_unpackl (vector signed short); |
2b9c51df | 13187 | vector bool int vec_unpackl (vector bool short); |
13188 | ||
13189 | vector unsigned int vec_vupklpx (vector pixel); | |
13190 | ||
13191 | vector bool int vec_vupklsh (vector bool short); | |
13192 | vector signed int vec_vupklsh (vector signed short); | |
13193 | ||
13194 | vector bool short vec_vupklsb (vector bool char); | |
13195 | vector signed short vec_vupklsb (vector signed char); | |
0ae4308e | 13196 | |
13197 | vector float vec_xor (vector float, vector float); | |
2b9c51df | 13198 | vector float vec_xor (vector float, vector bool int); |
13199 | vector float vec_xor (vector bool int, vector float); | |
13200 | vector bool int vec_xor (vector bool int, vector bool int); | |
13201 | vector signed int vec_xor (vector bool int, vector signed int); | |
13202 | vector signed int vec_xor (vector signed int, vector bool int); | |
0ae4308e | 13203 | vector signed int vec_xor (vector signed int, vector signed int); |
2b9c51df | 13204 | vector unsigned int vec_xor (vector bool int, vector unsigned int); |
13205 | vector unsigned int vec_xor (vector unsigned int, vector bool int); | |
0ae4308e | 13206 | vector unsigned int vec_xor (vector unsigned int, vector unsigned int); |
2b9c51df | 13207 | vector bool short vec_xor (vector bool short, vector bool short); |
13208 | vector signed short vec_xor (vector bool short, vector signed short); | |
13209 | vector signed short vec_xor (vector signed short, vector bool short); | |
0ae4308e | 13210 | vector signed short vec_xor (vector signed short, vector signed short); |
2b9c51df | 13211 | vector unsigned short vec_xor (vector bool short, |
8bdbaccf | 13212 | vector unsigned short); |
13213 | vector unsigned short vec_xor (vector unsigned short, | |
2b9c51df | 13214 | vector bool short); |
8e1103d3 | 13215 | vector unsigned short vec_xor (vector unsigned short, |
13216 | vector unsigned short); | |
2b9c51df | 13217 | vector signed char vec_xor (vector bool char, vector signed char); |
13218 | vector bool char vec_xor (vector bool char, vector bool char); | |
13219 | vector signed char vec_xor (vector signed char, vector bool char); | |
0ae4308e | 13220 | vector signed char vec_xor (vector signed char, vector signed char); |
2b9c51df | 13221 | vector unsigned char vec_xor (vector bool char, vector unsigned char); |
13222 | vector unsigned char vec_xor (vector unsigned char, vector bool char); | |
8bdbaccf | 13223 | vector unsigned char vec_xor (vector unsigned char, |
13224 | vector unsigned char); | |
0ae4308e | 13225 | |
2b9c51df | 13226 | int vec_all_eq (vector signed char, vector bool char); |
13227 | int vec_all_eq (vector signed char, vector signed char); | |
13228 | int vec_all_eq (vector unsigned char, vector bool char); | |
13229 | int vec_all_eq (vector unsigned char, vector unsigned char); | |
13230 | int vec_all_eq (vector bool char, vector bool char); | |
13231 | int vec_all_eq (vector bool char, vector unsigned char); | |
13232 | int vec_all_eq (vector bool char, vector signed char); | |
13233 | int vec_all_eq (vector signed short, vector bool short); | |
13234 | int vec_all_eq (vector signed short, vector signed short); | |
13235 | int vec_all_eq (vector unsigned short, vector bool short); | |
13236 | int vec_all_eq (vector unsigned short, vector unsigned short); | |
13237 | int vec_all_eq (vector bool short, vector bool short); | |
13238 | int vec_all_eq (vector bool short, vector unsigned short); | |
13239 | int vec_all_eq (vector bool short, vector signed short); | |
13240 | int vec_all_eq (vector pixel, vector pixel); | |
13241 | int vec_all_eq (vector signed int, vector bool int); | |
13242 | int vec_all_eq (vector signed int, vector signed int); | |
13243 | int vec_all_eq (vector unsigned int, vector bool int); | |
13244 | int vec_all_eq (vector unsigned int, vector unsigned int); | |
13245 | int vec_all_eq (vector bool int, vector bool int); | |
13246 | int vec_all_eq (vector bool int, vector unsigned int); | |
13247 | int vec_all_eq (vector bool int, vector signed int); | |
13248 | int vec_all_eq (vector float, vector float); | |
13249 | ||
13250 | int vec_all_ge (vector bool char, vector unsigned char); | |
13251 | int vec_all_ge (vector unsigned char, vector bool char); | |
13252 | int vec_all_ge (vector unsigned char, vector unsigned char); | |
13253 | int vec_all_ge (vector bool char, vector signed char); | |
13254 | int vec_all_ge (vector signed char, vector bool char); | |
13255 | int vec_all_ge (vector signed char, vector signed char); | |
13256 | int vec_all_ge (vector bool short, vector unsigned short); | |
13257 | int vec_all_ge (vector unsigned short, vector bool short); | |
13258 | int vec_all_ge (vector unsigned short, vector unsigned short); | |
13259 | int vec_all_ge (vector signed short, vector signed short); | |
13260 | int vec_all_ge (vector bool short, vector signed short); | |
13261 | int vec_all_ge (vector signed short, vector bool short); | |
13262 | int vec_all_ge (vector bool int, vector unsigned int); | |
13263 | int vec_all_ge (vector unsigned int, vector bool int); | |
13264 | int vec_all_ge (vector unsigned int, vector unsigned int); | |
13265 | int vec_all_ge (vector bool int, vector signed int); | |
13266 | int vec_all_ge (vector signed int, vector bool int); | |
13267 | int vec_all_ge (vector signed int, vector signed int); | |
13268 | int vec_all_ge (vector float, vector float); | |
13269 | ||
13270 | int vec_all_gt (vector bool char, vector unsigned char); | |
13271 | int vec_all_gt (vector unsigned char, vector bool char); | |
13272 | int vec_all_gt (vector unsigned char, vector unsigned char); | |
13273 | int vec_all_gt (vector bool char, vector signed char); | |
13274 | int vec_all_gt (vector signed char, vector bool char); | |
13275 | int vec_all_gt (vector signed char, vector signed char); | |
13276 | int vec_all_gt (vector bool short, vector unsigned short); | |
13277 | int vec_all_gt (vector unsigned short, vector bool short); | |
13278 | int vec_all_gt (vector unsigned short, vector unsigned short); | |
13279 | int vec_all_gt (vector bool short, vector signed short); | |
13280 | int vec_all_gt (vector signed short, vector bool short); | |
13281 | int vec_all_gt (vector signed short, vector signed short); | |
13282 | int vec_all_gt (vector bool int, vector unsigned int); | |
13283 | int vec_all_gt (vector unsigned int, vector bool int); | |
13284 | int vec_all_gt (vector unsigned int, vector unsigned int); | |
13285 | int vec_all_gt (vector bool int, vector signed int); | |
13286 | int vec_all_gt (vector signed int, vector bool int); | |
13287 | int vec_all_gt (vector signed int, vector signed int); | |
13288 | int vec_all_gt (vector float, vector float); | |
13289 | ||
13290 | int vec_all_in (vector float, vector float); | |
13291 | ||
13292 | int vec_all_le (vector bool char, vector unsigned char); | |
13293 | int vec_all_le (vector unsigned char, vector bool char); | |
13294 | int vec_all_le (vector unsigned char, vector unsigned char); | |
13295 | int vec_all_le (vector bool char, vector signed char); | |
13296 | int vec_all_le (vector signed char, vector bool char); | |
13297 | int vec_all_le (vector signed char, vector signed char); | |
13298 | int vec_all_le (vector bool short, vector unsigned short); | |
13299 | int vec_all_le (vector unsigned short, vector bool short); | |
13300 | int vec_all_le (vector unsigned short, vector unsigned short); | |
13301 | int vec_all_le (vector bool short, vector signed short); | |
13302 | int vec_all_le (vector signed short, vector bool short); | |
13303 | int vec_all_le (vector signed short, vector signed short); | |
13304 | int vec_all_le (vector bool int, vector unsigned int); | |
13305 | int vec_all_le (vector unsigned int, vector bool int); | |
13306 | int vec_all_le (vector unsigned int, vector unsigned int); | |
13307 | int vec_all_le (vector bool int, vector signed int); | |
13308 | int vec_all_le (vector signed int, vector bool int); | |
13309 | int vec_all_le (vector signed int, vector signed int); | |
13310 | int vec_all_le (vector float, vector float); | |
13311 | ||
13312 | int vec_all_lt (vector bool char, vector unsigned char); | |
13313 | int vec_all_lt (vector unsigned char, vector bool char); | |
13314 | int vec_all_lt (vector unsigned char, vector unsigned char); | |
13315 | int vec_all_lt (vector bool char, vector signed char); | |
13316 | int vec_all_lt (vector signed char, vector bool char); | |
13317 | int vec_all_lt (vector signed char, vector signed char); | |
13318 | int vec_all_lt (vector bool short, vector unsigned short); | |
13319 | int vec_all_lt (vector unsigned short, vector bool short); | |
13320 | int vec_all_lt (vector unsigned short, vector unsigned short); | |
13321 | int vec_all_lt (vector bool short, vector signed short); | |
13322 | int vec_all_lt (vector signed short, vector bool short); | |
13323 | int vec_all_lt (vector signed short, vector signed short); | |
13324 | int vec_all_lt (vector bool int, vector unsigned int); | |
13325 | int vec_all_lt (vector unsigned int, vector bool int); | |
13326 | int vec_all_lt (vector unsigned int, vector unsigned int); | |
13327 | int vec_all_lt (vector bool int, vector signed int); | |
13328 | int vec_all_lt (vector signed int, vector bool int); | |
13329 | int vec_all_lt (vector signed int, vector signed int); | |
13330 | int vec_all_lt (vector float, vector float); | |
13331 | ||
13332 | int vec_all_nan (vector float); | |
13333 | ||
13334 | int vec_all_ne (vector signed char, vector bool char); | |
13335 | int vec_all_ne (vector signed char, vector signed char); | |
13336 | int vec_all_ne (vector unsigned char, vector bool char); | |
13337 | int vec_all_ne (vector unsigned char, vector unsigned char); | |
13338 | int vec_all_ne (vector bool char, vector bool char); | |
13339 | int vec_all_ne (vector bool char, vector unsigned char); | |
13340 | int vec_all_ne (vector bool char, vector signed char); | |
13341 | int vec_all_ne (vector signed short, vector bool short); | |
13342 | int vec_all_ne (vector signed short, vector signed short); | |
13343 | int vec_all_ne (vector unsigned short, vector bool short); | |
13344 | int vec_all_ne (vector unsigned short, vector unsigned short); | |
13345 | int vec_all_ne (vector bool short, vector bool short); | |
13346 | int vec_all_ne (vector bool short, vector unsigned short); | |
13347 | int vec_all_ne (vector bool short, vector signed short); | |
13348 | int vec_all_ne (vector pixel, vector pixel); | |
13349 | int vec_all_ne (vector signed int, vector bool int); | |
13350 | int vec_all_ne (vector signed int, vector signed int); | |
13351 | int vec_all_ne (vector unsigned int, vector bool int); | |
13352 | int vec_all_ne (vector unsigned int, vector unsigned int); | |
13353 | int vec_all_ne (vector bool int, vector bool int); | |
13354 | int vec_all_ne (vector bool int, vector unsigned int); | |
13355 | int vec_all_ne (vector bool int, vector signed int); | |
13356 | int vec_all_ne (vector float, vector float); | |
13357 | ||
13358 | int vec_all_nge (vector float, vector float); | |
13359 | ||
13360 | int vec_all_ngt (vector float, vector float); | |
13361 | ||
13362 | int vec_all_nle (vector float, vector float); | |
13363 | ||
13364 | int vec_all_nlt (vector float, vector float); | |
13365 | ||
13366 | int vec_all_numeric (vector float); | |
13367 | ||
13368 | int vec_any_eq (vector signed char, vector bool char); | |
13369 | int vec_any_eq (vector signed char, vector signed char); | |
13370 | int vec_any_eq (vector unsigned char, vector bool char); | |
13371 | int vec_any_eq (vector unsigned char, vector unsigned char); | |
13372 | int vec_any_eq (vector bool char, vector bool char); | |
13373 | int vec_any_eq (vector bool char, vector unsigned char); | |
13374 | int vec_any_eq (vector bool char, vector signed char); | |
13375 | int vec_any_eq (vector signed short, vector bool short); | |
13376 | int vec_any_eq (vector signed short, vector signed short); | |
13377 | int vec_any_eq (vector unsigned short, vector bool short); | |
13378 | int vec_any_eq (vector unsigned short, vector unsigned short); | |
13379 | int vec_any_eq (vector bool short, vector bool short); | |
13380 | int vec_any_eq (vector bool short, vector unsigned short); | |
13381 | int vec_any_eq (vector bool short, vector signed short); | |
13382 | int vec_any_eq (vector pixel, vector pixel); | |
13383 | int vec_any_eq (vector signed int, vector bool int); | |
13384 | int vec_any_eq (vector signed int, vector signed int); | |
13385 | int vec_any_eq (vector unsigned int, vector bool int); | |
13386 | int vec_any_eq (vector unsigned int, vector unsigned int); | |
13387 | int vec_any_eq (vector bool int, vector bool int); | |
13388 | int vec_any_eq (vector bool int, vector unsigned int); | |
13389 | int vec_any_eq (vector bool int, vector signed int); | |
13390 | int vec_any_eq (vector float, vector float); | |
13391 | ||
13392 | int vec_any_ge (vector signed char, vector bool char); | |
13393 | int vec_any_ge (vector unsigned char, vector bool char); | |
13394 | int vec_any_ge (vector unsigned char, vector unsigned char); | |
13395 | int vec_any_ge (vector signed char, vector signed char); | |
13396 | int vec_any_ge (vector bool char, vector unsigned char); | |
13397 | int vec_any_ge (vector bool char, vector signed char); | |
13398 | int vec_any_ge (vector unsigned short, vector bool short); | |
13399 | int vec_any_ge (vector unsigned short, vector unsigned short); | |
13400 | int vec_any_ge (vector signed short, vector signed short); | |
13401 | int vec_any_ge (vector signed short, vector bool short); | |
13402 | int vec_any_ge (vector bool short, vector unsigned short); | |
13403 | int vec_any_ge (vector bool short, vector signed short); | |
13404 | int vec_any_ge (vector signed int, vector bool int); | |
13405 | int vec_any_ge (vector unsigned int, vector bool int); | |
13406 | int vec_any_ge (vector unsigned int, vector unsigned int); | |
13407 | int vec_any_ge (vector signed int, vector signed int); | |
13408 | int vec_any_ge (vector bool int, vector unsigned int); | |
13409 | int vec_any_ge (vector bool int, vector signed int); | |
13410 | int vec_any_ge (vector float, vector float); | |
13411 | ||
13412 | int vec_any_gt (vector bool char, vector unsigned char); | |
13413 | int vec_any_gt (vector unsigned char, vector bool char); | |
13414 | int vec_any_gt (vector unsigned char, vector unsigned char); | |
13415 | int vec_any_gt (vector bool char, vector signed char); | |
13416 | int vec_any_gt (vector signed char, vector bool char); | |
13417 | int vec_any_gt (vector signed char, vector signed char); | |
13418 | int vec_any_gt (vector bool short, vector unsigned short); | |
13419 | int vec_any_gt (vector unsigned short, vector bool short); | |
13420 | int vec_any_gt (vector unsigned short, vector unsigned short); | |
13421 | int vec_any_gt (vector bool short, vector signed short); | |
13422 | int vec_any_gt (vector signed short, vector bool short); | |
13423 | int vec_any_gt (vector signed short, vector signed short); | |
13424 | int vec_any_gt (vector bool int, vector unsigned int); | |
13425 | int vec_any_gt (vector unsigned int, vector bool int); | |
13426 | int vec_any_gt (vector unsigned int, vector unsigned int); | |
13427 | int vec_any_gt (vector bool int, vector signed int); | |
13428 | int vec_any_gt (vector signed int, vector bool int); | |
13429 | int vec_any_gt (vector signed int, vector signed int); | |
13430 | int vec_any_gt (vector float, vector float); | |
13431 | ||
13432 | int vec_any_le (vector bool char, vector unsigned char); | |
13433 | int vec_any_le (vector unsigned char, vector bool char); | |
13434 | int vec_any_le (vector unsigned char, vector unsigned char); | |
13435 | int vec_any_le (vector bool char, vector signed char); | |
13436 | int vec_any_le (vector signed char, vector bool char); | |
13437 | int vec_any_le (vector signed char, vector signed char); | |
13438 | int vec_any_le (vector bool short, vector unsigned short); | |
13439 | int vec_any_le (vector unsigned short, vector bool short); | |
13440 | int vec_any_le (vector unsigned short, vector unsigned short); | |
13441 | int vec_any_le (vector bool short, vector signed short); | |
13442 | int vec_any_le (vector signed short, vector bool short); | |
13443 | int vec_any_le (vector signed short, vector signed short); | |
13444 | int vec_any_le (vector bool int, vector unsigned int); | |
13445 | int vec_any_le (vector unsigned int, vector bool int); | |
13446 | int vec_any_le (vector unsigned int, vector unsigned int); | |
13447 | int vec_any_le (vector bool int, vector signed int); | |
13448 | int vec_any_le (vector signed int, vector bool int); | |
13449 | int vec_any_le (vector signed int, vector signed int); | |
13450 | int vec_any_le (vector float, vector float); | |
13451 | ||
13452 | int vec_any_lt (vector bool char, vector unsigned char); | |
13453 | int vec_any_lt (vector unsigned char, vector bool char); | |
13454 | int vec_any_lt (vector unsigned char, vector unsigned char); | |
13455 | int vec_any_lt (vector bool char, vector signed char); | |
13456 | int vec_any_lt (vector signed char, vector bool char); | |
13457 | int vec_any_lt (vector signed char, vector signed char); | |
13458 | int vec_any_lt (vector bool short, vector unsigned short); | |
13459 | int vec_any_lt (vector unsigned short, vector bool short); | |
13460 | int vec_any_lt (vector unsigned short, vector unsigned short); | |
13461 | int vec_any_lt (vector bool short, vector signed short); | |
13462 | int vec_any_lt (vector signed short, vector bool short); | |
13463 | int vec_any_lt (vector signed short, vector signed short); | |
13464 | int vec_any_lt (vector bool int, vector unsigned int); | |
13465 | int vec_any_lt (vector unsigned int, vector bool int); | |
13466 | int vec_any_lt (vector unsigned int, vector unsigned int); | |
13467 | int vec_any_lt (vector bool int, vector signed int); | |
13468 | int vec_any_lt (vector signed int, vector bool int); | |
13469 | int vec_any_lt (vector signed int, vector signed int); | |
13470 | int vec_any_lt (vector float, vector float); | |
13471 | ||
13472 | int vec_any_nan (vector float); | |
13473 | ||
13474 | int vec_any_ne (vector signed char, vector bool char); | |
13475 | int vec_any_ne (vector signed char, vector signed char); | |
13476 | int vec_any_ne (vector unsigned char, vector bool char); | |
13477 | int vec_any_ne (vector unsigned char, vector unsigned char); | |
13478 | int vec_any_ne (vector bool char, vector bool char); | |
13479 | int vec_any_ne (vector bool char, vector unsigned char); | |
13480 | int vec_any_ne (vector bool char, vector signed char); | |
13481 | int vec_any_ne (vector signed short, vector bool short); | |
13482 | int vec_any_ne (vector signed short, vector signed short); | |
13483 | int vec_any_ne (vector unsigned short, vector bool short); | |
13484 | int vec_any_ne (vector unsigned short, vector unsigned short); | |
13485 | int vec_any_ne (vector bool short, vector bool short); | |
13486 | int vec_any_ne (vector bool short, vector unsigned short); | |
13487 | int vec_any_ne (vector bool short, vector signed short); | |
13488 | int vec_any_ne (vector pixel, vector pixel); | |
13489 | int vec_any_ne (vector signed int, vector bool int); | |
13490 | int vec_any_ne (vector signed int, vector signed int); | |
13491 | int vec_any_ne (vector unsigned int, vector bool int); | |
13492 | int vec_any_ne (vector unsigned int, vector unsigned int); | |
13493 | int vec_any_ne (vector bool int, vector bool int); | |
13494 | int vec_any_ne (vector bool int, vector unsigned int); | |
13495 | int vec_any_ne (vector bool int, vector signed int); | |
13496 | int vec_any_ne (vector float, vector float); | |
13497 | ||
13498 | int vec_any_nge (vector float, vector float); | |
13499 | ||
13500 | int vec_any_ngt (vector float, vector float); | |
13501 | ||
13502 | int vec_any_nle (vector float, vector float); | |
13503 | ||
13504 | int vec_any_nlt (vector float, vector float); | |
13505 | ||
13506 | int vec_any_numeric (vector float); | |
13507 | ||
13508 | int vec_any_out (vector float, vector float); | |
0ae4308e | 13509 | @end smallexample |
13510 | ||
32374e3c | 13511 | If the vector/scalar (VSX) instruction set is available, the following |
13512 | additional functions are available: | |
13513 | ||
13514 | @smallexample | |
13515 | vector double vec_abs (vector double); | |
13516 | vector double vec_add (vector double, vector double); | |
13517 | vector double vec_and (vector double, vector double); | |
13518 | vector double vec_and (vector double, vector bool long); | |
13519 | vector double vec_and (vector bool long, vector double); | |
13520 | vector double vec_andc (vector double, vector double); | |
13521 | vector double vec_andc (vector double, vector bool long); | |
13522 | vector double vec_andc (vector bool long, vector double); | |
13523 | vector double vec_ceil (vector double); | |
13524 | vector bool long vec_cmpeq (vector double, vector double); | |
13525 | vector bool long vec_cmpge (vector double, vector double); | |
13526 | vector bool long vec_cmpgt (vector double, vector double); | |
13527 | vector bool long vec_cmple (vector double, vector double); | |
13528 | vector bool long vec_cmplt (vector double, vector double); | |
13529 | vector float vec_div (vector float, vector float); | |
13530 | vector double vec_div (vector double, vector double); | |
13531 | vector double vec_floor (vector double); | |
a501acda | 13532 | vector double vec_ld (int, const vector double *); |
13533 | vector double vec_ld (int, const double *); | |
13534 | vector double vec_ldl (int, const vector double *); | |
13535 | vector double vec_ldl (int, const double *); | |
13536 | vector unsigned char vec_lvsl (int, const volatile double *); | |
13537 | vector unsigned char vec_lvsr (int, const volatile double *); | |
32374e3c | 13538 | vector double vec_madd (vector double, vector double, vector double); |
13539 | vector double vec_max (vector double, vector double); | |
13540 | vector double vec_min (vector double, vector double); | |
13541 | vector float vec_msub (vector float, vector float, vector float); | |
13542 | vector double vec_msub (vector double, vector double, vector double); | |
13543 | vector float vec_mul (vector float, vector float); | |
13544 | vector double vec_mul (vector double, vector double); | |
13545 | vector float vec_nearbyint (vector float); | |
13546 | vector double vec_nearbyint (vector double); | |
13547 | vector float vec_nmadd (vector float, vector float, vector float); | |
13548 | vector double vec_nmadd (vector double, vector double, vector double); | |
13549 | vector double vec_nmsub (vector double, vector double, vector double); | |
13550 | vector double vec_nor (vector double, vector double); | |
13551 | vector double vec_or (vector double, vector double); | |
13552 | vector double vec_or (vector double, vector bool long); | |
13553 | vector double vec_or (vector bool long, vector double); | |
13554 | vector double vec_perm (vector double, | |
13555 | vector double, | |
13556 | vector unsigned char); | |
32374e3c | 13557 | vector double vec_rint (vector double); |
0eac26de | 13558 | vector double vec_recip (vector double, vector double); |
13559 | vector double vec_rsqrt (vector double); | |
13560 | vector double vec_rsqrte (vector double); | |
32374e3c | 13561 | vector double vec_sel (vector double, vector double, vector bool long); |
13562 | vector double vec_sel (vector double, vector double, vector unsigned long); | |
13563 | vector double vec_sub (vector double, vector double); | |
13564 | vector float vec_sqrt (vector float); | |
13565 | vector double vec_sqrt (vector double); | |
a501acda | 13566 | void vec_st (vector double, int, vector double *); |
13567 | void vec_st (vector double, int, double *); | |
32374e3c | 13568 | vector double vec_trunc (vector double); |
13569 | vector double vec_xor (vector double, vector double); | |
13570 | vector double vec_xor (vector double, vector bool long); | |
13571 | vector double vec_xor (vector bool long, vector double); | |
13572 | int vec_all_eq (vector double, vector double); | |
13573 | int vec_all_ge (vector double, vector double); | |
13574 | int vec_all_gt (vector double, vector double); | |
13575 | int vec_all_le (vector double, vector double); | |
13576 | int vec_all_lt (vector double, vector double); | |
13577 | int vec_all_nan (vector double); | |
13578 | int vec_all_ne (vector double, vector double); | |
13579 | int vec_all_nge (vector double, vector double); | |
13580 | int vec_all_ngt (vector double, vector double); | |
13581 | int vec_all_nle (vector double, vector double); | |
13582 | int vec_all_nlt (vector double, vector double); | |
13583 | int vec_all_numeric (vector double); | |
13584 | int vec_any_eq (vector double, vector double); | |
13585 | int vec_any_ge (vector double, vector double); | |
13586 | int vec_any_gt (vector double, vector double); | |
13587 | int vec_any_le (vector double, vector double); | |
13588 | int vec_any_lt (vector double, vector double); | |
13589 | int vec_any_nan (vector double); | |
13590 | int vec_any_ne (vector double, vector double); | |
13591 | int vec_any_nge (vector double, vector double); | |
13592 | int vec_any_ngt (vector double, vector double); | |
13593 | int vec_any_nle (vector double, vector double); | |
13594 | int vec_any_nlt (vector double, vector double); | |
13595 | int vec_any_numeric (vector double); | |
a501acda | 13596 | |
13597 | vector double vec_vsx_ld (int, const vector double *); | |
13598 | vector double vec_vsx_ld (int, const double *); | |
13599 | vector float vec_vsx_ld (int, const vector float *); | |
13600 | vector float vec_vsx_ld (int, const float *); | |
13601 | vector bool int vec_vsx_ld (int, const vector bool int *); | |
13602 | vector signed int vec_vsx_ld (int, const vector signed int *); | |
13603 | vector signed int vec_vsx_ld (int, const int *); | |
13604 | vector signed int vec_vsx_ld (int, const long *); | |
13605 | vector unsigned int vec_vsx_ld (int, const vector unsigned int *); | |
13606 | vector unsigned int vec_vsx_ld (int, const unsigned int *); | |
13607 | vector unsigned int vec_vsx_ld (int, const unsigned long *); | |
13608 | vector bool short vec_vsx_ld (int, const vector bool short *); | |
13609 | vector pixel vec_vsx_ld (int, const vector pixel *); | |
13610 | vector signed short vec_vsx_ld (int, const vector signed short *); | |
13611 | vector signed short vec_vsx_ld (int, const short *); | |
13612 | vector unsigned short vec_vsx_ld (int, const vector unsigned short *); | |
13613 | vector unsigned short vec_vsx_ld (int, const unsigned short *); | |
13614 | vector bool char vec_vsx_ld (int, const vector bool char *); | |
13615 | vector signed char vec_vsx_ld (int, const vector signed char *); | |
13616 | vector signed char vec_vsx_ld (int, const signed char *); | |
13617 | vector unsigned char vec_vsx_ld (int, const vector unsigned char *); | |
13618 | vector unsigned char vec_vsx_ld (int, const unsigned char *); | |
13619 | ||
13620 | void vec_vsx_st (vector double, int, vector double *); | |
13621 | void vec_vsx_st (vector double, int, double *); | |
13622 | void vec_vsx_st (vector float, int, vector float *); | |
13623 | void vec_vsx_st (vector float, int, float *); | |
13624 | void vec_vsx_st (vector signed int, int, vector signed int *); | |
13625 | void vec_vsx_st (vector signed int, int, int *); | |
13626 | void vec_vsx_st (vector unsigned int, int, vector unsigned int *); | |
13627 | void vec_vsx_st (vector unsigned int, int, unsigned int *); | |
13628 | void vec_vsx_st (vector bool int, int, vector bool int *); | |
13629 | void vec_vsx_st (vector bool int, int, unsigned int *); | |
13630 | void vec_vsx_st (vector bool int, int, int *); | |
13631 | void vec_vsx_st (vector signed short, int, vector signed short *); | |
13632 | void vec_vsx_st (vector signed short, int, short *); | |
13633 | void vec_vsx_st (vector unsigned short, int, vector unsigned short *); | |
13634 | void vec_vsx_st (vector unsigned short, int, unsigned short *); | |
13635 | void vec_vsx_st (vector bool short, int, vector bool short *); | |
13636 | void vec_vsx_st (vector bool short, int, unsigned short *); | |
13637 | void vec_vsx_st (vector pixel, int, vector pixel *); | |
13638 | void vec_vsx_st (vector pixel, int, unsigned short *); | |
13639 | void vec_vsx_st (vector pixel, int, short *); | |
13640 | void vec_vsx_st (vector bool short, int, short *); | |
13641 | void vec_vsx_st (vector signed char, int, vector signed char *); | |
13642 | void vec_vsx_st (vector signed char, int, signed char *); | |
13643 | void vec_vsx_st (vector unsigned char, int, vector unsigned char *); | |
13644 | void vec_vsx_st (vector unsigned char, int, unsigned char *); | |
13645 | void vec_vsx_st (vector bool char, int, vector bool char *); | |
13646 | void vec_vsx_st (vector bool char, int, unsigned char *); | |
13647 | void vec_vsx_st (vector bool char, int, signed char *); | |
13648 | @end smallexample | |
13649 | ||
13650 | Note that the @samp{vec_ld} and @samp{vec_st} builtins will always | |
13651 | generate the Altivec @samp{LVX} and @samp{STVX} instructions even | |
13652 | if the VSX instruction set is available. The @samp{vec_vsx_ld} and | |
13653 | @samp{vec_vsx_st} builtins will always generate the VSX @samp{LXVD2X}, | |
13654 | @samp{LXVW4X}, @samp{STXVD2X}, and @samp{STXVW4X} instructions. | |
32374e3c | 13655 | |
13656 | GCC provides a few other builtins on Powerpc to access certain instructions: | |
13657 | @smallexample | |
13658 | float __builtin_recipdivf (float, float); | |
13659 | float __builtin_rsqrtf (float); | |
13660 | double __builtin_recipdiv (double, double); | |
0eac26de | 13661 | double __builtin_rsqrt (double); |
32374e3c | 13662 | long __builtin_bpermd (long, long); |
32374e3c | 13663 | @end smallexample |
13664 | ||
0eac26de | 13665 | The @code{vec_rsqrt}, @code{__builtin_rsqrt}, and |
13666 | @code{__builtin_rsqrtf} functions generate multiple instructions to | |
13667 | implement the reciprocal sqrt functionality using reciprocal sqrt | |
13668 | estimate instructions. | |
13669 | ||
13670 | The @code{__builtin_recipdiv}, and @code{__builtin_recipdivf} | |
13671 | functions generate multiple instructions to implement division using | |
13672 | the reciprocal estimate instructions. | |
13673 | ||
24833e1a | 13674 | @node RX Built-in Functions |
13675 | @subsection RX Built-in Functions | |
13676 | GCC supports some of the RX instructions which cannot be expressed in | |
13677 | the C programming language via the use of built-in functions. The | |
13678 | following functions are supported: | |
13679 | ||
13680 | @deftypefn {Built-in Function} void __builtin_rx_brk (void) | |
13681 | Generates the @code{brk} machine instruction. | |
13682 | @end deftypefn | |
13683 | ||
13684 | @deftypefn {Built-in Function} void __builtin_rx_clrpsw (int) | |
13685 | Generates the @code{clrpsw} machine instruction to clear the specified | |
13686 | bit in the processor status word. | |
13687 | @end deftypefn | |
13688 | ||
13689 | @deftypefn {Built-in Function} void __builtin_rx_int (int) | |
13690 | Generates the @code{int} machine instruction to generate an interrupt | |
13691 | with the specified value. | |
13692 | @end deftypefn | |
13693 | ||
13694 | @deftypefn {Built-in Function} void __builtin_rx_machi (int, int) | |
13695 | Generates the @code{machi} machine instruction to add the result of | |
13696 | multiplying the top 16-bits of the two arguments into the | |
13697 | accumulator. | |
13698 | @end deftypefn | |
13699 | ||
13700 | @deftypefn {Built-in Function} void __builtin_rx_maclo (int, int) | |
13701 | Generates the @code{maclo} machine instruction to add the result of | |
13702 | multiplying the bottom 16-bits of the two arguments into the | |
13703 | accumulator. | |
13704 | @end deftypefn | |
13705 | ||
13706 | @deftypefn {Built-in Function} void __builtin_rx_mulhi (int, int) | |
13707 | Generates the @code{mulhi} machine instruction to place the result of | |
13708 | multiplying the top 16-bits of the two arguments into the | |
13709 | accumulator. | |
13710 | @end deftypefn | |
13711 | ||
13712 | @deftypefn {Built-in Function} void __builtin_rx_mullo (int, int) | |
13713 | Generates the @code{mullo} machine instruction to place the result of | |
13714 | multiplying the bottom 16-bits of the two arguments into the | |
13715 | accumulator. | |
13716 | @end deftypefn | |
13717 | ||
13718 | @deftypefn {Built-in Function} int __builtin_rx_mvfachi (void) | |
13719 | Generates the @code{mvfachi} machine instruction to read the top | |
13720 | 32-bits of the accumulator. | |
13721 | @end deftypefn | |
13722 | ||
13723 | @deftypefn {Built-in Function} int __builtin_rx_mvfacmi (void) | |
13724 | Generates the @code{mvfacmi} machine instruction to read the middle | |
13725 | 32-bits of the accumulator. | |
13726 | @end deftypefn | |
13727 | ||
13728 | @deftypefn {Built-in Function} int __builtin_rx_mvfc (int) | |
13729 | Generates the @code{mvfc} machine instruction which reads the control | |
13730 | register specified in its argument and returns its value. | |
13731 | @end deftypefn | |
13732 | ||
13733 | @deftypefn {Built-in Function} void __builtin_rx_mvtachi (int) | |
13734 | Generates the @code{mvtachi} machine instruction to set the top | |
13735 | 32-bits of the accumulator. | |
13736 | @end deftypefn | |
13737 | ||
13738 | @deftypefn {Built-in Function} void __builtin_rx_mvtaclo (int) | |
13739 | Generates the @code{mvtaclo} machine instruction to set the bottom | |
13740 | 32-bits of the accumulator. | |
13741 | @end deftypefn | |
13742 | ||
13743 | @deftypefn {Built-in Function} void __builtin_rx_mvtc (int reg, int val) | |
13744 | Generates the @code{mvtc} machine instruction which sets control | |
13745 | register number @code{reg} to @code{val}. | |
13746 | @end deftypefn | |
13747 | ||
13748 | @deftypefn {Built-in Function} void __builtin_rx_mvtipl (int) | |
13749 | Generates the @code{mvtipl} machine instruction set the interrupt | |
13750 | priority level. | |
13751 | @end deftypefn | |
13752 | ||
13753 | @deftypefn {Built-in Function} void __builtin_rx_racw (int) | |
13754 | Generates the @code{racw} machine instruction to round the accumulator | |
13755 | according to the specified mode. | |
13756 | @end deftypefn | |
13757 | ||
13758 | @deftypefn {Built-in Function} int __builtin_rx_revw (int) | |
13759 | Generates the @code{revw} machine instruction which swaps the bytes in | |
13760 | the argument so that bits 0--7 now occupy bits 8--15 and vice versa, | |
13761 | and also bits 16--23 occupy bits 24--31 and vice versa. | |
13762 | @end deftypefn | |
13763 | ||
13764 | @deftypefn {Built-in Function} void __builtin_rx_rmpa (void) | |
13765 | Generates the @code{rmpa} machine instruction which initiates a | |
13766 | repeated multiply and accumulate sequence. | |
13767 | @end deftypefn | |
13768 | ||
13769 | @deftypefn {Built-in Function} void __builtin_rx_round (float) | |
13770 | Generates the @code{round} machine instruction which returns the | |
13771 | floating point argument rounded according to the current rounding mode | |
13772 | set in the floating point status word register. | |
13773 | @end deftypefn | |
13774 | ||
13775 | @deftypefn {Built-in Function} int __builtin_rx_sat (int) | |
13776 | Generates the @code{sat} machine instruction which returns the | |
13777 | saturated value of the argument. | |
13778 | @end deftypefn | |
13779 | ||
13780 | @deftypefn {Built-in Function} void __builtin_rx_setpsw (int) | |
13781 | Generates the @code{setpsw} machine instruction to set the specified | |
13782 | bit in the processor status word. | |
13783 | @end deftypefn | |
13784 | ||
13785 | @deftypefn {Built-in Function} void __builtin_rx_wait (void) | |
13786 | Generates the @code{wait} machine instruction. | |
13787 | @end deftypefn | |
13788 | ||
88fb6217 | 13789 | @node SPARC VIS Built-in Functions |
13790 | @subsection SPARC VIS Built-in Functions | |
13791 | ||
13792 | GCC supports SIMD operations on the SPARC using both the generic vector | |
1b5d7d3d | 13793 | extensions (@pxref{Vector Extensions}) as well as built-in functions for |
88fb6217 | 13794 | the SPARC Visual Instruction Set (VIS). When you use the @option{-mvis} |
13795 | switch, the VIS extension is exposed as the following built-in functions: | |
13796 | ||
13797 | @smallexample | |
e39e0668 | 13798 | typedef int v1si __attribute__ ((vector_size (4))); |
88fb6217 | 13799 | typedef int v2si __attribute__ ((vector_size (8))); |
13800 | typedef short v4hi __attribute__ ((vector_size (8))); | |
13801 | typedef short v2hi __attribute__ ((vector_size (4))); | |
4e3a6159 | 13802 | typedef unsigned char v8qi __attribute__ ((vector_size (8))); |
13803 | typedef unsigned char v4qi __attribute__ ((vector_size (4))); | |
88fb6217 | 13804 | |
b011bbe2 | 13805 | void __builtin_vis_write_gsr (int64_t); |
13806 | int64_t __builtin_vis_read_gsr (void); | |
13807 | ||
88fb6217 | 13808 | void * __builtin_vis_alignaddr (void *, long); |
4e3a6159 | 13809 | void * __builtin_vis_alignaddrl (void *, long); |
88fb6217 | 13810 | int64_t __builtin_vis_faligndatadi (int64_t, int64_t); |
13811 | v2si __builtin_vis_faligndatav2si (v2si, v2si); | |
13812 | v4hi __builtin_vis_faligndatav4hi (v4si, v4si); | |
13813 | v8qi __builtin_vis_faligndatav8qi (v8qi, v8qi); | |
13814 | ||
13815 | v4hi __builtin_vis_fexpand (v4qi); | |
13816 | ||
13817 | v4hi __builtin_vis_fmul8x16 (v4qi, v4hi); | |
4e3a6159 | 13818 | v4hi __builtin_vis_fmul8x16au (v4qi, v2hi); |
13819 | v4hi __builtin_vis_fmul8x16al (v4qi, v2hi); | |
88fb6217 | 13820 | v4hi __builtin_vis_fmul8sux16 (v8qi, v4hi); |
13821 | v4hi __builtin_vis_fmul8ulx16 (v8qi, v4hi); | |
13822 | v2si __builtin_vis_fmuld8sux16 (v4qi, v2hi); | |
13823 | v2si __builtin_vis_fmuld8ulx16 (v4qi, v2hi); | |
13824 | ||
13825 | v4qi __builtin_vis_fpack16 (v4hi); | |
4e3a6159 | 13826 | v8qi __builtin_vis_fpack32 (v2si, v8qi); |
88fb6217 | 13827 | v2hi __builtin_vis_fpackfix (v2si); |
13828 | v8qi __builtin_vis_fpmerge (v4qi, v4qi); | |
13829 | ||
13830 | int64_t __builtin_vis_pdist (v8qi, v8qi, int64_t); | |
010db245 | 13831 | |
faa087bb | 13832 | long __builtin_vis_edge8 (void *, void *); |
13833 | long __builtin_vis_edge8l (void *, void *); | |
13834 | long __builtin_vis_edge16 (void *, void *); | |
13835 | long __builtin_vis_edge16l (void *, void *); | |
13836 | long __builtin_vis_edge32 (void *, void *); | |
13837 | long __builtin_vis_edge32l (void *, void *); | |
13838 | ||
13839 | long __builtin_vis_fcmple16 (v4hi, v4hi); | |
13840 | long __builtin_vis_fcmple32 (v2si, v2si); | |
13841 | long __builtin_vis_fcmpne16 (v4hi, v4hi); | |
13842 | long __builtin_vis_fcmpne32 (v2si, v2si); | |
13843 | long __builtin_vis_fcmpgt16 (v4hi, v4hi); | |
13844 | long __builtin_vis_fcmpgt32 (v2si, v2si); | |
13845 | long __builtin_vis_fcmpeq16 (v4hi, v4hi); | |
13846 | long __builtin_vis_fcmpeq32 (v2si, v2si); | |
e39e0668 | 13847 | |
13848 | v4hi __builtin_vis_fpadd16 (v4hi, v4hi); | |
13849 | v2hi __builtin_vis_fpadd16s (v2hi, v2hi); | |
13850 | v2si __builtin_vis_fpadd32 (v2si, v2si); | |
13851 | v1si __builtin_vis_fpadd32s (v1si, v1si); | |
13852 | v4hi __builtin_vis_fpsub16 (v4hi, v4hi); | |
13853 | v2hi __builtin_vis_fpsub16s (v2hi, v2hi); | |
13854 | v2si __builtin_vis_fpsub32 (v2si, v2si); | |
13855 | v1si __builtin_vis_fpsub32s (v1si, v1si); | |
386d043d | 13856 | |
13857 | long __builtin_vis_array8 (long, long); | |
13858 | long __builtin_vis_array16 (long, long); | |
13859 | long __builtin_vis_array32 (long, long); | |
88fb6217 | 13860 | @end smallexample |
13861 | ||
33e7b55c | 13862 | When you use the @option{-mvis2} switch, the VIS version 2.0 built-in |
13863 | functions also become available: | |
95c09f2c | 13864 | |
13865 | @smallexample | |
13866 | long __builtin_vis_bmask (long, long); | |
13867 | int64_t __builtin_vis_bshuffledi (int64_t, int64_t); | |
13868 | v2si __builtin_vis_bshufflev2si (v2si, v2si); | |
13869 | v4hi __builtin_vis_bshufflev2si (v4hi, v4hi); | |
13870 | v8qi __builtin_vis_bshufflev2si (v8qi, v8qi); | |
13871 | ||
13872 | long __builtin_vis_edge8n (void *, void *); | |
13873 | long __builtin_vis_edge8ln (void *, void *); | |
13874 | long __builtin_vis_edge16n (void *, void *); | |
13875 | long __builtin_vis_edge16ln (void *, void *); | |
13876 | long __builtin_vis_edge32n (void *, void *); | |
13877 | long __builtin_vis_edge32ln (void *, void *); | |
13878 | @end smallexample | |
13879 | ||
33e7b55c | 13880 | When you use the @option{-mvis3} switch, the VIS version 3.0 built-in |
13881 | functions also become available: | |
13882 | ||
13883 | @smallexample | |
13884 | void __builtin_vis_cmask8 (long); | |
13885 | void __builtin_vis_cmask16 (long); | |
13886 | void __builtin_vis_cmask32 (long); | |
13887 | ||
13888 | v4hi __builtin_vis_fchksm16 (v4hi, v4hi); | |
13889 | ||
13890 | v4hi __builtin_vis_fsll16 (v4hi, v4hi); | |
13891 | v4hi __builtin_vis_fslas16 (v4hi, v4hi); | |
13892 | v4hi __builtin_vis_fsrl16 (v4hi, v4hi); | |
13893 | v4hi __builtin_vis_fsra16 (v4hi, v4hi); | |
13894 | v2si __builtin_vis_fsll16 (v2si, v2si); | |
13895 | v2si __builtin_vis_fslas16 (v2si, v2si); | |
13896 | v2si __builtin_vis_fsrl16 (v2si, v2si); | |
13897 | v2si __builtin_vis_fsra16 (v2si, v2si); | |
13898 | ||
13899 | long __builtin_vis_pdistn (v8qi, v8qi); | |
13900 | ||
13901 | v4hi __builtin_vis_fmean16 (v4hi, v4hi); | |
13902 | ||
13903 | int64_t __builtin_vis_fpadd64 (int64_t, int64_t); | |
13904 | int64_t __builtin_vis_fpsub64 (int64_t, int64_t); | |
13905 | ||
13906 | v4hi __builtin_vis_fpadds16 (v4hi, v4hi); | |
13907 | v2hi __builtin_vis_fpadds16s (v2hi, v2hi); | |
13908 | v4hi __builtin_vis_fpsubs16 (v4hi, v4hi); | |
13909 | v2hi __builtin_vis_fpsubs16s (v2hi, v2hi); | |
13910 | v2si __builtin_vis_fpadds32 (v2si, v2si); | |
13911 | v1si __builtin_vis_fpadds32s (v1si, v1si); | |
13912 | v2si __builtin_vis_fpsubs32 (v2si, v2si); | |
13913 | v1si __builtin_vis_fpsubs32s (v1si, v1si); | |
13914 | ||
13915 | long __builtin_vis_fucmple8 (v8qi, v8qi); | |
13916 | long __builtin_vis_fucmpne8 (v8qi, v8qi); | |
13917 | long __builtin_vis_fucmpgt8 (v8qi, v8qi); | |
13918 | long __builtin_vis_fucmpeq8 (v8qi, v8qi); | |
47cc4525 | 13919 | |
13920 | float __builtin_vis_fhadds (float, float); | |
13921 | double __builtin_vis_fhaddd (double, double); | |
13922 | float __builtin_vis_fhsubs (float, float); | |
13923 | double __builtin_vis_fhsubd (double, double); | |
13924 | float __builtin_vis_fnhadds (float, float); | |
13925 | double __builtin_vis_fnhaddd (double, double); | |
13926 | ||
13927 | int64_t __builtin_vis_umulxhi (int64_t, int64_t); | |
13928 | int64_t __builtin_vis_xmulx (int64_t, int64_t); | |
13929 | int64_t __builtin_vis_xmulxhi (int64_t, int64_t); | |
33e7b55c | 13930 | @end smallexample |
13931 | ||
644459d0 | 13932 | @node SPU Built-in Functions |
13933 | @subsection SPU Built-in Functions | |
13934 | ||
13935 | GCC provides extensions for the SPU processor as described in the | |
13936 | Sony/Toshiba/IBM SPU Language Extensions Specification, which can be | |
13937 | found at @uref{http://cell.scei.co.jp/} or | |
13938 | @uref{http://www.ibm.com/developerworks/power/cell/}. GCC's | |
13939 | implementation differs in several ways. | |
13940 | ||
13941 | @itemize @bullet | |
13942 | ||
13943 | @item | |
13944 | The optional extension of specifying vector constants in parentheses is | |
13945 | not supported. | |
13946 | ||
13947 | @item | |
13948 | A vector initializer requires no cast if the vector constant is of the | |
13949 | same type as the variable it is initializing. | |
13950 | ||
13951 | @item | |
13952 | If @code{signed} or @code{unsigned} is omitted, the signedness of the | |
13953 | vector type is the default signedness of the base type. The default | |
13954 | varies depending on the operating system, so a portable program should | |
13955 | always specify the signedness. | |
13956 | ||
13957 | @item | |
13958 | By default, the keyword @code{__vector} is added. The macro | |
13959 | @code{vector} is defined in @code{<spu_intrinsics.h>} and can be | |
13960 | undefined. | |
13961 | ||
13962 | @item | |
13963 | GCC allows using a @code{typedef} name as the type specifier for a | |
13964 | vector type. | |
13965 | ||
13966 | @item | |
13967 | For C, overloaded functions are implemented with macros so the following | |
13968 | does not work: | |
13969 | ||
13970 | @smallexample | |
13971 | spu_add ((vector signed int)@{1, 2, 3, 4@}, foo); | |
13972 | @end smallexample | |
13973 | ||
13974 | Since @code{spu_add} is a macro, the vector constant in the example | |
13975 | is treated as four separate arguments. Wrap the entire argument in | |
13976 | parentheses for this to work. | |
13977 | ||
13978 | @item | |
13979 | The extended version of @code{__builtin_expect} is not supported. | |
13980 | ||
13981 | @end itemize | |
13982 | ||
b5fb9cbe | 13983 | @emph{Note:} Only the interface described in the aforementioned |
644459d0 | 13984 | specification is supported. Internally, GCC uses built-in functions to |
13985 | implement the required functionality, but these are not supported and | |
13986 | are subject to change without notice. | |
13987 | ||
5aa04b01 | 13988 | @node TI C6X Built-in Functions |
13989 | @subsection TI C6X Built-in Functions | |
13990 | ||
13991 | GCC provides intrinsics to access certain instructions of the TI C6X | |
13992 | processors. These intrinsics, listed below, are available after | |
13993 | inclusion of the @code{c6x_intrinsics.h} header file. They map directly | |
13994 | to C6X instructions. | |
13995 | ||
13996 | @smallexample | |
13997 | ||
13998 | int _sadd (int, int) | |
13999 | int _ssub (int, int) | |
14000 | int _sadd2 (int, int) | |
14001 | int _ssub2 (int, int) | |
14002 | long long _mpy2 (int, int) | |
14003 | long long _smpy2 (int, int) | |
14004 | int _add4 (int, int) | |
14005 | int _sub4 (int, int) | |
14006 | int _saddu4 (int, int) | |
14007 | ||
14008 | int _smpy (int, int) | |
14009 | int _smpyh (int, int) | |
14010 | int _smpyhl (int, int) | |
14011 | int _smpylh (int, int) | |
14012 | ||
14013 | int _sshl (int, int) | |
14014 | int _subc (int, int) | |
14015 | ||
14016 | int _avg2 (int, int) | |
14017 | int _avgu4 (int, int) | |
14018 | ||
14019 | int _clrr (int, int) | |
14020 | int _extr (int, int) | |
14021 | int _extru (int, int) | |
14022 | int _abs (int) | |
14023 | int _abs2 (int) | |
14024 | ||
14025 | @end smallexample | |
14026 | ||
7ce78e23 | 14027 | @node TILE-Gx Built-in Functions |
14028 | @subsection TILE-Gx Built-in Functions | |
14029 | ||
14030 | GCC provides intrinsics to access every instruction of the TILE-Gx | |
14031 | processor. The intrinsics are of the form: | |
14032 | ||
14033 | @smallexample | |
14034 | ||
14035 | unsigned long long __insn_@var{op} (...) | |
14036 | ||
14037 | @end smallexample | |
14038 | ||
14039 | Where @var{op} is the name of the instruction. Refer to the ISA manual | |
14040 | for the complete list of instructions. | |
14041 | ||
14042 | GCC also provides intrinsics to directly access the network registers. | |
14043 | The intrinsics are: | |
14044 | ||
14045 | @smallexample | |
14046 | ||
14047 | unsigned long long __tile_idn0_receive (void) | |
14048 | unsigned long long __tile_idn1_receive (void) | |
14049 | unsigned long long __tile_udn0_receive (void) | |
14050 | unsigned long long __tile_udn1_receive (void) | |
14051 | unsigned long long __tile_udn2_receive (void) | |
14052 | unsigned long long __tile_udn3_receive (void) | |
14053 | void __tile_idn_send (unsigned long long) | |
14054 | void __tile_udn_send (unsigned long long) | |
14055 | ||
14056 | @end smallexample | |
14057 | ||
14058 | The intrinsic @code{void __tile_network_barrier (void)} is used to | |
14059 | guarantee that no network operatons before it will be reordered with | |
14060 | those after it. | |
14061 | ||
14062 | @node TILEPro Built-in Functions | |
14063 | @subsection TILEPro Built-in Functions | |
14064 | ||
14065 | GCC provides intrinsics to access every instruction of the TILEPro | |
14066 | processor. The intrinsics are of the form: | |
14067 | ||
14068 | @smallexample | |
14069 | ||
14070 | unsigned __insn_@var{op} (...) | |
14071 | ||
14072 | @end smallexample | |
14073 | ||
14074 | Where @var{op} is the name of the instruction. Refer to the ISA manual | |
14075 | for the complete list of instructions. | |
14076 | ||
14077 | GCC also provides intrinsics to directly access the network registers. | |
14078 | The intrinsics are: | |
14079 | ||
14080 | @smallexample | |
14081 | ||
14082 | unsigned __tile_idn0_receive (void) | |
14083 | unsigned __tile_idn1_receive (void) | |
14084 | unsigned __tile_sn_receive (void) | |
14085 | unsigned __tile_udn0_receive (void) | |
14086 | unsigned __tile_udn1_receive (void) | |
14087 | unsigned __tile_udn2_receive (void) | |
14088 | unsigned __tile_udn3_receive (void) | |
14089 | void __tile_idn_send (unsigned) | |
14090 | void __tile_sn_send (unsigned) | |
14091 | void __tile_udn_send (unsigned) | |
14092 | ||
14093 | @end smallexample | |
14094 | ||
14095 | The intrinsic @code{void __tile_network_barrier (void)} is used to | |
14096 | guarantee that no network operatons before it will be reordered with | |
14097 | those after it. | |
14098 | ||
1e9af880 | 14099 | @node Target Format Checks |
14100 | @section Format Checks Specific to Particular Target Machines | |
14101 | ||
14102 | For some target machines, GCC supports additional options to the | |
14103 | format attribute | |
14104 | (@pxref{Function Attributes,,Declaring Attributes of Functions}). | |
14105 | ||
14106 | @menu | |
14107 | * Solaris Format Checks:: | |
1f6616ee | 14108 | * Darwin Format Checks:: |
1e9af880 | 14109 | @end menu |
14110 | ||
14111 | @node Solaris Format Checks | |
14112 | @subsection Solaris Format Checks | |
14113 | ||
14114 | Solaris targets support the @code{cmn_err} (or @code{__cmn_err__}) format | |
14115 | check. @code{cmn_err} accepts a subset of the standard @code{printf} | |
14116 | conversions, and the two-argument @code{%b} conversion for displaying | |
14117 | bit-fields. See the Solaris man page for @code{cmn_err} for more information. | |
14118 | ||
1f6616ee | 14119 | @node Darwin Format Checks |
14120 | @subsection Darwin Format Checks | |
14121 | ||
15b474a2 | 14122 | Darwin targets support the @code{CFString} (or @code{__CFString__}) in the format |
1f6616ee | 14123 | attribute context. Declarations made with such attribution will be parsed for correct syntax |
14124 | and format argument types. However, parsing of the format string itself is currently undefined | |
15b474a2 | 14125 | and will not be carried out by this version of the compiler. |
1f6616ee | 14126 | |
14127 | Additionally, @code{CFStringRefs} (defined by the @code{CoreFoundation} headers) may | |
14128 | also be used as format arguments. Note that the relevant headers are only likely to be | |
14129 | available on Darwin (OSX) installations. On such installations, the XCode and system | |
14130 | documentation provide descriptions of @code{CFString}, @code{CFStringRefs} and | |
14131 | associated functions. | |
14132 | ||
49f45d83 | 14133 | @node Pragmas |
14134 | @section Pragmas Accepted by GCC | |
14135 | @cindex pragmas | |
12786727 | 14136 | @cindex @code{#pragma} |
49f45d83 | 14137 | |
14138 | GCC supports several types of pragmas, primarily in order to compile | |
14139 | code originally written for other compilers. Note that in general | |
14140 | we do not recommend the use of pragmas; @xref{Function Attributes}, | |
14141 | for further explanation. | |
14142 | ||
14143 | @menu | |
14144 | * ARM Pragmas:: | |
85c84d5c | 14145 | * M32C Pragmas:: |
7c3116fb | 14146 | * MeP Pragmas:: |
edd2f2ae | 14147 | * RS/6000 and PowerPC Pragmas:: |
49f45d83 | 14148 | * Darwin Pragmas:: |
e02a1225 | 14149 | * Solaris Pragmas:: |
146c1b4f | 14150 | * Symbol-Renaming Pragmas:: |
6b5553e5 | 14151 | * Structure-Packing Pragmas:: |
b60f73dc | 14152 | * Weak Pragmas:: |
76f02516 | 14153 | * Diagnostic Pragmas:: |
4a2849cb | 14154 | * Visibility Pragmas:: |
ebba2dc7 | 14155 | * Push/Pop Macro Pragmas:: |
46f8e3b0 | 14156 | * Function Specific Option Pragmas:: |
49f45d83 | 14157 | @end menu |
14158 | ||
14159 | @node ARM Pragmas | |
14160 | @subsection ARM Pragmas | |
14161 | ||
14162 | The ARM target defines pragmas for controlling the default addition of | |
14163 | @code{long_call} and @code{short_call} attributes to functions. | |
14164 | @xref{Function Attributes}, for information about the effects of these | |
14165 | attributes. | |
14166 | ||
14167 | @table @code | |
14168 | @item long_calls | |
14169 | @cindex pragma, long_calls | |
14170 | Set all subsequent functions to have the @code{long_call} attribute. | |
14171 | ||
14172 | @item no_long_calls | |
14173 | @cindex pragma, no_long_calls | |
14174 | Set all subsequent functions to have the @code{short_call} attribute. | |
14175 | ||
14176 | @item long_calls_off | |
14177 | @cindex pragma, long_calls_off | |
14178 | Do not affect the @code{long_call} or @code{short_call} attributes of | |
14179 | subsequent functions. | |
14180 | @end table | |
14181 | ||
85c84d5c | 14182 | @node M32C Pragmas |
14183 | @subsection M32C Pragmas | |
14184 | ||
14185 | @table @code | |
e3d4e41e | 14186 | @item GCC memregs @var{number} |
85c84d5c | 14187 | @cindex pragma, memregs |
bfe513a4 | 14188 | Overrides the command-line option @code{-memregs=} for the current |
85c84d5c | 14189 | file. Use with care! This pragma must be before any function in the |
14190 | file, and mixing different memregs values in different objects may | |
14191 | make them incompatible. This pragma is useful when a | |
14192 | performance-critical function uses a memreg for temporary values, | |
14193 | as it may allow you to reduce the number of memregs used. | |
14194 | ||
e3d4e41e | 14195 | @item ADDRESS @var{name} @var{address} |
14196 | @cindex pragma, address | |
14197 | For any declared symbols matching @var{name}, this does three things | |
14198 | to that symbol: it forces the symbol to be located at the given | |
14199 | address (a number), it forces the symbol to be volatile, and it | |
14200 | changes the symbol's scope to be static. This pragma exists for | |
14201 | compatibility with other compilers, but note that the common | |
14202 | @code{1234H} numeric syntax is not supported (use @code{0x1234} | |
14203 | instead). Example: | |
14204 | ||
14205 | @example | |
14206 | #pragma ADDRESS port3 0x103 | |
14207 | char port3; | |
14208 | @end example | |
14209 | ||
85c84d5c | 14210 | @end table |
14211 | ||
7c3116fb | 14212 | @node MeP Pragmas |
14213 | @subsection MeP Pragmas | |
14214 | ||
14215 | @table @code | |
14216 | ||
14217 | @item custom io_volatile (on|off) | |
14218 | @cindex pragma, custom io_volatile | |
14219 | Overrides the command line option @code{-mio-volatile} for the current | |
14220 | file. Note that for compatibility with future GCC releases, this | |
14221 | option should only be used once before any @code{io} variables in each | |
14222 | file. | |
14223 | ||
14224 | @item GCC coprocessor available @var{registers} | |
14225 | @cindex pragma, coprocessor available | |
14226 | Specifies which coprocessor registers are available to the register | |
14227 | allocator. @var{registers} may be a single register, register range | |
14228 | separated by ellipses, or comma-separated list of those. Example: | |
14229 | ||
14230 | @example | |
14231 | #pragma GCC coprocessor available $c0...$c10, $c28 | |
14232 | @end example | |
14233 | ||
14234 | @item GCC coprocessor call_saved @var{registers} | |
14235 | @cindex pragma, coprocessor call_saved | |
14236 | Specifies which coprocessor registers are to be saved and restored by | |
14237 | any function using them. @var{registers} may be a single register, | |
14238 | register range separated by ellipses, or comma-separated list of | |
14239 | those. Example: | |
14240 | ||
14241 | @example | |
14242 | #pragma GCC coprocessor call_saved $c4...$c6, $c31 | |
14243 | @end example | |
14244 | ||
14245 | @item GCC coprocessor subclass '(A|B|C|D)' = @var{registers} | |
14246 | @cindex pragma, coprocessor subclass | |
14247 | Creates and defines a register class. These register classes can be | |
14248 | used by inline @code{asm} constructs. @var{registers} may be a single | |
14249 | register, register range separated by ellipses, or comma-separated | |
14250 | list of those. Example: | |
14251 | ||
14252 | @example | |
14253 | #pragma GCC coprocessor subclass 'B' = $c2, $c4, $c6 | |
14254 | ||
14255 | asm ("cpfoo %0" : "=B" (x)); | |
14256 | @end example | |
14257 | ||
14258 | @item GCC disinterrupt @var{name} , @var{name} @dots{} | |
14259 | @cindex pragma, disinterrupt | |
14260 | For the named functions, the compiler adds code to disable interrupts | |
14261 | for the duration of those functions. Any functions so named, which | |
14262 | are not encountered in the source, cause a warning that the pragma was | |
14263 | not used. Examples: | |
14264 | ||
14265 | @example | |
14266 | #pragma disinterrupt foo | |
14267 | #pragma disinterrupt bar, grill | |
58c0b97e | 14268 | int foo () @{ @dots{} @} |
7c3116fb | 14269 | @end example |
14270 | ||
14271 | @item GCC call @var{name} , @var{name} @dots{} | |
14272 | @cindex pragma, call | |
14273 | For the named functions, the compiler always uses a register-indirect | |
14274 | call model when calling the named functions. Examples: | |
14275 | ||
14276 | @example | |
14277 | extern int foo (); | |
14278 | #pragma call foo | |
14279 | @end example | |
14280 | ||
14281 | @end table | |
14282 | ||
edd2f2ae | 14283 | @node RS/6000 and PowerPC Pragmas |
14284 | @subsection RS/6000 and PowerPC Pragmas | |
14285 | ||
14286 | The RS/6000 and PowerPC targets define one pragma for controlling | |
14287 | whether or not the @code{longcall} attribute is added to function | |
14288 | declarations by default. This pragma overrides the @option{-mlongcall} | |
85456819 | 14289 | option, but not the @code{longcall} and @code{shortcall} attributes. |
edd2f2ae | 14290 | @xref{RS/6000 and PowerPC Options}, for more information about when long |
14291 | calls are and are not necessary. | |
14292 | ||
14293 | @table @code | |
14294 | @item longcall (1) | |
14295 | @cindex pragma, longcall | |
14296 | Apply the @code{longcall} attribute to all subsequent function | |
14297 | declarations. | |
14298 | ||
14299 | @item longcall (0) | |
14300 | Do not apply the @code{longcall} attribute to subsequent function | |
14301 | declarations. | |
14302 | @end table | |
14303 | ||
49f45d83 | 14304 | @c Describe h8300 pragmas here. |
49f45d83 | 14305 | @c Describe sh pragmas here. |
14306 | @c Describe v850 pragmas here. | |
14307 | ||
14308 | @node Darwin Pragmas | |
14309 | @subsection Darwin Pragmas | |
14310 | ||
14311 | The following pragmas are available for all architectures running the | |
14312 | Darwin operating system. These are useful for compatibility with other | |
1c95bb8d | 14313 | Mac OS compilers. |
49f45d83 | 14314 | |
14315 | @table @code | |
14316 | @item mark @var{tokens}@dots{} | |
14317 | @cindex pragma, mark | |
14318 | This pragma is accepted, but has no effect. | |
14319 | ||
14320 | @item options align=@var{alignment} | |
14321 | @cindex pragma, options align | |
14322 | This pragma sets the alignment of fields in structures. The values of | |
14323 | @var{alignment} may be @code{mac68k}, to emulate m68k alignment, or | |
14324 | @code{power}, to emulate PowerPC alignment. Uses of this pragma nest | |
14325 | properly; to restore the previous setting, use @code{reset} for the | |
14326 | @var{alignment}. | |
14327 | ||
14328 | @item segment @var{tokens}@dots{} | |
14329 | @cindex pragma, segment | |
14330 | This pragma is accepted, but has no effect. | |
14331 | ||
14332 | @item unused (@var{var} [, @var{var}]@dots{}) | |
14333 | @cindex pragma, unused | |
14334 | This pragma declares variables to be possibly unused. GCC will not | |
14335 | produce warnings for the listed variables. The effect is similar to | |
14336 | that of the @code{unused} attribute, except that this pragma may appear | |
14337 | anywhere within the variables' scopes. | |
14338 | @end table | |
14339 | ||
e02a1225 | 14340 | @node Solaris Pragmas |
14341 | @subsection Solaris Pragmas | |
14342 | ||
14343 | The Solaris target supports @code{#pragma redefine_extname} | |
14344 | (@pxref{Symbol-Renaming Pragmas}). It also supports additional | |
14345 | @code{#pragma} directives for compatibility with the system compiler. | |
14346 | ||
14347 | @table @code | |
14348 | @item align @var{alignment} (@var{variable} [, @var{variable}]...) | |
14349 | @cindex pragma, align | |
14350 | ||
14351 | Increase the minimum alignment of each @var{variable} to @var{alignment}. | |
14352 | This is the same as GCC's @code{aligned} attribute @pxref{Variable | |
68bf2ad9 | 14353 | Attributes}). Macro expansion occurs on the arguments to this pragma |
a81d4cba | 14354 | when compiling C and Objective-C@. It does not currently occur when |
68bf2ad9 | 14355 | compiling C++, but this is a bug which may be fixed in a future |
14356 | release. | |
e02a1225 | 14357 | |
14358 | @item fini (@var{function} [, @var{function}]...) | |
14359 | @cindex pragma, fini | |
14360 | ||
14361 | This pragma causes each listed @var{function} to be called after | |
14362 | main, or during shared module unloading, by adding a call to the | |
14363 | @code{.fini} section. | |
14364 | ||
14365 | @item init (@var{function} [, @var{function}]...) | |
14366 | @cindex pragma, init | |
14367 | ||
14368 | This pragma causes each listed @var{function} to be called during | |
14369 | initialization (before @code{main}) or during shared module loading, by | |
14370 | adding a call to the @code{.init} section. | |
14371 | ||
14372 | @end table | |
14373 | ||
146c1b4f | 14374 | @node Symbol-Renaming Pragmas |
14375 | @subsection Symbol-Renaming Pragmas | |
ea42c4de | 14376 | |
126b6848 | 14377 | For compatibility with the Solaris system headers, GCC |
146c1b4f | 14378 | supports two @code{#pragma} directives which change the name used in |
126b6848 | 14379 | assembly for a given declaration. To get this effect |
7f68f564 | 14380 | on all platforms supported by GCC, use the asm labels extension (@pxref{Asm |
146c1b4f | 14381 | Labels}). |
ea42c4de | 14382 | |
14383 | @table @code | |
14384 | @item redefine_extname @var{oldname} @var{newname} | |
14385 | @cindex pragma, redefine_extname | |
14386 | ||
146c1b4f | 14387 | This pragma gives the C function @var{oldname} the assembly symbol |
14388 | @var{newname}. The preprocessor macro @code{__PRAGMA_REDEFINE_EXTNAME} | |
7f68f564 | 14389 | will be defined if this pragma is available (currently on all platforms). |
ea42c4de | 14390 | @end table |
14391 | ||
126b6848 | 14392 | This pragma and the asm labels extension interact in a complicated |
146c1b4f | 14393 | manner. Here are some corner cases you may want to be aware of. |
14394 | ||
14395 | @enumerate | |
14396 | @item Both pragmas silently apply only to declarations with external | |
14397 | linkage. Asm labels do not have this restriction. | |
14398 | ||
14399 | @item In C++, both pragmas silently apply only to declarations with | |
14400 | ``C'' linkage. Again, asm labels do not have this restriction. | |
14401 | ||
14402 | @item If any of the three ways of changing the assembly name of a | |
14403 | declaration is applied to a declaration whose assembly name has | |
14404 | already been determined (either by a previous use of one of these | |
14405 | features, or because the compiler needed the assembly name in order to | |
14406 | generate code), and the new name is different, a warning issues and | |
14407 | the name does not change. | |
14408 | ||
14409 | @item The @var{oldname} used by @code{#pragma redefine_extname} is | |
14410 | always the C-language name. | |
146c1b4f | 14411 | @end enumerate |
14412 | ||
6b5553e5 | 14413 | @node Structure-Packing Pragmas |
14414 | @subsection Structure-Packing Pragmas | |
14415 | ||
ebba2dc7 | 14416 | For compatibility with Microsoft Windows compilers, GCC supports a |
14417 | set of @code{#pragma} directives which change the maximum alignment of | |
14418 | members of structures (other than zero-width bitfields), unions, and | |
14419 | classes subsequently defined. The @var{n} value below always is required | |
14420 | to be a small power of two and specifies the new alignment in bytes. | |
6b5553e5 | 14421 | |
14422 | @enumerate | |
14423 | @item @code{#pragma pack(@var{n})} simply sets the new alignment. | |
14424 | @item @code{#pragma pack()} sets the alignment to the one that was in | |
bfe513a4 | 14425 | effect when compilation started (see also command-line option |
c23d8da9 | 14426 | @option{-fpack-struct[=@var{n}]} @pxref{Code Gen Options}). |
6b5553e5 | 14427 | @item @code{#pragma pack(push[,@var{n}])} pushes the current alignment |
14428 | setting on an internal stack and then optionally sets the new alignment. | |
14429 | @item @code{#pragma pack(pop)} restores the alignment setting to the one | |
14430 | saved at the top of the internal stack (and removes that stack entry). | |
14431 | Note that @code{#pragma pack([@var{n}])} does not influence this internal | |
14432 | stack; thus it is possible to have @code{#pragma pack(push)} followed by | |
14433 | multiple @code{#pragma pack(@var{n})} instances and finalized by a single | |
14434 | @code{#pragma pack(pop)}. | |
14435 | @end enumerate | |
14436 | ||
83d10720 | 14437 | Some targets, e.g.@: i386 and powerpc, support the @code{ms_struct} |
114d1545 | 14438 | @code{#pragma} which lays out a structure as the documented |
14439 | @code{__attribute__ ((ms_struct))}. | |
14440 | @enumerate | |
14441 | @item @code{#pragma ms_struct on} turns on the layout for structures | |
14442 | declared. | |
14443 | @item @code{#pragma ms_struct off} turns off the layout for structures | |
14444 | declared. | |
14445 | @item @code{#pragma ms_struct reset} goes back to the default layout. | |
14446 | @end enumerate | |
14447 | ||
b60f73dc | 14448 | @node Weak Pragmas |
14449 | @subsection Weak Pragmas | |
14450 | ||
14451 | For compatibility with SVR4, GCC supports a set of @code{#pragma} | |
14452 | directives for declaring symbols to be weak, and defining weak | |
14453 | aliases. | |
14454 | ||
14455 | @table @code | |
14456 | @item #pragma weak @var{symbol} | |
14457 | @cindex pragma, weak | |
14458 | This pragma declares @var{symbol} to be weak, as if the declaration | |
14459 | had the attribute of the same name. The pragma may appear before | |
fbdda6a7 | 14460 | or after the declaration of @var{symbol}. It is not an error for |
b60f73dc | 14461 | @var{symbol} to never be defined at all. |
14462 | ||
14463 | @item #pragma weak @var{symbol1} = @var{symbol2} | |
14464 | This pragma declares @var{symbol1} to be a weak alias of @var{symbol2}. | |
14465 | It is an error if @var{symbol2} is not defined in the current | |
14466 | translation unit. | |
14467 | @end table | |
14468 | ||
76f02516 | 14469 | @node Diagnostic Pragmas |
14470 | @subsection Diagnostic Pragmas | |
14471 | ||
14472 | GCC allows the user to selectively enable or disable certain types of | |
14473 | diagnostics, and change the kind of the diagnostic. For example, a | |
14474 | project's policy might require that all sources compile with | |
14475 | @option{-Werror} but certain files might have exceptions allowing | |
14476 | specific types of warnings. Or, a project might selectively enable | |
14477 | diagnostics and treat them as errors depending on which preprocessor | |
14478 | macros are defined. | |
14479 | ||
14480 | @table @code | |
14481 | @item #pragma GCC diagnostic @var{kind} @var{option} | |
14482 | @cindex pragma, diagnostic | |
14483 | ||
14484 | Modifies the disposition of a diagnostic. Note that not all | |
d1c59264 | 14485 | diagnostics are modifiable; at the moment only warnings (normally |
7a5a9c54 | 14486 | controlled by @samp{-W@dots{}}) can be controlled, and not all of them. |
76f02516 | 14487 | Use @option{-fdiagnostics-show-option} to determine which diagnostics |
14488 | are controllable and which option controls them. | |
14489 | ||
14490 | @var{kind} is @samp{error} to treat this diagnostic as an error, | |
14491 | @samp{warning} to treat it like a warning (even if @option{-Werror} is | |
14492 | in effect), or @samp{ignored} if the diagnostic is to be ignored. | |
bfe513a4 | 14493 | @var{option} is a double quoted string which matches the command-line |
76f02516 | 14494 | option. |
14495 | ||
14496 | @example | |
14497 | #pragma GCC diagnostic warning "-Wformat" | |
ede5a481 | 14498 | #pragma GCC diagnostic error "-Wformat" |
14499 | #pragma GCC diagnostic ignored "-Wformat" | |
76f02516 | 14500 | @end example |
14501 | ||
0955be65 | 14502 | Note that these pragmas override any command-line options. GCC keeps |
14503 | track of the location of each pragma, and issues diagnostics according | |
14504 | to the state as of that point in the source file. Thus, pragmas occurring | |
14505 | after a line do not affect diagnostics caused by that line. | |
14506 | ||
14507 | @item #pragma GCC diagnostic push | |
14508 | @itemx #pragma GCC diagnostic pop | |
14509 | ||
14510 | Causes GCC to remember the state of the diagnostics as of each | |
14511 | @code{push}, and restore to that point at each @code{pop}. If a | |
14512 | @code{pop} has no matching @code{push}, the command line options are | |
14513 | restored. | |
14514 | ||
14515 | @example | |
14516 | #pragma GCC diagnostic error "-Wuninitialized" | |
14517 | foo(a); /* error is given for this one */ | |
14518 | #pragma GCC diagnostic push | |
14519 | #pragma GCC diagnostic ignored "-Wuninitialized" | |
14520 | foo(b); /* no diagnostic for this one */ | |
14521 | #pragma GCC diagnostic pop | |
14522 | foo(c); /* error is given for this one */ | |
14523 | #pragma GCC diagnostic pop | |
14524 | foo(d); /* depends on command line options */ | |
14525 | @end example | |
76f02516 | 14526 | |
14527 | @end table | |
14528 | ||
d0a9db40 | 14529 | GCC also offers a simple mechanism for printing messages during |
14530 | compilation. | |
14531 | ||
14532 | @table @code | |
14533 | @item #pragma message @var{string} | |
14534 | @cindex pragma, diagnostic | |
14535 | ||
14536 | Prints @var{string} as a compiler message on compilation. The message | |
14537 | is informational only, and is neither a compilation warning nor an error. | |
14538 | ||
14539 | @smallexample | |
14540 | #pragma message "Compiling " __FILE__ "..." | |
14541 | @end smallexample | |
14542 | ||
14543 | @var{string} may be parenthesized, and is printed with location | |
14544 | information. For example, | |
14545 | ||
14546 | @smallexample | |
14547 | #define DO_PRAGMA(x) _Pragma (#x) | |
14548 | #define TODO(x) DO_PRAGMA(message ("TODO - " #x)) | |
14549 | ||
14550 | TODO(Remember to fix this) | |
14551 | @end smallexample | |
14552 | ||
14553 | prints @samp{/tmp/file.c:4: note: #pragma message: | |
14554 | TODO - Remember to fix this}. | |
14555 | ||
14556 | @end table | |
14557 | ||
4a2849cb | 14558 | @node Visibility Pragmas |
14559 | @subsection Visibility Pragmas | |
14560 | ||
14561 | @table @code | |
14562 | @item #pragma GCC visibility push(@var{visibility}) | |
14563 | @itemx #pragma GCC visibility pop | |
14564 | @cindex pragma, visibility | |
14565 | ||
14566 | This pragma allows the user to set the visibility for multiple | |
14567 | declarations without having to give each a visibility attribute | |
14568 | @xref{Function Attributes}, for more information about visibility and | |
14569 | the attribute syntax. | |
14570 | ||
14571 | In C++, @samp{#pragma GCC visibility} affects only namespace-scope | |
14572 | declarations. Class members and template specializations are not | |
14573 | affected; if you want to override the visibility for a particular | |
14574 | member or instantiation, you must use an attribute. | |
14575 | ||
14576 | @end table | |
14577 | ||
ebba2dc7 | 14578 | |
14579 | @node Push/Pop Macro Pragmas | |
14580 | @subsection Push/Pop Macro Pragmas | |
14581 | ||
14582 | For compatibility with Microsoft Windows compilers, GCC supports | |
14583 | @samp{#pragma push_macro(@var{"macro_name"})} | |
14584 | and @samp{#pragma pop_macro(@var{"macro_name"})}. | |
14585 | ||
14586 | @table @code | |
14587 | @item #pragma push_macro(@var{"macro_name"}) | |
14588 | @cindex pragma, push_macro | |
14589 | This pragma saves the value of the macro named as @var{macro_name} to | |
14590 | the top of the stack for this macro. | |
14591 | ||
14592 | @item #pragma pop_macro(@var{"macro_name"}) | |
14593 | @cindex pragma, pop_macro | |
14594 | This pragma sets the value of the macro named as @var{macro_name} to | |
14595 | the value on top of the stack for this macro. If the stack for | |
14596 | @var{macro_name} is empty, the value of the macro remains unchanged. | |
14597 | @end table | |
14598 | ||
14599 | For example: | |
14600 | ||
14601 | @smallexample | |
14602 | #define X 1 | |
14603 | #pragma push_macro("X") | |
14604 | #undef X | |
14605 | #define X -1 | |
14606 | #pragma pop_macro("X") | |
15b474a2 | 14607 | int x [X]; |
ebba2dc7 | 14608 | @end smallexample |
14609 | ||
14610 | In this example, the definition of X as 1 is saved by @code{#pragma | |
14611 | push_macro} and restored by @code{#pragma pop_macro}. | |
14612 | ||
46f8e3b0 | 14613 | @node Function Specific Option Pragmas |
14614 | @subsection Function Specific Option Pragmas | |
14615 | ||
14616 | @table @code | |
24470055 | 14617 | @item #pragma GCC target (@var{"string"}...) |
14618 | @cindex pragma GCC target | |
46f8e3b0 | 14619 | |
14620 | This pragma allows you to set target specific options for functions | |
14621 | defined later in the source file. One or more strings can be | |
14622 | specified. Each function that is defined after this point will be as | |
24470055 | 14623 | if @code{attribute((target("STRING")))} was specified for that |
46f8e3b0 | 14624 | function. The parenthesis around the options is optional. |
14625 | @xref{Function Attributes}, for more information about the | |
24470055 | 14626 | @code{target} attribute and the attribute syntax. |
46f8e3b0 | 14627 | |
755fa783 | 14628 | The @code{#pragma GCC target} attribute is not implemented in GCC versions earlier |
14629 | than 4.4 for the i386/x86_64 and 4.6 for the PowerPC backends. At | |
14630 | present, it is not implemented for other backends. | |
46f8e3b0 | 14631 | @end table |
14632 | ||
46f8e3b0 | 14633 | @table @code |
14634 | @item #pragma GCC optimize (@var{"string"}...) | |
14635 | @cindex pragma GCC optimize | |
14636 | ||
14637 | This pragma allows you to set global optimization options for functions | |
14638 | defined later in the source file. One or more strings can be | |
14639 | specified. Each function that is defined after this point will be as | |
14640 | if @code{attribute((optimize("STRING")))} was specified for that | |
14641 | function. The parenthesis around the options is optional. | |
14642 | @xref{Function Attributes}, for more information about the | |
14643 | @code{optimize} attribute and the attribute syntax. | |
14644 | ||
14645 | The @samp{#pragma GCC optimize} pragma is not implemented in GCC | |
14646 | versions earlier than 4.4. | |
14647 | @end table | |
14648 | ||
14649 | @table @code | |
24470055 | 14650 | @item #pragma GCC push_options |
14651 | @itemx #pragma GCC pop_options | |
14652 | @cindex pragma GCC push_options | |
14653 | @cindex pragma GCC pop_options | |
14654 | ||
14655 | These pragmas maintain a stack of the current target and optimization | |
14656 | options. It is intended for include files where you temporarily want | |
14657 | to switch to using a different @samp{#pragma GCC target} or | |
14658 | @samp{#pragma GCC optimize} and then to pop back to the previous | |
14659 | options. | |
14660 | ||
14661 | The @samp{#pragma GCC push_options} and @samp{#pragma GCC pop_options} | |
14662 | pragmas are not implemented in GCC versions earlier than 4.4. | |
46f8e3b0 | 14663 | @end table |
14664 | ||
14665 | @table @code | |
24470055 | 14666 | @item #pragma GCC reset_options |
14667 | @cindex pragma GCC reset_options | |
46f8e3b0 | 14668 | |
24470055 | 14669 | This pragma clears the current @code{#pragma GCC target} and |
14670 | @code{#pragma GCC optimize} to use the default switches as specified | |
14671 | on the command line. | |
14672 | ||
14673 | The @samp{#pragma GCC reset_options} pragma is not implemented in GCC | |
14674 | versions earlier than 4.4. | |
46f8e3b0 | 14675 | @end table |
14676 | ||
7cb6c162 | 14677 | @node Unnamed Fields |
158eddcc | 14678 | @section Unnamed struct/union fields within structs/unions |
12786727 | 14679 | @cindex @code{struct} |
14680 | @cindex @code{union} | |
7cb6c162 | 14681 | |
32074525 | 14682 | As permitted by ISO C11 and for compatibility with other compilers, |
afb3d3c4 | 14683 | GCC allows you to define |
7cb6c162 | 14684 | a structure or union that contains, as fields, structures and unions |
14685 | without names. For example: | |
14686 | ||
a0ecd6b1 | 14687 | @smallexample |
7cb6c162 | 14688 | struct @{ |
14689 | int a; | |
14690 | union @{ | |
14691 | int b; | |
14692 | float c; | |
14693 | @}; | |
14694 | int d; | |
14695 | @} foo; | |
a0ecd6b1 | 14696 | @end smallexample |
7cb6c162 | 14697 | |
14698 | In this example, the user would be able to access members of the unnamed | |
14699 | union with code like @samp{foo.b}. Note that only unnamed structs and | |
14700 | unions are allowed, you may not have, for example, an unnamed | |
14701 | @code{int}. | |
14702 | ||
14703 | You must never create such structures that cause ambiguous field definitions. | |
14704 | For example, this structure: | |
14705 | ||
a0ecd6b1 | 14706 | @smallexample |
7cb6c162 | 14707 | struct @{ |
14708 | int a; | |
14709 | struct @{ | |
14710 | int a; | |
14711 | @}; | |
14712 | @} foo; | |
a0ecd6b1 | 14713 | @end smallexample |
7cb6c162 | 14714 | |
14715 | It is ambiguous which @code{a} is being referred to with @samp{foo.a}. | |
8af5341f | 14716 | The compiler gives errors for such constructs. |
7cb6c162 | 14717 | |
158eddcc | 14718 | @opindex fms-extensions |
14719 | Unless @option{-fms-extensions} is used, the unnamed field must be a | |
14720 | structure or union definition without a tag (for example, @samp{struct | |
9b280b35 | 14721 | @{ int a; @};}). If @option{-fms-extensions} is used, the field may |
158eddcc | 14722 | also be a definition with a tag such as @samp{struct foo @{ int a; |
14723 | @};}, a reference to a previously defined structure or union such as | |
14724 | @samp{struct foo;}, or a reference to a @code{typedef} name for a | |
9b280b35 | 14725 | previously defined structure or union type. |
158eddcc | 14726 | |
2fdec027 | 14727 | @opindex fplan9-extensions |
14728 | The option @option{-fplan9-extensions} enables | |
14729 | @option{-fms-extensions} as well as two other extensions. First, a | |
14730 | pointer to a structure is automatically converted to a pointer to an | |
14731 | anonymous field for assignments and function calls. For example: | |
14732 | ||
14733 | @smallexample | |
14734 | struct s1 @{ int a; @}; | |
14735 | struct s2 @{ struct s1; @}; | |
14736 | extern void f1 (struct s1 *); | |
14737 | void f2 (struct s2 *p) @{ f1 (p); @} | |
14738 | @end smallexample | |
14739 | ||
14740 | In the call to @code{f1} inside @code{f2}, the pointer @code{p} is | |
14741 | converted into a pointer to the anonymous field. | |
14742 | ||
14743 | Second, when the type of an anonymous field is a @code{typedef} for a | |
14744 | @code{struct} or @code{union}, code may refer to the field using the | |
14745 | name of the @code{typedef}. | |
14746 | ||
14747 | @smallexample | |
14748 | typedef struct @{ int a; @} s1; | |
14749 | struct s2 @{ s1; @}; | |
14750 | s1 f1 (struct s2 *p) @{ return p->s1; @} | |
14751 | @end smallexample | |
14752 | ||
14753 | These usages are only permitted when they are not ambiguous. | |
14754 | ||
2a6f0f81 | 14755 | @node Thread-Local |
14756 | @section Thread-Local Storage | |
14757 | @cindex Thread-Local Storage | |
abf68e10 | 14758 | @cindex @acronym{TLS} |
12786727 | 14759 | @cindex @code{__thread} |
2a6f0f81 | 14760 | |
abf68e10 | 14761 | Thread-local storage (@acronym{TLS}) is a mechanism by which variables |
14762 | are allocated such that there is one instance of the variable per extant | |
2a6f0f81 | 14763 | thread. The run-time model GCC uses to implement this originates |
14764 | in the IA-64 processor-specific ABI, but has since been migrated | |
14765 | to other processors as well. It requires significant support from | |
14766 | the linker (@command{ld}), dynamic linker (@command{ld.so}), and | |
14767 | system libraries (@file{libc.so} and @file{libpthread.so}), so it | |
abf68e10 | 14768 | is not available everywhere. |
2a6f0f81 | 14769 | |
14770 | At the user level, the extension is visible with a new storage | |
14771 | class keyword: @code{__thread}. For example: | |
14772 | ||
a0ecd6b1 | 14773 | @smallexample |
2a6f0f81 | 14774 | __thread int i; |
14775 | extern __thread struct state s; | |
14776 | static __thread char *p; | |
a0ecd6b1 | 14777 | @end smallexample |
2a6f0f81 | 14778 | |
14779 | The @code{__thread} specifier may be used alone, with the @code{extern} | |
14780 | or @code{static} specifiers, but with no other storage class specifier. | |
14781 | When used with @code{extern} or @code{static}, @code{__thread} must appear | |
14782 | immediately after the other storage class specifier. | |
14783 | ||
14784 | The @code{__thread} specifier may be applied to any global, file-scoped | |
4facf21c | 14785 | static, function-scoped static, or static data member of a class. It may |
14786 | not be applied to block-scoped automatic or non-static data member. | |
2a6f0f81 | 14787 | |
14788 | When the address-of operator is applied to a thread-local variable, it is | |
14789 | evaluated at run-time and returns the address of the current thread's | |
14790 | instance of that variable. An address so obtained may be used by any | |
14791 | thread. When a thread terminates, any pointers to thread-local variables | |
14792 | in that thread become invalid. | |
14793 | ||
14794 | No static initialization may refer to the address of a thread-local variable. | |
14795 | ||
4facf21c | 14796 | In C++, if an initializer is present for a thread-local variable, it must |
14797 | be a @var{constant-expression}, as defined in 5.19.2 of the ANSI/ISO C++ | |
14798 | standard. | |
2a6f0f81 | 14799 | |
f4e302ca | 14800 | See @uref{http://www.akkadia.org/drepper/tls.pdf, |
2a6f0f81 | 14801 | ELF Handling For Thread-Local Storage} for a detailed explanation of |
14802 | the four thread-local storage addressing models, and how the run-time | |
14803 | is expected to function. | |
14804 | ||
abf68e10 | 14805 | @menu |
14806 | * C99 Thread-Local Edits:: | |
14807 | * C++98 Thread-Local Edits:: | |
14808 | @end menu | |
14809 | ||
14810 | @node C99 Thread-Local Edits | |
14811 | @subsection ISO/IEC 9899:1999 Edits for Thread-Local Storage | |
14812 | ||
14813 | The following are a set of changes to ISO/IEC 9899:1999 (aka C99) | |
14814 | that document the exact semantics of the language extension. | |
14815 | ||
14816 | @itemize @bullet | |
14817 | @item | |
14818 | @cite{5.1.2 Execution environments} | |
14819 | ||
14820 | Add new text after paragraph 1 | |
14821 | ||
14822 | @quotation | |
14823 | Within either execution environment, a @dfn{thread} is a flow of | |
14824 | control within a program. It is implementation defined whether | |
14825 | or not there may be more than one thread associated with a program. | |
14826 | It is implementation defined how threads beyond the first are | |
14827 | created, the name and type of the function called at thread | |
14828 | startup, and how threads may be terminated. However, objects | |
14829 | with thread storage duration shall be initialized before thread | |
14830 | startup. | |
14831 | @end quotation | |
14832 | ||
14833 | @item | |
14834 | @cite{6.2.4 Storage durations of objects} | |
14835 | ||
14836 | Add new text before paragraph 3 | |
14837 | ||
14838 | @quotation | |
14839 | An object whose identifier is declared with the storage-class | |
14840 | specifier @w{@code{__thread}} has @dfn{thread storage duration}. | |
14841 | Its lifetime is the entire execution of the thread, and its | |
14842 | stored value is initialized only once, prior to thread startup. | |
14843 | @end quotation | |
14844 | ||
14845 | @item | |
14846 | @cite{6.4.1 Keywords} | |
14847 | ||
14848 | Add @code{__thread}. | |
14849 | ||
14850 | @item | |
14851 | @cite{6.7.1 Storage-class specifiers} | |
14852 | ||
14853 | Add @code{__thread} to the list of storage class specifiers in | |
14854 | paragraph 1. | |
14855 | ||
14856 | Change paragraph 2 to | |
14857 | ||
14858 | @quotation | |
14859 | With the exception of @code{__thread}, at most one storage-class | |
14860 | specifier may be given [@dots{}]. The @code{__thread} specifier may | |
14861 | be used alone, or immediately following @code{extern} or | |
14862 | @code{static}. | |
14863 | @end quotation | |
14864 | ||
14865 | Add new text after paragraph 6 | |
14866 | ||
14867 | @quotation | |
14868 | The declaration of an identifier for a variable that has | |
14869 | block scope that specifies @code{__thread} shall also | |
14870 | specify either @code{extern} or @code{static}. | |
14871 | ||
14872 | The @code{__thread} specifier shall be used only with | |
14873 | variables. | |
14874 | @end quotation | |
14875 | @end itemize | |
14876 | ||
14877 | @node C++98 Thread-Local Edits | |
14878 | @subsection ISO/IEC 14882:1998 Edits for Thread-Local Storage | |
14879 | ||
14880 | The following are a set of changes to ISO/IEC 14882:1998 (aka C++98) | |
14881 | that document the exact semantics of the language extension. | |
14882 | ||
14883 | @itemize @bullet | |
258b58a9 | 14884 | @item |
abf68e10 | 14885 | @b{[intro.execution]} |
14886 | ||
14887 | New text after paragraph 4 | |
14888 | ||
14889 | @quotation | |
14890 | A @dfn{thread} is a flow of control within the abstract machine. | |
14891 | It is implementation defined whether or not there may be more than | |
14892 | one thread. | |
14893 | @end quotation | |
14894 | ||
14895 | New text after paragraph 7 | |
14896 | ||
14897 | @quotation | |
85456819 | 14898 | It is unspecified whether additional action must be taken to |
abf68e10 | 14899 | ensure when and whether side effects are visible to other threads. |
14900 | @end quotation | |
14901 | ||
14902 | @item | |
14903 | @b{[lex.key]} | |
14904 | ||
14905 | Add @code{__thread}. | |
14906 | ||
14907 | @item | |
14908 | @b{[basic.start.main]} | |
14909 | ||
14910 | Add after paragraph 5 | |
14911 | ||
14912 | @quotation | |
14913 | The thread that begins execution at the @code{main} function is called | |
85456819 | 14914 | the @dfn{main thread}. It is implementation defined how functions |
abf68e10 | 14915 | beginning threads other than the main thread are designated or typed. |
14916 | A function so designated, as well as the @code{main} function, is called | |
14917 | a @dfn{thread startup function}. It is implementation defined what | |
14918 | happens if a thread startup function returns. It is implementation | |
14919 | defined what happens to other threads when any thread calls @code{exit}. | |
14920 | @end quotation | |
14921 | ||
14922 | @item | |
14923 | @b{[basic.start.init]} | |
14924 | ||
14925 | Add after paragraph 4 | |
14926 | ||
14927 | @quotation | |
14928 | The storage for an object of thread storage duration shall be | |
a99e98db | 14929 | statically initialized before the first statement of the thread startup |
abf68e10 | 14930 | function. An object of thread storage duration shall not require |
14931 | dynamic initialization. | |
14932 | @end quotation | |
14933 | ||
14934 | @item | |
14935 | @b{[basic.start.term]} | |
14936 | ||
14937 | Add after paragraph 3 | |
14938 | ||
14939 | @quotation | |
4facf21c | 14940 | The type of an object with thread storage duration shall not have a |
14941 | non-trivial destructor, nor shall it be an array type whose elements | |
14942 | (directly or indirectly) have non-trivial destructors. | |
abf68e10 | 14943 | @end quotation |
14944 | ||
14945 | @item | |
14946 | @b{[basic.stc]} | |
14947 | ||
14948 | Add ``thread storage duration'' to the list in paragraph 1. | |
14949 | ||
14950 | Change paragraph 2 | |
14951 | ||
14952 | @quotation | |
14953 | Thread, static, and automatic storage durations are associated with | |
14954 | objects introduced by declarations [@dots{}]. | |
14955 | @end quotation | |
14956 | ||
14957 | Add @code{__thread} to the list of specifiers in paragraph 3. | |
14958 | ||
14959 | @item | |
14960 | @b{[basic.stc.thread]} | |
14961 | ||
14962 | New section before @b{[basic.stc.static]} | |
14963 | ||
14964 | @quotation | |
299006ee | 14965 | The keyword @code{__thread} applied to a non-local object gives the |
abf68e10 | 14966 | object thread storage duration. |
14967 | ||
14968 | A local variable or class data member declared both @code{static} | |
14969 | and @code{__thread} gives the variable or member thread storage | |
14970 | duration. | |
14971 | @end quotation | |
14972 | ||
14973 | @item | |
14974 | @b{[basic.stc.static]} | |
14975 | ||
14976 | Change paragraph 1 | |
14977 | ||
14978 | @quotation | |
14979 | All objects which have neither thread storage duration, dynamic | |
14980 | storage duration nor are local [@dots{}]. | |
14981 | @end quotation | |
14982 | ||
14983 | @item | |
14984 | @b{[dcl.stc]} | |
14985 | ||
14986 | Add @code{__thread} to the list in paragraph 1. | |
14987 | ||
14988 | Change paragraph 1 | |
14989 | ||
14990 | @quotation | |
14991 | With the exception of @code{__thread}, at most one | |
14992 | @var{storage-class-specifier} shall appear in a given | |
14993 | @var{decl-specifier-seq}. The @code{__thread} specifier may | |
14994 | be used alone, or immediately following the @code{extern} or | |
14995 | @code{static} specifiers. [@dots{}] | |
14996 | @end quotation | |
14997 | ||
14998 | Add after paragraph 5 | |
14999 | ||
15000 | @quotation | |
15001 | The @code{__thread} specifier can be applied only to the names of objects | |
15002 | and to anonymous unions. | |
15003 | @end quotation | |
15004 | ||
15005 | @item | |
15006 | @b{[class.mem]} | |
15007 | ||
15008 | Add after paragraph 6 | |
15009 | ||
15010 | @quotation | |
15011 | Non-@code{static} members shall not be @code{__thread}. | |
15012 | @end quotation | |
15013 | @end itemize | |
15014 | ||
d7282a2b | 15015 | @node Binary constants |
15016 | @section Binary constants using the @samp{0b} prefix | |
15017 | @cindex Binary constants using the @samp{0b} prefix | |
15018 | ||
15019 | Integer constants can be written as binary constants, consisting of a | |
15020 | sequence of @samp{0} and @samp{1} digits, prefixed by @samp{0b} or | |
15021 | @samp{0B}. This is particularly useful in environments that operate a | |
15022 | lot on the bit-level (like microcontrollers). | |
15023 | ||
15024 | The following statements are identical: | |
15025 | ||
15026 | @smallexample | |
15027 | i = 42; | |
15028 | i = 0x2a; | |
15029 | i = 052; | |
15030 | i = 0b101010; | |
15031 | @end smallexample | |
15032 | ||
15033 | The type of these constants follows the same rules as for octal or | |
15034 | hexadecimal integer constants, so suffixes like @samp{L} or @samp{UL} | |
15035 | can be applied. | |
15036 | ||
146ef39f | 15037 | @node C++ Extensions |
15038 | @chapter Extensions to the C++ Language | |
15039 | @cindex extensions, C++ language | |
15040 | @cindex C++ language extensions | |
15041 | ||
15042 | The GNU compiler provides these extensions to the C++ language (and you | |
15043 | can also use most of the C language extensions in your C++ programs). If you | |
15044 | want to write code that checks whether these features are available, you can | |
15045 | test for the GNU compiler the same way as for C programs: check for a | |
15046 | predefined macro @code{__GNUC__}. You can also use @code{__GNUG__} to | |
c47cbd00 | 15047 | test specifically for GNU C++ (@pxref{Common Predefined Macros,, |
15048 | Predefined Macros,cpp,The GNU C Preprocessor}). | |
146ef39f | 15049 | |
15050 | @menu | |
e83c4d0f | 15051 | * C++ Volatiles:: What constitutes an access to a volatile object. |
dbe4c49e | 15052 | * Restricted Pointers:: C99 restricted pointers and references. |
a89b0e97 | 15053 | * Vague Linkage:: Where G++ puts inlines, vtables and such. |
146ef39f | 15054 | * C++ Interface:: You can use a single C++ header file for both |
64b04d50 | 15055 | declarations and definitions. |
146ef39f | 15056 | * Template Instantiation:: Methods for ensuring that exactly one copy of |
64b04d50 | 15057 | each needed template instantiation is emitted. |
8b76b461 | 15058 | * Bound member functions:: You can extract a function pointer to the |
15059 | method denoted by a @samp{->*} or @samp{.*} expression. | |
64b04d50 | 15060 | * C++ Attributes:: Variable, function, and type attributes for C++ only. |
ea4d28f3 | 15061 | * Namespace Association:: Strong using-directives for namespace association. |
481451eb | 15062 | * Type Traits:: Compiler support for type traits |
6df8a9dd | 15063 | * Java Exceptions:: Tweaking exception handling to work with Java. |
a77827f5 | 15064 | * Deprecated Features:: Things will disappear from g++. |
64b04d50 | 15065 | * Backwards Compatibility:: Compatibilities with earlier definitions of C++. |
146ef39f | 15066 | @end menu |
15067 | ||
e83c4d0f | 15068 | @node C++ Volatiles |
15069 | @section When is a Volatile C++ Object Accessed? | |
b1a8d4ce | 15070 | @cindex accessing volatiles |
15071 | @cindex volatile read | |
15072 | @cindex volatile write | |
15073 | @cindex volatile access | |
15074 | ||
e83c4d0f | 15075 | The C++ standard differs from the C standard in its treatment of |
15076 | volatile objects. It fails to specify what constitutes a volatile | |
15077 | access, except to say that C++ should behave in a similar manner to C | |
15078 | with respect to volatiles, where possible. However, the different | |
7e44812a | 15079 | lvalueness of expressions between C and C++ complicate the behavior. |
e83c4d0f | 15080 | G++ behaves the same as GCC for volatile access, @xref{C |
7e44812a | 15081 | Extensions,,Volatiles}, for a description of GCC's behavior. |
b1a8d4ce | 15082 | |
e83c4d0f | 15083 | The C and C++ language specifications differ when an object is |
15084 | accessed in a void context: | |
b1a8d4ce | 15085 | |
a0ecd6b1 | 15086 | @smallexample |
8e5fcce7 | 15087 | volatile int *src = @var{somevalue}; |
b1a8d4ce | 15088 | *src; |
a0ecd6b1 | 15089 | @end smallexample |
b1a8d4ce | 15090 | |
e83c4d0f | 15091 | The C++ standard specifies that such expressions do not undergo lvalue |
15092 | to rvalue conversion, and that the type of the dereferenced object may | |
15093 | be incomplete. The C++ standard does not specify explicitly that it | |
15094 | is lvalue to rvalue conversion which is responsible for causing an | |
15095 | access. There is reason to believe that it is, because otherwise | |
15096 | certain simple expressions become undefined. However, because it | |
15097 | would surprise most programmers, G++ treats dereferencing a pointer to | |
15098 | volatile object of complete type as GCC would do for an equivalent | |
15099 | type in C@. When the object has incomplete type, G++ issues a | |
15100 | warning; if you wish to force an error, you must force a conversion to | |
15101 | rvalue with, for instance, a static cast. | |
b1a8d4ce | 15102 | |
37744367 | 15103 | When using a reference to volatile, G++ does not treat equivalent |
b1a8d4ce | 15104 | expressions as accesses to volatiles, but instead issues a warning that |
71d6ad5e | 15105 | no volatile is accessed. The rationale for this is that otherwise it |
b1a8d4ce | 15106 | becomes difficult to determine where volatile access occur, and not |
15107 | possible to ignore the return value from functions returning volatile | |
71d6ad5e | 15108 | references. Again, if you wish to force a read, cast the reference to |
b1a8d4ce | 15109 | an rvalue. |
15110 | ||
7e44812a | 15111 | G++ implements the same behavior as GCC does when assigning to a |
e83c4d0f | 15112 | volatile object -- there is no reread of the assigned-to object, the |
15113 | assigned rvalue is reused. Note that in C++ assignment expressions | |
15114 | are lvalues, and if used as an lvalue, the volatile object will be | |
15115 | referred to. For instance, @var{vref} will refer to @var{vobj}, as | |
15116 | expected, in the following example: | |
15117 | ||
15118 | @smallexample | |
15119 | volatile int vobj; | |
15120 | volatile int &vref = vobj = @var{something}; | |
15121 | @end smallexample | |
15122 | ||
6795ece9 | 15123 | @node Restricted Pointers |
15124 | @section Restricting Pointer Aliasing | |
15125 | @cindex restricted pointers | |
15126 | @cindex restricted references | |
15127 | @cindex restricted this pointer | |
15128 | ||
ef8d967c | 15129 | As with the C front end, G++ understands the C99 feature of restricted pointers, |
6795ece9 | 15130 | specified with the @code{__restrict__}, or @code{__restrict} type |
71d6ad5e | 15131 | qualifier. Because you cannot compile C++ by specifying the @option{-std=c99} |
6795ece9 | 15132 | language flag, @code{restrict} is not a keyword in C++. |
15133 | ||
15134 | In addition to allowing restricted pointers, you can specify restricted | |
15135 | references, which indicate that the reference is not aliased in the local | |
15136 | context. | |
15137 | ||
a0ecd6b1 | 15138 | @smallexample |
6795ece9 | 15139 | void fn (int *__restrict__ rptr, int &__restrict__ rref) |
15140 | @{ | |
4ae74ddd | 15141 | /* @r{@dots{}} */ |
6795ece9 | 15142 | @} |
a0ecd6b1 | 15143 | @end smallexample |
6795ece9 | 15144 | |
15145 | @noindent | |
15146 | In the body of @code{fn}, @var{rptr} points to an unaliased integer and | |
15147 | @var{rref} refers to a (different) unaliased integer. | |
15148 | ||
15149 | You may also specify whether a member function's @var{this} pointer is | |
15150 | unaliased by using @code{__restrict__} as a member function qualifier. | |
15151 | ||
a0ecd6b1 | 15152 | @smallexample |
6795ece9 | 15153 | void T::fn () __restrict__ |
15154 | @{ | |
4ae74ddd | 15155 | /* @r{@dots{}} */ |
6795ece9 | 15156 | @} |
a0ecd6b1 | 15157 | @end smallexample |
6795ece9 | 15158 | |
15159 | @noindent | |
15160 | Within the body of @code{T::fn}, @var{this} will have the effective | |
71d6ad5e | 15161 | definition @code{T *__restrict__ const this}. Notice that the |
6795ece9 | 15162 | interpretation of a @code{__restrict__} member function qualifier is |
15163 | different to that of @code{const} or @code{volatile} qualifier, in that it | |
71d6ad5e | 15164 | is applied to the pointer rather than the object. This is consistent with |
6795ece9 | 15165 | other compilers which implement restricted pointers. |
15166 | ||
15167 | As with all outermost parameter qualifiers, @code{__restrict__} is | |
71d6ad5e | 15168 | ignored in function definition matching. This means you only need to |
6795ece9 | 15169 | specify @code{__restrict__} in a function definition, rather than |
15170 | in a function prototype as well. | |
15171 | ||
a89b0e97 | 15172 | @node Vague Linkage |
15173 | @section Vague Linkage | |
15174 | @cindex vague linkage | |
15175 | ||
15176 | There are several constructs in C++ which require space in the object | |
15177 | file but are not clearly tied to a single translation unit. We say that | |
15178 | these constructs have ``vague linkage''. Typically such constructs are | |
15179 | emitted wherever they are needed, though sometimes we can be more | |
15180 | clever. | |
15181 | ||
15182 | @table @asis | |
15183 | @item Inline Functions | |
15184 | Inline functions are typically defined in a header file which can be | |
15185 | included in many different compilations. Hopefully they can usually be | |
15186 | inlined, but sometimes an out-of-line copy is necessary, if the address | |
15187 | of the function is taken or if inlining fails. In general, we emit an | |
15188 | out-of-line copy in all translation units where one is needed. As an | |
15189 | exception, we only emit inline virtual functions with the vtable, since | |
15190 | it will always require a copy. | |
15191 | ||
15192 | Local static variables and string constants used in an inline function | |
15193 | are also considered to have vague linkage, since they must be shared | |
15194 | between all inlined and out-of-line instances of the function. | |
15195 | ||
15196 | @item VTables | |
15197 | @cindex vtable | |
15198 | C++ virtual functions are implemented in most compilers using a lookup | |
15199 | table, known as a vtable. The vtable contains pointers to the virtual | |
15200 | functions provided by a class, and each object of the class contains a | |
15201 | pointer to its vtable (or vtables, in some multiple-inheritance | |
15202 | situations). If the class declares any non-inline, non-pure virtual | |
15203 | functions, the first one is chosen as the ``key method'' for the class, | |
15204 | and the vtable is only emitted in the translation unit where the key | |
15205 | method is defined. | |
15206 | ||
15207 | @emph{Note:} If the chosen key method is later defined as inline, the | |
15208 | vtable will still be emitted in every translation unit which defines it. | |
15209 | Make sure that any inline virtuals are declared inline in the class | |
15210 | body, even if they are not defined there. | |
15211 | ||
12786727 | 15212 | @item @code{type_info} objects |
15213 | @cindex @code{type_info} | |
a89b0e97 | 15214 | @cindex RTTI |
15215 | C++ requires information about types to be written out in order to | |
15216 | implement @samp{dynamic_cast}, @samp{typeid} and exception handling. | |
12786727 | 15217 | For polymorphic classes (classes with virtual functions), the @samp{type_info} |
a89b0e97 | 15218 | object is written out along with the vtable so that @samp{dynamic_cast} |
15219 | can determine the dynamic type of a class object at runtime. For all | |
12786727 | 15220 | other types, we write out the @samp{type_info} object when it is used: when |
a89b0e97 | 15221 | applying @samp{typeid} to an expression, throwing an object, or |
15222 | referring to a type in a catch clause or exception specification. | |
15223 | ||
15224 | @item Template Instantiations | |
15225 | Most everything in this section also applies to template instantiations, | |
15226 | but there are other options as well. | |
15227 | @xref{Template Instantiation,,Where's the Template?}. | |
15228 | ||
15229 | @end table | |
15230 | ||
15231 | When used with GNU ld version 2.8 or later on an ELF system such as | |
c20b542c | 15232 | GNU/Linux or Solaris 2, or on Microsoft Windows, duplicate copies of |
a89b0e97 | 15233 | these constructs will be discarded at link time. This is known as |
15234 | COMDAT support. | |
15235 | ||
15236 | On targets that don't support COMDAT, but do support weak symbols, GCC | |
15237 | will use them. This way one copy will override all the others, but | |
15238 | the unused copies will still take up space in the executable. | |
15239 | ||
15240 | For targets which do not support either COMDAT or weak symbols, | |
15241 | most entities with vague linkage will be emitted as local symbols to | |
15242 | avoid duplicate definition errors from the linker. This will not happen | |
15243 | for local statics in inlines, however, as having multiple copies will | |
15244 | almost certainly break things. | |
15245 | ||
15246 | @xref{C++ Interface,,Declarations and Definitions in One Header}, for | |
15247 | another way to control placement of these constructs. | |
15248 | ||
146ef39f | 15249 | @node C++ Interface |
9dc0b451 | 15250 | @section #pragma interface and implementation |
146ef39f | 15251 | |
15252 | @cindex interface and implementation headers, C++ | |
15253 | @cindex C++ interface and implementation headers | |
146ef39f | 15254 | @cindex pragmas, interface and implementation |
146ef39f | 15255 | |
9dc0b451 | 15256 | @code{#pragma interface} and @code{#pragma implementation} provide the |
15257 | user with a way of explicitly directing the compiler to emit entities | |
15258 | with vague linkage (and debugging information) in a particular | |
15259 | translation unit. | |
146ef39f | 15260 | |
9dc0b451 | 15261 | @emph{Note:} As of GCC 2.7.2, these @code{#pragma}s are not useful in |
15262 | most cases, because of COMDAT support and the ``key method'' heuristic | |
15263 | mentioned in @ref{Vague Linkage}. Using them can actually cause your | |
fcc3191b | 15264 | program to grow due to unnecessary out-of-line copies of inline |
9dc0b451 | 15265 | functions. Currently (3.4) the only benefit of these |
15266 | @code{#pragma}s is reduced duplication of debugging information, and | |
15267 | that should be addressed soon on DWARF 2 targets with the use of | |
15268 | COMDAT groups. | |
146ef39f | 15269 | |
15270 | @table @code | |
15271 | @item #pragma interface | |
15272 | @itemx #pragma interface "@var{subdir}/@var{objects}.h" | |
15273 | @kindex #pragma interface | |
15274 | Use this directive in @emph{header files} that define object classes, to save | |
15275 | space in most of the object files that use those classes. Normally, | |
15276 | local copies of certain information (backup copies of inline member | |
15277 | functions, debugging information, and the internal tables that implement | |
15278 | virtual functions) must be kept in each object file that includes class | |
15279 | definitions. You can use this pragma to avoid such duplication. When a | |
15280 | header file containing @samp{#pragma interface} is included in a | |
15281 | compilation, this auxiliary information will not be generated (unless | |
15282 | the main input source file itself uses @samp{#pragma implementation}). | |
15283 | Instead, the object files will contain references to be resolved at link | |
15284 | time. | |
15285 | ||
15286 | The second form of this directive is useful for the case where you have | |
15287 | multiple headers with the same name in different directories. If you | |
15288 | use this form, you must specify the same string to @samp{#pragma | |
15289 | implementation}. | |
15290 | ||
15291 | @item #pragma implementation | |
15292 | @itemx #pragma implementation "@var{objects}.h" | |
15293 | @kindex #pragma implementation | |
15294 | Use this pragma in a @emph{main input file}, when you want full output from | |
15295 | included header files to be generated (and made globally visible). The | |
15296 | included header file, in turn, should use @samp{#pragma interface}. | |
15297 | Backup copies of inline member functions, debugging information, and the | |
15298 | internal tables used to implement virtual functions are all generated in | |
15299 | implementation files. | |
15300 | ||
15301 | @cindex implied @code{#pragma implementation} | |
15302 | @cindex @code{#pragma implementation}, implied | |
15303 | @cindex naming convention, implementation headers | |
15304 | If you use @samp{#pragma implementation} with no argument, it applies to | |
15305 | an include file with the same basename@footnote{A file's @dfn{basename} | |
15306 | was the name stripped of all leading path information and of trailing | |
15307 | suffixes, such as @samp{.h} or @samp{.C} or @samp{.cc}.} as your source | |
15308 | file. For example, in @file{allclass.cc}, giving just | |
15309 | @samp{#pragma implementation} | |
15310 | by itself is equivalent to @samp{#pragma implementation "allclass.h"}. | |
15311 | ||
15312 | In versions of GNU C++ prior to 2.6.0 @file{allclass.h} was treated as | |
15313 | an implementation file whenever you would include it from | |
15314 | @file{allclass.cc} even if you never specified @samp{#pragma | |
15315 | implementation}. This was deemed to be more trouble than it was worth, | |
15316 | however, and disabled. | |
15317 | ||
146ef39f | 15318 | Use the string argument if you want a single implementation file to |
15319 | include code from multiple header files. (You must also use | |
15320 | @samp{#include} to include the header file; @samp{#pragma | |
15321 | implementation} only specifies how to use the file---it doesn't actually | |
15322 | include it.) | |
15323 | ||
15324 | There is no way to split up the contents of a single header file into | |
15325 | multiple implementation files. | |
15326 | @end table | |
15327 | ||
15328 | @cindex inlining and C++ pragmas | |
15329 | @cindex C++ pragmas, effect on inlining | |
15330 | @cindex pragmas in C++, effect on inlining | |
15331 | @samp{#pragma implementation} and @samp{#pragma interface} also have an | |
15332 | effect on function inlining. | |
15333 | ||
15334 | If you define a class in a header file marked with @samp{#pragma | |
9dc0b451 | 15335 | interface}, the effect on an inline function defined in that class is |
15336 | similar to an explicit @code{extern} declaration---the compiler emits | |
15337 | no code at all to define an independent version of the function. Its | |
15338 | definition is used only for inlining with its callers. | |
146ef39f | 15339 | |
67791935 | 15340 | @opindex fno-implement-inlines |
146ef39f | 15341 | Conversely, when you include the same header file in a main source file |
15342 | that declares it as @samp{#pragma implementation}, the compiler emits | |
15343 | code for the function itself; this defines a version of the function | |
15344 | that can be found via pointers (or by callers compiled without | |
15345 | inlining). If all calls to the function can be inlined, you can avoid | |
67791935 | 15346 | emitting the function by compiling with @option{-fno-implement-inlines}. |
146ef39f | 15347 | If any calls were not inlined, you will get linker errors. |
15348 | ||
15349 | @node Template Instantiation | |
15350 | @section Where's the Template? | |
146ef39f | 15351 | @cindex template instantiation |
15352 | ||
15353 | C++ templates are the first language feature to require more | |
15354 | intelligence from the environment than one usually finds on a UNIX | |
15355 | system. Somehow the compiler and linker have to make sure that each | |
15356 | template instance occurs exactly once in the executable if it is needed, | |
15357 | and not at all otherwise. There are two basic approaches to this | |
153e79bc | 15358 | problem, which are referred to as the Borland model and the Cfront model. |
146ef39f | 15359 | |
15360 | @table @asis | |
15361 | @item Borland model | |
15362 | Borland C++ solved the template instantiation problem by adding the code | |
f96ff825 | 15363 | equivalent of common blocks to their linker; the compiler emits template |
15364 | instances in each translation unit that uses them, and the linker | |
15365 | collapses them together. The advantage of this model is that the linker | |
15366 | only has to consider the object files themselves; there is no external | |
15367 | complexity to worry about. This disadvantage is that compilation time | |
15368 | is increased because the template code is being compiled repeatedly. | |
15369 | Code written for this model tends to include definitions of all | |
15370 | templates in the header file, since they must be seen to be | |
15371 | instantiated. | |
146ef39f | 15372 | |
15373 | @item Cfront model | |
15374 | The AT&T C++ translator, Cfront, solved the template instantiation | |
15375 | problem by creating the notion of a template repository, an | |
f96ff825 | 15376 | automatically maintained place where template instances are stored. A |
15377 | more modern version of the repository works as follows: As individual | |
15378 | object files are built, the compiler places any template definitions and | |
15379 | instantiations encountered in the repository. At link time, the link | |
15380 | wrapper adds in the objects in the repository and compiles any needed | |
15381 | instances that were not previously emitted. The advantages of this | |
15382 | model are more optimal compilation speed and the ability to use the | |
15383 | system linker; to implement the Borland model a compiler vendor also | |
146ef39f | 15384 | needs to replace the linker. The disadvantages are vastly increased |
f96ff825 | 15385 | complexity, and thus potential for error; for some code this can be |
15386 | just as transparent, but in practice it can been very difficult to build | |
146ef39f | 15387 | multiple programs in one directory and one program in multiple |
f96ff825 | 15388 | directories. Code written for this model tends to separate definitions |
15389 | of non-inline member templates into a separate file, which should be | |
15390 | compiled separately. | |
146ef39f | 15391 | @end table |
15392 | ||
f96ff825 | 15393 | When used with GNU ld version 2.8 or later on an ELF system such as |
ef8d967c | 15394 | GNU/Linux or Solaris 2, or on Microsoft Windows, G++ supports the |
15395 | Borland model. On other systems, G++ implements neither automatic | |
865ff07f | 15396 | model. |
f96ff825 | 15397 | |
6ad63f69 | 15398 | You have the following options for dealing with template instantiations: |
146ef39f | 15399 | |
15400 | @enumerate | |
7223a120 | 15401 | @item |
67791935 | 15402 | @opindex frepo |
15403 | Compile your template-using code with @option{-frepo}. The compiler will | |
7223a120 | 15404 | generate files with the extension @samp{.rpo} listing all of the |
15405 | template instantiations used in the corresponding object files which | |
15406 | could be instantiated there; the link wrapper, @samp{collect2}, will | |
15407 | then update the @samp{.rpo} files to tell the compiler where to place | |
15408 | those instantiations and rebuild any affected object files. The | |
15409 | link-time overhead is negligible after the first pass, as the compiler | |
15410 | will continue to place the instantiations in the same files. | |
15411 | ||
15412 | This is your best option for application code written for the Borland | |
15413 | model, as it will just work. Code written for the Cfront model will | |
15414 | need to be modified so that the template definitions are available at | |
15415 | one or more points of instantiation; usually this is as simple as adding | |
15416 | @code{#include <tmethods.cc>} to the end of each template header. | |
15417 | ||
15418 | For library code, if you want the library to provide all of the template | |
15419 | instantiations it needs, just try to link all of its object files | |
15420 | together; the link will fail, but cause the instantiations to be | |
15421 | generated as a side effect. Be warned, however, that this may cause | |
15422 | conflicts if multiple libraries try to provide the same instantiations. | |
15423 | For greater control, use explicit instantiation as described in the next | |
15424 | option. | |
15425 | ||
146ef39f | 15426 | @item |
67791935 | 15427 | @opindex fno-implicit-templates |
15428 | Compile your code with @option{-fno-implicit-templates} to disable the | |
146ef39f | 15429 | implicit generation of template instances, and explicitly instantiate |
15430 | all the ones you use. This approach requires more knowledge of exactly | |
15431 | which instances you need than do the others, but it's less | |
15432 | mysterious and allows greater control. You can scatter the explicit | |
15433 | instantiations throughout your program, perhaps putting them in the | |
15434 | translation units where the instances are used or the translation units | |
15435 | that define the templates themselves; you can put all of the explicit | |
15436 | instantiations you need into one big file; or you can create small files | |
15437 | like | |
15438 | ||
a0ecd6b1 | 15439 | @smallexample |
146ef39f | 15440 | #include "Foo.h" |
15441 | #include "Foo.cc" | |
15442 | ||
15443 | template class Foo<int>; | |
15444 | template ostream& operator << | |
15445 | (ostream&, const Foo<int>&); | |
a0ecd6b1 | 15446 | @end smallexample |
146ef39f | 15447 | |
15448 | for each of the instances you need, and create a template instantiation | |
15449 | library from those. | |
15450 | ||
15451 | If you are using Cfront-model code, you can probably get away with not | |
67791935 | 15452 | using @option{-fno-implicit-templates} when compiling files that don't |
146ef39f | 15453 | @samp{#include} the member template definitions. |
15454 | ||
15455 | If you use one big file to do the instantiations, you may want to | |
67791935 | 15456 | compile it without @option{-fno-implicit-templates} so you get all of the |
146ef39f | 15457 | instances required by your explicit instantiations (but not by any |
15458 | other files) without having to specify them as well. | |
15459 | ||
6ad63f69 | 15460 | The ISO C++ 2011 standard allows forward declaration of explicit |
15461 | instantiations (with @code{extern}). G++ supports explicit instantiation | |
15462 | declarations in C++98 mode and has extended the template instantiation | |
15463 | syntax to support instantiation of the compiler support data for a | |
0858f8a2 | 15464 | template class (i.e.@: the vtable) without instantiating any of its |
d39bcd80 | 15465 | members (with @code{inline}), and instantiation of only the static data |
15466 | members of a template class, without the support data or member | |
15467 | functions (with (@code{static}): | |
146ef39f | 15468 | |
a0ecd6b1 | 15469 | @smallexample |
146ef39f | 15470 | extern template int max (int, int); |
146ef39f | 15471 | inline template class Foo<int>; |
d39bcd80 | 15472 | static template class Foo<int>; |
a0ecd6b1 | 15473 | @end smallexample |
146ef39f | 15474 | |
15475 | @item | |
ef8d967c | 15476 | Do nothing. Pretend G++ does implement automatic instantiation |
146ef39f | 15477 | management. Code written for the Borland model will work fine, but |
15478 | each translation unit will contain instances of each of the templates it | |
15479 | uses. In a large program, this can lead to an unacceptable amount of code | |
15480 | duplication. | |
146ef39f | 15481 | @end enumerate |
15482 | ||
8b76b461 | 15483 | @node Bound member functions |
15484 | @section Extracting the function pointer from a bound pointer to member function | |
8b76b461 | 15485 | @cindex pmf |
15486 | @cindex pointer to member function | |
15487 | @cindex bound pointer to member function | |
15488 | ||
15489 | In C++, pointer to member functions (PMFs) are implemented using a wide | |
15490 | pointer of sorts to handle all the possible call mechanisms; the PMF | |
15491 | needs to store information about how to adjust the @samp{this} pointer, | |
15492 | and if the function pointed to is virtual, where to find the vtable, and | |
15493 | where in the vtable to look for the member function. If you are using | |
15494 | PMFs in an inner loop, you should really reconsider that decision. If | |
15495 | that is not an option, you can extract the pointer to the function that | |
15496 | would be called for a given object/PMF pair and call it directly inside | |
15497 | the inner loop, to save a bit of time. | |
15498 | ||
15499 | Note that you will still be paying the penalty for the call through a | |
15500 | function pointer; on most modern architectures, such a call defeats the | |
0858e3a2 | 15501 | branch prediction features of the CPU@. This is also true of normal |
8b76b461 | 15502 | virtual function calls. |
15503 | ||
15504 | The syntax for this extension is | |
15505 | ||
a0ecd6b1 | 15506 | @smallexample |
8b76b461 | 15507 | extern A a; |
15508 | extern int (A::*fp)(); | |
15509 | typedef int (*fptr)(A *); | |
15510 | ||
15511 | fptr p = (fptr)(a.*fp); | |
a0ecd6b1 | 15512 | @end smallexample |
8b76b461 | 15513 | |
0858f8a2 | 15514 | For PMF constants (i.e.@: expressions of the form @samp{&Klasse::Member}), |
71d6ad5e | 15515 | no object is needed to obtain the address of the function. They can be |
96149f2d | 15516 | converted to function pointers directly: |
15517 | ||
a0ecd6b1 | 15518 | @smallexample |
96149f2d | 15519 | fptr p1 = (fptr)(&A::foo); |
a0ecd6b1 | 15520 | @end smallexample |
96149f2d | 15521 | |
67791935 | 15522 | @opindex Wno-pmf-conversions |
15523 | You must specify @option{-Wno-pmf-conversions} to use this extension. | |
8b76b461 | 15524 | |
2f1d6059 | 15525 | @node C++ Attributes |
15526 | @section C++-Specific Variable, Function, and Type Attributes | |
15527 | ||
15528 | Some attributes only make sense for C++ programs. | |
15529 | ||
15530 | @table @code | |
15531 | @item init_priority (@var{priority}) | |
12786727 | 15532 | @cindex @code{init_priority} attribute |
2f1d6059 | 15533 | |
15534 | ||
15535 | In Standard C++, objects defined at namespace scope are guaranteed to be | |
15536 | initialized in an order in strict accordance with that of their definitions | |
15537 | @emph{in a given translation unit}. No guarantee is made for initializations | |
15538 | across translation units. However, GNU C++ allows users to control the | |
f7b79b48 | 15539 | order of initialization of objects defined at namespace scope with the |
2f1d6059 | 15540 | @code{init_priority} attribute by specifying a relative @var{priority}, |
15541 | a constant integral expression currently bounded between 101 and 65535 | |
15542 | inclusive. Lower numbers indicate a higher priority. | |
15543 | ||
15544 | In the following example, @code{A} would normally be created before | |
15545 | @code{B}, but the @code{init_priority} attribute has reversed that order: | |
15546 | ||
b724fad7 | 15547 | @smallexample |
2f1d6059 | 15548 | Some_Class A __attribute__ ((init_priority (2000))); |
15549 | Some_Class B __attribute__ ((init_priority (543))); | |
b724fad7 | 15550 | @end smallexample |
2f1d6059 | 15551 | |
15552 | @noindent | |
15553 | Note that the particular values of @var{priority} do not matter; only their | |
15554 | relative ordering. | |
15555 | ||
15672c96 | 15556 | @item java_interface |
12786727 | 15557 | @cindex @code{java_interface} attribute |
15672c96 | 15558 | |
3b0848a2 | 15559 | This type attribute informs C++ that the class is a Java interface. It may |
15672c96 | 15560 | only be applied to classes declared within an @code{extern "Java"} block. |
3b0848a2 | 15561 | Calls to methods declared in this interface will be dispatched using GCJ's |
15562 | interface table mechanism, instead of regular virtual table dispatch. | |
15672c96 | 15563 | |
2f1d6059 | 15564 | @end table |
15565 | ||
e66bbea3 | 15566 | See also @ref{Namespace Association}. |
a5ed46c9 | 15567 | |
ea4d28f3 | 15568 | @node Namespace Association |
15569 | @section Namespace Association | |
a5ed46c9 | 15570 | |
b1cd4fdd | 15571 | @strong{Caution:} The semantics of this extension are equivalent |
15572 | to C++ 2011 inline namespaces. Users should use inline namespaces | |
15573 | instead as this extension will be removed in future versions of G++. | |
a703c8a1 | 15574 | |
a5ed46c9 | 15575 | A using-directive with @code{__attribute ((strong))} is stronger |
15576 | than a normal using-directive in two ways: | |
15577 | ||
15578 | @itemize @bullet | |
15579 | @item | |
ea4d28f3 | 15580 | Templates from the used namespace can be specialized and explicitly |
15581 | instantiated as though they were members of the using namespace. | |
a5ed46c9 | 15582 | |
15583 | @item | |
15584 | The using namespace is considered an associated namespace of all | |
15585 | templates in the used namespace for purposes of argument-dependent | |
15586 | name lookup. | |
15587 | @end itemize | |
15588 | ||
ea4d28f3 | 15589 | The used namespace must be nested within the using namespace so that |
15590 | normal unqualified lookup works properly. | |
15591 | ||
a5ed46c9 | 15592 | This is useful for composing a namespace transparently from |
15593 | implementation namespaces. For example: | |
15594 | ||
15595 | @smallexample | |
15596 | namespace std @{ | |
15597 | namespace debug @{ | |
15598 | template <class T> struct A @{ @}; | |
15599 | @} | |
15600 | using namespace debug __attribute ((__strong__)); | |
91acd86c | 15601 | template <> struct A<int> @{ @}; // @r{ok to specialize} |
a5ed46c9 | 15602 | |
15603 | template <class T> void f (A<T>); | |
15604 | @} | |
15605 | ||
15606 | int main() | |
15607 | @{ | |
91acd86c | 15608 | f (std::A<float>()); // @r{lookup finds} std::f |
a5ed46c9 | 15609 | f (std::A<int>()); |
15610 | @} | |
15611 | @end smallexample | |
15612 | ||
481451eb | 15613 | @node Type Traits |
15614 | @section Type Traits | |
15615 | ||
15616 | The C++ front-end implements syntactic extensions that allow to | |
15617 | determine at compile time various characteristics of a type (or of a | |
15618 | pair of types). | |
15619 | ||
15620 | @table @code | |
15621 | @item __has_nothrow_assign (type) | |
0aa5d886 | 15622 | If @code{type} is const qualified or is a reference type then the trait is |
15623 | false. Otherwise if @code{__has_trivial_assign (type)} is true then the trait | |
15624 | is true, else if @code{type} is a cv class or union type with copy assignment | |
15625 | operators that are known not to throw an exception then the trait is true, | |
15b474a2 | 15626 | else it is false. Requires: @code{type} shall be a complete type, |
a799da27 | 15627 | (possibly cv-qualified) @code{void}, or an array of unknown bound. |
481451eb | 15628 | |
15629 | @item __has_nothrow_copy (type) | |
15630 | If @code{__has_trivial_copy (type)} is true then the trait is true, else if | |
15631 | @code{type} is a cv class or union type with copy constructors that | |
15632 | are known not to throw an exception then the trait is true, else it is false. | |
a799da27 | 15633 | Requires: @code{type} shall be a complete type, (possibly cv-qualified) |
15634 | @code{void}, or an array of unknown bound. | |
481451eb | 15635 | |
15636 | @item __has_nothrow_constructor (type) | |
15637 | If @code{__has_trivial_constructor (type)} is true then the trait is | |
15638 | true, else if @code{type} is a cv class or union type (or array | |
15639 | thereof) with a default constructor that is known not to throw an | |
15b474a2 | 15640 | exception then the trait is true, else it is false. Requires: |
15641 | @code{type} shall be a complete type, (possibly cv-qualified) | |
a799da27 | 15642 | @code{void}, or an array of unknown bound. |
481451eb | 15643 | |
15644 | @item __has_trivial_assign (type) | |
15645 | If @code{type} is const qualified or is a reference type then the trait is | |
15646 | false. Otherwise if @code{__is_pod (type)} is true then the trait is | |
15647 | true, else if @code{type} is a cv class or union type with a trivial | |
15648 | copy assignment ([class.copy]) then the trait is true, else it is | |
15b474a2 | 15649 | false. Requires: @code{type} shall be a complete type, (possibly |
a799da27 | 15650 | cv-qualified) @code{void}, or an array of unknown bound. |
481451eb | 15651 | |
15652 | @item __has_trivial_copy (type) | |
15b474a2 | 15653 | If @code{__is_pod (type)} is true or @code{type} is a reference type |
481451eb | 15654 | then the trait is true, else if @code{type} is a cv class or union type |
15655 | with a trivial copy constructor ([class.copy]) then the trait | |
15656 | is true, else it is false. Requires: @code{type} shall be a complete | |
a799da27 | 15657 | type, (possibly cv-qualified) @code{void}, or an array of unknown bound. |
481451eb | 15658 | |
15659 | @item __has_trivial_constructor (type) | |
15660 | If @code{__is_pod (type)} is true then the trait is true, else if | |
15661 | @code{type} is a cv class or union type (or array thereof) with a | |
15662 | trivial default constructor ([class.ctor]) then the trait is true, | |
a799da27 | 15663 | else it is false. Requires: @code{type} shall be a complete |
15664 | type, (possibly cv-qualified) @code{void}, or an array of unknown bound. | |
481451eb | 15665 | |
15666 | @item __has_trivial_destructor (type) | |
15667 | If @code{__is_pod (type)} is true or @code{type} is a reference type then | |
15668 | the trait is true, else if @code{type} is a cv class or union type (or | |
15669 | array thereof) with a trivial destructor ([class.dtor]) then the trait | |
15670 | is true, else it is false. Requires: @code{type} shall be a complete | |
a799da27 | 15671 | type, (possibly cv-qualified) @code{void}, or an array of unknown bound. |
481451eb | 15672 | |
15673 | @item __has_virtual_destructor (type) | |
15674 | If @code{type} is a class type with a virtual destructor | |
15675 | ([class.dtor]) then the trait is true, else it is false. Requires: | |
a799da27 | 15676 | @code{type} shall be a complete type, (possibly cv-qualified) |
15677 | @code{void}, or an array of unknown bound. | |
481451eb | 15678 | |
15679 | @item __is_abstract (type) | |
15680 | If @code{type} is an abstract class ([class.abstract]) then the trait | |
15681 | is true, else it is false. Requires: @code{type} shall be a complete | |
a799da27 | 15682 | type, (possibly cv-qualified) @code{void}, or an array of unknown bound. |
481451eb | 15683 | |
15684 | @item __is_base_of (base_type, derived_type) | |
15685 | If @code{base_type} is a base class of @code{derived_type} | |
15686 | ([class.derived]) then the trait is true, otherwise it is false. | |
15687 | Top-level cv qualifications of @code{base_type} and | |
15688 | @code{derived_type} are ignored. For the purposes of this trait, a | |
15689 | class type is considered is own base. Requires: if @code{__is_class | |
15690 | (base_type)} and @code{__is_class (derived_type)} are true and | |
15691 | @code{base_type} and @code{derived_type} are not the same type | |
15692 | (disregarding cv-qualifiers), @code{derived_type} shall be a complete | |
15693 | type. Diagnostic is produced if this requirement is not met. | |
15694 | ||
15695 | @item __is_class (type) | |
15696 | If @code{type} is a cv class type, and not a union type | |
d2258b2f | 15697 | ([basic.compound]) the trait is true, else it is false. |
481451eb | 15698 | |
15699 | @item __is_empty (type) | |
15700 | If @code{__is_class (type)} is false then the trait is false. | |
15701 | Otherwise @code{type} is considered empty if and only if: @code{type} | |
15702 | has no non-static data members, or all non-static data members, if | |
d2258b2f | 15703 | any, are bit-fields of length 0, and @code{type} has no virtual |
481451eb | 15704 | members, and @code{type} has no virtual base classes, and @code{type} |
15b474a2 | 15705 | has no base classes @code{base_type} for which |
481451eb | 15706 | @code{__is_empty (base_type)} is false. Requires: @code{type} shall |
a799da27 | 15707 | be a complete type, (possibly cv-qualified) @code{void}, or an array |
15708 | of unknown bound. | |
481451eb | 15709 | |
15710 | @item __is_enum (type) | |
d2258b2f | 15711 | If @code{type} is a cv enumeration type ([basic.compound]) the trait is |
481451eb | 15712 | true, else it is false. |
15713 | ||
a799da27 | 15714 | @item __is_literal_type (type) |
15715 | If @code{type} is a literal type ([basic.types]) the trait is | |
15716 | true, else it is false. Requires: @code{type} shall be a complete type, | |
15717 | (possibly cv-qualified) @code{void}, or an array of unknown bound. | |
15718 | ||
481451eb | 15719 | @item __is_pod (type) |
15720 | If @code{type} is a cv POD type ([basic.types]) then the trait is true, | |
a799da27 | 15721 | else it is false. Requires: @code{type} shall be a complete type, |
15722 | (possibly cv-qualified) @code{void}, or an array of unknown bound. | |
481451eb | 15723 | |
15724 | @item __is_polymorphic (type) | |
15725 | If @code{type} is a polymorphic class ([class.virtual]) then the trait | |
15726 | is true, else it is false. Requires: @code{type} shall be a complete | |
a799da27 | 15727 | type, (possibly cv-qualified) @code{void}, or an array of unknown bound. |
15728 | ||
15729 | @item __is_standard_layout (type) | |
15730 | If @code{type} is a standard-layout type ([basic.types]) the trait is | |
15731 | true, else it is false. Requires: @code{type} shall be a complete | |
15732 | type, (possibly cv-qualified) @code{void}, or an array of unknown bound. | |
15733 | ||
15734 | @item __is_trivial (type) | |
15735 | If @code{type} is a trivial type ([basic.types]) the trait is | |
15736 | true, else it is false. Requires: @code{type} shall be a complete | |
15737 | type, (possibly cv-qualified) @code{void}, or an array of unknown bound. | |
481451eb | 15738 | |
15739 | @item __is_union (type) | |
d2258b2f | 15740 | If @code{type} is a cv union type ([basic.compound]) the trait is |
481451eb | 15741 | true, else it is false. |
15742 | ||
e455102d | 15743 | @item __underlying_type (type) |
15744 | The underlying type of @code{type}. Requires: @code{type} shall be | |
15745 | an enumeration type ([dcl.enum]). | |
15746 | ||
481451eb | 15747 | @end table |
15748 | ||
6df8a9dd | 15749 | @node Java Exceptions |
15750 | @section Java Exceptions | |
15751 | ||
15752 | The Java language uses a slightly different exception handling model | |
15753 | from C++. Normally, GNU C++ will automatically detect when you are | |
15754 | writing C++ code that uses Java exceptions, and handle them | |
15755 | appropriately. However, if C++ code only needs to execute destructors | |
15756 | when Java exceptions are thrown through it, GCC will guess incorrectly. | |
0fff59be | 15757 | Sample problematic code is: |
6df8a9dd | 15758 | |
b724fad7 | 15759 | @smallexample |
6df8a9dd | 15760 | struct S @{ ~S(); @}; |
91acd86c | 15761 | extern void bar(); // @r{is written in Java, and may throw exceptions} |
6df8a9dd | 15762 | void foo() |
15763 | @{ | |
15764 | S s; | |
15765 | bar(); | |
15766 | @} | |
b724fad7 | 15767 | @end smallexample |
6df8a9dd | 15768 | |
15769 | @noindent | |
15770 | The usual effect of an incorrect guess is a link failure, complaining of | |
15771 | a missing routine called @samp{__gxx_personality_v0}. | |
15772 | ||
15773 | You can inform the compiler that Java exceptions are to be used in a | |
15774 | translation unit, irrespective of what it might think, by writing | |
15775 | @samp{@w{#pragma GCC java_exceptions}} at the head of the file. This | |
15776 | @samp{#pragma} must appear before any functions that throw or catch | |
15777 | exceptions, or run destructors when exceptions are thrown through them. | |
15778 | ||
15779 | You cannot mix Java and C++ exceptions in the same translation unit. It | |
15780 | is believed to be safe to throw a C++ exception from one file through | |
0fff59be | 15781 | another file compiled for the Java exception model, or vice versa, but |
15782 | there may be bugs in this area. | |
6df8a9dd | 15783 | |
64b04d50 | 15784 | @node Deprecated Features |
15785 | @section Deprecated Features | |
15786 | ||
15787 | In the past, the GNU C++ compiler was extended to experiment with new | |
71d6ad5e | 15788 | features, at a time when the C++ language was still evolving. Now that |
64b04d50 | 15789 | the C++ standard is complete, some of those features are superseded by |
71d6ad5e | 15790 | superior alternatives. Using the old features might cause a warning in |
15791 | some cases that the feature will be dropped in the future. In other | |
64b04d50 | 15792 | cases, the feature might be gone already. |
15793 | ||
15794 | While the list below is not exhaustive, it documents some of the options | |
15795 | that are now deprecated: | |
15796 | ||
15797 | @table @code | |
15798 | @item -fexternal-templates | |
15799 | @itemx -falt-external-templates | |
ef8d967c | 15800 | These are two of the many ways for G++ to implement template |
71d6ad5e | 15801 | instantiation. @xref{Template Instantiation}. The C++ standard clearly |
64b04d50 | 15802 | defines how template definitions have to be organized across |
ef8d967c | 15803 | implementation units. G++ has an implicit instantiation mechanism that |
64b04d50 | 15804 | should work just fine for standard-conforming code. |
15805 | ||
15806 | @item -fstrict-prototype | |
15807 | @itemx -fno-strict-prototype | |
15808 | Previously it was possible to use an empty prototype parameter list to | |
15809 | indicate an unspecified number of parameters (like C), rather than no | |
71d6ad5e | 15810 | parameters, as C++ demands. This feature has been removed, except where |
e66bbea3 | 15811 | it is required for backwards compatibility. @xref{Backwards Compatibility}. |
64b04d50 | 15812 | @end table |
15813 | ||
ac1c4b0c | 15814 | G++ allows a virtual function returning @samp{void *} to be overridden |
15815 | by one returning a different pointer type. This extension to the | |
15816 | covariant return type rules is now deprecated and will be removed from a | |
15817 | future version. | |
15818 | ||
d50879bc | 15819 | The G++ minimum and maximum operators (@samp{<?} and @samp{>?}) and |
15820 | their compound forms (@samp{<?=}) and @samp{>?=}) have been deprecated | |
04222864 | 15821 | and are now removed from G++. Code using these operators should be |
15822 | modified to use @code{std::min} and @code{std::max} instead. | |
d50879bc | 15823 | |
57a9b138 | 15824 | The named return value extension has been deprecated, and is now |
ef8d967c | 15825 | removed from G++. |
64b04d50 | 15826 | |
4ea8b5e2 | 15827 | The use of initializer lists with new expressions has been deprecated, |
ef8d967c | 15828 | and is now removed from G++. |
57a9b138 | 15829 | |
15830 | Floating and complex non-type template parameters have been deprecated, | |
ef8d967c | 15831 | and are now removed from G++. |
57a9b138 | 15832 | |
a77827f5 | 15833 | The implicit typename extension has been deprecated and is now |
ef8d967c | 15834 | removed from G++. |
a77827f5 | 15835 | |
d1c59264 | 15836 | The use of default arguments in function pointers, function typedefs |
a77827f5 | 15837 | and other places where they are not permitted by the standard is |
ef8d967c | 15838 | deprecated and will be removed from a future version of G++. |
4ea8b5e2 | 15839 | |
36f6aa5e | 15840 | G++ allows floating-point literals to appear in integral constant expressions, |
15841 | e.g. @samp{ enum E @{ e = int(2.2 * 3.7) @} } | |
15842 | This extension is deprecated and will be removed from a future version. | |
15843 | ||
15844 | G++ allows static data members of const floating-point type to be declared | |
15845 | with an initializer in a class definition. The standard only allows | |
15846 | initializers for static members of const integral types and const | |
15847 | enumeration types so this extension has been deprecated and will be removed | |
15848 | from a future version. | |
15849 | ||
64b04d50 | 15850 | @node Backwards Compatibility |
15851 | @section Backwards Compatibility | |
15852 | @cindex Backwards Compatibility | |
15853 | @cindex ARM [Annotated C++ Reference Manual] | |
15854 | ||
70c2c81c | 15855 | Now that there is a definitive ISO standard C++, G++ has a specification |
71d6ad5e | 15856 | to adhere to. The C++ language evolved over time, and features that |
64b04d50 | 15857 | used to be acceptable in previous drafts of the standard, such as the ARM |
71d6ad5e | 15858 | [Annotated C++ Reference Manual], are no longer accepted. In order to allow |
70c2c81c | 15859 | compilation of C++ written to such drafts, G++ contains some backwards |
71d6ad5e | 15860 | compatibilities. @emph{All such backwards compatibility features are |
70c2c81c | 15861 | liable to disappear in future versions of G++.} They should be considered |
e66bbea3 | 15862 | deprecated. @xref{Deprecated Features}. |
64b04d50 | 15863 | |
15864 | @table @code | |
15865 | @item For scope | |
15866 | If a variable is declared at for scope, it used to remain in scope until | |
15867 | the end of the scope which contained the for statement (rather than just | |
70c2c81c | 15868 | within the for scope). G++ retains this, but issues a warning, if such a |
64b04d50 | 15869 | variable is accessed outside the for scope. |
15870 | ||
57a9b138 | 15871 | @item Implicit C language |
8ae77b3c | 15872 | Old C system header files did not contain an @code{extern "C" @{@dots{}@}} |
71d6ad5e | 15873 | scope to set the language. On such systems, all header files are |
15874 | implicitly scoped inside a C language scope. Also, an empty prototype | |
64b04d50 | 15875 | @code{()} will be treated as an unspecified number of arguments, rather |
15876 | than no arguments, as C++ demands. | |
15877 | @end table |