1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2<html>
3<!-- This file documents the GNU Assembler "as".
4
5Copyright (C) 1991-2021 Free Software Foundation, Inc.
6
7Permission is granted to copy, distribute and/or modify this document
8under the terms of the GNU Free Documentation License, Version 1.3
9or any later version published by the Free Software Foundation;
10with no Invariant Sections, with no Front-Cover Texts, and with no
11Back-Cover Texts.  A copy of the license is included in the
12section entitled "GNU Free Documentation License".
13 -->
14<!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ -->
15<head>
16<title>Using as: Xtensa Immediate Relaxation</title>
17
18<meta name="description" content="Using as: Xtensa Immediate Relaxation">
19<meta name="keywords" content="Using as: Xtensa Immediate Relaxation">
20<meta name="resource-type" content="document">
21<meta name="distribution" content="global">
22<meta name="Generator" content="makeinfo">
23<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
24<link href="index.html#Top" rel="start" title="Top">
25<link href="AS-Index.html#AS-Index" rel="index" title="AS Index">
26<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
27<link href="Xtensa-Relaxation.html#Xtensa-Relaxation" rel="up" title="Xtensa Relaxation">
28<link href="Xtensa-Directives.html#Xtensa-Directives" rel="next" title="Xtensa Directives">
29<link href="Xtensa-Jump-Relaxation.html#Xtensa-Jump-Relaxation" rel="previous" title="Xtensa Jump Relaxation">
30<style type="text/css">
31<!--
32a.summary-letter {text-decoration: none}
33blockquote.smallquotation {font-size: smaller}
34div.display {margin-left: 3.2em}
35div.example {margin-left: 3.2em}
36div.indentedblock {margin-left: 3.2em}
37div.lisp {margin-left: 3.2em}
38div.smalldisplay {margin-left: 3.2em}
39div.smallexample {margin-left: 3.2em}
40div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
41div.smalllisp {margin-left: 3.2em}
42kbd {font-style:oblique}
43pre.display {font-family: inherit}
44pre.format {font-family: inherit}
45pre.menu-comment {font-family: serif}
46pre.menu-preformatted {font-family: serif}
47pre.smalldisplay {font-family: inherit; font-size: smaller}
48pre.smallexample {font-size: smaller}
49pre.smallformat {font-family: inherit; font-size: smaller}
50pre.smalllisp {font-size: smaller}
51span.nocodebreak {white-space:nowrap}
52span.nolinebreak {white-space:nowrap}
53span.roman {font-family:serif; font-weight:normal}
54span.sansserif {font-family:sans-serif; font-weight:normal}
55ul.no-bullet {list-style: none}
56-->
57</style>
58
59
60</head>
61
62<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
63<a name="Xtensa-Immediate-Relaxation"></a>
64<div class="header">
65<p>
66Previous: <a href="Xtensa-Jump-Relaxation.html#Xtensa-Jump-Relaxation" accesskey="p" rel="previous">Xtensa Jump Relaxation</a>, Up: <a href="Xtensa-Relaxation.html#Xtensa-Relaxation" accesskey="u" rel="up">Xtensa Relaxation</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="AS-Index.html#AS-Index" title="Index" rel="index">Index</a>]</p>
67</div>
68<hr>
69<a name="Other-Immediate-Field-Relaxation"></a>
70<h4 class="subsubsection">9.55.4.4 Other Immediate Field Relaxation</h4>
71<a name="index-immediate-fields_002c-relaxation"></a>
72<a name="index-relaxation-of-immediate-fields"></a>
73
74<p>The assembler normally performs the following other relaxations.  They
75can be disabled by using underscore prefixes (see <a href="Xtensa-Opcodes.html#Xtensa-Opcodes">Opcode Names</a>), the &lsquo;<samp>--no-transform</samp>&rsquo; command-line option
76(see <a href="Xtensa-Options.html#Xtensa-Options">Command-line Options</a>), or the
77<code>no-transform</code> directive (see <a href="Transform-Directive.html#Transform-Directive">transform</a>).
78</p>
79<a name="index-MOVI-instructions_002c-relaxation"></a>
80<a name="index-relaxation-of-MOVI-instructions"></a>
81<p>The <code>MOVI</code> machine instruction can only materialize values in the
82range from -2048 to 2047.  Values outside this range are best
83materialized with <code>L32R</code> instructions.  Thus:
84</p>
85<div class="smallexample">
86<pre class="smallexample">    movi a0, 100000
87</pre></div>
88
89<p>is assembled into the following machine code:
90</p>
91<div class="smallexample">
92<pre class="smallexample">    .literal .L1, 100000
93    l32r a0, .L1
94</pre></div>
95
96<a name="index-L8UI-instructions_002c-relaxation"></a>
97<a name="index-L16SI-instructions_002c-relaxation"></a>
98<a name="index-L16UI-instructions_002c-relaxation"></a>
99<a name="index-L32I-instructions_002c-relaxation"></a>
100<a name="index-relaxation-of-L8UI-instructions"></a>
101<a name="index-relaxation-of-L16SI-instructions"></a>
102<a name="index-relaxation-of-L16UI-instructions"></a>
103<a name="index-relaxation-of-L32I-instructions"></a>
104<p>The <code>L8UI</code> machine instruction can only be used with immediate
105offsets in the range from 0 to 255. The <code>L16SI</code> and <code>L16UI</code>
106machine instructions can only be used with offsets from 0 to 510.  The
107<code>L32I</code> machine instruction can only be used with offsets from 0 to
1081020.  A load offset outside these ranges can be materialized with
109an <code>L32R</code> instruction if the destination register of the load
110is different than the source address register.  For example:
111</p>
112<div class="smallexample">
113<pre class="smallexample">    l32i a1, a0, 2040
114</pre></div>
115
116<p>is translated to:
117</p>
118<div class="smallexample">
119<pre class="smallexample">    .literal .L1, 2040
120    l32r a1, .L1
121</pre><pre class="smallexample">    add a1, a0, a1
122    l32i a1, a1, 0
123</pre></div>
124
125<p>If the load destination and source address register are the same, an
126out-of-range offset causes an error.
127</p>
128<a name="index-ADDI-instructions_002c-relaxation"></a>
129<a name="index-relaxation-of-ADDI-instructions"></a>
130<p>The Xtensa <code>ADDI</code> instruction only allows immediate operands in the
131range from -128 to 127.  There are a number of alternate instruction
132sequences for the <code>ADDI</code> operation.  First, if the
133immediate is 0, the <code>ADDI</code> will be turned into a <code>MOV.N</code>
134instruction (or the equivalent <code>OR</code> instruction if the code density
135option is not available).  If the <code>ADDI</code> immediate is outside of
136the range -128 to 127, but inside the range -32896 to 32639, an
137<code>ADDMI</code> instruction or <code>ADDMI</code>/<code>ADDI</code> sequence will be
138used.  Finally, if the immediate is outside of this range and a free
139register is available, an <code>L32R</code>/<code>ADD</code> sequence will be used
140with a literal allocated from the literal pool.
141</p>
142<p>For example:
143</p>
144<div class="smallexample">
145<pre class="smallexample">    addi    a5, a6, 0
146    addi    a5, a6, 512
147</pre><pre class="smallexample">    addi    a5, a6, 513
148    addi    a5, a6, 50000
149</pre></div>
150
151<p>is assembled into the following:
152</p>
153<div class="smallexample">
154<pre class="smallexample">    .literal .L1, 50000
155    mov.n   a5, a6
156</pre><pre class="smallexample">    addmi   a5, a6, 0x200
157    addmi   a5, a6, 0x200
158    addi    a5, a5, 1
159</pre><pre class="smallexample">    l32r    a5, .L1
160    add     a5, a6, a5
161</pre></div>
162
163<hr>
164<div class="header">
165<p>
166Previous: <a href="Xtensa-Jump-Relaxation.html#Xtensa-Jump-Relaxation" accesskey="p" rel="previous">Xtensa Jump Relaxation</a>, Up: <a href="Xtensa-Relaxation.html#Xtensa-Relaxation" accesskey="u" rel="up">Xtensa Relaxation</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="AS-Index.html#AS-Index" title="Index" rel="index">Index</a>]</p>
167</div>
168
169
170
171</body>
172</html>
173