RTL Expressions for Arithmetic#
Unless otherwise specified, all the operands of arithmetic expressions
must be valid for mode m. An operand is valid for mode m
if it has mode m, or if it is a const_int or
const_double and m is a mode of class MODE_INT.
For commutative binary operations, constants should be placed in the second operand.
(plus:m x y)(ss_plus:m x y)(us_plus:m x y)These three expressions all represent the sum of the values represented by
xandycarried out in machine modem. They differ in their behavior on overflow of integer modes.pluswraps round modulo the width ofm;ss_plussaturates at the maximum signed value representable inm;us_plussaturates at the maximum unsigned value.(lo_sum:m x y)This expression represents the sum of
xand the low-order bits ofy. It is used withhigh(see Constant Expression Types) 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,misPmodeandyis usually a constant expression involvingsymbol_ref.The number of low order bits is machine-dependent but is normally the number of bits in mode
mminus the number of bits set byhigh.(minus:m x y)(ss_minus:m x y)(us_minus:m x y)These three expressions represent the result of subtracting
yfromx, carried out in modeM. Behavior on overflow is the same as for the three variants ofplus(see above).(compare:m x y)Represents the result of subtracting
yfromxfor purposes of comparison. The result is computed without overflow, as if with infinite precision.Of course, machines cannot 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, in a register. See Comparison Operations.
The mode
mis not related to the modes ofxandy, but instead is the mode of the condition code value. It is some mode in classMODE_CC, oftenCCmode. See Condition Code Status. IfmisCCmode, the operation returns sufficient information (in an unspecified format) so that any comparison operator can be applied to the result of theCOMPAREoperation. For other modes in classMODE_CC, the operation only returns a subset of this information.Normally,
xandymust have the same mode. Otherwise,compareis valid only if the mode ofxis in classMODE_INTandyis aconst_intorconst_doublewith modeVOIDmode. The mode ofxdetermines what mode the comparison is to be done in; thus it must not beVOIDmode.If one of the operands is a constant, it should be placed in the second operand and the comparison code adjusted as appropriate.
A
comparespecifying twoVOIDmodeconstants 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.(neg:m x)(ss_neg:m x)(us_neg:m x)These two expressions represent the negation (subtraction from zero) of the value represented by
x, carried out in modem. They differ in the behavior on overflow of integer modes. In the case ofneg, the negation of the operand may be a number not representable in modem, in which case it is truncated tom.ss_negandus_negensure that an out-of-bounds result saturates to the maximum or minimum signed or unsigned value.(mult:m x y)(ss_mult:m x y)(us_mult:m x y)Represents the signed product of the values represented by
xandycarried out in machine modem.ss_multandus_multensure that an out-of-bounds result saturates to the maximum or minimum signed or unsigned value.Some machines support a multiplication that generates a product wider than the operands. Write the pattern for this as
(mult:m (sign_extend:m x) (sign_extend:m y))
where
mis wider than the modes ofxandy, which need not be the same.For unsigned widening multiplication, use the same idiom, but with
zero_extendinstead ofsign_extend.(smul_highpart:m x y)(umul_highpart:m x y)Represents the high-part multiplication of
xandycarried out in machine modem.smul_highpartreturns the high part of a signed multiplication,umul_highpartreturns the high part of an unsigned multiplication.(fma:m x y z)Represents the
fma,fmaf, andfmalbuiltin functions, which computex * y + zwithout doing an intermediate rounding step.(div:m x y)(ss_div:m x y)Represents the quotient in signed division of
xbyy, carried out in machine modem. Ifmis a floating point mode, it represents the exact quotient; otherwise, the integerized quotient.ss_divensures that an out-of-bounds result saturates to the maximum or minimum signed value.Some machines have division instructions in which the operands and quotient widths are not all the same; you should represent such instructions using
truncateandsign_extendas in,(truncate:m1 (div:m2 x (sign_extend:m2 y)))
(udiv:m x y)(us_div:m x y)Like
divbut represents unsigned division.us_divensures that an out-of-bounds result saturates to the maximum or minimum unsigned value.(mod:m x y)(umod:m x y)Like
divandudivbut represent the remainder instead of the quotient.(smin:m x y)(smax:m x y)Represents the smaller (for
smin) or larger (forsmax) ofxandy, interpreted as signed values in modem. When used with floating point, if both operands are zeros, or if either operand isNaN, then it is unspecified which of the two operands is returned as the result.(umin:m x y)(umax:m x y)Like
sminandsmax, but the values are interpreted as unsigned integers.(not:m x)Represents the bitwise complement of the value represented by
x, carried out in modem, which must be a fixed-point machine mode.(and:m x y)Represents the bitwise logical-and of the values represented by
xandy, carried out in machine modem, which must be a fixed-point machine mode.(ior:m x y)Represents the bitwise inclusive-or of the values represented by
xandy, carried out in machine modem, which must be a fixed-point mode.(xor:m x y)Represents the bitwise exclusive-or of the values represented by
xandy, carried out in machine modem, which must be a fixed-point mode.(ashift:m x c)(ss_ashift:m x c)(us_ashift:m x c)These three expressions represent the result of arithmetically shifting
xleft bycplaces. They differ in their behavior on overflow of integer modes. Anashiftoperation is a plain shift with no special behavior in case of a change in the sign bit;ss_ashiftandus_ashiftsaturates to the minimum or maximum representable value if any of the bits shifted out differs from the final sign bit.xhave modem, a fixed-point machine mode.cbe a fixed-point mode or be a constant with modeVOIDmode; 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 ofcisQImoderegardless ofm.(lshiftrt:m x c)(ashiftrt:m x c)Like
ashiftbut for right shift. Unlike the case for left shift, these two operations are distinct.(rotate:m x c)(rotatert:m x c)Similar but represent left and right rotate. If
cis a constant, userotate.(abs:m x)(ss_abs:m x)Represents the absolute value of
x, computed in modem.ss_absensures that an out-of-bounds result saturates to the maximum signed value.(sqrt:m x)Represents the square root of
x, computed in modem. Most oftenmwill be a floating point mode.(ffs:m x)Represents one plus the index of the least significant 1-bit in
x, represented as an integer of modem. (The value is zero ifxis zero.) The mode ofxmust bemorVOIDmode.(clrsb:m x)Represents the number of redundant leading sign bits in
x, represented as an integer of modem, starting at the most significant bit position. This is one less than the number of leading sign bits (either 0 or 1), with no special cases. The mode ofxmust bemorVOIDmode.(clz:m x)Represents the number of leading 0-bits in
x, represented as an integer of modem, starting at the most significant bit position. Ifxis zero, the value is determined byCLZ_DEFINED_VALUE_AT_ZERO(see Miscellaneous Parameters). Note that this is one of the few expressions that is not invariant under widening. The mode ofxmust bemorVOIDmode.(ctz:m x)Represents the number of trailing 0-bits in
x, represented as an integer of modem, starting at the least significant bit position. Ifxis zero, the value is determined byCTZ_DEFINED_VALUE_AT_ZERO(see Miscellaneous Parameters). Except for this case,ctz(x)is equivalent toffs(x) - 1. The mode ofxmust bemorVOIDmode.(popcount:m x)Represents the number of 1-bits in
x, represented as an integer of modem. The mode ofxmust bemorVOIDmode.(parity:m x)Represents the number of 1-bits modulo 2 in
x, represented as an integer of modem. The mode ofxmust bemorVOIDmode.(bswap:m x)Represents the value
xwith the order of bytes reversed, carried out in modem, which must be a fixed-point machine mode. The mode ofxmust bemorVOIDmode.