summaryrefslogtreecommitdiff
path: root/devdocs/gcc~13/multi-alternative.html
blob: 77a7f39d1f25a1dfd958d5dbe2941ac5eb7ef2f1 (plain)
1
2
3
4
5
6
7
8
<div class="subsubsection-level-extent" id="Multi-Alternative"> <div class="nav-panel"> <p> Next: <a href="modifiers" accesskey="n" rel="next">Constraint Modifier Characters</a>, Previous: <a href="simple-constraints" accesskey="p" rel="prev">Simple Constraints</a>, Up: <a href="constraints" accesskey="u" rel="up">Constraints for <code class="code">asm</code> Operands</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="subsubsection subsection-level-set-subsubsection" id="Multiple-Alternative-Constraints"><span>6.47.3.2 Multiple Alternative Constraints<a class="copiable-link" href="#Multiple-Alternative-Constraints"> ¶</a></span></h1>  <p>Sometimes a single instruction has multiple alternative sets of possible operands. For example, on the 68000, a logical-or instruction can combine register or an immediate value into memory, or it can combine any kind of operand into a register; but it cannot combine one memory location into another. </p> <p>These constraints are represented as multiple alternatives. An alternative can be described by a series of letters for each operand. The overall constraint for an operand is made from the letters for this operand from the first alternative, a comma, the letters for this operand from the second alternative, a comma, and so on until the last alternative. All operands for a single instruction must have the same number of alternatives. </p> <p>So the first alternative for the 68000’s logical-or could be written as <code class="code">"+m" (output) : "ir" (input)</code>. The second could be <code class="code">"+r" 
(output): "irm" (input)</code>. However, the fact that two memory locations cannot be used in a single instruction prevents simply using <code class="code">"+rm" 
(output) : "irm" (input)</code>. Using multi-alternatives, this might be written as <code class="code">"+m,r" (output) : "ir,irm" (input)</code>. This describes all the available alternatives to the compiler, allowing it to choose the most efficient one for the current conditions. </p> <p>There is no way within the template to determine which alternative was chosen. However you may be able to wrap your <code class="code">asm</code> statements with builtins such as <code class="code">__builtin_constant_p</code> to achieve the desired results. </p> </div><div class="_attribution">
  <p class="_attribution-p">
    &copy; 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/Multi-Alternative.html" class="_attribution-link">https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/Multi-Alternative.html</a>
  </p>
</div>