summaryrefslogtreecommitdiff
path: root/share/doc/gccint/Constants.html
blob: 57d657ffcb0721af53209f71008298b0d6dee9c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Copyright (C) 1988-2023 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.1, http://www.gnu.org/software/texinfo/ -->
<head>
<title>GNU Compiler Collection (GCC) Internals: Constants</title>

<meta name="description" content="GNU Compiler Collection (GCC) Internals: Constants">
<meta name="keywords" content="GNU Compiler Collection (GCC) Internals: Constants">
<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="RTL.html#RTL" rel="up" title="RTL">
<link href="Regs-and-Memory.html#Regs-and-Memory" rel="next" title="Regs and Memory">
<link href="Machine-Modes.html#Machine-Modes" rel="previous" title="Machine Modes">
<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="Constants"></a>
<div class="header">
<p>
Next: <a href="Regs-and-Memory.html#Regs-and-Memory" accesskey="n" rel="next">Regs and Memory</a>, Previous: <a href="Machine-Modes.html#Machine-Modes" accesskey="p" rel="previous">Machine Modes</a>, Up: <a href="RTL.html#RTL" accesskey="u" rel="up">RTL</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="Constant-Expression-Types"></a>
<h3 class="section">14.7 Constant Expression Types</h3>
<a name="index-RTL-constants"></a>
<a name="index-RTL-constant-expression-types"></a>

<p>The simplest RTL expressions are those that represent constant values.
</p>
<dl compact="compact">
<dd><a name="index-const_005fint"></a>
</dd>
<dt><code>(const_int <var>i</var>)</code></dt>
<dd><p>This type of expression represents the integer value <var>i</var>.  <var>i</var>
is customarily accessed with the macro <code>INTVAL</code> as in
<code>INTVAL (<var>exp</var>)</code>, which is equivalent to <code>XWINT (<var>exp</var>, 0)</code>.
</p>
<p>Constants generated for modes with fewer bits than in
<code>HOST_WIDE_INT</code> must be sign extended to full width (e.g., with
<code>gen_int_mode</code>).  For constants for modes with more bits than in
<code>HOST_WIDE_INT</code> the implied high order bits of that constant are
copies of the top bit.  Note however that values are neither
inherently signed nor inherently unsigned; where necessary, signedness
is determined by the rtl operation instead.
</p>
<a name="index-const0_005frtx"></a>
<a name="index-const1_005frtx"></a>
<a name="index-const2_005frtx"></a>
<a name="index-constm1_005frtx"></a>
<p>There is only one expression object for the integer value zero; it is
the value of the variable <code>const0_rtx</code>.  Likewise, the only
expression for integer value one is found in <code>const1_rtx</code>, the only
expression for integer value two is found in <code>const2_rtx</code>, and the
only expression for integer value negative one is found in
<code>constm1_rtx</code>.  Any attempt to create an expression of code
<code>const_int</code> and value zero, one, two or negative one will return
<code>const0_rtx</code>, <code>const1_rtx</code>, <code>const2_rtx</code> or
<code>constm1_rtx</code> as appropriate.
</p>
<a name="index-const_005ftrue_005frtx"></a>
<p>Similarly, there is only one object for the integer whose value is
<code>STORE_FLAG_VALUE</code>.  It is found in <code>const_true_rtx</code>.  If
<code>STORE_FLAG_VALUE</code> is one, <code>const_true_rtx</code> and
<code>const1_rtx</code> will point to the same object.  If
<code>STORE_FLAG_VALUE</code> is -1, <code>const_true_rtx</code> and
<code>constm1_rtx</code> will point to the same object.
</p>
<a name="index-const_005fdouble"></a>
</dd>
<dt><code>(const_double:<var>m</var> <var>i0</var> <var>i1</var> &hellip;)</code></dt>
<dd><p>This represents either a floating-point constant of mode <var>m</var> or
(on older ports that do not define
<code>TARGET_SUPPORTS_WIDE_INT</code>) an integer constant too large to fit
into <code>HOST_BITS_PER_WIDE_INT</code> bits but small enough to fit within
twice that number of bits.  In the latter case, <var>m</var> will be
<code>VOIDmode</code>.  For integral values constants for modes with more
bits than twice the number in <code>HOST_WIDE_INT</code> the implied high
order bits of that constant are copies of the top bit of
<code>CONST_DOUBLE_HIGH</code>.  Note however that integral values are
neither inherently signed nor inherently unsigned; where necessary,
signedness is determined by the rtl operation instead.
</p>
<p>On more modern ports, <code>CONST_DOUBLE</code> only represents floating
point values.  New ports define <code>TARGET_SUPPORTS_WIDE_INT</code> to
make this designation.
</p>
<a name="index-CONST_005fDOUBLE_005fLOW"></a>
<p>If <var>m</var> is <code>VOIDmode</code>, the bits of the value are stored in
<var>i0</var> and <var>i1</var>.  <var>i0</var> is customarily accessed with the macro
<code>CONST_DOUBLE_LOW</code> and <var>i1</var> with <code>CONST_DOUBLE_HIGH</code>.
</p>
<p>If the constant is floating point (regardless of its precision), then
the number of integers used to store the value depends on the size of
<code>REAL_VALUE_TYPE</code> (see <a href="Floating-Point.html#Floating-Point">Floating Point</a>).  The integers
represent a floating point number, but not precisely in the target
machine&rsquo;s or host machine&rsquo;s floating point format.  To convert them to
the precise bit pattern used by the target machine, use the macro
<code>REAL_VALUE_TO_TARGET_DOUBLE</code> and friends (see <a href="Data-Output.html#Data-Output">Data Output</a>).
</p>
<a name="index-const_005fdouble_005fzero"></a>
<p>The host dependency for the number of integers used to store a double
value makes it problematic for machine descriptions to use expressions
of code <code>const_double</code> and therefore a syntactic alias has been
provided:
</p>
<div class="smallexample">
<pre class="smallexample">(const_double_zero:<var>m</var>)
</pre></div>

<p>standing for:
</p>
<div class="smallexample">
<pre class="smallexample">(const_double:<var>m</var> 0 0 &hellip;)
</pre></div>

<p>for matching the floating-point value zero, possibly the only useful one.
</p>
<a name="index-CONST_005fWIDE_005fINT"></a>
</dd>
<dt><code>(const_wide_int:<var>m</var> <var>nunits</var> <var>elt0</var> &hellip;)</code></dt>
<dd><p>This contains an array of <code>HOST_WIDE_INT</code>s that is large enough
to hold any constant that can be represented on the target.  This form
of rtl is only used on targets that define
<code>TARGET_SUPPORTS_WIDE_INT</code> to be nonzero and then
<code>CONST_DOUBLE</code>s are only used to hold floating-point values.  If
the target leaves <code>TARGET_SUPPORTS_WIDE_INT</code> defined as 0,
<code>CONST_WIDE_INT</code>s are not used and <code>CONST_DOUBLE</code>s are as
they were before.
</p>
<p>The values are stored in a compressed format.  The higher-order
0s or -1s are not represented if they are just the logical sign
extension of the number that is represented.
</p>
<a name="index-CONST_005fWIDE_005fINT_005fVEC"></a>
</dd>
<dt><code>CONST_WIDE_INT_VEC (<var>code</var>)</code></dt>
<dd><p>Returns the entire array of <code>HOST_WIDE_INT</code>s that are used to
store the value.  This macro should be rarely used.
</p>
<a name="index-CONST_005fWIDE_005fINT_005fNUNITS"></a>
</dd>
<dt><code>CONST_WIDE_INT_NUNITS (<var>code</var>)</code></dt>
<dd><p>The number of <code>HOST_WIDE_INT</code>s used to represent the number.
Note that this generally is smaller than the number of
<code>HOST_WIDE_INT</code>s implied by the mode size.
</p>
<a name="index-CONST_005fWIDE_005fINT_005fELT"></a>
</dd>
<dt><code>CONST_WIDE_INT_ELT (<var>code</var>,<var>i</var>)</code></dt>
<dd><p>Returns the <code>i</code>th element of the array.   Element 0 is contains
the low order bits of the constant.
</p>
<a name="index-const_005ffixed"></a>
</dd>
<dt><code>(const_fixed:<var>m</var> &hellip;)</code></dt>
<dd><p>Represents a fixed-point constant of mode <var>m</var>.
The operand is a data structure of type <code>struct fixed_value</code> and
is accessed with the macro <code>CONST_FIXED_VALUE</code>.  The high part of
data is accessed with <code>CONST_FIXED_VALUE_HIGH</code>; the low part is
accessed with <code>CONST_FIXED_VALUE_LOW</code>.
</p>
<a name="index-const_005fpoly_005fint"></a>
</dd>
<dt><code>(const_poly_int:<var>m</var> [<var>c0</var> <var>c1</var> &hellip;])</code></dt>
<dd><p>Represents a <code>poly_int</code>-style polynomial integer with coefficients
<var>c0</var>, <var>c1</var>, &hellip;.  The coefficients are <code>wide_int</code>-based
integers rather than rtxes.  <code>CONST_POLY_INT_COEFFS</code> gives the
values of individual coefficients (which is mostly only useful in
low-level routines) and <code>const_poly_int_value</code> gives the full
<code>poly_int</code> value.
</p>
<a name="index-const_005fvector"></a>
</dd>
<dt><code>(const_vector:<var>m</var> [<var>x0</var> <var>x1</var> &hellip;])</code></dt>
<dd><p>Represents a vector constant.  The values in square brackets are
elements of the vector, which are always <code>const_int</code>,
<code>const_wide_int</code>, <code>const_double</code> or <code>const_fixed</code>
expressions.
</p>
<p>Each vector constant <var>v</var> is treated as a specific instance of an
arbitrary-length sequence that itself contains
&lsquo;<samp>CONST_VECTOR_NPATTERNS (<var>v</var>)</samp>&rsquo; interleaved patterns.  Each
pattern has the form:
</p>
<div class="smallexample">
<pre class="smallexample">{ <var>base0</var>, <var>base1</var>, <var>base1</var> + <var>step</var>, <var>base1</var> + <var>step</var> * 2, &hellip; }
</pre></div>

<p>The first three elements in each pattern are enough to determine the
values of the other elements.  However, if all <var>step</var>s are zero,
only the first two elements are needed.  If in addition each <var>base1</var>
is equal to the corresponding <var>base0</var>, only the first element in
each pattern is needed.  The number of determining elements per pattern
is given by &lsquo;<samp>CONST_VECTOR_NELTS_PER_PATTERN (<var>v</var>)</samp>&rsquo;.
</p>
<p>For example, the constant:
</p>
<div class="smallexample">
<pre class="smallexample">{ 0, 1, 2, 6, 3, 8, 4, 10, 5, 12, 6, 14, 7, 16, 8, 18 }
</pre></div>

<p>is interpreted as an interleaving of the sequences:
</p>
<div class="smallexample">
<pre class="smallexample">{ 0, 2, 3, 4, 5, 6, 7, 8 }
{ 1, 6, 8, 10, 12, 14, 16, 18 }
</pre></div>

<p>where the sequences are represented by the following patterns:
</p>
<div class="smallexample">
<pre class="smallexample"><var>base0</var> == 0, <var>base1</var> == 2, <var>step</var> == 1
<var>base0</var> == 1, <var>base1</var> == 6, <var>step</var> == 2
</pre></div>

<p>In this case:
</p>
<div class="smallexample">
<pre class="smallexample">CONST_VECTOR_NPATTERNS (<var>v</var>) == 2
CONST_VECTOR_NELTS_PER_PATTERN (<var>v</var>) == 3
</pre></div>

<p>Thus the first 6 elements (&lsquo;<samp>{ 0, 1, 2, 6, 3, 8 }</samp>&rsquo;) are enough
to determine the whole sequence; we refer to them as the &ldquo;encoded&rdquo;
elements.  They are the only elements present in the square brackets
for variable-length <code>const_vector</code>s (i.e. for
<code>const_vector</code>s whose mode <var>m</var> has a variable number of
elements).  However, as a convenience to code that needs to handle
both <code>const_vector</code>s and <code>parallel</code>s, all elements are
present in the square brackets for fixed-length <code>const_vector</code>s;
the encoding scheme simply reduces the amount of work involved in
processing constants that follow a regular pattern.
</p>
<p>Sometimes this scheme can create two possible encodings of the same
vector.  For example { 0, 1 } could be seen as two patterns with
one element each or one pattern with two elements (<var>base0</var> and
<var>base1</var>).  The canonical encoding is always the one with the
fewest patterns or (if both encodings have the same number of
petterns) the one with the fewest encoded elements.
</p>
<p>&lsquo;<samp>const_vector_encoding_nelts (<var>v</var>)</samp>&rsquo; gives the total number of
encoded elements in <var>v</var>, which is 6 in the example above.
<code>CONST_VECTOR_ENCODED_ELT (<var>v</var>, <var>i</var>)</code> accesses the value
of encoded element <var>i</var>.
</p>
<p>&lsquo;<samp>CONST_VECTOR_DUPLICATE_P (<var>v</var>)</samp>&rsquo; is true if <var>v</var> simply contains
repeated instances of &lsquo;<samp>CONST_VECTOR_NPATTERNS (<var>v</var>)</samp>&rsquo; values.  This is
a shorthand for testing &lsquo;<samp>CONST_VECTOR_NELTS_PER_PATTERN (<var>v</var>) == 1</samp>&rsquo;.
</p>
<p>&lsquo;<samp>CONST_VECTOR_STEPPED_P (<var>v</var>)</samp>&rsquo; is true if at least one
pattern in <var>v</var> has a nonzero step.  This is a shorthand for
testing &lsquo;<samp>CONST_VECTOR_NELTS_PER_PATTERN (<var>v</var>) == 3</samp>&rsquo;.
</p>
<p><code>CONST_VECTOR_NUNITS (<var>v</var>)</code> gives the total number of elements
in <var>v</var>; it is a shorthand for getting the number of units in
&lsquo;<samp>GET_MODE (<var>v</var>)</samp>&rsquo;.
</p>
<p>The utility function <code>const_vector_elt</code> gives the value of an
arbitrary element as an <code>rtx</code>.  <code>const_vector_int_elt</code> gives
the same value as a <code>wide_int</code>.
</p>
<a name="index-const_005fstring"></a>
</dd>
<dt><code>(const_string <var>str</var>)</code></dt>
<dd><p>Represents a constant string with value <var>str</var>.  Currently this is
used only for insn attributes (see <a href="Insn-Attributes.html#Insn-Attributes">Insn Attributes</a>) since constant
strings in C are placed in memory.
</p>
<a name="index-symbol_005fref"></a>
</dd>
<dt><code>(symbol_ref:<var>mode</var> <var>symbol</var>)</code></dt>
<dd><p>Represents the value of an assembler label for data.  <var>symbol</var> is
a string that describes the name of the assembler label.  If it starts
with a &lsquo;<samp>*</samp>&rsquo;, the label is the rest of <var>symbol</var> not including
the &lsquo;<samp>*</samp>&rsquo;.  Otherwise, the label is <var>symbol</var>, usually prefixed
with &lsquo;<samp>_</samp>&rsquo;.
</p>
<p>The <code>symbol_ref</code> contains a mode, which is usually <code>Pmode</code>.
Usually that is the only mode for which a symbol is directly valid.
</p>
<a name="index-label_005fref"></a>
</dd>
<dt><code>(label_ref:<var>mode</var> <var>label</var>)</code></dt>
<dd><p>Represents the value of an assembler label for code.  It contains one
operand, an expression, which must be a <code>code_label</code> or a <code>note</code>
of type <code>NOTE_INSN_DELETED_LABEL</code> that appears in the instruction
sequence to identify the place where the label should go.
</p>
<p>The reason for using a distinct expression type for code label
references is so that jump optimization can distinguish them.
</p>
<p>The <code>label_ref</code> contains a mode, which is usually <code>Pmode</code>.
Usually that is the only mode for which a label is directly valid.
</p>
<a name="index-const"></a>
</dd>
<dt><code>(const:<var>m</var> <var>exp</var>)</code></dt>
<dd><p>Represents a constant that is the result of an assembly-time
arithmetic computation.  The operand, <var>exp</var>, contains only
<code>const_int</code>, <code>symbol_ref</code>, <code>label_ref</code> or <code>unspec</code>
expressions, combined with <code>plus</code> and <code>minus</code>.  Any such
<code>unspec</code>s are target-specific and typically represent some form
of relocation operator.  <var>m</var> should be a valid address mode.
</p>
<a name="index-high"></a>
</dd>
<dt><code>(high:<var>m</var> <var>exp</var>)</code></dt>
<dd><p>Represents the high-order bits of <var>exp</var>.  
The number of bits is machine-dependent and is
normally the number of bits specified in an instruction that initializes
the high order bits of a register.  It is used with <code>lo_sum</code> to
represent the typical two-instruction sequence used in RISC machines to
reference large immediate values and/or link-time constants such
as global memory addresses.  In the latter case, <var>m</var> is <code>Pmode</code>
and <var>exp</var> is usually a constant expression involving <code>symbol_ref</code>.
</p></dd>
</dl>

<a name="index-CONST0_005fRTX"></a>
<a name="index-CONST1_005fRTX"></a>
<a name="index-CONST2_005fRTX"></a>
<p>The macro <code>CONST0_RTX (<var>mode</var>)</code> refers to an expression with
value 0 in mode <var>mode</var>.  If mode <var>mode</var> is of mode class
<code>MODE_INT</code>, it returns <code>const0_rtx</code>.  If mode <var>mode</var> is of
mode class <code>MODE_FLOAT</code>, it returns a <code>CONST_DOUBLE</code>
expression in mode <var>mode</var>.  Otherwise, it returns a
<code>CONST_VECTOR</code> expression in mode <var>mode</var>.  Similarly, the macro
<code>CONST1_RTX (<var>mode</var>)</code> refers to an expression with value 1 in
mode <var>mode</var> and similarly for <code>CONST2_RTX</code>.  The
<code>CONST1_RTX</code> and <code>CONST2_RTX</code> macros are undefined
for vector modes.
</p>
<hr>
<div class="header">
<p>
Next: <a href="Regs-and-Memory.html#Regs-and-Memory" accesskey="n" rel="next">Regs and Memory</a>, Previous: <a href="Machine-Modes.html#Machine-Modes" accesskey="p" rel="previous">Machine Modes</a>, Up: <a href="RTL.html#RTL" accesskey="u" rel="up">RTL</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>