How to use inline assembly asm operand constraints in C code

Constraints on asm operands
Constraints
can indicate whether the operand is in a register,
the type of register,
whether the operand can be used as a memory reference,
or the type of operand address,
whether the operand is an immediate value,
or whether the operand may have Which values.
It can also be stated that the two operands are required to match.
Side effects are not allowed in the operands of inline asm.
If the '<' or '>' constraint is used, there may be side effects, because there is no guarantee that the side effects will occur only once in the instruction that can update the addressing register.

• Simple Constraints: Basic use of constraints.
• Multi-Alternative: When an insn has two alternative constraint-patterns.
• Modifiers: More precise control over effects of constraints.
• Machine Constraints: Special constraints for some particular machines.

Simple constraint
https://gcc.gnu.org/onlinedocs/gcc-9.1.0/gcc/Simple-Constraints.html#Simple-Constraints
space
Whitespace is ignored
'm'
memory operand is allowed, the machine usually Support any type of address.
Note that, for the letters common memory constraints can be used to redefine the rear end TARGET_MEM_CONSTRAINT macro
'O'
'V'
'<'
'>'
'R & lt'
if the register operand is in general register, it is allowed.
'I'
'n-'
'the I', 'J', 'K', ... 'P'
'E'
'F.'
'G', 'H'
'S'
'G'
'X-'
'0', '. 1 ','2',...
'9''p'
other letters

Multiple optional constraints
https://gcc.gnu.org/onlinedocs/gcc-9.1.0/gcc/Multi-Alternative.html#Multi-Alternative
Sometimes, an instruction has multiple optional operand sets. For example, on the 68000, a logical OR instruction can combine a register or an immediate value into memory, and it can also combine any kind of operand into a register; but it cannot combine one memory location into another memory location.
These constraints are expressed as multiple alternatives. An alternative method can be described by a series of letters for each operand.
The overall constraint of the operand consists of the letter (comma) of the operand of the first alternative and the letter (comma) of the operand of the second alternative, and so on, until the last alternative. All operands of an instruction must have the same number of alternatives.

Constrained modifier characters
https://gcc.gnu.org/onlinedocs/gcc-9.1.0/gcc/Modifiers.html#Modifiers'=
'
indicates that this operand is written by this instruction: the previous value will be It is discarded and replaced by new data.
'+'
means that the operand is read and written by instructions.
When the compiler fixes the operands to meet the constraints, it needs to know which operands are read by the instruction and which operands are written by the instruction
'='Identifies only write operands;' +'Identifies one that is both readable and writable The operand of;
if'=' or'+' is specified in the constraint, it will be placed in the first character of the constraint string.
The'&'
means (in certain alternative methods) that this operand is an earlyclobber operand, which is written before the instruction is completed with the input operand.
Prior to this, this operand cannot exist in the register read by the instruction, nor can it be part of any memory address.
'%'
means that the compiler can swap two operands, if this is the cheapest way to make all operands meet the constraints. '%' Applies to all substitutions and must appear as the first character in the constraint. Only read-only operands can use '%'.

Machine-specific constraints

https://gcc.gnu.org/onlinedocs/gcc-9.1.0/gcc/Machine-Constraints.html#Machine-Constraints

Guess you like

Origin blog.csdn.net/wzc18743083828/article/details/100544095