You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

189 line
8.0KB

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1988-2020 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Funding Free Software", the Front-Cover
  8. Texts being (a) (see below), and with the Back-Cover Texts being (b)
  9. (see below). A copy of the license is included in the section entitled
  10. "GNU Free Documentation License".
  11. (a) The FSF's Front-Cover Text is:
  12. A GNU Manual
  13. (b) The FSF's Back-Cover Text is:
  14. You have freedom to copy and modify this GNU Manual, like GNU
  15. software. Copies published by the Free Software Foundation raise
  16. funds for GNU development. -->
  17. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  20. <title>x86 transactional memory intrinsics (Using the GNU Compiler Collection (GCC))</title>
  21. <meta name="description" content="x86 transactional memory intrinsics (Using the GNU Compiler Collection (GCC))">
  22. <meta name="keywords" content="x86 transactional memory intrinsics (Using the GNU Compiler Collection (GCC))">
  23. <meta name="resource-type" content="document">
  24. <meta name="distribution" content="global">
  25. <meta name="Generator" content="makeinfo">
  26. <link href="index.html#Top" rel="start" title="Top">
  27. <link href="Option-Index.html#Option-Index" rel="index" title="Option Index">
  28. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  29. <link href="Target-Builtins.html#Target-Builtins" rel="up" title="Target Builtins">
  30. <link href="x86-control_002dflow-protection-intrinsics.html#x86-control_002dflow-protection-intrinsics" rel="next" title="x86 control-flow protection intrinsics">
  31. <link href="x86-Built_002din-Functions.html#x86-Built_002din-Functions" rel="prev" title="x86 Built-in Functions">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.indentedblock {margin-right: 0em}
  36. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  37. blockquote.smallquotation {font-size: smaller}
  38. div.display {margin-left: 3.2em}
  39. div.example {margin-left: 3.2em}
  40. div.lisp {margin-left: 3.2em}
  41. div.smalldisplay {margin-left: 3.2em}
  42. div.smallexample {margin-left: 3.2em}
  43. div.smalllisp {margin-left: 3.2em}
  44. kbd {font-style: oblique}
  45. pre.display {font-family: inherit}
  46. pre.format {font-family: inherit}
  47. pre.menu-comment {font-family: serif}
  48. pre.menu-preformatted {font-family: serif}
  49. pre.smalldisplay {font-family: inherit; font-size: smaller}
  50. pre.smallexample {font-size: smaller}
  51. pre.smallformat {font-family: inherit; font-size: smaller}
  52. pre.smalllisp {font-size: smaller}
  53. span.nolinebreak {white-space: nowrap}
  54. span.roman {font-family: initial; font-weight: normal}
  55. span.sansserif {font-family: sans-serif; font-weight: normal}
  56. ul.no-bullet {list-style: none}
  57. -->
  58. </style>
  59. </head>
  60. <body lang="en">
  61. <a name="x86-transactional-memory-intrinsics"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="x86-control_002dflow-protection-intrinsics.html#x86-control_002dflow-protection-intrinsics" accesskey="n" rel="next">x86 control-flow protection intrinsics</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>
  65. </div>
  66. <hr>
  67. <a name="x86-Transactional-Memory-Intrinsics"></a>
  68. <h4 class="subsection">6.60.35 x86 Transactional Memory Intrinsics</h4>
  69. <p>These hardware transactional memory intrinsics for x86 allow you to use
  70. memory transactions with RTM (Restricted Transactional Memory).
  71. This support is enabled with the <samp>-mrtm</samp> option.
  72. For using HLE (Hardware Lock Elision) see
  73. <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.
  74. </p>
  75. <p>A memory transaction commits all changes to memory in an atomic way,
  76. as visible to other threads. If the transaction fails it is rolled back
  77. and all side effects discarded.
  78. </p>
  79. <p>Generally there is no guarantee that a memory transaction ever succeeds
  80. and suitable fallback code always needs to be supplied.
  81. </p>
  82. <dl>
  83. <dt><a name="index-_005fxbegin"></a>RTM Function: <em>unsigned</em> <strong>_xbegin</strong> <em>()</em></dt>
  84. <dd><p>Start a RTM (Restricted Transactional Memory) transaction.
  85. Returns <code>_XBEGIN_STARTED</code> when the transaction
  86. started successfully (note this is not 0, so the constant has to be
  87. explicitly tested).
  88. </p>
  89. <p>If the transaction aborts, all side effects
  90. are undone and an abort code encoded as a bit mask is returned.
  91. The following macros are defined:
  92. </p>
  93. <dl compact="compact">
  94. <dt><code>_XABORT_EXPLICIT</code></dt>
  95. <dd><p>Transaction was explicitly aborted with <code>_xabort</code>. The parameter passed
  96. to <code>_xabort</code> is available with <code>_XABORT_CODE(status)</code>.
  97. </p></dd>
  98. <dt><code>_XABORT_RETRY</code></dt>
  99. <dd><p>Transaction retry is possible.
  100. </p></dd>
  101. <dt><code>_XABORT_CONFLICT</code></dt>
  102. <dd><p>Transaction abort due to a memory conflict with another thread.
  103. </p></dd>
  104. <dt><code>_XABORT_CAPACITY</code></dt>
  105. <dd><p>Transaction abort due to the transaction using too much memory.
  106. </p></dd>
  107. <dt><code>_XABORT_DEBUG</code></dt>
  108. <dd><p>Transaction abort due to a debug trap.
  109. </p></dd>
  110. <dt><code>_XABORT_NESTED</code></dt>
  111. <dd><p>Transaction abort in an inner nested transaction.
  112. </p></dd>
  113. </dl>
  114. <p>There is no guarantee
  115. any transaction ever succeeds, so there always needs to be a valid
  116. fallback path.
  117. </p></dd></dl>
  118. <dl>
  119. <dt><a name="index-_005fxend"></a>RTM Function: <em>void</em> <strong>_xend</strong> <em>()</em></dt>
  120. <dd><p>Commit the current transaction. When no transaction is active this faults.
  121. All memory side effects of the transaction become visible
  122. to other threads in an atomic manner.
  123. </p></dd></dl>
  124. <dl>
  125. <dt><a name="index-_005fxtest"></a>RTM Function: <em>int</em> <strong>_xtest</strong> <em>()</em></dt>
  126. <dd><p>Return a nonzero value if a transaction is currently active, otherwise 0.
  127. </p></dd></dl>
  128. <dl>
  129. <dt><a name="index-_005fxabort"></a>RTM Function: <em>void</em> <strong>_xabort</strong> <em>(status)</em></dt>
  130. <dd><p>Abort the current transaction. When no transaction is active this is a no-op.
  131. The <var>status</var> is an 8-bit constant; its value is encoded in the return
  132. value from <code>_xbegin</code>.
  133. </p></dd></dl>
  134. <p>Here is an example showing handling for <code>_XABORT_RETRY</code>
  135. and a fallback path for other failures:
  136. </p>
  137. <div class="smallexample">
  138. <pre class="smallexample">#include &lt;immintrin.h&gt;
  139. int n_tries, max_tries;
  140. unsigned status = _XABORT_EXPLICIT;
  141. ...
  142. for (n_tries = 0; n_tries &lt; max_tries; n_tries++)
  143. {
  144. status = _xbegin ();
  145. if (status == _XBEGIN_STARTED || !(status &amp; _XABORT_RETRY))
  146. break;
  147. }
  148. if (status == _XBEGIN_STARTED)
  149. {
  150. ... transaction code...
  151. _xend ();
  152. }
  153. else
  154. {
  155. ... non-transactional fallback path...
  156. }
  157. </pre></div>
  158. <p>Note that, in most cases, the transactional and non-transactional code
  159. must synchronize together to ensure consistency.
  160. </p>
  161. <hr>
  162. <div class="header">
  163. <p>
  164. Next: <a href="x86-control_002dflow-protection-intrinsics.html#x86-control_002dflow-protection-intrinsics" accesskey="n" rel="next">x86 control-flow protection intrinsics</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>
  165. </div>
  166. </body>
  167. </html>