### RTM Usage Example Source: https://devdocs.io/gcc/x86-transactional-memory-intrinsics An example demonstrating how to use _xbegin, _xend, and _xabort with retry logic and a fallback path. ```APIDOC ## RTM Usage Example ### Description This example shows how to handle `_XABORT_RETRY` and provides a fallback path for other failures. ### Code ```c #include int n_tries, max_tries; unsigned status = _XABORT_EXPLICIT; ... for (n_tries = 0; n_tries < max_tries; n_tries++) { status = _xbegin (); if (status == _XBEGIN_STARTED || !(status & _XABORT_RETRY)) break; } if (status == _XBEGIN_STARTED) { ... transaction code... _xend (); } else { ... non-transactional fallback path... } ``` ### Note In most cases, the transactional and non-transactional code must synchronize together to ensure consistency. ``` -------------------------------- ### Print GCC Installation Directories Source: https://devdocs.io/gcc/developer-options Useful for diagnosing 'installation problem, cannot exec cpp0' errors. Helps in locating compiler components or setting GCC_EXEC_PREFIX. ```bash gcc -print-search-dirs ``` -------------------------------- ### CPU Feature Check Example Source: https://devdocs.io/gcc/basic-powerpc-built_002din-functions-available-on-all-configurations Example demonstrating how to check for CPU support of specific features like FPU using __builtin_cpu_supports and falling back to software implementation if not supported. ```APIDOC ## CPU Feature Check Example ### Description This example shows how to conditionally use hardware instructions based on CPU support. If the `__builtin_cpu_supports` function indicates that the CPU supports the specified feature (e.g., "fpu"), it proceeds to use an assembly instruction. Otherwise, it falls back to a software implementation. ### Code ```c #ifdef __BUILTIN_CPU_SUPPORTS__ if (__builtin_cpu_supports ("fpu")) { asm("fadd %0,%1,%2" : "=d"(dst) : "d"(src1), "d"(src2)); } else #endif { dst = __fadd (src1, src2); // Software FP addition function. } ``` ``` -------------------------------- ### Example Usage of __lsx_vinsgr2vr_b Source: https://devdocs.io/gcc/loongarch-sx-vector-intrinsics Example showing how to use intrinsics where the intent operand is also the source operand. ```APIDOC ```c #include extern __m128i dst; extern int src; void test (void) { dst = __lsx_vinsgr2vr_b (dst, src, 3); } ``` ``` -------------------------------- ### Example: Wrapper for variadic printf function Source: https://devdocs.io/gcc/constructing-calls This example demonstrates using __builtin_va_arg_pack within an always_inline extern inline function to create a wrapper for a variadic function like printf. ```c extern int myprintf (FILE *f, const char *format, ...); extern inline __attribute__ ((__gnu_inline__)) int myprintf (FILE *f, const char *format, ...) { int r = fprintf (f, "myprintf: "); if (r < 0) return r; int s = fprintf (f, format, __builtin_va_arg_pack ()); if (s < 0) return s; return r + s; } ``` -------------------------------- ### Example Usage of __lsx_bz_v Source: https://devdocs.io/gcc/loongarch-sx-vector-intrinsics An example demonstrating the usage of the `__lsx_bz_v` intrinsic. ```APIDOC ```c #include extern __m128i a; void test (void) { if (__lsx_bz_v (a)) printf ("1\n"); else printf ("2\n"); } ``` ``` -------------------------------- ### Assembly Output Header Example Source: https://devdocs.io/gcc/code-gen-options The beginning of assembly output generated with -fverbose-asm, indicating the source file. ```assembly .file "test.c" ``` -------------------------------- ### Equivalent initialization of static objects Source: https://devdocs.io/gcc/compound-literals These examples show the equivalent initialization of static objects without using compound literals, illustrating the direct initialization syntax. ```c static struct foo x = {1, 'a', 'b'}; ``` ```c static int y[] = {1, 2, 3}; ``` ```c static int z[] = {1, 0, 0}; ``` -------------------------------- ### GCC Spec: Example of Conditional Substitutions Source: https://devdocs.io/gcc/spec-files Demonstrates combining file suffix and language conditions with alternatives for substitutions. ```gcc-spec %{.c:-foo} %{!.c:-bar} %{.c|d:-baz} %{!.c|d:-boggle} ``` -------------------------------- ### Basic Asm Example for i386 Source: https://devdocs.io/gcc/basic-asm This example demonstrates a basic asm statement for i386 architecture, defining a DebugBreak macro. Note that this specific code may not compile with the -masm=intel option. ```c /* Note that this code will not compile with -masm=intel */ #define DebugBreak() asm("int $3") ``` -------------------------------- ### Worked-out Fast Enumeration Example Source: https://devdocs.io/gcc/using-fast-enumeration This example demonstrates fast enumeration with `NSArray` and `NSString` using Foundation library functions like `NSArray` and `NSLog`. It iterates through an array of strings and prints each one. ```objective-c NSArray *array = [NSArray arrayWithObjects: @"1", @"2", @"3", nil]; NSString *object; for (object in array) NSLog (@"Iterating over %@", object); ``` -------------------------------- ### Array Type Encoding Example Source: https://devdocs.io/gcc/type-encoding Demonstrates the compiler encoding for an array of integers. ```objc int a[10]; ``` -------------------------------- ### _xbegin Source: https://devdocs.io/gcc/x86-transactional-memory-intrinsics Starts a Restricted Transactional Memory (RTM) transaction. Returns _XBEGIN_STARTED on success. On abort, it returns a bitmask indicating the reason for failure. ```APIDOC ## _xbegin ### Description Starts a RTM (Restricted Transactional Memory) transaction. Returns `_XBEGIN_STARTED` when the transaction started successfully (note this is not 0, so the constant has to be explicitly tested). If the transaction aborts, all side effects are undone and an abort code encoded as a bit mask is returned. ### Return Value - `_XBEGIN_STARTED` (unsigned): Indicates the transaction started successfully. - Abort code (bit mask): Encodes the reason for transaction failure. ``` -------------------------------- ### Example Usage of Comparison Functions Source: https://devdocs.io/gcc/paired_002dsingle-built_002din-functions Demonstrates how to use the upper and lower comparison built-in functions with a specific condition (e.g., equality). ```c v2sf a, b; if (__builtin_mips_upper_c_eq_ps (a, b)) upper_halves_are_equal (); else upper_halves_are_unequal (); if (__builtin_mips_lower_c_eq_ps (a, b)) lower_halves_are_equal (); else lower_halves_are_unequal (); ``` -------------------------------- ### JSON Path Array Example Source: https://devdocs.io/gcc/diagnostic-message-formatting-options Demonstrates the structure of the 'path' array within a JSON diagnostic, representing control-flow events. ```json "path": [ { "depth": 0, "description": "when 'PyList_New' fails, returning NULL", "function": "test", "location": { "column": 10, "file": "test.c", "line": 25 } }, { "depth": 0, "description": "when 'i < count'", "function": "test", "location": { "column": 3, "file": "test.c", "line": 27 } }, { "depth": 0, "description": "when calling 'PyList_Append', passing NULL from (1) as argument 1", "function": "test", "location": { "column": 5, "file": "test.c", "line": 29 } } ] ``` -------------------------------- ### Example Usage of __lasx_xbz_v Source: https://devdocs.io/gcc/loongarch-asx-vector-intrinsics Demonstrates the usage of the __lasx_xbz_v intrinsic function, which checks if all elements in a vector are zero. Requires including ``. ```c #include extern __m256i a; void test (void) { if (__lasx_xbz_v (a)) printf ("1\n"); else printf ("2\n"); } ``` -------------------------------- ### Transparent Union Function Implementation Source: https://devdocs.io/gcc/common-type-attributes Provides an example implementation of a function accepting a transparent union, showing how to access the union members for argument passing. ```c pid_t wait (wait_status_ptr_t p) { return waitpid (-1, p.__ip, 0); } ``` -------------------------------- ### Example of Error with Caret and Range Highlighting Source: https://devdocs.io/gcc/diagnostic-message-formatting-options Demonstrates an error message with caret and range highlighting using tildes and pipes, indicating specific code locations. ```text bad-binary-ops.c:64:23: error: invalid operands to binary + (have 'S' {aka 'struct s'} and 'T' {aka 'struct t'}) 64 | return callee_4a () + callee_4b (); | ~~~~~~~~~~~~ ^ ~~~~~~~~~~~~ | | | | | T {aka struct t} | S {aka struct s} ``` -------------------------------- ### GCC Binary Constant Example Source: https://devdocs.io/gcc/binary-constants Demonstrates the equivalence of decimal, hexadecimal, octal, and binary integer constants in GCC. This is particularly useful for bit-level operations. ```c i = 42; i = 0x2a; i = 052; i = 0b101010; ``` -------------------------------- ### Fixed-Point Arithmetic with stdfix.h Source: https://devdocs.io/gcc/avr-built_002din-functions Example of re-interpreting bits of an unsigned integer as a Q-format fixed-point value using urbits from stdfix.h. This demonstrates using built-ins indirectly. ```c #include // Re-interpret the bit representation of unsigned 16-bit // integer uval as Q-format 0.16 value. unsigned fract get_bits (uint_ur_t uval) { return urbits (uval); } ``` -------------------------------- ### Display Options by Class and Qualifier Source: https://devdocs.io/gcc/overall-options Use --help= followed by classes and qualifiers to display specific command-line options. Supported classes include 'optimizers', 'warnings', 'target', 'params', and language names. Qualifiers like 'undocumented', 'joined', and 'separate' further refine the output. ```bash --help=optimizers ``` ```bash --help=warnings ``` ```bash --help=target ``` ```bash --help=params ``` ```bash --help=common ``` ```bash --help=undocumented ``` ```bash --help=joined ``` ```bash --help=separate ``` ```bash --help=c ``` ```bash --help=c++ ``` ```bash --help=undocumented,target ``` ```bash --help=joined,separate ``` -------------------------------- ### Align Function Start Source: https://devdocs.io/gcc/optimize-options Aligns the start of functions to a specified power-of-two boundary to improve instruction fetching performance. Alignment is ignored for cold functions. ```c -falign-functions=32 ``` ```c -falign-functions=24 ``` ```c -falign-functions=32:7 ``` ```c -falign-functions=64:7:32:3 ``` -------------------------------- ### Example: Runtime checking of open arguments Source: https://devdocs.io/gcc/constructing-calls This example shows how __builtin_va_arg_pack_len and __builtin_constant_p can be used for runtime checking of arguments in an always_inline extern inline function, specifically for the 'open' function. ```c #ifdef __OPTIMIZE__ extern inline __attribute__((__gnu_inline__)) int myopen (const char *path, int oflag, ...) { if (__builtin_va_arg_pack_len () > 1) warn_open_too_many_arguments (); if (__builtin_constant_p (oflag)) { if ((oflag & O_CREAT) != 0 && __builtin_va_arg_pack_len () < 1) { warn_open_missing_mode (); return __open_2 (path, oflag); } return open (path, oflag, __builtin_va_arg_pack ()); } if (__builtin_va_arg_pack_len () < 1) return __open_2 (path, oflag); return open (path, oflag, __builtin_va_arg_pack ()); } #endif ``` -------------------------------- ### Correct Initialization with +load Source: https://devdocs.io/gcc/executing-code-before-main This example shows the correct way to initialize global variables before main() using the +load method. This ensures that variables like Stdin, Stdout, and Stderr are initialized before any messages are sent to them. ```objectivec @implementation FileStream + (void)load { Stdin = [[FileStream new] initWithFd:0]; Stdout = [[FileStream new] initWithFd:1]; Stderr = [[FileStream new] initWithFd:2]; } /* Other methods here */ @end ``` -------------------------------- ### Specify System Startup File Source: https://devdocs.io/gcc/nios-ii-options Specifies the crt0 startfile for linking. Only useful with -mhal. ```bash -msys-crt0=startfile ``` -------------------------------- ### Fortify Source Macro for memcpy Source: https://devdocs.io/gcc/object-size-checking This example demonstrates how to use the _FORTIFY_SOURCE macro with a custom memcpy implementation using __builtin___memcpy_chk. It shows different scenarios for compile-time and run-time overflow checking. ```c #undef memcpy #define bos0(dest) __builtin_object_size (dest, 0) #define memcpy(dest, src, n) \ __builtin___memcpy_chk (dest, src, n, bos0 (dest)) char *volatile p; char buf[10]; /* It is unknown what object p points to, so this is optimized into plain memcpy - no checking is possible. */ memcpy (p, "abcde", n); /* Destination is known and length too. It is known at compile time there will be no overflow. */ memcpy (&buf[5], "abcde", 5); /* Destination is known, but the length is not known at compile time. This will result in __memcpy_chk call that can check for overflow at run time. */ memcpy (&buf[5], "abcde", n); /* Destination is known and it is known at compile time there will be overflow. There will be a warning and __memcpy_chk call that will abort the program at run time. */ memcpy (&buf[6], "abcde", 5); ``` -------------------------------- ### Initializer list lifetime warning example (C++) Source: https://devdocs.io/gcc/c_002b_002b-dialect-options This example demonstrates potential dangling pointer issues with std::initializer_list due to temporary array lifetimes. The warning is disabled by -Wno-init-list-lifetime. ```c++ // li's initial underlying array lives as long as li std::initializer_list li = { 1,2,3 }; // assignment changes li to point to a temporary array li = { 4, 5 }; // now the temporary is gone and li has a dangling pointer int i = li.begin()[0] // undefined behavior ``` -------------------------------- ### RS/6000 and PowerPC Options - Prototype and Simulation Source: https://devdocs.io/gcc/option-summary Options for RS/6000 and PowerPC to control function prototypes and simulation modes. ```bash -mprototype -mno-prototype -msim -mmvme -mads -myellowknife -memb -msdata ``` -------------------------------- ### Compiling and inspecting app.c with coverage Source: https://devdocs.io/gcc/freestanding-environments Demonstrates compiling `app.c` with the `--coverage` flag and using `nm` to inspect the resulting object file. This reveals the presence of gcov-related symbols and functions. ```bash $ gcc --coverage -c app.c $ nm app.o 0000000000000000 r a 0000000000000030 T application 0000000000000000 t can_decode U fgetc U fputc 0000000000000000 b __gcov0.application 0000000000000038 b __gcov0.can_decode 0000000000000000 d __gcov_.application 00000000000000c0 d __gcov_.can_decode U __gcov_exit U __gcov_init U __gcov_merge_add U stdin U stdout 0000000000000161 t _sub_D_00100_1 0000000000000151 t _sub_I_00100_0 ``` -------------------------------- ### Conditional memcpy using CPU Features Source: https://devdocs.io/gcc/x86-built_002din-functions Example demonstrating how to use `__builtin_cpu_init` and `__builtin_cpu_supports` within an ifunc resolver to select an optimized memcpy implementation based on CPU features like SSSE3. ```c static void (*resolve_memcpy (void)) (void) { // ifunc resolvers fire before constructors, explicitly call the init // function. __builtin_cpu_init (); if (__builtin_cpu_supports ("ssse3")) return ssse3_memcpy; // super fast memcpy with ssse3 instructions. else return default_memcpy; } void *memcpy (void *, const void *, size_t) __attribute__ ((ifunc ("resolve_memcpy"))); ``` -------------------------------- ### GCC 'asm goto' with i386 example Source: https://devdocs.io/gcc/extended-asm Demonstrates 'asm goto' for i386, using positional label referencing and the 'cc' clobber. Ensure 'cc' is clobbered if the assembly modifies condition codes. ```c asm goto ( "btl %1, %0\n\t" "jc %l2" : /* No outputs. */ : "r" (p1), "r" (p2) : "cc" : carry); return 0; carry: return 1; ``` -------------------------------- ### C++ Function Name Example Source: https://devdocs.io/gcc/function-names This C++ example demonstrates the usage of __FUNCTION__ and __PRETTY_FUNCTION__ within a class method. __FUNCTION__ outputs the bare function name, while __PRETTY_FUNCTION__ includes the full signature. ```cpp extern "C" int printf (const char *, ...); class a { public: void sub (int i) { printf ("__FUNCTION__ = %s\n", __FUNCTION__); printf ("__PRETTY_FUNCTION__ = %s\n", __PRETTY_FUNCTION__); } }; int main (void) { a ax; ax.sub (0); return 0; } ``` -------------------------------- ### C++ ABI Mangling Issue Example Source: https://devdocs.io/gcc/warning-options Demonstrates a C++ ABI mangling issue with non-type template parameters of reference type, which was fixed in -fabi-version=3. This example highlights a specific incompatibility that -Wabi can help detect. ```c++ extern int N; template struct S {}; void n (S) {2} ``` -------------------------------- ### Display Specific Help Information Source: https://devdocs.io/gcc/overall-options Use --help= with qualifiers to filter the displayed help information. Qualifiers can be inverted with '^'. Combining classes can restrict output, but 'target,optimizers' shows target-specific optimization options. ```bash --help=target,undocumented ``` ```bash --help=warnings,^joined,^undocumented ``` ```bash --help=target,optimizers ``` -------------------------------- ### S/390 Target Function Attribute Example Source: https://devdocs.io/gcc/s_002f390-function-attributes The 'target' attribute allows specifying target-specific compilation options. This example shows how to disable vector instructions ('vx') for S/390, which works like the command-line option but does not undefine feature macros. ```c target("no-vx") ``` -------------------------------- ### Atomic Fetch-and-Op Examples Source: https://devdocs.io/gcc/_005f_005fatomic-builtins These snippets illustrate the conceptual operations performed by atomic fetch-and-modify built-ins. The first shows a generic fetch-and-add/subtract, while the second demonstrates the specific logic for a fetch-and-nand operation. ```c { tmp = *ptr; *ptr op= val; return tmp; } ``` ```c { tmp = *ptr; *ptr = ~(*ptr & val); return tmp; } // nand ``` -------------------------------- ### Display Compiler Command-Line Options Source: https://devdocs.io/gcc/overall-options Use --help to print a description of the command-line options understood by GCC to standard output. If -v is also specified, --help is passed to invoked processes. ```bash gcc --help ``` -------------------------------- ### Simple i386 Extended Asm Example Source: https://devdocs.io/gcc/extended-asm A basic example demonstrating how to copy a C variable to another and increment it using i386 assembly instructions within an extended asm statement. Ensure the `asm` statement is placed inside a function. ```c int src = 1; int dst; asm ("mov %1, %0\n\t" "add $1, %0" : "=r" (dst) : "r" (src)); printf("%d\n", dst); ``` -------------------------------- ### C++ Implicit Copy-Assignment with Virtual Bases Example Source: https://devdocs.io/gcc/copy-assignment Demonstrates a scenario where implicit copy-assignment for a Derived class with virtual base inheritance might lead to unspecified behavior. This example is useful for understanding potential issues when assigning objects with virtual bases. ```cpp struct Base{ char *name; Base(const char *n) : name(strdup(n)){} Base& operator= (const Base& other){ free (name); name = strdup (other.name); return *this; } }; struct A:virtual Base{ int val; A():Base("A"){} }; struct B:virtual Base{ int bval; B():Base("B"){} }; struct Derived:public A, public B{ Derived():Base("Derived"){} }; void func(Derived &d1, Derived &d2) { d1 = d2; } ``` -------------------------------- ### Start RTM Transaction and Check Status Source: https://devdocs.io/gcc/x86-transactional-memory-intrinsics Starts a Restricted Transactional Memory (RTM) transaction. It returns _XBEGIN_STARTED on success. If the transaction aborts, it returns a bitmask indicating the reason, such as _XABORT_RETRY, _XABORT_CONFLICT, etc. A fallback path is essential as transactions may not always succeed. ```c #include int n_tries, max_tries; unsigned status = _XABORT_EXPLICIT; ... for (n_tries = 0; n_tries < max_tries; n_tries++) { status = _xbegin (); if (status == _XBEGIN_STARTED || !(status & _XABORT_RETRY)) break; } if (status == _XBEGIN_STARTED) { ... transaction code... _xend (); } else { ... non-transactional fallback path... } ``` -------------------------------- ### Compile a Header File for Precompilation Source: https://devdocs.io/gcc/precompiled-headers Compile a header file as a C or C++ header using the -x option. This is the first step in creating a precompiled header. ```bash gcc -x c-header-cpp-output all.h.gch all.h ``` -------------------------------- ### Print libgcc File Name Source: https://devdocs.io/gcc/developer-options Use this when linking with libgcc.a is necessary, especially with -nostdlib or -nodefaultlibs. ```bash gcc -nostdlib files… `gcc -print-libgcc-file-name` ``` -------------------------------- ### __builtin_extract_return_addr Source: https://devdocs.io/gcc/return-address Processes the address returned by `__builtin_return_address` to get the actual encoded address. ```APIDOC ## __builtin_extract_return_addr ### Description The address as returned by `__builtin_return_address` may have to be fed through this function to get the actual encoded address. For example, on the 31-bit S/390 platform the highest bit has to be masked out, or on SPARC platforms an offset has to be added for the true next instruction to be executed. ### Signature `void * __builtin_extract_return_addr(void *addr)` ### Parameters * **addr** (void *) - The address returned by `__builtin_return_address`. ### Notes * If no fixup is needed, this function simply passes through `addr`. ``` -------------------------------- ### RX Options - Simulation and Syntax Source: https://devdocs.io/gcc/option-summary RX options for simulation modes and assembler syntax. ```bash -msim -mno-sim -mas100-syntax -mno-as100-syntax ``` -------------------------------- ### DMA Setup and Write Operations Source: https://devdocs.io/gcc/arc-simd-built_002din-functions Functions for configuring and writing to DMA channels. ```APIDOC ## __builtin_arc_vdirun ### Description Initiates a DMA run operation. ### Signature `void __builtin_arc_vdirun (int, int)` ## __builtin_arc_vdorun ### Description Initiates a DMA run operation. ### Signature `void __builtin_arc_vdorun (int, int)` ## __builtin_arc_vdiwr ### Description Writes to a DMA channel. ### Signature `void __builtin_arc_vdiwr (const int, int)` ## __builtin_arc_vdowr ### Description Writes to a DMA channel. ### Signature `void __builtin_arc_vdowr (const int, int)` ``` -------------------------------- ### Suppress Comma Subscript Warning Source: https://devdocs.io/gcc/c_002b_002b-dialect-options Example of how to suppress the -Wcomma-subscript warning using a pragma. ```c++ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wno-comma-subscript" // Code that might trigger the warning #pragma GCC diagnostic pop ``` -------------------------------- ### vec_extracth Source: https://devdocs.io/gcc/powerpc-altivec-built_002din-functions-available-on-isa-3_002e1 Extracts an element from two concatenated vectors starting at a given byte index. ```APIDOC ## vec_extracth ### Description Extract an element from two concatenated vectors starting at the given byte index in natural-endian order, and place it zero-extended in doubleword 1 of the result according to natural element order. If the byte index is out of range for the data type, the intrinsic will be rejected. For little-endian, this output will match the placement by the hardware instruction, i.e., dword[0] in RTL notation. For big-endian, an additional instruction is needed to move it from the "left" doubleword to the "right" one. For little-endian, semantics matching the `vextdubvrx`, `vextduhvrx`, `vextduwvrx` instruction will be generated, while for big-endian, semantics matching the `vextdubvlx`, `vextduhvlx`, `vextduwvlx` instructions will be generated. Note that some fairly anomalous results can be generated if the byte index is not aligned on an element boundary for the element being extracted. This is a limitation of the bi-endian vector programming model is consistent with the limitation on `vec_perm`. ### Signatures ```c vector unsigned long long int vec_extracth(vector unsigned char, vector unsigned char, unsigned int); vector unsigned long long int vec_extracth(vector unsigned short, vector unsigned short, unsigned int); vector unsigned long long int vec_extracth(vector unsigned int, vector unsigned int, unsigned int); vector unsigned long long int vec_extracth(vector unsigned long long, vector unsigned long long, unsigned int); ``` ``` -------------------------------- ### Query Enabled Optimizations Source: https://devdocs.io/gcc/overall-options Use -Q with --help=optimizers to discover which optimizations are enabled at a specific optimization level, such as -O2 or -O3. Comparing outputs with diff can highlight differences. ```bash -Q -O2 --help=optimizers ``` ```bash gcc -c -Q -O3 --help=optimizers > /tmp/O3-opts gcc -c -Q -O2 --help=optimizers > /tmp/O2-opts diff /tmp/O2-opts /tmp/O3-opts | grep enabled ``` -------------------------------- ### vec_extractl Source: https://devdocs.io/gcc/powerpc-altivec-built_002din-functions-available-on-isa-3_002e1 Extracts an element from two concatenated vectors starting at a given byte index. ```APIDOC ## vec_extractl ### Description Extract an element from two concatenated vectors starting at the given byte index in natural-endian order, and place it zero-extended in doubleword 1 of the result according to natural element order. If the byte index is out of range for the data type, the intrinsic will be rejected. For little-endian, this output will match the placement by the hardware instruction, i.e., dword[0] in RTL notation. For big-endian, an additional instruction is needed to move it from the "left" doubleword to the "right" one. For little-endian, semantics matching the `vextdubvrx`, `vextduhvrx`, `vextduwvrx` instruction will be generated, while for big-endian, semantics matching the `vextdubvlx`, `vextduhvlx`, `vextduwvlx` instructions will be generated. Note that some fairly anomalous results can be generated if the byte index is not aligned on an element boundary for the element being extracted. This is a limitation of the bi-endian vector programming model is consistent with the limitation on `vec_perm`. ### Signatures ```c vector unsigned long long int vec_extractl(vector unsigned char, vector unsigned char, unsigned int); vector unsigned long long int vec_extractl(vector unsigned short, vector unsigned short, unsigned int); vector unsigned long long int vec_extractl(vector unsigned int, vector unsigned int, unsigned int); vector unsigned long long int vec_extractl(vector unsigned long long, vector unsigned long long, unsigned int); ``` ``` -------------------------------- ### Compile C code with Verbose Assembly and Optimization Source: https://devdocs.io/gcc/code-gen-options Example of compiling a C source file with -fverbose-asm for detailed assembly output and -Os for size optimization, directing output to stdout. ```gcc gcc -S test.c -fverbose-asm -Os -o - ``` -------------------------------- ### Vector Type Encoding Example Source: https://devdocs.io/gcc/type-encoding Shows the compiler encoding for a vector type, where alignment depends on the machine. ```objc int a __attribute__ ((vector_size (16))); ``` -------------------------------- ### Enable lwxc1/swxc1/ldxc1/sdxc1 Instructions Source: https://devdocs.io/gcc/mips-options When applicable, use this option to enable the generation of `lwxc1`, `swxc1`, `ldxc1`, and `sdxc1` instructions. This is enabled by default. ```bash -mmadd4 ``` -------------------------------- ### RS/6000 and PowerPC Options - Call Conventions Source: https://devdocs.io/gcc/option-summary Options for RS/6000 and PowerPC to specify different call conventions. ```bash -mcall-aixdesc -mcall-eabi -mcall-freebsd -mcall-linux -mcall-netbsd -mcall-openbsd -mcall-sysv -mcall-sysv-eabi -mcall-sysv-noeabi ``` -------------------------------- ### C Source Code Example Source: https://devdocs.io/gcc/code-gen-options A simple C function that calculates the sum of squares up to a given number. ```c int test (int n) { int i; int total = 0; for (i = 0; i < n; i++) total += i * i; return total; } ``` -------------------------------- ### __builtin_tbeginc Source: https://devdocs.io/gcc/s_002f390-system-z-built_002din-functions Generates the `tbeginc` machine instruction to start a constrained hardware transaction. This function does not take any arguments. ```APIDOC ## __builtin_tbeginc ### Description Generates the `tbeginc` machine instruction to start a constrained hardware transaction. The second operand for `tbeginc` is fixed to `0xff08`. ### Function Signature `void __builtin_tbeginc(void)` ### Parameters None. ### Return Value None. ``` -------------------------------- ### S/390 and zSeries Options - Tune, March, and Float Source: https://devdocs.io/gcc/option-summary Options for S/390 and zSeries to specify CPU tuning, architecture, and floating-point support. ```bash -mtune=cpu-type -march=cpu-type -mhard-float -msoft-float -mhard-dfp -mno-hard-dfp ``` -------------------------------- ### Get ARM FPSCR Source: https://devdocs.io/gcc/arm-floating-point-status-and-control-intrinsics Use this intrinsic to retrieve the current value of the Floating-Point Status and Control Register (FPSCR). ```c unsigned int __builtin_arm_get_fpscr (); ``` -------------------------------- ### GCC Optimization Report for Vectorizer and Loop Passes Source: https://devdocs.io/gcc/developer-options This example demonstrates specifying separate output files for missed vectorization opportunities and optimized loop information. Note that only the first output file will be used if multiple are specified due to a conflict. ```bash gcc -fopt-info-vec-missed=vec.miss -fopt-info-loop-optimized=loop.opt ``` -------------------------------- ### typeof with a type name Source: https://devdocs.io/gcc/typeof Use typeof with a type name to describe that type. This example describes the type of pointers to int. ```c typeof (int *) ```