📄 rtl.texi
字号:
first operand of @code{if_then_else} (in a conditional branch).
@end itemize
@findex cc0_rtx
There is only one expression object of code @code{cc0}; it is the
value of the variable @code{cc0_rtx}. Any attempt to create an
expression of code @code{cc0} will return @code{cc0_rtx}.
Instructions can set the condition code implicitly. On many machines,
nearly all instructions set the condition code based on the value that
they compute or store. It is not necessary to record these actions
explicitly in the RTL because the machine description includes a
prescription for recognizing the instructions that do so (by means of
the macro @code{NOTICE_UPDATE_CC}). @xref{Condition Code}. Only
instructions whose sole purpose is to set the condition code, and
instructions that use the condition code, need mention @code{(cc0)}.
On some machines, the condition code register is given a register number
and a @code{reg} is used instead of @code{(cc0)}. This is usually the
preferable approach if only a small subset of instructions modify the
condition code. Other machines store condition codes in general
registers; in such cases a pseudo register should be used.
Some machines, such as the Sparc and RS/6000, have two sets of
arithmetic instructions, one that sets and one that does not set the
condition code. This is best handled by normally generating the
instruction that does not set the condition code, and making a pattern
that both performs the arithmetic and sets the condition code register
(which would not be @code{(cc0)} in this case). For examples, search
for @samp{addcc} and @samp{andcc} in @file{sparc.md}.
@findex pc
@item (pc)
@cindex program counter
This represents the machine's program counter. It has no operands and
may not have a machine mode. @code{(pc)} may be validly used only in
certain specific contexts in jump instructions.
@findex pc_rtx
There is only one expression object of code @code{pc}; it is the value
of the variable @code{pc_rtx}. Any attempt to create an expression of
code @code{pc} will return @code{pc_rtx}.
All instructions that do not jump alter the program counter implicitly
by incrementing it, but there is no need to mention this in the RTL.
@findex mem
@item (mem:@var{m} @var{addr} @var{alias})
This RTX represents a reference to main memory at an address
represented by the expression @var{addr}. @var{m} specifies how large
a unit of memory is accessed. @var{alias} specifies an alias set for the
reference. In general two items are in different alias sets if they cannot
reference the same memory address.
@findex addressof
@item (addressof:@var{m} @var{reg})
This RTX represents a request for the address of register @var{reg}. Its mode
is always @code{Pmode}. If there are any @code{addressof}
expressions left in the function after CSE, @var{reg} is forced into the
stack and the @code{addressof} expression is replaced with a @code{plus}
expression for the address of its stack slot.
@end table
@node Arithmetic
@section RTL Expressions for Arithmetic
@cindex arithmetic, in RTL
@cindex math, in RTL
@cindex RTL expressions for arithmetic
Unless otherwise specified, all the operands of arithmetic expressions
must be valid for mode @var{m}. An operand is valid for mode @var{m}
if it has mode @var{m}, or if it is a @code{const_int} or
@code{const_double} and @var{m} is a mode of class @code{MODE_INT}.
For commutative binary operations, constants should be placed in the
second operand.
@table @code
@findex plus
@cindex RTL addition
@cindex RTL sum
@item (plus:@var{m} @var{x} @var{y})
Represents the sum of the values represented by @var{x} and @var{y}
carried out in machine mode @var{m}.
@findex lo_sum
@item (lo_sum:@var{m} @var{x} @var{y})
Like @code{plus}, except that it represents that sum of @var{x} and the
low-order bits of @var{y}. The number of low order bits is
machine-dependent but is normally the number of bits in a @code{Pmode}
item minus the number of bits set by the @code{high} code
(@pxref{Constants}).
@var{m} should be @code{Pmode}.
@findex minus
@cindex RTL subtraction
@cindex RTL difference
@item (minus:@var{m} @var{x} @var{y})
Like @code{plus} but represents subtraction.
@findex ss_plus
@cindex RTL addition with signed saturation
@item (ss_plus:@var{m} @var{x} @var{y})
Like @code{plus}, but using signed saturation in case of an overflow.
@findex us_plus
@cindex RTL addition with unsigned saturation
@item (us_plus:@var{m} @var{x} @var{y})
Like @code{plus}, but using unsigned saturation in case of an overflow.
@findex ss_minus
@cindex RTL addition with signed saturation
@item (ss_minus:@var{m} @var{x} @var{y})
Like @code{minus}, but using signed saturation in case of an overflow.
@findex us_minus
@cindex RTL addition with unsigned saturation
@item (us_minus:@var{m} @var{x} @var{y})
Like @code{minus}, but using unsigned saturation in case of an overflow.
@findex compare
@cindex RTL comparison
@item (compare:@var{m} @var{x} @var{y})
Represents the result of subtracting @var{y} from @var{x} for purposes
of comparison. The result is computed without overflow, as if with
infinite precision.
Of course, machines can't really subtract with infinite precision.
However, they can pretend to do so when only the sign of the
result will be used, which is the case when the result is stored
in the condition code. And that is the only way this kind of expression
may validly be used: as a value to be stored in the condition codes.
The mode @var{m} is not related to the modes of @var{x} and @var{y},
but instead is the mode of the condition code value. If @code{(cc0)}
is used, it is @code{VOIDmode}. Otherwise it is some mode in class
@code{MODE_CC}, often @code{CCmode}. @xref{Condition Code}.
Normally, @var{x} and @var{y} must have the same mode. Otherwise,
@code{compare} is valid only if the mode of @var{x} is in class
@code{MODE_INT} and @var{y} is a @code{const_int} or
@code{const_double} with mode @code{VOIDmode}. The mode of @var{x}
determines what mode the comparison is to be done in; thus it must not
be @code{VOIDmode}.
If one of the operands is a constant, it should be placed in the
second operand and the comparison code adjusted as appropriate.
A @code{compare} specifying two @code{VOIDmode} constants is not valid
since there is no way to know in what mode the comparison is to be
performed; the comparison must either be folded during the compilation
or the first operand must be loaded into a register while its mode is
still known.
@findex neg
@item (neg:@var{m} @var{x})
Represents the negation (subtraction from zero) of the value represented
by @var{x}, carried out in mode @var{m}.
@findex mult
@cindex multiplication
@cindex product
@item (mult:@var{m} @var{x} @var{y})
Represents the signed product of the values represented by @var{x} and
@var{y} carried out in machine mode @var{m}.
Some machines support a multiplication that generates a product wider
than the operands. Write the pattern for this as
@example
(mult:@var{m} (sign_extend:@var{m} @var{x}) (sign_extend:@var{m} @var{y}))
@end example
where @var{m} is wider than the modes of @var{x} and @var{y}, which need
not be the same.
Write patterns for unsigned widening multiplication similarly using
@code{zero_extend}.
@findex div
@cindex division
@cindex signed division
@cindex quotient
@item (div:@var{m} @var{x} @var{y})
Represents the quotient in signed division of @var{x} by @var{y},
carried out in machine mode @var{m}. If @var{m} is a floating point
mode, it represents the exact quotient; otherwise, the integerized
quotient.
Some machines have division instructions in which the operands and
quotient widths are not all the same; you should represent
such instructions using @code{truncate} and @code{sign_extend} as in,
@example
(truncate:@var{m1} (div:@var{m2} @var{x} (sign_extend:@var{m2} @var{y})))
@end example
@findex udiv
@cindex unsigned division
@cindex division
@item (udiv:@var{m} @var{x} @var{y})
Like @code{div} but represents unsigned division.
@findex mod
@findex umod
@cindex remainder
@cindex division
@item (mod:@var{m} @var{x} @var{y})
@itemx (umod:@var{m} @var{x} @var{y})
Like @code{div} and @code{udiv} but represent the remainder instead of
the quotient.
@findex smin
@findex smax
@cindex signed minimum
@cindex signed maximum
@item (smin:@var{m} @var{x} @var{y})
@itemx (smax:@var{m} @var{x} @var{y})
Represents the smaller (for @code{smin}) or larger (for @code{smax}) of
@var{x} and @var{y}, interpreted as signed integers in mode @var{m}.
@findex umin
@findex umax
@cindex unsigned minimum and maximum
@item (umin:@var{m} @var{x} @var{y})
@itemx (umax:@var{m} @var{x} @var{y})
Like @code{smin} and @code{smax}, but the values are interpreted as unsigned
integers.
@findex not
@cindex complement, bitwise
@cindex bitwise complement
@item (not:@var{m} @var{x})
Represents the bitwise complement of the value represented by @var{x},
carried out in mode @var{m}, which must be a fixed-point machine mode.
@findex and
@cindex logical-and, bitwise
@cindex bitwise logical-and
@item (and:@var{m} @var{x} @var{y})
Represents the bitwise logical-and of the values represented by
@var{x} and @var{y}, carried out in machine mode @var{m}, which must be
a fixed-point machine mode.
@findex ior
@cindex inclusive-or, bitwise
@cindex bitwise inclusive-or
@item (ior:@var{m} @var{x} @var{y})
Represents the bitwise inclusive-or of the values represented by @var{x}
and @var{y}, carried out in machine mode @var{m}, which must be a
fixed-point mode.
@findex xor
@cindex exclusive-or, bitwise
@cindex bitwise exclusive-or
@item (xor:@var{m} @var{x} @var{y})
Represents the bitwise exclusive-or of the values represented by @var{x}
and @var{y}, carried out in machine mode @var{m}, which must be a
fixed-point mode.
@findex ashift
@cindex left shift
@cindex shift
@cindex arithmetic shift
@item (ashift:@var{m} @var{x} @var{c})
Represents the result of arithmetically shifting @var{x} left by @var{c}
places. @var{x} have mode @var{m}, a fixed-point machine mode. @var{c}
be a fixed-point mode or be a constant with mode @code{VOIDmode}; which
mode is determined by the mode called for in the machine description
entry for the left-shift instruction. For example, on the Vax, the mode
of @var{c} is @code{QImode} regardless of @var{m}.
@findex lshiftrt
@cindex right shift
@findex ashiftrt
@item (lshiftrt:@var{m} @var{x} @var{c})
@itemx (ashiftrt:@var{m} @var{x} @var{c})
Like @code{ashift} but for right shift. Unlike the case for left shift,
these two operations are distinct.
@findex rotate
@cindex rotate
@cindex left rotate
@findex rotatert
@cindex right rotate
@item (rotate:@var{m} @var{x} @var{c})
@itemx (rotatert:@var{m} @var{x} @var{c})
Similar but represent left and right rotate. If @var{c} is a constant,
use @code{rotate}.
@findex abs
@cindex absolute value
@item (abs:@var{m} @var{x})
Represents the absolute value of @var{x}, computed in mode @var{m}.
@findex sqrt
@cindex square root
@item (sqrt:@var{m} @var{x})
Represents the square root of @var{x}, computed in mode @var{m}.
Most often @var{m} will be a floating point mode.
@findex ffs
@item (ffs:@var{m} @var{x})
Represents one plus the index of the least significant 1-bit in
@var{x}, represented as an integer of mode @var{m}. (The value is
zero if @var{x} is zero.) The mode of @var{x} need not be @var{m};
depending on the target machine, various mode combinations may be
valid.
@end table
@node Comparisons
@section Comparison Operations
@cindex RTL comparison operations
Comparison operators test a relation on two operands and are considered
to represent a machine-dependent nonzero value described by,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -