📄 md.texi
字号:
the appearance of the assembler code is determined mostly by which
alternative was matched. When this is so, the C code for writing the
assembler code can use the variable @code{which_alternative}, which is
the ordinal number of the alternative that was actually satisfied (0 for
the first, 1 for the second alternative, etc.). @xref{Output Statement}.
@end ifset
@ifset INTERNALS
@node Class Preferences
@subsection Register Class Preferences
@cindex class preference constraints
@cindex register class preference constraints
@cindex voting between constraint alternatives
The operand constraints have another function: they enable the compiler
to decide which kind of hardware register a pseudo register is best
allocated to. The compiler examines the constraints that apply to the
insns that use the pseudo register, looking for the machine-dependent
letters such as @samp{d} and @samp{a} that specify classes of registers.
The pseudo register is put in whichever class gets the most ``votes''.
The constraint letters @samp{g} and @samp{r} also vote: they vote in
favor of a general register. The machine description says which registers
are considered general.
Of course, on some machines all registers are equivalent, and no register
classes are defined. Then none of this complexity is relevant.
@end ifset
@node Modifiers
@subsection Constraint Modifier Characters
@cindex modifiers in constraints
@cindex constraint modifier characters
@c prevent bad page break with this line
Here are constraint modifier characters.
@table @samp
@cindex @samp{=} in constraint
@item =
Means that this operand is write-only for this instruction: the previous
value is discarded and replaced by output data.
@cindex @samp{+} in constraint
@item +
Means that this operand is both read and written by the instruction.
When the compiler fixes up the operands to satisfy the constraints,
it needs to know which operands are inputs to the instruction and
which are outputs from it. @samp{=} identifies an output; @samp{+}
identifies an operand that is both input and output; all other operands
are assumed to be input only.
If you specify @samp{=} or @samp{+} in a constraint, you put it in the
first character of the constraint string.
@cindex @samp{&} in constraint
@cindex earlyclobber operand
@item &
Means (in a particular alternative) that this operand is an
@dfn{earlyclobber} operand, which is modified before the instruction is
finished using the input operands. Therefore, this operand may not lie
in a register that is used as an input operand or as part of any memory
address.
@samp{&} applies only to the alternative in which it is written. In
constraints with multiple alternatives, sometimes one alternative
requires @samp{&} while others do not. See, for example, the
@samp{movdf} insn of the 68000.
An input operand can be tied to an earlyclobber operand if its only
use as an input occurs before the early result is written. Adding
alternatives of this form often allows GCC to produce better code
when only some of the inputs can be affected by the earlyclobber.
See, for example, the @samp{mulsi3} insn of the ARM.
@samp{&} does not obviate the need to write @samp{=}.
@cindex @samp{%} in constraint
@item %
Declares the instruction to be commutative for this operand and the
following operand. This means that the compiler may interchange the
two operands if that is the cheapest way to make all operands fit the
constraints.
@ifset INTERNALS
This is often used in patterns for addition instructions
that really have only two operands: the result must go in one of the
arguments. Here for example, is how the 68000 halfword-add
instruction is defined:
@smallexample
(define_insn "addhi3"
[(set (match_operand:HI 0 "general_operand" "=m,r")
(plus:HI (match_operand:HI 1 "general_operand" "%0,0")
(match_operand:HI 2 "general_operand" "di,g")))]
@dots{})
@end smallexample
@end ifset
@cindex @samp{#} in constraint
@item #
Says that all following characters, up to the next comma, are to be
ignored as a constraint. They are significant only for choosing
register preferences.
@ifset INTERNALS
@cindex @samp{*} in constraint
@item *
Says that the following character should be ignored when choosing
register preferences. @samp{*} has no effect on the meaning of the
constraint as a constraint, and no effect on reloading.
Here is an example: the 68000 has an instruction to sign-extend a
halfword in a data register, and can also sign-extend a value by
copying it into an address register. While either kind of register is
acceptable, the constraints on an address-register destination are
less strict, so it is best if register allocation makes an address
register its goal. Therefore, @samp{*} is used so that the @samp{d}
constraint letter (for data register) is ignored when computing
register preferences.
@smallexample
(define_insn "extendhisi2"
[(set (match_operand:SI 0 "general_operand" "=*d,a")
(sign_extend:SI
(match_operand:HI 1 "general_operand" "0,g")))]
@dots{})
@end smallexample
@end ifset
@end table
@node Machine Constraints
@subsection Constraints for Particular Machines
@cindex machine specific constraints
@cindex constraints, machine specific
Whenever possible, you should use the general-purpose constraint letters
in @code{asm} arguments, since they will convey meaning more readily to
people reading your code. Failing that, use the constraint letters
that usually have very similar meanings across architectures. The most
commonly used constraints are @samp{m} and @samp{r} (for memory and
general-purpose registers respectively; @pxref{Simple Constraints}), and
@samp{I}, usually the letter indicating the most common
immediate-constant format.
For each machine architecture, the @file{config/@var{machine}.h} file
defines additional constraints. These constraints are used by the
compiler itself for instruction generation, as well as for @code{asm}
statements; therefore, some of the constraints are not particularly
interesting for @code{asm}. The constraints are defined through these
macros:
@table @code
@item REG_CLASS_FROM_LETTER
Register class constraints (usually lower case).
@item CONST_OK_FOR_LETTER_P
Immediate constant constraints, for non-floating point constants of
word size or smaller precision (usually upper case).
@item CONST_DOUBLE_OK_FOR_LETTER_P
Immediate constant constraints, for all floating point constants and for
constants of greater than word size precision (usually upper case).
@item EXTRA_CONSTRAINT
Special cases of registers or memory. This macro is not required, and
is only defined for some machines.
@end table
Inspecting these macro definitions in the compiler source for your
machine is the best way to be certain you have the right constraints.
However, here is a summary of the machine-dependent constraints
available on some particular machines.
@table @emph
@item ARM family---@file{arm.h}
@table @code
@item f
Floating-point register
@item F
One of the floating-point constants 0.0, 0.5, 1.0, 2.0, 3.0, 4.0, 5.0
or 10.0
@item G
Floating-point constant that would satisfy the constraint @samp{F} if it
were negated
@item I
Integer that is valid as an immediate operand in a data processing
instruction. That is, an integer in the range 0 to 255 rotated by a
multiple of 2
@item J
Integer in the range @minus{}4095 to 4095
@item K
Integer that satisfies constraint @samp{I} when inverted (ones complement)
@item L
Integer that satisfies constraint @samp{I} when negated (twos complement)
@item M
Integer in the range 0 to 32
@item Q
A memory reference where the exact address is in a single register
(`@samp{m}' is preferable for @code{asm} statements)
@item R
An item in the constant pool
@item S
A symbol in the text segment of the current file
@end table
@item AMD 29000 family---@file{a29k.h}
@table @code
@item l
Local register 0
@item b
Byte Pointer (@samp{BP}) register
@item q
@samp{Q} register
@item h
Special purpose register
@item A
First accumulator register
@item a
Other accumulator register
@item f
Floating point register
@item I
Constant greater than 0, less than 0x100
@item J
Constant greater than 0, less than 0x10000
@item K
Constant whose high 24 bits are on (1)
@item L
16-bit constant whose high 8 bits are on (1)
@item M
32-bit constant whose high 16 bits are on (1)
@item N
32-bit negative constant that fits in 8 bits
@item O
The constant 0x80000000 or, on the 29050, any 32-bit constant
whose low 16 bits are 0.
@item P
16-bit negative constant that fits in 8 bits
@item G
@itemx H
A floating point constant (in @code{asm} statements, use the machine
independent @samp{E} or @samp{F} instead)
@end table
@item AVR family---@file{avr.h}
@table @code
@item l
Registers from r0 to r15
@item a
Registers from r16 to r23
@item d
Registers from r16 to r31
@item w
Registers from r24 to r31. These registers can be used in @samp{adiw} command
@item e
Pointer register (r26--r31)
@item b
Base pointer register (r28--r31)
@item q
Stack pointer register (SPH:SPL)
@item t
Temporary register r0
@item x
Register pair X (r27:r26)
@item y
Register pair Y (r29:r28)
@item z
Register pair Z (r31:r30)
@item I
Constant greater than @minus{}1, less than 64
@item J
Constant greater than @minus{}64, less than 1
@item K
Constant integer 2
@item L
Constant integer 0
@item M
Constant that fits in 8 bits
@item N
Constant integer @minus{}1
@item O
Constant integer 8, 16, or 24
@item P
Constant integer 1
@item G
A floating point constant 0.0
@end table
@item IBM RS6000---@file{rs6000.h}
@table @code
@item b
Address base register
@item f
Floating point register
@item h
@samp{MQ}, @samp{CTR}, or @samp{LINK} register
@item q
@samp{MQ} register
@item c
@samp{CTR} register
@item l
@samp{LINK} register
@item x
@samp{CR} register (condition register) number 0
@item y
@samp{CR} register (condition register)
@item z
@samp{FPMEM} stack memory for FPR-GPR transfers
@item I
Signed 16-bit constant
@item J
Unsigned 16-bit constant shifted left 16 bits (use @samp{L} instead for
@code{SImode} constants)
@item K
Unsigned 16-bit constant
@item L
Signed 16-bit constant shifted left 16 bits
@item M
Constant larger than 31
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -