You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
201 lines
9.2 KiB
HTML
201 lines
9.2 KiB
HTML
4 years ago
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||
|
<html>
|
||
|
<!-- Copyright (C) 1988-2018 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 6.4, http://www.gnu.org/software/texinfo/ -->
|
||
|
<head>
|
||
|
<title>Output Statement (GNU Compiler Collection (GCC) Internals)</title>
|
||
|
|
||
|
<meta name="description" content="Output Statement (GNU Compiler Collection (GCC) Internals)">
|
||
|
<meta name="keywords" content="Output Statement (GNU Compiler Collection (GCC) Internals)">
|
||
|
<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="Machine-Desc.html#Machine-Desc" rel="up" title="Machine Desc">
|
||
|
<link href="Predicates.html#Predicates" rel="next" title="Predicates">
|
||
|
<link href="Output-Template.html#Output-Template" rel="prev" title="Output Template">
|
||
|
<style type="text/css">
|
||
|
<!--
|
||
|
a.summary-letter {text-decoration: none}
|
||
|
blockquote.indentedblock {margin-right: 0em}
|
||
|
blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
|
||
|
blockquote.smallquotation {font-size: smaller}
|
||
|
div.display {margin-left: 3.2em}
|
||
|
div.example {margin-left: 3.2em}
|
||
|
div.lisp {margin-left: 3.2em}
|
||
|
div.smalldisplay {margin-left: 3.2em}
|
||
|
div.smallexample {margin-left: 3.2em}
|
||
|
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.nolinebreak {white-space: nowrap}
|
||
|
span.roman {font-family: initial; font-weight: normal}
|
||
|
span.sansserif {font-family: sans-serif; font-weight: normal}
|
||
|
ul.no-bullet {list-style: none}
|
||
|
-->
|
||
|
</style>
|
||
|
|
||
|
|
||
|
</head>
|
||
|
|
||
|
<body lang="en">
|
||
|
<a name="Output-Statement"></a>
|
||
|
<div class="header">
|
||
|
<p>
|
||
|
Next: <a href="Predicates.html#Predicates" accesskey="n" rel="next">Predicates</a>, Previous: <a href="Output-Template.html#Output-Template" accesskey="p" rel="prev">Output Template</a>, Up: <a href="Machine-Desc.html#Machine-Desc" accesskey="u" rel="up">Machine Desc</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="C-Statements-for-Assembler-Output"></a>
|
||
|
<h3 class="section">17.6 C Statements for Assembler Output</h3>
|
||
|
<a name="index-output-statements"></a>
|
||
|
<a name="index-C-statements-for-assembler-output"></a>
|
||
|
<a name="index-generating-assembler-output"></a>
|
||
|
|
||
|
<p>Often a single fixed template string cannot produce correct and efficient
|
||
|
assembler code for all the cases that are recognized by a single
|
||
|
instruction pattern. For example, the opcodes may depend on the kinds of
|
||
|
operands; or some unfortunate combinations of operands may require extra
|
||
|
machine instructions.
|
||
|
</p>
|
||
|
<p>If the output control string starts with a ‘<samp>@</samp>’, then it is actually
|
||
|
a series of templates, each on a separate line. (Blank lines and
|
||
|
leading spaces and tabs are ignored.) The templates correspond to the
|
||
|
pattern’s constraint alternatives (see <a href="Multi_002dAlternative.html#Multi_002dAlternative">Multi-Alternative</a>). For example,
|
||
|
if a target machine has a two-address add instruction ‘<samp>addr</samp>’ to add
|
||
|
into a register and another ‘<samp>addm</samp>’ to add a register to memory, you
|
||
|
might write this pattern:
|
||
|
</p>
|
||
|
<div class="smallexample">
|
||
|
<pre class="smallexample">(define_insn "addsi3"
|
||
|
[(set (match_operand:SI 0 "general_operand" "=r,m")
|
||
|
(plus:SI (match_operand:SI 1 "general_operand" "0,0")
|
||
|
(match_operand:SI 2 "general_operand" "g,r")))]
|
||
|
""
|
||
|
"@
|
||
|
addr %2,%0
|
||
|
addm %2,%0")
|
||
|
</pre></div>
|
||
|
|
||
|
<a name="index-_002a-in-template"></a>
|
||
|
<a name="index-asterisk-in-template"></a>
|
||
|
<p>If the output control string starts with a ‘<samp>*</samp>’, then it is not an
|
||
|
output template but rather a piece of C program that should compute a
|
||
|
template. It should execute a <code>return</code> statement to return the
|
||
|
template-string you want. Most such templates use C string literals, which
|
||
|
require doublequote characters to delimit them. To include these
|
||
|
doublequote characters in the string, prefix each one with ‘<samp>\</samp>’.
|
||
|
</p>
|
||
|
<p>If the output control string is written as a brace block instead of a
|
||
|
double-quoted string, it is automatically assumed to be C code. In that
|
||
|
case, it is not necessary to put in a leading asterisk, or to escape the
|
||
|
doublequotes surrounding C string literals.
|
||
|
</p>
|
||
|
<p>The operands may be found in the array <code>operands</code>, whose C data type
|
||
|
is <code>rtx []</code>.
|
||
|
</p>
|
||
|
<p>It is very common to select different ways of generating assembler code
|
||
|
based on whether an immediate operand is within a certain range. Be
|
||
|
careful when doing this, because the result of <code>INTVAL</code> is an
|
||
|
integer on the host machine. If the host machine has more bits in an
|
||
|
<code>int</code> than the target machine has in the mode in which the constant
|
||
|
will be used, then some of the bits you get from <code>INTVAL</code> will be
|
||
|
superfluous. For proper results, you must carefully disregard the
|
||
|
values of those bits.
|
||
|
</p>
|
||
|
<a name="index-output_005fasm_005finsn"></a>
|
||
|
<p>It is possible to output an assembler instruction and then go on to output
|
||
|
or compute more of them, using the subroutine <code>output_asm_insn</code>. This
|
||
|
receives two arguments: a template-string and a vector of operands. The
|
||
|
vector may be <code>operands</code>, or it may be another array of <code>rtx</code>
|
||
|
that you declare locally and initialize yourself.
|
||
|
</p>
|
||
|
<a name="index-which_005falternative"></a>
|
||
|
<p>When an insn pattern has multiple alternatives in its constraints, often
|
||
|
the appearance of the assembler code is determined mostly by which alternative
|
||
|
was matched. When this is so, the C code can test the variable
|
||
|
<code>which_alternative</code>, which is the ordinal number of the alternative
|
||
|
that was actually satisfied (0 for the first, 1 for the second alternative,
|
||
|
etc.).
|
||
|
</p>
|
||
|
<p>For example, suppose there are two opcodes for storing zero, ‘<samp>clrreg</samp>’
|
||
|
for registers and ‘<samp>clrmem</samp>’ for memory locations. Here is how
|
||
|
a pattern could use <code>which_alternative</code> to choose between them:
|
||
|
</p>
|
||
|
<div class="smallexample">
|
||
|
<pre class="smallexample">(define_insn ""
|
||
|
[(set (match_operand:SI 0 "general_operand" "=r,m")
|
||
|
(const_int 0))]
|
||
|
""
|
||
|
{
|
||
|
return (which_alternative == 0
|
||
|
? "clrreg %0" : "clrmem %0");
|
||
|
})
|
||
|
</pre></div>
|
||
|
|
||
|
<p>The example above, where the assembler code to generate was
|
||
|
<em>solely</em> determined by the alternative, could also have been specified
|
||
|
as follows, having the output control string start with a ‘<samp>@</samp>’:
|
||
|
</p>
|
||
|
<div class="smallexample">
|
||
|
<pre class="smallexample">(define_insn ""
|
||
|
[(set (match_operand:SI 0 "general_operand" "=r,m")
|
||
|
(const_int 0))]
|
||
|
""
|
||
|
"@
|
||
|
clrreg %0
|
||
|
clrmem %0")
|
||
|
</pre></div>
|
||
|
|
||
|
<p>If you just need a little bit of C code in one (or a few) alternatives,
|
||
|
you can use ‘<samp>*</samp>’ inside of a ‘<samp>@</samp>’ multi-alternative template:
|
||
|
</p>
|
||
|
<div class="smallexample">
|
||
|
<pre class="smallexample">(define_insn ""
|
||
|
[(set (match_operand:SI 0 "general_operand" "=r,<,m")
|
||
|
(const_int 0))]
|
||
|
""
|
||
|
"@
|
||
|
clrreg %0
|
||
|
* return stack_mem_p (operands[0]) ? \"push 0\" : \"clrmem %0\";
|
||
|
clrmem %0")
|
||
|
</pre></div>
|
||
|
|
||
|
<hr>
|
||
|
<div class="header">
|
||
|
<p>
|
||
|
Next: <a href="Predicates.html#Predicates" accesskey="n" rel="next">Predicates</a>, Previous: <a href="Output-Template.html#Output-Template" accesskey="p" rel="prev">Output Template</a>, Up: <a href="Machine-Desc.html#Machine-Desc" accesskey="u" rel="up">Machine Desc</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>
|