| <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
| <html> |
| <!-- Copyright (C) 1988-2015 Free Software Foundation, Inc. |
| |
| Permission is granted to copy, distribute and/or modify this document |
| under the terms of the GNU Free Documentation License, Version 1.3 or |
| any later version published by the Free Software Foundation; with the |
| Invariant Sections being "Funding Free Software", the Front-Cover |
| Texts being (a) (see below), and with the Back-Cover Texts being (b) |
| (see below). A copy of the license is included in the section entitled |
| "GNU Free Documentation License". |
| |
| (a) The FSF's Front-Cover Text is: |
| |
| A GNU Manual |
| |
| (b) The FSF's Back-Cover Text is: |
| |
| You have freedom to copy and modify this GNU Manual, like GNU |
| software. Copies published by the Free Software Foundation raise |
| funds for GNU development. --> |
| <!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ --> |
| <head> |
| <title>Using the GNU Compiler Collection (GCC): x86 transactional memory intrinsics</title> |
| |
| <meta name="description" content="Using the GNU Compiler Collection (GCC): x86 transactional memory intrinsics"> |
| <meta name="keywords" content="Using the GNU Compiler Collection (GCC): x86 transactional memory intrinsics"> |
| <meta name="resource-type" content="document"> |
| <meta name="distribution" content="global"> |
| <meta name="Generator" content="makeinfo"> |
| <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| <link href="index.html#Top" rel="start" title="Top"> |
| <link href="Option-Index.html#Option-Index" rel="index" title="Option Index"> |
| <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents"> |
| <link href="Target-Builtins.html#Target-Builtins" rel="up" title="Target Builtins"> |
| <link href="Target-Format-Checks.html#Target-Format-Checks" rel="next" title="Target Format Checks"> |
| <link href="x86-Built_002din-Functions.html#x86-Built_002din-Functions" rel="prev" title="x86 Built-in Functions"> |
| <style type="text/css"> |
| <!-- |
| a.summary-letter {text-decoration: none} |
| blockquote.smallquotation {font-size: smaller} |
| div.display {margin-left: 3.2em} |
| div.example {margin-left: 3.2em} |
| div.indentedblock {margin-left: 3.2em} |
| div.lisp {margin-left: 3.2em} |
| div.smalldisplay {margin-left: 3.2em} |
| div.smallexample {margin-left: 3.2em} |
| div.smallindentedblock {margin-left: 3.2em; font-size: smaller} |
| div.smalllisp {margin-left: 3.2em} |
| kbd {font-style:oblique} |
| pre.display {font-family: inherit} |
| pre.format {font-family: inherit} |
| pre.menu-comment {font-family: serif} |
| pre.menu-preformatted {font-family: serif} |
| pre.smalldisplay {font-family: inherit; font-size: smaller} |
| pre.smallexample {font-size: smaller} |
| pre.smallformat {font-family: inherit; font-size: smaller} |
| pre.smalllisp {font-size: smaller} |
| span.nocodebreak {white-space:nowrap} |
| span.nolinebreak {white-space:nowrap} |
| span.roman {font-family:serif; font-weight:normal} |
| span.sansserif {font-family:sans-serif; font-weight:normal} |
| ul.no-bullet {list-style: none} |
| --> |
| </style> |
| |
| |
| </head> |
| |
| <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000"> |
| <a name="x86-transactional-memory-intrinsics"></a> |
| <div class="header"> |
| <p> |
| Previous: <a href="x86-Built_002din-Functions.html#x86-Built_002din-Functions" accesskey="p" rel="prev">x86 Built-in Functions</a>, Up: <a href="Target-Builtins.html#Target-Builtins" accesskey="u" rel="up">Target Builtins</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p> |
| </div> |
| <hr> |
| <a name="x86-Transactional-Memory-Intrinsics"></a> |
| <h4 class="subsection">6.58.31 x86 Transactional Memory Intrinsics</h4> |
| |
| <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>-mrtm</samp> option. |
| For using HLE (Hardware Lock Elision) see |
| <a href="x86-specific-memory-model-extensions-for-transactional-memory.html#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> |
| <dt><a name="index-_005fxbegin"></a>RTM Function: <em>unsigned</em> <strong>_xbegin</strong> <em>()</em></dt> |
| <dd><p>Start a RTM (Restricted Transactional Memory) transaction. |
| Returns <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 compact="compact"> |
| <dt><code>_XABORT_EXPLICIT</code></dt> |
| <dd><p>Transaction was explicitly aborted with <code>_xabort</code>. The parameter passed |
| to <code>_xabort</code> is available with <code>_XABORT_CODE(status)</code>. |
| </p></dd> |
| <dt><code>_XABORT_RETRY</code></dt> |
| <dd><p>Transaction retry is possible. |
| </p></dd> |
| <dt><code>_XABORT_CONFLICT</code></dt> |
| <dd><p>Transaction abort due to a memory conflict with another thread. |
| </p></dd> |
| <dt><code>_XABORT_CAPACITY</code></dt> |
| <dd><p>Transaction abort due to the transaction using too much memory. |
| </p></dd> |
| <dt><code>_XABORT_DEBUG</code></dt> |
| <dd><p>Transaction abort due to a debug trap. |
| </p></dd> |
| <dt><code>_XABORT_NESTED</code></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> |
| <dt><a name="index-_005fxend"></a>RTM Function: <em>void</em> <strong>_xend</strong> <em>()</em></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> |
| <dt><a name="index-_005fxtest"></a>RTM Function: <em>int</em> <strong>_xtest</strong> <em>()</em></dt> |
| <dd><p>Return a nonzero value if a transaction is currently active, otherwise 0. |
| </p></dd></dl> |
| |
| <dl> |
| <dt><a name="index-_005fxabort"></a>RTM Function: <em>void</em> <strong>_xabort</strong> <em>(status)</em></dt> |
| <dd><p>Abort the current transaction. When no transaction is active this is a no-op. |
| The <var>status</var> is an 8-bit constant; its value is encoded in the return |
| value from <code>_xbegin</code>. |
| </p></dd></dl> |
| |
| <p>Here is an example showing handling for <code>_XABORT_RETRY</code> |
| and a fallback path for other failures: |
| </p> |
| <div class="smallexample"> |
| <pre class="smallexample">#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> |
| <hr> |
| <div class="header"> |
| <p> |
| Previous: <a href="x86-Built_002din-Functions.html#x86-Built_002din-Functions" accesskey="p" rel="prev">x86 Built-in Functions</a>, Up: <a href="Target-Builtins.html#Target-Builtins" accesskey="u" rel="up">Target Builtins</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p> |
| </div> |
| |
| |
| |
| </body> |
| </html> |