blob: db274e2f807d319837798b7942275d6be2231753 [file] [log] [blame]
<!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="MIPS-DSP-Built_002din-Functions.html#MIPS-DSP-Built_002din-Functions" rel="next" title="MIPS DSP Built-in Functions">
<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>
Next: <a href="MIPS-DSP-Built_002din-Functions.html#MIPS-DSP-Built_002din-Functions" accesskey="n" rel="next">MIPS DSP Built-in Functions</a>, 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> &nbsp; [<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-transaction-memory-intrinsics"></a>
<h4 class="subsection">6.57.13 X86 transaction memory intrinsics</h4>
<p>Hardware transactional memory intrinsics for i386. These allow to use
memory transactions with RTM (Restricted Transactional Memory).
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.
This support is enabled with the <samp>-mrtm</samp> option.
</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 _XBEGIN_STARTED when the transaction
started successfully (note this is not 0, so the constant has to be
explicitely tested). When the transaction aborts all side effects
are undone and an abort code is returned. There is no guarantee
any transaction ever succeeds, so there always needs to be a valid
tested fallback path.
</p></dd></dl>
<div class="smallexample">
<pre class="smallexample">#include &lt;immintrin.h&gt;
if ((status = _xbegin ()) == _XBEGIN_STARTED) {
... transaction code...
_xend ();
} else {
... non transactional fallback path...
}
</pre></div>
<p>Valid abort status bits (when the value is not <code>_XBEGIN_STARTED</code>) are:
</p>
<dl compact="compact">
<dt><code>_XABORT_EXPLICIT</code></dt>
<dd><p>Transaction explicitely 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 a inner nested transaction
</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 will
fault. All memory side effects of the transactions will become visible
to other threads in an atomic matter.
</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 value not zero when 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.
status must be a 8bit constant, that is included in the status code returned
by <code>_xbegin</code>
</p></dd></dl>
<hr>
<div class="header">
<p>
Next: <a href="MIPS-DSP-Built_002din-Functions.html#MIPS-DSP-Built_002din-Functions" accesskey="n" rel="next">MIPS DSP Built-in Functions</a>, 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> &nbsp; [<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>