diff options
| author | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
| commit | 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch) | |
| tree | f1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/gcc~13/x86-transactional-memory-intrinsics.html | |
new repository
Diffstat (limited to 'devdocs/gcc~13/x86-transactional-memory-intrinsics.html')
| -rw-r--r-- | devdocs/gcc~13/x86-transactional-memory-intrinsics.html | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/devdocs/gcc~13/x86-transactional-memory-intrinsics.html b/devdocs/gcc~13/x86-transactional-memory-intrinsics.html new file mode 100644 index 00000000..9572c6d7 --- /dev/null +++ b/devdocs/gcc~13/x86-transactional-memory-intrinsics.html @@ -0,0 +1,59 @@ +<div class="subsection-level-extent" id="x86-transactional-memory-intrinsics"> <div class="nav-panel"> <p> Next: <a href="x86-control-flow-protection-intrinsics" accesskey="n" rel="next">x86 Control-Flow Protection Intrinsics</a>, Previous: <a href="x86-built-in-functions" accesskey="p" rel="prev">x86 Built-in Functions</a>, Up: <a href="target-builtins" accesskey="u" rel="up">Built-in Functions Specific to Particular Target Machines</a> [<a href="index#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="indices" title="Index" rel="index">Index</a>]</p> </div> <h1 class="subsection" id="x86-Transactional-Memory-Intrinsics"><span>6.60.36 x86 Transactional Memory Intrinsics<a class="copiable-link" href="#x86-Transactional-Memory-Intrinsics"> ¶</a></span></h1> <p>These hardware transactional memory intrinsics for x86 allow you to use memory transactions with RTM (Restricted Transactional Memory). This support is enabled with the <samp class="option">-mrtm</samp> option. For using HLE (Hardware Lock Elision) see <a class="ref" href="x86-specific-memory-model-extensions-for-transactional-memory">x86-Specific Memory Model Extensions for Transactional Memory</a> instead. </p> <p>A memory transaction commits all changes to memory in an atomic way, as visible to other threads. If the transaction fails it is rolled back and all side effects discarded. </p> <p>Generally there is no guarantee that a memory transaction ever succeeds and suitable fallback code always needs to be supplied. </p> <dl class="first-deftypefn"> <dt class="deftypefn" id="index-_005fxbegin"> +<span class="category-def">RTM Function: </span><span><code class="def-type">unsigned</code> <strong class="def-name">_xbegin</strong> <code class="def-code-arguments">()</code><a class="copiable-link" href="#index-_005fxbegin"> ¶</a></span> +</dt> <dd> +<p>Start a RTM (Restricted Transactional Memory) transaction. Returns <code class="code">_XBEGIN_STARTED</code> when the transaction started successfully (note this is not 0, so the constant has to be explicitly tested). </p> <p>If the transaction aborts, all side effects are undone and an abort code encoded as a bit mask is returned. The following macros are defined: </p> <dl class="first-deffn first-defmac-alias-first-deffn"> <dt class="deffn defmac-alias-deffn" id="index-_005fXABORT_005fEXPLICIT"> +<span class="category-def">Macro: </span><span><strong class="def-name">_XABORT_EXPLICIT</strong><a class="copiable-link" href="#index-_005fXABORT_005fEXPLICIT"> ¶</a></span> +</dt> <dd><p>Transaction was explicitly aborted with <code class="code">_xabort</code>. The parameter passed to <code class="code">_xabort</code> is available with <code class="code">_XABORT_CODE(status)</code>. </p></dd> +</dl> <dl class="first-deffn first-defmac-alias-first-deffn"> <dt class="deffn defmac-alias-deffn" id="index-_005fXABORT_005fRETRY"> +<span class="category-def">Macro: </span><span><strong class="def-name">_XABORT_RETRY</strong><a class="copiable-link" href="#index-_005fXABORT_005fRETRY"> ¶</a></span> +</dt> <dd><p>Transaction retry is possible. </p></dd> +</dl> <dl class="first-deffn first-defmac-alias-first-deffn"> <dt class="deffn defmac-alias-deffn" id="index-_005fXABORT_005fCONFLICT"> +<span class="category-def">Macro: </span><span><strong class="def-name">_XABORT_CONFLICT</strong><a class="copiable-link" href="#index-_005fXABORT_005fCONFLICT"> ¶</a></span> +</dt> <dd><p>Transaction abort due to a memory conflict with another thread. </p></dd> +</dl> <dl class="first-deffn first-defmac-alias-first-deffn"> <dt class="deffn defmac-alias-deffn" id="index-_005fXABORT_005fCAPACITY"> +<span class="category-def">Macro: </span><span><strong class="def-name">_XABORT_CAPACITY</strong><a class="copiable-link" href="#index-_005fXABORT_005fCAPACITY"> ¶</a></span> +</dt> <dd><p>Transaction abort due to the transaction using too much memory. </p></dd> +</dl> <dl class="first-deffn first-defmac-alias-first-deffn"> <dt class="deffn defmac-alias-deffn" id="index-_005fXABORT_005fDEBUG"> +<span class="category-def">Macro: </span><span><strong class="def-name">_XABORT_DEBUG</strong><a class="copiable-link" href="#index-_005fXABORT_005fDEBUG"> ¶</a></span> +</dt> <dd><p>Transaction abort due to a debug trap. </p></dd> +</dl> <dl class="first-deffn first-defmac-alias-first-deffn"> <dt class="deffn defmac-alias-deffn" id="index-_005fXABORT_005fNESTED"> +<span class="category-def">Macro: </span><span><strong class="def-name">_XABORT_NESTED</strong><a class="copiable-link" href="#index-_005fXABORT_005fNESTED"> ¶</a></span> +</dt> <dd><p>Transaction abort in an inner nested transaction. </p></dd> +</dl> <p>There is no guarantee any transaction ever succeeds, so there always needs to be a valid fallback path. </p> +</dd> +</dl> <dl class="first-deftypefn"> <dt class="deftypefn" id="index-_005fxend"> +<span class="category-def">RTM Function: </span><span><code class="def-type">void</code> <strong class="def-name">_xend</strong> <code class="def-code-arguments">()</code><a class="copiable-link" href="#index-_005fxend"> ¶</a></span> +</dt> <dd><p>Commit the current transaction. When no transaction is active this faults. All memory side effects of the transaction become visible to other threads in an atomic manner. </p></dd> +</dl> <dl class="first-deftypefn"> <dt class="deftypefn" id="index-_005fxtest"> +<span class="category-def">RTM Function: </span><span><code class="def-type">int</code> <strong class="def-name">_xtest</strong> <code class="def-code-arguments">()</code><a class="copiable-link" href="#index-_005fxtest"> ¶</a></span> +</dt> <dd><p>Return a nonzero value if a transaction is currently active, otherwise 0. </p></dd> +</dl> <dl class="first-deftypefn"> <dt class="deftypefn" id="index-_005fxabort"> +<span class="category-def">RTM Function: </span><span><code class="def-type">void</code> <strong class="def-name">_xabort</strong> <code class="def-code-arguments">(status)</code><a class="copiable-link" href="#index-_005fxabort"> ¶</a></span> +</dt> <dd><p>Abort the current transaction. When no transaction is active this is a no-op. The <var class="var">status</var> is an 8-bit constant; its value is encoded in the return value from <code class="code">_xbegin</code>. </p></dd> +</dl> <p>Here is an example showing handling for <code class="code">_XABORT_RETRY</code> and a fallback path for other failures: </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">#include <immintrin.h> + +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... + }</pre> +</div> <p>Note that, in most cases, the transactional and non-transactional code must synchronize together to ensure consistency. </p> </div> <div class="nav-panel"> <p> Next: <a href="x86-control-flow-protection-intrinsics">x86 Control-Flow Protection Intrinsics</a>, Previous: <a href="x86-built-in-functions">x86 Built-in Functions</a>, Up: <a href="target-builtins">Built-in Functions Specific to Particular Target Machines</a> [<a href="index#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="indices" title="Index" rel="index">Index</a>]</p> </div><div class="_attribution"> + <p class="_attribution-p"> + © Free Software Foundation<br>Licensed under the GNU Free Documentation License, Version 1.3.<br> + <a href="https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/x86-transactional-memory-intrinsics.html" class="_attribution-link">https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/x86-transactional-memory-intrinsics.html</a> + </p> +</div> |
