Whenever possible, you should use the general-purpose constraint letters in 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 ‘m’ and ‘r’ (for memory and general-purpose registers respectively; see Simple Constraints), and ‘I’, usually the letter indicating the most common immediate-constant format.
Each architecture defines additional constraints. These constraints are used by the compiler itself for instruction generation, as well as for asm statements; therefore, some of the constraints are not particularly useful for asm. Here is a summary of some of the machine-dependent constraints available on some particular machines; it includes both constraints that are useful for asm and constraints that aren't. The compiler source file mentioned in the table heading for each architecture is the definitive reference for the meanings of that architecture's constraints.
config/aarch64/constraints.md
kSP) wIADD instruction JSUB instruction (once negated) KLMMOV pseudo instruction. The MOV may be assembled to one of several different machine instructions depending on the value NMOV pseudo instruction SYZUshQUmpconfig/arc/constraints.md
qr0-r3, r12-r15. This constraint can only match when the -mq option is in effect. er0-r3, r12-r15, sp. This constraint can only match when the -mq option is in effect. DD0, D1. ICalKLCnLCmLMOPHconfig/arm/constraints.md
hr8-r15. klr0-r7. In ARM state this is an alias for the r constraint. ts0-s31. Used for 32 bit values. wd0-d31 and the appropriate subset d0-d15 based on command line options. Used for 64 bit values only. Not valid for Thumb1. yzGIJKI’ when inverted (ones complement) LI’ when negated (twos complement) MQm’' is preferable for asm statements) RSUvUyUqconfig/avr/constraints.md
ladwadiw’ command ebqtxyzIJKLMNOPGQconfig/bfin/constraints.md
adzqn
A, then the register P0. DWeABbvfcCtkuxywKshKuhKs7Ku7Ku5Ks4Ks3Ku3Pn
PAPBM1M2JLH Qconfig/cr16/cr16.h
btpIJKLMNGconfig/epiphany/constraints.md
U16KLCm1Cl1Cr1Cali, except that for position independent code, no symbols / expressions needing relocations are allowed. CsyRcs-mprefer-short-insn-regs is in effect. RscRctRgsRraRccSraCfmUNSPEC_FP_MODE. config/frv/frv.h
aACC_REGS (acc0 to acc7). bEVEN_ACC_REGS (acc0 to acc7). cCC_REGS (fcc0 to fcc3 and icc0 to icc3). dGPR_REGS (gr0 to gr63). eEVEN_REGS (gr0 to gr63). Odd registers are excluded not in the class but through the use of a machine mode larger than 4 bytes. fFPR_REGS (fr0 to fr63). hFEVEN_REGS (fr0 to fr63). Odd registers are excluded not in the class but through the use of a machine mode larger than 4 bytes. lLR_REG (the lr register). qQUAD_REGS (gr2 to gr63). Register numbers not divisible by 4 are excluded not in the class but through the use of a machine mode larger than 8 bytes. tICC_REGS (icc0 to icc3). uFCC_REGS (fcc0 to fcc3). vICR_REGS (cc4 to cc7). wFCR_REGS (cc0 to cc3). xQUAD_FPR_REGS (fr0 to fr63). Register numbers not divisible by 4 are excluded not in the class but through the use of a machine mode larger than 8 bytes. zSPR_REGS (lcr and lr). AQUAD_ACC_REGS (acc0 to acc7). BACCG_REGS (accg0 to accg7). CCR_REGS (cc0 to cc7). GIJLMNOPconfig/ft32/constraints.md
ABWefOIwxLSbKAconfig/pa/pa.h
afqxyZIJKzdepi instruction LMNldil instruction OPand operations in depi and extru instructions SUGAlo_sum data-linkage-table memory operand QRTWconfig/ia64/ia64.h
ar0 to r3 for addl instruction bcc’ as in “conditional”) defm<’ or ‘>’, the operand can have postincrement and postdecrement which require printing with ‘%Pn’ on IA-64. GIJKLMNOPdep instruction QRshladd instruction Sm’ when not used together with ‘<’ or ‘>’. config/m32c/m32c.c
RspRfbRsb$sp’, ‘$fb’, ‘$sb’. RcrRclR0wR1wR2wR3wR02R13RdiRhlR23RaaRawRalRqiRadRsiRhiRhcRraRflRmmRpiRpaIs3IS1IS2IU2In4In5In6IM2IlbIlwSdSaSiSsSfSsS1config/mep/constraints.md
abcdemexerhjltvxyzABCDIJKLMNOSTUWYZconfig/microblaze/constraints.md
dr0 to r31). zrmsr, $fcc1 to $fcc7). config/mips/constraints.md
dr unless generating MIPS16 code. fhhi register. This constraint is no longer supported. llo register. Use this register to store values that are no bigger than a word. xhi and lo registers. Use this register to store doubleword values. c$25 for -mabicalls. v$3. Do not use this constraint in new code; it is retained only for compatibility with glibc. yr; retained for backwards compatibility. zIJKLlui. Mlui, addiu or ori. NOPGRZCll and sc. ZDprefetch instruction, or for any other instruction with the same addressing mode as prefetch. config/m68k/constraints.md
adfIJKLMNOPRGSTQUWCsCiC0CjCmvqCapswCmvzCmvsApAcconfig/moxie/constraints.md
ABWINconfig/msp430/constraints.md
R12R13KLMYaYlYsconfig/nds32/constraints.md
wldhtkIu03In03Iu04Is05Iu05In05Ip05Iu06Iu08Iu09Is10Is11Is15Iu15Ic15Ie15It15Ii15Is16Is17Is19Is20IhigIzebIzehIxlsIx11IbmsIfexU33U45U37config/nios2/constraints.md
IJKLMz to use r0 instead of 0 in the assembly output. NPSgp as a 16-bit immediate to re-create their 32-bit value. Uvwconfig/pdp11/constraints.md
adfGIJKI’ or ‘J’. LMNOQRconfig/rs6000/constraints.md
bdfvwaWhen using any of the register constraints (wa, wd, wf, wg, wh, wi, wj, wk, wl, wm, wo, wp, wq, ws, wt, wu, wv, ww, or wy) that take VSX registers, you must use %x<n> in the template so that the correct register is used. Otherwise the register number output in the assembly file will be incorrect if an Altivec register is an operand of a VSX instruction that expects VSX register numbering.
asm ("xvadddp %x0,%x1,%x2" : "=wa" (v1) : "wa" (v2), "wa" (v3)); is correct, but:
asm ("xvadddp %0,%1,%2" : "=wa" (v1) : "wa" (v2), "wa" (v3)); is not correct.
If an instruction only takes Altivec registers, you do not want to use %x<n>.
asm ("xsaddqp %0,%1,%2" : "=v" (v1) : "v" (v2), "v" (v3)); is correct because the xsaddqp instruction only takes Altivec registers, while:
asm ("xsaddqp %x0,%x1,%x2" : "=v" (v1) : "v" (v2), "v" (v3)); is incorrect.
wb-mpower9-dform is used or NO_REGS. wdwe-mpower9-vector and -m64 options were used or NO_REGS. wfwg-mmfpgpr was used, a floating point register or NO_REGS. whwiwjwkwlwmwnwowpwqwrwswtwuwvww-mvsx or NO_REGS. wxwywzwDwEwFwGwLwMwOwQlq and stq instructions. wShMQ’, ‘CTR’, or ‘LINK’ register cCTR’ register lLINK’ register xCR’ register (condition register) number 0 yCR’ register (condition register) zXER[CA]’ carry bit (part of the XER register) IJL’ instead for SImode constants) KLMNOPGHmm does not allow addresses that update the base register. If ‘<’ or ‘>’ constraint is also used, they are allowed and therefore on PowerPC targets in that case it is only safe to use ‘m<>’ in an asm statement if that asm statement accesses the operand exactly once. The asm statement must also use ‘%U<opno>’ as a placeholder for the “update” flag in the corresponding load or store instruction. For example: asm ("st%U0 %1,%0" : "=m<>" (mem) : "r" (val)); is correct but:
asm ("st %1,%0" : "=m<>" (mem) : "r" (val)); is not.
esm’ allowed automodification of the base register, but as those are now only allowed when ‘<’ or ‘>’ is used, ‘es’ is basically the same as ‘m’ without ‘<’ and ‘>’. Qm’ or ‘es’ in asm statements) Zm’ or ‘es’ in asm statements) Rap’ is preferable for asm statements) UWjconfig/rl78/constraints.md
Int3Int8JKLMNOPQbiQscWabWbcBC as a base register, with an optional offset. WcaAX, BC, DE, or HL for the address, for calls. WcvWd2DE as a base register, with an optional offset. WdeDE as a base register, without any offset. WfrWh1HL as a base register, with an optional one-byte offset. WhbHL as a base register, with B or C as the index register. WhlHL as a base register, without any offset. Ws1SP as a base register, with an optional one-byte offset. YAAX register. BBC register. DDE register. RA through L registers. SSP register. THL register. Z08WR8 register. Z10WR10 register. ZintR24 to R31). aA register. bB register. cC register. dD register. eE register. hH register. lL register. vwPSW register. xX register. config/rx/constraints.md
QSymbolInt08Sint08Sint16Sint24Uint04config/s390/s390.h
acdfIJKL(0..4095)(−524288..524287)MN0..9:H,Q:D,S,H:0,F:QRSTUWYconfig/sparc/sparc.h
fef’ on the SPARC-V8 architecture and contains both lower and upper floating-point registers on the SPARC-V9 architecture. cdbhCADIJKsethi instruction) Lmovcc instructions (11-bit signed immediate) Mmovrcc instructions (10-bit signed immediate) NK’, except that it verifies that bits that are not in the lower 32-bit range are all zero. Must be used instead of ‘K’ for modes wider than SImode OGHPQRSTUWe’ constraint registers wYconfig/spu/spu.h
acdiohl instruction. const_int is treated as a 64 bit value. ffsmbi. ABCDiohl instruction. const_int is treated as a 32 bit value. IJKMstop. Niohl and fsmbi. OPRSTUWYZiohl instruction. const_int is sign extended to 128 bit. config/c6x/constraints.md
abABCDaDbIu4Iu5In5Is5I5xIuBIsBIsCJcJsQRZconfig/tilegx/constraints.md
R00R01R02R03R04R05R06R07R08R09R10IJKLm<’ or ‘>’, the operand can have postincrement which requires printing with ‘%In’ and ‘%in’ on TILE-Gx. For example: asm ("st_add %I0,%1,%i0" : "=m<>" (*mem) : "r" (val)); MNOPQSTUm’ when not used together with ‘<’ or ‘>’. WYZ0Z1config/tilepro/constraints.md
R00R01R02R03R04R05R06R07R08R09R10IJKLm<’ or ‘>’, the operand can have postincrement which requires printing with ‘%In’ and ‘%in’ on TILEPro. For example: asm ("swadd %I0,%1,%i0" : "=m<>" (mem) : "r" (val)); MNOPQTUm’ when not used together with ‘<’ or ‘>’. WYconfig/visium/constraints.md
bmdb cmdc flr29, r30 and r31 tr1 ur2 vr3 GJKLMOPconfig/i386/constraints.md
Ra, b, c, d, si, di, bp, sp). ql. In 32-bit mode, a, b, c, and d; in 64-bit mode, any integer register. Qh: a, b, c, and d. aa register. bb register. cc register. dd register. Ssi register. Ddi register. Aa and d registers. This class is used for instructions that return double word results in the ax:dx register pair. Single word values will be allocated either in ax or dx. For example on i386 the following implements rdtsc: unsigned long long rdtsc (void)
{
unsigned long long tick;
__asm__ __volatile__("rdtsc":"=A"(tick));
return tick;
} This is not correct on x86-64 as it would allocate tick in either ax or dx. You have to use the following variant instead:
unsigned long long rdtsc (void)
{
unsigned int tickl, tickh;
__asm__ __volatile__("rdtsc":"=a"(tickl),"=d"(tickh));
return ((unsigned long long)tickh << 32)|tickl;
} ft%st(0)). u%st(1)). yxYz%xmm0). IJKL0xFF or 0xFFFF, for andsi as a zero-extending move. Mlea instruction). Nin and out instructions). GCeZconfig/stormy16/stormy16.h
abcdetyzIJKLMNOPQRSTUZconfig/xtensa/constraints.md
abAIJKL
© Free Software Foundation
Licensed under the GNU Free Documentation License, Version 1.3.
https://gcc.gnu.org/onlinedocs/gcc-6.3.0/gcc/Machine-Constraints.html